@arkitektio/bsx 4.3.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 (349) hide show
  1. package/README.md +39 -18
  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 +19 -8
  23. package/dist/bsx/parse.d.ts.map +1 -1
  24. package/dist/bsx/parse.js +49 -59
  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 +25 -35
  28. package/dist/bsx/print.js.map +1 -1
  29. package/dist/bsx/references.d.ts +48 -54
  30. package/dist/bsx/references.d.ts.map +1 -1
  31. package/dist/bsx/references.js +359 -159
  32. package/dist/bsx/references.js.map +1 -1
  33. package/dist/catalogs/html.d.ts +3 -3
  34. package/dist/catalogs/html.d.ts.map +1 -1
  35. package/dist/catalogs/html.js +3 -3
  36. package/dist/catalogs/html.js.map +1 -1
  37. package/dist/catalogs/index.d.ts +172 -180
  38. package/dist/catalogs/index.d.ts.map +1 -1
  39. package/dist/catalogs/index.js +6 -2
  40. package/dist/catalogs/index.js.map +1 -1
  41. package/dist/catalogs/logo.d.ts +19 -33
  42. package/dist/catalogs/logo.d.ts.map +1 -1
  43. package/dist/catalogs/logo.js +4 -5
  44. package/dist/catalogs/logo.js.map +1 -1
  45. package/dist/catalogs/parts/data.d.ts +6 -6
  46. package/dist/catalogs/parts/feedback.d.ts +15 -15
  47. package/dist/catalogs/parts/forms.d.ts +24 -24
  48. package/dist/catalogs/parts/html.d.ts +3 -3
  49. package/dist/catalogs/parts/html.d.ts.map +1 -1
  50. package/dist/catalogs/parts/html.js +1 -1
  51. package/dist/catalogs/parts/html.js.map +1 -1
  52. package/dist/catalogs/parts/icons.d.ts +11 -11
  53. package/dist/catalogs/parts/icons.js +1 -1
  54. package/dist/catalogs/parts/index.d.ts +153 -165
  55. package/dist/catalogs/parts/index.d.ts.map +1 -1
  56. package/dist/catalogs/parts/layout.d.ts +11 -1
  57. package/dist/catalogs/parts/layout.d.ts.map +1 -1
  58. package/dist/catalogs/parts/layout.js +9 -0
  59. package/dist/catalogs/parts/layout.js.map +1 -1
  60. package/dist/catalogs/parts/logo.d.ts +17 -32
  61. package/dist/catalogs/parts/logo.d.ts.map +1 -1
  62. package/dist/catalogs/parts/logo.js +13 -15
  63. package/dist/catalogs/parts/logo.js.map +1 -1
  64. package/dist/catalogs/parts/navigation.d.ts +20 -20
  65. package/dist/catalogs/parts/overlays.d.ts +55 -55
  66. package/dist/catalogs/parts/run.d.ts +5 -13
  67. package/dist/catalogs/parts/run.d.ts.map +1 -1
  68. package/dist/catalogs/parts/run.js +1 -1
  69. package/dist/catalogs/parts/scene.d.ts +9 -17
  70. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  71. package/dist/catalogs/parts/scene.js +1 -5
  72. package/dist/catalogs/parts/scene.js.map +1 -1
  73. package/dist/catalogs/parts/structure.js +2 -2
  74. package/dist/catalogs/parts/toast.js +1 -1
  75. package/dist/catalogs/parts/toast.js.map +1 -1
  76. package/dist/catalogs/parts/typography.d.ts +3 -3
  77. package/dist/catalogs/parts/typography.js +1 -1
  78. package/dist/catalogs/parts/typography.js.map +1 -1
  79. package/dist/catalogs/props.d.ts +4 -4
  80. package/dist/catalogs/scene.d.ts +8 -16
  81. package/dist/catalogs/scene.d.ts.map +1 -1
  82. package/dist/catalogs/scene.js +3 -3
  83. package/dist/catalogs/scene.js.map +1 -1
  84. package/dist/catalogs/shadcn.d.ts +58 -58
  85. package/dist/catalogs/shadcn.d.ts.map +1 -1
  86. package/dist/catalogs/shadcn.js +4 -4
  87. package/dist/catalogs/shadcn.js.map +1 -1
  88. package/dist/catalogs/structure.d.ts +1 -1
  89. package/dist/catalogs/structure.d.ts.map +1 -1
  90. package/dist/catalogs/structure.js +3 -3
  91. package/dist/catalogs/structure.js.map +1 -1
  92. package/dist/catalogs/ui.d.ts +83 -73
  93. package/dist/catalogs/ui.d.ts.map +1 -1
  94. package/dist/catalogs/ui.js +4 -3
  95. package/dist/catalogs/ui.js.map +1 -1
  96. package/dist/catalogs.d.ts +1 -1
  97. package/dist/catalogs.d.ts.map +1 -1
  98. package/dist/catalogs.js +2 -2
  99. package/dist/catalogs.js.map +1 -1
  100. package/dist/logo/actionLogoSource.d.ts +3 -3
  101. package/dist/logo/actionLogoSource.d.ts.map +1 -1
  102. package/dist/logo/actionLogoSource.js +4 -4
  103. package/dist/logo/actionLogoSource.js.map +1 -1
  104. package/dist/ports.js +1 -1
  105. package/dist/ports.js.map +1 -1
  106. package/dist/renderer/BlokRenderer.d.ts +10 -6
  107. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  108. package/dist/renderer/BlokRenderer.js +23 -9
  109. package/dist/renderer/BlokRenderer.js.map +1 -1
  110. package/dist/renderer/baseCatalog.d.ts +8 -6
  111. package/dist/renderer/baseCatalog.d.ts.map +1 -1
  112. package/dist/renderer/baseCatalog.js +7 -5
  113. package/dist/renderer/baseCatalog.js.map +1 -1
  114. package/dist/renderer/bloks/control.d.ts +20 -2
  115. package/dist/renderer/bloks/control.d.ts.map +1 -1
  116. package/dist/renderer/bloks/control.js +98 -15
  117. package/dist/renderer/bloks/control.js.map +1 -1
  118. package/dist/renderer/bloks/data.d.ts +6 -6
  119. package/dist/renderer/bloks/feedback.d.ts +15 -15
  120. package/dist/renderer/bloks/forms.d.ts +24 -24
  121. package/dist/renderer/bloks/html.d.ts +2 -2
  122. package/dist/renderer/bloks/html.js +2 -2
  123. package/dist/renderer/bloks/icons.d.ts +5 -5
  124. package/dist/renderer/bloks/index.d.ts +145 -144
  125. package/dist/renderer/bloks/index.d.ts.map +1 -1
  126. package/dist/renderer/bloks/index.js +1 -1
  127. package/dist/renderer/bloks/layout.d.ts +9 -1
  128. package/dist/renderer/bloks/layout.d.ts.map +1 -1
  129. package/dist/renderer/bloks/layout.js +15 -0
  130. package/dist/renderer/bloks/layout.js.map +1 -1
  131. package/dist/renderer/bloks/logo/index.d.ts +6 -13
  132. package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
  133. package/dist/renderer/bloks/logo/index.js +3 -4
  134. package/dist/renderer/bloks/logo/index.js.map +1 -1
  135. package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
  136. package/dist/renderer/bloks/navigation.d.ts +20 -20
  137. package/dist/renderer/bloks/overlays.d.ts +55 -55
  138. package/dist/renderer/bloks/run/components.d.ts +2 -6
  139. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  140. package/dist/renderer/bloks/run/components.js +1 -1
  141. package/dist/renderer/bloks/scene/index.d.ts +5 -9
  142. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  143. package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
  144. package/dist/renderer/bloks/scene/interaction.js +3 -2
  145. package/dist/renderer/bloks/scene/interaction.js.map +1 -1
  146. package/dist/renderer/bloks/shared/props.d.ts +2 -2
  147. package/dist/renderer/bloks/toast.d.ts +1 -1
  148. package/dist/renderer/bloks/typography.d.ts +3 -3
  149. package/dist/renderer/bloks/typography.js +1 -1
  150. package/dist/renderer/catalog.d.ts +4 -7
  151. package/dist/renderer/catalog.d.ts.map +1 -1
  152. package/dist/renderer/catalog.js +7 -31
  153. package/dist/renderer/catalog.js.map +1 -1
  154. package/dist/renderer/declarations.d.ts +40 -33
  155. package/dist/renderer/declarations.d.ts.map +1 -1
  156. package/dist/renderer/declarations.js +41 -56
  157. package/dist/renderer/declarations.js.map +1 -1
  158. package/dist/renderer/declare.d.ts +31 -19
  159. package/dist/renderer/declare.d.ts.map +1 -1
  160. package/dist/renderer/declare.js +44 -18
  161. package/dist/renderer/declare.js.map +1 -1
  162. package/dist/renderer/persist.d.ts +22 -13
  163. package/dist/renderer/persist.d.ts.map +1 -1
  164. package/dist/renderer/persist.js +40 -21
  165. package/dist/renderer/persist.js.map +1 -1
  166. package/dist/renderer/runtime/catalog.d.ts +27 -7
  167. package/dist/renderer/runtime/catalog.d.ts.map +1 -1
  168. package/dist/renderer/runtime/catalog.js +30 -3
  169. package/dist/renderer/runtime/catalog.js.map +1 -1
  170. package/dist/renderer/runtime/components.d.ts +10 -4
  171. package/dist/renderer/runtime/components.d.ts.map +1 -1
  172. package/dist/renderer/runtime/components.js +8 -5
  173. package/dist/renderer/runtime/components.js.map +1 -1
  174. package/dist/renderer/runtime/context.d.ts +5 -5
  175. package/dist/renderer/runtime/context.d.ts.map +1 -1
  176. package/dist/renderer/runtime/context.js +11 -5
  177. package/dist/renderer/runtime/context.js.map +1 -1
  178. package/dist/renderer/runtime/describe.d.ts +16 -6
  179. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  180. package/dist/renderer/runtime/describe.js +5 -2
  181. package/dist/renderer/runtime/describe.js.map +1 -1
  182. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  183. package/dist/renderer/runtime/hooks.js +8 -4
  184. package/dist/renderer/runtime/hooks.js.map +1 -1
  185. package/dist/renderer/runtime/index.d.ts +2 -0
  186. package/dist/renderer/runtime/index.d.ts.map +1 -1
  187. package/dist/renderer/runtime/index.js +2 -0
  188. package/dist/renderer/runtime/index.js.map +1 -1
  189. package/dist/renderer/runtime/locals.d.ts +57 -0
  190. package/dist/renderer/runtime/locals.d.ts.map +1 -0
  191. package/dist/renderer/runtime/locals.js +87 -0
  192. package/dist/renderer/runtime/locals.js.map +1 -0
  193. package/dist/renderer/runtime/preflight.d.ts.map +1 -1
  194. package/dist/renderer/runtime/preflight.js +5 -2
  195. package/dist/renderer/runtime/preflight.js.map +1 -1
  196. package/dist/renderer/runtime/scope.d.ts +14 -0
  197. package/dist/renderer/runtime/scope.d.ts.map +1 -1
  198. package/dist/renderer/runtime/scope.js +25 -3
  199. package/dist/renderer/runtime/scope.js.map +1 -1
  200. package/dist/renderer/runtime/text.d.ts +28 -0
  201. package/dist/renderer/runtime/text.d.ts.map +1 -0
  202. package/dist/renderer/runtime/text.js +82 -0
  203. package/dist/renderer/runtime/text.js.map +1 -0
  204. package/dist/renderer/runtime/tree.d.ts.map +1 -1
  205. package/dist/renderer/runtime/tree.js +7 -1
  206. package/dist/renderer/runtime/tree.js.map +1 -1
  207. package/dist/renderer/runtime/types.d.ts +8 -3
  208. package/dist/renderer/runtime/types.d.ts.map +1 -1
  209. package/dist/runtime.d.ts +0 -1
  210. package/dist/runtime.d.ts.map +1 -1
  211. package/dist/runtime.js +0 -1
  212. package/dist/runtime.js.map +1 -1
  213. package/dist/scene.d.ts +1 -1
  214. package/dist/scene.d.ts.map +1 -1
  215. package/dist/scene.js +2 -2
  216. package/dist/scene.js.map +1 -1
  217. package/dist/shadcn.d.ts +154 -153
  218. package/dist/shadcn.d.ts.map +1 -1
  219. package/dist/shadcn.js +7 -7
  220. package/dist/shadcn.js.map +1 -1
  221. package/dist/spec/bsx_v2.json +12324 -6934
  222. package/dist/spec/catalogs/base@4.json +13175 -0
  223. package/dist/spec/catalogs/base@4.json.js +13175 -0
  224. package/dist/spec/catalogs/orkestrator@1.json +489 -0
  225. package/dist/spec/catalogs/orkestrator@1.json.js +489 -0
  226. package/dist/spec/catalogs.d.ts +109 -46
  227. package/dist/spec/catalogs.d.ts.map +1 -1
  228. package/dist/spec/catalogs.js +243 -75
  229. package/dist/spec/catalogs.js.map +1 -1
  230. package/dist/spec/vocabulary.d.ts +44 -7
  231. package/dist/spec/vocabulary.d.ts.map +1 -1
  232. package/dist/spec/vocabulary.js +65 -7
  233. package/dist/spec/vocabulary.js.map +1 -1
  234. package/dist/spec/vocabulary.json +83 -43
  235. package/dist/spec/vocabulary.json.js +83 -43
  236. package/dist/vendor/core/ui/button-group.d.ts +1 -1
  237. package/dist/vendor/core/ui/button.d.ts +1 -1
  238. package/dist/vendor/core/ui/field.d.ts +1 -1
  239. package/package.json +1 -1
  240. package/src/bsx/analyze.ts +14 -12
  241. package/src/bsx/bsx.test.ts +4 -4
  242. package/src/bsx/declared.ts +346 -0
  243. package/src/bsx/index.ts +1 -0
  244. package/src/bsx/infer.test.ts +54 -52
  245. package/src/bsx/infer.ts +128 -71
  246. package/src/bsx/language.test.ts +37 -25
  247. package/src/bsx/language.ts +72 -25
  248. package/src/bsx/parse.ts +51 -64
  249. package/src/bsx/partial.test.ts +1 -1
  250. package/src/bsx/print.ts +27 -34
  251. package/src/bsx/references.test.ts +86 -83
  252. package/src/bsx/references.ts +391 -198
  253. package/src/catalogs/catalogs.test.ts +46 -14
  254. package/src/catalogs/html.ts +3 -3
  255. package/src/catalogs/index.ts +6 -2
  256. package/src/catalogs/logo.ts +4 -5
  257. package/src/catalogs/parts/html.ts +1 -1
  258. package/src/catalogs/parts/icons.ts +1 -1
  259. package/src/catalogs/parts/layout.ts +11 -0
  260. package/src/catalogs/parts/logo.ts +14 -18
  261. package/src/catalogs/parts/run.ts +1 -1
  262. package/src/catalogs/parts/scene.ts +1 -7
  263. package/src/catalogs/parts/structure.ts +2 -2
  264. package/src/catalogs/parts/toast.ts +1 -1
  265. package/src/catalogs/parts/typography.ts +1 -1
  266. package/src/catalogs/scene.ts +3 -3
  267. package/src/catalogs/shadcn.ts +4 -4
  268. package/src/catalogs/structure.ts +3 -3
  269. package/src/catalogs/ui.ts +4 -3
  270. package/src/catalogs.ts +9 -2
  271. package/src/logo/actionLogoSource.ts +4 -4
  272. package/src/ports.ts +1 -1
  273. package/src/renderer/BlokComponentHost.test.tsx +5 -5
  274. package/src/renderer/BlokRenderer.tsx +46 -14
  275. package/src/renderer/addBlokComponents.test.tsx +8 -22
  276. package/src/renderer/baseCatalog.ts +7 -5
  277. package/src/renderer/bloks/components.test.tsx +2 -2
  278. package/src/renderer/bloks/control.tsx +136 -17
  279. package/src/renderer/bloks/flow.test.tsx +1 -1
  280. package/src/renderer/bloks/html.tsx +2 -2
  281. package/src/renderer/bloks/index.ts +1 -1
  282. package/src/renderer/bloks/layout.tsx +28 -0
  283. package/src/renderer/bloks/logo/index.tsx +4 -5
  284. package/src/renderer/bloks/logo/logo.fixture.json +266 -250
  285. package/src/renderer/bloks/logo/logo.test.tsx +18 -7
  286. package/src/renderer/bloks/run/components.tsx +1 -1
  287. package/src/renderer/bloks/run/space.test.tsx +12 -4
  288. package/src/renderer/bloks/scene/interaction.tsx +11 -6
  289. package/src/renderer/bloks/scene/transform.test.ts +8 -7
  290. package/src/renderer/bloks/time.test.tsx +1 -1
  291. package/src/renderer/bloks/toast.tsx +1 -1
  292. package/src/renderer/bloks/typography.tsx +1 -1
  293. package/src/renderer/catalog.tsx +7 -31
  294. package/src/renderer/declarations.test.ts +38 -51
  295. package/src/renderer/declarations.ts +67 -88
  296. package/src/renderer/declare.test.ts +41 -0
  297. package/src/renderer/declare.ts +70 -32
  298. package/src/renderer/persist.test.ts +70 -49
  299. package/src/renderer/persist.ts +57 -34
  300. package/src/renderer/runtime/catalog.test.ts +2 -2
  301. package/src/renderer/runtime/catalog.ts +35 -10
  302. package/src/renderer/runtime/components.tsx +17 -8
  303. package/src/renderer/runtime/context.tsx +17 -10
  304. package/src/renderer/runtime/describe.ts +21 -8
  305. package/src/renderer/runtime/hooks.ts +6 -4
  306. package/src/renderer/runtime/index.ts +2 -0
  307. package/src/renderer/runtime/locals.tsx +105 -0
  308. package/src/renderer/runtime/preflight.ts +5 -2
  309. package/src/renderer/runtime/scope.tsx +31 -3
  310. package/src/renderer/runtime/text.test.tsx +65 -0
  311. package/src/renderer/runtime/text.ts +88 -0
  312. package/src/renderer/runtime/tree.tsx +16 -4
  313. package/src/renderer/runtime/types.ts +8 -3
  314. package/src/runtime.ts +0 -1
  315. package/src/scene.ts +2 -2
  316. package/src/shadcn.ts +7 -7
  317. package/src/spec/bsx_v2.json +12324 -6934
  318. package/src/spec/catalogs/base@4.json +13175 -0
  319. package/src/spec/catalogs/orkestrator@1.json +489 -0
  320. package/src/spec/catalogs.ts +259 -103
  321. package/src/spec/spec.test.ts +93 -24
  322. package/src/spec/vocabulary.json +83 -43
  323. package/src/spec/vocabulary.ts +102 -17
  324. package/dist/renderer/modules.d.ts +0 -4
  325. package/dist/renderer/modules.d.ts.map +0 -1
  326. package/dist/renderer/modules.js +0 -11
  327. package/dist/renderer/modules.js.map +0 -1
  328. package/dist/spec/catalogs/base@2.json +0 -355
  329. package/dist/spec/catalogs/base@2.json.js +0 -355
  330. package/dist/spec/catalogs/html@1.json +0 -308
  331. package/dist/spec/catalogs/html@1.json.js +0 -308
  332. package/dist/spec/catalogs/logo@1.json +0 -1687
  333. package/dist/spec/catalogs/logo@1.json.js +0 -1687
  334. package/dist/spec/catalogs/scene@1.json +0 -878
  335. package/dist/spec/catalogs/scene@1.json.js +0 -878
  336. package/dist/spec/catalogs/shadcn@1.json +0 -4002
  337. package/dist/spec/catalogs/shadcn@1.json.js +0 -4002
  338. package/dist/spec/catalogs/structure@1.json +0 -185
  339. package/dist/spec/catalogs/structure@1.json.js +0 -185
  340. package/dist/spec/catalogs/ui@1.json +0 -5349
  341. package/dist/spec/catalogs/ui@1.json.js +0 -5349
  342. package/src/renderer/modules.ts +0 -12
  343. package/src/spec/catalogs/base@2.json +0 -355
  344. package/src/spec/catalogs/html@1.json +0 -308
  345. package/src/spec/catalogs/logo@1.json +0 -1687
  346. package/src/spec/catalogs/scene@1.json +0 -878
  347. package/src/spec/catalogs/shadcn@1.json +0 -4002
  348. package/src/spec/catalogs/structure@1.json +0 -185
  349. package/src/spec/catalogs/ui@1.json +0 -5349
