Canvas
The canvas half of the kit: a pan/zoom board with draggable inspector panels, a boards section, an app toolbar, a tool rail, minimap and zoom bar.
import {
WhiteboardShell, FloatingPanel, SectionPanel, CreatePanel, sectionPanelWidth,
Toolbar, VerticalToolbar, useWhiteboardLayout, useWhiteboardStore,
} from '@objectifthunes/whiteboard'
// Module scope: useWhiteboardLayout re-derives on the object's identity, so an
// inline literal would recompute the layout on every render.
const WIDTHS = { inspector: 300, layers: 260, output: 300 }
// Returns { layout, panelWidth, positions }. panelWidth is grid-snapped.
const { positions, panelWidth } = useWhiteboardLayout({ widths: WIDTHS, startX: 60, y: 80, gap: 40 })
const fitToContent = useWhiteboardStore(s => s.fitToContent)
const resetWidgets = useWhiteboardStore(s => s.resetWidgets)
{/* static, not the default fixed: the screen is embedded in a page. */}
<Toolbar position="static" end={<><Chip>{pct}%</Chip><ThemeToggle … /></>}>
<SectionTitle>Canvas</SectionTitle>
<Divider orientation="vertical" />
<IconButton icon={<ZoomIn size={14} />} label="Fit to content" onClick={fitToContent} />
<Button onClick={render}><Play size={13} />Render</Button>
</Toolbar>
<VerticalToolbar position="static" bottom={<IconButton … />}>
{TOOLS.map(t => (
<Tooltip key={t.id} label={t.label} placement="right">
<Button variant={tool === t.id ? 'primary' : 'secondary'} iconOnly onClick={() => setTool(t.id)}>
<t.icon size={14} />
</Button>
</Tooltip>
))}
</VerticalToolbar>
{/* contained: lays out inside a sized, positioned parent rather than the
viewport. The shell renders its own ZoomBar and Minimap. */}
<WhiteboardShell contained showMinimap>
<FloatingPanel title="Inspector" defaultPosition={positions.inspector} width={panelWidth.inspector} focusable>
<PanelErrorBoundary>…</PanelErrorBoundary>
</FloatingPanel>
<SectionPanel title="Scenes" defaultPosition={{ x: 60, y: 560 }} cols={3} cardW={200}>
{scenes.map(s => <ItemCard key={s.id}>…</ItemCard>)}
</SectionPanel>
{/* sectionPanelWidth keeps the create card flush beside the board. */}
<CreatePanel
title="New scene"
label="Create scene"
defaultPosition={{ x: 60 + sectionPanelWidth(3, 200) + 40, y: 560 }}
onClick={create}
/>
</WhiteboardShell>The canvas half of the kit, which the other screens do not touch at all. Drag empty space to pan, wheel to zoom, drag a panel by its header to move it. The ZoomBar bottom-right and the Minimap come from WhiteboardShell itself — you do not mount them.
contained is what makes this embeddable. By default the shell, zoom bar and minimap are position: fixed and own the viewport; contained lays them out inside a sized, positioned parent instead. Toolbar and VerticalToolbar take position="static" for the same reason.
useWhiteboardLayout places the three panels in a row from one widths map. Keep that map at module scope — the hook re-derives on object identity, so an inline literal recomputes every render. Fit and Reset in the toolbar drive fitToContent and resetWidgets straight off the store, and the zoom percentage in the end slot reads scale from it.
The Scenes board is a SectionPanel — one draggable panel holding a static grid, with gaps that are multiples of the canvas grid so it lands on whole plus signs. sectionPanelWidth(cols, cardW) is what lets the CreatePanel sit flush beside it without hand-measuring.