@copilotkit/react-textarea 0.19.0-alpha.4 → 0.19.0-alpha.6

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 (220) hide show
  1. package/.turbo/turbo-build.log +174 -178
  2. package/CHANGELOG.md +20 -0
  3. package/dist/chunk-2NURR2DX.mjs +47 -0
  4. package/dist/chunk-2NURR2DX.mjs.map +1 -0
  5. package/dist/chunk-4S5ZJH3I.mjs +18 -0
  6. package/dist/chunk-4S5ZJH3I.mjs.map +1 -0
  7. package/dist/chunk-55EGOC5T.mjs +87 -0
  8. package/dist/chunk-55EGOC5T.mjs.map +1 -0
  9. package/dist/chunk-5ARCOTW3.mjs +34 -0
  10. package/dist/chunk-5ARCOTW3.mjs.map +1 -0
  11. package/dist/chunk-5EJ5XOGP.mjs +22 -0
  12. package/dist/chunk-5EJ5XOGP.mjs.map +1 -0
  13. package/dist/chunk-5FO6ISW4.mjs +3 -0
  14. package/dist/chunk-5FO6ISW4.mjs.map +1 -0
  15. package/dist/chunk-6XP7KEMW.mjs +20 -0
  16. package/dist/chunk-6XP7KEMW.mjs.map +1 -0
  17. package/dist/chunk-A2RRLD23.mjs +69 -0
  18. package/dist/chunk-A2RRLD23.mjs.map +1 -0
  19. package/dist/chunk-CSGFJU3L.mjs +65 -0
  20. package/dist/chunk-CSGFJU3L.mjs.map +1 -0
  21. package/dist/chunk-D7SEV5PR.mjs +12 -0
  22. package/dist/chunk-D7SEV5PR.mjs.map +1 -0
  23. package/dist/chunk-DE5K76I2.mjs +3 -0
  24. package/dist/chunk-DE5K76I2.mjs.map +1 -0
  25. package/dist/chunk-F3MHL6ZY.mjs +25 -0
  26. package/dist/chunk-F3MHL6ZY.mjs.map +1 -0
  27. package/dist/chunk-FBDXI5QA.mjs +501 -0
  28. package/dist/chunk-FBDXI5QA.mjs.map +1 -0
  29. package/dist/chunk-FN7GDKKG.mjs +29 -0
  30. package/dist/chunk-FN7GDKKG.mjs.map +1 -0
  31. package/dist/chunk-H4VKQGVU.mjs +3 -0
  32. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  33. package/dist/chunk-HAFHLU4N.mjs +55 -0
  34. package/dist/chunk-HAFHLU4N.mjs.map +1 -0
  35. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  36. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  37. package/dist/chunk-IWTOQKC5.mjs +201 -0
  38. package/dist/chunk-IWTOQKC5.mjs.map +1 -0
  39. package/dist/chunk-IXJ2HCOA.mjs +101 -0
  40. package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
  41. package/dist/chunk-JAFCXEPU.mjs +10 -0
  42. package/dist/chunk-JAFCXEPU.mjs.map +1 -0
  43. package/dist/chunk-KCHYD3EB.mjs +107 -0
  44. package/dist/chunk-KCHYD3EB.mjs.map +1 -0
  45. package/dist/chunk-KGKLUWKW.mjs +47 -0
  46. package/dist/chunk-KGKLUWKW.mjs.map +1 -0
  47. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  48. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  49. package/dist/chunk-LNAIMEB2.mjs +34 -0
  50. package/dist/chunk-LNAIMEB2.mjs.map +1 -0
  51. package/dist/chunk-MMVDU6DF.mjs +3 -0
  52. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  53. package/dist/chunk-MPME5BW2.mjs +59 -0
  54. package/dist/chunk-MPME5BW2.mjs.map +1 -0
  55. package/dist/chunk-MRXNTQOX.mjs +55 -0
  56. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  57. package/dist/chunk-N4JMCC7P.mjs +44 -0
  58. package/dist/chunk-N4JMCC7P.mjs.map +1 -0
  59. package/dist/chunk-ND5PXTAW.mjs +17 -0
  60. package/dist/chunk-ND5PXTAW.mjs.map +1 -0
  61. package/dist/chunk-NKW5OU2S.mjs +33 -0
  62. package/dist/chunk-NKW5OU2S.mjs.map +1 -0
  63. package/dist/chunk-O5OWT5GE.mjs +114 -0
  64. package/dist/chunk-O5OWT5GE.mjs.map +1 -0
  65. package/dist/chunk-OD7ZMOVE.mjs +45 -0
  66. package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
  67. package/dist/chunk-OELUUJZY.mjs +16 -0
  68. package/dist/chunk-OELUUJZY.mjs.map +1 -0
  69. package/dist/chunk-QL2GYGG5.mjs +19 -0
  70. package/dist/chunk-QL2GYGG5.mjs.map +1 -0
  71. package/dist/chunk-RQHOUUXQ.mjs +29 -0
  72. package/dist/chunk-RQHOUUXQ.mjs.map +1 -0
  73. package/dist/chunk-UHD44NC5.mjs +101 -0
  74. package/dist/chunk-UHD44NC5.mjs.map +1 -0
  75. package/dist/chunk-VBIJPE3H.mjs +108 -0
  76. package/dist/chunk-VBIJPE3H.mjs.map +1 -0
  77. package/dist/chunk-WADHCMPK.mjs +3 -0
  78. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  79. package/dist/chunk-WJHSY5T6.mjs +3 -0
  80. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  81. package/dist/chunk-WJYQWL4I.mjs +27 -0
  82. package/dist/chunk-WJYQWL4I.mjs.map +1 -0
  83. package/dist/chunk-XA7M72ZO.mjs +106 -0
  84. package/dist/chunk-XA7M72ZO.mjs.map +1 -0
  85. package/dist/chunk-XDT7BF3V.mjs +81 -0
  86. package/dist/chunk-XDT7BF3V.mjs.map +1 -0
  87. package/dist/chunk-XHUMROEY.mjs +91 -0
  88. package/dist/chunk-XHUMROEY.mjs.map +1 -0
  89. package/dist/chunk-YQU7WG7T.mjs +83 -0
  90. package/dist/chunk-YQU7WG7T.mjs.map +1 -0
  91. package/dist/chunk-YSZ7DO3X.mjs +107 -0
  92. package/dist/chunk-YSZ7DO3X.mjs.map +1 -0
  93. package/dist/chunk-YTOPHPSG.mjs +45 -0
  94. package/dist/chunk-YTOPHPSG.mjs.map +1 -0
  95. package/dist/chunk-YW3REYX6.mjs +23 -0
  96. package/dist/chunk-YW3REYX6.mjs.map +1 -0
  97. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +33 -1870
  98. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  99. package/dist/components/base-copilot-textarea/render-element.mjs +3 -52
  100. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  101. package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -46
  102. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  103. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
  104. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  105. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
  106. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  107. package/dist/components/copilot-textarea/copilot-textarea.mjs +43 -2339
  108. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  109. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -22
  110. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  111. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -125
  112. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  113. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +16 -1015
  114. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  115. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +10 -721
  116. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  117. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +11 -734
  118. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  119. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +12 -734
  120. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  121. package/dist/components/index.mjs +44 -2340
  122. package/dist/components/index.mjs.map +1 -1
  123. package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
  124. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  125. package/dist/components/source-search-box/source-search-box.mjs +10 -323
  126. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  127. package/dist/components/ui/button.mjs +4 -88
  128. package/dist/components/ui/button.mjs.map +1 -1
  129. package/dist/components/ui/card.mjs +7 -53
  130. package/dist/components/ui/card.mjs.map +1 -1
  131. package/dist/components/ui/command.mjs +5 -266
  132. package/dist/components/ui/command.mjs.map +1 -1
  133. package/dist/components/ui/dialog.mjs +4 -164
  134. package/dist/components/ui/dialog.mjs.map +1 -1
  135. package/dist/components/ui/label.mjs +4 -63
  136. package/dist/components/ui/label.mjs.map +1 -1
  137. package/dist/components/ui/separator.mjs +8 -50
  138. package/dist/components/ui/separator.mjs.map +1 -1
  139. package/dist/components/ui/textarea.mjs +7 -48
  140. package/dist/components/ui/textarea.mjs.map +1 -1
  141. package/dist/context/index.mjs +2 -0
  142. package/dist/context/index.mjs.map +1 -1
  143. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -168
  144. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  145. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
  146. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  147. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -155
  148. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  149. package/dist/hooks/index.mjs +2 -0
  150. package/dist/hooks/index.mjs.map +1 -1
  151. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +4 -90
  152. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  153. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +4 -143
  154. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  155. package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
  156. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  157. package/dist/index.css +3 -0
  158. package/dist/index.css.map +1 -1
  159. package/dist/index.mjs +48 -2343
  160. package/dist/index.mjs.map +1 -1
  161. package/dist/lib/debouncer.mjs +3 -51
  162. package/dist/lib/debouncer.mjs.map +1 -1
  163. package/dist/lib/editor-to-text.mjs +3 -43
  164. package/dist/lib/editor-to-text.mjs.map +1 -1
  165. package/dist/lib/get-text-around-cursor.mjs +3 -109
  166. package/dist/lib/get-text-around-cursor.mjs.map +1 -1
  167. package/dist/lib/retry.mjs +3 -17
  168. package/dist/lib/retry.mjs.map +1 -1
  169. package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
  170. package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
  171. package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -23
  172. package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
  173. package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
  174. package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
  175. package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
  176. package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
  177. package/dist/lib/stream-promise-flatten.mjs +3 -47
  178. package/dist/lib/stream-promise-flatten.mjs.map +1 -1
  179. package/dist/lib/utils.mjs +3 -71
  180. package/dist/lib/utils.mjs.map +1 -1
  181. package/dist/lib/utils.test.mjs +1 -0
  182. package/dist/lib/utils.test.mjs.map +1 -1
  183. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
  184. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
  185. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +9 -312
  186. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  187. package/dist/types/autosuggestions-config/editing-api-config.mjs +4 -155
  188. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  189. package/dist/types/autosuggestions-config/index.mjs +10 -313
  190. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  191. package/dist/types/autosuggestions-config/insertions-api-config.mjs +4 -149
  192. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
  193. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -71
  194. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
  195. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
  196. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
  197. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
  198. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
  199. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +4 -137
  200. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
  201. package/dist/types/base/autosuggestion-state.mjs +2 -0
  202. package/dist/types/base/autosuggestion-state.mjs.map +1 -1
  203. package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
  204. package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
  205. package/dist/types/base/base-autosuggestions-config.mjs +3 -11
  206. package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
  207. package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
  208. package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
  209. package/dist/types/base/custom-editor.mjs +2 -0
  210. package/dist/types/base/custom-editor.mjs.map +1 -1
  211. package/dist/types/base/editor-autocomplete-state.mjs +4 -17
  212. package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
  213. package/dist/types/base/index.mjs +4 -11
  214. package/dist/types/base/index.mjs.map +1 -1
  215. package/dist/types/html-copilot-textarea-element.mjs +2 -0
  216. package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
  217. package/dist/types/index.mjs +12 -314
  218. package/dist/types/index.mjs.map +1 -1
  219. package/package.json +6 -5
  220. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +40 -1
