Skip to content

Panel Registry ​

The panel registry maps string component keys (used in openPanel() and serialized layouts) to React component constructors. There are two ways to populate it.

Pass a panels map to createWorkspace(). It fills the workspace's own registry, workspace.registry:

ts
const workspace = createWorkspace({
  panels: {
    map:    { component: MapPanel,    defaultOptions: { title: 'Map', canClose: false } },
    editor: { component: EditorPanel, defaultOptions: { title: 'Editor' } },
    logs:   { component: LogsPanel },
  },
});

Each key is the componentKey argument to openPanel(id, componentKey). Keys must be stable — they are persisted inside saveLayout() JSON. Keys starting with rdd: are reserved for the library: 'rdd:widget' is the kind of a managed widget's own panel (7.11.0), which saveLayout() never saves.

PanelDefinition ​

ts
interface PanelDefinition {
  // The library injects `panelId` as a prop automatically.
  // Components that don't declare it in their props can read `usePanel().id` instead.
  component: ComponentType<any>;
  defaultOptions?: PanelRegistryEntry['defaultOptions'];
}

defaultOptions ​

The type is PanelRegistryEntry['defaultOptions'] (PanelRegistryEntry is exported). All fields are optional. They set the per-panel defaults; most can be overridden per-instance in openPanel.

OptionTypeDefaultDescription
titlestring | MessageDescriptor | (() => string)—Tab and window title. A function is called each time the title renders; it's also the title a restored panel takes, since a function title isn't saved in a layout.
iconReactNode—Icon shown in the tab, the floating title bar and the taskbar. A single instance can change it at runtime with usePanel().setIcon() or workspace.setPanelIcon().
initialTarget'floating' | 'docked' | 'tabbed''docked'Initial placement when the panel is first opened.
favoritePosition{ x, y, width, height }{ x: 300, y: 150, width: 450, height: 350 }Default floating bounds (position + size) when the panel is first floated. All four values accept numbers (px) or CSS strings ('50%').
canClosebooleantrueShow or hide the × close button.
canMinimizebooleantrueShow or hide the minimize button.
canDragbooleantrueAllow the tab to be dragged to a different leaf or position. When false, the panel cannot be floated via drag.
canFloatbooleantruefalse: the user can't make it floating. A tab drag can't end in a floating window, and "Float Window" and the taskbar's "Maximize" are hidden. See Controlling where users can move panels. (7.9.0)
canDockbooleantruefalse: the user can't dock it. Dragging it offers no group, tab or edge targets, only corners. Pair it with initialTarget: 'floating'. (7.9.0)
defaultAnchorFloatAnchor ('top-left' | 'top-right' | 'bottom-left' | 'bottom-right')— (unanchored)Every instance of this component opens pre-anchored to the given workspace corner when floated — see the anchor option in Workspace, which this is the per-component default for.
disableLivePreviewbooleanfalseShow a placeholder instead of a live thumbnail in the preview that pops up when the pointer is over this panel's taskbar button (while it is minimized). A canvas-rendered view (a WebGL map) that blurs in the scaled-down preview can instead be marked with data-rdd-preview-unscale on its container, which renders it at full resolution there.
renderHeaderActions(panelId: string) => ReactNode—Inject React nodes into the panel tab header (e.g. export buttons).
classNamestring—Class added to each panel of this type, on its own content element (.rdd-panel-content). That element moves with the panel, so the class applies docked, floating and in the taskbar preview. (7.8.0)
tabClassNamestring—Class added to the tab of each panel of this type. (7.8.0)
keepAlivebooleantruefalse unmounts the panel's component while it is hidden and mounts it afresh when shown — see Freeing a hidden panel below. (7.8.0)
preserveEmbedsbooleanfalseAn <iframe> (or other embedded document or media) in the panel doesn't reload when the panel moves: docked, floated, minimised, restored, or the grid changing around it. Uses moveBefore() in Chrome and Edge 133+ and Firefox 144+; in Safari it reloads as before. (7.11.0)
canPopOutbooleanfalseThe user may move a panel of this type into its own browser window ("Open in new window" in its tab and ⋮ menus), and workspace.popOutPanel(id) may. Needs createWorkspace({ popOut: true }). It gates the menu item and new calls only: a window already open stays open when it changes. preserveEmbeds doesn't reach into a window: an iframe reloads there. See Pop-out Windows. (7.12.0)

