@copilotkit/react-textarea 1.51.4 → 1.51.5-next.1

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