@copilotkit/react-textarea 1.51.4-next.7 → 1.51.4

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 (250) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +18 -12
  3. package/dist/{chunk-D47EKHIF.mjs → chunk-2X3CZVEP.mjs} +9 -3
  4. package/dist/chunk-2X3CZVEP.mjs.map +1 -0
  5. package/dist/{chunk-GU5LTWGL.mjs → chunk-3WLGLZTY.mjs} +19 -13
  6. package/dist/chunk-3WLGLZTY.mjs.map +1 -0
  7. package/dist/{chunk-DRV2FOHZ.mjs → chunk-7GZWOXE4.mjs} +2 -2
  8. package/dist/chunk-7GZWOXE4.mjs.map +1 -0
  9. package/dist/{chunk-NAFNY4FL.mjs → chunk-7V4ORVQX.mjs} +1 -1
  10. package/dist/chunk-7V4ORVQX.mjs.map +1 -0
  11. package/dist/{chunk-ECR45NSD.mjs → chunk-A6YGJFQI.mjs} +9 -2
  12. package/dist/chunk-A6YGJFQI.mjs.map +1 -0
  13. package/dist/{chunk-WGWQRALG.mjs → chunk-AHNPJMBR.mjs} +10 -3
  14. package/dist/chunk-AHNPJMBR.mjs.map +1 -0
  15. package/dist/{chunk-VSVQZUPW.mjs → chunk-ARLBRSB7.mjs} +23 -7
  16. package/dist/chunk-ARLBRSB7.mjs.map +1 -0
  17. package/dist/{chunk-72GJNLCO.mjs → chunk-AZ7RF6ED.mjs} +5 -5
  18. package/dist/chunk-AZ7RF6ED.mjs.map +1 -0
  19. package/dist/{chunk-I72DKFHD.mjs → chunk-CFCMZVQ2.mjs} +29 -7
  20. package/dist/chunk-CFCMZVQ2.mjs.map +1 -0
  21. package/dist/{chunk-T6MTDQZ7.mjs → chunk-CMKGYQFX.mjs} +1 -1
  22. package/dist/chunk-CMKGYQFX.mjs.map +1 -0
  23. package/dist/{chunk-DFTV4TST.mjs → chunk-DZMQBOPG.mjs} +1 -1
  24. package/dist/chunk-DZMQBOPG.mjs.map +1 -0
  25. package/dist/{chunk-CLGAJCZ5.mjs → chunk-E7C63KQP.mjs} +10 -6
  26. package/dist/chunk-E7C63KQP.mjs.map +1 -0
  27. package/dist/{chunk-GQN2HYFJ.mjs → chunk-EGBZSVLK.mjs} +5 -2
  28. package/dist/{chunk-GQN2HYFJ.mjs.map → chunk-EGBZSVLK.mjs.map} +1 -1
  29. package/dist/{chunk-3QJOFG3V.mjs → chunk-FTG7P3NP.mjs} +1 -1
  30. package/dist/chunk-FTG7P3NP.mjs.map +1 -0
  31. package/dist/{chunk-KMVGEY7Q.mjs → chunk-IBZTDP72.mjs} +9 -4
  32. package/dist/chunk-IBZTDP72.mjs.map +1 -0
  33. package/dist/{chunk-4PDYALMP.mjs → chunk-LYNGBKJR.mjs} +9 -3
  34. package/dist/chunk-LYNGBKJR.mjs.map +1 -0
  35. package/dist/{chunk-DL3JWL2E.mjs → chunk-M7GTVHFB.mjs} +26 -8
  36. package/dist/chunk-M7GTVHFB.mjs.map +1 -0
  37. package/dist/chunk-MQBPYOOZ.mjs +97 -0
  38. package/dist/chunk-MQBPYOOZ.mjs.map +1 -0
  39. package/dist/{chunk-6SGWO63I.mjs → chunk-MQXYWOE2.mjs} +3 -3
  40. package/dist/chunk-MQXYWOE2.mjs.map +1 -0
  41. package/dist/{chunk-F2ULK22F.mjs → chunk-NFMCLTJU.mjs} +1 -1
  42. package/dist/chunk-NFMCLTJU.mjs.map +1 -0
  43. package/dist/{chunk-F6RLSVG3.mjs → chunk-O4WCM57A.mjs} +1 -1
  44. package/dist/chunk-O4WCM57A.mjs.map +1 -0
  45. package/dist/{chunk-4NHVQZ67.mjs → chunk-PDFIUPCS.mjs} +1 -1
  46. package/dist/chunk-PDFIUPCS.mjs.map +1 -0
  47. package/dist/{chunk-7NOLZ5T3.mjs → chunk-SWX3MRZ4.mjs} +31 -22
  48. package/dist/chunk-SWX3MRZ4.mjs.map +1 -0
  49. package/dist/{chunk-QJNFNPWH.mjs → chunk-TGN3YVSO.mjs} +2 -2
  50. package/dist/chunk-TGN3YVSO.mjs.map +1 -0
  51. package/dist/{chunk-LYB4B6MK.mjs → chunk-UB4Y22EF.mjs} +4 -2
  52. package/dist/chunk-UB4Y22EF.mjs.map +1 -0
  53. package/dist/{chunk-ZQSEYPNN.mjs → chunk-UIBUYQPG.mjs} +7 -2
  54. package/dist/chunk-UIBUYQPG.mjs.map +1 -0
  55. package/dist/{chunk-AJ5OMEXM.mjs → chunk-VBPZTMXB.mjs} +2 -2
  56. package/dist/{chunk-EJGGLWWR.mjs → chunk-VH7INUR5.mjs} +1 -1
  57. package/dist/{chunk-EJGGLWWR.mjs.map → chunk-VH7INUR5.mjs.map} +1 -1
  58. package/dist/{chunk-7LSRNPNI.mjs → chunk-VVRGAA43.mjs} +1 -1
  59. package/dist/chunk-VVRGAA43.mjs.map +1 -0
  60. package/dist/{chunk-YLFAIYRY.mjs → chunk-VYLLLBUP.mjs} +1 -1
  61. package/dist/chunk-VYLLLBUP.mjs.map +1 -0
  62. package/dist/{chunk-2QDCE7PD.mjs → chunk-WXKPRNNO.mjs} +1 -1
  63. package/dist/chunk-WXKPRNNO.mjs.map +1 -0
  64. package/dist/{chunk-JLOABKLH.mjs → chunk-YINY56BI.mjs} +2 -2
  65. package/dist/{chunk-23Q6A46J.mjs → chunk-ZBP4SABT.mjs} +22 -8
  66. package/dist/chunk-ZBP4SABT.mjs.map +1 -0
  67. package/dist/{chunk-H5ZNEKUR.mjs → chunk-ZWI5KPQ5.mjs} +2 -2
  68. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +154 -86
  69. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  70. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +29 -29
  71. package/dist/components/base-copilot-textarea/render-element.js.map +1 -1
  72. package/dist/components/base-copilot-textarea/render-element.mjs +1 -1
  73. package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -1
  74. package/dist/components/base-copilot-textarea/render-placeholder.mjs +1 -1
  75. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -1
  76. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +2 -2
  77. package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -1
  78. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +1 -1
  79. package/dist/components/copilot-textarea/copilot-textarea.js +190 -95
  80. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  81. package/dist/components/copilot-textarea/copilot-textarea.mjs +34 -34
  82. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +1 -1
  83. package/dist/components/hovering-toolbar/hovering-editor-provider.js +3 -1
  84. package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -1
  85. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +1 -1
  86. package/dist/components/hovering-toolbar/hovering-toolbar-components.js +57 -63
  87. package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -1
  88. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +1 -1
  89. package/dist/components/hovering-toolbar/hovering-toolbar.js +117 -77
  90. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
  91. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +15 -15
  92. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +60 -14
  93. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
  94. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +11 -11
  95. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +60 -14
  96. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
  97. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +12 -12
  98. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +1 -1
  99. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +14 -3
  100. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -1
  101. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +3 -3
  102. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +60 -14
  103. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
  104. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +12 -12
  105. package/dist/components/index.js +190 -95
  106. package/dist/components/index.js.map +1 -1
  107. package/dist/components/index.mjs +34 -34
  108. package/dist/components/manual-ui/chip-with-icon.d.ts +1 -1
  109. package/dist/components/manual-ui/chip-with-icon.js +13 -2
  110. package/dist/components/manual-ui/chip-with-icon.js.map +1 -1
  111. package/dist/components/manual-ui/chip-with-icon.mjs +13 -2
  112. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  113. package/dist/components/source-search-box/source-search-box.js +28 -5
  114. package/dist/components/source-search-box/source-search-box.js.map +1 -1
  115. package/dist/components/source-search-box/source-search-box.mjs +4 -4
  116. package/dist/components/ui/button.js +7 -1
  117. package/dist/components/ui/button.js.map +1 -1
  118. package/dist/components/ui/button.mjs +2 -2
  119. package/dist/components/ui/command.js +47 -9
  120. package/dist/components/ui/command.js.map +1 -1
  121. package/dist/components/ui/command.mjs +3 -3
  122. package/dist/components/ui/dialog.js +27 -5
  123. package/dist/components/ui/dialog.js.map +1 -1
  124. package/dist/components/ui/dialog.mjs +2 -2
  125. package/dist/components/ui/label.js +7 -1
  126. package/dist/components/ui/label.js.map +1 -1
  127. package/dist/components/ui/label.mjs +2 -2
  128. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +18 -4
  129. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -1
  130. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +4 -4
  131. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -1
  132. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +2 -2
  133. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -1
  134. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +2 -2
  135. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +6 -1
  136. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -1
  137. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +1 -1
  138. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +25 -7
  139. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -1
  140. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +1 -1
  141. package/dist/hooks/misc/use-autosize-textarea.js.map +1 -1
  142. package/dist/hooks/misc/use-autosize-textarea.mjs +1 -1
  143. package/dist/index.js +190 -95
  144. package/dist/index.js.map +1 -1
  145. package/dist/index.mjs +35 -35
  146. package/dist/index.umd.js +16 -16
  147. package/dist/index.umd.js.map +1 -1
  148. package/dist/lib/debouncer.js.map +1 -1
  149. package/dist/lib/debouncer.mjs +1 -1
  150. package/dist/lib/editor-to-text.js.map +1 -1
  151. package/dist/lib/editor-to-text.mjs +1 -1
  152. package/dist/lib/get-text-around-cursor.js.map +1 -1
  153. package/dist/lib/get-text-around-cursor.mjs +1 -1
  154. package/dist/lib/slatejs-edits/clear-autocompletions.js +4 -1
  155. package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -1
  156. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +1 -1
  157. package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -1
  158. package/dist/lib/slatejs-edits/with-partial-history.mjs +1 -1
  159. package/dist/lib/stream-promise-flatten.js.map +1 -1
  160. package/dist/lib/stream-promise-flatten.mjs +1 -1
  161. package/dist/lib/utils.js.map +1 -1
  162. package/dist/lib/utils.mjs +1 -1
  163. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -1
  164. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
  165. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +3 -3
  166. package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -1
  167. package/dist/types/autosuggestions-config/editing-api-config.mjs +1 -1
  168. package/dist/types/autosuggestions-config/index.js.map +1 -1
  169. package/dist/types/autosuggestions-config/index.mjs +3 -3
  170. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -1
  171. package/dist/types/base/base-autosuggestions-config.js.map +1 -1
  172. package/dist/types/base/base-autosuggestions-config.mjs +1 -1
  173. package/dist/types/base/base-copilot-textarea-props.js.map +1 -1
  174. package/dist/types/base/editor-autocomplete-state.js.map +1 -1
  175. package/dist/types/base/editor-autocomplete-state.mjs +2 -2
  176. package/dist/types/base/index.js.map +1 -1
  177. package/dist/types/base/index.mjs +1 -1
  178. package/dist/types/index.js.map +1 -1
  179. package/dist/types/index.mjs +3 -3
  180. package/package.json +8 -8
  181. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +30 -10
  182. package/src/components/base-copilot-textarea/render-element.tsx +6 -2
  183. package/src/components/base-copilot-textarea/render-placeholder.tsx +3 -1
  184. package/src/components/base-copilot-textarea/use-add-branding-css.tsx +3 -1
  185. package/src/components/copilot-textarea/copilot-textarea.tsx +15 -9
  186. package/src/components/hovering-toolbar/hovering-editor-provider.tsx +3 -1
  187. package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +63 -52
  188. package/src/components/hovering-toolbar/hovering-toolbar.tsx +21 -5
  189. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +13 -7
  190. package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +7 -2
  191. package/src/components/manual-ui/chip-with-icon.tsx +12 -3
  192. package/src/components/source-search-box/source-search-box.tsx +12 -2
  193. package/src/components/ui/button.tsx +13 -5
  194. package/src/components/ui/command.tsx +17 -4
  195. package/src/components/ui/dialog.tsx +23 -5
  196. package/src/components/ui/label.tsx +7 -2
  197. package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +35 -9
  198. package/src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx +5 -1
  199. package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +5 -1
  200. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +9 -2
  201. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +24 -6
  202. package/src/hooks/misc/use-autosize-textarea.tsx +4 -1
  203. package/src/lib/debouncer.ts +3 -1
  204. package/src/lib/editor-to-text.ts +5 -2
  205. package/src/lib/get-text-around-cursor.ts +14 -2
  206. package/src/lib/slatejs-edits/clear-autocompletions.ts +4 -1
  207. package/src/lib/slatejs-edits/with-partial-history.ts +10 -3
  208. package/src/lib/stream-promise-flatten.ts +3 -1
  209. package/src/lib/utils.ts +6 -2
  210. package/src/types/autosuggestions-config/autosuggestions-config-user-specified.tsx +3 -2
  211. package/src/types/autosuggestions-config/autosuggestions-config.tsx +20 -5
  212. package/src/types/autosuggestions-config/editing-api-config.tsx +2 -1
  213. package/src/types/autosuggestions-config/subtypes/make-system-prompt.ts +4 -1
  214. package/src/types/base/base-autosuggestions-config.tsx +10 -4
  215. package/src/types/base/base-copilot-textarea-props.tsx +4 -2
  216. package/tsconfig.json +1 -1
  217. package/tsup.config.ts +5 -1
  218. package/dist/chunk-23Q6A46J.mjs.map +0 -1
  219. package/dist/chunk-2IWVZ4PP.mjs +0 -103
  220. package/dist/chunk-2IWVZ4PP.mjs.map +0 -1
  221. package/dist/chunk-2QDCE7PD.mjs.map +0 -1
  222. package/dist/chunk-3QJOFG3V.mjs.map +0 -1
  223. package/dist/chunk-4NHVQZ67.mjs.map +0 -1
  224. package/dist/chunk-4PDYALMP.mjs.map +0 -1
  225. package/dist/chunk-6SGWO63I.mjs.map +0 -1
  226. package/dist/chunk-72GJNLCO.mjs.map +0 -1
  227. package/dist/chunk-7LSRNPNI.mjs.map +0 -1
  228. package/dist/chunk-7NOLZ5T3.mjs.map +0 -1
  229. package/dist/chunk-CLGAJCZ5.mjs.map +0 -1
  230. package/dist/chunk-D47EKHIF.mjs.map +0 -1
  231. package/dist/chunk-DFTV4TST.mjs.map +0 -1
  232. package/dist/chunk-DL3JWL2E.mjs.map +0 -1
  233. package/dist/chunk-DRV2FOHZ.mjs.map +0 -1
  234. package/dist/chunk-ECR45NSD.mjs.map +0 -1
  235. package/dist/chunk-F2ULK22F.mjs.map +0 -1
  236. package/dist/chunk-F6RLSVG3.mjs.map +0 -1
  237. package/dist/chunk-GU5LTWGL.mjs.map +0 -1
  238. package/dist/chunk-I72DKFHD.mjs.map +0 -1
  239. package/dist/chunk-KMVGEY7Q.mjs.map +0 -1
  240. package/dist/chunk-LYB4B6MK.mjs.map +0 -1
  241. package/dist/chunk-NAFNY4FL.mjs.map +0 -1
  242. package/dist/chunk-QJNFNPWH.mjs.map +0 -1
  243. package/dist/chunk-T6MTDQZ7.mjs.map +0 -1
  244. package/dist/chunk-VSVQZUPW.mjs.map +0 -1
  245. package/dist/chunk-WGWQRALG.mjs.map +0 -1
  246. package/dist/chunk-YLFAIYRY.mjs.map +0 -1
  247. package/dist/chunk-ZQSEYPNN.mjs.map +0 -1
  248. /package/dist/{chunk-AJ5OMEXM.mjs.map → chunk-VBPZTMXB.mjs.map} +0 -0
  249. /package/dist/{chunk-JLOABKLH.mjs.map → chunk-YINY56BI.mjs.map} +0 -0
  250. /package/dist/{chunk-H5ZNEKUR.mjs.map → chunk-ZWI5KPQ5.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/copilot-textarea/copilot-textarea.tsx"],"sourcesContent":["/**\n * <br/>\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotTextarea.gif\" width=\"500\" />\n *\n * `<CopilotTextarea>` is a React component that acts as a drop-in replacement for the standard `<textarea>`,\n * offering enhanced autocomplete features powered by AI. It is context-aware, integrating seamlessly with the\n * [`useCopilotReadable`](/reference/hooks/useCopilotReadable) hook to provide intelligent suggestions based on the application context.\n *\n * In addition, it provides a hovering editor window (available by default via `Cmd + K` on Mac and `Ctrl + K` on Windows) that allows the user to\n * suggest changes to the text, for example providing a summary or rephrasing the text.\n *\n * ## Example\n *\n * ```tsx\n * import { CopilotTextarea } from '@copilotkit/react-textarea';\n * import \"@copilotkit/react-textarea/styles.css\";\n *\n * <CopilotTextarea\n * autosuggestionsConfig={{\n * textareaPurpose:\n * \"the body of an email message\",\n * chatApiConfigs: {},\n * }}\n * />\n * ```\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-textarea](https://npmjs.com/package/@copilotkit/react-textarea) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-textarea\"\\\n * npm install @copilotkit/react-core @copilotkit/react-textarea\n * ```\n *\n * ### Usage\n *\n * Use the CopilotTextarea component in your React application similarly to a standard `<textarea />`,\n * with additional configurations for AI-powered features.\n *\n * For example:\n *\n * ```tsx\n * import { useState } from \"react\";\n * import { CopilotTextarea } from \"@copilotkit/react-textarea\";\n * import \"@copilotkit/react-textarea/styles.css\";\n *\n * export function ExampleComponent() {\n * const [text, setText] = useState(\"\");\n *\n * return (\n * <CopilotTextarea\n * className=\"custom-textarea-class\"\n * value={text}\n * onValueChange={(value: string) => setText(value)}\n * placeholder=\"Enter your text here...\"\n * autosuggestionsConfig={{\n * textareaPurpose: \"Provide context or purpose of the textarea.\",\n * chatApiConfigs: {\n * suggestionsApiConfig: {\n * maxTokens: 20,\n * stop: [\".\", \"?\", \"!\"],\n * },\n * },\n * }}\n * />\n * );\n * }\n * ```\n *\n * ### Look & Feel\n *\n * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:\n * ```tsx title=\"YourRootComponent.tsx\"\n * ...\n * import \"@copilotkit/react-textarea/styles.css\"; // [!code highlight]\n *\n * export function YourRootComponent() {\n * return (\n * <CopilotKit>\n * ...\n * </CopilotKit>\n * );\n * }\n * ```\n * For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.\n * */\nimport React from \"react\";\nimport { useMakeStandardAutosuggestionFunction } from \"../../hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport {\n AutosuggestionsConfig,\n defaultAutosuggestionsConfig,\n} from \"../../types/autosuggestions-config\";\nimport { BaseCopilotTextarea } from \"../base-copilot-textarea/base-copilot-textarea\";\nimport { useMakeStandardInsertionOrEditingFunction } from \"../../hooks/make-autosuggestions-function/use-make-standard-insertion-function\";\nimport merge from \"lodash.merge\";\nimport { AutosuggestionsConfigUserSpecified } from \"../../types/autosuggestions-config/autosuggestions-config-user-specified\";\n\n// Like the base copilot textarea props,\n// but with baseAutosuggestionsConfig replaced with autosuggestionsConfig.\nexport interface CopilotTextareaProps extends Omit<\n BaseCopilotTextareaProps,\n \"baseAutosuggestionsConfig\"\n> {\n /**\n * Configuration settings for the autosuggestions feature.\n * For full reference, [check the interface on GitHub](https://github.com/CopilotKit/CopilotKit/blob/main/src/v1.x/packages/react-textarea/src/types/base/base-copilot-textarea-props.tsx#L8).\n *\n * <PropertyReference name=\"textareaPurpose\" type=\"string\" required={true} >\n * The purpose of the text area in plain text.\n *\n * Example: *\"The body of the email response\"*\n * </PropertyReference>\n *\n * <PropertyReference name=\"chatApiConfigs\" type=\"ChatApiConfigs\" >\n * The chat API configurations.\n *\n * <strong>NOTE:</strong> You must provide specify at least one of `suggestionsApiConfig` or `insertionApiConfig`.\n *\n * <PropertyReference name=\"suggestionsApiConfig\" type=\"SuggestionsApiConfig\">\n * For full reference, please [click here](https://github.com/CopilotKit/CopilotKit/blob/main/src/v1.x/packages/react-textarea/src/types/autosuggestions-config/suggestions-api-config.tsx#L4).\n * </PropertyReference>\n * <PropertyReference name=\"insertionApiConfig\" type=\"InsertionApiConfig\">\n * For full reference, please [click here](https://github.com/CopilotKit/CopilotKit/blob/main/src/v1.x/packages/react-textarea/src/types/autosuggestions-config/insertions-api-config.tsx#L4).\n * </PropertyReference>\n * </PropertyReference>\n *\n * <PropertyReference name=\"disabled\" type=\"boolean\" >\n * Whether the textarea is disabled.\n * </PropertyReference>\n *\n * <PropertyReference name=\"disableBranding\" type=\"boolean\" >\n * Whether to disable the CopilotKit branding.\n * </PropertyReference>\n *\n * <PropertyReference name=\"placeholderStyle\" type=\"React.CSSProperties\" >\n * Specifies the CSS styles to apply to the placeholder text.\n * </PropertyReference>\n *\n * <PropertyReference name=\"suggestionsStyle\" type=\"React.CSSProperties\" >\n * Specifies the CSS styles to apply to the suggestions list.\n * </PropertyReference>\n *\n * <PropertyReference name=\"hoverMenuClassname\" type=\"string\" >\n * A class name to apply to the editor popover window.\n * </PropertyReference>\n *\n * <PropertyReference name=\"value\" type=\"string\" >\n * The initial value of the textarea. Can be controlled via `onValueChange`.\n * </PropertyReference>\n *\n * <PropertyReference name=\"onValueChange\" type=\"(value: string) => void\" >\n * Callback invoked when the value of the textarea changes.\n * </PropertyReference>\n *\n * <PropertyReference name=\"onChange\" type=\"(event: React.ChangeEvent<HTMLTextAreaElement>) => void\" >\n * Callback invoked when a `change` event is triggered on the textarea element.\n * </PropertyReference>\n *\n * <PropertyReference name=\"shortcut\" type=\"string\" >\n * The shortcut to use to open the editor popover window. Default is `\"Cmd-k\"`.\n * </PropertyReference>\n */\n autosuggestionsConfig: AutosuggestionsConfigUserSpecified;\n}\n\n/**\n * A copilot textarea that uses the standard autosuggestions function.\n */\nexport const CopilotTextarea = React.forwardRef(\n (props: CopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>) => {\n // separate the AutosuggestionsConfigUserSpecified from the rest of the props\n const {\n autosuggestionsConfig: autosuggestionsConfigUserSpecified,\n ...forwardedProps\n } = props;\n\n const autosuggestionsConfig: AutosuggestionsConfig = merge(\n defaultAutosuggestionsConfig,\n autosuggestionsConfigUserSpecified,\n );\n\n const autosuggestionsFunction = useMakeStandardAutosuggestionFunction(\n autosuggestionsConfig.textareaPurpose,\n autosuggestionsConfig.contextCategories,\n autosuggestionsConfig.chatApiConfigs.suggestionsApiConfig,\n );\n\n const insertionOrEditingFunction =\n useMakeStandardInsertionOrEditingFunction(\n autosuggestionsConfig.textareaPurpose,\n autosuggestionsConfig.contextCategories,\n autosuggestionsConfig.chatApiConfigs.insertionApiConfig,\n autosuggestionsConfig.chatApiConfigs.editingApiConfig,\n );\n\n return (\n <>\n <BaseCopilotTextarea\n ref={ref}\n {...forwardedProps}\n baseAutosuggestionsConfig={{\n ...autosuggestionsConfig,\n apiConfig: {\n insertionOrEditingFunction: insertionOrEditingFunction,\n autosuggestionsFunction: autosuggestionsFunction,\n },\n }}\n />\n </>\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwFA,OAAO,WAAW;AAUlB,OAAO,WAAW;AAsGZ,mBACE,WADF;AA5BC,IAAM,kBAAkB,MAAM;AAAA,EACnC,CAAC,OAA6B,QAA+C;AAE3E,UAGI,YAFF;AAAA,6BAAuB;AAAA,IAhL7B,IAkLQ,IADC,2BACD,IADC;AAAA,MADH;AAAA;AAIF,UAAM,wBAA+C;AAAA,MACnD;AAAA,MACA;AAAA,IACF;AAEA,UAAM,0BAA0B;AAAA,MAC9B,sBAAsB;AAAA,MACtB,sBAAsB;AAAA,MACtB,sBAAsB,eAAe;AAAA,IACvC;AAEA,UAAM,6BACJ;AAAA,MACE,sBAAsB;AAAA,MACtB,sBAAsB;AAAA,MACtB,sBAAsB,eAAe;AAAA,MACrC,sBAAsB,eAAe;AAAA,IACvC;AAEF,WACE,gCACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,SACI,iBAFL;AAAA,QAGC,2BAA2B,iCACtB,wBADsB;AAAA,UAEzB,WAAW;AAAA,YACT;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AACF;","names":[]}
