@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/renderer/declare.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {baseBlokCatalog} from './baseCatalog';
|
|
2
2
|
import {
|
|
3
|
+
BASE_CATALOG_ADDRESS,
|
|
4
|
+
BASE_CATALOG_REF,
|
|
3
5
|
catalogRef,
|
|
4
6
|
describeBlokComponent,
|
|
5
7
|
extendBlokCatalog,
|
|
@@ -8,28 +10,51 @@ import {
|
|
|
8
10
|
type BlokComponentDefinition,
|
|
9
11
|
type SpecCatalogJson,
|
|
10
12
|
} from './runtime';
|
|
13
|
+
import {baseCatalog} from '../spec/catalogs';
|
|
14
|
+
import type {BlokContextName} from '../spec/vocabulary';
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
|
-
* A UI's catalog, declared:
|
|
17
|
+
* A UI's catalog, declared: what it draws, and nothing inferred.
|
|
14
18
|
*
|
|
15
|
-
* - `catalog` is what its renderers draw:
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* - `catalog` is what its renderers draw: the language's own elements and every
|
|
20
|
+
* implementation.
|
|
21
|
+
* - `contexts` are the contexts in which it draws the base catalog whole
|
|
22
|
+
* (`HTML`, `SCENE`, `LOGO`): a blok written for the base catalog and drawn in
|
|
23
|
+
* one of them is known to render here.
|
|
24
|
+
* - `claims` are the catalogs it speaks: the base catalog when it draws it
|
|
25
|
+
* whole in at least one context, and each published catalog of its own.
|
|
26
|
+
* - Its own catalogs are part of `catalog`; what it publishes as its app
|
|
27
|
+
* catalog is `ownComponentsOf(catalog)`, which also counts what its modules
|
|
28
|
+
* add later (`addBlokComponents`).
|
|
24
29
|
*/
|
|
25
30
|
export type BlokUi = {
|
|
26
31
|
name: string;
|
|
27
32
|
description: string | null;
|
|
28
33
|
catalog: BlokCatalog;
|
|
29
34
|
implementations: readonly BlokCatalogImplementation[];
|
|
35
|
+
contexts: readonly BlokContextName[];
|
|
30
36
|
claims: readonly string[];
|
|
31
37
|
};
|
|
32
38
|
|
|
39
|
+
const CONTEXTS: readonly BlokContextName[] = ['HTML', 'SCENE', 'LOGO'];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The context a base component counts towards: its own, and for one that
|
|
43
|
+
* bridges html and another context (`Scene` opens a scene inside html), the
|
|
44
|
+
* other one: a renderer that draws no 3D still draws html whole.
|
|
45
|
+
*/
|
|
46
|
+
const contextOf = (component: {context: BlokContextName; childrenContext: BlokContextName | null}): BlokContextName =>
|
|
47
|
+
component.context !== 'HTML' ? component.context : (component.childrenContext ?? 'HTML');
|
|
48
|
+
|
|
49
|
+
/** The contexts in which `catalog` draws every component of the base catalog. */
|
|
50
|
+
export const baseContextsOf = (catalog: BlokCatalog): BlokContextName[] => {
|
|
51
|
+
const components = baseCatalog().components;
|
|
52
|
+
return CONTEXTS.filter(context => {
|
|
53
|
+
const drawn = components.filter(component => !component.inheritsContext && contextOf(component) === context);
|
|
54
|
+
return drawn.length > 0 && drawn.every(component => catalog.components.has(component.name));
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
33
58
|
export const declareBlokUi = (declaration: {
|
|
34
59
|
name: string;
|
|
35
60
|
description?: string;
|
|
@@ -41,42 +66,55 @@ export const declareBlokUi = (declaration: {
|
|
|
41
66
|
if (twice.length > 0) {
|
|
42
67
|
throw new Error(`${declaration.name} implements ${[...new Set(twice)].join(', ')} twice`);
|
|
43
68
|
}
|
|
69
|
+
const catalog = extendBlokCatalog(
|
|
70
|
+
baseBlokCatalog,
|
|
71
|
+
declaration.name,
|
|
72
|
+
implementations.flatMap(implementation => implementation.components),
|
|
73
|
+
);
|
|
74
|
+
const contexts = baseContextsOf(catalog);
|
|
44
75
|
return {
|
|
45
76
|
name: declaration.name,
|
|
46
77
|
description: declaration.description ?? null,
|
|
47
|
-
catalog
|
|
48
|
-
baseBlokCatalog,
|
|
49
|
-
declaration.name,
|
|
50
|
-
implementations.flatMap(implementation => implementation.components),
|
|
51
|
-
),
|
|
78
|
+
catalog,
|
|
52
79
|
implementations,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.
|
|
56
|
-
|
|
80
|
+
contexts,
|
|
81
|
+
claims: [
|
|
82
|
+
...(contexts.length > 0 ? [BASE_CATALOG_REF] : []),
|
|
83
|
+
...implementations
|
|
84
|
+
.filter(implementation => implementation.contract.partOf === null && implementation.contract.version !== null && implementation.whole)
|
|
85
|
+
.map(implementation => catalogRef(implementation.contract))
|
|
86
|
+
.sort(),
|
|
87
|
+
],
|
|
57
88
|
};
|
|
58
89
|
};
|
|
59
90
|
|
|
60
91
|
/**
|
|
61
|
-
* What a UI
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* and a global component a module drew over (it is the module's now).
|
|
92
|
+
* What a UI draws beyond the base catalog: every component of its catalog
|
|
93
|
+
* that is neither the language's own nor one of the base catalog's. Its own
|
|
94
|
+
* catalogs' components, and what its modules added since (`addBlokComponents`).
|
|
65
95
|
*/
|
|
66
|
-
export const
|
|
96
|
+
export const ownComponentsOf = (catalog: BlokCatalog): BlokComponentDefinition[] =>
|
|
67
97
|
[...catalog.components.values()].filter(
|
|
68
|
-
component => catalog.base?.components.get(component.name) !== component && component.origin
|
|
98
|
+
component => catalog.base?.components.get(component.name) !== component && component.origin !== BASE_CATALOG_REF,
|
|
69
99
|
);
|
|
70
100
|
|
|
71
101
|
/**
|
|
72
|
-
* A UI's
|
|
73
|
-
*
|
|
74
|
-
*
|
|
102
|
+
* A UI's app catalog as the spec writes one (`{id, name, version, minor,
|
|
103
|
+
* extends, components}`): what it publishes at `id`, registers with the
|
|
104
|
+
* server, and hands the language (`setAppBlokCatalog(parseSpecCatalog(...))`)
|
|
105
|
+
* so its own parser, checks and editor know the components only it draws.
|
|
75
106
|
*/
|
|
76
|
-
export const
|
|
77
|
-
name,
|
|
78
|
-
|
|
79
|
-
|
|
107
|
+
export const blokCatalogSpec = (
|
|
108
|
+
meta: {id: string; name: string; version: number; minor?: number; extends?: string; description: string},
|
|
109
|
+
catalog: BlokCatalog,
|
|
110
|
+
): SpecCatalogJson => ({
|
|
111
|
+
id: meta.id,
|
|
112
|
+
name: meta.name,
|
|
113
|
+
version: meta.version,
|
|
114
|
+
minor: meta.minor ?? 0,
|
|
115
|
+
extends: meta.extends ?? BASE_CATALOG_ADDRESS,
|
|
116
|
+
description: meta.description,
|
|
117
|
+
components: ownComponentsOf(catalog)
|
|
80
118
|
.map(component => describeBlokComponent(component.name, component))
|
|
81
119
|
.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0)),
|
|
82
120
|
});
|
|
@@ -18,7 +18,7 @@ describe('coverage', () => {
|
|
|
18
18
|
it('implements every pure vocabulary function, and nothing else', () => {
|
|
19
19
|
const declared = [...loadVocabulary().functions.values()].filter(fn => !fn.effect).map(fn => fn.name).sort();
|
|
20
20
|
expect([...v2Functions.keys()].sort()).toEqual(declared);
|
|
21
|
-
expect(declared).toHaveLength(
|
|
21
|
+
expect(declared).toHaveLength(117);
|
|
22
22
|
expect(undeclaredImplementations()).toEqual([]);
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -153,6 +153,16 @@ describe('the null table', () => {
|
|
|
153
153
|
['fmt.quantity', {value: null}, ''],
|
|
154
154
|
['time.diff', {start: null, end: NOW}, null],
|
|
155
155
|
['time.diff', {start: NOW, end: null}, null],
|
|
156
|
+
['time.add', {value: null, seconds: 5}, null],
|
|
157
|
+
['time.before', {a: null, b: NOW}, false],
|
|
158
|
+
['time.after', {a: NOW, b: null}, false],
|
|
159
|
+
['list.where', {value: null, key: 'x'}, []],
|
|
160
|
+
['list.find', {value: null, key: 'x'}, null],
|
|
161
|
+
['list.count', {value: null, key: 'x'}, 0],
|
|
162
|
+
['list.concat', {value: null, other: [1]}, [1]],
|
|
163
|
+
['obj.merge', {value: null, other: {a: 1}}, {a: 1}],
|
|
164
|
+
['obj.pick', {value: null, keys: ['a']}, {}],
|
|
165
|
+
['obj.omit', {value: null, keys: ['a']}, {}],
|
|
156
166
|
];
|
|
157
167
|
|
|
158
168
|
it.each(nullCases)('%s(%j) is %j', (name, args, expected) => {
|
|
@@ -313,3 +323,32 @@ describe('semantics', () => {
|
|
|
313
323
|
expect(call('fmt.duration', {seconds: time('2026-10-25T13:30:00Z')})).toBe('1h 30m');
|
|
314
324
|
});
|
|
315
325
|
});
|
|
326
|
+
|
|
327
|
+
describe('filtering, joining and moments', () => {
|
|
328
|
+
const rows = [
|
|
329
|
+
{name: 'a', state: {ok: true}, n: 1},
|
|
330
|
+
{name: 'b', state: {ok: false}, n: 2},
|
|
331
|
+
{name: 'c', state: {ok: true}, n: 2},
|
|
332
|
+
];
|
|
333
|
+
|
|
334
|
+
it('keeps, finds and counts the items a key picks', () => {
|
|
335
|
+
expect(call('list.where', {value: rows, key: 'n', equals: 2})).toEqual([rows[1], rows[2]]);
|
|
336
|
+
expect(call('list.where', {value: rows, key: 'state.ok'})).toEqual([rows[0], rows[2]]);
|
|
337
|
+
expect(call('list.find', {value: rows, key: 'name', equals: 'b'})).toEqual(rows[1]);
|
|
338
|
+
expect(call('list.find', {value: rows, key: 'name', equals: 'z'})).toBeNull();
|
|
339
|
+
expect(call('list.count', {value: rows, key: 'state.ok'})).toBe(2);
|
|
340
|
+
expect(call('list.concat', {value: [1], other: [2, 3]})).toEqual([1, 2, 3]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('merges, picks and omits keys', () => {
|
|
344
|
+
expect(call('obj.merge', {value: {a: 1, b: 1}, other: {b: 2}})).toEqual({a: 1, b: 2});
|
|
345
|
+
expect(call('obj.pick', {value: {a: 1, b: 2}, keys: ['a']})).toEqual({a: 1});
|
|
346
|
+
expect(call('obj.omit', {value: {a: 1, b: 2}, keys: ['a']})).toEqual({b: 2});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('moves and orders moments without reading the clock', () => {
|
|
350
|
+
expect(call('time.add', {value: '2026-01-01T00:00:00Z', seconds: 90})).toBe('2026-01-01T00:01:30.000Z');
|
|
351
|
+
expect(call('time.before', {a: '2026-01-01T00:00:00Z', b: '2026-01-02T00:00:00Z'})).toBe(true);
|
|
352
|
+
expect(call('time.after', {a: '2026-01-01T00:00:00Z', b: '2026-01-02T00:00:00Z'})).toBe(false);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
@@ -282,6 +282,19 @@ const strTest =
|
|
|
282
282
|
return value !== null && other !== null && test(value, other);
|
|
283
283
|
};
|
|
284
284
|
|
|
285
|
+
/** What list.where keeps: the items whose `key` deep-equals `equals`, or is truthy when `equals` is left out. */
|
|
286
|
+
const matching = (args: Args): ((item: unknown) => boolean) => {
|
|
287
|
+
const key = optStr(args.key, '', 'key');
|
|
288
|
+
const any = isNull(args.equals);
|
|
289
|
+
return item => {
|
|
290
|
+
const found = readDotted(item, key).value;
|
|
291
|
+
return any ? truthy(found) : deepEqual(found, args.equals);
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/** Key names as a list holds them. */
|
|
296
|
+
const keyNames = (value: unknown): string[] => (list(value) ?? []).filter((key): key is string => typeof key === 'string');
|
|
297
|
+
|
|
285
298
|
const listOr =
|
|
286
299
|
(fallback: () => unknown, operate: (value: unknown[], args: Args) => unknown): Impl =>
|
|
287
300
|
args => {
|
|
@@ -517,6 +530,10 @@ const IMPLEMENTATIONS: Readonly<Partial<Record<string, Impl>>> = {
|
|
|
517
530
|
.map(entry => entry.item);
|
|
518
531
|
},
|
|
519
532
|
),
|
|
533
|
+
'list.where': listOr(() => [], (value, args) => value.filter(matching(args))),
|
|
534
|
+
'list.find': listOr(() => null, (value, args) => value.find(matching(args)) ?? null),
|
|
535
|
+
'list.count': listOr(() => 0, (value, args) => value.filter(matching(args)).length),
|
|
536
|
+
'list.concat': args => [...(list(args.value) ?? []), ...(list(args.other) ?? [])],
|
|
520
537
|
'list.range': args => {
|
|
521
538
|
const start = num(args.start);
|
|
522
539
|
const end = num(args.end);
|
|
@@ -547,6 +564,21 @@ const IMPLEMENTATIONS: Readonly<Partial<Record<string, Impl>>> = {
|
|
|
547
564
|
return key !== null && Object.prototype.hasOwnProperty.call(value, key);
|
|
548
565
|
},
|
|
549
566
|
),
|
|
567
|
+
'obj.merge': args => ({...(dict(args.value) ?? {}), ...(dict(args.other) ?? {})}),
|
|
568
|
+
'obj.pick': dictOr(
|
|
569
|
+
() => ({}),
|
|
570
|
+
(value, args) => {
|
|
571
|
+
const keys = keyNames(args.keys);
|
|
572
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => keys.includes(key)));
|
|
573
|
+
},
|
|
574
|
+
),
|
|
575
|
+
'obj.omit': dictOr(
|
|
576
|
+
() => ({}),
|
|
577
|
+
(value, args) => {
|
|
578
|
+
const keys = keyNames(args.keys);
|
|
579
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => !keys.includes(key)));
|
|
580
|
+
},
|
|
581
|
+
),
|
|
550
582
|
'obj.keys': dictOr(() => [], value => Object.keys(value)),
|
|
551
583
|
'obj.values': dictOr(() => [], value => Object.values(value)),
|
|
552
584
|
'obj.entries': dictOr(() => [], value => Object.entries(value).map(([key, item]) => ({key, value: item}))),
|
|
@@ -649,6 +681,21 @@ const IMPLEMENTATIONS: Readonly<Partial<Record<string, Impl>>> = {
|
|
|
649
681
|
const end = timeOf(args.end);
|
|
650
682
|
return start === null || end === null ? null : (end - start) / 1000;
|
|
651
683
|
},
|
|
684
|
+
'time.add': args => {
|
|
685
|
+
const start = timeOf(args.value);
|
|
686
|
+
const seconds = num(args.seconds);
|
|
687
|
+
return start === null || seconds === null ? null : new Date(start + seconds * 1000).toISOString();
|
|
688
|
+
},
|
|
689
|
+
'time.before': args => {
|
|
690
|
+
const a = timeOf(args.a);
|
|
691
|
+
const b = timeOf(args.b);
|
|
692
|
+
return a !== null && b !== null && a < b;
|
|
693
|
+
},
|
|
694
|
+
'time.after': args => {
|
|
695
|
+
const a = timeOf(args.a);
|
|
696
|
+
const b = timeOf(args.b);
|
|
697
|
+
return a !== null && b !== null && a > b;
|
|
698
|
+
},
|
|
652
699
|
};
|
|
653
700
|
|
|
654
701
|
const build = (): ReadonlyMap<string, BlokV2Function> => {
|
|
@@ -4,24 +4,40 @@ import type {BlokComponentContract, BlokComponentDefinition, BlokRenderArgs} fro
|
|
|
4
4
|
/**
|
|
5
5
|
* Catalogs as the UI defines them.
|
|
6
6
|
*
|
|
7
|
-
* A *contract* (`defineBlokCatalog`) says which components a
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
7
|
+
* A *contract* (`defineBlokCatalog`) says which components a set holds and what
|
|
8
|
+
* each takes: name, schema, placement. It draws nothing. There are two sorts:
|
|
9
|
+
*
|
|
10
|
+
* - A *family* of the base catalog (`ui`, `html`, `shadcn`, `structure`,
|
|
11
|
+
* `scene`, `logo`): `partOf` names the catalog it is part of (`base@3`). The
|
|
12
|
+
* base catalog is the spec's, and every renderer draws it whole; the families
|
|
13
|
+
* are how this package holds its contracts, one toolkit at a time.
|
|
14
|
+
* - A UI's *own* catalog (the Orkestrator's MikroScene parts): what it draws
|
|
15
|
+
* beyond the base. Given an `id` (the address it is published at) and a
|
|
16
|
+
* version it is an app catalog a blok can be written for.
|
|
12
17
|
*
|
|
13
18
|
* An *implementation* (`implementBlokCatalog`) is the app's: one render per
|
|
14
19
|
* component of a contract, a map the compiler checks against the contract.
|
|
15
20
|
*/
|
|
16
21
|
|
|
22
|
+
/** The base catalog, as components of it are tagged (`origin`). */
|
|
23
|
+
export const BASE_CATALOG_REF = 'base@3';
|
|
24
|
+
/** The address the base catalog is published at: what a blok is written for when it names none. */
|
|
25
|
+
export const BASE_CATALOG_ADDRESS = 'https://arkitekt.live/catalogs/base/v3';
|
|
26
|
+
|
|
17
27
|
export type BlokComponentContracts = Record<string, BlokComponentContract<any>>;
|
|
18
28
|
|
|
19
29
|
export type BlokCatalogContract<TComponents extends BlokComponentContracts = BlokComponentContracts> = {
|
|
20
30
|
name: string;
|
|
21
|
-
/** Set on a
|
|
31
|
+
/** Set on a published catalog (an app catalog's `1`); null on a family, and on a UI's own that nothing publishes. */
|
|
22
32
|
version: number | null;
|
|
23
33
|
description: string;
|
|
24
34
|
components: TComponents;
|
|
35
|
+
/** For a family: the catalog it is part of (`base@3`). Null on a catalog of its own. */
|
|
36
|
+
partOf: string | null;
|
|
37
|
+
/** For a published catalog: the address it is published at, which is what a blok names it by. */
|
|
38
|
+
id: string | null;
|
|
39
|
+
/** The id of the catalog it adds to; the base catalog's when left out. */
|
|
40
|
+
extends: string | null;
|
|
25
41
|
};
|
|
26
42
|
|
|
27
43
|
export const defineBlokCatalog = <const TComponents extends BlokComponentContracts>(contract: {
|
|
@@ -29,9 +45,18 @@ export const defineBlokCatalog = <const TComponents extends BlokComponentContrac
|
|
|
29
45
|
version?: number;
|
|
30
46
|
description: string;
|
|
31
47
|
components: TComponents;
|
|
32
|
-
|
|
48
|
+
partOf?: string;
|
|
49
|
+
id?: string;
|
|
50
|
+
extends?: string;
|
|
51
|
+
}): BlokCatalogContract<TComponents> => ({
|
|
52
|
+
...contract,
|
|
53
|
+
version: contract.version ?? null,
|
|
54
|
+
partOf: contract.partOf ?? null,
|
|
55
|
+
id: contract.id ?? null,
|
|
56
|
+
extends: contract.extends ?? null,
|
|
57
|
+
});
|
|
33
58
|
|
|
34
|
-
/** How a
|
|
59
|
+
/** How a contract is named: `name@version`, or the bare name of a family or of a UI's own unpublished catalog. */
|
|
35
60
|
export const catalogRef = (contract: Pick<BlokCatalogContract, 'name' | 'version'>): string =>
|
|
36
61
|
contract.version === null ? contract.name : `${contract.name}@${contract.version}`;
|
|
37
62
|
|
|
@@ -83,7 +108,7 @@ export function implementBlokCatalog(
|
|
|
83
108
|
}
|
|
84
109
|
const components = Object.entries(contract.components).flatMap(([name, component]): BlokComponentDefinition[] => {
|
|
85
110
|
const render = renders[name];
|
|
86
|
-
return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: ref}] : [];
|
|
111
|
+
return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: contract.partOf ?? ref}] : [];
|
|
87
112
|
});
|
|
88
113
|
return {contract, components, whole: missing.length === 0};
|
|
89
114
|
}
|
|
@@ -94,7 +119,7 @@ export function implementBlokCatalog(
|
|
|
94
119
|
* once. The UI owns both, so there is nothing to check one against.
|
|
95
120
|
*/
|
|
96
121
|
export const ownBlokCatalog = (
|
|
97
|
-
meta: {name: string; version?: number; description: string},
|
|
122
|
+
meta: {name: string; version?: number; description: string; id?: string; extends?: string},
|
|
98
123
|
components: readonly BlokComponentDefinition[],
|
|
99
124
|
): BlokCatalogImplementation => {
|
|
100
125
|
const contract = defineBlokCatalog({
|
|
@@ -67,6 +67,12 @@ type BlokComponentApi = {
|
|
|
67
67
|
* where the schema itself only says "a path".
|
|
68
68
|
*/
|
|
69
69
|
bindKinds?: Readonly<Record<string, string>>;
|
|
70
|
+
/** The blok kinds it may be placed in (`assign`); any kind when left out. */
|
|
71
|
+
kinds?: readonly string[];
|
|
72
|
+
/** The service it needs where it is drawn (`mikro`): without it a notice shows in its place. */
|
|
73
|
+
service?: string;
|
|
74
|
+
/** The minor of its catalog that added it; the first when left out. */
|
|
75
|
+
since?: number;
|
|
70
76
|
};
|
|
71
77
|
|
|
72
78
|
/**
|
|
@@ -82,7 +88,7 @@ export type BlokComponentDefinition = BlokComponentApi & {
|
|
|
82
88
|
name: string;
|
|
83
89
|
schema: BlokObjectSchema;
|
|
84
90
|
render: React.ComponentType<BlokRenderArgs>;
|
|
85
|
-
/** The catalog
|
|
91
|
+
/** The catalog it is of (`base@3` for a component of one of its families, `newswitch`); unset for one built on its own. */
|
|
86
92
|
origin?: string;
|
|
87
93
|
};
|
|
88
94
|
|
|
@@ -99,6 +105,9 @@ export const createBlokComponent = <TSchema extends BlokObjectSchema>(
|
|
|
99
105
|
textProp: api.textProp,
|
|
100
106
|
events: api.events,
|
|
101
107
|
bindKinds: api.bindKinds,
|
|
108
|
+
kinds: api.kinds,
|
|
109
|
+
service: api.service,
|
|
110
|
+
since: api.since,
|
|
102
111
|
render: render as React.ComponentType<BlokRenderArgs>,
|
|
103
112
|
});
|
|
104
113
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {BlokTaskControl} from './task';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import {useStore} from 'zustand';
|
|
3
4
|
import {createStore} from 'zustand/vanilla';
|
|
@@ -151,6 +152,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
151
152
|
travelAt?: string | null;
|
|
152
153
|
answerTask?: (values: Record<string, unknown>) => unknown;
|
|
153
154
|
startRun?: () => unknown;
|
|
155
|
+
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
154
156
|
}): BlokRuntimeStore => {
|
|
155
157
|
const initialDataModel = config?.initialDataModel;
|
|
156
158
|
const keptValues = config?.keptValues ?? {};
|
|
@@ -175,6 +177,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
175
177
|
fetchMoreQuery: undefined,
|
|
176
178
|
answerTask: config?.answerTask,
|
|
177
179
|
startRun: config?.startRun,
|
|
180
|
+
controlTask: config?.controlTask,
|
|
178
181
|
setStatus: (path, status) => {
|
|
179
182
|
const key = canonicalStatusPath(path);
|
|
180
183
|
set(currentState => {
|
|
@@ -214,6 +217,9 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
214
217
|
setStartRun: start => {
|
|
215
218
|
set({startRun: start});
|
|
216
219
|
},
|
|
220
|
+
setControlTask: control => {
|
|
221
|
+
set({controlTask: control});
|
|
222
|
+
},
|
|
217
223
|
setInitialDataModel: nextInitialDataModel => {
|
|
218
224
|
set(currentState => {
|
|
219
225
|
if (Object.is(currentState.initialDataModel, nextInitialDataModel)) {
|
|
@@ -5,10 +5,12 @@ import {isRequiredField} from './preflight';
|
|
|
5
5
|
import {isActionSchema, isBindSchema, unwrapSchema} from './schemas';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A contract
|
|
9
|
-
* `blok/catalogs/`)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* A contract in the spec's terms: what a catalog file (`spec/catalogs/base@3.json`,
|
|
9
|
+
* arkitekt-spec's `blok/catalogs/`) says of each component. Written from the
|
|
10
|
+
* contract, never by hand: the zod schemas are the source of a component's
|
|
11
|
+
* props and documentation, the JSON what they say in the spec's terms. The
|
|
12
|
+
* spec's base catalog is built from it (`pnpm spec:export`), and an app
|
|
13
|
+
* catalog is published as it (`blokCatalogSpec`).
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
export type SpecValueKind = 'STRING' | 'INT' | 'FLOAT' | 'BOOL' | 'DICT' | 'LIST' | 'ANY' | 'CALLBACK' | 'ASSET';
|
|
@@ -33,11 +35,19 @@ export type SpecComponentJson = {
|
|
|
33
35
|
not_downstream_of: string[];
|
|
34
36
|
text_prop: string | null;
|
|
35
37
|
props: SpecPropJson[];
|
|
38
|
+
kinds?: string[];
|
|
39
|
+
service?: string;
|
|
40
|
+
since?: number;
|
|
36
41
|
};
|
|
37
42
|
|
|
38
43
|
export type SpecCatalogJson = {
|
|
44
|
+
/** The address a published catalog is known by. */
|
|
45
|
+
id?: string;
|
|
39
46
|
name: string;
|
|
40
47
|
version?: number;
|
|
48
|
+
minor?: number;
|
|
49
|
+
/** The id of the catalog it adds to. */
|
|
50
|
+
extends?: string;
|
|
41
51
|
description: string;
|
|
42
52
|
components: SpecComponentJson[];
|
|
43
53
|
};
|
|
@@ -163,6 +173,9 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
|
|
|
163
173
|
not_downstream_of: [...(placement.notDownstreamOf ?? [])],
|
|
164
174
|
text_prop: component.textProp ?? null,
|
|
165
175
|
props,
|
|
176
|
+
...(component.kinds?.length ? {kinds: [...component.kinds]} : {}),
|
|
177
|
+
...(component.service ? {service: component.service} : {}),
|
|
178
|
+
...(component.since ? {since: component.since} : {}),
|
|
166
179
|
};
|
|
167
180
|
};
|
|
168
181
|
|
|
@@ -195,6 +195,7 @@ const createLiveResolutionContext = (
|
|
|
195
195
|
fetchMoreQuery: (name, variables) => store.getState().fetchMoreQuery?.(name, variables),
|
|
196
196
|
answerTask: values => store.getState().answerTask?.(values),
|
|
197
197
|
startRun: () => store.getState().startRun?.(),
|
|
198
|
+
controlTask: store.getState().controlTask ? operation => store.getState().controlTask?.(operation) : undefined,
|
|
198
199
|
travelling: store.getState().travelAt !== null,
|
|
199
200
|
invokeFunction: (name, args, options) => store.getState().invokeFunction(name, args, options),
|
|
200
201
|
dispatchAction: (action, component, observe) =>
|
|
@@ -3,6 +3,7 @@ import type {BlokCatalog} from './functions';
|
|
|
3
3
|
import {BlokSchemas, isActionSchema} from './schemas';
|
|
4
4
|
import type {PreparedBlokNode} from './tree';
|
|
5
5
|
import type {BlokActionArgument, BlokComponentNode, BlokComponentProp} from './types';
|
|
6
|
+
import {lowerBlokText} from './text';
|
|
6
7
|
import {extractUiComponents, isRecord} from './utils';
|
|
7
8
|
import {loadVocabulary} from '../../spec/vocabulary';
|
|
8
9
|
|
|
@@ -192,7 +193,9 @@ export const preflightBlokDocument = (
|
|
|
192
193
|
const invalidNodes = new Map<string, string[]>();
|
|
193
194
|
const rootIds: string[] = [];
|
|
194
195
|
const unknownKinds = new Map<string, string[]>();
|
|
195
|
-
|
|
196
|
+
// Text is stored as nodes; what each component does with it is the catalog's to say.
|
|
197
|
+
const roots = extractUiComponents(uiComponents).map(raw => lowerBlokText(raw, catalog));
|
|
198
|
+
roots.forEach(raw => unknownCallKinds(raw, unknownKinds));
|
|
196
199
|
|
|
197
200
|
const pushError = (error: BlokValidationError) => {
|
|
198
201
|
errors.push(error);
|
|
@@ -242,7 +245,7 @@ export const preflightBlokDocument = (
|
|
|
242
245
|
});
|
|
243
246
|
};
|
|
244
247
|
|
|
245
|
-
|
|
248
|
+
roots.forEach((rawComponent, componentIndex) => {
|
|
246
249
|
const basePath = `uiComponents[${componentIndex}]`;
|
|
247
250
|
const parsed = BlokSchemas.ComponentNode.safeParse(rawComponent);
|
|
248
251
|
|
|
@@ -441,6 +441,20 @@ describe("a callback does exactly one thing (v2)", () => {
|
|
|
441
441
|
expect(runActionCall(call, createContext({}), component).ok).toBe(false);
|
|
442
442
|
});
|
|
443
443
|
|
|
444
|
+
it("controls the task with task.cancel and its kin, where a host controls one, and never in the past", () => {
|
|
445
|
+
const controlTask = vi.fn(() => "taken");
|
|
446
|
+
for (const operation of ["cancel", "pause", "resume", "step", "interrupt"]) {
|
|
447
|
+
const call = {type: "util" as const, call: {operation: `task.${operation}`, arguments: []}};
|
|
448
|
+
expect(runActionCall(call, createContext({}, {controlTask}), component)).toEqual({ok: true, value: "taken"});
|
|
449
|
+
expect(controlTask).toHaveBeenLastCalledWith(operation);
|
|
450
|
+
expect(runActionCall(call, createContext({}), component).ok).toBe(false);
|
|
451
|
+
}
|
|
452
|
+
controlTask.mockClear();
|
|
453
|
+
const cancel = {type: "util" as const, call: {operation: "task.cancel", arguments: []}};
|
|
454
|
+
expect(runActionCall(cancel, createContext({}, {controlTask, travelling: true}), component)).toEqual({ok: true, value: undefined});
|
|
455
|
+
expect(controlTask).not.toHaveBeenCalled();
|
|
456
|
+
});
|
|
457
|
+
|
|
444
458
|
it("refuses a pure function as a callback", () => {
|
|
445
459
|
const result = runActionCall({type: "util", call: {operation: "str.upper", arguments: []}}, createContext({}), component);
|
|
446
460
|
expect(result.ok).toBe(false);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {TASK_CONTROLS, type BlokTaskControl} from './task';
|
|
1
2
|
import {z} from 'zod';
|
|
2
3
|
import {blokPlatform} from '../../platform';
|
|
3
4
|
import {loadVocabulary} from '../../spec/vocabulary';
|
|
@@ -391,6 +392,12 @@ const resolvePropValue = (
|
|
|
391
392
|
export const COPY_EFFECT = 'ui.copy';
|
|
392
393
|
export const ANSWER_EFFECT = 'task.answer';
|
|
393
394
|
export const START_EFFECT = 'assign.start';
|
|
395
|
+
/** `task.cancel()` and its kin: what the viewer does to the task the blok is about. */
|
|
396
|
+
const TASK_CONTROL_PREFIX = 'task.';
|
|
397
|
+
export const taskControlOf = (operation: string): BlokTaskControl | null => {
|
|
398
|
+
const name = operation.startsWith(TASK_CONTROL_PREFIX) ? operation.slice(TASK_CONTROL_PREFIX.length) : '';
|
|
399
|
+
return (TASK_CONTROLS as readonly string[]).includes(name) ? (name as BlokTaskControl) : null;
|
|
400
|
+
};
|
|
394
401
|
export const REFETCH_EFFECT = 'query.refetch';
|
|
395
402
|
export const FETCH_MORE_EFFECT = 'query.fetch_more';
|
|
396
403
|
|
|
@@ -417,7 +424,7 @@ const getPropActionCall = (
|
|
|
417
424
|
export const isCommand = (actionCall: BlokActionCall | undefined): boolean =>
|
|
418
425
|
actionCall !== undefined &&
|
|
419
426
|
(actionCall.type === 'agent' ||
|
|
420
|
-
(actionCall.type === 'util' && (
|
|
427
|
+
(actionCall.type === 'util' && loadVocabulary().functions.get(actionCall.call.operation)?.command === true));
|
|
421
428
|
|
|
422
429
|
const copyToClipboard = (value: unknown): void => {
|
|
423
430
|
const text = value === null || value === undefined ? '' : typeof value === 'string' ? value : JSON.stringify(value);
|
|
@@ -509,6 +516,13 @@ const runActionCall = (
|
|
|
509
516
|
);
|
|
510
517
|
return {ok: true, value: answered};
|
|
511
518
|
}
|
|
519
|
+
const control = taskControlOf(operation);
|
|
520
|
+
if (control !== null) {
|
|
521
|
+
if (context.travelling) return {ok: true, value: undefined};
|
|
522
|
+
if (!context.controlTask) return {ok: false, error: `${operation}: nothing here controls a task.`};
|
|
523
|
+
// What the host returns (a promise, while the task takes it) keeps the control busy.
|
|
524
|
+
return {ok: true, value: context.controlTask(control)};
|
|
525
|
+
}
|
|
512
526
|
if (operation === START_EFFECT) {
|
|
513
527
|
if (context.travelling) return {ok: true, value: undefined};
|
|
514
528
|
if (!context.startRun) return {ok: false, error: 'assign.start: nothing here starts a run.'};
|