@dowel-ui/react 0.3.0 → 0.5.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 (206) hide show
  1. package/README.md +13 -8
  2. package/dist/components/ai-disclosure/ai-disclosure.d.ts +92 -0
  3. package/dist/components/ai-disclosure/ai-disclosure.d.ts.map +1 -0
  4. package/dist/components/ai-disclosure/ai-disclosure.js +122 -0
  5. package/dist/components/ai-disclosure/ai-disclosure.js.map +1 -0
  6. package/dist/components/ai-disclosure/index.d.ts +2 -0
  7. package/dist/components/ai-disclosure/index.js +2 -0
  8. package/dist/components/ai-disclosure/meta.js +17 -0
  9. package/dist/components/ai-disclosure/meta.js.map +1 -0
  10. package/dist/components/ai-extraction-review/ai-extraction-review.d.ts +52 -0
  11. package/dist/components/ai-extraction-review/ai-extraction-review.d.ts.map +1 -0
  12. package/dist/components/ai-extraction-review/ai-extraction-review.js +249 -0
  13. package/dist/components/ai-extraction-review/ai-extraction-review.js.map +1 -0
  14. package/dist/components/ai-extraction-review/extraction-model.d.ts +94 -0
  15. package/dist/components/ai-extraction-review/extraction-model.d.ts.map +1 -0
  16. package/dist/components/ai-extraction-review/extraction-model.js +91 -0
  17. package/dist/components/ai-extraction-review/extraction-model.js.map +1 -0
  18. package/dist/components/ai-extraction-review/index.d.ts +3 -0
  19. package/dist/components/ai-extraction-review/index.js +3 -0
  20. package/dist/components/ai-extraction-review/meta.js +17 -0
  21. package/dist/components/ai-extraction-review/meta.js.map +1 -0
  22. package/dist/components/ai-suggested-value/ai-suggested-value.d.ts +72 -0
  23. package/dist/components/ai-suggested-value/ai-suggested-value.d.ts.map +1 -0
  24. package/dist/components/ai-suggested-value/ai-suggested-value.js +126 -0
  25. package/dist/components/ai-suggested-value/ai-suggested-value.js.map +1 -0
  26. package/dist/components/ai-suggested-value/index.d.ts +2 -0
  27. package/dist/components/ai-suggested-value/index.js +2 -0
  28. package/dist/components/ai-suggested-value/meta.js +17 -0
  29. package/dist/components/ai-suggested-value/meta.js.map +1 -0
  30. package/dist/components/alert/alert.d.ts +1 -1
  31. package/dist/components/avatar/avatar.d.ts +1 -1
  32. package/dist/components/badge/badge.d.ts +1 -1
  33. package/dist/components/button/button.d.ts +1 -1
  34. package/dist/components/confirm-typed/confirm-typed.d.ts +47 -0
  35. package/dist/components/confirm-typed/confirm-typed.d.ts.map +1 -0
  36. package/dist/components/confirm-typed/confirm-typed.js +106 -0
  37. package/dist/components/confirm-typed/confirm-typed.js.map +1 -0
  38. package/dist/components/confirm-typed/index.d.ts +2 -0
  39. package/dist/components/confirm-typed/index.js +2 -0
  40. package/dist/components/confirm-typed/meta.js +17 -0
  41. package/dist/components/confirm-typed/meta.js.map +1 -0
  42. package/dist/components/cron-editor/cron-editor.d.ts +36 -0
  43. package/dist/components/cron-editor/cron-editor.d.ts.map +1 -0
  44. package/dist/components/cron-editor/cron-editor.js +493 -0
  45. package/dist/components/cron-editor/cron-editor.js.map +1 -0
  46. package/dist/components/cron-editor/cron-expression.d.ts +82 -0
  47. package/dist/components/cron-editor/cron-expression.d.ts.map +1 -0
  48. package/dist/components/cron-editor/cron-expression.js +352 -0
  49. package/dist/components/cron-editor/cron-expression.js.map +1 -0
  50. package/dist/components/cron-editor/index.d.ts +3 -0
  51. package/dist/components/cron-editor/index.js +3 -0
  52. package/dist/components/cron-editor/meta.js +17 -0
  53. package/dist/components/cron-editor/meta.js.map +1 -0
  54. package/dist/components/date-picker/date-picker.js +1 -1
  55. package/dist/components/diff-viewer/diff-model.d.ts +69 -0
  56. package/dist/components/diff-viewer/diff-model.d.ts.map +1 -0
  57. package/dist/components/diff-viewer/diff-model.js +180 -0
  58. package/dist/components/diff-viewer/diff-model.js.map +1 -0
  59. package/dist/components/diff-viewer/diff-viewer.d.ts +42 -0
  60. package/dist/components/diff-viewer/diff-viewer.d.ts.map +1 -0
  61. package/dist/components/diff-viewer/diff-viewer.js +212 -0
  62. package/dist/components/diff-viewer/diff-viewer.js.map +1 -0
  63. package/dist/components/diff-viewer/index.d.ts +3 -0
  64. package/dist/components/diff-viewer/index.js +3 -0
  65. package/dist/components/diff-viewer/meta.js +17 -0
  66. package/dist/components/diff-viewer/meta.js.map +1 -0
  67. package/dist/components/dns-record/dns-record.d.ts +61 -0
  68. package/dist/components/dns-record/dns-record.d.ts.map +1 -0
  69. package/dist/components/dns-record/dns-record.js +227 -0
  70. package/dist/components/dns-record/dns-record.js.map +1 -0
  71. package/dist/components/dns-record/index.d.ts +2 -0
  72. package/dist/components/dns-record/index.js +2 -0
  73. package/dist/components/dns-record/meta.js +17 -0
  74. package/dist/components/dns-record/meta.js.map +1 -0
  75. package/dist/components/log-viewer/index.d.ts +3 -0
  76. package/dist/components/log-viewer/index.js +3 -0
  77. package/dist/components/log-viewer/log-stream.d.ts +68 -0
  78. package/dist/components/log-viewer/log-stream.d.ts.map +1 -0
  79. package/dist/components/log-viewer/log-stream.js +120 -0
  80. package/dist/components/log-viewer/log-stream.js.map +1 -0
  81. package/dist/components/log-viewer/log-viewer.d.ts +51 -0
  82. package/dist/components/log-viewer/log-viewer.d.ts.map +1 -0
  83. package/dist/components/log-viewer/log-viewer.js +284 -0
  84. package/dist/components/log-viewer/log-viewer.js.map +1 -0
  85. package/dist/components/log-viewer/meta.js +17 -0
  86. package/dist/components/log-viewer/meta.js.map +1 -0
  87. package/dist/components/permission-matrix/index.d.ts +3 -0
  88. package/dist/components/permission-matrix/index.js +3 -0
  89. package/dist/components/permission-matrix/meta.js +17 -0
  90. package/dist/components/permission-matrix/meta.js.map +1 -0
  91. package/dist/components/permission-matrix/permission-matrix.d.ts +46 -0
  92. package/dist/components/permission-matrix/permission-matrix.d.ts.map +1 -0
  93. package/dist/components/permission-matrix/permission-matrix.js +199 -0
  94. package/dist/components/permission-matrix/permission-matrix.js.map +1 -0
  95. package/dist/components/permission-matrix/permission-model.d.ts +53 -0
  96. package/dist/components/permission-matrix/permission-model.d.ts.map +1 -0
  97. package/dist/components/permission-matrix/permission-model.js +64 -0
  98. package/dist/components/permission-matrix/permission-model.js.map +1 -0
  99. package/dist/components/progress/progress.d.ts +1 -1
  100. package/dist/components/secret-field/index.d.ts +2 -0
  101. package/dist/components/secret-field/index.js +2 -0
  102. package/dist/components/secret-field/meta.js +17 -0
  103. package/dist/components/secret-field/meta.js.map +1 -0
  104. package/dist/components/secret-field/secret-field.d.ts +58 -0
  105. package/dist/components/secret-field/secret-field.d.ts.map +1 -0
  106. package/dist/components/secret-field/secret-field.js +168 -0
  107. package/dist/components/secret-field/secret-field.js.map +1 -0
  108. package/dist/components/session-expiry/index.d.ts +2 -0
  109. package/dist/components/session-expiry/index.js +2 -0
  110. package/dist/components/session-expiry/meta.js +17 -0
  111. package/dist/components/session-expiry/meta.js.map +1 -0
  112. package/dist/components/session-expiry/session-expiry.d.ts +64 -0
  113. package/dist/components/session-expiry/session-expiry.d.ts.map +1 -0
  114. package/dist/components/session-expiry/session-expiry.js +185 -0
  115. package/dist/components/session-expiry/session-expiry.js.map +1 -0
  116. package/dist/components/shortcut-recorder/index.d.ts +3 -0
  117. package/dist/components/shortcut-recorder/index.js +3 -0
  118. package/dist/components/shortcut-recorder/meta.js +17 -0
  119. package/dist/components/shortcut-recorder/meta.js.map +1 -0
  120. package/dist/components/shortcut-recorder/shortcut-model.d.ts +67 -0
  121. package/dist/components/shortcut-recorder/shortcut-model.d.ts.map +1 -0
  122. package/dist/components/shortcut-recorder/shortcut-model.js +168 -0
  123. package/dist/components/shortcut-recorder/shortcut-model.js.map +1 -0
  124. package/dist/components/shortcut-recorder/shortcut-recorder.d.ts +47 -0
  125. package/dist/components/shortcut-recorder/shortcut-recorder.d.ts.map +1 -0
  126. package/dist/components/shortcut-recorder/shortcut-recorder.js +212 -0
  127. package/dist/components/shortcut-recorder/shortcut-recorder.js.map +1 -0
  128. package/dist/components/spinner/spinner.d.ts +1 -1
  129. package/dist/components/sync-status/index.d.ts +2 -0
  130. package/dist/components/sync-status/index.js +2 -0
  131. package/dist/components/sync-status/meta.js +17 -0
  132. package/dist/components/sync-status/meta.js.map +1 -0
  133. package/dist/components/sync-status/sync-status.d.ts +65 -0
  134. package/dist/components/sync-status/sync-status.d.ts.map +1 -0
  135. package/dist/components/sync-status/sync-status.js +103 -0
  136. package/dist/components/sync-status/sync-status.js.map +1 -0
  137. package/dist/components/time-range-picker/index.d.ts +3 -0
  138. package/dist/components/time-range-picker/index.js +3 -0
  139. package/dist/components/time-range-picker/meta.js +22 -0
  140. package/dist/components/time-range-picker/meta.js.map +1 -0
  141. package/dist/components/time-range-picker/time-expression.d.ts +88 -0
  142. package/dist/components/time-range-picker/time-expression.d.ts.map +1 -0
  143. package/dist/components/time-range-picker/time-expression.js +335 -0
  144. package/dist/components/time-range-picker/time-expression.js.map +1 -0
  145. package/dist/components/time-range-picker/time-range-picker.d.ts +65 -0
  146. package/dist/components/time-range-picker/time-range-picker.d.ts.map +1 -0
  147. package/dist/components/time-range-picker/time-range-picker.js +377 -0
  148. package/dist/components/time-range-picker/time-range-picker.js.map +1 -0
  149. package/dist/components/toast/toast.d.ts +1 -1
  150. package/dist/index.d.ts +36 -1
  151. package/dist/index.js +24 -3
  152. package/dist/registry/components.d.ts.map +1 -1
  153. package/dist/registry/components.js +78 -50
  154. package/dist/registry/components.js.map +1 -1
  155. package/package.json +6 -4
  156. package/src/components/ai-disclosure/ai-disclosure.tsx +244 -0
  157. package/src/components/ai-disclosure/index.ts +9 -0
  158. package/src/components/ai-disclosure/meta.ts +23 -0
  159. package/src/components/ai-extraction-review/ai-extraction-review.tsx +492 -0
  160. package/src/components/ai-extraction-review/extraction-model.ts +159 -0
  161. package/src/components/ai-extraction-review/index.ts +13 -0
  162. package/src/components/ai-extraction-review/meta.ts +24 -0
  163. package/src/components/ai-suggested-value/ai-suggested-value.tsx +295 -0
  164. package/src/components/ai-suggested-value/index.ts +6 -0
  165. package/src/components/ai-suggested-value/meta.ts +24 -0
  166. package/src/components/confirm-typed/confirm-typed.tsx +191 -0
  167. package/src/components/confirm-typed/index.ts +1 -0
  168. package/src/components/confirm-typed/meta.ts +22 -0
  169. package/src/components/cron-editor/cron-editor.tsx +676 -0
  170. package/src/components/cron-editor/cron-expression.ts +552 -0
  171. package/src/components/cron-editor/index.ts +23 -0
  172. package/src/components/cron-editor/meta.ts +23 -0
  173. package/src/components/diff-viewer/diff-model.ts +256 -0
  174. package/src/components/diff-viewer/diff-viewer.tsx +339 -0
  175. package/src/components/diff-viewer/index.ts +17 -0
  176. package/src/components/diff-viewer/meta.ts +20 -0
  177. package/src/components/dns-record/dns-record.tsx +315 -0
  178. package/src/components/dns-record/index.ts +7 -0
  179. package/src/components/dns-record/meta.ts +21 -0
  180. package/src/components/log-viewer/index.ts +21 -0
  181. package/src/components/log-viewer/log-stream.ts +176 -0
  182. package/src/components/log-viewer/log-viewer.tsx +424 -0
  183. package/src/components/log-viewer/meta.ts +21 -0
  184. package/src/components/permission-matrix/index.ts +14 -0
  185. package/src/components/permission-matrix/meta.ts +23 -0
  186. package/src/components/permission-matrix/permission-matrix.tsx +368 -0
  187. package/src/components/permission-matrix/permission-model.ts +120 -0
  188. package/src/components/secret-field/index.ts +6 -0
  189. package/src/components/secret-field/meta.ts +21 -0
  190. package/src/components/secret-field/secret-field.tsx +284 -0
  191. package/src/components/session-expiry/index.ts +9 -0
  192. package/src/components/session-expiry/meta.ts +23 -0
  193. package/src/components/session-expiry/session-expiry.tsx +321 -0
  194. package/src/components/shortcut-recorder/index.ts +19 -0
  195. package/src/components/shortcut-recorder/meta.ts +22 -0
  196. package/src/components/shortcut-recorder/shortcut-model.ts +204 -0
  197. package/src/components/shortcut-recorder/shortcut-recorder.tsx +336 -0
  198. package/src/components/sync-status/index.ts +9 -0
  199. package/src/components/sync-status/meta.ts +21 -0
  200. package/src/components/sync-status/sync-status.tsx +217 -0
  201. package/src/components/time-range-picker/index.ts +25 -0
  202. package/src/components/time-range-picker/meta.ts +22 -0
  203. package/src/components/time-range-picker/time-expression.ts +491 -0
  204. package/src/components/time-range-picker/time-range-picker.tsx +522 -0
  205. package/src/index.ts +14 -0
  206. package/src/registry/components.ts +28 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-extraction-review.js","names":[],"sources":["../../../src/components/ai-extraction-review/ai-extraction-review.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type ReactNode,\n} from \"react\";\n\nimport { disabledStyles, focusRing } from \"@/lib/styles\";\nimport { cn } from \"@/lib/utils\";\n\nimport {\n evidenceOf,\n isSourced,\n segmentSource,\n summarizeReview,\n type ExtractionField,\n type FieldDecision,\n type SourceRun,\n} from \"./extraction-model\";\n\n/**\n * The check after extraction: the document on one side, what the model read\n * out of it on the other, and a decision about every field.\n *\n * Every extraction demo shows the filled object and stops. The products that\n * run extraction for a living — invoice capture, KYC onboarding, claims intake —\n * all have this screen, each built from scratch, because a value that cannot\n * be checked can only be trusted, and nobody who is paying an invoice trusts a\n * model that far. No component library ships it.\n *\n * The link is the component. Each field carries where in the source it was\n * read from, quoted in text under the value as well as highlighted in the\n * document, so a reviewer who cannot see the highlight still has the evidence.\n * And a value with no evidence is said outright — \"the model supplied this\n * without evidence\" — because that is the case a review exists to catch, and\n * the one every filled-object view renders identically to a good value.\n *\n * Evidence is a text offset, not a bounding box. A language model reads text,\n * and a text layer with offsets is what every OCR pipeline already yields.\n * Boxes over a rendered page need page rendering, zoom and geometry, and are a\n * different component; this one does not pretend at them.\n *\n * Decisions are controlled and the component writes nothing. It reports that\n * a field was accepted as proposed, corrected from what was proposed, or\n * rejected — a richer record than a form's submitted values, and the one an\n * audit later needs — and leaves what to do with it to the application.\n */\n\nexport interface ExtractionReviewProps extends Omit<\n ComponentPropsWithRef<\"section\">,\n \"children\"\n> {\n /** What the model read. Every span indexes into it. */\n source: string;\n /** Names the source — \"Invoice 4471.pdf, page 1\". */\n sourceLabel?: string;\n /** What is being reviewed, as the heading. */\n heading: string;\n fields: ExtractionField[];\n /** Per-field decisions, keyed by field name. Controlled. */\n decisions?: Record<string, FieldDecision>;\n /** Omit to render the review as a record rather than something to operate. */\n onDecision?: (name: string, decision: FieldDecision) => void;\n /** True while fields are still arriving. Missing values wait instead of reading as not found. */\n streaming?: boolean;\n /** Confidence below this is called low, in words. */\n lowConfidenceBelow?: number;\n children?: ReactNode;\n}\n\nexport function ExtractionReview({\n className,\n source,\n sourceLabel = \"Source\",\n heading,\n fields,\n decisions = {},\n onDecision,\n streaming = false,\n lowConfidenceBelow = 0.7,\n children,\n ...props\n}: ExtractionReviewProps) {\n const headingId = useId();\n const [activeField, setActiveField] = useState<string | null>(null);\n\n const runs = useMemo(() => segmentSource(source, fields), [source, fields]);\n const summary = useMemo(\n () => summarizeReview(source, fields, decisions),\n [source, fields, decisions],\n );\n\n return (\n <section\n data-slot=\"extraction-review\"\n data-complete={summary.complete || undefined}\n aria-labelledby={headingId}\n aria-busy={streaming || undefined}\n className={cn(\"flex flex-col gap-3\", className)}\n {...props}\n >\n <div className=\"flex flex-wrap items-baseline justify-between gap-2\">\n <h3 id={headingId} className=\"text-sm font-medium\">\n {heading}\n </h3>\n {/* Live from the start and short, so each decision is followed by\n where the review stands rather than by silence. Evidence gaps are\n counted here too: they are the reason to read carefully, and worth\n knowing before starting rather than discovering on field six. */}\n <p\n data-slot=\"extraction-review-summary\"\n aria-live=\"polite\"\n className=\"text-xs text-muted-foreground\"\n >\n {streaming\n ? \"Fields are still arriving\"\n : `${String(summary.reviewed)} of ${String(summary.total)} reviewed`}\n {summary.unsourced.length > 0\n ? ` · ${String(summary.unsourced.length)} without evidence`\n : null}\n </p>\n </div>\n\n {children}\n\n <div className=\"grid gap-4 md:grid-cols-2\">\n <SourcePanel\n label={sourceLabel}\n runs={runs}\n active={activeField}\n decisions={decisions}\n />\n\n <ol data-slot=\"extraction-fields\" className=\"m-0 flex list-none flex-col gap-3 p-0\">\n {fields.map((field) => (\n <ReviewField\n key={field.name}\n field={field}\n source={source}\n decision={decisions[field.name]}\n streaming={streaming}\n lowConfidenceBelow={lowConfidenceBelow}\n active={activeField === field.name}\n onActivate={() => {\n setActiveField(field.name);\n }}\n onDecision={onDecision}\n />\n ))}\n </ol>\n </div>\n </section>\n );\n}\n\nfunction SourcePanel({\n label,\n runs,\n active,\n decisions,\n}: {\n label: string;\n runs: SourceRun[];\n active: string | null;\n decisions: Record<string, FieldDecision>;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n\n // Bring the active field's evidence into view. Focus stays where it is —\n // in the field — so a keyboard user is shown the source without being\n // moved into it.\n useEffect(() => {\n if (!active || !ref.current) return;\n const mark = ref.current.querySelector(`mark[data-active]`);\n mark?.scrollIntoView({ block: \"nearest\" });\n }, [active]);\n\n return (\n <div\n ref={ref}\n data-slot=\"extraction-source\"\n // A scrolling box has to be focusable to be scrolled by keyboard, and a\n // focusable box needs a name.\n role=\"region\"\n aria-label={label}\n tabIndex={0}\n // Sticks beside the fields on a wide screen, so the evidence for field\n // nine is still in view when the reviewer reaches it.\n className={cn(\n \"max-h-96 overflow-auto rounded-lg border border-border bg-muted/30 p-3 md:sticky md:top-0 md:self-start\",\n focusRing,\n )}\n >\n {runs.length === 0 ? (\n <p className=\"text-xs text-muted-foreground\">No source text.</p>\n ) : (\n <pre className=\"m-0 font-sans text-sm leading-relaxed break-words whitespace-pre-wrap\">\n {runs.map((run, index) =>\n run.fields.length === 0 ? (\n <span key={index}>{run.text}</span>\n ) : (\n // A mark element, so the evidence survives as structure rather\n // than only as a tint. No label is inserted into the text: a\n // document read aloud with field names spliced into it is not\n // the document, and the field already quotes its evidence.\n <mark\n key={index}\n data-fields={run.fields.join(\" \")}\n data-active={active !== null && run.fields.includes(active) ? \"\" : undefined}\n className={cn(\n \"rounded-[2px] text-inherit\",\n run.fields.every((name) => decisions[name]?.kind === \"rejected\")\n ? \"bg-muted line-through decoration-muted-foreground\"\n : \"bg-primary/15\",\n active !== null &&\n run.fields.includes(active) &&\n \"bg-primary/30 ring-1 ring-primary ring-inset\",\n )}\n >\n {run.text}\n </mark>\n ),\n )}\n </pre>\n )}\n </div>\n );\n}\n\n/** Whitespace collapsed and cut short, for quoting evidence under a field. */\nfunction quote(text: string, limit = 80): string {\n const collapsed = text.replace(/\\s+/g, \" \").trim();\n return collapsed.length > limit ? `${collapsed.slice(0, limit - 1)}…` : collapsed;\n}\n\nfunction ReviewField({\n field,\n source,\n decision,\n streaming,\n lowConfidenceBelow,\n active,\n onActivate,\n onDecision,\n}: {\n field: ExtractionField;\n source: string;\n decision?: FieldDecision;\n streaming: boolean;\n lowConfidenceBelow: number;\n active: boolean;\n onActivate: () => void;\n onDecision?: (name: string, decision: FieldDecision) => void;\n}) {\n const inputId = useId();\n const evidenceId = useId();\n const statusId = useId();\n const confidenceId = useId();\n\n // The reviewer's typing, kept apart from the model's value so the decision\n // can say which is which.\n const [draft, setDraft] = useState<string | null>(null);\n\n const proposed = field.value ?? \"\";\n const decided = decision && decision.kind !== \"rejected\" ? decision.value : undefined;\n const current = draft ?? decided ?? proposed;\n const edited = current !== proposed;\n const changedSince = decided !== undefined && current !== decided;\n\n const arriving = streaming && field.value === undefined;\n const sourced = isSourced(source, field);\n const evidence = sourced ? evidenceOf(source, field.span) : \"\";\n const unsourced = !arriving && field.value !== undefined && !sourced;\n\n const accept = () => {\n onDecision?.(\n field.name,\n edited\n ? { kind: \"corrected\", value: current, proposed }\n : { kind: \"accepted\", value: current },\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n if (event.key !== \"Enter\") return;\n // Enter confirms an IME candidate before it means anything else. Without\n // this, a reviewer typing a Japanese correction accepts a fragment of it.\n if (event.nativeEvent.isComposing) return;\n if (field.multiline && !(event.ctrlKey || event.metaKey)) return;\n event.preventDefault();\n accept();\n };\n\n const status = arriving\n ? \"Arriving\"\n : !decision\n ? \"Not reviewed\"\n : decision.kind === \"rejected\"\n ? \"Rejected\"\n : changedSince\n ? `Changed since it was ${decision.kind}`\n : decision.kind === \"accepted\"\n ? \"Accepted\"\n : decision.proposed\n ? `Corrected from “${quote(decision.proposed, 40)}”`\n : \"Supplied by the reviewer\";\n\n const low = field.confidence !== undefined && field.confidence < lowConfidenceBelow;\n const percent =\n field.confidence === undefined\n ? null\n : new Intl.NumberFormat(undefined, { style: \"percent\", maximumFractionDigits: 0 }).format(\n field.confidence,\n );\n\n const describedBy = [evidenceId, statusId, percent !== null ? confidenceId : null]\n .filter(Boolean)\n .join(\" \");\n\n const controlClass = cn(\n \"w-full rounded-md border border-input bg-background px-2 py-1.5 text-sm\",\n edited && \"border-warning\",\n focusRing,\n );\n\n return (\n <li\n data-slot=\"extraction-field\"\n data-field={field.name}\n data-state={arriving ? \"arriving\" : (decision?.kind ?? \"undecided\")}\n data-active={active || undefined}\n data-unsourced={unsourced || undefined}\n // Focus anywhere in the field — value, either button — is the reviewer\n // looking at it, so the source follows without a separate step.\n onFocus={onActivate}\n className={cn(\n \"flex flex-col gap-1 rounded-lg border p-3\",\n active ? \"border-primary\" : \"border-border\",\n decision?.kind === \"rejected\" && \"bg-muted/40\",\n )}\n >\n <div className=\"flex flex-wrap items-baseline justify-between gap-2\">\n {onDecision && !arriving ? (\n <label htmlFor={inputId} className=\"text-xs font-medium text-muted-foreground\">\n {field.label}\n </label>\n ) : (\n <span className=\"text-xs font-medium text-muted-foreground\">{field.label}</span>\n )}\n {/* Status as a word, outside the label so editing never renames the\n control under a screen reader user. */}\n <span\n id={statusId}\n data-slot=\"extraction-field-status\"\n className={cn(\n \"text-xs\",\n decision?.kind === \"rejected\" ? \"text-destructive\" : \"text-muted-foreground\",\n changedSince && \"text-warning\",\n )}\n >\n {status}\n </span>\n </div>\n\n {arriving ? (\n <span\n aria-hidden=\"true\"\n className=\"block h-8 w-full animate-pulse-soft rounded-md bg-muted\"\n />\n ) : !onDecision ? (\n <p className=\"rounded-md bg-muted px-2 py-1.5 text-sm break-words\">\n {current || <span className=\"text-muted-foreground\">Empty</span>}\n </p>\n ) : field.multiline ? (\n <textarea\n id={inputId}\n rows={3}\n value={current}\n aria-describedby={describedBy}\n onChange={(event) => {\n setDraft(event.target.value);\n }}\n onKeyDown={onKeyDown}\n className={cn(controlClass, \"resize-none\")}\n />\n ) : (\n <input\n id={inputId}\n type=\"text\"\n value={current}\n aria-describedby={describedBy}\n onChange={(event) => {\n setDraft(event.target.value);\n }}\n onKeyDown={onKeyDown}\n className={controlClass}\n />\n )}\n\n {/* The evidence in text. This is the accessible path to the source, and\n for a sighted reviewer it is the comparison itself — \"1 March 2026\"\n beside \"2026-03-01\" is a normalisation, not an error, and only reads\n that way with both in view. */}\n <p\n id={evidenceId}\n data-slot=\"extraction-field-evidence\"\n className={cn(\"text-xs\", unsourced ? \"text-warning\" : \"text-muted-foreground\")}\n >\n {arriving\n ? \"Waiting for the model\"\n : sourced\n ? `In the source: “${quote(evidence)}”`\n : field.value === undefined\n ? \"The model found nothing for this field.\"\n : \"Not in the source — the model supplied this without evidence.\"}\n </p>\n\n {percent !== null ? (\n <p\n id={confidenceId}\n data-slot=\"extraction-field-confidence\"\n data-low={low || undefined}\n className={cn(\"text-xs\", low ? \"text-warning\" : \"text-muted-foreground\")}\n >\n {low ? `Low confidence, ${percent} — worth checking` : `${percent} confidence`}\n </p>\n ) : null}\n\n {onDecision && !arriving ? (\n <div className=\"mt-1 flex flex-wrap items-center gap-2\">\n <FieldButton\n variant=\"primary\"\n aria-label={`${edited ? \"Accept correction\" : \"Accept\"} — ${field.label}`}\n aria-pressed={\n decision !== undefined && decision.kind !== \"rejected\" && !changedSince\n }\n onClick={accept}\n >\n {edited ? \"Accept correction\" : \"Accept\"}\n </FieldButton>\n <FieldButton\n aria-label={`Reject — ${field.label}`}\n aria-pressed={decision?.kind === \"rejected\"}\n onClick={() => {\n onDecision(field.name, { kind: \"rejected\" });\n }}\n >\n Reject\n </FieldButton>\n {sourced ? (\n <FieldButton\n aria-label={`Show in source — ${field.label}`}\n className=\"ml-auto\"\n onClick={onActivate}\n >\n Show in source\n </FieldButton>\n ) : null}\n </div>\n ) : null}\n </li>\n );\n}\n\nfunction FieldButton({\n className,\n variant = \"default\",\n ...props\n}: ComponentPropsWithRef<\"button\"> & { variant?: \"default\" | \"primary\" }) {\n return (\n <button\n type=\"button\"\n className={cn(\n \"rounded-md border px-2.5 py-1 text-xs font-medium transition-colors\",\n variant === \"primary\" &&\n \"border-primary bg-primary text-primary-foreground hover:bg-primary-hover aria-pressed:bg-primary-active\",\n variant === \"default\" &&\n \"border-input bg-background hover:bg-accent hover:text-accent-foreground aria-pressed:bg-secondary aria-pressed:text-secondary-foreground\",\n focusRing,\n disabledStyles,\n className,\n )}\n {...props}\n />\n );\n}\n"],"mappings":";;;;;;;AA4EA,SAAgB,iBAAiB,EAC/B,WACA,QACA,cAAc,UACd,SACA,QACA,YAAY,CAAC,GACb,YACA,YAAY,OACZ,qBAAqB,IACrB,UACA,GAAG,SACqB;CACxB,MAAM,YAAY,MAAM;CACxB,MAAM,CAAC,aAAa,kBAAkB,SAAwB,IAAI;CAElE,MAAM,OAAO,cAAc,cAAc,QAAQ,MAAM,GAAG,CAAC,QAAQ,MAAM,CAAC;CAC1E,MAAM,UAAU,cACR,gBAAgB,QAAQ,QAAQ,SAAS,GAC/C;EAAC;EAAQ;EAAQ;CAAS,CAC5B;CAEA,OACE,qBAAC,WAAD;EACE,aAAU;EACV,iBAAe,QAAQ,YAAY,KAAA;EACnC,mBAAiB;EACjB,aAAW,aAAa,KAAA;EACxB,WAAW,GAAG,uBAAuB,SAAS;EAC9C,GAAI;EANN,UAAA;GAQE,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,MAAD;KAAI,IAAI;KAAW,WAAU;KAC1B,UAAA;IACC,CAAA,GAKJ,qBAAC,KAAD;KACE,aAAU;KACV,aAAU;KACV,WAAU;KAHZ,UAAA,CAKG,YACG,8BACA,GAAG,OAAO,QAAQ,QAAQ,EAAE,MAAM,OAAO,QAAQ,KAAK,EAAE,YAC3D,QAAQ,UAAU,SAAS,IACxB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ACX;IACD;GACH,CAAA,IAAA;EACF;;AAER;AAEA,SAAS,YAAY,EACnB,WACA,UAAU,WACV,GAAG,SACqE;CACxE,OACE,oBAAC,UAAD;EACE,MAAK;EACL,WAAW,GACT,uEACA,YAAY,aACV,2GACF,YAAY,aACV,4IACF,WACA,gBACA,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
