@arkitektio/bsx 4.3.0 → 5.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 (253) hide show
  1. package/README.md +39 -18
  2. package/dist/bsx/parse.d.ts +13 -7
  3. package/dist/bsx/parse.d.ts.map +1 -1
  4. package/dist/bsx/parse.js +18 -57
  5. package/dist/bsx/parse.js.map +1 -1
  6. package/dist/bsx/print.d.ts.map +1 -1
  7. package/dist/bsx/print.js +22 -35
  8. package/dist/bsx/print.js.map +1 -1
  9. package/dist/bsx/references.d.ts +5 -5
  10. package/dist/bsx/references.d.ts.map +1 -1
  11. package/dist/bsx/references.js +106 -33
  12. package/dist/bsx/references.js.map +1 -1
  13. package/dist/catalogs/html.d.ts +1 -1
  14. package/dist/catalogs/html.d.ts.map +1 -1
  15. package/dist/catalogs/html.js +3 -3
  16. package/dist/catalogs/html.js.map +1 -1
  17. package/dist/catalogs/index.d.ts +126 -112
  18. package/dist/catalogs/index.d.ts.map +1 -1
  19. package/dist/catalogs/index.js +6 -2
  20. package/dist/catalogs/index.js.map +1 -1
  21. package/dist/catalogs/logo.d.ts +5 -5
  22. package/dist/catalogs/logo.d.ts.map +1 -1
  23. package/dist/catalogs/logo.js +3 -3
  24. package/dist/catalogs/logo.js.map +1 -1
  25. package/dist/catalogs/parts/data.d.ts +5 -5
  26. package/dist/catalogs/parts/feedback.d.ts +12 -12
  27. package/dist/catalogs/parts/forms.d.ts +20 -20
  28. package/dist/catalogs/parts/html.d.ts +1 -1
  29. package/dist/catalogs/parts/html.d.ts.map +1 -1
  30. package/dist/catalogs/parts/html.js +1 -1
  31. package/dist/catalogs/parts/html.js.map +1 -1
  32. package/dist/catalogs/parts/icons.d.ts +9 -9
  33. package/dist/catalogs/parts/icons.js +1 -1
  34. package/dist/catalogs/parts/index.d.ts +120 -110
  35. package/dist/catalogs/parts/index.d.ts.map +1 -1
  36. package/dist/catalogs/parts/layout.d.ts +11 -1
  37. package/dist/catalogs/parts/layout.d.ts.map +1 -1
  38. package/dist/catalogs/parts/layout.js +9 -0
  39. package/dist/catalogs/parts/layout.js.map +1 -1
  40. package/dist/catalogs/parts/logo.d.ts +8 -8
  41. package/dist/catalogs/parts/logo.d.ts.map +1 -1
  42. package/dist/catalogs/parts/logo.js +2 -2
  43. package/dist/catalogs/parts/logo.js.map +1 -1
  44. package/dist/catalogs/parts/navigation.d.ts +16 -16
  45. package/dist/catalogs/parts/overlays.d.ts +44 -44
  46. package/dist/catalogs/parts/run.d.ts +5 -5
  47. package/dist/catalogs/parts/run.js +1 -1
  48. package/dist/catalogs/parts/scene.d.ts +4 -4
  49. package/dist/catalogs/parts/structure.js +2 -2
  50. package/dist/catalogs/parts/toast.js +1 -1
  51. package/dist/catalogs/parts/toast.js.map +1 -1
  52. package/dist/catalogs/parts/typography.js +1 -1
  53. package/dist/catalogs/parts/typography.js.map +1 -1
  54. package/dist/catalogs/props.d.ts +2 -2
  55. package/dist/catalogs/scene.d.ts +5 -5
  56. package/dist/catalogs/scene.d.ts.map +1 -1
  57. package/dist/catalogs/scene.js +3 -3
  58. package/dist/catalogs/scene.js.map +1 -1
  59. package/dist/catalogs/shadcn.d.ts +47 -47
  60. package/dist/catalogs/shadcn.d.ts.map +1 -1
  61. package/dist/catalogs/shadcn.js +4 -4
  62. package/dist/catalogs/shadcn.js.map +1 -1
  63. package/dist/catalogs/structure.d.ts +1 -1
  64. package/dist/catalogs/structure.d.ts.map +1 -1
  65. package/dist/catalogs/structure.js +3 -3
  66. package/dist/catalogs/structure.js.map +1 -1
  67. package/dist/catalogs/ui.d.ts +67 -57
  68. package/dist/catalogs/ui.d.ts.map +1 -1
  69. package/dist/catalogs/ui.js +4 -3
  70. package/dist/catalogs/ui.js.map +1 -1
  71. package/dist/catalogs.d.ts +1 -1
  72. package/dist/catalogs.d.ts.map +1 -1
  73. package/dist/catalogs.js +2 -2
  74. package/dist/catalogs.js.map +1 -1
  75. package/dist/ports.js +1 -1
  76. package/dist/ports.js.map +1 -1
  77. package/dist/renderer/baseCatalog.d.ts +8 -6
  78. package/dist/renderer/baseCatalog.d.ts.map +1 -1
  79. package/dist/renderer/baseCatalog.js +7 -5
  80. package/dist/renderer/baseCatalog.js.map +1 -1
  81. package/dist/renderer/bloks/control.d.ts +2 -0
  82. package/dist/renderer/bloks/control.d.ts.map +1 -1
  83. package/dist/renderer/bloks/control.js +13 -1
  84. package/dist/renderer/bloks/control.js.map +1 -1
  85. package/dist/renderer/bloks/data.d.ts +5 -5
  86. package/dist/renderer/bloks/feedback.d.ts +12 -12
  87. package/dist/renderer/bloks/forms.d.ts +20 -20
  88. package/dist/renderer/bloks/html.js +2 -2
  89. package/dist/renderer/bloks/icons.d.ts +4 -4
  90. package/dist/renderer/bloks/index.d.ts +115 -107
  91. package/dist/renderer/bloks/index.d.ts.map +1 -1
  92. package/dist/renderer/bloks/index.js +1 -1
  93. package/dist/renderer/bloks/layout.d.ts +9 -1
  94. package/dist/renderer/bloks/layout.d.ts.map +1 -1
  95. package/dist/renderer/bloks/layout.js +15 -0
  96. package/dist/renderer/bloks/layout.js.map +1 -1
  97. package/dist/renderer/bloks/logo/index.d.ts +5 -5
  98. package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
  99. package/dist/renderer/bloks/logo/index.js +2 -2
  100. package/dist/renderer/bloks/logo/index.js.map +1 -1
  101. package/dist/renderer/bloks/navigation.d.ts +16 -16
  102. package/dist/renderer/bloks/overlays.d.ts +44 -44
  103. package/dist/renderer/bloks/run/components.d.ts +2 -2
  104. package/dist/renderer/bloks/run/components.js +1 -1
  105. package/dist/renderer/bloks/scene/index.d.ts +2 -2
  106. package/dist/renderer/bloks/toast.d.ts +1 -1
  107. package/dist/renderer/bloks/typography.js +1 -1
  108. package/dist/renderer/catalog.d.ts +4 -7
  109. package/dist/renderer/catalog.d.ts.map +1 -1
  110. package/dist/renderer/catalog.js +7 -31
  111. package/dist/renderer/catalog.js.map +1 -1
  112. package/dist/renderer/declare.d.ts +31 -19
  113. package/dist/renderer/declare.d.ts.map +1 -1
  114. package/dist/renderer/declare.js +44 -18
  115. package/dist/renderer/declare.js.map +1 -1
  116. package/dist/renderer/runtime/catalog.d.ts +27 -7
  117. package/dist/renderer/runtime/catalog.d.ts.map +1 -1
  118. package/dist/renderer/runtime/catalog.js +30 -3
  119. package/dist/renderer/runtime/catalog.js.map +1 -1
  120. package/dist/renderer/runtime/components.d.ts +7 -1
  121. package/dist/renderer/runtime/components.d.ts.map +1 -1
  122. package/dist/renderer/runtime/components.js +3 -0
  123. package/dist/renderer/runtime/components.js.map +1 -1
  124. package/dist/renderer/runtime/describe.d.ts +14 -4
  125. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  126. package/dist/renderer/runtime/describe.js +3 -0
  127. package/dist/renderer/runtime/describe.js.map +1 -1
  128. package/dist/renderer/runtime/index.d.ts +1 -0
  129. package/dist/renderer/runtime/index.d.ts.map +1 -1
  130. package/dist/renderer/runtime/index.js +1 -0
  131. package/dist/renderer/runtime/index.js.map +1 -1
  132. package/dist/renderer/runtime/preflight.d.ts.map +1 -1
  133. package/dist/renderer/runtime/preflight.js +5 -2
  134. package/dist/renderer/runtime/preflight.js.map +1 -1
  135. package/dist/renderer/runtime/text.d.ts +28 -0
  136. package/dist/renderer/runtime/text.d.ts.map +1 -0
  137. package/dist/renderer/runtime/text.js +82 -0
  138. package/dist/renderer/runtime/text.js.map +1 -0
  139. package/dist/runtime.d.ts +0 -1
  140. package/dist/runtime.d.ts.map +1 -1
  141. package/dist/runtime.js +0 -1
  142. package/dist/runtime.js.map +1 -1
  143. package/dist/scene.d.ts +1 -1
  144. package/dist/scene.d.ts.map +1 -1
  145. package/dist/scene.js +2 -2
  146. package/dist/scene.js.map +1 -1
  147. package/dist/shadcn.d.ts +118 -110
  148. package/dist/shadcn.d.ts.map +1 -1
  149. package/dist/shadcn.js +6 -5
  150. package/dist/shadcn.js.map +1 -1
  151. package/dist/spec/bsx_v2.json +3080 -2436
  152. package/dist/spec/catalogs/base@3.json +13029 -0
  153. package/dist/spec/catalogs/base@3.json.js +13029 -0
  154. package/dist/spec/catalogs/orkestrator@1.json +489 -0
  155. package/dist/spec/catalogs/orkestrator@1.json.js +489 -0
  156. package/dist/spec/catalogs.d.ts +109 -46
  157. package/dist/spec/catalogs.d.ts.map +1 -1
  158. package/dist/spec/catalogs.js +241 -73
  159. package/dist/spec/catalogs.js.map +1 -1
  160. package/dist/spec/vocabulary.d.ts +19 -3
  161. package/dist/spec/vocabulary.d.ts.map +1 -1
  162. package/dist/spec/vocabulary.js +15 -2
  163. package/dist/spec/vocabulary.js.map +1 -1
  164. package/dist/spec/vocabulary.json +30 -16
  165. package/dist/spec/vocabulary.json.js +30 -16
  166. package/dist/vendor/core/ui/button-group.d.ts +1 -1
  167. package/dist/vendor/core/ui/button.d.ts +1 -1
  168. package/dist/vendor/core/ui/field.d.ts +1 -1
  169. package/package.json +1 -1
  170. package/src/bsx/infer.test.ts +18 -26
  171. package/src/bsx/language.test.ts +1 -1
  172. package/src/bsx/parse.ts +18 -62
  173. package/src/bsx/partial.test.ts +1 -1
  174. package/src/bsx/print.ts +24 -34
  175. package/src/bsx/references.test.ts +16 -14
  176. package/src/bsx/references.ts +96 -38
  177. package/src/catalogs/catalogs.test.ts +45 -14
  178. package/src/catalogs/html.ts +3 -3
  179. package/src/catalogs/index.ts +6 -2
  180. package/src/catalogs/logo.ts +3 -3
  181. package/src/catalogs/parts/html.ts +1 -1
  182. package/src/catalogs/parts/icons.ts +1 -1
  183. package/src/catalogs/parts/layout.ts +11 -0
  184. package/src/catalogs/parts/logo.ts +2 -2
  185. package/src/catalogs/parts/run.ts +1 -1
  186. package/src/catalogs/parts/structure.ts +2 -2
  187. package/src/catalogs/parts/toast.ts +1 -1
  188. package/src/catalogs/parts/typography.ts +1 -1
  189. package/src/catalogs/scene.ts +3 -3
  190. package/src/catalogs/shadcn.ts +4 -4
  191. package/src/catalogs/structure.ts +3 -3
  192. package/src/catalogs/ui.ts +4 -3
  193. package/src/catalogs.ts +9 -2
  194. package/src/ports.ts +1 -1
  195. package/src/renderer/addBlokComponents.test.tsx +8 -22
  196. package/src/renderer/baseCatalog.ts +7 -5
  197. package/src/renderer/bloks/components.test.tsx +2 -2
  198. package/src/renderer/bloks/control.tsx +17 -1
  199. package/src/renderer/bloks/flow.test.tsx +1 -1
  200. package/src/renderer/bloks/html.tsx +2 -2
  201. package/src/renderer/bloks/index.ts +1 -1
  202. package/src/renderer/bloks/layout.tsx +28 -0
  203. package/src/renderer/bloks/logo/index.tsx +2 -2
  204. package/src/renderer/bloks/run/components.tsx +1 -1
  205. package/src/renderer/bloks/time.test.tsx +1 -1
  206. package/src/renderer/bloks/toast.tsx +1 -1
  207. package/src/renderer/bloks/typography.tsx +1 -1
  208. package/src/renderer/catalog.tsx +7 -31
  209. package/src/renderer/declare.test.ts +41 -0
  210. package/src/renderer/declare.ts +70 -32
  211. package/src/renderer/runtime/catalog.ts +35 -10
  212. package/src/renderer/runtime/components.tsx +10 -1
  213. package/src/renderer/runtime/describe.ts +17 -4
  214. package/src/renderer/runtime/index.ts +1 -0
  215. package/src/renderer/runtime/preflight.ts +5 -2
  216. package/src/renderer/runtime/text.test.tsx +65 -0
  217. package/src/renderer/runtime/text.ts +88 -0
  218. package/src/runtime.ts +0 -1
  219. package/src/scene.ts +2 -2
  220. package/src/shadcn.ts +6 -5
  221. package/src/spec/bsx_v2.json +3080 -2436
  222. package/src/spec/catalogs/base@3.json +13029 -0
  223. package/src/spec/catalogs/orkestrator@1.json +489 -0
  224. package/src/spec/catalogs.ts +257 -101
  225. package/src/spec/spec.test.ts +87 -21
  226. package/src/spec/vocabulary.json +30 -16
  227. package/src/spec/vocabulary.ts +33 -7
  228. package/dist/renderer/modules.d.ts +0 -4
  229. package/dist/renderer/modules.d.ts.map +0 -1
  230. package/dist/renderer/modules.js +0 -11
  231. package/dist/renderer/modules.js.map +0 -1
  232. package/dist/spec/catalogs/base@2.json +0 -355
  233. package/dist/spec/catalogs/base@2.json.js +0 -355
  234. package/dist/spec/catalogs/html@1.json +0 -308
  235. package/dist/spec/catalogs/html@1.json.js +0 -308
  236. package/dist/spec/catalogs/logo@1.json +0 -1687
  237. package/dist/spec/catalogs/logo@1.json.js +0 -1687
  238. package/dist/spec/catalogs/scene@1.json +0 -878
  239. package/dist/spec/catalogs/scene@1.json.js +0 -878
  240. package/dist/spec/catalogs/shadcn@1.json +0 -4002
  241. package/dist/spec/catalogs/shadcn@1.json.js +0 -4002
  242. package/dist/spec/catalogs/structure@1.json +0 -185
  243. package/dist/spec/catalogs/structure@1.json.js +0 -185
  244. package/dist/spec/catalogs/ui@1.json +0 -5349
  245. package/dist/spec/catalogs/ui@1.json.js +0 -5349
  246. package/src/renderer/modules.ts +0 -12
  247. package/src/spec/catalogs/base@2.json +0 -355
  248. package/src/spec/catalogs/html@1.json +0 -308
  249. package/src/spec/catalogs/logo@1.json +0 -1687
  250. package/src/spec/catalogs/scene@1.json +0 -878
  251. package/src/spec/catalogs/shadcn@1.json +0 -4002
  252. package/src/spec/catalogs/structure@1.json +0 -185
  253. package/src/spec/catalogs/ui@1.json +0 -5349
