Built-in design generation now runs as an agentic MCP tool-loop (reusing the agent-rs BuiltInProvider), gated behind OPENPENCIL_DESIGN_AGENT_LOOP / the Settings experimental toggle; the orchestrator stays the default. - design-agent system prompt + in-process design toolset (parity-locked with the MCP surface) + flag-gated Intent::Design routing - spawn_agents execution as sequential sub-loops + live creation-mode badges (per-agent glow + 'N/M designing...' header) - new MCP tools: get_guidelines, ToolSearch, get_screenshot, get_editor_state, export_nodes, spawn_agents; style-guide local audit - #27 AI panel restyle: rounded tool cards + green check-rings, gray user bubbles, model-pill bottom toolbar, header, empty-state pills, the PARALLEL AGENTS (agent_team_size) 1x-6x chip dropdown - multi-chat tabs: ChatSessions model (Deref-to-active) + tab row UI (switch / close / + / Cmd+T) with each run bound to its tab Large checkpoint commit spanning the working tree (Rust shell crates).
4 KiB
4 KiB
pen-react
React UI SDK for OpenPencil -- provider, hooks, panels, toolbar, and property editor components.
Structure
Core
src/context.ts—DesignEngineContext: React context holding theDesignEngineinstancesrc/provider.tsx—DesignProvider: provides engine to React tree. Supports uncontrolled mode (initialDocument) and controlled mode (document+onDocumentChange) with echo-loop prevention
Hooks (src/hooks/)
use-design-engine.ts—useDesignEngine(): gets engine from context, throws if outside provideruse-document.ts—useDocument(): returns currentPenDocument, re-renders on mutationuse-selection.ts—useSelection(): returnsstring[]of selected node IDsuse-viewport.ts—useViewport(): returnsViewportState(zoom, panX, panY)use-active-tool.ts—useActiveTool(): returns currentToolTypeuse-history.ts—useHistory(): returns{ canUndo, canRedo }use-active-node.ts—useActiveNode(): returns the single activePenNodeor nulluse-active-page.ts—useActivePage(): returns active page IDuse-hover.ts—useHover(): returns hovered node IDuse-variables.ts—useVariables(): returns document variables map
Utilities (src/utils/)
use-engine-subscribe.ts—useEngineSubscribe(engine, event, getSnapshot): generic hook usinguseSyncExternalStoreto subscribe to engine events with stable snapshot refs
Stores (src/stores/)
ui-store.ts—useUIStore(Zustand): pure UI state -- panel visibility, layer drag state, collapsed nodes. NOT engine state
Components (src/components/)
design-canvas.tsx—DesignCanvas: canvas element with CanvasKit rendering viaattachCanvas+attachInteractionfrom pen-engine browser adaptercore-toolbar.tsx—CoreToolbar: main tool selection bartool-button.tsx—ToolButton: individual tool button with active stateshape-tool-dropdown.tsx—ShapeToolDropdown: dropdown for shape tools (rectangle, ellipse, line, polygon)layer-panel.tsx—LayerPanel: document tree panel with drag-and-drop reorderinglayer-item.tsx—LayerItem: individual layer row with visibility/lock toggleslayer-context-menu.tsx—LayerContextMenu: right-click context menu for layersproperty-panel.tsx—PropertyPanel: right-side property inspector (delegates to section components)color-picker.tsx—ColorPicker: color input with hex/opacity, gradient supportnumber-input.tsx—NumberInput: numeric input with drag-to-adjustsection-header.tsx—SectionHeader: collapsible section headerfont-picker.tsx—FontPicker: font family selector with searchvariable-picker.tsx—VariablePicker: design variable selectoricon-picker-dialog.tsx—IconPickerDialog: icon search and selectionboolean-toolbar.tsx—BooleanToolbar: union/subtract/intersect boolean operationspage-tabs.tsx—PageTabs: multi-page tab barstatus-bar.tsx—StatusBar: bottom status bar (zoom, selection info)
Property sections (src/components/sections/)
size-section.tsx— Width, height, x, y, rotationfill-section.tsx— Fill array editor (solid, gradient, image)stroke-section.tsx— Stroke properties (thickness, alignment, dash)text-section.tsx— Text content, font, size, weight, styletext-layout-section.tsx— Text alignment, growth modecorner-radius-section.tsx— Corner radius (uniform or per-corner)effects-section.tsx— Blur and shadow effectslayout-section.tsx— Auto-layout direction, gap, alignmentlayout-padding-section.tsx— Padding (uniform or per-side)appearance-section.tsx— Opacity, blend mode, visibilityicon-section.tsx— Icon font name and familyimage-section.tsx— Image source, fit mode, adjustmentsexport-section.tsx— Export format and code preview
Testing
bun --bun vitest run packages/pen-react/src/__tests__/