@arkitektio/bsx 5.0.0 → 6.1.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 (230) 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 +16 -6
  71. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  72. package/dist/renderer/BlokRenderer.js +32 -13
  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/Scene.d.ts.map +1 -1
  97. package/dist/renderer/bloks/scene/Scene.js +4 -2
  98. package/dist/renderer/bloks/scene/Scene.js.map +1 -1
  99. package/dist/renderer/bloks/scene/host.d.ts +2 -0
  100. package/dist/renderer/bloks/scene/host.d.ts.map +1 -1
  101. package/dist/renderer/bloks/scene/host.js +8 -0
  102. package/dist/renderer/bloks/scene/host.js.map +1 -1
  103. package/dist/renderer/bloks/scene/index.d.ts +4 -8
  104. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  105. package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
  106. package/dist/renderer/bloks/scene/interaction.js +3 -2
  107. package/dist/renderer/bloks/scene/interaction.js.map +1 -1
  108. package/dist/renderer/bloks/shared/props.d.ts +2 -2
  109. package/dist/renderer/bloks/typography.d.ts +3 -3
  110. package/dist/renderer/declarations.d.ts +40 -33
  111. package/dist/renderer/declarations.d.ts.map +1 -1
  112. package/dist/renderer/declarations.js +41 -56
  113. package/dist/renderer/declarations.js.map +1 -1
  114. package/dist/renderer/declare.js +4 -4
  115. package/dist/renderer/declare.js.map +1 -1
  116. package/dist/renderer/persist.d.ts +22 -13
  117. package/dist/renderer/persist.d.ts.map +1 -1
  118. package/dist/renderer/persist.js +40 -21
  119. package/dist/renderer/persist.js.map +1 -1
  120. package/dist/renderer/runtime/catalog.d.ts +4 -4
  121. package/dist/renderer/runtime/catalog.js +3 -3
  122. package/dist/renderer/runtime/components.d.ts +4 -4
  123. package/dist/renderer/runtime/components.d.ts.map +1 -1
  124. package/dist/renderer/runtime/components.js +5 -5
  125. package/dist/renderer/runtime/components.js.map +1 -1
  126. package/dist/renderer/runtime/context.d.ts +5 -5
  127. package/dist/renderer/runtime/context.d.ts.map +1 -1
  128. package/dist/renderer/runtime/context.js +11 -5
  129. package/dist/renderer/runtime/context.js.map +1 -1
  130. package/dist/renderer/runtime/describe.d.ts +3 -3
  131. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  132. package/dist/renderer/runtime/describe.js +2 -2
  133. package/dist/renderer/runtime/describe.js.map +1 -1
  134. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  135. package/dist/renderer/runtime/hooks.js +8 -4
  136. package/dist/renderer/runtime/hooks.js.map +1 -1
  137. package/dist/renderer/runtime/index.d.ts +1 -0
  138. package/dist/renderer/runtime/index.d.ts.map +1 -1
  139. package/dist/renderer/runtime/index.js +1 -0
  140. package/dist/renderer/runtime/index.js.map +1 -1
  141. package/dist/renderer/runtime/locals.d.ts +57 -0
  142. package/dist/renderer/runtime/locals.d.ts.map +1 -0
  143. package/dist/renderer/runtime/locals.js +87 -0
  144. package/dist/renderer/runtime/locals.js.map +1 -0
  145. package/dist/renderer/runtime/scope.d.ts +14 -0
  146. package/dist/renderer/runtime/scope.d.ts.map +1 -1
  147. package/dist/renderer/runtime/scope.js +25 -3
  148. package/dist/renderer/runtime/scope.js.map +1 -1
  149. package/dist/renderer/runtime/tree.d.ts.map +1 -1
  150. package/dist/renderer/runtime/tree.js +7 -1
  151. package/dist/renderer/runtime/tree.js.map +1 -1
  152. package/dist/renderer/runtime/types.d.ts +8 -3
  153. package/dist/renderer/runtime/types.d.ts.map +1 -1
  154. package/dist/shadcn.d.ts +36 -43
  155. package/dist/shadcn.d.ts.map +1 -1
  156. package/dist/shadcn.js +1 -2
  157. package/dist/shadcn.js.map +1 -1
  158. package/dist/spec/bsx_v2.json +11067 -6321
  159. package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
  160. package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
  161. package/dist/spec/catalogs/orkestrator@1.json +10 -10
  162. package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
  163. package/dist/spec/catalogs.d.ts +4 -4
  164. package/dist/spec/catalogs.d.ts.map +1 -1
  165. package/dist/spec/catalogs.js +7 -7
  166. package/dist/spec/catalogs.js.map +1 -1
  167. package/dist/spec/vocabulary.d.ts +25 -4
  168. package/dist/spec/vocabulary.d.ts.map +1 -1
  169. package/dist/spec/vocabulary.js +50 -5
  170. package/dist/spec/vocabulary.js.map +1 -1
  171. package/dist/spec/vocabulary.json +58 -32
  172. package/dist/spec/vocabulary.json.js +58 -32
  173. package/package.json +1 -1
  174. package/src/bsx/analyze.ts +14 -12
  175. package/src/bsx/bsx.test.ts +4 -4
  176. package/src/bsx/declared.ts +346 -0
  177. package/src/bsx/index.ts +1 -0
  178. package/src/bsx/infer.test.ts +42 -32
  179. package/src/bsx/infer.ts +128 -71
  180. package/src/bsx/language.test.ts +37 -25
  181. package/src/bsx/language.ts +72 -25
  182. package/src/bsx/parse.ts +34 -3
  183. package/src/bsx/print.ts +3 -0
  184. package/src/bsx/references.test.ts +82 -81
  185. package/src/bsx/references.ts +313 -178
  186. package/src/catalogs/catalogs.test.ts +3 -2
  187. package/src/catalogs/index.ts +1 -1
  188. package/src/catalogs/logo.ts +1 -2
  189. package/src/catalogs/parts/logo.ts +13 -17
  190. package/src/catalogs/parts/scene.ts +1 -7
  191. package/src/logo/actionLogoSource.ts +4 -4
  192. package/src/renderer/BlokComponentHost.test.tsx +5 -5
  193. package/src/renderer/BlokRenderer.test.tsx +22 -0
  194. package/src/renderer/BlokRenderer.tsx +70 -20
  195. package/src/renderer/addBlokComponents.test.tsx +1 -1
  196. package/src/renderer/baseCatalog.ts +2 -2
  197. package/src/renderer/bloks/control.tsx +119 -16
  198. package/src/renderer/bloks/logo/index.tsx +2 -3
  199. package/src/renderer/bloks/logo/logo.fixture.json +266 -250
  200. package/src/renderer/bloks/logo/logo.test.tsx +18 -7
  201. package/src/renderer/bloks/run/space.test.tsx +12 -4
  202. package/src/renderer/bloks/scene/Scene.tsx +4 -2
  203. package/src/renderer/bloks/scene/host.tsx +11 -0
  204. package/src/renderer/bloks/scene/interaction.tsx +11 -6
  205. package/src/renderer/bloks/scene/transform.test.ts +8 -7
  206. package/src/renderer/declarations.test.ts +38 -51
  207. package/src/renderer/declarations.ts +67 -88
  208. package/src/renderer/declare.test.ts +4 -4
  209. package/src/renderer/declare.ts +4 -4
  210. package/src/renderer/persist.test.ts +70 -49
  211. package/src/renderer/persist.ts +57 -34
  212. package/src/renderer/runtime/catalog.test.ts +2 -2
  213. package/src/renderer/runtime/catalog.ts +4 -4
  214. package/src/renderer/runtime/components.tsx +8 -8
  215. package/src/renderer/runtime/context.tsx +17 -10
  216. package/src/renderer/runtime/describe.ts +5 -5
  217. package/src/renderer/runtime/hooks.ts +6 -4
  218. package/src/renderer/runtime/index.ts +1 -0
  219. package/src/renderer/runtime/locals.tsx +105 -0
  220. package/src/renderer/runtime/scope.tsx +31 -3
  221. package/src/renderer/runtime/tree.tsx +16 -4
  222. package/src/renderer/runtime/types.ts +8 -3
  223. package/src/shadcn.ts +1 -2
  224. package/src/spec/bsx_v2.json +11067 -6321
  225. package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
  226. package/src/spec/catalogs/orkestrator@1.json +10 -10
  227. package/src/spec/catalogs.ts +8 -8
  228. package/src/spec/spec.test.ts +19 -16
  229. package/src/spec/vocabulary.json +58 -32
  230. package/src/spec/vocabulary.ts +69 -10
