WarUI documentation

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());

API reference

DOCK-A01-F01 API
KindNameTypeDescription
FunctioncreateDockModel(layout: DockLayout, options?: DockModelOptions) => DockModelValidates and normalizes a layout object. Throws DockLayoutError when the root or a node type is missing. The input is never mutated.
PropertyrootDockNodeRequired top-level node of the layout object.
PropertytypestringNode discriminator: 'split', 'tabs' or 'documentArea'. Unknown properties on nodes are preserved.
PropertychildrenDockNode[]Ordered child nodes of a split.
MethodgetLayout() => DockLayoutReturns a deep copy of the normalized layout. It contains only JSON data and round-trips through JSON.stringify and JSON.parse.
Eventready{ layout: DockLayout }Fires exactly once, after the first render calls markRendered().