@arkitektio/bsx 5.0.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 (220) hide show
  1. package/README.md +2 -2
  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 +6 -1
  23. package/dist/bsx/parse.d.ts.map +1 -1
  24. package/dist/bsx/parse.js +32 -3
  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 +3 -0
  28. package/dist/bsx/print.js.map +1 -1
  29. package/dist/bsx/references.d.ts +45 -51
  30. package/dist/bsx/references.d.ts.map +1 -1
  31. package/dist/bsx/references.js +265 -138
  32. package/dist/bsx/references.js.map +1 -1
  33. package/dist/catalogs/html.d.ts +2 -2
  34. package/dist/catalogs/index.d.ts +49 -71
  35. package/dist/catalogs/index.d.ts.map +1 -1
  36. package/dist/catalogs/index.js +1 -1
  37. package/dist/catalogs/logo.d.ts +14 -28
  38. package/dist/catalogs/logo.d.ts.map +1 -1
  39. package/dist/catalogs/logo.js +1 -2
  40. package/dist/catalogs/logo.js.map +1 -1
  41. package/dist/catalogs/parts/data.d.ts +1 -1
  42. package/dist/catalogs/parts/feedback.d.ts +3 -3
  43. package/dist/catalogs/parts/forms.d.ts +4 -4
  44. package/dist/catalogs/parts/html.d.ts +2 -2
  45. package/dist/catalogs/parts/icons.d.ts +2 -2
  46. package/dist/catalogs/parts/index.d.ts +35 -57
  47. package/dist/catalogs/parts/index.d.ts.map +1 -1
  48. package/dist/catalogs/parts/logo.d.ts +10 -25
  49. package/dist/catalogs/parts/logo.d.ts.map +1 -1
  50. package/dist/catalogs/parts/logo.js +12 -14
  51. package/dist/catalogs/parts/logo.js.map +1 -1
  52. package/dist/catalogs/parts/navigation.d.ts +4 -4
  53. package/dist/catalogs/parts/overlays.d.ts +11 -11
  54. package/dist/catalogs/parts/run.d.ts +2 -10
  55. package/dist/catalogs/parts/run.d.ts.map +1 -1
  56. package/dist/catalogs/parts/scene.d.ts +7 -15
  57. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  58. package/dist/catalogs/parts/scene.js +1 -5
  59. package/dist/catalogs/parts/scene.js.map +1 -1
  60. package/dist/catalogs/parts/typography.d.ts +3 -3
  61. package/dist/catalogs/props.d.ts +2 -2
  62. package/dist/catalogs/scene.d.ts +5 -13
  63. package/dist/catalogs/scene.d.ts.map +1 -1
  64. package/dist/catalogs/shadcn.d.ts +11 -11
  65. package/dist/catalogs/ui.d.ts +16 -16
  66. package/dist/logo/actionLogoSource.d.ts +3 -3
  67. package/dist/logo/actionLogoSource.d.ts.map +1 -1
  68. package/dist/logo/actionLogoSource.js +4 -4
  69. package/dist/logo/actionLogoSource.js.map +1 -1
  70. package/dist/renderer/BlokRenderer.d.ts +10 -6
  71. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  72. package/dist/renderer/BlokRenderer.js +23 -9
  73. package/dist/renderer/BlokRenderer.js.map +1 -1
  74. package/dist/renderer/baseCatalog.d.ts +3 -3
  75. package/dist/renderer/baseCatalog.js +2 -2
  76. package/dist/renderer/bloks/control.d.ts +18 -2
  77. package/dist/renderer/bloks/control.d.ts.map +1 -1
  78. package/dist/renderer/bloks/control.js +85 -14
  79. package/dist/renderer/bloks/control.js.map +1 -1
  80. package/dist/renderer/bloks/data.d.ts +1 -1
  81. package/dist/renderer/bloks/feedback.d.ts +3 -3
  82. package/dist/renderer/bloks/forms.d.ts +4 -4
  83. package/dist/renderer/bloks/html.d.ts +2 -2
  84. package/dist/renderer/bloks/icons.d.ts +1 -1
  85. package/dist/renderer/bloks/index.d.ts +30 -37
  86. package/dist/renderer/bloks/index.d.ts.map +1 -1
  87. package/dist/renderer/bloks/logo/index.d.ts +1 -8
  88. package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
  89. package/dist/renderer/bloks/logo/index.js +1 -2
  90. package/dist/renderer/bloks/logo/index.js.map +1 -1
  91. package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
  92. package/dist/renderer/bloks/navigation.d.ts +4 -4
  93. package/dist/renderer/bloks/overlays.d.ts +11 -11
  94. package/dist/renderer/bloks/run/components.d.ts +1 -5
  95. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  96. package/dist/renderer/bloks/scene/index.d.ts +4 -8
  97. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  98. package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
  99. package/dist/renderer/bloks/scene/interaction.js +3 -2
  100. package/dist/renderer/bloks/scene/interaction.js.map +1 -1
  101. package/dist/renderer/bloks/shared/props.d.ts +2 -2
  102. package/dist/renderer/bloks/typography.d.ts +3 -3
  103. package/dist/renderer/declarations.d.ts +40 -33
  104. package/dist/renderer/declarations.d.ts.map +1 -1
  105. package/dist/renderer/declarations.js +41 -56
  106. package/dist/renderer/declarations.js.map +1 -1
  107. package/dist/renderer/declare.js +4 -4
  108. package/dist/renderer/declare.js.map +1 -1
  109. package/dist/renderer/persist.d.ts +22 -13
  110. package/dist/renderer/persist.d.ts.map +1 -1
  111. package/dist/renderer/persist.js +40 -21
  112. package/dist/renderer/persist.js.map +1 -1
  113. package/dist/renderer/runtime/catalog.d.ts +4 -4
  114. package/dist/renderer/runtime/catalog.js +3 -3
  115. package/dist/renderer/runtime/components.d.ts +4 -4
  116. package/dist/renderer/runtime/components.d.ts.map +1 -1
  117. package/dist/renderer/runtime/components.js +5 -5
  118. package/dist/renderer/runtime/components.js.map +1 -1
  119. package/dist/renderer/runtime/context.d.ts +5 -5
  120. package/dist/renderer/runtime/context.d.ts.map +1 -1
  121. package/dist/renderer/runtime/context.js +11 -5
  122. package/dist/renderer/runtime/context.js.map +1 -1
  123. package/dist/renderer/runtime/describe.d.ts +3 -3
  124. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  125. package/dist/renderer/runtime/describe.js +2 -2
  126. package/dist/renderer/runtime/describe.js.map +1 -1
  127. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  128. package/dist/renderer/runtime/hooks.js +8 -4
  129. package/dist/renderer/runtime/hooks.js.map +1 -1
  130. package/dist/renderer/runtime/index.d.ts +1 -0
  131. package/dist/renderer/runtime/index.d.ts.map +1 -1
  132. package/dist/renderer/runtime/index.js +1 -0
  133. package/dist/renderer/runtime/index.js.map +1 -1
  134. package/dist/renderer/runtime/locals.d.ts +57 -0
  135. package/dist/renderer/runtime/locals.d.ts.map +1 -0
  136. package/dist/renderer/runtime/locals.js +87 -0
  137. package/dist/renderer/runtime/locals.js.map +1 -0
  138. package/dist/renderer/runtime/scope.d.ts +14 -0
  139. package/dist/renderer/runtime/scope.d.ts.map +1 -1
  140. package/dist/renderer/runtime/scope.js +25 -3
  141. package/dist/renderer/runtime/scope.js.map +1 -1
  142. package/dist/renderer/runtime/tree.d.ts.map +1 -1
  143. package/dist/renderer/runtime/tree.js +7 -1
  144. package/dist/renderer/runtime/tree.js.map +1 -1
  145. package/dist/renderer/runtime/types.d.ts +8 -3
  146. package/dist/renderer/runtime/types.d.ts.map +1 -1
  147. package/dist/shadcn.d.ts +36 -43
  148. package/dist/shadcn.d.ts.map +1 -1
  149. package/dist/shadcn.js +1 -2
  150. package/dist/shadcn.js.map +1 -1
  151. package/dist/spec/bsx_v2.json +11067 -6321
  152. package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
  153. package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
  154. package/dist/spec/catalogs/orkestrator@1.json +10 -10
  155. package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
  156. package/dist/spec/catalogs.d.ts +4 -4
  157. package/dist/spec/catalogs.d.ts.map +1 -1
  158. package/dist/spec/catalogs.js +7 -7
  159. package/dist/spec/catalogs.js.map +1 -1
  160. package/dist/spec/vocabulary.d.ts +25 -4
  161. package/dist/spec/vocabulary.d.ts.map +1 -1
  162. package/dist/spec/vocabulary.js +50 -5
  163. package/dist/spec/vocabulary.js.map +1 -1
  164. package/dist/spec/vocabulary.json +58 -32
  165. package/dist/spec/vocabulary.json.js +58 -32
  166. package/package.json +1 -1
  167. package/src/bsx/analyze.ts +14 -12
  168. package/src/bsx/bsx.test.ts +4 -4
  169. package/src/bsx/declared.ts +346 -0
  170. package/src/bsx/index.ts +1 -0
  171. package/src/bsx/infer.test.ts +42 -32
  172. package/src/bsx/infer.ts +128 -71
  173. package/src/bsx/language.test.ts +37 -25
  174. package/src/bsx/language.ts +72 -25
  175. package/src/bsx/parse.ts +34 -3
  176. package/src/bsx/print.ts +3 -0
  177. package/src/bsx/references.test.ts +82 -81
  178. package/src/bsx/references.ts +313 -178
  179. package/src/catalogs/catalogs.test.ts +3 -2
  180. package/src/catalogs/index.ts +1 -1
  181. package/src/catalogs/logo.ts +1 -2
  182. package/src/catalogs/parts/logo.ts +13 -17
  183. package/src/catalogs/parts/scene.ts +1 -7
  184. package/src/logo/actionLogoSource.ts +4 -4
  185. package/src/renderer/BlokComponentHost.test.tsx +5 -5
  186. package/src/renderer/BlokRenderer.tsx +46 -14
  187. package/src/renderer/addBlokComponents.test.tsx +1 -1
  188. package/src/renderer/baseCatalog.ts +2 -2
  189. package/src/renderer/bloks/control.tsx +119 -16
  190. package/src/renderer/bloks/logo/index.tsx +2 -3
  191. package/src/renderer/bloks/logo/logo.fixture.json +266 -250
  192. package/src/renderer/bloks/logo/logo.test.tsx +18 -7
  193. package/src/renderer/bloks/run/space.test.tsx +12 -4
  194. package/src/renderer/bloks/scene/interaction.tsx +11 -6
  195. package/src/renderer/bloks/scene/transform.test.ts +8 -7
  196. package/src/renderer/declarations.test.ts +38 -51
  197. package/src/renderer/declarations.ts +67 -88
  198. package/src/renderer/declare.test.ts +4 -4
  199. package/src/renderer/declare.ts +4 -4
  200. package/src/renderer/persist.test.ts +70 -49
  201. package/src/renderer/persist.ts +57 -34
  202. package/src/renderer/runtime/catalog.test.ts +2 -2
  203. package/src/renderer/runtime/catalog.ts +4 -4
  204. package/src/renderer/runtime/components.tsx +8 -8
  205. package/src/renderer/runtime/context.tsx +17 -10
  206. package/src/renderer/runtime/describe.ts +5 -5
  207. package/src/renderer/runtime/hooks.ts +6 -4
  208. package/src/renderer/runtime/index.ts +1 -0
  209. package/src/renderer/runtime/locals.tsx +105 -0
  210. package/src/renderer/runtime/scope.tsx +31 -3
  211. package/src/renderer/runtime/tree.tsx +16 -4
  212. package/src/renderer/runtime/types.ts +8 -3
  213. package/src/shadcn.ts +1 -2
  214. package/src/spec/bsx_v2.json +11067 -6321
  215. package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
  216. package/src/spec/catalogs/orkestrator@1.json +10 -10
  217. package/src/spec/catalogs.ts +8 -8
  218. package/src/spec/spec.test.ts +19 -16
  219. package/src/spec/vocabulary.json +58 -32
  220. package/src/spec/vocabulary.ts +69 -10
