@copilotkit/react-textarea 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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 (447) hide show
  1. package/CHANGELOG.md +4665 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -0
  4. package/dist/chunk-23Q6A46J.mjs +103 -0
  5. package/dist/chunk-23Q6A46J.mjs.map +1 -0
  6. package/dist/chunk-2C7O2EVM.mjs +27 -0
  7. package/dist/chunk-2C7O2EVM.mjs.map +1 -0
  8. package/dist/chunk-2IWVZ4PP.mjs +103 -0
  9. package/dist/chunk-2IWVZ4PP.mjs.map +1 -0
  10. package/dist/chunk-2QDCE7PD.mjs +32 -0
  11. package/dist/chunk-2QDCE7PD.mjs.map +1 -0
  12. package/dist/chunk-3QJOFG3V.mjs +25 -0
  13. package/dist/chunk-3QJOFG3V.mjs.map +1 -0
  14. package/dist/chunk-4NHVQZ67.mjs +108 -0
  15. package/dist/chunk-4NHVQZ67.mjs.map +1 -0
  16. package/dist/chunk-4PDYALMP.mjs +52 -0
  17. package/dist/chunk-4PDYALMP.mjs.map +1 -0
  18. package/dist/chunk-5GYFXESG.mjs +31 -0
  19. package/dist/chunk-5GYFXESG.mjs.map +1 -0
  20. package/dist/chunk-5UNJXFUO.mjs +29 -0
  21. package/dist/chunk-5UNJXFUO.mjs.map +1 -0
  22. package/dist/chunk-63LEUA5A.mjs +269 -0
  23. package/dist/chunk-63LEUA5A.mjs.map +1 -0
  24. package/dist/chunk-65XYKSXZ.mjs +226 -0
  25. package/dist/chunk-65XYKSXZ.mjs.map +1 -0
  26. package/dist/chunk-6SGWO63I.mjs +32 -0
  27. package/dist/chunk-6SGWO63I.mjs.map +1 -0
  28. package/dist/chunk-7LSRNPNI.mjs +59 -0
  29. package/dist/chunk-7LSRNPNI.mjs.map +1 -0
  30. package/dist/chunk-AJ5OMEXM.mjs +13 -0
  31. package/dist/chunk-AJ5OMEXM.mjs.map +1 -0
  32. package/dist/chunk-D47EKHIF.mjs +26 -0
  33. package/dist/chunk-D47EKHIF.mjs.map +1 -0
  34. package/dist/chunk-DE5K76I2.mjs +1 -0
  35. package/dist/chunk-DE5K76I2.mjs.map +1 -0
  36. package/dist/chunk-DFTV4TST.mjs +36 -0
  37. package/dist/chunk-DFTV4TST.mjs.map +1 -0
  38. package/dist/chunk-DL3JWL2E.mjs +170 -0
  39. package/dist/chunk-DL3JWL2E.mjs.map +1 -0
  40. package/dist/chunk-DRV2FOHZ.mjs +70 -0
  41. package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
  42. package/dist/chunk-ECR45NSD.mjs +104 -0
  43. package/dist/chunk-ECR45NSD.mjs.map +1 -0
  44. package/dist/chunk-EJGGLWWR.mjs +82 -0
  45. package/dist/chunk-EJGGLWWR.mjs.map +1 -0
  46. package/dist/chunk-F2ULK22F.mjs +39 -0
  47. package/dist/chunk-F2ULK22F.mjs.map +1 -0
  48. package/dist/chunk-F6RLSVG3.mjs +30 -0
  49. package/dist/chunk-F6RLSVG3.mjs.map +1 -0
  50. package/dist/chunk-GQN2HYFJ.mjs +22 -0
  51. package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
  52. package/dist/chunk-H4VKQGVU.mjs +1 -0
  53. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  54. package/dist/chunk-I72DKFHD.mjs +114 -0
  55. package/dist/chunk-I72DKFHD.mjs.map +1 -0
  56. package/dist/chunk-IU3WTXLQ.mjs +1 -0
  57. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  58. package/dist/chunk-JLOABKLH.mjs +49 -0
  59. package/dist/chunk-JLOABKLH.mjs.map +1 -0
  60. package/dist/chunk-KMVGEY7Q.mjs +51 -0
  61. package/dist/chunk-KMVGEY7Q.mjs.map +1 -0
  62. package/dist/chunk-KNQIEOFP.mjs +19 -0
  63. package/dist/chunk-KNQIEOFP.mjs.map +1 -0
  64. package/dist/chunk-L7VVZH4Q.mjs +1 -0
  65. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  66. package/dist/chunk-LYB4B6MK.mjs +19 -0
  67. package/dist/chunk-LYB4B6MK.mjs.map +1 -0
  68. package/dist/chunk-MCNXIA4Q.mjs +75 -0
  69. package/dist/chunk-MCNXIA4Q.mjs.map +1 -0
  70. package/dist/chunk-MMVDU6DF.mjs +1 -0
  71. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  72. package/dist/chunk-MRXNTQOX.mjs +59 -0
  73. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  74. package/dist/chunk-NAFNY4FL.mjs +17 -0
  75. package/dist/chunk-NAFNY4FL.mjs.map +1 -0
  76. package/dist/chunk-QFXR6DOA.mjs +64 -0
  77. package/dist/chunk-QFXR6DOA.mjs.map +1 -0
  78. package/dist/chunk-QJNFNPWH.mjs +85 -0
  79. package/dist/chunk-QJNFNPWH.mjs.map +1 -0
  80. package/dist/chunk-RUV6NBIF.mjs +1 -0
  81. package/dist/chunk-RUV6NBIF.mjs.map +1 -0
  82. package/dist/chunk-T4HVUB4T.mjs +60 -0
  83. package/dist/chunk-T4HVUB4T.mjs.map +1 -0
  84. package/dist/chunk-T6MTDQZ7.mjs +45 -0
  85. package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
  86. package/dist/chunk-VSVQZUPW.mjs +124 -0
  87. package/dist/chunk-VSVQZUPW.mjs.map +1 -0
  88. package/dist/chunk-WADHCMPK.mjs +1 -0
  89. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  90. package/dist/chunk-WGWQRALG.mjs +83 -0
  91. package/dist/chunk-WGWQRALG.mjs.map +1 -0
  92. package/dist/chunk-WJHSY5T6.mjs +1 -0
  93. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  94. package/dist/chunk-X2QR2YGZ.mjs +120 -0
  95. package/dist/chunk-X2QR2YGZ.mjs.map +1 -0
  96. package/dist/chunk-YLFAIYRY.mjs +50 -0
  97. package/dist/chunk-YLFAIYRY.mjs.map +1 -0
  98. package/dist/chunk-ZQSEYPNN.mjs +74 -0
  99. package/dist/chunk-ZQSEYPNN.mjs.map +1 -0
  100. package/dist/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
  101. package/dist/components/base-copilot-textarea/base-copilot-textarea.css.map +1 -0
  102. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +43 -0
  103. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1781 -0
  104. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
  105. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +40 -0
  106. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -0
  107. package/dist/components/base-copilot-textarea/render-element.d.ts +7 -0
  108. package/dist/components/base-copilot-textarea/render-element.js +75 -0
  109. package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
  110. package/dist/components/base-copilot-textarea/render-element.mjs +8 -0
  111. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -0
  112. package/dist/components/base-copilot-textarea/render-placeholder.d.ts +7 -0
  113. package/dist/components/base-copilot-textarea/render-placeholder.js +72 -0
  114. package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
  115. package/dist/components/base-copilot-textarea/render-placeholder.mjs +8 -0
  116. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -0
  117. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +8 -0
  118. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +112 -0
  119. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
  120. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +9 -0
  121. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -0
  122. package/dist/components/base-copilot-textarea/use-add-branding-css.d.ts +3 -0
  123. package/dist/components/base-copilot-textarea/use-add-branding-css.js +83 -0
  124. package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
  125. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +8 -0
  126. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -0
  127. package/dist/components/copilot-textarea/copilot-textarea.css +9 -0
  128. package/dist/components/copilot-textarea/copilot-textarea.css.map +1 -0
  129. package/dist/components/copilot-textarea/copilot-textarea.d.ts +171 -0
  130. package/dist/components/copilot-textarea/copilot-textarea.js +2261 -0
  131. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
  132. package/dist/components/copilot-textarea/copilot-textarea.mjs +49 -0
  133. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -0
  134. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +18 -0
  135. package/dist/components/hovering-toolbar/hovering-editor-provider.js +44 -0
  136. package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
  137. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +10 -0
  138. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -0
  139. package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
  140. package/dist/components/hovering-toolbar/hovering-toolbar-components.js +164 -0
  141. package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
  142. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +16 -0
  143. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -0
  144. package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +12 -0
  145. package/dist/components/hovering-toolbar/hovering-toolbar.js +894 -0
  146. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
  147. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +23 -0
  148. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -0
  149. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +16 -0
  150. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +603 -0
  151. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
  152. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +18 -0
  153. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -0
  154. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +13 -0
  155. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +626 -0
  156. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
  157. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +19 -0
  158. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -0
  159. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +16 -0
  160. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +133 -0
  161. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
  162. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +12 -0
  163. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -0
  164. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +4 -0
  165. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +626 -0
  166. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
  167. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +20 -0
  168. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -0
  169. package/dist/components/index.css +9 -0
  170. package/dist/components/index.css.map +1 -0
  171. package/dist/components/index.d.ts +15 -0
  172. package/dist/components/index.js +2265 -0
  173. package/dist/components/index.js.map +1 -0
  174. package/dist/components/index.mjs +53 -0
  175. package/dist/components/index.mjs.map +1 -0
  176. package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
  177. package/dist/components/manual-ui/chip-with-icon.js +38 -0
  178. package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
  179. package/dist/components/manual-ui/chip-with-icon.mjs +15 -0
  180. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -0
  181. package/dist/components/source-search-box/source-search-box.d.ts +16 -0
  182. package/dist/components/source-search-box/source-search-box.js +240 -0
  183. package/dist/components/source-search-box/source-search-box.js.map +1 -0
  184. package/dist/components/source-search-box/source-search-box.mjs +13 -0
  185. package/dist/components/source-search-box/source-search-box.mjs.map +1 -0
  186. package/dist/components/ui/button.d.ts +14 -0
  187. package/dist/components/ui/button.js +114 -0
  188. package/dist/components/ui/button.js.map +1 -0
  189. package/dist/components/ui/button.mjs +11 -0
  190. package/dist/components/ui/button.mjs.map +1 -0
  191. package/dist/components/ui/command.d.ts +53 -0
  192. package/dist/components/ui/command.js +285 -0
  193. package/dist/components/ui/command.js.map +1 -0
  194. package/dist/components/ui/command.mjs +26 -0
  195. package/dist/components/ui/command.mjs.map +1 -0
  196. package/dist/components/ui/dialog.d.ts +19 -0
  197. package/dist/components/ui/dialog.js +183 -0
  198. package/dist/components/ui/dialog.js.map +1 -0
  199. package/dist/components/ui/dialog.mjs +21 -0
  200. package/dist/components/ui/dialog.mjs.map +1 -0
  201. package/dist/components/ui/label.d.ts +8 -0
  202. package/dist/components/ui/label.js +87 -0
  203. package/dist/components/ui/label.js.map +1 -0
  204. package/dist/components/ui/label.mjs +9 -0
  205. package/dist/components/ui/label.mjs.map +1 -0
  206. package/dist/context/index.d.ts +2 -0
  207. package/dist/context/index.js +19 -0
  208. package/dist/context/index.js.map +1 -0
  209. package/dist/context/index.mjs +2 -0
  210. package/dist/context/index.mjs.map +1 -0
  211. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +15 -0
  212. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +180 -0
  213. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
  214. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +11 -0
  215. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -0
  216. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.ts +8 -0
  217. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +194 -0
  218. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
  219. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +9 -0
  220. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -0
  221. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +7 -0
  222. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +180 -0
  223. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
  224. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +10 -0
  225. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -0
  226. package/dist/hooks/index.d.ts +2 -0
  227. package/dist/hooks/index.js +19 -0
  228. package/dist/hooks/index.js.map +1 -0
  229. package/dist/hooks/index.mjs +2 -0
  230. package/dist/hooks/index.mjs.map +1 -0
  231. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +22 -0
  232. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +137 -0
  233. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
  234. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +9 -0
  235. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -0
  236. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +23 -0
  237. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +230 -0
  238. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
  239. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +9 -0
  240. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -0
  241. package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
  242. package/dist/hooks/misc/use-autosize-textarea.js +37 -0
  243. package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
  244. package/dist/hooks/misc/use-autosize-textarea.mjs +8 -0
  245. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -0
  246. package/dist/index.css +643 -0
  247. package/dist/index.css.map +1 -0
  248. package/dist/index.d.ts +15 -0
  249. package/dist/index.js +2270 -0
  250. package/dist/index.js.map +1 -0
  251. package/dist/index.mjs +64 -0
  252. package/dist/index.mjs.map +1 -0
  253. package/dist/lib/debouncer.d.ts +11 -0
  254. package/dist/lib/debouncer.js +76 -0
  255. package/dist/lib/debouncer.js.map +1 -0
  256. package/dist/lib/debouncer.mjs +8 -0
  257. package/dist/lib/debouncer.mjs.map +1 -0
  258. package/dist/lib/editor-to-text.d.ts +7 -0
  259. package/dist/lib/editor-to-text.js +69 -0
  260. package/dist/lib/editor-to-text.js.map +1 -0
  261. package/dist/lib/editor-to-text.mjs +8 -0
  262. package/dist/lib/editor-to-text.mjs.map +1 -0
  263. package/dist/lib/get-text-around-cursor.d.ts +15 -0
  264. package/dist/lib/get-text-around-cursor.js +131 -0
  265. package/dist/lib/get-text-around-cursor.js.map +1 -0
  266. package/dist/lib/get-text-around-cursor.mjs +14 -0
  267. package/dist/lib/get-text-around-cursor.mjs.map +1 -0
  268. package/dist/lib/retry.d.ts +3 -0
  269. package/dist/lib/retry.js +43 -0
  270. package/dist/lib/retry.js.map +1 -0
  271. package/dist/lib/retry.mjs +8 -0
  272. package/dist/lib/retry.mjs.map +1 -0
  273. package/dist/lib/slatejs-edits/add-autocompletions.d.ts +8 -0
  274. package/dist/lib/slatejs-edits/add-autocompletions.js +51 -0
  275. package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
  276. package/dist/lib/slatejs-edits/add-autocompletions.mjs +8 -0
  277. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -0
  278. package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +8 -0
  279. package/dist/lib/slatejs-edits/clear-autocompletions.js +46 -0
  280. package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
  281. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +8 -0
  282. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -0
  283. package/dist/lib/slatejs-edits/replace-text.d.ts +5 -0
  284. package/dist/lib/slatejs-edits/replace-text.js +53 -0
  285. package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
  286. package/dist/lib/slatejs-edits/replace-text.mjs +8 -0
  287. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -0
  288. package/dist/lib/slatejs-edits/with-partial-history.d.ts +8 -0
  289. package/dist/lib/slatejs-edits/with-partial-history.js +133 -0
  290. package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
  291. package/dist/lib/slatejs-edits/with-partial-history.mjs +10 -0
  292. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -0
  293. package/dist/lib/stream-promise-flatten.d.ts +12 -0
  294. package/dist/lib/stream-promise-flatten.js +72 -0
  295. package/dist/lib/stream-promise-flatten.js.map +1 -0
  296. package/dist/lib/stream-promise-flatten.mjs +8 -0
  297. package/dist/lib/stream-promise-flatten.mjs.map +1 -0
  298. package/dist/lib/utils.d.ts +9 -0
  299. package/dist/lib/utils.js +94 -0
  300. package/dist/lib/utils.js.map +1 -0
  301. package/dist/lib/utils.mjs +16 -0
  302. package/dist/lib/utils.mjs.map +1 -0
  303. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +23 -0
  304. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +19 -0
  305. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
  306. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +1 -0
  307. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -0
  308. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +20 -0
  309. package/dist/types/autosuggestions-config/autosuggestions-config.js +287 -0
  310. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
  311. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +13 -0
  312. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -0
  313. package/dist/types/autosuggestions-config/editing-api-config.d.ts +15 -0
  314. package/dist/types/autosuggestions-config/editing-api-config.js +108 -0
  315. package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
  316. package/dist/types/autosuggestions-config/editing-api-config.mjs +12 -0
  317. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -0
  318. package/dist/types/autosuggestions-config/index.d.ts +10 -0
  319. package/dist/types/autosuggestions-config/index.js +287 -0
  320. package/dist/types/autosuggestions-config/index.js.map +1 -0
  321. package/dist/types/autosuggestions-config/index.mjs +14 -0
  322. package/dist/types/autosuggestions-config/index.mjs.map +1 -0
  323. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +15 -0
  324. package/dist/types/autosuggestions-config/insertions-api-config.js +101 -0
  325. package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
  326. package/dist/types/autosuggestions-config/insertions-api-config.mjs +12 -0
  327. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -0
  328. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
  329. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +19 -0
  330. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
  331. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +1 -0
  332. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -0
  333. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +15 -0
  334. package/dist/types/autosuggestions-config/suggestions-api-config.js +90 -0
  335. package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
  336. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +12 -0
  337. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -0
  338. package/dist/types/base/autosuggestion-state.d.ts +8 -0
  339. package/dist/types/base/autosuggestion-state.js +19 -0
  340. package/dist/types/base/autosuggestion-state.js.map +1 -0
  341. package/dist/types/base/autosuggestion-state.mjs +1 -0
  342. package/dist/types/base/autosuggestion-state.mjs.map +1 -0
  343. package/dist/types/base/autosuggestions-bare-function.d.ts +19 -0
  344. package/dist/types/base/autosuggestions-bare-function.js +19 -0
  345. package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
  346. package/dist/types/base/autosuggestions-bare-function.mjs +1 -0
  347. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -0
  348. package/dist/types/base/base-autosuggestions-config.d.ts +87 -0
  349. package/dist/types/base/base-autosuggestions-config.js +54 -0
  350. package/dist/types/base/base-autosuggestions-config.js.map +1 -0
  351. package/dist/types/base/base-autosuggestions-config.mjs +8 -0
  352. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -0
  353. package/dist/types/base/base-copilot-textarea-props.d.ts +5 -0
  354. package/dist/types/base/base-copilot-textarea-props.js +19 -0
  355. package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
  356. package/dist/types/base/base-copilot-textarea-props.mjs +1 -0
  357. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -0
  358. package/dist/types/base/custom-editor.d.ts +29 -0
  359. package/dist/types/base/custom-editor.js +19 -0
  360. package/dist/types/base/custom-editor.js.map +1 -0
  361. package/dist/types/base/custom-editor.mjs +1 -0
  362. package/dist/types/base/custom-editor.mjs.map +1 -0
  363. package/dist/types/base/editor-autocomplete-state.d.ts +10 -0
  364. package/dist/types/base/editor-autocomplete-state.js +40 -0
  365. package/dist/types/base/editor-autocomplete-state.js.map +1 -0
  366. package/dist/types/base/editor-autocomplete-state.mjs +9 -0
  367. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -0
  368. package/dist/types/base/index.d.ts +54 -0
  369. package/dist/types/base/index.js +56 -0
  370. package/dist/types/base/index.js.map +1 -0
  371. package/dist/types/base/index.mjs +9 -0
  372. package/dist/types/base/index.mjs.map +1 -0
  373. package/dist/types/html-copilot-textarea-element.d.ts +7 -0
  374. package/dist/types/html-copilot-textarea-element.js +19 -0
  375. package/dist/types/html-copilot-textarea-element.js.map +1 -0
  376. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  377. package/dist/types/html-copilot-textarea-element.mjs.map +1 -0
  378. package/dist/types/index.d.ts +13 -0
  379. package/dist/types/index.js +289 -0
  380. package/dist/types/index.js.map +1 -0
  381. package/dist/types/index.mjs +19 -0
  382. package/dist/types/index.mjs.map +1 -0
  383. package/jest.config.js +5 -0
  384. package/package.json +99 -0
  385. package/postcss.config.js +12 -0
  386. package/src/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
  387. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +323 -0
  388. package/src/components/base-copilot-textarea/render-element.tsx +40 -0
  389. package/src/components/base-copilot-textarea/render-placeholder.tsx +24 -0
  390. package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +80 -0
  391. package/src/components/base-copilot-textarea/use-add-branding-css.tsx +74 -0
  392. package/src/components/copilot-textarea/copilot-textarea.tsx +210 -0
  393. package/src/components/hovering-toolbar/hovering-editor-provider.tsx +31 -0
  394. package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +88 -0
  395. package/src/components/hovering-toolbar/hovering-toolbar.tsx +154 -0
  396. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +273 -0
  397. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +30 -0
  398. package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +55 -0
  399. package/src/components/hovering-toolbar/text-insertion-prompt-box/index.ts +2 -0
  400. package/src/components/index.ts +4 -0
  401. package/src/components/manual-ui/chip-with-icon.tsx +17 -0
  402. package/src/components/source-search-box/source-search-box.tsx +117 -0
  403. package/src/components/ui/button.tsx +49 -0
  404. package/src/components/ui/command.tsx +141 -0
  405. package/src/components/ui/dialog.tsx +107 -0
  406. package/src/components/ui/label.tsx +19 -0
  407. package/src/context/index.ts +1 -0
  408. package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +142 -0
  409. package/src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx +100 -0
  410. package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +93 -0
  411. package/src/hooks/index.ts +1 -0
  412. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +116 -0
  413. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +215 -0
  414. package/src/hooks/misc/use-autosize-textarea.tsx +18 -0
  415. package/src/index.tsx +7 -0
  416. package/src/lib/debouncer.ts +36 -0
  417. package/src/lib/editor-to-text.ts +61 -0
  418. package/src/lib/get-text-around-cursor.ts +135 -0
  419. package/src/lib/retry.tsx +23 -0
  420. package/src/lib/slatejs-edits/add-autocompletions.ts +30 -0
  421. package/src/lib/slatejs-edits/clear-autocompletions.ts +19 -0
  422. package/src/lib/slatejs-edits/replace-text.ts +28 -0
  423. package/src/lib/slatejs-edits/with-partial-history.ts +149 -0
  424. package/src/lib/stream-promise-flatten.ts +33 -0
  425. package/src/lib/utils.test.ts +7 -0
  426. package/src/lib/utils.ts +49 -0
  427. package/src/styles.css +3 -0
  428. package/src/types/autosuggestions-config/autosuggestions-config-user-specified.tsx +19 -0
  429. package/src/types/autosuggestions-config/autosuggestions-config.tsx +30 -0
  430. package/src/types/autosuggestions-config/editing-api-config.tsx +96 -0
  431. package/src/types/autosuggestions-config/index.ts +8 -0
  432. package/src/types/autosuggestions-config/insertions-api-config.tsx +87 -0
  433. package/src/types/autosuggestions-config/subtypes/make-system-prompt.ts +1 -0
  434. package/src/types/autosuggestions-config/suggestions-api-config.tsx +76 -0
  435. package/src/types/base/autosuggestion-state.ts +6 -0
  436. package/src/types/base/autosuggestions-bare-function.ts +30 -0
  437. package/src/types/base/base-autosuggestions-config.tsx +128 -0
  438. package/src/types/base/base-copilot-textarea-props.tsx +58 -0
  439. package/src/types/base/custom-editor.tsx +29 -0
  440. package/src/types/base/editor-autocomplete-state.ts +20 -0
  441. package/src/types/base/index.ts +6 -0
  442. package/src/types/html-copilot-textarea-element.ts +5 -0
  443. package/src/types/index.ts +3 -0
  444. package/tailwind.config.js +9 -0
  445. package/tsconfig.json +12 -0
  446. package/tsup.config.ts +11 -0
  447. package/typedoc.json +4 -0
