@xemahq/ui-kernel 0.11.1 → 0.12.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 (257) hide show
  1. package/dist/errors/http-error-status.d.ts +17 -0
  2. package/dist/errors/http-error-status.d.ts.map +1 -0
  3. package/dist/errors/http-error-status.js +59 -0
  4. package/dist/errors/http-error-status.js.map +1 -0
  5. package/dist/errors/index.d.ts +2 -0
  6. package/dist/errors/index.d.ts.map +1 -0
  7. package/dist/errors/index.js +2 -0
  8. package/dist/errors/index.js.map +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/biome-host/errors.d.ts.map +1 -1
  14. package/dist/lib/biome-host/errors.js +1 -19
  15. package/dist/lib/biome-host/errors.js.map +1 -1
  16. package/dist/offline/index.d.ts.map +1 -1
  17. package/dist/offline/index.js.map +1 -1
  18. package/dist/offline/online-controller.d.ts.map +1 -1
  19. package/dist/offline/online-controller.js +6 -1
  20. package/dist/offline/online-controller.js.map +1 -1
  21. package/dist/offline/outbox.d.ts.map +1 -1
  22. package/dist/offline/outbox.js +2 -24
  23. package/dist/offline/outbox.js.map +1 -1
  24. package/package.json +1 -2
  25. package/src/index.ts +0 -17
  26. package/src/lib/biome-host/agent-validation.ts +0 -239
  27. package/src/lib/biome-host/biome-builders.ts +0 -112
  28. package/src/lib/biome-host/biome-mode.ts +0 -6
  29. package/src/lib/biome-host/biome-navigation.ts +0 -37
  30. package/src/lib/biome-host/biome-registry.ts +0 -299
  31. package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
  32. package/src/lib/biome-host/biome-scope.tsx +0 -52
  33. package/src/lib/biome-host/biome-scoped-query.ts +0 -134
  34. package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
  35. package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
  36. package/src/lib/biome-host/define-web-biome.ts +0 -222
  37. package/src/lib/biome-host/errors.ts +0 -220
  38. package/src/lib/biome-host/frontend-biome.ts +0 -256
  39. package/src/lib/biome-host/host-bridge.ts +0 -281
  40. package/src/lib/biome-host/host-sources.ts +0 -54
  41. package/src/lib/biome-host/i18n-hooks.ts +0 -51
  42. package/src/lib/biome-host/i18n-port.test.ts +0 -50
  43. package/src/lib/biome-host/i18n-port.ts +0 -96
  44. package/src/lib/biome-host/index.ts +0 -35
  45. package/src/lib/biome-host/realtime-hooks.ts +0 -75
  46. package/src/lib/biome-host/realtime-port.ts +0 -115
  47. package/src/lib/biome-host/session-contributions.ts +0 -296
  48. package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
  49. package/src/lib/biome-host/use-page-state.ts +0 -248
  50. package/src/lib/capabilities/capability-context.ts +0 -25
  51. package/src/lib/capabilities/capability-provider.tsx +0 -73
  52. package/src/lib/capabilities/index.ts +0 -17
  53. package/src/lib/capabilities/types.ts +0 -69
  54. package/src/lib/capabilities/use-capability.ts +0 -79
  55. package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
  56. package/src/lib/contribution-registry/contribution-registry.ts +0 -204
  57. package/src/lib/contribution-registry/index.ts +0 -9
  58. package/src/lib/contribution-registry/renderable-registry.ts +0 -142
  59. package/src/lib/system-bus/capability-invoke.ts +0 -92
  60. package/src/lib/system-bus/deeplink.ts +0 -210
  61. package/src/lib/system-bus/enums.ts +0 -86
  62. package/src/lib/system-bus/host-ports.ts +0 -93
  63. package/src/lib/system-bus/index.ts +0 -16
  64. package/src/lib/system-bus/intent-registry.ts +0 -109
  65. package/src/lib/system-bus/intents.ts +0 -113
  66. package/src/lib/system-bus/palette.ts +0 -78
  67. package/src/lib/system-bus/system-bus-builder.ts +0 -159
  68. package/src/lib/system-bus/system-bus.ts +0 -37
  69. package/src/lib/system-bus/windows.ts +0 -51
  70. package/src/offline/id.ts +0 -16
  71. package/src/offline/index.ts +0 -54
  72. package/src/offline/mutation.ts +0 -75
  73. package/src/offline/offline-status-badge.tsx +0 -51
  74. package/src/offline/online-controller.ts +0 -105
  75. package/src/offline/outbox.test.ts +0 -172
  76. package/src/offline/outbox.ts +0 -348
  77. package/src/offline/react-hooks.ts +0 -40
  78. package/src/offline/react.tsx +0 -32
  79. package/src/offline/storage.ts +0 -112
  80. package/src/offline/types.ts +0 -77
  81. package/src/org-db/components/DbResultTable.tsx +0 -176
  82. package/src/org-db/index.ts +0 -1
  83. package/src/pdf/index.ts +0 -11
  84. package/src/registry/index.ts +0 -9
  85. package/src/registry/lib/agent-validation-host.ts +0 -36
  86. package/src/registry/lib/biome-slot.tsx +0 -50
  87. package/src/registry/lib/biomes-enabled-context.ts +0 -20
  88. package/src/registry/lib/extension-points.ts +0 -134
  89. package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
  90. package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
  91. package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
  92. package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
  93. package/src/registry/lib/primitives/index.ts +0 -18
  94. package/src/registry/lib/session-context-builder.ts +0 -84
  95. package/src/registry/lib/session-context-provider.tsx +0 -33
  96. package/src/registry/lib/session-context.ts +0 -21
  97. package/src/registry/lib/session-selectors.ts +0 -272
  98. package/src/session/comments/CommentRail.tsx +0 -164
  99. package/src/session/index.ts +0 -3
  100. package/src/session/lib/cn.ts +0 -11
  101. package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
  102. package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
  103. package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
  104. package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
  105. package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
  106. package/src/session-kit/approvals/Obligation.tsx +0 -111
  107. package/src/session-kit/approvals/ScopedBody.tsx +0 -392
  108. package/src/session-kit/approvals/approval-icons.ts +0 -31
  109. package/src/session-kit/approvals/approval-model.ts +0 -204
  110. package/src/session-kit/approvals/index.ts +0 -22
  111. package/src/session-kit/approvals/obligation-display.ts +0 -100
  112. package/src/session-kit/approvals/risk-accent.ts +0 -47
  113. package/src/session-kit/approvals/scope-icons.ts +0 -19
  114. package/src/session-kit/combobox/Combobox.tsx +0 -358
  115. package/src/session-kit/combobox/use-click-outside.ts +0 -21
  116. package/src/session-kit/display/ContextHeader.tsx +0 -148
  117. package/src/session-kit/display/FileDiffCard.tsx +0 -140
  118. package/src/session-kit/display/MD.tsx +0 -162
  119. package/src/session-kit/display/MessageTurn.tsx +0 -157
  120. package/src/session-kit/display/ThinkingPanel.tsx +0 -81
  121. package/src/session-kit/display/TodoChecklist.tsx +0 -120
  122. package/src/session-kit/display/TokenMeter.tsx +0 -89
  123. package/src/session-kit/display/ToolStrip.tsx +0 -278
  124. package/src/session-kit/display/TypingDots.tsx +0 -24
  125. package/src/session-kit/index.ts +0 -44
  126. package/src/session-kit/lib/enums.ts +0 -66
  127. package/src/session-kit/lib/portal-accent.ts +0 -30
  128. package/src/session-kit/lib/status-dot.ts +0 -68
  129. package/src/session-kit/primitives/Avatar.tsx +0 -44
  130. package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
  131. package/src/session-kit/primitives/RiskPill.tsx +0 -95
  132. package/src/session-kit/primitives/ScopeDot.tsx +0 -47
  133. package/src/session-kit/primitives/Segmented.tsx +0 -71
  134. package/src/ui/branding/app-branding-context.ts +0 -20
  135. package/src/ui/branding/app-branding-provider.tsx +0 -123
  136. package/src/ui/branding/sanitize.ts +0 -89
  137. package/src/ui/breakpoints.ts +0 -14
  138. package/src/ui/capture/document-preview.tsx +0 -166
  139. package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
  140. package/src/ui/capture/field-spec-to-zod.ts +0 -174
  141. package/src/ui/capture/field-spec-validate.ts +0 -236
  142. package/src/ui/capture/field-spec.test.ts +0 -49
  143. package/src/ui/capture/field-spec.ts +0 -274
  144. package/src/ui/capture/index.ts +0 -51
  145. package/src/ui/capture/schema-field-input.tsx +0 -620
  146. package/src/ui/capture/schema-form.tsx +0 -149
  147. package/src/ui/capture/submit-values.test.ts +0 -70
  148. package/src/ui/capture/submit-values.ts +0 -63
  149. package/src/ui/capture/use-prefill.ts +0 -186
  150. package/src/ui/capture/use-schema-validation.ts +0 -145
  151. package/src/ui/capture/use-wizard.ts +0 -180
  152. package/src/ui/capture/value-format.ts +0 -32
  153. package/src/ui/capture/wizard.tsx +0 -105
  154. package/src/ui/charts/bar-chart.tsx +0 -139
  155. package/src/ui/charts/chart-frame.tsx +0 -125
  156. package/src/ui/charts/chart-types.ts +0 -52
  157. package/src/ui/charts/chart-utils.ts +0 -190
  158. package/src/ui/charts/charts.test.tsx +0 -204
  159. package/src/ui/charts/donut-chart.tsx +0 -129
  160. package/src/ui/charts/index.ts +0 -27
  161. package/src/ui/charts/line-chart.tsx +0 -202
  162. package/src/ui/charts/sparkline.tsx +0 -109
  163. package/src/ui/chrome/AsyncBoundary.tsx +0 -74
  164. package/src/ui/chrome/EmptyState.tsx +0 -257
  165. package/src/ui/chrome/ErrorCard.tsx +0 -63
  166. package/src/ui/chrome/LoadingState.tsx +0 -61
  167. package/src/ui/chrome/PageHeader.tsx +0 -137
  168. package/src/ui/chrome/RecordCardList.tsx +0 -98
  169. package/src/ui/chrome/StateCard.tsx +0 -150
  170. package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
  171. package/src/ui/chrome/page-shell.spec.tsx +0 -117
  172. package/src/ui/chrome/page-shell.tsx +0 -221
  173. package/src/ui/chrome/scope-badge.tsx +0 -40
  174. package/src/ui/chrome/status-badge.tsx +0 -79
  175. package/src/ui/cn.ts +0 -32
  176. package/src/ui/design-tokens.ts +0 -372
  177. package/src/ui/hooks/use-debounced-value.ts +0 -16
  178. package/src/ui/hooks/use-is-mobile.ts +0 -28
  179. package/src/ui/index.ts +0 -110
  180. package/src/ui/pdf/pdf-preview.tsx +0 -122
  181. package/src/ui/primitives/alert-dialog.tsx +0 -104
  182. package/src/ui/primitives/async-combobox.tsx +0 -182
  183. package/src/ui/primitives/badge-variants.ts +0 -21
  184. package/src/ui/primitives/badge.tsx +0 -25
  185. package/src/ui/primitives/button-variants.ts +0 -31
  186. package/src/ui/primitives/button.tsx +0 -29
  187. package/src/ui/primitives/card.tsx +0 -43
  188. package/src/ui/primitives/checkbox.tsx +0 -26
  189. package/src/ui/primitives/collapsible.tsx +0 -9
  190. package/src/ui/primitives/dialog.tsx +0 -103
  191. package/src/ui/primitives/dropdown-menu.tsx +0 -179
  192. package/src/ui/primitives/form-stepper.tsx +0 -94
  193. package/src/ui/primitives/form-stepper.types.ts +0 -15
  194. package/src/ui/primitives/input.tsx +0 -22
  195. package/src/ui/primitives/label.tsx +0 -17
  196. package/src/ui/primitives/overflow-tabs.tsx +0 -331
  197. package/src/ui/primitives/popover.tsx +0 -33
  198. package/src/ui/primitives/preview-device-frame.tsx +0 -213
  199. package/src/ui/primitives/radio-group.tsx +0 -36
  200. package/src/ui/primitives/resizable.tsx +0 -67
  201. package/src/ui/primitives/scroll-area.tsx +0 -38
  202. package/src/ui/primitives/select.tsx +0 -143
  203. package/src/ui/primitives/separator.tsx +0 -20
  204. package/src/ui/primitives/sheet.tsx +0 -107
  205. package/src/ui/primitives/skeleton.tsx +0 -99
  206. package/src/ui/primitives/switch.tsx +0 -27
  207. package/src/ui/primitives/table.tsx +0 -72
  208. package/src/ui/primitives/tabs.tsx +0 -53
  209. package/src/ui/primitives/tag-multi-select.tsx +0 -261
  210. package/src/ui/primitives/textarea.tsx +0 -21
  211. package/src/ui/primitives/tooltip.tsx +0 -30
  212. package/src/ui/primitives/url-preview-chrome.tsx +0 -103
  213. package/src/vista/GenericCatalogueSurface.tsx +0 -179
  214. package/src/vista/SurfaceFallbackCard.tsx +0 -109
  215. package/src/vista/VistaPanel.tsx +0 -163
  216. package/src/vista/form-payload.spec.ts +0 -139
  217. package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
  218. package/src/vista/html/CustomUiFrame.tsx +0 -206
  219. package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
  220. package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
  221. package/src/vista/html/custom-ui-frame-contract.ts +0 -88
  222. package/src/vista/html/custom-ui-intents.spec.ts +0 -135
  223. package/src/vista/html/custom-ui-intents.ts +0 -155
  224. package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
  225. package/src/vista/html/custom-ui-srcdoc.ts +0 -193
  226. package/src/vista/html/index.ts +0 -13
  227. package/src/vista/index.ts +0 -52
  228. package/src/vista/surface-catalogue.spec.ts +0 -140
  229. package/src/vista/surface-catalogue.ts +0 -90
  230. package/src/vista/surface-icons.ts +0 -57
  231. package/src/vista/surface-registry.ts +0 -56
  232. package/src/vista/surfaces/ChartSurface.tsx +0 -34
  233. package/src/vista/surfaces/FilesSurface.tsx +0 -202
  234. package/src/vista/surfaces/FormSurface.tsx +0 -380
  235. package/src/vista/surfaces/HtmlSurface.tsx +0 -43
  236. package/src/vista/surfaces/TableSurface.tsx +0 -100
  237. package/src/vista/surfaces/UrlSurface.tsx +0 -40
  238. package/src/vista/surfaces/blob-surfaces.tsx +0 -139
  239. package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
  240. package/src/vista/surfaces/elicitation-transport.ts +0 -367
  241. package/src/vista/surfaces/file-surface-utils.ts +0 -69
  242. package/src/vista/surfaces/index.ts +0 -24
  243. package/src/vista/surfaces/register-surfaces.tsx +0 -139
  244. package/src/vista/surfaces/text-surfaces.tsx +0 -132
  245. package/src/vista/use-vista-tabs.ts +0 -196
  246. package/src/vista/vista-code-renderer-context.ts +0 -16
  247. package/src/vista/vista-code-renderer.tsx +0 -35
  248. package/src/vista/vista-file-context.ts +0 -14
  249. package/src/vista/vista-file-source.tsx +0 -141
  250. package/src/vista/vista-form-context.ts +0 -20
  251. package/src/vista/vista-form-host.tsx +0 -48
  252. package/src/vista/vista-model.ts +0 -137
  253. package/src/vista/vista-open-context.tsx +0 -27
  254. package/src/vista/vista-open-state.ts +0 -11
  255. package/src/vista/vista-payloads.ts +0 -635
  256. package/src/vista/vista-tabs-manifest.ts +0 -138
  257. package/src/vista/vista-tools.ts +0 -232
