@neuronection/assistant-ui 0.51.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/chat-composer.d.ts +8 -0
- package/dist/chat-composer.js +1 -1
- package/dist/{chunk-NUD32RLL.js → chunk-YQQZMWHL.js} +5 -3
- package/dist/chunk-YQQZMWHL.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-NUD32RLL.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @neuronection/assistant-ui
|
|
2
2
|
|
|
3
|
+
## 0.52.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#76](https://github.com/neuronection/assistant-ui/pull/76) [`2911feb`](https://github.com/neuronection/assistant-ui/commit/2911feb99688cf5bb349411aae5482d8763edab1) Thanks [@constLiakos](https://github.com/constLiakos)! - ChatComposer: add the `canSubmit` override for attachment-only submits. The send button's default guard (`value.trim() !== ''`) blocks turns that carry only attachments — health-assistant's image-only "what's this?" chat turn is the driving case. Apps pass `canSubmit={draft.trim() !== '' || hasReadyAttachments}` (or `false` to force-disable); the Enter/form path is unchanged, the app's `onSubmit` stays the single submit guard. Consumers: health wires it in its chat composer (plan 13 H1); career/study only if they add attachment-only sends.
|
|
8
|
+
|
|
3
9
|
## 0.51.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/chat-composer.d.ts
CHANGED
|
@@ -21,6 +21,14 @@ interface ChatComposerProps {
|
|
|
21
21
|
sending?: boolean;
|
|
22
22
|
onStop?: () => void;
|
|
23
23
|
disabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Overrides the send button's blank-text guard. Apps that allow
|
|
26
|
+
* attachment-only submits (health's image-only "what's this?" turn) pass
|
|
27
|
+
* `true` while ready attachments exist; pass `false` to force-disable.
|
|
28
|
+
* Default: the button enables only when `value.trim() !== ''`. The
|
|
29
|
+
* Enter/form path is unaffected — the app's `onSubmit` stays the guard.
|
|
30
|
+
*/
|
|
31
|
+
canSubmit?: boolean;
|
|
24
32
|
placeholder?: string;
|
|
25
33
|
ariaLabel?: string;
|
|
26
34
|
/** Auto-grow cap before the textarea scrolls. Default 8. */
|
package/dist/chat-composer.js
CHANGED
|
@@ -14,6 +14,7 @@ var ChatComposer = React.forwardRef(
|
|
|
14
14
|
sending = false,
|
|
15
15
|
onStop,
|
|
16
16
|
disabled = false,
|
|
17
|
+
canSubmit,
|
|
17
18
|
placeholder,
|
|
18
19
|
ariaLabel,
|
|
19
20
|
maxRows = 8,
|
|
@@ -119,6 +120,7 @@ var ChatComposer = React.forwardRef(
|
|
|
119
120
|
const SendIcon = icons?.send ?? ArrowUp;
|
|
120
121
|
const StopIcon = icons?.stop ?? Square;
|
|
121
122
|
const showStop = sending && onStop !== void 0;
|
|
123
|
+
const submitBlocked = disabled || sending || (canSubmit === void 0 ? value.trim() === "" : !canSubmit);
|
|
122
124
|
return /* @__PURE__ */ jsxs(
|
|
123
125
|
"form",
|
|
124
126
|
{
|
|
@@ -179,7 +181,7 @@ var ChatComposer = React.forwardRef(
|
|
|
179
181
|
type: "submit",
|
|
180
182
|
"aria-label": labels?.send ?? "Send message",
|
|
181
183
|
title: labels?.send ?? "Send message",
|
|
182
|
-
disabled:
|
|
184
|
+
disabled: submitBlocked,
|
|
183
185
|
className: "mb-0.5 flex size-7 shrink-0 items-center justify-center rounded-full bg-[var(--as-primary)] text-[var(--as-primary-fg)] transition-opacity hover:opacity-90 disabled:pointer-events-none disabled:opacity-30 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[var(--as-focus-ring)]",
|
|
184
186
|
children: /* @__PURE__ */ jsx(SendIcon, { className: "size-4", "aria-hidden": true })
|
|
185
187
|
}
|
|
@@ -195,5 +197,5 @@ var ChatComposer = React.forwardRef(
|
|
|
195
197
|
);
|
|
196
198
|
|
|
197
199
|
export { ChatComposer };
|
|
198
|
-
//# sourceMappingURL=chunk-
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
200
|
+
//# sourceMappingURL=chunk-YQQZMWHL.js.map
|
|
201
|
+
//# sourceMappingURL=chunk-YQQZMWHL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat-composer/ChatComposer.tsx"],"names":["ChatComposer"],"mappings":";;;;;AAwDA,SAAS,iBAAiB,KAAA,EAA0D;AAClF,EAAA,OAAO,KAAA,CAAM,WAAA,CAAY,WAAA,IAAe,KAAA,CAAM,OAAA,KAAY,GAAA;AAC5D;AAOO,IAAM,YAAA,GAAqB,KAAA,CAAA,UAAA;AAAA,EAChC,SAASA,aAAAA,CACP;AAAA,IACE,KAAA;AAAA,IACA,aAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,MAAA;AAAA,IACA,QAAA,GAAW,KAAA;AAAA,IACX,SAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA,GAAU,CAAA;AAAA,IACV,YAAA;AAAA,IACA,UAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,aAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,KAEF,GAAA,EACA;AACA,IAAA,MAAM,mBAAA,GAA4B,aAAmC,IAAI,CAAA;AACzE,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAU,eAAS,KAAK,CAAA;AACpD,IAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAU,eAAS,KAAK,CAAA;AACtD,IAAA,MAAM,YAAA,GAAqB,aAAO,KAAK,CAAA;AACvC,IAAA,MAAM,SAAA,GAAkB,aAAO,CAAC,CAAA;AAEhC,IAAA,MAAM,WAAA,GAAc,CAAC,OAAA,KAAwC;AAC3D,MAAA,mB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,IAAY,aAAA,mBACX,GAAA,CAAC,GAAA,EAAA,EAAE,SAAA,EAAU,mCAAA,EAAoC,IAAA,EAAK,QAAA,EACnD,QAAA,EAAA,MAAA,EAAQ,SAAA,IAAa,sBAAA,EACxB,CAAA,GACE;AAAA;AAAA;AAAA,KACN;AAAA,EAEJ;AACF","file":"chunk-YQQZMWHL.js","sourcesContent":["import * as React from 'react'\nimport { ArrowUp, Square } from 'lucide-react'\nimport type { LucideIcon } from 'lucide-react'\n\nimport { cn } from '../../lib/utils'\n\nexport interface ChatComposerLabels {\n send: string\n stop: string\n placeholder: string\n ariaLabel: string\n dropFiles: string\n}\n\nexport interface ChatComposerIcons {\n send: LucideIcon\n stop: LucideIcon\n}\n\nexport interface ChatComposerProps {\n value: string\n onValueChange: (value: string) => void\n /** Enter / Send — IME-safe (composition and keyCode 229 are ignored). */\n onSubmit: () => void\n /** A turn is in flight — renders the stop control when `onStop` is provided. */\n sending?: boolean\n onStop?: () => void\n disabled?: boolean\n /**\n * Overrides the send button's blank-text guard. Apps that allow\n * attachment-only submits (health's image-only \"what's this?\" turn) pass\n * `true` while ready attachments exist; pass `false` to force-disable.\n * Default: the button enables only when `value.trim() !== ''`. The\n * Enter/form path is unaffected — the app's `onSubmit` stays the guard.\n */\n canSubmit?: boolean\n placeholder?: string\n ariaLabel?: string\n /** Auto-grow cap before the textarea scrolls. Default 8. */\n maxRows?: number\n /** Leading slot inside the input row (attach menu, equation, draw…). */\n toolbarStart?: React.ReactNode\n /** Trailing slot inside the input row (dictation, tools…). */\n toolbarEnd?: React.ReactNode\n /** Attachment rail above the input (usually `FileQueue` / chips). */\n attachments?: React.ReactNode\n /** Suggestion chips / context strip above everything. */\n suggestions?: React.ReactNode\n /** Drag-drop + paste wiring for file attachments. */\n onAttachFiles?: (files: File[]) => void\n labels?: Partial<ChatComposerLabels>\n icons?: Partial<ChatComposerIcons>\n textareaRef?: React.Ref<HTMLTextAreaElement>\n className?: string\n}\n\nfunction isIMEComposition(event: React.KeyboardEvent<HTMLTextAreaElement>): boolean {\n return event.nativeEvent.isComposing || event.keyCode === 229\n}\n\n/**\n * The family chat input: auto-growing IME-safe textarea, send/stop\n * states, attachment/dictation/toolbar slots, drag-drop + paste file\n * wiring. Presentational + controlled; transports stay app-side.\n */\nexport const ChatComposer = React.forwardRef<HTMLFormElement, ChatComposerProps>(\n function ChatComposer(\n {\n value,\n onValueChange,\n onSubmit,\n sending = false,\n onStop,\n disabled = false,\n canSubmit,\n placeholder,\n ariaLabel,\n maxRows = 8,\n toolbarStart,\n toolbarEnd,\n attachments,\n suggestions,\n onAttachFiles,\n labels,\n icons,\n textareaRef,\n className,\n },\n ref,\n ) {\n const internalTextareaRef = React.useRef<HTMLTextAreaElement | null>(null)\n const [dragging, setDragging] = React.useState(false)\n const [multiline, setMultiline] = React.useState(false)\n const multilineRef = React.useRef(false)\n const dragDepth = React.useRef(0)\n\n const setTextarea = (element: HTMLTextAreaElement | null) => {\n internalTextareaRef.current = element\n if (typeof textareaRef === 'function') {\n textareaRef(element)\n } else if (textareaRef && typeof textareaRef === 'object') {\n ;(textareaRef as React.MutableRefObject<HTMLTextAreaElement | null>).current = element\n }\n }\n\n React.useLayoutEffect(() => {\n const element = internalTextareaRef.current\n if (element === null) {\n return\n }\n const style = window.getComputedStyle(element)\n const lineHeight = Number.parseFloat(style.lineHeight) || 22\n const verticalPadding =\n (Number.parseFloat(style.paddingTop) || 0) + (Number.parseFloat(style.paddingBottom) || 0)\n // The JS cap must mirror the CSS box: a `max-h-*` class wins over\n // the maxRows fallback, otherwise overflowY and the real visible\n // cap disagree and lines clip silently.\n const cap = Number.parseFloat(style.maxHeight) || maxRows * 22\n element.style.height = 'auto'\n // scrollHeight rounds fractional line-heights down (22.75px at\n // text-sm/leading-relaxed), leaving the box ~1px short — the\n // caret then scrolls the hidden-overflow textarea and clips the\n // first line at the box top. The +1 absorbs the rounding; the\n // scrollTop reset guarantees the first line stays visible\n // whenever the whole content fits.\n const next =\n element.scrollHeight > 0 ? Math.min(Math.ceil(element.scrollHeight) + 1, cap) : 0\n element.style.height = next > 0 ? `${next}px` : 'auto'\n const overflowing = element.scrollHeight > element.clientHeight + 1\n element.style.overflowY = overflowing ? 'auto' : 'hidden'\n if (!overflowing && element.scrollTop !== 0) {\n element.scrollTop = 0\n }\n // Hysteresis: apps restyle this row off [data-multiline] (e.g.\n // footer-wrapping the toolbars under a full-width textarea), which\n // changes the textarea's width between the two states. A flag\n // re-measured at whichever width the previous decision produced\n // feeds back into itself and oscillates near the wrap threshold —\n // one keystroke wide, the next squeezed. Once multiline, stay\n // multiline until the draft clears.\n const grew = element.scrollHeight > lineHeight + verticalPadding + 1\n multilineRef.current = value === '' ? false : multilineRef.current || grew\n setMultiline(multilineRef.current)\n }, [value, maxRows])\n\n const submit = () => {\n if (disabled || sending) {\n return\n }\n onSubmit()\n }\n\n const onKeyDown: React.KeyboardEventHandler<HTMLTextAreaElement> = (event) => {\n if (event.key !== 'Enter' || event.shiftKey) {\n return\n }\n if (isIMEComposition(event)) {\n return\n }\n event.preventDefault()\n submit()\n }\n\n const emitFiles = (fileList: FileList | null | undefined) => {\n const files = fileList ? Array.from(fileList) : []\n if (files.length > 0) {\n onAttachFiles?.(files)\n }\n }\n\n const dragCounterHandlers = {\n onDragEnter: (event: React.DragEvent) => {\n if (onAttachFiles === undefined || !event.dataTransfer.types.includes('Files')) {\n return\n }\n event.preventDefault()\n dragDepth.current += 1\n setDragging(true)\n },\n onDragOver: (event: React.DragEvent) => {\n if (onAttachFiles === undefined || !event.dataTransfer.types.includes('Files')) {\n return\n }\n event.preventDefault()\n },\n onDragLeave: () => {\n if (dragDepth.current > 0) {\n dragDepth.current -= 1\n if (dragDepth.current === 0) {\n setDragging(false)\n }\n }\n },\n onDrop: (event: React.DragEvent) => {\n if (onAttachFiles === undefined) {\n return\n }\n event.preventDefault()\n dragDepth.current = 0\n setDragging(false)\n emitFiles(event.dataTransfer.files)\n },\n }\n\n const SendIcon = icons?.send ?? ArrowUp\n const StopIcon = icons?.stop ?? Square\n const showStop = sending && onStop !== undefined\n const submitBlocked =\n disabled || sending || (canSubmit === undefined ? value.trim() === '' : !canSubmit)\n\n return (\n <form\n ref={ref}\n data-as=\"chat-composer\"\n data-sending={sending}\n onSubmit={(event) => {\n event.preventDefault()\n submit()\n }}\n className={cn('flex w-full flex-col gap-2', className)}\n {...dragCounterHandlers}\n >\n {suggestions ? <div className=\"flex flex-wrap gap-1.5\">{suggestions}</div> : null}\n {attachments ? <div className=\"flex flex-wrap gap-1.5\">{attachments}</div> : null}\n <div\n data-as=\"chat-composer-row\"\n data-multiline={multiline || undefined}\n data-dragging={dragging || undefined}\n className={cn(\n 'flex items-end gap-1.5 rounded-[var(--as-radius-lg)] border border-[var(--as-border)] bg-[var(--as-surface)] px-2 py-1.5 transition-colors focus-within:border-[var(--as-primary)]',\n dragging && 'border-dashed border-[var(--as-primary)] bg-[var(--as-primary)]/5',\n disabled && 'opacity-50',\n )}\n >\n {toolbarStart ? <div className=\"flex shrink-0 items-center gap-0.5 pb-0.5\">{toolbarStart}</div> : null}\n <textarea\n ref={setTextarea}\n value={value}\n rows={1}\n disabled={disabled}\n placeholder={placeholder ?? labels?.placeholder ?? 'Send a message…'}\n aria-label={ariaLabel ?? labels?.ariaLabel ?? 'Message'}\n onChange={(event) => onValueChange(event.target.value)}\n onKeyDown={onKeyDown}\n onPaste={(event) => emitFiles(event.clipboardData.files)}\n className=\"max-h-40 min-h-[1.5rem] w-full flex-1 resize-none bg-transparent px-1 py-1 text-sm leading-relaxed text-[var(--as-fg)] placeholder:text-[var(--as-muted-fg)] focus-visible:outline-none disabled:cursor-not-allowed\"\n />\n {toolbarEnd ? <div className=\"flex shrink-0 items-center gap-0.5 pb-0.5\">{toolbarEnd}</div> : null}\n {showStop ? (\n <button\n type=\"button\"\n aria-label={labels?.stop ?? 'Stop generating'}\n title={labels?.stop ?? 'Stop generating'}\n onClick={onStop}\n className=\"mb-0.5 flex size-7 shrink-0 items-center justify-center rounded-full border border-[var(--as-border)] bg-[var(--as-surface-raised)] text-[var(--as-fg)] transition-colors hover:bg-[var(--as-secondary)] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[var(--as-focus-ring)]\"\n >\n <StopIcon className=\"size-3.5\" aria-hidden />\n </button>\n ) : (\n <button\n type=\"submit\"\n aria-label={labels?.send ?? 'Send message'}\n title={labels?.send ?? 'Send message'}\n disabled={submitBlocked}\n className=\"mb-0.5 flex size-7 shrink-0 items-center justify-center rounded-full bg-[var(--as-primary)] text-[var(--as-primary-fg)] transition-opacity hover:opacity-90 disabled:pointer-events-none disabled:opacity-30 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[var(--as-focus-ring)]\"\n >\n <SendIcon className=\"size-4\" aria-hidden />\n </button>\n )}\n </div>\n {dragging && onAttachFiles ? (\n <p className=\"text-xs text-[var(--as-muted-fg)]\" role=\"status\">\n {labels?.dropFiles ?? 'Drop files to attach'}\n </p>\n ) : null}\n </form>\n )\n },\n)\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2669,6 +2669,14 @@ interface ChatComposerProps {
|
|
|
2669
2669
|
sending?: boolean;
|
|
2670
2670
|
onStop?: () => void;
|
|
2671
2671
|
disabled?: boolean;
|
|
2672
|
+
/**
|
|
2673
|
+
* Overrides the send button's blank-text guard. Apps that allow
|
|
2674
|
+
* attachment-only submits (health's image-only "what's this?" turn) pass
|
|
2675
|
+
* `true` while ready attachments exist; pass `false` to force-disable.
|
|
2676
|
+
* Default: the button enables only when `value.trim() !== ''`. The
|
|
2677
|
+
* Enter/form path is unaffected — the app's `onSubmit` stays the guard.
|
|
2678
|
+
*/
|
|
2679
|
+
canSubmit?: boolean;
|
|
2672
2680
|
placeholder?: string;
|
|
2673
2681
|
ariaLabel?: string;
|
|
2674
2682
|
/** Auto-grow cap before the textarea scrolls. Default 8. */
|
package/dist/index.js
CHANGED
|
@@ -74,7 +74,7 @@ export { initialLiveTurnState, liveTurnReducer, useChatStream } from './chunk-O3
|
|
|
74
74
|
export { activePathSet, buildBranchTree, linearTree, variantInfo, walkActivePath } from './chunk-Z4IBQ53C.js';
|
|
75
75
|
export { ChatLauncher } from './chunk-E3NZM4U7.js';
|
|
76
76
|
export { Portal } from './chunk-XZWLTTHA.js';
|
|
77
|
-
export { ChatComposer } from './chunk-
|
|
77
|
+
export { ChatComposer } from './chunk-YQQZMWHL.js';
|
|
78
78
|
export { rawTokens, semanticTokens } from './chunk-GDGKARRB.js';
|
|
79
79
|
export { AiActionsDropdown } from './chunk-HUIKW2PK.js';
|
|
80
80
|
export { AboutCard, AboutFooterLine, AboutLinkList, AboutNote, AboutPanel, FamilyBadge, SponsorCard, TechChips } from './chunk-PPW4GNM6.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuronection/assistant-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "Shared React component library for the Assistant family (career-, study-, health-, desktop-assistant). Family look by default, app-flavored via CSS-variable tokens.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -439,8 +439,8 @@
|
|
|
439
439
|
"@testing-library/react": "^16.3.2",
|
|
440
440
|
"@testing-library/user-event": "^14.6.1",
|
|
441
441
|
"@types/node": "^26.2.0",
|
|
442
|
-
"@types/react": "^19.
|
|
443
|
-
"@types/react-dom": "^19.
|
|
442
|
+
"@types/react": "^19.3.0",
|
|
443
|
+
"@types/react-dom": "^19.3.0",
|
|
444
444
|
"@vitejs/plugin-react": "^6.0.5",
|
|
445
445
|
"concurrently": "^9.1.2",
|
|
446
446
|
"eslint": "^10.8.1",
|
|
@@ -450,8 +450,8 @@
|
|
|
450
450
|
"jsdom": "^30.0.1",
|
|
451
451
|
"lucide-react": "^1.31.0",
|
|
452
452
|
"postcss": "^8.5.3",
|
|
453
|
-
"react": "^19.
|
|
454
|
-
"react-dom": "^19.
|
|
453
|
+
"react": "^19.3.0",
|
|
454
|
+
"react-dom": "^19.3.0",
|
|
455
455
|
"tailwindcss": "^4.3.3",
|
|
456
456
|
"tsup": "^8.4.0",
|
|
457
457
|
"typescript": "^5.9.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat-composer/ChatComposer.tsx"],"names":["ChatComposer"],"mappings":";;;;;AAgDA,SAAS,iBAAiB,KAAA,EAA0D;AAClF,EAAA,OAAO,KAAA,CAAM,WAAA,CAAY,WAAA,IAAe,KAAA,CAAM,OAAA,KAAY,GAAA;AAC5D;AAOO,IAAM,YAAA,GAAqB,KAAA,CAAA,UAAA;AAAA,EAChC,SAASA,aAAAA,CACP;AAAA,IACE,KAAA;AAAA,IACA,aAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,MAAA;AAAA,IACA,QAAA,GAAW,KAAA;AAAA,IACX,WAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA,GAAU,CAAA;AAAA,IACV,YAAA;AAAA,IACA,UAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,aAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,KAEF,GAAA,EACA;AACA,IAAA,MAAM,mBAAA,GAA4B,aAAmC,IAAI,CAAA;AACzE,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAU,eAAS,KAAK,CAAA;AACpD,IAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAU,eAAS,KAAK,CAAA;AACtD,IAAA,MAAM,YAAA,GAAqB,aAAO,KAAK,CAAA;AACvC,IAAA,MAAM,SAAA,GAAkB,aAAO,CAAC,CAAA;AAEhC,IAAA,MAAM,WAAA,GAAc,CAAC,OAAA,KAAwC;AAC3D,MAAA,mBAAA,CAAoB,OAAA,GAAU,OAAA;AAC9B,MAAA,IAAI,OAAO,gBAAgB,UAAA,EAAY;AACrC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GACE;AAAA;AAAA;AAAA,KACN;AAAA,EAEJ;AACF","file":"chunk-NUD32RLL.js","sourcesContent":["import * as React from 'react'\nimport { ArrowUp, Square } from 'lucide-react'\nimport type { LucideIcon } from 'lucide-react'\n\nimport { cn } from '../../lib/utils'\n\nexport interface ChatComposerLabels {\n send: string\n stop: string\n placeholder: string\n ariaLabel: string\n dropFiles: string\n}\n\nexport interface ChatComposerIcons {\n send: LucideIcon\n stop: LucideIcon\n}\n\nexport interface ChatComposerProps {\n value: string\n onValueChange: (value: string) => void\n /** Enter / Send — IME-safe (composition and keyCode 229 are ignored). */\n onSubmit: () => void\n /** A turn is in flight — renders the stop control when `onStop` is provided. */\n sending?: boolean\n onStop?: () => void\n disabled?: boolean\n placeholder?: string\n ariaLabel?: string\n /** Auto-grow cap before the textarea scrolls. Default 8. */\n maxRows?: number\n /** Leading slot inside the input row (attach menu, equation, draw…). */\n toolbarStart?: React.ReactNode\n /** Trailing slot inside the input row (dictation, tools…). */\n toolbarEnd?: React.ReactNode\n /** Attachment rail above the input (usually `FileQueue` / chips). */\n attachments?: React.ReactNode\n /** Suggestion chips / context strip above everything. */\n suggestions?: React.ReactNode\n /** Drag-drop + paste wiring for file attachments. */\n onAttachFiles?: (files: File[]) => void\n labels?: Partial<ChatComposerLabels>\n icons?: Partial<ChatComposerIcons>\n textareaRef?: React.Ref<HTMLTextAreaElement>\n className?: string\n}\n\nfunction isIMEComposition(event: React.KeyboardEvent<HTMLTextAreaElement>): boolean {\n return event.nativeEvent.isComposing || event.keyCode === 229\n}\n\n/**\n * The family chat input: auto-growing IME-safe textarea, send/stop\n * states, attachment/dictation/toolbar slots, drag-drop + paste file\n * wiring. Presentational + controlled; transports stay app-side.\n */\nexport const ChatComposer = React.forwardRef<HTMLFormElement, ChatComposerProps>(\n function ChatComposer(\n {\n value,\n onValueChange,\n onSubmit,\n sending = false,\n onStop,\n disabled = false,\n placeholder,\n ariaLabel,\n maxRows = 8,\n toolbarStart,\n toolbarEnd,\n attachments,\n suggestions,\n onAttachFiles,\n labels,\n icons,\n textareaRef,\n className,\n },\n ref,\n ) {\n const internalTextareaRef = React.useRef<HTMLTextAreaElement | null>(null)\n const [dragging, setDragging] = React.useState(false)\n const [multiline, setMultiline] = React.useState(false)\n const multilineRef = React.useRef(false)\n const dragDepth = React.useRef(0)\n\n const setTextarea = (element: HTMLTextAreaElement | null) => {\n internalTextareaRef.current = element\n if (typeof textareaRef === 'function') {\n textareaRef(element)\n } else if (textareaRef && typeof textareaRef === 'object') {\n ;(textareaRef as React.MutableRefObject<HTMLTextAreaElement | null>).current = element\n }\n }\n\n React.useLayoutEffect(() => {\n const element = internalTextareaRef.current\n if (element === null) {\n return\n }\n const style = window.getComputedStyle(element)\n const lineHeight = Number.parseFloat(style.lineHeight) || 22\n const verticalPadding =\n (Number.parseFloat(style.paddingTop) || 0) + (Number.parseFloat(style.paddingBottom) || 0)\n // The JS cap must mirror the CSS box: a `max-h-*` class wins over\n // the maxRows fallback, otherwise overflowY and the real visible\n // cap disagree and lines clip silently.\n const cap = Number.parseFloat(style.maxHeight) || maxRows * 22\n element.style.height = 'auto'\n // scrollHeight rounds fractional line-heights down (22.75px at\n // text-sm/leading-relaxed), leaving the box ~1px short — the\n // caret then scrolls the hidden-overflow textarea and clips the\n // first line at the box top. The +1 absorbs the rounding; the\n // scrollTop reset guarantees the first line stays visible\n // whenever the whole content fits.\n const next =\n element.scrollHeight > 0 ? Math.min(Math.ceil(element.scrollHeight) + 1, cap) : 0\n element.style.height = next > 0 ? `${next}px` : 'auto'\n const overflowing = element.scrollHeight > element.clientHeight + 1\n element.style.overflowY = overflowing ? 'auto' : 'hidden'\n if (!overflowing && element.scrollTop !== 0) {\n element.scrollTop = 0\n }\n // Hysteresis: apps restyle this row off [data-multiline] (e.g.\n // footer-wrapping the toolbars under a full-width textarea), which\n // changes the textarea's width between the two states. A flag\n // re-measured at whichever width the previous decision produced\n // feeds back into itself and oscillates near the wrap threshold —\n // one keystroke wide, the next squeezed. Once multiline, stay\n // multiline until the draft clears.\n const grew = element.scrollHeight > lineHeight + verticalPadding + 1\n multilineRef.current = value === '' ? false : multilineRef.current || grew\n setMultiline(multilineRef.current)\n }, [value, maxRows])\n\n const submit = () => {\n if (disabled || sending) {\n return\n }\n onSubmit()\n }\n\n const onKeyDown: React.KeyboardEventHandler<HTMLTextAreaElement> = (event) => {\n if (event.key !== 'Enter' || event.shiftKey) {\n return\n }\n if (isIMEComposition(event)) {\n return\n }\n event.preventDefault()\n submit()\n }\n\n const emitFiles = (fileList: FileList | null | undefined) => {\n const files = fileList ? Array.from(fileList) : []\n if (files.length > 0) {\n onAttachFiles?.(files)\n }\n }\n\n const dragCounterHandlers = {\n onDragEnter: (event: React.DragEvent) => {\n if (onAttachFiles === undefined || !event.dataTransfer.types.includes('Files')) {\n return\n }\n event.preventDefault()\n dragDepth.current += 1\n setDragging(true)\n },\n onDragOver: (event: React.DragEvent) => {\n if (onAttachFiles === undefined || !event.dataTransfer.types.includes('Files')) {\n return\n }\n event.preventDefault()\n },\n onDragLeave: () => {\n if (dragDepth.current > 0) {\n dragDepth.current -= 1\n if (dragDepth.current === 0) {\n setDragging(false)\n }\n }\n },\n onDrop: (event: React.DragEvent) => {\n if (onAttachFiles === undefined) {\n return\n }\n event.preventDefault()\n dragDepth.current = 0\n setDragging(false)\n emitFiles(event.dataTransfer.files)\n },\n }\n\n const SendIcon = icons?.send ?? ArrowUp\n const StopIcon = icons?.stop ?? Square\n const showStop = sending && onStop !== undefined\n\n return (\n <form\n ref={ref}\n data-as=\"chat-composer\"\n data-sending={sending}\n onSubmit={(event) => {\n event.preventDefault()\n submit()\n }}\n className={cn('flex w-full flex-col gap-2', className)}\n {...dragCounterHandlers}\n >\n {suggestions ? <div className=\"flex flex-wrap gap-1.5\">{suggestions}</div> : null}\n {attachments ? <div className=\"flex flex-wrap gap-1.5\">{attachments}</div> : null}\n <div\n data-as=\"chat-composer-row\"\n data-multiline={multiline || undefined}\n data-dragging={dragging || undefined}\n className={cn(\n 'flex items-end gap-1.5 rounded-[var(--as-radius-lg)] border border-[var(--as-border)] bg-[var(--as-surface)] px-2 py-1.5 transition-colors focus-within:border-[var(--as-primary)]',\n dragging && 'border-dashed border-[var(--as-primary)] bg-[var(--as-primary)]/5',\n disabled && 'opacity-50',\n )}\n >\n {toolbarStart ? <div className=\"flex shrink-0 items-center gap-0.5 pb-0.5\">{toolbarStart}</div> : null}\n <textarea\n ref={setTextarea}\n value={value}\n rows={1}\n disabled={disabled}\n placeholder={placeholder ?? labels?.placeholder ?? 'Send a message…'}\n aria-label={ariaLabel ?? labels?.ariaLabel ?? 'Message'}\n onChange={(event) => onValueChange(event.target.value)}\n onKeyDown={onKeyDown}\n onPaste={(event) => emitFiles(event.clipboardData.files)}\n className=\"max-h-40 min-h-[1.5rem] w-full flex-1 resize-none bg-transparent px-1 py-1 text-sm leading-relaxed text-[var(--as-fg)] placeholder:text-[var(--as-muted-fg)] focus-visible:outline-none disabled:cursor-not-allowed\"\n />\n {toolbarEnd ? <div className=\"flex shrink-0 items-center gap-0.5 pb-0.5\">{toolbarEnd}</div> : null}\n {showStop ? (\n <button\n type=\"button\"\n aria-label={labels?.stop ?? 'Stop generating'}\n title={labels?.stop ?? 'Stop generating'}\n onClick={onStop}\n className=\"mb-0.5 flex size-7 shrink-0 items-center justify-center rounded-full border border-[var(--as-border)] bg-[var(--as-surface-raised)] text-[var(--as-fg)] transition-colors hover:bg-[var(--as-secondary)] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[var(--as-focus-ring)]\"\n >\n <StopIcon className=\"size-3.5\" aria-hidden />\n </button>\n ) : (\n <button\n type=\"submit\"\n aria-label={labels?.send ?? 'Send message'}\n title={labels?.send ?? 'Send message'}\n disabled={disabled || value.trim() === '' || sending}\n className=\"mb-0.5 flex size-7 shrink-0 items-center justify-center rounded-full bg-[var(--as-primary)] text-[var(--as-primary-fg)] transition-opacity hover:opacity-90 disabled:pointer-events-none disabled:opacity-30 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[var(--as-focus-ring)]\"\n >\n <SendIcon className=\"size-4\" aria-hidden />\n </button>\n )}\n </div>\n {dragging && onAttachFiles ? (\n <p className=\"text-xs text-[var(--as-muted-fg)]\" role=\"status\">\n {labels?.dropFiles ?? 'Drop files to attach'}\n </p>\n ) : null}\n </form>\n )\n },\n)\n"]}
|