@@ -0,0 +1,215 @@
1
+ import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
2
+ import { useCopilotContext } from "@copilotkit/react-core";
3
+ import { useCallback } from "react";
4
+ import {
5
+ CopilotRuntimeClient,
6
+ Message,
7
+ Role,
8
+ TextMessage,
9
+ convertGqlOutputToMessages,
10
+ convertMessagesToGqlInput,
11
+ filterAgentStateMessages,
12
+ CopilotRequestType,
13
+ } from "@copilotkit/runtime-client-gql";
14
+ import { retry } from "../../lib/retry";
15
+ import {
16
+ EditingEditorState,
17
+ Generator_InsertionOrEditingSuggestion,
18
+ } from "../../types/base/autosuggestions-bare-function";
19
+ import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
20
+ import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
21
+ import { DocumentPointer } from "@copilotkit/react-core";
22
+
23
+ /**
24
+ * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
25
+ * The function takes in the text before and after the cursor, and an abort signal.
26
+ * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
27
+ * The function returns the suggestion from the API response.
28
+ *
29
+ * @param textareaPurpose - The purpose of the textarea. This is included in the system message.
30
+ * @param apiEndpoint - The API endpoint to send the autosuggestion request to.
31
+ * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
32
+ * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
33
+ * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
34
+ * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
35
+ */
36
+ export function useMakeStandardInsertionOrEditingFunction(
37
+ textareaPurpose: string,
38
+ contextCategories: string[],
39
+ insertionApiConfig: InsertionsApiConfig,
40
+ editingApiConfig: EditingApiConfig,
41
+ ): Generator_InsertionOrEditingSuggestion {
42
+ const runtimeClient: any = { generateCopilotResponse: (...args: any[]) => {} };
43
+ const { getContextString, copilotApiConfig } = useCopilotContext();
44
+ const headers = {
45
+ ...(copilotApiConfig.publicApiKey
46
+ ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }
47
+ : {}),
48
+ };
49
+
50
+ async function runtimeClientResponseToStringStream(
51
+ responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,
52
+ ) {
53
+ const messagesStream = runtimeClient.asStream(responsePromise);
54
+
55
+ return new ReadableStream({
56
+ async start(controller) {
57
+ const reader = messagesStream.getReader();
58
+ let sentContent = "";
59
+
60
+ while (true) {
61
+ const { done, value } = await reader.read();
62
+ if (done) {
63
+ break;
64
+ }
65
+
66
+ const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
67
+
68
+ let newContent = "";
69
+
70
+ for (const message of messages) {
71
+ if (message.isTextMessage()) {
72
+ newContent += message.content;
73
+ }
74
+ }
75
+ if (newContent) {
76
+ const contentToSend = newContent.slice(sentContent.length);
77
+ controller.enqueue(contentToSend);
78
+ sentContent += contentToSend;
79
+ }
80
+ }
81
+ controller.close();
82
+ },
83
+ });
84
+ }
85
+
86
+ const insertionFunction = useCallback(
87
+ async (
88
+ editorState: EditingEditorState,
89
+ insertionPrompt: string,
90
+ documents: DocumentPointer[],
91
+ abortSignal: AbortSignal,
92
+ ) => {
93
+ const res = await retry(async () => {
94
+ const messages: Message[] = [
95
+ new TextMessage({
96
+ role: Role.System,
97
+ content: insertionApiConfig.makeSystemPrompt(
98
+ textareaPurpose,
99
+ getContextString(documents, contextCategories),
100
+ ),
101
+ }),
102
+ ...insertionApiConfig.fewShotMessages,
103
+ new TextMessage({
104
+ role: Role.User,
105
+ content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
106
+ }),
107
+ new TextMessage({
108
+ role: Role.User,
109
+ content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
110
+ }),
111
+ new TextMessage({
112
+ role: Role.User,
113
+ content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,
114
+ }),
115
+ ];
116
+
117
+ return runtimeClientResponseToStringStream(
118
+ runtimeClient.generateCopilotResponse({
119
+ data: {
120
+ frontend: {
121
+ actions: [],
122
+ url: window.location.href,
123
+ },
124
+ messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
125
+ metadata: {
126
+ requestType: CopilotRequestType.TextareaCompletion,
127
+ },
128
+ },
129
+ properties: copilotApiConfig.properties,
130
+ signal: abortSignal,
131
+ }),
132
+ );
133
+ });
134
+
135
+ return res;
136
+ },
137
+ [insertionApiConfig, getContextString, contextCategories, textareaPurpose],
138
+ );
139
+
140
+ const editingFunction = useCallback(
141
+ async (
142
+ editorState: EditingEditorState,
143
+ editingPrompt: string,
144
+ documents: DocumentPointer[],
145
+ abortSignal: AbortSignal,
146
+ ) => {
147
+ const res = await retry(async () => {
148
+ const messages: Message[] = [
149
+ new TextMessage({
150
+ role: Role.System,
151
+ content: editingApiConfig.makeSystemPrompt(
152
+ textareaPurpose,
153
+ getContextString(documents, contextCategories),
154
+ ),
155
+ }),
156
+ ...editingApiConfig.fewShotMessages,
157
+ new TextMessage({
158
+ role: Role.User,
159
+ content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
160
+ }),
161
+ new TextMessage({
162
+ role: Role.User,
163
+ content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,
164
+ }),
165
+ new TextMessage({
166
+ role: Role.User,
167
+ content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
168
+ }),
169
+ new TextMessage({
170
+ role: Role.User,
171
+ content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,
172
+ }),
173
+ ];
174
+
175
+ return runtimeClientResponseToStringStream(
176
+ runtimeClient.generateCopilotResponse({
177
+ data: {
178
+ frontend: {
179
+ actions: [],
180
+ url: window.location.href,
181
+ },
182
+ messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
183
+ metadata: {
184
+ requestType: CopilotRequestType.TextareaCompletion,
185
+ },
186
+ },
187
+ properties: copilotApiConfig.properties,
188
+ signal: abortSignal,
189
+ }),
190
+ );
191
+ });
192
+
193
+ return res;
194
+ },
195
+ [editingApiConfig, getContextString, contextCategories, textareaPurpose],
196
+ );
197
+
198
+ const insertionOrEditingFunction = useCallback(
199
+ async (
200
+ editorState: EditingEditorState,
201
+ insertionPrompt: string,
202
+ documents: DocumentPointer[],
203
+ abortSignal: AbortSignal,
204
+ ) => {
205
+ if (editorState.selectedText === "") {
206
+ return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);
207
+ } else {
208
+ return await editingFunction(editorState, insertionPrompt, documents, abortSignal);
209
+ }
210
+ },
211
+ [insertionFunction, editingFunction],
212
+ );
213
+
214
+ return insertionOrEditingFunction;
215
+ }
@@ -0,0 +1,18 @@
1
+ import { Ref, RefObject, useEffect } from "react";
2
+
3
+ // Updates the height of a <textarea> when the value changes.
4
+ const useAutosizeTextArea = (textAreaRef: RefObject<HTMLTextAreaElement | null>, value: string) => {
5
+ useEffect(() => {
6
+ if (textAreaRef.current !== null) {
7
+ // We need to reset the height momentarily to get the correct scrollHeight for the textarea
8
+ textAreaRef.current.style.height = "0px";
9
+ const scrollHeight = textAreaRef.current.scrollHeight;
10
+
11
+ // We then set the height directly, outside of the render loop
12
+ // Trying to set this with state or a ref will product an incorrect value.
13
+ textAreaRef.current.style.height = scrollHeight + "px";
14
+ }
15
+ }, [textAreaRef, value]);
16
+ };
17
+
18
+ export default useAutosizeTextArea;
package/src/index.tsx ADDED
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import "./styles.css";
3
+
4
+ export * from "./components";
5
+ export * from "./context";
6
+ export * from "./hooks";
7
+ export * from "./types";
@@ -0,0 +1,36 @@
1
+ export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;
2
+
3
+ export class Debouncer<T extends any[]> {
4
+ private timeoutId?: ReturnType<typeof setTimeout>;
5
+ private activeAbortController?: AbortController;
6
+
7
+ constructor(private wait: number) {}
8
+
9
+ debounce = async (func: AsyncFunction<T>, ...args: T) => {
10
+ // Abort the previous promise immediately
11
+ this.cancel();
12
+
13
+ this.timeoutId = setTimeout(async () => {
14
+ try {
15
+ this.activeAbortController = new AbortController();
16
+
17
+ // Pass the signal to the async function, assuming it supports it
18
+ await func(...args, this.activeAbortController.signal);
19
+
20
+ this.activeAbortController = undefined;
21
+ } catch (error) {}
22
+ }, this.wait);
23
+ };
24
+
25
+ cancel = () => {
26
+ if (this.activeAbortController) {
27
+ this.activeAbortController.abort();
28
+ this.activeAbortController = undefined;
29
+ }
30
+
31
+ if (this.timeoutId !== undefined) {
32
+ clearTimeout(this.timeoutId);
33
+ this.timeoutId = undefined;
34
+ }
35
+ };
36
+ }
@@ -0,0 +1,61 @@
1
+ import { BaseEditor, Descendant, Element } from "slate";
2
+ import { HistoryEditor } from "slate-history";
3
+ import { ReactEditor } from "slate-react";
4
+ import { SuggestionAwareText } from "../types/base/custom-editor";
5
+
6
+ function nodeChildrenToTextComponents(
7
+ editor: BaseEditor & ReactEditor & HistoryEditor,
8
+ nodes: Descendant[],
9
+ ): SuggestionAwareText[] {
10
+ // find inlineable elements
11
+ const indeciesOfInlineElements = new Set(
12
+ nodes
13
+ .map((node, index) => {
14
+ if (Element.isElement(node) && editor.isInline(node)) {
15
+ return index;
16
+ }
17
+ return -1;
18
+ })
19
+ .filter((index) => index !== -1),
20
+ );
21
+
22
+ // ignorable elements = inline elements,
23
+ // or neighbors of inline elements that are {text: ""}
24
+ const nonIgnorableItems = nodes.filter((node, index) => {
25
+ const isInline = indeciesOfInlineElements.has(index);
26
+ if (isInline) {
27
+ return false;
28
+ }
29
+
30
+ const isNeighbourOfInline =
31
+ indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
32
+ if (isNeighbourOfInline) {
33
+ return (node as any).text !== "";
34
+ }
35
+
36
+ return true;
37
+ });
38
+
39
+ return nonIgnorableItems
40
+ .map((node) => {
41
+ if (Element.isElement(node)) {
42
+ switch (node.type) {
43
+ case "paragraph":
44
+ return nodeChildrenToTextComponents(editor, node.children);
45
+ case "suggestion":
46
+ return [];
47
+ }
48
+ } else {
49
+ return [node];
50
+ }
51
+ })
52
+ .reduce((acc, val) => acc.concat(val), []);
53
+ }
54
+
55
+ export const editorToText = (editor: BaseEditor & ReactEditor & HistoryEditor) => {
56
+ const flattened = nodeChildrenToTextComponents(editor, editor.children);
57
+
58
+ const text = flattened.map((textComponent) => textComponent.text).join("\n");
59
+
60
+ return text;
61
+ };
@@ -0,0 +1,135 @@
1
+ import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from "slate";
2
+ import { EditorAutocompleteState } from "../types/base/editor-autocomplete-state";
3
+
4
+ export interface EditorTextState {
5
+ selection: BaseRange;
6
+
7
+ textBeforeCursor: string;
8
+ selectedText: string;
9
+ textAfterCursor: string;
10
+ }
11
+
12
+ export function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {
13
+ const { selection } = editor;
14
+ if (!selection || !Range.isCollapsed(selection)) {
15
+ return null;
16
+ }
17
+
18
+ const cursorPoint = selection.anchor;
19
+
20
+ // Create two ranges: one before the anchor and one after
21
+ const beforeRange: Range = {
22
+ anchor: Editor.start(editor, []),
23
+ focus: cursorPoint,
24
+ };
25
+ const afterRange: Range = {
26
+ anchor: cursorPoint,
27
+ focus: Editor.end(editor, []),
28
+ };
29
+
30
+ // Extract text for these ranges
31
+ const before = extractTextWithNewlines(editor, beforeRange);
32
+ const after = extractTextWithNewlines(editor, afterRange);
33
+
34
+ return {
35
+ cursorPoint: cursorPoint,
36
+ textBeforeCursor: before,
37
+ textAfterCursor: after,
38
+ };
39
+ }
40
+
41
+ export function getTextAroundSelection(editor: Editor): EditorTextState | null {
42
+ const { selection } = editor;
43
+ if (!selection) {
44
+ return null;
45
+ }
46
+
47
+ const wellOrderedSelection = wellOrderedRange(selection);
48
+
49
+ // Create two ranges: one before the anchor and one after
50
+ const beforeRange: Range = {
51
+ anchor: Editor.start(editor, []),
52
+ focus: wellOrderedSelection.anchor,
53
+ };
54
+ const afterRange: Range = {
55
+ anchor: wellOrderedSelection.focus,
56
+ focus: Editor.end(editor, []),
57
+ };
58
+
59
+ // Extract text for these ranges
60
+ const before = extractTextWithNewlines(editor, beforeRange);
61
+ const after = extractTextWithNewlines(editor, afterRange);
62
+ const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
63
+
64
+ return {
65
+ selection: wellOrderedSelection,
66
+ textBeforeCursor: before,
67
+ selectedText,
68
+ textAfterCursor: after,
69
+ };
70
+ }
71
+
72
+ export function getFullEditorTextWithNewlines(editor: Editor): string {
73
+ const fullDocumentRange: Range = {
74
+ anchor: Editor.start(editor, []),
75
+ focus: Editor.end(editor, []),
76
+ };
77
+ return extractTextWithNewlines(editor, fullDocumentRange);
78
+ }
79
+
80
+ // Helper function to extract text with newlines
81
+ export function extractTextWithNewlines(editor: Editor, range: Range): string {
82
+ const voids = false;
83
+ const [start, end] = Range.edges(range);
84
+ let text = "";
85
+ let lastBlock: Node | null = null;
86
+
87
+ for (const [node, path] of Editor.nodes(editor, {
88
+ at: range,
89
+ match: Text.isText,
90
+ voids,
91
+ })) {
92
+ let t = node.text;
93
+
94
+ // Determine the parent block of the current text node
95
+ const [block] = Editor.above(editor, {
96
+ at: path,
97
+ match: (n) => Element.isElement(n) && n.type === "paragraph",
98
+ }) || [null];
99
+
100
+ // If we encounter a new block, prepend a newline
101
+ if (lastBlock !== block && block) {
102
+ // check that lastBlock is not null to avoid adding a newline at the beginning
103
+ if (lastBlock) {
104
+ text += "\n";
105
+ }
106
+ lastBlock = block;
107
+ }
108
+
109
+ if (Path.equals(path, end.path)) {
110
+ t = t.slice(0, end.offset);
111
+ }
112
+
113
+ if (Path.equals(path, start.path)) {
114
+ t = t.slice(start.offset);
115
+ }
116
+
117
+ text += t;
118
+ }
119
+
120
+ return text;
121
+ }
122
+
123
+ function wellOrderedRange(range: BaseRange): BaseRange {
124
+ const { anchor, focus } = range;
125
+ // if anchor is before focus, return range as is
126
+ if (Point.isBefore(anchor, focus)) {
127
+ return range;
128
+ }
129
+
130
+ // if focus is before anchor, return range with anchor and focus swapped
131
+ return {
132
+ anchor: focus,
133
+ focus: anchor,
134
+ };
135
+ }
@@ -0,0 +1,23 @@
1
+ export function retry<T>(
2
+ fn: () => Promise<T>,
3
+ retriesLeft: number = 2,
4
+ interval: number = 200,
5
+ backoff: number = 1.5,
6
+ ): Promise<T> {
7
+ return new Promise((resolve, reject) => {
8
+ fn()
9
+ .then(resolve)
10
+ .catch((error) => {
11
+ if (retriesLeft === 1) {
12
+ reject(error);
13
+ return;
14
+ }
15
+
16
+ setTimeout(() => {
17
+ retry(fn, retriesLeft - 1, interval * backoff, backoff)
18
+ .then(resolve)
19
+ .catch(reject);
20
+ }, interval);
21
+ });
22
+ });
23
+ }
@@ -0,0 +1,30 @@
1
+ import { BasePoint, Transforms } from "slate";
2
+ import { CustomEditor } from "../../types/base/custom-editor";
3
+
4
+ export function addAutocompletionsToEditor(
5
+ editor: CustomEditor,
6
+ newSuggestion: string,
7
+ point: BasePoint,
8
+ ) {
9
+ const editorPosition = editor.selection;
10
+
11
+ Transforms.insertNodes(
12
+ editor,
13
+ [
14
+ {
15
+ type: "suggestion",
16
+ inline: true,
17
+ content: newSuggestion,
18
+ children: [{ text: "" }],
19
+ },
20
+ ],
21
+ {
22
+ at: point,
23
+ },
24
+ );
25
+
26
+ // restore cursor position
27
+ if (editorPosition) {
28
+ editor.selection = editorPosition;
29
+ }
30
+ }
@@ -0,0 +1,19 @@
1
+ import { Element, Node, Path, Transforms } from "slate";
2
+ import { CustomEditor } from "../../types/base/custom-editor";
3
+
4
+ export function clearAutocompletionsFromEditor(editor: CustomEditor) {
5
+ // clear previous suggestion
6
+ const paths: Path[] = [];
7
+ for (const [node, path] of Node.nodes(editor)) {
8
+ if (Element.isElement(node) && node.type === "suggestion") {
9
+ paths.push(path);
10
+ }
11
+ }
12
+ for (const path of paths) {
13
+ try {
14
+ Transforms.removeNodes(editor, { at: path });
15
+ } catch (e) {
16
+ console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,28 @@
1
+ import { Editor, Transforms } from "slate";
2
+
3
+ export function replaceEditorText(editor: Editor, newText: string) {
4
+ // clear all previous text
5
+ Transforms.delete(editor, {
6
+ at: {
7
+ anchor: Editor.start(editor, []),
8
+ focus: Editor.end(editor, []),
9
+ },
10
+ });
11
+
12
+ // insert new text
13
+ if (newText && newText !== "") {
14
+ // don't insert empty text - results in strange visual behavior
15
+ Transforms.insertNodes(
16
+ editor,
17
+ [
18
+ {
19
+ type: "paragraph",
20
+ children: [{ text: newText }],
21
+ },
22
+ ],
23
+ {
24
+ at: [0],
25
+ },
26
+ );
27
+ }
28
+ }