@langchain/macaw-components 1.5.0 → 1.5.2

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.
Files changed (91) hide show
  1. package/dist/catalog.json +826 -556
  2. package/dist/components/ChatComposer/ChatComposer.d.ts +31 -0
  3. package/dist/components/ChatComposer/ChatComposer.js +142 -0
  4. package/dist/components/ChatComposer/ChatComposer.js.map +1 -0
  5. package/dist/components/ChatComposer/ChatComposerAttachments.d.ts +17 -0
  6. package/dist/components/ChatComposer/ChatComposerAttachments.js +117 -0
  7. package/dist/components/ChatComposer/ChatComposerAttachments.js.map +1 -0
  8. package/dist/components/ChatComposer/ChatComposerCodeBlock.d.ts +2 -0
  9. package/dist/components/ChatComposer/ChatComposerCodeBlock.js +100 -0
  10. package/dist/components/ChatComposer/ChatComposerCodeBlock.js.map +1 -0
  11. package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.d.ts +19 -0
  12. package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.js +107 -0
  13. package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.js.map +1 -0
  14. package/dist/components/ChatComposer/ChatComposerCodeBlockView.d.ts +5 -0
  15. package/dist/components/ChatComposer/ChatComposerCodeBlockView.js +104 -0
  16. package/dist/components/ChatComposer/ChatComposerCodeBlockView.js.map +1 -0
  17. package/dist/components/ChatComposer/ChatComposerContext.d.ts +15 -0
  18. package/dist/components/ChatComposer/ChatComposerContext.js +16 -0
  19. package/dist/components/ChatComposer/ChatComposerContext.js.map +1 -0
  20. package/dist/components/ChatComposer/ChatComposerInput.d.ts +19 -0
  21. package/dist/components/ChatComposer/ChatComposerInput.js +38 -0
  22. package/dist/components/ChatComposer/ChatComposerInput.js.map +1 -0
  23. package/dist/components/ChatComposer/ChatComposerModelSelect.d.ts +3 -0
  24. package/dist/components/ChatComposer/ChatComposerModelSelect.js +56 -0
  25. package/dist/components/ChatComposer/ChatComposerModelSelect.js.map +1 -0
  26. package/dist/components/ChatComposer/ChatComposerPlainInput.d.ts +8 -0
  27. package/dist/components/ChatComposer/ChatComposerPlainInput.js +48 -0
  28. package/dist/components/ChatComposer/ChatComposerPlainInput.js.map +1 -0
  29. package/dist/components/ChatComposer/ChatComposerRichInput.d.ts +7 -0
  30. package/dist/components/ChatComposer/ChatComposerRichInput.js +53 -0
  31. package/dist/components/ChatComposer/ChatComposerRichInput.js.map +1 -0
  32. package/dist/components/ChatComposer/index.d.ts +10 -0
  33. package/dist/components/ChatComposer/index.js +6 -0
  34. package/dist/components/ChatComposer/useChatComposerEditor.d.ts +21 -0
  35. package/dist/components/ChatComposer/useChatComposerEditor.js +113 -0
  36. package/dist/components/ChatComposer/useChatComposerEditor.js.map +1 -0
  37. package/dist/components/ChatMessage/ChatMessage.js +1 -1
  38. package/dist/components/ChatState/ChatState.d.ts +16 -0
  39. package/dist/components/ChatState/ChatState.js +96 -0
  40. package/dist/components/ChatState/ChatState.js.map +1 -0
  41. package/dist/components/ChatState/ChatStateTimer.d.ts +11 -0
  42. package/dist/components/ChatState/ChatStateTimer.js +57 -0
  43. package/dist/components/ChatState/ChatStateTimer.js.map +1 -0
  44. package/dist/components/ChatState/index.d.ts +2 -0
  45. package/dist/components/ChatState/index.js +2 -0
  46. package/dist/components/ChatToolCall/ChatToolCall.d.ts +23 -0
  47. package/dist/components/ChatToolCall/ChatToolCall.js +98 -0
  48. package/dist/components/ChatToolCall/ChatToolCall.js.map +1 -0
  49. package/dist/components/ChatToolCall/ChatToolCall.types.d.ts +10 -0
  50. package/dist/components/ChatToolCall/ChatToolCall.types.js +0 -0
  51. package/dist/components/ChatToolCall/ChatToolCall.value.d.ts +2 -0
  52. package/dist/components/ChatToolCall/ChatToolCall.value.js +82 -0
  53. package/dist/components/ChatToolCall/ChatToolCall.value.js.map +1 -0
  54. package/dist/components/ChatToolCall/ChatToolCallAccordion.d.ts +17 -0
  55. package/dist/components/ChatToolCall/ChatToolCallAccordion.js +56 -0
  56. package/dist/components/ChatToolCall/ChatToolCallAccordion.js.map +1 -0
  57. package/dist/components/ChatToolCall/ChatToolCallDetails.d.ts +4 -0
  58. package/dist/components/ChatToolCall/ChatToolCallDetails.js +66 -0
  59. package/dist/components/ChatToolCall/ChatToolCallDetails.js.map +1 -0
  60. package/dist/components/ChatToolCall/ChatToolCallGroup.d.ts +11 -0
  61. package/dist/components/ChatToolCall/ChatToolCallGroup.js +63 -0
  62. package/dist/components/ChatToolCall/ChatToolCallGroup.js.map +1 -0
  63. package/dist/components/ChatToolCall/ChatToolCallReasoning.d.ts +18 -0
  64. package/dist/components/ChatToolCall/ChatToolCallReasoning.js +45 -0
  65. package/dist/components/ChatToolCall/ChatToolCallReasoning.js.map +1 -0
  66. package/dist/components/ChatToolCall/ChatToolCallStatusRow.d.ts +11 -0
  67. package/dist/components/ChatToolCall/ChatToolCallStatusRow.js +36 -0
  68. package/dist/components/ChatToolCall/ChatToolCallStatusRow.js.map +1 -0
  69. package/dist/components/ChatToolCall/index.d.ts +7 -0
  70. package/dist/components/ChatToolCall/index.js +4 -0
  71. package/dist/components/Code/CodeLite.js +1 -1
  72. package/dist/components/Code/index.js +7 -8
  73. package/dist/components/Code/index.js.map +1 -1
  74. package/dist/components/Input/Input.js +1 -1
  75. package/dist/components/Select/Select.d.ts +5 -0
  76. package/dist/components/Select/Select.js +2 -1
  77. package/dist/components/Select/Select.js.map +1 -1
  78. package/dist/components/TextWithLinks.js +1 -1
  79. package/dist/components/index.d.ts +2 -0
  80. package/dist/components/index.js +7 -2
  81. package/dist/components.css +2 -0
  82. package/dist/icons/LongTailPhosphorIcons.js +1 -1
  83. package/dist/icons/WeightedPhosphorIcons.js +1 -1
  84. package/dist/index.js +7 -2
  85. package/dist/utilities.css +1 -1
  86. package/dist/utils/componentUtils.d.ts +2 -0
  87. package/dist/utils/componentUtils.js +8 -0
  88. package/dist/utils/componentUtils.js.map +1 -0
  89. package/docs/CHAT.md +31 -0
  90. package/docs/DESIGN.md +44 -0
  91. package/package.json +29 -2
