@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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {baseCatalog} from '../../spec/catalogs';
|
|
2
|
+
import type {BlokCatalog} from './functions';
|
|
3
|
+
import {isRecord} from './utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Text as a renderer draws it.
|
|
7
|
+
*
|
|
8
|
+
* The parser stores every run of text as a `#text` node under the component
|
|
9
|
+
* it stands in, and knows no catalog. What a component does with its text is
|
|
10
|
+
* said here, by the renderer, which has the catalog:
|
|
11
|
+
*
|
|
12
|
+
* - A component with a `textProp` whose one child is a run of text takes that
|
|
13
|
+
* text as the prop (`<Button>Go</Button>` is a `Button` with `label="Go"`).
|
|
14
|
+
* - Any other run of text becomes the component text is drawn with in that
|
|
15
|
+
* place: a `span` inside a plain html element, a `Text` anywhere else.
|
|
16
|
+
*
|
|
17
|
+
* A tree stored before text was a node holds the prop, or the `Text`/`span`,
|
|
18
|
+
* already: it passes through as it is. A renderer on another toolkit (React
|
|
19
|
+
* Native) uses the same pass, so every run of text arrives as a component it
|
|
20
|
+
* can wrap.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** The node a run of text is stored as (`bsx/parse`'s `TEXT_NODE`). */
|
|
24
|
+
export const BLOK_TEXT_NODE = '#text';
|
|
25
|
+
/** The prop of a text node that holds its text. */
|
|
26
|
+
export const BLOK_TEXT_VALUE = 'value';
|
|
27
|
+
/** What a run of text is drawn with among other children, and inside a plain html element. */
|
|
28
|
+
const LOOSE_TEXT = 'Text';
|
|
29
|
+
const LOOSE_HTML_TEXT = 'span';
|
|
30
|
+
/** The prop `Text` and `span` take their text as. */
|
|
31
|
+
const LOOSE_TEXT_PROP = 'text';
|
|
32
|
+
|
|
33
|
+
let groups: Map<string, string | null> | null = null;
|
|
34
|
+
|
|
35
|
+
/** The family of a base component (`language`, `html`, ...), by name. */
|
|
36
|
+
const groupOf = (component: string): string | null | undefined => {
|
|
37
|
+
groups ??= new Map(baseCatalog().components.map(entry => [entry.name, entry.group]));
|
|
38
|
+
return groups.get(component);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type RawNode = Record<string, unknown> & {component: string};
|
|
42
|
+
|
|
43
|
+
const isNode = (value: unknown): value is RawNode => isRecord(value) && !Array.isArray(value) && typeof value.component === 'string';
|
|
44
|
+
const isTextNode = (value: unknown): value is RawNode => isNode(value) && value.component === BLOK_TEXT_NODE;
|
|
45
|
+
|
|
46
|
+
/** The one prop of a text node, under another key; null when the node holds anything else. */
|
|
47
|
+
const valueAs = (node: RawNode, key: string): Record<string, unknown> | null => {
|
|
48
|
+
const props = Array.isArray(node.props) ? node.props : [];
|
|
49
|
+
const value = props.length === 1 && isRecord(props[0]) && props[0].key === BLOK_TEXT_VALUE ? props[0] : null;
|
|
50
|
+
return value ? {...value, key} : null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* `raw` with every run of text made what `catalog` draws it as. Nodes without
|
|
55
|
+
* text among their children are returned as they are (the same object).
|
|
56
|
+
*/
|
|
57
|
+
export const lowerBlokText = (raw: unknown, catalog: BlokCatalog, looseText: string = LOOSE_TEXT): unknown => {
|
|
58
|
+
if (!isNode(raw)) return raw;
|
|
59
|
+
const group = groupOf(raw.component);
|
|
60
|
+
// The component loose text becomes here, from the nearest ancestor that is no language element.
|
|
61
|
+
const loose = group === 'html' ? LOOSE_HTML_TEXT : group === 'language' ? looseText : LOOSE_TEXT;
|
|
62
|
+
const children = Array.isArray(raw.children) ? raw.children : null;
|
|
63
|
+
if (!children) return raw;
|
|
64
|
+
const texts = children.filter(isTextNode);
|
|
65
|
+
if (texts.length === 0) {
|
|
66
|
+
const lowered = children.map(child => lowerBlokText(child, catalog, loose));
|
|
67
|
+
return lowered.some((child, index) => child !== children[index]) ? {...raw, children: lowered} : raw;
|
|
68
|
+
}
|
|
69
|
+
const props = Array.isArray(raw.props) ? raw.props : [];
|
|
70
|
+
const textProp = catalog.components.get(raw.component)?.textProp;
|
|
71
|
+
if (textProp && children.length === 1 && !props.some(prop => isRecord(prop) && prop.key === textProp)) {
|
|
72
|
+
const value = valueAs(texts[0], textProp);
|
|
73
|
+
if (value) {
|
|
74
|
+
const {children: _children, ...rest} = raw;
|
|
75
|
+
return {...rest, props: [...props, value]};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const drawnWith = catalog.components.has(loose) ? loose : null;
|
|
79
|
+
return {
|
|
80
|
+
...raw,
|
|
81
|
+
children: children.map(child => {
|
|
82
|
+
if (!isTextNode(child)) return lowerBlokText(child, catalog, loose);
|
|
83
|
+
const value = drawnWith ? valueAs(child, LOOSE_TEXT_PROP) : null;
|
|
84
|
+
// A catalog without it draws the text node itself (the language's own `#text`).
|
|
85
|
+
return value ? {id: child.id, component: drawnWith, props: [value]} : child;
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import {BlokComponentRenderer, BlokNodeError} from './components';
|
|
3
3
|
import type {BlokCatalog} from './functions';
|
|
4
|
+
import {BlokLocalsScope, localChildren} from './locals';
|
|
4
5
|
import {BlokScopeProvider} from './scope';
|
|
5
6
|
import type {BlokComponentNode} from './types';
|
|
6
7
|
|
|
@@ -64,13 +65,24 @@ const BlokNodeInner = ({id, basePath}: BlokNodeProps) => {
|
|
|
64
65
|
|
|
65
66
|
const nextTrail = React.useMemo(() => [...trail, id], [trail, id]);
|
|
66
67
|
|
|
68
|
+
// The node's `<local>` children are in scope in all of its children: each
|
|
69
|
+
// child is built inside them, so a child a foreach builds per item (inside
|
|
70
|
+
// the item's scope) gets the item's own values.
|
|
71
|
+
const node = tree.nodes.get(id)?.node;
|
|
72
|
+
const locals = React.useMemo(() => (node ? localChildren(node) : []), [node]);
|
|
73
|
+
|
|
67
74
|
// `buildChild` never closes over the trail or the tree — a child reads both
|
|
68
75
|
// from context — so its identity is stable for the life of the node.
|
|
69
76
|
const buildChild = React.useCallback(
|
|
70
|
-
(childId: string, childBasePath?: string) =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
(childId: string, childBasePath?: string) =>
|
|
78
|
+
locals.length ? (
|
|
79
|
+
<BlokLocalsScope locals={locals}>
|
|
80
|
+
<BlokNode id={childId} basePath={childBasePath} />
|
|
81
|
+
</BlokLocalsScope>
|
|
82
|
+
) : (
|
|
83
|
+
<BlokNode id={childId} basePath={childBasePath} />
|
|
84
|
+
),
|
|
85
|
+
[locals],
|
|
74
86
|
);
|
|
75
87
|
|
|
76
88
|
if (trail.includes(id)) {
|
|
@@ -194,6 +194,11 @@ export type BlokScope = {
|
|
|
194
194
|
aliases: Readonly<Record<string, string>>;
|
|
195
195
|
values: Readonly<Record<string, unknown>>;
|
|
196
196
|
basePath?: string;
|
|
197
|
+
/**
|
|
198
|
+
* What an aliased path reads while nothing was written there yet, by the
|
|
199
|
+
* alias' absolute path: a `<local>`'s default (`runtime/locals`).
|
|
200
|
+
*/
|
|
201
|
+
defaults?: Readonly<Record<string, unknown>>;
|
|
197
202
|
};
|
|
198
203
|
|
|
199
204
|
/**
|
|
@@ -236,8 +241,8 @@ export type BlokRuntimeContext = {
|
|
|
236
241
|
initialDataModel: unknown;
|
|
237
242
|
dataModel: unknown;
|
|
238
243
|
runtimePathValues: Record<string, unknown>;
|
|
239
|
-
/**
|
|
240
|
-
|
|
244
|
+
/** The `<local>` node ids whose values a reset keeps (every item's, in a foreach): the locals the host keeps between openings. */
|
|
245
|
+
keptLocals: ReadonlySet<string>;
|
|
241
246
|
/**
|
|
242
247
|
* The status of each source, by the data-model path it is read under
|
|
243
248
|
* (`deps.robot.arm`, `queries.cells.value`, `args`). A read below a path
|
|
@@ -271,7 +276,7 @@ export type BlokRuntimeContext = {
|
|
|
271
276
|
lockedActions: BlokLockedActions;
|
|
272
277
|
setInitialDataModel: (dataModel: unknown) => void;
|
|
273
278
|
resetRuntimeValues: () => void;
|
|
274
|
-
|
|
279
|
+
setKeptLocals: (keptLocals: ReadonlySet<string>) => void;
|
|
275
280
|
setRuntimeValue: (path: string, value: unknown) => void;
|
|
276
281
|
clearRuntimeValue: (path: string) => void;
|
|
277
282
|
setAgentMappingStateUpdates: (updates: BlokAgentMappingStateUpdates) => void;
|
package/src/runtime.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from './renderer/runtime';
|
|
|
3
3
|
export * from './renderer/functions';
|
|
4
4
|
export * from './renderer/declarations';
|
|
5
5
|
export * from './renderer/persist';
|
|
6
|
-
export * from './renderer/modules';
|
|
7
6
|
export * from './renderer/baseCatalog';
|
|
8
7
|
export * from './renderer/declare';
|
|
9
8
|
export * from './cache/keyedStore';
|
package/src/scene.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @arkitektio/bsx/scene: scene
|
|
1
|
+
// @arkitektio/bsx/scene: the scene family drawn with three, @react-three/fiber and drei (opt-in: an app passes
|
|
2
2
|
// threeScene to declareBlokUi), and the scene and run hosts the renderer mounts.
|
|
3
3
|
import {sceneCatalog} from './catalogs/index';
|
|
4
4
|
import {runRenders} from './renderer/bloks/run';
|
|
@@ -10,7 +10,7 @@ export * from './renderer/bloks/run';
|
|
|
10
10
|
|
|
11
11
|
const renders = {...sceneRenders, ...runRenders};
|
|
12
12
|
|
|
13
|
-
/** scene
|
|
13
|
+
/** the scene family, drawn with three. */
|
|
14
14
|
export const threeScene = implementBlokCatalog(sceneCatalog, {
|
|
15
15
|
Animate: renders.Animate,
|
|
16
16
|
Attach: renders.Attach,
|
package/src/shadcn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @arkitektio/bsx/shadcn: a reference implementation of ui
|
|
1
|
+
// @arkitektio/bsx/shadcn: a reference implementation of the ui family, the html family, the logo family and the shadcn family in shadcn/ui
|
|
2
2
|
// (radix, Tailwind) and SVG. Opt-in: an app passes these to declareBlokUi, or spreads one and draws over a part.
|
|
3
3
|
// The app's Tailwind must see this package's classes: @source on node_modules/@arkitektio/bsx/dist.
|
|
4
4
|
import {htmlCatalog, logoCatalog, shadcnCatalog, uiCatalog} from './catalogs/index';
|
|
@@ -7,7 +7,7 @@ import {implementBlokCatalog} from './renderer/runtime/catalog';
|
|
|
7
7
|
|
|
8
8
|
export {domRenders};
|
|
9
9
|
|
|
10
|
-
/** ui
|
|
10
|
+
/** the ui family, drawn with shadcn/ui. */
|
|
11
11
|
export const shadcnUiRenders = {
|
|
12
12
|
Accordion: domRenders.Accordion,
|
|
13
13
|
AccordionContent: domRenders.AccordionContent,
|
|
@@ -52,6 +52,7 @@ export const shadcnUiRenders = {
|
|
|
52
52
|
RadioGroup: domRenders.RadioGroup,
|
|
53
53
|
RadioGroupItem: domRenders.RadioGroupItem,
|
|
54
54
|
Row: domRenders.Row,
|
|
55
|
+
List: domRenders.List,
|
|
55
56
|
ScrollArea: domRenders.ScrollArea,
|
|
56
57
|
Select: domRenders.Select,
|
|
57
58
|
SelectContent: domRenders.SelectContent,
|
|
@@ -93,7 +94,7 @@ export const shadcnUiRenders = {
|
|
|
93
94
|
|
|
94
95
|
export const shadcnUi = implementBlokCatalog(uiCatalog, shadcnUiRenders);
|
|
95
96
|
|
|
96
|
-
/** html
|
|
97
|
+
/** the html family, drawn with shadcn/ui. */
|
|
97
98
|
export const shadcnHtmlRenders = {
|
|
98
99
|
div: domRenders.div,
|
|
99
100
|
p: domRenders.p,
|
|
@@ -102,10 +103,8 @@ export const shadcnHtmlRenders = {
|
|
|
102
103
|
|
|
103
104
|
export const shadcnHtml = implementBlokCatalog(htmlCatalog, shadcnHtmlRenders);
|
|
104
105
|
|
|
105
|
-
/** logo
|
|
106
|
+
/** the logo family, drawn with shadcn/ui. */
|
|
106
107
|
export const shadcnLogoRenders = {
|
|
107
|
-
ActionLogo: domRenders.ActionLogo,
|
|
108
|
-
AgentLogo: domRenders.AgentLogo,
|
|
109
108
|
Circle: domRenders.Circle,
|
|
110
109
|
ClipPath: domRenders.ClipPath,
|
|
111
110
|
Defs: domRenders.Defs,
|
|
@@ -113,6 +112,7 @@ export const shadcnLogoRenders = {
|
|
|
113
112
|
G: domRenders.G,
|
|
114
113
|
Line: domRenders.Line,
|
|
115
114
|
LinearGradient: domRenders.LinearGradient,
|
|
115
|
+
Logo: domRenders.Logo,
|
|
116
116
|
Path: domRenders.Path,
|
|
117
117
|
Polygon: domRenders.Polygon,
|
|
118
118
|
Polyline: domRenders.Polyline,
|
|
@@ -124,7 +124,7 @@ export const shadcnLogoRenders = {
|
|
|
124
124
|
|
|
125
125
|
export const shadcnLogo = implementBlokCatalog(logoCatalog, shadcnLogoRenders);
|
|
126
126
|
|
|
127
|
-
/** shadcn
|
|
127
|
+
/** the shadcn family, drawn with shadcn/ui. */
|
|
128
128
|
export const shadcnExtrasRenders = {
|
|
129
129
|
AlertDialog: domRenders.AlertDialog,
|
|
130
130
|
AlertDialogAction: domRenders.AlertDialogAction,
|