@copilotkit/react-textarea 0.21.0-alpha.5 → 0.21.0-alpha.7

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