@@ -0,0 +1,41 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import * as z from 'zod';
3
+ import {threeScene} from '../scene';
4
+ import {shadcnExtras, shadcnHtml, shadcnLogo, shadcnUi} from '../shadcn';
5
+ import {hostedStructure} from '../ports/structure/index';
6
+ import {ORKESTRATOR_CATALOG_ID, parseSpecCatalog} from '../spec/catalogs';
7
+ import {addBlokComponents} from './catalog';
8
+ import {blokCatalogSpec, declareBlokUi, ownComponentsOf} from './declare';
9
+ import {BASE_CATALOG_ADDRESS, createBlokComponent, ownBlokCatalog} from './runtime';
10
+
11
+ const gauge = createBlokComponent({name: 'Gauge', service: 'lab', schema: z.object({value: z.number().optional().describe('What it reads.')}).describe('A gauge.')}, () => null);
12
+
13
+ describe('declareBlokUi', () => {
14
+ it('speaks the base catalog in the contexts it draws whole', () => {
15
+ const whole = declareBlokUi({name: 'whole', implements: [shadcnUi, shadcnHtml, shadcnLogo, shadcnExtras, threeScene, hostedStructure]});
16
+ expect(whole.contexts).toEqual(['PANEL', 'SCENE', 'LOGO']);
17
+ expect(whole.claims).toEqual(['base@4']);
18
+ const flat = declareBlokUi({name: 'flat', implements: [shadcnUi, shadcnHtml, shadcnLogo, shadcnExtras, hostedStructure]});
19
+ expect(flat.contexts).toEqual(['PANEL', 'LOGO']);
20
+ const logos = declareBlokUi({name: 'logos', implements: [shadcnLogo]});
21
+ expect([logos.contexts, logos.claims]).toEqual([['LOGO'], ['base@4']]);
22
+ expect(declareBlokUi({name: 'none', implements: []}).claims).toEqual([]);
23
+ });
24
+
25
+ it('publishes what it draws beyond the base catalog as an app catalog', () => {
26
+ const ui = declareBlokUi({
27
+ name: 'lab',
28
+ implements: [shadcnUi, ownBlokCatalog({name: 'lab', version: 1, description: 'A lab.'}, [gauge])],
29
+ });
30
+ expect(ui.claims).toEqual(['lab@1']);
31
+ expect(ownComponentsOf(ui.catalog).map(component => component.name)).toEqual(['Gauge']);
32
+ const undo = addBlokComponents([createBlokComponent({name: 'Dial', schema: z.object({})}, () => null)], ui.catalog);
33
+ const spec = blokCatalogSpec({id: 'https://acme.example/catalogs/lab/v1', name: 'lab', version: 1, description: 'A lab.'}, ui.catalog);
34
+ undo();
35
+ expect([spec.id, spec.version, spec.minor, spec.extends]).toEqual(['https://acme.example/catalogs/lab/v1', 1, 0, BASE_CATALOG_ADDRESS]);
36
+ expect(spec.components.map(component => [component.name, component.service])).toEqual([['Dial', undefined], ['Gauge', 'lab']]);
37
+ const parsed = parseSpecCatalog(spec, 'lab');
38
+ expect(parsed.components.find(component => component.name === 'Gauge')?.service).toBe('lab');
39
+ expect(blokCatalogSpec({id: ORKESTRATOR_CATALOG_ID, name: 'orkestrator', version: 1, extends: BASE_CATALOG_ADDRESS, description: ''}, ui.catalog).extends).toBe(BASE_CATALOG_ADDRESS);
40
+ });
41
+ });
@@ -1,5 +1,7 @@
1
1
  import {baseBlokCatalog} from './baseCatalog';
