@copilotkit/react-textarea 1.8.14-next.0 → 1.8.14-next.1

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 (67) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-MGYT7RNL.mjs → chunk-4ECCCOFV.mjs} +2 -2
  3. package/dist/{chunk-4XXU5BSA.mjs → chunk-B7WYSFPJ.mjs} +18 -23
  4. package/dist/chunk-B7WYSFPJ.mjs.map +1 -0
  5. package/dist/{chunk-4CVSOOJY.mjs → chunk-F6RLSVG3.mjs} +5 -5
  6. package/dist/chunk-F6RLSVG3.mjs.map +1 -0
  7. package/dist/{chunk-PZYM7K4Y.mjs → chunk-FQHMDD6N.mjs} +15 -11
  8. package/dist/chunk-FQHMDD6N.mjs.map +1 -0
  9. package/dist/{chunk-BNBGJBBM.mjs → chunk-KNH7OQAM.mjs} +5 -5
  10. package/dist/{chunk-2VMZ5ZWT.mjs → chunk-YHMWPA3C.mjs} +1 -4
  11. package/dist/chunk-YHMWPA3C.mjs.map +1 -0
  12. package/dist/{chunk-ABYCGF77.mjs → chunk-YNYXWS2H.mjs} +2 -2
  13. package/dist/chunk-YNYXWS2H.mjs.map +1 -0
  14. package/dist/components/base-copilot-textarea/base-copilot-textarea.js +219 -223
  15. package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -1
  16. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +8 -8
  17. package/dist/components/copilot-textarea/copilot-textarea.js +221 -225
  18. package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -1
  19. package/dist/components/copilot-textarea/copilot-textarea.mjs +15 -15
  20. package/dist/components/hovering-toolbar/hovering-toolbar.js +281 -289
  21. package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -1
  22. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +4 -4
  23. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +0 -3
  24. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -1
  25. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +1 -1
  26. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +0 -1
  27. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +0 -3
  28. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -1
  29. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +2 -2
  30. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +0 -3
  31. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -1
  32. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +2 -2
  33. package/dist/components/index.js +223 -227
  34. package/dist/components/index.js.map +1 -1
  35. package/dist/components/index.mjs +15 -15
  36. package/dist/index.js +223 -227
  37. package/dist/index.js.map +1 -1
  38. package/dist/index.mjs +22 -22
  39. package/dist/types/autosuggestions-config/autosuggestions-config.js +4 -4
  40. package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -1
  41. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +2 -2
  42. package/dist/types/autosuggestions-config/index.js +4 -4
  43. package/dist/types/autosuggestions-config/index.js.map +1 -1
  44. package/dist/types/autosuggestions-config/index.mjs +2 -2
  45. package/dist/types/base/base-autosuggestions-config.d.ts +4 -0
  46. package/dist/types/base/base-autosuggestions-config.js +4 -4
  47. package/dist/types/base/base-autosuggestions-config.js.map +1 -1
  48. package/dist/types/base/base-autosuggestions-config.mjs +1 -1
  49. package/dist/types/base/index.js +4 -4
  50. package/dist/types/base/index.js.map +1 -1
  51. package/dist/types/base/index.mjs +1 -1
  52. package/dist/types/index.js +4 -4
  53. package/dist/types/index.js.map +1 -1
  54. package/dist/types/index.mjs +3 -3
  55. package/package.json +4 -4
  56. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +7 -1
  57. package/src/components/hovering-toolbar/hovering-toolbar.tsx +43 -40
  58. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +0 -3
  59. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +0 -1
  60. package/src/types/base/base-autosuggestions-config.tsx +9 -4
  61. package/dist/chunk-2VMZ5ZWT.mjs.map +0 -1
  62. package/dist/chunk-4CVSOOJY.mjs.map +0 -1
  63. package/dist/chunk-4XXU5BSA.mjs.map +0 -1
  64. package/dist/chunk-ABYCGF77.mjs.map +0 -1
  65. package/dist/chunk-PZYM7K4Y.mjs.map +0 -1
  66. /package/dist/{chunk-MGYT7RNL.mjs.map → chunk-4ECCCOFV.mjs.map} +0 -0
  67. /package/dist/{chunk-BNBGJBBM.mjs.map → chunk-KNH7OQAM.mjs.map} +0 -0
@@ -86,10 +86,194 @@ var import_react6 = require("react");
86
86
  var import_slate2 = require("slate");
87
87
  var import_slate_react = require("slate-react");
88
88
 
