@copilotkit/react-textarea 1.5.9 → 1.5.10

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 (386) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/chunk-23Q6A46J.mjs +103 -0
  3. package/dist/chunk-23Q6A46J.mjs.map +1 -0
  4. package/dist/chunk-2C7O2EVM.mjs +27 -0
  5. package/dist/chunk-2C7O2EVM.mjs.map +1 -0
  6. package/dist/chunk-2QDCE7PD.mjs +32 -0
  7. package/dist/chunk-2QDCE7PD.mjs.map +1 -0
  8. package/dist/chunk-2VMZ5ZWT.mjs +229 -0
  9. package/dist/chunk-2VMZ5ZWT.mjs.map +1 -0
  10. package/dist/chunk-3PQ7GSFE.mjs +17 -0
  11. package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
  12. package/dist/chunk-4CVSOOJY.mjs +30 -0
  13. package/dist/chunk-4CVSOOJY.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-4XXU5BSA.mjs +125 -0
  19. package/dist/chunk-4XXU5BSA.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-7L6GIHDM.mjs +39 -0
  23. package/dist/chunk-7L6GIHDM.mjs.map +1 -0
  24. package/dist/chunk-7LSRNPNI.mjs +59 -0
  25. package/dist/chunk-7LSRNPNI.mjs.map +1 -0
  26. package/dist/chunk-ABYCGF77.mjs +31 -0
  27. package/dist/chunk-ABYCGF77.mjs.map +1 -0
  28. package/dist/chunk-AJ5OMEXM.mjs +13 -0
  29. package/dist/chunk-AJ5OMEXM.mjs.map +1 -0
  30. package/dist/chunk-BNBGJBBM.mjs +60 -0
  31. package/dist/chunk-BNBGJBBM.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-DRV2FOHZ.mjs +70 -0
  39. package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
  40. package/dist/chunk-ECR45NSD.mjs +104 -0
  41. package/dist/chunk-ECR45NSD.mjs.map +1 -0
  42. package/dist/chunk-EJGGLWWR.mjs +82 -0
  43. package/dist/chunk-EJGGLWWR.mjs.map +1 -0
  44. package/dist/chunk-F6GMWOLE.mjs +93 -0
  45. package/dist/chunk-F6GMWOLE.mjs.map +1 -0
  46. package/dist/chunk-GQN2HYFJ.mjs +22 -0
  47. package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
  48. package/dist/chunk-H4VKQGVU.mjs +1 -0
  49. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  50. package/dist/chunk-HDBI2WN5.mjs +113 -0
  51. package/dist/chunk-HDBI2WN5.mjs.map +1 -0
  52. package/dist/chunk-I72DKFHD.mjs +114 -0
  53. package/dist/chunk-I72DKFHD.mjs.map +1 -0
  54. package/dist/chunk-IU3WTXLQ.mjs +1 -0
  55. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  56. package/dist/chunk-KMVGEY7Q.mjs +51 -0
  57. package/dist/chunk-KMVGEY7Q.mjs.map +1 -0
  58. package/dist/chunk-KNQIEOFP.mjs +19 -0
  59. package/dist/chunk-KNQIEOFP.mjs.map +1 -0
  60. package/dist/chunk-L7VVZH4Q.mjs +1 -0
  61. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  62. package/dist/chunk-LQ2OWQU7.mjs +49 -0
  63. package/dist/chunk-LQ2OWQU7.mjs.map +1 -0
  64. package/dist/chunk-LYB4B6MK.mjs +19 -0
  65. package/dist/chunk-LYB4B6MK.mjs.map +1 -0
  66. package/dist/chunk-MCNXIA4Q.mjs +75 -0
  67. package/dist/chunk-MCNXIA4Q.mjs.map +1 -0
  68. package/dist/chunk-MGYT7RNL.mjs +32 -0
  69. package/dist/chunk-MGYT7RNL.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-PZYM7K4Y.mjs +265 -0
  75. package/dist/chunk-PZYM7K4Y.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-RXV67GJN.mjs +168 -0
  83. package/dist/chunk-RXV67GJN.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-XW3ICO4S.mjs +25 -0
  95. package/dist/chunk-XW3ICO4S.mjs.map +1 -0
  96. package/dist/chunk-YLFAIYRY.mjs +50 -0
  97. package/dist/chunk-YLFAIYRY.mjs.map +1 -0
  98. package/dist/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
  99. package/dist/components/base-copilot-textarea/base-copilot-textarea.css.map +1 -0
  100. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +43 -0
  101. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1795 -0
  102. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
  103. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +40 -0
  104. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -0
  105. package/dist/components/base-copilot-textarea/render-element.d.ts +6 -0
  106. package/dist/components/base-copilot-textarea/render-element.js +75 -0
  107. package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
  108. package/dist/components/base-copilot-textarea/render-element.mjs +8 -0
  109. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -0
  110. package/dist/components/base-copilot-textarea/render-placeholder.d.ts +6 -0
  111. package/dist/components/base-copilot-textarea/render-placeholder.js +72 -0
  112. package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
  113. package/dist/components/base-copilot-textarea/render-placeholder.mjs +8 -0
  114. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -0
  115. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +8 -0
  116. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +112 -0
  117. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
  118. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +9 -0
  119. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -0
  120. package/dist/components/base-copilot-textarea/use-add-branding-css.d.ts +3 -0
  121. package/dist/components/base-copilot-textarea/use-add-branding-css.js +83 -0
  122. package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
  123. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +8 -0
  124. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -0
  125. package/dist/components/copilot-textarea/copilot-textarea.css +9 -0
  126. package/dist/components/copilot-textarea/copilot-textarea.css.map +1 -0
  127. package/dist/components/copilot-textarea/copilot-textarea.d.ts +171 -0
  128. package/dist/components/copilot-textarea/copilot-textarea.js +2289 -0
  129. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
  130. package/dist/components/copilot-textarea/copilot-textarea.mjs +49 -0
  131. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -0
  132. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +18 -0
  133. package/dist/components/hovering-toolbar/hovering-editor-provider.js +44 -0
  134. package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
  135. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +10 -0
  136. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -0
  137. package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
  138. package/dist/components/hovering-toolbar/hovering-toolbar-components.js +174 -0
  139. package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
  140. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +16 -0
  141. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -0
  142. package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +12 -0
  143. package/dist/components/hovering-toolbar/hovering-toolbar.js +912 -0
  144. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
  145. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +23 -0
  146. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -0
  147. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +16 -0
  148. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +606 -0
  149. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
  150. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +18 -0
  151. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -0
  152. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +14 -0
  153. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +629 -0
  154. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
  155. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +19 -0
  156. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -0
  157. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +16 -0
  158. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +133 -0
  159. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
  160. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +12 -0
  161. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -0
  162. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +4 -0
  163. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +629 -0
  164. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
  165. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +20 -0
  166. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -0
  167. package/dist/components/index.css +9 -0
  168. package/dist/components/index.css.map +1 -0
  169. package/dist/components/index.d.ts +15 -0
  170. package/dist/components/index.js +2293 -0
  171. package/dist/components/index.js.map +1 -0
  172. package/dist/components/index.mjs +53 -0
  173. package/dist/components/index.mjs.map +1 -0
  174. package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
  175. package/dist/components/manual-ui/chip-with-icon.js +38 -0
  176. package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
  177. package/dist/components/manual-ui/chip-with-icon.mjs +15 -0
  178. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -0
  179. package/dist/components/source-search-box/source-search-box.d.ts +16 -0
  180. package/dist/components/source-search-box/source-search-box.js +240 -0
  181. package/dist/components/source-search-box/source-search-box.js.map +1 -0
  182. package/dist/components/source-search-box/source-search-box.mjs +13 -0
  183. package/dist/components/source-search-box/source-search-box.mjs.map +1 -0
  184. package/dist/components/ui/button.d.ts +14 -0
  185. package/dist/components/ui/button.js +114 -0
  186. package/dist/components/ui/button.js.map +1 -0
  187. package/dist/components/ui/button.mjs +11 -0
  188. package/dist/components/ui/button.mjs.map +1 -0
  189. package/dist/components/ui/command.d.ts +53 -0
  190. package/dist/components/ui/command.js +285 -0
  191. package/dist/components/ui/command.js.map +1 -0
  192. package/dist/components/ui/command.mjs +26 -0
  193. package/dist/components/ui/command.mjs.map +1 -0
  194. package/dist/components/ui/dialog.d.ts +19 -0
  195. package/dist/components/ui/dialog.js +183 -0
  196. package/dist/components/ui/dialog.js.map +1 -0
  197. package/dist/components/ui/dialog.mjs +21 -0
  198. package/dist/components/ui/dialog.mjs.map +1 -0
  199. package/dist/components/ui/label.d.ts +8 -0
  200. package/dist/components/ui/label.js +87 -0
  201. package/dist/components/ui/label.js.map +1 -0
  202. package/dist/components/ui/label.mjs +9 -0
  203. package/dist/components/ui/label.mjs.map +1 -0
  204. package/dist/context/index.d.ts +2 -0
  205. package/dist/context/index.js +19 -0
  206. package/dist/context/index.js.map +1 -0
  207. package/dist/context/index.mjs +2 -0
  208. package/dist/context/index.mjs.map +1 -0
  209. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +15 -0
  210. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +180 -0
  211. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
  212. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +11 -0
  213. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -0
  214. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.ts +8 -0
  215. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +194 -0
  216. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
  217. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +9 -0
  218. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -0
  219. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +7 -0
  220. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +180 -0
  221. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
  222. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +10 -0
  223. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -0
  224. package/dist/hooks/index.d.ts +2 -0
  225. package/dist/hooks/index.js +19 -0
  226. package/dist/hooks/index.js.map +1 -0
  227. package/dist/hooks/index.mjs +2 -0
  228. package/dist/hooks/index.mjs.map +1 -0
  229. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +22 -0
  230. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +153 -0
  231. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
  232. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +9 -0
  233. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -0
  234. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +23 -0
  235. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +228 -0
  236. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
  237. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +9 -0
  238. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -0
  239. package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
  240. package/dist/hooks/misc/use-autosize-textarea.js +37 -0
  241. package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
  242. package/dist/hooks/misc/use-autosize-textarea.mjs +8 -0
  243. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -0
  244. package/dist/index.css +644 -0
  245. package/dist/index.css.map +1 -0
  246. package/dist/index.d.ts +15 -0
  247. package/dist/index.js +2298 -0
  248. package/dist/index.js.map +1 -0
  249. package/dist/index.mjs +64 -0
  250. package/dist/index.mjs.map +1 -0
  251. package/dist/lib/debouncer.d.ts +11 -0
  252. package/dist/lib/debouncer.js +76 -0
  253. package/dist/lib/debouncer.js.map +1 -0
  254. package/dist/lib/debouncer.mjs +8 -0
  255. package/dist/lib/debouncer.mjs.map +1 -0
  256. package/dist/lib/editor-to-text.d.ts +7 -0
  257. package/dist/lib/editor-to-text.js +69 -0
  258. package/dist/lib/editor-to-text.js.map +1 -0
  259. package/dist/lib/editor-to-text.mjs +8 -0
  260. package/dist/lib/editor-to-text.mjs.map +1 -0
  261. package/dist/lib/get-text-around-cursor.d.ts +15 -0
  262. package/dist/lib/get-text-around-cursor.js +131 -0
  263. package/dist/lib/get-text-around-cursor.js.map +1 -0
  264. package/dist/lib/get-text-around-cursor.mjs +14 -0
  265. package/dist/lib/get-text-around-cursor.mjs.map +1 -0
  266. package/dist/lib/retry.d.ts +3 -0
  267. package/dist/lib/retry.js +43 -0
  268. package/dist/lib/retry.js.map +1 -0
  269. package/dist/lib/retry.mjs +8 -0
  270. package/dist/lib/retry.mjs.map +1 -0
  271. package/dist/lib/slatejs-edits/add-autocompletions.d.ts +8 -0
  272. package/dist/lib/slatejs-edits/add-autocompletions.js +51 -0
  273. package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
  274. package/dist/lib/slatejs-edits/add-autocompletions.mjs +8 -0
  275. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -0
  276. package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +8 -0
  277. package/dist/lib/slatejs-edits/clear-autocompletions.js +46 -0
  278. package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
  279. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +8 -0
  280. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -0
  281. package/dist/lib/slatejs-edits/replace-text.d.ts +5 -0
  282. package/dist/lib/slatejs-edits/replace-text.js +53 -0
  283. package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
  284. package/dist/lib/slatejs-edits/replace-text.mjs +8 -0
  285. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -0
  286. package/dist/lib/slatejs-edits/with-partial-history.d.ts +8 -0
  287. package/dist/lib/slatejs-edits/with-partial-history.js +133 -0
  288. package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
  289. package/dist/lib/slatejs-edits/with-partial-history.mjs +10 -0
  290. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -0
  291. package/dist/lib/stream-promise-flatten.d.ts +12 -0
  292. package/dist/lib/stream-promise-flatten.js +72 -0
  293. package/dist/lib/stream-promise-flatten.js.map +1 -0
  294. package/dist/lib/stream-promise-flatten.mjs +8 -0
  295. package/dist/lib/stream-promise-flatten.mjs.map +1 -0
  296. package/dist/lib/utils.d.ts +9 -0
  297. package/dist/lib/utils.js +94 -0
  298. package/dist/lib/utils.js.map +1 -0
  299. package/dist/lib/utils.mjs +16 -0
  300. package/dist/lib/utils.mjs.map +1 -0
  301. package/dist/lib/utils.test.d.ts +2 -0
  302. package/dist/lib/utils.test.js +9 -0
  303. package/dist/lib/utils.test.js.map +1 -0
  304. package/dist/lib/utils.test.mjs +7 -0
  305. package/dist/lib/utils.test.mjs.map +1 -0
  306. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +23 -0
  307. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +19 -0
  308. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
  309. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +1 -0
  310. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -0
  311. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +20 -0
  312. package/dist/types/autosuggestions-config/autosuggestions-config.js +287 -0
  313. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
  314. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +13 -0
  315. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -0
  316. package/dist/types/autosuggestions-config/editing-api-config.d.ts +15 -0
  317. package/dist/types/autosuggestions-config/editing-api-config.js +108 -0
  318. package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
  319. package/dist/types/autosuggestions-config/editing-api-config.mjs +12 -0
  320. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -0
  321. package/dist/types/autosuggestions-config/index.d.ts +10 -0
  322. package/dist/types/autosuggestions-config/index.js +287 -0
  323. package/dist/types/autosuggestions-config/index.js.map +1 -0
  324. package/dist/types/autosuggestions-config/index.mjs +14 -0
  325. package/dist/types/autosuggestions-config/index.mjs.map +1 -0
  326. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +15 -0
  327. package/dist/types/autosuggestions-config/insertions-api-config.js +101 -0
  328. package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
  329. package/dist/types/autosuggestions-config/insertions-api-config.mjs +12 -0
  330. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -0
  331. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
  332. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +19 -0
  333. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
  334. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +1 -0
  335. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -0
  336. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +15 -0
  337. package/dist/types/autosuggestions-config/suggestions-api-config.js +90 -0
  338. package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
  339. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +12 -0
  340. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -0
  341. package/dist/types/base/autosuggestion-state.d.ts +8 -0
  342. package/dist/types/base/autosuggestion-state.js +19 -0
  343. package/dist/types/base/autosuggestion-state.js.map +1 -0
  344. package/dist/types/base/autosuggestion-state.mjs +1 -0
  345. package/dist/types/base/autosuggestion-state.mjs.map +1 -0
  346. package/dist/types/base/autosuggestions-bare-function.d.ts +19 -0
  347. package/dist/types/base/autosuggestions-bare-function.js +19 -0
  348. package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
  349. package/dist/types/base/autosuggestions-bare-function.mjs +1 -0
  350. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -0
  351. package/dist/types/base/base-autosuggestions-config.d.ts +83 -0
  352. package/dist/types/base/base-autosuggestions-config.js +54 -0
  353. package/dist/types/base/base-autosuggestions-config.js.map +1 -0
  354. package/dist/types/base/base-autosuggestions-config.mjs +8 -0
  355. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -0
  356. package/dist/types/base/base-copilot-textarea-props.d.ts +5 -0
  357. package/dist/types/base/base-copilot-textarea-props.js +19 -0
  358. package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
  359. package/dist/types/base/base-copilot-textarea-props.mjs +1 -0
  360. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -0
  361. package/dist/types/base/custom-editor.d.ts +29 -0
  362. package/dist/types/base/custom-editor.js +19 -0
  363. package/dist/types/base/custom-editor.js.map +1 -0
  364. package/dist/types/base/custom-editor.mjs +1 -0
  365. package/dist/types/base/custom-editor.mjs.map +1 -0
  366. package/dist/types/base/editor-autocomplete-state.d.ts +10 -0
  367. package/dist/types/base/editor-autocomplete-state.js +40 -0
  368. package/dist/types/base/editor-autocomplete-state.js.map +1 -0
  369. package/dist/types/base/editor-autocomplete-state.mjs +9 -0
  370. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -0
  371. package/dist/types/base/index.d.ts +54 -0
  372. package/dist/types/base/index.js +56 -0
  373. package/dist/types/base/index.js.map +1 -0
  374. package/dist/types/base/index.mjs +9 -0
  375. package/dist/types/base/index.mjs.map +1 -0
  376. package/dist/types/html-copilot-textarea-element.d.ts +7 -0
  377. package/dist/types/html-copilot-textarea-element.js +19 -0
  378. package/dist/types/html-copilot-textarea-element.js.map +1 -0
  379. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  380. package/dist/types/html-copilot-textarea-element.mjs.map +1 -0
  381. package/dist/types/index.d.ts +13 -0
  382. package/dist/types/index.js +289 -0
  383. package/dist/types/index.js.map +1 -0
  384. package/dist/types/index.mjs +19 -0
  385. package/dist/types/index.mjs.map +1 -0
  386. package/package.json +4 -4
