@copilotkit/react-textarea 0.19.0-alpha.4 → 0.19.0-alpha.5

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 (277) hide show
  1. package/.turbo/turbo-build.log +129 -190
  2. package/CHANGELOG.md +10 -0
  3. package/dist/chunk-2NURR2DX.mjs +47 -0
  4. package/dist/chunk-2NURR2DX.mjs.map +1 -0
  5. package/dist/chunk-4HSJ5XUO.mjs +107 -0
  6. package/dist/chunk-4HSJ5XUO.mjs.map +1 -0
  7. package/dist/chunk-4S5ZJH3I.mjs +18 -0
  8. package/dist/chunk-4S5ZJH3I.mjs.map +1 -0
  9. package/dist/chunk-55EGOC5T.mjs +87 -0
  10. package/dist/chunk-55EGOC5T.mjs.map +1 -0
  11. package/dist/chunk-5ARCOTW3.mjs +34 -0
  12. package/dist/chunk-5ARCOTW3.mjs.map +1 -0
  13. package/dist/chunk-5EJ5XOGP.mjs +22 -0
  14. package/dist/chunk-5EJ5XOGP.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-6Z6Z2K7O.mjs +20 -0
  18. package/dist/chunk-6Z6Z2K7O.mjs.map +1 -0
  19. package/dist/chunk-7PSM4AUU.mjs +201 -0
  20. package/dist/chunk-7PSM4AUU.mjs.map +1 -0
  21. package/dist/chunk-A2RRLD23.mjs +69 -0
  22. package/dist/chunk-A2RRLD23.mjs.map +1 -0
  23. package/dist/chunk-CSGFJU3L.mjs +65 -0
  24. package/dist/chunk-CSGFJU3L.mjs.map +1 -0
  25. package/dist/chunk-D7SEV5PR.mjs +12 -0
  26. package/dist/chunk-D7SEV5PR.mjs.map +1 -0
  27. package/dist/chunk-DE5K76I2.mjs +3 -0
  28. package/dist/chunk-DE5K76I2.mjs.map +1 -0
  29. package/dist/chunk-F3MHL6ZY.mjs +25 -0
  30. package/dist/chunk-F3MHL6ZY.mjs.map +1 -0
  31. package/dist/chunk-FN7GDKKG.mjs +29 -0
  32. package/dist/chunk-FN7GDKKG.mjs.map +1 -0
  33. package/dist/chunk-GQJYEVBT.mjs +461 -0
  34. package/dist/chunk-GQJYEVBT.mjs.map +1 -0
  35. package/dist/chunk-H4VKQGVU.mjs +3 -0
  36. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  37. package/dist/chunk-HAFHLU4N.mjs +55 -0
  38. package/dist/chunk-HAFHLU4N.mjs.map +1 -0
  39. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  40. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  41. package/dist/chunk-IXJ2HCOA.mjs +101 -0
  42. package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
  43. package/dist/chunk-JAFCXEPU.mjs +10 -0
  44. package/dist/chunk-JAFCXEPU.mjs.map +1 -0
  45. package/dist/chunk-KCHYD3EB.mjs +107 -0
  46. package/dist/chunk-KCHYD3EB.mjs.map +1 -0
  47. package/dist/chunk-KGKLUWKW.mjs +47 -0
  48. package/dist/chunk-KGKLUWKW.mjs.map +1 -0
  49. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  50. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  51. package/dist/chunk-LNAIMEB2.mjs +34 -0
  52. package/dist/chunk-LNAIMEB2.mjs.map +1 -0
  53. package/dist/chunk-MMVDU6DF.mjs +3 -0
  54. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  55. package/dist/chunk-MPME5BW2.mjs +59 -0
  56. package/dist/chunk-MPME5BW2.mjs.map +1 -0
  57. package/dist/chunk-MRXNTQOX.mjs +55 -0
  58. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  59. package/dist/chunk-ND5PXTAW.mjs +17 -0
  60. package/dist/chunk-ND5PXTAW.mjs.map +1 -0
  61. package/dist/chunk-NKW5OU2S.mjs +33 -0
  62. package/dist/chunk-NKW5OU2S.mjs.map +1 -0
  63. package/dist/chunk-O5OWT5GE.mjs +114 -0
  64. package/dist/chunk-O5OWT5GE.mjs.map +1 -0
  65. package/dist/chunk-OD7ZMOVE.mjs +45 -0
  66. package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
  67. package/dist/chunk-OELUUJZY.mjs +16 -0
  68. package/dist/chunk-OELUUJZY.mjs.map +1 -0
  69. package/dist/chunk-PHFEZQTN.mjs +44 -0
  70. package/dist/chunk-PHFEZQTN.mjs.map +1 -0
  71. package/dist/chunk-QL2GYGG5.mjs +19 -0
  72. package/dist/chunk-QL2GYGG5.mjs.map +1 -0
  73. package/dist/chunk-RQHOUUXQ.mjs +29 -0
  74. package/dist/chunk-RQHOUUXQ.mjs.map +1 -0
  75. package/dist/chunk-UHD44NC5.mjs +101 -0
  76. package/dist/chunk-UHD44NC5.mjs.map +1 -0
  77. package/dist/chunk-VBIJPE3H.mjs +108 -0
  78. package/dist/chunk-VBIJPE3H.mjs.map +1 -0
  79. package/dist/chunk-WADHCMPK.mjs +3 -0
  80. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  81. package/dist/chunk-WJHSY5T6.mjs +3 -0
  82. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  83. package/dist/chunk-WJYQWL4I.mjs +27 -0
  84. package/dist/chunk-WJYQWL4I.mjs.map +1 -0
  85. package/dist/chunk-XA7M72ZO.mjs +106 -0
  86. package/dist/chunk-XA7M72ZO.mjs.map +1 -0
  87. package/dist/chunk-XDT7BF3V.mjs +81 -0
  88. package/dist/chunk-XDT7BF3V.mjs.map +1 -0
  89. package/dist/chunk-XHUMROEY.mjs +91 -0
  90. package/dist/chunk-XHUMROEY.mjs.map +1 -0
  91. package/dist/chunk-YQU7WG7T.mjs +83 -0
  92. package/dist/chunk-YQU7WG7T.mjs.map +1 -0
  93. package/dist/chunk-YTOPHPSG.mjs +45 -0
  94. package/dist/chunk-YTOPHPSG.mjs.map +1 -0
  95. package/dist/chunk-YW3REYX6.mjs +23 -0
  96. package/dist/chunk-YW3REYX6.mjs.map +1 -0
  97. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +33 -1870
  98. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  99. package/dist/components/base-copilot-textarea/render-element.mjs +3 -52
  100. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  101. package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -46
  102. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  103. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
  104. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  105. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
  106. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  107. package/dist/components/copilot-textarea/copilot-textarea.mjs +43 -2339
  108. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  109. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -22
  110. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  111. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -125
  112. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  113. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +16 -1015
  114. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  115. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +10 -721
  116. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  117. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +11 -734
  118. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  119. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +12 -734
  120. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  121. package/dist/components/index.mjs +44 -2340
  122. package/dist/components/index.mjs.map +1 -1
  123. package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
  124. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  125. package/dist/components/source-search-box/source-search-box.mjs +10 -323
  126. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  127. package/dist/components/ui/button.mjs +4 -88
  128. package/dist/components/ui/button.mjs.map +1 -1
  129. package/dist/components/ui/card.mjs +7 -53
  130. package/dist/components/ui/card.mjs.map +1 -1
  131. package/dist/components/ui/command.mjs +5 -266
  132. package/dist/components/ui/command.mjs.map +1 -1
  133. package/dist/components/ui/dialog.mjs +4 -164
  134. package/dist/components/ui/dialog.mjs.map +1 -1
  135. package/dist/components/ui/label.mjs +4 -63
  136. package/dist/components/ui/label.mjs.map +1 -1
  137. package/dist/components/ui/separator.mjs +8 -50
  138. package/dist/components/ui/separator.mjs.map +1 -1
  139. package/dist/components/ui/textarea.mjs +7 -48
  140. package/dist/components/ui/textarea.mjs.map +1 -1
  141. package/dist/context/index.mjs +2 -0
  142. package/dist/context/index.mjs.map +1 -1
  143. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -168
  144. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  145. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
  146. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  147. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -155
  148. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  149. package/dist/hooks/index.mjs +2 -0
  150. package/dist/hooks/index.mjs.map +1 -1
  151. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +4 -90
  152. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  153. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +4 -143
  154. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  155. package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
  156. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  157. package/dist/index.mjs +48 -2343
  158. package/dist/index.mjs.map +1 -1
  159. package/dist/lib/debouncer.mjs +3 -51
  160. package/dist/lib/debouncer.mjs.map +1 -1
  161. package/dist/lib/editor-to-text.mjs +3 -43
  162. package/dist/lib/editor-to-text.mjs.map +1 -1
  163. package/dist/lib/get-text-around-cursor.mjs +3 -109
  164. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  165. package/dist/lib/retry.mjs +3 -17
  166. package/dist/lib/retry.mjs.map +1 -1
  167. package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
  168. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  169. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -23
  170. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  171. package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
  172. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  173. package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
  174. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  175. package/dist/lib/stream-promise-flatten.mjs +3 -47
  176. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  177. package/dist/lib/utils.mjs +3 -71
  178. package/dist/lib/utils.mjs.map +1 -1
  179. package/dist/lib/utils.test.mjs +1 -0
  180. package/dist/lib/utils.test.mjs.map +1 -1
  181. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
  182. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  183. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +9 -312
  184. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  185. package/dist/types/autosuggestions-config/editing-api-config.mjs +4 -155
  186. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  187. package/dist/types/autosuggestions-config/index.mjs +10 -313
  188. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  189. package/dist/types/autosuggestions-config/insertions-api-config.mjs +4 -149
  190. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  191. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -71
  192. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  193. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
  194. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  195. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
  196. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  197. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +4 -137
  198. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  199. package/dist/types/base/autosuggestion-state.mjs +2 -0
  200. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  201. package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
  202. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  203. package/dist/types/base/base-autosuggestions-config.mjs +3 -11
  204. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  205. package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
  206. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  207. package/dist/types/base/custom-editor.mjs +2 -0
  208. package/dist/types/base/custom-editor.mjs.map +1 -1
  209. package/dist/types/base/editor-autocomplete-state.mjs +4 -17
  210. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  211. package/dist/types/base/index.mjs +4 -11
  212. package/dist/types/base/index.mjs.map +1 -1
  213. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  214. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  215. package/dist/types/index.mjs +12 -314
  216. package/dist/types/index.mjs.map +1 -1
  217. package/package.json +3 -3
  218. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +0 -13
  219. package/dist/components/base-copilot-textarea/render-element.d.ts +0 -6
  220. package/dist/components/base-copilot-textarea/render-placeholder.d.ts +0 -6
  221. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +0 -6
  222. package/dist/components/base-copilot-textarea/use-add-branding-css.d.ts +0 -3
  223. package/dist/components/copilot-textarea/copilot-textarea.d.ts +0 -20
  224. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +0 -13
  225. package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +0 -18
  226. package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +0 -8
  227. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +0 -29
  228. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +0 -12
  229. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +0 -3
  230. package/dist/components/index.d.ts +0 -15
  231. package/dist/components/manual-ui/chip-with-icon.d.ts +0 -10
  232. package/dist/components/source-search-box/source-search-box.d.ts +0 -17
  233. package/dist/components/ui/button.d.ts +0 -14
  234. package/dist/components/ui/card.d.ts +0 -10
  235. package/dist/components/ui/command.d.ts +0 -48
  236. package/dist/components/ui/dialog.d.ts +0 -18
  237. package/dist/components/ui/label.d.ts +0 -8
  238. package/dist/components/ui/separator.d.ts +0 -6
  239. package/dist/components/ui/textarea.d.ts +0 -7
  240. package/dist/context/index.d.ts +0 -1
  241. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +0 -13
  242. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.ts +0 -8
  243. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +0 -7
  244. package/dist/hooks/index.d.ts +0 -1
  245. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +0 -22
  246. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +0 -23
  247. package/dist/hooks/misc/use-autosize-textarea.d.ts +0 -5
  248. package/dist/index.d.ts +0 -15
  249. package/dist/lib/debouncer.d.ts +0 -11
  250. package/dist/lib/editor-to-text.d.ts +0 -7
  251. package/dist/lib/get-text-around-cursor.d.ts +0 -15
  252. package/dist/lib/retry.d.ts +0 -3
  253. package/dist/lib/slatejs-edits/add-autocompletions.d.ts +0 -8
  254. package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +0 -8
  255. package/dist/lib/slatejs-edits/replace-text.d.ts +0 -5
  256. package/dist/lib/slatejs-edits/with-partial-history.d.ts +0 -10
  257. package/dist/lib/stream-promise-flatten.d.ts +0 -3
  258. package/dist/lib/utils.d.ts +0 -10
  259. package/dist/lib/utils.test.d.ts +0 -1
  260. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +0 -25
  261. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +0 -20
  262. package/dist/types/autosuggestions-config/editing-api-config.d.ts +0 -17
  263. package/dist/types/autosuggestions-config/index.d.ts +0 -10
  264. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +0 -17
  265. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.d.ts +0 -26
  266. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +0 -3
  267. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.d.ts +0 -7
  268. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +0 -17
  269. package/dist/types/base/autosuggestion-state.d.ts +0 -8
  270. package/dist/types/base/autosuggestions-bare-function.d.ts +0 -17
  271. package/dist/types/base/base-autosuggestions-config.d.ts +0 -14
  272. package/dist/types/base/base-copilot-textarea-props.d.ts +0 -40
  273. package/dist/types/base/custom-editor.d.ts +0 -29
  274. package/dist/types/base/editor-autocomplete-state.d.ts +0 -10
  275. package/dist/types/base/index.d.ts +0 -4
  276. package/dist/types/html-copilot-textarea-element.d.ts +0 -7
  277. package/dist/types/index.d.ts +0 -13
