@dowel-ui/react 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist/components/ai-agent-plan/ai-agent-plan.d.ts +50 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.d.ts.map +1 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.js +156 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.js.map +1 -0
- package/dist/components/ai-agent-plan/index.d.ts +2 -0
- package/dist/components/ai-agent-plan/index.js +2 -0
- package/dist/components/ai-agent-plan/meta.js +17 -0
- package/dist/components/ai-agent-plan/meta.js.map +1 -0
- package/dist/components/ai-agent-status/ai-agent-status.d.ts +1 -1
- package/dist/components/ai-approval-request/ai-approval-request.d.ts +67 -0
- package/dist/components/ai-approval-request/ai-approval-request.d.ts.map +1 -0
- package/dist/components/ai-approval-request/ai-approval-request.js +218 -0
- package/dist/components/ai-approval-request/ai-approval-request.js.map +1 -0
- package/dist/components/ai-approval-request/index.d.ts +2 -0
- package/dist/components/ai-approval-request/index.js +2 -0
- package/dist/components/ai-approval-request/meta.js +17 -0
- package/dist/components/ai-approval-request/meta.js.map +1 -0
- package/dist/components/ai-response/ai-response.d.ts.map +1 -1
- package/dist/components/ai-response/ai-response.js +1 -0
- package/dist/components/ai-response/ai-response.js.map +1 -1
- package/dist/components/ai-structured-output/ai-structured-output.d.ts.map +1 -1
- package/dist/components/ai-structured-output/ai-structured-output.js +13 -2
- package/dist/components/ai-structured-output/ai-structured-output.js.map +1 -1
- package/dist/components/ai-tool/ai-tool.d.ts +1 -1
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/button/button.d.ts +1 -1
- package/dist/components/file-upload/file-upload.d.ts +46 -0
- package/dist/components/file-upload/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload/file-upload.js +204 -0
- package/dist/components/file-upload/file-upload.js.map +1 -0
- package/dist/components/file-upload/index.d.ts +3 -0
- package/dist/components/file-upload/index.js +3 -0
- package/dist/components/file-upload/meta.js +17 -0
- package/dist/components/file-upload/meta.js.map +1 -0
- package/dist/components/file-upload/upload-queue.d.ts +87 -0
- package/dist/components/file-upload/upload-queue.d.ts.map +1 -0
- package/dist/components/file-upload/upload-queue.js +249 -0
- package/dist/components/file-upload/upload-queue.js.map +1 -0
- package/dist/components/progress/progress.d.ts +1 -1
- package/dist/components/progress/progress.js +1 -0
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/spinner/spinner.js +1 -0
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/tags-input/index.d.ts +2 -0
- package/dist/components/tags-input/index.js +2 -0
- package/dist/components/tags-input/meta.js +17 -0
- package/dist/components/tags-input/meta.js.map +1 -0
- package/dist/components/tags-input/tags-input.d.ts +47 -0
- package/dist/components/tags-input/tags-input.d.ts.map +1 -0
- package/dist/components/tags-input/tags-input.js +182 -0
- package/dist/components/tags-input/tags-input.js.map +1 -0
- package/dist/components/toast/toast.d.ts +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +6 -1
- package/dist/registry/components.d.ts.map +1 -1
- package/dist/registry/components.js +58 -50
- package/dist/registry/components.js.map +1 -1
- package/package.json +4 -4
- package/src/components/ai-agent-plan/ai-agent-plan.tsx +0 -0
- package/src/components/ai-agent-plan/index.ts +10 -0
- package/src/components/ai-agent-plan/meta.ts +19 -0
- package/src/components/ai-approval-request/ai-approval-request.tsx +368 -0
- package/src/components/ai-approval-request/index.ts +7 -0
- package/src/components/ai-approval-request/meta.ts +21 -0
- package/src/components/ai-response/ai-response.tsx +1 -0
- package/src/components/ai-structured-output/ai-structured-output.tsx +25 -1
- package/src/components/file-upload/file-upload.tsx +322 -0
- package/src/components/file-upload/index.ts +20 -0
- package/src/components/file-upload/meta.ts +21 -0
- package/src/components/file-upload/upload-queue.ts +337 -0
- package/src/components/progress/progress.tsx +3 -0
- package/src/components/spinner/spinner.tsx +5 -0
- package/src/components/tags-input/index.ts +1 -0
- package/src/components/tags-input/meta.ts +23 -0
- package/src/components/tags-input/tags-input.tsx +300 -0
- package/src/index.ts +4 -0
- package/src/registry/components.ts +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-approval-request.js","names":[],"sources":["../../../src/components/ai-approval-request/ai-approval-request.tsx"],"sourcesContent":["\"use client\";\n\nimport { useId, useMemo, useState, type ComponentPropsWithRef, type ReactNode } from \"react\";\n\nimport { disabledStyles, focusRing } from \"@/lib/styles\";\nimport { cn } from \"@/lib/utils\";\n\n/**\n * The gate between an agent deciding to act and it acting.\n *\n * Two things separate this from the confirmations that already exist.\n *\n * The first is that the proposed arguments are editable. Every implementation\n * surveyed returns a boolean over a read-only payload, which forces a false\n * choice: approve a call whose recipient is wrong, or deny it and make the\n * model try again. \"Approve this, but fix the address first\" is the answer\n * people actually want, and it is only possible if the arguments are fields.\n * Edited values come back in the decision, and are marked as changed so an\n * audit trail can tell the model's proposal from the human's correction.\n *\n * The second is that it renders while the arguments are still arriving. The\n * common implementation returns null until the tool input is complete, which\n * means nothing is on screen at the moment approval becomes relevant and the\n * request appears abruptly, fully formed. Here the request is visible as it\n * forms, with the decision held until there is something whole to decide on.\n */\n\nexport type ApprovalScope = \"once\" | \"always\";\n\nexport type ApprovalDecision =\n | {\n approved: true;\n scope: ApprovalScope;\n arguments: Record<string, string>;\n edited: string[];\n }\n | { approved: false; reason?: string };\n\nexport interface ApprovalField {\n name: string;\n label: string;\n /** A textarea instead of a single line. For message bodies and prompts. */\n multiline?: boolean;\n /** Locked arguments are shown but not editable — an id, a resolved amount. */\n readOnly?: boolean;\n}\n\nexport interface ApprovalRequestProps extends Omit<\n ComponentPropsWithRef<\"section\">,\n \"onSubmit\" | \"children\"\n> {\n /** The tool the model wants to call, as it named it. */\n tool: string;\n /** What the call will do, in the reader's language rather than the API's. */\n summary: string;\n /** Proposed arguments. Missing keys are treated as still arriving. */\n arguments: Record<string, string>;\n /** Which arguments to show, in order, and which may be changed. */\n fields: ApprovalField[];\n onDecision: (decision: ApprovalDecision) => void;\n /**\n * True while the model is still producing the arguments. The request renders\n * anyway; only the decision waits.\n */\n streaming?: boolean;\n /**\n * Said plainly above the controls when the call cannot be taken back. Not a\n * severity colour — the sentence is the warning.\n */\n irreversible?: string;\n /** Set once decided, to render the outcome instead of the controls. */\n decision?: ApprovalDecision;\n children?: ReactNode;\n}\n\nexport function ApprovalRequest({\n className,\n tool,\n summary,\n arguments: proposed,\n fields,\n onDecision,\n streaming = false,\n irreversible,\n decision,\n children,\n ...props\n}: ApprovalRequestProps) {\n const headingId = useId();\n const [edits, setEdits] = useState<Record<string, string>>({});\n const [denying, setDenying] = useState(false);\n const [reason, setReason] = useState(\"\");\n\n // The model's proposal with the human's corrections applied on top. Keeping\n // them apart is what lets the component say which is which.\n const values = useMemo(() => ({ ...proposed, ...edits }), [proposed, edits]);\n\n const edited = useMemo(\n () => Object.keys(edits).filter((name) => edits[name] !== proposed[name]),\n [edits, proposed],\n );\n\n const missing = fields.filter((field) => proposed[field.name] === undefined);\n const settled = !streaming && missing.length === 0;\n\n if (decision) {\n return (\n <section\n data-slot=\"approval-request\"\n data-state={decision.approved ? \"approved\" : \"denied\"}\n aria-labelledby={headingId}\n className={cn(\n \"rounded-lg border p-4 text-sm\",\n decision.approved ? \"border-border bg-muted/40\" : \"border-border bg-muted/40\",\n className,\n )}\n {...props}\n >\n <h3 id={headingId} className=\"text-sm font-medium\">\n {summary}\n </h3>\n <p data-slot=\"approval-outcome\" className=\"mt-1 text-xs text-muted-foreground\">\n {decision.approved\n ? `Approved ${decision.scope === \"always\" ? \"for every call to this tool\" : \"once\"}` +\n (decision.edited.length > 0\n ? `, with ${String(decision.edited.length)} argument${decision.edited.length === 1 ? \"\" : \"s\"} corrected`\n : \"\")\n : `Denied${decision.reason ? `: ${decision.reason}` : \"\"}`}\n </p>\n </section>\n );\n }\n\n return (\n <section\n data-slot=\"approval-request\"\n data-state={settled ? \"pending\" : \"forming\"}\n aria-labelledby={headingId}\n // Busy while the arguments are still arriving, so a reader is told the\n // request is not yet whole rather than acting on half of it.\n aria-busy={!settled}\n className={cn(\"rounded-lg border border-border bg-card p-4\", 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 {summary}\n </h3>\n <code className=\"rounded bg-muted px-1.5 py-0.5 font-mono text-2xs text-muted-foreground\">\n {tool}\n </code>\n </div>\n\n <dl className=\"mt-3 flex flex-col gap-2.5\">\n {fields.map((field) => {\n const arrived = proposed[field.name] !== undefined;\n const changed = edited.includes(field.name);\n\n return (\n <ApprovalArgument\n key={field.name}\n field={field}\n value={values[field.name] ?? \"\"}\n arrived={arrived}\n changed={changed}\n onChange={(next) => {\n setEdits((current) => ({ ...current, [field.name]: next }));\n }}\n />\n );\n })}\n </dl>\n\n {children}\n\n {irreversible ? (\n <p data-slot=\"approval-warning\" className=\"mt-3 text-xs text-destructive\">\n {irreversible}\n </p>\n ) : null}\n\n {denying ? (\n <div className=\"mt-3 flex flex-col gap-2\">\n <label htmlFor={`${headingId}-reason`} className=\"text-xs text-muted-foreground\">\n Why not? The model sees this.\n </label>\n <textarea\n id={`${headingId}-reason`}\n rows={2}\n value={reason}\n onChange={(event) => {\n setReason(event.target.value);\n }}\n className={cn(\n \"w-full resize-none rounded-md border border-input bg-background px-2 py-1.5 text-sm\",\n focusRing,\n )}\n />\n <div className=\"flex flex-wrap gap-2\">\n <Action\n variant=\"destructive\"\n onClick={() => {\n onDecision({ approved: false, reason: reason.trim() || undefined });\n }}\n >\n Deny\n </Action>\n <Action\n onClick={() => {\n setDenying(false);\n }}\n >\n Back\n </Action>\n </div>\n </div>\n ) : (\n <div className=\"mt-4 flex flex-wrap items-center gap-2\">\n <Action\n variant=\"primary\"\n disabled={!settled}\n onClick={() => {\n onDecision({ approved: true, scope: \"once\", arguments: values, edited });\n }}\n >\n {edited.length > 0 ? \"Approve with changes\" : \"Approve once\"}\n </Action>\n\n {/* Scope is a separate decision from approval, and blanket consent\n should never be the easiest button to reach. */}\n <Action\n disabled={!settled}\n onClick={() => {\n onDecision({ approved: true, scope: \"always\", arguments: values, edited });\n }}\n >\n Always allow {tool}\n </Action>\n\n <Action\n onClick={() => {\n setDenying(true);\n }}\n >\n Deny…\n </Action>\n\n {!settled ? (\n <span aria-live=\"polite\" className=\"text-xs text-muted-foreground\">\n Waiting for the model to finish the request\n </span>\n ) : null}\n </div>\n )}\n </section>\n );\n}\n\nfunction ApprovalArgument({\n field,\n value,\n arrived,\n changed,\n onChange,\n}: {\n field: ApprovalField;\n value: string;\n arrived: boolean;\n changed: boolean;\n onChange: (value: string) => void;\n}) {\n const id = useId();\n const changedId = useId();\n const editable = !field.readOnly && arrived;\n\n return (\n <div\n data-slot=\"approval-argument\"\n data-changed={changed || undefined}\n className=\"flex flex-col gap-1\"\n >\n <dt className=\"flex items-baseline gap-1\">\n <label htmlFor={editable ? id : undefined} className=\"text-xs text-muted-foreground\">\n {field.label}\n </label>\n {/* Outside the label, and attached as a description instead. Inside it,\n editing a field would rename the field — a screen reader user would\n hear its accessible name change under them mid-edit. Marked in text\n rather than by border colour alone, because an audit trail has to\n tell the model's proposal from the human's correction. */}\n {changed ? (\n <span id={changedId} className=\"text-xs text-warning\">\n · changed from the model’s proposal\n </span>\n ) : null}\n </dt>\n <dd className=\"m-0\">\n {!arrived ? (\n <span\n aria-hidden=\"true\"\n className=\"block h-8 w-full animate-pulse-soft rounded-md bg-muted\"\n />\n ) : editable ? (\n field.multiline ? (\n <textarea\n id={id}\n aria-describedby={changed ? changedId : undefined}\n rows={3}\n value={value}\n onChange={(event) => {\n onChange(event.target.value);\n }}\n className={cn(\n \"w-full resize-none rounded-md border border-input bg-background px-2 py-1.5 font-mono text-xs\",\n changed && \"border-warning\",\n focusRing,\n )}\n />\n ) : (\n <input\n id={id}\n type=\"text\"\n aria-describedby={changed ? changedId : undefined}\n value={value}\n onChange={(event) => {\n onChange(event.target.value);\n }}\n className={cn(\n \"w-full rounded-md border border-input bg-background px-2 py-1.5 font-mono text-xs\",\n changed && \"border-warning\",\n focusRing,\n )}\n />\n )\n ) : (\n <p className=\"rounded-md bg-muted px-2 py-1.5 font-mono text-xs break-words\">\n {value}\n </p>\n )}\n </dd>\n </div>\n );\n}\n\nfunction Action({\n className,\n variant = \"default\",\n ...props\n}: ComponentPropsWithRef<\"button\"> & { variant?: \"default\" | \"primary\" | \"destructive\" }) {\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\",\n variant === \"destructive\" &&\n \"border-destructive bg-destructive text-destructive-foreground hover:bg-destructive/90\",\n variant === \"default\" &&\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":";;;;;;AA2EA,SAAgB,gBAAgB,EAC9B,WACA,MACA,SACA,WAAW,UACX,QACA,YACA,YAAY,OACZ,cACA,UACA,UACA,GAAG,SACoB;CACvB,MAAM,YAAY,MAAM;CACxB,MAAM,CAAC,OAAO,YAAY,SAAiC,CAAC,CAAC;CAC7D,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CAIvC,MAAM,SAAS,eAAe;EAAE,GAAG;EAAU,GAAG;CAAM,IAAI,CAAC,UAAU,KAAK,CAAC;CAE3E,MAAM,SAAS,cACP,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,SAAS,MAAM,UAAU,SAAS,KAAK,GACxE,CAAC,OAAO,QAAQ,CAClB;CAEA,MAAM,UAAU,OAAO,QAAQ,UAAU,SAAS,MAAM,UAAU,KAAA,CAAS;CAC3E,MAAM,UAAU,CAAC,aAAa,QAAQ,WAAW;CAEjD,IAAI,UACF,OACE,qBAAC,WAA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,MAAM,YAAY;CAEpC,OACE,qBAAC,OAAD;EACE,aAAU;EACV,gBAAc,WAAW,KAAA;EACzB,WAAU;EAHZ,UAAA,CAKE,qBAAC,MAAD;GAAI,WAAU;GAAd,UAAA,CACE,oBAAC,SAAD;IAAO,SAAS,WAAW,KAAK,KAAA;IAAW,WAAU;IAClD,UAAA,MAAM;GACF,CAAA,GAMN,UACC,oBAAC,QAAD;IAAM,IAAI;IAAW,WAAU;IAAuB,UAAA;GAEhD,CAAA,IACJ,IACF;EACJ,CAAA,GAAA,oBAAC,MAAD;GAAI,WAAU;GACX,UAAA,CAAC,UACA,oBAAC,QAAD;IACE,eAAY;IACZ,WAAU;GACX,CAAA,IACC,WACF,MAAM,YACJ,oBAAC,YAAD;IACM;IACJ,oBAAkB,UAAU,YAAY,KAAA;IACxC,MAAM;IACC;IACP,WAAW,UAAU;KACnB,SAAS,MAAM,OAAO,KAAK;IAC7B;IACA,WAAW,GACT,iGACA,WAAW,kBACX,SACF;GACD,CAAA,IAED,oBAAC,SAAD;IACM;IACJ,MAAK;IACL,oBAAkB,UAAU,YAAY,KAAA;IACjC;IACP,WAAW,UAAU;KACnB,SAAS,MAAM,OAAO,KAAK;IAC7B;IACA,WAAW,GACT,qFACA,WAAW,kBACX,SACF;GACD,CAAA,IAGH,oBAAC,KAAD;IAAG,WAAU;IACV,UAAA;GACA,CAAA;EAEH,CAAA,CACD;;AAET;AAEA,SAAS,OAAO,EACd,WACA,UAAU,WACV,GAAG,SACqF;CACxF,OACE,oBAAC,UAAD;EACE,MAAK;EACL,WAAW,GACT,uEACA,YAAY,aACV,4EACF,YAAY,iBACV,yFACF,YAAY,aACV,2EACF,WACA,gBACA,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineMeta } from "../../registry/schema.js";
|
|
2
|
+
//#region src/components/ai-approval-request/meta.ts
|
|
3
|
+
const meta = defineMeta({
|
|
4
|
+
name: "ai-approval-request",
|
|
5
|
+
title: "AI Approval Request",
|
|
6
|
+
description: "Approve a tool call — after correcting the arguments the model got wrong.",
|
|
7
|
+
category: "ai",
|
|
8
|
+
status: "stable",
|
|
9
|
+
dependencies: [],
|
|
10
|
+
registryDependencies: [],
|
|
11
|
+
files: ["ai-approval-request.tsx"],
|
|
12
|
+
a11y: "The proposed arguments are a description list of real labelled form controls, so each value is associated with its name and editable ones are reachable by keyboard. A corrected argument is marked in text rather than by border colour alone, because an audit trail has to distinguish the model's proposal from the human's edit. The request is aria-busy while arguments are still arriving and the decision controls stay disabled until it is whole — rendering nothing until then, as the common implementation does, means nothing is on screen at the moment approval becomes relevant. Irreversibility is stated as a sentence, never as a severity colour."
|
|
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-approval-request/meta.ts"],"sourcesContent":["import { defineMeta } from \"@/registry/schema\";\n\nexport const meta = defineMeta({\n name: \"ai-approval-request\",\n title: \"AI Approval Request\",\n description: \"Approve a tool call — after correcting the arguments the model got wrong.\",\n category: \"ai\",\n status: \"stable\",\n dependencies: [],\n registryDependencies: [],\n files: [\"ai-approval-request.tsx\"],\n a11y:\n \"The proposed arguments are a description list of real labelled form controls, so each value \" +\n \"is associated with its name and editable ones are reachable by keyboard. A corrected \" +\n \"argument is marked in text rather than by border colour alone, because an audit trail has \" +\n \"to distinguish the model's proposal from the human's edit. The request is aria-busy while \" +\n \"arguments are still arriving and the decision controls stay disabled until it is whole — \" +\n \"rendering nothing until then, as the common implementation does, means nothing is on screen \" +\n \"at the moment approval becomes relevant. Irreversibility is stated as a sentence, never as a \" +\n \"severity colour.\",\n});\n"],"mappings":";;AAEA,MAAa,OAAO,WAAW;CAC7B,MAAM;CACN,OAAO;CACP,aAAa;CACb,UAAU;CACV,QAAQ;CACR,cAAc,CAAC;CACf,sBAAsB,CAAC;CACvB,OAAO,CAAC,yBAAyB;CACjC,MACE;AAQJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-response.d.ts","names":[],"sources":["../../../src/components/ai-response/ai-response.tsx"],"mappings":";;;;;;;;;;;;;;UAkBiB,sBAAsB;;EAErC;;iBAGc,WAAW,WAAW,WAAW,aAAa,SAAS,gCAAa,IAAA;;;iBAwBpE,gBAAgB,cAAc,SAAS,gDAA6B,IAAA;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ai-response.d.ts","names":[],"sources":["../../../src/components/ai-response/ai-response.tsx"],"mappings":";;;;;;;;;;;;;;UAkBiB,sBAAsB;;EAErC;;iBAGc,WAAW,WAAW,WAAW,aAAa,SAAS,gCAAa,IAAA;;;iBAwBpE,gBAAgB,cAAc,SAAS,gDAA6B,IAAA;;;;;;;;UAsBnE,+BAA+B;EAC9C;;iBAGc,oBACd,WACA,UACG,SACF,yCAAsB,IAAA"}
|
|
@@ -17,6 +17,7 @@ function ResponseCaret({ className, ...props }) {
|
|
|
17
17
|
return /* @__PURE__ */ jsx("span", {
|
|
18
18
|
"data-slot": "response-caret",
|
|
19
19
|
"aria-hidden": "true",
|
|
20
|
+
"data-motion": "indicator",
|
|
20
21
|
className: cn("ml-0.5 inline-block h-[1em] w-[2px] translate-y-[0.15em] animate-caret bg-current align-baseline", className),
|
|
21
22
|
...props
|
|
22
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-response.js","names":[],"sources":["../../../src/components/ai-response/ai-response.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentPropsWithRef } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/**\n * The text of an assistant response.\n *\n * Renders plain text with paragraph whitespace preserved. Markdown is\n * deliberately not parsed here: a Markdown renderer is a dependency, a security\n * decision about raw HTML, and a styling surface all at once, and every product\n * makes those differently. Pass already-rendered content as children when you\n * need it — the prose styling below applies either way.\n *\n * Not a live region, and not by omission. See the note on `Conversation`:\n * announcing streamed text token by token is unusable with a screen reader.\n */\nexport interface ResponseProps extends ComponentPropsWithRef<\"div\"> {\n /** Shows the caret. Purely visual — it carries no announcement. */\n streaming?: boolean;\n}\n\nexport function Response({ className, streaming, children, ...props }: ResponseProps) {\n return (\n <div\n data-slot=\"response\"\n data-streaming={streaming || undefined}\n className={cn(\n \"text-sm leading-relaxed whitespace-pre-wrap text-foreground\",\n // Minimal prose styling for consumers who pass rendered Markdown.\n \"[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-4\",\n \"[&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.9em]\",\n \"[&_ol]:my-2 [&_ol]:list-decimal [&_ol]:pl-5 [&_ul]:my-2 [&_ul]:list-disc [&_ul]:pl-5\",\n \"[&_p+p]:mt-3\",\n className,\n )}\n {...props}\n >\n {children}\n {streaming ? <ResponseCaret /> : null}\n </div>\n );\n}\n\n/** The trailing cursor. Decorative — the streaming state is announced, if at\n * all, through ConversationStatus. */\nexport function ResponseCaret({ className, ...props }: ComponentPropsWithRef<\"span\">) {\n return (\n <span\n data-slot=\"response-caret\"\n aria-hidden=\"true\"\n className={cn(\n \"ml-0.5 inline-block h-[1em] w-[2px] translate-y-[0.15em] animate-caret bg-current align-baseline\",\n className,\n )}\n {...props}\n />\n );\n}\n\n/**\n * Shown while waiting for the first token.\n *\n * A distinct state from streaming: nothing has arrived yet, so there is no text\n * to show a caret after. Labelled for assistive technology because, unlike the\n * caret, this is the only thing on screen.\n */\nexport interface ThinkingIndicatorProps extends ComponentPropsWithRef<\"div\"> {\n label?: string;\n}\n\nexport function ThinkingIndicator({\n className,\n label = \"Thinking\",\n ...props\n}: ThinkingIndicatorProps) {\n return (\n <div\n data-slot=\"thinking-indicator\"\n className={cn(\"flex items-center gap-1.5 text-sm text-muted-foreground\", className)}\n {...props}\n >\n <span className=\"sr-only\">{label}</span>\n {[0, 1, 2].map((index) => (\n <span\n key={index}\n aria-hidden=\"true\"\n className=\"size-1.5 animate-pulse-soft rounded-full bg-current\"\n style={{ animationDelay: `${String(index * 160)}ms` }}\n />\n ))}\n </div>\n );\n}\n"],"mappings":";;;;AAuBA,SAAgB,SAAS,EAAE,WAAW,WAAW,UAAU,GAAG,SAAwB;CACpF,OACE,qBAAC,OAAD;EACE,aAAU;EACV,kBAAgB,aAAa,KAAA;EAC7B,WAAW,GACT,+DAEA,+DACA,6GACA,wFACA,gBACA,SACF;EACA,GAAI;EAZN,UAAA,CAcG,UACA,YAAY,oBAAC,eAAD,CAAgB,CAAA,IAAI,IAC9B;;AAET;;;AAIA,SAAgB,cAAc,EAAE,WAAW,GAAG,SAAwC;CACpF,OACE,oBAAC,QAAD;EACE,aAAU;EACV,eAAY;EACZ,WAAW,GACT,oGACA,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAaA,SAAgB,kBAAkB,EAChC,WACA,QAAQ,YACR,GAAG,SACsB;CACzB,OACE,qBAAC,OAAD;EACE,aAAU;EACV,WAAW,GAAG,2DAA2D,SAAS;EAClF,GAAI;EAHN,UAAA,CAKE,oBAAC,QAAD;GAAM,WAAU;GAAW,UAAA;EAAY,CAAA,GACtC;GAAC;GAAG;GAAG;EAAC,CAAC,CAAC,KAAK,UACd,oBAAC,QAAD;GAEE,eAAY;GACZ,WAAU;GACV,OAAO,EAAE,gBAAgB,GAAG,OAAO,QAAQ,GAAG,EAAE,IAAI;EACrD,GAJM,KAIN,CACF,CACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"ai-response.js","names":[],"sources":["../../../src/components/ai-response/ai-response.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentPropsWithRef } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/**\n * The text of an assistant response.\n *\n * Renders plain text with paragraph whitespace preserved. Markdown is\n * deliberately not parsed here: a Markdown renderer is a dependency, a security\n * decision about raw HTML, and a styling surface all at once, and every product\n * makes those differently. Pass already-rendered content as children when you\n * need it — the prose styling below applies either way.\n *\n * Not a live region, and not by omission. See the note on `Conversation`:\n * announcing streamed text token by token is unusable with a screen reader.\n */\nexport interface ResponseProps extends ComponentPropsWithRef<\"div\"> {\n /** Shows the caret. Purely visual — it carries no announcement. */\n streaming?: boolean;\n}\n\nexport function Response({ className, streaming, children, ...props }: ResponseProps) {\n return (\n <div\n data-slot=\"response\"\n data-streaming={streaming || undefined}\n className={cn(\n \"text-sm leading-relaxed whitespace-pre-wrap text-foreground\",\n // Minimal prose styling for consumers who pass rendered Markdown.\n \"[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-4\",\n \"[&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.9em]\",\n \"[&_ol]:my-2 [&_ol]:list-decimal [&_ol]:pl-5 [&_ul]:my-2 [&_ul]:list-disc [&_ul]:pl-5\",\n \"[&_p+p]:mt-3\",\n className,\n )}\n {...props}\n >\n {children}\n {streaming ? <ResponseCaret /> : null}\n </div>\n );\n}\n\n/** The trailing cursor. Decorative — the streaming state is announced, if at\n * all, through ConversationStatus. */\nexport function ResponseCaret({ className, ...props }: ComponentPropsWithRef<\"span\">) {\n return (\n <span\n data-slot=\"response-caret\"\n aria-hidden=\"true\"\n data-motion=\"indicator\"\n className={cn(\n \"ml-0.5 inline-block h-[1em] w-[2px] translate-y-[0.15em] animate-caret bg-current align-baseline\",\n className,\n )}\n {...props}\n />\n );\n}\n\n/**\n * Shown while waiting for the first token.\n *\n * A distinct state from streaming: nothing has arrived yet, so there is no text\n * to show a caret after. Labelled for assistive technology because, unlike the\n * caret, this is the only thing on screen.\n */\nexport interface ThinkingIndicatorProps extends ComponentPropsWithRef<\"div\"> {\n label?: string;\n}\n\nexport function ThinkingIndicator({\n className,\n label = \"Thinking\",\n ...props\n}: ThinkingIndicatorProps) {\n return (\n <div\n data-slot=\"thinking-indicator\"\n className={cn(\"flex items-center gap-1.5 text-sm text-muted-foreground\", className)}\n {...props}\n >\n <span className=\"sr-only\">{label}</span>\n {[0, 1, 2].map((index) => (\n <span\n key={index}\n aria-hidden=\"true\"\n className=\"size-1.5 animate-pulse-soft rounded-full bg-current\"\n style={{ animationDelay: `${String(index * 160)}ms` }}\n />\n ))}\n </div>\n );\n}\n"],"mappings":";;;;AAuBA,SAAgB,SAAS,EAAE,WAAW,WAAW,UAAU,GAAG,SAAwB;CACpF,OACE,qBAAC,OAAD;EACE,aAAU;EACV,kBAAgB,aAAa,KAAA;EAC7B,WAAW,GACT,+DAEA,+DACA,6GACA,wFACA,gBACA,SACF;EACA,GAAI;EAZN,UAAA,CAcG,UACA,YAAY,oBAAC,eAAD,CAAgB,CAAA,IAAI,IAC9B;;AAET;;;AAIA,SAAgB,cAAc,EAAE,WAAW,GAAG,SAAwC;CACpF,OACE,oBAAC,QAAD;EACE,aAAU;EACV,eAAY;EACZ,eAAY;EACZ,WAAW,GACT,oGACA,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAaA,SAAgB,kBAAkB,EAChC,WACA,QAAQ,YACR,GAAG,SACsB;CACzB,OACE,qBAAC,OAAD;EACE,aAAU;EACV,WAAW,GAAG,2DAA2D,SAAS;EAClF,GAAI;EAHN,UAAA,CAKE,oBAAC,QAAD;GAAM,WAAU;GAAW,UAAA;EAAY,CAAA,GACtC;GAAC;GAAG;GAAG;EAAC,CAAC,CAAC,KAAK,UACd,oBAAC,QAAD;GAEE,eAAY;GACZ,WAAU;GACV,OAAO,EAAE,gBAAgB,GAAG,OAAO,QAAQ,GAAG,EAAE,IAAI;EACrD,GAJM,KAIN,CACF,CACE;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-structured-output.d.ts","names":[],"sources":["../../../src/components/ai-structured-output/ai-structured-output.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ai-structured-output.d.ts","names":[],"sources":["../../../src/components/ai-structured-output/ai-structured-output.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;KAgCY;UAEK;;EAEf;EACA;;EAEA;;UA6Be,8BAA8B,KAAK;;EAElD,QAAQ;;EAER,OAAO;;;;;EAKP;;;;;EAKA;;EAEA,SAAS;EACT,eAAe,gBAAgB;EAC/B,WAAW;;iBAGG,mBACd,WACA,QACA,OACA,WACA,SACA,QACA,aACA,aACG,SACF,wCAAqB,IAAA;UAiDP,6BAA6B,KAAK;EACjD;EACA,WAAW;;;;;;;;iBASG,kBAAkB,WAAW,MAAM,aAAa,SAAS,uCAAoB,IAAA;;;;;;;iBA2E7E,uBACd,WACA,OAAO,YACP,aACG,SACF;EAA+B;EAAe;oBAAmB,IAAA;;iBAoBpD,uBAAuB,cAAc,SAAS,6CAA0B,IAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../../lib/utils.js";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
5
5
|
//#region src/components/ai-structured-output/ai-structured-output.tsx
|
|
6
6
|
const StructuredOutputContext = createContext(null);
|
|
7
7
|
function useStructuredOutputContext(component) {
|
|
@@ -72,9 +72,16 @@ function StructuredField({ className, name, children, ...props }) {
|
|
|
72
72
|
if (!field) throw new Error(`StructuredField "${name}" is not declared in the fields prop.`);
|
|
73
73
|
const state = stateOf(name);
|
|
74
74
|
const raw = value[name];
|
|
75
|
+
const [seenState, setSeenState] = useState(state);
|
|
76
|
+
const [hasSettled, setHasSettled] = useState(false);
|
|
77
|
+
if (seenState !== state) {
|
|
78
|
+
setSeenState(state);
|
|
79
|
+
if (state === "settled" && seenState !== "settled") setHasSettled(true);
|
|
80
|
+
}
|
|
75
81
|
return /* @__PURE__ */ jsxs("div", {
|
|
76
82
|
"data-slot": "structured-field",
|
|
77
83
|
"data-state": state,
|
|
84
|
+
"data-settled": hasSettled || void 0,
|
|
78
85
|
"data-field": name,
|
|
79
86
|
className: cn("flex flex-col gap-1", className),
|
|
80
87
|
...props,
|
|
@@ -88,7 +95,11 @@ function StructuredField({ className, name, children, ...props }) {
|
|
|
88
95
|
"data-slot": "structured-field-placeholder",
|
|
89
96
|
"aria-hidden": "true",
|
|
90
97
|
className: "block h-4 w-24 animate-pulse-soft rounded bg-muted"
|
|
91
|
-
}) :
|
|
98
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
99
|
+
"data-slot": "structured-field-value",
|
|
100
|
+
className: cn(hasSettled && "inline-block animate-settle"),
|
|
101
|
+
children: children ?? formatValue(raw, name)
|
|
102
|
+
})
|
|
92
103
|
})]
|
|
93
104
|
});
|
|
94
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-structured-output.js","names":[],"sources":["../../../src/components/ai-structured-output/ai-structured-output.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useMemo,\n type ComponentPropsWithRef,\n type ReactNode,\n} from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/**\n * An object arriving field by field from the model.\n *\n * Most AI features inside real software are not chatbots. They are invoice\n * extraction, CRM enrichment, resume parsing, form autofill — a schema goes in\n * and a filled object comes back. Every one of them streams a partial object\n * into a layout, and almost every one reflows on each token because the fields\n * appear as they arrive.\n *\n * The honest limitation, stated here rather than discovered later: there is no\n * per-field completion signal anywhere in the stack. A streaming API hands you\n * successive partial snapshots, and a string that has stopped growing is\n * indistinguishable from one still arriving. So this component does not pretend\n * to know. It takes the field list up front, reserves the layout from it, and\n * lets the caller say which fields are settled — defaulting to the rule that a\n * field is settled once a later field has appeared, which is true of\n * depth-first JSON streaming and is documented rather than assumed silently.\n */\n\nexport type FieldState = \"pending\" | \"streaming\" | \"settled\" | \"error\";\n\nexport interface OutputField {\n /** Key in the streamed object. */\n name: string;\n label: string;\n /** Rough height reserved before the value arrives, in lines. */\n lines?: number;\n}\n\ninterface StructuredOutputContextValue {\n fields: OutputField[];\n value: Record<string, unknown>;\n stateOf: (name: string) => FieldState;\n formatValue: (value: unknown, name: string) => string;\n}\n\nconst StructuredOutputContext = createContext<StructuredOutputContextValue | null>(null);\n\nfunction useStructuredOutputContext(component: string): StructuredOutputContextValue {\n const context = useContext(StructuredOutputContext);\n if (!context) {\n throw new Error(`${component} must be rendered inside <StructuredOutput>.`);\n }\n return context;\n}\n\nfunction defaultFormat(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 (Array.isArray(value)) return value.map(defaultFormat).join(\", \");\n return JSON.stringify(value);\n}\n\nexport interface StructuredOutputProps extends Omit<ComponentPropsWithRef<\"dl\">, \"children\"> {\n /** Declared up front, so layout is reserved before anything arrives. */\n fields: OutputField[];\n /** The latest partial snapshot. */\n value: Record<string, unknown>;\n /**\n * True while more of the object is still expected. When false every present\n * field is settled, which is the only completion signal that is ever certain.\n */\n streaming?: boolean;\n /**\n * Fields the caller knows are finished. Supply this when the API gives a\n * real signal; otherwise the default rule applies.\n */\n settled?: string[];\n /** Fields that failed to extract, with the reason shown in place. */\n errors?: Record<string, string>;\n formatValue?: (value: unknown, name: string) => string;\n children?: ReactNode;\n}\n\nexport function StructuredOutput({\n className,\n fields,\n value,\n streaming = false,\n settled,\n errors,\n formatValue = defaultFormat,\n children,\n ...props\n}: StructuredOutputProps) {\n const stateOf = useMemo(() => {\n const explicit = settled ? new Set(settled) : null;\n const lastPresentIndex = fields.reduce(\n (last, field, index) => (value[field.name] !== undefined ? index : last),\n -1,\n );\n\n return (name: string): FieldState => {\n if (errors?.[name]) return \"error\";\n\n const index = fields.findIndex((field) => field.name === name);\n const present = value[name] !== undefined;\n\n if (!present) return \"pending\";\n if (explicit) return explicit.has(name) ? \"settled\" : \"streaming\";\n // No explicit signal. Once a later field has appeared this one cannot\n // still be growing, which holds for depth-first JSON streaming. The last\n // present field stays \"streaming\" until the caller says streaming ended.\n if (!streaming) return \"settled\";\n return index < lastPresentIndex ? \"settled\" : \"streaming\";\n };\n }, [fields, value, streaming, settled, errors]);\n\n const context = useMemo<StructuredOutputContextValue>(\n () => ({ fields, value, stateOf, formatValue }),\n [fields, value, stateOf, formatValue],\n );\n\n return (\n <StructuredOutputContext.Provider value={context}>\n <dl\n data-slot=\"structured-output\"\n data-streaming={streaming || undefined}\n // Fields arrive one at a time and each is a small, self-contained fact,\n // so the region is polite and additive rather than re-reading the whole\n // object on every token.\n aria-live=\"polite\"\n aria-busy={streaming}\n className={cn(\"flex flex-col gap-3\", className)}\n {...props}\n >\n {children ??\n fields.map((field) => <StructuredField key={field.name} name={field.name} />)}\n </dl>\n </StructuredOutputContext.Provider>\n );\n}\n\nexport interface StructuredFieldProps extends Omit<ComponentPropsWithRef<\"div\">, \"children\"> {\n name: string;\n children?: ReactNode;\n}\n\n/**\n * One field: its label, its value, and the space it will occupy before it has\n * one.\n *\n * The reserved height is what stops the layout jumping as the object fills in.\n */\nexport function StructuredField({ className, name, children, ...props }: StructuredFieldProps) {\n const { fields, value, stateOf, formatValue } = useStructuredOutputContext(\"StructuredField\");\n\n const field = fields.find((candidate) => candidate.name === name);\n if (!field) {\n throw new Error(`StructuredField \"${name}\" is not declared in the fields prop.`);\n }\n\n const state = stateOf(name);\n const raw = value[name];\n\n return (\n <div\n data-slot=\"structured-field\"\n data-state={state}\n data-field={name}\n className={cn(\"flex flex-col gap-1\", className)}\n {...props}\n >\n <dt className=\"text-xs text-muted-foreground\">{field.label}</dt>\n <dd\n className={cn(\n \"m-0 text-sm\",\n state === \"pending\" && \"text-muted-foreground\",\n state === \"error\" && \"text-destructive\",\n )}\n // Height is reserved from the declared line count so the value lands in\n // space already set aside for it rather than pushing the page down.\n // Computed rather than left to calc() so the reserved height is a plain\n // value that can be asserted and reasoned about.\n style={{ minHeight: `${String((field.lines ?? 1) * 1.25)}rem` }}\n >\n {state === \"pending\" ? (\n <span\n data-slot=\"structured-field-placeholder\"\n aria-hidden=\"true\"\n className=\"block h-4 w-24 animate-pulse-soft rounded bg-muted\"\n />\n ) : (\n (children ?? formatValue(raw, name))\n )}\n </dd>\n </div>\n );\n}\n\n/**\n * A confidence score for one field.\n *\n * Rendered as text with the number, never as a bare colour, because \"how much\n * should I trust this\" is exactly the thing a colour cannot answer.\n */\nexport function StructuredConfidence({\n className,\n value: confidence,\n lowBelow = 0.7,\n ...props\n}: ComponentPropsWithRef<\"p\"> & { value: number; lowBelow?: number }) {\n const low = confidence < lowBelow;\n const percent = new Intl.NumberFormat(undefined, {\n style: \"percent\",\n maximumFractionDigits: 0,\n }).format(confidence);\n\n return (\n <p\n data-slot=\"structured-confidence\"\n data-low={low || undefined}\n className={cn(\"text-xs\", low ? \"text-warning\" : \"text-muted-foreground\", className)}\n {...props}\n >\n {low ? `Low confidence, ${percent} — worth checking` : `${percent} confidence`}\n </p>\n );\n}\n\n/** The reason a field could not be extracted, shown where the value would be. */\nexport function StructuredFieldError({ className, ...props }: ComponentPropsWithRef<\"p\">) {\n return (\n <p\n data-slot=\"structured-field-error\"\n className={cn(\"text-xs text-destructive\", className)}\n {...props}\n />\n );\n}\n"],"mappings":";;;;;AAgDA,MAAM,0BAA0B,cAAmD,IAAI;AAEvF,SAAS,2BAA2B,WAAiD;CACnF,MAAM,UAAU,WAAW,uBAAuB;CAClD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,GAAG,UAAU,6CAA6C;CAE5E,OAAO;AACT;AAEA,SAAS,cAAc,OAAwB;CAC7C,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,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,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/components/ai-structured-output/ai-structured-output.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useMemo,\n useState,\n type ComponentPropsWithRef,\n type ReactNode,\n} from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/**\n * An object arriving field by field from the model.\n *\n * Most AI features inside real software are not chatbots. They are invoice\n * extraction, CRM enrichment, resume parsing, form autofill — a schema goes in\n * and a filled object comes back. Every one of them streams a partial object\n * into a layout, and almost every one reflows on each token because the fields\n * appear as they arrive.\n *\n * The honest limitation, stated here rather than discovered later: there is no\n * per-field completion signal anywhere in the stack. A streaming API hands you\n * successive partial snapshots, and a string that has stopped growing is\n * indistinguishable from one still arriving. So this component does not pretend\n * to know. It takes the field list up front, reserves the layout from it, and\n * lets the caller say which fields are settled — defaulting to the rule that a\n * field is settled once a later field has appeared, which is true of\n * depth-first JSON streaming and is documented rather than assumed silently.\n */\n\nexport type FieldState = \"pending\" | \"streaming\" | \"settled\" | \"error\";\n\nexport interface OutputField {\n /** Key in the streamed object. */\n name: string;\n label: string;\n /** Rough height reserved before the value arrives, in lines. */\n lines?: number;\n}\n\ninterface StructuredOutputContextValue {\n fields: OutputField[];\n value: Record<string, unknown>;\n stateOf: (name: string) => FieldState;\n formatValue: (value: unknown, name: string) => string;\n}\n\nconst StructuredOutputContext = createContext<StructuredOutputContextValue | null>(null);\n\nfunction useStructuredOutputContext(component: string): StructuredOutputContextValue {\n const context = useContext(StructuredOutputContext);\n if (!context) {\n throw new Error(`${component} must be rendered inside <StructuredOutput>.`);\n }\n return context;\n}\n\nfunction defaultFormat(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 (Array.isArray(value)) return value.map(defaultFormat).join(\", \");\n return JSON.stringify(value);\n}\n\nexport interface StructuredOutputProps extends Omit<ComponentPropsWithRef<\"dl\">, \"children\"> {\n /** Declared up front, so layout is reserved before anything arrives. */\n fields: OutputField[];\n /** The latest partial snapshot. */\n value: Record<string, unknown>;\n /**\n * True while more of the object is still expected. When false every present\n * field is settled, which is the only completion signal that is ever certain.\n */\n streaming?: boolean;\n /**\n * Fields the caller knows are finished. Supply this when the API gives a\n * real signal; otherwise the default rule applies.\n */\n settled?: string[];\n /** Fields that failed to extract, with the reason shown in place. */\n errors?: Record<string, string>;\n formatValue?: (value: unknown, name: string) => string;\n children?: ReactNode;\n}\n\nexport function StructuredOutput({\n className,\n fields,\n value,\n streaming = false,\n settled,\n errors,\n formatValue = defaultFormat,\n children,\n ...props\n}: StructuredOutputProps) {\n const stateOf = useMemo(() => {\n const explicit = settled ? new Set(settled) : null;\n const lastPresentIndex = fields.reduce(\n (last, field, index) => (value[field.name] !== undefined ? index : last),\n -1,\n );\n\n return (name: string): FieldState => {\n if (errors?.[name]) return \"error\";\n\n const index = fields.findIndex((field) => field.name === name);\n const present = value[name] !== undefined;\n\n if (!present) return \"pending\";\n if (explicit) return explicit.has(name) ? \"settled\" : \"streaming\";\n // No explicit signal. Once a later field has appeared this one cannot\n // still be growing, which holds for depth-first JSON streaming. The last\n // present field stays \"streaming\" until the caller says streaming ended.\n if (!streaming) return \"settled\";\n return index < lastPresentIndex ? \"settled\" : \"streaming\";\n };\n }, [fields, value, streaming, settled, errors]);\n\n const context = useMemo<StructuredOutputContextValue>(\n () => ({ fields, value, stateOf, formatValue }),\n [fields, value, stateOf, formatValue],\n );\n\n return (\n <StructuredOutputContext.Provider value={context}>\n <dl\n data-slot=\"structured-output\"\n data-streaming={streaming || undefined}\n // Fields arrive one at a time and each is a small, self-contained fact,\n // so the region is polite and additive rather than re-reading the whole\n // object on every token.\n aria-live=\"polite\"\n aria-busy={streaming}\n className={cn(\"flex flex-col gap-3\", className)}\n {...props}\n >\n {children ??\n fields.map((field) => <StructuredField key={field.name} name={field.name} />)}\n </dl>\n </StructuredOutputContext.Provider>\n );\n}\n\nexport interface StructuredFieldProps extends Omit<ComponentPropsWithRef<\"div\">, \"children\"> {\n name: string;\n children?: ReactNode;\n}\n\n/**\n * One field: its label, its value, and the space it will occupy before it has\n * one.\n *\n * The reserved height is what stops the layout jumping as the object fills in.\n */\nexport function StructuredField({ className, name, children, ...props }: StructuredFieldProps) {\n const { fields, value, stateOf, formatValue } = useStructuredOutputContext(\"StructuredField\");\n\n const field = fields.find((candidate) => candidate.name === name);\n if (!field) {\n throw new Error(`StructuredField \"${name}\" is not declared in the fields prop.`);\n }\n\n const state = stateOf(name);\n const raw = value[name];\n\n // \"A token arrived\" and \"this field is final\" are different facts, and in a\n // streamed object they look identical. The settle makes that distinction\n // visible — so it plays on the transition into settled, and never on a field\n // that was already final when the component mounted.\n //\n // State adjusted during render rather than tracked in a ref: reading a ref\n // while rendering is unsafe under concurrent rendering, and an effect would\n // paint the plain value first and animate a frame later. React re-renders\n // immediately here and discards the intermediate pass.\n const [seenState, setSeenState] = useState<FieldState>(state);\n const [hasSettled, setHasSettled] = useState(false);\n\n if (seenState !== state) {\n setSeenState(state);\n if (state === \"settled\" && seenState !== \"settled\") setHasSettled(true);\n }\n\n return (\n <div\n data-slot=\"structured-field\"\n data-state={state}\n data-settled={hasSettled || undefined}\n data-field={name}\n className={cn(\"flex flex-col gap-1\", className)}\n {...props}\n >\n <dt className=\"text-xs text-muted-foreground\">{field.label}</dt>\n <dd\n className={cn(\n \"m-0 text-sm\",\n state === \"pending\" && \"text-muted-foreground\",\n state === \"error\" && \"text-destructive\",\n )}\n // Height is reserved from the declared line count so the value lands in\n // space already set aside for it rather than pushing the page down.\n // Computed rather than left to calc() so the reserved height is a plain\n // value that can be asserted and reasoned about.\n style={{ minHeight: `${String((field.lines ?? 1) * 1.25)}rem` }}\n >\n {state === \"pending\" ? (\n <span\n data-slot=\"structured-field-placeholder\"\n aria-hidden=\"true\"\n className=\"block h-4 w-24 animate-pulse-soft rounded bg-muted\"\n />\n ) : (\n <span\n data-slot=\"structured-field-value\"\n className={cn(hasSettled && \"inline-block animate-settle\")}\n >\n {children ?? formatValue(raw, name)}\n </span>\n )}\n </dd>\n </div>\n );\n}\n\n/**\n * A confidence score for one field.\n *\n * Rendered as text with the number, never as a bare colour, because \"how much\n * should I trust this\" is exactly the thing a colour cannot answer.\n */\nexport function StructuredConfidence({\n className,\n value: confidence,\n lowBelow = 0.7,\n ...props\n}: ComponentPropsWithRef<\"p\"> & { value: number; lowBelow?: number }) {\n const low = confidence < lowBelow;\n const percent = new Intl.NumberFormat(undefined, {\n style: \"percent\",\n maximumFractionDigits: 0,\n }).format(confidence);\n\n return (\n <p\n data-slot=\"structured-confidence\"\n data-low={low || undefined}\n className={cn(\"text-xs\", low ? \"text-warning\" : \"text-muted-foreground\", className)}\n {...props}\n >\n {low ? `Low confidence, ${percent} — worth checking` : `${percent} confidence`}\n </p>\n );\n}\n\n/** The reason a field could not be extracted, shown where the value would be. */\nexport function StructuredFieldError({ className, ...props }: ComponentPropsWithRef<\"p\">) {\n return (\n <p\n data-slot=\"structured-field-error\"\n className={cn(\"text-xs text-destructive\", className)}\n {...props}\n />\n );\n}\n"],"mappings":";;;;;AAiDA,MAAM,0BAA0B,cAAmD,IAAI;AAEvF,SAAS,2BAA2B,WAAiD;CACnF,MAAM,UAAU,WAAW,uBAAuB;CAClD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,GAAG,UAAU,6CAA6C;CAE5E,OAAO;AACT;AAEA,SAAS,cAAc,OAAwB;CAC7C,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,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,aAAa,CAAC,CAAC,KAAK,IAAI;CACnE,OAAO,KAAK,UAAU,KAAK;AAC7B;AAuBA,SAAgB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AAA;AAEP;;AAGA,SAAgB,qBAAqB,EAAE,WAAW,GAAG,SAAqC;CACxF,OACE,oBAAC,KAAD;EACE,aAAU;EACV,WAAW,GAAG,4BAA4B,SAAS;EACnD,GAAI;CACL,CAAA;AAEL"}
|
|
@@ -14,7 +14,7 @@ import { ComponentPropsWithRef, ReactNode } from "react";
|
|
|
14
14
|
*/
|
|
15
15
|
type ToolStatus = "pending" | "running" | "success" | "error";
|
|
16
16
|
declare const toolVariants: (props?: ({
|
|
17
|
-
status?: "success" | "
|
|
17
|
+
status?: "success" | "pending" | "running" | "error" | null | undefined;
|
|
18
18
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
19
19
|
interface ToolProps extends ComponentPropsWithRef<typeof Collapsible.Root>, VariantProps<typeof toolVariants> {
|
|
20
20
|
status?: ToolStatus;
|
|
@@ -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?: "
|
|
5
|
+
variant?: "default" | "destructive" | "success" | "warning" | "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.
|
|
@@ -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?: "
|
|
5
|
+
variant?: "default" | "secondary" | "outline" | "destructive" | "success" | "warning" | "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" | "
|
|
5
|
+
variant?: "link" | "secondary" | "outline" | "destructive" | "primary" | "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> {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { QueuedFile } from "./upload-queue.js";
|
|
2
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/components/file-upload/file-upload.d.ts
|
|
4
|
+
interface FileUploadProps extends Omit<ComponentPropsWithRef<"div">, "onDrop"> {
|
|
5
|
+
/** Names the control. */
|
|
6
|
+
label: string;
|
|
7
|
+
onFiles: (files: File[]) => void;
|
|
8
|
+
accept?: string;
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Shown under the prompt: accepted types, size limit. */
|
|
12
|
+
hint?: ReactNode;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare function FileUpload({ className, label, onFiles, accept, multiple, disabled, hint, children, ...props }: FileUploadProps): import("react").JSX.Element;
|
|
16
|
+
interface FileUploadListProps extends ComponentPropsWithRef<"ul"> {
|
|
17
|
+
files: QueuedFile[];
|
|
18
|
+
onCancel?: (id: string) => void;
|
|
19
|
+
onRetry?: (id: string) => void;
|
|
20
|
+
onRemove?: (id: string) => void;
|
|
21
|
+
}
|
|
22
|
+
declare function FileUploadList({ className, files, onCancel, onRetry, onRemove, ...props }: FileUploadListProps): import("react").JSX.Element | null;
|
|
23
|
+
interface FileUploadItemProps extends Omit<ComponentPropsWithRef<"li">, "children"> {
|
|
24
|
+
entry: QueuedFile;
|
|
25
|
+
onCancel?: (id: string) => void;
|
|
26
|
+
onRetry?: (id: string) => void;
|
|
27
|
+
onRemove?: (id: string) => void;
|
|
28
|
+
}
|
|
29
|
+
declare function FileUploadItem({ className, entry, onCancel, onRetry, onRemove, ...props }: FileUploadItemProps): import("react").JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* One sentence covering the whole queue, announced politely.
|
|
32
|
+
*
|
|
33
|
+
* Per-file live regions would talk over each other the moment two uploads run
|
|
34
|
+
* at once; one summary of the set is readable where six competing ones are not.
|
|
35
|
+
*/
|
|
36
|
+
declare function FileUploadStatus({ className, stats, ...props }: ComponentPropsWithRef<"p"> & {
|
|
37
|
+
stats: {
|
|
38
|
+
total: number;
|
|
39
|
+
active: number;
|
|
40
|
+
done: number;
|
|
41
|
+
failed: number;
|
|
42
|
+
};
|
|
43
|
+
}): import("react").JSX.Element;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { FileUpload, FileUploadItem, FileUploadItemProps, FileUploadList, FileUploadListProps, FileUploadProps, FileUploadStatus };
|
|
46
|
+
//# sourceMappingURL=file-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-upload.d.ts","names":[],"sources":["../../../src/components/file-upload/file-upload.tsx"],"mappings":";;;UAqCiB,wBAAwB,KAAK;;EAE5C;EACA,UAAU,OAAO;EACjB;EACA;EACA;;EAEA,OAAO;EACP,WAAW;;iBAGG,aACd,WACA,OACA,SACA,QACA,UACA,UACA,MACA,aACG,SACF,kCAAe,IAAA;UAsFD,4BAA4B;EAC3C,OAAO;EACP,YAAY;EACZ,WAAW;EACX,YAAY;;iBAGE,iBACd,WACA,OACA,UACA,SACA,aACG,SACF,sCAAmB,IAAA;UAsBL,4BAA4B,KAAK;EAChD,OAAO;EACP,YAAY;EACZ,WAAW;EACX,YAAY;;iBAGE,iBACd,WACA,OACA,UACA,SACA,aACG,SACF,sCAAmB,IAAA;;;;;;;iBA+FN,mBACd,WACA,UACG,SACF;EACD;IAAS;IAAe;IAAgB;IAAc;;oBACvD,IAAA"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { disabledStyles, focusRing } from "../../lib/styles.js";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
import { formatBytes } from "./upload-queue.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useId, useRef, useState } from "react";
|
|
7
|
+
//#region src/components/file-upload/file-upload.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The visible half of uploading. The queue is in `upload-queue.ts` and is the
|
|
10
|
+
* part worth owning.
|
|
11
|
+
*
|
|
12
|
+
* There is no dropzone pattern in the WAI-ARIA APG, and inventing one is the
|
|
13
|
+
* usual failure: a `div` with `role="button"`, a keydown handler, and a file
|
|
14
|
+
* picker that keyboard users can never reach. So the control here is a real
|
|
15
|
+
* `<input type="file">` with a real `<label>`. That is already operable by
|
|
16
|
+
* keyboard, already announces itself, already opens the picker on Enter and
|
|
17
|
+
* Space, and needs nothing added. Drag and drop is layered on top as a pointer
|
|
18
|
+
* convenience, and every drop can also be done from the input.
|
|
19
|
+
*/
|
|
20
|
+
const STATUS_LABEL = {
|
|
21
|
+
queued: "Waiting",
|
|
22
|
+
uploading: "Uploading",
|
|
23
|
+
done: "Uploaded",
|
|
24
|
+
failed: "Failed",
|
|
25
|
+
cancelled: "Cancelled"
|
|
26
|
+
};
|
|
27
|
+
function FileUpload({ className, label, onFiles, accept, multiple = true, disabled = false, hint, children, ...props }) {
|
|
28
|
+
const inputId = useId();
|
|
29
|
+
const hintId = useId();
|
|
30
|
+
const [dragging, setDragging] = useState(false);
|
|
31
|
+
const depth = useRef(0);
|
|
32
|
+
function handleDrop(event) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
depth.current = 0;
|
|
35
|
+
setDragging(false);
|
|
36
|
+
if (disabled) return;
|
|
37
|
+
const dropped = [...event.dataTransfer.files];
|
|
38
|
+
if (dropped.length > 0) onFiles(multiple ? dropped : dropped.slice(0, 1));
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
41
|
+
"data-slot": "file-upload",
|
|
42
|
+
className: cn("flex flex-col gap-3", className),
|
|
43
|
+
...props,
|
|
44
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
45
|
+
"data-slot": "file-upload-dropzone",
|
|
46
|
+
"data-dragging": dragging || void 0,
|
|
47
|
+
onDragEnter: (event) => {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
depth.current += 1;
|
|
50
|
+
if (!disabled) setDragging(true);
|
|
51
|
+
},
|
|
52
|
+
onDragLeave: () => {
|
|
53
|
+
depth.current -= 1;
|
|
54
|
+
if (depth.current <= 0) setDragging(false);
|
|
55
|
+
},
|
|
56
|
+
onDragOver: (event) => {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
},
|
|
59
|
+
onDrop: handleDrop,
|
|
60
|
+
className: cn("rounded-lg border border-dashed border-border-strong bg-muted/30 px-4 py-6 text-center", "transition-colors duration-[var(--duration-fast)]", dragging && "border-primary bg-primary/5", disabled && "pointer-events-none opacity-55"),
|
|
61
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
62
|
+
htmlFor: inputId,
|
|
63
|
+
className: cn("inline-flex cursor-pointer flex-col items-center gap-1 rounded-md px-2 py-1 text-sm", "focus-within:ring-2 focus-within:ring-ring/55"),
|
|
64
|
+
children: [
|
|
65
|
+
/* @__PURE__ */ jsx("span", {
|
|
66
|
+
className: "font-medium",
|
|
67
|
+
children: label
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ jsxs("span", {
|
|
70
|
+
className: "text-xs text-muted-foreground",
|
|
71
|
+
children: [
|
|
72
|
+
"Drop ",
|
|
73
|
+
multiple ? "files" : "a file",
|
|
74
|
+
" here, or choose from your device"
|
|
75
|
+
]
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ jsx("input", {
|
|
78
|
+
id: inputId,
|
|
79
|
+
type: "file",
|
|
80
|
+
accept,
|
|
81
|
+
multiple,
|
|
82
|
+
disabled,
|
|
83
|
+
"aria-describedby": hint ? hintId : void 0,
|
|
84
|
+
onChange: (event) => {
|
|
85
|
+
const chosen = [...event.target.files ?? []];
|
|
86
|
+
if (chosen.length > 0) onFiles(chosen);
|
|
87
|
+
event.target.value = "";
|
|
88
|
+
},
|
|
89
|
+
className: "sr-only"
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
}), hint ? /* @__PURE__ */ jsx("p", {
|
|
93
|
+
id: hintId,
|
|
94
|
+
className: "mt-2 text-xs text-muted-foreground",
|
|
95
|
+
children: hint
|
|
96
|
+
}) : null]
|
|
97
|
+
}), children]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function FileUploadList({ className, files, onCancel, onRetry, onRemove, ...props }) {
|
|
101
|
+
if (files.length === 0) return null;
|
|
102
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
103
|
+
"data-slot": "file-upload-list",
|
|
104
|
+
className: cn("flex list-none flex-col gap-2", className),
|
|
105
|
+
...props,
|
|
106
|
+
children: files.map((entry) => /* @__PURE__ */ jsx(FileUploadItem, {
|
|
107
|
+
entry,
|
|
108
|
+
onCancel,
|
|
109
|
+
onRetry,
|
|
110
|
+
onRemove
|
|
111
|
+
}, entry.id))
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function FileUploadItem({ className, entry, onCancel, onRetry, onRemove, ...props }) {
|
|
115
|
+
const { id, file, status, progress, error } = entry;
|
|
116
|
+
const percent = progress === null ? null : Math.round(progress * 100);
|
|
117
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
118
|
+
"data-slot": "file-upload-item",
|
|
119
|
+
"data-status": status,
|
|
120
|
+
className: cn("flex items-center gap-3 rounded-lg border px-3 py-2 text-sm", status === "failed" ? "border-destructive/40 bg-destructive/5" : "border-border bg-card", className),
|
|
121
|
+
...props,
|
|
122
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
123
|
+
className: "flex min-w-0 flex-1 flex-col gap-1",
|
|
124
|
+
children: [
|
|
125
|
+
/* @__PURE__ */ jsxs("div", {
|
|
126
|
+
className: "flex items-baseline justify-between gap-2",
|
|
127
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
128
|
+
className: "truncate font-medium",
|
|
129
|
+
children: file.name
|
|
130
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
131
|
+
className: "shrink-0 text-xs text-muted-foreground tabular-nums",
|
|
132
|
+
children: formatBytes(file.size)
|
|
133
|
+
})]
|
|
134
|
+
}),
|
|
135
|
+
/* @__PURE__ */ jsxs("p", {
|
|
136
|
+
className: cn("text-xs", status === "failed" ? "text-destructive" : "text-muted-foreground"),
|
|
137
|
+
children: [
|
|
138
|
+
STATUS_LABEL[status],
|
|
139
|
+
status === "uploading" && percent !== null ? ` · ${String(percent)}%` : null,
|
|
140
|
+
error ? ` · ${error}` : null
|
|
141
|
+
]
|
|
142
|
+
}),
|
|
143
|
+
status === "uploading" ? /* @__PURE__ */ jsx("div", {
|
|
144
|
+
role: "progressbar",
|
|
145
|
+
"aria-label": `Uploading ${file.name}`,
|
|
146
|
+
"aria-valuenow": percent ?? void 0,
|
|
147
|
+
"aria-valuemin": 0,
|
|
148
|
+
"aria-valuemax": 100,
|
|
149
|
+
className: "h-1 w-full overflow-hidden rounded-full bg-muted",
|
|
150
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
151
|
+
"data-slot": "file-upload-progress",
|
|
152
|
+
className: "h-full rounded-full bg-primary transition-[width] duration-[var(--duration-normal)] ease-[var(--ease-out-quint)]",
|
|
153
|
+
style: { width: `${String(percent ?? 0)}%` }
|
|
154
|
+
})
|
|
155
|
+
}) : null
|
|
156
|
+
]
|
|
157
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
158
|
+
className: "flex shrink-0 items-center gap-1",
|
|
159
|
+
children: [
|
|
160
|
+
status === "uploading" && onCancel ? /* @__PURE__ */ jsx(ItemButton, {
|
|
161
|
+
onClick: () => onCancel(id),
|
|
162
|
+
children: "Cancel"
|
|
163
|
+
}) : null,
|
|
164
|
+
(status === "failed" || status === "cancelled") && onRetry ? /* @__PURE__ */ jsx(ItemButton, {
|
|
165
|
+
onClick: () => onRetry(id),
|
|
166
|
+
children: "Retry"
|
|
167
|
+
}) : null,
|
|
168
|
+
onRemove ? /* @__PURE__ */ jsx(ItemButton, {
|
|
169
|
+
onClick: () => onRemove(id),
|
|
170
|
+
"aria-label": `Remove ${file.name}`,
|
|
171
|
+
children: "Remove"
|
|
172
|
+
}) : null
|
|
173
|
+
]
|
|
174
|
+
})]
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function ItemButton({ className, ...props }) {
|
|
178
|
+
return /* @__PURE__ */ jsx("button", {
|
|
179
|
+
type: "button",
|
|
180
|
+
className: cn("rounded-md border border-input bg-background px-2 py-0.5 text-xs font-medium", "transition-colors hover:bg-accent hover:text-accent-foreground", focusRing, disabledStyles, className),
|
|
181
|
+
...props
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* One sentence covering the whole queue, announced politely.
|
|
186
|
+
*
|
|
187
|
+
* Per-file live regions would talk over each other the moment two uploads run
|
|
188
|
+
* at once; one summary of the set is readable where six competing ones are not.
|
|
189
|
+
*/
|
|
190
|
+
function FileUploadStatus({ className, stats, ...props }) {
|
|
191
|
+
const { total, active, done, failed } = stats;
|
|
192
|
+
const message = total === 0 ? "" : active > 0 ? `${String(done)} of ${String(total)} uploaded` : failed > 0 ? `${String(done)} uploaded, ${String(failed)} failed` : `${String(done)} uploaded`;
|
|
193
|
+
return /* @__PURE__ */ jsx("p", {
|
|
194
|
+
"data-slot": "file-upload-status",
|
|
195
|
+
"aria-live": "polite",
|
|
196
|
+
className: cn("text-xs text-muted-foreground", className),
|
|
197
|
+
...props,
|
|
198
|
+
children: message
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
export { FileUpload, FileUploadItem, FileUploadList, FileUploadStatus };
|
|
203
|
+
|
|
204
|
+
//# sourceMappingURL=file-upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-upload.js","names":[],"sources":["../../../src/components/file-upload/file-upload.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useId,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type DragEvent,\n type ReactNode,\n} from \"react\";\n\nimport { disabledStyles, focusRing } from \"@/lib/styles\";\nimport { cn } from \"@/lib/utils\";\n\nimport { formatBytes, type QueuedFile, type UploadStatus } from \"./upload-queue\";\n\n/**\n * The visible half of uploading. The queue is in `upload-queue.ts` and is the\n * part worth owning.\n *\n * There is no dropzone pattern in the WAI-ARIA APG, and inventing one is the\n * usual failure: a `div` with `role=\"button\"`, a keydown handler, and a file\n * picker that keyboard users can never reach. So the control here is a real\n * `<input type=\"file\">` with a real `<label>`. That is already operable by\n * keyboard, already announces itself, already opens the picker on Enter and\n * Space, and needs nothing added. Drag and drop is layered on top as a pointer\n * convenience, and every drop can also be done from the input.\n */\n\nconst STATUS_LABEL: Record<UploadStatus, string> = {\n queued: \"Waiting\",\n uploading: \"Uploading\",\n done: \"Uploaded\",\n failed: \"Failed\",\n cancelled: \"Cancelled\",\n};\n\nexport interface FileUploadProps extends Omit<ComponentPropsWithRef<\"div\">, \"onDrop\"> {\n /** Names the control. */\n label: string;\n onFiles: (files: File[]) => void;\n accept?: string;\n multiple?: boolean;\n disabled?: boolean;\n /** Shown under the prompt: accepted types, size limit. */\n hint?: ReactNode;\n children?: ReactNode;\n}\n\nexport function FileUpload({\n className,\n label,\n onFiles,\n accept,\n multiple = true,\n disabled = false,\n hint,\n children,\n ...props\n}: FileUploadProps) {\n const inputId = useId();\n const hintId = useId();\n const [dragging, setDragging] = useState(false);\n const depth = useRef(0);\n\n function handleDrop(event: DragEvent<HTMLDivElement>) {\n event.preventDefault();\n depth.current = 0;\n setDragging(false);\n if (disabled) return;\n\n const dropped = [...event.dataTransfer.files];\n if (dropped.length > 0) onFiles(multiple ? dropped : dropped.slice(0, 1));\n }\n\n return (\n <div data-slot=\"file-upload\" className={cn(\"flex flex-col gap-3\", className)} {...props}>\n {/* dragenter/dragleave fire for every child element, so a plain boolean\n flickers as the pointer crosses the prompt text. Counting depth is\n what makes the highlight steady. */}\n <div\n data-slot=\"file-upload-dropzone\"\n data-dragging={dragging || undefined}\n onDragEnter={(event) => {\n event.preventDefault();\n depth.current += 1;\n if (!disabled) setDragging(true);\n }}\n onDragLeave={() => {\n depth.current -= 1;\n if (depth.current <= 0) setDragging(false);\n }}\n onDragOver={(event) => {\n event.preventDefault();\n }}\n onDrop={handleDrop}\n className={cn(\n \"rounded-lg border border-dashed border-border-strong bg-muted/30 px-4 py-6 text-center\",\n \"transition-colors duration-[var(--duration-fast)]\",\n dragging && \"border-primary bg-primary/5\",\n disabled && \"pointer-events-none opacity-55\",\n )}\n >\n {/* The label is the control. Clicking it opens the picker, Enter and\n Space activate it, and assistive technology already describes it. */}\n <label\n htmlFor={inputId}\n className={cn(\n \"inline-flex cursor-pointer flex-col items-center gap-1 rounded-md px-2 py-1 text-sm\",\n \"focus-within:ring-2 focus-within:ring-ring/55\",\n )}\n >\n <span className=\"font-medium\">{label}</span>\n <span className=\"text-xs text-muted-foreground\">\n Drop {multiple ? \"files\" : \"a file\"} here, or choose from your device\n </span>\n <input\n id={inputId}\n type=\"file\"\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n aria-describedby={hint ? hintId : undefined}\n onChange={(event) => {\n const chosen = [...(event.target.files ?? [])];\n if (chosen.length > 0) onFiles(chosen);\n // Reset, so choosing the same file twice fires change twice.\n event.target.value = \"\";\n }}\n className=\"sr-only\"\n />\n </label>\n\n {hint ? (\n <p id={hintId} className=\"mt-2 text-xs text-muted-foreground\">\n {hint}\n </p>\n ) : null}\n </div>\n\n {children}\n </div>\n );\n}\n\nexport interface FileUploadListProps extends ComponentPropsWithRef<\"ul\"> {\n files: QueuedFile[];\n onCancel?: (id: string) => void;\n onRetry?: (id: string) => void;\n onRemove?: (id: string) => void;\n}\n\nexport function FileUploadList({\n className,\n files,\n onCancel,\n onRetry,\n onRemove,\n ...props\n}: FileUploadListProps) {\n if (files.length === 0) return null;\n\n return (\n <ul\n data-slot=\"file-upload-list\"\n className={cn(\"flex list-none flex-col gap-2\", className)}\n {...props}\n >\n {files.map((entry) => (\n <FileUploadItem\n key={entry.id}\n entry={entry}\n onCancel={onCancel}\n onRetry={onRetry}\n onRemove={onRemove}\n />\n ))}\n </ul>\n );\n}\n\nexport interface FileUploadItemProps extends Omit<ComponentPropsWithRef<\"li\">, \"children\"> {\n entry: QueuedFile;\n onCancel?: (id: string) => void;\n onRetry?: (id: string) => void;\n onRemove?: (id: string) => void;\n}\n\nexport function FileUploadItem({\n className,\n entry,\n onCancel,\n onRetry,\n onRemove,\n ...props\n}: FileUploadItemProps) {\n const { id, file, status, progress, error } = entry;\n const percent = progress === null ? null : Math.round(progress * 100);\n\n return (\n <li\n data-slot=\"file-upload-item\"\n data-status={status}\n className={cn(\n \"flex items-center gap-3 rounded-lg border px-3 py-2 text-sm\",\n status === \"failed\"\n ? \"border-destructive/40 bg-destructive/5\"\n : \"border-border bg-card\",\n className,\n )}\n {...props}\n >\n <div className=\"flex min-w-0 flex-1 flex-col gap-1\">\n <div className=\"flex items-baseline justify-between gap-2\">\n <span className=\"truncate font-medium\">{file.name}</span>\n <span className=\"shrink-0 text-xs text-muted-foreground tabular-nums\">\n {formatBytes(file.size)}\n </span>\n </div>\n\n {/* Status in words, always. A bar at 60% with a red tint does not say\n whether it is uploading, stalled or failed. */}\n <p\n className={cn(\n \"text-xs\",\n status === \"failed\" ? \"text-destructive\" : \"text-muted-foreground\",\n )}\n >\n {STATUS_LABEL[status]}\n {status === \"uploading\" && percent !== null ? ` · ${String(percent)}%` : null}\n {error ? ` · ${error}` : null}\n </p>\n\n {status === \"uploading\" ? (\n <div\n role=\"progressbar\"\n aria-label={`Uploading ${file.name}`}\n aria-valuenow={percent ?? undefined}\n aria-valuemin={0}\n aria-valuemax={100}\n className=\"h-1 w-full overflow-hidden rounded-full bg-muted\"\n >\n <div\n data-slot=\"file-upload-progress\"\n className=\"h-full rounded-full bg-primary transition-[width] duration-[var(--duration-normal)] ease-[var(--ease-out-quint)]\"\n style={{ width: `${String(percent ?? 0)}%` }}\n />\n </div>\n ) : null}\n </div>\n\n <div className=\"flex shrink-0 items-center gap-1\">\n {status === \"uploading\" && onCancel ? (\n <ItemButton onClick={() => onCancel(id)}>Cancel</ItemButton>\n ) : null}\n {(status === \"failed\" || status === \"cancelled\") && onRetry ? (\n <ItemButton onClick={() => onRetry(id)}>Retry</ItemButton>\n ) : null}\n {onRemove ? (\n <ItemButton onClick={() => onRemove(id)} aria-label={`Remove ${file.name}`}>\n Remove\n </ItemButton>\n ) : null}\n </div>\n </li>\n );\n}\n\nfunction ItemButton({ className, ...props }: ComponentPropsWithRef<\"button\">) {\n return (\n <button\n type=\"button\"\n className={cn(\n \"rounded-md border border-input bg-background px-2 py-0.5 text-xs font-medium\",\n \"transition-colors hover:bg-accent hover:text-accent-foreground\",\n focusRing,\n disabledStyles,\n className,\n )}\n {...props}\n />\n );\n}\n\n/**\n * One sentence covering the whole queue, announced politely.\n *\n * Per-file live regions would talk over each other the moment two uploads run\n * at once; one summary of the set is readable where six competing ones are not.\n */\nexport function FileUploadStatus({\n className,\n stats,\n ...props\n}: ComponentPropsWithRef<\"p\"> & {\n stats: { total: number; active: number; done: number; failed: number };\n}) {\n const { total, active, done, failed } = stats;\n\n // Progress through the set, not a count of what happens to be in flight.\n // \"3 of 5 uploading\" is wrong the moment a concurrency limit holds two back,\n // and it never tells the reader how much of the job is left.\n const message =\n total === 0\n ? \"\"\n : active > 0\n ? `${String(done)} of ${String(total)} uploaded`\n : failed > 0\n ? `${String(done)} uploaded, ${String(failed)} failed`\n : `${String(done)} uploaded`;\n\n return (\n <p\n data-slot=\"file-upload-status\"\n aria-live=\"polite\"\n className={cn(\"text-xs text-muted-foreground\", className)}\n {...props}\n >\n {message}\n </p>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6BA,MAAM,eAA6C;CACjD,QAAQ;CACR,WAAW;CACX,MAAM;CACN,QAAQ;CACR,WAAW;AACb;AAcA,SAAgB,WAAW,EACzB,WACA,OACA,SACA,QACA,WAAW,MACX,WAAW,OACX,MACA,UACA,GAAG,SACe;CAClB,MAAM,UAAU,MAAM;CACtB,MAAM,SAAS,MAAM;CACrB,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,QAAQ,OAAO,CAAC;CAEtB,SAAS,WAAW,OAAkC;EACpD,MAAM,eAAe;EACrB,MAAM,UAAU;EAChB,YAAY,KAAK;EACjB,IAAI,UAAU;EAEd,MAAM,UAAU,CAAC,GAAG,MAAM,aAAa,KAAK;EAC5C,IAAI,QAAQ,SAAS,GAAG,QAAQ,WAAW,UAAU,QAAQ,MAAM,GAAG,CAAC,CAAC;CAC1E;CAEA,OACE,qBAAC,OAAD;EAAK,aAAU;EAAc,WAAW,GAAG,uBAAuB,SAAS;EAAG,GAAI;EAAlF,UAAA,CAIE,qBAAC,OAAD;GACE,aAAU;GACV,iBAAe,YAAY,KAAA;GAC3B,cAAc,UAAU;IACtB,MAAM,eAAe;IACrB,MAAM,WAAW;IACjB,IAAI,CAAC,UAAU,YAAY,IAAI;GACjC;GACA,mBAAmB;IACjB,MAAM,WAAW;IACjB,IAAI,MAAM,WAAW,GAAG,YAAY,KAAK;GAC3C;GACA,aAAa,UAAU;IACrB,MAAM,eAAe;GACvB;GACA,QAAQ;GACR,WAAW,GACT,0FACA,qDACA,YAAY,+BACZ,YAAY,gCACd;GArBF,UAAA,CAyBE,qBAAC,SAAD;IACE,SAAS;IACT,WAAW,GACT,uFACA,+CACF;IALF,UAAA;KAOE,oBAAC,QAAD;MAAM,WAAU;MAAe,UAAA;KAAY,CAAA;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S,IACP,GAAG,OAAO,IAAI,EAAE,aAAa,OAAO,MAAM,EAAE,WAC5C,GAAG,OAAO,IAAI,EAAE;CAE1B,OACE,oBAAC,KAAD;EACE,aAAU;EACV,aAAU;EACV,WAAW,GAAG,iCAAiC,SAAS;EACxD,GAAI;EAEH,UAAA;CACA,CAAA;AAEP"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { QueuedFile, UploadContext, UploadFn, UploadQueueOptions, UploadStatus, formatBytes, matchesAccept, useUploadQueue, xhrUpload } from "./upload-queue.js";
|
|
2
|
+
import { FileUpload, FileUploadItem, FileUploadItemProps, FileUploadList, FileUploadListProps, FileUploadProps, FileUploadStatus } from "./file-upload.js";
|
|
3
|
+
export { FileUpload, FileUploadItem, type FileUploadItemProps, FileUploadList, type FileUploadListProps, type FileUploadProps, FileUploadStatus, type QueuedFile, type UploadContext, type UploadFn, type UploadQueueOptions, type UploadStatus, formatBytes, matchesAccept, useUploadQueue, xhrUpload };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { formatBytes, matchesAccept, useUploadQueue, xhrUpload } from "./upload-queue.js";
|
|
2
|
+
import { FileUpload, FileUploadItem, FileUploadList, FileUploadStatus } from "./file-upload.js";
|
|
3
|
+
export { FileUpload, FileUploadItem, FileUploadList, FileUploadStatus, formatBytes, matchesAccept, useUploadQueue, xhrUpload };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineMeta } from "../../registry/schema.js";
|
|
2
|
+
//#region src/components/file-upload/meta.ts
|
|
3
|
+
const meta = defineMeta({
|
|
4
|
+
name: "file-upload",
|
|
5
|
+
title: "File Upload",
|
|
6
|
+
description: "A dropzone over a real file input, plus the upload queue nobody ships.",
|
|
7
|
+
category: "form",
|
|
8
|
+
status: "stable",
|
|
9
|
+
dependencies: [],
|
|
10
|
+
registryDependencies: [],
|
|
11
|
+
files: ["upload-queue.ts", "file-upload.tsx"],
|
|
12
|
+
a11y: "The APG has no dropzone pattern, and inventing one is the usual failure — a div with role=\"button\", a keydown handler, and a picker keyboard users never reach. The control here is a real input[type=file] with a real label, which is already operable, already announced, and opens the picker on Enter and Space with nothing added. Drag and drop is a pointer convenience layered on top; every drop can also be done from the input. Each uploading file gets a progressbar named after it, status is always stated in words as well as drawn, and one polite live region summarises the whole queue rather than six per-file regions talking over each other."
|
|
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/file-upload/meta.ts"],"sourcesContent":["import { defineMeta } from \"@/registry/schema\";\n\nexport const meta = defineMeta({\n name: \"file-upload\",\n title: \"File Upload\",\n description: \"A dropzone over a real file input, plus the upload queue nobody ships.\",\n category: \"form\",\n status: \"stable\",\n dependencies: [],\n registryDependencies: [],\n files: [\"upload-queue.ts\", \"file-upload.tsx\"],\n a11y:\n \"The APG has no dropzone pattern, and inventing one is the usual failure — a div with \" +\n 'role=\"button\", a keydown handler, and a picker keyboard users never reach. The control here ' +\n \"is a real input[type=file] with a real label, which is already operable, already announced, \" +\n \"and opens the picker on Enter and Space with nothing added. Drag and drop is a pointer \" +\n \"convenience layered on top; every drop can also be done from the input. Each uploading file \" +\n \"gets a progressbar named after it, status is always stated in words as well as drawn, and \" +\n \"one polite live region summarises the whole queue rather than six per-file regions talking \" +\n \"over each other.\",\n});\n"],"mappings":";;AAEA,MAAa,OAAO,WAAW;CAC7B,MAAM;CACN,OAAO;CACP,aAAa;CACb,UAAU;CACV,QAAQ;CACR,cAAc,CAAC;CACf,sBAAsB,CAAC;CACvB,OAAO,CAAC,mBAAmB,iBAAiB;CAC5C,MACE;AAQJ,CAAC"}
|