@@ -11,7 +11,10 @@ function clearAutocompletionsFromEditor(editor) {
11
11
  try {
12
12
  Transforms.removeNodes(editor, { at: path });
13
13
  } catch (e) {
14
- console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
14
+ console.log(
15
+ "CopilotTextarea.clearAutocompletionsFromEditor: error removing node",
16
+ e
17
+ );
15
18
  }
16
19
  }
17
20
  }
@@ -19,4 +22,4 @@ function clearAutocompletionsFromEditor(editor) {
19
22
  export {
20
23
  clearAutocompletionsFromEditor
21
24
  };
22
- //# sourceMappingURL=chunk-GQN2HYFJ.mjs.map
25
+ //# sourceMappingURL=chunk-EGBZSVLK.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/slatejs-edits/clear-autocompletions.ts"],"sourcesContent":["import { Element, Node, Path, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function clearAutocompletionsFromEditor(editor: CustomEditor) {\n // clear previous suggestion\n const paths: Path[] = [];\n for (const [node, path] of Node.nodes(editor)) {\n if (Element.isElement(node) && node.type === \"suggestion\") {\n paths.push(path);\n }\n }\n for (const path of paths) {\n try {\n Transforms.removeNodes(editor, { at: path });\n } catch (e) {\n console.log(\"CopilotTextarea.clearAutocompletionsFromEditor: error removing node\", e);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,MAAY,kBAAkB;AAGzC,SAAS,+BAA+B,QAAsB;AAEnE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,GAAG;AAC7C,QAAI,QAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,cAAc;AACzD,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,iBAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,GAAP;AACA,cAAQ,IAAI,uEAAuE,CAAC;AAAA,IACtF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/lib/slatejs-edits/clear-autocompletions.ts"],"sourcesContent":["import { Element, Node, Path, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function clearAutocompletionsFromEditor(editor: CustomEditor) {\n // clear previous suggestion\n const paths: Path[] = [];\n for (const [node, path] of Node.nodes(editor)) {\n if (Element.isElement(node) && node.type === \"suggestion\") {\n paths.push(path);\n }\n }\n for (const path of paths) {\n try {\n Transforms.removeNodes(editor, { at: path });\n } catch (e) {\n console.log(\n \"CopilotTextarea.clearAutocompletionsFromEditor: error removing node\",\n e,\n );\n }\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,MAAY,kBAAkB;AAGzC,SAAS,+BAA+B,QAAsB;AAEnE,QAAM,QAAgB,CAAC;AACvB,aAAW,CAAC,MAAM,IAAI,KAAK,KAAK,MAAM,MAAM,GAAG;AAC7C,QAAI,QAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,cAAc;AACzD,YAAM,KAAK,IAAI;AAAA,IACjB;AAAA,EACF;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,iBAAW,YAAY,QAAQ,EAAE,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,GAAP;AACA,cAAQ;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -22,4 +22,4 @@ function makeRenderPlaceholderFunction(placeholderStyle) {
22
22
  export {
23
23
  makeRenderPlaceholderFunction
24
24
  };
25
- //# sourceMappingURL=chunk-3QJOFG3V.mjs.map
25
+ //# sourceMappingURL=chunk-FTG7P3NP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/render-placeholder.tsx"],"sourcesContent":["import { RenderPlaceholderProps } from \"slate-react\";\nimport React from \"react\";\n\nexport type RenderPlaceholderFunction = (\n props: RenderPlaceholderProps,\n) => React.JSX.Element;\n\nexport function makeRenderPlaceholderFunction(\n placeholderStyle?: React.CSSProperties,\n): RenderPlaceholderFunction {\n return (props: RenderPlaceholderProps) => {\n const { style, ...restAttributes } = props.attributes;\n\n return (\n <div\n {...restAttributes}\n style={{\n ...style,\n ...placeholderStyle,\n }}\n >\n {props.children}\n </div>\n );\n };\n}\n"],"mappings":";;;;;;;AAcM;AAPC,SAAS,8BACd,kBAC2B;AAC3B,SAAO,CAAC,UAAkC;AACxC,UAAqC,WAAM,YAAnC,QAXZ,IAWyC,IAAnB,2BAAmB,IAAnB,CAAV;AAER,WACE;AAAA,MAAC;AAAA,uCACK,iBADL;AAAA,QAEC,OAAO,kCACF,QACA;AAAA,QAGJ,gBAAM;AAAA;AAAA,IACT;AAAA,EAEJ;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Label
3
- } from "./chunk-D47EKHIF.mjs";
3
+ } from "./chunk-2X3CZVEP.mjs";
4
4
 
