Declarative JSON layout tree
experimental
The whole workspace is described by one plain JSON object with nested nodes. Edit the JSON and apply it to re-render the dock.
Live example
Expected behavior
Pressing Apply re-renders the dock to match the tree exactly. Node badges show the type of each region. Invalid JSON shows an inline parse error and the previous layout stays on screen.
Source
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
orientation: 'horizontal',
sizes: [0.2, 0.8],
children: [
{ type: 'tabs', id: 'explorer', title: 'Explorer', activePaneId: 'files',
panes: [{ id: 'files', kind: 'tool', title: 'Files' }] },
{ type: 'tabs', id: 'editor', title: 'Editor', activePaneId: 'main',
panes: [{ id: 'main', kind: 'document', title: 'main.ts' }] },
],
},
});
model.on('ready', () => console.log('ready'));
model.markRendered();
console.log(model.getLayout());
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
orientation: 'horizontal',
sizes: [0.2, 0.8],
children: [
{ type: 'tabs', id: 'explorer', title: 'Explorer', activePaneId: 'files',
panes: [{ id: 'files', kind: 'tool', title: 'Files' }] },
{ type: 'tabs', id: 'editor', title: 'Editor', activePaneId: 'main',
panes: [{ id: 'main', kind: 'document', title: 'main.ts' }] },
],
},
});
model.on('ready', () => console.log('ready'));
model.markRendered();
console.log(model.getLayout());
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
orientation: 'horizontal',
sizes: [0.2, 0.8],
children: [
{ type: 'tabs', id: 'explorer', title: 'Explorer', activePaneId: 'files',
panes: [{ id: 'files', kind: 'tool', title: 'Files' }] },
{ type: 'tabs', id: 'editor', title: 'Editor', activePaneId: 'main',
panes: [{ id: 'main', kind: 'document', title: 'main.ts' }] },
],
},
});
model.on('ready', () => console.log('ready'));
model.markRendered();
console.log(model.getLayout());
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
orientation: 'horizontal',
sizes: [0.2, 0.8],
children: [
{ type: 'tabs', id: 'explorer', title: 'Explorer', activePaneId: 'files',
panes: [{ id: 'files', kind: 'tool', title: 'Files' }] },
{ type: 'tabs', id: 'editor', title: 'Editor', activePaneId: 'main',
panes: [{ id: 'main', kind: 'document', title: 'main.ts' }] },
],
},
});
model.on('ready', () => console.log('ready'));
model.markRendered();
console.log(model.getLayout());
// JavaScript module for Blazor interop
import { createDockModel } from '@warlockcode/warui-core';
const model = createDockModel({
root: {
type: 'split',
id: 'root',
orientation: 'horizontal',
sizes: [0.2, 0.8],
children: [
{ type: 'tabs', id: 'explorer', title: 'Explorer', activePaneId: 'files',
panes: [{ id: 'files', kind: 'tool', title: 'Files' }] },
{ type: 'tabs', id: 'editor', title: 'Editor', activePaneId: 'main',
panes: [{ id: 'main', kind: 'document', title: 'main.ts' }] },
],
},
});
model.on('ready', () => console.log('ready'));
model.markRendered();
console.log(model.getLayout());
API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Function | createDockModel | (layout: DockLayout, options?: DockModelOptions) => DockModel | Validates and normalizes a layout object. Throws DockLayoutError when the root or a node type is missing. The input is never mutated. |
| Property | root | DockNode | Required top-level node of the layout object. |
| Property | type | string | Node discriminator: 'split', 'tabs' or 'documentArea'. Unknown properties on nodes are preserved. |
| Property | children | DockNode[] | Ordered child nodes of a split. |
| Method | getLayout | () => DockLayout | Returns a deep copy of the normalized layout. It contains only JSON data and round-trips through JSON.stringify and JSON.parse. |
| Event | ready | { layout: DockLayout } | Fires exactly once, after the first render calls markRendered(). |