@selvajs/ui 5.0.1 → 6.0.0-beta.1

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.
Files changed (48) hide show
  1. package/README.md +42 -9
  2. package/dist/components/compute/ComputeApp.svelte +36 -12
  3. package/dist/components/compute/ComputeApp.svelte.d.ts +14 -3
  4. package/dist/components/primitives/textarea/textarea.svelte +1 -2
  5. package/dist/components/viewer/SceneManager.svelte +75 -160
  6. package/dist/components/viewer/SceneManager.svelte.d.ts +8 -3
  7. package/dist/components/viewer/Viewer.svelte +22 -5
  8. package/dist/compute/useSolveSession.svelte.d.ts +12 -0
  9. package/dist/compute/useSolveSession.svelte.js +79 -0
  10. package/dist/external/storage.d.ts +1 -15
  11. package/dist/external/storage.js +4 -54
  12. package/dist/index.d.ts +4 -3
  13. package/dist/index.js +7 -4
  14. package/dist/public.d.ts +4 -3
  15. package/dist/public.js +9 -5
  16. package/package.json +9 -4
  17. package/src/lib/components/compute/ComputeApp.svelte +36 -12
  18. package/src/lib/components/primitives/textarea/textarea.svelte +1 -2
  19. package/src/lib/components/viewer/SceneManager.svelte +75 -160
  20. package/src/lib/components/viewer/Viewer.svelte +22 -5
  21. package/src/lib/compute/useSolveSession.svelte.ts +86 -0
  22. package/src/lib/external/storage.ts +12 -64
  23. package/src/lib/index.ts +15 -5
  24. package/src/lib/public.ts +17 -6
  25. package/dist/compute/computeThrottle.svelte.d.ts +0 -24
  26. package/dist/compute/computeThrottle.svelte.js +0 -82
  27. package/dist/compute/createSolveSession.svelte.d.ts +0 -66
  28. package/dist/compute/createSolveSession.svelte.js +0 -159
  29. package/dist/compute/solve-session-core.d.ts +0 -54
  30. package/dist/compute/solve-session-core.js +0 -87
  31. package/dist/compute/solveMemo.d.ts +0 -22
  32. package/dist/compute/solveMemo.js +0 -124
  33. package/dist/types/solveFn.d.ts +0 -25
  34. package/dist/types/solveFn.js +0 -1
  35. package/src/lib/compute/computeThrottle.svelte.ts +0 -109
  36. package/src/lib/compute/computeThrottle.test.ts +0 -106
  37. package/src/lib/compute/createSolveSession.svelte.ts +0 -239
  38. package/src/lib/compute/createSolveSession.test.ts +0 -168
  39. package/src/lib/compute/solve-session-core.test.ts +0 -153
  40. package/src/lib/compute/solve-session-core.ts +0 -122
  41. package/src/lib/compute/solveMemo.test.ts +0 -220
  42. package/src/lib/compute/solveMemo.ts +0 -140
  43. package/src/lib/external/storage.test.ts +0 -99
  44. package/src/lib/schema/dynamic-value-list.test.ts +0 -150
  45. package/src/lib/schema/param-exporter.test.ts +0 -136
  46. package/src/lib/schema/traversal.test.ts +0 -92
  47. package/src/lib/schema/visibility-rules.test.ts +0 -173
  48. package/src/lib/types/solveFn.ts +0 -29
package/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # @selvajs/ui
2
2
 
3
- Shared Svelte components, utilities, and theme system for Selva applications.
3
+ The Svelte layer over Selva's framework-free cores. Its npm surface is the **compute-app SDK**:
4
+ everything an external host app needs to embed a Grasshopper-driven app, drive solves, and wire
5
+ pre-step producers.
6
+
7
+ The design system (`Button`, `Card`, `Dialog`, `AppShell`, …) lives here too, but is **internal to
8
+ the monorepo** — it is reachable from the full barrel via the `@selvajs/source` export condition and
9
+ never ships to npm. [`src/lib/public.ts`](./src/lib/public.ts) is the authoritative list of what a
10
+ published consumer can import; promote a primitive there explicitly rather than assuming it is
11
+ available.
4
12
 
