@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
@@ -4,24 +4,40 @@ import type {BlokComponentContract, BlokComponentDefinition, BlokRenderArgs} fro
4
4
  /**
5
5
  * Catalogs as the UI defines them.
6
6
  *
7
- * A *contract* (`defineBlokCatalog`) says which components a catalog holds and
8
- * what each takes: name, schema, placement. It draws nothing. A versioned one
9
- * (`ui@1`, `scene@1`) is global: every UI that implements it whole draws the
10
- * same bloks, and the spec publishes it. An unversioned one is a UI's own (the
11
- * `newswitch` catalog, orkestrator's MikroScene parts), registered with that UI.
7
+ * A *contract* (`defineBlokCatalog`) says which components a set holds and what
8
+ * each takes: name, schema, placement. It draws nothing. There are two sorts:
9
+ *
10
+ * - A *family* of the base catalog (`ui`, `html`, `shadcn`, `structure`,
11
+ * `scene`, `logo`): `partOf` names the catalog it is part of (`base@4`). The
12
+ * base catalog is the spec's, and every renderer draws it whole; the families
13
+ * are how this package holds its contracts, one toolkit at a time.
14
+ * - A UI's *own* catalog (the Orkestrator's MikroScene parts): what it draws
15
+ * beyond the base. Given an `id` (the address it is published at) and a
16
+ * version it is an app catalog a blok can be written for.
12
17
  *
13
18
  * An *implementation* (`implementBlokCatalog`) is the app's: one render per
14
19
  * component of a contract, a map the compiler checks against the contract.
15
20
  */
16
21
 
22
+ /** The base catalog, as components of it are tagged (`origin`). */
23
+ export const BASE_CATALOG_REF = 'base@4';
24
+ /** The address the base catalog is published at: what a blok is written for when it names none. */
25
+ export const BASE_CATALOG_ADDRESS = 'https://arkitekt.live/catalogs/base/v4';
26
+
17
27
  export type BlokComponentContracts = Record<string, BlokComponentContract<any>>;
18
28
 
19
29
  export type BlokCatalogContract<TComponents extends BlokComponentContracts = BlokComponentContracts> = {
20
30
  name: string;
21
- /** Set on a global catalog (`ui@1`); null on a UI's own. */
31
+ /** Set on a published catalog (an app catalog's `1`); null on a family, and on a UI's own that nothing publishes. */
22
32
  version: number | null;
23
33
  description: string;
24
34
  components: TComponents;
35
+ /** For a family: the catalog it is part of (`base@4`). Null on a catalog of its own. */
36
+ partOf: string | null;
37
+ /** For a published catalog: the address it is published at, which is what a blok names it by. */
38
+ id: string | null;
39
+ /** The id of the catalog it adds to; the base catalog's when left out. */
40
+ extends: string | null;
25
41
  };
26
42
 
27
43
  export const defineBlokCatalog = <const TComponents extends BlokComponentContracts>(contract: {
@@ -29,9 +45,18 @@ export const defineBlokCatalog = <const TComponents extends BlokComponentContrac
29
45
  version?: number;
30
46
  description: string;
31
47
  components: TComponents;
32
- }): BlokCatalogContract<TComponents> => ({...contract, version: contract.version ?? null});
48
+ partOf?: string;
49
+ id?: string;
50
+ extends?: string;
51
+ }): BlokCatalogContract<TComponents> => ({
52
+ ...contract,
53
+ version: contract.version ?? null,
54
+ partOf: contract.partOf ?? null,
55
+ id: contract.id ?? null,
56
+ extends: contract.extends ?? null,
57
+ });
33
58
 
34
- /** How a catalog is named on the wire: `name@version`, or a UI's own catalog's bare name. */
59
+ /** How a contract is named: `name@version`, or the bare name of a family or of a UI's own unpublished catalog. */
35
60
  export const catalogRef = (contract: Pick<BlokCatalogContract, 'name' | 'version'>): string =>
36
61
  contract.version === null ? contract.name : `${contract.name}@${contract.version}`;
37
62
 
@@ -83,7 +108,7 @@ export function implementBlokCatalog(
83
108
  }
84
109
  const components = Object.entries(contract.components).flatMap(([name, component]): BlokComponentDefinition[] => {
85
110
  const render = renders[name];
86
- return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: ref}] : [];
111
+ return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: contract.partOf ?? ref}] : [];
87
112
  });
88
113
  return {contract, components, whole: missing.length === 0};
89
114
  }
