@assistant-ui/react 0.15.25 → 0.15.27
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/hooks/useToolCallElapsed.d.ts.map +1 -1
- package/dist/hooks/useToolCallElapsed.js +3 -2
- package/dist/hooks/useToolCallElapsed.js.map +1 -1
- package/dist/index.d.ts +31 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/mcp-apps/McpAppRenderer.d.ts.map +1 -1
- package/dist/mcp-apps/McpAppRenderer.js +3 -2
- package/dist/mcp-apps/McpAppRenderer.js.map +1 -1
- package/dist/mcp-apps/app-frame.d.ts.map +1 -1
- package/dist/mcp-apps/app-frame.js +58 -48
- package/dist/mcp-apps/app-frame.js.map +1 -1
- package/dist/mcp-apps/bridge.d.ts.map +1 -1
- package/dist/mcp-apps/bridge.js +28 -3
- package/dist/mcp-apps/bridge.js.map +1 -1
- package/dist/mcp-apps/csp.d.ts +4 -0
- package/dist/mcp-apps/csp.d.ts.map +1 -0
- package/dist/mcp-apps/csp.js +93 -0
- package/dist/mcp-apps/csp.js.map +1 -0
- package/dist/mcp-apps/index.d.ts +1 -1
- package/dist/mcp-apps/index.d.ts.map +1 -1
- package/dist/mcp-apps/types.d.ts +19 -1
- package/dist/mcp-apps/types.d.ts.map +1 -1
- package/dist/mcp-apps/types.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.d.ts +1 -0
- package/dist/primitives/assistantModal/AssistantModalRoot.d.ts.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
- package/dist/primitives/attachment.d.ts +3 -1
- package/dist/primitives/attachment.d.ts.map +1 -1
- package/dist/primitives/attachment.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +14 -12
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.d.ts +5 -1
- package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerCancel.js +14 -1
- package/dist/primitives/composer/ComposerCancel.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts +14 -0
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +4 -3
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerRoot.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerRoot.js +24 -19
- package/dist/primitives/composer/ComposerRoot.js.map +1 -1
- package/dist/primitives/composer/composerInputSelector.d.ts +3 -0
- package/dist/primitives/composer/composerInputSelector.d.ts.map +1 -0
- package/dist/primitives/composer/composerInputSelector.js +7 -0
- package/dist/primitives/composer/composerInputSelector.js.map +1 -0
- package/dist/primitives/composer/useComposerCancelWithFocus.d.ts +2 -0
- package/dist/primitives/composer/useComposerCancelWithFocus.d.ts.map +1 -0
- package/dist/primitives/composer/useComposerCancelWithFocus.js +42 -0
- package/dist/primitives/composer/useComposerCancelWithFocus.js.map +1 -0
- package/dist/primitives/composer.d.ts +35 -14
- package/dist/primitives/composer.d.ts.map +1 -1
- package/dist/primitives/composer.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts +8 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +58 -278
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +5 -2
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +4 -3
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/topAnchor/useTopAnchorReserve.js +2 -2
- package/dist/primitives/thread/topAnchor/useTopAnchorReserve.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +90 -21
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/sandbox-host/SandboxHost.d.ts.map +1 -1
- package/dist/sandbox-host/SandboxHost.js +3 -2
- package/dist/sandbox-host/SandboxHost.js.map +1 -1
- package/dist/unstable/useComposerInput.d.ts +9 -4
- package/dist/unstable/useComposerInput.d.ts.map +1 -1
- package/dist/unstable/useComposerInput.js +6 -4
- package/dist/unstable/useComposerInput.js.map +1 -1
- package/dist/unstable/useComposerInputHistory.d.ts +3 -2
- package/dist/unstable/useComposerInputHistory.d.ts.map +1 -1
- package/dist/unstable/useComposerInputHistory.js +2 -2
- package/dist/unstable/useComposerInputHistory.js.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.d.ts +3 -2
- package/dist/unstable/useLiveCompletionAdapter.d.ts.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.js +8 -7
- package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
- package/dist/unstable/useMentionAdapter.d.ts +12 -3
- package/dist/unstable/useMentionAdapter.d.ts.map +1 -1
- package/dist/unstable/useMentionAdapter.js +2 -2
- package/dist/unstable/useMentionAdapter.js.map +1 -1
- package/dist/unstable/useMessageStallDetection.d.ts +4 -2
- package/dist/unstable/useMessageStallDetection.d.ts.map +1 -1
- package/dist/unstable/useMessageStallDetection.js +2 -2
- package/dist/unstable/useMessageStallDetection.js.map +1 -1
- package/dist/unstable/useSlashCommandAdapter.d.ts +5 -2
- package/dist/unstable/useSlashCommandAdapter.d.ts.map +1 -1
- package/dist/unstable/useSlashCommandAdapter.js +5 -4
- package/dist/unstable/useSlashCommandAdapter.js.map +1 -1
- package/dist/unstable/webmcp/useWebMcpProvider.d.ts +4 -0
- package/dist/unstable/webmcp/useWebMcpProvider.d.ts.map +1 -1
- package/dist/unstable/webmcp/useWebMcpProvider.js +2 -0
- package/dist/unstable/webmcp/useWebMcpProvider.js.map +1 -1
- package/dist/utils/getSelectionMessageId.d.ts.map +1 -1
- package/dist/utils/getSelectionMessageId.js +31 -8
- package/dist/utils/getSelectionMessageId.js.map +1 -1
- package/dist/utils/hooks/useOnResizeContent.d.ts.map +1 -1
- package/dist/utils/hooks/useOnResizeContent.js +2 -22
- package/dist/utils/hooks/useOnResizeContent.js.map +1 -1
- package/dist/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/dist/utils/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/dist/utils/useIsomorphicLayoutEffect.js +6 -0
- package/dist/utils/useIsomorphicLayoutEffect.js.map +1 -0
- package/package.json +10 -10
- package/src/hooks/useToolCallElapsed.test.tsx +4 -2
- package/src/hooks/useToolCallElapsed.ts +3 -2
- package/src/index.ts +20 -2
- package/src/mcp-apps/McpAppRenderer.test.tsx +7 -2
- package/src/mcp-apps/McpAppRenderer.tsx +3 -9
- package/src/mcp-apps/app-frame.test.tsx +102 -6
- package/src/mcp-apps/app-frame.tsx +7 -10
- package/src/mcp-apps/bridge.test.ts +154 -0
- package/src/mcp-apps/bridge.ts +51 -9
- package/src/mcp-apps/csp.test.ts +112 -0
- package/src/mcp-apps/csp.ts +124 -0
- package/src/mcp-apps/index.ts +1 -0
- package/src/mcp-apps/types.ts +16 -1
- package/src/model-context/frame/AssistantFrame.test.ts +45 -0
- package/src/model-context/frame/SPEC_AssistantFrame.md +1 -0
- package/src/primitives/assistantModal/AssistantModalRoot.tsx +1 -0
- package/src/primitives/attachment.ts +4 -1
- package/src/primitives/composer/ComposerAttachmentDropzone.test.tsx +32 -1
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +14 -12
- package/src/primitives/composer/ComposerCancel.focus.test.tsx +307 -0
- package/src/primitives/composer/ComposerCancel.ts +8 -1
- package/src/primitives/composer/ComposerDisabledThread.test.tsx +121 -0
- package/src/primitives/composer/ComposerInput.tsx +19 -1
- package/src/primitives/composer/ComposerRoot.tsx +6 -5
- package/src/primitives/composer/composerInputSelector.ts +4 -0
- package/src/primitives/composer/useComposerCancelWithFocus.ts +57 -0
- package/src/primitives/composer.ts +56 -21
- package/src/primitives/message/MessagePartsGrouped.test.tsx +106 -2
- package/src/primitives/message/MessagePartsGrouped.tsx +36 -134
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.test.tsx +20 -12
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +6 -2
- package/src/primitives/thread/ThreadViewport.tsx +3 -3
- package/src/primitives/thread/topAnchor/useTopAnchorReserve.ts +2 -2
- package/src/primitives/thread/useThreadViewportAutoScroll.test.tsx +666 -63
- package/src/primitives/thread/useThreadViewportAutoScroll.ts +201 -73
- package/src/sandbox-host/SandboxHost.tsx +3 -8
- package/src/unstable/useComposerInput.ts +9 -4
- package/src/unstable/useComposerInputHistory.ts +3 -2
- package/src/unstable/useLiveCompletionAdapter.ts +9 -14
- package/src/unstable/useMentionAdapter.ts +12 -3
- package/src/unstable/useMessageStallDetection.ts +4 -2
- package/src/unstable/useSlashCommandAdapter.ts +8 -4
- package/src/unstable/webmcp/useWebMcpProvider.ts +4 -0
- package/src/utils/getSelectionMessageId.test.ts +231 -0
- package/src/utils/getSelectionMessageId.ts +45 -7
- package/src/utils/hooks/useOnResizeContent.ts +2 -29
- package/src/utils/useIsomorphicLayoutEffect.test.tsx +21 -0
- package/src/utils/useIsomorphicLayoutEffect.ts +9 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerAttachmentDropzone.js","names":["forwardRef","useCallback","useEffect","useState","ReactElement","isValidElement","composeEventHandlers","Slot","React","useAui","renderSlot","ComposerPrimitiveAttachmentDropzone","Element","HTMLDivElement","Props","HTMLAttributes","asChild","render","disabled","children","rest","ref","isDragging","setIsDragging","aui","handleDragEnterCapture","e","DragEvent","dataTransfer","types","includes","preventDefault","
|
|
1
|
+
{"version":3,"file":"ComposerAttachmentDropzone.js","names":["forwardRef","useCallback","useEffect","useState","ReactElement","isValidElement","composeEventHandlers","Slot","React","useAui","useAuiState","renderSlot","ComposerPrimitiveAttachmentDropzone","Element","HTMLDivElement","Props","HTMLAttributes","asChild","render","disabled","children","rest","ref","isDragging","setIsDragging","aui","disabledByThread","s","thread","isDisabled","handleDragEnterCapture","e","DragEvent","dataTransfer","types","includes","preventDefault","getState","capabilities","attachments","dropEffect","handleDragOverCapture","handleDragLeaveCapture","next","relatedTarget","Node","currentTarget","contains","handleDrop","files","Array","from","length","Promise","all","map","file","composer","addAttachment","mergedProps","onDragEnterCapture","onDragOverCapture","onDragLeaveCapture","onDropCapture","Comp","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerAttachmentDropzone.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useState,\n type ReactElement,\n isValidElement,\n} from \"react\";\n\nimport { composeEventHandlers } from \"radix-ui/internal\";\nimport { Slot } from \"radix-ui\";\nimport type React from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { renderSlot } from \"../../utils/Primitive\";\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 const disabledByThread = useAuiState((s) => s.thread.isDisabled);\n const isDisabled = disabled || disabledByThread;\n\n useEffect(() => {\n if (!isDisabled) return;\n // Disabled handlers cannot clear the latch, so reset it when the enabled period ends.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setIsDragging(false);\n }, [isDisabled]);\n\n // An unprevented file drop navigates the tab to the file, so file drags are\n // claimed via preventDefault even when the runtime does not support attachments.\n const handleDragEnterCapture = useCallback(\n (e: React.DragEvent) => {\n if (!e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n if (isDisabled || !aui.thread.getState().capabilities.attachments) {\n e.dataTransfer.dropEffect = \"none\";\n return;\n }\n setIsDragging(true);\n },\n [isDisabled, aui],\n );\n\n const handleDragOverCapture = useCallback(\n (e: React.DragEvent) => {\n if (!e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n if (isDisabled || !aui.thread.getState().capabilities.attachments) {\n e.dataTransfer.dropEffect = \"none\";\n return;\n }\n if (!isDragging) setIsDragging(true);\n },\n [isDisabled, isDragging, aui],\n );\n\n const handleDragLeaveCapture = useCallback(\n (e: React.DragEvent) => {\n if (isDisabled) 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 [isDisabled],\n );\n\n const handleDrop = useCallback(\n async (e: React.DragEvent) => {\n setIsDragging(false);\n if (!e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n if (isDisabled) return;\n const files = Array.from(e.dataTransfer.files);\n if (!aui.thread.getState().capabilities.attachments || files.length === 0)\n return;\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 [isDisabled, aui],\n );\n\n const mergedProps = {\n ...(isDragging && !isDisabled ? { \"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 return renderSlot(render, children, mergedProps);\n }\n\n const Comp = asChild ? Slot.Root : \"div\";\n return <Comp {...mergedProps}>{children}</Comp>;\n});\n\nComposerPrimitiveAttachmentDropzone.displayName =\n \"ComposerPrimitive.AttachmentDropzone\";\n"],"mappings":";;;;;;;;AA0BA,MAAaY,sCAAsCZ,YAGhD,EAAEmB,UAAUF,UAAU,OAAOC,QAAQE,UAAU,GAAGC,QAAQC,QAAQ;CACnE,MAAM,CAACC,YAAYC,iBAAiBrB,SAAS,KAAK;CAClD,MAAMsB,MAAMhB,OAAO;CACnB,MAAMiB,mBAAmBhB,aAAaiB,MAAMA,EAAEC,OAAOC,UAAU;CAC/D,MAAMA,aAAaV,YAAYO;CAE/BxB,gBAAgB;EACd,IAAI,CAAC2B,YAAY;EAGjBL,cAAc,KAAK;CACrB,GAAG,CAACK,UAAU,CAAC;CAIf,MAAMC,yBAAyB7B,aAC5B8B,MAAuB;EACtB,IAAI,CAACA,EAAEE,aAAaC,MAAMC,SAAS,OAAO,GAAG;EAC7CJ,EAAEK,eAAe;EACjB,IAAIP,cAAc,CAACJ,IAAIG,OAAOS,SAAS,CAAC,CAACC,aAAaC,aAAa;GACjER,EAAEE,aAAaO,aAAa;GAC5B;EACF;EACAhB,cAAc,IAAI;CACpB,GACA,CAACK,YAAYJ,GAAG,CAClB;CAEA,MAAMgB,wBAAwBxC,aAC3B8B,QAAuB;EACtB,IAAI,CAACA,IAAEE,aAAaC,MAAMC,SAAS,OAAO,GAAG;EAC7CJ,IAAEK,eAAe;EACjB,IAAIP,cAAc,CAACJ,IAAIG,OAAOS,SAAS,CAAC,CAACC,aAAaC,aAAa;GACjER,IAAEE,aAAaO,aAAa;GAC5B;EACF;EACA,IAAI,CAACjB,YAAYC,cAAc,IAAI;CACrC,GACA;EAACK;EAAYN;EAAYE;CAAG,CAC9B;CAEA,MAAMiB,yBAAyBzC,aAC5B8B,QAAuB;EACtB,IAAIF,YAAY;EAChBE,IAAEK,eAAe;EACjB,MAAMO,OAAOZ,IAAEa;EACf,IAAID,QAAQZ,IAAEe,cAAcC,SAASJ,IAAI,GACvC;EAEFnB,cAAc,KAAK;CACrB,GACA,CAACK,UAAU,CACb;CAEA,MAAMmB,aAAa/C,YACjB,OAAO8B,QAAuB;EAC5BP,cAAc,KAAK;EACnB,IAAI,CAACO,IAAEE,aAAaC,MAAMC,SAAS,OAAO,GAAG;EAC7CJ,IAAEK,eAAe;EACjB,IAAIP,YAAY;EAChB,MAAMoB,QAAQC,MAAMC,KAAKpB,IAAEE,aAAagB,KAAK;EAC7C,IAAI,CAACxB,IAAIG,OAAOS,SAAS,CAAC,CAACC,aAAaC,eAAeU,MAAMG,WAAW,GACtE;EACF,MAAMC,QAAQC,IACZL,MAAMM,IAAI,OAAOC,SAAS;GACxB,IAAI;IACF,MAAM/B,IAAIgC,SAASC,cAAcF,IAAI;GACvC,QAAQ,CAEN;EAEJ,CAAC,CACH;CACF,GACA,CAAC3B,YAAYJ,GAAG,CAClB;CAEA,MAAMkC,cAAc;EAClB,GAAIpC,cAAc,CAACM,aAAa,EAAE,iBAAiB,OAAO,IAAI;EAC9D,GAAGR;EACHuC,oBAAoBtD,qBAClBe,KAAKuC,oBACL9B,sBACF;EACA+B,mBAAmBvD,qBACjBe,KAAKwC,mBACLpB,qBACF;EACAqB,oBAAoBxD,qBAClBe,KAAKyC,oBACLpB,sBACF;EACAqB,eAAezD,qBAAqBe,KAAK0C,eAAef,UAAU;EAClE1B;CACF;CAEA,IAAIJ,UAAUb,eAAea,MAAM,GACjC,OAAOP,WAAWO,QAAQE,UAAUuC,WAAW;CAGjD,MAAMK,OAAO/C,UAAUV,KAAK0D,OAAO;CACnC,OAAO,oBAAC,MAAD;EAAM,GAAIN;EAAcvC;CAAe,CAAA;AAChD,CAAC;AAEDR,oCAAoCsD,cAClC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ActionButtonElement, type ActionButtonProps } from "../../utils/createActionButton.js";
|
|
2
|
-
|
|
2
|
+
import type { MouseEvent } from "react";
|
|
3
|
+
declare const useComposerCancel: () => ((event: MouseEvent<HTMLButtonElement>) => void) | null;
|
|
3
4
|
export declare namespace ComposerPrimitiveCancel {
|
|
4
5
|
type Element = ActionButtonElement;
|
|
5
6
|
/**
|
|
@@ -13,6 +14,9 @@ export declare namespace ComposerPrimitiveCancel {
|
|
|
13
14
|
*
|
|
14
15
|
* This component automatically handles the cancel functionality and is disabled
|
|
15
16
|
* when canceling is not available.
|
|
17
|
+
* Keyboard or assistive-technology activation after editing returns focus to the
|
|
18
|
+
* main thread composer when available, unless a handler has moved focus elsewhere.
|
|
19
|
+
* Pointer activation preserves the existing focus behavior.
|
|
16
20
|
*
|
|
17
21
|
* @example
|
|
18
22
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerCancel.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerCancel.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EAEvB,0CAAuC;
|
|
1
|
+
{"version":3,"file":"ComposerCancel.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerCancel.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EAEvB,0CAAuC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAIxC,QAAA,MAAM,iBAAiB,iBAIN,UAAU,CAAC,iBAAiB,CAAC,iBAE7C,CAAC;AAEF,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C;;;OAGG;IACH,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,iBAAiB,CAAC,CAAC;CACjE;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB;;;;gHAGnC,CAAC"}
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createActionButton } from "../../utils/createActionButton.js";
|
|
3
|
+
import { useComposerCancelWithFocus } from "./useComposerCancelWithFocus.js";
|
|
4
|
+
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
5
|
import { useComposerCancel } from "@assistant-ui/core/react";
|
|
4
6
|
//#region src/primitives/composer/ComposerCancel.ts
|
|
5
7
|
const useComposerCancel$1 = () => {
|
|
8
|
+
const $ = c(2);
|
|
6
9
|
const { disabled, cancel } = useComposerCancel();
|
|
10
|
+
const cancelWithFocus = useComposerCancelWithFocus(cancel);
|
|
7
11
|
if (disabled) return null;
|
|
8
|
-
|
|
12
|
+
let t0;
|
|
13
|
+
if ($[0] !== cancelWithFocus) {
|
|
14
|
+
t0 = (event) => cancelWithFocus(event.detail === 0 ? event.currentTarget : null);
|
|
15
|
+
$[0] = cancelWithFocus;
|
|
16
|
+
$[1] = t0;
|
|
17
|
+
} else t0 = $[1];
|
|
18
|
+
return t0;
|
|
9
19
|
};
|
|
10
20
|
/**
|
|
11
21
|
* A button component that cancels the current message composition.
|
|
12
22
|
*
|
|
13
23
|
* This component automatically handles the cancel functionality and is disabled
|
|
14
24
|
* when canceling is not available.
|
|
25
|
+
* Keyboard or assistive-technology activation after editing returns focus to the
|
|
26
|
+
* main thread composer when available, unless a handler has moved focus elsewhere.
|
|
27
|
+
* Pointer activation preserves the existing focus behavior.
|
|
15
28
|
*
|
|
16
29
|
* @example
|
|
17
30
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerCancel.js","names":["ActionButtonElement","ActionButtonProps","createActionButton","useComposerCancel","useComposerCancelBehavior","disabled","cancel","ComposerPrimitiveCancel","Element","Props","useComposerCancel","useComposerCancelBehavior"],"sources":["../../../src/primitives/composer/ComposerCancel.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useComposerCancel as useComposerCancelBehavior } from \"@assistant-ui/core/react\";\n\nconst useComposerCancel = () => {\n const { disabled, cancel } = useComposerCancelBehavior();\n if (disabled) return null;\n return
|
|
1
|
+
{"version":3,"file":"ComposerCancel.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","MouseEvent","useComposerCancel","useComposerCancelBehavior","useComposerCancelWithFocus","$","disabled","cancel","cancelWithFocus","t0","event","detail","currentTarget","ComposerPrimitiveCancel","Element","Props","useComposerCancel","_c","useComposerCancelBehavior"],"sources":["../../../src/primitives/composer/ComposerCancel.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport type { MouseEvent } from \"react\";\nimport { useComposerCancel as useComposerCancelBehavior } from \"@assistant-ui/core/react\";\nimport { useComposerCancelWithFocus } from \"./useComposerCancelWithFocus\";\n\nconst useComposerCancel = () => {\n const { disabled, cancel } = useComposerCancelBehavior();\n const cancelWithFocus = useComposerCancelWithFocus(cancel);\n if (disabled) return null;\n return (event: MouseEvent<HTMLButtonElement>) =>\n cancelWithFocus(event.detail === 0 ? event.currentTarget : null);\n};\n\nexport namespace ComposerPrimitiveCancel {\n export type Element = ActionButtonElement;\n /**\n * Props for the ComposerPrimitive.Cancel component.\n * Inherits all button element props and action button functionality.\n */\n export type Props = ActionButtonProps<typeof useComposerCancel>;\n}\n\n/**\n * A button component that cancels the current message composition.\n *\n * This component automatically handles the cancel functionality and is disabled\n * when canceling is not available.\n * Keyboard or assistive-technology activation after editing returns focus to the\n * main thread composer when available, unless a handler has moved focus elsewhere.\n * Pointer activation preserves the existing focus behavior.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Cancel>\n * Cancel\n * </ComposerPrimitive.Cancel>\n * ```\n */\nexport const ComposerPrimitiveCancel = createActionButton(\n \"ComposerPrimitive.Cancel\",\n useComposerCancel,\n);\n"],"mappings":";;;;;;AAWA,MAAMM,4BAAoB;CAAA,MAAAG,IAAAR,EAAA,CAAA;CACxB,MAAA,EAAAS,UAAAC,WAA6BJ,kBAA0B;CACvD,MAAAK,kBAAwBJ,2BAA2BG,MAAM;CACzD,IAAID,UAAQ,OAAS;CAAK,IAAAG;CAAA,IAAAJ,EAAA,OAAAG,iBAAA;EACnBC,MAAAC,UACLF,gBAAgBE,MAAKC,WAAY,IAAID,MAAKE,gBAA1B,IAA+C;EAACP,EAAA,KAAAG;EAAAH,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,OAD3DI;AAC2D;;;;;;;;;;;;;;;;;AA4BpE,MAAaI,0BAA0Bb,mBACrC,4BACAE,mBACF"}
|
|
@@ -14,21 +14,32 @@ export declare namespace ComposerPrimitiveInput {
|
|
|
14
14
|
render?: ReactElement | undefined;
|
|
15
15
|
/**
|
|
16
16
|
* Whether to cancel message composition when Escape is pressed.
|
|
17
|
+
* After cancelling an edit, focus returns to the main thread composer when
|
|
18
|
+
* available, unless a handler has moved focus elsewhere.
|
|
17
19
|
* @default true
|
|
18
20
|
*/
|
|
19
21
|
cancelOnEscape?: boolean | undefined;
|
|
20
22
|
/**
|
|
21
23
|
* Whether to automatically focus the input when a new run starts.
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Experimental since 2024-10-12. Not scheduled for removal; the API may change in any release.
|
|
26
|
+
*
|
|
22
27
|
* @default true
|
|
23
28
|
*/
|
|
24
29
|
unstable_focusOnRunStart?: boolean | undefined;
|
|
25
30
|
/**
|
|
26
31
|
* Whether to automatically focus the input when scrolling to bottom.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Experimental since 2024-10-12. Not scheduled for removal; the API may change in any release.
|
|
34
|
+
*
|
|
27
35
|
* @default true
|
|
28
36
|
*/
|
|
29
37
|
unstable_focusOnScrollToBottom?: boolean | undefined;
|
|
30
38
|
/**
|
|
31
39
|
* Whether to automatically focus the input when switching threads.
|
|
40
|
+
*
|
|
41
|
+
* @deprecated Experimental since 2024-10-12. Not scheduled for removal; the API may change in any release.
|
|
42
|
+
*
|
|
32
43
|
* @default true
|
|
33
44
|
*/
|
|
34
45
|
unstable_focusOnThreadSwitched?: boolean | undefined;
|
|
@@ -37,6 +48,9 @@ export declare namespace ComposerPrimitiveInput {
|
|
|
37
48
|
* instead of submitting, detected via
|
|
38
49
|
* `(pointer: coarse) and (not (any-pointer: fine))`. Only takes effect
|
|
39
50
|
* when `submitMode` resolves to `"enter"`.
|
|
51
|
+
*
|
|
52
|
+
* @deprecated Experimental since 2026-05-24. Not scheduled for removal; the API may change in any release.
|
|
53
|
+
*
|
|
40
54
|
* @default false
|
|
41
55
|
*/
|
|
42
56
|
unstable_insertNewlineOnTouchEnter?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerInput.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerInput.tsx"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,YAAY,EAOlB,MAAM,OAAO,CAAC;AACf,OAAyB,EACvB,KAAK,qBAAqB,EAE3B,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"ComposerInput.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerInput.tsx"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,YAAY,EAOlB,MAAM,OAAO,CAAC;AACf,OAAyB,EACvB,KAAK,qBAAqB,EAE3B,MAAM,yBAAyB,CAAC;AAmBjC,yBAAiB,sBAAsB,CAAC;IACtC,MAAM,MAAM,OAAO,GAAG,mBAAmB,CAAC;IAE1C,KAAK,SAAS,GAAG;QACf;;;WAGG;QACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC9B;;WAEG;QACH,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;QAClC;;;;;WAKG;QACH,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACrC;;;;;;WAMG;QACH,wBAAwB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC/C;;;;;;WAMG;QACH,8BAA8B,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACrD;;;;;;WAMG;QACH,8BAA8B,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACrD;;;;;;;;;WASG;QACH,kCAAkC,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACzD;;;WAGG;QACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAC5C,CAAC;IAEF,KAAK,eAAe,GAChB;QACE;;;;;;WAMG;QACH,UAAU,CAAC,EAAE,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;QACxD;;;WAGG;QACH,aAAa,CAAC,EAAE,KAAK,CAAC;KACvB,GACD;QACE,UAAU,CAAC,EAAE,KAAK,CAAC;QACnB;;;;WAIG;QACH,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACrC,CAAC;IAEN,MAAM,MAAM,KAAK,GAAG,qBAAqB,GAAG,SAAS,GAAG,eAAe,CAAC;;CACzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,sBAAsB,8HAoTlC,CAAC"}
|
|
@@ -5,6 +5,7 @@ import { useOnScrollToBottom } from "../../utils/hooks/useOnScrollToBottom.js";
|
|
|
5
5
|
import { useMediaQuery } from "../../utils/hooks/useMediaQuery.js";
|
|
6
6
|
import { isCompositionKey } from "../../utils/isCompositionKey.js";
|
|
7
7
|
import { useComposerInputPluginRegistryOptional } from "./ComposerInputPluginContext.js";
|
|
8
|
+
import { useComposerCancelWithFocus } from "./useComposerCancelWithFocus.js";
|
|
8
9
|
import { useComposerInputDisabled, useComposerInputValue, useTriggerPopoverAriaProps } from "./useComposerInputState.js";
|
|
9
10
|
import { forwardRef, isValidElement, useCallback, useEffect, useRef } from "@assistant-ui/tap/react-shim";
|
|
10
11
|
import { useAui } from "@assistant-ui/store";
|
|
@@ -59,6 +60,7 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
59
60
|
const value = useComposerInputValue();
|
|
60
61
|
const isDisabled = useComposerInputDisabled(disabledProp);
|
|
61
62
|
const textareaRef = useRef(null);
|
|
63
|
+
const cancel = useComposerCancelWithFocus(useCallback(() => aui.composer.cancel(), [aui]));
|
|
62
64
|
const ref = useComposedRefs(forwardedRef, textareaRef);
|
|
63
65
|
const compositionRef = useRef(false);
|
|
64
66
|
useEscapeKeydown((e) => {
|
|
@@ -68,9 +70,8 @@ const ComposerPrimitiveInput = forwardRef(({ autoFocus = false, asChild, render,
|
|
|
68
70
|
for (const plugin of pluginRegistry.getPlugins()) if (plugin.handleKeyDown(e)) return;
|
|
69
71
|
}
|
|
70
72
|
if (!cancelOnEscape) return;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
composer.cancel();
|
|
73
|
+
if (aui.composer.getState().canCancel) {
|
|
74
|
+
cancel(textareaRef.current);
|
|
74
75
|
e.preventDefault();
|
|
75
76
|
}
|
|
76
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerInput.js","names":["composeEventHandlers","useComposedRefs","Slot","ClipboardEvent","KeyboardEvent","ReactElement","ReactNode","forwardRef","useCallback","useEffect","useRef","isValidElement","TextareaAutosize","TextareaAutosizeProps","TextareaHeightChangeMeta","useEscapeKeydown","useOnScrollToBottom","useMediaQuery","renderSlot","isCompositionKey","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","key","threadState","thread","hasQueue","capabilities","queue","shiftKey","ctrlKey","metaKey","canSend","send","steer","isRunning","voice","undefined","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","on","ariaComboboxProps","inputProps","name","const","React","ForwardedRef","ChangeEvent","isEditing","nativeIsComposing","isComposing","setText","pos","selectionStart","setCursorPosition","onCompositionStart","CompositionEventHandler","onCompositionEnd","CompositionEvent","SyntheticEvent","children","Component","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"radix-ui/internal\";\nimport { useComposedRefs } from \"radix-ui/internal\";\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 isValidElement,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n type TextareaHeightChangeMeta,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"radix-ui/internal\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useMediaQuery } from \"../../utils/hooks/useMediaQuery\";\nimport { renderSlot } from \"../../utils/Primitive\";\nimport { isCompositionKey } from \"../../utils/isCompositionKey\";\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 `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 // ignore IME composition events\n if (isCompositionKey(e)) 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 (isCompositionKey(e.nativeEvent)) 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; a voice\n // session leaves the decision to canSend\n if (\n threadState.isRunning &&\n !hasQueue &&\n threadState.voice === undefined\n )\n 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(\"threads.selectionChanged\", 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 return renderSlot(\n render,\n (rest as { children?: ReactNode }).children,\n inputProps,\n );\n }\n\n const Component = asChild ? Slot.Root : TextareaAutosize;\n return <Component {...inputProps} />;\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;;;;;;;;;;;;;;AAmCA,MAAM2B,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiH5B,MAAaC,yBAAyBrB,YAKlC,EACEqC,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;CAEzD,MAAMkC,qBACJhB,eAAeC,kBAAkB,QAAQ,SAAS;CACpD,MAAMgB,iBAAiBzC,cACrBqB,qCAAqCX,sBAAsB,IAC7D;CACA,MAAMgC,sBACJrB,sCACAoB,kBACAD,uBAAuB,UACnB,SACAA;CAEN,MAAMG,QAAQnC,sBAAsB;CACpC,MAAMoC,aAAarC,yBAAyBsB,YAAY;CACxD,MAAMgB,cAAcpD,OAA4B,IAAI;CACpD,MAAMqD,MAAM9D,gBAAgBoD,cAAcS,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AAW,GAC7CD,SAAO8E,kBAAkBF,GAAG;EAGlC,CACF;EACAlG,WAAWhD,qBAAqBgD,WAAW8B,cAAc;EACzDuE,oBAAoBrJ,qBACjBoD,KACEiG,0BACG;GACJrF,eAAeE,UAAU;EAC3B,CACF;EACAqF,kBAAkBvJ,qBACfoD,KACEmG,mBACFtF,QAAmD;GAClDD,eAAeE,UAAU;GACzB,IAAI,CAACZ,IAAImB,SAASC,SAAS,CAAC,CAACoE,WAAW;GACxC,MAAM1E,SAASH,IAAEG;GACjB/C,mBAAmB;IACjBiC,IAAImB,SAASwE,QAAQ7E,OAAOR,KAAK;GACnC,CAAC;GACD,MAAMsF,QAAM9E,OAAO+E,kBAAkB/E,OAAOR,MAAM6C;GAClD,IAAIlD,gBACF,KAAK,MAAMe,YAAUf,eAAegB,WAAW,GAC7CD,SAAO8E,kBAAkBF,KAAG;EAGlC,CACF;EACAhG,UAAUlD,qBACRkD,WACCe,QAAiD;GAChD,IAAID,eAAeE,SAAS;GAC5B,MAAME,WAASH,IAAEG;GACjB,MAAM8E,QAAM9E,SAAO+E,kBAAkB/E,SAAOR,MAAM6C;GAClD,IAAIlD,gBACF,KAAK,MAAMe,YAAUf,eAAegB,WAAW,GAC7CD,SAAO8E,kBAAkBF,KAAG;EAGlC,CACF;EACAjG,SAASjD,qBAAqBiD,SAASiD,WAAW;EAClD,GAAI1C,iBACA,EAAEL,gBAAgB4D,mBAAmB,IACrC5D,mBAAmB2C,KAAAA,IACjB,EAAE3C,eAAe,IACjB,CAAC;CACT;CAEA,IAAIlB,UAAUtB,eAAesB,MAAM,GACjC,OAAOf,WACLe,QACCmB,KAAkCsG,UACnClB,UACF;CAGF,MAAMmB,YAAY3H,UAAU9B,KAAK0J,OAAOhJ;CACxC,OAAO,oBAAC,WAAD,EAAW,GAAI4H,WAAW,CAAA;AACnC,CACF;AAEA5G,uBAAuBiI,cAAc"}
|
|
1
|
+
{"version":3,"file":"ComposerInput.js","names":["composeEventHandlers","useComposedRefs","Slot","ClipboardEvent","KeyboardEvent","ReactElement","ReactNode","forwardRef","useCallback","useEffect","useRef","isValidElement","TextareaAutosize","TextareaAutosizeProps","TextareaHeightChangeMeta","useEscapeKeydown","useOnScrollToBottom","useMediaQuery","renderSlot","isCompositionKey","useAui","flushTapSync","useComposerInputPluginRegistryOptional","useComposerCompactContextOptional","useComposerCancelWithFocus","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","cancel","composer","ref","compositionRef","e","current","contains","target","Node","plugin","getPlugins","handleKeyDown","getState","canCancel","preventDefault","handleKeyPress","nativeEvent","key","threadState","thread","hasQueue","capabilities","queue","shiftKey","ctrlKey","metaKey","canSend","send","steer","isRunning","voice","undefined","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","on","ariaComboboxProps","inputProps","name","const","React","ForwardedRef","ChangeEvent","isEditing","nativeIsComposing","isComposing","setText","pos","selectionStart","setCursorPosition","onCompositionStart","CompositionEventHandler","onCompositionEnd","CompositionEvent","SyntheticEvent","children","Component","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"radix-ui/internal\";\nimport { useComposedRefs } from \"radix-ui/internal\";\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 isValidElement,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n type TextareaHeightChangeMeta,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"radix-ui/internal\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useMediaQuery } from \"../../utils/hooks/useMediaQuery\";\nimport { renderSlot } from \"../../utils/Primitive\";\nimport { isCompositionKey } from \"../../utils/isCompositionKey\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { flushTapSync } from \"@assistant-ui/tap\";\nimport { useComposerInputPluginRegistryOptional } from \"./ComposerInputPluginContext\";\nimport { useComposerCompactContextOptional } from \"./ComposerCompactContext\";\nimport { useComposerCancelWithFocus } from \"./useComposerCancelWithFocus\";\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 * After cancelling an edit, focus returns to the main thread composer when\n * available, unless a handler has moved focus elsewhere.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n *\n * @deprecated Experimental since 2024-10-12. Not scheduled for removal; the API may change in any release.\n *\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n *\n * @deprecated Experimental since 2024-10-12. Not scheduled for removal; the API may change in any release.\n *\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n *\n * @deprecated Experimental since 2024-10-12. Not scheduled for removal; the API may change in any release.\n *\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 *\n * @deprecated Experimental since 2026-05-24. Not scheduled for removal; the API may change in any release.\n *\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 `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 cancel = useComposerCancelWithFocus(\n useCallback(() => aui.composer.cancel(), [aui]),\n );\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 // ignore IME composition events\n if (isCompositionKey(e)) 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 cancel(textareaRef.current);\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled) return;\n\n // ignore IME composition events\n if (isCompositionKey(e.nativeEvent)) 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; a voice\n // session leaves the decision to canSend\n if (\n threadState.isRunning &&\n !hasQueue &&\n threadState.voice === undefined\n )\n 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(\"threads.selectionChanged\", 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 return renderSlot(\n render,\n (rest as { children?: ReactNode }).children,\n inputProps,\n );\n }\n\n const Component = asChild ? Slot.Root : TextareaAutosize;\n return <Component {...inputProps} />;\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,MAAM4B,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+H5B,MAAaC,yBAAyBtB,YAKlC,EACEsC,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,MAAMnC,OAAO;CACnB,MAAMoC,iBAAiBlC,uCAAuC;CAC9D,MAAMmC,iBAAiBlC,kCAAkC;CAEzD,MAAMmC,qBACJhB,eAAeC,kBAAkB,QAAQ,SAAS;CACpD,MAAMgB,iBAAiB1C,cACrBsB,qCAAqCX,sBAAsB,IAC7D;CACA,MAAMgC,sBACJrB,sCACAoB,kBACAD,uBAAuB,UACnB,SACAA;CAEN,MAAMG,QAAQnC,sBAAsB;CACpC,MAAMoC,aAAarC,yBAAyBsB,YAAY;CACxD,MAAMgB,cAAcrD,OAA4B,IAAI;CACpD,MAAMsD,SAASxC,2BACbhB,kBAAkB+C,IAAIU,SAASD,OAAO,GAAG,CAACT,GAAG,CAAC,CAChD;CACA,MAAMW,MAAMjE,gBAAgBqD,cAAcS,WAAW;CAErD,MAAMI,iBAAiBzD,OAAO,KAAK;CAEnCK,kBAAkBqD,MAAM;EAEtB,IAAI,CAACL,YAAYM,SAASC,SAASF,EAAEG,MAAc,GAAG;EAGtD,IAAIpD,iBAAiBiD,CAAC,GAAG;EAGzB,IAAIZ,gBACG;QAAA,M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fqD,KACEmG,mBACFpF,QAAmD;GAClDD,eAAeE,UAAU;GACzB,IAAI,CAACd,IAAIU,SAASW,SAAS,CAAC,CAACmE,WAAW;GACxC,MAAMxE,SAASH,IAAEG;GACjBlD,mBAAmB;IACjBkC,IAAIU,SAASiF,QAAQ3E,OAAOV,KAAK;GACnC,CAAC;GACD,MAAMsF,QAAM5E,OAAO6E,kBAAkB7E,OAAOV,MAAM6C;GAClD,IAAIlD,gBACF,KAAK,MAAMiB,YAAUjB,eAAekB,WAAW,GAC7CD,SAAO4E,kBAAkBF,KAAG;EAGlC,CACF;EACAhG,UAAUnD,qBACRmD,WACCiB,QAAiD;GAChD,IAAID,eAAeE,SAAS;GAC5B,MAAME,WAASH,IAAEG;GACjB,MAAM4E,QAAM5E,SAAO6E,kBAAkB7E,SAAOV,MAAM6C;GAClD,IAAIlD,gBACF,KAAK,MAAMiB,YAAUjB,eAAekB,WAAW,GAC7CD,SAAO4E,kBAAkBF,KAAG;EAGlC,CACF;EACAjG,SAASlD,qBAAqBkD,SAASiD,WAAW;EAClD,GAAI1C,iBACA,EAAEL,gBAAgB4D,mBAAmB,IACrC5D,mBAAmB2C,KAAAA,IACjB,EAAE3C,eAAe,IACjB,CAAC;CACT;CAEA,IAAIlB,UAAUvB,eAAeuB,MAAM,GACjC,OAAOhB,WACLgB,QACCmB,KAAkCsG,UACnClB,UACF;CAGF,MAAMmB,YAAY3H,UAAU/B,KAAK2J,OAAOjJ;CACxC,OAAO,oBAAC,WAAD,EAAW,GAAI6H,WAAW,CAAA;AACnC,CACF;AAEA5G,uBAAuBiI,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,iCAA8B;AAClD,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,wBAAwB,EAI9B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ComposerRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,iCAA8B;AAClD,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,wBAAwB,EAI9B,MAAM,OAAO,CAAC;AA0Bf,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1D;;;OAGG;IACH,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG;QACpE;;;;;;;WAOG;QACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAC/B,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,qBAAqB;;;;;IAhC9B;;;;;;;OAOG;cACO,OAAO,GAAG,SAAS;mDAkF/B,CAAC"}
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
import { Primitive as Primitive$1 } from "../../utils/Primitive.js";
|
|
3
3
|
import { useComposerSend } from "./ComposerSend.js";
|
|
4
4
|
import { ComposerCompactContext } from "./ComposerCompactContext.js";
|
|
5
|
+
import { COMPOSER_INPUT_SELECTOR, CONTENT_EDITABLE_SELECTOR } from "./composerInputSelector.js";
|
|
5
6
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
6
7
|
import { forwardRef, useState } from "@assistant-ui/tap/react-shim";
|
|
7
8
|
import { useAuiState } from "@assistant-ui/store";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
import { composeEventHandlers } from "radix-ui/internal";
|
|
10
11
|
//#region src/primitives/composer/ComposerRoot.tsx
|
|
11
|
-
const CONTENT_EDITABLE_SELECTOR = "[contenteditable]:not([contenteditable='false'])";
|
|
12
|
-
const COMPOSER_INPUT_SELECTOR = `textarea:not(:disabled), ${CONTENT_EDITABLE_SELECTOR}`;
|
|
13
12
|
const INTERACTIVE_ELEMENT_SELECTOR = [
|
|
14
13
|
"a",
|
|
15
14
|
"audio[controls]",
|
|
@@ -47,7 +46,7 @@ const INTERACTIVE_ELEMENT_SELECTOR = [
|
|
|
47
46
|
* ```
|
|
48
47
|
*/
|
|
49
48
|
const ComposerPrimitiveRoot = forwardRef((t0, forwardedRef) => {
|
|
50
|
-
const $ = c(
|
|
49
|
+
const $ = c(25);
|
|
51
50
|
let compact;
|
|
52
51
|
let onMouseDown;
|
|
53
52
|
let onSubmit;
|
|
@@ -66,6 +65,7 @@ const ComposerPrimitiveRoot = forwardRef((t0, forwardedRef) => {
|
|
|
66
65
|
rest = $[4];
|
|
67
66
|
}
|
|
68
67
|
const send = useComposerSend();
|
|
68
|
+
const composerType = useAuiState(_temp);
|
|
69
69
|
const [multiline, setMultiline] = useState(false);
|
|
70
70
|
let t1;
|
|
71
71
|
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
@@ -75,7 +75,7 @@ const ComposerPrimitiveRoot = forwardRef((t0, forwardedRef) => {
|
|
|
75
75
|
const compactContext = t1;
|
|
76
76
|
let t2;
|
|
77
77
|
if ($[6] !== compact) {
|
|
78
|
-
t2 = (
|
|
78
|
+
t2 = (s_0) => compact ? s_0.composer.attachments.length === 0 && s_0.composer.quote == null && s_0.composer.queue.length === 0 && s_0.composer.dictation == null && !s_0.composer.text.includes("\n") : false;
|
|
79
79
|
$[6] = compact;
|
|
80
80
|
$[7] = t2;
|
|
81
81
|
} else t2 = $[7];
|
|
@@ -91,7 +91,7 @@ const ComposerPrimitiveRoot = forwardRef((t0, forwardedRef) => {
|
|
|
91
91
|
$[9] = t3;
|
|
92
92
|
} else t3 = $[9];
|
|
93
93
|
const handleSubmit = t3;
|
|
94
|
-
const handleMouseDown =
|
|
94
|
+
const handleMouseDown = _temp2;
|
|
95
95
|
const t4 = compact ? compactContext : null;
|
|
96
96
|
const t5 = isCompact ? "" : void 0;
|
|
97
97
|
let t6;
|
|
@@ -108,35 +108,40 @@ const ComposerPrimitiveRoot = forwardRef((t0, forwardedRef) => {
|
|
|
108
108
|
$[14] = t7;
|
|
109
109
|
} else t7 = $[14];
|
|
110
110
|
let t8;
|
|
111
|
-
if ($[15] !==
|
|
111
|
+
if ($[15] !== composerType || $[16] !== forwardedRef || $[17] !== rest || $[18] !== t5 || $[19] !== t6 || $[20] !== t7) {
|
|
112
112
|
t8 = /* @__PURE__ */ jsx(Primitive$1.form, {
|
|
113
113
|
...rest,
|
|
114
|
+
"data-aui-composer-type": composerType,
|
|
114
115
|
"data-compact": t5,
|
|
115
116
|
ref: forwardedRef,
|
|
116
117
|
onSubmit: t6,
|
|
117
118
|
onMouseDown: t7
|
|
118
119
|
});
|
|
119
|
-
$[15] =
|
|
120
|
-
$[16] =
|
|
121
|
-
$[17] =
|
|
122
|
-
$[18] =
|
|
123
|
-
$[19] =
|
|
124
|
-
$[20] =
|
|
125
|
-
|
|
120
|
+
$[15] = composerType;
|
|
121
|
+
$[16] = forwardedRef;
|
|
122
|
+
$[17] = rest;
|
|
123
|
+
$[18] = t5;
|
|
124
|
+
$[19] = t6;
|
|
125
|
+
$[20] = t7;
|
|
126
|
+
$[21] = t8;
|
|
127
|
+
} else t8 = $[21];
|
|
126
128
|
let t9;
|
|
127
|
-
if ($[
|
|
129
|
+
if ($[22] !== t4 || $[23] !== t8) {
|
|
128
130
|
t9 = /* @__PURE__ */ jsx(ComposerCompactContext.Provider, {
|
|
129
131
|
value: t4,
|
|
130
132
|
children: t8
|
|
131
133
|
});
|
|
132
|
-
$[
|
|
133
|
-
$[
|
|
134
|
-
$[
|
|
135
|
-
} else t9 = $[
|
|
134
|
+
$[22] = t4;
|
|
135
|
+
$[23] = t8;
|
|
136
|
+
$[24] = t9;
|
|
137
|
+
} else t9 = $[24];
|
|
136
138
|
return t9;
|
|
137
139
|
});
|
|
138
140
|
ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
|
139
|
-
function _temp(
|
|
141
|
+
function _temp(s) {
|
|
142
|
+
return s.composer.type;
|
|
143
|
+
}
|
|
144
|
+
function _temp2(e_0) {
|
|
140
145
|
if (e_0.button !== 0) return;
|
|
141
146
|
const target = e_0.target;
|
|
142
147
|
if (!(target instanceof Element) || !e_0.currentTarget.contains(target)) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerRoot.js","names":["c","_c","composeEventHandlers","useAuiState","Primitive","ComponentRef","FormEvent","forwardRef","ComponentPropsWithoutRef","MouseEvent","useMemo","useState","useComposerSend","ComposerCompactContext","
|
|
1
|
+
{"version":3,"file":"ComposerRoot.js","names":["c","_c","composeEventHandlers","useAuiState","Primitive","ComponentRef","FormEvent","forwardRef","ComponentPropsWithoutRef","MouseEvent","useMemo","useState","useComposerSend","ComposerCompactContext","COMPOSER_INPUT_SELECTOR","CONTENT_EDITABLE_SELECTOR","INTERACTIVE_ELEMENT_SELECTOR","join","ComposerPrimitiveRoot","Element","form","Props","compact","t0","forwardedRef","$","onMouseDown","onSubmit","rest","send","composerType","_temp","multiline","setMultiline","t1","Symbol","for","compactContext","t2","s_0","s","composer","attachments","length","quote","queue","dictation","text","includes","stateAllowsCompact","isCompact","t3","e","preventDefault","handleSubmit","handleMouseDown","_temp2","t4","t5","undefined","t6","t7","t8","t9","displayName","type","e_0","button","target","currentTarget","contains","interactive","closest","input","querySelector","focus","_c","Primitive"],"sources":["../../../src/primitives/composer/ComposerRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"radix-ui/internal\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { Primitive } from \"../../utils/Primitive\";\nimport {\n type ComponentRef,\n type FormEvent,\n forwardRef,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n useMemo,\n useState,\n} from \"react\";\nimport { useComposerSend } from \"./ComposerSend\";\nimport { ComposerCompactContext } from \"./ComposerCompactContext\";\nimport {\n COMPOSER_INPUT_SELECTOR,\n CONTENT_EDITABLE_SELECTOR,\n} from \"./composerInputSelector\";\n\n// Keeps tabindex=\"-1\": roving-tabindex widgets click-focus items at -1.\nconst INTERACTIVE_ELEMENT_SELECTOR = [\n \"a\",\n \"audio[controls]\",\n \"button\",\n \"details\",\n \"embed\",\n \"iframe\",\n \"input\",\n \"label\",\n \"select\",\n \"summary\",\n \"textarea\",\n \"video[controls]\",\n CONTENT_EDITABLE_SELECTOR,\n \"[tabindex]\",\n].join(\", \");\n\nexport namespace ComposerPrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.form>;\n /**\n * Props for the ComposerPrimitive.Root component.\n * Accepts all standard form element props.\n */\n export type Props = ComponentPropsWithoutRef<typeof Primitive.form> & {\n /**\n * Opt the composer into compact mode. While the input holds at most a single\n * line of text and there are no attachments, quote, queued messages, or\n * active dictation, the root renders a `data-compact` attribute so styles\n * can collapse the composer into a single row. It expands automatically\n * when any of those conditions stop holding.\n * @default false\n */\n compact?: boolean | undefined;\n };\n}\n\n/**\n * The root form container for message composition.\n *\n * This component provides a form wrapper that handles message submission when the form\n * is submitted (e.g., via Enter key or submit button). It automatically prevents the\n * default form submission and triggers the composer's send functionality.\n *\n * Clicking blank form space focuses the composer input (the first textarea or\n * contenteditable inside the form). Text selection cannot start from blank\n * areas; descendants that need native mousedown defaults can call\n * `stopPropagation()` in their own `onMouseDown`.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Root>\n * <ComposerPrimitive.Input placeholder=\"Type your message...\" />\n * <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>\n * </ComposerPrimitive.Root>\n * ```\n */\nexport const ComposerPrimitiveRoot = forwardRef<\n ComposerPrimitiveRoot.Element,\n ComposerPrimitiveRoot.Props\n>(({ onSubmit, onMouseDown, compact, ...rest }, forwardedRef) => {\n const send = useComposerSend();\n const composerType = useAuiState((s) => s.composer.type);\n\n const [multiline, setMultiline] = useState(false);\n const compactContext = useMemo(() => ({ setMultiline }), []);\n const stateAllowsCompact = useAuiState((s) =>\n compact\n ? s.composer.attachments.length === 0 &&\n s.composer.quote == null &&\n s.composer.queue.length === 0 &&\n s.composer.dictation == null &&\n !s.composer.text.includes(\"\\n\")\n : false,\n );\n const isCompact = stateAllowsCompact && !multiline;\n\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault();\n\n if (!send) return;\n send();\n };\n\n const handleMouseDown = (e: MouseEvent<HTMLFormElement>) => {\n if (e.button !== 0) return;\n const target = e.target;\n // Portaled descendants (e.g. a dialog overlay) propagate mousedown through\n // the React tree while their DOM nodes live outside the form.\n if (!(target instanceof Element) || !e.currentTarget.contains(target))\n return;\n // Bound the ancestor walk to the form: hosts like AssistantModal render\n // the composer inside a wrapper carrying tabindex=\"-1\" (Radix FocusScope).\n const interactive = target.closest(INTERACTIVE_ELEMENT_SELECTOR);\n if (interactive && e.currentTarget.contains(interactive)) return;\n const input = e.currentTarget.querySelector<HTMLElement>(\n COMPOSER_INPUT_SELECTOR,\n );\n if (!input) return;\n e.preventDefault();\n input.focus();\n };\n\n return (\n <ComposerCompactContext.Provider value={compact ? compactContext : null}>\n <Primitive.form\n {...rest}\n data-aui-composer-type={composerType}\n data-compact={isCompact ? \"\" : undefined}\n ref={forwardedRef}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n onMouseDown={composeEventHandlers(onMouseDown, handleMouseDown)}\n />\n </ComposerCompactContext.Provider>\n );\n});\n\nComposerPrimitiveRoot.displayName = \"ComposerPrimitive.Root\";\n"],"mappings":";;;;;;;;;;;AAsBA,MAAMgB,+BAA+B;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACAD;CACA;AAAY,CACb,CAACE,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;AAyCX,MAAaC,wBAAwBX,YAGnCgB,IAAAC,iBAAA;CAAA,MAAAC,IAAAxB,EAAA,EAAA;CAAA,IAAAqB;CAAA,IAAAI;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,IAAA;EAAC,CAA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e,WAAY,GAAC;CAClB,MAAAC,SAAehB,IAACgB;CAGhB,IAAI,EAAEA,kBAAkBjD,YAApB,CAAiCiC,IAACiB,cAAcC,SAAUF,MAAM,GAAC;CAIrE,MAAAG,cAAoBH,OAAMI,QAASxD,4BAA4B;CAC/D,IAAIuD,eAAenB,IAACiB,cAAcC,SAAUC,WAAW,GAAC;CACxD,MAAAE,QAAcrB,IAACiB,cAAcK,cAC3B5D,uBACF;CACA,IAAI,CAAC2D,OAAK;CACVrB,IAACC,eAAgB;CACjBoB,MAAKE,MAAO;AAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const CONTENT_EDITABLE_SELECTOR = "[contenteditable]:not([contenteditable='false'])";
|
|
2
|
+
export declare const COMPOSER_INPUT_SELECTOR = "textarea:not(:disabled), [contenteditable]:not([contenteditable='false'])";
|
|
3
|
+
//# sourceMappingURL=composerInputSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composerInputSelector.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/composerInputSelector.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,qDACc,CAAC;AAErD,eAAO,MAAM,uBAAuB,8EAA0D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/primitives/composer/composerInputSelector.ts
|
|
2
|
+
const CONTENT_EDITABLE_SELECTOR = "[contenteditable]:not([contenteditable='false'])";
|
|
3
|
+
const COMPOSER_INPUT_SELECTOR = `textarea:not(:disabled), ${CONTENT_EDITABLE_SELECTOR}`;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { COMPOSER_INPUT_SELECTOR, CONTENT_EDITABLE_SELECTOR };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=composerInputSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composerInputSelector.js","names":["CONTENT_EDITABLE_SELECTOR","COMPOSER_INPUT_SELECTOR"],"sources":["../../../src/primitives/composer/composerInputSelector.ts"],"sourcesContent":["export const CONTENT_EDITABLE_SELECTOR =\n \"[contenteditable]:not([contenteditable='false'])\";\n\nexport const COMPOSER_INPUT_SELECTOR = `textarea:not(:disabled), ${CONTENT_EDITABLE_SELECTOR}`;\n"],"mappings":";AAAA,MAAaA,4BACX;AAEF,MAAaC,0BAA0B,4BAA4BD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComposerCancelWithFocus.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/useComposerCancelWithFocus.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,0BAA0B,GAAI,QAAQ,MAAM,IAAI,cAKhD,WAAW,GAAG,IAAI,SAyC9B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { COMPOSER_INPUT_SELECTOR } from "./composerInputSelector.js";
|
|
3
|
+
import { useThreadRootElementRef } from "../thread/ThreadRootElementContext.js";
|
|
4
|
+
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
|
+
import "@assistant-ui/tap/react-shim";
|
|
6
|
+
import { useAui } from "@assistant-ui/store";
|
|
7
|
+
//#region src/primitives/composer/useComposerCancelWithFocus.ts
|
|
8
|
+
const COMPOSER_SELECTOR = "[data-aui-composer-type]";
|
|
9
|
+
const THREAD_SELECTOR = "[data-aui-thread-root]";
|
|
10
|
+
const useComposerCancelWithFocus = (cancel) => {
|
|
11
|
+
const $ = c(4);
|
|
12
|
+
const aui = useAui();
|
|
13
|
+
const threadRootRef = useThreadRootElementRef();
|
|
14
|
+
let t0;
|
|
15
|
+
if ($[0] !== aui.composer || $[1] !== cancel || $[2] !== threadRootRef) {
|
|
16
|
+
t0 = (source) => {
|
|
17
|
+
const root = threadRootRef?.current;
|
|
18
|
+
const doc = source?.ownerDocument;
|
|
19
|
+
const active = doc?.activeElement;
|
|
20
|
+
const composer = source?.closest(COMPOSER_SELECTOR);
|
|
21
|
+
const shouldRestore = aui.composer.getState().type === "edit" && root && active && composer?.getAttribute("data-aui-composer-type") === "edit" && composer.contains(active) && composer.closest(THREAD_SELECTOR) === root;
|
|
22
|
+
const candidates = shouldRestore ? Array.from(root.querySelectorAll(COMPOSER_INPUT_SELECTOR)).filter((input) => input.closest(THREAD_SELECTOR) === root && input.closest(COMPOSER_SELECTOR)?.getAttribute("data-aui-composer-type") === "thread") : [];
|
|
23
|
+
cancel();
|
|
24
|
+
if (!doc || !active || !shouldRestore) return;
|
|
25
|
+
if (doc.activeElement !== active && doc.activeElement !== doc.body) return;
|
|
26
|
+
for (const input_0 of candidates) {
|
|
27
|
+
if (!input_0.isConnected || input_0.closest("[hidden], [inert]")) continue;
|
|
28
|
+
input_0.focus({ preventScroll: true });
|
|
29
|
+
if (doc.activeElement !== active && doc.activeElement !== doc.body) break;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
$[0] = aui.composer;
|
|
33
|
+
$[1] = cancel;
|
|
34
|
+
$[2] = threadRootRef;
|
|
35
|
+
$[3] = t0;
|
|
36
|
+
} else t0 = $[3];
|
|
37
|
+
return t0;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { useComposerCancelWithFocus };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=useComposerCancelWithFocus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComposerCancelWithFocus.js","names":["c","_c","useCallback","useAui","useThreadRootElementRef","COMPOSER_INPUT_SELECTOR","COMPOSER_SELECTOR","THREAD_SELECTOR","useComposerCancelWithFocus","cancel","$","aui","threadRootRef","t0","composer","source","root","current","doc","ownerDocument","active","activeElement","closest","shouldRestore","getState","type","getAttribute","contains","candidates","Array","from","querySelectorAll","filter","input","body","input_0","isConnected","focus","preventScroll","cancelWithFocus","_c","cancelWithFocus"],"sources":["../../../src/primitives/composer/useComposerCancelWithFocus.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useThreadRootElementRef } from \"../thread/ThreadRootElementContext\";\nimport { COMPOSER_INPUT_SELECTOR } from \"./composerInputSelector\";\n\nconst COMPOSER_SELECTOR = \"[data-aui-composer-type]\";\nconst THREAD_SELECTOR = \"[data-aui-thread-root]\";\n\nexport const useComposerCancelWithFocus = (cancel: () => void) => {\n const aui = useAui();\n const threadRootRef = useThreadRootElementRef();\n\n const cancelWithFocus = useCallback(\n (source: HTMLElement | null) => {\n const root = threadRootRef?.current;\n const doc = source?.ownerDocument;\n const active = doc?.activeElement;\n const composer = source?.closest(COMPOSER_SELECTOR);\n const shouldRestore =\n aui.composer.getState().type === \"edit\" &&\n root &&\n active &&\n composer?.getAttribute(\"data-aui-composer-type\") === \"edit\" &&\n composer.contains(active) &&\n composer.closest(THREAD_SELECTOR) === root;\n const candidates = shouldRestore\n ? Array.from(\n root.querySelectorAll<HTMLElement>(COMPOSER_INPUT_SELECTOR),\n ).filter(\n (input) =>\n input.closest(THREAD_SELECTOR) === root &&\n input\n .closest(COMPOSER_SELECTOR)\n ?.getAttribute(\"data-aui-composer-type\") === \"thread\",\n )\n : [];\n\n cancel();\n\n if (!doc || !active || !shouldRestore) return;\n if (doc.activeElement !== active && doc.activeElement !== doc.body)\n return;\n\n for (const input of candidates) {\n if (!input.isConnected || input.closest(\"[hidden], [inert]\")) continue;\n input.focus({ preventScroll: true });\n if (doc.activeElement !== active && doc.activeElement !== doc.body)\n break;\n }\n },\n [aui, cancel, threadRootRef],\n );\n\n return cancelWithFocus;\n};\n"],"mappings":";;;;;;;AAOA,MAAMM,oBAAoB;AAC1B,MAAMC,kBAAkB;AAExB,MAAaC,8BAA6BC,WAAA;CAAA,MAAAC,IAAAT,EAAA,CAAA;CACxC,MAAAU,MAAYR,OAAO;CACnB,MAAAS,gBAAsBR,wBAAwB;CAAE,IAAAS;CAAA,IAAAH,EAAA,OAAAC,IAAAG,YAAAJ,EAAA,OAAAD,UAAAC,EAAA,O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