@@ -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-IXJ2HCOA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/get-text-around-cursor.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n Editor,\n Node,\n Path,\n Range,\n Text,\n Element,\n BasePoint,\n BaseRange,\n Point,\n} from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(\n editor: Editor\n): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { arraysAreEqual } from './chunk-KGKLUWKW.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-JAFCXEPU.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,107 @@
1
+ import { Transforms, Editor, Operation, Path } from 'slate';
2
+ import { HistoryEditor } from 'slate-history';
3
+
4
+ // src/lib/slatejs-edits/with-partial-history.ts
5
+ var withPartialHistory = (editor, shouldSave) => {
6
+ const e = editor;
7
+ const { apply } = e;
8
+ e.history = { undos: [], redos: [] };
9
+ e.redo = () => {
10
+ const { history } = e;
11
+ const { redos } = history;
12
+ if (redos.length > 0) {
13
+ const batch = redos[redos.length - 1];
14
+ if (batch.selectionBefore) {
15
+ Transforms.setSelection(e, batch.selectionBefore);
16
+ }
17
+ HistoryEditor.withoutSaving(e, () => {
18
+ Editor.withoutNormalizing(e, () => {
19
+ for (const op of batch.operations) {
20
+ e.apply(op);
21
+ }
22
+ });
23
+ });
24
+ history.redos.pop();
25
+ e.writeHistory("undos", batch);
26
+ }
27
+ };
28
+ e.undo = () => {
29
+ const { history } = e;
30
+ const { undos } = history;
31
+ if (undos.length > 0) {
32
+ const batch = undos[undos.length - 1];
33
+ HistoryEditor.withoutSaving(e, () => {
34
+ Editor.withoutNormalizing(e, () => {
35
+ const inverseOps = batch.operations.map(Operation.inverse).reverse();
36
+ for (const op of inverseOps) {
37
+ e.apply(op);
38
+ }
39
+ if (batch.selectionBefore) {
40
+ Transforms.setSelection(e, batch.selectionBefore);
41
+ }
42
+ });
43
+ });
44
+ e.writeHistory("redos", batch);
45
+ history.undos.pop();
46
+ }
47
+ };
48
+ e.apply = (op) => {
49
+ const { operations, history } = e;
50
+ const { undos } = history;
51
+ const lastBatch = undos[undos.length - 1];
52
+ const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
53
+ let save = HistoryEditor.isSaving(e);
54
+ let merge = HistoryEditor.isMerging(e);
55
+ if (save == null) {
56
+ save = shouldSave(op, lastOp);
57
+ }
58
+ if (save) {
59
+ if (merge == null) {
60
+ if (lastBatch == null) {
61
+ merge = false;
62
+ } else if (operations.length !== 0) {
63
+ merge = true;
64
+ } else {
65
+ merge = shouldMerge(op, lastOp);
66
+ }
67
+ }
68
+ if (lastBatch && merge) {
69
+ lastBatch.operations.push(op);
70
+ } else {
71
+ const batch = {
72
+ operations: [op],
73
+ selectionBefore: e.selection
74
+ };
75
+ e.writeHistory("undos", batch);
76
+ }
77
+ while (undos.length > 100) {
78
+ undos.shift();
79
+ }
80
+ history.redos = [];
81
+ }
82
+ apply(op);
83
+ };
84
+ e.writeHistory = (stack, batch) => {
85
+ e.history[stack].push(batch);
86
+ };
87
+ return e;
88
+ };
89
+ var shouldMerge = (op, prev) => {
90
+ if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
91
+ return true;
92
+ }
93
+ if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
94
+ return true;
95
+ }
96
+ return false;
97
+ };
98
+ var defaultShouldSave = (op, prev) => {
99
+ if (op.type === "set_selection") {
100
+ return false;
101
+ }
102
+ return true;
103
+ };
104
+
105
+ export { defaultShouldSave, withPartialHistory };
106
+ //# sourceMappingURL=out.js.map
107
+ //# sourceMappingURL=chunk-KCHYD3EB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/slatejs-edits/with-partial-history.ts"],"names":[],"mappings":"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","sourcesContent":["import { Editor, Operation, Path, Range, Transforms } from \"slate\";\nimport { HistoryEditor } from \"slate-history\";\n\n// Copy-pasted from `https://github.com/ianstormtaylor/slate/blob/main/packages/slate-history/src/with-history.ts`\n// With one exception: the `shouldSave` function is passed in as an argument to `withPartialHistory` instead of being hardcoded\nexport type ShouldSaveToHistory = (\n op: Operation,\n prev: Operation | undefined\n) => boolean;\n\nexport const withPartialHistory = <T extends Editor>(\n editor: T,\n shouldSave: ShouldSaveToHistory\n) => {\n const e = editor as T & HistoryEditor;\n const { apply } = e;\n e.history = { undos: [], redos: [] };\n\n e.redo = () => {\n const { history } = e;\n const { redos } = history;\n\n if (redos.length > 0) {\n const batch = redos[redos.length - 1];\n\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n for (const op of batch.operations) {\n e.apply(op);\n }\n });\n });\n\n history.redos.pop();\n e.writeHistory(\"undos\", batch);\n }\n };\n\n e.undo = () => {\n const { history } = e;\n const { undos } = history;\n\n if (undos.length > 0) {\n const batch = undos[undos.length - 1];\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n const inverseOps = batch.operations.map(Operation.inverse).reverse();\n\n for (const op of inverseOps) {\n e.apply(op);\n }\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n });\n });\n\n e.writeHistory(\"redos\", batch);\n history.undos.pop();\n }\n };\n\n e.apply = (op: Operation) => {\n const { operations, history } = e;\n const { undos } = history;\n const lastBatch = undos[undos.length - 1];\n const lastOp =\n lastBatch && lastBatch.operations[lastBatch.operations.length - 1];\n let save = HistoryEditor.isSaving(e);\n let merge = HistoryEditor.isMerging(e);\n\n if (save == null) {\n save = shouldSave(op, lastOp);\n }\n\n if (save) {\n if (merge == null) {\n if (lastBatch == null) {\n merge = false;\n } else if (operations.length !== 0) {\n merge = true;\n } else {\n merge = shouldMerge(op, lastOp);\n }\n }\n\n if (lastBatch && merge) {\n lastBatch.operations.push(op);\n } else {\n const batch = {\n operations: [op],\n selectionBefore: e.selection,\n };\n e.writeHistory(\"undos\", batch);\n }\n\n while (undos.length > 100) {\n undos.shift();\n }\n\n history.redos = [];\n }\n\n apply(op);\n };\n\n e.writeHistory = (stack: \"undos\" | \"redos\", batch: any) => {\n e.history[stack].push(batch);\n };\n\n return e;\n};\n\n/**\n * Check whether to merge an operation into the previous operation.\n */\n\nconst shouldMerge = (op: Operation, prev: Operation | undefined): boolean => {\n if (\n prev &&\n op.type === \"insert_text\" &&\n prev.type === \"insert_text\" &&\n op.offset === prev.offset + prev.text.length &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n if (\n prev &&\n op.type === \"remove_text\" &&\n prev.type === \"remove_text\" &&\n op.offset + op.text.length === prev.offset &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n return false;\n};\n\nexport const defaultShouldSave = (\n op: Operation,\n prev: Operation | undefined\n): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"]}
@@ -0,0 +1,47 @@
1
+ import { __async } from './chunk-MRXNTQOX.mjs';
2
+ import { clsx } from 'clsx';
3
+ import { customAlphabet } from 'nanoid';
4
+ import { twMerge } from 'tailwind-merge';
5
+
6
+ function cn(...inputs) {
7
+ return twMerge(clsx(inputs));
8
+ }
9
+ var nanoid = customAlphabet(
10
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
11
+ 7
12
+ );
13
+ function fetcher(input, init) {
14
+ return __async(this, null, function* () {
15
+ const res = yield fetch(input, init);
16
+ if (!res.ok) {
17
+ const json = yield res.json();
18
+ if (json.error) {
19
+ const error = new Error(json.error);
20
+ error.status = res.status;
21
+ throw error;
22
+ } else {
23
+ throw new Error("An unexpected error occurred");
24
+ }
25
+ }
26
+ return res.json();
27
+ });
28
+ }
29
+ function formatDate(input) {
30
+ const date = new Date(input);
31
+ return date.toLocaleDateString("en-US", {
32
+ month: "long",
33
+ day: "numeric",
34
+ year: "numeric"
35
+ });
36
+ }
37
+ var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
38
+ function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
39
+ if (a === null || a === void 0 || b === null || b === void 0) {
40
+ return a === b;
41
+ }
42
+ return naiveEqualityCheck(a, b);
43
+ }
44
+
45
+ export { arraysAreEqual, cn, fetcher, formatDate, nanoid, nullableCompatibleEqualityCheck };
46
+ //# sourceMappingURL=out.js.map
47
+ //# sourceMappingURL=chunk-KGKLUWKW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/utils.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAA6B;AACtC,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAEO,IAAM,SAAS;AAAA,EACpB;AAAA,EACA;AACF;AAEA,SAAsB,QACpB,OACA,MACe;AAAA;AACf,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;AAEO,IAAM,iBAAiB,CAAC,MAAgB,SAC7C,KAAK,WAAW,KAAK,UACrB,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU,KAAK,MAAM;AAE7C,SAAS,gCACd,oBACA,GACA,GACS;AACT,MAAI,MAAM,QAAQ,MAAM,UAAa,MAAM,QAAQ,MAAM,QAAW;AAClE,WAAO,MAAM;AAAA,EACf;AAEA,SAAO,mBAAmB,GAAG,CAAC;AAChC","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { customAlphabet } from \"nanoid\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(\n input: RequestInfo,\n init?: RequestInit\n): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>\n arr1.length === arr2.length &&\n arr1.every((value, index) => value === arr2[index]);\n\nexport function nullableCompatibleEqualityCheck<T>(\n naiveEqualityCheck: (a: T, b: T) => boolean,\n a: T | null | undefined,\n b: T | null | undefined\n): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n return naiveEqualityCheck(a, b);\n}\n"]}
@@ -0,0 +1,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,34 @@
1
+ import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+
4
+ function makeRenderElementFunction(suggestionsStyle) {
5
+ return (props) => {
6
+ switch (props.element.type) {
7
+ case "paragraph":
8
+ return /* @__PURE__ */ jsx(DefaultElement, __spreadValues({}, props));
9
+ case "suggestion":
10
+ return /* @__PURE__ */ jsx(SuggestionElement, __spreadProps(__spreadValues({}, props), {
11
+ suggestionsStyle
12
+ }));
13
+ }
14
+ };
15
+ }
16
+ var DefaultElement = (props) => {
17
+ return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({}, props.attributes), {
18
+ children: props.children
19
+ }));
20
+ };
21
+ var SuggestionElement = (props) => {
22
+ return /* @__PURE__ */ jsxs("span", __spreadProps(__spreadValues({}, props.attributes), {
23
+ style: __spreadValues({}, props.suggestionsStyle),
24
+ contentEditable: false,
25
+ children: [
26
+ props.children,
27
+ props.element.type === "suggestion" && props.element.content
28
+ ]
29
+ }));
30
+ };
31
+
32
+ export { makeRenderElementFunction };
33
+ //# sourceMappingURL=out.js.map
34
+ //# sourceMappingURL=chunk-LNAIMEB2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/render-element.tsx"],"names":[],"mappings":";;;;;;AAUe,cAkBX,YAlBW;AANR,SAAS,0BACd,kBACuB;AACvB,SAAO,CAAC,UAA8B;AACpC,YAAQ,MAAM,QAAQ,MAAM;AAAA,MAC1B,KAAK;AACH,eAAO,oBAAC,mCAAmB,MAAO;AAAA,MACpC,KAAK;AACH,eACE,oBAAC,oDAAsB,QAAtB;AAAA,UAA6B;AAAA,UAAoC;AAAA,IAExE;AAAA,EACF;AACF;AAEA,IAAM,iBAAiB,CAAC,UAA8B;AACpD,SAAO,oBAAC,wCAAQ,MAAM,aAAd;AAAA,IAA2B,gBAAM;AAAA,IAAS;AACpD;AACA,IAAM,oBAAoB,CACxB,UAGG;AACH,SACE,qBAAC,yCACK,MAAM,aADX;AAAA,IAEC,OAAO,mBACF,MAAM;AAAA,IAEX,iBAAiB;AAAA,IAEhB;AAAA,YAAM;AAAA,MACN,MAAM,QAAQ,SAAS,gBAAgB,MAAM,QAAQ;AAAA;AAAA,IACxD;AAEJ","sourcesContent":["import { RenderElementProps } from \"slate-react\";\n\nexport type RenderElementFunction = (props: RenderElementProps) => JSX.Element;\n\nexport function makeRenderElementFunction(\n suggestionsStyle: React.CSSProperties\n): RenderElementFunction {\n return (props: RenderElementProps) => {\n switch (props.element.type) {\n case \"paragraph\":\n return <DefaultElement {...props} />;\n case \"suggestion\":\n return (\n <SuggestionElement {...props} suggestionsStyle={suggestionsStyle} />\n );\n }\n };\n}\n\nconst DefaultElement = (props: RenderElementProps) => {\n return <div {...props.attributes}>{props.children}</div>;\n};\nconst SuggestionElement = (\n props: RenderElementProps & {\n suggestionsStyle: React.CSSProperties;\n }\n) => {\n return (\n <span\n {...props.attributes}\n style={{\n ...props.suggestionsStyle,\n }}\n contentEditable={false}\n >\n {props.children /* https://github.com/ianstormtaylor/slate/issues/3930 */}\n {props.element.type === \"suggestion\" && props.element.content}\n </span>\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":""}
@@ -0,0 +1,59 @@
1
+ import { useEffect } from 'react';
2
+
3
+ // src/components/base-copilot-textarea/use-add-branding-css.tsx
4
+ function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
5
+ const cssSelector = ".copilot-textarea.with-branding";
6
+ useEffect(() => {
7
+ if (disableBranding) {
8
+ return;
9
+ }
10
+ const styleEl = document.createElement("style");
11
+ styleEl.id = "dynamic-styles";
12
+ let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
13
+ const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
14
+ return `${kebabCaseKey}: ${value};`;
15
+ }).join(" ");
16
+ dynamicStyles += `font-style: normal; font-size: x-small;`;
17
+ dynamicStyles += `content: "CopilotKit";`;
18
+ dynamicStyles += `bottom: 6px;`;
19
+ dynamicStyles += `right: 6px;`;
20
+ dynamicStyles += `pointer-events: none;`;
21
+ dynamicStyles += `font-weight: 200;`;
22
+ dynamicStyles += `padding: 0;`;
23
+ dynamicStyles += `margin: 0;`;
24
+ dynamicStyles += `border: 0;`;
25
+ dynamicStyles += `line-height: 1;`;
26
+ dynamicStyles += `position: absolute;`;
27
+ styleEl.innerHTML = `
28
+ ${cssSelector}::after {
29
+ ${dynamicStyles}
30
+ }
31
+ `;
32
+ document.head.appendChild(styleEl);
33
+ const textarea = document.querySelector(cssSelector);
34
+ const handleScroll = () => {
35
+ const styleEl2 = document.getElementById("dynamic-styles");
36
+ if (styleEl2 && textarea) {
37
+ const offsetFromBottom = -textarea.scrollTop + 6;
38
+ const offsetFromRight = -textarea.scrollLeft + 6;
39
+ styleEl2.innerHTML = `
40
+ ${cssSelector}::after {
41
+ ${dynamicStyles}
42
+ bottom: ${offsetFromBottom}px;
43
+ right: ${offsetFromRight}px;
44
+ }
45
+ `;
46
+ }
47
+ };
48
+ textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
49
+ return () => {
50
+ var _a;
51
+ (_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
52
+ textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
53
+ };
54
+ }, [disableBranding, suggestionStyleAugmented]);
55
+ }
56
+
57
+ export { useAddBrandingCss };
58
+ //# sourceMappingURL=out.js.map
59
+ //# sourceMappingURL=chunk-MPME5BW2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/use-add-branding-css.tsx"],"names":["styleEl"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,SAAS,kBACd,0BACA,iBACA;AACA,QAAM,cAAc;AACpB,YAAU,MAAM;AACd,QAAI,iBAAiB;AACnB;AAAA,IACF;AAIA,UAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,YAAQ,KAAK;AAGb,QAAI,gBAAgB,OAAO,QAAQ,wBAAwB,EACxD,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,YAAM,eAAe,IAClB,QAAQ,gCAAgC,OAAO,EAC/C,YAAY;AACf,aAAO,GAAG,iBAAiB;AAAA,IAC7B,CAAC,EACA,KAAK,GAAG;AAGX,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AAGjB,YAAQ,YAAY;AAAA,QAChB;AAAA,UACE;AAAA;AAAA;AAIN,aAAS,KAAK,YAAY,OAAO;AAIjC,UAAM,WAAW,SAAS,cAAc,WAAW;AACnD,UAAM,eAAe,MAAM;AACzB,YAAMA,WAAU,SAAS,eAAe,gBAAgB;AACxD,UAAIA,YAAW,UAAU;AACvB,cAAM,mBAAmB,CAAC,SAAS,YAAY;AAC/C,cAAM,kBAAkB,CAAC,SAAS,aAAa;AAC/C,QAAAA,SAAQ,YAAY;AAAA,YAChB;AAAA,cACE;AAAA,sBACQ;AAAA,qBACD;AAAA;AAAA;AAAA,MAGf;AAAA,IACF;AAEA,yCAAU,iBAAiB,UAAU;AAGrC,WAAO,MAAM;AAtEjB;AAuEM,qBAAS,eAAe,gBAAgB,MAAxC,mBAA2C;AAC3C,2CAAU,oBAAoB,UAAU;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,iBAAiB,wBAAwB,CAAC;AAChD","sourcesContent":["import { useEffect } from \"react\";\n\nexport function useAddBrandingCss(\n suggestionStyleAugmented: React.CSSProperties,\n disableBranding: boolean | undefined\n) {\n const cssSelector = \".copilot-textarea.with-branding\";\n useEffect(() => {\n if (disableBranding) {\n return;\n }\n\n // ---\n // 1: Add the CSS to the DOM\n const styleEl = document.createElement(\"style\");\n styleEl.id = \"dynamic-styles\";\n\n // Build the CSS string dynamically\n let dynamicStyles = Object.entries(suggestionStyleAugmented)\n .map(([key, value]) => {\n const kebabCaseKey = key\n .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, \"$1-$2\")\n .toLowerCase();\n return `${kebabCaseKey}: ${value};`;\n })\n .join(\" \");\n\n // Append overrides for italics and font-size\n dynamicStyles += `font-style: normal; font-size: x-small;`;\n dynamicStyles += `content: \"CopilotKit\";`;\n dynamicStyles += `bottom: 6px;`;\n dynamicStyles += `right: 6px;`;\n dynamicStyles += `pointer-events: none;`;\n dynamicStyles += `font-weight: 200;`;\n dynamicStyles += `padding: 0;`;\n dynamicStyles += `margin: 0;`;\n dynamicStyles += `border: 0;`;\n dynamicStyles += `line-height: 1;`;\n dynamicStyles += `position: absolute;`;\n\n // Append it to the ::after class\n styleEl.innerHTML = `\n ${cssSelector}::after {\n ${dynamicStyles}\n }\n `;\n\n document.head.appendChild(styleEl);\n\n // ---\n // 2: Add the scroll listener (to keep the branding in the bottom right as the textarea scrolls)\n const textarea = document.querySelector(cssSelector);\n const handleScroll = () => {\n const styleEl = document.getElementById(\"dynamic-styles\");\n if (styleEl && textarea) {\n const offsetFromBottom = -textarea.scrollTop + 6;\n const offsetFromRight = -textarea.scrollLeft + 6;\n styleEl.innerHTML = `\n ${cssSelector}::after {\n ${dynamicStyles}\n bottom: ${offsetFromBottom}px;\n right: ${offsetFromRight}px;\n }\n `;\n }\n };\n\n textarea?.addEventListener(\"scroll\", handleScroll);\n\n // Cleanup\n return () => {\n document.getElementById(\"dynamic-styles\")?.remove();\n textarea?.removeEventListener(\"scroll\", handleScroll);\n };\n }, [disableBranding, suggestionStyleAugmented]);\n}\n"]}
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+
53
+ export { __async, __objRest, __spreadProps, __spreadValues };
54
+ //# sourceMappingURL=out.js.map
55
+ //# sourceMappingURL=chunk-MRXNTQOX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -0,0 +1,17 @@
1
+ import { useEffect } from 'react';
2
+
3
+ // src/hooks/misc/use-autosize-textarea.tsx
4
+ var useAutosizeTextArea = (textAreaRef, value) => {
5
+ useEffect(() => {
6
+ if (textAreaRef.current !== null) {
7
+ textAreaRef.current.style.height = "0px";
8
+ const scrollHeight = textAreaRef.current.scrollHeight;
9
+ textAreaRef.current.style.height = scrollHeight + "px";
10
+ }
11
+ }, [textAreaRef, value]);
12
+ };
13
+ var use_autosize_textarea_default = useAutosizeTextArea;
14
+
15
+ export { use_autosize_textarea_default };
16
+ //# sourceMappingURL=out.js.map
17
+ //# sourceMappingURL=chunk-ND5PXTAW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/misc/use-autosize-textarea.tsx"],"names":[],"mappings":";AAAA,SAAyB,iBAAiB;AAG1C,IAAM,sBAAsB,CAC1B,aACA,UACG;AACH,YAAU,MAAM;AACd,QAAI,YAAY,YAAY,MAAM;AAEhC,kBAAY,QAAQ,MAAM,SAAS;AACnC,YAAM,eAAe,YAAY,QAAQ;AAIzC,kBAAY,QAAQ,MAAM,SAAS,eAAe;AAAA,IACpD;AAAA,EACF,GAAG,CAAC,aAAa,KAAK,CAAC;AACzB;AAEA,IAAO,gCAAQ","sourcesContent":["import { Ref, RefObject, useEffect } from \"react\";\n\n// Updates the height of a <textarea> when the value changes.\nconst useAutosizeTextArea = (\n textAreaRef: RefObject<HTMLTextAreaElement>,\n value: string\n) => {\n useEffect(() => {\n if (textAreaRef.current !== null) {\n // We need to reset the height momentarily to get the correct scrollHeight for the textarea\n textAreaRef.current.style.height = \"0px\";\n const scrollHeight = textAreaRef.current.scrollHeight;\n\n // We then set the height directly, outside of the render loop\n // Trying to set this with state or a ref will product an incorrect value.\n textAreaRef.current.style.height = scrollHeight + \"px\";\n }\n }, [textAreaRef, value]);\n};\n\nexport default useAutosizeTextArea;\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-NKW5OU2S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/debouncer.ts"],"names":[],"mappings":";;;;;AAIO,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[]> = (\n ...args: [...T, AbortSignal]\n) => 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"]}