Files
editor/packages/nodes/src/slab/definition.ts
T
Wassim SAMADandClaude Opus 4.7 b2e5d84986 Phase 5 Stage D slab: port placement + move + boundary/hole editors
Replicates the fence Stage D recipe for slab — three drag affordances
+ one placement tool, all routed through the registry:

  affordanceTools:
    'boundary-edit' → thin <PolygonEditor> wrapper (vertex/edge drag)
    'hole-edit'     → same for a single hole polygon
    move            → DragAction with single-undo dance
  tool: () => placement (multi-click polygon with axis/45° snap)

`PolygonEditor` + `PolygonEditorProps` exported from
`@pascal-app/editor` as Stage D transitional surface (Stage F cleanup
moves them into `@pascal-app/nodes`).

ToolManager mount sites for SlabBoundaryEditor / SlabHoleEditor now
route through `getRegistryAffordanceTool` with legacy fallback.

Slab move action does not use the live-drag exception (polygon CSG
rebuild every tick) — matches legacy behavior; optimization is a
separate task once we measure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 18:27:31 -04:00

94 lines
2.8 KiB
TypeScript

import type { NodeDefinition } from '@pascal-app/core'
import { buildSlabFloorplan } from './floorplan'
import { buildSlabGeometry } from './geometry'
import { slabParametrics } from './parametrics'
import { SlabNode } from './schema'
/**
* Slab — Phase 5 batch kind, polygon-based. Stage B: `def.geometry`
* drives the rebuild via generic <GeometrySystem>; <ParametricNodeRenderer>
* mounts the empty group. No per-kind renderer or system file.
*
* Capabilities:
* - **No `movable`**: slab's "move" today is whole-slab translation via
* legacy `MoveSlabTool`, which integrates with the floor-plan boundary /
* hole editors. Capability-driven dispatch keeps the legacy mover.
* - **`surfaces.top`**: items host on the slab top at `elevation`.
* - `selectable`, `duplicable`, `deletable` standard.
*
* Relations:
* - `hosts: ['item']` — items mount on the slab top.
* - `cascadeDelete: 'descendants'` — deleting a slab removes hosted items.
*/
export const slabDefinition: NodeDefinition<typeof SlabNode> = {
kind: 'slab',
schemaVersion: 1,
schema: SlabNode,
category: 'structure',
defaults: () => ({
object: 'node',
parentId: null,
visible: true,
metadata: {},
polygon: [],
holes: [],
holeMetadata: [],
elevation: 0.05,
autoFromWalls: false,
}),
capabilities: {
selectable: { hitVolume: 'bbox' },
surfaces: {
top: { height: (n) => (n as SlabNode).elevation },
},
duplicable: true,
deletable: true,
},
relations: {
hosts: ['item'],
cascadeDelete: 'descendants',
},
parametrics: slabParametrics,
// Stage D: kind-owned placement tool. Multi-click polygon drawing
// with axis/45° snap (Shift to defeat).
tool: () => import('./tool'),
// Stage D: drag/edit affordances. Boundary editor + hole editor
// delegate to the shared `<PolygonEditor>`; move uses the single-
// undo dance for the polygon-translate commit.
affordanceTools: {
'boundary-edit': () => import('./boundary-editor'),
'hole-edit': () => import('./hole-editor'),
move: () => import('./move-tool'),
},
// Stage B: pure geometry function.
geometry: buildSlabGeometry,
// Stage C: floor-plan rendering. Legacy `slabPolygons` short-circuits
// to [] when slab is registered (see floorplan-panel.tsx).
floorplan: buildSlabFloorplan,
toolHints: [
{ key: 'Left click', label: 'Trace slab outline' },
{ key: 'Enter', label: 'Finish slab' },
{ key: 'Esc', label: 'Cancel' },
],
presentation: {
label: 'Slab',
description: 'A polygon-bounded floor surface that hosts items on top.',
icon: { kind: 'iconify', name: 'lucide:square' },
paletteSection: 'structure',
paletteOrder: 30,
},
mcp: {
description: 'A polygon-bounded slab (floor) with optional cutout holes.',
},
}