@@ -94,7 +119,7 @@ export function implementBlokCatalog(
94
119
  * once. The UI owns both, so there is nothing to check one against.
95
120
  */
96
121
  export const ownBlokCatalog = (
97
- meta: {name: string; version?: number; description: string},
122
+ meta: {name: string; version?: number; description: string; id?: string; extends?: string},
98
123
  components: readonly BlokComponentDefinition[],
99
124
  ): BlokCatalogImplementation => {
100
125
  const contract = defineBlokCatalog({
@@ -15,8 +15,8 @@ export type BlokRenderArgs<TSchema extends BlokObjectSchema = BlokObjectSchema>
15
15
  schema: TSchema;
16
16
  };
17
17
 
18
- /** The renderer a component lives in. A blok's tree starts in `html`. */
19
- export type BlokComponentContext = 'html' | 'scene' | 'logo';
18
+ /** The renderer a component lives in. A blok's tree starts in `panel`. */
19
+ export type BlokComponentContext = 'panel' | 'scene' | 'logo';
20
20
 
21
21
  /**
22
22
  * Where a component may sit in a tree. Published with the catalog, so the
@@ -67,6 +67,12 @@ type BlokComponentApi = {
67
67
  * where the schema itself only says "a path".
68
68
  */
69
69
  bindKinds?: Readonly<Record<string, string>>;
70
+ /** The blok kinds it may be placed in (`assign`); any kind when left out. */
71
+ kinds?: readonly string[];
72
+ /** The service it needs where it is drawn (`mikro`): without it a notice shows in its place. */
73
+ service?: string;
74
+ /** The minor of its catalog that added it; the first when left out. */
75
+ since?: number;
70
76
  };
71
77
 
72
78
  /**
@@ -82,7 +88,7 @@ export type BlokComponentDefinition = BlokComponentApi & {
82
88
  name: string;
83
89
  schema: BlokObjectSchema;
84
90
  render: React.ComponentType<BlokRenderArgs>;
85
- /** The catalog contract it implements (`ui@1`, `newswitch`); unset for one built on its own. */
91
+ /** The catalog it is of (`base@4` for a component of one of its families, `newswitch`); unset for one built on its own. */
86
92
  origin?: string;
87
93
  };
88
94
 
@@ -99,6 +105,9 @@ export const createBlokComponent = <TSchema extends BlokObjectSchema>(
99
105
  textProp: api.textProp,
100
106
  events: api.events,
101
107
  bindKinds: api.bindKinds,
108
+ kinds: api.kinds,
109
+ service: api.service,
110
+ since: api.since,
102
111
  render: render as React.ComponentType<BlokRenderArgs>,
103
112
  });
104
113
 
@@ -188,8 +197,8 @@ export class BlokNodeBoundary extends React.Component<
188
197
  /* Statuses, guards and boundaries */
189
198
  /* -------------------------------------------------------------------------- */
190
199
 
191
- /** The renderer a node draws in: what decides how a pending node shows (a skeleton only in html). */
192
- export const BlokDrawContext = React.createContext<BlokComponentContext>('html');
200
+ /** The renderer a node draws in: what decides how a pending node shows (a skeleton only in a panel). */
201
+ export const BlokDrawContext = React.createContext<BlokComponentContext>('panel');
193
202
 
194
203
  export const useBlokDrawContext = (): BlokComponentContext => React.useContext(BlokDrawContext);
195
204
 
