@langchain/macaw-components 1.6.0 → 1.6.2

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 (37) hide show
  1. package/dist/catalog.json +743 -686
  2. package/dist/components/ChatRichContent/ChatRichContent.d.ts +4 -0
  3. package/dist/components/ChatRichContent/ChatRichContent.js +315 -0
  4. package/dist/components/ChatRichContent/ChatRichContent.js.map +1 -0
  5. package/dist/components/ChatRichContent/ChatRichContent.types.d.ts +101 -0
  6. package/dist/components/ChatRichContent/ChatRichContent.types.js +0 -0
  7. package/dist/components/ChatRichContent/ChatRichContentChoices.d.ts +2 -0
  8. package/dist/components/ChatRichContent/ChatRichContentChoices.js +121 -0
  9. package/dist/components/ChatRichContent/ChatRichContentChoices.js.map +1 -0
  10. package/dist/components/ChatRichContent/ChatRichContentCollapsible.d.ts +10 -0
  11. package/dist/components/ChatRichContent/ChatRichContentCollapsible.js +23 -0
  12. package/dist/components/ChatRichContent/ChatRichContentCollapsible.js.map +1 -0
  13. package/dist/components/ChatRichContent/ChatRichContentQuestionNav.d.ts +7 -0
  14. package/dist/components/ChatRichContent/ChatRichContentQuestionNav.js +53 -0
  15. package/dist/components/ChatRichContent/ChatRichContentQuestionNav.js.map +1 -0
  16. package/dist/components/ChatRichContent/ChatRichContentStatus.d.ts +11 -0
  17. package/dist/components/ChatRichContent/ChatRichContentStatus.js +31 -0
  18. package/dist/components/ChatRichContent/ChatRichContentStatus.js.map +1 -0
  19. package/dist/components/ChatRichContent/index.d.ts +3 -0
  20. package/dist/components/ChatRichContent/index.js +3 -0
  21. package/dist/components/index.d.ts +2 -0
  22. package/dist/components/index.js +7 -5
  23. package/dist/docs/ControlSizeMatrix.d.ts +16 -0
  24. package/dist/docs/ControlSizeMatrix.js +34 -0
  25. package/dist/docs/ControlSizeMatrix.js.map +1 -0
  26. package/dist/docs/overviewEntries.d.ts +10 -0
  27. package/dist/docs/overviewEntries.js +557 -0
  28. package/dist/docs/overviewEntries.js.map +1 -0
  29. package/dist/docs/phosphor-icon-catalog.d.ts +9 -0
  30. package/dist/docs/phosphor-icon-catalog.js +459 -0
  31. package/dist/docs/phosphor-icon-catalog.js.map +1 -0
  32. package/dist/icons/LongTailPhosphorIcons.js +2 -2
  33. package/dist/icons/WeightedPhosphorIcons.js +9 -9
  34. package/dist/index.js +7 -5
  35. package/dist/utilities.css +1 -1
  36. package/docs/DESIGN.md +24 -0
  37. package/package.json +6 -2