@@ -1,25 +1,33 @@
1
- import baseCatalogJson from './catalogs/base@2.json';
2
- import htmlCatalogJson from './catalogs/html@1.json';
3
- import logoCatalogJson from './catalogs/logo@1.json';
4
- import sceneCatalogJson from './catalogs/scene@1.json';
5
- import structureCatalogJson from './catalogs/structure@1.json';
6
- import shadcnCatalogJson from './catalogs/shadcn@1.json';
7
- import uiCatalogJson from './catalogs/ui@1.json';
1
+ import baseCatalogJson from './catalogs/base@3.json';
2
+ import orkestratorCatalogJson from './catalogs/orkestrator@1.json';
8
3
  import {loadVocabulary, type BlokContextName, type VocabFunction} from './vocabulary';
9
4
 
10
5
  /**
11
- * What a v2 blok is parsed and checked against, in the spec's terms. base@2
12
- * (the language) is the spec's; the global catalogs (`ui@1`, `scene@1`,
13
- * `logo@1`, `structure@1`, `html@1`, `shadcn@1`) are written from this
14
- * package's contracts (`catalogs/`, `pnpm spec:export`). A *module* is a UI's
15
- * own unversioned catalog, registered by that UI (the server's `Module`): an
16
- * app adds its own to the default view with `registerBlokModules`. The port
17
- * of arkitekt-spec's `blok/catalogs` (`BlokView`, `default_view`).
6
+ * The catalogs a blok is drawn with, in the spec's terms: the port of
7
+ * arkitekt-spec's `blok/catalogs`.
8
+ *
9
+ * A *catalog* is a versioned set of components, named by the address it is
10
+ * published at (its `id`).
11
+ *
12
+ * - The **base catalog** (`catalogs/base@3.json`,
13
+ * `https://arkitekt.live/catalogs/base/v3`): everything every renderer draws.
14
+ * The language's own elements, the html components, the structure and run
15
+ * parts a host supplies, the scene and the logo shapes. The spec owns it; this
16
+ * package's contracts (`catalogs/`) are held to it by a test.
17
+ * - An **app catalog** extends another (in the end the base) with what one
18
+ * frontend draws beyond it. A snapshot of the Orkestrator's ships
19
+ * (`catalogs/orkestrator@1.json`); any other is registered by the app that
20
+ * draws it (`registerBlokCatalog`).
21
+ *
22
+ * A blok names the one catalog it is written for; the base when it names none.
23
+ * A catalog only ever adds to what it extends.
18
24
  */
