@langchain/macaw-components 1.7.20 → 1.7.21
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/catalog.json +787 -787
- package/dist/components/ChatComposer/ChatComposer.js +8 -1
- package/dist/components/ChatComposer/ChatComposer.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.js +2 -10
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/utils/inputModality.d.ts +3 -0
- package/dist/utils/inputModality.js +18 -0
- package/dist/utils/inputModality.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { getLastInputModality } from "../../utils/inputModality.js";
|
|
2
3
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
3
4
|
import { mergeRefs } from "../../utils/merge-refs.js";
|
|
4
5
|
import { ChatComposerContext, useChatComposerContext } from "./ChatComposerContext.js";
|
|
@@ -16,6 +17,7 @@ var DRAWER_INTENT_CLASSES = {
|
|
|
16
17
|
function isAttachmentTargetBlocked(target) {
|
|
17
18
|
return target instanceof Element && target.closest(":disabled, [readonly], [aria-disabled=\"true\"], [aria-readonly=\"true\"]") !== null;
|
|
18
19
|
}
|
|
20
|
+
var COMPOSER_INPUT_SELECTOR = "textarea, [contenteditable=true]";
|
|
19
21
|
var COMPOSER_CLICK_TARGET_SELECTOR = "a[href], button, input, select, textarea, label, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"]), [role=\"button\"], [role=\"link\"], [role=\"menuitem\"], [role=\"option\"], [role=\"combobox\"], [role=\"checkbox\"], [role=\"radio\"], [role=\"switch\"], [role=\"tab\"]";
|
|
20
22
|
function reportFieldsetValidity(fieldset) {
|
|
21
23
|
for (const element of fieldset?.elements ?? []) if ((element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) && !element.reportValidity()) return false;
|
|
@@ -24,6 +26,7 @@ function reportFieldsetValidity(fieldset) {
|
|
|
24
26
|
function ChatComposer({ children, drawer, drawerIntent = "neutral", className, ref, disabled = false, submitDisabled = false, action = "send", onStop, onSubmit, onFilesSelected, onDragOver, onDragLeave, onDropCapture, onPasteCapture, noValidate, ...props }) {
|
|
25
27
|
const formRef = useRef(null);
|
|
26
28
|
const [isDropTarget, setIsDropTarget] = useState(false);
|
|
29
|
+
const [showsFocusRing, setShowsFocusRing] = useState(false);
|
|
27
30
|
const canSubmit = !disabled && !submitDisabled && action === "send" && !!onSubmit;
|
|
28
31
|
const hasDrawer = Boolean(drawer);
|
|
29
32
|
const fieldsetRef = useRef(null);
|
|
@@ -97,7 +100,11 @@ function ChatComposer({ children, drawer, drawerIntent = "neutral", className, r
|
|
|
97
100
|
if (event.defaultPrevented || !(event.target instanceof Element) || event.target.closest(COMPOSER_CLICK_TARGET_SELECTOR) || window.getSelection()?.isCollapsed === false) return;
|
|
98
101
|
inputFocusRef.current?.();
|
|
99
102
|
},
|
|
100
|
-
|
|
103
|
+
onPointerDown: () => setShowsFocusRing(false),
|
|
104
|
+
onFocus: (event) => {
|
|
105
|
+
if (event.target.matches(COMPOSER_INPUT_SELECTOR)) setShowsFocusRing(getLastInputModality() === "keyboard");
|
|
106
|
+
},
|
|
107
|
+
className: cn("relative m-0 flex w-full min-w-0 flex-col gap-space-2 rounded-lg border border-subtle bg-elevated p-space-2 transition-[border-color,box-shadow,background-color] duration-normal motion-reduce:transition-none", showsFocusRing && "has-[:is(textarea,[contenteditable=true]):focus]:border-focus has-[:is(textarea,[contenteditable=true]):focus]:shadow-[0_0_0_1px_var(--border-focus)]", disabled && "border-disabled bg-input-disabled", isDropTarget && !disabled && "border-focus bg-surface-level-2 shadow-[0_0_0_1px_var(--border-focus)]"),
|
|
101
108
|
children
|
|
102
109
|
})]
|
|
103
110
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatComposer.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposer.tsx"],"sourcesContent":["import type { ComponentPropsWithRef, ReactNode } from 'react';\nimport { useRef, useState } from 'react';\n\nimport { ArrowUpIcon } from '@phosphor-icons/react/dist/ssr/ArrowUp';\nimport { StopIcon } from '@phosphor-icons/react/dist/ssr/Stop';\n\nimport { cn } from '../../utils/cn';\nimport { mergeRefs } from '../../utils/merge-refs';\nimport { IconButton } from '../IconButton';\nimport type { IconButtonProps } from '../IconButton';\nimport {\n ChatComposerContext,\n type ChatComposerContextValue,\n useChatComposerContext,\n} from './ChatComposerContext';\n\nexport type ChatComposerDrawerIntent = 'neutral' | 'info' | 'warning' | 'error';\n\n// Dividers match the drawer border, so stacked drawer content reads as one surface.\nconst DRAWER_INTENT_CLASSES: Record<ChatComposerDrawerIntent, string> = {\n neutral: 'border-subtle divide-subtle bg-surface-level-2',\n info: 'border-brand-subtle divide-brand-subtle bg-brand-subtle',\n warning: 'border-warning divide-warning bg-warning',\n error: 'border-error divide-error bg-error',\n};\n\nexport type ChatComposerProps = ComponentPropsWithRef<'form'> & {\n /**\n * Supplementary content attached above the editor, inside the composer form.\n * Several items, such as a plan and a question, stack with dividers; put the\n * one the input answers last, next to it.\n */\n drawer?: ReactNode;\n /**\n * Drawer surface color. Color alone doesn't convey severity, so the drawer\n * content should also say it in text or with an icon.\n */\n drawerIntent?: ChatComposerDrawerIntent;\n /**\n * Blocks writing and sending. Stop stays available while `action` is\n * `stop`, so host controls inside the composer must take `disabled`\n * themselves to stay disabled during a response.\n */\n disabled?: boolean;\n submitDisabled?: boolean;\n onFilesSelected?: (files: File[]) => void;\n} & (\n | { action?: 'send' | 'sending'; onStop?: never }\n | { action: 'stop'; onStop: () => void }\n /** A stop request is pending; Stop shows progress and sending stays blocked. */\n | { action: 'stopping'; onStop?: never }\n );\n\n// A disabled or read-only part of the composer, such as a read-only message\n// input, does not accept input, so files dropped or pasted onto it are not\n// attached either.\nfunction isAttachmentTargetBlocked(target: EventTarget) {\n return (\n target instanceof Element &&\n target.closest(\n ':disabled, [readonly], [aria-disabled=\"true\"], [aria-readonly=\"true\"]'\n ) !== null\n );\n}\n\n// Clicks on the composer's own empty space go to the message input; clicks on\n// controls, fields, links, and the editor itself keep their behavior.\nconst COMPOSER_CLICK_TARGET_SELECTOR =\n 'a[href], button, input, select, textarea, label, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"]), [role=\"button\"], [role=\"link\"], [role=\"menuitem\"], [role=\"option\"], [role=\"combobox\"], [role=\"checkbox\"], [role=\"radio\"], [role=\"switch\"], [role=\"tab\"]';\n\n// A fieldset is barred from constraint validation, so its own\n// reportValidity() never inspects the controls inside it.\nfunction reportFieldsetValidity(fieldset: HTMLFieldSetElement | null) {\n for (const element of fieldset?.elements ?? []) {\n if (\n (element instanceof HTMLInputElement ||\n element instanceof HTMLSelectElement ||\n element instanceof HTMLTextAreaElement) &&\n !element.reportValidity()\n )\n return false;\n }\n return true;\n}\n\nexport function ChatComposer({\n children,\n drawer,\n drawerIntent = 'neutral',\n className,\n ref,\n disabled = false,\n submitDisabled = false,\n action = 'send',\n onStop,\n onSubmit,\n onFilesSelected,\n onDragOver,\n onDragLeave,\n onDropCapture,\n onPasteCapture,\n noValidate,\n ...props\n}: ChatComposerProps) {\n const formRef = useRef<HTMLFormElement>(null);\n const [isDropTarget, setIsDropTarget] = useState(false);\n const canSubmit =\n !disabled && !submitDisabled && action === 'send' && !!onSubmit;\n const hasDrawer = Boolean(drawer);\n const fieldsetRef = useRef<HTMLFieldSetElement>(null);\n const inputFocusRef = useRef<(() => boolean) | null>(null);\n // Inert drawer fields cannot be focused to report errors, so the drawer's\n // host validates them; fields outside the drawer keep native checks.\n const validatesFieldsetOnly = noValidate === undefined && hasDrawer;\n\n return (\n <ChatComposerContext.Provider\n value={{\n disabled,\n canSubmit,\n action,\n onStop,\n onFilesSelected,\n inputFocusRef,\n submit: onSubmit\n ? () => {\n if (canSubmit) formRef.current?.requestSubmit();\n }\n : undefined,\n }}\n >\n <form\n {...props}\n ref={mergeRefs([formRef, ref])}\n noValidate={noValidate ?? hasDrawer}\n className={cn('isolate w-full min-w-0 @container/composer', className)}\n onSubmit={(event) => {\n event.preventDefault();\n if (!canSubmit) return;\n if (\n validatesFieldsetOnly &&\n !reportFieldsetValidity(fieldsetRef.current)\n )\n return;\n onSubmit?.(event);\n }}\n onDragOver={(event) => {\n onDragOver?.(event);\n if (event.defaultPrevented || !onFilesSelected) return;\n if (!event.dataTransfer.types.includes('Files')) return;\n event.preventDefault();\n const canAttach =\n !disabled && !isAttachmentTargetBlocked(event.target);\n event.dataTransfer.dropEffect = canAttach ? 'copy' : 'none';\n setIsDropTarget(canAttach);\n }}\n onDragLeave={(event) => {\n onDragLeave?.(event);\n if (\n !(event.relatedTarget instanceof Node) ||\n !event.currentTarget.contains(event.relatedTarget)\n ) {\n setIsDropTarget(false);\n }\n }}\n onDropCapture={(event) => {\n onDropCapture?.(event);\n setIsDropTarget(false);\n if (event.defaultPrevented || !onFilesSelected) return;\n const files = Array.from(event.dataTransfer.files);\n if (!files.length) return;\n event.preventDefault();\n if (!disabled && !isAttachmentTargetBlocked(event.target)) {\n onFilesSelected(files);\n }\n }}\n onPasteCapture={(event) => {\n onPasteCapture?.(event);\n if (event.defaultPrevented || !onFilesSelected) return;\n const files = Array.from(event.clipboardData.files);\n if (!files.length) return;\n if (disabled || isAttachmentTargetBlocked(event.target)) {\n event.preventDefault();\n return;\n }\n // Let the focused editor preserve mixed-paste text and its selection.\n if (!event.clipboardData.getData('text/plain')) {\n event.preventDefault();\n }\n onFilesSelected(files);\n }}\n >\n {hasDrawer && (\n <fieldset\n disabled={disabled}\n className={cn(\n // Extends under the composer's rounded top so the seam stays hidden.\n 'mx-space-3 -mb-space-3 max-h-[50dvh] min-w-0 divide-y overflow-y-auto overscroll-contain rounded-t-lg border border-b-0 pb-space-3 duration-normal ease-out animate-in fade-in slide-in-from-bottom-2 motion-reduce:animate-none',\n DRAWER_INTENT_CLASSES[drawerIntent],\n disabled && 'border-disabled divide-disabled'\n )}\n >\n {drawer}\n </fieldset>\n )}\n <fieldset\n ref={fieldsetRef}\n // A disabled fieldset would also disable Stop; the composer's own\n // parts read `disabled` from context instead.\n disabled={disabled && action !== 'stop'}\n onClick={(event) => {\n if (\n event.defaultPrevented ||\n !(event.target instanceof Element) ||\n event.target.closest(COMPOSER_CLICK_TARGET_SELECTOR) ||\n // Finishing a drag selection, such as in an attachment name.\n window.getSelection()?.isCollapsed === false\n )\n return;\n inputFocusRef.current?.();\n }}\n className={cn(\n 'relative m-0 flex w-full min-w-0 flex-col gap-space-2 rounded-lg border border-subtle bg-elevated p-space-2 transition-[border-color,box-shadow,background-color] duration-normal motion-reduce:transition-none',\n // Toolbar menus portal out, so focus-within would flash as focus\n // moves from their trigger to the menu; only typing shows focus.\n 'has-[:is(textarea,[contenteditable=true]):focus]:border-focus has-[:is(textarea,[contenteditable=true]):focus]:shadow-[0_0_0_1px_var(--border-focus)]',\n disabled && 'border-disabled bg-input-disabled',\n isDropTarget &&\n !disabled &&\n 'border-focus bg-surface-level-2 shadow-[0_0_0_1px_var(--border-focus)]'\n )}\n >\n {children}\n </fieldset>\n </form>\n </ChatComposerContext.Provider>\n );\n}\n\nexport interface ChatComposerToolbarProps extends ComponentPropsWithRef<'div'> {\n modelSelector?: ReactNode;\n actions?: ReactNode;\n}\n\nexport function ChatComposerToolbar({\n children,\n modelSelector,\n actions = <ChatComposerAction />,\n className,\n ...props\n}: ChatComposerToolbarProps) {\n return (\n <div\n {...props}\n className={cn('flex min-w-0 items-center gap-space-2', className)}\n >\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-space-1 @[440px]/composer:gap-space-2\">\n {children}\n {modelSelector != null && (\n <div className=\"min-w-0 max-w-full [&>*]:max-w-full\">\n {modelSelector}\n </div>\n )}\n </div>\n <div className=\"flex shrink-0 items-center gap-space-1\">{actions}</div>\n </div>\n );\n}\n\nconst ACTION_LABELS = {\n send: 'Send message',\n sending: 'Sending message',\n stop: 'Stop response',\n stopping: 'Stopping response',\n} satisfies Record<ChatComposerContextValue['action'], string>;\n\n// Pending sends use the composer's action=\"sending\", which also blocks the\n// send shortcuts; a button-level loading state would only block clicks.\nexport type ChatComposerActionProps = Omit<\n IconButtonProps,\n 'icon' | 'type' | 'onClick' | 'asChild' | 'label' | 'loading'\n> & { label?: string };\n\nexport function ChatComposerAction({\n disabled,\n label,\n ...props\n}: ChatComposerActionProps) {\n const composer = useChatComposerContext();\n const isStop = composer.action === 'stop';\n const isStopping = composer.action === 'stopping';\n return (\n <IconButton\n size=\"sm\"\n round\n color=\"primary\"\n iconWeight=\"regular\"\n {...props}\n type={isStop || isStopping ? 'button' : 'submit'}\n icon={isStop || isStopping ? StopIcon : ArrowUpIcon}\n label={label ?? ACTION_LABELS[composer.action]}\n // canSubmit is false while disabled, sending, or stopping, so this also\n // disables Stop once a stop is pending; Stop ignores `disabled` otherwise.\n disabled={disabled || (!isStop && !composer.canSubmit)}\n loading={composer.action === 'sending' || isStopping}\n onClick={isStop ? composer.onStop : undefined}\n />\n );\n}\n"],"mappings":";;;;;;;;;AAmBA,IAAM,wBAAkE;CACtE,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;AACT;AAgCA,SAAS,0BAA0B,QAAqB;CACtD,OACE,kBAAkB,WAClB,OAAO,QACL,2EACF,MAAM;AAEV;AAIA,IAAM,iCACJ;AAIF,SAAS,uBAAuB,UAAsC;CACpE,KAAK,MAAM,WAAW,UAAU,YAAY,CAAC,GAC3C,KACG,mBAAmB,oBAClB,mBAAmB,qBACnB,mBAAmB,wBACrB,CAAC,QAAQ,eAAe,GAExB,OAAO;CAEX,OAAO;AACT;AAEA,SAAgB,aAAa,EAC3B,UACA,QACA,eAAe,WACf,WACA,KACA,WAAW,OACX,iBAAiB,OACjB,SAAS,QACT,QACA,UACA,iBACA,YACA,aACA,eACA,gBACA,YACA,GAAG,SACiB;CACpB,MAAM,UAAU,OAAwB,IAAI;CAC5C,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,YACJ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AM;CACN,SAAS;CACT,MAAM;CACN,UAAU;AACZ;AASA,SAAgB,mBAAmB,EACjC,UACA,OACA,GAAG,SACuB;CAC1B,MAAM,WAAW,uBAAuB;CACxC,MAAM,SAAS,SAAS,WAAW;CACnC,MAAM,aAAa,SAAS,WAAW;CACvC,OACE,oBAAC,YAAD;EACE,MAAK;EACL,OAAA;EACA,OAAM;EACN,YAAW;EACX,GAAI;EACJ,MAAM,UAAU,aAAa,WAAW;EACxC,MAAM,UAAU,aAAa,WAAW;EACxC,OAAO,SAAS,cAAc,SAAS;EAGvC,UAAU,YAAa,CAAC,UAAU,CAAC,SAAS;EAC5C,SAAS,SAAS,WAAW,aAAa;EAC1C,SAAS,SAAS,SAAS,SAAS,KAAA;CACrC,CAAA;AAEL"}
|
|
1
|
+
{"version":3,"file":"ChatComposer.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposer.tsx"],"sourcesContent":["import type { ComponentPropsWithRef, ReactNode } from 'react';\nimport { useRef, useState } from 'react';\n\nimport { ArrowUpIcon } from '@phosphor-icons/react/dist/ssr/ArrowUp';\nimport { StopIcon } from '@phosphor-icons/react/dist/ssr/Stop';\n\nimport { cn } from '../../utils/cn';\nimport { getLastInputModality } from '../../utils/inputModality';\nimport { mergeRefs } from '../../utils/merge-refs';\nimport { IconButton } from '../IconButton';\nimport type { IconButtonProps } from '../IconButton';\nimport {\n ChatComposerContext,\n type ChatComposerContextValue,\n useChatComposerContext,\n} from './ChatComposerContext';\n\nexport type ChatComposerDrawerIntent = 'neutral' | 'info' | 'warning' | 'error';\n\n// Dividers match the drawer border, so stacked drawer content reads as one surface.\nconst DRAWER_INTENT_CLASSES: Record<ChatComposerDrawerIntent, string> = {\n neutral: 'border-subtle divide-subtle bg-surface-level-2',\n info: 'border-brand-subtle divide-brand-subtle bg-brand-subtle',\n warning: 'border-warning divide-warning bg-warning',\n error: 'border-error divide-error bg-error',\n};\n\nexport type ChatComposerProps = ComponentPropsWithRef<'form'> & {\n /**\n * Supplementary content attached above the editor, inside the composer form.\n * Several items, such as a plan and a question, stack with dividers; put the\n * one the input answers last, next to it.\n */\n drawer?: ReactNode;\n /**\n * Drawer surface color. Color alone doesn't convey severity, so the drawer\n * content should also say it in text or with an icon.\n */\n drawerIntent?: ChatComposerDrawerIntent;\n /**\n * Blocks writing and sending. Stop stays available while `action` is\n * `stop`, so host controls inside the composer must take `disabled`\n * themselves to stay disabled during a response.\n */\n disabled?: boolean;\n submitDisabled?: boolean;\n onFilesSelected?: (files: File[]) => void;\n} & (\n | { action?: 'send' | 'sending'; onStop?: never }\n | { action: 'stop'; onStop: () => void }\n /** A stop request is pending; Stop shows progress and sending stays blocked. */\n | { action: 'stopping'; onStop?: never }\n );\n\n// A disabled or read-only part of the composer, such as a read-only message\n// input, does not accept input, so files dropped or pasted onto it are not\n// attached either.\nfunction isAttachmentTargetBlocked(target: EventTarget) {\n return (\n target instanceof Element &&\n target.closest(\n ':disabled, [readonly], [aria-disabled=\"true\"], [aria-readonly=\"true\"]'\n ) !== null\n );\n}\n\nconst COMPOSER_INPUT_SELECTOR = 'textarea, [contenteditable=true]';\n\n// Clicks on the composer's own empty space go to the message input; clicks on\n// controls, fields, links, and the editor itself keep their behavior.\nconst COMPOSER_CLICK_TARGET_SELECTOR =\n 'a[href], button, input, select, textarea, label, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"]), [role=\"button\"], [role=\"link\"], [role=\"menuitem\"], [role=\"option\"], [role=\"combobox\"], [role=\"checkbox\"], [role=\"radio\"], [role=\"switch\"], [role=\"tab\"]';\n\n// A fieldset is barred from constraint validation, so its own\n// reportValidity() never inspects the controls inside it.\nfunction reportFieldsetValidity(fieldset: HTMLFieldSetElement | null) {\n for (const element of fieldset?.elements ?? []) {\n if (\n (element instanceof HTMLInputElement ||\n element instanceof HTMLSelectElement ||\n element instanceof HTMLTextAreaElement) &&\n !element.reportValidity()\n )\n return false;\n }\n return true;\n}\n\nexport function ChatComposer({\n children,\n drawer,\n drawerIntent = 'neutral',\n className,\n ref,\n disabled = false,\n submitDisabled = false,\n action = 'send',\n onStop,\n onSubmit,\n onFilesSelected,\n onDragOver,\n onDragLeave,\n onDropCapture,\n onPasteCapture,\n noValidate,\n ...props\n}: ChatComposerProps) {\n const formRef = useRef<HTMLFormElement>(null);\n const [isDropTarget, setIsDropTarget] = useState(false);\n const [showsFocusRing, setShowsFocusRing] = useState(false);\n const canSubmit =\n !disabled && !submitDisabled && action === 'send' && !!onSubmit;\n const hasDrawer = Boolean(drawer);\n const fieldsetRef = useRef<HTMLFieldSetElement>(null);\n const inputFocusRef = useRef<(() => boolean) | null>(null);\n // Inert drawer fields cannot be focused to report errors, so the drawer's\n // host validates them; fields outside the drawer keep native checks.\n const validatesFieldsetOnly = noValidate === undefined && hasDrawer;\n\n return (\n <ChatComposerContext.Provider\n value={{\n disabled,\n canSubmit,\n action,\n onStop,\n onFilesSelected,\n inputFocusRef,\n submit: onSubmit\n ? () => {\n if (canSubmit) formRef.current?.requestSubmit();\n }\n : undefined,\n }}\n >\n <form\n {...props}\n ref={mergeRefs([formRef, ref])}\n noValidate={noValidate ?? hasDrawer}\n className={cn('isolate w-full min-w-0 @container/composer', className)}\n onSubmit={(event) => {\n event.preventDefault();\n if (!canSubmit) return;\n if (\n validatesFieldsetOnly &&\n !reportFieldsetValidity(fieldsetRef.current)\n )\n return;\n onSubmit?.(event);\n }}\n onDragOver={(event) => {\n onDragOver?.(event);\n if (event.defaultPrevented || !onFilesSelected) return;\n if (!event.dataTransfer.types.includes('Files')) return;\n event.preventDefault();\n const canAttach =\n !disabled && !isAttachmentTargetBlocked(event.target);\n event.dataTransfer.dropEffect = canAttach ? 'copy' : 'none';\n setIsDropTarget(canAttach);\n }}\n onDragLeave={(event) => {\n onDragLeave?.(event);\n if (\n !(event.relatedTarget instanceof Node) ||\n !event.currentTarget.contains(event.relatedTarget)\n ) {\n setIsDropTarget(false);\n }\n }}\n onDropCapture={(event) => {\n onDropCapture?.(event);\n setIsDropTarget(false);\n if (event.defaultPrevented || !onFilesSelected) return;\n const files = Array.from(event.dataTransfer.files);\n if (!files.length) return;\n event.preventDefault();\n if (!disabled && !isAttachmentTargetBlocked(event.target)) {\n onFilesSelected(files);\n }\n }}\n onPasteCapture={(event) => {\n onPasteCapture?.(event);\n if (event.defaultPrevented || !onFilesSelected) return;\n const files = Array.from(event.clipboardData.files);\n if (!files.length) return;\n if (disabled || isAttachmentTargetBlocked(event.target)) {\n event.preventDefault();\n return;\n }\n // Let the focused editor preserve mixed-paste text and its selection.\n if (!event.clipboardData.getData('text/plain')) {\n event.preventDefault();\n }\n onFilesSelected(files);\n }}\n >\n {hasDrawer && (\n <fieldset\n disabled={disabled}\n className={cn(\n // Extends under the composer's rounded top so the seam stays hidden.\n 'mx-space-3 -mb-space-3 max-h-[50dvh] min-w-0 divide-y overflow-y-auto overscroll-contain rounded-t-lg border border-b-0 pb-space-3 duration-normal ease-out animate-in fade-in slide-in-from-bottom-2 motion-reduce:animate-none',\n DRAWER_INTENT_CLASSES[drawerIntent],\n disabled && 'border-disabled divide-disabled'\n )}\n >\n {drawer}\n </fieldset>\n )}\n <fieldset\n ref={fieldsetRef}\n // A disabled fieldset would also disable Stop; the composer's own\n // parts read `disabled` from context instead.\n disabled={disabled && action !== 'stop'}\n onClick={(event) => {\n if (\n event.defaultPrevented ||\n !(event.target instanceof Element) ||\n event.target.closest(COMPOSER_CLICK_TARGET_SELECTOR) ||\n // Finishing a drag selection, such as in an attachment name.\n window.getSelection()?.isCollapsed === false\n )\n return;\n inputFocusRef.current?.();\n }}\n onPointerDown={() => setShowsFocusRing(false)}\n onFocus={(event) => {\n if (event.target.matches(COMPOSER_INPUT_SELECTOR)) {\n setShowsFocusRing(getLastInputModality() === 'keyboard');\n }\n }}\n className={cn(\n 'relative m-0 flex w-full min-w-0 flex-col gap-space-2 rounded-lg border border-subtle bg-elevated p-space-2 transition-[border-color,box-shadow,background-color] duration-normal motion-reduce:transition-none',\n // Toolbar menus portal out, so focus-within would flash as focus\n // moves from their trigger to the menu; only the input shows focus,\n // and only when it was reached by keyboard, like :focus-visible.\n showsFocusRing &&\n 'has-[:is(textarea,[contenteditable=true]):focus]:border-focus has-[:is(textarea,[contenteditable=true]):focus]:shadow-[0_0_0_1px_var(--border-focus)]',\n disabled && 'border-disabled bg-input-disabled',\n isDropTarget &&\n !disabled &&\n 'border-focus bg-surface-level-2 shadow-[0_0_0_1px_var(--border-focus)]'\n )}\n >\n {children}\n </fieldset>\n </form>\n </ChatComposerContext.Provider>\n );\n}\n\nexport interface ChatComposerToolbarProps extends ComponentPropsWithRef<'div'> {\n modelSelector?: ReactNode;\n actions?: ReactNode;\n}\n\nexport function ChatComposerToolbar({\n children,\n modelSelector,\n actions = <ChatComposerAction />,\n className,\n ...props\n}: ChatComposerToolbarProps) {\n return (\n <div\n {...props}\n className={cn('flex min-w-0 items-center gap-space-2', className)}\n >\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-space-1 @[440px]/composer:gap-space-2\">\n {children}\n {modelSelector != null && (\n <div className=\"min-w-0 max-w-full [&>*]:max-w-full\">\n {modelSelector}\n </div>\n )}\n </div>\n <div className=\"flex shrink-0 items-center gap-space-1\">{actions}</div>\n </div>\n );\n}\n\nconst ACTION_LABELS = {\n send: 'Send message',\n sending: 'Sending message',\n stop: 'Stop response',\n stopping: 'Stopping response',\n} satisfies Record<ChatComposerContextValue['action'], string>;\n\n// Pending sends use the composer's action=\"sending\", which also blocks the\n// send shortcuts; a button-level loading state would only block clicks.\nexport type ChatComposerActionProps = Omit<\n IconButtonProps,\n 'icon' | 'type' | 'onClick' | 'asChild' | 'label' | 'loading'\n> & { label?: string };\n\nexport function ChatComposerAction({\n disabled,\n label,\n ...props\n}: ChatComposerActionProps) {\n const composer = useChatComposerContext();\n const isStop = composer.action === 'stop';\n const isStopping = composer.action === 'stopping';\n return (\n <IconButton\n size=\"sm\"\n round\n color=\"primary\"\n iconWeight=\"regular\"\n {...props}\n type={isStop || isStopping ? 'button' : 'submit'}\n icon={isStop || isStopping ? StopIcon : ArrowUpIcon}\n label={label ?? ACTION_LABELS[composer.action]}\n // canSubmit is false while disabled, sending, or stopping, so this also\n // disables Stop once a stop is pending; Stop ignores `disabled` otherwise.\n disabled={disabled || (!isStop && !composer.canSubmit)}\n loading={composer.action === 'sending' || isStopping}\n onClick={isStop ? composer.onStop : undefined}\n />\n );\n}\n"],"mappings":";;;;;;;;;;AAoBA,IAAM,wBAAkE;CACtE,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;AACT;AAgCA,SAAS,0BAA0B,QAAqB;CACtD,OACE,kBAAkB,WAClB,OAAO,QACL,2EACF,MAAM;AAEV;AAEA,IAAM,0BAA0B;AAIhC,IAAM,iCACJ;AAIF,SAAS,uBAAuB,UAAsC;CACpE,KAAK,MAAM,WAAW,UAAU,YAAY,CAAC,GAC3C,KACG,mBAAmB,oBAClB,mBAAmB,qBACnB,mBAAmB,wBACrB,CAAC,QAAQ,eAAe,GAExB,OAAO;CAEX,OAAO;AACT;AAEA,SAAgB,aAAa,EAC3B,UACA,QACA,eAAe,WACf,WACA,KACA,WAAW,OACX,iBAAiB,OACjB,SAAS,QACT,QACA,UACA,iBACA,YACA,aACA,eACA,gBACA,YACA,GAAG,SACiB;CACpB,MAAM,UAAU,OAAwB,IAAI;CAC5C,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,KAAK;CAC1D,MAAM,YACJ,CAAC,YAAY,CAAC,kBAAkB,WAAW,UAAU,CAAC,CAAC;CACzD,MAAM,YAAY,QAAQ,MAAM;CAChC,MAAM,cAAc,OAA4B,IAAI;CACpD,MAAM,gBAAgB,OAA+B,IAAI;CAGzD,MAAM,wBAAwB,eAAe,KAAA,KAAa;CAE1D,OACE,oBAAC,oBAAoB,UAArB;EACE,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA,QAAQ,iBACE;IACJ,IAAI,WAAW,QAAQ,SAAS,cAAc;GAChD,I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oBAAC,YAAD;EACE,MAAK;EACL,OAAA;EACA,OAAM;EACN,YAAW;EACX,GAAI;EACJ,MAAM,UAAU,aAAa,WAAW;EACxC,MAAM,UAAU,aAAa,WAAW;EACxC,OAAO,SAAS,cAAc,SAAS;EAGvC,UAAU,YAAa,CAAC,UAAU,CAAC,SAAS;EAC5C,SAAS,SAAS,WAAW,aAAa;EAC1C,SAAS,SAAS,SAAS,SAAS,KAAA;CACrC,CAAA;AAEL"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { getLastInputModality } from "../../utils/inputModality.js";
|
|
2
3
|
import zIndices from "../../utils/zIndices.js";
|
|
3
4
|
import { useZIndex } from "../../utils/useZIndex.js";
|
|
4
5
|
import { ZIndexProvider } from "../../utils/ZIndexContext.js";
|
|
@@ -6,15 +7,6 @@ import { Text } from "../Text/Text.js";
|
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
8
9
|
//#region packages/components/src/components/Tooltip/Tooltip.tsx
|
|
9
|
-
var focusFromKeyboard = true;
|
|
10
|
-
if (typeof document !== "undefined") {
|
|
11
|
-
document.addEventListener("keydown", (event) => {
|
|
12
|
-
if (!event.metaKey && !event.altKey && !event.ctrlKey) focusFromKeyboard = true;
|
|
13
|
-
}, true);
|
|
14
|
-
document.addEventListener("pointerdown", () => {
|
|
15
|
-
focusFromKeyboard = false;
|
|
16
|
-
}, true);
|
|
17
|
-
}
|
|
18
10
|
function Tooltip({ title, description, children, tooltipClassName, side = "top", sideOffset = 10, align = "center", alignOffset = 0, invert = false, delayDuration = 300, disabled = false, blockTriggerEvents = false, open, onOpenChange, disableHoverableContent = true }) {
|
|
19
11
|
const zIndex = useZIndex(zIndices.tooltipOverlay);
|
|
20
12
|
if (!title && !description || disabled) return children;
|
|
@@ -26,7 +18,7 @@ function Tooltip({ title, description, children, tooltipClassName, side = "top",
|
|
|
26
18
|
children: [/* @__PURE__ */ jsx(TooltipPrimitive.Trigger, {
|
|
27
19
|
asChild: true,
|
|
28
20
|
onFocus: (e) => {
|
|
29
|
-
if (
|
|
21
|
+
if (getLastInputModality() === "pointer") e.preventDefault();
|
|
30
22
|
},
|
|
31
23
|
onPointerDown: (e) => {
|
|
32
24
|
if (blockTriggerEvents) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":[],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip';\n\nimport { cn } from '../../utils/cn';\nimport { useZIndex } from '../../utils/useZIndex';\nimport { ZIndexProvider } from '../../utils/ZIndexContext';\nimport zIndices from '../../utils/zIndices';\nimport { Text } from '../Text';\n\nexport type TooltipProps = {\n title?: string | ReactNode;\n description?: ReactNode;\n children: ReactNode;\n tooltipClassName?: string;\n side?: 'top' | 'bottom' | 'left' | 'right';\n sideOffset?: number;\n align?: 'start' | 'center' | 'end';\n alignOffset?: number;\n invert?: boolean;\n delayDuration?: number;\n disabled?: boolean;\n blockTriggerEvents?: boolean;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n disableHoverableContent?: boolean;\n};\n\
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":[],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip';\n\nimport { cn } from '../../utils/cn';\nimport { getLastInputModality } from '../../utils/inputModality';\nimport { useZIndex } from '../../utils/useZIndex';\nimport { ZIndexProvider } from '../../utils/ZIndexContext';\nimport zIndices from '../../utils/zIndices';\nimport { Text } from '../Text';\n\nexport type TooltipProps = {\n title?: string | ReactNode;\n description?: ReactNode;\n children: ReactNode;\n tooltipClassName?: string;\n side?: 'top' | 'bottom' | 'left' | 'right';\n sideOffset?: number;\n align?: 'start' | 'center' | 'end';\n alignOffset?: number;\n invert?: boolean;\n delayDuration?: number;\n disabled?: boolean;\n blockTriggerEvents?: boolean;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n disableHoverableContent?: boolean;\n};\n\n// Tooltip sets two opinionated defaults — override with caution:\n// - delayDuration=300: prevents tooltips from blocking clicks\n// - disableHoverableContent=true: dismisses the tooltip when hovering off the trigger\nexport function Tooltip({\n title,\n description,\n children,\n tooltipClassName,\n side = 'top',\n sideOffset = 10,\n align = 'center',\n alignOffset = 0,\n invert = false,\n delayDuration = 300,\n disabled = false,\n blockTriggerEvents = false,\n open,\n onOpenChange,\n disableHoverableContent = true,\n}: TooltipProps) {\n const zIndex = useZIndex(zIndices.tooltipOverlay);\n\n if ((!title && !description) || disabled) {\n return children;\n }\n\n return (\n <TooltipPrimitive.Root\n delayDuration={delayDuration}\n open={open}\n onOpenChange={onOpenChange}\n disableHoverableContent={disableHoverableContent}\n >\n <TooltipPrimitive.Trigger\n asChild\n onFocus={(e) => {\n if (getLastInputModality() === 'pointer') e.preventDefault();\n }}\n onPointerDown={(e) => {\n if (blockTriggerEvents) {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n {children}\n </TooltipPrimitive.Trigger>\n <TooltipPrimitive.Portal>\n <TooltipPrimitive.Content\n sideOffset={sideOffset}\n side={side}\n align={align}\n alignOffset={alignOffset}\n collisionPadding={8}\n className={cn(\n 'max-w-[320px] overflow-hidden rounded-md border border-subtle bg-popover p-space-2 text-sm shadow-md',\n 'animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',\n tooltipClassName,\n invert && 'invert'\n )}\n style={{ zIndex }}\n >\n <ZIndexProvider value={zIndex}>\n <div className=\"flex flex-col gap-space-2 text-xxs\">\n {typeof title === 'string' ? (\n <Text\n variant=\"sm\"\n data-target=\"title\"\n className={!tooltipClassName ? 'text-primary' : ''}\n >\n {title}\n </Text>\n ) : (\n title\n )}\n {description && (\n <Text\n variant=\"sm\"\n className={!tooltipClassName ? 'text-secondary' : ''}\n data-target=\"description\"\n >\n {description}\n </Text>\n )}\n </div>\n </ZIndexProvider>\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n );\n}\n"],"mappings":";;;;;;;;;AAgCA,SAAgB,QAAQ,EACtB,OACA,aACA,UACA,kBACA,OAAO,OACP,aAAa,IACb,QAAQ,UACR,cAAc,GACd,SAAS,OACT,gBAAgB,KAChB,WAAW,OACX,qBAAqB,OACrB,MACA,cACA,0BAA0B,QACX;CACf,MAAM,SAAS,UAAU,SAAS,cAAc;CAEhD,IAAK,CAAC,SAAS,CAAC,eAAgB,UAC9B,OAAO;CAGT,OACE,qBAAC,iBAAiB,MAAlB;EACiB;EACT;EACQ;EACW;EAJ3B,UAAA,CAME,oBAAC,iBAAiB,SAAlB;GACE,SAAA;GACA,UAAU,MAAM;IACd,IAAI,qBAAqB,MAAM,WAAW,EAAE,eAAe;GAC7D;GACA,gBAAgB,MAAM;IACpB,IAAI,oBAAoB;KACtB,EAAE,eAAe;KACjB,EAAE,gBAAgB;IACpB;GACF;GAEC;EACuB,CAAA,GAC1B,oBAAC,iBAAiB,QAAlB,EAAA,UACE,oBAAC,iBAAiB,SAAlB;GACc;GACN;GACC;GACM;GACb,kBAAkB;GAClB,WAAW,GACT,wGACA,8RACA,kBACA,UAAU,QACZ;GACA,OAAO,EAAE,OAAO;GAEhB,UAAA,oBAAC,gBAAD;IAAgB,OAAO;IACrB,UAAA,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACG,OAAO,UAAU,WAChB,oBAAC,MAAD;MACE,SAAQ;MACR,eAAY;MACZ,WAAW,CAAC,mBAAmB,iBAAiB;MAE/C,UAAA;KACG,CAAA,IAEN,OAED,eACC,oBAAC,MAAD;MACE,SAAQ;MACR,WAAW,CAAC,mBAAmB,mBAAmB;MAClD,eAAY;MAEX,UAAA;KACG,CAAA,CAEL;;GACS,CAAA;EACQ,CAAA,EACH,CAAA,CACJ;;AAE3B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region packages/components/src/utils/inputModality.ts
|
|
2
|
+
var lastInputModality = null;
|
|
3
|
+
if (typeof document !== "undefined") {
|
|
4
|
+
document.addEventListener("keydown", (event) => {
|
|
5
|
+
if (!event.metaKey && !event.altKey && !event.ctrlKey) lastInputModality = "keyboard";
|
|
6
|
+
}, true);
|
|
7
|
+
document.addEventListener("pointerdown", () => {
|
|
8
|
+
lastInputModality = "pointer";
|
|
9
|
+
}, true);
|
|
10
|
+
}
|
|
11
|
+
/** The last user input type, or null before any keyboard or pointer input. */
|
|
12
|
+
function getLastInputModality() {
|
|
13
|
+
return lastInputModality;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getLastInputModality };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=inputModality.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputModality.js","names":[],"sources":["../../src/utils/inputModality.ts"],"sourcesContent":["export type InputModality = 'keyboard' | 'pointer';\n\nlet lastInputModality: InputModality | null = null;\n\nif (typeof document !== 'undefined') {\n document.addEventListener(\n 'keydown',\n (event) => {\n if (!event.metaKey && !event.altKey && !event.ctrlKey) {\n lastInputModality = 'keyboard';\n }\n },\n true\n );\n document.addEventListener(\n 'pointerdown',\n () => {\n lastInputModality = 'pointer';\n },\n true\n );\n}\n\n/** The last user input type, or null before any keyboard or pointer input. */\nexport function getLastInputModality(): InputModality | null {\n return lastInputModality;\n}\n"],"mappings":";AAEA,IAAI,oBAA0C;AAE9C,IAAI,OAAO,aAAa,aAAa;CACnC,SAAS,iBACP,YACC,UAAU;EACT,IAAI,CAAC,MAAM,WAAW,CAAC,MAAM,UAAU,CAAC,MAAM,SAC5C,oBAAoB;CAExB,GACA,IACF;CACA,SAAS,iBACP,qBACM;EACJ,oBAAoB;CACtB,GACA,IACF;AACF;;AAGA,SAAgB,uBAA6C;CAC3D,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/macaw-components",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.21",
|
|
4
4
|
"description": "React components and usage guidance for the Macaw Design System.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -669,7 +669,7 @@
|
|
|
669
669
|
"@fontsource/fira-code": "^5.2.7",
|
|
670
670
|
"@fontsource/inter": "^5.2.8",
|
|
671
671
|
"@headlessui/react": "^2.2.10",
|
|
672
|
-
"@langchain/macaw-tokens": "1.7.
|
|
672
|
+
"@langchain/macaw-tokens": "1.7.21",
|
|
673
673
|
"@lezer/common": "^1.2.1",
|
|
674
674
|
"@lezer/highlight": "^1.2.0",
|
|
675
675
|
"@lezer/yaml": "^1.0.4",
|