@arkitektio/bsx 4.3.0 → 6.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/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 +19 -8
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +49 -59
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +25 -35
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +48 -54
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +359 -159
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +3 -3
- 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 +172 -180
- 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 +19 -33
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +4 -5
- 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 +24 -24
- package/dist/catalogs/parts/html.d.ts +3 -3
- 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 +153 -165
- 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 +17 -32
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +13 -15
- 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 +5 -13
- 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 +9 -17
- 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/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.d.ts +3 -3
- package/dist/catalogs/parts/typography.js +1 -1
- package/dist/catalogs/parts/typography.js.map +1 -1
- package/dist/catalogs/props.d.ts +4 -4
- package/dist/catalogs/scene.d.ts +8 -16
- 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 +58 -58
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +4 -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/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/ports.js +1 -1
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +10 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +23 -9
- 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 +20 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +98 -15
- 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 +24 -24
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/html.js +2 -2
- package/dist/renderer/bloks/icons.d.ts +5 -5
- package/dist/renderer/bloks/index.d.ts +145 -144
- 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 +6 -13
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +3 -4
- 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 +20 -20
- package/dist/renderer/bloks/overlays.d.ts +55 -55
- package/dist/renderer/bloks/run/components.d.ts +2 -6
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +5 -9
- 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/toast.d.ts +1 -1
- package/dist/renderer/bloks/typography.d.ts +3 -3
- 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/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.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/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 +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 +10 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +8 -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 +16 -6
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +5 -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 +2 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +2 -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/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/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/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/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/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 +154 -153
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +7 -7
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +12324 -6934
- package/dist/spec/catalogs/base@4.json +13175 -0
- package/dist/spec/catalogs/base@4.json.js +13175 -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 +243 -75
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +44 -7
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +65 -7
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +83 -43
- package/dist/spec/vocabulary.json.js +83 -43
- 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/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 +54 -52
- 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 +51 -64
- package/src/bsx/partial.test.ts +1 -1
- package/src/bsx/print.ts +27 -34
- package/src/bsx/references.test.ts +86 -83
- package/src/bsx/references.ts +391 -198
- package/src/catalogs/catalogs.test.ts +46 -14
- package/src/catalogs/html.ts +3 -3
- package/src/catalogs/index.ts +6 -2
- package/src/catalogs/logo.ts +4 -5
- 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 +14 -18
- package/src/catalogs/parts/run.ts +1 -1
- package/src/catalogs/parts/scene.ts +1 -7
- 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 +4 -4
- package/src/catalogs/structure.ts +3 -3
- package/src/catalogs/ui.ts +4 -3
- package/src/catalogs.ts +9 -2
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/ports.ts +1 -1
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.tsx +46 -14
- 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 +136 -17
- package/src/renderer/bloks/flow.test.tsx +1 -1
- 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 +4 -5
- 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/components.tsx +1 -1
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- 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/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +41 -0
- package/src/renderer/declare.ts +70 -32
- 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 +35 -10
- package/src/renderer/runtime/components.tsx +17 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +21 -8
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +2 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/preflight.ts +5 -2
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/text.test.tsx +65 -0
- package/src/renderer/runtime/text.ts +88 -0
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/runtime.ts +0 -1
- package/src/scene.ts +2 -2
- package/src/shadcn.ts +7 -7
- package/src/spec/bsx_v2.json +12324 -6934
- package/src/spec/catalogs/base@4.json +13175 -0
- package/src/spec/catalogs/orkestrator@1.json +489 -0
- package/src/spec/catalogs.ts +259 -103
- package/src/spec/spec.test.ts +93 -24
- package/src/spec/vocabulary.json +83 -43
- package/src/spec/vocabulary.ts +102 -17
- 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 -355
- package/dist/spec/catalogs/base@2.json.js +0 -355
- 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 -878
- package/dist/spec/catalogs/scene@1.json.js +0 -878
- package/dist/spec/catalogs/shadcn@1.json +0 -4002
- package/dist/spec/catalogs/shadcn@1.json.js +0 -4002
- 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 -355
- 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 -878
- package/src/spec/catalogs/shadcn@1.json +0 -4002
- package/src/spec/catalogs/structure@1.json +0 -185
- package/src/spec/catalogs/ui@1.json +0 -5349
|
@@ -4,24 +4,40 @@ import type {BlokComponentContract, BlokComponentDefinition, BlokRenderArgs} fro
|
|
|
4
4
|
/**
|
|
5
5
|
* Catalogs as the UI defines them.
|
|
6
6
|
*
|
|
7
|
-
* A *contract* (`defineBlokCatalog`) says which components a
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
7
|
+
* A *contract* (`defineBlokCatalog`) says which components a set holds and what
|
|
8
|
+
* each takes: name, schema, placement. It draws nothing. There are two sorts:
|
|
9
|
+
*
|
|
10
|
+
* - A *family* of the base catalog (`ui`, `html`, `shadcn`, `structure`,
|
|
11
|
+
* `scene`, `logo`): `partOf` names the catalog it is part of (`base@4`). The
|
|
12
|
+
* base catalog is the spec's, and every renderer draws it whole; the families
|
|
13
|
+
* are how this package holds its contracts, one toolkit at a time.
|
|
14
|
+
* - A UI's *own* catalog (the Orkestrator's MikroScene parts): what it draws
|
|
15
|
+
* beyond the base. Given an `id` (the address it is published at) and a
|
|
16
|
+
* version it is an app catalog a blok can be written for.
|
|
12
17
|
*
|
|
13
18
|
* An *implementation* (`implementBlokCatalog`) is the app's: one render per
|
|
14
19
|
* component of a contract, a map the compiler checks against the contract.
|
|
15
20
|
*/
|
|
16
21
|
|
|
22
|
+
/** The base catalog, as components of it are tagged (`origin`). */
|
|
23
|
+
export const BASE_CATALOG_REF = 'base@4';
|
|
24
|
+
/** The address the base catalog is published at: what a blok is written for when it names none. */
|
|
25
|
+
export const BASE_CATALOG_ADDRESS = 'https://arkitekt.live/catalogs/base/v4';
|
|
26
|
+
|
|
17
27
|
export type BlokComponentContracts = Record<string, BlokComponentContract<any>>;
|
|
18
28
|
|
|
19
29
|
export type BlokCatalogContract<TComponents extends BlokComponentContracts = BlokComponentContracts> = {
|
|
20
30
|
name: string;
|
|
21
|
-
/** Set on a
|
|
31
|
+
/** Set on a published catalog (an app catalog's `1`); null on a family, and on a UI's own that nothing publishes. */
|
|
22
32
|
version: number | null;
|
|
23
33
|
description: string;
|
|
24
34
|
components: TComponents;
|
|
35
|
+
/** For a family: the catalog it is part of (`base@4`). Null on a catalog of its own. */
|
|
36
|
+
partOf: string | null;
|
|
37
|
+
/** For a published catalog: the address it is published at, which is what a blok names it by. */
|
|
38
|
+
id: string | null;
|
|
39
|
+
/** The id of the catalog it adds to; the base catalog's when left out. */
|
|
40
|
+
extends: string | null;
|
|
25
41
|
};
|
|
26
42
|
|
|
27
43
|
export const defineBlokCatalog = <const TComponents extends BlokComponentContracts>(contract: {
|
|
@@ -29,9 +45,18 @@ export const defineBlokCatalog = <const TComponents extends BlokComponentContrac
|
|
|
29
45
|
version?: number;
|
|
30
46
|
description: string;
|
|
31
47
|
components: TComponents;
|
|
32
|
-
|
|
48
|
+
partOf?: string;
|
|
49
|
+
id?: string;
|
|
50
|
+
extends?: string;
|
|
51
|
+
}): BlokCatalogContract<TComponents> => ({
|
|
52
|
+
...contract,
|
|
53
|
+
version: contract.version ?? null,
|
|
54
|
+
partOf: contract.partOf ?? null,
|
|
55
|
+
id: contract.id ?? null,
|
|
56
|
+
extends: contract.extends ?? null,
|
|
57
|
+
});
|
|
33
58
|
|
|
34
|
-
/** How a
|
|
59
|
+
/** How a contract is named: `name@version`, or the bare name of a family or of a UI's own unpublished catalog. */
|
|
35
60
|
export const catalogRef = (contract: Pick<BlokCatalogContract, 'name' | 'version'>): string =>
|
|
36
61
|
contract.version === null ? contract.name : `${contract.name}@${contract.version}`;
|
|
37
62
|
|
|
@@ -83,7 +108,7 @@ export function implementBlokCatalog(
|
|
|
83
108
|
}
|
|
84
109
|
const components = Object.entries(contract.components).flatMap(([name, component]): BlokComponentDefinition[] => {
|
|
85
110
|
const render = renders[name];
|
|
86
|
-
return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: ref}] : [];
|
|
111
|
+
return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: contract.partOf ?? ref}] : [];
|
|
87
112
|
});
|
|
88
113
|
return {contract, components, whole: missing.length === 0};
|
|
89
114
|
}
|
|
@@ -94,7 +119,7 @@ export function implementBlokCatalog(
|
|
|
94
119
|
* once. The UI owns both, so there is nothing to check one against.
|
|
95
120
|
*/
|
|
96
121
|
export const ownBlokCatalog = (
|
|
97
|
-
meta: {name: string; version?: number; description: string},
|
|
122
|
+
meta: {name: string; version?: number; description: string; id?: string; extends?: string},
|
|
98
123
|
components: readonly BlokComponentDefinition[],
|
|
99
124
|
): BlokCatalogImplementation => {
|
|
100
125
|
const contract = defineBlokCatalog({
|
|
@@ -15,8 +15,8 @@ export type BlokRenderArgs<TSchema extends BlokObjectSchema = BlokObjectSchema>
|
|
|
15
15
|
schema: TSchema;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
/** The renderer a component lives in. A blok's tree starts in `
|
|
19
|
-
export type BlokComponentContext = '
|
|
18
|
+
/** The renderer a component lives in. A blok's tree starts in `panel`. */
|
|
19
|
+
export type BlokComponentContext = 'panel' | 'scene' | 'logo';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Where a component may sit in a tree. Published with the catalog, so the
|
|
@@ -67,6 +67,12 @@ type BlokComponentApi = {
|
|
|
67
67
|
* where the schema itself only says "a path".
|
|
68
68
|
*/
|
|
69
69
|
bindKinds?: Readonly<Record<string, string>>;
|
|
70
|
+
/** The blok kinds it may be placed in (`assign`); any kind when left out. */
|
|
71
|
+
kinds?: readonly string[];
|
|
72
|
+
/** The service it needs where it is drawn (`mikro`): without it a notice shows in its place. */
|
|
73
|
+
service?: string;
|
|
74
|
+
/** The minor of its catalog that added it; the first when left out. */
|
|
75
|
+
since?: number;
|
|
70
76
|
};
|
|
71
77
|
|
|
72
78
|
/**
|
|
@@ -82,7 +88,7 @@ export type BlokComponentDefinition = BlokComponentApi & {
|
|
|
82
88
|
name: string;
|
|
83
89
|
schema: BlokObjectSchema;
|
|
84
90
|
render: React.ComponentType<BlokRenderArgs>;
|
|
85
|
-
/** The catalog
|
|
91
|
+
/** The catalog it is of (`base@4` for a component of one of its families, `newswitch`); unset for one built on its own. */
|
|
86
92
|
origin?: string;
|
|
87
93
|
};
|
|
88
94
|
|
|
@@ -99,6 +105,9 @@ export const createBlokComponent = <TSchema extends BlokObjectSchema>(
|
|
|
99
105
|
textProp: api.textProp,
|
|
100
106
|
events: api.events,
|
|
101
107
|
bindKinds: api.bindKinds,
|
|
108
|
+
kinds: api.kinds,
|
|
109
|
+
service: api.service,
|
|
110
|
+
since: api.since,
|
|
102
111
|
render: render as React.ComponentType<BlokRenderArgs>,
|
|
103
112
|
});
|
|
104
113
|
|
|
@@ -188,8 +197,8 @@ export class BlokNodeBoundary extends React.Component<
|
|
|
188
197
|
/* Statuses, guards and boundaries */
|
|
189
198
|
/* -------------------------------------------------------------------------- */
|
|
190
199
|
|
|
191
|
-
/** The renderer a node draws in: what decides how a pending node shows (a skeleton only in
|
|
192
|
-
export const BlokDrawContext = React.createContext<BlokComponentContext>('
|
|
200
|
+
/** The renderer a node draws in: what decides how a pending node shows (a skeleton only in a panel). */
|
|
201
|
+
export const BlokDrawContext = React.createContext<BlokComponentContext>('panel');
|
|
193
202
|
|
|
194
203
|
export const useBlokDrawContext = (): BlokComponentContext => React.useContext(BlokDrawContext);
|
|
195
204
|
|
|
@@ -279,7 +288,7 @@ const NodeGuard = (props: {
|
|
|
279
288
|
if (status.status === 'pending' || status.status === 'failed') {
|
|
280
289
|
// Inside a boundary its fallback or error shows; on its own a node shows
|
|
281
290
|
// its own skeleton or inline error, so a blok never blanks entirely.
|
|
282
|
-
if (caught || definition.placement?.inheritsContext || drawContext !== '
|
|
291
|
+
if (caught || definition.placement?.inheritsContext || drawContext !== 'panel') return null;
|
|
283
292
|
if (status.status === 'failed') {
|
|
284
293
|
return <BlokNodeError componentId={component.id} title="Could not load" detail={status.error ?? undefined} />;
|
|
285
294
|
}
|
|
@@ -300,7 +309,7 @@ const BlokComponentRendererInner = (props: {
|
|
|
300
309
|
const locked = useNodeLocked(props.props);
|
|
301
310
|
const parentContext = React.useContext(BlokDrawContext);
|
|
302
311
|
const placement = props.definition.placement ?? {};
|
|
303
|
-
const own = placement.inheritsContext ? parentContext : (placement.context ?? '
|
|
312
|
+
const own = placement.inheritsContext ? parentContext : (placement.context ?? 'panel');
|
|
304
313
|
const forChildren = placement.inheritsContext ? parentContext : (placement.childrenContext ?? own);
|
|
305
314
|
|
|
306
315
|
const rendered = (
|
|
@@ -326,7 +335,7 @@ const BlokComponentRendererInner = (props: {
|
|
|
326
335
|
// A node whose action a held lock keeps from running is marked for the `locked:`
|
|
327
336
|
// variant. The marker takes no box (`display: contents`), so the layout stays; a
|
|
328
337
|
// scene or a logo cannot hold an element, and is not marked.
|
|
329
|
-
if (!locked || own !== '
|
|
338
|
+
if (!locked || own !== 'panel') return rendered;
|
|
330
339
|
const Locked = blokPlatform().primitives.Locked ?? DomLocked;
|
|
331
340
|
return <Locked reason={locked}>{rendered}</Locked>;
|
|
332
341
|
};
|
|
@@ -4,6 +4,7 @@ import {useStore} from 'zustand';
|
|
|
4
4
|
import {createStore} from 'zustand/vanilla';
|
|
5
5
|
import {combineStatus, READY, type BlokSourceStatus} from './status';
|
|
6
6
|
import {isRecord, splitPathSegments} from './utils';
|
|
7
|
+
import {localNodeOfPath, localValuePath} from './locals';
|
|
7
8
|
import type {
|
|
8
9
|
BlokAgentMappingStateUpdates,
|
|
9
10
|
BlokDispatchActionHandler,
|
|
@@ -131,6 +132,12 @@ const isUnderRoot = (path: string, roots: ReadonlySet<string>): boolean => {
|
|
|
131
132
|
return root !== undefined && roots.has(root);
|
|
132
133
|
};
|
|
133
134
|
|
|
135
|
+
/** Whether a runtime value is a kept local's (one of `keptLocals`, in any foreach item). */
|
|
136
|
+
const isKeptLocal = (path: string, keptLocals: ReadonlySet<string>): boolean => {
|
|
137
|
+
const node = localNodeOfPath(path);
|
|
138
|
+
return node !== null && keptLocals.has(node);
|
|
139
|
+
};
|
|
140
|
+
|
|
134
141
|
export const createBlokRuntimeStore = (config?: {
|
|
135
142
|
initialDataModel?: unknown;
|
|
136
143
|
agentMappingStateUpdates?: BlokAgentMappingStateUpdates;
|
|
@@ -140,13 +147,13 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
140
147
|
unavailableDependencies?: BlokUnavailableDependencies;
|
|
141
148
|
lockedActions?: BlokLockedActions;
|
|
142
149
|
/**
|
|
143
|
-
* Locals the host kept from an earlier opening, by
|
|
144
|
-
* as runtime values
|
|
145
|
-
* them and clearing one shows its default again.
|
|
150
|
+
* Locals the host kept from an earlier opening, by runtime id (`runtimeIdOf`):
|
|
151
|
+
* written as runtime values at their paths (`localValuePath`), so the first
|
|
152
|
+
* render shows them and clearing one shows its default again.
|
|
146
153
|
*/
|
|
147
154
|
keptValues?: Record<string, unknown>;
|
|
148
|
-
/** The
|
|
149
|
-
|
|
155
|
+
/** The `<local>` node ids whose values a reset of the runtime values leaves alone (`keptValues`' and later edits of them). */
|
|
156
|
+
keptLocals?: ReadonlySet<string>;
|
|
150
157
|
/** Source statuses known before the first render (a preview's are all ready). */
|
|
151
158
|
statuses?: Readonly<Record<string, BlokSourceStatus>>;
|
|
152
159
|
travelAt?: string | null;
|
|
@@ -155,7 +162,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
155
162
|
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
156
163
|
}): BlokRuntimeStore => {
|
|
157
164
|
const initialDataModel = config?.initialDataModel;
|
|
158
|
-
const keptValues = config?.keptValues ?? {};
|
|
165
|
+
const keptValues = Object.fromEntries(Object.entries(config?.keptValues ?? {}).map(([runtimeId, value]) => [localValuePath(runtimeId), value]));
|
|
159
166
|
const initialAgentMappingStateUpdates = config?.agentMappingStateUpdates ?? {};
|
|
160
167
|
const invokeFunction = config?.invokeFunction ?? defaultInvokeFunction;
|
|
161
168
|
const dispatchAction = config?.dispatchAction ?? defaultDispatchAction;
|
|
@@ -164,7 +171,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
164
171
|
initialDataModel,
|
|
165
172
|
dataModel: modelOf(initialDataModel, config?.travelAt ?? null, keptValues),
|
|
166
173
|
runtimePathValues: {...keptValues},
|
|
167
|
-
|
|
174
|
+
keptLocals: config?.keptLocals ?? NONE_KEPT,
|
|
168
175
|
agentMappingStateUpdates: initialAgentMappingStateUpdates,
|
|
169
176
|
invokeFunction,
|
|
170
177
|
dispatchAction,
|
|
@@ -236,7 +243,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
236
243
|
set(currentState => {
|
|
237
244
|
const paths = Object.keys(currentState.runtimePathValues);
|
|
238
245
|
// What the host keeps between openings outlives a reset, as it outlives a reload.
|
|
239
|
-
const kept = paths.filter(path =>
|
|
246
|
+
const kept = paths.filter(path => isKeptLocal(path, currentState.keptLocals) || isUnderRoot(path, HOST_ROOTS));
|
|
240
247
|
if (kept.length === paths.length) {
|
|
241
248
|
return currentState;
|
|
242
249
|
}
|
|
@@ -248,8 +255,8 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
248
255
|
};
|
|
249
256
|
});
|
|
250
257
|
},
|
|
251
|
-
|
|
252
|
-
set({
|
|
258
|
+
setKeptLocals: nextKeptLocals => {
|
|
259
|
+
set({keptLocals: nextKeptLocals});
|
|
253
260
|
},
|
|
254
261
|
setRuntimeValue: (path, value) => {
|
|
255
262
|
set(currentState => {
|
|
@@ -5,10 +5,12 @@ import {isRequiredField} from './preflight';
|
|
|
5
5
|
import {isActionSchema, isBindSchema, unwrapSchema} from './schemas';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A contract
|
|
9
|
-
* `blok/catalogs/`)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* A contract in the spec's terms: what a catalog file (`spec/catalogs/base@4.json`,
|
|
9
|
+
* arkitekt-spec's `blok/catalogs/`) says of each component. Written from the
|
|
10
|
+
* contract, never by hand: the zod schemas are the source of a component's
|
|
11
|
+
* props and documentation, the JSON what they say in the spec's terms. The
|
|
12
|
+
* spec's base catalog is built from it (`pnpm spec:export`), and an app
|
|
13
|
+
* catalog is published as it (`blokCatalogSpec`).
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
export type SpecValueKind = 'STRING' | 'INT' | 'FLOAT' | 'BOOL' | 'DICT' | 'LIST' | 'ANY' | 'CALLBACK' | 'ASSET';
|
|
@@ -25,19 +27,27 @@ export type SpecPropJson = {
|
|
|
25
27
|
export type SpecComponentJson = {
|
|
26
28
|
name: string;
|
|
27
29
|
description: string | null;
|
|
28
|
-
context: '
|
|
29
|
-
children_context: '
|
|
30
|
+
context: 'PANEL' | 'SCENE' | 'LOGO';
|
|
31
|
+
children_context: 'PANEL' | 'SCENE' | 'LOGO' | null;
|
|
30
32
|
inherits_context: boolean;
|
|
31
33
|
accepts_children: boolean;
|
|
32
34
|
downstream_of: string[];
|
|
33
35
|
not_downstream_of: string[];
|
|
34
36
|
text_prop: string | null;
|
|
35
37
|
props: SpecPropJson[];
|
|
38
|
+
kinds?: string[];
|
|
39
|
+
service?: string;
|
|
40
|
+
since?: number;
|
|
36
41
|
};
|
|
37
42
|
|
|
38
43
|
export type SpecCatalogJson = {
|
|
44
|
+
/** The address a published catalog is known by. */
|
|
45
|
+
id?: string;
|
|
39
46
|
name: string;
|
|
40
47
|
version?: number;
|
|
48
|
+
minor?: number;
|
|
49
|
+
/** The id of the catalog it adds to. */
|
|
50
|
+
extends?: string;
|
|
41
51
|
description: string;
|
|
42
52
|
components: SpecComponentJson[];
|
|
43
53
|
};
|
|
@@ -112,7 +122,7 @@ export const zodToSpecKind = (schema: z.ZodTypeAny): SpecValueKind => {
|
|
|
112
122
|
}
|
|
113
123
|
};
|
|
114
124
|
|
|
115
|
-
const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {
|
|
125
|
+
const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {panel: 'PANEL', scene: 'SCENE', logo: 'LOGO'};
|
|
116
126
|
|
|
117
127
|
const byKey = <T extends {key: string}>(left: T, right: T) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
|
|
118
128
|
const byName = <T extends {name: string}>(left: T, right: T) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
@@ -155,7 +165,7 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
|
|
|
155
165
|
return {
|
|
156
166
|
name,
|
|
157
167
|
description: component.schema.description ?? null,
|
|
158
|
-
context: CONTEXT[placement.context ?? '
|
|
168
|
+
context: CONTEXT[placement.context ?? 'panel'],
|
|
159
169
|
children_context: placement.childrenContext ? CONTEXT[placement.childrenContext] : null,
|
|
160
170
|
inherits_context: placement.inheritsContext ?? false,
|
|
161
171
|
accepts_children: component.acceptsChildren ?? CHILDREN in shape,
|
|
@@ -163,6 +173,9 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
|
|
|
163
173
|
not_downstream_of: [...(placement.notDownstreamOf ?? [])],
|
|
164
174
|
text_prop: component.textProp ?? null,
|
|
165
175
|
props,
|
|
176
|
+
...(component.kinds?.length ? {kinds: [...component.kinds]} : {}),
|
|
177
|
+
...(component.service ? {service: component.service} : {}),
|
|
178
|
+
...(component.since ? {since: component.since} : {}),
|
|
166
179
|
};
|
|
167
180
|
};
|
|
168
181
|
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type BlokResolved,
|
|
17
17
|
} from './resolution';
|
|
18
18
|
import {isActionSchema} from './schemas';
|
|
19
|
-
import {isWritableScopedPath, readScopedPath, resolveScopedPath, useBlokScope} from './scope';
|
|
19
|
+
import {isWritableScopedPath, readScopedPath, resolveScopedPath, scopedWrite, useBlokScope} from './scope';
|
|
20
20
|
import {defaultBlokView} from '../../spec/catalogs';
|
|
21
21
|
import {useBlokNodeState} from './nodeState';
|
|
22
22
|
import {combineStatus, READY, type BlokSourceStatus} from './status';
|
|
@@ -680,13 +680,15 @@ export const useBinding = (
|
|
|
680
680
|
return undefined;
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
-
const absolutePath = resolveScopedPath(path, scope);
|
|
684
|
-
|
|
685
683
|
return {
|
|
686
684
|
value: snapshot.values.get(path),
|
|
687
685
|
// The past is read-only: a bound control shows what was, and writes nothing.
|
|
688
686
|
setValue: (value: unknown) => {
|
|
689
|
-
if (
|
|
687
|
+
if (travelling) return;
|
|
688
|
+
const state = store.getState();
|
|
689
|
+
const write = scopedWrite(state.dataModel, path, scope);
|
|
690
|
+
if (write.seed) state.setRuntimeValue(write.seed.path, write.seed.value);
|
|
691
|
+
store.getState().setRuntimeValue(write.path, value);
|
|
690
692
|
},
|
|
691
693
|
readOnly: travelling,
|
|
692
694
|
};
|
|
@@ -15,6 +15,7 @@ export * from './status';
|
|
|
15
15
|
export * from './resource';
|
|
16
16
|
export * from './reads';
|
|
17
17
|
export * from './task';
|
|
18
|
+
export * from './text';
|
|
18
19
|
export * from './tree';
|
|
19
20
|
export * from './types';
|
|
20
21
|
export * from './viewer';
|
|
@@ -31,3 +32,4 @@ export {
|
|
|
31
32
|
isString,
|
|
32
33
|
splitPathSegments,
|
|
33
34
|
} from './utils';
|
|
35
|
+
export * from './locals';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {runtimeIdOf, nodeOfRuntimeId} from '../../bsx/declared';
|
|
3
|
+
|
|
4
|
+
export {runtimeIdOf, nodeOfRuntimeId};
|
|
5
|
+
import {BlokScopeProvider} from './scope';
|
|
6
|
+
import type {BlokComponentNode} from './types';
|
|
7
|
+
import {splitPathSegments} from './utils';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Where a blok's `<local>` values live while it is open (blok language v2
|
|
11
|
+
* `locals.scope`).
|
|
12
|
+
*
|
|
13
|
+
* A `<local>` is in scope in its parent's subtree. Its value lives in the one
|
|
14
|
+
* runtime store under its *runtime id*: its node id plus one `@<item key>` per
|
|
15
|
+
* enclosing `foreach`, outermost first (`runtimeIdOf`), so inside a foreach
|
|
16
|
+
* every item has a value of its own. The value sits at `$locals/<runtime id,
|
|
17
|
+
* encoded as one path segment>`: a root no name a blok writes can be (`into`
|
|
18
|
+
* names are identifiers). It outlives an `if` branch closing, as long as the
|
|
19
|
+
* blok stays open. Until something writes it, it reads its default.
|
|
20
|
+
*
|
|
21
|
+
* When a node renders its children, its `local` children are provided to them
|
|
22
|
+
* as scope aliases `{name → that local's path}` (`BlokLocalsScope`); a bound
|
|
23
|
+
* control writes through the alias.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** The data-model root every local's value lives under. */
|
|
27
|
+
export const LOCALS_ROOT = '$locals';
|
|
28
|
+
|
|
29
|
+
/** One path segment for a runtime id: `/` and `.` would split it. */
|
|
30
|
+
const encodeSegment = (runtimeId: string): string => encodeURIComponent(runtimeId).replace(/\./g, '%2E');
|
|
31
|
+
|
|
32
|
+
/** The data-model path of the value of the local whose runtime id is `runtimeId`. */
|
|
33
|
+
export const localValuePath = (runtimeId: string): string => `${LOCALS_ROOT}/${encodeSegment(runtimeId)}`;
|
|
34
|
+
|
|
35
|
+
/** The runtime id of the local whose value `path` is (or is below), or null when it is no local's. */
|
|
36
|
+
export const runtimeIdOfPath = (path: string): string | null => {
|
|
37
|
+
const [root, segment] = splitPathSegments(path);
|
|
38
|
+
if (root !== LOCALS_ROOT || segment === undefined) return null;
|
|
39
|
+
try {
|
|
40
|
+
return decodeURIComponent(segment);
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The `<local>` node a runtime path value belongs to, or null when it is no local's. */
|
|
47
|
+
export const localNodeOfPath = (path: string): string | null => {
|
|
48
|
+
const runtimeId = runtimeIdOfPath(path);
|
|
49
|
+
return runtimeId === null ? null : nodeOfRuntimeId(runtimeId);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const NO_KEYS: readonly string[] = Object.freeze([]);
|
|
53
|
+
const BlokItemKeysContext = React.createContext<readonly string[]>(NO_KEYS);
|
|
54
|
+
|
|
55
|
+
/** The item keys of the foreach items this subtree is inside, outermost first (`7`, `#2`). */
|
|
56
|
+
export const useBlokItemKeys = (): readonly string[] => React.useContext(BlokItemKeysContext);
|
|
57
|
+
|
|
58
|
+
/** A subtree inside one more foreach item: `key` is the item's (`foreachItemIds` without the foreach's id and `@`). */
|
|
59
|
+
export const BlokItemKeyProvider = ({itemKey, children}: {itemKey: string; children: React.ReactNode}) => {
|
|
60
|
+
const outer = React.useContext(BlokItemKeysContext);
|
|
61
|
+
const keys = React.useMemo(() => [...outer, itemKey], [outer, itemKey]);
|
|
62
|
+
return <BlokItemKeysContext.Provider value={keys}>{children}</BlokItemKeysContext.Provider>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Passes the item keys through a boundary that drops React context (a scene's portal). */
|
|
66
|
+
export const BlokItemKeysBridge = ({keys, children}: {keys: readonly string[]; children: React.ReactNode}) => (
|
|
67
|
+
<BlokItemKeysContext.Provider value={keys}>{children}</BlokItemKeysContext.Provider>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
/** A `<local>` child as the renderer provides it: its node, the name it is read by, and its default. */
|
|
71
|
+
export type BlokLocalDeclaration = {node: string; name: string; default: unknown};
|
|
72
|
+
|
|
73
|
+
/** The `<local>` children of `node`, each with its name and default (a literal); one without a name is skipped. */
|
|
74
|
+
export const localChildren = (node: BlokComponentNode): BlokLocalDeclaration[] =>
|
|
75
|
+
(node.children ?? []).flatMap(child => {
|
|
76
|
+
if (child.component !== 'local') return [];
|
|
77
|
+
const name = child.props?.find(prop => prop.key === 'name');
|
|
78
|
+
const declared = name?.declares_value ?? (typeof name?.static_value === 'string' ? name.static_value : null);
|
|
79
|
+
if (!declared) return [];
|
|
80
|
+
const fallback = child.props?.find(prop => prop.key === 'default')?.static_value;
|
|
81
|
+
return [{node: child.id, name: declared, default: fallback ?? null}];
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Provides a node's locals to its children: each name aliased to the path of
|
|
86
|
+
* its value here (in this foreach item), reading its default until written.
|
|
87
|
+
*/
|
|
88
|
+
export const BlokLocalsScope = ({locals, children}: {locals: readonly BlokLocalDeclaration[]; children: React.ReactNode}) => {
|
|
89
|
+
const keys = useBlokItemKeys();
|
|
90
|
+
const {aliases, defaults} = React.useMemo(() => {
|
|
91
|
+
const aliases: Record<string, string> = {};
|
|
92
|
+
const defaults: Record<string, unknown> = {};
|
|
93
|
+
for (const local of locals) {
|
|
94
|
+
const path = localValuePath(runtimeIdOf(local.node, keys));
|
|
95
|
+
aliases[local.name] = path;
|
|
96
|
+
defaults[path] = local.default;
|
|
97
|
+
}
|
|
98
|
+
return {aliases, defaults};
|
|
99
|
+
}, [keys, locals]);
|
|
100
|
+
return (
|
|
101
|
+
<BlokScopeProvider aliases={aliases} defaults={defaults}>
|
|
102
|
+
{children}
|
|
103
|
+
</BlokScopeProvider>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
@@ -3,6 +3,7 @@ import type {BlokCatalog} from './functions';
|
|
|
3
3
|
import {BlokSchemas, isActionSchema} from './schemas';
|
|
4
4
|
import type {PreparedBlokNode} from './tree';
|
|
5
5
|
import type {BlokActionArgument, BlokComponentNode, BlokComponentProp} from './types';
|
|
6
|
+
import {lowerBlokText} from './text';
|
|
6
7
|
import {extractUiComponents, isRecord} from './utils';
|
|
7
8
|
import {loadVocabulary} from '../../spec/vocabulary';
|
|
8
9
|
|
|
@@ -192,7 +193,9 @@ export const preflightBlokDocument = (
|
|
|
192
193
|
const invalidNodes = new Map<string, string[]>();
|
|
193
194
|
const rootIds: string[] = [];
|
|
194
195
|
const unknownKinds = new Map<string, string[]>();
|
|
195
|
-
|
|
196
|
+
// Text is stored as nodes; what each component does with it is the catalog's to say.
|
|
197
|
+
const roots = extractUiComponents(uiComponents).map(raw => lowerBlokText(raw, catalog));
|
|
198
|
+
roots.forEach(raw => unknownCallKinds(raw, unknownKinds));
|
|
196
199
|
|
|
197
200
|
const pushError = (error: BlokValidationError) => {
|
|
198
201
|
errors.push(error);
|
|
@@ -242,7 +245,7 @@ export const preflightBlokDocument = (
|
|
|
242
245
|
});
|
|
243
246
|
};
|
|
244
247
|
|
|
245
|
-
|
|
248
|
+
roots.forEach((rawComponent, componentIndex) => {
|
|
246
249
|
const basePath = `uiComponents[${componentIndex}]`;
|
|
247
250
|
const parsed = BlokSchemas.ComponentNode.safeParse(rawComponent);
|
|
248
251
|
|
|
@@ -26,13 +26,15 @@ export const BlokScopeProvider = (props: {
|
|
|
26
26
|
aliases?: Readonly<Record<string, string>>;
|
|
27
27
|
values?: Readonly<Record<string, unknown>>;
|
|
28
28
|
basePath?: string;
|
|
29
|
+
/** What an alias reads before anything was written at its path, by the alias' absolute path (a `<local>`'s default). */
|
|
30
|
+
defaults?: Readonly<Record<string, unknown>>;
|
|
29
31
|
children: React.ReactNode;
|
|
30
32
|
}) => {
|
|
31
|
-
const {aliases, values, basePath, children} = props;
|
|
33
|
+
const {aliases, values, basePath, defaults, children} = props;
|
|
32
34
|
const parentScope = React.useContext(BlokScopeContext);
|
|
33
35
|
|
|
34
36
|
const scope = React.useMemo<BlokScope>(() => {
|
|
35
|
-
if (!aliases && !values && basePath === undefined) {
|
|
37
|
+
if (!aliases && !values && basePath === undefined && !defaults) {
|
|
36
38
|
return parentScope;
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -40,8 +42,9 @@ export const BlokScopeProvider = (props: {
|
|
|
40
42
|
aliases: aliases ? {...parentScope.aliases, ...aliases} : parentScope.aliases,
|
|
41
43
|
values: values ? {...parentScope.values, ...values} : parentScope.values,
|
|
42
44
|
basePath: basePath ?? parentScope.basePath,
|
|
45
|
+
defaults: defaults ? {...parentScope.defaults, ...defaults} : parentScope.defaults,
|
|
43
46
|
};
|
|
44
|
-
}, [aliases, basePath, parentScope, values]);
|
|
47
|
+
}, [aliases, basePath, defaults, parentScope, values]);
|
|
45
48
|
|
|
46
49
|
return <BlokScopeContext.Provider value={scope}>{children}</BlokScopeContext.Provider>;
|
|
47
50
|
};
|
|
@@ -107,9 +110,34 @@ export const readScopedPath = (
|
|
|
107
110
|
return getValueAtPath(scope.values[head], tail.join('/'));
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
const aliased = head ? scope.aliases[head] : undefined;
|
|
114
|
+
if (aliased !== undefined && scope.defaults && aliased in scope.defaults && getValueAtPath(dataModel, aliased) === undefined) {
|
|
115
|
+
// Nothing written at the alias yet (a local before its first input): it reads its default.
|
|
116
|
+
return getValueAtPath(scope.defaults[aliased], tail.join('/'));
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
return getValueAtPath(dataModel, resolveScopedPath(path, scope));
|
|
111
120
|
};
|
|
112
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Where a write of `path` lands, and what to write first so it lands on the
|
|
124
|
+
* value it was read as: a write below an alias that still reads its default
|
|
125
|
+
* (`bind={p.x}` on a dict local) seeds the default at the alias first.
|
|
126
|
+
*/
|
|
127
|
+
export const scopedWrite = (
|
|
128
|
+
dataModel: unknown,
|
|
129
|
+
path: string,
|
|
130
|
+
scope: BlokScope,
|
|
131
|
+
): {path: string; seed: {path: string; value: unknown} | null} => {
|
|
132
|
+
const [head, ...tail] = splitPathSegments(path);
|
|
133
|
+
const aliased = head ? scope.aliases[head] : undefined;
|
|
134
|
+
const absolute = resolveScopedPath(path, scope);
|
|
135
|
+
if (aliased === undefined || tail.length === 0 || !scope.defaults || !(aliased in scope.defaults)) return {path: absolute, seed: null};
|
|
136
|
+
if (getValueAtPath(dataModel, aliased) !== undefined) return {path: absolute, seed: null};
|
|
137
|
+
const value = scope.defaults[aliased];
|
|
138
|
+
return {path: absolute, seed: value === null || value === undefined ? null : {path: aliased, value: structuredClone(value)}};
|
|
139
|
+
};
|
|
140
|
+
|
|
113
141
|
/** True when a path can be written back through the data model. */
|
|
114
142
|
export const isWritableScopedPath = (path: string, scope: BlokScope): boolean => {
|
|
115
143
|
const [head] = splitPathSegments(path);
|
|
@@ -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
|
+
});
|