@arkitektio/bsx 5.0.0 → 6.0.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.
Files changed (220) hide show
  1. package/README.md +2 -2
  2. package/dist/bsx/analyze.d.ts +6 -5
  3. package/dist/bsx/analyze.d.ts.map +1 -1
  4. package/dist/bsx/analyze.js +12 -10
  5. package/dist/bsx/analyze.js.map +1 -1
  6. package/dist/bsx/declared.d.ts +111 -0
  7. package/dist/bsx/declared.d.ts.map +1 -0
  8. package/dist/bsx/declared.js +311 -0
  9. package/dist/bsx/declared.js.map +1 -0
  10. package/dist/bsx/index.d.ts +1 -0
  11. package/dist/bsx/index.d.ts.map +1 -1
  12. package/dist/bsx/index.js +1 -0
  13. package/dist/bsx/index.js.map +1 -1
  14. package/dist/bsx/infer.d.ts +40 -17
  15. package/dist/bsx/infer.d.ts.map +1 -1
  16. package/dist/bsx/infer.js +105 -49
  17. package/dist/bsx/infer.js.map +1 -1
  18. package/dist/bsx/language.d.ts +6 -2
  19. package/dist/bsx/language.d.ts.map +1 -1
  20. package/dist/bsx/language.js +65 -21
  21. package/dist/bsx/language.js.map +1 -1
  22. package/dist/bsx/parse.d.ts +6 -1
  23. package/dist/bsx/parse.d.ts.map +1 -1
  24. package/dist/bsx/parse.js +32 -3
  25. package/dist/bsx/parse.js.map +1 -1
  26. package/dist/bsx/print.d.ts.map +1 -1
  27. package/dist/bsx/print.js +3 -0
  28. package/dist/bsx/print.js.map +1 -1
  29. package/dist/bsx/references.d.ts +45 -51
  30. package/dist/bsx/references.d.ts.map +1 -1
  31. package/dist/bsx/references.js +265 -138
  32. package/dist/bsx/references.js.map +1 -1
  33. package/dist/catalogs/html.d.ts +2 -2
  34. package/dist/catalogs/index.d.ts +49 -71
  35. package/dist/catalogs/index.d.ts.map +1 -1
  36. package/dist/catalogs/index.js +1 -1
  37. package/dist/catalogs/logo.d.ts +14 -28
  38. package/dist/catalogs/logo.d.ts.map +1 -1
  39. package/dist/catalogs/logo.js +1 -2
  40. package/dist/catalogs/logo.js.map +1 -1
  41. package/dist/catalogs/parts/data.d.ts +1 -1
  42. package/dist/catalogs/parts/feedback.d.ts +3 -3
  43. package/dist/catalogs/parts/forms.d.ts +4 -4
  44. package/dist/catalogs/parts/html.d.ts +2 -2
  45. package/dist/catalogs/parts/icons.d.ts +2 -2
  46. package/dist/catalogs/parts/index.d.ts +35 -57
  47. package/dist/catalogs/parts/index.d.ts.map +1 -1
  48. package/dist/catalogs/parts/logo.d.ts +10 -25
  49. package/dist/catalogs/parts/logo.d.ts.map +1 -1
  50. package/dist/catalogs/parts/logo.js +12 -14
  51. package/dist/catalogs/parts/logo.js.map +1 -1
  52. package/dist/catalogs/parts/navigation.d.ts +4 -4
  53. package/dist/catalogs/parts/overlays.d.ts +11 -11
  54. package/dist/catalogs/parts/run.d.ts +2 -10
  55. package/dist/catalogs/parts/run.d.ts.map +1 -1
  56. package/dist/catalogs/parts/scene.d.ts +7 -15
  57. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  58. package/dist/catalogs/parts/scene.js +1 -5
  59. package/dist/catalogs/parts/scene.js.map +1 -1
  60. package/dist/catalogs/parts/typography.d.ts +3 -3
  61. package/dist/catalogs/props.d.ts +2 -2
  62. package/dist/catalogs/scene.d.ts +5 -13
  63. package/dist/catalogs/scene.d.ts.map +1 -1
  64. package/dist/catalogs/shadcn.d.ts +11 -11
  65. package/dist/catalogs/ui.d.ts +16 -16
  66. package/dist/logo/actionLogoSource.d.ts +3 -3
  67. package/dist/logo/actionLogoSource.d.ts.map +1 -1
  68. package/dist/logo/actionLogoSource.js +4 -4
  69. package/dist/logo/actionLogoSource.js.map +1 -1
  70. package/dist/renderer/BlokRenderer.d.ts +10 -6
  71. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  72. package/dist/renderer/BlokRenderer.js +23 -9
  73. package/dist/renderer/BlokRenderer.js.map +1 -1
  74. package/dist/renderer/baseCatalog.d.ts +3 -3
  75. package/dist/renderer/baseCatalog.js +2 -2
  76. package/dist/renderer/bloks/control.d.ts +18 -2
  77. package/dist/renderer/bloks/control.d.ts.map +1 -1
  78. package/dist/renderer/bloks/control.js +85 -14
  79. package/dist/renderer/bloks/control.js.map +1 -1
  80. package/dist/renderer/bloks/data.d.ts +1 -1
  81. package/dist/renderer/bloks/feedback.d.ts +3 -3
  82. package/dist/renderer/bloks/forms.d.ts +4 -4
  83. package/dist/renderer/bloks/html.d.ts +2 -2
  84. package/dist/renderer/bloks/icons.d.ts +1 -1
  85. package/dist/renderer/bloks/index.d.ts +30 -37
  86. package/dist/renderer/bloks/index.d.ts.map +1 -1
  87. package/dist/renderer/bloks/logo/index.d.ts +1 -8
  88. package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
  89. package/dist/renderer/bloks/logo/index.js +1 -2
  90. package/dist/renderer/bloks/logo/index.js.map +1 -1
  91. package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
  92. package/dist/renderer/bloks/navigation.d.ts +4 -4
  93. package/dist/renderer/bloks/overlays.d.ts +11 -11
  94. package/dist/renderer/bloks/run/components.d.ts +1 -5
  95. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  96. package/dist/renderer/bloks/scene/index.d.ts +4 -8
  97. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  98. package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
  99. package/dist/renderer/bloks/scene/interaction.js +3 -2
  100. package/dist/renderer/bloks/scene/interaction.js.map +1 -1
  101. package/dist/renderer/bloks/shared/props.d.ts +2 -2
  102. package/dist/renderer/bloks/typography.d.ts +3 -3
  103. package/dist/renderer/declarations.d.ts +40 -33
  104. package/dist/renderer/declarations.d.ts.map +1 -1
  105. package/dist/renderer/declarations.js +41 -56
  106. package/dist/renderer/declarations.js.map +1 -1
  107. package/dist/renderer/declare.js +4 -4
  108. package/dist/renderer/declare.js.map +1 -1
  109. package/dist/renderer/persist.d.ts +22 -13
  110. package/dist/renderer/persist.d.ts.map +1 -1
  111. package/dist/renderer/persist.js +40 -21
  112. package/dist/renderer/persist.js.map +1 -1
  113. package/dist/renderer/runtime/catalog.d.ts +4 -4
  114. package/dist/renderer/runtime/catalog.js +3 -3
  115. package/dist/renderer/runtime/components.d.ts +4 -4
  116. package/dist/renderer/runtime/components.d.ts.map +1 -1
  117. package/dist/renderer/runtime/components.js +5 -5
  118. package/dist/renderer/runtime/components.js.map +1 -1
  119. package/dist/renderer/runtime/context.d.ts +5 -5
  120. package/dist/renderer/runtime/context.d.ts.map +1 -1
  121. package/dist/renderer/runtime/context.js +11 -5
  122. package/dist/renderer/runtime/context.js.map +1 -1
  123. package/dist/renderer/runtime/describe.d.ts +3 -3
  124. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  125. package/dist/renderer/runtime/describe.js +2 -2
  126. package/dist/renderer/runtime/describe.js.map +1 -1
  127. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  128. package/dist/renderer/runtime/hooks.js +8 -4
  129. package/dist/renderer/runtime/hooks.js.map +1 -1
  130. package/dist/renderer/runtime/index.d.ts +1 -0
  131. package/dist/renderer/runtime/index.d.ts.map +1 -1
  132. package/dist/renderer/runtime/index.js +1 -0
  133. package/dist/renderer/runtime/index.js.map +1 -1
  134. package/dist/renderer/runtime/locals.d.ts +57 -0
  135. package/dist/renderer/runtime/locals.d.ts.map +1 -0
  136. package/dist/renderer/runtime/locals.js +87 -0
  137. package/dist/renderer/runtime/locals.js.map +1 -0
  138. package/dist/renderer/runtime/scope.d.ts +14 -0
  139. package/dist/renderer/runtime/scope.d.ts.map +1 -1
  140. package/dist/renderer/runtime/scope.js +25 -3
  141. package/dist/renderer/runtime/scope.js.map +1 -1
  142. package/dist/renderer/runtime/tree.d.ts.map +1 -1
  143. package/dist/renderer/runtime/tree.js +7 -1
  144. package/dist/renderer/runtime/tree.js.map +1 -1
  145. package/dist/renderer/runtime/types.d.ts +8 -3
  146. package/dist/renderer/runtime/types.d.ts.map +1 -1
  147. package/dist/shadcn.d.ts +36 -43
  148. package/dist/shadcn.d.ts.map +1 -1
  149. package/dist/shadcn.js +1 -2
  150. package/dist/shadcn.js.map +1 -1
  151. package/dist/spec/bsx_v2.json +11067 -6321
  152. package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
  153. package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
  154. package/dist/spec/catalogs/orkestrator@1.json +10 -10
  155. package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
  156. package/dist/spec/catalogs.d.ts +4 -4
  157. package/dist/spec/catalogs.d.ts.map +1 -1
  158. package/dist/spec/catalogs.js +7 -7
  159. package/dist/spec/catalogs.js.map +1 -1
  160. package/dist/spec/vocabulary.d.ts +25 -4
  161. package/dist/spec/vocabulary.d.ts.map +1 -1
  162. package/dist/spec/vocabulary.js +50 -5
  163. package/dist/spec/vocabulary.js.map +1 -1
  164. package/dist/spec/vocabulary.json +58 -32
  165. package/dist/spec/vocabulary.json.js +58 -32
  166. package/package.json +1 -1
  167. package/src/bsx/analyze.ts +14 -12
  168. package/src/bsx/bsx.test.ts +4 -4
  169. package/src/bsx/declared.ts +346 -0
  170. package/src/bsx/index.ts +1 -0
  171. package/src/bsx/infer.test.ts +42 -32
  172. package/src/bsx/infer.ts +128 -71
  173. package/src/bsx/language.test.ts +37 -25
  174. package/src/bsx/language.ts +72 -25
  175. package/src/bsx/parse.ts +34 -3
  176. package/src/bsx/print.ts +3 -0
  177. package/src/bsx/references.test.ts +82 -81
  178. package/src/bsx/references.ts +313 -178
  179. package/src/catalogs/catalogs.test.ts +3 -2
  180. package/src/catalogs/index.ts +1 -1
  181. package/src/catalogs/logo.ts +1 -2
  182. package/src/catalogs/parts/logo.ts +13 -17
  183. package/src/catalogs/parts/scene.ts +1 -7
  184. package/src/logo/actionLogoSource.ts +4 -4
  185. package/src/renderer/BlokComponentHost.test.tsx +5 -5
  186. package/src/renderer/BlokRenderer.tsx +46 -14
  187. package/src/renderer/addBlokComponents.test.tsx +1 -1
  188. package/src/renderer/baseCatalog.ts +2 -2
  189. package/src/renderer/bloks/control.tsx +119 -16
  190. package/src/renderer/bloks/logo/index.tsx +2 -3
  191. package/src/renderer/bloks/logo/logo.fixture.json +266 -250
  192. package/src/renderer/bloks/logo/logo.test.tsx +18 -7
  193. package/src/renderer/bloks/run/space.test.tsx +12 -4
  194. package/src/renderer/bloks/scene/interaction.tsx +11 -6
  195. package/src/renderer/bloks/scene/transform.test.ts +8 -7
  196. package/src/renderer/declarations.test.ts +38 -51
  197. package/src/renderer/declarations.ts +67 -88
  198. package/src/renderer/declare.test.ts +4 -4
  199. package/src/renderer/declare.ts +4 -4
  200. package/src/renderer/persist.test.ts +70 -49
  201. package/src/renderer/persist.ts +57 -34
  202. package/src/renderer/runtime/catalog.test.ts +2 -2
  203. package/src/renderer/runtime/catalog.ts +4 -4
  204. package/src/renderer/runtime/components.tsx +8 -8
  205. package/src/renderer/runtime/context.tsx +17 -10
  206. package/src/renderer/runtime/describe.ts +5 -5
  207. package/src/renderer/runtime/hooks.ts +6 -4
  208. package/src/renderer/runtime/index.ts +1 -0
  209. package/src/renderer/runtime/locals.tsx +105 -0
  210. package/src/renderer/runtime/scope.tsx +31 -3
  211. package/src/renderer/runtime/tree.tsx +16 -4
  212. package/src/renderer/runtime/types.ts +8 -3
  213. package/src/shadcn.ts +1 -2
  214. package/src/spec/bsx_v2.json +11067 -6321
  215. package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
  216. package/src/spec/catalogs/orkestrator@1.json +10 -10
  217. package/src/spec/catalogs.ts +8 -8
  218. package/src/spec/spec.test.ts +19 -16
  219. package/src/spec/vocabulary.json +58 -32
  220. 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 (`Local(default, persist=True)`). */
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 locals at their defaults, the kept values over them. */
57
- const runtimeFor = (initial: KeptLocals, keys: ReadonlySet<string>) =>
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
- describe("kept blok locals: Local(persist=True)", () => {
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.keys].sort()).toEqual(["iterations", "pose"]);
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", { iterations: 30 });
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({ iterations: 30 });
74
- const runtime = runtimeFor(again.initial, again.keys);
75
- expect((runtime.getState().dataModel as Record<string, unknown>).iterations).toBe(30);
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.keys);
93
+ const runtime = runtimeFor(persistence.initial, persistence.locals);
83
94
  const detach = persistence.attach(runtime);