@@ -0,0 +1,1795 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
78
+
79
+ // src/components/base-copilot-textarea/base-copilot-textarea.tsx
80
+ var base_copilot_textarea_exports = {};
81
+ __export(base_copilot_textarea_exports, {
82
+ BaseCopilotTextarea: () => BaseCopilotTextarea
83
+ });
84
+ module.exports = __toCommonJS(base_copilot_textarea_exports);
85
+ var import_react12 = __toESM(require("react"));
86
+ var import_slate10 = require("slate");
87
+ var import_slate_react5 = require("slate-react");
88
+ var import_tailwind_merge2 = require("tailwind-merge");
89
+
90
+ // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
91
+ var import_react = require("react");
92
+
93
+ // src/lib/debouncer.ts
94
+ var Debouncer = class {
95
+ constructor(wait) {
96
+ this.wait = wait;
97
+ this.debounce = (func, ...args) => __async(this, null, function* () {
98
+ this.cancel();
99
+ this.timeoutId = setTimeout(() => __async(this, null, function* () {
100
+ try {
101
+ this.activeAbortController = new AbortController();
102
+ yield func(...args, this.activeAbortController.signal);
103
+ this.activeAbortController = void 0;
104
+ } catch (error) {
105
+ }
106
+ }), this.wait);
107
+ });
108
+ this.cancel = () => {
109
+ if (this.activeAbortController) {
110
+ this.activeAbortController.abort();
111
+ this.activeAbortController = void 0;
112
+ }
113
+ if (this.timeoutId !== void 0) {
114
+ clearTimeout(this.timeoutId);
115
+ this.timeoutId = void 0;
116
+ }
117
+ };
118
+ }
119
+ };
120
+
121
+ // src/lib/utils.ts
122
+ var import_clsx = require("clsx");
123
+ var import_tailwind_merge = require("tailwind-merge");
124
+ function cn(...inputs) {
125
+ return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
126
+ }
127
+ var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
128
+ function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
129
+ if (a === null || a === void 0 || b === null || b === void 0) {
130
+ return a === b;
131
+ }
132
+ return naiveEqualityCheck(a, b);
133
+ }
134
+
135
+ // src/types/base/editor-autocomplete-state.ts
136
+ function areEqual_autocompleteState(prev, next) {
137
+ return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
138
+ }
139
+
140
+ // src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts
141
+ function useAutosuggestions(debounceTime, shouldAcceptAutosuggestionOnKeyPress, shouldAcceptAutosuggestionOnTouch, autosuggestionFunction, insertAutocompleteSuggestion, disableWhenEmpty, disabled) {
142
+ const [previousAutocompleteState, setPreviousAutocompleteState] = (0, import_react.useState)(null);
143
+ const [currentAutocompleteSuggestion, setCurrentAutocompleteSuggestion] = (0, import_react.useState)(null);
144
+ const awaitForAndAppendSuggestion = (0, import_react.useCallback)(
145
+ (editorAutocompleteState, abortSignal) => __async(this, null, function* () {
146
+ if (disabled) {
147
+ return;
148
+ }
149
+ if (disableWhenEmpty && editorAutocompleteState.textBeforeCursor === "" && editorAutocompleteState.textAfterCursor === "") {
150
+ return;
151
+ }
152
+ const suggestion = yield autosuggestionFunction(editorAutocompleteState, abortSignal);
153
+ if (!suggestion || abortSignal.aborted) {
154
+ throw new DOMException("Aborted", "AbortError");
155
+ }
156
+ setCurrentAutocompleteSuggestion({
157
+ text: suggestion,
158
+ point: editorAutocompleteState.cursorPoint
159
+ });
160
+ }),
161
+ [autosuggestionFunction, setCurrentAutocompleteSuggestion, disableWhenEmpty, disabled]
162
+ );
163
+ const debouncedFunction = (0, import_react.useMemo)(
164
+ () => new Debouncer(debounceTime),
165
+ [debounceTime]
166
+ );
167
+ (0, import_react.useEffect)(() => {
168
+ return () => {
169
+ debouncedFunction.cancel();
170
+ setCurrentAutocompleteSuggestion(null);
171
+ };
172
+ }, [debouncedFunction, disabled]);
173
+ const onChange = (0, import_react.useCallback)(
174
+ (newEditorState) => {
175
+ const editorStateHasChanged = !nullableCompatibleEqualityCheck(
176
+ areEqual_autocompleteState,
177
+ previousAutocompleteState,
178
+ newEditorState
179
+ );
180
+ setPreviousAutocompleteState(newEditorState);
181
+ if (!editorStateHasChanged) {
182
+ return;
183
+ }
184
+ setCurrentAutocompleteSuggestion(null);
185
+ if (newEditorState) {
186
+ debouncedFunction.debounce(awaitForAndAppendSuggestion, newEditorState);
187
+ } else {
188
+ debouncedFunction.cancel();
189
+ }
190
+ },
191
+ [
192
+ previousAutocompleteState,
193
+ setPreviousAutocompleteState,
194
+ debouncedFunction,
195
+ awaitForAndAppendSuggestion,
196
+ setCurrentAutocompleteSuggestion
197
+ ]
198
+ );
199
+ const keyDownOrTouchHandler = (0, import_react.useCallback)(
200
+ (event) => {
201
+ if (currentAutocompleteSuggestion) {
202
+ const shouldAcceptSuggestion = event.type === "touchstart" ? shouldAcceptAutosuggestionOnTouch(event) : shouldAcceptAutosuggestionOnKeyPress(event);
203
+ if (shouldAcceptSuggestion) {
204
+ event.preventDefault();
205
+ insertAutocompleteSuggestion(currentAutocompleteSuggestion);
206
+ setCurrentAutocompleteSuggestion(null);
207
+ }
208
+ }
209
+ },
210
+ [
211
+ currentAutocompleteSuggestion,
212
+ setCurrentAutocompleteSuggestion,
213
+ insertAutocompleteSuggestion,
214
+ shouldAcceptAutosuggestionOnKeyPress
215
+ ]
216
+ );
217
+ return {
218
+ currentAutocompleteSuggestion,
219
+ onChangeHandler: onChange,
220
+ onKeyDownHandler: keyDownOrTouchHandler,
221
+ onTouchStartHandler: keyDownOrTouchHandler
222
+ };
223
+ }
224
+
225
+ // src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
226
+ var import_react2 = require("react");
227
+ var import_slate2 = require("slate");
228
+ var import_slate_react = require("slate-react");
229
+
230
+ // src/lib/slatejs-edits/with-partial-history.ts
231
+ var import_slate = require("slate");
232
+ var import_slate_history = require("slate-history");
233
+ var withPartialHistory = (editor, shouldSave2) => {
234
+ const e = editor;
235
+ const { apply } = e;
236
+ e.history = { undos: [], redos: [] };
237
+ e.redo = () => {
238
+ const { history } = e;
239
+ const { redos } = history;
240
+ if (redos.length > 0) {
241
+ const batch = redos[redos.length - 1];
242
+ if (batch.selectionBefore) {
243
+ import_slate.Transforms.setSelection(e, batch.selectionBefore);
244
+ }
245
+ import_slate_history.HistoryEditor.withoutSaving(e, () => {
246
+ import_slate.Editor.withoutNormalizing(e, () => {
247
+ for (const op of batch.operations) {
248
+ e.apply(op);
249
+ }
250
+ });
251
+ });
252
+ history.redos.pop();
253
+ e.writeHistory("undos", batch);
254
+ }
255
+ };
256
+ e.undo = () => {
257
+ const { history } = e;
258
+ const { undos } = history;
259
+ if (undos.length > 0) {
260
+ const batch = undos[undos.length - 1];
261
+ import_slate_history.HistoryEditor.withoutSaving(e, () => {
262
+ import_slate.Editor.withoutNormalizing(e, () => {
263
+ const inverseOps = batch.operations.map(import_slate.Operation.inverse).reverse();
264
+ for (const op of inverseOps) {
265
+ e.apply(op);
266
+ }
267
+ if (batch.selectionBefore) {
268
+ import_slate.Transforms.setSelection(e, batch.selectionBefore);
269
+ }
270
+ });
271
+ });
272
+ e.writeHistory("redos", batch);
273
+ history.undos.pop();
274
+ }
275
+ };
276
+ e.apply = (op) => {
277
+ const { operations, history } = e;
278
+ const { undos } = history;
279
+ const lastBatch = undos[undos.length - 1];
280
+ const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
281
+ let save = import_slate_history.HistoryEditor.isSaving(e);
282
+ let merge = import_slate_history.HistoryEditor.isMerging(e);
283
+ if (save == null) {
284
+ save = shouldSave2(op, lastOp);
285
+ }
286
+ if (save) {
287
+ if (merge == null) {
288
+ if (lastBatch == null) {
289
+ merge = false;
290
+ } else if (operations.length !== 0) {
291
+ merge = true;
292
+ } else {
293
+ merge = shouldMerge(op, lastOp);
294
+ }
295
+ }
296
+ if (lastBatch && merge) {
297
+ lastBatch.operations.push(op);
298
+ } else {
299
+ const batch = {
300
+ operations: [op],
301
+ selectionBefore: e.selection
302
+ };
303
+ e.writeHistory("undos", batch);
304
+ }
305
+ while (undos.length > 100) {
306
+ undos.shift();
307
+ }
308
+ history.redos = [];
309
+ }
310
+ apply(op);
311
+ };
312
+ e.writeHistory = (stack, batch) => {
313
+ e.history[stack].push(batch);
314
+ };
315
+ return e;
316
+ };
317
+ var shouldMerge = (op, prev) => {
318
+ if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && import_slate.Path.equals(op.path, prev.path)) {
319
+ return true;
320
+ }
321
+ if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && import_slate.Path.equals(op.path, prev.path)) {
322
+ return true;
323
+ }
324
+ return false;
325
+ };
326
+ var defaultShouldSave = (op, prev) => {
327
+ if (op.type === "set_selection") {
328
+ return false;
329
+ }
330
+ return true;
331
+ };
332
+
333
+ // src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx
334
+ var shouldSave = (op, prev) => {
335
+ const excludedNodeType = "suggestion";
336
+ if (op.type === "insert_node" && import_slate2.Element.isElement(op.node) && op.node.type === excludedNodeType) {
337
+ return false;
338
+ }
339
+ if (op.type === "remove_node" && import_slate2.Element.isElement(op.node) && op.node.type === excludedNodeType) {
340
+ return false;
341
+ }
342
+ if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
343
+ return false;
344
+ }
345
+ if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
346
+ return false;
347
+ }
348
+ if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
349
+ return false;
350
+ }
351
+ if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
352
+ return false;
353
+ }
354
+ return defaultShouldSave(op, prev);
355
+ };
356
+ function useCopilotTextareaEditor() {
357
+ const editor = (0, import_react2.useMemo)(() => {
358
+ const editor2 = withPartialHistory((0, import_slate_react.withReact)((0, import_slate2.createEditor)()), shouldSave);
359
+ const { isVoid } = editor2;
360
+ editor2.isVoid = (element) => {
361
+ switch (element.type) {
362
+ case "suggestion":
363
+ return true;
364
+ default:
365
+ return isVoid(element);
366
+ }
367
+ };
368
+ const { markableVoid } = editor2;
369
+ editor2.markableVoid = (element) => {
370
+ switch (element.type) {
371
+ case "suggestion":
372
+ return true;
373
+ default:
374
+ return markableVoid(element);
375
+ }
376
+ };
377
+ const { isInline } = editor2;
378
+ editor2.isInline = (element) => {
379
+ switch (element.type) {
380
+ case "suggestion":
381
+ return element.inline;
382
+ default:
383
+ return isInline(element);
384
+ }
385
+ };
386
+ return editor2;
387
+ }, []);
388
+ return editor;
389
+ }
390
+
391
+ // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
392
+ var import_react3 = __toESM(require("react"));
393
+ var import_slate_react2 = require("slate-react");
394
+
395
+ // src/lib/get-text-around-cursor.ts
396
+ var import_slate3 = require("slate");
397
+ function getTextAroundCollapsedCursor(editor) {
398
+ const { selection } = editor;
399
+ if (!selection || !import_slate3.Range.isCollapsed(selection)) {
400
+ return null;
401
+ }
402
+ const cursorPoint = selection.anchor;
403
+ const beforeRange = {
404
+ anchor: import_slate3.Editor.start(editor, []),
405
+ focus: cursorPoint
406
+ };
407
+ const afterRange = {
408
+ anchor: cursorPoint,
409
+ focus: import_slate3.Editor.end(editor, [])
410
+ };
411
+ const before = extractTextWithNewlines(editor, beforeRange);
412
+ const after = extractTextWithNewlines(editor, afterRange);
413
+ return {
414
+ cursorPoint,
415
+ textBeforeCursor: before,
416
+ textAfterCursor: after
417
+ };
418
+ }
419
+ function getTextAroundSelection(editor) {
420
+ const { selection } = editor;
421
+ if (!selection) {
422
+ return null;
423
+ }
424
+ const wellOrderedSelection = wellOrderedRange(selection);
425
+ const beforeRange = {
426
+ anchor: import_slate3.Editor.start(editor, []),
427
+ focus: wellOrderedSelection.anchor
428
+ };
429
+ const afterRange = {
430
+ anchor: wellOrderedSelection.focus,
431
+ focus: import_slate3.Editor.end(editor, [])
432
+ };
433
+ const before = extractTextWithNewlines(editor, beforeRange);
434
+ const after = extractTextWithNewlines(editor, afterRange);
435
+ const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
436
+ return {
437
+ selection: wellOrderedSelection,
438
+ textBeforeCursor: before,
439
+ selectedText,
440
+ textAfterCursor: after
441
+ };
442
+ }
443
+ function getFullEditorTextWithNewlines(editor) {
444
+ const fullDocumentRange = {
445
+ anchor: import_slate3.Editor.start(editor, []),
446
+ focus: import_slate3.Editor.end(editor, [])
447
+ };
448
+ return extractTextWithNewlines(editor, fullDocumentRange);
449
+ }
450
+ function extractTextWithNewlines(editor, range) {
451
+ const voids = false;
452
+ const [start, end] = import_slate3.Range.edges(range);
453
+ let text = "";
454
+ let lastBlock = null;
455
+ for (const [node, path] of import_slate3.Editor.nodes(editor, {
456
+ at: range,
457
+ match: import_slate3.Text.isText,
458
+ voids
459
+ })) {
460
+ let t = node.text;
461
+ const [block] = import_slate3.Editor.above(editor, {
462
+ at: path,
463
+ match: (n) => import_slate3.Element.isElement(n) && n.type === "paragraph"
464
+ }) || [null];
465
+ if (lastBlock !== block && block) {
466
+ if (lastBlock) {
467
+ text += "\n";
468
+ }
469
+ lastBlock = block;
470
+ }
471
+ if (import_slate3.Path.equals(path, end.path)) {
472
+ t = t.slice(0, end.offset);
473
+ }
474
+ if (import_slate3.Path.equals(path, start.path)) {
475
+ t = t.slice(start.offset);
476
+ }
477
+ text += t;
478
+ }
479
+ return text;
480
+ }
481
+ function wellOrderedRange(range) {
482
+ const { anchor, focus } = range;
483
+ if (import_slate3.Point.isBefore(anchor, focus)) {
484
+ return range;
485
+ }
486
+ return {
487
+ anchor: focus,
488
+ focus: anchor
489
+ };
490
+ }
491
+
492
+ // src/lib/slatejs-edits/replace-text.ts
493
+ var import_slate4 = require("slate");
494
+ function replaceEditorText(editor, newText) {
495
+ import_slate4.Transforms.delete(editor, {
496
+ at: {
497
+ anchor: import_slate4.Editor.start(editor, []),
498
+ focus: import_slate4.Editor.end(editor, [])
499
+ }
500
+ });
501
+ if (newText && newText !== "") {
502
+ import_slate4.Transforms.insertNodes(
503
+ editor,
504
+ [
505
+ {
506
+ type: "paragraph",
507
+ children: [{ text: newText }]
508
+ }
509
+ ],
510
+ {
511
+ at: [0]
512
+ }
513
+ );
514
+ }
515
+ }
516
+
517
+ // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
518
+ function usePopulateCopilotTextareaRef(editor, ref) {
519
+ import_react3.default.useImperativeHandle(ref, () => {
520
+ class Combined {
521
+ constructor(customMethods2, editorHtmlElement2) {
522
+ this.customMethods = customMethods2;
523
+ this.editorHtmlElement = editorHtmlElement2;
524
+ }
525
+ get(target, propKey) {
526
+ if (this.isKeyOfCustomMethods(propKey)) {
527
+ const value = this.customMethods[propKey];
528
+ if (typeof value === "function") {
529
+ return value.bind(this.customMethods);
530
+ }
531
+ return value;
532
+ } else if (this.isKeyOfHTMLElement(propKey)) {
533
+ const value = this.editorHtmlElement[propKey];
534
+ if (typeof value === "function") {
535
+ return value.bind(this.editorHtmlElement);
536
+ }
537
+ return value;
538
+ }
539
+ }
540
+ set(target, propKey, value) {
541
+ if (this.isKeyOfCustomMethods(propKey)) {
542
+ this.customMethods[propKey] = value;
543
+ } else if (this.isKeyOfHTMLElement(propKey)) {
544
+ this.editorHtmlElement[propKey] = value;
545
+ } else {
546
+ target[propKey] = value;
547
+ }
548
+ return true;
549
+ }
550
+ isKeyOfCustomMethods(key) {
551
+ return key in this.customMethods;
552
+ }
553
+ isKeyOfHTMLElement(key) {
554
+ return key in this.editorHtmlElement;
555
+ }
556
+ }
557
+ const handler = {
558
+ get(target, propKey) {
559
+ return target.get(target, propKey);
560
+ },
561
+ set(target, propKey, value) {
562
+ return target.set(target, propKey, value);
563
+ }
564
+ };
565
+ class CustomMethods {
566
+ constructor(editor2) {
567
+ this.editor = editor2;
568
+ }
569
+ focus() {
570
+ import_slate_react2.ReactEditor.focus(this.editor);
571
+ }
572
+ blur() {
573
+ import_slate_react2.ReactEditor.blur(this.editor);
574
+ }
575
+ get value() {
576
+ return getFullEditorTextWithNewlines(this.editor);
577
+ }
578
+ set value(value) {
579
+ replaceEditorText(this.editor, value);
580
+ }
581
+ }
582
+ const editorHtmlElement = import_slate_react2.ReactEditor.toDOMNode(editor, editor);
583
+ const customMethods = new CustomMethods(editor);
584
+ const combined = new Combined(customMethods, editorHtmlElement);
585
+ return new Proxy(combined, handler);
586
+ }, [editor]);
587
+ }
588
+
589
+ // src/lib/slatejs-edits/add-autocompletions.ts
590
+ var import_slate5 = require("slate");
591
+ function addAutocompletionsToEditor(editor, newSuggestion, point) {
592
+ const editorPosition = editor.selection;
593
+ import_slate5.Transforms.insertNodes(
594
+ editor,
595
+ [
596
+ {
597
+ type: "suggestion",
598
+ inline: true,
599
+ content: newSuggestion,
600
+ children: [{ text: "" }]
601
+ }
602
+ ],
603
+ {
604
+ at: point
605
+ }
606
+ );
607
+ if (editorPosition) {
608
+ editor.selection = editorPosition;
609
+ }
610
+ }
611
+
612
+ // src/lib/slatejs-edits/clear-autocompletions.ts
613
+ var import_slate6 = require("slate");
614
+ function clearAutocompletionsFromEditor(editor) {
615
+ const paths = [];
616
+ for (const [node, path] of import_slate6.Node.nodes(editor)) {
617
+ if (import_slate6.Element.isElement(node) && node.type === "suggestion") {
618
+ paths.push(path);
619
+ }
620
+ }
621
+ for (const path of paths) {
622
+ try {
623
+ import_slate6.Transforms.removeNodes(editor, { at: path });
624
+ } catch (e) {
625
+ console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
626
+ }
627
+ }
628
+ }
629
+
630
+ // src/types/base/base-autosuggestions-config.tsx
631
+ var import_react_core = require("@copilotkit/react-core");
632
+ var defaultShouldToggleHoveringEditorOnKeyPress = (event, shortcut) => {
633
+ if (event.key === shortcut && event.metaKey) {
634
+ return true;
635
+ }
636
+ return false;
637
+ };
638
+ var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
639
+ if (event.key === "Tab") {
640
+ return true;
641
+ }
642
+ return false;
643
+ };
644
+ var defaultShouldAcceptAutosuggestionOnTouch = () => false;
645
+ var defaultBaseAutosuggestionsConfig = {
646
+ debounceTime: 250,
647
+ contextCategories: import_react_core.defaultCopilotContextCategories,
648
+ disableWhenEmpty: true,
649
+ disabled: false,
650
+ temporarilyDisableWhenMovingCursorWithoutChangingText: true,
651
+ shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
652
+ shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,
653
+ shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch
654
+ };
655
+
656
+ // src/components/hovering-toolbar/hovering-toolbar.tsx
657
+ var import_react9 = require("react");
658
+ var import_slate7 = require("slate");
659
+ var import_slate_react3 = require("slate-react");
660
+
661
+ // src/hooks/misc/use-autosize-textarea.tsx
662
+ var import_react4 = require("react");
663
+ var useAutosizeTextArea = (textAreaRef, value) => {
664
+ (0, import_react4.useEffect)(() => {
665
+ if (textAreaRef.current !== null) {
666
+ textAreaRef.current.style.height = "0px";
667
+ const scrollHeight = textAreaRef.current.scrollHeight;
668
+ textAreaRef.current.style.height = scrollHeight + "px";
669
+ }
670
+ }, [textAreaRef, value]);
671
+ };
672
+ var use_autosize_textarea_default = useAutosizeTextArea;
673
+
674
+ // src/components/source-search-box/source-search-box.tsx
675
+ var import_react5 = require("react");
676
+
677
+ // src/components/ui/command.tsx
678
+ var React2 = __toESM(require("react"));
679
+ var import_cmdk = require("cmdk");
680
+ var import_jsx_runtime = require("react/jsx-runtime");
681
+ var Command = React2.forwardRef((_a, ref) => {
682
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
683
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
684
+ import_cmdk.Command,
685
+ __spreadValues({
686
+ ref,
687
+ className: cn(
688
+ "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
689
+ className
690
+ )
691
+ }, props)
692
+ );
693
+ });
694
+ Command.displayName = import_cmdk.Command.displayName;
695
+ var CommandInput = React2.forwardRef((_a, ref) => {
696
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
697
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
698
+ import_cmdk.Command.Input,
699
+ __spreadValues({
700
+ ref,
701
+ className: cn(
702
+ "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
703
+ className
704
+ )
705
+ }, props)
706
+ ) });
707
+ });
708
+ CommandInput.displayName = import_cmdk.Command.Input.displayName;
709
+ var CommandList = React2.forwardRef((_a, ref) => {
710
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
711
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
712
+ import_cmdk.Command.List,
713
+ __spreadValues({
714
+ ref,
715
+ className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden pb-2", className)
716
+ }, props)
717
+ );
718
+ });
719
+ CommandList.displayName = import_cmdk.Command.List.displayName;
720
+ var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
721
+ CommandEmpty.displayName = import_cmdk.Command.Empty.displayName;
722
+ var CommandGroup = React2.forwardRef((_a, ref) => {
723
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
724
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
725
+ import_cmdk.Command.Group,
726
+ __spreadValues({
727
+ ref,
728
+ className: cn(
729
+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
730
+ className
731
+ )
732
+ }, props)
733
+ );
734
+ });
735
+ CommandGroup.displayName = import_cmdk.Command.Group.displayName;
736
+ var CommandSeparator = React2.forwardRef((_a, ref) => {
737
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
738
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
739
+ import_cmdk.Command.Separator,
740
+ __spreadValues({
741
+ ref,
742
+ className: cn("-mx-1 h-px bg-border", className)
743
+ }, props)
744
+ );
745
+ });
746
+ CommandSeparator.displayName = import_cmdk.Command.Separator.displayName;
747
+ var CommandItem = React2.forwardRef((_a, ref) => {
748
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
749
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
750
+ import_cmdk.Command.Item,
751
+ __spreadValues({
752
+ ref,
753
+ className: cn(
754
+ "relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
755
+ className
756
+ )
757
+ }, props)
758
+ );
759
+ });
760
+ CommandItem.displayName = import_cmdk.Command.Item.displayName;
761
+ var CommandShortcut = (_a) => {
762
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
763
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
764
+ "span",
765
+ __spreadValues({
766
+ className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
767
+ }, props)
768
+ );
769
+ };
770
+ CommandShortcut.displayName = "CommandShortcut";
771
+
772
+ // src/components/source-search-box/source-search-box.tsx
773
+ var import_jsx_runtime2 = require("react/jsx-runtime");
774
+ function SourceSearchBox(props) {
775
+ const [selectedValue, setSelectedValue] = (0, import_react5.useState)("");
776
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
777
+ Command,
778
+ {
779
+ className: "rounded-lg border shadow-md",
780
+ value: selectedValue,
781
+ onValueChange: (value) => {
782
+ setSelectedValue(value);
783
+ },
784
+ filter: (value, search) => {
785
+ if (props.searchTerm === "")
786
+ return 1;
787
+ if (value.startsWith(props.searchTerm))
788
+ return 1;
789
+ return 0;
790
+ },
791
+ children: [
792
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
793
+ CommandInput,
794
+ {
795
+ value: props.searchTerm,
796
+ className: "rounded-t-lg hidden",
797
+ placeholder: "Search for a command..."
798
+ }
799
+ ),
800
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(CommandList, { children: [
801
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandEmpty, { children: "No results found." }),
802
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
803
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
804
+ CommandItem,
805
+ {
806
+ value: filePointer.name,
807
+ onSelect: (value) => {
808
+ props.onSelectedFile(filePointer);
809
+ },
810
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
811
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
812
+ "img",
813
+ {
814
+ src: filePointer.iconImageUri,
815
+ alt: filePointer.sourceApplication,
816
+ className: "w-full h-full"
817
+ }
818
+ ) }),
819
+ filePointer.name
820
+ ] })
821
+ },
822
+ `word-${filePointer.sourceApplication}.${filePointer.name}`
823
+ );
824
+ }) }),
825
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandSeparator, {})
826
+ ] })
827
+ ]
828
+ }
829
+ );
830
+ }
831
+ function Logo({
832
+ children,
833
+ width,
834
+ height
835
+ }) {
836
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex items-center justify-center", style: { width, height }, children });
837
+ }
838
+
839
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
840
+ var import_react_core2 = require("@copilotkit/react-core");
841
+
842
+ // src/components/ui/button.tsx
843
+ var React3 = __toESM(require("react"));
844
+ var import_react_slot = require("@radix-ui/react-slot");
845
+ var import_class_variance_authority = require("class-variance-authority");
846
+ var import_jsx_runtime3 = require("react/jsx-runtime");
847
+ var buttonVariants = (0, import_class_variance_authority.cva)(
848
+ "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
849
+ {
850
+ variants: {
851
+ variant: {
852
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
853
+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
854
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
855
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
856
+ ghost: "hover:bg-accent hover:text-accent-foreground",
857
+ link: "text-primary underline-offset-4 hover:underline"
858
+ },
859
+ size: {
860
+ default: "h-10 px-4 py-2",
861
+ sm: "h-9 rounded-md px-3",
862
+ lg: "h-11 rounded-md px-8",
863
+ icon: "h-10 w-10"
864
+ }
865
+ },
866
+ defaultVariants: {
867
+ variant: "default",
868
+ size: "default"
869
+ }
870
+ }
871
+ );
872
+ var Button = React3.forwardRef(
873
+ (_a, ref) => {
874
+ var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
875
+ const Comp = asChild ? import_react_slot.Slot : "button";
876
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
877
+ }
878
+ );
879
+ Button.displayName = "Button";
880
+
881
+ // src/components/ui/label.tsx
882
+ var React4 = __toESM(require("react"));
883
+ var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
884
+ var import_class_variance_authority2 = require("class-variance-authority");
885
+ var import_jsx_runtime4 = require("react/jsx-runtime");
886
+ var labelVariants = (0, import_class_variance_authority2.cva)(
887
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
888
+ );
889
+ var Label = React4.forwardRef((_a, ref) => {
890
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
891
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
892
+ });
893
+ Label.displayName = LabelPrimitive.Root.displayName;
894
+
895
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
896
+ var import_react7 = require("react");
897
+
898
+ // src/lib/stream-promise-flatten.ts
899
+ function streamPromiseFlatten(promise) {
900
+ return new ReadableStream({
901
+ start(controller) {
902
+ return __async(this, null, function* () {
903
+ try {
904
+ const stream = yield promise;
905
+ const reader = stream.getReader();
906
+ while (true) {
907
+ const { done, value } = yield reader.read();
908
+ if (done) {
909
+ controller.close();
910
+ return;
911
+ }
912
+ controller.enqueue(value);
913
+ }
914
+ } catch (error) {
915
+ controller.error(error);
916
+ }
917
+ });
918
+ }
919
+ });
920
+ }
921
+
922
+ // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
923
+ var import_Chip = __toESM(require("@mui/material/Chip/Chip.js"));
924
+ var import_Avatar = __toESM(require("@mui/material/Avatar/Avatar.js"));
925
+ var import_jsx_runtime5 = require("react/jsx-runtime");
926
+ var IncludedFilesPreview = ({
927
+ includedFiles,
928
+ setIncludedFiles
929
+ }) => {
930
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-col gap-2 mt-2", children: [
931
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { className: "", children: "Included context:" }),
932
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
933
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
934
+ FileChipPreview,
935
+ {
936
+ filePointer,
937
+ onDelete: () => {
938
+ setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
939
+ }
940
+ },
941
+ `file-${filePointer.sourceApplication}.${filePointer.name}`
942
+ );
943
+ }) })
944
+ ] });
945
+ };
946
+ var FileChipPreview = ({ filePointer, onDelete }) => {
947
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
948
+ import_Chip.default,
949
+ {
950
+ label: filePointer.name,
951
+ onDelete,
952
+ avatar: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
953
+ import_Avatar.default,
954
+ {
955
+ src: filePointer.iconImageUri,
956
+ alt: filePointer.sourceApplication,
957
+ sx: { backgroundColor: "transparent" }
958
+ }
959
+ )
960
+ }
961
+ );
962
+ };
963
+
964
+ // src/components/hovering-toolbar/hovering-editor-provider.tsx
965
+ var import_react6 = require("react");
966
+ var import_jsx_runtime6 = require("react/jsx-runtime");
967
+ var HoveringEditorContext = (0, import_react6.createContext)({
968
+ isDisplayed: false,
969
+ setIsDisplayed: () => {
970
+ }
971
+ });
972
+ var HoveringEditorProvider = ({ children }) => {
973
+ const [isDisplayed, setIsDisplayed] = (0, import_react6.useState)(false);
974
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
975
+ };
976
+ var useHoveringEditorContext = () => (0, import_react6.useContext)(HoveringEditorContext);
977
+
978
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
979
+ var import_jsx_runtime7 = require("react/jsx-runtime");
980
+ var HoveringInsertionPromptBoxCore = ({
981
+ performInsertion,
982
+ state,
983
+ insertionOrEditingFunction,
984
+ contextCategories
985
+ }) => {
986
+ const { getDocumentsContext } = (0, import_react_core2.useCopilotContext)();
987
+ const [editSuggestion, setEditSuggestion] = (0, import_react7.useState)("");
988
+ const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react7.useState)(false);
989
+ const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react7.useState)("");
990
+ const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react7.useState)(
991
+ null
992
+ );
993
+ const adjustmentTextAreaRef = (0, import_react7.useRef)(null);
994
+ const suggestionTextAreaRef = (0, import_react7.useRef)(null);
995
+ const [filePointers, setFilePointers] = (0, import_react7.useState)([]);
996
+ const [suggestedFiles, setSuggestedFiles] = (0, import_react7.useState)([]);
997
+ (0, import_react7.useEffect)(() => {
998
+ setSuggestedFiles(getDocumentsContext(contextCategories));
999
+ }, [contextCategories, getDocumentsContext]);
1000
+ use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
1001
+ use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
1002
+ (0, import_react7.useEffect)(() => {
1003
+ var _a;
1004
+ (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
1005
+ }, []);
1006
+ (0, import_react7.useEffect)(() => {
1007
+ if (!generatingSuggestion) {
1008
+ return;
1009
+ }
1010
+ if (generatingSuggestion.locked) {
1011
+ return;
1012
+ }
1013
+ setEditSuggestion("");
1014
+ const reader = generatingSuggestion.getReader();
1015
+ const read = () => __async(void 0, null, function* () {
1016
+ setSuggestionIsLoading(true);
1017
+ while (true) {
1018
+ const { done, value } = yield reader.read();
1019
+ if (done) {
1020
+ break;
1021
+ }
1022
+ setEditSuggestion((prev) => {
1023
+ const newSuggestion = prev + value;
1024
+ if (suggestionTextAreaRef.current) {
1025
+ suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
1026
+ }
1027
+ return newSuggestion;
1028
+ });
1029
+ }
1030
+ setSuggestionIsLoading(false);
1031
+ });
1032
+ read();
1033
+ return () => {
1034
+ const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
1035
+ try {
1036
+ yield reader.closed;
1037
+ } catch (e) {
1038
+ reader.releaseLock();
1039
+ }
1040
+ });
1041
+ releaseLockIfNotClosed();
1042
+ };
1043
+ }, [generatingSuggestion]);
1044
+ const beginGeneratingAdjustment = (0, import_react7.useCallback)(() => __async(void 0, null, function* () {
1045
+ if (!adjustmentPrompt.trim()) {
1046
+ return;
1047
+ }
1048
+ let modificationState = state.editorState;
1049
+ if (editSuggestion !== "") {
1050
+ modificationState.selectedText = editSuggestion;
1051
+ }
1052
+ const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
1053
+ modificationState,
1054
+ adjustmentPrompt,
1055
+ filePointers,
1056
+ new AbortController().signal
1057
+ );
1058
+ const adjustmentSuggestionTextStream = streamPromiseFlatten(
1059
+ adjustmentSuggestionTextStreamPromise
1060
+ );
1061
+ setGeneratingSuggestion(adjustmentSuggestionTextStream);
1062
+ }), [
1063
+ adjustmentPrompt,
1064
+ editSuggestion,
1065
+ state.editorState,
1066
+ insertionOrEditingFunction,
1067
+ filePointers
1068
+ ]);
1069
+ const isLoading = suggestionIsLoading;
1070
+ const textToEdit = editSuggestion || state.editorState.selectedText;
1071
+ const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
1072
+ const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
1073
+ const { setIsDisplayed } = useHoveringEditorContext();
1074
+ const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1075
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "", children: adjustmentLabel }),
1076
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative w-full flex items-center", children: [
1077
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1078
+ "textarea",
1079
+ {
1080
+ "data-testid": "adjustment-prompt",
1081
+ disabled: suggestionIsLoading,
1082
+ ref: adjustmentTextAreaRef,
1083
+ value: adjustmentPrompt,
1084
+ onChange: (e) => setAdjustmentPrompt(e.target.value),
1085
+ onKeyDown: (e) => {
1086
+ if (e.key === "Enter" && e.shiftKey) {
1087
+ e.preventDefault();
1088
+ setAdjustmentPrompt(adjustmentPrompt + "\n");
1089
+ } else if (e.key === "Enter") {
1090
+ e.preventDefault();
1091
+ beginGeneratingAdjustment();
1092
+ } else if (e.key == "Escape") {
1093
+ e.preventDefault();
1094
+ setIsDisplayed(false);
1095
+ }
1096
+ },
1097
+ placeholder,
1098
+ style: { minHeight: "3rem" },
1099
+ className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
1100
+ rows: 1
1101
+ }
1102
+ ),
1103
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1104
+ "button",
1105
+ {
1106
+ onClick: beginGeneratingAdjustment,
1107
+ className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
1108
+ "data-testid": "generate-button",
1109
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "arrow_forward" })
1110
+ }
1111
+ )
1112
+ ] })
1113
+ ] });
1114
+ const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1115
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-between items-end w-full", children: [
1116
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "mt-4", children: "Suggested:" }),
1117
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1118
+ "div",
1119
+ {
1120
+ className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
1121
+ role: "status",
1122
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." })
1123
+ }
1124
+ ) }) })
1125
+ ] }),
1126
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1127
+ "textarea",
1128
+ {
1129
+ "data-testid": "suggestion-result",
1130
+ ref: suggestionTextAreaRef,
1131
+ value: editSuggestion,
1132
+ disabled: suggestionIsLoading,
1133
+ onChange: (e) => setEditSuggestion(e.target.value),
1134
+ className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
1135
+ style: { overflow: "auto", maxHeight: "10em" }
1136
+ }
1137
+ )
1138
+ ] });
1139
+ const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1140
+ Button,
1141
+ {
1142
+ "data-testid": "insert-button",
1143
+ className: " bg-green-700 text-white",
1144
+ onClick: () => {
1145
+ performInsertion(editSuggestion);
1146
+ },
1147
+ children: [
1148
+ "Insert ",
1149
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "check" })
1150
+ ]
1151
+ }
1152
+ ) });
1153
+ const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
1154
+ const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
1155
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
1156
+ AdjustmentPromptComponent,
1157
+ filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
1158
+ sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1159
+ SourceSearchBox,
1160
+ {
1161
+ searchTerm: sourceSearchWord,
1162
+ suggestedFiles,
1163
+ onSelectedFile: (filePointer) => {
1164
+ var _a;
1165
+ setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), ""));
1166
+ setFilePointers((prev) => [...prev, filePointer]);
1167
+ (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
1168
+ }
1169
+ }
1170
+ ),
1171
+ generatingSuggestion ? SuggestionComponent : null,
1172
+ generatingSuggestion ? SubmitComponent : null
1173
+ ] });
1174
+ };
1175
+
1176
+ // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
1177
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1178
+ var HoveringInsertionPromptBox = (props) => {
1179
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1180
+ "div",
1181
+ {
1182
+ className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
1183
+ style: { width: "35rem" },
1184
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1185
+ HoveringInsertionPromptBoxCore,
1186
+ {
1187
+ state: {
1188
+ editorState: props.editorState
1189
+ },
1190
+ insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
1191
+ performInsertion: props.performInsertion,
1192
+ contextCategories: props.contextCategories
1193
+ }
1194
+ )
1195
+ }
1196
+ );
1197
+ };
1198
+
1199
+ // src/components/hovering-toolbar/hovering-toolbar-components.tsx
1200
+ var import_css = require("@emotion/css");
1201
+ var import_react8 = __toESM(require("react"));
1202
+ var import_react_dom = __toESM(require("react-dom"));
1203
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1204
+ var Button2 = import_react8.default.forwardRef(
1205
+ (_a, ref) => {
1206
+ var _b = _a, {
1207
+ className,
1208
+ active,
1209
+ reversed
1210
+ } = _b, props = __objRest(_b, [
1211
+ "className",
1212
+ "active",
1213
+ "reversed"
1214
+ ]);
1215
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1216
+ "span",
1217
+ __spreadProps(__spreadValues({}, props), {
1218
+ ref,
1219
+ className: (0, import_css.cx)(
1220
+ className,
1221
+ import_css.css`
1222
+ cursor: pointer;
1223
+ color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
1224
+ `
1225
+ )
1226
+ })
1227
+ );
1228
+ }
1229
+ );
1230
+ var Icon = import_react8.default.forwardRef(
1231
+ (_a, ref) => {
1232
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1233
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1234
+ "span",
1235
+ __spreadProps(__spreadValues({}, props), {
1236
+ ref,
1237
+ className: (0, import_css.cx)(
1238
+ "material-icons",
1239
+ className,
1240
+ import_css.css`
1241
+ font-size: 18px;
1242
+ vertical-align: text-bottom;
1243
+ `
1244
+ )
1245
+ })
1246
+ );
1247
+ }
1248
+ );
1249
+ var Menu = import_react8.default.forwardRef(
1250
+ (_a, ref) => {
1251
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1252
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1253
+ "div",
1254
+ __spreadProps(__spreadValues({}, props), {
1255
+ "data-testid": "menu",
1256
+ ref,
1257
+ className: (0, import_css.cx)(
1258
+ className,
1259
+ import_css.css`
1260
+ & > * {
1261
+ display: inline-block;
1262
+ }
1263
+
1264
+ & > * + * {
1265
+ margin-left: 15px;
1266
+ }
1267
+ `
1268
+ )
1269
+ })
1270
+ );
1271
+ }
1272
+ );
1273
+ var Portal = ({ children }) => {
1274
+ return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
1275
+ };
1276
+ var Toolbar = import_react8.default.forwardRef(
1277
+ (_a, ref) => {
1278
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1279
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1280
+ Menu,
1281
+ __spreadProps(__spreadValues({}, props), {
1282
+ ref,
1283
+ className: (0, import_css.cx)(
1284
+ className,
1285
+ import_css.css`
1286
+ position: relative;
1287
+ padding: 1px 18px 17px;
1288
+ margin: 0 -20px;
1289
+ border-bottom: 2px solid #eee;
1290
+ margin-bottom: 20px;
1291
+ `
1292
+ )
1293
+ })
1294
+ );
1295
+ }
1296
+ );
1297
+
1298
+ // src/components/hovering-toolbar/hovering-toolbar.tsx
1299
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1300
+ var HoveringToolbar = (props) => {
1301
+ const ref = (0, import_react9.useRef)(null);
1302
+ const editor = (0, import_slate_react3.useSlate)();
1303
+ const selection = (0, import_slate_react3.useSlateSelection)();
1304
+ const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
1305
+ const [isClient, setIsClient] = (0, import_react9.useState)(false);
1306
+ (0, import_react9.useEffect)(() => {
1307
+ setIsClient(true);
1308
+ }, []);
1309
+ (0, import_react9.useEffect)(() => {
1310
+ const el = ref.current;
1311
+ const { selection: selection2 } = editor;
1312
+ if (!el) {
1313
+ return;
1314
+ }
1315
+ if (!selection2) {
1316
+ el.removeAttribute("style");
1317
+ return;
1318
+ }
1319
+ const domSelection = window.getSelection();
1320
+ if (!domSelection || domSelection.rangeCount === 0) {
1321
+ return;
1322
+ }
1323
+ const domRange = domSelection.getRangeAt(0);
1324
+ const rect = domRange.getBoundingClientRect();
1325
+ if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
1326
+ return;
1327
+ }
1328
+ const minGapFromEdge = 60;
1329
+ const verticalOffsetFromCorner = 35;
1330
+ const horizontalOffsetFromCorner = 15;
1331
+ let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
1332
+ if (top < minGapFromEdge) {
1333
+ top = rect.bottom + window.scrollY + minGapFromEdge;
1334
+ } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
1335
+ top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
1336
+ }
1337
+ let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
1338
+ if (left < minGapFromEdge) {
1339
+ left = minGapFromEdge;
1340
+ } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
1341
+ left = window.innerWidth - el.offsetWidth - minGapFromEdge;
1342
+ }
1343
+ el.style.opacity = "1";
1344
+ el.style.position = "absolute";
1345
+ el.style.top = `${top}px`;
1346
+ el.style.left = `${left}px`;
1347
+ });
1348
+ (0, import_react9.useEffect)(() => {
1349
+ const handleClickOutside = (event) => {
1350
+ if (ref.current && !ref.current.contains(event.target)) {
1351
+ setIsDisplayed(false);
1352
+ }
1353
+ };
1354
+ document.addEventListener("mousedown", handleClickOutside);
1355
+ return () => {
1356
+ document.removeEventListener("mousedown", handleClickOutside);
1357
+ };
1358
+ }, [ref, setIsDisplayed]);
1359
+ if (!isClient) {
1360
+ return null;
1361
+ }
1362
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1363
+ Menu,
1364
+ {
1365
+ ref,
1366
+ className: "copilot-kit-textarea-css-scope " + (props.hoverMenuClassname || "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700"),
1367
+ "data-testid": "hovering-toolbar",
1368
+ children: isDisplayed && selection && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1369
+ HoveringInsertionPromptBox,
1370
+ {
1371
+ editorState: editorState(editor, selection),
1372
+ apiConfig: props.apiConfig,
1373
+ closeWindow: () => {
1374
+ setIsDisplayed(false);
1375
+ },
1376
+ performInsertion: (insertedText) => {
1377
+ import_slate7.Transforms.delete(editor, { at: selection });
1378
+ import_slate7.Transforms.insertText(editor, insertedText, {
1379
+ at: selection
1380
+ });
1381
+ setIsDisplayed(false);
1382
+ },
1383
+ contextCategories: props.contextCategories
1384
+ }
1385
+ )
1386
+ }
1387
+ ) });
1388
+ };
1389
+ function editorState(editor, selection) {
1390
+ const textAroundCursor = getTextAroundSelection(editor);
1391
+ if (textAroundCursor) {
1392
+ return textAroundCursor;
1393
+ }
1394
+ return {
1395
+ textBeforeCursor: getFullEditorTextWithNewlines(editor),
1396
+ textAfterCursor: "",
1397
+ selectedText: ""
1398
+ };
1399
+ }
1400
+
1401
+ // src/components/base-copilot-textarea/render-element.tsx
1402
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1403
+ function makeRenderElementFunction(suggestionsStyle) {
1404
+ return (props) => {
1405
+ switch (props.element.type) {
1406
+ case "paragraph":
1407
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(DefaultElement, __spreadValues({}, props));
1408
+ case "suggestion":
1409
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SuggestionElement, __spreadProps(__spreadValues({}, props), { suggestionsStyle }));
1410
+ }
1411
+ };
1412
+ }
1413
+ var DefaultElement = (props) => {
1414
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", __spreadProps(__spreadValues({}, props.attributes), { children: props.children }));
1415
+ };
1416
+ var SuggestionElement = (props) => {
1417
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1418
+ "span",
1419
+ __spreadProps(__spreadValues({}, props.attributes), {
1420
+ style: __spreadValues({}, props.suggestionsStyle),
1421
+ "data-testid": "suggestion",
1422
+ contentEditable: false,
1423
+ children: [
1424
+ props.children,
1425
+ props.element.type === "suggestion" && props.element.content
1426
+ ]
1427
+ })
1428
+ );
1429
+ };
1430
+
1431
+ // src/components/base-copilot-textarea/render-placeholder.tsx
1432
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1433
+ function makeRenderPlaceholderFunction(placeholderStyle) {
1434
+ return (props) => {
1435
+ const _a = props.attributes, { style } = _a, restAttributes = __objRest(_a, ["style"]);
1436
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1437
+ "div",
1438
+ __spreadProps(__spreadValues({}, restAttributes), {
1439
+ style: __spreadValues(__spreadValues({}, style), placeholderStyle),
1440
+ children: props.children
1441
+ })
1442
+ );
1443
+ };
1444
+ }
1445
+
1446
+ // src/components/base-copilot-textarea/use-add-branding-css.tsx
1447
+ var import_react10 = require("react");
1448
+ function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
1449
+ const cssSelector = ".copilot-textarea.with-branding";
1450
+ (0, import_react10.useEffect)(() => {
1451
+ if (disableBranding) {
1452
+ return;
1453
+ }
1454
+ const styleEl = document.createElement("style");
1455
+ styleEl.id = "dynamic-styles";
1456
+ let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
1457
+ const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
1458
+ return `${kebabCaseKey}: ${value};`;
1459
+ }).join(" ");
1460
+ dynamicStyles += `font-style: normal; font-size: x-small;`;
1461
+ dynamicStyles += `content: "CopilotKit";`;
1462
+ dynamicStyles += `bottom: 6px;`;
1463
+ dynamicStyles += `right: 6px;`;
1464
+ dynamicStyles += `pointer-events: none;`;
1465
+ dynamicStyles += `font-weight: 200;`;
1466
+ dynamicStyles += `padding: 0;`;
1467
+ dynamicStyles += `margin: 0;`;
1468
+ dynamicStyles += `border: 0;`;
1469
+ dynamicStyles += `line-height: 1;`;
1470
+ dynamicStyles += `position: absolute;`;
1471
+ styleEl.innerHTML = `
1472
+ ${cssSelector}::after {
1473
+ ${dynamicStyles}
1474
+ }
1475
+ `;
1476
+ document.head.appendChild(styleEl);
1477
+ const textarea = document.querySelector(cssSelector);
1478
+ const handleScroll = () => {
1479
+ const styleEl2 = document.getElementById("dynamic-styles");
1480
+ if (styleEl2 && textarea) {
1481
+ const offsetFromBottom = -textarea.scrollTop + 6;
1482
+ const offsetFromRight = -textarea.scrollLeft + 6;
1483
+ styleEl2.innerHTML = `
1484
+ ${cssSelector}::after {
1485
+ ${dynamicStyles}
1486
+ bottom: ${offsetFromBottom}px;
1487
+ right: ${offsetFromRight}px;
1488
+ }
1489
+ `;
1490
+ }
1491
+ };
1492
+ textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
1493
+ return () => {
1494
+ var _a;
1495
+ (_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
1496
+ textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
1497
+ };
1498
+ }, [disableBranding, suggestionStyleAugmented]);
1499
+ }
1500
+
1501
+ // src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
1502
+ var import_react11 = require("react");
1503
+ var import_slate_react4 = require("slate-react");
1504
+ var import_slate9 = require("slate");
1505
+
1506
+ // src/lib/editor-to-text.ts
1507
+ var import_slate8 = require("slate");
1508
+ function nodeChildrenToTextComponents(editor, nodes) {
1509
+ const indeciesOfInlineElements = new Set(
1510
+ nodes.map((node, index) => {
1511
+ if (import_slate8.Element.isElement(node) && editor.isInline(node)) {
1512
+ return index;
1513
+ }
1514
+ return -1;
1515
+ }).filter((index) => index !== -1)
1516
+ );
1517
+ const nonIgnorableItems = nodes.filter((node, index) => {
1518
+ const isInline = indeciesOfInlineElements.has(index);
1519
+ if (isInline) {
1520
+ return false;
1521
+ }
1522
+ const isNeighbourOfInline = indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
1523
+ if (isNeighbourOfInline) {
1524
+ return node.text !== "";
1525
+ }
1526
+ return true;
1527
+ });
1528
+ return nonIgnorableItems.map((node) => {
1529
+ if (import_slate8.Element.isElement(node)) {
1530
+ switch (node.type) {
1531
+ case "paragraph":
1532
+ return nodeChildrenToTextComponents(editor, node.children);
1533
+ case "suggestion":
1534
+ return [];
1535
+ }
1536
+ } else {
1537
+ return [node];
1538
+ }
1539
+ }).reduce((acc, val) => acc.concat(val), []);
1540
+ }
1541
+ var editorToText = (editor) => {
1542
+ const flattened = nodeChildrenToTextComponents(editor, editor.children);
1543
+ const text = flattened.map((textComponent) => textComponent.text).join("\n");
1544
+ return text;
1545
+ };
1546
+
1547
+ // src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx
1548
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1549
+ function TrackerTextEditedSinceLastCursorMovement(props) {
1550
+ const cursorState = (0, import_slate_react4.useSlateSelector)((state) => ({
1551
+ selection: state.selection,
1552
+ text: editorToText(state)
1553
+ }));
1554
+ const previousState = usePrevious(cursorState);
1555
+ (0, import_react11.useEffect)(() => {
1556
+ if (!previousState) {
1557
+ return;
1558
+ }
1559
+ if (cursorChangedWithoutTextChanged(previousState, cursorState)) {
1560
+ props.setCursorMovedSinceLastTextChange(true);
1561
+ }
1562
+ }, [props.setCursorMovedSinceLastTextChange, cursorState]);
1563
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, {});
1564
+ }
1565
+ var cursorChangedWithoutTextChanged = (prev, next) => {
1566
+ const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);
1567
+ const isTextSame = prev.text === next.text;
1568
+ return isSelectionChanged && isTextSame;
1569
+ };
1570
+ var isSelectionEqual = (a, b) => {
1571
+ if (!a && !b)
1572
+ return true;
1573
+ if (!a || !b)
1574
+ return false;
1575
+ return import_slate9.Range.equals(a, b);
1576
+ };
1577
+ function usePrevious(value) {
1578
+ const ref = (0, import_react11.useRef)();
1579
+ (0, import_react11.useEffect)(() => {
1580
+ ref.current = value;
1581
+ });
1582
+ return ref.current;
1583
+ }
1584
+
1585
+ // src/components/base-copilot-textarea/base-copilot-textarea.tsx
1586
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1587
+ var BaseCopilotTextarea = import_react12.default.forwardRef(
1588
+ (props, ref) => {
1589
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(HoveringEditorProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), { ref })) });
1590
+ }
1591
+ );
1592
+ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1593
+ (props, ref) => {
1594
+ const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
1595
+ const valueOnInitialRender = (0, import_react12.useMemo)(() => {
1596
+ var _a2;
1597
+ return (_a2 = props.value) != null ? _a2 : "";
1598
+ }, []);
1599
+ const [lastKnownFullEditorText, setLastKnownFullEditorText] = (0, import_react12.useState)(valueOnInitialRender);
1600
+ const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = (0, import_react12.useState)(false);
1601
+ const initialValue = (0, import_react12.useMemo)(() => {
1602
+ return [
1603
+ {
1604
+ type: "paragraph",
1605
+ children: [{ text: valueOnInitialRender }]
1606
+ }
1607
+ ];
1608
+ }, [valueOnInitialRender]);
1609
+ const editor = useCopilotTextareaEditor();
1610
+ const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } = useHoveringEditorContext();
1611
+ const insertText = (0, import_react12.useCallback)(
1612
+ (autosuggestion) => {
1613
+ import_slate10.Editor.insertText(editor, autosuggestion.text, {
1614
+ at: autosuggestion.point
1615
+ });
1616
+ },
1617
+ [editor]
1618
+ );
1619
+ const shouldDisableAutosuggestions = (
1620
+ // textarea is manually disabled:
1621
+ autosuggestionsConfig.disabled || // hovering editor is displayed:
1622
+ hoveringEditorIsDisplayed || // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
1623
+ cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
1624
+ );
1625
+ const {
1626
+ currentAutocompleteSuggestion,
1627
+ onChangeHandler: onChangeHandlerForAutocomplete,
1628
+ onKeyDownHandler: onKeyDownHandlerForAutocomplete,
1629
+ onTouchStartHandler: onTouchStartHandlerForAutocomplete
1630
+ } = useAutosuggestions(
1631
+ autosuggestionsConfig.debounceTime,
1632
+ autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,
1633
+ autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,
1634
+ autosuggestionsConfig.apiConfig.autosuggestionsFunction,
1635
+ insertText,
1636
+ autosuggestionsConfig.disableWhenEmpty,
1637
+ shouldDisableAutosuggestions
1638
+ );
1639
+ const onKeyDownHandlerForHoveringEditor = (0, import_react12.useCallback)(
1640
+ (event) => {
1641
+ var _a2;
1642
+ if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, (_a2 = props.shortcut) != null ? _a2 : "k")) {
1643
+ event.preventDefault();
1644
+ setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
1645
+ }
1646
+ },
1647
+ [
1648
+ hoveringEditorIsDisplayed,
1649
+ setHoveringEditorIsDisplayed,
1650
+ autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress
1651
+ ]
1652
+ );
1653
+ (0, import_react12.useEffect)(() => {
1654
+ clearAutocompletionsFromEditor(editor);
1655
+ if (currentAutocompleteSuggestion) {
1656
+ addAutocompletionsToEditor(
1657
+ editor,
1658
+ currentAutocompleteSuggestion.text,
1659
+ currentAutocompleteSuggestion.point
1660
+ );
1661
+ }
1662
+ }, [currentAutocompleteSuggestion]);
1663
+ const suggestionStyleAugmented = (0, import_react12.useMemo)(() => {
1664
+ return __spreadValues({
1665
+ fontStyle: "italic",
1666
+ color: "gray"
1667
+ }, props.suggestionsStyle);
1668
+ }, [props.suggestionsStyle]);
1669
+ const renderElementMemoized = (0, import_react12.useMemo)(() => {
1670
+ return makeRenderElementFunction(suggestionStyleAugmented);
1671
+ }, [suggestionStyleAugmented]);
1672
+ const renderPlaceholderMemoized = (0, import_react12.useMemo)(() => {
1673
+ const placeholderStyleSlatejsOverrides = {
1674
+ top: void 0
1675
+ };
1676
+ const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
1677
+ return makeRenderPlaceholderFunction(placeholderStyleAugmented);
1678
+ }, [props.placeholderStyle]);
1679
+ (0, import_react12.useEffect)(() => {
1680
+ var _a2, _b;
1681
+ if (props.value === lastKnownFullEditorText) {
1682
+ return;
1683
+ }
1684
+ setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
1685
+ replaceEditorText(editor, (_b = props.value) != null ? _b : "");
1686
+ }, [props.value]);
1687
+ const _a = props, {
1688
+ placeholderStyle,
1689
+ value,
1690
+ hoverMenuClassname,
1691
+ onValueChange,
1692
+ baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
1693
+ className,
1694
+ onChange,
1695
+ onKeyDown,
1696
+ disableBranding
1697
+ } = _a, propsToForward = __objRest(_a, [
1698
+ "placeholderStyle",
1699
+ "value",
1700
+ "hoverMenuClassname",
1701
+ "onValueChange",
1702
+ "baseAutosuggestionsConfig",
1703
+ "className",
1704
+ "onChange",
1705
+ "onKeyDown",
1706
+ "disableBranding"
1707
+ ]);
1708
+ useAddBrandingCss(suggestionStyleAugmented, disableBranding);
1709
+ usePopulateCopilotTextareaRef(editor, ref);
1710
+ const moddedClassName = (() => {
1711
+ const baseClassName = "copilot-textarea";
1712
+ const brandingClass = disableBranding ? "no-branding" : "with-branding";
1713
+ const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
1714
+ const mergedClassName = (0, import_tailwind_merge2.twMerge)(defaultTailwindClassName, className != null ? className : "");
1715
+ return `${baseClassName} ${brandingClass} ${mergedClassName}`;
1716
+ })();
1717
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1718
+ import_slate_react5.Slate,
1719
+ {
1720
+ editor,
1721
+ initialValue,
1722
+ onChange: (value2) => {
1723
+ var _a2, _b;
1724
+ const newEditorState = getTextAroundCollapsedCursor(editor);
1725
+ const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
1726
+ setLastKnownFullEditorText((prev) => {
1727
+ if (prev !== fullEditorText) {
1728
+ setCursorMovedSinceLastTextChange(false);
1729
+ }
1730
+ return fullEditorText;
1731
+ });
1732
+ onChangeHandlerForAutocomplete(newEditorState);
1733
+ (_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
1734
+ (_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
1735
+ },
1736
+ children: [
1737
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1738
+ TrackerTextEditedSinceLastCursorMovement,
1739
+ {
1740
+ setCursorMovedSinceLastTextChange
1741
+ }
1742
+ ),
1743
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1744
+ HoveringToolbar,
1745
+ {
1746
+ apiConfig: autosuggestionsConfig.apiConfig,
1747
+ contextCategories: autosuggestionsConfig.contextCategories,
1748
+ hoverMenuClassname
1749
+ }
1750
+ ),
1751
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1752
+ import_slate_react5.Editable,
1753
+ __spreadValues({
1754
+ renderElement: renderElementMemoized,
1755
+ renderPlaceholder: renderPlaceholderMemoized,
1756
+ onKeyDown: (event) => {
1757
+ var _a2;
1758
+ onKeyDownHandlerForHoveringEditor(event);
1759
+ onKeyDownHandlerForAutocomplete(event);
1760
+ (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
1761
+ },
1762
+ onTouchStart: (event) => {
1763
+ onTouchStartHandlerForAutocomplete(event);
1764
+ },
1765
+ "data-testid": "copilot-textarea-editable",
1766
+ className: moddedClassName,
1767
+ onBlur: (ev) => {
1768
+ var _a2;
1769
+ (_a2 = props.onBlur) == null ? void 0 : _a2.call(props, ev);
1770
+ clearAutocompletionsFromEditor(editor);
1771
+ }
1772
+ }, propsToForward)
1773
+ )
1774
+ ]
1775
+ }
1776
+ );
1777
+ }
1778
+ );
1779
+ function makeSemiFakeReactTextAreaEvent(currentText) {
1780
+ return {
1781
+ target: {
1782
+ value: currentText,
1783
+ type: "copilot-textarea"
1784
+ },
1785
+ currentTarget: {
1786
+ value: currentText,
1787
+ type: "copilot-textarea"
1788
+ }
1789
+ };
1790
+ }
1791
+ // Annotate the CommonJS export names for ESM import in node:
1792
+ 0 && (module.exports = {
1793
+ BaseCopilotTextarea
1794
+ });
1795
+ //# sourceMappingURL=base-copilot-textarea.js.map