5
13
  ## Installation
6
14
 
@@ -8,20 +16,41 @@ Shared Svelte components, utilities, and theme system for Selva applications.
8
16
  pnpm add @selvajs/ui
9
17
  ```
10
18
 
11
- Peer dependencies required: `svelte ^5`, `@sveltejs/kit ^2`, `bits-ui ^2`, `tailwind-variants ^3`, `@selvajs/compute ^1`
19
+ Peer dependencies: `svelte ^5`, `@sveltejs/kit ^2`, `bits-ui ^2`, `tailwind-variants ^3`, plus the
20
+ Selva cores this package wraps — `@selvajs/compute`, `@selvajs/schemas`, `@selvajs/solve`, and
21
+ `@selvajs/visualization`.
22
+
23
+ `three` is an **optional** peer: install it only if you use `Viewer`, the part that wraps
24
+ `@selvajs/visualization`.
12
25
 
13
26
  ## Usage
14
27
 
28
+ Embed a whole Grasshopper-driven app:
29
+
30
+ ```svelte
31
+ <script lang="ts">
32
+ import { ComputeApp } from '@selvajs/ui';
33
+ </script>
34
+ ```
35
+
36
+ Or render meshes on their own, outside a `ComputeApp` host:
37
+
15
38
  ```svelte
16
39
  <script lang="ts">
17
- import { Button, Card, Input } from '@selvajs/ui';
40
+ import { Viewer, type ViewerConfig } from '@selvajs/ui';
18
41
  </script>
19
42
  ```
20
43
 
44
+ To drive a solve session yourself rather than letting `ComputeApp` own it:
45
+
21
46
  ```typescript
22
- import { cn, debounce, themeStore } from '@selvajs/ui';
47
+ import { useSolveSession } from '@selvajs/ui';
23
48
  ```
24
49
 
50
+ The session itself lives in `@selvajs/solve/client` and is framework-free. Inside a Svelte
51
+ component always use `useSolveSession` — the raw `createSolveSession` factory returns correct
52
+ values that never re-render.
53
+
25
54
  ## Styles
26
55
 
27
56
  In your `app.css`:
@@ -30,16 +59,20 @@ In your `app.css`:
30
59
  @import '@selvajs/ui/styles/base.css';
31
60
  ```
32
61
 
33
- Themes are available under `@selvajs/ui/styles/themes/*`.
62
+ Themes are available under `@selvajs/ui/styles/themes/*` — `selva`, `neutral`, `ocean`, and
63
+ `cyberpunk`.
64
+
65
+ ## Schema types
34
66
 
35
- ## Generated Types
67
+ Types generated from `packages/schemas/ui-schema.json` are published by `@selvajs/schemas`, not
68
+ re-exported here:
36
69
 
37
70
  ```typescript
38
- import type { UISchema } from '@selvajs/ui';
71
+ import type { SelvaUISchema } from '@selvajs/schemas';
39
72
  ```
40
73
 
41
- Types are generated from `packages/schemas/ui-schema.json`. After modifying the schema, run:
74
+ After modifying the schema, run:
42
75
 
43
76
  ```bash
44
- cd packages/schemas && pnpm run generate:all
77
+ cd packages/schemas && pnpm run generate
45
78
  ```
@@ -3,13 +3,13 @@
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 '../../types/solveFn';
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
- createSolveSession,
11
- createRequestResponseDriver
12
- } from '../../compute/createSolveSession.svelte';
9
+ import { createRequestResponseDriver } from '@selvajs/solve/client';
10
+ import type { RetainedSolveResult } from '@selvajs/solve/client';
11
+ import { meshPolicy } from '@selvajs/visualization/parse';
12
+ import { useSolveSession } from '../../compute/useSolveSession.svelte';
13
13
  import { useFooterItem } from '../../composables/useFooterItem.svelte';
14
14
  import { hexToOklch } from '../../utils/color';
