@copilotkit/react-textarea 0.28.0-alpha.1 → 0.28.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 +301 -152
- package/CHANGELOG.md +16 -1
- package/dist/{chunk-LQZBI6XD.mjs → chunk-5J3UZV77.mjs} +3 -3
- package/dist/chunk-5J3UZV77.mjs.map +1 -0
- package/dist/{chunk-YLXEQDMS.mjs → chunk-B6TKVDDY.mjs} +5 -5
- package/dist/chunk-B6TKVDDY.mjs.map +1 -0
- package/dist/{chunk-HSCZA5TS.mjs → chunk-BBZ7AWOB.mjs} +2 -2
- package/dist/chunk-BBZ7AWOB.mjs.map +1 -0
- package/dist/{chunk-47L4PLG4.mjs → chunk-LQ2OWQU7.mjs} +1 -1
- package/dist/chunk-LQ2OWQU7.mjs.map +1 -0
- package/dist/{chunk-XV7MLLXQ.mjs → chunk-LYB4B6MK.mjs} +1 -1
- package/dist/chunk-LYB4B6MK.mjs.map +1 -0
- package/dist/{chunk-KJNSWCJC.mjs → chunk-QCPS6IYI.mjs} +6 -10
- package/dist/chunk-QCPS6IYI.mjs.map +1 -0
- package/dist/{chunk-NT3GWKWK.mjs → chunk-RT4UTBH3.mjs} +7 -7
- package/dist/chunk-RT4UTBH3.mjs.map +1 -0
- package/dist/{chunk-JYWINDWZ.mjs → chunk-SNQEBH5I.mjs} +4 -4
- package/dist/{chunk-JYWINDWZ.mjs.map → chunk-SNQEBH5I.mjs.map} +1 -1
- package/dist/{chunk-EPBVNDKE.mjs → chunk-SX6NY5FW.mjs} +1 -1
- package/dist/chunk-SX6NY5FW.mjs.map +1 -0
- package/dist/{chunk-KTTN5H7S.mjs → chunk-VB4VNCIQ.mjs} +6 -4
- package/dist/chunk-VB4VNCIQ.mjs.map +1 -0
- package/dist/{chunk-OHO4G6DR.mjs → chunk-XW3ICO4S.mjs} +1 -1
- package/dist/chunk-XW3ICO4S.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1658 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +8 -8
- package/dist/components/base-copilot-textarea/render-element.js +53 -0
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js +51 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +85 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.js +61 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +2082 -0
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs +11 -11
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +2 -2
- package/dist/components/hovering-toolbar/hovering-editor-provider.js +21 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +144 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js +842 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +5 -5
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +1 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +544 -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-core.mjs +2 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +1 -2
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +564 -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/hovering-insertion-prompt-box.mjs +3 -3
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +4 -4
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +122 -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/included-files-preview.mjs +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +0 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +564 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +3 -3
- package/dist/components/index.js +2083 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +11 -11
- package/dist/components/manual-ui/chip-with-icon.d.ts +1 -3
- package/dist/components/manual-ui/chip-with-icon.js +16 -0
- package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.js +213 -0
- package/dist/components/source-search-box/source-search-box.js.map +1 -0
- package/dist/components/ui/button.js +103 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/card.js +124 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/command.js +243 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/dialog.js +162 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/label.js +78 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/separator.js +86 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/textarea.js +83 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/context/index.js +4 -0
- package/dist/context/index.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +158 -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 +169 -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 +151 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +113 -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-autosuggestions-function.mjs +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +162 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
- package/dist/hooks/misc/use-autosize-textarea.js +19 -0
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
- package/dist/index.js +2085 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +12 -12
- package/dist/lib/debouncer.js +54 -0
- package/dist/lib/debouncer.js.map +1 -0
- package/dist/lib/editor-to-text.js +47 -0
- package/dist/lib/editor-to-text.js.map +1 -0
- package/dist/lib/get-text-around-cursor.js +106 -0
- package/dist/lib/get-text-around-cursor.js.map +1 -0
- package/dist/lib/retry.js +20 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js +29 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js +24 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.js +31 -0
- package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.js +110 -0
- package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
- package/dist/lib/stream-promise-flatten.js +50 -0
- package/dist/lib/stream-promise-flatten.js.map +1 -0
- package/dist/lib/utils.js +73 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.test.js +10 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +4 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js +273 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.js +90 -0
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/index.js +273 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js +81 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +4 -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 +4 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.js.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js +67 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
- package/dist/types/base/autosuggestion-state.js +4 -0
- package/dist/types/base/autosuggestion-state.js.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.js +4 -0
- package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
- package/dist/types/base/base-autosuggestions-config.js +30 -0
- package/dist/types/base/base-autosuggestions-config.js.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.js +4 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
- package/dist/types/base/custom-editor.js +4 -0
- package/dist/types/base/custom-editor.js.map +1 -0
- package/dist/types/base/editor-autocomplete-state.js +21 -0
- package/dist/types/base/editor-autocomplete-state.js.map +1 -0
- package/dist/types/base/index.js +30 -0
- package/dist/types/base/index.js.map +1 -0
- package/dist/types/html-copilot-textarea-element.js +4 -0
- package/dist/types/html-copilot-textarea-element.js.map +1 -0
- package/dist/types/index.js +274 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +8 -7
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +2 -3
- package/src/components/base-copilot-textarea/render-placeholder.tsx +1 -1
- package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +2 -2
- package/src/components/copilot-textarea/copilot-textarea.tsx +1 -1
- package/src/components/hovering-toolbar/hovering-editor-provider.tsx +2 -2
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +4 -5
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +10 -5
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +1 -2
- package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +4 -4
- package/src/components/manual-ui/chip-with-icon.tsx +1 -3
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +10 -11
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +7 -11
- package/tsup.config.ts +1 -2
- package/dist/chunk-47L4PLG4.mjs.map +0 -1
- package/dist/chunk-EPBVNDKE.mjs.map +0 -1
- package/dist/chunk-HSCZA5TS.mjs.map +0 -1
- package/dist/chunk-KJNSWCJC.mjs.map +0 -1
- package/dist/chunk-KTTN5H7S.mjs.map +0 -1
- package/dist/chunk-LQZBI6XD.mjs.map +0 -1
- package/dist/chunk-NT3GWKWK.mjs.map +0 -1
- package/dist/chunk-OHO4G6DR.mjs.map +0 -1
- package/dist/chunk-XV7MLLXQ.mjs.map +0 -1
- package/dist/chunk-YLXEQDMS.mjs.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var slate = require('slate');
|
|
4
|
+
|
|
5
|
+
// src/lib/get-text-around-cursor.ts
|
|
6
|
+
function getTextAroundCollapsedCursor(editor) {
|
|
7
|
+
const { selection } = editor;
|
|
8
|
+
if (!selection || !slate.Range.isCollapsed(selection)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const cursorPoint = selection.anchor;
|
|
12
|
+
const beforeRange = {
|
|
13
|
+
anchor: slate.Editor.start(editor, []),
|
|
14
|
+
focus: cursorPoint
|
|
15
|
+
};
|
|
16
|
+
const afterRange = {
|
|
17
|
+
anchor: cursorPoint,
|
|
18
|
+
focus: slate.Editor.end(editor, [])
|
|
19
|
+
};
|
|
20
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
21
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
22
|
+
return {
|
|
23
|
+
cursorPoint,
|
|
24
|
+
textBeforeCursor: before,
|
|
25
|
+
textAfterCursor: after
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getTextAroundSelection(editor) {
|
|
29
|
+
const { selection } = editor;
|
|
30
|
+
if (!selection) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
34
|
+
const beforeRange = {
|
|
35
|
+
anchor: slate.Editor.start(editor, []),
|
|
36
|
+
focus: wellOrderedSelection.anchor
|
|
37
|
+
};
|
|
38
|
+
const afterRange = {
|
|
39
|
+
anchor: wellOrderedSelection.focus,
|
|
40
|
+
focus: slate.Editor.end(editor, [])
|
|
41
|
+
};
|
|
42
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
43
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
44
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
45
|
+
return {
|
|
46
|
+
selection: wellOrderedSelection,
|
|
47
|
+
textBeforeCursor: before,
|
|
48
|
+
selectedText,
|
|
49
|
+
textAfterCursor: after
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function getFullEditorTextWithNewlines(editor) {
|
|
53
|
+
const fullDocumentRange = {
|
|
54
|
+
anchor: slate.Editor.start(editor, []),
|
|
55
|
+
focus: slate.Editor.end(editor, [])
|
|
56
|
+
};
|
|
57
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
58
|
+
}
|
|
59
|
+
function extractTextWithNewlines(editor, range) {
|
|
60
|
+
const voids = false;
|
|
61
|
+
const [start, end] = slate.Range.edges(range);
|
|
62
|
+
let text = "";
|
|
63
|
+
let lastBlock = null;
|
|
64
|
+
for (const [node, path] of slate.Editor.nodes(editor, {
|
|
65
|
+
at: range,
|
|
66
|
+
match: slate.Text.isText,
|
|
67
|
+
voids
|
|
68
|
+
})) {
|
|
69
|
+
let t = node.text;
|
|
70
|
+
const [block] = slate.Editor.above(editor, {
|
|
71
|
+
at: path,
|
|
72
|
+
match: (n) => slate.Element.isElement(n) && n.type === "paragraph"
|
|
73
|
+
}) || [null];
|
|
74
|
+
if (lastBlock !== block && block) {
|
|
75
|
+
if (lastBlock) {
|
|
76
|
+
text += "\n";
|
|
77
|
+
}
|
|
78
|
+
lastBlock = block;
|
|
79
|
+
}
|
|
80
|
+
if (slate.Path.equals(path, end.path)) {
|
|
81
|
+
t = t.slice(0, end.offset);
|
|
82
|
+
}
|
|
83
|
+
if (slate.Path.equals(path, start.path)) {
|
|
84
|
+
t = t.slice(start.offset);
|
|
85
|
+
}
|
|
86
|
+
text += t;
|
|
87
|
+
}
|
|
88
|
+
return text;
|
|
89
|
+
}
|
|
90
|
+
function wellOrderedRange(range) {
|
|
91
|
+
const { anchor, focus } = range;
|
|
92
|
+
if (slate.Point.isBefore(anchor, focus)) {
|
|
93
|
+
return range;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
anchor: focus,
|
|
97
|
+
focus: anchor
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
exports.extractTextWithNewlines = extractTextWithNewlines;
|
|
102
|
+
exports.getFullEditorTextWithNewlines = getFullEditorTextWithNewlines;
|
|
103
|
+
exports.getTextAroundCollapsedCursor = getTextAroundCollapsedCursor;
|
|
104
|
+
exports.getTextAroundSelection = getTextAroundSelection;
|
|
105
|
+
//# sourceMappingURL=out.js.map
|
|
106
|
+
//# sourceMappingURL=get-text-around-cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/get-text-around-cursor.ts"],"names":[],"mappings":";AAAA,SAAS,QAAc,MAAM,OAAO,MAAM,SAA+B,aAAa;AAW/E,SAAS,6BAA6B,QAAgD;AAC3F,QAAM,EAAE,UAAU,IAAI;AACtB,MAAI,CAAC,aAAa,CAAC,MAAM,YAAY,SAAS,GAAG;AAC/C,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,UAAU;AAG9B,QAAM,cAAqB;AAAA,IACzB,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO;AAAA,EACT;AACA,QAAM,aAAoB;AAAA,IACxB,QAAQ;AAAA,IACR,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,IACA,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,EACnB;AACF;AAEO,SAAS,uBAAuB,QAAwC;AAC7E,QAAM,E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AAc,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;AAEA,SAAS,iBAAiB,OAA6B;AACrD,QAAM,EAAE,QAAQ,MAAM,IAAI;AAE1B,MAAI,MAAM,SAAS,QAAQ,KAAK,GAAG;AACjC,WAAO;AAAA,EACT;AAGA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF","sourcesContent":["import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } 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(editor: Editor): 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"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/lib/retry.tsx
|
|
4
|
+
function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
fn().then(resolve).catch((error) => {
|
|
7
|
+
if (retriesLeft === 1) {
|
|
8
|
+
reject(error);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
|
|
13
|
+
}, interval);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.retry = retry;
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/retry.tsx"],"names":[],"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","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"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var slate = require('slate');
|
|
4
|
+
|
|
5
|
+
// src/lib/slatejs-edits/add-autocompletions.ts
|
|
6
|
+
function addAutocompletionsToEditor(editor, newSuggestion, point) {
|
|
7
|
+
const editorPosition = editor.selection;
|
|
8
|
+
slate.Transforms.insertNodes(
|
|
9
|
+
editor,
|
|
10
|
+
[
|
|
11
|
+
{
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
inline: true,
|
|
14
|
+
content: newSuggestion,
|
|
15
|
+
children: [{ text: "" }]
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
{
|
|
19
|
+
at: point
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
if (editorPosition) {
|
|
23
|
+
editor.selection = editorPosition;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.addAutocompletionsToEditor = addAutocompletionsToEditor;
|
|
28
|
+
//# sourceMappingURL=out.js.map
|
|
29
|
+
//# sourceMappingURL=add-autocompletions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/add-autocompletions.ts"],"names":[],"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","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"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var slate = require('slate');
|
|
4
|
+
|
|
5
|
+
// src/lib/slatejs-edits/clear-autocompletions.ts
|
|
6
|
+
function clearAutocompletionsFromEditor(editor) {
|
|
7
|
+
const paths = [];
|
|
8
|
+
for (const [node, path] of slate.Node.nodes(editor)) {
|
|
9
|
+
if (slate.Element.isElement(node) && node.type === "suggestion") {
|
|
10
|
+
paths.push(path);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
for (const path of paths) {
|
|
14
|
+
try {
|
|
15
|
+
slate.Transforms.removeNodes(editor, { at: path });
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.clearAutocompletionsFromEditor = clearAutocompletionsFromEditor;
|
|
23
|
+
//# sourceMappingURL=out.js.map
|
|
24
|
+
//# sourceMappingURL=clear-autocompletions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/clear-autocompletions.ts"],"names":[],"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","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"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var slate = require('slate');
|
|
4
|
+
|
|
5
|
+
// src/lib/slatejs-edits/replace-text.ts
|
|
6
|
+
function replaceEditorText(editor, newText) {
|
|
7
|
+
slate.Transforms.delete(editor, {
|
|
8
|
+
at: {
|
|
9
|
+
anchor: slate.Editor.start(editor, []),
|
|
10
|
+
focus: slate.Editor.end(editor, [])
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
if (newText && newText !== "") {
|
|
14
|
+
slate.Transforms.insertNodes(
|
|
15
|
+
editor,
|
|
16
|
+
[
|
|
17
|
+
{
|
|
18
|
+
type: "paragraph",
|
|
19
|
+
children: [{ text: newText }]
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
{
|
|
23
|
+
at: [0]
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.replaceEditorText = replaceEditorText;
|
|
30
|
+
//# sourceMappingURL=out.js.map
|
|
31
|
+
//# sourceMappingURL=replace-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slatejs-edits/replace-text.ts"],"names":[],"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","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"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var slate = require('slate');
|
|
4
|
+
var slateHistory = require('slate-history');
|
|
5
|
+
|
|
6
|
+
// src/lib/slatejs-edits/with-partial-history.ts
|
|
7
|
+
var withPartialHistory = (editor, shouldSave) => {
|
|
8
|
+
const e = editor;
|
|
9
|
+
const { apply } = e;
|
|
10
|
+
e.history = { undos: [], redos: [] };
|
|
11
|
+
e.redo = () => {
|
|
12
|
+
const { history } = e;
|
|
13
|
+
const { redos } = history;
|
|
14
|
+
if (redos.length > 0) {
|
|
15
|
+
const batch = redos[redos.length - 1];
|
|
16
|
+
if (batch.selectionBefore) {
|
|
17
|
+
slate.Transforms.setSelection(e, batch.selectionBefore);
|
|
18
|
+
}
|
|
19
|
+
slateHistory.HistoryEditor.withoutSaving(e, () => {
|
|
20
|
+
slate.Editor.withoutNormalizing(e, () => {
|
|
21
|
+
for (const op of batch.operations) {
|
|
22
|
+
e.apply(op);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
history.redos.pop();
|
|
27
|
+
e.writeHistory("undos", batch);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
e.undo = () => {
|
|
31
|
+
const { history } = e;
|
|
32
|
+
const { undos } = history;
|
|
33
|
+
if (undos.length > 0) {
|
|
34
|
+
const batch = undos[undos.length - 1];
|
|
35
|
+
slateHistory.HistoryEditor.withoutSaving(e, () => {
|
|
36
|
+
slate.Editor.withoutNormalizing(e, () => {
|
|
37
|
+
const inverseOps = batch.operations.map(slate.Operation.inverse).reverse();
|
|
38
|
+
for (const op of inverseOps) {
|
|
39
|
+
e.apply(op);
|
|
40
|
+
}
|
|
41
|
+
if (batch.selectionBefore) {
|
|
42
|
+
slate.Transforms.setSelection(e, batch.selectionBefore);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
e.writeHistory("redos", batch);
|
|
47
|
+
history.undos.pop();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
e.apply = (op) => {
|
|
51
|
+
const { operations, history } = e;
|
|
52
|
+
const { undos } = history;
|
|
53
|
+
const lastBatch = undos[undos.length - 1];
|
|
54
|
+
const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
|
|
55
|
+
let save = slateHistory.HistoryEditor.isSaving(e);
|
|
56
|
+
let merge = slateHistory.HistoryEditor.isMerging(e);
|
|
57
|
+
if (save == null) {
|
|
58
|
+
save = shouldSave(op, lastOp);
|
|
59
|
+
}
|
|
60
|
+
if (save) {
|
|
61
|
+
if (merge == null) {
|
|
62
|
+
if (lastBatch == null) {
|
|
63
|
+
merge = false;
|
|
64
|
+
} else if (operations.length !== 0) {
|
|
65
|
+
merge = true;
|
|
66
|
+
} else {
|
|
67
|
+
merge = shouldMerge(op, lastOp);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (lastBatch && merge) {
|
|
71
|
+
lastBatch.operations.push(op);
|
|
72
|
+
} else {
|
|
73
|
+
const batch = {
|
|
74
|
+
operations: [op],
|
|
75
|
+
selectionBefore: e.selection
|
|
76
|
+
};
|
|
77
|
+
e.writeHistory("undos", batch);
|
|
78
|
+
}
|
|
79
|
+
while (undos.length > 100) {
|
|
80
|
+
undos.shift();
|
|
81
|
+
}
|
|
82
|
+
history.redos = [];
|
|
83
|
+
}
|
|
84
|
+
apply(op);
|
|
85
|
+
};
|
|
86
|
+
e.writeHistory = (stack, batch) => {
|
|
87
|
+
e.history[stack].push(batch);
|
|
88
|
+
};
|
|
89
|
+
return e;
|
|
90
|
+
};
|
|
91
|
+
var shouldMerge = (op, prev) => {
|
|
92
|
+
if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && slate.Path.equals(op.path, prev.path)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && slate.Path.equals(op.path, prev.path)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
};
|
|
100
|
+
var defaultShouldSave = (op, prev) => {
|
|
101
|
+
if (op.type === "set_selection") {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.defaultShouldSave = defaultShouldSave;
|
|
108
|
+
exports.withPartialHistory = withPartialHistory;
|
|
109
|
+
//# sourceMappingURL=out.js.map
|
|
110
|
+
//# sourceMappingURL=with-partial-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib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S,iBACZ,KAAK,SAAS,iBACd,GAAG,SAAS,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","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"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __async = (__this, __arguments, generator) => {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
var fulfilled = (value) => {
|
|
6
|
+
try {
|
|
7
|
+
step(generator.next(value));
|
|
8
|
+
} catch (e) {
|
|
9
|
+
reject(e);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var rejected = (value) => {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.throw(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
20
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/lib/stream-promise-flatten.ts
|
|
25
|
+
function streamPromiseFlatten(promise) {
|
|
26
|
+
return new ReadableStream({
|
|
27
|
+
start(controller) {
|
|
28
|
+
return __async(this, null, function* () {
|
|
29
|
+
try {
|
|
30
|
+
const stream = yield promise;
|
|
31
|
+
const reader = stream.getReader();
|
|
32
|
+
while (true) {
|
|
33
|
+
const { done, value } = yield reader.read();
|
|
34
|
+
if (done) {
|
|
35
|
+
controller.close();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
controller.enqueue(value);
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
controller.error(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.streamPromiseFlatten = streamPromiseFlatten;
|
|
49
|
+
//# sourceMappingURL=out.js.map
|
|
50
|
+
//# sourceMappingURL=stream-promise-flatten.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/stream-promise-flatten.ts"],"names":[],"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","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"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var clsx = require('clsx');
|
|
4
|
+
var nanoid$1 = require('nanoid');
|
|
5
|
+
var tailwindMerge = require('tailwind-merge');
|
|
6
|
+
|
|
7
|
+
var __async = (__this, __arguments, generator) => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
var fulfilled = (value) => {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var rejected = (value) => {
|
|
17
|
+
try {
|
|
18
|
+
step(generator.throw(value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
24
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
function cn(...inputs) {
|
|
28
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
29
|
+
}
|
|
30
|
+
var nanoid = nanoid$1.customAlphabet(
|
|
31
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
32
|
+
7
|
|
33
|
+
);
|
|
34
|
+
function fetcher(input, init) {
|
|
35
|
+
return __async(this, null, function* () {
|
|
36
|
+
const res = yield fetch(input, init);
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const json = yield res.json();
|
|
39
|
+
if (json.error) {
|
|
40
|
+
const error = new Error(json.error);
|
|
41
|
+
error.status = res.status;
|
|
42
|
+
throw error;
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error("An unexpected error occurred");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return res.json();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function formatDate(input) {
|
|
51
|
+
const date = new Date(input);
|
|
52
|
+
return date.toLocaleDateString("en-US", {
|
|
53
|
+
month: "long",
|
|
54
|
+
day: "numeric",
|
|
55
|
+
year: "numeric"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
59
|
+
function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
|
|
60
|
+
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
61
|
+
return a === b;
|
|
62
|
+
}
|
|
63
|
+
return naiveEqualityCheck(a, b);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.arraysAreEqual = arraysAreEqual;
|
|
67
|
+
exports.cn = cn;
|
|
68
|
+
exports.fetcher = fetcher;
|
|
69
|
+
exports.formatDate = formatDate;
|
|
70
|
+
exports.nanoid = nanoid;
|
|
71
|
+
exports.nullableCompatibleEqualityCheck = nullableCompatibleEqualityCheck;
|
|
72
|
+
//# sourceMappingURL=out.js.map
|
|
73
|
+
//# sourceMappingURL=utils.js.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,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","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils.test.ts"],"names":[],"mappings":";AAEA,SAAS,aAAa,MAAM;AAC1B,KAAG,oBAAoB,MAAM;AAC3B,WAAO,IAAI,EAAE,WAAW;AAAA,EAC1B,CAAC;AACH,CAAC","sourcesContent":["import * as utils from \"./utils\";\n\ndescribe(\"emptyTest\", () => {\n it(\"should be truthy\", () => {\n expect(true).toBeTruthy();\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|