@arkitektio/bsx 6.8.0 → 7.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/dist/bsx/declared.d.ts +25 -0
- package/dist/bsx/declared.d.ts.map +1 -1
- package/dist/bsx/declared.js +59 -0
- package/dist/bsx/declared.js.map +1 -1
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +4 -2
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +17 -12
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +139 -37
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/index.d.ts +191 -98
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/parts/data.d.ts +2 -2
- package/dist/catalogs/parts/data.d.ts.map +1 -1
- package/dist/catalogs/parts/data.js +2 -3
- package/dist/catalogs/parts/data.js.map +1 -1
- package/dist/catalogs/parts/feedback.d.ts +6 -6
- package/dist/catalogs/parts/forms.d.ts +8 -8
- package/dist/catalogs/parts/icons.d.ts +4 -4
- package/dist/catalogs/parts/index.d.ts +48 -48
- package/dist/catalogs/parts/navigation.d.ts +8 -8
- package/dist/catalogs/parts/overlays.d.ts +22 -22
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +4 -5
- package/dist/catalogs/parts/run.js.map +1 -1
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +7 -14
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/structure.d.ts.map +1 -1
- package/dist/catalogs/parts/structure.js +2 -3
- package/dist/catalogs/parts/structure.js.map +1 -1
- package/dist/catalogs/parts/toast.d.ts.map +1 -1
- package/dist/catalogs/parts/toast.js +2 -1
- package/dist/catalogs/parts/toast.js.map +1 -1
- package/dist/catalogs/props.d.ts +23 -0
- package/dist/catalogs/props.d.ts.map +1 -1
- package/dist/catalogs/props.js +56 -4
- package/dist/catalogs/props.js.map +1 -1
- package/dist/catalogs/scene.d.ts +134 -127
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +5 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/catalogs/shadcn.d.ts +79 -41
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +13 -13
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/structure.d.ts +9 -2
- package/dist/catalogs/structure.d.ts.map +1 -1
- package/dist/catalogs/structure.js +1 -1
- package/dist/catalogs/structure.js.map +1 -1
- package/dist/catalogs/ui.d.ts +935 -892
- package/dist/catalogs/ui.d.ts.map +1 -1
- package/dist/catalogs/ui.js +16 -14
- package/dist/catalogs/ui.js.map +1 -1
- package/dist/catalogs/zodToPort.d.ts +9 -0
- package/dist/catalogs/zodToPort.d.ts.map +1 -0
- package/dist/catalogs/zodToPort.js +156 -0
- package/dist/catalogs/zodToPort.js.map +1 -0
- package/dist/catalogs.d.ts +4 -1
- package/dist/catalogs.d.ts.map +1 -1
- package/dist/catalogs.js +3 -0
- package/dist/catalogs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/ports/rekuest.d.ts +6 -0
- package/dist/ports/rekuest.d.ts.map +1 -1
- package/dist/ports/rekuest.js +6 -0
- package/dist/ports/rekuest.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +7 -1
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +20 -2
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +2 -2
- package/dist/renderer/bloks/feedback.d.ts +6 -6
- package/dist/renderer/bloks/forms.d.ts +8 -8
- package/dist/renderer/bloks/icons.d.ts +2 -2
- package/dist/renderer/bloks/index.d.ts +48 -48
- package/dist/renderer/bloks/navigation.d.ts +8 -8
- package/dist/renderer/bloks/overlays.d.ts +22 -22
- package/dist/renderer/runtime/components.d.ts +6 -8
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +5 -12
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +25 -89
- 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 +3 -1
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/schemas.d.ts +8 -6
- package/dist/renderer/runtime/schemas.d.ts.map +1 -1
- package/dist/renderer/runtime/schemas.js +40 -16
- package/dist/renderer/runtime/schemas.js.map +1 -1
- package/dist/shadcn.d.ts +48 -48
- package/dist/spec/bsx_v2.json +1421 -19
- package/dist/spec/catalogs/base@4.json +18738 -5273
- package/dist/spec/catalogs/base@4.json.js +18738 -5273
- package/dist/spec/catalogs/orkestrator@1.json +532 -126
- package/dist/spec/catalogs/orkestrator@1.json.js +532 -126
- package/dist/spec/catalogs.d.ts +3 -11
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +13 -11
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/fit.d.ts +21 -0
- package/dist/spec/fit.d.ts.map +1 -0
- package/dist/spec/fit.js +114 -0
- package/dist/spec/fit.js.map +1 -0
- package/dist/spec/ports.d.ts +56 -0
- package/dist/spec/ports.d.ts.map +1 -0
- package/dist/spec/ports.js +174 -0
- package/dist/spec/ports.js.map +1 -0
- package/dist/spec/vocabulary.json +12 -5
- package/dist/spec/vocabulary.json.js +12 -5
- package/package.json +1 -1
- package/src/bsx/declared.ts +60 -0
- package/src/bsx/infer.test.ts +1 -1
- package/src/bsx/infer.ts +4 -2
- package/src/bsx/language.ts +16 -11
- package/src/bsx/logo.test.ts +47 -0
- package/src/bsx/references.ts +170 -39
- package/src/catalogs/parts/data.ts +3 -2
- package/src/catalogs/parts/run.ts +9 -7
- package/src/catalogs/parts/scene.ts +7 -14
- package/src/catalogs/parts/structure.ts +2 -3
- package/src/catalogs/parts/toast.ts +5 -1
- package/src/catalogs/props.ts +64 -4
- package/src/catalogs/scene.ts +5 -3
- package/src/catalogs/shadcn.ts +13 -13
- package/src/catalogs/structure.ts +1 -1
- package/src/catalogs/ui.ts +16 -14
- package/src/catalogs/zodToPort.test.ts +96 -0
- package/src/catalogs/zodToPort.ts +177 -0
- package/src/catalogs.ts +4 -1
- package/src/index.ts +2 -0
- package/src/ports/rekuest.ts +6 -0
- package/src/renderer/bloks/control.tsx +26 -2
- package/src/renderer/runtime/catalog.test.ts +12 -8
- package/src/renderer/runtime/components.tsx +5 -8
- package/src/renderer/runtime/describe.ts +25 -100
- package/src/renderer/runtime/hooks.ts +3 -1
- package/src/renderer/runtime/schemas.ts +51 -17
- package/src/spec/bsx_v2.json +1421 -19
- package/src/spec/catalogs/base@4.json +18738 -5273
- package/src/spec/catalogs/orkestrator@1.json +532 -126
- package/src/spec/catalogs.ts +14 -19
- package/src/spec/fit.test.ts +65 -0
- package/src/spec/fit.ts +114 -0
- package/src/spec/ports.ts +172 -0
- package/src/spec/spec.test.ts +5 -2
- package/src/spec/vocabulary.json +12 -5
package/src/catalogs/shadcn.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const shadcnCatalog = defineBlokCatalog({
|
|
|
7
7
|
partOf: BASE_CATALOG_REF,
|
|
8
8
|
description: "The shadcn families beyond the ui family (alert dialogs, sheets, drawers, menus, calendars, carousels, resizable panels, bento grids ...), charts and the raw inspector.",
|
|
9
9
|
components: {
|
|
10
|
-
AlertDialog: {...parts.AlertDialog, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
10
|
+
AlertDialog: {...parts.AlertDialog, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
11
11
|
AlertDialogAction: parts.AlertDialogAction,
|
|
12
12
|
AlertDialogCancel: parts.AlertDialogCancel,
|
|
13
13
|
AlertDialogContent: parts.AlertDialogContent,
|
|
@@ -24,42 +24,42 @@ export const shadcnCatalog = defineBlokCatalog({
|
|
|
24
24
|
BreadcrumbItem: parts.BreadcrumbItem,
|
|
25
25
|
BreadcrumbSeparator: parts.BreadcrumbSeparator,
|
|
26
26
|
ButtonGroup: parts.ButtonGroup,
|
|
27
|
-
Calendar: {...parts.Calendar, events: {onChange: [{key: "value", kind: "STRING", description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: "STRING"}},
|
|
27
|
+
Calendar: {...parts.Calendar, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
28
28
|
Carousel: parts.Carousel,
|
|
29
|
-
Combobox: {...parts.Combobox, events: {onChange: [{key: "value", kind: "STRING", description: "The value picked."}]}, bindKinds: {bind: "STRING"}},
|
|
30
|
-
DatePicker: {...parts.DatePicker, events: {onChange: [{key: "value", kind: "STRING", description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: "STRING"}},
|
|
29
|
+
Combobox: {...parts.Combobox, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The value picked."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
30
|
+
DatePicker: {...parts.DatePicker, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
31
31
|
CarouselItem: parts.CarouselItem,
|
|
32
32
|
Chart: parts.Chart,
|
|
33
|
-
Collapsible: {...parts.Collapsible, events: {onChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
33
|
+
Collapsible: {...parts.Collapsible, events: {onChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
34
34
|
CollapsibleContent: parts.CollapsibleContent,
|
|
35
35
|
CollapsibleTrigger: parts.CollapsibleTrigger,
|
|
36
|
-
ContextMenu: {...parts.ContextMenu, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
37
|
-
ContextMenuCheckboxItem: {...parts.ContextMenuCheckboxItem, events: {onChange: [{key: "value", kind: "BOOL", description: "The new checked state."}]}, bindKinds: {bind: "BOOL"}},
|
|
36
|
+
ContextMenu: {...parts.ContextMenu, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
37
|
+
ContextMenuCheckboxItem: {...parts.ContextMenuCheckboxItem, events: {onChange: [{key: "value", port: {kind: "BOOL"}, description: "The new checked state."}]}, bindKinds: {bind: {kind: "BOOL"}}},
|
|
38
38
|
ContextMenuContent: parts.ContextMenuContent,
|
|
39
39
|
ContextMenuItem: parts.ContextMenuItem,
|
|
40
40
|
ContextMenuLabel: parts.ContextMenuLabel,
|
|
41
41
|
ContextMenuSeparator: parts.ContextMenuSeparator,
|
|
42
42
|
ContextMenuTrigger: parts.ContextMenuTrigger,
|
|
43
|
-
Drawer: {...parts.Drawer, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
43
|
+
Drawer: {...parts.Drawer, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
44
44
|
DrawerContent: parts.DrawerContent,
|
|
45
45
|
DrawerDescription: parts.DrawerDescription,
|
|
46
46
|
DrawerFooter: parts.DrawerFooter,
|
|
47
47
|
DrawerHeader: parts.DrawerHeader,
|
|
48
48
|
DrawerTitle: parts.DrawerTitle,
|
|
49
49
|
DrawerTrigger: parts.DrawerTrigger,
|
|
50
|
-
DropdownMenu: {...parts.DropdownMenu, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
51
|
-
DropdownMenuCheckboxItem: {...parts.DropdownMenuCheckboxItem, events: {onChange: [{key: "value", kind: "BOOL", description: "The new checked state."}]}, bindKinds: {bind: "BOOL"}},
|
|
50
|
+
DropdownMenu: {...parts.DropdownMenu, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
51
|
+
DropdownMenuCheckboxItem: {...parts.DropdownMenuCheckboxItem, events: {onChange: [{key: "value", port: {kind: "BOOL"}, description: "The new checked state."}]}, bindKinds: {bind: {kind: "BOOL"}}},
|
|
52
52
|
DropdownMenuContent: parts.DropdownMenuContent,
|
|
53
53
|
DropdownMenuItem: parts.DropdownMenuItem,
|
|
54
54
|
DropdownMenuLabel: parts.DropdownMenuLabel,
|
|
55
55
|
DropdownMenuSeparator: parts.DropdownMenuSeparator,
|
|
56
56
|
DropdownMenuTrigger: parts.DropdownMenuTrigger,
|
|
57
|
-
HoverCard: {...parts.HoverCard, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
57
|
+
HoverCard: {...parts.HoverCard, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
58
58
|
HoverCardContent: parts.HoverCardContent,
|
|
59
59
|
HoverCardTrigger: parts.HoverCardTrigger,
|
|
60
60
|
InputGroup: parts.InputGroup,
|
|
61
61
|
InputGroupAddon: parts.InputGroupAddon,
|
|
62
|
-
InputOTP: {...parts.InputOTP, events: {onComplete: [{key: "value", kind: "STRING", description: "The code entered."}]}, bindKinds: {bind: "STRING"}},
|
|
62
|
+
InputOTP: {...parts.InputOTP, events: {onComplete: [{key: "value", port: {kind: "STRING"}, description: "The code entered."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
63
63
|
Item: parts.Item,
|
|
64
64
|
ItemGroup: parts.ItemGroup,
|
|
65
65
|
Kbd: parts.Kbd,
|
|
@@ -73,7 +73,7 @@ export const shadcnCatalog = defineBlokCatalog({
|
|
|
73
73
|
Resizable: parts.Resizable,
|
|
74
74
|
ResizableHandle: parts.ResizableHandle,
|
|
75
75
|
ResizablePanel: parts.ResizablePanel,
|
|
76
|
-
Sheet: {...parts.Sheet, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
76
|
+
Sheet: {...parts.Sheet, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
77
77
|
SheetContent: parts.SheetContent,
|
|
78
78
|
SheetDescription: parts.SheetDescription,
|
|
79
79
|
SheetFooter: parts.SheetFooter,
|
|
@@ -8,7 +8,7 @@ export const structureCatalog = defineBlokCatalog({
|
|
|
8
8
|
description: "Pick, show and view structures, typed by `\"@package/key\"`.",
|
|
9
9
|
components: {
|
|
10
10
|
StructureDisplay: parts.StructureDisplay,
|
|
11
|
-
StructurePicker: {...parts.StructurePicker, events: {onChange: [{key: "value", kind: "
|
|
11
|
+
StructurePicker: {...parts.StructurePicker, events: {onChange: [{key: "value", port: {kind: "STRUCTURE", identifier: "*", nullable: true}, description: "The structure reference picked, or null when cleared."}]}, bindKinds: {bind: {kind: "STRUCTURE", identifier: "*"}}},
|
|
12
12
|
StructureViewer: parts.StructureViewer,
|
|
13
13
|
},
|
|
14
14
|
});
|
package/src/catalogs/ui.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {BASE_CATALOG_REF, defineBlokCatalog} from '../renderer/runtime/catalog';
|
|
2
|
+
import * as z from 'zod';
|
|
2
3
|
import {parts} from './parts';
|
|
4
|
+
import {openValuesSchema} from './props';
|
|
3
5
|
|
|
4
6
|
/** The `ui` family of the base catalog. */
|
|
5
7
|
export const uiCatalog = defineBlokCatalog({
|
|
@@ -7,7 +9,7 @@ export const uiCatalog = defineBlokCatalog({
|
|
|
7
9
|
partOf: BASE_CATALOG_REF,
|
|
8
10
|
description: "Standard HTML components: layout, text, feedback, forms, data and overlays (shadcn-based).",
|
|
9
11
|
components: {
|
|
10
|
-
Accordion: {...parts.Accordion, events: {onChange: [{key: "value",
|
|
12
|
+
Accordion: {...parts.Accordion, events: {onChange: [{key: "value", port: openValuesSchema, description: "The open/pressed value(s): a string, or a list when multiple."}]}},
|
|
11
13
|
AccordionContent: parts.AccordionContent,
|
|
12
14
|
AccordionItem: parts.AccordionItem,
|
|
13
15
|
AccordionTrigger: {...parts.AccordionTrigger, textProp: "label"},
|
|
@@ -20,10 +22,10 @@ export const uiCatalog = defineBlokCatalog({
|
|
|
20
22
|
CardFooter: parts.CardFooter,
|
|
21
23
|
CardHeader: parts.CardHeader,
|
|
22
24
|
CardTitle: {...parts.CardTitle, textProp: "text"},
|
|
23
|
-
Checkbox: {...parts.Checkbox, textProp: "label", events: {onChange: [{key: "value", kind: "BOOL", description: "The new checked state."}]}, bindKinds: {bind: "BOOL"}},
|
|
25
|
+
Checkbox: {...parts.Checkbox, textProp: "label", events: {onChange: [{key: "value", port: {kind: "BOOL"}, description: "The new checked state."}]}, bindKinds: {bind: {kind: "BOOL"}}},
|
|
24
26
|
Code: {...parts.Code, textProp: "text"},
|
|
25
27
|
Column: parts.Column,
|
|
26
|
-
Dialog: {...parts.Dialog, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
28
|
+
Dialog: {...parts.Dialog, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
27
29
|
DialogClose: parts.DialogClose,
|
|
28
30
|
DialogContent: parts.DialogContent,
|
|
29
31
|
DialogDescription: {...parts.DialogDescription, textProp: "text"},
|
|
@@ -39,20 +41,20 @@ export const uiCatalog = defineBlokCatalog({
|
|
|
39
41
|
Heading: {...parts.Heading, textProp: "text"},
|
|
40
42
|
Icon: parts.Icon,
|
|
41
43
|
Image: parts.Image,
|
|
42
|
-
Input: {...parts.Input, events: {action: [{key: "value", kind: "STRING", description: "The text after the edit."}]}, bindKinds: {bind: "STRING"}},
|
|
44
|
+
Input: {...parts.Input, events: {action: [{key: "value", port: {kind: "STRING"}, description: "The text after the edit."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
43
45
|
Label: {...parts.Label, textProp: "text"},
|
|
44
46
|
Link: {...parts.Link, textProp: "text"},
|
|
45
47
|
Markdown: {...parts.Markdown, textProp: "content"},
|
|
46
|
-
Popover: {...parts.Popover, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
48
|
+
Popover: {...parts.Popover, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
47
49
|
PopoverContent: parts.PopoverContent,
|
|
48
50
|
PopoverTrigger: {...parts.PopoverTrigger, textProp: "label"},
|
|
49
51
|
Progress: parts.Progress,
|
|
50
|
-
RadioGroup: {...parts.RadioGroup, events: {onChange: [{key: "value", kind: "STRING", description: "The value now chosen."}]}, bindKinds: {bind: "STRING"}},
|
|
52
|
+
RadioGroup: {...parts.RadioGroup, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The value now chosen."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
51
53
|
RadioGroupItem: {...parts.RadioGroupItem, textProp: "label"},
|
|
52
54
|
Row: parts.Row,
|
|
53
55
|
List: parts.List,
|
|
54
56
|
ScrollArea: parts.ScrollArea,
|
|
55
|
-
Select: {...parts.Select, events: {onChange: [{key: "value", kind: "STRING", description: "The value now chosen."}]}, bindKinds: {bind: "STRING"}},
|
|
57
|
+
Select: {...parts.Select, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The value now chosen."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
56
58
|
SelectContent: parts.SelectContent,
|
|
57
59
|
SelectGroup: parts.SelectGroup,
|
|
58
60
|
SelectItem: {...parts.SelectItem, textProp: "label"},
|
|
@@ -60,10 +62,10 @@ export const uiCatalog = defineBlokCatalog({
|
|
|
60
62
|
SelectTrigger: parts.SelectTrigger,
|
|
61
63
|
Separator: parts.Separator,
|
|
62
64
|
Skeleton: parts.Skeleton,
|
|
63
|
-
Slider: {...parts.Slider, events: {onChange: [{key: "value", kind: "FLOAT", description: "The value."}], onCommit: [{key: "value", kind: "FLOAT", description: "Where the drag ended."}]}, bindKinds: {bind: "FLOAT"}},
|
|
65
|
+
Slider: {...parts.Slider, events: {onChange: [{key: "value", port: {kind: "FLOAT"}, description: "The value."}], onCommit: [{key: "value", port: {kind: "FLOAT"}, description: "Where the drag ended."}]}, bindKinds: {bind: {kind: "FLOAT"}}},
|
|
64
66
|
Spacer: parts.Spacer,
|
|
65
67
|
Spinner: parts.Spinner,
|
|
66
|
-
Switch: {...parts.Switch, textProp: "label", events: {onChange: [{key: "value", kind: "BOOL", description: "The new checked state."}]}, bindKinds: {bind: "BOOL"}},
|
|
68
|
+
Switch: {...parts.Switch, textProp: "label", events: {onChange: [{key: "value", port: {kind: "BOOL"}, description: "The new checked state."}]}, bindKinds: {bind: {kind: "BOOL"}}},
|
|
67
69
|
Table: parts.Table,
|
|
68
70
|
TableBody: parts.TableBody,
|
|
69
71
|
TableCell: {...parts.TableCell, textProp: "text"},
|
|
@@ -71,18 +73,18 @@ export const uiCatalog = defineBlokCatalog({
|
|
|
71
73
|
TableHead: {...parts.TableHead, textProp: "text"},
|
|
72
74
|
TableHeader: parts.TableHeader,
|
|
73
75
|
TableRow: parts.TableRow,
|
|
74
|
-
Tabs: {...parts.Tabs, events: {onChange: [{key: "value", kind: "STRING", description: "The value now chosen."}]}},
|
|
76
|
+
Tabs: {...parts.Tabs, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The value now chosen."}]}},
|
|
75
77
|
TabsContent: parts.TabsContent,
|
|
76
78
|
TabsList: parts.TabsList,
|
|
77
79
|
TabsTrigger: {...parts.TabsTrigger, textProp: "label"},
|
|
78
80
|
Text: {...parts.Text, textProp: "text"},
|
|
79
|
-
Textarea: {...parts.Textarea, events: {onChange: [{key: "value", kind: "STRING", description: "The text after the edit."}]}, bindKinds: {bind: "STRING"}},
|
|
81
|
+
Textarea: {...parts.Textarea, events: {onChange: [{key: "value", port: {kind: "STRING"}, description: "The text after the edit."}]}, bindKinds: {bind: {kind: "STRING"}}},
|
|
80
82
|
Time: parts.Time,
|
|
81
83
|
Toast: parts.Toast,
|
|
82
|
-
Toggle: {...parts.Toggle, textProp: "label", events: {onChange: [{key: "value", kind: "BOOL", description: "The new checked state."}]}, bindKinds: {bind: "BOOL"}},
|
|
83
|
-
ToggleGroup: {...parts.ToggleGroup, events: {onChange: [{key: "value",
|
|
84
|
+
Toggle: {...parts.Toggle, textProp: "label", events: {onChange: [{key: "value", port: {kind: "BOOL"}, description: "The new checked state."}]}, bindKinds: {bind: {kind: "BOOL"}}},
|
|
85
|
+
ToggleGroup: {...parts.ToggleGroup, events: {onChange: [{key: "value", port: openValuesSchema, description: "The open/pressed value(s): a string, or a list when multiple."}]}, bindKinds: {bind: z.union([z.string(), z.array(z.string())])}},
|
|
84
86
|
ToggleGroupItem: {...parts.ToggleGroupItem, textProp: "label"},
|
|
85
|
-
Tooltip: {...parts.Tooltip, events: {onOpenChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
87
|
+
Tooltip: {...parts.Tooltip, events: {onOpenChange: [{key: "value", port: {kind: "BOOL"}, description: "Whether it is open now."}]}},
|
|
86
88
|
TooltipContent: parts.TooltipContent,
|
|
87
89
|
TooltipTrigger: {...parts.TooltipTrigger, textProp: "label"},
|
|
88
90
|
cancelled: {...parts.cancelled, textProp: "text"},
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import {portToZod} from '../ports/engine/utils';
|
|
4
|
+
import {blokPropPort} from '../renderer/runtime/describe';
|
|
5
|
+
import {markStructureSchema, markTextSchema} from '../renderer/runtime/schemas';
|
|
6
|
+
import {fits} from '../spec/fit';
|
|
7
|
+
import {hasOpenNode, portJson, TEXT_PORT, type SpecPort} from '../spec/ports';
|
|
8
|
+
import {baseFamilies} from './index';
|
|
9
|
+
import {zodToPort} from './zodToPort';
|
|
10
|
+
|
|
11
|
+
const port = (schema: z.ZodTypeAny): Record<string, unknown> | null => portJson(zodToPort(schema, 'test'));
|
|
12
|
+
|
|
13
|
+
describe('zodToPort', () => {
|
|
14
|
+
it('reads scalars, choices and dates', () => {
|
|
15
|
+
expect(port(z.string())).toEqual({kind: 'STRING'});
|
|
16
|
+
expect(port(z.number())).toEqual({kind: 'FLOAT'});
|
|
17
|
+
expect(port(z.number().int())).toEqual({kind: 'INT'});
|
|
18
|
+
expect(port(z.int())).toEqual({kind: 'INT'});
|
|
19
|
+
expect(port(z.boolean().optional())).toEqual({kind: 'BOOL'});
|
|
20
|
+
expect(port(z.string().nullable())).toEqual({kind: 'STRING', nullable: true});
|
|
21
|
+
expect(port(z.enum(['a', 'b']))).toEqual({kind: 'STRING', choices: [{value: 'a'}, {value: 'b'}]});
|
|
22
|
+
expect(port(z.literal(3))).toEqual({kind: 'INT', choices: [{value: 3}]});
|
|
23
|
+
expect(port(z.iso.date())).toEqual({kind: 'DATE'});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('reads containers', () => {
|
|
27
|
+
expect(port(z.array(z.number()))).toEqual({kind: 'LIST', children: [{key: '...', kind: 'FLOAT'}]});
|
|
28
|
+
expect(port(z.record(z.string(), z.boolean()))).toEqual({kind: 'DICT', children: [{key: '...', kind: 'BOOL'}]});
|
|
29
|
+
expect(port(z.object({a: z.string().describe('A.'), b: z.number().optional()}))).toEqual({
|
|
30
|
+
kind: 'MODEL',
|
|
31
|
+
children: [
|
|
32
|
+
{key: 'a', kind: 'STRING', description: 'A.'},
|
|
33
|
+
{key: 'b', kind: 'FLOAT', nullable: true},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
expect(port(z.tuple([z.string(), z.number()]))).toEqual({
|
|
37
|
+
kind: 'LIST',
|
|
38
|
+
children: [{key: '...', kind: 'UNION', children: [{key: '0', kind: 'STRING'}, {key: '1', kind: 'FLOAT'}]}],
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('flattens unions, merges literals and collapses one variant', () => {
|
|
43
|
+
expect(port(z.union([z.string(), z.union([z.number(), z.string()])]))).toEqual({
|
|
44
|
+
kind: 'UNION',
|
|
45
|
+
children: [{key: '0', kind: 'STRING'}, {key: '1', kind: 'FLOAT'}],
|
|
46
|
+
});
|
|
47
|
+
expect(port(z.union([z.literal('a'), z.literal('b')]))).toEqual({kind: 'STRING', choices: [{value: 'a'}, {value: 'b'}]});
|
|
48
|
+
expect(port(z.union([z.string(), z.string()]))).toEqual({kind: 'STRING'});
|
|
49
|
+
expect(port(z.union([z.string(), z.null()]))).toEqual({kind: 'STRING', nullable: true});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('takes a mark before the shape', () => {
|
|
53
|
+
expect(port(markTextSchema(z.string().transform(String)).optional().describe('x'))).toEqual(portJson(TEXT_PORT));
|
|
54
|
+
expect(port(markStructureSchema(z.object({object: z.string()}), '*').nullish())).toEqual({kind: 'STRUCTURE', identifier: '*', nullable: true});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('throws on a shape no port says, naming where', () => {
|
|
58
|
+
expect(() => zodToPort(z.unknown(), '<X> y')).toThrow(/<X> y/);
|
|
59
|
+
expect(() => zodToPort(z.object({a: z.any()}), '<X> y')).toThrow(/<X> y\.a/);
|
|
60
|
+
expect(() => zodToPort(z.custom(() => true), 'z')).toThrow();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('round-trips the ports a form builds (list and dict forms wrap their items: not here)', () => {
|
|
64
|
+
const cases: SpecPort[] = [
|
|
65
|
+
{kind: 'STRING'},
|
|
66
|
+
{kind: 'BOOL', nullable: true},
|
|
67
|
+
{kind: 'INT'},
|
|
68
|
+
{kind: 'FLOAT'},
|
|
69
|
+
{kind: 'MODEL', children: [{key: 'a', kind: 'STRING'}, {key: 'b', kind: 'INT'}]},
|
|
70
|
+
];
|
|
71
|
+
for (const original of cases) {
|
|
72
|
+
const back = zodToPort(portToZod({key: 'x', ...original} as never), 'round trip');
|
|
73
|
+
expect(fits(back, original).status, JSON.stringify(original)).toBe('ok');
|
|
74
|
+
expect(fits(original, back).status, JSON.stringify(original)).toBe('ok');
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('the families of the base catalog', () => {
|
|
80
|
+
it('type every prop, with no open node anywhere', () => {
|
|
81
|
+
const problems: string[] = [];
|
|
82
|
+
for (const family of baseFamilies) {
|
|
83
|
+
for (const [name, component] of Object.entries(family.components)) {
|
|
84
|
+
for (const [key, schema] of Object.entries(component.schema.shape as Record<string, z.ZodTypeAny>)) {
|
|
85
|
+
if (key === 'children') continue;
|
|
86
|
+
try {
|
|
87
|
+
if (hasOpenNode(blokPropPort(name, key, schema, component))) problems.push(`<${name}> ${key}: open`);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
problems.push((error as Error).message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
expect(problems).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type * as z from 'zod';
|
|
2
|
+
import {markedPort} from '../renderer/runtime/schemas';
|
|
3
|
+
import {checkShape, ITEM_KEY, portJson, type SpecChildPort, type SpecPort} from '../spec/ports';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The port a zod schema publishes as a catalog prop (arkitekt-spec's
|
|
7
|
+
* `CatalogPort`). A marked schema (`markPortSchema`, `markTextSchema`,
|
|
8
|
+
* `markStructureSchema`) is its mark; any other is read by its shape. A shape
|
|
9
|
+
* no port says (`unknown`, `any`, `custom`, ...) throws, naming `where`: every
|
|
10
|
+
* drawn prop is typed.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
type ZodDef = {
|
|
14
|
+
type?: string;
|
|
15
|
+
format?: string;
|
|
16
|
+
innerType?: z.ZodTypeAny;
|
|
17
|
+
in?: z.ZodTypeAny;
|
|
18
|
+
out?: z.ZodTypeAny;
|
|
19
|
+
options?: z.ZodTypeAny[];
|
|
20
|
+
values?: unknown[];
|
|
21
|
+
entries?: Record<string, unknown>;
|
|
22
|
+
element?: z.ZodTypeAny;
|
|
23
|
+
valueType?: z.ZodTypeAny;
|
|
24
|
+
items?: z.ZodTypeAny[];
|
|
25
|
+
rest?: z.ZodTypeAny | null;
|
|
26
|
+
shape?: Record<string, z.ZodTypeAny>;
|
|
27
|
+
catchall?: z.ZodTypeAny;
|
|
28
|
+
getter?: () => z.ZodTypeAny;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const defOf = (schema: z.ZodTypeAny): ZodDef => (schema as unknown as {def?: ZodDef}).def ?? {};
|
|
32
|
+
const formatOf = (schema: z.ZodTypeAny): string | undefined =>
|
|
33
|
+
(schema as unknown as {format?: string | null}).format ?? defOf(schema).format ?? undefined;
|
|
34
|
+
|
|
35
|
+
const INT_FORMATS = new Set(['safeint', 'int32', 'uint32', 'int64', 'uint64']);
|
|
36
|
+
const DATE_FORMATS = new Set(['date', 'datetime']);
|
|
37
|
+
const WRAPPERS = new Set(['optional', 'default', 'prefault', 'readonly', 'catch', 'nonoptional']);
|
|
38
|
+
|
|
39
|
+
const describedAs = (schema: z.ZodTypeAny): string | null => (schema as unknown as {description?: string}).description ?? null;
|
|
40
|
+
|
|
41
|
+
/** The port of `schema`; throws, naming `where`, on a shape no port says. */
|
|
42
|
+
export const zodToPort = (schema: z.ZodTypeAny, where: string): SpecPort => {
|
|
43
|
+
let current = schema;
|
|
44
|
+
let nullable = false;
|
|
45
|
+
const lazies = new Set<object>();
|
|
46
|
+
for (let depth = 0; depth < 64; depth += 1) {
|
|
47
|
+
const marked = markedPort(current);
|
|
48
|
+
if (marked) return nullable ? {...marked, nullable: true} : marked;
|
|
49
|
+
const def = defOf(current);
|
|
50
|
+
if (def.type && WRAPPERS.has(def.type) && def.innerType) current = def.innerType;
|
|
51
|
+
else if (def.type === 'nullable' && def.innerType) {
|
|
52
|
+
nullable = true;
|
|
53
|
+
current = def.innerType;
|
|
54
|
+
} else if (def.type === 'pipe' && def.in && def.out) current = defOf(def.in).type === 'transform' ? def.out : def.in;
|
|
55
|
+
else if (def.type === 'lazy' && def.getter) {
|
|
56
|
+
if (lazies.has(current)) throw new Error(`${where}: a recursive schema has no port; mark it (markPortSchema)`);
|
|
57
|
+
lazies.add(current);
|
|
58
|
+
current = def.getter();
|
|
59
|
+
} else break;
|
|
60
|
+
}
|
|
61
|
+
const port = shapePort(current, where);
|
|
62
|
+
return nullable ? {...port, nullable: true} : port;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const child = (key: string, port: SpecPort, description?: string | null): SpecChildPort => ({
|
|
66
|
+
key,
|
|
67
|
+
...port,
|
|
68
|
+
...(description ? {description} : {}),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const scalarKind = (values: readonly unknown[], where: string): string => {
|
|
72
|
+
if (values.every(value => typeof value === 'string')) return 'STRING';
|
|
73
|
+
if (values.every(value => typeof value === 'boolean')) return 'BOOL';
|
|
74
|
+
if (values.every(value => typeof value === 'number')) return values.every(value => Number.isInteger(value)) ? 'INT' : 'FLOAT';
|
|
75
|
+
throw new Error(`${where}: literals of mixed kinds have no port; use a union`);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const shapePort = (schema: z.ZodTypeAny, where: string): SpecPort => {
|
|
79
|
+
const def = defOf(schema);
|
|
80
|
+
switch (def.type) {
|
|
81
|
+
case 'string':
|
|
82
|
+
return {kind: DATE_FORMATS.has(formatOf(schema) ?? '') ? 'DATE' : 'STRING'};
|
|
83
|
+
case 'template_literal':
|
|
84
|
+
return {kind: 'STRING'};
|
|
85
|
+
case 'enum': {
|
|
86
|
+
const values = Object.values(def.entries ?? {});
|
|
87
|
+
return {kind: scalarKind(values, where), choices: values.map(value => ({value}))};
|
|
88
|
+
}
|
|
89
|
+
case 'literal': {
|
|
90
|
+
const values = def.values ?? [];
|
|
91
|
+
return {kind: scalarKind(values, where), choices: values.map(value => ({value}))};
|
|
92
|
+
}
|
|
93
|
+
case 'number':
|
|
94
|
+
return {kind: INT_FORMATS.has(formatOf(schema) ?? '') ? 'INT' : 'FLOAT'};
|
|
95
|
+
case 'nan':
|
|
96
|
+
return {kind: 'FLOAT'};
|
|
97
|
+
case 'bigint':
|
|
98
|
+
return {kind: 'INT'};
|
|
99
|
+
case 'boolean':
|
|
100
|
+
return {kind: 'BOOL'};
|
|
101
|
+
case 'date':
|
|
102
|
+
return {kind: 'DATE'};
|
|
103
|
+
case 'array':
|
|
104
|
+
case 'set':
|
|
105
|
+
return {kind: 'LIST', children: [child(ITEM_KEY, zodToPort((def.element ?? def.valueType) as z.ZodTypeAny, `${where}[]`))]};
|
|
106
|
+
case 'tuple': {
|
|
107
|
+
const items = [...(def.items ?? []), ...(def.rest ? [def.rest] : [])];
|
|
108
|
+
return {kind: 'LIST', children: [child(ITEM_KEY, unionOf(items.map((item, index) => zodToPort(item, `${where}[${index}]`)), where))]};
|
|
109
|
+
}
|
|
110
|
+
case 'record':
|
|
111
|
+
case 'map':
|
|
112
|
+
return {kind: 'DICT', children: [child(ITEM_KEY, zodToPort(def.valueType as z.ZodTypeAny, `${where}{}`))]};
|
|
113
|
+
case 'object': {
|
|
114
|
+
const shape = Object.entries(def.shape ?? {});
|
|
115
|
+
if (!shape.length) {
|
|
116
|
+
const catchall = def.catchall && defOf(def.catchall).type !== 'never' ? def.catchall : null;
|
|
117
|
+
if (!catchall) throw new Error(`${where}: an empty object has no port; say what it holds (z.record)`);
|
|
118
|
+
return {kind: 'DICT', children: [child(ITEM_KEY, zodToPort(catchall, `${where}{}`))]};
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
kind: 'MODEL',
|
|
122
|
+
children: shape.map(([key, field]) => {
|
|
123
|
+
const port = zodToPort(field, `${where}.${key}`);
|
|
124
|
+
return child(key, field.safeParse(undefined).success ? {...port, nullable: true} : port, describedAs(field));
|
|
125
|
+
}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
case 'union': {
|
|
129
|
+
const isNull = (option: z.ZodTypeAny) => ['null', 'undefined'].includes(defOf(option).type ?? '');
|
|
130
|
+
const options = def.options ?? [];
|
|
131
|
+
const port = unionOf(options.filter(option => !isNull(option)).map((option, index) => zodToPort(option, `${where}|${index}`)), where);
|
|
132
|
+
return options.some(isNull) ? {...port, nullable: true} : port;
|
|
133
|
+
}
|
|
134
|
+
case 'null':
|
|
135
|
+
case 'undefined':
|
|
136
|
+
throw new Error(`${where}: null alone has no port; make a typed schema nullable`);
|
|
137
|
+
default:
|
|
138
|
+
throw new Error(`${where}: a ${def.type ?? 'schema'} has no port; type it (or mark it: markPortSchema)`);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const LEAF_CHOICES = new Set(['STRING', 'INT', 'FLOAT', 'BOOL']);
|
|
143
|
+
|
|
144
|
+
/** Variants as one port: nested unions flattened, the same variant once, literals of one kind merged; one variant is itself. */
|
|
145
|
+
export const unionOf = (variants: readonly SpecPort[], where: string): SpecPort => {
|
|
146
|
+
const flat: SpecPort[] = [];
|
|
147
|
+
for (const variant of variants) {
|
|
148
|
+
if (variant.kind === 'UNION') flat.push(...(variant.children ?? []).map(({key: _key, description: _description, ...port}) => port));
|
|
149
|
+
else flat.push(variant);
|
|
150
|
+
}
|
|
151
|
+
const merged: SpecPort[] = [];
|
|
152
|
+
for (const variant of flat) {
|
|
153
|
+
const same = merged.findIndex(other => other.kind === variant.kind && LEAF_CHOICES.has(variant.kind ?? '') && other.choices && variant.choices);
|
|
154
|
+
if (same >= 0 && variant.choices) {
|
|
155
|
+
const other = merged[same];
|
|
156
|
+
const values = new Set((other.choices ?? []).map(choice => choice.value));
|
|
157
|
+
merged[same] = {...other, choices: [...(other.choices ?? []), ...variant.choices.filter(choice => !values.has(choice.value))]};
|
|
158
|
+
} else merged.push(variant);
|
|
159
|
+
}
|
|
160
|
+
const seen = new Set<string>();
|
|
161
|
+
const unique = merged.filter(variant => {
|
|
162
|
+
const text = JSON.stringify(portJson(variant));
|
|
163
|
+
if (seen.has(text)) return false;
|
|
164
|
+
seen.add(text);
|
|
165
|
+
return true;
|
|
166
|
+
});
|
|
167
|
+
// A plain variant takes every literal of its kind: the literals add nothing.
|
|
168
|
+
const kept = unique.filter(variant => !(variant.choices && unique.some(other => other !== variant && other.kind === variant.kind && !other.choices)));
|
|
169
|
+
if (kept.length === 1) return kept[0];
|
|
170
|
+
const port: SpecPort = {kind: 'UNION', children: kept.map((variant, index) => child(String(index), variant))};
|
|
171
|
+
checkShape(port, where);
|
|
172
|
+
return port;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** A hand-written port or a zod schema, as a port. */
|
|
176
|
+
export const asPort = (value: SpecPort | z.ZodTypeAny, where: string): SpecPort =>
|
|
177
|
+
typeof value === 'object' && value !== null && '_zod' in value ? zodToPort(value as z.ZodTypeAny, where) : (value as SpecPort);
|
package/src/catalogs.ts
CHANGED
|
@@ -9,5 +9,8 @@ export {
|
|
|
9
9
|
type BlokCatalogContract,
|
|
10
10
|
type BlokComponentContracts,
|
|
11
11
|
} from './renderer/runtime/catalog';
|
|
12
|
-
export type {BlokComponentContract} from './renderer/runtime/components';
|
|
12
|
+
export type {BlokComponentContract, BlokEventField} from './renderer/runtime/components';
|
|
13
|
+
export {markPortSchema, markStructureSchema, markTextSchema} from './renderer/runtime/schemas';
|
|
14
|
+
export {asPort, zodToPort} from './catalogs/zodToPort';
|
|
15
|
+
export {portJson, portSummary, TEXT_PORT, type SpecChildPort, type SpecPort} from './spec/ports';
|
|
13
16
|
export {describeBlokContract, specJsonText, type SpecCatalogJson} from './renderer/runtime/describe';
|
package/src/index.ts
CHANGED
package/src/ports/rekuest.ts
CHANGED
|
@@ -48,7 +48,13 @@ export type OptionKey = (typeof OptionKey)[keyof typeof OptionKey];
|
|
|
48
48
|
|
|
49
49
|
/** The kind of a port: its structural type. Decides which of children, identifier and choices the port must, may or must not carry (see docs/design/ports.md). */
|
|
50
50
|
export const PortKind = {
|
|
51
|
+
/** Catalog only: a file an app registered. */
|
|
52
|
+
Asset: 'ASSET',
|
|
53
|
+
/** Catalog only: the local a control writes; its one child is the value. */
|
|
54
|
+
Binding: 'BINDING',
|
|
51
55
|
Bool: 'BOOL',
|
|
56
|
+
/** Catalog only: a callback; its children are the payload. */
|
|
57
|
+
Callback: 'CALLBACK',
|
|
52
58
|
Date: 'DATE',
|
|
53
59
|
Dict: 'DICT',
|
|
54
60
|
Enum: 'ENUM',
|
|
@@ -284,9 +284,9 @@ export const chromeSchema = z
|
|
|
284
284
|
);
|
|
285
285
|
|
|
286
286
|
const BLOK_COMPONENT = 'Blok';
|
|
287
|
-
const DECLARATIONS: ReadonlySet<string> = new Set(['local', 'query', 'subscription', 'var', 'dependencies']);
|
|
287
|
+
const DECLARATIONS: ReadonlySet<string> = new Set(['local', 'query', 'subscription', 'var', 'dependencies', 'logo']);
|
|
288
288
|
|
|
289
|
-
/** The children of a node that draw: its declarations (`local`, `query`, `subscription`, `var`, `dependencies`) left out. */
|
|
289
|
+
/** The children of a node that draw: its declarations (`local`, `query`, `subscription`, `var`, `dependencies`, `logo`) left out. */
|
|
290
290
|
export const drawnChildren = (component: BlokComponentNode): BlokComponentNode[] =>
|
|
291
291
|
(component.children ?? []).filter(child => !DECLARATIONS.has(child.component));
|
|
292
292
|
|
|
@@ -738,6 +738,29 @@ export const PortField = createBlokComponent({name: 'field', schema: fieldSchema
|
|
|
738
738
|
return <>{typeof key === 'string' ? parts.renderField(key) : null}</>;
|
|
739
739
|
});
|
|
740
740
|
|
|
741
|
+
/**
|
|
742
|
+
* `<logo title viewBox>`: the blok's own logo, what stands for it in lists, pins and tabs. Draws
|
|
743
|
+
* nothing in the blok; its children are a drawing of the logo catalog, drawn as a logo blok of
|
|
744
|
+
* its own (`blokLogoTree`).
|
|
745
|
+
*/
|
|
746
|
+
export const LogoDeclaration = createBlokComponent(
|
|
747
|
+
{
|
|
748
|
+
name: 'logo',
|
|
749
|
+
acceptsChildren: true,
|
|
750
|
+
placement: {childrenContext: 'logo'},
|
|
751
|
+
since: 4,
|
|
752
|
+
schema: z
|
|
753
|
+
.object({
|
|
754
|
+
title: z.string().optional().describe('What the logo is called: read out in place of the drawing.'),
|
|
755
|
+
viewBox: z.string().optional().describe("The drawing's grid; 0 0 24 24 when left out."),
|
|
756
|
+
})
|
|
757
|
+
.describe(
|
|
758
|
+
"Declares the blok's own logo: what stands for it in lists, pins and tabs. A drawing of the logo catalog on a 24-unit grid, painted with the logo pens, drawn with the action logos' pen unless a shape says otherwise; literals only. A child of <Blok>, one; draws nothing in the blok.",
|
|
759
|
+
),
|
|
760
|
+
},
|
|
761
|
+
() => null,
|
|
762
|
+
);
|
|
763
|
+
|
|
741
764
|
export const controlBlokComponents = [
|
|
742
765
|
TextNode,
|
|
743
766
|
Foreach,
|
|
@@ -750,6 +773,7 @@ export const controlBlokComponents = [
|
|
|
750
773
|
Subscription,
|
|
751
774
|
Var,
|
|
752
775
|
Dependencies,
|
|
776
|
+
LogoDeclaration,
|
|
753
777
|
Match,
|
|
754
778
|
Case,
|
|
755
779
|
Default,
|
|
@@ -18,8 +18,8 @@ const contract = defineBlokCatalog({
|
|
|
18
18
|
onTurn: actionProp('Runs when turned.'),
|
|
19
19
|
})
|
|
20
20
|
.describe('A knob.'),
|
|
21
|
-
bindKinds: {bind: 'FLOAT'},
|
|
22
|
-
events: {onTurn: [{key: 'value',
|
|
21
|
+
bindKinds: {bind: {kind: 'FLOAT'}},
|
|
22
|
+
events: {onTurn: [{key: 'value', port: z.number(), description: 'Where it stands.'}]},
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
});
|
|
@@ -56,7 +56,7 @@ describe('implementBlokCatalog', () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
describe('describeBlokContract', () => {
|
|
59
|
-
it('writes the spec JSON:
|
|
59
|
+
it('writes the spec JSON: each prop\'s port (choices, a binding, a callback\'s payload) and the text prop', () => {
|
|
60
60
|
expect(describeBlokContract(contract)).toEqual({
|
|
61
61
|
name: 'demo',
|
|
62
62
|
version: 1,
|
|
@@ -73,14 +73,13 @@ describe('describeBlokContract', () => {
|
|
|
73
73
|
not_downstream_of: [],
|
|
74
74
|
text_prop: null,
|
|
75
75
|
props: [
|
|
76
|
-
{key: 'bind', kind: 'FLOAT', required: false, description: expect.any(String)},
|
|
77
|
-
{key: 'level', kind: 'STRING',
|
|
76
|
+
{key: 'bind', port: {kind: 'BINDING', children: [{key: '...', kind: 'FLOAT'}]}, required: false, description: expect.any(String)},
|
|
77
|
+
{key: 'level', port: {kind: 'STRING', choices: [{value: 'low'}, {value: 'high'}]}, required: false, description: 'How far.'},
|
|
78
78
|
{
|
|
79
79
|
key: 'onTurn',
|
|
80
|
-
kind: 'CALLBACK',
|
|
80
|
+
port: {kind: 'CALLBACK', children: [{key: 'value', kind: 'FLOAT', description: 'Where it stands.'}]},
|
|
81
81
|
required: false,
|
|
82
82
|
description: 'Runs when turned.',
|
|
83
|
-
event: [{key: 'value', kind: 'FLOAT', description: 'Where it stands.'}],
|
|
84
83
|
},
|
|
85
84
|
],
|
|
86
85
|
},
|
|
@@ -94,9 +93,14 @@ describe('describeBlokContract', () => {
|
|
|
94
93
|
downstream_of: [],
|
|
95
94
|
not_downstream_of: [],
|
|
96
95
|
text_prop: 'text',
|
|
97
|
-
props: [{key: 'text', kind: 'STRING', required: false, description: 'What it says.'}],
|
|
96
|
+
props: [{key: 'text', port: {kind: 'STRING'}, required: false, description: 'What it says.'}],
|
|
98
97
|
},
|
|
99
98
|
],
|
|
100
99
|
});
|
|
101
100
|
});
|
|
101
|
+
|
|
102
|
+
it('refuses a prop no port says', () => {
|
|
103
|
+
const untyped = defineBlokCatalog({name: 'odd', description: '', components: {Odd: {schema: z.object({any: z.unknown()})}}});
|
|
104
|
+
expect(() => describeBlokContract(untyped)).toThrow(/<Odd> any/);
|
|
105
|
+
});
|
|
102
106
|
});
|
|
@@ -7,6 +7,7 @@ import {BlokNodeStateContext, type BlokNodeState} from './nodeState';
|
|
|
7
7
|
import {readScopedPath, useBlokScope} from './scope';
|
|
8
8
|
import {READY, combineStatus, type BlokSourceStatus} from './status';
|
|
9
9
|
import type {BlokComponentNode, BlokComponentProp, BlokObjectSchema} from './types';
|
|
10
|
+
import type {SpecPort} from '../../spec/ports';
|
|
10
11
|
|
|
11
12
|
export type BlokRenderArgs<TSchema extends BlokObjectSchema = BlokObjectSchema> = {
|
|
12
13
|
props: ReadonlyArray<BlokComponentProp>;
|
|
@@ -43,8 +44,8 @@ export type BlokComponentPlacement = {
|
|
|
43
44
|
/** Props the server holds to more than their shape: an `ASSET` prop names a file its app registered. */
|
|
44
45
|
export type BlokPropKind = 'ASSET';
|
|
45
46
|
|
|
46
|
-
/** A field of what a callback is called with (`event.value`),
|
|
47
|
-
export type BlokEventField = {key: string;
|
|
47
|
+
/** A field of what a callback is called with (`event.value`): its port, or a zod schema of it. */
|
|
48
|
+
export type BlokEventField = {key: string; port: SpecPort | z.ZodTypeAny; description: string};
|
|
48
49
|
|
|
49
50
|
type BlokComponentApi = {
|
|
50
51
|
/** Set when the component renders declared children its schema has no `children` prop for. */
|
|
@@ -61,12 +62,8 @@ type BlokComponentApi = {
|
|
|
61
62
|
textProp?: string;
|
|
62
63
|
/** Per callback prop, the fields of the event it is called with (`[]`: none). */
|
|
63
64
|
events?: Readonly<Record<string, readonly BlokEventField[]>>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
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>>;
|
|
65
|
+
/** Per `bind` prop, what the control writes (`Slider.bind`: a FLOAT): its port, or a zod schema of it. */
|
|
66
|
+
bindKinds?: Readonly<Record<string, SpecPort | z.ZodTypeAny>>;
|
|
70
67
|
/** The blok kinds it may be placed in (`assign`); any kind when left out. */
|
|
71
68
|
kinds?: readonly string[];
|
|
72
69
|
/** The service it needs where it is drawn (`mikro`): without it a notice shows in its place. */
|