@copilotkit/react-textarea 0.21.0-alpha.1 → 0.21.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +302 -170
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-34D4UIYX.mjs → chunk-4ENJ4VF6.mjs} +4 -4
- package/dist/{chunk-IPM5WWPW.mjs → chunk-JHLXWI44.mjs} +5 -5
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1772 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +3 -3
- package/dist/components/base-copilot-textarea/render-element.js +75 -0
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js +69 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +112 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js +83 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +2246 -0
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs +5 -5
- package/dist/components/hovering-toolbar/hovering-editor-provider.js +49 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +158 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js +915 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +622 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +639 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +140 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +639 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
- package/dist/components/index.js +2250 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +5 -5
- package/dist/components/manual-ui/chip-with-icon.js +53 -0
- package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
- package/dist/components/source-search-box/source-search-box.js +243 -0
- package/dist/components/source-search-box/source-search-box.js.map +1 -0
- package/dist/components/ui/button.js +118 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/card.js +142 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/command.js +306 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/dialog.js +199 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/label.js +92 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/separator.js +96 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/textarea.js +91 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/context/index.js +19 -0
- package/dist/context/index.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +193 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +194 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +180 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +167 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +227 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.js +39 -0
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
- package/dist/index.js +2256 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6 -6
- package/dist/lib/debouncer.js +76 -0
- package/dist/lib/debouncer.js.map +1 -0
- package/dist/lib/editor-to-text.js +69 -0
- package/dist/lib/editor-to-text.js.map +1 -0
- package/dist/lib/get-text-around-cursor.js +131 -0
- package/dist/lib/get-text-around-cursor.js.map +1 -0
- package/dist/lib/retry.js +43 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js +51 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js +49 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.js +53 -0
- package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.js +133 -0
- package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
- package/dist/lib/stream-promise-flatten.js +72 -0
- package/dist/lib/stream-promise-flatten.js.map +1 -0
- package/dist/lib/utils.js +101 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.test.js +9 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +19 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js +275 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.js +109 -0
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/index.js +331 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js +103 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.js +99 -0
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +19 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js +19 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js +92 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
- package/dist/types/base/autosuggestion-state.js +19 -0
- package/dist/types/base/autosuggestion-state.js.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.js +19 -0
- package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
- package/dist/types/base/base-autosuggestions-config.js +38 -0
- package/dist/types/base/base-autosuggestions-config.js.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.js +19 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
- package/dist/types/base/custom-editor.js +19 -0
- package/dist/types/base/custom-editor.js.map +1 -0
- package/dist/types/base/editor-autocomplete-state.js +45 -0
- package/dist/types/base/editor-autocomplete-state.js.map +1 -0
- package/dist/types/base/index.js +40 -0
- package/dist/types/base/index.js.map +1 -0
- package/dist/types/html-copilot-textarea-element.js +19 -0
- package/dist/types/html-copilot-textarea-element.js.map +1 -0
- package/dist/types/index.js +333 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +4 -4
- package/tsup.config.ts +1 -1
- /package/dist/{chunk-34D4UIYX.mjs.map → chunk-4ENJ4VF6.mjs.map} +0 -0
- /package/dist/{chunk-IPM5WWPW.mjs.map → chunk-JHLXWI44.mjs.map} +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/get-text-around-cursor.ts
|
|
21
|
+
var get_text_around_cursor_exports = {};
|
|
22
|
+
__export(get_text_around_cursor_exports, {
|
|
23
|
+
extractTextWithNewlines: () => extractTextWithNewlines,
|
|
24
|
+
getFullEditorTextWithNewlines: () => getFullEditorTextWithNewlines,
|
|
25
|
+
getTextAroundCollapsedCursor: () => getTextAroundCollapsedCursor,
|
|
26
|
+
getTextAroundSelection: () => getTextAroundSelection
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(get_text_around_cursor_exports);
|
|
29
|
+
var import_slate = require("slate");
|
|
30
|
+
function getTextAroundCollapsedCursor(editor) {
|
|
31
|
+
const { selection } = editor;
|
|
32
|
+
if (!selection || !import_slate.Range.isCollapsed(selection)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const cursorPoint = selection.anchor;
|
|
36
|
+
const beforeRange = {
|
|
37
|
+
anchor: import_slate.Editor.start(editor, []),
|
|
38
|
+
focus: cursorPoint
|
|
39
|
+
};
|
|
40
|
+
const afterRange = {
|
|
41
|
+
anchor: cursorPoint,
|
|
42
|
+
focus: import_slate.Editor.end(editor, [])
|
|
43
|
+
};
|
|
44
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
45
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
46
|
+
return {
|
|
47
|
+
cursorPoint,
|
|
48
|
+
textBeforeCursor: before,
|
|
49
|
+
textAfterCursor: after
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function getTextAroundSelection(editor) {
|
|
53
|
+
const { selection } = editor;
|
|
54
|
+
if (!selection) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
58
|
+
const beforeRange = {
|
|
59
|
+
anchor: import_slate.Editor.start(editor, []),
|
|
60
|
+
focus: wellOrderedSelection.anchor
|
|
61
|
+
};
|
|
62
|
+
const afterRange = {
|
|
63
|
+
anchor: wellOrderedSelection.focus,
|
|
64
|
+
focus: import_slate.Editor.end(editor, [])
|
|
65
|
+
};
|
|
66
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
67
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
68
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
69
|
+
return {
|
|
70
|
+
selection: wellOrderedSelection,
|
|
71
|
+
textBeforeCursor: before,
|
|
72
|
+
selectedText,
|
|
73
|
+
textAfterCursor: after
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getFullEditorTextWithNewlines(editor) {
|
|
77
|
+
const fullDocumentRange = {
|
|
78
|
+
anchor: import_slate.Editor.start(editor, []),
|
|
79
|
+
focus: import_slate.Editor.end(editor, [])
|
|
80
|
+
};
|
|
81
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
82
|
+
}
|
|
83
|
+
function extractTextWithNewlines(editor, range) {
|
|
84
|
+
const voids = false;
|
|
85
|
+
const [start, end] = import_slate.Range.edges(range);
|
|
86
|
+
let text = "";
|
|
87
|
+
let lastBlock = null;
|
|
88
|
+
for (const [node, path] of import_slate.Editor.nodes(editor, {
|
|
89
|
+
at: range,
|
|
90
|
+
match: import_slate.Text.isText,
|
|
91
|
+
voids
|
|
92
|
+
})) {
|
|
93
|
+
let t = node.text;
|
|
94
|
+
const [block] = import_slate.Editor.above(editor, {
|
|
95
|
+
at: path,
|
|
96
|
+
match: (n) => import_slate.Element.isElement(n) && n.type === "paragraph"
|
|
97
|
+
}) || [null];
|
|
98
|
+
if (lastBlock !== block && block) {
|
|
99
|
+
if (lastBlock) {
|
|
100
|
+
text += "\n";
|
|
101
|
+
}
|
|
102
|
+
lastBlock = block;
|
|
103
|
+
}
|
|
104
|
+
if (import_slate.Path.equals(path, end.path)) {
|
|
105
|
+
t = t.slice(0, end.offset);
|
|
106
|
+
}
|
|
107
|
+
if (import_slate.Path.equals(path, start.path)) {
|
|
108
|
+
t = t.slice(start.offset);
|
|
109
|
+
}
|
|
110
|
+
text += t;
|
|
111
|
+
}
|
|
112
|
+
return text;
|
|
113
|
+
}
|
|
114
|
+
function wellOrderedRange(range) {
|
|
115
|
+
const { anchor, focus } = range;
|
|
116
|
+
if (import_slate.Point.isBefore(anchor, focus)) {
|
|
117
|
+
return range;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
anchor: focus,
|
|
121
|
+
focus: anchor
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
extractTextWithNewlines,
|
|
127
|
+
getFullEditorTextWithNewlines,
|
|
128
|
+
getTextAroundCollapsedCursor,
|
|
129
|
+
getTextAroundSelection
|
|
130
|
+
});
|
|
131
|
+
//# sourceMappingURL=get-text-around-cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/get-text-around-cursor.ts"],"sourcesContent":["import {\n Editor,\n Node,\n Path,\n Range,\n Text,\n Element,\n BasePoint,\n BaseRange,\n Point,\n} from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(\n editor: Editor\n): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\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: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\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 const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\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\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAUO;AAWA,SAAS,6BACd,QACgC;AAChC,QAAM,EAAE,UAAU,IAAI;AACtB,MAAI,CAAC,aAAa,CAAC,mBAAM,YAAY,SAAS,GAAG;AAC/C,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,UAAU;AAG9B,QAAM,cAAqB;AAAA,IACzB,QAAQ,oBAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO;AAAA,EACT;AACA,QAAM,aAA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AM,QAAQ;AAAA,IAC9C,IAAI;AAAA,IACJ,OAAO,kBAAK;AAAA,IACZ;AAAA,EACF,CAAC,GAAG;AACF,QAAI,IAAI,KAAK;AAGb,UAAM,CAAC,KAAK,IAAI,oBAAO,MAAM,QAAQ;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO,CAAC,MAAM,qBAAQ,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,kBAAK,OAAO,MAAM,IAAI,IAAI,GAAG;AAC/B,UAAI,EAAE,MAAM,GAAG,IAAI,MAAM;AAAA,IAC3B;AAEA,QAAI,kBAAK,OAAO,MAAM,MAAM,IAAI,GAAG;AACjC,UAAI,EAAE,MAAM,MAAM,MAAM;AAAA,IAC1B;AAEA,YAAQ;AAAA,EACV;AAEA,SAAO;AACT;AAEA,SAAS,iBAAiB,OAA6B;AACrD,QAAM,EAAE,QAAQ,MAAM,IAAI;AAE1B,MAAI,mBAAM,SAAS,QAAQ,KAAK,GAAG;AACjC,WAAO;AAAA,EACT;AAGA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/retry.tsx
|
|
21
|
+
var retry_exports = {};
|
|
22
|
+
__export(retry_exports, {
|
|
23
|
+
retry: () => retry
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(retry_exports);
|
|
26
|
+
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
fn().then(resolve).catch((error) => {
|
|
29
|
+
if (retriesLeft === 1) {
|
|
30
|
+
reject(error);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
35
|
+
}, interval);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
retry
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/retry.tsx"],"sourcesContent":["export function retry<T>(\n fn: () => Promise<T>,\n retriesLeft: number = 2,\n interval: number = 200,\n backoff: number = 1.5\n): Promise<T> {\n return new Promise((resolve, reject) => {\n fn()\n .then(resolve)\n .catch((error) => {\n if (retriesLeft === 1) {\n reject(error);\n return;\n }\n\n setTimeout(() => {\n retry(fn, retriesLeft - 1, interval * backoff, backoff)\n .then(resolve)\n .catch(reject);\n }, interval);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,MACd,IACA,cAAsB,GACtB,WAAmB,KACnB,UAAkB,KACN;AACZ,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,UAAU;AAChB,UAAI,gBAAgB,GAAG;AACrB,eAAO,KAAK;AACZ;AAAA,MACF;AAEA,iBAAW,MAAM;AACf,cAAM,IAAI,cAAc,GAAG,WAAW,SAAS,OAAO,EACnD,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,MACjB,GAAG,QAAQ;AAAA,IACb,CAAC;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/slatejs-edits/add-autocompletions.ts
|
|
21
|
+
var add_autocompletions_exports = {};
|
|
22
|
+
__export(add_autocompletions_exports, {
|
|
23
|
+
addAutocompletionsToEditor: () => addAutocompletionsToEditor
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(add_autocompletions_exports);
|
|
26
|
+
var import_slate = require("slate");
|
|
27
|
+
function addAutocompletionsToEditor(editor, newSuggestion, point) {
|
|
28
|
+
const editorPosition = editor.selection;
|
|
29
|
+
import_slate.Transforms.insertNodes(
|
|
30
|
+
editor,
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
type: "suggestion",
|
|
34
|
+
inline: true,
|
|
35
|
+
content: newSuggestion,
|
|
36
|
+
children: [{ text: "" }]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
{
|
|
40
|
+
at: point
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
if (editorPosition) {
|
|
44
|
+
editor.selection = editorPosition;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
addAutocompletionsToEditor
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=add-autocompletions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/add-autocompletions.ts"],"sourcesContent":["import { BasePoint, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function addAutocompletionsToEditor(\n editor: CustomEditor,\n newSuggestion: string,\n point: BasePoint\n) {\n const editorPosition = editor.selection;\n\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"suggestion\",\n inline: true,\n content: newSuggestion,\n children: [{ text: \"\" }],\n },\n ],\n {\n at: point,\n }\n );\n\n // restore cursor position\n if (editorPosition) {\n editor.selection = editorPosition;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAG/B,SAAS,2BACd,QACA,eACA,OACA;AACA,QAAM,iBAAiB,OAAO;AAE9B,0BAAW;AAAA,IACT;AAAA,IACA;AAAA,MACE;AAAA,QACE,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,UAAU,CAAC,EAAE,MAAM,GAAG,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,IACA;AAAA,MACE,IAAI;AAAA,IACN;AAAA,EACF;AAGA,MAAI,gBAAgB;AAClB,WAAO,YAAY;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/slatejs-edits/clear-autocompletions.ts
|
|
21
|
+
var clear_autocompletions_exports = {};
|
|
22
|
+
__export(clear_autocompletions_exports, {
|
|
23
|
+
clearAutocompletionsFromEditor: () => clearAutocompletionsFromEditor
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(clear_autocompletions_exports);
|
|
26
|
+
var import_slate = require("slate");
|
|
27
|
+
function clearAutocompletionsFromEditor(editor) {
|
|
28
|
+
const paths = [];
|
|
29
|
+
for (const [node, path] of import_slate.Node.nodes(editor)) {
|
|
30
|
+
if (import_slate.Element.isElement(node) && node.type === "suggestion") {
|
|
31
|
+
paths.push(path);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const path of paths) {
|
|
35
|
+
try {
|
|
36
|
+
import_slate.Transforms.removeNodes(editor, { at: path });
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.log(
|
|
39
|
+
"CopilotTextarea.clearAutocompletionsFromEditor: error removing node",
|
|
40
|
+
e
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
clearAutocompletionsFromEditor
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=clear-autocompletions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/clear-autocompletions.ts"],"sourcesContent":["import { Element, Node, Path, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/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 try {\n Transforms.removeNodes(editor, { at: path });\n } catch (e) {\n console.log(\n \"CopilotTextarea.clearAutocompletionsFromEditor: error removing node\",\n e\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgD;AAGzC,SAAS,+BAA+B,QAAsB;AAEnE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,kBAAK,MAAM,MAAM,GAAG;AAC7C,QAAI,qBAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,cAAc;AACzD,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,8BAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,GAAP;AACA,cAAQ;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/slatejs-edits/replace-text.ts
|
|
21
|
+
var replace_text_exports = {};
|
|
22
|
+
__export(replace_text_exports, {
|
|
23
|
+
replaceEditorText: () => replaceEditorText
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(replace_text_exports);
|
|
26
|
+
var import_slate = require("slate");
|
|
27
|
+
function replaceEditorText(editor, newText) {
|
|
28
|
+
import_slate.Transforms.delete(editor, {
|
|
29
|
+
at: {
|
|
30
|
+
anchor: import_slate.Editor.start(editor, []),
|
|
31
|
+
focus: import_slate.Editor.end(editor, [])
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (newText && newText !== "") {
|
|
35
|
+
import_slate.Transforms.insertNodes(
|
|
36
|
+
editor,
|
|
37
|
+
[
|
|
38
|
+
{
|
|
39
|
+
type: "paragraph",
|
|
40
|
+
children: [{ text: newText }]
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
{
|
|
44
|
+
at: [0]
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
replaceEditorText
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=replace-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/replace-text.ts"],"sourcesContent":["import { Editor, Transforms } from \"slate\";\n\nexport function replaceEditorText(editor: Editor, newText: string) {\n // clear all previous text\n Transforms.delete(editor, {\n at: {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n },\n });\n\n // insert new text\n if (newText && newText !== \"\") {\n // don't insert empty text - results in strange visual behavior\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"paragraph\",\n children: [{ text: newText }],\n },\n ],\n {\n at: [0],\n }\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AAE5B,SAAS,kBAAkB,QAAgB,SAAiB;AAEjE,0BAAW,OAAO,QAAQ;AAAA,IACxB,IAAI;AAAA,MACF,QAAQ,oBAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,MAC/B,OAAO,oBAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,IAC9B;AAAA,EACF,CAAC;AAGD,MAAI,WAAW,YAAY,IAAI;AAE7B,4BAAW;AAAA,MACT;AAAA,MACA;AAAA,QACE;AAAA,UACE,MAAM;AAAA,UACN,UAAU,CAAC,EAAE,MAAM,QAAQ,CAAC;AAAA,QAC9B;AAAA,MACF;AAAA,MACA;AAAA,QACE,IAAI,CAAC,CAAC;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/slatejs-edits/with-partial-history.ts
|
|
21
|
+
var with_partial_history_exports = {};
|
|
22
|
+
__export(with_partial_history_exports, {
|
|
23
|
+
defaultShouldSave: () => defaultShouldSave,
|
|
24
|
+
withPartialHistory: () => withPartialHistory
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(with_partial_history_exports);
|
|
27
|
+
var import_slate = require("slate");
|
|
28
|
+
var import_slate_history = require("slate-history");
|
|
29
|
+
var withPartialHistory = (editor, shouldSave) => {
|
|
30
|
+
const e = editor;
|
|
31
|
+
const { apply } = e;
|
|
32
|
+
e.history = { undos: [], redos: [] };
|
|
33
|
+
e.redo = () => {
|
|
34
|
+
const { history } = e;
|
|
35
|
+
const { redos } = history;
|
|
36
|
+
if (redos.length > 0) {
|
|
37
|
+
const batch = redos[redos.length - 1];
|
|
38
|
+
if (batch.selectionBefore) {
|
|
39
|
+
import_slate.Transforms.setSelection(e, batch.selectionBefore);
|
|
40
|
+
}
|
|
41
|
+
import_slate_history.HistoryEditor.withoutSaving(e, () => {
|
|
42
|
+
import_slate.Editor.withoutNormalizing(e, () => {
|
|
43
|
+
for (const op of batch.operations) {
|
|
44
|
+
e.apply(op);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
history.redos.pop();
|
|
49
|
+
e.writeHistory("undos", batch);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
e.undo = () => {
|
|
53
|
+
const { history } = e;
|
|
54
|
+
const { undos } = history;
|
|
55
|
+
if (undos.length > 0) {
|
|
56
|
+
const batch = undos[undos.length - 1];
|
|
57
|
+
import_slate_history.HistoryEditor.withoutSaving(e, () => {
|
|
58
|
+
import_slate.Editor.withoutNormalizing(e, () => {
|
|
59
|
+
const inverseOps = batch.operations.map(import_slate.Operation.inverse).reverse();
|
|
60
|
+
for (const op of inverseOps) {
|
|
61
|
+
e.apply(op);
|
|
62
|
+
}
|
|
63
|
+
if (batch.selectionBefore) {
|
|
64
|
+
import_slate.Transforms.setSelection(e, batch.selectionBefore);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
e.writeHistory("redos", batch);
|
|
69
|
+
history.undos.pop();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
e.apply = (op) => {
|
|
73
|
+
const { operations, history } = e;
|
|
74
|
+
const { undos } = history;
|
|
75
|
+
const lastBatch = undos[undos.length - 1];
|
|
76
|
+
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
77
|
+
let save = import_slate_history.HistoryEditor.isSaving(e);
|
|
78
|
+
let merge = import_slate_history.HistoryEditor.isMerging(e);
|
|
79
|
+
if (save == null) {
|
|
80
|
+
save = shouldSave(op, lastOp);
|
|
81
|
+
}
|
|
82
|
+
if (save) {
|
|
83
|
+
if (merge == null) {
|
|
84
|
+
if (lastBatch == null) {
|
|
85
|
+
merge = false;
|
|
86
|
+
} else if (operations.length !== 0) {
|
|
87
|
+
merge = true;
|
|
88
|
+
} else {
|
|
89
|
+
merge = shouldMerge(op, lastOp);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (lastBatch && merge) {
|
|
93
|
+
lastBatch.operations.push(op);
|
|
94
|
+
} else {
|
|
95
|
+
const batch = {
|
|
96
|
+
operations: [op],
|
|
97
|
+
selectionBefore: e.selection
|
|
98
|
+
};
|
|
99
|
+
e.writeHistory("undos", batch);
|
|
100
|
+
}
|
|
101
|
+
while (undos.length > 100) {
|
|
102
|
+
undos.shift();
|
|
103
|
+
}
|
|
104
|
+
history.redos = [];
|
|
105
|
+
}
|
|
106
|
+
apply(op);
|
|
107
|
+
};
|
|
108
|
+
e.writeHistory = (stack, batch) => {
|
|
109
|
+
e.history[stack].push(batch);
|
|
110
|
+
};
|
|
111
|
+
return e;
|
|
112
|
+
};
|
|
113
|
+
var shouldMerge = (op, prev) => {
|
|
114
|
+
if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && import_slate.Path.equals(op.path, prev.path)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && import_slate.Path.equals(op.path, prev.path)) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
var defaultShouldSave = (op, prev) => {
|
|
123
|
+
if (op.type === "set_selection") {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
defaultShouldSave,
|
|
131
|
+
withPartialHistory
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=with-partial-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/with-partial-history.ts"],"sourcesContent":["import { Editor, Operation, Path, Range, Transforms } from \"slate\";\nimport { HistoryEditor } from \"slate-history\";\n\n// Copy-pasted from `https://github.com/ianstormtaylor/slate/blob/main/packages/slate-history/src/with-history.ts`\n// With one exception: the `shouldSave` function is passed in as an argument to `withPartialHistory` instead of being hardcoded\nexport type ShouldSaveToHistory = (\n op: Operation,\n prev: Operation | undefined\n) => boolean;\n\nexport const withPartialHistory = <T extends Editor>(\n editor: T,\n shouldSave: ShouldSaveToHistory\n) => {\n const e = editor as T & HistoryEditor;\n const { apply } = e;\n e.history = { undos: [], redos: [] };\n\n e.redo = () => {\n const { history } = e;\n const { redos } = history;\n\n if (redos.length > 0) {\n const batch = redos[redos.length - 1];\n\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n for (const op of batch.operations) {\n e.apply(op);\n }\n });\n });\n\n history.redos.pop();\n e.writeHistory(\"undos\", batch);\n }\n };\n\n e.undo = () => {\n const { history } = e;\n const { undos } = history;\n\n if (undos.length > 0) {\n const batch = undos[undos.length - 1];\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n const inverseOps = batch.operations.map(Operation.inverse).reverse();\n\n for (const op of inverseOps) {\n e.apply(op);\n }\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n });\n });\n\n e.writeHistory(\"redos\", batch);\n history.undos.pop();\n }\n };\n\n e.apply = (op: Operation) => {\n const { operations, history } = e;\n const { undos } = history;\n const lastBatch = undos[undos.length - 1];\n const lastOp =\n lastBatch && lastBatch.operations[lastBatch.operations.length - 1];\n let save = HistoryEditor.isSaving(e);\n let merge = HistoryEditor.isMerging(e);\n\n if (save == null) {\n save = shouldSave(op, lastOp);\n }\n\n if (save) {\n if (merge == null) {\n if (lastBatch == null) {\n merge = false;\n } else if (operations.length !== 0) {\n merge = true;\n } else {\n merge = shouldMerge(op, lastOp);\n }\n }\n\n if (lastBatch && merge) {\n lastBatch.operations.push(op);\n } else {\n const batch = {\n operations: [op],\n selectionBefore: e.selection,\n };\n e.writeHistory(\"undos\", batch);\n }\n\n while (undos.length > 100) {\n undos.shift();\n }\n\n history.redos = [];\n }\n\n apply(op);\n };\n\n e.writeHistory = (stack: \"undos\" | \"redos\", batch: any) => {\n e.history[stack].push(batch);\n };\n\n return e;\n};\n\n/**\n * Check whether to merge an operation into the previous operation.\n */\n\nconst shouldMerge = (op: Operation, prev: Operation | undefined): boolean => {\n if (\n prev &&\n op.type === \"insert_text\" &&\n prev.type === \"insert_text\" &&\n op.offset === prev.offset + prev.text.length &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n if (\n prev &&\n op.type === \"remove_text\" &&\n prev.type === \"remove_text\" &&\n op.offset + op.text.length === prev.offset &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n return false;\n};\n\nexport const defaultShouldSave = (\n op: Operation,\n prev: Operation | undefined\n): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2D;AAC3D,2BAA8B;AASvB,IAAM,qBAAqB,CAChC,QACA,eACG;AACH,QAAM,IAAI;AACV,QAAM,EAAE,MAAM,IAAI;AAClB,IAAE,UAAU,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE;AAEnC,IAAE,OAAO,MAAM;AACb,UAAM,EAAE,QAAQ,IAAI;AACpB,UAAM,EAAE,MAAM,IAAI;AAElB,QAAI,MAAM,SAAS,GAAG;AACpB,YAAM,QAAQ,MAAM,MAAM,SA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wnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/lib/stream-promise-flatten.ts
|
|
41
|
+
var stream_promise_flatten_exports = {};
|
|
42
|
+
__export(stream_promise_flatten_exports, {
|
|
43
|
+
streamPromiseFlatten: () => streamPromiseFlatten
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(stream_promise_flatten_exports);
|
|
46
|
+
function streamPromiseFlatten(promise) {
|
|
47
|
+
return new ReadableStream({
|
|
48
|
+
start(controller) {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const stream = yield promise;
|
|
52
|
+
const reader = stream.getReader();
|
|
53
|
+
while (true) {
|
|
54
|
+
const { done, value } = yield reader.read();
|
|
55
|
+
if (done) {
|
|
56
|
+
controller.close();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
controller.enqueue(value);
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
controller.error(error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
streamPromiseFlatten
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=stream-promise-flatten.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/stream-promise-flatten.ts"],"sourcesContent":["/**\n * Flatten a promise of a stream, into a stream.\n *\n * Useful because a stream already includes the notion of async value delivery,\n * so it often makes sense to simply await the values rather than the generator of the values.\n *\n * @param {Promise<ReadableStream<A>>} promise - The promise to flatten.\n * @returns {ReadableStream<A>} - The flattened stream.\n */\n\nexport function streamPromiseFlatten<A>(\n promise: Promise<ReadableStream<A>>\n): ReadableStream<A> {\n return new ReadableStream<A>({\n async start(controller) {\n try {\n const stream = await promise;\n const reader = stream.getReader();\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n controller.close();\n return;\n }\n\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n }\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,qBACd,SACmB;AACnB,SAAO,IAAI,eAAkB;AAAA,IACrB,MAAM,YAAY;AAAA;AACtB,YAAI;AACF,gBAAM,SAAS,MAAM;AACrB,gBAAM,SAAS,OAAO,UAAU;AAEhC,iBAAO,MAAM;AACX,kBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,gBAAI,MAAM;AACR,yBAAW,MAAM;AACjB;AAAA,YACF;AAEA,uBAAW,QAAQ,KAAK;AAAA,UAC1B;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AAAA,QACxB;AAAA,MACF;AAAA;AAAA,EACF,CAAC;AACH;","names":[]}
|