@@ -0,0 +1,4 @@
1
+ import type { ChatRichContentFallbackProps, ChatRichContentProps } from './ChatRichContent.types.js';
2
+ export declare function ChatRichContent(props: ChatRichContentProps): import("react").JSX.Element;
3
+ /** Use after the host adapter rejects a block. Inert unless the host supplies actions. */
4
+ export declare function ChatRichContentFallback({ actions, }: ChatRichContentFallbackProps): import("react").JSX.Element;
@@ -0,0 +1,315 @@
1
+ import { cn } from "../../utils/cn.js";
2
+ import { Text } from "../Text/Text.js";
3
+ import { IconButton } from "../IconButton/IconButton.js";
4
+ import { Button } from "../Button/Button.js";
5
+ import { ChatComposerContext } from "../ChatComposer/ChatComposerContext.js";
6
+ import { Textarea } from "../Textarea/Textarea.js";
7
+ import { ChatRichContentCollapsible } from "./ChatRichContentCollapsible.js";
8
+ import { ChatRichContentQuestionNav } from "./ChatRichContentQuestionNav.js";
9
+ import { ChatRichContentStatus } from "./ChatRichContentStatus.js";
10
+ import { useContext, useId, useLayoutEffect, useRef, useState } from "react";
11
+ import { CaretDownIcon } from "@phosphor-icons/react/dist/ssr/CaretDown";
12
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
+ import { ArrowCounterClockwiseIcon } from "@phosphor-icons/react/dist/ssr/ArrowCounterClockwise";
14
+ //#region packages/components/src/components/ChatRichContent/ChatRichContent.tsx
15
+ var containerClassName = "flex w-full min-w-0 flex-col gap-space-3 rounded-xl border border-subtle bg-elevated p-space-4 transition-colors duration-normal [overflow-wrap:anywhere] focus-within:border-focus motion-reduce:transition-none";
16
+ var stateMessages = {
17
+ unanswered: void 0,
18
+ submitting: "Submitting response…",
19
+ submitted: "Response submitted",
20
+ approved: "Approved",
21
+ rejected: "Rejected",
22
+ "submission-failed": "Could not submit your response.",
23
+ "validation-error": "Check your response.",
24
+ expired: "This request has expired.",
25
+ disabled: "Responding is unavailable.",
26
+ "read-only": "Read-only response"
27
+ };
28
+ function ChatRichContent(props) {
29
+ const { presentation = "block", open: openProp, defaultOpen = true, onOpenChange, title, description, state = "unanswered", message, children, className } = props;
30
+ const isDrawer = presentation === "drawer";
31
+ const Container = isDrawer ? "section" : "form";
32
+ const approval = props.variant === "approval" ? props : void 0;
33
+ const form = props.variant !== "approval" ? props : void 0;
34
+ const { onNext, onSkip, skipLabel = "Skip", hintLabel = children == null ? "Type your answer below" : "Or type your own answer below", navigation } = form ?? {};
35
+ const { onReject, onUndo, rejectLabel = "Reject", rejectionReason } = approval ?? {};
36
+ const submitAction = approval ? approval.onApprove : form?.onSubmit;
37
+ const id = useId();
38
+ const currentQuestion = navigation?.current ?? 1;
39
+ const [questionTransition, setQuestionTransition] = useState({
40
+ current: currentQuestion,
41
+ direction: 0
42
+ });
43
+ if (questionTransition.current !== currentQuestion) setQuestionTransition({
44
+ current: currentQuestion,
45
+ direction: currentQuestion > questionTransition.current ? 1 : -1
46
+ });
47
+ const questionAnimation = navigation && navigation.total > 1 && questionTransition.direction !== 0 && cn("duration-normal ease-out animate-in fade-in motion-reduce:animate-none", questionTransition.direction > 0 ? "slide-in-from-right-4" : "slide-in-from-left-4");
48
+ const submitGuard = useRef(false);
49
+ const [submission, setSubmission] = useState();
50
+ const [awaitingConfirmationFrom, setAwaitingConfirmationFrom] = useState();
51
+ useLayoutEffect(() => {
52
+ if (awaitingConfirmationFrom !== void 0 && state !== awaitingConfirmationFrom && state !== "submitting") {
53
+ submitGuard.current = false;
54
+ setSubmission(void 0);
55
+ setAwaitingConfirmationFrom(void 0);
56
+ }
57
+ }, [awaitingConfirmationFrom, state]);
58
+ const nextAction = state === "submission-failed" ? void 0 : onNext;
59
+ const editable = state === "unanswered" || state === "validation-error" || state === "submission-failed";
60
+ const pending = submission !== void 0;
61
+ const displayState = pending && editable ? "submitting" : state;
62
+ const hasDecision = state === "approved" || state === "rejected";
63
+ const readOnly = state === "submitted" || hasDecision || state === "read-only";
64
+ const composerDisabled = useContext(ChatComposerContext)?.disabled ?? false;
65
+ const actionsDisabled = !editable || pending || composerDisabled;
66
+ const disabled = actionsDisabled || !isDrawer && !nextAction && !submitAction && !onReject;
67
+ const submitDisabled = actionsDisabled || !nextAction && !submitAction;
68
+ const navigationDisabled = pending || composerDisabled || state === "submitting" || state === "disabled";
69
+ const isError = displayState === "submission-failed" || displayState === "validation-error";
70
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
71
+ const open = openProp ?? uncontrolledOpen;
72
+ const expanded = !isDrawer || isError || open;
73
+ const errorExpansionRequested = useRef(false);
74
+ useLayoutEffect(() => {
75
+ if (!isDrawer || !isError || open) {
76
+ errorExpansionRequested.current = false;
77
+ return;
78
+ }
79
+ if (errorExpansionRequested.current) return;
80
+ errorExpansionRequested.current = true;
81
+ setUncontrolledOpen(true);
82
+ onOpenChange?.(true);
83
+ }, [
84
+ isDrawer,
85
+ isError,
86
+ open,
87
+ onOpenChange
88
+ ]);
89
+ const statusMessage = submission === "skipping" && editable ? "Skipping question…" : submission === "rejecting" && displayState === "submitting" ? "Rejecting request…" : displayState === state ? message ?? stateMessages[state] : stateMessages[displayState];
90
+ const errorId = isError ? `${id}-status` : void 0;
91
+ const footerHint = isDrawer && form && !readOnly && !composerDisabled && !statusMessage ? hintLabel : void 0;
92
+ const canUndo = hasDecision && onUndo !== void 0;
93
+ const showFooter = Boolean(statusMessage || footerHint || canUndo || !readOnly && (!isDrawer || onSkip || onReject));
94
+ async function handleAction(callback, progress) {
95
+ if (!callback || submitGuard.current || (progress === "undoing" ? !hasDecision : !editable)) return;
96
+ submitGuard.current = true;
97
+ setSubmission(progress);
98
+ try {
99
+ await callback();
100
+ if (progress === "pending" || progress === "rejecting") setAwaitingConfirmationFrom(state);
101
+ else {
102
+ submitGuard.current = false;
103
+ setSubmission(void 0);
104
+ }
105
+ } catch {
106
+ submitGuard.current = false;
107
+ setSubmission(void 0);
108
+ }
109
+ }
110
+ function changeQuestion(current) {
111
+ if (!navigation || navigationDisabled || submitGuard.current || current < 1 || current > navigation.total) return;
112
+ navigation.onChange(current);
113
+ }
114
+ function renderSecondaryActions(size) {
115
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [onSkip && /* @__PURE__ */ jsx(Button, {
116
+ type: "button",
117
+ size,
118
+ color: "secondary",
119
+ variant: "plain",
120
+ disabled: actionsDisabled,
121
+ loading: submission === "skipping",
122
+ onClick: (event) => {
123
+ if (event.detail > 1) return;
124
+ handleAction(onSkip, "skipping");
125
+ },
126
+ children: skipLabel
127
+ }), onReject && /* @__PURE__ */ jsx(Button, {
128
+ type: "button",
129
+ size,
130
+ color: "secondary",
131
+ variant: "outlined",
132
+ disabled: actionsDisabled,
133
+ loading: submission === "rejecting",
134
+ onClick: () => {
135
+ handleAction(() => onReject(rejectionReason?.value ?? ""), "rejecting");
136
+ },
137
+ children: rejectLabel
138
+ })] });
139
+ }
140
+ function toggleOpen() {
141
+ const next = !expanded;
142
+ setUncontrolledOpen(next);
143
+ onOpenChange?.(next);
144
+ }
145
+ return /* @__PURE__ */ jsxs(Container, {
146
+ noValidate: isDrawer ? void 0 : true,
147
+ "aria-labelledby": `${id}-title`,
148
+ "aria-describedby": statusMessage ? `${id}-status` : void 0,
149
+ "aria-busy": pending || state === "submitting",
150
+ "data-state": displayState,
151
+ className: cn(containerClassName, isDrawer && "gap-0 rounded-none border-0 bg-transparent py-space-3", className),
152
+ onSubmit: isDrawer ? void 0 : (event) => {
153
+ event.preventDefault();
154
+ event.stopPropagation();
155
+ if (nextAction) {
156
+ if (!submitDisabled && !submitGuard.current) nextAction();
157
+ return;
158
+ }
159
+ handleAction(submitAction, "pending");
160
+ },
161
+ children: [/* @__PURE__ */ jsxs("div", {
162
+ className: "flex min-w-0 flex-col",
163
+ children: [/* @__PURE__ */ jsxs("div", {
164
+ className: cn("flex justify-between gap-space-2", expanded ? "items-start" : "items-center", !isDrawer && "flex-wrap"),
165
+ children: [
166
+ /* @__PURE__ */ jsx(Text, {
167
+ id: `${id}-title`,
168
+ variant: "sm",
169
+ weight: "semibold",
170
+ className: cn("min-w-0 flex-1", expanded ? "text-pretty" : "truncate", questionAnimation),
171
+ children: title
172
+ }, currentQuestion),
173
+ !expanded && statusMessage && /* @__PURE__ */ jsx(ChatRichContentStatus, {
174
+ id: `${id}-status`,
175
+ live: true,
176
+ compact: true,
177
+ state,
178
+ isError,
179
+ children: statusMessage
180
+ }),
181
+ !expanded && !statusMessage && !readOnly && (onSkip || onReject) && /* @__PURE__ */ jsx("div", {
182
+ className: "flex shrink-0 items-center gap-space-1",
183
+ children: renderSecondaryActions("xs")
184
+ }),
185
+ /* @__PURE__ */ jsxs("div", {
186
+ className: "flex h-[1lh] shrink-0 items-center gap-space-2 text-xs leading-tight empty:hidden",
187
+ children: [expanded && navigation && navigation.total > 1 && /* @__PURE__ */ jsx(ChatRichContentQuestionNav, {
188
+ title,
189
+ current: navigation.current,
190
+ total: navigation.total,
191
+ disabled: navigationDisabled,
192
+ onChange: changeQuestion
193
+ }), isDrawer && !isError && /* @__PURE__ */ jsx(IconButton, {
194
+ type: "button",
195
+ icon: CaretDownIcon,
196
+ iconWeight: "bold",
197
+ size: "xxs",
198
+ color: "secondary",
199
+ variant: "plain",
200
+ label: expanded ? "Collapse question" : "Expand question",
201
+ "aria-expanded": expanded,
202
+ "aria-controls": `${id}-body`,
203
+ className: cn("shrink-0 [&_svg]:transition-transform [&_svg]:duration-normal [&_svg]:ease-out motion-reduce:[&_svg]:transition-none", expanded && "[&_svg]:rotate-180"),
204
+ onClick: toggleOpen
205
+ })]
206
+ })
207
+ ]
208
+ }), description && /* @__PURE__ */ jsx(ChatRichContentCollapsible, {
209
+ open: expanded,
210
+ children: /* @__PURE__ */ jsx(Text, {
211
+ variant: "xs",
212
+ color: "tertiary",
213
+ className: cn("pt-space-1 text-pretty", questionAnimation),
214
+ children: description
215
+ }, currentQuestion)
216
+ })]
217
+ }), /* @__PURE__ */ jsxs(ChatRichContentCollapsible, {
218
+ id: `${id}-body`,
219
+ open: expanded,
220
+ disabled: !isDrawer,
221
+ className: cn(isDrawer && (children == null ? "pt-space-1" : "pt-space-4")),
222
+ children: [
223
+ children != null && /* @__PURE__ */ jsx("fieldset", {
224
+ disabled,
225
+ className: cn("m-0 flex min-w-0 flex-col gap-space-4 border-0 p-0", questionAnimation),
226
+ children: typeof children === "function" ? children({
227
+ disabled,
228
+ isError,
229
+ errorId
230
+ }) : children
231
+ }, currentQuestion),
232
+ rejectionReason && state !== "submitted" && state !== "approved" && (!readOnly || rejectionReason.value) && /* @__PURE__ */ jsx(Textarea, {
233
+ label: readOnly ? "Rejection Reason" : "Rejection Reason (Optional)",
234
+ placeholder: "What should the agent change?",
235
+ size: "md",
236
+ rows: 2,
237
+ resize: "vertical",
238
+ value: rejectionReason.value,
239
+ onChange: rejectionReason.onChange,
240
+ disabled: actionsDisabled || !onReject,
241
+ isError,
242
+ "aria-describedby": errorId
243
+ }),
244
+ showFooter && /* @__PURE__ */ jsxs("div", {
245
+ className: "flex flex-wrap items-center justify-end gap-space-2",
246
+ children: [
247
+ canUndo && /* @__PURE__ */ jsx(Button, {
248
+ type: "button",
249
+ size: "sm",
250
+ color: "secondary",
251
+ variant: "plain",
252
+ leftDecorator: ArrowCounterClockwiseIcon,
253
+ className: "mr-auto",
254
+ disabled: pending || composerDisabled,
255
+ loading: submission === "undoing",
256
+ onClick: () => {
257
+ handleAction(onUndo, "undoing");
258
+ },
259
+ children: "Undo"
260
+ }),
261
+ footerHint && /* @__PURE__ */ jsx(Text, {
262
+ variant: "xs",
263
+ color: "tertiary",
264
+ className: "min-w-0 flex-1 text-pretty",
265
+ children: footerHint
266
+ }),
267
+ statusMessage && /* @__PURE__ */ jsx(ChatRichContentStatus, {
268
+ id: `${id}-status`,
269
+ live: expanded,
270
+ compact: false,
271
+ state,
272
+ isError,
273
+ children: statusMessage
274
+ }),
275
+ !readOnly && renderSecondaryActions("sm"),
276
+ !readOnly && !isDrawer && /* @__PURE__ */ jsx(Button, {
277
+ type: "submit",
278
+ size: "sm",
279
+ color: "primary",
280
+ variant: nextAction || approval ? "outlined" : "normal",
281
+ disabled: submitDisabled,
282
+ onClick: (event) => {
283
+ if (event.detail > 1) event.preventDefault();
284
+ },
285
+ loading: displayState === "submitting" && submission !== "skipping" && submission !== "rejecting",
286
+ children: nextAction ? "Next" : approval ? approval.approveLabel ?? "Approve" : state === "submission-failed" ? "Retry response" : form?.submitLabel ?? "Submit response"
287
+ })
288
+ ]
289
+ })
290
+ ]
291
+ })]
292
+ });
293
+ }
294
+ /** Use after the host adapter rejects a block. Inert unless the host supplies actions. */
295
+ function ChatRichContentFallback({ actions }) {
296
+ return /* @__PURE__ */ jsx("div", {
297
+ className: containerClassName,
298
+ children: /* @__PURE__ */ jsxs("div", {
299
+ className: "flex flex-wrap items-center gap-space-2",
300
+ children: [/* @__PURE__ */ jsx(Text, {
301
+ variant: "sm",
302
+ color: "secondary",
303
+ className: "min-w-0 flex-1",
304
+ children: "This content is unavailable."
305
+ }), actions != null && /* @__PURE__ */ jsx("div", {
306
+ className: "flex flex-wrap items-center justify-end gap-space-2",
307
+ children: actions
308
+ })]
309
+ })
310
+ });
311
+ }
312
+ //#endregion
313
+ export { ChatRichContent, ChatRichContentFallback };
314
+
315
+ //# sourceMappingURL=ChatRichContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatRichContent.js","names":[],"sources":["../../../src/components/ChatRichContent/ChatRichContent.tsx"],"sourcesContent":["import { useContext, useId, useLayoutEffect, useRef, useState } from 'react';\n\nimport { ArrowCounterClockwiseIcon } from '@phosphor-icons/react/dist/ssr/ArrowCounterClockwise';\nimport { CaretDownIcon } from '@phosphor-icons/react/dist/ssr/CaretDown';\n\nimport { cn } from '../../utils/cn';\nimport { Button } from '../Button';\nimport { ChatComposerContext } from '../ChatComposer/ChatComposerContext';\nimport { IconButton } from '../IconButton';\nimport { Text } from '../Text';\nimport { Textarea } from '../Textarea';\nimport type {\n ChatRichContentFallbackProps,\n ChatRichContentProps,\n ChatRichContentState,\n} from './ChatRichContent.types';\nimport { ChatRichContentCollapsible } from './ChatRichContentCollapsible';\nimport { ChatRichContentQuestionNav } from './ChatRichContentQuestionNav';\nimport { ChatRichContentStatus } from './ChatRichContentStatus';\n\nconst containerClassName =\n 'flex w-full min-w-0 flex-col gap-space-3 rounded-xl border border-subtle bg-elevated p-space-4 transition-colors duration-normal [overflow-wrap:anywhere] focus-within:border-focus motion-reduce:transition-none';\n\nconst stateMessages: Record<ChatRichContentState, string | undefined> = {\n unanswered: undefined,\n submitting: 'Submitting response…',\n submitted: 'Response submitted',\n approved: 'Approved',\n rejected: 'Rejected',\n 'submission-failed': 'Could not submit your response.',\n 'validation-error': 'Check your response.',\n expired: 'This request has expired.',\n disabled: 'Responding is unavailable.',\n 'read-only': 'Read-only response',\n};\n\nexport function ChatRichContent(props: ChatRichContentProps) {\n const {\n presentation = 'block',\n open: openProp,\n defaultOpen = true,\n onOpenChange,\n title,\n description,\n state = 'unanswered',\n message,\n children,\n className,\n } = props;\n const isDrawer = presentation === 'drawer';\n const Container = isDrawer ? 'section' : 'form';\n const approval = props.variant === 'approval' ? props : undefined;\n const form = props.variant !== 'approval' ? props : undefined;\n const {\n onNext,\n onSkip,\n skipLabel = 'Skip',\n hintLabel = children == null\n ? 'Type your answer below'\n : 'Or type your own answer below',\n navigation,\n } = form ?? {};\n const {\n onReject,\n onUndo,\n rejectLabel = 'Reject',\n rejectionReason,\n } = approval ?? {};\n const submitAction = approval ? approval.onApprove : form?.onSubmit;\n const id = useId();\n const currentQuestion = navigation?.current ?? 1;\n const [questionTransition, setQuestionTransition] = useState({\n current: currentQuestion,\n direction: 0,\n });\n if (questionTransition.current !== currentQuestion) {\n setQuestionTransition({\n current: currentQuestion,\n direction: currentQuestion > questionTransition.current ? 1 : -1,\n });\n }\n const questionAnimation =\n navigation &&\n navigation.total > 1 &&\n questionTransition.direction !== 0 &&\n cn(\n 'duration-normal ease-out animate-in fade-in motion-reduce:animate-none',\n questionTransition.direction > 0\n ? 'slide-in-from-right-4'\n : 'slide-in-from-left-4'\n );\n const submitGuard = useRef(false);\n const [submission, setSubmission] = useState<\n 'pending' | 'rejecting' | 'skipping' | 'undoing'\n >();\n const [awaitingConfirmationFrom, setAwaitingConfirmationFrom] =\n useState<ChatRichContentState>();\n useLayoutEffect(() => {\n if (\n awaitingConfirmationFrom !== undefined &&\n state !== awaitingConfirmationFrom &&\n state !== 'submitting'\n ) {\n submitGuard.current = false;\n setSubmission(undefined);\n setAwaitingConfirmationFrom(undefined);\n }\n }, [awaitingConfirmationFrom, state]);\n const nextAction = state === 'submission-failed' ? undefined : onNext;\n const editable =\n state === 'unanswered' ||\n state === 'validation-error' ||\n state === 'submission-failed';\n const pending = submission !== undefined;\n const displayState = pending && editable ? 'submitting' : state;\n const hasDecision = state === 'approved' || state === 'rejected';\n const readOnly =\n state === 'submitted' || hasDecision || state === 'read-only';\n const composerDisabled = useContext(ChatComposerContext)?.disabled ?? false;\n const actionsDisabled = !editable || pending || composerDisabled;\n const disabled =\n actionsDisabled || (!isDrawer && !nextAction && !submitAction && !onReject);\n const submitDisabled = actionsDisabled || (!nextAction && !submitAction);\n const navigationDisabled =\n pending ||\n composerDisabled ||\n state === 'submitting' ||\n state === 'disabled';\n const isError =\n displayState === 'submission-failed' || displayState === 'validation-error';\n const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n const open = openProp ?? uncontrolledOpen;\n // Errors stay visible so a collapsed drawer cannot hide why submission failed.\n const expanded = !isDrawer || isError || open;\n const errorExpansionRequested = useRef(false);\n // Stay open once the error clears so the choices remain while the answer is fixed.\n useLayoutEffect(() => {\n if (!isDrawer || !isError || open) {\n errorExpansionRequested.current = false;\n return;\n }\n // A controlled host may decline this request. Do not notify it again on\n // every render (including renders caused by its own onOpenChange handler).\n if (errorExpansionRequested.current) return;\n errorExpansionRequested.current = true;\n setUncontrolledOpen(true);\n onOpenChange?.(true);\n }, [isDrawer, isError, open, onOpenChange]);\n const statusMessage =\n submission === 'skipping' && editable\n ? 'Skipping question…'\n : submission === 'rejecting' && displayState === 'submitting'\n ? 'Rejecting request…'\n : displayState === state\n ? (message ?? stateMessages[state])\n : stateMessages[displayState];\n const errorId = isError ? `${id}-status` : undefined;\n // The composer below owns the answer in a drawer, so the footer says so\n // beside Skip; status feedback takes its place.\n const footerHint =\n isDrawer && form && !readOnly && !composerDisabled && !statusMessage\n ? hintLabel\n : undefined;\n const canUndo = hasDecision && onUndo !== undefined;\n // Block cards always render a submit button; drawers only render Skip/Reject.\n const hasFooterActions = !readOnly && (!isDrawer || onSkip || onReject);\n const showFooter = Boolean(\n statusMessage || footerHint || canUndo || hasFooterActions\n );\n\n async function handleAction(\n callback: (() => void | Promise<void>) | undefined,\n progress: 'pending' | 'rejecting' | 'skipping' | 'undoing'\n ) {\n if (\n !callback ||\n submitGuard.current ||\n (progress === 'undoing' ? !hasDecision : !editable)\n )\n return;\n // Guard synchronously; Enter and click may arrive before React rerenders.\n submitGuard.current = true;\n setSubmission(progress);\n try {\n await callback();\n if (progress === 'pending' || progress === 'rejecting') {\n // A retry's existing error is not confirmation of this attempt.\n setAwaitingConfirmationFrom(state);\n } else {\n submitGuard.current = false;\n setSubmission(undefined);\n }\n } catch {\n // The host supplies the validation/failure state and preserves its draft.\n submitGuard.current = false;\n setSubmission(undefined);\n }\n }\n\n function changeQuestion(current: number) {\n if (\n !navigation ||\n navigationDisabled ||\n submitGuard.current ||\n current < 1 ||\n current > navigation.total\n )\n return;\n navigation.onChange(current);\n }\n\n function renderSecondaryActions(size: 'xs' | 'sm') {\n return (\n <>\n {onSkip && (\n <Button\n type=\"button\"\n size={size}\n color=\"secondary\"\n variant=\"plain\"\n disabled={actionsDisabled}\n loading={submission === 'skipping'}\n onClick={(event) => {\n if (event.detail > 1) return;\n void handleAction(onSkip, 'skipping');\n }}\n >\n {skipLabel}\n </Button>\n )}\n {onReject && (\n <Button\n type=\"button\"\n size={size}\n color=\"secondary\"\n variant=\"outlined\"\n disabled={actionsDisabled}\n loading={submission === 'rejecting'}\n onClick={() => {\n void handleAction(\n () => onReject(rejectionReason?.value ?? ''),\n 'rejecting'\n );\n }}\n >\n {rejectLabel}\n </Button>\n )}\n </>\n );\n }\n\n function toggleOpen() {\n const next = !expanded;\n setUncontrolledOpen(next);\n onOpenChange?.(next);\n }\n\n return (\n <Container\n noValidate={isDrawer ? undefined : true}\n aria-labelledby={`${id}-title`}\n aria-describedby={statusMessage ? `${id}-status` : undefined}\n aria-busy={pending || state === 'submitting'}\n data-state={displayState}\n className={cn(\n containerClassName,\n isDrawer && 'gap-0 rounded-none border-0 bg-transparent py-space-3',\n className\n )}\n onSubmit={\n isDrawer\n ? undefined\n : (event) => {\n event.preventDefault();\n event.stopPropagation();\n if (nextAction) {\n if (!submitDisabled && !submitGuard.current) nextAction();\n return;\n }\n void handleAction(submitAction, 'pending');\n }\n }\n >\n <div className=\"flex min-w-0 flex-col\">\n <div\n className={cn(\n 'flex justify-between gap-space-2',\n expanded ? 'items-start' : 'items-center',\n !isDrawer && 'flex-wrap'\n )}\n >\n <Text\n key={currentQuestion}\n id={`${id}-title`}\n variant=\"sm\"\n weight=\"semibold\"\n className={cn(\n 'min-w-0 flex-1',\n expanded ? 'text-pretty' : 'truncate',\n questionAnimation\n )}\n >\n {title}\n </Text>\n {/* A collapsed drawer keeps its status in the header. */}\n {!expanded && statusMessage && (\n <ChatRichContentStatus\n id={`${id}-status`}\n live\n compact\n state={state}\n isError={isError}\n >\n {statusMessage}\n </ChatRichContentStatus>\n )}\n {!expanded && !statusMessage && !readOnly && (onSkip || onReject) && (\n <div className=\"flex shrink-0 items-center gap-space-1\">\n {renderSecondaryActions('xs')}\n </div>\n )}\n {/* One title line tall (same text classes as Text sm) so controls\n center on the title's first line when it wraps. */}\n <div className=\"flex h-[1lh] shrink-0 items-center gap-space-2 text-xs leading-tight empty:hidden\">\n {expanded && navigation && navigation.total > 1 && (\n <ChatRichContentQuestionNav\n title={title}\n current={navigation.current}\n total={navigation.total}\n disabled={navigationDisabled}\n onChange={changeQuestion}\n />\n )}\n {/* Errors force the drawer open, so there is nothing to toggle. */}\n {isDrawer && !isError && (\n <IconButton\n type=\"button\"\n icon={CaretDownIcon}\n // Heavier than the pager's carets so the two controls read apart.\n iconWeight=\"bold\"\n size=\"xxs\"\n color=\"secondary\"\n variant=\"plain\"\n label={expanded ? 'Collapse question' : 'Expand question'}\n aria-expanded={expanded}\n aria-controls={`${id}-body`}\n className={cn(\n 'shrink-0 [&_svg]:transition-transform [&_svg]:duration-normal [&_svg]:ease-out motion-reduce:[&_svg]:transition-none',\n expanded && '[&_svg]:rotate-180'\n )}\n onClick={toggleOpen}\n />\n )}\n </div>\n </div>\n {description && (\n <ChatRichContentCollapsible open={expanded}>\n <Text\n key={currentQuestion}\n variant=\"xs\"\n color=\"tertiary\"\n className={cn('pt-space-1 text-pretty', questionAnimation)}\n >\n {description}\n </Text>\n </ChatRichContentCollapsible>\n )}\n </div>\n <ChatRichContentCollapsible\n id={`${id}-body`}\n open={expanded}\n disabled={!isDrawer}\n className={cn(\n isDrawer && (children == null ? 'pt-space-1' : 'pt-space-4')\n )}\n >\n {children != null && (\n <fieldset\n key={currentQuestion}\n disabled={disabled}\n className={cn(\n 'm-0 flex min-w-0 flex-col gap-space-4 border-0 p-0',\n questionAnimation\n )}\n >\n {typeof children === 'function'\n ? children({ disabled, isError, errorId })\n : children}\n </fieldset>\n )}\n {rejectionReason &&\n state !== 'submitted' &&\n state !== 'approved' &&\n (!readOnly || rejectionReason.value) && (\n <Textarea\n label={\n readOnly ? 'Rejection Reason' : 'Rejection Reason (Optional)'\n }\n placeholder=\"What should the agent change?\"\n size=\"md\"\n rows={2}\n resize=\"vertical\"\n value={rejectionReason.value}\n onChange={rejectionReason.onChange}\n disabled={actionsDisabled || !onReject}\n isError={isError}\n aria-describedby={errorId}\n />\n )}\n {showFooter && (\n <div className=\"flex flex-wrap items-center justify-end gap-space-2\">\n {canUndo && (\n <Button\n type=\"button\"\n size=\"sm\"\n color=\"secondary\"\n variant=\"plain\"\n leftDecorator={ArrowCounterClockwiseIcon}\n className=\"mr-auto\"\n disabled={pending || composerDisabled}\n loading={submission === 'undoing'}\n onClick={() => {\n void handleAction(onUndo, 'undoing');\n }}\n >\n Undo\n </Button>\n )}\n {footerHint && (\n <Text\n variant=\"xs\"\n color=\"tertiary\"\n className=\"min-w-0 flex-1 text-pretty\"\n >\n {footerHint}\n </Text>\n )}\n {/* Stays mounted while collapsed so the body height animates. */}\n {statusMessage && (\n <ChatRichContentStatus\n id={`${id}-status`}\n live={expanded}\n compact={false}\n state={state}\n isError={isError}\n >\n {statusMessage}\n </ChatRichContentStatus>\n )}\n {!readOnly && renderSecondaryActions('sm')}\n {!readOnly && !isDrawer && (\n <Button\n type=\"submit\"\n size=\"sm\"\n color=\"primary\"\n variant={nextAction || approval ? 'outlined' : 'normal'}\n disabled={submitDisabled}\n onClick={(event) => {\n if (event.detail > 1) event.preventDefault();\n }}\n loading={\n displayState === 'submitting' &&\n submission !== 'skipping' &&\n submission !== 'rejecting'\n }\n >\n {nextAction\n ? 'Next'\n : approval\n ? (approval.approveLabel ?? 'Approve')\n : state === 'submission-failed'\n ? 'Retry response'\n : (form?.submitLabel ?? 'Submit response')}\n </Button>\n )}\n </div>\n )}\n </ChatRichContentCollapsible>\n </Container>\n );\n}\n\n/** Use after the host adapter rejects a block. Inert unless the host supplies actions. */\nexport function ChatRichContentFallback({\n actions,\n}: ChatRichContentFallbackProps) {\n return (\n <div className={containerClassName}>\n <div className=\"flex flex-wrap items-center gap-space-2\">\n <Text variant=\"sm\" color=\"secondary\" className=\"min-w-0 flex-1\">\n This content is unavailable.\n </Text>\n {actions != null && (\n <div className=\"flex flex-wrap items-center justify-end gap-space-2\">\n {actions}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAM,qBACJ;AAEF,IAAM,gBAAkE;CACtE,YAAY,KAAA;CACZ,YAAY;CACZ,WAAW;CACX,UAAU;CACV,UAAU;CACV,qBAAqB;CACrB,oBAAoB;CACpB,SAAS;CACT,UAAU;CACV,aAAa;AACf;AAEA,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,EACJ,eAAe,SACf,MAAM,UACN,cAAc,MACd,cACA,OACA,aACA,QAAQ,cACR,SACA,UACA,cACE;CACJ,MAAM,WAAW,iBAAiB;CAClC,MAAM,YAAY,WAAW,YAAY;CACzC,MAAM,WAAW,MAAM,YAAY,aAAa,QAAQ,KAAA;CACxD,MAAM,OAAO,MAAM,YAAY,aAAa,QAAQ,KAAA;CACpD,MAAM,EACJ,QACA,QACA,YAAY,QACZ,YAAY,YAAY,OACpB,2BACA,iCACJ,eACE,QAAQ,CAAC;CACb,MAAM,EACJ,UACA,QACA,cAAc,UACd,oBACE,YAAY,CAAC;CACjB,MAAM,eAAe,WAAW,SAAS,YAAY,MAAM;CAC3D,MAAM,KAAK,MAAM;CACjB,MAAM,kBAAkB,YAAY,WAAW;CAC/C,MAAM,CAAC,oBAAoB,yBAAyB,SAAS;EAC3D,SAAS;EACT,WAAW;CACb,CAAC;CACD,IAAI,mBAAmB,YAAY,iBACjC,sBAAsB;EACpB,SAAS;EACT,WAAW,kBAAkB,mBAAmB,UAAU,IAAI;CAChE,CAAC;CAEH,MAAM,oBACJ,cACA,WAAW,QAAQ,KACnB,mBAAmB,cAAc,KACjC,GACE,0EACA,mBAAmB,YAAY,IAC3B,0BACA,sBACN;CACF,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,CAAC,YAAY,iBAAiB,SAElC;CACF,MAAM,CAAC,0BAA0B,+BAC/B,SAA+B;CACjC,sBAAsB;EACpB,IACE,6BAA6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C,YACb,oBAAC,QAAD;OACE,MAAK;OACL,MAAK;OACL,OAAM;OACN,SAAS,cAAc,WAAW,aAAa;OAC/C,UAAU;OACV,UAAU,UAAU;QAClB,IAAI,MAAM,SAAS,GAAG,MAAM,eAAe;OAC7C;OACA,SACE,iBAAiB,gBACjB,eAAe,cACf,eAAe;OAGhB,UAAA,aACG,SACA,WACG,SAAS,gBAAgB,YAC1B,UAAU,sBACR,mBACC,MAAM,eAAe;MACxB,CAAA;KAEP;;GAEmB;EACnB,CAAA,CAAA;;AAEf;;AAGA,SAAgB,wBAAwB,EACtC,WAC+B;CAC/B,OACE,oBAAC,OAAD;EAAK,WAAW;EACd,UAAA,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,oBAAC,MAAD;IAAM,SAAQ;IAAK,OAAM;IAAY,WAAU;IAAiB,UAAA;GAE1D,CAAA,GACL,WAAW,QACV,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,CAEJ;;CACF,CAAA;AAET"}
@@ -0,0 +1,101 @@
1
+ import type { ReactNode } from 'react';
2
+ export type ChatRichContentState = 'unanswered' | 'submitting' | 'submitted' | 'approved' | 'rejected' | 'submission-failed' | 'validation-error' | 'expired' | 'disabled' | 'read-only';
3
+ export interface ChatRichContentRendererContext {
4
+ disabled: boolean;
5
+ /** The host focuses the invalid field after a failed submit. */
6
+ isError: boolean;
7
+ /** The status message's id while invalid; pass to the field's `aria-describedby`. */
8
+ errorId?: string;
9
+ }
10
+ /** Render-prop children that connect custom controls to the card state. */
11
+ export type ChatRichContentRenderer = (context: ChatRichContentRendererContext) => ReactNode;
12
+ export interface ChatRichContentNavigation {
13
+ /** One-based position; keep the container mounted and preserve values when switching. */
14
+ current: number;
15
+ total: number;
16
+ onChange: (current: number) => void;
17
+ }
18
+ interface ChatRichContentBaseProps {
19
+ /** Drawer content belongs in ChatComposer's drawer slot; the composer owns submission. */
20
+ presentation?: 'block' | 'drawer';
21
+ /** Drawer only. Collapsing keeps the title visible; errors always expand. */
22
+ open?: boolean;
23
+ defaultOpen?: boolean;
24
+ onOpenChange?: (open: boolean) => void;
25
+ title: string;
26
+ description?: string;
27
+ /**
28
+ * Decisions stay pending until state changes from the attempt's starting state,
29
+ * excluding submitting. Throw from the callback when a retry fails with the same
30
+ * error state. Set unanswered after confirmation to reopen; key by request ID
31
+ * for a new request.
32
+ */
33
+ state?: ChatRichContentState;
34
+ /** Host-provided validation, failure, or availability explanation. */
35
+ message?: string;
36
+ children?: ReactNode | ChatRichContentRenderer;
37
+ className?: string;
38
+ }
39
+ interface ChatRichContentFormProps extends ChatRichContentBaseProps {
40
+ variant?: 'form';
41
+ submitLabel?: string;
42
+ skipLabel?: string;
43
+ /** Drawer-only guidance beside the footer actions that points at the composer below. */
44
+ hintLabel?: string;
45
+ /** Shows Next instead of Submit; the host validates and advances without accepting answers. */
46
+ onNext?: () => void;
47
+ /** The host saves the response and sets submitted or an error state. */
48
+ onSubmit?: () => void | Promise<void>;
49
+ /** Advances or marks skipped without accepting the response; set read-only state for a final skip. */
50
+ onSkip?: () => void | Promise<void>;
51
+ navigation?: ChatRichContentNavigation;
52
+ }
53
+ interface ChatRichContentApprovalProps extends ChatRichContentBaseProps {
54
+ variant: 'approval';
55
+ approveLabel?: string;
56
+ rejectLabel?: string;
57
+ /** The host saves the decision and sets approved or an error state. */
58
+ onApprove?: () => void | Promise<void>;
59
+ /** Receives the reason unchanged, or an empty string. The host saves and sets rejected or an error state. */
60
+ onReject?: (reason: string) => void | Promise<void>;
61
+ /** Set unanswered after undo succeeds; preserve the decision and show a message on failure. */
62
+ onUndo?: () => void | Promise<void>;
63
+ /** Opt into a reason field within the card; the host owns the draft and any validation. */
64
+ rejectionReason?: {
65
+ value: string;
66
+ onChange: (value: string) => void;
67
+ };
68
+ }
69
+ export type ChatRichContentProps = ChatRichContentFormProps | ChatRichContentApprovalProps;
70
+ export interface ChatRichContentFallbackProps {
71
+ /** Optional recovery controls; the host decides whether reloading or skipping is available. */
72
+ actions?: ReactNode;
73
+ }
74
+ export interface ChatRichContentChoicesValue {
75
+ /** At most one option in single-choice mode. */
76
+ selected: string[];
77
+ /** Keep deselected text as a draft; the host excludes it from submission. */
78
+ custom?: {
79
+ selected: boolean;
80
+ text: string;
81
+ };
82
+ }
83
+ export interface ChatRichContentChoicesProps {
84
+ mode: 'single' | 'multiple';
85
+ options: {
86
+ value: string;
87
+ label: string;
88
+ }[];
89
+ value: ChatRichContentChoicesValue;
90
+ onChange: (value: ChatRichContentChoicesValue) => void;
91
+ 'aria-label': string;
92
+ /** Typically the renderer context's `errorId`. */
93
+ 'aria-describedby'?: string;
94
+ allowCustom?: boolean;
95
+ /** External entry keeps the custom option but lets the host supply its editor. */
96
+ customInput?: 'inline' | 'external';
97
+ onCustomSelect?: () => void;
98
+ disabled?: boolean;
99
+ isError?: boolean;
100
+ }
101
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { ChatRichContentChoicesProps } from './ChatRichContent.types.js';
2
+ export declare function ChatRichContentChoices({ mode, options, value, onChange, 'aria-label': label, 'aria-describedby': describedBy, allowCustom, customInput, onCustomSelect, disabled, isError, }: ChatRichContentChoicesProps): import("react").JSX.Element;
@@ -0,0 +1,121 @@
1
+ import { Checkbox } from "../Checkbox/Checkbox.js";
2
+ import { Input } from "../Input/Input.js";
3
+ import { RadioButton } from "../RadioButton/RadioButton.js";
4
+ import { RadioGroup } from "../RadioGroup/RadioGroup.js";
5
+ import { useRef } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ //#region packages/components/src/components/ChatRichContent/ChatRichContentChoices.tsx
8
+ function ChatRichContentChoices({ mode, options, value, onChange, "aria-label": label, "aria-describedby": describedBy, allowCustom = false, customInput = "inline", onCustomSelect, disabled = false, isError = false }) {
9
+ const focusCustomInput = useRef(false);
10
+ const customSelected = allowCustom && value.custom?.selected === true;
11
+ function selectCustom(selected) {
12
+ if (disabled) return;
13
+ focusCustomInput.current = customInput === "inline" && selected && !customSelected;
14
+ onChange({
15
+ selected: mode === "single" ? [] : value.selected,
16
+ custom: {
17
+ selected,
18
+ text: value.custom?.text ?? ""
19
+ }
20
+ });
21
+ if (selected) onCustomSelect?.();
22
+ }
23
+ const showCustomInput = customSelected && customInput === "inline";
24
+ const customLabelProps = showCustomInput ? { "aria-label": "Something else…" } : { label: "Something else…" };
25
+ const customTextInput = showCustomInput && /* @__PURE__ */ jsx(Input, {
26
+ ref: (element) => {
27
+ if (element && focusCustomInput.current && !disabled) {
28
+ element.focus();
29
+ focusCustomInput.current = false;
30
+ }
31
+ },
32
+ "aria-label": `${label} — Something else`,
33
+ "aria-describedby": describedBy,
34
+ placeholder: "Something else…",
35
+ size: "sm",
36
+ variant: "plain",
37
+ className: "min-w-0 flex-1",
38
+ debounceMs: 0,
39
+ disabled,
40
+ isError,
41
+ value: value.custom?.text ?? "",
42
+ onChange: (text) => {
43
+ if (disabled) return;
44
+ onChange({
45
+ ...value,
46
+ custom: {
47
+ selected: true,
48
+ text
49
+ }
50
+ });
51
+ }
52
+ });
53
+ return mode === "single" ? /* @__PURE__ */ jsxs(RadioGroup, {
54
+ "aria-label": label,
55
+ "aria-describedby": describedBy,
56
+ "aria-invalid": isError || void 0,
57
+ disabled,
58
+ className: "flex flex-col gap-space-1",
59
+ value: customSelected ? "custom" : value.selected[0] === void 0 ? "" : `option:${value.selected[0]}`,
60
+ onValueChange: (next) => {
61
+ if (disabled) return;
62
+ if (next === "custom") {
63
+ selectCustom(true);
64
+ return;
65
+ }
66
+ focusCustomInput.current = false;
67
+ onChange({
68
+ selected: [next.slice(7)],
69
+ ...value.custom && { custom: {
70
+ ...value.custom,
71
+ selected: false
72
+ } }
73
+ });
74
+ },
75
+ children: [options.map((option) => /* @__PURE__ */ jsx(RadioButton, {
76
+ value: `option:${option.value}`,
77
+ label: option.label,
78
+ disabled,
79
+ className: "min-h-6"
80
+ }, option.value)), allowCustom && /* @__PURE__ */ jsxs("div", {
81
+ className: "flex min-h-6 min-w-0 items-center gap-space-2",
82
+ children: [/* @__PURE__ */ jsx(RadioButton, {
83
+ value: "custom",
84
+ ...customLabelProps,
85
+ disabled
86
+ }), customTextInput]
87
+ })]
88
+ }) : /* @__PURE__ */ jsxs("div", {
89
+ role: "group",
90
+ "aria-label": label,
91
+ "aria-describedby": describedBy,
92
+ className: "flex flex-col gap-space-1",
93
+ children: [options.map((option) => /* @__PURE__ */ jsx(Checkbox, {
94
+ label: option.label,
95
+ checked: value.selected.includes(option.value),
96
+ "aria-invalid": isError || void 0,
97
+ disabled,
98
+ containerClassName: "min-h-6",
99
+ onCheckedChange: (checked) => {
100
+ if (disabled) return;
101
+ onChange({
102
+ ...value,
103
+ selected: checked === true ? [...value.selected, option.value] : value.selected.filter((item) => item !== option.value)
104
+ });
105
+ }
106
+ }, option.value)), allowCustom && /* @__PURE__ */ jsxs("div", {
107
+ className: "flex min-h-6 min-w-0 items-center gap-space-2",
108
+ children: [/* @__PURE__ */ jsx(Checkbox, {
109
+ ...customLabelProps,
110
+ checked: customSelected,
111
+ "aria-invalid": isError || void 0,
112
+ disabled,
113
+ onCheckedChange: (checked) => selectCustom(checked === true)
114
+ }), customTextInput]
115
+ })]
116
+ });
117
+ }
118
+ //#endregion
119
+ export { ChatRichContentChoices };
120
+
121
+ //# sourceMappingURL=ChatRichContentChoices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatRichContentChoices.js","names":[],"sources":["../../../src/components/ChatRichContent/ChatRichContentChoices.tsx"],"sourcesContent":["import { useRef } from 'react';\n\nimport { Checkbox } from '../Checkbox';\nimport { Input } from '../Input';\nimport { RadioButton } from '../RadioButton';\nimport { RadioGroup } from '../RadioGroup';\nimport type { ChatRichContentChoicesProps } from './ChatRichContent.types';\n\nexport function ChatRichContentChoices({\n mode,\n options,\n value,\n onChange,\n 'aria-label': label,\n 'aria-describedby': describedBy,\n allowCustom = false,\n customInput = 'inline',\n onCustomSelect,\n disabled = false,\n isError = false,\n}: ChatRichContentChoicesProps) {\n const focusCustomInput = useRef(false);\n const customSelected = allowCustom && value.custom?.selected === true;\n\n function selectCustom(selected: boolean) {\n if (disabled) return;\n focusCustomInput.current =\n customInput === 'inline' && selected && !customSelected;\n onChange({\n selected: mode === 'single' ? [] : value.selected,\n custom: { selected, text: value.custom?.text ?? '' },\n });\n if (selected) onCustomSelect?.();\n }\n\n const showCustomInput = customSelected && customInput === 'inline';\n const customLabelProps = showCustomInput\n ? { 'aria-label': 'Something else…' }\n : { label: 'Something else…' };\n const customTextInput = showCustomInput && (\n <Input\n ref={(element) => {\n if (element && focusCustomInput.current && !disabled) {\n element.focus();\n focusCustomInput.current = false;\n }\n }}\n aria-label={`${label} — Something else`}\n aria-describedby={describedBy}\n placeholder=\"Something else…\"\n size=\"sm\"\n variant=\"plain\"\n className=\"min-w-0 flex-1\"\n debounceMs={0}\n disabled={disabled}\n isError={isError}\n value={value.custom?.text ?? ''}\n onChange={(text) => {\n if (disabled) return;\n onChange({ ...value, custom: { selected: true, text } });\n }}\n />\n );\n\n return mode === 'single' ? (\n <RadioGroup\n aria-label={label}\n aria-describedby={describedBy}\n aria-invalid={isError || undefined}\n disabled={disabled}\n className=\"flex flex-col gap-space-1\"\n value={\n customSelected\n ? 'custom'\n : value.selected[0] === undefined\n ? ''\n : `option:${value.selected[0]}`\n }\n onValueChange={(next) => {\n if (disabled) return;\n if (next === 'custom') {\n selectCustom(true);\n return;\n }\n focusCustomInput.current = false;\n onChange({\n selected: [next.slice('option:'.length)],\n ...(value.custom && {\n custom: { ...value.custom, selected: false },\n }),\n });\n }}\n >\n {options.map((option) => (\n <RadioButton\n key={option.value}\n value={`option:${option.value}`}\n label={option.label}\n disabled={disabled}\n className=\"min-h-6\"\n />\n ))}\n {allowCustom && (\n <div className=\"flex min-h-6 min-w-0 items-center gap-space-2\">\n <RadioButton\n value=\"custom\"\n {...customLabelProps}\n disabled={disabled}\n />\n {customTextInput}\n </div>\n )}\n </RadioGroup>\n ) : (\n <div\n role=\"group\"\n aria-label={label}\n aria-describedby={describedBy}\n className=\"flex flex-col gap-space-1\"\n >\n {options.map((option) => (\n <Checkbox\n key={option.value}\n label={option.label}\n checked={value.selected.includes(option.value)}\n aria-invalid={isError || undefined}\n disabled={disabled}\n containerClassName=\"min-h-6\"\n onCheckedChange={(checked) => {\n if (disabled) return;\n onChange({\n ...value,\n selected:\n checked === true\n ? [...value.selected, option.value]\n : value.selected.filter((item) => item !== option.value),\n });\n }}\n />\n ))}\n {allowCustom && (\n <div className=\"flex min-h-6 min-w-0 items-center gap-space-2\">\n <Checkbox\n {...customLabelProps}\n checked={customSelected}\n aria-invalid={isError || undefined}\n disabled={disabled}\n onCheckedChange={(checked) => selectCustom(checked === true)}\n />\n {customTextInput}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,uBAAuB,EACrC,MACA,SACA,OACA,UACA,cAAc,OACd,oBAAoB,aACpB,cAAc,OACd,cAAc,UACd,gBACA,WAAW,OACX,UAAU,SACoB;CAC9B,MAAM,mBAAmB,OAAO,KAAK;CACrC,MAAM,iBAAiB,eAAe,MAAM,QAAQ,aAAa;CAEjE,SAAS,aAAa,UAAmB;EACvC,IAAI,UAAU;EACd,iBAAiB,UACf,gBAAgB,YAAY,YAAY,CAAC;EAC3C,SAAS;GACP,UAAU,SAAS,WAAW,CAAC,IAAI,MAAM;GACzC,QAAQ;IAAE;IAAU,MAAM,MAAM,QAAQ,QAAQ;GAAG;EACrD,CAAC;EACD,IAAI,UAAU,iBAAiB;CACjC;CAEA,MAAM,kBAAkB,kBAAkB,gBAAgB;CAC1D,MAAM,mBAAmB,kBACrB,EAAE,cAAc,kBAAkB,IAClC,EAAE,OAAO,kBAAkB;CAC/B,MAAM,kBAAkB,mBACtB,oBAAC,OAAD;EACE,MAAM,YAAY;GAChB,IAAI,WAAW,iBAAiB,WAAW,CAAC,UAAU;IACpD,QAAQ,MAAM;IACd,iBAAiB,UAAU;GAC7B;EACF;EACA,cAAY,GAAG,MAAM;EACrB,oBAAkB;EAClB,aAAY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Y,OACR,CAAC,GAAG,MAAM,UAAU,OAAO,KAAK,IAChC,MAAM,SAAS,QAAQ,SAAS,SAAS,OAAO,KAAK;IAC7D,CAAC;GACH;EACD,GAhBM,OAAO,KAgBb,CACF,GACA,eACC,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,oBAAC,UAAD;IACE,GAAI;IACJ,SAAS;IACT,gBAAc,WAAW,KAAA;IACf;IACV,kBAAkB,YAAY,aAAa,YAAY,IAAI;GAC5D,CAAA,GACA,eACE;EAEJ,CAAA,CAAA;;AAET"}
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from 'react';
2
+ /** Animates height between 0 and auto; hidden content is inert. */
3
+ export declare function ChatRichContentCollapsible({ id, open, disabled, className, children, }: {
4
+ id?: string;
5
+ open: boolean;
6
+ /** Renders children directly in the parent's layout. */
7
+ disabled?: boolean;
8
+ className?: string;
9
+ children: ReactNode;
10
+ }): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;