Document area vs tool panes
experimental
A central document area holds open documents while tool panes dock around it. Documents and tool panes have different default behaviours and can be read separately.
Live example
Expected behavior
Documents are drawn with a solid border and a Document badge and have a close button; tool panes use a dashed border and a Tool badge and cannot be closed. Opening a document appends and activates it; closing the active document activates its neighbour. The JSON readout lists documents only.
Source
import { closeDocument, getDocuments, openDocument } from '@warlockcode/warui-core';
let layout = {
type: 'split',
orientation: 'horizontal',
children: [
{ type: 'tabs', id: 'left', activePaneId: 'explorer',
panes: [{ id: 'explorer', kind: 'tool', title: 'Explorer' }] },
{ type: 'documentArea', id: 'center', activePaneId: 'doc-2',
panes: [
{ id: 'doc-1', kind: 'document', title: 'main.ts' },
{ id: 'doc-2', kind: 'document', title: 'readme.md' },
] },
],
};
layout = openDocument(layout, { id: 'doc-3', title: 'Untitled-3' });
layout = closeDocument(layout, 'doc-1');
console.log(getDocuments(layout));
import { closeDocument, getDocuments, openDocument } from '@warlockcode/warui-core';
let layout = {
type: 'split',
orientation: 'horizontal',
children: [
{ type: 'tabs', id: 'left', activePaneId: 'explorer',
panes: [{ id: 'explorer', kind: 'tool', title: 'Explorer' }] },
{ type: 'documentArea', id: 'center', activePaneId: 'doc-2',
panes: [
{ id: 'doc-1', kind: 'document', title: 'main.ts' },
{ id: 'doc-2', kind: 'document', title: 'readme.md' },
] },
],
};
layout = openDocument(layout, { id: 'doc-3', title: 'Untitled-3' });
layout = closeDocument(layout, 'doc-1');
console.log(getDocuments(layout));
import { closeDocument, getDocuments, openDocument } from '@warlockcode/warui-core';
let layout = {
type: 'split',
orientation: 'horizontal',
children: [
{ type: 'tabs', id: 'left', activePaneId: 'explorer',
panes: [{ id: 'explorer', kind: 'tool', title: 'Explorer' }] },
{ type: 'documentArea', id: 'center', activePaneId: 'doc-2',
panes: [
{ id: 'doc-1', kind: 'document', title: 'main.ts' },
{ id: 'doc-2', kind: 'document', title: 'readme.md' },
] },
],
};
layout = openDocument(layout, { id: 'doc-3', title: 'Untitled-3' });
layout = closeDocument(layout, 'doc-1');
console.log(getDocuments(layout));
import { closeDocument, getDocuments, openDocument } from '@warlockcode/warui-core';
let layout = {
type: 'split',
orientation: 'horizontal',
children: [
{ type: 'tabs', id: 'left', activePaneId: 'explorer',
panes: [{ id: 'explorer', kind: 'tool', title: 'Explorer' }] },
{ type: 'documentArea', id: 'center', activePaneId: 'doc-2',
panes: [
{ id: 'doc-1', kind: 'document', title: 'main.ts' },
{ id: 'doc-2', kind: 'document', title: 'readme.md' },
] },
],
};
layout = openDocument(layout, { id: 'doc-3', title: 'Untitled-3' });
layout = closeDocument(layout, 'doc-1');
console.log(getDocuments(layout));
// JavaScript module for Blazor interop
import { closeDocument, getDocuments, openDocument } from '@warlockcode/warui-core';
let layout = {
type: 'split',
orientation: 'horizontal',
children: [
{ type: 'tabs', id: 'left', activePaneId: 'explorer',
panes: [{ id: 'explorer', kind: 'tool', title: 'Explorer' }] },
{ type: 'documentArea', id: 'center', activePaneId: 'doc-2',
panes: [
{ id: 'doc-1', kind: 'document', title: 'main.ts' },
{ id: 'doc-2', kind: 'document', title: 'readme.md' },
] },
],
};
layout = openDocument(layout, { id: 'doc-3', title: 'Untitled-3' });
layout = closeDocument(layout, 'doc-1');
console.log(getDocuments(layout));
API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Node type | type: 'documentArea' | — | Central region holding panes of kind document, with an activePaneId. |
| Property | kind | 'document' | 'tool' | Pane property that selects document or tool behaviour. |
| Function | openDocument | (root: DockNode, descriptor: DocumentDescriptor) => DockNode | Adds a document to a document area and activates it. An open id is activated, not duplicated. Throws DockLayoutError if the id is a tool pane or no document area matches. |
| Function | closeDocument | (root: DockNode, paneId: string) => DockNode | Closes a document and activates the next or previous one. Tool panes and unknown ids return the same root unchanged. |
| Function | getDocuments | (root: DockNode) => DockPane[] | Returns the open documents in document order. |