@arkitektio/bsx 4.2.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -18
- package/dist/bsx/parse.d.ts +13 -7
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +18 -57
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +22 -35
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +5 -5
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +124 -30
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +1 -1
- package/dist/catalogs/html.d.ts.map +1 -1
- package/dist/catalogs/html.js +3 -3
- package/dist/catalogs/html.js.map +1 -1
- package/dist/catalogs/index.d.ts +209 -139
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +6 -2
- package/dist/catalogs/index.js.map +1 -1
- package/dist/catalogs/logo.d.ts +5 -5
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +3 -3
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +6 -6
- package/dist/catalogs/parts/feedback.d.ts +15 -15
- package/dist/catalogs/parts/forms.d.ts +55 -27
- package/dist/catalogs/parts/forms.d.ts.map +1 -1
- package/dist/catalogs/parts/forms.js +32 -0
- package/dist/catalogs/parts/forms.js.map +1 -1
- package/dist/catalogs/parts/html.d.ts +1 -1
- package/dist/catalogs/parts/html.d.ts.map +1 -1
- package/dist/catalogs/parts/html.js +1 -1
- package/dist/catalogs/parts/html.js.map +1 -1
- package/dist/catalogs/parts/icons.d.ts +11 -11
- package/dist/catalogs/parts/icons.js +1 -1
- package/dist/catalogs/parts/index.d.ts +183 -137
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.d.ts +11 -1
- package/dist/catalogs/parts/layout.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.js +9 -0
- package/dist/catalogs/parts/layout.js.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +8 -8
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +2 -2
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +20 -20
- package/dist/catalogs/parts/overlays.d.ts +55 -55
- package/dist/catalogs/parts/run.d.ts +13 -5
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +1 -1
- package/dist/catalogs/parts/scene.d.ts +12 -4
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +4 -0
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/structure.js +2 -2
- package/dist/catalogs/parts/toast.js +1 -1
- package/dist/catalogs/parts/toast.js.map +1 -1
- package/dist/catalogs/parts/typography.js +1 -1
- package/dist/catalogs/parts/typography.js.map +1 -1
- package/dist/catalogs/props.d.ts +3 -3
- package/dist/catalogs/scene.d.ts +13 -5
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +3 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/catalogs/shadcn.d.ts +106 -58
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +6 -4
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/structure.d.ts +1 -1
- package/dist/catalogs/structure.d.ts.map +1 -1
- package/dist/catalogs/structure.js +3 -3
- package/dist/catalogs/structure.js.map +1 -1
- package/dist/catalogs/ui.d.ts +83 -73
- package/dist/catalogs/ui.d.ts.map +1 -1
- package/dist/catalogs/ui.js +4 -3
- package/dist/catalogs/ui.js.map +1 -1
- package/dist/catalogs.d.ts +1 -1
- package/dist/catalogs.d.ts.map +1 -1
- package/dist/catalogs.js +2 -2
- package/dist/catalogs.js.map +1 -1
- package/dist/ports.js +1 -1
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +4 -1
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +5 -1
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +8 -6
- package/dist/renderer/baseCatalog.d.ts.map +1 -1
- package/dist/renderer/baseCatalog.js +7 -5
- package/dist/renderer/baseCatalog.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +14 -0
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +105 -6
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +6 -6
- package/dist/renderer/bloks/feedback.d.ts +15 -15
- package/dist/renderer/bloks/forms.d.ts +51 -27
- package/dist/renderer/bloks/forms.d.ts.map +1 -1
- package/dist/renderer/bloks/forms.js +56 -0
- package/dist/renderer/bloks/forms.js.map +1 -1
- package/dist/renderer/bloks/html.js +2 -2
- package/dist/renderer/bloks/icons.d.ts +5 -5
- package/dist/renderer/bloks/index.d.ts +166 -134
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/index.js +1 -1
- package/dist/renderer/bloks/layout.d.ts +9 -1
- package/dist/renderer/bloks/layout.d.ts.map +1 -1
- package/dist/renderer/bloks/layout.js +15 -0
- package/dist/renderer/bloks/layout.js.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +5 -5
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +2 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/navigation.d.ts +20 -20
- package/dist/renderer/bloks/overlays.d.ts +55 -55
- package/dist/renderer/bloks/run/components.d.ts +6 -2
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +1 -1
- package/dist/renderer/bloks/run/host.d.ts +32 -3
- package/dist/renderer/bloks/run/host.d.ts.map +1 -1
- package/dist/renderer/bloks/run/host.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +6 -2
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/toast.d.ts +1 -1
- package/dist/renderer/bloks/typography.js +1 -1
- package/dist/renderer/catalog.d.ts +4 -7
- package/dist/renderer/catalog.d.ts.map +1 -1
- package/dist/renderer/catalog.js +7 -31
- package/dist/renderer/catalog.js.map +1 -1
- package/dist/renderer/declare.d.ts +31 -19
- package/dist/renderer/declare.d.ts.map +1 -1
- package/dist/renderer/declare.js +44 -18
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/functions/v2/index.d.ts.map +1 -1
- package/dist/renderer/functions/v2/index.js +39 -0
- package/dist/renderer/functions/v2/index.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +27 -7
- package/dist/renderer/runtime/catalog.d.ts.map +1 -1
- package/dist/renderer/runtime/catalog.js +30 -3
- package/dist/renderer/runtime/catalog.js.map +1 -1
- package/dist/renderer/runtime/components.d.ts +7 -1
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +3 -0
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +2 -0
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +4 -0
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +14 -4
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +3 -0
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +1 -0
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +1 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +1 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/preflight.d.ts.map +1 -1
- package/dist/renderer/runtime/preflight.js +5 -2
- package/dist/renderer/runtime/preflight.js.map +1 -1
- package/dist/renderer/runtime/resolution.d.ts +2 -0
- package/dist/renderer/runtime/resolution.d.ts.map +1 -1
- package/dist/renderer/runtime/resolution.js +17 -1
- package/dist/renderer/runtime/resolution.js.map +1 -1
- package/dist/renderer/runtime/schemas.d.ts +5 -5
- package/dist/renderer/runtime/task.d.ts +25 -2
- package/dist/renderer/runtime/task.d.ts.map +1 -1
- package/dist/renderer/runtime/task.js +11 -2
- package/dist/renderer/runtime/task.js.map +1 -1
- package/dist/renderer/runtime/text.d.ts +28 -0
- package/dist/renderer/runtime/text.d.ts.map +1 -0
- package/dist/renderer/runtime/text.js +82 -0
- package/dist/renderer/runtime/text.js.map +1 -0
- package/dist/renderer/runtime/types.d.ts +7 -2
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/scene.d.ts +1 -1
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +2 -2
- package/dist/scene.js.map +1 -1
- package/dist/shadcn.d.ts +169 -137
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +8 -5
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +3080 -2372
- package/dist/spec/catalogs/base@3.json +13029 -0
- package/dist/spec/catalogs/base@3.json.js +13029 -0
- package/dist/spec/catalogs/orkestrator@1.json +489 -0
- package/dist/spec/catalogs/orkestrator@1.json.js +489 -0
- package/dist/spec/catalogs.d.ts +109 -46
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +241 -73
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +21 -3
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +16 -2
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +73 -27
- package/dist/spec/vocabulary.json.js +73 -27
- package/dist/vendor/core/ui/button-group.d.ts +1 -1
- package/dist/vendor/core/ui/button.d.ts +1 -1
- package/dist/vendor/core/ui/field.d.ts +1 -1
- package/package.json +1 -1
- package/src/bsx/infer.test.ts +18 -26
- package/src/bsx/language.test.ts +2 -2
- package/src/bsx/parse.ts +18 -62
- package/src/bsx/partial.test.ts +1 -1
- package/src/bsx/print.ts +24 -34
- package/src/bsx/references.test.ts +71 -10
- package/src/bsx/references.ts +114 -35
- package/src/catalogs/catalogs.test.ts +45 -14
- package/src/catalogs/html.ts +3 -3
- package/src/catalogs/index.ts +6 -2
- package/src/catalogs/logo.ts +3 -3
- package/src/catalogs/parts/forms.ts +32 -0
- package/src/catalogs/parts/html.ts +1 -1
- package/src/catalogs/parts/icons.ts +1 -1
- package/src/catalogs/parts/layout.ts +11 -0
- package/src/catalogs/parts/logo.ts +2 -2
- package/src/catalogs/parts/run.ts +1 -1
- package/src/catalogs/parts/scene.ts +6 -0
- package/src/catalogs/parts/structure.ts +2 -2
- package/src/catalogs/parts/toast.ts +1 -1
- package/src/catalogs/parts/typography.ts +1 -1
- package/src/catalogs/scene.ts +3 -3
- package/src/catalogs/shadcn.ts +6 -4
- package/src/catalogs/structure.ts +3 -3
- package/src/catalogs/ui.ts +4 -3
- package/src/catalogs.ts +9 -2
- package/src/ports.ts +1 -1
- package/src/renderer/BlokRenderer.tsx +9 -0
- package/src/renderer/addBlokComponents.test.tsx +8 -22
- package/src/renderer/baseCatalog.ts +7 -5
- package/src/renderer/bloks/components.test.tsx +2 -2
- package/src/renderer/bloks/control.tsx +133 -6
- package/src/renderer/bloks/flow.test.tsx +1 -1
- package/src/renderer/bloks/forms.tsx +126 -0
- package/src/renderer/bloks/html.tsx +2 -2
- package/src/renderer/bloks/index.ts +1 -1
- package/src/renderer/bloks/layout.tsx +28 -0
- package/src/renderer/bloks/logo/index.tsx +2 -2
- package/src/renderer/bloks/run/components.tsx +1 -1
- package/src/renderer/bloks/run/host.tsx +33 -3
- package/src/renderer/bloks/run/space.test.tsx +76 -0
- package/src/renderer/bloks/time.test.tsx +1 -1
- package/src/renderer/bloks/toast.tsx +1 -1
- package/src/renderer/bloks/typography.tsx +1 -1
- package/src/renderer/catalog.tsx +7 -31
- package/src/renderer/declare.test.ts +41 -0
- package/src/renderer/declare.ts +70 -32
- package/src/renderer/functions/v2/functions.test.ts +40 -1
- package/src/renderer/functions/v2/index.ts +47 -0
- package/src/renderer/runtime/catalog.ts +35 -10
- package/src/renderer/runtime/components.tsx +10 -1
- package/src/renderer/runtime/context.tsx +6 -0
- package/src/renderer/runtime/describe.ts +17 -4
- package/src/renderer/runtime/hooks.ts +1 -0
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/preflight.ts +5 -2
- package/src/renderer/runtime/resolution.test.ts +14 -0
- package/src/renderer/runtime/resolution.ts +15 -1
- package/src/renderer/runtime/task.ts +33 -4
- package/src/renderer/runtime/text.test.tsx +65 -0
- package/src/renderer/runtime/text.ts +88 -0
- package/src/renderer/runtime/types.ts +7 -2
- package/src/runtime.ts +0 -1
- package/src/scene.ts +2 -2
- package/src/shadcn.ts +8 -5
- package/src/spec/bsx_v2.json +3080 -2372
- package/src/spec/catalogs/base@3.json +13029 -0
- package/src/spec/catalogs/orkestrator@1.json +489 -0
- package/src/spec/catalogs.ts +257 -101
- package/src/spec/spec.test.ts +107 -21
- package/src/spec/vocabulary.json +73 -27
- package/src/spec/vocabulary.ts +36 -7
- package/dist/renderer/modules.d.ts +0 -4
- package/dist/renderer/modules.d.ts.map +0 -1
- package/dist/renderer/modules.js +0 -11
- package/dist/renderer/modules.js.map +0 -1
- package/dist/spec/catalogs/base@2.json +0 -222
- package/dist/spec/catalogs/base@2.json.js +0 -222
- package/dist/spec/catalogs/html@1.json +0 -308
- package/dist/spec/catalogs/html@1.json.js +0 -308
- package/dist/spec/catalogs/logo@1.json +0 -1687
- package/dist/spec/catalogs/logo@1.json.js +0 -1687
- package/dist/spec/catalogs/scene@1.json +0 -858
- package/dist/spec/catalogs/scene@1.json.js +0 -858
- package/dist/spec/catalogs/shadcn@1.json +0 -3860
- package/dist/spec/catalogs/shadcn@1.json.js +0 -3860
- package/dist/spec/catalogs/structure@1.json +0 -185
- package/dist/spec/catalogs/structure@1.json.js +0 -185
- package/dist/spec/catalogs/ui@1.json +0 -5349
- package/dist/spec/catalogs/ui@1.json.js +0 -5349
- package/src/renderer/modules.ts +0 -12
- package/src/spec/catalogs/base@2.json +0 -222
- package/src/spec/catalogs/html@1.json +0 -308
- package/src/spec/catalogs/logo@1.json +0 -1687
- package/src/spec/catalogs/scene@1.json +0 -858
- package/src/spec/catalogs/shadcn@1.json +0 -3860
- package/src/spec/catalogs/structure@1.json +0 -185
- package/src/spec/catalogs/ui@1.json +0 -5349
package/dist/spec/catalogs.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import { type BlokContextName, type VocabFunction } from './vocabulary';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
3
|
+
* The catalogs a blok is drawn with, in the spec's terms: the port of
|
|
4
|
+
* arkitekt-spec's `blok/catalogs`.
|
|
5
|
+
*
|
|
6
|
+
* A *catalog* is a versioned set of components, named by the address it is
|
|
7
|
+
* published at (its `id`).
|
|
8
|
+
*
|
|
9
|
+
* - The **base catalog** (`catalogs/base@3.json`,
|
|
10
|
+
* `https://arkitekt.live/catalogs/base/v3`): everything every renderer draws.
|
|
11
|
+
* The language's own elements, the html components, the structure and run
|
|
12
|
+
* parts a host supplies, the scene and the logo shapes. The spec owns it; this
|
|
13
|
+
* package's contracts (`catalogs/`) are held to it by a test.
|
|
14
|
+
* - An **app catalog** extends another (in the end the base) with what one
|
|
15
|
+
* frontend draws beyond it. A snapshot of the Orkestrator's ships
|
|
16
|
+
* (`catalogs/orkestrator@1.json`); any other is registered by the app that
|
|
17
|
+
* draws it (`registerBlokCatalog`).
|
|
18
|
+
*
|
|
19
|
+
* A blok names the one catalog it is written for; the base when it names none.
|
|
20
|
+
* A catalog only ever adds to what it extends.
|
|
10
21
|
*/
|
|
11
22
|
export declare const BASE_NAME = "base";
|
|
12
|
-
|
|
13
|
-
export
|
|
23
|
+
/** The family of the language's own elements (control flow, async boundaries, the context roots, text). */
|
|
24
|
+
export declare const LANGUAGE_GROUP = "language";
|
|
25
|
+
/** The Orkestrator's catalog: what it draws beyond the base. */
|
|
26
|
+
export declare const ORKESTRATOR_CATALOG_ID = "https://arkitekt.live/catalogs/orkestrator/v1";
|
|
14
27
|
export type SpecEventField = {
|
|
15
28
|
key: string;
|
|
16
29
|
kind: string;
|
|
@@ -26,6 +39,8 @@ export type SpecProp = {
|
|
|
26
39
|
event: readonly SpecEventField[] | null;
|
|
27
40
|
/** For a `STRING`, the closed set of literals the component draws; null: any string. */
|
|
28
41
|
values: readonly string[] | null;
|
|
42
|
+
/** The minor of its catalog that added the prop; 0: there from the start. */
|
|
43
|
+
since: number;
|
|
29
44
|
};
|
|
30
45
|
export type SpecComponent = {
|
|
31
46
|
name: string;
|
|
@@ -36,10 +51,20 @@ export type SpecComponent = {
|
|
|
36
51
|
acceptsChildren: boolean;
|
|
37
52
|
downstreamOf: readonly string[];
|
|
38
53
|
notDownstreamOf: readonly string[];
|
|
39
|
-
/** The prop text children fill (`<Button>Grip</Button>`
|
|
54
|
+
/** The prop its text children fill when it draws them (`<Button>Grip</Button>` is its `label`); null: it has none. */
|
|
40
55
|
textProp: string | null;
|
|
41
56
|
props: readonly SpecProp[];
|
|
42
|
-
/** The
|
|
57
|
+
/** The blok kinds it may be placed in (`assign`); empty: any kind. */
|
|
58
|
+
kinds: readonly string[];
|
|
59
|
+
/** The service it needs where it is drawn (`mikro`); null: none beyond the host's own. */
|
|
60
|
+
service: string | null;
|
|
61
|
+
/** The minor of its catalog that added it; 0: there from the start. */
|
|
62
|
+
since: number;
|
|
63
|
+
/** The family it is listed under (`language`, `ui`, `html`, `run`, `scene`, `logo`). */
|
|
64
|
+
group: string | null;
|
|
65
|
+
/** How it is drawn where there is no pointer, when that differs. */
|
|
66
|
+
touch: string | null;
|
|
67
|
+
/** The catalog it is from, `name@version` (`base@3`), or the bare name of one nothing published. */
|
|
43
68
|
catalog: string;
|
|
44
69
|
};
|
|
45
70
|
export type SpecCatalog = {
|
|
@@ -47,57 +72,95 @@ export type SpecCatalog = {
|
|
|
47
72
|
version: number | null;
|
|
48
73
|
description: string | null;
|
|
49
74
|
components: readonly SpecComponent[];
|
|
75
|
+
/** What a blok names it by: the address it is published at. Null for a catalog nothing targets. */
|
|
76
|
+
id: string | null;
|
|
77
|
+
/** How far it has grown within its version. */
|
|
78
|
+
minor: number;
|
|
79
|
+
/** The id of the catalog it adds to; null for the base catalog, and for one that adds to the base without saying so. */
|
|
80
|
+
extends: string | null;
|
|
50
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* A catalog file (`{id, name, version, minor, extends, components}`) as a
|
|
84
|
+
* `SpecCatalog`. Only data is read, field by field; nothing is ever executed.
|
|
85
|
+
*/
|
|
51
86
|
export declare const parseSpecCatalog: (raw: unknown, file: string) => SpecCatalog;
|
|
52
|
-
|
|
87
|
+
export declare const catalogLabel: (catalog: SpecCatalog) => string;
|
|
88
|
+
/** The base catalog: what every renderer draws. */
|
|
53
89
|
export declare const baseCatalog: () => SpecCatalog;
|
|
54
|
-
/**
|
|
55
|
-
export declare const
|
|
56
|
-
export declare const standardCatalogs: () => SpecCatalog[];
|
|
90
|
+
/** The Orkestrator's catalog, as the snapshot this package ships. */
|
|
91
|
+
export declare const orkestratorCatalog: () => SpecCatalog;
|
|
57
92
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
93
|
+
* The catalog called `id`: one an app registered, or one that ships; undefined
|
|
94
|
+
* when unknown. What an app registers under the id of a shipped snapshot is
|
|
95
|
+
* that catalog here (the app that draws it knows it best); the base catalog
|
|
96
|
+
* is never replaced.
|
|
62
97
|
*/
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
export declare const knownCatalog: (id: string) => SpecCatalog | undefined;
|
|
99
|
+
/** Every catalog known here: those that ship (the base first; a registered one in its snapshot's place), then those registered. */
|
|
100
|
+
export declare const knownCatalogs: () => SpecCatalog[];
|
|
101
|
+
/** Two definitions of a component are the same when everything but where they come from is. */
|
|
102
|
+
export declare const sameComponent: (a: SpecComponent, b: SpecComponent) => boolean;
|
|
103
|
+
/**
|
|
104
|
+
* The catalogs a blok written for `target` is drawn with, the base first.
|
|
105
|
+
* `target` is a catalog's id, a catalog (one nothing published: it extends the
|
|
106
|
+
* base unless it says otherwise), or null for the base alone. Throws when the
|
|
107
|
+
* target or a catalog it extends is not known, or a catalog redefines a
|
|
108
|
+
* component of one it extends.
|
|
109
|
+
*/
|
|
110
|
+
export declare const catalogChain: (target?: string | SpecCatalog | null) => SpecCatalog[];
|
|
111
|
+
/** What a blok is drawn with: the components of the catalog it is written for, and of those that one extends, down to the base. */
|
|
73
112
|
export type BlokView = {
|
|
74
113
|
components: ReadonlyMap<string, SpecComponent>;
|
|
75
114
|
functions: ReadonlyMap<string, VocabFunction>;
|
|
76
115
|
label: string;
|
|
77
|
-
/** Whether the components are every one the
|
|
116
|
+
/** Whether the components are every one the target draws, so an unknown one is a finding. */
|
|
78
117
|
complete: boolean;
|
|
79
|
-
/** The
|
|
80
|
-
|
|
118
|
+
/** The id of the catalog the view is of; null for one nothing published. */
|
|
119
|
+
target: string | null;
|
|
120
|
+
/** Per component of a known catalog the view is NOT of, that catalog's id (`catalog.target`). */
|
|
121
|
+
foreign: ReadonlyMap<string, string>;
|
|
81
122
|
};
|
|
82
|
-
/**
|
|
83
|
-
export declare const
|
|
84
|
-
/**
|
|
85
|
-
* The view base, the standard catalogs and `extra` ones (modules: the
|
|
86
|
-
* Orkestrator's, an app's) give; the port of the spec's `blok_view`.
|
|
87
|
-
*/
|
|
88
|
-
export declare const blokView: (extra?: readonly SpecCatalog[], options?: {
|
|
89
|
-
standard?: boolean;
|
|
123
|
+
/** The view of a blok written for `target` (see `catalogChain`); the base's when null. */
|
|
124
|
+
export declare const blokView: (target?: string | SpecCatalog | null, options?: {
|
|
90
125
|
complete?: boolean;
|
|
91
126
|
}) => BlokView;
|
|
127
|
+
/** The view of a blok that names no catalog: the base catalog's. */
|
|
128
|
+
export declare const baseBlokView: () => BlokView;
|
|
129
|
+
/**
|
|
130
|
+
* Make a catalog known here, so a blok written for it is checked against it:
|
|
131
|
+
* what an app does with the catalog of what it draws beyond the base
|
|
132
|
+
* (`blokCatalogSpec` of its own contracts). Registered under the id of a
|
|
133
|
+
* snapshot that ships, it stands in its place; the base catalog is never
|
|
134
|
+
* replaced. Throws when it redefines a component of what it extends.
|
|
135
|
+
*/
|
|
136
|
+
export declare const registerBlokCatalog: (catalog: SpecCatalog) => void;
|
|
137
|
+
/** Forget every catalog `registerBlokCatalog` was handed, and the app's own view (for tests). */
|
|
138
|
+
export declare const forgetBlokCatalogs: () => void;
|
|
92
139
|
/**
|
|
93
|
-
* The app
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
140
|
+
* The catalog this app draws: the one its own editor, checks and renderer
|
|
141
|
+
* read a blok against when the blok names none of its own. An app that draws
|
|
142
|
+
* only the base leaves it unset. Call it once at start, beside
|
|
143
|
+
* `configureBlokPlatform`.
|
|
97
144
|
*/
|
|
98
|
-
export declare const
|
|
99
|
-
/** The app's view:
|
|
145
|
+
export declare const setAppBlokCatalog: (target: string | SpecCatalog | null) => void;
|
|
146
|
+
/** The app's own view: everything it draws (`setAppBlokCatalog`), the base catalog's when it set none. */
|
|
100
147
|
export declare const defaultBlokView: () => BlokView;
|
|
148
|
+
/**
|
|
149
|
+
* The view a blok that names `catalog` is read against: that catalog's when it
|
|
150
|
+
* is known here, the app's own when the blok names none, and the base's,
|
|
151
|
+
* incomplete (nothing is reported unknown), for a catalog nobody here knows.
|
|
152
|
+
*/
|
|
153
|
+
export declare const blokViewFor: (catalog: string | null | undefined) => BlokView;
|
|
154
|
+
/** Whether `target` can name a catalog at all: a published one's address, or the name of one registered in an organization. */
|
|
155
|
+
export declare const isCatalogTarget: (target: string) => boolean;
|
|
156
|
+
/** The minor of the catalog the view is of that `tree` needs: the newest `since` among the components and props of that catalog it uses. */
|
|
157
|
+
export declare const minorNeeded: (tree: {
|
|
158
|
+
component: string;
|
|
159
|
+
props?: ReadonlyArray<{
|
|
160
|
+
key: string;
|
|
161
|
+
}> | null;
|
|
162
|
+
children?: readonly unknown[] | null;
|
|
163
|
+
}, view: BlokView) => number;
|
|
101
164
|
/** Whether a component is a language one that holds others in whatever context (`if`, `foreach`, `fragment`). */
|
|
102
165
|
export declare const isLanguageContainer: (component: SpecComponent | undefined) => boolean;
|
|
103
166
|
/** The context a component's children are in, given the one it sits in. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalogs.d.ts","sourceRoot":"","sources":["../../src/spec/catalogs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"catalogs.d.ts","sourceRoot":"","sources":["../../src/spec/catalogs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,eAAe,EAAE,KAAK,aAAa,EAAC,MAAM,cAAc,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,SAAS,SAAS,CAAC;AAChC,2GAA2G;AAC3G,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,gEAAgE;AAChE,eAAO,MAAM,sBAAsB,kDAAkD,CAAC;AAEtF,MAAM,MAAM,cAAc,GAAG;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI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AAI,WAAW,aAAa,GAAG,SAAS,EAAE,SAAS,eAAe,KAAG,eAG7F,CAAC"}
|
package/dist/spec/catalogs.js
CHANGED
|
@@ -1,31 +1,53 @@
|
|
|
1
|
-
import baseCatalogJson from './catalogs/base@
|
|
2
|
-
import
|
|
3
|
-
import logoCatalogJson from './catalogs/logo@1.json.js';
|
|
4
|
-
import sceneCatalogJson from './catalogs/scene@1.json.js';
|
|
5
|
-
import structureCatalogJson from './catalogs/structure@1.json.js';
|
|
6
|
-
import shadcnCatalogJson from './catalogs/shadcn@1.json.js';
|
|
7
|
-
import uiCatalogJson from './catalogs/ui@1.json.js';
|
|
1
|
+
import baseCatalogJson from './catalogs/base@3.json.js';
|
|
2
|
+
import orkestratorCatalogJson from './catalogs/orkestrator@1.json.js';
|
|
8
3
|
import { loadVocabulary } from './vocabulary.js';
|
|
9
4
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
5
|
+
* The catalogs a blok is drawn with, in the spec's terms: the port of
|
|
6
|
+
* arkitekt-spec's `blok/catalogs`.
|
|
7
|
+
*
|
|
8
|
+
* A *catalog* is a versioned set of components, named by the address it is
|
|
9
|
+
* published at (its `id`).
|
|
10
|
+
*
|
|
11
|
+
* - The **base catalog** (`catalogs/base@3.json`,
|
|
12
|
+
* `https://arkitekt.live/catalogs/base/v3`): everything every renderer draws.
|
|
13
|
+
* The language's own elements, the html components, the structure and run
|
|
14
|
+
* parts a host supplies, the scene and the logo shapes. The spec owns it; this
|
|
15
|
+
* package's contracts (`catalogs/`) are held to it by a test.
|
|
16
|
+
* - An **app catalog** extends another (in the end the base) with what one
|
|
17
|
+
* frontend draws beyond it. A snapshot of the Orkestrator's ships
|
|
18
|
+
* (`catalogs/orkestrator@1.json`); any other is registered by the app that
|
|
19
|
+
* draws it (`registerBlokCatalog`).
|
|
20
|
+
*
|
|
21
|
+
* A blok names the one catalog it is written for; the base when it names none.
|
|
22
|
+
* A catalog only ever adds to what it extends.
|
|
17
23
|
*/
|
|
18
24
|
export const BASE_NAME = 'base';
|
|
19
|
-
|
|
25
|
+
/** The family of the language's own elements (control flow, async boundaries, the context roots, text). */
|
|
26
|
+
export const LANGUAGE_GROUP = 'language';
|
|
27
|
+
/** The Orkestrator's catalog: what it draws beyond the base. */
|
|
28
|
+
export const ORKESTRATOR_CATALOG_ID = 'https://arkitekt.live/catalogs/orkestrator/v1';
|
|
20
29
|
const isRaw = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
21
30
|
const rawList = (value) => (Array.isArray(value) ? value : []);
|
|
22
31
|
const text = (value) => (typeof value === 'string' ? value : null);
|
|
23
32
|
const texts = (value) => rawList(value).filter((item) => typeof item === 'string');
|
|
33
|
+
const count = (value) => (typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : 0);
|
|
24
34
|
const contextOf = (value) => value === 'HTML' || value === 'SCENE' || value === 'LOGO' ? value : null;
|
|
35
|
+
/**
|
|
36
|
+
* A catalog file (`{id, name, version, minor, extends, components}`) as a
|
|
37
|
+
* `SpecCatalog`. Only data is read, field by field; nothing is ever executed.
|
|
38
|
+
*/
|
|
25
39
|
export const parseSpecCatalog = (raw, file) => {
|
|
26
40
|
if (!isRaw(raw) || typeof raw.name !== 'string')
|
|
27
41
|
throw new Error(`${file} is not a catalog`);
|
|
42
|
+
const vocabulary = loadVocabulary();
|
|
28
43
|
const version = typeof raw.version === 'number' ? raw.version : null;
|
|
44
|
+
const address = (value, what) => {
|
|
45
|
+
if (value === undefined || value === null)
|
|
46
|
+
return null;
|
|
47
|
+
if (typeof value !== 'string' || !vocabulary.catalogId.test(value))
|
|
48
|
+
throw new Error(`${file} has an ${what} that is not the address of a catalog`);
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
29
51
|
const catalog = version === null ? raw.name : `${raw.name}@${version}`;
|
|
30
52
|
const components = rawList(raw.components).filter(isRaw).map((entry) => ({
|
|
31
53
|
name: String(entry.name),
|
|
@@ -46,90 +68,236 @@ export const parseSpecCatalog = (raw, file) => {
|
|
|
46
68
|
? prop.event.filter(isRaw).map(field => ({ key: String(field.key), kind: String(field.kind), description: text(field.description) }))
|
|
47
69
|
: null,
|
|
48
70
|
values: Array.isArray(prop.values) ? prop.values.map(String) : null,
|
|
71
|
+
since: count(prop.since),
|
|
49
72
|
})),
|
|
73
|
+
kinds: texts(entry.kinds),
|
|
74
|
+
service: text(entry.service) || null,
|
|
75
|
+
since: count(entry.since),
|
|
76
|
+
group: text(entry.group) || null,
|
|
77
|
+
touch: text(entry.touch) || null,
|
|
50
78
|
catalog,
|
|
51
79
|
}));
|
|
52
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
name: raw.name,
|
|
82
|
+
version,
|
|
83
|
+
description: text(raw.description),
|
|
84
|
+
components,
|
|
85
|
+
id: address(raw.id, 'id'),
|
|
86
|
+
minor: count(raw.minor),
|
|
87
|
+
extends: address(raw.extends, 'extends'),
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export const catalogLabel = (catalog) => (catalog.version === null ? catalog.name : `${catalog.name}@${catalog.version}`);
|
|
91
|
+
const BUNDLED = {
|
|
92
|
+
'catalogs/base@3.json': baseCatalogJson,
|
|
93
|
+
'catalogs/orkestrator@1.json': orkestratorCatalogJson,
|
|
53
94
|
};
|
|
54
|
-
let
|
|
55
|
-
const
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
95
|
+
let bundled = null;
|
|
96
|
+
const bundledCatalogs = () => {
|
|
97
|
+
if (!bundled) {
|
|
98
|
+
bundled = new Map();
|
|
99
|
+
for (const [id, file] of Object.entries(loadVocabulary().bundledCatalogs)) {
|
|
100
|
+
const raw = BUNDLED[file];
|
|
101
|
+
if (raw === undefined)
|
|
102
|
+
throw new Error(`${file} does not ship with this package`);
|
|
103
|
+
const catalog = parseSpecCatalog(raw, file);
|
|
104
|
+
if (catalog.id !== id)
|
|
105
|
+
throw new Error(`${file} is ${catalog.id}, not ${id}`);
|
|
106
|
+
bundled.set(id, catalog);
|
|
107
|
+
}
|
|
68
108
|
}
|
|
69
|
-
return
|
|
109
|
+
return bundled;
|
|
70
110
|
};
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
/**
|
|
111
|
+
/** Catalogs an app handed over (`registerBlokCatalog`), by id. */
|
|
112
|
+
const registered = new Map();
|
|
113
|
+
let defaultTarget = null;
|
|
114
|
+
let defaultView = null;
|
|
115
|
+
/** The base catalog: what every renderer draws. */
|
|
116
|
+
export const baseCatalog = () => bundledCatalogs().get(loadVocabulary().baseCatalog);
|
|
117
|
+
/** The Orkestrator's catalog, as the snapshot this package ships. */
|
|
118
|
+
export const orkestratorCatalog = () => bundledCatalogs().get(ORKESTRATOR_CATALOG_ID);
|
|
119
|
+
/**
|
|
120
|
+
* The catalog called `id`: one an app registered, or one that ships; undefined
|
|
121
|
+
* when unknown. What an app registers under the id of a shipped snapshot is
|
|
122
|
+
* that catalog here (the app that draws it knows it best); the base catalog
|
|
123
|
+
* is never replaced.
|
|
124
|
+
*/
|
|
125
|
+
export const knownCatalog = (id) => registered.get(id) ?? bundledCatalogs().get(id);
|
|
126
|
+
/** Every catalog known here: those that ship (the base first; a registered one in its snapshot's place), then those registered. */
|
|
127
|
+
export const knownCatalogs = () => [
|
|
128
|
+
...[...bundledCatalogs().values()].map(catalog => (catalog.id !== null ? registered.get(catalog.id) : undefined) ?? catalog),
|
|
129
|
+
...[...registered.values()].filter(catalog => catalog.id === null || !bundledCatalogs().has(catalog.id)),
|
|
130
|
+
];
|
|
131
|
+
/** Two definitions of a component are the same when everything but where they come from is. */
|
|
78
132
|
export const sameComponent = (a, b) => {
|
|
79
|
-
const
|
|
80
|
-
return
|
|
133
|
+
const comparable = (component) => JSON.stringify(component, (key, value) => (key === 'catalog' || key === 'group' || key === 'touch' ? undefined : value));
|
|
134
|
+
return comparable(a) === comparable(b);
|
|
81
135
|
};
|
|
82
136
|
/**
|
|
83
|
-
* The
|
|
84
|
-
*
|
|
137
|
+
* The catalogs a blok written for `target` is drawn with, the base first.
|
|
138
|
+
* `target` is a catalog's id, a catalog (one nothing published: it extends the
|
|
139
|
+
* base unless it says otherwise), or null for the base alone. Throws when the
|
|
140
|
+
* target or a catalog it extends is not known, or a catalog redefines a
|
|
141
|
+
* component of one it extends.
|
|
85
142
|
*/
|
|
86
|
-
export const
|
|
143
|
+
export const catalogChain = (target = null) => {
|
|
87
144
|
const base = baseCatalog();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
145
|
+
let current;
|
|
146
|
+
if (target === null)
|
|
147
|
+
current = base;
|
|
148
|
+
else if (typeof target === 'string') {
|
|
149
|
+
const named = knownCatalog(target);
|
|
150
|
+
if (!named)
|
|
151
|
+
throw new Error(`the catalog '${target}' is not known here`);
|
|
152
|
+
current = named;
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
current = target;
|
|
156
|
+
const chain = [];
|
|
157
|
+
const seen = new Set();
|
|
158
|
+
while (current !== base && current.id !== base.id) {
|
|
159
|
+
if (current.id !== null) {
|
|
160
|
+
if (seen.has(current.id))
|
|
161
|
+
throw new Error(`the catalog '${current.id}' extends itself`);
|
|
162
|
+
seen.add(current.id);
|
|
163
|
+
}
|
|
164
|
+
chain.push(current);
|
|
165
|
+
if (current.extends === null)
|
|
166
|
+
break;
|
|
167
|
+
const parent = knownCatalog(current.extends);
|
|
168
|
+
if (!parent)
|
|
169
|
+
throw new Error(`the catalog ${catalogLabel(current)} extends '${current.extends}', which is not known here`);
|
|
170
|
+
current = parent;
|
|
171
|
+
}
|
|
172
|
+
const ordered = [base, ...chain.reverse()];
|
|
173
|
+
const owner = new Map();
|
|
174
|
+
for (const catalog of ordered) {
|
|
94
175
|
for (const component of catalog.components) {
|
|
95
|
-
const previous =
|
|
96
|
-
if (!previous) {
|
|
97
|
-
|
|
98
|
-
continue;
|
|
176
|
+
const previous = owner.get(component.name);
|
|
177
|
+
if (previous && !sameComponent(previous[0], component)) {
|
|
178
|
+
throw new Error(`the catalog ${catalogLabel(catalog)} redefines <${component.name}> of ${previous[1]}: a catalog only adds`);
|
|
99
179
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
180
|
+
if (!previous)
|
|
181
|
+
owner.set(component.name, [component, catalogLabel(catalog)]);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return ordered;
|
|
185
|
+
};
|
|
186
|
+
/** The view of a blok written for `target` (see `catalogChain`); the base's when null. */
|
|
187
|
+
export const blokView = (target = null, options = {}) => {
|
|
188
|
+
const chain = catalogChain(target);
|
|
189
|
+
const components = new Map();
|
|
190
|
+
for (const catalog of chain) {
|
|
191
|
+
for (const component of catalog.components)
|
|
192
|
+
if (!components.has(component.name))
|
|
106
193
|
components.set(component.name, component);
|
|
107
|
-
|
|
194
|
+
}
|
|
195
|
+
const foreign = new Map();
|
|
196
|
+
for (const catalog of knownCatalogs()) {
|
|
197
|
+
if (chain.includes(catalog) || catalog.id === null)
|
|
198
|
+
continue;
|
|
199
|
+
for (const component of catalog.components) {
|
|
200
|
+
if (!components.has(component.name) && !foreign.has(component.name))
|
|
201
|
+
foreign.set(component.name, catalog.id);
|
|
108
202
|
}
|
|
109
203
|
}
|
|
110
|
-
|
|
111
|
-
|
|
204
|
+
return {
|
|
205
|
+
components,
|
|
206
|
+
functions: loadVocabulary().functions,
|
|
207
|
+
label: chain.map(catalogLabel).join(' + '),
|
|
208
|
+
complete: options.complete ?? true,
|
|
209
|
+
target: chain[chain.length - 1].id,
|
|
210
|
+
foreign,
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
/** The view of a blok that names no catalog: the base catalog's. */
|
|
214
|
+
export const baseBlokView = () => blokView();
|
|
215
|
+
/**
|
|
216
|
+
* Make a catalog known here, so a blok written for it is checked against it:
|
|
217
|
+
* what an app does with the catalog of what it draws beyond the base
|
|
218
|
+
* (`blokCatalogSpec` of its own contracts). Registered under the id of a
|
|
219
|
+
* snapshot that ships, it stands in its place; the base catalog is never
|
|
220
|
+
* replaced. Throws when it redefines a component of what it extends.
|
|
221
|
+
*/
|
|
222
|
+
export const registerBlokCatalog = (catalog) => {
|
|
223
|
+
if (catalog.id === null)
|
|
224
|
+
throw new Error(`the catalog '${catalog.name}' has no id to be known by`);
|
|
225
|
+
if (catalog.id === loadVocabulary().baseCatalog)
|
|
226
|
+
return;
|
|
227
|
+
const previous = registered.get(catalog.id);
|
|
228
|
+
registered.set(catalog.id, catalog);
|
|
229
|
+
defaultView = null;
|
|
230
|
+
try {
|
|
231
|
+
catalogChain(catalog.id);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (previous)
|
|
235
|
+
registered.set(catalog.id, previous);
|
|
236
|
+
else
|
|
237
|
+
registered.delete(catalog.id);
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
/** Forget every catalog `registerBlokCatalog` was handed, and the app's own view (for tests). */
|
|
242
|
+
export const forgetBlokCatalogs = () => {
|
|
243
|
+
registered.clear();
|
|
244
|
+
defaultTarget = null;
|
|
245
|
+
defaultView = null;
|
|
112
246
|
};
|
|
113
|
-
let defaultView = null;
|
|
114
|
-
let defaultModules = [];
|
|
115
247
|
/**
|
|
116
|
-
* The app
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
248
|
+
* The catalog this app draws: the one its own editor, checks and renderer
|
|
249
|
+
* read a blok against when the blok names none of its own. An app that draws
|
|
250
|
+
* only the base leaves it unset. Call it once at start, beside
|
|
251
|
+
* `configureBlokPlatform`.
|
|
120
252
|
*/
|
|
121
|
-
export const
|
|
122
|
-
|
|
253
|
+
export const setAppBlokCatalog = (target) => {
|
|
254
|
+
if (target !== null && typeof target !== 'string' && target.id !== null)
|
|
255
|
+
registerBlokCatalog(target);
|
|
256
|
+
defaultTarget = target !== null && typeof target !== 'string' && target.id !== null ? target.id : target;
|
|
123
257
|
defaultView = null;
|
|
124
258
|
};
|
|
125
|
-
/** The app's view:
|
|
259
|
+
/** The app's own view: everything it draws (`setAppBlokCatalog`), the base catalog's when it set none. */
|
|
126
260
|
export const defaultBlokView = () => {
|
|
127
261
|
if (!defaultView)
|
|
128
|
-
defaultView = blokView(
|
|
262
|
+
defaultView = blokView(defaultTarget);
|
|
129
263
|
return defaultView;
|
|
130
264
|
};
|
|
265
|
+
/**
|
|
266
|
+
* The view a blok that names `catalog` is read against: that catalog's when it
|
|
267
|
+
* is known here, the app's own when the blok names none, and the base's,
|
|
268
|
+
* incomplete (nothing is reported unknown), for a catalog nobody here knows.
|
|
269
|
+
*/
|
|
270
|
+
export const blokViewFor = (catalog) => {
|
|
271
|
+
if (catalog === null || catalog === undefined)
|
|
272
|
+
return baseBlokView();
|
|
273
|
+
if (knownCatalog(catalog))
|
|
274
|
+
return blokView(catalog);
|
|
275
|
+
return blokView(null, { complete: false });
|
|
276
|
+
};
|
|
277
|
+
/** Whether `target` can name a catalog at all: a published one's address, or the name of one registered in an organization. */
|
|
278
|
+
export const isCatalogTarget = (target) => {
|
|
279
|
+
const vocabulary = loadVocabulary();
|
|
280
|
+
return vocabulary.catalogId.test(target) || vocabulary.catalogName.test(target);
|
|
281
|
+
};
|
|
282
|
+
/** The minor of the catalog the view is of that `tree` needs: the newest `since` among the components and props of that catalog it uses. */
|
|
283
|
+
export const minorNeeded = (tree, view) => {
|
|
284
|
+
const target = view.label.split(' + ').pop();
|
|
285
|
+
let needed = 0;
|
|
286
|
+
const visit = (node) => {
|
|
287
|
+
const spec = view.components.get(node.component);
|
|
288
|
+
if (spec && spec.catalog === target) {
|
|
289
|
+
needed = Math.max(needed, spec.since);
|
|
290
|
+
for (const prop of node.props ?? [])
|
|
291
|
+
needed = Math.max(needed, spec.props.find(candidate => candidate.key === prop.key)?.since ?? 0);
|
|
292
|
+
}
|
|
293
|
+
for (const child of node.children ?? [])
|
|
294
|
+
visit(child);
|
|
295
|
+
};
|
|
296
|
+
visit(tree);
|
|
297
|
+
return needed;
|
|
298
|
+
};
|
|
131
299
|
/** Whether a component is a language one that holds others in whatever context (`if`, `foreach`, `fragment`). */
|
|
132
|
-
export const isLanguageContainer = (component) => component !== undefined && component.
|
|
300
|
+
export const isLanguageContainer = (component) => component !== undefined && component.group === LANGUAGE_GROUP && component.inheritsContext && component.acceptsChildren;
|
|
133
301
|
/** The context a component's children are in, given the one it sits in. */
|
|
134
302
|
export const innerContext = (component, context) => {
|
|
135
303
|
if (!component)
|