@copilotkit/react-textarea 1.8.13 → 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 +19 -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 +21 -21
  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
package/dist/index.js CHANGED
@@ -635,11 +635,10 @@ function clearAutocompletionsFromEditor(editor) {
635
635
 
636
636
  // src/types/base/base-autosuggestions-config.tsx
637
637
  var import_react_core = require("@copilotkit/react-core");
638
+ var import_shared = require("@copilotkit/shared");
638
639
  var defaultShouldToggleHoveringEditorOnKeyPress = (event, shortcut) => {
639
- if (event.key === shortcut && event.metaKey) {
640
- return true;
641
- }
642
- return false;
640
+ const isMetaKey = (0, import_shared.isMacOS)() ? event.metaKey : event.ctrlKey;
641
+ return event.key === shortcut && isMetaKey;
643
642
  };
644
643
  var defaultShouldAcceptAutosuggestionOnKeyPress = (event) => {
645
644
  if (event.key === "Tab") {
@@ -654,6 +653,7 @@ var defaultBaseAutosuggestionsConfig = {
654
653
  disableWhenEmpty: true,
655
654
  disabled: false,
656
655
  temporarilyDisableWhenMovingCursorWithoutChangingText: true,
656
+ temporarilyDisableNotTrustedEvents: true,
657
657
  shouldToggleHoveringEditorOnKeyPress: defaultShouldToggleHoveringEditorOnKeyPress,
658
658
  shouldAcceptAutosuggestionOnKeyPress: defaultShouldAcceptAutosuggestionOnKeyPress,
659
659
  shouldAcceptAutosuggestionOnTouch: defaultShouldAcceptAutosuggestionOnTouch
@@ -664,10 +664,123 @@ var import_react9 = require("react");
664
664
  var import_slate7 = require("slate");
665
665
  var import_slate_react3 = require("slate-react");
666
666
 
667
- // src/hooks/misc/use-autosize-textarea.tsx
667
+ // src/components/hovering-toolbar/hovering-editor-provider.tsx
668
668
  var import_react4 = require("react");
669
+ var import_jsx_runtime = require("react/jsx-runtime");
670
+ var HoveringEditorContext = (0, import_react4.createContext)({
671
+ isDisplayed: false,
672
+ setIsDisplayed: () => {
673
+ }
674
+ });
675
+ var HoveringEditorProvider = ({ children }) => {
676
+ const [isDisplayed, setIsDisplayed] = (0, import_react4.useState)(false);
677
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
678
+ };
679
+ var useHoveringEditorContext = () => (0, import_react4.useContext)(HoveringEditorContext);
680
+
681
+ // src/components/hovering-toolbar/hovering-toolbar-components.tsx
682
+ var import_css = require("@emotion/css");
683
+ var import_react5 = __toESM(require("react"));
684
+ var import_react_dom = __toESM(require("react-dom"));
685
+ var import_jsx_runtime2 = require("react/jsx-runtime");
686
+ var Button = import_react5.default.forwardRef(
687
+ (_a, ref) => {
688
+ var _b = _a, {
689
+ className,
690
+ active,
691
+ reversed
692
+ } = _b, props = __objRest(_b, [
693
+ "className",
694
+ "active",
695
+ "reversed"
696
+ ]);
697
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
698
+ "span",
699
+ __spreadProps(__spreadValues({}, props), {
700
+ ref,
701
+ className: (0, import_css.cx)(
702
+ className,
703
+ import_css.css`
704
+ cursor: pointer;
705
+ color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
706
+ `
707
+ )
708
+ })
709
+ );
710
+ }
711
+ );
712
+ var Icon = import_react5.default.forwardRef(
713
+ (_a, ref) => {
714
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
715
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
716
+ "span",
717
+ __spreadProps(__spreadValues({}, props), {
718
+ ref,
719
+ className: (0, import_css.cx)(
720
+ "material-icons",
721
+ className,
722
+ import_css.css`
723
+ font-size: 18px;
724
+ vertical-align: text-bottom;
725
+ `
726
+ )
727
+ })
728
+ );
729
+ }
730
+ );
731
+ var Menu = import_react5.default.forwardRef(
732
+ (_a, ref) => {
733
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
734
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
735
+ "div",
736
+ __spreadProps(__spreadValues({}, props), {
737
+ "data-testid": "menu",
738
+ ref,
739
+ className: (0, import_css.cx)(
740
+ className,
741
+ import_css.css`
742
+ & > * {
743
+ display: inline-block;
744
+ }
745
+
746
+ & > * + * {
747
+ margin-left: 15px;
748
+ }
749
+ `
750
+ )
751
+ })
752
+ );
753
+ }
754
+ );
755
+ var Portal = ({ children }) => {
756
+ return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
757
+ };
758
+ var Toolbar = import_react5.default.forwardRef(
759
+ (_a, ref) => {
760
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
761
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
762
+ Menu,
763
+ __spreadProps(__spreadValues({}, props), {
764
+ ref,
765
+ className: (0, import_css.cx)(
766
+ className,
767
+ import_css.css`
768
+ position: relative;
769
+ padding: 1px 18px 17px;
770
+ margin: 0 -20px;
771
+ border-bottom: 2px solid #eee;
772
+ margin-bottom: 20px;
773
+ `
774
+ )
775
+ })
776
+ );
777
+ }
778
+ );
779
+
780
+ // src/hooks/misc/use-autosize-textarea.tsx
781
+ var import_react6 = require("react");
669
782
  var useAutosizeTextArea = (textAreaRef, value) => {
670
- (0, import_react4.useEffect)(() => {
783
+ (0, import_react6.useEffect)(() => {
671
784
  if (textAreaRef.current !== null) {
672
785
  textAreaRef.current.style.height = "0px";
673
786
  const scrollHeight = textAreaRef.current.scrollHeight;
@@ -678,15 +791,15 @@ var useAutosizeTextArea = (textAreaRef, value) => {
678
791
  var use_autosize_textarea_default = useAutosizeTextArea;
679
792
 
680
793
  // src/components/source-search-box/source-search-box.tsx
681
- var import_react5 = require("react");
794
+ var import_react7 = require("react");
682
795
 
683
796
  // src/components/ui/command.tsx
684
- var React2 = __toESM(require("react"));
797
+ var React3 = __toESM(require("react"));
685
798
  var import_cmdk = require("cmdk");
686
- var import_jsx_runtime = require("react/jsx-runtime");
687
- var Command = React2.forwardRef((_a, ref) => {
799
+ var import_jsx_runtime3 = require("react/jsx-runtime");
800
+ var Command = React3.forwardRef((_a, ref) => {
688
801
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
689
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
802
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
690
803
  import_cmdk.Command,
691
804
  __spreadValues({
692
805
  ref,
@@ -698,9 +811,9 @@ var Command = React2.forwardRef((_a, ref) => {
698
811
  );
699
812
  });
700
813
  Command.displayName = import_cmdk.Command.displayName;
701
- var CommandInput = React2.forwardRef((_a, ref) => {
814
+ var CommandInput = React3.forwardRef((_a, ref) => {
702
815
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
703
- 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)(
816
+ 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)(
704
817
  import_cmdk.Command.Input,
705
818
  __spreadValues({
706
819
  ref,
@@ -712,9 +825,9 @@ var CommandInput = React2.forwardRef((_a, ref) => {
712
825
  ) });
713
826
  });
714
827
  CommandInput.displayName = import_cmdk.Command.Input.displayName;
715
- var CommandList = React2.forwardRef((_a, ref) => {
828
+ var CommandList = React3.forwardRef((_a, ref) => {
716
829
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
717
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
830
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
718
831
  import_cmdk.Command.List,
719
832
  __spreadValues({
720
833
  ref,
@@ -723,11 +836,11 @@ var CommandList = React2.forwardRef((_a, ref) => {
723
836
  );
724
837
  });
725
838
  CommandList.displayName = import_cmdk.Command.List.displayName;
726
- var CommandEmpty = React2.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
839
+ var CommandEmpty = React3.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_cmdk.Command.Empty, __spreadValues({ ref, className: "py-6 text-center text-sm" }, props)));
727
840
  CommandEmpty.displayName = import_cmdk.Command.Empty.displayName;
728
- var CommandGroup = React2.forwardRef((_a, ref) => {
841
+ var CommandGroup = React3.forwardRef((_a, ref) => {
729
842
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
730
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
843
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
731
844
  import_cmdk.Command.Group,
732
845
  __spreadValues({
733
846
  ref,
@@ -739,9 +852,9 @@ var CommandGroup = React2.forwardRef((_a, ref) => {
739
852
  );
740
853
  });
741
854
  CommandGroup.displayName = import_cmdk.Command.Group.displayName;
742
- var CommandSeparator = React2.forwardRef((_a, ref) => {
855
+ var CommandSeparator = React3.forwardRef((_a, ref) => {
743
856
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
744
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
857
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
745
858
  import_cmdk.Command.Separator,
746
859
  __spreadValues({
747
860
  ref,
@@ -750,9 +863,9 @@ var CommandSeparator = React2.forwardRef((_a, ref) => {
750
863
  );
751
864
  });
752
865
  CommandSeparator.displayName = import_cmdk.Command.Separator.displayName;
753
- var CommandItem = React2.forwardRef((_a, ref) => {
866
+ var CommandItem = React3.forwardRef((_a, ref) => {
754
867
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
755
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
868
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
756
869
  import_cmdk.Command.Item,
757
870
  __spreadValues({
758
871
  ref,
@@ -766,7 +879,7 @@ var CommandItem = React2.forwardRef((_a, ref) => {
766
879
  CommandItem.displayName = import_cmdk.Command.Item.displayName;
767
880
  var CommandShortcut = (_a) => {
768
881
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
769
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
882
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
770
883
  "span",
771
884
  __spreadValues({
772
885
  className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className)
@@ -776,10 +889,10 @@ var CommandShortcut = (_a) => {
776
889
  CommandShortcut.displayName = "CommandShortcut";
777
890
 
778
891
  // src/components/source-search-box/source-search-box.tsx
779
- var import_jsx_runtime2 = require("react/jsx-runtime");
892
+ var import_jsx_runtime4 = require("react/jsx-runtime");
780
893
  function SourceSearchBox(props) {
781
- const [selectedValue, setSelectedValue] = (0, import_react5.useState)("");
782
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
894
+ const [selectedValue, setSelectedValue] = (0, import_react7.useState)("");
895
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
783
896
  Command,
784
897
  {
785
898
  className: "rounded-lg border shadow-md",
@@ -795,7 +908,7 @@ function SourceSearchBox(props) {
795
908
  return 0;
796
909
  },
797
910
  children: [
798
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
911
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
799
912
  CommandInput,
800
913
  {
801
914
  value: props.searchTerm,
@@ -803,18 +916,18 @@ function SourceSearchBox(props) {
803
916
  placeholder: "Search for a command..."
804
917
  }
805
918
  ),
806
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(CommandList, { children: [
807
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandEmpty, { children: "No results found." }),
808
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
809
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
919
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(CommandList, { children: [
920
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommandEmpty, { children: "No results found." }),
921
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommandGroup, { heading: "Available resources", children: props.suggestedFiles.map((filePointer) => {
922
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
810
923
  CommandItem,
811
924
  {
812
925
  value: filePointer.name,
813
926
  onSelect: (value) => {
814
927
  props.onSelectedFile(filePointer);
815
928
  },
816
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
817
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
929
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: " px-3 flex flex-row gap-1 items-center", children: [
930
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Logo, { width: "20px", height: "20px", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
818
931
  "img",
819
932
  {
820
933
  src: filePointer.iconImageUri,
@@ -828,7 +941,7 @@ function SourceSearchBox(props) {
828
941
  `word-${filePointer.sourceApplication}.${filePointer.name}`
829
942
  );
830
943
  }) }),
831
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CommandSeparator, {})
944
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CommandSeparator, {})
832
945
  ] })
833
946
  ]
834
947
  }
@@ -839,17 +952,17 @@ function Logo({
839
952
  width,
840
953
  height
841
954
  }) {
842
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex items-center justify-center", style: { width, height }, children });
955
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex items-center justify-center", style: { width, height }, children });
843
956
  }
844
957
 
845
958
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
846
959
  var import_react_core2 = require("@copilotkit/react-core");
847
960
 
848
961
  // src/components/ui/button.tsx
849
- var React3 = __toESM(require("react"));
962
+ var React4 = __toESM(require("react"));
850
963
  var import_react_slot = require("@radix-ui/react-slot");
851
964
  var import_class_variance_authority = require("class-variance-authority");
852
- var import_jsx_runtime3 = require("react/jsx-runtime");
965
+ var import_jsx_runtime5 = require("react/jsx-runtime");
853
966
  var buttonVariants = (0, import_class_variance_authority.cva)(
854
967
  "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",
855
968
  {
@@ -875,31 +988,31 @@ var buttonVariants = (0, import_class_variance_authority.cva)(
875
988
  }
876
989
  }
877
990
  );
878
- var Button = React3.forwardRef(
991
+ var Button2 = React4.forwardRef(
879
992
  (_a, ref) => {
880
993
  var _b = _a, { className, variant, size, asChild = false } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild"]);
881
994
  const Comp = asChild ? import_react_slot.Slot : "button";
882
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
995
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Comp, __spreadValues({ className: cn(buttonVariants({ variant, size, className })), ref }, props));
883
996
  }
884
997
  );
885
- Button.displayName = "Button";
998
+ Button2.displayName = "Button";
886
999
 
887
1000
  // src/components/ui/label.tsx
888
- var React4 = __toESM(require("react"));
1001
+ var React5 = __toESM(require("react"));
889
1002
  var LabelPrimitive = __toESM(require("@radix-ui/react-label"));
890
1003
  var import_class_variance_authority2 = require("class-variance-authority");
891
- var import_jsx_runtime4 = require("react/jsx-runtime");
1004
+ var import_jsx_runtime6 = require("react/jsx-runtime");
892
1005
  var labelVariants = (0, import_class_variance_authority2.cva)(
893
1006
  "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
894
1007
  );
895
- var Label = React4.forwardRef((_a, ref) => {
1008
+ var Label = React5.forwardRef((_a, ref) => {
896
1009
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
897
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
1010
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LabelPrimitive.Root, __spreadValues({ ref, className: cn(labelVariants(), className) }, props));
898
1011
  });
899
1012
  Label.displayName = LabelPrimitive.Root.displayName;
900
1013
 
901
1014
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
902
- var import_react7 = require("react");
1015
+ var import_react8 = require("react");
903
1016
 
904
1017
  // src/lib/stream-promise-flatten.ts
905
1018
  function streamPromiseFlatten(promise) {
@@ -928,15 +1041,15 @@ function streamPromiseFlatten(promise) {
928
1041
  // src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx
929
1042
  var import_Chip = __toESM(require("@mui/material/Chip/Chip.js"));
930
1043
  var import_Avatar = __toESM(require("@mui/material/Avatar/Avatar.js"));
931
- var import_jsx_runtime5 = require("react/jsx-runtime");
1044
+ var import_jsx_runtime7 = require("react/jsx-runtime");
932
1045
  var IncludedFilesPreview = ({
933
1046
  includedFiles,
934
1047
  setIncludedFiles
935
1048
  }) => {
936
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-col gap-2 mt-2", children: [
937
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { className: "", children: "Included context:" }),
938
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
939
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1049
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex flex-col gap-2 mt-2", children: [
1050
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "", children: "Included context:" }),
1051
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
1052
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
940
1053
  FileChipPreview,
941
1054
  {
942
1055
  filePointer,
@@ -950,12 +1063,12 @@ var IncludedFilesPreview = ({
950
1063
  ] });
951
1064
  };
952
1065
  var FileChipPreview = ({ filePointer, onDelete }) => {
953
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1066
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
954
1067
  import_Chip.default,
955
1068
  {
956
1069
  label: filePointer.name,
957
1070
  onDelete,
958
- avatar: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1071
+ avatar: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
959
1072
  import_Avatar.default,
960
1073
  {
961
1074
  src: filePointer.iconImageUri,
@@ -967,22 +1080,8 @@ var FileChipPreview = ({ filePointer, onDelete }) => {
967
1080
  );
968
1081
  };
969
1082
 
970
- // src/components/hovering-toolbar/hovering-editor-provider.tsx
971
- var import_react6 = require("react");
972
- var import_jsx_runtime6 = require("react/jsx-runtime");
973
- var HoveringEditorContext = (0, import_react6.createContext)({
974
- isDisplayed: false,
975
- setIsDisplayed: () => {
976
- }
977
- });
978
- var HoveringEditorProvider = ({ children }) => {
979
- const [isDisplayed, setIsDisplayed] = (0, import_react6.useState)(false);
980
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HoveringEditorContext.Provider, { value: { isDisplayed, setIsDisplayed }, children });
981
- };
982
- var useHoveringEditorContext = () => (0, import_react6.useContext)(HoveringEditorContext);
983
-
984
1083
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx
985
- var import_jsx_runtime7 = require("react/jsx-runtime");
1084
+ var import_jsx_runtime8 = require("react/jsx-runtime");
986
1085
  var HoveringInsertionPromptBoxCore = ({
987
1086
  performInsertion,
988
1087
  state,
@@ -990,26 +1089,26 @@ var HoveringInsertionPromptBoxCore = ({
990
1089
  contextCategories
991
1090
  }) => {
992
1091
  const { getDocumentsContext } = (0, import_react_core2.useCopilotContext)();
993
- const [editSuggestion, setEditSuggestion] = (0, import_react7.useState)("");
994
- const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react7.useState)(false);
995
- const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react7.useState)("");
996
- const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react7.useState)(
1092
+ const [editSuggestion, setEditSuggestion] = (0, import_react8.useState)("");
1093
+ const [suggestionIsLoading, setSuggestionIsLoading] = (0, import_react8.useState)(false);
1094
+ const [adjustmentPrompt, setAdjustmentPrompt] = (0, import_react8.useState)("");
1095
+ const [generatingSuggestion, setGeneratingSuggestion] = (0, import_react8.useState)(
997
1096
  null
998
1097
  );
999
- const adjustmentTextAreaRef = (0, import_react7.useRef)(null);
1000
- const suggestionTextAreaRef = (0, import_react7.useRef)(null);
1001
- const [filePointers, setFilePointers] = (0, import_react7.useState)([]);
1002
- const [suggestedFiles, setSuggestedFiles] = (0, import_react7.useState)([]);
1003
- (0, import_react7.useEffect)(() => {
1098
+ const adjustmentTextAreaRef = (0, import_react8.useRef)(null);
1099
+ const suggestionTextAreaRef = (0, import_react8.useRef)(null);
1100
+ const [filePointers, setFilePointers] = (0, import_react8.useState)([]);
1101
+ const [suggestedFiles, setSuggestedFiles] = (0, import_react8.useState)([]);
1102
+ (0, import_react8.useEffect)(() => {
1004
1103
  setSuggestedFiles(getDocumentsContext(contextCategories));
1005
1104
  }, [contextCategories, getDocumentsContext]);
1006
1105
  use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
1007
1106
  use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
1008
- (0, import_react7.useEffect)(() => {
1107
+ (0, import_react8.useEffect)(() => {
1009
1108
  var _a;
1010
1109
  (_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
1011
1110
  }, []);
1012
- (0, import_react7.useEffect)(() => {
1111
+ (0, import_react8.useEffect)(() => {
1013
1112
  if (!generatingSuggestion) {
1014
1113
  return;
1015
1114
  }
@@ -1047,7 +1146,7 @@ var HoveringInsertionPromptBoxCore = ({
1047
1146
  releaseLockIfNotClosed();
1048
1147
  };
1049
1148
  }, [generatingSuggestion]);
1050
- const beginGeneratingAdjustment = (0, import_react7.useCallback)(() => __async(void 0, null, function* () {
1149
+ const beginGeneratingAdjustment = (0, import_react8.useCallback)(() => __async(void 0, null, function* () {
1051
1150
  if (!adjustmentPrompt.trim()) {
1052
1151
  return;
1053
1152
  }
@@ -1077,10 +1176,10 @@ var HoveringInsertionPromptBoxCore = ({
1077
1176
  const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
1078
1177
  const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
1079
1178
  const { setIsDisplayed } = useHoveringEditorContext();
1080
- const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1081
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "", children: adjustmentLabel }),
1082
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative w-full flex items-center", children: [
1083
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1179
+ const AdjustmentPromptComponent = /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1180
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Label, { className: "", children: adjustmentLabel }),
1181
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "relative w-full flex items-center", children: [
1182
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1084
1183
  "textarea",
1085
1184
  {
1086
1185
  "data-testid": "adjustment-prompt",
@@ -1095,9 +1194,6 @@ var HoveringInsertionPromptBoxCore = ({
1095
1194
  } else if (e.key === "Enter") {
1096
1195
  e.preventDefault();
1097
1196
  beginGeneratingAdjustment();
1098
- } else if (e.key == "Escape") {
1099
- e.preventDefault();
1100
- setIsDisplayed(false);
1101
1197
  }
1102
1198
  },
1103
1199
  placeholder,
@@ -1106,30 +1202,30 @@ var HoveringInsertionPromptBoxCore = ({
1106
1202
  rows: 1
1107
1203
  }
1108
1204
  ),
1109
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1205
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1110
1206
  "button",
1111
1207
  {
1112
1208
  onClick: beginGeneratingAdjustment,
1113
1209
  className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
1114
1210
  "data-testid": "generate-button",
1115
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "arrow_forward" })
1211
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("i", { className: "material-icons", children: "arrow_forward" })
1116
1212
  }
1117
1213
  )
1118
1214
  ] })
1119
1215
  ] });
1120
- const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1121
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-between items-end w-full", children: [
1122
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Label, { className: "mt-4", children: "Suggested:" }),
1123
- /* @__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)(
1216
+ const SuggestionComponent = /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1217
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex justify-between items-end w-full", children: [
1218
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Label, { className: "mt-4", children: "Suggested:" }),
1219
+ /* @__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)(
1124
1220
  "div",
1125
1221
  {
1126
1222
  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]",
1127
1223
  role: "status",
1128
- 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..." })
1224
+ 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..." })
1129
1225
  }
1130
1226
  ) }) })
1131
1227
  ] }),
1132
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1228
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1133
1229
  "textarea",
1134
1230
  {
1135
1231
  "data-testid": "suggestion-result",
@@ -1142,8 +1238,8 @@ var HoveringInsertionPromptBoxCore = ({
1142
1238
  }
1143
1239
  )
1144
1240
  ] });
1145
- const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1146
- Button,
1241
+ const SubmitComponent = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1242
+ Button2,
1147
1243
  {
1148
1244
  "data-testid": "insert-button",
1149
1245
  className: " bg-green-700 text-white",
@@ -1152,16 +1248,16 @@ var HoveringInsertionPromptBoxCore = ({
1152
1248
  },
1153
1249
  children: [
1154
1250
  "Insert ",
1155
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("i", { className: "material-icons", children: "check" })
1251
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("i", { className: "material-icons", children: "check" })
1156
1252
  ]
1157
1253
  }
1158
1254
  ) });
1159
1255
  const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
1160
1256
  const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
1161
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
1257
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
1162
1258
  AdjustmentPromptComponent,
1163
- filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
1164
- sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1259
+ filePointers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
1260
+ sourceSearchWord !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1165
1261
  SourceSearchBox,
1166
1262
  {
1167
1263
  searchTerm: sourceSearchWord,
@@ -1180,14 +1276,14 @@ var HoveringInsertionPromptBoxCore = ({
1180
1276
  };
1181
1277
 
1182
1278
  // src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx
1183
- var import_jsx_runtime8 = require("react/jsx-runtime");
1279
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1184
1280
  var HoveringInsertionPromptBox = (props) => {
1185
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1281
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1186
1282
  "div",
1187
1283
  {
1188
1284
  className: "flex flex-col justify-center items-center space-y-4 rounded-md border shadow-lg p-4 border-gray- bg-white",
1189
1285
  style: { width: "35rem" },
1190
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1286
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1191
1287
  HoveringInsertionPromptBoxCore,
1192
1288
  {
1193
1289
  state: {
@@ -1202,105 +1298,6 @@ var HoveringInsertionPromptBox = (props) => {
1202
1298
  );
1203
1299
  };
1204
1300
 
1205
- // src/components/hovering-toolbar/hovering-toolbar-components.tsx
1206
- var import_css = require("@emotion/css");
1207
- var import_react8 = __toESM(require("react"));
1208
- var import_react_dom = __toESM(require("react-dom"));
1209
- var import_jsx_runtime9 = require("react/jsx-runtime");
1210
- var Button2 = import_react8.default.forwardRef(
1211
- (_a, ref) => {
1212
- var _b = _a, {
1213
- className,
1214
- active,
1215
- reversed
1216
- } = _b, props = __objRest(_b, [
1217
- "className",
1218
- "active",
1219
- "reversed"
1220
- ]);
1221
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1222
- "span",
1223
- __spreadProps(__spreadValues({}, props), {
1224
- ref,
1225
- className: (0, import_css.cx)(
1226
- className,
1227
- import_css.css`
1228
- cursor: pointer;
1229
- color: ${reversed ? active ? "white" : "#aaa" : active ? "black" : "#ccc"};
1230
- `
1231
- )
1232
- })
1233
- );
1234
- }
1235
- );
1236
- var Icon = import_react8.default.forwardRef(
1237
- (_a, ref) => {
1238
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1239
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1240
- "span",
1241
- __spreadProps(__spreadValues({}, props), {
1242
- ref,
1243
- className: (0, import_css.cx)(
1244
- "material-icons",
1245
- className,
1246
- import_css.css`
1247
- font-size: 18px;
1248
- vertical-align: text-bottom;
1249
- `
1250
- )
1251
- })
1252
- );
1253
- }
1254
- );
1255
- var Menu = import_react8.default.forwardRef(
1256
- (_a, ref) => {
1257
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1258
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1259
- "div",
1260
- __spreadProps(__spreadValues({}, props), {
1261
- "data-testid": "menu",
1262
- ref,
1263
- className: (0, import_css.cx)(
1264
- className,
1265
- import_css.css`
1266
- & > * {
1267
- display: inline-block;
1268
- }
1269
-
1270
- & > * + * {
1271
- margin-left: 15px;
1272
- }
1273
- `
1274
- )
1275
- })
1276
- );
1277
- }
1278
- );
1279
- var Portal = ({ children }) => {
1280
- return typeof document === "object" ? import_react_dom.default.createPortal(children, document.body) : null;
1281
- };
1282
- var Toolbar = import_react8.default.forwardRef(
1283
- (_a, ref) => {
1284
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
1285
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1286
- Menu,
1287
- __spreadProps(__spreadValues({}, props), {
1288
- ref,
1289
- className: (0, import_css.cx)(
1290
- className,
1291
- import_css.css`
1292
- position: relative;
1293
- padding: 1px 18px 17px;
1294
- margin: 0 -20px;
1295
- border-bottom: 2px solid #eee;
1296
- margin-bottom: 20px;
1297
- `
1298
- )
1299
- })
1300
- );
1301
- }
1302
- );
1303
-
1304
1301
  // src/components/hovering-toolbar/hovering-toolbar.tsx
1305
1302
  var import_jsx_runtime10 = require("react/jsx-runtime");
1306
1303
  var HoveringToolbar = (props) => {
@@ -1312,10 +1309,11 @@ var HoveringToolbar = (props) => {
1312
1309
  (0, import_react9.useEffect)(() => {
1313
1310
  setIsClient(true);
1314
1311
  }, []);
1315
- (0, import_react9.useEffect)(() => {
1312
+ const isShown = isClient && isDisplayed && selection;
1313
+ (0, import_react9.useLayoutEffect)(() => {
1316
1314
  const el = ref.current;
1317
1315
  const { selection: selection2 } = editor;
1318
- if (!el) {
1316
+ if (!el || !isShown) {
1319
1317
  return;
1320
1318
  }
1321
1319
  if (!selection2) {
@@ -1331,26 +1329,23 @@ var HoveringToolbar = (props) => {
1331
1329
  if (rect.top === 0 && rect.left === 0 && rect.width === 0 && rect.height === 0) {
1332
1330
  return;
1333
1331
  }
1334
- const minGapFromEdge = 60;
1335
- const verticalOffsetFromCorner = 35;
1336
- const horizontalOffsetFromCorner = 15;
1337
- let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner;
1338
- if (top < minGapFromEdge) {
1339
- top = rect.bottom + window.scrollY + minGapFromEdge;
1340
- } else if (top + el.offsetHeight > window.innerHeight - minGapFromEdge) {
1341
- top = rect.top + window.scrollY - el.offsetHeight - minGapFromEdge;
1332
+ const verticalOffsetFromCorner = 0;
1333
+ const horizontalOffsetFromCorner = 0;
1334
+ let top = rect.bottom + window.scrollY + verticalOffsetFromCorner;
1335
+ if (rect.bottom + el.offsetHeight > window.innerHeight - verticalOffsetFromCorner) {
1336
+ top = rect.top + window.scrollY - el.offsetHeight - verticalOffsetFromCorner;
1342
1337
  }
1343
1338
  let left = rect.left + window.scrollX - el.offsetWidth / 2 + rect.width / 2 + horizontalOffsetFromCorner;
1344
- if (left < minGapFromEdge) {
1345
- left = minGapFromEdge;
1346
- } else if (left + el.offsetWidth > window.innerWidth - minGapFromEdge) {
1347
- left = window.innerWidth - el.offsetWidth - minGapFromEdge;
1339
+ if (left < horizontalOffsetFromCorner) {
1340
+ left = horizontalOffsetFromCorner;
1341
+ } else if (left + el.offsetWidth > window.innerWidth - horizontalOffsetFromCorner) {
1342
+ left = window.innerWidth - el.offsetWidth - horizontalOffsetFromCorner;
1348
1343
  }
1349
1344
  el.style.opacity = "1";
1350
1345
  el.style.position = "absolute";
1351
1346
  el.style.top = `${top}px`;
1352
1347
  el.style.left = `${left}px`;
1353
- });
1348
+ }, [isShown]);
1354
1349
  (0, import_react9.useEffect)(() => {
1355
1350
  const handleClickOutside = (event) => {
1356
1351
  if (ref.current && !ref.current.contains(event.target)) {
@@ -1362,7 +1357,7 @@ var HoveringToolbar = (props) => {
1362
1357
  document.removeEventListener("mousedown", handleClickOutside);
1363
1358
  };
1364
1359
  }, [ref, setIsDisplayed]);
1365
- if (!isClient) {
1360
+ if (!isShown) {
1366
1361
  return null;
1367
1362
  }
1368
1363
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
@@ -1371,14 +1366,11 @@ var HoveringToolbar = (props) => {
1371
1366
  ref,
1372
1367
  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"),
1373
1368
  "data-testid": "hovering-toolbar",
1374
- children: isDisplayed && selection && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1369
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1375
1370
  HoveringInsertionPromptBox,
1376
1371
  {
1377
1372
  editorState: editorState(editor, selection),
1378
1373
  apiConfig: props.apiConfig,
1379
- closeWindow: () => {
1380
- setIsDisplayed(false);
1381
- },
1382
1374
  performInsertion: (insertedText) => {
1383
1375
  import_slate7.Transforms.delete(editor, { at: selection });
1384
1376
  import_slate7.Transforms.insertText(editor, insertedText, {
@@ -1604,6 +1596,7 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1604
1596
  }, []);
1605
1597
  const [lastKnownFullEditorText, setLastKnownFullEditorText] = (0, import_react12.useState)(valueOnInitialRender);
1606
1598
  const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = (0, import_react12.useState)(false);
1599
+ const [isUserInputActive, setIsUserInputActive] = (0, import_react12.useState)(false);
1607
1600
  const initialValue = (0, import_react12.useMemo)(() => {
1608
1601
  return [
1609
1602
  {
@@ -1626,7 +1619,8 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1626
1619
  // textarea is manually disabled:
1627
1620
  autosuggestionsConfig.disabled || // hovering editor is displayed:
1628
1621
  hoveringEditorIsDisplayed || // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:
1629
- cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText
1622
+ cursorMovedSinceLastTextChange && autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText || // not user input and we want to disable non-trusted events (like text insertion from autocomplete plugins):
1623
+ !isUserInputActive && autosuggestionsConfig.temporarilyDisableNotTrustedEvents
1630
1624
  );
1631
1625
  const {
1632
1626
  currentAutocompleteSuggestion,
@@ -1761,6 +1755,7 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1761
1755
  renderPlaceholder: renderPlaceholderMemoized,
1762
1756
  onKeyDown: (event) => {
1763
1757
  var _a2;
1758
+ setIsUserInputActive(true);
1764
1759
  onKeyDownHandlerForHoveringEditor(event);
1765
1760
  onKeyDownHandlerForAutocomplete(event);
1766
1761
  (_a2 = props.onKeyDown) == null ? void 0 : _a2.call(props, event);
@@ -1774,6 +1769,7 @@ var BaseCopilotTextareaWithHoveringContext = import_react12.default.forwardRef(
1774
1769
  var _a2;
1775
1770
  (_a2 = props.onBlur) == null ? void 0 : _a2.call(props, ev);
1776
1771
  clearAutocompletionsFromEditor(editor);
1772
+ setIsUserInputActive(false);
1777
1773
  }
1778
1774
  }, propsToForward)
1779
1775
  )
@@ -1799,7 +1795,7 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
1799
1795
  var import_react15 = __toESM(require("react"));
1800
1796
 
1801
1797
  // src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx
1802
- var import_shared = require("@copilotkit/shared");
1798
+ var import_shared2 = require("@copilotkit/shared");
1803
1799
  var import_react_core3 = require("@copilotkit/react-core");
1804
1800
  var import_react13 = require("react");
1805
1801
 
@@ -1823,7 +1819,7 @@ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1823
1819
  function useMakeStandardAutosuggestionFunction(textareaPurpose, contextCategories, apiConfig) {
1824
1820
  const { getContextString, copilotApiConfig, runtimeClient } = (0, import_react_core3.useCopilotContext)();
1825
1821
  const { chatApiEndpoint: url, publicApiKey, credentials, properties } = copilotApiConfig;
1826
- const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1822
+ const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1827
1823
  const { maxTokens, stop, temperature = 0 } = apiConfig;
1828
1824
  return (0, import_react13.useCallback)(
1829
1825
  (editorState2, abortSignal) => __async(this, null, function* () {
@@ -2104,13 +2100,13 @@ var defaultAutosuggestionsConfig = __spreadProps(__spreadValues({}, defaultBaseA
2104
2100
  });
2105
2101
 
2106
2102
  // src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx
2107
- var import_shared2 = require("@copilotkit/shared");
2103
+ var import_shared3 = require("@copilotkit/shared");
2108
2104
  var import_react_core5 = require("@copilotkit/react-core");
2109
2105
  var import_react14 = require("react");
2110
2106
  var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
2111
2107
  function useMakeStandardInsertionOrEditingFunction(textareaPurpose, contextCategories, insertionApiConfig, editingApiConfig) {
2112
2108
  const { getContextString, copilotApiConfig, runtimeClient } = (0, import_react_core5.useCopilotContext)();
2113
- const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
2109
+ const headers = __spreadValues({}, copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
2114
2110
  function runtimeClientResponseToStringStream(responsePromise) {
2115
2111
  return __async(this, null, function* () {
2116
2112
  const messagesStream = runtimeClient.asStream(responsePromise);