@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
|
@@ -11,16 +11,28 @@ import type {BlokRuntimeStore, BlokTaskObserver, BlokTaskUpdate} from './types';
|
|
|
11
11
|
* An `into` record is the viewer's own state: nothing is published to the
|
|
12
12
|
* agent, and a reload forgets it.
|
|
13
13
|
*/
|
|
14
|
-
export type BlokTaskStatus = 'idle' | 'queued' | 'running' | 'asking' | 'done' | 'failed' | 'cancelled';
|
|
14
|
+
export type BlokTaskStatus = 'idle' | 'queued' | 'running' | 'asking' | 'paused' | 'done' | 'failed' | 'cancelled';
|
|
15
15
|
|
|
16
16
|
export type BlokTaskAsk = {question: string; form: Record<string, unknown>};
|
|
17
17
|
|
|
18
|
+
/** One thing a task reported. */
|
|
19
|
+
export type BlokTaskLogEntry = {at: string | null; kind: string; message: string | null};
|
|
20
|
+
|
|
21
|
+
/** What may be done to a task: one flag per `task.<operation>()`. */
|
|
22
|
+
export type BlokTaskControl = 'cancel' | 'pause' | 'resume' | 'step' | 'interrupt';
|
|
23
|
+
export const TASK_CONTROLS: readonly BlokTaskControl[] = ['cancel', 'pause', 'resume', 'step', 'interrupt'];
|
|
24
|
+
export type BlokTaskCan = Record<BlokTaskControl, boolean>;
|
|
25
|
+
|
|
26
|
+
export const NO_TASK_CONTROL: BlokTaskCan = Object.freeze({cancel: false, pause: false, resume: false, step: false, interrupt: false});
|
|
27
|
+
|
|
18
28
|
export type BlokTaskRecord = {
|
|
19
29
|
/** The task's id; null before it was started. */
|
|
20
30
|
id: string | null;
|
|
21
31
|
status: BlokTaskStatus;
|
|
22
|
-
/** queued, running or
|
|
32
|
+
/** Started and not ended: queued, running, asking or paused. */
|
|
23
33
|
running: boolean;
|
|
34
|
+
/** Waiting for someone to resume it. */
|
|
35
|
+
paused: boolean;
|
|
24
36
|
done: boolean;
|
|
25
37
|
failed: boolean;
|
|
26
38
|
/** 0-100, as last reported; 100 once done. */
|
|
@@ -37,9 +49,19 @@ export type BlokTaskRecord = {
|
|
|
37
49
|
answer: Record<string, unknown> | null;
|
|
38
50
|
/** The latest yield, by return port key. */
|
|
39
51
|
returns: Record<string, unknown>;
|
|
52
|
+
/** When it was started (ISO 8601); null before. */
|
|
53
|
+
started_at: string | null;
|
|
54
|
+
/** When it ended; null while it has not. */
|
|
55
|
+
ended_at: string | null;
|
|
56
|
+
/** Seconds from start to end; null while it has not ended. */
|
|
57
|
+
duration: number | null;
|
|
58
|
+
/** What it reported, oldest first. */
|
|
59
|
+
log: BlokTaskLogEntry[];
|
|
60
|
+
/** What the viewer may do to it right now (`task.cancel()` and its kin); all false where the host controls nothing. */
|
|
61
|
+
can: BlokTaskCan;
|
|
40
62
|
};
|
|
41
63
|
|
|
42
|
-
const TASK_STATUSES: readonly BlokTaskStatus[] = ['idle', 'queued', 'running', 'asking', 'done', 'failed', 'cancelled'];
|
|
64
|
+
const TASK_STATUSES: readonly BlokTaskStatus[] = ['idle', 'queued', 'running', 'asking', 'paused', 'done', 'failed', 'cancelled'];
|
|
43
65
|
export const isTaskStatus = (value: unknown): value is BlokTaskStatus =>
|
|
44
66
|
typeof value === 'string' && (TASK_STATUSES as readonly string[]).includes(value);
|
|
45
67
|
|
|
@@ -50,6 +72,7 @@ export const idleTaskRecord = (): BlokTaskRecord => {
|
|
|
50
72
|
id: null,
|
|
51
73
|
status: 'idle',
|
|
52
74
|
running: false,
|
|
75
|
+
paused: false,
|
|
53
76
|
done: false,
|
|
54
77
|
failed: false,
|
|
55
78
|
progress: 0,
|
|
@@ -59,6 +82,11 @@ export const idleTaskRecord = (): BlokTaskRecord => {
|
|
|
59
82
|
ask: null,
|
|
60
83
|
answer: null,
|
|
61
84
|
returns: {},
|
|
85
|
+
started_at: null,
|
|
86
|
+
ended_at: null,
|
|
87
|
+
duration: null,
|
|
88
|
+
log: [],
|
|
89
|
+
can: NO_TASK_CONTROL,
|
|
62
90
|
...(idle as Partial<BlokTaskRecord>),
|
|
63
91
|
};
|
|
64
92
|
};
|
|
@@ -71,7 +99,8 @@ export const isSettledStatus = (status: BlokTaskStatus): boolean =>
|
|
|
71
99
|
export const withTaskStatus = (record: BlokTaskRecord, status: BlokTaskStatus): BlokTaskRecord => ({
|
|
72
100
|
...record,
|
|
73
101
|
status,
|
|
74
|
-
running: status === 'queued' || status === 'running' || status === 'asking',
|
|
102
|
+
running: status === 'queued' || status === 'running' || status === 'asking' || status === 'paused',
|
|
103
|
+
paused: status === 'paused',
|
|
75
104
|
done: status === 'done',
|
|
76
105
|
failed: status === 'failed',
|
|
77
106
|
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import {cleanup, screen} from '@testing-library/react';
|
|
3
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
4
|
+
import {parseBsx} from '../../bsx/parse';
|
|
5
|
+
import {renderBsx, testCatalog} from '../bloks/testing';
|
|
6
|
+
import {baseBlokCatalog} from '../baseCatalog';
|
|
7
|
+
import {lowerBlokText} from './text';
|
|
8
|
+
|
|
9
|
+
afterEach(cleanup);
|
|
10
|
+
|
|
11
|
+
type Lowered = {component: string; props?: Array<Record<string, unknown>>; children?: Lowered[]};
|
|
12
|
+
|
|
13
|
+
const lowered = (source: string, catalog = testCatalog()): Lowered => lowerBlokText(parseBsx(source).tree, catalog) as Lowered;
|
|
14
|
+
|
|
15
|
+
describe('text, as the renderer draws it', () => {
|
|
16
|
+
it('is the text prop of a component that has one', () => {
|
|
17
|
+
const button = lowered('<Button>Go</Button>');
|
|
18
|
+
expect(button.children).toBeUndefined();
|
|
19
|
+
expect(button.props).toEqual([{key: 'label', static_value: 'Go'}]);
|
|
20
|
+
const badge = lowered('<Badge>{task.status}</Badge>');
|
|
21
|
+
expect(badge.props).toEqual([{key: 'text', dynamic_value: {path: 'task.status'}}]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('is a Text among other children, a span inside a plain html element', () => {
|
|
25
|
+
const card = lowered('<Card>Hello <Badge>new</Badge> there</Card>');
|
|
26
|
+
expect(card.children?.map(child => child.component)).toEqual(['Text', 'Badge', 'Text']);
|
|
27
|
+
expect(card.children?.[0].props).toEqual([{key: 'text', static_value: 'Hello '}]);
|
|
28
|
+
expect(card.children?.[1].props).toEqual([{key: 'text', static_value: 'new'}]);
|
|
29
|
+
expect(lowered('<div>plain</div>').children?.map(child => child.component)).toEqual(['span']);
|
|
30
|
+
// A language element is no place of its own: the text takes after what is around it.
|
|
31
|
+
const within = lowered('<div><if when={args.x}>shown</if></div>');
|
|
32
|
+
expect(within.children?.[0].children?.map(child => child.component)).toEqual(['span']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('leaves a component alone that sets the prop itself, and a tree with no text', () => {
|
|
36
|
+
const both = lowered('<Button label="a">b</Button>');
|
|
37
|
+
expect(both.props).toEqual([{key: 'label', static_value: 'a'}]);
|
|
38
|
+
expect(both.children?.map(child => child.component)).toEqual(['Text']);
|
|
39
|
+
const {tree} = parseBsx('<Card><Button label="Go" /></Card>');
|
|
40
|
+
expect(lowerBlokText(tree, testCatalog())).toBe(tree);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('passes a tree stored before text was a node through as it is', () => {
|
|
44
|
+
const stored = {
|
|
45
|
+
id: 'Card[0]',
|
|
46
|
+
component: 'Card',
|
|
47
|
+
children: [
|
|
48
|
+
{id: 'Card[0]/#0', component: 'Text', props: [{key: 'text', static_value: 'Hello'}]},
|
|
49
|
+
{id: 'Card[0]/Button[0]', component: 'Button', props: [{key: 'label', static_value: 'Go'}]},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
expect(lowerBlokText(stored, testCatalog())).toBe(stored);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('is the text node itself where the catalog draws nothing else with it', () => {
|
|
56
|
+
const fragment = lowered('<fragment>bare</fragment>', baseBlokCatalog);
|
|
57
|
+
expect(fragment.children?.map(child => child.component)).toEqual(['#text']);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('shows on the page, whichever way it was written', () => {
|
|
61
|
+
renderBsx(testCatalog(), '<Card><Button>Go</Button><Text>Arrived</Text>and done<div>in a div</div></Card>');
|
|
62
|
+
expect(screen.getByRole('button').textContent).toBe('Go');
|
|
63
|
+
for (const shown of ['Arrived', 'and done', 'in a div']) expect(screen.queryByText(shown)).not.toBeNull();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {baseCatalog} from '../../spec/catalogs';
|
|
2
|
+
import type {BlokCatalog} from './functions';
|
|
3
|
+
import {isRecord} from './utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Text as a renderer draws it.
|
|
7
|
+
*
|
|
8
|
+
* The parser stores every run of text as a `#text` node under the component
|
|
9
|
+
* it stands in, and knows no catalog. What a component does with its text is
|
|
10
|
+
* said here, by the renderer, which has the catalog:
|
|
11
|
+
*
|
|
12
|
+
* - A component with a `textProp` whose one child is a run of text takes that
|
|
13
|
+
* text as the prop (`<Button>Go</Button>` is a `Button` with `label="Go"`).
|
|
14
|
+
* - Any other run of text becomes the component text is drawn with in that
|
|
15
|
+
* place: a `span` inside a plain html element, a `Text` anywhere else.
|
|
16
|
+
*
|
|
17
|
+
* A tree stored before text was a node holds the prop, or the `Text`/`span`,
|
|
18
|
+
* already: it passes through as it is. A renderer on another toolkit (React
|
|
19
|
+
* Native) uses the same pass, so every run of text arrives as a component it
|
|
20
|
+
* can wrap.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** The node a run of text is stored as (`bsx/parse`'s `TEXT_NODE`). */
|
|
24
|
+
export const BLOK_TEXT_NODE = '#text';
|
|
25
|
+
/** The prop of a text node that holds its text. */
|
|
26
|
+
export const BLOK_TEXT_VALUE = 'value';
|
|
27
|
+
/** What a run of text is drawn with among other children, and inside a plain html element. */
|
|
28
|
+
const LOOSE_TEXT = 'Text';
|
|
29
|
+
const LOOSE_HTML_TEXT = 'span';
|
|
30
|
+
/** The prop `Text` and `span` take their text as. */
|
|
31
|
+
const LOOSE_TEXT_PROP = 'text';
|
|
32
|
+
|
|
33
|
+
let groups: Map<string, string | null> | null = null;
|
|
34
|
+
|
|
35
|
+
/** The family of a base component (`language`, `html`, ...), by name. */
|
|
36
|
+
const groupOf = (component: string): string | null | undefined => {
|
|
37
|
+
groups ??= new Map(baseCatalog().components.map(entry => [entry.name, entry.group]));
|
|
38
|
+
return groups.get(component);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type RawNode = Record<string, unknown> & {component: string};
|
|
42
|
+
|
|
43
|
+
const isNode = (value: unknown): value is RawNode => isRecord(value) && !Array.isArray(value) && typeof value.component === 'string';
|
|
44
|
+
const isTextNode = (value: unknown): value is RawNode => isNode(value) && value.component === BLOK_TEXT_NODE;
|
|
45
|
+
|
|
46
|
+
/** The one prop of a text node, under another key; null when the node holds anything else. */
|
|
47
|
+
const valueAs = (node: RawNode, key: string): Record<string, unknown> | null => {
|
|
48
|
+
const props = Array.isArray(node.props) ? node.props : [];
|
|
49
|
+
const value = props.length === 1 && isRecord(props[0]) && props[0].key === BLOK_TEXT_VALUE ? props[0] : null;
|
|
50
|
+
return value ? {...value, key} : null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* `raw` with every run of text made what `catalog` draws it as. Nodes without
|
|
55
|
+
* text among their children are returned as they are (the same object).
|
|
56
|
+
*/
|
|
57
|
+
export const lowerBlokText = (raw: unknown, catalog: BlokCatalog, looseText: string = LOOSE_TEXT): unknown => {
|
|
58
|
+
if (!isNode(raw)) return raw;
|
|
59
|
+
const group = groupOf(raw.component);
|
|
60
|
+
// The component loose text becomes here, from the nearest ancestor that is no language element.
|
|
61
|
+
const loose = group === 'html' ? LOOSE_HTML_TEXT : group === 'language' ? looseText : LOOSE_TEXT;
|
|
62
|
+
const children = Array.isArray(raw.children) ? raw.children : null;
|
|
63
|
+
if (!children) return raw;
|
|
64
|
+
const texts = children.filter(isTextNode);
|
|
65
|
+
if (texts.length === 0) {
|
|
66
|
+
const lowered = children.map(child => lowerBlokText(child, catalog, loose));
|
|
67
|
+
return lowered.some((child, index) => child !== children[index]) ? {...raw, children: lowered} : raw;
|
|
68
|
+
}
|
|
69
|
+
const props = Array.isArray(raw.props) ? raw.props : [];
|
|
70
|
+
const textProp = catalog.components.get(raw.component)?.textProp;
|
|
71
|
+
if (textProp && children.length === 1 && !props.some(prop => isRecord(prop) && prop.key === textProp)) {
|
|
72
|
+
const value = valueAs(texts[0], textProp);
|
|
73
|
+
if (value) {
|
|
74
|
+
const {children: _children, ...rest} = raw;
|
|
75
|
+
return {...rest, props: [...props, value]};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const drawnWith = catalog.components.has(loose) ? loose : null;
|
|
79
|
+
return {
|
|
80
|
+
...raw,
|
|
81
|
+
children: children.map(child => {
|
|
82
|
+
if (!isTextNode(child)) return lowerBlokText(child, catalog, loose);
|
|
83
|
+
const value = drawnWith ? valueAs(child, LOOSE_TEXT_PROP) : null;
|
|
84
|
+
// A catalog without it draws the text node itself (the language's own `#text`).
|
|
85
|
+
return value ? {id: child.id, component: drawnWith, props: [value]} : child;
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {StoreApi} from 'zustand/vanilla';
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
import type {BlokSourceStatus} from './status';
|
|
4
|
-
import type {BlokTaskAsk, BlokTaskBinding} from './task';
|
|
4
|
+
import type {BlokTaskAsk, BlokTaskBinding, BlokTaskControl} from './task';
|
|
5
5
|
|
|
6
6
|
export type ChildDescriptor = string | {id: string; basePath?: string};
|
|
7
7
|
|
|
@@ -116,7 +116,7 @@ export type BlokTaskUpdate = {
|
|
|
116
116
|
/** The task's id, once the host knows it. */
|
|
117
117
|
id?: string;
|
|
118
118
|
/** Where it stands while it has not ended. */
|
|
119
|
-
status?: 'queued' | 'running' | 'asking';
|
|
119
|
+
status?: 'queued' | 'running' | 'asking' | 'paused';
|
|
120
120
|
/** The ask it opened (null: answered or withdrawn). */
|
|
121
121
|
ask?: BlokTaskAsk | null;
|
|
122
122
|
/** The values given for its ask. */
|
|
@@ -216,6 +216,8 @@ export type BlokResolutionContext = {
|
|
|
216
216
|
answerTask?: (values: Record<string, unknown>) => unknown;
|
|
217
217
|
/** Starts the run an assign blok prepares (`assign.start()`); undefined where the host starts none. */
|
|
218
218
|
startRun?: () => unknown;
|
|
219
|
+
/** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin); undefined where the host controls no task. */
|
|
220
|
+
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
219
221
|
/** Set while the blok shows a moment in the past: no command runs. */
|
|
220
222
|
travelling?: boolean;
|
|
221
223
|
resolvePath: (path: string) => string;
|
|
@@ -252,12 +254,15 @@ export type BlokRuntimeContext = {
|
|
|
252
254
|
answerTask: ((values: Record<string, unknown>) => unknown) | undefined;
|
|
253
255
|
/** Starts the run an assign blok prepares; set by a host that can start one. */
|
|
254
256
|
startRun: (() => unknown) | undefined;
|
|
257
|
+
/** Controls `task`; set by a host that can. */
|
|
258
|
+
controlTask: ((operation: BlokTaskControl) => unknown) | undefined;
|
|
255
259
|
setStatus: (path: string, status: BlokSourceStatus | null) => void;
|
|
256
260
|
setTravelAt: (at: string | null) => void;
|
|
257
261
|
setRefetchQuery: (refetch: ((name: string) => void) | undefined) => void;
|
|
258
262
|
setFetchMoreQuery: (fetchMore: ((name: string, variables: Record<string, unknown>) => void) | undefined) => void;
|
|
259
263
|
setAnswerTask: (answer: ((values: Record<string, unknown>) => unknown) | undefined) => void;
|
|
260
264
|
setStartRun: (start: (() => unknown) | undefined) => void;
|
|
265
|
+
setControlTask: (control: ((operation: BlokTaskControl) => unknown) | undefined) => void;
|
|
261
266
|
agentMappingStateUpdates: BlokAgentMappingStateUpdates;
|
|
262
267
|
invokeFunction: BlokInvokeFunctionHandler;
|
|
263
268
|
dispatchAction: BlokDispatchActionHandler;
|
package/src/runtime.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from './renderer/runtime';
|
|
|
3
3
|
export * from './renderer/functions';
|
|
4
4
|
export * from './renderer/declarations';
|
|
5
5
|
export * from './renderer/persist';
|
|
6
|
-
export * from './renderer/modules';
|
|
7
6
|
export * from './renderer/baseCatalog';
|
|
8
7
|
export * from './renderer/declare';
|
|
9
8
|
export * from './cache/keyedStore';
|
package/src/scene.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @arkitektio/bsx/scene: scene
|
|
1
|
+
// @arkitektio/bsx/scene: the scene family drawn with three, @react-three/fiber and drei (opt-in: an app passes
|
|
2
2
|
// threeScene to declareBlokUi), and the scene and run hosts the renderer mounts.
|
|
3
3
|
import {sceneCatalog} from './catalogs/index';
|
|
4
4
|
import {runRenders} from './renderer/bloks/run';
|
|
@@ -10,7 +10,7 @@ export * from './renderer/bloks/run';
|
|
|
10
10
|
|
|
11
11
|
const renders = {...sceneRenders, ...runRenders};
|
|
12
12
|
|
|
13
|
-
/** scene
|
|
13
|
+
/** the scene family, drawn with three. */
|
|
14
14
|
export const threeScene = implementBlokCatalog(sceneCatalog, {
|
|
15
15
|
Animate: renders.Animate,
|
|
16
16
|
Attach: renders.Attach,
|
package/src/shadcn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @arkitektio/bsx/shadcn: a reference implementation of ui
|
|
1
|
+
// @arkitektio/bsx/shadcn: a reference implementation of the ui family, the html family, the logo family and the shadcn family in shadcn/ui
|
|
2
2
|
// (radix, Tailwind) and SVG. Opt-in: an app passes these to declareBlokUi, or spreads one and draws over a part.
|
|
3
3
|
// The app's Tailwind must see this package's classes: @source on node_modules/@arkitektio/bsx/dist.
|
|
4
4
|
import {htmlCatalog, logoCatalog, shadcnCatalog, uiCatalog} from './catalogs/index';
|
|
@@ -7,7 +7,7 @@ import {implementBlokCatalog} from './renderer/runtime/catalog';
|
|
|
7
7
|
|
|
8
8
|
export {domRenders};
|
|
9
9
|
|
|
10
|
-
/** ui
|
|
10
|
+
/** the ui family, drawn with shadcn/ui. */
|
|
11
11
|
export const shadcnUiRenders = {
|
|
12
12
|
Accordion: domRenders.Accordion,
|
|
13
13
|
AccordionContent: domRenders.AccordionContent,
|
|
@@ -52,6 +52,7 @@ export const shadcnUiRenders = {
|
|
|
52
52
|
RadioGroup: domRenders.RadioGroup,
|
|
53
53
|
RadioGroupItem: domRenders.RadioGroupItem,
|
|
54
54
|
Row: domRenders.Row,
|
|
55
|
+
List: domRenders.List,
|
|
55
56
|
ScrollArea: domRenders.ScrollArea,
|
|
56
57
|
Select: domRenders.Select,
|
|
57
58
|
SelectContent: domRenders.SelectContent,
|
|
@@ -93,7 +94,7 @@ export const shadcnUiRenders = {
|
|
|
93
94
|
|
|
94
95
|
export const shadcnUi = implementBlokCatalog(uiCatalog, shadcnUiRenders);
|
|
95
96
|
|
|
96
|
-
/** html
|
|
97
|
+
/** the html family, drawn with shadcn/ui. */
|
|
97
98
|
export const shadcnHtmlRenders = {
|
|
98
99
|
div: domRenders.div,
|
|
99
100
|
p: domRenders.p,
|
|
@@ -102,7 +103,7 @@ export const shadcnHtmlRenders = {
|
|
|
102
103
|
|
|
103
104
|
export const shadcnHtml = implementBlokCatalog(htmlCatalog, shadcnHtmlRenders);
|
|
104
105
|
|
|
105
|
-
/** logo
|
|
106
|
+
/** the logo family, drawn with shadcn/ui. */
|
|
106
107
|
export const shadcnLogoRenders = {
|
|
107
108
|
ActionLogo: domRenders.ActionLogo,
|
|
108
109
|
AgentLogo: domRenders.AgentLogo,
|
|
@@ -124,7 +125,7 @@ export const shadcnLogoRenders = {
|
|
|
124
125
|
|
|
125
126
|
export const shadcnLogo = implementBlokCatalog(logoCatalog, shadcnLogoRenders);
|
|
126
127
|
|
|
127
|
-
/** shadcn
|
|
128
|
+
/** the shadcn family, drawn with shadcn/ui. */
|
|
128
129
|
export const shadcnExtrasRenders = {
|
|
129
130
|
AlertDialog: domRenders.AlertDialog,
|
|
130
131
|
AlertDialogAction: domRenders.AlertDialogAction,
|
|
@@ -145,6 +146,8 @@ export const shadcnExtrasRenders = {
|
|
|
145
146
|
ButtonGroup: domRenders.ButtonGroup,
|
|
146
147
|
Calendar: domRenders.Calendar,
|
|
147
148
|
Carousel: domRenders.Carousel,
|
|
149
|
+
Combobox: domRenders.Combobox,
|
|
150
|
+
DatePicker: domRenders.DatePicker,
|
|
148
151
|
CarouselItem: domRenders.CarouselItem,
|
|
149
152
|
Chart: domRenders.Chart,
|
|
150
153
|
Collapsible: domRenders.Collapsible,
|