@@ -0,0 +1,55 @@
1
+ import { retry } from './chunk-4S5ZJH3I.mjs';
2
+ import { __async } from './chunk-MRXNTQOX.mjs';
3
+ import { CopilotContext } from '@copilotkit/react-core';
4
+ import { useContext, useCallback } from 'react';
5
+
6
+ function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
7
+ const { getContextString } = useContext(CopilotContext);
8
+ return useCallback(
9
+ (editorState, abortSignal) => __async(this, null, function* () {
10
+ const res = yield retry(() => __async(this, null, function* () {
11
+ const messages = [
12
+ {
13
+ role: "system",
14
+ content: apiConfig.makeSystemPrompt(
15
+ textareaPurpose,
16
+ getContextString(contextCategories)
17
+ )
18
+ },
19
+ ...apiConfig.fewShotMessages,
20
+ {
21
+ role: "user",
22
+ name: "TextAfterCursor",
23
+ content: editorState.textAfterCursor
24
+ },
25
+ {
26
+ role: "user",
27
+ name: "TextBeforeCursor",
28
+ content: editorState.textBeforeCursor
29
+ }
30
+ ];
31
+ const stream = yield apiConfig.apiEndpoint.run(
32
+ abortSignal,
33
+ messages,
34
+ apiConfig.forwardedParams
35
+ );
36
+ const reader = stream.getReader();
37
+ let result = "";
38
+ while (true) {
39
+ const { done, value } = yield reader.read();
40
+ if (done) {
41
+ break;
42
+ }
43
+ result += value;
44
+ }
45
+ return result;
46
+ }));
47
+ return res;
48
+ }),
49
+ [apiConfig, getContextString, contextCategories, textareaPurpose]
50
+ );
51
+ }
52
+
53
+ export { useMakeStandardAutosuggestionFunction };
54
+ //# sourceMappingURL=out.js.map
55
+ //# sourceMappingURL=chunk-HAFHLU4N.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAqBjC,SAAS,sCACd,iBACA,mBACA,WAC6B;AAC7B,QAAM,EAAE,iBAAiB,IAAI,WAAW,cAAc;AAEtD,SAAO;AAAA,IACL,CAAO,aAAmC,gBAA6B;AACrE,YAAM,MAAM,MAAM,MAAM,MAAY;AAClC,cAAM,WAAoC;AAAA,UACxC;AAAA,YACE,MAAM;AAAA,YACN,SAAS,UAAU;AAAA,cACjB;AAAA,cACA,iBAAiB,iBAAiB;AAAA,YACpC;AAAA,UACF;AAAA,UACA,GAAG,UAAU;AAAA,UACb;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,UACvB;AAAA,QACF;AAEA,cAAM,SAAS,MAAM,UAAU,YAAY;AAAA,UACzC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QACZ;AAGA,cAAM,SAAS,OAAO,UAAU;AAChC,YAAI,SAAS;AAEb,eAAO,MAAM;AACX,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI,MAAM;AACR;AAAA,UACF;AACA,oBAAU;AAAA,QACZ;AAEA,eAAO;AAAA,MACT,EAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,kBAAkB,mBAAmB,eAAe;AAAA,EAClE;AACF","sourcesContent":["import { CopilotContext } from \"@copilotkit/react-core\";\nimport { useCallback, useContext } from \"react\";\nimport {\n AutosuggestionsBareFunction,\n MinimalChatGPTMessage,\n} from \"../../types\";\nimport { retry } from \"../../lib/retry\";\nimport { InsertionEditorState } from \"../../types/base/autosuggestions-bare-function\";\nimport { SuggestionsApiConfig } from \"../../types/autosuggestions-config/suggestions-api-config\";\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 useMakeStandardAutosuggestionFunction(\n textareaPurpose: string,\n contextCategories: string[] | undefined,\n apiConfig: SuggestionsApiConfig\n): AutosuggestionsBareFunction {\n const { getContextString } = useContext(CopilotContext);\n\n return useCallback(\n async (editorState: InsertionEditorState, abortSignal: AbortSignal) => {\n const res = await retry(async () => {\n const messages: MinimalChatGPTMessage[] = [\n {\n role: \"system\",\n content: apiConfig.makeSystemPrompt(\n textareaPurpose,\n getContextString(contextCategories)\n ),\n },\n ...apiConfig.fewShotMessages,\n {\n role: \"user\",\n name: \"TextAfterCursor\",\n content: editorState.textAfterCursor,\n },\n {\n role: \"user\",\n name: \"TextBeforeCursor\",\n content: editorState.textBeforeCursor,\n },\n ];\n\n const stream = await apiConfig.apiEndpoint.run(\n abortSignal,\n messages,\n apiConfig.forwardedParams\n );\n\n // read the stream:\n const reader = stream.getReader();\n let result = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n result += value;\n }\n\n return result;\n });\n\n return res;\n },\n [apiConfig, getContextString, contextCategories, textareaPurpose]\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-IU3WTXLQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,201 @@
1
+ import { useCopilotTextareaEditor } from './chunk-CSGFJU3L.mjs';
2
+ import { usePopulateCopilotTextareaRef } from './chunk-YQU7WG7T.mjs';
3
+ import { addAutocompletionsToEditor } from './chunk-WJYQWL4I.mjs';
4
+ import { clearAutocompletionsFromEditor } from './chunk-F3MHL6ZY.mjs';
5
+ import { replaceEditorText } from './chunk-RQHOUUXQ.mjs';
6
+ import { useAutosuggestions } from './chunk-UHD44NC5.mjs';
7
+ import { makeRenderElementFunction } from './chunk-LNAIMEB2.mjs';
8
+ import { makeRenderPlaceholderFunction } from './chunk-OELUUJZY.mjs';
9
+ import { TrackerTextEditedSinceLastCursorMovement } from './chunk-OD7ZMOVE.mjs';
10
+ import { useAddBrandingCss } from './chunk-MPME5BW2.mjs';
11
+ import { defaultBaseAutosuggestionsConfig } from './chunk-D7SEV5PR.mjs';
12
+ import { HoveringToolbar } from './chunk-YSZ7DO3X.mjs';
13
+ import { useHoveringEditorContext, HoveringEditorProvider } from './chunk-YW3REYX6.mjs';
14
+ import { getTextAroundCollapsedCursor, getFullEditorTextWithNewlines } from './chunk-IXJ2HCOA.mjs';
15
+ import { __spreadValues, __objRest, __spreadProps } from './chunk-MRXNTQOX.mjs';
16
+ import React, { useMemo, useState, useCallback, useEffect } from 'react';
17
+ import { Editor } from 'slate';
18
+ import { Slate, Editable } from 'slate-react';
19
+ import { twMerge } from 'tailwind-merge';
20
+ import { jsxs, jsx } from 'react/jsx-runtime';
21
+
22
+ var BaseCopilotTextareaWithHoveringContext = React.forwardRef(
23
+ (props, ref) => {
24
+ const autosuggestionsConfig = __spreadValues(__spreadValues({}, defaultBaseAutosuggestionsConfig), props.baseAutosuggestionsConfig);
25
+ const valueOnInitialRender = useMemo(() => {
26
+ var _a2;
27
+ return (_a2 = props.value) != null ? _a2 : "";
28
+ }, []);
29
+ const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);
30
+ const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);
31
+ const initialValue = useMemo(() => {
32
+ return [
33
+ {
34
+ type: "paragraph",
35
+ children: [{ text: valueOnInitialRender }]
36
+ }
37
+ ];
38
+ }, [valueOnInitialRender]);
39
+ const editor = useCopilotTextareaEditor();
40
+ const {
41
+ isDisplayed: hoveringEditorIsDisplayed,
42
+ setIsDisplayed: setHoveringEditorIsDisplayed
43
+ } = useHoveringEditorContext();
44
+ const insertText = useCallback(
45
+ (autosuggestion) => {
46
+ Editor.insertText(editor, autosuggestion.text, {
47
+ at: autosuggestion.point
48
+ });
49
+ },
50
+ [editor]
51
+ );
52
+ const {
53
+ currentAutocompleteSuggestion,
54
+ onChangeHandler: onChangeHandlerForAutocomplete,
55
+ onKeyDownHandler: onKeyDownHandlerForAutocomplete
56
+ } = useAutosuggestions(
57
+ autosuggestionsConfig.debounceTime,
58
+ autosuggestionsConfig.acceptAutosuggestionKey,
59
+ autosuggestionsConfig.apiConfig.autosuggestionsFunction,
60
+ insertText,
61
+ autosuggestionsConfig.disableWhenEmpty,
62
+ autosuggestionsConfig.disabled || hoveringEditorIsDisplayed || cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
63
+ );
64
+ const onKeyDownHandlerForHoveringEditor = useCallback(
65
+ (event) => {
66
+ if (event.key === "k" && event.metaKey) {
67
+ event.preventDefault();
68
+ setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);
69
+ }
70
+ },
71
+ [hoveringEditorIsDisplayed, setHoveringEditorIsDisplayed]
72
+ );
73
+ useEffect(() => {
74
+ clearAutocompletionsFromEditor(editor);
75
+ if (currentAutocompleteSuggestion) {
76
+ addAutocompletionsToEditor(
77
+ editor,
78
+ currentAutocompleteSuggestion.text,
79
+ currentAutocompleteSuggestion.point
80
+ );
81
+ }
82
+ }, [currentAutocompleteSuggestion]);
83
+ const suggestionStyleAugmented = useMemo(() => {
84
+ return __spreadValues({
85
+ fontStyle: "italic",
86
+ color: "gray"
87
+ }, props.suggestionsStyle);
88
+ }, [props.suggestionsStyle]);
89
+ const renderElementMemoized = useMemo(() => {
90
+ return makeRenderElementFunction(suggestionStyleAugmented);
91
+ }, [suggestionStyleAugmented]);
92
+ const renderPlaceholderMemoized = useMemo(() => {
93
+ const placeholderStyleSlatejsOverrides = {
94
+ top: void 0
95
+ };
96
+ const placeholderStyleAugmented = __spreadValues(__spreadValues({}, placeholderStyleSlatejsOverrides), props.placeholderStyle);
97
+ return makeRenderPlaceholderFunction(placeholderStyleAugmented);
98
+ }, [props.placeholderStyle]);
99
+ useEffect(() => {
100
+ var _a2, _b;
101
+ if (props.value === lastKnownFullEditorText) {
102
+ return;
103
+ }
104
+ setLastKnownFullEditorText((_a2 = props.value) != null ? _a2 : "");
105
+ replaceEditorText(editor, (_b = props.value) != null ? _b : "");
106
+ }, [props.value]);
107
+ const _a = props, {
108
+ placeholderStyle,
109
+ value,
110
+ onValueChange,
111
+ baseAutosuggestionsConfig: autosuggestionsConfigFromProps,
112
+ className,
113
+ onChange,
114
+ onKeyDown,
115
+ disableBranding
116
+ } = _a, propsToForward = __objRest(_a, [
117
+ "placeholderStyle",
118
+ "value",
119
+ "onValueChange",
120
+ "baseAutosuggestionsConfig",
121
+ "className",
122
+ "onChange",
123
+ "onKeyDown",
124
+ "disableBranding"
125
+ ]);
126
+ useAddBrandingCss(suggestionStyleAugmented, disableBranding);
127
+ usePopulateCopilotTextareaRef(editor, ref);
128
+ const moddedClassName = (() => {
129
+ const baseClassName = "copilot-textarea";
130
+ const brandingClass = disableBranding ? "no-branding" : "with-branding";
131
+ const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
132
+ const mergedClassName = twMerge(
133
+ defaultTailwindClassName,
134
+ className != null ? className : ""
135
+ );
136
+ return `${baseClassName} ${brandingClass} ${mergedClassName}`;
137
+ })();
138
+ return /* @__PURE__ */ jsxs(Slate, {
139
+ editor,
140
+ initialValue,
141
+ onChange: (value2) => {
142
+ var _a2, _b;
143
+ const newEditorState = getTextAroundCollapsedCursor(editor);
144
+ const fullEditorText = newEditorState ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor : getFullEditorTextWithNewlines(editor);
145
+ setLastKnownFullEditorText((prev) => {
146
+ if (prev !== fullEditorText) {
147
+ setCursorMovedSinceLastTextChange(false);
148
+ }
149
+ return fullEditorText;
150
+ });
151
+ onChangeHandlerForAutocomplete(newEditorState);
152
+ (_a2 = props.onValueChange) == null ? void 0 : _a2.call(props, fullEditorText);
153
+ (_b = props.onChange) == null ? void 0 : _b.call(props, makeSemiFakeReactTextAreaEvent(fullEditorText));
154
+ },
155
+ children: [
156
+ /* @__PURE__ */ jsx(TrackerTextEditedSinceLastCursorMovement, {
157
+ setCursorMovedSinceLastTextChange
158
+ }),
159
+ /* @__PURE__ */ jsx(HoveringToolbar, {
160
+ apiConfig: autosuggestionsConfig.apiConfig
161
+ }),
162
+ /* @__PURE__ */ jsx(Editable, __spreadValues({
163
+ renderElement: renderElementMemoized,
164
+ renderPlaceholder: renderPlaceholderMemoized,
165
+ onKeyDown: (event) => {
166
+ var _a2;
167
+ onKeyDownHandlerForHoveringEditor(event);
168
+ onKeyDownHandlerForAutocomplete(event);
169
+ (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
170
+ },
171
+ className: moddedClassName
172
+ }, propsToForward))
173
+ ]
174
+ });
175
+ }
176
+ );
177
+ function makeSemiFakeReactTextAreaEvent(currentText) {
178
+ return {
179
+ target: {
180
+ value: currentText,
181
+ type: "copilot-textarea"
182
+ },
183
+ currentTarget: {
184
+ value: currentText,
185
+ type: "copilot-textarea"
186
+ }
187
+ };
188
+ }
189
+ var BaseCopilotTextarea = React.forwardRef(
190
+ (props, ref) => {
191
+ return /* @__PURE__ */ jsx(HoveringEditorProvider, {
192
+ children: /* @__PURE__ */ jsx(BaseCopilotTextareaWithHoveringContext, __spreadProps(__spreadValues({}, props), {
193
+ ref
194
+ }))
195
+ });
196
+ }
197
+ );
198
+
199
+ export { BaseCopilotTextarea };
200
+ //# sourceMappingURL=out.js.map
201
+ //# sourceMappingURL=chunk-IWTOQKC5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"names":["_a","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAqB,cAAc;AACnC,SAAS,UAAU,aAAa;AAChC,SAAS,eAAe;AAuLlB,SAsBE,KAtBF;AApJN,IAAM,yCAAyC,MAAM;AAAA,EACnD,CACE,OACA,QACgB;AAChB,UAAM,wBAAmD,kCACpD,mCACA,MAAM;AAGX,UAAM,uBAAuB,QAAQ,MAAG;AAhD5C,UAAAA;AAgD+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;AAOhB,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,oBAAoB,CAAC;AAEzB,UAAM,SAAS,yBAAyB;AAExC,UAAM;AAAA,MACJ,aAAa;AAAA,MACb,gBAAgB;AAAA,IAClB,IAAI,yBAAyB;AAE7B,UAAM,aAAa;AAAA,MACjB,CAAC,mBAAwC;AACvC,eAAO,WAAW,QAAQ,eAAe,MAAM;AAAA,UAC7C,IAAI,eAAe;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,MACA,CAAC,MAAM;AAAA,IACT;AAEA,UAAM;AAAA,MACJ;AAAA,MACA,iBAAiB;AAAA,MACjB,kBAAkB;AAAA,IACpB,IAAI;AAAA,MACF,sBAAsB;AAAA,M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,UACpB;AAAA,UACA,WAAW;AAAA,WACP,eACN;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AAaA,SAAS,+BACP,aACwC;AACxC,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,eAAe;AAAA,MACb,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEO,IAAM,sBAAsB,MAAM;AAAA,EACvC,CACE,OACA,QACgB;AAChB,WACE,oBAAC;AAAA,MACC,8BAAC,yEAA2C,QAA3C;AAAA,QAAkD;AAAA,QAAU;AAAA,KAC/D;AAAA,EAEJ;AACF","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 { EditorAutocompleteState } from \"../../types/base/editor-autocomplete-state\";\nimport { TrackerTextEditedSinceLastCursorMovement } from \"./track-cursor-moved-since-last-text-change\";\n\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n value: string;\n focus: () => void;\n blur: () => void;\n}\n\nconst BaseCopilotTextareaWithHoveringContext = React.forwardRef(\n (\n props: BaseCopilotTextareaProps,\n ref: React.Ref<HTMLCopilotTextAreaElement>\n ): JSX.Element => {\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\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 {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.acceptAutosuggestionKey,\n autosuggestionsConfig.apiConfig.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n autosuggestionsConfig.disabled ||\n hoveringEditorIsDisplayed || // disable autosuggestions when the hovering editor is displayed\n (cursorMovedSinceLastTextChange &&\n autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText) // disable autosuggestions when the cursor has moved since the last text change\n );\n const onKeyDownHandlerForHoveringEditor = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n // if command-k, toggle the hovering editor\n if (event.key === \"k\" && event.metaKey) {\n event.preventDefault();\n setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);\n }\n },\n [hoveringEditorIsDisplayed, setHoveringEditorIsDisplayed]\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 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 onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <TrackerTextEditedSinceLastCursorMovement\n setCursorMovedSinceLastTextChange={setCursorMovedSinceLastTextChange}\n />\n <HoveringToolbar apiConfig={autosuggestionsConfig.apiConfig} />\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\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 className={moddedClassName}\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\nexport const BaseCopilotTextarea = React.forwardRef(\n (\n props: BaseCopilotTextareaProps,\n ref: React.Ref<HTMLCopilotTextAreaElement>\n ): JSX.Element => {\n return (\n <HoveringEditorProvider>\n <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />\n </HoveringEditorProvider>\n );\n }\n);\n"]}
@@ -0,0 +1,101 @@
1
+ import { Range, Editor, Text, Element, Path, Point } from 'slate';
2
+
3
+ // src/lib/get-text-around-cursor.ts
4
+ function getTextAroundCollapsedCursor(editor) {
5
+ const { selection } = editor;
6
+ if (!selection || !Range.isCollapsed(selection)) {
7
+ return null;
8
+ }
9
+ const cursorPoint = selection.anchor;
10
+ const beforeRange = {
11
+ anchor: Editor.start(editor, []),
12
+ focus: cursorPoint
13
+ };
14
+ const afterRange = {
15
+ anchor: cursorPoint,
16
+ focus: Editor.end(editor, [])
17
+ };
18
+ const before = extractTextWithNewlines(editor, beforeRange);
19
+ const after = extractTextWithNewlines(editor, afterRange);
20
+ return {
21
+ cursorPoint,
22
+ textBeforeCursor: before,
23
+ textAfterCursor: after
24
+ };
25
+ }
26
+ function getTextAroundSelection(editor) {
27
+ const { selection } = editor;
28
+ if (!selection) {
29
+ return null;
30
+ }
31
+ const wellOrderedSelection = wellOrderedRange(selection);
32
+ const beforeRange = {
33
+ anchor: Editor.start(editor, []),
34
+ focus: wellOrderedSelection.anchor
35
+ };
36
+ const afterRange = {
37
+ anchor: wellOrderedSelection.focus,
38
+ focus: Editor.end(editor, [])
39
+ };
40
+ const before = extractTextWithNewlines(editor, beforeRange);
41
+ const after = extractTextWithNewlines(editor, afterRange);
42
+ const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
43
+ return {
44
+ selection: wellOrderedSelection,
45
+ textBeforeCursor: before,
46
+ selectedText,
47
+ textAfterCursor: after
48
+ };
49
+ }
50
+ function getFullEditorTextWithNewlines(editor) {
51
+ const fullDocumentRange = {
52
+ anchor: Editor.start(editor, []),
53
+ focus: Editor.end(editor, [])
54
+ };
55
+ return extractTextWithNewlines(editor, fullDocumentRange);
56
+ }
57
+ function extractTextWithNewlines(editor, range) {
58
+ const voids = false;
59
+ const [start, end] = Range.edges(range);
60
+ let text = "";
61
+ let lastBlock = null;
62
+ for (const [node, path] of Editor.nodes(editor, {
63
+ at: range,
64
+ match: Text.isText,
65
+ voids
66
+ })) {
67
+ let t = node.text;
68
+ const [block] = Editor.above(editor, {
69
+ at: path,
70
+ match: (n) => Element.isElement(n) && n.type === "paragraph"
71
+ }) || [null];
72
+ if (lastBlock !== block && block) {
73
+ if (lastBlock) {
74
+ text += "\n";
75
+ }
76
+ lastBlock = block;
77
+ }
78
+ if (Path.equals(path, end.path)) {
79
+ t = t.slice(0, end.offset);
80
+ }
81
+ if (Path.equals(path, start.path)) {
82
+ t = t.slice(start.offset);
83
+ }
84
+ text += t;
85
+ }
86
+ return text;
87
+ }
88
+ function wellOrderedRange(range) {
89
+ const { anchor, focus } = range;
90
+ if (Point.isBefore(anchor, focus)) {
91
+ return range;
92
+ }
93
+ return {
94
+ anchor: focus,
95
+ focus: anchor
96
+ };
97
+ }
98
+
99
+ export { extractTextWithNewlines, getFullEditorTextWithNewlines, getTextAroundCollapsedCursor, getTextAroundSelection };
100
+ //# sourceMappingURL=out.js.map
101
+ //# sourceMappingURL=chunk-IXJ2HCOA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/get-text-around-cursor.ts"],"names":[],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AAWA,SAAS,6BACd,QACgC;AAChC,QAAM,EAAE,UAAU,IAAI;AACtB,MAAI,CAAC,aAAa,CAAC,MAAM,YAAY,SAAS,GAAG;AAC/C,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,UAAU;AAG9B,QAAM,cAAqB;AAAA,IACzB,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO;AAAA,EACT;AACA,QAAM,aAAoB;AAAA,IACxB,QAAQ;AAAA,IACR,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AAGA,QAAM,SAAS,wBAAwB,QAAQ,WAAW;AAC1D,QAAM,QAAQ,wBAAwB,QAAQ,UAAU;AAExD,SAAO;AAAA,IACL;AAAA,IACA,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,EACnB;AACF;AAEO,SAAS,uBAAuB,QAAwC;AAC7E,QAAM,EAAE,UAAU,IAAI;AACtB,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,QAAM,uBAAuB,iBAAiB,SAAS;AAGvD,QAAM,cAAqB;AAAA,IACzB,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,qBAAqB;AAAA,EAC9B;AACA,QAAM,aAAoB;AAAA,IACxB,QAAQ,qBAAqB;AAAA,IAC7B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AAGA,QAAM,SAAS,wBAAwB,QAAQ,WAAW;AAC1D,QAAM,QAAQ,wBAAwB,QAAQ,UAAU;AACxD,QAAM,eAAe,wBAAwB,QAAQ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G;AACjC,WAAO;AAAA,EACT;AAGA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF","sourcesContent":["import {\n Editor,\n Node,\n Path,\n Range,\n Text,\n Element,\n BasePoint,\n BaseRange,\n Point,\n} from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(\n editor: Editor\n): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { arraysAreEqual } from './chunk-KGKLUWKW.mjs';
2
+
3
+ // src/types/base/editor-autocomplete-state.ts
4
+ function areEqual_autocompleteState(prev, next) {
5
+ return prev.cursorPoint.offset === next.cursorPoint.offset && arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) && prev.textBeforeCursor === next.textBeforeCursor && prev.textAfterCursor === next.textAfterCursor;
6
+ }
7
+
8
+ export { areEqual_autocompleteState };
9
+ //# sourceMappingURL=out.js.map
10
+ //# sourceMappingURL=chunk-JAFCXEPU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/base/editor-autocomplete-state.ts"],"names":[],"mappings":";;;;;AASO,SAAS,2BACd,MACA,MACA;AACA,SACE,KAAK,YAAY,WAAW,KAAK,YAAY,UAC7C,eAAe,KAAK,YAAY,MAAM,KAAK,YAAY,IAAI,KAC3D,KAAK,qBAAqB,KAAK,oBAC/B,KAAK,oBAAoB,KAAK;AAElC","sourcesContent":["import { BasePoint } from \"slate\";\nimport { arraysAreEqual } from \"../../lib/utils\";\n\nexport interface EditorAutocompleteState {\n cursorPoint: BasePoint;\n textBeforeCursor: string;\n textAfterCursor: string;\n}\n\nexport function areEqual_autocompleteState(\n prev: EditorAutocompleteState,\n next: EditorAutocompleteState\n) {\n return (\n prev.cursorPoint.offset === next.cursorPoint.offset &&\n arraysAreEqual(prev.cursorPoint.path, next.cursorPoint.path) &&\n prev.textBeforeCursor === next.textBeforeCursor &&\n prev.textAfterCursor === next.textAfterCursor\n );\n}\n"]}
@@ -0,0 +1,107 @@
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-KCHYD3EB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"s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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","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"]}
@@ -0,0 +1,47 @@
1
+ import { __async } from './chunk-MRXNTQOX.mjs';
2
+ import { clsx } from 'clsx';
3
+ import { customAlphabet } from 'nanoid';
4
+ import { twMerge } from 'tailwind-merge';
5
+
6
+ function cn(...inputs) {
7
+ return twMerge(clsx(inputs));
8
+ }
9
+ var nanoid = customAlphabet(
10
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
11
+ 7
12
+ );
13
+ function fetcher(input, init) {
14
+ return __async(this, null, function* () {
15
+ const res = yield fetch(input, init);
16
+ if (!res.ok) {
17
+ const json = yield res.json();
18
+ if (json.error) {
19
+ const error = new Error(json.error);
20
+ error.status = res.status;
21
+ throw error;
22
+ } else {
23
+ throw new Error("An unexpected error occurred");
24
+ }
25
+ }
26
+ return res.json();
27
+ });
28
+ }
29
+ function formatDate(input) {
30
+ const date = new Date(input);
31
+ return date.toLocaleDateString("en-US", {
32
+ month: "long",
33
+ day: "numeric",
34
+ year: "numeric"
35
+ });
36
+ }
37
+ var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
38
+ function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
39
+ if (a === null || a === void 0 || b === null || b === void 0) {
40
+ return a === b;
41
+ }
42
+ return naiveEqualityCheck(a, b);
43
+ }
44
+
45
+ export { arraysAreEqual, cn, fetcher, formatDate, nanoid, nullableCompatibleEqualityCheck };
46
+ //# sourceMappingURL=out.js.map
47
+ //# sourceMappingURL=chunk-KGKLUWKW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/utils.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAA6B;AACtC,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAEO,IAAM,SAAS;AAAA,EACpB;AAAA,EACA;AACF;AAEA,SAAsB,QACpB,OACA,MACe;AAAA;AACf,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;AAEO,IAAM,iBAAiB,CAAC,MAAgB,SAC7C,KAAK,WAAW,KAAK,UACrB,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU,KAAK,MAAM;AAE7C,SAAS,gCACd,oBACA,GACA,GACS;AACT,MAAI,MAAM,QAAQ,MAAM,UAAa,MAAM,QAAQ,MAAM,QAAW;AAClE,WAAO,MAAM;AAAA,EACf;AAEA,SAAO,mBAAmB,GAAG,CAAC;AAChC","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { customAlphabet } from \"nanoid\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(\n input: RequestInfo,\n init?: RequestInit\n): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>\n arr1.length === arr2.length &&\n arr1.every((value, index) => value === arr2[index]);\n\nexport function nullableCompatibleEqualityCheck<T>(\n naiveEqualityCheck: (a: T, b: T) => boolean,\n a: T | null | undefined,\n b: T | null | undefined\n): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n return naiveEqualityCheck(a, b);\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-L7VVZH4Q.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+
4
+ function makeRenderElementFunction(suggestionsStyle) {
5
+ return (props) => {
6
+ switch (props.element.type) {
7
+ case "paragraph":
8
+ return /* @__PURE__ */ jsx(DefaultElement, __spreadValues({}, props));
9
+ case "suggestion":
10
+ return /* @__PURE__ */ jsx(SuggestionElement, __spreadProps(__spreadValues({}, props), {
11
+ suggestionsStyle
12
+ }));
13
+ }
14
+ };
15
+ }
16
+ var DefaultElement = (props) => {
17
+ return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({}, props.attributes), {
18
+ children: props.children
19
+ }));
20
+ };
21
+ var SuggestionElement = (props) => {
22
+ return /* @__PURE__ */ jsxs("span", __spreadProps(__spreadValues({}, props.attributes), {
23
+ style: __spreadValues({}, props.suggestionsStyle),
24
+ contentEditable: false,
25
+ children: [
26
+ props.children,
27
+ props.element.type === "suggestion" && props.element.content
28
+ ]
29
+ }));
30
+ };
31
+
32
+ export { makeRenderElementFunction };
33
+ //# sourceMappingURL=out.js.map
34
+ //# sourceMappingURL=chunk-LNAIMEB2.mjs.map