@@ -0,0 +1,105 @@
1
+ import * as React from 'react';
2
+ import {runtimeIdOf, nodeOfRuntimeId} from '../../bsx/declared';
3
+
4
+ export {runtimeIdOf, nodeOfRuntimeId};
5
+ import {BlokScopeProvider} from './scope';
6
+ import type {BlokComponentNode} from './types';
7
+ import {splitPathSegments} from './utils';
8
+
9
+ /**
10
+ * Where a blok's `<local>` values live while it is open (blok language v2
11
+ * `locals.scope`).
12
+ *
13
+ * A `<local>` is in scope in its parent's subtree. Its value lives in the one
14
+ * runtime store under its *runtime id*: its node id plus one `@<item key>` per
15
+ * enclosing `foreach`, outermost first (`runtimeIdOf`), so inside a foreach
16
+ * every item has a value of its own. The value sits at `$locals/<runtime id,
17
+ * encoded as one path segment>`: a root no name a blok writes can be (`into`
18
+ * names are identifiers). It outlives an `if` branch closing, as long as the
19
+ * blok stays open. Until something writes it, it reads its default.
20
+ *
21
+ * When a node renders its children, its `local` children are provided to them
22
+ * as scope aliases `{name → that local's path}` (`BlokLocalsScope`); a bound
23
+ * control writes through the alias.
24
+ */
25
+
26
+ /** The data-model root every local's value lives under. */
27
+ export const LOCALS_ROOT = '$locals';
28
+
29
+ /** One path segment for a runtime id: `/` and `.` would split it. */
30
+ const encodeSegment = (runtimeId: string): string => encodeURIComponent(runtimeId).replace(/\./g, '%2E');
31
+
32
+ /** The data-model path of the value of the local whose runtime id is `runtimeId`. */
33
+ export const localValuePath = (runtimeId: string): string => `${LOCALS_ROOT}/${encodeSegment(runtimeId)}`;
34
+
35
+ /** The runtime id of the local whose value `path` is (or is below), or null when it is no local's. */
36
+ export const runtimeIdOfPath = (path: string): string | null => {
37
+ const [root, segment] = splitPathSegments(path);
38
+ if (root !== LOCALS_ROOT || segment === undefined) return null;
39
+ try {
40
+ return decodeURIComponent(segment);
41
+ } catch {
42
+ return null;
43
+ }
44
+ };
45
+
46
+ /** The `<local>` node a runtime path value belongs to, or null when it is no local's. */
47
+ export const localNodeOfPath = (path: string): string | null => {
48
+ const runtimeId = runtimeIdOfPath(path);
49
+ return runtimeId === null ? null : nodeOfRuntimeId(runtimeId);
50
+ };
51
+
52
+ const NO_KEYS: readonly string[] = Object.freeze([]);
53
+ const BlokItemKeysContext = React.createContext<readonly string[]>(NO_KEYS);
54
+
55
+ /** The item keys of the foreach items this subtree is inside, outermost first (`7`, `#2`). */
56
+ export const useBlokItemKeys = (): readonly string[] => React.useContext(BlokItemKeysContext);
57
+
58
+ /** A subtree inside one more foreach item: `key` is the item's (`foreachItemIds` without the foreach's id and `@`). */
59
+ export const BlokItemKeyProvider = ({itemKey, children}: {itemKey: string; children: React.ReactNode}) => {
60
+ const outer = React.useContext(BlokItemKeysContext);
61
+ const keys = React.useMemo(() => [...outer, itemKey], [outer, itemKey]);
62
+ return <BlokItemKeysContext.Provider value={keys}>{children}</BlokItemKeysContext.Provider>;
63
+ };
64
+
65
+ /** Passes the item keys through a boundary that drops React context (a scene's portal). */
66
+ export const BlokItemKeysBridge = ({keys, children}: {keys: readonly string[]; children: React.ReactNode}) => (
67
+ <BlokItemKeysContext.Provider value={keys}>{children}</BlokItemKeysContext.Provider>
68
+ );
69
+
70
+ /** A `<local>` child as the renderer provides it: its node, the name it is read by, and its default. */
71
+ export type BlokLocalDeclaration = {node: string; name: string; default: unknown};
72
+
73
+ /** The `<local>` children of `node`, each with its name and default (a literal); one without a name is skipped. */
74
+ export const localChildren = (node: BlokComponentNode): BlokLocalDeclaration[] =>
75
+ (node.children ?? []).flatMap(child => {
76
+ if (child.component !== 'local') return [];
77
+ const name = child.props?.find(prop => prop.key === 'name');
78
+ const declared = name?.declares_value ?? (typeof name?.static_value === 'string' ? name.static_value : null);
79
+ if (!declared) return [];
80
+ const fallback = child.props?.find(prop => prop.key === 'default')?.static_value;
81
+ return [{node: child.id, name: declared, default: fallback ?? null}];
82
+ });
83
+
84
+ /**
85
+ * Provides a node's locals to its children: each name aliased to the path of
86
+ * its value here (in this foreach item), reading its default until written.
87
+ */
88
+ export const BlokLocalsScope = ({locals, children}: {locals: readonly BlokLocalDeclaration[]; children: React.ReactNode}) => {
89
+ const keys = useBlokItemKeys();
90
+ const {aliases, defaults} = React.useMemo(() => {
91
+ const aliases: Record<string, string> = {};
92
+ const defaults: Record<string, unknown> = {};
93
+ for (const local of locals) {
94
+ const path = localValuePath(runtimeIdOf(local.node, keys));
95
+ aliases[local.name] = path;
96
+ defaults[path] = local.default;
97
+ }
98
+ return {aliases, defaults};
99
+ }, [keys, locals]);
100
+ return (
101
+ <BlokScopeProvider aliases={aliases} defaults={defaults}>
102
+ {children}
103
+ </BlokScopeProvider>
104
+ );
105
+ };
@@ -26,13 +26,15 @@ export const BlokScopeProvider = (props: {
26
26
  aliases?: Readonly<Record<string, string>>;
27
27
  values?: Readonly<Record<string, unknown>>;
28
28
  basePath?: string;
29
+ /** What an alias reads before anything was written at its path, by the alias' absolute path (a `<local>`'s default). */
30
+ defaults?: Readonly<Record<string, unknown>>;
29
31
  children: React.ReactNode;
30
32
  }) => {
31
- const {aliases, values, basePath, children} = props;
33
+ const {aliases, values, basePath, defaults, children} = props;
32
34
  const parentScope = React.useContext(BlokScopeContext);
33
35
 
34
36
  const scope = React.useMemo<BlokScope>(() => {
35
- if (!aliases && !values && basePath === undefined) {
37
+ if (!aliases && !values && basePath === undefined && !defaults) {
36
38
  return parentScope;
37
39
  }
38
40
 
@@ -40,8 +42,9 @@ export const BlokScopeProvider = (props: {
40
42
  aliases: aliases ? {...parentScope.aliases, ...aliases} : parentScope.aliases,
41
43
  values: values ? {...parentScope.values, ...values} : parentScope.values,
42
44
  basePath: basePath ?? parentScope.basePath,
45
+ defaults: defaults ? {...parentScope.defaults, ...defaults} : parentScope.defaults,
43
46
  };
44
- }, [aliases, basePath, parentScope, values]);
47
+ }, [aliases, basePath, defaults, parentScope, values]);
45
48
 
46
49
  return <BlokScopeContext.Provider value={scope}>{children}</BlokScopeContext.Provider>;
47
50
  };
