@easyops-cn/a2ui-react 0.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.
Files changed (161) hide show
  1. package/.claude/commands/speckit.analyze.md +184 -0
  2. package/.claude/commands/speckit.checklist.md +294 -0
  3. package/.claude/commands/speckit.clarify.md +181 -0
  4. package/.claude/commands/speckit.constitution.md +82 -0
  5. package/.claude/commands/speckit.implement.md +135 -0
  6. package/.claude/commands/speckit.plan.md +89 -0
  7. package/.claude/commands/speckit.specify.md +256 -0
  8. package/.claude/commands/speckit.tasks.md +137 -0
  9. package/.claude/commands/speckit.taskstoissues.md +30 -0
  10. package/.github/workflows/deploy.yml +69 -0
  11. package/.husky/pre-commit +1 -0
  12. package/.prettierignore +4 -0
  13. package/.prettierrc +7 -0
  14. package/.specify/memory/constitution.md +73 -0
  15. package/.specify/scripts/bash/check-prerequisites.sh +166 -0
  16. package/.specify/scripts/bash/common.sh +156 -0
  17. package/.specify/scripts/bash/create-new-feature.sh +297 -0
  18. package/.specify/scripts/bash/setup-plan.sh +61 -0
  19. package/.specify/scripts/bash/update-agent-context.sh +799 -0
  20. package/.specify/templates/agent-file-template.md +28 -0
  21. package/.specify/templates/checklist-template.md +40 -0
  22. package/.specify/templates/plan-template.md +105 -0
  23. package/.specify/templates/spec-template.md +115 -0
  24. package/.specify/templates/tasks-template.md +250 -0
  25. package/CLAUDE.md +105 -0
  26. package/CONTRIBUTING.md +97 -0
  27. package/README.md +126 -0
  28. package/components.json +21 -0
  29. package/eslint.config.js +25 -0
  30. package/netlify.toml +50 -0
  31. package/package.json +94 -0
  32. package/playground/README.md +75 -0
  33. package/playground/index.html +22 -0
  34. package/playground/package.json +32 -0
  35. package/playground/public/favicon.svg +8 -0
  36. package/playground/src/App.css +256 -0
  37. package/playground/src/App.tsx +115 -0
  38. package/playground/src/assets/react.svg +1 -0
  39. package/playground/src/components/ErrorDisplay.tsx +13 -0
  40. package/playground/src/components/ExampleSelector.tsx +64 -0
  41. package/playground/src/components/Header.tsx +47 -0
  42. package/playground/src/components/JsonEditor.tsx +32 -0
  43. package/playground/src/components/Preview.tsx +78 -0
  44. package/playground/src/components/ThemeToggle.tsx +19 -0
  45. package/playground/src/data/examples.ts +1571 -0
  46. package/playground/src/hooks/useTheme.ts +55 -0
  47. package/playground/src/index.css +220 -0
  48. package/playground/src/main.tsx +10 -0
  49. package/playground/tsconfig.app.json +34 -0
  50. package/playground/tsconfig.json +13 -0
  51. package/playground/tsconfig.node.json +26 -0
  52. package/playground/vite.config.ts +31 -0
  53. package/specs/001-a2ui-renderer/checklists/requirements.md +41 -0
  54. package/specs/001-a2ui-renderer/data-model.md +140 -0
  55. package/specs/001-a2ui-renderer/plan.md +123 -0
  56. package/specs/001-a2ui-renderer/quickstart.md +141 -0
  57. package/specs/001-a2ui-renderer/research.md +140 -0
  58. package/specs/001-a2ui-renderer/spec.md +165 -0
  59. package/specs/001-a2ui-renderer/tasks.md +310 -0
  60. package/specs/002-playground/checklists/requirements.md +37 -0
  61. package/specs/002-playground/contracts/components.md +120 -0
  62. package/specs/002-playground/data-model.md +149 -0
  63. package/specs/002-playground/plan.md +73 -0
  64. package/specs/002-playground/quickstart.md +158 -0
  65. package/specs/002-playground/research.md +117 -0
  66. package/specs/002-playground/spec.md +109 -0
  67. package/specs/002-playground/tasks.md +224 -0
  68. package/src/0.8/A2UIRender.test.tsx +793 -0
  69. package/src/0.8/A2UIRender.tsx +142 -0
  70. package/src/0.8/components/ComponentRenderer.test.tsx +373 -0
  71. package/src/0.8/components/ComponentRenderer.tsx +163 -0
  72. package/src/0.8/components/UnknownComponent.tsx +49 -0
  73. package/src/0.8/components/display/AudioPlayerComponent.tsx +37 -0
  74. package/src/0.8/components/display/DividerComponent.tsx +23 -0
  75. package/src/0.8/components/display/IconComponent.tsx +137 -0
  76. package/src/0.8/components/display/ImageComponent.tsx +57 -0
  77. package/src/0.8/components/display/TextComponent.tsx +56 -0
  78. package/src/0.8/components/display/VideoComponent.tsx +31 -0
  79. package/src/0.8/components/display/display.test.tsx +660 -0
  80. package/src/0.8/components/display/index.ts +10 -0
  81. package/src/0.8/components/index.ts +14 -0
  82. package/src/0.8/components/interactive/ButtonComponent.tsx +44 -0
  83. package/src/0.8/components/interactive/CheckBoxComponent.tsx +45 -0
  84. package/src/0.8/components/interactive/DateTimeInputComponent.tsx +176 -0
  85. package/src/0.8/components/interactive/MultipleChoiceComponent.tsx +157 -0
  86. package/src/0.8/components/interactive/SliderComponent.tsx +53 -0
  87. package/src/0.8/components/interactive/TextFieldComponent.tsx +65 -0
  88. package/src/0.8/components/interactive/index.ts +10 -0
  89. package/src/0.8/components/interactive/interactive.test.tsx +618 -0
  90. package/src/0.8/components/layout/CardComponent.tsx +30 -0
  91. package/src/0.8/components/layout/ColumnComponent.tsx +93 -0
  92. package/src/0.8/components/layout/ListComponent.tsx +81 -0
  93. package/src/0.8/components/layout/ModalComponent.tsx +41 -0
  94. package/src/0.8/components/layout/RowComponent.tsx +94 -0
  95. package/src/0.8/components/layout/TabsComponent.tsx +59 -0
  96. package/src/0.8/components/layout/index.ts +10 -0
  97. package/src/0.8/components/layout/layout.test.tsx +558 -0
  98. package/src/0.8/contexts/A2UIProvider.test.tsx +226 -0
  99. package/src/0.8/contexts/A2UIProvider.tsx +54 -0
  100. package/src/0.8/contexts/ActionContext.test.tsx +242 -0
  101. package/src/0.8/contexts/ActionContext.tsx +105 -0
  102. package/src/0.8/contexts/ComponentsMapContext.tsx +125 -0
  103. package/src/0.8/contexts/DataModelContext.test.tsx +335 -0
  104. package/src/0.8/contexts/DataModelContext.tsx +184 -0
  105. package/src/0.8/contexts/SurfaceContext.test.tsx +339 -0
  106. package/src/0.8/contexts/SurfaceContext.tsx +197 -0
  107. package/src/0.8/hooks/useA2UIMessageHandler.test.tsx +399 -0
  108. package/src/0.8/hooks/useA2UIMessageHandler.ts +123 -0
  109. package/src/0.8/hooks/useComponent.test.tsx +148 -0
  110. package/src/0.8/hooks/useComponent.ts +39 -0
  111. package/src/0.8/hooks/useDataBinding.test.tsx +334 -0
  112. package/src/0.8/hooks/useDataBinding.ts +99 -0
  113. package/src/0.8/hooks/useDispatchAction.test.tsx +83 -0
  114. package/src/0.8/hooks/useDispatchAction.ts +35 -0
  115. package/src/0.8/hooks/useSurface.test.tsx +114 -0
  116. package/src/0.8/hooks/useSurface.ts +34 -0
  117. package/src/0.8/index.ts +38 -0
  118. package/src/0.8/schemas/client_to_server.json +50 -0
  119. package/src/0.8/schemas/server_to_client.json +148 -0
  120. package/src/0.8/schemas/standard_catalog_definition.json +661 -0
  121. package/src/0.8/types/index.ts +448 -0
  122. package/src/0.8/utils/dataBinding.test.ts +443 -0
  123. package/src/0.8/utils/dataBinding.ts +212 -0
  124. package/src/0.8/utils/pathUtils.test.ts +353 -0
  125. package/src/0.8/utils/pathUtils.ts +200 -0
  126. package/src/components/ui/button.tsx +62 -0
  127. package/src/components/ui/calendar.tsx +220 -0
  128. package/src/components/ui/card.tsx +92 -0
  129. package/src/components/ui/checkbox.tsx +30 -0
  130. package/src/components/ui/dialog.tsx +141 -0
  131. package/src/components/ui/input.tsx +21 -0
  132. package/src/components/ui/label.tsx +22 -0
  133. package/src/components/ui/native-select.tsx +53 -0
  134. package/src/components/ui/popover.tsx +46 -0
  135. package/src/components/ui/select.tsx +188 -0
  136. package/src/components/ui/separator.tsx +26 -0
  137. package/src/components/ui/slider.tsx +61 -0
  138. package/src/components/ui/tabs.tsx +64 -0
  139. package/src/components/ui/textarea.tsx +18 -0
  140. package/src/index.ts +1 -0
  141. package/src/lib/utils.ts +6 -0
  142. package/tsconfig.json +28 -0
  143. package/vite.config.ts +29 -0
  144. package/vitest.config.ts +22 -0
  145. package/vitest.setup.ts +8 -0
  146. package/website/README.md +4 -0
  147. package/website/assets/favicon.svg +8 -0
  148. package/website/content/.gitkeep +0 -0
  149. package/website/content/index.md +122 -0
  150. package/website/global.d.ts +9 -0
  151. package/website/package.json +17 -0
  152. package/website/plain.config.js +28 -0
  153. package/website/serve.json +6 -0
  154. package/website/src/client/color-mode-switch.css +47 -0
  155. package/website/src/client/index.js +61 -0
  156. package/website/src/client/moon.svg +1 -0
  157. package/website/src/client/sun.svg +1 -0
  158. package/website/src/components/Footer.jsx +9 -0
  159. package/website/src/components/Header.jsx +44 -0
  160. package/website/src/components/Page.jsx +28 -0
  161. package/website/src/global.css +423 -0
