@arkitektio/bsx 5.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/bsx/analyze.d.ts +6 -5
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +12 -10
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +111 -0
- package/dist/bsx/declared.d.ts.map +1 -0
- package/dist/bsx/declared.js +311 -0
- package/dist/bsx/declared.js.map +1 -0
- package/dist/bsx/index.d.ts +1 -0
- package/dist/bsx/index.d.ts.map +1 -1
- package/dist/bsx/index.js +1 -0
- package/dist/bsx/index.js.map +1 -1
- package/dist/bsx/infer.d.ts +40 -17
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +105 -49
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts +6 -2
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +65 -21
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +6 -1
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +32 -3
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +3 -0
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +45 -51
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +265 -138
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +2 -2
- package/dist/catalogs/index.d.ts +49 -71
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +1 -1
- package/dist/catalogs/logo.d.ts +14 -28
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +1 -2
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +1 -1
- package/dist/catalogs/parts/feedback.d.ts +3 -3
- package/dist/catalogs/parts/forms.d.ts +4 -4
- package/dist/catalogs/parts/html.d.ts +2 -2
- package/dist/catalogs/parts/icons.d.ts +2 -2
- package/dist/catalogs/parts/index.d.ts +35 -57
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +10 -25
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +12 -14
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +4 -4
- package/dist/catalogs/parts/overlays.d.ts +11 -11
- package/dist/catalogs/parts/run.d.ts +2 -10
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.d.ts +7 -15
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +1 -5
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/typography.d.ts +3 -3
- package/dist/catalogs/props.d.ts +2 -2
- package/dist/catalogs/scene.d.ts +5 -13
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/shadcn.d.ts +11 -11
- package/dist/catalogs/ui.d.ts +16 -16
- package/dist/logo/actionLogoSource.d.ts +3 -3
- package/dist/logo/actionLogoSource.d.ts.map +1 -1
- package/dist/logo/actionLogoSource.js +4 -4
- package/dist/logo/actionLogoSource.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +16 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +32 -13
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +3 -3
- package/dist/renderer/baseCatalog.js +2 -2
- package/dist/renderer/bloks/control.d.ts +18 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +85 -14
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +1 -1
- package/dist/renderer/bloks/feedback.d.ts +3 -3
- package/dist/renderer/bloks/forms.d.ts +4 -4
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/icons.d.ts +1 -1
- package/dist/renderer/bloks/index.d.ts +30 -37
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +1 -8
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +1 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
- package/dist/renderer/bloks/navigation.d.ts +4 -4
- package/dist/renderer/bloks/overlays.d.ts +11 -11
- package/dist/renderer/bloks/run/components.d.ts +1 -5
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.js +4 -2
- package/dist/renderer/bloks/scene/Scene.js.map +1 -1
- package/dist/renderer/bloks/scene/host.d.ts +2 -0
- package/dist/renderer/bloks/scene/host.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/host.js +8 -0
- package/dist/renderer/bloks/scene/host.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +4 -8
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +3 -2
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +2 -2
- package/dist/renderer/bloks/typography.d.ts +3 -3
- package/dist/renderer/declarations.d.ts +40 -33
- package/dist/renderer/declarations.d.ts.map +1 -1
- package/dist/renderer/declarations.js +41 -56
- package/dist/renderer/declarations.js.map +1 -1
- package/dist/renderer/declare.js +4 -4
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/persist.d.ts +22 -13
- package/dist/renderer/persist.d.ts.map +1 -1
- package/dist/renderer/persist.js +40 -21
- package/dist/renderer/persist.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +4 -4
- package/dist/renderer/runtime/catalog.js +3 -3
- package/dist/renderer/runtime/components.d.ts +4 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +5 -5
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +5 -5
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +11 -5
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +3 -3
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +2 -2
- 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 +8 -4
- 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/locals.d.ts +57 -0
- package/dist/renderer/runtime/locals.d.ts.map +1 -0
- package/dist/renderer/runtime/locals.js +87 -0
- package/dist/renderer/runtime/locals.js.map +1 -0
- package/dist/renderer/runtime/scope.d.ts +14 -0
- package/dist/renderer/runtime/scope.d.ts.map +1 -1
- package/dist/renderer/runtime/scope.js +25 -3
- package/dist/renderer/runtime/scope.js.map +1 -1
- package/dist/renderer/runtime/tree.d.ts.map +1 -1
- package/dist/renderer/runtime/tree.js +7 -1
- package/dist/renderer/runtime/tree.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +8 -3
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/shadcn.d.ts +36 -43
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +1 -2
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +11067 -6321
- package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
- package/dist/spec/catalogs/orkestrator@1.json +10 -10
- package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
- package/dist/spec/catalogs.d.ts +4 -4
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +7 -7
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +25 -4
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +50 -5
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +58 -32
- package/dist/spec/vocabulary.json.js +58 -32
- package/package.json +1 -1
- package/src/bsx/analyze.ts +14 -12
- package/src/bsx/bsx.test.ts +4 -4
- package/src/bsx/declared.ts +346 -0
- package/src/bsx/index.ts +1 -0
- package/src/bsx/infer.test.ts +42 -32
- package/src/bsx/infer.ts +128 -71
- package/src/bsx/language.test.ts +37 -25
- package/src/bsx/language.ts +72 -25
- package/src/bsx/parse.ts +34 -3
- package/src/bsx/print.ts +3 -0
- package/src/bsx/references.test.ts +82 -81
- package/src/bsx/references.ts +313 -178
- package/src/catalogs/catalogs.test.ts +3 -2
- package/src/catalogs/index.ts +1 -1
- package/src/catalogs/logo.ts +1 -2
- package/src/catalogs/parts/logo.ts +13 -17
- package/src/catalogs/parts/scene.ts +1 -7
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.test.tsx +22 -0
- package/src/renderer/BlokRenderer.tsx +70 -20
- package/src/renderer/addBlokComponents.test.tsx +1 -1
- package/src/renderer/baseCatalog.ts +2 -2
- package/src/renderer/bloks/control.tsx +119 -16
- package/src/renderer/bloks/logo/index.tsx +2 -3
- package/src/renderer/bloks/logo/logo.fixture.json +266 -250
- package/src/renderer/bloks/logo/logo.test.tsx +18 -7
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/Scene.tsx +4 -2
- package/src/renderer/bloks/scene/host.tsx +11 -0
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- package/src/renderer/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +4 -4
- package/src/renderer/declare.ts +4 -4
- package/src/renderer/persist.test.ts +70 -49
- package/src/renderer/persist.ts +57 -34
- package/src/renderer/runtime/catalog.test.ts +2 -2
- package/src/renderer/runtime/catalog.ts +4 -4
- package/src/renderer/runtime/components.tsx +8 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +5 -5
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/shadcn.ts +1 -2
- package/src/spec/bsx_v2.json +11067 -6321
- package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/src/spec/catalogs/orkestrator@1.json +10 -10
- package/src/spec/catalogs.ts +8 -8
- package/src/spec/spec.test.ts +19 -16
- package/src/spec/vocabulary.json +58 -32
- package/src/spec/vocabulary.ts +69 -10
|
@@ -31,6 +31,12 @@ const mount = (canSave: boolean, room = 'room:lab') =>
|
|
|
31
31
|
</BlokSpaceHostProvider>,
|
|
32
32
|
);
|
|
33
33
|
|
|
34
|
+
|
|
35
|
+
/** The props of an action's panel `<Blok>`. */
|
|
36
|
+
const PANEL = [
|
|
37
|
+
{key: 'kind', static_value: 'action'},
|
|
38
|
+
{key: 'context', static_value: 'panel'},
|
|
39
|
+
];
|
|
34
40
|
describe('a space shown on its own', () => {
|
|
35
41
|
it('opens a scene of its own, with Arrange where the host keeps poses', () => {
|
|
36
42
|
mount(true);
|
|
@@ -52,7 +58,7 @@ describe('a space shown on its own', () => {
|
|
|
52
58
|
|
|
53
59
|
describe('the argument form an assign blok places', () => {
|
|
54
60
|
it('draws what the host gives for <args />, and nothing without a host', () => {
|
|
55
|
-
const tree = [{id: 'root', component: '
|
|
61
|
+
const tree = [{id: 'root', component: 'Blok', props: PANEL, children: [{id: 'form', component: 'args'}]}];
|
|
56
62
|
const run: BlokRunHost = {agentsFor: () => [], renderAsk: () => null, renderArgs: () => <div data-testid="args-form" />};
|
|
57
63
|
const hosted = render(
|
|
58
64
|
<BlokRunHostProvider value={run}>
|
|
@@ -68,7 +74,7 @@ describe('the argument form an assign blok places', () => {
|
|
|
68
74
|
|
|
69
75
|
describe('the time slider a task blok places', () => {
|
|
70
76
|
it('draws what the host gives for <timeline />, and nothing without a host', () => {
|
|
71
|
-
const tree = [{id: 'root', component: '
|
|
77
|
+
const tree = [{id: 'root', component: 'Blok', props: PANEL, children: [{id: 'slider', component: 'timeline'}]}];
|
|
72
78
|
const run: BlokRunHost = {agentsFor: () => [], renderAsk: () => null, renderTimeline: () => <div data-testid="timeline" />};
|
|
73
79
|
const hosted = render(
|
|
74
80
|
<BlokRunHostProvider value={run}>
|
|
@@ -87,7 +93,8 @@ describe('what an assign blok places one by one', () => {
|
|
|
87
93
|
const tree = [
|
|
88
94
|
{
|
|
89
95
|
id: 'root',
|
|
90
|
-
component: '
|
|
96
|
+
component: 'Blok',
|
|
97
|
+
props: PANEL,
|
|
91
98
|
children: [
|
|
92
99
|
{id: 'one', component: 'arg', props: [{key: 'key', static_value: 'exposure'}]},
|
|
93
100
|
{id: 'rest', component: 'args', props: [{key: 'omit', static_value: 'gain offset'}, {key: 'given', static_value: 'show'}]},
|
|
@@ -122,7 +129,8 @@ describe('what a task blok places of its run', () => {
|
|
|
122
129
|
const tree = [
|
|
123
130
|
{
|
|
124
131
|
id: 'root',
|
|
125
|
-
component: '
|
|
132
|
+
component: 'Blok',
|
|
133
|
+
props: PANEL,
|
|
126
134
|
children: [
|
|
127
135
|
{id: 'status', component: 'status'},
|
|
128
136
|
{id: 'result', component: 'returns', props: [{key: 'only', static_value: ['image']}]},
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
type SceneOverlay,
|
|
35
35
|
type SceneView,
|
|
36
36
|
} from './context';
|
|
37
|
-
import {BlokSceneEmbedProvider, useBlokSceneEmbedded, useBlokSceneFill} from './host';
|
|
37
|
+
import {BlokSceneEmbedProvider, useBlokSceneControls, useBlokSceneEmbedded, useBlokSceneFill} from './host';
|
|
38
38
|
import { useKeepTabLive } from "../../../platform";
|
|
39
39
|
import {usePersistedComponentState} from '../../persist';
|
|
40
40
|
import {useBlokReady, useBlokSnapshotMode} from '../../../preview/snapshotMode';
|
|
@@ -758,6 +758,8 @@ export const SceneSurface = ({
|
|
|
758
758
|
useKeepTabLive();
|
|
759
759
|
// A preview reads the canvas after it painted: keep the drawing buffer.
|
|
760
760
|
const snapshot = useBlokSnapshotMode();
|
|
761
|
+
// A thumbnail, or a host that shows the scene as a preview, gets no view controls.
|
|
762
|
+
const controls = useBlokSceneControls() && !snapshot;
|
|
761
763
|
|
|
762
764
|
return (
|
|
763
765
|
<SceneStoreProvider value={store}>
|
|
@@ -789,7 +791,7 @@ export const SceneSurface = ({
|
|
|
789
791
|
</SceneStoreProvider>
|
|
790
792
|
</Canvas>
|
|
791
793
|
<SceneOverlays cards={cards} />
|
|
792
|
-
<SceneControls />
|
|
794
|
+
{controls ? <SceneControls /> : null}
|
|
793
795
|
{overlay}
|
|
794
796
|
</div>
|
|
795
797
|
</SceneStoreProvider>
|
|
@@ -72,6 +72,17 @@ export const BlokSceneInertProvider = BlokSceneInertContext.Provider;
|
|
|
72
72
|
|
|
73
73
|
export const useBlokSceneInert = (): boolean => React.useContext(BlokSceneInertContext);
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Whether a scene shows its own view controls (where to look from, frame,
|
|
77
|
+
* grid, turning, settings). On where the scene is mounted as a view of its
|
|
78
|
+
* own; a host showing it as a preview, a card or a thumbnail turns them off.
|
|
79
|
+
*/
|
|
80
|
+
const BlokSceneControlsContext = React.createContext(true);
|
|
81
|
+
|
|
82
|
+
export const BlokSceneControlsProvider = BlokSceneControlsContext.Provider;
|
|
83
|
+
|
|
84
|
+
export const useBlokSceneControls = (): boolean => React.useContext(BlokSceneControlsContext);
|
|
85
|
+
|
|
75
86
|
/**
|
|
76
87
|
* Whether the scene shows a moment instead of a running device. A host that
|
|
77
88
|
* shows state from the past sets this: parts then stand where they were
|
|
@@ -2,12 +2,14 @@ import * as React from 'react';
|
|
|
2
2
|
import type * as THREE from 'three';
|
|
3
3
|
import {onClickSchema, popoutSchema, type sceneContracts} from '../../../catalogs/parts/scene';
|
|
4
4
|
import {
|
|
5
|
+
BlokItemKeysBridge,
|
|
5
6
|
BlokRuntimeProvider,
|
|
6
7
|
BlokScopeProvider,
|
|
7
8
|
BlokTreeProvider,
|
|
8
9
|
useBlok,
|
|
9
10
|
useBlokRuntimeStoreApi,
|
|
10
11
|
useBlokScope,
|
|
12
|
+
useBlokItemKeys,
|
|
11
13
|
useBlokTree,
|
|
12
14
|
useEventAction,
|
|
13
15
|
useValue,
|
|
@@ -129,21 +131,24 @@ export const PopoutRender: BlokRender<Contracts['Popout']> = ({component, buildC
|
|
|
129
131
|
// So are the blok's runtime and tree: in a scene shared by several bloks
|
|
130
132
|
// that half is outside each of them.
|
|
131
133
|
const scope = useBlokScope();
|
|
134
|
+
const itemKeys = useBlokItemKeys();
|
|
132
135
|
const runtime = useBlokRuntimeStoreApi();
|
|
133
136
|
const tree = useBlokTree();
|
|
134
137
|
const content = React.useMemo(
|
|
135
138
|
() => (
|
|
136
139
|
<BlokRuntimeProvider store={runtime}>
|
|
137
140
|
<BlokTreeProvider tree={tree}>
|
|
138
|
-
<
|
|
139
|
-
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
<BlokItemKeysBridge keys={itemKeys}>
|
|
142
|
+
<BlokScopeProvider aliases={scope.aliases} values={scope.values} basePath={scope.basePath} defaults={scope.defaults}>
|
|
143
|
+
{(component.children ?? []).map(child => (
|
|
144
|
+
<React.Fragment key={child.id}>{buildChild(child.id)}</React.Fragment>
|
|
145
|
+
))}
|
|
146
|
+
</BlokScopeProvider>
|
|
147
|
+
</BlokItemKeysBridge>
|
|
143
148
|
</BlokTreeProvider>
|
|
144
149
|
</BlokRuntimeProvider>
|
|
145
150
|
),
|
|
146
|
-
[buildChild, component, runtime, scope, tree],
|
|
151
|
+
[buildChild, component, itemKeys, runtime, scope, tree],
|
|
147
152
|
);
|
|
148
153
|
useSceneOverlay({
|
|
149
154
|
visible: Boolean(node) && visible,
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { analyzeBsx } from "../../../bsx/analyze";
|
|
4
|
-
import {
|
|
4
|
+
import { mountedBlokScope } from "../../../bsx/references";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
6
|
+
/** A scene blok that declares the local `pose`, around `body` (a `<Scene>`). */
|
|
7
|
+
const analyze = (body: string) =>
|
|
8
|
+
analyzeBsx(`<Blok kind="agent" context="scene"><local name="pose" persist />${body}</Blok>`, { scope: mountedBlokScope() });
|
|
10
9
|
|
|
11
10
|
describe("Transform", () => {
|
|
12
11
|
it("places what it holds in a scene, bound to a local the gizmo writes", () => {
|
|
13
12
|
const { tree, markers } = analyze('<Scene><Transform bind={pose} mode="rotate"><Transform /></Transform></Scene>');
|
|
14
13
|
expect(markers).toEqual([]);
|
|
15
|
-
expect(tree?.children?.[0]?.component).toBe("Transform");
|
|
14
|
+
expect(tree?.children?.[1]?.children?.[0]?.component).toBe("Transform");
|
|
16
15
|
});
|
|
17
16
|
|
|
18
17
|
it("keeps its own pose by id when it persists", () => {
|
|
@@ -21,6 +20,8 @@ describe("Transform", () => {
|
|
|
21
20
|
});
|
|
22
21
|
|
|
23
22
|
it("stands only in a scene", () => {
|
|
24
|
-
expect(
|
|
23
|
+
expect(
|
|
24
|
+
analyzeBsx('<Blok kind="agent" context="panel"><local name="pose" /><Transform bind={pose} /></Blok>', { scope: mountedBlokScope() }).markers.length,
|
|
25
|
+
).toBeGreaterThan(0);
|
|
25
26
|
});
|
|
26
27
|
});
|
|
@@ -1,72 +1,59 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {parseBsx} from '../bsx/parse';
|
|
3
|
+
import {declaredLocals, demoModel, parseBlokDeclarations, resolveTreeLocals, treeQueries, treeSubscriptions} from './declarations';
|
|
4
|
+
|
|
5
|
+
const tree = (source: string) => [parseBsx(source).tree];
|
|
3
6
|
|
|
4
7
|
describe('parseBlokDeclarations', () => {
|
|
5
|
-
it('reads the
|
|
8
|
+
it('reads the locals a service resolved, each by its <local> node', () => {
|
|
6
9
|
const declarations = parseBlokDeclarations({
|
|
7
10
|
vocab: 2,
|
|
8
|
-
|
|
9
|
-
{key: 'iterations', kind: 'INT', default: 3, persist: true},
|
|
10
|
-
{key: 'mode', kind: 'ENUM', choices: [{value: 'fast', label: 'Fast'}], default: 'fast'},
|
|
11
|
-
{key: 'form', kind: 'DICT', children: [{key: 'name', kind: 'STRING'}]},
|
|
12
|
-
{key: '
|
|
11
|
+
resolvedLocals: [
|
|
12
|
+
{node: 'Blok[0]/local[0]', key: 'iterations', kind: 'INT', default: 3, persist: true},
|
|
13
|
+
{node: 'Blok[0]/local[1]', key: 'mode', kind: 'ENUM', choices: [{value: 'fast', label: 'Fast'}], default: 'fast'},
|
|
14
|
+
{node: 'Blok[0]/Card[0]/local[0]', key: 'form', kind: 'DICT', children: [{key: 'name', kind: 'STRING'}]},
|
|
15
|
+
{key: 'nodeless', kind: 'INT'},
|
|
16
|
+
{node: 'Blok[0]/local[2]', key: 'kindless'},
|
|
13
17
|
],
|
|
14
|
-
demo: {args: {scene: 1}
|
|
15
|
-
queries: [{key: 'stats', service: 'mikro', document: 'query Stats { stats }', variables: {table_id: 1}, poll: 5, more: 'stats.rows'}],
|
|
18
|
+
demo: {args: {scene: 1}},
|
|
16
19
|
});
|
|
17
20
|
const port = {identifier: null, nullable: false, default: null, children: null, choices: null, label: null, description: null};
|
|
18
|
-
// A local is a port plus persist; one left without a kind (and no tree to tell) is ANY.
|
|
19
21
|
expect(declaredLocals(declarations)).toEqual([
|
|
20
|
-
{...port, key: 'iterations', kind: 'INT', default: 3, persist: true},
|
|
21
|
-
{...port, key: 'mode', kind: 'ENUM', default: 'fast', choices: [{value: 'fast', label: 'Fast', description: null}], persist: false},
|
|
22
|
-
{...port, key: 'form', kind: 'DICT', children: [{...port, key: 'name', kind: 'STRING'}], persist: false},
|
|
23
|
-
{...port, key: 'kindless', kind: 'ANY', persist: false},
|
|
24
|
-
]);
|
|
25
|
-
expect(declarations.queries).toEqual([
|
|
26
|
-
{key: 'stats', service: 'mikro', document: 'query Stats { stats }', variables: {table_id: 1}, poll: 5, more: 'stats.rows', keep: null, history: null},
|
|
22
|
+
{...port, node: 'Blok[0]/local[0]', key: 'iterations', kind: 'INT', default: 3, persist: true},
|
|
23
|
+
{...port, node: 'Blok[0]/local[1]', key: 'mode', kind: 'ENUM', default: 'fast', choices: [{value: 'fast', label: 'Fast', description: null}], persist: false},
|
|
24
|
+
{...port, node: 'Blok[0]/Card[0]/local[0]', key: 'form', kind: 'DICT', children: [{...port, key: 'name', kind: 'STRING'}], persist: false},
|
|
27
25
|
]);
|
|
28
|
-
expect(declarations.subscriptions).toEqual([]);
|
|
29
26
|
});
|
|
30
27
|
|
|
31
|
-
it('
|
|
32
|
-
const declarations = parseBlokDeclarations({locals: [{default: 1}, 'x', null], queries: {key: 'q'}, subscriptions: [{key: 's', service: 'mikro'}]});
|
|
33
|
-
expect(declarations.resolvedLocals).toEqual([]);
|
|
34
|
-
expect(declarations.queries).toEqual([]);
|
|
35
|
-
expect(declarations.subscriptions).toEqual([]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('resolves locals served as written against the tree, as the server does', () => {
|
|
28
|
+
it('resolves the tree\'s locals when the service sent none, as the server does', () => {
|
|
39
29
|
const declarations = parseBlokDeclarations({
|
|
40
|
-
componentTree:
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
component: 'Card',
|
|
44
|
-
children: [
|
|
45
|
-
{id: 'Card[0]/Switch[0]', component: 'Switch', props: [{key: 'bind', dynamic_value: {path: 'on'}}]},
|
|
46
|
-
{id: 'Card[0]/Text[0]', component: 'Text', props: [{key: 'text', dynamic_value: {path: 'note'}}]},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
locals: [{key: 'on'}, {key: 'count', default: 2}, {key: 'note'}, {key: 'given', kind: 'STRING', default: 1}],
|
|
30
|
+
componentTree: tree(
|
|
31
|
+
'<Blok kind="custom" context="panel"><local name="on" /><local name="count" default={2} /><Card><local name="note" /><Switch bind={on} /><Text text={note} /></Card></Blok>',
|
|
32
|
+
),
|
|
51
33
|
});
|
|
52
|
-
expect(declarations.resolvedLocals.map(local => [local.key, local.kind])).toEqual([
|
|
53
|
-
['on', 'BOOL'],
|
|
54
|
-
['count', 'INT'],
|
|
55
|
-
['note', 'ANY'],
|
|
56
|
-
['given', 'STRING'],
|
|
34
|
+
expect(declarations.resolvedLocals.map(local => [local.node, local.key, local.kind])).toEqual([
|
|
35
|
+
['Blok[0]/local[0]', 'on', 'BOOL'],
|
|
36
|
+
['Blok[0]/local[1]', 'count', 'INT'],
|
|
37
|
+
['Blok[0]/Card[0]/local[0]', 'note', 'ANY'],
|
|
57
38
|
]);
|
|
39
|
+
expect(resolveTreeLocals([])).toEqual([]);
|
|
58
40
|
});
|
|
41
|
+
});
|
|
59
42
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
locals: [{key: 'iterations', kind: 'INT', default: 3}],
|
|
65
|
-
demo: {queries: {stats: {mean: 2}}},
|
|
66
|
-
queries: [{key: 'stats', service: 'mikro', document: 'query Stats { stats }'}],
|
|
67
|
-
}),
|
|
43
|
+
describe('the reads a tree declares', () => {
|
|
44
|
+
it('reads its <query> and <subscription> children, with their <var> variables', () => {
|
|
45
|
+
const roots = tree(
|
|
46
|
+
'<Blok kind="custom" context="panel"><query name="stats" service="mikro" document="query Stats($t: ID) { stats(t: $t) }" poll={5} more="stats.rows"><var key="t" value={args.table} /></query><subscription name="live" service="mikro" document="subscription { live }" keep={3} /><Text /></Blok>',
|
|
68
47
|
);
|
|
69
|
-
expect(
|
|
48
|
+
expect(treeQueries(roots)).toEqual([
|
|
49
|
+
{key: 'stats', service: 'mikro', document: 'query Stats($t: ID) { stats(t: $t) }', variables: [{key: 't', value_path: 'args.table'}], poll: 5, more: 'stats.rows'},
|
|
50
|
+
]);
|
|
51
|
+
expect(treeSubscriptions(roots)).toEqual([{key: 'live', service: 'mikro', document: 'subscription { live }', variables: [], keep: 3, history: null}]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('gives a preview its reads answered by the demo', () => {
|
|
55
|
+
const roots = tree('<Blok kind="custom" context="panel"><query name="stats" service="mikro" document="query Stats { stats }" /><Text /></Blok>');
|
|
56
|
+
const model = demoModel(roots, {demo: {queries: {stats: {mean: 2}}}});
|
|
70
57
|
expect(model.queries).toEqual({stats: {status: 'ready', value: {mean: 2}, error: null, refetching: false, fetching_more: false}});
|
|
71
58
|
});
|
|
72
59
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {LOCAL_ANY_KIND} from '../spec/vocabulary';
|
|
1
|
+
import {declaredQueries as queriesOfTree, declaredSubscriptions as subscriptionsOfTree} from '../bsx/declared';
|
|
2
|
+
import {resolveLocals} from '../bsx/infer';
|
|
3
|
+
import {viewForTree} from '../bsx/references';
|
|
5
4
|
import type {BlokLocal, BlokLocalChoice, BlokLocalPort} from './persist';
|
|
6
5
|
import {
|
|
7
6
|
idleTaskRecord,
|
|
@@ -18,9 +17,9 @@ import {
|
|
|
18
17
|
} from './runtime';
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* What a v2 blok
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* What a host gets of a v2 blok beside its tree (`Blok`/`BlokRevision`:
|
|
21
|
+
* `vocab`, `resolvedLocals`, `demo`), what its tree declares (its `<query>`
|
|
22
|
+
* and `<subscription>` children), and the data model a renderer starts from.
|
|
24
23
|
*
|
|
25
24
|
* The roots a blok reads (vocabulary `roots.data`) are laid out as:
|
|
26
25
|
*
|
|
@@ -29,19 +28,23 @@ import {
|
|
|
29
28
|
* args: {...}, task: TaskRecord, viewer: {...}, then: null | "...",
|
|
30
29
|
* queries: {<name>: {status, value, error, refetching, fetching_more}},
|
|
31
30
|
* subscriptions: {<name>: {status, value, error}},
|
|
32
|
-
* <
|
|
31
|
+
* <into name>: TaskRecord,
|
|
32
|
+
* $locals: {<local's runtime id, encoded>: value},
|
|
33
33
|
* }
|
|
34
34
|
*
|
|
35
|
-
* `self` reads `deps.self
|
|
35
|
+
* `self` reads `deps.self`; a `<local>` is read by its name through its
|
|
36
|
+
* parent's scope (`runtime/locals`).
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* A local as its tree resolves it (`resolvedLocals`): an arg port (`ArgPort`
|
|
40
41
|
* fields) plus `persist`, its kind always said (inferred where the blok left
|
|
41
|
-
* it out, ANY when nothing tells)
|
|
42
|
-
*
|
|
42
|
+
* it out, ANY when nothing tells), and `node`, the id of the `<local>` that
|
|
43
|
+
* declares it. A renderer types a local's values (a kept one too) by its node.
|
|
43
44
|
*/
|
|
44
45
|
export type BlokDeclaredLocal = {
|
|
46
|
+
/** The id of the `<local>` node that declares it. */
|
|
47
|
+
node: string;
|
|
45
48
|
key: string;
|
|
46
49
|
kind: string;
|
|
47
50
|
identifier?: string | null;
|
|
@@ -55,7 +58,7 @@ export type BlokDeclaredLocal = {
|
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
/** A child port of a local (a list's item, a dict's or model's fields). */
|
|
58
|
-
export type BlokDeclaredLocalPort = Omit<BlokDeclaredLocal, 'persist'>;
|
|
61
|
+
export type BlokDeclaredLocalPort = Omit<BlokDeclaredLocal, 'persist' | 'node'>;
|
|
59
62
|
|
|
60
63
|
export type BlokDeclaredRead = {
|
|
61
64
|
key: string;
|
|
@@ -70,13 +73,16 @@ export type BlokDeclaredRead = {
|
|
|
70
73
|
history?: string | null;
|
|
71
74
|
};
|
|
72
75
|
|
|
76
|
+
/**
|
|
77
|
+
* What a host gets of a blok beside its tree (`Blok`/`BlokRevision`: `vocab`,
|
|
78
|
+
* `resolvedLocals`, `demo`). Its locals, queries and subscriptions are nodes
|
|
79
|
+
* of the tree; `resolvedLocals` is how the server typed the locals.
|
|
80
|
+
*/
|
|
73
81
|
export type BlokDeclarations = {
|
|
74
82
|
vocab?: number | null;
|
|
75
|
-
/** The
|
|
83
|
+
/** The `<local>` nodes as the tree resolves them, each with its `node`: what the renderer types them with. */
|
|
76
84
|
resolvedLocals: readonly BlokDeclaredLocal[];
|
|
77
85
|
demo?: unknown;
|
|
78
|
-
queries?: readonly BlokDeclaredRead[] | null;
|
|
79
|
-
subscriptions?: readonly BlokDeclaredRead[] | null;
|
|
80
86
|
};
|
|
81
87
|
|
|
82
88
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
@@ -98,10 +104,18 @@ const localPort = (port: BlokDeclaredLocalPort): BlokLocalPort => ({
|
|
|
98
104
|
});
|
|
99
105
|
|
|
100
106
|
export const declaredLocals = (declarations: BlokDeclarations): BlokLocal[] =>
|
|
101
|
-
declarations.resolvedLocals.map(local => ({...localPort(local), persist: local.persist === true}));
|
|
107
|
+
declarations.resolvedLocals.map(local => ({...localPort(local), node: local.node, persist: local.persist === true}));
|
|
108
|
+
|
|
109
|
+
/** The one root of a tree as the wire spells it (a list of roots, or one), or null. */
|
|
110
|
+
const rootOf = (roots: ReadonlyArray<unknown> | unknown): BlokComponentNode | null => {
|
|
111
|
+
const list = Array.isArray(roots) ? roots : [roots];
|
|
112
|
+
const [root] = list;
|
|
113
|
+
return list.length === 1 && isRecord(root) && typeof root.component === 'string' ? (root as BlokComponentNode) : null;
|
|
114
|
+
};
|
|
102
115
|
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
/** The reads a blok declares: its `<Blok>`'s `<query>` children. */
|
|
117
|
+
export const treeQueries = (roots: ReadonlyArray<unknown> | unknown): BlokQuery[] =>
|
|
118
|
+
queriesOfTree(rootOf(roots)).map(query => ({
|
|
105
119
|
key: query.key,
|
|
106
120
|
service: query.service,
|
|
107
121
|
document: query.document,
|
|
@@ -110,8 +124,9 @@ export const declaredQueries = (declarations: BlokDeclarations): BlokQuery[] =>
|
|
|
110
124
|
more: query.more ?? null,
|
|
111
125
|
}));
|
|
112
126
|
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
/** The streams a blok declares: its `<Blok>`'s `<subscription>` children. */
|
|
128
|
+
export const treeSubscriptions = (roots: ReadonlyArray<unknown> | unknown): BlokSubscription[] =>
|
|
129
|
+
subscriptionsOfTree(rootOf(roots)).map(subscription => ({
|
|
115
130
|
key: subscription.key,
|
|
116
131
|
service: subscription.service,
|
|
117
132
|
document: subscription.document,
|
|
@@ -120,10 +135,6 @@ export const declaredSubscriptions = (declarations: BlokDeclarations): BlokSubsc
|
|
|
120
135
|
history: subscription.history ?? null,
|
|
121
136
|
}));
|
|
122
137
|
|
|
123
|
-
/** Each declared local at its default. */
|
|
124
|
-
export const localsModel = (locals: readonly BlokLocal[]): Record<string, unknown> =>
|
|
125
|
-
Object.fromEntries(locals.map(local => [local.key, local.default ?? null]));
|
|
126
|
-
|
|
127
138
|
/** The names `into` gives a task call's record, in the tree. */
|
|
128
139
|
export const intoNames = (roots: ReadonlyArray<unknown>): string[] => {
|
|
129
140
|
const names = new Set<string>();
|
|
@@ -143,42 +154,41 @@ export const intoNames = (roots: ReadonlyArray<unknown>): string[] => {
|
|
|
143
154
|
export const intoModel = (roots: ReadonlyArray<unknown>): Record<string, BlokTaskRecord> =>
|
|
144
155
|
Object.fromEntries(intoNames(roots).map(name => [name, idleTaskRecord()]));
|
|
145
156
|
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
): {data: Record<string, unknown>; statuses: Record<string, BlokSourceStatus>} => {
|
|
151
|
-
const reads = pendingReads(
|
|
157
|
+
/**
|
|
158
|
+
* What a renderer shows live before anything synced: idle `into` records and
|
|
159
|
+
* pending reads. Locals read their defaults until written (`runtime/locals`).
|
|
160
|
+
*/
|
|
161
|
+
export const liveModel = (roots: ReadonlyArray<unknown>): {data: Record<string, unknown>; statuses: Record<string, BlokSourceStatus>} => {
|
|
162
|
+
const reads = pendingReads(treeQueries(roots), treeSubscriptions(roots));
|
|
152
163
|
return {
|
|
153
|
-
data: {...
|
|
164
|
+
data: {...intoModel(roots), ...reads.data},
|
|
154
165
|
statuses: reads.statuses,
|
|
155
166
|
};
|
|
156
167
|
};
|
|
157
168
|
|
|
158
169
|
/**
|
|
159
170
|
* What a preview renders: the blok's `demo`, mirroring the roots
|
|
160
|
-
* (`{deps, args, task, queries, subscriptions}`), with every
|
|
161
|
-
* answered by its demo value. Nothing is pending in a preview.
|
|
171
|
+
* (`{deps, args, task, queries, subscriptions}`), with every read the tree
|
|
172
|
+
* declares answered by its demo value. Nothing is pending in a preview.
|
|
162
173
|
*/
|
|
163
|
-
export const demoModel = (roots: ReadonlyArray<unknown>, declarations: BlokDeclarations): Record<string, unknown> => {
|
|
174
|
+
export const demoModel = (roots: ReadonlyArray<unknown>, declarations: Pick<BlokDeclarations, 'demo'>): Record<string, unknown> => {
|
|
164
175
|
const demo = isRecord(declarations.demo) ? declarations.demo : {};
|
|
165
176
|
const demoQueries = isRecord(demo.queries) ? demo.queries : {};
|
|
166
177
|
const demoSubscriptions = isRecord(demo.subscriptions) ? demo.subscriptions : {};
|
|
167
178
|
const queries = Object.fromEntries(
|
|
168
|
-
|
|
179
|
+
treeQueries(roots).map(query => [
|
|
169
180
|
query.key,
|
|
170
181
|
{status: 'ready', value: demoQueries[query.key] ?? null, error: null, refetching: false, fetching_more: false} satisfies BlokQueryRecord,
|
|
171
182
|
]),
|
|
172
183
|
);
|
|
173
184
|
const subscriptions = Object.fromEntries(
|
|
174
|
-
|
|
185
|
+
treeSubscriptions(roots).map(subscription => [
|
|
175
186
|
subscription.key,
|
|
176
187
|
{status: 'ready', value: demoSubscriptions[subscription.key] ?? null, error: null} satisfies BlokSubscriptionRecord,
|
|
177
188
|
]),
|
|
178
189
|
);
|
|
179
190
|
const task = isRecord(demo.task) ? {...idleTaskRecord(), ...demo.task} : undefined;
|
|
180
191
|
return {
|
|
181
|
-
...localsModel(declaredLocals(declarations)),
|
|
182
192
|
...intoModel(roots),
|
|
183
193
|
deps: isRecord(demo.deps) ? demo.deps : {},
|
|
184
194
|
args: isRecord(demo.args) ? demo.args : {},
|
|
@@ -189,20 +199,17 @@ export const demoModel = (roots: ReadonlyArray<unknown>, declarations: BlokDecla
|
|
|
189
199
|
};
|
|
190
200
|
|
|
191
201
|
/**
|
|
192
|
-
* What a service serves of a blok
|
|
193
|
-
*
|
|
194
|
-
*
|
|
202
|
+
* What a service serves of a blok as JSON (snake_case values): its tree, and
|
|
203
|
+
* the locals as it resolved them (`resolved_locals`, each with its `node`),
|
|
204
|
+
* when it did.
|
|
195
205
|
*/
|
|
196
206
|
export type BlokDeclarationsJson = {
|
|
197
207
|
vocab?: number | null;
|
|
198
208
|
componentTree?: unknown;
|
|
199
|
-
|
|
209
|
+
resolvedLocals?: unknown;
|
|
200
210
|
demo?: unknown;
|
|
201
|
-
queries?: unknown;
|
|
202
|
-
subscriptions?: unknown;
|
|
203
211
|
};
|
|
204
212
|
|
|
205
|
-
const optionalNumber = (value: unknown): number | null => (typeof value === 'number' ? value : null);
|
|
206
213
|
const optionalString = (value: unknown): string | null => (typeof value === 'string' ? value : null);
|
|
207
214
|
|
|
208
215
|
const jsonChoices = (raw: unknown): BlokLocalChoice[] | null =>
|
|
@@ -210,16 +217,12 @@ const jsonChoices = (raw: unknown): BlokLocalChoice[] | null =>
|
|
|
210
217
|
? raw.filter(isRecord).map(choice => ({value: choice.value ?? null, label: optionalString(choice.label), description: optionalString(choice.description)}))
|
|
211
218
|
: null;
|
|
212
219
|
|
|
213
|
-
/** A port from JSON;
|
|
220
|
+
/** A port from JSON; one without a key or kind is dropped. */
|
|
214
221
|
const jsonLocalPort = (port: Record<string, unknown>): BlokDeclaredLocalPort | null =>
|
|
215
|
-
typeof port.
|
|
216
|
-
|
|
217
|
-
/** A port from JSON with `kind` as given; null without a key. */
|
|
218
|
-
const jsonLocalWritten = <Kind extends string | null>(port: Record<string, unknown>, kind: Kind): (Omit<BlokDeclaredLocalPort, 'kind'> & {kind: Kind}) | null =>
|
|
219
|
-
typeof port.key === 'string'
|
|
222
|
+
typeof port.key === 'string' && typeof port.kind === 'string'
|
|
220
223
|
? {
|
|
221
224
|
key: port.key,
|
|
222
|
-
kind,
|
|
225
|
+
kind: port.kind,
|
|
223
226
|
identifier: optionalString(port.identifier),
|
|
224
227
|
nullable: port.nullable === true,
|
|
225
228
|
default: port.default ?? null,
|
|
@@ -235,51 +238,27 @@ const jsonLocalWritten = <Kind extends string | null>(port: Record<string, unkno
|
|
|
235
238
|
}
|
|
236
239
|
: null;
|
|
237
240
|
|
|
238
|
-
/**
|
|
239
|
-
const
|
|
241
|
+
/** Resolved locals from JSON; one without a node, a key or a kind is dropped. */
|
|
242
|
+
const jsonResolvedLocals = (raw: unknown): BlokDeclaredLocal[] =>
|
|
240
243
|
(Array.isArray(raw) ? raw : []).filter(isRecord).flatMap(local => {
|
|
241
|
-
const port =
|
|
242
|
-
return port ? [{...port, persist: local.persist === true}] : [];
|
|
244
|
+
const port = jsonLocalPort(local);
|
|
245
|
+
return port && typeof local.node === 'string' ? [{...port, node: local.node, persist: local.persist === true}] : [];
|
|
243
246
|
});
|
|
244
247
|
|
|
245
|
-
const jsonRoots = (raw: unknown): BlokComponentNode[] =>
|
|
246
|
-
(Array.isArray(raw) ? raw : [raw]).filter((node): node is BlokComponentNode => isRecord(node) && typeof node.component === 'string');
|
|
247
|
-
|
|
248
248
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
249
|
+
* The `<local>` nodes of a tree resolved the way the spec and the server
|
|
250
|
+
* resolve them (default, task argument, bind, else ANY), checked unmounted:
|
|
251
|
+
* what a host uses when the server sent no `resolvedLocals`.
|
|
252
252
|
*/
|
|
253
|
-
export const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return resolveBlokScope(root, {...emptyBlokScope(), locals}, defaultBlokView()).locals.map(local => ({...local}));
|
|
253
|
+
export const resolveTreeLocals = (roots: ReadonlyArray<unknown> | unknown): BlokDeclaredLocal[] => {
|
|
254
|
+
const root = rootOf(roots);
|
|
255
|
+
if (!root) return [];
|
|
256
|
+
return [...resolveLocals(root, null, viewForTree(root))].map(([node, {local}]) => ({...local, node}) as BlokDeclaredLocal);
|
|
258
257
|
};
|
|
259
258
|
|
|
260
|
-
|
|
261
|
-
(Array.isArray(raw) ? raw : []).filter(isRecord).flatMap(read =>
|
|
262
|
-
typeof read.key === 'string' && typeof read.service === 'string' && typeof read.document === 'string'
|
|
263
|
-
? [
|
|
264
|
-
{
|
|
265
|
-
key: read.key,
|
|
266
|
-
service: read.service,
|
|
267
|
-
document: read.document,
|
|
268
|
-
variables: read.variables,
|
|
269
|
-
poll: optionalNumber(read.poll),
|
|
270
|
-
more: optionalString(read.more),
|
|
271
|
-
keep: optionalNumber(read.keep),
|
|
272
|
-
history: optionalString(read.history),
|
|
273
|
-
},
|
|
274
|
-
]
|
|
275
|
-
: [],
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
/** A blok's declarations from JSON a service serves, keeping only well-formed entries. */
|
|
259
|
+
/** A blok's declarations from JSON a service serves: its resolved locals as served, or resolved from its tree. */
|
|
279
260
|
export const parseBlokDeclarations = (raw: BlokDeclarationsJson): BlokDeclarations => ({
|
|
280
261
|
vocab: raw.vocab ?? null,
|
|
281
|
-
resolvedLocals:
|
|
262
|
+
resolvedLocals: raw.resolvedLocals !== undefined && raw.resolvedLocals !== null ? jsonResolvedLocals(raw.resolvedLocals) : resolveTreeLocals(raw.componentTree),
|
|
282
263
|
demo: raw.demo ?? null,
|
|
283
|
-
queries: jsonReads(raw.queries),
|
|
284
|
-
subscriptions: jsonReads(raw.subscriptions),
|
|
285
264
|
});
|
|
@@ -13,12 +13,12 @@ const gauge = createBlokComponent({name: 'Gauge', service: 'lab', schema: z.obje
|
|
|
13
13
|
describe('declareBlokUi', () => {
|
|
14
14
|
it('speaks the base catalog in the contexts it draws whole', () => {
|
|
15
15
|
const whole = declareBlokUi({name: 'whole', implements: [shadcnUi, shadcnHtml, shadcnLogo, shadcnExtras, threeScene, hostedStructure]});
|
|
16
|
-
expect(whole.contexts).toEqual(['
|
|
17
|
-
expect(whole.claims).toEqual(['base@
|
|
16
|
+
expect(whole.contexts).toEqual(['PANEL', 'SCENE', 'LOGO']);
|
|
17
|
+
expect(whole.claims).toEqual(['base@4']);
|
|
18
18
|
const flat = declareBlokUi({name: 'flat', implements: [shadcnUi, shadcnHtml, shadcnLogo, shadcnExtras, hostedStructure]});
|
|
19
|
-
expect(flat.contexts).toEqual(['
|
|
19
|
+
expect(flat.contexts).toEqual(['PANEL', 'LOGO']);
|
|
20
20
|
const logos = declareBlokUi({name: 'logos', implements: [shadcnLogo]});
|
|
21
|
-
expect([logos.contexts, logos.claims]).toEqual([['LOGO'], ['base@
|
|
21
|
+
expect([logos.contexts, logos.claims]).toEqual([['LOGO'], ['base@4']]);
|
|
22
22
|
expect(declareBlokUi({name: 'none', implements: []}).claims).toEqual([]);
|
|
23
23
|
});
|
|
24
24
|
|
package/src/renderer/declare.ts
CHANGED
|
@@ -36,15 +36,15 @@ export type BlokUi = {
|
|
|
36
36
|
claims: readonly string[];
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const CONTEXTS: readonly BlokContextName[] = ['
|
|
39
|
+
const CONTEXTS: readonly BlokContextName[] = ['PANEL', 'SCENE', 'LOGO'];
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* The context a base component counts towards: its own, and for one that
|
|
43
|
-
* bridges
|
|
44
|
-
* other one: a renderer that draws no 3D still draws
|
|
43
|
+
* bridges a panel and another context (`Scene` opens a scene inside a panel),
|
|
44
|
+
* the other one: a renderer that draws no 3D still draws panels whole.
|
|
45
45
|
*/
|
|
46
46
|
const contextOf = (component: {context: BlokContextName; childrenContext: BlokContextName | null}): BlokContextName =>
|
|
47
|
-
component.context !== '
|
|
47
|
+
component.context !== 'PANEL' ? component.context : (component.childrenContext ?? 'PANEL');
|
|
48
48
|
|
|
49
49
|
/** The contexts in which `catalog` draws every component of the base catalog. */
|
|
50
50
|
export const baseContextsOf = (catalog: BlokCatalog): BlokContextName[] => {
|