2
2
  import {
3
+ BASE_CATALOG_ADDRESS,
4
+ BASE_CATALOG_REF,
3
5
  catalogRef,
4
6
  describeBlokComponent,
5
7
  extendBlokCatalog,
@@ -8,28 +10,51 @@ import {
8
10
  type BlokComponentDefinition,
9
11
  type SpecCatalogJson,
10
12
  } from './runtime';
13
+ import {baseCatalog} from '../spec/catalogs';
14
+ import type {BlokContextName} from '../spec/vocabulary';
11
15
 
12
16
  /**
13
- * A UI's catalog, declared: the catalogs it implements and nothing inferred.
17
+ * A UI's catalog, declared: what it draws, and nothing inferred.
14
18
  *
15
- * - `catalog` is what its renderers draw: base@2 and every implementation.
16
- * - `claims` are the global catalogs it implements whole (`ui@1`, `scene@1`):
17
- * the server resolves their components from the spec, so a blok that uses
18
- * only claimed catalogs is known to render here.
19
- * - Its own catalogs (unversioned contracts) are part of `catalog`; what it
20
- * registers as its module is `moduleComponentsOf(catalog)`, which also counts
21
- * what its modules add later (`addBlokComponents`).
22
- *
23
- * A global catalog implemented `partial`ly is drawn but not claimed.
19
+ * - `catalog` is what its renderers draw: the language's own elements and every
20
+ * implementation.
21
+ * - `contexts` are the contexts in which it draws the base catalog whole
22
+ * (`HTML`, `SCENE`, `LOGO`): a blok written for the base catalog and drawn in
23
+ * one of them is known to render here.
24
+ * - `claims` are the catalogs it speaks: the base catalog when it draws it
25
+ * whole in at least one context, and each published catalog of its own.
26
+ * - Its own catalogs are part of `catalog`; what it publishes as its app
27
+ * catalog is `ownComponentsOf(catalog)`, which also counts what its modules
28
+ * add later (`addBlokComponents`).
24
29
  */
25
30
  export type BlokUi = {
26
31
  name: string;
27
32
  description: string | null;
28
33
  catalog: BlokCatalog;
29
34
  implementations: readonly BlokCatalogImplementation[];
35
+ contexts: readonly BlokContextName[];
30
36
  claims: readonly string[];
31
37
  };
32
38
 
39
+ const CONTEXTS: readonly BlokContextName[] = ['PANEL', 'SCENE', 'LOGO'];
40
+
41
+ /**
42
+ * The context a base component counts towards: its own, and for one that
43
+ * bridges a panel and another context (`Scene` opens a scene inside a panel),
44
+ * the other one: a renderer that draws no 3D still draws panels whole.
45
+ */
46
+ const contextOf = (component: {context: BlokContextName; childrenContext: BlokContextName | null}): BlokContextName =>
47
+ component.context !== 'PANEL' ? component.context : (component.childrenContext ?? 'PANEL');
48
+
49
+ /** The contexts in which `catalog` draws every component of the base catalog. */
50
+ export const baseContextsOf = (catalog: BlokCatalog): BlokContextName[] => {
51
+ const components = baseCatalog().components;
52
+ return CONTEXTS.filter(context => {
53
+ const drawn = components.filter(component => !component.inheritsContext && contextOf(component) === context);
54
+ return drawn.length > 0 && drawn.every(component => catalog.components.has(component.name));
55
+ });
56
+ };
57
+
33
58
  export const declareBlokUi = (declaration: {
34
59
  name: string;
35
60
  description?: string;
@@ -41,42 +66,55 @@ export const declareBlokUi = (declaration: {
41
66
  if (twice.length > 0) {
42
67
  throw new Error(`${declaration.name} implements ${[...new Set(twice)].join(', ')} twice`);
43
68
  }
69
+ const catalog = extendBlokCatalog(
70
+ baseBlokCatalog,
71
+ declaration.name,
72
+ implementations.flatMap(implementation => implementation.components),
73
+ );
74
+ const contexts = baseContextsOf(catalog);
44
75
  return {
45
76
  name: declaration.name,
46
77
  description: declaration.description ?? null,
47
- catalog: extendBlokCatalog(
48
- baseBlokCatalog,
49
- declaration.name,
50
- implementations.flatMap(implementation => implementation.components),
51
- ),
78
+ catalog,
52
79
  implementations,
53
- claims: implementations
54
- .filter(implementation => implementation.contract.version !== null && implementation.whole)
55
- .map(implementation => catalogRef(implementation.contract))
56
- .sort(),
80
+ contexts,
81
+ claims: [
82
+ ...(contexts.length > 0 ? [BASE_CATALOG_REF] : []),
83
+ ...implementations
84
+ .filter(implementation => implementation.contract.partOf === null && implementation.contract.version !== null && implementation.whole)
85
+ .map(implementation => catalogRef(implementation.contract))
86
+ .sort(),
87
+ ],
57
88
  };
58
89
  };
59
90
 
60
91
  /**
61
- * What a UI registers as its module (the server's `Module.components`): every
62
- * component of its catalog that is neither base@2's nor a global catalog's. Its
63
- * own catalogs' components, what its modules added since (`addBlokComponents`),
64
- * and a global component a module drew over (it is the module's now).
92
+ * What a UI draws beyond the base catalog: every component of its catalog
93
+ * that is neither the language's own nor one of the base catalog's. Its own
94
+ * catalogs' components, and what its modules added since (`addBlokComponents`).
65
95
  */
66
- export const moduleComponentsOf = (catalog: BlokCatalog): BlokComponentDefinition[] =>
96
+ export const ownComponentsOf = (catalog: BlokCatalog): BlokComponentDefinition[] =>
67
97
  [...catalog.components.values()].filter(
68
- component => catalog.base?.components.get(component.name) !== component && component.origin?.includes('@') !== true,
98
+ component => catalog.base?.components.get(component.name) !== component && component.origin !== BASE_CATALOG_REF,
69
99
  );
70
100
 
71
101
  /**
72
- * A UI's module as the spec writes a catalog: for the language's default view
73
- * (`registerBlokModules([parseSpecCatalog(blokModuleSpec(...), ...)])`), so the
74
- * parser and the checks know the components only this UI draws.
102
+ * A UI's app catalog as the spec writes one (`{id, name, version, minor,
103
+ * extends, components}`): what it publishes at `id`, registers with the
104
+ * server, and hands the language (`setAppBlokCatalog(parseSpecCatalog(...))`)
105
+ * so its own parser, checks and editor know the components only it draws.
75
106
  */
76
- export const blokModuleSpec = (name: string, description: string, catalog: BlokCatalog): SpecCatalogJson => ({
77
- name,
78
- description,
79
- components: moduleComponentsOf(catalog)
107
+ export const blokCatalogSpec = (
108
+ meta: {id: string; name: string; version: number; minor?: number; extends?: string; description: string},
109
+ catalog: BlokCatalog,
110
+ ): SpecCatalogJson => ({
111
+ id: meta.id,
112
+ name: meta.name,
113
+ version: meta.version,
114
+ minor: meta.minor ?? 0,
115
+ extends: meta.extends ?? BASE_CATALOG_ADDRESS,
116
+ description: meta.description,
117
+ components: ownComponentsOf(catalog)
80
118
  .map(component => describeBlokComponent(component.name, component))
81
119
  .sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0)),
82
120
  });
@@ -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,