@copilotkit/react-textarea 0.29.0-alpha.1 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +428 -428
- package/CHANGELOG.md +16 -0
- package/dist/{chunk-BBZ7AWOB.mjs → chunk-4H2O7MYQ.mjs} +2 -2
- package/dist/{chunk-AZHILHKM.mjs → chunk-DKE57EAC.mjs} +2 -2
- package/dist/{chunk-VB4VNCIQ.mjs → chunk-K7GVTNZU.mjs} +8 -1
- package/dist/chunk-K7GVTNZU.mjs.map +1 -0
- package/dist/{chunk-FP2EKU3L.mjs → chunk-LCDTIJSD.mjs} +3 -3
- package/dist/{chunk-FP2EKU3L.mjs.map → chunk-LCDTIJSD.mjs.map} +1 -1
- package/dist/{chunk-SNQEBH5I.mjs → chunk-PXALH4EC.mjs} +3 -3
- package/dist/{chunk-5J3UZV77.mjs → chunk-W3TDW7EW.mjs} +2 -2
- package/dist/{chunk-B6TKVDDY.mjs → chunk-WGFQTPTF.mjs} +5 -4
- package/dist/chunk-WGFQTPTF.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +67 -62
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +5 -5
- package/dist/components/copilot-textarea/copilot-textarea.js +67 -62
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +7 -7
- package/dist/components/hovering-toolbar/hovering-toolbar.js +59 -55
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +3 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +46 -32
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +2 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +49 -35
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +3 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +49 -35
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +3 -2
- package/dist/components/index.js +67 -62
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +7 -7
- package/dist/index.js +67 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/types/autosuggestions-config/autosuggestions-config.js +2 -2
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
- package/dist/types/autosuggestions-config/index.js +2 -2
- package/dist/types/autosuggestions-config/index.js.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +2 -2
- package/dist/types/base/base-autosuggestions-config.d.ts +1 -1
- package/dist/types/base/base-autosuggestions-config.js +2 -2
- package/dist/types/base/base-autosuggestions-config.js.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +1 -1
- package/dist/types/base/base-copilot-textarea-props.d.ts +1 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -1
- package/dist/types/base/index.js +2 -2
- package/dist/types/base/index.js.map +1 -1
- package/dist/types/base/index.mjs +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -2
- package/package.json +6 -6
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +3 -1
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +6 -0
- package/src/types/base/base-autosuggestions-config.tsx +6 -2
- package/src/types/base/base-copilot-textarea-props.tsx +1 -0
- package/dist/chunk-B6TKVDDY.mjs.map +0 -1
- package/dist/chunk-VB4VNCIQ.mjs.map +0 -1
- /package/dist/{chunk-BBZ7AWOB.mjs.map → chunk-4H2O7MYQ.mjs.map} +0 -0
- /package/dist/{chunk-AZHILHKM.mjs.map → chunk-DKE57EAC.mjs.map} +0 -0
- /package/dist/{chunk-SNQEBH5I.mjs.map → chunk-PXALH4EC.mjs.map} +0 -0
- /package/dist/{chunk-5J3UZV77.mjs.map → chunk-W3TDW7EW.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 0.29.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- node CopilotBackend support
|
|
8
|
+
- 58a8524: clean node example impl
|
|
9
|
+
- a34a226: node-native backend support
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- Updated dependencies [58a8524]
|
|
15
|
+
- Updated dependencies [a34a226]
|
|
16
|
+
- @copilotkit/react-core@0.19.0
|
|
17
|
+
- @copilotkit/shared@0.3.0
|
|
18
|
+
|
|
3
19
|
## 0.29.0-alpha.1
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HoveringInsertionPromptBoxCore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-K7GVTNZU.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -28,4 +28,4 @@ var HoveringInsertionPromptBox = (props) => {
|
|
|
28
28
|
export {
|
|
29
29
|
HoveringInsertionPromptBox
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-4H2O7MYQ.mjs.map
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./chunk-KDVMG3XF.mjs";
|
|
10
10
|
import {
|
|
11
11
|
defaultBaseAutosuggestionsConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-LCDTIJSD.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__spreadProps,
|
|
15
15
|
__spreadValues
|
|
@@ -29,4 +29,4 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
|
|
|
29
29
|
export {
|
|
30
30
|
defaultAutosuggestionsConfig
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-DKE57EAC.mjs.map
|
|
@@ -10,6 +10,9 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
Label
|
|
12
12
|
} from "./chunk-KFQZHRPJ.mjs";
|
|
13
|
+
import {
|
|
14
|
+
useHoveringEditorContext
|
|
15
|
+
} from "./chunk-LYB4B6MK.mjs";
|
|
13
16
|
import {
|
|
14
17
|
SourceSearchBox
|
|
15
18
|
} from "./chunk-FJNUPSQK.mjs";
|
|
@@ -119,6 +122,7 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
119
122
|
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
120
123
|
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
121
124
|
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
125
|
+
const { setIsDisplayed } = useHoveringEditorContext();
|
|
122
126
|
const AdjustmentPromptComponent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
123
127
|
/* @__PURE__ */ jsx(Label, { className: "", children: adjustmentLabel }),
|
|
124
128
|
/* @__PURE__ */ jsxs("div", { className: "relative w-full flex items-center", children: [
|
|
@@ -136,6 +140,9 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
136
140
|
} else if (e.key === "Enter") {
|
|
137
141
|
e.preventDefault();
|
|
138
142
|
beginGeneratingAdjustment();
|
|
143
|
+
} else if (e.key == "Escape") {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
setIsDisplayed(false);
|
|
139
146
|
}
|
|
140
147
|
},
|
|
141
148
|
placeholder,
|
|
@@ -217,4 +224,4 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
217
224
|
export {
|
|
218
225
|
HoveringInsertionPromptBoxCore
|
|
219
226
|
};
|
|
220
|
-
//# sourceMappingURL=chunk-
|
|
227
|
+
//# sourceMappingURL=chunk-K7GVTNZU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx"],"sourcesContent":["import useAutosizeTextArea from \"../../../hooks/misc/use-autosize-textarea\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../../types/base/autosuggestions-bare-function\";\nimport { SourceSearchBox } from \"../../source-search-box/source-search-box\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { Button } from \"../../ui/button\";\nimport { Label } from \"../../ui/label\";\nimport { useCallback, useContext, useEffect, useRef, useState } from \"react\";\n\nimport { streamPromiseFlatten } from \"../../../lib/stream-promise-flatten\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { IncludedFilesPreview } from \"./included-files-preview\";\nimport { useHoveringEditorContext } from \"../hovering-editor-provider\";\n\nexport type SuggestionState = {\n editorState: EditingEditorState;\n};\n\nexport interface HoveringInsertionPromptBoxCoreProps {\n state: SuggestionState;\n performInsertion: (insertedText: string) => void;\n insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBoxCore = ({\n performInsertion,\n state,\n insertionOrEditingFunction,\n contextCategories,\n}: HoveringInsertionPromptBoxCoreProps) => {\n const { getDocumentsContext } = useContext(CopilotContext);\n\n const [editSuggestion, setEditSuggestion] = useState<string>(\"\");\n const [suggestionIsLoading, setSuggestionIsLoading] = useState<boolean>(false);\n\n const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>(\"\");\n\n const [generatingSuggestion, setGeneratingSuggestion] = useState<ReadableStream<string> | null>(\n null,\n );\n\n const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);\n const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [filePointers, setFilePointers] = useState<DocumentPointer[]>([]);\n\n const [suggestedFiles, setSuggestedFiles] = useState<DocumentPointer[]>([]);\n useEffect(() => {\n setSuggestedFiles(getDocumentsContext(contextCategories));\n }, [contextCategories, getDocumentsContext]);\n\n useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || \"\");\n useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || \"\");\n\n // initially focus on the adjustment prompt text area\n useEffect(() => {\n // Focus in the next tick, making sure the adjustment prompt text area is rendered\n // TODO: This happens in Safari, but not in Chrome. Need to look further into this,\n // because focus() should not throw IndexSizeError.\n // this fixes https://github.com/CopilotKit/CopilotKit/issues/171\n setTimeout(() => {\n adjustmentTextAreaRef.current?.focus();\n }, 0);\n }, []);\n\n // continuously read the generating suggestion stream and update the edit suggestion\n useEffect(() => {\n // if no generating suggestion, do nothing\n if (!generatingSuggestion) {\n return;\n }\n\n // Check if the stream is already locked (i.e. already reading from it)\n if (generatingSuggestion.locked) {\n return;\n }\n\n // reset the edit suggestion\n setEditSuggestion(\"\");\n\n // read the generating suggestion stream and continuously update the edit suggestion\n const reader = generatingSuggestion.getReader();\n const read = async () => {\n setSuggestionIsLoading(true);\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n setEditSuggestion((prev) => {\n const newSuggestion = prev + value;\n\n // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.\n if (suggestionTextAreaRef.current) {\n suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;\n }\n return newSuggestion;\n });\n }\n\n setSuggestionIsLoading(false);\n };\n read();\n\n return () => {\n // release the lock if the reader is not closed on unmount\n const releaseLockIfNotClosed = async () => {\n try {\n await reader.closed;\n } catch {\n reader.releaseLock();\n }\n };\n\n releaseLockIfNotClosed();\n };\n }, [generatingSuggestion]);\n\n // generate an adjustment to the completed text, based on the adjustment prompt\n const beginGeneratingAdjustment = useCallback(async () => {\n // don't generate text if the prompt is empty\n if (!adjustmentPrompt.trim()) {\n return;\n }\n\n // editor state includes the text being edited, and the text before/after the selection\n // if the current edit suggestion is not empty, then use *it* as the \"selected text\" - instead of the editor state's selected text\n let modificationState = state.editorState;\n if (editSuggestion !== \"\") {\n modificationState.selectedText = editSuggestion;\n }\n\n // generate the adjustment suggestion\n const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(\n modificationState,\n adjustmentPrompt,\n filePointers,\n new AbortController().signal,\n );\n const adjustmentSuggestionTextStream = streamPromiseFlatten(\n adjustmentSuggestionTextStreamPromise,\n );\n\n setGeneratingSuggestion(adjustmentSuggestionTextStream);\n }, [\n adjustmentPrompt,\n editSuggestion,\n state.editorState,\n insertionOrEditingFunction,\n filePointers,\n ]);\n\n const isLoading = suggestionIsLoading;\n\n const textToEdit = editSuggestion || state.editorState.selectedText;\n const adjustmentLabel =\n textToEdit === \"\"\n ? \"Describe the text you want to insert\"\n : \"Describe adjustments to the suggested text\";\n const placeholder =\n textToEdit === \"\"\n ? \"e.g. 'summarize the client's top 3 pain-points from @CallTranscript'\"\n : \"e.g. 'make it more formal', 'be more specific', ...\";\n\n const { setIsDisplayed } = useHoveringEditorContext();\n\n const AdjustmentPromptComponent = (\n <>\n <Label className=\"\">{adjustmentLabel}</Label>\n <div className=\"relative w-full flex items-center\">\n <textarea\n disabled={suggestionIsLoading}\n ref={adjustmentTextAreaRef}\n value={adjustmentPrompt}\n onChange={(e) => setAdjustmentPrompt(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && e.shiftKey) {\n e.preventDefault();\n setAdjustmentPrompt(adjustmentPrompt + \"\\n\");\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n beginGeneratingAdjustment();\n } else if (e.key == \"Escape\") {\n e.preventDefault();\n setIsDisplayed(false);\n }\n }}\n placeholder={placeholder}\n style={{ minHeight: \"3rem\" }}\n className=\"w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]\"\n rows={1}\n />\n <button\n onClick={beginGeneratingAdjustment}\n className=\"absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center\"\n >\n <i className=\"material-icons\">arrow_forward</i>\n </button>\n </div>\n </>\n );\n\n const SuggestionComponent = (\n <>\n <div className=\"flex justify-between items-end w-full\">\n <Label className=\"mt-4\">Suggested:</Label>\n <div className=\"ml-auto\">\n {isLoading && (\n <div className=\"flex justify-center items-center\">\n <div\n className=\"inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]\"\n role=\"status\"\n >\n <span className=\"!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]\">\n Loading...\n </span>\n </div>\n </div>\n )}\n </div>\n </div>\n <textarea\n ref={suggestionTextAreaRef}\n value={editSuggestion}\n disabled={suggestionIsLoading}\n onChange={(e) => setEditSuggestion(e.target.value)}\n className=\"w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50\"\n style={{ overflow: \"auto\", maxHeight: \"10em\" }}\n />\n </>\n );\n\n const SubmitComponent = (\n <div className=\"flex w-full gap-4 justify-start\">\n <Button\n className=\" bg-green-700 text-white\"\n onClick={() => {\n performInsertion(editSuggestion);\n }}\n >\n Insert <i className=\"material-icons\">check</i>\n </Button>\n </div>\n );\n\n // show source search if the last word in the adjustment prompt BEGINS with an @\n const sourceSearchCandidate = adjustmentPrompt.split(\" \").pop();\n // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined\n const sourceSearchWord = sourceSearchCandidate?.startsWith(\"@\")\n ? sourceSearchCandidate.slice(1)\n : undefined;\n\n return (\n <div className=\"w-full flex flex-col items-start relative gap-2\">\n {AdjustmentPromptComponent}\n {filePointers.length > 0 && (\n <IncludedFilesPreview includedFiles={filePointers} setIncludedFiles={setFilePointers} />\n )}\n {sourceSearchWord !== undefined && (\n <SourceSearchBox\n searchTerm={sourceSearchWord}\n suggestedFiles={suggestedFiles}\n onSelectedFile={(filePointer) => {\n setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), \"\"));\n setFilePointers((prev) => [...prev, filePointer]);\n\n // focus back on the adjustment prompt, and move the cursor to the end\n adjustmentTextAreaRef.current?.focus();\n }}\n />\n )}\n {generatingSuggestion ? SuggestionComponent : null}\n {generatingSuggestion ? SubmitComponent : null}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AASA,SAAS,aAAa,YAAY,WAAW,QAAQ,gBAAgB;AAGrE,SAAS,sBAAsB;AA8J3B,mBACE,KACA,YAFF;AA/IG,IAAM,iCAAiC,CAAC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA2C;AACzC,QAAM,EAAE,oBAAoB,IAAI,WAAW,cAAc;AAEzD,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAiB,EAAE;AAC/D,QAAM,CAAC,qBAAqB,sBAAsB,IAAI,SAAkB,KAAK;AAE7E,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAiB,EAAE;AAEnE,QAAM,CAAC,sBAAsB,uBAAuB,IAAI;AAAA,IACtD;AAAA,EACF;AAEA,QAAM,wBAAwB,OAA4B,IAAI;AAC9D,QAAM,wBAAwB,OAA4B,IAAI;AAE9D,QAAM,CAAC,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BAAmB,GAAG,EAAE,CAAC;AACrF,0BAAgB,CAAC,SAAS,CAAC,GAAG,MAAM,WAAW,CAAC;AAGhD,sCAAsB,YAAtB,mBAA+B;AAAA,QACjC;AAAA;AAAA,IACF;AAAA,IAED,uBAAuB,sBAAsB;AAAA,IAC7C,uBAAuB,kBAAkB;AAAA,KAC5C;AAEJ;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/types/base/base-autosuggestions-config.tsx
|
|
2
2
|
import { defaultCopilotContextCategories } from "@copilotkit/react-core";
|
|
3
|
-
var defaultShouldToggleHoveringEditorOnKeyPress = (event) => {
|
|
4
|
-
if (event.key ===
|
|
3
|
+
var defaultShouldToggleHoveringEditorOnKeyPress = (event, shortcut) => {
|
|
4
|
+
if (event.key === shortcut && event.metaKey) {
|
|
5
5
|
return true;
|
|
6
6
|
}
|
|
7
7
|
return false;
|
|
@@ -25,4 +25,4 @@ var defaultBaseAutosuggestionsConfig = {
|
|
|
25
25
|
export {
|
|
26
26
|
defaultBaseAutosuggestionsConfig
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-LCDTIJSD.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/base/base-autosuggestions-config.tsx"],"sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement
|
|
1
|
+
{"version":3,"sources":["../src/types/base/base-autosuggestions-config.tsx"],"sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n ) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === shortcut && event.metaKey) {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n};\n"],"mappings":";AACA,SAAS,uCAAuC;AA4DhD,IAAM,8CAA8C,CAClD,OACA,aACG;AAEH,MAAI,MAAM,QAAQ,YAAY,MAAM,SAAS;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAcO,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AAAA,EACvD,sCAAsC;AAAA,EACtC,sCAAsC;AACxC;","names":[]}
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
} from "./chunk-QCPS6IYI.mjs";
|
|
7
7
|
import {
|
|
8
8
|
defaultAutosuggestionsConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-DKE57EAC.mjs";
|
|
10
10
|
import {
|
|
11
11
|
BaseCopilotTextarea
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WGFQTPTF.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__objRest,
|
|
15
15
|
__spreadProps,
|
|
@@ -57,4 +57,4 @@ var CopilotTextarea = React.forwardRef(
|
|
|
57
57
|
export {
|
|
58
58
|
CopilotTextarea
|
|
59
59
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-PXALH4EC.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HoveringInsertionPromptBox
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4H2O7MYQ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useHoveringEditorContext
|
|
6
6
|
} from "./chunk-LYB4B6MK.mjs";
|
|
@@ -121,4 +121,4 @@ function editorState(editor, selection) {
|
|
|
121
121
|
export {
|
|
122
122
|
HoveringToolbar
|
|
123
123
|
};
|
|
124
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-W3TDW7EW.mjs.map
|
|
@@ -24,14 +24,14 @@ import {
|
|
|
24
24
|
} from "./chunk-7LSRNPNI.mjs";
|
|
25
25
|
import {
|
|
26
26
|
HoveringToolbar
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-W3TDW7EW.mjs";
|
|
28
28
|
import {
|
|
29
29
|
HoveringEditorProvider,
|
|
30
30
|
useHoveringEditorContext
|
|
31
31
|
} from "./chunk-LYB4B6MK.mjs";
|
|
32
32
|
import {
|
|
33
33
|
defaultBaseAutosuggestionsConfig
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-LCDTIJSD.mjs";
|
|
35
35
|
import {
|
|
36
36
|
makeRenderElementFunction
|
|
37
37
|
} from "./chunk-224UKA7C.mjs";
|
|
@@ -106,7 +106,8 @@ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
|
|
|
106
106
|
);
|
|
107
107
|
const onKeyDownHandlerForHoveringEditor = useCallback(
|
|
108
108
|
(event) => {
|
|
109
|
-
|
|
109
|
+
var _a2;
|
|
110
|
+
if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, (_a2 = props.shortcut) != null ? _a2 : "k")) {
|
|
110
111
|
event.preventDefault();
|
|
111
112
|
setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
|
|
112
113
|
}
|
|
@@ -250,4 +251,4 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
|
|
|
250
251
|
export {
|
|
251
252
|
BaseCopilotTextarea
|
|
252
253
|
};
|
|
253
|
-
//# sourceMappingURL=chunk-
|
|
254
|
+
//# sourceMappingURL=chunk-WGFQTPTF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Descendant, Editor } from \"slate\";\nimport { Editable, Slate } from \"slate-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { useAutosuggestions } from \"../../hooks/base-copilot-textarea-implementation/use-autosuggestions\";\nimport { useCopilotTextareaEditor } from \"../../hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor\";\nimport { usePopulateCopilotTextareaRef } from \"../../hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundCollapsedCursor,\n} from \"../../lib/get-text-around-cursor\";\nimport { addAutocompletionsToEditor } from \"../../lib/slatejs-edits/add-autocompletions\";\nimport { clearAutocompletionsFromEditor } from \"../../lib/slatejs-edits/clear-autocompletions\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport \"./base-copilot-textarea.css\";\nimport { HoveringToolbar } from \"../hovering-toolbar/hovering-toolbar\";\nimport { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\nimport {\n HoveringEditorProvider,\n useHoveringEditorContext,\n} from \"../hovering-toolbar/hovering-editor-provider\";\nimport { TrackerTextEditedSinceLastCursorMovement } from \"./track-cursor-moved-since-last-text-change\";\n\n/**\n * Purpose: to be used as the `ref` type for `CopilotTextarea` and `BaseCopilotTextarea`.\n *\n * This interface extends `HTMLElement`, and is the subset of `HTMLTextAreaElement` that \"actually matters\".\n * It provides the core functionality that consumers of `HTMLTextAreaElement` need 99.9% of the time:\n * - `value`: the current value of the textarea\n * - `focus`: make the textarea focused\n * - `blur`: make the textarea unfocused\n */\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n /**\n * The current value of the textarea.\n */\n value: string;\n\n /**\n * focus on the textarea\n */\n focus: () => void;\n\n /**\n * unfocus the textarea.\n *\n * Called `blur` for syntactic compatibility with `HTMLTextAreaElement`.\n */\n blur: () => void;\n}\n\n/**\n * Not intended for direct use. Use CopilotTextarea instead.\n *\n * The `BaseCopilotTextarea` includes the basic UX component,\n * without the business logic / AI logic that makes the content useful and coherent.\n *\n * It is useful if you want to build your own backend, with fully custom business logic\n * for figuring out which contnet to fill in.\n */\nexport const BaseCopilotTextarea = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {\n return (\n <HoveringEditorProvider>\n <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />\n </HoveringEditorProvider>\n );\n },\n);\n\n/**\n * Not intended for direct use. Use `CopilotTextarea` instead.\n *\n * This is the private core of the `BaseCopilotTextarea` component.\n * For practical purposes the implementation is cleaner assuming containment in a `HoveringEditorProviderContext`.\n *\n * Therefore we separate the core logic into this component,\n * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.\n */\nconst BaseCopilotTextareaWithHoveringContext = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.baseAutosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);\n const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);\n\n // // When the editor text changes, we want to reset the `textEditedSinceLastCursorMovement` state.\n // useEffect(() => {\n // setCursorMovedSinceLastTextChange(false);\n // }, [lastKnownFullEditorText]);\n\n const initialValue: Descendant[] = useMemo(() => {\n return [\n {\n type: \"paragraph\",\n children: [{ text: valueOnInitialRender }],\n },\n ];\n }, [valueOnInitialRender]);\n\n const editor = useCopilotTextareaEditor();\n\n const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } =\n useHoveringEditorContext();\n\n const insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor],\n );\n\n const shouldDisableAutosuggestions =\n // textarea is manually disabled:\n autosuggestionsConfig.disabled ||\n // hovering editor is displayed:\n hoveringEditorIsDisplayed ||\n // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:\n (cursorMovedSinceLastTextChange &&\n autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText);\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,\n autosuggestionsConfig.apiConfig.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n shouldDisableAutosuggestions,\n );\n\n const onKeyDownHandlerForHoveringEditor = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, props.shortcut ?? \"k\")\n ) {\n event.preventDefault();\n setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);\n }\n },\n [\n hoveringEditorIsDisplayed,\n setHoveringEditorIsDisplayed,\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress,\n ],\n );\n\n // sync autosuggestions state with the editor\n useEffect(() => {\n clearAutocompletionsFromEditor(editor);\n if (currentAutocompleteSuggestion) {\n addAutocompletionsToEditor(\n editor,\n currentAutocompleteSuggestion.text,\n currentAutocompleteSuggestion.point,\n );\n }\n }, [currentAutocompleteSuggestion]);\n\n const suggestionStyleAugmented: React.CSSProperties = useMemo(() => {\n return {\n fontStyle: \"italic\",\n color: \"gray\",\n ...props.suggestionsStyle,\n };\n }, [props.suggestionsStyle]);\n\n const renderElementMemoized = useMemo(() => {\n return makeRenderElementFunction(suggestionStyleAugmented);\n }, [suggestionStyleAugmented]);\n\n const renderPlaceholderMemoized = useMemo(() => {\n // For some reason slateJS specifies a top value of 0, which makes for strange styling. We override this here.\n const placeholderStyleSlatejsOverrides: React.CSSProperties = {\n top: undefined,\n };\n\n const placeholderStyleAugmented: React.CSSProperties = {\n ...placeholderStyleSlatejsOverrides,\n ...props.placeholderStyle,\n };\n\n return makeRenderPlaceholderFunction(placeholderStyleAugmented);\n }, [props.placeholderStyle]);\n\n // update the editor text, but only when the value changes from outside the component\n useEffect(() => {\n if (props.value === lastKnownFullEditorText) {\n return;\n }\n\n setLastKnownFullEditorText(props.value ?? \"\");\n replaceEditorText(editor, props.value ?? \"\");\n }, [props.value]);\n\n // separate into TextareaHTMLAttributes<HTMLDivElement> and CopilotTextareaProps\n const {\n placeholderStyle,\n value,\n hoverMenuClassname,\n onValueChange,\n baseAutosuggestionsConfig: autosuggestionsConfigFromProps,\n className,\n onChange,\n onKeyDown,\n disableBranding,\n ...propsToForward\n } = props;\n\n useAddBrandingCss(suggestionStyleAugmented, disableBranding);\n usePopulateCopilotTextareaRef(editor, ref);\n\n const moddedClassName = (() => {\n const baseClassName = \"copilot-textarea\";\n const brandingClass = disableBranding ? \"no-branding\" : \"with-branding\";\n const defaultTailwindClassName = \"bg-white overflow-y-auto resize-y\";\n const mergedClassName = twMerge(defaultTailwindClassName, className ?? \"\");\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCollapsedCursor(editor);\n\n const fullEditorText = newEditorState\n ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor\n : getFullEditorTextWithNewlines(editor); // we don't double-parse the editor. When `newEditorState` is null, we didn't parse the editor yet.\n\n setLastKnownFullEditorText((prev) => {\n if (prev !== fullEditorText) {\n setCursorMovedSinceLastTextChange(false);\n }\n return fullEditorText;\n });\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <TrackerTextEditedSinceLastCursorMovement\n setCursorMovedSinceLastTextChange={setCursorMovedSinceLastTextChange}\n />\n <HoveringToolbar\n apiConfig={autosuggestionsConfig.apiConfig}\n contextCategories={autosuggestionsConfig.contextCategories}\n hoverMenuClassname={hoverMenuClassname}\n />\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\n onKeyDownHandlerForHoveringEditor(event); // forward the event for internal use\n onKeyDownHandlerForAutocomplete(event); // forward the event for internal use\n props.onKeyDown?.(event); // forward the event for external use\n }}\n className={moddedClassName}\n {...propsToForward}\n />\n </Slate>\n );\n },\n);\n\n// Consumers of <textarea> expect a `onChange: (React.ChangeEvent<HTMLTextAreaElement>) => void` event handler to be passed in.\n// This is *extremely* common, and we want to support it.\n//\n// We can't support the full functionality, but in 99% of cases, the consumer only cares about the `event.target.value` property --\n// that's how they get the new value of the textarea.\n//\n// So, the tradeoff we are making is minimizing compiler complaint, with a small chance of runtime error.\n// The alternative would be defining a different onChange entrypoint (we actually do have that in `onValueChange`),\n// And starting to explain subtleties to users the moment they try to use the component for the first time for very basic functionality.\n//\n// If this proves problematic, we can always revisit this decision.\nfunction makeSemiFakeReactTextAreaEvent(\n currentText: string,\n): React.ChangeEvent<HTMLTextAreaElement> {\n return {\n target: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n currentTarget: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n } as React.ChangeEvent<HTMLTextAreaElement>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAqB,cAAc;AACnC,SAAS,UAAU,aAAa;AAChC,SAAS,eAAe;AAkEhB,cAsKF,YAtKE;AAJD,IAAM,sBAAsB,MAAM;AAAA,EACvC,CAAC,OAAiC,QAA+C;AAC/E,WACE,oBAAC,0BACC,8BAAC,yEAA2C,QAA3C,EAAkD,MAAU,GAC/D;AAAA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AAS,+BACP,aACwC;AACxC,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,eAAe;AAAA,MACb,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["_a","value"]}
|
|
@@ -636,8 +636,8 @@ function clearAutocompletionsFromEditor(editor) {
|
|
|
636
636
|
|
|
637
637
|
// src/types/base/base-autosuggestions-config.tsx
|
|
638
638
|
var import_react_core = require("@copilotkit/react-core");
|
|
639
|
-
var defaultShouldToggleHoveringEditorOnKeyPress = (event) => {
|
|
640
|
-
if (event.key ===
|
|
639
|
+
var defaultShouldToggleHoveringEditorOnKeyPress = (event, shortcut) => {
|
|
640
|
+
if (event.key === shortcut && event.metaKey) {
|
|
641
641
|
return true;
|
|
642
642
|
}
|
|
643
643
|
return false;
|
|
@@ -895,7 +895,7 @@ var Label = React4.forwardRef((_a, ref) => {
|
|
|
895
895
|
Label.displayName = LabelPrimitive.Root.displayName;
|
|
896
896
|
|
|
897
897
|
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
898
|
-
var
|
|
898
|
+
var import_react7 = require("react");
|
|
899
899
|
|
|
900
900
|
// src/lib/stream-promise-flatten.ts
|
|
901
901
|
function streamPromiseFlatten(promise) {
|
|
@@ -966,37 +966,51 @@ var FileChipPreview = ({ filePointer, onDelete }) => {
|
|
|
966
966
|
);
|
|
967
967
|
};
|
|
968
968
|
|
|
969
|
-
// src/components/hovering-toolbar/
|
|
969
|
+
// src/components/hovering-toolbar/hovering-editor-provider.tsx
|
|
970
|
+
var import_react6 = require("react");
|
|
970
971
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
972
|
+
var HoveringEditorContext = (0, import_react6.createContext)({
|
|
973
|
+
isDisplayed: false,
|
|
974
|
+
setIsDisplayed: () => {
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
var HoveringEditorProvider = ({ children }) => {
|
|
978
|
+
const [isDisplayed, setIsDisplayed] = (0, import_react6.useState)(false);
|
|
979
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
|
|
980
|
+
};
|
|
981
|
+
var useHoveringEditorContext = () => (0, import_react6.useContext)(HoveringEditorContext);
|
|
982
|
+
|
|
983
|
+
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
984
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
971
985
|
var HoveringInsertionPromptBoxCore = ({
|
|
972
986
|
performInsertion,
|
|
973
987
|
state,
|
|
974
988
|
insertionOrEditingFunction,
|
|
975
989
|
contextCategories
|
|
976
990
|
}) => {
|
|
977
|
-
const { getDocumentsContext } = (0,
|
|
978
|
-
const [editSuggestion, setEditSuggestion] = (0,
|
|
979
|
-
const [suggestionIsLoading, setSuggestionIsLoading] = (0,
|
|
980
|
-
const [adjustmentPrompt, setAdjustmentPrompt] = (0,
|
|
981
|
-
const [generatingSuggestion, setGeneratingSuggestion] = (0,
|
|
991
|
+
const { getDocumentsContext } = (0, import_react7.useContext)(import_react_core2.CopilotContext);
|
|
992
|
+
const [editSuggestion, setEditSuggestion] = (0, import_react7.useState)("");
|
|
993
|
+
const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react7.useState)(false);
|
|
994
|
+
const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react7.useState)("");
|
|
995
|
+
const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react7.useState)(
|
|
982
996
|
null
|
|
983
997
|
);
|
|
984
|
-
const adjustmentTextAreaRef = (0,
|
|
985
|
-
const suggestionTextAreaRef = (0,
|
|
986
|
-
const [filePointers, setFilePointers] = (0,
|
|
987
|
-
const [suggestedFiles, setSuggestedFiles] = (0,
|
|
988
|
-
(0,
|
|
998
|
+
const adjustmentTextAreaRef = (0, import_react7.useRef)(null);
|
|
999
|
+
const suggestionTextAreaRef = (0, import_react7.useRef)(null);
|
|
1000
|
+
const [filePointers, setFilePointers] = (0, import_react7.useState)([]);
|
|
1001
|
+
const [suggestedFiles, setSuggestedFiles] = (0, import_react7.useState)([]);
|
|
1002
|
+
(0, import_react7.useEffect)(() => {
|
|
989
1003
|
setSuggestedFiles(getDocumentsContext(contextCategories));
|
|
990
1004
|
}, [contextCategories, getDocumentsContext]);
|
|
991
1005
|
use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
|
|
992
1006
|
use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
|
|
993
|
-
(0,
|
|
1007
|
+
(0, import_react7.useEffect)(() => {
|
|
994
1008
|
setTimeout(() => {
|
|
995
1009
|
var _a;
|
|
996
1010
|
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
997
1011
|
}, 0);
|
|
998
1012
|
}, []);
|
|
999
|
-
(0,
|
|
1013
|
+
(0, import_react7.useEffect)(() => {
|
|
1000
1014
|
if (!generatingSuggestion) {
|
|
1001
1015
|
return;
|
|
1002
1016
|
}
|
|
@@ -1034,7 +1048,7 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1034
1048
|
releaseLockIfNotClosed();
|
|
1035
1049
|
};
|
|
1036
1050
|
}, [generatingSuggestion]);
|
|
1037
|
-
const beginGeneratingAdjustment = (0,
|
|
1051
|
+
const beginGeneratingAdjustment = (0, import_react7.useCallback)(() => __async(void 0, null, function* () {
|
|
1038
1052
|
if (!adjustmentPrompt.trim()) {
|
|
1039
1053
|
return;
|
|
1040
1054
|
}
|
|
@@ -1063,10 +1077,11 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1063
1077
|
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
1064
1078
|
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
1065
1079
|
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1068
|
-
/* @__PURE__ */ (0,
|
|
1069
|
-
|
|
1080
|
+
const { setIsDisplayed } = useHoveringEditorContext();
|
|
1081
|
+
const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1082
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "", children: adjustmentLabel }),
|
|
1083
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative w-full flex items-center", children: [
|
|
1084
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1070
1085
|
"textarea",
|
|
1071
1086
|
{
|
|
1072
1087
|
disabled: suggestionIsLoading,
|
|
@@ -1080,6 +1095,9 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1080
1095
|
} else if (e.key === "Enter") {
|
|
1081
1096
|
e.preventDefault();
|
|
1082
1097
|
beginGeneratingAdjustment();
|
|
1098
|
+
} else if (e.key == "Escape") {
|
|
1099
|
+
e.preventDefault();
|
|
1100
|
+
setIsDisplayed(false);
|
|
1083
1101
|
}
|
|
1084
1102
|
},
|
|
1085
1103
|
placeholder,
|
|
@@ -1088,29 +1106,29 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1088
1106
|
rows: 1
|
|
1089
1107
|
}
|
|
1090
1108
|
),
|
|
1091
|
-
/* @__PURE__ */ (0,
|
|
1109
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1092
1110
|
"button",
|
|
1093
1111
|
{
|
|
1094
1112
|
onClick: beginGeneratingAdjustment,
|
|
1095
1113
|
className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
|
|
1096
|
-
children: /* @__PURE__ */ (0,
|
|
1114
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "arrow_forward" })
|
|
1097
1115
|
}
|
|
1098
1116
|
)
|
|
1099
1117
|
] })
|
|
1100
1118
|
] });
|
|
1101
|
-
const SuggestionComponent = /* @__PURE__ */ (0,
|
|
1102
|
-
/* @__PURE__ */ (0,
|
|
1103
|
-
/* @__PURE__ */ (0,
|
|
1104
|
-
/* @__PURE__ */ (0,
|
|
1119
|
+
const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1120
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-between items-end w-full", children: [
|
|
1121
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "mt-4", children: "Suggested:" }),
|
|
1122
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1105
1123
|
"div",
|
|
1106
1124
|
{
|
|
1107
1125
|
className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
|
|
1108
1126
|
role: "status",
|
|
1109
|
-
children: /* @__PURE__ */ (0,
|
|
1127
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." })
|
|
1110
1128
|
}
|
|
1111
1129
|
) }) })
|
|
1112
1130
|
] }),
|
|
1113
|
-
/* @__PURE__ */ (0,
|
|
1131
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1114
1132
|
"textarea",
|
|
1115
1133
|
{
|
|
1116
1134
|
ref: suggestionTextAreaRef,
|
|
@@ -1122,7 +1140,7 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1122
1140
|
}
|
|
1123
1141
|
)
|
|
1124
1142
|
] });
|
|
1125
|
-
const SubmitComponent = /* @__PURE__ */ (0,
|
|
1143
|
+
const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1126
1144
|
Button,
|
|
1127
1145
|
{
|
|
1128
1146
|
className: " bg-green-700 text-white",
|
|
@@ -1131,16 +1149,16 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1131
1149
|
},
|
|
1132
1150
|
children: [
|
|
1133
1151
|
"Insert ",
|
|
1134
|
-
/* @__PURE__ */ (0,
|
|
1152
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "check" })
|
|
1135
1153
|
]
|
|
1136
1154
|
}
|
|
1137
1155
|
) });
|
|
1138
1156
|
const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
|
|
1139
1157
|
const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
|
|
1140
|
-
return /* @__PURE__ */ (0,
|
|
1158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
|
|
1141
1159
|
AdjustmentPromptComponent,
|
|
1142
|
-
filePointers.length > 0 && /* @__PURE__ */ (0,
|
|
1143
|
-
sourceSearchWord !== void 0 && /* @__PURE__ */ (0,
|
|
1160
|
+
filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
|
|
1161
|
+
sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1144
1162
|
SourceSearchBox,
|
|
1145
1163
|
{
|
|
1146
1164
|
searchTerm: sourceSearchWord,
|
|
@@ -1159,14 +1177,14 @@ var HoveringInsertionPromptBoxCore = ({
|
|
|
1159
1177
|
};
|
|
1160
1178
|
|
|
1161
1179
|
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
|
|
1162
|
-
var
|
|
1180
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1163
1181
|
var HoveringInsertionPromptBox = (props) => {
|
|
1164
|
-
return /* @__PURE__ */ (0,
|
|
1182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1165
1183
|
"div",
|
|
1166
1184
|
{
|
|
1167
1185
|
className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
|
|
1168
1186
|
style: { width: "35rem" },
|
|
1169
|
-
children: /* @__PURE__ */ (0,
|
|
1187
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1170
1188
|
HoveringInsertionPromptBoxCore,
|
|
1171
1189
|
{
|
|
1172
1190
|
state: {
|
|
@@ -1183,10 +1201,10 @@ var HoveringInsertionPromptBox = (props) => {
|
|
|
1183
1201
|
|
|
1184
1202
|
// src/components/hovering-toolbar/hovering-toolbar-components.tsx
|
|
1185
1203
|
var import_css = require("@emotion/css");
|
|
1186
|
-
var
|
|
1204
|
+
var import_react8 = __toESM(require("react"));
|
|
1187
1205
|
var import_react_dom = __toESM(require("react-dom"));
|
|
1188
|
-
var
|
|
1189
|
-
var Button2 =
|
|
1206
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1207
|
+
var Button2 = import_react8.default.forwardRef(
|
|
1190
1208
|
(_a, ref) => {
|
|
1191
1209
|
var _b = _a, {
|
|
1192
1210
|
className,
|
|
@@ -1197,7 +1215,7 @@ var Button2 = import_react7.default.forwardRef(
|
|
|
1197
1215
|
"active",
|
|
1198
1216
|
"reversed"
|
|
1199
1217
|
]);
|
|
1200
|
-
return /* @__PURE__ */ (0,
|
|
1218
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1201
1219
|
"span",
|
|
1202
1220
|
__spreadProps(__spreadValues({}, props), {
|
|
1203
1221
|
ref,
|
|
@@ -1212,10 +1230,10 @@ var Button2 = import_react7.default.forwardRef(
|
|
|
1212
1230
|
);
|
|
1213
1231
|
}
|
|
1214
1232
|
);
|
|
1215
|
-
var Icon =
|
|
1233
|
+
var Icon = import_react8.default.forwardRef(
|
|
1216
1234
|
(_a, ref) => {
|
|
1217
1235
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1218
|
-
return /* @__PURE__ */ (0,
|
|
1236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1219
1237
|
"span",
|
|
1220
1238
|
__spreadProps(__spreadValues({}, props), {
|
|
1221
1239
|
ref,
|
|
@@ -1231,10 +1249,10 @@ var Icon = import_react7.default.forwardRef(
|
|
|
1231
1249
|
);
|
|
1232
1250
|
}
|
|
1233
1251
|
);
|
|
1234
|
-
var Menu =
|
|
1252
|
+
var Menu = import_react8.default.forwardRef(
|
|
1235
1253
|
(_a, ref) => {
|
|
1236
1254
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1237
|
-
return /* @__PURE__ */ (0,
|
|
1255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1238
1256
|
"div",
|
|
1239
1257
|
__spreadProps(__spreadValues({}, props), {
|
|
1240
1258
|
"data-test-id": "menu",
|
|
@@ -1258,10 +1276,10 @@ var Menu = import_react7.default.forwardRef(
|
|
|
1258
1276
|
var Portal = ({ children }) => {
|
|
1259
1277
|
return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
|
|
1260
1278
|
};
|
|
1261
|
-
var Toolbar =
|
|
1279
|
+
var Toolbar = import_react8.default.forwardRef(
|
|
1262
1280
|
(_a, ref) => {
|
|
1263
1281
|
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1264
|
-
return /* @__PURE__ */ (0,
|
|
1282
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1265
1283
|
Menu,
|
|
1266
1284
|
__spreadProps(__spreadValues({}, props), {
|
|
1267
1285
|
ref,
|
|
@@ -1280,20 +1298,6 @@ var Toolbar = import_react7.default.forwardRef(
|
|
|
1280
1298
|
}
|
|
1281
1299
|
);
|
|
1282
1300
|
|
|
1283
|
-
// src/components/hovering-toolbar/hovering-editor-provider.tsx
|
|
1284
|
-
var import_react8 = require("react");
|
|
1285
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1286
|
-
var HoveringEditorContext = (0, import_react8.createContext)({
|
|
1287
|
-
isDisplayed: false,
|
|
1288
|
-
setIsDisplayed: () => {
|
|
1289
|
-
}
|
|
1290
|
-
});
|
|
1291
|
-
var HoveringEditorProvider = ({ children }) => {
|
|
1292
|
-
const [isDisplayed, setIsDisplayed] = (0, import_react8.useState)(false);
|
|
1293
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
|
|
1294
|
-
};
|
|
1295
|
-
var useHoveringEditorContext = () => (0, import_react8.useContext)(HoveringEditorContext);
|
|
1296
|
-
|
|
1297
1301
|
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
1298
1302
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1299
1303
|
var HoveringToolbar = (props) => {
|
|
@@ -1633,7 +1637,8 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
|
|
|
1633
1637
|
);
|
|
1634
1638
|
const onKeyDownHandlerForHoveringEditor = (0, import_react12.useCallback)(
|
|
1635
1639
|
(event) => {
|
|
1636
|
-
|
|
1640
|
+
var _a2;
|
|
1641
|
+
if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, (_a2 = props.shortcut) != null ? _a2 : "k")) {
|
|
1637
1642
|
event.preventDefault();
|
|
1638
1643
|
setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
|
|
1639
1644
|
}
|