@pascal-app/editor 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -0
- package/package.json +40 -38
- package/src/components/editor/__bench__/room-label-placement.bench.ts +108 -0
- package/src/components/editor/bake-thumbnail.tsx +6 -15
- package/src/components/editor/construction-reveal-audio.test.tsx +150 -0
- package/src/components/editor/construction-reveal-audio.tsx +40 -0
- package/src/components/editor/custom-camera-controls.tsx +81 -8
- package/src/components/editor/editor-layout-mobile.tsx +1 -1
- package/src/components/editor/editor-layout-v2.tsx +1 -1
- package/src/components/editor/export-manager.tsx +14 -19
- package/src/components/editor/first-person/build-collider-world.test.ts +269 -0
- package/src/components/editor/first-person/build-collider-world.ts +22 -5
- package/src/components/editor/first-person/ground-holes.test.ts +128 -0
- package/src/components/editor/first-person/ground-holes.ts +130 -0
- package/src/components/editor/first-person/mechanism-targets.test.ts +89 -2
- package/src/components/editor/first-person/mechanism-targets.ts +52 -0
- package/src/components/editor/first-person-controls.tsx +19 -11
- package/src/components/editor/floor-aware-camera-controls.test.ts +24 -0
- package/src/components/editor/floorplan-mode-coordinator.tsx +2 -2
- package/src/components/editor/floorplan-panel.tsx +72 -23
- package/src/components/editor/follow-pascal.test.tsx +912 -0
- package/src/components/editor/follow-pascal.tsx +354 -0
- package/src/components/editor/group-actions.ts +2 -0
- package/src/components/editor/group-move-3d.ts +2 -0
- package/src/components/editor/group-rotate-handle.tsx +2 -0
- package/src/components/editor/group-transform-shared.test.ts +460 -0
- package/src/components/editor/index.tsx +166 -79
- package/src/components/editor/riser-diagram-panel.tsx +14 -7
- package/src/components/editor/room-highlight.tsx +13 -5
- package/src/components/editor/room-labels.test.ts +621 -128
- package/src/components/editor/room-labels.tsx +1090 -190
- package/src/components/editor/selection-manager.tsx +38 -117
- package/src/components/editor/slab-hole-highlights.tsx +2 -2
- package/src/components/editor/snapshot-capture-overlay.tsx +3 -2
- package/src/components/editor/snapshot-capture.test.ts +69 -58
- package/src/components/editor/snapshot-capture.ts +7 -1
- package/src/components/editor/thumbnail-generator.test.ts +350 -4
- package/src/components/editor/thumbnail-generator.tsx +128 -54
- package/src/components/editor/use-floorplan-background-placement.ts +3 -1
- package/src/components/editor/views/plugins-view.tsx +1 -8
- package/src/components/editor/views/view-bar.test.tsx +54 -0
- package/src/components/editor/views/view-bar.tsx +140 -17
- package/src/components/editor/wall-snap-beacon-layer.tsx +5 -4
- package/src/components/editor-2d/floorplan-group-move.tsx +3 -0
- package/src/components/editor-2d/floorplan-registered-tool-layer.tsx +2 -2
- package/src/components/editor-2d/floorplan-registry-move-overlay.tsx +3 -4
- package/src/components/editor-2d/renderers/floorplan-dimension-edit-overlay.test.ts +1 -1
- package/src/components/editor-2d/renderers/floorplan-registry-layer.tsx +29 -7
- package/src/components/editor-2d/renderers/floorplan-reveal.test.tsx +254 -0
- package/src/components/editor-2d/renderers/floorplan-reveal.ts +141 -0
- package/src/components/point-ask/bubble.tsx +538 -0
- package/src/components/point-ask/hover-chip.tsx +91 -0
- package/src/components/point-ask/mode-pill.tsx +92 -0
- package/src/components/point-ask/optional-motion.ts +22 -0
- package/src/components/point-ask/outline-corners.tsx +93 -0
- package/src/components/point-ask/pins.tsx +711 -0
- package/src/components/point-ask/point-ask-layer.tsx +83 -0
- package/src/components/point-ask/point-ask-styles.ts +105 -0
- package/src/components/point-ask/region-marquee-styles.ts +15 -0
- package/src/components/point-ask/region-marquee.tsx +64 -0
- package/src/components/systems/ceiling/ceiling-bracket-batch.test.ts +12 -2
- package/src/components/systems/roof/roof-edit-system.tsx +1 -0
- package/src/components/tools/distribution/connection-compatibility.test.ts +34 -0
- package/src/components/tools/distribution/connection-compatibility.ts +43 -0
- package/src/components/tools/distribution/distribution-public.ts +9 -0
- package/src/components/tools/distribution/distribution-run-contract.test.ts +26 -0
- package/src/components/tools/distribution/distribution-run-contract.ts +94 -0
- package/src/components/tools/distribution/distribution-run-tool.test.ts +241 -0
- package/src/components/tools/distribution/distribution-run-tool.test.tsx +125 -0
- package/src/components/tools/distribution/distribution-run-tool.tsx +1323 -0
- package/src/components/tools/distribution/draw-alignment.ts +35 -0
- package/src/components/tools/distribution/ports.test.ts +56 -0
- package/src/components/tools/distribution/ports.ts +378 -0
- package/src/components/tools/distribution/run-cursor.test.ts +135 -0
- package/src/components/tools/distribution/run-cursor.ts +36 -0
- package/src/components/tools/distribution/run-direction-feedback.test.ts +60 -0
- package/src/components/tools/distribution/run-direction-feedback.tsx +251 -0
- package/src/components/tools/distribution/run-port-snap.test.ts +79 -0
- package/src/components/tools/distribution/run-port-snap.ts +25 -0
- package/src/components/tools/distribution/run-screen-direction.test.ts +23 -0
- package/src/components/tools/distribution/run-screen-direction.ts +30 -0
- package/src/components/tools/elevator/elevator-tool.tsx +3 -6
- package/src/components/tools/elevator/move-elevator-tool.tsx +2 -3
- package/src/components/tools/item/item-surface-strategy-resolver.test.ts +67 -68
- package/src/components/tools/item/placement-history.test.tsx +38 -0
- package/src/components/tools/item/placement-strategies.test.ts +46 -1
- package/src/components/tools/item/placement-strategies.ts +3 -6
- package/src/components/tools/item/shelf-surface-strategy-resolver.test.ts +56 -56
- package/src/components/tools/item/use-draft-node.test.tsx +94 -94
- package/src/components/tools/item/use-placement-coordinator.tsx +55 -49
- package/src/components/tools/registry/item-surface-move.test.ts +62 -63
- package/src/components/tools/registry/item-surface-move.ts +2 -0
- package/src/components/tools/registry/item-surface-resolver.test.ts +26 -26
- package/src/components/tools/registry/move-registry-node-tool.test.ts +268 -1
- package/src/components/tools/registry/move-registry-node-tool.tsx +63 -29
- package/src/components/tools/tool-manager.tsx +14 -5
- package/src/components/tools/wall/wall-drafting.test.ts +170 -57
- package/src/components/ui/action-menu/action-button.tsx +6 -1
- package/src/components/ui/action-menu/camera-actions.tsx +7 -3
- package/src/components/ui/action-menu/control-modes.tsx +13 -7
- package/src/components/ui/action-menu/follow-pascal-pill.tsx +32 -0
- package/src/components/ui/action-menu/follow-pascal-toggle.tsx +36 -0
- package/src/components/ui/action-menu/index.tsx +56 -33
- package/src/components/ui/action-menu/measurement-control.tsx +11 -9
- package/src/components/ui/action-menu/placement.ts +20 -0
- package/src/components/ui/action-menu/point-ask-button.tsx +52 -0
- package/src/components/ui/action-menu/view-toggles.tsx +47 -42
- package/src/components/ui/build-panel/build-panel.tsx +10 -3
- package/src/components/ui/command-palette/editor-commands.tsx +3 -12
- package/src/components/ui/command-palette/index.tsx +45 -15
- package/src/components/ui/command-palette/ranked-groups.test.ts +31 -0
- package/src/components/ui/controls/action-button.tsx +5 -2
- package/src/components/ui/controls/metric-control.tsx +1 -1
- package/src/components/ui/controls/segmented-control.tsx +21 -8
- package/src/components/ui/controls/select-control.tsx +1 -1
- package/src/components/ui/controls/slider-control.tsx +1 -1
- package/src/components/ui/controls/toggle-control.tsx +3 -3
- package/src/components/ui/controls/tool-options-panel.tsx +1 -1
- package/src/components/ui/floating-level-selector.tsx +150 -45
- package/src/components/ui/helpers/contextual-helper-panel.tsx +32 -7
- package/src/components/ui/helpers/helper-manager.test.tsx +54 -2
- package/src/components/ui/helpers/helper-manager.tsx +7 -1
- package/src/components/ui/helpers/item-helper.tsx +9 -1
- package/src/components/ui/panels/collections/collections-popover.tsx +8 -8
- package/src/components/ui/panels/mobile-panel-sheet.tsx +2 -2
- package/src/components/ui/panels/mobile-selection-bar.tsx +6 -3
- package/src/components/ui/panels/multi-selection-panel.tsx +120 -3
- package/src/components/ui/panels/panel-wrapper.tsx +53 -27
- package/src/components/ui/panels/parametric-field-control.tsx +2 -2
- package/src/components/ui/panels/parametric-inspector.tsx +3 -3
- package/src/components/ui/panels/room-panel.tsx +65 -0
- package/src/components/ui/primitives/badge.tsx +8 -0
- package/src/components/ui/primitives/sidebar.tsx +1 -1
- package/src/components/ui/right-stack.tsx +21 -2
- package/src/components/ui/sidebar/app-sidebar.tsx +1 -1
- package/src/components/ui/sidebar/icon-rail.tsx +3 -3
- package/src/components/ui/sidebar/panels/items-panel/function-tree-panel.tsx +1 -1
- package/src/components/ui/sidebar/panels/items-panel/index.tsx +6 -6
- package/src/components/ui/sidebar/panels/settings-panel/animation-speed-setting.tsx +40 -0
- package/src/components/ui/sidebar/panels/settings-panel/audio-settings-dialog.tsx +7 -8
- package/src/components/ui/sidebar/panels/settings-panel/construction-animation-setting.test.tsx +170 -0
- package/src/components/ui/sidebar/panels/settings-panel/construction-animation-setting.tsx +92 -0
- package/src/components/ui/sidebar/panels/settings-panel/index.tsx +107 -23
- package/src/components/ui/sidebar/panels/settings-panel/interface-theme.test.tsx +20 -0
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.tsx +4 -10
- package/src/components/ui/sidebar/panels/site-panel/building-tree-node.tsx +3 -11
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +5 -12
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +13 -10
- package/src/components/ui/sidebar/panels/zone-panel/index.tsx +2 -2
- package/src/components/ui/sidebar/tab-bar.tsx +4 -4
- package/src/components/viewer/viewer-controls-bar.tsx +18 -6
- package/src/components/viewer/viewer-rooms.tsx +16 -0
- package/src/hooks/use-auto-save.integration.test.tsx +96 -38
- package/src/hooks/use-auto-save.ts +26 -1
- package/src/hooks/use-ceiling-events.test.ts +123 -118
- package/src/hooks/use-grid-events.test.ts +105 -105
- package/src/hooks/use-keyboard.test.ts +65 -16
- package/src/hooks/use-keyboard.ts +29 -12
- package/src/hooks/use-placement-notice.test.ts +24 -1
- package/src/hooks/use-placement-notice.ts +37 -6
- package/src/index.tsx +71 -24
- package/src/lib/__fixtures__/owner-victor-seattle-parking.json +1 -0
- package/src/lib/__fixtures__/owner-villa-aurelia-basement.json +1 -0
- package/src/lib/add-storey.test.ts +177 -0
- package/src/lib/add-storey.ts +59 -0
- package/src/lib/below-grade.test.tsx +171 -0
- package/src/lib/below-grade.ts +133 -0
- package/src/lib/camera-facing.test.ts +24 -0
- package/src/lib/camera-facing.ts +24 -0
- package/src/lib/direct-manipulation.ts +2 -0
- package/src/lib/download-project-file.ts +17 -0
- package/src/lib/editor-level-display.ts +9 -2
- package/src/lib/editor-views.ts +35 -1
- package/src/lib/export-texture-utils.ts +2 -4
- package/src/lib/floor-foundation-support.test.ts +1 -0
- package/src/lib/floorplan/floorplan-pdfkit-document.ts +31 -16
- package/src/lib/floorplan/floorplan-pdfkit-renderer.test.ts +39 -0
- package/src/lib/floorplan/floorplan-pdfkit-renderer.ts +4 -0
- package/src/lib/floorplan/pdfkit-standard-fonts.d.ts +5 -0
- package/src/lib/floorplan/sheet-export.test.ts +24 -0
- package/src/lib/floorplan/site-plan/build-site-plan-drawing.ts +34 -45
- package/src/lib/floorplan/site-plan/coverage.ts +2 -4
- package/src/lib/floorplan/site-plan/front-edge.ts +2 -1
- package/src/lib/floorplan/site-plan/geometry.test.ts +9 -15
- package/src/lib/floorplan/site-plan/geometry.ts +1 -416
- package/src/lib/floorplan/site-plan/index.ts +0 -16
- package/src/lib/floorplan/site-plan/site-annotations.test.ts +117 -0
- package/src/lib/floorplan/site-plan/site-annotations.ts +3 -2
- package/src/lib/floorplan/site-plan/site-parts.ts +14 -106
- package/src/lib/floorplan/site-plan/yards.test.ts +2 -1
- package/src/lib/follow-pascal-exterior.test-fixture.ts +17 -0
- package/src/lib/follow-pascal-exterior.test.ts +171 -0
- package/src/lib/follow-pascal-exterior.ts +39 -0
- package/src/lib/follow-pascal-presentation.test.ts +203 -0
- package/src/lib/follow-pascal-presentation.ts +129 -0
- package/src/lib/follow-pascal-sight.ts +84 -0
- package/src/lib/follow-pascal-targets.test.ts +406 -0
- package/src/lib/follow-pascal-targets.ts +198 -0
- package/src/lib/follow-pascal.test.ts +350 -0
- package/src/lib/follow-pascal.ts +284 -0
- package/src/lib/fresh-planar-placement.test.ts +112 -0
- package/src/lib/fresh-planar-placement.ts +57 -3
- package/src/lib/geometry-script/author.ts +6 -1
- package/src/lib/geometry-script/client.ts +8 -1
- package/src/lib/geometry-script/finish-scripts.ts +127 -0
- package/src/lib/geometry-script/protocol.ts +1 -0
- package/src/lib/glb-export.test.ts +187 -162
- package/src/lib/glb-export.ts +4 -1
- package/src/lib/history.test.ts +12 -7
- package/src/lib/interaction/scope.ts +4 -0
- package/src/lib/level-selection.test.ts +57 -0
- package/src/lib/level-selection.ts +16 -1
- package/src/lib/lot/clean-ring.test.ts +2 -1
- package/src/lib/lot/drop-in.ts +9 -24
- package/src/lib/lot/lot-patch.test.ts +1 -1
- package/src/lib/lot/lot-patch.ts +2 -2
- package/src/lib/measurement-kind.test.ts +6 -8
- package/src/lib/measurements.test.ts +23 -0
- package/src/lib/orbit-floor-clearance.test.ts +36 -0
- package/src/lib/orbit-floor-clearance.ts +48 -0
- package/src/lib/paint-pass-through.test.ts +11 -0
- package/src/lib/paint-pass-through.ts +4 -2
- package/src/lib/paint-scope.ts +1 -0
- package/src/lib/parametric-node-update.ts +16 -7
- package/src/lib/plugin-chat.ts +15 -0
- package/src/lib/point-ask/__fixtures__/consumer-browser.tsx +76 -0
- package/src/lib/point-ask/__fixtures__/house.ts +81 -0
- package/src/lib/point-ask/ask-created.test.ts +195 -0
- package/src/lib/point-ask/ask-flow.test.ts +380 -0
- package/src/lib/point-ask/build-context.test.ts +173 -0
- package/src/lib/point-ask/build-context.ts +94 -0
- package/src/lib/point-ask/capture-crop.ts +129 -0
- package/src/lib/point-ask/choreography.ts +69 -0
- package/src/lib/point-ask/compare.test.ts +145 -0
- package/src/lib/point-ask/compare.ts +73 -0
- package/src/lib/point-ask/describe-target.test.ts +165 -0
- package/src/lib/point-ask/describe-target.ts +234 -0
- package/src/lib/point-ask/dictation.ts +79 -0
- package/src/lib/point-ask/edge-marker.test.ts +61 -0
- package/src/lib/point-ask/edge-marker.ts +27 -0
- package/src/lib/point-ask/frame-loop.ts +25 -0
- package/src/lib/point-ask/history-marks.test.ts +94 -0
- package/src/lib/point-ask/history-marks.ts +39 -0
- package/src/lib/point-ask/host-api.ts +32 -0
- package/src/lib/point-ask/outline-box.test.ts +30 -0
- package/src/lib/point-ask/outline-box.ts +11 -0
- package/src/lib/point-ask/overlay-metrics.ts +6 -0
- package/src/lib/point-ask/pick.test.ts +220 -0
- package/src/lib/point-ask/pick.ts +121 -0
- package/src/lib/point-ask/pin-machine.test.ts +494 -0
- package/src/lib/point-ask/pin-machine.ts +217 -0
- package/src/lib/point-ask/placement.test.ts +203 -0
- package/src/lib/point-ask/placement.ts +141 -0
- package/src/lib/point-ask/pointer-tracker.ts +34 -0
- package/src/lib/point-ask/projector.ts +83 -0
- package/src/lib/point-ask/region.test.ts +157 -0
- package/src/lib/point-ask/region.ts +136 -0
- package/src/lib/point-ask/retry.test.ts +217 -0
- package/src/lib/point-ask/retry.ts +37 -0
- package/src/lib/point-ask/scene-commit.test.ts +312 -0
- package/src/lib/point-ask/scene-commit.ts +32 -0
- package/src/lib/point-ask/session.ts +1391 -0
- package/src/lib/point-ask/spring-keyframes.test.ts +45 -0
- package/src/lib/point-ask/spring-keyframes.ts +38 -0
- package/src/lib/point-ask/spring.test.ts +63 -0
- package/src/lib/point-ask/spring.ts +107 -0
- package/src/lib/point-ask/suggestions.test.ts +80 -0
- package/src/lib/point-ask/suggestions.ts +125 -0
- package/src/lib/point-ask/target-scope.test.ts +622 -0
- package/src/lib/point-ask/target-scope.ts +338 -0
- package/src/lib/point-ask/types.ts +48 -0
- package/src/lib/portable-export.test.ts +34 -1
- package/src/lib/portable-export.ts +119 -53
- package/src/lib/print-feature-thickness.ts +10 -1
- package/src/lib/print-roof-solids.test.ts +39 -1
- package/src/lib/print-roof-solids.ts +43 -10
- package/src/lib/print-shell-compiler-manifold-core.ts +1 -1
- package/src/lib/room-assembly-overlay.ts +2 -3
- package/src/lib/room-selection.test.ts +45 -1
- package/src/lib/scene-clipboard.test.ts +246 -1
- package/src/lib/scene-clipboard.ts +44 -14
- package/src/lib/selection-routing.ts +1 -1
- package/src/lib/sfx-bus.ts +13 -0
- package/src/lib/sfx-player.test.ts +70 -9
- package/src/lib/sfx-player.ts +6 -0
- package/src/lib/stair-levels.test.ts +25 -0
- package/src/lib/stair-levels.ts +22 -3
- package/src/lib/terrace-draft.ts +2 -1
- package/src/lib/viewer-selection.ts +22 -11
- package/src/lib/wall-placement-pointer.test.ts +42 -0
- package/src/lib/wall-placement-pointer.ts +57 -0
- package/src/lib/window-changes.ts +35 -0
- package/src/store/use-audio.test.ts +146 -0
- package/src/store/use-audio.tsx +127 -3
- package/src/store/use-construction-reveal.test.ts +173 -0
- package/src/store/use-construction-reveal.ts +145 -0
- package/src/store/use-corner-snap-hint.test.ts +24 -0
- package/src/store/use-corner-snap-hint.ts +47 -0
- package/src/store/use-follow-pascal.test.ts +62 -0
- package/src/store/use-follow-pascal.ts +53 -0
- package/src/store/use-point-ask.ts +247 -0
- package/src/store/use-stair-build-preview.ts +25 -5
- package/src/store/view-layout.test.ts +27 -1
- package/src/store/view-layout.ts +4 -1
- package/src/test-utils/render-current-markup.tsx +16 -0
- package/src/components/tools/stair/stair-click-guard.test.ts +0 -58
- package/src/components/tools/stair/stair-click-guard.ts +0 -72
- package/src/components/tools/stair/stair-defaults.ts +0 -15
- package/src/components/tools/stair/stair-tool.tsx +0 -682
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
type AnyNode,
|
|
4
|
+
type AnyNodeId,
|
|
5
|
+
applyScenePatch,
|
|
6
|
+
applySceneSnapshot,
|
|
7
|
+
BuildingNode,
|
|
8
|
+
clearSceneHistory,
|
|
9
|
+
ItemNode,
|
|
10
|
+
LevelNode,
|
|
11
|
+
type SceneCommit,
|
|
12
|
+
SceneMaterial,
|
|
13
|
+
type SceneSnapshot,
|
|
14
|
+
subscribeSceneCommits,
|
|
15
|
+
useScene,
|
|
16
|
+
ZoneNode,
|
|
17
|
+
} from '@pascal-app/core'
|
|
18
|
+
import { markHistory, stepsSince } from './history-marks'
|
|
19
|
+
import { createPin, type PinModel, reducePin } from './pin-machine'
|
|
20
|
+
import { pointCommitEvent } from './scene-commit'
|
|
21
|
+
|
|
22
|
+
function fixture() {
|
|
23
|
+
const building = BuildingNode.parse({})
|
|
24
|
+
const level = LevelNode.parse({ parentId: building.id })
|
|
25
|
+
const room = ZoneNode.parse({
|
|
26
|
+
parentId: level.id,
|
|
27
|
+
name: 'Kitchen',
|
|
28
|
+
polygon: [
|
|
29
|
+
[0, 0],
|
|
30
|
+
[4, 0],
|
|
31
|
+
[4, 4],
|
|
32
|
+
[0, 4],
|
|
33
|
+
],
|
|
34
|
+
})
|
|
35
|
+
const item = (position: [number, number, number]) =>
|
|
36
|
+
ItemNode.parse({
|
|
37
|
+
parentId: level.id,
|
|
38
|
+
position,
|
|
39
|
+
asset: {
|
|
40
|
+
id: 'fixture',
|
|
41
|
+
name: 'Fridge',
|
|
42
|
+
category: 'furniture',
|
|
43
|
+
thumbnail: '',
|
|
44
|
+
src: 'https://example.invalid/fridge.glb',
|
|
45
|
+
dimensions: [1, 1, 1],
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
const fridge = item([2, 0, 2])
|
|
49
|
+
const outside = item([8, 0, 2])
|
|
50
|
+
building.children = [level.id]
|
|
51
|
+
level.children = [room.id, fridge.id, outside.id]
|
|
52
|
+
const snapshot: SceneSnapshot = {
|
|
53
|
+
nodes: {
|
|
54
|
+
[building.id]: building,
|
|
55
|
+
[level.id]: level,
|
|
56
|
+
[room.id]: room,
|
|
57
|
+
[fridge.id]: fridge,
|
|
58
|
+
[outside.id]: outside,
|
|
59
|
+
},
|
|
60
|
+
rootNodeIds: [building.id],
|
|
61
|
+
collections: {},
|
|
62
|
+
materials: {},
|
|
63
|
+
installedPlugins: [],
|
|
64
|
+
hasExplicitPluginInstallState: false,
|
|
65
|
+
}
|
|
66
|
+
return { snapshot, room, fridge, outside }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const beginPin = (target: string): PinModel =>
|
|
70
|
+
reducePin(createPin({ askId: 'ask_scope', text: 'Move the fridge', targetIds: [target] }), {
|
|
71
|
+
type: 'status',
|
|
72
|
+
status: { askId: 'ask_scope', status: 'working' },
|
|
73
|
+
})
|
|
74
|
+
const finishPin = (
|
|
75
|
+
pin: PinModel,
|
|
76
|
+
wroteScene = true,
|
|
77
|
+
outcome: 'completed' | 'cancelled' | 'errored' = 'completed',
|
|
78
|
+
) =>
|
|
79
|
+
reducePin(pin, {
|
|
80
|
+
type: 'status',
|
|
81
|
+
status: { askId: pin.askId, status: 'ended', outcome, asked: false, wroteScene },
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const original = useScene.getState()
|
|
85
|
+
const originalRaf = globalThis.requestAnimationFrame
|
|
86
|
+
const originalCancelRaf = globalThis.cancelAnimationFrame
|
|
87
|
+
let unsubscribe = () => {}
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
90
|
+
callback(0)
|
|
91
|
+
return 0
|
|
92
|
+
}
|
|
93
|
+
globalThis.cancelAnimationFrame = () => {}
|
|
94
|
+
})
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
unsubscribe()
|
|
97
|
+
unsubscribe = () => {}
|
|
98
|
+
useScene.setState(original)
|
|
99
|
+
clearSceneHistory()
|
|
100
|
+
if (originalRaf) globalThis.requestAnimationFrame = originalRaf
|
|
101
|
+
else Reflect.deleteProperty(globalThis, 'requestAnimationFrame')
|
|
102
|
+
if (originalCancelRaf) globalThis.cancelAnimationFrame = originalCancelRaf
|
|
103
|
+
else Reflect.deleteProperty(globalThis, 'cancelAnimationFrame')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
function watch(snapshot: SceneSnapshot, target: string) {
|
|
107
|
+
useScene.setState({ ...snapshot, dirtyNodes: new Set<AnyNodeId>(), readOnly: false })
|
|
108
|
+
clearSceneHistory()
|
|
109
|
+
let pin = beginPin(target)
|
|
110
|
+
const commits: SceneCommit[] = []
|
|
111
|
+
const events: ReturnType<typeof pointCommitEvent>[] = []
|
|
112
|
+
unsubscribe = subscribeSceneCommits((commit) => {
|
|
113
|
+
commits.push(commit)
|
|
114
|
+
const event = pointCommitEvent(commit, [target])
|
|
115
|
+
events.push(event)
|
|
116
|
+
if (event) pin = reducePin(pin, event)
|
|
117
|
+
})
|
|
118
|
+
return {
|
|
119
|
+
commits,
|
|
120
|
+
events,
|
|
121
|
+
pin: () => pin,
|
|
122
|
+
mark: markHistory(useScene.temporal.getState().pastStates),
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
describe('Point commits through the real scene authority and history', () => {
|
|
127
|
+
// A read-only ask is not a read-only scene: foreign edits really land, but belong
|
|
128
|
+
// to neither this turn's local-write flag nor its Undo history.
|
|
129
|
+
for (const origin of ['host', 'load'] as const) {
|
|
130
|
+
test(`${origin} writes during a read-only ask do not claim a local edit or Undo`, () => {
|
|
131
|
+
const f = fixture()
|
|
132
|
+
const observed = watch(f.snapshot, f.room.id)
|
|
133
|
+
const working = observed.pin()
|
|
134
|
+
const applied =
|
|
135
|
+
origin === 'host'
|
|
136
|
+
? applyScenePatch({
|
|
137
|
+
materialChanges: [],
|
|
138
|
+
nodeUpdates: [{ id: f.fridge.id, data: { position: [3, 0, 2] }, removeFields: [] }],
|
|
139
|
+
})
|
|
140
|
+
: applySceneSnapshot(
|
|
141
|
+
{
|
|
142
|
+
...f.snapshot,
|
|
143
|
+
nodes: {
|
|
144
|
+
...f.snapshot.nodes,
|
|
145
|
+
[f.fridge.id]: { ...f.fridge, position: [3, 0, 2] },
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{ origin: 'load' },
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
expect(applied).toBe(true)
|
|
152
|
+
expect((useScene.getState().nodes[f.fridge.id] as typeof f.fridge).position).toEqual([
|
|
153
|
+
3, 0, 2,
|
|
154
|
+
])
|
|
155
|
+
expect(observed.commits.map((commit) => commit.origin)).toEqual([origin])
|
|
156
|
+
expect(observed.events).toEqual([null])
|
|
157
|
+
expect(observed.pin()).toBe(working)
|
|
158
|
+
expect(observed.pin().state).toBe('working')
|
|
159
|
+
expect(observed.pin().committed).toBe(false)
|
|
160
|
+
expect(observed.pin().landed).toBe(0)
|
|
161
|
+
expect(observed.pin().changedTargetIds).toEqual([])
|
|
162
|
+
expect(observed.pin().alsoChangedIds).toEqual([])
|
|
163
|
+
expect(finishPin(observed.pin(), false).state).toBe('no-change')
|
|
164
|
+
expect(finishPin(observed.pin(), false, 'cancelled').state).toBe('no-change')
|
|
165
|
+
expect(finishPin(observed.pin(), false, 'errored').state).toBe('error')
|
|
166
|
+
expect(stepsSince(useScene.temporal.getState().pastStates, observed.mark)).toBe(0)
|
|
167
|
+
expect(useScene.temporal.getState().pastStates).toHaveLength(0)
|
|
168
|
+
expect(useScene.temporal.getState().futureStates).toHaveLength(0)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
test('ignoring a host write does not suppress the next local write or undo the foreign edit', () => {
|
|
173
|
+
const f = fixture()
|
|
174
|
+
const observed = watch(f.snapshot, f.room.id)
|
|
175
|
+
expect(
|
|
176
|
+
applyScenePatch({
|
|
177
|
+
materialChanges: [],
|
|
178
|
+
nodeUpdates: [{ id: f.outside.id, data: { position: [9, 0, 2] }, removeFields: [] }],
|
|
179
|
+
}),
|
|
180
|
+
).toBe(true)
|
|
181
|
+
useScene.getState().updateNode(f.fridge.id, { position: [3, 0, 2] })
|
|
182
|
+
|
|
183
|
+
const pin = finishPin(observed.pin(), false)
|
|
184
|
+
expect(observed.commits.map((commit) => commit.origin)).toEqual(['host', 'local'])
|
|
185
|
+
expect(observed.events[0]).toBeNull()
|
|
186
|
+
expect(pin.state).toBe('done')
|
|
187
|
+
expect(pin.committed).toBe(true)
|
|
188
|
+
expect(pin.landed).toBe(1)
|
|
189
|
+
expect(pin.changedTargetIds).toEqual([f.fridge.id])
|
|
190
|
+
expect(pin.alsoChangedIds).toEqual([])
|
|
191
|
+
const steps = stepsSince(useScene.temporal.getState().pastStates, observed.mark)
|
|
192
|
+
expect(steps).toBe(1)
|
|
193
|
+
useScene.temporal.getState().undo(steps!)
|
|
194
|
+
expect((useScene.getState().nodes[f.fridge.id] as typeof f.fridge).position).toEqual([2, 0, 2])
|
|
195
|
+
expect((useScene.getState().nodes[f.outside.id] as typeof f.outside).position).toEqual([
|
|
196
|
+
9, 0, 2,
|
|
197
|
+
])
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
// Actual store mutations, commit bus, reducer and temporal Undo. The host's
|
|
201
|
+
// wroteScene hint is deliberately false: observed local writes are authoritative.
|
|
202
|
+
for (const kind of ['inside', 'outside', 'collection', 'material'] as const) {
|
|
203
|
+
for (const outcome of ['completed', 'cancelled', 'errored'] as const) {
|
|
204
|
+
test(`${kind} local write remains reversible when the turn is ${outcome}`, () => {
|
|
205
|
+
const f = fixture()
|
|
206
|
+
const observed = watch(f.snapshot, f.room.id)
|
|
207
|
+
if (kind === 'inside') {
|
|
208
|
+
useScene.getState().updateNode(f.fridge.id, { position: [3, 0, 2] })
|
|
209
|
+
expect((useScene.getState().nodes[f.fridge.id] as typeof f.fridge).position).toEqual([
|
|
210
|
+
3, 0, 2,
|
|
211
|
+
])
|
|
212
|
+
} else if (kind === 'outside') {
|
|
213
|
+
useScene.getState().updateNode(f.outside.id, { position: [9, 0, 2] })
|
|
214
|
+
expect((useScene.getState().nodes[f.outside.id] as typeof f.outside).position).toEqual([
|
|
215
|
+
9, 0, 2,
|
|
216
|
+
])
|
|
217
|
+
} else if (kind === 'collection') {
|
|
218
|
+
const id = useScene.getState().createCollection('Kitchen furniture')
|
|
219
|
+
expect(useScene.getState().collections[id]?.name).toBe('Kitchen furniture')
|
|
220
|
+
} else {
|
|
221
|
+
const material = SceneMaterial.parse({
|
|
222
|
+
id: 'mat_point_finish',
|
|
223
|
+
name: 'Kitchen finish',
|
|
224
|
+
material: { properties: { color: '#336699' } },
|
|
225
|
+
})
|
|
226
|
+
useScene.getState().addSceneMaterial(material)
|
|
227
|
+
expect(useScene.getState().materials.mat_point_finish).toEqual(material)
|
|
228
|
+
}
|
|
229
|
+
const pin = finishPin(observed.pin(), false, outcome)
|
|
230
|
+
|
|
231
|
+
expect(observed.commits.map((commit) => commit.origin)).toEqual(['local'])
|
|
232
|
+
expect(pin.state).toBe(outcome === 'errored' ? 'error' : 'done')
|
|
233
|
+
expect(pin.committed).toBe(true)
|
|
234
|
+
expect(pin.landed).toBe(kind === 'inside' ? 1 : 0)
|
|
235
|
+
expect(pin.changedTargetIds).toEqual(kind === 'inside' ? [f.fridge.id] : [])
|
|
236
|
+
expect(pin.alsoChangedIds).toEqual(kind === 'outside' ? [f.outside.id] : [])
|
|
237
|
+
const steps = stepsSince(useScene.temporal.getState().pastStates, observed.mark)
|
|
238
|
+
expect(steps).toBe(1)
|
|
239
|
+
useScene.temporal.getState().undo(steps!)
|
|
240
|
+
expect(useScene.getState().nodes).toEqual(f.snapshot.nodes)
|
|
241
|
+
expect(useScene.getState().collections).toEqual(f.snapshot.collections)
|
|
242
|
+
expect(useScene.getState().materials).toEqual(f.snapshot.materials)
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
test('a semantically unchanged writing call stays no-change with no history step', () => {
|
|
248
|
+
const f = fixture()
|
|
249
|
+
const observed = watch(f.snapshot, f.room.id)
|
|
250
|
+
|
|
251
|
+
useScene.getState().updateNode(f.fridge.id, { position: [2, 0, 2] })
|
|
252
|
+
|
|
253
|
+
expect(observed.commits).toEqual([])
|
|
254
|
+
expect(finishPin(observed.pin()).state).toBe('no-change')
|
|
255
|
+
expect(stepsSince(useScene.temporal.getState().pastStates, observed.mark)).toBe(0)
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
describe('optional node metadata on a semantic commit', () => {
|
|
260
|
+
test('derives creation and deletion IDs and classifies both snapshots', () => {
|
|
261
|
+
const f = fixture()
|
|
262
|
+
const created = ItemNode.parse({ ...f.fridge, id: 'item_created' })
|
|
263
|
+
const nodes: Record<AnyNodeId, AnyNode> = { ...f.snapshot.nodes, [created.id]: created }
|
|
264
|
+
delete nodes[f.fridge.id]
|
|
265
|
+
const event = pointCommitEvent(
|
|
266
|
+
{
|
|
267
|
+
origin: 'local',
|
|
268
|
+
before: f.snapshot,
|
|
269
|
+
current: { ...f.snapshot, nodes },
|
|
270
|
+
},
|
|
271
|
+
[f.room.id],
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
if (!event) throw new Error('A local semantic commit must produce a Point event')
|
|
275
|
+
expect(new Set(event.changedNodeIds)).toEqual(new Set([f.fridge.id, created.id]))
|
|
276
|
+
expect(event.isInTargets?.(f.fridge.id)).toBe(true)
|
|
277
|
+
expect(event.isInTargets?.(created.id)).toBe(true)
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
test('derives exact changed IDs when node IDs are absent or empty', () => {
|
|
281
|
+
const f = fixture()
|
|
282
|
+
const current: SceneSnapshot = {
|
|
283
|
+
...f.snapshot,
|
|
284
|
+
nodes: { ...f.snapshot.nodes, [f.fridge.id]: { ...f.fridge, position: [8, 0, 2] } },
|
|
285
|
+
}
|
|
286
|
+
for (const changedNodeIds of [undefined, new Set<AnyNodeId>()]) {
|
|
287
|
+
const event = pointCommitEvent(
|
|
288
|
+
{ origin: 'local', before: f.snapshot, current, changedNodeIds },
|
|
289
|
+
[f.room.id],
|
|
290
|
+
)
|
|
291
|
+
if (!event) throw new Error('A local semantic commit must produce a Point event')
|
|
292
|
+
expect(event.changedNodeIds).toEqual([f.fridge.id])
|
|
293
|
+
expect(event.isInTargets?.(f.fridge.id)).toBe(true)
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('does not count semantically equal cloned nodes or reordered keys as changed', () => {
|
|
298
|
+
const f = fixture()
|
|
299
|
+
const nodes: Record<AnyNodeId, AnyNode> = Object.fromEntries(
|
|
300
|
+
Object.entries(f.snapshot.nodes).map(([id, node]) => [
|
|
301
|
+
id,
|
|
302
|
+
Object.fromEntries(Object.entries(structuredClone(node)).reverse()),
|
|
303
|
+
]),
|
|
304
|
+
) as Record<AnyNodeId, AnyNode>
|
|
305
|
+
const current = { ...f.snapshot, nodes, installedPlugins: ['test:plugin'] }
|
|
306
|
+
const event = pointCommitEvent({ origin: 'local', before: f.snapshot, current }, [f.room.id])
|
|
307
|
+
|
|
308
|
+
if (!event) throw new Error('A local semantic commit must produce a Point event')
|
|
309
|
+
expect(event.changedNodeIds).toEqual([])
|
|
310
|
+
expect(finishPin(reducePin(beginPin(f.room.id), event)).state).toBe('done')
|
|
311
|
+
})
|
|
312
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AnyNodeId, areSemanticValuesEqual, type SceneCommit } from '@pascal-app/core'
|
|
2
|
+
import type { PinEvent } from './pin-machine'
|
|
3
|
+
import { pointTargetScope } from './target-scope'
|
|
4
|
+
|
|
5
|
+
/** Node metadata is optional on the commit bus; classify real changes, not fresh equal clones. */
|
|
6
|
+
export function pointCommitEvent(
|
|
7
|
+
commit: SceneCommit,
|
|
8
|
+
targetIds: readonly string[],
|
|
9
|
+
): Extract<PinEvent, { type: 'commit' }> | null {
|
|
10
|
+
// Host/load snapshots do not belong to the local turn or its Undo history.
|
|
11
|
+
if (commit.origin !== 'local') return null
|
|
12
|
+
let changedNodeIds = [...(commit.changedNodeIds ?? [])]
|
|
13
|
+
if (changedNodeIds.length === 0 && commit.before.nodes !== commit.current.nodes) {
|
|
14
|
+
const ids = new Set<AnyNodeId>([
|
|
15
|
+
...(Object.keys(commit.before.nodes) as AnyNodeId[]),
|
|
16
|
+
...(Object.keys(commit.current.nodes) as AnyNodeId[]),
|
|
17
|
+
])
|
|
18
|
+
changedNodeIds = [...ids].filter(
|
|
19
|
+
(id) => !areSemanticValuesEqual(commit.before.nodes[id], commit.current.nodes[id]),
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
const scope =
|
|
23
|
+
changedNodeIds.length > 0
|
|
24
|
+
? pointTargetScope(targetIds, commit.before.nodes, commit.current.nodes)
|
|
25
|
+
: null
|
|
26
|
+
return {
|
|
27
|
+
type: 'commit',
|
|
28
|
+
changedNodeIds,
|
|
29
|
+
committed: true,
|
|
30
|
+
...(scope ? { isInTargets: (id: string) => scope.has(id) } : {}),
|
|
31
|
+
}
|
|
32
|
+
}
|