@@ -1,180 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // useWizard — headless multi-step engine
3
- //
4
- // The state machine the hand-rolled wizards lack: step index, next/prev, goTo,
5
- // isFirst/isLast, per-step advance gating, and a `status(i)` that maps 1:1 onto
6
- // the presentational `FormStepper`'s `FormStepStatus`. Controlled (pass `step`)
7
- // and uncontrolled (pass `initialStep`) modes. No timers, no side effects.
8
- // ═══════════════════════════════════════════════════════════════════════════
9
- import { useCallback, useMemo, useState } from 'react';
10
-
11
- import { FormStepStatus } from '../primitives/form-stepper.types';
12
-
13
- export interface WizardStepDef {
14
- readonly key: string;
15
- readonly label: string;
16
- readonly hint?: string;
17
- }
18
-
19
- export interface UseWizardOptions {
20
- readonly steps: readonly WizardStepDef[];
21
- /**
22
- * Per-step forward gate. `canAdvance(i)` must return true before the wizard
23
- * will move PAST step `i`. Backward navigation is always allowed. Defaults to
24
- * always-advanceable.
25
- */
26
- readonly canAdvance?: (index: number) => boolean;
27
- /** Uncontrolled initial index (default 0). Ignored when `step` is provided. */
28
- readonly initialStep?: number;
29
- /** Controlled active index. When set, the hook is controlled. */
30
- readonly step?: number;
31
- /** Fired on every requested index change (both modes). */
32
- readonly onStepChange?: (index: number) => void;
33
- }
34
-
35
- export interface WizardApi {
36
- readonly steps: readonly WizardStepDef[];
37
- readonly activeIndex: number;
38
- readonly activeStep: WizardStepDef;
39
- readonly isFirst: boolean;
40
- readonly isLast: boolean;
41
- /** Whether the CURRENT step's forward gate is satisfied. */
42
- readonly canAdvance: boolean;
43
- /** 0..1 progress across the steps. */
44
- readonly progress: number;
45
- readonly next: () => void;
46
- readonly prev: () => void;
47
- /** Jump to `index`. Backward is free; forward requires every intervening gate. */
48
- readonly goTo: (index: number) => void;
49
- /** {@link FormStepStatus} for step `index` — feeds `<FormStepper>`. */
50
- readonly status: (index: number) => FormStepStatus;
51
- }
52
-
53
- /**
54
- * Strict access guard — keeps `steps[index]` typed as defined.
55
- *
56
- * `activeIndex` is clamped into `[0, count - 1]`, so the only way this misses is
57
- * an EMPTY `steps` array: `clamp` floors at 0 and `steps[0]` is then `undefined`.
58
- * `WizardApi.activeStep` is declared non-optional and consumers dereference it
59
- * (`api.activeStep.key`), so a zero-step wizard must fail here with a message
60
- * naming the cause rather than hand back an `undefined` typed as `WizardStepDef`.
61
- */
62
- function requireStep(
63
- steps: readonly WizardStepDef[],
64
- index: number,
65
- ): WizardStepDef {
66
- const step = steps[index];
67
- if (!step) {
68
- throw new Error(
69
- `useWizard: no step at index ${index} (have ${steps.length}). ` +
70
- '`steps` must contain at least one entry.',
71
- );
72
- }
73
- return step;
74
- }
75
-
76
- /**
77
- * @example
78
- * const wizard = useWizard({
79
- * steps: [{ key: 'details', label: 'Details' }, { key: 'review', label: 'Review' }],
80
- * canAdvance: (i) => (i === 0 ? isValid : true),
81
- * });
82
- * <Wizard api={wizard} onFinish={submit}>
83
- * <WizardStep stepKey="details"><SchemaForm … /></WizardStep>
84
- * <WizardStep stepKey="review"><DocumentPreview … /></WizardStep>
85
- * </Wizard>
86
- */
87
- export function useWizard(options: UseWizardOptions): WizardApi {
88
- const { steps, canAdvance, initialStep = 0, step, onStepChange } = options;
89
- const count = steps.length;
90
- const clamp = useCallback(
91
- (i: number) => Math.max(0, Math.min(count - 1, i)),
92
- [count],
93
- );
94
-
95
- const isControlled = step !== undefined;
96
- const [internal, setInternal] = useState(() => clamp(initialStep));
97
- const activeIndex = clamp(isControlled ? step : internal);
98
-
99
- const gate = useCallback(
100
- (i: number) => (canAdvance ? canAdvance(i) : true),
101
- [canAdvance],
102
- );
103
-
104
- const request = useCallback(
105
- (target: number) => {
106
- const next = clamp(target);
107
- if (next === activeIndex) {
108
- return;
109
- }
110
- onStepChange?.(next);
111
- if (!isControlled) {
112
- setInternal(next);
113
- }
114
- },
115
- [activeIndex, clamp, isControlled, onStepChange],
116
- );
117
-
118
- const goTo = useCallback(
119
- (index: number) => {
120
- const target = clamp(index);
121
- if (target <= activeIndex) {
122
- request(target); // backward is always allowed
123
- return;
124
- }
125
- // Forward: every step from active..target-1 must pass its gate.
126
- for (let i = activeIndex; i < target; i += 1) {
127
- if (!gate(i)) {
128
- return;
129
- }
130
- }
131
- request(target);
132
- },
133
- [activeIndex, clamp, gate, request],
134
- );
135
-
136
- const next = useCallback(() => {
137
- if (activeIndex >= count - 1) {
138
- return;
139
- }
140
- if (!gate(activeIndex)) {
141
- return;
142
- }
143
- request(activeIndex + 1);
144
- }, [activeIndex, count, gate, request]);
145
-
146
- const prev = useCallback(
147
- () => request(activeIndex - 1),
148
- [activeIndex, request],
149
- );
150
-
151
- const status = useCallback(
152
- (index: number): FormStepStatus => {
153
- if (index < activeIndex) {
154
- return FormStepStatus.DONE;
155
- }
156
- if (index === activeIndex) {
157
- return FormStepStatus.ACTIVE;
158
- }
159
- return FormStepStatus.PENDING;
160
- },
161
- [activeIndex],
162
- );
163
-
164
- return useMemo<WizardApi>(
165
- () => ({
166
- steps,
167
- activeIndex,
168
- activeStep: requireStep(steps, activeIndex),
169
- isFirst: activeIndex === 0,
170
- isLast: activeIndex === count - 1,
171
- canAdvance: gate(activeIndex),
172
- progress: count <= 1 ? 1 : activeIndex / (count - 1),
173
- next,
174
- prev,
175
- goTo,
176
- status,
177
- }),
178
- [steps, activeIndex, count, gate, next, prev, goTo, status],
179
- );
180
- }
@@ -1,32 +0,0 @@
1
- // Shared value coercion/formatting for the capture kit — used by the input
2
- // boundary (SchemaForm) and the read-only view (DocumentPreview) so the two
3
- // never disagree on how a stored value maps to its display/edit string.
4
- import { CaptureFieldType, type CaptureFieldSpec } from './field-spec';
5
-
6
- /** Coerce any stored value to a display/edit string (empty for absent). */
7
- export function asString(value: unknown): string {
8
- if (typeof value === 'string') {
9
- return value;
10
- }
11
- if (value === undefined || value === null) {
12
- return '';
13
- }
14
- return String(value);
15
- }
16
-
17
- /** Human-readable rendering of a scalar field value for the read-only preview. */
18
- export function formatScalar(
19
- field: CaptureFieldSpec,
20
- value: unknown,
21
- emptyText: string,
22
- ): string {
23
- if (value === undefined || value === null || value === '') {
24
- return emptyText;
25
- }
26
- switch (field.type) {
27
- case CaptureFieldType.Boolean:
28
- return value === true ? 'Yes' : 'No';
29
- default:
30
- return asString(value);
31
- }
32
- }
@@ -1,105 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // <Wizard> / <WizardStep> — thin presentational shell over useWizard
3
- //
4
- // Composes the existing `<FormStepper>` for the numbered rail (with the ACTIVE
5
- // step's body rendered inline, guided-style — pending steps stay empty) and
6
- // renders a Back / Next / Finish nav bar. All state lives in the `useWizard`
7
- // engine you pass via `api`; this component is presentation only.
8
- // ═══════════════════════════════════════════════════════════════════════════
9
- import {
10
- Children,
11
- isValidElement,
12
- type ReactNode,
13
- } from 'react';
14
-
15
- import { cn } from '../cn';
16
- import { Button } from '../primitives/button';
17
- import { FormStepper } from '../primitives/form-stepper';
18
-
19
- import type { WizardApi } from './use-wizard';
20
- import type { FormStep } from '../primitives/form-stepper.types';
21
-
22
- export interface WizardStepProps {
23
- /** Must match a `useWizard` step `key`. */
24
- readonly stepKey: string;
25
- readonly children: ReactNode;
26
- }
27
-
28
- /**
29
- * Declarative wrapper for one wizard step's body. Rendered by `<Wizard>` only
30
- * when its `stepKey` is the active step.
31
- */
32
- export function WizardStep(_props: WizardStepProps): null {
33
- // Rendering is orchestrated by <Wizard>; this component only carries props.
34
- return null;
35
- }
36
-
37
- export interface WizardProps {
38
- readonly api: WizardApi;
39
- readonly children: ReactNode;
40
- /** Called when Finish is pressed on the last step (gate already satisfied). */
41
- readonly onFinish?: () => void;
42
- readonly nextLabel?: string;
43
- readonly backLabel?: string;
44
- readonly finishLabel?: string;
45
- /** Hide the built-in nav bar (caller renders its own using `api`). */
46
- readonly hideNav?: boolean;
47
- readonly className?: string;
48
- }
49
-
50
- function stepBodies(children: ReactNode): Map<string, ReactNode> {
51
- const map = new Map<string, ReactNode>();
52
- Children.forEach(children, (child) => {
53
- if (isValidElement<WizardStepProps>(child) && child.props.stepKey) {
54
- const p = child.props;
55
- map.set(p.stepKey, p.children);
56
- }
57
- });
58
- return map;
59
- }
60
-
61
- export function Wizard({
62
- api,
63
- children,
64
- onFinish,
65
- nextLabel = 'Continue',
66
- backLabel = 'Back',
67
- finishLabel = 'Finish',
68
- hideNav = false,
69
- className,
70
- }: WizardProps) {
71
- const bodies = stepBodies(children);
72
-
73
- const formSteps: FormStep[] = api.steps.map((step, index) => ({
74
- key: step.key,
75
- label: step.label,
76
- hint: step.hint,
77
- status: api.status(index),
78
- // Render the active step's body inline; pending/done steps stay empty so
79
- // the rail reads as a guided one-step-at-a-time flow.
80
- children: index === api.activeIndex ? (bodies.get(step.key) ?? null) : null,
81
- }));
82
-
83
- return (
84
- <div className={cn('space-y-5', className)}>
85
- <FormStepper steps={formSteps} />
86
-
87
- {!hideNav && (
88
- <div className="flex items-center justify-between gap-2 border-t border-rule pt-4">
89
- <Button variant="ghost" onClick={api.prev} disabled={api.isFirst}>
90
- {backLabel}
91
- </Button>
92
- {api.isLast ? (
93
- <Button onClick={onFinish} disabled={!api.canAdvance}>
94
- {finishLabel}
95
- </Button>
96
- ) : (
97
- <Button onClick={api.next} disabled={!api.canAdvance}>
98
- {nextLabel}
99
- </Button>
100
- )}
101
- </div>
102
- )}
103
- </div>
104
- );
105
- }
@@ -1,139 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // BarChart — categorical bars, pure SVG (Wave 9.2)
3
- // ═══════════════════════════════════════════════════════════════════════════
4
-
5
- import { ChartEmpty, ChartFrame, type ChartLegendItem } from './chart-frame';
6
- import {
7
- buildAriaSummary,
8
- chartColorAt,
9
- defaultFormatValue,
10
- finitePoints,
11
- niceScale,
12
- } from './chart-utils';
13
-
14
- import type { ChartBaseProps, ChartDatum } from './chart-types';
15
- import type { ReactNode } from 'react';
16
-
17
- // Internal coordinate space — the `viewBox`. `width="100%"` makes the SVG scale
18
- // to its container (D20 fluid), so these are ratios, not device pixels.
19
- const VIEW_W = 640;
20
- const VIEW_H = 360;
21
- const PAD = { top: 12, right: 12, bottom: 44, left: 48 } as const;
22
- const PLOT_L = PAD.left;
23
- const PLOT_R = VIEW_W - PAD.right;
24
- const PLOT_T = PAD.top;
25
- const PLOT_B = VIEW_H - PAD.bottom;
26
- const PLOT_W = PLOT_R - PLOT_L;
27
- const PLOT_H = PLOT_B - PLOT_T;
28
-
29
- export interface BarChartProps extends ChartBaseProps {
30
- /** The bars — one per labelled datum. */
31
- readonly data: readonly ChartDatum[];
32
- }
33
-
34
- export function BarChart({
35
- data,
36
- title,
37
- ariaLabel,
38
- formatValue,
39
- className,
40
- emptyLabel = 'No data',
41
- }: BarChartProps): ReactNode {
42
- const format = formatValue ?? defaultFormatValue;
43
- const points = finitePoints(data);
44
-
45
- if (points.length === 0) {
46
- return (
47
- <ChartEmpty title={title} label={emptyLabel} className={className} />
48
- );
49
- }
50
-
51
- const values = points.map((p) => p.value);
52
- const scale = niceScale(Math.min(...values), Math.max(...values));
53
- const span = scale.max - scale.min;
54
- const yToPx = (v: number): number =>
55
- PLOT_B - ((v - scale.min) / span) * PLOT_H;
56
- const baseline = yToPx(0);
57
-
58
- const band = PLOT_W / points.length;
59
- const barW = Math.min(band * 0.62, 72);
60
-
61
- const legend: ChartLegendItem[] = points.map((p, i) => ({
62
- label: p.label,
63
- value: format(p.value),
64
- color: chartColorAt(i, p.color),
65
- }));
66
-
67
- const summary = ariaLabel ?? buildAriaSummary(title, points, format, 'bar');
68
-
69
- const plot = (
70
- <svg
71
- role="img"
72
- aria-label={summary}
73
- width="100%"
74
- viewBox={`0 0 ${VIEW_W} ${VIEW_H}`}
75
- preserveAspectRatio="xMidYMid meet"
76
- className="block h-auto w-full overflow-visible text-ink-4"
77
- >
78
- {/* y gridlines + tick labels */}
79
- {scale.ticks.map((t) => {
80
- const y = yToPx(t);
81
- return (
82
- <g key={`y-${t}`}>
83
- <line
84
- x1={PLOT_L}
85
- x2={PLOT_R}
86
- y1={y}
87
- y2={y}
88
- stroke="currentColor"
89
- strokeOpacity={t === 0 ? 0.35 : 0.12}
90
- />
91
- <text
92
- x={PLOT_L - 8}
93
- y={y}
94
- textAnchor="end"
95
- dominantBaseline="middle"
96
- fontSize={12}
97
- fill="currentColor"
98
- >
99
- {format(t)}
100
- </text>
101
- </g>
102
- );
103
- })}
104
-
105
- {/* bars + x labels */}
106
- {points.map((p, i) => {
107
- const cx = PLOT_L + band * i + band / 2;
108
- const yv = yToPx(p.value);
109
- const top = Math.min(yv, baseline);
110
- const h = Math.max(1, Math.abs(baseline - yv));
111
- return (
112
- <g key={`bar-${p.label}-${i}`}>
113
- <rect
114
- x={cx - barW / 2}
115
- y={top}
116
- width={barW}
117
- height={h}
118
- rx={3}
119
- fill={chartColorAt(i, p.color)}
120
- >
121
- <title>{`${p.label}: ${format(p.value)}`}</title>
122
- </rect>
123
- <text
124
- x={cx}
125
- y={PLOT_B + 16}
126
- textAnchor="middle"
127
- fontSize={12}
128
- fill="currentColor"
129
- >
130
- {p.label}
131
- </text>
132
- </g>
133
- );
134
- })}
135
- </svg>
136
- );
137
-
138
- return <ChartFrame plot={plot} legend={legend} className={className} />;
139
- }
@@ -1,125 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // Chart primitives — shared layout frame, legend and empty state (Wave 9.2)
3
- //
4
- // `ChartFrame` owns the D20 responsive contract: the plot is a fluid container
5
- // and the legend sits BESIDE it on wide viewports but MOVES BELOW the plot
6
- // below `md`. That decision is driven by `useIsMobile()` — which reads the one
7
- // shared `MOBILE_BREAKPOINT` token — never a second breakpoint.
8
- // ═══════════════════════════════════════════════════════════════════════════
9
-
10
- import { cn } from '../cn';
11
- import { useIsMobile } from '../hooks/use-is-mobile';
12
-
13
- import type { ReactNode } from 'react';
14
-
15
- /** One row of the legend: a color swatch + its label + (optional) value. */
16
- export interface ChartLegendItem {
17
- readonly label: string;
18
- readonly color: string;
19
- readonly value?: string;
20
- }
21
-
22
- interface ChartLegendProps {
23
- readonly items: readonly ChartLegendItem[];
24
- /** `below` stacks items into a wrapping row; `beside` stacks them vertically. */
25
- readonly layout: 'beside' | 'below';
26
- }
27
-
28
- /**
29
- * The legend. Meaning is carried by the text label + value — the swatch is a
30
- * secondary cue, so a color-blind or monochrome reader loses nothing.
31
- */
32
- export function ChartLegend({ items, layout }: ChartLegendProps): ReactNode {
33
- if (items.length === 0) {
34
- return null;
35
- }
36
- return (
37
- <ul
38
- className={cn(
39
- 'm-0 list-none p-0 text-body-2 text-ink-3',
40
- layout === 'below'
41
- ? 'flex flex-row flex-wrap gap-x-4 gap-y-1.5'
42
- : 'flex flex-col gap-1.5',
43
- )}
44
- >
45
- {items.map((item, i) => (
46
- <li key={`${item.label}-${i}`} className="flex items-center gap-2">
47
- <span
48
- aria-hidden="true"
49
- className="inline-block h-2.5 w-2.5 shrink-0 rounded-sm"
50
- style={{ backgroundColor: item.color }}
51
- />
52
- <span className="text-ink-3">{item.label}</span>
53
- {item.value !== undefined && (
54
- <span className="ml-auto font-medium tabular-nums text-ink">
55
- {item.value}
56
- </span>
57
- )}
58
- </li>
59
- ))}
60
- </ul>
61
- );
62
- }
63
-
64
- interface ChartFrameProps {
65
- /** The plot itself — a fluid `<svg>` with `width="100%"` + a `viewBox`. */
66
- readonly plot: ReactNode;
67
- readonly legend: readonly ChartLegendItem[];
68
- readonly className?: string;
69
- }
70
-
71
- /**
72
- * Wraps a plot + legend with the responsive D20 layout. Uses `useIsMobile()`
73
- * so below `md` the legend renders BELOW the plot; at/above `md` it sits to the
74
- * right. One token (`MOBILE_BREAKPOINT`), no second breakpoint.
75
- */
76
- export function ChartFrame({
77
- plot,
78
- legend,
79
- className,
80
- }: ChartFrameProps): ReactNode {
81
- const isMobile = useIsMobile();
82
- return (
83
- <div className={cn('w-full min-w-0 text-ink-3', className)}>
84
- <div
85
- className={cn(
86
- 'flex min-w-0 gap-4',
87
- isMobile ? 'flex-col' : 'flex-row items-start',
88
- )}
89
- >
90
- <div className="min-w-0 flex-1">{plot}</div>
91
- <ChartLegend items={legend} layout={isMobile ? 'below' : 'beside'} />
92
- </div>
93
- </div>
94
- );
95
- }
96
-
97
- interface ChartEmptyProps {
98
- readonly title: string;
99
- readonly label: string;
100
- readonly className?: string;
101
- }
102
-
103
- /**
104
- * Explicit empty state — rendered instead of a broken/NaN SVG when a series has
105
- * no finite points. Still carries `role="img"` + an `aria-label` so assistive
106
- * tech announces the (empty) chart rather than a silent gap.
107
- */
108
- export function ChartEmpty({
109
- title,
110
- label,
111
- className,
112
- }: ChartEmptyProps): ReactNode {
113
- return (
114
- <div
115
- role="img"
116
- aria-label={`${title}: ${label}`}
117
- className={cn(
118
- 'flex w-full items-center justify-center rounded-lg border border-dashed border-border/60 bg-muted/20 px-4 py-10 text-body-2 text-ink-4',
119
- className,
120
- )}
121
- >
122
- {label}
123
- </div>
124
- );
125
- }
@@ -1,52 +0,0 @@
1
- // ═══════════════════════════════════════════════════════════════════════════
2
- // Chart primitives — public typed contracts (Wave 9.2)
3
- //
4
- // Pure-SVG chart primitives shipped by the kernel (NO external chart library).
5
- // These are the closed, typed shapes every chart primitive consumes. No `any`.
6
- // ═══════════════════════════════════════════════════════════════════════════
7
-
8
- /** A single labelled numeric point. The atom of every chart series. */
9
- export interface ChartDatum {
10
- /** Human-readable category / x-axis label. Always present (never color-only). */
11
- readonly label: string;
12
- /** The numeric value. Non-finite values (NaN/Infinity) are skipped, never plotted. */
13
- readonly value: number;
14
- /**
15
- * Optional per-datum color override — any CSS color, `currentColor`, or a
16
- * `var(--…)` token. When omitted the themeable palette assigns one by index.
17
- */
18
- readonly color?: string;
19
- }
20
-
21
- /** A named line series over a shared set of x-labels (LineChart). */
22
- export interface ChartLineSeries {
23
- /** Series name — shown in the legend and the aria summary. */
24
- readonly name: string;
25
- /** The ordered points of this line. */
26
- readonly points: readonly ChartDatum[];
27
- /** Optional color override (CSS color / `currentColor` / `var(--…)`). */
28
- readonly color?: string;
29
- }
30
-
31
- /** Formats a raw numeric value for axis ticks, legend and the aria summary. */
32
- export type ChartValueFormatter = (value: number) => string;
33
-
34
- /** Props shared by every chart primitive. */
35
- export interface ChartBaseProps {
36
- /**
37
- * Chart title — the spine of the `aria-label` summary and (optionally) a
38
- * visible caption. Required: an accessible chart always announces what it is.
39
- */
40
- readonly title: string;
41
- /**
42
- * Overrides the auto-generated `aria-label`. When omitted, each primitive
43
- * builds a deterministic summary from `title` + the data.
44
- */
45
- readonly ariaLabel?: string;
46
- /** Formats values in ticks / legend / summary. Deterministic by contract. */
47
- readonly formatValue?: ChartValueFormatter;
48
- /** Extra classes for the outermost wrapper. */
49
- readonly className?: string;
50
- /** Label rendered by the empty state when the series has no finite points. */
51
- readonly emptyLabel?: string;
52
- }