@arkitektio/bsx 4.2.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -18
- package/dist/bsx/parse.d.ts +13 -7
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +18 -57
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +22 -35
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +5 -5
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +124 -30
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +1 -1
- package/dist/catalogs/html.d.ts.map +1 -1
- package/dist/catalogs/html.js +3 -3
- package/dist/catalogs/html.js.map +1 -1
- package/dist/catalogs/index.d.ts +209 -139
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +6 -2
- package/dist/catalogs/index.js.map +1 -1
- package/dist/catalogs/logo.d.ts +5 -5
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +3 -3
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +6 -6
- package/dist/catalogs/parts/feedback.d.ts +15 -15
- package/dist/catalogs/parts/forms.d.ts +55 -27
- package/dist/catalogs/parts/forms.d.ts.map +1 -1
- package/dist/catalogs/parts/forms.js +32 -0
- package/dist/catalogs/parts/forms.js.map +1 -1
- package/dist/catalogs/parts/html.d.ts +1 -1
- package/dist/catalogs/parts/html.d.ts.map +1 -1
- package/dist/catalogs/parts/html.js +1 -1
- package/dist/catalogs/parts/html.js.map +1 -1
- package/dist/catalogs/parts/icons.d.ts +11 -11
- package/dist/catalogs/parts/icons.js +1 -1
- package/dist/catalogs/parts/index.d.ts +183 -137
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.d.ts +11 -1
- package/dist/catalogs/parts/layout.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.js +9 -0
- package/dist/catalogs/parts/layout.js.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +8 -8
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +2 -2
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +20 -20
- package/dist/catalogs/parts/overlays.d.ts +55 -55
- package/dist/catalogs/parts/run.d.ts +13 -5
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +1 -1
- package/dist/catalogs/parts/scene.d.ts +12 -4
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +4 -0
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/structure.js +2 -2
- package/dist/catalogs/parts/toast.js +1 -1
- package/dist/catalogs/parts/toast.js.map +1 -1
- package/dist/catalogs/parts/typography.js +1 -1
- package/dist/catalogs/parts/typography.js.map +1 -1
- package/dist/catalogs/props.d.ts +3 -3
- package/dist/catalogs/scene.d.ts +13 -5
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +3 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/catalogs/shadcn.d.ts +106 -58
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +6 -4
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/structure.d.ts +1 -1
- package/dist/catalogs/structure.d.ts.map +1 -1
- package/dist/catalogs/structure.js +3 -3
- package/dist/catalogs/structure.js.map +1 -1
- package/dist/catalogs/ui.d.ts +83 -73
- package/dist/catalogs/ui.d.ts.map +1 -1
- package/dist/catalogs/ui.js +4 -3
- package/dist/catalogs/ui.js.map +1 -1
- package/dist/catalogs.d.ts +1 -1
- package/dist/catalogs.d.ts.map +1 -1
- package/dist/catalogs.js +2 -2
- package/dist/catalogs.js.map +1 -1
- package/dist/ports.js +1 -1
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +4 -1
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +5 -1
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +8 -6
- package/dist/renderer/baseCatalog.d.ts.map +1 -1
- package/dist/renderer/baseCatalog.js +7 -5
- package/dist/renderer/baseCatalog.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +14 -0
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +105 -6
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +6 -6
- package/dist/renderer/bloks/feedback.d.ts +15 -15
- package/dist/renderer/bloks/forms.d.ts +51 -27
- package/dist/renderer/bloks/forms.d.ts.map +1 -1
- package/dist/renderer/bloks/forms.js +56 -0
- package/dist/renderer/bloks/forms.js.map +1 -1
- package/dist/renderer/bloks/html.js +2 -2
- package/dist/renderer/bloks/icons.d.ts +5 -5
- package/dist/renderer/bloks/index.d.ts +166 -134
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/index.js +1 -1
- package/dist/renderer/bloks/layout.d.ts +9 -1
- package/dist/renderer/bloks/layout.d.ts.map +1 -1
- package/dist/renderer/bloks/layout.js +15 -0
- package/dist/renderer/bloks/layout.js.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +5 -5
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +2 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/navigation.d.ts +20 -20
- package/dist/renderer/bloks/overlays.d.ts +55 -55
- package/dist/renderer/bloks/run/components.d.ts +6 -2
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +1 -1
- package/dist/renderer/bloks/run/host.d.ts +32 -3
- package/dist/renderer/bloks/run/host.d.ts.map +1 -1
- package/dist/renderer/bloks/run/host.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +6 -2
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/toast.d.ts +1 -1
- package/dist/renderer/bloks/typography.js +1 -1
- package/dist/renderer/catalog.d.ts +4 -7
- package/dist/renderer/catalog.d.ts.map +1 -1
- package/dist/renderer/catalog.js +7 -31
- package/dist/renderer/catalog.js.map +1 -1
- package/dist/renderer/declare.d.ts +31 -19
- package/dist/renderer/declare.d.ts.map +1 -1
- package/dist/renderer/declare.js +44 -18
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/functions/v2/index.d.ts.map +1 -1
- package/dist/renderer/functions/v2/index.js +39 -0
- package/dist/renderer/functions/v2/index.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +27 -7
- package/dist/renderer/runtime/catalog.d.ts.map +1 -1
- package/dist/renderer/runtime/catalog.js +30 -3
- package/dist/renderer/runtime/catalog.js.map +1 -1
- package/dist/renderer/runtime/components.d.ts +7 -1
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +3 -0
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +2 -0
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +4 -0
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +14 -4
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +3 -0
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +1 -0
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +1 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +1 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/preflight.d.ts.map +1 -1
- package/dist/renderer/runtime/preflight.js +5 -2
- package/dist/renderer/runtime/preflight.js.map +1 -1
- package/dist/renderer/runtime/resolution.d.ts +2 -0
- package/dist/renderer/runtime/resolution.d.ts.map +1 -1
- package/dist/renderer/runtime/resolution.js +17 -1
- package/dist/renderer/runtime/resolution.js.map +1 -1
- package/dist/renderer/runtime/schemas.d.ts +5 -5
- package/dist/renderer/runtime/task.d.ts +25 -2
- package/dist/renderer/runtime/task.d.ts.map +1 -1
- package/dist/renderer/runtime/task.js +11 -2
- package/dist/renderer/runtime/task.js.map +1 -1
- package/dist/renderer/runtime/text.d.ts +28 -0
- package/dist/renderer/runtime/text.d.ts.map +1 -0
- package/dist/renderer/runtime/text.js +82 -0
- package/dist/renderer/runtime/text.js.map +1 -0
- package/dist/renderer/runtime/types.d.ts +7 -2
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/scene.d.ts +1 -1
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +2 -2
- package/dist/scene.js.map +1 -1
- package/dist/shadcn.d.ts +169 -137
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +8 -5
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +3080 -2372
- package/dist/spec/catalogs/base@3.json +13029 -0
- package/dist/spec/catalogs/base@3.json.js +13029 -0
- package/dist/spec/catalogs/orkestrator@1.json +489 -0
- package/dist/spec/catalogs/orkestrator@1.json.js +489 -0
- package/dist/spec/catalogs.d.ts +109 -46
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +241 -73
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +21 -3
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +16 -2
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +73 -27
- package/dist/spec/vocabulary.json.js +73 -27
- package/dist/vendor/core/ui/button-group.d.ts +1 -1
- package/dist/vendor/core/ui/button.d.ts +1 -1
- package/dist/vendor/core/ui/field.d.ts +1 -1
- package/package.json +1 -1
- package/src/bsx/infer.test.ts +18 -26
- package/src/bsx/language.test.ts +2 -2
- package/src/bsx/parse.ts +18 -62
- package/src/bsx/partial.test.ts +1 -1
- package/src/bsx/print.ts +24 -34
- package/src/bsx/references.test.ts +71 -10
- package/src/bsx/references.ts +114 -35
- package/src/catalogs/catalogs.test.ts +45 -14
- package/src/catalogs/html.ts +3 -3
- package/src/catalogs/index.ts +6 -2
- package/src/catalogs/logo.ts +3 -3
- package/src/catalogs/parts/forms.ts +32 -0
- package/src/catalogs/parts/html.ts +1 -1
- package/src/catalogs/parts/icons.ts +1 -1
- package/src/catalogs/parts/layout.ts +11 -0
- package/src/catalogs/parts/logo.ts +2 -2
- package/src/catalogs/parts/run.ts +1 -1
- package/src/catalogs/parts/scene.ts +6 -0
- package/src/catalogs/parts/structure.ts +2 -2
- package/src/catalogs/parts/toast.ts +1 -1
- package/src/catalogs/parts/typography.ts +1 -1
- package/src/catalogs/scene.ts +3 -3
- package/src/catalogs/shadcn.ts +6 -4
- package/src/catalogs/structure.ts +3 -3
- package/src/catalogs/ui.ts +4 -3
- package/src/catalogs.ts +9 -2
- package/src/ports.ts +1 -1
- package/src/renderer/BlokRenderer.tsx +9 -0
- package/src/renderer/addBlokComponents.test.tsx +8 -22
- package/src/renderer/baseCatalog.ts +7 -5
- package/src/renderer/bloks/components.test.tsx +2 -2
- package/src/renderer/bloks/control.tsx +133 -6
- package/src/renderer/bloks/flow.test.tsx +1 -1
- package/src/renderer/bloks/forms.tsx +126 -0
- package/src/renderer/bloks/html.tsx +2 -2
- package/src/renderer/bloks/index.ts +1 -1
- package/src/renderer/bloks/layout.tsx +28 -0
- package/src/renderer/bloks/logo/index.tsx +2 -2
- package/src/renderer/bloks/run/components.tsx +1 -1
- package/src/renderer/bloks/run/host.tsx +33 -3
- package/src/renderer/bloks/run/space.test.tsx +76 -0
- package/src/renderer/bloks/time.test.tsx +1 -1
- package/src/renderer/bloks/toast.tsx +1 -1
- package/src/renderer/bloks/typography.tsx +1 -1
- package/src/renderer/catalog.tsx +7 -31
- package/src/renderer/declare.test.ts +41 -0
- package/src/renderer/declare.ts +70 -32
- package/src/renderer/functions/v2/functions.test.ts +40 -1
- package/src/renderer/functions/v2/index.ts +47 -0
- package/src/renderer/runtime/catalog.ts +35 -10
- package/src/renderer/runtime/components.tsx +10 -1
- package/src/renderer/runtime/context.tsx +6 -0
- package/src/renderer/runtime/describe.ts +17 -4
- package/src/renderer/runtime/hooks.ts +1 -0
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/preflight.ts +5 -2
- package/src/renderer/runtime/resolution.test.ts +14 -0
- package/src/renderer/runtime/resolution.ts +15 -1
- package/src/renderer/runtime/task.ts +33 -4
- package/src/renderer/runtime/text.test.tsx +65 -0
- package/src/renderer/runtime/text.ts +88 -0
- package/src/renderer/runtime/types.ts +7 -2
- package/src/runtime.ts +0 -1
- package/src/scene.ts +2 -2
- package/src/shadcn.ts +8 -5
- package/src/spec/bsx_v2.json +3080 -2372
- package/src/spec/catalogs/base@3.json +13029 -0
- package/src/spec/catalogs/orkestrator@1.json +489 -0
- package/src/spec/catalogs.ts +257 -101
- package/src/spec/spec.test.ts +107 -21
- package/src/spec/vocabulary.json +73 -27
- package/src/spec/vocabulary.ts +36 -7
- package/dist/renderer/modules.d.ts +0 -4
- package/dist/renderer/modules.d.ts.map +0 -1
- package/dist/renderer/modules.js +0 -11
- package/dist/renderer/modules.js.map +0 -1
- package/dist/spec/catalogs/base@2.json +0 -222
- package/dist/spec/catalogs/base@2.json.js +0 -222
- package/dist/spec/catalogs/html@1.json +0 -308
- package/dist/spec/catalogs/html@1.json.js +0 -308
- package/dist/spec/catalogs/logo@1.json +0 -1687
- package/dist/spec/catalogs/logo@1.json.js +0 -1687
- package/dist/spec/catalogs/scene@1.json +0 -858
- package/dist/spec/catalogs/scene@1.json.js +0 -858
- package/dist/spec/catalogs/shadcn@1.json +0 -3860
- package/dist/spec/catalogs/shadcn@1.json.js +0 -3860
- package/dist/spec/catalogs/structure@1.json +0 -185
- package/dist/spec/catalogs/structure@1.json.js +0 -185
- package/dist/spec/catalogs/ui@1.json +0 -5349
- package/dist/spec/catalogs/ui@1.json.js +0 -5349
- package/src/renderer/modules.ts +0 -12
- package/src/spec/catalogs/base@2.json +0 -222
- package/src/spec/catalogs/html@1.json +0 -308
- package/src/spec/catalogs/logo@1.json +0 -1687
- package/src/spec/catalogs/scene@1.json +0 -858
- package/src/spec/catalogs/shadcn@1.json +0 -3860
- package/src/spec/catalogs/structure@1.json +0 -185
- package/src/spec/catalogs/ui@1.json +0 -5349
package/src/bsx/print.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
BlokComponentProp,
|
|
6
6
|
BlokUtilCall,
|
|
7
7
|
} from '../renderer/runtime/types';
|
|
8
|
-
import {defaultBlokView,
|
|
8
|
+
import {defaultBlokView, type BlokView} from '../spec/catalogs';
|
|
9
9
|
import {isExplicitId, loadVocabulary, type BlokContextName} from '../spec/vocabulary';
|
|
10
10
|
import {
|
|
11
11
|
CLASS_NAME,
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
FETCH_MORE_FUNCTION,
|
|
14
14
|
FOREACH_COMPONENT,
|
|
15
15
|
FOREACH_LET_PROP,
|
|
16
|
-
|
|
16
|
+
LEGACY_IMPLICIT_TEXTS,
|
|
17
|
+
TEXT_NODE,
|
|
18
|
+
TEXT_VALUE,
|
|
17
19
|
REFETCH_FUNCTION,
|
|
18
20
|
TEMPLATE_FUNCTION,
|
|
19
21
|
} from './parse';
|
|
@@ -157,10 +159,8 @@ class Printer {
|
|
|
157
159
|
this.indent = indent;
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
node(node: BlokComponentNode, derived: string, depth: number,
|
|
162
|
+
node(node: BlokComponentNode, derived: string, depth: number, lines: string[]): void {
|
|
161
163
|
const pad = ' '.repeat(this.indent * depth);
|
|
162
|
-
const spec = this.view.components.get(node.component);
|
|
163
|
-
const inner = spec ? innerContext(spec, context) : context;
|
|
164
164
|
const attributes: string[] = [];
|
|
165
165
|
if (node.id !== derived) {
|
|
166
166
|
if (!isExplicitId(node.id)) {
|
|
@@ -169,23 +169,9 @@ class Printer {
|
|
|
169
169
|
attributes.push(`id=${quoted(node.id)}`);
|
|
170
170
|
}
|
|
171
171
|
const children = node.children ?? [];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const drawsText = this.vocabulary.contexts[inner]?.text ?? true;
|
|
176
|
-
const props = node.props ?? [];
|
|
177
|
-
props.forEach((prop, position) => {
|
|
178
|
-
// The parser puts the prop text children fill last, so only the last is spelled as text.
|
|
179
|
-
const last = position === props.length - 1;
|
|
180
|
-
if (textProp !== null && prop.key === textProp && last && children.length === 0 && drawsText) {
|
|
181
|
-
const printed = this.textOf(prop, node, true);
|
|
182
|
-
if (printed !== null) {
|
|
183
|
-
textChild = printed;
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
attributes.push(this.attribute(node, prop));
|
|
188
|
-
});
|
|
172
|
+
// Its one child a text node: spelled on the line of its tags.
|
|
173
|
+
const textChild = children.length === 1 && Printer.isImplicit(children[0], node.id) ? this.textNode(children[0], true) : null;
|
|
174
|
+
for (const prop of node.props ?? []) attributes.push(this.attribute(node, prop));
|
|
189
175
|
let head = `<${node.component}${attributes.map(attribute => ` ${attribute}`).join('')}`;
|
|
190
176
|
const wrapped = pad.length + head.length > LINE_WIDTH && attributes.length > 1;
|
|
191
177
|
if (wrapped) {
|
|
@@ -204,27 +190,32 @@ class Printer {
|
|
|
204
190
|
let implicit = 0;
|
|
205
191
|
for (const child of children) {
|
|
206
192
|
if (Printer.isImplicit(child, node.id)) {
|
|
207
|
-
if (
|
|
208
|
-
refuse(`<${node.component}> (${node.id}) holds implicit Text with no element beside it`);
|
|
209
|
-
}
|
|
210
|
-
if (child.id !== `${node.id}/#${implicit}`) refuse(`<${node.component}> (${node.id}): implicit Text '${child.id}' is out of order`);
|
|
193
|
+
if (child.id !== `${node.id}/#${implicit}`) refuse(`<${node.component}> (${node.id}): the text node '${child.id}' is out of order`);
|
|
211
194
|
implicit += 1;
|
|
212
|
-
|
|
213
|
-
const text = only ? this.textOf(only, child, false) : null;
|
|
214
|
-
if (text === null) refuse(`implicit Text '${child.id}' cannot be spelled as text`);
|
|
215
|
-
lines.push(`${pad}${' '.repeat(this.indent)}${text}`);
|
|
195
|
+
lines.push(`${pad}${' '.repeat(this.indent)}${this.textNode(child, false)}`);
|
|
216
196
|
continue;
|
|
217
197
|
}
|
|
218
198
|
const index = counts.get(child.component) ?? 0;
|
|
219
199
|
counts.set(child.component, index + 1);
|
|
220
|
-
this.node(child, `${node.id}/${child.component}[${index}]`, depth + 1,
|
|
200
|
+
this.node(child, `${node.id}/${child.component}[${index}]`, depth + 1, lines);
|
|
221
201
|
}
|
|
222
202
|
lines.push(`${pad}</${node.component}>`);
|
|
223
203
|
}
|
|
224
204
|
|
|
205
|
+
/** Whether `child` is a run of text of `parent`: a text node, or what one was stored as before. */
|
|
225
206
|
static isImplicit(child: BlokComponentNode, parent: string): boolean {
|
|
226
207
|
const match = IMPLICIT.exec(child.id);
|
|
227
|
-
return match !== null && match.groups?.parent === parent &&
|
|
208
|
+
return match !== null && match.groups?.parent === parent && (child.component === TEXT_NODE || LEGACY_IMPLICIT_TEXTS.includes(child.component));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** A text node as the text it was parsed from; refuses one that holds anything but its one value. */
|
|
212
|
+
private textNode(child: BlokComponentNode, inline: boolean): string {
|
|
213
|
+
const key = child.component === TEXT_NODE ? TEXT_VALUE : 'text';
|
|
214
|
+
const props = child.props ?? [];
|
|
215
|
+
const only = props.length === 1 && props[0].key === key && !(child.children && child.children.length > 0) ? props[0] : null;
|
|
216
|
+
const text = only ? this.textOf(only, child, inline) : null;
|
|
217
|
+
if (text === null) return refuse(`the text node '${child.id}' cannot be spelled as text`);
|
|
218
|
+
return text;
|
|
228
219
|
}
|
|
229
220
|
|
|
230
221
|
/**
|
|
@@ -233,7 +224,6 @@ class Printer {
|
|
|
233
224
|
* its ends; on a line of its own they are trimmed, so they are spelled as strings.
|
|
234
225
|
*/
|
|
235
226
|
private textOf(prop: BlokComponentProp, node: BlokComponentNode, inline: boolean): string | null {
|
|
236
|
-
if (prop.key !== 'text' && IMPLICIT_TEXTS.includes(node.component)) return null;
|
|
237
227
|
if (prop.declares_value || prop.agent_call) return null;
|
|
238
228
|
if (typeof prop.static_value === 'string') return textLiteral(prop.static_value, !inline);
|
|
239
229
|
if (prop.dynamic_value) {
|
|
@@ -406,7 +396,7 @@ class Printer {
|
|
|
406
396
|
/** Print `node` as v2 BSX that `parseBsx` (with the same view) reads back into it. Throws a `BsxPrintError`. */
|
|
407
397
|
export const printBsx = (node: BlokComponentNode, options: {view?: BlokView; indent?: number} = {}): string => {
|
|
408
398
|
const lines: string[] = [];
|
|
409
|
-
new Printer(options.view ?? defaultBlokView(), options.indent ?? 2).node(node, `${node.component}[0]`, 0,
|
|
399
|
+
new Printer(options.view ?? defaultBlokView(), options.indent ?? 2).node(node, `${node.component}[0]`, 0, lines);
|
|
410
400
|
return lines.join('\n');
|
|
411
401
|
};
|
|
412
402
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
2
|
import corpus from '../spec/bsx_v2.json';
|
|
3
|
-
import {
|
|
3
|
+
import {baseBlokView, blokView, type BlokView} from '../spec/catalogs';
|
|
4
4
|
import {resolveBlokScope} from './infer';
|
|
5
5
|
import {parseBsx} from './parse';
|
|
6
6
|
import {checkBlokTree, dependencyHint, emptyBlokScope, type BlokCheckScope} from './references';
|
|
7
7
|
|
|
8
|
-
type CorpusScope =
|
|
8
|
+
type CorpusScope = BlokCheckScope & {catalog?: boolean};
|
|
9
9
|
type CheckedCase = {
|
|
10
10
|
name: string;
|
|
11
11
|
source: string;
|
|
@@ -15,18 +15,13 @@ type CheckedCase = {
|
|
|
15
15
|
codes: string[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
/** The view a case is checked with: none, the
|
|
18
|
+
/** The view a case is checked with: none (the language alone), the base catalog's, or that of the catalog it is written for. */
|
|
19
19
|
const caseView = (scope: CorpusScope): BlokView | null => {
|
|
20
20
|
if (scope.catalog === false) return null;
|
|
21
|
-
|
|
22
|
-
return blokView([parseSpecCatalog(scope.module, 'module')]);
|
|
21
|
+
return scope.target == null ? baseBlokView() : blokView(scope.target);
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
const caseScope = (scope: CorpusScope): BlokCheckScope =>
|
|
26
|
-
const {module} = scope;
|
|
27
|
-
const named = typeof module === 'object' && module !== null && 'name' in module && typeof module.name === 'string' ? module.name : null;
|
|
28
|
-
return {...scope, module: named};
|
|
29
|
-
};
|
|
24
|
+
const caseScope = (scope: CorpusScope): BlokCheckScope => scope;
|
|
30
25
|
|
|
31
26
|
/** The wire spells "nothing" as null or leaves it out (as bsx.test.ts compares trees). */
|
|
32
27
|
const withoutNulls = (value: unknown): unknown => {
|
|
@@ -159,3 +154,69 @@ describe('findings', () => {
|
|
|
159
154
|
expect(checkBlokTree(tree, emptyBlokScope('agent'))).toEqual([]);
|
|
160
155
|
});
|
|
161
156
|
});
|
|
157
|
+
|
|
158
|
+
describe('what an assign blok places and reads of the run it prepares', () => {
|
|
159
|
+
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
160
|
+
const assign = {...emptyBlokScope('assign'), args: ['image', 'exposure']};
|
|
161
|
+
|
|
162
|
+
it('reads assign.given.<key>, assign.missing and assign.ready', () => {
|
|
163
|
+
const source =
|
|
164
|
+
'<Html><if when={assign.given.image}><Text text={args.image} /></if><arg key="exposure" /><args /><deps /><Button onClick={assign.start()} disabled={!assign.ready}>Run</Button></Html>';
|
|
165
|
+
expect(codes(source, assign)).toEqual([]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('refuses a given flag for an argument the action has not, and a field assign has not', () => {
|
|
169
|
+
expect(codes('<Html><Text text={assign.given.nope} /></Html>', assign)).toEqual(['args.unknown']);
|
|
170
|
+
expect(codes('<Html><Text text={assign.nope} /></Html>', assign)).toEqual(['path.unknown']);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('keeps <arg>, <deps>, <dep> and the assign root to an assign blok', () => {
|
|
174
|
+
const task = emptyBlokScope('task');
|
|
175
|
+
expect(codes('<Html><arg key="image" /></Html>', task)).toEqual(['catalog.kind']);
|
|
176
|
+
expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['catalog.kind', 'catalog.kind']);
|
|
177
|
+
// The language alone knows no kind of a component: that is the catalog's to say.
|
|
178
|
+
expect(checkBlokTree(parseBsx('<Html><arg key="image" /></Html>').tree, task, null)).toEqual([]);
|
|
179
|
+
expect(codes('<Html><Text text={assign.ready} /></Html>', task)).toEqual(['roots.not_in_kind']);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('what a blok does to the task it is about', () => {
|
|
184
|
+
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
185
|
+
|
|
186
|
+
it('cancels, pauses, resumes, steps and interrupts it, and reads whether it may', () => {
|
|
187
|
+
const source =
|
|
188
|
+
'<Html><Button onClick={task.cancel()} disabled={!task.can.cancel}>Stop</Button><Button onClick={task.pause()}>Pause</Button><Button onClick={task.resume()}>Resume</Button><Button onClick={task.step()}>Step</Button><Button onClick={task.interrupt()}>Kill</Button><Text text={deps.robot.connected ? task.started_at : task.status} /></Html>';
|
|
189
|
+
const scope = {...emptyBlokScope('action'), dependencies: [{key: 'robot'}]} as BlokCheckScope;
|
|
190
|
+
expect(codes(source, scope)).toEqual([]);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('starts no run again: a rerun is the page\'s, never a blok\'s', () => {
|
|
194
|
+
expect(() => parseBsx('<Html><Button onClick={task.rerun()}>Again</Button></Html>')).toThrow(/calls nothing/);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('refuses them where there is no task', () => {
|
|
198
|
+
expect(codes('<Html><Button onClick={task.cancel()}>Stop</Button></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind']);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('what a blok places of its task, and what it leaves the host', () => {
|
|
203
|
+
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
204
|
+
|
|
205
|
+
it('places the result, the status line and the time slider, and says how much chrome it wants', () => {
|
|
206
|
+
const source = '<Html chrome="none"><status /><ask /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} /></Html>';
|
|
207
|
+
expect(codes(source, emptyBlokScope('action'))).toEqual([]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('warns where no chrome leaves the asks to a blok that places none, and where a part is claimed from inside a branch', () => {
|
|
211
|
+
expect(codes('<Html chrome="none"><status /></Html>', emptyBlokScope('action'))).toEqual(['chrome.no_ask']);
|
|
212
|
+
expect(codes('<Html><if when={task.running}><timeline /></if></Html>', emptyBlokScope('action'))).toEqual(['part.conditional']);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('keeps <returns> and <status> to a blok that has a task', () => {
|
|
216
|
+
expect(codes('<Html><returns /><status /></Html>', emptyBlokScope('assign'))).toEqual(['catalog.kind', 'catalog.kind']);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('reads what an assign blok knows of starting', () => {
|
|
220
|
+
expect(codes('<Html><Text text={assign.blocked} /><Button disabled={assign.starting} onClick={assign.start()}>Run</Button></Html>', emptyBlokScope('assign'))).toEqual([]);
|
|
221
|
+
});
|
|
222
|
+
});
|
package/src/bsx/references.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
BlokUtilCall,
|
|
7
7
|
} from '../renderer/runtime/types';
|
|
8
8
|
import {defaultBlokView, type BlokView, type SpecComponent} from '../spec/catalogs';
|
|
9
|
+
import {TEXT_NODE} from './parse';
|
|
9
10
|
import {valueFitsPort} from '../spec/locals';
|
|
10
11
|
import {LOCAL_ANY, resolveBlokScope} from './infer';
|
|
11
12
|
import {
|
|
@@ -107,6 +108,43 @@ export type BlokScopeSubscription = {
|
|
|
107
108
|
history?: string | null;
|
|
108
109
|
};
|
|
109
110
|
|
|
111
|
+
/** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
|
|
112
|
+
const splitClass = (token: string): string[] => {
|
|
113
|
+
const parts: string[] = [];
|
|
114
|
+
let depth = 0;
|
|
115
|
+
let current = '';
|
|
116
|
+
for (const character of token) {
|
|
117
|
+
if (character === '[') depth += 1;
|
|
118
|
+
else if (character === ']') depth = Math.max(0, depth - 1);
|
|
119
|
+
if (character === ':' && depth === 0) {
|
|
120
|
+
parts.push(current);
|
|
121
|
+
current = '';
|
|
122
|
+
} else current += character;
|
|
123
|
+
}
|
|
124
|
+
parts.push(current);
|
|
125
|
+
return parts;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** What of the class `token` is outside the portable subset (`the before variant`), or null. */
|
|
129
|
+
export const unportableClass = (token: string, vocabulary: BlokVocabulary): string | null => {
|
|
130
|
+
const parts = splitClass(token);
|
|
131
|
+
const utility = (parts.pop() ?? '').replace(/^[!-]+/, '');
|
|
132
|
+
for (const variant of parts) {
|
|
133
|
+
if (variant.startsWith('[')) return 'an arbitrary variant';
|
|
134
|
+
const name = variant.split('/')[0];
|
|
135
|
+
if (vocabulary.unportableVariants.has(name) || vocabulary.unportableVariants.has(name.split('-[')[0])) return `the ${name} variant`;
|
|
136
|
+
}
|
|
137
|
+
if (utility.startsWith('[')) return 'an arbitrary property';
|
|
138
|
+
if (utility.includes('[')) {
|
|
139
|
+
const prefix = utility.split('-[')[0];
|
|
140
|
+
return vocabulary.arbitraryValues.has(prefix) ? null : `an arbitrary value of ${prefix}`;
|
|
141
|
+
}
|
|
142
|
+
for (const prefix of vocabulary.unportableUtilities) {
|
|
143
|
+
if (utility === prefix || utility.startsWith(`${prefix}-`)) return `the ${prefix} utility`;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
|
|
110
148
|
/** What a blok declares beside its tree; the corpus' `scope` verbatim. */
|
|
111
149
|
export type BlokCheckScope = {
|
|
112
150
|
kind: BlokKind;
|
|
@@ -118,10 +156,8 @@ export type BlokCheckScope = {
|
|
|
118
156
|
subscriptions: readonly BlokScopeSubscription[];
|
|
119
157
|
/** The keys `args.<key>` may read; null reads any. */
|
|
120
158
|
args: readonly string[] | null;
|
|
121
|
-
/** The
|
|
122
|
-
|
|
123
|
-
/** The module (an app's own extras) the blok names, if any. */
|
|
124
|
-
module?: string | null;
|
|
159
|
+
/** The id of the catalog the blok is written for; null (or absent): the base catalog. The corpus' `target`. */
|
|
160
|
+
target?: string | null;
|
|
125
161
|
/** Per declared query, the shape of its value when its service's schema is known. */
|
|
126
162
|
query_values?: Readonly<Record<string, BlokPortMatch>>;
|
|
127
163
|
/** The assets `self.assets.<name>` may name; null (or absent) names any. */
|
|
@@ -141,7 +177,6 @@ export const emptyBlokScope = (kind: BlokKind = 'agent', context = 'HTML'): Blok
|
|
|
141
177
|
queries: [],
|
|
142
178
|
subscriptions: [],
|
|
143
179
|
args: null,
|
|
144
|
-
catalogs: [],
|
|
145
180
|
});
|
|
146
181
|
|
|
147
182
|
const ACTION_LOGO = 'ACTION_LOGO';
|
|
@@ -173,8 +208,15 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
|
|
|
173
208
|
/** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
|
|
174
209
|
const RUN_KINDS: readonly string[] = ['action', 'assign'];
|
|
175
210
|
const ASSIGN_KIND = 'assign';
|
|
176
|
-
|
|
177
|
-
const
|
|
211
|
+
const ASK_COMPONENT = 'ask';
|
|
212
|
+
const CHROME_PROP = 'chrome';
|
|
213
|
+
const CHROME_NONE = 'none';
|
|
214
|
+
/** The language's elements whose children do not always show: a host part inside one still claims its slot. */
|
|
215
|
+
const CONDITIONAL_COMPONENTS: ReadonlySet<string> = new Set(['if', 'else', 'match', 'case', 'default', 'foreach', 'suspense', 'fallback', 'error']);
|
|
216
|
+
/** The one field of an agent that is not text. */
|
|
217
|
+
const AGENT_CONNECTED = 'connected';
|
|
218
|
+
/** Where an assign blok reads which arguments the caller decided. */
|
|
219
|
+
const GIVEN_FIELD = 'given';
|
|
178
220
|
/** Starts the run an assign blok prepares. */
|
|
179
221
|
const START_EFFECT = 'assign.start';
|
|
180
222
|
|
|
@@ -403,7 +445,9 @@ class Checker {
|
|
|
403
445
|
private readonly subscriptions: Map<string, BlokScopeSubscription>;
|
|
404
446
|
private readonly boundLocals = new Set<string>();
|
|
405
447
|
private readonly into = new Set<string>();
|
|
406
|
-
private
|
|
448
|
+
private asks = false;
|
|
449
|
+
/** The id of the root that says `chrome="none"`, when it does. */
|
|
450
|
+
private chromeless: string | null = null;
|
|
407
451
|
private readonly colour: RegExp;
|
|
408
452
|
|
|
409
453
|
readonly scope: ResolvedBlokScope;
|
|
@@ -510,6 +554,7 @@ class Checker {
|
|
|
510
554
|
for (const local of this.scope.locals) {
|
|
511
555
|
if (local.persist && !this.boundLocals.has(local.key)) this.add('local.unused_persist', `locals.${local.key}`, {name: local.key});
|
|
512
556
|
}
|
|
557
|
+
if (this.chromeless !== null && this.kind.roots.includes('task') && !this.asks) this.add('chrome.no_ask', this.chromeless);
|
|
513
558
|
}
|
|
514
559
|
|
|
515
560
|
/* -- the walk -- */
|
|
@@ -566,25 +611,36 @@ class Checker {
|
|
|
566
611
|
|
|
567
612
|
private visitComponent(node: BlokComponentNode, ancestors: readonly BlokComponentNode[]): void {
|
|
568
613
|
const spec = this.view?.components.get(node.component);
|
|
569
|
-
if (this.view && !spec
|
|
570
|
-
this.
|
|
614
|
+
if (this.view && !spec) {
|
|
615
|
+
const foreign = this.view.foreign.get(node.component);
|
|
616
|
+
if (foreign !== undefined) {
|
|
617
|
+
this.add('catalog.target', node.id, {component: node.component, catalog: foreign, target: this.view.target ?? this.view.label});
|
|
618
|
+
} else if (this.view.complete) {
|
|
619
|
+
this.add('catalog.unknown_component', node.id, {component: node.component, catalogs: this.view.label});
|
|
620
|
+
}
|
|
571
621
|
}
|
|
572
622
|
if (spec) this.checkCatalog(node, spec, ancestors);
|
|
573
|
-
|
|
574
|
-
if (shadow && !this.shadowed.has(node.component)) {
|
|
575
|
-
this.shadowed.add(node.component);
|
|
576
|
-
this.add('catalog.shadow', node.id, {component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner});
|
|
577
|
-
}
|
|
578
|
-
if (node.component === ARGS_COMPONENT && this.scope.kind !== ASSIGN_KIND) {
|
|
579
|
-
this.add('assign.kind', node.id, {what: '<args>', n: article(this.scope.kind), kind: this.scope.kind});
|
|
580
|
-
}
|
|
623
|
+
this.checkHostPart(node, ancestors);
|
|
581
624
|
for (const prop of node.props ?? []) this.checkProp(node, prop, spec);
|
|
582
625
|
}
|
|
583
626
|
|
|
584
627
|
private checkCatalog(node: BlokComponentNode, spec: SpecComponent, ancestors: readonly BlokComponentNode[]): void {
|
|
585
628
|
const view = this.view;
|
|
586
629
|
if (!view) return;
|
|
587
|
-
|
|
630
|
+
const texts = (node.children ?? []).filter(child => child.component === TEXT_NODE);
|
|
631
|
+
const elements = (node.children ?? []).length - texts.length;
|
|
632
|
+
if (elements && !spec.acceptsChildren) this.add('catalog.children', node.id, {component: node.component});
|
|
633
|
+
if (texts.length) {
|
|
634
|
+
// Text is a child like any other; what takes it is the catalog's to say.
|
|
635
|
+
const textProp = spec.textProp;
|
|
636
|
+
if (textProp === null && !spec.acceptsChildren) {
|
|
637
|
+
this.add('catalog.text', node.id, {component: node.component, detail: 'takes no text'});
|
|
638
|
+
} else if (textProp !== null && (node.props ?? []).some(prop => prop.key === textProp)) {
|
|
639
|
+
this.add('catalog.text', node.id, {component: node.component, detail: `sets ${textProp} as an attribute and as its text`});
|
|
640
|
+
} else if (textProp !== null && !spec.acceptsChildren && (elements || texts.length > 1)) {
|
|
641
|
+
this.add('catalog.text', node.id, {component: node.component, detail: `takes one run of text as its ${textProp}, and no elements beside it`});
|
|
642
|
+
}
|
|
643
|
+
}
|
|
588
644
|
const present = new Set((node.props ?? []).map(prop => prop.key));
|
|
589
645
|
const known = new Set([...spec.props.map(prop => prop.key), WHEN_PROP]);
|
|
590
646
|
const unknown = [...present].filter(key => !known.has(key)).sort();
|
|
@@ -610,20 +666,31 @@ class Checker {
|
|
|
610
666
|
if (forbidden.length) {
|
|
611
667
|
this.add('catalog.placement', node.id, {component: node.component, detail: `must not be inside [${forbidden.map(pythonRepr).join(', ')}]`});
|
|
612
668
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
669
|
+
if (spec.kinds.length && !spec.kinds.includes(this.scope.kind)) {
|
|
670
|
+
this.add('catalog.kind', node.id, {component: node.component, kinds: spec.kinds.join(' and '), n: article(this.scope.kind), kind: this.scope.kind});
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* What the language itself says of the host's parts, whatever catalog draws
|
|
676
|
+
* them: a part placed anywhere claims its slot, and a root without chrome
|
|
677
|
+
* leaves the asks to the blok.
|
|
678
|
+
*/
|
|
679
|
+
private checkHostPart(node: BlokComponentNode, ancestors: readonly BlokComponentNode[]): void {
|
|
680
|
+
if (node.component === ASK_COMPONENT) this.asks = true;
|
|
681
|
+
if (ancestors.length === 0 && (node.props ?? []).some(prop => prop.key === CHROME_PROP && prop.static_value === CHROME_NONE)) {
|
|
682
|
+
this.chromeless = node.id;
|
|
683
|
+
}
|
|
684
|
+
if (this.vocabulary.hostParts.includes(node.component)) {
|
|
685
|
+
const inside = [...ancestors].reverse().find(ancestor => CONDITIONAL_COMPONENTS.has(ancestor.component));
|
|
686
|
+
if (inside) this.add('part.conditional', node.id, {component: node.component, inside: inside.component});
|
|
618
687
|
}
|
|
619
688
|
}
|
|
620
689
|
|
|
621
690
|
/** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
|
|
622
691
|
private checkDependencyKeys(node: BlokComponentNode, prop: BlokComponentProp): void {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
692
|
+
// catalog.kind says it: a Space and its parts belong to an action's own blok.
|
|
693
|
+
if (!RUN_KINDS.includes(this.scope.kind)) return;
|
|
627
694
|
const path = `${node.component}.${prop.key}`;
|
|
628
695
|
const value = prop.static_value;
|
|
629
696
|
const keys = typeof value === 'string' ? [value] : Array.isArray(value) ? value.filter((key): key is string => typeof key === 'string') : [];
|
|
@@ -667,8 +734,10 @@ class Checker {
|
|
|
667
734
|
}
|
|
668
735
|
}
|
|
669
736
|
}
|
|
670
|
-
|
|
671
|
-
|
|
737
|
+
// `task.answer(...)`, `task.cancel()` and their kin act on the task the blok is about.
|
|
738
|
+
const effect = prop.util_call?.operation;
|
|
739
|
+
if (effect !== undefined && vocabulary.functions.get(effect)?.taskOperation && !this.kind.roots.includes('task')) {
|
|
740
|
+
this.notInKind(node.id, effect, 'task', prop.key);
|
|
672
741
|
}
|
|
673
742
|
if (prop.key === BIND_PROP) {
|
|
674
743
|
const path = prop.dynamic_value?.path ?? null;
|
|
@@ -687,10 +756,6 @@ class Checker {
|
|
|
687
756
|
this.add('assign.kind', node.id, {what: 'assign.start()', n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
|
|
688
757
|
}
|
|
689
758
|
if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`)) this.checkDependencyKeys(node, prop);
|
|
690
|
-
if (node.component === 'Space' && prop.key === 'room' && !RUN_KINDS.includes(this.scope.kind)) {
|
|
691
|
-
// A Space places the run's dependencies: only an action's own blok (for a run, or for starting one) has them.
|
|
692
|
-
this.add('space.kind', node.id, {component: node.component, n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
|
|
693
|
-
}
|
|
694
759
|
if (node.component === TOAST_COMPONENT && prop.key === TOAST_TASK_PROP) {
|
|
695
760
|
const path = prop.dynamic_value?.path ?? null;
|
|
696
761
|
if (path === null || (path !== 'task' && !this.into.has(path))) this.add('toast.task', node.id, {what: path ?? what(prop)}, prop.key);
|
|
@@ -738,7 +803,11 @@ class Checker {
|
|
|
738
803
|
{token, suggestion: `${arbitrary.groups.utility}-<role> (${this.vocabulary.theme.colourRoles.slice(0, 6).join(', ')}, ...)`},
|
|
739
804
|
propKey,
|
|
740
805
|
);
|
|
806
|
+
continue;
|
|
741
807
|
}
|
|
808
|
+
// A colour that is no role is told as that; anything else outside the portable subset as this.
|
|
809
|
+
const unportable = unportableClass(token, this.vocabulary);
|
|
810
|
+
if (unportable !== null) this.add('class.not_portable', owner, {token, what: unportable}, propKey);
|
|
742
811
|
}
|
|
743
812
|
}
|
|
744
813
|
|
|
@@ -979,6 +1048,16 @@ class Checker {
|
|
|
979
1048
|
return null;
|
|
980
1049
|
}
|
|
981
1050
|
return openMatch(path);
|
|
1051
|
+
case 'assign':
|
|
1052
|
+
// `assign.given.<key>` is open below `given`: one flag per argument of the action.
|
|
1053
|
+
if (rest[0] === GIVEN_FIELD && rest.length > 1) {
|
|
1054
|
+
if (this.scope.args !== null && !this.scope.args.includes(rest[1])) {
|
|
1055
|
+
report('args.unknown', {path, key: rest[1], keys: this.scope.args.join(', ') || 'none'});
|
|
1056
|
+
return null;
|
|
1057
|
+
}
|
|
1058
|
+
return {key: rest[1], kind: 'BOOL'};
|
|
1059
|
+
}
|
|
1060
|
+
return this.descend(recordMatch('assign', vocabulary.records.assign.fields), rest, path, nodeId, propKey);
|
|
982
1061
|
case 'task':
|
|
983
1062
|
this.checkReturns(path, rest, nodeId, propKey);
|
|
984
1063
|
return this.descend(taskRecordMatch('task'), rest, path, nodeId, propKey);
|
|
@@ -1050,7 +1129,7 @@ class Checker {
|
|
|
1050
1129
|
const report = (code: string, fields: DiagnosticFields) => this.add(code, nodeId, fields, propKey);
|
|
1051
1130
|
if (head in agentSegments.fields) {
|
|
1052
1131
|
if (tail.length) report('path.unknown', {path, detail: `${head} of an agent has no fields`});
|
|
1053
|
-
return {key: head, kind: 'STRING'};
|
|
1132
|
+
return {key: head, kind: head === AGENT_CONNECTED ? 'BOOL' : 'STRING'};
|
|
1054
1133
|
}
|
|
1055
1134
|
if (head === agentSegments.tasks) {
|
|
1056
1135
|
if (!tail.length) {
|
|
@@ -1,28 +1,59 @@
|
|
|
1
|
-
import {readFileSync} from 'node:fs';
|
|
2
1
|
import {describe, expect, it} from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import {controlBlokComponents} from '../renderer/bloks/control';
|
|
3
|
+
import {BASE_CATALOG_REF, describeBlokContract, type SpecComponentJson} from '../renderer/runtime';
|
|
4
|
+
import baseCatalogJson from '../spec/catalogs/base@3.json';
|
|
5
|
+
import {baseFamilies} from './index';
|
|
5
6
|
import {parts} from './parts';
|
|
6
|
-
import baseCatalogJson from '../spec/catalogs/base@2.json';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** What the spec adds to an entry beside what its contract says: where it is listed, and what the spec alone knows of it. */
|
|
9
|
+
const SPEC_OWNED = ['group', 'kinds', 'touch', 'since', 'service'] as const;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type BaseEntry = SpecComponentJson & {group: string};
|
|
12
|
+
|
|
13
|
+
const shipped = new Map((baseCatalogJson.components as unknown as BaseEntry[]).map(component => [component.name, component]));
|
|
14
|
+
|
|
15
|
+
const asContract = (entry: BaseEntry): SpecComponentJson =>
|
|
16
|
+
Object.fromEntries(Object.entries(entry).filter(([key]) => !(SPEC_OWNED as readonly string[]).includes(key))) as SpecComponentJson;
|
|
17
|
+
|
|
18
|
+
describe('the families of the base catalog', () => {
|
|
19
|
+
it('are what the spec\'s base catalog says, component for component', () => {
|
|
20
|
+
for (const family of baseFamilies) {
|
|
21
|
+
expect(family.partOf, family.name).toBe(BASE_CATALOG_REF);
|
|
22
|
+
for (const described of describeBlokContract(family).components) {
|
|
23
|
+
const entry = shipped.get(described.name);
|
|
24
|
+
expect(entry, `<${described.name}> is not in the base catalog: rebuild it from \`pnpm spec:export\``).toBeDefined();
|
|
25
|
+
if (!entry) continue;
|
|
26
|
+
expect(entry.group, described.name).toBe(family.name);
|
|
27
|
+
expect(asContract(entry), described.name).toEqual(described);
|
|
28
|
+
}
|
|
14
29
|
}
|
|
15
30
|
});
|
|
16
31
|
|
|
17
|
-
it('hold each component once, and never one
|
|
18
|
-
const
|
|
19
|
-
const names =
|
|
32
|
+
it('hold each component once, and never one the renderer draws itself', () => {
|
|
33
|
+
const own = new Set(controlBlokComponents.map(component => component.name));
|
|
34
|
+
const names = baseFamilies.flatMap(family => Object.keys(family.components));
|
|
20
35
|
expect(names.filter((name, index) => names.indexOf(name) !== index)).toEqual([]);
|
|
21
|
-
expect(names.filter(name =>
|
|
36
|
+
expect(names.filter(name => own.has(name))).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('are, with what the renderer draws itself, the whole base catalog', () => {
|
|
40
|
+
const drawn = new Set([...baseFamilies.flatMap(family => Object.keys(family.components)), ...controlBlokComponents.map(component => component.name)]);
|
|
41
|
+
expect([...shipped.keys()].filter(name => !drawn.has(name))).toEqual([]);
|
|
42
|
+
expect([...drawn].filter(name => !shipped.has(name))).toEqual([]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('take, where the renderer draws a component itself, the props the base catalog lists', () => {
|
|
46
|
+
for (const component of controlBlokComponents) {
|
|
47
|
+
const entry = shipped.get(component.name);
|
|
48
|
+
expect(entry, component.name).toBeDefined();
|
|
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();
|
|
51
|
+
expect(props, component.name).toEqual((entry?.props ?? []).map(prop => prop.key).sort());
|
|
52
|
+
}
|
|
22
53
|
});
|
|
23
54
|
|
|
24
55
|
it('use every contract the package defines', () => {
|
|
25
|
-
const used = new Set(
|
|
56
|
+
const used = new Set(baseFamilies.flatMap(family => Object.keys(family.components)));
|
|
26
57
|
expect(Object.keys(parts).filter(name => !used.has(name))).toEqual([]);
|
|
27
58
|
});
|
|
28
59
|
});
|
package/src/catalogs/html.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {defineBlokCatalog} from '../renderer/runtime/catalog';
|
|
1
|
+
import {BASE_CATALOG_REF, defineBlokCatalog} from '../renderer/runtime/catalog';
|
|
2
2
|
import {parts} from './parts';
|
|
3
3
|
|
|
4
|
-
/** `html
|
|
4
|
+
/** The `html` family of the base catalog. */
|
|
5
5
|
export const htmlCatalog = defineBlokCatalog({
|
|
6
6
|
name: "html",
|
|
7
|
-
|
|
7
|
+
partOf: BASE_CATALOG_REF,
|
|
8
8
|
description: "Plain containers that translate directly to React Native: div (View), p and span (Text).",
|
|
9
9
|
components: {
|
|
10
10
|
div: parts.div,
|
package/src/catalogs/index.ts
CHANGED
|
@@ -8,5 +8,9 @@ import {uiCatalog} from './ui';
|
|
|
8
8
|
export {htmlCatalog, logoCatalog, sceneCatalog, shadcnCatalog, structureCatalog, uiCatalog};
|
|
9
9
|
export * from './props';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The families of the base catalog this package holds contracts for: every
|
|
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`).
|
|
15
|
+
*/
|
|
16
|
+
export const baseFamilies = [uiCatalog, htmlCatalog, logoCatalog, sceneCatalog, structureCatalog, shadcnCatalog] as const;
|
package/src/catalogs/logo.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {defineBlokCatalog} from '../renderer/runtime/catalog';
|
|
1
|
+
import {BASE_CATALOG_REF, defineBlokCatalog} from '../renderer/runtime/catalog';
|
|
2
2
|
import {parts} from './parts';
|
|
3
3
|
|
|
4
|
-
/** `logo
|
|
4
|
+
/** The `logo` family of the base catalog. */
|
|
5
5
|
export const logoCatalog = defineBlokCatalog({
|
|
6
6
|
name: "logo",
|
|
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
10
|
ActionLogo: parts.ActionLogo,
|
|
@@ -320,6 +320,38 @@ export const formContracts = {
|
|
|
320
320
|
})
|
|
321
321
|
.describe('A labelled form field with description and error slots.'),
|
|
322
322
|
},
|
|
323
|
+
Combobox: {
|
|
324
|
+
schema: z
|
|
325
|
+
.object({
|
|
326
|
+
bind: markBindSchema(bindSchema.describe('Data-model path holding the picked value.')),
|
|
327
|
+
value: BlokPropSchemas.DynamicString.optional().describe('Controlled value.'),
|
|
328
|
+
defaultValue: BlokPropSchemas.DynamicString.optional().describe('Initial value.'),
|
|
329
|
+
options: z
|
|
330
|
+
.array(z.union([z.string(), z.object({value: z.string(), label: z.string().optional()})]))
|
|
331
|
+
.optional()
|
|
332
|
+
.describe('What can be picked: strings, or `{value, label}` objects. Typing narrows them.'),
|
|
333
|
+
placeholder: BlokPropSchemas.DynamicString.optional().describe('Shown while nothing is picked.'),
|
|
334
|
+
searchPlaceholder: BlokPropSchemas.DynamicString.optional().describe('Shown in the search field.'),
|
|
335
|
+
emptyText: BlokPropSchemas.DynamicString.optional().describe('Shown when typing matches nothing.'),
|
|
336
|
+
disabled: disabledSchema,
|
|
337
|
+
className: classNameSchema,
|
|
338
|
+
onChange: actionProp('Runs on selection. Arguments may read event.value.'),
|
|
339
|
+
})
|
|
340
|
+
.describe('A select with a search field: for a list too long to scan.'),
|
|
341
|
+
},
|
|
342
|
+
DatePicker: {
|
|
343
|
+
schema: z
|
|
344
|
+
.object({
|
|
345
|
+
bind: markBindSchema(bindSchema.describe('Data-model path holding an ISO date string (YYYY-MM-DD).')),
|
|
346
|
+
value: BlokPropSchemas.DynamicString.optional().describe('Controlled ISO date.'),
|
|
347
|
+
defaultValue: BlokPropSchemas.DynamicString.optional().describe('Initial ISO date.'),
|
|
348
|
+
placeholder: BlokPropSchemas.DynamicString.optional().describe('Shown while no date is picked.'),
|
|
349
|
+
disabled: disabledSchema,
|
|
350
|
+
className: classNameSchema,
|
|
351
|
+
onChange: actionProp('Runs on selection. Arguments may read event.value.'),
|
|
352
|
+
})
|
|
353
|
+
.describe('A button that opens a calendar and shows the date picked.'),
|
|
354
|
+
},
|
|
323
355
|
Calendar: {
|
|
324
356
|
schema: z
|
|
325
357
|
.object({
|