@copilotkit/react-textarea 0.26.0-alpha.2 → 0.26.0-alpha.4
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 +189 -185
- package/CHANGELOG.md +22 -0
- package/dist/chunk-224UKA7C.mjs +33 -0
- package/dist/chunk-224UKA7C.mjs.map +1 -0
- package/dist/chunk-2C7O2EVM.mjs +27 -0
- package/dist/chunk-2C7O2EVM.mjs.map +1 -0
- package/dist/chunk-2QDCE7PD.mjs +29 -0
- package/dist/chunk-2QDCE7PD.mjs.map +1 -0
- package/dist/chunk-3PQ7GSFE.mjs +17 -0
- package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
- package/dist/chunk-47L4PLG4.mjs +45 -0
- package/dist/chunk-47L4PLG4.mjs.map +1 -0
- package/dist/chunk-4NHVQZ67.mjs +107 -0
- package/dist/chunk-4NHVQZ67.mjs.map +1 -0
- package/dist/chunk-5FO6ISW4.mjs +3 -0
- package/dist/chunk-5FO6ISW4.mjs.map +1 -0
- package/dist/chunk-5UNJXFUO.mjs +29 -0
- package/dist/chunk-5UNJXFUO.mjs.map +1 -0
- package/dist/chunk-72P3KOHZ.mjs +91 -0
- package/dist/chunk-72P3KOHZ.mjs.map +1 -0
- package/dist/chunk-7LSRNPNI.mjs +59 -0
- package/dist/chunk-7LSRNPNI.mjs.map +1 -0
- package/dist/chunk-7SUZ6CXM.mjs +47 -0
- package/dist/chunk-7SUZ6CXM.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +3 -0
- package/dist/chunk-DE5K76I2.mjs.map +1 -0
- package/dist/chunk-DRV2FOHZ.mjs +65 -0
- package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
- package/dist/chunk-ECR45NSD.mjs +101 -0
- package/dist/chunk-ECR45NSD.mjs.map +1 -0
- package/dist/chunk-ELEY7HWW.mjs +202 -0
- package/dist/chunk-ELEY7HWW.mjs.map +1 -0
- package/dist/chunk-EPBVNDKE.mjs +46 -0
- package/dist/chunk-EPBVNDKE.mjs.map +1 -0
- package/dist/chunk-FJNUPSQK.mjs +72 -0
- package/dist/chunk-FJNUPSQK.mjs.map +1 -0
- package/dist/chunk-FP2EKU3L.mjs +28 -0
- package/dist/chunk-FP2EKU3L.mjs.map +1 -0
- package/dist/chunk-FRIYJQCI.mjs +99 -0
- package/dist/chunk-FRIYJQCI.mjs.map +1 -0
- package/dist/chunk-GQN2HYFJ.mjs +22 -0
- package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +3 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +3 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JJLQVT7S.mjs +10 -0
- package/dist/chunk-JJLQVT7S.mjs.map +1 -0
- package/dist/chunk-K5LNB36H.mjs +80 -0
- package/dist/chunk-K5LNB36H.mjs.map +1 -0
- package/dist/chunk-KDVMG3XF.mjs +63 -0
- package/dist/chunk-KDVMG3XF.mjs.map +1 -0
- package/dist/chunk-KFQZHRPJ.mjs +19 -0
- package/dist/chunk-KFQZHRPJ.mjs.map +1 -0
- package/dist/chunk-KNBNKEXR.mjs +27 -0
- package/dist/chunk-KNBNKEXR.mjs.map +1 -0
- package/dist/chunk-KNQIEOFP.mjs +18 -0
- package/dist/chunk-KNQIEOFP.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +3 -0
- package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
- package/dist/chunk-LP2REBM5.mjs +217 -0
- package/dist/chunk-LP2REBM5.mjs.map +1 -0
- package/dist/chunk-M2DR4KVB.mjs +33 -0
- package/dist/chunk-M2DR4KVB.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +3 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-MTDBPK5D.mjs +53 -0
- package/dist/chunk-MTDBPK5D.mjs.map +1 -0
- package/dist/chunk-NRTYAQJE.mjs +46 -0
- package/dist/chunk-NRTYAQJE.mjs.map +1 -0
- package/dist/chunk-NTLVQENP.mjs +19 -0
- package/dist/chunk-NTLVQENP.mjs.map +1 -0
- package/dist/chunk-OHO4G6DR.mjs +19 -0
- package/dist/chunk-OHO4G6DR.mjs.map +1 -0
- package/dist/chunk-P4QVFRLY.mjs +103 -0
- package/dist/chunk-P4QVFRLY.mjs.map +1 -0
- package/dist/chunk-PTZVE6NC.mjs +94 -0
- package/dist/chunk-PTZVE6NC.mjs.map +1 -0
- package/dist/chunk-QDFAIRQF.mjs +45 -0
- package/dist/chunk-QDFAIRQF.mjs.map +1 -0
- package/dist/chunk-RBR32FWA.mjs +74 -0
- package/dist/chunk-RBR32FWA.mjs.map +1 -0
- package/dist/chunk-T6MTDQZ7.mjs +45 -0
- package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
- package/dist/chunk-VPEH6V7T.mjs +83 -0
- package/dist/chunk-VPEH6V7T.mjs.map +1 -0
- package/dist/chunk-WADHCMPK.mjs +3 -0
- package/dist/chunk-WADHCMPK.mjs.map +1 -0
- package/dist/chunk-WFTAAA7R.mjs +44 -0
- package/dist/chunk-WFTAAA7R.mjs.map +1 -0
- package/dist/chunk-WJHSY5T6.mjs +3 -0
- package/dist/chunk-WJHSY5T6.mjs.map +1 -0
- package/dist/chunk-WTASPE2W.mjs +105 -0
- package/dist/chunk-WTASPE2W.mjs.map +1 -0
- package/dist/chunk-XV7MLLXQ.mjs +18 -0
- package/dist/chunk-XV7MLLXQ.mjs.map +1 -0
- package/dist/chunk-Y473E2ZQ.mjs +112 -0
- package/dist/chunk-Y473E2ZQ.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +35 -1745
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +3 -51
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -49
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +47 -2202
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -17
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -137
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +18 -875
- 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 +12 -558
- 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 +13 -581
- 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 +5 -102
- 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 +14 -581
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.mjs +48 -2203
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +6 -211
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.mjs +4 -85
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/card.mjs +7 -53
- package/dist/components/ui/card.mjs.map +1 -1
- package/dist/components/ui/command.mjs +5 -244
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +4 -144
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +4 -60
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/components/ui/separator.mjs +8 -50
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/textarea.mjs +7 -48
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -158
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -148
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -147
- 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 +14 -193
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.mjs +50 -2206
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.mjs +3 -51
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +3 -43
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.mjs +3 -102
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +3 -17
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -20
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +3 -47
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +3 -71
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/lib/utils.test.mjs +1 -0
- package/dist/lib/utils.test.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +8 -265
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -81
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +10 -327
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -75
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -83
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +3 -64
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/autosuggestion-state.mjs +2 -0
- package/dist/types/base/autosuggestion-state.mjs.map +1 -1
- package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
- package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +3 -26
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
- package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
- package/dist/types/base/custom-editor.mjs +2 -0
- package/dist/types/base/custom-editor.mjs.map +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +4 -17
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.mjs +4 -26
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +2 -0
- package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
- package/dist/types/index.mjs +12 -328
- package/dist/types/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { withPartialHistory, defaultShouldSave } from './chunk-4NHVQZ67.mjs';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { createEditor, Element } from 'slate';
|
|
4
|
+
import { withReact } from 'slate-react';
|
|
5
|
+
|
|
6
|
+
var shouldSave = (op, prev) => {
|
|
7
|
+
const excludedNodeType = "suggestion";
|
|
8
|
+
if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return defaultShouldSave(op, prev);
|
|
27
|
+
};
|
|
28
|
+
function useCopilotTextareaEditor() {
|
|
29
|
+
const editor = useMemo(() => {
|
|
30
|
+
const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
|
|
31
|
+
const { isVoid } = editor2;
|
|
32
|
+
editor2.isVoid = (element) => {
|
|
33
|
+
switch (element.type) {
|
|
34
|
+
case "suggestion":
|
|
35
|
+
return true;
|
|
36
|
+
default:
|
|
37
|
+
return isVoid(element);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const { markableVoid } = editor2;
|
|
41
|
+
editor2.markableVoid = (element) => {
|
|
42
|
+
switch (element.type) {
|
|
43
|
+
case "suggestion":
|
|
44
|
+
return true;
|
|
45
|
+
default:
|
|
46
|
+
return markableVoid(element);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const { isInline } = editor2;
|
|
50
|
+
editor2.isInline = (element) => {
|
|
51
|
+
switch (element.type) {
|
|
52
|
+
case "suggestion":
|
|
53
|
+
return element.inline;
|
|
54
|
+
default:
|
|
55
|
+
return isInline(element);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return editor2;
|
|
59
|
+
}, []);
|
|
60
|
+
return editor;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { useCopilotTextareaEditor };
|
|
64
|
+
//# sourceMappingURL=out.js.map
|
|
65
|
+
//# sourceMappingURL=chunk-DRV2FOHZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx"],"names":["editor"],"mappings":";;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,cAAc,eAAe;AACtC,SAAS,iBAAiB;AAQ1B,IAAM,aAAkC,CAAC,IAAI,SAAS;AACpD,QAAM,mBAAmB;AAEzB,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,iBACZ,QAAQ,UAAU,GAAG,IAAI,KACzB,GAAG,KAAK,SAAS,kBACjB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,cACZ,UAAU,GAAG,iBACb,GAAG,cAAc,SAAS,kBAC1B;AACA,WAAO;AAAA,EACT;AAEA,MAAI,GAAG,QAAQ,cAAc,UAAU,GAAG,cAAc,GAAG,WAAW,SAAS,kBAAkB;AAC/F,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAEA,MACE,GAAG,SAAS,gBACZ,UAAU,GAAG,cACb,GAAG,WAAW,SAAS,kBACvB;AACA,WAAO;AAAA,EACT;AAGA,SAAO,kBAAkB,IAAI,IAAI;AACnC;AAEO,SAAS,2BAAyC;AACvD,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAMA,UAAS,mBAAmB,UAAU,aAAa,CAAC,GAAG,UAAU;AAEvE,UAAM,EAAE,OAAO,IAAIA;AACnB,IAAAA,QAAO,SAAS,CAAC,YAAY;AAC3B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,OAAO,OAAO;AAAA,MACzB;AAAA,IACF;AAEA,UAAM,EAAE,aAAa,IAAIA;AACzB,IAAAA,QAAO,eAAe,CAAC,YAAY;AACjC,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO,aAAa,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,EAAE,SAAS,IAAIA;AACrB,IAAAA,QAAO,WAAW,CAAC,YAAY;AAC7B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO,QAAQ;AAAA,QACjB;AACE,iBAAO,SAAS,OAAO;AAAA,MAC3B;AAAA,IACF;AAEA,WAAOA;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT","sourcesContent":["import { useMemo } from \"react\";\nimport { createEditor, Element } from \"slate\";\nimport { withReact } from \"slate-react\";\nimport {\n defaultShouldSave,\n ShouldSaveToHistory,\n withPartialHistory,\n} from \"../../lib/slatejs-edits/with-partial-history\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nconst shouldSave: ShouldSaveToHistory = (op, prev) => {\n const excludedNodeType = \"suggestion\";\n // Check if the operation involves the suggestion inline node type\n if (\n op.type === \"insert_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"remove_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"set_node\" &&\n \"type\" in op.newProperties &&\n op.newProperties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (op.type == \"set_node\" && \"type\" in op.properties && op.properties.type === excludedNodeType) {\n return false;\n }\n\n if (\n op.type === \"merge_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"split_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n // Otherwise, save the operation to history\n return defaultShouldSave(op, prev);\n};\n\nexport function useCopilotTextareaEditor(): CustomEditor {\n const editor = useMemo(() => {\n const editor = withPartialHistory(withReact(createEditor()), shouldSave);\n\n const { isVoid } = editor;\n editor.isVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return isVoid(element);\n }\n };\n\n const { markableVoid } = editor;\n editor.markableVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return markableVoid(element);\n }\n };\n\n const { isInline } = editor;\n editor.isInline = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return element.inline;\n default:\n return isInline(element);\n }\n };\n\n return editor;\n }, []);\n\n return editor;\n}\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Range, Editor, Text, Element, Path, Point } from 'slate';
|
|
2
|
+
|
|
3
|
+
// src/lib/get-text-around-cursor.ts
|
|
4
|
+
function getTextAroundCollapsedCursor(editor) {
|
|
5
|
+
const { selection } = editor;
|
|
6
|
+
if (!selection || !Range.isCollapsed(selection)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const cursorPoint = selection.anchor;
|
|
10
|
+
const beforeRange = {
|
|
11
|
+
anchor: Editor.start(editor, []),
|
|
12
|
+
focus: cursorPoint
|
|
13
|
+
};
|
|
14
|
+
const afterRange = {
|
|
15
|
+
anchor: cursorPoint,
|
|
16
|
+
focus: Editor.end(editor, [])
|
|
17
|
+
};
|
|
18
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
19
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
20
|
+
return {
|
|
21
|
+
cursorPoint,
|
|
22
|
+
textBeforeCursor: before,
|
|
23
|
+
textAfterCursor: after
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getTextAroundSelection(editor) {
|
|
27
|
+
const { selection } = editor;
|
|
28
|
+
if (!selection) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
32
|
+
const beforeRange = {
|
|
33
|
+
anchor: Editor.start(editor, []),
|
|
34
|
+
focus: wellOrderedSelection.anchor
|
|
35
|
+
};
|
|
36
|
+
const afterRange = {
|
|
37
|
+
anchor: wellOrderedSelection.focus,
|
|
38
|
+
focus: Editor.end(editor, [])
|
|
39
|
+
};
|
|
40
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
41
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
42
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
43
|
+
return {
|
|
44
|
+
selection: wellOrderedSelection,
|
|
45
|
+
textBeforeCursor: before,
|
|
46
|
+
selectedText,
|
|
47
|
+
textAfterCursor: after
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getFullEditorTextWithNewlines(editor) {
|
|
51
|
+
const fullDocumentRange = {
|
|
52
|
+
anchor: Editor.start(editor, []),
|
|
53
|
+
focus: Editor.end(editor, [])
|
|
54
|
+
};
|
|
55
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
56
|
+
}
|
|
57
|
+
function extractTextWithNewlines(editor, range) {
|
|
58
|
+
const voids = false;
|
|
59
|
+
const [start, end] = Range.edges(range);
|
|
60
|
+
let text = "";
|
|
61
|
+
let lastBlock = null;
|
|
62
|
+
for (const [node, path] of Editor.nodes(editor, {
|
|
63
|
+
at: range,
|
|
64
|
+
match: Text.isText,
|
|
65
|
+
voids
|
|
66
|
+
})) {
|
|
67
|
+
let t = node.text;
|
|
68
|
+
const [block] = Editor.above(editor, {
|
|
69
|
+
at: path,
|
|
70
|
+
match: (n) => Element.isElement(n) && n.type === "paragraph"
|
|
71
|
+
}) || [null];
|
|
72
|
+
if (lastBlock !== block && block) {
|
|
73
|
+
if (lastBlock) {
|
|
74
|
+
text += "\n";
|
|
75
|
+
}
|
|
76
|
+
lastBlock = block;
|
|
77
|
+
}
|
|
78
|
+
if (Path.equals(path, end.path)) {
|
|
79
|
+
t = t.slice(0, end.offset);
|
|
80
|
+
}
|
|
81
|
+
if (Path.equals(path, start.path)) {
|
|
82
|
+
t = t.slice(start.offset);
|
|
83
|
+
}
|
|
84
|
+
text += t;
|
|
85
|
+
}
|
|
86
|
+
return text;
|
|
87
|
+
}
|
|
88
|
+
function wellOrderedRange(range) {
|
|
89
|
+
const { anchor, focus } = range;
|
|
90
|
+
if (Point.isBefore(anchor, focus)) {
|
|
91
|
+
return range;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
anchor: focus,
|
|
95
|
+
focus: anchor
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { extractTextWithNewlines, getFullEditorTextWithNewlines, getTextAroundCollapsedCursor, getTextAroundSelection };
|
|
100
|
+
//# sourceMappingURL=out.js.map
|
|
101
|
+
//# sourceMappingURL=chunk-ECR45NSD.mjs.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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I,IAAI,KAAK;AAGb,UAAM,CAAC,KAAK,IAAI,OAAO,MAAM,QAAQ;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO,CAAC,MAAM,QAAQ,UAAU,CAAC,KAAK,EAAE,SAAS;AAAA,IACnD,CAAC,KAAK,CAAC,IAAI;AAGX,QAAI,cAAc,SAAS,OAAO;AAEhC,UAAI,WAAW;AACb,gBAAQ;AAAA,MACV;AACA,kBAAY;AAAA,IACd;AAEA,QAAI,KAAK,OAAO,MAAM,IAAI,IAAI,GAAG;AAC/B,UAAI,EAAE,MAAM,GAAG,IAAI,MAAM;AAAA,IAC3B;AAEA,QAAI,KAAK,OAAO,MAAM,MAAM,IAAI,GAAG;AACjC,UAAI,EAAE,MAAM,MAAM,MAAM;AAAA,IAC1B;AAEA,YAAQ;AAAA,EACV;AAEA,SAAO;AACT;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,202 @@
|
|
|
1
|
+
import { IncludedFilesPreview } from './chunk-EPBVNDKE.mjs';
|
|
2
|
+
import { Label } from './chunk-KFQZHRPJ.mjs';
|
|
3
|
+
import { SourceSearchBox } from './chunk-FJNUPSQK.mjs';
|
|
4
|
+
import { Button } from './chunk-WFTAAA7R.mjs';
|
|
5
|
+
import { use_autosize_textarea_default } from './chunk-3PQ7GSFE.mjs';
|
|
6
|
+
import { streamPromiseFlatten } from './chunk-2QDCE7PD.mjs';
|
|
7
|
+
import { __async } from './chunk-MRXNTQOX.mjs';
|
|
8
|
+
import { useContext, useState, useRef, useEffect, useCallback } from 'react';
|
|
9
|
+
import { CopilotContext } from '@copilotkit/react-core';
|
|
10
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
var HoveringInsertionPromptBoxCore = ({
|
|
13
|
+
performInsertion,
|
|
14
|
+
state,
|
|
15
|
+
insertionOrEditingFunction,
|
|
16
|
+
contextCategories
|
|
17
|
+
}) => {
|
|
18
|
+
const { getDocumentsContext } = useContext(CopilotContext);
|
|
19
|
+
const [editSuggestion, setEditSuggestion] = useState("");
|
|
20
|
+
const [suggestionIsLoading, setSuggestionIsLoading] = useState(false);
|
|
21
|
+
const [adjustmentPrompt, setAdjustmentPrompt] = useState("");
|
|
22
|
+
const [generatingSuggestion, setGeneratingSuggestion] = useState(
|
|
23
|
+
null
|
|
24
|
+
);
|
|
25
|
+
const adjustmentTextAreaRef = useRef(null);
|
|
26
|
+
const suggestionTextAreaRef = useRef(null);
|
|
27
|
+
const [filePointers, setFilePointers] = useState([]);
|
|
28
|
+
const [suggestedFiles, setSuggestedFiles] = useState([]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setSuggestedFiles(getDocumentsContext(contextCategories));
|
|
31
|
+
}, [contextCategories, getDocumentsContext]);
|
|
32
|
+
use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
|
|
33
|
+
use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!generatingSuggestion) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (generatingSuggestion.locked) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
setEditSuggestion("");
|
|
46
|
+
const reader = generatingSuggestion.getReader();
|
|
47
|
+
const read = () => __async(void 0, null, function* () {
|
|
48
|
+
setSuggestionIsLoading(true);
|
|
49
|
+
while (true) {
|
|
50
|
+
const { done, value } = yield reader.read();
|
|
51
|
+
if (done) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
setEditSuggestion((prev) => {
|
|
55
|
+
const newSuggestion = prev + value;
|
|
56
|
+
if (suggestionTextAreaRef.current) {
|
|
57
|
+
suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
|
|
58
|
+
}
|
|
59
|
+
return newSuggestion;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
setSuggestionIsLoading(false);
|
|
63
|
+
});
|
|
64
|
+
read();
|
|
65
|
+
return () => {
|
|
66
|
+
const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
|
|
67
|
+
try {
|
|
68
|
+
yield reader.closed;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
reader.releaseLock();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
releaseLockIfNotClosed();
|
|
74
|
+
};
|
|
75
|
+
}, [generatingSuggestion]);
|
|
76
|
+
const beginGeneratingAdjustment = useCallback(() => __async(void 0, null, function* () {
|
|
77
|
+
if (!adjustmentPrompt.trim()) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let modificationState = state.editorState;
|
|
81
|
+
if (editSuggestion !== "") {
|
|
82
|
+
modificationState.selectedText = editSuggestion;
|
|
83
|
+
}
|
|
84
|
+
const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
|
|
85
|
+
modificationState,
|
|
86
|
+
adjustmentPrompt,
|
|
87
|
+
filePointers,
|
|
88
|
+
new AbortController().signal
|
|
89
|
+
);
|
|
90
|
+
const adjustmentSuggestionTextStream = streamPromiseFlatten(
|
|
91
|
+
adjustmentSuggestionTextStreamPromise
|
|
92
|
+
);
|
|
93
|
+
setGeneratingSuggestion(adjustmentSuggestionTextStream);
|
|
94
|
+
}), [
|
|
95
|
+
adjustmentPrompt,
|
|
96
|
+
editSuggestion,
|
|
97
|
+
state.editorState,
|
|
98
|
+
insertionOrEditingFunction,
|
|
99
|
+
filePointers
|
|
100
|
+
]);
|
|
101
|
+
const isLoading = suggestionIsLoading;
|
|
102
|
+
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
103
|
+
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
104
|
+
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
105
|
+
const AdjustmentPromptComponent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
106
|
+
/* @__PURE__ */ jsx(Label, { className: "", children: adjustmentLabel }),
|
|
107
|
+
/* @__PURE__ */ jsxs("div", { className: "relative w-full flex items-center", children: [
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
"textarea",
|
|
110
|
+
{
|
|
111
|
+
disabled: suggestionIsLoading,
|
|
112
|
+
ref: adjustmentTextAreaRef,
|
|
113
|
+
value: adjustmentPrompt,
|
|
114
|
+
onChange: (e) => setAdjustmentPrompt(e.target.value),
|
|
115
|
+
onKeyDown: (e) => {
|
|
116
|
+
if (e.key === "Enter" && e.shiftKey) {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
setAdjustmentPrompt(adjustmentPrompt + "\n");
|
|
119
|
+
} else if (e.key === "Enter") {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
beginGeneratingAdjustment();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
placeholder,
|
|
125
|
+
style: { minHeight: "3rem" },
|
|
126
|
+
className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
|
|
127
|
+
rows: 1
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
"button",
|
|
132
|
+
{
|
|
133
|
+
onClick: beginGeneratingAdjustment,
|
|
134
|
+
className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
|
|
135
|
+
children: /* @__PURE__ */ jsx("i", { className: "material-icons", children: "arrow_forward" })
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
] })
|
|
139
|
+
] });
|
|
140
|
+
const SuggestionComponent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
141
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between items-end w-full", children: [
|
|
142
|
+
/* @__PURE__ */ jsx(Label, { className: "mt-4", children: "Suggested:" }),
|
|
143
|
+
/* @__PURE__ */ jsx("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ jsx("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ jsx(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
|
|
147
|
+
role: "status",
|
|
148
|
+
children: /* @__PURE__ */ jsx("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." })
|
|
149
|
+
}
|
|
150
|
+
) }) })
|
|
151
|
+
] }),
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
"textarea",
|
|
154
|
+
{
|
|
155
|
+
ref: suggestionTextAreaRef,
|
|
156
|
+
value: editSuggestion,
|
|
157
|
+
disabled: suggestionIsLoading,
|
|
158
|
+
onChange: (e) => setEditSuggestion(e.target.value),
|
|
159
|
+
className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
|
|
160
|
+
style: { overflow: "auto", maxHeight: "10em" }
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] });
|
|
164
|
+
const SubmitComponent = /* @__PURE__ */ jsx("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ jsxs(
|
|
165
|
+
Button,
|
|
166
|
+
{
|
|
167
|
+
className: " bg-green-700 text-white",
|
|
168
|
+
onClick: () => {
|
|
169
|
+
performInsertion(editSuggestion);
|
|
170
|
+
},
|
|
171
|
+
children: [
|
|
172
|
+
"Insert ",
|
|
173
|
+
/* @__PURE__ */ jsx("i", { className: "material-icons", children: "check" })
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
) });
|
|
177
|
+
const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
|
|
178
|
+
const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
|
|
179
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
|
|
180
|
+
AdjustmentPromptComponent,
|
|
181
|
+
filePointers.length > 0 && /* @__PURE__ */ jsx(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
|
|
182
|
+
sourceSearchWord !== void 0 && /* @__PURE__ */ jsx(
|
|
183
|
+
SourceSearchBox,
|
|
184
|
+
{
|
|
185
|
+
searchTerm: sourceSearchWord,
|
|
186
|
+
suggestedFiles,
|
|
187
|
+
onSelectedFile: (filePointer) => {
|
|
188
|
+
var _a;
|
|
189
|
+
setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), ""));
|
|
190
|
+
setFilePointers((prev) => [...prev, filePointer]);
|
|
191
|
+
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
generatingSuggestion ? SuggestionComponent : null,
|
|
196
|
+
generatingSuggestion ? SubmitComponent : null
|
|
197
|
+
] });
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export { HoveringInsertionPromptBoxCore };
|
|
201
|
+
//# sourceMappingURL=out.js.map
|
|
202
|
+
//# sourceMappingURL=chunk-ELEY7HWW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAgB,aAAa,YAAY,WAAW,QAAQ,gBAAgB;AAG5E,SAAS,sBAAsB;AAqJ3B,mBACE,KACA,YAFF;AAvIG,IAAM,iCAAgF,CAAC;AAAA,EAC5F;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,oBAAoB,IAAI,WAAW,cAAc;AAEzD,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAiB,EAAE;AAC/D,QAAM,CAAC,qBAAqB,sBAAsB,IAAI,SAAkB,KAAK;AAE7E,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAiB,EAAE;AAEnE,QAAM,CAAC,sBAAsB,uBAAuB,IAAI;AAAA,IACtD;AAAA,EACF;AAEA,QAAM,wBAAwB,OAA4B,IAAI;AAC9D,QAAM,wBAAwB,OAA4B,IAAI;AAE9D,QAAM,CAAC,cAAc,eAAe,IAAI,SAA4B,CA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AAuB,kBAAkB;AAAA,KAC5C;AAEJ","sourcesContent":["import useAutosizeTextArea from \"../../../hooks/misc/use-autosize-textarea\";\nimport { MinimalChatGPTMessage } from \"../../../types\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../../types/base/autosuggestions-bare-function\";\nimport { SourceSearchBox } from \"../../source-search-box/source-search-box\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { Button } from \"../../ui/button\";\nimport { Label } from \"../../ui/label\";\nimport React, { useCallback, useContext, useEffect, useRef, useState } from \"react\";\n\nimport { streamPromiseFlatten } from \"../../../lib/stream-promise-flatten\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { IncludedFilesPreview } from \"./included-files-preview\";\n\nexport type SuggestionState = {\n editorState: EditingEditorState;\n};\n\nexport interface HoveringInsertionPromptBoxCoreProps {\n state: SuggestionState;\n performInsertion: (insertedText: string) => void;\n insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBoxCore: React.FC<HoveringInsertionPromptBoxCoreProps> = ({\n performInsertion,\n state,\n insertionOrEditingFunction,\n contextCategories,\n}) => {\n const { getDocumentsContext } = useContext(CopilotContext);\n\n const [editSuggestion, setEditSuggestion] = useState<string>(\"\");\n const [suggestionIsLoading, setSuggestionIsLoading] = useState<boolean>(false);\n\n const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>(\"\");\n\n const [generatingSuggestion, setGeneratingSuggestion] = useState<ReadableStream<string> | null>(\n null,\n );\n\n const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);\n const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [filePointers, setFilePointers] = useState<DocumentPointer[]>([]);\n\n const [suggestedFiles, setSuggestedFiles] = useState<DocumentPointer[]>([]);\n useEffect(() => {\n setSuggestedFiles(getDocumentsContext(contextCategories));\n }, [contextCategories, getDocumentsContext]);\n\n useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || \"\");\n useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || \"\");\n\n // initially focus on the adjustment prompt text area\n useEffect(() => {\n adjustmentTextAreaRef.current?.focus();\n }, []);\n\n // continuously read the generating suggestion stream and update the edit suggestion\n useEffect(() => {\n // if no generating suggestion, do nothing\n if (!generatingSuggestion) {\n return;\n }\n\n // Check if the stream is already locked (i.e. already reading from it)\n if (generatingSuggestion.locked) {\n return;\n }\n\n // reset the edit suggestion\n setEditSuggestion(\"\");\n\n // read the generating suggestion stream and continuously update the edit suggestion\n const reader = generatingSuggestion.getReader();\n const read = async () => {\n setSuggestionIsLoading(true);\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n setEditSuggestion((prev) => {\n const newSuggestion = prev + value;\n\n // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.\n if (suggestionTextAreaRef.current) {\n suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;\n }\n return newSuggestion;\n });\n }\n\n setSuggestionIsLoading(false);\n };\n read();\n\n return () => {\n // release the lock if the reader is not closed on unmount\n const releaseLockIfNotClosed = async () => {\n try {\n await reader.closed;\n } catch {\n reader.releaseLock();\n }\n };\n\n releaseLockIfNotClosed();\n };\n }, [generatingSuggestion]);\n\n // generate an adjustment to the completed text, based on the adjustment prompt\n const beginGeneratingAdjustment = useCallback(async () => {\n // don't generate text if the prompt is empty\n if (!adjustmentPrompt.trim()) {\n return;\n }\n\n // editor state includes the text being edited, and the text before/after the selection\n // if the current edit suggestion is not empty, then use *it* as the \"selected text\" - instead of the editor state's selected text\n let modificationState = state.editorState;\n if (editSuggestion !== \"\") {\n modificationState.selectedText = editSuggestion;\n }\n\n // generate the adjustment suggestion\n const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(\n modificationState,\n adjustmentPrompt,\n filePointers,\n new AbortController().signal,\n );\n const adjustmentSuggestionTextStream = streamPromiseFlatten(\n adjustmentSuggestionTextStreamPromise,\n );\n\n setGeneratingSuggestion(adjustmentSuggestionTextStream);\n }, [\n adjustmentPrompt,\n editSuggestion,\n state.editorState,\n insertionOrEditingFunction,\n filePointers,\n ]);\n\n const isLoading = suggestionIsLoading;\n\n const textToEdit = editSuggestion || state.editorState.selectedText;\n const adjustmentLabel =\n textToEdit === \"\"\n ? \"Describe the text you want to insert\"\n : \"Describe adjustments to the suggested text\";\n const placeholder =\n textToEdit === \"\"\n ? \"e.g. 'summarize the client's top 3 pain-points from @CallTranscript'\"\n : \"e.g. 'make it more formal', 'be more specific', ...\";\n\n const AdjustmentPromptComponent = (\n <>\n <Label className=\"\">{adjustmentLabel}</Label>\n <div className=\"relative w-full flex items-center\">\n <textarea\n disabled={suggestionIsLoading}\n ref={adjustmentTextAreaRef}\n value={adjustmentPrompt}\n onChange={(e) => setAdjustmentPrompt(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && e.shiftKey) {\n e.preventDefault();\n setAdjustmentPrompt(adjustmentPrompt + \"\\n\");\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n beginGeneratingAdjustment();\n }\n }}\n placeholder={placeholder}\n style={{ minHeight: \"3rem\" }}\n className=\"w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]\"\n rows={1}\n />\n <button\n onClick={beginGeneratingAdjustment}\n className=\"absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center\"\n >\n <i className=\"material-icons\">arrow_forward</i>\n </button>\n </div>\n </>\n );\n\n const SuggestionComponent = (\n <>\n <div className=\"flex justify-between items-end w-full\">\n <Label className=\"mt-4\">Suggested:</Label>\n <div className=\"ml-auto\">\n {isLoading && (\n <div className=\"flex justify-center items-center\">\n <div\n className=\"inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]\"\n role=\"status\"\n >\n <span className=\"!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]\">\n Loading...\n </span>\n </div>\n </div>\n )}\n </div>\n </div>\n <textarea\n ref={suggestionTextAreaRef}\n value={editSuggestion}\n disabled={suggestionIsLoading}\n onChange={(e) => setEditSuggestion(e.target.value)}\n className=\"w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50\"\n style={{ overflow: \"auto\", maxHeight: \"10em\" }}\n />\n </>\n );\n\n const SubmitComponent = (\n <div className=\"flex w-full gap-4 justify-start\">\n <Button\n className=\" bg-green-700 text-white\"\n onClick={() => {\n performInsertion(editSuggestion);\n }}\n >\n Insert <i className=\"material-icons\">check</i>\n </Button>\n </div>\n );\n\n // show source search if the last word in the adjustment prompt BEGINS with an @\n const sourceSearchCandidate = adjustmentPrompt.split(\" \").pop();\n // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined\n const sourceSearchWord = sourceSearchCandidate?.startsWith(\"@\")\n ? sourceSearchCandidate.slice(1)\n : undefined;\n\n return (\n <div className=\"w-full flex flex-col items-start relative gap-2\">\n {AdjustmentPromptComponent}\n {filePointers.length > 0 && (\n <IncludedFilesPreview includedFiles={filePointers} setIncludedFiles={setFilePointers} />\n )}\n {sourceSearchWord !== undefined && (\n <SourceSearchBox\n searchTerm={sourceSearchWord}\n suggestedFiles={suggestedFiles}\n onSelectedFile={(filePointer) => {\n setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), \"\"));\n setFilePointers((prev) => [...prev, filePointer]);\n\n // focus back on the adjustment prompt, and move the cursor to the end\n adjustmentTextAreaRef.current?.focus();\n }}\n />\n )}\n {generatingSuggestion ? SuggestionComponent : null}\n {generatingSuggestion ? SubmitComponent : null}\n </div>\n );\n};\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Label } from './chunk-KFQZHRPJ.mjs';
|
|
2
|
+
import Chip from '@mui/material/Chip/Chip.js';
|
|
3
|
+
import Avatar from '@mui/material/Avatar/Avatar.js';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var IncludedFilesPreview = ({
|
|
7
|
+
includedFiles,
|
|
8
|
+
setIncludedFiles
|
|
9
|
+
}) => {
|
|
10
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 mt-2", children: [
|
|
11
|
+
/* @__PURE__ */ jsx(Label, { className: "", children: "Included context:" }),
|
|
12
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
FileChipPreview,
|
|
15
|
+
{
|
|
16
|
+
filePointer,
|
|
17
|
+
onDelete: () => {
|
|
18
|
+
setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
`file-${filePointer.sourceApplication}.${filePointer.name}`
|
|
22
|
+
);
|
|
23
|
+
}) })
|
|
24
|
+
] });
|
|
25
|
+
};
|
|
26
|
+
var FileChipPreview = ({ filePointer, onDelete }) => {
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
Chip,
|
|
29
|
+
{
|
|
30
|
+
label: filePointer.name,
|
|
31
|
+
onDelete,
|
|
32
|
+
avatar: /* @__PURE__ */ jsx(
|
|
33
|
+
Avatar,
|
|
34
|
+
{
|
|
35
|
+
src: filePointer.iconImageUri,
|
|
36
|
+
alt: filePointer.sourceApplication,
|
|
37
|
+
sx: { backgroundColor: "transparent" }
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { FileChipPreview, IncludedFilesPreview };
|
|
45
|
+
//# sourceMappingURL=out.js.map
|
|
46
|
+
//# sourceMappingURL=chunk-EPBVNDKE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx"],"names":[],"mappings":";;;;;AAGA,OAAO,UAAU;AACjB,OAAO,YAAY;AAYf,SACE,KADF;AALG,IAAM,uBAA4D,CAAC;AAAA,EACxE;AAAA,EACA;AACF,MAAM;AACJ,SACE,qBAAC,SAAI,WAAU,4BACb;AAAA,wBAAC,SAAM,WAAU,IAAG,+BAAiB;AAAA,IACrC,oBAAC,SAAI,WAAU,wBACZ,wBAAc,IAAI,CAAC,aAAa,UAAU;AACzC,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA,UAAU,MAAM;AACd,6BAAiB,CAAC,SAAS,KAAK,OAAO,CAAC,OAAO,OAAO,WAAW,CAAC;AAAA,UACpE;AAAA;AAAA,QAJK,QAAQ,YAAY,qBAAqB,YAAY;AAAA,MAK5D;AAAA,IAEJ,CAAC,GACH;AAAA,KACF;AAEJ;AAOO,IAAM,kBAAiD,CAAC,EAAE,aAAa,SAAS,MAAM;AAC3F,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,YAAY;AAAA,MACnB;AAAA,MACA,QACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAK,YAAY;AAAA,UACjB,KAAK,YAAY;AAAA,UACjB,IAAI,EAAE,iBAAiB,cAAc;AAAA;AAAA,MACtC;AAAA;AAAA,EAEL;AAEJ","sourcesContent":["import { DocumentPointer } from \"@copilotkit/react-core\";\nimport { Label } from \"../../ui/label\";\nimport React from \"react\";\nimport Chip from \"@mui/material/Chip/Chip.js\";\nimport Avatar from \"@mui/material/Avatar/Avatar.js\";\n\nexport interface IncludedFilesPreviewProps {\n includedFiles: DocumentPointer[];\n setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;\n}\n\nexport const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({\n includedFiles,\n setIncludedFiles,\n}) => {\n return (\n <div className=\"flex flex-col gap-2 mt-2\">\n <Label className=\"\">Included context:</Label>\n <div className=\"flex flex-wrap gap-2\">\n {includedFiles.map((filePointer, index) => {\n return (\n <FileChipPreview\n key={`file-${filePointer.sourceApplication}.${filePointer.name}`}\n filePointer={filePointer}\n onDelete={() => {\n setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));\n }}\n />\n );\n })}\n </div>\n </div>\n );\n};\n\nexport interface FileChipPreviewProp {\n filePointer: DocumentPointer;\n onDelete: () => void;\n}\n\nexport const FileChipPreview: React.FC<FileChipPreviewProp> = ({ filePointer, onDelete }) => {\n return (\n <Chip\n label={filePointer.name}\n onDelete={onDelete}\n avatar={\n <Avatar\n src={filePointer.iconImageUri}\n alt={filePointer.sourceApplication}\n sx={{ backgroundColor: \"transparent\" }}\n ></Avatar>\n }\n />\n );\n};\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator } from './chunk-WTASPE2W.mjs';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
function SourceSearchBox(props) {
|
|
6
|
+
const [selectedValue, setSelectedValue] = useState("");
|
|
7
|
+
return /* @__PURE__ */ jsxs(
|
|
8
|
+
Command,
|
|
9
|
+
{
|
|
10
|
+
className: "rounded-lg border shadow-md",
|
|
11
|
+
value: selectedValue,
|
|
12
|
+
onValueChange: (value) => {
|
|
13
|
+
setSelectedValue(value);
|
|
14
|
+
},
|
|
15
|
+
filter: (value, search) => {
|
|
16
|
+
if (props.searchTerm === "")
|
|
17
|
+
return 1;
|
|
18
|
+
if (value.startsWith(props.searchTerm))
|
|
19
|
+
return 1;
|
|
20
|
+
return 0;
|
|
21
|
+
},
|
|
22
|
+
children: [
|
|
23
|
+
/* @__PURE__ */ jsx(
|
|
24
|
+
CommandInput,
|
|
25
|
+
{
|
|
26
|
+
value: props.searchTerm,
|
|
27
|
+
className: "rounded-t-lg hidden",
|
|
28
|
+
placeholder: "Search for a command..."
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
/* @__PURE__ */ jsxs(CommandList, { children: [
|
|
32
|
+
/* @__PURE__ */ jsx(CommandEmpty, { children: "No results found." }),
|
|
33
|
+
/* @__PURE__ */ jsx(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
CommandItem,
|
|
36
|
+
{
|
|
37
|
+
value: filePointer.name,
|
|
38
|
+
onSelect: (value) => {
|
|
39
|
+
props.onSelectedFile(filePointer);
|
|
40
|
+
},
|
|
41
|
+
children: /* @__PURE__ */ jsxs("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
|
|
42
|
+
/* @__PURE__ */ jsx(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ jsx(
|
|
43
|
+
"img",
|
|
44
|
+
{
|
|
45
|
+
src: filePointer.iconImageUri,
|
|
46
|
+
alt: filePointer.sourceApplication,
|
|
47
|
+
className: "w-full h-full"
|
|
48
|
+
}
|
|
49
|
+
) }),
|
|
50
|
+
filePointer.name
|
|
51
|
+
] })
|
|
52
|
+
},
|
|
53
|
+
`word-${filePointer.sourceApplication}.${filePointer.name}`
|
|
54
|
+
);
|
|
55
|
+
}) }),
|
|
56
|
+
/* @__PURE__ */ jsx(CommandSeparator, {})
|
|
57
|
+
] })
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function Logo({
|
|
63
|
+
children,
|
|
64
|
+
width,
|
|
65
|
+
height
|
|
66
|
+
}) {
|
|
67
|
+
return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center", style: { width, height }, children });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { Logo, SourceSearchBox };
|
|
71
|
+
//# sourceMappingURL=out.js.map
|
|
72
|
+
//# sourceMappingURL=chunk-FJNUPSQK.mjs.map
|
|
@@ -0,0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,SAAS,KAAK;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SACE,oBAAC,SAAI,WAAU,oCAAmC,OAAO,EAAE,OAAc,OAAe,GACrF,UACH;AAEJ","sourcesContent":["import { useState } from \"react\";\nimport {\n Command,\n CommandDialog,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n CommandSeparator,\n CommandShortcut,\n} from \"../ui/command\";\n\nimport { Calculator, Calendar, CreditCard, Settings, Smile, User } from \"lucide-react\";\n\nimport { DocumentPointer } from \"@copilotkit/react-core\";\n\nexport interface SourceSearchBoxProps {\n searchTerm: string;\n suggestedFiles: DocumentPointer[];\n onSelectedFile: (filePointer: DocumentPointer) => void;\n}\n\nexport function SourceSearchBox(props: SourceSearchBoxProps) {\n const [selectedValue, setSelectedValue] = useState<string>(\"\");\n\n return (\n <Command\n className=\"rounded-lg border shadow-md\"\n value={selectedValue}\n onValueChange={(value) => {\n setSelectedValue(value);\n }}\n filter={(value, search) => {\n // if the search term is empty, show all commands\n if (props.searchTerm === \"\") return 1;\n\n // if the search term is a prefix of the command, show it\n if (value.startsWith(props.searchTerm)) return 1;\n\n // otherwise, don't show it\n return 0;\n }}\n >\n <CommandInput\n value={props.searchTerm}\n className=\"rounded-t-lg hidden\"\n placeholder=\"Search for a command...\"\n />\n <CommandList>\n <CommandEmpty>No results found.</CommandEmpty>\n\n <CommandGroup heading=\"Available resources\">\n {props.suggestedFiles.map((filePointer) => {\n return (\n <CommandItem\n key={`word-${filePointer.sourceApplication}.${filePointer.name}`}\n value={filePointer.name}\n onSelect={(value) => {\n props.onSelectedFile(filePointer);\n }}\n >\n <div className=\" px-3 flex flex-row gap-1 items-center\">\n <Logo width=\"20px\" height=\"20px\">\n <img\n src={filePointer.iconImageUri}\n alt={filePointer.sourceApplication}\n className=\"w-full h-full\"\n />\n </Logo>\n {filePointer.name}\n </div>\n </CommandItem>\n );\n })}\n </CommandGroup>\n\n {/* <CommandGroup heading=\"Suggestions\">\n <CommandItem\n onSelect={(value) => {\n console.log(value);\n console.log(value);\n }}\n >\n <Calendar className=\"mr-2 h-4 w-4\" />\n <span>Calendar</span>\n </CommandItem>\n <CommandItem>\n <Smile className=\"mr-2 h-4 w-4\" />\n <span>Search Emoji</span>\n </CommandItem>\n <CommandItem>\n <Calculator className=\"mr-2 h-4 w-4\" />\n <span>Calculator</span>\n </CommandItem>\n </CommandGroup> */}\n <CommandSeparator />\n </CommandList>\n </Command>\n );\n}\n\nexport function Logo({\n children,\n width,\n height,\n}: {\n children: React.ReactNode;\n width: string;\n height: string;\n}) {\n return (\n <div className=\"flex items-center justify-center\" style={{ width: width, height: height }}>\n {children}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defaultCopilotContextCategories } from '@copilotkit/react-core';
|
|
2
|
+
|
|
3
|
+
// src/types/base/base-autosuggestions-config.tsx
|
|
4
|
+
var defaultShouldToggleHoveringEditorOnKeyPress = (event) => {
|
|
5
|
+
if (event.key === "k" && event.metaKey) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
|
|
11
|
+
if (event.key === "Tab") {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
var defaultBaseAutosuggestionsConfig = {
|
|
17
|
+
debounceTime: 250,
|
|
18
|
+
contextCategories: defaultCopilotContextCategories,
|
|
19
|
+
disableWhenEmpty: true,
|
|
20
|
+
disabled: false,
|
|
21
|
+
temporarilyDisableWhenMovingCursorWithoutChangingText: true,
|
|
22
|
+
shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
|
|
23
|
+
shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { defaultBaseAutosuggestionsConfig };
|
|
27
|
+
//# sourceMappingURL=out.js.map
|
|
28
|
+
//# sourceMappingURL=chunk-FP2EKU3L.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/base/base-autosuggestions-config.tsx"],"names":[],"mappings":";AACA,SAAS,uCAAuC;AAyDhD,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO,MAAM,SAAS;AACtC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAcO,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AAAA,EACvD,sCAAsC;AAAA,EACtC,sCAAsC;AACxC","sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === \"k\" && event.metaKey) {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n};\n"]}
|