@langchain/macaw-components 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog.json +740 -548
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +4 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +160 -42
- package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/components/ChatComposer/ChatComposer.d.ts +31 -0
- package/dist/components/ChatComposer/ChatComposer.js +142 -0
- package/dist/components/ChatComposer/ChatComposer.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerAttachments.d.ts +17 -0
- package/dist/components/ChatComposer/ChatComposerAttachments.js +117 -0
- package/dist/components/ChatComposer/ChatComposerAttachments.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlock.d.ts +2 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlock.js +100 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlock.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.d.ts +19 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.js +107 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlockView.d.ts +5 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlockView.js +104 -0
- package/dist/components/ChatComposer/ChatComposerCodeBlockView.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerContext.d.ts +15 -0
- package/dist/components/ChatComposer/ChatComposerContext.js +16 -0
- package/dist/components/ChatComposer/ChatComposerContext.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerInput.d.ts +19 -0
- package/dist/components/ChatComposer/ChatComposerInput.js +38 -0
- package/dist/components/ChatComposer/ChatComposerInput.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerModelSelect.d.ts +3 -0
- package/dist/components/ChatComposer/ChatComposerModelSelect.js +56 -0
- package/dist/components/ChatComposer/ChatComposerModelSelect.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerPlainInput.d.ts +8 -0
- package/dist/components/ChatComposer/ChatComposerPlainInput.js +48 -0
- package/dist/components/ChatComposer/ChatComposerPlainInput.js.map +1 -0
- package/dist/components/ChatComposer/ChatComposerRichInput.d.ts +7 -0
- package/dist/components/ChatComposer/ChatComposerRichInput.js +53 -0
- package/dist/components/ChatComposer/ChatComposerRichInput.js.map +1 -0
- package/dist/components/ChatComposer/index.d.ts +10 -0
- package/dist/components/ChatComposer/index.js +6 -0
- package/dist/components/ChatComposer/useChatComposerEditor.d.ts +21 -0
- package/dist/components/ChatComposer/useChatComposerEditor.js +113 -0
- package/dist/components/ChatComposer/useChatComposerEditor.js.map +1 -0
- package/dist/components/ChatMessage/ChatMessage.js +1 -1
- package/dist/components/Code/CodeLite.js +1 -1
- package/dist/components/Code/index.js +7 -8
- package/dist/components/Code/index.js.map +1 -1
- package/dist/components/Input/Input.js +1 -1
- package/dist/components/Select/Select.d.ts +5 -0
- package/dist/components/Select/Select.js +2 -1
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/TextWithLinks.js +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +7 -2
- package/dist/components.css +2 -0
- package/dist/index.js +7 -2
- package/dist/utilities.css +1 -1
- package/docs/DESIGN.md +49 -15
- package/package.json +13 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { isComposerSubmitKey, useChatComposerContext } from "./ChatComposerContext.js";
|
|
2
|
+
import { Textarea } from "../Textarea/Textarea.js";
|
|
3
|
+
import { useImperativeHandle, useRef } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region packages/components/src/components/ChatComposer/ChatComposerPlainInput.tsx
|
|
6
|
+
/** Keeps the composer usable with plain Markdown text when the rich editor fails. */
|
|
7
|
+
function ChatComposerPlainInput({ ref, value, onChange, placeholder = "Write a message…", disabled = false, readOnly = false, autoFocus = false, minHeight, maxHeight, className, "aria-label": ariaLabel = "Message", "aria-describedby": ariaDescribedBy }) {
|
|
8
|
+
const composer = useChatComposerContext();
|
|
9
|
+
const textareaRef = useRef(null);
|
|
10
|
+
const isDisabled = composer.disabled || disabled;
|
|
11
|
+
const editable = !isDisabled && !readOnly;
|
|
12
|
+
useImperativeHandle(ref, () => ({ focus: () => {
|
|
13
|
+
if (editable) textareaRef.current?.focus();
|
|
14
|
+
} }), [editable]);
|
|
15
|
+
useImperativeHandle(composer.inputFocusRef, () => () => {
|
|
16
|
+
if (!editable || !textareaRef.current) return false;
|
|
17
|
+
textareaRef.current.focus();
|
|
18
|
+
return true;
|
|
19
|
+
}, [editable]);
|
|
20
|
+
return /* @__PURE__ */ jsx(Textarea, {
|
|
21
|
+
ref: textareaRef,
|
|
22
|
+
variant: "plain",
|
|
23
|
+
size: "md",
|
|
24
|
+
rows: 1,
|
|
25
|
+
autoResize: true,
|
|
26
|
+
maxHeight,
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
placeholder,
|
|
30
|
+
disabled: isDisabled,
|
|
31
|
+
readOnly,
|
|
32
|
+
autoFocus,
|
|
33
|
+
"aria-label": ariaLabel,
|
|
34
|
+
"aria-describedby": ariaDescribedBy,
|
|
35
|
+
className,
|
|
36
|
+
style: { minHeight },
|
|
37
|
+
onKeyDown: (event) => {
|
|
38
|
+
if (!composer.submit || !editable) return;
|
|
39
|
+
if (!isComposerSubmitKey(event.nativeEvent)) return;
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
composer.submit();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { ChatComposerPlainInput };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=ChatComposerPlainInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatComposerPlainInput.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposerPlainInput.tsx"],"sourcesContent":["import { useImperativeHandle, useRef } from 'react';\n\nimport { Textarea } from '../Textarea';\nimport {\n isComposerSubmitKey,\n useChatComposerContext,\n} from './ChatComposerContext';\nimport type { ChatComposerInputProps } from './ChatComposerInput';\n\ninterface ChatComposerPlainInputProps extends ChatComposerInputProps {\n minHeight: number;\n maxHeight: number;\n}\n\n/** Keeps the composer usable with plain Markdown text when the rich editor fails. */\nexport function ChatComposerPlainInput({\n ref,\n value,\n onChange,\n placeholder = 'Write a message…',\n disabled = false,\n readOnly = false,\n autoFocus = false,\n minHeight,\n maxHeight,\n className,\n 'aria-label': ariaLabel = 'Message',\n 'aria-describedby': ariaDescribedBy,\n}: ChatComposerPlainInputProps) {\n const composer = useChatComposerContext();\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const isDisabled = composer.disabled || disabled;\n const editable = !isDisabled && !readOnly;\n\n useImperativeHandle(\n ref,\n () => ({\n focus: () => {\n if (editable) textareaRef.current?.focus();\n },\n }),\n [editable]\n );\n\n useImperativeHandle(\n composer.inputFocusRef,\n () => () => {\n if (!editable || !textareaRef.current) return false;\n textareaRef.current.focus();\n return true;\n },\n [editable]\n );\n\n return (\n <Textarea\n ref={textareaRef}\n variant=\"plain\"\n size=\"md\"\n rows={1}\n autoResize\n maxHeight={maxHeight}\n value={value}\n onChange={onChange}\n placeholder={placeholder}\n disabled={isDisabled}\n readOnly={readOnly}\n autoFocus={autoFocus}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n className={className}\n style={{ minHeight }}\n onKeyDown={(event) => {\n if (!composer.submit || !editable) return;\n if (!isComposerSubmitKey(event.nativeEvent)) return;\n event.preventDefault();\n composer.submit();\n }}\n />\n );\n}\n"],"mappings":";;;;;;AAeA,SAAgB,uBAAuB,EACrC,KACA,OACA,UACA,cAAc,oBACd,WAAW,OACX,WAAW,OACX,YAAY,OACZ,WACA,WACA,WACA,cAAc,YAAY,WAC1B,oBAAoB,mBACU;CAC9B,MAAM,WAAW,uBAAuB;CACxC,MAAM,cAAc,OAA4B,IAAI;CACpD,MAAM,aAAa,SAAS,YAAY;CACxC,MAAM,WAAW,CAAC,cAAc,CAAC;CAEjC,oBACE,YACO,EACL,aAAa;EACX,IAAI,UAAU,YAAY,SAAS,MAAM;CAC3C,EACF,IACA,CAAC,QAAQ,CACX;CAEA,oBACE,SAAS,2BACG;EACV,IAAI,CAAC,YAAY,CAAC,YAAY,SAAS,OAAO;EAC9C,YAAY,QAAQ,MAAM;EAC1B,OAAO;CACT,GACA,CAAC,QAAQ,CACX;CAEA,OACE,oBAAC,UAAD;EACE,KAAK;EACL,SAAQ;EACR,MAAK;EACL,MAAM;EACN,YAAA;EACW;EACJ;EACG;EACG;EACb,UAAU;EACA;EACC;EACX,cAAY;EACZ,oBAAkB;EACP;EACX,OAAO,EAAE,UAAU;EACnB,YAAY,UAAU;GACpB,IAAI,CAAC,SAAS,UAAU,CAAC,UAAU;GACnC,IAAI,CAAC,oBAAoB,MAAM,WAAW,GAAG;GAC7C,MAAM,eAAe;GACrB,SAAS,OAAO;EAClB;CACD,CAAA;AAEL"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChatComposerInputProps } from './ChatComposerInput.js';
|
|
2
|
+
interface ChatComposerRichInputProps extends ChatComposerInputProps {
|
|
3
|
+
minHeight: number;
|
|
4
|
+
maxHeight: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function ChatComposerRichInput({ ref, value, onChange, placeholder, disabled, readOnly, autoFocus, minHeight, maxHeight, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }: ChatComposerRichInputProps): import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { ChatComposerInputEditableContext, useChatComposerContext } from "./ChatComposerContext.js";
|
|
3
|
+
import { useChatComposerEditor } from "./useChatComposerEditor.js";
|
|
4
|
+
import { useImperativeHandle } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { EditorContent } from "@tiptap/react";
|
|
7
|
+
var ChatComposerRichInput_module_default = { editor: "_editor_1jx45_3" };
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region packages/components/src/components/ChatComposer/ChatComposerRichInput.tsx
|
|
10
|
+
function ChatComposerRichInput({ ref, value, onChange, placeholder = "Write a message…", disabled = false, readOnly = false, autoFocus = false, minHeight, maxHeight, className, "aria-label": ariaLabel = "Message", "aria-describedby": ariaDescribedBy }) {
|
|
11
|
+
"use no memo";
|
|
12
|
+
const composer = useChatComposerContext();
|
|
13
|
+
const isDisabled = composer.disabled || disabled;
|
|
14
|
+
const editable = !isDisabled && !readOnly;
|
|
15
|
+
const { editor } = useChatComposerEditor({
|
|
16
|
+
value,
|
|
17
|
+
onChange,
|
|
18
|
+
onSubmit: composer.submit,
|
|
19
|
+
placeholder,
|
|
20
|
+
editable,
|
|
21
|
+
autofocus: autoFocus,
|
|
22
|
+
editorClassName: cn(ChatComposerRichInput_module_default.editor, "min-w-0 break-words px-space-1 text-sm leading-relaxed text-primary outline-hidden", isDisabled && "text-disabled"),
|
|
23
|
+
editorAttributes: {
|
|
24
|
+
role: "textbox",
|
|
25
|
+
style: `min-height: ${minHeight}px`,
|
|
26
|
+
"aria-label": ariaLabel,
|
|
27
|
+
"aria-multiline": "true",
|
|
28
|
+
"aria-disabled": String(isDisabled),
|
|
29
|
+
"aria-readonly": String(readOnly),
|
|
30
|
+
...ariaDescribedBy ? { "aria-describedby": ariaDescribedBy } : {}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
useImperativeHandle(ref, () => ({ focus: () => {
|
|
34
|
+
if (editable) editor?.commands.focus("end");
|
|
35
|
+
} }), [editor, editable]);
|
|
36
|
+
useImperativeHandle(composer.inputFocusRef, () => () => {
|
|
37
|
+
if (!editable || !editor) return false;
|
|
38
|
+
editor.commands.focus("end");
|
|
39
|
+
return true;
|
|
40
|
+
}, [editor, editable]);
|
|
41
|
+
return /* @__PURE__ */ jsx("div", {
|
|
42
|
+
className: cn("min-w-0 overflow-y-auto overscroll-contain", className),
|
|
43
|
+
style: { maxHeight },
|
|
44
|
+
children: /* @__PURE__ */ jsx(ChatComposerInputEditableContext.Provider, {
|
|
45
|
+
value: editable,
|
|
46
|
+
children: /* @__PURE__ */ jsx(EditorContent, { editor })
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ChatComposerRichInput };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=ChatComposerRichInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatComposerRichInput.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposerRichInput.module.css","../../../src/components/ChatComposer/ChatComposerRichInput.tsx"],"sourcesContent":["@reference \"../../styles/tailwind.css\";\n\n.editor :global(p.is-editor-empty:first-child)::before {\n @apply pointer-events-none float-left h-0 text-placeholder;\n content: attr(data-placeholder);\n}\n\n.editor p {\n @apply m-0;\n}\n\n.editor > * + * {\n @apply mt-space-2;\n}\n\n.editor h1,\n.editor h2,\n.editor h3,\n.editor h4,\n.editor h5,\n.editor h6 {\n @apply text-base font-semibold;\n}\n\n.editor ul {\n @apply list-outside list-disc pl-space-5;\n}\n\n.editor ol {\n @apply list-outside list-decimal pl-space-5;\n}\n\n.editor a {\n @apply text-link underline underline-offset-2;\n}\n\n.editor blockquote {\n @apply border-l-2 border-default pl-space-3 text-secondary;\n}\n\n.editor :not(pre) > code {\n @apply rounded-sm bg-surface-level-2 px-space-1 font-mono;\n}\n\n.editor pre code {\n @apply bg-transparent p-0;\n}\n\n.editor hr {\n @apply border-default;\n}\n","import { useImperativeHandle } from 'react';\n\nimport { EditorContent } from '@tiptap/react';\n\nimport { cn } from '../../utils/cn';\nimport {\n ChatComposerInputEditableContext,\n useChatComposerContext,\n} from './ChatComposerContext';\nimport type { ChatComposerInputProps } from './ChatComposerInput';\nimport { useChatComposerEditor } from './useChatComposerEditor';\n\nimport styles from './ChatComposerRichInput.module.css';\n\ninterface ChatComposerRichInputProps extends ChatComposerInputProps {\n minHeight: number;\n maxHeight: number;\n}\n\nexport function ChatComposerRichInput({\n ref,\n value,\n onChange,\n placeholder = 'Write a message…',\n disabled = false,\n readOnly = false,\n autoFocus = false,\n minHeight,\n maxHeight,\n className,\n 'aria-label': ariaLabel = 'Message',\n 'aria-describedby': ariaDescribedBy,\n}: ChatComposerRichInputProps) {\n 'use no memo';\n\n const composer = useChatComposerContext();\n const isDisabled = composer.disabled || disabled;\n const editable = !isDisabled && !readOnly;\n const { editor } = useChatComposerEditor({\n value,\n onChange,\n onSubmit: composer.submit,\n placeholder,\n editable,\n autofocus: autoFocus,\n editorClassName: cn(\n styles.editor,\n 'min-w-0 break-words px-space-1 text-sm leading-relaxed text-primary outline-hidden',\n // Read-only text is still the user's message, such as a prefilled draft\n // being typed in, so only disabled input looks unavailable.\n isDisabled && 'text-disabled'\n ),\n editorAttributes: {\n role: 'textbox',\n style: `min-height: ${minHeight}px`,\n 'aria-label': ariaLabel,\n 'aria-multiline': 'true',\n 'aria-disabled': String(isDisabled),\n 'aria-readonly': String(readOnly),\n ...(ariaDescribedBy ? { 'aria-describedby': ariaDescribedBy } : {}),\n },\n });\n\n useImperativeHandle(\n ref,\n () => ({\n focus: () => {\n if (editable) editor?.commands.focus('end');\n },\n }),\n [editor, editable]\n );\n\n useImperativeHandle(\n composer.inputFocusRef,\n () => () => {\n if (!editable || !editor) return false;\n editor.commands.focus('end');\n return true;\n },\n [editor, editable]\n );\n\n return (\n <div\n className={cn('min-w-0 overflow-y-auto overscroll-contain', className)}\n style={{ maxHeight }}\n >\n <ChatComposerInputEditableContext.Provider value={editable}>\n <EditorContent editor={editor} />\n </ChatComposerInputEditableContext.Provider>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;ACmBA,SAAgB,sBAAsB,EACpC,KACA,OACA,UACA,cAAc,oBACd,WAAW,OACX,WAAW,OACX,YAAY,OACZ,WACA,WACA,WACA,cAAc,YAAY,WAC1B,oBAAoB,mBACS;CAC7B;CAEA,MAAM,WAAW,uBAAuB;CACxC,MAAM,aAAa,SAAS,YAAY;CACxC,MAAM,WAAW,CAAC,cAAc,CAAC;CACjC,MAAM,EAAE,WAAW,sBAAsB;EACvC;EACA;EACA,UAAU,SAAS;EACnB;EACA;EACA,WAAW;EACX,iBAAiB,GACf,qCAAO,QACP,sFAGA,cAAc,eAChB;EACA,kBAAkB;GAChB,MAAM;GACN,OAAO,eAAe,UAAU;GAChC,cAAc;GACd,kBAAkB;GAClB,iBAAiB,OAAO,UAAU;GAClC,iBAAiB,OAAO,QAAQ;GAChC,GAAI,kBAAkB,EAAE,oBAAoB,gBAAgB,IAAI,CAAC;EACnE;CACF,CAAC;CAED,oBACE,YACO,EACL,aAAa;EACX,IAAI,UAAU,QAAQ,SAAS,MAAM,KAAK;CAC5C,EACF,IACA,CAAC,QAAQ,QAAQ,CACnB;CAEA,oBACE,SAAS,2BACG;EACV,IAAI,CAAC,YAAY,CAAC,QAAQ,OAAO;EACjC,OAAO,SAAS,MAAM,KAAK;EAC3B,OAAO;CACT,GACA,CAAC,QAAQ,QAAQ,CACnB;CAEA,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,8CAA8C,SAAS;EACrE,OAAO,EAAE,UAAU;EAEnB,UAAA,oBAAC,iCAAiC,UAAlC;GAA2C,OAAO;GAChD,UAAA,oBAAC,eAAD,EAAuB,OAAS,CAAA;EACS,CAAA;CACxC,CAAA;AAET"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ChatComposer, ChatComposerToolbar, ChatComposerAction, } from './ChatComposer.js';
|
|
2
|
+
export type { ChatComposerDrawerIntent, ChatComposerProps, ChatComposerToolbarProps, ChatComposerActionProps, } from './ChatComposer.js';
|
|
3
|
+
export { ChatComposerInput } from './ChatComposerInput.js';
|
|
4
|
+
export type { ChatComposerInputHandle, ChatComposerInputProps, } from './ChatComposerInput.js';
|
|
5
|
+
export { ChatComposerAttachmentMenu, ChatComposerAttachments, ChatComposerAttachment, } from './ChatComposerAttachments.js';
|
|
6
|
+
export type { ChatComposerAttachmentMenuProps, ChatComposerAttachmentsProps, ChatComposerAttachmentProps, } from './ChatComposerAttachments.js';
|
|
7
|
+
export { ChatComposerModelSelect } from './ChatComposerModelSelect.js';
|
|
8
|
+
export type { ChatComposerModelSelectProps } from './ChatComposerModelSelect.js';
|
|
9
|
+
export { ChatComposerContext } from './ChatComposerContext.js';
|
|
10
|
+
export type { ChatComposerContextValue } from './ChatComposerContext.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ChatComposerContext } from "./ChatComposerContext.js";
|
|
2
|
+
import { ChatComposer, ChatComposerAction, ChatComposerToolbar } from "./ChatComposer.js";
|
|
3
|
+
import { ChatComposerAttachment, ChatComposerAttachmentMenu, ChatComposerAttachments } from "./ChatComposerAttachments.js";
|
|
4
|
+
import { ChatComposerInput } from "./ChatComposerInput.js";
|
|
5
|
+
import { ChatComposerModelSelect } from "./ChatComposerModelSelect.js";
|
|
6
|
+
export { ChatComposer, ChatComposerAction, ChatComposerAttachment, ChatComposerAttachmentMenu, ChatComposerAttachments, ChatComposerContext, ChatComposerInput, ChatComposerModelSelect, ChatComposerToolbar };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type MarkdownStorage } from 'tiptap-markdown';
|
|
2
|
+
import { type Editor } from '@tiptap/core';
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
|
+
interface Storage {
|
|
5
|
+
markdown: MarkdownStorage;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface UseChatComposerEditorOptions {
|
|
9
|
+
value: string;
|
|
10
|
+
onChange: (md: string) => void;
|
|
11
|
+
onSubmit?: () => void;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
editable?: boolean;
|
|
14
|
+
autofocus?: boolean;
|
|
15
|
+
editorClassName?: string;
|
|
16
|
+
editorAttributes?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
export declare function useChatComposerEditor({ value, onChange, onSubmit, placeholder, editable, autofocus, editorClassName, editorAttributes, }: UseChatComposerEditorOptions): {
|
|
19
|
+
editor: Editor | null;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { isComposerSubmitKey } from "./ChatComposerContext.js";
|
|
2
|
+
import { COMPOSER_CODE_FENCE, ChatComposerCodeBlock } from "./ChatComposerCodeBlock.js";
|
|
3
|
+
import { useEffect, useReducer, useRef } from "react";
|
|
4
|
+
import { Extension } from "@tiptap/core";
|
|
5
|
+
import { useEditor } from "@tiptap/react";
|
|
6
|
+
import { Markdown } from "tiptap-markdown";
|
|
7
|
+
import Placeholder from "@tiptap/extension-placeholder";
|
|
8
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
9
|
+
//#region packages/components/src/components/ChatComposer/useChatComposerEditor.ts
|
|
10
|
+
var PlainTextTables = Extension.create({
|
|
11
|
+
name: "composerPlainTextTables",
|
|
12
|
+
addStorage() {
|
|
13
|
+
return { markdown: { parse: { setup(markdownit) {
|
|
14
|
+
markdownit.disable("table");
|
|
15
|
+
} } } };
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
function useChatComposerEditor({ value, onChange, onSubmit, placeholder = "", editable = true, autofocus = false, editorClassName, editorAttributes }) {
|
|
19
|
+
"use no memo";
|
|
20
|
+
const valueRef = useRef(value);
|
|
21
|
+
const pastingTableText = useRef(false);
|
|
22
|
+
const placeholderRef = useRef(placeholder);
|
|
23
|
+
const [editRevision, reconcileEdit] = useReducer((revision) => revision + 1, 0);
|
|
24
|
+
const editor = useEditor({
|
|
25
|
+
extensions: [
|
|
26
|
+
StarterKit.configure({
|
|
27
|
+
codeBlock: false,
|
|
28
|
+
link: {
|
|
29
|
+
openOnClick: false,
|
|
30
|
+
autolink: false,
|
|
31
|
+
linkOnPaste: false
|
|
32
|
+
},
|
|
33
|
+
underline: false
|
|
34
|
+
}),
|
|
35
|
+
PlainTextTables,
|
|
36
|
+
Markdown.configure({
|
|
37
|
+
html: false,
|
|
38
|
+
breaks: true,
|
|
39
|
+
transformPastedText: true
|
|
40
|
+
}),
|
|
41
|
+
Placeholder.configure({ placeholder: () => placeholderRef.current }),
|
|
42
|
+
ChatComposerCodeBlock
|
|
43
|
+
],
|
|
44
|
+
content: value,
|
|
45
|
+
editorProps: {
|
|
46
|
+
attributes: {
|
|
47
|
+
class: editorClassName ?? "",
|
|
48
|
+
...editorAttributes
|
|
49
|
+
},
|
|
50
|
+
handlePaste: (view, event) => {
|
|
51
|
+
if (pastingTableText.current) return false;
|
|
52
|
+
const html = event.clipboardData?.getData("text/html") ?? "";
|
|
53
|
+
const text = event.clipboardData?.getData("text/plain");
|
|
54
|
+
if (!text || !/<table[\s>]/i.test(html)) return false;
|
|
55
|
+
pastingTableText.current = true;
|
|
56
|
+
try {
|
|
57
|
+
view.pasteText(text, event);
|
|
58
|
+
} finally {
|
|
59
|
+
pastingTableText.current = false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
handleKeyDown: (view, event) => {
|
|
64
|
+
if (!onSubmit || !editable || view.composing || event.key !== "Enter") return false;
|
|
65
|
+
const { $from, empty } = view.state.selection;
|
|
66
|
+
let multiline = empty && $from.parent.type.name === "paragraph" && $from.parentOffset === $from.parent.content.size && COMPOSER_CODE_FENCE.test($from.parent.textContent);
|
|
67
|
+
for (let depth = $from.depth; depth > 0; depth--) if ([
|
|
68
|
+
"codeBlock",
|
|
69
|
+
"listItem",
|
|
70
|
+
"blockquote"
|
|
71
|
+
].includes($from.node(depth).type.name)) {
|
|
72
|
+
multiline = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (!isComposerSubmitKey(event, multiline)) return false;
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
onSubmit();
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
editable,
|
|
82
|
+
autofocus,
|
|
83
|
+
onUpdate: ({ editor }) => {
|
|
84
|
+
const nextValue = editor.storage.markdown.getMarkdown();
|
|
85
|
+
valueRef.current = nextValue;
|
|
86
|
+
onChange(nextValue);
|
|
87
|
+
reconcileEdit();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (!editor || valueRef.current === value) return;
|
|
92
|
+
editor.commands.setContent(value, { emitUpdate: false });
|
|
93
|
+
valueRef.current = value;
|
|
94
|
+
}, [
|
|
95
|
+
value,
|
|
96
|
+
editor,
|
|
97
|
+
editRevision
|
|
98
|
+
]);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (!editor || placeholderRef.current === placeholder) return;
|
|
101
|
+
placeholderRef.current = placeholder;
|
|
102
|
+
editor.view.dispatch(editor.state.tr);
|
|
103
|
+
}, [placeholder, editor]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!editor || editor.isEditable === editable) return;
|
|
106
|
+
editor.setEditable(editable, false);
|
|
107
|
+
}, [editable, editor]);
|
|
108
|
+
return { editor };
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { useChatComposerEditor };
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=useChatComposerEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChatComposerEditor.js","names":[],"sources":["../../../src/components/ChatComposer/useChatComposerEditor.ts"],"sourcesContent":["import { useEffect, useReducer, useRef } from 'react';\n\nimport { Markdown, type MarkdownStorage } from 'tiptap-markdown';\n\nimport { Extension, type Editor } from '@tiptap/core';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport { useEditor } from '@tiptap/react';\nimport StarterKit from '@tiptap/starter-kit';\n\nimport {\n ChatComposerCodeBlock,\n COMPOSER_CODE_FENCE,\n} from './ChatComposerCodeBlock';\nimport { isComposerSubmitKey } from './ChatComposerContext';\n\ndeclare module '@tiptap/core' {\n interface Storage {\n markdown: MarkdownStorage;\n }\n}\n\n// tiptap-markdown writes any table that is not a simple grid as the literal\n// \"[table]\", so the editor has no table nodes. Pipe rows stay plain text so\n// drafts, host values, and pasted tables keep their content.\nconst PlainTextTables = Extension.create({\n name: 'composerPlainTextTables',\n addStorage() {\n return {\n markdown: {\n parse: {\n setup(markdownit: { disable: (rule: string) => unknown }) {\n markdownit.disable('table');\n },\n },\n },\n };\n },\n});\n\ninterface UseChatComposerEditorOptions {\n value: string;\n onChange: (md: string) => void;\n onSubmit?: () => void;\n placeholder?: string;\n editable?: boolean;\n autofocus?: boolean;\n editorClassName?: string;\n editorAttributes?: Record<string, string>;\n}\n\nexport function useChatComposerEditor({\n value,\n onChange,\n onSubmit,\n placeholder = '',\n editable = true,\n autofocus = false,\n editorClassName,\n editorAttributes,\n}: UseChatComposerEditorOptions): { editor: Editor | null } {\n 'use no memo';\n\n const valueRef = useRef(value);\n const pastingTableText = useRef(false);\n const placeholderRef = useRef(placeholder);\n const [editRevision, reconcileEdit] = useReducer(\n (revision: number) => revision + 1,\n 0\n );\n const editor = useEditor({\n extensions: [\n StarterKit.configure({\n codeBlock: false,\n // Links keep their URL in the draft but never navigate from the editor.\n link: { openOnClick: false, autolink: false, linkOnPaste: false },\n // Markdown has no underline, and pasted links carry it as an inline\n // style that would continue into the text typed after them.\n underline: false,\n }),\n PlainTextTables,\n Markdown.configure({\n html: false,\n // A single newline in a host value would otherwise collapse to a\n // space the first time the draft is edited.\n breaks: true,\n transformPastedText: true,\n }),\n Placeholder.configure({ placeholder: () => placeholderRef.current }),\n ChatComposerCodeBlock,\n ],\n content: value,\n editorProps: {\n attributes: { class: editorClassName ?? '', ...editorAttributes },\n handlePaste: (view, event) => {\n if (pastingTableText.current) return false;\n const html = event.clipboardData?.getData('text/html') ?? '';\n const text = event.clipboardData?.getData('text/plain');\n // Without table nodes, pasted HTML cells run together. Spreadsheets and\n // browsers also copy the table as text with tabs and line breaks.\n if (!text || !/<table[\\s>]/i.test(html)) return false;\n // pasteText reruns this handler with the same event.\n pastingTableText.current = true;\n try {\n view.pasteText(text, event);\n } finally {\n pastingTableText.current = false;\n }\n return true;\n },\n handleKeyDown: (view, event) => {\n if (!onSubmit || !editable || view.composing || event.key !== 'Enter') {\n return false;\n }\n const { $from, empty } = view.state.selection;\n let multiline =\n empty &&\n $from.parent.type.name === 'paragraph' &&\n $from.parentOffset === $from.parent.content.size &&\n COMPOSER_CODE_FENCE.test($from.parent.textContent);\n for (let depth = $from.depth; depth > 0; depth--) {\n if (\n ['codeBlock', 'listItem', 'blockquote'].includes(\n $from.node(depth).type.name\n )\n ) {\n multiline = true;\n break;\n }\n }\n if (!isComposerSubmitKey(event, multiline)) return false;\n event.preventDefault();\n onSubmit();\n return true;\n },\n },\n editable,\n autofocus,\n onUpdate: ({ editor }) => {\n const nextValue = editor.storage.markdown.getMarkdown();\n valueRef.current = nextValue;\n onChange(nextValue);\n // Reconcile even when the parent rejects the edit and keeps the same value.\n reconcileEdit();\n },\n });\n\n useEffect(() => {\n if (!editor || valueRef.current === value) return;\n editor.commands.setContent(value, { emitUpdate: false });\n valueRef.current = value;\n }, [value, editor, editRevision]);\n\n useEffect(() => {\n if (!editor || placeholderRef.current === placeholder) return;\n placeholderRef.current = placeholder;\n // Placeholder decorations only recompute on a transaction.\n editor.view.dispatch(editor.state.tr);\n }, [placeholder, editor]);\n\n useEffect(() => {\n if (!editor || editor.isEditable === editable) return;\n editor.setEditable(editable, false);\n }, [editable, editor]);\n\n return { editor };\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAM,kBAAkB,UAAU,OAAO;CACvC,MAAM;CACN,aAAa;EACX,OAAO,EACL,UAAU,EACR,OAAO,EACL,MAAM,YAAoD;GACxD,WAAW,QAAQ,OAAO;EAC5B,EACF,EACF,EACF;CACF;AACF,CAAC;AAaD,SAAgB,sBAAsB,EACpC,OACA,UACA,UACA,cAAc,IACd,WAAW,MACX,YAAY,OACZ,iBACA,oBAC0D;CAC1D;CAEA,MAAM,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AK,IACzB,GACA;KACA,YAAY;KACZ;IACF;IAEF,IAAI,CAAC,oBAAoB,OAAO,SAAS,GAAG,OAAO;IACnD,MAAM,eAAe;IACrB,SAAS;IACT,OAAO;GACT;EACF;EACA;EACA;EACA,WAAW,EAAE,aAAa;GACxB,MAAM,YAAY,OAAO,QAAQ,SAAS,YAAY;GACtD,SAAS,UAAU;GACnB,SAAS,SAAS;GAElB,cAAc;EAChB;CACF,CAAC;CAED,gBAAgB;EACd,IAAI,CAAC,UAAU,SAAS,YAAY,OAAO;EAC3C,OAAO,SAAS,WAAW,OAAO,EAAE,YAAY,MAAM,CAAC;EACvD,SAAS,UAAU;CACrB,GAAG;EAAC;EAAO;EAAQ;CAAY,CAAC;CAEhC,gBAAgB;EACd,IAAI,CAAC,UAAU,eAAe,YAAY,aAAa;EACvD,eAAe,UAAU;EAEzB,OAAO,KAAK,SAAS,OAAO,MAAM,EAAE;CACtC,GAAG,CAAC,aAAa,MAAM,CAAC;CAExB,gBAAgB;EACd,IAAI,CAAC,UAAU,OAAO,eAAe,UAAU;EAC/C,OAAO,YAAY,UAAU,KAAK;CACpC,GAAG,CAAC,UAAU,MAAM,CAAC;CAErB,OAAO,EAAE,OAAO;AAClB"}
|
|
@@ -8,9 +8,9 @@ import { ThinkingState } from "../ThinkingState/ThinkingState.js";
|
|
|
8
8
|
import { Fragment, useState } from "react";
|
|
9
9
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
import { WarningCircleIcon } from "@phosphor-icons/react/dist/ssr/WarningCircle";
|
|
11
|
+
import { CopySimpleIcon } from "@phosphor-icons/react/dist/ssr/CopySimple";
|
|
11
12
|
import { PencilSimpleIcon } from "@phosphor-icons/react/dist/ssr/PencilSimple";
|
|
12
13
|
import { ArrowClockwiseIcon } from "@phosphor-icons/react/dist/ssr/ArrowClockwise";
|
|
13
|
-
import { CopySimpleIcon } from "@phosphor-icons/react/dist/ssr/CopySimple";
|
|
14
14
|
//#region packages/components/src/components/ChatMessage/ChatMessage.tsx
|
|
15
15
|
var roleLabels = {
|
|
16
16
|
user: "User",
|
|
@@ -4,8 +4,8 @@ import { Text } from "../Text/Text.js";
|
|
|
4
4
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
5
|
import { useCodeMirror } from "../../utils/useCodeMirror.js";
|
|
6
6
|
import { CopyIconButton } from "../CopyButton/CopyButton.js";
|
|
7
|
-
import { convertFile, getVisibleLines, parseFile } from "./CodeLite.utils.js";
|
|
8
7
|
import { CodeToolbar } from "./CodeToolbar.js";
|
|
8
|
+
import { convertFile, getVisibleLines, parseFile } from "./CodeLite.utils.js";
|
|
9
9
|
import { Suspense, lazy, memo, useEffect, useRef, useState } from "react";
|
|
10
10
|
import { DotsThreeIcon } from "@phosphor-icons/react/dist/ssr/DotsThree";
|
|
11
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -3,19 +3,18 @@ import zIndices from "../../utils/zIndices.js";
|
|
|
3
3
|
import { useZIndex } from "../../utils/useZIndex.js";
|
|
4
4
|
import { Button } from "../Button/Button.js";
|
|
5
5
|
import { Banner } from "../Banner/Banner.js";
|
|
6
|
-
import "../Banner/index.js";
|
|
7
6
|
import { useColorScheme } from "../../hooks/useColorScheme.js";
|
|
8
|
-
import {
|
|
9
|
-
import { CODE_LANGUAGES, resolveCodeLanguage } from "./codeLanguages.js";
|
|
10
|
-
import { CodeLanguageSelect } from "./CodeLanguageSelect.js";
|
|
7
|
+
import { getNonce } from "../../utils/csp-nonce.js";
|
|
11
8
|
import { useCodeMirror } from "../../utils/useCodeMirror.js";
|
|
12
9
|
import { CopyButton } from "../CopyButton/CopyButton.js";
|
|
13
|
-
import { CodeToolbar } from "./CodeToolbar.js";
|
|
14
|
-
import "./constants.js";
|
|
15
|
-
import { getImageReplacerExtensions } from "./ImageReplacerExtension.js";
|
|
16
|
-
import { getNonce } from "../../utils/csp-nonce.js";
|
|
17
10
|
import { ErrorBoundary } from "../ErrorBoundary.js";
|
|
11
|
+
import "./constants.js";
|
|
18
12
|
import { PlainTextEditor } from "../PlainTextEditor/index.js";
|
|
13
|
+
import { getLanguageExtension, getSyntaxTheme, useEditorTheme } from "./Code.utils.js";
|
|
14
|
+
import { getImageReplacerExtensions } from "./ImageReplacerExtension.js";
|
|
15
|
+
import { CODE_LANGUAGES, resolveCodeLanguage } from "./codeLanguages.js";
|
|
16
|
+
import { CodeLanguageSelect } from "./CodeLanguageSelect.js";
|
|
17
|
+
import { CodeToolbar } from "./CodeToolbar.js";
|
|
19
18
|
import { useMemo, useState } from "react";
|
|
20
19
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
21
20
|
//#region packages/components/src/components/Code/index.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/Code/index.tsx"],"sourcesContent":["import { type ReactNode, useMemo, useState } from 'react';\n\nimport type { Extension } from '@codemirror/state';\nimport type { EditorView, ViewUpdate } from '@codemirror/view';\n\nimport { useColorScheme } from '../../hooks/useColorScheme';\nimport { cn } from '../../utils/cn';\nimport { getNonce } from '../../utils/csp-nonce';\nimport { useCodeMirror } from '../../utils/useCodeMirror';\nimport { useZIndex } from '../../utils/useZIndex';\nimport zIndices from '../../utils/zIndices';\nimport { Banner } from '../Banner';\nimport { Button } from '../Button';\nimport { CopyButton } from '../CopyButton';\nimport { ErrorBoundary } from '../ErrorBoundary';\nimport { PlainTextEditor } from '../PlainTextEditor';\nimport {\n getLanguageExtension,\n getSyntaxTheme,\n useEditorTheme,\n} from './Code.utils';\nimport { MAX_CODE_LENGTH } from './constants';\nimport { getImageReplacerExtensions } from './ImageReplacerExtension';\nimport type { CodeLanguageType } from './types';\n\nexport { CodeLanguageSelect } from './CodeLanguageSelect';\nexport type { CodeLanguageSelectProps } from './CodeLanguageSelect';\nexport { CodeToolbar } from './CodeToolbar';\nexport type { CodeToolbarProps } from './CodeToolbar';\nexport { CODE_LANGUAGES, resolveCodeLanguage } from './codeLanguages';\nexport type { CodeLanguageType } from './types';\n\n/** Props for the syntax-highlighted CodeMirror block. */\nexport interface CodeProps {\n language: CodeLanguageType;\n extensions?: Extension[];\n value: string | undefined;\n onChange?: (code: string) => void;\n readOnly?: boolean;\n autoFocus?: boolean;\n height?: string;\n maxHeight?: string;\n omitMaxHeight?: boolean;\n width?: string;\n fontSize?: string;\n placeholder?: string;\n ariaLabel?: string;\n toolbar?: ReactNode;\n /** Floating copy control when no toolbar is supplied. */\n showCopyButton?: boolean;\n showFoldGutter?: boolean;\n testId?: string;\n variant?: 'plain' | 'full';\n onCreateEditor?: (view: EditorView) => void;\n /** Receives document and selection updates, including programmatic changes. */\n onUpdate?: (update: ViewUpdate) => void;\n converterExtensions?: Extension[];\n}\n\n/**\n * Renders syntax-highlighted code with optional editing and copy support.\n *\n * Import directly from `@langchain/macaw-components/Code` so the CodeMirror\n * dependency is only loaded by surfaces that use it.\n */\nexport const Code = ({\n value,\n readOnly,\n onChange,\n autoFocus,\n placeholder,\n ariaLabel,\n language,\n extensions,\n converterExtensions,\n height,\n maxHeight,\n omitMaxHeight,\n width,\n fontSize,\n onCreateEditor,\n onUpdate,\n variant = 'full',\n testId,\n toolbar,\n showCopyButton,\n showFoldGutter = true,\n}: CodeProps) => {\n const cm = useCodeMirror();\n const { isDarkMode } = useColorScheme();\n const copyButtonZIndex = useZIndex(zIndices.floatingBar);\n\n const [ignoreWarning, setIgnoreWarning] = useState(false);\n\n const lineCount = value?.split('\\n').length ?? 0;\n\n // Stable CM-derived values — memoized so StateField/ViewPlugin instances are\n // created once and not recreated on every render (which resets editor state).\n const imageReplacerExtensions = useMemo(\n () => (cm ? getImageReplacerExtensions(cm) : null),\n [cm]\n );\n const editorTheme = useEditorTheme(cm, { variant, showFoldGutter });\n const langExt = useMemo(\n () => (cm ? getLanguageExtension(cm, language) : null),\n [cm, language]\n );\n const syntaxTheme = useMemo(\n () => (cm ? getSyntaxTheme(cm, isDarkMode) : null),\n [cm, isDarkMode]\n );\n\n const nonce = getNonce();\n\n const mExtensions = useMemo(() => {\n if (!cm || !imageReplacerExtensions || !langExt || !editorTheme) return [];\n const { keymap, defaultKeymap, EditorView } = cm;\n const { decorationStateField, imageReplacerPlugin } =\n imageReplacerExtensions;\n return [\n keymap.of([{ key: 'Mod-Enter', run: () => true }, ...defaultKeymap]),\n langExt.language,\n ...(extensions ?? []),\n // YAML folding blocks rendering for large files, so cap it at 500 lines.\n ...(lineCount <= 500\n ? (converterExtensions ?? langExt.extensions ?? [])\n : []),\n imageReplacerPlugin,\n decorationStateField,\n EditorView.lineWrapping,\n editorTheme,\n // Untagged text otherwise uses the syntax theme's dim default.\n ...(language === 'plaintext'\n ? [\n EditorView.theme({\n '.cm-content': { color: 'var(--text-primary)' },\n }),\n ]\n : []),\n ...(ariaLabel\n ? [EditorView.contentAttributes.of({ 'aria-label': ariaLabel })]\n : []),\n ...(readOnly ? [EditorView.editable.of(false)] : []),\n ...(nonce ? [EditorView.cspNonce.of(nonce)] : []),\n ];\n // extensions/converterExtensions are caller-provided arrays. Include them\n // directly so changes propagate.\n }, [\n cm,\n imageReplacerExtensions,\n langExt,\n editorTheme,\n language,\n ariaLabel,\n extensions,\n converterExtensions,\n lineCount,\n readOnly,\n nonce,\n ]);\n\n if (value == null) return null;\n\n // Avoid mounting CodeMirror by default when style recomputation could block rendering.\n const showWarning = lineCount > MAX_CODE_LENGTH && !ignoreWarning;\n const hasToolbar = Boolean(toolbar);\n const CodeMirror = cm?.CodeMirror;\n const editorHeight = hasToolbar && height ? '100%' : height;\n const editor = showWarning ? (\n <Banner\n intent=\"warning\"\n action={\n <Button\n variant=\"underlined\"\n color=\"secondary\"\n size=\"sm\"\n onClick={() => setIgnoreWarning(true)}\n >\n Open anyway\n </Button>\n }\n >\n This content might be too long to display in the editor.\n </Banner>\n ) : !CodeMirror || !syntaxTheme ? (\n <PlainTextEditor\n value={value}\n readOnly={true}\n placeholder={placeholder}\n className={cn(\n 'font-mono text-xs',\n height && 'h-full overflow-auto',\n maxHeight && !omitMaxHeight && `max-h-[${maxHeight}]`\n )}\n />\n ) : (\n <ErrorBoundary fallback={() => <div>Error showing code</div>}>\n <CodeMirror\n value={value}\n readOnly={readOnly}\n autoFocus={autoFocus}\n placeholder={placeholder}\n height={editorHeight}\n maxHeight={omitMaxHeight ? undefined : (maxHeight ?? '50vh')}\n width={hasToolbar ? '100%' : width}\n style={{\n fontSize,\n backgroundColor: 'var(--bg-surface-level-2)',\n borderRadius: hasToolbar ? 0 : 'var(--radius-lg)',\n cursor: readOnly ? 'default' : 'text',\n ...(editorHeight ? { height: editorHeight } : {}),\n ...(width ? { width: hasToolbar ? '100%' : width } : {}),\n }}\n extensions={mExtensions}\n onCreateEditor={onCreateEditor}\n onUpdate={onUpdate}\n onChange={(code) => {\n if (!readOnly) {\n onChange?.(code);\n }\n }}\n theme={syntaxTheme}\n basicSetup={{\n foldGutter: showFoldGutter,\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n defaultKeymap: false,\n ...(variant === 'plain' && {\n lineNumbers: false,\n highlightSelectionMatches: false,\n }),\n }}\n />\n </ErrorBoundary>\n );\n\n return (\n <div\n data-testid={testId}\n className={cn(\n 'group relative text-xs',\n height && !hasToolbar && 'h-full',\n hasToolbar &&\n 'flex flex-col overflow-hidden rounded-lg border border-subtle bg-surface-level-2'\n )}\n style={hasToolbar ? { width, height } : undefined}\n >\n {hasToolbar ? (\n <>\n <div className=\"shrink-0\">{toolbar}</div>\n <div className={cn(height && 'min-h-0 flex-1 overflow-auto')}>\n {editor}\n </div>\n </>\n ) : (\n editor\n )}\n {!hasToolbar &&\n !showWarning &&\n CodeMirror &&\n syntaxTheme &&\n showCopyButton &&\n value && (\n <div\n onMouseDown={(e) => e.preventDefault()}\n className=\"absolute right-1 top-1 opacity-0 transition-opacity duration-300 group-hover:opacity-100\"\n style={{ zIndex: copyButtonZIndex }}\n >\n <CopyButton copy={value} variant=\"icon\" />\n </div>\n )}\n </div>\n );\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YAAY;IACV,YAAY;IACZ,qBAAqB;IACrB,2BAA2B;IAC3B,eAAe;IACf,GAAI,YAAY,WAAW;KACzB,aAAa;KACb,2BAA2B;IAC7B;GACF;EACD,CAAA;CACY,CAAA;CAGjB,OACE,qBAAC,OAAD;EACE,eAAa;EACb,WAAW,GACT,0BACA,UAAU,CAAC,cAAc,UACzB,cACE,kFACJ;EACA,OAAO,aAAa;GAAE;GAAO;EAAO,IAAI,KAAA;EAR1C,UAAA,CAUG,aACC,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,OAAD;GAAK,WAAU;GAAY,UAAA;EAAa,CAAA,GACxC,oBAAC,OAAD;GAAK,WAAW,GAAG,UAAU,8BAA8B;GACxD,UAAA;EACE,CAAA,CACL,EAAA,CAAA,IAEF,QAED,CAAC,cACA,CAAC,eACD,cACA,eACA,kBACA,SACE,oBAAC,OAAD;GACE,cAAc,MAAM,EAAE,eAAe;GACrC,WAAU;GACV,OAAO,EAAE,QAAQ,iBAAiB;GAElC,UAAA,oBAAC,YAAD;IAAY,MAAM;IAAO,SAAQ;GAAQ,CAAA;EACtC,CAAA,CAEN;;AAET"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/Code/index.tsx"],"sourcesContent":["import { type ReactNode, useMemo, useState } from 'react';\n\nimport type { Extension } from '@codemirror/state';\nimport type { EditorView, ViewUpdate } from '@codemirror/view';\n\nimport { useColorScheme } from '../../hooks/useColorScheme';\nimport { cn } from '../../utils/cn';\nimport { getNonce } from '../../utils/csp-nonce';\nimport { useCodeMirror } from '../../utils/useCodeMirror';\nimport { useZIndex } from '../../utils/useZIndex';\nimport zIndices from '../../utils/zIndices';\nimport { Banner } from '../Banner';\nimport { Button } from '../Button';\nimport { CopyButton } from '../CopyButton';\nimport { ErrorBoundary } from '../ErrorBoundary';\nimport { PlainTextEditor } from '../PlainTextEditor';\nimport {\n getLanguageExtension,\n getSyntaxTheme,\n useEditorTheme,\n} from './Code.utils';\nimport { MAX_CODE_LENGTH } from './constants';\nimport { getImageReplacerExtensions } from './ImageReplacerExtension';\nimport type { CodeLanguageType } from './types';\n\nexport { CodeLanguageSelect } from './CodeLanguageSelect';\nexport type { CodeLanguageSelectProps } from './CodeLanguageSelect';\nexport { CodeToolbar } from './CodeToolbar';\nexport type { CodeToolbarProps } from './CodeToolbar';\nexport { CODE_LANGUAGES, resolveCodeLanguage } from './codeLanguages';\nexport type { CodeLanguageType } from './types';\n\n/** Props for the syntax-highlighted CodeMirror block. */\nexport interface CodeProps {\n language: CodeLanguageType;\n extensions?: Extension[];\n value: string | undefined;\n onChange?: (code: string) => void;\n readOnly?: boolean;\n autoFocus?: boolean;\n height?: string;\n maxHeight?: string;\n omitMaxHeight?: boolean;\n width?: string;\n fontSize?: string;\n placeholder?: string;\n ariaLabel?: string;\n toolbar?: ReactNode;\n /** Floating copy control when no toolbar is supplied. */\n showCopyButton?: boolean;\n showFoldGutter?: boolean;\n testId?: string;\n variant?: 'plain' | 'full';\n onCreateEditor?: (view: EditorView) => void;\n /** Receives document and selection updates, including programmatic changes. */\n onUpdate?: (update: ViewUpdate) => void;\n converterExtensions?: Extension[];\n}\n\n/**\n * Renders syntax-highlighted code with optional editing and copy support.\n *\n * Import directly from `@langchain/macaw-components/Code` so the CodeMirror\n * dependency is only loaded by surfaces that use it.\n */\nexport const Code = ({\n value,\n readOnly,\n onChange,\n autoFocus,\n placeholder,\n ariaLabel,\n language,\n extensions,\n converterExtensions,\n height,\n maxHeight,\n omitMaxHeight,\n width,\n fontSize,\n onCreateEditor,\n onUpdate,\n variant = 'full',\n testId,\n toolbar,\n showCopyButton,\n showFoldGutter = true,\n}: CodeProps) => {\n const cm = useCodeMirror();\n const { isDarkMode } = useColorScheme();\n const copyButtonZIndex = useZIndex(zIndices.floatingBar);\n\n const [ignoreWarning, setIgnoreWarning] = useState(false);\n\n const lineCount = value?.split('\\n').length ?? 0;\n\n // Stable CM-derived values — memoized so StateField/ViewPlugin instances are\n // created once and not recreated on every render (which resets editor state).\n const imageReplacerExtensions = useMemo(\n () => (cm ? getImageReplacerExtensions(cm) : null),\n [cm]\n );\n const editorTheme = useEditorTheme(cm, { variant, showFoldGutter });\n const langExt = useMemo(\n () => (cm ? getLanguageExtension(cm, language) : null),\n [cm, language]\n );\n const syntaxTheme = useMemo(\n () => (cm ? getSyntaxTheme(cm, isDarkMode) : null),\n [cm, isDarkMode]\n );\n\n const nonce = getNonce();\n\n const mExtensions = useMemo(() => {\n if (!cm || !imageReplacerExtensions || !langExt || !editorTheme) return [];\n const { keymap, defaultKeymap, EditorView } = cm;\n const { decorationStateField, imageReplacerPlugin } =\n imageReplacerExtensions;\n return [\n keymap.of([{ key: 'Mod-Enter', run: () => true }, ...defaultKeymap]),\n langExt.language,\n ...(extensions ?? []),\n // YAML folding blocks rendering for large files, so cap it at 500 lines.\n ...(lineCount <= 500\n ? (converterExtensions ?? langExt.extensions ?? [])\n : []),\n imageReplacerPlugin,\n decorationStateField,\n EditorView.lineWrapping,\n editorTheme,\n // Untagged text otherwise uses the syntax theme's dim default.\n ...(language === 'plaintext'\n ? [\n EditorView.theme({\n '.cm-content': { color: 'var(--text-primary)' },\n }),\n ]\n : []),\n ...(ariaLabel\n ? [EditorView.contentAttributes.of({ 'aria-label': ariaLabel })]\n : []),\n ...(readOnly ? [EditorView.editable.of(false)] : []),\n ...(nonce ? [EditorView.cspNonce.of(nonce)] : []),\n ];\n // extensions/converterExtensions are caller-provided arrays. Include them\n // directly so changes propagate.\n }, [\n cm,\n imageReplacerExtensions,\n langExt,\n editorTheme,\n language,\n ariaLabel,\n extensions,\n converterExtensions,\n lineCount,\n readOnly,\n nonce,\n ]);\n\n if (value == null) return null;\n\n // Avoid mounting CodeMirror by default when style recomputation could block rendering.\n const showWarning = lineCount > MAX_CODE_LENGTH && !ignoreWarning;\n const hasToolbar = Boolean(toolbar);\n const CodeMirror = cm?.CodeMirror;\n const editorHeight = hasToolbar && height ? '100%' : height;\n const editor = showWarning ? (\n <Banner\n intent=\"warning\"\n action={\n <Button\n variant=\"underlined\"\n color=\"secondary\"\n size=\"sm\"\n onClick={() => setIgnoreWarning(true)}\n >\n Open anyway\n </Button>\n }\n >\n This content might be too long to display in the editor.\n </Banner>\n ) : !CodeMirror || !syntaxTheme ? (\n <PlainTextEditor\n value={value}\n readOnly={true}\n placeholder={placeholder}\n className={cn(\n 'font-mono text-xs',\n height && 'h-full overflow-auto',\n maxHeight && !omitMaxHeight && `max-h-[${maxHeight}]`\n )}\n />\n ) : (\n <ErrorBoundary fallback={() => <div>Error showing code</div>}>\n <CodeMirror\n value={value}\n readOnly={readOnly}\n autoFocus={autoFocus}\n placeholder={placeholder}\n height={editorHeight}\n maxHeight={omitMaxHeight ? undefined : (maxHeight ?? '50vh')}\n width={hasToolbar ? '100%' : width}\n style={{\n fontSize,\n backgroundColor: 'var(--bg-surface-level-2)',\n borderRadius: hasToolbar ? 0 : 'var(--radius-lg)',\n cursor: readOnly ? 'default' : 'text',\n ...(editorHeight ? { height: editorHeight } : {}),\n ...(width ? { width: hasToolbar ? '100%' : width } : {}),\n }}\n extensions={mExtensions}\n onCreateEditor={onCreateEditor}\n onUpdate={onUpdate}\n onChange={(code) => {\n if (!readOnly) {\n onChange?.(code);\n }\n }}\n theme={syntaxTheme}\n basicSetup={{\n foldGutter: showFoldGutter,\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n defaultKeymap: false,\n ...(variant === 'plain' && {\n lineNumbers: false,\n highlightSelectionMatches: false,\n }),\n }}\n />\n </ErrorBoundary>\n );\n\n return (\n <div\n data-testid={testId}\n className={cn(\n 'group relative text-xs',\n height && !hasToolbar && 'h-full',\n hasToolbar &&\n 'flex flex-col overflow-hidden rounded-lg border border-subtle bg-surface-level-2'\n )}\n style={hasToolbar ? { width, height } : undefined}\n >\n {hasToolbar ? (\n <>\n <div className=\"shrink-0\">{toolbar}</div>\n <div className={cn(height && 'min-h-0 flex-1 overflow-auto')}>\n {editor}\n </div>\n </>\n ) : (\n editor\n )}\n {!hasToolbar &&\n !showWarning &&\n CodeMirror &&\n syntaxTheme &&\n showCopyButton &&\n value && (\n <div\n onMouseDown={(e) => e.preventDefault()}\n className=\"absolute right-1 top-1 opacity-0 transition-opacity duration-300 group-hover:opacity-100\"\n style={{ zIndex: copyButtonZIndex }}\n >\n <CopyButton copy={value} variant=\"icon\" />\n </div>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,QAAQ,EACnB,OACA,UACA,UACA,WACA,aACA,WACA,UACA,YACA,qBACA,QACA,WACA,eACA,OACA,UACA,gBACA,UACA,UAAU,QACV,QACA,SACA,gBACA,iBAAiB,WACF;CACf,MAAM,KAAK,cAAc;CACzB,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,mBAAmB,UAAU,SAAS,WAAW;CAEvD,MAAM,CAAC,eAAe,oBAAoB,SAAS,KAAK;CAExD,MAAM,YAAY,OAAO,MAAM,IAAI,CAAC,CAAC,UAAU;CAI/C,MAAM,0BAA0B,cACvB,KAAK,2BAA2B,EAAE,IAAI,MAC7C,CAAC,EAAE,CACL;CACA,MAAM,cAAc,eAAe,IAAI;EAAE;EAAS;CAAe,CAAC;CAClE,MAAM,UAAU,cACP,KAAK,qBAAqB,IAAI,QAAQ,IAAI,MACjD,CAAC,IAAI,QAAQ,CACf;CACA,MAAM,cAAc,cACX,KAAK,eAAe,IAAI,UAAU,IAAI,MAC7C,CAAC,IAAI,UAAU,CACjB;CAEA,MAAM,QAAQ,SAAS;CAEvB,MAAM,cAAc,cAAc;EAChC,IAAI,CAAC,MAAM,CAAC,2BAA2B,CAAC,WAAW,CAAC,aAAa,OAAO,CAAC;EACzE,MAAM,EAAE,QAAQ,eAAe,eAAe;EAC9C,MAAM,EAAE,sBAAsB,wBAC5B;EACF,OAAO;GACL,OAAO,GAAG,CAAC;IAAE,KAAK;IAAa,WAAW;GAAK,GAAG,GAAG,aAAa,CAAC;GACnE,QAAQ;GACR,GAAI,cAAc,CAAC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,WAAW,YAAY;IAC/B,GAAI,eAAe,EAAE,QAAQ,aAAa,IAAI,CAAC;IAC/C,GAAI,QAAQ,EAAE,OAAO,aAAa,SAAS,MAAM,IAAI,CAAC;GACxD;GACA,YAAY;GACI;GACN;GACV,WAAW,SAAS;IAClB,IAAI,CAAC,UACH,WAAW,IAAI;GAEnB;GACA,OAAO;GACP,YAAY;IACV,YAAY;IACZ,qBAAqB;IACrB,2BAA2B;IAC3B,eAAe;IACf,GAAI,YAAY,WAAW;KACzB,aAAa;KACb,2BAA2B;IAC7B;GACF;EACD,CAAA;CACY,CAAA;CAGjB,OACE,qBAAC,OAAD;EACE,eAAa;EACb,WAAW,GACT,0BACA,UAAU,CAAC,cAAc,UACzB,cACE,kFACJ;EACA,OAAO,aAAa;GAAE;GAAO;EAAO,IAAI,KAAA;EAR1C,UAAA,CAUG,aACC,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,OAAD;GAAK,WAAU;GAAY,UAAA;EAAa,CAAA,GACxC,oBAAC,OAAD;GAAK,WAAW,GAAG,UAAU,8BAA8B;GACxD,UAAA;EACE,CAAA,CACL,EAAA,CAAA,IAEF,QAED,CAAC,cACA,CAAC,eACD,cACA,eACA,kBACA,SACE,oBAAC,OAAD;GACE,cAAc,MAAM,EAAE,eAAe;GACrC,WAAU;GACV,OAAO,EAAE,QAAQ,iBAAiB;GAElC,UAAA,oBAAC,YAAD;IAAY,MAAM;IAAO,SAAQ;GAAQ,CAAA;EACtC,CAAA,CAEN;;AAET"}
|
|
@@ -7,11 +7,11 @@ import { CONTROL_ICON_SIZES } from "../../utils/controlIconSizes.js";
|
|
|
7
7
|
import { INPUT_TEXT_CLASSES, getInputContainerClasses, getInputElementClasses } from "./inputStyles.js";
|
|
8
8
|
import { forwardRef, useEffect, useId, useRef, useState } from "react";
|
|
9
9
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { PaperclipIcon } from "@phosphor-icons/react/dist/ssr/Paperclip";
|
|
10
11
|
import { useDebouncedCallback } from "use-debounce";
|
|
11
12
|
import { CalendarBlankIcon } from "@phosphor-icons/react/dist/ssr/CalendarBlank";
|
|
12
13
|
import { EyeIcon } from "@phosphor-icons/react/dist/ssr/Eye";
|
|
13
14
|
import { EyeSlashIcon } from "@phosphor-icons/react/dist/ssr/EyeSlash";
|
|
14
|
-
import { PaperclipIcon } from "@phosphor-icons/react/dist/ssr/Paperclip";
|
|
15
15
|
//#region packages/components/src/components/Input/Input.tsx
|
|
16
16
|
function InputIconSlot({ icon, action, size, disabled }) {
|
|
17
17
|
const isDisabled = disabled || action?.disabled;
|
|
@@ -69,6 +69,11 @@ interface SelectBaseProps<T extends string = string> extends DataAttributes {
|
|
|
69
69
|
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
70
70
|
/** Alignment of the popover relative to the trigger */
|
|
71
71
|
align?: 'start' | 'center' | 'end';
|
|
72
|
+
/**
|
|
73
|
+
* Called when the menu closes, before focus returns to the trigger. Move
|
|
74
|
+
* focus elsewhere and call `event.preventDefault()` to keep it there.
|
|
75
|
+
*/
|
|
76
|
+
onCloseAutoFocus?: (event: Event) => void;
|
|
72
77
|
/** aria-label for the trigger button */
|
|
73
78
|
'aria-label'?: string;
|
|
74
79
|
/** Test id for the trigger button */
|
|
@@ -21,7 +21,7 @@ function optionToItem(opt) {
|
|
|
21
21
|
keywords: opt.label ? [opt.label] : void 0
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function OptionSelect({ value, onChange, options, groups, placeholder = "Select...", searchPlaceholder = "Search...", disabled = false, size = "sm", emptyText = "No results found.", open: controlledOpen, onOpenChange: controlledOnOpenChange, allowDeselect, hideSearch = true, disableFilter, onSearchChange, loading, loadingRows, onEndReached, endReachedThresholdPx, triggerClassName, variant = "outlined", contentClassName, renderValue, renderOption, side, align = "start", "aria-label": ariaLabel, "data-testid": dataTestId, ...rest }) {
|
|
24
|
+
function OptionSelect({ value, onChange, options, groups, placeholder = "Select...", searchPlaceholder = "Search...", disabled = false, size = "sm", emptyText = "No results found.", open: controlledOpen, onOpenChange: controlledOnOpenChange, allowDeselect, hideSearch = true, disableFilter, onSearchChange, loading, loadingRows, onEndReached, endReachedThresholdPx, triggerClassName, variant = "outlined", contentClassName, renderValue, renderOption, side, align = "start", onCloseAutoFocus, "aria-label": ariaLabel, "data-testid": dataTestId, ...rest }) {
|
|
25
25
|
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
26
26
|
const isControlled = controlledOpen !== void 0;
|
|
27
27
|
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
@@ -103,6 +103,7 @@ function OptionSelect({ value, onChange, options, groups, placeholder = "Select.
|
|
|
103
103
|
className: cn("w-max min-w-[var(--radix-popover-trigger-width)] max-w-[min(24rem,calc(100vw-1rem))] p-0 text-primary", contentClassName),
|
|
104
104
|
side,
|
|
105
105
|
align,
|
|
106
|
+
onCloseAutoFocus,
|
|
106
107
|
children: commandGroups ? /* @__PURE__ */ jsx(CommandMenu, {
|
|
107
108
|
groups: commandGroups,
|
|
108
109
|
...commandMenuSharedProps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","names":[],"sources":["../../../src/components/Select/Select.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { CaretDownIcon } from '../../icons/PaddedPhosphorIcons';\nimport { cn } from '../../utils/cn';\nimport {\n CONTROL_SIZES,\n type ControlSize,\n type OptionRowSize,\n} from '../../utils/componentSizes';\nimport { CONTROL_ICON_SIZES } from '../../utils/controlIconSizes';\nimport {\n type DataAttributes,\n pickDataAttributes,\n} from '../../utils/dataAttributes';\nimport { Button } from '../Button';\nimport { CommandMenu } from '../Command/CommandMenu';\nimport type { CommandMenuGroup, CommandMenuItem } from '../Command/CommandMenu';\nimport { Icon } from '../Icon';\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover';\nimport { Text } from '../Text';\n\nexport interface SelectOption<T extends string = string> {\n /** The value used for selection and filtering */\n value: T;\n /** Display label (defaults to value if not provided) */\n label?: string;\n /** Secondary description text displayed below the label */\n description?: string;\n /** Element displayed on the right side of the item (e.g. badge, shortcut) */\n rightDecorator?: ReactNode;\n /** Whether this option is disabled */\n disabled?: boolean;\n}\n\nexport interface SelectGroup<T extends string = string> {\n heading?: string;\n options: SelectOption<T>[];\n}\n\nexport type SelectSize = ControlSize;\n\nexport type SelectVariant = 'outlined' | 'plain';\n\ninterface SelectBaseProps<T extends string = string> extends DataAttributes {\n /** The currently selected value */\n value?: T;\n /** Callback when selection changes. Receives undefined when deselected. */\n onChange: (value: T | undefined) => void;\n /** Placeholder text when no value is selected */\n placeholder?: string;\n /** Placeholder text for the search input */\n searchPlaceholder?: string;\n /** Whether the select is disabled */\n disabled?: boolean;\n /** Exact trigger height: xs=20px, sm=24px, md=32px, lg=40px. */\n size?: SelectSize;\n /** Text to show when no options match the search */\n emptyText?: string;\n /** Allow deselecting the current value by clicking it again (default: false) */\n allowDeselect?: boolean;\n /** Hide the search input (default: true, search is hidden) */\n hideSearch?: boolean;\n /** Disable client-side filtering by cmdk (default: false). Set true for server-side filtering. */\n disableFilter?: boolean;\n /** Callback when the search input value changes. Useful for server-side filtering. */\n onSearchChange?: (query: string) => void;\n /** Whether more items are currently being loaded */\n loading?: boolean;\n /** Number of skeleton rows to show while loading (default: 5) */\n loadingRows?: number;\n /** Callback when the user scrolls near the end of the list. Use for infinite loading. */\n onEndReached?: () => void;\n /** Distance in pixels from the bottom to trigger onEndReached (default: 50) */\n endReachedThresholdPx?: number;\n /** Additional class name for the trigger button */\n triggerClassName?: string;\n /**\n * Trigger appearance. `outlined` (default) is a full-width form field.\n * `plain` drops the field fill and border and sizes the trigger to its\n * value, so it reads as text until hovered — for an inline setting in a row,\n * such as a member's role, where a field box would crowd it.\n */\n variant?: SelectVariant;\n /** Additional class name for the popover content */\n contentClassName?: string;\n /** Custom render function for the selected value in the trigger */\n renderValue?: (option: SelectOption<T>) => ReactNode;\n /** Custom render function for each option in the list */\n renderOption?: (option: SelectOption<T>, isSelected: boolean) => ReactNode;\n /** Side of the trigger to align the popover */\n side?: 'top' | 'bottom' | 'left' | 'right';\n /** Alignment of the popover relative to the trigger */\n align?: 'start' | 'center' | 'end';\n /** aria-label for the trigger button */\n 'aria-label'?: string;\n /** Test id for the trigger button */\n 'data-testid'?: string;\n}\n\nexport type SelectProps<T extends string = string> = SelectBaseProps<T> &\n (\n | {\n options: SelectOption<T>[];\n groups?: never;\n }\n | {\n groups: SelectGroup<T>[];\n options?: never;\n }\n ) &\n (\n | {\n /** Controlled open state */\n open: boolean;\n /** Callback when open state changes (required when `open` is provided) */\n onOpenChange: (open: boolean) => void;\n }\n | {\n open?: never;\n onOpenChange?: never;\n }\n );\n\nfunction optionToItem(opt: SelectOption): CommandMenuItem {\n return {\n value: opt.value,\n label: opt.label,\n description: opt.description,\n rightDecorator: opt.rightDecorator,\n disabled: opt.disabled,\n keywords: opt.label ? [opt.label] : undefined,\n };\n}\n\nfunction OptionSelect<T extends string = string>({\n value,\n onChange,\n options,\n groups,\n placeholder = 'Select...',\n searchPlaceholder = 'Search...',\n disabled = false,\n size = 'sm',\n emptyText = 'No results found.',\n open: controlledOpen,\n onOpenChange: controlledOnOpenChange,\n allowDeselect,\n hideSearch = true,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n triggerClassName,\n variant = 'outlined',\n contentClassName,\n renderValue,\n renderOption,\n side,\n align = 'start',\n 'aria-label': ariaLabel,\n 'data-testid': dataTestId,\n ...rest\n}: SelectProps<T>) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n const isControlled = controlledOpen !== undefined;\n const open = isControlled ? controlledOpen : uncontrolledOpen;\n const setOpen = isControlled ? controlledOnOpenChange : setUncontrolledOpen;\n\n const allOptions = useMemo<SelectOption<T>[]>(\n () => (groups ? groups.flatMap((g) => g.options) : (options ?? [])),\n [groups, options]\n );\n\n const selectedOption = useMemo(\n () => allOptions.find((opt) => opt.value === value),\n [allOptions, value]\n );\n\n const handleSelect = useCallback(\n (optionValue: string) => {\n const match = allOptions.find((o) => o.value === optionValue);\n if (!match) return;\n if (allowDeselect && match.value === value) {\n onChange(undefined);\n } else {\n onChange(match.value);\n }\n setOpen(false);\n },\n [allowDeselect, value, onChange, setOpen, allOptions]\n );\n\n const items: CommandMenuItem[] = useMemo(\n () => (options ?? []).map(optionToItem),\n [options]\n );\n\n const commandGroups: CommandMenuGroup[] | undefined = useMemo(\n () =>\n groups?.map((g) => ({\n heading: g.heading,\n items: g.options.map(optionToItem),\n })),\n [groups]\n );\n\n const renderItem = renderOption\n ? (item: CommandMenuItem, isSelected: boolean) => {\n const option = allOptions.find((o) => o.value === item.value);\n return option ? renderOption(option, isSelected) : null;\n }\n : undefined;\n const searchInputSize = size === 'xs' ? 'sm' : size === 'lg' ? 'md' : size;\n const triggerButtonSize = size === 'lg' ? 'md' : size;\n const itemRowSize: OptionRowSize =\n size === 'xs' || size === 'sm' ? 'sm' : 'md';\n\n const commandMenuSharedProps = {\n value,\n onSelect: handleSelect,\n placeholder: searchPlaceholder,\n emptyText,\n hideSearch,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n renderItem,\n inputSize: searchInputSize,\n itemRowSize,\n };\n\n const triggerContent =\n selectedOption && renderValue ? (\n renderValue(selectedOption)\n ) : (\n <Text\n as=\"span\"\n variant={triggerButtonSize}\n weight=\"normal\"\n className=\"min-w-0 truncate text-left\"\n >\n {selectedOption\n ? (selectedOption.label ?? selectedOption.value)\n : placeholder}\n </Text>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n {...pickDataAttributes(rest)}\n role=\"combobox\"\n aria-expanded={open}\n aria-label={ariaLabel ?? placeholder}\n variant={variant}\n color=\"secondary\"\n size={triggerButtonSize}\n className={cn(\n 'box-border justify-between py-0',\n CONTROL_SIZES[size].heightClassName,\n variant === 'plain'\n ? cn(\n 'w-auto max-w-full gap-space-1 px-space-1',\n // The shared disabled fill, in both themes.\n disabled && 'bg-disabled text-disabled dark:bg-disabled'\n )\n : cn(\n 'w-full',\n disabled\n ? 'border-muted bg-input-disabled text-disabled dark:bg-input-disabled'\n : 'bg-input border-input shadow-none hover:bg-input-hover hover:border-input-hover focus-visible:border-focus focus-visible:shadow-[0_0_0_1px_var(--border-focus)] focus-visible:outline-none'\n ),\n triggerClassName\n )}\n disabled={disabled}\n data-testid={dataTestId}\n >\n {triggerContent}\n <Icon\n aria-hidden\n icon={CaretDownIcon}\n iconClassName={CONTROL_ICON_SIZES[size].iconClassName}\n className={disabled ? 'text-icon-disabled' : 'text-inherit'}\n weight=\"regular\"\n />\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className={cn(\n 'w-max min-w-[var(--radix-popover-trigger-width)] max-w-[min(24rem,calc(100vw-1rem))] p-0 text-primary',\n contentClassName\n )}\n side={side}\n align={align}\n >\n {commandGroups ? (\n <CommandMenu groups={commandGroups} {...commandMenuSharedProps} />\n ) : (\n <CommandMenu items={items} {...commandMenuSharedProps} />\n )}\n </PopoverContent>\n </Popover>\n );\n}\n\nexport function Select<T extends string = string>(\n props: SelectProps<T>\n): React.ReactElement<unknown> {\n return <OptionSelect {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;AA4HA,SAAS,aAAa,KAAoC;CACxD,OAAO;EACL,OAAO,IAAI;EACX,OAAO,IAAI;EACX,aAAa,IAAI;EACjB,gBAAgB,IAAI;EACpB,UAAU,IAAI;EACd,UAAU,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,KAAA;CACtC;AACF;AAEA,SAAS,aAAwC,EAC/C,OACA,UACA,SACA,QACA,cAAc,aACd,oBAAoB,aACpB,WAAW,OACX,OAAO,MACP,YAAY,qBACZ,MAAM,gBACN,cAAc,wBACd,eACA,aAAa,MACb,eACA,gBACA,SACA,aACA,cACA,uBACA,kBACA,UAAU,YACV,kBACA,a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ACA;EACA;EACA,WAAW;EACX,aAhBA,SAAS,QAAQ,SAAS,OAAO,OAAO;CAiB1C;CAEA,MAAM,iBACJ,kBAAkB,cAChB,YAAY,cAAc,IAE1B,oBAAC,MAAD;EACE,IAAG;EACH,SAAS;EACT,QAAO;EACP,WAAU;EAET,UAAA,iBACI,eAAe,SAAS,eAAe,QACxC;CACA,CAAA;CAGV,OACE,qBAAC,SAAD;EAAe;EAAM,cAAc;EAAnC,UAAA,CACE,oBAAC,gBAAD;GAAgB,SAAA;GACd,UAAA,qBAAC,QAAD;IACE,GAAI,mBAAmB,IAAI;IAC3B,MAAK;IACL,iBAAe;IACf,cAAY,aAAa;IAChB;IACT,OAAM;IACN,MAAM;IACN,WAAW,GACT,mCACA,cAAc,KAAK,CAAC,iBACpB,YAAY,UACR,GACE,4CAEA,YAAY,4CACd,IACA,GACE,UACA,WACI,wEACA,4LACN,GACJ,gBACF;IACU;IACV,eAAa;IA1Bf,UAAA,CA4BG,gBACD,oBAAC,MAAD;KACE,eAAA;KACA,MAAM;KACN,eAAe,mBAAmB,KAAK,CAAC;KACxC,WAAW,WAAW,uBAAuB;KAC7C,QAAO;IACR,CAAA,CACK;;EACM,CAAA,GAChB,oBAAC,gBAAD;GACE,WAAW,GACT,yGACA,gBACF;GACM;GACC;GAEN,UAAA,gBACC,oBAAC,aAAD;IAAa,QAAQ;IAAe,GAAI;GAAyB,CAAA,IAEjE,oBAAC,aAAD;IAAoB;IAAO,GAAI;GAAyB,CAAA;EAE5C,CAAA,CACT;;AAEb;AAEA,SAAgB,OACd,OAC6B;CAC7B,OAAO,oBAAC,cAAD,EAAc,GAAI,MAAQ,CAAA;AACnC"}
|
|
1
|
+
{"version":3,"file":"Select.js","names":[],"sources":["../../../src/components/Select/Select.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { CaretDownIcon } from '../../icons/PaddedPhosphorIcons';\nimport { cn } from '../../utils/cn';\nimport {\n CONTROL_SIZES,\n type ControlSize,\n type OptionRowSize,\n} from '../../utils/componentSizes';\nimport { CONTROL_ICON_SIZES } from '../../utils/controlIconSizes';\nimport {\n type DataAttributes,\n pickDataAttributes,\n} from '../../utils/dataAttributes';\nimport { Button } from '../Button';\nimport { CommandMenu } from '../Command/CommandMenu';\nimport type { CommandMenuGroup, CommandMenuItem } from '../Command/CommandMenu';\nimport { Icon } from '../Icon';\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover';\nimport { Text } from '../Text';\n\nexport interface SelectOption<T extends string = string> {\n /** The value used for selection and filtering */\n value: T;\n /** Display label (defaults to value if not provided) */\n label?: string;\n /** Secondary description text displayed below the label */\n description?: string;\n /** Element displayed on the right side of the item (e.g. badge, shortcut) */\n rightDecorator?: ReactNode;\n /** Whether this option is disabled */\n disabled?: boolean;\n}\n\nexport interface SelectGroup<T extends string = string> {\n heading?: string;\n options: SelectOption<T>[];\n}\n\nexport type SelectSize = ControlSize;\n\nexport type SelectVariant = 'outlined' | 'plain';\n\ninterface SelectBaseProps<T extends string = string> extends DataAttributes {\n /** The currently selected value */\n value?: T;\n /** Callback when selection changes. Receives undefined when deselected. */\n onChange: (value: T | undefined) => void;\n /** Placeholder text when no value is selected */\n placeholder?: string;\n /** Placeholder text for the search input */\n searchPlaceholder?: string;\n /** Whether the select is disabled */\n disabled?: boolean;\n /** Exact trigger height: xs=20px, sm=24px, md=32px, lg=40px. */\n size?: SelectSize;\n /** Text to show when no options match the search */\n emptyText?: string;\n /** Allow deselecting the current value by clicking it again (default: false) */\n allowDeselect?: boolean;\n /** Hide the search input (default: true, search is hidden) */\n hideSearch?: boolean;\n /** Disable client-side filtering by cmdk (default: false). Set true for server-side filtering. */\n disableFilter?: boolean;\n /** Callback when the search input value changes. Useful for server-side filtering. */\n onSearchChange?: (query: string) => void;\n /** Whether more items are currently being loaded */\n loading?: boolean;\n /** Number of skeleton rows to show while loading (default: 5) */\n loadingRows?: number;\n /** Callback when the user scrolls near the end of the list. Use for infinite loading. */\n onEndReached?: () => void;\n /** Distance in pixels from the bottom to trigger onEndReached (default: 50) */\n endReachedThresholdPx?: number;\n /** Additional class name for the trigger button */\n triggerClassName?: string;\n /**\n * Trigger appearance. `outlined` (default) is a full-width form field.\n * `plain` drops the field fill and border and sizes the trigger to its\n * value, so it reads as text until hovered — for an inline setting in a row,\n * such as a member's role, where a field box would crowd it.\n */\n variant?: SelectVariant;\n /** Additional class name for the popover content */\n contentClassName?: string;\n /** Custom render function for the selected value in the trigger */\n renderValue?: (option: SelectOption<T>) => ReactNode;\n /** Custom render function for each option in the list */\n renderOption?: (option: SelectOption<T>, isSelected: boolean) => ReactNode;\n /** Side of the trigger to align the popover */\n side?: 'top' | 'bottom' | 'left' | 'right';\n /** Alignment of the popover relative to the trigger */\n align?: 'start' | 'center' | 'end';\n /**\n * Called when the menu closes, before focus returns to the trigger. Move\n * focus elsewhere and call `event.preventDefault()` to keep it there.\n */\n onCloseAutoFocus?: (event: Event) => void;\n /** aria-label for the trigger button */\n 'aria-label'?: string;\n /** Test id for the trigger button */\n 'data-testid'?: string;\n}\n\nexport type SelectProps<T extends string = string> = SelectBaseProps<T> &\n (\n | {\n options: SelectOption<T>[];\n groups?: never;\n }\n | {\n groups: SelectGroup<T>[];\n options?: never;\n }\n ) &\n (\n | {\n /** Controlled open state */\n open: boolean;\n /** Callback when open state changes (required when `open` is provided) */\n onOpenChange: (open: boolean) => void;\n }\n | {\n open?: never;\n onOpenChange?: never;\n }\n );\n\nfunction optionToItem(opt: SelectOption): CommandMenuItem {\n return {\n value: opt.value,\n label: opt.label,\n description: opt.description,\n rightDecorator: opt.rightDecorator,\n disabled: opt.disabled,\n keywords: opt.label ? [opt.label] : undefined,\n };\n}\n\nfunction OptionSelect<T extends string = string>({\n value,\n onChange,\n options,\n groups,\n placeholder = 'Select...',\n searchPlaceholder = 'Search...',\n disabled = false,\n size = 'sm',\n emptyText = 'No results found.',\n open: controlledOpen,\n onOpenChange: controlledOnOpenChange,\n allowDeselect,\n hideSearch = true,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n triggerClassName,\n variant = 'outlined',\n contentClassName,\n renderValue,\n renderOption,\n side,\n align = 'start',\n onCloseAutoFocus,\n 'aria-label': ariaLabel,\n 'data-testid': dataTestId,\n ...rest\n}: SelectProps<T>) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n const isControlled = controlledOpen !== undefined;\n const open = isControlled ? controlledOpen : uncontrolledOpen;\n const setOpen = isControlled ? controlledOnOpenChange : setUncontrolledOpen;\n\n const allOptions = useMemo<SelectOption<T>[]>(\n () => (groups ? groups.flatMap((g) => g.options) : (options ?? [])),\n [groups, options]\n );\n\n const selectedOption = useMemo(\n () => allOptions.find((opt) => opt.value === value),\n [allOptions, value]\n );\n\n const handleSelect = useCallback(\n (optionValue: string) => {\n const match = allOptions.find((o) => o.value === optionValue);\n if (!match) return;\n if (allowDeselect && match.value === value) {\n onChange(undefined);\n } else {\n onChange(match.value);\n }\n setOpen(false);\n },\n [allowDeselect, value, onChange, setOpen, allOptions]\n );\n\n const items: CommandMenuItem[] = useMemo(\n () => (options ?? []).map(optionToItem),\n [options]\n );\n\n const commandGroups: CommandMenuGroup[] | undefined = useMemo(\n () =>\n groups?.map((g) => ({\n heading: g.heading,\n items: g.options.map(optionToItem),\n })),\n [groups]\n );\n\n const renderItem = renderOption\n ? (item: CommandMenuItem, isSelected: boolean) => {\n const option = allOptions.find((o) => o.value === item.value);\n return option ? renderOption(option, isSelected) : null;\n }\n : undefined;\n const searchInputSize = size === 'xs' ? 'sm' : size === 'lg' ? 'md' : size;\n const triggerButtonSize = size === 'lg' ? 'md' : size;\n const itemRowSize: OptionRowSize =\n size === 'xs' || size === 'sm' ? 'sm' : 'md';\n\n const commandMenuSharedProps = {\n value,\n onSelect: handleSelect,\n placeholder: searchPlaceholder,\n emptyText,\n hideSearch,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n renderItem,\n inputSize: searchInputSize,\n itemRowSize,\n };\n\n const triggerContent =\n selectedOption && renderValue ? (\n renderValue(selectedOption)\n ) : (\n <Text\n as=\"span\"\n variant={triggerButtonSize}\n weight=\"normal\"\n className=\"min-w-0 truncate text-left\"\n >\n {selectedOption\n ? (selectedOption.label ?? selectedOption.value)\n : placeholder}\n </Text>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n {...pickDataAttributes(rest)}\n role=\"combobox\"\n aria-expanded={open}\n aria-label={ariaLabel ?? placeholder}\n variant={variant}\n color=\"secondary\"\n size={triggerButtonSize}\n className={cn(\n 'box-border justify-between py-0',\n CONTROL_SIZES[size].heightClassName,\n variant === 'plain'\n ? cn(\n 'w-auto max-w-full gap-space-1 px-space-1',\n // The shared disabled fill, in both themes.\n disabled && 'bg-disabled text-disabled dark:bg-disabled'\n )\n : cn(\n 'w-full',\n disabled\n ? 'border-muted bg-input-disabled text-disabled dark:bg-input-disabled'\n : 'bg-input border-input shadow-none hover:bg-input-hover hover:border-input-hover focus-visible:border-focus focus-visible:shadow-[0_0_0_1px_var(--border-focus)] focus-visible:outline-none'\n ),\n triggerClassName\n )}\n disabled={disabled}\n data-testid={dataTestId}\n >\n {triggerContent}\n <Icon\n aria-hidden\n icon={CaretDownIcon}\n iconClassName={CONTROL_ICON_SIZES[size].iconClassName}\n className={disabled ? 'text-icon-disabled' : 'text-inherit'}\n weight=\"regular\"\n />\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className={cn(\n 'w-max min-w-[var(--radix-popover-trigger-width)] max-w-[min(24rem,calc(100vw-1rem))] p-0 text-primary',\n contentClassName\n )}\n side={side}\n align={align}\n onCloseAutoFocus={onCloseAutoFocus}\n >\n {commandGroups ? (\n <CommandMenu groups={commandGroups} {...commandMenuSharedProps} />\n ) : (\n <CommandMenu items={items} {...commandMenuSharedProps} />\n )}\n </PopoverContent>\n </Popover>\n );\n}\n\nexport function Select<T extends string = string>(\n props: SelectProps<T>\n): React.ReactElement<unknown> {\n return <OptionSelect {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;AAiIA,SAAS,aAAa,KAAoC;CACxD,OAAO;EACL,OAAO,IAAI;EACX,OAAO,IAAI;EACX,aAAa,IAAI;EACjB,gBAAgB,IAAI;EACpB,UAAU,IAAI;EACd,UAAU,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,KAAA;CACtC;AACF;AAEA,SAAS,aAAwC,EAC/C,OACA,UACA,SACA,QACA,cAAc,aACd,oBAAoB,aACpB,WAAW,OACX,OAAO,MACP,YAAY,qBACZ,MAAM,gBACN,cAAc,wBACd,eACA,aAAa,MACb,eACA,gBACA,SACA,aACA,cACA,uBACA,kBACA,UAAU,YACV,kBACA,aACA,cACA,MACA,QAAQ,SACR,kBACA,cAAc,WACd,eAAe,YACf,GAAG,QACc;CACjB,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,KAAK;CAC9D,MAAM,eAAe,mBAAmB,KAAA;CACxC,MAAM,OAAO,eAAe,iBAAiB;CAC7C,MAAM,UAAU,eAAe,yBAAyB;CAExD,MAAM,aAAa,cACV,SAAS,OAAO,SAAS,MAAM,EAAE,OAAO,IAAK,WAAW,CAAC,GAChE,CAAC,QAAQ,OAAO,CAClB;CAEA,MAAM,iBAAiB,cACf,WAAW,MAAM,QAAQ,IAAI,UAAU,KAAK,GAClD,CAAC,YAAY,KAAK,CACpB;CAEA,MAAM,eAAe,aAClB,gBAAwB;EACvB,MAAM,QAAQ,WAAW,MAAM,MAAM,EAAE,UAAU,WAAW;EAC5D,IAAI,CAAC,OAAO;EACZ,IAAI,iBAAiB,MAAM,UAAU,OACnC,SAAS,KAAA,CAAS;OAElB,SAAS,MAAM,KAAK;EAEtB,QAAQ,KAAK;CACf,GACA;EAAC;EAAe;EAAO;EAAU;EAAS;CAAU,CACtD;CAEA,MAAM,QAA2B,eACxB,WAAW,CAAC,EAAA,CAAG,IAAI,YAAY,GACtC,CAAC,OA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oBAAC,gBAAD;GACE,WAAW,GACT,yGACA,gBACF;GACM;GACC;GACW;GAEjB,UAAA,gBACC,oBAAC,aAAD;IAAa,QAAQ;IAAe,GAAI;GAAyB,CAAA,IAEjE,oBAAC,aAAD;IAAoB;IAAO,GAAI;GAAyB,CAAA;EAE5C,CAAA,CACT;;AAEb;AAEA,SAAgB,OACd,OAC6B;CAC7B,OAAO,oBAAC,cAAD,EAAc,GAAI,MAAQ,CAAA;AACnC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Text } from "./Text/Text.js";
|
|
2
2
|
import { Button } from "./Button/Button.js";
|
|
3
|
-
import { MAX_TEXT_LENGTH } from "./Code/constants.js";
|
|
4
3
|
import { getScrollParent } from "../utils/get-closest-scroll-parent.js";
|
|
5
4
|
import { parseTextWithLinks } from "../utils/parseTextLinks.js";
|
|
5
|
+
import { MAX_TEXT_LENGTH } from "./Code/constants.js";
|
|
6
6
|
import { TextVirtualizer } from "./TextVirtualizer.js";
|
|
7
7
|
import { useMemo, useState } from "react";
|
|
8
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -28,6 +28,8 @@ export { StatusBadge } from './StatusBadge/index.js';
|
|
|
28
28
|
export type { StatusBadgeProps, StatusBadgeSize, StatusBadgeVariant, } from './StatusBadge/index.js';
|
|
29
29
|
export { Banner } from './Banner/Banner.js';
|
|
30
30
|
export type { BannerProps } from './Banner/Banner.js';
|
|
31
|
+
export { ChatComposer, ChatComposerAction, ChatComposerAttachment, ChatComposerAttachmentMenu, ChatComposerAttachments, ChatComposerContext, ChatComposerInput, ChatComposerModelSelect, ChatComposerToolbar, } from './ChatComposer/index.js';
|
|
32
|
+
export type { ChatComposerActionProps, ChatComposerAttachmentMenuProps, ChatComposerAttachmentProps, ChatComposerAttachmentsProps, ChatComposerContextValue, ChatComposerDrawerIntent, ChatComposerInputHandle, ChatComposerInputProps, ChatComposerModelSelectProps, ChatComposerProps, ChatComposerToolbarProps, } from './ChatComposer/index.js';
|
|
31
33
|
export { ChatMessage, ChatMessageActions, ChatMessageBody, ChatMessageHeader, ChatTurnDivider, } from './ChatMessage/index.js';
|
|
32
34
|
export type { ChatMessageAction, ChatMessageActionCapabilities, ChatMessageActionsProps, ChatMessageBodyProps, ChatMessageContentBlock, ChatMessageHeaderProps, ChatMessageModel, ChatMessageProps, ChatMessageRole, ChatMessageStatus, ChatTurnDividerProps, } from './ChatMessage/index.js';
|
|
33
35
|
export { Checkbox, getCheckedState } from './Checkbox/index.js';
|
package/dist/components/index.js
CHANGED
|
@@ -17,6 +17,12 @@ import { Link } from "./Link/Link.js";
|
|
|
17
17
|
import { EmptyState } from "./EmptyState/EmptyState.js";
|
|
18
18
|
import { CircleSkeleton, Skeleton, SkeletonRows } from "./Skeleton/Skeleton.js";
|
|
19
19
|
import { ChartTooltip, ChartTooltipBody, ChartTooltipHeader, ChartTooltipRow } from "./ChartTooltip/ChartTooltip.js";
|
|
20
|
+
import { ChatComposerContext } from "./ChatComposer/ChatComposerContext.js";
|
|
21
|
+
import { ChatComposer, ChatComposerAction, ChatComposerToolbar } from "./ChatComposer/ChatComposer.js";
|
|
22
|
+
import { ChatComposerAttachment, ChatComposerAttachmentMenu, ChatComposerAttachments } from "./ChatComposer/ChatComposerAttachments.js";
|
|
23
|
+
import { Textarea } from "./Textarea/Textarea.js";
|
|
24
|
+
import { ChatComposerInput } from "./ChatComposer/ChatComposerInput.js";
|
|
25
|
+
import { ChatComposerModelSelect } from "./ChatComposer/ChatComposerModelSelect.js";
|
|
20
26
|
import { Divider } from "./Divider/Divider.js";
|
|
21
27
|
import { ChatMessage, ChatMessageActions, ChatMessageBody, ChatMessageHeader, ChatTurnDivider } from "./ChatMessage/ChatMessage.js";
|
|
22
28
|
import { Checkbox } from "./Checkbox/Checkbox.js";
|
|
@@ -40,5 +46,4 @@ import { RadioGroupItem } from "./RadioGroup/RadioGroupItem.js";
|
|
|
40
46
|
import { Slider } from "./Slider/Slider.js";
|
|
41
47
|
import { StatusBadge } from "./StatusBadge/StatusBadge.js";
|
|
42
48
|
import { Switch } from "./Switch/Switch.js";
|
|
43
|
-
|
|
44
|
-
export { Attachment, AttachmentList, Avatar, Badge, Banner, Breadcrumb, BreadcrumbLink, BreadcrumbPage, Button, ButtonGroup, Card, ChartTooltip, ChartTooltipBody, ChartTooltipHeader, ChartTooltipRow, ChatMessage, ChatMessageActions, ChatMessageBody, ChatMessageHeader, ChatTurnDivider, Checkbox, CircleSkeleton, Divider, EmptyState, ErrorState, GroupedTabs, HeatmapBlock, HeatmapChart, Icon, IconButton, ImagePreviewBlock, ImagePreviewDialog, Input, Kbd, KbdGroup, LinearProgress, Link, MetricChart, ProgressBar, RadioButton, RadioCard, RadioGroup, RadioGroupItem, Skeleton, SkeletonRows, Slider, Spinner, SpinnerIcon, StatusBadge, Switch, Text, Textarea, Tooltip, TooltipProvider, formatMetricCurrency, formatMetricDate, formatMetricDuration, formatMetricNumber, formatMetricTime, getCheckedState };
|
|
49
|
+
export { Attachment, AttachmentList, Avatar, Badge, Banner, Breadcrumb, BreadcrumbLink, BreadcrumbPage, Button, ButtonGroup, Card, ChartTooltip, ChartTooltipBody, ChartTooltipHeader, ChartTooltipRow, ChatComposer, ChatComposerAction, ChatComposerAttachment, ChatComposerAttachmentMenu, ChatComposerAttachments, ChatComposerContext, ChatComposerInput, ChatComposerModelSelect, ChatComposerToolbar, ChatMessage, ChatMessageActions, ChatMessageBody, ChatMessageHeader, ChatTurnDivider, Checkbox, CircleSkeleton, Divider, EmptyState, ErrorState, GroupedTabs, HeatmapBlock, HeatmapChart, Icon, IconButton, ImagePreviewBlock, ImagePreviewDialog, Input, Kbd, KbdGroup, LinearProgress, Link, MetricChart, ProgressBar, RadioButton, RadioCard, RadioGroup, RadioGroupItem, Skeleton, SkeletonRows, Slider, Spinner, SpinnerIcon, StatusBadge, Switch, Text, Textarea, Tooltip, TooltipProvider, formatMetricCurrency, formatMetricDate, formatMetricDuration, formatMetricNumber, formatMetricTime, getCheckedState };
|
package/dist/components.css
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
|
|
2
|
+
._editor_1jx45_3 p.is-editor-empty:first-child:before{pointer-events:none;float:left;height:0;color:var(--text-placeholder);content:attr(data-placeholder)}._editor_1jx45_3 p{margin:0}._editor_1jx45_3>*+*{margin-top:.5rem}._editor_1jx45_3 h1,._editor_1jx45_3 h2,._editor_1jx45_3 h3,._editor_1jx45_3 h4,._editor_1jx45_3 h5,._editor_1jx45_3 h6{font-size:1rem;line-height:var(--tw-leading,1.5rem);--tw-font-weight:var(--font-weight-semibold,600);font-weight:var(--font-weight-semibold,600)}._editor_1jx45_3 ul{padding-left:1.5rem;list-style-type:disc;list-style-position:outside}._editor_1jx45_3 ol{padding-left:1.5rem;list-style-type:decimal;list-style-position:outside}._editor_1jx45_3 a{color:var(--text-link);text-underline-offset:2px;text-decoration-line:underline}._editor_1jx45_3 blockquote{border-left-style:var(--tw-border-style);border-left-width:2px;border-color:var(--border-default);color:var(--text-secondary);padding-left:.75rem}._editor_1jx45_3 :not(pre)>code{border-radius:var(--radius-sm);background-color:var(--bg-surface-level-2);padding-inline:.25rem;font-family:Fira Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}._editor_1jx45_3 pre code{background-color:#0000;padding:0}._editor_1jx45_3 hr{border-color:var(--border-default)}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}
|
|
3
|
+
/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
|
|
2
4
|
._grid_rs273_4{grid-template:repeat(3,minmax(0,1fr))/repeat(3,minmax(0,1fr));gap:10%;display:inline-grid}._pixel_rs273_10{opacity:.15;animation:_pixel-on_rs273_1 var(--loading-cycle) ease-in-out infinite;border-radius:1px}._dot_rs273_16{border-radius:var(--radius-full)}._inactive_rs273_20{opacity:.07;animation:none}._grid_rs273_4[data-animated=false] ._pixel_rs273_10{animation:none}._grid_rs273_4[data-animated=false] ._pixel_rs273_10:not(._inactive_rs273_20){opacity:.5}._shimmer_rs273_33{--macaw-shimmer-highlight:var(--text-primary);color:#0000;-webkit-background-clip:text;background-clip:text;background-image:linear-gradient(to right, var(--text-tertiary) 35%, var(--macaw-shimmer-highlight) 50%, var(--text-tertiary) 65%);background-size:200% 100%;animation:1.4s linear infinite _shimmer-text_rs273_1}._slow_rs273_46{animation-duration:2.8s}._brandShimmer_rs273_50{--macaw-shimmer-highlight:var(--text-brand-primary)}@keyframes _pixel-on_rs273_1{0%,to{opacity:.15}18%,42%{opacity:1}62%{opacity:.15}}@keyframes _shimmer-text_rs273_1{0%{background-position:150%}to{background-position:-50%}}@media (prefers-reduced-motion:reduce){._pixel_rs273_10,._shimmer_rs273_33{animation:none}._pixel_rs273_10:not(._inactive_rs273_20){opacity:.5}._shimmer_rs273_33{color:var(--text-secondary);background:0 0}}@media (forced-colors:active){._shimmer_rs273_33{color:canvastext;background:0 0}._pixel_rs273_10{background:canvastext}}
|
|
3
5
|
/*$vite$:1*/
|