5
5
  // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
6
6
  import Chip from "@mui/material/Chip/Chip.js";
@@ -18,7 +18,9 @@ var IncludedFilesPreview = ({
18
18
  {
19
19
  filePointer,
20
20
  onDelete: () => {
21
- setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
21
+ setIncludedFiles(
22
+ (prev) => prev.filter((fp) => fp !== filePointer)
23
+ );
22
24
  }
23
25
  },
24
26
  `file-${filePointer.sourceApplication}.${filePointer.name}`
@@ -26,7 +28,10 @@ var IncludedFilesPreview = ({
26
28
  }) })
27
29
  ] });
28
30
  };
29
- var FileChipPreview = ({ filePointer, onDelete }) => {
31
+ var FileChipPreview = ({
32
+ filePointer,
33
+ onDelete
34
+ }) => {
30
35
  return /* @__PURE__ */ jsx(
31
36
  Chip,
32
37
  {
@@ -48,4 +53,4 @@ export {
48
53
  IncludedFilesPreview,
49
54
  FileChipPreview
50
55
  };
51
- //# sourceMappingURL=chunk-KMVGEY7Q.mjs.map
56
+ //# sourceMappingURL=chunk-IBZTDP72.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx"],"sourcesContent":["import { DocumentPointer } from \"@copilotkit/react-core\";\nimport { Label } from \"../../ui/label\";\nimport React from \"react\";\nimport Chip from \"@mui/material/Chip/Chip.js\";\nimport Avatar from \"@mui/material/Avatar/Avatar.js\";\n\nexport interface IncludedFilesPreviewProps {\n includedFiles: DocumentPointer[];\n setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;\n}\n\nexport const IncludedFilesPreview = ({\n includedFiles,\n setIncludedFiles,\n}: IncludedFilesPreviewProps) => {\n return (\n <div className=\"flex flex-col gap-2 mt-2\">\n <Label className=\"\">Included context:</Label>\n <div className=\"flex flex-wrap gap-2\">\n {includedFiles.map((filePointer, index) => {\n return (\n <FileChipPreview\n key={`file-${filePointer.sourceApplication}.${filePointer.name}`}\n filePointer={filePointer}\n onDelete={() => {\n setIncludedFiles((prev) =>\n prev.filter((fp) => fp !== filePointer),\n );\n }}\n />\n );\n })}\n </div>\n </div>\n );\n};\n\nexport interface FileChipPreviewProps {\n filePointer: DocumentPointer;\n onDelete: () => void;\n}\n\nexport const FileChipPreview = ({\n filePointer,\n onDelete,\n}: FileChipPreviewProps) => {\n return (\n <Chip\n label={filePointer.name}\n onDelete={onDelete}\n avatar={\n <Avatar\n src={filePointer.iconImageUri}\n alt={filePointer.sourceApplication}\n sx={{ backgroundColor: \"transparent\" }}\n ></Avatar>\n }\n />\n );\n};\n"],"mappings":";;;;;AAGA,OAAO,UAAU;AACjB,OAAO,YAAY;AAYf,SACE,KADF;AALG,IAAM,uBAAuB,CAAC;AAAA,EACnC;AAAA,EACA;AACF,MAAiC;AAC/B,SACE,qBAAC,SAAI,WAAU,4BACb;AAAA,wBAAC,SAAM,WAAU,IAAG,+BAAiB;AAAA,IACrC,oBAAC,SAAI,WAAU,wBACZ,wBAAc,IAAI,CAAC,aAAa,UAAU;AACzC,aACE;AAAA,QAAC;AAAA;AAAA,UAEC;AAAA,UACA,UAAU,MAAM;AACd;AAAA,cAAiB,CAAC,SAChB,KAAK,OAAO,CAAC,OAAO,OAAO,WAAW;AAAA,YACxC;AAAA,UACF;AAAA;AAAA,QANK,QAAQ,YAAY,qBAAqB,YAAY;AAAA,MAO5D;AAAA,IAEJ,CAAC,GACH;AAAA,KACF;AAEJ;AAOO,IAAM,kBAAkB,CAAC;AAAA,EAC9B;AAAA,EACA;AACF,MAA4B;AAC1B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,YAAY;AAAA,MACnB;AAAA,MACA,QACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAK,YAAY;AAAA,UACjB,KAAK,YAAY;AAAA,UACjB,IAAI,EAAE,iBAAiB,cAAc;AAAA;AAAA,MACtC;AAAA;AAAA,EAEL;AAEJ;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cn
3
- } from "./chunk-YLFAIYRY.mjs";
3
+ } from "./chunk-VYLLLBUP.mjs";
4
4
  import {
5
5
  __objRest,
6
6
  __spreadValues
@@ -40,7 +40,13 @@ var Button = React.forwardRef(
40
40
  (_a, ref) => {
41
41
  var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
42
42
  const Comp = asChild ? Slot : "button";
43
- return /* @__PURE__ */ jsx(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
43
+ return /* @__PURE__ */ jsx(
44
+ Comp,
45
+ __spreadValues({
46
+ className: cn(buttonVariants({ variant, size, className })),
47
+ ref
48
+ }, props)
49
+ );
44
50
  }
45
51
  );
46
52
  Button.displayName = "Button";
@@ -49,4 +55,4 @@ export {
49
55
  buttonVariants,
50
56
  Button
51
57
  };
52
- //# sourceMappingURL=chunk-4PDYALMP.mjs.map
58
+ //# sourceMappingURL=chunk-LYNGBKJR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/ui/button.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst buttonVariants = cva(\n \"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\",\n {\n variants: {\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive:\n \"bg-destructive text-destructive-foreground hover:bg-destructive/90\",\n outline:\n \"border border-input bg-background hover:bg-accent hover:text-accent-foreground\",\n secondary:\n \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost: \"hover:bg-accent hover:text-accent-foreground\",\n link: \"text-primary underline-offset-4 hover:underline\",\n },\n size: {\n default: \"h-10 px-4 py-2\",\n sm: \"h-9 rounded-md px-3\",\n lg: \"h-11 rounded-md px-8\",\n icon: \"h-10 w-10\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n },\n);\n\nexport interface ButtonProps\n extends\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n asChild?: boolean;\n}\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n className={cn(buttonVariants({ variant, size, className }))}\n ref={ref}\n {...props}\n />\n );\n },\n);\nButton.displayName = \"Button\";\n\nexport { Button, buttonVariants };\n"],"mappings":";;;;;;;;;AAAA,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,WAA8B;AA4CjC;AAxCN,IAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,aACE;AAAA,QACF,SACE;AAAA,QACF,WACE;AAAA,QACF,OAAO;AAAA,QACP,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AASA,IAAM,SAAe;AAAA,EACnB,CAAC,IAAyD,QAAQ;AAAjE,iBAAE,aAAW,SAAS,MAAM,UAAU,MA3CzC,IA2CG,IAAgD,kBAAhD,IAAgD,CAA9C,aAAW,WAAS,QAAM;AAC3B,UAAM,OAAO,UAAU,OAAO;AAC9B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,GAAG,eAAe,EAAE,SAAS,MAAM,UAAU,CAAC,CAAC;AAAA,QAC1D;AAAA,SACI;AAAA,IACN;AAAA,EAEJ;AACF;AACA,OAAO,cAAc;","names":[]}
@@ -19,8 +19,10 @@ import {
19
19
  CopilotRequestType
20
20
  } from "@copilotkit/runtime-client-gql";
21
21
  function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
22
- const runtimeClient = { generateCopilotResponse: (...args) => {
23
- } };
22
+ const runtimeClient = {
23
+ generateCopilotResponse: (...args) => {
24
+ }
25
+ };
24
26
  const { getContextString, copilotApiConfig } = useCopilotContext();
25
27
  const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
26
28
  function runtimeClientResponseToStringStream(responsePromise) {
@@ -36,7 +38,9 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
36
38
  if (done) {
37
39
  break;
38
40
  }
39
- const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
41
+ const messages = convertGqlOutputToMessages(
42
+ value.generateCopilotResponse.messages
43
+ );
40
44
  let newContent = "";
41
45
  for (const message of messages) {
42
46
  if (message.isTextMessage()) {
@@ -87,7 +91,9 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
87
91
  actions: [],
88
92
  url: window.location.href
89
93
  },
90
- messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
94
+ messages: convertMessagesToGqlInput(
95
+ filterAgentStateMessages(messages)
96
+ ),
91
97
  metadata: {
92
98
  requestType: CopilotRequestType.TextareaCompletion
93
99
  }
@@ -137,7 +143,9 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
137
143
  actions: [],
138
144
  url: window.location.href
139
145
  },
140
- messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
146
+ messages: convertMessagesToGqlInput(
147
+ filterAgentStateMessages(messages)
148
+ ),
141
149
  metadata: {
142
150
  requestType: CopilotRequestType.TextareaCompletion
143
151
  }
@@ -154,9 +162,19 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
154
162
  const insertionOrEditingFunction = useCallback(
155
163
  (editorState, insertionPrompt, documents, abortSignal) => __async(this, null, function* () {
156
164
  if (editorState.selectedText === "") {
157
- return yield insertionFunction(editorState, insertionPrompt, documents, abortSignal);
165
+ return yield insertionFunction(
166
+ editorState,
167
+ insertionPrompt,
168
+ documents,
169
+ abortSignal
170
+ );
158
171
  } else {
159
- return yield editingFunction(editorState, insertionPrompt, documents, abortSignal);
172
+ return yield editingFunction(
173
+ editorState,
174
+ insertionPrompt,
175
+ documents,
176
+ abortSignal
177
+ );
160
178
  }
161
179
  }),
162
180
  [insertionFunction, editingFunction]
@@ -167,4 +185,4 @@ function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCateg
167
185
  export {
168
186
  useMakeStandardInsertionOrEditingFunction
169
187
  };
170
- //# sourceMappingURL=chunk-DL3JWL2E.mjs.map
188
+ //# sourceMappingURL=chunk-M7GTVHFB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx"],"sourcesContent":["import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from \"@copilotkit/shared\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback } from \"react\";\nimport {\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\nimport { retry } from \"../../lib/retry\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../types/base/autosuggestions-bare-function\";\nimport { InsertionsApiConfig } from \"../../types/autosuggestions-config/insertions-api-config\";\nimport { EditingApiConfig } from \"../../types/autosuggestions-config/editing-api-config\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\n\n/**\n * Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n * The function takes in the text before and after the cursor, and an abort signal.\n * It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.\n * The function returns the suggestion from the API response.\n *\n * @param textareaPurpose - The purpose of the textarea. This is included in the system message.\n * @param apiEndpoint - The API endpoint to send the autosuggestion request to.\n * @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.\n * @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.\n * @param contextCategories - The categories of context strings we want to include. By default, we include the (default) \"global\" context category.\n * @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.\n */\nexport function useMakeStandardInsertionOrEditingFunction(\n textareaPurpose: string,\n contextCategories: string[],\n insertionApiConfig: InsertionsApiConfig,\n editingApiConfig: EditingApiConfig,\n): Generator_InsertionOrEditingSuggestion {\n const runtimeClient: any = {\n generateCopilotResponse: (...args: any[]) => {},\n };\n const { getContextString, copilotApiConfig } = useCopilotContext();\n const headers = {\n ...(copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }\n : {}),\n };\n\n async function runtimeClientResponseToStringStream(\n responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,\n ) {\n const messagesStream = runtimeClient.asStream(responsePromise);\n\n return new ReadableStream({\n async start(controller) {\n const reader = messagesStream.getReader();\n let sentContent = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n const messages = convertGqlOutputToMessages(\n value.generateCopilotResponse.messages,\n );\n\n let newContent = \"\";\n\n for (const message of messages) {\n if (message.isTextMessage()) {\n newContent += message.content;\n }\n }\n if (newContent) {\n const contentToSend = newContent.slice(sentContent.length);\n controller.enqueue(contentToSend);\n sentContent += contentToSend;\n }\n }\n controller.close();\n },\n });\n }\n\n const insertionFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: insertionApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n }),\n ...insertionApiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,\n }),\n ];\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(\n filterAgentStateMessages(messages),\n ),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.properties,\n signal: abortSignal,\n }),\n );\n });\n\n return res;\n },\n [insertionApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const editingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n editingPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n const res = await retry(async () => {\n const messages: Message[] = [\n new TextMessage({\n role: Role.System,\n content: editingApiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(documents, contextCategories),\n ),\n }),\n ...editingApiConfig.fewShotMessages,\n new TextMessage({\n role: Role.User,\n content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,\n }),\n new TextMessage({\n role: Role.User,\n content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,\n }),\n ];\n\n return runtimeClientResponseToStringStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [],\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(\n filterAgentStateMessages(messages),\n ),\n metadata: {\n requestType: CopilotRequestType.TextareaCompletion,\n },\n },\n properties: copilotApiConfig.properties,\n signal: abortSignal,\n }),\n );\n });\n\n return res;\n },\n [editingApiConfig, getContextString, contextCategories, textareaPurpose],\n );\n\n const insertionOrEditingFunction = useCallback(\n async (\n editorState: EditingEditorState,\n insertionPrompt: string,\n documents: DocumentPointer[],\n abortSignal: AbortSignal,\n ) => {\n if (editorState.selectedText === \"\") {\n return await insertionFunction(\n editorState,\n insertionPrompt,\n documents,\n abortSignal,\n );\n } else {\n return await editingFunction(\n editorState,\n insertionPrompt,\n documents,\n abortSignal,\n );\n }\n },\n [insertionFunction, editingFunction],\n );\n\n return insertionOrEditingFunction;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,2CAA2C;AACpD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B;AAAA,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,YAAY;AAAA,UACtC,CAAC;AAAA,UACD,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,oBAAoB,YAAY;AAAA,UAC3C,CAAC;AAAA,UACD,IAAI,YAAY;AAAA,YACd,MAAM,KAAK;AAAA,YACX,SAAS,kBAAkB;AAAA,UAC7B,CAAC;AAAA,QACH;AAEA,eAAO;AAAA,UACL,cAAc,wBAAwB;AAAA,YACpC,MAAM;AAAA,cACJ,UAAU;AAAA,gBACR,SAAS,CAAC;AAAA,gBACV,KAAK,OAAO,SAAS;AAAA,cACvB;AAAA,cACA,UAAU;AAAA,gBACR,yBAAyB,QAAQ;AAAA,cACnC;AAAA,cACA,UAAU;AAAA,gBACR,aAAa,mBAAmB;AAAA,cAClC;AAAA,YACF;AAAA,YACA,YAAY,iBAAiB;AAAA,YAC7B,QAAQ;AAAA,UACV,CAAC;AAAA,QACH;AAAA,MACF,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,kBAAkB,kBAAkB,mBAAmB,eAAe;AAAA,EACzE;AAEA,QAAM,6BAA6B;AAAA,IACjC,CACE,aACA,iBACA,WACA,gBACG;AACH,UAAI,YAAY,iBAAiB,IAAI;AACnC,eAAO,MAAM;AAAA,UACX;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,OAAO;AACL,eAAO,MAAM;AAAA,UACX;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,mBAAmB,eAAe;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,97 @@
1
+ import {
2
+ __objRest,
3
+ __spreadProps,
4
+ __spreadValues
5
+ } from "./chunk-MRXNTQOX.mjs";
6
+
7
+ // src/components/hovering-toolbar/hovering-toolbar-components.tsx
8
+ import { css, cx } from "@emotion/css";
9
+ import React from "react";
10
+ import ReactDOM from "react-dom";
11
+ import { jsx } from "react/jsx-runtime";
12
+ var Button = React.forwardRef((_a, ref) => {
13
+ var _b = _a, { className, active, reversed } = _b, props = __objRest(_b, ["className", "active", "reversed"]);
14
+ return /* @__PURE__ */ jsx(
15
+ "span",
16
+ __spreadProps(__spreadValues({}, props), {
17
+ ref,
18
+ className: cx(
19
+ className,
20
+ css`
21
+ cursor: pointer;
22
+ color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
23
+ `
24
+ )
25
+ })
26
+ );
27
+ });
28
+ var Icon = React.forwardRef((_a, ref) => {
29
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
30
+ return /* @__PURE__ */ jsx(
31
+ "span",
32
+ __spreadProps(__spreadValues({}, props), {
33
+ ref,
34
+ className: cx(
35
+ "material-icons",
36
+ className,
37
+ css`
38
+ font-size: 18px;
39
+ vertical-align: text-bottom;
40
+ `
41
+ )
42
+ })
43
+ );
44
+ });
45
+ var Menu = React.forwardRef((_a, ref) => {
46
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
47
+ return /* @__PURE__ */ jsx(
48
+ "div",
49
+ __spreadProps(__spreadValues({}, props), {
50
+ "data-testid": "menu",
51
+ ref,
52
+ className: cx(
53
+ className,
54
+ css`
55
+ & > * {
56
+ display: inline-block;
57
+ }
58
+
59
+ & > * + * {
60
+ margin-left: 15px;
61
+ }
62
+ `
63
+ )
64
+ })
65
+ );
66
+ });
67
+ var Portal = ({ children }) => {
68
+ return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
69
+ };
70
+ var Toolbar = React.forwardRef((_a, ref) => {
71
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
72
+ return /* @__PURE__ */ jsx(
73
+ Menu,
74
+ __spreadProps(__spreadValues({}, props), {
75
+ ref,
76
+ className: cx(
77
+ className,
78
+ css`
79
+ position: relative;
80
+ padding: 1px 18px 17px;
81
+ margin: 0 -20px;
82
+ border-bottom: 2px solid #eee;
83
+ margin-bottom: 20px;
84
+ `
85
+ )
86
+ })
87
+ );
88
+ });
89
+
90
+ export {
91
+ Button,
92
+ Icon,
93
+ Menu,
94
+ Portal,
95
+ Toolbar
96
+ };
97
+ //# sourceMappingURL=chunk-MQBPYOOZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/hovering-toolbar/hovering-toolbar-components.tsx"],"sourcesContent":["import { css, cx } from \"@emotion/css\";\nimport React, { PropsWithChildren, Ref } from \"react\";\nimport ReactDOM from \"react-dom\";\n\ninterface BaseProps {\n className?: string;\n [key: string]: unknown;\n}\n\nexport const Button = React.forwardRef<\n HTMLSpanElement,\n PropsWithChildren<{ active: boolean; reversed: boolean } & BaseProps>\n>(({ className, active, reversed, ...props }, ref) => (\n <span\n {...props}\n ref={ref}\n className={cx(\n className as string,\n css`\n cursor: pointer;\n color: ${reversed\n ? active\n ? \"white\"\n : \"#aaa\"\n : active\n ? \"black\"\n : \"#ccc\"};\n `,\n )}\n />\n));\n\nexport const Icon = React.forwardRef<\n HTMLSpanElement,\n PropsWithChildren<BaseProps>\n>(({ className, ...props }, ref) => (\n <span\n {...props}\n ref={ref}\n className={cx(\n \"material-icons\",\n className as string,\n css`\n font-size: 18px;\n vertical-align: text-bottom;\n `,\n )}\n />\n));\n\nexport const Menu = React.forwardRef<\n HTMLDivElement,\n PropsWithChildren<BaseProps>\n>(({ className, ...props }, ref) => {\n return (\n <div\n {...props}\n data-testid=\"menu\"\n ref={ref}\n className={cx(\n className as string,\n css`\n & > * {\n display: inline-block;\n }\n\n & > * + * {\n margin-left: 15px;\n }\n `,\n )}\n />\n );\n});\nexport const Portal = ({ children }: { children: React.ReactNode }) => {\n return typeof document === \"object\"\n ? ReactDOM.createPortal(children, document.body)\n : null;\n};\n\nexport const Toolbar = React.forwardRef<\n HTMLDivElement,\n PropsWithChildren<BaseProps>\n>(({ className, ...props }, ref) => (\n <Menu\n {...props}\n ref={ref}\n className={cx(\n className as string,\n css`\n position: relative;\n padding: 1px 18px 17px;\n margin: 0 -20px;\n border-bottom: 2px solid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A,IAAC;AAAA,qCACK,QADL;AAAA,MAEC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOF;AAAA;AAAA,EACF;AAAA,CACD;","names":[]}
@@ -6,10 +6,10 @@ import {
6
6
  } from "./chunk-QFXR6DOA.mjs";
7
7
  import {
8
8
  defaultEditingApiConfig
9
- } from "./chunk-EJGGLWWR.mjs";
9
+ } from "./chunk-VH7INUR5.mjs";
10
10
  import {
11
11
  defaultBaseAutosuggestionsConfig
12
- } from "./chunk-F6RLSVG3.mjs";
12
+ } from "./chunk-O4WCM57A.mjs";
13
13
  import {
14
14
  __spreadProps,
15
15
  __spreadValues
@@ -29,4 +29,4 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
29
29
  export {
30
30
  defaultAutosuggestionsConfig
31
31
  };
32
- //# sourceMappingURL=chunk-6SGWO63I.mjs.map
32
+ //# sourceMappingURL=chunk-MQXYWOE2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/autosuggestions-config/autosuggestions-config.tsx"],"sourcesContent":["import {\n BaseAutosuggestionsConfig,\n defaultBaseAutosuggestionsConfig,\n} from \"../base\";\nimport {\n SuggestionsApiConfig,\n defaultSuggestionsApiConfig,\n} from \"./suggestions-api-config\";\nimport {\n InsertionsApiConfig,\n defaultInsertionsApiConfig,\n} from \"./insertions-api-config\";\nimport {\n EditingApiConfig,\n defaultEditingApiConfig,\n} from \"./editing-api-config\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\n\n// Like the base autosuggestions config, with 2 additional fields:\n// 1. contextCategories: string[] | undefined;\n// 2. instead of apiConfigs, we have chatApiConfigs: a higher-level abstraction that uses a ChatGPT-like API endpoint.\nexport interface AutosuggestionsConfig extends Omit<\n BaseAutosuggestionsConfig,\n \"apiConfig\"\n> {\n contextCategories: string[];\n chatApiConfigs: {\n suggestionsApiConfig: SuggestionsApiConfig;\n insertionApiConfig: InsertionsApiConfig;\n editingApiConfig: EditingApiConfig;\n };\n}\n\nexport const defaultAutosuggestionsConfig: Omit<\n AutosuggestionsConfig,\n \"textareaPurpose\" | \"apiEndpoint\"\n> = {\n ...defaultBaseAutosuggestionsConfig,\n contextCategories: defaultCopilotContextCategories,\n chatApiConfigs: {\n suggestionsApiConfig: defaultSuggestionsApiConfig,\n insertionApiConfig: defaultInsertionsApiConfig,\n editingApiConfig: defaultEditingApiConfig,\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,SAAS,uCAAuC;AAiBzC,IAAM,+BAGT,iCACC,mCADD;AAAA,EAEF,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,IACd,sBAAsB;AAAA,IACtB,oBAAoB;AAAA,IACpB,kBAAkB;AAAA,EACpB;AACF;","names":[]}
@@ -36,4 +36,4 @@ var SuggestionElement = (props) => {
36
36
  export {
37
37
  makeRenderElementFunction
38
38
  };
39
- //# sourceMappingURL=chunk-F2ULK22F.mjs.map
39
+ //# sourceMappingURL=chunk-NFMCLTJU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/render-element.tsx"],"sourcesContent":["import { RenderElementProps } from \"slate-react\";\nimport React from \"react\";\n\nexport type RenderElementFunction = (\n props: RenderElementProps,\n) => React.JSX.Element;\n\nexport function makeRenderElementFunction(\n suggestionsStyle: React.CSSProperties,\n): RenderElementFunction {\n return (props: RenderElementProps) => {\n switch (props.element.type) {\n case \"paragraph\":\n return <DefaultElement {...props} />;\n case \"suggestion\":\n return (\n <SuggestionElement {...props} suggestionsStyle={suggestionsStyle} />\n );\n }\n };\n}\n\nconst DefaultElement = (props: RenderElementProps) => {\n return <div {...props.attributes}>{props.children}</div>;\n};\nconst SuggestionElement = (\n props: RenderElementProps & {\n suggestionsStyle: React.CSSProperties;\n },\n) => {\n return (\n <span\n {...props.attributes}\n style={{\n ...props.suggestionsStyle,\n }}\n data-testid=\"suggestion\"\n contentEditable={false}\n >\n {props.children /* https://github.com/ianstormtaylor/slate/issues/3930 */}\n {props.element.type === \"suggestion\" && props.element.content}\n </span>\n );\n};\n"],"mappings":";;;;;;AAae,cAkBX,YAlBW;AANR,SAAS,0BACd,kBACuB;AACvB,SAAO,CAAC,UAA8B;AACpC,YAAQ,MAAM,QAAQ,MAAM;AAAA,MAC1B,KAAK;AACH,eAAO,oBAAC,mCAAmB,MAAO;AAAA,MACpC,KAAK;AACH,eACE,oBAAC,oDAAsB,QAAtB,EAA6B,mBAAoC;AAAA,IAExE;AAAA,EACF;AACF;AAEA,IAAM,iBAAiB,CAAC,UAA8B;AACpD,SAAO,oBAAC,wCAAQ,MAAM,aAAd,EAA2B,gBAAM,WAAS;AACpD;AACA,IAAM,oBAAoB,CACxB,UAGG;AACH,SACE;AAAA,IAAC;AAAA,qCACK,MAAM,aADX;AAAA,MAEC,OAAO,mBACF,MAAM;AAAA,MAEX,eAAY;AAAA,MACZ,iBAAiB;AAAA,MAEhB;AAAA,cAAM;AAAA,QACN,MAAM,QAAQ,SAAS,gBAAgB,MAAM,QAAQ;AAAA;AAAA;AAAA,EACxD;AAEJ;","names":[]}
@@ -27,4 +27,4 @@ var defaultBaseAutosuggestionsConfig = {
27
27
  export {
28
28
  defaultBaseAutosuggestionsConfig
29
29
  };
30
- //# sourceMappingURL=chunk-F6RLSVG3.mjs.map
30
+ //# sourceMappingURL=chunk-O4WCM57A.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/base/base-autosuggestions-config.tsx"],"sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\nimport { isMacOS } from \"@copilotkit/shared\";\n\n/**\n * @interface BaseAutosuggestionsConfig\n *\n * @property {string} textareaPurpose - The purpose of the textarea. This is used to guide the autosuggestions.\n *\n * @property {string[]} contextCategories - The categories of context to consider when providing autosuggestions.\n *\n * @property {number} debounceTime - The amount of time (in milliseconds) to wait before triggering autosuggestions after the user has stopped typing.\n *\n * @property {BaseCopilotTextareaApiConfig} apiConfig - The configuration for the API that provides the autosuggestions.\n *\n * @property {boolean} disableWhenEmpty - Whether to disable autosuggestions when the textarea is empty.\n *\n * @property {boolean} disabled - Whether to disable autosuggestions entirely.\n *\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable autosuggestions when the user moves the cursor without changing the text.\n *\n * @property {boolean} temporarilyDisableNotTrustedEvents - Temporarily disable autosuggestions after change event from non-trusted sources (like text insertion from autocomplete plugins)\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the current autosuggestion based on a key press event. By default, the Tab key is used to accept the autosuggestion. Example code:\n *\n * ```typescript\n * const defaultShouldAcceptAutosuggestionOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.key === \"Tab\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.TouchEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the current autosuggestion based on a mobile touch event. By default, the touching the end of a suggestion will accept it. Example code:\n *\n * ```typescript\n * const shouldAcceptAutosuggestionOnTouch = (event: React.TouchEvent<HTMLDivElement>) => {\n * // if tab, accept the autosuggestion\n * if (event.type === \"touchstart\") {\n * return true;\n * }\n * return false;\n * }\n * ```\n *\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event. By default, the Command + K key combination is used to toggle the hovering editor. Example code:\n *\n * ```typescript\n * const defaultShouldToggleHoveringEditorOnKeyPress = (event: React.KeyboardEvent<HTMLDivElement>) => {\n * // if command-k, toggle the hovering editor\n * if (event.key === \"k\" && event.metaKey) {\n * return true;\n * }\n * return false;\n * }\n * ```\n */\nexport interface BaseAutosuggestionsConfig {\n textareaPurpose: string;\n contextCategories: string[];\n debounceTime: number;\n apiConfig: BaseCopilotTextareaApiConfig;\n\n disableWhenEmpty: boolean;\n disabled: boolean;\n temporarilyDisableWhenMovingCursorWithoutChangingText: boolean;\n temporarilyDisableNotTrustedEvents: boolean;\n shouldAcceptAutosuggestionOnKeyPress: (\n event: React.KeyboardEvent<HTMLDivElement>,\n ) => boolean;\n shouldAcceptAutosuggestionOnTouch: (\n event: React.TouchEvent<HTMLDivElement>,\n ) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n ) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n shortcut: string,\n) => {\n const isMetaKey = isMacOS() ? event.metaKey : event.ctrlKey;\n\n // if command-k, toggle the hovering editor\n return event.key === shortcut && isMetaKey;\n};\n\nconst defaultShouldAcceptAutosuggestionOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if tab, accept the autosuggestion\n if (event.key === \"Tab\") {\n return true;\n }\n return false;\n};\n\nconst defaultShouldAcceptAutosuggestionOnTouch = () => false;\n\n/**\n * Default configuration for the BaseAutosuggestions.\n *\n * @property {number} debounceTime - The amount of time to wait before triggering the autosuggestions API call.\n * @property {string[]} contextCategories - The categories to use for context when making the autosuggestions API call.\n * @property {boolean} disableWhenEmpty - Whether to disable the autosuggestions when the textarea is empty.\n * @property {boolean} disabled - Whether to disable the autosuggestions feature entirely.\n * @property {boolean} temporarilyDisableWhenMovingCursorWithoutChangingText - Whether to temporarily disable the autosuggestions when the cursor is moved without changing the text.\n * @property {boolean} temporarilyDisableNotTrustedEvents - Temporarily disable the autosuggestions after change event from non-trusted sources (like text insertion from autocomplete plugins)\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldToggleHoveringEditorOnKeyPress - A function that determines whether to toggle the hovering editor based on a key press event.\n * @property {(event: React.KeyboardEvent<HTMLDivElement>) => boolean} shouldAcceptAutosuggestionOnKeyPress - A function that determines whether to accept the autosuggestion based on a key press event.\n * @property {() => boolean} defaultShouldAcceptAutosuggestionOnTouch - A function that determines whether to accept the autosuggestion based on a mobile touch event.\n */\n\nexport const defaultBaseAutosuggestionsConfig: Omit<\n BaseAutosuggestionsConfig,\n \"textareaPurpose\" | \"apiConfig\"\n> = {\n debounceTime: 250,\n contextCategories: defaultCopilotContextCategories,\n disableWhenEmpty: true,\n disabled: false,\n temporarilyDisableWhenMovingCursorWithoutChangingText: true,\n temporarilyDisableNotTrustedEvents: true,\n shouldToggleHoveringEditorOnKeyPress:\n defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress:\n defaultShouldAcceptAutosuggestionOnKeyPress,\n shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch,\n};\n"],"mappings":";AACA,SAAS,uCAAuC;AAChD,SAAS,eAAe;AAgFxB,IAAM,8CAA8C,CAClD,OACA,aACG;AACH,QAAM,YAAY,QAAQ,IAAI,MAAM,UAAU,MAAM;AAGpD,SAAO,MAAM,QAAQ,YAAY;AACnC;AAEA,IAAM,8CAA8C,CAClD,UACG;AAEH,MAAI,MAAM,QAAQ,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,2CAA2C,MAAM;AAgBhD,IAAM,mCAGT;AAAA,EACF,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,uDAAuD;AAAA,EACvD,oCAAoC;AAAA,EACpC,sCACE;AAAA,EACF,sCACE;AAAA,EACF,mCAAmC;AACrC;","names":[]}
@@ -105,4 +105,4 @@ export {
105
105
  withPartialHistory,
106
106
  defaultShouldSave
107
107
  };
108
- //# sourceMappingURL=chunk-4NHVQZ67.mjs.map
108
+ //# sourceMappingURL=chunk-PDFIUPCS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/slatejs-edits/with-partial-history.ts"],"sourcesContent":["import { Editor, Operation, Path, Range, Transforms } from \"slate\";\nimport { HistoryEditor } from \"slate-history\";\n\n// Copy-pasted from `https://github.com/ianstormtaylor/slate/blob/main/packages/slate-history/src/with-history.ts`\n// With one exception: the `shouldSave` function is passed in as an argument to `withPartialHistory` instead of being hardcoded\nexport type ShouldSaveToHistory = (\n op: Operation,\n prev: Operation | undefined,\n) => boolean;\n\nexport const withPartialHistory = <T extends Editor>(\n editor: T,\n shouldSave: ShouldSaveToHistory,\n) => {\n const e = editor as T & HistoryEditor;\n const { apply } = e;\n e.history = { undos: [], redos: [] };\n\n e.redo = () => {\n const { history } = e;\n const { redos } = history;\n\n if (redos.length > 0) {\n const batch = redos[redos.length - 1];\n\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n for (const op of batch.operations) {\n e.apply(op);\n }\n });\n });\n\n history.redos.pop();\n e.writeHistory(\"undos\", batch);\n }\n };\n\n e.undo = () => {\n const { history } = e;\n const { undos } = history;\n\n if (undos.length > 0) {\n const batch = undos[undos.length - 1];\n\n HistoryEditor.withoutSaving(e, () => {\n Editor.withoutNormalizing(e, () => {\n const inverseOps = batch.operations.map(Operation.inverse).reverse();\n\n for (const op of inverseOps) {\n e.apply(op);\n }\n if (batch.selectionBefore) {\n Transforms.setSelection(e, batch.selectionBefore);\n }\n });\n });\n\n e.writeHistory(\"redos\", batch);\n history.undos.pop();\n }\n };\n\n e.apply = (op: Operation) => {\n const { operations, history } = e;\n const { undos } = history;\n const lastBatch = undos[undos.length - 1];\n const lastOp =\n lastBatch && lastBatch.operations[lastBatch.operations.length - 1];\n let save = HistoryEditor.isSaving(e);\n let merge = HistoryEditor.isMerging(e);\n\n if (save == null) {\n save = shouldSave(op, lastOp);\n }\n\n if (save) {\n if (merge == null) {\n if (lastBatch == null) {\n merge = false;\n } else if (operations.length !== 0) {\n merge = true;\n } else {\n merge = shouldMerge(op, lastOp);\n }\n }\n\n if (lastBatch && merge) {\n lastBatch.operations.push(op);\n } else {\n const batch = {\n operations: [op],\n selectionBefore: e.selection,\n };\n e.writeHistory(\"undos\", batch);\n }\n\n while (undos.length > 100) {\n undos.shift();\n }\n\n history.redos = [];\n }\n\n apply(op);\n };\n\n e.writeHistory = (stack: \"undos\" | \"redos\", batch: any) => {\n e.history[stack].push(batch);\n };\n\n return e;\n};\n\n/**\n * Check whether to merge an operation into the previous operation.\n */\n\nconst shouldMerge = (op: Operation, prev: Operation | undefined): boolean => {\n if (\n prev &&\n op.type === \"insert_text\" &&\n prev.type === \"insert_text\" &&\n op.offset === prev.offset + prev.text.length &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n if (\n prev &&\n op.type === \"remove_text\" &&\n prev.type === \"remove_text\" &&\n op.offset + op.text.length === prev.offset &&\n Path.equals(op.path, prev.path)\n ) {\n return true;\n }\n\n return false;\n};\n\nexport const defaultShouldSave = (\n op: Operation,\n prev: Operation | undefined,\n): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"],"mappings":";AAAA,SAAS,QAAQ,WAAW,MAAa,kBAAkB;AAC3D,SAAS,qBAAqB;AASvB,IAAM,qBAAqB,CAChC,QACA,eACG;AACH,QAAM,IAAI;AACV,QAAM,EAAE,MAAM,IAAI;AAClB,IAAE,UAAU,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE;AAEnC,IAAE,OAAO,MAAM;AACb,UAAM,EAAE,QAAQ,IAAI;AACpB,UAAM,EAAE,MAAM,IAAI;AAElB,QAAI,MAAM,SAAS,GAAG;AACpB,YAAM,QAAQ,MAAM,MAAM,SAAS,CAAC;AAEpC,UAAI,MAAM,iBAAiB;AACzB,mBAAW,aAAa,GAAG,MAAM,eAAe;AAAA,MAClD;AAEA,oBAAc,cAAc,GAAG,MAAM;AACnC,eAAO,mB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AQ,YAAY,IAAI,MAAM;AAAA,QAChC;AAAA,MACF;AAEA,UAAI,aAAa,OAAO;AACtB,kBAAU,WAAW,KAAK,EAAE;AAAA,MAC9B,OAAO;AACL,cAAM,QAAQ;AAAA,UACZ,YAAY,CAAC,EAAE;AAAA,UACf,iBAAiB,EAAE;AAAA,QACrB;AACA,UAAE,aAAa,SAAS,KAAK;AAAA,MAC/B;AAEA,aAAO,MAAM,SAAS,KAAK;AACzB,cAAM,MAAM;AAAA,MACd;AAEA,cAAQ,QAAQ,CAAC;AAAA,IACnB;AAEA,UAAM,EAAE;AAAA,EACV;AAEA,IAAE,eAAe,CAAC,OAA0B,UAAe;AACzD,MAAE,QAAQ,KAAK,EAAE,KAAK,KAAK;AAAA,EAC7B;AAEA,SAAO;AACT;AAMA,IAAM,cAAc,CAAC,IAAe,SAAyC;AAC3E,MACE,QACA,GAAG,SAAS,iBACZ,KAAK,SAAS,iBACd,GAAG,WAAW,KAAK,SAAS,KAAK,KAAK,UACtC,KAAK,OAAO,GAAG,MAAM,KAAK,IAAI,GAC9B;AACA,WAAO;AAAA,EACT;AAEA,MACE,QACA,GAAG,SAAS,iBACZ,KAAK,SAAS,iBACd,GAAG,SAAS,GAAG,KAAK,WAAW,KAAK,UACpC,KAAK,OAAO,GAAG,MAAM,KAAK,IAAI,GAC9B;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAC/B,IACA,SACY;AACZ,MAAI,GAAG,SAAS,iBAAiB;AAC/B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
@@ -1,47 +1,47 @@
1
- import {
2
- useCopilotTextareaEditor
3
- } from "./chunk-DRV2FOHZ.mjs";
4
- import {
5
- usePopulateCopilotTextareaRef
6
- } from "./chunk-QJNFNPWH.mjs";
7
1
  import {
8
2
  addAutocompletionsToEditor
9
3
  } from "./chunk-2C7O2EVM.mjs";
10
4
  import {
11
5
  clearAutocompletionsFromEditor
12
- } from "./chunk-GQN2HYFJ.mjs";
6
+ } from "./chunk-EGBZSVLK.mjs";
7
+ import {
8
+ useAutosuggestions
9
+ } from "./chunk-ZBP4SABT.mjs";
10
+ import {
11
+ useCopilotTextareaEditor
12
+ } from "./chunk-7GZWOXE4.mjs";
13
+ import {
14
+ usePopulateCopilotTextareaRef
15
+ } from "./chunk-TGN3YVSO.mjs";
13
16
  import {
14
17
  replaceEditorText
15
18
  } from "./chunk-5UNJXFUO.mjs";
16
- import {
17
- useAutosuggestions
18
- } from "./chunk-23Q6A46J.mjs";
19
19
  import {
20
20
  useAddBrandingCss
21
- } from "./chunk-7LSRNPNI.mjs";
21
+ } from "./chunk-VVRGAA43.mjs";
22
22
  import {
23
23
  HoveringToolbar
24
- } from "./chunk-72GJNLCO.mjs";
24
+ } from "./chunk-AZ7RF6ED.mjs";
25
25
  import {
26
26
  HoveringEditorProvider,
27
27
  useHoveringEditorContext
28
- } from "./chunk-LYB4B6MK.mjs";
28
+ } from "./chunk-UB4Y22EF.mjs";
29
29
  import {
30
30
  defaultBaseAutosuggestionsConfig
31
- } from "./chunk-F6RLSVG3.mjs";
31
+ } from "./chunk-O4WCM57A.mjs";
32
32
  import {
33
33
  makeRenderElementFunction
34
- } from "./chunk-F2ULK22F.mjs";
34
+ } from "./chunk-NFMCLTJU.mjs";
35
35
  import {
36
36
  makeRenderPlaceholderFunction
37
- } from "./chunk-3QJOFG3V.mjs";
37
+ } from "./chunk-FTG7P3NP.mjs";
38
38
  import {
39
39
  TrackerTextEditedSinceLastCursorMovement
40
- } from "./chunk-JLOABKLH.mjs";
40
+ } from "./chunk-YINY56BI.mjs";
41
41
  import {
42
42
  getFullEditorTextWithNewlines,
43
43
  getTextAroundCollapsedCursor
44
- } from "./chunk-ECR45NSD.mjs";
44
+ } from "./chunk-A6YGJFQI.mjs";
45
45
  import {
46
46
  __objRest,
47
47
  __spreadProps,
@@ -78,7 +78,10 @@ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
78
78
  ];