@@ -107,9 +110,34 @@ export const readScopedPath = (
107
110
  return getValueAtPath(scope.values[head], tail.join('/'));
108
111
  }
109
112
 
113
+ const aliased = head ? scope.aliases[head] : undefined;
114
+ if (aliased !== undefined && scope.defaults && aliased in scope.defaults && getValueAtPath(dataModel, aliased) === undefined) {
115
+ // Nothing written at the alias yet (a local before its first input): it reads its default.
116
+ return getValueAtPath(scope.defaults[aliased], tail.join('/'));
117
+ }
118
+
110
119
  return getValueAtPath(dataModel, resolveScopedPath(path, scope));
111
120
  };
112
121
 
122
+ /**
123
+ * Where a write of `path` lands, and what to write first so it lands on the
124
+ * value it was read as: a write below an alias that still reads its default
125
+ * (`bind={p.x}` on a dict local) seeds the default at the alias first.
126
+ */
127
+ export const scopedWrite = (
128
+ dataModel: unknown,
129
+ path: string,
130
+ scope: BlokScope,
131
+ ): {path: string; seed: {path: string; value: unknown} | null} => {
132
+ const [head, ...tail] = splitPathSegments(path);
133
+ const aliased = head ? scope.aliases[head] : undefined;
134
+ const absolute = resolveScopedPath(path, scope);
135
+ if (aliased === undefined || tail.length === 0 || !scope.defaults || !(aliased in scope.defaults)) return {path: absolute, seed: null};
136
+ if (getValueAtPath(dataModel, aliased) !== undefined) return {path: absolute, seed: null};
137
+ const value = scope.defaults[aliased];
138
+ return {path: absolute, seed: value === null || value === undefined ? null : {path: aliased, value: structuredClone(value)}};
139
+ };
140
+
113
141
  /** True when a path can be written back through the data model. */
