@copilotkit/react-textarea 0.26.0-alpha.3 → 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.
Files changed (223) hide show
  1. package/.turbo/turbo-build.log +189 -185
  2. package/CHANGELOG.md +11 -0
  3. package/dist/chunk-224UKA7C.mjs +33 -0
  4. package/dist/chunk-224UKA7C.mjs.map +1 -0
  5. package/dist/chunk-2C7O2EVM.mjs +27 -0
  6. package/dist/chunk-2C7O2EVM.mjs.map +1 -0
  7. package/dist/chunk-2QDCE7PD.mjs +29 -0
  8. package/dist/chunk-2QDCE7PD.mjs.map +1 -0
  9. package/dist/chunk-3PQ7GSFE.mjs +17 -0
  10. package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
  11. package/dist/chunk-47L4PLG4.mjs +45 -0
  12. package/dist/chunk-47L4PLG4.mjs.map +1 -0
  13. package/dist/chunk-4NHVQZ67.mjs +107 -0
  14. package/dist/chunk-4NHVQZ67.mjs.map +1 -0
  15. package/dist/chunk-5FO6ISW4.mjs +3 -0
  16. package/dist/chunk-5FO6ISW4.mjs.map +1 -0
  17. package/dist/chunk-5UNJXFUO.mjs +29 -0
  18. package/dist/chunk-5UNJXFUO.mjs.map +1 -0
  19. package/dist/chunk-72P3KOHZ.mjs +91 -0
  20. package/dist/chunk-72P3KOHZ.mjs.map +1 -0
  21. package/dist/chunk-7LSRNPNI.mjs +59 -0
  22. package/dist/chunk-7LSRNPNI.mjs.map +1 -0
  23. package/dist/chunk-7SUZ6CXM.mjs +47 -0
  24. package/dist/chunk-7SUZ6CXM.mjs.map +1 -0
  25. package/dist/chunk-DE5K76I2.mjs +3 -0
  26. package/dist/chunk-DE5K76I2.mjs.map +1 -0
  27. package/dist/chunk-DRV2FOHZ.mjs +65 -0
  28. package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
  29. package/dist/chunk-ECR45NSD.mjs +101 -0
  30. package/dist/chunk-ECR45NSD.mjs.map +1 -0
  31. package/dist/chunk-ELEY7HWW.mjs +202 -0
  32. package/dist/chunk-ELEY7HWW.mjs.map +1 -0
  33. package/dist/chunk-EPBVNDKE.mjs +46 -0
  34. package/dist/chunk-EPBVNDKE.mjs.map +1 -0
  35. package/dist/chunk-FJNUPSQK.mjs +72 -0
  36. package/dist/chunk-FJNUPSQK.mjs.map +1 -0
  37. package/dist/chunk-FP2EKU3L.mjs +28 -0
  38. package/dist/chunk-FP2EKU3L.mjs.map +1 -0
  39. package/dist/chunk-FRIYJQCI.mjs +99 -0
  40. package/dist/chunk-FRIYJQCI.mjs.map +1 -0
  41. package/dist/chunk-GQN2HYFJ.mjs +22 -0
  42. package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
  43. package/dist/chunk-H4VKQGVU.mjs +3 -0
  44. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  45. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  46. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  47. package/dist/chunk-JJLQVT7S.mjs +10 -0
  48. package/dist/chunk-JJLQVT7S.mjs.map +1 -0
  49. package/dist/chunk-K5LNB36H.mjs +80 -0
  50. package/dist/chunk-K5LNB36H.mjs.map +1 -0
  51. package/dist/chunk-KDVMG3XF.mjs +63 -0
  52. package/dist/chunk-KDVMG3XF.mjs.map +1 -0
  53. package/dist/chunk-KFQZHRPJ.mjs +19 -0
  54. package/dist/chunk-KFQZHRPJ.mjs.map +1 -0
  55. package/dist/chunk-KNBNKEXR.mjs +27 -0
  56. package/dist/chunk-KNBNKEXR.mjs.map +1 -0
  57. package/dist/chunk-KNQIEOFP.mjs +18 -0
  58. package/dist/chunk-KNQIEOFP.mjs.map +1 -0
  59. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  60. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  61. package/dist/chunk-LP2REBM5.mjs +217 -0
  62. package/dist/chunk-LP2REBM5.mjs.map +1 -0
  63. package/dist/chunk-M2DR4KVB.mjs +33 -0
  64. package/dist/chunk-M2DR4KVB.mjs.map +1 -0
  65. package/dist/chunk-MMVDU6DF.mjs +3 -0
  66. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  67. package/dist/chunk-MRXNTQOX.mjs +55 -0
  68. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  69. package/dist/chunk-MTDBPK5D.mjs +53 -0
  70. package/dist/chunk-MTDBPK5D.mjs.map +1 -0
  71. package/dist/chunk-NRTYAQJE.mjs +46 -0
  72. package/dist/chunk-NRTYAQJE.mjs.map +1 -0
  73. package/dist/chunk-NTLVQENP.mjs +19 -0
  74. package/dist/chunk-NTLVQENP.mjs.map +1 -0
  75. package/dist/chunk-OHO4G6DR.mjs +19 -0
  76. package/dist/chunk-OHO4G6DR.mjs.map +1 -0
  77. package/dist/chunk-P4QVFRLY.mjs +103 -0
  78. package/dist/chunk-P4QVFRLY.mjs.map +1 -0
  79. package/dist/chunk-PTZVE6NC.mjs +94 -0
  80. package/dist/chunk-PTZVE6NC.mjs.map +1 -0
  81. package/dist/chunk-QDFAIRQF.mjs +45 -0
  82. package/dist/chunk-QDFAIRQF.mjs.map +1 -0
  83. package/dist/chunk-RBR32FWA.mjs +74 -0
  84. package/dist/chunk-RBR32FWA.mjs.map +1 -0
  85. package/dist/chunk-T6MTDQZ7.mjs +45 -0
  86. package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
  87. package/dist/chunk-VPEH6V7T.mjs +83 -0
  88. package/dist/chunk-VPEH6V7T.mjs.map +1 -0
  89. package/dist/chunk-WADHCMPK.mjs +3 -0
  90. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  91. package/dist/chunk-WFTAAA7R.mjs +44 -0
  92. package/dist/chunk-WFTAAA7R.mjs.map +1 -0
  93. package/dist/chunk-WJHSY5T6.mjs +3 -0
  94. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  95. package/dist/chunk-WTASPE2W.mjs +105 -0
  96. package/dist/chunk-WTASPE2W.mjs.map +1 -0
  97. package/dist/chunk-XV7MLLXQ.mjs +18 -0
  98. package/dist/chunk-XV7MLLXQ.mjs.map +1 -0
  99. package/dist/chunk-Y473E2ZQ.mjs +112 -0
  100. package/dist/chunk-Y473E2ZQ.mjs.map +1 -0
  101. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +35 -1745
  102. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  103. package/dist/components/base-copilot-textarea/render-element.mjs +3 -51
  104. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  105. package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -49
  106. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  107. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
  108. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  109. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
  110. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  111. package/dist/components/copilot-textarea/copilot-textarea.mjs +47 -2202
  112. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  113. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -17
  114. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  115. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -137
  116. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  117. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +18 -875
  118. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  119. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +12 -558
  120. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  121. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +13 -581
  122. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  123. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +5 -102
  124. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
  125. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +14 -581
  126. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  127. package/dist/components/index.mjs +48 -2203
  128. package/dist/components/index.mjs.map +1 -1
  129. package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
  130. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  131. package/dist/components/source-search-box/source-search-box.mjs +6 -211
  132. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  133. package/dist/components/ui/button.mjs +4 -85
  134. package/dist/components/ui/button.mjs.map +1 -1
  135. package/dist/components/ui/card.mjs +7 -53
  136. package/dist/components/ui/card.mjs.map +1 -1
  137. package/dist/components/ui/command.mjs +5 -244
  138. package/dist/components/ui/command.mjs.map +1 -1
  139. package/dist/components/ui/dialog.mjs +4 -144
  140. package/dist/components/ui/dialog.mjs.map +1 -1
  141. package/dist/components/ui/label.mjs +4 -60
  142. package/dist/components/ui/label.mjs.map +1 -1
  143. package/dist/components/ui/separator.mjs +8 -50
  144. package/dist/components/ui/separator.mjs.map +1 -1
  145. package/dist/components/ui/textarea.mjs +7 -48
  146. package/dist/components/ui/textarea.mjs.map +1 -1
  147. package/dist/context/index.mjs +2 -0
  148. package/dist/context/index.mjs.map +1 -1
  149. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -158
  150. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  151. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
  152. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  153. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -148
  154. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  155. package/dist/hooks/index.mjs +2 -0
  156. package/dist/hooks/index.mjs.map +1 -1
  157. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -147
  158. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  159. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +14 -193
  160. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  161. package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
  162. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  163. package/dist/index.mjs +50 -2206
  164. package/dist/index.mjs.map +1 -1
  165. package/dist/lib/debouncer.mjs +3 -51
  166. package/dist/lib/debouncer.mjs.map +1 -1
  167. package/dist/lib/editor-to-text.mjs +3 -43
  168. package/dist/lib/editor-to-text.mjs.map +1 -1
  169. package/dist/lib/get-text-around-cursor.mjs +3 -102
  170. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  171. package/dist/lib/retry.mjs +3 -17
  172. package/dist/lib/retry.mjs.map +1 -1
  173. package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
  174. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  175. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -20
  176. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  177. package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
  178. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  179. package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
  180. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  181. package/dist/lib/stream-promise-flatten.mjs +3 -47
  182. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  183. package/dist/lib/utils.mjs +3 -71
  184. package/dist/lib/utils.mjs.map +1 -1
  185. package/dist/lib/utils.test.mjs +1 -0
  186. package/dist/lib/utils.test.mjs.map +1 -1
  187. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
  188. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  189. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +8 -265
  190. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  191. package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -81
  192. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  193. package/dist/types/autosuggestions-config/index.mjs +10 -327
  194. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  195. package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -75
  196. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  197. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -83
  198. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  199. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
  200. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  201. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
  202. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  203. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +3 -64
  204. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  205. package/dist/types/base/autosuggestion-state.mjs +2 -0
  206. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  207. package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
  208. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  209. package/dist/types/base/base-autosuggestions-config.mjs +3 -26
  210. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  211. package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
  212. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  213. package/dist/types/base/custom-editor.mjs +2 -0
  214. package/dist/types/base/custom-editor.mjs.map +1 -1
  215. package/dist/types/base/editor-autocomplete-state.mjs +4 -17
  216. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  217. package/dist/types/base/index.mjs +4 -26
  218. package/dist/types/base/index.mjs.map +1 -1
  219. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  220. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  221. package/dist/types/index.mjs +12 -328
  222. package/dist/types/index.mjs.map +1 -1
  223. package/package.json +3 -3
