@copilotkit/react-ui 1.4.0-pre-1-4-0-alpha.10 → 1.4.0-pre-1-4-0.14

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 (39) hide show
  1. package/CHANGELOG.md +190 -26
  2. package/dist/{chunk-QK6XA3PL.mjs → chunk-H5CXJBR5.mjs} +3 -3
  3. package/dist/{chunk-TEZWY2BL.mjs → chunk-M2NVAJQA.mjs} +2 -2
  4. package/dist/{chunk-C5KOJ3IH.mjs → chunk-ORHE7FYT.mjs} +2 -2
  5. package/dist/{chunk-OJ5NVSTU.mjs → chunk-PY7YBFPA.mjs} +2 -2
  6. package/dist/{chunk-CPMIEVKK.mjs → chunk-RKPANT3F.mjs} +65 -15
  7. package/dist/chunk-RKPANT3F.mjs.map +1 -0
  8. package/dist/components/chat/Chat.js +62 -13
  9. package/dist/components/chat/Chat.js.map +1 -1
  10. package/dist/components/chat/Chat.mjs +2 -2
  11. package/dist/components/chat/Messages.d.ts +6 -1
  12. package/dist/components/chat/Messages.js +66 -15
  13. package/dist/components/chat/Messages.js.map +1 -1
  14. package/dist/components/chat/Messages.mjs +5 -3
  15. package/dist/components/chat/Modal.js +62 -13
  16. package/dist/components/chat/Modal.js.map +1 -1
  17. package/dist/components/chat/Modal.mjs +3 -3
  18. package/dist/components/chat/Popup.js +62 -13
  19. package/dist/components/chat/Popup.js.map +1 -1
  20. package/dist/components/chat/Popup.mjs +4 -4
  21. package/dist/components/chat/Sidebar.js +62 -13
  22. package/dist/components/chat/Sidebar.js.map +1 -1
  23. package/dist/components/chat/Sidebar.mjs +4 -4
  24. package/dist/components/chat/index.js +62 -13
  25. package/dist/components/chat/index.js.map +1 -1
  26. package/dist/components/chat/index.mjs +5 -5
  27. package/dist/components/index.js +62 -13
  28. package/dist/components/index.js.map +1 -1
  29. package/dist/components/index.mjs +5 -5
  30. package/dist/index.js +62 -13
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +5 -5
  33. package/package.json +7 -7
  34. package/src/components/chat/Messages.tsx +72 -15
  35. package/dist/chunk-CPMIEVKK.mjs.map +0 -1
  36. /package/dist/{chunk-QK6XA3PL.mjs.map → chunk-H5CXJBR5.mjs.map} +0 -0
  37. /package/dist/{chunk-TEZWY2BL.mjs.map → chunk-M2NVAJQA.mjs.map} +0 -0
  38. /package/dist/{chunk-C5KOJ3IH.mjs.map → chunk-ORHE7FYT.mjs.map} +0 -0
  39. /package/dist/{chunk-OJ5NVSTU.mjs.map → chunk-PY7YBFPA.mjs.map} +0 -0
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  CopilotPopup
3
- } from "../../chunk-OJ5NVSTU.mjs";
4
- import "../../chunk-QK6XA3PL.mjs";
3
+ } from "../../chunk-PY7YBFPA.mjs";
4
+ import "../../chunk-H5CXJBR5.mjs";
5
5
  import "../../chunk-YAGE7RCE.mjs";
6
6
  import "../../chunk-VEC45H6Q.mjs";
7
7
  import "../../chunk-RQNJNK2W.mjs";
8
- import "../../chunk-C5KOJ3IH.mjs";
8
+ import "../../chunk-ORHE7FYT.mjs";
9
9
  import "../../chunk-V7W6IM2V.mjs";
10
10
  import "../../chunk-OMTPWC7T.mjs";
11
11
  import "../../chunk-ZABXREBH.mjs";
@@ -18,7 +18,7 @@ import "../../chunk-OTPAZXVR.mjs";
18
18
  import "../../chunk-4LUMV4YO.mjs";
