@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
2
|
import {controlBlokComponents} from '../renderer/bloks/control';
|
|
3
3
|
import {BASE_CATALOG_REF, describeBlokContract, type SpecComponentJson} from '../renderer/runtime';
|
|
4
|
-
import baseCatalogJson from '../spec/catalogs/base@
|
|
4
|
+
import baseCatalogJson from '../spec/catalogs/base@4.json';
|
|
5
5
|
import {baseFamilies} from './index';
|
|
6
6
|
import {parts} from './parts';
|
|
7
7
|
|
|
@@ -47,7 +47,8 @@ describe('the families of the base catalog', () => {
|
|
|
47
47
|
const entry = shipped.get(component.name);
|
|
48
48
|
expect(entry, component.name).toBeDefined();
|
|
49
49
|
expect(entry?.group === 'language' || entry?.group === 'run', component.name).toBe(true);
|
|
50
|
-
|
|
50
|
+
// `children` is a slot where a component takes children; a `<local>`'s is a prop (its child ports).
|
|
51
|
+
const props = Object.keys(component.schema.shape).filter(key => key !== 'children' || !component.acceptsChildren).sort();
|
|
51
52
|
expect(props, component.name).toEqual((entry?.props ?? []).map(prop => prop.key).sort());
|
|
52
53
|
}
|
|
53
54
|
});
|
package/src/catalogs/index.ts
CHANGED
|
@@ -11,6 +11,6 @@ export * from './props';
|
|
|
11
11
|
/**
|
|
12
12
|
* The families of the base catalog this package holds contracts for: every
|
|
13
13
|
* component of it that is not the language's own (`renderer/bloks/control`).
|
|
14
|
-
* The spec's `catalogs/base@
|
|
14
|
+
* The spec's `catalogs/base@4.json` is what they say (`catalogs.test.ts`).
|
|
15
15
|
*/
|
|
16
16
|
export const baseFamilies = [uiCatalog, htmlCatalog, logoCatalog, sceneCatalog, structureCatalog, shadcnCatalog] as const;
|
package/src/catalogs/logo.ts
CHANGED
|
@@ -7,8 +7,6 @@ export const logoCatalog = defineBlokCatalog({
|
|
|
7
7
|
partOf: BASE_CATALOG_REF,
|
|
8
8
|
description: "SVG drawing for logos and action logos; the palette is restricted to the logo pens.",
|
|
9
9
|
components: {
|
|
10
|
-
ActionLogo: parts.ActionLogo,
|
|
11
|
-
AgentLogo: parts.AgentLogo,
|
|
12
10
|
Circle: parts.Circle,
|
|
13
11
|
ClipPath: parts.ClipPath,
|
|
14
12
|
Defs: parts.Defs,
|
|
@@ -16,6 +14,7 @@ export const logoCatalog = defineBlokCatalog({
|
|
|
16
14
|
G: parts.G,
|
|
17
15
|
Line: parts.Line,
|
|
18
16
|
LinearGradient: parts.LinearGradient,
|
|
17
|
+
Logo: parts.Logo,
|
|
19
18
|
Path: parts.Path,
|
|
20
19
|
Polygon: parts.Polygon,
|
|
21
20
|
Polyline: parts.Polyline,
|
|
@@ -5,14 +5,14 @@ import {loadVocabulary} from '../../spec/vocabulary';
|
|
|
5
5
|
import {actionProp, describedString} from '../props';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* The `logo` family of the blok language: the `
|
|
9
|
-
*
|
|
8
|
+
* The `logo` family of the blok language: the `Logo` drawing and the classic
|
|
9
|
+
* SVG elements as components.
|
|
10
10
|
*
|
|
11
|
-
* A
|
|
12
|
-
* `Path` or a `Circle` is only ever placed inside one.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* A `Logo` sits in a panel like `Scene` does and opens the `logo` context, so
|
|
12
|
+
* a `Path` or a `Circle` is only ever placed inside one. It is the one element
|
|
13
|
+
* of a logo blok (`<Blok kind="agent" context="logo"><Logo>`); an action's
|
|
14
|
+
* logo is `<Blok kind="action" context="logo">` and reads only `task`, the
|
|
15
|
+
* viewer's last task of the action. Any panel may draw a `Logo` too.
|
|
16
16
|
*
|
|
17
17
|
* A logo paints with the viewer's pens only (vocabulary `theme.logo_pens`:
|
|
18
18
|
* `ink`, `brand`, ..., the status roles `success`, `warning`, `info`), drawn
|
|
@@ -39,11 +39,10 @@ export const LOGO_ANIMATIONS = ['spin', 'pulse', 'float', 'draw', 'march', 'blin
|
|
|
39
39
|
const length = (description: string) =>
|
|
40
40
|
z.union([z.number(), z.string()]).optional().describe(description);
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
export const
|
|
44
|
-
export const LOGO_ROOTS = [AGENT_LOGO_ROOT, ACTION_LOGO_ROOT];
|
|
42
|
+
/** A logo's drawing: the one element of a logo blok. */
|
|
43
|
+
export const LOGO_ROOT = 'Logo';
|
|
45
44
|
|
|
46
|
-
const IN_SVG: BlokComponentPlacement = {context: 'logo', downstreamOf:
|
|
45
|
+
const IN_SVG: BlokComponentPlacement = {context: 'logo', downstreamOf: [LOGO_ROOT]};
|
|
47
46
|
|
|
48
47
|
/* -------------------------------------------------------------------------- */
|
|
49
48
|
/* Presentation: what every shape and group may set */
|
|
@@ -143,7 +142,7 @@ const rootSchema = (description: string) =>
|
|
|
143
142
|
/** A drawing's root: an `<svg>` whose shapes paint with the pens. */
|
|
144
143
|
const logoRoot = (description: string) => ({
|
|
145
144
|
acceptsChildren: true,
|
|
146
|
-
placement: {childrenContext: 'logo', notDownstreamOf:
|
|
145
|
+
placement: {childrenContext: 'logo', notDownstreamOf: [LOGO_ROOT]} satisfies BlokComponentPlacement,
|
|
147
146
|
schema: rootSchema(description),
|
|
148
147
|
});
|
|
149
148
|
|
|
@@ -158,11 +157,8 @@ const gradientUnits = z
|
|
|
158
157
|
|
|
159
158
|
/** The `logo` family: the root, seven shapes, text, and what shapes reference. */
|
|
160
159
|
export const logoContracts = {
|
|
161
|
-
[
|
|
162
|
-
"
|
|
163
|
-
),
|
|
164
|
-
[ACTION_LOGO_ROOT]: logoRoot(
|
|
165
|
-
"The root of an action's logo: a drawing in the viewer's pens that reads task (the viewer's last task of the action, idle until they run it). Its children are SVG shapes.",
|
|
160
|
+
[LOGO_ROOT]: logoRoot(
|
|
161
|
+
"A logo's drawing, the one element of a logo blok: an SVG in the viewer's pens (an action's paints with the pens only). Its children are SVG shapes.",
|
|
166
162
|
),
|
|
167
163
|
Path: shape('An SVG path.', shapeGeometry.Path),
|
|
168
164
|
Circle: shape('An SVG circle.', shapeGeometry.Circle),
|
|
@@ -19,12 +19,6 @@ import {actionProp, bindSchema, describedString} from '../props';
|
|
|
19
19
|
|
|
20
20
|
export const sceneSchema = z
|
|
21
21
|
.object({
|
|
22
|
-
chrome: z
|
|
23
|
-
.enum(['auto', 'none'])
|
|
24
|
-
.optional()
|
|
25
|
-
.describe(
|
|
26
|
-
"What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
|
|
27
|
-
),
|
|
28
22
|
camera: z
|
|
29
23
|
.enum(['iso', 'front', 'side', 'top'])
|
|
30
24
|
.optional()
|
|
@@ -292,7 +286,7 @@ export const sceneContracts = {
|
|
|
292
286
|
OnClick: {placement: IN_MODEL_OR_AT, schema: onClickSchema},
|
|
293
287
|
Popout: {
|
|
294
288
|
acceptsChildren: true,
|
|
295
|
-
placement: {...IN_MODEL_OR_AT, childrenContext: '
|
|
289
|
+
placement: {...IN_MODEL_OR_AT, childrenContext: 'panel'},
|
|
296
290
|
schema: popoutSchema,
|
|
297
291
|
},
|
|
298
292
|
} satisfies BlokComponentContracts;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The pen this app draws its action logos with: logo bloks in v2 BSX
|
|
3
|
-
*
|
|
2
|
+
* The pen this app draws its action logos with: logo bloks in v2 BSX
|
|
3
|
+
* (`<Blok kind="action" context="logo"><Logo>`), on a 24 px grid, painted with the viewer's pens
|
|
4
4
|
* only (vocabulary `theme.logo_pens`: `ink muted brand brand-strong brand-soft
|
|
5
5
|
* surface none`, the status pens `success warning info` and the spectral pens
|
|
6
6
|
* `spectrum-violet` ... `spectrum-red`, for a logo of something that has a
|
|
@@ -19,6 +19,6 @@ export const ACTION_LOGO_PEN =
|
|
|
19
19
|
/** An attribute literal: in v2 BSX `"..."` is always a string, so only the markup needs escaping. */
|
|
20
20
|
const attribute = (value: string): string => value.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
|
21
21
|
|
|
22
|
-
/** An
|
|
22
|
+
/** An action's logo blok of `body`, drawn with the pen. */
|
|
23
23
|
export const actionLogoSource = (title: string, body: string): string =>
|
|
24
|
-
`<
|
|
24
|
+
`<Blok kind="action" context="logo"><Logo viewBox="0 0 24 24" title="${attribute(title)}"><G ${ACTION_LOGO_PEN}>${body}</G></Logo></Blok>`;
|
|
@@ -7,21 +7,21 @@ import {BlokComponentHost} from './BlokComponentHost';
|
|
|
7
7
|
|
|
8
8
|
afterEach(cleanup);
|
|
9
9
|
|
|
10
|
-
/** `<
|
|
10
|
+
/** `<fragment><Card><Input bind={value} placeholder="scale" /><p>{limit}</p></Card></fragment>`, as the server sends it. */
|
|
11
11
|
const NODES = [
|
|
12
12
|
{
|
|
13
|
-
id: '
|
|
13
|
+
id: 'fragment[0]/Card[0]',
|
|
14
14
|
component: 'Card',
|
|
15
15
|
children: [
|
|
16
16
|
{
|
|
17
|
-
id: '
|
|
17
|
+
id: 'fragment[0]/Card[0]/Input[0]',
|
|
18
18
|
component: 'Input',
|
|
19
19
|
props: [
|
|
20
20
|
{key: 'bind', dynamic_value: {path: 'value'}},
|
|
21
21
|
{key: 'placeholder', static_value: 'scale'},
|
|
22
22
|
],
|
|
23
23
|
},
|
|
24
|
-
{id: '
|
|
24
|
+
{id: 'fragment[0]/Card[0]/p[0]', component: 'p', props: [{key: 'text', dynamic_value: {path: 'limit'}}]},
|
|
25
25
|
],
|
|
26
26
|
},
|
|
27
27
|
];
|
|
@@ -31,7 +31,7 @@ describe('BlokComponentHost with a tree', () => {
|
|
|
31
31
|
const onValue = vi.fn();
|
|
32
32
|
render(
|
|
33
33
|
<BlokComponentHost
|
|
34
|
-
component="
|
|
34
|
+
component="fragment"
|
|
35
35
|
props={[]}
|
|
36
36
|
nodes={NODES}
|
|
37
37
|
data={{value: 'a', limit: 'up to 9'}}
|
|
@@ -9,6 +9,28 @@ import {testCatalog} from './bloks/testing';
|
|
|
9
9
|
afterEach(cleanup);
|
|
10
10
|
|
|
11
11
|
describe('BlokRenderer', () => {
|
|
12
|
+
it('draws no frame around a scene blok, whatever chrome the host asks for', () => {
|
|
13
|
+
const blok = (context: string) => [
|
|
14
|
+
{
|
|
15
|
+
id: 'Blok[0]',
|
|
16
|
+
component: 'Blok',
|
|
17
|
+
props: [
|
|
18
|
+
{key: 'kind', static_value: 'custom'},
|
|
19
|
+
{key: 'context', static_value: context},
|
|
20
|
+
],
|
|
21
|
+
children: [{id: 'Blok[0]/Button[0]', component: 'Button'}],
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
const framed = (context: string) => {
|
|
25
|
+
const {container, unmount} = render(<BlokRenderer catalog={testCatalog()} chrome="minimal" uiComponents={blok(context)} />);
|
|
26
|
+
const border = container.querySelector('.a2ui-container')?.className.includes('border');
|
|
27
|
+
unmount();
|
|
28
|
+
return border;
|
|
29
|
+
};
|
|
30
|
+
expect(framed('panel')).toBe(true);
|
|
31
|
+
expect(framed('scene')).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
12
34
|
it('resolves a function of the vocabulary on the first render', () => {
|
|
13
35
|
render(
|
|
14
36
|
<BlokRenderer catalog={testCatalog()}
|
|
@@ -4,10 +4,12 @@ import {cn} from '../vendor/core/util/utils';
|
|
|
4
4
|
import {useBlokTailwind} from '../tailwind/useBlokTailwind';
|
|
5
5
|
import BlokDebugState from './BlokDebugState';
|
|
6
6
|
import {SceneModelScopeProvider, useSceneNotice} from './bloks/scene/context';
|
|
7
|
-
import {BlokSceneFillProvider} from './bloks/scene/host';
|
|
7
|
+
import {BlokSceneControlsProvider, BlokSceneFillProvider} from './bloks/scene/host';
|
|
8
8
|
import {useBlokCatalog} from './catalog';
|
|
9
9
|
import {invokeBlokFunction} from './functions/v2/handler';
|
|
10
10
|
import {BlokComponentStateContext, type BlokComponentStateStore} from './persist';
|
|
11
|
+
import {drawnChildren} from './bloks/control';
|
|
12
|
+
import {treeQueries, treeSubscriptions} from './declarations';
|
|
11
13
|
import {
|
|
12
14
|
BlokNode,
|
|
13
15
|
BlokNodeErrorSurface,
|
|
@@ -15,10 +17,14 @@ import {
|
|
|
15
17
|
BlokTreeProvider,
|
|
16
18
|
createBlokRuntimeStore,
|
|
17
19
|
dependencyStatusPath,
|
|
20
|
+
BlokLocalsScope,
|
|
21
|
+
localChildren,
|
|
22
|
+
normalizeBlokComponentTree,
|
|
18
23
|
preflightBlokDocument,
|
|
19
24
|
unboundDependencyStatus,
|
|
20
25
|
unboundDependencyStatuses,
|
|
21
26
|
type BlokCatalog,
|
|
27
|
+
type BlokComponentNode,
|
|
22
28
|
type BlokNodeErrorProps,
|
|
23
29
|
type BlokDispatchActionHandler,
|
|
24
30
|
type BlokInvokeFunctionHandler,
|
|
@@ -62,22 +68,32 @@ type BlokRendererProps = {
|
|
|
62
68
|
* inside its canvas: no element of its own, and its `Scene` adds to that one.
|
|
63
69
|
*/
|
|
64
70
|
embedded?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether a scene shows its own view controls (where to look from, frame,
|
|
73
|
+
* grid, settings). On by default; a host showing the blok as a preview turns
|
|
74
|
+
* them off. A thumbnail never shows them.
|
|
75
|
+
*/
|
|
76
|
+
sceneControls?: boolean;
|
|
65
77
|
/** Shows the floating runtime-state inspector. Off by default. */
|
|
66
78
|
debug?: boolean;
|
|
67
79
|
/**
|
|
68
|
-
* Locals kept from an earlier opening, by
|
|
69
|
-
* first render on (`./persist.ts`). Read once, when the renderer mounts.
|
|
80
|
+
* Locals kept from an earlier opening, by runtime id (`runtimeIdOf`), shown
|
|
81
|
+
* from the first render on (`./persist.ts`). Read once, when the renderer mounts.
|
|
70
82
|
*/
|
|
71
83
|
keptValues?: Record<string, unknown>;
|
|
72
|
-
/** The
|
|
73
|
-
|
|
84
|
+
/** The `<local>` node ids kept between openings: swapping the payload leaves their values alone. */
|
|
85
|
+
keptLocals?: ReadonlySet<string>;
|
|
74
86
|
/** Source statuses known before the first render, by data-model path (`deps.robot.arm`: pending). */
|
|
75
87
|
statuses?: Readonly<Record<string, BlokSourceStatus>>;
|
|
76
88
|
/** The moment the blok shows while travelling (ISO 8601): commands and toasts are off, inputs read-only. */
|
|
77
89
|
travelAt?: string | null;
|
|
78
90
|
/** Who is looking: `viewer`. */
|
|
79
91
|
viewer?: BlokViewer | null;
|
|
80
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* The blok's reads, and how they run; a preview runs none (it seeds
|
|
94
|
+
* `demo.queries`). Left out, the tree's `<query>` and `<subscription>`
|
|
95
|
+
* children (`treeQueries`).
|
|
96
|
+
*/
|
|
81
97
|
queries?: readonly BlokQuery[];
|
|
82
98
|
subscriptions?: readonly BlokSubscription[];
|
|
83
99
|
readExecutor?: BlokReadExecutor;
|
|
@@ -107,14 +123,25 @@ const EmbeddedNodeError = ({componentId, title, detail}: BlokNodeErrorProps) =>
|
|
|
107
123
|
<EmbeddedNotice title={title} detail={detail ? `${detail} (${componentId})` : componentId} />
|
|
108
124
|
);
|
|
109
125
|
|
|
110
|
-
/**
|
|
126
|
+
/** Whether `root` is a `<Blok context="scene">`. */
|
|
127
|
+
const isSceneBlok = (root: BlokComponentNode | undefined): boolean =>
|
|
128
|
+
root?.component === 'Blok' && (root.props ?? []).some(prop => prop.key === 'context' && prop.static_value === 'scene');
|
|
129
|
+
|
|
130
|
+
/** What a root draws: a `<Blok>`'s one element (its first drawn child), any other root itself. */
|
|
131
|
+
const drawnRoot = (tree: BlokTree, rootId: string): string | undefined => {
|
|
132
|
+
const node = tree.nodes.get(rootId)?.node;
|
|
133
|
+
if (node?.component !== 'Blok') return node?.component;
|
|
134
|
+
return drawnChildren(node)[0]?.component;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** The roots of a blok shown in a scene that is already open. Only a blok that opens a scene can stand in one. */
|
|
111
138
|
const EmbeddedRoots = ({tree, rootIds, errors}: {tree: BlokTree; rootIds: string[]; errors: string[]}) => (
|
|
112
139
|
<>
|
|
113
140
|
{errors.map(error => (
|
|
114
141
|
<EmbeddedNotice key={error} title="Blok payload could not be parsed" detail={error} />
|
|
115
142
|
))}
|
|
116
143
|
{rootIds.map(rootId => {
|
|
117
|
-
const component = tree
|
|
144
|
+
const component = drawnRoot(tree, rootId);
|
|
118
145
|
const opensScene =
|
|
119
146
|
!component || tree.catalog.components.get(component)?.placement?.childrenContext === 'scene';
|
|
120
147
|
return opensScene ? (
|
|
@@ -140,14 +167,15 @@ export default function BlokRenderer({
|
|
|
140
167
|
chrome = 'default',
|
|
141
168
|
sizing = 'fill',
|
|
142
169
|
embedded = false,
|
|
170
|
+
sceneControls = true,
|
|
143
171
|
debug = false,
|
|
144
172
|
keptValues,
|
|
145
|
-
|
|
173
|
+
keptLocals,
|
|
146
174
|
statuses,
|
|
147
175
|
travelAt = null,
|
|
148
176
|
viewer = null,
|
|
149
|
-
queries
|
|
150
|
-
subscriptions
|
|
177
|
+
queries: givenQueries,
|
|
178
|
+
subscriptions: givenSubscriptions,
|
|
151
179
|
readExecutor,
|
|
152
180
|
answerTask,
|
|
153
181
|
startRun,
|
|
@@ -162,6 +190,22 @@ export default function BlokRenderer({
|
|
|
162
190
|
[catalog, uiComponents],
|
|
163
191
|
);
|
|
164
192
|
|
|
193
|
+
const roots = useMemo(
|
|
194
|
+
() => normalizeBlokComponentTree(Array.isArray(uiComponents) ? uiComponents : uiComponents ? [uiComponents] : null).roots,
|
|
195
|
+
[uiComponents],
|
|
196
|
+
);
|
|
197
|
+
const queries = useMemo(() => givenQueries ?? (roots.length === 1 ? treeQueries(roots[0]) : NO_QUERIES), [givenQueries, roots]);
|
|
198
|
+
const subscriptions = useMemo(
|
|
199
|
+
() => givenSubscriptions ?? (roots.length === 1 ? treeSubscriptions(roots[0]) : NO_SUBSCRIPTIONS),
|
|
200
|
+
[givenSubscriptions, roots],
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// A scene blok is its canvas: the host draws no frame around it, and it fills the box it is in.
|
|
204
|
+
const sceneRoot = useMemo(() => roots.length === 1 && isSceneBlok(roots[0] as BlokComponentNode), [roots]);
|
|
205
|
+
const frame = sceneRoot ? 'none' : chrome;
|
|
206
|
+
|
|
207
|
+
const rootLocals = useMemo(() => (roots.length === 1 ? localChildren(roots[0] as BlokComponentNode) : []), [roots]);
|
|
208
|
+
|
|
165
209
|
const tree = useMemo<BlokTree>(
|
|
166
210
|
() => ({
|
|
167
211
|
catalog,
|
|
@@ -201,7 +245,7 @@ export default function BlokRenderer({
|
|
|
201
245
|
unavailableDependencies,
|
|
202
246
|
lockedActions,
|
|
203
247
|
keptValues,
|
|
204
|
-
|
|
248
|
+
keptLocals,
|
|
205
249
|
statuses: unboundDependencies?.length ? {...statuses, ...unboundDependencyStatuses(unboundDependencies)} : statuses,
|
|
206
250
|
travelAt,
|
|
207
251
|
answerTask,
|
|
@@ -239,8 +283,8 @@ export default function BlokRenderer({
|
|
|
239
283
|
}, [controlTask, runtimeStore]);
|
|
240
284
|
|
|
241
285
|
useEffect(() => {
|
|
242
|
-
if (
|
|
243
|
-
}, [
|
|
286
|
+
if (keptLocals) runtimeStore.getState().setKeptLocals(keptLocals);
|
|
287
|
+
}, [keptLocals, runtimeStore]);
|
|
244
288
|
|
|
245
289
|
useEffect(() => {
|
|
246
290
|
runtimeStore.getState().setInitialDataModel(initialState);
|
|
@@ -284,9 +328,9 @@ export default function BlokRenderer({
|
|
|
284
328
|
const containerClassName = cn(
|
|
285
329
|
'a2ui-container relative',
|
|
286
330
|
sizingClassName,
|
|
287
|
-
|
|
331
|
+
frame === 'none'
|
|
288
332
|
? ''
|
|
289
|
-
:
|
|
333
|
+
: frame === 'minimal'
|
|
290
334
|
? 'rounded-xl border border-border/50 bg-background/90 p-1 shadow-sm'
|
|
291
335
|
: 'rounded-2xl border border-border/60 bg-background/70 p-4 shadow-sm backdrop-blur-sm',
|
|
292
336
|
);
|
|
@@ -303,11 +347,14 @@ export default function BlokRenderer({
|
|
|
303
347
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
304
348
|
useBlokTailwind(preflight.nodes, embedded ? undefined : containerRef);
|
|
305
349
|
|
|
350
|
+
// A query's variables read the blok-level locals: the <Blok>'s own.
|
|
306
351
|
const syncs = (
|
|
307
352
|
<>
|
|
308
353
|
<BlokViewerSync viewer={viewer} />
|
|
309
354
|
{readExecutor && (queries.length > 0 || subscriptions.length > 0) ? (
|
|
310
|
-
<
|
|
355
|
+
<BlokLocalsScope locals={rootLocals}>
|
|
356
|
+
<BlokReads queries={queries} subscriptions={subscriptions} executor={readExecutor} />
|
|
357
|
+
</BlokLocalsScope>
|
|
311
358
|
) : null}
|
|
312
359
|
</>
|
|
313
360
|
);
|
|
@@ -338,17 +385,19 @@ export default function BlokRenderer({
|
|
|
338
385
|
<BlokComponentStateContext.Provider value={componentState}>
|
|
339
386
|
<BlokRuntimeProvider store={runtimeStore}>
|
|
340
387
|
<BlokTreeProvider tree={tree}>
|
|
341
|
-
{children}
|
|
342
388
|
{syncs}
|
|
343
|
-
<
|
|
389
|
+
<BlokSceneControlsProvider value={sceneControls}>
|
|
390
|
+
<BlokSceneFillProvider value={frame === 'none'}>
|
|
344
391
|
<div ref={containerRef} className={containerClassName}>
|
|
345
392
|
{debug && <BlokDebugState surfaceId={surfaceId} />}
|
|
393
|
+
{/* What the host adds (a notice that the tree was cut): inside the box, so it scrolls with the blok instead of pushing it out. */}
|
|
394
|
+
{children}
|
|
346
395
|
|
|
347
396
|
{documentErrors.length > 0 && (
|
|
348
397
|
<div
|
|
349
398
|
className={cn(
|
|
350
399
|
'rounded-xl border border-destructive/30 bg-background/80 p-4',
|
|
351
|
-
|
|
400
|
+
frame === 'default' ? 'mb-4' : 'mb-2',
|
|
352
401
|
)}
|
|
353
402
|
>
|
|
354
403
|
<h3 className="text-sm font-semibold text-destructive">
|
|
@@ -380,6 +429,7 @@ export default function BlokRenderer({
|
|
|
380
429
|
))}
|
|
381
430
|
</div>
|
|
382
431
|
</BlokSceneFillProvider>
|
|
432
|
+
</BlokSceneControlsProvider>
|
|
383
433
|
</BlokTreeProvider>
|
|
384
434
|
</BlokRuntimeProvider>
|
|
385
435
|
</BlokComponentStateContext.Provider>
|
|
@@ -9,7 +9,7 @@ import { createBlokCatalog, createBlokComponent } from "./runtime";
|
|
|
9
9
|
|
|
10
10
|
const part = (name: string) => createBlokComponent({ name, schema: z.object({}) }, () => null);
|
|
11
11
|
/** A component of the base catalog, as `implementBlokCatalog` tags one of its families'. */
|
|
12
|
-
const base = (name: string) => ({ ...part(name), origin: "base@
|
|
12
|
+
const base = (name: string) => ({ ...part(name), origin: "base@4" });
|
|
13
13
|
|
|
14
14
|
describe("addBlokComponents", () => {
|
|
15
15
|
it("adds a module's components and takes them back out", () => {
|
|
@@ -5,12 +5,12 @@ import {createBlokCatalog, type BlokCatalog} from './runtime';
|
|
|
5
5
|
* The part of the base catalog the renderer itself draws, whatever toolkit
|
|
6
6
|
* draws the rest: the language's elements (`if`/`else`, `foreach`,
|
|
7
7
|
* `match`/`case`/`default`, `fragment`, `suspense`/`fallback`/`error`, the
|
|
8
|
-
*
|
|
8
|
+
* the `Blok` element, the declarations, text) and the parts of a host's interface a blok may
|
|
9
9
|
* place (`ask`, `args`, `timeline`, ...), which the host supplies. Its
|
|
10
10
|
* functions are the vocabulary's (`functions/v2`), evaluated by the renderer.
|
|
11
11
|
*/
|
|
12
12
|
export const BASE_CATALOG_NAME = 'base';
|
|
13
|
-
export const BASE_CATALOG_VERSION =
|
|
13
|
+
export const BASE_CATALOG_VERSION = 4;
|
|
14
14
|
export const BASE_CATALOG_ID = `${BASE_CATALOG_NAME}@${BASE_CATALOG_VERSION}`;
|
|
15
15
|
|
|
16
16
|
export const baseBlokCatalog: BlokCatalog = createBlokCatalog(BASE_CATALOG_ID, controlBlokComponents);
|