19
25
 
20
26
  export const BASE_NAME = 'base';
21
- export const STANDARD_CATALOGS = ['ui', 'scene', 'logo', 'structure', 'html', 'shadcn'] as const;
22
- export type StandardCatalog = (typeof STANDARD_CATALOGS)[number];
27
+ /** The family of the language's own elements (control flow, async boundaries, the context roots, text). */
28
+ export const LANGUAGE_GROUP = 'language';
29
+ /** The Orkestrator's catalog: what it draws beyond the base. */
30
+ export const ORKESTRATOR_CATALOG_ID = 'https://arkitekt.live/catalogs/orkestrator/v1';
23
31
 
24
32
  export type SpecEventField = {key: string; kind: string; description: string | null};
25
33
 
@@ -33,6 +41,8 @@ export type SpecProp = {
33
41
  event: readonly SpecEventField[] | null;
34
42
  /** For a `STRING`, the closed set of literals the component draws; null: any string. */
35
43
  values: readonly string[] | null;
44
+ /** The minor of its catalog that added the prop; 0: there from the start. */
45
+ since: number;
36
46
  };
37
47
 
38
48
  export type SpecComponent = {
@@ -44,10 +54,20 @@ export type SpecComponent = {
44
54
  acceptsChildren: boolean;
45
55
  downstreamOf: readonly string[];
46
56
  notDownstreamOf: readonly string[];
47
- /** The prop text children fill (`<Button>Grip</Button>` sets `label`); null: it takes no text. */
57
+ /** The prop its text children fill when it draws them (`<Button>Grip</Button>` is its `label`); null: it has none. */
48
58
  textProp: string | null;
49
59
  props: readonly SpecProp[];
50
- /** The catalog it is from, `name@version` (`ui@1`), or the module's name (`orkestrator`). */
60
+ /** The blok kinds it may be placed in (`assign`); empty: any kind. */
61
+ kinds: readonly string[];
62
+ /** The service it needs where it is drawn (`mikro`); null: none beyond the host's own. */
63
+ service: string | null;
64
+ /** The minor of its catalog that added it; 0: there from the start. */
65
+ since: number;
66
+ /** The family it is listed under (`language`, `ui`, `html`, `run`, `scene`, `logo`). */
67
+ group: string | null;
68
+ /** How it is drawn where there is no pointer, when that differs. */
69
+ touch: string | null;
70
+ /** The catalog it is from, `name@version` (`base@3`), or the bare name of one nothing published. */
51
71
  catalog: string;
52
72
  };
53
73
 
@@ -56,6 +76,12 @@ export type SpecCatalog = {
56
76
  version: number | null;
57
77
  description: string | null;
58
78
  components: readonly SpecComponent[];
79
+ /** What a blok names it by: the address it is published at. Null for a catalog nothing targets. */
80
+ id: string | null;
81
+ /** How far it has grown within its version. */
82
+ minor: number;
83
+ /** The id of the catalog it adds to; null for the base catalog, and for one that adds to the base without saying so. */
84
+ extends: string | null;
59
85
  };
60
86
 
61
87
  type Raw = Record<string, unknown>;
@@ -64,13 +90,24 @@ const isRaw = (value: unknown): value is Raw => typeof value === 'object' && val
64
90
  const rawList = (value: unknown): unknown[] => (Array.isArray(value) ? value : []);
65
91
  const text = (value: unknown): string | null => (typeof value === 'string' ? value : null);
66
92
  const texts = (value: unknown): string[] => rawList(value).filter((item): item is string => typeof item === 'string');
93
+ const count = (value: unknown): number => (typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : 0);
67
94
 
68
95
  const contextOf = (value: unknown): BlokContextName | null =>
69
96
  value === 'HTML' || value === 'SCENE' || value === 'LOGO' ? value : null;
70
97
 
98
+ /**
99
+ * A catalog file (`{id, name, version, minor, extends, components}`) as a
100
+ * `SpecCatalog`. Only data is read, field by field; nothing is ever executed.
101
+ */
71
102
  export const parseSpecCatalog = (raw: unknown, file: string): SpecCatalog => {
72
103
  if (!isRaw(raw) || typeof raw.name !== 'string') throw new Error(`${file} is not a catalog`);
104
+ const vocabulary = loadVocabulary();
73
105
  const version = typeof raw.version === 'number' ? raw.version : null;
106
+ const address = (value: unknown, what: string): string | null => {
107
+ if (value === undefined || value === null) return null;
108
+ if (typeof value !== 'string' || !vocabulary.catalogId.test(value)) throw new Error(`${file} has an ${what} that is not the address of a catalog`);
109
+ return value;
110
+ };
74
111
  const catalog = version === null ? raw.name : `${raw.name}@${version}`;
75
112
  const components = rawList(raw.components).filter(isRaw).map((entry): SpecComponent => ({
76
113
  name: String(entry.name),
@@ -91,126 +128,245 @@ export const parseSpecCatalog = (raw: unknown, file: string): SpecCatalog => {
91
128
  ? prop.event.filter(isRaw).map(field => ({key: String(field.key), kind: String(field.kind), description: text(field.description)}))
92
129
  : null,
93
130
  values: Array.isArray(prop.values) ? prop.values.map(String) : null,
131
+ since: count(prop.since),
94
132
  })),
133
+ kinds: texts(entry.kinds),
134
+ service: text(entry.service) || null,
135
+ since: count(entry.since),
136
+ group: text(entry.group) || null,
137
+ touch: text(entry.touch) || null,
95
138
  catalog,
96
139
  }));