89
- // src/hooks/misc/use-autosize-textarea.tsx
89
+ // src/lib/get-text-around-cursor.ts
90
+ var import_slate = require("slate");
91
+ function getTextAroundSelection(editor) {
92
+ const { selection } = editor;
93
+ if (!selection) {
94
+ return null;
95
+ }
96
+ const wellOrderedSelection = wellOrderedRange(selection);
97
+ const beforeRange = {
98
+ anchor: import_slate.Editor.start(editor, []),
99
+ focus: wellOrderedSelection.anchor
100
+ };
101
+ const afterRange = {
102
+ anchor: wellOrderedSelection.focus,
103
+ focus: import_slate.Editor.end(editor, [])
104
+ };
105
+ const before = extractTextWithNewlines(editor, beforeRange);
106
+ const after = extractTextWithNewlines(editor, afterRange);
107
+ const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
108
+ return {
109
+ selection: wellOrderedSelection,
110
+ textBeforeCursor: before,
111
+ selectedText,
112
+ textAfterCursor: after
113
+ };
114
+ }
115
+ function getFullEditorTextWithNewlines(editor) {
116
+ const fullDocumentRange = {
117
+ anchor: import_slate.Editor.start(editor, []),
118
+ focus: import_slate.Editor.end(editor, [])
119
+ };
120
+ return extractTextWithNewlines(editor, fullDocumentRange);
121
+ }
122
+ function extractTextWithNewlines(editor, range) {
123
+ const voids = false;
124
+ const [start, end] = import_slate.Range.edges(range);
125
+ let text = "";
126
+ let lastBlock = null;
127
+ for (const [node, path] of import_slate.Editor.nodes(editor, {
128
+ at: range,
129
+ match: import_slate.Text.isText,
130
+ voids
131
+ })) {
132
+ let t = node.text;
133
+ const [block] = import_slate.Editor.above(editor, {
134
+ at: path,
135
+ match: (n) => import_slate.Element.isElement(n) && n.type === "paragraph"
136
+ }) || [null];
137
+ if (lastBlock !== block && block) {
138
+ if (lastBlock) {
139
+ text += "\n";
140
+ }
141
+ lastBlock = block;
142
+ }
143
+ if (import_slate.Path.equals(path, end.path)) {
144
+ t = t.slice(0, end.offset);
145
+ }
146
+ if (import_slate.Path.equals(path, start.path)) {
147
+ t = t.slice(start.offset);
148
+ }
149
+ text += t;
150
+ }
151
+ return text;
152
+ }
153
+ function wellOrderedRange(range) {
154
+ const { anchor, focus } = range;
155
+ if (import_slate.Point.isBefore(anchor, focus)) {
156
+ return range;
157
+ }
158
+ return {
159
+ anchor: focus,
160
+ focus: anchor
161
+ };
162
+ }
163
+
164
+ // src/components/hovering-toolbar/hovering-editor-provider.tsx
90
165
  var import_react = require("react");
