@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
@@ -1,30 +1,61 @@
1
- import { defaultBlokView } from '../spec/catalogs.js';
1
+ import { blokViewFor, defaultBlokView } from '../spec/catalogs.js';
2
+ import { TEXT_NODE } from './parse.js';
2
3
  import { valueFitsPort } from '../spec/locals.js';
3
- import { LOCAL_ANY, resolveBlokScope } from './infer.js';
4
- import { argFits, finding, loadVocabulary, } from '../spec/vocabulary.js';
5
- export const emptyBlokScope = (kind = 'agent', context = 'HTML') => ({
6
- kind,
7
- context,
8
- dependencies: [],
9
- locals: [],
10
- queries: [],
11
- subscriptions: [],
12
- args: null,
13
- catalogs: [],
14
- });
15
- const ACTION_LOGO = 'ACTION_LOGO';
4
+ import { LOCAL_ANY, localDeclared, resolveLocals } from './infer.js';
5
+ import { blokCatalog, blokHeader, content, declarationProblem, declaredQueries, declaredSubscriptions, headerProblem, isDeclaration, iterWithParents, LIKE_PROP, LOCAL_COMPONENT, localName, localProblem, QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, VAR_COMPONENT, } from './declared.js';
6
+ import { argFits, finding, kindIn, loadVocabulary, } from '../spec/vocabulary.js';
7
+ /** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
8
+ const splitClass = (token) => {
9
+ const parts = [];
10
+ let depth = 0;
11
+ let current = '';
12
+ for (const character of token) {
13
+ if (character === '[')
14
+ depth += 1;
15
+ else if (character === ']')
16
+ depth = Math.max(0, depth - 1);
17
+ if (character === ':' && depth === 0) {
18
+ parts.push(current);
19
+ current = '';
20
+ }
21
+ else
22
+ current += character;
23
+ }
24
+ parts.push(current);
25
+ return parts;
26
+ };
27
+ /** What of the class `token` is outside the portable subset (`the before variant`), or null. */
28
+ export const unportableClass = (token, vocabulary) => {
29
+ const parts = splitClass(token);
30
+ const utility = (parts.pop() ?? '').replace(/^[!-]+/, '');
31
+ for (const variant of parts) {
32
+ if (variant.startsWith('['))
33
+ return 'an arbitrary variant';
34
+ const name = variant.split('/')[0];
35
+ if (vocabulary.unportableVariants.has(name) || vocabulary.unportableVariants.has(name.split('-[')[0]))
36
+ return `the ${name} variant`;
37
+ }
38
+ if (utility.startsWith('['))
39
+ return 'an arbitrary property';
40
+ if (utility.includes('[')) {
41
+ const prefix = utility.split('-[')[0];
42
+ return vocabulary.arbitraryValues.has(prefix) ? null : `an arbitrary value of ${prefix}`;
43
+ }
44
+ for (const prefix of vocabulary.unportableUtilities) {
45
+ if (utility === prefix || utility.startsWith(`${prefix}-`))
46
+ return `the ${prefix} utility`;
47
+ }
48
+ return null;
49
+ };
50
+ /** A blok checked on its own, mounted nowhere: what an editor checks from the source alone. */
51
+ export const unmountedBlokScope = () => ({ kinds: [], dependencies: null, args: null });
52
+ /** A blok mounted where `kinds` go, with `dependencies` (none by default): every agent it reads must be one of them. */
53
+ export const mountedBlokScope = (kinds = [], dependencies = [], args = null) => ({ kinds, dependencies, args });
16
54
  const LOGO = 'LOGO';
17
55
  const SCENE = 'SCENE';
18
- /** The context a scope's components are drawn in: an action logo's is a logo's. */
19
- export const drawnIn = (scope) => (scope.context === ACTION_LOGO ? LOGO : scope.context);
20
- /** The root components a blok of ``context`` may start with (`HTML` → `Html`; `SCENE` → `Scene`, `Space`): a blok's root names its context. */
21
- export const blokRootsOf = (context) => Object.entries(loadVocabulary().blokRoots)
22
- .filter(([, named]) => named === context)
23
- .map(([root]) => root);
24
- /** The root a new blok of ``context`` starts with: the first it may start with (`SCENE` → `Scene`). */
25
- export const blokRootOf = (context) => blokRootsOf(context)[0] ?? null;
26
- /** The blok context a root component names (`Space` → `SCENE`), or null when it names none. */
27
- export const blokContextOf = (component) => loadVocabulary().blokRoots[component] ?? null;
56
+ const PANEL = 'PANEL';
57
+ /** A context as a `<Blok context>` spells it (`PANEL` → `panel`). */
58
+ export const spelledContext = (context) => context.toLowerCase();
28
59
  /* -------------------------------------------------------------------------- */
29
60
  /* Matches */
30
61
  /* -------------------------------------------------------------------------- */
@@ -33,10 +64,10 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
33
64
  /** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
34
65
  const RUN_KINDS = ['action', 'assign'];
35
66
  const ASSIGN_KIND = 'assign';
36
- /** What an assign blok places of the host's own: the argument form or one argument, the dependency picker or one dependency. */
37
- const ASSIGN_COMPONENTS = new Set(['args', 'arg', 'deps', 'dep']);
38
- /** What a blok places of the task it is about: only a kind with a `task`. */
39
- const TASK_COMPONENTS = new Set(['returns', 'status']);
67
+ const ASK_COMPONENT = 'ask';
68
+ const CHROME_NONE = 'none';
69
+ /** The language's elements whose children do not always show: a host part inside one still claims its slot. */
70
+ const CONDITIONAL_COMPONENTS = new Set(['if', 'else', 'match', 'case', 'default', 'foreach', 'suspense', 'fallback', 'error']);
40
71
  /** The one field of an agent that is not text. */