@@ -1,7 +1,7 @@
1
1
  import {describe, expect, it} from 'vitest';
2
2
  import {controlBlokComponents} from '../renderer/bloks/control';
3
3
  import {BASE_CATALOG_REF, describeBlokContract, type SpecComponentJson} from '../renderer/runtime';
4
- import baseCatalogJson from '../spec/catalogs/base@3.json';
4
+ import baseCatalogJson from '../spec/catalogs/base@4.json';
5
5
  import {baseFamilies} from './index';
6
6
  import {parts} from './parts';
7
7
 
@@ -47,7 +47,8 @@ describe('the families of the base catalog', () => {
47
47
  const entry = shipped.get(component.name);
48
48
  expect(entry, component.name).toBeDefined();
49
49
  expect(entry?.group === 'language' || entry?.group === 'run', component.name).toBe(true);
50
- const props = Object.keys(component.schema.shape).filter(key => key !== 'children').sort();
50
+ // `children` is a slot where a component takes children; a `<local>`'s is a prop (its child ports).
51
+ const props = Object.keys(component.schema.shape).filter(key => key !== 'children' || !component.acceptsChildren).sort();
51
52
  expect(props, component.name).toEqual((entry?.props ?? []).map(prop => prop.key).sort());
52
53
  }
53
54
  });