@@ -0,0 +1,448 @@
1
+ /**
2
+ * A2UI React Renderer - Type Definitions
3
+ *
4
+ * Core type definitions for the A2UI React renderer.
5
+ * Based on the A2UI specification documents.
6
+ */
7
+
8
+ // ============ Value Types ============
9
+
10
+ /**
11
+ * Represents a value source - either a literal value or a reference to a data model path.
12
+ */
13
+ export type ValueSource =
14
+ | { literalString: string }
15
+ | { literalNumber: number }
16
+ | { literalBoolean: boolean }
17
+ | { literalArray: string[] }
18
+ | { path: string }
19
+
20
+ // ============ Data Model ============
21
+
22
+ /**
23
+ * Primitive values that can be stored in the data model.
24
+ */
25
+ export type DataModelValue =
26
+ | string
27
+ | number
28
+ | boolean
29
+ | null
30
+ | DataModel
31
+ | unknown[]
32
+
33
+ /**
34
+ * The data model is a hierarchical key-value store.
35
+ * Components reference data using paths like "/user/name".
36
+ */
37
+ export interface DataModel {
38
+ [key: string]: DataModelValue
39
+ }
40
+
41
+ /**
42
+ * Data entry from server messages (dataModelUpdate).
43
+ */
44
+ export interface DataEntry {
45
+ key: string
46
+ valueString?: string
47
+ valueNumber?: number
48
+ valueBoolean?: boolean
49
+ valueMap?: DataEntry[]
50
+ }
51
+
52
+ // ============ Surface ============
53
+
54
+ /**
55
+ * Surface styles configuration.
56
+ */
57
+ export interface SurfaceStyles {
58
+ font?: string
59
+ primaryColor?: string
60
+ }
61
+
62
+ /**
63
+ * A Surface is the top-level container for A2UI rendering.
64
+ */
65
+ export interface Surface {
66
+ surfaceId: string
67
+ root: string
68
+ components: Map<string, ComponentDefinition>
69
+ styles?: SurfaceStyles
70
+ }
71
+
72
+ // ============ Component Definition ============
73
+
74
+ /**
75
+ * Base component properties that all components share.
76
+ */
77
+ export interface ComponentDefinition {
78
+ id: string
79
+ weight?: number
80
+ component: {
81
+ [componentType: string]: ComponentProps
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Generic component properties type.
87
+ */
88
+ export type ComponentProps = Record<string, unknown>
89
+
90
+ // ============ Children Definition ============
91
+
92
+ /**
93
+ * Template binding for dynamic child generation.
94
+ */
95
+ export interface TemplateBinding {
96
+ componentId: string
97
+ dataBinding: string
98
+ }
99
+
100
+ /**
101
+ * Children definition for container components.
102
+ */
103
+ export interface ChildrenDefinition {
104
+ explicitList?: string[]
105
+ template?: TemplateBinding
106
+ }
107
+
108
+ // ============ Action ============
109
+
110
+ /**
111
+ * A single item in the action context.
112
+ */
113
+ export interface ActionContextItem {
114
+ key: string
115
+ value: ValueSource
116
+ }
117
+
118
+ /**
119
+ * Action definition (attached to Button components).
120
+ */
121
+ export interface Action {
122
+ name: string
123
+ context?: ActionContextItem[]
124
+ }
125
+
126
+ /**
127
+ * Resolved action payload sent to the action handler.
128
+ */
129
+ export interface ActionPayload {
130
+ surfaceId: string
131
+ name: string
132
+ context: Record<string, unknown>
133
+ sourceComponentId: string
134
+ }
135
+
136
+ /**
137
+ * Action handler callback type.
138
+ */
139
+ export type ActionHandler = (action: ActionPayload) => void
140
+
141
+ // ============ Message Types ============
142
+
143
+ /**
144
+ * BeginRendering message payload - initializes a new Surface.
145
+ */
146
+ export interface BeginRenderingPayload {
147
+ surfaceId: string
148
+ root: string
149
+ catalogId?: string
150
+ styles?: SurfaceStyles
151
+ }
152
+
153
+ /**
154
+ * SurfaceUpdate message payload - updates the component tree.
155
+ */
156
+ export interface SurfaceUpdatePayload {
157
+ surfaceId: string
158
+ components: ComponentDefinition[]
159
+ }
160
+
161
+ /**
162
+ * DataModelUpdate message payload - updates the data model.
163
+ */
164
+ export interface DataModelUpdatePayload {
165
+ surfaceId: string
166
+ path?: string
167
+ contents: DataEntry[]
168
+ }
169
+
170
+ /**
171
+ * DeleteSurface message payload - removes a Surface.
172
+ */
173
+ export interface DeleteSurfacePayload {
174
+ surfaceId: string
175
+ }
176
+
177
+ /**
178
+ * A2UI message from server to client.
179
+ * Only one of the fields should be set per message.
180
+ */
181
+ export interface A2UIMessage {
182
+ beginRendering?: BeginRenderingPayload
183
+ surfaceUpdate?: SurfaceUpdatePayload
184
+ dataModelUpdate?: DataModelUpdatePayload
185
+ deleteSurface?: DeleteSurfacePayload
186
+ }
187
+
188
+ // ============ Base Component Props ============
189
+
190
+ /**
191
+ * Base props shared by all A2UI components.
192
+ */
193
+ export interface BaseComponentProps {
194
+ surfaceId: string
195
+ componentId: string
196
+ weight?: number
197
+ }
198
+
199
+ // ============ Display Component Props ============
200
+
201
+ /**
202
+ * Text component properties.
203
+ */
204
+ export interface TextComponentProps extends BaseComponentProps {
205
+ text?: ValueSource
206
+ usageHint?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'caption' | 'body'
207
+ }
208
+
209
+ /**
210
+ * Image component properties.
211
+ */
212
+ export interface ImageComponentProps extends BaseComponentProps {
213
+ url?: ValueSource
214
+ fit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down'
215
+ usageHint?:
216
+ | 'icon'
217
+ | 'avatar'
218
+ | 'smallFeature'
219
+ | 'mediumFeature'
220
+ | 'largeFeature'
221
+ | 'header'
222
+ }
223
+
224
+ /**
225
+ * Icon component properties.
226
+ */
227
+ export interface IconComponentProps extends BaseComponentProps {
228
+ name?: ValueSource
229
+ }
230
+
231
+ /**
232
+ * Video component properties.
233
+ */
234
+ export interface VideoComponentProps extends BaseComponentProps {
235
+ url?: ValueSource
236
+ }
237
+
238
+ /**
239
+ * AudioPlayer component properties.
240
+ */
241
+ export interface AudioPlayerComponentProps extends BaseComponentProps {
242
+ url?: ValueSource
243
+ description?: ValueSource
244
+ }
245
+
246
+ /**
247
+ * Divider component properties.
248
+ */
249
+ export interface DividerComponentProps extends BaseComponentProps {
250
+ axis?: 'horizontal' | 'vertical'
251
+ }
252
+
253
+ // ============ Layout Component Props ============
254
+
255
+ /**
256
+ * Distribution values for flex layouts.
257
+ */
258
+ export type Distribution =
259
+ | 'start'
260
+ | 'center'
261
+ | 'end'
262
+ | 'spaceBetween'
263
+ | 'spaceAround'
264
+ | 'spaceEvenly'
265
+
266
+ /**
267
+ * Alignment values for flex layouts.
268
+ */
269
+ export type Alignment = 'start' | 'center' | 'end' | 'stretch'
270
+
271
+ /**
272
+ * Row component properties.
273
+ */
274
+ export interface RowComponentProps extends BaseComponentProps {
275
+ children?: ChildrenDefinition
276
+ distribution?: Distribution
277
+ alignment?: Alignment
278
+ }
279
+
280
+ /**
281
+ * Column component properties.
282
+ */
283
+ export interface ColumnComponentProps extends BaseComponentProps {
284
+ children?: ChildrenDefinition
285
+ distribution?: Distribution
286
+ alignment?: Alignment
287
+ }
288
+
289
+ /**
290
+ * List component properties.
291
+ */
292
+ export interface ListComponentProps extends BaseComponentProps {
293
+ children?: ChildrenDefinition
294
+ direction?: 'vertical' | 'horizontal'
295
+ alignment?: Alignment
296
+ }
297
+
298
+ /**
299
+ * Card component properties.
300
+ */
301
+ export interface CardComponentProps extends BaseComponentProps {
302
+ child?: string
303
+ }
304
+
305
+ /**
306
+ * Tab item definition.
307
+ */
308
+ export interface TabItem {
309
+ title?: ValueSource
310
+ child: string
311
+ }
312
+
313
+ /**
314
+ * Tabs component properties.
315
+ */
316
+ export interface TabsComponentProps extends BaseComponentProps {
317
+ tabItems?: TabItem[]
318
+ }
319
+
320
+ /**
321
+ * Modal component properties.
322
+ */
323
+ export interface ModalComponentProps extends BaseComponentProps {
324
+ entryPointChild?: string
325
+ contentChild?: string
326
+ }
327
+
328
+ // ============ Interactive Component Props ============
329
+
330
+ /**
331
+ * Button component properties.
332
+ */
333
+ export interface ButtonComponentProps extends BaseComponentProps {
334
+ child?: string
335
+ primary?: boolean
336
+ action?: Action
337
+ }
338
+
339
+ /**
340
+ * CheckBox component properties.
341
+ */
342
+ export interface CheckBoxComponentProps extends BaseComponentProps {
343
+ label?: ValueSource
344
+ value?: ValueSource
345
+ }
346
+
347
+ /**
348
+ * TextField component properties.
349
+ */
350
+ export interface TextFieldComponentProps extends BaseComponentProps {
351
+ label?: ValueSource
352
+ text?: ValueSource
353
+ textFieldType?: 'date' | 'longText' | 'number' | 'shortText' | 'obscured'
354
+ validationRegexp?: string
355
+ }
356
+
357
+ /**
358
+ * DateTimeInput component properties.
359
+ */
360
+ export interface DateTimeInputComponentProps extends BaseComponentProps {
361
+ value?: ValueSource
362
+ enableDate?: boolean
363
+ enableTime?: boolean
364
+ }
365
+
366
+ /**
367
+ * MultipleChoice option definition.
368
+ */
369
+ export interface MultipleChoiceOption {
370
+ label?: ValueSource
371
+ value: string
372
+ }
373
+
374
+ /**
375
+ * MultipleChoice component properties.
376
+ */
377
+ export interface MultipleChoiceComponentProps extends BaseComponentProps {
378
+ selections?: ValueSource
379
+ options?: MultipleChoiceOption[]
380
+ maxAllowedSelections?: number
381
+ }
382
+
383
+ /**
384
+ * Slider component properties.
385
+ */
386
+ export interface SliderComponentProps extends BaseComponentProps {
387
+ value?: ValueSource
388
+ minValue?: number
389
+ maxValue?: number
390
+ }
391
+
392
+ // ============ Renderer Props ============
393
+
394
+ /**
395
+ * Decision button for the fixed bottom area.
396
+ */
397
+ export interface DecisionButton {
398
+ name: string
399
+ label: string
400
+ action: string
401
+ variant?: 'primary' | 'secondary' | 'destructive'
402
+ icon?: string
403
+ }
404
+
405
+ /**
406
+ * Confirmed info item for display.
407
+ */
408
+ export interface ConfirmedInfoItem {
409
+ label: string
410
+ value: string
411
+ highlight?: boolean
412
+ isFullWidth?: boolean
413
+ }
414
+
415
+ /**
416
+ * Confirmed info section configuration.
417
+ */
418
+ export interface ConfirmedInfo {
419
+ title?: string
420
+ items: ConfirmedInfoItem[]
421
+ }
422
+
423
+ /**
424
+ * Form section warning configuration.
425
+ */
426
+ export interface FormSectionWarning {
427
+ title: string
428
+ message: string
429
+ }
430
+
431
+ /**
432
+ * Completed action information.
433
+ */
434
+ export interface CompletedAction {
435
+ action: string
436
+ label: string
437
+ completedAt?: string
438
+ completedBy?: string
439
+ formData?: Record<string, unknown>
440
+ }
441
+
442
+ /**
443
+ * Progress information.
444
+ */
445
+ export interface Progress {
446
+ current: number
447
+ total: number
448
+ }