97
- return {name: raw.name, version, description: text(raw.description), components};
98
- };
99
-
100
- let parsed: {base: SpecCatalog; standard: Record<StandardCatalog, SpecCatalog>} | null = null;
101
-
102
- const catalogs = () => {
103
- if (!parsed) {
104
- parsed = {
105
- base: parseSpecCatalog(baseCatalogJson, 'catalogs/base@2.json'),
106
- standard: {
107
- ui: parseSpecCatalog(uiCatalogJson, 'catalogs/ui@1.json'),
108
- scene: parseSpecCatalog(sceneCatalogJson, 'catalogs/scene@1.json'),
109
- logo: parseSpecCatalog(logoCatalogJson, 'catalogs/logo@1.json'),
110
- structure: parseSpecCatalog(structureCatalogJson, 'catalogs/structure@1.json'),
111
- html: parseSpecCatalog(htmlCatalogJson, 'catalogs/html@1.json'),
112
- shadcn: parseSpecCatalog(shadcnCatalogJson, 'catalogs/shadcn@1.json'),
113
- },
114
- };
140
+ return {
141
+ name: raw.name,
142
+ version,
143
+ description: text(raw.description),
144
+ components,
145
+ id: address(raw.id, 'id'),
146
+ minor: count(raw.minor),
147
+ extends: address(raw.extends, 'extends'),
148
+ };
149
+ };
150
+
151
+ export const catalogLabel = (catalog: SpecCatalog): string => (catalog.version === null ? catalog.name : `${catalog.name}@${catalog.version}`);
152
+
153
+ const BUNDLED: Readonly<Record<string, unknown>> = {
154
+ 'catalogs/base@3.json': baseCatalogJson,
155
+ 'catalogs/orkestrator@1.json': orkestratorCatalogJson,
156
+ };
157
+
158
+ let bundled: Map<string, SpecCatalog> | null = null;
159
+
160
+ const bundledCatalogs = (): Map<string, SpecCatalog> => {
161
+ if (!bundled) {
162
+ bundled = new Map();
163
+ for (const [id, file] of Object.entries(loadVocabulary().bundledCatalogs)) {
164
+ const raw = BUNDLED[file];
165
+ if (raw === undefined) throw new Error(`${file} does not ship with this package`);
166
+ const catalog = parseSpecCatalog(raw, file);
167
+ if (catalog.id !== id) throw new Error(`${file} is ${catalog.id}, not ${id}`);
168
+ bundled.set(id, catalog);
169
+ }
115
170
  }
116
- return parsed;
171
+ return bundled;
117
172
  };
118
173
 
119
- /** base@2: the language components. */
120
- export const baseCatalog = (): SpecCatalog => catalogs().base;
121
- /** A standard catalog at the version the vocabulary names. */
122
- export const standardCatalog = (name: StandardCatalog): SpecCatalog => catalogs().standard[name];
123
- export const standardCatalogs = (): SpecCatalog[] => STANDARD_CATALOGS.map(name => standardCatalog(name));
174
+ /** Catalogs an app handed over (`registerBlokCatalog`), by id. */
175
+ const registered = new Map<string, SpecCatalog>();
176
+ let defaultTarget: string | SpecCatalog | null = null;
177
+ let defaultView: BlokView | null = null;
178
+
179
+ /** The base catalog: what every renderer draws. */
180
+ export const baseCatalog = (): SpecCatalog => bundledCatalogs().get(loadVocabulary().baseCatalog) as SpecCatalog;
181
+ /** The Orkestrator's catalog, as the snapshot this package ships. */
182
+ export const orkestratorCatalog = (): SpecCatalog => bundledCatalogs().get(ORKESTRATOR_CATALOG_ID) as SpecCatalog;
124
183
 
125
184
  /**
126
- * A component name two sources define differently, and which definition is
127
- * drawn: a module's beats a standard catalog's (the app draws its own
128
- * `Slider`), base's is never shadowed, and between two standard catalogs the
129
- * first is kept. The validator warns `catalog.shadow` where a tree uses it.
185
+ * The catalog called `id`: one an app registered, or one that ships; undefined
186
+ * when unknown. What an app registers under the id of a shipped snapshot is
187
+ * that catalog here (the app that draws it knows it best); the base catalog
188
+ * is never replaced.
130
189
  */
131
- export type CatalogShadow = {
132
- component: string;
133
- /** The source that defines it first: base or a standard catalog (`ui@1`). */
134
- catalog: string;
135
- /** The source that defines it again: a module, or a later standard catalog. */
136
- module: string;
137
- /** Whose definition is used. */
138
- winner: string;
190
+ export const knownCatalog = (id: string): SpecCatalog | undefined => registered.get(id) ?? bundledCatalogs().get(id);
191
+ /** Every catalog known here: those that ship (the base first; a registered one in its snapshot's place), then those registered. */
192
+ export const knownCatalogs = (): SpecCatalog[] => [
193
+ ...[...bundledCatalogs().values()].map(catalog => (catalog.id !== null ? registered.get(catalog.id) : undefined) ?? catalog),
194
+ ...[...registered.values()].filter(catalog => catalog.id === null || !bundledCatalogs().has(catalog.id)),
195
+ ];
196
+
197
+ /** Two definitions of a component are the same when everything but where they come from is. */
198
+ export const sameComponent = (a: SpecComponent, b: SpecComponent): boolean => {
199
+ const comparable = (component: SpecComponent): string =>
200
+ JSON.stringify(component, (key, value: unknown) => (key === 'catalog' || key === 'group' || key === 'touch' ? undefined : value));
201
+ return comparable(a) === comparable(b);
139
202
  };
140
203
 
141
- /** What a v2 blok is parsed and checked against. */
204
+ /**
205
+ * The catalogs a blok written for `target` is drawn with, the base first.
206
+ * `target` is a catalog's id, a catalog (one nothing published: it extends the
207
+ * base unless it says otherwise), or null for the base alone. Throws when the
208
+ * target or a catalog it extends is not known, or a catalog redefines a
209
+ * component of one it extends.
210
+ */
211
+ export const catalogChain = (target: string | SpecCatalog | null = null): SpecCatalog[] => {
212
+ const base = baseCatalog();
213
+ let current: SpecCatalog;
214
+ if (target === null) current = base;
215
+ else if (typeof target === 'string') {
216
+ const named = knownCatalog(target);
217
+ if (!named) throw new Error(`the catalog '${target}' is not known here`);
218
+ current = named;
219
+ } else current = target;
220
+ const chain: SpecCatalog[] = [];
221
+ const seen = new Set<string>();
222
+ while (current !== base && current.id !== base.id) {
223
+ if (current.id !== null) {
224
+ if (seen.has(current.id)) throw new Error(`the catalog '${current.id}' extends itself`);
225
+ seen.add(current.id);
226
+ }
227
+ chain.push(current);
228
+ if (current.extends === null) break;
229
+ const parent = knownCatalog(current.extends);
230
+ if (!parent) throw new Error(`the catalog ${catalogLabel(current)} extends '${current.extends}', which is not known here`);
231
+ current = parent;
232
+ }
233
+ const ordered = [base, ...chain.reverse()];
234
+ const owner = new Map<string, [SpecComponent, string]>();
235
+ for (const catalog of ordered) {
236
+ for (const component of catalog.components) {
237
+ const previous = owner.get(component.name);
238
+ if (previous && !sameComponent(previous[0], component)) {
239
+ throw new Error(`the catalog ${catalogLabel(catalog)} redefines <${component.name}> of ${previous[1]}: a catalog only adds`);
240
+ }
241
+ if (!previous) owner.set(component.name, [component, catalogLabel(catalog)]);
242
+ }
243
+ }
244
+ return ordered;
245
+ };
246
+
247
+ /** What a blok is drawn with: the components of the catalog it is written for, and of those that one extends, down to the base. */
142
248
  export type BlokView = {
143
249
  components: ReadonlyMap<string, SpecComponent>;
144
250
  functions: ReadonlyMap<string, VocabFunction>;
145
251
  label: string;
146
- /** Whether the components are every one the renderer draws, so an unknown one is a finding. */
252
+ /** Whether the components are every one the target draws, so an unknown one is a finding. */
147
253
  complete: boolean;
148
- /** The names two sources define differently, by name (`catalog.shadow`). */
149
- shadows: ReadonlyMap<string, CatalogShadow>;
254
+ /** The id of the catalog the view is of; null for one nothing published. */
255
+ target: string | null;
256
+ /** Per component of a known catalog the view is NOT of, that catalog's id (`catalog.target`). */
257
+ foreign: ReadonlyMap<string, string>;
150
258
  };
151
259
 
152
- const catalogLabel = (catalog: SpecCatalog): string => (catalog.version === null ? catalog.name : `${catalog.name}@${catalog.version}`);
153
-
154
- /** Two definitions of a component are the same when everything but the catalog they come from is. */
155
- export const sameComponent = (a: SpecComponent, b: SpecComponent): boolean => {
156
- const withoutCatalog = (component: SpecComponent): string =>
157
- JSON.stringify(component, (key, value: unknown) => (key === 'catalog' ? undefined : value));
158
- return withoutCatalog(a) === withoutCatalog(b);
260
+ /** The view of a blok written for `target` (see `catalogChain`); the base's when null. */
261
+ export const blokView = (target: string | SpecCatalog | null = null, options: {complete?: boolean} = {}): BlokView => {
262
+ const chain = catalogChain(target);
263
+ const components = new Map<string, SpecComponent>();
264
+ for (const catalog of chain) {
265
+ for (const component of catalog.components) if (!components.has(component.name)) components.set(component.name, component);
266
+ }
267
+ const foreign = new Map<string, string>();
268
+ for (const catalog of knownCatalogs()) {
269
+ if (chain.includes(catalog) || catalog.id === null) continue;
270
+ for (const component of catalog.components) {
271
+ if (!components.has(component.name) && !foreign.has(component.name)) foreign.set(component.name, catalog.id);
272
+ }
273
+ }
274
+ return {
275
+ components,
276
+ functions: loadVocabulary().functions,
277
+ label: chain.map(catalogLabel).join(' + '),
278
+ complete: options.complete ?? true,
279
+ target: chain[chain.length - 1].id,
280
+ foreign,
281
+ };
159
282
  };
160
283
 
284
+ /** The view of a blok that names no catalog: the base catalog's. */
285
+ export const baseBlokView = (): BlokView => blokView();
286
+
161
287
  /**
162
- * The view base, the standard catalogs and `extra` ones (modules: the
163
- * Orkestrator's, an app's) give; the port of the spec's `blok_view`.
288
+ * Make a catalog known here, so a blok written for it is checked against it:
289
+ * what an app does with the catalog of what it draws beyond the base
290
+ * (`blokCatalogSpec` of its own contracts). Registered under the id of a
291
+ * snapshot that ships, it stands in its place; the base catalog is never
292
+ * replaced. Throws when it redefines a component of what it extends.
164
293
  */
165
- export const blokView = (extra: readonly SpecCatalog[] = [], options: {standard?: boolean; complete?: boolean} = {}): BlokView => {
166
- const base = baseCatalog();
167
- const sources = [base, ...(options.standard === false ? [] : standardCatalogs()), ...extra];
168
- const modules = new Set<SpecCatalog>(extra);
169
- const baseLabel = catalogLabel(base);
170
- const components = new Map<string, SpecComponent>();
171
- const shadows = new Map<string, CatalogShadow>();
172
- for (const catalog of sources) {
173
- for (const component of catalog.components) {
174
- const previous = components.get(component.name);
175
- if (!previous) {
176
- components.set(component.name, component);
177
- continue;
178
- }
179
- if (sameComponent(previous, component)) continue;
180
- const kept = previous.catalog;
181
- const other = component.catalog || catalog.name;
182
- const wins = modules.has(catalog) && kept !== baseLabel;
183
- if (wins) components.set(component.name, component);
184
- shadows.set(component.name, {component: component.name, catalog: kept, module: other, winner: wins ? other : kept});
185
- }
294
+ export const registerBlokCatalog = (catalog: SpecCatalog): void => {
295
+ if (catalog.id === null) throw new Error(`the catalog '${catalog.name}' has no id to be known by`);
296
+ if (catalog.id === loadVocabulary().baseCatalog) return;
297
+ const previous = registered.get(catalog.id);
298
+ registered.set(catalog.id, catalog);
299
+ defaultView = null;
300
+ try {
301
+ catalogChain(catalog.id);
302
+ } catch (error) {
303
+ if (previous) registered.set(catalog.id, previous);
304
+ else registered.delete(catalog.id);
305
+ throw error;
186
306
  }
187
- const label = sources.map(catalogLabel).join(' + ');
188
- return {components, functions: loadVocabulary().functions, label, complete: options.complete ?? true, shadows};
189
307
  };
190
308
 
191
- let defaultView: BlokView | null = null;
192
- let defaultModules: readonly SpecCatalog[] = [];
309
+ /** Forget every catalog `registerBlokCatalog` was handed, and the app's own view (for tests). */
310
+ export const forgetBlokCatalogs = (): void => {
311
+ registered.clear();
312
+ defaultTarget = null;
313
+ defaultView = null;
314
+ };
193
315
 
194
316
  /**
195
- * The app's own catalogs, as its UI registers them (`describeBlokContract` of
196
- * each unversioned contract it implements): part of the default view from now
197
- * on, so the parser, the checks and the editor know its components. Call it
198
- * once at start, beside `configureBlokPlatform`.
317
+ * The catalog this app draws: the one its own editor, checks and renderer
318
+ * read a blok against when the blok names none of its own. An app that draws
319
+ * only the base leaves it unset. Call it once at start, beside
320
+ * `configureBlokPlatform`.
199
321
  */
200
- export const registerBlokModules = (modules: readonly SpecCatalog[]): void => {
201
- defaultModules = modules;
322
+ export const setAppBlokCatalog = (target: string | SpecCatalog | null): void => {
323
+ if (target !== null && typeof target !== 'string' && target.id !== null) registerBlokCatalog(target);
324
+ defaultTarget = target !== null && typeof target !== 'string' && target.id !== null ? target.id : target;
202
325
  defaultView = null;
203
326
  };
204
327
 
205
- /** The app's view: base, every global catalog and its own (`registerBlokModules`). */
328
+ /** The app's own view: everything it draws (`setAppBlokCatalog`), the base catalog's when it set none. */
206
329
  export const defaultBlokView = (): BlokView => {
207
- if (!defaultView) defaultView = blokView(defaultModules);
330
+ if (!defaultView) defaultView = blokView(defaultTarget);
208
331
  return defaultView;
209
332
  };
210
333
 
334
+ /**
335
+ * The view a blok that names `catalog` is read against: that catalog's when it
336
+ * is known here, the app's own when the blok names none, and the base's,
337
+ * incomplete (nothing is reported unknown), for a catalog nobody here knows.
338
+ */
339
+ export const blokViewFor = (catalog: string | null | undefined): BlokView => {
340
+ if (catalog === null || catalog === undefined) return baseBlokView();
341
+ if (knownCatalog(catalog)) return blokView(catalog);
342
+ return blokView(null, {complete: false});
343
+ };
344
+
345
+ /** Whether `target` can name a catalog at all: a published one's address, or the name of one registered in an organization. */
346
+ export const isCatalogTarget = (target: string): boolean => {
347
+ const vocabulary = loadVocabulary();
348
+ return vocabulary.catalogId.test(target) || vocabulary.catalogName.test(target);
349
+ };
350
+
351
+ /** The minor of the catalog the view is of that `tree` needs: the newest `since` among the components and props of that catalog it uses. */
352
+ export const minorNeeded = (tree: {component: string; props?: ReadonlyArray<{key: string}> | null; children?: readonly unknown[] | null}, view: BlokView): number => {
353
+ const target = view.label.split(' + ').pop();
354
+ let needed = 0;
355
+ const visit = (node: typeof tree): void => {
356
+ const spec = view.components.get(node.component);
357
+ if (spec && spec.catalog === target) {
358
+ needed = Math.max(needed, spec.since);
359
+ for (const prop of node.props ?? []) needed = Math.max(needed, spec.props.find(candidate => candidate.key === prop.key)?.since ?? 0);
360
+ }
361
+ for (const child of node.children ?? []) visit(child as typeof tree);
362
+ };
363
+ visit(tree);
364
+ return needed;
365
+ };
366
+
211
367
  /** Whether a component is a language one that holds others in whatever context (`if`, `foreach`, `fragment`). */
212
368
  export const isLanguageContainer = (component: SpecComponent | undefined): boolean =>
213
- component !== undefined && component.catalog.startsWith(`${BASE_NAME}@`) && component.inheritsContext && component.acceptsChildren;
369
+ component !== undefined && component.group === LANGUAGE_GROUP && component.inheritsContext && component.acceptsChildren;
214
370
 
215
371
  /** The context a component's children are in, given the one it sits in. */
216
372
  export const innerContext = (component: SpecComponent | undefined, context: BlokContextName): BlokContextName => {
@@ -1,6 +1,20 @@
1
- import {describe, expect, it} from 'vitest';
2
- import corpus from './bsx_v2.json';
3
- import {defaultBlokView} from './catalogs';
1
+ import {afterEach, describe, expect, it} from 'vitest';
2
+ import {
3
+ ORKESTRATOR_CATALOG_ID,
4
+ baseBlokView,
5
+ baseCatalog,
6
+ blokView,
7
+ blokViewFor,
8
+ catalogChain,
9
+ defaultBlokView,
10
+ forgetBlokCatalogs,
11
+ isCatalogTarget,
12
+ minorNeeded,
13
+ orkestratorCatalog,
14
+ parseSpecCatalog,
15
+ registerBlokCatalog,
16
+ setAppBlokCatalog,
17
+ } from './catalogs';
4
18
  import {argFits, bindFits, bindKindsOf, diagnosticMessage, isExplicitId, loadVocabulary} from './vocabulary';
5
19
 
6
20
  describe('the synced vocabulary', () => {
@@ -32,8 +46,12 @@ describe('the synced vocabulary', () => {
32
46
  expect(vocabulary.callKinds).not.toContain('query_refetch');
33
47
  expect(vocabulary.records.query.fields.map(field => field.key)).toContain('fetching_more');
34
48
  expect(Object.keys(vocabulary.theme.dataAttributes).sort()).toEqual(['busy', 'stale']);
35
- expect(vocabulary.catalogs).toEqual({ui: 1, scene: 1, logo: 1, structure: 1, html: 1, shadcn: 1});
36
- expect(vocabulary.baseVersion).toBe(2);
49
+ expect([vocabulary.vocab, vocabulary.minor]).toEqual([2, 1]);
50
+ expect(vocabulary.baseCatalog).toBe('https://arkitekt.live/catalogs/base/v3');
51
+ expect(Object.values(vocabulary.bundledCatalogs)).toEqual(['catalogs/base@3.json', 'catalogs/orkestrator@1.json']);
52
+ expect(vocabulary.hostParts).toEqual(['args', 'arg', 'deps', 'dep', 'ask', 'returns', 'status', 'timeline']);
53
+ expect(vocabulary.unportableVariants.has('before')).toBe(true);
54
+ expect(vocabulary.unportableVariants.has('hover')).toBe(false);
37
55
  });
38
56
 
39
57
  it('says what a bind writes and what an argument takes', () => {
@@ -66,23 +84,71 @@ describe('the synced vocabulary', () => {
66
84
  });
67
85
  });
68
86
 
69
- describe('the catalog view', () => {
70
- it("gives the corpus's text table, component for component", () => {
71
- const view = defaultBlokView();
72
- const table = Object.fromEntries(
73
- [...view.components.values()].map(component => [
74
- component.name,
75
- {
76
- text_prop: component.textProp,
77
- context: component.context,
78
- children_context: component.childrenContext,
79
- inherits_context: component.inheritsContext,
80
- accepts_children: component.acceptsChildren,
81
- catalog: component.catalog,
82
- },
83
- ]),
87
+ describe('the catalogs', () => {
88
+ afterEach(() => forgetBlokCatalogs());
89
+
90
+ it('ship as the vocabulary names them, the base catalog first', () => {
91
+ const base = baseCatalog();
92
+ expect([base.id, base.name, base.version, base.extends]).toEqual(['https://arkitekt.live/catalogs/base/v3', 'base', 3, null]);
93
+ const orkestrator = orkestratorCatalog();
94
+ expect([orkestrator.id, orkestrator.extends]).toEqual([ORKESTRATOR_CATALOG_ID, base.id]);
95
+ expect(catalogChain(ORKESTRATOR_CATALOG_ID).map(catalog => catalog.name)).toEqual(['base', 'orkestrator']);
96
+ });
97
+
98
+ it('give a view of one catalog, which knows what is another\'s', () => {
99
+ const base = baseBlokView();
100
+ expect(base.label).toBe('base@3');
101
+ expect(base.components.has('MikroScene')).toBe(false);
102
+ expect(base.foreign.get('MikroScene')).toBe(ORKESTRATOR_CATALOG_ID);
103
+ const orkestrator = blokView(ORKESTRATOR_CATALOG_ID);
104
+ expect(orkestrator.label).toBe('base@3 + orkestrator@1');
105
+ expect(orkestrator.components.get('MikroScene')?.service).toBe('mikro');
106
+ expect(orkestrator.components.has('Button')).toBe(true);
107
+ expect(orkestrator.components.get('args')?.kinds).toEqual(['assign']);
108
+ });
109
+
110
+ it('take in what an app registers, and read a blok against the catalog it names', () => {
111
+ const lab = parseSpecCatalog(
112
+ {id: 'https://acme.example/catalogs/lab/v1', name: 'lab', version: 1, minor: 2, extends: ORKESTRATOR_CATALOG_ID, components: [{name: 'Spectrum', props: [{key: 'bands', kind: 'LIST', since: 2}]}]},
113
+ 'lab',
114
+ );
115
+ expect(blokViewFor(lab.id).complete).toBe(false);
116
+ registerBlokCatalog(lab);
117
+ const view = blokViewFor(lab.id);
118
+ expect(view.complete).toBe(true);
119
+ expect(['Spectrum', 'MikroScene', 'Button'].every(name => view.components.has(name))).toBe(true);
120
+ expect(minorNeeded({component: 'Html', children: [{component: 'Spectrum', props: [{key: 'bands'}]}]}, view)).toBe(2);
121
+ expect(minorNeeded({component: 'Html', children: [{component: 'Spectrum'}]}, view)).toBe(0);
122
+ expect(blokViewFor(null).label).toBe('base@3');
123
+ });
124
+
125
+ it('are the app\'s own view once it says what it draws', () => {
126
+ expect(defaultBlokView().label).toBe('base@3');
127
+ setAppBlokCatalog(ORKESTRATOR_CATALOG_ID);
128
+ expect(defaultBlokView().components.has('MikroScene')).toBe(true);
129
+ setAppBlokCatalog(parseSpecCatalog({name: 'mine', components: [{name: 'Gauge', props: []}]}, 'mine'));
130
+ expect(defaultBlokView().label).toBe('base@3 + mine');
131
+ });
132
+
133
+ it('take the app\'s own catalog over the snapshot that ships under its id, and never replace the base', () => {
134
+ const live = parseSpecCatalog(
135
+ {id: ORKESTRATOR_CATALOG_ID, name: 'orkestrator', version: 1, minor: 3, extends: baseCatalog().id, components: [{name: 'MikroScene', props: []}, {name: 'Fresh', props: []}]},
136
+ 'orkestrator',
84
137
  );
85
- expect(table).toEqual(corpus.text_table);
138
+ setAppBlokCatalog(live);
139
+ expect(defaultBlokView().components.has('Fresh')).toBe(true);
140
+ expect(blokViewFor(ORKESTRATOR_CATALOG_ID).components.has('Fresh')).toBe(true);
141
+ expect(baseBlokView().foreign.get('Fresh')).toBe(ORKESTRATOR_CATALOG_ID);
142
+ registerBlokCatalog(parseSpecCatalog({id: baseCatalog().id, name: 'base', version: 3, components: []}, 'base'));
143
+ expect(baseBlokView().components.has('Button')).toBe(true);
144
+ });
145
+
146
+ it('refuse a catalog that redefines what it extends, or names no catalog address', () => {
147
+ const redefining = parseSpecCatalog({id: 'https://acme.example/catalogs/x/v1', name: 'x', version: 1, components: [{name: 'Button', props: []}]}, 'x');
148
+ expect(() => registerBlokCatalog(redefining)).toThrow(/redefines <Button> of base@3/);
149
+ expect(() => parseSpecCatalog({id: 'http://acme.example/catalogs/x/v1', name: 'x', components: []}, 'x')).toThrow(/not the address of a catalog/);
150
+ expect(isCatalogTarget('ui@1')).toBe(false);
151
+ expect(isCatalogTarget(ORKESTRATOR_CATALOG_ID) && isCatalogTarget('mine')).toBe(true);
86
152
  });
87
153
  });
88
154