114
142
  export const isWritableScopedPath = (path: string, scope: BlokScope): boolean => {
115
143
  const [head] = splitPathSegments(path);
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import {BlokComponentRenderer, BlokNodeError} from './components';
3
3
  import type {BlokCatalog} from './functions';
4
+ import {BlokLocalsScope, localChildren} from './locals';
4
5
  import {BlokScopeProvider} from './scope';
5
6
  import type {BlokComponentNode} from './types';
6
7
 
@@ -64,13 +65,24 @@ const BlokNodeInner = ({id, basePath}: BlokNodeProps) => {
64
65
 
65
66
  const nextTrail = React.useMemo(() => [...trail, id], [trail, id]);
66
67
 
68
+ // The node's `<local>` children are in scope in all of its children: each
69
+ // child is built inside them, so a child a foreach builds per item (inside
70
+ // the item's scope) gets the item's own values.
71
+ const node = tree.nodes.get(id)?.node;
72
+ const locals = React.useMemo(() => (node ? localChildren(node) : []), [node]);
73
+
67
74
  // `buildChild` never closes over the trail or the tree — a child reads both
68
75
  // from context — so its identity is stable for the life of the node.
69
76
  const buildChild = React.useCallback(
70
- (childId: string, childBasePath?: string) => (
71
- <BlokNode id={childId} basePath={childBasePath} />
72
- ),
73
- [],
77
+ (childId: string, childBasePath?: string) =>
78
+ locals.length ? (
79
+ <BlokLocalsScope locals={locals}>
80
+ <BlokNode id={childId} basePath={childBasePath} />
81
+ </BlokLocalsScope>
82
+ ) : (
83
+ <BlokNode id={childId} basePath={childBasePath} />
84
+ ),
85
+ [locals],
74
86
  );
75
87
 
76
88
  if (trail.includes(id)) {
@@ -194,6 +194,11 @@ export type BlokScope = {
194
194
  aliases: Readonly<Record<string, string>>;
195
195
  values: Readonly<Record<string, unknown>>;
196
196
  basePath?: string;
197
+ /**
198
+ * What an aliased path reads while nothing was written there yet, by the
199
+ * alias' absolute path: a `<local>`'s default (`runtime/locals`).
200
+ */
201
+ defaults?: Readonly<Record<string, unknown>>;
197
202
  };
198
203
 
199
204
  /**
@@ -236,8 +241,8 @@ export type BlokRuntimeContext = {
236
241
  initialDataModel: unknown;
237
242
  dataModel: unknown;
238
243
  runtimePathValues: Record<string, unknown>;
239
- /** Top-level keys whose runtime values a reset keeps: the locals the host keeps between openings. */
240
- keptRoots: ReadonlySet<string>;
244
+ /** The `<local>` node ids whose values a reset keeps (every item's, in a foreach): the locals the host keeps between openings. */
245
+ keptLocals: ReadonlySet<string>;
241
246
  /**
242
247
  * The status of each source, by the data-model path it is read under
243
248
  * (`deps.robot.arm`, `queries.cells.value`, `args`). A read below a path
@@ -271,7 +276,7 @@ export type BlokRuntimeContext = {
271
276
  lockedActions: BlokLockedActions;
272
277
  setInitialDataModel: (dataModel: unknown) => void;
273
278
  resetRuntimeValues: () => void;
274
- setKeptRoots: (roots: ReadonlySet<string>) => void;
279
+ setKeptLocals: (keptLocals: ReadonlySet<string>) => void;
275
280
  setRuntimeValue: (path: string, value: unknown) => void;
276
281
  clearRuntimeValue: (path: string) => void;
277
282
  setAgentMappingStateUpdates: (updates: BlokAgentMappingStateUpdates) => void;
package/src/shadcn.ts CHANGED
@@ -105,8 +105,6 @@ export const shadcnHtml = implementBlokCatalog(htmlCatalog, shadcnHtmlRenders);
105
105
 
106
106
  /** the logo family, drawn with shadcn/ui. */
107
107
  export const shadcnLogoRenders = {
108
- ActionLogo: domRenders.ActionLogo,
109
- AgentLogo: domRenders.AgentLogo,
110
108
  Circle: domRenders.Circle,
111
109
  ClipPath: domRenders.ClipPath,
112
110
  Defs: domRenders.Defs,
@@ -114,6 +112,7 @@ export const shadcnLogoRenders = {
114
112
  G: domRenders.G,
115
113
  Line: domRenders.Line,
116
114
  LinearGradient: domRenders.LinearGradient,
115
+ Logo: domRenders.Logo,
117
116
  Path: domRenders.Path,
118
117
  Polygon: domRenders.Polygon,
119
118
  Polyline: domRenders.Polyline,