@copilotkit/react-textarea 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +133 -0
- package/CHANGELOG.md +50 -0
- package/dist/chunk-4LJAS777.mjs +10 -0
- package/dist/chunk-4LJAS777.mjs.map +1 -0
- package/dist/chunk-5SJM4R4K.mjs +10 -0
- package/dist/chunk-5SJM4R4K.mjs.map +1 -0
- package/dist/chunk-ETGKLURC.mjs +27 -0
- package/dist/chunk-ETGKLURC.mjs.map +1 -0
- package/dist/chunk-GOAPCQCR.mjs +124 -0
- package/dist/chunk-GOAPCQCR.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +3 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +3 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +3 -0
- package/dist/chunk-JD7BAH7U.mjs.map +1 -0
- package/dist/chunk-JJASB23A.mjs +88 -0
- package/dist/chunk-JJASB23A.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-KKG2RK2T.mjs +16 -0
- package/dist/chunk-KKG2RK2T.mjs.map +1 -0
- package/dist/chunk-L24ZN4LL.mjs +65 -0
- package/dist/chunk-L24ZN4LL.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-NKW5OU2S.mjs +33 -0
- package/dist/chunk-NKW5OU2S.mjs.map +1 -0
- package/dist/chunk-RVJAOO4S.mjs +18 -0
- package/dist/chunk-RVJAOO4S.mjs.map +1 -0
- package/dist/chunk-TSF4AJIK.mjs +30 -0
- package/dist/chunk-TSF4AJIK.mjs.map +1 -0
- package/dist/chunk-X4FJ6WVZ.mjs +66 -0
- package/dist/chunk-X4FJ6WVZ.mjs.map +1 -0
- package/dist/chunk-Y5BUWZOI.mjs +37 -0
- package/dist/chunk-Y5BUWZOI.mjs.map +1 -0
- package/dist/chunk-YPBKY4KY.mjs +3 -0
- package/dist/chunk-YPBKY4KY.mjs.map +1 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/base-copilot-textarea.d.ts +18 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/base-copilot-textarea.mjs +17 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/render-element.d.ts +6 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/render-element.mjs +4 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/render-element.mjs.map +1 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/render-placeholder.d.ts +6 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/render-placeholder.mjs +4 -0
- package/dist/components/copilot-textarea/base-copilot-textarea/render-placeholder.mjs.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.mjs +18 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.mjs +3 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.mjs +3 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-autosuggestions.d.ts +13 -0
- package/dist/hooks/use-autosuggestions.mjs +7 -0
- package/dist/hooks/use-autosuggestions.mjs.map +1 -0
- package/dist/hooks/use-copilot-textarea-editor.d.ts +8 -0
- package/dist/hooks/use-copilot-textarea-editor.mjs +5 -0
- package/dist/hooks/use-copilot-textarea-editor.mjs.map +1 -0
- package/dist/index.css +340 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +21 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/debouncer.d.ts +11 -0
- package/dist/lib/debouncer.mjs +4 -0
- package/dist/lib/debouncer.mjs.map +1 -0
- package/dist/lib/editor-to-text.d.ts +7 -0
- package/dist/lib/editor-to-text.mjs +45 -0
- package/dist/lib/editor-to-text.mjs.map +1 -0
- package/dist/lib/get-text-around-cursor.d.ts +8 -0
- package/dist/lib/get-text-around-cursor.mjs +4 -0
- package/dist/lib/get-text-around-cursor.mjs.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.d.ts +8 -0
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +4 -0
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +8 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +4 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.d.ts +5 -0
- package/dist/lib/slatejs-edits/replace-text.mjs +4 -0
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.d.ts +10 -0
- package/dist/lib/slatejs-edits/with-partial-history.mjs +4 -0
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -0
- package/dist/lib/utils.d.ts +10 -0
- package/dist/lib/utils.mjs +4 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/types/autosuggestion-state.d.ts +8 -0
- package/dist/types/autosuggestion-state.mjs +3 -0
- package/dist/types/autosuggestion-state.mjs.map +1 -0
- package/dist/types/autosuggestions-bare-function.d.ts +3 -0
- package/dist/types/autosuggestions-bare-function.mjs +3 -0
- package/dist/types/autosuggestions-bare-function.mjs.map +1 -0
- package/dist/types/base-autosuggestions-config.d.ts +9 -0
- package/dist/types/base-autosuggestions-config.mjs +4 -0
- package/dist/types/base-autosuggestions-config.mjs.map +1 -0
- package/dist/types/custom-editor.d.ts +29 -0
- package/dist/types/custom-editor.mjs +3 -0
- package/dist/types/custom-editor.mjs.map +1 -0
- package/dist/types/editor-autocomplete-state.d.ts +10 -0
- package/dist/types/editor-autocomplete-state.mjs +5 -0
- package/dist/types/editor-autocomplete-state.mjs.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.mjs +5 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +53 -0
- package/postcss.config.js +9 -0
- package/src/components/copilot-textarea/base-copilot-textarea/base-copilot-textarea.tsx +175 -0
- package/src/components/copilot-textarea/base-copilot-textarea/render-element.tsx +42 -0
- package/src/components/copilot-textarea/base-copilot-textarea/render-placeholder.tsx +25 -0
- package/src/components/index.ts +2 -0
- package/src/context/index.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-autosuggestions.ts +129 -0
- package/src/hooks/use-copilot-textarea-editor.tsx +104 -0
- package/src/index.tsx +7 -0
- package/src/lib/debouncer.ts +38 -0
- package/src/lib/editor-to-text.ts +64 -0
- package/src/lib/get-text-around-cursor.ts +82 -0
- package/src/lib/slatejs-edits/add-autocompletions.ts +30 -0
- package/src/lib/slatejs-edits/clear-autocompletions.ts +15 -0
- package/src/lib/slatejs-edits/replace-text.ts +32 -0
- package/src/lib/slatejs-edits/with-partial-history.ts +156 -0
- package/src/lib/utils.ts +59 -0
- package/src/styles.css +3 -0
- package/src/types/autosuggestion-state.ts +6 -0
- package/src/types/autosuggestions-bare-function.ts +5 -0
- package/src/types/base-autosuggestions-config.tsx +15 -0
- package/src/types/custom-editor.tsx +29 -0
- package/src/types/editor-autocomplete-state.ts +19 -0
- package/src/types/index.ts +4 -0
- package/tailwind.config.js +7 -0
- package/tsconfig.json +5 -0
- package/tsup.config.ts +12 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __async } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { customAlphabet } from 'nanoid';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
|
|
6
|
+
function cn(...inputs) {
|
|
7
|
+
return twMerge(clsx(inputs));
|
|
8
|
+
}
|
|
9
|
+
var nanoid = customAlphabet(
|
|
10
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
11
|
+
7
|
|
12
|
+
);
|
|
13
|
+
function fetcher(input, init) {
|
|
14
|
+
return __async(this, null, function* () {
|
|
15
|
+
const res = yield fetch(input, init);
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
const json = yield res.json();
|
|
18
|
+
if (json.error) {
|
|
19
|
+
const error = new Error(json.error);
|
|
20
|
+
error.status = res.status;
|
|
21
|
+
throw error;
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error("An unexpected error occurred");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return res.json();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function formatDate(input) {
|
|
30
|
+
const date = new Date(input);
|
|
31
|
+
return date.toLocaleDateString("en-US", {
|
|
32
|
+
month: "long",
|
|
33
|
+
day: "numeric",
|
|
34
|
+
year: "numeric"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
38
|
+
function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
|
|
39
|
+
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
40
|
+
return a === b;
|
|
41
|
+
}
|
|
42
|
+
return naiveEqualityCheck(a, b);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { arraysAreEqual, cn, fetcher, formatDate, nanoid, nullableCompatibleEqualityCheck };
|
|
46
|
+
//# sourceMappingURL=out.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-KGKLUWKW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/utils.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAA6B;AACtC,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAEO,IAAM,SAAS;AAAA,EACpB;AAAA,EACA;AACF;AAEA,SAAsB,QACpB,OACA,MACe;AAAA;AACf,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;AAEO,IAAM,iBAAiB,CAAC,MAAgB,SAC7C,KAAK,WAAW,KAAK,UACrB,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU,KAAK,MAAM;AAE7C,SAAS,gCACd,oBACA,GACA,GACS;AACT,MAAI,MAAM,QAAQ,MAAM,UAAa,MAAM,QAAQ,MAAM,QAAW;AAClE,WAAO,MAAM;AAAA,EACf;AAEA,SAAO,mBAAmB,GAAG,CAAC;AAChC","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { customAlphabet } from \"nanoid\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(\n input: RequestInfo,\n init?: RequestInit\n): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>\n arr1.length === arr2.length &&\n arr1.every((value, index) => value === arr2[index]);\n\nexport function nullableCompatibleEqualityCheck<T>(\n naiveEqualityCheck: (a: T, b: T) => boolean,\n a: T | null | undefined,\n b: T | null | undefined\n): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n return naiveEqualityCheck(a, b);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
function makeRenderPlaceholderFunction(placeholderStyle) {
|
|
5
|
+
return (props) => {
|
|
6
|
+
const _a = props.attributes, { style } = _a, restAttributes = __objRest(_a, ["style"]);
|
|
7
|
+
return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({}, restAttributes), {
|
|
8
|
+
style: __spreadValues(__spreadValues({}, style), placeholderStyle),
|
|
9
|
+
children: props.children
|
|
10
|
+
}));
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { makeRenderPlaceholderFunction };
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=chunk-KKG2RK2T.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/copilot-textarea/base-copilot-textarea/render-placeholder.tsx"],"names":[],"mappings":";;;;;;;AAaM;AAPC,SAAS,8BACd,kBAC2B;AAC3B,SAAO,CAAC,UAAkC;AACxC,UAAqC,WAAM,YAAnC,QAVZ,IAUyC,IAAnB,2BAAmB,IAAnB,CAAV;AAER,WACE,oBAAC,wCACK,iBADL;AAAA,MAEC,OAAO,kCACF,QACA;AAAA,MAGJ,gBAAM;AAAA,MACT;AAAA,EAEJ;AACF","sourcesContent":["import { RenderElementProps, RenderPlaceholderProps } from \"slate-react\";\n\nexport type RenderPlaceholderFunction = (\n props: RenderPlaceholderProps\n) => JSX.Element;\n\nexport function makeRenderPlaceholderFunction(\n placeholderStyle?: React.CSSProperties\n): RenderPlaceholderFunction {\n return (props: RenderPlaceholderProps) => {\n const { style, ...restAttributes } = props.attributes;\n\n return (\n <div\n {...restAttributes}\n style={{\n ...style,\n ...placeholderStyle,\n }}\n >\n {props.children}\n </div>\n );\n };\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { withPartialHistory, defaultShouldSave } from './chunk-KCHYD3EB.mjs';
|
|
2
|
+
import { createEditor, Element } from 'slate';
|
|
3
|
+
import { withReact } from 'slate-react';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
|
|
6
|
+
var shouldSave = (op, prev) => {
|
|
7
|
+
const excludedNodeType = "suggestion";
|
|
8
|
+
if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return defaultShouldSave(op, prev);
|
|
27
|
+
};
|
|
28
|
+
function useCopilotTextareaEditor() {
|
|
29
|
+
const editor = useMemo(() => {
|
|
30
|
+
const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
|
|
31
|
+
const { isVoid } = editor2;
|
|
32
|
+
editor2.isVoid = (element) => {
|
|
33
|
+
switch (element.type) {
|
|
34
|
+
case "suggestion":
|
|
35
|
+
return true;
|
|
36
|
+
default:
|
|
37
|
+
return isVoid(element);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const { markableVoid } = editor2;
|
|
41
|
+
editor2.markableVoid = (element) => {
|
|
42
|
+
switch (element.type) {
|
|
43
|
+
case "suggestion":
|
|
44
|
+
return true;
|
|
45
|
+
default:
|
|
46
|
+
return markableVoid(element);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const { isInline } = editor2;
|
|
50
|
+
editor2.isInline = (element) => {
|
|
51
|
+
switch (element.type) {
|
|
52
|
+
case "suggestion":
|
|
53
|
+
return element.inline;
|
|
54
|
+
default:
|
|
55
|
+
return isInline(element);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return editor2;
|
|
59
|
+
}, []);
|
|
60
|
+
return editor;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { useCopilotTextareaEditor };
|
|
64
|
+
//# sourceMappingURL=out.js.map
|
|
65
|
+
//# sourceMappingURL=chunk-L24ZN4LL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-copilot-textarea-editor.tsx"],"names":["editor"],"mappings":";;;;;;AAAA,SAAS,cAAc,eAAe;AACtC,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAQxB,IAAM,aAAkC,CAAC,IAAI,SAAS;AACpD,QAAM,mBAAmB;AAEzB,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,cACZ,UAAU,GAAG,iBACb,GAAG,cAAc,SAAS,kBAC1B;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,QAAQ,cACX,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAGA,SAAO,kBAAkB,IAAI,IAAI;AACnC;AAEO,SAAS,2BAAyC;AACvD,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAMA,UAAS,mBAAmB,UAAU,aAAa,CAAC,GAAG,UAAU;AAEvE,UAAM,EAAE,OAAO,IAAIA;AACnB,IAAAA,QAAO,SAAS,CAAC,YAAY;AAC3B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,OAAO,OAAO;AAAA,MACzB;AAAA,IACF;AAEA,UAAM,EAAE,aAAa,IAAIA;AACzB,IAAAA,QAAO,eAAe,CAAC,YAAY;AACjC,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,aAAa,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,EAAE,SAAS,IAAIA;AACrB,IAAAA,QAAO,WAAW,CAAC,YAAY;AAC7B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO,QAAQ;AAAA,QACjB;AACE,iBAAO,SAAS,OAAO;AAAA,MAC3B;AAAA,IACF;AAEA,WAAOA;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT","sourcesContent":["import { createEditor, Element } from \"slate\";\nimport { withReact } from \"slate-react\";\nimport { useMemo } from \"react\";\nimport { CustomEditor } from \"../types/custom-editor\";\nimport {\n withPartialHistory,\n ShouldSaveToHistory,\n defaultShouldSave,\n} from \"../lib/slatejs-edits/with-partial-history\";\n\nconst shouldSave: ShouldSaveToHistory = (op, prev) => {\n const excludedNodeType = \"suggestion\";\n // Check if the operation involves the suggestion inline node type\n if (\n op.type === \"insert_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"remove_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"set_node\" &&\n \"type\" in op.newProperties &&\n op.newProperties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type == \"set_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"merge_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"split_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n // Otherwise, save the operation to history\n return defaultShouldSave(op, prev);\n};\n\nexport function useCopilotTextareaEditor(): CustomEditor {\n const editor = useMemo(() => {\n const editor = withPartialHistory(withReact(createEditor()), shouldSave);\n\n const { isVoid } = editor;\n editor.isVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return isVoid(element);\n }\n };\n\n const { markableVoid } = editor;\n editor.markableVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return markableVoid(element);\n }\n };\n\n const { isInline } = editor;\n editor.isInline = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return element.inline;\n default:\n return isInline(element);\n }\n };\n\n return editor;\n }, []);\n\n return editor;\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
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
|
+
export { __async, __objRest, __spreadProps, __spreadValues };
|
|
54
|
+
//# sourceMappingURL=out.js.map
|
|
55
|
+
//# sourceMappingURL=chunk-MRXNTQOX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __async } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
|
|
3
|
+
// src/lib/debouncer.ts
|
|
4
|
+
var Debouncer = class {
|
|
5
|
+
constructor(wait) {
|
|
6
|
+
this.wait = wait;
|
|
7
|
+
this.debounce = (func, ...args) => __async(this, null, function* () {
|
|
8
|
+
this.cancel();
|
|
9
|
+
this.timeoutId = setTimeout(() => __async(this, null, function* () {
|
|
10
|
+
try {
|
|
11
|
+
this.activeAbortController = new AbortController();
|
|
12
|
+
yield func(...args, this.activeAbortController.signal);
|
|
13
|
+
this.activeAbortController = void 0;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
}
|
|
16
|
+
}), this.wait);
|
|
17
|
+
});
|
|
18
|
+
this.cancel = () => {
|
|
19
|
+
if (this.activeAbortController) {
|
|
20
|
+
this.activeAbortController.abort();
|
|
21
|
+
this.activeAbortController = void 0;
|
|
22
|
+
}
|
|
23
|
+
if (this.timeoutId !== void 0) {
|
|
24
|
+
clearTimeout(this.timeoutId);
|
|
25
|
+
this.timeoutId = void 0;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { Debouncer };
|
|
32
|
+
//# sourceMappingURL=out.js.map
|
|
33
|
+
//# sourceMappingURL=chunk-NKW5OU2S.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/debouncer.ts"],"names":[],"mappings":";;;;;AAIO,IAAM,YAAN,MAAiC;AAAA,EAItC,YAAoB,MAAc;AAAd;AAEpB,oBAAW,CAAO,SAA2B,SAAY;AAEvD,WAAK,OAAO;AAEZ,WAAK,YAAY,WAAW,MAAY;AACtC,YAAI;AACF,eAAK,wBAAwB,IAAI,gBAAgB;AAGjD,gBAAM,KAAK,GAAG,MAAM,KAAK,sBAAsB,MAAM;AAErD,eAAK,wBAAwB;AAAA,QAC/B,SAAS,OAAP;AAAA,QAAe;AAAA,MACnB,IAAG,KAAK,IAAI;AAAA,IACd;AAEA,kBAAS,MAAM;AACb,UAAI,KAAK,uBAAuB;AAC9B,aAAK,sBAAsB,MAAM;AACjC,aAAK,wBAAwB;AAAA,MAC/B;AAEA,UAAI,KAAK,cAAc,QAAW;AAChC,qBAAa,KAAK,SAAS;AAC3B,aAAK,YAAY;AAAA,MACnB;AAAA,IACF;AAAA,EA5BmC;AA6BrC","sourcesContent":["export type AsyncFunction<T extends any[]> = (\n ...args: [...T, AbortSignal]\n) => Promise<void>;\n\nexport class Debouncer<T extends any[]> {\n private timeoutId?: number;\n private activeAbortController?: AbortController;\n\n constructor(private wait: number) {}\n\n debounce = async (func: AsyncFunction<T>, ...args: T) => {\n // Abort the previous promise immediately\n this.cancel();\n\n this.timeoutId = setTimeout(async () => {\n try {\n this.activeAbortController = new AbortController();\n\n // Pass the signal to the async function, assuming it supports it\n await func(...args, this.activeAbortController.signal);\n\n this.activeAbortController = undefined;\n } catch (error) {}\n }, this.wait);\n };\n\n cancel = () => {\n if (this.activeAbortController) {\n this.activeAbortController.abort();\n this.activeAbortController = undefined;\n }\n\n if (this.timeoutId !== undefined) {\n clearTimeout(this.timeoutId);\n this.timeoutId = undefined;\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Node, Element, Transforms } from 'slate';
|
|
2
|
+
|
|
3
|
+
// src/lib/slatejs-edits/clear-autocompletions.ts
|
|
4
|
+
function clearAutocompletionsFromEditor(editor) {
|
|
5
|
+
const paths = [];
|
|
6
|
+
for (const [node, path] of Node.nodes(editor)) {
|
|
7
|
+
if (Element.isElement(node) && node.type === "suggestion") {
|
|
8
|
+
paths.push(path);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (const path of paths) {
|
|
12
|
+
Transforms.removeNodes(editor, { at: path });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { clearAutocompletionsFromEditor };
|
|
17
|
+
//# sourceMappingURL=out.js.map
|
|
18
|
+
//# sourceMappingURL=chunk-RVJAOO4S.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/slatejs-edits/clear-autocompletions.ts"],"names":[],"mappings":";AAAA,SAAe,MAAM,SAAS,kBAAkB;AAGzC,SAAS,+BAA+B,QAAsB;AAEnE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,GAAG;AAC7C,QAAI,QAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,cAAc;AACzD,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,eAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,EAC7C;AACF","sourcesContent":["import { Path, Node, Element, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/custom-editor\";\n\nexport function clearAutocompletionsFromEditor(editor: CustomEditor) {\n // clear previous suggestion\n const paths: Path[] = [];\n for (const [node, path] of Node.nodes(editor)) {\n if (Element.isElement(node) && node.type === \"suggestion\") {\n paths.push(path);\n }\n }\n for (const path of paths) {\n Transforms.removeNodes(editor, { at: path });\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Node, Element, Transforms } from 'slate';
|
|
2
|
+
|
|
3
|
+
// src/lib/slatejs-edits/replace-text.ts
|
|
4
|
+
function replaceEditorText(editor, newText) {
|
|
5
|
+
const paths = [];
|
|
6
|
+
for (const [node, path] of Node.nodes(editor)) {
|
|
7
|
+
if (Element.isElement(node) && (node.type === "paragraph" || node.type === "suggestion") && path.length === 1) {
|
|
8
|
+
paths.push(path);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (const path of paths) {
|
|
12
|
+
Transforms.removeNodes(editor, { at: path });
|
|
13
|
+
}
|
|
14
|
+
Transforms.insertNodes(
|
|
15
|
+
editor,
|
|
16
|
+
[
|
|
17
|
+
{
|
|
18
|
+
type: "paragraph",
|
|
19
|
+
children: [{ text: newText }]
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
{
|
|
23
|
+
at: [0]
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { replaceEditorText };
|
|
29
|
+
//# sourceMappingURL=out.js.map
|
|
30
|
+
//# sourceMappingURL=chunk-TSF4AJIK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/slatejs-edits/replace-text.ts"],"names":[],"mappings":";AAAA,SAAuB,YAAY,MAAM,eAAe;AAEjD,SAAS,kBAAkB,QAAgB,SAAiB;AAEjE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,GAAG;AAC7C,QACE,QAAQ,UAAU,IAAI,MACrB,KAAK,SAAS,eAAe,KAAK,SAAS,iBAC5C,KAAK,WAAW,GAChB;AACA,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,eAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,EAC7C;AAGA,aAAW;AAAA,IACT;AAAA,IACA;AAAA,MACE;AAAA,QACE,MAAM;AAAA,QACN,UAAU,CAAC,EAAE,MAAM,QAAQ,CAAC;AAAA,MAC9B;AAAA,IACF;AAAA,IACA;AAAA,MACE,IAAI,CAAC,CAAC;AAAA,IACR;AAAA,EACF;AACF","sourcesContent":["import { Editor, Path, Transforms, Node, Element } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n const paths: Path[] = [];\n for (const [node, path] of Node.nodes(editor)) {\n if (\n Element.isElement(node) &&\n (node.type === \"paragraph\" || node.type === \"suggestion\") &&\n path.length === 1\n ) {\n paths.push(path);\n }\n }\n for (const path of paths) {\n Transforms.removeNodes(editor, { at: path });\n }\n\n // insert new text\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n }\n );\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Range, Editor, Text, Element, Path } from 'slate';
|
|
2
|
+
|
|
3
|
+
// src/lib/get-text-around-cursor.ts
|
|
4
|
+
function getTextAroundCursor(editor) {
|
|
5
|
+
const { selection } = editor;
|
|
6
|
+
if (!selection || !Range.isCollapsed(selection)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const beforeRange = {
|
|
10
|
+
anchor: Editor.start(editor, []),
|
|
11
|
+
focus: selection.anchor
|
|
12
|
+
};
|
|
13
|
+
const afterRange = {
|
|
14
|
+
anchor: selection.anchor,
|
|
15
|
+
focus: Editor.end(editor, [])
|
|
16
|
+
};
|
|
17
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
18
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
19
|
+
return {
|
|
20
|
+
cursorPoint: selection.anchor,
|
|
21
|
+
textBeforeCursor: before,
|
|
22
|
+
textAfterCursor: after
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function getFullEditorTextWithNewlines(editor) {
|
|
26
|
+
const fullDocumentRange = {
|
|
27
|
+
anchor: Editor.start(editor, []),
|
|
28
|
+
focus: Editor.end(editor, [])
|
|
29
|
+
};
|
|
30
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
31
|
+
}
|
|
32
|
+
function extractTextWithNewlines(editor, range) {
|
|
33
|
+
const voids = false;
|
|
34
|
+
const [start, end] = Range.edges(range);
|
|
35
|
+
let text = "";
|
|
36
|
+
let lastBlock = null;
|
|
37
|
+
for (const [node, path] of Editor.nodes(editor, {
|
|
38
|
+
at: range,
|
|
39
|
+
match: Text.isText,
|
|
40
|
+
voids
|
|
41
|
+
})) {
|
|
42
|
+
let t = node.text;
|
|
43
|
+
const [block] = Editor.above(editor, {
|
|
44
|
+
at: path,
|
|
45
|
+
match: (n) => Element.isElement(n) && n.type === "paragraph"
|
|
46
|
+
}) || [null];
|
|
47
|
+
if (lastBlock !== block && block) {
|
|
48
|
+
if (lastBlock) {
|
|
49
|
+
text += "\n";
|
|
50
|
+
}
|
|
51
|
+
lastBlock = block;
|
|
52
|
+
}
|
|
53
|
+
if (Path.equals(path, end.path)) {
|
|
54
|
+
t = t.slice(0, end.offset);
|
|
55
|
+
}
|
|
56
|
+
if (Path.equals(path, start.path)) {
|
|
57
|
+
t = t.slice(start.offset);
|
|
58
|
+
}
|
|
59
|
+
text += t;
|
|
60
|
+
}
|
|
61
|
+
return text;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { extractTextWithNewlines, getFullEditorTextWithNewlines, getTextAroundCursor };
|
|
65
|
+
//# sourceMappingURL=out.js.map
|
|
66
|
+
//# sourceMappingURL=chunk-X4FJ6WVZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/get-text-around-cursor.ts"],"names":[],"mappings":";AAAA,SAAS,QAAc,MAAM,OAAO,MAAM,eAAe;AAGlD,SAAS,oBACd,QACgC;AAChC,QAAM,EAAE,UAAU,IAAI;AAEtB,MAAI,CAAC,aAAa,CAAC,MAAM,YAAY,SAAS,GAAG;AAC/C,WAAO;AAAA,EACT;AAEA,QAAM,cAAqB;AAAA,IACzB,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,UAAU;AAAA,EACnB;AACA,QAAM,aAAoB;AAAA,IACxB,QAAQ,UAAU;AAAA,IAClB,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AAGA,QAAM,SAAS,wBAAwB,QAAQ,WAAW;AAC1D,QAAM,QAAQ,wBAAwB,QAAQ,UAAU;AAExD,SAAO;AAAA,IACL,aAAa,UAAU;AAAA,IACvB,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,EACnB;AACF;AAEO,SAAS,8BAA8B,QAAwB;AACpE,QAAM,oBAA2B;AAAA,IAC/B,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACA,SAAO,wBAAwB,QAAQ,iBAAiB;AAC1D;AAGO,SAAS,wBAAwB,QAAgB,OAAsB;AAC5E,QAAM,QAAQ;AACd,QAAM,CAAC,OAAO,GAAG,IAAI,MAAM,MAAM,KAAK;AACtC,MAAI,OAAO;AACX,MAAI,YAAyB;AAE7B,aAAW,CAAC,MAAM,IAAI,KAAK,OAAO,MAAM,QAAQ;AAAA,IAC9C,IAAI;AAAA,IACJ,OAAO,KAAK;AAAA,IACZ;AAAA,EACF,CAAC,GAAG;AACF,QAAI,IAAI,KAAK;AAGb,UAAM,CAAC,KAAK,IAAI,OAAO,MAAM,QAAQ;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO,CAAC,MAAM,QAAQ,UAAU,CAAC,KAAK,EAAE,SAAS;AAAA,IACnD,CAAC,KAAK,CAAC,IAAI;AAGX,QAAI,cAAc,SAAS,OAAO;AAEhC,UAAI,WAAW;AACb,gBAAQ;AAAA,MACV;AACA,kBAAY;AAAA,IACd;AAEA,QAAI,KAAK,OAAO,MAAM,IAAI,IAAI,GAAG;AAC/B,UAAI,EAAE,MAAM,GAAG,IAAI,MAAM;AAAA,IAC3B;AAEA,QAAI,KAAK,OAAO,MAAM,MAAM,IAAI,GAAG;AACjC,UAAI,EAAE,MAAM,MAAM,MAAM;AAAA,IAC1B;AAEA,YAAQ;AAAA,EACV;AAEA,SAAO;AACT","sourcesContent":["import { Editor, Node, Path, Range, Text, Element } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/editor-autocomplete-state\";\n\nexport function getTextAroundCursor(\n editor: Editor\n): EditorAutocompleteState | null {\n const { selection } = editor;\n\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: selection.anchor,\n };\n const afterRange: Range = {\n anchor: selection.anchor,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: selection.anchor,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
function makeRenderElementFunction(suggestionsStyle) {
|
|
5
|
+
return (props) => {
|
|
6
|
+
switch (props.element.type) {
|
|
7
|
+
case "paragraph":
|
|
8
|
+
return /* @__PURE__ */ jsx(DefaultElement, __spreadValues({}, props));
|
|
9
|
+
case "suggestion":
|
|
10
|
+
return /* @__PURE__ */ jsx(SuggestionElement, __spreadProps(__spreadValues({}, props), {
|
|
11
|
+
suggestionsStyle
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var DefaultElement = (props) => {
|
|
17
|
+
return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({}, props.attributes), {
|
|
18
|
+
children: props.children
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
21
|
+
var SuggestionElement = (props) => {
|
|
22
|
+
return /* @__PURE__ */ jsxs("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
23
|
+
style: __spreadValues({
|
|
24
|
+
fontStyle: "italic",
|
|
25
|
+
color: "gray"
|
|
26
|
+
}, props.suggestionsStyle),
|
|
27
|
+
contentEditable: false,
|
|
28
|
+
children: [
|
|
29
|
+
props.children,
|
|
30
|
+
props.element.type === "suggestion" && props.element.content
|
|
31
|
+
]
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { makeRenderElementFunction };
|
|
36
|
+
//# sourceMappingURL=out.js.map
|
|
37
|
+
//# sourceMappingURL=chunk-Y5BUWZOI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/copilot-textarea/base-copilot-textarea/render-element.tsx"],"names":[],"mappings":";;;;;;AAUe,cAkBX,YAlBW;AANR,SAAS,0BACd,kBACuB;AACvB,SAAO,CAAC,UAA8B;AACpC,YAAQ,MAAM,QAAQ,MAAM;AAAA,MAC1B,KAAK;AACH,eAAO,oBAAC,mCAAmB,MAAO;AAAA,MACpC,KAAK;AACH,eACE,oBAAC,oDAAsB,QAAtB;AAAA,UAA6B;AAAA,UAAoC;AAAA,IAExE;AAAA,EACF;AACF;AAEA,IAAM,iBAAiB,CAAC,UAA8B;AACpD,SAAO,oBAAC,wCAAQ,MAAM,aAAd;AAAA,IAA2B,gBAAM;AAAA,IAAS;AACpD;AACA,IAAM,oBAAoB,CACxB,UAGG;AACH,SACE,qBAAC,yCACK,MAAM,aADX;AAAA,IAEC,OAAO;AAAA,MACL,WAAW;AAAA,MACX,OAAO;AAAA,OACJ,MAAM;AAAA,IAEX,iBAAiB;AAAA,IAEhB;AAAA,YAAM;AAAA,MACN,MAAM,QAAQ,SAAS,gBAAgB,MAAM,QAAQ;AAAA;AAAA,IACxD;AAEJ","sourcesContent":["import { RenderElementProps } from \"slate-react\";\n\nexport type RenderElementFunction = (props: RenderElementProps) => JSX.Element;\n\nexport function makeRenderElementFunction(\n suggestionsStyle: React.CSSProperties\n): RenderElementFunction {\n return (props: RenderElementProps) => {\n switch (props.element.type) {\n case \"paragraph\":\n return <DefaultElement {...props} />;\n case \"suggestion\":\n return (\n <SuggestionElement {...props} suggestionsStyle={suggestionsStyle} />\n );\n }\n };\n}\n\nconst DefaultElement = (props: RenderElementProps) => {\n return <div {...props.attributes}>{props.children}</div>;\n};\nconst SuggestionElement = (\n props: RenderElementProps & {\n suggestionsStyle: React.CSSProperties;\n }\n) => {\n return (\n <span\n {...props.attributes}\n style={{\n fontStyle: \"italic\",\n color: \"gray\",\n ...props.suggestionsStyle,\n }}\n contentEditable={false}\n >\n {props.children /* https://github.com/ianstormtaylor/slate/issues/3930 */}\n {props.element.type === \"suggestion\" && props.element.content}\n </span>\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TextareaHTMLAttributes } from 'react';
|
|
2
|
+
import { AutosuggestionsBareFunction } from '../../../types/autosuggestions-bare-function.js';
|
|
3
|
+
import { BaseAutosuggestionsConfig } from '../../../types/base-autosuggestions-config.js';
|
|
4
|
+
|
|
5
|
+
interface BaseCopilotTextareaProps extends TextareaHTMLAttributes<HTMLDivElement> {
|
|
6
|
+
placeholderStyle?: React.CSSProperties;
|
|
7
|
+
suggestionsStyle?: React.CSSProperties;
|
|
8
|
+
value?: string;
|
|
9
|
+
onValueChange?: (value: string) => void;
|
|
10
|
+
autosuggestionsConfig: Partial<BaseAutosuggestionsConfig> & {
|
|
11
|
+
purposePrompt: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
declare function BaseCopilotTextarea(props: BaseCopilotTextareaProps & {
|
|
15
|
+
autosuggestionsFunction: AutosuggestionsBareFunction;
|
|
16
|
+
}): JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { BaseCopilotTextarea, BaseCopilotTextareaProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { BaseCopilotTextarea } from '../../../chunk-GOAPCQCR.mjs';
|
|
2
|
+
import '../../../chunk-ETGKLURC.mjs';
|
|
3
|
+
import '../../../chunk-RVJAOO4S.mjs';
|
|
4
|
+
import '../../../chunk-TSF4AJIK.mjs';
|
|
5
|
+
import '../../../chunk-Y5BUWZOI.mjs';
|
|
6
|
+
import '../../../chunk-KKG2RK2T.mjs';
|
|
7
|
+
import '../../../chunk-X4FJ6WVZ.mjs';
|
|
8
|
+
import '../../../chunk-5SJM4R4K.mjs';
|
|
9
|
+
import '../../../chunk-JJASB23A.mjs';
|
|
10
|
+
import '../../../chunk-4LJAS777.mjs';
|
|
11
|
+
import '../../../chunk-KGKLUWKW.mjs';
|
|
12
|
+
import '../../../chunk-L24ZN4LL.mjs';
|
|
13
|
+
import '../../../chunk-KCHYD3EB.mjs';
|
|
14
|
+
import '../../../chunk-NKW5OU2S.mjs';
|
|
15
|
+
import '../../../chunk-MRXNTQOX.mjs';
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=base-copilot-textarea.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RenderElementProps } from 'slate-react';
|
|
2
|
+
|
|
3
|
+
type RenderElementFunction = (props: RenderElementProps) => JSX.Element;
|
|
4
|
+
declare function makeRenderElementFunction(suggestionsStyle: React.CSSProperties): RenderElementFunction;
|
|
5
|
+
|
|
6
|
+
export { RenderElementFunction, makeRenderElementFunction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RenderPlaceholderProps } from 'slate-react';
|
|
2
|
+
|
|
3
|
+
type RenderPlaceholderFunction = (props: RenderPlaceholderProps) => JSX.Element;
|
|
4
|
+
declare function makeRenderPlaceholderFunction(placeholderStyle?: React.CSSProperties): RenderPlaceholderFunction;
|
|
5
|
+
|
|
6
|
+
export { RenderPlaceholderFunction, makeRenderPlaceholderFunction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '../chunk-JD7BAH7U.mjs';
|
|
2
|
+
export { BaseCopilotTextarea } from '../chunk-GOAPCQCR.mjs';
|
|
3
|
+
import '../chunk-ETGKLURC.mjs';
|
|
4
|
+
import '../chunk-RVJAOO4S.mjs';
|
|
5
|
+
import '../chunk-TSF4AJIK.mjs';
|
|
6
|
+
import '../chunk-Y5BUWZOI.mjs';
|
|
7
|
+
import '../chunk-KKG2RK2T.mjs';
|
|
8
|
+
import '../chunk-X4FJ6WVZ.mjs';
|
|
9
|
+
import '../chunk-5SJM4R4K.mjs';
|
|
10
|
+
import '../chunk-JJASB23A.mjs';
|
|
11
|
+
import '../chunk-4LJAS777.mjs';
|
|
12
|
+
import '../chunk-KGKLUWKW.mjs';
|
|
13
|
+
import '../chunk-L24ZN4LL.mjs';
|
|
14
|
+
import '../chunk-KCHYD3EB.mjs';
|
|
15
|
+
import '../chunk-NKW5OU2S.mjs';
|
|
16
|
+
import '../chunk-MRXNTQOX.mjs';
|
|
17
|
+
//# sourceMappingURL=out.js.map
|
|
18
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AutosuggestionState } from '../types/autosuggestion-state.js';
|
|
2
|
+
import { EditorAutocompleteState } from '../types/editor-autocomplete-state.js';
|
|
3
|
+
import { AutosuggestionsBareFunction } from '../types/autosuggestions-bare-function.js';
|
|
4
|
+
import 'slate';
|
|
5
|
+
|
|
6
|
+
interface UseAutosuggestionsResult {
|
|
7
|
+
currentAutocompleteSuggestion: AutosuggestionState | null;
|
|
8
|
+
onChangeHandler: (newEditorState: EditorAutocompleteState | null) => void;
|
|
9
|
+
onKeyDownHandler: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
10
|
+
}
|
|
11
|
+
declare function useAutosuggestions(debounceTime: number, acceptAutosuggestionKey: string, autosuggestionFunction: AutosuggestionsBareFunction, insertAutocompleteSuggestion: (suggestion: AutosuggestionState) => void, disableWhenEmpty: boolean): UseAutosuggestionsResult;
|
|
12
|
+
|
|
13
|
+
export { UseAutosuggestionsResult, useAutosuggestions };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { useAutosuggestions } from '../chunk-JJASB23A.mjs';
|
|
2
|
+
import '../chunk-4LJAS777.mjs';
|
|
3
|
+
import '../chunk-KGKLUWKW.mjs';
|
|
4
|
+
import '../chunk-NKW5OU2S.mjs';
|
|
5
|
+
import '../chunk-MRXNTQOX.mjs';
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=use-autosuggestions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|