@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
@@ -31,6 +31,12 @@ const mount = (canSave: boolean, room = 'room:lab') =>
31
31
  </BlokSpaceHostProvider>,
32
32
  );
33
33
 
34
+
35
+ /** The props of an action's panel `<Blok>`. */
36
+ const PANEL = [
37
+ {key: 'kind', static_value: 'action'},
38
+ {key: 'context', static_value: 'panel'},
39
+ ];
34
40
  describe('a space shown on its own', () => {
35
41
  it('opens a scene of its own, with Arrange where the host keeps poses', () => {
36
42
  mount(true);
@@ -52,7 +58,7 @@ describe('a space shown on its own', () => {
52
58
 
53
59
  describe('the argument form an assign blok places', () => {
54
60
  it('draws what the host gives for <args />, and nothing without a host', () => {
55
- const tree = [{id: 'root', component: 'Html', children: [{id: 'form', component: 'args'}]}];
61
+ const tree = [{id: 'root', component: 'Blok', props: PANEL, children: [{id: 'form', component: 'args'}]}];
56
62
  const run: BlokRunHost = {agentsFor: () => [], renderAsk: () => null, renderArgs: () => <div data-testid="args-form" />};
57
63
  const hosted = render(
58
64
  <BlokRunHostProvider value={run}>
@@ -68,7 +74,7 @@ describe('the argument form an assign blok places', () => {
68
74
 
69
75
  describe('the time slider a task blok places', () => {
70
76
  it('draws what the host gives for <timeline />, and nothing without a host', () => {
71
- const tree = [{id: 'root', component: 'Html', children: [{id: 'slider', component: 'timeline'}]}];
77
+ const tree = [{id: 'root', component: 'Blok', props: PANEL, children: [{id: 'slider', component: 'timeline'}]}];
72
78
  const run: BlokRunHost = {agentsFor: () => [], renderAsk: () => null, renderTimeline: () => <div data-testid="timeline" />};
73
79
  const hosted = render(
74
80
  <BlokRunHostProvider value={run}>
@@ -87,7 +93,8 @@ describe('what an assign blok places one by one', () => {
87
93
  const tree = [
88
94
  {
89
95
  id: 'root',
90
- component: 'Html',
96
+ component: 'Blok',
97
+ props: PANEL,
91
98
  children: [
92
99
  {id: 'one', component: 'arg', props: [{key: 'key', static_value: 'exposure'}]},
93
100
  {id: 'rest', component: 'args', props: [{key: 'omit', static_value: 'gain offset'}, {key: 'given', static_value: 'show'}]},
@@ -122,7 +129,8 @@ describe('what a task blok places of its run', () => {
122
129
  const tree = [
123
130
  {
124
131
  id: 'root',
125
- component: 'Html',
132
+ component: 'Blok',
133
+ props: PANEL,
126
134
  children: [
127
135
  {id: 'status', component: 'status'},
128
136
  {id: 'result', component: 'returns', props: [{key: 'only', static_value: ['image']}]},
@@ -2,12 +2,14 @@ import * as React from 'react';
2
2
  import type * as THREE from 'three';
3
3
  import {onClickSchema, popoutSchema, type sceneContracts} from '../../../catalogs/parts/scene';
4
4
  import {
5
+ BlokItemKeysBridge,
5
6
  BlokRuntimeProvider,
6
7
  BlokScopeProvider,
7
8
  BlokTreeProvider,
8
9
  useBlok,
9
10
  useBlokRuntimeStoreApi,
10
11
  useBlokScope,
12
+ useBlokItemKeys,
11
13
  useBlokTree,
12
14
  useEventAction,
13
15
  useValue,
@@ -129,21 +131,24 @@ export const PopoutRender: BlokRender<Contracts['Popout']> = ({component, buildC
129
131
  // So are the blok's runtime and tree: in a scene shared by several bloks
130
132
  // that half is outside each of them.
131
133
  const scope = useBlokScope();
134
+ const itemKeys = useBlokItemKeys();
132
135
  const runtime = useBlokRuntimeStoreApi();
133
136
  const tree = useBlokTree();
134
137
  const content = React.useMemo(
135
138
  () => (
136
139
  <BlokRuntimeProvider store={runtime}>
137
140
  <BlokTreeProvider tree={tree}>
138
- <BlokScopeProvider aliases={scope.aliases} values={scope.values} basePath={scope.basePath}>
139
- {(component.children ?? []).map(child => (
140
- <React.Fragment key={child.id}>{buildChild(child.id)}</React.Fragment>
141
- ))}
142
- </BlokScopeProvider>
141
+ <BlokItemKeysBridge keys={itemKeys}>
142
+ <BlokScopeProvider aliases={scope.aliases} values={scope.values} basePath={scope.basePath} defaults={scope.defaults}>
143
+ {(component.children ?? []).map(child => (
144
+ <React.Fragment key={child.id}>{buildChild(child.id)}</React.Fragment>
145
+ ))}
146
+ </BlokScopeProvider>
147
+ </BlokItemKeysBridge>
143
148
  </BlokTreeProvider>
144
149
  </BlokRuntimeProvider>
145
150
  ),
146
- [buildChild, component, runtime, scope, tree],
151
+ [buildChild, component, itemKeys, runtime, scope, tree],
147
152
  );
148
153
  useSceneOverlay({
149
154
  visible: Boolean(node) && visible,
@@ -1,18 +1,17 @@
1
1
  // @vitest-environment jsdom
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { analyzeBsx } from "../../../bsx/analyze";
4
- import { emptyBlokScope } from "../../../bsx/references";
4
+ import { mountedBlokScope } from "../../../bsx/references";
5
5
 
6
- const analyze = (source: string) =>
7
- analyzeBsx(source, {
8
- scope: { ...emptyBlokScope("agent", "SCENE"), locals: [{ key: "pose", default: null, persist: true }] },
9
- });
6
+ /** A scene blok that declares the local `pose`, around `body` (a `<Scene>`). */
7
+ const analyze = (body: string) =>
8
+ analyzeBsx(`<Blok kind="agent" context="scene"><local name="pose" persist />${body}</Blok>`, { scope: mountedBlokScope() });
10
9
 
11
10
  describe("Transform", () => {
12
11
  it("places what it holds in a scene, bound to a local the gizmo writes", () => {
13
12
  const { tree, markers } = analyze('<Scene><Transform bind={pose} mode="rotate"><Transform /></Transform></Scene>');
14
13
  expect(markers).toEqual([]);
15
- expect(tree?.children?.[0]?.component).toBe("Transform");
14
+ expect(tree?.children?.[1]?.children?.[0]?.component).toBe("Transform");
16
15
  });
17
16
 
18
17
  it("keeps its own pose by id when it persists", () => {
@@ -21,6 +20,8 @@ describe("Transform", () => {
21
20
  });
22
21
 
23
22
  it("stands only in a scene", () => {
24
- expect(analyzeBsx('<Html><Transform bind={pose} /></Html>', { scope: { ...emptyBlokScope("agent", "HTML"), locals: [{ key: "pose" }] } }).markers.length).toBeGreaterThan(0);
23
+ expect(
24
+ analyzeBsx('<Blok kind="agent" context="panel"><local name="pose" /><Transform bind={pose} /></Blok>', { scope: mountedBlokScope() }).markers.length,
25
+ ).toBeGreaterThan(0);
25
26
  });
26
27
  });
@@ -4,7 +4,7 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
4
4
  import {renderBsx, testCatalog} from './testing';
5
5
 
6
6
  /**
7
- * `<Time value relative? format?>` (ui@1): a moment, absolute or relative.
7
+ * `<Time value relative? format?>` (the ui family): a moment, absolute or relative.
8
8
  * Relative time ticks inside the component, against the wall clock live and
9
9
  * against `then` while travelling; a blok never reads the clock itself.
10
10
  */
@@ -16,7 +16,7 @@ type Contracts = typeof toastContracts;
16
16
 
17
17
  /**
18
18
  * `<Toast task={move}>`: a notification when a task settles, once per task
19
- * (ui@1). Each outcome slot (`done`, `failed`, `cancelled`) is optional and
19
+ * (the ui family). Each outcome slot (`done`, `failed`, `cancelled`) is optional and
20
20
  * holds the text shown for it:
21
21
  *
22
22
  * <Toast task={move}>
@@ -115,7 +115,7 @@ const useClock = (active: boolean, target: number | null): number => {
115
115
  };
116
116
 
117
117
  /**
118
- * `<Time value relative? format?>` (ui@1): a moment, absolute or relative.
118
+ * `<Time value relative? format?>` (the ui family): a moment, absolute or relative.
119
119
  * Relative time is measured from the viewed moment: the wall clock live
120
120
  * (ticking here), `then` while travelling, so the past renders as it did.
121
121
  */
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import {baseBlokCatalog} from './baseCatalog';
3
- import {moduleShadowsOf} from './modules';
4
3
  import {blokPlatform} from '../platform';
5
4
  import type {BlokCatalog, BlokComponentDefinition} from './runtime';
6
5
 
@@ -18,57 +17,34 @@ export const BlokCatalogProvider = ({catalog, children}: {catalog: BlokCatalog;
18
17
  <BlokCatalogContext.Provider value={catalog}>{children}</BlokCatalogContext.Provider>
19
18
  );
20
19
 
21
- /** The app's catalog when no provider says otherwise: the platform's, or base@2 alone. */
20
+ /** The app's catalog when no provider says otherwise: the platform's, or the language's own elements alone. */
22
21
  export const appBlokCatalog = (): BlokCatalog => blokPlatform().catalog ?? baseBlokCatalog;
23
22
 
24
23
  /** The catalog the app provides here, or the app's. */
25
24
  export const useBlokCatalog = (): BlokCatalog => React.useContext(BlokCatalogContext) ?? appBlokCatalog();
26
25
 
27
- /** A component of a global catalog (`ui@1`, `scene@1`): what a module may draw over. */
28
- const isGlobal = (component: BlokComponentDefinition | undefined): boolean => component?.origin?.includes('@') === true;
29
-
30
26
  /**
31
27
  * Adds components a module brings (`ModuleBuiltins.bloks`) to the catalog, so
32
28
  * everything that reads the app's catalog (the renderer, the registrar, the
33
29
  * export) offers them. Called once, by the composition root that installs the
34
30
  * modules; core never imports a module.
35
31
  *
36
- * A module may draw over a global catalog's component (its own `Slider`):
37
- * the module's is rendered, as the spec's `blok_view` says, and the validator
38
- * warns `catalog.shadow` where a blok uses it. Any other name the catalog
39
- * already holds (base's, the app's own, another module's) is refused, whoever
40
- * brought it. Returns the undo, which puts a drawn-over component back (a dev
41
- * hot reload installs the modules again).
32
+ * A catalog only adds: a name the catalog already holds (the language's, the
33
+ * base catalog's, the app's own, another module's) is refused, whoever brought
34
+ * it. Returns the undo (a dev hot reload installs the modules again).
42
35
  */
43
36
  export const addBlokComponents = (
44
37
  components: readonly BlokComponentDefinition[],
45
38
  catalog: BlokCatalog,
46
39
  ): (() => void) => {
47
- const shadows = moduleShadowsOf(catalog);
48
- const taken = components.filter(component => {
49
- const held = catalog.components.get(component.name);
50
- return held !== undefined && (!isGlobal(held) || shadows.has(component.name));
51
- });
40
+ const taken = components.filter(component => catalog.components.has(component.name));
52
41
  if (taken.length > 0) {
53
42
  throw new Error(`Blok components already in the catalog: ${taken.map(component => component.name).join(', ')}`);
54
43
  }
55
- const previous = new Map<string, BlokComponentDefinition>();
56
- for (const component of components) {
57
- const drawnOver = catalog.components.get(component.name);
58
- if (drawnOver) {
59
- previous.set(component.name, drawnOver);
60
- shadows.add(component.name);
61
- }
62
- catalog.components.set(component.name, component);
63
- }
44
+ for (const component of components) catalog.components.set(component.name, component);
64
45
  return () => {
65
46
  for (const component of components) {
66
- if (catalog.components.get(component.name) !== component) continue;
67
- const restored = previous.get(component.name);
68
- if (restored) {
69
- catalog.components.set(component.name, restored);
70
- shadows.delete(component.name);
71
- } else catalog.components.delete(component.name);
47
+ if (catalog.components.get(component.name) === component) catalog.components.delete(component.name);
72
48
  }
73
49
  };
74
50
  };
@@ -1,72 +1,59 @@
1
1
  import {describe, expect, it} from 'vitest';
2
- import {declaredLocals, demoModel, parseBlokDeclarations} from './declarations';
2
+ import {parseBsx} from '../bsx/parse';
3
+ import {declaredLocals, demoModel, parseBlokDeclarations, resolveTreeLocals, treeQueries, treeSubscriptions} from './declarations';
4
+
5
+ const tree = (source: string) => [parseBsx(source).tree];
3
6
 
4
7
  describe('parseBlokDeclarations', () => {
5
- it('reads the declarations a service serves as JSON', () => {
8
+ it('reads the locals a service resolved, each by its <local> node', () => {
6
9
  const declarations = parseBlokDeclarations({
7
10
  vocab: 2,
8
- locals: [
9
- {key: 'iterations', kind: 'INT', default: 3, persist: true},
10
- {key: 'mode', kind: 'ENUM', choices: [{value: 'fast', label: 'Fast'}], default: 'fast'},
11
- {key: 'form', kind: 'DICT', children: [{key: 'name', kind: 'STRING'}]},
12
- {key: 'kindless'},
11
+ resolvedLocals: [
12
+ {node: 'Blok[0]/local[0]', key: 'iterations', kind: 'INT', default: 3, persist: true},
13
+ {node: 'Blok[0]/local[1]', key: 'mode', kind: 'ENUM', choices: [{value: 'fast', label: 'Fast'}], default: 'fast'},
14
+ {node: 'Blok[0]/Card[0]/local[0]', key: 'form', kind: 'DICT', children: [{key: 'name', kind: 'STRING'}]},
15
+ {key: 'nodeless', kind: 'INT'},
16
+ {node: 'Blok[0]/local[2]', key: 'kindless'},
13
17
  ],
14
- demo: {args: {scene: 1}, queries: {stats: {mean: 2}}},
15
- queries: [{key: 'stats', service: 'mikro', document: 'query Stats { stats }', variables: {table_id: 1}, poll: 5, more: 'stats.rows'}],
18
+ demo: {args: {scene: 1}},
16
19
  });
17
20
  const port = {identifier: null, nullable: false, default: null, children: null, choices: null, label: null, description: null};
18
- // A local is a port plus persist; one left without a kind (and no tree to tell) is ANY.
19
21
  expect(declaredLocals(declarations)).toEqual([
20
- {...port, key: 'iterations', kind: 'INT', default: 3, persist: true},
21
- {...port, key: 'mode', kind: 'ENUM', default: 'fast', choices: [{value: 'fast', label: 'Fast', description: null}], persist: false},
22
- {...port, key: 'form', kind: 'DICT', children: [{...port, key: 'name', kind: 'STRING'}], persist: false},
23
- {...port, key: 'kindless', kind: 'ANY', persist: false},
24
- ]);
25
- expect(declarations.queries).toEqual([
26
- {key: 'stats', service: 'mikro', document: 'query Stats { stats }', variables: {table_id: 1}, poll: 5, more: 'stats.rows', keep: null, history: null},
22
+ {...port, node: 'Blok[0]/local[0]', key: 'iterations', kind: 'INT', default: 3, persist: true},
23
+ {...port, node: 'Blok[0]/local[1]', key: 'mode', kind: 'ENUM', default: 'fast', choices: [{value: 'fast', label: 'Fast', description: null}], persist: false},
24
+ {...port, node: 'Blok[0]/Card[0]/local[0]', key: 'form', kind: 'DICT', children: [{...port, key: 'name', kind: 'STRING'}], persist: false},
27
25
  ]);
28
- expect(declarations.subscriptions).toEqual([]);
29
26
  });
30
27
 
31
- it('drops malformed entries and non-list values', () => {
32
- const declarations = parseBlokDeclarations({locals: [{default: 1}, 'x', null], queries: {key: 'q'}, subscriptions: [{key: 's', service: 'mikro'}]});
33
- expect(declarations.resolvedLocals).toEqual([]);
34
- expect(declarations.queries).toEqual([]);
35
- expect(declarations.subscriptions).toEqual([]);
36
- });
37
-
38
- it('resolves locals served as written against the tree, as the server does', () => {
28
+ it('resolves the tree\'s locals when the service sent none, as the server does', () => {
39
29
  const declarations = parseBlokDeclarations({
40
- componentTree: [
41
- {
42
- id: 'Card[0]',
43
- component: 'Card',
44
- children: [
45
- {id: 'Card[0]/Switch[0]', component: 'Switch', props: [{key: 'bind', dynamic_value: {path: 'on'}}]},
46
- {id: 'Card[0]/Text[0]', component: 'Text', props: [{key: 'text', dynamic_value: {path: 'note'}}]},
47
- ],
48
- },
49
- ],
50
- locals: [{key: 'on'}, {key: 'count', default: 2}, {key: 'note'}, {key: 'given', kind: 'STRING', default: 1}],
30
+ componentTree: tree(
31
+ '<Blok kind="custom" context="panel"><local name="on" /><local name="count" default={2} /><Card><local name="note" /><Switch bind={on} /><Text text={note} /></Card></Blok>',
32
+ ),
51
33
  });
52
- expect(declarations.resolvedLocals.map(local => [local.key, local.kind])).toEqual([
53
- ['on', 'BOOL'],
54
- ['count', 'INT'],
55
- ['note', 'ANY'],
56
- ['given', 'STRING'],
34
+ expect(declarations.resolvedLocals.map(local => [local.node, local.key, local.kind])).toEqual([
35
+ ['Blok[0]/local[0]', 'on', 'BOOL'],
36
+ ['Blok[0]/local[1]', 'count', 'INT'],
37
+ ['Blok[0]/Card[0]/local[0]', 'note', 'ANY'],
57
38
  ]);
39
+ expect(resolveTreeLocals([])).toEqual([]);
58
40
  });
41
+ });
59
42
 
60
- it('gives a preview its locals at their defaults and its reads answered by the demo', () => {
61
- const model = demoModel(
62
- [],
63
- parseBlokDeclarations({
64
- locals: [{key: 'iterations', kind: 'INT', default: 3}],
65
- demo: {queries: {stats: {mean: 2}}},
66
- queries: [{key: 'stats', service: 'mikro', document: 'query Stats { stats }'}],
67
- }),
43
+ describe('the reads a tree declares', () => {
44
+ it('reads its <query> and <subscription> children, with their <var> variables', () => {
45
+ const roots = tree(
46
+ '<Blok kind="custom" context="panel"><query name="stats" service="mikro" document="query Stats($t: ID) { stats(t: $t) }" poll={5} more="stats.rows"><var key="t" value={args.table} /></query><subscription name="live" service="mikro" document="subscription { live }" keep={3} /><Text /></Blok>',
68
47
  );
69
- expect(model.iterations).toBe(3);
48
+ expect(treeQueries(roots)).toEqual([
49
+ {key: 'stats', service: 'mikro', document: 'query Stats($t: ID) { stats(t: $t) }', variables: [{key: 't', value_path: 'args.table'}], poll: 5, more: 'stats.rows'},
50
+ ]);
51
+ expect(treeSubscriptions(roots)).toEqual([{key: 'live', service: 'mikro', document: 'subscription { live }', variables: [], keep: 3, history: null}]);
52
+ });
53
+
54
+ it('gives a preview its reads answered by the demo', () => {
55
+ const roots = tree('<Blok kind="custom" context="panel"><query name="stats" service="mikro" document="query Stats { stats }" /><Text /></Blok>');
56
+ const model = demoModel(roots, {demo: {queries: {stats: {mean: 2}}}});
70
57
  expect(model.queries).toEqual({stats: {status: 'ready', value: {mean: 2}, error: null, refetching: false, fetching_more: false}});
71
58
  });
72
59
  });
@@ -1,7 +1,6 @@
1
- import {resolveBlokScope} from '../bsx/infer';
2
- import {emptyBlokScope, type BlokScopeLocal} from '../bsx/references';
3
- import {defaultBlokView} from '../spec/catalogs';
4
- import {LOCAL_ANY_KIND} from '../spec/vocabulary';
1
+ import {declaredQueries as queriesOfTree, declaredSubscriptions as subscriptionsOfTree} from '../bsx/declared';
2
+ import {resolveLocals} from '../bsx/infer';
3
+ import {viewForTree} from '../bsx/references';
5
4
  import type {BlokLocal, BlokLocalChoice, BlokLocalPort} from './persist';
6
5
  import {
7
6
  idleTaskRecord,
@@ -18,9 +17,9 @@ import {
18
17
  } from './runtime';
19
18
 
20
19
  /**
21
- * What a v2 blok declares beside its tree, as a host gets it from the server
22
- * (`Blok`/`BlokRevision`: `vocab`, `resolvedLocals`, `demo`, `queries`,
23
- * `subscriptions`), and the data model a renderer starts from.
20
+ * What a host gets of a v2 blok beside its tree (`Blok`/`BlokRevision`:
21
+ * `vocab`, `resolvedLocals`, `demo`), what its tree declares (its `<query>`
22
+ * and `<subscription>` children), and the data model a renderer starts from.
24
23
  *
25
24
  * The roots a blok reads (vocabulary `roots.data`) are laid out as:
26
25
  *
@@ -29,19 +28,23 @@ import {
29
28
  * args: {...}, task: TaskRecord, viewer: {...}, then: null | "...",
30
29
  * queries: {<name>: {status, value, error, refetching, fetching_more}},
31
30
  * subscriptions: {<name>: {status, value, error}},
32
- * <local>: value, <into name>: TaskRecord,
31
+ * <into name>: TaskRecord,
32
+ * $locals: {<local's runtime id, encoded>: value},
33
33
  * }
34
34
  *
35
- * `self` reads `deps.self`.
35
+ * `self` reads `deps.self`; a `<local>` is read by its name through its
36
+ * parent's scope (`runtime/locals`).
36
37
  */
37
38
 
38
39
  /**
39
40
  * A local as its tree resolves it (`resolvedLocals`): an arg port (`ArgPort`
40
41
  * fields) plus `persist`, its kind always said (inferred where the blok left
41
- * it out, ANY when nothing tells). A renderer never types a local with the
42
- * as-written `locals`, whose kind may be missing.
42
+ * it out, ANY when nothing tells), and `node`, the id of the `<local>` that
43
+ * declares it. A renderer types a local's values (a kept one too) by its node.
43
44
  */
44
45
  export type BlokDeclaredLocal = {
46
+ /** The id of the `<local>` node that declares it. */
47
+ node: string;
45
48
  key: string;
46
49
  kind: string;
47
50
  identifier?: string | null;
@@ -55,7 +58,7 @@ export type BlokDeclaredLocal = {
55
58
  };
56
59
 
57
60
  /** A child port of a local (a list's item, a dict's or model's fields). */
58
- export type BlokDeclaredLocalPort = Omit<BlokDeclaredLocal, 'persist'>;
61
+ export type BlokDeclaredLocalPort = Omit<BlokDeclaredLocal, 'persist' | 'node'>;
59
62
 
60
63
  export type BlokDeclaredRead = {
61
64
  key: string;
@@ -70,13 +73,16 @@ export type BlokDeclaredRead = {
70
73
  history?: string | null;
71
74
  };
72
75
 
76
+ /**
77
+ * What a host gets of a blok beside its tree (`Blok`/`BlokRevision`: `vocab`,
78
+ * `resolvedLocals`, `demo`). Its locals, queries and subscriptions are nodes
79
+ * of the tree; `resolvedLocals` is how the server typed the locals.
80
+ */
73
81
  export type BlokDeclarations = {
74
82
  vocab?: number | null;
75
- /** The locals as the tree resolves them: what the renderer types them with. */
83
+ /** The `<local>` nodes as the tree resolves them, each with its `node`: what the renderer types them with. */
76
84
  resolvedLocals: readonly BlokDeclaredLocal[];
77
85
  demo?: unknown;
78
- queries?: readonly BlokDeclaredRead[] | null;
79
- subscriptions?: readonly BlokDeclaredRead[] | null;
80
86
  };
81
87
 
82
88
  const isRecord = (value: unknown): value is Record<string, unknown> =>
@@ -98,10 +104,18 @@ const localPort = (port: BlokDeclaredLocalPort): BlokLocalPort => ({
98
104
  });
99
105
 
100
106
  export const declaredLocals = (declarations: BlokDeclarations): BlokLocal[] =>
101
- declarations.resolvedLocals.map(local => ({...localPort(local), persist: local.persist === true}));
107
+ declarations.resolvedLocals.map(local => ({...localPort(local), node: local.node, persist: local.persist === true}));
108
+
109
+ /** The one root of a tree as the wire spells it (a list of roots, or one), or null. */
110
+ const rootOf = (roots: ReadonlyArray<unknown> | unknown): BlokComponentNode | null => {
111
+ const list = Array.isArray(roots) ? roots : [roots];
112
+ const [root] = list;
113
+ return list.length === 1 && isRecord(root) && typeof root.component === 'string' ? (root as BlokComponentNode) : null;
114
+ };
102
115
 
103
- export const declaredQueries = (declarations: BlokDeclarations): BlokQuery[] =>
104
- (declarations.queries ?? []).map(query => ({
116
+ /** The reads a blok declares: its `<Blok>`'s `<query>` children. */
117
+ export const treeQueries = (roots: ReadonlyArray<unknown> | unknown): BlokQuery[] =>
118
+ queriesOfTree(rootOf(roots)).map(query => ({
105
119
  key: query.key,
106
120
  service: query.service,
107
121
  document: query.document,
@@ -110,8 +124,9 @@ export const declaredQueries = (declarations: BlokDeclarations): BlokQuery[] =>
110
124
  more: query.more ?? null,
111
125
  }));
112
126
 
113
- export const declaredSubscriptions = (declarations: BlokDeclarations): BlokSubscription[] =>
114
- (declarations.subscriptions ?? []).map(subscription => ({
127
+ /** The streams a blok declares: its `<Blok>`'s `<subscription>` children. */
128
+ export const treeSubscriptions = (roots: ReadonlyArray<unknown> | unknown): BlokSubscription[] =>
129
+ subscriptionsOfTree(rootOf(roots)).map(subscription => ({
115
130
  key: subscription.key,
116
131
  service: subscription.service,
117
132
  document: subscription.document,
@@ -120,10 +135,6 @@ export const declaredSubscriptions = (declarations: BlokDeclarations): BlokSubsc
120
135
  history: subscription.history ?? null,
121
136
  }));
122
137
 
123
- /** Each declared local at its default. */
124
- export const localsModel = (locals: readonly BlokLocal[]): Record<string, unknown> =>
125
- Object.fromEntries(locals.map(local => [local.key, local.default ?? null]));
126
-
127
138
  /** The names `into` gives a task call's record, in the tree. */
128
139
  export const intoNames = (roots: ReadonlyArray<unknown>): string[] => {
129
140
  const names = new Set<string>();
@@ -143,42 +154,41 @@ export const intoNames = (roots: ReadonlyArray<unknown>): string[] => {
143
154
  export const intoModel = (roots: ReadonlyArray<unknown>): Record<string, BlokTaskRecord> =>
144
155
  Object.fromEntries(intoNames(roots).map(name => [name, idleTaskRecord()]));
145
156
 
146
- /** What a renderer shows live before anything synced: locals, idle `into` records, pending reads. */
147
- export const liveModel = (
148
- roots: ReadonlyArray<unknown>,
149
- declarations: BlokDeclarations,
150
- ): {data: Record<string, unknown>; statuses: Record<string, BlokSourceStatus>} => {
151
- const reads = pendingReads(declaredQueries(declarations), declaredSubscriptions(declarations));
157
+ /**
158
+ * What a renderer shows live before anything synced: idle `into` records and
159
+ * pending reads. Locals read their defaults until written (`runtime/locals`).
160
+ */
161
+ export const liveModel = (roots: ReadonlyArray<unknown>): {data: Record<string, unknown>; statuses: Record<string, BlokSourceStatus>} => {
162
+ const reads = pendingReads(treeQueries(roots), treeSubscriptions(roots));
152
163
  return {
153
- data: {...localsModel(declaredLocals(declarations)), ...intoModel(roots), ...reads.data},
164
+ data: {...intoModel(roots), ...reads.data},
154
165
  statuses: reads.statuses,
155
166
  };
156
167
  };
157
168
 
158
169
  /**
159
170
  * What a preview renders: the blok's `demo`, mirroring the roots
160
- * (`{deps, args, task, queries, subscriptions}`), with every declared read
161
- * answered by its demo value. Nothing is pending in a preview.
171
+ * (`{deps, args, task, queries, subscriptions}`), with every read the tree
172
+ * declares answered by its demo value. Nothing is pending in a preview.
162
173
  */
163
- export const demoModel = (roots: ReadonlyArray<unknown>, declarations: BlokDeclarations): Record<string, unknown> => {
174
+ export const demoModel = (roots: ReadonlyArray<unknown>, declarations: Pick<BlokDeclarations, 'demo'>): Record<string, unknown> => {
164
175
  const demo = isRecord(declarations.demo) ? declarations.demo : {};
165
176
  const demoQueries = isRecord(demo.queries) ? demo.queries : {};
166
177
  const demoSubscriptions = isRecord(demo.subscriptions) ? demo.subscriptions : {};
167
178
  const queries = Object.fromEntries(
168
- declaredQueries(declarations).map(query => [
179
+ treeQueries(roots).map(query => [
169
180
  query.key,
170
181
  {status: 'ready', value: demoQueries[query.key] ?? null, error: null, refetching: false, fetching_more: false} satisfies BlokQueryRecord,
171
182
  ]),
172
183
  );
173
184
  const subscriptions = Object.fromEntries(
174
- declaredSubscriptions(declarations).map(subscription => [
185
+ treeSubscriptions(roots).map(subscription => [
175
186
  subscription.key,
176
187
  {status: 'ready', value: demoSubscriptions[subscription.key] ?? null, error: null} satisfies BlokSubscriptionRecord,
177
188
  ]),
178
189
  );
179
190
  const task = isRecord(demo.task) ? {...idleTaskRecord(), ...demo.task} : undefined;
180
191
  return {
181
- ...localsModel(declaredLocals(declarations)),
182
192
  ...intoModel(roots),
183
193
  deps: isRecord(demo.deps) ? demo.deps : {},
184
194
  args: isRecord(demo.args) ? demo.args : {},
@@ -189,20 +199,17 @@ export const demoModel = (roots: ReadonlyArray<unknown>, declarations: BlokDecla
189
199
  };
190
200
 
191
201
  /**
192
- * What a service serves of a blok's declarations as JSON (kabinet's `locals`,
193
- * `queries`, ...: snake_case values). Its `locals` are as the app wrote them
194
- * (a kind may be left out), so they are resolved here against its tree.
202
+ * What a service serves of a blok as JSON (snake_case values): its tree, and
203
+ * the locals as it resolved them (`resolved_locals`, each with its `node`),
204
+ * when it did.
195
205
  */
196
206
  export type BlokDeclarationsJson = {
197
207
  vocab?: number | null;
198
208
  componentTree?: unknown;
199
- locals?: unknown;
209
+ resolvedLocals?: unknown;
200
210
  demo?: unknown;
201
- queries?: unknown;
202
- subscriptions?: unknown;
203
211
  };
204
212
 
205
- const optionalNumber = (value: unknown): number | null => (typeof value === 'number' ? value : null);
206
213
  const optionalString = (value: unknown): string | null => (typeof value === 'string' ? value : null);
207
214
 
208
215
  const jsonChoices = (raw: unknown): BlokLocalChoice[] | null =>
@@ -210,16 +217,12 @@ const jsonChoices = (raw: unknown): BlokLocalChoice[] | null =>
210
217
  ? raw.filter(isRecord).map(choice => ({value: choice.value ?? null, label: optionalString(choice.label), description: optionalString(choice.description)}))
211
218
  : null;
212
219
 
213
- /** A port from JSON; a child without a key or kind is dropped. */
220
+ /** A port from JSON; one without a key or kind is dropped. */
214
221
  const jsonLocalPort = (port: Record<string, unknown>): BlokDeclaredLocalPort | null =>
215
- typeof port.kind === 'string' ? jsonLocalWritten(port, port.kind) : null;
216
-
217
- /** A port from JSON with `kind` as given; null without a key. */
218
- const jsonLocalWritten = <Kind extends string | null>(port: Record<string, unknown>, kind: Kind): (Omit<BlokDeclaredLocalPort, 'kind'> & {kind: Kind}) | null =>
219
- typeof port.key === 'string'
222
+ typeof port.key === 'string' && typeof port.kind === 'string'
220
223
  ? {
221
224
  key: port.key,
222
- kind,
225
+ kind: port.kind,
223
226
  identifier: optionalString(port.identifier),
224
227
  nullable: port.nullable === true,
225
228
  default: port.default ?? null,
@@ -235,51 +238,27 @@ const jsonLocalWritten = <Kind extends string | null>(port: Record<string, unkno
235
238
  }
236
239
  : null;
237
240
 
238
- /** Locals from JSON as written (snake_case port fields plus `persist`, a kind maybe left out); one without a key is dropped. */
239
- const jsonLocals = (raw: unknown): BlokScopeLocal[] =>
241
+ /** Resolved locals from JSON; one without a node, a key or a kind is dropped. */
242
+ const jsonResolvedLocals = (raw: unknown): BlokDeclaredLocal[] =>
240
243
  (Array.isArray(raw) ? raw : []).filter(isRecord).flatMap(local => {
241
- const port = jsonLocalWritten(local, typeof local.kind === 'string' ? local.kind : null);
242
- return port ? [{...port, persist: local.persist === true}] : [];
244
+ const port = jsonLocalPort(local);
245
+ return port && typeof local.node === 'string' ? [{...port, node: local.node, persist: local.persist === true}] : [];
243
246
  });
244
247
 
245
- const jsonRoots = (raw: unknown): BlokComponentNode[] =>
246
- (Array.isArray(raw) ? raw : [raw]).filter((node): node is BlokComponentNode => isRecord(node) && typeof node.component === 'string');
247
-
248
248
  /**
249
- * Locals as written, resolved against the tree the way the spec and the
250
- * server resolve them (`resolveBlokScope`: default, task argument, bind, else
251
- * ANY); a given kind is kept.
249
+ * The `<local>` nodes of a tree resolved the way the spec and the server
250
+ * resolve them (default, task argument, bind, else ANY), checked unmounted:
251
+ * what a host uses when the server sent no `resolvedLocals`.
252
252
  */
253
- export const resolveWrittenLocals = (roots: readonly BlokComponentNode[], locals: readonly BlokScopeLocal[]): BlokDeclaredLocal[] => {
254
- if (!locals.length) return [];
255
- const [root] = roots;
256
- if (!root || roots.length !== 1) return locals.map(local => ({...local, kind: local.kind ?? LOCAL_ANY_KIND}));
257
- return resolveBlokScope(root, {...emptyBlokScope(), locals}, defaultBlokView()).locals.map(local => ({...local}));
253
+ export const resolveTreeLocals = (roots: ReadonlyArray<unknown> | unknown): BlokDeclaredLocal[] => {
254
+ const root = rootOf(roots);
255
+ if (!root) return [];
256
+ return [...resolveLocals(root, null, viewForTree(root))].map(([node, {local}]) => ({...local, node}) as BlokDeclaredLocal);
258
257
  };
259
258
 
260
- const jsonReads = (raw: unknown): BlokDeclaredRead[] =>
261
- (Array.isArray(raw) ? raw : []).filter(isRecord).flatMap(read =>
262
- typeof read.key === 'string' && typeof read.service === 'string' && typeof read.document === 'string'
263
- ? [
264
- {
265
- key: read.key,
266
- service: read.service,
267
- document: read.document,
268
- variables: read.variables,
269
- poll: optionalNumber(read.poll),
270
- more: optionalString(read.more),
271
- keep: optionalNumber(read.keep),
272
- history: optionalString(read.history),
273
- },
274
- ]
275
- : [],
276
- );
277
-
278
- /** A blok's declarations from JSON a service serves, keeping only well-formed entries. */
259
+ /** A blok's declarations from JSON a service serves: its resolved locals as served, or resolved from its tree. */
279
260
  export const parseBlokDeclarations = (raw: BlokDeclarationsJson): BlokDeclarations => ({
280
261
  vocab: raw.vocab ?? null,
281
- resolvedLocals: resolveWrittenLocals(jsonRoots(raw.componentTree), jsonLocals(raw.locals)),
262
+ resolvedLocals: raw.resolvedLocals !== undefined && raw.resolvedLocals !== null ? jsonResolvedLocals(raw.resolvedLocals) : resolveTreeLocals(raw.componentTree),
282
263
  demo: raw.demo ?? null,
283
- queries: jsonReads(raw.queries),
284
- subscriptions: jsonReads(raw.subscriptions),
285
264
  });