41
72
  const AGENT_CONNECTED = 'connected';
42
73
  /** Where an assign blok reads which arguments the caller decided. */
@@ -122,19 +153,23 @@ export const foreachLet = (node) => {
122
153
  return null;
123
154
  return node.props?.find(prop => prop.key === FOREACH_LET && prop.declares_value)?.declares_value ?? null;
124
155
  };
125
- const iterNodes = (node) => [node, ...(node.children ?? []).flatMap(iterNodes)];
126
- /** Every path a list of arguments reads (a query's variables), depth first. */
127
- const argumentPaths = (args) => {
128
- const paths = [];
129
- const visit = (argument) => {
130
- if (argument.value_path != null)
131
- paths.push(argument.value_path);
132
- for (const call of [argument.util_call, argument.agent_call])
133
- call?.arguments?.forEach(visit);
134
- [...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(visit);
135
- };
136
- args.forEach(visit);
137
- return paths;
156
+ const isLocalBinding = (binding) => binding !== null && binding !== undefined && binding.local === true;
157
+ /** What a name in scope is, for `roots.shadow`. */
158
+ const bindingWhat = (name, binding, into) => {
159
+ if (isLocalBinding(binding))
160
+ return `the local ${binding.node}`;
161
+ if (into.has(name))
162
+ return "a call's record";
163
+ return 'a let';
164
+ };
165
+ const LOCAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
166
+ const FIELD_PATH = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
167
+ /** The kind of a GraphQL document's first operation: `query` (also for `{ ... }`), `mutation`, `subscription`, `fragment`. */
168
+ export const operationKeyword = (document) => {
169
+ const text = document.replace(/#[^\n]*/g, '').trimStart();
170
+ if (text.startsWith('{'))
171
+ return 'query';
172
+ return /^[A-Za-z_]+/.exec(text)?.[0] ?? '';
138
173
  };
139
174
  /* -------------------------------------------------------------------------- */
140
175
  /* The checker */
@@ -155,7 +190,7 @@ const DIGITS = /^[0-9]+$/;
155
190
  * - an agent blok has none: ``agent bloks read only `self` ``.
156
191
  */
157
192
  export const dependencyHint = (key, kind) => {
158
- if (kind === 'action' || kind === 'assign' || kind === 'action_logo')
193
+ if (kind === 'action' || kind === 'assign')
159
194
  return `add a dependency parameter \`${key}\` to the action`;
160
195
  if (kind === 'agent')
161
196
  return 'agent bloks read only `self`';
@@ -241,25 +276,37 @@ const argumentWhat = (argument) => {
241
276
  class Checker {
242
277
  findings = [];
243
278
  vocabulary = loadVocabulary();
279
+ /** The kind's row in the blok's context (an action's logo reads only `task`). */
244
280
  kind;
281
+ kindName;
282
+ context;
283
+ mounted;
245
284
  dependencies;
246
- locals;
247
- queries;
248
- subscriptions;
285
+ /** Per `<local>` node id, its port with its kind resolved. */
286
+ resolved;
287
+ queries = new Map();
288
+ subscriptions = new Map();
289
+ /** The node ids of the locals a control binds. */
249
290
  boundLocals = new Set();
250
291
  into = new Set();
251
- shadowed = new Set();
292
+ asks = false;
293
+ /** The id of the root that says `chrome="none"`, when it does. */
294
+ chromeless;
252
295
  colour;
296
+ header;
253
297
  scope;
254
298
  view;
255
- constructor(scope, view) {
299
+ constructor(header, scope, view, resolved) {
300
+ this.header = header;
256
301
  this.scope = scope;
257
302
  this.view = view;
258
- this.kind = this.vocabulary.kinds[scope.kind];
259
- this.dependencies = new Map(scope.dependencies.map(dependency => [dependency.key, dependency]));
260
- this.locals = new Map(scope.locals.map(local => [local.key, local]));
261
- this.queries = new Map(scope.queries.map(query => [query.key, query]));
262
- this.subscriptions = new Map(scope.subscriptions.map(subscription => [subscription.key, subscription]));
303
+ this.kindName = header.kind;
304
+ this.context = header.context;
305
+ this.kind = kindIn(this.vocabulary.kinds[header.kind], header.context);
306
+ this.mounted = scope.dependencies !== null;
307
+ this.dependencies = new Map((scope.dependencies ?? []).map(dependency => [dependency.key, dependency]));
308
+ this.resolved = resolved;
309
+ this.chromeless = header.chrome === CHROME_NONE ? header.node : null;
263
310
  this.colour = colourPattern(this.vocabulary);
264
311
  }
265
312
  add(code, nodeId, fields = {}, propKey) {
@@ -269,76 +316,166 @@ class Checker {
269
316
  return [...this.kind.roots].sort().join(', ');
270
317
  }
271
318
  notInKind(nodeId, path, root, propKey) {
272
- this.add('roots.not_in_kind', nodeId, { path, n: article(this.scope.kind), kind: this.scope.kind, root, roots: this.rootsText() }, propKey);
319
+ this.add('roots.not_in_kind', nodeId, { path, n: article(this.kindName), kind: this.kindName, root, roots: this.rootsText() }, propKey);
273
320
  }
274
321
  /* -- declarations -- */
275
322
  checkDeclarations(tree) {
276
- const { vocabulary, scope } = this;
277
- const drawn = drawnIn(scope);
278
- const wrongLogo = (scope.context === ACTION_LOGO) !== (scope.kind === 'action_logo');
279
- if (wrongLogo || !this.kind.contexts.includes(drawn)) {
280
- this.add('context.kind', null, { n: article(scope.kind), kind: scope.kind, contexts: this.kind.contexts.join(', '), context: scope.context });
281
- }
282
- // A context may have several roots (a SCENE blok is a <Scene> or a <Space>).
283
- const roots = blokRootsOf(scope.context);
284
- if (roots.length && !roots.includes(tree.component)) {
285
- this.add('context.root', tree.id, { context: scope.context.toLowerCase(), root: roots.join('> or <'), component: tree.component });
286
- }
287
- if (scope.locals.length && !this.kind.locals)
288
- this.notInKind(null, 'locals', 'locals');
289
- for (const local of scope.locals) {
290
- if (vocabulary.reserved.has(local.key))
291
- this.add('roots.reserved', `locals.${local.key}`, { name: local.key });
292
- this.checkLocalDefault(local);
323
+ const { vocabulary, header } = this;
324
+ const kind = this.kindName;
325
+ const row = vocabulary.kinds[kind];
326
+ const contextName = spelledContext(header.context);
327
+ if (!row.contexts.includes(header.context)) {
328
+ this.add('context.kind', tree.id, { n: article(kind), kind, contexts: row.contexts.map(spelledContext).join(', '), context: contextName });
329
+ }
330
+ const kinds = this.scope.kinds ?? [];
331
+ if (kinds.length && !kinds.includes(kind)) {
332
+ this.add('kind.placement', tree.id, { n: article(kind), kind, m: article(kinds[0]), expected: kinds.join(' or '), where: this.scope.mount || 'here' });
333
+ }
334
+ if (header.chrome !== null && !vocabulary.blok.chrome.includes(header.context))
335
+ this.add('chrome.context', tree.id, { context: contextName });
336
+ const allowed = vocabulary.blok.content[header.context];
337
+ if (allowed) {
338
+ const drawn = content(tree);
339
+ if (drawn.length !== 1 || !allowed.includes(drawn[0].component)) {
340
+ const found = drawn.map(node => (node.component === TEXT_NODE ? 'text' : `<${node.component}>`)).join(', ') || 'nothing';
341
+ this.add('blok.content', tree.id, { context: contextName, expected: allowed.map(name => `one <${name}>`).join(' or '), found });
342
+ }
293
343
  }
344
+ this.checkLocalPositions(tree);
345
+ this.checkQueries(tree);
294
346
  for (const [name, sites] of intoSites(tree)) {
295
347
  this.into.add(name);
296
348
  if (vocabulary.reserved.has(name))
297
349
  this.add('roots.reserved', sites[0].site, { name });
298
- if (this.locals.has(name))
299
- this.add('roots.shadow', sites[0].site, { name, first: 'a local', second: `the record of ${sites[0].site}` });
300
350
  if (sites.length > 1)
301
351
  this.add('into.twice', sites[1].site, { name, first: sites[0].site, second: sites[1].site });
302
352
  }
303
- for (const node of iterNodes(tree)) {
304
- const declared = foreachLet(node);
305
- if (declared === null)
353
+ }
354
+ /**
355
+ * Each `<local>` reads, comes first among its parent's children, inside an
356
+ * element that takes children, in a kind that has locals; a persisted one
357
+ * inside a keyless foreach is a warning.
358
+ */
359
+ checkLocalPositions(tree) {
360
+ for (const [node, ancestors] of iterWithParents(tree)) {
361
+ const parent = ancestors.length ? ancestors[ancestors.length - 1] : null;
362
+ if (node.component === VAR_COMPONENT && (parent === null || (parent.component !== QUERY_COMPONENT && parent.component !== SUBSCRIPTION_COMPONENT))) {
363
+ this.add('query.declaration', node.id, { component: 'var', problem: 'belongs inside a <query> or <subscription>' });
364
+ }
365
+ if (node.component !== LOCAL_COMPONENT)
366
+ continue;
367
+ const name = localName(node) ?? '?';
368
+ const problem = localProblem(node);
369
+ if (problem !== null) {
370
+ this.findings.push(problem);
371
+ continue;
372
+ }
373
+ if (!this.kind.locals)
374
+ this.notInKind(node.id, `<local name='${name}'>`, 'locals');
375
+ if (this.vocabulary.reserved.has(name))
376
+ this.add('roots.reserved', node.id, { name });
377
+ if (parent === null) {
378
+ this.add('local.position', node.id, { name, problem: "is a blok's root; a blok is a <Blok>" });
306
379
  continue;
307
- if (vocabulary.reserved.has(declared))
308
- this.add('roots.reserved', node.id, { name: declared });
309
- else if (this.locals.has(declared) || this.into.has(declared)) {
310
- this.add('roots.shadow', node.id, {
311
- name: declared,
312
- first: this.locals.has(declared) ? 'a local' : "a call's record",
313
- second: `the let of <foreach> (${node.id})`,
314
- });
380
+ }
381
+ const siblings = parent.children ?? [];
382
+ const other = siblings.slice(0, siblings.indexOf(node)).find(sibling => sibling.component !== LOCAL_COMPONENT);
383
+ if (other) {
384
+ const shown = other.component === TEXT_NODE ? 'text' : `<${other.component}>`;
385
+ this.add('local.position', node.id, { name, problem: `comes after ${shown} (${other.id}); locals come first among their parent's children` });
386
+ }
387
+ if ([QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, LOCAL_COMPONENT, VAR_COMPONENT].includes(parent.component)) {
388
+ this.add('local.position', node.id, { name, problem: `is inside <${parent.component}>, which declares, and draws nothing` });
389
+ }
390
+ else if (this.view) {
391
+ const spec = this.view.components.get(parent.component);
392
+ if (spec && !spec.acceptsChildren)
393
+ this.add('local.position', node.id, { name, problem: `is inside <${parent.component}>, which takes no children` });
394
+ }
395
+ const resolved = this.resolved.get(node.id);
396
+ if (!resolved)
397
+ continue;
398
+ if (resolved.likeProblem !== null) {
399
+ const like = node.props?.find(prop => prop.key === LIKE_PROP)?.static_value ?? null;
400
+ this.add('local.like', node.id, { name, like, problem: resolved.likeProblem });
401
+ }
402
+ this.checkLocalDefault(node.id, resolved.local);
403
+ if (resolved.local.persist) {
404
+ const loop = [...ancestors].reverse().find(ancestor => ancestor.component === FOREACH);
405
+ if (loop && !(loop.props ?? []).some(prop => prop.key === FOREACH_KEY))
406
+ this.add('local.persist_id', node.id, { name });
315
407
  }
316
408
  }
317
- for (const query of scope.queries) {
318
- for (const path of argumentPaths(query.variables ?? []))
319
- this.resolve(path, null, new Map(), `query ${query.key}`);
409
+ }
410
+ /** Queries and subscriptions are children of the `<Blok>`, each declared once and readable. */
411
+ checkQueries(tree) {
412
+ const first = new Map();
413
+ for (const [node, ancestors] of iterWithParents(tree)) {
414
+ if (node.component !== QUERY_COMPONENT && node.component !== SUBSCRIPTION_COMPONENT)
415
+ continue;
416
+ const named = node.props?.find(prop => prop.key === 'name')?.static_value;
417
+ const name = typeof named === 'string' ? named : '?';
418
+ if (ancestors.length !== 1) {
419
+ const at = ancestors.length ? ancestors[ancestors.length - 1].id : 'the root';
420
+ this.add('query.position', node.id, { component: node.component, name, at });
421
+ }
422
+ const problem = declarationProblem(node);
423
+ if (problem !== null) {
424
+ this.findings.push(problem);
425
+ continue;
426
+ }
427
+ const key = `${node.component}\u0000${name}`;
428
+ const seen = first.get(key);
429
+ if (seen !== undefined)
430
+ this.add('query.duplicate', node.id, { what: node.component, name, first: seen, second: node.id });
431
+ else
432
+ first.set(key, node.id);
433
+ }
434
+ this.queries = new Map(declaredQueries(tree).map(query => [query.key, query]));
435
+ this.subscriptions = new Map(declaredSubscriptions(tree).map(subscription => [subscription.key, subscription]));
436
+ const declared = [
437
+ ...[...this.queries.values()].map(query => ['query', query]),
438
+ ...[...this.subscriptions.values()].map(subscription => ['subscription', subscription]),
439
+ ];
440
+ for (const [what, each] of declared) {
441
+ const at = `${what === 'query' ? 'queries' : 'subscriptions'}.${each.key}`;
442
+ if (!LOCAL_NAME.test(each.key))
443
+ this.add('manifest.name', at, { what, key: each.key });
444
+ if (this.vocabulary.reserved.has(each.key))
445
+ this.add('roots.reserved', at, { name: each.key });
446
+ const operation = operationKeyword(each.document);
447
+ if (operation === 'mutation') {
448
+ this.add('query.read_only', at, { kind: what, name: each.key, problem: 'is a mutation: a blok reads, and writes only through a task' });
449
+ }
450
+ else if (operation !== what) {
451
+ this.add('query.kind', at, { kind: what, name: each.key, operation: operation || 'document without an operation' });
452
+ }
453
+ }
454
+ for (const query of this.queries.values()) {
455
+ if (query.more != null && !FIELD_PATH.test(query.more)) {
456
+ this.add('query.more', `queries.${query.key}`, { name: query.key, more: query.more, problem: 'is not a field path into its data (positions, images.items)' });
457
+ }
320
458
  }
321
- for (const subscription of scope.subscriptions) {
322
- for (const path of argumentPaths(subscription.variables ?? []))
323
- this.resolve(path, null, new Map(), `subscription ${subscription.key}`);
459
+ if (this.kindName === 'action' && this.context === LOGO && this.dependencies.size)
460
+ this.add('manifest.action_logo', this.header.node);
461
+ for (const subscription of this.subscriptions.values()) {
324
462
  if (subscription.history != null && !this.queries.has(subscription.history)) {
325
463
  this.add('query.history', `subscriptions.${subscription.key}`, { name: subscription.key, history: subscription.history });
326
464
  }
327
465
  }
328
466
  }
329
467
  /** A local's default fits its port: a number for a number, a list for a list, one of its choices. */
330
- checkLocalDefault(local) {
468
+ checkLocalDefault(nodeId, local) {
331
469
  if (local.kind === LOCAL_ANY)
332
470
  return;
333
471
  if (!valueFitsPort(local.default, local)) {
334
- this.add('local.default', `locals.${local.key}`, { name: local.key, default: local.default, kind: local.kind });
472
+ this.add('local.default', nodeId, { name: local.key, default: local.default, kind: local.kind });
335
473
  }
336
474
  }
337
475
  /** The port a path into a local names (the local, or a field of it), or null when its shape does not say (an ANY local). */
338
- localPort(path) {
339
- const [root, ...rest] = path.split('.');
340
- const local = this.locals.get(root) ?? null;
341
- let port = local !== null && local.kind !== LOCAL_ANY ? local : null;
476
+ localPort(binding, path) {
477
+ const rest = path.split('.').slice(1);
478
+ let port = binding.port.kind !== LOCAL_ANY ? binding.port : null;
342
479
  for (const part of rest) {
343
480
  if (port === null)
344
481
  return null;
@@ -351,10 +488,12 @@ class Checker {
351
488
  return port;
352
489
  }
353
490
  finish() {
354
- for (const local of this.scope.locals) {
355
- if (local.persist && !this.boundLocals.has(local.key))
356
- this.add('local.unused_persist', `locals.${local.key}`, { name: local.key });
491
+ for (const [nodeId, resolved] of this.resolved) {
492
+ if (resolved.local.persist && !this.boundLocals.has(nodeId))
493
+ this.add('local.unused_persist', nodeId, { name: resolved.local.key });
357
494
  }
495
+ if (this.chromeless !== null && this.kind.roots.includes('task') && !this.asks)
496
+ this.add('chrome.no_ask', this.chromeless);
358
497
  }
359
498
  /* -- the walk -- */
360
499
  walk(tree) {
@@ -364,7 +503,7 @@ class Checker {
364
503
  this.walkNode(tree, scope, [], false);
365
504
  }
366
505
  walkNode(node, scope, ancestors, inError) {
367
- this.visitComponent(node, ancestors);
506
+ this.visitComponent(node, ancestors, scope);
368
507
  const inner = new Map(scope);
369
508
  const declared = foreachLet(node);
370
509
  if (declared !== null) {
@@ -377,7 +516,14 @@ class Checker {
377
516
  this.walkProp(node, prop, propScope, inError);
378
517
  }
379
518
  const inSlot = inError || (node.component === ERROR_SLOT && ancestors.length > 0 && ancestors[ancestors.length - 1].component === SUSPENSE);
380
- for (const child of node.children ?? [])
519
+ // Every local of a node is bound before any of its children is walked, in order: a second local of one name sees the first.
520
+ const children = node.children ?? [];
521
+ for (const child of children) {
522
+ const name = localDeclared(child);
523
+ if (name !== null)
524
+ inner.set(name, this.bindLocal(name, child, new Map(inner)));
525
+ }
526
+ for (const child of children)
381
527
  this.walkNode(child, inner, [...ancestors, node], inSlot);
382
528
  }
383
529
  walkProp(node, prop, scope, inError) {
@@ -407,33 +553,44 @@ class Checker {
407
553
  [...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(nested => this.walkArgument(nested, scope, where));
408
554
  }
409
555
  /* -- components and props -- */
410
- visitComponent(node, ancestors) {
556
+ visitComponent(node, ancestors, scope) {
411
557
  const spec = this.view?.components.get(node.component);
412
- if (this.view && !spec && this.view.complete) {
413
- this.add('catalog.unknown_component', node.id, { component: node.component, catalogs: this.view.label });
558
+ if (this.view && !spec) {
559
+ const foreign = this.view.foreign.get(node.component);
560
+ if (foreign !== undefined) {
561
+ this.add('catalog.target', node.id, { component: node.component, catalog: foreign, target: this.view.target ?? this.view.label });
562
+ }
563
+ else if (this.view.complete) {
564
+ this.add('catalog.unknown_component', node.id, { component: node.component, catalogs: this.view.label });
565
+ }
414
566
  }
415
567
  if (spec)
416
568
  this.checkCatalog(node, spec, ancestors);
417
- const shadow = this.view?.shadows.get(node.component);
418
- if (shadow && !this.shadowed.has(node.component)) {
419
- this.shadowed.add(node.component);
420
- this.add('catalog.shadow', node.id, { component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner });
421
- }
422
- if (TASK_COMPONENTS.has(node.component) && !this.kind.roots.includes('task')) {
423
- this.notInKind(node.id, `<${node.component}>`, 'task');
424
- }
425
- if (ASSIGN_COMPONENTS.has(node.component) && this.scope.kind !== ASSIGN_KIND) {
426
- this.add('assign.kind', node.id, { what: `<${node.component}>`, n: article(this.scope.kind), kind: this.scope.kind });
427
- }
569
+ this.checkHostPart(node, ancestors);
428
570
  for (const prop of node.props ?? [])
429
- this.checkProp(node, prop, spec);
571
+ this.checkProp(node, prop, spec, scope);
430
572
  }
431
573
  checkCatalog(node, spec, ancestors) {
432
574
  const view = this.view;
433
575
  if (!view)
434
576
  return;
435
- if (node.children?.length && !spec.acceptsChildren)
577
+ const texts = (node.children ?? []).filter(child => child.component === TEXT_NODE);
578
+ const elements = (node.children ?? []).filter(child => child.component !== TEXT_NODE && !isDeclaration(child)).length;
579
+ if (elements && !spec.acceptsChildren)
436
580
  this.add('catalog.children', node.id, { component: node.component });
581
+ if (texts.length) {
582
+ // Text is a child like any other; what takes it is the catalog's to say.
583
+ const textProp = spec.textProp;
584
+ if (textProp === null && !spec.acceptsChildren) {
585
+ this.add('catalog.text', node.id, { component: node.component, detail: 'takes no text' });
586
+ }
587
+ else if (textProp !== null && (node.props ?? []).some(prop => prop.key === textProp)) {
588
+ this.add('catalog.text', node.id, { component: node.component, detail: `sets ${textProp} as an attribute and as its text` });
589
+ }
590
+ else if (textProp !== null && !spec.acceptsChildren && (elements || texts.length > 1)) {
591
+ this.add('catalog.text', node.id, { component: node.component, detail: `takes one run of text as its ${textProp}, and no elements beside it` });
592
+ }
593
+ }
437
594
  const present = new Set((node.props ?? []).map(prop => prop.key));
438
595
  const known = new Set([...spec.props.map(prop => prop.key), WHEN_PROP]);
439
596
  const unknown = [...present].filter(key => !known.has(key)).sort();
@@ -442,7 +599,7 @@ class Checker {
442
599
  const missing = spec.props.filter(prop => prop.required && !present.has(prop.key)).map(prop => prop.key).sort();
443
600
  if (missing.length)
444
601
  this.add('catalog.props', node.id, { component: node.component, detail: `requires props [${missing.map(pythonRepr).join(', ')}]` });
445
- let context = 'HTML';
602
+ let context = PANEL;
446
603
  for (const ancestor of ancestors) {
447
604
  const above = view.components.get(ancestor.component);
448
605
  if (above && !above.inheritsContext)
@@ -462,29 +619,39 @@ class Checker {
462
619
  if (forbidden.length) {
463
620
  this.add('catalog.placement', node.id, { component: node.component, detail: `must not be inside [${forbidden.map(pythonRepr).join(', ')}]` });
464
621
  }
465
- // Only the versioned standard catalogs are declared; a module (the Orkestrator's, an app's) is what the blok's `module` names.
466
- const catalog = spec.catalog;
467
- const standard = catalog.includes('@') && catalog.split('@')[0] in this.vocabulary.catalogs;
468
- if (this.scope.catalogs.length && standard && !this.scope.catalogs.includes(catalog)) {
469
- this.add('catalog.undeclared', node.id, { component: node.component, catalog });
622
+ if (spec.kinds.length && !spec.kinds.includes(this.kindName)) {
623
+ this.add('catalog.kind', node.id, { component: node.component, kinds: spec.kinds.join(' and '), n: article(this.kindName), kind: this.kindName });
624
+ }
625
+ }
626
+ /**
627
+ * What the language itself says of the host's parts, whatever catalog draws
628
+ * them: a part placed anywhere claims its slot (a blok without chrome
629
+ * leaves the asks to itself: `finish`).
630
+ */
631
+ checkHostPart(node, ancestors) {
632
+ if (node.component === ASK_COMPONENT)
633
+ this.asks = true;
634
+ if (this.vocabulary.hostParts.includes(node.component)) {
635
+ const inside = [...ancestors].reverse().find(ancestor => CONDITIONAL_COMPONENTS.has(ancestor.component));
636
+ if (inside)
637
+ this.add('part.conditional', node.id, { component: node.component, inside: inside.component });
470
638
  }
471
639
  }
472
640
  /** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
473
641
  checkDependencyKeys(node, prop) {
474
- if (!RUN_KINDS.includes(this.scope.kind)) {
475
- this.add('space.kind', node.id, { component: node.component, n: article(this.scope.kind), kind: this.scope.kind }, prop.key);
642
+ // catalog.kind says it: a Space and its parts belong to an action's own blok. Unmounted, its keys are taken as written.
643
+ if (!RUN_KINDS.includes(this.kindName) || !this.mounted)
476
644
  return;
477
- }
478
645
  const path = `${node.component}.${prop.key}`;
479
646
  const value = prop.static_value;
480
647
  const keys = typeof value === 'string' ? [value] : Array.isArray(value) ? value.filter((key) => typeof key === 'string') : [];
481
648
  for (const key of keys) {
482
649
  if (!this.dependencies.has(key)) {
483
- this.add('deps.unknown', node.id, { path, key, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(key, this.scope.kind) }, prop.key);
650
+ this.add('deps.unknown', node.id, { path, key, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(key, this.kindName) }, prop.key);
484
651
  }
485
652
  }
486
653
  }
487
- checkProp(node, prop, spec) {
654
+ checkProp(node, prop, spec, scope) {
488
655
  const { vocabulary } = this;
489
656
  const propSpec = spec?.props.find(candidate => candidate.key === prop.key);
490
657
  const holds = isCallbackValue(prop);
@@ -509,7 +676,7 @@ class Checker {
509
676
  }
510
677
  // `task.answer(...)`, `task.cancel()` and their kin act on the task the blok is about.
511
678
  const effect = prop.util_call?.operation;
512
- if (effect?.startsWith('task.') && vocabulary.functions.get(effect)?.effect && !this.kind.roots.includes('task')) {
679
+ if (effect !== undefined && vocabulary.functions.get(effect)?.taskOperation && !this.kind.roots.includes('task')) {
513
680
  this.notInKind(node.id, effect, 'task', prop.key);
514
681
  }
515
682
  if (prop.key === BIND_PROP) {
@@ -519,24 +686,21 @@ class Checker {
519
686
  }
520
687
  else {
521
688
  const root = path.split('.')[0];
522
- if (!this.locals.has(root))
689
+ const binding = scope.get(root);
690
+ if (!isLocalBinding(binding))
523
691
  this.add('local.unknown', node.id, { path, root }, prop.key);
524
692
  else {
525
- this.boundLocals.add(root);
693
+ this.boundLocals.add(binding.node);
526
694
  if (propSpec)
527
- this.checkBindKind(node, propSpec.kind, path);
695
+ this.checkBindKind(node, propSpec.kind, binding, path);
528
696
  }
529
697
  }
530
698
  }
531
- if (prop.util_call?.operation === START_EFFECT && this.scope.kind !== ASSIGN_KIND) {
532
- this.add('assign.kind', node.id, { what: 'assign.start()', n: article(this.scope.kind), kind: this.scope.kind }, prop.key);
699
+ if (prop.util_call?.operation === START_EFFECT && this.kindName !== ASSIGN_KIND) {
700
+ this.add('assign.kind', node.id, { what: 'assign.start()', n: article(this.kindName), kind: this.kindName }, prop.key);
533
701
  }
534
702
  if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`))
535
703
  this.checkDependencyKeys(node, prop);
536
- if (node.component === 'Space' && prop.key === 'room' && !RUN_KINDS.includes(this.scope.kind)) {
537
- // A Space places the run's dependencies: only an action's own blok (for a run, or for starting one) has them.
538
- this.add('space.kind', node.id, { component: node.component, n: article(this.scope.kind), kind: this.scope.kind }, prop.key);
539
- }
540
704
  if (node.component === TOAST_COMPONENT && prop.key === TOAST_TASK_PROP) {
541
705
  const path = prop.dynamic_value?.path ?? null;
542
706
  if (path === null || (path !== 'task' && !this.into.has(path)))
@@ -545,7 +709,7 @@ class Checker {
545
709
  if (typeof prop.static_value === 'string') {
546
710
  if (prop.key === CLASS_NAME)
547
711
  this.checkClasses(prop.static_value, node.id, prop.key);
548
- if (drawnIn(this.scope) === LOGO && vocabulary.theme.logoPaintProps.includes(prop.key))
712
+ if (this.context === LOGO && vocabulary.theme.logoPaintProps.includes(prop.key))
549
713
  this.checkPaint(node, prop.key, prop.static_value);
550
714
  if (spec?.context === SCENE && vocabulary.theme.scenePaintProps.includes(prop.key))
551
715
  this.checkSceneColour(node, prop.key, prop.static_value);
@@ -556,9 +720,9 @@ class Checker {
556
720
  }
557
721
  }
558
722
  /** The local a control writes is of a kind the control writes (`Slider`: FLOAT or INT). */
559
- checkBindKind(node, propKind, path) {
723
+ checkBindKind(node, propKind, binding, path) {
560
724
  const allowed = this.vocabulary.locals.bindKinds[propKind];
561
- const port = this.localPort(path);
725
+ const port = this.localPort(binding, path);
562
726
  if (!allowed || port === null)
563
727
  return;
564
728
  if (!allowed.includes(port.kind)) {
@@ -578,7 +742,12 @@ class Checker {
578
742
  const arbitrary = ARBITRARY_COLOUR.exec(base);
579
743
  if (arbitrary?.groups) {
580
744
  this.add('palette.raw_colour', owner, { token, suggestion: `${arbitrary.groups.utility}-<role> (${this.vocabulary.theme.colourRoles.slice(0, 6).join(', ')}, ...)` }, propKey);
745
+ continue;
581
746
  }
747
+ // A colour that is no role is told as that; anything else outside the portable subset as this.
748
+ const unportable = unportableClass(token, this.vocabulary);
749
+ if (unportable !== null)
750
+ this.add('class.not_portable', owner, { token, what: unportable }, propKey);
582
751
  }
583
752
  }
584
753
  checkPaint(node, key, value) {
@@ -610,8 +779,8 @@ class Checker {
610
779
  }
611
780
  const dependency = this.dependencies.get(call.dependency);
612
781
  if (!dependency) {
613
- if (call.dependency !== 'self') {
614
- this.add('deps.unknown', where.node.id, { path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.scope.kind) }, where.key);
782
+ if (call.dependency !== 'self' && this.mounted) {
783
+ this.add('deps.unknown', where.node.id, { path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.kindName) }, where.key);
615
784
  }
616
785
  return;
617
786
  }
@@ -633,10 +802,10 @@ class Checker {
633
802
  const match = ports.get(argument.key ?? '');
634
803
  if (path == null || !match || match.kind == null)
635
804
  continue;
636
- const root = path.split('.')[0];
637
- if (scope.has(root) || !this.locals.has(root))
805
+ const binding = scope.get(path.split('.')[0]);
806
+ if (!isLocalBinding(binding))
638
807
  continue;
639
- const port = this.localPort(path);
808
+ const port = this.localPort(binding, path);
640
809
  if (port === null)
641
810
  continue;
642
811
  const target = { kind: match.kind, identifier: match.identifier ?? null };
@@ -702,6 +871,11 @@ class Checker {
702
871
  this.add('query.fetch_more', where.node.id, { path, name }, where.key);
703
872
  }
704
873
  bindLet(name, items, where, scope) {
874
+ if (this.vocabulary.reserved.has(name))
875
+ this.add('roots.reserved', where.node.id, { name });
876
+ else if (scope.has(name)) {
877
+ this.add('roots.shadow', where.node.id, { name, first: bindingWhat(name, scope.get(name), this.into), second: `the let of <foreach> (${where.node.id})` });
878
+ }
705
879
  const keyed = (where.node.props ?? []).some(prop => prop.key === FOREACH_KEY);
706
880
  const literal = items?.static_value;
707
881
  if (!keyed && Array.isArray(literal) && literal.some(item => typeof item === 'object' && item !== null)) {
@@ -726,6 +900,15 @@ class Checker {
726
900
  this.add('path.unknown', where.node.id, { path, detail: `${FOREACH_ITEMS} of a foreach reads a list, not this ${resolved.kind.toLowerCase()}` }, FOREACH_ITEMS);
727
901
  return openMatch(name);
728
902
  }
903
+ bindLocal(name, node, scope) {
904
+ if (scope.has(name) && !this.vocabulary.reserved.has(name)) {
905
+ this.add('roots.shadow', node.id, { name, first: bindingWhat(name, scope.get(name), this.into), second: `the local ${node.id}` });
906
+ }
907
+ const resolved = this.resolved.get(node.id);
908
+ if (!resolved)
909
+ return openMatch(name);
910
+ return { local: true, node: node.id, name, port: resolved.local };
911
+ }
729
912
  bindInto(call) {
730
913
  const dependency = this.dependencies.get(call.dependency);
731
914
  const action = actionKeyFor(call);
@@ -751,15 +934,16 @@ class Checker {
751
934
  const [root, ...rest] = parts;
752
935
  const report = (code, fields) => this.add(code, nodeId, fields, propKey);
753
936
  if (scope.has(root)) {
937
+ const binding = scope.get(root) ?? null;
938
+ if (isLocalBinding(binding)) {
939
+ const local = binding.port;
940
+ if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind))
941
+ return openMatch(root);
942
+ return this.descend({ ...portMatch(local), key: root }, rest, path, nodeId, propKey);
943
+ }
754
944
  if (this.into.has(root))
755
945
  this.checkReturns(path, rest, nodeId, propKey);
756
- return this.descend(scope.get(root) ?? null, rest, path, nodeId, propKey);
757
- }
758
- const local = this.locals.get(root);
759
- if (local) {
760
- if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind))
761
- return openMatch(root);
762
- return this.descend({ ...portMatch(local), key: root }, rest, path, nodeId, propKey);
946
+ return this.descend(binding, rest, path, nodeId, propKey);
763
947
  }
764
948
  if (root === 'event') {
765
949
  if (!where || !where.callback) {
@@ -798,7 +982,9 @@ class Checker {
798
982
  }
799
983
  const dependency = this.dependencies.get(rest[0]);
800
984
  if (!dependency) {
801
- report('deps.unknown', { path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.scope.kind) });
985
+ if (!this.mounted)
986
+ return openMatch(path);
987
+ report('deps.unknown', { path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.kindName) });
802
988
  return null;
803
989
  }
804
990
  return this.agent(dependency, rest[0], rest.slice(1), path, nodeId, propKey);
@@ -1017,15 +1203,29 @@ export const checkLogo = (tree, demo) => {
1017
1203
  return findings;
1018
1204
  };
1019
1205
  /**
1020
- * Every finding of `tree` against `scope` and `view`: errors and warnings, in
1021
- * tree order. `view` defaults to the Orkestrator's (base, the standard catalogs
1022
- * and its module); `null` skips every catalog rule.
1206
+ * The view a blok is checked with when none is given: that of the catalog its
1207
+ * `<Blok catalog>` names when it is known here, the app's own when it names
1208
+ * none, and an incomplete base view (nothing reported unknown) otherwise.
1209
+ */
1210
+ export const viewForTree = (tree) => {
1211
+ const catalog = blokCatalog(tree);
1212
+ return catalog === null ? defaultBlokView() : blokViewFor(catalog);
1213
+ };
1214
+ /**
1215
+ * Every finding of `tree` mounted as `scope` says (unmounted by default),
1216
+ * against `view`: errors and warnings, in tree order. A root that is no
1217
+ * readable `<Blok>` is the one finding. `view` defaults to that of the catalog
1218
+ * the blok names (`viewForTree`); `null` skips every catalog rule.
1023
1219
  */
1024
- export const checkBlokTree = (tree, scope, view = defaultBlokView()) => {
1025
- const checker = new Checker(resolveBlokScope(tree, scope, view), view);
1220
+ export const checkBlokTree = (tree, scope = unmountedBlokScope(), view = viewForTree(tree)) => {
1221
+ const problem = headerProblem(tree);
1222
+ if (problem !== null)
1223
+ return [problem];
1224
+ const header = blokHeader(tree);
1225
+ const checker = new Checker(header, scope, view, resolveLocals(tree, scope.dependencies, view));
1026
1226
  checker.checkDeclarations(tree);
1027
1227
  checker.walk(tree);
1028
- if (drawnIn(scope) === LOGO)
1228
+ if (header.context === LOGO)
1029
1229
  checker.findings.push(...checkLogo(tree, scope.demo));
1030
1230
  checker.finish();
1031
1231
  return checker.findings;