@copilotkit/react-textarea 0.28.0-alpha.1 → 0.28.0-alpha.2

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