@@ -0,0 +1,22 @@
1
+ import { Node, Element, Transforms } from 'slate';
2
+
3
+ // src/lib/slatejs-edits/clear-autocompletions.ts
4
+ function clearAutocompletionsFromEditor(editor) {
5
+ const paths = [];
6
+ for (const [node, path] of Node.nodes(editor)) {
7
+ if (Element.isElement(node) && node.type === "suggestion") {
8
+ paths.push(path);
9
+ }
10
+ }
11
+ for (const path of paths) {
12
+ try {
13
+ Transforms.removeNodes(editor, { at: path });
14
+ } catch (e) {
15
+ console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
16
+ }
17
+ }
18
+ }
19
+
20
+ export { clearAutocompletionsFromEditor };
21
+ //# sourceMappingURL=out.js.map
22
+ //# sourceMappingURL=chunk-GQN2HYFJ.mjs.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,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-H4VKQGVU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-IU3WTXLQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { arraysAreEqual } from './chunk-7SUZ6CXM.mjs';
2
+
3
+ // src/types/base/editor-autocomplete-state.ts
4
+ function areEqual_autocompleteState(prev, next) {
5
+ return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
6
+ }
7
+
8
+ export { areEqual_autocompleteState };
9
+ //# sourceMappingURL=out.js.map
10
+ //# sourceMappingURL=chunk-JJLQVT7S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/base/editor-autocomplete-state.ts"],"names":[],"mappings":";;;;;AASO,SAAS,2BACd,MACA,MACA;AACA,SACE,KAAK,YAAY,WAAW,KAAK,YAAY,UAC7C,eAAe,KAAK,YAAY,MAAM,KAAK,YAAY,IAAI,KAC3D,KAAK,qBAAqB,KAAK,oBAC/B,KAAK,oBAAoB,KAAK;AAElC","sourcesContent":["import { BasePoint } from \"slate\";\nimport { arraysAreEqual } from \"../../lib/utils\";\n\nexport interface EditorAutocompleteState {\n cursorPoint: BasePoint;\n textBeforeCursor: string;\n textAfterCursor: string;\n}\n\nexport function areEqual_autocompleteState(\n prev: EditorAutocompleteState,\n next: EditorAutocompleteState,\n) {\n return (\n prev.cursorPoint.offset === next.cursorPoint.offset &&\n arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) &&\n prev.textBeforeCursor === next.textBeforeCursor &&\n prev.textAfterCursor === next.textAfterCursor\n );\n}\n"]}
@@ -0,0 +1,80 @@
1
+ // src/types/autosuggestions-config/editing-api-config.tsx
2
+ var defaultEditingMakeSystemPrompt = (textareaPurpose, contextString) => {
3
+ return `You are a versatile writing assistant.
4
+
5
+ The user is writing some text.
6
+ The purpose is: "${textareaPurpose}"
7
+
8
+ The following external context is also provided. Use it to help you make better suggestions!!!
9
+ \`\`\`
10
+ ${contextString}
11
+ \`\`\`
12
+
13
+ The user also provides you with a prompt for EDITING some text they are writing.
14
+ Your job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.
15
+
16
+ Adjust yourself to the user's style and implied intent.
17
+
18
+ The user will provide the following information; use this to infer the best relevant EDIT:
19
+ <TextBeforeCursor>
20
+ <TextToEdit>
21
+ <TextAfterCursor>
22
+ <EditingPrompt>
23
+
24
+ <YourEditSuggestion>
25
+ `;
26
+ };
27
+ var defaultEditingFewShotMessages = [
28
+ {
29
+ role: "user",
30
+ name: "TextBeforeCursor",
31
+ content: "This morning I woke up and went straight to the grocery store. "
32
+ },
33
+ {
34
+ role: "user",
35
+ name: "TextToEdit",
36
+ content: "While I was there I also picked up some apples, oranges, and bananas. "
37
+ },
38
+ {
39
+ role: "user",
40
+ name: "TextAfterCursor",
41
+ content: "The grocery store was having a sale on fruit, so I decided to stock up."
42
+ },
43
+ {
44
+ role: "user",
45
+ name: "EditingPrompt",
46
+ content: "I bought a big watermelon"
47
+ },
48
+ {
49
+ role: "assistant",
50
+ content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
51
+ },
52
+ {
53
+ role: "user",
54
+ name: "TextAfterCursor",
55
+ content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
56
+ },
57
+ {
58
+ role: "user",
59
+ name: "TextBeforeCursor",
60
+ content: `The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;`
61
+ },
62
+ {
63
+ role: "user",
64
+ name: "InsertionPrompt",
65
+ content: "add section about the optionholder's pro rata share"
66
+ },
67
+ {
68
+ role: "assistant",
69
+ content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
70
+ }
71
+ ];
72
+ var defaultEditingApiConfig = {
73
+ makeSystemPrompt: defaultEditingMakeSystemPrompt,
74
+ fewShotMessages: defaultEditingFewShotMessages,
75
+ forwardedParams: void 0
76
+ };
77
+
78
+ export { defaultEditingApiConfig, defaultEditingFewShotMessages, defaultEditingMakeSystemPrompt };
79
+ //# sourceMappingURL=out.js.map
80
+ //# sourceMappingURL=chunk-K5LNB36H.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/autosuggestions-config/editing-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,iCAAmD,CAC9D,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA,EAIlB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBF;AAEO,IAAM,gCAAyD;AAAA,EACpE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,0BAA4C;AAAA,EACvD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user also provides you with a prompt for EDITING some text they are writing. \nYour job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide the following information; use this to infer the best relevant EDIT:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n`;\n};\n\nexport const defaultEditingFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store. \",\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: \"While I was there I also picked up some apples, oranges, and bananas. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"The grocery store was having a sale on fruit, so I decided to stock up.\",\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: \"I bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -0,0 +1,63 @@
1
+ // src/types/autosuggestions-config/suggestions-api-config.tsx
2
+ var defaultSuggestionsMakeSystemPrompt = (textareaPurpose, contextString) => {
3
+ return `You are a versatile writing assistant.
4
+
5
+ The user is writing some text.
6
+ The purpose is: "${textareaPurpose}"
7
+
8
+ Your job is to guess what the user will write next AS BEST YOU CAN.
9
+ Only guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.
10
+
11
+ Adjust yourself to the user's style and implied intent.
12
+
13
+ The user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.
14
+ <TextAfterCursor>
15
+ <TextBeforeCursor>
16
+ <YourSuggestion>
17
+
18
+ If we need to add a whitespace character to the suggested text, make sure to explicitly add it in.
19
+
20
+ The following external context is also provided. Use it to help you make better suggestions!!!
21
+ \`\`\`
22
+ ${contextString}
23
+ \`\`\`
24
+ `;
25
+ };
26
+ var defaultSuggestionsFewShotMessages = [
27
+ {
28
+ role: "user",
29
+ name: "TextAfterCursor",
30
+ content: "While I was there I also picked up some apples, oranges, and bananas."
31
+ },
32
+ {
33
+ role: "user",
34
+ content: "This morning I woke up and went straight to the grocery store."
35
+ },
36
+ {
37
+ role: "assistant",
38
+ content: " When I arrived I went straight to the produce section and picked out a big watermelon. "
39
+ },
40
+ {
41
+ role: "user",
42
+ name: "TextAfterCursor",
43
+ content: "and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof."
44
+ },
45
+ {
46
+ role: "user",
47
+ name: "TextBeforeCursor",
48
+ content: `The Optionholder, in the Optionholder's capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an "Equityholder" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an "Equityholder" thereunder;`
49
+ },
50
+ {
51
+ role: "assistant",
52
+ content: ` (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder's "Pro Rata Share"; `
53
+ }
54
+ ];
55
+ var defaultSuggestionsApiConfig = {
56
+ makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,
57
+ fewShotMessages: defaultSuggestionsFewShotMessages,
58
+ forwardedParams: void 0
59
+ };
60
+
61
+ export { defaultSuggestionsApiConfig, defaultSuggestionsFewShotMessages, defaultSuggestionsMakeSystemPrompt };
62
+ //# sourceMappingURL=out.js.map
63
+ //# sourceMappingURL=chunk-KDVMG3XF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/autosuggestions-config/suggestions-api-config.tsx"],"names":[],"mappings":";AASO,IAAM,qCAAuD,CAClE,iBACA,kBACG;AACH,SAAO;AAAA;AAAA;AAAA,mBAGW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBlB;AAAA;AAAA;AAGF;AAEO,IAAM,oCAA6D;AAAA,EACxE;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SACE;AAAA,EACJ;AACF;AAEO,IAAM,8BAAoD;AAAA,EAC/D,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB","sourcesContent":["import { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n forwardedParams: undefined,\n};\n"]}
@@ -0,0 +1,19 @@
1
+ import { cn } from './chunk-7SUZ6CXM.mjs';
2
+ import { __objRest, __spreadValues } from './chunk-MRXNTQOX.mjs';
3
+ import * as React from 'react';
4
+ import * as LabelPrimitive from '@radix-ui/react-label';
5
+ import { cva } from 'class-variance-authority';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ var labelVariants = cva(
9
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
10
+ );
11
+ var Label = React.forwardRef((_a, ref) => {
12
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
13
+ return /* @__PURE__ */ jsx(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
14
+ });
15
+ Label.displayName = LabelPrimitive.Root.displayName;
16
+
17
+ export { Label };
18
+ //# sourceMappingURL=out.js.map
19
+ //# sourceMappingURL=chunk-KFQZHRPJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/ui/label.tsx"],"names":[],"mappings":";;;;;;;;;AAEA,YAAY,WAAW;AACvB,YAAY,oBAAoB;AAChC,SAAS,WAA8B;AAYrC;AARF,IAAM,gBAAgB;AAAA,EACpB;AACF;AAEA,IAAM,QAAc,iBAGlB,CAAC,IAAyB,QAAK;AAA9B,eAAE,YAfL,IAeG,IAAgB,kBAAhB,IAAgB,CAAd;AACH,6BAAgB,qBAAf,iBAAoB,KAAU,WAAW,GAAG,cAAc,GAAG,SAAS,KAAO,MAAO;AAAA,CACtF;AACD,MAAM,cAA6B,oBAAK","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\",\n);\n\nconst Label = React.forwardRef<\n React.ElementRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>\n>(({ className, ...props }, ref) => (\n <LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />\n));\nLabel.displayName = LabelPrimitive.Root.displayName;\n\nexport { Label };\n"]}
@@ -0,0 +1,27 @@
1
+ import { HoveringInsertionPromptBoxCore } from './chunk-ELEY7HWW.mjs';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ var HoveringInsertionPromptBox = (props) => {
5
+ return /* @__PURE__ */ jsx(
6
+ "div",
7
+ {
8
+ className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
9
+ style: { width: "35rem" },
10
+ children: /* @__PURE__ */ jsx(
11
+ HoveringInsertionPromptBoxCore,
12
+ {
13
+ state: {
14
+ editorState: props.editorState
15
+ },
16
+ insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
17
+ performInsertion: props.performInsertion,
18
+ contextCategories: props.contextCategories
19
+ }
20
+ )
21
+ }
22
+ );
23
+ };
24
+
25
+ export { HoveringInsertionPromptBox };
26
+ //# sourceMappingURL=out.js.map
27
+ //# sourceMappingURL=chunk-KNBNKEXR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx"],"names":[],"mappings":";;;;;AAqBM;AANC,IAAM,6BAA8C,CAAC,UAAU;AACpE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,OAAO,EAAE,OAAO,QAAQ;AAAA,MAExB;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL,aAAa,MAAM;AAAA,UACrB;AAAA,UACA,4BAA4B,MAAM,UAAU;AAAA,UAC5C,kBAAkB,MAAM;AAAA,UACxB,mBAAmB,MAAM;AAAA;AAAA,MAC3B;AAAA;AAAA,EACF;AAEJ","sourcesContent":["import React, { useCallback, useState } from \"react\";\nimport { HoveringInsertionPromptBoxCore } from \"./hovering-insertion-prompt-box-core\";\nimport {\n EditingEditorState,\n InsertionEditorApiConfig,\n} from \"../../../types/base/autosuggestions-bare-function\";\n\nexport interface Props {\n editorState: EditingEditorState;\n apiConfig: InsertionEditorApiConfig;\n performInsertion: (insertedText: string) => void;\n closeWindow: () => void;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBox: React.FC<Props> = (props) => {\n return (\n <div\n className=\"flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white\"\n style={{ width: \"35rem\" }}\n >\n <HoveringInsertionPromptBoxCore\n state={{\n editorState: props.editorState,\n }}\n insertionOrEditingFunction={props.apiConfig.insertionOrEditingFunction}\n performInsertion={props.performInsertion}\n contextCategories={props.contextCategories}\n />\n </div>\n );\n};\n"]}
@@ -0,0 +1,18 @@
1
+ // src/lib/retry.tsx
2
+ function retry(fn, retriesLeft = 2, interval = 200, backoff = 1.5) {
3
+ return new Promise((resolve, reject) => {
4
+ fn().then(resolve).catch((error) => {
5
+ if (retriesLeft === 1) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ setTimeout(() => {
10
+ retry(fn, retriesLeft - 1, interval * backoff, backoff).then(resolve).catch(reject);
11
+ }, interval);
12
+ });
13
+ });
14
+ }
15
+
16
+ export { retry };
17
+ //# sourceMappingURL=out.js.map
18
+ //# sourceMappingURL=chunk-KNQIEOFP.mjs.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,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-L7VVZH4Q.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,217 @@
1
+ import { addAutocompletionsToEditor } from './chunk-2C7O2EVM.mjs';
2
+ import { clearAutocompletionsFromEditor } from './chunk-GQN2HYFJ.mjs';
3
+ import { HoveringToolbar } from './chunk-Y473E2ZQ.mjs';
4
+ import { HoveringEditorProvider, useHoveringEditorContext } from './chunk-XV7MLLXQ.mjs';
5
+ import { makeRenderElementFunction } from './chunk-224UKA7C.mjs';
6
+ import { makeRenderPlaceholderFunction } from './chunk-OHO4G6DR.mjs';
7
+ import { TrackerTextEditedSinceLastCursorMovement } from './chunk-47L4PLG4.mjs';
8
+ import { useAddBrandingCss } from './chunk-7LSRNPNI.mjs';
9
+ import { defaultBaseAutosuggestionsConfig } from './chunk-FP2EKU3L.mjs';
10
+ import { useAutosuggestions } from './chunk-72P3KOHZ.mjs';
11
+ import { useCopilotTextareaEditor } from './chunk-DRV2FOHZ.mjs';
12
+ import { usePopulateCopilotTextareaRef } from './chunk-VPEH6V7T.mjs';
13
+ import { replaceEditorText } from './chunk-5UNJXFUO.mjs';
14
+ import { getTextAroundCollapsedCursor, getFullEditorTextWithNewlines } from './chunk-ECR45NSD.mjs';
15
+ import { __spreadProps, __spreadValues, __objRest } from './chunk-MRXNTQOX.mjs';
16
+ import React, { useMemo, useState, useCallback, useEffect } from 'react';
17
+ import { Editor } from 'slate';
18
+ import { Slate, Editable } from 'slate-react';
19
+ import { twMerge } from 'tailwind-merge';
20
+ import { jsx, jsxs } from 'react/jsx-runtime';
21
+
22
+ var BaseCopilotTextarea = React.forwardRef(
23
+ (props, ref) => {
24
+ return /* @__PURE__ */ jsx(HoveringEditorProvider, { children: /* @__PURE__ */ jsx(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), { ref })) });
25
+ }
26
+ );
27
+ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
28
+ (props, ref) => {
29
+ const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
30
+ const valueOnInitialRender = useMemo(() => {
31
+ var _a2;
32
+ return (_a2 = props.value) != null ? _a2 : "";
33
+ }, []);
34
+ const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);
35
+ const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);
36
+ const initialValue = useMemo(() => {
37
+ return [
38
+ {
39
+ type: "paragraph",
40
+ children: [{ text: valueOnInitialRender }]
41
+ }
42
+ ];
43
+ }, [valueOnInitialRender]);
44
+ const editor = useCopilotTextareaEditor();
45
+ const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } = useHoveringEditorContext();
46
+ const insertText = useCallback(
47
+ (autosuggestion) => {
48
+ Editor.insertText(editor, autosuggestion.text, {
49
+ at: autosuggestion.point
50
+ });
51
+ },
52
+ [editor]
53
+ );
54
+ const shouldDisableAutosuggestions = (
55
+ // textarea is manually disabled:
56
+ autosuggestionsConfig.disabled || // hovering editor is displayed:
57
+ hoveringEditorIsDisplayed || // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
58
+ cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
59
+ );
60
+ const {
61
+ currentAutocompleteSuggestion,
62
+ onChangeHandler: onChangeHandlerForAutocomplete,
63
+ onKeyDownHandler: onKeyDownHandlerForAutocomplete
64
+ } = useAutosuggestions(
65
+ autosuggestionsConfig.debounceTime,
66
+ autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
67
+ autosuggestionsConfig.apiConfig.autosuggestionsFunction,
68
+ insertText,
69
+ autosuggestionsConfig.disableWhenEmpty,
70
+ shouldDisableAutosuggestions
71
+ );
72
+ const onKeyDownHandlerForHoveringEditor = useCallback(
73
+ (event) => {
74
+ if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event)) {
75
+ event.preventDefault();
76
+ setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
77
+ }
78
+ },
79
+ [
80
+ hoveringEditorIsDisplayed,
81
+ setHoveringEditorIsDisplayed,
82
+ autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress
83
+ ]
84
+ );
85
+ useEffect(() => {
86
+ clearAutocompletionsFromEditor(editor);
87
+ if (currentAutocompleteSuggestion) {
88
+ addAutocompletionsToEditor(
89
+ editor,
90
+ currentAutocompleteSuggestion.text,
91
+ currentAutocompleteSuggestion.point
92
+ );
93
+ }
94
+ }, [currentAutocompleteSuggestion]);
95
+ const suggestionStyleAugmented = useMemo(() => {
96
+ return __spreadValues({
97
+ fontStyle: "italic",
98
+ color: "gray"
99
+ }, props.suggestionsStyle);
100
+ }, [props.suggestionsStyle]);
101
+ const renderElementMemoized = useMemo(() => {
102
+ return makeRenderElementFunction(suggestionStyleAugmented);
103
+ }, [suggestionStyleAugmented]);
104
+ const renderPlaceholderMemoized = useMemo(() => {
105
+ const placeholderStyleSlatejsOverrides = {
106
+ top: void 0
107
+ };
108
+ const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
109
+ return makeRenderPlaceholderFunction(placeholderStyleAugmented);
110
+ }, [props.placeholderStyle]);
111
+ useEffect(() => {
112
+ var _a2, _b;
113
+ if (props.value === lastKnownFullEditorText) {
114
+ return;
115
+ }
116
+ setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
117
+ replaceEditorText(editor, (_b = props.value) != null ? _b : "");
118
+ }, [props.value]);
119
+ const _a = props, {
120
+ placeholderStyle,
121
+ value,
122
+ hoverMenuClassname,
123
+ onValueChange,
124
+ baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
125
+ className,
126
+ onChange,
127
+ onKeyDown,
128
+ disableBranding
129
+ } = _a, propsToForward = __objRest(_a, [
130
+ "placeholderStyle",
131
+ "value",
132
+ "hoverMenuClassname",
133
+ "onValueChange",
134
+ "baseAutosuggestionsConfig",
135
+ "className",
136
+ "onChange",
137
+ "onKeyDown",
138
+ "disableBranding"
139
+ ]);
140
+ useAddBrandingCss(suggestionStyleAugmented, disableBranding);
141
+ usePopulateCopilotTextareaRef(editor, ref);
142
+ const moddedClassName = (() => {
143
+ const baseClassName = "copilot-textarea";
144
+ const brandingClass = disableBranding ? "no-branding" : "with-branding";
145
+ const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
146
+ const mergedClassName = twMerge(defaultTailwindClassName, className != null ? className : "");
147
+ return `${baseClassName} ${brandingClass} ${mergedClassName}`;
148
+ })();
149
+ return /* @__PURE__ */ jsxs(
150
+ Slate,
151
+ {
152
+ editor,
153
+ initialValue,
154
+ onChange: (value2) => {
155
+ var _a2, _b;
156
+ const newEditorState = getTextAroundCollapsedCursor(editor);
157
+ const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
158
+ setLastKnownFullEditorText((prev) => {
159
+ if (prev !== fullEditorText) {
160
+ setCursorMovedSinceLastTextChange(false);
161
+ }
162
+ return fullEditorText;
163
+ });
164
+ onChangeHandlerForAutocomplete(newEditorState);
165
+ (_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
166
+ (_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
167
+ },
168
+ children: [
169
+ /* @__PURE__ */ jsx(
170
+ TrackerTextEditedSinceLastCursorMovement,
171
+ {
172
+ setCursorMovedSinceLastTextChange
173
+ }
174
+ ),
175
+ /* @__PURE__ */ jsx(
176
+ HoveringToolbar,
177
+ {
178
+ apiConfig: autosuggestionsConfig.apiConfig,
179
+ contextCategories: autosuggestionsConfig.contextCategories,
180
+ hoverMenuClassname
181
+ }
182
+ ),
183
+ /* @__PURE__ */ jsx(
184
+ Editable,
185
+ __spreadValues({
186
+ renderElement: renderElementMemoized,
187
+ renderPlaceholder: renderPlaceholderMemoized,
188
+ onKeyDown: (event) => {
189
+ var _a2;
190
+ onKeyDownHandlerForHoveringEditor(event);
191
+ onKeyDownHandlerForAutocomplete(event);
192
+ (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
193
+ },
194
+ className: moddedClassName
195
+ }, propsToForward)
196
+ )
197
+ ]
198
+ }
199
+ );
200
+ }
201
+ );
202
+ function makeSemiFakeReactTextAreaEvent(currentText) {
203
+ return {
204
+ target: {
205
+ value: currentText,
206
+ type: "copilot-textarea"
207
+ },
208
+ currentTarget: {
209
+ value: currentText,
210
+ type: "copilot-textarea"
211
+ }
212
+ };
213
+ }
214
+
215
+ export { BaseCopilotTextarea };
216
+ //# sourceMappingURL=out.js.map
217
+ //# sourceMappingURL=chunk-LP2REBM5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"names":["_a","value"],"mappings":"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","sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Descendant, Editor } from \"slate\";\nimport { Editable, Slate } from \"slate-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { useAutosuggestions } from \"../../hooks/base-copilot-textarea-implementation/use-autosuggestions\";\nimport { useCopilotTextareaEditor } from \"../../hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor\";\nimport { usePopulateCopilotTextareaRef } from \"../../hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundCollapsedCursor,\n} from \"../../lib/get-text-around-cursor\";\nimport { addAutocompletionsToEditor } from \"../../lib/slatejs-edits/add-autocompletions\";\nimport { clearAutocompletionsFromEditor } from \"../../lib/slatejs-edits/clear-autocompletions\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport \"./base-copilot-textarea.css\";\nimport { HoveringToolbar } from \"../hovering-toolbar/hovering-toolbar\";\nimport { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\nimport {\n HoveringEditorProvider,\n useHoveringEditorContext,\n} from \"../hovering-toolbar/hovering-editor-provider\";\nimport { EditorAutocompleteState } from \"../../types/base/editor-autocomplete-state\";\nimport { TrackerTextEditedSinceLastCursorMovement } from \"./track-cursor-moved-since-last-text-change\";\n\n/**\n * Purpose: to be used as the `ref` type for `CopilotTextarea` and `BaseCopilotTextarea`.\n *\n * This interface extends `HTMLElement`, and is the subset of `HTMLTextAreaElement` that \"actually matters\".\n * It provides the core functionality that consumers of `HTMLTextAreaElement` need 99.9% of the time:\n * - `value`: the current value of the textarea\n * - `focus`: make the textarea focused\n * - `blur`: make the textarea unfocused\n */\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n /**\n * The current value of the textarea.\n */\n value: string;\n\n /**\n * focus on the textarea\n */\n focus: () => void;\n\n /**\n * unfocus the textarea.\n *\n * Called `blur` for syntactic compatibility with `HTMLTextAreaElement`.\n */\n blur: () => void;\n}\n\n/**\n * Not intended for direct use. Use CopilotTextarea instead.\n *\n * The `BaseCopilotTextarea` includes the basic UX component,\n * without the business logic / AI logic that makes the content useful and coherent.\n *\n * It is useful if you want to build your own backend, with fully custom business logic\n * for figuring out which contnet to fill in.\n */\nexport const BaseCopilotTextarea = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {\n return (\n <HoveringEditorProvider>\n <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />\n </HoveringEditorProvider>\n );\n },\n);\n\n/**\n * Not intended for direct use. Use `CopilotTextarea` instead.\n *\n * This is the private core of the `BaseCopilotTextarea` component.\n * For practical purposes the implementation is cleaner assuming containment in a `HoveringEditorProviderContext`.\n *\n * Therefore we separate the core logic into this component,\n * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.\n */\nconst BaseCopilotTextareaWithHoveringContext = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.baseAutosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);\n const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);\n\n // // When the editor text changes, we want to reset the `textEditedSinceLastCursorMovement` state.\n // useEffect(() => {\n // setCursorMovedSinceLastTextChange(false);\n // }, [lastKnownFullEditorText]);\n\n const initialValue: Descendant[] = useMemo(() => {\n return [\n {\n type: \"paragraph\",\n children: [{ text: valueOnInitialRender }],\n },\n ];\n }, [valueOnInitialRender]);\n\n const editor = useCopilotTextareaEditor();\n\n const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } =\n useHoveringEditorContext();\n\n const insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor],\n );\n\n const shouldDisableAutosuggestions =\n // textarea is manually disabled:\n autosuggestionsConfig.disabled ||\n // hovering editor is displayed:\n hoveringEditorIsDisplayed ||\n // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:\n (cursorMovedSinceLastTextChange &&\n autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText);\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,\n autosuggestionsConfig.apiConfig.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n shouldDisableAutosuggestions,\n );\n\n const onKeyDownHandlerForHoveringEditor = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event)) {\n event.preventDefault();\n setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);\n }\n },\n [\n hoveringEditorIsDisplayed,\n setHoveringEditorIsDisplayed,\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress,\n ],\n );\n\n // sync autosuggestions state with the editor\n useEffect(() => {\n clearAutocompletionsFromEditor(editor);\n if (currentAutocompleteSuggestion) {\n addAutocompletionsToEditor(\n editor,\n currentAutocompleteSuggestion.text,\n currentAutocompleteSuggestion.point,\n );\n }\n }, [currentAutocompleteSuggestion]);\n\n const suggestionStyleAugmented: React.CSSProperties = useMemo(() => {\n return {\n fontStyle: \"italic\",\n color: \"gray\",\n ...props.suggestionsStyle,\n };\n }, [props.suggestionsStyle]);\n\n const renderElementMemoized = useMemo(() => {\n return makeRenderElementFunction(suggestionStyleAugmented);\n }, [suggestionStyleAugmented]);\n\n const renderPlaceholderMemoized = useMemo(() => {\n // For some reason slateJS specifies a top value of 0, which makes for strange styling. We override this here.\n const placeholderStyleSlatejsOverrides: React.CSSProperties = {\n top: undefined,\n };\n\n const placeholderStyleAugmented: React.CSSProperties = {\n ...placeholderStyleSlatejsOverrides,\n ...props.placeholderStyle,\n };\n\n return makeRenderPlaceholderFunction(placeholderStyleAugmented);\n }, [props.placeholderStyle]);\n\n // update the editor text, but only when the value changes from outside the component\n useEffect(() => {\n if (props.value === lastKnownFullEditorText) {\n return;\n }\n\n setLastKnownFullEditorText(props.value ?? \"\");\n replaceEditorText(editor, props.value ?? \"\");\n }, [props.value]);\n\n // separate into TextareaHTMLAttributes<HTMLDivElement> and CopilotTextareaProps\n const {\n placeholderStyle,\n value,\n hoverMenuClassname,\n onValueChange,\n baseAutosuggestionsConfig: autosuggestionsConfigFromProps,\n className,\n onChange,\n onKeyDown,\n disableBranding,\n ...propsToForward\n } = props;\n\n useAddBrandingCss(suggestionStyleAugmented, disableBranding);\n usePopulateCopilotTextareaRef(editor, ref);\n\n const moddedClassName = (() => {\n const baseClassName = \"copilot-textarea\";\n const brandingClass = disableBranding ? \"no-branding\" : \"with-branding\";\n const defaultTailwindClassName = \"bg-white overflow-y-auto resize-y\";\n const mergedClassName = twMerge(defaultTailwindClassName, className ?? \"\");\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCollapsedCursor(editor);\n\n const fullEditorText = newEditorState\n ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor\n : getFullEditorTextWithNewlines(editor); // we don't double-parse the editor. When `newEditorState` is null, we didn't parse the editor yet.\n\n setLastKnownFullEditorText((prev) => {\n if (prev !== fullEditorText) {\n setCursorMovedSinceLastTextChange(false);\n }\n return fullEditorText;\n });\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <TrackerTextEditedSinceLastCursorMovement\n setCursorMovedSinceLastTextChange={setCursorMovedSinceLastTextChange}\n />\n <HoveringToolbar\n apiConfig={autosuggestionsConfig.apiConfig}\n contextCategories={autosuggestionsConfig.contextCategories}\n hoverMenuClassname={hoverMenuClassname}\n />\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\n onKeyDownHandlerForHoveringEditor(event); // forward the event for internal use\n onKeyDownHandlerForAutocomplete(event); // forward the event for internal use\n props.onKeyDown?.(event); // forward the event for external use\n }}\n className={moddedClassName}\n {...propsToForward}\n />\n </Slate>\n );\n },\n);\n\n// Consumers of <textarea> expect a `onChange: (React.ChangeEvent<HTMLTextAreaElement>) => void` event handler to be passed in.\n// This is *extremely* common, and we want to support it.\n//\n// We can't support the full functionality, but in 99% of cases, the consumer only cares about the `event.target.value` property --\n// that's how they get the new value of the textarea.\n//\n// So, the tradeoff we are making is minimizing compiler complaint, with a small chance of runtime error.\n// The alternative would be defining a different onChange entrypoint (we actually do have that in `onValueChange`),\n// And starting to explain subtleties to users the moment they try to use the component for the first time for very basic functionality.\n//\n// If this proves problematic, we can always revisit this decision.\nfunction makeSemiFakeReactTextAreaEvent(\n currentText: string,\n): React.ChangeEvent<HTMLTextAreaElement> {\n return {\n target: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n currentTarget: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n } as React.ChangeEvent<HTMLTextAreaElement>;\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import { __async } from './chunk-MRXNTQOX.mjs';
2
+
3
+ // src/lib/debouncer.ts
4
+ var Debouncer = class {
5
+ constructor(wait) {
6
+ this.wait = wait;
7
+ this.debounce = (func, ...args) => __async(this, null, function* () {
8
+ this.cancel();
9
+ this.timeoutId = setTimeout(() => __async(this, null, function* () {
10
+ try {
11
+ this.activeAbortController = new AbortController();
12
+ yield func(...args, this.activeAbortController.signal);
13
+ this.activeAbortController = void 0;
14
+ } catch (error) {
15
+ }
16
+ }), this.wait);
17
+ });
18
+ this.cancel = () => {
19
+ if (this.activeAbortController) {
20
+ this.activeAbortController.abort();
21
+ this.activeAbortController = void 0;
22
+ }
23
+ if (this.timeoutId !== void 0) {
24
+ clearTimeout(this.timeoutId);
25
+ this.timeoutId = void 0;
26
+ }
27
+ };
28
+ }
29
+ };
30
+
31
+ export { Debouncer };
32
+ //# sourceMappingURL=out.js.map
33
+ //# sourceMappingURL=chunk-M2DR4KVB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/debouncer.ts"],"names":[],"mappings":";;;;;AAEO,IAAM,YAAN,MAAiC;AAAA,EAItC,YAAoB,MAAc;AAAd;AAEpB,oBAAW,CAAO,SAA2B,SAAY;AAEvD,WAAK,OAAO;AAEZ,WAAK,YAAY,WAAW,MAAY;AACtC,YAAI;AACF,eAAK,wBAAwB,IAAI,gBAAgB;AAGjD,gBAAM,KAAK,GAAG,MAAM,KAAK,sBAAsB,MAAM;AAErD,eAAK,wBAAwB;AAAA,QAC/B,SAAS,OAAP;AAAA,QAAe;AAAA,MACnB,IAAG,KAAK,IAAI;AAAA,IACd;AAEA,kBAAS,MAAM;AACb,UAAI,KAAK,uBAAuB;AAC9B,aAAK,sBAAsB,MAAM;AACjC,aAAK,wBAAwB;AAAA,MAC/B;AAEA,UAAI,KAAK,cAAc,QAAW;AAChC,qBAAa,KAAK,SAAS;AAC3B,aAAK,YAAY;AAAA,MACnB;AAAA,IACF;AAAA,EA5BmC;AA6BrC","sourcesContent":["export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;\n\nexport class Debouncer<T extends any[]> {\n private timeoutId?: number;\n private activeAbortController?: AbortController;\n\n constructor(private wait: number) {}\n\n debounce = async (func: AsyncFunction<T>, ...args: T) => {\n // Abort the previous promise immediately\n this.cancel();\n\n this.timeoutId = setTimeout(async () => {\n try {\n this.activeAbortController = new AbortController();\n\n // Pass the signal to the async function, assuming it supports it\n await func(...args, this.activeAbortController.signal);\n\n this.activeAbortController = undefined;\n } catch (error) {}\n }, this.wait);\n };\n\n cancel = () => {\n if (this.activeAbortController) {\n this.activeAbortController.abort();\n this.activeAbortController = undefined;\n }\n\n if (this.timeoutId !== undefined) {\n clearTimeout(this.timeoutId);\n this.timeoutId = undefined;\n }\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-MMVDU6DF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}