84
95
 
85
- runtime.getState().setRuntimeValue("pose", [2, 0, 0, 0]);
86
- runtime.getState().setRuntimeValue("pose.0", 3);
87
- runtime.getState().setRuntimeValue("label", "not kept");
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({ pose: [3, 0, 0, 0] });
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.keys);
110
+ const runtime = runtimeFor(persistence.initial, persistence.locals);
99
111
  const detach = persistence.attach(runtime);
100
- runtime.getState().setRuntimeValue("iterations", 4);
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({ iterations: 4 });
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.keys);
109
- runtime.getState().setRuntimeValue("pose", [5, 0, 0, 0]);
110
- runtime.getState().setRuntimeValue("label", "edited");
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
- const model = runtime.getState().dataModel as Record<string, unknown>;
113
- expect(model.pose).toEqual([5, 0, 0, 0]);
114
- expect(model.label).toBe("x");
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", { pose: [0, 1, 0, 0], iterations: 3 });
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.keys);
135
+ const runtime = runtimeFor(persistence.initial, persistence.locals);
122
136
  persistence.attach(runtime);
123
137
  await persistence.resetLocals();
124
- expect((runtime.getState().dataModel as Record<string, unknown>).pose).toEqual(DEFAULTS.pose);
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", { pose: { x: 1 }, iterations: 2.5, label: "kept?", gone: true });
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", { iterations: 2 });
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
- expect(fitsLocal(3, { key: "n", kind: "INT" })).toBe(true);
145
- expect(fitsLocal(3.5, { key: "n", kind: "INT" })).toBe(false);
146
- expect(fitsLocal(3.5, { key: "n", kind: "FLOAT" })).toBe(true);
147
- expect(fitsLocal(true, { key: "n", kind: "FLOAT" })).toBe(false);
148
- expect(fitsLocal("a", { key: "s", kind: "STRING" })).toBe(true);
149
- expect(fitsLocal({ object: "4", __identifier: "@mikro/image" }, { key: "img", kind: "STRUCTURE", identifier: "@mikro/image" })).toBe(true);
150
- expect(fitsLocal([1], { key: "l", kind: "LIST" })).toBe(true);
151
- expect(fitsLocal("x", { key: "l", kind: "LIST" })).toBe(false);
152
- expect(fitsLocal("fast", { key: "m", kind: "ENUM", choices: [{ value: "fast" }] })).toBe(true);
153
- expect(fitsLocal("slow", { key: "m", kind: "ENUM", choices: [{ value: "fast" }] })).toBe(false);
154
- expect(fitsLocal(null, { key: "n", kind: "INT" })).toBe(true);
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
 
