@copilotkit/react-textarea 0.19.0-alpha.9 → 0.19.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 (219) hide show
  1. package/.turbo/turbo-build.log +298 -298
  2. package/CHANGELOG.md +28 -0
  3. package/dist/chunk-2NURR2DX.mjs +47 -0
  4. package/dist/chunk-2NURR2DX.mjs.map +1 -0
  5. package/dist/chunk-3TK2VELX.mjs +202 -0
  6. package/dist/chunk-3TK2VELX.mjs.map +1 -0
  7. package/dist/chunk-47JRPWI3.mjs +257 -0
  8. package/dist/chunk-47JRPWI3.mjs.map +1 -0
  9. package/dist/chunk-4S5ZJH3I.mjs +18 -0
  10. package/dist/chunk-4S5ZJH3I.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-66BDXIX4.mjs +76 -0
  16. package/dist/chunk-66BDXIX4.mjs.map +1 -0
  17. package/dist/chunk-7QWJ3OV7.mjs +108 -0
  18. package/dist/chunk-7QWJ3OV7.mjs.map +1 -0
  19. package/dist/chunk-BBKDE7YT.mjs +19 -0
  20. package/dist/chunk-BBKDE7YT.mjs.map +1 -0
  21. package/dist/chunk-CSGFJU3L.mjs +65 -0
  22. package/dist/chunk-CSGFJU3L.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-FN7GDKKG.mjs +29 -0
  28. package/dist/chunk-FN7GDKKG.mjs.map +1 -0
  29. package/dist/chunk-H4VKQGVU.mjs +3 -0
  30. package/dist/chunk-H4VKQGVU.mjs.map +1 -0
  31. package/dist/chunk-HRTFMM7P.mjs +82 -0
  32. package/dist/chunk-HRTFMM7P.mjs.map +1 -0
  33. package/dist/chunk-IU3WTXLQ.mjs +3 -0
  34. package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
  35. package/dist/chunk-IXJ2HCOA.mjs +101 -0
  36. package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
  37. package/dist/chunk-JAFCXEPU.mjs +10 -0
  38. package/dist/chunk-JAFCXEPU.mjs.map +1 -0
  39. package/dist/chunk-JHTAOLEW.mjs +63 -0
  40. package/dist/chunk-JHTAOLEW.mjs.map +1 -0
  41. package/dist/chunk-K2AVA67P.mjs +57 -0
  42. package/dist/chunk-K2AVA67P.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-KIRROE2K.mjs +37 -0
  48. package/dist/chunk-KIRROE2K.mjs.map +1 -0
  49. package/dist/chunk-L6DZHWEL.mjs +76 -0
  50. package/dist/chunk-L6DZHWEL.mjs.map +1 -0
  51. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  52. package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
  53. package/dist/chunk-LNAIMEB2.mjs +34 -0
  54. package/dist/chunk-LNAIMEB2.mjs.map +1 -0
  55. package/dist/chunk-MMVDU6DF.mjs +3 -0
  56. package/dist/chunk-MMVDU6DF.mjs.map +1 -0
  57. package/dist/chunk-MPME5BW2.mjs +59 -0
  58. package/dist/chunk-MPME5BW2.mjs.map +1 -0
  59. package/dist/chunk-MRXNTQOX.mjs +55 -0
  60. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  61. package/dist/chunk-ND5PXTAW.mjs +17 -0
  62. package/dist/chunk-ND5PXTAW.mjs.map +1 -0
  63. package/dist/chunk-NKW5OU2S.mjs +33 -0
  64. package/dist/chunk-NKW5OU2S.mjs.map +1 -0
  65. package/dist/chunk-O5OWT5GE.mjs +114 -0
  66. package/dist/chunk-O5OWT5GE.mjs.map +1 -0
  67. package/dist/chunk-OD7ZMOVE.mjs +45 -0
  68. package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
  69. package/dist/chunk-OELUUJZY.mjs +16 -0
  70. package/dist/chunk-OELUUJZY.mjs.map +1 -0
  71. package/dist/chunk-OXPXFYUG.mjs +111 -0
  72. package/dist/chunk-OXPXFYUG.mjs.map +1 -0
  73. package/dist/chunk-QNJ6MXJ2.mjs +21 -0
  74. package/dist/chunk-QNJ6MXJ2.mjs.map +1 -0
  75. package/dist/chunk-RDHPSSHJ.mjs +44 -0
  76. package/dist/chunk-RDHPSSHJ.mjs.map +1 -0
  77. package/dist/chunk-RQHOUUXQ.mjs +29 -0
  78. package/dist/chunk-RQHOUUXQ.mjs.map +1 -0
  79. package/dist/chunk-S6JUGJK2.mjs +13 -0
  80. package/dist/chunk-S6JUGJK2.mjs.map +1 -0
  81. package/dist/chunk-UHD44NC5.mjs +101 -0
  82. package/dist/chunk-UHD44NC5.mjs.map +1 -0
  83. package/dist/chunk-WADHCMPK.mjs +3 -0
  84. package/dist/chunk-WADHCMPK.mjs.map +1 -0
  85. package/dist/chunk-WJHSY5T6.mjs +3 -0
  86. package/dist/chunk-WJHSY5T6.mjs.map +1 -0
  87. package/dist/chunk-WJYQWL4I.mjs +27 -0
  88. package/dist/chunk-WJYQWL4I.mjs.map +1 -0
  89. package/dist/chunk-XA7M72ZO.mjs +106 -0
  90. package/dist/chunk-XA7M72ZO.mjs.map +1 -0
  91. package/dist/chunk-XHUMROEY.mjs +91 -0
  92. package/dist/chunk-XHUMROEY.mjs.map +1 -0
  93. package/dist/chunk-YQU7WG7T.mjs +83 -0
  94. package/dist/chunk-YQU7WG7T.mjs.map +1 -0
  95. package/dist/chunk-YTOPHPSG.mjs +45 -0
  96. package/dist/chunk-YTOPHPSG.mjs.map +1 -0
  97. package/dist/chunk-YW3REYX6.mjs +23 -0
  98. package/dist/chunk-YW3REYX6.mjs.map +1 -0
  99. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +34 -1734
  100. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
  101. package/dist/components/base-copilot-textarea/render-element.mjs +3 -52
  102. package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
  103. package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -46
  104. package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
  105. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
  106. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
  107. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
  108. package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
  109. package/dist/components/copilot-textarea/copilot-textarea.mjs +46 -2202
  110. package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
  111. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -22
  112. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
  113. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -125
  114. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
  115. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +17 -877
  116. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
  117. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +11 -577
  118. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
  119. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +12 -592
  120. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
  121. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +13 -592
  122. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
  123. package/dist/components/index.mjs +47 -2203
  124. package/dist/components/index.mjs.map +1 -1
  125. package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
  126. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
  127. package/dist/components/source-search-box/source-search-box.mjs +6 -209
  128. package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
  129. package/dist/components/ui/button.mjs +4 -88
  130. package/dist/components/ui/button.mjs.map +1 -1
  131. package/dist/components/ui/card.mjs +7 -53
  132. package/dist/components/ui/card.mjs.map +1 -1
  133. package/dist/components/ui/command.mjs +5 -266
  134. package/dist/components/ui/command.mjs.map +1 -1
  135. package/dist/components/ui/dialog.mjs +4 -164
  136. package/dist/components/ui/dialog.mjs.map +1 -1
  137. package/dist/components/ui/label.mjs +4 -63
  138. package/dist/components/ui/label.mjs.map +1 -1
  139. package/dist/components/ui/separator.mjs +8 -50
  140. package/dist/components/ui/separator.mjs.map +1 -1
  141. package/dist/components/ui/textarea.mjs +7 -48
  142. package/dist/components/ui/textarea.mjs.map +1 -1
  143. package/dist/context/index.mjs +2 -0
  144. package/dist/context/index.mjs.map +1 -1
  145. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -168
  146. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
  147. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
  148. package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
  149. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -155
  150. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
  151. package/dist/hooks/index.mjs +2 -0
  152. package/dist/hooks/index.mjs.map +1 -1
  153. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -145
  154. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
  155. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +14 -199
  156. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
  157. package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
  158. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
  159. package/dist/index.mjs +49 -2206
  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 +8 -254
  186. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
  187. package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -83
  188. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
  189. package/dist/types/autosuggestions-config/index.mjs +10 -310
  190. package/dist/types/autosuggestions-config/index.mjs.map +1 -1
  191. package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -77
  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 -77
  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 +3 -64
  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 -12
  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 -12
  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 -311
  218. package/dist/types/index.mjs.map +1 -1
  219. package/package.json +4 -4