166
+ var import_jsx_runtime = require("react/jsx-runtime");
167
+ var HoveringEditorContext = (0, import_react.createContext)({
168
+ isDisplayed: false,
169
+ setIsDisplayed: () => {
170
+ }
171
+ });
172
+ var useHoveringEditorContext = () => (0, import_react.useContext)(HoveringEditorContext);
173
+
174
+ // src/components/hovering-toolbar/hovering-toolbar-components.tsx
175
+ var import_css = require("@emotion/css");
176
+ var import_react2 = __toESM(require("react"));
177
+ var import_react_dom = __toESM(require("react-dom"));
178
+ var import_jsx_runtime2 = require("react/jsx-runtime");
179
+ var Button = import_react2.default.forwardRef(
180
+ (_a, ref) => {
181
+ var _b = _a, {
182
+ className,
183
+ active,
184
+ reversed
185
+ } = _b, props = __objRest(_b, [
186
+ "className",
187
+ "active",
188
+ "reversed"
189
+ ]);
190
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
191
+ "span",
192
+ __spreadProps(__spreadValues({}, props), {
193
+ ref,
194
+ className: (0, import_css.cx)(
195
+ className,
196
+ import_css.css`
197
+ cursor: pointer;
198
+ color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
199
+ `
200
+ )
201
+ })
202
+ );
203
+ }
204
+ );
205
+ var Icon = import_react2.default.forwardRef(
206
+ (_a, ref) => {
207
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
208
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
209
+ "span",
210
+ __spreadProps(__spreadValues({}, props), {
211
+ ref,
212
+ className: (0, import_css.cx)(
213
+ "material-icons",
214
+ className,
215
+ import_css.css`
216
+ font-size: 18px;
217
+ vertical-align: text-bottom;
218
+ `
219
+ )
220
+ })
221
+ );
222
+ }
223
+ );
224
+ var Menu = import_react2.default.forwardRef(
225
+ (_a, ref) => {
226
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
227
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
228
+ "div",
229
+ __spreadProps(__spreadValues({}, props), {
230
+ "data-testid": "menu",
231
+ ref,
232
+ className: (0, import_css.cx)(
233
+ className,
234
+ import_css.css`
235
+ & > * {
236
+ display: inline-block;
237
+ }
238
+
239
+ & > * + * {
240
+ margin-left: 15px;
241
+ }
242
+ `
243
+ )
244
+ })
245
+ );
246
+ }
247
+ );
248
+ var Portal = ({ children }) => {
249
+ return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
250
+ };
251
+ var Toolbar = import_react2.default.forwardRef(
252
+ (_a, ref) => {
253
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
254
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
255
+ Menu,
256
+ __spreadProps(__spreadValues({}, props), {
257
+ ref,
258
+ className: (0, import_css.cx)(
259
+ className,
260
+ import_css.css`
261
+ position: relative;
262
+ padding: 1px 18px 17px;
263
+ margin: 0 -20px;
264
+ border-bottom: 2px solid #eee;
265
+ margin-bottom: 20px;
266
+ `
267
+ )
268
+ })
269
+ );
270
+ }
271
+ );
272
+
273
+ // src/hooks/misc/use-autosize-textarea.tsx
274
+ var import_react3 = require("react");
91
275
  var useAutosizeTextArea = (textAreaRef, value) => {
92
- (0, import_react.useEffect)(() => {
276
+ (0, import_react3.useEffect)(() => {
93
277
  if (textAreaRef.current !== null) {
94
278
  textAreaRef.current.style.height = "0px";
95
279
  const scrollHeight = textAreaRef.current.scrollHeight;
@@ -100,10 +284,10 @@ var useAutosizeTextArea = (textAreaRef, value) => {
100
284
  var use_autosize_textarea_default = useAutosizeTextArea;
101
285
 
102
286
  // src/components/source-search-box/source-search-box.tsx
103
- var import_react2 = require("react");
287
+ var import_react4 = require("react");
104
288
 
105
289
  // src/components/ui/command.tsx
106
- var React = __toESM(require("react"));
290
+ var React2 = __toESM(require("react"));
107
291
  var import_cmdk = require("cmdk");
108
292
 
109
293
  // src/lib/utils.ts
@@ -114,10 +298,10 @@ function cn(...inputs) {
114
298
  }
115
299
 
116
300
  // src/components/ui/command.tsx
117
- var import_jsx_runtime = require("react/jsx-runtime");
118
- var Command = React.forwardRef((_a, ref) => {
301
+ var import_jsx_runtime3 = require("react/jsx-runtime");
302
+ var Command = React2.forwardRef((_a, ref) => {
119
303
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
120
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
304
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
121
305
  import_cmdk.Command,
122
306
  __spreadValues({
123
307
  ref,
@@ -129,9 +313,9 @@ var Command = React.forwardRef((_a, ref) => {
129
313
  );
130
314
  });
131
315
  Command.displayName = import_cmdk.Command.displayName;
132
- var CommandInput = React.forwardRef((_a, ref) => {
316
+ var CommandInput = React2.forwardRef((_a, ref) => {
133
317
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
134
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
318
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex items-center border-b px-3", "cmdk-input-wrapper": "", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
135
319
  import_cmdk.Command.Input,
136
320
  __spreadValues({
137
321
  ref,
@@ -143,9 +327,9 @@ var CommandInput = React.forwardRef((_a, ref) => {
143
327
  ) });
144
328
  });
145
329
  CommandInput.displayName = import_cmdk.Command.Input.displayName;
146
- var CommandList = React.forwardRef((_a, ref) => {
330
+ var CommandList = React2.forwardRef((_a, ref) => {
147
331
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
148
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
332
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
149
333
  import_cmdk.Command.List,
150
334
  __spreadValues({
151
335
  ref,
@@ -154,11 +338,11 @@ var CommandList = React.forwardRef((_a, ref) => {
154
338
  );
155
339
  });
156
340
  CommandList.displayName = import_cmdk.Command.List.displayName;
157
- var CommandEmpty = React.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
341
+ var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_cmdk.Command.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
158
342
  CommandEmpty.displayName = import_cmdk.Command.Empty.displayName;
159
- var CommandGroup = React.forwardRef((_a, ref) => {
343
+ var CommandGroup = React2.forwardRef((_a, ref) => {
160
344
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
161
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
345
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
162
346
  import_cmdk.Command.Group,
163
347
  __spreadValues({
164
348
  ref,
@@ -170,9 +354,9 @@ var CommandGroup = React.forwardRef((_a, ref) => {
170
354
  );
171
355
  });
172
356
  CommandGroup.displayName = import_cmdk.Command.Group.displayName;
173
- var CommandSeparator = React.forwardRef((_a, ref) => {
357
+ var CommandSeparator = React2.forwardRef((_a, ref) => {
174
358
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
175
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
359
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
176
360
  import_cmdk.Command.Separator,
177
361
  __spreadValues({
178
362
  ref,
@@ -181,9 +365,9 @@ var CommandSeparator = React.forwardRef((_a, ref) => {
181
365
  );
182
366
  });
183
367
  CommandSeparator.displayName = import_cmdk.Command.Separator.displayName;
184
- var CommandItem = React.forwardRef((_a, ref) => {
368
+ var CommandItem = React2.forwardRef((_a, ref) => {
185
369
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
186
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
370
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
187
371
  import_cmdk.Command.Item,
188
372
  __spreadValues({
189
373
  ref,
@@ -197,7 +381,7 @@ var CommandItem = React.forwardRef((_a, ref) => {
197
381
  CommandItem.displayName = import_cmdk.Command.Item.displayName;
198
382
  var CommandShortcut = (_a) => {
199
383
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
200
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
384
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
201
385
  "span",
202
386
  __spreadValues({
203
387
  className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
@@ -207,10 +391,10 @@ var CommandShortcut = (_a) => {
207
391
  CommandShortcut.displayName = "CommandShortcut";
208
392
 
209
393
  // src/components/source-search-box/source-search-box.tsx
210
- var import_jsx_runtime2 = require("react/jsx-runtime");
394
+ var import_jsx_runtime4 = require("react/jsx-runtime");
211
395
  function SourceSearchBox(props) {
212
- const [selectedValue, setSelectedValue] = (0, import_react2.useState)("");
213
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
396
+ const [selectedValue, setSelectedValue] = (0, import_react4.useState)("");
397
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
214
398
  Command,
215
399
  {
216
400
  className: "rounded-lg border shadow-md",
@@ -226,7 +410,7 @@ function SourceSearchBox(props) {
226
410
  return 0;
227
411
  },
228
412
  children: [
229
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
413
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
230
414
  CommandInput,
231
415
  {
232
416
  value: props.searchTerm,
@@ -234,18 +418,18 @@ function SourceSearchBox(props) {
234
418
  placeholder: "Search for a command..."
235
419
  }
236
420
  ),
237
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(CommandList, { children: [
238
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandEmpty, { children: "No results found." }),
239
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
240
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
421
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(CommandList, { children: [
422
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommandEmpty, { children: "No results found." }),
423
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
424
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
241
425
  CommandItem,
242
426
  {
243
427
  value: filePointer.name,
244
428
  onSelect: (value) => {
245
429
  props.onSelectedFile(filePointer);
246
430
  },
247
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
248
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
431
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
432
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
249
433
  "img",
250
434
  {
251
435
  src: filePointer.iconImageUri,
@@ -259,7 +443,7 @@ function SourceSearchBox(props) {
259
443
  `word-${filePointer.sourceApplication}.${filePointer.name}`
260
444
  );
261
445
  }) }),
262
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandSeparator, {})
446
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommandSeparator, {})
263
447
  ] })
264
448
  ]
265
449
  }
@@ -270,17 +454,17 @@ function Logo({
270
454
  width,
271
455
  height
272
456
  }) {
273
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex items-center justify-center", style: { width, height }, children });
457
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex items-center justify-center", style: { width, height }, children });
274
458
  }
275
459
 
276
460
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
277
461
  var import_react_core = require("@copilotkit/react-core");
278
462
 
279
463
  // src/components/ui/button.tsx
280
- var React2 = __toESM(require("react"));
464
+ var React3 = __toESM(require("react"));
281
465
  var import_react_slot = require("@radix-ui/react-slot");
282
466
  var import_class_variance_authority = require("class-variance-authority");
283
- var import_jsx_runtime3 = require("react/jsx-runtime");
467
+ var import_jsx_runtime5 = require("react/jsx-runtime");
284
468
  var buttonVariants = (0, import_class_variance_authority.cva)(
285
469
  "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",
286
470
  {
@@ -306,31 +490,31 @@ var buttonVariants = (0, import_class_variance_authority.cva)(
306
490
  }
307
491
  }
308
492
  );
309
- var Button = React2.forwardRef(
493
+ var Button2 = React3.forwardRef(
310
494
  (_a, ref) => {
311
495
  var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
312
496
  const Comp = asChild ? import_react_slot.Slot : "button";
313
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
497
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
314
498
  }
315
499
  );
316
- Button.displayName = "Button";
500
+ Button2.displayName = "Button";
317
501
 
318
502
  // src/components/ui/label.tsx
319
- var React3 = __toESM(require("react"));
503
+ var React4 = __toESM(require("react"));
320
504
  var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
321
505
  var import_class_variance_authority2 = require("class-variance-authority");
322
- var import_jsx_runtime4 = require("react/jsx-runtime");
506
+ var import_jsx_runtime6 = require("react/jsx-runtime");
323
507
  var labelVariants = (0, import_class_variance_authority2.cva)(
324
508
  "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
325
509
  );
326
- var Label = React3.forwardRef((_a, ref) => {
510
+ var Label = React4.forwardRef((_a, ref) => {
327
511
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
328
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
512
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
329
513
  });
330
514
  Label.displayName = LabelPrimitive.Root.displayName;
331
515
 
332
516
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
333
- var import_react4 = require("react");
517
+ var import_react5 = require("react");
334
518
 
335
519
  // src/lib/stream-promise-flatten.ts
336
520
  function streamPromiseFlatten(promise) {
@@ -359,15 +543,15 @@ function streamPromiseFlatten(promise) {
359
543
  // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
360
544
  var import_Chip = __toESM(require("@mui/material/Chip/Chip.js"));
361
545
  var import_Avatar = __toESM(require("@mui/material/Avatar/Avatar.js"));
362
- var import_jsx_runtime5 = require("react/jsx-runtime");
546
+ var import_jsx_runtime7 = require("react/jsx-runtime");
363
547
  var IncludedFilesPreview = ({
364
548
  includedFiles,
365
549
  setIncludedFiles
366
550
  }) => {
367
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-col gap-2 mt-2", children: [
368
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { className: "", children: "Included context:" }),
369
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
370
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
551
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex flex-col gap-2 mt-2", children: [
552
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "", children: "Included context:" }),
553
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
554
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
371
555
  FileChipPreview,
372
556
  {
373
557
  filePointer,
@@ -381,12 +565,12 @@ var IncludedFilesPreview = ({
381
565
  ] });
382
566
  };
383
567
  var FileChipPreview = ({ filePointer, onDelete }) => {
384
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
568
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
385
569
  import_Chip.default,
386
570
  {
387
571
  label: filePointer.name,
388
572
  onDelete,
389
- avatar: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
573
+ avatar: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
390
574
  import_Avatar.default,
391
575
  {
392
576
  src: filePointer.iconImageUri,
@@ -398,18 +582,8 @@ var FileChipPreview = ({ filePointer, onDelete }) => {
398
582
  );
399
583
  };
400
584
 
401
- // src/components/hovering-toolbar/hovering-editor-provider.tsx
402
- var import_react3 = require("react");
403
- var import_jsx_runtime6 = require("react/jsx-runtime");
404
- var HoveringEditorContext = (0, import_react3.createContext)({
405
- isDisplayed: false,
406
- setIsDisplayed: () => {
407
- }
408
- });
409
- var useHoveringEditorContext = () => (0, import_react3.useContext)(HoveringEditorContext);
410
-
411
585
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
412
- var import_jsx_runtime7 = require("react/jsx-runtime");
586
+ var import_jsx_runtime8 = require("react/jsx-runtime");
413
587
  var HoveringInsertionPromptBoxCore = ({
414
588
  performInsertion,
415
589
  state,
@@ -417,26 +591,26 @@ var HoveringInsertionPromptBoxCore = ({
417
591
  contextCategories
418
592
  }) => {
419
593
  const { getDocumentsContext } = (0, import_react_core.useCopilotContext)();
420
- const [editSuggestion, setEditSuggestion] = (0, import_react4.useState)("");
421
- const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react4.useState)(false);
422
- const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react4.useState)("");
423
- const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react4.useState)(
594
+ const [editSuggestion, setEditSuggestion] = (0, import_react5.useState)("");
595
+ const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react5.useState)(false);
596
+ const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react5.useState)("");
597
+ const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react5.useState)(
424
598
  null
425
599
  );
426
- const adjustmentTextAreaRef = (0, import_react4.useRef)(null);
427
- const suggestionTextAreaRef = (0, import_react4.useRef)(null);
428
- const [filePointers, setFilePointers] = (0, import_react4.useState)([]);
429
- const [suggestedFiles, setSuggestedFiles] = (0, import_react4.useState)([]);
430
- (0, import_react4.useEffect)(() => {
600
+ const adjustmentTextAreaRef = (0, import_react5.useRef)(null);
601
+ const suggestionTextAreaRef = (0, import_react5.useRef)(null);
602
+ const [filePointers, setFilePointers] = (0, import_react5.useState)([]);
603
+ const [suggestedFiles, setSuggestedFiles] = (0, import_react5.useState)([]);
604
+ (0, import_react5.useEffect)(() => {
431
605
  setSuggestedFiles(getDocumentsContext(contextCategories));
432
606
  }, [contextCategories, getDocumentsContext]);
433
607
  use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
434
608
  use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
435
- (0, import_react4.useEffect)(() => {
609
+ (0, import_react5.useEffect)(() => {
436
610
  var _a;
437
611
  (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
438
612
  }, []);
439
- (0, import_react4.useEffect)(() => {
613
+ (0, import_react5.useEffect)(() => {
440
614
  if (!generatingSuggestion) {
441
615
  return;
442
616
  }
@@ -474,7 +648,7 @@ var HoveringInsertionPromptBoxCore = ({
474
648
  releaseLockIfNotClosed();
475
649
  };
476
650
  }, [generatingSuggestion]);
477
- const beginGeneratingAdjustment = (0, import_react4.useCallback)(() => __async(void 0, null, function* () {
651
+ const beginGeneratingAdjustment = (0, import_react5.useCallback)(() => __async(void 0, null, function* () {
478
652
  if (!adjustmentPrompt.trim()) {
479
653
  return;
480
654
  }
@@ -504,10 +678,10 @@ var HoveringInsertionPromptBoxCore = ({
504
678
  const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
505
679
  const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
506
680
  const { setIsDisplayed } = useHoveringEditorContext();
507
- const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
508
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "", children: adjustmentLabel }),
509
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative w-full flex items-center", children: [
510
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
681
+ const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
682
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Label, { className: "", children: adjustmentLabel }),
683
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "relative w-full flex items-center", children: [
684
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
511
685
  "textarea",
512
686
  {
513
687
  "data-testid": "adjustment-prompt",
@@ -522,9 +696,6 @@ var HoveringInsertionPromptBoxCore = ({
522
696
  } else if (e.key === "Enter") {
523
697
  e.preventDefault();
524
698
  beginGeneratingAdjustment();
525
- } else if (e.key == "Escape") {
526
- e.preventDefault();
527
- setIsDisplayed(false);
528
699
  }
529
700
  },
530
701
  placeholder,
@@ -533,30 +704,30 @@ var HoveringInsertionPromptBoxCore = ({
533
704
  rows: 1
534
705
  }
535
706
  ),
536
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
707
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
537
708
  "button",
538
709
  {
539
710
  onClick: beginGeneratingAdjustment,
540
711
  className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
541
712
  "data-testid": "generate-button",
542
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "arrow_forward" })
713
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("i", { className: "material-icons", children: "arrow_forward" })
543
714
  }
544
715
  )
545
716
  ] })
546
717
  ] });
547
- const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
548
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-between items-end w-full", children: [
549
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "mt-4", children: "Suggested:" }),
550
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
718
+ const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
719
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex justify-between items-end w-full", children: [
720
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Label, { className: "mt-4", children: "Suggested:" }),
721
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
551
722
  "div",
552
723
  {
553
724
  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]",
554
725
  role: "status",
555
- children: /* @__PURE__ */ (0, import_jsx_runtime7.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..." })
726
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.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..." })
556
727
  }
557
728
  ) }) })
558
729
  ] }),
559
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
730
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
560
731
  "textarea",
561
732
  {
562
733
  "data-testid": "suggestion-result",
@@ -569,8 +740,8 @@ var HoveringInsertionPromptBoxCore = ({
569
740
  }
570
741
  )
571
742
  ] });
572
- const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
573
- Button,
743
+ const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
744
+ Button2,
574
745
  {
575
746
  "data-testid": "insert-button",
576
747
  className: " bg-green-700 text-white",
@@ -579,16 +750,16 @@ var HoveringInsertionPromptBoxCore = ({
579
750
  },
580
751
  children: [
581
752
  "Insert ",
582
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "check" })
753
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("i", { className: "material-icons", children: "check" })
583
754
  ]
584
755
  }
585
756
  ) });
586
757
  const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
587
758
  const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
588
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
759
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
589
760
  AdjustmentPromptComponent,
590
- filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
591
- sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
761
+ filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
762
+ sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
592
763
  SourceSearchBox,
593
764
  {
594
765
  searchTerm: sourceSearchWord,
@@ -607,14 +778,14 @@ var HoveringInsertionPromptBoxCore = ({
607
778
  };
608
779
 
609
780
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
610
- var import_jsx_runtime8 = require("react/jsx-runtime");
781
+ var import_jsx_runtime9 = require("react/jsx-runtime");
611
782
  var HoveringInsertionPromptBox = (props) => {
612
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
783
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
613
784
  "div",
614
785
  {
615
786
  className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
616
787
  style: { width: "35rem" },
617
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
788
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
618
789
  HoveringInsertionPromptBoxCore,
619
790
  {
620
791
  state: {
@@ -629,180 +800,6 @@ var HoveringInsertionPromptBox = (props) => {
629
800
  );
630
801
  };
631
802
 
632
- // src/components/hovering-toolbar/hovering-toolbar-components.tsx
633
- var import_css = require("@emotion/css");
634
- var import_react5 = __toESM(require("react"));
635
- var import_react_dom = __toESM(require("react-dom"));
636
- var import_jsx_runtime9 = require("react/jsx-runtime");
637
- var Button2 = import_react5.default.forwardRef(
638
- (_a, ref) => {
639
- var _b = _a, {
640
- className,
641
- active,
642
- reversed
643
- } = _b, props = __objRest(_b, [
644
- "className",
645
- "active",
646
- "reversed"
647
- ]);
648
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
649
- "span",
650
- __spreadProps(__spreadValues({}, props), {
651
- ref,
652
- className: (0, import_css.cx)(
653
- className,
654
- import_css.css`
655
- cursor: pointer;
656
- color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
657
- `
658
- )
659
- })
660
- );
661
- }
662
- );
663
- var Icon = import_react5.default.forwardRef(
664
- (_a, ref) => {
665
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
666
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
667
- "span",
668
- __spreadProps(__spreadValues({}, props), {
669
- ref,
670
- className: (0, import_css.cx)(
671
- "material-icons",
672
- className,
673
- import_css.css`
674
- font-size: 18px;
675
- vertical-align: text-bottom;
676
- `
677
- )
678
- })
679
- );
680
- }
681
- );
682
- var Menu = import_react5.default.forwardRef(
683
- (_a, ref) => {
684
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
685
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
686
- "div",
687
- __spreadProps(__spreadValues({}, props), {
688
- "data-testid": "menu",
689
- ref,
690
- className: (0, import_css.cx)(
691
- className,
692
- import_css.css`
693
- & > * {
694
- display: inline-block;
695
- }
696
-
697
- & > * + * {
698
- margin-left: 15px;
699
- }
700
- `
701
- )
702
- })
703
- );
704
- }
705
- );
706
- var Portal = ({ children }) => {
707
- return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
708
- };
709
- var Toolbar = import_react5.default.forwardRef(
710
- (_a, ref) => {
711
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
712
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
713
- Menu,
714
- __spreadProps(__spreadValues({}, props), {
715
- ref,
716
- className: (0, import_css.cx)(
717
- className,
718
- import_css.css`
719
- position: relative;
720
- padding: 1px 18px 17px;
721
- margin: 0 -20px;
722
- border-bottom: 2px solid #eee;
723
- margin-bottom: 20px;
724
- `
725
- )
726
- })
727
- );
728
- }
729
- );
730
-
731
- // src/lib/get-text-around-cursor.ts
732
- var import_slate = require("slate");
733
- function getTextAroundSelection(editor) {
734
- const { selection } = editor;
735
- if (!selection) {
736
- return null;
737
- }
738
- const wellOrderedSelection = wellOrderedRange(selection);
739
- const beforeRange = {
740
- anchor: import_slate.Editor.start(editor, []),
741
- focus: wellOrderedSelection.anchor
742
- };
743
- const afterRange = {
744
- anchor: wellOrderedSelection.focus,
745
- focus: import_slate.Editor.end(editor, [])
746
- };
747
- const before = extractTextWithNewlines(editor, beforeRange);
748
- const after = extractTextWithNewlines(editor, afterRange);
749
- const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
750
- return {
751
- selection: wellOrderedSelection,
752
- textBeforeCursor: before,
753
- selectedText,
754
- textAfterCursor: after
755
- };
756
- }
757
- function getFullEditorTextWithNewlines(editor) {
758
- const fullDocumentRange = {
759
- anchor: import_slate.Editor.start(editor, []),
760
- focus: import_slate.Editor.end(editor, [])
761
- };
762
- return extractTextWithNewlines(editor, fullDocumentRange);
763
- }
764
- function extractTextWithNewlines(editor, range) {
765
- const voids = false;
766
- const [start, end] = import_slate.Range.edges(range);
767
- let text = "";
768
- let lastBlock = null;
769
- for (const [node, path] of import_slate.Editor.nodes(editor, {
770
- at: range,
771
- match: import_slate.Text.isText,
772
- voids
773
- })) {
774
- let t = node.text;
775
- const [block] = import_slate.Editor.above(editor, {
776
- at: path,
777
- match: (n) => import_slate.Element.isElement(n) && n.type === "paragraph"
778
- }) || [null];
779
- if (lastBlock !== block && block) {
780
- if (lastBlock) {
781
- text += "\n";
782
- }
783
- lastBlock = block;
784
- }
785
- if (import_slate.Path.equals(path, end.path)) {
786
- t = t.slice(0, end.offset);
787
- }
788
- if (import_slate.Path.equals(path, start.path)) {
789
- t = t.slice(start.offset);
790
- }
791
- text += t;
792
- }
793
- return text;
794
- }
795
- function wellOrderedRange(range) {
796
- const { anchor, focus } = range;
797
- if (import_slate.Point.isBefore(anchor, focus)) {
798
- return range;
799
- }
800
- return {
801
- anchor: focus,
802
- focus: anchor
803
- };
804
- }
805
-
806
803
  // src/components/hovering-toolbar/hovering-toolbar.tsx
807
804
  var import_jsx_runtime10 = require("react/jsx-runtime");
808
805
  var HoveringToolbar = (props) => {
@@ -814,10 +811,11 @@ var HoveringToolbar = (props) => {
814
811
  (0, import_react6.useEffect)(() => {
815
812
  setIsClient(true);
816
813
  }, []);
817
- (0, import_react6.useEffect)(() => {
814
+ const isShown = isClient && isDisplayed && selection;
815
+ (0, import_react6.useLayoutEffect)(() => {
818
816
  const el = ref.current;
819
817
  const { selection: selection2 } = editor;
820
- if (!el) {
818
+ if (!el || !isShown) {
821
819
  return;
822
820
  }
823
821
  if (!selection2) {
@@ -833,26 +831,23 @@ var HoveringToolbar = (props) => {
833
831
  if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
834
832
  return;
835
833
  }
836
- const minGapFromEdge = 60;
837
- const verticalOffsetFromCorner = 35;
838
- const horizontalOffsetFromCorner = 15;
839
- let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
840
- if (top < minGapFromEdge) {
841
- top = rect.bottom + window.scrollY + minGapFromEdge;
842
- } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
843
- top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
834
+ const verticalOffsetFromCorner = 0;
835
+ const horizontalOffsetFromCorner = 0;
836
+ let top = rect.bottom + window.scrollY + verticalOffsetFromCorner;
837
+ if (rect.bottom + el.offsetHeight > window.innerHeight - verticalOffsetFromCorner) {
838
+ top = rect.top + window.scrollY - el.offsetHeight - verticalOffsetFromCorner;
844
839
  }
845
840
  let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
846
- if (left < minGapFromEdge) {
847
- left = minGapFromEdge;
848
- } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
849
- left = window.innerWidth - el.offsetWidth - minGapFromEdge;
841
+ if (left < horizontalOffsetFromCorner) {
842
+ left = horizontalOffsetFromCorner;
843
+ } else if (left + el.offsetWidth > window.innerWidth - horizontalOffsetFromCorner) {
844
+ left = window.innerWidth - el.offsetWidth - horizontalOffsetFromCorner;
850
845
  }
851
846
  el.style.opacity = "1";
852
847
  el.style.position = "absolute";
853
848
  el.style.top = `${top}px`;
854
849
  el.style.left = `${left}px`;
855
- });
850
+ }, [isShown]);
856
851
  (0, import_react6.useEffect)(() => {
857
852
  const handleClickOutside = (event) => {
858
853
  if (ref.current && !ref.current.contains(event.target)) {
@@ -864,7 +859,7 @@ var HoveringToolbar = (props) => {
864
859
  document.removeEventListener("mousedown", handleClickOutside);
865
860
  };
866
861
  }, [ref, setIsDisplayed]);
867
- if (!isClient) {
862
+ if (!isShown) {
868
863
  return null;
869
864
  }
870
865
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
@@ -873,14 +868,11 @@ var HoveringToolbar = (props) => {
873
868
  ref,
874
869
  className: "copilot-kit-textarea-css-scope " + (props.hoverMenuClassname || "p-2 absolute z-10 top-[-10000px] left-[-10000px] mt-[-6px] opacity-0 transition-opacity duration-700"),
875
870
  "data-testid": "hovering-toolbar",
876
- children: isDisplayed && selection && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
871
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
877
872
  HoveringInsertionPromptBox,
878
873
  {
879
874
  editorState: editorState(editor, selection),
880
875
  apiConfig: props.apiConfig,
881
- closeWindow: () => {
882
- setIsDisplayed(false);
883
- },
884
876
  performInsertion: (insertedText) => {
885
877
  import_slate2.Transforms.delete(editor, { at: selection });
886
878
  import_slate2.Transforms.insertText(editor, insertedText, {