@selvajs/ui 5.0.1 → 6.0.0-beta.0
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/dist/components/compute/ComputeApp.svelte +15 -7
- package/dist/components/compute/ComputeApp.svelte.d.ts +1 -1
- package/dist/components/primitives/textarea/textarea.svelte +1 -2
- package/dist/components/viewer/SceneManager.svelte +75 -160
- package/dist/components/viewer/SceneManager.svelte.d.ts +8 -3
- package/dist/components/viewer/Viewer.svelte +20 -3
- package/dist/compute/useSolveSession.svelte.d.ts +12 -0
- package/dist/compute/useSolveSession.svelte.js +76 -0
- package/dist/external/storage.d.ts +1 -15
- package/dist/external/storage.js +4 -54
- package/dist/index.d.ts +4 -3
- package/dist/index.js +7 -4
- package/dist/public.d.ts +4 -3
- package/dist/public.js +9 -5
- package/package.json +5 -3
- package/src/lib/components/compute/ComputeApp.svelte +15 -7
- package/src/lib/components/primitives/textarea/textarea.svelte +1 -2
- package/src/lib/components/viewer/SceneManager.svelte +75 -160
- package/src/lib/components/viewer/Viewer.svelte +20 -3
- package/src/lib/compute/mesh-policy-wiring.test.ts +72 -0
- package/src/lib/compute/useSolveSession.svelte.ts +83 -0
- package/src/lib/external/storage.ts +12 -64
- package/src/lib/index.ts +15 -5
- package/src/lib/public.ts +17 -6
- package/dist/compute/computeThrottle.svelte.d.ts +0 -24
- package/dist/compute/computeThrottle.svelte.js +0 -82
- package/dist/compute/createSolveSession.svelte.d.ts +0 -66
- package/dist/compute/createSolveSession.svelte.js +0 -159
- package/dist/compute/solve-session-core.d.ts +0 -54
- package/dist/compute/solve-session-core.js +0 -87
- package/dist/compute/solveMemo.d.ts +0 -22
- package/dist/compute/solveMemo.js +0 -124
- package/dist/types/solveFn.d.ts +0 -25
- package/dist/types/solveFn.js +0 -1
- package/src/lib/compute/computeThrottle.svelte.ts +0 -109
- package/src/lib/compute/computeThrottle.test.ts +0 -106
- package/src/lib/compute/createSolveSession.svelte.ts +0 -239
- package/src/lib/compute/createSolveSession.test.ts +0 -168
- package/src/lib/compute/solve-session-core.test.ts +0 -153
- package/src/lib/compute/solve-session-core.ts +0 -122
- package/src/lib/compute/solveMemo.test.ts +0 -220
- package/src/lib/compute/solveMemo.ts +0 -140
- package/src/lib/external/storage.test.ts +0 -99
- package/src/lib/types/solveFn.ts +0 -29
package/dist/index.js
CHANGED
|
@@ -15,12 +15,15 @@ export * from './schema/defaults';
|
|
|
15
15
|
export * from './schema/dynamic-value-list';
|
|
16
16
|
export * from './schema/traversal';
|
|
17
17
|
export * from './compute/solving.svelte';
|
|
18
|
-
// Solve Session seam
|
|
19
|
-
//
|
|
18
|
+
// Solve Session seam. The session itself now lives in `@selvajs/solve/client`
|
|
19
|
+
// (framework-free); `useSolveSession` is this package's Svelte binding, which republishes
|
|
20
|
+
// the session's subscribe() notifications as rune state so its getters read reactively in
|
|
21
|
+
// markup. Re-exported so transports outside this package — e.g. plugin-ui's WebSocket
|
|
20
22
|
// driver — can satisfy SolveDriver and drive a session. See CONTEXT.md.
|
|
21
|
-
export {
|
|
23
|
+
export { useSolveSession } from './compute/useSolveSession.svelte';
|
|
24
|
+
export { createSolveSession, createRequestResponseDriver } from '@selvajs/solve/client';
|
|
22
25
|
// External-input transit storage (used by routes that wire pre-step producers)
|
|
23
|
-
export
|
|
26
|
+
export { writeExternalValue, readExternalValue, clearExternalValue, getExternalInputs } from '@selvajs/solve/client';
|
|
24
27
|
// Contexts & Composables
|
|
25
28
|
export * from './contexts/footerContext.svelte';
|
|
26
29
|
export * from './contexts/clientSlotContext.svelte';
|
package/dist/public.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ export type { Locale, ViewerMessages } from './i18n/messages';
|
|
|
5
5
|
export { VIEWER_MESSAGES, DEFAULT_LOCALE, messagesFor } from './i18n/messages';
|
|
6
6
|
export { setLocaleContext, getLocaleContext, type LocaleContext } from './i18n/localeContext.svelte';
|
|
7
7
|
export { default as ErrorScreen } from './components/ErrorScreen.svelte';
|
|
8
|
-
export {
|
|
8
|
+
export { useSolveSession } from './compute/useSolveSession.svelte';
|
|
9
|
+
export { createSolveSession, createRequestResponseDriver, type SolveSession, type SolveSessionArgs, type SolveDriver, type SolveReporter } from '@selvajs/solve/client';
|
|
9
10
|
export type { ClientSlotArgs, ClientSlot } from './contexts/clientSlotContext.svelte';
|
|
10
|
-
export
|
|
11
|
+
export { writeExternalValue, readExternalValue, clearExternalValue, getExternalInputs, type ExternalValueRef, type ExternalInput } from '@selvajs/solve/client';
|
|
11
12
|
export * from './schema/defaults';
|
|
12
13
|
export * from './schema/traversal';
|
|
13
14
|
export * from './schema/dynamic-value-list';
|
|
14
15
|
export type { ActionButton } from './types/actionButton';
|
|
15
|
-
export type { SolveFn, SolveResult } from '
|
|
16
|
+
export type { SolveFn, SolveResult } from '@selvajs/solve/shared';
|
|
16
17
|
export { DEFAULT_PRESET_LABELS, type PresetLabels } from './types/presetLabels';
|
package/dist/public.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// Scope: the compute-app SDK — everything an external host app needs to embed a
|
|
9
9
|
// Grasshopper-driven app (ComputeApp), drive solves, and wire pre-step
|
|
10
10
|
// producers. Verified against real external host apps: they import
|
|
11
|
-
// ComputeApp + its types, the solve seam, and external
|
|
11
|
+
// ComputeApp + its types, the solve seam, and the external-input storage
|
|
12
|
+
// helpers. Nothing else.
|
|
12
13
|
//
|
|
13
14
|
// Deliberately NOT public: design-system primitives (Button, Card, Dialog, …),
|
|
14
15
|
// page-chrome layout (AppShell, SideNav, …), toast/Toaster, ThemeSwitcher,
|
|
@@ -30,11 +31,14 @@ export { setLocaleContext, getLocaleContext } from './i18n/localeContext.svelte'
|
|
|
30
31
|
// Full-screen states a host app renders
|
|
31
32
|
export { default as ErrorScreen } from './components/ErrorScreen.svelte';
|
|
32
33
|
// Solve Session seam (transport-agnostic value/lifecycle state machine + its
|
|
33
|
-
// driver interface).
|
|
34
|
-
//
|
|
35
|
-
|
|
34
|
+
// driver interface). The session lives in `@selvajs/solve/client` and is
|
|
35
|
+
// framework-free; `useSolveSession` is the Svelte binding that makes its getters
|
|
36
|
+
// read reactively inside components. A host embedding <ComputeApp> needs neither —
|
|
37
|
+
// both are re-exported for hosts driving a session themselves. See CONTEXT.md.
|
|
38
|
+
export { useSolveSession } from './compute/useSolveSession.svelte';
|
|
39
|
+
export { createSolveSession, createRequestResponseDriver } from '@selvajs/solve/client';
|
|
36
40
|
// Pre-step producer transit storage (host apps wire producers via these).
|
|
37
|
-
export
|
|
41
|
+
export { writeExternalValue, readExternalValue, clearExternalValue, getExternalInputs } from '@selvajs/solve/client';
|
|
38
42
|
// Schema utilities a ComputeApp host reasonably needs to read/shape values.
|
|
39
43
|
export * from './schema/defaults';
|
|
40
44
|
export * from './schema/traversal';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selvajs/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-beta.0",
|
|
4
4
|
"description": "Shared UI components and utilities for Selva applications",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "VektorNode",
|
|
@@ -60,8 +60,10 @@
|
|
|
60
60
|
"svelte": "^5",
|
|
61
61
|
"tailwind-variants": "^3.3.0",
|
|
62
62
|
"three": "^0.185.1",
|
|
63
|
+
"@selvajs/compute": "^4.0.0-beta.0",
|
|
63
64
|
"@selvajs/schemas": "^4.7.0",
|
|
64
|
-
"@selvajs/
|
|
65
|
+
"@selvajs/solve": "^0.2.0-beta.0",
|
|
66
|
+
"@selvajs/visualization": "^1.0.0-beta.0"
|
|
65
67
|
},
|
|
66
68
|
"peerDependenciesMeta": {
|
|
67
69
|
"three": {
|
|
@@ -89,7 +91,7 @@
|
|
|
89
91
|
"rimraf": "^6.0.1",
|
|
90
92
|
"svelte": "5.56.8",
|
|
91
93
|
"tailwind-variants": "^3.3.0",
|
|
92
|
-
"vitest": "^
|
|
94
|
+
"vitest": "^4.1.10",
|
|
93
95
|
"@selvajs/config": "0.0.3",
|
|
94
96
|
"@selvajs/schemas": "4.7.0"
|
|
95
97
|
},
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
import { page } from '$app/state';
|
|
4
4
|
import type { UISchema, ParameterPreset } from '@selvajs/schemas';
|
|
5
5
|
import type { ActionButton } from '../../types/actionButton';
|
|
6
|
-
import type { SolveFn } from '
|
|
6
|
+
import type { SolveFn } from '@selvajs/solve/shared';
|
|
7
7
|
import type { PresetLabels } from '../../types/presetLabels';
|
|
8
8
|
import { createSolvingIndicator } from '../../compute/solving.svelte';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '../../compute/createSolveSession.svelte';
|
|
9
|
+
import { createRequestResponseDriver } from '@selvajs/solve/client';
|
|
10
|
+
import { meshPolicy } from '@selvajs/visualization/parse';
|
|
11
|
+
import { useSolveSession } from '../../compute/useSolveSession.svelte';
|
|
13
12
|
import { useFooterItem } from '../../composables/useFooterItem.svelte';
|
|
14
13
|
import { hexToOklch } from '../../utils/color';
|
|
15
14
|
import AppShell from '../layout/AppShell.svelte';
|
|
@@ -115,10 +114,19 @@
|
|
|
115
114
|
// reads the reporter lazily so it can capture the session it's wired into.
|
|
116
115
|
// svelte-ignore state_referenced_locally
|
|
117
116
|
const driver = createRequestResponseDriver(onSolve, () => session, {
|
|
118
|
-
timeout: solveTimeoutMs
|
|
117
|
+
timeout: solveTimeoutMs,
|
|
118
|
+
// The driver's result memo caches whole solve results, meshes included — and the viewer
|
|
119
|
+
// disposes what it renders on the next scene update. `@selvajs/solve` keeps meshes opaque,
|
|
120
|
+
// so the three.js clone/dispose rules are injected from the renderer that owns them
|
|
121
|
+
// (audit C1). Without this a memo hit serves an already-disposed mesh.
|
|
122
|
+
meshPolicy,
|
|
123
|
+
// `session.isSolving` forwards to the driver, which the session can't observe on its
|
|
124
|
+
// own — republish so the spinner and disabled states track it. Deferred into a
|
|
125
|
+
// callback, so it reads `session` after initialization rather than during it.
|
|
126
|
+
onChange: () => session.notify()
|
|
119
127
|
});
|
|
120
128
|
// svelte-ignore state_referenced_locally
|
|
121
|
-
const session =
|
|
129
|
+
const session = useSolveSession({
|
|
122
130
|
schema,
|
|
123
131
|
scopeKey: externalScopeKey || definitionKey || schema?.id || '',
|
|
124
132
|
driver
|
|
@@ -1,173 +1,85 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import { Eye, EyeOff, ChevronRight, Search, X } from '@lucide/svelte';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getObjectLabel,
|
|
6
|
+
getTrackingKey,
|
|
7
|
+
getTypeLabel,
|
|
8
|
+
type SceneOutliner
|
|
9
|
+
} from '@selvajs/visualization/scene';
|
|
5
10
|
import { getLocaleContext } from '$lib/i18n/localeContext.svelte';
|
|
6
11
|
|
|
7
12
|
const locale = getLocaleContext();
|
|
8
13
|
const t = $derived(locale.messages);
|
|
9
14
|
|
|
10
15
|
interface Props {
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Owned by `Viewer.svelte`, not built here: this panel unmounts when it is closed, and
|
|
18
|
+
* hidden objects have to stay hidden — and keep being re-hidden after each solve — while it
|
|
19
|
+
* is. Its state is backed by SvelteSets, so mutating one re-renders this list.
|
|
20
|
+
*/
|
|
21
|
+
outliner: SceneOutliner;
|
|
12
22
|
sceneVersion?: number;
|
|
13
23
|
}
|
|
14
24
|
|
|
15
|
-
let {
|
|
25
|
+
let { outliner, sceneVersion = 0 }: Props = $props();
|
|
16
26
|
|
|
17
|
-
//
|
|
18
|
-
// @selvajs/
|
|
19
|
-
|
|
27
|
+
// All list logic (content filtering, layer grouping, search, visibility, selection) lives in
|
|
28
|
+
// @selvajs/visualization/scene. This component only renders it and forwards clicks.
|
|
29
|
+
// Derived, not destructured: the prop is reassignable, and these must follow it.
|
|
30
|
+
const hidden = $derived(outliner.visibility.hidden);
|
|
31
|
+
const selected = $derived(outliner.selection.selected);
|
|
32
|
+
const collapsed = $derived(outliner.collapsed);
|
|
20
33
|
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
|
|
34
|
+
// Mirrored into runes because the outliner holds them as plain fields, not sets. Both start
|
|
35
|
+
// fresh: the search box and the shift-anchor are panel state, so reopening the panel clears
|
|
36
|
+
// them, while hiding and collapse persist in the outliner that outlives it.
|
|
37
|
+
let searchQuery = $state('');
|
|
38
|
+
let anchor = $state<string | null>(null);
|
|
39
|
+
|
|
40
|
+
$effect(() => outliner.onAnchorChange((next) => (anchor = next)));
|
|
41
|
+
|
|
42
|
+
// `scene.children` is a plain array the render layer mutates in place, so a solve bumping
|
|
43
|
+
// `sceneVersion` is the only signal that content changed. Both derivations below read it, which
|
|
44
|
+
// is what makes one walk per solve serve every template site that needs the list.
|
|
25
45
|
const sceneObjects = $derived.by(() => {
|
|
26
46
|
void sceneVersion;
|
|
27
|
-
return
|
|
28
|
-
(obj) =>
|
|
29
|
-
!(obj instanceof THREE.Camera) &&
|
|
30
|
-
!(obj instanceof THREE.Light) &&
|
|
31
|
-
!HELPER_IDS.has(obj.userData?.id)
|
|
32
|
-
);
|
|
47
|
+
return outliner.objects();
|
|
33
48
|
});
|
|
34
49
|
|
|
35
|
-
// Content grouped by layer. Derived from `sceneObjects`, so the grouping map is rebuilt once per
|
|
36
|
-
// solve rather than every time the list renders.
|
|
37
50
|
const layerGroups = $derived.by(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
groups.get(layer)!.push(obj);
|
|
43
|
-
}
|
|
44
|
-
return groups;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
let hiddenUuids = new SvelteSet<string>();
|
|
48
|
-
|
|
49
|
-
let collapsedLayers = new SvelteSet<string>();
|
|
50
|
-
|
|
51
|
-
const setObjectVisible = (object: THREE.Object3D, visible: boolean) => {
|
|
52
|
-
object.visible = visible;
|
|
53
|
-
object.traverse((child) => {
|
|
54
|
-
child.visible = visible;
|
|
55
|
-
});
|
|
56
|
-
if (visible) {
|
|
57
|
-
hiddenUuids.delete(object.uuid);
|
|
58
|
-
} else {
|
|
59
|
-
hiddenUuids.add(object.uuid);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const toggleObject = (object: THREE.Object3D) => {
|
|
64
|
-
if (selectedUuids.has(object.uuid) && selectedUuids.size > 1) {
|
|
65
|
-
const selected = sceneObjects.filter((o) => selectedUuids.has(o.uuid));
|
|
66
|
-
const allHidden = selected.every((o) => hiddenUuids.has(o.uuid));
|
|
67
|
-
for (const o of selected) setObjectVisible(o, allHidden);
|
|
68
|
-
} else {
|
|
69
|
-
setObjectVisible(object, hiddenUuids.has(object.uuid));
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const isLayerHidden = (objects: THREE.Object3D[]) =>
|
|
74
|
-
objects.every((obj) => hiddenUuids.has(obj.uuid));
|
|
75
|
-
|
|
76
|
-
const isLayerPartial = (objects: THREE.Object3D[]) => {
|
|
77
|
-
const hidden = objects.filter((obj) => hiddenUuids.has(obj.uuid)).length;
|
|
78
|
-
return hidden > 0 && hidden < objects.length;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const toggleLayer = (_layerName: string, objects: THREE.Object3D[]) => {
|
|
82
|
-
const allHidden = isLayerHidden(objects);
|
|
83
|
-
for (const obj of objects) {
|
|
84
|
-
setObjectVisible(obj, allHidden);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const toggleLayerCollapsed = (layerName: string) => {
|
|
89
|
-
if (collapsedLayers.has(layerName)) {
|
|
90
|
-
collapsedLayers.delete(layerName);
|
|
91
|
-
} else {
|
|
92
|
-
collapsedLayers.add(layerName);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const prettyType = (type: string) =>
|
|
97
|
-
type
|
|
98
|
-
.replace(/^Line(Segments)?2$/, 'Curve')
|
|
99
|
-
.replace('Mesh', '')
|
|
100
|
-
.replace('Object3D', 'Obj') || type;
|
|
101
|
-
|
|
102
|
-
const getObjectLabel = (object: THREE.Object3D) =>
|
|
103
|
-
object.userData?.name || object.userData?.fileName || object.name || prettyType(object.type);
|
|
104
|
-
|
|
105
|
-
const getTypeLabel = (object: THREE.Object3D) => prettyType(object.type);
|
|
106
|
-
|
|
107
|
-
let searchQuery = $state('');
|
|
108
|
-
|
|
109
|
-
// Layer groups after the search filter. Derived from `layerGroups` + `searchQuery`, so filtering
|
|
110
|
-
// runs once per search keystroke — not twice per render (it's read by both the list and the
|
|
111
|
-
// empty-state check below).
|
|
112
|
-
const filteredLayerGroups = $derived.by(() => {
|
|
113
|
-
if (!searchQuery.trim()) return layerGroups;
|
|
114
|
-
const q = searchQuery.toLowerCase();
|
|
115
|
-
const filtered = new SvelteMap<string, THREE.Object3D[]>();
|
|
116
|
-
for (const [layerName, objects] of layerGroups) {
|
|
117
|
-
const matchingObjects = layerName.toLowerCase().includes(q)
|
|
118
|
-
? objects
|
|
119
|
-
: objects.filter((obj) => getObjectLabel(obj).toLowerCase().includes(q));
|
|
120
|
-
if (matchingObjects.length > 0) filtered.set(layerName, matchingObjects);
|
|
121
|
-
}
|
|
122
|
-
return filtered;
|
|
51
|
+
void sceneVersion;
|
|
52
|
+
void searchQuery;
|
|
53
|
+
outliner.searchQuery = searchQuery;
|
|
54
|
+
return outliner.layerGroups();
|
|
123
55
|
});
|
|
124
56
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return result;
|
|
133
|
-
};
|
|
57
|
+
// Hidden state is keyed by Grasshopper identity, not by uuid, so ask the outliner rather than
|
|
58
|
+
// looking the object up in the set directly. Touching `hidden` registers the reactive read that
|
|
59
|
+
// re-renders this row when the eye is clicked.
|
|
60
|
+
// `SvelteSet.has()` is itself the reactive read, so go through the set rather than calling
|
|
61
|
+
// `visibility.isHidden` — that reads the set through a plain reference inside the outliner and
|
|
62
|
+
// would not re-render this row.
|
|
63
|
+
const isObjectHidden = (object: THREE.Object3D) => hidden.has(getTrackingKey(object));
|
|
134
64
|
|
|
135
|
-
|
|
136
|
-
|
|
65
|
+
// Same reason: count through the reactive set so the layer's tri-state eye tracks its objects.
|
|
66
|
+
const hiddenCount = (objects: THREE.Object3D[]) =>
|
|
67
|
+
objects.filter((object) => isObjectHidden(object)).length;
|
|
137
68
|
|
|
69
|
+
// Reading `anchor` keeps the shift-range dependent on it; the outliner owns the value.
|
|
138
70
|
const selectObject = (uuid: string, event: MouseEvent) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const [lo, hi] = a < b ? [a, b] : [b, a];
|
|
145
|
-
if (!event.ctrlKey && !event.metaKey) selectedUuids.clear();
|
|
146
|
-
for (let i = lo; i <= hi; i++) selectedUuids.add(flat[i]);
|
|
147
|
-
}
|
|
148
|
-
} else if (event.ctrlKey || event.metaKey) {
|
|
149
|
-
if (selectedUuids.has(uuid)) {
|
|
150
|
-
selectedUuids.delete(uuid);
|
|
151
|
-
} else {
|
|
152
|
-
selectedUuids.add(uuid);
|
|
153
|
-
lastSelectedUuid = uuid;
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
selectedUuids.clear();
|
|
157
|
-
selectedUuids.add(uuid);
|
|
158
|
-
lastSelectedUuid = uuid;
|
|
159
|
-
}
|
|
160
|
-
if (!event.shiftKey) lastSelectedUuid = uuid;
|
|
71
|
+
void anchor;
|
|
72
|
+
outliner.select(uuid, {
|
|
73
|
+
shiftKey: event.shiftKey,
|
|
74
|
+
toggleKey: event.ctrlKey || event.metaKey
|
|
75
|
+
});
|
|
161
76
|
};
|
|
162
77
|
</script>
|
|
163
78
|
|
|
164
79
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
165
80
|
<div
|
|
166
81
|
class="flex h-full flex-col bg-card text-card-foreground"
|
|
167
|
-
onmousedown={() =>
|
|
168
|
-
selectedUuids.clear();
|
|
169
|
-
lastSelectedUuid = null;
|
|
170
|
-
}}
|
|
82
|
+
onmousedown={() => outliner.selection.clear()}
|
|
171
83
|
>
|
|
172
84
|
<div class="px-3 py-2 gap-2 flex items-center border-b border-border">
|
|
173
85
|
<Search class="h-3.5 w-3.5 shrink-0 text-muted-foreground/50" />
|
|
@@ -186,25 +98,26 @@
|
|
|
186
98
|
</div>
|
|
187
99
|
|
|
188
100
|
<div class="py-1 flex-1 overflow-y-auto">
|
|
189
|
-
{#each [...
|
|
190
|
-
{@const
|
|
191
|
-
{@const
|
|
192
|
-
{@const
|
|
101
|
+
{#each [...layerGroups] as [layerName, objects] (layerName)}
|
|
102
|
+
{@const numHidden = hiddenCount(objects)}
|
|
103
|
+
{@const layerHidden = objects.length > 0 && numHidden === objects.length}
|
|
104
|
+
{@const layerPartial = numHidden > 0 && numHidden < objects.length}
|
|
105
|
+
{@const isCollapsed = collapsed.has(layerName)}
|
|
193
106
|
|
|
194
107
|
<div class="gap-1 pl-1 pr-2 py-1 group flex items-center transition-colors hover:bg-muted">
|
|
195
108
|
<button
|
|
196
109
|
class="rounded p-0.5 shrink-0 text-muted-foreground transition-colors hover:text-muted-foreground"
|
|
197
|
-
onclick={() =>
|
|
198
|
-
aria-label={
|
|
110
|
+
onclick={() => outliner.toggleCollapsed(layerName)}
|
|
111
|
+
aria-label={isCollapsed ? t.expandLayer : t.collapseLayer}
|
|
199
112
|
>
|
|
200
113
|
<ChevronRight
|
|
201
|
-
class="h-3.5 w-3.5 transition-transform duration-150 {
|
|
114
|
+
class="h-3.5 w-3.5 transition-transform duration-150 {isCollapsed ? '' : 'rotate-90'}"
|
|
202
115
|
/>
|
|
203
116
|
</button>
|
|
204
117
|
|
|
205
118
|
<button
|
|
206
119
|
class="rounded p-1 shrink-0 transition-colors hover:bg-muted"
|
|
207
|
-
onclick={() => toggleLayer(
|
|
120
|
+
onclick={() => outliner.visibility.toggleLayer(objects)}
|
|
208
121
|
title={layerHidden ? t.showLayer : t.hideLayer}
|
|
209
122
|
aria-label={layerHidden ? t.showLayer : t.hideLayer}
|
|
210
123
|
>
|
|
@@ -230,18 +143,20 @@
|
|
|
230
143
|
</span>
|
|
231
144
|
</div>
|
|
232
145
|
|
|
233
|
-
{#if !
|
|
146
|
+
{#if !isCollapsed}
|
|
234
147
|
<div role="listbox" aria-multiselectable="true" class="ml-3 border-l border-border">
|
|
235
148
|
{#each objects as object (object.uuid)}
|
|
236
|
-
|
|
237
|
-
|
|
149
|
+
<!-- Visibility is keyed by Grasshopper identity (so it survives a solve), selection
|
|
150
|
+
by uuid (so it does not) — hence the two different lookups. -->
|
|
151
|
+
{@const isHidden = isObjectHidden(object)}
|
|
152
|
+
{@const isSelected = selected.has(object.uuid)}
|
|
238
153
|
<div
|
|
239
154
|
role="option"
|
|
240
|
-
aria-selected={
|
|
155
|
+
aria-selected={isSelected}
|
|
241
156
|
tabindex="-1"
|
|
242
157
|
class="gap-1.5 pl-5 pr-2 py-0.5 flex cursor-pointer items-center transition-colors
|
|
243
|
-
{
|
|
244
|
-
{
|
|
158
|
+
{isSelected ? 'bg-primary/10 hover:bg-primary/15' : 'hover:bg-muted'}
|
|
159
|
+
{isHidden ? 'opacity-40' : ''}"
|
|
245
160
|
onmousedown={(e) => {
|
|
246
161
|
e.stopPropagation();
|
|
247
162
|
if (e.shiftKey) e.preventDefault();
|
|
@@ -255,12 +170,12 @@
|
|
|
255
170
|
class="rounded p-1 shrink-0 transition-colors hover:bg-muted"
|
|
256
171
|
onclick={(e) => {
|
|
257
172
|
e.stopPropagation();
|
|
258
|
-
toggleObject(object);
|
|
173
|
+
outliner.toggleObject(object);
|
|
259
174
|
}}
|
|
260
|
-
title={
|
|
261
|
-
aria-label={
|
|
175
|
+
title={isHidden ? t.showObject : t.hideObject}
|
|
176
|
+
aria-label={isHidden ? t.showObject : t.hideObject}
|
|
262
177
|
>
|
|
263
|
-
{#if
|
|
178
|
+
{#if isHidden}
|
|
264
179
|
<EyeOff class="h-3 w-3 text-muted-foreground/60" />
|
|
265
180
|
{:else}
|
|
266
181
|
<Eye class="h-3 w-3 text-muted-foreground" />
|
|
@@ -269,7 +184,7 @@
|
|
|
269
184
|
|
|
270
185
|
<!-- Object name -->
|
|
271
186
|
<span
|
|
272
|
-
class="min-w-0 text-xs flex-1 truncate {
|
|
187
|
+
class="min-w-0 text-xs flex-1 truncate {isHidden
|
|
273
188
|
? 'text-muted-foreground line-through'
|
|
274
189
|
: 'text-foreground/80'}"
|
|
275
190
|
>
|
|
@@ -294,7 +209,7 @@
|
|
|
294
209
|
<EyeOff class="mb-2 h-5 w-5 text-muted-foreground/30" />
|
|
295
210
|
<p class="text-xs text-muted-foreground">{t.noObjects}</p>
|
|
296
211
|
</div>
|
|
297
|
-
{:else if
|
|
212
|
+
{:else if layerGroups.size === 0}
|
|
298
213
|
<div class="py-12 flex flex-col items-center justify-center text-center">
|
|
299
214
|
<Search class="mb-2 h-5 w-5 text-muted-foreground/30" />
|
|
300
215
|
<p class="text-xs text-muted-foreground">
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
type MeasureTool,
|
|
13
13
|
type ViewPreset,
|
|
14
14
|
type Grid
|
|
15
|
-
} from '@selvajs/
|
|
15
|
+
} from '@selvajs/visualization/render';
|
|
16
16
|
import {
|
|
17
17
|
Maximize,
|
|
18
18
|
Minimize,
|
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
Spline
|
|
31
31
|
} from '@lucide/svelte';
|
|
32
32
|
import { DropdownMenu } from 'bits-ui';
|
|
33
|
+
import { SvelteSet } from 'svelte/reactivity';
|
|
33
34
|
import type * as THREE from 'three';
|
|
34
35
|
import type { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
|
36
|
+
import { createSceneOutliner, type SceneOutliner } from '@selvajs/visualization/scene';
|
|
35
37
|
import SceneManager from './SceneManager.svelte';
|
|
36
38
|
import MeshMetadataDialog from './MeshMetadataDialog.svelte';
|
|
37
39
|
import * as Resizable from '$lib/components/primitives/resizable/index.js';
|
|
@@ -127,6 +129,15 @@
|
|
|
127
129
|
let sceneVersion = $state(0);
|
|
128
130
|
let hideButton = $state(false);
|
|
129
131
|
let sceneManagerOpen = $state(false);
|
|
132
|
+
|
|
133
|
+
// The scene outliner lives here rather than inside <SceneManager> because that component is
|
|
134
|
+
// mounted only while its panel is open. Hidden objects must stay hidden when the panel is
|
|
135
|
+
// closed — and must be re-hidden after each solve, which nothing would do if the state
|
|
136
|
+
// unmounted with the panel.
|
|
137
|
+
const hiddenObjects = new SvelteSet<string>();
|
|
138
|
+
const selectedObjects = new SvelteSet<string>();
|
|
139
|
+
const collapsedLayers = new SvelteSet<string>();
|
|
140
|
+
let outliner: SceneOutliner | null = $state(null);
|
|
130
141
|
let projection: CameraProjection = $state('perspective');
|
|
131
142
|
let measureActive = $state(false);
|
|
132
143
|
let gridVisible = $state(false);
|
|
@@ -195,6 +206,9 @@
|
|
|
195
206
|
|
|
196
207
|
const init = initThree(canvas, opts);
|
|
197
208
|
scene = init.scene;
|
|
209
|
+
outliner = createSceneOutliner(init.scene, {
|
|
210
|
+
sets: { hidden: hiddenObjects, selected: selectedObjects, collapsed: collapsedLayers }
|
|
211
|
+
});
|
|
198
212
|
camera = init.camera;
|
|
199
213
|
controls = init.controls;
|
|
200
214
|
cameraController = init.cameraController;
|
|
@@ -272,6 +286,9 @@
|
|
|
272
286
|
if (edgesVisible) applyEdges?.(scene!);
|
|
273
287
|
// Rescale the grid to the new content's extent so cells and fade match the part size.
|
|
274
288
|
updateGridScale?.();
|
|
289
|
+
// The rebuild above also un-hid everything the user had hidden. Re-hide it: the outliner
|
|
290
|
+
// keys that state on Grasshopper identity, not on the instances just discarded.
|
|
291
|
+
outliner?.applyTo();
|
|
275
292
|
sceneVersion++;
|
|
276
293
|
// New solve content — repaint now rather than on the render loop's safety interval.
|
|
277
294
|
invalidate?.();
|
|
@@ -546,10 +563,10 @@
|
|
|
546
563
|
</Resizable.Pane>
|
|
547
564
|
|
|
548
565
|
<!-- Scene Manager Pane -->
|
|
549
|
-
{#if sceneManagerOpen && scene}
|
|
566
|
+
{#if sceneManagerOpen && scene && outliner}
|
|
550
567
|
<Resizable.Handle withHandle />
|
|
551
568
|
<Resizable.Pane defaultSize={15} minSize={8} maxSize={30}>
|
|
552
|
-
<SceneManager {
|
|
569
|
+
<SceneManager {outliner} {sceneVersion} />
|
|
553
570
|
</Resizable.Pane>
|
|
554
571
|
{/if}
|
|
555
572
|
</Resizable.PaneGroup>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { createRequestResponseDriver, type SolveReporter } from '@selvajs/solve/client';
|
|
5
|
+
import type { SolveResult } from '@selvajs/solve/shared';
|
|
6
|
+
import { meshPolicy } from '@selvajs/visualization/parse';
|
|
7
|
+
|
|
8
|
+
// The C1 seam test. `@selvajs/solve` keeps meshes opaque and `@selvajs/visualization` owns the
|
|
9
|
+
// three.js clone/dispose rules; neither package can prove they compose, because neither may
|
|
10
|
+
// import the other. This is the only place both are in scope — it exists to catch a
|
|
11
|
+
// `ComputeApp` that forgets to pass `meshPolicy`, or a policy whose shape drifts from
|
|
12
|
+
// `MeshPolicy`.
|
|
13
|
+
|
|
14
|
+
function meshResult(tag: string): SolveResult<THREE.Object3D> {
|
|
15
|
+
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshBasicMaterial());
|
|
16
|
+
mesh.name = tag;
|
|
17
|
+
return { outputs: { out: tag }, meshes: [mesh] };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Mirrors the viewer's `clearScene`: it disposes the geometry of whatever it was handed. */
|
|
21
|
+
function renderAndDispose(result: SolveResult<THREE.Object3D>): void {
|
|
22
|
+
result.meshes?.forEach((root) =>
|
|
23
|
+
root.traverse((child) => (child as Partial<THREE.Mesh>).geometry?.dispose())
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function collectingReporter(): SolveReporter<THREE.Object3D> & {
|
|
28
|
+
reports: SolveResult<THREE.Object3D>[];
|
|
29
|
+
} {
|
|
30
|
+
const reports: SolveResult<THREE.Object3D>[] = [];
|
|
31
|
+
return {
|
|
32
|
+
reports,
|
|
33
|
+
report: (result) => reports.push(result),
|
|
34
|
+
reportError: () => {}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
39
|
+
|
|
40
|
+
describe('mesh policy wiring (audit C1)', () => {
|
|
41
|
+
it('a memo hit serves a live mesh after the viewer disposed the previous one', async () => {
|
|
42
|
+
const onSolve = async () => meshResult('a');
|
|
43
|
+
const reporter = collectingReporter();
|
|
44
|
+
const driver = createRequestResponseDriver(onSolve, () => reporter, { meshPolicy });
|
|
45
|
+
|
|
46
|
+
driver.solve({ a: 1 });
|
|
47
|
+
await flush();
|
|
48
|
+
renderAndDispose(reporter.reports[0]); // the viewer eats solve 1's meshes
|
|
49
|
+
|
|
50
|
+
driver.solve({ a: 1 }); // same inputs → memo hit, no onSolve call
|
|
51
|
+
await flush();
|
|
52
|
+
|
|
53
|
+
expect(reporter.reports).toHaveLength(2);
|
|
54
|
+
const served = reporter.reports[1].meshes![0] as THREE.Mesh;
|
|
55
|
+
expect(served).not.toBe(reporter.reports[0].meshes![0]);
|
|
56
|
+
expect(served.geometry.attributes.position).toBeDefined();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('without a policy the same flow serves the disposed instance (why the wiring matters)', async () => {
|
|
60
|
+
// Pins the failure mode, so the assertion above is known to be testing something.
|
|
61
|
+
const onSolve = async () => meshResult('a');
|
|
62
|
+
const reporter = collectingReporter();
|
|
63
|
+
const driver = createRequestResponseDriver(onSolve, () => reporter); // no meshPolicy
|
|
64
|
+
|
|
65
|
+
driver.solve({ a: 1 });
|
|
66
|
+
await flush();
|
|
67
|
+
driver.solve({ a: 1 });
|
|
68
|
+
await flush();
|
|
69
|
+
|
|
70
|
+
expect(reporter.reports[1].meshes![0]).toBe(reporter.reports[0].meshes![0]);
|
|
71
|
+
});
|
|
72
|
+
});
|