@@ -1,878 +1,18 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
-
53
- // src/components/hovering-toolbar/hovering-toolbar.tsx
54
- import { useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
55
- import { Transforms } from "slate";
56
- import { useSlate, useSlateSelection } from "slate-react";
57
-
58
- // src/hooks/misc/use-autosize-textarea.tsx
59
- import { useEffect } from "react";
60
- var useAutosizeTextArea = (textAreaRef, value) => {
61
- useEffect(() => {
62
- if (textAreaRef.current !== null) {
63
- textAreaRef.current.style.height = "0px";
64
- const scrollHeight = textAreaRef.current.scrollHeight;
65
- textAreaRef.current.style.height = scrollHeight + "px";
66
- }
67
- }, [textAreaRef, value]);
68
- };
69
- var use_autosize_textarea_default = useAutosizeTextArea;
70
-
71
- // src/components/source-search-box/source-search-box.tsx
72
- import { useState } from "react";
73
-
74
- // src/components/ui/command.tsx
75
- import * as React from "react";
76
- import { Command as CommandPrimitive } from "cmdk";
77
-
78
- // src/lib/utils.ts
79
- import { clsx } from "clsx";
80
- import { customAlphabet } from "nanoid";
81
- import { twMerge } from "tailwind-merge";
82
- function cn(...inputs) {
83
- return twMerge(clsx(inputs));
84
- }
85
- var nanoid = customAlphabet(
86
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
87
- 7
88
- );
89
-
90
- // src/components/ui/command.tsx
91
- import { jsx } from "react/jsx-runtime";
92
- "use client";
93
- var Command = React.forwardRef((_a, ref) => {
94
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
95
- return /* @__PURE__ */ jsx(CommandPrimitive, __spreadValues({
96
- ref,
97
- className: cn(
98
- "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
99
- className
100
- )
101
- }, props));
102
- });
103
- Command.displayName = CommandPrimitive.displayName;
104
- var CommandInput = React.forwardRef((_a, ref) => {
105
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
106
- return /* @__PURE__ */ jsx("div", {
107
- className: "flex items-center border-b px-3",
108
- "cmdk-input-wrapper": "",
109
- children: /* @__PURE__ */ jsx(CommandPrimitive.Input, __spreadValues({
110
- ref,
111
- className: cn(
112
- "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
113
- className
114
- )
115
- }, props))
116
- });
117
- });
118
- CommandInput.displayName = CommandPrimitive.Input.displayName;
119
- var CommandList = React.forwardRef((_a, ref) => {
120
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
121
- return /* @__PURE__ */ jsx(CommandPrimitive.List, __spreadValues({
122
- ref,
123
- className: cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)
124
- }, props));
125
- });
126
- CommandList.displayName = CommandPrimitive.List.displayName;
127
- var CommandEmpty = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(CommandPrimitive.Empty, __spreadValues({
128
- ref,
129
- className: "py-6 text-center text-sm"
130
- }, props)));
131
- CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
132
- var CommandGroup = React.forwardRef((_a, ref) => {
133
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
134
- return /* @__PURE__ */ jsx(CommandPrimitive.Group, __spreadValues({
135
- ref,
136
- className: cn(
137
- "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
138
- className
139
- )
140
- }, props));
141
- });
142
- CommandGroup.displayName = CommandPrimitive.Group.displayName;
143
- var CommandSeparator = React.forwardRef((_a, ref) => {
144
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
145
- return /* @__PURE__ */ jsx(CommandPrimitive.Separator, __spreadValues({
146
- ref,
147
- className: cn("-mx-1 h-px bg-border", className)
148
- }, props));
149
- });
150
- CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
151
- var CommandItem = React.forwardRef((_a, ref) => {
152
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
153
- return /* @__PURE__ */ jsx(CommandPrimitive.Item, __spreadValues({
154
- ref,
155
- className: cn(
156
- "relative flex cursor-default select-none items-center rounded-sm text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
157
- className
158
- )
159
- }, props));
160
- });
161
- CommandItem.displayName = CommandPrimitive.Item.displayName;
162
- var CommandShortcut = (_a) => {
163
- var _b = _a, {
164
- className
165
- } = _b, props = __objRest(_b, [
166
- "className"
167
- ]);
168
- return /* @__PURE__ */ jsx("span", __spreadValues({
169
- className: cn(
170
- "ml-auto text-xs tracking-widest text-muted-foreground",
171
- className
172
- )
173
- }, props));
174
- };
175
- CommandShortcut.displayName = "CommandShortcut";
176
-
177
- // src/components/source-search-box/source-search-box.tsx
178
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
179
- function SourceSearchBox(props) {
180
- const [selectedValue, setSelectedValue] = useState("");
181
- return /* @__PURE__ */ jsxs(Command, {
182
- className: "rounded-lg border shadow-md",
183
- value: selectedValue,
184
- onValueChange: (value) => {
185
- setSelectedValue(value);
186
- },
187
- filter: (value, search) => {
188
- if (props.searchTerm === "")
189
- return 1;
190
- if (value.startsWith(props.searchTerm))
191
- return 1;
192
- return 0;
193
- },
194
- children: [
195
- /* @__PURE__ */ jsx2(CommandInput, {
196
- value: props.searchTerm,
197
- className: "rounded-t-lg hidden",
198
- placeholder: "Search for a command..."
199
- }),
200
- /* @__PURE__ */ jsxs(CommandList, {
201
- children: [
202
- /* @__PURE__ */ jsx2(CommandEmpty, {
203
- children: "No results found."
204
- }),
205
- /* @__PURE__ */ jsx2(CommandGroup, {
206
- heading: "Available resources",
207
- children: props.suggestedFiles.map((filePointer) => {
208
- return /* @__PURE__ */ jsx2(CommandItem, {
209
- value: filePointer.name,
210
- onSelect: (value) => {
211
- props.onSelectedFile(filePointer);
212
- },
213
- children: /* @__PURE__ */ jsxs("div", {
214
- className: "flex flex-row gap-3 items-center",
215
- children: [
216
- /* @__PURE__ */ jsx2(Logo, {
217
- size: "30px",
218
- children: /* @__PURE__ */ jsx2("img", {
219
- src: filePointer.iconImageUri,
220
- alt: filePointer.sourceApplication,
221
- width: 30,
222
- height: 30
223
- })
224
- }),
225
- filePointer.name
226
- ]
227
- })
228
- }, `word-${filePointer.sourceApplication}.${filePointer.name}`);
229
- })
230
- }),
231
- /* @__PURE__ */ jsx2(CommandSeparator, {})
232
- ]
233
- })
234
- ]
235
- });
236
- }
237
- function Logo({
238
- children,
239
- size = "30px"
240
- }) {
241
- return /* @__PURE__ */ jsx2("div", {
242
- className: "flex items-center justify-center bg-black",
243
- style: { width: size, height: size },
244
- children
245
- });
246
- }
247
-
248
- // src/components/ui/button.tsx
249
- import * as React2 from "react";
250
- import { Slot } from "@radix-ui/react-slot";
251
- import { cva } from "class-variance-authority";
252
- import { jsx as jsx3 } from "react/jsx-runtime";
253
- var buttonVariants = cva(
254
- "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
255
- {
256
- variants: {
257
- variant: {
258
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
259
- destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
260
- outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
261
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
262
- ghost: "hover:bg-accent hover:text-accent-foreground",
263
- link: "text-primary underline-offset-4 hover:underline"
264
- },
265
- size: {
266
- default: "h-10 px-4 py-2",
267
- sm: "h-9 rounded-md px-3",
268
- lg: "h-11 rounded-md px-8",
269
- icon: "h-10 w-10"
270
- }
271
- },
272
- defaultVariants: {
273
- variant: "default",
274
- size: "default"
275
- }
276
- }
277
- );
278
- var Button = React2.forwardRef(
279
- (_a, ref) => {
280
- var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
281
- const Comp = asChild ? Slot : "button";
282
- return /* @__PURE__ */ jsx3(Comp, __spreadValues({
283
- className: cn(buttonVariants({ variant, size, className })),
284
- ref
285
- }, props));
286
- }
287
- );
288
- Button.displayName = "Button";
289
-
290
- // src/components/ui/label.tsx
291
- import * as React3 from "react";
292
- import * as LabelPrimitive from "@radix-ui/react-label";
293
- import { cva as cva2 } from "class-variance-authority";
294
- import { jsx as jsx4 } from "react/jsx-runtime";
295
- "use client";
296
- var labelVariants = cva2(
297
- "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
298
- );
299
- var Label = React3.forwardRef((_a, ref) => {
300
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
301
- return /* @__PURE__ */ jsx4(LabelPrimitive.Root, __spreadValues({
302
- ref,
303
- className: cn(labelVariants(), className)
304
- }, props));
305
- });
306
- Label.displayName = LabelPrimitive.Root.displayName;
307
-
308
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
309
- import { useContext, useEffect as useEffect2, useRef, useState as useState2 } from "react";
310
- import Chip from "@mui/material/Chip";
311
- import Avatar from "@mui/material/Avatar";
312
-
313
- // src/lib/stream-promise-flatten.ts
314
- function streamPromiseFlatten(promise) {
315
- return new ReadableStream({
316
- start(controller) {
317
- return __async(this, null, function* () {
318
- try {
319
- const stream = yield promise;
320
- const reader = stream.getReader();
321
- while (true) {
322
- const { done, value } = yield reader.read();
323
- if (done) {
324
- controller.close();
325
- return;
326
- }
327
- controller.enqueue(value);
328
- }
329
- } catch (error) {
330
- controller.error(error);
331
- }
332
- });
333
- }
334
- });
335
- }
336
-
337
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
338
- import { CopilotContext } from "@copilotkit/react-core";
339
- import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
340
- var HoveringInsertionPromptBoxCore = ({
341
- performInsertion,
342
- state,
343
- insertionOrEditingFunction,
344
- contextCategories
345
- }) => {
346
- const { getDocumentsContext } = useContext(CopilotContext);
347
- const [editSuggestion, setEditSuggestion] = useState2("");
348
- const [suggestionIsLoading, setSuggestionIsLoading] = useState2(false);
349
- const [adjustmentPrompt, setAdjustmentPrompt] = useState2("");
350
- const [generatingSuggestion, setGeneratingSuggestion] = useState2(null);
351
- const adjustmentTextAreaRef = useRef(null);
352
- const suggestionTextAreaRef = useRef(null);
353
- const [filePointers, setFilePointers] = useState2([]);
354
- const [suggestedFiles, setSuggestedFiles] = useState2([]);
355
- useEffect2(() => {
356
- setSuggestedFiles(getDocumentsContext(contextCategories));
357
- }, [contextCategories, getDocumentsContext]);
358
- use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
359
- use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
360
- useEffect2(() => {
361
- var _a;
362
- (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
363
- }, []);
364
- useEffect2(() => {
365
- if (!generatingSuggestion) {
366
- return;
367
- }
368
- if (generatingSuggestion.locked) {
369
- return;
370
- }
371
- setEditSuggestion("");
372
- const reader = generatingSuggestion.getReader();
373
- const read = () => __async(void 0, null, function* () {
374
- setSuggestionIsLoading(true);
375
- while (true) {
376
- const { done, value } = yield reader.read();
377
- if (done) {
378
- break;
379
- }
380
- setEditSuggestion((prev) => {
381
- const newSuggestion = prev + value;
382
- if (suggestionTextAreaRef.current) {
383
- suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
384
- }
385
- return newSuggestion;
386
- });
387
- }
388
- setSuggestionIsLoading(false);
389
- });
390
- read();
391
- return () => {
392
- const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
393
- try {
394
- yield reader.closed;
395
- } catch (e) {
396
- reader.releaseLock();
397
- }
398
- });
399
- releaseLockIfNotClosed();
400
- };
401
- }, [generatingSuggestion]);
402
- const begingGeneratingAdjustment = () => __async(void 0, null, function* () {
403
- if (!adjustmentPrompt.trim()) {
404
- return;
405
- }
406
- let editorState2 = state.editorState;
407
- if (editSuggestion !== "") {
408
- editorState2.selectedText = editSuggestion;
409
- }
410
- const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
411
- editorState2,
412
- adjustmentPrompt,
413
- new AbortController().signal
414
- );
415
- const adjustmentSuggestionTextStream = streamPromiseFlatten(
416
- adjustmentSuggestionTextStreamPromise
417
- );
418
- setGeneratingSuggestion(adjustmentSuggestionTextStream);
419
- });
420
- const isLoading = suggestionIsLoading;
421
- const textToEdit = editSuggestion || state.editorState.selectedText;
422
- const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
423
- const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
424
- const AdjustmentPromptComponent = /* @__PURE__ */ jsxs2(Fragment, {
425
- children: [
426
- /* @__PURE__ */ jsx5(Label, {
427
- className: "",
428
- children: adjustmentLabel
429
- }),
430
- /* @__PURE__ */ jsxs2("div", {
431
- className: "relative w-full flex items-center",
432
- children: [
433
- /* @__PURE__ */ jsx5("textarea", {
434
- disabled: suggestionIsLoading,
435
- ref: adjustmentTextAreaRef,
436
- value: adjustmentPrompt,
437
- onChange: (e) => setAdjustmentPrompt(e.target.value),
438
- onKeyDown: (e) => {
439
- if (e.key === "Enter" && e.shiftKey) {
440
- e.preventDefault();
441
- setAdjustmentPrompt(adjustmentPrompt + "\n");
442
- } else if (e.key === "Enter") {
443
- e.preventDefault();
444
- begingGeneratingAdjustment();
445
- }
446
- },
447
- placeholder,
448
- style: { minHeight: "3rem" },
449
- className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
450
- rows: 1
451
- }),
452
- /* @__PURE__ */ jsx5("button", {
453
- onClick: begingGeneratingAdjustment,
454
- className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
455
- children: /* @__PURE__ */ jsx5("i", {
456
- className: "material-icons",
457
- children: "arrow_forward"
458
- })
459
- })
460
- ]
461
- })
462
- ]
463
- });
464
- const SuggestionComponent = /* @__PURE__ */ jsxs2(Fragment, {
465
- children: [
466
- /* @__PURE__ */ jsxs2("div", {
467
- className: "flex justify-between items-end w-full",
468
- children: [
469
- /* @__PURE__ */ jsx5(Label, {
470
- className: "mt-4",
471
- children: "Suggested:"
472
- }),
473
- /* @__PURE__ */ jsx5("div", {
474
- className: "ml-auto",
475
- children: isLoading && /* @__PURE__ */ jsx5("div", {
476
- className: "flex justify-center items-center",
477
- children: /* @__PURE__ */ jsx5("div", {
478
- className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
479
- role: "status",
480
- children: /* @__PURE__ */ jsx5("span", {
481
- className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]",
482
- children: "Loading..."
483
- })
484
- })
485
- })
486
- })
487
- ]
488
- }),
489
- /* @__PURE__ */ jsx5("textarea", {
490
- ref: suggestionTextAreaRef,
491
- value: editSuggestion,
492
- disabled: suggestionIsLoading,
493
- onChange: (e) => setEditSuggestion(e.target.value),
494
- className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
495
- style: { overflow: "auto", maxHeight: "10em" }
496
- })
497
- ]
498
- });
499
- const SubmitComponent = /* @__PURE__ */ jsx5("div", {
500
- className: "flex w-full gap-4 justify-start",
501
- children: /* @__PURE__ */ jsxs2(Button, {
502
- className: " bg-green-700 text-white",
503
- onClick: () => {
504
- performInsertion(editSuggestion);
505
- },
506
- children: [
507
- "Insert ",
508
- /* @__PURE__ */ jsx5("i", {
509
- className: "material-icons",
510
- children: "check"
511
- })
512
- ]
513
- })
514
- });
515
- const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
516
- const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
517
- return /* @__PURE__ */ jsxs2("div", {
518
- className: "w-full flex flex-col items-start relative gap-2",
519
- children: [
520
- AdjustmentPromptComponent,
521
- filePointers.length > 0 && /* @__PURE__ */ jsx5(IncludedFilesPreview, {
522
- includedFiles: filePointers,
523
- setIncludedFiles: setFilePointers
524
- }),
525
- sourceSearchWord !== void 0 && /* @__PURE__ */ jsx5(SourceSearchBox, {
526
- searchTerm: sourceSearchWord,
527
- suggestedFiles,
528
- onSelectedFile: (filePointer) => {
529
- var _a;
530
- setAdjustmentPrompt(
531
- adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), "")
532
- );
533
- setFilePointers((prev) => [...prev, filePointer]);
534
- (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
535
- }
536
- }),
537
- generatingSuggestion ? SuggestionComponent : null,
538
- generatingSuggestion ? SubmitComponent : null
539
- ]
540
- });
541
- };
542
- var IncludedFilesPreview = ({
543
- includedFiles,
544
- setIncludedFiles
545
- }) => {
546
- return /* @__PURE__ */ jsxs2("div", {
547
- className: "flex flex-col gap-2 mt-2",
548
- children: [
549
- /* @__PURE__ */ jsx5(Label, {
550
- className: "",
551
- children: "Included context:"
552
- }),
553
- /* @__PURE__ */ jsx5("div", {
554
- className: "flex flex-wrap gap-2",
555
- children: includedFiles.map((filePointer, index) => {
556
- return /* @__PURE__ */ jsx5(FileChipPreview, {
557
- filePointer,
558
- onDelete: () => {
559
- setIncludedFiles(
560
- (prev) => prev.filter((fp) => fp !== filePointer)
561
- );
562
- }
563
- }, `file-${filePointer.sourceApplication}.${filePointer.name}`);
564
- })
565
- })
566
- ]
567
- });
568
- };
569
- var FileChipPreview = ({
570
- filePointer,
571
- onDelete
572
- }) => {
573
- return /* @__PURE__ */ jsx5(Chip, {
574
- label: filePointer.name,
575
- onDelete,
576
- avatar: /* @__PURE__ */ jsx5(Avatar, {
577
- sx: { backgroundColor: "transparent" }
578
- })
579
- });
580
- };
581
-
582
- // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
583
- import { jsx as jsx6 } from "react/jsx-runtime";
584
- var HoveringInsertionPromptBox = (props) => {
585
- return /* @__PURE__ */ jsx6("div", {
586
- className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
587
- style: { width: "35rem" },
588
- children: /* @__PURE__ */ jsx6(HoveringInsertionPromptBoxCore, {
589
- state: {
590
- editorState: props.editorState
591
- },
592
- performInsertion: props.performInsertion,
593
- insertionOrEditingFunction: props.apiConfig.insertionOrEditingFunction,
594
- contextCategories: props.contextCategories
595
- })
596
- });
597
- };
598
-
599
- // src/components/hovering-toolbar/hovering-toolbar-components.tsx
600
- import { css, cx } from "@emotion/css";
601
- import React5 from "react";
602
- import ReactDOM from "react-dom";
603
- import { jsx as jsx7 } from "react/jsx-runtime";
604
- var Button2 = React5.forwardRef(
605
- (_a, ref) => {
606
- var _b = _a, {
607
- className,
608
- active,
609
- reversed
610
- } = _b, props = __objRest(_b, [
611
- "className",
612
- "active",
613
- "reversed"
614
- ]);
615
- return /* @__PURE__ */ jsx7("span", __spreadProps(__spreadValues({}, props), {
616
- ref,
617
- className: cx(
618
- className,
619
- css`
620
- cursor: pointer;
621
- color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
622
- `
623
- )
624
- }));
625
- }
626
- );
627
- var Icon = React5.forwardRef(
628
- (_a, ref) => {
629
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
630
- return /* @__PURE__ */ jsx7("span", __spreadProps(__spreadValues({}, props), {
631
- ref,
632
- className: cx(
633
- "material-icons",
634
- className,
635
- css`
636
- font-size: 18px;
637
- vertical-align: text-bottom;
638
- `
639
- )
640
- }));
641
- }
642
- );
643
- var Menu = React5.forwardRef(
644
- (_a, ref) => {
645
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
646
- return /* @__PURE__ */ jsx7("div", __spreadProps(__spreadValues({}, props), {
647
- "data-test-id": "menu",
648
- ref,
649
- className: cx(
650
- className,
651
- css`
652
- & > * {
653
- display: inline-block;
654
- }
655
-
656
- & > * + * {
657
- margin-left: 15px;
658
- }
659
- `
660
- )
661
- }));
662
- }
663
- );
664
- var Portal = ({ children }) => {
665
- return typeof document === "object" ? ReactDOM.createPortal(children, document.body) : null;
666
- };
667
- var Toolbar = React5.forwardRef(
668
- (_a, ref) => {
669
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
670
- return /* @__PURE__ */ jsx7(Menu, __spreadProps(__spreadValues({}, props), {
671
- ref,
672
- className: cx(
673
- className,
674
- css`
675
- position: relative;
676
- padding: 1px 18px 17px;
677
- margin: 0 -20px;
678
- border-bottom: 2px solid #eee;
679
- margin-bottom: 20px;
680
- `
681
- )
682
- }));
683
- }
684
- );
685
-
686
- // src/components/hovering-toolbar/hovering-editor-provider.tsx
687
- import { createContext, useState as useState3, useContext as useContext2 } from "react";
688
- import { jsx as jsx8 } from "react/jsx-runtime";
689
- var HoveringEditorContext = createContext({
690
- isDisplayed: false,
691
- setIsDisplayed: () => {
692
- }
693
- });
694
- var useHoveringEditorContext = () => useContext2(HoveringEditorContext);
695
-
696
- // src/lib/get-text-around-cursor.ts
697
- import {
698
- Editor,
699
- Path,
700
- Range,
701
- Text,
702
- Element,
703
- Point
704
- } from "slate";
705
- function getTextAroundSelection(editor) {
706
- const { selection } = editor;
707
- if (!selection) {
708
- return null;
709
- }
710
- const wellOrderedSelection = wellOrderedRange(selection);
711
- const beforeRange = {
712
- anchor: Editor.start(editor, []),
713
- focus: wellOrderedSelection.anchor
714
- };
715
- const afterRange = {
716
- anchor: wellOrderedSelection.focus,
717
- focus: Editor.end(editor, [])
718
- };
719
- const before = extractTextWithNewlines(editor, beforeRange);
720
- const after = extractTextWithNewlines(editor, afterRange);
721
- const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
722
- return {
723
- selection: wellOrderedSelection,
724
- textBeforeCursor: before,
725
- selectedText,
726
- textAfterCursor: after
727
- };
728
- }
729
- function getFullEditorTextWithNewlines(editor) {
730
- const fullDocumentRange = {
731
- anchor: Editor.start(editor, []),
732
- focus: Editor.end(editor, [])
733
- };
734
- return extractTextWithNewlines(editor, fullDocumentRange);
735
- }
736
- function extractTextWithNewlines(editor, range) {
737
- const voids = false;
738
- const [start, end] = Range.edges(range);
739
- let text = "";
740
- let lastBlock = null;
741
- for (const [node, path] of Editor.nodes(editor, {
742
- at: range,
743
- match: Text.isText,
744
- voids
745
- })) {
746
- let t = node.text;
747
- const [block] = Editor.above(editor, {
748
- at: path,
749
- match: (n) => Element.isElement(n) && n.type === "paragraph"
750
- }) || [null];
751
- if (lastBlock !== block && block) {
752
- if (lastBlock) {
753
- text += "\n";
754
- }
755
- lastBlock = block;
756
- }
757
- if (Path.equals(path, end.path)) {
758
- t = t.slice(0, end.offset);
759
- }
760
- if (Path.equals(path, start.path)) {
761
- t = t.slice(start.offset);
762
- }
763
- text += t;
764
- }
765
- return text;
766
- }
767
- function wellOrderedRange(range) {
768
- const { anchor, focus } = range;
769
- if (Point.isBefore(anchor, focus)) {
770
- return range;
771
- }
772
- return {
773
- anchor: focus,
774
- focus: anchor
775
- };
776
- }
777
-
778
- // src/components/hovering-toolbar/hovering-toolbar.tsx
779
- import { jsx as jsx9 } from "react/jsx-runtime";
780
- var HoveringToolbar = (props) => {
781
- const ref = useRef2(null);
782
- const editor = useSlate();
783
- const selection = useSlateSelection();
784
- const { isDisplayed, setIsDisplayed } = useHoveringEditorContext();
785
- const [isClient, setIsClient] = useState4(false);
786
- useEffect3(() => {
787
- setIsClient(true);
788
- }, []);
789
- useEffect3(() => {
790
- const el = ref.current;
791
- const { selection: selection2 } = editor;
792
- if (!el) {
793
- return;
794
- }
795
- if (!selection2) {
796
- el.removeAttribute("style");
797
- return;
798
- }
799
- const domSelection = window.getSelection();
800
- if (!domSelection) {
801
- return;
802
- }
803
- const domRange = domSelection.getRangeAt(0);
804
- const rect = domRange.getBoundingClientRect();
805
- if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
806
- return;
807
- }
808
- const minGapFromEdge = 60;
809
- const verticalOffsetFromCorner = 35;
810
- const horizontalOffsetFromCorner = 15;
811
- let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
812
- if (top < minGapFromEdge) {
813
- top = rect.bottom + window.scrollY + minGapFromEdge;
814
- } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
815
- top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
816
- }
817
- let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
818
- if (left < minGapFromEdge) {
819
- left = minGapFromEdge;
820
- } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
821
- left = window.innerWidth - el.offsetWidth - minGapFromEdge;
822
- }
823
- el.style.opacity = "1";
824
- el.style.top = `${top}px`;
825
- el.style.left = `${left}px`;
826
- });
827
- useEffect3(() => {
828
- const handleClickOutside = (event) => {
829
- if (ref.current && !ref.current.contains(event.target)) {
830
- setIsDisplayed(false);
831
- }
832
- };
833
- document.addEventListener("mousedown", handleClickOutside);
834
- return () => {
835
- document.removeEventListener("mousedown", handleClickOutside);
836
- };
837
- }, [ref, setIsDisplayed]);
838
- if (!isClient) {
839
- return null;
840
- }
841
- return /* @__PURE__ */ jsx9(Portal, {
842
- children: /* @__PURE__ */ jsx9(Menu, {
843
- ref,
844
- className: "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700",
845
- children: isDisplayed && selection && /* @__PURE__ */ jsx9(HoveringInsertionPromptBox, {
846
- editorState: editorState(editor, selection),
847
- apiConfig: props.apiConfig,
848
- closeWindow: () => {
849
- setIsDisplayed(false);
850
- },
851
- performInsertion: (insertedText) => {
852
- console.log("inserted text", insertedText);
853
- Transforms.delete(editor, { at: selection });
854
- Transforms.insertText(editor, insertedText, {
855
- at: selection
856
- });
857
- setIsDisplayed(false);
858
- },
859
- contextCategories: props.contextCategories
860
- })
861
- })
862
- });
863
- };
864
- function editorState(editor, selection) {
865
- const textAroundCursor = getTextAroundSelection(editor);
866
- if (textAroundCursor) {
867
- return textAroundCursor;
868
- }
869
- return {
870
- textBeforeCursor: getFullEditorTextWithNewlines(editor),
871
- textAfterCursor: "",
872
- selectedText: ""
873
- };
874
- }
875
- export {
876
- HoveringToolbar
877
- };
1
+ export { HoveringToolbar } from '../../chunk-7QWJ3OV7.mjs';
2
+ import '../../chunk-L7VVZH4Q.mjs';
3
+ import '../../chunk-QNJ6MXJ2.mjs';
4
+ import '../../chunk-47JRPWI3.mjs';
5
+ import '../../chunk-ND5PXTAW.mjs';
6
+ import '../../chunk-2NURR2DX.mjs';
7
+ import '../../chunk-5EJ5XOGP.mjs';
8
+ import '../../chunk-YW3REYX6.mjs';
9
+ import '../../chunk-XHUMROEY.mjs';
10
+ import '../../chunk-L6DZHWEL.mjs';
11
+ import '../../chunk-XA7M72ZO.mjs';
12
+ import '../../chunk-O5OWT5GE.mjs';
13
+ import '../../chunk-FN7GDKKG.mjs';
14
+ import '../../chunk-KGKLUWKW.mjs';
15
+ import '../../chunk-IXJ2HCOA.mjs';
16
+ import '../../chunk-MRXNTQOX.mjs';
17
+ //# sourceMappingURL=out.js.map
878
18
  //# sourceMappingURL=hovering-toolbar.mjs.map