Skip to content

Layout System ​

Opening panels ​

ts
// Docked (default) — goes into the first available leaf group
workspace.openPanel('my-map', 'map', { title: 'Satellite View' });

// Forced docked — explicit
workspace.openPanel('my-map', 'map', { initialTarget: 'docked' });

// Floating — opens as a resizable window
workspace.openPanel('settings', 'settings', { initialTarget: 'floating' });

// 'tabbed' is the same as 'docked': both add a tab to the first group
workspace.openPanel('log-2', 'logs', { initialTarget: 'tabbed' });

To put a panel into a particular group, or split one, open it and then use dockPanelToGroup(id, leafId, position) or dockPanelToWorkspaceEdge(id, side).

If the panel ID is already open, openPanel focuses it instead of creating a duplicate.

Opening beside another panel ​

dockTo places a new panel next to one that is already docked (7.8.0):

ts
// A legend in a new group on the right of the chart, taking a quarter of the width:
workspace.openPanel('legend-1', 'legend', { dockTo: { panel: 'chart-1', position: 'right', size: 0.25 } });

// A second document as a tab in the same group as the first:
workspace.openPanel('doc-2', 'editor', { dockTo: { panel: 'doc-1', position: 'center' } });
  • position is 'left', 'right', 'top', 'bottom' (a new group split off on that side) or 'center' (a tab in the same group).
  • size is the new group's share of that split, from 0.1 to 0.9. Without it, the workspace's default split ratio applies.
  • dockTo wins over initialTarget, and applies only to a panel that isn't open yet: opening an open panel focuses it, as always.
  • If panel isn't docked (not open, floating or minimized), the new panel is placed as usual, and a development warning says why.

Controlling where users can move panels ​

Two opt-in controls decide where the user can move a panel (7.9.0). Neither restricts your own calls: floatPanel, dockPanelToGroup, openPanel and the others always do what they say.

Per panel type, in its defaultOptions:

ts
createWorkspace({
  panels: {
    // A main view that must stay in the grid.
    main: { component: MainView, defaultOptions: { canFloat: false } },
    // A tool palette that must stay floating.
    palette: { component: Palette, defaultOptions: { canDock: false, initialTarget: 'floating' } },
  },
});
  • canFloat: false: a tab drag can't end in a floating window. Dropped on nothing or on a corner, the panel stays where it was. "Float Window" and the taskbar's "Maximize" are hidden. A window your app floated itself can still be moved to another corner.
  • canDock: false: dragging the panel offers no group, tab or edge targets, only corners, so it stays floating.

Across the workspace, canDrop vetoes any move, for rules that depend on where a panel would go:

ts
createWorkspace({
  panels,
  // Only tool panels in the "tools" group, and nothing along the top edge.
  canDrop: ({ panelId, component, to }) =>
    !(to.kind === 'group' && to.leafId === 'tools' && component !== 'tool') &&
    !(to.kind === 'edge' && to.side === 'top'),
});

It's called with the panel and its registered component, and with to, one of:

toThe move
{ kind: 'group', leafId, position }Into a group: a new split on one side ('left', 'right', 'top', 'bottom'), or 'center' as a tab, which also covers dropping it between tabs
{ kind: 'edge', side }Along a workspace edge, as a full-width or full-height strip
{ kind: 'float', anchor }Into a floating window, pinned to a corner, or free (anchor: null: a tab dropped on nothing)

A forbidden target isn't offered: its drop zone, edge or corner doesn't appear while the panel is dragged, and releasing there does nothing. The rule is asked again at release, so a rule that changes mid-drag still holds.

  • Positions are the ones the move applies. Under RTL, the zone drawn on the screen's right splits to the left, and canDrop sees 'left'.
  • It runs while the pointer moves, for every target, so keep it fast and free of side effects.
  • If it throws, the move is allowed and the error is logged.
  • canDrop runs after the panel type's own canFloat / canDock; it can't allow what those forbid.

defaultOptions.canPopOut (7.12.0) is the same kind of switch for the "Open in new window" menu item, on a workspace created with popOut: true; see Pop-out Windows.

Activating / focusing panels ​

ts
workspace.focusPanel('my-map');
// For floating: raises z-index so the window appears on top.
// For docked: selects the tab within its leaf group.

workspace.focusPanel('my-map', { restore: true });
// A minimized panel is restored first, then focused (7.11.0). Without it, a minimized panel stays
// in the taskbar.

A panel in its own browser window (7.12.0) comes forward with its window, best effort; workspace.focusPanelWindow(id) does the same for any panel. See Pop-out Windows.

Querying open panels ​

