@hilum/designer
v4.7.5
Published
Engine-agnostic canvas-editor chrome — DesignerShell, Toolbar, Panel, Pane + generic useHistory and useKeybindings hooks
Readme
@hilum/designer
Engine-agnostic canvas-editor chrome. Provides the shell, toolbar, side panels, collapsible panes, and generic hooks (undo/redo stack, keyboard shortcuts) — works with any kind of editing surface (free-positioned canvas, form builder, layout editor, code editor).
For the actual canvas (pan/zoom viewport, layers, drag/resize), use @hilum/designer-canvas on top.
Components
<DesignerShell>— root layout (full viewport, themed)<DesignerWorkspace>/<DesignerWorkspaceViewport>— floating-chrome positioning boundary and safe canvas region<DesignerHeader>/<DesignerSidebar>/<DesignerPanel>— chrome<DesignerPanelHeader>/<DesignerPanelTabs>— panel title bar and value-based tabs<DesignerPane>(+DesignerPaneTitle,DesignerPaneContent) — collapsible property panel section withshowForpredicate<DesignerPropertyRow>/DesignerPropertyLabel/DesignerPropertyControls/DesignerPropertyField/DesignerPropertyGroup— inspector rowsTwoValueControl/FourValueControl/SpacingControl/CornerRadiusControl— compound numeric inputs<DesignerToolbar>+DesignerToolbarGroup/DesignerToolbarButton/DesignerToolbarSeparator— composable toolbar<FontPicker>— searchable font-family picker with live previews (compact density)
Floating workspace
Use the workspace primitives when desktop editor chrome should float over a
full-bleed surface. Without safeInsets, the viewport fills the workspace and
floating panels overlay the canvas. Add safeInsets when an editor instead
needs an unobscured region for fit and center calculations.
Floating rails and panels size themselves to their content. Their configured top and bottom insets define a maximum available height; overflowing content scrolls inside the surface instead of stretching it to the full workspace.
<DesignerWorkspace>
<DesignerWorkspaceViewport>{canvas}</DesignerWorkspaceViewport>
<DesignerSidebar variant="floating" floatingInset={{ left: 0 }} items={tools} />
<DesignerPanel side="left" variant="floating" width={280} floatingInset={{ left: 60 }}>
{library}
</DesignerPanel>
<DesignerPanel side="right" variant="floating" width={304}>
{inspector}
</DesignerPanel>
<DesignerToolbar boundary="workspace" center="boundary">
{actions}
</DesignerToolbar>
</DesignerWorkspace>To reserve an unobscured canvas between the floating surfaces, configure safe insets and center the toolbar within the same region:
<DesignerWorkspace safeInsets={{ top: 16, right: 336, bottom: 72, left: 376 }}>
<DesignerWorkspaceViewport>{canvas}</DesignerWorkspaceViewport>
<DesignerSidebar variant="floating" items={tools} />
<DesignerPanel side="left" variant="floating" width={280} floatingInset={{ left: 76 }}>
{library}
</DesignerPanel>
<DesignerPanel side="right" variant="floating" width={304}>
{inspector}
</DesignerPanel>
<DesignerToolbar boundary="workspace" center="safe-area">
{actions}
</DesignerToolbar>
</DesignerWorkspace>The existing inline desktop and sheet/bottom mobile variants remain available.
Inspector grid
<DesignerPropertyRow layout="grid"> is the Figma inspector row: two equal
field columns plus a fixed action column (24px in compact density, 32px in
default), with the label spanning the row above the fields. Every grid row
keeps the action column, so field edges line up down the panel whether or not
a row has an action.
- Children (or the children of a
DesignerPropertyControls) fill columns 1 and 2 and stretch to their cell. A row's only field spans both columns. <DesignerPropertyField span={2}>(ordata-span="2") spans both columns;span={1}keeps a lone field in column 1. A field can hold several controls.action, and any icon-onlyButtonchild, sit centred in the action column.
<DesignerPaneTitle muted> is for an empty or optional section: a muted,
normal-weight title next to an action such as a "+" button. In compact
density the title is flush with the field labels and the collapse chevron
trails the actions.
<DesignerPane collapsible>
<DesignerPaneTitle>Position</DesignerPaneTitle>
<DesignerPaneContent>
<DesignerPropertyRow layout="grid" label="Position" action={constraintsButton}>
<InputNumber label="X" value={x} onChange={setX} />
<InputNumber label="Y" value={y} onChange={setY} />
</DesignerPropertyRow>
<DesignerPropertyRow layout="grid" label="Rotation">
<InputNumber label={<RotateCw />} aria-label="Rotation" unit="°" value={r} onChange={setR} />
<DesignerPropertyField className="gap-0.5">
{flipHorizontalButton}
{flipVerticalButton}
</DesignerPropertyField>
<Button size="icon-sm" variant="ghost" aria-label="Rotate 90°">
<RotateCwSquare />
</Button>
</DesignerPropertyRow>
</DesignerPaneContent>
</DesignerPane>
<DesignerPane>
<DesignerPaneTitle muted action={addFillButton}>
Fill
</DesignerPaneTitle>
</DesignerPane>Header actions
DesignerHeader takes a structured action cluster at its inline end. The
primary action is never cut off; secondary actions show inline on wide headers
(up to maxVisibleSecondaryActions, default 2) and collapse into a "More
actions" menu otherwise. Free-form right content renders before them and is
clipped first.
<DesignerHeader
left={<ProjectName />}
center={<ModeSwitcher />}
right={<Presence />}
primaryAction={{ label: "Publish", onAction: publish, loading: publishing }}
secondaryActions={[
{ label: "Preview", href: previewUrl },
{ label: "Share", onAction: share },
{ label: "Version history", onAction: openHistory },
]}
/>Font picker
<FontPicker
aria-label="Heading font"
fonts={[{ family: "Inter", category: "sans-serif", weights: [400, 700] }, …]}
value={settings.headingFont}
onChange={(family) => update({ headingFont: family })}
// Load faces lazily as options scroll into view (e.g. a Google Fonts <link>).
onLoadFont={(font) => loadGoogleFont(font.family)}
/>Each option previews its family with a "Family", <generic> stack, so it
renders in the category's generic face until the font has loaded. Under a
strict CSP, load fonts with <link rel="stylesheet"> or the FontFace API
(style-src must allow the font CSS origin).
Search matches family names (case-insensitive substring, in the order of
fonts), so "play" finds "Playfair Display" but not every display font. A
query that names a category exactly ("serif", "display", "sans serif") also
lists that category's other fonts, after the name matches.
Hooks
useShellContext()/<ShellProvider>— selection, active tool, read-only flaguseHistory<T>(initial, options?)— generic undo/redo stackuseKeybindings(bindings, options?)— keyboard shortcut registry
useHistory
const history = useHistory<Doc>(initialDoc, { limit: 100 });
history.setState(next); // records one undo step
history.replaceState(next); // overwrites without recording
const prev = history.undo(); // returns the new present state synchronously
const next = history.redo();
// Group a gesture (e.g. a drag) into a single undo step:
history.beginTransaction();
history.setState(a); // folded into the transaction
history.setState(b);
history.commitTransaction(); // one entry; or cancelTransaction() to revertlimit caps the undo depth (default 100; oldest entries are dropped). Transactions nest; only the outermost commit records. undo / redo commit an open transaction first. getState() reads the latest state from event handlers.
useKeybindings
useKeybindings([
{ key: "z", code: "KeyZ", mod: "platform", action: undo },
{ key: "z", code: "KeyZ", mod: "platform", shift: true, action: redo },
{ key: "delete", action: remove },
{ key: "s", mod: "platform", allowInInputs: true, action: save },
]);keymatchesKeyboardEvent.key(case-insensitive);codematches the physicalKeyboardEvent.code(layout-independent). Either one matching is enough.mod: "platform"means Cmd on macOS/iOS and Ctrl elsewhere.mod: trueaccepts either Ctrl or Cmd.ctrl,meta,shiftandaltmust match exactly.- Bindings are skipped while focus is in an input, textarea, select or contentEditable element unless the binding sets
allowInInputs: true(skipInputs: falsestill works). - The first matching binding wins and
preventDefault()is called unlesspreventDefault: false. - Bindings are read through a ref, so an inline array doesn't re-subscribe the listener on each render. Options:
disabled,target(defaultwindow),platform("apple"/"other", default detected).