@@ -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 type {BlokRuntimeStore} from './runtime';
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 `Local(default, persist=True)` (a port
12
- * plus `persist`) remembers the viewer's last input;
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 and (hub, user, materialized blok, component id) for each
21
- * component, and are written a moment after the last change. A local the
22
- * blok no longer persists, or a value that no longer fits its port, is
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
- /** A local (vocabulary `locals`): an arg port plus `persist`, remembering the last input on this device. */
48
- export type BlokLocal = BlokLocalPort & {persist?: boolean | null};
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 key. */
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: 1,
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
- for (const local of locals) {
114
- if (local.persist && local.key in record && fitsLocal(record[local.key], local)) values[local.key] = record[local.key];
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 locals kept on this device (those declared with `persist`). */
127
- keys: ReadonlySet<string>;
128
- /** The kept locals to seed the runtime with, before the first render. */
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 declared locals; those with `persist` are kept. */
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 keys = new Set(persisted.map(local => local.key));
190
- const defaults = new Map(options.locals.map(local => [local.key, local.default ?? null] as const));
191
- const record = keys.size > 0 ? await store.load(id, LOCALS_RECORD) : null;
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
- keys,
236
+ locals,
214
237
  initial,
215
238
  attach: target => {
216
239
  runtime = target;
217
- const valueOf = (key: string) => (target.getState().dataModel as Record<string, unknown> | null)?.[key];
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 key of keys) {
222
- const value = (state.dataModel as Record<string, unknown> | null)?.[key];
223
- if (same(value, seen.get(key))) continue;
224
- seen.set(key, value);
225
- // Back at the default is nothing to keep.
226
- if (same(value, defaults.get(key))) {
227
- if (!(key in kept)) continue;
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[key] = value;
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 [root] = path.split(/[/.]/);
248
- if (keys.has(root)) state.clearRuntimeValue(path);
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: 'HTML',
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: 'HTML',
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@3`). The
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@3';
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/v3';
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@3`). Null on a catalog of its own. */
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 `html`. */
19
- export type BlokComponentContext = 'html' | 'scene' | 'logo';
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@3` for a component of one of its families, `newswitch`); unset for one built on its own. */
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 html). */
201
- export const BlokDrawContext = React.createContext<BlokComponentContext>('html');
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 !== 'html') return null;
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 ?? 'html');
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 !== 'html') return rendered;
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 top-level key: written
144
- * as runtime values over the initial data model, so the first render shows
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 top-level keys a reset of the runtime values leaves alone (`keptValues`' and later edits of them). */
149
- keptRoots?: ReadonlySet<string>;
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
- keptRoots: config?.keptRoots ?? NONE_KEPT,
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 => isUnderRoot(path, currentState.keptRoots) || isUnderRoot(path, HOST_ROOTS));
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
- setKeptRoots: nextKeptRoots => {
252
- set({keptRoots: nextKeptRoots});
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@3.json`,
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: 'HTML' | 'SCENE' | 'LOGO';
31
- children_context: 'HTML' | 'SCENE' | 'LOGO' | null;
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']> = {html: 'HTML', scene: 'SCENE', logo: 'LOGO'};
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 ?? 'html'],
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 (!travelling) store.getState().setRuntimeValue(absolutePath, value);
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
  };
@@ -32,3 +32,4 @@ export {
32
32
  isString,
33
33
  splitPathSegments,
34
34
  } from './utils';
35
+ export * from './locals';