@selvajs/ui 5.0.0 → 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/alert/alert.svelte.d.ts +8 -8
- package/dist/components/primitives/badge/badge.svelte.d.ts +14 -14
- package/dist/components/primitives/button/button.svelte.d.ts +41 -41
- package/dist/components/primitives/button-group/button-group.svelte.d.ts +8 -8
- package/dist/components/primitives/field/field.svelte.d.ts +5 -5
- 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 +17 -15
- 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
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
getExternalInputs,
|
|
4
|
-
writeExternalValue,
|
|
5
|
-
readExternalValue,
|
|
6
|
-
clearExternalValue
|
|
7
|
-
} from './storage';
|
|
8
|
-
import type { UISchema } from '@selvajs/schemas';
|
|
9
|
-
|
|
10
|
-
// getExternalInputs is the gate the whole client-input feature hangs on: it decides
|
|
11
|
-
// which inputs a producer route must fill. These pin the source.kind === 'client'
|
|
12
|
-
// filter and the displayName fallback. The read/write helpers are also covered with a
|
|
13
|
-
// sessionStorage stub, including the no-storage guard (SSR / node).
|
|
14
|
-
|
|
15
|
-
const input = (paramId: string, opts: { displayName?: string; source?: { kind: string } } = {}) =>
|
|
16
|
-
({ type: 'input', paramId, ...opts }) as never;
|
|
17
|
-
|
|
18
|
-
function schema(items: unknown[]): UISchema {
|
|
19
|
-
return {
|
|
20
|
-
layout: { type: 'flat', groups: [{ id: 'g', label: 'g', items }] }
|
|
21
|
-
} as unknown as UISchema;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe('getExternalInputs', () => {
|
|
25
|
-
it('keeps only inputs with source.kind === client', () => {
|
|
26
|
-
const s = schema([
|
|
27
|
-
input('a', { source: { kind: 'client' } }),
|
|
28
|
-
input('b', { source: { kind: 'user' } }),
|
|
29
|
-
input('c') // no source
|
|
30
|
-
]);
|
|
31
|
-
expect(getExternalInputs(s).map((e) => e.paramId)).toEqual(['a']);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('falls back to paramId when displayName is absent', () => {
|
|
35
|
-
const s = schema([input('a', { source: { kind: 'client' } })]);
|
|
36
|
-
expect(getExternalInputs(s)[0].displayName).toBe('a');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('uses displayName when present', () => {
|
|
40
|
-
const s = schema([input('a', { displayName: 'Width', source: { kind: 'client' } })]);
|
|
41
|
-
expect(getExternalInputs(s)[0].displayName).toBe('Width');
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('read/write/clear with a sessionStorage stub', () => {
|
|
46
|
-
afterEach(() => {
|
|
47
|
-
vi.unstubAllGlobals();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
function stubStorage() {
|
|
51
|
-
const store = new Map<string, string>();
|
|
52
|
-
vi.stubGlobal('sessionStorage', {
|
|
53
|
-
getItem: (k: string) => store.get(k) ?? null,
|
|
54
|
-
setItem: (k: string, v: string) => store.set(k, v),
|
|
55
|
-
removeItem: (k: string) => store.delete(k)
|
|
56
|
-
});
|
|
57
|
-
return store;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
it('round-trips a value scoped by (scopeKey, inputId)', () => {
|
|
61
|
-
const store = stubStorage();
|
|
62
|
-
writeExternalValue({ scopeKey: 's1', inputId: 'p1', value: { x: 1 } });
|
|
63
|
-
expect(readExternalValue({ scopeKey: 's1', inputId: 'p1' })).toEqual({ x: 1 });
|
|
64
|
-
expect(store.has('external:s1:p1')).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('scopes values so they do not bleed across scopeKey', () => {
|
|
68
|
-
stubStorage();
|
|
69
|
-
writeExternalValue({ scopeKey: 's1', inputId: 'p1', value: 'a' });
|
|
70
|
-
expect(readExternalValue({ scopeKey: 's2', inputId: 'p1' })).toBeUndefined();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('clear removes the value', () => {
|
|
74
|
-
stubStorage();
|
|
75
|
-
writeExternalValue({ scopeKey: 's1', inputId: 'p1', value: 'a' });
|
|
76
|
-
clearExternalValue({ scopeKey: 's1', inputId: 'p1' });
|
|
77
|
-
expect(readExternalValue({ scopeKey: 's1', inputId: 'p1' })).toBeUndefined();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('returns undefined for malformed JSON', () => {
|
|
81
|
-
const store = stubStorage();
|
|
82
|
-
store.set('external:s1:p1', '{not json');
|
|
83
|
-
expect(readExternalValue({ scopeKey: 's1', inputId: 'p1' })).toBeUndefined();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('no-storage guard (SSR / node)', () => {
|
|
88
|
-
it('read returns undefined and write/clear no-op when sessionStorage is absent', () => {
|
|
89
|
-
// node env: sessionStorage is undefined by default
|
|
90
|
-
expect(readExternalValue({ scopeKey: 's1', inputId: 'p1' })).toBeUndefined();
|
|
91
|
-
expect(() => writeExternalValue({ scopeKey: 's1', inputId: 'p1', value: 1 })).not.toThrow();
|
|
92
|
-
expect(() => clearExternalValue({ scopeKey: 's1', inputId: 'p1' })).not.toThrow();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('ignores empty scopeKey or inputId', () => {
|
|
96
|
-
expect(readExternalValue({ scopeKey: '', inputId: 'p1' })).toBeUndefined();
|
|
97
|
-
expect(readExternalValue({ scopeKey: 's1', inputId: '' })).toBeUndefined();
|
|
98
|
-
});
|
|
99
|
-
});
|
package/src/lib/types/solveFn.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Result returned from a solve operation.
|
|
3
|
-
*
|
|
4
|
-
* @property outputs - Key-value pairs of computed results
|
|
5
|
-
* @property meshes - Optional array of 3D mesh data generated during computation
|
|
6
|
-
* @property errors - Optional array of error messages that occurred
|
|
7
|
-
* @property warnings - Optional array of warning messages from the computation
|
|
8
|
-
*/
|
|
9
|
-
export interface SolveResult {
|
|
10
|
-
outputs: Record<string, unknown>;
|
|
11
|
-
meshes?: any[];
|
|
12
|
-
errors?: string[];
|
|
13
|
-
warnings?: string[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Function type for running a computation with given input values.
|
|
18
|
-
*
|
|
19
|
-
* Implementations should listen to the abort signal and clean up resources
|
|
20
|
-
* when the signal is triggered (e.g., when the user cancels the operation).
|
|
21
|
-
*
|
|
22
|
-
* @param values - Input parameters for the computation
|
|
23
|
-
* @param signal - AbortSignal to cancel ongoing operations
|
|
24
|
-
* @returns Promise resolving to the computation result
|
|
25
|
-
*/
|
|
26
|
-
export type SolveFn = (
|
|
27
|
-
values: Record<string, unknown>,
|
|
28
|
-
signal: AbortSignal
|
|
29
|
-
) => Promise<SolveResult>;
|