@progress/kendo-react-conversational-ui 14.4.1 → 14.5.0-develop.10

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 (35) hide show
  1. package/ai-prompt/AIPromptContent.js +1 -1
  2. package/ai-prompt/AIPromptContent.mjs +5 -5
  3. package/ai-prompt/views/AIPromptOutputView.js +1 -1
  4. package/ai-prompt/views/AIPromptOutputView.mjs +6 -6
  5. package/chat/ChatPropsAndState.d.ts +5 -3
  6. package/chat/Events.d.ts +3 -3
  7. package/chat/components/Chat.js +1 -1
  8. package/chat/components/Chat.mjs +17 -17
  9. package/chat/components/ChatMessage.js +1 -1
  10. package/chat/components/ChatMessage.mjs +56 -55
  11. package/chat/components/Header.js +1 -1
  12. package/chat/components/Header.mjs +1 -1
  13. package/chat/components/NewMessage.js +1 -1
  14. package/chat/components/NewMessage.mjs +49 -48
  15. package/chat/components/Notification.js +1 -1
  16. package/chat/components/Notification.mjs +1 -1
  17. package/chat/components/elements/FileBox.js +1 -1
  18. package/chat/components/elements/FileBox.mjs +10 -9
  19. package/chat/components/elements/PinnedMessage.js +1 -1
  20. package/chat/components/elements/PinnedMessage.mjs +14 -13
  21. package/chat/hooks/useEndlessScroll.d.ts +1 -1
  22. package/chat/hooks/useEndlessScroll.js +1 -1
  23. package/chat/hooks/useEndlessScroll.mjs +160 -160
  24. package/dist/cdn/js/kendo-react-conversational-ui.js +1 -1
  25. package/inline-ai-prompt/InlineAIPrompt.js +1 -1
  26. package/inline-ai-prompt/InlineAIPrompt.mjs +10 -10
  27. package/inline-ai-prompt/InlineAIPromptInput.js +1 -1
  28. package/inline-ai-prompt/InlineAIPromptInput.mjs +1 -1
  29. package/package-metadata.js +1 -1
  30. package/package-metadata.mjs +2 -2
  31. package/package.json +17 -12
  32. package/prompt-box/FileBox.js +1 -1
  33. package/prompt-box/FileBox.mjs +21 -20
  34. package/prompt-box/PromptBox.js +1 -1
  35. package/prompt-box/PromptBox.mjs +30 -30
@@ -6,32 +6,33 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import * as a from "react";
9
- import { classNames as h, IconWrap as u, getFileExtensionIcon as k } from "@progress/kendo-react-common";
10
- import { DropDownButton as I } from "@progress/kendo-react-buttons";
11
- import { downloadLightIcon as B, moreVerticalIcon as w } from "@progress/kendo-svg-icons";
9
+ import { classNames as I, IconWrap as u, getFileExtensionIcon as k } from "@progress/kendo-react-common";
10
+ import { DropDownButton as h } from "@progress/kendo-react-buttons";
11
+ import { downloadIcon as B, moreVerticalIcon as w } from "@progress/kendo-svg-icons";
12
12
  import { useLocalization as F } from "@progress/kendo-react-intl";
13
13
  import { fileActions as l, messages as E } from "../../../messages/index.mjs";
14
14
  import { useChatContext as C } from "../ChatContext.mjs";
