@k8ordo/ui 3.0.0 → 4.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 +73 -182
- package/dist/{integrations/_shared → catalog}/icon-map.d.mts +4 -2
- package/dist/catalog/icon-map.mjs +212 -0
- package/dist/catalog/icon-names.d.mts +1 -0
- package/dist/{integrations/_shared → catalog}/icon-names.mjs +3 -1
- package/dist/catalog/index.d.mts +1289 -0
- package/dist/catalog/index.mjs +419 -0
- package/dist/catalog/render.css +34 -0
- package/dist/catalog/render.d.mts +72 -0
- package/dist/catalog/render.mjs +631 -0
- package/dist/catalog/render.module.mjs +11 -0
- package/dist/{integrations/_shared → catalog}/schemas.d.mts +120 -132
- package/dist/{integrations/_shared → catalog}/schemas.mjs +189 -131
- package/dist/catalog/to-tree.d.mts +4 -0
- package/dist/catalog/to-tree.mjs +17 -0
- package/dist/components/_internal/checked-values.d.mts +1 -0
- package/dist/components/_internal/checked-values.mjs +5 -0
- package/dist/components/_internal/field-message.css +25 -0
- package/dist/components/_internal/field-message.d.mts +10 -0
- package/dist/components/_internal/field-message.mjs +22 -0
- package/dist/components/_internal/field-message.module.mjs +9 -0
- package/dist/components/_internal/focus-ring.css +1 -1
- package/dist/components/_internal/high-contrast.css +1 -0
- package/dist/components/{observers/in-view → _internal}/in-view.mjs +1 -1
- package/dist/components/{observers/resize → _internal}/resize.mjs +1 -1
- package/dist/components/ai/_internal/attachment-preview.mjs +1 -1
- package/dist/components/ai/_internal/collapsible.mjs +1 -1
- package/dist/components/ai/attachment/attachment.d.mts +1 -1
- package/dist/components/ai/attachment/index.d.mts +1 -1
- package/dist/components/ai/conversation/conversation.mjs +4 -4
- package/dist/components/ai/index.d.mts +2 -2
- package/dist/components/ai/message/index.d.mts +2 -2
- package/dist/components/ai/message/message.d.mts +2 -2
- package/dist/components/ai/message/message.mjs +9 -9
- package/dist/components/ai/prompt-input/prompt-input.mjs +4 -4
- package/dist/components/ai/source/index.d.mts +2 -2
- package/dist/components/ai/source/source.d.mts +2 -2
- package/dist/components/ai/source/source.mjs +1 -1
- package/dist/components/ai/tool-invocation/approval-bar.mjs +11 -22
- package/dist/components/ai/tool-invocation/tool-invocation.d.mts +2 -2
- package/dist/components/buttons/button/button.css +1 -1
- package/dist/components/buttons/button/button.d.mts +34 -37
- package/dist/components/buttons/button/button.mjs +37 -24
- package/dist/components/buttons/button/button.module.mjs +0 -1
- package/dist/components/buttons/button/index.d.mts +2 -2
- package/dist/components/buttons/copy-button/copy-button.mjs +4 -4
- package/dist/components/buttons/icon-button/icon-button.css +3 -3
- package/dist/components/buttons/icon-button/icon-button.d.mts +37 -43
- package/dist/components/buttons/icon-button/icon-button.mjs +73 -63
- package/dist/components/buttons/icon-button/icon-button.module.mjs +2 -2
- package/dist/components/buttons/icon-button/index.d.mts +2 -2
- package/dist/components/buttons/toolbar/toolbar.css +5 -1
- package/dist/components/buttons/toolbar/toolbar.mjs +1 -1
- package/dist/components/data-display/accordion/accordion-button.d.mts +4 -1
- package/dist/components/data-display/accordion/accordion-button.mjs +4 -4
- package/dist/components/data-display/accordion/index.d.mts +3 -3
- package/dist/components/data-display/card/card-action.d.mts +6 -0
- package/dist/components/data-display/card/card-action.mjs +21 -0
- package/dist/components/data-display/card/card.css +24 -0
- package/dist/components/data-display/card/card.d.mts +26 -3
- package/dist/components/data-display/card/card.mjs +46 -6
- package/dist/components/data-display/card/card.module.mjs +4 -1
- package/dist/components/data-display/card/index.d.mts +2 -2
- package/dist/components/data-display/carousel/carousel.mjs +2 -2
- package/dist/components/data-display/code/code.css +4 -0
- package/dist/components/data-display/code-block/code-block.mjs +1 -1
- package/dist/components/data-display/data-table/data-table.css +0 -3
- package/dist/components/data-display/data-table/data-table.mjs +25 -26
- package/dist/components/data-display/tree/tree.d.mts +1 -1
- package/dist/components/data-display/tree/tree.mjs +6 -5
- package/dist/components/feedback/alert/alert.d.mts +2 -7
- package/dist/components/feedback/alert/alert.mjs +11 -11
- package/dist/components/feedback/alert/index.d.mts +2 -2
- package/dist/components/feedback/callout/callout.mjs +2 -2
- package/dist/components/feedback/progress/progress.mjs +1 -1
- package/dist/components/feedback/toast/context.d.mts +4 -5
- package/dist/components/feedback/toast/index.d.mts +2 -2
- package/dist/components/feedback/toast/provider.d.mts +7 -2
- package/dist/components/feedback/toast/provider.mjs +7 -2
- package/dist/components/feedback/toast/toast.d.mts +2 -3
- package/dist/components/form/autocomplete/autocomplete.d.mts +2 -2
- package/dist/components/form/autocomplete/autocomplete.mjs +12 -9
- package/dist/components/form/calendar/calendar.mjs +3 -5
- package/dist/components/form/checkbox/checkbox.d.mts +3 -1
- package/dist/components/form/checkbox/checkbox.mjs +44 -45
- package/dist/components/form/checkbox-card/checkbox-card.d.mts +3 -2
- package/dist/components/form/checkbox-card/checkbox-card.mjs +13 -6
- package/dist/components/form/checkbox-group/checkbox-group.d.mts +15 -20
- package/dist/components/form/checkbox-group/checkbox-group.mjs +18 -26
- package/dist/components/form/checkbox-group/index.d.mts +2 -34
- package/dist/components/form/checkbox-group/index.mjs +1 -8
- package/dist/components/form/color-picker/color-picker.css +3 -5
- package/dist/components/form/color-picker/color-picker.d.mts +0 -1
- package/dist/components/form/color-picker/color-picker.mjs +4 -4
- package/dist/components/form/combobox/combobox.d.mts +0 -1
- package/dist/components/form/combobox/combobox.mjs +9 -8
- package/dist/components/form/date-picker/date-picker.css +0 -5
- package/dist/components/form/date-picker/date-picker.mjs +21 -22
- package/dist/components/form/file-field/file-field.d.mts +6 -3
- package/dist/components/form/file-field/file-field.mjs +41 -18
- package/dist/components/form/file-field/index.d.mts +4 -1
- package/dist/components/form/form/form.mjs +0 -1
- package/dist/components/form/form-control/form-control.css +0 -15
- package/dist/components/form/form-control/form-control.d.mts +3 -4
- package/dist/components/form/form-control/form-control.mjs +44 -46
- package/dist/components/form/form-control/form-control.module.mjs +0 -3
- package/dist/components/form/number-field/number-field.d.mts +2 -2
- package/dist/components/form/number-field/number-field.mjs +13 -52
- package/dist/components/form/password-input/password-input.mjs +1 -1
- package/dist/components/form/radio/radio.mjs +4 -2
- package/dist/components/form/radio-card/radio-card.mjs +9 -2
- package/dist/components/form/range-slider/range-slider.d.mts +4 -2
- package/dist/components/form/range-slider/range-slider.mjs +2 -4
- package/dist/components/form/select/select.css +6 -4
- package/dist/components/form/select/select.d.mts +5 -0
- package/dist/components/form/select/select.mjs +10 -7
- package/dist/components/form/slider/slider.d.mts +2 -2
- package/dist/components/form/slider/slider.mjs +3 -6
- package/dist/components/form/switch/switch.d.mts +3 -0
- package/dist/components/form/switch/switch.mjs +43 -31
- package/dist/components/form/text-field/index.d.mts +2 -2
- package/dist/components/form/text-field/text-field.css +4 -0
- package/dist/components/form/text-field/text-field.d.mts +1 -1
- package/dist/components/form/textarea/textarea.d.mts +0 -1
- package/dist/components/form/textarea/textarea.mjs +1 -1
- package/dist/components/icons/base.d.mts +0 -1
- package/dist/components/icons/base.mjs +1 -2
- package/dist/components/icons/clipboard-check.d.mts +3 -0
- package/dist/components/icons/clipboard-check.mjs +18 -0
- package/dist/components/icons/git-pull-request.d.mts +3 -0
- package/dist/components/icons/git-pull-request.mjs +20 -0
- package/dist/components/icons/index.d.mts +9 -7
- package/dist/components/icons/index.mjs +30 -28
- package/dist/components/index.d.mts +58 -66
- package/dist/components/index.mjs +13 -19
- package/dist/components/layout/resizable-panels/resizable-panels.mjs +3 -3
- package/dist/components/navigation/anchor/anchor.css +3 -3
- package/dist/components/navigation/anchor/anchor.mjs +20 -7
- package/dist/components/navigation/anchor/anchor.module.mjs +1 -1
- package/dist/components/navigation/breadcrumb/breadcrumb.d.mts +6 -4
- package/dist/components/navigation/breadcrumb/breadcrumb.mjs +3 -2
- package/dist/components/navigation/pagination/pagination.d.mts +2 -2
- package/dist/components/navigation/pagination/pagination.mjs +2 -2
- package/dist/components/navigation/side-nav/side-nav.mjs +1 -1
- package/dist/components/navigation/stepper/stepper.mjs +3 -3
- package/dist/components/navigation/tabs/index.d.mts +10 -5
- package/dist/components/navigation/tabs/tabs.d.mts +11 -6
- package/dist/components/navigation/tabs/tabs.mjs +24 -27
- package/dist/components/overlays/_internal/modal-header.css +38 -0
- package/dist/components/overlays/_internal/modal-header.d.mts +7 -0
- package/dist/components/overlays/_internal/modal-header.mjs +32 -0
- package/dist/components/overlays/_internal/modal-header.module.mjs +10 -0
- package/dist/components/overlays/command-palette/command-palette.d.mts +2 -2
- package/dist/components/overlays/command-palette/command-palette.mjs +9 -8
- package/dist/components/overlays/context-menu/context-menu.mjs +3 -3
- package/dist/components/overlays/context-menu/index.d.mts +27 -2
- package/dist/components/overlays/dialog/dialog.css +3 -21
- package/dist/components/overlays/dialog/dialog.d.mts +20 -9
- package/dist/components/overlays/dialog/dialog.mjs +35 -73
- package/dist/components/overlays/dialog/dialog.module.mjs +1 -3
- package/dist/components/overlays/dialog/index.d.mts +2 -15
- package/dist/components/overlays/dialog/index.mjs +1 -8
- package/dist/components/overlays/drawer/drawer.css +4 -26
- package/dist/components/overlays/drawer/drawer.d.mts +7 -2
- package/dist/components/overlays/drawer/drawer.mjs +24 -37
- package/dist/components/overlays/drawer/drawer.module.mjs +2 -6
- package/dist/components/overlays/dropdown-menu/dropdown-menu.d.mts +35 -5
- package/dist/components/overlays/dropdown-menu/dropdown-menu.mjs +29 -11
- package/dist/components/overlays/dropdown-menu/hooks.d.mts +1 -1
- package/dist/components/overlays/dropdown-menu/hooks.mjs +1 -1
- package/dist/components/overlays/dropdown-menu/index.d.mts +34 -4
- package/dist/components/overlays/dropdown-menu/shared.css +1 -0
- package/dist/components/overlays/dropdown-menu/sub-menu.mjs +4 -4
- package/dist/components/overlays/list-box/hooks.mjs +2 -2
- package/dist/components/overlays/list-box/index.d.mts +2 -25
- package/dist/components/overlays/list-box/index.mjs +1 -9
- package/dist/components/overlays/list-box/list-box.d.mts +11 -16
- package/dist/components/overlays/list-box/list-box.mjs +23 -16
- package/dist/components/overlays/modal/modal.d.mts +8 -7
- package/dist/components/overlays/modal/modal.mjs +23 -32
- package/dist/components/overlays/popover/anchor-positioning.d.mts +3 -16
- package/dist/components/overlays/popover/anchor-positioning.mjs +14 -6
- package/dist/components/overlays/popover/hooks.d.mts +0 -2
- package/dist/components/overlays/popover/hooks.mjs +0 -2
- package/dist/components/overlays/popover/index.d.mts +19 -2
- package/dist/components/overlays/popover/index.mjs +7 -2
- package/dist/components/overlays/popover/popover.css +6 -0
- package/dist/components/overlays/popover/popover.d.mts +15 -2
- package/dist/components/overlays/popover/popover.mjs +28 -13
- package/dist/components/overlays/popover/popover.module.mjs +2 -1
- package/dist/components/overlays/tooltip/bridge.css +1 -1
- package/dist/components/overlays/tooltip/tooltip.mjs +5 -5
- package/dist/helpers/index.mjs +1 -1
- package/dist/i18n/en.mjs +1 -2
- package/dist/i18n/index.d.mts +3 -4
- package/dist/i18n/index.mjs +1 -2
- package/dist/i18n/ja.mjs +1 -2
- package/dist/i18n/messages.d.mts +2 -4
- package/dist/i18n/usage.d.mts +2 -1
- package/dist/i18n/usage.mjs +3 -3
- package/dist/index.d.mts +30 -36
- package/dist/index.mjs +4 -10
- package/dist/internal/iso-date.mjs +1 -1
- package/dist/styles/index.css +79 -225
- package/dist/styles/tailwind.css +1 -1
- package/dist/styles/tokens.css +281 -0
- package/dist/styles/tokens.d.mts +1 -1
- package/dist/styles/tokens.mjs +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/variables.d.mts +4 -2
- package/docs/GUIDE.md +141 -66
- package/docs/llms.txt +38 -11
- package/docs/props.generated.json +752 -481
- package/docs/references/ai-chat.md +87 -39
- package/docs/references/color.md +15 -15
- package/docs/references/components.md +568 -499
- package/docs/references/generative-ui.md +373 -185
- package/docs/references/interaction-design.md +6 -5
- package/docs/references/spatial-design.md +8 -8
- package/docs/references/types.md +22 -25
- package/package.json +37 -70
- package/dist/components/form/date-field/date-field.css +0 -31
- package/dist/components/form/date-field/date-field.d.mts +0 -7
- package/dist/components/form/date-field/date-field.mjs +0 -19
- package/dist/components/form/date-field/date-field.module.mjs +0 -4
- package/dist/components/form/date-field/index.d.mts +0 -2
- package/dist/components/form/date-field/index.mjs +0 -1
- package/dist/components/observers/in-view/index.d.mts +0 -2
- package/dist/components/observers/in-view/index.mjs +0 -1
- package/dist/components/observers/resize/index.d.mts +0 -2
- package/dist/components/observers/resize/index.mjs +0 -1
- package/dist/components/overlays/_internal/modal-dialog-context.d.mts +0 -11
- package/dist/components/overlays/_internal/modal-dialog-context.mjs +0 -12
- package/dist/components/providers/index.d.mts +0 -3
- package/dist/components/providers/index.mjs +0 -3
- package/dist/components/providers/portal-root.d.mts +0 -8
- package/dist/components/providers/portal-root.mjs +0 -11
- package/dist/components/providers/ui-provider.d.mts +0 -2
- package/dist/components/providers/ui-provider.mjs +0 -6
- package/dist/integrations/_shared/icon-map.mjs +0 -208
- package/dist/integrations/_shared/icon-names.d.mts +0 -1
- package/dist/integrations/_shared/openui-defs.d.mts +0 -15
- package/dist/integrations/_shared/openui-defs.mjs +0 -230
- package/dist/integrations/_shared/renderers.css +0 -50
- package/dist/integrations/_shared/renderers.d.mts +0 -88
- package/dist/integrations/_shared/renderers.mjs +0 -880
- package/dist/integrations/_shared/renderers.module.mjs +0 -13
- package/dist/integrations/ai-sdk/index.d.mts +0 -3
- package/dist/integrations/ai-sdk/index.mjs +0 -1
- package/dist/integrations/ai-sdk/map-parts.d.mts +0 -44
- package/dist/integrations/ai-sdk/map-parts.mjs +0 -56
- package/dist/integrations/json-render/catalog.d.mts +0 -1359
- package/dist/integrations/json-render/catalog.mjs +0 -373
- package/dist/integrations/json-render/registry.d.mts +0 -26
- package/dist/integrations/json-render/registry.mjs +0 -192
- package/dist/integrations/openui/form-views.d.mts +0 -24
- package/dist/integrations/openui/form-views.mjs +0 -89
- package/dist/integrations/openui/library.d.mts +0 -202
- package/dist/integrations/openui/library.mjs +0 -83
- package/dist/integrations/openui/prompt.d.mts +0 -2
- package/dist/integrations/openui/prompt.mjs +0 -18
- /package/dist/components/{observers → _internal}/fragment-instance.d.mts +0 -0
- /package/dist/components/{observers/in-view → _internal}/in-view.d.mts +0 -0
- /package/dist/components/{observers/resize → _internal}/resize.d.mts +0 -0
|
@@ -1,55 +1,380 @@
|
|
|
1
|
-
# Generative UI (
|
|
1
|
+
# Generative UI (the catalog)
|
|
2
2
|
|
|
3
|
-
`@k8ordo/ui`
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
`@k8ordo/ui` describes its own components for an LLM, for no generative-UI
|
|
4
|
+
format in particular: what each component is, the props a model may write,
|
|
5
|
+
whether it holds children, and which prop holds a field's value. The props are
|
|
6
|
+
pinned to the design tokens, so a UI a model composes from them cannot drift
|
|
7
|
+
off-brand.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
The library ties itself to no format. json-render, OpenUI, A2UI, or your own
|
|
10
|
+
format each needs a small piece of glue that maps over the catalog — see
|
|
11
|
+
[Connecting a format](#connecting-a-format). `zod` is the only peer the catalog
|
|
12
|
+
needs:
|
|
9
13
|
|
|
10
14
|
```bash
|
|
11
|
-
|
|
12
|
-
pnpm add @json-render/core @json-render/react zod
|
|
13
|
-
# OpenUI — both entries import lang-core directly, so install both packages
|
|
14
|
-
pnpm add @openuidev/react-lang @openuidev/lang-core zod
|
|
15
|
+
pnpm add zod
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
## The two entries
|
|
19
|
+
|
|
20
|
+
- `@k8ordo/ui/catalog` is **server-safe**: it imports no React, so a Server
|
|
21
|
+
Component or an API route can build the system prompt from it.
|
|
22
|
+
- `@k8ordo/ui/catalog/render` is `'use client'`: how each component is drawn.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { catalog, catalogRules, catalogPropIssues } from '@k8ordo/ui/catalog';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
'use client';
|
|
30
|
+
import { renderers } from '@k8ordo/ui/catalog/render';
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## What an entry says
|
|
34
|
+
|
|
35
|
+
`catalog` maps each component's name to an entry:
|
|
36
|
+
|
|
37
|
+
- `description`: what the component is, for the model.
|
|
38
|
+
- `props`: a zod object of the props the model writes.
|
|
39
|
+
- `children: true`: the component lays out children of its own (`Stack`,
|
|
40
|
+
`Card`, `Dialog`, …). Absent for every other component.
|
|
41
|
+
- `value`: present on a field. `value.prop` is the prop that carries the value
|
|
42
|
+
the field starts from (`defaultValue`, `defaultChecked`, or `defaultPage`), and
|
|
43
|
+
`value.initial(props)` is what it starts from when nothing is bound to it.
|
|
44
|
+
- `events`: present on a component the user acts on in a way the application
|
|
45
|
+
should hear about. It maps each event's name to a description for the model.
|
|
46
|
+
`Button`, `IconButton`, `Card`, and `DropdownMenuItem` have one, `press`.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
catalog.TextField;
|
|
50
|
+
// {
|
|
51
|
+
// description: 'Single-line text input. type picks the kind of value: …',
|
|
52
|
+
// props: z.object({ name, label, placeholder, … }),
|
|
53
|
+
// value: { prop: 'defaultValue', initial: (props) => props.defaultValue ?? '' },
|
|
54
|
+
// }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The types follow the table: `CatalogName` is the union of the names,
|
|
58
|
+
`CatalogProps<'Button'>` the props of one component, `CatalogValueOf<'Slider'>`
|
|
59
|
+
the value of one field (`never` for a component that is not a field), and
|
|
60
|
+
`CatalogEventOf<'Card'>` the events of one component (`never` for none).
|
|
61
|
+
|
|
62
|
+
The key order of every `props` schema is part of the contract. A format with
|
|
63
|
+
positional arguments (OpenUI Lang) maps the arguments back to props by that
|
|
64
|
+
order, so an optional key is only ever appended. A new required key breaks every
|
|
65
|
+
saved string of its entry anyway, so it goes where it reads best: a field's
|
|
66
|
+
`label` comes right after its `name`.
|
|
67
|
+
|
|
68
|
+
Some entries' `props` also check props against each other (see
|
|
69
|
+
[Checking what a model wrote](#checking-what-a-model-wrote)). zod keeps such a
|
|
70
|
+
check only on the schema it was written on: `.omit()`, `.pick()`, and
|
|
71
|
+
`.partial()` throw on these entries, and `.extend()` throws when it replaces a
|
|
72
|
+
key, so a glue that derives a schema from one uses `.safeExtend()`. The checks
|
|
73
|
+
do not reach JSON Schema either (`z.toJSONSchema` leaves them out): only a zod
|
|
74
|
+
parse, or `catalogPropIssues`, applies them.
|
|
75
|
+
|
|
76
|
+
## Drawing
|
|
77
|
+
|
|
78
|
+
`renderers` has the same names as `catalog`. Call one with props that fit the
|
|
79
|
+
entry's schema (see below) and the children the format drew — one node per
|
|
80
|
+
child, keyed; `Children.toArray` keys them. A component without children takes
|
|
81
|
+
none. A field also takes its value and a setter, so the format decides
|
|
82
|
+
where the value lives: in its own state, or in the component's. A component
|
|
83
|
+
with events takes `on`, the handler of each event the model bound. Leave an
|
|
84
|
+
event out of `on` when the model bound nothing to it: an unbound `Card` is not
|
|
85
|
+
pressable, and an unbound button presses to no effect. A handler may return a
|
|
86
|
+
promise; the button or card is busy until it settles.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
'use client';
|
|
90
|
+
import { renderers } from '@k8ordo/ui/catalog/render';
|
|
91
|
+
|
|
92
|
+
renderers.Button({
|
|
93
|
+
props: { label: 'Save' },
|
|
94
|
+
on: { press: () => sendToAgent('save') },
|
|
95
|
+
});
|
|
96
|
+
renderers.TextField({
|
|
97
|
+
props: { name: 'title', label: 'Title' },
|
|
98
|
+
value,
|
|
99
|
+
setValue,
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The props a renderer takes are values that fit the entry's `props` schema, with
|
|
104
|
+
no `null`: a prop the model left out is absent or `undefined`. A renderer does
|
|
105
|
+
not tidy up what a format wrote; the glue does, before it calls one. It drops
|
|
106
|
+
every `null` key, nested ones included (OpenUI Lang, for one, writes an omitted
|
|
107
|
+
positional argument as `null`), parses the rest with the entry's `props`
|
|
108
|
+
schema, and hands the renderer what the parse returns. A format's own
|
|
109
|
+
validation is not enough: JSON Schema leaves zod's own checks out, and OpenUI
|
|
110
|
+
does not check `pattern`. An element whose props do not parse is drawn as
|
|
111
|
+
nothing; while a spec streams in, it appears once they do. That includes an
|
|
112
|
+
element with an unknown key inside an object nested in its props (a `Table`
|
|
113
|
+
column, an `Accordion` item, an option): the schema refuses the key. An
|
|
114
|
+
unknown prop at the top of the props is dropped instead, and the element is
|
|
115
|
+
drawn without it. A field's value bound to the format's state is left out of
|
|
116
|
+
the parse, since the user, not the model, wrote it.
|
|
117
|
+
|
|
118
|
+
`Form` submits nothing, not even on Enter in a field: a submission is the press
|
|
119
|
+
of a `Button` inside it. A `Button` or `Card` with `href` is a link and reports
|
|
120
|
+
no press.
|
|
121
|
+
|
|
122
|
+
Draw the generated UI inside your application's `ToastProvider`, the one its own
|
|
123
|
+
`useToast` reads. A `Toast` opens its toast there, in the same region, under the
|
|
124
|
+
same limit, as the application's own. Outside one, drawing a `Toast` fails with
|
|
125
|
+
`useToast`'s error.
|
|
126
|
+
|
|
127
|
+
## Connecting a format
|
|
128
|
+
|
|
129
|
+
The glue for a format does three things, each by mapping over `catalog`:
|
|
130
|
+
|
|
131
|
+
1. **Register** every component with the format, by name, with its
|
|
132
|
+
`description` and its `props` schema. A component with `children: true`
|
|
133
|
+
gets the format's way of holding children — json-render's `slots`, a
|
|
134
|
+
`children` prop in OpenUI.
|
|
135
|
+
2. **Bind** each field: read the format's state at `value.prop` (json-render's
|
|
136
|
+
`$bindState`, OpenUI's form state by `name`, A2UI's `{"@path": ...}` into
|
|
137
|
+
the data model), starting from `value.initial(props)` when nothing is bound.
|
|
138
|
+
Bind each of `events` to the format's own action — A2UI's `action` prop,
|
|
139
|
+
json-render's `on`, an OpenUI action prop — and hand the bound ones to the
|
|
140
|
+
renderer as `on`. What an action does then (report to the agent, or change
|
|
141
|
+
the format's own state) is the format's.
|
|
142
|
+
3. **Draw** each component through `renderers`: drop the `null` keys, parse
|
|
143
|
+
the rest with the entry's `props` schema, and hand the renderer what the
|
|
144
|
+
parse returns. Draw nothing for an element that fails (see
|
|
145
|
+
[Drawing](#drawing)).
|
|
146
|
+
|
|
147
|
+
Since no step names a component, a component added to `@k8ordo/ui` reaches
|
|
148
|
+
every format without a change to the glue, and a new format is one new piece of
|
|
149
|
+
glue.
|
|
150
|
+
|
|
151
|
+
The glue knows a component's name only at run time, where each entry's own
|
|
152
|
+
types are of no use. `@k8ordo/ui/catalog` and `@k8ordo/ui/catalog/render`
|
|
153
|
+
each export a view with those types erased, so the glue needs no cast: every
|
|
154
|
+
entry of `catalog` is assignable to `AnyCatalogEntry`, whose `value.initial`
|
|
155
|
+
takes any props, and `rendererOf(name)` returns the renderer as an
|
|
156
|
+
`AnyRenderer`, which takes `AnyRenderArgs` — the parsed props as
|
|
157
|
+
`Record<string, unknown>`, and a field's value and setter as `unknown`. A name
|
|
158
|
+
the format hands over as a string becomes a `CatalogName` through
|
|
159
|
+
`isCatalogName(name)`, and `catalogNames` lists every entry's name, so building
|
|
160
|
+
a format's registry needs no cast either.
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
'use client';
|
|
164
|
+
import { catalog } from '@k8ordo/ui/catalog';
|
|
165
|
+
import type { AnyCatalogEntry, CatalogName } from '@k8ordo/ui/catalog';
|
|
166
|
+
import { rendererOf } from '@k8ordo/ui/catalog/render';
|
|
167
|
+
import type { AnyRenderArgs } from '@k8ordo/ui/catalog/render';
|
|
168
|
+
|
|
169
|
+
// args.props: what the format resolved, its null keys dropped
|
|
170
|
+
const draw = (name: CatalogName, args: AnyRenderArgs) => {
|
|
171
|
+
const entry: AnyCatalogEntry = catalog[name];
|
|
172
|
+
const parsed = entry.props.safeParse(args.props);
|
|
173
|
+
if (!parsed.success) return null;
|
|
174
|
+
return rendererOf(name)({
|
|
175
|
+
...args,
|
|
176
|
+
props: parsed.data,
|
|
177
|
+
value: args.value ?? entry.value?.initial(parsed.data),
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The repository keeps working glue for A2UI 1.0, json-render, OpenUI, and the AI SDK in
|
|
183
|
+
[`examples/ui-integrations`](https://github.com/k35o/k8ordo/tree/main/examples/ui-integrations),
|
|
184
|
+
run in a real browser on every change. Copy the one you use into your
|
|
185
|
+
application and own it: the glue depends on the format's own release cycle, not
|
|
186
|
+
on `@k8ordo/ui`'s.
|
|
187
|
+
|
|
188
|
+
json-render, for example, is registered like this (the full glue adds the
|
|
189
|
+
system prompt, validation, and a ready-wired `<JsonRenderUI spec={spec} />`):
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { defineCatalog } from '@json-render/core';
|
|
193
|
+
import { schema } from '@json-render/react/schema';
|
|
194
|
+
import { catalog as k8ordo } from '@k8ordo/ui/catalog';
|
|
195
|
+
|
|
196
|
+
export const catalog = defineCatalog(schema, {
|
|
197
|
+
components: Object.fromEntries(
|
|
198
|
+
Object.entries(k8ordo).map(([name, entry]) => [
|
|
199
|
+
name,
|
|
200
|
+
{
|
|
201
|
+
props: entry.props,
|
|
202
|
+
description:
|
|
203
|
+
entry.value === undefined
|
|
204
|
+
? entry.description
|
|
205
|
+
: `${entry.description} ${entry.value.prop} can be bound to state with $bindState.`,
|
|
206
|
+
...(entry.children === true ? { slots: ['default'] } : {}),
|
|
207
|
+
},
|
|
208
|
+
]),
|
|
209
|
+
),
|
|
210
|
+
actions: {},
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Checking what a model wrote
|
|
215
|
+
|
|
216
|
+
`catalogPropIssues(type, props)` checks one component the model wrote and
|
|
217
|
+
returns what is wrong with it, in English, ready to send back to the model. An
|
|
218
|
+
empty array means the component exists and its props are valid.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
catalogPropIssues('Anchor', {
|
|
222
|
+
label: 'Docs',
|
|
223
|
+
href: 'ftp://example.com',
|
|
224
|
+
rel: 'x',
|
|
225
|
+
});
|
|
226
|
+
// [
|
|
227
|
+
// 'Anchor.href: …',
|
|
228
|
+
// 'Anchor: Unknown prop "rel". Allowed props: label, href, …',
|
|
229
|
+
// ]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Unknown props are reported too. zod drops a key the schema does not know rather
|
|
233
|
+
than failing, so a prop the model invented would otherwise pass and render as if
|
|
234
|
+
it were not there. An object nested in the props — a `Table` column, an
|
|
235
|
+
`Accordion` item, an option — refuses a key it does not know, and the issue
|
|
236
|
+
names the path of that object:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
catalogPropIssues('Table', {
|
|
240
|
+
columns: [{ label: 'Name' }, { label: 'Qty', width: 80 }],
|
|
241
|
+
rows: [['Apple', '3']],
|
|
242
|
+
});
|
|
243
|
+
// ['Table.columns.1: Unknown prop "width". Allowed props: label, align.']
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Run it on every element of a spec, after the format's own structural check,
|
|
247
|
+
and send the issues back as a repair prompt.
|
|
248
|
+
|
|
249
|
+
Props are also checked against each other, each issue under the path it is at
|
|
250
|
+
and in the same round as the other issues of the component, as long as the
|
|
251
|
+
props the check reads are valid themselves. Every row of a `Table` or
|
|
252
|
+
`DataTable` must have as many cells as there are columns. A `TextField` whose
|
|
253
|
+
`type` is a date or time kind takes a `defaultValue` in the input format of
|
|
254
|
+
that kind, as `DatePicker` does: a real calendar day as `YYYY-MM-DD` for
|
|
255
|
+
`date`, `HH:MM` or `HH:MM:SS` for `time`, `YYYY-MM-DDTHH:MM` with optional
|
|
256
|
+
seconds for `datetime-local`, `YYYY-MM` for `month`, and `YYYY-Www` for
|
|
257
|
+
`week`. The `defaultValue` of `Select`, `Radio`,
|
|
258
|
+
`RadioCard`, `ListBox`, `CheckboxGroup`, and `CheckboxCard` must be the `value`
|
|
259
|
+
of one of its `options` (each entry of it, for the two that take an array):
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
catalogPropIssues('Table', {
|
|
263
|
+
caption: 3,
|
|
264
|
+
columns: [{ label: 'Name' }, { label: 'Qty' }],
|
|
265
|
+
rows: [['Apple', '3'], ['Orange']],
|
|
266
|
+
});
|
|
267
|
+
// [
|
|
268
|
+
// 'Table.caption: Invalid input: expected string, received number',
|
|
269
|
+
// 'Table.rows.1: Expected 2 cells (one per column), received 1',
|
|
270
|
+
// ]
|
|
271
|
+
|
|
272
|
+
catalogPropIssues('CheckboxGroup', {
|
|
273
|
+
name: 'tags',
|
|
274
|
+
label: 'Tags',
|
|
275
|
+
options: [
|
|
276
|
+
{ value: 'news', label: 'News' },
|
|
277
|
+
{ value: 'blog', label: 'Blog' },
|
|
278
|
+
],
|
|
279
|
+
defaultValue: ['news', 'Blog'],
|
|
280
|
+
});
|
|
281
|
+
// ['CheckboxGroup.defaultValue.1: Expected the value of an option ("news" | "blog"), received "Blog"']
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
A prop the format resolves later, such as one a json-render spec binds with
|
|
285
|
+
`{ "$bindState": "/form/name" }`, cannot be checked as a value yet. Name it in
|
|
286
|
+
`unresolved`: its name is still checked, its value is not, and a required one
|
|
287
|
+
is not reported missing. A check across props that needs it is not made.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
catalogPropIssues(
|
|
291
|
+
'TextField',
|
|
292
|
+
{
|
|
293
|
+
name: 'nickname',
|
|
294
|
+
label: 'Nickname',
|
|
295
|
+
defaultValue: { $bindState: '/form/nickname' },
|
|
296
|
+
},
|
|
297
|
+
{ unresolved: ['defaultValue'] },
|
|
298
|
+
);
|
|
299
|
+
// []
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Prompt language
|
|
303
|
+
|
|
304
|
+
Everything the catalog hands the model — the descriptions, the schemas'
|
|
305
|
+
descriptions, `catalogRules`, and the issues `catalogPropIssues` returns — is
|
|
306
|
+
English, whatever your application's locale. The model reads it; your users
|
|
307
|
+
never see it.
|
|
308
|
+
|
|
309
|
+
`catalogRules` holds the cross-cutting constraints a model most often breaks
|
|
310
|
+
(a `Table` row with as many cells as there are columns, the `href` format, plain
|
|
311
|
+
text inside `Tabs` and `Accordion`). Pass it to the format's system prompt, and
|
|
312
|
+
add a rule of your own to pin the language of the text the model writes into the
|
|
313
|
+
UI:
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
// json-render
|
|
317
|
+
catalog.prompt({
|
|
318
|
+
customRules: [...catalogRules, 'Write all UI text in Japanese.'],
|
|
319
|
+
});
|
|
320
|
+
// OpenUI
|
|
321
|
+
prompt({
|
|
322
|
+
additionalRules: [...catalogRules, 'Write all UI text in Japanese.'],
|
|
323
|
+
});
|
|
324
|
+
```
|
|
36
325
|
|
|
37
326
|
## What the catalog covers
|
|
38
327
|
|
|
39
|
-
|
|
40
|
-
|
|
328
|
+
The entries, under the category of the component each one draws. An entry that
|
|
329
|
+
is no exported component of its own is under Catalog only.
|
|
330
|
+
|
|
331
|
+
<!-- generated:catalog-entries -->
|
|
332
|
+
|
|
333
|
+
- **Buttons**: `Button`, `IconButton`, `CopyButton`, `Toolbar`
|
|
334
|
+
- **Navigation**: `Anchor`, `Breadcrumb`, `Pagination`, `Stepper`, `SideNav`,
|
|
335
|
+
`Tabs`
|
|
336
|
+
- **Forms**: `Form`, `TextField`, `Textarea`, `PasswordInput`, `NumberField`,
|
|
337
|
+
`Slider`, `RangeSlider`, `DatePicker`, `Calendar`, `ColorPicker`, `Combobox`,
|
|
338
|
+
`Checkbox`, `Switch`, `Select`, `Radio`, `RadioCard`, `CheckboxCard`,
|
|
339
|
+
`CheckboxGroup`, `Autocomplete`, `FileField`
|
|
340
|
+
- **Data display**: `Card`, `Carousel`, `Badge`, `Heading`, `Avatar`, `Code`,
|
|
341
|
+
`Kbd`, `Accordion`, `Table`, `DataTable`, `Tree`
|
|
342
|
+
- **Feedback**: `EmptyState`, `Alert`, `Callout`, `Spinner`, `Progress`,
|
|
343
|
+
`Skeleton`
|
|
344
|
+
- **Overlays**: `Dialog`, `Drawer`, `Popover`, `Tooltip`, `DropdownMenu`,
|
|
345
|
+
`ListBox`
|
|
346
|
+
- **Layout**: `Stack`, `Grid`, `Separator`
|
|
347
|
+
- **Catalog only**: `Icon`, `DropdownMenuItem`, `Toast`
|
|
348
|
+
|
|
349
|
+
<!-- /generated:catalog-entries -->
|
|
350
|
+
|
|
351
|
+
Most entries are the exported component of the same name. A few are shaped for a
|
|
41
352
|
model instead:
|
|
42
353
|
|
|
43
354
|
- **Icons** are one `Icon` entry whose `name` picks the glyph. Every icon in
|
|
44
355
|
`@k8ordo/ui/icons` that needs nothing but a size is there, under its name in
|
|
45
356
|
kebab-case without the suffix: `eye-closed` is `EyeClosedIcon`. `ChevronIcon`
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
`
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
357
|
+
and `AlertIcon` are not there by name: each draws one of the icons above,
|
|
358
|
+
picked by `direction` or `status`, so a spec names that icon instead
|
|
359
|
+
(`chevron-down`, `circle-check`).
|
|
360
|
+
- **Fields** each take a required `label` and an optional `helpText`, and are
|
|
361
|
+
drawn through `FormControl`'s `renderInput`. The label is a `<label for>`
|
|
362
|
+
tied to the input, or, for a group (`Radio`, `RadioCard`, `CheckboxGroup`,
|
|
363
|
+
`CheckboxCard`, `RangeSlider`, `FileField`), the heading the group is named
|
|
364
|
+
by (`labelAs="group"`). The help text sits under the field and describes it.
|
|
365
|
+
`Checkbox` and `Switch` are not wrapped in `FormControl`: their `label` is
|
|
366
|
+
their own, and they draw `helpText` themselves. `ListBox` is a button that
|
|
367
|
+
opens a list, and its required `label` names the button.
|
|
368
|
+
- **Toasts** are a `Toast` entry, standing in for `useToast`: a widget whose
|
|
369
|
+
`triggerLabel` button opens the toast through your application's
|
|
370
|
+
`ToastProvider` (see [Drawing](#drawing)).
|
|
371
|
+
- **Overlays** (`Dialog`, `Drawer`, `Popover`, `Tooltip`, `DropdownMenu`) are
|
|
372
|
+
self-contained widgets. Each declares its own trigger with `triggerLabel` and
|
|
373
|
+
handles opening and closing itself. `Dialog` opens in the center or along the
|
|
374
|
+
bottom edge and `Drawer` along the left or right one, each by its `side`, as
|
|
375
|
+
the components do. The items of a `DropdownMenu` are its children, each a
|
|
376
|
+
`DropdownMenuItem` with its own `press`, so the menu needs no event of its
|
|
377
|
+
own to say which item was chosen.
|
|
53
378
|
- **Compound components** (`Tabs`, `Accordion`, `Table`, `Breadcrumb`, …) are
|
|
54
379
|
one entry each, with their parts flattened into data such as
|
|
55
380
|
`tabs: [{ label, content }]`. `Carousel` is one container entry whose
|
|
@@ -67,12 +392,6 @@ These exports are left out on purpose, so a model cannot place them:
|
|
|
67
392
|
- `ContextMenu` — it opens on a right-click, which nothing on screen invites,
|
|
68
393
|
so actions put in it would be hidden in a generated UI. It belongs on your
|
|
69
394
|
application's own content (a file, a row).
|
|
70
|
-
- `InView`, `Resize` — they report to a callback and draw nothing of their own,
|
|
71
|
-
and a spec has no code to receive the report.
|
|
72
|
-
- `UIProvider` — your application mounts it once, around the generated UI as
|
|
73
|
-
well.
|
|
74
|
-
- `PortalRootProvider`, `usePortalRoot` — wiring for your own `createPortal`
|
|
75
|
-
calls. The generated overlays open their own surfaces.
|
|
76
395
|
- `Conversation`, `Message`, `PromptInput`, `Reasoning`, `Suggestion`,
|
|
77
396
|
`ToolInvocation`, `Attachment`, and `Source` from `@k8ordo/ui/ai`, and
|
|
78
397
|
`Response` from
|
|
@@ -95,151 +414,20 @@ These exports are left out on purpose, so a model cannot place them:
|
|
|
95
414
|
lay a flow out with `Stack`.
|
|
96
415
|
- `BaseIcon` — the base your own icons are drawn on. It has no glyph of its
|
|
97
416
|
own, and a spec picks a glyph by `name`.
|
|
417
|
+
- `FormControl` — every field in the catalog takes its own `label` and
|
|
418
|
+
`helpText` and is drawn through `FormControl` already (see
|
|
419
|
+
[What the catalog covers](#what-the-catalog-covers)). An entry for the frame
|
|
420
|
+
alone would be a second way to write the same field.
|
|
98
421
|
- `TableOfContents` — it points at the ids of the document's headings and
|
|
99
422
|
follows the scroll. The headings a spec places carry no id, so there would be
|
|
100
423
|
nothing to point at.
|
|
101
424
|
|
|
102
|
-
## Prompt language
|
|
103
|
-
|
|
104
|
-
Everything the adapters hand the model — component descriptions, `uiRules`,
|
|
105
|
-
schema descriptions, and the repair prompt — is English, whatever your
|
|
106
|
-
application's locale. The model reads it; your users never see it. To pin the
|
|
107
|
-
language of the text the model writes into the UI, add a rule of your own:
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
// json-render
|
|
111
|
-
catalog.prompt({ customRules: [...uiRules, 'Write all UI text in Japanese.'] });
|
|
112
|
-
// OpenUI
|
|
113
|
-
prompt({ additionalRules: ['Write all UI text in Japanese.'] });
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## json-render
|
|
117
|
-
|
|
118
|
-
The catalog (schemas and prompt) is separate from the registry (rendering), and
|
|
119
|
-
the catalog is **server-safe**.
|
|
120
|
-
|
|
121
|
-
### 1. Generate the prompt on the server
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
|
-
import { catalog, uiRules } from '@k8ordo/ui/json-render';
|
|
125
|
-
|
|
126
|
-
// customRules injects the cross-cutting constraints an LLM most often breaks
|
|
127
|
-
// (cell count matching columns in Table, href format, text-only content in
|
|
128
|
-
// Tabs and Accordion).
|
|
129
|
-
const systemPrompt = catalog.prompt({ customRules: [...uiRules] });
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 2. Render on the client
|
|
133
|
-
|
|
134
|
-
`JsonRenderUI` already wires up `JSONUIProvider` + `Renderer` + registry
|
|
135
|
-
internally, so passing the spec is enough. Pass `onStateChange` when you need to
|
|
136
|
-
collect form values.
|
|
137
|
-
|
|
138
|
-
```tsx
|
|
139
|
-
'use client';
|
|
140
|
-
import type { UISpec } from '@k8ordo/ui/json-render';
|
|
141
|
-
import { JsonRenderUI } from '@k8ordo/ui/json-render/registry';
|
|
142
|
-
|
|
143
|
-
export function GenUi({ spec }: { spec: UISpec }) {
|
|
144
|
-
return <JsonRenderUI spec={spec} />;
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Props:
|
|
149
|
-
|
|
150
|
-
- `spec`: `Spec | null` (required; a `UISpec` is assignable to json-render's `Spec` without a cast, and `null` renders nothing)
|
|
151
|
-
- `loading`: boolean (passed to `Renderer`: set it while the spec is still streaming in, so children that have not arrived yet are skipped without a warning)
|
|
152
|
-
- `onStateChange`: `(changes: Array<{ path: string; value: unknown }>) => void` (called once per state update with every changed path and its new value)
|
|
153
|
-
|
|
154
|
-
For an advanced setup (your own `navigate`, `handlers`, or
|
|
155
|
-
`validationFunctions`), pass the low-level `registry` straight to
|
|
156
|
-
`@json-render/react`'s `JSONUIProvider` / `Renderer`.
|
|
157
|
-
|
|
158
|
-
### 3. Validate LLM output, then render or repair it
|
|
159
|
-
|
|
160
|
-
`validateGeneratedSpec` applies mechanical fixes, validates the structure, then
|
|
161
|
-
validates props per component. On failure it returns the `issues` it found (each
|
|
162
|
-
a `message`, plus the `elementKey` of the offending element when there is one)
|
|
163
|
-
and a repair prompt built from them that you can send straight back to the LLM.
|
|
164
|
-
Use it instead of `catalog.validate()`, which rejects valid specs in the current
|
|
165
|
-
upstream version. The result and issue types are exported as
|
|
166
|
-
`ValidateGeneratedSpecResult` and `GeneratedSpecIssue`.
|
|
167
|
-
|
|
168
|
-
```tsx
|
|
169
|
-
import { validateGeneratedSpec } from '@k8ordo/ui/json-render';
|
|
170
|
-
|
|
171
|
-
const result = validateGeneratedSpec(JSON.parse(llmOutput));
|
|
172
|
-
if (result.ok) {
|
|
173
|
-
// result.fixes lists what was auto-corrected
|
|
174
|
-
return <JsonRenderUI spec={result.spec} />;
|
|
175
|
-
}
|
|
176
|
-
// If it is broken, regenerate with the repair prompt
|
|
177
|
-
const retried = await llm(result.repairPrompt);
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### 4. Typed specs (optional)
|
|
181
|
-
|
|
182
|
-
Writing `satisfies UISpec` turns a typo in a component name or prop into a
|
|
183
|
-
compile error, and removes the need for `as unknown as Spec`.
|
|
184
|
-
|
|
185
|
-
```tsx
|
|
186
|
-
import type { UISpec } from '@k8ordo/ui/json-render';
|
|
187
|
-
|
|
188
|
-
const spec = {
|
|
189
|
-
root: 'root',
|
|
190
|
-
elements: {
|
|
191
|
-
root: { type: 'Stack', props: { direction: 'column' }, children: ['ok'] },
|
|
192
|
-
ok: { type: 'Button', props: { label: 'OK' } },
|
|
193
|
-
},
|
|
194
|
-
} satisfies UISpec;
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
`UISpecElement` (one element of a `UISpec`), `ComponentName`, and
|
|
198
|
-
`ComponentProps<K>` are exported as well, so you can pull out the props type of a
|
|
199
|
-
specific component.
|
|
200
|
-
|
|
201
|
-
## OpenUI
|
|
202
|
-
|
|
203
|
-
A model where children are expressed as typed subcomponents
|
|
204
|
-
(`z.array(Child.ref)`). Rendering is `'use client'`.
|
|
205
|
-
|
|
206
|
-
```tsx
|
|
207
|
-
'use client';
|
|
208
|
-
import { library } from '@k8ordo/ui/openui';
|
|
209
|
-
import { Renderer } from '@openuidev/react-lang';
|
|
210
|
-
|
|
211
|
-
export function GenUi({ response }: { response: string }) {
|
|
212
|
-
return <Renderer library={library} response={response} />;
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
The system prompt comes from a dedicated server-safe entry, mirroring
|
|
217
|
-
json-render's `catalog.prompt()`.
|
|
218
|
-
|
|
219
|
-
```tsx
|
|
220
|
-
import { prompt } from '@k8ordo/ui/openui/prompt';
|
|
221
|
-
|
|
222
|
-
const systemPrompt = prompt(); // No React dependency — callable from RSC or an API route
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
`prompt` takes an optional `PromptOptions` from `@openuidev/lang-core`
|
|
226
|
-
(`preamble`, `additionalRules`, `examples`, …) and passes it straight through to
|
|
227
|
-
the library's prompt generation.
|
|
228
|
-
|
|
229
|
-
Containers nest freely in OpenUI, as they do in json-render: `Stack`, `Grid`,
|
|
230
|
-
`Card`, `Form`, `Modal`, `Dialog`, `Drawer`, and `Popover` each list every
|
|
231
|
-
container among their children, so a `Card` can sit inside a `Stack` and a
|
|
232
|
-
`Stack` inside another `Stack`.
|
|
233
|
-
|
|
234
425
|
## Exports at a glance
|
|
235
426
|
|
|
236
|
-
| Export
|
|
237
|
-
|
|
|
238
|
-
| `@k8ordo/ui/
|
|
239
|
-
| `@k8ordo/ui/
|
|
240
|
-
| `@k8ordo/ui/openui` | `'use client'` | `library` (rendering) |
|
|
241
|
-
| `@k8ordo/ui/openui/prompt` | server-safe | `prompt(options?)` (prompt generation) |
|
|
427
|
+
| Export | Kind | Contents |
|
|
428
|
+
| --------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
429
|
+
| `@k8ordo/ui/catalog` | server-safe | `catalog`, `catalogNames`, `isCatalogName`, `catalogRules`, `catalogPropIssues`, types (`CatalogName`, `CatalogProps`, `CatalogEntry`, `AnyCatalogEntry`, …) |
|
|
430
|
+
| `@k8ordo/ui/catalog/render` | `'use client'` | `renderers`, `rendererOf`, types (`RenderArgs`, `Renderer`, `AnyRenderArgs`, `AnyRenderer`) |
|
|
242
431
|
|
|
243
|
-
>
|
|
244
|
-
> `@k8ordo/ui/tailwind.css` after Tailwind, in a Tailwind CSS 4 project)
|
|
245
|
-
> wrapped the tree in `UIProvider`.
|
|
432
|
+
> The drawn components assume you have loaded `@k8ordo/ui/styles.css` (or
|
|
433
|
+
> `@k8ordo/ui/tailwind.css` after Tailwind, in a Tailwind CSS 4 project).
|
|
@@ -70,10 +70,11 @@ duration-150 ease-out`.
|
|
|
70
70
|
## Focus management
|
|
71
71
|
|
|
72
72
|
- Use `:focus-visible`, not `:focus` — no ring appears on a mouse click
|
|
73
|
+
- A date or time `<input>` is the exception and takes the ring on `:focus` as well. Its inner parts (year, month, day) hold the focus, and WebKit then matches `:focus` on the input but never `:focus-visible`. Chromium and Firefox match `:focus-visible` on such a field whenever it has focus, a mouse click included, so `:focus` adds nothing there. `TextField` does this
|
|
73
74
|
- Keep the focus ring consistent with `--shadow-ring-info`
|
|
74
75
|
- Clear the default outline before applying the ring, and give it back under forced colors, where the ring (a shadow) disappears
|
|
75
|
-
- Keep focus on a button that is waiting on its own action: show the wait with `aria-busy` and `aria-disabled` and ignore presses, rather than setting `disabled`. Chromium moves focus to `body` when the focused element becomes disabled, so the keyboard user who pressed it loses their place. `Button` and `IconButton` do this for `
|
|
76
|
-
- For the same reason, a text field whose form's action is pending turns `readOnly`, not `disabled`, and ignores the keys that would change its value, so the user who pressed Enter in it keeps their place. `TextField`, `Textarea`, `PasswordInput`, `NumberField`, `
|
|
76
|
+
- Keep focus on a button that is waiting on its own action: show the wait with `aria-busy` and `aria-disabled` and ignore presses, rather than setting `disabled`. Chromium moves focus to `body` when the focused element becomes disabled, so the keyboard user who pressed it loses their place. `Button` and `IconButton` do this for `action`
|
|
77
|
+
- For the same reason, a text field whose form's action is pending turns `readOnly`, not `disabled`, and ignores the keys that would change its value, so the user who pressed Enter in it keeps their place. `TextField`, `Textarea`, `PasswordInput`, `NumberField`, `DatePicker`, `ColorPicker`, `Combobox`, and `Autocomplete` do this. `readOnly` does not apply to a checkbox, radio, range, or select, yet Enter in one still submits the form through its submit button, so `Checkbox`, `Radio`, `Switch`, `CheckboxCard`, `RadioCard`, `Slider`, `RangeSlider`, and `Select` take `aria-disabled` instead and ignore what would change their value. A checkbox or radio cancels the click in the capture phase and stops it there: cancelled any later, React's change tracking has already recorded the toggle the browser then undoes, calls `onChange` for it, and misses the next real one. A range ignores the arrow, Home, End, and Page keys and the pointer; a select ignores those keys, Space, F4, typed characters, and the pointer
|
|
77
78
|
|
|
78
79
|
```css
|
|
79
80
|
.control:focus-visible {
|
|
@@ -91,9 +92,9 @@ duration-150 ease-out`.
|
|
|
91
92
|
|
|
92
93
|
- Put the label above the input (a left-aligned label reads badly in Japanese)
|
|
93
94
|
- Put the error message directly under the input, in `--color-fg-error` at `--font-size-sm`
|
|
94
|
-
- Mark required
|
|
95
|
+
- Mark a required field after its label: `FormControl`'s `required` draws the built-in `required` wording there. A single field's mark is hidden from screen readers, since the input's own `required` already says it; with `labelAs="group"` — a group, or `FileField`, whose trigger is a button — the mark is part of the name, since neither a group nor a button can be required itself
|
|
95
96
|
- Validate on submit; keep real-time validation to a minimum
|
|
96
|
-
- Use the `FormControl` component so labels and errors stay consistent
|
|
97
|
+
- Use the `FormControl` component so labels and errors stay consistent. `Checkbox` and `Switch` carry their own label instead, and take `errorText` / `helpText` themselves
|
|
97
98
|
|
|
98
99
|
```tsx
|
|
99
100
|
import { FormControl, TextField } from '@k8ordo/ui';
|
|
@@ -112,7 +113,7 @@ import { FormControl, TextField } from '@k8ordo/ui';
|
|
|
112
113
|
|
|
113
114
|
- Set `aria-label` / `aria-describedby` where they belong
|
|
114
115
|
- Guarantee keyboard navigation (Tab, Enter, Escape, arrow keys)
|
|
115
|
-
- Respect `prefers-reduced-motion`. Under it the stylesheet turns off the open animation of Popover and what is built on it (DropdownMenu, ListBox, Tooltip), the Toast,
|
|
116
|
+
- Respect `prefers-reduced-motion`. Under it the stylesheet turns off the open animation of Popover and what is built on it (DropdownMenu, ListBox, Tooltip), the Toast, Dialog, and Drawer animations, the Tabs indicator slide, and every view transition; `Card`'s hover scale runs only under `prefers-reduced-motion: no-preference`. Skeleton's pulse, Spinner's spin, and the Accordion chevron, Switch thumb, and Progress bar transitions keep running. Put your own motion under `@media (prefers-reduced-motion: no-preference)`
|
|
116
117
|
- Never signal state with color alone; pair it with an icon or text
|
|
117
118
|
- The components follow `prefers-contrast: more` and stay legible under `forced-colors: active` (see [High contrast and forced colors](./color.md#high-contrast-and-forced-colors)); do the same in your own UI
|
|
118
119
|
|