@copilotkit/react-textarea 0.25.0 → 0.26.0-alpha.0

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 (233) hide show
  1. package/.turbo/turbo-build.log +313 -309
  2. package/CHANGELOG.md +11 -0
  3. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +29 -0
  4. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +1745 -35
  5. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  6. package/dist/components/base-copilot-textarea/render-element.mjs +51 -3
  7. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  8. package/dist/components/base-copilot-textarea/render-placeholder.mjs +49 -3
  9. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  10. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +86 -4
  11. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  12. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +57 -3
  13. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  14. package/dist/components/copilot-textarea/copilot-textarea.d.ts +3 -0
  15. package/dist/components/copilot-textarea/copilot-textarea.mjs +2202 -47
  16. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  17. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +7 -3
  18. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +17 -3
  19. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  20. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +137 -3
  21. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  22. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +875 -18
  23. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  24. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +558 -12
  25. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  26. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +581 -13
  27. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  28. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +102 -5
  29. package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
  30. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +581 -14
  31. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  32. package/dist/components/index.mjs +2203 -48
  33. package/dist/components/index.mjs.map +1 -1
  34. package/dist/components/manual-ui/chip-with-icon.mjs +10 -22
  35. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  36. package/dist/components/source-search-box/source-search-box.mjs +211 -6
  37. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  38. package/dist/components/ui/button.mjs +85 -4
  39. package/dist/components/ui/button.mjs.map +1 -1
  40. package/dist/components/ui/card.mjs +71 -31
  41. package/dist/components/ui/card.mjs.map +1 -1
  42. package/dist/components/ui/command.mjs +244 -5
  43. package/dist/components/ui/command.mjs.map +1 -1
  44. package/dist/components/ui/dialog.mjs +144 -4
  45. package/dist/components/ui/dialog.mjs.map +1 -1
  46. package/dist/components/ui/label.mjs +60 -4
  47. package/dist/components/ui/label.mjs.map +1 -1
  48. package/dist/components/ui/separator.mjs +63 -18
  49. package/dist/components/ui/separator.mjs.map +1 -1
  50. package/dist/components/ui/textarea.mjs +58 -14
  51. package/dist/components/ui/textarea.mjs.map +1 -1
  52. package/dist/context/index.d.ts +1 -0
  53. package/dist/context/index.mjs +0 -2
  54. package/dist/context/index.mjs.map +1 -1
  55. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +158 -6
  56. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  57. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +168 -4
  58. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  59. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +148 -5
  60. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  61. package/dist/hooks/index.d.ts +1 -0
  62. package/dist/hooks/index.mjs +0 -2
  63. package/dist/hooks/index.mjs.map +1 -1
  64. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +147 -14
  65. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  66. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +193 -14
  67. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  68. package/dist/hooks/misc/use-autosize-textarea.mjs +15 -3
  69. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  70. package/dist/index.mjs +2206 -50
  71. package/dist/index.mjs.map +1 -1
  72. package/dist/lib/debouncer.mjs +51 -3
  73. package/dist/lib/debouncer.mjs.map +1 -1
  74. package/dist/lib/editor-to-text.mjs +43 -3
  75. package/dist/lib/editor-to-text.mjs.map +1 -1
  76. package/dist/lib/get-text-around-cursor.mjs +102 -3
  77. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  78. package/dist/lib/retry.mjs +17 -3
  79. package/dist/lib/retry.mjs.map +1 -1
  80. package/dist/lib/slatejs-edits/add-autocompletions.mjs +25 -3
  81. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  82. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +20 -3
  83. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  84. package/dist/lib/slatejs-edits/replace-text.mjs +27 -3
  85. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  86. package/dist/lib/slatejs-edits/with-partial-history.mjs +106 -3
  87. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  88. package/dist/lib/stream-promise-flatten.mjs +47 -3
  89. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  90. package/dist/lib/utils.mjs +71 -3
  91. package/dist/lib/utils.mjs.map +1 -1
  92. package/dist/lib/utils.test.d.ts +1 -0
  93. package/dist/lib/utils.test.mjs +0 -1
  94. package/dist/lib/utils.test.mjs.map +1 -1
  95. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +0 -2
  96. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  97. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +265 -8
  98. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  99. package/dist/types/autosuggestions-config/editing-api-config.mjs +81 -3
  100. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  101. package/dist/types/autosuggestions-config/index.mjs +327 -10
  102. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  103. package/dist/types/autosuggestions-config/insertions-api-config.mjs +75 -3
  104. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  105. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +83 -3
  106. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  107. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +0 -2
  108. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  109. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +0 -2
  110. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  111. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +64 -3
  112. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  113. package/dist/types/base/autosuggestion-state.mjs +0 -2
  114. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  115. package/dist/types/base/autosuggestions-bare-function.mjs +0 -2
  116. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  117. package/dist/types/base/base-autosuggestions-config.mjs +26 -3
  118. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  119. package/dist/types/base/base-copilot-textarea-props.mjs +0 -2
  120. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  121. package/dist/types/base/custom-editor.mjs +0 -2
  122. package/dist/types/base/custom-editor.mjs.map +1 -1
  123. package/dist/types/base/editor-autocomplete-state.mjs +17 -4
  124. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  125. package/dist/types/base/index.mjs +26 -4
  126. package/dist/types/base/index.mjs.map +1 -1
  127. package/dist/types/html-copilot-textarea-element.mjs +0 -2
  128. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  129. package/dist/types/index.mjs +328 -12
  130. package/dist/types/index.mjs.map +1 -1
  131. package/package.json +7 -7
  132. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +50 -10
  133. package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +23 -1
  134. package/src/components/copilot-textarea/copilot-textarea.tsx +3 -0
  135. package/src/components/hovering-toolbar/hovering-editor-provider.tsx +7 -3
  136. package/dist/chunk-2C7O2EVM.mjs +0 -27
  137. package/dist/chunk-2C7O2EVM.mjs.map +0 -1
  138. package/dist/chunk-2CDXHWVF.mjs +0 -107
  139. package/dist/chunk-2CDXHWVF.mjs.map +0 -1
  140. package/dist/chunk-2QDCE7PD.mjs +0 -29
  141. package/dist/chunk-2QDCE7PD.mjs.map +0 -1
  142. package/dist/chunk-3PQ7GSFE.mjs +0 -17
  143. package/dist/chunk-3PQ7GSFE.mjs.map +0 -1
  144. package/dist/chunk-5FO6ISW4.mjs +0 -3
  145. package/dist/chunk-5FO6ISW4.mjs.map +0 -1
  146. package/dist/chunk-5IISSXS2.mjs +0 -224
  147. package/dist/chunk-5IISSXS2.mjs.map +0 -1
  148. package/dist/chunk-5UNJXFUO.mjs +0 -29
  149. package/dist/chunk-5UNJXFUO.mjs.map +0 -1
  150. package/dist/chunk-74HF6Q3L.mjs +0 -204
  151. package/dist/chunk-74HF6Q3L.mjs.map +0 -1
  152. package/dist/chunk-7LSRNPNI.mjs +0 -59
  153. package/dist/chunk-7LSRNPNI.mjs.map +0 -1
  154. package/dist/chunk-7SZDD6XT.mjs +0 -53
  155. package/dist/chunk-7SZDD6XT.mjs.map +0 -1
  156. package/dist/chunk-7VKOE5UL.mjs +0 -45
  157. package/dist/chunk-7VKOE5UL.mjs.map +0 -1
  158. package/dist/chunk-AUCHS4VR.mjs +0 -77
  159. package/dist/chunk-AUCHS4VR.mjs.map +0 -1
  160. package/dist/chunk-BLRAOGXD.mjs +0 -10
  161. package/dist/chunk-BLRAOGXD.mjs.map +0 -1
  162. package/dist/chunk-CK7Q3Y5A.mjs +0 -21
  163. package/dist/chunk-CK7Q3Y5A.mjs.map +0 -1
  164. package/dist/chunk-DE5K76I2.mjs +0 -3
  165. package/dist/chunk-DE5K76I2.mjs.map +0 -1
  166. package/dist/chunk-ECR45NSD.mjs +0 -101
  167. package/dist/chunk-ECR45NSD.mjs.map +0 -1
  168. package/dist/chunk-EZCKXWQF.mjs +0 -16
  169. package/dist/chunk-EZCKXWQF.mjs.map +0 -1
  170. package/dist/chunk-F626GQCD.mjs +0 -47
  171. package/dist/chunk-F626GQCD.mjs.map +0 -1
  172. package/dist/chunk-FK2XUDQQ.mjs +0 -22
  173. package/dist/chunk-FK2XUDQQ.mjs.map +0 -1
  174. package/dist/chunk-FP2EKU3L.mjs +0 -28
  175. package/dist/chunk-FP2EKU3L.mjs.map +0 -1
  176. package/dist/chunk-GQN2HYFJ.mjs +0 -22
  177. package/dist/chunk-GQN2HYFJ.mjs.map +0 -1
  178. package/dist/chunk-H4VKQGVU.mjs +0 -3
  179. package/dist/chunk-H4VKQGVU.mjs.map +0 -1
  180. package/dist/chunk-IU3WTXLQ.mjs +0 -3
  181. package/dist/chunk-IU3WTXLQ.mjs.map +0 -1
  182. package/dist/chunk-K5LNB36H.mjs +0 -80
  183. package/dist/chunk-K5LNB36H.mjs.map +0 -1
  184. package/dist/chunk-KDVMG3XF.mjs +0 -63
  185. package/dist/chunk-KDVMG3XF.mjs.map +0 -1
  186. package/dist/chunk-KMXSZRIA.mjs +0 -47
  187. package/dist/chunk-KMXSZRIA.mjs.map +0 -1
  188. package/dist/chunk-KNQIEOFP.mjs +0 -18
  189. package/dist/chunk-KNQIEOFP.mjs.map +0 -1
  190. package/dist/chunk-L7VVZH4Q.mjs +0 -3
  191. package/dist/chunk-L7VVZH4Q.mjs.map +0 -1
  192. package/dist/chunk-LZ3UOAQ4.mjs +0 -83
  193. package/dist/chunk-LZ3UOAQ4.mjs.map +0 -1
  194. package/dist/chunk-M2DR4KVB.mjs +0 -33
  195. package/dist/chunk-M2DR4KVB.mjs.map +0 -1
  196. package/dist/chunk-MMVDU6DF.mjs +0 -3
  197. package/dist/chunk-MMVDU6DF.mjs.map +0 -1
  198. package/dist/chunk-MRXNTQOX.mjs +0 -55
  199. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  200. package/dist/chunk-NTLVQENP.mjs +0 -19
  201. package/dist/chunk-NTLVQENP.mjs.map +0 -1
  202. package/dist/chunk-PDCIGRCE.mjs +0 -93
  203. package/dist/chunk-PDCIGRCE.mjs.map +0 -1
  204. package/dist/chunk-QRKKPCUD.mjs +0 -21
  205. package/dist/chunk-QRKKPCUD.mjs.map +0 -1
  206. package/dist/chunk-RBR32FWA.mjs +0 -74
  207. package/dist/chunk-RBR32FWA.mjs.map +0 -1
  208. package/dist/chunk-T6MTDQZ7.mjs +0 -45
  209. package/dist/chunk-T6MTDQZ7.mjs.map +0 -1
  210. package/dist/chunk-TZLW7PBU.mjs +0 -35
  211. package/dist/chunk-TZLW7PBU.mjs.map +0 -1
  212. package/dist/chunk-U3LUDDT5.mjs +0 -65
  213. package/dist/chunk-U3LUDDT5.mjs.map +0 -1
  214. package/dist/chunk-UEQYKC4W.mjs +0 -34
  215. package/dist/chunk-UEQYKC4W.mjs.map +0 -1
  216. package/dist/chunk-V55OPCG4.mjs +0 -45
  217. package/dist/chunk-V55OPCG4.mjs.map +0 -1
  218. package/dist/chunk-VYECMH73.mjs +0 -99
  219. package/dist/chunk-VYECMH73.mjs.map +0 -1
  220. package/dist/chunk-W2ZHOUV6.mjs +0 -108
  221. package/dist/chunk-W2ZHOUV6.mjs.map +0 -1
  222. package/dist/chunk-WADHCMPK.mjs +0 -3
  223. package/dist/chunk-WADHCMPK.mjs.map +0 -1
  224. package/dist/chunk-WJHSY5T6.mjs +0 -3
  225. package/dist/chunk-WJHSY5T6.mjs.map +0 -1
  226. package/dist/chunk-WVRTFPNO.mjs +0 -91
  227. package/dist/chunk-WVRTFPNO.mjs.map +0 -1
  228. package/dist/chunk-ZEHF3AXH.mjs +0 -45
  229. package/dist/chunk-ZEHF3AXH.mjs.map +0 -1
  230. package/dist/chunk-ZKRM3DIR.mjs +0 -91
  231. package/dist/chunk-ZKRM3DIR.mjs.map +0 -1
  232. package/dist/chunk-ZMNOLW5V.mjs +0 -99
  233. package/dist/chunk-ZMNOLW5V.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../src/types/base/base-autosuggestions-config.tsx","../../src/types/autosuggestions-config/suggestions-api-config.tsx","../../src/types/autosuggestions-config/insertions-api-config.tsx","../../src/types/autosuggestions-config/editing-api-config.tsx","../../src/types/autosuggestions-config/autosuggestions-config.tsx","../../src/types/autosuggestions-config/subtypes/chatlike-api-endpoint.tsx"],"sourcesContent":["import { BaseCopilotTextareaApiConfig } from \"./autosuggestions-bare-function\";\nimport { defaultCopilotContextCategories } from \"@copilotkit/react-core\";\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 {(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.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 shouldAcceptAutosuggestionOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n shouldToggleHoveringEditorOnKeyPress: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;\n}\n\n// by default, command-k toggles the hovering editor\nconst defaultShouldToggleHoveringEditorOnKeyPress = (\n event: React.KeyboardEvent<HTMLDivElement>,\n) => {\n // if command-k, toggle the hovering editor\n if (event.key === \"k\" && event.metaKey) {\n return true;\n }\n return false;\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\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 {(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 */\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 shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,\n shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,\n};\n","import { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\nimport { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\n\nexport interface SuggestionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultSuggestionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nYour job is to guess what the user will write next AS BEST YOU CAN.\nOnly guess a SHORT distance ahead. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide both the text before and after the cursor. You should use this to infer what the user is likely to write next.\n<TextAfterCursor>\n<TextBeforeCursor>\n<YourSuggestion>\n\nIf we need to add a whitespace character to the suggested text, make sure to explicitly add it in.\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n`;\n};\n\nexport const defaultSuggestionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultSuggestionsApiConfig: SuggestionsApiConfig = {\n makeSystemPrompt: defaultSuggestionsMakeSystemPrompt,\n fewShotMessages: defaultSuggestionsFewShotMessages,\n forwardedParams: undefined,\n};\n","import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface InsertionsApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultInsertionsMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user also provides you with a prompt for INSERTIONS into the text they are writing. \nYour job is to come up with an INSERTION into the text that the user would like AS BEST YOU CAN.\nOnly insert a SHORT segment. Usually 1 sentence, or at most 1 paragraph.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide the text before and after the cursor, as well as the insertion prompt. You should use this to infer the best relevant insertion.\n<TextAfterCursor>\n<TextBeforeCursor>\n<InsertionPrompt>\n<YourSuggestion>\n`;\n};\n\nexport const defaultInsertionsFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"While I was there I also picked up some apples, oranges, and bananas.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store.\",\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"I bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultInsertionsApiConfig: InsertionsApiConfig = {\n makeSystemPrompt: defaultInsertionsMakeSystemPrompt,\n fewShotMessages: defaultInsertionsFewShotMessages,\n forwardedParams: undefined,\n};\n","import { MakeSystemPrompt } from \"./subtypes/make-system-prompt\";\nimport { MinimalChatGPTMessage } from \"./subtypes/minimal-chat-gpt-message\";\n\nexport interface EditingApiConfig {\n makeSystemPrompt: MakeSystemPrompt;\n fewShotMessages: MinimalChatGPTMessage[];\n forwardedParams: { [key: string]: any } | undefined;\n}\n\nexport const defaultEditingMakeSystemPrompt: MakeSystemPrompt = (\n textareaPurpose,\n contextString,\n) => {\n return `You are a versatile writing assistant.\n \nThe user is writing some text.\nThe purpose is: \\\"${textareaPurpose}\\\"\n\nThe following external context is also provided. Use it to help you make better suggestions!!!\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThe user also provides you with a prompt for EDITING some text they are writing. \nYour job is to come up with an EDIT of the text that the user would like to use - AS BEST YOU CAN.\n\nAdjust yourself to the user's style and implied intent.\n\nThe user will provide the following information; use this to infer the best relevant EDIT:\n<TextBeforeCursor>\n<TextToEdit>\n<TextAfterCursor>\n<EditingPrompt>\n\n<YourEditSuggestion>\n`;\n};\n\nexport const defaultEditingFewShotMessages: MinimalChatGPTMessage[] = [\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: \"This morning I woke up and went straight to the grocery store. \",\n },\n {\n role: \"user\",\n name: \"TextToEdit\",\n content: \"While I was there I also picked up some apples, oranges, and bananas. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: \"The grocery store was having a sale on fruit, so I decided to stock up.\",\n },\n {\n role: \"user\",\n name: \"EditingPrompt\",\n content: \"I bought a big watermelon\",\n },\n {\n role: \"assistant\",\n content:\n \" When I arrived I went straight to the produce section and picked out a big watermelon. \",\n },\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content:\n \"and (iii) to the appointment of the Equityholders' Representative pursuant to Section 10.7 of the Merger Agreement and to the provisions thereof.\",\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content:\n 'The Optionholder, in the Optionholder\\'s capacity as a holder of vested Options, hereby irrevocably and unconditionally agrees: (i) that the Optionholder shall be deemed an \"Equityholder\" under the Merger Agreement and shall be entitled to the rights and benefits, and subject to the obligations, of an \"Equityholder\" thereunder;',\n },\n {\n role: \"user\",\n name: \"InsertionPrompt\",\n content: \"add section about the optionholder's pro rata share\",\n },\n {\n role: \"assistant\",\n content:\n ' (ii) that, for purposes of this Agreement and the Merger Agreement, the applicable percentage set forth opposite the name of the Optionholder in the Distribution Waterfall shall be such the Optionholder\\'s \"Pro Rata Share\"; ',\n },\n];\n\nexport const defaultEditingApiConfig: EditingApiConfig = {\n makeSystemPrompt: defaultEditingMakeSystemPrompt,\n fewShotMessages: defaultEditingFewShotMessages,\n forwardedParams: undefined,\n};\n","import { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../base\";\nimport { SuggestionsApiConfig, defaultSuggestionsApiConfig } from \"./suggestions-api-config\";\nimport { InsertionsApiConfig, defaultInsertionsApiConfig } from \"./insertions-api-config\";\nimport { ChatlikeApiEndpoint } from \".\";\nimport { EditingApiConfig, defaultEditingApiConfig } 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<BaseAutosuggestionsConfig, \"apiConfig\"> {\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","import { CopilotApiConfig, copilotApiConfigExtrapolator } from \"@copilotkit/react-core\";\nimport { MinimalChatGPTMessage } from \"./minimal-chat-gpt-message\";\n\nexport type ChatlikeApiEndpointImpl = (\n abortSignal: AbortSignal,\n messages: MinimalChatGPTMessage[],\n forwardedProps?: { [key: string]: any },\n) => Promise<string>;\n\nexport type StreamingChatlikeApiEndpointImpl = (\n abortSignal: AbortSignal,\n messages: MinimalChatGPTMessage[],\n forwardedProps?: { [key: string]: any },\n) => Promise<ReadableStream<string>>;\n\nexport class ChatlikeApiEndpoint {\n public run: StreamingChatlikeApiEndpointImpl;\n\n constructor(run: StreamingChatlikeApiEndpointImpl) {\n this.run = run;\n }\n\n /**\n * Creates a new instance of ChatlikeApiEndpoint with the provided API endpoint.\n * @param apiEndpoint The URL of the OpenAI-compatible API endpoint.\n * @returns A new instance of ChatlikeApiEndpoint.\n */\n static fromCopilotApiConfig(copilotApiConfig: CopilotApiConfig): ChatlikeApiEndpoint {\n return new ChatlikeApiEndpoint(\n async (\n abortSignal: AbortSignal,\n messages: MinimalChatGPTMessage[],\n forwardedProps?: { [key: string]: any },\n ) => {\n const res = await fetch(copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint, {\n method: \"POST\",\n headers: {\n ...copilotApiConfig.headers,\n },\n body: JSON.stringify({\n ...forwardedProps,\n ...copilotApiConfig.body,\n messages: messages,\n }),\n signal: abortSignal,\n });\n\n const bodySteram: ReadableStream<Uint8Array> | null = res.body;\n if (!bodySteram) {\n throw new Error(\"The response body is empty.\");\n }\n\n // map the stream to a stream of strings\n const stringStream = bodySteram.pipeThrough(new TextDecoderStream());\n\n return stringStream;\n },\n );\n }\n\n /**\n * Creates a fully customized instance of ChatlikeApiEndpoint.\n * @param run - The implementation of the ChatlikeApiEndpointImpl interface.\n * @returns A new instance of ChatlikeApiEndpoint .\n */\n static custom(run: StreamingChatlikeApiEndpointImpl): ChatlikeApiEndpoint {\n return new ChatlikeApiEndpoint(run);\n }\n}\n"],"mappings":"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","names":["defaultCopilotContextCategories","defaultCopilotContextCategories"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.25.0",
7
+ "version": "0.26.0-alpha.0",
8
8
  "sideEffects": [
9
9
  "**/*.css"
10
10
  ],
@@ -31,11 +31,11 @@
31
31
  "react": "^18.2.0",
32
32
  "tailwindcss": "^3.3.0",
33
33
  "ts-jest": "^29.1.1",
34
- "tsup": "^6.1.3",
35
- "typescript": "^4.9.4",
34
+ "tsup": "^6.7.0",
35
+ "typescript": "^5.1.3",
36
36
  "eslint-config-custom": "0.2.0",
37
- "tailwind-config": "0.1.0",
38
- "tsconfig": "0.5.0"
37
+ "tsconfig": "0.6.0-alpha.0",
38
+ "tailwind-config": "0.1.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "@emotion/css": "^11.11.2",
@@ -46,7 +46,7 @@
46
46
  "@radix-ui/react-label": "^2.0.2",
47
47
  "@radix-ui/react-separator": "^1.0.3",
48
48
  "@radix-ui/react-slot": "^1.0.2",
49
- "ai": "^2.2.12",
49
+ "ai": "^2.2.23",
50
50
  "class-variance-authority": "^0.6.1",
51
51
  "clsx": "^1.2.1",
52
52
  "cmdk": "^0.2.0",
@@ -59,7 +59,7 @@
59
59
  "slate-history": "^0.93.0",
60
60
  "slate-react": "^0.98.1",
61
61
  "tailwind-merge": "^1.13.2",
62
- "@copilotkit/react-core": "0.14.0"
62
+ "@copilotkit/react-core": "0.15.0-alpha.0"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "tsup --treeshake",
@@ -27,12 +27,62 @@ import {
27
27
  import { EditorAutocompleteState } from "../../types/base/editor-autocomplete-state";
28
28
  import { TrackerTextEditedSinceLastCursorMovement } from "./track-cursor-moved-since-last-text-change";
29
29
 
30
+ /**
31
+ * Purpose: to be used as the `ref` type for `CopilotTextarea` and `BaseCopilotTextarea`.
32
+ *
33
+ * This interface extends `HTMLElement`, and is the subset of `HTMLTextAreaElement` that "actually matters".
34
+ * It provides the core functionality that consumers of `HTMLTextAreaElement` need 99.9% of the time:
35
+ * - `value`: the current value of the textarea
36
+ * - `focus`: make the textarea focused
37
+ * - `blur`: make the textarea unfocused
38
+ */
30
39
  export interface HTMLCopilotTextAreaElement extends HTMLElement {
40
+ /**
41
+ * The current value of the textarea.
42
+ */
31
43
  value: string;
44
+
45
+ /**
46
+ * focus on the textarea
47
+ */
32
48
  focus: () => void;
49
+
50
+ /**
51
+ * unfocus the textarea.
52
+ *
53
+ * Called `blur` for syntactic compatibility with `HTMLTextAreaElement`.
54
+ */
33
55
  blur: () => void;
34
56
  }
35
57
 
58
+ /**
59
+ * Not intended for direct use. Use CopilotTextarea instead.
60
+ *
61
+ * The `BaseCopilotTextarea` includes the basic UX component,
62
+ * without the business logic / AI logic that makes the content useful and coherent.
63
+ *
64
+ * It is useful if you want to build your own backend, with fully custom business logic
65
+ * for figuring out which contnet to fill in.
66
+ */
67
+ export const BaseCopilotTextarea = React.forwardRef(
68
+ (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
69
+ return (
70
+ <HoveringEditorProvider>
71
+ <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />
72
+ </HoveringEditorProvider>
73
+ );
74
+ },
75
+ );
76
+
77
+ /**
78
+ * Not intended for direct use. Use `CopilotTextarea` instead.
79
+ *
80
+ * This is the private core of the `BaseCopilotTextarea` component.
81
+ * For practical purposes the implementation is cleaner assuming containment in a `HoveringEditorProviderContext`.
82
+ *
83
+ * Therefore we separate the core logic into this component,
84
+ * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.
85
+ */
36
86
  const BaseCopilotTextareaWithHoveringContext = React.forwardRef(
37
87
  (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
38
88
  const autosuggestionsConfig: BaseAutosuggestionsConfig = {
@@ -253,13 +303,3 @@ function makeSemiFakeReactTextAreaEvent(
253
303
  },
254
304
  } as React.ChangeEvent<HTMLTextAreaElement>;
255
305
  }
256
-
257
- export const BaseCopilotTextarea = React.forwardRef(
258
- (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
259
- return (
260
- <HoveringEditorProvider>
261
- <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />
262
- </HoveringEditorProvider>
263
- );
264
- },
265
- );
@@ -29,11 +29,16 @@ export function TrackerTextEditedSinceLastCursorMovement(
29
29
 
30
30
  return <></>;
31
31
  }
32
+
32
33
  type RelevantEditorState = {
33
34
  selection: BaseSelection;
34
35
  text: string;
35
36
  };
36
- const cursorChangedWithoutTextChanged = (prev: RelevantEditorState, next: RelevantEditorState) => {
37
+
38
+ const cursorChangedWithoutTextChanged = (
39
+ prev: RelevantEditorState,
40
+ next: RelevantEditorState,
41
+ ): boolean => {
37
42
  // Check if the selection has changed
38
43
  const isSelectionChanged = !isSelectionEqual(prev.selection, next.selection);
39
44
 
@@ -42,11 +47,28 @@ const cursorChangedWithoutTextChanged = (prev: RelevantEditorState, next: Releva
42
47
 
43
48
  return isSelectionChanged && isTextSame;
44
49
  };
50
+
45
51
  const isSelectionEqual = (a: BaseSelection, b: BaseSelection) => {
46
52
  if (!a && !b) return true;
47
53
  if (!a || !b) return false;
48
54
  return Range.equals(a, b);
49
55
  };
56
+
57
+ /**
58
+ * Easily keep track of the *previous* value of a variable.
59
+ *
60
+ * Example:
61
+ * ```
62
+ * const [count, setCount] = useState(0);
63
+ * const prevCount = usePrevious(count);
64
+ *
65
+ * useEffect(() => {
66
+ * if (count > prevCount) {
67
+ * console.log('Now I know that count is bigger than before');
68
+ * }
69
+ * }, [count, prevCount]);
70
+ * ```
71
+ */
50
72
  function usePrevious<T>(value: T): T | undefined {
51
73
  const ref = useRef<T>();
52
74
 
@@ -19,6 +19,9 @@ export interface CopilotTextareaProps
19
19
  autosuggestionsConfig: AutosuggestionsConfigUserSpecified;
20
20
  }
21
21
 
22
+ /**
23
+ * A copilot textarea that uses the standard autosuggestions function.
24
+ */
22
25
  export const CopilotTextarea = React.forwardRef(
23
26
  (props: CopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {
24
27
  // separate the AutosuggestionsConfigUserSpecified from the rest of the props
@@ -10,12 +10,16 @@ const HoveringEditorContext = createContext<HoveringEditorContextProps>({
10
10
  setIsDisplayed: () => {},
11
11
  });
12
12
 
13
- interface HoveringEditorProviderProps {
13
+ export interface HoveringEditorProviderProps {
14
14
  children: ReactNode;
15
15
  }
16
16
 
17
- export const HoveringEditorProvider = ({ children }: HoveringEditorProviderProps) => {
18
- const [isDisplayed, setIsDisplayed] = useState(false);
17
+ /**
18
+ * A context provider for the hovering editor over the `CopilotTextarea`
19
+ * (used to edit and insert text into the `CopilotTextarea`).
20
+ */
21
+ export const HoveringEditorProvider: React.FC<HoveringEditorProviderProps> = ({ children }) => {
22
+ const [isDisplayed, setIsDisplayed] = useState<boolean>(false);
19
23
 
20
24
  return (
21
25
  <HoveringEditorContext.Provider value={{ isDisplayed, setIsDisplayed }}>
@@ -1,27 +0,0 @@
1
- import { Transforms } from 'slate';
2
-
3
- // src/lib/slatejs-edits/add-autocompletions.ts
4
- function addAutocompletionsToEditor(editor, newSuggestion, point) {
5
- const editorPosition = editor.selection;
6
- Transforms.insertNodes(
7
- editor,
8
- [
9
- {
10
- type: "suggestion",
11
- inline: true,
12
- content: newSuggestion,
13
- children: [{ text: "" }]
14
- }
15
- ],
16
- {
17
- at: point
18
- }
19
- );
20
- if (editorPosition) {
21
- editor.selection = editorPosition;
22
- }
23
- }
24
-
25
- export { addAutocompletionsToEditor };
26
- //# sourceMappingURL=out.js.map
27
- //# sourceMappingURL=chunk-2C7O2EVM.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/slatejs-edits/add-autocompletions.ts"],"names":[],"mappings":";AAAA,SAAoB,kBAAkB;AAG/B,SAAS,2BACd,QACA,eACA,OACA;AACA,QAAM,iBAAiB,OAAO;AAE9B,aAAW;AAAA,IACT;AAAA,IACA;AAAA,MACE;AAAA,QACE,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,UAAU,CAAC,EAAE,MAAM,GAAG,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,IACA;AAAA,MACE,IAAI;AAAA,IACN;AAAA,EACF;AAGA,MAAI,gBAAgB;AAClB,WAAO,YAAY;AAAA,EACrB;AACF","sourcesContent":["import { BasePoint, Transforms } from \"slate\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nexport function addAutocompletionsToEditor(\n editor: CustomEditor,\n newSuggestion: string,\n point: BasePoint,\n) {\n const editorPosition = editor.selection;\n\n Transforms.insertNodes(\n editor,\n [\n {\n type: \"suggestion\",\n inline: true,\n content: newSuggestion,\n children: [{ text: \"\" }],\n },\n ],\n {\n at: point,\n },\n );\n\n // restore cursor position\n if (editorPosition) {\n editor.selection = editorPosition;\n }\n}\n"]}
@@ -1,107 +0,0 @@
1
- import { Transforms, Editor, Operation, Path } from 'slate';
2
- import { HistoryEditor } from 'slate-history';
3
-
4
- // src/lib/slatejs-edits/with-partial-history.ts
5
- var withPartialHistory = (editor, shouldSave) => {
6
- const e = editor;
7
- const { apply } = e;
8
- e.history = { undos: [], redos: [] };
9
- e.redo = () => {
10
- const { history } = e;
11
- const { redos } = history;
12
- if (redos.length > 0) {
13
- const batch = redos[redos.length - 1];
14
- if (batch.selectionBefore) {
15
- Transforms.setSelection(e, batch.selectionBefore);
16
- }
17
- HistoryEditor.withoutSaving(e, () => {
18
- Editor.withoutNormalizing(e, () => {
19
- for (const op of batch.operations) {
20
- e.apply(op);
21
- }
22
- });
23
- });
24
- history.redos.pop();
25
- e.writeHistory("undos", batch);
26
- }
27
- };
28
- e.undo = () => {
29
- const { history } = e;
30
- const { undos } = history;
31
- if (undos.length > 0) {
32
- const batch = undos[undos.length - 1];
33
- HistoryEditor.withoutSaving(e, () => {
34
- Editor.withoutNormalizing(e, () => {
35
- const inverseOps = batch.operations.map(Operation.inverse).reverse();
36
- for (const op of inverseOps) {
37
- e.apply(op);
38
- }
39
- if (batch.selectionBefore) {
40
- Transforms.setSelection(e, batch.selectionBefore);
41
- }
42
- });
43
- });
44
- e.writeHistory("redos", batch);
45
- history.undos.pop();
46
- }
47
- };
48
- e.apply = (op) => {
49
- const { operations, history } = e;
50
- const { undos } = history;
51
- const lastBatch = undos[undos.length - 1];
52
- const lastOp = lastBatch && lastBatch.operations[lastBatch.operations.length - 1];
53
- let save = HistoryEditor.isSaving(e);
54
- let merge = HistoryEditor.isMerging(e);
55
- if (save == null) {
56
- save = shouldSave(op, lastOp);
57
- }
58
- if (save) {
59
- if (merge == null) {
60
- if (lastBatch == null) {
61
- merge = false;
62
- } else if (operations.length !== 0) {
63
- merge = true;
64
- } else {
65
- merge = shouldMerge(op, lastOp);
66
- }
67
- }
68
- if (lastBatch && merge) {
69
- lastBatch.operations.push(op);
70
- } else {
71
- const batch = {
72
- operations: [op],
73
- selectionBefore: e.selection
74
- };
75
- e.writeHistory("undos", batch);
76
- }
77
- while (undos.length > 100) {
78
- undos.shift();
79
- }
80
- history.redos = [];
81
- }
82
- apply(op);
83
- };
84
- e.writeHistory = (stack, batch) => {
85
- e.history[stack].push(batch);
86
- };
87
- return e;
88
- };
89
- var shouldMerge = (op, prev) => {
90
- if (prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path)) {
91
- return true;
92
- }
93
- if (prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path)) {
94
- return true;
95
- }
96
- return false;
97
- };
98
- var defaultShouldSave = (op, prev) => {
99
- if (op.type === "set_selection") {
100
- return false;
101
- }
102
- return true;
103
- };
104
-
105
- export { defaultShouldSave, withPartialHistory };
106
- //# sourceMappingURL=out.js.map
107
- //# sourceMappingURL=chunk-2CDXHWVF.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/slatejs-edits/with-partial-history.ts"],"names":[],"mappings":"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","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 = (op: Operation, prev: Operation | undefined) => 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 = 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 = (op: Operation, prev: Operation | undefined): boolean => {\n if (op.type === \"set_selection\") {\n return false;\n }\n\n return true;\n};\n"]}
@@ -1,29 +0,0 @@
1
- import { __async } from './chunk-MRXNTQOX.mjs';
2
-
3
- // src/lib/stream-promise-flatten.ts
4
- function streamPromiseFlatten(promise) {
5
- return new ReadableStream({
6
- start(controller) {
7
- return __async(this, null, function* () {
8
- try {
9
- const stream = yield promise;
10
- const reader = stream.getReader();
11
- while (true) {
12
- const { done, value } = yield reader.read();
13
- if (done) {
14
- controller.close();
15
- return;
16
- }
17
- controller.enqueue(value);
18
- }
19
- } catch (error) {
20
- controller.error(error);
21
- }
22
- });
23
- }
24
- });
25
- }
26
-
27
- export { streamPromiseFlatten };
28
- //# sourceMappingURL=out.js.map
29
- //# sourceMappingURL=chunk-2QDCE7PD.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/stream-promise-flatten.ts"],"names":[],"mappings":";;;;;AAUO,SAAS,qBAAwB,SAAwD;AAC9F,SAAO,IAAI,eAAkB;AAAA,IACrB,MAAM,YAAY;AAAA;AACtB,YAAI;AACF,gBAAM,SAAS,MAAM;AACrB,gBAAM,SAAS,OAAO,UAAU;AAEhC,iBAAO,MAAM;AACX,kBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,gBAAI,MAAM;AACR,yBAAW,MAAM;AACjB;AAAA,YACF;AAEA,uBAAW,QAAQ,KAAK;AAAA,UAC1B;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AAAA,QACxB;AAAA,MACF;AAAA;AAAA,EACF,CAAC;AACH","sourcesContent":["/**\n * Flatten a promise of a stream, into a stream.\n *\n * Useful because a stream already includes the notion of async value delivery,\n * so it often makes sense to simply await the values rather than the generator of the values.\n *\n * @param {Promise<ReadableStream<A>>} promise - The promise to flatten.\n * @returns {ReadableStream<A>} - The flattened stream.\n */\n\nexport function streamPromiseFlatten<A>(promise: Promise<ReadableStream<A>>): ReadableStream<A> {\n return new ReadableStream<A>({\n async start(controller) {\n try {\n const stream = await promise;\n const reader = stream.getReader();\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n controller.close();\n return;\n }\n\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n }\n },\n });\n}\n"]}
@@ -1,17 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- // src/hooks/misc/use-autosize-textarea.tsx
4
- var useAutosizeTextArea = (textAreaRef, value) => {
5
- useEffect(() => {
6
- if (textAreaRef.current !== null) {
7
- textAreaRef.current.style.height = "0px";
8
- const scrollHeight = textAreaRef.current.scrollHeight;
9
- textAreaRef.current.style.height = scrollHeight + "px";
10
- }
11
- }, [textAreaRef, value]);
12
- };
13
- var use_autosize_textarea_default = useAutosizeTextArea;
14
-
15
- export { use_autosize_textarea_default };
16
- //# sourceMappingURL=out.js.map
17
- //# sourceMappingURL=chunk-3PQ7GSFE.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/misc/use-autosize-textarea.tsx"],"names":[],"mappings":";AAAA,SAAyB,iBAAiB;AAG1C,IAAM,sBAAsB,CAAC,aAA6C,UAAkB;AAC1F,YAAU,MAAM;AACd,QAAI,YAAY,YAAY,MAAM;AAEhC,kBAAY,QAAQ,MAAM,SAAS;AACnC,YAAM,eAAe,YAAY,QAAQ;AAIzC,kBAAY,QAAQ,MAAM,SAAS,eAAe;AAAA,IACpD;AAAA,EACF,GAAG,CAAC,aAAa,KAAK,CAAC;AACzB;AAEA,IAAO,gCAAQ","sourcesContent":["import { Ref, RefObject, useEffect } from \"react\";\n\n// Updates the height of a <textarea> when the value changes.\nconst useAutosizeTextArea = (textAreaRef: RefObject<HTMLTextAreaElement>, value: string) => {\n useEffect(() => {\n if (textAreaRef.current !== null) {\n // We need to reset the height momentarily to get the correct scrollHeight for the textarea\n textAreaRef.current.style.height = \"0px\";\n const scrollHeight = textAreaRef.current.scrollHeight;\n\n // We then set the height directly, outside of the render loop\n // Trying to set this with state or a ref will product an incorrect value.\n textAreaRef.current.style.height = scrollHeight + \"px\";\n }\n }, [textAreaRef, value]);\n};\n\nexport default useAutosizeTextArea;\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-5FO6ISW4.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}