ts
if (!workspace.isOpen('my-map')) {
  workspace.openPanel('my-map', 'map');
}

const openIds = workspace.getOpenPanelIds();
// → ['my-map', 'settings', 'log-2']
// While a managed widget is out of its panel, its own panel is listed too: 'my-map/results'.

Floating window operations ​

ts
workspace.floatPanel('my-map');                  // detach from grid
workspace.floatPanel('my-map', { x: 100, y: 60, width: 800, height: 600 });

workspace.maximizePanel('my-map');               // toggle: fill the workspace, or restore its size
workspace.dockPanel('my-map');                   // return to grid
workspace.dockPanel('my-map', 'left-leaf');      // dock to specific group

Its own browser window (7.12.0) ​

With createWorkspace({ popOut: true }) and a type with defaultOptions.canPopOut, a panel can move into a browser window of its own, for a second monitor:

ts
workspace.popOutPanel('my-map');   // inside the user's click → PopOutResult
workspace.returnPanel('my-map');   // back where it was

While out, maximizePanel and floatPanel are ignored, and minimizePanel or dockPanel bring it back first. See Pop-out Windows.

Minimizing ​

ts
workspace.minimizePanel('my-map');   // sends to taskbar
workspace.restorePanel('my-map');    // restores from taskbar

Layout serialization ​

ts
// Save the entire workspace to JSON
const snapshot = workspace.saveLayout();
localStorage.setItem('layout', snapshot);

// Restore — replaces everything currently open
workspace.loadLayout(localStorage.getItem('layout') ?? '');

The snapshot JSON contains:

  • version — schema version, for migrating older saved layouts as the format evolves
  • activePanelId — the panel that was active at save time; omitted when none was, or when that panel was excluded from the snapshot as non-serializable
  • gridRoot — the full tree of branches and leaf groups
  • floating — positions and sizes of floating windows
  • minimized — panels in the taskbar
  • panels — metadata (title, component key, state) for every open panel

A managed widget's own panel ('<ownerId>/<widgetId>', 7.11.0) is never saved, and isn't reported as excluded: loadLayout() sends such a widget back into its panel. Restore widgets from their owner panel with placement(); see Widgets Out of the Panel.

A panel in its own browser window (7.12.0) is saved at the place it would come back to, so the saved layout is the one from before it left. No window reopens after a load, and loadLayout() closes every pop-out window. See Pop-out Windows.

Which panel is active after a restore ​

A restored workspace comes back with state.activePanelId set to the panel the user was actually looking at — which matters because that is the panel useActiveContribution() reads from, so every contributed sidebar tab and toolbar item is wired to it.

It resolves in this order:

  1. The snapshot's own activePanelId, if that panel is still visible in the restored layout.
  2. Otherwise the selected tab of the first leaf in the grid, depth-first. This is the path taken by layouts saved before activePanelId was persisted, and by any snapshot whose recorded value is no longer valid.
  3. Otherwise the frontmost (highest z-index) floating window, so a layout of only floating windows still restores with something active.
  4. Otherwise null.

A minimized panel is never chosen — it isn't on screen, even though it stays mounted. The same rule holds during normal use: closing or minimizing the active panel moves activePanelId to whatever becomes visible in its place, rather than leaving it on a panel that is gone or hidden.

Pre-loading a layout on startup ​

Pass the JSON string directly as the initialState of createWorkspace():

ts
const workspace = createWorkspace({
  panels: { ... },
  initialState: localStorage.getItem('layout'),
});

The layout is parsed synchronously before the first render — no flicker, no useEffect needed.

Loading asynchronously ​

For layouts fetched from a server, use the imperative API:

ts
// Outside React:
fetchLayoutFromServer().then(json => workspace.loadLayout(json));

// Or inside a component:
const workspace = useWorkspace();
useEffect(() => {
  fetch('/api/layout').then(r => r.text()).then(json => {
    workspace.loadLayout(json);
  });
}, [workspace]);

Dirty-state close guards ​

Prevent accidental data loss with close guards:

ts
// In your panel component:
useBeforeClose(hasUnsavedChanges ? () => confirm('Discard unsaved changes?') : null);

// Or use the built-in dirty flag + modal:
const panel = usePanel();
panel.setDirty(true, {
  title: 'Unsaved Changes',
  message: 'Your changes will be lost. Continue?',
});

Event bus ​

ts
// Publish from any panel or outside React:
workspace.publish('map:zoom', { level: 12 });

// Subscribe in a panel:
const workspace = useWorkspace();
useEffect(() => {
  return workspace.subscribe('map:zoom', ({ level }) => {
    setZoom(level);
  });
}, [workspace]);

Released under the MIT License.