@arkitektio/bsx 4.3.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -18
- package/dist/bsx/analyze.d.ts +6 -5
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +12 -10
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +111 -0
- package/dist/bsx/declared.d.ts.map +1 -0
- package/dist/bsx/declared.js +311 -0
- package/dist/bsx/declared.js.map +1 -0
- package/dist/bsx/index.d.ts +1 -0
- package/dist/bsx/index.d.ts.map +1 -1
- package/dist/bsx/index.js +1 -0
- package/dist/bsx/index.js.map +1 -1
- package/dist/bsx/infer.d.ts +40 -17
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +105 -49
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts +6 -2
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +65 -21
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +19 -8
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +49 -59
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +25 -35
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +48 -54
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +359 -159
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +3 -3
- package/dist/catalogs/html.d.ts.map +1 -1
- package/dist/catalogs/html.js +3 -3
- package/dist/catalogs/html.js.map +1 -1
- package/dist/catalogs/index.d.ts +172 -180
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +6 -2
- package/dist/catalogs/index.js.map +1 -1
- package/dist/catalogs/logo.d.ts +19 -33
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +4 -5
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +6 -6
- package/dist/catalogs/parts/feedback.d.ts +15 -15
- package/dist/catalogs/parts/forms.d.ts +24 -24
- package/dist/catalogs/parts/html.d.ts +3 -3
- package/dist/catalogs/parts/html.d.ts.map +1 -1
- package/dist/catalogs/parts/html.js +1 -1
- package/dist/catalogs/parts/html.js.map +1 -1
- package/dist/catalogs/parts/icons.d.ts +11 -11
- package/dist/catalogs/parts/icons.js +1 -1
- package/dist/catalogs/parts/index.d.ts +153 -165
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.d.ts +11 -1
- package/dist/catalogs/parts/layout.d.ts.map +1 -1
- package/dist/catalogs/parts/layout.js +9 -0
- package/dist/catalogs/parts/layout.js.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +17 -32
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +13 -15
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +20 -20
- package/dist/catalogs/parts/overlays.d.ts +55 -55
- package/dist/catalogs/parts/run.d.ts +5 -13
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +1 -1
- package/dist/catalogs/parts/scene.d.ts +9 -17
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +1 -5
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/structure.js +2 -2
- package/dist/catalogs/parts/toast.js +1 -1
- package/dist/catalogs/parts/toast.js.map +1 -1
- package/dist/catalogs/parts/typography.d.ts +3 -3
- package/dist/catalogs/parts/typography.js +1 -1
- package/dist/catalogs/parts/typography.js.map +1 -1
- package/dist/catalogs/props.d.ts +4 -4
- package/dist/catalogs/scene.d.ts +8 -16
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +3 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/catalogs/shadcn.d.ts +58 -58
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +4 -4
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/structure.d.ts +1 -1
- package/dist/catalogs/structure.d.ts.map +1 -1
- package/dist/catalogs/structure.js +3 -3
- package/dist/catalogs/structure.js.map +1 -1
- package/dist/catalogs/ui.d.ts +83 -73
- package/dist/catalogs/ui.d.ts.map +1 -1
- package/dist/catalogs/ui.js +4 -3
- package/dist/catalogs/ui.js.map +1 -1
- package/dist/catalogs.d.ts +1 -1
- package/dist/catalogs.d.ts.map +1 -1
- package/dist/catalogs.js +2 -2
- package/dist/catalogs.js.map +1 -1
- package/dist/logo/actionLogoSource.d.ts +3 -3
- package/dist/logo/actionLogoSource.d.ts.map +1 -1
- package/dist/logo/actionLogoSource.js +4 -4
- package/dist/logo/actionLogoSource.js.map +1 -1
- package/dist/ports.js +1 -1
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +10 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +23 -9
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +8 -6
- package/dist/renderer/baseCatalog.d.ts.map +1 -1
- package/dist/renderer/baseCatalog.js +7 -5
- package/dist/renderer/baseCatalog.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +20 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +98 -15
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +6 -6
- package/dist/renderer/bloks/feedback.d.ts +15 -15
- package/dist/renderer/bloks/forms.d.ts +24 -24
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/html.js +2 -2
- package/dist/renderer/bloks/icons.d.ts +5 -5
- package/dist/renderer/bloks/index.d.ts +145 -144
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/index.js +1 -1
- package/dist/renderer/bloks/layout.d.ts +9 -1
- package/dist/renderer/bloks/layout.d.ts.map +1 -1
- package/dist/renderer/bloks/layout.js +15 -0
- package/dist/renderer/bloks/layout.js.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +6 -13
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +3 -4
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
- package/dist/renderer/bloks/navigation.d.ts +20 -20
- package/dist/renderer/bloks/overlays.d.ts +55 -55
- package/dist/renderer/bloks/run/components.d.ts +2 -6
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +5 -9
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +3 -2
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +2 -2
- package/dist/renderer/bloks/toast.d.ts +1 -1
- package/dist/renderer/bloks/typography.d.ts +3 -3
- package/dist/renderer/bloks/typography.js +1 -1
- package/dist/renderer/catalog.d.ts +4 -7
- package/dist/renderer/catalog.d.ts.map +1 -1
- package/dist/renderer/catalog.js +7 -31
- package/dist/renderer/catalog.js.map +1 -1
- package/dist/renderer/declarations.d.ts +40 -33
- package/dist/renderer/declarations.d.ts.map +1 -1
- package/dist/renderer/declarations.js +41 -56
- package/dist/renderer/declarations.js.map +1 -1
- package/dist/renderer/declare.d.ts +31 -19
- package/dist/renderer/declare.d.ts.map +1 -1
- package/dist/renderer/declare.js +44 -18
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/persist.d.ts +22 -13
- package/dist/renderer/persist.d.ts.map +1 -1
- package/dist/renderer/persist.js +40 -21
- package/dist/renderer/persist.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +27 -7
- package/dist/renderer/runtime/catalog.d.ts.map +1 -1
- package/dist/renderer/runtime/catalog.js +30 -3
- package/dist/renderer/runtime/catalog.js.map +1 -1
- package/dist/renderer/runtime/components.d.ts +10 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +8 -5
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +5 -5
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +11 -5
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +16 -6
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +5 -2
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +8 -4
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +2 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +2 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/locals.d.ts +57 -0
- package/dist/renderer/runtime/locals.d.ts.map +1 -0
- package/dist/renderer/runtime/locals.js +87 -0
- package/dist/renderer/runtime/locals.js.map +1 -0
- package/dist/renderer/runtime/preflight.d.ts.map +1 -1
- package/dist/renderer/runtime/preflight.js +5 -2
- package/dist/renderer/runtime/preflight.js.map +1 -1
- package/dist/renderer/runtime/scope.d.ts +14 -0
- package/dist/renderer/runtime/scope.d.ts.map +1 -1
- package/dist/renderer/runtime/scope.js +25 -3
- package/dist/renderer/runtime/scope.js.map +1 -1
- package/dist/renderer/runtime/text.d.ts +28 -0
- package/dist/renderer/runtime/text.d.ts.map +1 -0
- package/dist/renderer/runtime/text.js +82 -0
- package/dist/renderer/runtime/text.js.map +1 -0
- package/dist/renderer/runtime/tree.d.ts.map +1 -1
- package/dist/renderer/runtime/tree.js +7 -1
- package/dist/renderer/runtime/tree.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +8 -3
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/scene.d.ts +1 -1
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +2 -2
- package/dist/scene.js.map +1 -1
- package/dist/shadcn.d.ts +154 -153
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +7 -7
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +12324 -6934
- package/dist/spec/catalogs/base@4.json +13175 -0
- package/dist/spec/catalogs/base@4.json.js +13175 -0
- package/dist/spec/catalogs/orkestrator@1.json +489 -0
- package/dist/spec/catalogs/orkestrator@1.json.js +489 -0
- package/dist/spec/catalogs.d.ts +109 -46
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +243 -75
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +44 -7
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +65 -7
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +83 -43
- package/dist/spec/vocabulary.json.js +83 -43
- package/dist/vendor/core/ui/button-group.d.ts +1 -1
- package/dist/vendor/core/ui/button.d.ts +1 -1
- package/dist/vendor/core/ui/field.d.ts +1 -1
- package/package.json +1 -1
- package/src/bsx/analyze.ts +14 -12
- package/src/bsx/bsx.test.ts +4 -4
- package/src/bsx/declared.ts +346 -0
- package/src/bsx/index.ts +1 -0
- package/src/bsx/infer.test.ts +54 -52
- package/src/bsx/infer.ts +128 -71
- package/src/bsx/language.test.ts +37 -25
- package/src/bsx/language.ts +72 -25
- package/src/bsx/parse.ts +51 -64
- package/src/bsx/partial.test.ts +1 -1
- package/src/bsx/print.ts +27 -34
- package/src/bsx/references.test.ts +86 -83
- package/src/bsx/references.ts +391 -198
- package/src/catalogs/catalogs.test.ts +46 -14
- package/src/catalogs/html.ts +3 -3
- package/src/catalogs/index.ts +6 -2
- package/src/catalogs/logo.ts +4 -5
- package/src/catalogs/parts/html.ts +1 -1
- package/src/catalogs/parts/icons.ts +1 -1
- package/src/catalogs/parts/layout.ts +11 -0
- package/src/catalogs/parts/logo.ts +14 -18
- package/src/catalogs/parts/run.ts +1 -1
- package/src/catalogs/parts/scene.ts +1 -7
- package/src/catalogs/parts/structure.ts +2 -2
- package/src/catalogs/parts/toast.ts +1 -1
- package/src/catalogs/parts/typography.ts +1 -1
- package/src/catalogs/scene.ts +3 -3
- package/src/catalogs/shadcn.ts +4 -4
- package/src/catalogs/structure.ts +3 -3
- package/src/catalogs/ui.ts +4 -3
- package/src/catalogs.ts +9 -2
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/ports.ts +1 -1
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.tsx +46 -14
- package/src/renderer/addBlokComponents.test.tsx +8 -22
- package/src/renderer/baseCatalog.ts +7 -5
- package/src/renderer/bloks/components.test.tsx +2 -2
- package/src/renderer/bloks/control.tsx +136 -17
- package/src/renderer/bloks/flow.test.tsx +1 -1
- package/src/renderer/bloks/html.tsx +2 -2
- package/src/renderer/bloks/index.ts +1 -1
- package/src/renderer/bloks/layout.tsx +28 -0
- package/src/renderer/bloks/logo/index.tsx +4 -5
- package/src/renderer/bloks/logo/logo.fixture.json +266 -250
- package/src/renderer/bloks/logo/logo.test.tsx +18 -7
- package/src/renderer/bloks/run/components.tsx +1 -1
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- package/src/renderer/bloks/time.test.tsx +1 -1
- package/src/renderer/bloks/toast.tsx +1 -1
- package/src/renderer/bloks/typography.tsx +1 -1
- package/src/renderer/catalog.tsx +7 -31
- package/src/renderer/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +41 -0
- package/src/renderer/declare.ts +70 -32
- package/src/renderer/persist.test.ts +70 -49
- package/src/renderer/persist.ts +57 -34
- package/src/renderer/runtime/catalog.test.ts +2 -2
- package/src/renderer/runtime/catalog.ts +35 -10
- package/src/renderer/runtime/components.tsx +17 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +21 -8
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +2 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/preflight.ts +5 -2
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/text.test.tsx +65 -0
- package/src/renderer/runtime/text.ts +88 -0
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/runtime.ts +0 -1
- package/src/scene.ts +2 -2
- package/src/shadcn.ts +7 -7
- package/src/spec/bsx_v2.json +12324 -6934
- package/src/spec/catalogs/base@4.json +13175 -0
- package/src/spec/catalogs/orkestrator@1.json +489 -0
- package/src/spec/catalogs.ts +259 -103
- package/src/spec/spec.test.ts +93 -24
- package/src/spec/vocabulary.json +83 -43
- package/src/spec/vocabulary.ts +102 -17
- package/dist/renderer/modules.d.ts +0 -4
- package/dist/renderer/modules.d.ts.map +0 -1
- package/dist/renderer/modules.js +0 -11
- package/dist/renderer/modules.js.map +0 -1
- package/dist/spec/catalogs/base@2.json +0 -355
- package/dist/spec/catalogs/base@2.json.js +0 -355
- package/dist/spec/catalogs/html@1.json +0 -308
- package/dist/spec/catalogs/html@1.json.js +0 -308
- package/dist/spec/catalogs/logo@1.json +0 -1687
- package/dist/spec/catalogs/logo@1.json.js +0 -1687
- package/dist/spec/catalogs/scene@1.json +0 -878
- package/dist/spec/catalogs/scene@1.json.js +0 -878
- package/dist/spec/catalogs/shadcn@1.json +0 -4002
- package/dist/spec/catalogs/shadcn@1.json.js +0 -4002
- package/dist/spec/catalogs/structure@1.json +0 -185
- package/dist/spec/catalogs/structure@1.json.js +0 -185
- package/dist/spec/catalogs/ui@1.json +0 -5349
- package/dist/spec/catalogs/ui@1.json.js +0 -5349
- package/src/renderer/modules.ts +0 -12
- package/src/spec/catalogs/base@2.json +0 -355
- package/src/spec/catalogs/html@1.json +0 -308
- package/src/spec/catalogs/logo@1.json +0 -1687
- package/src/spec/catalogs/scene@1.json +0 -878
- package/src/spec/catalogs/shadcn@1.json +0 -4002
- package/src/spec/catalogs/structure@1.json +0 -185
- package/src/spec/catalogs/ui@1.json +0 -5349
|
@@ -5,12 +5,11 @@ import * as z from "zod";
|
|
|
5
5
|
import { cleanup, screen } from "@testing-library/react";
|
|
6
6
|
import { renderBsx, testCatalog} from "./bloks/testing";
|
|
7
7
|
import { addBlokComponents } from "./catalog";
|
|
8
|
-
import { moduleShadowsOf } from "./modules";
|
|
9
8
|
import { createBlokCatalog, createBlokComponent } from "./runtime";
|
|
10
9
|
|
|
11
10
|
const part = (name: string) => createBlokComponent({ name, schema: z.object({}) }, () => null);
|
|
12
|
-
/** A component of
|
|
13
|
-
const
|
|
11
|
+
/** A component of the base catalog, as `implementBlokCatalog` tags one of its families'. */
|
|
12
|
+
const base = (name: string) => ({ ...part(name), origin: "base@4" });
|
|
14
13
|
|
|
15
14
|
describe("addBlokComponents", () => {
|
|
16
15
|
it("adds a module's components and takes them back out", () => {
|
|
@@ -29,36 +28,23 @@ describe("addBlokComponents", () => {
|
|
|
29
28
|
expect([...catalog.components.keys()]).toEqual(["Card", "foreach", "MikroScene"]);
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
it("
|
|
33
|
-
const standard =
|
|
34
|
-
const mine = part("Slider");
|
|
31
|
+
it("never draws over a component of the base catalog: a catalog only adds", () => {
|
|
32
|
+
const standard = base("Slider");
|
|
35
33
|
const catalog = createBlokCatalog("test", [standard]);
|
|
36
|
-
const undo = addBlokComponents([mine], catalog);
|
|
37
|
-
expect(catalog.components.get("Slider")).toBe(mine);
|
|
38
|
-
// A second module cannot draw over it again.
|
|
39
34
|
expect(() => addBlokComponents([part("Slider")], catalog)).toThrow(/Slider/);
|
|
40
|
-
undo();
|
|
41
35
|
expect(catalog.components.get("Slider")).toBe(standard);
|
|
42
36
|
});
|
|
43
37
|
|
|
44
38
|
it("renders the module's component where a blok uses the name", () => {
|
|
45
|
-
const mine = createBlokComponent({ name: "
|
|
39
|
+
const mine = createBlokComponent({ name: "Gauge", schema: z.object({}) }, () => <span>my gauge</span>);
|
|
46
40
|
const undo = addBlokComponents([mine], testCatalog());
|
|
47
41
|
try {
|
|
48
|
-
renderBsx(testCatalog(), "<Card><
|
|
49
|
-
expect(screen.queryByText("my
|
|
42
|
+
renderBsx(testCatalog(), "<Card><Gauge /></Card>");
|
|
43
|
+
expect(screen.queryByText("my gauge")).not.toBeNull();
|
|
50
44
|
} finally {
|
|
51
45
|
cleanup();
|
|
52
46
|
undo();
|
|
53
47
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
it("records a drawn-over global component as the module's own until undone", () => {
|
|
57
|
-
const catalog = createBlokCatalog("test", [global("Slider")]);
|
|
58
|
-
expect(moduleShadowsOf(catalog).has("Slider")).toBe(false);
|
|
59
|
-
const undo = addBlokComponents([part("Slider")], catalog);
|
|
60
|
-
expect(moduleShadowsOf(catalog).has("Slider")).toBe(true);
|
|
61
|
-
undo();
|
|
62
|
-
expect(moduleShadowsOf(catalog).has("Slider")).toBe(false);
|
|
48
|
+
expect(testCatalog().components.has("Gauge")).toBe(false);
|
|
63
49
|
});
|
|
64
50
|
});
|
|
@@ -2,13 +2,15 @@ import {controlBlokComponents} from './bloks/control';
|
|
|
2
2
|
import {createBlokCatalog, type BlokCatalog} from './runtime';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
7
|
-
* `fragment`, `suspense`/`fallback`/`error`,
|
|
8
|
-
*
|
|
5
|
+
* The part of the base catalog the renderer itself draws, whatever toolkit
|
|
6
|
+
* draws the rest: the language's elements (`if`/`else`, `foreach`,
|
|
7
|
+
* `match`/`case`/`default`, `fragment`, `suspense`/`fallback`/`error`, the
|
|
8
|
+
* the `Blok` element, the declarations, text) and the parts of a host's interface a blok may
|
|
9
|
+
* place (`ask`, `args`, `timeline`, ...), which the host supplies. Its
|
|
10
|
+
* functions are the vocabulary's (`functions/v2`), evaluated by the renderer.
|
|
9
11
|
*/
|
|
10
12
|
export const BASE_CATALOG_NAME = 'base';
|
|
11
|
-
export const BASE_CATALOG_VERSION =
|
|
13
|
+
export const BASE_CATALOG_VERSION = 4;
|
|
12
14
|
export const BASE_CATALOG_ID = `${BASE_CATALOG_NAME}@${BASE_CATALOG_VERSION}`;
|
|
13
15
|
|
|
14
16
|
export const baseBlokCatalog: BlokCatalog = createBlokCatalog(BASE_CATALOG_ID, controlBlokComponents);
|
|
@@ -8,7 +8,7 @@ afterEach(cleanup);
|
|
|
8
8
|
const render = (roots: unknown[], initialState?: unknown) =>
|
|
9
9
|
renderBlokDocument(testCatalog(), roots, initialState);
|
|
10
10
|
|
|
11
|
-
describe('links and media (ui
|
|
11
|
+
describe('links and media (the ui family)', () => {
|
|
12
12
|
it('renders a link, inline code and a heading', () => {
|
|
13
13
|
const {errors} = render([
|
|
14
14
|
{
|
|
@@ -33,7 +33,7 @@ describe('links and media (ui@1)', () => {
|
|
|
33
33
|
expect(screen.getByRole('heading', {level: 2}).textContent).toBe('Overview');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it('keeps raw html to the three containers html
|
|
36
|
+
it('keeps raw html to the three containers the html family has', () => {
|
|
37
37
|
expect(testCatalog().components.has('div')).toBe(true);
|
|
38
38
|
expect(testCatalog().components.has('p')).toBe(true);
|
|
39
39
|
expect(testCatalog().components.has('span')).toBe(true);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as z from 'zod';
|
|
3
3
|
import {
|
|
4
|
+
BlokItemKeyProvider,
|
|
4
5
|
BlokScopeProvider,
|
|
5
6
|
BlokSuspenseContext,
|
|
6
7
|
createBlokComponent,
|
|
@@ -16,13 +17,14 @@ import {
|
|
|
16
17
|
type BlokComponentNode,
|
|
17
18
|
type BlokSourceStatus,
|
|
18
19
|
type BlokScope,
|
|
20
|
+
type BlokObjectSchema,
|
|
19
21
|
type BlokSuspenseReporter,
|
|
20
22
|
} from '../runtime';
|
|
21
23
|
import {useBlokRunHost} from './run/host';
|
|
22
24
|
import {blokPlatform} from '../../platform';
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
* The language of base
|
|
27
|
+
* The language of the base catalog (`core/blok/spec/base_v2.json`): components that
|
|
26
28
|
* decide *whether* and *how often* their children render, rather than drawing
|
|
27
29
|
* anything themselves. Lowercase names are reserved for language.
|
|
28
30
|
*
|
|
@@ -53,6 +55,8 @@ const renderDeclaredChildren = (component: BlokComponentNode, buildChild: (id: s
|
|
|
53
55
|
/* -------------------------------------------------------------------------- */
|
|
54
56
|
|
|
55
57
|
const ForeachIteration = (props: {
|
|
58
|
+
/** The item's key, as its runtime ids carry it (`7`, `#2`). */
|
|
59
|
+
itemKey: string;
|
|
56
60
|
scopeName: string;
|
|
57
61
|
/** Absolute path of this item, when the items came from a data binding. */
|
|
58
62
|
itemPath?: string;
|
|
@@ -61,7 +65,7 @@ const ForeachIteration = (props: {
|
|
|
61
65
|
childIds: string[];
|
|
62
66
|
buildChild: (id: string, basePath?: string) => React.ReactNode;
|
|
63
67
|
}) => {
|
|
64
|
-
const {buildChild, childIds, item, itemPath, scopeName} = props;
|
|
68
|
+
const {buildChild, childIds, item, itemKey, itemPath, scopeName} = props;
|
|
65
69
|
|
|
66
70
|
// A path-backed item aliases to its path, so a bound control inside the loop
|
|
67
71
|
// writes the real backing list. Without a path the item is handed down by value.
|
|
@@ -69,11 +73,13 @@ const ForeachIteration = (props: {
|
|
|
69
73
|
const values = React.useMemo(() => (itemPath ? undefined : {[scopeName]: item}), [item, itemPath, scopeName]);
|
|
70
74
|
|
|
71
75
|
return (
|
|
72
|
-
<
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
<BlokItemKeyProvider itemKey={itemKey}>
|
|
77
|
+
<BlokScopeProvider aliases={aliases} values={values}>
|
|
78
|
+
{childIds.map(childId => (
|
|
79
|
+
<React.Fragment key={childId}>{buildChild(childId)}</React.Fragment>
|
|
80
|
+
))}
|
|
81
|
+
</BlokScopeProvider>
|
|
82
|
+
</BlokItemKeyProvider>
|
|
77
83
|
);
|
|
78
84
|
};
|
|
79
85
|
|
|
@@ -155,6 +161,7 @@ export const Foreach = createBlokComponent(
|
|
|
155
161
|
return (
|
|
156
162
|
<ForeachIteration
|
|
157
163
|
key={ids[index]}
|
|
164
|
+
itemKey={ids[index].slice(component.id.length + 1)}
|
|
158
165
|
scopeName={scopeName}
|
|
159
166
|
itemPath={itemPath(index)}
|
|
160
167
|
item={item}
|
|
@@ -228,6 +235,21 @@ export const Else = createBlokComponent(
|
|
|
228
235
|
({buildChild, component}) => renderDeclaredChildren(component, buildChild),
|
|
229
236
|
);
|
|
230
237
|
|
|
238
|
+
/** A run of text, as the parser stores it: drawn as it stands where no component took it (`runtime/text`). */
|
|
239
|
+
export const TextNode = createBlokComponent(
|
|
240
|
+
{
|
|
241
|
+
name: '#text',
|
|
242
|
+
schema: z
|
|
243
|
+
.object({value: z.unknown().describe('The text: a literal, or an expression whose value is shown as text.')})
|
|
244
|
+
.describe('A run of text between elements: what the parser stores it as (no element can be called this).'),
|
|
245
|
+
},
|
|
246
|
+
({component, schema}) => {
|
|
247
|
+
const blok = useBlok(component, schema);
|
|
248
|
+
const value = useValue(blok.value);
|
|
249
|
+
return <>{value === null || value === undefined ? null : typeof value === 'string' ? value : String(value)}</>;
|
|
250
|
+
},
|
|
251
|
+
);
|
|
252
|
+
|
|
231
253
|
export const Fragment = createBlokComponent(
|
|
232
254
|
{
|
|
233
255
|
name: 'fragment',
|
|
@@ -238,24 +260,116 @@ export const Fragment = createBlokComponent(
|
|
|
238
260
|
({buildChild, component}) => renderDeclaredChildren(component, buildChild),
|
|
239
261
|
);
|
|
240
262
|
|
|
241
|
-
/** What the host adds around a blok; read by the host off
|
|
263
|
+
/** What the host adds around a blok; read by the host off its `<Blok>`, the blok itself draws the same either way. */
|
|
242
264
|
export const chromeSchema = z
|
|
243
265
|
.enum(['auto', 'none'])
|
|
244
266
|
.optional()
|
|
245
267
|
.describe(
|
|
246
|
-
"What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
|
|
268
|
+
"What the host draws around the blok of its own (panel and scene): `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
|
|
247
269
|
);
|
|
248
270
|
|
|
249
|
-
|
|
271
|
+
const BLOK_COMPONENT = 'Blok';
|
|
272
|
+
const DECLARATIONS: ReadonlySet<string> = new Set(['local', 'query', 'subscription', 'var']);
|
|
273
|
+
|
|
274
|
+
/** The children of a node that draw: its declarations (`local`, `query`, `subscription`, `var`) left out. */
|
|
275
|
+
export const drawnChildren = (component: BlokComponentNode): BlokComponentNode[] =>
|
|
276
|
+
(component.children ?? []).filter(child => !DECLARATIONS.has(child.component));
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The one element every blok is (vocabulary `blok`). In a panel it lays its
|
|
280
|
+
* children out as a fragment does; in a scene or a logo it draws its one
|
|
281
|
+
* element (a `Scene` or `Space`, a `Logo`). Its declarations draw nothing.
|
|
282
|
+
*/
|
|
283
|
+
export const Blok = createBlokComponent(
|
|
250
284
|
{
|
|
251
|
-
name:
|
|
285
|
+
name: BLOK_COMPONENT,
|
|
252
286
|
acceptsChildren: true,
|
|
253
|
-
placement: {
|
|
287
|
+
placement: {notDownstreamOf: [BLOK_COMPONENT]},
|
|
254
288
|
schema: z
|
|
255
|
-
.object({
|
|
256
|
-
|
|
289
|
+
.object({
|
|
290
|
+
kind: z.enum(['agent', 'custom', 'task', 'action', 'assign']).describe('What the blok is: what it reads, and where it may be mounted.'),
|
|
291
|
+
context: z
|
|
292
|
+
.enum(['panel', 'scene', 'logo'])
|
|
293
|
+
.describe('What draws it: a panel (a flat rectangle the host lays out), a scene (a 3D view) or a logo (an SVG drawing).'),
|
|
294
|
+
catalog: z
|
|
295
|
+
.string()
|
|
296
|
+
.optional()
|
|
297
|
+
.describe('The catalog it is written for (the address it is published at, or the name of one registered in the organization); the base catalog when left out.'),
|
|
298
|
+
chrome: chromeSchema,
|
|
299
|
+
})
|
|
300
|
+
.describe(
|
|
301
|
+
"Every blok is one: it says its kind (what it reads, where it may be mounted), its context (what host draws it), the catalog it is written for and the host's chrome. A panel lays its children out as a fragment does; a scene holds one Scene or Space, a logo one Logo, besides its declarations.",
|
|
302
|
+
),
|
|
257
303
|
},
|
|
258
|
-
({buildChild, component}) =>
|
|
304
|
+
({buildChild, component}) => {
|
|
305
|
+
const context = component.props?.find(prop => prop.key === 'context')?.static_value;
|
|
306
|
+
const drawn = drawnChildren(component);
|
|
307
|
+
return renderNodes(context === 'scene' || context === 'logo' ? drawn.slice(0, 1) : drawn, buildChild);
|
|
308
|
+
},
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const declaration = <T extends BlokObjectSchema>(name: string, schema: T, acceptsChildren = false) =>
|
|
312
|
+
createBlokComponent({name, acceptsChildren, placement: {inheritsContext: true}, schema}, () => null);
|
|
313
|
+
|
|
314
|
+
/** `<local name="x" default={...} persist />`: draws nothing; its parent provides it to its children (`runtime/locals`). */
|
|
315
|
+
export const Local = declaration(
|
|
316
|
+
'local',
|
|
317
|
+
z
|
|
318
|
+
.object({
|
|
319
|
+
name: z.string().describe("The name the subtree reads it by, bare (never a reserved root)."),
|
|
320
|
+
default: z.unknown().optional().describe('The value it starts with: a literal.'),
|
|
321
|
+
kind: z.string().optional().describe('Its port kind (INT, FLOAT, STRING, BOOL, ENUM, DATE, QUANTITY, LIST, DICT, MODEL, STRUCTURE, ...) or ANY; inferred when left out.'),
|
|
322
|
+
identifier: z.string().optional().describe("A structure local's identifier (@mikro/image)."),
|
|
323
|
+
nullable: z.boolean().optional().describe('Whether it may be null.'),
|
|
324
|
+
choices: z.unknown().optional().describe("An ENUM local's choices: [{value, label}, ...]."),
|
|
325
|
+
children: z.unknown().optional().describe("A LIST, DICT or MODEL local's child ports, as ports."),
|
|
326
|
+
label: z.string().optional().describe('What a form shows it as.'),
|
|
327
|
+
description: z.string().optional().describe('What it is for.'),
|
|
328
|
+
persist: z.boolean().optional().describe('Remember the last input on this device (never on a server).'),
|
|
329
|
+
like: z.string().optional().describe("Take the port of an action's argument: self.<action>.<arg> or deps.<key>.<action>.<arg>."),
|
|
330
|
+
})
|
|
331
|
+
.describe("Declares a local: form state controls write through bind, read bare in its parent's subtree; inside a foreach, one per item. It comes first among its parent's children and draws nothing."),
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
/** `<query name service document>`: draws nothing; the host runs it (`declaredQueries`). */
|
|
335
|
+
export const Query = declaration(
|
|
336
|
+
'query',
|
|
337
|
+
z
|
|
338
|
+
.object({
|
|
339
|
+
name: z.string().describe('Its name: read as queries.<name>.'),
|
|
340
|
+
service: z.string().describe('The service it runs on, by key (mikro).'),
|
|
341
|
+
document: z.string().describe('One GraphQL query operation, never a mutation.'),
|
|
342
|
+
poll: z.number().optional().describe('Also re-run every this many seconds.'),
|
|
343
|
+
more: z.string().optional().describe('The list field of its result new pages append to (queries.<name>.fetch_more).'),
|
|
344
|
+
})
|
|
345
|
+
.describe('Declares a read, queries.<name>: one GraphQL query on a service, re-run when its variables (its <var> children) change. A child of <Blok>; draws nothing.'),
|
|
346
|
+
true,
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
/** `<subscription name service document>`: draws nothing; the host runs it (`declaredSubscriptions`). */
|
|
350
|
+
export const Subscription = declaration(
|
|
351
|
+
'subscription',
|
|
352
|
+
z
|
|
353
|
+
.object({
|
|
354
|
+
name: z.string().describe('Its name: read as subscriptions.<name>.'),
|
|
355
|
+
service: z.string().describe('The service it runs on, by key.'),
|
|
356
|
+
document: z.string().describe('One GraphQL subscription operation.'),
|
|
357
|
+
keep: z.number().optional().describe('Keep the last this many payloads as a list; the latest only when absent.'),
|
|
358
|
+
history: z.string().optional().describe('A declared query to replay from while travelling.'),
|
|
359
|
+
})
|
|
360
|
+
.describe('Declares a stream, subscriptions.<name>: one GraphQL subscription on a service, re-subscribed when its variables (its <var> children) change. A child of <Blok>; draws nothing.'),
|
|
361
|
+
true,
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
/** `<var key value>`: one variable of its query or subscription. */
|
|
365
|
+
export const Var = declaration(
|
|
366
|
+
'var',
|
|
367
|
+
z
|
|
368
|
+
.object({
|
|
369
|
+
key: z.string().describe("The variable's name in the document."),
|
|
370
|
+
value: z.unknown().optional().describe('Its value.'),
|
|
371
|
+
})
|
|
372
|
+
.describe('One variable of its query or subscription: an expression over args, blok-level locals and agents, or a literal.'),
|
|
259
373
|
);
|
|
260
374
|
|
|
261
375
|
/* -------------------------------------------------------------------------- */
|
|
@@ -343,7 +457,7 @@ const DomHidden = ({hidden, children}: {hidden: boolean; children?: React.ReactN
|
|
|
343
457
|
/** Outside html (a scene, a logo) nothing can hold a box: hidden is not drawn. In html, the platform's (a native view), or a DOM `div`. */
|
|
344
458
|
const Hidden = ({hidden, children}: {hidden: boolean; children: React.ReactNode}) => {
|
|
345
459
|
const draw = useBlokDrawContext();
|
|
346
|
-
if (draw !== '
|
|
460
|
+
if (draw !== 'panel') return hidden ? null : <>{children}</>;
|
|
347
461
|
const Primitive = blokPlatform().primitives.Hidden ?? DomHidden;
|
|
348
462
|
return <Primitive hidden={hidden}>{children}</Primitive>;
|
|
349
463
|
};
|
|
@@ -540,11 +654,16 @@ export const Timeline = createBlokComponent(
|
|
|
540
654
|
);
|
|
541
655
|
|
|
542
656
|
export const controlBlokComponents = [
|
|
657
|
+
TextNode,
|
|
543
658
|
Foreach,
|
|
544
659
|
If,
|
|
545
660
|
Else,
|
|
546
661
|
Fragment,
|
|
547
|
-
|
|
662
|
+
Blok,
|
|
663
|
+
Local,
|
|
664
|
+
Query,
|
|
665
|
+
Subscription,
|
|
666
|
+
Var,
|
|
548
667
|
Match,
|
|
549
668
|
Case,
|
|
550
669
|
Default,
|
|
@@ -5,7 +5,7 @@ import {foreachItemIds} from './control';
|
|
|
5
5
|
import {renderBsx, testCatalog} from './testing';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* The language of base
|
|
8
|
+
* The language of the base catalog rendered end to end, from BSX: branches, loops, the
|
|
9
9
|
* `when` guard, and the async model (suspense, fallback, error, stale).
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -8,8 +8,8 @@ import {renderContent, textPresentationClasses, useTextPresentationProps} from '
|
|
|
8
8
|
type Contracts = typeof htmlContracts;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* ui
|
|
12
|
-
* part of the language; html
|
|
11
|
+
* The ui family's links and media: `Link`, `Image` and `Code`. Raw HTML tags are not
|
|
12
|
+
* part of the language; the html family keeps only `div`, `p` and `span`, the
|
|
13
13
|
* containers that translate directly to React Native (View, Text).
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -13,7 +13,7 @@ import {typographyRenders} from './typography';
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The shadcn/HTML/SVG renders, by component name: what `@arkitektio/bsx/shadcn`
|
|
16
|
-
* implements ui
|
|
16
|
+
* implements the ui family, the html family, the logo family and the shadcn family with. Grouped by family as the
|
|
17
17
|
* contracts are (`catalogs/parts`).
|
|
18
18
|
*/
|
|
19
19
|
export const domRenders = {
|
|
@@ -166,6 +166,33 @@ const ScrollAreaRender: BlokRender<Contracts['ScrollArea']> = ({buildChild, comp
|
|
|
166
166
|
);
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
+
/**
|
|
170
|
+
* A long list. Its rows are the children a `foreach` draws straight into it:
|
|
171
|
+
* each is left unlaid and unpainted until it scrolls near the view
|
|
172
|
+
* (`content-visibility`), so a list of thousands costs what a screenful does
|
|
173
|
+
* to draw. The rows are still mounted, as a renderer without a window of its
|
|
174
|
+
* own would mount them.
|
|
175
|
+
*/
|
|
176
|
+
const ListRender: BlokRender<Contracts['List']> = ({buildChild, component, schema}) => {
|
|
177
|
+
const blok = useBlok(component, schema);
|
|
178
|
+
const children = useValue(blok.children);
|
|
179
|
+
const className = useValue(blok.className);
|
|
180
|
+
const height = useValue(blok.height);
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<div
|
|
184
|
+
className={cn(
|
|
185
|
+
'flex min-h-0 min-w-0 flex-col overflow-y-auto [&>*]:shrink-0 [&>*]:[contain-intrinsic-size:auto_2.5rem] [&>*]:[content-visibility:auto]',
|
|
186
|
+
!height && 'h-full',
|
|
187
|
+
className,
|
|
188
|
+
)}
|
|
189
|
+
style={{height}}
|
|
190
|
+
>
|
|
191
|
+
{renderChildList(children, buildChild)}
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
169
196
|
const ResizableRender: BlokRender<Contracts['Resizable']> = ({buildChild, component, schema}) => {
|
|
170
197
|
const blok = useBlok(component, schema);
|
|
171
198
|
const children = useValue(blok.children);
|
|
@@ -293,6 +320,7 @@ export const layoutRenders = {
|
|
|
293
320
|
Separator: SeparatorRender,
|
|
294
321
|
AspectRatio: AspectRatioRender,
|
|
295
322
|
ScrollArea: ScrollAreaRender,
|
|
323
|
+
List: ListRender,
|
|
296
324
|
Resizable: ResizableRender,
|
|
297
325
|
ResizablePanel: ResizablePanelRender,
|
|
298
326
|
ResizableHandle: ResizableHandleRender,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
type Contracts = typeof logoContracts;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* The `logo
|
|
25
|
+
* The `logo` family drawn: see the contract for the language. A node's id is
|
|
26
26
|
* the BSX `id`, and that is what a gradient or a clip path is referenced by.
|
|
27
27
|
* Ids are made unique per drawing, so two logos on one page never share a
|
|
28
28
|
* gradient.
|
|
@@ -146,7 +146,7 @@ const SvgNodeError = ({componentId, title, detail}: BlokNodeErrorProps) => (
|
|
|
146
146
|
);
|
|
147
147
|
|
|
148
148
|
/** A drawing's root: an `<svg>` whose shapes paint with the pens. */
|
|
149
|
-
const LogoRootRender: BlokRender<Contracts['
|
|
149
|
+
const LogoRootRender: BlokRender<Contracts['Logo']> = args => {
|
|
150
150
|
const blok = useBlok(args.component, args.schema);
|
|
151
151
|
const viewBox = useValue(blok.viewBox);
|
|
152
152
|
const width = useValue(blok.width);
|
|
@@ -265,10 +265,9 @@ const ClipPathRender: BlokRender<Contracts['ClipPath']> = args => {
|
|
|
265
265
|
);
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
-
/** The `logo
|
|
268
|
+
/** The `logo` family: the root, seven shapes, text, and what shapes reference. */
|
|
269
269
|
export const logoRenders = {
|
|
270
|
-
|
|
271
|
-
ActionLogo: LogoRootRender,
|
|
270
|
+
Logo: LogoRootRender,
|
|
272
271
|
Path: shapeRender('path', shapeGeometry.Path),
|
|
273
272
|
Circle: shapeRender('circle', shapeGeometry.Circle),
|
|
274
273
|
Ellipse: shapeRender('ellipse', shapeGeometry.Ellipse),
|