@assistant-ui/react 0.14.29 → 0.15.1
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/dist/client/ExternalThread.js +4 -3
- package/dist/client/ExternalThread.js.map +1 -1
- package/dist/client/InMemoryThreadList.js +3 -3
- package/dist/client/InMemoryThreadList.js.map +1 -1
- package/dist/context/index.d.ts +1 -8
- package/dist/context/index.js +1 -8
- package/dist/hooks/useToolCallElapsed.js +24 -29
- package/dist/hooks/useToolCallElapsed.js.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.js +1 -8
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +3 -3
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/mcp-apps/McpAppRenderer.js +1 -1
- package/dist/mcp-apps/McpAppRenderer.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +26 -25
- package/dist/model-context/makeAssistantVisible.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +3 -3
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/attachment/AttachmentRemove.js +3 -3
- package/dist/primitives/attachment/AttachmentRemove.js.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +3 -3
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +3 -3
- package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +13 -13
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.js +1 -1
- package/dist/primitives/composer/ComposerQuote.js.map +1 -1
- package/dist/primitives/composer/ComposerStopDictation.js +3 -3
- package/dist/primitives/composer/ComposerStopDictation.js.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.js +3 -3
- package/dist/primitives/composer/trigger/triggerSelectionResource.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +67 -89
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/message/MessageRoot.js +3 -3
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/queueItem/QueueItemRemove.js +3 -3
- package/dist/primitives/queueItem/QueueItemRemove.js.map +1 -1
- package/dist/primitives/queueItem/QueueItemSteer.js +3 -3
- package/dist/primitives/queueItem/QueueItemSteer.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.js +16 -15
- package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -1
- package/dist/unstable/useComposerInput.js +2 -2
- package/dist/unstable/useComposerInput.js.map +1 -1
- package/dist/unstable/useComposerInputHistory.js +6 -6
- package/dist/unstable/useComposerInputHistory.js.map +1 -1
- package/dist/unstable/useMentionAdapter.js +1 -1
- package/dist/unstable/useMentionAdapter.js.map +1 -1
- package/dist/utils/smooth/SmoothContext.js +3 -3
- package/dist/utils/smooth/SmoothContext.js.map +1 -1
- package/dist/utils/smooth/useSmooth.js +1 -1
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.d.ts +2 -2
- package/package.json +5 -5
- package/src/client/ExternalThread.ts +5 -3
- package/src/client/InMemoryThreadList.ts +3 -3
- package/src/context/index.ts +0 -44
- package/src/hooks/useToolCallElapsed.ts +9 -12
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +5 -9
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +1 -1
- package/src/mcp-apps/McpAppRenderer.tsx +1 -1
- package/src/model-context/makeAssistantVisible.test.tsx +1 -1
- package/src/model-context/makeAssistantVisible.tsx +1 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
- package/src/primitives/attachment/AttachmentRemove.ts +1 -1
- package/src/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.ts +1 -1
- package/src/primitives/composer/ComposerAddAttachment.test.tsx +2 -2
- package/src/primitives/composer/ComposerAddAttachment.ts +1 -1
- package/src/primitives/composer/ComposerAttachmentDropzone.test.tsx +2 -2
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +1 -1
- package/src/primitives/composer/ComposerInput.test.tsx +7 -7
- package/src/primitives/composer/ComposerInput.tsx +13 -13
- package/src/primitives/composer/ComposerQuote.tsx +1 -1
- package/src/primitives/composer/ComposerStopDictation.ts +1 -1
- package/src/primitives/composer/trigger/triggerSelectionResource.ts +7 -9
- package/src/primitives/message/MessagePartsGrouped.tsx +6 -8
- package/src/primitives/message/MessageRoot.tsx +1 -1
- package/src/primitives/queueItem/QueueItemRemove.ts +1 -1
- package/src/primitives/queueItem/QueueItemSteer.ts +1 -1
- package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +1 -1
- package/src/primitives/suggestion/SuggestionTrigger.ts +9 -9
- package/src/tests/DataRenderers.test.tsx +1 -1
- package/src/tests/RemoteThreadListRuntime.deferredProvider.test.tsx +3 -3
- package/src/tests/external-thread-attachments.test.tsx +21 -23
- package/src/tests/external-thread-branches.test.tsx +10 -10
- package/src/tests/external-thread-parity.test.tsx +18 -20
- package/src/tests/local-runtime-queue.test.tsx +29 -34
- package/src/tests/messagePartSwitchRace.test.tsx +30 -13
- package/src/unstable/useComposerInput.test.tsx +2 -2
- package/src/unstable/useComposerInput.ts +2 -2
- package/src/unstable/useComposerInputHistory.test.tsx +3 -3
- package/src/unstable/useComposerInputHistory.ts +6 -6
- package/src/unstable/useMentionAdapter.ts +1 -1
- package/src/utils/smooth/SmoothContext.tsx +1 -1
- package/src/utils/smooth/useSmooth.test.tsx +1 -1
- package/src/utils/smooth/useSmooth.ts +1 -1
- package/dist/context/react/utils/createStateHookForRuntime.d.ts +0 -34
- package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +0 -1
- package/dist/context/react/utils/createStateHookForRuntime.js +0 -21
- package/dist/context/react/utils/createStateHookForRuntime.js.map +0 -1
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts +0 -74
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js +0 -29
- package/dist/legacy-runtime/hooks/AssistantContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +0 -1007
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js +0 -47
- package/dist/legacy-runtime/hooks/AttachmentContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts +0 -141
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/ComposerContext.js +0 -65
- package/dist/legacy-runtime/hooks/ComposerContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/MessageContext.d.ts +0 -155
- package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/MessageContext.js +0 -68
- package/dist/legacy-runtime/hooks/MessageContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +0 -44
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js +0 -26
- package/dist/legacy-runtime/hooks/MessagePartContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts +0 -139
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadContext.js +0 -84
- package/dist/legacy-runtime/hooks/ThreadContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +0 -44
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js +0 -26
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +0 -1
- package/src/context/react/utils/createStateHookForRuntime.ts +0 -82
- package/src/legacy-runtime/hooks/AssistantContext.ts +0 -67
- package/src/legacy-runtime/hooks/AttachmentContext.ts +0 -99
- package/src/legacy-runtime/hooks/ComposerContext.ts +0 -131
- package/src/legacy-runtime/hooks/MessageContext.ts +0 -127
- package/src/legacy-runtime/hooks/MessagePartContext.ts +0 -32
- package/src/legacy-runtime/hooks/ThreadContext.ts +0 -120
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +0 -36
|
@@ -18,13 +18,13 @@ const useComposerAddAttachment$1 = (t0) => {
|
|
|
18
18
|
const { disabled, addAttachment } = useComposerAddAttachment();
|
|
19
19
|
const aui = useAui();
|
|
20
20
|
let t3;
|
|
21
|
-
if ($[2] !== addAttachment || $[3] !== aui || $[4] !== multiple) {
|
|
21
|
+
if ($[2] !== addAttachment || $[3] !== aui.composer || $[4] !== multiple) {
|
|
22
22
|
t3 = () => {
|
|
23
23
|
const input = document.createElement("input");
|
|
24
24
|
input.type = "file";
|
|
25
25
|
input.multiple = multiple;
|
|
26
26
|
input.hidden = true;
|
|
27
|
-
const attachmentAccept = aui.composer
|
|
27
|
+
const attachmentAccept = aui.composer.getState().attachmentAccept;
|
|
28
28
|
if (attachmentAccept !== "*") input.accept = attachmentAccept;
|
|
29
29
|
document.body.appendChild(input);
|
|
30
30
|
input.onchange = async (e) => {
|
|
@@ -44,7 +44,7 @@ const useComposerAddAttachment$1 = (t0) => {
|
|
|
44
44
|
input.click();
|
|
45
45
|
};
|
|
46
46
|
$[2] = addAttachment;
|
|
47
|
-
$[3] = aui;
|
|
47
|
+
$[3] = aui.composer;
|
|
48
48
|
$[4] = multiple;
|
|
49
49
|
$[5] = t3;
|
|
50
50
|
} else t3 = $[5];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerAddAttachment.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","useCallback","useAui","useComposerAddAttachment","useComposerAddAttachmentBehavior","t0","$","t1","undefined","multiple","t2","disabled","addAttachment","aui","t3","input","document","createElement","type","hidden","attachmentAccept","
|
|
1
|
+
{"version":3,"file":"ComposerAddAttachment.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","useCallback","useAui","useComposerAddAttachment","useComposerAddAttachmentBehavior","t0","$","t1","undefined","multiple","t2","disabled","addAttachment","aui","t3","composer","input","document","createElement","type","hidden","attachmentAccept","getState","accept","body","appendChild","onchange","e","fileList","target","HTMLInputElement","files","attachmentPromises","Array","from","file","removeChild","Promise","all","oncancel","length","click","callback","ComposerPrimitiveAddAttachment","Element","Props"],"sources":["../../../src/primitives/composer/ComposerAddAttachment.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useCallback } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useComposerAddAttachment as useComposerAddAttachmentBehavior } from \"@assistant-ui/core/react\";\n\nconst useComposerAddAttachment = ({\n multiple = true,\n}: {\n /** allow selecting multiple files */\n multiple?: boolean | undefined;\n} = {}) => {\n const { disabled, addAttachment } = useComposerAddAttachmentBehavior();\n const aui = useAui();\n\n const callback = useCallback(() => {\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.multiple = multiple;\n input.hidden = true;\n\n const attachmentAccept = aui.composer.getState().attachmentAccept;\n if (attachmentAccept !== \"*\") {\n input.accept = attachmentAccept;\n }\n\n document.body.appendChild(input);\n\n input.onchange = async (e) => {\n const fileList = (e.target as HTMLInputElement).files;\n if (!fileList) return;\n\n const attachmentPromises = Array.from(fileList, async (file) => {\n try {\n await addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting.\n }\n });\n\n document.body.removeChild(input);\n await Promise.all(attachmentPromises);\n };\n\n input.oncancel = () => {\n if (!input.files || input.files.length === 0) {\n document.body.removeChild(input);\n }\n };\n\n input.click();\n }, [aui, multiple, addAttachment]);\n\n if (disabled) return null;\n return callback;\n};\n\nexport namespace ComposerPrimitiveAddAttachment {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useComposerAddAttachment>;\n}\n\nexport const ComposerPrimitiveAddAttachment = createActionButton(\n \"ComposerPrimitive.AddAttachment\",\n useComposerAddAttachment,\n [\"multiple\"],\n);\n"],"mappings":";;;;;;;AAWA,MAAMO,8BAA2BE,OAAA;CAAA,MAAAC,IAAAT,EAAA,CAAA;CAAA,IAAAU;CAAA,IAAAD,EAAA,OAAAD,IAAA;EAACE,KAAAF,OAAAG,KAAAA,IAAA,CAK7B,IAL6BH;EAK5BC,EAAA,KAAAD;EAAAC,EAAA,KAAAC;CAAA,OAAAA,KAAAD,EAAA;CAL4B,MAAA,EAAAG,UAAAC,OAAAH;CAChC,MAAAE,WAAAC,OAAAF,KAAAA,IAAA,OAAAE;CAKA,MAAA,EAAAC,UAAAC,kBAAoCR,yBAAiC;CACrE,MAAAS,MAAYX,OAAO;CAAE,IAAAY;CAAA,IAAAR,EAAA,OAAAM,iBAAAN,EAAA,OAAAO,IAAAE,YAAAT,EAAA,OAAAG,UAAA;EAEQK,WAAA;GAC3B,MAAAE,QAAcC,SAAQC,cAAe,OAAO;GAC5CF,MAAKG,OAAQ;GACbH,MAAKP,WAAYA;GACjBO,MAAKI,SAAU;GAEf,MAAAC,mBAAyBR,IAAGE,SAASO,SAAU,CAAC,CAAAD;GAChD,IAAIA,qBAAqB,KACvBL,MAAKO,SAAUF;GAGjBJ,SAAQO,KAAKC,YAAaT,KAAK;GAE/BA,MAAKU,WAAY,OAAAC,MAAA;IACf,MAAAC,WAAkBD,EAACE,OAA2BE;IAC9C,IAAI,CAACH,UAAQ;IAEb,MAAAI,qBAA2BC,MAAKC,KAAMN,UAAU,OAAAO,SAAA;KAC9C,IAAA;MACE,MAAMvB,cAAcuB,IAAI;KAAC,QAAA,CAAA;IAG1B,CACF;IAEDlB,SAAQO,KAAKY,YAAapB,KAAK;IAC/B,MAAMqB,QAAOC,IAAKN,kBAAkB;GAAC;GAGvChB,MAAKuB,iBAAY;IACf,IAAI,CAACvB,MAAKe,SAAUf,MAAKe,MAAMS,WAAY,GACzCvB,SAAQO,KAAKY,YAAapB,KAAK;GAChC;GAGHA,MAAKyB,MAAO;EAAC;EACdnC,EAAA,KAAAM;EAAAN,EAAA,KAAAO,IAAAE;EAAAT,EAAA,KAAAG;EAAAH,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CApCD,MAAAoC,WAAiB5B;CAsCjB,IAAIH,UAAQ,OAAS;CAAK,OACnB+B;AAAQ;AAQjB,MAAaC,iCAAiC3C,mBAC5C,mCACAG,4BACA,CAAC,UAAU,CACb"}
|
|
@@ -57,7 +57,7 @@ const ComposerPrimitiveAttachmentDropzone = forwardRef((t0, ref) => {
|
|
|
57
57
|
const files = Array.from(e_2.dataTransfer.files);
|
|
58
58
|
await Promise.all(files.map(async (file) => {
|
|
59
59
|
try {
|
|
60
|
-
await aui.composer
|
|
60
|
+
await aui.composer.addAttachment(file);
|
|
61
61
|
} catch {}
|
|
62
62
|
}));
|
|
63
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerAttachmentDropzone.js","names":["c","_c","forwardRef","useCallback","useState","ReactElement","cloneElement","isValidElement","composeEventHandlers","Slot","React","useAui","ComposerPrimitiveAttachmentDropzone","Element","HTMLDivElement","Props","HTMLAttributes","asChild","render","disabled","t0","ref","$","t1","children","rest","undefined","isDragging","setIsDragging","aui","t2","e","preventDefault","handleDragEnterCapture","t3","e_0","handleDragOverCapture","t4","e_1","next","relatedTarget","Node","currentTarget","contains","handleDragLeaveCapture","t5","e_2","files","Array","from","dataTransfer","Promise","all","map","file","composer","addAttachment","handleDrop","t6","t7","onDragEnterCapture","t8","onDragOverCapture","t9","onDragLeaveCapture","t10","onDropCapture","t11","mergedProps","renderChildren","props","Record","t12","ReactNode","t13","t14","Comp","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerAttachmentDropzone.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n useCallback,\n useState,\n type ReactElement,\n cloneElement,\n isValidElement,\n} from \"react\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Slot } from \"radix-ui\";\nimport type React from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\n\nexport namespace ComposerPrimitiveAttachmentDropzone {\n export type Element = HTMLDivElement;\n export type Props = React.HTMLAttributes<HTMLDivElement> & {\n asChild?: boolean | undefined;\n render?: ReactElement | undefined;\n disabled?: boolean | undefined;\n };\n}\n\nexport const ComposerPrimitiveAttachmentDropzone = forwardRef<\n HTMLDivElement,\n ComposerPrimitiveAttachmentDropzone.Props\n>(({ disabled, asChild = false, render, children, ...rest }, ref) => {\n const [isDragging, setIsDragging] = useState(false);\n const aui = useAui();\n\n const handleDragEnterCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n setIsDragging(true);\n },\n [disabled],\n );\n\n const handleDragOverCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n if (!isDragging) setIsDragging(true);\n },\n [disabled, isDragging],\n );\n\n const handleDragLeaveCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n const next = e.relatedTarget as Node | null;\n if (next && e.currentTarget.contains(next)) {\n return;\n }\n setIsDragging(false);\n },\n [disabled],\n );\n\n const handleDrop = useCallback(\n async (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n setIsDragging(false);\n const files = Array.from(e.dataTransfer.files);\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer
|
|
1
|
+
{"version":3,"file":"ComposerAttachmentDropzone.js","names":["c","_c","forwardRef","useCallback","useState","ReactElement","cloneElement","isValidElement","composeEventHandlers","Slot","React","useAui","ComposerPrimitiveAttachmentDropzone","Element","HTMLDivElement","Props","HTMLAttributes","asChild","render","disabled","t0","ref","$","t1","children","rest","undefined","isDragging","setIsDragging","aui","t2","e","preventDefault","handleDragEnterCapture","t3","e_0","handleDragOverCapture","t4","e_1","next","relatedTarget","Node","currentTarget","contains","handleDragLeaveCapture","t5","e_2","files","Array","from","dataTransfer","Promise","all","map","file","composer","addAttachment","handleDrop","t6","t7","onDragEnterCapture","t8","onDragOverCapture","t9","onDragLeaveCapture","t10","onDropCapture","t11","mergedProps","renderChildren","props","Record","t12","ReactNode","t13","t14","Comp","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerAttachmentDropzone.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n useCallback,\n useState,\n type ReactElement,\n cloneElement,\n isValidElement,\n} from \"react\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Slot } from \"radix-ui\";\nimport type React from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\n\nexport namespace ComposerPrimitiveAttachmentDropzone {\n export type Element = HTMLDivElement;\n export type Props = React.HTMLAttributes<HTMLDivElement> & {\n asChild?: boolean | undefined;\n render?: ReactElement | undefined;\n disabled?: boolean | undefined;\n };\n}\n\nexport const ComposerPrimitiveAttachmentDropzone = forwardRef<\n HTMLDivElement,\n ComposerPrimitiveAttachmentDropzone.Props\n>(({ disabled, asChild = false, render, children, ...rest }, ref) => {\n const [isDragging, setIsDragging] = useState(false);\n const aui = useAui();\n\n const handleDragEnterCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n setIsDragging(true);\n },\n [disabled],\n );\n\n const handleDragOverCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n if (!isDragging) setIsDragging(true);\n },\n [disabled, isDragging],\n );\n\n const handleDragLeaveCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n const next = e.relatedTarget as Node | null;\n if (next && e.currentTarget.contains(next)) {\n return;\n }\n setIsDragging(false);\n },\n [disabled],\n );\n\n const handleDrop = useCallback(\n async (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n setIsDragging(false);\n const files = Array.from(e.dataTransfer.files);\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer.addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting;\n // the readonly and empty-thread stubs only throw.\n }\n }),\n );\n },\n [disabled, aui],\n );\n\n const mergedProps = {\n ...(isDragging ? { \"data-dragging\": \"true\" } : null),\n ...rest,\n onDragEnterCapture: composeEventHandlers(\n rest.onDragEnterCapture,\n handleDragEnterCapture,\n ),\n onDragOverCapture: composeEventHandlers(\n rest.onDragOverCapture,\n handleDragOverCapture,\n ),\n onDragLeaveCapture: composeEventHandlers(\n rest.onDragLeaveCapture,\n handleDragLeaveCapture,\n ),\n onDropCapture: composeEventHandlers(rest.onDropCapture, handleDrop),\n ref,\n };\n\n if (render && isValidElement(render)) {\n const renderChildren =\n children !== undefined\n ? children\n : (render.props as Record<string, unknown>).children;\n return (\n <Slot.Root {...mergedProps}>\n {cloneElement(render, undefined, renderChildren as React.ReactNode)}\n </Slot.Root>\n );\n }\n\n const Comp = asChild ? Slot.Root : \"div\";\n return <Comp {...mergedProps}>{children}</Comp>;\n});\n\nComposerPrimitiveAttachmentDropzone.displayName =\n \"ComposerPrimitive.AttachmentDropzone\";\n"],"mappings":";;;;;;;;AAyBA,MAAaY,sCAAsCV,YAGjDkB,IAAAC,QAAA;CAAA,MAAAC,IAAArB,EAAA,EAAA;CAAC,MAAA,EAAAkB,UAAAF,SAAAM,IAAAL,QAAAM,UAAA,GAAAC,SAAAL;CAAY,MAAAH,UAAAM,OAAAG,KAAAA,IAAA,Q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AA;GAAjEE,MAAApE,aAAaY,QAAQQ,KAAAA,GAAW8C,GAAiC;GAAClD,EAAA,MAAAJ;GAAAI,EAAA,MAAAkD;GAAAlD,EAAA,MAAAoD;EAAA,OAAAA,MAAApD,EAAA;EAAA,IAAAqD;EAAA,IAAArD,EAAA,QAAA8C,eAAA9C,EAAA,QAAAoD,KAAA;GADrEC,MAAA,oBAAA,KAAA,MAAA;IAAA,GAAeP;IACZM,UAAAA;GACH,CAAA;GAAYpD,EAAA,MAAA8C;GAAA9C,EAAA,MAAAoD;GAAApD,EAAA,MAAAqD;EAAA,OAAAA,MAAArD,EAAA;EAAA,OAFZqD;CAEY;CAIhB,MAAAC,OAAa3D,UAAUR,KAAIoE,OAAd;CAA4B,IAAAL;CAAA,IAAAlD,EAAA,QAAAsD,QAAAtD,EAAA,QAAAE,YAAAF,EAAA,QAAA8C,aAAA;EAClCI,MAAA,oBAAC,MAAD;GAAK,GAAKJ;GAAc5C;EAAnB,CAAA;EAAmCF,EAAA,MAAAsD;EAAAtD,EAAA,MAAAE;EAAAF,EAAA,MAAA8C;EAAA9C,EAAA,MAAAkD;CAAA,OAAAA,MAAAlD,EAAA;CAAA,OAAxCkD;AAAwC,CAChD;AAED5D,oCAAoCkE,cAClC"}
|
|
@@ -67,7 +67,7 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
67
67
|
for (const plugin of pluginRegistry.getPlugins()) if (plugin.handleKeyDown(e)) return;
|
|
68
68
|
}
|
|
69
69
|
if (!cancelOnEscape) return;
|
|
70
|
-
const composer = aui.composer
|
|
70
|
+
const composer = aui.composer;
|
|
71
71
|
if (composer.getState().canCancel) {
|
|
72
72
|
composer.cancel();
|
|
73
73
|
e.preventDefault();
|
|
@@ -80,11 +80,11 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
80
80
|
for (const plugin_0 of pluginRegistry.getPlugins()) if (plugin_0.handleKeyDown(e_0)) return;
|
|
81
81
|
}
|
|
82
82
|
if (e_0.key === "Enter") {
|
|
83
|
-
const threadState = aui.thread
|
|
83
|
+
const threadState = aui.thread.getState();
|
|
84
84
|
const hasQueue = threadState.capabilities.queue;
|
|
85
|
-
if (e_0.shiftKey && (e_0.ctrlKey || e_0.metaKey) && hasQueue && declaredSubmitMode !== "none" && aui.composer
|
|
85
|
+
if (e_0.shiftKey && (e_0.ctrlKey || e_0.metaKey) && hasQueue && declaredSubmitMode !== "none" && aui.composer.getState().canSend) {
|
|
86
86
|
e_0.preventDefault();
|
|
87
|
-
aui.composer
|
|
87
|
+
aui.composer.send({ steer: true });
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
if (e_0.shiftKey) return;
|
|
@@ -100,13 +100,13 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
100
100
|
};
|
|
101
101
|
const handlePaste = async (e_1) => {
|
|
102
102
|
if (!addAttachmentOnPaste) return;
|
|
103
|
-
const threadCapabilities = aui.thread
|
|
103
|
+
const threadCapabilities = aui.thread.getState().capabilities;
|
|
104
104
|
const files = Array.from(e_1.clipboardData?.files || []);
|
|
105
105
|
if (threadCapabilities.attachments && files.length > 0) {
|
|
106
106
|
e_1.preventDefault();
|
|
107
107
|
await Promise.all(files.map(async (file) => {
|
|
108
108
|
try {
|
|
109
|
-
await aui.composer
|
|
109
|
+
await aui.composer.addAttachment(file);
|
|
110
110
|
} catch {}
|
|
111
111
|
}));
|
|
112
112
|
}
|
|
@@ -129,10 +129,10 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
129
129
|
}, [autoFocusEnabled]);
|
|
130
130
|
useEffect(() => focus(), [focus]);
|
|
131
131
|
useOnScrollToBottom(() => {
|
|
132
|
-
if (aui.composer
|
|
132
|
+
if (aui.composer.getState().type === "thread" && unstable_focusOnScrollToBottom) focus();
|
|
133
133
|
});
|
|
134
134
|
useEffect(() => {
|
|
135
|
-
if (aui.composer
|
|
135
|
+
if (aui.composer.getState().type !== "thread" || !unstable_focusOnRunStart) return void 0;
|
|
136
136
|
return aui.on("thread.runStart", focus);
|
|
137
137
|
}, [
|
|
138
138
|
unstable_focusOnRunStart,
|
|
@@ -140,7 +140,7 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
140
140
|
aui
|
|
141
141
|
]);
|
|
142
142
|
useEffect(() => {
|
|
143
|
-
if (aui.composer
|
|
143
|
+
if (aui.composer.getState().type !== "thread" || !unstable_focusOnThreadSwitched) return void 0;
|
|
144
144
|
return aui.on("threadListItem.switchedTo", focus);
|
|
145
145
|
}, [
|
|
146
146
|
unstable_focusOnThreadSwitched,
|
|
@@ -159,12 +159,12 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
159
159
|
ref,
|
|
160
160
|
disabled: isDisabled,
|
|
161
161
|
onChange: composeEventHandlers(onChange, (e_2) => {
|
|
162
|
-
if (!aui.composer
|
|
162
|
+
if (!aui.composer.getState().isEditing) return;
|
|
163
163
|
const nativeIsComposing = e_2.nativeEvent.isComposing === true;
|
|
164
164
|
if (compositionRef.current && !nativeIsComposing) compositionRef.current = false;
|
|
165
165
|
const isComposing = nativeIsComposing || compositionRef.current;
|
|
166
166
|
flushTapSync(() => {
|
|
167
|
-
aui.composer
|
|
167
|
+
aui.composer.setText(e_2.target.value);
|
|
168
168
|
});
|
|
169
169
|
if (isComposing) return;
|
|
170
170
|
const pos = e_2.target.selectionStart ?? e_2.target.value.length;
|
|
@@ -176,10 +176,10 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
176
176
|
}),
|
|
177
177
|
onCompositionEnd: composeEventHandlers(rest.onCompositionEnd, (e_3) => {
|
|
178
178
|
compositionRef.current = false;
|
|
179
|
-
if (!aui.composer
|
|
179
|
+
if (!aui.composer.getState().isEditing) return;
|
|
180
180
|
const target = e_3.target;
|
|
181
181
|
flushTapSync(() => {
|
|
182
|
-
aui.composer
|
|
182
|
+
aui.composer.setText(target.value);
|
|
183
183
|
});
|
|
184
184
|
const pos_0 = target.selectionStart ?? target.value.length;
|
|
185
185
|
if (pluginRegistry) for (const plugin_2 of pluginRegistry.getPlugins()) plugin_2.setCursorPosition(pos_0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerInput.js","names":["composeEventHandlers","useComposedRefs","Slot","ClipboardEvent","KeyboardEvent","ReactElement","ReactNode","forwardRef","useCallback","useEffect","useRef","cloneElement","isValidElement","TextareaAutosize","TextareaAutosizeProps","TextareaHeightChangeMeta","useEscapeKeydown","useOnScrollToBottom","useMediaQuery","useAui","flushTapSync","useComposerInputPluginRegistryOptional","useComposerCompactContextOptional","useComposerInputDisabled","useComposerInputValue","useTriggerPopoverAriaProps","TOUCH_PRIMARY_QUERY","ComposerPrimitiveInput","Element","HTMLTextAreaElement","BaseProps","asChild","render","cancelOnEscape","unstable_focusOnRunStart","unstable_focusOnScrollToBottom","unstable_focusOnThreadSwitched","unstable_insertNewlineOnTouchEnter","addAttachmentOnPaste","SubmitModeProps","submitMode","submitOnEnter","Props","autoFocus","disabled","disabledProp","onChange","onKeyDown","onPaste","onSelect","onHeightChange","rest","forwardedRef","aui","pluginRegistry","compactContext","declaredSubmitMode","isTouchPrimary","effectiveSubmitMode","value","isDisabled","textareaRef","ref","compositionRef","e","current","contains","target","Node","plugin","getPlugins","handleKeyDown","composer","getState","canCancel","cancel","preventDefault","handleKeyPress","nativeEvent","isComposing","key","threadState","thread","hasQueue","capabilities","queue","shiftKey","ctrlKey","metaKey","canSend","send","steer","isRunning","shouldSubmit","closest","requestSubmit","handlePaste","threadCapabilities","files","Array","from","clipboardData","attachments","length","Promise","all","map","file","addAttachment","handleHeightChange","height","meta","el","cs","getComputedStyle","contentHeight","boxSizing","parseFloat","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth","Math","round","rowHeight","setMultiline","autoFocusEnabled","focus","textarea","preventScroll","setSelectionRange","type","undefined","on","ariaComboboxProps","inputProps","name","const","React","ForwardedRef","ChangeEvent","isEditing","nativeIsComposing","setText","pos","selectionStart","setCursorPosition","onCompositionStart","CompositionEventHandler","onCompositionEnd","CompositionEvent","SyntheticEvent","renderChildren","children","props","Record","Component","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"radix-ui\";\nimport {\n type ClipboardEvent,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n cloneElement,\n isValidElement,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n type TextareaHeightChangeMeta,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useMediaQuery } from \"../../utils/hooks/useMediaQuery\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { flushTapSync } from \"@assistant-ui/tap\";\nimport { useComposerInputPluginRegistryOptional } from \"./ComposerInputPluginContext\";\nimport { useComposerCompactContextOptional } from \"./ComposerCompactContext\";\nimport {\n useComposerInputDisabled,\n useComposerInputValue,\n useTriggerPopoverAriaProps,\n} from \"./useComposerInputState\";\n\nconst TOUCH_PRIMARY_QUERY = \"(pointer: coarse) and (not (any-pointer: fine))\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n\n type BaseProps = {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * A React element to use as the input container, with props merged in.\n */\n render?: ReactElement | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether plain Enter on a touch-primary device should insert a newline\n * instead of submitting, detected via\n * `(pointer: coarse) and (not (any-pointer: fine))`. Only takes effect\n * when `submitMode` resolves to `\"enter\"`.\n * @default false\n */\n unstable_insertNewlineOnTouchEnter?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n\n type SubmitModeProps =\n | {\n /**\n * Controls how the Enter key submits messages.\n * - \"enter\": Plain Enter submits (Shift+Enter for newline)\n * - \"ctrlEnter\": Ctrl/Cmd+Enter submits (plain Enter for newline)\n * - \"none\": Keyboard submission disabled\n * @default \"enter\"\n */\n submitMode?: \"enter\" | \"ctrlEnter\" | \"none\" | undefined;\n /**\n * @deprecated Use `submitMode` instead\n * @ignore\n */\n submitOnEnter?: never;\n }\n | {\n submitMode?: never;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n * @deprecated Use `submitMode` instead. Will be removed in a future version.\n */\n submitOnEnter?: boolean | undefined;\n };\n\n export type Props = TextareaAutosizeProps & BaseProps & SubmitModeProps;\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * When rendered inside `Unstable_TriggerPopoverRoot` and a popover is open, the\n * underlying `<textarea>` automatically receives `aria-controls`,\n * `aria-expanded`, `aria-haspopup`, and `aria-activedescendant` for the\n * combobox relationship. These computed attributes override user-provided\n * values for those four ARIA props while the popover is open.\n *\n * @example\n * ```tsx\n * // Ctrl/Cmd+Enter to submit (plain Enter inserts newline)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitMode=\"ctrlEnter\"\n * />\n *\n * // Insert a newline on Enter on touch-primary devices.\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * unstable_insertNewlineOnTouchEnter\n * />\n *\n * // Old API (deprecated, still supported)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n render,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n onSelect,\n submitOnEnter,\n submitMode,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n unstable_insertNewlineOnTouchEnter = false,\n addAttachmentOnPaste = true,\n onHeightChange,\n ...rest\n },\n forwardedRef,\n ) => {\n const aui = useAui();\n const pluginRegistry = useComposerInputPluginRegistryOptional();\n const compactContext = useComposerCompactContextOptional();\n\n const declaredSubmitMode =\n submitMode ?? (submitOnEnter === false ? \"none\" : \"enter\");\n const isTouchPrimary = useMediaQuery(\n unstable_insertNewlineOnTouchEnter ? TOUCH_PRIMARY_QUERY : null,\n );\n const effectiveSubmitMode =\n unstable_insertNewlineOnTouchEnter &&\n isTouchPrimary &&\n declaredSubmitMode === \"enter\"\n ? \"none\"\n : declaredSubmitMode;\n\n const value = useComposerInputValue();\n const isDisabled = useComposerInputDisabled(disabledProp);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n // suppress text/cursor broadcasts during IME composition\n const compositionRef = useRef(false);\n\n useEscapeKeydown((e) => {\n // Only handle ESC if it originated from within this input\n if (!textareaRef.current?.contains(e.target as Node)) return;\n\n // Let registered plugins (mention, slash command, etc.) handle Escape first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (!cancelOnEscape) return;\n\n const composer = aui.composer();\n if (composer.getState().canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n // Let registered plugins (mention, slash command, etc.) handle keyboard events first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (e.key === \"Enter\") {\n const threadState = aui.thread().getState();\n const hasQueue = threadState.capabilities.queue;\n\n // Steer hotkey: Cmd/Ctrl+Shift+Enter (respects submitMode=\"none\" and canSend)\n if (\n e.shiftKey &&\n (e.ctrlKey || e.metaKey) &&\n hasQueue &&\n declaredSubmitMode !== \"none\" &&\n aui.composer().getState().canSend\n ) {\n e.preventDefault();\n aui.composer().send({ steer: true });\n return;\n }\n\n // Regular newline: Shift+Enter\n if (e.shiftKey) return;\n\n // Block submission when running unless queue is supported\n if (threadState.isRunning && !hasQueue) return;\n\n let shouldSubmit = false;\n if (effectiveSubmitMode === \"ctrlEnter\") {\n shouldSubmit = e.ctrlKey || e.metaKey;\n } else if (effectiveSubmitMode === \"enter\") {\n shouldSubmit = true;\n }\n\n if (shouldSubmit) {\n e.preventDefault();\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = aui.thread().getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n e.preventDefault();\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer().addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting.\n }\n }),\n );\n }\n };\n\n const handleHeightChange = (\n height: number,\n meta: TextareaHeightChangeMeta,\n ) => {\n onHeightChange?.(height, meta);\n if (!compactContext) return;\n const el = textareaRef.current;\n if (!el || el.value === \"\") return;\n const cs = getComputedStyle(el);\n const contentHeight =\n cs.boxSizing === \"border-box\"\n ? height -\n parseFloat(cs.paddingTop) -\n parseFloat(cs.paddingBottom) -\n parseFloat(cs.borderTopWidth) -\n parseFloat(cs.borderBottomWidth)\n : height;\n if (Math.round(contentHeight / meta.rowHeight) > 1) {\n compactContext.setMultiline(true);\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (\n aui.composer().getState().type === \"thread\" &&\n unstable_focusOnScrollToBottom\n ) {\n focus();\n }\n });\n\n useEffect(() => {\n if (\n aui.composer().getState().type !== \"thread\" ||\n !unstable_focusOnRunStart\n )\n return undefined;\n\n return aui.on(\"thread.runStart\", focus);\n }, [unstable_focusOnRunStart, focus, aui]);\n\n useEffect(() => {\n if (\n aui.composer().getState().type !== \"thread\" ||\n !unstable_focusOnThreadSwitched\n )\n return undefined;\n\n return aui.on(\"threadListItem.switchedTo\", focus);\n }, [unstable_focusOnThreadSwitched, focus, aui]);\n\n useEffect(() => {\n if (value === \"\") compactContext?.setMultiline(false);\n }, [value, compactContext]);\n\n const ariaComboboxProps = useTriggerPopoverAriaProps();\n\n const inputProps = {\n name: \"input\" as const,\n value,\n ...rest,\n ...ariaComboboxProps,\n ref: ref as React.ForwardedRef<HTMLTextAreaElement>,\n disabled: isDisabled,\n onChange: composeEventHandlers(\n onChange,\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (!aui.composer().getState().isEditing) return;\n const nativeIsComposing =\n (e.nativeEvent as { isComposing?: boolean }).isComposing === true;\n // recover stuck compositionRef when the browser drops compositionend\n if (compositionRef.current && !nativeIsComposing) {\n compositionRef.current = false;\n }\n const isComposing = nativeIsComposing || compositionRef.current;\n // keep controlled value in sync mid-IME so react does not reset the textarea to a stale value\n flushTapSync(() => {\n aui.composer().setText(e.target.value);\n });\n if (isComposing) return;\n const pos = e.target.selectionStart ?? e.target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onKeyDown: composeEventHandlers(onKeyDown, handleKeyPress),\n onCompositionStart: composeEventHandlers(\n (rest as { onCompositionStart?: React.CompositionEventHandler })\n .onCompositionStart,\n () => {\n compositionRef.current = true;\n },\n ),\n onCompositionEnd: composeEventHandlers(\n (rest as { onCompositionEnd?: React.CompositionEventHandler })\n .onCompositionEnd,\n (e: React.CompositionEvent<HTMLTextAreaElement>) => {\n compositionRef.current = false;\n if (!aui.composer().getState().isEditing) return;\n const target = e.target as HTMLTextAreaElement;\n flushTapSync(() => {\n aui.composer().setText(target.value);\n });\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onSelect: composeEventHandlers(\n onSelect,\n (e: React.SyntheticEvent<HTMLTextAreaElement>) => {\n if (compositionRef.current) return;\n const target = e.target as HTMLTextAreaElement;\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onPaste: composeEventHandlers(onPaste, handlePaste),\n ...(compactContext\n ? { onHeightChange: handleHeightChange }\n : onHeightChange !== undefined\n ? { onHeightChange }\n : {}),\n };\n\n if (render && isValidElement(render)) {\n const renderChildren =\n (rest as any).children !== undefined\n ? ((rest as any).children as ReactNode)\n : ((render.props as Record<string, unknown>).children as ReactNode);\n return (\n <Slot.Root {...inputProps}>\n {cloneElement(render, undefined, renderChildren)}\n </Slot.Root>\n );\n }\n\n const Component = asChild ? Slot.Root : TextareaAutosize;\n return <Component {...inputProps} />;\n },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AQ5E,OAAOR,KAAK;GACrC,CAAC;GACD,MAAMqF,QAAM7E,OAAO8E,kBAAkB9E,OAAOR,MAAM4C;GAClD,IAAIjD,gBACF,KAAK,MAAMe,YAAUf,eAAegB,WAAW,GAC7CD,SAAO6E,kBAAkBF,KAAG;EAGlC,CACF;EACA/F,UAAUjD,qBACRiD,WACCe,QAAiD;GAChD,IAAID,eAAeE,SAAS;GAC5B,MAAME,WAASH,IAAEG;GACjB,MAAM6E,QAAM7E,SAAO8E,kBAAkB9E,SAAOR,MAAM4C;GAClD,IAAIjD,gBACF,KAAK,MAAMe,YAAUf,eAAegB,WAAW,GAC7CD,SAAO6E,kBAAkBF,KAAG;EAGlC,CACF;EACAhG,SAAShD,qBAAqBgD,SAASgD,WAAW;EAClD,GAAIzC,iBACA,EAAEL,gBAAgB2D,mBAAmB,IACrC3D,mBAAmBkF,KAAAA,IACjB,EAAElF,eAAe,IACjB,CAAC;CACT;CAEA,IAAIlB,UAAUpB,eAAeoB,MAAM,GAAG;EACpC,MAAMwH,iBACHrG,KAAasG,aAAarB,KAAAA,IACrBjF,KAAasG,WACbzH,OAAO0H,MAAkCD;EACjD,OACE,oBAAC,KAAK,MAAN;GAAW,GAAIlB;GACZ5H,UAAAA,aAAaqB,QAAQoG,KAAAA,GAAWoB,cAAc;EACtC,CAAA;CAEf;CAGA,OAAO,oBADWzH,UAAU7B,KAAK2J,OAAOhJ,kBACjC,EAAW,GAAI0H,WAAW,CAAA;AACnC,CACF;AAEA5G,uBAAuBmI,cAAc"}
|
|
1
|
+
{"version":3,"file":"ComposerInput.js","names":["composeEventHandlers","useComposedRefs","Slot","ClipboardEvent","KeyboardEvent","ReactElement","ReactNode","forwardRef","useCallback","useEffect","useRef","cloneElement","isValidElement","TextareaAutosize","TextareaAutosizeProps","TextareaHeightChangeMeta","useEscapeKeydown","useOnScrollToBottom","useMediaQuery","useAui","flushTapSync","useComposerInputPluginRegistryOptional","useComposerCompactContextOptional","useComposerInputDisabled","useComposerInputValue","useTriggerPopoverAriaProps","TOUCH_PRIMARY_QUERY","ComposerPrimitiveInput","Element","HTMLTextAreaElement","BaseProps","asChild","render","cancelOnEscape","unstable_focusOnRunStart","unstable_focusOnScrollToBottom","unstable_focusOnThreadSwitched","unstable_insertNewlineOnTouchEnter","addAttachmentOnPaste","SubmitModeProps","submitMode","submitOnEnter","Props","autoFocus","disabled","disabledProp","onChange","onKeyDown","onPaste","onSelect","onHeightChange","rest","forwardedRef","aui","pluginRegistry","compactContext","declaredSubmitMode","isTouchPrimary","effectiveSubmitMode","value","isDisabled","textareaRef","ref","compositionRef","e","current","contains","target","Node","plugin","getPlugins","handleKeyDown","composer","getState","canCancel","cancel","preventDefault","handleKeyPress","nativeEvent","isComposing","key","threadState","thread","hasQueue","capabilities","queue","shiftKey","ctrlKey","metaKey","canSend","send","steer","isRunning","shouldSubmit","closest","requestSubmit","handlePaste","threadCapabilities","files","Array","from","clipboardData","attachments","length","Promise","all","map","file","addAttachment","handleHeightChange","height","meta","el","cs","getComputedStyle","contentHeight","boxSizing","parseFloat","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth","Math","round","rowHeight","setMultiline","autoFocusEnabled","focus","textarea","preventScroll","setSelectionRange","type","undefined","on","ariaComboboxProps","inputProps","name","const","React","ForwardedRef","ChangeEvent","isEditing","nativeIsComposing","setText","pos","selectionStart","setCursorPosition","onCompositionStart","CompositionEventHandler","onCompositionEnd","CompositionEvent","SyntheticEvent","renderChildren","children","props","Record","Component","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"radix-ui\";\nimport {\n type ClipboardEvent,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n cloneElement,\n isValidElement,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n type TextareaHeightChangeMeta,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useMediaQuery } from \"../../utils/hooks/useMediaQuery\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { flushTapSync } from \"@assistant-ui/tap\";\nimport { useComposerInputPluginRegistryOptional } from \"./ComposerInputPluginContext\";\nimport { useComposerCompactContextOptional } from \"./ComposerCompactContext\";\nimport {\n useComposerInputDisabled,\n useComposerInputValue,\n useTriggerPopoverAriaProps,\n} from \"./useComposerInputState\";\n\nconst TOUCH_PRIMARY_QUERY = \"(pointer: coarse) and (not (any-pointer: fine))\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n\n type BaseProps = {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * A React element to use as the input container, with props merged in.\n */\n render?: ReactElement | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether plain Enter on a touch-primary device should insert a newline\n * instead of submitting, detected via\n * `(pointer: coarse) and (not (any-pointer: fine))`. Only takes effect\n * when `submitMode` resolves to `\"enter\"`.\n * @default false\n */\n unstable_insertNewlineOnTouchEnter?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n\n type SubmitModeProps =\n | {\n /**\n * Controls how the Enter key submits messages.\n * - \"enter\": Plain Enter submits (Shift+Enter for newline)\n * - \"ctrlEnter\": Ctrl/Cmd+Enter submits (plain Enter for newline)\n * - \"none\": Keyboard submission disabled\n * @default \"enter\"\n */\n submitMode?: \"enter\" | \"ctrlEnter\" | \"none\" | undefined;\n /**\n * @deprecated Use `submitMode` instead\n * @ignore\n */\n submitOnEnter?: never;\n }\n | {\n submitMode?: never;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n * @deprecated Use `submitMode` instead. Will be removed in a future version.\n */\n submitOnEnter?: boolean | undefined;\n };\n\n export type Props = TextareaAutosizeProps & BaseProps & SubmitModeProps;\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * When rendered inside `Unstable_TriggerPopoverRoot` and a popover is open, the\n * underlying `<textarea>` automatically receives `aria-controls`,\n * `aria-expanded`, `aria-haspopup`, and `aria-activedescendant` for the\n * combobox relationship. These computed attributes override user-provided\n * values for those four ARIA props while the popover is open.\n *\n * @example\n * ```tsx\n * // Ctrl/Cmd+Enter to submit (plain Enter inserts newline)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitMode=\"ctrlEnter\"\n * />\n *\n * // Insert a newline on Enter on touch-primary devices.\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * unstable_insertNewlineOnTouchEnter\n * />\n *\n * // Old API (deprecated, still supported)\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n render,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n onSelect,\n submitOnEnter,\n submitMode,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n unstable_insertNewlineOnTouchEnter = false,\n addAttachmentOnPaste = true,\n onHeightChange,\n ...rest\n },\n forwardedRef,\n ) => {\n const aui = useAui();\n const pluginRegistry = useComposerInputPluginRegistryOptional();\n const compactContext = useComposerCompactContextOptional();\n\n const declaredSubmitMode =\n submitMode ?? (submitOnEnter === false ? \"none\" : \"enter\");\n const isTouchPrimary = useMediaQuery(\n unstable_insertNewlineOnTouchEnter ? TOUCH_PRIMARY_QUERY : null,\n );\n const effectiveSubmitMode =\n unstable_insertNewlineOnTouchEnter &&\n isTouchPrimary &&\n declaredSubmitMode === \"enter\"\n ? \"none\"\n : declaredSubmitMode;\n\n const value = useComposerInputValue();\n const isDisabled = useComposerInputDisabled(disabledProp);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n // suppress text/cursor broadcasts during IME composition\n const compositionRef = useRef(false);\n\n useEscapeKeydown((e) => {\n // Only handle ESC if it originated from within this input\n if (!textareaRef.current?.contains(e.target as Node)) return;\n\n // Let registered plugins (mention, slash command, etc.) handle Escape first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (!cancelOnEscape) return;\n\n const composer = aui.composer;\n if (composer.getState().canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n // Let registered plugins (mention, slash command, etc.) handle keyboard events first\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n if (plugin.handleKeyDown(e)) return;\n }\n }\n\n if (e.key === \"Enter\") {\n const threadState = aui.thread.getState();\n const hasQueue = threadState.capabilities.queue;\n\n // Steer hotkey: Cmd/Ctrl+Shift+Enter (respects submitMode=\"none\" and canSend)\n if (\n e.shiftKey &&\n (e.ctrlKey || e.metaKey) &&\n hasQueue &&\n declaredSubmitMode !== \"none\" &&\n aui.composer.getState().canSend\n ) {\n e.preventDefault();\n aui.composer.send({ steer: true });\n return;\n }\n\n // Regular newline: Shift+Enter\n if (e.shiftKey) return;\n\n // Block submission when running unless queue is supported\n if (threadState.isRunning && !hasQueue) return;\n\n let shouldSubmit = false;\n if (effectiveSubmitMode === \"ctrlEnter\") {\n shouldSubmit = e.ctrlKey || e.metaKey;\n } else if (effectiveSubmitMode === \"enter\") {\n shouldSubmit = true;\n }\n\n if (shouldSubmit) {\n e.preventDefault();\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = aui.thread.getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n e.preventDefault();\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer.addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting.\n }\n }),\n );\n }\n };\n\n const handleHeightChange = (\n height: number,\n meta: TextareaHeightChangeMeta,\n ) => {\n onHeightChange?.(height, meta);\n if (!compactContext) return;\n const el = textareaRef.current;\n if (!el || el.value === \"\") return;\n const cs = getComputedStyle(el);\n const contentHeight =\n cs.boxSizing === \"border-box\"\n ? height -\n parseFloat(cs.paddingTop) -\n parseFloat(cs.paddingBottom) -\n parseFloat(cs.borderTopWidth) -\n parseFloat(cs.borderBottomWidth)\n : height;\n if (Math.round(contentHeight / meta.rowHeight) > 1) {\n compactContext.setMultiline(true);\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (\n aui.composer.getState().type === \"thread\" &&\n unstable_focusOnScrollToBottom\n ) {\n focus();\n }\n });\n\n useEffect(() => {\n if (\n aui.composer.getState().type !== \"thread\" ||\n !unstable_focusOnRunStart\n )\n return undefined;\n\n return aui.on(\"thread.runStart\", focus);\n }, [unstable_focusOnRunStart, focus, aui]);\n\n useEffect(() => {\n if (\n aui.composer.getState().type !== \"thread\" ||\n !unstable_focusOnThreadSwitched\n )\n return undefined;\n\n return aui.on(\"threadListItem.switchedTo\", focus);\n }, [unstable_focusOnThreadSwitched, focus, aui]);\n\n useEffect(() => {\n if (value === \"\") compactContext?.setMultiline(false);\n }, [value, compactContext]);\n\n const ariaComboboxProps = useTriggerPopoverAriaProps();\n\n const inputProps = {\n name: \"input\" as const,\n value,\n ...rest,\n ...ariaComboboxProps,\n ref: ref as React.ForwardedRef<HTMLTextAreaElement>,\n disabled: isDisabled,\n onChange: composeEventHandlers(\n onChange,\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (!aui.composer.getState().isEditing) return;\n const nativeIsComposing =\n (e.nativeEvent as { isComposing?: boolean }).isComposing === true;\n // recover stuck compositionRef when the browser drops compositionend\n if (compositionRef.current && !nativeIsComposing) {\n compositionRef.current = false;\n }\n const isComposing = nativeIsComposing || compositionRef.current;\n // keep controlled value in sync mid-IME so react does not reset the textarea to a stale value\n flushTapSync(() => {\n aui.composer.setText(e.target.value);\n });\n if (isComposing) return;\n const pos = e.target.selectionStart ?? e.target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onKeyDown: composeEventHandlers(onKeyDown, handleKeyPress),\n onCompositionStart: composeEventHandlers(\n (rest as { onCompositionStart?: React.CompositionEventHandler })\n .onCompositionStart,\n () => {\n compositionRef.current = true;\n },\n ),\n onCompositionEnd: composeEventHandlers(\n (rest as { onCompositionEnd?: React.CompositionEventHandler })\n .onCompositionEnd,\n (e: React.CompositionEvent<HTMLTextAreaElement>) => {\n compositionRef.current = false;\n if (!aui.composer.getState().isEditing) return;\n const target = e.target as HTMLTextAreaElement;\n flushTapSync(() => {\n aui.composer.setText(target.value);\n });\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onSelect: composeEventHandlers(\n onSelect,\n (e: React.SyntheticEvent<HTMLTextAreaElement>) => {\n if (compositionRef.current) return;\n const target = e.target as HTMLTextAreaElement;\n const pos = target.selectionStart ?? target.value.length;\n if (pluginRegistry) {\n for (const plugin of pluginRegistry.getPlugins()) {\n plugin.setCursorPosition(pos);\n }\n }\n },\n ),\n onPaste: composeEventHandlers(onPaste, handlePaste),\n ...(compactContext\n ? { onHeightChange: handleHeightChange }\n : onHeightChange !== undefined\n ? { onHeightChange }\n : {}),\n };\n\n if (render && isValidElement(render)) {\n const renderChildren =\n (rest as any).children !== undefined\n ? ((rest as any).children as ReactNode)\n : ((render.props as Record<string, unknown>).children as ReactNode);\n return (\n <Slot.Root {...inputProps}>\n {cloneElement(render, undefined, renderChildren)}\n </Slot.Root>\n );\n }\n\n const Component = asChild ? Slot.Root : TextareaAutosize;\n return <Component {...inputProps} />;\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,MAAM0B,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiH5B,MAAaC,yBAAyBpB,YAKlC,EACEoC,YAAY,OACZZ,SACAC,QACAY,UAAUC,cACVC,UACAC,WACAC,SACAC,UACAR,eACAD,YACAP,iBAAiB,MACjBC,2BAA2B,MAC3BC,iCAAiC,MACjCC,iCAAiC,MACjCC,qCAAqC,OACrCC,uBAAuB,MACvBY,gBACA,GAAGC,QAELC,iBACG;CACH,MAAMC,MAAMlC,OAAO;CACnB,MAAMmC,iBAAiBjC,uCAAuC;CAC9D,MAAMkC,iBAAiBjC,kCAAkC;CA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,MAAMwH,iBACHrG,KAAasG,aAAarB,KAAAA,IACrBjF,KAAasG,WACbzH,OAAO0H,MAAkCD;EACjD,OACE,oBAAC,KAAK,MAAN;GAAW,GAAIlB;GACZ5H,UAAAA,aAAaqB,QAAQoG,KAAAA,GAAWoB,cAAc;EACtC,CAAA;CAEf;CAGA,OAAO,oBADWzH,UAAU7B,KAAK2J,OAAOhJ,kBACjC,EAAW,GAAI0H,WAAW,CAAA;AACnC,CACF;AAEA5G,uBAAuBmI,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerQuote.js","names":["c","_c","Primitive","ComponentRef","ComponentPropsWithoutRef","forwardRef","useCallback","useAui","useAuiState","composeEventHandlers","ComposerPrimitiveQuote","Element","div","Props","props","forwardedRef","$","quote","_temp","t0","displayName","ComposerPrimitiveQuoteText","span","children","text","_temp2","t1","t2","ComposerPrimitiveQuoteDismiss","button","onClick","aui","composer","setQuote","undefined","handleDismiss","t3","s"],"sources":["../../../src/primitives/composer/ComposerQuote.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport {\n type ComponentRef,\n type ComponentPropsWithoutRef,\n forwardRef,\n useCallback,\n} from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\n\n// ---- Root ----\n\nexport namespace ComposerPrimitiveQuote {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\n/**\n * Renders a container for the quoted text preview in the composer.\n * Only renders when a quote is set.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Quote>\n * <ComposerPrimitive.QuoteText />\n * <ComposerPrimitive.QuoteDismiss>×</ComposerPrimitive.QuoteDismiss>\n * </ComposerPrimitive.Quote>\n * ```\n */\nexport const ComposerPrimitiveQuote = forwardRef<\n ComposerPrimitiveQuote.Element,\n ComposerPrimitiveQuote.Props\n>((props, forwardedRef) => {\n const quote = useAuiState((s) => s.composer.quote);\n if (!quote) return null;\n\n return <Primitive.div {...props} ref={forwardedRef} />;\n});\n\nComposerPrimitiveQuote.displayName = \"ComposerPrimitive.Quote\";\n\n// ---- QuoteText ----\n\nexport namespace ComposerPrimitiveQuoteText {\n export type Element = ComponentRef<typeof Primitive.span>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.span>;\n}\n\n/**\n * Renders the quoted text content.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.QuoteText />\n * ```\n */\nexport const ComposerPrimitiveQuoteText = forwardRef<\n ComposerPrimitiveQuoteText.Element,\n ComposerPrimitiveQuoteText.Props\n>(({ children, ...props }, forwardedRef) => {\n const text = useAuiState((s) => s.composer.quote?.text);\n if (!text) return null;\n\n return (\n <Primitive.span {...props} ref={forwardedRef}>\n {children ?? text}\n </Primitive.span>\n );\n});\n\nComposerPrimitiveQuoteText.displayName = \"ComposerPrimitive.QuoteText\";\n\n// ---- QuoteDismiss ----\n\nexport namespace ComposerPrimitiveQuoteDismiss {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\n/**\n * A button that clears the current quote from the composer.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.QuoteDismiss>×</ComposerPrimitive.QuoteDismiss>\n * ```\n */\nexport const ComposerPrimitiveQuoteDismiss = forwardRef<\n ComposerPrimitiveQuoteDismiss.Element,\n ComposerPrimitiveQuoteDismiss.Props\n>(({ onClick, ...props }, forwardedRef) => {\n const aui = useAui();\n const handleDismiss = useCallback(() => {\n aui.composer
|
|
1
|
+
{"version":3,"file":"ComposerQuote.js","names":["c","_c","Primitive","ComponentRef","ComponentPropsWithoutRef","forwardRef","useCallback","useAui","useAuiState","composeEventHandlers","ComposerPrimitiveQuote","Element","div","Props","props","forwardedRef","$","quote","_temp","t0","displayName","ComposerPrimitiveQuoteText","span","children","text","_temp2","t1","t2","ComposerPrimitiveQuoteDismiss","button","onClick","aui","composer","setQuote","undefined","handleDismiss","t3","s"],"sources":["../../../src/primitives/composer/ComposerQuote.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport {\n type ComponentRef,\n type ComponentPropsWithoutRef,\n forwardRef,\n useCallback,\n} from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\n\n// ---- Root ----\n\nexport namespace ComposerPrimitiveQuote {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\n/**\n * Renders a container for the quoted text preview in the composer.\n * Only renders when a quote is set.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Quote>\n * <ComposerPrimitive.QuoteText />\n * <ComposerPrimitive.QuoteDismiss>×</ComposerPrimitive.QuoteDismiss>\n * </ComposerPrimitive.Quote>\n * ```\n */\nexport const ComposerPrimitiveQuote = forwardRef<\n ComposerPrimitiveQuote.Element,\n ComposerPrimitiveQuote.Props\n>((props, forwardedRef) => {\n const quote = useAuiState((s) => s.composer.quote);\n if (!quote) return null;\n\n return <Primitive.div {...props} ref={forwardedRef} />;\n});\n\nComposerPrimitiveQuote.displayName = \"ComposerPrimitive.Quote\";\n\n// ---- QuoteText ----\n\nexport namespace ComposerPrimitiveQuoteText {\n export type Element = ComponentRef<typeof Primitive.span>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.span>;\n}\n\n/**\n * Renders the quoted text content.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.QuoteText />\n * ```\n */\nexport const ComposerPrimitiveQuoteText = forwardRef<\n ComposerPrimitiveQuoteText.Element,\n ComposerPrimitiveQuoteText.Props\n>(({ children, ...props }, forwardedRef) => {\n const text = useAuiState((s) => s.composer.quote?.text);\n if (!text) return null;\n\n return (\n <Primitive.span {...props} ref={forwardedRef}>\n {children ?? text}\n </Primitive.span>\n );\n});\n\nComposerPrimitiveQuoteText.displayName = \"ComposerPrimitive.QuoteText\";\n\n// ---- QuoteDismiss ----\n\nexport namespace ComposerPrimitiveQuoteDismiss {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\n/**\n * A button that clears the current quote from the composer.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.QuoteDismiss>×</ComposerPrimitive.QuoteDismiss>\n * ```\n */\nexport const ComposerPrimitiveQuoteDismiss = forwardRef<\n ComposerPrimitiveQuoteDismiss.Element,\n ComposerPrimitiveQuoteDismiss.Props\n>(({ onClick, ...props }, forwardedRef) => {\n const aui = useAui();\n const handleDismiss = useCallback(() => {\n aui.composer.setQuote(undefined);\n }, [aui]);\n\n return (\n <Primitive.button\n type=\"button\"\n {...props}\n ref={forwardedRef}\n onClick={composeEventHandlers(onClick, handleDismiss)}\n />\n );\n});\n\nComposerPrimitiveQuoteDismiss.displayName = \"ComposerPrimitive.QuoteDismiss\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+BA,MAAaU,yBAAyBL,YAGpCS,OAAAC,iBAAA;CAAA,MAAAC,IAAAf,EAAA,CAAA;CAEA,IAAI,CADUO,YAAYU,KACrBD,GAAK,OAAS;CAAK,IAAAE;CAAA,IAAAH,EAAA,OAAAD,gBAAAC,EAAA,OAAAF,OAAA;EAEjBK,KAAA,oBAAA,UAAA,KAAA;GAAA,GAAmBL;GAAYC,KAAAA;EAAY,CAAA;EAAIC,EAAA,KAAAD;EAAAC,EAAA,KAAAF;EAAAE,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,OAA/CG;AAA+C,CACvD;AAEDT,uBAAuBU,cAAc;;;;;;;;;AAiBrC,MAAaC,6BAA6BhB,YAGxCc,IAAAJ,iBAAA;CAAA,MAAAC,IAAAf,EAAA,CAAA;CAAA,IAAAsB;CAAA,IAAAT;CAAA,IAAAE,EAAA,OAAAG,IAAA;EAAC,CAAA,CAAAI,aAAAT,SAAAK;EAAsBH,EAA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c;EAAAd,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,IAAAoB;CAAA,IAAApB,EAAA,OAAAD,gBAAAC,EAAA,OAAAF,SAAAE,EAAA,QAAAW,IAAA;EAJvDS,KAAA,oBAAA,UAAA,QAAA;GACO,MAAA;GAAQ,GACTtB;GACCC,KAAAA;GACI,SAAAY;EAA4C,CAAA;EACrDX,EAAA,KAAAD;EAAAC,EAAA,KAAAF;EAAAE,EAAA,MAAAW;EAAAX,EAAA,MAAAoB;CAAA,OAAAA,KAAApB,EAAA;CAAA,OALFoB;AAKE,CAEL;AAEDR,8BAA8BR,cAAc;AA1E1C,SAAAF,MAAAmB,GAAA;CAAA,OACiCA,EAACL,SAASf;AAAM;AA0BjD,SAAAQ,OAAAY,GAAA;CAAA,OACgCA,EAACL,SAASf,OAAYO;AAAA"}
|
|
@@ -9,11 +9,11 @@ const useComposerStopDictation = () => {
|
|
|
9
9
|
const aui = useAui();
|
|
10
10
|
const isDictating = useAuiState(_temp);
|
|
11
11
|
let t0;
|
|
12
|
-
if ($[0] !== aui) {
|
|
12
|
+
if ($[0] !== aui.composer) {
|
|
13
13
|
t0 = () => {
|
|
14
|
-
aui.composer
|
|
14
|
+
aui.composer.stopDictation();
|
|
15
15
|
};
|
|
16
|
-
$[0] = aui;
|
|
16
|
+
$[0] = aui.composer;
|
|
17
17
|
$[1] = t0;
|
|
18
18
|
} else t0 = $[1];
|
|
19
19
|
const callback = t0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerStopDictation.js","names":["c","_c","useCallback","useAui","ActionButtonElement","ActionButtonProps","createActionButton","useAuiState","useComposerStopDictation","$","aui","isDictating","_temp","t0","composer","stopDictation","callback","ComposerPrimitiveStopDictation","Element","Props","s","dictation"],"sources":["../../../src/primitives/composer/ComposerStopDictation.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type {\n ActionButtonElement,\n ActionButtonProps,\n} from \"../../utils/createActionButton\";\nimport { createActionButton } from \"../../utils/createActionButton\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\nconst useComposerStopDictation = () => {\n const aui = useAui();\n const isDictating = useAuiState((s) => s.composer.dictation != null);\n\n const callback = useCallback(() => {\n aui.composer
|
|
1
|
+
{"version":3,"file":"ComposerStopDictation.js","names":["c","_c","useCallback","useAui","ActionButtonElement","ActionButtonProps","createActionButton","useAuiState","useComposerStopDictation","$","aui","isDictating","_temp","t0","composer","stopDictation","callback","ComposerPrimitiveStopDictation","Element","Props","s","dictation"],"sources":["../../../src/primitives/composer/ComposerStopDictation.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type {\n ActionButtonElement,\n ActionButtonProps,\n} from \"../../utils/createActionButton\";\nimport { createActionButton } from \"../../utils/createActionButton\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\nconst useComposerStopDictation = () => {\n const aui = useAui();\n const isDictating = useAuiState((s) => s.composer.dictation != null);\n\n const callback = useCallback(() => {\n aui.composer.stopDictation();\n }, [aui]);\n\n if (!isDictating) return null;\n return callback;\n};\n\nexport namespace ComposerPrimitiveStopDictation {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useComposerStopDictation>;\n}\n\n/**\n * A button that stops the current dictation session.\n *\n * Only rendered when dictation is active.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.StopDictation>\n * <StopIcon />\n * </ComposerPrimitive.StopDictation>\n * ```\n */\nexport const ComposerPrimitiveStopDictation = createActionButton(\n \"ComposerPrimitive.StopDictation\",\n useComposerStopDictation,\n);\n"],"mappings":";;;;;;AAWA,MAAMQ,iCAA2B;CAAA,MAAAC,IAAAR,EAAA,CAAA;CAC/B,MAAAS,MAAYP,OAAO;CACnB,MAAAQ,cAAoBJ,YAAYK,KAAmC;CAAE,IAAAC;CAAA,IAAAJ,EAAA,OAAAC,IAAAI,UAAA;EAExCD,WAAA;GAC3BH,IAAGI,SAASC,cAAe;EAAC;EAC7BN,EAAA,KAAAC,IAAAI;EAAAL,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAFD,MAAAO,WAAiBH;CAIjB,IAAI,CAACF,aAAW,OAAS;CAAK,OACvBK;AAAQ;;;;;;;;;;;;;AAoBjB,MAAaC,iCAAiCX,mBAC5C,mCACAE,wBACF;AAhCiC,SAAAI,MAAAQ,GAAA;CAAA,OAEQA,EAACN,SAASO,aAAc;AAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggerSelectionResource.d.ts","names":[],"sources":["../../../../src/primitives/composer/trigger/triggerSelectionResource.ts"],"mappings":";;;;;KAUY,sBAAsB,MAAM;KAE5B;WAEG;WACA,WAAW;WACX,cAAc,MAAM;;WAGpB;WACA,WAAW;WACX,YAAY,MAAM;WAClB;;KAGH;;EAEV,WAAW,MAAM;;EAEjB;;EAEA,2BAA2B,IAAI;;
|
|
1
|
+
{"version":3,"file":"triggerSelectionResource.d.ts","names":[],"sources":["../../../../src/primitives/composer/trigger/triggerSelectionResource.ts"],"mappings":";;;;;KAUY,sBAAsB,MAAM;KAE5B;WAEG;WACA,WAAW;WACX,cAAc,MAAM;;WAGpB;WACA,WAAW;WACX,YAAY,MAAM;WAClB;;KAGH;;EAEV,WAAW,MAAM;;EAEjB;;EAEA,2BAA2B,IAAI;;cAyFpB,sDAAwB,SAAA;EA7EzB,UAAA;EACD,SAAA;EACJ,KAAA;EACQ;EACM,oBAAC;;EAER"}
|
|
@@ -26,18 +26,18 @@ const useTriggerSelectionResource = (t0) => {
|
|
|
26
26
|
onSelected();
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
const currentText = aui.composer
|
|
29
|
+
const currentText = aui.composer.getState().text;
|
|
30
30
|
const before = currentText.slice(0, trigger.offset);
|
|
31
31
|
const after = currentText.slice(trigger.offset + triggerChar.length + trigger.query.length);
|
|
32
32
|
const insertDirective = () => {
|
|
33
33
|
const directive = behavior.formatter.serialize(item);
|
|
34
|
-
aui.composer
|
|
34
|
+
aui.composer.setText(before + directive + (after.startsWith(" ") ? after : ` ${after}`));
|
|
35
35
|
};
|
|
36
36
|
if (behavior.kind === "directive") {
|
|
37
37
|
insertDirective();
|
|
38
38
|
behavior.onInserted?.(item);
|
|
39
39
|
} else {
|
|
40
|
-
if (behavior.removeOnExecute) aui.composer
|
|
40
|
+
if (behavior.removeOnExecute) aui.composer.setText(before + (after.startsWith(" ") ? after.slice(1) : after));
|
|
41
41
|
else insertDirective();
|
|
42
42
|
behavior.onExecute(item);
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggerSelectionResource.js","names":["useEffectEvent","useRef","resource","Unstable_DirectiveFormatter","Unstable_TriggerItem","AssistantClient","DetectedTrigger","SelectItemOverride","item","TriggerBehavior","kind","formatter","onInserted","onExecute","removeOnExecute","TriggerSelectionResourceOutput","selectItem","close","registerSelectItemOverride","fn","useTriggerSelectionResource","t0","$","_c","behavior","trigger","aui","triggerChar","setCursorPosition","onSelected","selectItemOverrideRef","t1","Symbol","for","current","t2","currentText","composer","getState","text","before","slice","offset","after","length","query","insertDirective","directive","serialize","setText","startsWith","t3","t4","TriggerSelectionResource"],"sources":["../../../../src/primitives/composer/trigger/triggerSelectionResource.ts"],"sourcesContent":["import { useEffectEvent, useRef } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type {\n Unstable_DirectiveFormatter,\n Unstable_TriggerItem,\n} from \"@assistant-ui/core\";\nimport type { AssistantClient } from \"@assistant-ui/store\";\nimport type { DetectedTrigger } from \"./triggerDetectionResource\";\n\n/** External override for selection (used by Lexical's DirectivePlugin). */\nexport type SelectItemOverride = (item: Unstable_TriggerItem) => boolean;\n\nexport type TriggerBehavior =\n | {\n readonly kind: \"directive\";\n readonly formatter: Unstable_DirectiveFormatter;\n readonly onInserted?: (item: Unstable_TriggerItem) => void;\n }\n | {\n readonly kind: \"action\";\n readonly formatter: Unstable_DirectiveFormatter;\n readonly onExecute: (item: Unstable_TriggerItem) => void;\n readonly removeOnExecute?: boolean;\n };\n\nexport type TriggerSelectionResourceOutput = {\n /** Select an item — runs override (if any) then applies behavior. */\n selectItem(item: Unstable_TriggerItem): void;\n /** Close the popover (moves cursor before trigger to deactivate detection). */\n close(): void;\n /** Register a Lexical-style selection override. Returns unregister fn. */\n registerSelectItemOverride(fn: SelectItemOverride): () => void;\n};\n\n/** Owns composer text mutation + behavior dispatch on item selection. */\nconst useTriggerSelectionResource = ({\n behavior,\n trigger,\n aui,\n triggerChar,\n setCursorPosition,\n onSelected,\n}: {\n behavior: TriggerBehavior | undefined;\n trigger: DetectedTrigger | null;\n aui: AssistantClient;\n triggerChar: string;\n setCursorPosition: (pos: number) => void;\n /** Called after a successful selection so the parent can reset nav state. */\n onSelected: () => void;\n}): TriggerSelectionResourceOutput => {\n // Select-item override: lets Lexical's DirectivePlugin intercept selection\n // and drive its own node insertion.\n const selectItemOverrideRef = useRef<SelectItemOverride | null>(null);\n\n const registerSelectItemOverride = useEffectEvent(\n (fn: SelectItemOverride) => {\n selectItemOverrideRef.current = fn;\n return () => {\n if (selectItemOverrideRef.current === fn) {\n selectItemOverrideRef.current = null;\n }\n };\n },\n );\n\n const selectItem = useEffectEvent((item: Unstable_TriggerItem) => {\n if (!trigger || !behavior) return;\n\n if (selectItemOverrideRef.current?.(item)) {\n onSelected();\n return;\n }\n\n const currentText = aui.composer
|
|
1
|
+
{"version":3,"file":"triggerSelectionResource.js","names":["useEffectEvent","useRef","resource","Unstable_DirectiveFormatter","Unstable_TriggerItem","AssistantClient","DetectedTrigger","SelectItemOverride","item","TriggerBehavior","kind","formatter","onInserted","onExecute","removeOnExecute","TriggerSelectionResourceOutput","selectItem","close","registerSelectItemOverride","fn","useTriggerSelectionResource","t0","$","_c","behavior","trigger","aui","triggerChar","setCursorPosition","onSelected","selectItemOverrideRef","t1","Symbol","for","current","t2","currentText","composer","getState","text","before","slice","offset","after","length","query","insertDirective","directive","serialize","setText","startsWith","t3","t4","TriggerSelectionResource"],"sources":["../../../../src/primitives/composer/trigger/triggerSelectionResource.ts"],"sourcesContent":["import { useEffectEvent, useRef } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type {\n Unstable_DirectiveFormatter,\n Unstable_TriggerItem,\n} from \"@assistant-ui/core\";\nimport type { AssistantClient } from \"@assistant-ui/store\";\nimport type { DetectedTrigger } from \"./triggerDetectionResource\";\n\n/** External override for selection (used by Lexical's DirectivePlugin). */\nexport type SelectItemOverride = (item: Unstable_TriggerItem) => boolean;\n\nexport type TriggerBehavior =\n | {\n readonly kind: \"directive\";\n readonly formatter: Unstable_DirectiveFormatter;\n readonly onInserted?: (item: Unstable_TriggerItem) => void;\n }\n | {\n readonly kind: \"action\";\n readonly formatter: Unstable_DirectiveFormatter;\n readonly onExecute: (item: Unstable_TriggerItem) => void;\n readonly removeOnExecute?: boolean;\n };\n\nexport type TriggerSelectionResourceOutput = {\n /** Select an item — runs override (if any) then applies behavior. */\n selectItem(item: Unstable_TriggerItem): void;\n /** Close the popover (moves cursor before trigger to deactivate detection). */\n close(): void;\n /** Register a Lexical-style selection override. Returns unregister fn. */\n registerSelectItemOverride(fn: SelectItemOverride): () => void;\n};\n\n/** Owns composer text mutation + behavior dispatch on item selection. */\nconst useTriggerSelectionResource = ({\n behavior,\n trigger,\n aui,\n triggerChar,\n setCursorPosition,\n onSelected,\n}: {\n behavior: TriggerBehavior | undefined;\n trigger: DetectedTrigger | null;\n aui: AssistantClient;\n triggerChar: string;\n setCursorPosition: (pos: number) => void;\n /** Called after a successful selection so the parent can reset nav state. */\n onSelected: () => void;\n}): TriggerSelectionResourceOutput => {\n // Select-item override: lets Lexical's DirectivePlugin intercept selection\n // and drive its own node insertion.\n const selectItemOverrideRef = useRef<SelectItemOverride | null>(null);\n\n const registerSelectItemOverride = useEffectEvent(\n (fn: SelectItemOverride) => {\n selectItemOverrideRef.current = fn;\n return () => {\n if (selectItemOverrideRef.current === fn) {\n selectItemOverrideRef.current = null;\n }\n };\n },\n );\n\n const selectItem = useEffectEvent((item: Unstable_TriggerItem) => {\n if (!trigger || !behavior) return;\n\n if (selectItemOverrideRef.current?.(item)) {\n onSelected();\n return;\n }\n\n const currentText = aui.composer.getState().text;\n const before = currentText.slice(0, trigger.offset);\n const after = currentText.slice(\n trigger.offset + triggerChar.length + trigger.query.length,\n );\n\n const insertDirective = () => {\n const directive = behavior.formatter.serialize(item);\n aui.composer.setText(\n before + directive + (after.startsWith(\" \") ? after : ` ${after}`),\n );\n };\n\n if (behavior.kind === \"directive\") {\n insertDirective();\n behavior.onInserted?.(item);\n } else {\n if (behavior.removeOnExecute) {\n aui.composer.setText(\n before + (after.startsWith(\" \") ? after.slice(1) : after),\n );\n } else {\n // Leave directive chip in the composer as an audit trail\n insertDirective();\n }\n behavior.onExecute(item);\n }\n\n onSelected();\n });\n\n const close = useEffectEvent(() => {\n onSelected();\n // Move cursor before the trigger so trigger detection deactivates\n if (trigger) {\n setCursorPosition(trigger.offset);\n }\n });\n\n return {\n selectItem,\n close,\n registerSelectItemOverride,\n };\n};\n\nexport const TriggerSelectionResource = resource(useTriggerSelectionResource);\n"],"mappings":";;;;;AAmCA,MAAMoB,+BAA8BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,UAAAC,SAAAC,KAAAC,aAAAC,mBAAAC,eAAAR;CAkBnC,MAAAS,wBAA8B7B,OAAkC,IAAI;CAAE,IAAA8B;CAAA,IAAAT,EAAA,OAAAU,OAAAC,IAAA,2BAAA,GAAA;EAGpEF,MAAAZ,OAAA;GACEW,sBAAqBI,UAAWf;GAAH,aACtB;IACL,IAAIW,sBAAqBI,YAAaf,IACpCW,sBAAqBI,UAAW;GACjC;EACF;EACFZ,EAAA,KAAAS;CAAA,OAAAA,KAAAT,EAAA;CARH,MAAAJ,6BAAmClB,eACjC+B,EAQF;CAAE,IAAAI;CAAA,IAAAb,EAA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QAAOiB,MAAO;EACjC;EACFpB,EAAA,KAAAO;EAAAP,EAAA,KAAAM;EAAAN,EAAA,KAAAG;EAAAH,EAAA,MAAA6B;CAAA,OAAAA,KAAA7B,EAAA;CAND,MAAAL,QAAcjB,eAAemD,EAM5B;CAAE,IAAAC;CAAA,IAAA9B,EAAA,QAAAL,SAAAK,EAAA,QAAAJ,8BAAAI,EAAA,QAAAN,YAAA;EAEIoC,KAAA;GAAApC;GAAAC;GAAAC;EAIP;EAACI,EAAA,MAAAL;EAAAK,EAAA,MAAAJ;EAAAI,EAAA,MAAAN;EAAAM,EAAA,MAAA8B;CAAA,OAAAA,KAAA9B,EAAA;CAAA,OAJM8B;AAIN;AAGH,MAAaC,2BAA2BnD,SAASkB,2BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartsGrouped.d.ts","names":[],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"mappings":";;;KA8BK;EACH;EACA;;KAGU,oBAAoB,0BAA0B;kBAmDzC;OACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4CV,kBAAkB;;;;;;;IAQlB;;MAGM,QAAQ;;MAER,OAAO;;MAEP,YAAY;;MAEZ,SAAS;;MAET,QAAQ;;MAER,OAAO;;MAEP,iBAAiB;;MAEjB;;QAGM,UACI,eAAe;;QAGnB,WAAW;;;MAIjB;;QAGM,UACI,eAAe;;QAGnB,WAAW,cAAc;;;QAIzB,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAqC9B,QAAQ,cACN;QACE;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"MessagePartsGrouped.d.ts","names":[],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"mappings":";;;KA8BK;EACH;EACA;;KAGU,oBAAoB,0BAA0B;kBAmDzC;OACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4CV,kBAAkB;;;;;;;IAQlB;;MAGM,QAAQ;;MAER,OAAO;;MAEP,YAAY;;MAEZ,SAAS;;MAET,QAAQ;;MAER,OAAO;;MAEP,iBAAiB;;MAEjB;;QAGM,UACI,eAAe;;QAGnB,WAAW;;;MAIjB;;QAGM,UACI,eAAe;;QAGnB,WAAW,cAAc;;;QAIzB,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAqC9B,QAAQ,cACN;QACE;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqOD,uCAAuC,GAClD,sCAAsC;;;;;;;cA2C3B,iDAAiD,GAC5D,KAAK,sCAAsC"}
|