@arkitektio/bsx 5.0.0 → 6.1.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/README.md +2 -2
- package/dist/bsx/analyze.d.ts +6 -5
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +12 -10
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +111 -0
- package/dist/bsx/declared.d.ts.map +1 -0
- package/dist/bsx/declared.js +311 -0
- package/dist/bsx/declared.js.map +1 -0
- package/dist/bsx/index.d.ts +1 -0
- package/dist/bsx/index.d.ts.map +1 -1
- package/dist/bsx/index.js +1 -0
- package/dist/bsx/index.js.map +1 -1
- package/dist/bsx/infer.d.ts +40 -17
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +105 -49
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts +6 -2
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +65 -21
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +6 -1
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +32 -3
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +3 -0
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +45 -51
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +265 -138
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +2 -2
- package/dist/catalogs/index.d.ts +49 -71
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +1 -1
- package/dist/catalogs/logo.d.ts +14 -28
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +1 -2
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +1 -1
- package/dist/catalogs/parts/feedback.d.ts +3 -3
- package/dist/catalogs/parts/forms.d.ts +4 -4
- package/dist/catalogs/parts/html.d.ts +2 -2
- package/dist/catalogs/parts/icons.d.ts +2 -2
- package/dist/catalogs/parts/index.d.ts +35 -57
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +10 -25
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +12 -14
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +4 -4
- package/dist/catalogs/parts/overlays.d.ts +11 -11
- package/dist/catalogs/parts/run.d.ts +2 -10
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.d.ts +7 -15
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +1 -5
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/typography.d.ts +3 -3
- package/dist/catalogs/props.d.ts +2 -2
- package/dist/catalogs/scene.d.ts +5 -13
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/shadcn.d.ts +11 -11
- package/dist/catalogs/ui.d.ts +16 -16
- package/dist/logo/actionLogoSource.d.ts +3 -3
- package/dist/logo/actionLogoSource.d.ts.map +1 -1
- package/dist/logo/actionLogoSource.js +4 -4
- package/dist/logo/actionLogoSource.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +16 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +32 -13
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +3 -3
- package/dist/renderer/baseCatalog.js +2 -2
- package/dist/renderer/bloks/control.d.ts +18 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +85 -14
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +1 -1
- package/dist/renderer/bloks/feedback.d.ts +3 -3
- package/dist/renderer/bloks/forms.d.ts +4 -4
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/icons.d.ts +1 -1
- package/dist/renderer/bloks/index.d.ts +30 -37
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +1 -8
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +1 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
- package/dist/renderer/bloks/navigation.d.ts +4 -4
- package/dist/renderer/bloks/overlays.d.ts +11 -11
- package/dist/renderer/bloks/run/components.d.ts +1 -5
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.js +4 -2
- package/dist/renderer/bloks/scene/Scene.js.map +1 -1
- package/dist/renderer/bloks/scene/host.d.ts +2 -0
- package/dist/renderer/bloks/scene/host.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/host.js +8 -0
- package/dist/renderer/bloks/scene/host.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +4 -8
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +3 -2
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +2 -2
- package/dist/renderer/bloks/typography.d.ts +3 -3
- package/dist/renderer/declarations.d.ts +40 -33
- package/dist/renderer/declarations.d.ts.map +1 -1
- package/dist/renderer/declarations.js +41 -56
- package/dist/renderer/declarations.js.map +1 -1
- package/dist/renderer/declare.js +4 -4
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/persist.d.ts +22 -13
- package/dist/renderer/persist.d.ts.map +1 -1
- package/dist/renderer/persist.js +40 -21
- package/dist/renderer/persist.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +4 -4
- package/dist/renderer/runtime/catalog.js +3 -3
- package/dist/renderer/runtime/components.d.ts +4 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +5 -5
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +5 -5
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +11 -5
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +3 -3
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +2 -2
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +8 -4
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +1 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +1 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/locals.d.ts +57 -0
- package/dist/renderer/runtime/locals.d.ts.map +1 -0
- package/dist/renderer/runtime/locals.js +87 -0
- package/dist/renderer/runtime/locals.js.map +1 -0
- package/dist/renderer/runtime/scope.d.ts +14 -0
- package/dist/renderer/runtime/scope.d.ts.map +1 -1
- package/dist/renderer/runtime/scope.js +25 -3
- package/dist/renderer/runtime/scope.js.map +1 -1
- package/dist/renderer/runtime/tree.d.ts.map +1 -1
- package/dist/renderer/runtime/tree.js +7 -1
- package/dist/renderer/runtime/tree.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +8 -3
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/shadcn.d.ts +36 -43
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +1 -2
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +11067 -6321
- package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
- package/dist/spec/catalogs/orkestrator@1.json +10 -10
- package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
- package/dist/spec/catalogs.d.ts +4 -4
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +7 -7
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +25 -4
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +50 -5
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +58 -32
- package/dist/spec/vocabulary.json.js +58 -32
- package/package.json +1 -1
- package/src/bsx/analyze.ts +14 -12
- package/src/bsx/bsx.test.ts +4 -4
- package/src/bsx/declared.ts +346 -0
- package/src/bsx/index.ts +1 -0
- package/src/bsx/infer.test.ts +42 -32
- package/src/bsx/infer.ts +128 -71
- package/src/bsx/language.test.ts +37 -25
- package/src/bsx/language.ts +72 -25
- package/src/bsx/parse.ts +34 -3
- package/src/bsx/print.ts +3 -0
- package/src/bsx/references.test.ts +82 -81
- package/src/bsx/references.ts +313 -178
- package/src/catalogs/catalogs.test.ts +3 -2
- package/src/catalogs/index.ts +1 -1
- package/src/catalogs/logo.ts +1 -2
- package/src/catalogs/parts/logo.ts +13 -17
- package/src/catalogs/parts/scene.ts +1 -7
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.test.tsx +22 -0
- package/src/renderer/BlokRenderer.tsx +70 -20
- package/src/renderer/addBlokComponents.test.tsx +1 -1
- package/src/renderer/baseCatalog.ts +2 -2
- package/src/renderer/bloks/control.tsx +119 -16
- package/src/renderer/bloks/logo/index.tsx +2 -3
- package/src/renderer/bloks/logo/logo.fixture.json +266 -250
- package/src/renderer/bloks/logo/logo.test.tsx +18 -7
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/Scene.tsx +4 -2
- package/src/renderer/bloks/scene/host.tsx +11 -0
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- package/src/renderer/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +4 -4
- package/src/renderer/declare.ts +4 -4
- package/src/renderer/persist.test.ts +70 -49
- package/src/renderer/persist.ts +57 -34
- package/src/renderer/runtime/catalog.test.ts +2 -2
- package/src/renderer/runtime/catalog.ts +4 -4
- package/src/renderer/runtime/components.tsx +8 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +5 -5
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/shadcn.ts +1 -2
- package/src/spec/bsx_v2.json +11067 -6321
- package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/src/spec/catalogs/orkestrator@1.json +10 -10
- package/src/spec/catalogs.ts +8 -8
- package/src/spec/spec.test.ts +19 -16
- package/src/spec/vocabulary.json +58 -32
- package/src/spec/vocabulary.ts +69 -10
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type KeptComponentState,
|
|
11
11
|
type KeptLocals,
|
|
12
12
|
} from "./persist";
|
|
13
|
-
import { createBlokRuntimeStore } from "./runtime";
|
|
13
|
+
import { createBlokRuntimeStore, getValueAtPath, localValuePath, runtimeIdOf } from "./runtime";
|
|
14
14
|
|
|
15
15
|
// No IndexedDB in node: the keyed store keeps what it saves in memory, as a window does.
|
|
16
16
|
const freshStore = () =>
|
|
@@ -32,13 +32,18 @@ const freshComponentStore = () =>
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
const SCOPE = { hub: "h1", user: "u1", materializedBlok: "7" };
|
|
35
|
-
/** The blok's locals: ports plus persist
|
|
35
|
+
/** The blok's locals as the tree resolves them: ports plus persist, each by its `<local>` node. */
|
|
36
|
+
const ITERATIONS = "Blok[0]/local[0]";
|
|
37
|
+
const POSE = "Blok[0]/local[1]";
|
|
38
|
+
const LABEL = "Blok[0]/local[2]";
|
|
39
|
+
/** The local inside a foreach: one value per item. */
|
|
40
|
+
const OPEN = "Blok[0]/foreach[0]/local[0]";
|
|
36
41
|
const LOCALS: BlokLocal[] = [
|
|
37
|
-
{ key: "iterations", kind: "INT", default: 15, persist: true },
|
|
38
|
-
{ key: "pose", kind: "LIST", default: [1, 0, 0, 0], persist: true },
|
|
39
|
-
{ key: "label", kind: "STRING", default: "x" },
|
|
42
|
+
{ node: ITERATIONS, key: "iterations", kind: "INT", default: 15, persist: true },
|
|
43
|
+
{ node: POSE, key: "pose", kind: "LIST", default: [1, 0, 0, 0], persist: true },
|
|
44
|
+
{ node: LABEL, key: "label", kind: "STRING", default: "x" },
|
|
45
|
+
{ node: OPEN, key: "open", kind: "BOOL", default: false, persist: true },
|
|
40
46
|
];
|
|
41
|
-
const DEFAULTS = { iterations: 15, pose: [1, 0, 0, 0], label: "x" };
|
|
42
47
|
|
|
43
48
|
beforeEach(() => {
|
|
44
49
|
vi.useFakeTimers();
|
|
@@ -53,105 +58,121 @@ afterEach(() => {
|
|
|
53
58
|
const open = (store: ReturnType<typeof freshStore>, locals = LOCALS) =>
|
|
54
59
|
openBlokPersistence({ scope: SCOPE, locals, store, componentStore: freshComponentStore(), delay: 100 });
|
|
55
60
|
|
|
56
|
-
/** A runtime as a materialized blok seeds it: the
|
|
57
|
-
const runtimeFor = (initial: KeptLocals,
|
|
58
|
-
createBlokRuntimeStore({ initialDataModel: DEFAULTS, keptValues: initial, keptRoots: keys });
|
|
61
|
+
/** A runtime as a materialized blok seeds it: the kept values at their locals' paths. */
|
|
62
|
+
const runtimeFor = (initial: KeptLocals, locals: ReadonlySet<string>) => createBlokRuntimeStore({ keptValues: initial, keptLocals: locals });
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
/** What the runtime holds for the local of `runtimeId` (undefined: nothing written, it reads its default). */
|
|
65
|
+
const valueOf = (runtime: ReturnType<typeof runtimeFor>, runtimeId: string) => getValueAtPath(runtime.getState().dataModel, localValuePath(runtimeId));
|
|
66
|
+
const write = (runtime: ReturnType<typeof runtimeFor>, runtimeId: string, value: unknown, below = "") =>
|
|
67
|
+
runtime.getState().setRuntimeValue(`${localValuePath(runtimeId)}${below}`, value);
|
|
68
|
+
|
|
69
|
+
describe("kept blok locals: <local persist>", () => {
|
|
61
70
|
it("keeps only the locals declared with persist", async () => {
|
|
62
71
|
const persistence = await open(freshStore());
|
|
63
|
-
expect([...persistence.
|
|
72
|
+
expect([...persistence.locals].sort()).toEqual([OPEN, ITERATIONS, POSE].sort());
|
|
64
73
|
});
|
|
65
74
|
|
|
66
|
-
it("seeds what was kept before the first render, and nothing for a first opening", async () => {
|
|
75
|
+
it("seeds what was kept before the first render, by runtime id, and nothing for a first opening", async () => {
|
|
67
76
|
const store = freshStore();
|
|
68
77
|
const first = await open(store);
|
|
69
78
|
expect(first.initial).toEqual({});
|
|
70
79
|
|
|
71
|
-
await store.save(keptLocalsId(SCOPE), "locals", {
|
|
80
|
+
await store.save(keptLocalsId(SCOPE), "locals", { [ITERATIONS]: 30, [runtimeIdOf(OPEN, ["7"])]: true });
|
|
72
81
|
const again = await open(store);
|
|
73
|
-
expect(again.initial).toEqual({
|
|
74
|
-
const runtime = runtimeFor(again.initial, again.
|
|
75
|
-
expect((runtime
|
|
82
|
+
expect(again.initial).toEqual({ [ITERATIONS]: 30, [`${OPEN}@7`]: true });
|
|
83
|
+
const runtime = runtimeFor(again.initial, again.locals);
|
|
84
|
+
expect(valueOf(runtime, ITERATIONS)).toBe(30);
|
|
85
|
+
expect(valueOf(runtime, `${OPEN}@7`)).toBe(true);
|
|
86
|
+
expect(valueOf(runtime, `${OPEN}@8`)).toBeUndefined();
|
|
76
87
|
});
|
|
77
88
|
|
|
78
|
-
it("writes a change of a kept local once, after the last change settles", async () => {
|
|
89
|
+
it("writes a change of a kept local once, after the last change settles, one value per foreach item", async () => {
|
|
79
90
|
const store = freshStore();
|
|
80
91
|
const save = vi.spyOn(store, "save");
|
|
81
92
|
const persistence = await open(store);
|
|
82
|
-
const runtime = runtimeFor(persistence.initial, persistence.
|
|
93
|
+
const runtime = runtimeFor(persistence.initial, persistence.locals);
|
|
83
94
|
const detach = persistence.attach(runtime);
|
|
84
95
|
|
|
85
|
-
runtime
|
|
86
|
-
runtime
|
|
87
|
-
runtime
|
|
96
|
+
write(runtime, POSE, [2, 0, 0, 0]);
|
|
97
|
+
write(runtime, POSE, 3, "/0");
|
|
98
|
+
write(runtime, LABEL, "not kept");
|
|
99
|
+
write(runtime, `${OPEN}@a`, true);
|
|
88
100
|
expect(save).not.toHaveBeenCalled();
|
|
89
101
|
await vi.advanceTimersByTimeAsync(100);
|
|
90
102
|
expect(save).toHaveBeenCalledTimes(1);
|
|
91
|
-
expect(await store.load(keptLocalsId(SCOPE), "locals")).toEqual({
|
|
103
|
+
expect(await store.load(keptLocalsId(SCOPE), "locals")).toEqual({ [POSE]: [3, 0, 0, 0], [`${OPEN}@a`]: true });
|
|
92
104
|
detach();
|
|
93
105
|
});
|
|
94
106
|
|
|
95
107
|
it("writes what is pending when the blok closes, and nothing back at the default", async () => {
|
|
96
108
|
const store = freshStore();
|
|
97
109
|
const persistence = await open(store);
|
|
98
|
-
const runtime = runtimeFor(persistence.initial, persistence.
|
|
110
|
+
const runtime = runtimeFor(persistence.initial, persistence.locals);
|
|
99
111
|
const detach = persistence.attach(runtime);
|
|
100
|
-
runtime
|
|
112
|
+
write(runtime, ITERATIONS, 4);
|
|
113
|
+
write(runtime, `${OPEN}@a`, false);
|
|
101
114
|
detach();
|
|
102
115
|
await vi.runAllTimersAsync();
|
|
103
|
-
expect(await store.load(keptLocalsId(SCOPE), "locals")).toEqual({
|
|
116
|
+
expect(await store.load(keptLocalsId(SCOPE), "locals")).toEqual({ [ITERATIONS]: 4 });
|
|
104
117
|
});
|
|
105
118
|
|
|
106
119
|
it("keeps the kept locals across a reset of the runtime values", async () => {
|
|
107
120
|
const persistence = await open(freshStore());
|
|
108
|
-
const runtime = runtimeFor(persistence.initial, persistence.
|
|
109
|
-
runtime
|
|
110
|
-
runtime
|
|
121
|
+
const runtime = runtimeFor(persistence.initial, persistence.locals);
|
|
122
|
+
write(runtime, POSE, [5, 0, 0, 0]);
|
|
123
|
+
write(runtime, `${OPEN}@a`, true);
|
|
124
|
+
write(runtime, LABEL, "edited");
|
|
111
125
|
runtime.getState().resetRuntimeValues();
|
|
112
|
-
|
|
113
|
-
expect(
|
|
114
|
-
expect(
|
|
126
|
+
expect(valueOf(runtime, POSE)).toEqual([5, 0, 0, 0]);
|
|
127
|
+
expect(valueOf(runtime, `${OPEN}@a`)).toBe(true);
|
|
128
|
+
expect(valueOf(runtime, LABEL)).toBeUndefined();
|
|
115
129
|
});
|
|
116
130
|
|
|
117
131
|
it("forgets every kept local and shows the defaults again", async () => {
|
|
118
132
|
const store = freshStore();
|
|
119
|
-
await store.save(keptLocalsId(SCOPE), "locals", {
|
|
133
|
+
await store.save(keptLocalsId(SCOPE), "locals", { [POSE]: [0, 1, 0, 0], [ITERATIONS]: 3 });
|
|
120
134
|
const persistence = await open(store);
|
|
121
|
-
const runtime = runtimeFor(persistence.initial, persistence.
|
|
135
|
+
const runtime = runtimeFor(persistence.initial, persistence.locals);
|
|
122
136
|
persistence.attach(runtime);
|
|
123
137
|
await persistence.resetLocals();
|
|
124
|
-
expect((runtime
|
|
138
|
+
expect(valueOf(runtime, POSE)).toBeUndefined();
|
|
125
139
|
expect(await store.load(keptLocalsId(SCOPE), "locals")).toBeNull();
|
|
126
140
|
});
|
|
127
141
|
|
|
128
142
|
it("drops what no longer persists or no longer fits its port", async () => {
|
|
129
143
|
const store = freshStore();
|
|
130
|
-
await store.save(keptLocalsId(SCOPE), "locals", {
|
|
144
|
+
await store.save(keptLocalsId(SCOPE), "locals", { [POSE]: { x: 1 }, [ITERATIONS]: 2.5, [LABEL]: "kept?", "Blok[0]/local[9]": true, [`${OPEN}@a`]: 3 });
|
|
145
|
+
expect((await open(store)).initial).toEqual({});
|
|
146
|
+
await store.save(keptLocalsId(SCOPE), "locals", { [ITERATIONS]: 2 });
|
|
147
|
+
expect((await open(store)).initial).toEqual({ [ITERATIONS]: 2 });
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("drops what a blok kept by top-level key, before locals were kept by runtime id", async () => {
|
|
151
|
+
const store = freshStore();
|
|
152
|
+
await store.save(keptLocalsId(SCOPE), "locals", { iterations: 30 });
|
|
131
153
|
expect((await open(store)).initial).toEqual({});
|
|
132
|
-
await store.save(keptLocalsId(SCOPE), "locals", { iterations: 2 });
|
|
133
|
-
expect((await open(store)).initial).toEqual({ iterations: 2 });
|
|
134
154
|
});
|
|
135
155
|
|
|
136
156
|
it("keeps nothing for another user or hub", async () => {
|
|
137
157
|
const store = freshStore();
|
|
138
|
-
await store.save(keptLocalsId(SCOPE), "locals", {
|
|
158
|
+
await store.save(keptLocalsId(SCOPE), "locals", { [ITERATIONS]: 2 });
|
|
139
159
|
const other = await openBlokPersistence({ scope: { ...SCOPE, user: "u2" }, locals: LOCALS, store, componentStore: freshComponentStore() });
|
|
140
160
|
expect(other.initial).toEqual({});
|
|
141
161
|
});
|
|
142
162
|
|
|
143
163
|
it("checks a kept value against the local's port", () => {
|
|
144
|
-
|
|
145
|
-
expect(fitsLocal(3
|
|
146
|
-
expect(fitsLocal(3.5, { key: "n", kind: "
|
|
147
|
-
expect(fitsLocal(
|
|
148
|
-
expect(fitsLocal(
|
|
149
|
-
expect(fitsLocal(
|
|
150
|
-
expect(fitsLocal(
|
|
151
|
-
expect(fitsLocal(
|
|
152
|
-
expect(fitsLocal("
|
|
153
|
-
expect(fitsLocal("
|
|
154
|
-
expect(fitsLocal(
|
|
164
|
+
const local = (port: Omit<BlokLocal, "node">): BlokLocal => ({ node: "n", ...port });
|
|
165
|
+
expect(fitsLocal(3, local({ key: "n", kind: "INT" }))).toBe(true);
|
|
166
|
+
expect(fitsLocal(3.5, local({ key: "n", kind: "INT" }))).toBe(false);
|
|
167
|
+
expect(fitsLocal(3.5, local({ key: "n", kind: "FLOAT" }))).toBe(true);
|
|
168
|
+
expect(fitsLocal(true, local({ key: "n", kind: "FLOAT" }))).toBe(false);
|
|
169
|
+
expect(fitsLocal("a", local({ key: "s", kind: "STRING" }))).toBe(true);
|
|
170
|
+
expect(fitsLocal({ object: "4", __identifier: "@mikro/image" }, local({ key: "img", kind: "STRUCTURE", identifier: "@mikro/image" }))).toBe(true);
|
|
171
|
+
expect(fitsLocal([1], local({ key: "l", kind: "LIST" }))).toBe(true);
|
|
172
|
+
expect(fitsLocal("x", local({ key: "l", kind: "LIST" }))).toBe(false);
|
|
173
|
+
expect(fitsLocal("fast", local({ key: "m", kind: "ENUM", choices: [{ value: "fast" }] }))).toBe(true);
|
|
174
|
+
expect(fitsLocal("slow", local({ key: "m", kind: "ENUM", choices: [{ value: "fast" }] }))).toBe(false);
|
|
175
|
+
expect(fitsLocal(null, local({ key: "n", kind: "INT" }))).toBe(true);
|
|
155
176
|
});
|
|
156
177
|
});
|
|
157
178
|
|
package/src/renderer/persist.ts
CHANGED
|
@@ -3,13 +3,16 @@ import type {KeyedStore, KeyedStoreOptions} from '../cache/keyedStore';
|
|
|
3
3
|
import {blokPlatform} from '../platform';
|
|
4
4
|
import {valueFitsPort} from '../spec/locals';
|
|
5
5
|
import {isExplicitId} from '../spec/vocabulary';
|
|
6
|
-
import
|
|
6
|
+
import {nodeOfRuntimeId} from '../bsx/declared';
|
|
7
|
+
import {LOCALS_ROOT, localNodeOfPath, runtimeIdOfPath, type BlokRuntimeStore} from './runtime';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* What a blok keeps between openings, on this device only (blok language v2):
|
|
10
11
|
*
|
|
11
|
-
* - **form inputs**: a local declared
|
|
12
|
-
*
|
|
12
|
+
* - **form inputs**: a local declared `<local name="x" default={...} persist />`
|
|
13
|
+
* remembers the viewer's last input, by its runtime id: the `<local>`'s node
|
|
14
|
+
* id, plus `@<item key>` per enclosing foreach (one value per item). An
|
|
15
|
+
* explicit `id=` on the `<local>` keeps it across edits of the tree;
|
|
13
16
|
* - **component state**: a component that offers it as its own BOOL prop
|
|
14
17
|
* (`<Scene id="main" persist>`, `<Transform id="arm-pose" persist>`) keeps
|
|
15
18
|
* its interaction state (the camera, the pose) by its id. The language
|
|
@@ -17,10 +20,10 @@ import type {BlokRuntimeStore} from './runtime';
|
|
|
17
20
|
*
|
|
18
21
|
* Nothing reaches a server, so keeping cannot become a channel between
|
|
19
22
|
* clients. Values live in IndexedDB keyed by (hub, user, materialized blok)
|
|
20
|
-
* for the locals
|
|
21
|
-
* component, and are written a
|
|
22
|
-
*
|
|
23
|
-
* dropped when the blok opens.
|
|
23
|
+
* for the locals (one record, values by runtime id) and (hub, user,
|
|
24
|
+
* materialized blok, component id) for each component, and are written a
|
|
25
|
+
* moment after the last change. A local the blok no longer persists, or a
|
|
26
|
+
* value that no longer fits its port, is dropped when the blok opens.
|
|
24
27
|
*/
|
|
25
28
|
|
|
26
29
|
/** A choice a local's port offers (`ChoiceInput`). */
|
|
@@ -44,10 +47,14 @@ export type BlokLocalPort = {
|
|
|
44
47
|
description?: string | null;
|
|
45
48
|
};
|
|
46
49
|
|
|
47
|
-
/**
|
|
48
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A `<local>` (vocabulary `locals`): an arg port plus `persist`, remembering
|
|
52
|
+
* the last input on this device, and `node`, the id of the `<local>` node
|
|
53
|
+
* that declares it.
|
|
54
|
+
*/
|
|
55
|
+
export type BlokLocal = BlokLocalPort & {node: string; persist?: boolean | null};
|
|
49
56
|
|
|
50
|
-
/** What is kept for one materialization's locals: values by local
|
|
57
|
+
/** What is kept for one materialization's locals: values by the local's runtime id (`runtimeIdOf`). */
|
|
51
58
|
export type KeptLocals = Record<string, unknown>;
|
|
52
59
|
|
|
53
60
|
/** Whose a kept record is: the hub and user it was set under, and the materialization. */
|
|
@@ -68,10 +75,11 @@ const lazyKeyedStore = <T,>(options: KeyedStoreOptions<T>): KeyedStore<T> => {
|
|
|
68
75
|
const isKeptLocals = (value: unknown): value is KeptLocals =>
|
|
69
76
|
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
70
77
|
|
|
78
|
+
/** Version 2: kept values by runtime id (version 1 kept them by top-level key, and is dropped). */
|
|
71
79
|
export const keptLocalsStore: KeyedStore<KeptLocals> = lazyKeyedStore<KeptLocals>({
|
|
72
80
|
db: 'orkestrator-blok-locals',
|
|
73
81
|
store: 'locals',
|
|
74
|
-
version:
|
|
82
|
+
version: 2,
|
|
75
83
|
isValue: isKeptLocals,
|
|
76
84
|
label: 'kept blok local',
|
|
77
85
|
});
|
|
@@ -107,11 +115,14 @@ export const fitsLocal = (kept: unknown, local: BlokLocal): boolean => {
|
|
|
107
115
|
return valueFitsPort(kept, local);
|
|
108
116
|
};
|
|
109
117
|
|
|
118
|
+
/** What of `record` still stands: the values of persisted locals (by their node) that still fit their port. */
|
|
110
119
|
export const keptValuesOf = (record: KeptLocals | null, locals: readonly BlokLocal[]): {values: KeptLocals; dropped: boolean} => {
|
|
111
120
|
const values: KeptLocals = {};
|
|
112
121
|
if (!record) return {values, dropped: false};
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
const persisted = new Map(locals.filter(local => local.persist).map(local => [local.node, local] as const));
|
|
123
|
+
for (const [runtimeId, value] of Object.entries(record)) {
|
|
124
|
+
const local = persisted.get(nodeOfRuntimeId(runtimeId));
|
|
125
|
+
if (local && fitsLocal(value, local)) values[runtimeId] = value;
|
|
115
126
|
}
|
|
116
127
|
return {values, dropped: Object.keys(values).length !== Object.keys(record).length};
|
|
117
128
|
};
|
|
@@ -123,9 +134,9 @@ const same = (a: unknown, b: unknown): boolean => JSON.stringify(a ?? null) ===
|
|
|
123
134
|
* seed the renderer with, and what writes changes back.
|
|
124
135
|
*/
|
|
125
136
|
export type BlokPersistence = {
|
|
126
|
-
/** The
|
|
127
|
-
|
|
128
|
-
/** The kept
|
|
137
|
+
/** The `<local>` node ids kept on this device (those declared with `persist`): `BlokRenderer`'s `keptLocals`. */
|
|
138
|
+
locals: ReadonlySet<string>;
|
|
139
|
+
/** The kept values to seed the runtime with, before the first render, by runtime id: `BlokRenderer`'s `keptValues`. */
|
|
129
140
|
initial: KeptLocals;
|
|
130
141
|
/** Follows `store`: a change of a kept local is written after `delay`. Returns the detach, which flushes. */
|
|
131
142
|
attach: (store: BlokRuntimeStore) => () => void;
|
|
@@ -173,9 +184,21 @@ export const componentStateStore = (
|
|
|
173
184
|
};
|
|
174
185
|
};
|
|
175
186
|
|
|
187
|
+
/** The values of the kept locals in `dataModel`, by runtime id: every item's, in a foreach. */
|
|
188
|
+
const keptIn = (dataModel: unknown, locals: ReadonlySet<string>): Map<string, unknown> => {
|
|
189
|
+
const found = new Map<string, unknown>();
|
|
190
|
+
const values = (dataModel as Record<string, unknown> | null)?.[LOCALS_ROOT];
|
|
191
|
+
if (typeof values !== 'object' || values === null) return found;
|
|
192
|
+
for (const [segment, value] of Object.entries(values as Record<string, unknown>)) {
|
|
193
|
+
const runtimeId = runtimeIdOfPath(`${LOCALS_ROOT}/${segment}`);
|
|
194
|
+
if (runtimeId !== null && locals.has(nodeOfRuntimeId(runtimeId))) found.set(runtimeId, value);
|
|
195
|
+
}
|
|
196
|
+
return found;
|
|
197
|
+
};
|
|
198
|
+
|
|
176
199
|
export const openBlokPersistence = async (options: {
|
|
177
200
|
scope: BlokPersistScope;
|
|
178
|
-
/** The blok's
|
|
201
|
+
/** The blok's resolved locals (by node); those with `persist` are kept. */
|
|
179
202
|
locals: readonly BlokLocal[];
|
|
180
203
|
store?: KeyedStore<KeptLocals>;
|
|
181
204
|
componentStore?: KeyedStore<KeptComponentState>;
|
|
@@ -186,9 +209,9 @@ export const openBlokPersistence = async (options: {
|
|
|
186
209
|
const delay = options.delay ?? 400;
|
|
187
210
|
const id = keptLocalsId(options.scope);
|
|
188
211
|
const persisted = options.locals.filter(local => local.persist);
|
|
189
|
-
const
|
|
190
|
-
const defaults = new Map(options.locals.map(local => [local.
|
|
191
|
-
const record =
|
|
212
|
+
const locals = new Set(persisted.map(local => local.node));
|
|
213
|
+
const defaults = new Map(options.locals.map(local => [local.node, local.default ?? null] as const));
|
|
214
|
+
const record = locals.size > 0 ? await store.load(id, LOCALS_RECORD) : null;
|
|
192
215
|
const {values: initial, dropped} = keptValuesOf(record, persisted);
|
|
193
216
|
if (dropped) {
|
|
194
217
|
await (Object.keys(initial).length > 0 ? store.save(id, LOCALS_RECORD, initial) : store.forget(id));
|
|
@@ -210,27 +233,27 @@ export const openBlokPersistence = async (options: {
|
|
|
210
233
|
};
|
|
211
234
|
|
|
212
235
|
return {
|
|
213
|
-
|
|
236
|
+
locals,
|
|
214
237
|
initial,
|
|
215
238
|
attach: target => {
|
|
216
239
|
runtime = target;
|
|
217
|
-
|
|
218
|
-
const seen = new Map([...keys].map(key => [key, valueOf(key)] as const));
|
|
240
|
+
let seen = keptIn(target.getState().dataModel, locals);
|
|
219
241
|
const unsubscribe = target.subscribe(state => {
|
|
242
|
+
const now = keptIn(state.dataModel, locals);
|
|
220
243
|
let changed = false;
|
|
221
|
-
for (const
|
|
222
|
-
const value = (
|
|
223
|
-
if (same(value, seen.get(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
delete kept[key];
|
|
244
|
+
for (const runtimeId of new Set([...seen.keys(), ...now.keys()])) {
|
|
245
|
+
const value = now.get(runtimeId);
|
|
246
|
+
if (same(value, seen.get(runtimeId))) continue;
|
|
247
|
+
// Back at the default (or cleared) is nothing to keep.
|
|
248
|
+
if (value === undefined || same(value, defaults.get(nodeOfRuntimeId(runtimeId)))) {
|
|
249
|
+
if (!(runtimeId in kept)) continue;
|
|
250
|
+
delete kept[runtimeId];
|
|
229
251
|
} else {
|
|
230
|
-
kept[
|
|
252
|
+
kept[runtimeId] = value;
|
|
231
253
|
}
|
|
232
254
|
changed = true;
|
|
233
255
|
}
|
|
256
|
+
seen = now;
|
|
234
257
|
if (changed) schedule();
|
|
235
258
|
});
|
|
236
259
|
return () => {
|
|
@@ -244,8 +267,8 @@ export const openBlokPersistence = async (options: {
|
|
|
244
267
|
const state = runtime?.getState();
|
|
245
268
|
if (state) {
|
|
246
269
|
for (const path of Object.keys(state.runtimePathValues)) {
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
270
|
+
const node = localNodeOfPath(path);
|
|
271
|
+
if (node !== null && locals.has(node)) state.clearRuntimeValue(path);
|
|
249
272
|
}
|
|
250
273
|
}
|
|
251
274
|
await write();
|
|
@@ -65,7 +65,7 @@ describe('describeBlokContract', () => {
|
|
|
65
65
|
{
|
|
66
66
|
name: 'Knob',
|
|
67
67
|
description: 'A knob.',
|
|
68
|
-
context: '
|
|
68
|
+
context: 'PANEL',
|
|
69
69
|
children_context: null,
|
|
70
70
|
inherits_context: false,
|
|
71
71
|
accepts_children: false,
|
|
@@ -87,7 +87,7 @@ describe('describeBlokContract', () => {
|
|
|
87
87
|
{
|
|
88
88
|
name: 'Label',
|
|
89
89
|
description: 'A label.',
|
|
90
|
-
context: '
|
|
90
|
+
context: 'PANEL',
|
|
91
91
|
children_context: null,
|
|
92
92
|
inherits_context: false,
|
|
93
93
|
accepts_children: false,
|
|
@@ -8,7 +8,7 @@ import type {BlokComponentContract, BlokComponentDefinition, BlokRenderArgs} fro
|
|
|
8
8
|
* each takes: name, schema, placement. It draws nothing. There are two sorts:
|
|
9
9
|
*
|
|
10
10
|
* - A *family* of the base catalog (`ui`, `html`, `shadcn`, `structure`,
|
|
11
|
-
* `scene`, `logo`): `partOf` names the catalog it is part of (`base@
|
|
11
|
+
* `scene`, `logo`): `partOf` names the catalog it is part of (`base@4`). The
|
|
12
12
|
* base catalog is the spec's, and every renderer draws it whole; the families
|
|
13
13
|
* are how this package holds its contracts, one toolkit at a time.
|
|
14
14
|
* - A UI's *own* catalog (the Orkestrator's MikroScene parts): what it draws
|
|
@@ -20,9 +20,9 @@ import type {BlokComponentContract, BlokComponentDefinition, BlokRenderArgs} fro
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
/** The base catalog, as components of it are tagged (`origin`). */
|
|
23
|
-
export const BASE_CATALOG_REF = 'base@
|
|
23
|
+
export const BASE_CATALOG_REF = 'base@4';
|
|
24
24
|
/** The address the base catalog is published at: what a blok is written for when it names none. */
|
|
25
|
-
export const BASE_CATALOG_ADDRESS = 'https://arkitekt.live/catalogs/base/
|
|
25
|
+
export const BASE_CATALOG_ADDRESS = 'https://arkitekt.live/catalogs/base/v4';
|
|
26
26
|
|
|
27
27
|
export type BlokComponentContracts = Record<string, BlokComponentContract<any>>;
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ export type BlokCatalogContract<TComponents extends BlokComponentContracts = Blo
|
|
|
32
32
|
version: number | null;
|
|
33
33
|
description: string;
|
|
34
34
|
components: TComponents;
|
|
35
|
-
/** For a family: the catalog it is part of (`base@
|
|
35
|
+
/** For a family: the catalog it is part of (`base@4`). Null on a catalog of its own. */
|
|
36
36
|
partOf: string | null;
|
|
37
37
|
/** For a published catalog: the address it is published at, which is what a blok names it by. */
|
|
38
38
|
id: string | null;
|
|
@@ -15,8 +15,8 @@ export type BlokRenderArgs<TSchema extends BlokObjectSchema = BlokObjectSchema>
|
|
|
15
15
|
schema: TSchema;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
/** The renderer a component lives in. A blok's tree starts in `
|
|
19
|
-
export type BlokComponentContext = '
|
|
18
|
+
/** The renderer a component lives in. A blok's tree starts in `panel`. */
|
|
19
|
+
export type BlokComponentContext = 'panel' | 'scene' | 'logo';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Where a component may sit in a tree. Published with the catalog, so the
|
|
@@ -88,7 +88,7 @@ export type BlokComponentDefinition = BlokComponentApi & {
|
|
|
88
88
|
name: string;
|
|
89
89
|
schema: BlokObjectSchema;
|
|
90
90
|
render: React.ComponentType<BlokRenderArgs>;
|
|
91
|
-
/** The catalog it is of (`base@
|
|
91
|
+
/** The catalog it is of (`base@4` for a component of one of its families, `newswitch`); unset for one built on its own. */
|
|
92
92
|
origin?: string;
|
|
93
93
|
};
|
|
94
94
|
|
|
@@ -197,8 +197,8 @@ export class BlokNodeBoundary extends React.Component<
|
|
|
197
197
|
/* Statuses, guards and boundaries */
|
|
198
198
|
/* -------------------------------------------------------------------------- */
|
|
199
199
|
|
|
200
|
-
/** The renderer a node draws in: what decides how a pending node shows (a skeleton only in
|
|
201
|
-
export const BlokDrawContext = React.createContext<BlokComponentContext>('
|
|
200
|
+
/** The renderer a node draws in: what decides how a pending node shows (a skeleton only in a panel). */
|
|
201
|
+
export const BlokDrawContext = React.createContext<BlokComponentContext>('panel');
|
|
202
202
|
|
|
203
203
|
export const useBlokDrawContext = (): BlokComponentContext => React.useContext(BlokDrawContext);
|
|
204
204
|
|
|
@@ -288,7 +288,7 @@ const NodeGuard = (props: {
|
|
|
288
288
|
if (status.status === 'pending' || status.status === 'failed') {
|
|
289
289
|
// Inside a boundary its fallback or error shows; on its own a node shows
|
|
290
290
|
// its own skeleton or inline error, so a blok never blanks entirely.
|
|
291
|
-
if (caught || definition.placement?.inheritsContext || drawContext !== '
|
|
291
|
+
if (caught || definition.placement?.inheritsContext || drawContext !== 'panel') return null;
|
|
292
292
|
if (status.status === 'failed') {
|
|
293
293
|
return <BlokNodeError componentId={component.id} title="Could not load" detail={status.error ?? undefined} />;
|
|
294
294
|
}
|
|
@@ -309,7 +309,7 @@ const BlokComponentRendererInner = (props: {
|
|
|
309
309
|
const locked = useNodeLocked(props.props);
|
|
310
310
|
const parentContext = React.useContext(BlokDrawContext);
|
|
311
311
|
const placement = props.definition.placement ?? {};
|
|
312
|
-
const own = placement.inheritsContext ? parentContext : (placement.context ?? '
|
|
312
|
+
const own = placement.inheritsContext ? parentContext : (placement.context ?? 'panel');
|
|
313
313
|
const forChildren = placement.inheritsContext ? parentContext : (placement.childrenContext ?? own);
|
|
314
314
|
|
|
315
315
|
const rendered = (
|
|
@@ -335,7 +335,7 @@ const BlokComponentRendererInner = (props: {
|
|
|
335
335
|
// A node whose action a held lock keeps from running is marked for the `locked:`
|
|
336
336
|
// variant. The marker takes no box (`display: contents`), so the layout stays; a
|
|
337
337
|
// scene or a logo cannot hold an element, and is not marked.
|
|
338
|
-
if (!locked || own !== '
|
|
338
|
+
if (!locked || own !== 'panel') return rendered;
|
|
339
339
|
const Locked = blokPlatform().primitives.Locked ?? DomLocked;
|
|
340
340
|
return <Locked reason={locked}>{rendered}</Locked>;
|
|
341
341
|
};
|
|
@@ -4,6 +4,7 @@ import {useStore} from 'zustand';
|
|
|
4
4
|
import {createStore} from 'zustand/vanilla';
|
|
5
5
|
import {combineStatus, READY, type BlokSourceStatus} from './status';
|
|
6
6
|
import {isRecord, splitPathSegments} from './utils';
|
|
7
|
+
import {localNodeOfPath, localValuePath} from './locals';
|
|
7
8
|
import type {
|
|
8
9
|
BlokAgentMappingStateUpdates,
|
|
9
10
|
BlokDispatchActionHandler,
|
|
@@ -131,6 +132,12 @@ const isUnderRoot = (path: string, roots: ReadonlySet<string>): boolean => {
|
|
|
131
132
|
return root !== undefined && roots.has(root);
|
|
132
133
|
};
|
|
133
134
|
|
|
135
|
+
/** Whether a runtime value is a kept local's (one of `keptLocals`, in any foreach item). */
|
|
136
|
+
const isKeptLocal = (path: string, keptLocals: ReadonlySet<string>): boolean => {
|
|
137
|
+
const node = localNodeOfPath(path);
|
|
138
|
+
return node !== null && keptLocals.has(node);
|
|
139
|
+
};
|
|
140
|
+
|
|
134
141
|
export const createBlokRuntimeStore = (config?: {
|
|
135
142
|
initialDataModel?: unknown;
|
|
136
143
|
agentMappingStateUpdates?: BlokAgentMappingStateUpdates;
|
|
@@ -140,13 +147,13 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
140
147
|
unavailableDependencies?: BlokUnavailableDependencies;
|
|
141
148
|
lockedActions?: BlokLockedActions;
|
|
142
149
|
/**
|
|
143
|
-
* Locals the host kept from an earlier opening, by
|
|
144
|
-
* as runtime values
|
|
145
|
-
* them and clearing one shows its default again.
|
|
150
|
+
* Locals the host kept from an earlier opening, by runtime id (`runtimeIdOf`):
|
|
151
|
+
* written as runtime values at their paths (`localValuePath`), so the first
|
|
152
|
+
* render shows them and clearing one shows its default again.
|
|
146
153
|
*/
|
|
147
154
|
keptValues?: Record<string, unknown>;
|
|
148
|
-
/** The
|
|
149
|
-
|
|
155
|
+
/** The `<local>` node ids whose values a reset of the runtime values leaves alone (`keptValues`' and later edits of them). */
|
|
156
|
+
keptLocals?: ReadonlySet<string>;
|
|
150
157
|
/** Source statuses known before the first render (a preview's are all ready). */
|
|
151
158
|
statuses?: Readonly<Record<string, BlokSourceStatus>>;
|
|
152
159
|
travelAt?: string | null;
|
|
@@ -155,7 +162,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
155
162
|
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
156
163
|
}): BlokRuntimeStore => {
|
|
157
164
|
const initialDataModel = config?.initialDataModel;
|
|
158
|
-
const keptValues = config?.keptValues ?? {};
|
|
165
|
+
const keptValues = Object.fromEntries(Object.entries(config?.keptValues ?? {}).map(([runtimeId, value]) => [localValuePath(runtimeId), value]));
|
|
159
166
|
const initialAgentMappingStateUpdates = config?.agentMappingStateUpdates ?? {};
|
|
160
167
|
const invokeFunction = config?.invokeFunction ?? defaultInvokeFunction;
|
|
161
168
|
const dispatchAction = config?.dispatchAction ?? defaultDispatchAction;
|
|
@@ -164,7 +171,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
164
171
|
initialDataModel,
|
|
165
172
|
dataModel: modelOf(initialDataModel, config?.travelAt ?? null, keptValues),
|
|
166
173
|
runtimePathValues: {...keptValues},
|
|
167
|
-
|
|
174
|
+
keptLocals: config?.keptLocals ?? NONE_KEPT,
|
|
168
175
|
agentMappingStateUpdates: initialAgentMappingStateUpdates,
|
|
169
176
|
invokeFunction,
|
|
170
177
|
dispatchAction,
|
|
@@ -236,7 +243,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
236
243
|
set(currentState => {
|
|
237
244
|
const paths = Object.keys(currentState.runtimePathValues);
|
|
238
245
|
// What the host keeps between openings outlives a reset, as it outlives a reload.
|
|
239
|
-
const kept = paths.filter(path =>
|
|
246
|
+
const kept = paths.filter(path => isKeptLocal(path, currentState.keptLocals) || isUnderRoot(path, HOST_ROOTS));
|
|
240
247
|
if (kept.length === paths.length) {
|
|
241
248
|
return currentState;
|
|
242
249
|
}
|
|
@@ -248,8 +255,8 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
248
255
|
};
|
|
249
256
|
});
|
|
250
257
|
},
|
|
251
|
-
|
|
252
|
-
set({
|
|
258
|
+
setKeptLocals: nextKeptLocals => {
|
|
259
|
+
set({keptLocals: nextKeptLocals});
|
|
253
260
|
},
|
|
254
261
|
setRuntimeValue: (path, value) => {
|
|
255
262
|
set(currentState => {
|
|
@@ -5,7 +5,7 @@ import {isRequiredField} from './preflight';
|
|
|
5
5
|
import {isActionSchema, isBindSchema, unwrapSchema} from './schemas';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A contract in the spec's terms: what a catalog file (`spec/catalogs/base@
|
|
8
|
+
* A contract in the spec's terms: what a catalog file (`spec/catalogs/base@4.json`,
|
|
9
9
|
* arkitekt-spec's `blok/catalogs/`) says of each component. Written from the
|
|
10
10
|
* contract, never by hand: the zod schemas are the source of a component's
|
|
11
11
|
* props and documentation, the JSON what they say in the spec's terms. The
|
|
@@ -27,8 +27,8 @@ export type SpecPropJson = {
|
|
|
27
27
|
export type SpecComponentJson = {
|
|
28
28
|
name: string;
|
|
29
29
|
description: string | null;
|
|
30
|
-
context: '
|
|
31
|
-
children_context: '
|
|
30
|
+
context: 'PANEL' | 'SCENE' | 'LOGO';
|
|
31
|
+
children_context: 'PANEL' | 'SCENE' | 'LOGO' | null;
|
|
32
32
|
inherits_context: boolean;
|
|
33
33
|
accepts_children: boolean;
|
|
34
34
|
downstream_of: string[];
|
|
@@ -122,7 +122,7 @@ export const zodToSpecKind = (schema: z.ZodTypeAny): SpecValueKind => {
|
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
-
const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {
|
|
125
|
+
const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {panel: 'PANEL', scene: 'SCENE', logo: 'LOGO'};
|
|
126
126
|
|
|
127
127
|
const byKey = <T extends {key: string}>(left: T, right: T) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
|
|
128
128
|
const byName = <T extends {name: string}>(left: T, right: T) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
@@ -165,7 +165,7 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
|
|
|
165
165
|
return {
|
|
166
166
|
name,
|
|
167
167
|
description: component.schema.description ?? null,
|
|
168
|
-
context: CONTEXT[placement.context ?? '
|
|
168
|
+
context: CONTEXT[placement.context ?? 'panel'],
|
|
169
169
|
children_context: placement.childrenContext ? CONTEXT[placement.childrenContext] : null,
|
|
170
170
|
inherits_context: placement.inheritsContext ?? false,
|
|
171
171
|
accepts_children: component.acceptsChildren ?? CHILDREN in shape,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type BlokResolved,
|
|
17
17
|
} from './resolution';
|
|
18
18
|
import {isActionSchema} from './schemas';
|
|
19
|
-
import {isWritableScopedPath, readScopedPath, resolveScopedPath, useBlokScope} from './scope';
|
|
19
|
+
import {isWritableScopedPath, readScopedPath, resolveScopedPath, scopedWrite, useBlokScope} from './scope';
|
|
20
20
|
import {defaultBlokView} from '../../spec/catalogs';
|
|
21
21
|
import {useBlokNodeState} from './nodeState';
|
|
22
22
|
import {combineStatus, READY, type BlokSourceStatus} from './status';
|
|
@@ -680,13 +680,15 @@ export const useBinding = (
|
|
|
680
680
|
return undefined;
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
-
const absolutePath = resolveScopedPath(path, scope);
|
|
684
|
-
|
|
685
683
|
return {
|
|
686
684
|
value: snapshot.values.get(path),
|
|
687
685
|
// The past is read-only: a bound control shows what was, and writes nothing.
|
|
688
686
|
setValue: (value: unknown) => {
|
|
689
|
-
if (
|
|
687
|
+
if (travelling) return;
|
|
688
|
+
const state = store.getState();
|
|
689
|
+
const write = scopedWrite(state.dataModel, path, scope);
|
|
690
|
+
if (write.seed) state.setRuntimeValue(write.seed.path, write.seed.value);
|
|
691
|
+
store.getState().setRuntimeValue(write.path, value);
|
|
690
692
|
},
|
|
691
693
|
readOnly: travelling,
|
|
692
694
|
};
|