15
15
  import AppShell from '../layout/AppShell.svelte';
@@ -44,13 +44,25 @@
44
44
  copyrightName?: string;
45
45
  /** Fully overrides the footer copyright line. `{name}` and `{year}` are substituted. */
46
46
  footerText?: string;
47
- /** Per-solve abort timeout (ms). Falls back to createComputeThrottle's default. */
48
- solveTimeoutMs?: number;
47
+ /**
48
+ * How long one solve may take before the client aborts it (ms). Required: pass
49
+ * the same value the server enforces (`COMPUTE_SOLVE_DEADLINE_MS`), so the client
50
+ * doesn't abort a solve that would have finished.
51
+ */
52
+ solveDeadlineMs: number;
49
53
  footerComponent?: any;
50
54
  footerComponentProps?: () => Record<string, unknown>;
51
55
  footerItemId?: string;
52
56
  footerItemPriority?: number;
53
- onReady?: (api: { loadValues: (values: Record<string, unknown>) => void }) => void;
57
+ onReady?: (api: {
58
+ loadValues: (values: Record<string, unknown>) => void;
59
+ /**
60
+ * The last result reported to the session — the one the viewer is showing, carrying
61
+ * `source`/`values` even when a memo hit served it. Null before the first solve.
62
+ * A getter, not a snapshot: `onReady` fires once.
63
+ */
64
+ getLastResult: () => RetainedSolveResult | null;
65
+ }) => void;
54
66
  headerRight?: Snippet;
55
67
  // Replaces the built-in header; takes precedence over `headerRight`.
56
68
  header?: Snippet;
@@ -84,7 +96,7 @@
84
96
  presetLabels,
85
97
  copyrightName,
86
98
  footerText,
87
- solveTimeoutMs,
99
+ solveDeadlineMs,
88
100
  footerComponent,
89
101
  footerComponentProps,
90
102
  footerItemId = 'footer-item',
@@ -115,10 +127,19 @@
115
127
  // reads the reporter lazily so it can capture the session it's wired into.
116
128
  // svelte-ignore state_referenced_locally
117
129
  const driver = createRequestResponseDriver(onSolve, () => session, {
118
- timeout: solveTimeoutMs
130
+ solveDeadlineMs,
131
+ // The driver's result memo caches whole solve results, meshes included — and the viewer
132
+ // disposes what it renders on the next scene update. `@selvajs/solve` keeps meshes opaque,
133
+ // so the three.js clone/dispose rules are injected from the renderer that owns them
134
+ // (audit C1). Without this a memo hit serves an already-disposed mesh.
135
+ meshPolicy,
136
+ // `session.isSolving` forwards to the driver, which the session can't observe on its
137
+ // own — republish so the spinner and disabled states track it. Deferred into a
138
+ // callback, so it reads `session` after initialization rather than during it.
139
+ onChange: () => session.notify()
119
140
  });
120
141
  // svelte-ignore state_referenced_locally
