@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
package/src/bsx/parse.ts CHANGED
@@ -5,7 +5,7 @@ import type {
5
5
  BlokComponentProp,
6
6
  BlokUtilCall,
7
7
  } from '../renderer/runtime/types';
8
- import {defaultBlokView, innerContext, isLanguageContainer, type BlokView} from '../spec/catalogs';
8
+ import {blokViewFor, defaultBlokView, type BlokView} from '../spec/catalogs';
9
9
  import {isExplicitId, loadVocabulary, type BlokContextName} from '../spec/vocabulary';
10
10
  import {
11
11
  blokError,
@@ -30,8 +30,10 @@ import {BsxSyntaxError, type BsxRange} from './source';
30
30
  *
31
31
  * - `attr="..."` is always a literal string, `attr={...}` an expression, a bare
32
32
  * `attr` is `true`.
33
- * - Text children fill the component's `text_prop`; mixed with elements they
34
- * become implicit `Text` nodes. Several parts desugar to `str.template`.
33
+ * - Text is a child like any other: each run of text between elements is
34
+ * stored as a `#text` node holding its `value`. What a component does with
35
+ * it (a `Button` makes it its label) is its renderer's to say, so no catalog
36
+ * is needed to parse. Several parts of one run desugar to `str.template`.
35
37
  * Whitespace follows JSX.
36
38
  * - `className={[...]}` and `className={{...}}` desugar to `str.classes`.
37
39
  * - Operators desugar to `cmp.*` / `logic.*` calls; a callback holds one task
@@ -42,11 +44,15 @@ import {BsxSyntaxError, type BsxRange} from './source';
42
44
  */
43
45
 
44
46
  export const MAX_SOURCE_BYTES = 256 * 1024;
45
- /** The component a run of text becomes when it sits among elements. */
46
- export const IMPLICIT_TEXT = 'Text';
47
- /** Loose text inside an `html@` component becomes a `span`, so an html-only blok stays inside the catalogs it declares. */
48
- export const IMPLICIT_HTML_TEXT = 'span';
49
- export const IMPLICIT_TEXTS: readonly string[] = [IMPLICIT_TEXT, IMPLICIT_HTML_TEXT];
47
+ /** The node a run of text is stored as: no element can be called this, so only text makes one. */
48
+ export const TEXT_NODE = '#text';
49
+ /** The prop of a text node that holds its text: a literal, or an expression. */
50
+ export const TEXT_VALUE = 'value';
51
+ /**
52
+ * The components text between elements was stored as before it was a node of
53
+ * its own: a tree stored then still prints as text, and still renders.
54
+ */
55
+ export const LEGACY_IMPLICIT_TEXTS: readonly string[] = ['Text', 'span'];
50
56
  export const CLASS_NAME = 'className';
51
57
  export const CLASSES_FUNCTION = 'str.classes';
52
58
  export const TEMPLATE_FUNCTION = 'str.template';
@@ -56,6 +62,9 @@ export const FOREACH_COMPONENT = 'foreach';
56
62
  export const FOREACH_LET_PROP = 'let';
57
63
  export const FOREACH_ITEMS_PROP = 'items';
58
64
  export const FOREACH_KEY_PROP = 'key';
65
+ const LOCAL_COMPONENT = 'local';
66
+ const LOCAL_NAME_PROP = 'name';
67
+ const CATALOG_ATTRIBUTE = 'catalog';
59
68
  export const INTO_KEYWORD = 'into';
60
69
  export const EVENT_ROOT = 'event';
61
70
  export const REFETCH_FUNCTION = 'query.refetch';
@@ -378,24 +387,7 @@ class Lowering {
378
387
  return blokError(this.locator, code, offset, fields);
379
388
  }
380
389
 
381
- node(
382
- element: MarkupElement,
383
- derivedId: string,
384
- context: BlokContextName,
385
- parent: string | null,
386
- inheritedLooseText: string = IMPLICIT_TEXT,
387
- ): BlokComponentNode {
388
- const spec = this.view.components.get(element.name);
389
- // the component loose text becomes here, from the nearest non-language ancestor
390
- const catalog = spec?.catalog;
391
- const looseText =
392
- spec === undefined
393
- ? inheritedLooseText
394
- : catalog?.startsWith('html@')
395
- ? IMPLICIT_HTML_TEXT
396
- : catalog?.startsWith('base@')
397
- ? inheritedLooseText
398
- : IMPLICIT_TEXT;
390
+ node(element: MarkupElement, derivedId: string, parent: string | null): BlokComponentNode {
399
391
  if (element.name === ELSE_COMPONENT && parent !== IF_COMPONENT) throw this.fail('bsx.else_outside_if', element.offset);
400
392
  let nodeId = derivedId;
401
393
  const explicit = element.attributes.find(attribute => attribute.name === 'id');
@@ -411,31 +403,15 @@ class Lowering {
411
403
  const props = element.attributes.filter(attribute => attribute.name !== 'id').map(attribute => this.prop(element.name, attribute));
412
404
  if (element.name === FOREACH_COMPONENT) this.checkForeach(element);
413
405
 
414
- const inner = spec ? innerContext(spec, context) : context;
415
-
416
406
  const children: BlokComponentNode[] = [];
417
407
  const runs = this.runs(element);
418
- const hasElements = element.children.some(child => child.kind === 'element');
419
- const textRuns = runs.filter(isTextRun);
420
- let implicitText = false;
421
- if (textRuns.length > 0) {
422
- const textProp = this.textTarget(element, inner, textRuns, hasElements);
423
- implicitText = textProp === null;
424
- if (textProp !== null) {
425
- if (props.some(prop => prop.key === textProp)) {
426
- throw this.fail('bsx.text_and_prop', element.offset, {component: element.name, key: textProp});
427
- }
428
- props.push(this.textProp(textProp, textRuns[0], element.offset));
429
- }
430
- }
431
408
  let implicit = 0;
432
409
  const counts = new Map<string, number>();
433
410
  let seenElse = false;
434
411
  for (const run of runs) {
435
412
  if (isTextRun(run)) {
436
- if (!implicitText) continue;
437
413
  if (seenElse) throw this.fail('bsx.else_order', element.offset);
438
- children.push({id: `${nodeId}/#${implicit}`, component: looseText, props: [this.textProp('text', run, element.offset)]});
414
+ children.push({id: `${nodeId}/#${implicit}`, component: TEXT_NODE, props: [this.textProp(TEXT_VALUE, run, element.offset)]});
439
415
  implicit += 1;
440
416
  continue;
441
417
  }
@@ -446,7 +422,7 @@ class Lowering {
446
422
  }
447
423
  const index = counts.get(child.name) ?? 0;
448
424
  counts.set(child.name, index + 1);
449
- children.push(this.node(child, `${nodeId}/${child.name}[${index}]`, inner, element.name, looseText));
425
+ children.push(this.node(child, `${nodeId}/${child.name}[${index}]`, element.name));
450
426
  }
451
427
  if (element.name === IF_COMPONENT) {
452
428
  const elses = element.children.filter((child): child is MarkupElement => child.kind === 'element' && child.name === ELSE_COMPONENT);
@@ -535,23 +511,6 @@ class Lowering {
535
511
  return runs;
536
512
  }
537
513
 
538
- /** Where text goes: the text_prop (returned), implicit Text nodes (null), or refused. */
539
- private textTarget(element: MarkupElement, context: BlokContextName, runs: Part[][], hasElements: boolean): string | null {
540
- const component = this.view.components.get(element.name);
541
- const sample = runs[0].map(part => (typeof part === 'string' ? part : '{...}')).join('').slice(0, 60);
542
- if (!component) throw this.fail('bsx.text_unknown_component', element.offset, {component: element.name, text: sample});
543
- const drawsText = this.vocabulary.contexts[context];
544
- if (drawsText && !drawsText.text) {
545
- throw this.fail('bsx.text_in_context', element.offset, {component: element.name, context, text: sample});
546
- }
547
- if (component.textProp !== null && !hasElements) {
548
- if (runs.length > 1) throw this.fail('bsx.text_not_accepted', element.offset, {component: element.name, text: sample});
549
- return component.textProp;
550
- }
551
- if (component.textProp !== null || isLanguageContainer(component)) return null;
552
- throw this.fail('bsx.text_not_accepted', element.offset, {component: element.name, text: sample});
553
- }
554
-
555
514
  private textProp(key: string, parts: Part[], offset: number): BlokComponentProp {
556
515
  if (parts.length === 1) {
557
516
  const only = parts[0];
@@ -582,6 +541,17 @@ class Lowering {
582
541
 
583
542
  private prop(component: string, attribute: MarkupAttribute): BlokComponentProp {
584
543
  const value = attribute.value;
544
+ if (component === LOCAL_COMPONENT && attribute.name === LOCAL_NAME_PROP) {
545
+ // A local declares its name, as a foreach's let does.
546
+ if (typeof value !== 'string' || !isLocalName(value)) {
547
+ throw this.fail('local.attribute', attribute.offset, {
548
+ name: typeof value === 'string' ? value : '{...}',
549
+ key: LOCAL_NAME_PROP,
550
+ problem: 'is not a name: write name="x", a plain identifier',
551
+ });
552
+ }
553
+ return {key: attribute.name, static_value: value, declares_value: value};
554
+ }
585
555
  if (value === true) return {key: attribute.name, static_value: true};
586
556
  if (typeof value === 'string') {
587
557
  if (attribute.name === FOREACH_LET_PROP && component === FOREACH_COMPONENT) {
@@ -819,15 +789,32 @@ class Lowering {
819
789
  const utf8Length = (source: string): number => new TextEncoder().encode(source).length;
820
790
 
821
791
  /** Parse a v2 BSX source into the tree a blok stores, and where each node is. Throws a `BsxSyntaxError`. */
822
- export const parseBsx = (source: string, view: BlokView = defaultBlokView()): {tree: BlokComponentNode; sources: BsxSourceMap} => {
792
+ /** The view of the catalog a source's `<Blok catalog=...>` names: the app's own when it names none (`blokViewFor`). */
793
+ const rootView = (root: MarkupElement): BlokView => {
794
+ const catalog = root.attributes.find(attribute => attribute.name === CATALOG_ATTRIBUTE)?.value;
795
+ return typeof catalog === 'string' ? blokViewFor(catalog) : defaultBlokView();
796
+ };
797
+
798
+ /** The catalog a BSX source's `<Blok catalog=...>` names, read off its markup alone; null for none. Throws a `BsxSyntaxError`. */
799
+ export const sourceCatalog = (source: string): string | null => {
800
+ const locator = new Locator(source);
801
+ const catalog = new Markup(source, locator).document().attributes.find(attribute => attribute.name === CATALOG_ATTRIBUTE)?.value;
802
+ return typeof catalog === 'string' ? catalog : null;
803
+ };
804
+
805
+ /**
806
+ * Parse a v2 BSX source into the tree a blok stores, and where each node is.
807
+ * Without a view, the one of the catalog its `<Blok catalog>` names. Throws a `BsxSyntaxError`.
808
+ */
809
+ export const parseBsx = (source: string, view?: BlokView): {tree: BlokComponentNode; sources: BsxSourceMap} => {
823
810
  const locator = new Locator(source);
824
811
  if (utf8Length(source) > MAX_SOURCE_BYTES) {
825
812
  throw blokError(locator, 'bsx.syntax', 0, {detail: `a blok's source is at most ${MAX_SOURCE_BYTES} bytes`});
826
813
  }
827
814
  const markup = new Markup(source, locator);
828
815
  const root = markup.document();
829
- const lowering = new Lowering(view, locator, markup);
830
- const tree = lowering.node(root, `${root.name}[0]`, 'HTML', null);
816
+ const lowering = new Lowering(view ?? rootView(root), locator, markup);
817
+ const tree = lowering.node(root, `${root.name}[0]`, null);
831
818
  return {tree, sources: lowering.sources};
832
819
  };
833
820
 
@@ -60,7 +60,7 @@ describe('parseBsxPartial', () => {
60
60
  const result = parseBsxPartial('<Html><Card><Text>Hel');
61
61
  expect(result.complete).toBe(false);
62
62
  expect(result.error?.code).toBe('bsx.unclosed');
63
- expect(result.tree && [...ids(result.tree)]).toEqual(['Html[0]', 'Html[0]/Card[0]', 'Html[0]/Card[0]/Text[0]']);
63
+ expect(result.tree && [...ids(result.tree)]).toEqual(['Html[0]', 'Html[0]/Card[0]', 'Html[0]/Card[0]/Text[0]', 'Html[0]/Card[0]/Text[0]/#0']);
64
64
  });
65
65
 
66
66
  it('drops a tag that cannot draw until its attributes arrive', () => {
package/src/bsx/print.ts CHANGED
@@ -5,7 +5,7 @@ import type {
5
5
  BlokComponentProp,
6
6
  BlokUtilCall,
7
7
  } from '../renderer/runtime/types';
8
- import {defaultBlokView, innerContext, isLanguageContainer, type BlokView} from '../spec/catalogs';
8
+ import {defaultBlokView, type BlokView} from '../spec/catalogs';
9
9
  import {isExplicitId, loadVocabulary, type BlokContextName} from '../spec/vocabulary';
10
10
  import {
11
11
  CLASS_NAME,
@@ -13,7 +13,9 @@ import {
13
13
  FETCH_MORE_FUNCTION,
14
14
  FOREACH_COMPONENT,
15
15
  FOREACH_LET_PROP,
16
- IMPLICIT_TEXTS,
16
+ LEGACY_IMPLICIT_TEXTS,
17
+ TEXT_NODE,
18
+ TEXT_VALUE,
17
19
  REFETCH_FUNCTION,
18
20
  TEMPLATE_FUNCTION,
19
21
  } from './parse';
@@ -157,10 +159,8 @@ class Printer {
157
159
  this.indent = indent;
158
160
  }
159
161
 
160
- node(node: BlokComponentNode, derived: string, depth: number, context: BlokContextName, lines: string[]): void {
162
+ node(node: BlokComponentNode, derived: string, depth: number, lines: string[]): void {
161
163
  const pad = ' '.repeat(this.indent * depth);
162
- const spec = this.view.components.get(node.component);
163
- const inner = spec ? innerContext(spec, context) : context;
164
164
  const attributes: string[] = [];
165
165
  if (node.id !== derived) {
166
166
  if (!isExplicitId(node.id)) {
@@ -169,23 +169,9 @@ class Printer {
169
169
  attributes.push(`id=${quoted(node.id)}`);
170
170
  }
171
171
  const children = node.children ?? [];
172
- const elements = children.filter(child => !Printer.isImplicit(child, node.id));
173
- let textChild: string | null = null;
174
- const textProp = spec?.textProp ?? null;
175
- const drawsText = this.vocabulary.contexts[inner]?.text ?? true;
176
- const props = node.props ?? [];
177
- props.forEach((prop, position) => {
178
- // The parser puts the prop text children fill last, so only the last is spelled as text.
179
- const last = position === props.length - 1;
180
- if (textProp !== null && prop.key === textProp && last && children.length === 0 && drawsText) {
181
- const printed = this.textOf(prop, node, true);
182
- if (printed !== null) {
183
- textChild = printed;
184
- return;
185
- }
186
- }
187
- attributes.push(this.attribute(node, prop));
188
- });
172
+ // Its one child a text node: spelled on the line of its tags.
173
+ const textChild = children.length === 1 && Printer.isImplicit(children[0], node.id) ? this.textNode(children[0], true) : null;
174
+ for (const prop of node.props ?? []) attributes.push(this.attribute(node, prop));
189
175
  let head = `<${node.component}${attributes.map(attribute => ` ${attribute}`).join('')}`;
190
176
  const wrapped = pad.length + head.length > LINE_WIDTH && attributes.length > 1;
191
177
  if (wrapped) {
@@ -204,27 +190,32 @@ class Printer {
204
190
  let implicit = 0;
205
191
  for (const child of children) {
206
192
  if (Printer.isImplicit(child, node.id)) {
207
- if (elements.length === 0 && !isLanguageContainer(spec)) {
208
- refuse(`<${node.component}> (${node.id}) holds implicit Text with no element beside it`);
209
- }
210
- if (child.id !== `${node.id}/#${implicit}`) refuse(`<${node.component}> (${node.id}): implicit Text '${child.id}' is out of order`);
193
+ if (child.id !== `${node.id}/#${implicit}`) refuse(`<${node.component}> (${node.id}): the text node '${child.id}' is out of order`);
211
194
  implicit += 1;
212
- const only = child.props && child.props.length === 1 ? child.props[0] : null;
213
- const text = only ? this.textOf(only, child, false) : null;
214
- if (text === null) refuse(`implicit Text '${child.id}' cannot be spelled as text`);
215
- lines.push(`${pad}${' '.repeat(this.indent)}${text}`);
195
+ lines.push(`${pad}${' '.repeat(this.indent)}${this.textNode(child, false)}`);
216
196
  continue;
217
197
  }
218
198
  const index = counts.get(child.component) ?? 0;
219
199
  counts.set(child.component, index + 1);
220
- this.node(child, `${node.id}/${child.component}[${index}]`, depth + 1, inner, lines);
200
+ this.node(child, `${node.id}/${child.component}[${index}]`, depth + 1, lines);
221
201
  }
222
202
  lines.push(`${pad}</${node.component}>`);
223
203
  }
224
204
 
205
+ /** Whether `child` is a run of text of `parent`: a text node, or what one was stored as before. */
225
206
  static isImplicit(child: BlokComponentNode, parent: string): boolean {
226
207
  const match = IMPLICIT.exec(child.id);
227
- return match !== null && match.groups?.parent === parent && IMPLICIT_TEXTS.includes(child.component);
208
+ return match !== null && match.groups?.parent === parent && (child.component === TEXT_NODE || LEGACY_IMPLICIT_TEXTS.includes(child.component));
209
+ }
210
+
211
+ /** A text node as the text it was parsed from; refuses one that holds anything but its one value. */
212
+ private textNode(child: BlokComponentNode, inline: boolean): string {
213
+ const key = child.component === TEXT_NODE ? TEXT_VALUE : 'text';
214
+ const props = child.props ?? [];
215
+ const only = props.length === 1 && props[0].key === key && !(child.children && child.children.length > 0) ? props[0] : null;
216
+ const text = only ? this.textOf(only, child, inline) : null;
217
+ if (text === null) return refuse(`the text node '${child.id}' cannot be spelled as text`);
218
+ return text;
228
219
  }
229
220
 
230
221
  /**
@@ -233,7 +224,6 @@ class Printer {
233
224
  * its ends; on a line of its own they are trimmed, so they are spelled as strings.
234
225
  */
235
226
  private textOf(prop: BlokComponentProp, node: BlokComponentNode, inline: boolean): string | null {
236
- if (prop.key !== 'text' && IMPLICIT_TEXTS.includes(node.component)) return null;
237
227
  if (prop.declares_value || prop.agent_call) return null;
238
228
  if (typeof prop.static_value === 'string') return textLiteral(prop.static_value, !inline);
239
229
  if (prop.dynamic_value) {
@@ -266,6 +256,9 @@ class Printer {
266
256
  if (node.component === FOREACH_COMPONENT && key === FOREACH_LET_PROP && prop.static_value === prop.declares_value) {
267
257
  return `${key}=${quoted(prop.declares_value)}`;
268
258
  }
259
+ if (node.component === 'local' && key === 'name' && prop.static_value === prop.declares_value) {
260
+ return `${key}=${quoted(prop.declares_value)}`;
261
+ }
269
262
  return refuse(`<${node.component}> (${node.id}): ${key} declares '${prop.declares_value}', which BSX cannot spell`);
270
263
  }
271
264
  if (prop.util_call) {
@@ -406,7 +399,7 @@ class Printer {
406
399
  /** Print `node` as v2 BSX that `parseBsx` (with the same view) reads back into it. Throws a `BsxPrintError`. */
407
400
  export const printBsx = (node: BlokComponentNode, options: {view?: BlokView; indent?: number} = {}): string => {
408
401
  const lines: string[] = [];
409
- new Printer(options.view ?? defaultBlokView(), options.indent ?? 2).node(node, `${node.component}[0]`, 0, 'HTML', lines);
402
+ new Printer(options.view ?? defaultBlokView(), options.indent ?? 2).node(node, `${node.component}[0]`, 0, lines);
410
403
  return lines.join('\n');
411
404
  };
412
405
 
@@ -1,31 +1,30 @@
1
1
  import {describe, expect, it} from 'vitest';
2
2
  import corpus from '../spec/bsx_v2.json';
3
- import {blokView, defaultBlokView, parseSpecCatalog, type BlokView} from '../spec/catalogs';
4
- import {resolveBlokScope} from './infer';
3
+ import {baseBlokView, blokViewFor, type BlokView} from '../spec/catalogs';
4
+ import {blokCatalog} from './declared';
5
+ import {resolveLocals} from './infer';
5
6
  import {parseBsx} from './parse';
6
- import {checkBlokTree, dependencyHint, emptyBlokScope, type BlokCheckScope} from './references';
7
+ import {checkBlokTree, dependencyHint, mountedBlokScope, type BlokCheckScope} from './references';
8
+ import type {BlokComponentNode} from '../renderer/runtime/types';
7
9
 
8
- type CorpusScope = Omit<BlokCheckScope, 'module'> & {catalog?: boolean; module?: unknown};
10
+ /** Where a corpus case is checked: the spec's `mount`, and whether a catalog is read at all. */
11
+ type CorpusMount = Omit<BlokCheckScope, 'catalog'> & {catalog: boolean};
12
+
13
+ const scopeOf = (mount: CorpusMount): BlokCheckScope => ({kinds: mount.kinds, dependencies: mount.dependencies, args: mount.args});
9
14
  type CheckedCase = {
10
15
  name: string;
11
16
  source: string;
12
- scope: CorpusScope;
13
- /** The locals after `resolve_scope`, each kinded: nothing else is resolved. */
14
- resolved: {locals: unknown[]};
17
+ mount: CorpusMount;
18
+ /** Each `<local>` after `resolve_locals`, by node id, kinded: nothing else is resolved. */
19
+ resolved: {locals: Record<string, unknown>};
15
20
  codes: string[];
16
21
  };
17
22
 
18
- /** The view a case is checked with: none, the Orkestrator's, or that plus the case's module. */
19
- const caseView = (scope: CorpusScope): BlokView | null => {
20
- if (scope.catalog === false) return null;
21
- if (scope.module == null) return defaultBlokView();
22
- return blokView([parseSpecCatalog(scope.module, 'module')]);
23
- };
24
-
25
- const caseScope = (scope: CorpusScope): BlokCheckScope => {
26
- const {module} = scope;
27
- const named = typeof module === 'object' && module !== null && 'name' in module && typeof module.name === 'string' ? module.name : null;
28
- return {...scope, module: named};
23
+ /** The view a case is checked with: none (the language alone), else that of the catalog its <Blok> names (the base's for none). */
24
+ const caseView = (mount: CorpusMount, tree: BlokComponentNode): BlokView | null => {
25
+ if (mount.catalog === false) return null;
26
+ const catalog = blokCatalog(tree);
27
+ return catalog === null ? baseBlokView() : blokViewFor(catalog);
29
28
  };
30
29
 
31
30
  /** The wire spells "nothing" as null or leaves it out (as bsx.test.ts compares trees). */
@@ -37,7 +36,6 @@ const withoutNulls = (value: unknown): unknown => {
37
36
  return value;
38
37
  };
39
38
 
40
- /** The fields the spec's models dump at their defaults; the resolver leaves them out. */
41
39
  const PYDANTIC_DEFAULTS: Readonly<Record<string, unknown>> = {
42
40
  optional: false,
43
41
  auto_resolvable: false,
@@ -63,7 +61,7 @@ const withoutDefaults = (value: unknown): unknown => {
63
61
  };
64
62
 
65
63
  const checked = (corpus.cases as ReadonlyArray<Record<string, unknown>>).filter(
66
- (entry): entry is CheckedCase & Record<string, unknown> => 'scope' in entry && 'codes' in entry,
64
+ (entry): entry is CheckedCase & Record<string, unknown> => 'mount' in entry && 'codes' in entry,
67
65
  );
68
66
 
69
67
  describe('the validator against the corpus', () => {
@@ -73,8 +71,7 @@ describe('the validator against the corpus', () => {
73
71
 
74
72
  it.each(checked.map(entry => [entry.name, entry] as const))('%s', (_name, entry) => {
75
73
  const {tree} = parseBsx(entry.source);
76
- const view = caseView(entry.scope);
77
- const findings = checkBlokTree(tree, caseScope(entry.scope), view);
74
+ const findings = checkBlokTree(tree, scopeOf(entry.mount), caseView(entry.mount, tree));
78
75
  expect(findings.map(found => found.code).sort()).toEqual([...entry.codes].sort());
79
76
  });
80
77
  });
@@ -82,50 +79,48 @@ describe('the validator against the corpus', () => {
82
79
  describe('inference against the corpus', () => {
83
80
  it.each(checked.map(entry => [entry.name, entry] as const))('%s', (_name, entry) => {
84
81
  const {tree} = parseBsx(entry.source);
85
- const resolved = resolveBlokScope(tree, caseScope(entry.scope), caseView(entry.scope));
82
+ const resolved = resolveLocals(tree, entry.mount.dependencies, caseView(entry.mount, tree));
86
83
  expect(Object.keys(entry.resolved)).toEqual(['locals']);
87
- expect(withoutDefaults({locals: resolved.locals})).toEqual(withoutDefaults(entry.resolved));
88
- // Dependencies are never inferred: they stay as declared.
89
- expect(resolved.dependencies).toBe(caseScope(entry.scope).dependencies);
90
- });
91
-
92
- it('is idempotent', () => {
93
- for (const entry of checked) {
94
- const {tree} = parseBsx(entry.source);
95
- const once = resolveBlokScope(tree, caseScope(entry.scope), null);
96
- const twice = resolveBlokScope(tree, once, null);
97
- expect(twice).toEqual(once);
98
- }
84
+ const locals = Object.fromEntries([...resolved].map(([node, {local}]) => [node, local]));
85
+ expect(withoutDefaults(locals)).toEqual(withoutDefaults(entry.resolved.locals));
99
86
  });
100
87
  });
101
88
 
89
+ /** A panel blok of `kind` around `body`. */
90
+ const blok = (kind: string, body: string, attributes = '') => `<Blok kind="${kind}" context="panel"${attributes}>${body}</Blok>`;
91
+ /** Mounted with no dependencies: every one it reads is undeclared. */
92
+ const mounted = mountedBlokScope();
93
+
102
94
  describe('findings', () => {
103
95
  it('name the node and prop they are about, with a filled message', () => {
104
- const {tree} = parseBsx('<Html><Card><Text text={deps.nope.x} /></Card></Html>');
105
- const [found] = checkBlokTree(tree, emptyBlokScope('custom'));
106
- expect(found).toMatchObject({code: 'deps.unknown', level: 'error', nodeId: 'Html[0]/Card[0]/Text[0]', propKey: 'text'});
96
+ const {tree} = parseBsx(blok('custom', '<Card><Text text={deps.nope.x} /></Card>'));
97
+ const [found] = checkBlokTree(tree, mounted);
98
+ expect(found).toMatchObject({code: 'deps.unknown', level: 'error', nodeId: 'Blok[0]/Card[0]/Text[0]', propKey: 'text'});
107
99
  expect(found.message).toBe(
108
100
  'deps.nope.x: \'nope\' is not a dependency of the blok (its dependencies: none). Fix: dependencies=[AgentDependencyInput(key="nope")].',
109
101
  );
110
102
  });
111
103
 
112
104
  it('hint the declaration a custom blok misses, for a read, a call and a query variable', () => {
113
- const {tree} = parseBsx('<Html><Card><Text text={queries.positions.status} /><Button onClick={deps.stage.move(x: 1)} /></Card></Html>');
114
- const scope: BlokCheckScope = {
115
- ...emptyBlokScope('custom'),
116
- dependencies: [{key: 'robot'}],
117
- queries: [{key: 'positions', service: 'mikro', document: 'query { positions { id } }', variables: [{key: 'agent', value_path: 'deps.laser.id'}]}],
118
- };
119
- const found = checkBlokTree(tree, scope).filter(finding => finding.code === 'deps.unknown');
105
+ const {tree} = parseBsx(
106
+ blok(
107
+ 'custom',
108
+ '<query name="positions" service="mikro" document="query { positions { id } }"><var key="agent" value={deps.laser.id} /></query><Card><Text text={queries.positions.status} /><Button onClick={deps.stage.move(x: 1)} /></Card>',
109
+ ),
110
+ );
111
+ const found = checkBlokTree(tree, mountedBlokScope([], [{key: 'robot'}])).filter(finding => finding.code === 'deps.unknown');
120
112
  expect(found.map(finding => finding.message).sort()).toEqual([
121
- 'onClick of <Button> (Html[0]/Card[0]/Button[0]): \'stage\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="stage")].',
113
+ 'onClick of <Button> (Blok[0]/Card[0]/Button[0]): \'stage\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="stage")].',
122
114
  'deps.laser.id: \'laser\' is not a dependency of the blok (its dependencies: robot). Fix: dependencies=[AgentDependencyInput(key="laser")].',
123
115
  ].sort());
124
116
  });
125
117
 
118
+ it('take what the mount provides as written where the blok is mounted nowhere', () => {
119
+ expect(checkBlokTree(parseBsx(blok('custom', '<Text text={deps.nope.x} /><Button onClick={deps.stage.move(x: 1)} />')).tree)).toEqual([]);
120
+ });
121
+
126
122
  it('hint per kind what a blok reading an undeclared dependency does about it, as the spec does', () => {
127
- const {tree} = parseBsx('<Html><Text text={deps.laser.power} /></Html>');
128
- const message = (kind: BlokCheckScope['kind']): string => checkBlokTree(tree, emptyBlokScope(kind))[0]?.message ?? '';
123
+ const message = (kind: string): string => checkBlokTree(parseBsx(blok(kind, '<Text text={deps.laser.power} />')).tree, mounted)[0]?.message ?? '';
129
124
  expect(message('custom')).toContain('Fix: dependencies=[AgentDependencyInput(key="laser")].');
130
125
  expect(message('task')).toContain('Fix: dependencies=[AgentDependencyInput(key="laser")].');
131
126
  expect(message('action')).toContain('Fix: add a dependency parameter `laser` to the action.');
@@ -135,86 +130,94 @@ describe('findings', () => {
135
130
 
136
131
  it('scope a let to its loop and an into name to the whole tree', () => {
137
132
  const {tree} = parseBsx(
138
- '<Html><Card><foreach items={args.xs} let="p" key={p.id}><Button onClick={self.go(to: p.id) into run} /></foreach><Text text={run.status} /></Card></Html>',
133
+ blok('agent', '<Card><foreach items={args.xs} let="p" key={p.id}><Button onClick={self.go(to: p.id) into run} /></foreach><Text text={run.status} /></Card>'),
139
134
  );
140
- expect(checkBlokTree(tree, emptyBlokScope('agent'))).toEqual([]);
135
+ expect(checkBlokTree(tree, mounted)).toEqual([]);
136
+ });
137
+
138
+ it('scope a local to its parent\'s subtree', () => {
139
+ const {tree} = parseBsx(blok('agent', '<Card><local name="open" default={false} /><Switch bind={open} /></Card><Switch bind={open} />'));
140
+ // Outside its scope the name is neither a local to write nor a root to read (as the spec says).
141
+ expect(checkBlokTree(tree, mounted).map(found => [found.code, found.nodeId])).toEqual([['local.unknown', 'Blok[0]/Switch[0]'], ['roots.unknown', 'Blok[0]/Switch[0]']]);
141
142
  });
142
143
 
143
144
  it('fill the bind and argument kind messages', () => {
144
- const {tree} = parseBsx('<Html><Card><Switch bind={count} /><Button onClick={self.go(to: count)} /></Card></Html>');
145
- const scope: BlokCheckScope = {
146
- ...emptyBlokScope('agent'),
147
- dependencies: [{key: 'self', action_dependencies: [{key: 'go', demand: {arg_matches: [{key: 'to', kind: 'BOOL'}]}}]}],
148
- locals: [{key: 'count', kind: 'INT', default: 1}],
149
- };
145
+ const {tree} = parseBsx(blok('agent', '<local name="count" kind="INT" default={1} /><Card><Switch bind={count} /><Button onClick={self.go(to: count)} /></Card>'));
146
+ const scope = mountedBlokScope([], [{key: 'self', action_dependencies: [{key: 'go', demand: {arg_matches: [{key: 'to', kind: 'BOOL'}]}}]}]);
150
147
  const findings = checkBlokTree(tree, scope);
151
148
  expect(findings.map(found => found.code)).toEqual(['local.bind_kind', 'local.arg_kind']);
152
- expect(findings[0]).toMatchObject({nodeId: 'Html[0]/Card[0]/Switch[0]', propKey: 'bind'});
149
+ expect(findings[0]).toMatchObject({nodeId: 'Blok[0]/Card[0]/Switch[0]', propKey: 'bind'});
153
150
  expect(findings[0].message).toBe('bind of <Switch> writes a BOOL, but count is a INT local (a BOOL control writes BOOL).');
154
151
  expect(findings[1].message).toBe('self.go: to takes a BOOL, but count is a INT local.');
155
152
  });
156
153
 
157
154
  it('bind error only inside an error slot', () => {
158
- const {tree} = parseBsx('<Html><suspense><error><Alert>{error.message}</Alert></error><Text /></suspense></Html>');
159
- expect(checkBlokTree(tree, emptyBlokScope('agent'))).toEqual([]);
155
+ const {tree} = parseBsx(blok('agent', '<suspense><error><Alert>{error.message}</Alert></error><Text /></suspense>'));
156
+ expect(checkBlokTree(tree, mounted)).toEqual([]);
160
157
  });
161
158
  });
162
159
 
160
+ const codes = (source: string, scope: BlokCheckScope = mounted) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
161
+
163
162
  describe('what an assign blok places and reads of the run it prepares', () => {
164
- const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
165
- const assign = {...emptyBlokScope('assign'), args: ['image', 'exposure']};
163
+ const assign = mountedBlokScope([], [], ['image', 'exposure']);
166
164
 
167
165
  it('reads assign.given.<key>, assign.missing and assign.ready', () => {
168
- const source =
169
- '<Html><if when={assign.given.image}><Text text={args.image} /></if><arg key="exposure" /><args /><deps /><Button onClick={assign.start()} disabled={!assign.ready}>Run</Button></Html>';
166
+ const source = blok(
167
+ 'assign',
168
+ '<if when={assign.given.image}><Text text={args.image} /></if><arg key="exposure" /><args /><deps /><Button onClick={assign.start()} disabled={!assign.ready}>Run</Button>',
169
+ );
170
170
  expect(codes(source, assign)).toEqual([]);
171
171
  });
172
172
 
173
173
  it('refuses a given flag for an argument the action has not, and a field assign has not', () => {
174
- expect(codes('<Html><Text text={assign.given.nope} /></Html>', assign)).toEqual(['args.unknown']);
175
- expect(codes('<Html><Text text={assign.nope} /></Html>', assign)).toEqual(['path.unknown']);
174
+ expect(codes(blok('assign', '<Text text={assign.given.nope} />'), assign)).toEqual(['args.unknown']);
175
+ expect(codes(blok('assign', '<Text text={assign.nope} />'), assign)).toEqual(['path.unknown']);
176
176
  });
177
177
 
178
178
  it('keeps <arg>, <deps>, <dep> and the assign root to an assign blok', () => {
179
- const task = emptyBlokScope('task');
180
- expect(codes('<Html><arg key="image" /></Html>', task)).toEqual(['assign.kind']);
181
- expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['assign.kind', 'assign.kind']);
182
- expect(codes('<Html><Text text={assign.ready} /></Html>', task)).toEqual(['roots.not_in_kind']);
179
+ expect(codes(blok('task', '<arg key="image" />'))).toEqual(['catalog.kind']);
180
+ expect(codes(blok('task', '<deps /><dep key="robot" />'))).toEqual(['catalog.kind', 'catalog.kind']);
181
+ // The language alone knows no kind of a component: that is the catalog's to say.
182
+ expect(checkBlokTree(parseBsx(blok('task', '<arg key="image" />')).tree, mounted, null)).toEqual([]);
183
+ expect(codes(blok('task', '<Text text={assign.ready} />'))).toEqual(['roots.not_in_kind']);
183
184
  });
184
185
  });
185
186
 
186
187
  describe('what a blok does to the task it is about', () => {
187
- const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
188
-
189
188
  it('cancels, pauses, resumes, steps and interrupts it, and reads whether it may', () => {
190
- const source =
191
- '<Html><Button onClick={task.cancel()} disabled={!task.can.cancel}>Stop</Button><Button onClick={task.pause()}>Pause</Button><Button onClick={task.resume()}>Resume</Button><Button onClick={task.step()}>Step</Button><Button onClick={task.interrupt()}>Kill</Button><Text text={deps.robot.connected ? task.started_at : task.status} /></Html>';
192
- const scope = {...emptyBlokScope('action'), dependencies: [{key: 'robot'}]} as BlokCheckScope;
193
- expect(codes(source, scope)).toEqual([]);
189
+ const source = blok(
190
+ 'action',
191
+ '<Button onClick={task.cancel()} disabled={!task.can.cancel}>Stop</Button><Button onClick={task.pause()}>Pause</Button><Button onClick={task.resume()}>Resume</Button><Button onClick={task.step()}>Step</Button><Button onClick={task.interrupt()}>Kill</Button><Text text={deps.robot.connected ? task.started_at : task.status} />',
192
+ );
193
+ expect(codes(source, mountedBlokScope([], [{key: 'robot'}]))).toEqual([]);
194
194
  });
195
195
 
196
196
  it('starts no run again: a rerun is the page\'s, never a blok\'s', () => {
197
- expect(() => parseBsx('<Html><Button onClick={task.rerun()}>Again</Button></Html>')).toThrow(/calls nothing/);
197
+ expect(() => parseBsx(blok('action', '<Button onClick={task.rerun()}>Again</Button>'))).toThrow(/calls nothing/);
198
198
  });
199
199
 
200
200
  it('refuses them where there is no task', () => {
201
- expect(codes('<Html><Button onClick={task.cancel()}>Stop</Button></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind']);
201
+ expect(codes(blok('assign', '<Button onClick={task.cancel()}>Stop</Button>'))).toEqual(['roots.not_in_kind']);
202
202
  });
203
203
  });
204
204
 
205
205
  describe('what a blok places of its task, and what it leaves the host', () => {
206
- const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
207
-
208
206
  it('places the result, the status line and the time slider, and says how much chrome it wants', () => {
209
- const source = '<Html chrome="none"><status /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} /></Html>';
210
- expect(codes(source, emptyBlokScope('action'))).toEqual([]);
207
+ const source = blok('action', '<status /><ask /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} />', ' chrome="none"');
208
+ expect(codes(source)).toEqual([]);
209
+ });
210
+
211
+ it('warns where no chrome leaves the asks to a blok that places none, and where a part is claimed from inside a branch', () => {
212
+ expect(codes(blok('action', '<status />', ' chrome="none"'))).toEqual(['chrome.no_ask']);
213
+ expect(codes(blok('action', '<if when={task.running}><timeline /></if>'))).toEqual(['part.conditional']);
211
214
  });
212
215
 
213
216
  it('keeps <returns> and <status> to a blok that has a task', () => {
214
- expect(codes('<Html><returns /><status /></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind', 'roots.not_in_kind']);
217
+ expect(codes(blok('assign', '<returns /><status />'))).toEqual(['catalog.kind', 'catalog.kind']);
215
218
  });
216
219
 
217
220
  it('reads what an assign blok knows of starting', () => {
218
- expect(codes('<Html><Text text={assign.blocked} /><Button disabled={assign.starting} onClick={assign.start()}>Run</Button></Html>', emptyBlokScope('assign'))).toEqual([]);
221
+ expect(codes(blok('assign', '<Text text={assign.blocked} /><Button disabled={assign.starting} onClick={assign.start()}>Run</Button>'))).toEqual([]);
219
222
  });
220
223
  });