@copilotkit/react-textarea 0.35.0-function-calling-fixes.1 → 0.35.0-function-calling-fixes.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 +308 -304
- package/CHANGELOG.md +12 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +1752 -36
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +48 -4
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +46 -4
- 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 +83 -5
- 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 +54 -4
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +2196 -45
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +13 -5
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +130 -8
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +876 -19
- 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 +569 -14
- 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 +592 -15
- 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/included-files-preview.mjs +98 -7
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +592 -16
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.mjs +2196 -48
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +0 -2
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +207 -8
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.mjs +81 -6
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/card.mjs +42 -7
- package/dist/components/ui/card.mjs.map +1 -1
- package/dist/components/ui/command.mjs +232 -14
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +134 -11
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +56 -5
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/components/ui/separator.mjs +42 -7
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/textarea.mjs +42 -7
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/context/index.mjs +0 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +155 -7
- 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 +165 -5
- 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 +145 -6
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.mjs +0 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +111 -5
- 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 +160 -5
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +12 -4
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.mjs +2196 -56
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.mjs +48 -4
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +40 -4
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.mjs +96 -7
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +14 -4
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +22 -4
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +17 -4
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +24 -4
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +102 -5
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +44 -4
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +63 -9
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +271 -9
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +82 -6
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +271 -10
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +73 -6
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +59 -6
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +23 -4
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +14 -5
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.mjs +23 -5
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +0 -1
- package/dist/types/index.mjs +271 -14
- package/dist/types/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/lib/retry.mjs
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/lib/retry.tsx
|
|
2
|
+
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
fn().then(resolve).catch((error) => {
|
|
5
|
+
if (retriesLeft === 1) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
setTimeout(() => {
|
|
10
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
11
|
+
}, interval);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
5
15
|
export {
|
|
6
16
|
retry
|
|
7
17
|
};
|
package/dist/lib/retry.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
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":";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":[]}
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/lib/slatejs-edits/add-autocompletions.ts
|
|
2
|
+
import { Transforms } from "slate";
|
|
3
|
+
function addAutocompletionsToEditor(editor, newSuggestion, point) {
|
|
4
|
+
const editorPosition = editor.selection;
|
|
5
|
+
Transforms.insertNodes(
|
|
6
|
+
editor,
|
|
7
|
+
[
|
|
8
|
+
{
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
inline: true,
|
|
11
|
+
content: newSuggestion,
|
|
12
|
+
children: [{ text: "" }]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
{
|
|
16
|
+
at: point
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
if (editorPosition) {
|
|
20
|
+
editor.selection = editorPosition;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
5
23
|
export {
|
|
6
24
|
addAutocompletionsToEditor
|
|
7
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
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,SAAoB,kBAAkB;AAG/B,SAAS,2BACd,QACA,eACA,OACA;AACA,QAAM,iBAAiB,OAAO;AAE9B,aAAW;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":[]}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/lib/slatejs-edits/clear-autocompletions.ts
|
|
2
|
+
import { Element, Node, Transforms } from "slate";
|
|
3
|
+
function clearAutocompletionsFromEditor(editor) {
|
|
4
|
+
const paths = [];
|
|
5
|
+
for (const [node, path] of Node.nodes(editor)) {
|
|
6
|
+
if (Element.isElement(node) && node.type === "suggestion") {
|
|
7
|
+
paths.push(path);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
for (const path of paths) {
|
|
11
|
+
try {
|
|
12
|
+
Transforms.removeNodes(editor, { at: path });
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
5
18
|
export {
|
|
6
19
|
clearAutocompletionsFromEditor
|
|
7
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
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(\"CopilotTextarea.clearAutocompletionsFromEditor: error removing node\", e);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,MAAY,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,QAAI;AACF,iBAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,GAAP;AACA,cAAQ,IAAI,uEAAuE,CAAC;AAAA,IACtF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/lib/slatejs-edits/replace-text.ts
|
|
2
|
+
import { Editor, Transforms } from "slate";
|
|
3
|
+
function replaceEditorText(editor, newText) {
|
|
4
|
+
Transforms.delete(editor, {
|
|
5
|
+
at: {
|
|
6
|
+
anchor: Editor.start(editor, []),
|
|
7
|
+
focus: Editor.end(editor, [])
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (newText && newText !== "") {
|
|
11
|
+
Transforms.insertNodes(
|
|
12
|
+
editor,
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
type: "paragraph",
|
|
16
|
+
children: [{ text: newText }]
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
{
|
|
20
|
+
at: [0]
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
5
25
|
export {
|
|
6
26
|
replaceEditorText
|
|
7
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
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,SAAS,QAAQ,kBAAkB;AAE5B,SAAS,kBAAkB,QAAgB,SAAiB;AAEjE,aAAW,OAAO,QAAQ;AAAA,IACxB,IAAI;AAAA,MACF,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,MAC/B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,IAC9B;AAAA,EACF,CAAC;AAGD,MAAI,WAAW,YAAY,IAAI;AAE7B,eAAW;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":[]}
|
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/lib/slatejs-edits/with-partial-history.ts
|
|
2
|
+
import { Editor, Operation, Path, Transforms } from "slate";
|
|
3
|
+
import { HistoryEditor } from "slate-history";
|
|
4
|
+
var withPartialHistory = (editor, shouldSave) => {
|
|
5
|
+
const e = editor;
|
|
6
|
+
const { apply } = e;
|
|
7
|
+
e.history = { undos: [], redos: [] };
|
|
8
|
+
e.redo = () => {
|
|
9
|
+
const { history } = e;
|
|
10
|
+
const { redos } = history;
|
|
11
|
+
if (redos.length > 0) {
|
|
12
|
+
const batch = redos[redos.length - 1];
|
|
13
|
+
if (batch.selectionBefore) {
|
|
14
|
+
Transforms.setSelection(e, batch.selectionBefore);
|
|
15
|
+
}
|
|
16
|
+
HistoryEditor.withoutSaving(e, () => {
|
|
17
|
+
Editor.withoutNormalizing(e, () => {
|
|
18
|
+
for (const op of batch.operations) {
|
|
19
|
+
e.apply(op);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
history.redos.pop();
|
|
24
|
+
e.writeHistory("undos", batch);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
e.undo = () => {
|
|
28
|
+
const { history } = e;
|
|
29
|
+
const { undos } = history;
|
|
30
|
+
if (undos.length > 0) {
|
|
31
|
+
const batch = undos[undos.length - 1];
|
|
32
|
+
HistoryEditor.withoutSaving(e, () => {
|
|
33
|
+
Editor.withoutNormalizing(e, () => {
|
|
34
|
+
const inverseOps = batch.operations.map(Operation.inverse).reverse();
|
|
35
|
+
for (const op of inverseOps) {
|
|
36
|
+
e.apply(op);
|
|
37
|
+
}
|
|
38
|
+
if (batch.selectionBefore) {
|
|
39
|
+
Transforms.setSelection(e, batch.selectionBefore);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
e.writeHistory("redos", batch);
|
|
44
|
+
history.undos.pop();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
e.apply = (op) => {
|
|
48
|
+
const { operations, history } = e;
|
|
49
|
+
const { undos } = history;
|
|
50
|
+
const lastBatch = undos[undos.length - 1];
|
|
51
|
+
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
52
|
+
let save = HistoryEditor.isSaving(e);
|
|
53
|
+
let merge = HistoryEditor.isMerging(e);
|
|
54
|
+
if (save == null) {
|
|
55
|
+
save = shouldSave(op, lastOp);
|
|
56
|
+
}
|
|
57
|
+
if (save) {
|
|
58
|
+
if (merge == null) {
|
|
59
|
+
if (lastBatch == null) {
|
|
60
|
+
merge = false;
|
|
61
|
+
} else if (operations.length !== 0) {
|
|
62
|
+
merge = true;
|
|
63
|
+
} else {
|
|
64
|
+
merge = shouldMerge(op, lastOp);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (lastBatch && merge) {
|
|
68
|
+
lastBatch.operations.push(op);
|
|
69
|
+
} else {
|
|
70
|
+
const batch = {
|
|
71
|
+
operations: [op],
|
|
72
|
+
selectionBefore: e.selection
|
|
73
|
+
};
|
|
74
|
+
e.writeHistory("undos", batch);
|
|
75
|
+
}
|
|
76
|
+
while (undos.length > 100) {
|
|
77
|
+
undos.shift();
|
|
78
|
+
}
|
|
79
|
+
history.redos = [];
|
|
80
|
+
}
|
|
81
|
+
apply(op);
|
|
82
|
+
};
|
|
83
|
+
e.writeHistory = (stack, batch) => {
|
|
84
|
+
e.history[stack].push(batch);
|
|
85
|
+
};
|
|
86
|
+
return e;
|
|
87
|
+
};
|
|
88
|
+
var shouldMerge = (op, prev) => {
|
|
89
|
+
if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
};
|
|
97
|
+
var defaultShouldSave = (op, prev) => {
|
|
98
|
+
if (op.type === "set_selection") {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
6
103
|
export {
|
|
7
104
|
defaultShouldSave,
|
|
8
105
|
withPartialHistory
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
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 = (op: Operation, prev: Operation | undefined) => 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 = 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 = (op: Operation, prev: Operation | undefined): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"],"mappings":";AA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GAAG,KAAK,WAAW,KAAK,UACpC,KAAK,OAAO,GAAG,MAAM,KAAK,IAAI,GAC9B;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,IAAe,SAAyC;AACxF,MAAI,GAAG,SAAS,iBAAiB;AAC/B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/stream-promise-flatten.ts
|
|
23
|
+
function streamPromiseFlatten(promise) {
|
|
24
|
+
return new ReadableStream({
|
|
25
|
+
start(controller) {
|
|
26
|
+
return __async(this, null, function* () {
|
|
27
|
+
try {
|
|
28
|
+
const stream = yield promise;
|
|
29
|
+
const reader = stream.getReader();
|
|
30
|
+
while (true) {
|
|
31
|
+
const { done, value } = yield reader.read();
|
|
32
|
+
if (done) {
|
|
33
|
+
controller.close();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
controller.enqueue(value);
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
controller.error(error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
5
45
|
export {
|
|
6
46
|
streamPromiseFlatten
|
|
7
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
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>(promise: Promise<ReadableStream<A>>): 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":";;;;;;;;;;;;;;;;;;;;;;AAUO,SAAS,qBAAwB,SAAwD;AAC9F,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":[]}
|
package/dist/lib/utils.mjs
CHANGED
|
@@ -1,12 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/utils.ts
|
|
23
|
+
import { clsx } from "clsx";
|
|
24
|
+
import { customAlphabet } from "nanoid";
|
|
25
|
+
import { twMerge } from "tailwind-merge";
|
|
26
|
+
function cn(...inputs) {
|
|
27
|
+
return twMerge(clsx(inputs));
|
|
28
|
+
}
|
|
29
|
+
var nanoid = customAlphabet(
|
|
30
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
31
|
+
7
|
|
32
|
+
);
|
|
33
|
+
function fetcher(input, init) {
|
|
34
|
+
return __async(this, null, function* () {
|
|
35
|
+
const res = yield fetch(input, init);
|
|
36
|
+
if (!res.ok) {
|
|
37
|
+
const json = yield res.json();
|
|
38
|
+
if (json.error) {
|
|
39
|
+
const error = new Error(json.error);
|
|
40
|
+
error.status = res.status;
|
|
41
|
+
throw error;
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error("An unexpected error occurred");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return res.json();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function formatDate(input) {
|
|
50
|
+
const date = new Date(input);
|
|
51
|
+
return date.toLocaleDateString("en-US", {
|
|
52
|
+
month: "long",
|
|
53
|
+
day: "numeric",
|
|
54
|
+
year: "numeric"
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
58
|
+
function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
|
|
59
|
+
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
60
|
+
return a === b;
|
|
61
|
+
}
|
|
62
|
+
return naiveEqualityCheck(a, b);
|
|
63
|
+
}
|
|
10
64
|
export {
|
|
11
65
|
arraysAreEqual,
|
|
12
66
|
cn,
|
package/dist/lib/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils.ts"],"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>(input: RequestInfo, init?: RequestInit): 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 && 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"],"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,QAAoB,OAAoB,MAAmC;AAAA;AAC/F,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,UAAU,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU,KAAK,KAAK,CAAC;AAE5E,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;","names":[]}
|