@@ -0,0 +1,94 @@
1
+ //#region src/components/ai-extraction-review/extraction-model.d.ts
2
+ /**
3
+ * The model behind a review of extracted fields: where each value was read
4
+ * from, what the reviewer decided about it, and how far through the review
5
+ * they are.
6
+ *
7
+ * Pure, so overlap handling and the completion rule are tested without
8
+ * rendering anything — and so an application can answer "is this review
9
+ * finished" on the server from the same decisions the component reports,
10
+ * rather than trusting a flag the client sent.
11
+ */
12
+ interface SourceSpan {
13
+ /** Offset into the source text in UTF-16 code units. Inclusive. */
14
+ start: number;
15
+ /** Exclusive. */
16
+ end: number;
17
+ }
18
+ interface ExtractionField {
19
+ /** Key in the extracted object. */
20
+ name: string;
21
+ label: string;
22
+ /**
23
+ * What the model extracted. Absent while streaming means it has not arrived;
24
+ * absent once streaming has ended means the model found nothing.
25
+ */
26
+ value?: string;
27
+ /**
28
+ * Where in the source the value was read from. Absent means the model
29
+ * supplied the value without evidence, which the review says outright.
30
+ */
31
+ span?: SourceSpan;
32
+ /** 0 to 1. Shown as a number, never only as a colour. */
33
+ confidence?: number;
34
+ /** A textarea instead of a single line. For addresses and descriptions. */
35
+ multiline?: boolean;
36
+ }
37
+ type FieldDecision =
38
+ /** The model's value, taken as it was. */
39
+ {
40
+ kind: "accepted";
41
+ value: string;
42
+ } |
43
+ /** The reviewer's value, with the model's kept so a record can tell them apart. */
44
+ {
45
+ kind: "corrected";
46
+ value: string;
47
+ proposed: string;
48
+ } |
49
+ /** Wrong and not corrected — the field does not apply, or cannot be known. */
50
+ {
51
+ kind: "rejected";
52
+ };
53
+ /** A run of source text and the fields whose evidence covers it. */
54
+ interface SourceRun {
55
+ text: string;
56
+ /** Field names, in declaration order. Empty for text nobody cites. */
57
+ fields: string[];
58
+ }
59
+ /**
60
+ * A span brought within the source, or null if nothing of it is.
61
+ *
62
+ * Offsets come from a model or an OCR layer and are wrong often enough that
63
+ * refusing to render on a bad one would leave the whole review blank. A span
64
+ * past the end is clamped; an inverted or empty one is treated as no evidence,
65
+ * which is what it is.
66
+ */
67
+ declare function clampSpan(span: SourceSpan, length: number): SourceSpan | null;
68
+ /** The text a span points at, or an empty string if it points at nothing. */
69
+ declare function evidenceOf(source: string, span: SourceSpan | undefined): string;
70
+ /** Whether a field's value can be checked against the source at all. */
71
+ declare function isSourced(source: string, field: ExtractionField): boolean;
72
+ /**
73
+ * Cuts the source into runs at every span boundary, so overlapping evidence —
74
+ * a total that sits inside the line that contains it — renders as nested
75
+ * coverage rather than as two marks fighting over the same characters.
76
+ */
77
+ declare function segmentSource(source: string, fields: ExtractionField[]): SourceRun[];
78
+ interface ReviewSummary {
79
+ total: number;
80
+ reviewed: number;
81
+ accepted: number;
82
+ corrected: number;
83
+ rejected: number;
84
+ /** Fields with a value the model could not point to in the source. */
85
+ unsourced: string[];
86
+ /** Fields still awaiting a decision. */
87
+ remaining: string[];
88
+ /** Every field has a decision. The only completion signal worth trusting. */
89
+ complete: boolean;
90
+ }
91
+ declare function summarizeReview(source: string, fields: ExtractionField[], decisions?: Record<string, FieldDecision>): ReviewSummary;
92
+ //#endregion
93
+ export { ExtractionField, FieldDecision, ReviewSummary, SourceRun, SourceSpan, clampSpan, evidenceOf, isSourced, segmentSource, summarizeReview };
94
+ //# sourceMappingURL=extraction-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extraction-model.d.ts","names":[],"sources":["../../../src/components/ai-extraction-review/extraction-model.ts"],"mappings":";;;;;;;;;;;UAWiB;;EAEf;;EAEA;;UAGe;;EAEf;EACA;;;;;EAKA;;;;;EAKA,OAAO;;EAEP;;EAEA;;KAGU;;;EAEN;EAAkB;;;;EAElB;EAAmB;EAAe;;;;EAElC;;;UAGW;EACf;;EAEA;;;;;;;;;;iBAWc,UAAU,MAAM,YAAY,iBAAiB;;iBAO7C,WAAW,gBAAgB,MAAM;;iBAOjC,UAAU,gBAAgB,OAAO;;;;;;iBASjC,cAAc,gBAAgB,QAAQ,oBAAoB;UA6BzD;EACf;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;iBAGc,gBACd,gBACA,QAAQ,mBACR,YAAW,eAAe,iBACzB"}
@@ -0,0 +1,91 @@
1
+ //#region src/components/ai-extraction-review/extraction-model.ts
2
+ /**
3
+ * A span brought within the source, or null if nothing of it is.
4
+ *
5
+ * Offsets come from a model or an OCR layer and are wrong often enough that
6
+ * refusing to render on a bad one would leave the whole review blank. A span
7
+ * past the end is clamped; an inverted or empty one is treated as no evidence,
8
+ * which is what it is.
9
+ */
10
+ function clampSpan(span, length) {
11
+ const start = Math.max(0, Math.min(span.start, length));
12
+ const end = Math.max(0, Math.min(span.end, length));
13
+ return end > start ? {
14
+ start,
15
+ end
16
+ } : null;
17
+ }
18
+ /** The text a span points at, or an empty string if it points at nothing. */
19
+ function evidenceOf(source, span) {
20
+ if (!span) return "";
21
+ const clamped = clampSpan(span, source.length);
22
+ return clamped ? source.slice(clamped.start, clamped.end) : "";
23
+ }
24
+ /** Whether a field's value can be checked against the source at all. */
25
+ function isSourced(source, field) {
26
+ return field.span !== void 0 && clampSpan(field.span, source.length) !== null;
27
+ }
28
+ /**
29
+ * Cuts the source into runs at every span boundary, so overlapping evidence —
30
+ * a total that sits inside the line that contains it — renders as nested
31
+ * coverage rather than as two marks fighting over the same characters.
32
+ */
33
+ function segmentSource(source, fields) {
34
+ const spans = fields.flatMap((field) => {
35
+ const clamped = field.span ? clampSpan(field.span, source.length) : null;
36
+ return clamped ? [{
37
+ name: field.name,
38
+ ...clamped
39
+ }] : [];
40
+ });
41
+ if (source.length === 0) return [];
42
+ if (spans.length === 0) return [{
43
+ text: source,
44
+ fields: []
45
+ }];
46
+ const cuts = /* @__PURE__ */ new Set([0, source.length]);
47
+ for (const span of spans) {
48
+ cuts.add(span.start);
49
+ cuts.add(span.end);
50
+ }
51
+ const points = [...cuts].sort((a, b) => a - b);
52
+ const runs = [];
53
+ for (let index = 0; index < points.length - 1; index += 1) {
54
+ const start = points[index] ?? 0;
55
+ const end = points[index + 1] ?? start;
56
+ if (end <= start) continue;
57
+ runs.push({
58
+ text: source.slice(start, end),
59
+ fields: spans.filter((span) => span.start <= start && span.end >= end).map((s) => s.name)
60
+ });
61
+ }
62
+ return runs;
63
+ }
64
+ function summarizeReview(source, fields, decisions = {}) {
65
+ const summary = {
66
+ total: fields.length,
67
+ reviewed: 0,
68
+ accepted: 0,
69
+ corrected: 0,
70
+ rejected: 0,
71
+ unsourced: [],
72
+ remaining: [],
73
+ complete: false
74
+ };
75
+ for (const field of fields) {
76
+ if (field.value !== void 0 && !isSourced(source, field)) summary.unsourced.push(field.name);
77
+ const decision = decisions[field.name];
78
+ if (!decision) {
79
+ summary.remaining.push(field.name);
80
+ continue;
81
+ }
82
+ summary.reviewed += 1;
83
+ summary[decision.kind] += 1;
84
+ }
85
+ summary.complete = fields.length > 0 && summary.remaining.length === 0;
86
+ return summary;
87
+ }
88
+ //#endregion
89
+ export { clampSpan, evidenceOf, isSourced, segmentSource, summarizeReview };
90
+
91
+ //# sourceMappingURL=extraction-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extraction-model.js","names":[],"sources":["../../../src/components/ai-extraction-review/extraction-model.ts"],"sourcesContent":["/**\n * The model behind a review of extracted fields: where each value was read\n * from, what the reviewer decided about it, and how far through the review\n * they are.\n *\n * Pure, so overlap handling and the completion rule are tested without\n * rendering anything — and so an application can answer \"is this review\n * finished\" on the server from the same decisions the component reports,\n * rather than trusting a flag the client sent.\n */\n\nexport interface SourceSpan {\n /** Offset into the source text in UTF-16 code units. Inclusive. */\n start: number;\n /** Exclusive. */\n end: number;\n}\n\nexport interface ExtractionField {\n /** Key in the extracted object. */\n name: string;\n label: string;\n /**\n * What the model extracted. Absent while streaming means it has not arrived;\n * absent once streaming has ended means the model found nothing.\n */\n value?: string;\n /**\n * Where in the source the value was read from. Absent means the model\n * supplied the value without evidence, which the review says outright.\n */\n span?: SourceSpan;\n /** 0 to 1. Shown as a number, never only as a colour. */\n confidence?: number;\n /** A textarea instead of a single line. For addresses and descriptions. */\n multiline?: boolean;\n}\n\nexport type FieldDecision =\n /** The model's value, taken as it was. */\n | { kind: \"accepted\"; value: string }\n /** The reviewer's value, with the model's kept so a record can tell them apart. */\n | { kind: \"corrected\"; value: string; proposed: string }\n /** Wrong and not corrected — the field does not apply, or cannot be known. */\n | { kind: \"rejected\" };\n\n/** A run of source text and the fields whose evidence covers it. */\nexport interface SourceRun {\n text: string;\n /** Field names, in declaration order. Empty for text nobody cites. */\n fields: string[];\n}\n\n/**\n * A span brought within the source, or null if nothing of it is.\n *\n * Offsets come from a model or an OCR layer and are wrong often enough that\n * refusing to render on a bad one would leave the whole review blank. A span\n * past the end is clamped; an inverted or empty one is treated as no evidence,\n * which is what it is.\n */\nexport function clampSpan(span: SourceSpan, length: number): SourceSpan | null {\n const start = Math.max(0, Math.min(span.start, length));\n const end = Math.max(0, Math.min(span.end, length));\n return end > start ? { start, end } : null;\n}\n\n/** The text a span points at, or an empty string if it points at nothing. */\nexport function evidenceOf(source: string, span: SourceSpan | undefined): string {\n if (!span) return \"\";\n const clamped = clampSpan(span, source.length);\n return clamped ? source.slice(clamped.start, clamped.end) : \"\";\n}\n\n/** Whether a field's value can be checked against the source at all. */\nexport function isSourced(source: string, field: ExtractionField): boolean {\n return field.span !== undefined && clampSpan(field.span, source.length) !== null;\n}\n\n/**\n * Cuts the source into runs at every span boundary, so overlapping evidence —\n * a total that sits inside the line that contains it — renders as nested\n * coverage rather than as two marks fighting over the same characters.\n */\nexport function segmentSource(source: string, fields: ExtractionField[]): SourceRun[] {\n const spans = fields.flatMap((field) => {\n const clamped = field.span ? clampSpan(field.span, source.length) : null;\n return clamped ? [{ name: field.name, ...clamped }] : [];\n });\n\n if (source.length === 0) return [];\n if (spans.length === 0) return [{ text: source, fields: [] }];\n\n const cuts = new Set<number>([0, source.length]);\n for (const span of spans) {\n cuts.add(span.start);\n cuts.add(span.end);\n }\n const points = [...cuts].sort((a, b) => a - b);\n\n const runs: SourceRun[] = [];\n for (let index = 0; index < points.length - 1; index += 1) {\n const start = points[index] ?? 0;\n const end = points[index + 1] ?? start;\n if (end <= start) continue;\n runs.push({\n text: source.slice(start, end),\n fields: spans.filter((span) => span.start <= start && span.end >= end).map((s) => s.name),\n });\n }\n return runs;\n}\n\nexport interface ReviewSummary {\n total: number;\n reviewed: number;\n accepted: number;\n corrected: number;\n rejected: number;\n /** Fields with a value the model could not point to in the source. */\n unsourced: string[];\n /** Fields still awaiting a decision. */\n remaining: string[];\n /** Every field has a decision. The only completion signal worth trusting. */\n complete: boolean;\n}\n\nexport function summarizeReview(\n source: string,\n fields: ExtractionField[],\n decisions: Record<string, FieldDecision> = {},\n): ReviewSummary {\n const summary: ReviewSummary = {\n total: fields.length,\n reviewed: 0,\n accepted: 0,\n corrected: 0,\n rejected: 0,\n unsourced: [],\n remaining: [],\n complete: false,\n };\n\n for (const field of fields) {\n if (field.value !== undefined && !isSourced(source, field)) {\n summary.unsourced.push(field.name);\n }\n const decision = decisions[field.name];\n if (!decision) {\n summary.remaining.push(field.name);\n continue;\n }\n summary.reviewed += 1;\n summary[decision.kind] += 1;\n }\n\n summary.complete = fields.length > 0 && summary.remaining.length === 0;\n return summary;\n}\n"],"mappings":";;;;;;;;;AA6DA,SAAgB,UAAU,MAAkB,QAAmC;CAC7E,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,OAAO,MAAM,CAAC;CACtD,MAAM,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC;CAClD,OAAO,MAAM,QAAQ;EAAE;EAAO;CAAI,IAAI;AACxC;;AAGA,SAAgB,WAAW,QAAgB,MAAsC;CAC/E,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T;AAgBA,SAAgB,gBACd,QACA,QACA,YAA2C,CAAC,GAC7B;CACf,MAAM,UAAyB;EAC7B,OAAO,OAAO;EACd,UAAU;EACV,UAAU;EACV,WAAW;EACX,UAAU;EACV,WAAW,CAAC;EACZ,WAAW,CAAC;EACZ,UAAU;CACZ;CAEA,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,UAAU,KAAA,KAAa,CAAC,UAAU,QAAQ,KAAK,GACvD,QAAQ,UAAU,KAAK,MAAM,IAAI;EAEnC,MAAM,WAAW,UAAU,MAAM;EACjC,IAAI,CAAC,UAAU;GACb,QAAQ,UAAU,KAAK,MAAM,IAAI;GACjC;EACF;EACA,QAAQ,YAAY;EACpB,QAAQ,SAAS,SAAS;CAC5B;CAEA,QAAQ,WAAW,OAAO,SAAS,KAAK,QAAQ,UAAU,WAAW;CACrE,OAAO;AACT"}
@@ -0,0 +1,3 @@
1
+ import { ExtractionField, FieldDecision, ReviewSummary, SourceRun, SourceSpan, clampSpan, evidenceOf, isSourced, segmentSource, summarizeReview } from "./extraction-model.js";
2
+ import { ExtractionReview, ExtractionReviewProps } from "./ai-extraction-review.js";
3
+ export { type ExtractionField, ExtractionReview, type ExtractionReviewProps, type FieldDecision, type ReviewSummary, type SourceRun, type SourceSpan, clampSpan, evidenceOf, isSourced, segmentSource, summarizeReview };
@@ -0,0 +1,3 @@
1
+ import { clampSpan, evidenceOf, isSourced, segmentSource, summarizeReview } from "./extraction-model.js";
2
+ import { ExtractionReview } from "./ai-extraction-review.js";
3
+ export { ExtractionReview, clampSpan, evidenceOf, isSourced, segmentSource, summarizeReview };
@@ -0,0 +1,17 @@
1
+ import { defineMeta } from "../../registry/schema.js";
2
+ //#region src/components/ai-extraction-review/meta.ts
3
+ const meta = defineMeta({
4
+ name: "ai-extraction-review",
5
+ title: "AI Extraction Review",
6
+ description: "Check extracted fields against the document they came from, and decide each one.",
7
+ category: "ai",
8
+ status: "stable",
9
+ dependencies: [],
10
+ registryDependencies: [],
11
+ files: ["extraction-model.ts", "ai-extraction-review.tsx"],
12
+ a11y: "Every field quotes its evidence in text under the value, so a reviewer who cannot see the highlight in the source still has what the model read. A value with no evidence is said in words — never left to look like a good one. The source is a focusable named region because it scrolls, and its highlights are mark elements with nothing spliced into the text, since a document read aloud with field names inserted is no longer the document. Focus anywhere in a field brings its evidence into view without moving focus, so a keyboard user is shown the source rather than sent into it. Each control's name carries the field it belongs to, so ten Accept buttons are ten different buttons. Status is a word, outside the label so editing never renames the control, and the running count is a polite live region present from the start. Enter accepts, except while an IME is composing."
13
+ });
14
+ //#endregion
15
+ export { meta };
16
+
17
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","names":[],"sources":["../../../src/components/ai-extraction-review/meta.ts"],"sourcesContent":["import { defineMeta } from \"@/registry/schema\";\n\nexport const meta = defineMeta({\n name: \"ai-extraction-review\",\n title: \"AI Extraction Review\",\n description:\n \"Check extracted fields against the document they came from, and decide each one.\",\n category: \"ai\",\n status: \"stable\",\n dependencies: [],\n registryDependencies: [],\n files: [\"extraction-model.ts\", \"ai-extraction-review.tsx\"],\n a11y:\n \"Every field quotes its evidence in text under the value, so a reviewer who cannot see the \" +\n \"highlight in the source still has what the model read. A value with no evidence is said in \" +\n \"words — never left to look like a good one. The source is a focusable named region because \" +\n \"it scrolls, and its highlights are mark elements with nothing spliced into the text, since a \" +\n \"document read aloud with field names inserted is no longer the document. Focus anywhere in a \" +\n \"field brings its evidence into view without moving focus, so a keyboard user is shown the \" +\n \"source rather than sent into it. Each control's name carries the field it belongs to, so \" +\n \"ten Accept buttons are ten different buttons. Status is a word, outside the label so editing \" +\n \"never renames the control, and the running count is a polite live region present from the \" +\n \"start. Enter accepts, except while an IME is composing.\",\n});\n"],"mappings":";;AAEA,MAAa,OAAO,WAAW;CAC7B,MAAM;CACN,OAAO;CACP,aACE;CACF,UAAU;CACV,QAAQ;CACR,cAAc,CAAC;CACf,sBAAsB,CAAC;CACvB,OAAO,CAAC,uBAAuB,0BAA0B;CACzD,MACE;AAUJ,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { ComponentPropsWithRef, ReactElement } from "react";
2
+ //#region src/components/ai-suggested-value/ai-suggested-value.d.ts
3
+ /**
4
+ * An AI-proposed value for a form control, offered beside it rather than
5
+ * written into it.
6
+ *
7
+ * Autofill is the most common shape AI takes inside ordinary software —
8
+ * enrich this contact, fill this form from the upload, guess the category —
9
+ * and nearly every implementation writes the value straight into the field
10
+ * as if the person had typed it. Two things go wrong. A plausible, wrong
11
+ * value rides through on the person's own Submit, because nothing marked it
12
+ * as needing a look. And once submitted, the record cannot tell a value the
13
+ * model supplied from one a human typed, which is the one fact an audit later
14
+ * needs.
15
+ *
16
+ * So the suggestion stays pending until it is accepted, and acceptance is
17
+ * reported rather than performed: the component hands the value to `onAccept`
18
+ * and never touches the control. That is also what lets it wrap any control —
19
+ * a select, a date, a number, a combobox — where ghost text can only complete
20
+ * a string. Afterwards the field says it was filled by AI, says if it was
21
+ * edited since, and offers to put back what was there.
22
+ *
23
+ * Deliberately no "accept all". A button that takes every suggestion at once
24
+ * is the review deleting itself, and every product that ships one watches its
25
+ * users press it without reading.
26
+ */
27
+ interface Suggestion<T = string> {
28
+ value: T;
29
+ /** How the value reads — a select's option text, a formatted date. Defaults to the value. */
30
+ label?: string;
31
+ /** Where it came from, in the reader's language: "from the invoice header". */
32
+ source?: string;
33
+ /** 0 to 1. Shown as a number, never only as a colour. */
34
+ confidence?: number;
35
+ }
36
+ type SuggestionStatus = "pending" | "accepted" | "dismissed";
37
+ interface SuggestedValueProps<T = string> extends Omit<ComponentPropsWithRef<"div">, "children" | "id" | "aria-describedby" | "aria-invalid"> {
38
+ /** The field, for the buttons' names: "Accept suggestion — Company". */
39
+ label: string;
40
+ /** Null or undefined offers nothing. A different suggestion starts pending again. */
41
+ suggestion?: Suggestion<T> | null;
42
+ /**
43
+ * The control's current value. Lets the marker say the fill was edited
44
+ * since, and lets Undo restore what the field held before.
45
+ */
46
+ value?: T;
47
+ /** Supply to own the status; otherwise it is kept here. */
48
+ status?: SuggestionStatus;
49
+ onAccept: (value: T, suggestion: Suggestion<T>) => void;
50
+ onDismiss?: (suggestion: Suggestion<T>) => void;
51
+ /** Called with the value the field held before the fill, so it can be put back. */
52
+ onRevert?: (previous: T | undefined) => void;
53
+ /** How to compare values. Object.is by default. */
54
+ equals?: (a: T, b: T) => boolean;
55
+ /** Confidence below this is called low, in words. */
56
+ lowConfidenceBelow?: number;
57
+ /**
58
+ * Announce a suggestion when it arrives. Off by default: a form that fills
59
+ * twenty fields at once would narrate all twenty, and the description on
60
+ * the control already tells a reader when they reach the field.
61
+ */
62
+ announce?: boolean;
63
+ /** The control. Receives the description, and any id or ARIA a FormControl passes down. */
64
+ children: ReactElement<Record<string, unknown>>;
65
+ id?: string;
66
+ "aria-describedby"?: string;
67
+ "aria-invalid"?: ComponentPropsWithRef<"input">["aria-invalid"];
68
+ }
69
+ declare function SuggestedValue<T = string>({ className, label, suggestion, value, status: controlledStatus, onAccept, onDismiss, onRevert, equals, lowConfidenceBelow, announce, children, id, "aria-describedby": describedByProp, "aria-invalid": ariaInvalid, ...props }: SuggestedValueProps<T>): import("react").JSX.Element;
70
+ //#endregion
71
+ export { SuggestedValue, SuggestedValueProps, Suggestion, SuggestionStatus };
72
+ //# sourceMappingURL=ai-suggested-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-suggested-value.d.ts","names":[],"sources":["../../../src/components/ai-suggested-value/ai-suggested-value.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;UAwCiB,WAAW;EAC1B,OAAO;;EAEP;;EAEA;;EAEA;;KAGU;UAEK,oBAAoB,oBAAoB,KACvD;;EAIA;;EAEA,aAAa,WAAW;;;;;EAKxB,QAAQ;;EAER,SAAS;EACT,WAAW,OAAO,GAAG,YAAY,WAAW;EAC5C,aAAa,YAAY,WAAW;;EAEpC,YAAY,UAAU;;EAEtB,UAAU,GAAG,GAAG,GAAG;;EAEnB;;;;;;EAMA;;EAEA,UAAU,aAAa;EAEvB;EACA;EACA,iBAAiB;;iBAqBH,eAAe,cAC7B,WACA,OACA,YACA,OACA,QAAQ,kBACR,UACA,WACA,UACA,QACA,oBACA,UACA,UACA,wBACoB,iCACJ,gBACb,SACF,oBAAoB,qBAAE,IAAA"}
@@ -0,0 +1,126 @@
1
+ "use client";
2
+ import { disabledStyles, focusRing } from "../../lib/styles.js";
3
+ import { cn } from "../../lib/utils.js";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ import { cloneElement, isValidElement, useId, useState } from "react";
6
+ //#region src/components/ai-suggested-value/ai-suggested-value.tsx
7
+ function defaultLabel(value) {
8
+ if (value === null || value === void 0) return "";
9
+ if (typeof value === "string") return value;
10
+ if (typeof value === "number" || typeof value === "bigint") return String(value);
11
+ if (typeof value === "boolean") return value ? "Yes" : "No";
12
+ if (value instanceof Date) return value.toLocaleDateString();
13
+ return JSON.stringify(value);
14
+ }
15
+ function sameSuggestion(a, b, equals) {
16
+ if (!a || !b) return a === b;
17
+ return equals(a.value, b.value) && a.label === b.label && a.source === b.source;
18
+ }
19
+ function SuggestedValue({ className, label, suggestion, value, status: controlledStatus, onAccept, onDismiss, onRevert, equals = Object.is, lowConfidenceBelow = .7, announce = false, children, id, "aria-describedby": describedByProp, "aria-invalid": ariaInvalid, ...props }) {
20
+ const descriptionId = useId();
21
+ const [internalStatus, setInternalStatus] = useState("pending");
22
+ const [previous, setPrevious] = useState(void 0);
23
+ const [seen, setSeen] = useState(suggestion);
24
+ if (!sameSuggestion(seen, suggestion, equals)) {
25
+ setSeen(suggestion);
26
+ setInternalStatus("pending");
27
+ }
28
+ const status = controlledStatus ?? internalStatus;
29
+ const offered = suggestion ?? null;
30
+ const pending = offered !== null && status === "pending";
31
+ const accepted = offered !== null && status === "accepted";
32
+ const edited = accepted && value !== void 0 && !equals(value, offered.value);
33
+ const low = offered?.confidence !== void 0 && offered.confidence < lowConfidenceBelow;
34
+ const percent = offered?.confidence === void 0 ? null : new Intl.NumberFormat(void 0, {
35
+ style: "percent",
36
+ maximumFractionDigits: 0
37
+ }).format(offered.confidence);
38
+ const source = offered?.source ? ` ${offered.source}` : "";
39
+ let description = null;
40
+ if (pending) description = /* @__PURE__ */ jsxs(Fragment, { children: [
41
+ "Suggested:",
42
+ " ",
43
+ /* @__PURE__ */ jsx("strong", {
44
+ className: "font-medium text-foreground",
45
+ children: offered.label ?? defaultLabel(offered.value)
46
+ }),
47
+ source ? `,${source}` : null,
48
+ percent !== null ? /* @__PURE__ */ jsx("span", {
49
+ className: cn(low && "text-warning"),
50
+ children: low ? `. Low confidence, ${percent} — worth checking` : `. ${percent} confidence`
51
+ }) : null
52
+ ] });
53
+ else if (accepted) description = edited ? `Filled by AI${source ? `,${source}` : ""}, then edited` : `Filled by AI${source ? `,${source}` : ""}`;
54
+ const describedBy = [
55
+ isValidElement(children) ? children.props["aria-describedby"] : void 0,
56
+ describedByProp,
57
+ description !== null ? descriptionId : null
58
+ ].filter(Boolean).join(" ") || void 0;
59
+ const control = isValidElement(children) ? cloneElement(children, {
60
+ id: id ?? children.props.id,
61
+ "aria-describedby": describedBy,
62
+ "aria-invalid": ariaInvalid ?? children.props["aria-invalid"]
63
+ }) : children;
64
+ const accept = () => {
65
+ if (!offered) return;
66
+ setPrevious(value);
67
+ setInternalStatus("accepted");
68
+ onAccept(offered.value, offered);
69
+ };
70
+ return /* @__PURE__ */ jsxs("div", {
71
+ "data-slot": "suggested-value",
72
+ "data-status": offered ? status : void 0,
73
+ "data-filled-by": accepted ? "ai" : void 0,
74
+ "data-edited": edited || void 0,
75
+ className: cn("flex flex-col gap-1.5", className),
76
+ ...props,
77
+ children: [control, /* @__PURE__ */ jsxs("div", {
78
+ "data-slot": "suggested-value-row",
79
+ "aria-live": announce ? "polite" : void 0,
80
+ className: cn("flex flex-wrap items-center gap-x-3 gap-y-1 text-xs", pending && "rounded-md border border-primary/40 bg-primary/5 px-2.5 py-1.5"),
81
+ children: [
82
+ description !== null ? /* @__PURE__ */ jsx("p", {
83
+ id: descriptionId,
84
+ "data-slot": "suggested-value-description",
85
+ className: "m-0 flex-1 text-muted-foreground",
86
+ children: description
87
+ }) : null,
88
+ pending ? /* @__PURE__ */ jsxs("span", {
89
+ className: "flex items-center gap-2",
90
+ children: [/* @__PURE__ */ jsx(RowButton, {
91
+ variant: "primary",
92
+ "aria-label": `Accept suggestion — ${label}`,
93
+ onClick: accept,
94
+ children: "Accept"
95
+ }), /* @__PURE__ */ jsx(RowButton, {
96
+ "aria-label": `Dismiss suggestion — ${label}`,
97
+ onClick: () => {
98
+ setInternalStatus("dismissed");
99
+ onDismiss?.(offered);
100
+ },
101
+ children: "Dismiss"
102
+ })]
103
+ }) : null,
104
+ accepted && onRevert ? /* @__PURE__ */ jsx(RowButton, {
105
+ "aria-label": `Undo — ${label}`,
106
+ onClick: () => {
107
+ setInternalStatus("pending");
108
+ onRevert(previous);
109
+ },
110
+ children: "Undo"
111
+ }) : null
112
+ ]
113
+ })]
114
+ });
115
+ }
116
+ function RowButton({ className, variant = "default", ...props }) {
117
+ return /* @__PURE__ */ jsx("button", {
118
+ type: "button",
119
+ className: cn("rounded-md border px-2 py-0.5 text-xs font-medium transition-colors", variant === "primary" ? "border-primary bg-primary text-primary-foreground hover:bg-primary-hover" : "border-input bg-background hover:bg-accent hover:text-accent-foreground", focusRing, disabledStyles, className),
120
+ ...props
121
+ });
122
+ }
123
+ //#endregion
124
+ export { SuggestedValue };
125
+
126
+ //# sourceMappingURL=ai-suggested-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-suggested-value.js","names":[],"sources":["../../../src/components/ai-suggested-value/ai-suggested-value.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n isValidElement,\n useId,\n useState,\n type ComponentPropsWithRef,\n type ReactElement,\n type ReactNode,\n} from \"react\";\n\nimport { disabledStyles, focusRing } from \"@/lib/styles\";\nimport { cn } from \"@/lib/utils\";\n\n/**\n * An AI-proposed value for a form control, offered beside it rather than\n * written into it.\n *\n * Autofill is the most common shape AI takes inside ordinary software —\n * enrich this contact, fill this form from the upload, guess the category —\n * and nearly every implementation writes the value straight into the field\n * as if the person had typed it. Two things go wrong. A plausible, wrong\n * value rides through on the person's own Submit, because nothing marked it\n * as needing a look. And once submitted, the record cannot tell a value the\n * model supplied from one a human typed, which is the one fact an audit later\n * needs.\n *\n * So the suggestion stays pending until it is accepted, and acceptance is\n * reported rather than performed: the component hands the value to `onAccept`\n * and never touches the control. That is also what lets it wrap any control —\n * a select, a date, a number, a combobox — where ghost text can only complete\n * a string. Afterwards the field says it was filled by AI, says if it was\n * edited since, and offers to put back what was there.\n *\n * Deliberately no \"accept all\". A button that takes every suggestion at once\n * is the review deleting itself, and every product that ships one watches its\n * users press it without reading.\n */\n\nexport interface Suggestion<T = string> {\n value: T;\n /** How the value reads — a select's option text, a formatted date. Defaults to the value. */\n label?: string;\n /** Where it came from, in the reader's language: \"from the invoice header\". */\n source?: string;\n /** 0 to 1. Shown as a number, never only as a colour. */\n confidence?: number;\n}\n\nexport type SuggestionStatus = \"pending\" | \"accepted\" | \"dismissed\";\n\nexport interface SuggestedValueProps<T = string> extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"children\" | \"id\" | \"aria-describedby\" | \"aria-invalid\"\n> {\n /** The field, for the buttons' names: \"Accept suggestion — Company\". */\n label: string;\n /** Null or undefined offers nothing. A different suggestion starts pending again. */\n suggestion?: Suggestion<T> | null;\n /**\n * The control's current value. Lets the marker say the fill was edited\n * since, and lets Undo restore what the field held before.\n */\n value?: T;\n /** Supply to own the status; otherwise it is kept here. */\n status?: SuggestionStatus;\n onAccept: (value: T, suggestion: Suggestion<T>) => void;\n onDismiss?: (suggestion: Suggestion<T>) => void;\n /** Called with the value the field held before the fill, so it can be put back. */\n onRevert?: (previous: T | undefined) => void;\n /** How to compare values. Object.is by default. */\n equals?: (a: T, b: T) => boolean;\n /** Confidence below this is called low, in words. */\n lowConfidenceBelow?: number;\n /**\n * Announce a suggestion when it arrives. Off by default: a form that fills\n * twenty fields at once would narrate all twenty, and the description on\n * the control already tells a reader when they reach the field.\n */\n announce?: boolean;\n /** The control. Receives the description, and any id or ARIA a FormControl passes down. */\n children: ReactElement<Record<string, unknown>>;\n /* Passed through to the control, so this can sit inside a FormControl. */\n id?: string;\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: ComponentPropsWithRef<\"input\">[\"aria-invalid\"];\n}\n\nfunction defaultLabel(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"bigint\") return String(value);\n if (typeof value === \"boolean\") return value ? \"Yes\" : \"No\";\n if (value instanceof Date) return value.toLocaleDateString();\n return JSON.stringify(value);\n}\n\nfunction sameSuggestion<T>(\n a: Suggestion<T> | null | undefined,\n b: Suggestion<T> | null | undefined,\n equals: (x: T, y: T) => boolean,\n): boolean {\n if (!a || !b) return a === b;\n return equals(a.value, b.value) && a.label === b.label && a.source === b.source;\n}\n\nexport function SuggestedValue<T = string>({\n className,\n label,\n suggestion,\n value,\n status: controlledStatus,\n onAccept,\n onDismiss,\n onRevert,\n equals = Object.is,\n lowConfidenceBelow = 0.7,\n announce = false,\n children,\n id,\n \"aria-describedby\": describedByProp,\n \"aria-invalid\": ariaInvalid,\n ...props\n}: SuggestedValueProps<T>) {\n const descriptionId = useId();\n\n const [internalStatus, setInternalStatus] = useState<SuggestionStatus>(\"pending\");\n const [previous, setPrevious] = useState<T | undefined>(undefined);\n\n // A new suggestion starts pending, whatever happened to the last one.\n // Compared by content rather than identity, so a parent that rebuilds the\n // object on every keystroke does not reopen a suggestion already accepted.\n const [seen, setSeen] = useState(suggestion);\n if (!sameSuggestion(seen, suggestion, equals)) {\n setSeen(suggestion);\n setInternalStatus(\"pending\");\n }\n\n const status = controlledStatus ?? internalStatus;\n const offered = suggestion ?? null;\n const pending = offered !== null && status === \"pending\";\n const accepted = offered !== null && status === \"accepted\";\n const edited = accepted && value !== undefined && !equals(value, offered.value);\n\n const low = offered?.confidence !== undefined && offered.confidence < lowConfidenceBelow;\n const percent =\n offered?.confidence === undefined\n ? null\n : new Intl.NumberFormat(undefined, { style: \"percent\", maximumFractionDigits: 0 }).format(\n offered.confidence,\n );\n\n const source = offered?.source ? ` ${offered.source}` : \"\";\n\n // What the control's description says. This is how a reader who lands on\n // the field learns there is a suggestion, without any announcement.\n let description: ReactNode = null;\n if (pending) {\n description = (\n <>\n Suggested:{\" \"}\n <strong className=\"font-medium text-foreground\">\n {offered.label ?? defaultLabel(offered.value)}\n </strong>\n {source ? `,${source}` : null}\n {percent !== null ? (\n <span className={cn(low && \"text-warning\")}>\n {low ? `. Low confidence, ${percent} — worth checking` : `. ${percent} confidence`}\n </span>\n ) : null}\n </>\n );\n } else if (accepted) {\n description = edited\n ? `Filled by AI${source ? `,${source}` : \"\"}, then edited`\n : `Filled by AI${source ? `,${source}` : \"\"}`;\n }\n\n // Merged with whatever already describes the control — a FormControl's\n // description and message, or the child's own — rather than replacing it.\n const childDescribedBy = isValidElement(children)\n ? (children.props[\"aria-describedby\"] as string | undefined)\n : undefined;\n const describedBy =\n [childDescribedBy, describedByProp, description !== null ? descriptionId : null]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n const control = isValidElement(children)\n ? cloneElement(children, {\n id: id ?? children.props.id,\n \"aria-describedby\": describedBy,\n \"aria-invalid\": ariaInvalid ?? children.props[\"aria-invalid\"],\n })\n : children;\n\n const accept = () => {\n if (!offered) return;\n setPrevious(value);\n setInternalStatus(\"accepted\");\n onAccept(offered.value, offered);\n };\n\n return (\n <div\n data-slot=\"suggested-value\"\n data-status={offered ? status : undefined}\n data-filled-by={accepted ? \"ai\" : undefined}\n data-edited={edited || undefined}\n className={cn(\"flex flex-col gap-1.5\", className)}\n {...props}\n >\n {control}\n\n {/* Present from the start and never display:none, so that with `announce`\n a suggestion arriving after mount is heard — a region that enters the\n accessibility tree at the same moment as its content announces\n nothing. Empty, it has no height. */}\n <div\n data-slot=\"suggested-value-row\"\n aria-live={announce ? \"polite\" : undefined}\n className={cn(\n \"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs\",\n pending && \"rounded-md border border-primary/40 bg-primary/5 px-2.5 py-1.5\",\n )}\n >\n {description !== null ? (\n <p\n id={descriptionId}\n data-slot=\"suggested-value-description\"\n className=\"m-0 flex-1 text-muted-foreground\"\n >\n {description}\n </p>\n ) : null}\n\n {pending ? (\n <span className=\"flex items-center gap-2\">\n <RowButton\n variant=\"primary\"\n aria-label={`Accept suggestion — ${label}`}\n onClick={accept}\n >\n Accept\n </RowButton>\n <RowButton\n aria-label={`Dismiss suggestion — ${label}`}\n onClick={() => {\n setInternalStatus(\"dismissed\");\n onDismiss?.(offered);\n }}\n >\n Dismiss\n </RowButton>\n </span>\n ) : null}\n\n {accepted && onRevert ? (\n <RowButton\n aria-label={`Undo — ${label}`}\n onClick={() => {\n setInternalStatus(\"pending\");\n onRevert(previous);\n }}\n >\n Undo\n </RowButton>\n ) : null}\n </div>\n </div>\n );\n}\n\nfunction RowButton({\n className,\n variant = \"default\",\n ...props\n}: ComponentPropsWithRef<\"button\"> & { variant?: \"default\" | \"primary\" }) {\n return (\n <button\n type=\"button\"\n className={cn(\n \"rounded-md border px-2 py-0.5 text-xs font-medium transition-colors\",\n variant === \"primary\"\n ? \"border-primary bg-primary text-primary-foreground hover:bg-primary-hover\"\n : \"border-input bg-background hover:bg-accent hover:text-accent-foreground\",\n focusRing,\n disabledStyles,\n className,\n )}\n {...props}\n />\n );\n}\n"],"mappings":";;;;;;AAyFA,SAAS,aAAa,OAAwB;CAC5C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU,OAAO,OAAO,KAAK;CAC/E,IAAI,OAAO,UAAU,WAAW,OAAO,QAAQ,QAAQ;CACvD,IAAI,i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;MACR,cAAY,uBAAuB;MACnC,SAAS;MACV,UAAA;KAEU,CAAA,GACX,oBAAC,WAAD;MACE,cAAY,wBAAwB;MACpC,eAAe;OACb,kBAAkB,WAAW;OAC7B,YAAY,OAAO;MACrB;MACD,UAAA;KAEU,CAAA,CACP;IACJ,CAAA,IAAA;IAEH,YAAY,WACX,oBAAC,WAAD;KACE,cAAY,UAAU;KACtB,eAAe;MACb,kBAAkB,SAAS;MAC3B,SAAS,QAAQ;KACnB;KACD,UAAA;IAEU,CAAA,IACT;GACD;EACF,CAAA,CAAA;;AAET;AAEA,SAAS,UAAU,EACjB,WACA,UAAU,WACV,GAAG,SACqE;CACxE,OACE,oBAAC,UAAD;EACE,MAAK;EACL,WAAW,GACT,uEACA,YAAY,YACR,6EACA,2EACJ,WACA,gBACA,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
@@ -0,0 +1,2 @@
1
+ import { SuggestedValue, SuggestedValueProps, Suggestion, SuggestionStatus } from "./ai-suggested-value.js";
2
+ export { SuggestedValue, type SuggestedValueProps, type Suggestion, type SuggestionStatus };
@@ -0,0 +1,2 @@
1
+ import { SuggestedValue } from "./ai-suggested-value.js";
2
+ export { SuggestedValue };
@@ -0,0 +1,17 @@
1
+ import { defineMeta } from "../../registry/schema.js";
2
+ //#region src/components/ai-suggested-value/meta.ts
3
+ const meta = defineMeta({
4
+ name: "ai-suggested-value",
5
+ title: "AI Suggested Value",
6
+ description: "An AI-proposed value for any form control, pending until accepted and marked afterwards.",
7
+ category: "ai",
8
+ status: "stable",
9
+ dependencies: [],
10
+ registryDependencies: [],
11
+ files: ["ai-suggested-value.tsx"],
12
+ a11y: "The suggestion is the control's description, so a reader who lands on the field hears it without any announcement — and announcing is opt-in, because a form filling twenty fields at once would narrate all twenty. The row that holds it is rendered from the start and never display:none, so when announcing is on, a suggestion arriving after mount is actually heard. Each button's name carries the field it belongs to, so a page of Accepts is a page of different buttons. Provenance and confidence are words with a number, never a colour. Acceptance is reported, not performed: the control is the consumer's, so its value, its label and its own keyboard behaviour are untouched — there is no shortcut hijacked from a select or a date field. The id and ARIA a FormControl passes down are forwarded to the control, and an existing aria-describedby is merged rather than replaced."
13
+ });
14
+ //#endregion
15
+ export { meta };
16
+
17
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","names":[],"sources":["../../../src/components/ai-suggested-value/meta.ts"],"sourcesContent":["import { defineMeta } from \"@/registry/schema\";\n\nexport const meta = defineMeta({\n name: \"ai-suggested-value\",\n title: \"AI Suggested Value\",\n description:\n \"An AI-proposed value for any form control, pending until accepted and marked afterwards.\",\n category: \"ai\",\n status: \"stable\",\n dependencies: [],\n registryDependencies: [],\n files: [\"ai-suggested-value.tsx\"],\n a11y:\n \"The suggestion is the control's description, so a reader who lands on the field hears it \" +\n \"without any announcement — and announcing is opt-in, because a form filling twenty fields at \" +\n \"once would narrate all twenty. The row that holds it is rendered from the start and never \" +\n \"display:none, so when announcing is on, a suggestion arriving after mount is actually heard. \" +\n \"Each button's name carries the field it belongs to, so a page of Accepts is a page of \" +\n \"different buttons. Provenance and confidence are words with a number, never a colour. \" +\n \"Acceptance is reported, not performed: the control is the consumer's, so its value, its \" +\n \"label and its own keyboard behaviour are untouched — there is no shortcut hijacked from a \" +\n \"select or a date field. The id and ARIA a FormControl passes down are forwarded to the \" +\n \"control, and an existing aria-describedby is merged rather than replaced.\",\n});\n"],"mappings":";;AAEA,MAAa,OAAO,WAAW;CAC7B,MAAM;CACN,OAAO;CACP,aACE;CACF,UAAU;CACV,QAAQ;CACR,cAAc,CAAC;CACf,sBAAsB,CAAC;CACvB,OAAO,CAAC,wBAAwB;CAChC,MACE;AAUJ,CAAC"}
@@ -2,7 +2,7 @@ import { VariantProps } from "class-variance-authority";
2
2
  import { ComponentPropsWithRef } from "react";