15
15
  const P = (x) => {
16
- const { files: c, onFileAction: i, onDownload: r, fileActions: N } = x, { messageFilesLayout: s = "vertical" } = C(), m = F(), p = N || [{ id: "download", label: "Download", svgIcon: B }], f = (e) => {
16
+ const { files: c, onFileAction: i, onDownload: r, fileActions: z } = x, { messageFilesLayout: s = "vertical" } = C(), m = F(), p = z || [{ id: "download", label: "Download", svgIcon: B }], f = (e) => {
17
17
  if (e == null)
18
18
  return "";
19
19
  if (e === 0)
20
20
  return "0 B";
21
21
  const t = 1024, o = ["B", "KB", "MB", "GB", "TB"], n = Math.floor(Math.log(e) / Math.log(t));
22
22
  return `${parseFloat((e / Math.pow(t, n)).toFixed(2))} ${o[n]}`;
23
- }, g = (e) => "." + e.split(".").pop() || "", v = (e, t) => {
23
+ }, g = (e) => "." + e.split(".").pop() || "", N = (e, t) => {
24
24
  var o, n;
25
25
  (n = (o = e.syntheticEvent) == null ? void 0 : o.stopPropagation) == null || n.call(o), e.item.id === "download" && (r == null || r([t])), i == null || i(e.item, e, t);
26
26
  }, d = (e) => p.length > 0 && /* @__PURE__ */ a.createElement(
27
- I,
27
+ h,
28
28
  {
29
29
  fillMode: "flat",
30
+ size: "small",
30
31
  svgIcon: w,
31
32
  onClick: (t) => {
32
33
  t.syntheticEvent.stopPropagation();
33
34
  },
34
- onItemClick: (t) => v(t, e),
35
+ onItemClick: (t) => N(t, e),
35
36
  items: p.map((t) => ({
36
37
  id: t.id,
37
38
  icon: t.icon,
@@ -44,14 +45,14 @@ const P = (x) => {
44
45
  )} ${e.name}`,
45
46
  title: `${m.toLanguageString(l, E[l])} ${e.name}`
46
47
  }
47
- ), z = a.useCallback(() => h(
48
+ ), v = a.useCallback(() => I(
48
49
  {
49
50
  "k-files-wrap": s === "wrap",
50
51
  "k-files-vertical": s === "vertical"
51
52
  },
52
53
  "k-file-box-wrapper"
53
54
  ), [s]);
54
- return /* @__PURE__ */ a.createElement("ul", { className: z() }, s === "horizontal" ? /* @__PURE__ */ a.createElement("div", { className: "k-files-scroll" }, c.map((e) => /* @__PURE__ */ a.createElement("li", { key: e.name, className: "k-file-box" }, /* @__PURE__ */ a.createElement(u, { size: "xlarge", ...k(g(e.name)) }), /* @__PURE__ */ a.createElement("div", { className: "k-file-info" }, /* @__PURE__ */ a.createElement("span", { className: "k-file-name" }, e.name), /* @__PURE__ */ a.createElement("span", { className: "k-file-size" }, f(e.size))), d(e)))) : c.map((e) => /* @__PURE__ */ a.createElement("li", { key: e.name, className: "k-file-box" }, /* @__PURE__ */ a.createElement(u, { size: "xlarge", ...k(g(e.name)) }), /* @__PURE__ */ a.createElement("div", { className: "k-file-info" }, /* @__PURE__ */ a.createElement("span", { className: "k-file-name" }, e.name), /* @__PURE__ */ a.createElement("span", { className: "k-file-size" }, f(e.size))), d(e))));
55
+ return /* @__PURE__ */ a.createElement("ul", { className: v() }, s === "horizontal" ? /* @__PURE__ */ a.createElement("div", { className: "k-files-scroll" }, c.map((e) => /* @__PURE__ */ a.createElement("li", { key: e.name, className: "k-file-box" }, /* @__PURE__ */ a.createElement(u, { size: "xlarge", ...k(g(e.name)) }), /* @__PURE__ */ a.createElement("div", { className: "k-file-info" }, /* @__PURE__ */ a.createElement("span", { className: "k-file-name" }, e.name), /* @__PURE__ */ a.createElement("span", { className: "k-file-size" }, f(e.size))), d(e)))) : c.map((e) => /* @__PURE__ */ a.createElement("li", { key: e.name, className: "k-file-box" }, /* @__PURE__ */ a.createElement(u, { size: "xlarge", ...k(g(e.name)) }), /* @__PURE__ */ a.createElement("div", { className: "k-file-info" }, /* @__PURE__ */ a.createElement("span", { className: "k-file-name" }, e.name), /* @__PURE__ */ a.createElement("span", { className: "k-file-size" }, f(e.size))), d(e))));
55
56
  };
56
57
  export {
57
58
  P as default
@@ -5,4 +5,4 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- "use strict";const m=require("react"),p=require("@progress/kendo-react-common"),g=require("@progress/kendo-react-buttons"),i=require("@progress/kendo-svg-icons"),k=require("@progress/kendo-react-intl"),a=require("../../utils.js");function v(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const c=v(m),b=n=>{const{message:e,onUnpin:t,user:r,onReferencedMessageClick:s}=n,l=k.useLocalization(),u=c.useRef(null),d=r&&a.isAuthor(r,e),f=c.useCallback(o=>{o.preventDefault(),o.stopPropagation(),s==null||s(e.id)},[e.id,s]);return c.createElement("div",{ref:u,className:`k-message-reference ${d?"k-message-reference-sender":"k-message-reference-receiver"} k-message-pinned`,onClick:f},c.createElement(p.IconWrap,{icon:i.pinOutlineIcon}),c.createElement("div",{className:"k-message-reference-content"},e!=null&&e.isDeleted?r&&a.getDeletedMessageText(a.isAuthor(r,e),l):e==null?void 0:e.text),c.createElement("span",{className:"k-spacer"}),c.createElement(g.Button,{fillMode:"flat",svgIcon:i.xMarkSmOutlineIcon,onClick:o=>{o.stopPropagation(),t==null||t(e)}}))};module.exports=b;
8
+ "use strict";const p=require("react"),m=require("@progress/kendo-react-common"),g=require("@progress/kendo-react-buttons"),i=require("@progress/kendo-svg-icons"),k=require("@progress/kendo-react-intl"),a=require("../../utils.js");function v(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const c=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,c.get?c:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const r=v(p),b=n=>{const{message:e,onUnpin:t,user:c,onReferencedMessageClick:s}=n,l=k.useLocalization(),u=r.useRef(null),d=c&&a.isAuthor(c,e),f=r.useCallback(o=>{o.preventDefault(),o.stopPropagation(),s==null||s(e.id)},[e.id,s]);return r.createElement("div",{ref:u,className:`k-message-reference ${d?"k-message-reference-sender":"k-message-reference-receiver"} k-message-pinned`,onClick:f},r.createElement(m.IconWrap,{icon:i.pinIcon}),r.createElement("div",{className:"k-message-reference-content"},e!=null&&e.isDeleted?c&&a.getDeletedMessageText(a.isAuthor(c,e),l):e==null?void 0:e.text),r.createElement("span",{className:"k-spacer"}),r.createElement(g.Button,{fillMode:"flat",size:"xs",svgIcon:i.xCircleIcon,onClick:o=>{o.stopPropagation(),t==null||t(e)}}))};module.exports=b;
@@ -8,15 +8,15 @@
8
8
  import * as t from "react";
9
9
  import { IconWrap as f } from "@progress/kendo-react-common";
10
10
  import { Button as d } from "@progress/kendo-react-buttons";
11
- import { pinOutlineIcon as u, xMarkSmOutlineIcon as k } from "@progress/kendo-svg-icons";
12
- import { useLocalization as g } from "@progress/kendo-react-intl";
13
- import { isAuthor as s, getDeletedMessageText as v } from "../../utils.mjs";
14
- const C = (c) => {
15
- const { message: e, onUnpin: a, user: n, onReferencedMessageClick: r } = c, i = g(), l = t.useRef(null), m = n && s(n, e), p = t.useCallback(
16
- (o) => {
17
- o.preventDefault(), o.stopPropagation(), r == null || r(e.id);
11
+ import { pinIcon as u, xCircleIcon as g } from "@progress/kendo-svg-icons";
12
+ import { useLocalization as k } from "@progress/kendo-react-intl";
13
+ import { isAuthor as a, getDeletedMessageText as v } from "../../utils.mjs";
14
+ const P = (c) => {
15
+ const { message: e, onUnpin: o, user: r, onReferencedMessageClick: n } = c, i = k(), l = t.useRef(null), m = r && a(r, e), p = t.useCallback(
16
+ (s) => {
17
+ s.preventDefault(), s.stopPropagation(), n == null || n(e.id);
18
18
  },
19
- [e.id, r]
19
+ [e.id, n]
20
20
  );
21
21
  return /* @__PURE__ */ t.createElement(
22
22
  "div",
@@ -26,20 +26,21 @@ const C = (c) => {
26
26
  onClick: p
27
27
  },
28
28
  /* @__PURE__ */ t.createElement(f, { icon: u }),
29
- /* @__PURE__ */ t.createElement("div", { className: "k-message-reference-content" }, e != null && e.isDeleted ? n && v(s(n, e), i) : e == null ? void 0 : e.text),
29
+ /* @__PURE__ */ t.createElement("div", { className: "k-message-reference-content" }, e != null && e.isDeleted ? r && v(a(r, e), i) : e == null ? void 0 : e.text),
30
30
  /* @__PURE__ */ t.createElement("span", { className: "k-spacer" }),
31
31
  /* @__PURE__ */ t.createElement(
32
32
  d,
33
33
  {
34
34
  fillMode: "flat",
35
- svgIcon: k,
36
- onClick: (o) => {
37
- o.stopPropagation(), a == null || a(e);
35
+ size: "xs",
36
+ svgIcon: g,
37
+ onClick: (s) => {
38
+ s.stopPropagation(), o == null || o(e);
38
39
  }
39
40
  }
40
41
  )
41
42
  );
42
43
  };
43
44
  export {
44
- C as default
45
+ P as default
45
46
  };
@@ -42,7 +42,7 @@ export interface UseEndlessScrollReturn {
42
42
  * Hook that manages the endless scroll behavior for the Chat component.
43
43
  *
44
44
  * Built-in mode: messages.length === total — Chat manages rendering internally.
45
- * Remote mode: messages.length < total — Chat fires onLoadMoreMessages, consumer manages data.
45
+ * Remote mode: messages.length < total — consumer manages data.
46
46
  *
47
47
  * @hidden
48
48
  */
@@ -5,4 +5,4 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tt=require("react"),nt=require("../utils.js");function rt(y){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(y){for(const q in y)if(q!=="default"){const l=Object.getOwnPropertyDescriptor(y,q);Object.defineProperty(n,q,l.get?l:{enumerable:!0,get:()=>y[q]})}}return n.default=y,Object.freeze(n)}const r=rt(tt),ct=50,I=100,ut=({scrollMode:y,processedMessages:n,total:q,pageSize:l=ct,startIndex:G,endIndex:U,onLoadMoreMessages:T,onReferencedMessageClick:_,viewItemsWrapperRef:u,authorId:V})=>{const F=r.useRef(!1),S=y==="endless",e=q!=null?q:n.length,a=S&&n.length===e&&!F.current,f=S&&(n.length<e||F.current);f&&(F.current=!0);const[D,B]=r.useState(-1),[E,O]=r.useState(-1),X=r.useRef(D),C=r.useRef(E);X.current=D,C.current=E;const o=r.useRef(!1),Y=r.useRef(0),v=r.useRef(0),b=r.useRef(!1),L=r.useRef(e),j=r.useRef(V);j.current=V;const k=r.useRef(!1),s=r.useRef(null),$=r.useRef(!1),g=r.useRef(!1),J=r.useRef(!0),N=r.useRef(e);r.useEffect(()=>{if(a){if(F.current){(D===-1||E===-1)&&(B(0),O(n.length));return}if(D===-1||E===-1){const t=Math.max(0,n.length-l),c=n.length;B(t),O(c)}else if(E<n.length){const t=L.current;if(C.current>=t)O(n.length);else if(n.length>t&&n.slice(t).some(i=>{var x;return((x=i.author)==null?void 0:x.id)!==void 0&&String(i.author.id)===String(j.current)})){const i=Math.max(0,n.length-l);B(i),O(n.length),$.current=!0}}L.current=e}},[a,n.length,l,D,E,e]);const d=G!=null?G:0,H=U!=null?U:n.length,P=r.useCallback(()=>{const t=u.current;t&&(Y.current=t.scrollHeight,v.current=t.scrollTop)},[u]),A=r.useCallback(t=>{var h,i,x;const c=(h=u.current)==null?void 0:h.closest(".k-chat"),m=((x=(i=u.current)==null?void 0:i.querySelector(".k-message-pinned"))==null?void 0:x.offsetHeight)||0;nt.scrollToMessageById(t,c,m)},[u]);r.useLayoutEffect(()=>{if(!b.current)return;const t=u.current;if(!t){b.current=!1;return}const c=t.scrollHeight-Y.current;c>0&&(t.scrollTop=v.current+c),b.current=!1,o.current=!1}),r.useLayoutEffect(()=>{if(!$.current)return;const t=u.current;if(!t){$.current=!1;return}E>=n.length&&E>0&&($.current=!1,t.scrollTop=t.scrollHeight-t.clientHeight)});const w=r.useRef(!1);r.useLayoutEffect(()=>{if(!S||w.current)return;const t=u.current;t&&t.querySelector("[data-message-id]")&&(t.scrollTop=t.scrollHeight-t.clientHeight,w.current=!0)}),r.useEffect(()=>{if(!S)return;const t=u.current;if(!t)return;let c=t.scrollTop;const m=()=>{const{scrollTop:h,scrollHeight:i,clientHeight:x}=t,K=h<c,p=h>c;if(c=h,!o.current){if(K&&h<=I){if(a){const R=X.current;if(R>0){const Q=Math.max(0,R-l);b.current=!0,P(),B(Q)}}else if(f&&d>0){o.current=!0;const R=Math.max(0,d-l);b.current=!0,P(),T==null||T({startIndex:R,endIndex:d})}}if(p&&i-h-x<=I){if(a){const R=C.current;if(R<n.length){const Q=Math.min(n.length,R+l);g.current=!0,O(Q)}}else if(f&&H<e){o.current=!0,g.current=!0;const R=Math.min(e,H+l);T==null||T({startIndex:H,endIndex:R})}}}};return t.addEventListener("scroll",m,{passive:!0}),()=>t.removeEventListener("scroll",m)},[S,a,f,u,l,n.length,d,H,e,T]),r.useEffect(()=>{var h;const t=H>=e;if(!f){N.current=e,J.current=t;return}const c=N.current,m=J.current;if(N.current=e,J.current=t,e>c&&!m&&t){const i=n[n.length-1];j.current!==void 0&&((h=i==null?void 0:i.author)==null?void 0:h.id)!==void 0&&String(i.author.id)===String(j.current)&&(k.current=!0,g.current=!0)}},[f,e,H,n]),r.useEffect(()=>{!f||!k.current||(k.current=!1,o.current=!1,requestAnimationFrame(()=>{const t=u.current;t&&(t.scrollTop=t.scrollHeight-t.clientHeight)}))},[f,n,u]),r.useEffect(()=>{if(!f||s.current===null)return;const t=s.current,c=u.current;if(!c)return;c.querySelector(`[data-message-id="${t}"]`)&&(s.current=null,o.current=!1,requestAnimationFrame(()=>{A(t)}))},[f,n,u,A]),r.useEffect(()=>{f&&o.current&&!b.current&&(o.current=!1)},[f,d,H]);const z=r.useMemo(()=>{if(a){const t=Math.max(0,D),c=Math.min(n.length,E);if(t>=c){const m=Math.max(0,n.length-l);return n.slice(m)}return n.slice(t,c)}return n},[a,n,D,E,l]),Z=r.useMemo(()=>S?a?E>=n.length:H>=e:!0,[S,a,E,n.length,H,e]),W=r.useCallback(()=>{if(!S||Z){const t=u.current;t&&t.scrollTo({top:t.scrollHeight-t.clientHeight,behavior:"smooth"});return}if(!o.current){if(a){const t=Math.max(0,n.length-l);B(t),O(n.length),requestAnimationFrame(()=>{const c=u.current;c&&(c.scrollTop=c.scrollHeight-c.clientHeight)})}else if(f){k.current=!0,b.current=!1,o.current=!0;const t=Math.max(0,e-l);T==null||T({startIndex:t,endIndex:e})}}},[S,a,f,Z,n.length,l,e,T,u]),M=r.useCallback(t=>{if(!S)A(t);else if(a){const c=u.current;if(c==null?void 0:c.querySelector(`[data-message-id="${t}"]`))A(t);else{if(o.current)return;const h=n.findIndex(i=>i.id===t||String(i.id)===String(t));if(h>=0){const i=Math.floor(l/2),x=Math.max(0,h-i),K=Math.min(n.length,x+l);o.current=!0,B(x),O(K),requestAnimationFrame(()=>{requestAnimationFrame(()=>{A(t),o.current=!1})})}}}else if(f){const c=u.current;if(c==null?void 0:c.querySelector(`[data-message-id="${t}"]`))A(t);else{if(o.current)return;s.current=t,b.current=!1,o.current=!0}}_==null||_({id:t})},[S,a,f,u,n,l,_,A]);return{renderedMessages:z,handleScrollToBottom:W,handleReferencedMessageClick:M,isEndless:S,isOnLastBatch:Z,skipAutoScrollRef:g}};exports.useEndlessScroll=ut;
8
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tt=require("react"),nt=require("../utils.js");function rt(y){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(y){for(const q in y)if(q!=="default"){const i=Object.getOwnPropertyDescriptor(y,q);Object.defineProperty(n,q,i.get?i:{enumerable:!0,get:()=>y[q]})}}return n.default=y,Object.freeze(n)}const r=rt(tt),ct=50,L=100,ut=({scrollMode:y,processedMessages:n,total:q,pageSize:i=ct,startIndex:Z,endIndex:d,onLoadMoreMessages:u,onReferencedMessageClick:j,viewItemsWrapperRef:l,authorId:v})=>{const k=r.useRef(!1),x=y==="endless",e=q!=null?q:n.length,E=x&&n.length===e&&!k.current,h=x&&(n.length<e||k.current);h&&(k.current=!0);const[D,B]=r.useState(-1),[m,O]=r.useState(-1),K=r.useRef(D),$=r.useRef(m);K.current=D,$.current=m;const o=r.useRef(!1),P=r.useRef(0),w=r.useRef(0),b=r.useRef(!1),I=r.useRef(e),G=r.useRef(v);G.current=v;const U=r.useRef(!1),C=r.useRef(null),J=r.useRef(!1),N=r.useRef(!1),Q=r.useRef(!0),V=r.useRef(e);r.useEffect(()=>{if(E){if(k.current){(D===-1||m===-1)&&(B(0),O(n.length));return}if(D===-1||m===-1){const t=Math.max(0,n.length-i),c=n.length;B(t),O(c)}else if(m<n.length){const t=I.current;if($.current>=t)O(n.length);else if(n.length>t&&n.slice(t).some(f=>{var a;return((a=f.author)==null?void 0:a.id)!==void 0&&String(f.author.id)===String(G.current)})){const f=Math.max(0,n.length-i);B(f),O(n.length),J.current=!0}}I.current=e}},[E,n.length,i,D,m,e]);const _=Z!=null?Z:0,H=d!=null?d:n.length,g=r.useCallback(()=>{const t=l.current;t&&(P.current=t.scrollHeight,w.current=t.scrollTop)},[l]),A=r.useCallback(t=>{var S,f,a;const c=(S=l.current)==null?void 0:S.closest(".k-chat"),T=((a=(f=l.current)==null?void 0:f.querySelector(".k-message-pinned"))==null?void 0:a.offsetHeight)||0;nt.scrollToMessageById(t,c,T)},[l]);r.useLayoutEffect(()=>{if(!b.current)return;const t=l.current;if(!t){b.current=!1;return}const c=t.scrollHeight-P.current;c>0&&(t.scrollTop=w.current+c),b.current=!1,o.current=!1}),r.useLayoutEffect(()=>{if(!J.current)return;const t=l.current;if(!t){J.current=!1;return}m>=n.length&&m>0&&(J.current=!1,t.scrollTop=t.scrollHeight-t.clientHeight)});const z=r.useRef(!1);r.useLayoutEffect(()=>{if(!x||z.current)return;const t=l.current;t&&t.querySelector("[data-message-id]")&&(t.scrollTop=t.scrollHeight-t.clientHeight,z.current=!0)}),r.useEffect(()=>{if(!x)return;const t=l.current;if(!t)return;let c=t.scrollTop;const T=()=>{const{scrollTop:S,scrollHeight:f,clientHeight:a}=t,Y=S<c,M=S>c;if(c=S,!o.current){if(Y&&S<=L){if(E){const R=K.current;if(R>0){const F=Math.max(0,R-i);b.current=!0,g(),B(F),u==null||u({startIndex:F,endIndex:$.current})}}else if(h&&_>0){o.current=!0;const R=Math.max(0,_-i);b.current=!0,g(),u==null||u({startIndex:R,endIndex:H})}}if(M&&f-S-a<=L){if(E){const R=$.current;if(R<n.length){const F=Math.min(n.length,R+i);N.current=!0,O(F),u==null||u({startIndex:K.current,endIndex:F})}}else if(h&&H<e){o.current=!0,N.current=!0;const R=Math.min(e,H+i);u==null||u({startIndex:_,endIndex:R})}}}};return t.addEventListener("scroll",T,{passive:!0}),()=>t.removeEventListener("scroll",T)},[x,E,h,l,i,n.length,_,H,e,u]),r.useEffect(()=>{var S;const t=H>=e;if(!h){V.current=e,Q.current=t;return}const c=V.current,T=Q.current;if(V.current=e,Q.current=t,e>c&&!T&&t){const f=n[n.length-1];G.current!==void 0&&((S=f==null?void 0:f.author)==null?void 0:S.id)!==void 0&&String(f.author.id)===String(G.current)&&(U.current=!0,N.current=!0)}},[h,e,H,n]),r.useEffect(()=>{!h||!U.current||(U.current=!1,o.current=!1,requestAnimationFrame(()=>{const t=l.current;t&&(t.scrollTop=t.scrollHeight-t.clientHeight)}))},[h,n,l]),r.useEffect(()=>{if(!h||C.current===null)return;const t=C.current,c=l.current;if(!c)return;c.querySelector(`[data-message-id="${t}"]`)&&(C.current=null,o.current=!1,requestAnimationFrame(()=>{A(t)}))},[h,n,l,A]),r.useEffect(()=>{h&&o.current&&!b.current&&(o.current=!1)},[h,_,H]);const W=r.useMemo(()=>{if(E){const t=Math.max(0,D),c=Math.min(n.length,m);if(t>=c){const T=Math.max(0,n.length-i);return n.slice(T)}return n.slice(t,c)}return n},[E,n,D,m,i]),X=r.useMemo(()=>x?E?m>=n.length:H>=e:!0,[x,E,m,n.length,H,e]),s=r.useCallback(()=>{if(!x||X){const t=l.current;t&&t.scrollTo({top:t.scrollHeight-t.clientHeight,behavior:"smooth"});return}if(!o.current){if(E){const t=Math.max(0,n.length-i);B(t),O(n.length),u==null||u({startIndex:t,endIndex:n.length}),requestAnimationFrame(()=>{const c=l.current;c&&(c.scrollTop=c.scrollHeight-c.clientHeight)})}else if(h){U.current=!0,b.current=!1,o.current=!0;const t=Math.max(0,e-i);u==null||u({startIndex:t,endIndex:e})}}},[x,E,h,X,n.length,i,e,u,l]),p=r.useCallback(t=>{if(!x)A(t);else if(E){const c=l.current;if(c==null?void 0:c.querySelector(`[data-message-id="${t}"]`))A(t);else{if(o.current)return;const S=n.findIndex(f=>f.id===t||String(f.id)===String(t));if(S>=0){const f=Math.floor(i/2),a=Math.max(0,S-f),Y=Math.min(n.length,a+i);o.current=!0,B(a),O(Y),requestAnimationFrame(()=>{requestAnimationFrame(()=>{A(t),o.current=!1})})}}}else if(h){const c=l.current;if(c==null?void 0:c.querySelector(`[data-message-id="${t}"]`))A(t);else{if(o.current)return;C.current=t,b.current=!1,o.current=!0}}j==null||j({id:t})},[x,E,h,l,n,i,j,A]);return{renderedMessages:W,handleScrollToBottom:s,handleReferencedMessageClick:p,isEndless:x,isOnLastBatch:X,skipAutoScrollRef:N}};exports.useEndlessScroll=ut;
@@ -7,259 +7,259 @@
7
7
  */
8
8
  import * as r from "react";
9
9
  import { scrollToMessageById as tt } from "../utils.mjs";
10
- const nt = 50, s = 100, ct = ({
11
- scrollMode: I,
10
+ const nt = 50, L = 100, ct = ({
11
+ scrollMode: W,
12
12
  processedMessages: n,
13
- total: C,
14
- pageSize: i = nt,
15
- startIndex: J,
16
- endIndex: Z,
17
- onLoadMoreMessages: T,
18
- onReferencedMessageClick: b,
19
- viewItemsWrapperRef: u,
20
- authorId: Y
13
+ total: Z,
14
+ pageSize: e = nt,
15
+ startIndex: j,
16
+ endIndex: K,
17
+ onLoadMoreMessages: u,
18
+ onReferencedMessageClick: F,
19
+ viewItemsWrapperRef: l,
20
+ authorId: v
21
21
  }) => {
22
- const F = r.useRef(!1), E = I === "endless", l = C != null ? C : n.length, a = E && n.length === l && !F.current, f = E && (n.length < l || F.current);
23
- f && (F.current = !0);
24
- const [D, B] = r.useState(-1), [S, A] = r.useState(-1), d = r.useRef(D), j = r.useRef(S);
25
- d.current = D, j.current = S;
26
- const o = r.useRef(!1), L = r.useRef(0), v = r.useRef(0), q = r.useRef(!1), g = r.useRef(l), k = r.useRef(Y);
27
- k.current = Y;
28
- const _ = r.useRef(!1), $ = r.useRef(null), G = r.useRef(!1), U = r.useRef(!1), K = r.useRef(!0), N = r.useRef(l);
22
+ const k = r.useRef(!1), x = W === "endless", i = Z != null ? Z : n.length, S = x && n.length === i && !k.current, h = x && (n.length < i || k.current);
23
+ h && (k.current = !0);
24
+ const [A, a] = r.useState(-1), [m, y] = r.useState(-1), N = r.useRef(A), _ = r.useRef(m);
25
+ N.current = A, _.current = m;
26
+ const o = r.useRef(!1), P = r.useRef(0), w = r.useRef(0), D = r.useRef(!1), I = r.useRef(i), $ = r.useRef(v);
27
+ $.current = v;
28
+ const G = r.useRef(!1), U = r.useRef(null), C = r.useRef(!1), J = r.useRef(!1), Q = r.useRef(!0), V = r.useRef(i);
29
29
  r.useEffect(() => {
30
- if (a) {
31
- if (F.current) {
32
- (D === -1 || S === -1) && (B(0), A(n.length));
30
+ if (S) {
31
+ if (k.current) {
32
+ (A === -1 || m === -1) && (a(0), y(n.length));
33
33
  return;
34
34
  }
35
- if (D === -1 || S === -1) {
36
- const t = Math.max(0, n.length - i), c = n.length;
37
- B(t), A(c);
38
- } else if (S < n.length) {
39
- const t = g.current;
40
- if (j.current >= t)
41
- A(n.length);
35
+ if (A === -1 || m === -1) {
36
+ const t = Math.max(0, n.length - e), c = n.length;
37
+ a(t), y(c);
38
+ } else if (m < n.length) {
39
+ const t = I.current;
40
+ if (_.current >= t)
41
+ y(n.length);
42
42
  else if (n.length > t && n.slice(t).some(
43
- (e) => {
44
- var x;
45
- return ((x = e.author) == null ? void 0 : x.id) !== void 0 && String(e.author.id) === String(k.current);
43
+ (f) => {
44
+ var H;
45
+ return ((H = f.author) == null ? void 0 : H.id) !== void 0 && String(f.author.id) === String($.current);
46
46
  }
47
47
  )) {
48
- const e = Math.max(0, n.length - i);
49
- B(e), A(n.length), G.current = !0;
48
+ const f = Math.max(0, n.length - e);
49
+ a(f), y(n.length), C.current = !0;
50
50
  }
51
51
  }
52
- g.current = l;
52
+ I.current = i;
53
53
  }
54
- }, [a, n.length, i, D, S, l]);
55
- const O = J != null ? J : 0, H = Z != null ? Z : n.length, P = r.useCallback(() => {
56
- const t = u.current;
57
- t && (L.current = t.scrollHeight, v.current = t.scrollTop);
58
- }, [u]), y = r.useCallback(
54
+ }, [S, n.length, e, A, m, i]);
55
+ const O = j != null ? j : 0, R = K != null ? K : n.length, d = r.useCallback(() => {
56
+ const t = l.current;
57
+ t && (P.current = t.scrollHeight, w.current = t.scrollTop);
58
+ }, [l]), B = r.useCallback(
59
59
  (t) => {
60
- var h, e, x;
61
- const c = (h = u.current) == null ? void 0 : h.closest(".k-chat"), m = ((x = (e = u.current) == null ? void 0 : e.querySelector(".k-message-pinned")) == null ? void 0 : x.offsetHeight) || 0;
62
- tt(t, c, m);
60
+ var E, f, H;
61
+ const c = (E = l.current) == null ? void 0 : E.closest(".k-chat"), T = ((H = (f = l.current) == null ? void 0 : f.querySelector(".k-message-pinned")) == null ? void 0 : H.offsetHeight) || 0;
62
+ tt(t, c, T);
63
63
  },
64
- [u]
64
+ [l]
65
65
  );
66
66
  r.useLayoutEffect(() => {
67
- if (!q.current)
67
+ if (!D.current)
68
68
  return;
69
- const t = u.current;
69
+ const t = l.current;
70
70
  if (!t) {
71
- q.current = !1;
71
+ D.current = !1;
72
72
  return;
73
73
  }
74
- const c = t.scrollHeight - L.current;
75
- c > 0 && (t.scrollTop = v.current + c), q.current = !1, o.current = !1;
74
+ const c = t.scrollHeight - P.current;
75
+ c > 0 && (t.scrollTop = w.current + c), D.current = !1, o.current = !1;
76
76
  }), r.useLayoutEffect(() => {
77
- if (!G.current)
77
+ if (!C.current)
78
78
  return;
79
- const t = u.current;
79
+ const t = l.current;
80
80
  if (!t) {
81
- G.current = !1;
81
+ C.current = !1;
82
82
  return;
83
83
  }
84
- S >= n.length && S > 0 && (G.current = !1, t.scrollTop = t.scrollHeight - t.clientHeight);
84
+ m >= n.length && m > 0 && (C.current = !1, t.scrollTop = t.scrollHeight - t.clientHeight);
85
85
  });
86
- const w = r.useRef(!1);
86
+ const z = r.useRef(!1);
87
87
  r.useLayoutEffect(() => {
88
- if (!E || w.current)
88
+ if (!x || z.current)
89
89
  return;
90
- const t = u.current;
91
- t && t.querySelector("[data-message-id]") && (t.scrollTop = t.scrollHeight - t.clientHeight, w.current = !0);
90
+ const t = l.current;
91
+ t && t.querySelector("[data-message-id]") && (t.scrollTop = t.scrollHeight - t.clientHeight, z.current = !0);
92
92
  }), r.useEffect(() => {
93
- if (!E)
93
+ if (!x)
94
94
  return;
95
- const t = u.current;
95
+ const t = l.current;
96
96
  if (!t)
97
97
  return;
98
98
  let c = t.scrollTop;
99
- const m = () => {
100
- const { scrollTop: h, scrollHeight: e, clientHeight: x } = t, V = h < c, p = h > c;
101
- if (c = h, !o.current) {
102
- if (V && h <= s) {
103
- if (a) {
104
- const R = d.current;
105
- if (R > 0) {
106
- const X = Math.max(0, R - i);
107
- q.current = !0, P(), B(X);
99
+ const T = () => {
100
+ const { scrollTop: E, scrollHeight: f, clientHeight: H } = t, Y = E < c, M = E > c;
101
+ if (c = E, !o.current) {
102
+ if (Y && E <= L) {
103
+ if (S) {
104
+ const q = N.current;
105
+ if (q > 0) {
106
+ const b = Math.max(0, q - e);
107
+ D.current = !0, d(), a(b), u == null || u({ startIndex: b, endIndex: _.current });
108
108
  }
109
- } else if (f && O > 0) {
109
+ } else if (h && O > 0) {
110
110
  o.current = !0;
111
- const R = Math.max(0, O - i);
112
- q.current = !0, P(), T == null || T({ startIndex: R, endIndex: O });
111
+ const q = Math.max(0, O - e);
112
+ D.current = !0, d(), u == null || u({ startIndex: q, endIndex: R });
113
113
  }
114
114
  }
115
- if (p && e - h - x <= s) {
116
- if (a) {
117
- const R = j.current;
118
- if (R < n.length) {
119
- const X = Math.min(n.length, R + i);
120
- U.current = !0, A(X);
115
+ if (M && f - E - H <= L) {
116
+ if (S) {
117
+ const q = _.current;
118
+ if (q < n.length) {
119
+ const b = Math.min(n.length, q + e);
120
+ J.current = !0, y(b), u == null || u({ startIndex: N.current, endIndex: b });
121
121
  }
122
- } else if (f && H < l) {
123
- o.current = !0, U.current = !0;
124
- const R = Math.min(l, H + i);
125
- T == null || T({ startIndex: H, endIndex: R });
122
+ } else if (h && R < i) {
123
+ o.current = !0, J.current = !0;
124
+ const q = Math.min(i, R + e);
125
+ u == null || u({ startIndex: O, endIndex: q });
126
126
  }
127
127
  }
128
128
  }
129
129
  };
130
- return t.addEventListener("scroll", m, { passive: !0 }), () => t.removeEventListener("scroll", m);
130
+ return t.addEventListener("scroll", T, { passive: !0 }), () => t.removeEventListener("scroll", T);
131
131
  }, [
132
- E,
133
- a,
134
- f,
135
- u,
136
- i,
132
+ x,
133
+ S,
134
+ h,
135
+ l,
136
+ e,
137
137
  n.length,
138
138
  O,
139
- H,
140
- l,
141
- T
139
+ R,
140
+ i,
141
+ u
142
142
  ]), r.useEffect(() => {
143
- var h;
144
- const t = H >= l;
145
- if (!f) {
146
- N.current = l, K.current = t;
143
+ var E;
144
+ const t = R >= i;
145
+ if (!h) {
146
+ V.current = i, Q.current = t;
147
147
  return;
148
148
  }
149
- const c = N.current, m = K.current;
150
- if (N.current = l, K.current = t, l > c && !m && t) {
151
- const e = n[n.length - 1];
152
- k.current !== void 0 && ((h = e == null ? void 0 : e.author) == null ? void 0 : h.id) !== void 0 && String(e.author.id) === String(k.current) && (_.current = !0, U.current = !0);
149
+ const c = V.current, T = Q.current;
150
+ if (V.current = i, Q.current = t, i > c && !T && t) {
151
+ const f = n[n.length - 1];
152
+ $.current !== void 0 && ((E = f == null ? void 0 : f.author) == null ? void 0 : E.id) !== void 0 && String(f.author.id) === String($.current) && (G.current = !0, J.current = !0);
153
153
  }
154
- }, [f, l, H, n]), r.useEffect(() => {
155
- !f || !_.current || (_.current = !1, o.current = !1, requestAnimationFrame(() => {
156
- const t = u.current;
154
+ }, [h, i, R, n]), r.useEffect(() => {
155
+ !h || !G.current || (G.current = !1, o.current = !1, requestAnimationFrame(() => {
156
+ const t = l.current;
157
157
  t && (t.scrollTop = t.scrollHeight - t.clientHeight);
158
158
  }));
159
- }, [f, n, u]), r.useEffect(() => {
160
- if (!f || $.current === null)
159
+ }, [h, n, l]), r.useEffect(() => {
160
+ if (!h || U.current === null)
161
161
  return;
162
- const t = $.current, c = u.current;
162
+ const t = U.current, c = l.current;
163
163
  if (!c)
164
164
  return;
165
- c.querySelector(`[data-message-id="${t}"]`) && ($.current = null, o.current = !1, requestAnimationFrame(() => {
166
- y(t);
165
+ c.querySelector(`[data-message-id="${t}"]`) && (U.current = null, o.current = !1, requestAnimationFrame(() => {
166
+ B(t);
167
167
  }));
168
- }, [f, n, u, y]), r.useEffect(() => {
169
- f && o.current && !q.current && (o.current = !1);
170
- }, [f, O, H]);
171
- const z = r.useMemo(() => {
172
- if (a) {
173
- const t = Math.max(0, D), c = Math.min(n.length, S);
168
+ }, [h, n, l, B]), r.useEffect(() => {
169
+ h && o.current && !D.current && (o.current = !1);
170
+ }, [h, O, R]);
171
+ const g = r.useMemo(() => {
172
+ if (S) {
173
+ const t = Math.max(0, A), c = Math.min(n.length, m);
174
174
  if (t >= c) {
175
- const m = Math.max(0, n.length - i);
176
- return n.slice(m);
175
+ const T = Math.max(0, n.length - e);
176
+ return n.slice(T);
177
177
  }
178
178
  return n.slice(t, c);
179
179
  }
180
180
  return n;
181
- }, [a, n, D, S, i]), Q = r.useMemo(() => E ? a ? S >= n.length : H >= l : !0, [E, a, S, n.length, H, l]), W = r.useCallback(() => {
182
- if (!E || Q) {
183
- const t = u.current;
181
+ }, [S, n, A, m, e]), X = r.useMemo(() => x ? S ? m >= n.length : R >= i : !0, [x, S, m, n.length, R, i]), s = r.useCallback(() => {
182
+ if (!x || X) {
183
+ const t = l.current;
184
184
  t && t.scrollTo({ top: t.scrollHeight - t.clientHeight, behavior: "smooth" });
185
185
  return;
186
186
  }
187
187
  if (!o.current) {
188
- if (a) {
189
- const t = Math.max(0, n.length - i);
190
- B(t), A(n.length), requestAnimationFrame(() => {
191
- const c = u.current;
188
+ if (S) {
189
+ const t = Math.max(0, n.length - e);
190
+ a(t), y(n.length), u == null || u({ startIndex: t, endIndex: n.length }), requestAnimationFrame(() => {
191
+ const c = l.current;
192
192
  c && (c.scrollTop = c.scrollHeight - c.clientHeight);
193
193
  });
194
- } else if (f) {
195
- _.current = !0, q.current = !1, o.current = !0;
196
- const t = Math.max(0, l - i);
197
- T == null || T({ startIndex: t, endIndex: l });
194
+ } else if (h) {
195
+ G.current = !0, D.current = !1, o.current = !0;
196
+ const t = Math.max(0, i - e);
197
+ u == null || u({ startIndex: t, endIndex: i });
198
198
  }
199
199
  }
200
200
  }, [
201
- E,
202
- a,
203
- f,
204
- Q,
201
+ x,
202
+ S,
203
+ h,
204
+ X,
205
205
  n.length,
206
+ e,
206
207
  i,
207
- l,
208
- T,
209
- u
210
- ]), M = r.useCallback(
208
+ u,
209
+ l
210
+ ]), p = r.useCallback(
211
211
  (t) => {
212
- if (!E)
213
- y(t);
214
- else if (a) {
215
- const c = u.current;
212
+ if (!x)
213
+ B(t);
214
+ else if (S) {
215
+ const c = l.current;
216
216
  if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
217
- y(t);
217
+ B(t);
218
218
  else {
219
219
  if (o.current)
220
220
  return;
221
- const h = n.findIndex(
222
- (e) => e.id === t || String(e.id) === String(t)
221
+ const E = n.findIndex(
222
+ (f) => f.id === t || String(f.id) === String(t)
223
223
  );
224
- if (h >= 0) {
225
- const e = Math.floor(i / 2), x = Math.max(0, h - e), V = Math.min(n.length, x + i);
226
- o.current = !0, B(x), A(V), requestAnimationFrame(() => {
224
+ if (E >= 0) {
225
+ const f = Math.floor(e / 2), H = Math.max(0, E - f), Y = Math.min(n.length, H + e);
226
+ o.current = !0, a(H), y(Y), requestAnimationFrame(() => {
227
227
  requestAnimationFrame(() => {
228
- y(t), o.current = !1;
228
+ B(t), o.current = !1;
229
229
  });
230
230
  });
231
231
  }
232
232
  }
233
- } else if (f) {
234
- const c = u.current;
233
+ } else if (h) {
234
+ const c = l.current;
235
235
  if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
236
- y(t);
236
+ B(t);
237
237
  else {
238
238
  if (o.current)
239
239
  return;
240
- $.current = t, q.current = !1, o.current = !0;
240
+ U.current = t, D.current = !1, o.current = !0;
241
241
  }
242
242
  }
243
- b == null || b({ id: t });
243
+ F == null || F({ id: t });
244
244
  },
245
245
  [
246
- E,
247
- a,
248
- f,
249
- u,
246
+ x,
247
+ S,
248
+ h,
249
+ l,
250
250
  n,
251
- i,
252
- b,
253
- y
251
+ e,
252
+ F,
253
+ B
254
254
  ]
255
255
  );
256
256
  return {
257
- renderedMessages: z,
258
- handleScrollToBottom: W,
259
- handleReferencedMessageClick: M,
260
- isEndless: E,
261
- isOnLastBatch: Q,
262
- skipAutoScrollRef: U
257
+ renderedMessages: g,
258
+ handleScrollToBottom: s,
259
+ handleReferencedMessageClick: p,
260
+ isEndless: x,
261
+ isOnLastBatch: X,
262
+ skipAutoScrollRef: J
263
263
  };
264
264
  };
265
265
  export {