121
- const session = createSolveSession({
142
+ const session = useSolveSession({
122
143
  schema,
123
144
  scopeKey: externalScopeKey || definitionKey || schema?.id || '',
124
145
  driver
@@ -129,7 +150,10 @@
129
150
  const solvingIndicator = createSolvingIndicator(() => session.isSolving);
130
151
 
131
152
  $effect(() => {
132
- onReady?.({ loadValues: (incoming) => session.loadValues(incoming) });
153
+ onReady?.({
154
+ loadValues: (incoming) => session.loadValues(incoming),
155
+ getLastResult: () => session.lastResult
156
+ });
133
157
  });
134
158
 
135
159
  let previousDefinitionKey = $state('');
@@ -1,7 +1,8 @@
1
1
  import type { UISchema, ParameterPreset } from '@selvajs/schemas';
2
2
  import type { ActionButton } from '../../types/actionButton';
3
- import type { SolveFn } from '../../types/solveFn';
3
+ import type { SolveFn } from '@selvajs/solve/shared';
4
4
  import type { PresetLabels } from '../../types/presetLabels';
5
+ import type { RetainedSolveResult } from '@selvajs/solve/client';
5
6
  import { type ClientSlot } from '../../contexts/clientSlotContext.svelte';
6
7
  import type { Locale } from '../../i18n/messages';
7
8
  import type { Snippet } from 'svelte';
@@ -28,14 +29,24 @@ interface Props {
28
29
  copyrightName?: string;
29
30
  /** Fully overrides the footer copyright line. `{name}` and `{year}` are substituted. */
30
31
  footerText?: string;
31
- /** Per-solve abort timeout (ms). Falls back to createComputeThrottle's default. */
32
- solveTimeoutMs?: number;
32
+ /**
33
+ * How long one solve may take before the client aborts it (ms). Required: pass
34
+ * the same value the server enforces (`COMPUTE_SOLVE_DEADLINE_MS`), so the client
35
+ * doesn't abort a solve that would have finished.
36
+ */
37
+ solveDeadlineMs: number;
33
38
  footerComponent?: any;
34
39
  footerComponentProps?: () => Record<string, unknown>;
35
40
  footerItemId?: string;
36
41
  footerItemPriority?: number;
37
42
  onReady?: (api: {
38
43
  loadValues: (values: Record<string, unknown>) => void;
44
+ /**
45
+ * The last result reported to the session — the one the viewer is showing, carrying
46
+ * `source`/`values` even when a memo hit served it. Null before the first solve.
47
+ * A getter, not a snapshot: `onReady` fires once.
48
+ */
49
+ getLastResult: () => RetainedSolveResult | null;
39
50
  }) => void;
40
51
  headerRight?: Snippet;
41
52
  header?: Snippet;
@@ -19,5 +19,4 @@
19
19
  className
20
20
  )}
21
21
  bind:value
22
- {...restProps}
23
- ></textarea>
22
+ {...restProps}></textarea>
@@ -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 { SvelteSet, SvelteMap } from 'svelte/reactivity';
4
+ import {
5
+ getObjectLabel,
6
+ getTrackingKey,
7
+ getTypeLabel,
8
+ type SceneOutliner
9
+ } from '@selvajs/visualization/scene';
5
10
  import { getLocaleContext } from '../../i18n/localeContext.svelte';
6
11
 
7
12
  const locale = getLocaleContext();
8
13
  const t = $derived(locale.messages);
9
14
 
10
15
  interface Props {
11
- scene: THREE.Scene;
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 { scene = $bindable(), sceneVersion = 0 }: Props = $props();
25
+ let { outliner, sceneVersion = 0 }: Props = $props();
16
26
 
17
- // Viewer aids (grid, floor, measurement overlay, CSS2D label layer) are tagged with these ids by
18
- // @selvajs/compute. They aren't scene content, so they're hidden from the object list.
19
- const HELPER_IDS = new Set(['grid', 'floor', 'label-layer', 'measure']);
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
- // Content objects of the scene, recomputed only when a solve bumps `sceneVersion` (scene.children is
22
- // a plain array the library mutates in place, so that counter is the sole reactive trigger). Derived
23
- // not a function so the several template sites that read it share one walk per solve instead of
24
- // re-filtering scene.children on every render.
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 scene.children.filter(
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
- const groups = new SvelteMap<string, THREE.Object3D[]>();
39
- for (const obj of sceneObjects) {
40
- const layer: string = obj.userData?.layer || obj.userData?.category || 'Default';
41
- if (!groups.has(layer)) groups.set(layer, []);
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
- const getFlatVisibleUuids = (): string[] => {
126
- const result: string[] = [];
127
- for (const [layerName, objects] of filteredLayerGroups) {
128
- if (!collapsedLayers.has(layerName)) {
129
- for (const obj of objects) result.push(obj.uuid);
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
- let selectedUuids = new SvelteSet<string>();
136
- let lastSelectedUuid = $state<string | null>(null);
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
- if (event.shiftKey && lastSelectedUuid) {
140
- const flat = getFlatVisibleUuids();
141
- const a = flat.indexOf(lastSelectedUuid);
142
- const b = flat.indexOf(uuid);
143
- if (a !== -1 && b !== -1) {
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 [...filteredLayerGroups] as [layerName, objects] (layerName)}
190
- {@const layerHidden = isLayerHidden(objects)}
191
- {@const layerPartial = isLayerPartial(objects)}
192
- {@const collapsed = collapsedLayers.has(layerName)}
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={() => toggleLayerCollapsed(layerName)}
198
- aria-label={collapsed ? t.expandLayer : t.collapseLayer}
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 {collapsed ? '' : 'rotate-90'}"
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(layerName, objects)}
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 !collapsed}
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
- {@const hidden = hiddenUuids.has(object.uuid)}
237
- {@const selected = selectedUuids.has(object.uuid)}
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={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
- {selected ? 'bg-primary/10 hover:bg-primary/15' : 'hover:bg-muted'}
244
- {hidden ? 'opacity-40' : ''}"
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={hidden ? t.showObject : t.hideObject}
261
- aria-label={hidden ? t.showObject : t.hideObject}
175
+ title={isHidden ? t.showObject : t.hideObject}
176
+ aria-label={isHidden ? t.showObject : t.hideObject}
262
177
  >
263
- {#if hidden}
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 {hidden
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 filteredLayerGroups.size === 0}
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">
@@ -1,8 +1,13 @@
1
- import * as THREE from 'three';
1
+ import { type SceneOutliner } from '@selvajs/visualization/scene';
2
2
  interface Props {
3
- scene: THREE.Scene;
3
+ /**
4
+ * Owned by `Viewer.svelte`, not built here: this panel unmounts when it is closed, and
5
+ * hidden objects have to stay hidden — and keep being re-hidden after each solve — while it
6
+ * is. Its state is backed by SvelteSets, so mutating one re-renders this list.
7
+ */
8
+ outliner: SceneOutliner;
4
9
  sceneVersion?: number;
5
10
  }
6
- declare const SceneManager: import("svelte").Component<Props, {}, "scene">;
11
+ declare const SceneManager: import("svelte").Component<Props, {}, "">;
7
12
  type SceneManager = ReturnType<typeof SceneManager>;
8
13
  export default SceneManager;
@@ -12,7 +12,7 @@
12
12
  type MeasureTool,
13
13
  type ViewPreset,
14
14
  type Grid
15
- } from '@selvajs/compute/visualization';
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 '../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);
@@ -183,10 +194,10 @@
183
194
  measure: { enabled: config.showToolsMenu },
184
195
  events: {
185
196
  onMeshMetadataClicked: config.enableMeshClick
186
- ? (metadata: Record<string, string>) => {
197
+ ? (metadata: Record<string, unknown>) => {
187
198
  if (hasUsefulMetadata(metadata)) {
188
199
  selectedMeshMetadata = metadata;
189
- selectedMeshName = metadata?.name || t.objectFallbackName;
200
+ selectedMeshName = String(metadata?.name ?? '') || t.objectFallbackName;
190
201
  }
191
202
  }
192
203
  : undefined
@@ -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 {scene} {sceneVersion} />
569
+ <SceneManager {outliner} {sceneVersion} />
553
570
  </Resizable.Pane>
554
571
  {/if}
555
572
  </Resizable.PaneGroup>
@@ -0,0 +1,12 @@
1
+ import type { SolveSession, SolveSessionArgs } from '@selvajs/solve/client';
2
+ /**
3
+ * Wraps a Solve Session so its state reads reactively inside Svelte components.
4
+ *
5
+ * Returns the same `SolveSession` surface — every method delegates untouched, and every
6
+ * getter additionally depends on the version counter. Callers use it exactly like the
7
+ * session it wraps.
8
+ *
9
+ * Must be called during component initialization (it uses `$effect` to manage the
10
+ * subscription, so teardown follows the owning component's lifecycle).
11
+ */
12
+ export declare function useSolveSession(args: SolveSessionArgs): SolveSession;