3
3
  //#region src/components/alert/alert.d.ts
4
4
  declare const alertVariants: (props?: ({
5
- variant?: "default" | "destructive" | "success" | "warning" | "info" | null | undefined;
5
+ variant?: "success" | "warning" | "destructive" | "default" | "info" | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  /**
8
8
  * How urgently the alert should interrupt a screen reader.
@@ -3,7 +3,7 @@ import { VariantProps } from "class-variance-authority";
3
3
  import { ComponentPropsWithRef } from "react";
4
4
  //#region src/components/avatar/avatar.d.ts
5
5
  declare const avatarVariants: (props?: ({
6
- size?: "sm" | "md" | "lg" | "xs" | "xl" | null | undefined;
6
+ size?: "xs" | "sm" | "md" | "lg" | "xl" | null | undefined;
7
7
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
8
  interface AvatarProps extends ComponentPropsWithRef<typeof Avatar.Root>, VariantProps<typeof avatarVariants> {}
9
9
  /** Image representation of a user or entity, with a text fallback. */
@@ -2,7 +2,7 @@ import { VariantProps } from "class-variance-authority";
2
2
  import { ComponentPropsWithRef } from "react";
3
3
  //#region src/components/badge/badge.d.ts
4
4
  declare const badgeVariants: (props?: ({
5
- variant?: "default" | "secondary" | "outline" | "destructive" | "success" | "warning" | "info" | null | undefined;
5
+ variant?: "success" | "warning" | "destructive" | "default" | "secondary" | "outline" | "info" | null | undefined;
6
6
  size?: "sm" | "md" | null | undefined;
7
7
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
8
  interface BadgeProps extends ComponentPropsWithRef<"span">, VariantProps<typeof badgeVariants> {
@@ -2,7 +2,7 @@ import { VariantProps } from "class-variance-authority";
2
2
  import { ComponentPropsWithRef } from "react";
3
3
  //#region src/components/button/button.d.ts
4
4
  declare const buttonVariants: (props?: ({
5
- variant?: "link" | "secondary" | "outline" | "destructive" | "primary" | "ghost" | null | undefined;
5
+ variant?: "link" | "primary" | "destructive" | "secondary" | "outline" | "ghost" | null | undefined;
6
6
  size?: "sm" | "md" | "lg" | "icon" | "icon-sm" | null | undefined;
7
7
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
8
  interface ButtonProps extends ComponentPropsWithRef<"button">, VariantProps<typeof buttonVariants> {