79
79
  }, [valueOnInitialRender]);
80
80
  const editor = useCopilotTextareaEditor();
81
- const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } = useHoveringEditorContext();
81
+ const {
82
+ isDisplayed: hoveringEditorIsDisplayed,
83
+ setIsDisplayed: setHoveringEditorIsDisplayed
84
+ } = useHoveringEditorContext();
82
85
  const insertText = useCallback(
83
86
  (autosuggestion) => {
84
87
  Editor.insertText(editor, autosuggestion.text, {
@@ -111,7 +114,10 @@ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
111
114
  const onKeyDownHandlerForHoveringEditor = useCallback(
112
115
  (event) => {
113
116
  var _a2;
114
- if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event, (_a2 = props.shortcut) != null ? _a2 : "k")) {
117
+ if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(
118
+ event,
119
+ (_a2 = props.shortcut) != null ? _a2 : "k"
120
+ )) {
115
121
  event.preventDefault();
116
122
  setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
117
123
  }
@@ -183,7 +189,10 @@ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
183
189
  const baseClassName = "copilot-textarea";
184
190
  const brandingClass = disableBranding ? "no-branding" : "with-branding";
185
191
  const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
186
- const mergedClassName = twMerge(defaultTailwindClassName, className != null ? className : "");
192
+ const mergedClassName = twMerge(
193
+ defaultTailwindClassName,
194
+ className != null ? className : ""
195
+ );
187
196
  return `${baseClassName} ${brandingClass} ${mergedClassName}`;
188
197
  })();
189
198
  return /* @__PURE__ */ jsxs(
@@ -266,4 +275,4 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
266
275
  export {
267
276
  BaseCopilotTextarea
268
277
  };
269
- //# sourceMappingURL=chunk-7NOLZ5T3.mjs.map
278
+ //# sourceMappingURL=chunk-SWX3MRZ4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Descendant, Editor } from \"slate\";\nimport { Editable, Slate } from \"slate-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { useAutosuggestions } from \"../../hooks/base-copilot-textarea-implementation/use-autosuggestions\";\nimport { useCopilotTextareaEditor } from \"../../hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor\";\nimport { usePopulateCopilotTextareaRef } from \"../../hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundCollapsedCursor,\n} from \"../../lib/get-text-around-cursor\";\nimport { addAutocompletionsToEditor } from \"../../lib/slatejs-edits/add-autocompletions\";\nimport { clearAutocompletionsFromEditor } from \"../../lib/slatejs-edits/clear-autocompletions\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport {\n BaseAutosuggestionsConfig,\n defaultBaseAutosuggestionsConfig,\n} from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport \"./base-copilot-textarea.css\";\nimport { HoveringToolbar } from \"../hovering-toolbar/hovering-toolbar\";\nimport { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\nimport {\n HoveringEditorProvider,\n useHoveringEditorContext,\n} from \"../hovering-toolbar/hovering-editor-provider\";\nimport { TrackerTextEditedSinceLastCursorMovement } from \"./track-cursor-moved-since-last-text-change\";\n\n/**\n * Purpose: to be used as the `ref` type for `CopilotTextarea` and `BaseCopilotTextarea`.\n *\n * This interface extends `HTMLElement`, and is the subset of `HTMLTextAreaElement` that \"actually matters\".\n * It provides the core functionality that consumers of `HTMLTextAreaElement` need 99.9% of the time:\n * - `value`: the current value of the textarea\n * - `focus`: make the textarea focused\n * - `blur`: make the textarea unfocused\n */\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n /**\n * The current value of the textarea.\n */\n value: string;\n\n /**\n * focus on the textarea\n */\n focus: () => void;\n\n /**\n * unfocus the textarea.\n *\n * Called `blur` for syntactic compatibility with `HTMLTextAreaElement`.\n */\n blur: () => void;\n}\n\n/**\n * Not intended for direct use. Use CopilotTextarea instead.\n *\n * The `BaseCopilotTextarea` includes the basic UX component,\n * without the business logic / AI logic that makes the content useful and coherent.\n *\n * It is useful if you want to build your own backend, with fully custom business logic\n * for figuring out which contnet to fill in.\n */\nexport const BaseCopilotTextarea = React.forwardRef(\n (\n props: BaseCopilotTextareaProps,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n ) => {\n return (\n <HoveringEditorProvider>\n <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />\n </HoveringEditorProvider>\n );\n },\n);\n\n/**\n * Not intended for direct use. Use `CopilotTextarea` instead.\n *\n * This is the private core of the `BaseCopilotTextarea` component.\n * For practical purposes the implementation is cleaner assuming containment in a `HoveringEditorProviderContext`.\n *\n * Therefore we separate the core logic into this component,\n * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.\n */\nconst BaseCopilotTextareaWithHoveringContext = React.forwardRef(\n (\n props: BaseCopilotTextareaProps,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n ) => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.baseAutosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] =\n useState(valueOnInitialRender);\n const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] =\n useState(false);\n const [isUserInputActive, setIsUserInputActive] = useState(false);\n\n // // When the editor text changes, we want to reset the `textEditedSinceLastCursorMovement` state.\n // useEffect(() => {\n // setCursorMovedSinceLastTextChange(false);\n // }, [lastKnownFullEditorText]);\n\n const initialValue: Descendant[] = useMemo(() => {\n return [\n {\n type: \"paragraph\",\n children: [{ text: valueOnInitialRender }],\n },\n ];\n }, [valueOnInitialRender]);\n\n const editor = useCopilotTextareaEditor();\n\n const {\n isDisplayed: hoveringEditorIsDisplayed,\n setIsDisplayed: setHoveringEditorIsDisplayed,\n } = useHoveringEditorContext();\n\n const insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor],\n );\n\n const shouldDisableAutosuggestions =\n // textarea is manually disabled:\n autosuggestionsConfig.disabled ||\n // hovering editor is displayed:\n hoveringEditorIsDisplayed ||\n // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:\n (cursorMovedSinceLastTextChange &&\n autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText) ||\n // not user input and we want to disable non-trusted events (like text insertion from autocomplete plugins):\n (!isUserInputActive &&\n autosuggestionsConfig.temporarilyDisableNotTrustedEvents);\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n onTouchStartHandler: onTouchStartHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnTouch,\n autosuggestionsConfig.apiConfig.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n shouldDisableAutosuggestions,\n );\n\n const onKeyDownHandlerForHoveringEditor = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(\n event,\n props.shortcut ?? \"k\",\n )\n ) {\n event.preventDefault();\n setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);\n }\n },\n [\n hoveringEditorIsDisplayed,\n setHoveringEditorIsDisplayed,\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress,\n ],\n );\n\n // sync autosuggestions state with the editor\n useEffect(() => {\n clearAutocompletionsFromEditor(editor);\n if (currentAutocompleteSuggestion) {\n addAutocompletionsToEditor(\n editor,\n currentAutocompleteSuggestion.text,\n currentAutocompleteSuggestion.point,\n );\n }\n }, [currentAutocompleteSuggestion]);\n\n const suggestionStyleAugmented: React.CSSProperties = useMemo(() => {\n return {\n fontStyle: \"italic\",\n color: \"gray\",\n ...props.suggestionsStyle,\n };\n }, [props.suggestionsStyle]);\n\n const renderElementMemoized = useMemo(() => {\n return makeRenderElementFunction(suggestionStyleAugmented);\n }, [suggestionStyleAugmented]);\n\n const renderPlaceholderMemoized = useMemo(() => {\n // For some reason slateJS specifies a top value of 0, which makes for strange styling. We override this here.\n const placeholderStyleSlatejsOverrides: React.CSSProperties = {\n top: undefined,\n };\n\n const placeholderStyleAugmented: React.CSSProperties = {\n ...placeholderStyleSlatejsOverrides,\n ...props.placeholderStyle,\n };\n\n return makeRenderPlaceholderFunction(placeholderStyleAugmented);\n }, [props.placeholderStyle]);\n\n // update the editor text, but only when the value changes from outside the component\n useEffect(() => {\n if (props.value === lastKnownFullEditorText) {\n return;\n }\n\n setLastKnownFullEditorText(props.value ?? \"\");\n replaceEditorText(editor, props.value ?? \"\");\n }, [props.value]);\n\n // separate into TextareaHTMLAttributes<HTMLDivElement> and CopilotTextareaProps\n const {\n placeholderStyle,\n value,\n hoverMenuClassname,\n onValueChange,\n baseAutosuggestionsConfig: autosuggestionsConfigFromProps,\n className,\n onChange,\n onKeyDown,\n disableBranding,\n ...propsToForward\n } = props;\n\n useAddBrandingCss(suggestionStyleAugmented, disableBranding);\n usePopulateCopilotTextareaRef(editor, ref);\n\n const moddedClassName = (() => {\n const baseClassName = \"copilot-textarea\";\n const brandingClass = disableBranding ? \"no-branding\" : \"with-branding\";\n const defaultTailwindClassName = \"bg-white overflow-y-auto resize-y\";\n const mergedClassName = twMerge(\n defaultTailwindClassName,\n className ?? \"\",\n );\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCollapsedCursor(editor);\n\n const fullEditorText = newEditorState\n ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor\n : getFullEditorTextWithNewlines(editor); // we don't double-parse the editor. When `newEditorState` is null, we didn't parse the editor yet.\n\n setLastKnownFullEditorText((prev) => {\n if (prev !== fullEditorText) {\n setCursorMovedSinceLastTextChange(false);\n }\n return fullEditorText;\n });\n\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <TrackerTextEditedSinceLastCursorMovement\n setCursorMovedSinceLastTextChange={setCursorMovedSinceLastTextChange}\n />\n <HoveringToolbar\n apiConfig={autosuggestionsConfig.apiConfig}\n contextCategories={autosuggestionsConfig.contextCategories}\n hoverMenuClassname={hoverMenuClassname}\n />\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\n setIsUserInputActive(true);\n onKeyDownHandlerForHoveringEditor(event); // forward the event for internal use\n onKeyDownHandlerForAutocomplete(event); // forward the event for internal use\n props.onKeyDown?.(event); // forward the event for external use\n }}\n onTouchStart={(event) => {\n onTouchStartHandlerForAutocomplete(event); // forward the event for internal use\n }}\n data-testid=\"copilot-textarea-editable\"\n className={moddedClassName}\n onBlur={(ev) => {\n // clear autocompletion on blur\n props.onBlur?.(ev);\n clearAutocompletionsFromEditor(editor);\n setIsUserInputActive(false);\n }}\n {...propsToForward}\n />\n </Slate>\n );\n },\n);\n\n// Consumers of <textarea> expect a `onChange: (React.ChangeEvent<HTMLTextAreaElement>) => void` event handler to be passed in.\n// This is *extremely* common, and we want to support it.\n//\n// We can't support the full functionality, but in 99% of cases, the consumer only cares about the `event.target.value` property --\n// that's how they get the new value of the textarea.\n//\n// So, the tradeoff we are making is minimizing compiler complaint, with a small chance of runtime error.\n// The alternative would be defining a different onChange entrypoint (we actually do have that in `onValueChange`),\n// And starting to explain subtleties to users the moment they try to use the component for the first time for very basic functionality.\n//\n// If this proves problematic, we can always revisit this decision.\nfunction makeSemiFakeReactTextAreaEvent(\n currentText: string,\n): React.ChangeEvent<HTMLTextAreaElement> {\n return {\n target: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n currentTarget: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n } as React.ChangeEvent<HTMLTextAreaElement>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAqB,cAAc;AACnC,SAAS,UAAU,aAAa;AAChC,SAAS,eAAe;AAwEhB,cAyLF,YAzLE;AAPD,IAAM,sBAAsB,MAAM;AAAA,EACvC,CACE,OACA,QACG;AACH,WACE,oBAAC,0BACC,8BAAC,yEAA2C,QAA3C,EAAkD,MAAU,GAC/D;AAAA,EAEJ;AACF;AAWA,IAAM,yCAAyC,MAAM;AAAA,EACnD,CACE,OACA,QACG;AACH,UAAM,wBAAmD,kCACpD,mCACA,MAAM;AAGX,UAAM,uBAAuB,QAAQ,MAAG;AApG5C,UAAAA;AAoG+C,cAAAA,MAAA,MAAM,UAAN,OAAAA,MAAe;AAAA,OAAI,CAAC,CAAC;AAChE,UAAM,CAAC,yBAAyB,0BAA0B,IACxD,SAAS,oBAAoB;AAC/B,UAAM,CAAC,gCAAgC,iCAAiC,IACtE,SAAS,KAAK;AAChB,UAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAAS,KAAK;AAOhE,UAAM,eAA6B,QAAQ,MAAM;AAC/C,aAAO;AAAA,QACL;AAAA,UACE,MAAM;AAAA,UACN,UAAU,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF,GAAG,CAAC,o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;AAAA,EACF;AACF;","names":["_a","value"]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-5UNJXFUO.mjs";
4
4
  import {
5
5
  getFullEditorTextWithNewlines
6
- } from "./chunk-ECR45NSD.mjs";
6
+ } from "./chunk-A6YGJFQI.mjs";
7
7
 
8
8
  // src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts
9
9
  import React from "react";
@@ -82,4 +82,4 @@ function usePopulateCopilotTextareaRef(editor, ref) {
82
82
  export {
83
83
  usePopulateCopilotTextareaRef
84
84
  };
85
- //# sourceMappingURL=chunk-QJNFNPWH.mjs.map
85
+ //# sourceMappingURL=chunk-TGN3YVSO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts"],"sourcesContent":["import React from \"react\";\nimport { Editor } from \"slate\";\nimport { ReactEditor } from \"slate-react\";\nimport { getFullEditorTextWithNewlines } from \"../../lib/get-text-around-cursor\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { HTMLCopilotTextAreaElement } from \"../../types\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function usePopulateCopilotTextareaRef(\n editor: Editor,\n ref: React.Ref<HTMLCopilotTextAreaElement>,\n) {\n React.useImperativeHandle(ref, () => {\n class Combined {\n constructor(\n private customMethods: CustomMethods,\n private editorHtmlElement: HTMLElement,\n ) {}\n\n [key: string]: any;\n\n get(target: any, propKey: string): any {\n if (this.isKeyOfCustomMethods(propKey)) {\n const value = this.customMethods[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.customMethods);\n }\n return value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n const value = this.editorHtmlElement[propKey];\n if (typeof value === \"function\") {\n return value.bind(this.editorHtmlElement);\n }\n return value;\n }\n }\n\n set(target: any, propKey: string, value: any): boolean {\n if (this.isKeyOfCustomMethods(propKey)) {\n (this.customMethods as any)[propKey] = value;\n } else if (this.isKeyOfHTMLElement(propKey)) {\n (this.editorHtmlElement as any)[propKey] = value;\n } else {\n // Default behavior (optional)\n target[propKey] = value;\n }\n return true;\n }\n\n private isKeyOfCustomMethods(key: string): key is keyof CustomMethods {\n return key in this.customMethods;\n }\n\n private isKeyOfHTMLElement(key: string): key is keyof HTMLElement {\n return key in this.editorHtmlElement;\n }\n }\n\n const handler = {\n get(target: any, propKey: keyof CustomMethods | keyof HTMLElement) {\n return target.get(target, propKey);\n },\n set(\n target: any,\n propKey: keyof CustomMethods | keyof HTMLElement,\n value: any,\n ) {\n return target.set(target, propKey, value);\n },\n };\n\n class CustomMethods {\n constructor(private editor: CustomEditor) {}\n\n focus() {\n ReactEditor.focus(this.editor);\n }\n\n blur() {\n ReactEditor.blur(this.editor);\n }\n\n get value() {\n return getFullEditorTextWithNewlines(this.editor);\n }\n set value(value: string) {\n replaceEditorText(this.editor, value);\n }\n }\n\n const editorHtmlElement = ReactEditor.toDOMNode(editor, editor);\n const customMethods = new CustomMethods(editor);\n\n const combined = new Combined(customMethods, editorHtmlElement);\n return new Proxy(combined, handler);\n }, [editor]);\n}\n"],"mappings":";;;;;;;;AAAA,OAAO,WAAW;AAElB,SAAS,mBAAmB;AAMrB,SAAS,8BACd,QACA,KACA;AACA,QAAM,oBAAoB,KAAK,MAAM;AACnC,UAAM,SAAS;AAAA,MACb,YACUA,gBACAC,oBACR;AAFQ,6BAAAD;AACA,iCAAAC;AAAA,MACP;AAAA,MAIH,IAAI,QAAa,SAAsB;AACrC,YAAI,KAAK,qBAAqB,OAAO,GAAG;AACtC,gBAAM,QAAQ,KAAK,cAAc,OAAO;AACxC,cAAI,OAAO,UAAU,YAAY;AAC/B,mBAAO,MAAM,KAAK,KAAK,aAAa;AAAA,UACtC;AACA,iBAAO;AAAA,QACT,WAAW,KAAK,mBAAmB,OAAO,GAAG;AAC3C,gBAAM,QAAQ,KAAK,kBAAkB,OAAO;AAC5C,cAAI,OAAO,UAAU,YAAY;AAC/B,mBA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