19
19
  import "../../chunk-YQFVRDNC.mjs";
20
20
  import "../../chunk-YQ3D5IQV.mjs";
21
- import "../../chunk-CPMIEVKK.mjs";
21
+ import "../../chunk-RKPANT3F.mjs";
22
22
  import "../../chunk-3XAXY2Z3.mjs";
23
23
  import "../../chunk-CBBFRI3Q.mjs";
24
24
  import "../../chunk-UPTB2MVO.mjs";
@@ -527,7 +527,7 @@ var Header = ({}) => {
527
527
  };
528
528
 
529
529
  // src/components/chat/Messages.tsx
530
- var import_react3 = __toESM(require("react"));
530
+ var import_react3 = require("react");
531
531
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
532
532
  var import_jsx_runtime6 = require("react/jsx-runtime");
533
533
  var Messages = ({
@@ -557,18 +557,8 @@ var Messages = ({
557
557
  }
558
558
  }
559
559
  }
560
- const messagesEndRef = import_react3.default.useRef(null);
561
- const scrollToBottom = () => {
562
- if (messagesEndRef.current) {
563
- messagesEndRef.current.scrollIntoView({
564
- behavior: "auto"
565
- });
566
- }
567
- };
568
- (0, import_react3.useEffect)(() => {
569
- scrollToBottom();
570
- }, [messages]);
571
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", children: [
560
+ const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages);
561
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
572
562
  messages.map((message, index) => {
573
563
  const isCurrentMessage = index === messages.length - 1;
574
564
  if (message.isTextMessage()) {
@@ -637,6 +627,65 @@ function makeInitialMessages(initial) {
637
627
  })
638
628
  );
639
629
  }
630
+ function useScrollToBottom(messages) {
631
+ const messagesEndRef = (0, import_react3.useRef)(null);
632
+ const messagesContainerRef = (0, import_react3.useRef)(null);
633
+ const isProgrammaticScrollRef = (0, import_react3.useRef)(false);
634
+ const isUserScrollUpRef = (0, import_react3.useRef)(false);
635
+ const scrollToBottom = () => {
636
+ if (messagesEndRef.current) {
637
+ isProgrammaticScrollRef.current = true;
638
+ messagesEndRef.current.scrollIntoView({
639
+ behavior: "auto"
640
+ });
641
+ }
642
+ };
643
+ const handleScroll = () => {
644
+ if (isProgrammaticScrollRef.current) {
645
+ isProgrammaticScrollRef.current = false;
646
+ return;
647
+ }
648
+ if (messagesContainerRef.current) {
649
+ const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
650
+ isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
651
+ }
652
+ };
653
+ (0, import_react3.useEffect)(() => {
654
+ const container = messagesContainerRef.current;
655
+ if (container) {
656
+ container.addEventListener("scroll", handleScroll);
657
+ }
658
+ return () => {
659
+ if (container) {
660
+ container.removeEventListener("scroll", handleScroll);
661
+ }
662
+ };
663
+ }, []);
664
+ (0, import_react3.useEffect)(() => {
665
+ const container = messagesContainerRef.current;
666
+ if (!container) {
667
+ return;
668
+ }
669
+ const mutationObserver = new MutationObserver(() => {
670
+ if (!isUserScrollUpRef.current) {
671
+ scrollToBottom();
672
+ }
673
+ });
674
+ mutationObserver.observe(container, {
675
+ childList: true,
676
+ subtree: true,
677
+ characterData: true
678
+ });
679
+ return () => {
680
+ mutationObserver.disconnect();
681
+ };
682
+ }, []);
683
+ (0, import_react3.useEffect)(() => {
684
+ isUserScrollUpRef.current = false;
685
+ scrollToBottom();
686
+ }, [messages.filter((m) => m.isTextMessage() && m.role === import_runtime_client_gql.Role.User).length]);
687
+ return { messagesEndRef, messagesContainerRef };
688
+ }
640
689
 
641
690
  // src/components/chat/Input.tsx
642
691
  var import_react6 = require("react");