@cognitap/radiant 0.0.90 → 0.0.92
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/CHANGELOG.md +18 -0
- package/dist/library/a2ui/A2uiPlaceholder.d.ts +14 -0
- package/dist/library/a2ui/A2uiPlaceholder.d.ts.map +1 -0
- package/dist/library/a2ui/A2uiPlaceholder.js +44 -0
- package/dist/library/a2ui/A2uiPlaceholder.js.map +1 -0
- package/dist/library/a2ui/A2uiSurface.d.ts +33 -0
- package/dist/library/a2ui/A2uiSurface.d.ts.map +1 -0
- package/dist/library/a2ui/A2uiSurface.js +542 -0
- package/dist/library/a2ui/A2uiSurface.js.map +1 -0
- package/dist/library/a2ui/accessibility.d.ts +31 -0
- package/dist/library/a2ui/accessibility.d.ts.map +1 -0
- package/dist/library/a2ui/accessibility.js +108 -0
- package/dist/library/a2ui/accessibility.js.map +1 -0
- package/dist/library/a2ui/accessibilityRules.d.ts +28 -0
- package/dist/library/a2ui/accessibilityRules.d.ts.map +1 -0
- package/dist/library/a2ui/accessibilityRules.js +73 -0
- package/dist/library/a2ui/accessibilityRules.js.map +1 -0
- package/dist/library/a2ui/catalogGenerator.d.ts +29 -0
- package/dist/library/a2ui/catalogGenerator.d.ts.map +1 -0
- package/dist/library/a2ui/catalogGenerator.js +578 -0
- package/dist/library/a2ui/catalogGenerator.js.map +1 -0
- package/dist/library/a2ui/coerce.d.ts +16 -0
- package/dist/library/a2ui/coerce.d.ts.map +1 -0
- package/dist/library/a2ui/coerce.js +254 -0
- package/dist/library/a2ui/coerce.js.map +1 -0
- package/dist/library/a2ui/entries.d.ts +6 -0
- package/dist/library/a2ui/entries.d.ts.map +1 -0
- package/dist/library/a2ui/entries.js +277 -0
- package/dist/library/a2ui/entries.js.map +1 -0
- package/dist/library/a2ui/fixtures.d.ts +38 -0
- package/dist/library/a2ui/fixtures.d.ts.map +1 -0
- package/dist/library/a2ui/fixtures.js +389 -0
- package/dist/library/a2ui/fixtures.js.map +1 -0
- package/dist/library/a2ui/index.d.ts +17 -0
- package/dist/library/a2ui/index.d.ts.map +1 -0
- package/dist/library/a2ui/index.js +9 -0
- package/dist/library/a2ui/index.js.map +1 -0
- package/dist/library/a2ui/protocolErrors.d.ts +13 -0
- package/dist/library/a2ui/protocolErrors.d.ts.map +1 -0
- package/dist/library/a2ui/protocolErrors.js +48 -0
- package/dist/library/a2ui/protocolErrors.js.map +1 -0
- package/dist/library/a2ui/registry.d.ts +58 -0
- package/dist/library/a2ui/registry.d.ts.map +1 -0
- package/dist/library/a2ui/registry.js +128 -0
- package/dist/library/a2ui/registry.js.map +1 -0
- package/dist/library/a2ui/sanitize.d.ts +7 -0
- package/dist/library/a2ui/sanitize.d.ts.map +1 -0
- package/dist/library/a2ui/sanitize.js +54 -0
- package/dist/library/a2ui/sanitize.js.map +1 -0
- package/dist/library/a2ui/surfaceRuntime.d.ts +34 -0
- package/dist/library/a2ui/surfaceRuntime.d.ts.map +1 -0
- package/dist/library/a2ui/surfaceRuntime.js +284 -0
- package/dist/library/a2ui/surfaceRuntime.js.map +1 -0
- package/dist/library/catalog/actions.d.ts +40 -0
- package/dist/library/catalog/actions.d.ts.map +1 -0
- package/dist/library/catalog/actions.js +70 -0
- package/dist/library/catalog/actions.js.map +1 -0
- package/dist/library/catalog/coerce.d.ts +70 -0
- package/dist/library/catalog/coerce.d.ts.map +1 -0
- package/dist/library/catalog/coerce.js +332 -0
- package/dist/library/catalog/coerce.js.map +1 -0
- package/dist/library/catalog/index.d.ts +9 -0
- package/dist/library/catalog/index.d.ts.map +1 -0
- package/dist/library/catalog/index.js +6 -0
- package/dist/library/catalog/index.js.map +1 -0
- package/dist/library/catalog/radiantCatalog.d.ts +9 -0
- package/dist/library/catalog/radiantCatalog.d.ts.map +1 -0
- package/dist/library/catalog/radiantCatalog.js +902 -0
- package/dist/library/catalog/radiantCatalog.js.map +1 -0
- package/dist/library/catalog/types.d.ts +113 -0
- package/dist/library/catalog/types.d.ts.map +1 -0
- package/dist/library/catalog/types.js +27 -0
- package/dist/library/catalog/types.js.map +1 -0
- package/dist/library/catalog/validate.d.ts +31 -0
- package/dist/library/catalog/validate.d.ts.map +1 -0
- package/dist/library/catalog/validate.js +420 -0
- package/dist/library/catalog/validate.js.map +1 -0
- package/dist/library/components/Card/Card.d.ts +6 -2
- package/dist/library/components/Card/Card.d.ts.map +1 -1
- package/dist/library/components/Card/Card.js +12 -4
- package/dist/library/components/Card/Card.js.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.js +2 -2
- package/dist/library/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.js +1 -1
- package/dist/library/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/library/components/InputGroup/InputGroup.js +1 -1
- package/dist/library/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/library/components/NavLink/NavLink.d.ts.map +1 -1
- package/dist/library/components/NavLink/NavLink.js +1 -1
- package/dist/library/components/NavLink/NavLink.js.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.js +3 -3
- package/dist/library/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.d.ts.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.js +4 -1
- package/dist/library/components/ScrollArea/ScrollArea.js.map +1 -1
- package/dist/library/components/Switch/Switch.d.ts.map +1 -1
- package/dist/library/components/Switch/Switch.js +2 -2
- package/dist/library/components/Switch/Switch.js.map +1 -1
- package/dist/library/components/Table/Table.d.ts +6 -2
- package/dist/library/components/Table/Table.d.ts.map +1 -1
- package/dist/library/components/Table/Table.js +10 -4
- package/dist/library/components/Table/Table.js.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.d.ts.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.js +1 -1
- package/dist/library/components/TagsInput/TagsInput.js.map +1 -1
- package/dist/library/components/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/library/components/TimeInput/TimeInput.js +28 -20
- package/dist/library/components/TimeInput/TimeInput.js.map +1 -1
- package/dist/library/components/Toast/Toast.js +1 -1
- package/dist/library/components/Toast/Toast.js.map +1 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js +1 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js.map +1 -1
- package/dist/library/index.d.ts +1 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/presentation.d.ts +3 -0
- package/dist/library/presentation.d.ts.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +6 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +6 -0
- package/dist/library/themes/components.js.map +1 -1
- package/dist/library/themes/tokens.d.ts +4 -0
- package/dist/library/themes/tokens.d.ts.map +1 -1
- package/dist/library/themes/tokens.js +3 -0
- package/dist/library/themes/tokens.js.map +1 -1
- package/docs/accessibility.md +6 -0
- package/docs/architecture.md +20 -1
- package/docs/theming.md +13 -0
- package/package.json +17 -5
- package/src/a2ui/A2uiPlaceholder.tsx +64 -0
- package/src/a2ui/A2uiSurface.tsx +790 -0
- package/src/a2ui/accessibility.ts +145 -0
- package/src/a2ui/accessibilityRules.ts +106 -0
- package/src/a2ui/catalog.json +317 -0
- package/src/a2ui/catalogGenerator.ts +717 -0
- package/src/a2ui/coerce.ts +379 -0
- package/src/a2ui/entries.tsx +519 -0
- package/src/a2ui/fixtures.ts +402 -0
- package/src/a2ui/index.ts +50 -0
- package/src/a2ui/protocolErrors.ts +63 -0
- package/src/a2ui/registry.ts +221 -0
- package/src/a2ui/sanitize.ts +51 -0
- package/src/a2ui/surfaceRuntime.ts +317 -0
- package/src/catalog/actions.ts +108 -0
- package/src/catalog/coerce.ts +447 -0
- package/src/catalog/index.ts +67 -0
- package/src/catalog/radiantCatalog.ts +949 -0
- package/src/catalog/types.ts +159 -0
- package/src/catalog/validate.ts +454 -0
- package/src/components/Card/Card.tsx +35 -19
- package/src/components/Checkbox/Checkbox.tsx +2 -0
- package/src/components/Collapsible/Collapsible.tsx +1 -1
- package/src/components/InputGroup/InputGroup.tsx +2 -2
- package/src/components/NavLink/NavLink.tsx +1 -6
- package/src/components/RadioGroup/RadioGroup.tsx +3 -0
- package/src/components/ScrollArea/ScrollArea.tsx +5 -1
- package/src/components/Switch/Switch.tsx +2 -0
- package/src/components/Table/Table.tsx +16 -3
- package/src/components/TagsInput/TagsInput.tsx +1 -0
- package/src/components/TimeInput/TimeInput.tsx +100 -75
- package/src/components/Toast/Toast.tsx +1 -1
- package/src/components/ToggleGroup/ToggleGroup.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/presentation.ts +3 -0
- package/src/themes/baseline.css +3 -0
- package/src/themes/components.ts +6 -0
- package/src/themes/tokens.ts +7 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Fragment, useState, type ChangeEvent, type Ref } from 'react'
|
|
4
|
+
import {
|
|
5
|
+
isComponentNode,
|
|
6
|
+
isWritable,
|
|
7
|
+
ResolvedBinding,
|
|
8
|
+
type ComponentNode,
|
|
9
|
+
type NodeAction
|
|
10
|
+
} from '@a2ui/web_core/resolution'
|
|
11
|
+
import { Button, type ButtonVariant } from '../components/Button/Button.js'
|
|
12
|
+
import { Checkbox } from '../components/Checkbox/Checkbox.js'
|
|
13
|
+
import { CheckboxGroup } from '../components/CheckboxGroup/CheckboxGroup.js'
|
|
14
|
+
import { Field } from '../components/Field/Field.js'
|
|
15
|
+
import { Input } from '../components/Input/Input.js'
|
|
16
|
+
import { Radio, RadioGroup } from '../components/RadioGroup/RadioGroup.js'
|
|
17
|
+
import { Slider } from '../components/Slider/Slider.js'
|
|
18
|
+
import { Textarea } from '../components/Textarea/Textarea.js'
|
|
19
|
+
import { ToggleGroup, ToggleGroupItem } from '../components/ToggleGroup/ToggleGroup.js'
|
|
20
|
+
import { radiantCatalog } from '../catalog/index.js'
|
|
21
|
+
import { humanizeNodeId } from '../catalog/coerce.js'
|
|
22
|
+
import {
|
|
23
|
+
A2UI_BASIC_CATALOG_ID,
|
|
24
|
+
generateA2uiCatalogs,
|
|
25
|
+
type A2uiJsonSchema
|
|
26
|
+
} from './catalogGenerator.js'
|
|
27
|
+
import { createA2uiRegistry, createA2uiRegistryEntry } from './registry.js'
|
|
28
|
+
import { buttonNameRule, controlLabelRule } from './accessibilityRules.js'
|
|
29
|
+
|
|
30
|
+
function unwrapDisplayText(value: unknown): string {
|
|
31
|
+
const raw = value instanceof ResolvedBinding ? value.value : value
|
|
32
|
+
if (typeof raw === 'string') return raw
|
|
33
|
+
if (typeof raw === 'number' && Number.isFinite(raw)) return String(raw)
|
|
34
|
+
if (typeof raw === 'boolean') return String(raw)
|
|
35
|
+
return ''
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function unwrapString(value: unknown): string | undefined {
|
|
39
|
+
if (value instanceof ResolvedBinding) {
|
|
40
|
+
return typeof value.value === 'string' ? value.value : undefined
|
|
41
|
+
}
|
|
42
|
+
return typeof value === 'string' ? value : undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function unwrapBoolean(value: unknown): boolean | undefined {
|
|
46
|
+
const raw = value instanceof ResolvedBinding ? value.value : value
|
|
47
|
+
return typeof raw === 'boolean' ? raw : undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function unwrapNumber(value: unknown): number | undefined {
|
|
51
|
+
const raw = value instanceof ResolvedBinding ? value.value : value
|
|
52
|
+
return typeof raw === 'number' && Number.isFinite(raw) ? raw : undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function unwrapStringList(value: unknown): string[] {
|
|
56
|
+
const raw = value instanceof ResolvedBinding ? value.value : value
|
|
57
|
+
return Array.isArray(raw) ? raw.filter((item): item is string => typeof item === 'string') : []
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function writeBinding(raw: unknown, nextValue: unknown) {
|
|
61
|
+
if (raw instanceof ResolvedBinding && isWritable(raw)) {
|
|
62
|
+
raw.set(nextValue)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readValidationError(props: Readonly<Record<string, unknown>>): string | undefined {
|
|
67
|
+
const errors = props.validationErrors
|
|
68
|
+
if (!Array.isArray(errors) || errors.length === 0) return undefined
|
|
69
|
+
const first = errors[0]
|
|
70
|
+
return typeof first === 'string' && first.length > 0 ? first : undefined
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const basicCatalog = generateA2uiCatalogs(radiantCatalog).basic
|
|
74
|
+
|
|
75
|
+
function basicSchema(name: string): A2uiJsonSchema {
|
|
76
|
+
const schema = basicCatalog.components[name]
|
|
77
|
+
if (!schema) {
|
|
78
|
+
throw new TypeError(`A2UI basic catalog generator did not emit schema for "${name}".`)
|
|
79
|
+
}
|
|
80
|
+
return schema
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const COLUMN_JUSTIFY: Record<string, string> = {
|
|
84
|
+
start: 'justify-start',
|
|
85
|
+
center: 'justify-center',
|
|
86
|
+
end: 'justify-end',
|
|
87
|
+
spaceBetween: 'justify-between',
|
|
88
|
+
spaceAround: 'justify-around',
|
|
89
|
+
spaceEvenly: 'justify-evenly',
|
|
90
|
+
stretch: 'justify-stretch'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const COLUMN_ALIGN: Record<string, string> = {
|
|
94
|
+
start: 'items-start',
|
|
95
|
+
center: 'items-center',
|
|
96
|
+
end: 'items-end',
|
|
97
|
+
stretch: 'items-stretch'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const columnEntry = createA2uiRegistryEntry({
|
|
101
|
+
name: 'Column',
|
|
102
|
+
accessibility: [],
|
|
103
|
+
component: 'div',
|
|
104
|
+
schema: basicSchema('Column'),
|
|
105
|
+
description: radiantCatalog.entries.Column.description,
|
|
106
|
+
adapter(props, context) {
|
|
107
|
+
const children = Array.isArray(props.children)
|
|
108
|
+
? props.children.filter((child): child is ComponentNode => isComponentNode(child))
|
|
109
|
+
: []
|
|
110
|
+
const justify =
|
|
111
|
+
typeof props.justify === 'string' && props.justify in COLUMN_JUSTIFY
|
|
112
|
+
? COLUMN_JUSTIFY[props.justify]
|
|
113
|
+
: COLUMN_JUSTIFY.start
|
|
114
|
+
const align =
|
|
115
|
+
typeof props.align === 'string' && props.align in COLUMN_ALIGN
|
|
116
|
+
? COLUMN_ALIGN[props.align]
|
|
117
|
+
: COLUMN_ALIGN.stretch
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div
|
|
121
|
+
data-slot="a2ui-column"
|
|
122
|
+
className={`flex flex-col gap-[var(--rad-surface-gap,1rem)] ${justify} ${align}`}
|
|
123
|
+
>
|
|
124
|
+
{children.map(child => (
|
|
125
|
+
<Fragment key={child.id}>{context.renderNode(child)}</Fragment>
|
|
126
|
+
))}
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const textEntry = createA2uiRegistryEntry({
|
|
133
|
+
name: 'Text',
|
|
134
|
+
accessibility: [],
|
|
135
|
+
component: 'p',
|
|
136
|
+
schema: basicSchema('Text'),
|
|
137
|
+
description: radiantCatalog.entries.Text.description,
|
|
138
|
+
adapter(props, context) {
|
|
139
|
+
const text = unwrapDisplayText(props.text)
|
|
140
|
+
const variant = props.variant === 'caption' ? 'caption' : 'body'
|
|
141
|
+
// Text bound to a data path with no value yet reserves its line.
|
|
142
|
+
const reserve =
|
|
143
|
+
props.text instanceof ResolvedBinding && props.text.value === undefined
|
|
144
|
+
? ' block min-h-[1lh]'
|
|
145
|
+
: ''
|
|
146
|
+
if (context.inline) {
|
|
147
|
+
return (
|
|
148
|
+
<span
|
|
149
|
+
data-slot="a2ui-text"
|
|
150
|
+
data-variant={variant}
|
|
151
|
+
>
|
|
152
|
+
{text}
|
|
153
|
+
</span>
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
if (variant === 'caption') {
|
|
157
|
+
return (
|
|
158
|
+
<span
|
|
159
|
+
data-slot="a2ui-text"
|
|
160
|
+
data-variant="caption"
|
|
161
|
+
className={`text-[length:var(--rad-typography-roles-ui-supporting-size,0.8125rem)] leading-[var(--rad-typography-roles-ui-supporting-line-height,1.4)] [color:var(--rad-color-muted-foreground,oklch(0.45_0.01_286))]${reserve}`}
|
|
162
|
+
>
|
|
163
|
+
{text}
|
|
164
|
+
</span>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
return (
|
|
168
|
+
<p
|
|
169
|
+
data-slot="a2ui-text"
|
|
170
|
+
data-variant="body"
|
|
171
|
+
className={`m-0 text-[length:var(--rad-typography-roles-ui-body-size,1rem)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] [color:var(--rad-color-foreground,oklch(0.21_0.006_286))]${reserve}`}
|
|
172
|
+
>
|
|
173
|
+
{text}
|
|
174
|
+
</p>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
const TEXT_FIELD_INPUT_TYPE: Record<string, string> = {
|
|
180
|
+
shortText: 'text',
|
|
181
|
+
number: 'number',
|
|
182
|
+
obscured: 'password'
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const textFieldEntry = createA2uiRegistryEntry({
|
|
186
|
+
name: 'TextField',
|
|
187
|
+
accessibility: [controlLabelRule({ fixFrom: ['accessibility.label', 'placeholder'] })],
|
|
188
|
+
component: [Field, Input, Textarea],
|
|
189
|
+
schema: basicSchema('TextField'),
|
|
190
|
+
description: radiantCatalog.entries.TextField.description,
|
|
191
|
+
adapter(props) {
|
|
192
|
+
const label = unwrapString(props.label) ?? ''
|
|
193
|
+
const placeholder = unwrapString(props.placeholder)
|
|
194
|
+
const error = readValidationError(props)
|
|
195
|
+
const rawValue = props.value
|
|
196
|
+
const valueBinding = rawValue instanceof ResolvedBinding ? rawValue : undefined
|
|
197
|
+
const value = unwrapString(rawValue) ?? ''
|
|
198
|
+
const variant = typeof props.variant === 'string' ? props.variant : 'shortText'
|
|
199
|
+
|
|
200
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
201
|
+
if (valueBinding && isWritable(valueBinding)) {
|
|
202
|
+
valueBinding.set(event.currentTarget.value)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<Field
|
|
208
|
+
label={label}
|
|
209
|
+
error={error}
|
|
210
|
+
>
|
|
211
|
+
{variant === 'longText' ? (
|
|
212
|
+
<Textarea
|
|
213
|
+
value={value}
|
|
214
|
+
placeholder={placeholder}
|
|
215
|
+
onChange={handleChange}
|
|
216
|
+
/>
|
|
217
|
+
) : (
|
|
218
|
+
<Input
|
|
219
|
+
type={TEXT_FIELD_INPUT_TYPE[variant] ?? 'text'}
|
|
220
|
+
value={value}
|
|
221
|
+
placeholder={placeholder}
|
|
222
|
+
onChange={handleChange}
|
|
223
|
+
/>
|
|
224
|
+
)}
|
|
225
|
+
</Field>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
const BUTTON_VARIANT_MAP: Record<string, ButtonVariant> = {
|
|
231
|
+
default: 'soft',
|
|
232
|
+
primary: 'solid',
|
|
233
|
+
borderless: 'ghost'
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const buttonEntry = createA2uiRegistryEntry({
|
|
237
|
+
name: 'Button',
|
|
238
|
+
accessibility: [buttonNameRule()],
|
|
239
|
+
component: Button,
|
|
240
|
+
schema: basicSchema('Button'),
|
|
241
|
+
description: radiantCatalog.entries.Button.description,
|
|
242
|
+
adapter(props, context) {
|
|
243
|
+
const variant: ButtonVariant =
|
|
244
|
+
typeof props.variant === 'string' && props.variant in BUTTON_VARIANT_MAP
|
|
245
|
+
? BUTTON_VARIANT_MAP[props.variant]!
|
|
246
|
+
: 'soft'
|
|
247
|
+
const childNode = isComponentNode(props.child) ? props.child : undefined
|
|
248
|
+
const action = typeof props.action === 'function' ? (props.action as NodeAction) : undefined
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<Button
|
|
252
|
+
variant={variant}
|
|
253
|
+
onClick={() => {
|
|
254
|
+
void action?.()
|
|
255
|
+
}}
|
|
256
|
+
>
|
|
257
|
+
{childNode ? context.renderNode(childNode, { inline: true }) : null}
|
|
258
|
+
</Button>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
function resolveControlLabel(
|
|
264
|
+
props: Readonly<Record<string, unknown>>,
|
|
265
|
+
componentId: string
|
|
266
|
+
): { readonly text: string; readonly srOnly: boolean } {
|
|
267
|
+
const visible = unwrapDisplayText(props.label).trim()
|
|
268
|
+
if (visible) return { text: visible, srOnly: false }
|
|
269
|
+
const accessibility =
|
|
270
|
+
props.accessibility && typeof props.accessibility === 'object'
|
|
271
|
+
? (props.accessibility as Record<string, unknown>)
|
|
272
|
+
: undefined
|
|
273
|
+
const accessible = unwrapDisplayText(accessibility?.label).trim()
|
|
274
|
+
if (accessible) return { text: accessible, srOnly: true }
|
|
275
|
+
return { text: humanizeNodeId(componentId), srOnly: false }
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const SR_ONLY_LABEL_PARTS = { label: { className: 'sr-only' } } as const
|
|
279
|
+
|
|
280
|
+
const checkBoxEntry = createA2uiRegistryEntry({
|
|
281
|
+
name: 'CheckBox',
|
|
282
|
+
accessibility: [controlLabelRule({ fixFrom: ['accessibility.label'] })],
|
|
283
|
+
component: [Checkbox, Field],
|
|
284
|
+
schema: basicSchema('CheckBox'),
|
|
285
|
+
description: radiantCatalog.entries.Checkbox.description,
|
|
286
|
+
adapter(props) {
|
|
287
|
+
const label = unwrapDisplayText(props.label)
|
|
288
|
+
const error = readValidationError(props)
|
|
289
|
+
const checked = unwrapBoolean(props.value) ?? false
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<Field
|
|
293
|
+
label={label}
|
|
294
|
+
error={error}
|
|
295
|
+
>
|
|
296
|
+
<Checkbox
|
|
297
|
+
checked={checked}
|
|
298
|
+
onChange={event => writeBinding(props.value, event.currentTarget.checked)}
|
|
299
|
+
/>
|
|
300
|
+
</Field>
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
type ChoiceOptionItem = { readonly value: string; readonly label: string }
|
|
306
|
+
|
|
307
|
+
function readChoiceOptions(raw: unknown): readonly ChoiceOptionItem[] {
|
|
308
|
+
if (!Array.isArray(raw)) return []
|
|
309
|
+
const seen = new Set<string>()
|
|
310
|
+
const items: ChoiceOptionItem[] = []
|
|
311
|
+
for (const option of raw) {
|
|
312
|
+
if (!option || typeof option !== 'object') continue
|
|
313
|
+
const record = option as Record<string, unknown>
|
|
314
|
+
if (typeof record.value !== 'string' || seen.has(record.value)) continue
|
|
315
|
+
seen.add(record.value)
|
|
316
|
+
items.push({ value: record.value, label: unwrapDisplayText(record.label) || record.value })
|
|
317
|
+
}
|
|
318
|
+
return items
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function A2uiChoicePicker({
|
|
322
|
+
ref,
|
|
323
|
+
label,
|
|
324
|
+
srOnly,
|
|
325
|
+
error,
|
|
326
|
+
options,
|
|
327
|
+
selected,
|
|
328
|
+
multiple,
|
|
329
|
+
chips,
|
|
330
|
+
filterable,
|
|
331
|
+
onSelect
|
|
332
|
+
}: {
|
|
333
|
+
ref?: Ref<HTMLElement>
|
|
334
|
+
label: string
|
|
335
|
+
srOnly: boolean
|
|
336
|
+
error?: string
|
|
337
|
+
options: readonly ChoiceOptionItem[]
|
|
338
|
+
selected: readonly string[]
|
|
339
|
+
multiple: boolean
|
|
340
|
+
chips: boolean
|
|
341
|
+
filterable: boolean
|
|
342
|
+
onSelect: (next: string[]) => void
|
|
343
|
+
}) {
|
|
344
|
+
const [query, setQuery] = useState('')
|
|
345
|
+
const needle = query.trim().toLowerCase()
|
|
346
|
+
const visible =
|
|
347
|
+
filterable && needle ? options.filter(o => o.label.toLowerCase().includes(needle)) : options
|
|
348
|
+
const parts = srOnly ? SR_ONLY_LABEL_PARTS : undefined
|
|
349
|
+
const filterInput = filterable ? (
|
|
350
|
+
<Input
|
|
351
|
+
type="search"
|
|
352
|
+
aria-label={`Filter ${label}`}
|
|
353
|
+
placeholder={`Filter ${label}`}
|
|
354
|
+
value={query}
|
|
355
|
+
onChange={e => setQuery(e.currentTarget.value)}
|
|
356
|
+
/>
|
|
357
|
+
) : null
|
|
358
|
+
|
|
359
|
+
if (chips) {
|
|
360
|
+
const items = visible.map(o => (
|
|
361
|
+
<ToggleGroupItem
|
|
362
|
+
key={o.value}
|
|
363
|
+
value={o.value}
|
|
364
|
+
>
|
|
365
|
+
{o.label}
|
|
366
|
+
</ToggleGroupItem>
|
|
367
|
+
))
|
|
368
|
+
return (
|
|
369
|
+
<Field
|
|
370
|
+
ref={ref as Ref<HTMLFieldSetElement>}
|
|
371
|
+
layout="group"
|
|
372
|
+
label={label}
|
|
373
|
+
error={error}
|
|
374
|
+
parts={parts}
|
|
375
|
+
>
|
|
376
|
+
{filterInput}
|
|
377
|
+
{multiple ? (
|
|
378
|
+
<ToggleGroup
|
|
379
|
+
type="multiple"
|
|
380
|
+
aria-label={label}
|
|
381
|
+
value={[...selected]}
|
|
382
|
+
onValueChange={onSelect}
|
|
383
|
+
>
|
|
384
|
+
{items}
|
|
385
|
+
</ToggleGroup>
|
|
386
|
+
) : (
|
|
387
|
+
<ToggleGroup
|
|
388
|
+
type="single"
|
|
389
|
+
aria-label={label}
|
|
390
|
+
value={selected[0] ?? null}
|
|
391
|
+
onValueChange={next => onSelect(next ? [next] : [])}
|
|
392
|
+
>
|
|
393
|
+
{items}
|
|
394
|
+
</ToggleGroup>
|
|
395
|
+
)}
|
|
396
|
+
</Field>
|
|
397
|
+
)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const group = multiple ? (
|
|
401
|
+
<CheckboxGroup
|
|
402
|
+
label={label}
|
|
403
|
+
error={error}
|
|
404
|
+
parts={parts}
|
|
405
|
+
items={visible}
|
|
406
|
+
value={[...selected]}
|
|
407
|
+
onValueChange={onSelect}
|
|
408
|
+
/>
|
|
409
|
+
) : (
|
|
410
|
+
<RadioGroup
|
|
411
|
+
label={label}
|
|
412
|
+
error={error}
|
|
413
|
+
parts={parts}
|
|
414
|
+
value={selected[0] ?? null}
|
|
415
|
+
onValueChange={next => onSelect([next])}
|
|
416
|
+
>
|
|
417
|
+
{visible.map(o => (
|
|
418
|
+
<Radio
|
|
419
|
+
key={o.value}
|
|
420
|
+
value={o.value}
|
|
421
|
+
label={o.label}
|
|
422
|
+
/>
|
|
423
|
+
))}
|
|
424
|
+
</RadioGroup>
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
return (
|
|
428
|
+
<div
|
|
429
|
+
ref={ref as Ref<HTMLDivElement>}
|
|
430
|
+
data-slot="a2ui-choice-picker"
|
|
431
|
+
className="grid gap-2"
|
|
432
|
+
>
|
|
433
|
+
{filterInput}
|
|
434
|
+
{group}
|
|
435
|
+
</div>
|
|
436
|
+
)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const choicePickerEntry = createA2uiRegistryEntry({
|
|
440
|
+
name: 'ChoicePicker',
|
|
441
|
+
accessibility: [controlLabelRule({ alternatives: ['accessibility.label'] })],
|
|
442
|
+
component: [RadioGroup, Radio, CheckboxGroup, ToggleGroup, ToggleGroupItem, Input, Field],
|
|
443
|
+
schema: basicSchema('ChoicePicker'),
|
|
444
|
+
description: radiantCatalog.entries.Choice.description,
|
|
445
|
+
adapter(props, context) {
|
|
446
|
+
const label = resolveControlLabel(props, context.node.componentId)
|
|
447
|
+
return (
|
|
448
|
+
<A2uiChoicePicker
|
|
449
|
+
label={label.text}
|
|
450
|
+
srOnly={label.srOnly}
|
|
451
|
+
error={readValidationError(props)}
|
|
452
|
+
options={readChoiceOptions(props.options)}
|
|
453
|
+
selected={unwrapStringList(props.value)}
|
|
454
|
+
multiple={props.variant === 'multipleSelection'}
|
|
455
|
+
chips={props.displayStyle === 'chips'}
|
|
456
|
+
filterable={props.filterable === true}
|
|
457
|
+
onSelect={next => writeBinding(props.value, next)}
|
|
458
|
+
/>
|
|
459
|
+
)
|
|
460
|
+
}
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
const sliderEntry = createA2uiRegistryEntry({
|
|
464
|
+
name: 'Slider',
|
|
465
|
+
accessibility: [controlLabelRule({ alternatives: ['accessibility.label'] })],
|
|
466
|
+
component: [Field, Slider],
|
|
467
|
+
schema: basicSchema('Slider'),
|
|
468
|
+
description: radiantCatalog.entries.Slider.description,
|
|
469
|
+
adapter(props, context) {
|
|
470
|
+
const label = resolveControlLabel(props, context.node.componentId)
|
|
471
|
+
const error = readValidationError(props)
|
|
472
|
+
const min = typeof props.min === 'number' && Number.isFinite(props.min) ? props.min : 0
|
|
473
|
+
const rawMax = typeof props.max === 'number' && Number.isFinite(props.max) ? props.max : 100
|
|
474
|
+
const max = rawMax >= min ? rawMax : min
|
|
475
|
+
const rawValue = unwrapNumber(props.value) ?? min
|
|
476
|
+
const value = Math.min(max, Math.max(min, rawValue))
|
|
477
|
+
const steps =
|
|
478
|
+
typeof props.steps === 'number' && Number.isFinite(props.steps) && props.steps >= 1
|
|
479
|
+
? props.steps
|
|
480
|
+
: undefined
|
|
481
|
+
const step = steps && max > min ? (max - min) / steps : undefined
|
|
482
|
+
|
|
483
|
+
return (
|
|
484
|
+
<Field
|
|
485
|
+
label={label.text}
|
|
486
|
+
error={error}
|
|
487
|
+
parts={label.srOnly ? SR_ONLY_LABEL_PARTS : undefined}
|
|
488
|
+
>
|
|
489
|
+
<Slider
|
|
490
|
+
min={min}
|
|
491
|
+
max={max}
|
|
492
|
+
step={step}
|
|
493
|
+
value={value}
|
|
494
|
+
onValueChange={next => writeBinding(props.value, next)}
|
|
495
|
+
/>
|
|
496
|
+
</Field>
|
|
497
|
+
)
|
|
498
|
+
}
|
|
499
|
+
})
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Radiant's built-in A2UI 1.0 component registry.
|
|
503
|
+
* Generated catalog JSON (`src/a2ui/catalog.json`) is derived directly from this registry.
|
|
504
|
+
*/
|
|
505
|
+
export const radiantA2uiRegistry = createA2uiRegistry({
|
|
506
|
+
catalogId: A2UI_BASIC_CATALOG_ID,
|
|
507
|
+
title: 'Radiant A2UI 1.0 Catalog',
|
|
508
|
+
description:
|
|
509
|
+
'A2UI 1.0 catalog generated from Radiant registry entries backed by @cognitap/radiant/catalog.',
|
|
510
|
+
entries: [
|
|
511
|
+
columnEntry,
|
|
512
|
+
textEntry,
|
|
513
|
+
textFieldEntry,
|
|
514
|
+
checkBoxEntry,
|
|
515
|
+
choicePickerEntry,
|
|
516
|
+
sliderEntry,
|
|
517
|
+
buttonEntry
|
|
518
|
+
]
|
|
519
|
+
})
|