@@ -0,0 +1,104 @@
1
+ import { ChatComposerInputEditableContext, isComposerSubmitKey, useChatComposerContext } from "./ChatComposerContext.js";
2
+ import { moveSelectionOutsideCodeBlock } from "./ChatComposerCodeBlockAdapter.js";
3
+ import { CODE_LANGUAGES, resolveCodeLanguage } from "../Code/codeLanguages.js";
4
+ import { CodeLanguageSelect } from "../Code/CodeLanguageSelect.js";
5
+ import { CodeToolbar } from "../Code/CodeToolbar.js";
6
+ import { Code } from "../Code/index.js";
7
+ import { useContext } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ import { NodeViewWrapper } from "@tiptap/react";
10
+ //#region packages/components/src/components/ChatComposer/ChatComposerCodeBlockView.tsx
11
+ function ComposerCodeBlockView({ node, updateAttributes, editor, getPos, adapter }) {
12
+ const editable = useContext(ChatComposerInputEditableContext);
13
+ const composer = useChatComposerContext();
14
+ const language = typeof node.attrs.language === "string" ? node.attrs.language : "";
15
+ const resolvedLanguage = resolveCodeLanguage(language);
16
+ const languageLabel = CODE_LANGUAGES.find((option) => option.value === resolvedLanguage)?.label ?? language;
17
+ function onCodeKeyDown(event) {
18
+ const view = adapter.view;
19
+ if (!view || !(event.target instanceof Node) || !view.contentDOM.contains(event.target) || !editable || !editor.isEditable || view.composing || event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
20
+ const consume = () => {
21
+ event.preventDefault();
22
+ event.stopPropagation();
23
+ };
24
+ if (composer.submit && isComposerSubmitKey(event.nativeEvent, true)) {
25
+ consume();
26
+ composer.submit();
27
+ return;
28
+ }
29
+ if ((event.metaKey || event.ctrlKey) && !event.altKey) {
30
+ const key = event.key.toLowerCase();
31
+ if (key === "z" || key === "y") {
32
+ consume();
33
+ if (key === "y" || event.shiftKey) editor.commands.redo();
34
+ else editor.commands.undo();
35
+ adapter.syncFromComposer();
36
+ editor.view.focus();
37
+ }
38
+ return;
39
+ }
40
+ if (event.altKey) return;
41
+ const position = getPos();
42
+ if (position === void 0) return;
43
+ const { head, empty } = view.state.selection.main;
44
+ const code = view.state.doc;
45
+ if (event.key === "Enter" && event.shiftKey) {
46
+ consume();
47
+ view.dispatch({
48
+ ...view.state.replaceSelection("\n"),
49
+ userEvent: "input"
50
+ });
51
+ return;
52
+ }
53
+ if (event.shiftKey) return;
54
+ if (event.key === "Enter" && empty && head === code.length && code.toString().endsWith("\n\n")) {
55
+ consume();
56
+ editor.commands.keyboardShortcut("Enter");
57
+ editor.view.focus();
58
+ return;
59
+ }
60
+ if (event.key === "Backspace" && empty && code.length === 0) {
61
+ consume();
62
+ editor.commands.setParagraph();
63
+ editor.view.focus();
64
+ return;
65
+ }
66
+ if (moveSelectionOutsideCodeBlock(editor, position, view.state, event.key)) {
67
+ consume();
68
+ editor.view.focus();
69
+ }
70
+ }
71
+ return /* @__PURE__ */ jsx(NodeViewWrapper, {
72
+ contentEditable: false,
73
+ className: "my-space-2 min-w-0",
74
+ children: /* @__PURE__ */ jsx("div", {
75
+ onKeyDownCapture: onCodeKeyDown,
76
+ children: /* @__PURE__ */ jsx(Code, {
77
+ value: node.textContent,
78
+ language: resolvedLanguage ?? "plaintext",
79
+ readOnly: !editable,
80
+ variant: "plain",
81
+ showFoldGutter: false,
82
+ ariaLabel: `${languageLabel} code block`,
83
+ fontSize: "14px",
84
+ omitMaxHeight: true,
85
+ onUpdate: adapter.forwardUpdate,
86
+ onCreateEditor: (view) => adapter.attach(view),
87
+ toolbar: /* @__PURE__ */ jsx(CodeToolbar, { language: /* @__PURE__ */ jsx(CodeLanguageSelect, {
88
+ value: language,
89
+ onChange: (value) => {
90
+ if (editable && editor.isEditable) {
91
+ updateAttributes({ language: value === "plaintext" ? "" : value });
92
+ requestAnimationFrame(() => adapter.focus());
93
+ }
94
+ },
95
+ disabled: !editable
96
+ }) })
97
+ })
98
+ })
99
+ });
100
+ }
101
+ //#endregion
102
+ export { ComposerCodeBlockView };
103
+
104
+ //# sourceMappingURL=ChatComposerCodeBlockView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatComposerCodeBlockView.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposerCodeBlockView.tsx"],"sourcesContent":["import { useContext } from 'react';\nimport type { KeyboardEvent } from 'react';\n\nimport type { ReactNodeViewProps } from '@tiptap/react';\nimport { NodeViewWrapper } from '@tiptap/react';\n\nimport { Code } from '../Code';\nimport { CODE_LANGUAGES, resolveCodeLanguage } from '../Code/codeLanguages';\nimport { CodeLanguageSelect } from '../Code/CodeLanguageSelect';\nimport { CodeToolbar } from '../Code/CodeToolbar';\nimport type { ComposerCodeBlockAdapter } from './ChatComposerCodeBlockAdapter';\nimport { moveSelectionOutsideCodeBlock } from './ChatComposerCodeBlockAdapter';\nimport {\n ChatComposerInputEditableContext,\n isComposerSubmitKey,\n useChatComposerContext,\n} from './ChatComposerContext';\n\nexport function ComposerCodeBlockView({\n node,\n updateAttributes,\n editor,\n getPos,\n adapter,\n}: ReactNodeViewProps & { adapter: ComposerCodeBlockAdapter }) {\n const editable = useContext(ChatComposerInputEditableContext);\n const composer = useChatComposerContext();\n const language =\n typeof node.attrs.language === 'string' ? node.attrs.language : '';\n const resolvedLanguage = resolveCodeLanguage(language);\n const languageLabel =\n CODE_LANGUAGES.find((option) => option.value === resolvedLanguage)?.label ??\n language;\n\n function onCodeKeyDown(event: KeyboardEvent<HTMLDivElement>) {\n const view = adapter.view;\n if (\n !view ||\n !(event.target instanceof Node) ||\n !view.contentDOM.contains(event.target) ||\n !editable ||\n !editor.isEditable ||\n view.composing ||\n event.nativeEvent.isComposing ||\n event.nativeEvent.keyCode === 229\n ) {\n return;\n }\n const consume = () => {\n event.preventDefault();\n event.stopPropagation();\n };\n if (composer.submit && isComposerSubmitKey(event.nativeEvent, true)) {\n consume();\n composer.submit();\n return;\n }\n if ((event.metaKey || event.ctrlKey) && !event.altKey) {\n const key = event.key.toLowerCase();\n if (key === 'z' || key === 'y') {\n consume();\n if (key === 'y' || event.shiftKey) editor.commands.redo();\n else editor.commands.undo();\n adapter.syncFromComposer();\n editor.view.focus();\n }\n return;\n }\n if (event.altKey) return;\n\n const position = getPos();\n if (position === undefined) return;\n const { head, empty } = view.state.selection.main;\n const code = view.state.doc;\n if (event.key === 'Enter' && event.shiftKey) {\n consume();\n view.dispatch({\n ...view.state.replaceSelection('\\n'),\n userEvent: 'input',\n });\n return;\n }\n if (event.shiftKey) return;\n if (\n event.key === 'Enter' &&\n empty &&\n head === code.length &&\n code.toString().endsWith('\\n\\n')\n ) {\n consume();\n editor.commands.keyboardShortcut('Enter');\n editor.view.focus();\n return;\n }\n if (event.key === 'Backspace' && empty && code.length === 0) {\n consume();\n editor.commands.setParagraph();\n editor.view.focus();\n return;\n }\n if (\n moveSelectionOutsideCodeBlock(editor, position, view.state, event.key)\n ) {\n consume();\n editor.view.focus();\n }\n }\n\n return (\n <NodeViewWrapper contentEditable={false} className=\"my-space-2 min-w-0\">\n <div onKeyDownCapture={onCodeKeyDown}>\n <Code\n value={node.textContent}\n language={resolvedLanguage ?? 'plaintext'}\n readOnly={!editable}\n variant=\"plain\"\n showFoldGutter={false}\n ariaLabel={`${languageLabel} code block`}\n fontSize=\"14px\"\n omitMaxHeight\n onUpdate={adapter.forwardUpdate}\n onCreateEditor={(view) => adapter.attach(view)}\n toolbar={\n <CodeToolbar\n language={\n <CodeLanguageSelect\n value={language}\n onChange={(value) => {\n if (editable && editor.isEditable) {\n updateAttributes({\n language: value === 'plaintext' ? '' : value,\n });\n requestAnimationFrame(() => adapter.focus());\n }\n }}\n disabled={!editable}\n />\n }\n />\n }\n />\n </div>\n </NodeViewWrapper>\n );\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,sBAAsB,EACpC,MACA,kBACA,QACA,QACA,WAC6D;CAC7D,MAAM,WAAW,WAAW,gCAAgC;CAC5D,MAAM,WAAW,uBAAuB;CACxC,MAAM,WACJ,OAAO,KAAK,MAAM,aAAa,WAAW,KAAK,MAAM,WAAW;CAClE,MAAM,mBAAmB,oBAAoB,QAAQ;CACrD,MAAM,gBACJ,eAAe,MAAM,WAAW,OAAO,UAAU,gBAAgB,CAAC,EAAE,SACpE;CAEF,SAAS,cAAc,OAAsC;EAC3D,MAAM,OAAO,QAAQ;EACrB,IACE,CAAC,QACD,EAAE,MAAM,kBAAkB,SAC1B,CAAC,KAAK,WAAW,SAAS,MAAM,MAAM,KACtC,CAAC,YACD,CAAC,OAAO,cACR,KAAK,aACL,MAAM,YAAY,eAClB,MAAM,YAAY,YAAY,KAE9B;EAEF,MAAM,gBAAgB;GACpB,MAAM,eAAe;GACrB,MAAM,gBAAgB;EACxB;EACA,IAAI,SAAS,UAAU,oBAAoB,MAAM,aAAa,IAAI,GAAG;GACnE,QAAQ;GACR,SAAS,OAAO;GAChB;EACF;EACA,KAAK,MAAM,WAAW,MAAM,YAAY,CAAC,MAAM,QAAQ;GACrD,MAAM,MAAM,MAAM,IAAI,YAAY;GAClC,IAAI,QAAQ,OAAO,QAAQ,KAAK;IAC9B,QAAQ;IACR,IAAI,QAAQ,OAAO,MAAM,UAAU,OAAO,SAAS,KAAK;SACnD,OAAO,SAAS,KAAK;IAC1B,QAAQ,iBAAiB;IACzB,OAAO,KAAK,MAAM;GACpB;GACA;EACF;EACA,IAAI,MAAM,QAAQ;EAElB,MAAM,WAAW,OAAO;EACxB,IAAI,aAAa,KAAA,GAAW;EAC5B,MAAM,EAAE,MAAM,UAAU,KAAK,MAAM,UAAU;EAC7C,MAAM,OAAO,KAAK,MAAM;EACxB,IAAI,MAAM,QAAQ,WAAW,MAAM,UAAU;GAC3C,QAAQ;GACR,KAAK,SAAS;IACZ,GAAG,KAAK,MAAM,iBAAiB,IAAI;IACnC,WAAW;GACb,CAAC;GACD;EACF;EACA,IAAI,MAAM,UAAU;EACpB,IACE,MAAM,QAAQ,WACd,SACA,SAAS,KAAK,UACd,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,GAC/B;GACA,QAAQ;GACR,OAAO,SAAS,iBAAiB,OAAO;GACxC,OAAO,KAAK,MAAM;GAClB;EACF;EACA,IAAI,MAAM,QAAQ,eAAe,SAAS,KAAK,WAAW,GAAG;GAC3D,QAAQ;GACR,OAAO,SAAS,aAAa;GAC7B,OAAO,KAAK,MAAM;GAClB;EACF;EACA,IACE,8BAA8B,QAAQ,UAAU,KAAK,OAAO,MAAM,GAAG,GACrE;GACA,QAAQ;GACR,OAAO,KAAK,MAAM;EACpB;CACF;CAEA,OACE,oBAAC,iBAAD;EAAiB,iBAAiB;EAAO,WAAU;EACjD,UAAA,oBAAC,OAAD;GAAK,kBAAkB;GACrB,UAAA,oBAAC,MAAD;IACE,OAAO,KAAK;IACZ,UAAU,oBAAoB;IAC9B,UAAU,CAAC;IACX,SAAQ;IACR,gBAAgB;IAChB,WAAW,GAAG,cAAc;IAC5B,UAAS;IACT,eAAA;IACA,UAAU,QAAQ;IAClB,iBAAiB,SAAS,QAAQ,OAAO,IAAI;IAC7C,SACE,oBAAC,aAAD,EACE,UACE,oBAAC,oBAAD;KACE,OAAO;KACP,WAAW,UAAU;MACnB,IAAI,YAAY,OAAO,YAAY;OACjC,iBAAiB,EACf,UAAU,UAAU,cAAc,KAAK,MACzC,CAAC;OACD,4BAA4B,QAAQ,MAAM,CAAC;MAC7C;KACF;KACA,UAAU,CAAC;IACZ,CAAA,EAEJ,CAAA;GAEJ,CAAA;EACE,CAAA;CACU,CAAA;AAErB"}
@@ -0,0 +1,15 @@
1
+ import { type RefObject } from 'react';
2
+ export interface ChatComposerContextValue {
3
+ disabled: boolean;
4
+ canSubmit: boolean;
5
+ action: 'send' | 'sending' | 'stop';
6
+ submit?: () => void;
7
+ onStop?: () => void;
8
+ onFilesSelected?: (files: File[]) => void;
9
+ /** Set by ChatComposerInput; returns false when the input cannot take focus. */
10
+ inputFocusRef?: RefObject<(() => boolean) | null>;
11
+ }
12
+ export declare const ChatComposerContext: import("react").Context<ChatComposerContextValue | null>;
13
+ export declare const ChatComposerInputEditableContext: import("react").Context<boolean>;
14
+ export declare function useChatComposerContext(): ChatComposerContextValue;
15
+ export declare function isComposerSubmitKey(event: KeyboardEvent, multiline?: boolean): boolean;
@@ -0,0 +1,16 @@
1
+ import { createContext, useContext } from "react";
2
+ //#region packages/components/src/components/ChatComposer/ChatComposerContext.ts
3
+ var ChatComposerContext = createContext(null);
4
+ var ChatComposerInputEditableContext = createContext(false);
5
+ function useChatComposerContext() {
6
+ const context = useContext(ChatComposerContext);
7
+ if (!context) throw new Error("ChatComposer parts must be inside a ChatComposer.");
8
+ return context;
9
+ }
10
+ function isComposerSubmitKey(event, multiline = false) {
11
+ return event.key === "Enter" && !event.shiftKey && !event.altKey && !event.isComposing && event.keyCode !== 229 && (!multiline || event.metaKey || event.ctrlKey);
12
+ }
13
+ //#endregion
14
+ export { ChatComposerContext, ChatComposerInputEditableContext, isComposerSubmitKey, useChatComposerContext };
15
+
16
+ //# sourceMappingURL=ChatComposerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatComposerContext.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposerContext.ts"],"sourcesContent":["import { createContext, useContext, type RefObject } from 'react';\n\nexport interface ChatComposerContextValue {\n disabled: boolean;\n canSubmit: boolean;\n action: 'send' | 'sending' | 'stop';\n submit?: () => void;\n onStop?: () => void;\n onFilesSelected?: (files: File[]) => void;\n /** Set by ChatComposerInput; returns false when the input cannot take focus. */\n inputFocusRef?: RefObject<(() => boolean) | null>;\n}\n\nexport const ChatComposerContext =\n createContext<ChatComposerContextValue | null>(null);\n\n// Node views render through portals and need input-level editability updates.\nexport const ChatComposerInputEditableContext = createContext(false);\n\nexport function useChatComposerContext() {\n const context = useContext(ChatComposerContext);\n if (!context) {\n throw new Error('ChatComposer parts must be inside a ChatComposer.');\n }\n return context;\n}\n\nexport function isComposerSubmitKey(event: KeyboardEvent, multiline = false) {\n return (\n event.key === 'Enter' &&\n !event.shiftKey &&\n !event.altKey &&\n !event.isComposing &&\n // Safari can end composition before dispatching the confirming Enter.\n event.keyCode !== 229 &&\n (!multiline || event.metaKey || event.ctrlKey)\n );\n}\n"],"mappings":";;AAaA,IAAa,sBACX,cAA+C,IAAI;AAGrD,IAAa,mCAAmC,cAAc,KAAK;AAEnE,SAAgB,yBAAyB;CACvC,MAAM,UAAU,WAAW,mBAAmB;CAC9C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;AACT;AAEA,SAAgB,oBAAoB,OAAsB,YAAY,OAAO;CAC3E,OACE,MAAM,QAAQ,WACd,CAAC,MAAM,YACP,CAAC,MAAM,UACP,CAAC,MAAM,eAEP,MAAM,YAAY,QACjB,CAAC,aAAa,MAAM,WAAW,MAAM;AAE1C"}
@@ -0,0 +1,19 @@
1
+ import { type Ref } from 'react';
2
+ export interface ChatComposerInputHandle {
3
+ focus: () => void;
4
+ }
5
+ export interface ChatComposerInputProps {
6
+ ref?: Ref<ChatComposerInputHandle>;
7
+ value: string;
8
+ onChange: (value: string) => void;
9
+ placeholder?: string;
10
+ disabled?: boolean;
11
+ readOnly?: boolean;
12
+ autoFocus?: boolean;
13
+ minHeight?: number;
14
+ maxHeight?: number;
15
+ className?: string;
16
+ 'aria-label'?: string;
17
+ 'aria-describedby'?: string;
18
+ }
19
+ export declare function ChatComposerInput({ minHeight, maxHeight, ...props }: ChatComposerInputProps): import("react").JSX.Element;
@@ -0,0 +1,38 @@
1
+ import { cn } from "../../utils/cn.js";
2
+ import { Skeleton } from "../Skeleton/Skeleton.js";
3
+ import { ErrorBoundary } from "../ErrorBoundary.js";
4
+ import { ChatComposerPlainInput } from "./ChatComposerPlainInput.js";
5
+ import { Suspense, lazy } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ //#region packages/components/src/components/ChatComposer/ChatComposerInput.tsx
8
+ var RichInput = lazy(() => import("./ChatComposerRichInput.js").then((module) => ({ default: module.ChatComposerRichInput })));
9
+ function ChatComposerInput({ minHeight = 40, maxHeight = 240, ...props }) {
10
+ return /* @__PURE__ */ jsx(ErrorBoundary, {
11
+ fallback: () => /* @__PURE__ */ jsx(ChatComposerPlainInput, {
12
+ ...props,
13
+ minHeight,
14
+ maxHeight
15
+ }),
16
+ children: /* @__PURE__ */ jsx(Suspense, {
17
+ fallback: /* @__PURE__ */ jsx("div", {
18
+ className: cn("flex flex-col justify-center overflow-hidden px-space-1", props.className),
19
+ style: {
20
+ minHeight,
21
+ maxHeight
22
+ },
23
+ role: "status",
24
+ "aria-label": "Loading message editor",
25
+ children: /* @__PURE__ */ jsx(Skeleton, { className: "w-2/3" })
26
+ }),
27
+ children: /* @__PURE__ */ jsx(RichInput, {
28
+ ...props,
29
+ minHeight,
30
+ maxHeight
31
+ })
32
+ })
33
+ });
34
+ }
35
+ //#endregion
36
+ export { ChatComposerInput };
37
+
38
+ //# sourceMappingURL=ChatComposerInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatComposerInput.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposerInput.tsx"],"sourcesContent":["import { lazy, Suspense, type Ref } from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { ErrorBoundary } from '../ErrorBoundary';\nimport { Skeleton } from '../Skeleton';\nimport { ChatComposerPlainInput } from './ChatComposerPlainInput';\n\nconst RichInput = lazy(() =>\n import('./ChatComposerRichInput').then((module) => ({\n default: module.ChatComposerRichInput,\n }))\n);\n\nexport interface ChatComposerInputHandle {\n focus: () => void;\n}\n\nexport interface ChatComposerInputProps {\n ref?: Ref<ChatComposerInputHandle>;\n value: string;\n onChange: (value: string) => void;\n placeholder?: string;\n disabled?: boolean;\n readOnly?: boolean;\n autoFocus?: boolean;\n minHeight?: number;\n maxHeight?: number;\n className?: string;\n 'aria-label'?: string;\n 'aria-describedby'?: string;\n}\n\nexport function ChatComposerInput({\n minHeight = 40,\n maxHeight = 240,\n ...props\n}: ChatComposerInputProps) {\n return (\n // A failed editor load or render falls back to plain text so the message\n // can still be written and sent. React caches a rejected lazy import, so a\n // retry would not reload it; the fallback stays until the page reloads.\n <ErrorBoundary\n fallback={() => (\n <ChatComposerPlainInput\n {...props}\n minHeight={minHeight}\n maxHeight={maxHeight}\n />\n )}\n >\n <Suspense\n fallback={\n <div\n className={cn(\n 'flex flex-col justify-center overflow-hidden px-space-1',\n props.className\n )}\n style={{ minHeight, maxHeight }}\n role=\"status\"\n aria-label=\"Loading message editor\"\n >\n <Skeleton className=\"w-2/3\" />\n </div>\n }\n >\n <RichInput {...props} minHeight={minHeight} maxHeight={maxHeight} />\n </Suspense>\n </ErrorBoundary>\n );\n}\n"],"mappings":";;;;;;;AAOA,IAAM,YAAY,WAChB,OAAO,6BAA0B,CAAC,MAAM,YAAY,EAClD,SAAS,OAAO,sBAClB,EAAE,CACJ;AAqBA,SAAgB,kBAAkB,EAChC,YAAY,IACZ,YAAY,KACZ,GAAG,SACsB;CACzB,OAIE,oBAAC,eAAD;EACE,gBACE,oBAAC,wBAAD;GACE,GAAI;GACO;GACA;EACZ,CAAA;EAGH,UAAA,oBAAC,UAAD;GACE,UACE,oBAAC,OAAD;IACE,WAAW,GACT,2DACA,MAAM,SACR;IACA,OAAO;KAAE;KAAW;IAAU;IAC9B,MAAK;IACL,cAAW;IAEX,UAAA,oBAAC,UAAD,EAAU,WAAU,QAAS,CAAA;GAC1B,CAAA;GAGP,UAAA,oBAAC,WAAD;IAAW,GAAI;IAAkB;IAAsB;GAAY,CAAA;EAC3D,CAAA;CACG,CAAA;AAEnB"}
@@ -0,0 +1,3 @@
1
+ import type { SelectProps } from '../Select/index.js';
2
+ export type ChatComposerModelSelectProps<T extends string = string> = SelectProps<T>;
3
+ export declare function ChatComposerModelSelect<T extends string>({ disabled, triggerClassName, renderValue, placeholder, size, onChange, onCloseAutoFocus, ...props }: ChatComposerModelSelectProps<T>): import("react").JSX.Element;
@@ -0,0 +1,56 @@
1
+ import { cn } from "../../utils/cn.js";
2
+ import { Text } from "../Text/Text.js";
3
+ import { useChatComposerContext } from "./ChatComposerContext.js";
4
+ import { Select } from "../Select/Select.js";
5
+ import { useRef } from "react";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ //#region packages/components/src/components/ChatComposer/ChatComposerModelSelect.tsx
8
+ function ChatComposerModelSelect({ disabled, triggerClassName, renderValue, placeholder = "Select...", size = "sm", onChange, onCloseAutoFocus, ...props }) {
9
+ const composer = useChatComposerContext();
10
+ const choseModel = useRef(false);
11
+ return /* @__PURE__ */ jsx("div", {
12
+ className: "flex min-w-0 max-w-full items-center",
13
+ children: /* @__PURE__ */ jsx(Select, {
14
+ "aria-label": "Model",
15
+ size,
16
+ side: "top",
17
+ hideSearch: false,
18
+ searchPlaceholder: "Search models…",
19
+ ...props,
20
+ placeholder,
21
+ renderValue: (option) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Text, {
22
+ as: "span",
23
+ variant: size === "lg" ? "md" : size,
24
+ weight: "normal",
25
+ className: "inline-block shrink-0 @[440px]/composer:hidden",
26
+ children: "Model"
27
+ }), /* @__PURE__ */ jsx("span", {
28
+ className: "hidden min-w-0 truncate text-left @[440px]/composer:block",
29
+ children: renderValue ? renderValue(option) : /* @__PURE__ */ jsx(Text, {
30
+ as: "span",
31
+ variant: size === "lg" ? "md" : size,
32
+ weight: "normal",
33
+ children: option.label ?? option.value
34
+ })
35
+ })] }),
36
+ disabled: composer.disabled || disabled,
37
+ triggerClassName: cn("max-w-full gap-space-1 border-0 bg-transparent px-space-1 shadow-none @[440px]/composer:px-space-2", triggerClassName),
38
+ onChange: (value) => {
39
+ if (composer.disabled || disabled) return;
40
+ choseModel.current = true;
41
+ onChange(value);
42
+ },
43
+ onCloseAutoFocus: (event) => {
44
+ const continueInInput = choseModel.current;
45
+ choseModel.current = false;
46
+ onCloseAutoFocus?.(event);
47
+ if (event.defaultPrevented) return;
48
+ if (continueInInput && composer.inputFocusRef?.current?.()) event.preventDefault();
49
+ }
50
+ })
51
+ });
52
+ }
53
+ //#endregion
54
+ export { ChatComposerModelSelect };
55
+
56
+ //# sourceMappingURL=ChatComposerModelSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatComposerModelSelect.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposerModelSelect.tsx"],"sourcesContent":["import { useRef } from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { Select } from '../Select';\nimport type { SelectProps } from '../Select';\nimport { Text } from '../Text';\nimport { useChatComposerContext } from './ChatComposerContext';\n\nexport type ChatComposerModelSelectProps<T extends string = string> =\n SelectProps<T>;\n\nexport function ChatComposerModelSelect<T extends string>({\n disabled,\n triggerClassName,\n renderValue,\n placeholder = 'Select...',\n size = 'sm',\n onChange,\n onCloseAutoFocus,\n ...props\n}: ChatComposerModelSelectProps<T>) {\n const composer = useChatComposerContext();\n const choseModel = useRef(false);\n\n return (\n <div className=\"flex min-w-0 max-w-full items-center\">\n <Select\n aria-label=\"Model\"\n size={size}\n side=\"top\"\n hideSearch={false}\n searchPlaceholder=\"Search models…\"\n {...props}\n placeholder={placeholder}\n renderValue={(option) => (\n <>\n <Text\n as=\"span\"\n variant={size === 'lg' ? 'md' : size}\n weight=\"normal\"\n className=\"inline-block shrink-0 @[440px]/composer:hidden\"\n >\n Model\n </Text>\n <span className=\"hidden min-w-0 truncate text-left @[440px]/composer:block\">\n {renderValue ? (\n renderValue(option)\n ) : (\n <Text\n as=\"span\"\n variant={size === 'lg' ? 'md' : size}\n weight=\"normal\"\n >\n {option.label ?? option.value}\n </Text>\n )}\n </span>\n </>\n )}\n disabled={composer.disabled || disabled}\n triggerClassName={cn(\n 'max-w-full gap-space-1 border-0 bg-transparent px-space-1 shadow-none @[440px]/composer:px-space-2',\n triggerClassName\n )}\n onChange={(value) => {\n if (composer.disabled || disabled) return;\n choseModel.current = true;\n onChange(value);\n }}\n // After a choice, continue in the message. Escape and outside clicks\n // keep the default.\n onCloseAutoFocus={(event) => {\n const continueInInput = choseModel.current;\n choseModel.current = false;\n onCloseAutoFocus?.(event);\n if (event.defaultPrevented) return;\n if (continueInInput && composer.inputFocusRef?.current?.()) {\n event.preventDefault();\n }\n }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;AAWA,SAAgB,wBAA0C,EACxD,UACA,kBACA,aACA,cAAc,aACd,OAAO,MACP,UACA,kBACA,GAAG,SAC+B;CAClC,MAAM,WAAW,uBAAuB;CACxC,MAAM,aAAa,OAAO,KAAK;CAE/B,OACE,oBAAC,OAAD;EAAK,WAAU;EACb,UAAA,oBAAC,QAAD;GACE,cAAW;GACL;GACN,MAAK;GACL,YAAY;GACZ,mBAAkB;GAClB,GAAI;GACS;GACb,cAAc,WACZ,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,MAAD;IACE,IAAG;IACH,SAAS,SAAS,OAAO,OAAO;IAChC,QAAO;IACP,WAAU;IACX,UAAA;GAEK,CAAA,GACN,oBAAC,QAAD;IAAM,WAAU;IACb,UAAA,cACC,YAAY,MAAM,IAElB,oBAAC,MAAD;KACE,IAAG;KACH,SAAS,SAAS,OAAO,OAAO;KAChC,QAAO;KAEN,UAAA,OAAO,SAAS,OAAO;IACpB,CAAA;GAEJ,CAAA,CACN,EAAA,CAAA;GAEJ,UAAU,SAAS,YAAY;GAC/B,kBAAkB,GAChB,sGACA,gBACF;GACA,WAAW,UAAU;IACnB,IAAI,SAAS,YAAY,UAAU;IACnC,WAAW,UAAU;IACrB,SAAS,KAAK;GAChB;GAGA,mBAAmB,UAAU;IAC3B,MAAM,kBAAkB,WAAW;IACnC,WAAW,UAAU;IACrB,mBAAmB,KAAK;IACxB,IAAI,MAAM,kBAAkB;IAC5B,IAAI,mBAAmB,SAAS,eAAe,UAAU,GACvD,MAAM,eAAe;GAEzB;EACD,CAAA;CACE,CAAA;AAET"}
@@ -0,0 +1,8 @@
1
+ import type { ChatComposerInputProps } from './ChatComposerInput.js';
2
+ interface ChatComposerPlainInputProps extends ChatComposerInputProps {
3
+ minHeight: number;
4
+ maxHeight: number;
5
+ }
6
+ /** Keeps the composer usable with plain Markdown text when the rich editor fails. */
7
+ export declare function ChatComposerPlainInput({ ref, value, onChange, placeholder, disabled, readOnly, autoFocus, minHeight, maxHeight, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }: ChatComposerPlainInputProps): import("react").JSX.Element;
8
+ export {};
@@ -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,WAAW,OAAO,KAAK;CAC7B,MAAM,mBAAmB,OAAO,KAAK;CACrC,MAAM,iBAAiB,OAAO,WAAW;CACzC,MAAM,CAAC,cAAc,iBAAiB,YACnC,aAAqB,WAAW,GACjC,CACF;CACA,MAAM,SAAS,UAAU;EACvB,YAAY;GACV,WAAW,UAAU;IACnB,WAAW;IAEX,MAAM;KAAE,aAAa;KAAO,UAAU;KAAO,aAAa;IAAM;IAGhE,WAAW;GACb,CAAC;GACD;GACA,SAAS,UAAU;IACjB,MAAM;IAGN,QAAQ;IACR,qBAAqB;GACvB,CAAC;GACD,YAAY,UAAU,EAAE,mBAAmB,eAAe,QAAQ,CAAC;GACnE;EACF;EACA,SAAS;EACT,aAAa;GACX,YAAY;IAAE,OAAO,mBAAmB;IAAI,GAAG;GAAiB;GAChE,cAAc,MAAM,UAAU;IAC5B,IAAI,iBAAiB,SAAS,OAAO;IACrC,MAAM,OAAO,MAAM,eAAe,QAAQ,WAAW,KAAK;IAC1D,MAAM,OAAO,MAAM,eAAe,QAAQ,YAAY;IAGtD,IAAI,CAAC,QAAQ,CAAC,eAAe,KAAK,IAAI,GAAG,OAAO;IAEhD,iBAAiB,UAAU;IAC3B,IAAI;KACF,KAAK,UAAU,MAAM,KAAK;IAC5B,UAAU;KACR,iBAAiB,UAAU;IAC7B;IACA,OAAO;GACT;GACA,gBAAgB,MAAM,UAAU;IAC9B,IAAI,CAAC,YAAY,CAAC,YAAY,KAAK,aAAa,MAAM,QAAQ,SAC5D,OAAO;IAET,MAAM,EAAE,OAAO,UAAU,KAAK,MAAM;IACpC,IAAI,YACF,SACA,MAAM,OAAO,KAAK,SAAS,eAC3B,MAAM,iBAAiB,MAAM,OAAO,QAAQ,QAC5C,oBAAoB,KAAK,MAAM,OAAO,WAAW;IACnD,KAAK,IAAI,QAAQ,MAAM,OAAO,QAAQ,GAAG,SACvC,IACE;KAAC;KAAa;KAAY;IAAY,CAAC,CAAC,SACtC,MAAM,KAAK,KAAK,CAAC,CAAC,KAAK,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",