@arkitektio/bsx 6.3.0 → 6.4.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.
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +4 -0
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.js +3 -3
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +1 -0
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +8 -1
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +2 -2
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +2 -0
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +19 -0
- package/dist/bsx/references.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +13 -5
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/spec/bsx_v2.json +235 -1
- package/dist/spec/catalogs/base@4.json +9 -2
- package/dist/spec/catalogs/base@4.json.js +9 -2
- package/dist/spec/vocabulary.json +7 -6
- package/dist/spec/vocabulary.json.js +7 -6
- package/package.json +1 -1
- package/src/bsx/infer.ts +4 -0
- package/src/bsx/language.ts +3 -3
- package/src/bsx/parse.ts +7 -1
- package/src/bsx/print.ts +2 -1
- package/src/bsx/references.ts +17 -0
- package/src/renderer/bloks/control.tsx +18 -4
- package/src/renderer/bloks/flow.test.tsx +11 -0
- package/src/spec/bsx_v2.json +235 -1
- package/src/spec/catalogs/base@4.json +9 -2
- package/src/spec/spec.test.ts +2 -2
- package/src/spec/vocabulary.json +7 -6
package/src/bsx/print.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
CLASSES_FUNCTION,
|
|
13
13
|
FETCH_MORE_FUNCTION,
|
|
14
14
|
FOREACH_COMPONENT,
|
|
15
|
+
FOREACH_INDEX_PROP,
|
|
15
16
|
FOREACH_LET_PROP,
|
|
16
17
|
LEGACY_IMPLICIT_TEXTS,
|
|
17
18
|
TEXT_NODE,
|
|
@@ -253,7 +254,7 @@ class Printer {
|
|
|
253
254
|
return `${key}={${this.agentCall(prop.agent_call)}${into}}`;
|
|
254
255
|
}
|
|
255
256
|
if (prop.declares_value != null) {
|
|
256
|
-
if (node.component === FOREACH_COMPONENT && key === FOREACH_LET_PROP && prop.static_value === prop.declares_value) {
|
|
257
|
+
if (node.component === FOREACH_COMPONENT && (key === FOREACH_LET_PROP || key === FOREACH_INDEX_PROP) && prop.static_value === prop.declares_value) {
|
|
257
258
|
return `${key}=${quoted(prop.declares_value)}`;
|
|
258
259
|
}
|
|
259
260
|
if (node.component === 'local' && key === 'name' && prop.static_value === prop.declares_value) {
|
package/src/bsx/references.ts
CHANGED
|
@@ -224,6 +224,7 @@ const TOAST_TASK_PROP = 'task';
|
|
|
224
224
|
const CLASS_NAME = 'className';
|
|
225
225
|
const FOREACH = 'foreach';
|
|
226
226
|
const FOREACH_LET = 'let';
|
|
227
|
+
const FOREACH_INDEX = 'index';
|
|
227
228
|
const FOREACH_ITEMS = 'items';
|
|
228
229
|
const FOREACH_KEY = 'key';
|
|
229
230
|
/** An item of these kinds is no scalar: a foreach over it without key is keyed by position (`foreach.position_key`). */
|
|
@@ -327,6 +328,11 @@ export const foreachLet = (node: BlokComponentNode): string | null => {
|
|
|
327
328
|
return node.props?.find(prop => prop.key === FOREACH_LET && prop.declares_value)?.declares_value ?? null;
|
|
328
329
|
};
|
|
329
330
|
|
|
331
|
+
/** The name a `foreach` gives each item's position (`index="i"`), or null when it names none. */
|
|
332
|
+
export const foreachIndex = (node: BlokComponentNode): string | null => {
|
|
333
|
+
if (node.component !== FOREACH) return null;
|
|
334
|
+
return node.props?.find(prop => prop.key === FOREACH_INDEX && prop.declares_value)?.declares_value ?? null;
|
|
335
|
+
};
|
|
330
336
|
|
|
331
337
|
/** A `<local>` in scope: its node and the port it resolved to. */
|
|
332
338
|
type LocalBinding = {local: true; node: string; name: string; port: ResolvedBlokLocal};
|
|
@@ -677,6 +683,8 @@ class Checker {
|
|
|
677
683
|
const items = node.props?.find(prop => prop.key === FOREACH_ITEMS) ?? null;
|
|
678
684
|
inner.set(declared, this.bindLet(declared, items, {node, key: FOREACH_ITEMS, callback: false, inError}, scope));
|
|
679
685
|
}
|
|
686
|
+
const index = foreachIndex(node);
|
|
687
|
+
if (index !== null) inner.set(index, this.bindIndex(index, {node, key: FOREACH_INDEX, callback: false, inError}, new Map(inner)));
|
|
680
688
|
for (const prop of node.props ?? []) {
|
|
681
689
|
// A foreach reads its items outside the loop, its key inside it.
|
|
682
690
|
const propScope = declared !== null && prop.key === FOREACH_ITEMS ? scope : inner;
|
|
@@ -1048,6 +1056,15 @@ class Checker {
|
|
|
1048
1056
|
if (call.operation === FETCH_MORE_FUNCTION && query.more == null) this.add('query.fetch_more', where.node.id, {path, name}, where.key);
|
|
1049
1057
|
}
|
|
1050
1058
|
|
|
1059
|
+
/** What a foreach's `index` is bound to: the item's 0-based position. `scope` holds the loop variable already. */
|
|
1060
|
+
private bindIndex(name: string, where: Where, scope: Scope): Binding {
|
|
1061
|
+
if (this.vocabulary.reserved.has(name)) this.add('roots.reserved', where.node.id, {name});
|
|
1062
|
+
else if (scope.has(name)) {
|
|
1063
|
+
this.add('roots.shadow', where.node.id, {name, first: bindingWhat(name, scope.get(name), this.into), second: `the index of <foreach> (${where.node.id})`});
|
|
1064
|
+
}
|
|
1065
|
+
return {key: name, kind: 'INT'};
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1051
1068
|
private bindLet(name: string, items: BlokComponentProp | null, where: Where, scope: Scope): Binding {
|
|
1052
1069
|
if (this.vocabulary.reserved.has(name)) this.add('roots.reserved', where.node.id, {name});
|
|
1053
1070
|
else if (scope.has(name)) {
|
|
@@ -31,7 +31,7 @@ import {blokPlatform} from '../../platform';
|
|
|
31
31
|
* - `<if when={...}>`: its children are the then-branch, then `<else when>`
|
|
32
32
|
* (else-if) and a last `<else>`; only the active branch is rendered and read.
|
|
33
33
|
* - `<foreach items={...} let="p" key={p.id}>`: once per item, keyed; without
|
|
34
|
-
* `key`, keyed by position.
|
|
34
|
+
* `key`, keyed by position. `index="i"` names the item's position, from 0.
|
|
35
35
|
* - `<match value={...}>` with `<case is={...}>` and `<default>`.
|
|
36
36
|
* - `<suspense>` with `<fallback>` and `<error>`: React's model, the error
|
|
37
37
|
* boundary folded in; a pending read inside shows the fallback, a failed
|
|
@@ -62,15 +62,23 @@ const ForeachIteration = (props: {
|
|
|
62
62
|
itemPath?: string;
|
|
63
63
|
/** The item itself, for sources that have no addressable path. */
|
|
64
64
|
item: unknown;
|
|
65
|
+
/** The name the item's position is read by (`index="i"`), when the foreach names one. */
|
|
66
|
+
indexName?: string;
|
|
67
|
+
/** The item's 0-based position in the list. */
|
|
68
|
+
index: number;
|
|
65
69
|
childIds: string[];
|
|
66
70
|
buildChild: (id: string, basePath?: string) => React.ReactNode;
|
|
67
71
|
}) => {
|
|
68
|
-
const {buildChild, childIds, item, itemKey, itemPath, scopeName} = props;
|
|
72
|
+
const {buildChild, childIds, index, indexName, item, itemKey, itemPath, scopeName} = props;
|
|
69
73
|
|
|
70
74
|
// A path-backed item aliases to its path, so a bound control inside the loop
|
|
71
75
|
// writes the real backing list. Without a path the item is handed down by value.
|
|
72
76
|
const aliases = React.useMemo(() => (itemPath ? {[scopeName]: itemPath} : undefined), [itemPath, scopeName]);
|
|
73
|
-
|
|
77
|
+
// The position has no path: it is always handed down by value.
|
|
78
|
+
const values = React.useMemo(() => {
|
|
79
|
+
const position = indexName ? {[indexName]: index} : undefined;
|
|
80
|
+
return itemPath ? position : {[scopeName]: item, ...position};
|
|
81
|
+
}, [index, indexName, item, itemPath, scopeName]);
|
|
74
82
|
|
|
75
83
|
return (
|
|
76
84
|
<BlokItemKeyProvider itemKey={itemKey}>
|
|
@@ -87,6 +95,7 @@ const foreachSchema = z
|
|
|
87
95
|
.object({
|
|
88
96
|
items: z.array(z.unknown()).nullish().describe('The list to iterate.'),
|
|
89
97
|
let: z.string().describe('The name each item is read by inside the loop (`let="p"`, read as `p.name`).'),
|
|
98
|
+
index: z.string().optional().describe('A name for the item\'s position, from 0 (`index="i"`), read bare inside the loop.'),
|
|
90
99
|
key: z
|
|
91
100
|
.unknown()
|
|
92
101
|
.optional()
|
|
@@ -136,6 +145,8 @@ export const Foreach = createBlokComponent(
|
|
|
136
145
|
const blok = useBlok(component, schema);
|
|
137
146
|
const items = useValue(blok.items);
|
|
138
147
|
const scopeName = blok['let'].prop?.declares_value ?? (typeof blok['let'].prop?.static_value === 'string' ? blok['let'].prop.static_value : '');
|
|
148
|
+
const indexProp = blok.index.prop;
|
|
149
|
+
const indexName = indexProp?.declares_value ?? (typeof indexProp?.static_value === 'string' ? indexProp.static_value : undefined);
|
|
139
150
|
const resolve = useScopedResolver();
|
|
140
151
|
const childIds = React.useMemo(() => component.children?.map(child => child.id) ?? [], [component]);
|
|
141
152
|
const scope = useBlokScope();
|
|
@@ -150,7 +161,8 @@ export const Foreach = createBlokComponent(
|
|
|
150
161
|
const keys = keyProp
|
|
151
162
|
? items.map((item, index) => {
|
|
152
163
|
const path = itemPath(index);
|
|
153
|
-
const
|
|
164
|
+
const position = indexName ? {[indexName]: index} : {};
|
|
165
|
+
const resolved = resolve(keyProp, path ? position : {[scopeName]: item, ...position}, path ? {[scopeName]: path} : undefined);
|
|
154
166
|
return resolved.ok ? resolved.value : null;
|
|
155
167
|
})
|
|
156
168
|
: null;
|
|
@@ -165,6 +177,8 @@ export const Foreach = createBlokComponent(
|
|
|
165
177
|
scopeName={scopeName}
|
|
166
178
|
itemPath={itemPath(index)}
|
|
167
179
|
item={item}
|
|
180
|
+
indexName={indexName || undefined}
|
|
181
|
+
index={index}
|
|
168
182
|
childIds={childIds}
|
|
169
183
|
buildChild={buildChild}
|
|
170
184
|
/>
|
|
@@ -85,6 +85,17 @@ describe('foreach', () => {
|
|
|
85
85
|
expect([...document.querySelectorAll('p')].map(element => element.textContent)).toEqual(['one', 'two', 'three']);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
+
it('names each item\'s position with index, for a path-backed list and a computed one', () => {
|
|
89
|
+
render(
|
|
90
|
+
'<Card><foreach items={xs} let="x" index="i"><Text>{math.add(a: i, b: 1)}. {x}</Text></foreach><foreach items={list.reverse(xs)} let="y" index="j" key={j}><Text>r{j} {y}</Text></foreach></Card>',
|
|
91
|
+
{xs: ['one', 'two']},
|
|
92
|
+
);
|
|
93
|
+
expect(screen.queryByText('1. one')).not.toBeNull();
|
|
94
|
+
expect(screen.queryByText('2. two')).not.toBeNull();
|
|
95
|
+
expect(screen.queryByText('r0 two')).not.toBeNull();
|
|
96
|
+
expect(screen.queryByText('r1 one')).not.toBeNull();
|
|
97
|
+
});
|
|
98
|
+
|
|
88
99
|
describe('inside another foreach', () => {
|
|
89
100
|
const rows = [
|
|
90
101
|
{id: 'r1', cells: [{id: 'c1', name: 'One'}, {id: 'c2', name: 'Two'}]},
|
package/src/spec/bsx_v2.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"vocab": 2,
|
|
3
|
-
"minor":
|
|
3
|
+
"minor": 4,
|
|
4
4
|
"catalogs": {
|
|
5
5
|
"base": "https://arkitekt.live/catalogs/base/v4",
|
|
6
6
|
"bundled": {
|
|
@@ -2643,6 +2643,63 @@
|
|
|
2643
2643
|
},
|
|
2644
2644
|
"printed": "<foreach items={self.names} let=\"n\">\n <Text>{n}</Text>\n</foreach>"
|
|
2645
2645
|
},
|
|
2646
|
+
{
|
|
2647
|
+
"name": "a foreach with an index",
|
|
2648
|
+
"source": "<foreach items={self.names} let=\"n\" index=\"i\"><Text>{math.add(a: i, b: 1)}</Text></foreach>",
|
|
2649
|
+
"tree": {
|
|
2650
|
+
"id": "foreach[0]",
|
|
2651
|
+
"component": "foreach",
|
|
2652
|
+
"props": [
|
|
2653
|
+
{
|
|
2654
|
+
"key": "items",
|
|
2655
|
+
"dynamic_value": {
|
|
2656
|
+
"path": "self.names"
|
|
2657
|
+
}
|
|
2658
|
+
},
|
|
2659
|
+
{
|
|
2660
|
+
"key": "let",
|
|
2661
|
+
"static_value": "n",
|
|
2662
|
+
"declares_value": "n"
|
|
2663
|
+
},
|
|
2664
|
+
{
|
|
2665
|
+
"key": "index",
|
|
2666
|
+
"static_value": "i",
|
|
2667
|
+
"declares_value": "i"
|
|
2668
|
+
}
|
|
2669
|
+
],
|
|
2670
|
+
"children": [
|
|
2671
|
+
{
|
|
2672
|
+
"id": "foreach[0]/Text[0]",
|
|
2673
|
+
"component": "Text",
|
|
2674
|
+
"children": [
|
|
2675
|
+
{
|
|
2676
|
+
"id": "foreach[0]/Text[0]/#0",
|
|
2677
|
+
"component": "#text",
|
|
2678
|
+
"props": [
|
|
2679
|
+
{
|
|
2680
|
+
"key": "value",
|
|
2681
|
+
"util_call": {
|
|
2682
|
+
"operation": "math.add",
|
|
2683
|
+
"arguments": [
|
|
2684
|
+
{
|
|
2685
|
+
"key": "a",
|
|
2686
|
+
"value_path": "i"
|
|
2687
|
+
},
|
|
2688
|
+
{
|
|
2689
|
+
"key": "b",
|
|
2690
|
+
"value_literal": 1
|
|
2691
|
+
}
|
|
2692
|
+
]
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
]
|
|
2696
|
+
}
|
|
2697
|
+
]
|
|
2698
|
+
}
|
|
2699
|
+
]
|
|
2700
|
+
},
|
|
2701
|
+
"printed": "<foreach items={self.names} let=\"n\" index=\"i\">\n <Text>{math.add(i, 1)}</Text>\n</foreach>"
|
|
2702
|
+
},
|
|
2646
2703
|
{
|
|
2647
2704
|
"name": "coalesce",
|
|
2648
2705
|
"source": "<Text text={a ?? b} />",
|
|
@@ -3106,6 +3163,15 @@
|
|
|
3106
3163
|
"column": 21
|
|
3107
3164
|
}
|
|
3108
3165
|
},
|
|
3166
|
+
{
|
|
3167
|
+
"name": "an index from an expression",
|
|
3168
|
+
"source": "<foreach items={xs} let=\"p\" index={i}><Text /></foreach>",
|
|
3169
|
+
"error": {
|
|
3170
|
+
"code": "bsx.index",
|
|
3171
|
+
"line": 1,
|
|
3172
|
+
"column": 29
|
|
3173
|
+
}
|
|
3174
|
+
},
|
|
3109
3175
|
{
|
|
3110
3176
|
"name": "a local named by an expression",
|
|
3111
3177
|
"source": "<local name={x} />",
|
|
@@ -4447,6 +4513,174 @@
|
|
|
4447
4513
|
]
|
|
4448
4514
|
}
|
|
4449
4515
|
},
|
|
4516
|
+
{
|
|
4517
|
+
"name": "an index is a number",
|
|
4518
|
+
"source": "<Blok kind=\"agent\" context=\"panel\"><foreach items={args.xs} let=\"x\" index=\"i\" key={i}><Progress value={i} /><Text text={i.name} /></foreach></Blok>",
|
|
4519
|
+
"tree": {
|
|
4520
|
+
"id": "Blok[0]",
|
|
4521
|
+
"component": "Blok",
|
|
4522
|
+
"props": [
|
|
4523
|
+
{
|
|
4524
|
+
"key": "kind",
|
|
4525
|
+
"static_value": "agent"
|
|
4526
|
+
},
|
|
4527
|
+
{
|
|
4528
|
+
"key": "context",
|
|
4529
|
+
"static_value": "panel"
|
|
4530
|
+
}
|
|
4531
|
+
],
|
|
4532
|
+
"children": [
|
|
4533
|
+
{
|
|
4534
|
+
"id": "Blok[0]/foreach[0]",
|
|
4535
|
+
"component": "foreach",
|
|
4536
|
+
"props": [
|
|
4537
|
+
{
|
|
4538
|
+
"key": "items",
|
|
4539
|
+
"dynamic_value": {
|
|
4540
|
+
"path": "args.xs"
|
|
4541
|
+
}
|
|
4542
|
+
},
|
|
4543
|
+
{
|
|
4544
|
+
"key": "let",
|
|
4545
|
+
"static_value": "x",
|
|
4546
|
+
"declares_value": "x"
|
|
4547
|
+
},
|
|
4548
|
+
{
|
|
4549
|
+
"key": "index",
|
|
4550
|
+
"static_value": "i",
|
|
4551
|
+
"declares_value": "i"
|
|
4552
|
+
},
|
|
4553
|
+
{
|
|
4554
|
+
"key": "key",
|
|
4555
|
+
"dynamic_value": {
|
|
4556
|
+
"path": "i"
|
|
4557
|
+
}
|
|
4558
|
+
}
|
|
4559
|
+
],
|
|
4560
|
+
"children": [
|
|
4561
|
+
{
|
|
4562
|
+
"id": "Blok[0]/foreach[0]/Progress[0]",
|
|
4563
|
+
"component": "Progress",
|
|
4564
|
+
"props": [
|
|
4565
|
+
{
|
|
4566
|
+
"key": "value",
|
|
4567
|
+
"dynamic_value": {
|
|
4568
|
+
"path": "i"
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
]
|
|
4572
|
+
},
|
|
4573
|
+
{
|
|
4574
|
+
"id": "Blok[0]/foreach[0]/Text[0]",
|
|
4575
|
+
"component": "Text",
|
|
4576
|
+
"props": [
|
|
4577
|
+
{
|
|
4578
|
+
"key": "text",
|
|
4579
|
+
"dynamic_value": {
|
|
4580
|
+
"path": "i.name"
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4583
|
+
]
|
|
4584
|
+
}
|
|
4585
|
+
]
|
|
4586
|
+
}
|
|
4587
|
+
]
|
|
4588
|
+
},
|
|
4589
|
+
"mount": {
|
|
4590
|
+
"kinds": [],
|
|
4591
|
+
"dependencies": [],
|
|
4592
|
+
"args": null,
|
|
4593
|
+
"catalog": true
|
|
4594
|
+
},
|
|
4595
|
+
"resolved": {
|
|
4596
|
+
"locals": {}
|
|
4597
|
+
},
|
|
4598
|
+
"codes": [
|
|
4599
|
+
"path.unknown"
|
|
4600
|
+
],
|
|
4601
|
+
"language": {
|
|
4602
|
+
"resolved": {
|
|
4603
|
+
"locals": {}
|
|
4604
|
+
},
|
|
4605
|
+
"codes": [
|
|
4606
|
+
"path.unknown"
|
|
4607
|
+
]
|
|
4608
|
+
}
|
|
4609
|
+
},
|
|
4610
|
+
{
|
|
4611
|
+
"name": "an index shadowing its let",
|
|
4612
|
+
"source": "<Blok kind=\"agent\" context=\"panel\"><foreach items={args.xs} let=\"x\" index=\"x\" key={x}><Text /></foreach></Blok>",
|
|
4613
|
+
"tree": {
|
|
4614
|
+
"id": "Blok[0]",
|
|
4615
|
+
"component": "Blok",
|
|
4616
|
+
"props": [
|
|
4617
|
+
{
|
|
4618
|
+
"key": "kind",
|
|
4619
|
+
"static_value": "agent"
|
|
4620
|
+
},
|
|
4621
|
+
{
|
|
4622
|
+
"key": "context",
|
|
4623
|
+
"static_value": "panel"
|
|
4624
|
+
}
|
|
4625
|
+
],
|
|
4626
|
+
"children": [
|
|
4627
|
+
{
|
|
4628
|
+
"id": "Blok[0]/foreach[0]",
|
|
4629
|
+
"component": "foreach",
|
|
4630
|
+
"props": [
|
|
4631
|
+
{
|
|
4632
|
+
"key": "items",
|
|
4633
|
+
"dynamic_value": {
|
|
4634
|
+
"path": "args.xs"
|
|
4635
|
+
}
|
|
4636
|
+
},
|
|
4637
|
+
{
|
|
4638
|
+
"key": "let",
|
|
4639
|
+
"static_value": "x",
|
|
4640
|
+
"declares_value": "x"
|
|
4641
|
+
},
|
|
4642
|
+
{
|
|
4643
|
+
"key": "index",
|
|
4644
|
+
"static_value": "x",
|
|
4645
|
+
"declares_value": "x"
|
|
4646
|
+
},
|
|
4647
|
+
{
|
|
4648
|
+
"key": "key",
|
|
4649
|
+
"dynamic_value": {
|
|
4650
|
+
"path": "x"
|
|
4651
|
+
}
|
|
4652
|
+
}
|
|
4653
|
+
],
|
|
4654
|
+
"children": [
|
|
4655
|
+
{
|
|
4656
|
+
"id": "Blok[0]/foreach[0]/Text[0]",
|
|
4657
|
+
"component": "Text"
|
|
4658
|
+
}
|
|
4659
|
+
]
|
|
4660
|
+
}
|
|
4661
|
+
]
|
|
4662
|
+
},
|
|
4663
|
+
"mount": {
|
|
4664
|
+
"kinds": [],
|
|
4665
|
+
"dependencies": [],
|
|
4666
|
+
"args": null,
|
|
4667
|
+
"catalog": true
|
|
4668
|
+
},
|
|
4669
|
+
"resolved": {
|
|
4670
|
+
"locals": {}
|
|
4671
|
+
},
|
|
4672
|
+
"codes": [
|
|
4673
|
+
"roots.shadow"
|
|
4674
|
+
],
|
|
4675
|
+
"language": {
|
|
4676
|
+
"resolved": {
|
|
4677
|
+
"locals": {}
|
|
4678
|
+
},
|
|
4679
|
+
"codes": [
|
|
4680
|
+
"roots.shadow"
|
|
4681
|
+
]
|
|
4682
|
+
}
|
|
4683
|
+
},
|
|
4450
4684
|
{
|
|
4451
4685
|
"name": "one record, two calls",
|
|
4452
4686
|
"source": "<Blok kind=\"agent\" context=\"panel\"><Card><Button onClick={self.move_to(position: 1) into move} /><Button onClick={self.move_to(position: 2) into move} /></Card></Blok>",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "https://arkitekt.live/catalogs/base/v4",
|
|
3
3
|
"name": "base",
|
|
4
4
|
"version": 4,
|
|
5
|
-
"minor":
|
|
5
|
+
"minor": 1,
|
|
6
6
|
"extends": null,
|
|
7
7
|
"description": "The base catalog: everything every renderer draws. The language's own elements (control flow, async boundaries, the Blok element, the declarations, text), the html components, the structure and run parts a host supplies, the scene and the logo shapes. A renderer speaks it whole, in the contexts it draws; functions and effects are in vocabulary.json.",
|
|
8
8
|
"components": [
|
|
@@ -371,7 +371,7 @@
|
|
|
371
371
|
{
|
|
372
372
|
"name": "foreach",
|
|
373
373
|
"group": "language",
|
|
374
|
-
"description": "Renders its children once per item, the item bound to `let`; each item's subtree takes its ids from `key`, or from its position without one.",
|
|
374
|
+
"description": "Renders its children once per item, the item bound to `let` and its position to `index`; each item's subtree takes its ids from `key`, or from its position without one.",
|
|
375
375
|
"context": "PANEL",
|
|
376
376
|
"children_context": null,
|
|
377
377
|
"inherits_context": true,
|
|
@@ -380,6 +380,13 @@
|
|
|
380
380
|
"not_downstream_of": [],
|
|
381
381
|
"text_prop": null,
|
|
382
382
|
"props": [
|
|
383
|
+
{
|
|
384
|
+
"key": "index",
|
|
385
|
+
"kind": "STRING",
|
|
386
|
+
"required": false,
|
|
387
|
+
"description": "A name for the item's position, from 0 (`index=\"i\"`): a plain name, read bare inside.",
|
|
388
|
+
"since": 1
|
|
389
|
+
},
|
|
383
390
|
{
|
|
384
391
|
"key": "items",
|
|
385
392
|
"kind": "ANY",
|
package/src/spec/spec.test.ts
CHANGED
|
@@ -49,7 +49,7 @@ describe('the synced vocabulary', () => {
|
|
|
49
49
|
expect(vocabulary.callKinds).not.toContain('query_refetch');
|
|
50
50
|
expect(vocabulary.records.query.fields.map(field => field.key)).toContain('fetching_more');
|
|
51
51
|
expect(Object.keys(vocabulary.theme.dataAttributes).sort()).toEqual(['busy', 'stale']);
|
|
52
|
-
expect([vocabulary.vocab, vocabulary.minor]).toEqual([2,
|
|
52
|
+
expect([vocabulary.vocab, vocabulary.minor]).toEqual([2, 4]);
|
|
53
53
|
expect(vocabulary.baseCatalog).toBe('https://arkitekt.live/catalogs/base/v4');
|
|
54
54
|
expect(Object.values(vocabulary.bundledCatalogs)).toEqual(['catalogs/base@4.json', 'catalogs/orkestrator@1.json']);
|
|
55
55
|
expect(vocabulary.hostParts).toEqual(['args', 'arg', 'deps', 'dep', 'ask', 'returns', 'status', 'timeline']);
|
|
@@ -76,7 +76,7 @@ describe('the synced vocabulary', () => {
|
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
it('fills diagnostic messages like str.format', () => {
|
|
79
|
-
expect(diagnosticMessage('roots.reserved', {name: 'task'})).toBe("'task' is reserved: no local, let or into may use it.");
|
|
79
|
+
expect(diagnosticMessage('roots.reserved', {name: 'task'})).toBe("'task' is reserved: no local, let, index or into may use it.");
|
|
80
80
|
expect(diagnosticMessage('local.bind', {what: 'x'})).toContain('{name}');
|
|
81
81
|
});
|
|
82
82
|
|
package/src/spec/vocabulary.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"vocab": 2,
|
|
3
|
-
"minor":
|
|
3
|
+
"minor": 4,
|
|
4
4
|
"description": "The blok language, version 2: what a blok may read, call and store. The spec's parser, the server (rekuest_core, takt) and the renderer (orkestrator) load this file or are generated from it. The design is the blok-vocab-v2 proposal of 2026-10-25. Three layers, each versioned on its own: this language (vocab, and minor for what it gained since); the base catalog, everything every renderer draws; and the app catalogs that extend it with what one frontend draws beyond (see catalogs). A server holds a blok to the language alone, never to a catalog: whoever draws a blok checks it against the catalog it has, and an author's tooling checks it when asked.",
|
|
5
5
|
"roots": {
|
|
6
6
|
"data": {
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"stale": "Known, but the source stopped updating (agent offline): the last value, flagged.",
|
|
176
176
|
"failed": "Cannot be known (no access, agent gone, query error), with an error."
|
|
177
177
|
},
|
|
178
|
-
"always_ready": ["locals", "event", "let", "literals"],
|
|
178
|
+
"always_ready": ["locals", "event", "let", "index", "literals"],
|
|
179
179
|
"propagation": [
|
|
180
180
|
"If any input of an expression is pending, the result is pending; else if any failed, the result is failed; else if any is stale, the result is stale.",
|
|
181
181
|
"logic.choose and <if> read only the branch taken; logic.all and logic.any stop at the first operand that decides them.",
|
|
@@ -340,7 +340,7 @@
|
|
|
340
340
|
"description": "How a v2 blok is stored: ComponentNodeInput {id, component, props?, children?}; ComponentPropInput {key, static_value? | dynamic_value {path} | util_call | agent_call (+ declares_value)}; ActionArgumentInput {key?, value_literal? | value_path? | util_call? | value_list? | value_dict?}. A prop or argument with no value field is null.",
|
|
341
341
|
"ids": "An explicit id matches explicit_id; a derived id is the parent's id plus /<Component>[<n>] (n: occurrence among same-named siblings), the root's <Component>[0]. A derived id always ends in ']'. A text node is <parent>/#<n> (n: text-run index) and nothing may target it.",
|
|
342
342
|
"explicit_id": "^[A-Za-z_][A-Za-z0-9_.:-]*$",
|
|
343
|
-
"foreach": "foreach props: items (expression), let (static_value and declares_value the name), key (expression, optional). With a key each item's subtree takes its runtime ids from it: <id>@<key>; without one, from its position: <id>@#<n> (n: the 0-based index). A foreach without key is stored with no key prop at all; the validator warns foreach.position_key when its items are known not to be scalars.",
|
|
343
|
+
"foreach": "foreach props: items (expression), let (static_value and declares_value the name), index (optional; static_value and declares_value the name: an INT, the item's 0-based position in items, in scope where let is), key (expression, optional). With a key each item's subtree takes its runtime ids from it: <id>@<key>; without one, from its position: <id>@#<n> (n: the 0-based index). A foreach without key is stored with no key prop at all; the validator warns foreach.position_key when its items are known not to be scalars.",
|
|
344
344
|
"if": "if props: when; children: the then-branch, then the else nodes (component else, an else-if with a when prop; only the last else may lack when).",
|
|
345
345
|
"into": "agent_call prop with declares_value <name>: a task record only that call writes. Allowed inside foreach; one name is written by one call site.",
|
|
346
346
|
"text": "Text is a child like any other: each run of text between elements is stored as a node {id: <parent>/#<n>, component: \"#text\", props: [value]}, its value a literal or an expression; several parts of one run desugar to str.template(template, values). No element can be called #text, so only text makes one. Parsing needs no catalog. What a component does with its text is its renderer's: one with a text_prop makes its text children that prop (a Button its label), any other that takes children draws them in place; a component that sets its text_prop as an attribute too, or takes neither text nor children, is a catalog finding (catalog.text). A tree stored before text was a node holds the text_prop itself, and implicit Text or span nodes under the same ids: a renderer draws both."
|
|
@@ -424,7 +424,8 @@
|
|
|
424
424
|
"bsx.text_callback": {"level": "error", "message": "Text holds a call or an effect; only a callback prop may.", "hint": "Put the call in a callback prop (onClick={{...}}), never between tags."},
|
|
425
425
|
"bsx.else_outside_if": {"level": "error", "message": "<else> is a child of <if>, after its then-branch.", "hint": "Move the <else> inside its <if>, after the then-branch children."},
|
|
426
426
|
"bsx.else_order": {"level": "error", "message": "<else> comes after the then-branch, and only the last <else> may lack when.", "hint": "Put the <else> branches last in the <if>; only the final one may leave out when."},
|
|
427
|
-
"bsx.foreach": {"level": "error", "message": "<foreach> needs items={{...}} and let=\"name\" (key={{...}}
|
|
427
|
+
"bsx.foreach": {"level": "error", "message": "<foreach> needs items={{...}} and let=\"name\" (key={{...}} and index=\"name\" are optional): {missing}."},
|
|
428
|
+
"bsx.index": {"level": "error", "message": "index={index!r} is not a name.", "hint": "Write index=\"i\": a plain identifier the children read as the item's position, from 0."},
|
|
428
429
|
"bsx.let": {"level": "error", "message": "let={let!r} is not a name.", "hint": "Write let=\"name\": a plain identifier the children read as name.field."},
|
|
429
430
|
"expr.syntax": {"level": "error", "message": "{detail}", "hint": "Expressions are a JavaScript subset: paths, literals, calls with name: value arguments, == != > >= < <=, && || !, ?? and c ? a : b."},
|
|
430
431
|
"expr.arithmetic": {"level": "error", "message": "{operator} is not an operator of the blok language; call math.{function}(a, b)."},
|
|
@@ -445,9 +446,9 @@
|
|
|
445
446
|
"callback.not_callback": {"level": "error", "message": "{key} of <{component}> is not a callback prop, so it cannot hold {what}.", "hint": "Use a callback prop of <{component}> (the catalog lists them as CALLBACK), or compute {key} without a call."},
|
|
446
447
|
"callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
|
|
447
448
|
"callback.event_field": {"level": "error", "message": "event has no field {field!r} in {key} of <{component}> (its fields: {fields}).", "hint": "Read one of the fields listed for {key}: {fields}."},
|
|
448
|
-
"roots.unknown": {"level": "error", "message": "{path} reads {root!r}, which is no root, local, loop variable or record of this blok.", "hint": "Read a root this blok has (deps.<key>, args.<key>, queries.<name>, ...), a declared local, a foreach let, or an into record."},
|
|
449
|
+
"roots.unknown": {"level": "error", "message": "{path} reads {root!r}, which is no root, local, loop variable or record of this blok.", "hint": "Read a root this blok has (deps.<key>, args.<key>, queries.<name>, ...), a declared local, a foreach let or index, or an into record."},
|
|
449
450
|
"roots.not_in_kind": {"level": "error", "message": "{path}: a{n} {kind} blok has no {root!r} (it reads {roots}).", "hint": "Read one of {roots} instead."},
|
|
450
|
-
"roots.reserved": {"level": "error", "message": "{name!r} is reserved: no local, let or into may use it."},
|
|
451
|
+
"roots.reserved": {"level": "error", "message": "{name!r} is reserved: no local, let, index or into may use it."},
|
|
451
452
|
"roots.shadow": {"level": "error", "message": "{name!r} is declared twice: as {first} and as {second}."},
|
|
452
453
|
"roots.event_outside_callback": {"level": "error", "message": "{path} reads event outside a callback.", "hint": "Read event only inside a callback prop; outside one, bind a control to a local and read the local."},
|
|
453
454
|
"roots.error_outside_boundary": {"level": "error", "message": "{path} reads error outside an <error> slot.", "hint": "Read error only inside the <error> slot of a <suspense>."},
|