@arkitektio/bsx 1.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -16
- package/dist/catalogs/html.d.ts +117 -0
- package/dist/catalogs/html.d.ts.map +1 -0
- package/dist/catalogs/html.js +14 -0
- package/dist/catalogs/html.js.map +1 -0
- package/dist/catalogs/index.d.ts +6059 -0
- package/dist/catalogs/index.d.ts.map +1 -0
- package/dist/catalogs/index.js +11 -0
- package/dist/catalogs/index.js.map +1 -0
- package/dist/catalogs/logo.d.ts +214 -0
- package/dist/catalogs/logo.d.ts.map +1 -0
- package/dist/catalogs/logo.js +27 -0
- package/dist/catalogs/logo.js.map +1 -0
- package/dist/catalogs/parts/data.d.ts +408 -0
- package/dist/catalogs/parts/data.d.ts.map +1 -0
- package/dist/catalogs/parts/data.js +206 -0
- package/dist/catalogs/parts/data.js.map +1 -0
- package/dist/catalogs/parts/feedback.d.ts +440 -0
- package/dist/catalogs/parts/feedback.d.ts.map +1 -0
- package/dist/catalogs/parts/feedback.js +70 -0
- package/dist/catalogs/parts/feedback.js.map +1 -0
- package/dist/catalogs/parts/forms.d.ts +874 -0
- package/dist/catalogs/parts/forms.d.ts.map +1 -0
- package/dist/catalogs/parts/forms.js +302 -0
- package/dist/catalogs/parts/forms.js.map +1 -0
- package/dist/catalogs/parts/html.d.ts +93 -0
- package/dist/catalogs/parts/html.d.ts.map +1 -0
- package/dist/catalogs/parts/html.js +45 -0
- package/dist/catalogs/parts/html.js.map +1 -0
- package/dist/catalogs/parts/icons.d.ts +266 -0
- package/dist/catalogs/parts/icons.d.ts.map +1 -0
- package/dist/catalogs/parts/icons.js +149 -0
- package/dist/catalogs/parts/icons.js.map +1 -0
- package/dist/catalogs/parts/index.d.ts +5765 -0
- package/dist/catalogs/parts/index.d.ts.map +1 -0
- package/dist/catalogs/parts/index.js +38 -0
- package/dist/catalogs/parts/index.js.map +1 -0
- package/dist/catalogs/parts/inspector.d.ts +10 -0
- package/dist/catalogs/parts/inspector.d.ts.map +1 -0
- package/dist/catalogs/parts/inspector.js +12 -0
- package/dist/catalogs/parts/inspector.js.map +1 -0
- package/dist/catalogs/parts/layout.d.ts +647 -0
- package/dist/catalogs/parts/layout.d.ts.map +1 -0
- package/dist/catalogs/parts/layout.js +188 -0
- package/dist/catalogs/parts/layout.js.map +1 -0
- package/dist/catalogs/parts/logo.d.ts +321 -0
- package/dist/catalogs/parts/logo.d.ts.map +1 -0
- package/dist/catalogs/parts/logo.js +227 -0
- package/dist/catalogs/parts/logo.js.map +1 -0
- package/dist/catalogs/parts/navigation.d.ts +697 -0
- package/dist/catalogs/parts/navigation.d.ts.map +1 -0
- package/dist/catalogs/parts/navigation.js +194 -0
- package/dist/catalogs/parts/navigation.js.map +1 -0
- package/dist/catalogs/parts/overlays.d.ts +2012 -0
- package/dist/catalogs/parts/overlays.d.ts.map +1 -0
- package/dist/catalogs/parts/overlays.js +191 -0
- package/dist/catalogs/parts/overlays.js.map +1 -0
- package/dist/catalogs/parts/run.d.ts +41 -0
- package/dist/catalogs/parts/run.d.ts.map +1 -0
- package/dist/catalogs/parts/run.js +46 -0
- package/dist/catalogs/parts/run.js.map +1 -0
- package/dist/catalogs/parts/scene.d.ts +326 -0
- package/dist/catalogs/parts/scene.d.ts.map +1 -0
- package/dist/catalogs/parts/scene.js +237 -0
- package/dist/catalogs/parts/scene.js.map +1 -0
- package/dist/catalogs/parts/structure.d.ts +51 -0
- package/dist/catalogs/parts/structure.d.ts.map +1 -0
- package/dist/catalogs/parts/structure.js +66 -0
- package/dist/catalogs/parts/structure.js.map +1 -0
- package/dist/catalogs/parts/toast.d.ts +37 -0
- package/dist/catalogs/parts/toast.d.ts.map +1 -0
- package/dist/catalogs/parts/toast.js +23 -0
- package/dist/catalogs/parts/toast.js.map +1 -0
- package/dist/catalogs/parts/typography.d.ts +174 -0
- package/dist/catalogs/parts/typography.d.ts.map +1 -0
- package/dist/catalogs/parts/typography.js +56 -0
- package/dist/catalogs/parts/typography.js.map +1 -0
- package/dist/{renderer/bloks/shared/schemas.d.ts → catalogs/props.d.ts} +3 -3
- package/dist/catalogs/props.d.ts.map +1 -0
- package/dist/{renderer/bloks/shared/schemas.js → catalogs/props.js} +3 -4
- package/dist/catalogs/props.js.map +1 -0
- package/dist/catalogs/scene.d.ts +250 -0
- package/dist/catalogs/scene.d.ts.map +1 -0
- package/dist/catalogs/scene.js +28 -0
- package/dist/catalogs/scene.js.map +1 -0
- package/dist/catalogs/shadcn.d.ts +2397 -0
- package/dist/catalogs/shadcn.d.ts.map +1 -0
- package/dist/catalogs/shadcn.js +82 -0
- package/dist/catalogs/shadcn.js.map +1 -0
- package/dist/catalogs/structure.d.ts +61 -0
- package/dist/catalogs/structure.d.ts.map +1 -0
- package/dist/catalogs/structure.js +14 -0
- package/dist/catalogs/structure.js.map +1 -0
- package/dist/catalogs/ui.d.ts +3027 -0
- package/dist/catalogs/ui.d.ts.map +1 -0
- package/dist/catalogs/ui.js +91 -0
- package/dist/catalogs/ui.js.map +1 -0
- package/dist/catalogs.d.ts +5 -0
- package/dist/catalogs.d.ts.map +1 -0
- package/dist/catalogs.js +6 -0
- package/dist/catalogs.js.map +1 -0
- package/dist/platform.d.ts +11 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +5 -1
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +378 -27
- package/dist/renderer/bloks/data.d.ts.map +1 -1
- package/dist/renderer/bloks/data.js +55 -251
- package/dist/renderer/bloks/data.js.map +1 -1
- package/dist/renderer/bloks/feedback.d.ts +425 -8
- package/dist/renderer/bloks/feedback.d.ts.map +1 -1
- package/dist/renderer/bloks/feedback.js +23 -79
- package/dist/renderer/bloks/feedback.js.map +1 -1
- package/dist/renderer/bloks/forms.d.ts +828 -42
- package/dist/renderer/bloks/forms.d.ts.map +1 -1
- package/dist/renderer/bloks/forms.js +78 -368
- package/dist/renderer/bloks/forms.js.map +1 -1
- package/dist/renderer/bloks/html.d.ts +84 -9
- package/dist/renderer/bloks/html.d.ts.map +1 -1
- package/dist/renderer/bloks/html.js +13 -48
- package/dist/renderer/bloks/html.js.map +1 -1
- package/dist/renderer/bloks/icons.d.ts +133 -130
- package/dist/renderer/bloks/icons.d.ts.map +1 -1
- package/dist/renderer/bloks/icons.js +10 -23
- package/dist/renderer/bloks/icons.js.map +1 -1
- package/dist/renderer/bloks/index.d.ts +5251 -16
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/index.js +29 -27
- package/dist/renderer/bloks/index.js.map +1 -1
- package/dist/renderer/bloks/inspector/Inspector.d.ts +5 -1
- package/dist/renderer/bloks/inspector/Inspector.d.ts.map +1 -1
- package/dist/renderer/bloks/inspector/Inspector.js +5 -11
- package/dist/renderer/bloks/inspector/Inspector.js.map +1 -1
- package/dist/renderer/bloks/layout.d.ts +432 -15
- package/dist/renderer/bloks/layout.d.ts.map +1 -1
- package/dist/renderer/bloks/layout.js +43 -224
- package/dist/renderer/bloks/layout.js.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +172 -24
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +42 -236
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/navigation.d.ts +651 -28
- package/dist/renderer/bloks/navigation.d.ts.map +1 -1
- package/dist/renderer/bloks/navigation.js +65 -249
- package/dist/renderer/bloks/navigation.js.map +1 -1
- package/dist/renderer/bloks/overlays.d.ts +1998 -55
- package/dist/renderer/bloks/overlays.d.ts.map +1 -1
- package/dist/renderer/bloks/overlays.js +87 -265
- package/dist/renderer/bloks/overlays.js.map +1 -1
- package/dist/renderer/bloks/run/components.d.ts +13 -4
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +12 -34
- package/dist/renderer/bloks/run/components.js.map +1 -1
- package/dist/renderer/bloks/run/index.d.ts +1 -1
- package/dist/renderer/bloks/run/index.d.ts.map +1 -1
- package/dist/renderer/bloks/run/index.js +1 -1
- package/dist/renderer/bloks/run/index.js.map +1 -1
- package/dist/renderer/bloks/scene/Model.d.ts +6 -2
- package/dist/renderer/bloks/scene/Model.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Model.js +4 -48
- package/dist/renderer/bloks/scene/Model.js.map +1 -1
- package/dist/renderer/bloks/scene/Scene.d.ts +4 -1
- package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.js +3 -24
- package/dist/renderer/bloks/scene/Scene.js.map +1 -1
- package/dist/renderer/bloks/scene/Transform.d.ts +5 -1
- package/dist/renderer/bloks/scene/Transform.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Transform.js +3 -25
- package/dist/renderer/bloks/scene/Transform.js.map +1 -1
- package/dist/renderer/bloks/scene/bindings.d.ts +40 -8
- package/dist/renderer/bloks/scene/bindings.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/bindings.js +18 -102
- package/dist/renderer/bloks/scene/bindings.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +194 -1
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/index.js +21 -21
- package/dist/renderer/bloks/scene/index.js.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts +6 -2
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +6 -42
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/index.d.ts +0 -1
- package/dist/renderer/bloks/shared/index.d.ts.map +1 -1
- package/dist/renderer/bloks/shared/index.js +0 -1
- package/dist/renderer/bloks/shared/index.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +1 -1
- package/dist/renderer/bloks/shared/props.d.ts.map +1 -1
- package/dist/renderer/bloks/shared/props.js +1 -1
- package/dist/renderer/bloks/shared/props.js.map +1 -1
- package/dist/renderer/bloks/testing.d.ts +1 -1
- package/dist/renderer/bloks/testing.d.ts.map +1 -1
- package/dist/renderer/bloks/testing.js +5 -5
- package/dist/renderer/bloks/testing.js.map +1 -1
- package/dist/renderer/bloks/toast.d.ts +15 -5
- package/dist/renderer/bloks/toast.d.ts.map +1 -1
- package/dist/renderer/bloks/toast.js +11 -19
- package/dist/renderer/bloks/toast.js.map +1 -1
- package/dist/renderer/bloks/typography.d.ts +166 -24
- package/dist/renderer/bloks/typography.d.ts.map +1 -1
- package/dist/renderer/bloks/typography.js +22 -98
- package/dist/renderer/bloks/typography.js.map +1 -1
- package/dist/renderer/catalog.d.ts +3 -19
- package/dist/renderer/catalog.d.ts.map +1 -1
- package/dist/renderer/catalog.js +12 -29
- package/dist/renderer/catalog.js.map +1 -1
- package/dist/renderer/declare.d.ts +40 -0
- package/dist/renderer/declare.d.ts.map +1 -0
- package/dist/renderer/declare.js +40 -0
- package/dist/renderer/declare.js.map +1 -0
- package/dist/renderer/modules.d.ts +1 -18
- package/dist/renderer/modules.d.ts.map +1 -1
- package/dist/renderer/modules.js +1 -31
- package/dist/renderer/modules.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +63 -0
- package/dist/renderer/runtime/catalog.d.ts.map +1 -0
- package/dist/renderer/runtime/catalog.js +33 -0
- package/dist/renderer/runtime/catalog.js.map +1 -0
- package/dist/renderer/runtime/components.d.ts +27 -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/describe.d.ts +49 -0
- package/dist/renderer/runtime/describe.d.ts.map +1 -0
- package/dist/renderer/runtime/describe.js +127 -0
- package/dist/renderer/runtime/describe.js.map +1 -0
- package/dist/renderer/runtime/functions.d.ts +0 -13
- package/dist/renderer/runtime/functions.d.ts.map +1 -1
- package/dist/renderer/runtime/functions.js +0 -14
- package/dist/renderer/runtime/functions.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/runtime.d.ts +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -0
- package/dist/runtime.js.map +1 -1
- package/dist/scene.d.ts +2 -0
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +27 -1
- package/dist/scene.js.map +1 -1
- package/dist/shadcn.d.ts +5265 -0
- package/dist/shadcn.d.ts.map +1 -0
- package/dist/shadcn.js +194 -0
- package/dist/shadcn.js.map +1 -0
- package/dist/spec/bsx_v2.json +74 -113
- package/dist/spec/catalogs/logo@1.json +39 -25
- package/dist/spec/catalogs/logo@1.json.js +39 -25
- package/dist/spec/catalogs/scene@1.json +23 -23
- package/dist/spec/catalogs/scene@1.json.js +23 -23
- package/dist/spec/{modules/orkestrator.json → catalogs/shadcn@1.json} +1391 -286
- package/dist/spec/{modules/orkestrator.json.js → catalogs/shadcn@1.json.js} +1391 -286
- package/dist/spec/catalogs/structure@1.json +1 -1
- package/dist/spec/catalogs/structure@1.json.js +1 -1
- package/dist/spec/catalogs/ui@1.json +1690 -37
- package/dist/spec/catalogs/ui@1.json.js +1690 -37
- package/dist/spec/catalogs.d.ts +16 -12
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +23 -15
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.json +1 -1
- package/dist/spec/vocabulary.json.js +1 -1
- package/dist/vendor/core/ui/button-group.d.ts +1 -1
- package/dist/vendor/core/ui/field.d.ts +1 -1
- package/dist/web.d.ts +0 -3
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +2 -4
- package/dist/web.js.map +1 -1
- package/package.json +11 -2
- package/src/bsx/infer.test.ts +2 -2
- package/src/bsx/references.test.ts +2 -2
- package/src/catalogs/catalogs.test.ts +28 -0
- package/src/catalogs/html.ts +14 -0
- package/src/catalogs/index.ts +12 -0
- package/src/catalogs/logo.ts +27 -0
- package/src/catalogs/parts/data.ts +228 -0
- package/src/catalogs/parts/feedback.ts +79 -0
- package/src/catalogs/parts/forms.ts +335 -0
- package/src/catalogs/parts/html.ts +51 -0
- package/src/catalogs/parts/icons.ts +154 -0
- package/src/catalogs/parts/index.ts +38 -0
- package/src/catalogs/parts/inspector.ts +14 -0
- package/src/catalogs/parts/layout.ts +217 -0
- package/src/catalogs/parts/logo.ts +254 -0
- package/src/catalogs/parts/navigation.ts +198 -0
- package/src/catalogs/parts/overlays.ts +221 -0
- package/src/catalogs/parts/run.ts +57 -0
- package/src/catalogs/parts/scene.ts +292 -0
- package/src/catalogs/parts/structure.ts +83 -0
- package/src/catalogs/parts/toast.ts +27 -0
- package/src/catalogs/parts/typography.ts +63 -0
- package/src/{renderer/bloks/shared/schemas.ts → catalogs/props.ts} +2 -3
- package/src/catalogs/scene.ts +28 -0
- package/src/catalogs/shadcn.ts +82 -0
- package/src/catalogs/structure.ts +14 -0
- package/src/catalogs/ui.ts +91 -0
- package/src/catalogs.ts +6 -0
- package/src/platform.ts +8 -2
- package/src/preview/CachedBlokPreview.test.tsx +6 -1
- package/src/renderer/addBlokComponents.test.tsx +9 -7
- package/src/renderer/bloks/control.tsx +8 -1
- package/src/renderer/bloks/data.tsx +339 -621
- package/src/renderer/bloks/feedback.tsx +32 -112
- package/src/renderer/bloks/forms.tsx +103 -504
- package/src/renderer/bloks/html.tsx +16 -78
- package/src/renderer/bloks/icons.tsx +14 -31
- package/src/renderer/bloks/index.ts +28 -38
- package/src/renderer/bloks/inspector/Inspector.tsx +9 -11
- package/src/renderer/bloks/layout.tsx +216 -453
- package/src/renderer/bloks/logo/index.tsx +144 -387
- package/src/renderer/bloks/navigation.tsx +87 -343
- package/src/renderer/bloks/overlays.tsx +106 -524
- package/src/renderer/bloks/primitives.test.tsx +3 -1
- package/src/renderer/bloks/run/components.tsx +20 -58
- package/src/renderer/bloks/run/index.ts +1 -1
- package/src/renderer/bloks/scene/Model.tsx +7 -64
- package/src/renderer/bloks/scene/Scene.tsx +12 -38
- package/src/renderer/bloks/scene/Transform.tsx +6 -34
- package/src/renderer/bloks/scene/animate.test.tsx +2 -2
- package/src/renderer/bloks/scene/bindings.tsx +31 -113
- package/src/renderer/bloks/scene/index.ts +21 -21
- package/src/renderer/bloks/scene/interaction.tsx +7 -59
- package/src/renderer/bloks/shared/index.ts +0 -1
- package/src/renderer/bloks/shared/props.ts +1 -1
- package/src/renderer/bloks/testing.tsx +5 -5
- package/src/renderer/bloks/toast.tsx +16 -31
- package/src/renderer/bloks/typography.tsx +28 -141
- package/src/renderer/bloks/unavailable.test.tsx +3 -1
- package/src/renderer/catalog.tsx +13 -36
- package/src/renderer/declare.ts +82 -0
- package/src/renderer/modules.ts +1 -43
- package/src/renderer/runtime/catalog.test.ts +102 -0
- package/src/renderer/runtime/catalog.ts +108 -0
- package/src/renderer/runtime/components.tsx +27 -0
- package/src/renderer/runtime/describe.ts +180 -0
- package/src/renderer/runtime/functions.ts +0 -25
- package/src/renderer/runtime/index.ts +2 -0
- package/src/runtime.ts +1 -0
- package/src/scene.ts +30 -1
- package/src/shadcn.ts +202 -0
- package/src/spec/bsx_v2.json +74 -113
- package/src/spec/catalogs/logo@1.json +39 -25
- package/src/spec/catalogs/scene@1.json +23 -23
- package/src/spec/{modules/orkestrator.json → catalogs/shadcn@1.json} +1391 -286
- package/src/spec/catalogs/structure@1.json +1 -1
- package/src/spec/catalogs/ui@1.json +1690 -37
- package/src/spec/catalogs.ts +25 -16
- package/src/spec/spec.test.ts +1 -1
- package/src/spec/vocabulary.json +1 -1
- package/src/web.ts +2 -4
- package/dist/renderer/bloks/shared/schemas.d.ts.map +0 -1
- package/dist/renderer/bloks/shared/schemas.js.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {baseBlokCatalog} from './baseCatalog';
|
|
2
|
+
import {
|
|
3
|
+
catalogRef,
|
|
4
|
+
describeBlokComponent,
|
|
5
|
+
extendBlokCatalog,
|
|
6
|
+
type BlokCatalog,
|
|
7
|
+
type BlokCatalogImplementation,
|
|
8
|
+
type BlokComponentDefinition,
|
|
9
|
+
type SpecCatalogJson,
|
|
10
|
+
} from './runtime';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A UI's catalog, declared: the catalogs it implements and nothing inferred.
|
|
14
|
+
*
|
|
15
|
+
* - `catalog` is what its renderers draw: base@2 and every implementation.
|
|
16
|
+
* - `claims` are the global catalogs it implements whole (`ui@1`, `scene@1`):
|
|
17
|
+
* the server resolves their components from the spec, so a blok that uses
|
|
18
|
+
* only claimed catalogs is known to render here.
|
|
19
|
+
* - Its own catalogs (unversioned contracts) are part of `catalog`; what it
|
|
20
|
+
* registers as its module is `moduleComponentsOf(catalog)`, which also counts
|
|
21
|
+
* what its modules add later (`addBlokComponents`).
|
|
22
|
+
*
|
|
23
|
+
* A global catalog implemented `partial`ly is drawn but not claimed.
|
|
24
|
+
*/
|
|
25
|
+
export type BlokUi = {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string | null;
|
|
28
|
+
catalog: BlokCatalog;
|
|
29
|
+
implementations: readonly BlokCatalogImplementation[];
|
|
30
|
+
claims: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const declareBlokUi = (declaration: {
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
implements: readonly BlokCatalogImplementation[];
|
|
37
|
+
}): BlokUi => {
|
|
38
|
+
const implementations = declaration.implements;
|
|
39
|
+
const refs = implementations.map(implementation => catalogRef(implementation.contract));
|
|
40
|
+
const twice = refs.filter((ref, index) => refs.indexOf(ref) !== index);
|
|
41
|
+
if (twice.length > 0) {
|
|
42
|
+
throw new Error(`${declaration.name} implements ${[...new Set(twice)].join(', ')} twice`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name: declaration.name,
|
|
46
|
+
description: declaration.description ?? null,
|
|
47
|
+
catalog: extendBlokCatalog(
|
|
48
|
+
baseBlokCatalog,
|
|
49
|
+
declaration.name,
|
|
50
|
+
implementations.flatMap(implementation => implementation.components),
|
|
51
|
+
),
|
|
52
|
+
implementations,
|
|
53
|
+
claims: implementations
|
|
54
|
+
.filter(implementation => implementation.contract.version !== null && implementation.whole)
|
|
55
|
+
.map(implementation => catalogRef(implementation.contract))
|
|
56
|
+
.sort(),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* What a UI registers as its module (the server's `Module.components`): every
|
|
62
|
+
* component of its catalog that is neither base@2's nor a global catalog's. Its
|
|
63
|
+
* own catalogs' components, what its modules added since (`addBlokComponents`),
|
|
64
|
+
* and a global component a module drew over (it is the module's now).
|
|
65
|
+
*/
|
|
66
|
+
export const moduleComponentsOf = (catalog: BlokCatalog): BlokComponentDefinition[] =>
|
|
67
|
+
[...catalog.components.values()].filter(
|
|
68
|
+
component => catalog.base?.components.get(component.name) !== component && component.origin?.includes('@') !== true,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A UI's module as the spec writes a catalog: for the language's default view
|
|
73
|
+
* (`registerBlokModules([parseSpecCatalog(blokModuleSpec(...), ...)])`), so the
|
|
74
|
+
* parser and the checks know the components only this UI draws.
|
|
75
|
+
*/
|
|
76
|
+
export const blokModuleSpec = (name: string, description: string, catalog: BlokCatalog): SpecCatalogJson => ({
|
|
77
|
+
name,
|
|
78
|
+
description,
|
|
79
|
+
components: moduleComponentsOf(catalog)
|
|
80
|
+
.map(component => describeBlokComponent(component.name, component))
|
|
81
|
+
.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0)),
|
|
82
|
+
});
|
package/src/renderer/modules.ts
CHANGED
|
@@ -1,34 +1,8 @@
|
|
|
1
|
-
import {baseCatalog, standardCatalog, STANDARD_CATALOGS, type StandardCatalog} from '../spec/catalogs';
|
|
2
|
-
import {loadVocabulary} from '../spec/vocabulary';
|
|
3
1
|
import type {BlokCatalog} from './runtime';
|
|
4
2
|
|
|
5
|
-
/**
|
|
6
|
-
* What this renderer implements of the spec (blok language v2): base@2, every
|
|
7
|
-
* standard catalog whose every component it draws (`ui@1`, `scene@1`, ...),
|
|
8
|
-
* and its own extras, registered as the `orkestrator` module (the server's
|
|
9
|
-
* `Module`, `registerModule`) with those catalogs as `Module.catalogs`.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** The standard catalogs a renderer implements whole, as `name@version`. */
|
|
13
|
-
export const implementedCatalogs = (catalog: BlokCatalog): string[] =>
|
|
14
|
-
STANDARD_CATALOGS.filter((name: StandardCatalog) =>
|
|
15
|
-
standardCatalog(name).components.every(component => catalog.components.has(component.name)),
|
|
16
|
-
).map(name => `${name}@${loadVocabulary().catalogs[name]}`);
|
|
17
|
-
|
|
18
|
-
/** The standard catalogs a renderer leaves components of undrawn, with those components: what keeps it from claiming them. */
|
|
19
|
-
export const missingCatalogComponents = (catalog: BlokCatalog): Record<string, string[]> =>
|
|
20
|
-
Object.fromEntries(
|
|
21
|
-
STANDARD_CATALOGS.map((name): [string, string[]] => [
|
|
22
|
-
`${name}@${loadVocabulary().catalogs[name]}`,
|
|
23
|
-
standardCatalog(name)
|
|
24
|
-
.components.filter(component => !catalog.components.has(component.name))
|
|
25
|
-
.map(component => component.name),
|
|
26
|
-
]).filter(([, missing]) => missing.length > 0),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
3
|
const moduleShadows = new WeakMap<BlokCatalog, Set<string>>();
|
|
30
4
|
|
|
31
|
-
/** Per catalog, the
|
|
5
|
+
/** Per catalog, the global component names a module drew over (`addBlokComponents`): those the module's own definition renders. */
|
|
32
6
|
export const moduleShadowsOf = (catalog: BlokCatalog): Set<string> => {
|
|
33
7
|
const found = moduleShadows.get(catalog);
|
|
34
8
|
if (found) return found;
|
|
@@ -36,19 +10,3 @@ export const moduleShadowsOf = (catalog: BlokCatalog): Set<string> => {
|
|
|
36
10
|
moduleShadows.set(catalog, created);
|
|
37
11
|
return created;
|
|
38
12
|
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The components the spec owns (base and the standard catalogs): never part
|
|
42
|
-
* of the `orkestrator` module, except a standard one a module drew over in
|
|
43
|
-
* `catalog`, which the module registers as its own (it shadows the standard
|
|
44
|
-
* one, `catalog.shadow`).
|
|
45
|
-
*/
|
|
46
|
-
export const specOwnedComponents = (catalog?: BlokCatalog): ReadonlySet<string> => {
|
|
47
|
-
const shadowed = catalog ? moduleShadowsOf(catalog) : new Set<string>();
|
|
48
|
-
return new Set(
|
|
49
|
-
[
|
|
50
|
-
...baseCatalog().components.map(component => component.name),
|
|
51
|
-
...STANDARD_CATALOGS.flatMap(name => standardCatalog(name).components.map(component => component.name)),
|
|
52
|
-
].filter(name => !shadowed.has(name)),
|
|
53
|
-
);
|
|
54
|
-
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import {catalogRef, defineBlokCatalog, implementBlokCatalog, type BlokRender} from './catalog';
|
|
4
|
+
import {describeBlokContract} from './describe';
|
|
5
|
+
import {actionProp, bindSchema} from '../../catalogs/props';
|
|
6
|
+
|
|
7
|
+
const contract = defineBlokCatalog({
|
|
8
|
+
name: 'demo',
|
|
9
|
+
version: 1,
|
|
10
|
+
description: 'Two components.',
|
|
11
|
+
components: {
|
|
12
|
+
Label: {schema: z.object({text: z.string().optional().describe('What it says.')}).describe('A label.'), textProp: 'text'},
|
|
13
|
+
Knob: {
|
|
14
|
+
schema: z
|
|
15
|
+
.object({
|
|
16
|
+
bind: bindSchema,
|
|
17
|
+
level: z.enum(['low', 'high']).optional().describe('How far.'),
|
|
18
|
+
onTurn: actionProp('Runs when turned.'),
|
|
19
|
+
})
|
|
20
|
+
.describe('A knob.'),
|
|
21
|
+
bindKinds: {bind: 'FLOAT'},
|
|
22
|
+
events: {onTurn: [{key: 'value', kind: 'FLOAT', description: 'Where it stands.'}]},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const Label: BlokRender<typeof contract.components.Label> = () => null;
|
|
28
|
+
const Knob: BlokRender<typeof contract.components.Knob> = () => null;
|
|
29
|
+
|
|
30
|
+
describe('implementBlokCatalog', () => {
|
|
31
|
+
it('draws every component of the contract, tagged with it', () => {
|
|
32
|
+
const implementation = implementBlokCatalog(contract, {Label, Knob});
|
|
33
|
+
expect(implementation.whole).toBe(true);
|
|
34
|
+
expect(implementation.components.map(component => [component.name, component.origin])).toEqual([
|
|
35
|
+
['Label', 'demo@1'],
|
|
36
|
+
['Knob', 'demo@1'],
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('refuses a component left undrawn, unless partial', () => {
|
|
41
|
+
// @ts-expect-error Knob has no render.
|
|
42
|
+
expect(() => implementBlokCatalog(contract, {Label})).toThrow('demo@1 is implemented without Knob');
|
|
43
|
+
const partial = implementBlokCatalog(contract, {Label}, {partial: true});
|
|
44
|
+
expect(partial.whole).toBe(false);
|
|
45
|
+
expect(partial.components.map(component => component.name)).toEqual(['Label']);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('refuses a render for a component the contract does not hold', () => {
|
|
49
|
+
// @ts-expect-error Dial is not in the contract.
|
|
50
|
+
expect(() => implementBlokCatalog(contract, {Label, Knob, Dial: Label})).toThrow('demo@1 holds no Dial');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('names a UI-owned catalog without a version', () => {
|
|
54
|
+
expect(catalogRef(defineBlokCatalog({name: 'newswitch', description: '', components: {}}))).toBe('newswitch');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('describeBlokContract', () => {
|
|
59
|
+
it('writes the spec JSON: kinds, values, the bind kind, event fields and the text prop', () => {
|
|
60
|
+
expect(describeBlokContract(contract)).toEqual({
|
|
61
|
+
name: 'demo',
|
|
62
|
+
version: 1,
|
|
63
|
+
description: 'Two components.',
|
|
64
|
+
components: [
|
|
65
|
+
{
|
|
66
|
+
name: 'Knob',
|
|
67
|
+
description: 'A knob.',
|
|
68
|
+
context: 'HTML',
|
|
69
|
+
children_context: null,
|
|
70
|
+
inherits_context: false,
|
|
71
|
+
accepts_children: false,
|
|
72
|
+
downstream_of: [],
|
|
73
|
+
not_downstream_of: [],
|
|
74
|
+
text_prop: null,
|
|
75
|
+
props: [
|
|
76
|
+
{key: 'bind', kind: 'FLOAT', required: false, description: expect.any(String)},
|
|
77
|
+
{key: 'level', kind: 'STRING', required: false, description: 'How far.', values: ['low', 'high']},
|
|
78
|
+
{
|
|
79
|
+
key: 'onTurn',
|
|
80
|
+
kind: 'CALLBACK',
|
|
81
|
+
required: false,
|
|
82
|
+
description: 'Runs when turned.',
|
|
83
|
+
event: [{key: 'value', kind: 'FLOAT', description: 'Where it stands.'}],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'Label',
|
|
89
|
+
description: 'A label.',
|
|
90
|
+
context: 'HTML',
|
|
91
|
+
children_context: null,
|
|
92
|
+
inherits_context: false,
|
|
93
|
+
accepts_children: false,
|
|
94
|
+
downstream_of: [],
|
|
95
|
+
not_downstream_of: [],
|
|
96
|
+
text_prop: 'text',
|
|
97
|
+
props: [{key: 'text', kind: 'STRING', required: false, description: 'What it says.'}],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type {BlokComponentContract, BlokComponentDefinition, BlokRenderArgs} from './components';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Catalogs as the UI defines them.
|
|
6
|
+
*
|
|
7
|
+
* A *contract* (`defineBlokCatalog`) says which components a catalog holds and
|
|
8
|
+
* what each takes: name, schema, placement. It draws nothing. A versioned one
|
|
9
|
+
* (`ui@1`, `scene@1`) is global: every UI that implements it whole draws the
|
|
10
|
+
* same bloks, and the spec publishes it. An unversioned one is a UI's own (the
|
|
11
|
+
* `newswitch` catalog, orkestrator's MikroScene parts), registered with that UI.
|
|
12
|
+
*
|
|
13
|
+
* An *implementation* (`implementBlokCatalog`) is the app's: one render per
|
|
14
|
+
* component of a contract, a map the compiler checks against the contract.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type BlokComponentContracts = Record<string, BlokComponentContract<any>>;
|
|
18
|
+
|
|
19
|
+
export type BlokCatalogContract<TComponents extends BlokComponentContracts = BlokComponentContracts> = {
|
|
20
|
+
name: string;
|
|
21
|
+
/** Set on a global catalog (`ui@1`); null on a UI's own. */
|
|
22
|
+
version: number | null;
|
|
23
|
+
description: string;
|
|
24
|
+
components: TComponents;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const defineBlokCatalog = <const TComponents extends BlokComponentContracts>(contract: {
|
|
28
|
+
name: string;
|
|
29
|
+
version?: number;
|
|
30
|
+
description: string;
|
|
31
|
+
components: TComponents;
|
|
32
|
+
}): BlokCatalogContract<TComponents> => ({...contract, version: contract.version ?? null});
|
|
33
|
+
|
|
34
|
+
/** How a catalog is named on the wire: `name@version`, or a UI's own catalog's bare name. */
|
|
35
|
+
export const catalogRef = (contract: Pick<BlokCatalogContract, 'name' | 'version'>): string =>
|
|
36
|
+
contract.version === null ? contract.name : `${contract.name}@${contract.version}`;
|
|
37
|
+
|
|
38
|
+
/** How one component of a contract is drawn: its props typed from the contract's schema. */
|
|
39
|
+
export type BlokRender<TComponent extends BlokComponentContract<any>> = React.ComponentType<
|
|
40
|
+
BlokRenderArgs<TComponent['schema']>
|
|
41
|
+
>;
|
|
42
|
+
|
|
43
|
+
/** A render for every component of `TContract`. */
|
|
44
|
+
export type BlokRendersOf<TContract extends BlokCatalogContract<any>> = {
|
|
45
|
+
[K in keyof TContract['components']]: BlokRender<TContract['components'][K]>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type BlokCatalogImplementation = {
|
|
49
|
+
contract: BlokCatalogContract;
|
|
50
|
+
/** The contract's components, with this implementation's renders. */
|
|
51
|
+
components: readonly BlokComponentDefinition[];
|
|
52
|
+
/** Every component is drawn: the UI may claim the catalog. */
|
|
53
|
+
whole: boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Draw `contract` with `renders`. Every component must be drawn, unless
|
|
58
|
+
* `partial` says this UI draws a subset (it then does not claim the catalog,
|
|
59
|
+
* and a blok naming an undrawn component gets the "unknown component" card).
|
|
60
|
+
*/
|
|
61
|
+
export function implementBlokCatalog<TContract extends BlokCatalogContract<any>>(
|
|
62
|
+
contract: TContract,
|
|
63
|
+
renders: BlokRendersOf<TContract>,
|
|
64
|
+
): BlokCatalogImplementation;
|
|
65
|
+
export function implementBlokCatalog<TContract extends BlokCatalogContract<any>>(
|
|
66
|
+
contract: TContract,
|
|
67
|
+
renders: Partial<BlokRendersOf<TContract>>,
|
|
68
|
+
options: {partial: true},
|
|
69
|
+
): BlokCatalogImplementation;
|
|
70
|
+
export function implementBlokCatalog(
|
|
71
|
+
contract: BlokCatalogContract,
|
|
72
|
+
renders: Partial<Record<string, React.ComponentType<BlokRenderArgs<any>>>>,
|
|
73
|
+
options?: {partial: true},
|
|
74
|
+
): BlokCatalogImplementation {
|
|
75
|
+
const ref = catalogRef(contract);
|
|
76
|
+
const foreign = Object.keys(renders).filter(name => !(name in contract.components));
|
|
77
|
+
if (foreign.length > 0) {
|
|
78
|
+
throw new Error(`${ref} holds no ${foreign.join(', ')}`);
|
|
79
|
+
}
|
|
80
|
+
const missing = Object.keys(contract.components).filter(name => renders[name] === undefined);
|
|
81
|
+
if (missing.length > 0 && !options?.partial) {
|
|
82
|
+
throw new Error(`${ref} is implemented without ${missing.join(', ')}`);
|
|
83
|
+
}
|
|
84
|
+
const components = Object.entries(contract.components).flatMap(([name, component]): BlokComponentDefinition[] => {
|
|
85
|
+
const render = renders[name];
|
|
86
|
+
return render ? [{...component, name, render: render as React.ComponentType<BlokRenderArgs>, origin: ref}] : [];
|
|
87
|
+
});
|
|
88
|
+
return {contract, components, whole: missing.length === 0};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A UI's own catalog from components it defines whole, schema and render
|
|
93
|
+
* together (`createBlokComponent`): the contract and its implementation at
|
|
94
|
+
* once. The UI owns both, so there is nothing to check one against.
|
|
95
|
+
*/
|
|
96
|
+
export const ownBlokCatalog = (
|
|
97
|
+
meta: {name: string; version?: number; description: string},
|
|
98
|
+
components: readonly BlokComponentDefinition[],
|
|
99
|
+
): BlokCatalogImplementation => {
|
|
100
|
+
const contract = defineBlokCatalog({
|
|
101
|
+
...meta,
|
|
102
|
+
components: Object.fromEntries(
|
|
103
|
+
components.map(({name, render: _render, origin: _origin, ...component}) => [name, component as BlokComponentContract]),
|
|
104
|
+
),
|
|
105
|
+
});
|
|
106
|
+
const ref = catalogRef(contract);
|
|
107
|
+
return {contract, components: components.map(component => ({...component, origin: ref})), whole: true};
|
|
108
|
+
};
|
|
@@ -43,6 +43,9 @@ export type BlokComponentPlacement = {
|
|
|
43
43
|
/** Props the server holds to more than their shape: an `ASSET` prop names a file its app registered. */
|
|
44
44
|
export type BlokPropKind = 'ASSET';
|
|
45
45
|
|
|
46
|
+
/** A field of what a callback is called with (`event.value`), as the spec publishes it. */
|
|
47
|
+
export type BlokEventField = {key: string; kind: string; description: string};
|
|
48
|
+
|
|
46
49
|
type BlokComponentApi = {
|
|
47
50
|
/** Set when the component renders declared children its schema has no `children` prop for. */
|
|
48
51
|
acceptsChildren?: boolean;
|
|
@@ -54,12 +57,33 @@ type BlokComponentApi = {
|
|
|
54
57
|
* node binds the same path, since only one may write it.
|
|
55
58
|
*/
|
|
56
59
|
writesRecordTo?: string;
|
|
60
|
+
/** The prop text children fill (`<Button>Grip</Button>` sets `label`). */
|
|
61
|
+
textProp?: string;
|
|
62
|
+
/** Per callback prop, the fields of the event it is called with (`[]`: none). */
|
|
63
|
+
events?: Readonly<Record<string, readonly BlokEventField[]>>;
|
|
64
|
+
/**
|
|
65
|
+
* Per `bind` prop, the kind of value the control writes to the path it names
|
|
66
|
+
* (`Slider.bind` writes a FLOAT): what the spec publishes as the prop's kind,
|
|
67
|
+
* where the schema itself only says "a path".
|
|
68
|
+
*/
|
|
69
|
+
bindKinds?: Readonly<Record<string, string>>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* One component of a catalog contract: what it takes (`schema`, whose
|
|
74
|
+
* `.describe()` strings are the published documentation) and where it may sit.
|
|
75
|
+
* Nothing about how it is drawn: that is an implementation's.
|
|
76
|
+
*/
|
|
77
|
+
export type BlokComponentContract<TSchema extends BlokObjectSchema = BlokObjectSchema> = BlokComponentApi & {
|
|
78
|
+
schema: TSchema;
|
|
57
79
|
};
|
|
58
80
|
|
|
59
81
|
export type BlokComponentDefinition = BlokComponentApi & {
|
|
60
82
|
name: string;
|
|
61
83
|
schema: BlokObjectSchema;
|
|
62
84
|
render: React.ComponentType<BlokRenderArgs>;
|
|
85
|
+
/** The catalog contract it implements (`ui@1`, `newswitch`); unset for one built on its own. */
|
|
86
|
+
origin?: string;
|
|
63
87
|
};
|
|
64
88
|
|
|
65
89
|
export const createBlokComponent = <TSchema extends BlokObjectSchema>(
|
|
@@ -72,6 +96,9 @@ export const createBlokComponent = <TSchema extends BlokObjectSchema>(
|
|
|
72
96
|
placement: api.placement,
|
|
73
97
|
propKinds: api.propKinds,
|
|
74
98
|
writesRecordTo: api.writesRecordTo,
|
|
99
|
+
textProp: api.textProp,
|
|
100
|
+
events: api.events,
|
|
101
|
+
bindKinds: api.bindKinds,
|
|
75
102
|
render: render as React.ComponentType<BlokRenderArgs>,
|
|
76
103
|
});
|
|
77
104
|
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import type {BlokCatalogContract} from './catalog';
|
|
3
|
+
import type {BlokComponentContext, BlokComponentContract} from './components';
|
|
4
|
+
import {isRequiredField} from './preflight';
|
|
5
|
+
import {isActionSchema, isBindSchema, unwrapSchema} from './schemas';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A contract as the spec publishes it (`spec/catalogs/ui@1.json`, arkitekt-spec's
|
|
9
|
+
* `blok/catalogs/`): the JSON the server and `arkitekt check` validate bloks
|
|
10
|
+
* against. Written from the contract, never by hand: the zod schemas are the
|
|
11
|
+
* source, the JSON what they say in the spec's terms.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type SpecValueKind = 'STRING' | 'INT' | 'FLOAT' | 'BOOL' | 'DICT' | 'LIST' | 'ANY' | 'CALLBACK' | 'ASSET';
|
|
15
|
+
|
|
16
|
+
export type SpecPropJson = {
|
|
17
|
+
key: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
required: boolean;
|
|
20
|
+
description: string | null;
|
|
21
|
+
values?: string[];
|
|
22
|
+
event?: Array<{key: string; kind: string; description: string}>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type SpecComponentJson = {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string | null;
|
|
28
|
+
context: 'HTML' | 'SCENE' | 'LOGO';
|
|
29
|
+
children_context: 'HTML' | 'SCENE' | 'LOGO' | null;
|
|
30
|
+
inherits_context: boolean;
|
|
31
|
+
accepts_children: boolean;
|
|
32
|
+
downstream_of: string[];
|
|
33
|
+
not_downstream_of: string[];
|
|
34
|
+
text_prop: string | null;
|
|
35
|
+
props: SpecPropJson[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type SpecCatalogJson = {
|
|
39
|
+
name: string;
|
|
40
|
+
version?: number;
|
|
41
|
+
description: string;
|
|
42
|
+
components: SpecComponentJson[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const INT_FORMATS = new Set(['safeint', 'int32', 'uint32', 'int64', 'uint64']);
|
|
46
|
+
|
|
47
|
+
type ZodDef = {
|
|
48
|
+
type?: string;
|
|
49
|
+
format?: string;
|
|
50
|
+
in?: z.ZodTypeAny;
|
|
51
|
+
options?: z.ZodTypeAny[];
|
|
52
|
+
values?: unknown[];
|
|
53
|
+
entries?: Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const defOf = (schema: z.ZodTypeAny): ZodDef => (schema as unknown as {def?: ZodDef}).def ?? {};
|
|
57
|
+
|
|
58
|
+
/** Through optional/nullable/default wrappers and transforms (`pipe`). */
|
|
59
|
+
const unwrapForKind = (schema: z.ZodTypeAny): z.ZodTypeAny => {
|
|
60
|
+
let current = unwrapSchema(schema);
|
|
61
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
62
|
+
const def = defOf(current);
|
|
63
|
+
if (def.type !== 'pipe' || !def.in) return current;
|
|
64
|
+
current = unwrapSchema(def.in);
|
|
65
|
+
}
|
|
66
|
+
return current;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** The closed set of strings a `z.enum` prop takes, through its wrappers; null for any other schema. */
|
|
70
|
+
export const zodEnumValues = (schema: z.ZodTypeAny): string[] | null => {
|
|
71
|
+
const def = defOf(unwrapForKind(schema));
|
|
72
|
+
if (def.type !== 'enum' || !def.entries) return null;
|
|
73
|
+
const values = Object.values(def.entries);
|
|
74
|
+
return values.every((value): value is string => typeof value === 'string') ? values : null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** The spec's value kind for a zod schema; a shape it has no word for is `ANY`. */
|
|
78
|
+
export const zodToSpecKind = (schema: z.ZodTypeAny): SpecValueKind => {
|
|
79
|
+
// Action props are `z.custom(...)` under a brand: check before the type switch.
|
|
80
|
+
if (isActionSchema(schema)) return 'CALLBACK';
|
|
81
|
+
const def = defOf(unwrapForKind(schema));
|
|
82
|
+
switch (def.type) {
|
|
83
|
+
case 'string':
|
|
84
|
+
case 'enum':
|
|
85
|
+
case 'template_literal':
|
|
86
|
+
return 'STRING';
|
|
87
|
+
case 'literal': {
|
|
88
|
+
const values = def.values ?? [];
|
|
89
|
+
if (values.every(value => typeof value === 'string')) return 'STRING';
|
|
90
|
+
if (values.every(value => typeof value === 'boolean')) return 'BOOL';
|
|
91
|
+
if (values.every(value => typeof value === 'number')) return 'FLOAT';
|
|
92
|
+
return 'ANY';
|
|
93
|
+
}
|
|
94
|
+
case 'number':
|
|
95
|
+
return def.format && INT_FORMATS.has(def.format) ? 'INT' : 'FLOAT';
|
|
96
|
+
case 'boolean':
|
|
97
|
+
return 'BOOL';
|
|
98
|
+
case 'array':
|
|
99
|
+
case 'tuple':
|
|
100
|
+
case 'set':
|
|
101
|
+
return 'LIST';
|
|
102
|
+
case 'object':
|
|
103
|
+
case 'record':
|
|
104
|
+
case 'map':
|
|
105
|
+
return 'DICT';
|
|
106
|
+
case 'union': {
|
|
107
|
+
const kinds = new Set((def.options ?? []).map(zodToSpecKind));
|
|
108
|
+
return kinds.size === 1 ? [...kinds][0] : 'ANY';
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
return 'ANY';
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {html: 'HTML', scene: 'SCENE', logo: 'LOGO'};
|
|
116
|
+
|
|
117
|
+
const byKey = <T extends {key: string}>(left: T, right: T) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
|
|
118
|
+
const byName = <T extends {name: string}>(left: T, right: T) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* What a `bind` says it writes, by the kind it writes: the ports whose locals
|
|
122
|
+
* it may name. Appended to a bind prop's description unless it says so itself.
|
|
123
|
+
*/
|
|
124
|
+
const BIND_WRITES: Readonly<Record<string, string>> = {
|
|
125
|
+
BOOL: 'It writes a BOOL: the local is a BOOL port.',
|
|
126
|
+
FLOAT: 'It writes a FLOAT: the local is a FLOAT, INT or QUANTITY port.',
|
|
127
|
+
STRING: 'It writes a STRING: the local is a STRING, ENUM or DATE port.',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const bindDescription = (description: string | null, kind: string): string | null => {
|
|
131
|
+
const writes = BIND_WRITES[kind];
|
|
132
|
+
if (!writes || description?.includes('It writes')) return description;
|
|
133
|
+
return description ? `${description} ${writes}` : writes;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** `children` is no prop in the spec: `accepts_children` says a component takes them. */
|
|
137
|
+
const CHILDREN = 'children';
|
|
138
|
+
|
|
139
|
+
export const describeBlokComponent = (name: string, component: BlokComponentContract): SpecComponentJson => {
|
|
140
|
+
const shape = component.schema.shape as Record<string, z.ZodTypeAny>;
|
|
141
|
+
const placement = component.placement ?? {};
|
|
142
|
+
const props = Object.entries(shape)
|
|
143
|
+
.filter(([key]) => key !== CHILDREN)
|
|
144
|
+
.map(([key, schema]): SpecPropJson => {
|
|
145
|
+
const bindKind = isBindSchema(schema) ? component.bindKinds?.[key] : undefined;
|
|
146
|
+
const kind = component.propKinds?.[key] ?? bindKind ?? zodToSpecKind(schema);
|
|
147
|
+
const description = bindKind ? bindDescription(schema.description ?? null, bindKind) : (schema.description ?? null);
|
|
148
|
+
const prop: SpecPropJson = {key, kind, required: isRequiredField(schema), description};
|
|
149
|
+
const values = kind === 'STRING' ? zodEnumValues(schema) : null;
|
|
150
|
+
if (values) prop.values = values;
|
|
151
|
+
if (kind === 'CALLBACK') prop.event = [...(component.events?.[key] ?? [])];
|
|
152
|
+
return prop;
|
|
153
|
+
})
|
|
154
|
+
.sort(byKey);
|
|
155
|
+
return {
|
|
156
|
+
name,
|
|
157
|
+
description: component.schema.description ?? null,
|
|
158
|
+
context: CONTEXT[placement.context ?? 'html'],
|
|
159
|
+
children_context: placement.childrenContext ? CONTEXT[placement.childrenContext] : null,
|
|
160
|
+
inherits_context: placement.inheritsContext ?? false,
|
|
161
|
+
accepts_children: component.acceptsChildren ?? CHILDREN in shape,
|
|
162
|
+
downstream_of: [...(placement.downstreamOf ?? [])],
|
|
163
|
+
not_downstream_of: [...(placement.notDownstreamOf ?? [])],
|
|
164
|
+
text_prop: component.textProp ?? null,
|
|
165
|
+
props,
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const describeBlokContract = (contract: BlokCatalogContract): SpecCatalogJson => ({
|
|
170
|
+
name: contract.name,
|
|
171
|
+
...(contract.version === null ? {} : {version: contract.version}),
|
|
172
|
+
description: contract.description,
|
|
173
|
+
components: Object.entries(contract.components)
|
|
174
|
+
.map(([name, component]) => describeBlokComponent(name, component))
|
|
175
|
+
.sort(byName),
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/** The spec's file text: Python's `json.dumps(indent=1)` (ASCII-escaped), so a regenerated file diffs clean. */
|
|
179
|
+
export const specJsonText = (value: unknown): string =>
|
|
180
|
+
`${JSON.stringify(value, null, 1).replace(/[\u007f-]/g, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`)}\n`;
|
|
@@ -42,28 +42,3 @@ export const extendBlokCatalog = (
|
|
|
42
42
|
}
|
|
43
43
|
return {...createBlokCatalog(id, [...base.components.values(), ...components]), base};
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
export const mergeBlokCatalogs = (id: string, catalogs: ReadonlyArray<BlokCatalog>): BlokCatalog =>
|
|
47
|
-
createBlokCatalog(
|
|
48
|
-
id,
|
|
49
|
-
catalogs.flatMap(catalog => [...catalog.components.values()]),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
export type BlokCatalogManifest = {
|
|
53
|
-
id: string;
|
|
54
|
-
components: Array<{name: string; props: string[]}>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Serializable description of what a catalog offers: its components and their
|
|
59
|
-
* props, what an authoring UI needs to complete component names.
|
|
60
|
-
*/
|
|
61
|
-
export const describeBlokCatalog = (catalog: BlokCatalog): BlokCatalogManifest => ({
|
|
62
|
-
id: catalog.id,
|
|
63
|
-
components: [...catalog.components.values()]
|
|
64
|
-
.map(component => ({
|
|
65
|
-
name: component.name,
|
|
66
|
-
props: Object.keys(component.schema.shape).sort(),
|
|
67
|
-
}))
|
|
68
|
-
.sort((left, right) => left.name.localeCompare(right.name)),
|
|
69
|
-
});
|
package/src/runtime.ts
CHANGED
package/src/scene.ts
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
// @arkitektio/bsx/scene:
|
|
1
|
+
// @arkitektio/bsx/scene: scene@1 drawn with three, @react-three/fiber and drei (opt-in: an app passes
|
|
2
|
+
// threeScene to declareBlokUi), and the scene and run hosts the renderer mounts.
|
|
3
|
+
import {sceneCatalog} from './catalogs/index';
|
|
4
|
+
import {runRenders} from './renderer/bloks/run';
|
|
5
|
+
import {sceneRenders} from './renderer/bloks/scene';
|
|
6
|
+
import {implementBlokCatalog} from './renderer/runtime/catalog';
|
|
7
|
+
|
|
2
8
|
export * from './renderer/bloks/scene';
|
|
3
9
|
export * from './renderer/bloks/run';
|
|
10
|
+
|
|
11
|
+
const renders = {...sceneRenders, ...runRenders};
|
|
12
|
+
|
|
13
|
+
/** scene@1, drawn with three. */
|
|
14
|
+
export const threeScene = implementBlokCatalog(sceneCatalog, {
|
|
15
|
+
Anchor: renders.Anchor,
|
|
16
|
+
Animate: renders.Animate,
|
|
17
|
+
Attach: renders.Attach,
|
|
18
|
+
Beam: renders.Beam,
|
|
19
|
+
Glow: renders.Glow,
|
|
20
|
+
Model: renders.Model,
|
|
21
|
+
Move: renders.Move,
|
|
22
|
+
OnClick: renders.OnClick,
|
|
23
|
+
Overlay: renders.Overlay,
|
|
24
|
+
Popout: renders.Popout,
|
|
25
|
+
Robot: renders.Robot,
|
|
26
|
+
Rotate: renders.Rotate,
|
|
27
|
+
Route: renders.Route,
|
|
28
|
+
Scene: renders.Scene,
|
|
29
|
+
Tint: renders.Tint,
|
|
30
|
+
Transform: renders.Transform,
|
|
31
|
+
Visible: renders.Visible,
|
|
32
|
+
});
|