@@ -11,6 +11,6 @@ export * from './props';
11
11
  /**
12
12
  * The families of the base catalog this package holds contracts for: every
13
13
  * component of it that is not the language's own (`renderer/bloks/control`).
14
- * The spec's `catalogs/base@3.json` is what they say (`catalogs.test.ts`).
14
+ * The spec's `catalogs/base@4.json` is what they say (`catalogs.test.ts`).
15
15
  */
16
16
  export const baseFamilies = [uiCatalog, htmlCatalog, logoCatalog, sceneCatalog, structureCatalog, shadcnCatalog] as const;
@@ -7,8 +7,6 @@ export const logoCatalog = defineBlokCatalog({
7
7
  partOf: BASE_CATALOG_REF,
8
8
  description: "SVG drawing for logos and action logos; the palette is restricted to the logo pens.",
9
9
  components: {
10
- ActionLogo: parts.ActionLogo,
11
- AgentLogo: parts.AgentLogo,
12
10
  Circle: parts.Circle,
13
11
  ClipPath: parts.ClipPath,
14
12
  Defs: parts.Defs,
@@ -16,6 +14,7 @@ export const logoCatalog = defineBlokCatalog({
16
14
  G: parts.G,
17
15
  Line: parts.Line,
18
16
  LinearGradient: parts.LinearGradient,
17
+ Logo: parts.Logo,
19
18
  Path: parts.Path,
20
19
  Polygon: parts.Polygon,
21
20
  Polyline: parts.Polyline,
@@ -5,14 +5,14 @@ import {loadVocabulary} from '../../spec/vocabulary';
5
5
  import {actionProp, describedString} from '../props';
6
6
 
7
7
  /**
8
- * The `logo` family of the blok language: the `AgentLogo` and `ActionLogo`
9
- * roots and the classic SVG elements as components.
8
+ * The `logo` family of the blok language: the `Logo` drawing and the classic
9
+ * SVG elements as components.
10
10
  *
11
- * A logo root sits in html like `Scene` does and opens the `logo` context, so a
12
- * `Path` or a `Circle` is only ever placed inside one. The root names the
13
- * blok's context: an `AgentLogo` root is a LOGO blok, an `ActionLogo` root an
14
- * ACTION_LOGO blok (it reads `task`, the viewer's last task of the action); any
15
- * html blok may draw either too.
11
+ * A `Logo` sits in a panel like `Scene` does and opens the `logo` context, so
12
+ * a `Path` or a `Circle` is only ever placed inside one. It is the one element
13
+ * of a logo blok (`<Blok kind="agent" context="logo"><Logo>`); an action's
14
+ * logo is `<Blok kind="action" context="logo">` and reads only `task`, the
15
+ * viewer's last task of the action. Any panel may draw a `Logo` too.
16
16
  *
17
17
  * A logo paints with the viewer's pens only (vocabulary `theme.logo_pens`:
18
18
  * `ink`, `brand`, ..., the status roles `success`, `warning`, `info`), drawn
@@ -39,11 +39,10 @@ export const LOGO_ANIMATIONS = ['spin', 'pulse', 'float', 'draw', 'march', 'blin
39
39
  const length = (description: string) =>
40
40
  z.union([z.number(), z.string()]).optional().describe(description);
41
41
 
42
- export const AGENT_LOGO_ROOT = 'AgentLogo';
43
- export const ACTION_LOGO_ROOT = 'ActionLogo';
44
- export const LOGO_ROOTS = [AGENT_LOGO_ROOT, ACTION_LOGO_ROOT];
42
+ /** A logo's drawing: the one element of a logo blok. */
43
+ export const LOGO_ROOT = 'Logo';
45
44
 
46
- const IN_SVG: BlokComponentPlacement = {context: 'logo', downstreamOf: LOGO_ROOTS};
45
+ const IN_SVG: BlokComponentPlacement = {context: 'logo', downstreamOf: [LOGO_ROOT]};
47
46
 
48
47
  /* -------------------------------------------------------------------------- */
49
48
  /* Presentation: what every shape and group may set */
@@ -143,7 +142,7 @@ const rootSchema = (description: string) =>
143
142
  /** A drawing's root: an `<svg>` whose shapes paint with the pens. */
144
143
  const logoRoot = (description: string) => ({
145
144
  acceptsChildren: true,
146
- placement: {childrenContext: 'logo', notDownstreamOf: LOGO_ROOTS} satisfies BlokComponentPlacement,
145
+ placement: {childrenContext: 'logo', notDownstreamOf: [LOGO_ROOT]} satisfies BlokComponentPlacement,
147
146
  schema: rootSchema(description),
148
147
  });
149
148
 
@@ -158,11 +157,8 @@ const gradientUnits = z
158
157
 
159
158
  /** The `logo` family: the root, seven shapes, text, and what shapes reference. */
160
159
  export const logoContracts = {
161
- [AGENT_LOGO_ROOT]: logoRoot(
162
- "The root of an agent's logo: a drawing in the viewer's pens. Its children are SVG shapes.",
163
- ),
164
- [ACTION_LOGO_ROOT]: logoRoot(
165
- "The root of an action's logo: a drawing in the viewer's pens that reads task (the viewer's last task of the action, idle until they run it). Its children are SVG shapes.",
160
+ [LOGO_ROOT]: logoRoot(
161
+ "A logo's drawing, the one element of a logo blok: an SVG in the viewer's pens (an action's paints with the pens only). Its children are SVG shapes.",
166
162
  ),
167
163
  Path: shape('An SVG path.', shapeGeometry.Path),
168
164
  Circle: shape('An SVG circle.', shapeGeometry.Circle),
@@ -19,12 +19,6 @@ import {actionProp, bindSchema, describedString} from '../props';
19
19
 
20
20
  export const sceneSchema = z
21
21
  .object({
22
- chrome: z
23
- .enum(['auto', 'none'])
24
- .optional()
25
- .describe(
26
- "What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
27
- ),
28
22
  camera: z
29
23
  .enum(['iso', 'front', 'side', 'top'])
30
24
  .optional()
@@ -292,7 +286,7 @@ export const sceneContracts = {
292
286
  OnClick: {placement: IN_MODEL_OR_AT, schema: onClickSchema},
293
287
  Popout: {
294
288
  acceptsChildren: true,
295
- placement: {...IN_MODEL_OR_AT, childrenContext: 'html'},
289
+ placement: {...IN_MODEL_OR_AT, childrenContext: 'panel'},
296
290
  schema: popoutSchema,
297
291
  },
298
292
  } satisfies BlokComponentContracts;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The pen this app draws its action logos with: logo bloks in v2 BSX (an
3
- * `ActionLogo` root, the action-logo kind), on a 24 px grid, painted with the viewer's pens
2
+ * The pen this app draws its action logos with: logo bloks in v2 BSX
3
+ * (`<Blok kind="action" context="logo"><Logo>`), on a 24 px grid, painted with the viewer's pens
4
4
  * only (vocabulary `theme.logo_pens`: `ink muted brand brand-strong brand-soft
5
5
  * surface none`, the status pens `success warning info` and the spectral pens
6
6
  * `spectrum-violet` ... `spectrum-red`, for a logo of something that has a
@@ -19,6 +19,6 @@ export const ACTION_LOGO_PEN =
19
19
  /** An attribute literal: in v2 BSX `"..."` is always a string, so only the markup needs escaping. */
20
20
  const attribute = (value: string): string => value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
21
21
 
22
- /** An `ActionLogo` of `body`, drawn with the pen. */
22
+ /** An action's logo blok of `body`, drawn with the pen. */
23
23
  export const actionLogoSource = (title: string, body: string): string =>
24
- `<ActionLogo viewBox="0 0 24 24" title="${attribute(title)}"><G ${ACTION_LOGO_PEN}>${body}</G></ActionLogo>`;
24
+ `<Blok kind="action" context="logo"><Logo viewBox="0 0 24 24" title="${attribute(title)}"><G ${ACTION_LOGO_PEN}>${body}</G></Logo></Blok>`;
@@ -7,21 +7,21 @@ import {BlokComponentHost} from './BlokComponentHost';
7
7
 
8
8
  afterEach(cleanup);
9
9
 
10
- /** `<Html><Card><Input bind={value} placeholder="scale" /><p>{limit}</p></Card></Html>`, as the server sends it. */
10
+ /** `<fragment><Card><Input bind={value} placeholder="scale" /><p>{limit}</p></Card></fragment>`, as the server sends it. */
11
11
  const NODES = [
12
12
  {
13
- id: 'Html[0]/Card[0]',
13
+ id: 'fragment[0]/Card[0]',
14
14
  component: 'Card',
15
15
  children: [
16
16
  {
17
- id: 'Html[0]/Card[0]/Input[0]',
17
+ id: 'fragment[0]/Card[0]/Input[0]',
18
18
  component: 'Input',
19
19
  props: [
20
20
  {key: 'bind', dynamic_value: {path: 'value'}},
21
21
  {key: 'placeholder', static_value: 'scale'},
22
22
  ],
23
23
  },
24
- {id: 'Html[0]/Card[0]/p[0]', component: 'p', props: [{key: 'text', dynamic_value: {path: 'limit'}}]},
24
+ {id: 'fragment[0]/Card[0]/p[0]', component: 'p', props: [{key: 'text', dynamic_value: {path: 'limit'}}]},
25
25
  ],
26
26
  },
27
27
  ];
@@ -31,7 +31,7 @@ describe('BlokComponentHost with a tree', () => {
31
31
  const onValue = vi.fn();
32
32
  render(
33
33
  <BlokComponentHost
34
- component="Html"
34
+ component="fragment"
35
35
  props={[]}
36
36
  nodes={NODES}
37
37
  data={{value: 'a', limit: 'up to 9'}}
@@ -8,6 +8,8 @@ import {BlokSceneFillProvider} from './bloks/scene/host';
8
8
  import {useBlokCatalog} from './catalog';
9
9
  import {invokeBlokFunction} from './functions/v2/handler';
10
10
  import {BlokComponentStateContext, type BlokComponentStateStore} from './persist';
11
+ import {drawnChildren} from './bloks/control';
12
+ import {treeQueries, treeSubscriptions} from './declarations';
11
13
  import {
12
14
  BlokNode,
13
15
  BlokNodeErrorSurface,
@@ -15,10 +17,14 @@ import {
15
17
  BlokTreeProvider,
16
18
  createBlokRuntimeStore,
17
19
  dependencyStatusPath,
20
+ BlokLocalsScope,
21
+ localChildren,
22
+ normalizeBlokComponentTree,
18
23
  preflightBlokDocument,
19
24
  unboundDependencyStatus,
20
25
  unboundDependencyStatuses,
21
26
  type BlokCatalog,
27
+ type BlokComponentNode,
22
28
  type BlokNodeErrorProps,
23
29
  type BlokDispatchActionHandler,
24
30
  type BlokInvokeFunctionHandler,
@@ -65,19 +71,23 @@ type BlokRendererProps = {
65
71
  /** Shows the floating runtime-state inspector. Off by default. */
66
72
  debug?: boolean;
67
73
  /**
68
- * Locals kept from an earlier opening, by top-level key, shown from the
69
- * first render on (`./persist.ts`). Read once, when the renderer mounts.
74
+ * Locals kept from an earlier opening, by runtime id (`runtimeIdOf`), shown
75
+ * from the first render on (`./persist.ts`). Read once, when the renderer mounts.
70
76
  */
71
77
  keptValues?: Record<string, unknown>;
72
- /** The top-level keys kept between openings: swapping the payload leaves their values alone. */
73
- keptRoots?: ReadonlySet<string>;
78
+ /** The `<local>` node ids kept between openings: swapping the payload leaves their values alone. */
79
+ keptLocals?: ReadonlySet<string>;
74
80
  /** Source statuses known before the first render, by data-model path (`deps.robot.arm`: pending). */
75
81
  statuses?: Readonly<Record<string, BlokSourceStatus>>;
76
82
  /** The moment the blok shows while travelling (ISO 8601): commands and toasts are off, inputs read-only. */
77
83
  travelAt?: string | null;
78
84
  /** Who is looking: `viewer`. */
79
85
  viewer?: BlokViewer | null;
80
- /** The blok's declared reads, and how they run; a preview runs none (it seeds `demo.queries`). */
86
+ /**
87
+ * The blok's reads, and how they run; a preview runs none (it seeds
88
+ * `demo.queries`). Left out, the tree's `<query>` and `<subscription>`
89
+ * children (`treeQueries`).
90
+ */
81
91
  queries?: readonly BlokQuery[];
82
92
  subscriptions?: readonly BlokSubscription[];
83
93
  readExecutor?: BlokReadExecutor;
@@ -107,14 +117,21 @@ const EmbeddedNodeError = ({componentId, title, detail}: BlokNodeErrorProps) =>
107
117
  <EmbeddedNotice title={title} detail={detail ? `${detail} (${componentId})` : componentId} />
108
118
  );
109
119
 
110
- /** The roots of a blok shown in a scene that is already open. Only a root that opens a scene can stand in one. */
120
+ /** What a root draws: a `<Blok>`'s one element (its first drawn child), any other root itself. */
121
+ const drawnRoot = (tree: BlokTree, rootId: string): string | undefined => {
122
+ const node = tree.nodes.get(rootId)?.node;
123
+ if (node?.component !== 'Blok') return node?.component;
124
+ return drawnChildren(node)[0]?.component;
125
+ };
126
+
127
+ /** The roots of a blok shown in a scene that is already open. Only a blok that opens a scene can stand in one. */
111
128
  const EmbeddedRoots = ({tree, rootIds, errors}: {tree: BlokTree; rootIds: string[]; errors: string[]}) => (
112
129
  <>
113
130
  {errors.map(error => (
114
131
  <EmbeddedNotice key={error} title="Blok payload could not be parsed" detail={error} />
115
132
  ))}
116
133
  {rootIds.map(rootId => {
117
- const component = tree.nodes.get(rootId)?.component;
134
+ const component = drawnRoot(tree, rootId);
118
135
  const opensScene =
119
136
  !component || tree.catalog.components.get(component)?.placement?.childrenContext === 'scene';
120
137
  return opensScene ? (
@@ -142,12 +159,12 @@ export default function BlokRenderer({
142
159
  embedded = false,
143
160
  debug = false,
144
161
  keptValues,
145
- keptRoots,
162
+ keptLocals,
146
163
  statuses,
147
164
  travelAt = null,
148
165
  viewer = null,
149
- queries = NO_QUERIES,
150
- subscriptions = NO_SUBSCRIPTIONS,
166
+ queries: givenQueries,
167
+ subscriptions: givenSubscriptions,
151
168
  readExecutor,
152
169
  answerTask,
153
170
  startRun,
@@ -162,6 +179,18 @@ export default function BlokRenderer({
162
179
  [catalog, uiComponents],
163
180
  );
164
181
 
182
+ const roots = useMemo(
183
+ () => normalizeBlokComponentTree(Array.isArray(uiComponents) ? uiComponents : uiComponents ? [uiComponents] : null).roots,
184
+ [uiComponents],
185
+ );
186
+ const queries = useMemo(() => givenQueries ?? (roots.length === 1 ? treeQueries(roots[0]) : NO_QUERIES), [givenQueries, roots]);
187
+ const subscriptions = useMemo(
188
+ () => givenSubscriptions ?? (roots.length === 1 ? treeSubscriptions(roots[0]) : NO_SUBSCRIPTIONS),
189
+ [givenSubscriptions, roots],
190
+ );
191
+
192
+ const rootLocals = useMemo(() => (roots.length === 1 ? localChildren(roots[0] as BlokComponentNode) : []), [roots]);
193
+
165
194
  const tree = useMemo<BlokTree>(
166
195
  () => ({
167
196
  catalog,
@@ -201,7 +230,7 @@ export default function BlokRenderer({
201
230
  unavailableDependencies,
202
231
  lockedActions,
203
232
  keptValues,
204
- keptRoots,
233
+ keptLocals,
205
234
  statuses: unboundDependencies?.length ? {...statuses, ...unboundDependencyStatuses(unboundDependencies)} : statuses,
206
235
  travelAt,
207
236
  answerTask,
@@ -239,8 +268,8 @@ export default function BlokRenderer({
239
268
  }, [controlTask, runtimeStore]);
240
269
 
241
270
  useEffect(() => {
242
- if (keptRoots) runtimeStore.getState().setKeptRoots(keptRoots);
243
- }, [keptRoots, runtimeStore]);
271
+ if (keptLocals) runtimeStore.getState().setKeptLocals(keptLocals);
272
+ }, [keptLocals, runtimeStore]);
244
273
 
245
274
  useEffect(() => {
246
275
  runtimeStore.getState().setInitialDataModel(initialState);
@@ -303,11 +332,14 @@ export default function BlokRenderer({
303
332
  const containerRef = useRef<HTMLDivElement>(null);
304
333
  useBlokTailwind(preflight.nodes, embedded ? undefined : containerRef);
305
334
 
335
+ // A query's variables read the blok-level locals: the <Blok>'s own.
306
336
  const syncs = (
307
337
  <>
308
338
  <BlokViewerSync viewer={viewer} />
309
339
  {readExecutor && (queries.length > 0 || subscriptions.length > 0) ? (
310
- <BlokReads queries={queries} subscriptions={subscriptions} executor={readExecutor} />
340
+ <BlokLocalsScope locals={rootLocals}>
341
+ <BlokReads queries={queries} subscriptions={subscriptions} executor={readExecutor} />
342
+ </BlokLocalsScope>
311
343
  ) : null}
312
344
  </>
313
345
  );
@@ -9,7 +9,7 @@ import { createBlokCatalog, createBlokComponent } from "./runtime";
9
9
 
10
10
  const part = (name: string) => createBlokComponent({ name, schema: z.object({}) }, () => null);
11
11
  /** A component of the base catalog, as `implementBlokCatalog` tags one of its families'. */
12
- const base = (name: string) => ({ ...part(name), origin: "base@3" });
12
+ const base = (name: string) => ({ ...part(name), origin: "base@4" });
13
13
 
14
14
  describe("addBlokComponents", () => {
15
15
  it("adds a module's components and takes them back out", () => {
@@ -5,12 +5,12 @@ import {createBlokCatalog, type BlokCatalog} from './runtime';
5
5
  * The part of the base catalog the renderer itself draws, whatever toolkit
6
6
  * draws the rest: the language's elements (`if`/`else`, `foreach`,
7
7
  * `match`/`case`/`default`, `fragment`, `suspense`/`fallback`/`error`, the
8
- * context root `Html`, text) and the parts of a host's interface a blok may
8
+ * the `Blok` element, the declarations, text) and the parts of a host's interface a blok may
9
9
  * place (`ask`, `args`, `timeline`, ...), which the host supplies. Its
10
10
  * functions are the vocabulary's (`functions/v2`), evaluated by the renderer.
11
11
  */
12
12
  export const BASE_CATALOG_NAME = 'base';
13
- export const BASE_CATALOG_VERSION = 3;
13
+ export const BASE_CATALOG_VERSION = 4;
14
14
  export const BASE_CATALOG_ID = `${BASE_CATALOG_NAME}@${BASE_CATALOG_VERSION}`;
15
15
 
16
16
  export const baseBlokCatalog: BlokCatalog = createBlokCatalog(BASE_CATALOG_ID, controlBlokComponents);
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import * as z from 'zod';
3
3
  import {
4
+ BlokItemKeyProvider,
4
5
  BlokScopeProvider,
5
6
  BlokSuspenseContext,
6
7
  createBlokComponent,
@@ -16,6 +17,7 @@ import {
16
17
  type BlokComponentNode,
17
18
  type BlokSourceStatus,
18
19
  type BlokScope,
20
+ type BlokObjectSchema,
19
21
  type BlokSuspenseReporter,
20
22
  } from '../runtime';
21
23
  import {useBlokRunHost} from './run/host';
@@ -53,6 +55,8 @@ const renderDeclaredChildren = (component: BlokComponentNode, buildChild: (id: s
53
55
  /* -------------------------------------------------------------------------- */
54
56
 
55
57
  const ForeachIteration = (props: {
58
+ /** The item's key, as its runtime ids carry it (`7`, `#2`). */
59
+ itemKey: string;
56
60
  scopeName: string;
57
61
  /** Absolute path of this item, when the items came from a data binding. */
58
62
  itemPath?: string;
@@ -61,7 +65,7 @@ const ForeachIteration = (props: {
61
65
  childIds: string[];
62
66
  buildChild: (id: string, basePath?: string) => React.ReactNode;
63
67
  }) => {
64
- const {buildChild, childIds, item, itemPath, scopeName} = props;
68
+ const {buildChild, childIds, item, itemKey, itemPath, scopeName} = props;
65
69
 
66
70
  // A path-backed item aliases to its path, so a bound control inside the loop
67
71
  // writes the real backing list. Without a path the item is handed down by value.
@@ -69,11 +73,13 @@ const ForeachIteration = (props: {
69
73
  const values = React.useMemo(() => (itemPath ? undefined : {[scopeName]: item}), [item, itemPath, scopeName]);
70
74
 
71
75
  return (
72
- <BlokScopeProvider aliases={aliases} values={values}>
73
- {childIds.map(childId => (
74
- <React.Fragment key={childId}>{buildChild(childId)}</React.Fragment>
75
- ))}
76
- </BlokScopeProvider>
76
+ <BlokItemKeyProvider itemKey={itemKey}>
77
+ <BlokScopeProvider aliases={aliases} values={values}>
78
+ {childIds.map(childId => (
79
+ <React.Fragment key={childId}>{buildChild(childId)}</React.Fragment>
80
+ ))}
81
+ </BlokScopeProvider>
82
+ </BlokItemKeyProvider>
77
83
  );
78
84
  };
79
85
 
@@ -155,6 +161,7 @@ export const Foreach = createBlokComponent(
155
161
  return (
156
162
  <ForeachIteration
157
163
  key={ids[index]}
164
+ itemKey={ids[index].slice(component.id.length + 1)}
158
165
  scopeName={scopeName}
159
166
  itemPath={itemPath(index)}
160
167
  item={item}
@@ -253,24 +260,116 @@ export const Fragment = createBlokComponent(
253
260
  ({buildChild, component}) => renderDeclaredChildren(component, buildChild),
254
261
  );
255
262
 
256
- /** What the host adds around a blok; read by the host off the root, the blok itself draws the same either way. */
263
+ /** What the host adds around a blok; read by the host off its `<Blok>`, the blok itself draws the same either way. */
257
264
  export const chromeSchema = z
258
265
  .enum(['auto', 'none'])
259
266
  .optional()
260
267
  .describe(
261
- "What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
268
+ "What the host draws around the blok of its own (panel and scene): `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
262
269
  );
263
270
 
264
- export const Html = createBlokComponent(
271
+ const BLOK_COMPONENT = 'Blok';
272
+ const DECLARATIONS: ReadonlySet<string> = new Set(['local', 'query', 'subscription', 'var']);
273
+
274
+ /** The children of a node that draw: its declarations (`local`, `query`, `subscription`, `var`) left out. */
275
+ export const drawnChildren = (component: BlokComponentNode): BlokComponentNode[] =>
276
+ (component.children ?? []).filter(child => !DECLARATIONS.has(child.component));
277
+
278
+ /**
279
+ * The one element every blok is (vocabulary `blok`). In a panel it lays its
280
+ * children out as a fragment does; in a scene or a logo it draws its one
281
+ * element (a `Scene` or `Space`, a `Logo`). Its declarations draw nothing.
282
+ */
283
+ export const Blok = createBlokComponent(
265
284
  {
266
- name: 'Html',
285
+ name: BLOK_COMPONENT,
267
286
  acceptsChildren: true,
268
- placement: {childrenContext: 'html', notDownstreamOf: ['Html']},
287
+ placement: {notDownstreamOf: [BLOK_COMPONENT]},
269
288
  schema: z
270
- .object({chrome: chromeSchema})
271
- .describe("The root of an html blok (a panel, a dashboard, a popout's page): lays its children out as a fragment does, and names the blok's context."),
289
+ .object({
290
+ kind: z.enum(['agent', 'custom', 'task', 'action', 'assign']).describe('What the blok is: what it reads, and where it may be mounted.'),
291
+ context: z
292
+ .enum(['panel', 'scene', 'logo'])
293
+ .describe('What draws it: a panel (a flat rectangle the host lays out), a scene (a 3D view) or a logo (an SVG drawing).'),
294
+ catalog: z
295
+ .string()
296
+ .optional()
297
+ .describe('The catalog it is written for (the address it is published at, or the name of one registered in the organization); the base catalog when left out.'),
298
+ chrome: chromeSchema,
299
+ })
300
+ .describe(
301
+ "Every blok is one: it says its kind (what it reads, where it may be mounted), its context (what host draws it), the catalog it is written for and the host's chrome. A panel lays its children out as a fragment does; a scene holds one Scene or Space, a logo one Logo, besides its declarations.",
302
+ ),
272
303
  },
273
- ({buildChild, component}) => renderDeclaredChildren(component, buildChild),
304
+ ({buildChild, component}) => {
305
+ const context = component.props?.find(prop => prop.key === 'context')?.static_value;
306
+ const drawn = drawnChildren(component);
307
+ return renderNodes(context === 'scene' || context === 'logo' ? drawn.slice(0, 1) : drawn, buildChild);
308
+ },
309
+ );
310
+
311
+ const declaration = <T extends BlokObjectSchema>(name: string, schema: T, acceptsChildren = false) =>
312
+ createBlokComponent({name, acceptsChildren, placement: {inheritsContext: true}, schema}, () => null);
313
+
314
+ /** `<local name="x" default={...} persist />`: draws nothing; its parent provides it to its children (`runtime/locals`). */
315
+ export const Local = declaration(
316
+ 'local',
317
+ z
318
+ .object({
319
+ name: z.string().describe("The name the subtree reads it by, bare (never a reserved root)."),
320
+ default: z.unknown().optional().describe('The value it starts with: a literal.'),
321
+ kind: z.string().optional().describe('Its port kind (INT, FLOAT, STRING, BOOL, ENUM, DATE, QUANTITY, LIST, DICT, MODEL, STRUCTURE, ...) or ANY; inferred when left out.'),
322
+ identifier: z.string().optional().describe("A structure local's identifier (@mikro/image)."),
323
+ nullable: z.boolean().optional().describe('Whether it may be null.'),
324
+ choices: z.unknown().optional().describe("An ENUM local's choices: [{value, label}, ...]."),
325
+ children: z.unknown().optional().describe("A LIST, DICT or MODEL local's child ports, as ports."),
326
+ label: z.string().optional().describe('What a form shows it as.'),
327
+ description: z.string().optional().describe('What it is for.'),
328
+ persist: z.boolean().optional().describe('Remember the last input on this device (never on a server).'),
329
+ like: z.string().optional().describe("Take the port of an action's argument: self.<action>.<arg> or deps.<key>.<action>.<arg>."),
330
+ })
331
+ .describe("Declares a local: form state controls write through bind, read bare in its parent's subtree; inside a foreach, one per item. It comes first among its parent's children and draws nothing."),
332
+ );
333
+
334
+ /** `<query name service document>`: draws nothing; the host runs it (`declaredQueries`). */
335
+ export const Query = declaration(
336
+ 'query',
337
+ z
338
+ .object({
339
+ name: z.string().describe('Its name: read as queries.<name>.'),
340
+ service: z.string().describe('The service it runs on, by key (mikro).'),
341
+ document: z.string().describe('One GraphQL query operation, never a mutation.'),
342
+ poll: z.number().optional().describe('Also re-run every this many seconds.'),
343
+ more: z.string().optional().describe('The list field of its result new pages append to (queries.<name>.fetch_more).'),
344
+ })
345
+ .describe('Declares a read, queries.<name>: one GraphQL query on a service, re-run when its variables (its <var> children) change. A child of <Blok>; draws nothing.'),
346
+ true,
347
+ );
348
+
349
+ /** `<subscription name service document>`: draws nothing; the host runs it (`declaredSubscriptions`). */
350
+ export const Subscription = declaration(
351
+ 'subscription',
352
+ z
353
+ .object({
354
+ name: z.string().describe('Its name: read as subscriptions.<name>.'),
355
+ service: z.string().describe('The service it runs on, by key.'),
356
+ document: z.string().describe('One GraphQL subscription operation.'),
357
+ keep: z.number().optional().describe('Keep the last this many payloads as a list; the latest only when absent.'),
358
+ history: z.string().optional().describe('A declared query to replay from while travelling.'),
359
+ })
360
+ .describe('Declares a stream, subscriptions.<name>: one GraphQL subscription on a service, re-subscribed when its variables (its <var> children) change. A child of <Blok>; draws nothing.'),
361
+ true,
362
+ );
363
+
364
+ /** `<var key value>`: one variable of its query or subscription. */
365
+ export const Var = declaration(
366
+ 'var',
367
+ z
368
+ .object({
369
+ key: z.string().describe("The variable's name in the document."),
370
+ value: z.unknown().optional().describe('Its value.'),
371
+ })
372
+ .describe('One variable of its query or subscription: an expression over args, blok-level locals and agents, or a literal.'),
274
373
  );
275
374
 
276
375
  /* -------------------------------------------------------------------------- */
@@ -358,7 +457,7 @@ const DomHidden = ({hidden, children}: {hidden: boolean; children?: React.ReactN
358
457
  /** Outside html (a scene, a logo) nothing can hold a box: hidden is not drawn. In html, the platform's (a native view), or a DOM `div`. */
359
458
  const Hidden = ({hidden, children}: {hidden: boolean; children: React.ReactNode}) => {
360
459
  const draw = useBlokDrawContext();
361
- if (draw !== 'html') return hidden ? null : <>{children}</>;
460
+ if (draw !== 'panel') return hidden ? null : <>{children}</>;
362
461
  const Primitive = blokPlatform().primitives.Hidden ?? DomHidden;
363
462
  return <Primitive hidden={hidden}>{children}</Primitive>;
364
463
  };
@@ -560,7 +659,11 @@ export const controlBlokComponents = [
560
659
  If,
561
660
  Else,
562
661
  Fragment,
563
- Html,
662
+ Blok,
663
+ Local,
664
+ Query,
665
+ Subscription,
666
+ Var,
564
667
  Match,
565
668
  Case,
566
669
  Default,
@@ -146,7 +146,7 @@ const SvgNodeError = ({componentId, title, detail}: BlokNodeErrorProps) => (
146
146
  );
147
147
 
148
148
  /** A drawing's root: an `<svg>` whose shapes paint with the pens. */
149
- const LogoRootRender: BlokRender<Contracts['AgentLogo']> = args => {
149
+ const LogoRootRender: BlokRender<Contracts['Logo']> = args => {
150
150
  const blok = useBlok(args.component, args.schema);
151
151
  const viewBox = useValue(blok.viewBox);
152
152
  const width = useValue(blok.width);
@@ -267,8 +267,7 @@ const ClipPathRender: BlokRender<Contracts['ClipPath']> = args => {
267
267
 
268
268
  /** The `logo` family: the root, seven shapes, text, and what shapes reference. */
269
269
  export const logoRenders = {
270
- AgentLogo: LogoRootRender,
271
- ActionLogo: LogoRootRender,
270
+ Logo: LogoRootRender,
272
271
  Path: shapeRender('path', shapeGeometry.Path),
273
272
  Circle: shapeRender('circle', shapeGeometry.Circle),
274
273
  Ellipse: shapeRender('ellipse', shapeGeometry.Ellipse),