@@ -279,7 +288,7 @@ const NodeGuard = (props: {
279
288
  if (status.status === 'pending' || status.status === 'failed') {
280
289
  // Inside a boundary its fallback or error shows; on its own a node shows
281
290
  // its own skeleton or inline error, so a blok never blanks entirely.
282
- if (caught || definition.placement?.inheritsContext || drawContext !== 'html') return null;
291
+ if (caught || definition.placement?.inheritsContext || drawContext !== 'panel') return null;
283
292
  if (status.status === 'failed') {
284
293
  return <BlokNodeError componentId={component.id} title="Could not load" detail={status.error ?? undefined} />;
285
294
  }
@@ -300,7 +309,7 @@ const BlokComponentRendererInner = (props: {
300
309
  const locked = useNodeLocked(props.props);
301
310
  const parentContext = React.useContext(BlokDrawContext);
302
311
  const placement = props.definition.placement ?? {};
303
- const own = placement.inheritsContext ? parentContext : (placement.context ?? 'html');
312
+ const own = placement.inheritsContext ? parentContext : (placement.context ?? 'panel');
304
313
  const forChildren = placement.inheritsContext ? parentContext : (placement.childrenContext ?? own);
305
314
 
306
315
  const rendered = (
@@ -326,7 +335,7 @@ const BlokComponentRendererInner = (props: {
326
335
  // A node whose action a held lock keeps from running is marked for the `locked:`
327
336
  // variant. The marker takes no box (`display: contents`), so the layout stays; a
328
337
  // scene or a logo cannot hold an element, and is not marked.
329
- if (!locked || own !== 'html') return rendered;
338
+ if (!locked || own !== 'panel') return rendered;
330
339
  const Locked = blokPlatform().primitives.Locked ?? DomLocked;
331
340
  return <Locked reason={locked}>{rendered}</Locked>;
332
341
  };
@@ -4,6 +4,7 @@ import {useStore} from 'zustand';
4
4
  import {createStore} from 'zustand/vanilla';
5
5
  import {combineStatus, READY, type BlokSourceStatus} from './status';
6
6
  import {isRecord, splitPathSegments} from './utils';
7
+ import {localNodeOfPath, localValuePath} from './locals';
7
8
  import type {
8
9
  BlokAgentMappingStateUpdates,
9
10
  BlokDispatchActionHandler,
@@ -131,6 +132,12 @@ const isUnderRoot = (path: string, roots: ReadonlySet<string>): boolean => {
131
132
  return root !== undefined && roots.has(root);
132
133
  };
133
134
 
135
+ /** Whether a runtime value is a kept local's (one of `keptLocals`, in any foreach item). */
136
+ const isKeptLocal = (path: string, keptLocals: ReadonlySet<string>): boolean => {
137
+ const node = localNodeOfPath(path);
138
+ return node !== null && keptLocals.has(node);
139
+ };
140
+
134
141
  export const createBlokRuntimeStore = (config?: {
135
142
  initialDataModel?: unknown;
136
143
  agentMappingStateUpdates?: BlokAgentMappingStateUpdates;
@@ -140,13 +147,13 @@ export const createBlokRuntimeStore = (config?: {
140
147
  unavailableDependencies?: BlokUnavailableDependencies;
141
148
  lockedActions?: BlokLockedActions;
142
149
  /**
143
- * Locals the host kept from an earlier opening, by top-level key: written
144
- * as runtime values over the initial data model, so the first render shows
145
- * them and clearing one shows its default again.
150
+ * Locals the host kept from an earlier opening, by runtime id (`runtimeIdOf`):
151
+ * written as runtime values at their paths (`localValuePath`), so the first
152
+ * render shows them and clearing one shows its default again.
146
153
  */
147
154
  keptValues?: Record<string, unknown>;
148
- /** The top-level keys a reset of the runtime values leaves alone (`keptValues`' and later edits of them). */
149
- keptRoots?: ReadonlySet<string>;
155
+ /** The `<local>` node ids whose values a reset of the runtime values leaves alone (`keptValues`' and later edits of them). */
156
+ keptLocals?: ReadonlySet<string>;
150
157
  /** Source statuses known before the first render (a preview's are all ready). */
151
158
  statuses?: Readonly<Record<string, BlokSourceStatus>>;
152
159
  travelAt?: string | null;
@@ -155,7 +162,7 @@ export const createBlokRuntimeStore = (config?: {
155
162
  controlTask?: (operation: BlokTaskControl) => unknown;
156
163
  }): BlokRuntimeStore => {
157
164
  const initialDataModel = config?.initialDataModel;
158
- const keptValues = config?.keptValues ?? {};
165
+ const keptValues = Object.fromEntries(Object.entries(config?.keptValues ?? {}).map(([runtimeId, value]) => [localValuePath(runtimeId), value]));
159
166
  const initialAgentMappingStateUpdates = config?.agentMappingStateUpdates ?? {};
160
167
  const invokeFunction = config?.invokeFunction ?? defaultInvokeFunction;
161
168
  const dispatchAction = config?.dispatchAction ?? defaultDispatchAction;
@@ -164,7 +171,7 @@ export const createBlokRuntimeStore = (config?: {
164
171
  initialDataModel,
165
172
  dataModel: modelOf(initialDataModel, config?.travelAt ?? null, keptValues),
166
173
  runtimePathValues: {...keptValues},
167
- keptRoots: config?.keptRoots ?? NONE_KEPT,
174
+ keptLocals: config?.keptLocals ?? NONE_KEPT,
168
175
  agentMappingStateUpdates: initialAgentMappingStateUpdates,
169
176
  invokeFunction,
170
177
  dispatchAction,
@@ -236,7 +243,7 @@ export const createBlokRuntimeStore = (config?: {
236
243
  set(currentState => {
237
244
  const paths = Object.keys(currentState.runtimePathValues);
238
245
  // What the host keeps between openings outlives a reset, as it outlives a reload.
239
- const kept = paths.filter(path => isUnderRoot(path, currentState.keptRoots) || isUnderRoot(path, HOST_ROOTS));
246
+ const kept = paths.filter(path => isKeptLocal(path, currentState.keptLocals) || isUnderRoot(path, HOST_ROOTS));
240
247
  if (kept.length === paths.length) {
241
248
  return currentState;
242
249
  }
@@ -248,8 +255,8 @@ export const createBlokRuntimeStore = (config?: {
248
255
  };
249
256
  });
250
257
  },
251
- setKeptRoots: nextKeptRoots => {
252
- set({keptRoots: nextKeptRoots});
258
+ setKeptLocals: nextKeptLocals => {
259
+ set({keptLocals: nextKeptLocals});
253
260
  },
254
261
  setRuntimeValue: (path, value) => {
255
262
  set(currentState => {
@@ -5,10 +5,12 @@ import {isRequiredField} from './preflight';
5
5
  import {isActionSchema, isBindSchema, unwrapSchema} from './schemas';
6
6
 
7
7
  /**
8
- * A contract as the spec publishes it (`spec/catalogs/ui@1.json`, arkitekt-spec's
9
- * `blok/catalogs/`): the JSON the server and `arkitekt check` validate bloks
10
- * against. Written from the contract, never by hand: the zod schemas are the
11
- * source, the JSON what they say in the spec's terms.
8
+ * A contract in the spec's terms: what a catalog file (`spec/catalogs/base@4.json`,
9
+ * arkitekt-spec's `blok/catalogs/`) says of each component. Written from the
10
+ * contract, never by hand: the zod schemas are the source of a component's
11
+ * props and documentation, the JSON what they say in the spec's terms. The
12
+ * spec's base catalog is built from it (`pnpm spec:export`), and an app
13
+ * catalog is published as it (`blokCatalogSpec`).
12
14
  */
13
15
 
14
16
  export type SpecValueKind = 'STRING' | 'INT' | 'FLOAT' | 'BOOL' | 'DICT' | 'LIST' | 'ANY' | 'CALLBACK' | 'ASSET';
@@ -25,19 +27,27 @@ export type SpecPropJson = {
25
27
  export type SpecComponentJson = {
26
28
  name: string;
27
29
  description: string | null;
28
- context: 'HTML' | 'SCENE' | 'LOGO';
29
- children_context: 'HTML' | 'SCENE' | 'LOGO' | null;
30
+ context: 'PANEL' | 'SCENE' | 'LOGO';
31
+ children_context: 'PANEL' | 'SCENE' | 'LOGO' | null;
30
32
  inherits_context: boolean;
31
33
  accepts_children: boolean;
32
34
  downstream_of: string[];
33
35
  not_downstream_of: string[];
34
36
  text_prop: string | null;
35
37
  props: SpecPropJson[];
38
+ kinds?: string[];
39
+ service?: string;
40
+ since?: number;
36
41
  };
37
42
 
38
43
  export type SpecCatalogJson = {
44
+ /** The address a published catalog is known by. */
45
+ id?: string;
39
46
  name: string;
40
47
  version?: number;
48
+ minor?: number;
49
+ /** The id of the catalog it adds to. */
50
+ extends?: string;
41
51
  description: string;
42
52
  components: SpecComponentJson[];
43
53
  };
@@ -112,7 +122,7 @@ export const zodToSpecKind = (schema: z.ZodTypeAny): SpecValueKind => {
112
122
  }
113
123
  };
114
124
 
115
- const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {html: 'HTML', scene: 'SCENE', logo: 'LOGO'};
125
+ const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {panel: 'PANEL', scene: 'SCENE', logo: 'LOGO'};
116
126
 
117
127
  const byKey = <T extends {key: string}>(left: T, right: T) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
118
128
  const byName = <T extends {name: string}>(left: T, right: T) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
@@ -155,7 +165,7 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
155
165
  return {
156
166
  name,
157
167
  description: component.schema.description ?? null,
158
- context: CONTEXT[placement.context ?? 'html'],
168
+ context: CONTEXT[placement.context ?? 'panel'],
159
169
  children_context: placement.childrenContext ? CONTEXT[placement.childrenContext] : null,
160
170
  inherits_context: placement.inheritsContext ?? false,
161
171
  accepts_children: component.acceptsChildren ?? CHILDREN in shape,
@@ -163,6 +173,9 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
163
173
  not_downstream_of: [...(placement.notDownstreamOf ?? [])],
164
174
  text_prop: component.textProp ?? null,
165
175
  props,
176
+ ...(component.kinds?.length ? {kinds: [...component.kinds]} : {}),
177
+ ...(component.service ? {service: component.service} : {}),
178
+ ...(component.since ? {since: component.since} : {}),
166
179
  };
167
180
  };
168
181
 
@@ -16,7 +16,7 @@ import {
16
16
  type BlokResolved,
17
17
  } from './resolution';
18
18
  import {isActionSchema} from './schemas';
19
- import {isWritableScopedPath, readScopedPath, resolveScopedPath, useBlokScope} from './scope';
19
+ import {isWritableScopedPath, readScopedPath, resolveScopedPath, scopedWrite, useBlokScope} from './scope';
20
20
  import {defaultBlokView} from '../../spec/catalogs';
21
21
  import {useBlokNodeState} from './nodeState';
22
22
  import {combineStatus, READY, type BlokSourceStatus} from './status';
@@ -680,13 +680,15 @@ export const useBinding = (
680
680
  return undefined;
681
681
  }
682
682
 
683
- const absolutePath = resolveScopedPath(path, scope);
684
-
685
683
  return {
686
684
  value: snapshot.values.get(path),
687
685
  // The past is read-only: a bound control shows what was, and writes nothing.
688
686
  setValue: (value: unknown) => {
689
- if (!travelling) store.getState().setRuntimeValue(absolutePath, value);
687
+ if (travelling) return;
688
+ const state = store.getState();
689
+ const write = scopedWrite(state.dataModel, path, scope);
690
+ if (write.seed) state.setRuntimeValue(write.seed.path, write.seed.value);
691
+ store.getState().setRuntimeValue(write.path, value);
690
692
  },
691
693
  readOnly: travelling,
692
694
  };
@@ -15,6 +15,7 @@ export * from './status';
15
15
  export * from './resource';
16
16
  export * from './reads';
17
17
  export * from './task';
18
+ export * from './text';
18
19
  export * from './tree';
19
20
  export * from './types';
20
21
  export * from './viewer';
@@ -31,3 +32,4 @@ export {
31
32
  isString,
32
33
  splitPathSegments,
33
34
  } from './utils';
35
+ export * from './locals';
@@ -0,0 +1,105 @@
1
+ import * as React from 'react';
2
+ import {runtimeIdOf, nodeOfRuntimeId} from '../../bsx/declared';
3
+
4
+ export {runtimeIdOf, nodeOfRuntimeId};
5
+ import {BlokScopeProvider} from './scope';
6
+ import type {BlokComponentNode} from './types';
7
+ import {splitPathSegments} from './utils';
8
+
9
+ /**
10
+ * Where a blok's `<local>` values live while it is open (blok language v2
11
+ * `locals.scope`).
12
+ *
13
+ * A `<local>` is in scope in its parent's subtree. Its value lives in the one
14
+ * runtime store under its *runtime id*: its node id plus one `@<item key>` per
15
+ * enclosing `foreach`, outermost first (`runtimeIdOf`), so inside a foreach
16
+ * every item has a value of its own. The value sits at `$locals/<runtime id,
17
+ * encoded as one path segment>`: a root no name a blok writes can be (`into`
18
+ * names are identifiers). It outlives an `if` branch closing, as long as the
19
+ * blok stays open. Until something writes it, it reads its default.
20
+ *
21
+ * When a node renders its children, its `local` children are provided to them
22
+ * as scope aliases `{name → that local's path}` (`BlokLocalsScope`); a bound
23
+ * control writes through the alias.
24
+ */
25
+
26
+ /** The data-model root every local's value lives under. */
27
+ export const LOCALS_ROOT = '$locals';
28
+
29
+ /** One path segment for a runtime id: `/` and `.` would split it. */
30
+ const encodeSegment = (runtimeId: string): string => encodeURIComponent(runtimeId).replace(/\./g, '%2E');
31
+
32
+ /** The data-model path of the value of the local whose runtime id is `runtimeId`. */
33
+ export const localValuePath = (runtimeId: string): string => `${LOCALS_ROOT}/${encodeSegment(runtimeId)}`;
34
+
35
+ /** The runtime id of the local whose value `path` is (or is below), or null when it is no local's. */
36
+ export const runtimeIdOfPath = (path: string): string | null => {
37
+ const [root, segment] = splitPathSegments(path);
38
+ if (root !== LOCALS_ROOT || segment === undefined) return null;
39
+ try {
40
+ return decodeURIComponent(segment);
41
+ } catch {
42
+ return null;
43
+ }
44
+ };
45
+
46
+ /** The `<local>` node a runtime path value belongs to, or null when it is no local's. */
47
+ export const localNodeOfPath = (path: string): string | null => {
48
+ const runtimeId = runtimeIdOfPath(path);
49
+ return runtimeId === null ? null : nodeOfRuntimeId(runtimeId);
50
+ };
51
+
52
+ const NO_KEYS: readonly string[] = Object.freeze([]);
53
+ const BlokItemKeysContext = React.createContext<readonly string[]>(NO_KEYS);
54
+
55
+ /** The item keys of the foreach items this subtree is inside, outermost first (`7`, `#2`). */
56
+ export const useBlokItemKeys = (): readonly string[] => React.useContext(BlokItemKeysContext);
57
+
58
+ /** A subtree inside one more foreach item: `key` is the item's (`foreachItemIds` without the foreach's id and `@`). */
59
+ export const BlokItemKeyProvider = ({itemKey, children}: {itemKey: string; children: React.ReactNode}) => {
60
+ const outer = React.useContext(BlokItemKeysContext);
61
+ const keys = React.useMemo(() => [...outer, itemKey], [outer, itemKey]);
62
+ return <BlokItemKeysContext.Provider value={keys}>{children}</BlokItemKeysContext.Provider>;
63
+ };
64
+
65
+ /** Passes the item keys through a boundary that drops React context (a scene's portal). */
66
+ export const BlokItemKeysBridge = ({keys, children}: {keys: readonly string[]; children: React.ReactNode}) => (
67
+ <BlokItemKeysContext.Provider value={keys}>{children}</BlokItemKeysContext.Provider>
68
+ );
69
+
70
+ /** A `<local>` child as the renderer provides it: its node, the name it is read by, and its default. */
71
+ export type BlokLocalDeclaration = {node: string; name: string; default: unknown};
72
+
73
+ /** The `<local>` children of `node`, each with its name and default (a literal); one without a name is skipped. */
74
+ export const localChildren = (node: BlokComponentNode): BlokLocalDeclaration[] =>
75
+ (node.children ?? []).flatMap(child => {
76
+ if (child.component !== 'local') return [];
77
+ const name = child.props?.find(prop => prop.key === 'name');
78
+ const declared = name?.declares_value ?? (typeof name?.static_value === 'string' ? name.static_value : null);
79
+ if (!declared) return [];
80
+ const fallback = child.props?.find(prop => prop.key === 'default')?.static_value;
81
+ return [{node: child.id, name: declared, default: fallback ?? null}];
82
+ });
83
+
84
+ /**
85
+ * Provides a node's locals to its children: each name aliased to the path of
86
+ * its value here (in this foreach item), reading its default until written.
87
+ */
88
+ export const BlokLocalsScope = ({locals, children}: {locals: readonly BlokLocalDeclaration[]; children: React.ReactNode}) => {
89
+ const keys = useBlokItemKeys();
90
+ const {aliases, defaults} = React.useMemo(() => {
91
+ const aliases: Record<string, string> = {};
92
+ const defaults: Record<string, unknown> = {};
93
+ for (const local of locals) {
94
+ const path = localValuePath(runtimeIdOf(local.node, keys));
95
+ aliases[local.name] = path;
96
+ defaults[path] = local.default;
97
+ }
98
+ return {aliases, defaults};
99
+ }, [keys, locals]);
100
+ return (
101
+ <BlokScopeProvider aliases={aliases} defaults={defaults}>
102
+ {children}
103
+ </BlokScopeProvider>
104
+ );
105
+ };
@@ -3,6 +3,7 @@ import type {BlokCatalog} from './functions';
3
3
  import {BlokSchemas, isActionSchema} from './schemas';
4
4
  import type {PreparedBlokNode} from './tree';
5
5
  import type {BlokActionArgument, BlokComponentNode, BlokComponentProp} from './types';
6
+ import {lowerBlokText} from './text';
6
7
  import {extractUiComponents, isRecord} from './utils';
7
8
  import {loadVocabulary} from '../../spec/vocabulary';
8
9
 
@@ -192,7 +193,9 @@ export const preflightBlokDocument = (
192
193
  const invalidNodes = new Map<string, string[]>();
193
194
  const rootIds: string[] = [];
194
195
  const unknownKinds = new Map<string, string[]>();
195
- extractUiComponents(uiComponents).forEach(raw => unknownCallKinds(raw, unknownKinds));
196
+ // Text is stored as nodes; what each component does with it is the catalog's to say.
197
+ const roots = extractUiComponents(uiComponents).map(raw => lowerBlokText(raw, catalog));
198
+ roots.forEach(raw => unknownCallKinds(raw, unknownKinds));
196
199
 
197
200
  const pushError = (error: BlokValidationError) => {
198
201
  errors.push(error);
@@ -242,7 +245,7 @@ export const preflightBlokDocument = (
242
245
  });
243
246
  };
244
247
 
245
- extractUiComponents(uiComponents).forEach((rawComponent, componentIndex) => {
248
+ roots.forEach((rawComponent, componentIndex) => {
246
249
  const basePath = `uiComponents[${componentIndex}]`;
247
250
  const parsed = BlokSchemas.ComponentNode.safeParse(rawComponent);
248
251
 
@@ -26,13 +26,15 @@ export const BlokScopeProvider = (props: {
26
26
  aliases?: Readonly<Record<string, string>>;
27
27
  values?: Readonly<Record<string, unknown>>;
28
28
  basePath?: string;
29
+ /** What an alias reads before anything was written at its path, by the alias' absolute path (a `<local>`'s default). */
30
+ defaults?: Readonly<Record<string, unknown>>;
29
31
  children: React.ReactNode;
30
32
  }) => {
31
- const {aliases, values, basePath, children} = props;
33
+ const {aliases, values, basePath, defaults, children} = props;
32
34
  const parentScope = React.useContext(BlokScopeContext);
33
35
 
34
36
  const scope = React.useMemo<BlokScope>(() => {
35
- if (!aliases && !values && basePath === undefined) {
37
+ if (!aliases && !values && basePath === undefined && !defaults) {
36
38
  return parentScope;
37
39
  }
38
40
 
@@ -40,8 +42,9 @@ export const BlokScopeProvider = (props: {
40
42
  aliases: aliases ? {...parentScope.aliases, ...aliases} : parentScope.aliases,
41
43
  values: values ? {...parentScope.values, ...values} : parentScope.values,
42
44
  basePath: basePath ?? parentScope.basePath,
45
+ defaults: defaults ? {...parentScope.defaults, ...defaults} : parentScope.defaults,
43
46
  };
44
- }, [aliases, basePath, parentScope, values]);
47
+ }, [aliases, basePath, defaults, parentScope, values]);
45
48
 
46
49
  return <BlokScopeContext.Provider value={scope}>{children}</BlokScopeContext.Provider>;
47
50
  };
@@ -107,9 +110,34 @@ export const readScopedPath = (
107
110
  return getValueAtPath(scope.values[head], tail.join('/'));
108
111
  }
109
112
 
113
+ const aliased = head ? scope.aliases[head] : undefined;
114
+ if (aliased !== undefined && scope.defaults && aliased in scope.defaults && getValueAtPath(dataModel, aliased) === undefined) {
115
+ // Nothing written at the alias yet (a local before its first input): it reads its default.
116
+ return getValueAtPath(scope.defaults[aliased], tail.join('/'));
117
+ }
118
+
110
119
  return getValueAtPath(dataModel, resolveScopedPath(path, scope));
111
120
  };
112
121
 
122
+ /**
123
+ * Where a write of `path` lands, and what to write first so it lands on the
124
+ * value it was read as: a write below an alias that still reads its default
125
+ * (`bind={p.x}` on a dict local) seeds the default at the alias first.
126
+ */
127
+ export const scopedWrite = (
128
+ dataModel: unknown,
129
+ path: string,
130
+ scope: BlokScope,
131
+ ): {path: string; seed: {path: string; value: unknown} | null} => {
132
+ const [head, ...tail] = splitPathSegments(path);
133
+ const aliased = head ? scope.aliases[head] : undefined;
134
+ const absolute = resolveScopedPath(path, scope);
135
+ if (aliased === undefined || tail.length === 0 || !scope.defaults || !(aliased in scope.defaults)) return {path: absolute, seed: null};
136
+ if (getValueAtPath(dataModel, aliased) !== undefined) return {path: absolute, seed: null};
137
+ const value = scope.defaults[aliased];
138
+ return {path: absolute, seed: value === null || value === undefined ? null : {path: aliased, value: structuredClone(value)}};
139
+ };
140
+
113
141
  /** True when a path can be written back through the data model. */
114
142
  export const isWritableScopedPath = (path: string, scope: BlokScope): boolean => {
115
143
  const [head] = splitPathSegments(path);
@@ -0,0 +1,65 @@
1
+ // @vitest-environment jsdom
2
+ import {cleanup, screen} from '@testing-library/react';
3
+ import {afterEach, describe, expect, it} from 'vitest';
4
+ import {parseBsx} from '../../bsx/parse';
5
+ import {renderBsx, testCatalog} from '../bloks/testing';
6
+ import {baseBlokCatalog} from '../baseCatalog';
7
+ import {lowerBlokText} from './text';
8
+
9
+ afterEach(cleanup);
10
+
11
+ type Lowered = {component: string; props?: Array<Record<string, unknown>>; children?: Lowered[]};
12
+
13
+ const lowered = (source: string, catalog = testCatalog()): Lowered => lowerBlokText(parseBsx(source).tree, catalog) as Lowered;
14
+
15
+ describe('text, as the renderer draws it', () => {
16
+ it('is the text prop of a component that has one', () => {
17
+ const button = lowered('<Button>Go</Button>');
18
+ expect(button.children).toBeUndefined();
19
+ expect(button.props).toEqual([{key: 'label', static_value: 'Go'}]);
20
+ const badge = lowered('<Badge>{task.status}</Badge>');
21
+ expect(badge.props).toEqual([{key: 'text', dynamic_value: {path: 'task.status'}}]);
22
+ });
23
+
24
+ it('is a Text among other children, a span inside a plain html element', () => {
25
+ const card = lowered('<Card>Hello <Badge>new</Badge> there</Card>');
26
+ expect(card.children?.map(child => child.component)).toEqual(['Text', 'Badge', 'Text']);
27
+ expect(card.children?.[0].props).toEqual([{key: 'text', static_value: 'Hello '}]);
28
+ expect(card.children?.[1].props).toEqual([{key: 'text', static_value: 'new'}]);
29
+ expect(lowered('<div>plain</div>').children?.map(child => child.component)).toEqual(['span']);
30
+ // A language element is no place of its own: the text takes after what is around it.
31
+ const within = lowered('<div><if when={args.x}>shown</if></div>');
32
+ expect(within.children?.[0].children?.map(child => child.component)).toEqual(['span']);
33
+ });
34
+
35
+ it('leaves a component alone that sets the prop itself, and a tree with no text', () => {
36
+ const both = lowered('<Button label="a">b</Button>');
37
+ expect(both.props).toEqual([{key: 'label', static_value: 'a'}]);
38
+ expect(both.children?.map(child => child.component)).toEqual(['Text']);
39
+ const {tree} = parseBsx('<Card><Button label="Go" /></Card>');
40
+ expect(lowerBlokText(tree, testCatalog())).toBe(tree);
41
+ });
42
+
43
+ it('passes a tree stored before text was a node through as it is', () => {
44
+ const stored = {
45
+ id: 'Card[0]',
46
+ component: 'Card',
47
+ children: [
48
+ {id: 'Card[0]/#0', component: 'Text', props: [{key: 'text', static_value: 'Hello'}]},
49
+ {id: 'Card[0]/Button[0]', component: 'Button', props: [{key: 'label', static_value: 'Go'}]},
50
+ ],
51
+ };
52
+ expect(lowerBlokText(stored, testCatalog())).toBe(stored);
53
+ });
54
+
55
+ it('is the text node itself where the catalog draws nothing else with it', () => {
56
+ const fragment = lowered('<fragment>bare</fragment>', baseBlokCatalog);
57
+ expect(fragment.children?.map(child => child.component)).toEqual(['#text']);
58
+ });
59
+
60
+ it('shows on the page, whichever way it was written', () => {
61
+ renderBsx(testCatalog(), '<Card><Button>Go</Button><Text>Arrived</Text>and done<div>in a div</div></Card>');
62
+ expect(screen.getByRole('button').textContent).toBe('Go');
63
+ for (const shown of ['Arrived', 'and done', 'in a div']) expect(screen.queryByText(shown)).not.toBeNull();
64
+ });
65
+ });