@copilotkit/react-textarea 0.19.0-alpha.4 → 0.19.0-alpha.6
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 +174 -178
- package/CHANGELOG.md +20 -0
- package/dist/chunk-2NURR2DX.mjs +47 -0
- package/dist/chunk-2NURR2DX.mjs.map +1 -0
- package/dist/chunk-4S5ZJH3I.mjs +18 -0
- package/dist/chunk-4S5ZJH3I.mjs.map +1 -0
- package/dist/chunk-55EGOC5T.mjs +87 -0
- package/dist/chunk-55EGOC5T.mjs.map +1 -0
- package/dist/chunk-5ARCOTW3.mjs +34 -0
- package/dist/chunk-5ARCOTW3.mjs.map +1 -0
- package/dist/chunk-5EJ5XOGP.mjs +22 -0
- package/dist/chunk-5EJ5XOGP.mjs.map +1 -0
- package/dist/chunk-5FO6ISW4.mjs +3 -0
- package/dist/chunk-5FO6ISW4.mjs.map +1 -0
- package/dist/chunk-6XP7KEMW.mjs +20 -0
- package/dist/chunk-6XP7KEMW.mjs.map +1 -0
- package/dist/chunk-A2RRLD23.mjs +69 -0
- package/dist/chunk-A2RRLD23.mjs.map +1 -0
- package/dist/chunk-CSGFJU3L.mjs +65 -0
- package/dist/chunk-CSGFJU3L.mjs.map +1 -0
- package/dist/chunk-D7SEV5PR.mjs +12 -0
- package/dist/chunk-D7SEV5PR.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +3 -0
- package/dist/chunk-DE5K76I2.mjs.map +1 -0
- package/dist/chunk-F3MHL6ZY.mjs +25 -0
- package/dist/chunk-F3MHL6ZY.mjs.map +1 -0
- package/dist/chunk-FBDXI5QA.mjs +501 -0
- package/dist/chunk-FBDXI5QA.mjs.map +1 -0
- package/dist/chunk-FN7GDKKG.mjs +29 -0
- package/dist/chunk-FN7GDKKG.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +3 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-HAFHLU4N.mjs +55 -0
- package/dist/chunk-HAFHLU4N.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +3 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-IWTOQKC5.mjs +201 -0
- package/dist/chunk-IWTOQKC5.mjs.map +1 -0
- package/dist/chunk-IXJ2HCOA.mjs +101 -0
- package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
- package/dist/chunk-JAFCXEPU.mjs +10 -0
- package/dist/chunk-JAFCXEPU.mjs.map +1 -0
- package/dist/chunk-KCHYD3EB.mjs +107 -0
- package/dist/chunk-KCHYD3EB.mjs.map +1 -0
- package/dist/chunk-KGKLUWKW.mjs +47 -0
- package/dist/chunk-KGKLUWKW.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +3 -0
- package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
- package/dist/chunk-LNAIMEB2.mjs +34 -0
- package/dist/chunk-LNAIMEB2.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +3 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MPME5BW2.mjs +59 -0
- package/dist/chunk-MPME5BW2.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-N4JMCC7P.mjs +44 -0
- package/dist/chunk-N4JMCC7P.mjs.map +1 -0
- package/dist/chunk-ND5PXTAW.mjs +17 -0
- package/dist/chunk-ND5PXTAW.mjs.map +1 -0
- package/dist/chunk-NKW5OU2S.mjs +33 -0
- package/dist/chunk-NKW5OU2S.mjs.map +1 -0
- package/dist/chunk-O5OWT5GE.mjs +114 -0
- package/dist/chunk-O5OWT5GE.mjs.map +1 -0
- package/dist/chunk-OD7ZMOVE.mjs +45 -0
- package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
- package/dist/chunk-OELUUJZY.mjs +16 -0
- package/dist/chunk-OELUUJZY.mjs.map +1 -0
- package/dist/chunk-QL2GYGG5.mjs +19 -0
- package/dist/chunk-QL2GYGG5.mjs.map +1 -0
- package/dist/chunk-RQHOUUXQ.mjs +29 -0
- package/dist/chunk-RQHOUUXQ.mjs.map +1 -0
- package/dist/chunk-UHD44NC5.mjs +101 -0
- package/dist/chunk-UHD44NC5.mjs.map +1 -0
- package/dist/chunk-VBIJPE3H.mjs +108 -0
- package/dist/chunk-VBIJPE3H.mjs.map +1 -0
- package/dist/chunk-WADHCMPK.mjs +3 -0
- package/dist/chunk-WADHCMPK.mjs.map +1 -0
- package/dist/chunk-WJHSY5T6.mjs +3 -0
- package/dist/chunk-WJHSY5T6.mjs.map +1 -0
- package/dist/chunk-WJYQWL4I.mjs +27 -0
- package/dist/chunk-WJYQWL4I.mjs.map +1 -0
- package/dist/chunk-XA7M72ZO.mjs +106 -0
- package/dist/chunk-XA7M72ZO.mjs.map +1 -0
- package/dist/chunk-XDT7BF3V.mjs +81 -0
- package/dist/chunk-XDT7BF3V.mjs.map +1 -0
- package/dist/chunk-XHUMROEY.mjs +91 -0
- package/dist/chunk-XHUMROEY.mjs.map +1 -0
- package/dist/chunk-YQU7WG7T.mjs +83 -0
- package/dist/chunk-YQU7WG7T.mjs.map +1 -0
- package/dist/chunk-YSZ7DO3X.mjs +107 -0
- package/dist/chunk-YSZ7DO3X.mjs.map +1 -0
- package/dist/chunk-YTOPHPSG.mjs +45 -0
- package/dist/chunk-YTOPHPSG.mjs.map +1 -0
- package/dist/chunk-YW3REYX6.mjs +23 -0
- package/dist/chunk-YW3REYX6.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +33 -1870
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +3 -52
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -46
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +43 -2339
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -22
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -125
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +16 -1015
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +10 -721
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +11 -734
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +12 -734
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.mjs +44 -2340
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +10 -323
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.mjs +4 -88
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/card.mjs +7 -53
- package/dist/components/ui/card.mjs.map +1 -1
- package/dist/components/ui/command.mjs +5 -266
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +4 -164
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +4 -63
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/components/ui/separator.mjs +8 -50
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/textarea.mjs +7 -48
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -168
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -155
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +4 -90
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +4 -143
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -1
- package/dist/index.mjs +48 -2343
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.mjs +3 -51
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +3 -43
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.mjs +3 -109
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +3 -17
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -23
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +3 -47
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +3 -71
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/lib/utils.test.mjs +1 -0
- package/dist/lib/utils.test.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +9 -312
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +4 -155
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +10 -313
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +4 -149
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -71
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +4 -137
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/autosuggestion-state.mjs +2 -0
- package/dist/types/base/autosuggestion-state.mjs.map +1 -1
- package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
- package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +3 -11
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
- package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
- package/dist/types/base/custom-editor.mjs +2 -0
- package/dist/types/base/custom-editor.mjs.map +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +4 -17
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.mjs +4 -11
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +2 -0
- package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
- package/dist/types/index.mjs +12 -314
- package/dist/types/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +40 -1
|
@@ -1,1871 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/components/base-copilot-textarea/base-copilot-textarea.tsx
|
|
54
|
-
import React9, { useCallback as useCallback2, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
|
|
55
|
-
import { Editor as Editor5 } from "slate";
|
|
56
|
-
import { Editable, Slate } from "slate-react";
|
|
57
|
-
import { twMerge as twMerge2 } from "tailwind-merge";
|
|
58
|
-
|
|
59
|
-
// src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
|
|
60
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
61
|
-
|
|
62
|
-
// src/lib/debouncer.ts
|
|
63
|
-
var Debouncer = class {
|
|
64
|
-
constructor(wait) {
|
|
65
|
-
this.wait = wait;
|
|
66
|
-
this.debounce = (func, ...args) => __async(this, null, function* () {
|
|
67
|
-
this.cancel();
|
|
68
|
-
this.timeoutId = setTimeout(() => __async(this, null, function* () {
|
|
69
|
-
try {
|
|
70
|
-
this.activeAbortController = new AbortController();
|
|
71
|
-
yield func(...args, this.activeAbortController.signal);
|
|
72
|
-
this.activeAbortController = void 0;
|
|
73
|
-
} catch (error) {
|
|
74
|
-
}
|
|
75
|
-
}), this.wait);
|
|
76
|
-
});
|
|
77
|
-
this.cancel = () => {
|
|
78
|
-
if (this.activeAbortController) {
|
|
79
|
-
this.activeAbortController.abort();
|
|
80
|
-
this.activeAbortController = void 0;
|
|
81
|
-
}
|
|
82
|
-
if (this.timeoutId !== void 0) {
|
|
83
|
-
clearTimeout(this.timeoutId);
|
|
84
|
-
this.timeoutId = void 0;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// src/lib/utils.ts
|
|
91
|
-
import { clsx } from "clsx";
|
|
92
|
-
import { customAlphabet } from "nanoid";
|
|
93
|
-
import { twMerge } from "tailwind-merge";
|
|
94
|
-
function cn(...inputs) {
|
|
95
|
-
return twMerge(clsx(inputs));
|
|
96
|
-
}
|
|
97
|
-
var nanoid = customAlphabet(
|
|
98
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
99
|
-
7
|
|
100
|
-
);
|
|
101
|
-
var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
102
|
-
function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
|
|
103
|
-
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
104
|
-
return a === b;
|
|
105
|
-
}
|
|
106
|
-
return naiveEqualityCheck(a, b);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/types/base/editor-autocomplete-state.ts
|
|
110
|
-
function areEqual_autocompleteState(prev, next) {
|
|
111
|
-
return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
|
|
115
|
-
function useAutosuggestions(debounceTime, acceptAutosuggestionKey, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
|
|
116
|
-
const [previousAutocompleteState, setPreviousAutocompleteState] = useState(null);
|
|
117
|
-
const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = useState(null);
|
|
118
|
-
const awaitForAndAppendSuggestion = useCallback(
|
|
119
|
-
(editorAutocompleteState, abortSignal) => __async(this, null, function* () {
|
|
120
|
-
if (disabled) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (disableWhenEmpty && editorAutocompleteState.textBeforeCursor === "" && editorAutocompleteState.textAfterCursor === "") {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const suggestion = yield autosuggestionFunction(
|
|
127
|
-
editorAutocompleteState,
|
|
128
|
-
abortSignal
|
|
129
|
-
);
|
|
130
|
-
if (!suggestion || abortSignal.aborted) {
|
|
131
|
-
throw new DOMException("Aborted", "AbortError");
|
|
132
|
-
}
|
|
133
|
-
setCurrentAutocompleteSuggestion({
|
|
134
|
-
text: suggestion,
|
|
135
|
-
point: editorAutocompleteState.cursorPoint
|
|
136
|
-
});
|
|
137
|
-
}),
|
|
138
|
-
[
|
|
139
|
-
autosuggestionFunction,
|
|
140
|
-
setCurrentAutocompleteSuggestion,
|
|
141
|
-
disableWhenEmpty,
|
|
142
|
-
disabled
|
|
143
|
-
]
|
|
144
|
-
);
|
|
145
|
-
const debouncedFunction = useMemo(
|
|
146
|
-
() => new Debouncer(
|
|
147
|
-
debounceTime
|
|
148
|
-
),
|
|
149
|
-
[debounceTime]
|
|
150
|
-
);
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
return () => {
|
|
153
|
-
debouncedFunction.cancel();
|
|
154
|
-
setCurrentAutocompleteSuggestion(null);
|
|
155
|
-
};
|
|
156
|
-
}, [debouncedFunction, disabled]);
|
|
157
|
-
const onChange = useCallback(
|
|
158
|
-
(newEditorState) => {
|
|
159
|
-
const editorStateHasChanged = !nullableCompatibleEqualityCheck(
|
|
160
|
-
areEqual_autocompleteState,
|
|
161
|
-
previousAutocompleteState,
|
|
162
|
-
newEditorState
|
|
163
|
-
);
|
|
164
|
-
setPreviousAutocompleteState(newEditorState);
|
|
165
|
-
if (!editorStateHasChanged) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
setCurrentAutocompleteSuggestion(null);
|
|
169
|
-
if (newEditorState) {
|
|
170
|
-
debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);
|
|
171
|
-
} else {
|
|
172
|
-
debouncedFunction.cancel();
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
[
|
|
176
|
-
previousAutocompleteState,
|
|
177
|
-
setPreviousAutocompleteState,
|
|
178
|
-
debouncedFunction,
|
|
179
|
-
awaitForAndAppendSuggestion,
|
|
180
|
-
setCurrentAutocompleteSuggestion
|
|
181
|
-
]
|
|
182
|
-
);
|
|
183
|
-
const keyDownHandler = useCallback(
|
|
184
|
-
(event) => {
|
|
185
|
-
if (currentAutocompleteSuggestion) {
|
|
186
|
-
if (event.key === acceptAutosuggestionKey) {
|
|
187
|
-
event.preventDefault();
|
|
188
|
-
insertAutocompleteSuggestion(currentAutocompleteSuggestion);
|
|
189
|
-
setCurrentAutocompleteSuggestion(null);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
[
|
|
194
|
-
currentAutocompleteSuggestion,
|
|
195
|
-
setCurrentAutocompleteSuggestion,
|
|
196
|
-
insertAutocompleteSuggestion,
|
|
197
|
-
acceptAutosuggestionKey
|
|
198
|
-
]
|
|
199
|
-
);
|
|
200
|
-
return {
|
|
201
|
-
currentAutocompleteSuggestion,
|
|
202
|
-
onChangeHandler: onChange,
|
|
203
|
-
onKeyDownHandler: keyDownHandler
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
|
|
208
|
-
import { useMemo as useMemo2 } from "react";
|
|
209
|
-
import { createEditor, Element } from "slate";
|
|
210
|
-
import { withReact } from "slate-react";
|
|
211
|
-
|
|
212
|
-
// src/lib/slatejs-edits/with-partial-history.ts
|
|
213
|
-
import { Editor, Operation, Path, Transforms } from "slate";
|
|
214
|
-
import { HistoryEditor } from "slate-history";
|
|
215
|
-
var withPartialHistory = (editor, shouldSave2) => {
|
|
216
|
-
const e = editor;
|
|
217
|
-
const { apply } = e;
|
|
218
|
-
e.history = { undos: [], redos: [] };
|
|
219
|
-
e.redo = () => {
|
|
220
|
-
const { history } = e;
|
|
221
|
-
const { redos } = history;
|
|
222
|
-
if (redos.length > 0) {
|
|
223
|
-
const batch = redos[redos.length - 1];
|
|
224
|
-
if (batch.selectionBefore) {
|
|
225
|
-
Transforms.setSelection(e, batch.selectionBefore);
|
|
226
|
-
}
|
|
227
|
-
HistoryEditor.withoutSaving(e, () => {
|
|
228
|
-
Editor.withoutNormalizing(e, () => {
|
|
229
|
-
for (const op of batch.operations) {
|
|
230
|
-
e.apply(op);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
history.redos.pop();
|
|
235
|
-
e.writeHistory("undos", batch);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
e.undo = () => {
|
|
239
|
-
const { history } = e;
|
|
240
|
-
const { undos } = history;
|
|
241
|
-
if (undos.length > 0) {
|
|
242
|
-
const batch = undos[undos.length - 1];
|
|
243
|
-
HistoryEditor.withoutSaving(e, () => {
|
|
244
|
-
Editor.withoutNormalizing(e, () => {
|
|
245
|
-
const inverseOps = batch.operations.map(Operation.inverse).reverse();
|
|
246
|
-
for (const op of inverseOps) {
|
|
247
|
-
e.apply(op);
|
|
248
|
-
}
|
|
249
|
-
if (batch.selectionBefore) {
|
|
250
|
-
Transforms.setSelection(e, batch.selectionBefore);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
e.writeHistory("redos", batch);
|
|
255
|
-
history.undos.pop();
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
e.apply = (op) => {
|
|
259
|
-
const { operations, history } = e;
|
|
260
|
-
const { undos } = history;
|
|
261
|
-
const lastBatch = undos[undos.length - 1];
|
|
262
|
-
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
263
|
-
let save = HistoryEditor.isSaving(e);
|
|
264
|
-
let merge = HistoryEditor.isMerging(e);
|
|
265
|
-
if (save == null) {
|
|
266
|
-
save = shouldSave2(op, lastOp);
|
|
267
|
-
}
|
|
268
|
-
if (save) {
|
|
269
|
-
if (merge == null) {
|
|
270
|
-
if (lastBatch == null) {
|
|
271
|
-
merge = false;
|
|
272
|
-
} else if (operations.length !== 0) {
|
|
273
|
-
merge = true;
|
|
274
|
-
} else {
|
|
275
|
-
merge = shouldMerge(op, lastOp);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (lastBatch && merge) {
|
|
279
|
-
lastBatch.operations.push(op);
|
|
280
|
-
} else {
|
|
281
|
-
const batch = {
|
|
282
|
-
operations: [op],
|
|
283
|
-
selectionBefore: e.selection
|
|
284
|
-
};
|
|
285
|
-
e.writeHistory("undos", batch);
|
|
286
|
-
}
|
|
287
|
-
while (undos.length > 100) {
|
|
288
|
-
undos.shift();
|
|
289
|
-
}
|
|
290
|
-
history.redos = [];
|
|
291
|
-
}
|
|
292
|
-
apply(op);
|
|
293
|
-
};
|
|
294
|
-
e.writeHistory = (stack, batch) => {
|
|
295
|
-
e.history[stack].push(batch);
|
|
296
|
-
};
|
|
297
|
-
return e;
|
|
298
|
-
};
|
|
299
|
-
var shouldMerge = (op, prev) => {
|
|
300
|
-
if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
return false;
|
|
307
|
-
};
|
|
308
|
-
var defaultShouldSave = (op, prev) => {
|
|
309
|
-
if (op.type === "set_selection") {
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
return true;
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
// src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
|
|
316
|
-
var shouldSave = (op, prev) => {
|
|
317
|
-
const excludedNodeType = "suggestion";
|
|
318
|
-
if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
return defaultShouldSave(op, prev);
|
|
337
|
-
};
|
|
338
|
-
function useCopilotTextareaEditor() {
|
|
339
|
-
const editor = useMemo2(() => {
|
|
340
|
-
const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
|
|
341
|
-
const { isVoid } = editor2;
|
|
342
|
-
editor2.isVoid = (element) => {
|
|
343
|
-
switch (element.type) {
|
|
344
|
-
case "suggestion":
|
|
345
|
-
return true;
|
|
346
|
-
default:
|
|
347
|
-
return isVoid(element);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const { markableVoid } = editor2;
|
|
351
|
-
editor2.markableVoid = (element) => {
|
|
352
|
-
switch (element.type) {
|
|
353
|
-
case "suggestion":
|
|
354
|
-
return true;
|
|
355
|
-
default:
|
|
356
|
-
return markableVoid(element);
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
const { isInline } = editor2;
|
|
360
|
-
editor2.isInline = (element) => {
|
|
361
|
-
switch (element.type) {
|
|
362
|
-
case "suggestion":
|
|
363
|
-
return element.inline;
|
|
364
|
-
default:
|
|
365
|
-
return isInline(element);
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
return editor2;
|
|
369
|
-
}, []);
|
|
370
|
-
return editor;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
|
|
374
|
-
import React from "react";
|
|
375
|
-
import { ReactEditor } from "slate-react";
|
|
376
|
-
|
|
377
|
-
// src/lib/get-text-around-cursor.ts
|
|
378
|
-
import {
|
|
379
|
-
Editor as Editor2,
|
|
380
|
-
Path as Path2,
|
|
381
|
-
Range as Range2,
|
|
382
|
-
Text,
|
|
383
|
-
Element as Element2,
|
|
384
|
-
Point
|
|
385
|
-
} from "slate";
|
|
386
|
-
function getTextAroundCollapsedCursor(editor) {
|
|
387
|
-
const { selection } = editor;
|
|
388
|
-
if (!selection || !Range2.isCollapsed(selection)) {
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
const cursorPoint = selection.anchor;
|
|
392
|
-
const beforeRange = {
|
|
393
|
-
anchor: Editor2.start(editor, []),
|
|
394
|
-
focus: cursorPoint
|
|
395
|
-
};
|
|
396
|
-
const afterRange = {
|
|
397
|
-
anchor: cursorPoint,
|
|
398
|
-
focus: Editor2.end(editor, [])
|
|
399
|
-
};
|
|
400
|
-
const before = extractTextWithNewlines(editor, beforeRange);
|
|
401
|
-
const after = extractTextWithNewlines(editor, afterRange);
|
|
402
|
-
return {
|
|
403
|
-
cursorPoint,
|
|
404
|
-
textBeforeCursor: before,
|
|
405
|
-
textAfterCursor: after
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
function getTextAroundSelection(editor) {
|
|
409
|
-
const { selection } = editor;
|
|
410
|
-
if (!selection) {
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
const wellOrderedSelection = wellOrderedRange(selection);
|
|
414
|
-
const beforeRange = {
|
|
415
|
-
anchor: Editor2.start(editor, []),
|
|
416
|
-
focus: wellOrderedSelection.anchor
|
|
417
|
-
};
|
|
418
|
-
const afterRange = {
|
|
419
|
-
anchor: wellOrderedSelection.focus,
|
|
420
|
-
focus: Editor2.end(editor, [])
|
|
421
|
-
};
|
|
422
|
-
const before = extractTextWithNewlines(editor, beforeRange);
|
|
423
|
-
const after = extractTextWithNewlines(editor, afterRange);
|
|
424
|
-
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
425
|
-
return {
|
|
426
|
-
selection: wellOrderedSelection,
|
|
427
|
-
textBeforeCursor: before,
|
|
428
|
-
selectedText,
|
|
429
|
-
textAfterCursor: after
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
function getFullEditorTextWithNewlines(editor) {
|
|
433
|
-
const fullDocumentRange = {
|
|
434
|
-
anchor: Editor2.start(editor, []),
|
|
435
|
-
focus: Editor2.end(editor, [])
|
|
436
|
-
};
|
|
437
|
-
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
438
|
-
}
|
|
439
|
-
function extractTextWithNewlines(editor, range) {
|
|
440
|
-
const voids = false;
|
|
441
|
-
const [start, end] = Range2.edges(range);
|
|
442
|
-
let text = "";
|
|
443
|
-
let lastBlock = null;
|
|
444
|
-
for (const [node, path] of Editor2.nodes(editor, {
|
|
445
|
-
at: range,
|
|
446
|
-
match: Text.isText,
|
|
447
|
-
voids
|
|
448
|
-
})) {
|
|
449
|
-
let t = node.text;
|
|
450
|
-
const [block] = Editor2.above(editor, {
|
|
451
|
-
at: path,
|
|
452
|
-
match: (n) => Element2.isElement(n) && n.type === "paragraph"
|
|
453
|
-
}) || [null];
|
|
454
|
-
if (lastBlock !== block && block) {
|
|
455
|
-
if (lastBlock) {
|
|
456
|
-
text += "\n";
|
|
457
|
-
}
|
|
458
|
-
lastBlock = block;
|
|
459
|
-
}
|
|
460
|
-
if (Path2.equals(path, end.path)) {
|
|
461
|
-
t = t.slice(0, end.offset);
|
|
462
|
-
}
|
|
463
|
-
if (Path2.equals(path, start.path)) {
|
|
464
|
-
t = t.slice(start.offset);
|
|
465
|
-
}
|
|
466
|
-
text += t;
|
|
467
|
-
}
|
|
468
|
-
return text;
|
|
469
|
-
}
|
|
470
|
-
function wellOrderedRange(range) {
|
|
471
|
-
const { anchor, focus } = range;
|
|
472
|
-
if (Point.isBefore(anchor, focus)) {
|
|
473
|
-
return range;
|
|
474
|
-
}
|
|
475
|
-
return {
|
|
476
|
-
anchor: focus,
|
|
477
|
-
focus: anchor
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// src/lib/slatejs-edits/replace-text.ts
|
|
482
|
-
import { Editor as Editor3, Transforms as Transforms2 } from "slate";
|
|
483
|
-
function replaceEditorText(editor, newText) {
|
|
484
|
-
Transforms2.delete(editor, {
|
|
485
|
-
at: {
|
|
486
|
-
anchor: Editor3.start(editor, []),
|
|
487
|
-
focus: Editor3.end(editor, [])
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
if (newText && newText !== "") {
|
|
491
|
-
Transforms2.insertNodes(
|
|
492
|
-
editor,
|
|
493
|
-
[
|
|
494
|
-
{
|
|
495
|
-
type: "paragraph",
|
|
496
|
-
children: [{ text: newText }]
|
|
497
|
-
}
|
|
498
|
-
],
|
|
499
|
-
{
|
|
500
|
-
at: [0]
|
|
501
|
-
}
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
|
|
507
|
-
function usePopulateCopilotTextareaRef(editor, ref) {
|
|
508
|
-
React.useImperativeHandle(
|
|
509
|
-
ref,
|
|
510
|
-
() => {
|
|
511
|
-
class Combined {
|
|
512
|
-
constructor(customMethods2, editorHtmlElement2) {
|
|
513
|
-
this.customMethods = customMethods2;
|
|
514
|
-
this.editorHtmlElement = editorHtmlElement2;
|
|
515
|
-
}
|
|
516
|
-
get(target, propKey) {
|
|
517
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
518
|
-
const value = this.customMethods[propKey];
|
|
519
|
-
if (typeof value === "function") {
|
|
520
|
-
return value.bind(this.customMethods);
|
|
521
|
-
}
|
|
522
|
-
return value;
|
|
523
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
524
|
-
const value = this.editorHtmlElement[propKey];
|
|
525
|
-
if (typeof value === "function") {
|
|
526
|
-
return value.bind(this.editorHtmlElement);
|
|
527
|
-
}
|
|
528
|
-
return value;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
set(target, propKey, value) {
|
|
532
|
-
if (this.isKeyOfCustomMethods(propKey)) {
|
|
533
|
-
this.customMethods[propKey] = value;
|
|
534
|
-
} else if (this.isKeyOfHTMLElement(propKey)) {
|
|
535
|
-
this.editorHtmlElement[propKey] = value;
|
|
536
|
-
} else {
|
|
537
|
-
target[propKey] = value;
|
|
538
|
-
}
|
|
539
|
-
return true;
|
|
540
|
-
}
|
|
541
|
-
isKeyOfCustomMethods(key) {
|
|
542
|
-
return key in this.customMethods;
|
|
543
|
-
}
|
|
544
|
-
isKeyOfHTMLElement(key) {
|
|
545
|
-
return key in this.editorHtmlElement;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
const handler = {
|
|
549
|
-
get(target, propKey) {
|
|
550
|
-
return target.get(target, propKey);
|
|
551
|
-
},
|
|
552
|
-
set(target, propKey, value) {
|
|
553
|
-
return target.set(target, propKey, value);
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
class CustomMethods {
|
|
557
|
-
constructor(editor2) {
|
|
558
|
-
this.editor = editor2;
|
|
559
|
-
}
|
|
560
|
-
focus() {
|
|
561
|
-
ReactEditor.focus(this.editor);
|
|
562
|
-
}
|
|
563
|
-
blur() {
|
|
564
|
-
ReactEditor.blur(this.editor);
|
|
565
|
-
}
|
|
566
|
-
get value() {
|
|
567
|
-
return getFullEditorTextWithNewlines(this.editor);
|
|
568
|
-
}
|
|
569
|
-
set value(value) {
|
|
570
|
-
replaceEditorText(this.editor, value);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);
|
|
574
|
-
const customMethods = new CustomMethods(editor);
|
|
575
|
-
const combined = new Combined(customMethods, editorHtmlElement);
|
|
576
|
-
return new Proxy(combined, handler);
|
|
577
|
-
},
|
|
578
|
-
[editor]
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// src/lib/slatejs-edits/add-autocompletions.ts
|
|
583
|
-
import { Transforms as Transforms3 } from "slate";
|
|
584
|
-
function addAutocompletionsToEditor(editor, newSuggestion, point) {
|
|
585
|
-
const editorPosition = editor.selection;
|
|
586
|
-
Transforms3.insertNodes(
|
|
587
|
-
editor,
|
|
588
|
-
[
|
|
589
|
-
{
|
|
590
|
-
type: "suggestion",
|
|
591
|
-
inline: true,
|
|
592
|
-
content: newSuggestion,
|
|
593
|
-
children: [{ text: "" }]
|
|
594
|
-
}
|
|
595
|
-
],
|
|
596
|
-
{
|
|
597
|
-
at: point
|
|
598
|
-
}
|
|
599
|
-
);
|
|
600
|
-
if (editorPosition) {
|
|
601
|
-
editor.selection = editorPosition;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/lib/slatejs-edits/clear-autocompletions.ts
|
|
606
|
-
import { Element as Element3, Node as Node2, Transforms as Transforms4 } from "slate";
|
|
607
|
-
function clearAutocompletionsFromEditor(editor) {
|
|
608
|
-
const paths = [];
|
|
609
|
-
for (const [node, path] of Node2.nodes(editor)) {
|
|
610
|
-
if (Element3.isElement(node) && node.type === "suggestion") {
|
|
611
|
-
paths.push(path);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
for (const path of paths) {
|
|
615
|
-
try {
|
|
616
|
-
Transforms4.removeNodes(editor, { at: path });
|
|
617
|
-
} catch (e) {
|
|
618
|
-
console.log(
|
|
619
|
-
"CopilotTextarea.clearAutocompletionsFromEditor: error removing node",
|
|
620
|
-
e
|
|
621
|
-
);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// src/types/base/base-autosuggestions-config.tsx
|
|
627
|
-
var defaultBaseAutosuggestionsConfig = {
|
|
628
|
-
debounceTime: 250,
|
|
629
|
-
acceptAutosuggestionKey: "Tab",
|
|
630
|
-
disableWhenEmpty: true,
|
|
631
|
-
disabled: false,
|
|
632
|
-
temporarilyDisableWhenMovingCursorWithoutChangingText: true
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
636
|
-
import { useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
|
|
637
|
-
import { Transforms as Transforms5 } from "slate";
|
|
638
|
-
import { useSlate, useSlateSelection } from "slate-react";
|
|
639
|
-
|
|
640
|
-
// src/hooks/misc/use-autosize-textarea.tsx
|
|
641
|
-
import { useEffect as useEffect2 } from "react";
|
|
642
|
-
var useAutosizeTextArea = (textAreaRef, value) => {
|
|
643
|
-
useEffect2(() => {
|
|
644
|
-
if (textAreaRef.current !== null) {
|
|
645
|
-
textAreaRef.current.style.height = "0px";
|
|
646
|
-
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
647
|
-
textAreaRef.current.style.height = scrollHeight + "px";
|
|
648
|
-
}
|
|
649
|
-
}, [textAreaRef, value]);
|
|
650
|
-
};
|
|
651
|
-
var use_autosize_textarea_default = useAutosizeTextArea;
|
|
652
|
-
|
|
653
|
-
// src/components/source-search-box/source-search-box.tsx
|
|
654
|
-
import { useState as useState2 } from "react";
|
|
655
|
-
|
|
656
|
-
// src/components/ui/command.tsx
|
|
657
|
-
import * as React2 from "react";
|
|
658
|
-
import { Command as CommandPrimitive } from "cmdk";
|
|
659
|
-
import { jsx } from "react/jsx-runtime";
|
|
660
|
-
"use client";
|
|
661
|
-
var Command = React2.forwardRef((_a, ref) => {
|
|
662
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
663
|
-
return /* @__PURE__ */ jsx(CommandPrimitive, __spreadValues({
|
|
664
|
-
ref,
|
|
665
|
-
className: cn(
|
|
666
|
-
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
667
|
-
className
|
|
668
|
-
)
|
|
669
|
-
}, props));
|
|
670
|
-
});
|
|
671
|
-
Command.displayName = CommandPrimitive.displayName;
|
|
672
|
-
var CommandInput = React2.forwardRef((_a, ref) => {
|
|
673
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
674
|
-
return /* @__PURE__ */ jsx("div", {
|
|
675
|
-
className: "flex items-center border-b px-3",
|
|
676
|
-
"cmdk-input-wrapper": "",
|
|
677
|
-
children: /* @__PURE__ */ jsx(CommandPrimitive.Input, __spreadValues({
|
|
678
|
-
ref,
|
|
679
|
-
className: cn(
|
|
680
|
-
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
681
|
-
className
|
|
682
|
-
)
|
|
683
|
-
}, props))
|
|
684
|
-
});
|
|
685
|
-
});
|
|
686
|
-
CommandInput.displayName = CommandPrimitive.Input.displayName;
|
|
687
|
-
var CommandList = React2.forwardRef((_a, ref) => {
|
|
688
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
689
|
-
return /* @__PURE__ */ jsx(CommandPrimitive.List, __spreadValues({
|
|
690
|
-
ref,
|
|
691
|
-
className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)
|
|
692
|
-
}, props));
|
|
693
|
-
});
|
|
694
|
-
CommandList.displayName = CommandPrimitive.List.displayName;
|
|
695
|
-
var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ jsx(CommandPrimitive.Empty, __spreadValues({
|
|
696
|
-
ref,
|
|
697
|
-
className: "py-6 text-center text-sm"
|
|
698
|
-
}, props)));
|
|
699
|
-
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
|
|
700
|
-
var CommandGroup = React2.forwardRef((_a, ref) => {
|
|
701
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
702
|
-
return /* @__PURE__ */ jsx(CommandPrimitive.Group, __spreadValues({
|
|
703
|
-
ref,
|
|
704
|
-
className: cn(
|
|
705
|
-
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
|
706
|
-
className
|
|
707
|
-
)
|
|
708
|
-
}, props));
|
|
709
|
-
});
|
|
710
|
-
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
|
711
|
-
var CommandSeparator = React2.forwardRef((_a, ref) => {
|
|
712
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
713
|
-
return /* @__PURE__ */ jsx(CommandPrimitive.Separator, __spreadValues({
|
|
714
|
-
ref,
|
|
715
|
-
className: cn("-mx-1 h-px bg-border", className)
|
|
716
|
-
}, props));
|
|
717
|
-
});
|
|
718
|
-
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
|
|
719
|
-
var CommandItem = React2.forwardRef((_a, ref) => {
|
|
720
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
721
|
-
return /* @__PURE__ */ jsx(CommandPrimitive.Item, __spreadValues({
|
|
722
|
-
ref,
|
|
723
|
-
className: cn(
|
|
724
|
-
"relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
725
|
-
className
|
|
726
|
-
)
|
|
727
|
-
}, props));
|
|
728
|
-
});
|
|
729
|
-
CommandItem.displayName = CommandPrimitive.Item.displayName;
|
|
730
|
-
var CommandShortcut = (_a) => {
|
|
731
|
-
var _b = _a, {
|
|
732
|
-
className
|
|
733
|
-
} = _b, props = __objRest(_b, [
|
|
734
|
-
"className"
|
|
735
|
-
]);
|
|
736
|
-
return /* @__PURE__ */ jsx("span", __spreadValues({
|
|
737
|
-
className: cn(
|
|
738
|
-
"ml-auto text-xs tracking-widest text-muted-foreground",
|
|
739
|
-
className
|
|
740
|
-
)
|
|
741
|
-
}, props));
|
|
742
|
-
};
|
|
743
|
-
CommandShortcut.displayName = "CommandShortcut";
|
|
744
|
-
|
|
745
|
-
// src/components/source-search-box/source-search-box.tsx
|
|
746
|
-
import {
|
|
747
|
-
Calculator,
|
|
748
|
-
Calendar,
|
|
749
|
-
Smile
|
|
750
|
-
} from "lucide-react";
|
|
751
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
752
|
-
function SourceSearchBox(props) {
|
|
753
|
-
const [selectedValue, setSelectedValue] = useState2("");
|
|
754
|
-
return /* @__PURE__ */ jsxs(Command, {
|
|
755
|
-
className: "rounded-lg border shadow-md",
|
|
756
|
-
value: selectedValue,
|
|
757
|
-
onValueChange: (value) => {
|
|
758
|
-
setSelectedValue(value);
|
|
759
|
-
},
|
|
760
|
-
filter: (value, search) => {
|
|
761
|
-
if (props.searchTerm === "")
|
|
762
|
-
return 1;
|
|
763
|
-
if (value.startsWith(props.searchTerm))
|
|
764
|
-
return 1;
|
|
765
|
-
return 0;
|
|
766
|
-
},
|
|
767
|
-
children: [
|
|
768
|
-
/* @__PURE__ */ jsx2(CommandInput, {
|
|
769
|
-
value: props.searchTerm,
|
|
770
|
-
className: "rounded-t-lg hidden",
|
|
771
|
-
placeholder: "Search for a command..."
|
|
772
|
-
}),
|
|
773
|
-
/* @__PURE__ */ jsxs(CommandList, {
|
|
774
|
-
children: [
|
|
775
|
-
/* @__PURE__ */ jsx2(CommandEmpty, {
|
|
776
|
-
children: "No results found."
|
|
777
|
-
}),
|
|
778
|
-
/* @__PURE__ */ jsx2(CommandGroup, {
|
|
779
|
-
heading: "Recents",
|
|
780
|
-
children: props.recentFiles.map((filePointer) => {
|
|
781
|
-
return /* @__PURE__ */ jsx2(CommandItem, {
|
|
782
|
-
value: filePointer.name,
|
|
783
|
-
onSelect: (value) => {
|
|
784
|
-
console.log(filePointer.name);
|
|
785
|
-
props.onSelectedFile(filePointer);
|
|
786
|
-
},
|
|
787
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
788
|
-
className: "flex flex-row gap-3 items-center",
|
|
789
|
-
children: [
|
|
790
|
-
/* @__PURE__ */ jsx2(Logo, {
|
|
791
|
-
size: "30px",
|
|
792
|
-
children: /* @__PURE__ */ jsx2(IconForFilePointer, {
|
|
793
|
-
filePointer,
|
|
794
|
-
className: "mx-auto my-auto"
|
|
795
|
-
})
|
|
796
|
-
}),
|
|
797
|
-
filePointer.name
|
|
798
|
-
]
|
|
799
|
-
})
|
|
800
|
-
}, `word-${filePointer.sourceApplication}.${filePointer.name}`);
|
|
801
|
-
})
|
|
802
|
-
}),
|
|
803
|
-
/* @__PURE__ */ jsxs(CommandGroup, {
|
|
804
|
-
heading: "Suggestions",
|
|
805
|
-
children: [
|
|
806
|
-
/* @__PURE__ */ jsxs(CommandItem, {
|
|
807
|
-
onSelect: (value) => {
|
|
808
|
-
console.log(value);
|
|
809
|
-
console.log(value);
|
|
810
|
-
},
|
|
811
|
-
children: [
|
|
812
|
-
/* @__PURE__ */ jsx2(Calendar, {
|
|
813
|
-
className: "mr-2 h-4 w-4"
|
|
814
|
-
}),
|
|
815
|
-
/* @__PURE__ */ jsx2("span", {
|
|
816
|
-
children: "Calendar"
|
|
817
|
-
})
|
|
818
|
-
]
|
|
819
|
-
}),
|
|
820
|
-
/* @__PURE__ */ jsxs(CommandItem, {
|
|
821
|
-
children: [
|
|
822
|
-
/* @__PURE__ */ jsx2(Smile, {
|
|
823
|
-
className: "mr-2 h-4 w-4"
|
|
824
|
-
}),
|
|
825
|
-
/* @__PURE__ */ jsx2("span", {
|
|
826
|
-
children: "Search Emoji"
|
|
827
|
-
})
|
|
828
|
-
]
|
|
829
|
-
}),
|
|
830
|
-
/* @__PURE__ */ jsxs(CommandItem, {
|
|
831
|
-
children: [
|
|
832
|
-
/* @__PURE__ */ jsx2(Calculator, {
|
|
833
|
-
className: "mr-2 h-4 w-4"
|
|
834
|
-
}),
|
|
835
|
-
/* @__PURE__ */ jsx2("span", {
|
|
836
|
-
children: "Calculator"
|
|
837
|
-
})
|
|
838
|
-
]
|
|
839
|
-
})
|
|
840
|
-
]
|
|
841
|
-
}),
|
|
842
|
-
/* @__PURE__ */ jsx2(CommandSeparator, {})
|
|
843
|
-
]
|
|
844
|
-
})
|
|
845
|
-
]
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
function Logo({
|
|
849
|
-
children,
|
|
850
|
-
size = "30px"
|
|
851
|
-
}) {
|
|
852
|
-
return /* @__PURE__ */ jsx2("div", {
|
|
853
|
-
className: "flex items-center justify-center",
|
|
854
|
-
style: { width: size, height: size },
|
|
855
|
-
children
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// src/components/ui/button.tsx
|
|
860
|
-
import * as React3 from "react";
|
|
861
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
862
|
-
import { cva } from "class-variance-authority";
|
|
863
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
864
|
-
var buttonVariants = cva(
|
|
865
|
-
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
866
|
-
{
|
|
867
|
-
variants: {
|
|
868
|
-
variant: {
|
|
869
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
870
|
-
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
871
|
-
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
872
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
873
|
-
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
874
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
875
|
-
},
|
|
876
|
-
size: {
|
|
877
|
-
default: "h-10 px-4 py-2",
|
|
878
|
-
sm: "h-9 rounded-md px-3",
|
|
879
|
-
lg: "h-11 rounded-md px-8",
|
|
880
|
-
icon: "h-10 w-10"
|
|
881
|
-
}
|
|
882
|
-
},
|
|
883
|
-
defaultVariants: {
|
|
884
|
-
variant: "default",
|
|
885
|
-
size: "default"
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
);
|
|
889
|
-
var Button = React3.forwardRef(
|
|
890
|
-
(_a, ref) => {
|
|
891
|
-
var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
|
|
892
|
-
const Comp = asChild ? Slot : "button";
|
|
893
|
-
return /* @__PURE__ */ jsx3(Comp, __spreadValues({
|
|
894
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
895
|
-
ref
|
|
896
|
-
}, props));
|
|
897
|
-
}
|
|
898
|
-
);
|
|
899
|
-
Button.displayName = "Button";
|
|
900
|
-
|
|
901
|
-
// src/components/ui/label.tsx
|
|
902
|
-
import * as React4 from "react";
|
|
903
|
-
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
904
|
-
import { cva as cva2 } from "class-variance-authority";
|
|
905
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
906
|
-
"use client";
|
|
907
|
-
var labelVariants = cva2(
|
|
908
|
-
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
909
|
-
);
|
|
910
|
-
var Label = React4.forwardRef((_a, ref) => {
|
|
911
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
912
|
-
return /* @__PURE__ */ jsx4(LabelPrimitive.Root, __spreadValues({
|
|
913
|
-
ref,
|
|
914
|
-
className: cn(labelVariants(), className)
|
|
915
|
-
}, props));
|
|
916
|
-
});
|
|
917
|
-
Label.displayName = LabelPrimitive.Root.displayName;
|
|
918
|
-
|
|
919
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
920
|
-
import { useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
921
|
-
import Chip from "@mui/material/Chip";
|
|
922
|
-
import Avatar from "@mui/material/Avatar";
|
|
923
|
-
|
|
924
|
-
// src/lib/stream-promise-flatten.ts
|
|
925
|
-
function streamPromiseFlatten(promise) {
|
|
926
|
-
return new ReadableStream({
|
|
927
|
-
start(controller) {
|
|
928
|
-
return __async(this, null, function* () {
|
|
929
|
-
try {
|
|
930
|
-
const stream = yield promise;
|
|
931
|
-
const reader = stream.getReader();
|
|
932
|
-
while (true) {
|
|
933
|
-
const { done, value } = yield reader.read();
|
|
934
|
-
if (done) {
|
|
935
|
-
controller.close();
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
controller.enqueue(value);
|
|
939
|
-
}
|
|
940
|
-
} catch (error) {
|
|
941
|
-
controller.error(error);
|
|
942
|
-
}
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
|
|
949
|
-
import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
950
|
-
var HoveringInsertionPromptBoxCore = ({ performInsertion, state, insertionOrEditingFunction }) => {
|
|
951
|
-
const [editSuggestion, setEditSuggestion] = useState3("");
|
|
952
|
-
const [suggestionIsLoading, setSuggestionIsLoading] = useState3(false);
|
|
953
|
-
const [adjustmentPrompt, setAdjustmentPrompt] = useState3("");
|
|
954
|
-
const [generatingSuggestion, setGeneratingSuggestion] = useState3(null);
|
|
955
|
-
const adjustmentTextAreaRef = useRef(null);
|
|
956
|
-
const suggestionTextAreaRef = useRef(null);
|
|
957
|
-
const [filePointers, setFilePointers] = useState3([]);
|
|
958
|
-
use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
|
|
959
|
-
use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
|
|
960
|
-
useEffect3(() => {
|
|
961
|
-
var _a;
|
|
962
|
-
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
963
|
-
}, []);
|
|
964
|
-
useEffect3(() => {
|
|
965
|
-
if (!generatingSuggestion) {
|
|
966
|
-
return;
|
|
967
|
-
}
|
|
968
|
-
if (generatingSuggestion.locked) {
|
|
969
|
-
return;
|
|
970
|
-
}
|
|
971
|
-
setEditSuggestion("");
|
|
972
|
-
const reader = generatingSuggestion.getReader();
|
|
973
|
-
const read = () => __async(void 0, null, function* () {
|
|
974
|
-
setSuggestionIsLoading(true);
|
|
975
|
-
while (true) {
|
|
976
|
-
const { done, value } = yield reader.read();
|
|
977
|
-
if (done) {
|
|
978
|
-
break;
|
|
979
|
-
}
|
|
980
|
-
setEditSuggestion((prev) => {
|
|
981
|
-
const newSuggestion = prev + value;
|
|
982
|
-
if (suggestionTextAreaRef.current) {
|
|
983
|
-
suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
|
|
984
|
-
}
|
|
985
|
-
return newSuggestion;
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
setSuggestionIsLoading(false);
|
|
989
|
-
});
|
|
990
|
-
read();
|
|
991
|
-
return () => {
|
|
992
|
-
const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
|
|
993
|
-
try {
|
|
994
|
-
yield reader.closed;
|
|
995
|
-
} catch (e) {
|
|
996
|
-
reader.releaseLock();
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
releaseLockIfNotClosed();
|
|
1000
|
-
};
|
|
1001
|
-
}, [generatingSuggestion]);
|
|
1002
|
-
const begingGeneratingAdjustment = () => __async(void 0, null, function* () {
|
|
1003
|
-
if (!adjustmentPrompt.trim()) {
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
let editorState2 = state.editorState;
|
|
1007
|
-
if (editSuggestion !== "") {
|
|
1008
|
-
editorState2.selectedText = editSuggestion;
|
|
1009
|
-
}
|
|
1010
|
-
const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
|
|
1011
|
-
editorState2,
|
|
1012
|
-
adjustmentPrompt,
|
|
1013
|
-
new AbortController().signal
|
|
1014
|
-
);
|
|
1015
|
-
const adjustmentSuggestionTextStream = streamPromiseFlatten(
|
|
1016
|
-
adjustmentSuggestionTextStreamPromise
|
|
1017
|
-
);
|
|
1018
|
-
setGeneratingSuggestion(adjustmentSuggestionTextStream);
|
|
1019
|
-
});
|
|
1020
|
-
const isLoading = suggestionIsLoading;
|
|
1021
|
-
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
1022
|
-
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
1023
|
-
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
1024
|
-
const AdjustmentPromptComponent = /* @__PURE__ */ jsxs2(Fragment, {
|
|
1025
|
-
children: [
|
|
1026
|
-
/* @__PURE__ */ jsx5(Label, {
|
|
1027
|
-
className: "",
|
|
1028
|
-
children: adjustmentLabel
|
|
1029
|
-
}),
|
|
1030
|
-
/* @__PURE__ */ jsxs2("div", {
|
|
1031
|
-
className: "relative w-full flex items-center",
|
|
1032
|
-
children: [
|
|
1033
|
-
/* @__PURE__ */ jsx5("textarea", {
|
|
1034
|
-
disabled: suggestionIsLoading,
|
|
1035
|
-
ref: adjustmentTextAreaRef,
|
|
1036
|
-
value: adjustmentPrompt,
|
|
1037
|
-
onChange: (e) => setAdjustmentPrompt(e.target.value),
|
|
1038
|
-
onKeyDown: (e) => {
|
|
1039
|
-
if (e.key === "Enter" && e.shiftKey) {
|
|
1040
|
-
e.preventDefault();
|
|
1041
|
-
setAdjustmentPrompt(adjustmentPrompt + "\n");
|
|
1042
|
-
} else if (e.key === "Enter") {
|
|
1043
|
-
e.preventDefault();
|
|
1044
|
-
begingGeneratingAdjustment();
|
|
1045
|
-
}
|
|
1046
|
-
},
|
|
1047
|
-
placeholder,
|
|
1048
|
-
style: { minHeight: "3rem" },
|
|
1049
|
-
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]",
|
|
1050
|
-
rows: 1
|
|
1051
|
-
}),
|
|
1052
|
-
/* @__PURE__ */ jsx5("button", {
|
|
1053
|
-
onClick: begingGeneratingAdjustment,
|
|
1054
|
-
className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
|
|
1055
|
-
children: /* @__PURE__ */ jsx5("i", {
|
|
1056
|
-
className: "material-icons",
|
|
1057
|
-
children: "arrow_forward"
|
|
1058
|
-
})
|
|
1059
|
-
})
|
|
1060
|
-
]
|
|
1061
|
-
})
|
|
1062
|
-
]
|
|
1063
|
-
});
|
|
1064
|
-
const SuggestionComponent = /* @__PURE__ */ jsxs2(Fragment, {
|
|
1065
|
-
children: [
|
|
1066
|
-
/* @__PURE__ */ jsxs2("div", {
|
|
1067
|
-
className: "flex justify-between items-end w-full",
|
|
1068
|
-
children: [
|
|
1069
|
-
/* @__PURE__ */ jsx5(Label, {
|
|
1070
|
-
className: "mt-4",
|
|
1071
|
-
children: "Suggested:"
|
|
1072
|
-
}),
|
|
1073
|
-
/* @__PURE__ */ jsx5("div", {
|
|
1074
|
-
className: "ml-auto",
|
|
1075
|
-
children: isLoading && /* @__PURE__ */ jsx5("div", {
|
|
1076
|
-
className: "flex justify-center items-center",
|
|
1077
|
-
children: /* @__PURE__ */ jsx5("div", {
|
|
1078
|
-
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]",
|
|
1079
|
-
role: "status",
|
|
1080
|
-
children: /* @__PURE__ */ jsx5("span", {
|
|
1081
|
-
className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]",
|
|
1082
|
-
children: "Loading..."
|
|
1083
|
-
})
|
|
1084
|
-
})
|
|
1085
|
-
})
|
|
1086
|
-
})
|
|
1087
|
-
]
|
|
1088
|
-
}),
|
|
1089
|
-
/* @__PURE__ */ jsx5("textarea", {
|
|
1090
|
-
ref: suggestionTextAreaRef,
|
|
1091
|
-
value: editSuggestion,
|
|
1092
|
-
disabled: suggestionIsLoading,
|
|
1093
|
-
onChange: (e) => setEditSuggestion(e.target.value),
|
|
1094
|
-
className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
|
|
1095
|
-
style: { overflow: "auto", maxHeight: "10em" }
|
|
1096
|
-
})
|
|
1097
|
-
]
|
|
1098
|
-
});
|
|
1099
|
-
const SubmitComponent = /* @__PURE__ */ jsx5("div", {
|
|
1100
|
-
className: "flex w-full gap-4 justify-start",
|
|
1101
|
-
children: /* @__PURE__ */ jsxs2(Button, {
|
|
1102
|
-
className: " bg-green-700 text-white",
|
|
1103
|
-
onClick: () => {
|
|
1104
|
-
performInsertion(editSuggestion);
|
|
1105
|
-
},
|
|
1106
|
-
children: [
|
|
1107
|
-
"Insert ",
|
|
1108
|
-
/* @__PURE__ */ jsx5("i", {
|
|
1109
|
-
className: "material-icons",
|
|
1110
|
-
children: "check"
|
|
1111
|
-
})
|
|
1112
|
-
]
|
|
1113
|
-
})
|
|
1114
|
-
});
|
|
1115
|
-
const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
|
|
1116
|
-
const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
|
|
1117
|
-
return /* @__PURE__ */ jsxs2("div", {
|
|
1118
|
-
className: "w-full flex flex-col items-start relative gap-2",
|
|
1119
|
-
children: [
|
|
1120
|
-
AdjustmentPromptComponent,
|
|
1121
|
-
filePointers.length > 0 && /* @__PURE__ */ jsx5(IncludedFilesPreview, {
|
|
1122
|
-
includedFiles: filePointers,
|
|
1123
|
-
setIncludedFiles: setFilePointers
|
|
1124
|
-
}),
|
|
1125
|
-
sourceSearchWord !== void 0 && /* @__PURE__ */ jsx5(SourceSearchBox, {
|
|
1126
|
-
searchTerm: sourceSearchWord,
|
|
1127
|
-
recentFiles: mockFiles,
|
|
1128
|
-
onSelectedFile: (filePointer) => {
|
|
1129
|
-
var _a;
|
|
1130
|
-
setAdjustmentPrompt(
|
|
1131
|
-
adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), "")
|
|
1132
|
-
);
|
|
1133
|
-
setFilePointers((prev) => [...prev, filePointer]);
|
|
1134
|
-
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
1135
|
-
}
|
|
1136
|
-
}),
|
|
1137
|
-
generatingSuggestion ? SuggestionComponent : null,
|
|
1138
|
-
generatingSuggestion ? SubmitComponent : null
|
|
1139
|
-
]
|
|
1140
|
-
});
|
|
1141
|
-
};
|
|
1142
|
-
var IncludedFilesPreview = ({
|
|
1143
|
-
includedFiles,
|
|
1144
|
-
setIncludedFiles
|
|
1145
|
-
}) => {
|
|
1146
|
-
return /* @__PURE__ */ jsxs2("div", {
|
|
1147
|
-
className: "flex flex-col gap-2 mt-2",
|
|
1148
|
-
children: [
|
|
1149
|
-
/* @__PURE__ */ jsx5(Label, {
|
|
1150
|
-
className: "",
|
|
1151
|
-
children: "Included context:"
|
|
1152
|
-
}),
|
|
1153
|
-
/* @__PURE__ */ jsx5("div", {
|
|
1154
|
-
className: "flex flex-wrap gap-2",
|
|
1155
|
-
children: includedFiles.map((filePointer, index) => {
|
|
1156
|
-
return /* @__PURE__ */ jsx5(FileChipPreview, {
|
|
1157
|
-
filePointer,
|
|
1158
|
-
onDelete: () => {
|
|
1159
|
-
setIncludedFiles(
|
|
1160
|
-
(prev) => prev.filter((fp) => fp !== filePointer)
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
}, `file-${filePointer.sourceApplication}.${filePointer.name}`);
|
|
1164
|
-
})
|
|
1165
|
-
})
|
|
1166
|
-
]
|
|
1167
|
-
});
|
|
1168
|
-
};
|
|
1169
|
-
var FileChipPreview = ({
|
|
1170
|
-
filePointer,
|
|
1171
|
-
onDelete
|
|
1172
|
-
}) => {
|
|
1173
|
-
return /* @__PURE__ */ jsx5(Chip, {
|
|
1174
|
-
label: filePointer.name,
|
|
1175
|
-
onDelete,
|
|
1176
|
-
avatar: /* @__PURE__ */ jsx5(Avatar, {
|
|
1177
|
-
sx: { backgroundColor: "transparent" },
|
|
1178
|
-
children: /* @__PURE__ */ jsx5(IconForFilePointer, {
|
|
1179
|
-
filePointer,
|
|
1180
|
-
className: "w-4 h-4 object-contain"
|
|
1181
|
-
})
|
|
1182
|
-
})
|
|
1183
|
-
});
|
|
1184
|
-
};
|
|
1185
|
-
function IconForFilePointer({
|
|
1186
|
-
filePointer,
|
|
1187
|
-
className
|
|
1188
|
-
}) {
|
|
1189
|
-
if (filePointer.sourceApplication === "Salesforce") {
|
|
1190
|
-
return /* @__PURE__ */ jsx5(IconSalesforce, {
|
|
1191
|
-
className
|
|
1192
|
-
});
|
|
1193
|
-
} else {
|
|
1194
|
-
return /* @__PURE__ */ jsx5(IconSalesforce, {
|
|
1195
|
-
className
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
function IconSalesforce(_a) {
|
|
1200
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1201
|
-
return /* @__PURE__ */ jsxs2("svg", __spreadProps(__spreadValues({
|
|
1202
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1203
|
-
xmlnsXlink: "http://www.w3.org/1999/xlink",
|
|
1204
|
-
preserveAspectRatio: "xMidYMid meet",
|
|
1205
|
-
viewBox: "0 0 273 191"
|
|
1206
|
-
}, props), {
|
|
1207
|
-
children: [
|
|
1208
|
-
/* @__PURE__ */ jsx5("title", {
|
|
1209
|
-
children: "Salesforce.com logo"
|
|
1210
|
-
}),
|
|
1211
|
-
/* @__PURE__ */ jsx5("defs", {
|
|
1212
|
-
children: /* @__PURE__ */ jsx5("path", {
|
|
1213
|
-
id: "a",
|
|
1214
|
-
d: "M.06.5h272v190H.06z"
|
|
1215
|
-
})
|
|
1216
|
-
}),
|
|
1217
|
-
/* @__PURE__ */ jsxs2("g", {
|
|
1218
|
-
fillRule: "evenodd",
|
|
1219
|
-
children: [
|
|
1220
|
-
/* @__PURE__ */ jsx5("mask", {
|
|
1221
|
-
id: "b",
|
|
1222
|
-
fill: "#fff",
|
|
1223
|
-
children: /* @__PURE__ */ jsx5("use", {
|
|
1224
|
-
xlinkHref: "#a"
|
|
1225
|
-
})
|
|
1226
|
-
}),
|
|
1227
|
-
/* @__PURE__ */ jsx5("path", {
|
|
1228
|
-
fill: "#00A1E0",
|
|
1229
|
-
d: "M113 21.3c8.78-9.14 21-14.8 34.5-14.8 18 0 33.6 10 42 24.9a58 58 0 0 1 23.7-5.05c32.4 0 58.7 26.5 58.7 59.2s-26.3 59.2-58.7 59.2c-3.96 0-7.82-.398-11.6-1.15-7.35 13.1-21.4 22-37.4 22a42.7 42.7 0 0 1-18.8-4.32c-7.45 17.5-24.8 29.8-45 29.8-21.1 0-39-13.3-45.9-32a45.1 45.1 0 0 1-9.34.972c-25.1 0-45.4-20.6-45.4-45.9 0-17 9.14-31.8 22.7-39.8a52.6 52.6 0 0 1-4.35-21c0-29.2 23.7-52.8 52.9-52.8 17.1 0 32.4 8.15 42 20.8",
|
|
1230
|
-
mask: "url(#b)"
|
|
1231
|
-
}),
|
|
1232
|
-
/* @__PURE__ */ jsx5("path", {
|
|
1233
|
-
fill: "#FFFFFE",
|
|
1234
|
-
d: "M39.4 99.3c-.171.446.061.539.116.618.511.37 1.03.638 1.55.939 2.78 1.47 5.4 1.9 8.14 1.9 5.58 0 9.05-2.97 9.05-7.75v-.094c0-4.42-3.92-6.03-7.58-7.18l-.479-.155c-2.77-.898-5.16-1.68-5.16-3.5v-.093c0-1.56 1.4-2.71 3.56-2.71 2.4 0 5.26.799 7.09 1.81 0 0 .542.35.739-.173.107-.283 1.04-2.78 1.14-3.06.106-.293-.08-.514-.271-.628-2.1-1.28-5-2.15-8-2.15l-.557.002c-5.11 0-8.68 3.09-8.68 7.51v.095c0 4.66 3.94 6.18 7.62 7.23l.592.184c2.68.824 5 1.54 5 3.42v.094c0 1.73-1.51 3.02-3.93 3.02-.941 0-3.94-.016-7.19-2.07-.393-.229-.617-.394-.92-.579-.16-.097-.56-.272-.734.252l-1.1 3.06m81.7 0c-.171.446.061.539.118.618.509.37 1.03.638 1.55.939 2.78 1.47 5.4 1.9 8.14 1.9 5.58 0 9.05-2.97 9.05-7.75v-.094c0-4.42-3.91-6.03-7.58-7.18l-.479-.155c-2.77-.898-5.16-1.68-5.16-3.5v-.093c0-1.56 1.4-2.71 3.56-2.71 2.4 0 5.25.799 7.09 1.81 0 0 .542.35.74-.173.106-.283 1.04-2.78 1.13-3.06.107-.293-.08-.514-.27-.628-2.1-1.28-5-2.15-8-2.15l-.558.002c-5.11 0-8.68 3.09-8.68 7.51v.095c0 4.66 3.94 6.18 7.62 7.23l.591.184c2.69.824 5 1.54 5 3.42v.094c0 1.73-1.51 3.02-3.93 3.02-.943 0-3.95-.016-7.19-2.07-.393-.229-.623-.387-.921-.579-.101-.064-.572-.248-.733.252l-1.1 3.06m55.8-9.36c0 2.7-.504 4.83-1.49 6.34-.984 1.49-2.47 2.22-4.54 2.22s-3.55-.724-4.52-2.21c-.977-1.5-1.47-3.64-1.47-6.34 0-2.7.496-4.82 1.47-6.31.968-1.48 2.44-2.19 4.52-2.19s3.56.717 4.54 2.19c.992 1.49 1.49 3.61 1.49 6.31m4.66-5.01c-.459-1.55-1.17-2.91-2.12-4.05a10.151 10.151 0 0 0-3.58-2.72c-1.42-.665-3.1-1-5-1s-3.57.337-5 1c-1.42.664-2.63 1.58-3.58 2.72-.948 1.14-1.66 2.5-2.12 4.05-.455 1.54-.686 3.22-.686 5.01 0 1.79.231 3.47.686 5.01.457 1.55 1.17 2.91 2.12 4.05.951 1.14 2.16 2.05 3.58 2.7 1.43.648 3.11.978 5 .978 1.89 0 3.57-.33 4.99-.978 1.42-.648 2.63-1.56 3.58-2.7.949-1.14 1.66-2.5 2.12-4.05.454-1.54.685-3.22.685-5.01 0-1.78-.231-3.47-.685-5.01m38.3 12.8c-.153-.453-.595-.282-.595-.282-.677.259-1.4.499-2.17.619-.776.122-1.64.183-2.55.183-2.25 0-4.05-.671-5.33-2-1.29-1.33-2.01-3.47-2-6.37.007-2.64.645-4.62 1.79-6.14 1.13-1.5 2.87-2.28 5.17-2.28 1.92 0 3.39.223 4.93.705 0 0 .365.159.54-.322.409-1.13.711-1.94 1.15-3.18.124-.355-.18-.505-.291-.548-.604-.236-2.03-.623-3.11-.786-1.01-.154-2.18-.234-3.5-.234-1.96 0-3.7.335-5.19.999-1.49.663-2.75 1.58-3.75 2.72-1 1.14-1.76 2.5-2.27 4.05-.505 1.54-.76 3.23-.76 5.02 0 3.86 1.04 6.99 3.1 9.28 2.06 2.3 5.16 3.46 9.2 3.46 2.39 0 4.84-.483 6.6-1.18 0 0 .336-.162.19-.554l-1.15-3.16m8.15-10.4c.223-1.5.634-2.75 1.28-3.72.967-1.48 2.44-2.29 4.51-2.29s3.44.814 4.42 2.29c.65.975.934 2.27 1.04 3.72l-11.3-.002zm15.7-3.3c-.397-1.49-1.38-3-2.02-3.69-1.02-1.09-2.01-1.86-3-2.28a11.5 11.5 0 0 0-4.52-.917c-1.97 0-3.76.333-5.21 1.01-1.45.682-2.67 1.61-3.63 2.77-.959 1.16-1.68 2.53-2.14 4.1-.46 1.55-.692 3.25-.692 5.03 0 1.82.241 3.51.715 5.04.479 1.54 1.25 2.89 2.29 4.01 1.04 1.13 2.37 2.01 3.97 2.63 1.59.615 3.52.934 5.73.927 4.56-.015 6.96-1.03 7.94-1.58.175-.098.34-.267.134-.754l-1.03-2.89c-.158-.431-.594-.275-.594-.275-1.13.422-2.73 1.18-6.48 1.17-2.45-.004-4.26-.727-5.4-1.86-1.16-1.16-1.74-2.85-1.83-5.25l15.8.012s.416-.004.459-.41c.017-.168.541-3.24-.471-6.79zm-142 3.3c.223-1.5.635-2.75 1.28-3.72.968-1.48 2.44-2.29 4.51-2.29s3.44.814 4.42 2.29c.649.975.933 2.27 1.04 3.72l-11.3-.002zm15.7-3.3c-.396-1.49-1.38-3-2.02-3.69-1.02-1.09-2.01-1.86-3-2.28a11.5 11.5 0 0 0-4.52-.917c-1.97 0-3.76.333-5.21 1.01-1.45.682-2.67 1.61-3.63 2.77-.957 1.16-1.68 2.53-2.14 4.1-.459 1.55-.69 3.25-.69 5.03 0 1.82.239 3.51.716 5.04.478 1.54 1.25 2.89 2.28 4.01 1.04 1.13 2.37 2.01 3.97 2.63 1.59.615 3.51.934 5.73.927 4.56-.015 6.96-1.03 7.94-1.58.174-.098.34-.267.133-.754l-1.03-2.89c-.159-.431-.595-.275-.595-.275-1.13.422-2.73 1.18-6.48 1.17-2.44-.004-4.26-.727-5.4-1.86-1.16-1.16-1.74-2.85-1.83-5.25l15.8.012s.416-.004.459-.41c.017-.168.541-3.24-.472-6.79zm-49.8 13.6c-.619-.494-.705-.615-.91-.936-.313-.483-.473-1.17-.473-2.05 0-1.38.46-2.38 1.41-3.05-.01.002 1.36-1.18 4.58-1.14a32 32 0 0 1 4.28.365v7.17h.002s-2 .431-4.26.567c-3.21.193-4.63-.924-4.62-.921zm6.28-11.1c-.64-.047-1.47-.07-2.46-.07-1.35 0-2.66.168-3.88.498-1.23.332-2.34.846-3.29 1.53a7.63 7.63 0 0 0-2.29 2.6c-.559 1.04-.844 2.26-.844 3.64 0 1.4.243 2.61.723 3.6a6.54 6.54 0 0 0 2.06 2.47c.877.638 1.96 1.11 3.21 1.39 1.24.283 2.64.426 4.18.426 1.62 0 3.23-.136 4.79-.399a95.1 95.1 0 0 0 3.97-.772c.526-.121 1.11-.28 1.11-.28.39-.099.36-.516.36-.516l-.009-14.4c0-3.16-.844-5.51-2.51-6.96-1.66-1.45-4.09-2.18-7.24-2.18-1.18 0-3.09.16-4.23.389 0 0-3.44.668-4.86 1.78 0 0-.312.192-.142.627l1.12 3c.139.389.518.256.518.256s.119-.047.259-.13c3.03-1.65 6.87-1.6 6.87-1.6 1.7 0 3.02.345 3.9 1.02.861.661 1.3 1.66 1.3 3.76v.667c-1.35-.196-2.6-.309-2.6-.309zm127-8.13a.428.428 0 0 0-.237-.568c-.269-.102-1.61-.385-2.64-.449-1.98-.124-3.08.21-4.07.654-.978.441-2.06 1.15-2.66 1.97l-.002-1.92c0-.264-.187-.477-.453-.477h-4.04c-.262 0-.452.213-.452.477v23.5a.48.48 0 0 0 .479.479h4.14a.479.479 0 0 0 .478-.479v-11.8c0-1.58.174-3.15.521-4.14.342-.979.807-1.76 1.38-2.32a4.79 4.79 0 0 1 1.95-1.17 7.68 7.68 0 0 1 2.12-.298c.825 0 1.73.212 1.73.212.304.034.473-.152.576-.426.271-.721 1.04-2.88 1.19-3.31"
|
|
1235
|
-
}),
|
|
1236
|
-
/* @__PURE__ */ jsx5("path", {
|
|
1237
|
-
fill: "#FFFFFE",
|
|
1238
|
-
d: "M162.201 67.548a13.258 13.258 0 0 0-1.559-.37 12.217 12.217 0 0 0-2.144-.166c-2.853 0-5.102.806-6.681 2.398-1.568 1.58-2.635 3.987-3.17 7.154l-.193 1.069h-3.581s-.437-.018-.529.459l-.588 3.28c-.041.314.094.51.514.508h3.486l-3.537 19.743c-.277 1.59-.594 2.898-.945 3.889-.346.978-.684 1.711-1.1 2.243-.403.515-.785.894-1.444 1.115-.544.183-1.17.267-1.856.267-.382 0-.89-.064-1.265-.139-.375-.074-.57-.158-.851-.276 0 0-.409-.156-.57.254-.131.335-1.06 2.89-1.17 3.206-.112.312.045.558.243.629.464.166.809.272 1.441.421.878.207 1.618.22 2.311.22 1.452 0 2.775-.204 3.872-.6 1.104-.399 2.065-1.094 2.915-2.035.919-1.015 1.497-2.078 2.05-3.528.547-1.437 1.013-3.221 1.386-5.3l3.554-20.109h5.196s.438.016.529-.459l.588-3.28c.041-.314-.093-.51-.515-.508h-5.043c.025-.114.254-1.888.833-3.558.247-.713.712-1.288 1.106-1.683a3.273 3.273 0 0 1 1.321-.822 5.48 5.48 0 0 1 1.693-.244c.475 0 .941.057 1.296.131.489.104.679.159.807.197.514.157.583.005.684-.244l1.206-3.312c.124-.356-.178-.506-.29-.55m-70.474 34.117c0 .264-.188.479-.452.479h-4.183c-.265 0-.453-.215-.453-.479V67.997c0-.263.188-.476.453-.476h4.183c.264 0 .452.213.452.476v33.668"
|
|
1239
|
-
})
|
|
1240
|
-
]
|
|
1241
|
-
})
|
|
1242
|
-
]
|
|
1243
|
-
}));
|
|
1244
|
-
}
|
|
1245
|
-
var mockFiles = [
|
|
1246
|
-
{
|
|
1247
|
-
name: "prospecting call transcript",
|
|
1248
|
-
sourceApplication: "Salesforce",
|
|
1249
|
-
getContents: () => __async(void 0, null, function* () {
|
|
1250
|
-
return "some contents";
|
|
1251
|
-
})
|
|
1252
|
-
},
|
|
1253
|
-
{
|
|
1254
|
-
name: "customer feedback",
|
|
1255
|
-
sourceApplication: "Zendesk",
|
|
1256
|
-
getContents: () => __async(void 0, null, function* () {
|
|
1257
|
-
return "some contents";
|
|
1258
|
-
})
|
|
1259
|
-
},
|
|
1260
|
-
{
|
|
1261
|
-
name: "product specifications",
|
|
1262
|
-
sourceApplication: "Google Docs",
|
|
1263
|
-
getContents: () => __async(void 0, null, function* () {
|
|
1264
|
-
return "some contents";
|
|
1265
|
-
})
|
|
1266
|
-
},
|
|
1267
|
-
{
|
|
1268
|
-
name: "meeting minutes",
|
|
1269
|
-
sourceApplication: "Microsoft Teams",
|
|
1270
|
-
getContents: () => __async(void 0, null, function* () {
|
|
1271
|
-
return "some contents";
|
|
1272
|
-
})
|
|
1273
|
-
},
|
|
1274
|
-
{
|
|
1275
|
-
name: "project plan",
|
|
1276
|
-
sourceApplication: "Trello",
|
|
1277
|
-
getContents: () => __async(void 0, null, function* () {
|
|
1278
|
-
return "some contents";
|
|
1279
|
-
})
|
|
1280
|
-
},
|
|
1281
|
-
{
|
|
1282
|
-
name: "code review comments",
|
|
1283
|
-
sourceApplication: "Github",
|
|
1284
|
-
getContents: () => __async(void 0, null, function* () {
|
|
1285
|
-
return "some contents";
|
|
1286
|
-
})
|
|
1287
|
-
}
|
|
1288
|
-
];
|
|
1289
|
-
|
|
1290
|
-
// src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
|
|
1291
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
1292
|
-
var HoveringInsertionPromptBox = (props) => {
|
|
1293
|
-
return /* @__PURE__ */ jsx6("div", {
|
|
1294
|
-
className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
|
|
1295
|
-
style: { width: "35rem" },
|
|
1296
|
-
children: /* @__PURE__ */ jsx6(HoveringInsertionPromptBoxCore, {
|
|
1297
|
-
state: {
|
|
1298
|
-
editorState: props.editorState
|
|
1299
|
-
},
|
|
1300
|
-
performInsertion: props.performInsertion,
|
|
1301
|
-
insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction
|
|
1302
|
-
})
|
|
1303
|
-
});
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
|
-
// src/components/hovering-toolbar/hovering-toolbar-components.tsx
|
|
1307
|
-
import { css, cx } from "@emotion/css";
|
|
1308
|
-
import React6 from "react";
|
|
1309
|
-
import ReactDOM from "react-dom";
|
|
1310
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1311
|
-
var Button2 = React6.forwardRef(
|
|
1312
|
-
(_a, ref) => {
|
|
1313
|
-
var _b = _a, {
|
|
1314
|
-
className,
|
|
1315
|
-
active,
|
|
1316
|
-
reversed
|
|
1317
|
-
} = _b, props = __objRest(_b, [
|
|
1318
|
-
"className",
|
|
1319
|
-
"active",
|
|
1320
|
-
"reversed"
|
|
1321
|
-
]);
|
|
1322
|
-
return /* @__PURE__ */ jsx7("span", __spreadProps(__spreadValues({}, props), {
|
|
1323
|
-
ref,
|
|
1324
|
-
className: cx(
|
|
1325
|
-
className,
|
|
1326
|
-
css`
|
|
1327
|
-
cursor: pointer;
|
|
1328
|
-
color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
|
|
1329
|
-
`
|
|
1330
|
-
)
|
|
1331
|
-
}));
|
|
1332
|
-
}
|
|
1333
|
-
);
|
|
1334
|
-
var Icon = React6.forwardRef(
|
|
1335
|
-
(_a, ref) => {
|
|
1336
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1337
|
-
return /* @__PURE__ */ jsx7("span", __spreadProps(__spreadValues({}, props), {
|
|
1338
|
-
ref,
|
|
1339
|
-
className: cx(
|
|
1340
|
-
"material-icons",
|
|
1341
|
-
className,
|
|
1342
|
-
css`
|
|
1343
|
-
font-size: 18px;
|
|
1344
|
-
vertical-align: text-bottom;
|
|
1345
|
-
`
|
|
1346
|
-
)
|
|
1347
|
-
}));
|
|
1348
|
-
}
|
|
1349
|
-
);
|
|
1350
|
-
var Menu = React6.forwardRef(
|
|
1351
|
-
(_a, ref) => {
|
|
1352
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1353
|
-
return /* @__PURE__ */ jsx7("div", __spreadProps(__spreadValues({}, props), {
|
|
1354
|
-
"data-test-id": "menu",
|
|
1355
|
-
ref,
|
|
1356
|
-
className: cx(
|
|
1357
|
-
className,
|
|
1358
|
-
css`
|
|
1359
|
-
& > * {
|
|
1360
|
-
display: inline-block;
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
& > * + * {
|
|
1364
|
-
margin-left: 15px;
|
|
1365
|
-
}
|
|
1366
|
-
`
|
|
1367
|
-
)
|
|
1368
|
-
}));
|
|
1369
|
-
}
|
|
1370
|
-
);
|
|
1371
|
-
var Portal = ({ children }) => {
|
|
1372
|
-
return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
|
|
1373
|
-
};
|
|
1374
|
-
var Toolbar = React6.forwardRef(
|
|
1375
|
-
(_a, ref) => {
|
|
1376
|
-
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
1377
|
-
return /* @__PURE__ */ jsx7(Menu, __spreadProps(__spreadValues({}, props), {
|
|
1378
|
-
ref,
|
|
1379
|
-
className: cx(
|
|
1380
|
-
className,
|
|
1381
|
-
css`
|
|
1382
|
-
position: relative;
|
|
1383
|
-
padding: 1px 18px 17px;
|
|
1384
|
-
margin: 0 -20px;
|
|
1385
|
-
border-bottom: 2px solid #eee;
|
|
1386
|
-
margin-bottom: 20px;
|
|
1387
|
-
`
|
|
1388
|
-
)
|
|
1389
|
-
}));
|
|
1390
|
-
}
|
|
1391
|
-
);
|
|
1392
|
-
|
|
1393
|
-
// src/components/hovering-toolbar/hovering-editor-provider.tsx
|
|
1394
|
-
import { createContext, useState as useState4, useContext } from "react";
|
|
1395
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1396
|
-
var HoveringEditorContext = createContext({
|
|
1397
|
-
isDisplayed: false,
|
|
1398
|
-
setIsDisplayed: () => {
|
|
1399
|
-
}
|
|
1400
|
-
});
|
|
1401
|
-
var HoveringEditorProvider = ({
|
|
1402
|
-
children
|
|
1403
|
-
}) => {
|
|
1404
|
-
const [isDisplayed, setIsDisplayed] = useState4(false);
|
|
1405
|
-
return /* @__PURE__ */ jsx8(HoveringEditorContext.Provider, {
|
|
1406
|
-
value: { isDisplayed, setIsDisplayed },
|
|
1407
|
-
children
|
|
1408
|
-
});
|
|
1409
|
-
};
|
|
1410
|
-
var useHoveringEditorContext = () => useContext(HoveringEditorContext);
|
|
1411
|
-
|
|
1412
|
-
// src/components/hovering-toolbar/hovering-toolbar.tsx
|
|
1413
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1414
|
-
var HoveringToolbar = (props) => {
|
|
1415
|
-
const ref = useRef2(null);
|
|
1416
|
-
const editor = useSlate();
|
|
1417
|
-
const selection = useSlateSelection();
|
|
1418
|
-
const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
|
|
1419
|
-
const [isClient, setIsClient] = useState5(false);
|
|
1420
|
-
useEffect4(() => {
|
|
1421
|
-
setIsClient(true);
|
|
1422
|
-
}, []);
|
|
1423
|
-
useEffect4(() => {
|
|
1424
|
-
const el = ref.current;
|
|
1425
|
-
const { selection: selection2 } = editor;
|
|
1426
|
-
if (!el) {
|
|
1427
|
-
return;
|
|
1428
|
-
}
|
|
1429
|
-
if (!selection2) {
|
|
1430
|
-
el.removeAttribute("style");
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
|
-
const domSelection = window.getSelection();
|
|
1434
|
-
if (!domSelection) {
|
|
1435
|
-
return;
|
|
1436
|
-
}
|
|
1437
|
-
const domRange = domSelection.getRangeAt(0);
|
|
1438
|
-
const rect = domRange.getBoundingClientRect();
|
|
1439
|
-
if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
|
|
1440
|
-
return;
|
|
1441
|
-
}
|
|
1442
|
-
const minGapFromEdge = 60;
|
|
1443
|
-
const verticalOffsetFromCorner = 35;
|
|
1444
|
-
const horizontalOffsetFromCorner = 15;
|
|
1445
|
-
let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
|
|
1446
|
-
if (top < minGapFromEdge) {
|
|
1447
|
-
top = rect.bottom + window.scrollY + minGapFromEdge;
|
|
1448
|
-
} else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
|
|
1449
|
-
top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
|
|
1450
|
-
}
|
|
1451
|
-
let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
|
|
1452
|
-
if (left < minGapFromEdge) {
|
|
1453
|
-
left = minGapFromEdge;
|
|
1454
|
-
} else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
|
|
1455
|
-
left = window.innerWidth - el.offsetWidth - minGapFromEdge;
|
|
1456
|
-
}
|
|
1457
|
-
el.style.opacity = "1";
|
|
1458
|
-
el.style.top = `${top}px`;
|
|
1459
|
-
el.style.left = `${left}px`;
|
|
1460
|
-
});
|
|
1461
|
-
useEffect4(() => {
|
|
1462
|
-
const handleClickOutside = (event) => {
|
|
1463
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
1464
|
-
setIsDisplayed(false);
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
1468
|
-
return () => {
|
|
1469
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
1470
|
-
};
|
|
1471
|
-
}, [ref, setIsDisplayed]);
|
|
1472
|
-
if (!isClient) {
|
|
1473
|
-
return null;
|
|
1474
|
-
}
|
|
1475
|
-
return /* @__PURE__ */ jsx9(Portal, {
|
|
1476
|
-
children: /* @__PURE__ */ jsx9(Menu, {
|
|
1477
|
-
ref,
|
|
1478
|
-
className: "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
|
|
1479
|
-
children: isDisplayed && selection && /* @__PURE__ */ jsx9(HoveringInsertionPromptBox, {
|
|
1480
|
-
editorState: editorState(editor, selection),
|
|
1481
|
-
apiConfig: props.apiConfig,
|
|
1482
|
-
closeWindow: () => {
|
|
1483
|
-
setIsDisplayed(false);
|
|
1484
|
-
},
|
|
1485
|
-
performInsertion: (insertedText) => {
|
|
1486
|
-
console.log("inserted text", insertedText);
|
|
1487
|
-
Transforms5.delete(editor, { at: selection });
|
|
1488
|
-
Transforms5.insertText(editor, insertedText, {
|
|
1489
|
-
at: selection
|
|
1490
|
-
});
|
|
1491
|
-
setIsDisplayed(false);
|
|
1492
|
-
}
|
|
1493
|
-
})
|
|
1494
|
-
})
|
|
1495
|
-
});
|
|
1496
|
-
};
|
|
1497
|
-
function editorState(editor, selection) {
|
|
1498
|
-
const textAroundCursor = getTextAroundSelection(editor);
|
|
1499
|
-
if (textAroundCursor) {
|
|
1500
|
-
return textAroundCursor;
|
|
1501
|
-
}
|
|
1502
|
-
return {
|
|
1503
|
-
textBeforeCursor: getFullEditorTextWithNewlines(editor),
|
|
1504
|
-
textAfterCursor: "",
|
|
1505
|
-
selectedText: ""
|
|
1506
|
-
};
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
// src/components/base-copilot-textarea/render-element.tsx
|
|
1510
|
-
import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1511
|
-
function makeRenderElementFunction(suggestionsStyle) {
|
|
1512
|
-
return (props) => {
|
|
1513
|
-
switch (props.element.type) {
|
|
1514
|
-
case "paragraph":
|
|
1515
|
-
return /* @__PURE__ */ jsx10(DefaultElement, __spreadValues({}, props));
|
|
1516
|
-
case "suggestion":
|
|
1517
|
-
return /* @__PURE__ */ jsx10(SuggestionElement, __spreadProps(__spreadValues({}, props), {
|
|
1518
|
-
suggestionsStyle
|
|
1519
|
-
}));
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
}
|
|
1523
|
-
var DefaultElement = (props) => {
|
|
1524
|
-
return /* @__PURE__ */ jsx10("div", __spreadProps(__spreadValues({}, props.attributes), {
|
|
1525
|
-
children: props.children
|
|
1526
|
-
}));
|
|
1527
|
-
};
|
|
1528
|
-
var SuggestionElement = (props) => {
|
|
1529
|
-
return /* @__PURE__ */ jsxs3("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
1530
|
-
style: __spreadValues({}, props.suggestionsStyle),
|
|
1531
|
-
contentEditable: false,
|
|
1532
|
-
children: [
|
|
1533
|
-
props.children,
|
|
1534
|
-
props.element.type === "suggestion" && props.element.content
|
|
1535
|
-
]
|
|
1536
|
-
}));
|
|
1537
|
-
};
|
|
1538
|
-
|
|
1539
|
-
// src/components/base-copilot-textarea/render-placeholder.tsx
|
|
1540
|
-
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1541
|
-
function makeRenderPlaceholderFunction(placeholderStyle) {
|
|
1542
|
-
return (props) => {
|
|
1543
|
-
const _a = props.attributes, { style } = _a, restAttributes = __objRest(_a, ["style"]);
|
|
1544
|
-
return /* @__PURE__ */ jsx11("div", __spreadProps(__spreadValues({}, restAttributes), {
|
|
1545
|
-
style: __spreadValues(__spreadValues({}, style), placeholderStyle),
|
|
1546
|
-
children: props.children
|
|
1547
|
-
}));
|
|
1548
|
-
};
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
// src/components/base-copilot-textarea/use-add-branding-css.tsx
|
|
1552
|
-
import { useEffect as useEffect5 } from "react";
|
|
1553
|
-
function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
|
|
1554
|
-
const cssSelector = ".copilot-textarea.with-branding";
|
|
1555
|
-
useEffect5(() => {
|
|
1556
|
-
if (disableBranding) {
|
|
1557
|
-
return;
|
|
1558
|
-
}
|
|
1559
|
-
const styleEl = document.createElement("style");
|
|
1560
|
-
styleEl.id = "dynamic-styles";
|
|
1561
|
-
let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
|
|
1562
|
-
const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
1563
|
-
return `${kebabCaseKey}: ${value};`;
|
|
1564
|
-
}).join(" ");
|
|
1565
|
-
dynamicStyles += `font-style: normal; font-size: x-small;`;
|
|
1566
|
-
dynamicStyles += `content: "CopilotKit";`;
|
|
1567
|
-
dynamicStyles += `bottom: 6px;`;
|
|
1568
|
-
dynamicStyles += `right: 6px;`;
|
|
1569
|
-
dynamicStyles += `pointer-events: none;`;
|
|
1570
|
-
dynamicStyles += `font-weight: 200;`;
|
|
1571
|
-
dynamicStyles += `padding: 0;`;
|
|
1572
|
-
dynamicStyles += `margin: 0;`;
|
|
1573
|
-
dynamicStyles += `border: 0;`;
|
|
1574
|
-
dynamicStyles += `line-height: 1;`;
|
|
1575
|
-
dynamicStyles += `position: absolute;`;
|
|
1576
|
-
styleEl.innerHTML = `
|
|
1577
|
-
${cssSelector}::after {
|
|
1578
|
-
${dynamicStyles}
|
|
1579
|
-
}
|
|
1580
|
-
`;
|
|
1581
|
-
document.head.appendChild(styleEl);
|
|
1582
|
-
const textarea = document.querySelector(cssSelector);
|
|
1583
|
-
const handleScroll = () => {
|
|
1584
|
-
const styleEl2 = document.getElementById("dynamic-styles");
|
|
1585
|
-
if (styleEl2 && textarea) {
|
|
1586
|
-
const offsetFromBottom = -textarea.scrollTop + 6;
|
|
1587
|
-
const offsetFromRight = -textarea.scrollLeft + 6;
|
|
1588
|
-
styleEl2.innerHTML = `
|
|
1589
|
-
${cssSelector}::after {
|
|
1590
|
-
${dynamicStyles}
|
|
1591
|
-
bottom: ${offsetFromBottom}px;
|
|
1592
|
-
right: ${offsetFromRight}px;
|
|
1593
|
-
}
|
|
1594
|
-
`;
|
|
1595
|
-
}
|
|
1596
|
-
};
|
|
1597
|
-
textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
|
|
1598
|
-
return () => {
|
|
1599
|
-
var _a;
|
|
1600
|
-
(_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
|
|
1601
|
-
textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
|
|
1602
|
-
};
|
|
1603
|
-
}, [disableBranding, suggestionStyleAugmented]);
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
// src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
|
|
1607
|
-
import { useEffect as useEffect6, useRef as useRef3 } from "react";
|
|
1608
|
-
import { useSlateSelector } from "slate-react";
|
|
1609
|
-
import { Range as Range4 } from "slate";
|
|
1610
|
-
|
|
1611
|
-
// src/lib/editor-to-text.ts
|
|
1612
|
-
import { Element as Element4 } from "slate";
|
|
1613
|
-
function nodeChildrenToTextComponents(editor, nodes) {
|
|
1614
|
-
const indeciesOfInlineElements = new Set(
|
|
1615
|
-
nodes.map((node, index) => {
|
|
1616
|
-
if (Element4.isElement(node) && editor.isInline(node)) {
|
|
1617
|
-
return index;
|
|
1618
|
-
}
|
|
1619
|
-
return -1;
|
|
1620
|
-
}).filter((index) => index !== -1)
|
|
1621
|
-
);
|
|
1622
|
-
const nonIgnorableItems = nodes.filter((node, index) => {
|
|
1623
|
-
const isInline = indeciesOfInlineElements.has(index);
|
|
1624
|
-
if (isInline) {
|
|
1625
|
-
return false;
|
|
1626
|
-
}
|
|
1627
|
-
const isNeighbourOfInline = indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
|
|
1628
|
-
if (isNeighbourOfInline) {
|
|
1629
|
-
return node.text !== "";
|
|
1630
|
-
}
|
|
1631
|
-
return true;
|
|
1632
|
-
});
|
|
1633
|
-
return nonIgnorableItems.map((node) => {
|
|
1634
|
-
if (Element4.isElement(node)) {
|
|
1635
|
-
switch (node.type) {
|
|
1636
|
-
case "paragraph":
|
|
1637
|
-
return nodeChildrenToTextComponents(editor, node.children);
|
|
1638
|
-
case "suggestion":
|
|
1639
|
-
return [];
|
|
1640
|
-
}
|
|
1641
|
-
} else {
|
|
1642
|
-
return [node];
|
|
1643
|
-
}
|
|
1644
|
-
}).reduce((acc, val) => acc.concat(val), []);
|
|
1645
|
-
}
|
|
1646
|
-
var editorToText = (editor) => {
|
|
1647
|
-
const flattened = nodeChildrenToTextComponents(editor, editor.children);
|
|
1648
|
-
const text = flattened.map((textComponent) => textComponent.text).join("\n");
|
|
1649
|
-
return text;
|
|
1650
|
-
};
|
|
1651
|
-
|
|
1652
|
-
// src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
|
|
1653
|
-
import { Fragment as Fragment2, jsx as jsx12 } from "react/jsx-runtime";
|
|
1654
|
-
function TrackerTextEditedSinceLastCursorMovement(props) {
|
|
1655
|
-
const cursorState = useSlateSelector((state) => ({
|
|
1656
|
-
selection: state.selection,
|
|
1657
|
-
text: editorToText(state)
|
|
1658
|
-
}));
|
|
1659
|
-
const previousState = usePrevious(cursorState);
|
|
1660
|
-
useEffect6(() => {
|
|
1661
|
-
if (!previousState) {
|
|
1662
|
-
return;
|
|
1663
|
-
}
|
|
1664
|
-
if (cursorChangedWithoutTextChanged(previousState, cursorState)) {
|
|
1665
|
-
props.setCursorMovedSinceLastTextChange(true);
|
|
1666
|
-
}
|
|
1667
|
-
}, [props.setCursorMovedSinceLastTextChange, cursorState]);
|
|
1668
|
-
return /* @__PURE__ */ jsx12(Fragment2, {});
|
|
1669
|
-
}
|
|
1670
|
-
var cursorChangedWithoutTextChanged = (prev, next) => {
|
|
1671
|
-
const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);
|
|
1672
|
-
const isTextSame = prev.text === next.text;
|
|
1673
|
-
return isSelectionChanged && isTextSame;
|
|
1674
|
-
};
|
|
1675
|
-
var isSelectionEqual = (a, b) => {
|
|
1676
|
-
if (!a && !b)
|
|
1677
|
-
return true;
|
|
1678
|
-
if (!a || !b)
|
|
1679
|
-
return false;
|
|
1680
|
-
return Range4.equals(a, b);
|
|
1681
|
-
};
|
|
1682
|
-
function usePrevious(value) {
|
|
1683
|
-
const ref = useRef3();
|
|
1684
|
-
useEffect6(() => {
|
|
1685
|
-
ref.current = value;
|
|
1686
|
-
});
|
|
1687
|
-
return ref.current;
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
// src/components/base-copilot-textarea/base-copilot-textarea.tsx
|
|
1691
|
-
import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1692
|
-
var BaseCopilotTextareaWithHoveringContext = React9.forwardRef(
|
|
1693
|
-
(props, ref) => {
|
|
1694
|
-
const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
|
|
1695
|
-
const valueOnInitialRender = useMemo4(() => {
|
|
1696
|
-
var _a2;
|
|
1697
|
-
return (_a2 = props.value) != null ? _a2 : "";
|
|
1698
|
-
}, []);
|
|
1699
|
-
const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState6(valueOnInitialRender);
|
|
1700
|
-
const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState6(false);
|
|
1701
|
-
const initialValue = useMemo4(() => {
|
|
1702
|
-
return [
|
|
1703
|
-
{
|
|
1704
|
-
type: "paragraph",
|
|
1705
|
-
children: [{ text: valueOnInitialRender }]
|
|
1706
|
-
}
|
|
1707
|
-
];
|
|
1708
|
-
}, [valueOnInitialRender]);
|
|
1709
|
-
const editor = useCopilotTextareaEditor();
|
|
1710
|
-
const {
|
|
1711
|
-
isDisplayed: hoveringEditorIsDisplayed,
|
|
1712
|
-
setIsDisplayed: setHoveringEditorIsDisplayed
|
|
1713
|
-
} = useHoveringEditorContext();
|
|
1714
|
-
const insertText = useCallback2(
|
|
1715
|
-
(autosuggestion) => {
|
|
1716
|
-
Editor5.insertText(editor, autosuggestion.text, {
|
|
1717
|
-
at: autosuggestion.point
|
|
1718
|
-
});
|
|
1719
|
-
},
|
|
1720
|
-
[editor]
|
|
1721
|
-
);
|
|
1722
|
-
const {
|
|
1723
|
-
currentAutocompleteSuggestion,
|
|
1724
|
-
onChangeHandler: onChangeHandlerForAutocomplete,
|
|
1725
|
-
onKeyDownHandler: onKeyDownHandlerForAutocomplete
|
|
1726
|
-
} = useAutosuggestions(
|
|
1727
|
-
autosuggestionsConfig.debounceTime,
|
|
1728
|
-
autosuggestionsConfig.acceptAutosuggestionKey,
|
|
1729
|
-
autosuggestionsConfig.apiConfig.autosuggestionsFunction,
|
|
1730
|
-
insertText,
|
|
1731
|
-
autosuggestionsConfig.disableWhenEmpty,
|
|
1732
|
-
autosuggestionsConfig.disabled || hoveringEditorIsDisplayed || cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
|
|
1733
|
-
);
|
|
1734
|
-
const onKeyDownHandlerForHoveringEditor = useCallback2(
|
|
1735
|
-
(event) => {
|
|
1736
|
-
if (event.key === "k" && event.metaKey) {
|
|
1737
|
-
event.preventDefault();
|
|
1738
|
-
setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
|
|
1739
|
-
}
|
|
1740
|
-
},
|
|
1741
|
-
[hoveringEditorIsDisplayed, setHoveringEditorIsDisplayed]
|
|
1742
|
-
);
|
|
1743
|
-
useEffect7(() => {
|
|
1744
|
-
clearAutocompletionsFromEditor(editor);
|
|
1745
|
-
if (currentAutocompleteSuggestion) {
|
|
1746
|
-
addAutocompletionsToEditor(
|
|
1747
|
-
editor,
|
|
1748
|
-
currentAutocompleteSuggestion.text,
|
|
1749
|
-
currentAutocompleteSuggestion.point
|
|
1750
|
-
);
|
|
1751
|
-
}
|
|
1752
|
-
}, [currentAutocompleteSuggestion]);
|
|
1753
|
-
const suggestionStyleAugmented = useMemo4(() => {
|
|
1754
|
-
return __spreadValues({
|
|
1755
|
-
fontStyle: "italic",
|
|
1756
|
-
color: "gray"
|
|
1757
|
-
}, props.suggestionsStyle);
|
|
1758
|
-
}, [props.suggestionsStyle]);
|
|
1759
|
-
const renderElementMemoized = useMemo4(() => {
|
|
1760
|
-
return makeRenderElementFunction(suggestionStyleAugmented);
|
|
1761
|
-
}, [suggestionStyleAugmented]);
|
|
1762
|
-
const renderPlaceholderMemoized = useMemo4(() => {
|
|
1763
|
-
const placeholderStyleSlatejsOverrides = {
|
|
1764
|
-
top: void 0
|
|
1765
|
-
};
|
|
1766
|
-
const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
|
|
1767
|
-
return makeRenderPlaceholderFunction(placeholderStyleAugmented);
|
|
1768
|
-
}, [props.placeholderStyle]);
|
|
1769
|
-
useEffect7(() => {
|
|
1770
|
-
var _a2, _b;
|
|
1771
|
-
if (props.value === lastKnownFullEditorText) {
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
|
|
1775
|
-
replaceEditorText(editor, (_b = props.value) != null ? _b : "");
|
|
1776
|
-
}, [props.value]);
|
|
1777
|
-
const _a = props, {
|
|
1778
|
-
placeholderStyle,
|
|
1779
|
-
value,
|
|
1780
|
-
onValueChange,
|
|
1781
|
-
baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
|
|
1782
|
-
className,
|
|
1783
|
-
onChange,
|
|
1784
|
-
onKeyDown,
|
|
1785
|
-
disableBranding
|
|
1786
|
-
} = _a, propsToForward = __objRest(_a, [
|
|
1787
|
-
"placeholderStyle",
|
|
1788
|
-
"value",
|
|
1789
|
-
"onValueChange",
|
|
1790
|
-
"baseAutosuggestionsConfig",
|
|
1791
|
-
"className",
|
|
1792
|
-
"onChange",
|
|
1793
|
-
"onKeyDown",
|
|
1794
|
-
"disableBranding"
|
|
1795
|
-
]);
|
|
1796
|
-
useAddBrandingCss(suggestionStyleAugmented, disableBranding);
|
|
1797
|
-
usePopulateCopilotTextareaRef(editor, ref);
|
|
1798
|
-
const moddedClassName = (() => {
|
|
1799
|
-
const baseClassName = "copilot-textarea";
|
|
1800
|
-
const brandingClass = disableBranding ? "no-branding" : "with-branding";
|
|
1801
|
-
const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
|
|
1802
|
-
const mergedClassName = twMerge2(
|
|
1803
|
-
defaultTailwindClassName,
|
|
1804
|
-
className != null ? className : ""
|
|
1805
|
-
);
|
|
1806
|
-
return `${baseClassName} ${brandingClass} ${mergedClassName}`;
|
|
1807
|
-
})();
|
|
1808
|
-
return /* @__PURE__ */ jsxs4(Slate, {
|
|
1809
|
-
editor,
|
|
1810
|
-
initialValue,
|
|
1811
|
-
onChange: (value2) => {
|
|
1812
|
-
var _a2, _b;
|
|
1813
|
-
const newEditorState = getTextAroundCollapsedCursor(editor);
|
|
1814
|
-
const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
|
|
1815
|
-
setLastKnownFullEditorText((prev) => {
|
|
1816
|
-
if (prev !== fullEditorText) {
|
|
1817
|
-
setCursorMovedSinceLastTextChange(false);
|
|
1818
|
-
}
|
|
1819
|
-
return fullEditorText;
|
|
1820
|
-
});
|
|
1821
|
-
onChangeHandlerForAutocomplete(newEditorState);
|
|
1822
|
-
(_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
|
|
1823
|
-
(_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
|
|
1824
|
-
},
|
|
1825
|
-
children: [
|
|
1826
|
-
/* @__PURE__ */ jsx13(TrackerTextEditedSinceLastCursorMovement, {
|
|
1827
|
-
setCursorMovedSinceLastTextChange
|
|
1828
|
-
}),
|
|
1829
|
-
/* @__PURE__ */ jsx13(HoveringToolbar, {
|
|
1830
|
-
apiConfig: autosuggestionsConfig.apiConfig
|
|
1831
|
-
}),
|
|
1832
|
-
/* @__PURE__ */ jsx13(Editable, __spreadValues({
|
|
1833
|
-
renderElement: renderElementMemoized,
|
|
1834
|
-
renderPlaceholder: renderPlaceholderMemoized,
|
|
1835
|
-
onKeyDown: (event) => {
|
|
1836
|
-
var _a2;
|
|
1837
|
-
onKeyDownHandlerForHoveringEditor(event);
|
|
1838
|
-
onKeyDownHandlerForAutocomplete(event);
|
|
1839
|
-
(_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
|
|
1840
|
-
},
|
|
1841
|
-
className: moddedClassName
|
|
1842
|
-
}, propsToForward))
|
|
1843
|
-
]
|
|
1844
|
-
});
|
|
1845
|
-
}
|
|
1846
|
-
);
|
|
1847
|
-
function makeSemiFakeReactTextAreaEvent(currentText) {
|
|
1848
|
-
return {
|
|
1849
|
-
target: {
|
|
1850
|
-
value: currentText,
|
|
1851
|
-
type: "copilot-textarea"
|
|
1852
|
-
},
|
|
1853
|
-
currentTarget: {
|
|
1854
|
-
value: currentText,
|
|
1855
|
-
type: "copilot-textarea"
|
|
1856
|
-
}
|
|
1857
|
-
};
|
|
1858
|
-
}
|
|
1859
|
-
var BaseCopilotTextarea = React9.forwardRef(
|
|
1860
|
-
(props, ref) => {
|
|
1861
|
-
return /* @__PURE__ */ jsx13(HoveringEditorProvider, {
|
|
1862
|
-
children: /* @__PURE__ */ jsx13(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), {
|
|
1863
|
-
ref
|
|
1864
|
-
}))
|
|
1865
|
-
});
|
|
1866
|
-
}
|
|
1867
|
-
);
|
|
1868
|
-
export {
|
|
1869
|
-
BaseCopilotTextarea
|
|
1870
|
-
};
|
|
1
|
+
export { BaseCopilotTextarea } from '../../chunk-IWTOQKC5.mjs';
|
|
2
|
+
import '../../chunk-CSGFJU3L.mjs';
|
|
3
|
+
import '../../chunk-KCHYD3EB.mjs';
|
|
4
|
+
import '../../chunk-YQU7WG7T.mjs';
|
|
5
|
+
import '../../chunk-WJYQWL4I.mjs';
|
|
6
|
+
import '../../chunk-F3MHL6ZY.mjs';
|
|
7
|
+
import '../../chunk-RQHOUUXQ.mjs';
|
|
8
|
+
import '../../chunk-UHD44NC5.mjs';
|
|
9
|
+
import '../../chunk-JAFCXEPU.mjs';
|
|
10
|
+
import '../../chunk-LNAIMEB2.mjs';
|
|
11
|
+
import '../../chunk-OELUUJZY.mjs';
|
|
12
|
+
import '../../chunk-OD7ZMOVE.mjs';
|
|
13
|
+
import '../../chunk-MPME5BW2.mjs';
|
|
14
|
+
import '../../chunk-WJHSY5T6.mjs';
|
|
15
|
+
import '../../chunk-D7SEV5PR.mjs';
|
|
16
|
+
import '../../chunk-YSZ7DO3X.mjs';
|
|
17
|
+
import '../../chunk-L7VVZH4Q.mjs';
|
|
18
|
+
import '../../chunk-6XP7KEMW.mjs';
|
|
19
|
+
import '../../chunk-FBDXI5QA.mjs';
|
|
20
|
+
import '../../chunk-ND5PXTAW.mjs';
|
|
21
|
+
import '../../chunk-2NURR2DX.mjs';
|
|
22
|
+
import '../../chunk-XA7M72ZO.mjs';
|
|
23
|
+
import '../../chunk-O5OWT5GE.mjs';
|
|
24
|
+
import '../../chunk-5EJ5XOGP.mjs';
|
|
25
|
+
import '../../chunk-FN7GDKKG.mjs';
|
|
26
|
+
import '../../chunk-KGKLUWKW.mjs';
|
|
27
|
+
import '../../chunk-YW3REYX6.mjs';
|
|
28
|
+
import '../../chunk-XHUMROEY.mjs';
|
|
29
|
+
import '../../chunk-NKW5OU2S.mjs';
|
|
30
|
+
import '../../chunk-YTOPHPSG.mjs';
|
|
31
|
+
import '../../chunk-IXJ2HCOA.mjs';
|
|
32
|
+
import '../../chunk-MRXNTQOX.mjs';
|
|
33
|
+
//# sourceMappingURL=out.js.map
|
|
1871
34
|
//# sourceMappingURL=base-copilot-textarea.mjs.map
|