Freeing a hidden panel (keepAlive: false) ​

By default a panel is never unmounted while it is open: moving it, hiding it behind another tab or minimizing it keeps its component, its state, its scroll position and anything it holds (a canvas, a video, a WebGL context). That is the right default for almost every panel.

For a heavy panel that is rarely shown, keepAlive: false trades that for memory: its component unmounts while the panel is an unselected tab or minimized, and mounts afresh when it is shown again.

ts
const workspace = createWorkspace({
  panels: {
    report: { component: ReportPanel, defaultOptions: { title: 'Report', keepAlive: false } },
  },
});

What to expect:

  • Its own state is lost each time it is hidden, like a component that unmounts anywhere else. Keep what must survive outside it (a store, props, useSaveState).
  • Its tab, title, dirty flag and lifecycle continue. Hiding is not closing: onClose is not called; it is called once, when the panel is really closed.
  • A guard it registered with useBeforeClose is not active while it is unmounted, since the guard goes with the component. Its dirty flag lives in the workspace and still is, so closing a hidden dirty panel still asks first.
  • The taskbar shows a placeholder instead of a live preview while it is minimized.
  • While it is unmounted, saveLayout() saves its open-time props, since there is no component to report state through useSaveState.
  • A floating window is always shown, so a floating panel stays mounted.

Locked / pinned panel pattern ​

Set canDrag, canClose, and canMinimize all to false to create a panel the user cannot move, close, or hide — useful for a primary map or content area:

ts
const workspace = createWorkspace({
  panels: {
    mainMap: {
      component: MapPanel,
      defaultOptions: {
        title:       'Map',
        canDrag:     false,
        canClose:    false,
        canMinimize: false,
      },
    },
  },
});

A panel locked this way has no tab context menu (every built-in item is off), so custom items it adds with usePanelContextMenu don't appear on its tab.

Typed registry: definePanels ​

Wrap the map in definePanels() and the workspace's openPanel is typed from it: only registered names are accepted, and props is checked against that panel's component (without panelId, which the library passes). Opt-in: a plain map keeps working exactly as before.

tsx
import { createWorkspace, definePanels } from 'react-dockable-desktop';

const panels = definePanels({
  map:   { component: MapPanel },
  chart: { component: ChartPanel },   // ChartPanel: React.FC<{ panelId: string; series: number }>
});
export const workspace = createWorkspace({ panels });

workspace.openPanel('c1', 'chart', { props: { series: 3 } });   // ✓
workspace.openPanel('m1', 'mpa');                               // ✗ not a registered panel
workspace.openPanel('c2', 'chart', { props: { series: '3' } }); // ✗ series is a number

definePanels returns its argument unchanged; the typing is all at compile time. With a typed event bus as well, pass both type arguments: createWorkspace<typeof panels, AppEvents>({ panels }).

The typing comes from the workspace createWorkspace returns. useWorkspace() returns the untyped Workspace, so for typed calls inside components, import that same workspace (it's the one you passed to <DockableDesktopProvider>). The typed workspace is still a Workspace and goes anywhere one does.

Panels registered later with registry.register() aren't in the type; open them through useWorkspace().

Imperative registration (advanced) ​

For dynamic panel types registered after the workspace is created, use workspace.registry.register() — or, inside React, useWorkspace().registry.register():

ts
workspace.registry.register('live-chart', LiveChartComponent, {
  title: 'Live Chart',
  canClose: true,
});

Look entries up with get() and list them with getRegisteredIds():

ts
workspace.registry.get('live-chart');        // → { Component, defaultOptions } | undefined
workspace.registry.getRegisteredIds();       // → ['live-chart', …]

There is no global registry: each workspace has its own, so several workspaces on one page never share panel keys.

Unregistered key warning ​

If openPanel('id', 'unknown-key') is called and 'unknown-key' is not in the registry, the panel renders a visual warning placeholder and emits a console.warn naming the panel and the missing key. Add the key to the panels config of createWorkspace(), or register it with workspace.registry.register().

Released under the MIT License.