@progress/kendo-react-conversational-ui 14.5.0-develop.9 → 15.0.0-develop.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.
@@ -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 ye=require("react"),g=require("@progress/kendo-react-common"),D=require("@progress/kendo-react-buttons"),f=require("@progress/kendo-svg-icons"),ne=require("@progress/kendo-react-layout"),i=require("../utils.js"),xe=require("./ChatContext.js"),Ee=require("./elements/FileBox.js"),le=require("@progress/kendo-react-intl"),l=require("../../messages/index.js");function Ie(u){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const d=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(r,e,d.get?d:{enumerable:!0,get:()=>u[e]})}}return r.default=u,Object.freeze(r)}const s=Ie(ye),oe=s.forwardRef((u,r)=>{const{item:e,template:d,contentTemplate:F,onRequestSelection:C,tabIndex:ce=-1,dateFormat:H="g",selected:c,allowMessageCollapse:y,messageToolbarActions:x,messageContextMenuActions:E,fileActions:U,isSender:I}=u,{setReplyToMessage:w,messages:X,repliedToMessages:A,user:b,onToolbarAction:R,onContextMenuAction:z,onFileAction:Y,onDownload:m,onResendMessage:q,setShowCopyNotification:M,statusTemplate:L,timestampVisibility:v="onFocus",onReferencedMessageClick:T}=xe.useChatContext(),[G,V]=s.useState(!1),[J,O]=s.useState(!1),[h,ie]=s.useState(!0),[re,Q]=s.useState(!1),o=le.useLocalization(),Z=le.useInternationalization(),$=s.useRef({left:0,top:0}),N=s.useCallback(()=>{e!=null&&e.text&&i.copyToClipboard(e.text),M&&(M(!0),setTimeout(()=>{M(!1)},3e3))},[e,M]),j=s.useCallback(t=>{t.stopPropagation(),ie(a=>!a)},[]),ue=s.useCallback(()=>{Q(!1)},[]),de=s.useCallback(t=>{(t.key==="Tab"||t.key==="Enter"||t.key===" "||t.key==="ArrowUp"||t.key==="ArrowDown")&&Q(!0)},[]),B=s.useRef(null);s.useEffect(()=>{c&&B.current&&B.current.focus()},[c]);const P=s.useCallback(t=>{$.current={left:t.pageX,top:t.pageY},t.preventDefault(),O(!0),V(!0)},[]),ee=s.useCallback(()=>{O(!1),V(!1)},[]),S=s.useCallback((t,a)=>t.isDeleted?i.getDeletedMessageText(a,o):t.text?t.text:"",[o]),te=s.useCallback(t=>{var a;(a=t.item)!=null&&a.text&&(t.item.data.id==="copy"&&!e.isDeleted?N():t.item.data.id==="reply"&&w(e),z&&z(t.item.data,t,e)),O(!1),V(!1)},[e,z,w,N]),se=s.useCallback(()=>{if(e.replyToId){const t=i.getMessageById(X,e.replyToId)||(A?i.getMessageById(A,e.replyToId):void 0);if(t){const a=n=>{n.preventDefault(),n.stopPropagation(),T==null||T(t.id)};return s.createElement("div",{className:g.classNames("k-message-reference",i.isAuthor(b,t)?"k-message-reference-sender":"k-message-reference-receiver"),onClick:a},s.createElement("div",{className:"k-message-reference-content"},i.convertTextToLinkedContent(S(t,i.isAuthor(b,t)))))}}return null},[e.replyToId,X,A,b,S,T]),K=s.useCallback(()=>{const t=[{id:"reply",label:"Reply",svgIcon:f.undoIcon},{id:"copy",label:"Copy",svgIcon:f.copyIcon}],a=E?[...t.map(n=>E.find(k=>k.id===n.id)||n),...E.filter(n=>!t.some(p=>p.id===n.id))]:t;return s.createElement(ne.ContextMenu,{onSelect:te,onClose:ee,vertical:!0,show:G,offset:$.current},a.map(n=>n.id==="delete"&&!I?null:s.createElement(ne.MenuItem,{key:n.id,text:n.label,icon:n.icon,svgIcon:n.svgIcon,data:n})))},[E,te,ee,G,I]),ae=s.useCallback(()=>e.files&&e.files.length>1?s.createElement("div",{className:"k-chat-download-button-wrapper"},s.createElement(D.Button,{className:"k-chat-download-button",fillMode:"flat",svgIcon:f.downloadIcon,size:"small",onClick:t=>{t.stopPropagation(),m&&m(e.files,e)},"aria-label":o.toLanguageString(l.downloadAllFiles,l.messages[l.downloadAllFiles])},s.createElement("span",{className:"k-button-text"},o.toLanguageString(l.downloadAll,l.messages[l.downloadAll])))):null,[e,m,o]),me=s.useCallback(()=>{if(e.typing)return s.createElement("div",{className:"k-chat-bubble k-bubble"},s.createElement("div",{className:"k-bubble-content"},s.createElement("div",{className:"k-typing-indicator"},s.createElement("span",null),s.createElement("span",null),s.createElement("span",null))));if(d){const t=d;return s.createElement(s.Fragment,null,s.createElement(t,{item:e}),K())}else if(e.text||e.files&&e.files.length>0)return s.createElement(s.Fragment,null,s.createElement("div",{className:g.classNames("k-chat-bubble","k-bubble",{"k-bubble-expandable":y,"k-expanded":y&&h,"k-selected":c,"k-active":J}),onClick:()=>C(c?void 0:e.selectionIndex),onContextMenu:P},s.createElement("div",{className:"k-bubble-content"},F?s.createElement(F,{item:e}):s.createElement(s.Fragment,null,(e.text||e.isDeleted||e.replyToId)&&s.createElement("span",{className:"k-chat-bubble-text"},!e.isDeleted&&se(),i.convertTextToLinkedContent(S(e,i.isAuthor(b,e)))),e.files&&e.files.length>0&&s.createElement(Ee,{files:e.files,message:e,onFileAction:Y,onDownload:t=>m==null?void 0:m(t,e),renderInTextarea:!1,fileActions:U}),ae())),y&&s.createElement("span",{className:"k-bubble-expandable-indicator",onClick:j,role:"button","aria-label":h?o.toLanguageString(l.collapseMessage,l.messages[l.collapseMessage]):o.toLanguageString(l.expandMessage,l.messages[l.expandMessage]),tabIndex:0,onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),j(t))}},s.createElement(g.IconWrap,{icon:h?f.chevronUpIcon:f.chevronDownIcon,size:"medium"}))),K());return null},[e,d,F,y,h,c,J,C,P,se,S,b,Y,U,ae,j,o,K,m]),ge=s.useCallback(()=>{let t=null;if(e.timestamp){const a=v==="onFocus"&&c;v==="hidden"||(t=s.createElement("time",{className:"k-message-time","aria-hidden":!a},Z.formatDate(e.timestamp,H)))}return t},[e.timestamp,c,H,v,Z]),fe=s.useCallback(()=>{if(!e.status)return null;let t;if(L)t=s.createElement(L,{item:e});else{const a=typeof e.status=="object"&&e.status!==null;let n,p,k;if(a){const _=e.status;n=_.text,p=_.icon,k=_.svgIcon}else n=e.status;let W=null;p?W=s.createElement(g.Icon,{name:p,size:"xsmall"}):k&&(W=s.createElement(g.IconWrap,{icon:k,size:"xsmall"})),t=s.createElement(s.Fragment,null,W,n)}return s.createElement("span",{className:"k-message-status"},t)},[e,L]),pe=s.useCallback(()=>{let t=null;if(e.isFailed){const a=o.toLanguageString(l.messageFailed,l.messages[l.messageFailed]);t=s.createElement("span",{className:"k-message-failed-content"},s.createElement(g.IconWrap,{icon:f.warningTriangleIcon,size:"xsmall"}),s.createElement("span",{className:"k-message-failed-text"},a))}return t},[e,o]),be=s.useCallback(()=>{let t=null;if(e.isFailed){const a=o.toLanguageString(l.retryMessage,l.messages[l.retryMessage]);t=s.createElement(D.Button,{fillMode:"clear",size:"xs",className:"k-resend-button",svgIcon:f.arrowRotateCwIcon,"aria-label":a,title:a,onClick:n=>{n.stopPropagation(),q&&q({message:e,syntheticEvent:n,nativeEvent:n.nativeEvent,target:n.target})}})}return t},[e,o,q]),ke=s.useCallback(()=>g.classNames({"k-focus":c,"k-message-removed":e.isDeleted,"k-message-failed":e.isFailed},"k-message"),[c,e.isDeleted,e.isFailed]),Ce=s.useCallback(()=>x&&x.length>0&&s.createElement(D.Toolbar,{className:"k-chat-message-toolbar",fillMode:"flat",size:"small"},x.map(t=>t.id==="delete"&&!I?null:s.createElement(D.Button,{key:t.id,fillMode:"flat",size:"xs",className:"k-toolbar-button",icon:t.icon,svgIcon:t.svgIcon,onClick:a=>{a.stopPropagation(),t.id==="copy"&&!e.isDeleted?N():t.id==="reply"&&w(e),R&&R(t,a,e)},onMouseDown:a=>a.preventDefault()}))),[N,I,e,x,R,w]);return s.createElement("div",{key:e.id,"data-message-id":e.id,className:ke(),tabIndex:ce,onMouseDown:ue,onKeyDown:de,onFocus:t=>{re&&C(e.selectionIndex)},ref:t=>{B.current=t,typeof r=="function"?r(t):r&&(r.current=t)},onContextMenu:d?P:void 0},be(),me(),(e.status||e.timestamp&&v!=="hidden"||e.isFailed)&&s.createElement("div",{className:"k-message-info"},fe(),ge(),pe()),Ce())});oe.displayName="ChatMessage";exports.ChatMessage=oe;
8
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=require("react"),g=require("@progress/kendo-react-common"),S=require("@progress/kendo-react-buttons"),f=require("@progress/kendo-svg-icons"),ne=require("@progress/kendo-react-layout"),c=require("../utils.js"),Ee=require("./ChatContext.js"),xe=require("./elements/FileBox.js"),le=require("@progress/kendo-react-intl"),l=require("../../messages/index.js");function Ie(i){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const u=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(r,e,u.get?u:{enumerable:!0,get:()=>i[e]})}}return r.default=i,Object.freeze(r)}const a=Ie(ye),oe=a.forwardRef((i,r)=>{const{item:e,template:u,contentTemplate:D,onRequestSelection:C,tabIndex:ce=-1,dateFormat:H="g",selected:d,allowMessageCollapse:y,messageToolbarActions:E,messageContextMenuActions:x,fileActions:U,isSender:I}=i,{setReplyToMessage:M,messages:X,repliedToMessages:A,user:b,onToolbarAction:F,onContextMenuAction:R,onFileAction:Y,onDownload:m,onResendMessage:L,setShowCopyNotification:w,statusTemplate:q,timestampVisibility:z="onFocus",onReferencedMessageClick:T}=Ee.useChatContext(),[G,O]=a.useState(!1),[J,V]=a.useState(!1),[h,re]=a.useState(!0),[ie,Q]=a.useState(!1),o=le.useLocalization(),Z=le.useInternationalization(),$=a.useRef({left:0,top:0}),v=a.useCallback(()=>{e!=null&&e.text&&c.copyToClipboard(e.text),w&&(w(!0),setTimeout(()=>{w(!1)},3e3))},[e,w]),j=a.useCallback(t=>{t.stopPropagation(),re(s=>!s)},[]),ue=a.useCallback(()=>{Q(!1)},[]),de=a.useCallback(t=>{(t.key==="Tab"||t.key==="Enter"||t.key===" "||t.key==="ArrowUp"||t.key==="ArrowDown")&&Q(!0)},[]),B=a.useRef(null);a.useEffect(()=>{d&&B.current&&B.current.focus()},[d]);const P=a.useCallback(t=>{$.current={left:t.pageX,top:t.pageY},t.preventDefault(),V(!0),O(!0)},[]),ee=a.useCallback(()=>{V(!1),O(!1)},[]),N=a.useCallback((t,s)=>t.isDeleted?c.getDeletedMessageText(s,o):t.text?t.text:"",[o]),te=a.useCallback(t=>{var s;(s=t.item)!=null&&s.text&&(t.item.data.id==="copy"&&!e.isDeleted?v():t.item.data.id==="reply"&&M(e),R&&R(t.item.data,t,e)),V(!1),O(!1)},[e,R,M,v]),ae=a.useCallback(()=>{if(e.replyToId){const t=c.getMessageById(X,e.replyToId)||(A?c.getMessageById(A,e.replyToId):void 0);if(t){const s=n=>{n.preventDefault(),n.stopPropagation(),T==null||T(t.id)};return a.createElement("div",{className:g.classNames("k-message-reference",c.isAuthor(b,t)?"k-message-reference-sender":"k-message-reference-receiver"),onClick:s},a.createElement("div",{className:"k-message-reference-content"},c.convertTextToLinkedContent(N(t,c.isAuthor(b,t)))))}}return null},[e.replyToId,X,A,b,N,T]),K=a.useCallback(()=>{const t=[{id:"reply",label:"Reply",svgIcon:f.undoIcon},{id:"copy",label:"Copy",svgIcon:f.copyIcon}],s=x?[...t.map(n=>x.find(k=>k.id===n.id)||n),...x.filter(n=>!t.some(p=>p.id===n.id))]:t;return a.createElement(ne.ContextMenu,{onSelect:te,onClose:ee,vertical:!0,show:G,offset:$.current},s.map(n=>n.id==="delete"&&!I?null:a.createElement(ne.MenuItem,{key:n.id,text:n.label,icon:n.icon,svgIcon:n.svgIcon,data:n})))},[x,te,ee,G,I]),se=a.useCallback(()=>e.files&&e.files.length>1?a.createElement("div",{className:"k-chat-download-button-wrapper"},a.createElement(S.Button,{className:"k-chat-download-button",fillMode:"flat",svgIcon:f.downloadIcon,size:"small",onClick:t=>{t.stopPropagation(),m&&m(e.files,e)},"aria-label":o.toLanguageString(l.downloadAllFiles,l.messages[l.downloadAllFiles])},a.createElement("span",{className:"k-button-text"},o.toLanguageString(l.downloadAll,l.messages[l.downloadAll])))):null,[e,m,o]),me=a.useCallback(()=>{if(e.typing)return a.createElement("div",{className:"k-chat-bubble k-bubble"},a.createElement("div",{className:"k-bubble-content"},a.createElement("div",{className:"k-typing-indicator"},a.createElement("span",null),a.createElement("span",null),a.createElement("span",null))));if(u){const t=u;return a.createElement(a.Fragment,null,a.createElement(t,{item:e}),K())}else if(e.text||e.files&&e.files.length>0)return a.createElement(a.Fragment,null,a.createElement("div",{className:g.classNames("k-chat-bubble","k-bubble",{"k-bubble-expandable":y,"k-expanded":y&&h,"k-selected":d,"k-active":J}),onClick:()=>C(d?void 0:e.selectionIndex),onContextMenu:P},a.createElement("div",{className:"k-bubble-content"},D?a.createElement(D,{item:e}):a.createElement(a.Fragment,null,(e.text||e.isDeleted||e.replyToId)&&a.createElement("span",{className:"k-chat-bubble-text"},!e.isDeleted&&ae(),c.convertTextToLinkedContent(N(e,c.isAuthor(b,e)))),e.files&&e.files.length>0&&a.createElement(xe,{files:e.files,message:e,onFileAction:Y,onDownload:t=>m==null?void 0:m(t,e),renderInTextarea:!1,fileActions:U}),se())),y&&a.createElement("span",{className:"k-bubble-expandable-indicator",onClick:j,role:"button","aria-label":h?o.toLanguageString(l.collapseMessage,l.messages[l.collapseMessage]):o.toLanguageString(l.expandMessage,l.messages[l.expandMessage]),tabIndex:0,onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),j(t))}},a.createElement(g.IconWrap,{icon:h?f.chevronUpIcon:f.chevronDownIcon,size:"medium"}))),K());return null},[e,u,D,y,h,d,J,C,P,ae,N,b,Y,U,se,j,o,K,m]),ge=a.useCallback(()=>{let t=null;return e.timestamp&&(z==="hidden"||(t=a.createElement("time",{className:"k-message-time"},Z.formatDate(e.timestamp,H)))),t},[e.timestamp,H,z,Z]),fe=a.useCallback(()=>{if(!e.status)return null;let t;if(q)t=a.createElement(q,{item:e});else{const s=typeof e.status=="object"&&e.status!==null;let n,p,k;if(s){const _=e.status;n=_.text,p=_.icon,k=_.svgIcon}else n=e.status;let W=null;p?W=a.createElement(g.Icon,{name:p,size:"xsmall"}):k&&(W=a.createElement(g.IconWrap,{icon:k,size:"xsmall"})),t=a.createElement(a.Fragment,null,W,n)}return a.createElement("span",{className:"k-message-status"},t)},[e,q]),pe=a.useCallback(()=>{let t=null;if(e.isFailed){const s=o.toLanguageString(l.messageFailed,l.messages[l.messageFailed]);t=a.createElement("span",{className:"k-message-failed-content"},a.createElement(g.IconWrap,{icon:f.warningTriangleIcon,size:"xsmall"}),a.createElement("span",{className:"k-message-failed-text"},s))}return t},[e,o]),be=a.useCallback(()=>{let t=null;if(e.isFailed){const s=o.toLanguageString(l.retryMessage,l.messages[l.retryMessage]);t=a.createElement(S.Button,{fillMode:"clear",size:"xs",className:"k-resend-button",svgIcon:f.arrowRotateCwIcon,"aria-label":s,title:s,onClick:n=>{n.stopPropagation(),L&&L({message:e,syntheticEvent:n,nativeEvent:n.nativeEvent,target:n.target})}})}return t},[e,o,L]),ke=a.useCallback(()=>g.classNames({"k-focus":d,"k-message-removed":e.isDeleted,"k-message-failed":e.isFailed},"k-message"),[d,e.isDeleted,e.isFailed]),Ce=a.useCallback(()=>E&&E.length>0&&a.createElement(S.Toolbar,{className:"k-chat-message-toolbar",fillMode:"flat",ariaLabel:o.toLanguageString(l.chatMessageToolbar,l.messages[l.chatMessageToolbar])},E.map(t=>t.id==="delete"&&!I?null:a.createElement(S.Button,{key:t.id,fillMode:"flat",className:"k-toolbar-button",icon:t.icon,svgIcon:t.svgIcon,"aria-label":t.label,onClick:s=>{s.stopPropagation(),t.id==="copy"&&!e.isDeleted?v():t.id==="reply"&&M(e),F&&F(t,s,e)},onMouseDown:s=>s.preventDefault()}))),[v,I,e,o,E,F,M]);return a.createElement("div",{key:e.id,"data-message-id":e.id,className:ke(),tabIndex:ce,onMouseDown:ue,onKeyDown:de,onFocus:t=>{ie&&C(e.selectionIndex)},ref:t=>{B.current=t,typeof r=="function"?r(t):r&&(r.current=t)},onContextMenu:u?P:void 0},be(),me(),(e.status||e.timestamp&&z!=="hidden"||e.isFailed)&&a.createElement("div",{className:"k-message-info"},fe(),ge(),pe()),Ce())});oe.displayName="ChatMessage";exports.ChatMessage=oe;
@@ -7,76 +7,76 @@
7
7
  */
8
8
  import * as t from "react";
9
9
  import { classNames as O, IconWrap as j, Icon as ve } from "@progress/kendo-react-common";
10
- import { Button as W, Toolbar as Te } from "@progress/kendo-react-buttons";
11
- import { undoIcon as he, copyIcon as Me, downloadIcon as Ne, chevronUpIcon as De, chevronDownIcon as Se, warningTriangleIcon as Fe, arrowRotateCwIcon as Ae } from "@progress/kendo-svg-icons";
12
- import { ContextMenu as Re, MenuItem as ze } from "@progress/kendo-react-layout";
13
- import { copyToClipboard as Ve, getDeletedMessageText as Le, getMessageById as se, isAuthor as H, convertTextToLinkedContent as ne } from "../utils.mjs";
14
- import { useChatContext as Ke } from "./ChatContext.mjs";
15
- import Pe from "./elements/FileBox.mjs";
16
- import { useLocalization as Be, useInternationalization as Oe } from "@progress/kendo-react-intl";
17
- import { downloadAllFiles as le, messages as c, downloadAll as oe, collapseMessage as ie, expandMessage as re, messageFailed as ce, retryMessage as ue } from "../../messages/index.mjs";
18
- const je = t.forwardRef(
19
- (me, d) => {
10
+ import { Button as W, Toolbar as he } from "@progress/kendo-react-buttons";
11
+ import { undoIcon as Me, copyIcon as Ne, downloadIcon as De, chevronUpIcon as Se, chevronDownIcon as Fe, warningTriangleIcon as Ae, arrowRotateCwIcon as Re } from "@progress/kendo-svg-icons";
12
+ import { ContextMenu as Le, MenuItem as Ve } from "@progress/kendo-react-layout";
13
+ import { copyToClipboard as ze, getDeletedMessageText as Ke, getMessageById as se, isAuthor as H, convertTextToLinkedContent as ne } from "../utils.mjs";
14
+ import { useChatContext as Pe } from "./ChatContext.mjs";
15
+ import Be from "./elements/FileBox.mjs";
16
+ import { useLocalization as Oe, useInternationalization as je } from "@progress/kendo-react-intl";
17
+ import { downloadAllFiles as le, messages as r, downloadAll as oe, collapseMessage as ie, expandMessage as re, messageFailed as ce, retryMessage as ue, chatMessageToolbar as me } from "../../messages/index.mjs";
18
+ const We = t.forwardRef(
19
+ (de, d) => {
20
20
  const {
21
21
  item: a,
22
22
  template: f,
23
- contentTemplate: h,
24
- onRequestSelection: p,
25
- tabIndex: de = -1,
23
+ contentTemplate: v,
24
+ onRequestSelection: g,
25
+ tabIndex: fe = -1,
26
26
  dateFormat: U = "g",
27
27
  selected: o,
28
- allowMessageCollapse: g,
28
+ allowMessageCollapse: p,
29
29
  messageToolbarActions: b,
30
30
  messageContextMenuActions: k,
31
31
  fileActions: q,
32
32
  isSender: C
33
- } = me, {
33
+ } = de, {
34
34
  setReplyToMessage: E,
35
35
  messages: X,
36
- repliedToMessages: M,
36
+ repliedToMessages: h,
37
37
  user: u,
38
- onToolbarAction: N,
39
- onContextMenuAction: D,
38
+ onToolbarAction: M,
39
+ onContextMenuAction: N,
40
40
  onFileAction: Y,
41
41
  onDownload: i,
42
- onResendMessage: S,
42
+ onResendMessage: D,
43
43
  setShowCopyNotification: x,
44
- statusTemplate: F,
45
- timestampVisibility: y = "onFocus",
46
- onReferencedMessageClick: I
47
- } = Ke(), [$, A] = t.useState(!1), [G, R] = t.useState(!1), [w, fe] = t.useState(!0), [pe, J] = t.useState(!1), l = Be(), Q = Oe(), Z = t.useRef({ left: 0, top: 0 }), v = t.useCallback(() => {
48
- a != null && a.text && Ve(a.text), x && (x(!0), setTimeout(() => {
44
+ statusTemplate: S,
45
+ timestampVisibility: F = "onFocus",
46
+ onReferencedMessageClick: y
47
+ } = Pe(), [$, A] = t.useState(!1), [G, R] = t.useState(!1), [I, ge] = t.useState(!0), [pe, J] = t.useState(!1), l = Oe(), Q = je(), Z = t.useRef({ left: 0, top: 0 }), w = t.useCallback(() => {
48
+ a != null && a.text && ze(a.text), x && (x(!0), setTimeout(() => {
49
49
  x(!1);
50
50
  }, 3e3));
51
- }, [a, x]), z = t.useCallback((e) => {
52
- e.stopPropagation(), fe((s) => !s);
53
- }, []), ge = t.useCallback(() => {
51
+ }, [a, x]), L = t.useCallback((e) => {
52
+ e.stopPropagation(), ge((s) => !s);
53
+ }, []), be = t.useCallback(() => {
54
54
  J(!1);
55
- }, []), be = t.useCallback((e) => {
55
+ }, []), ke = t.useCallback((e) => {
56
56
  (e.key === "Tab" || e.key === "Enter" || e.key === " " || e.key === "ArrowUp" || e.key === "ArrowDown") && J(!0);
57
57
  }, []), V = t.useRef(null);
58
58
  t.useEffect(() => {
59
59
  o && V.current && V.current.focus();
60
60
  }, [o]);
61
- const L = t.useCallback((e) => {
61
+ const z = t.useCallback((e) => {
62
62
  Z.current = { left: e.pageX, top: e.pageY }, e.preventDefault(), R(!0), A(!0);
63
63
  }, []), _ = t.useCallback(() => {
64
64
  R(!1), A(!1);
65
65
  }, []), T = t.useCallback(
66
- (e, s) => e.isDeleted ? Le(s, l) : e.text ? e.text : "",
66
+ (e, s) => e.isDeleted ? Ke(s, l) : e.text ? e.text : "",
67
67
  [l]
68
68
  ), ee = t.useCallback(
69
69
  (e) => {
70
70
  var s;
71
- (s = e.item) != null && s.text && (e.item.data.id === "copy" && !a.isDeleted ? v() : e.item.data.id === "reply" && E(a), D && D(e.item.data, e, a)), R(!1), A(!1);
71
+ (s = e.item) != null && s.text && (e.item.data.id === "copy" && !a.isDeleted ? w() : e.item.data.id === "reply" && E(a), N && N(e.item.data, e, a)), R(!1), A(!1);
72
72
  },
73
- [a, D, E, v]
73
+ [a, N, E, w]
74
74
  ), te = t.useCallback(() => {
75
75
  if (a.replyToId) {
76
- const e = se(X, a.replyToId) || (M ? se(M, a.replyToId) : void 0);
76
+ const e = se(X, a.replyToId) || (h ? se(h, a.replyToId) : void 0);
77
77
  if (e) {
78
78
  const s = (n) => {
79
- n.preventDefault(), n.stopPropagation(), I == null || I(e.id);
79
+ n.preventDefault(), n.stopPropagation(), y == null || y(e.id);
80
80
  };
81
81
  return /* @__PURE__ */ t.createElement(
82
82
  "div",
@@ -94,28 +94,28 @@ const je = t.forwardRef(
94
94
  }
95
95
  }
96
96
  return null;
97
- }, [a.replyToId, X, M, u, T, I]), K = t.useCallback(() => {
97
+ }, [a.replyToId, X, h, u, T, y]), K = t.useCallback(() => {
98
98
  const e = [
99
99
  {
100
100
  id: "reply",
101
101
  label: "Reply",
102
- svgIcon: he
102
+ svgIcon: Me
103
103
  },
104
104
  {
105
105
  id: "copy",
106
106
  label: "Copy",
107
- svgIcon: Me
107
+ svgIcon: Ne
108
108
  }
109
109
  ], s = k ? [
110
110
  ...e.map((n) => k.find(
111
111
  (m) => m.id === n.id
112
112
  ) || n),
113
113
  ...k.filter(
114
- (n) => !e.some((r) => r.id === n.id)
114
+ (n) => !e.some((c) => c.id === n.id)
115
115
  )
116
116
  ] : e;
117
117
  return /* @__PURE__ */ t.createElement(
118
- Re,
118
+ Le,
119
119
  {
120
120
  onSelect: ee,
121
121
  onClose: _,
@@ -125,7 +125,7 @@ const je = t.forwardRef(
125
125
  },
126
126
  s.map(
127
127
  (n) => n.id === "delete" && !C ? null : /* @__PURE__ */ t.createElement(
128
- ze,
128
+ Ve,
129
129
  {
130
130
  key: n.id,
131
131
  text: n.label,
@@ -141,18 +141,18 @@ const je = t.forwardRef(
141
141
  {
142
142
  className: "k-chat-download-button",
143
143
  fillMode: "flat",
144
- svgIcon: Ne,
144
+ svgIcon: De,
145
145
  size: "small",
146
146
  onClick: (e) => {
147
147
  e.stopPropagation(), i && i(a.files, a);
148
148
  },
149
149
  "aria-label": l.toLanguageString(
150
150
  le,
151
- c[le]
151
+ r[le]
152
152
  )
153
153
  },
154
- /* @__PURE__ */ t.createElement("span", { className: "k-button-text" }, l.toLanguageString(oe, c[oe]))
155
- )) : null, [a, i, l]), ke = t.useCallback(() => {
154
+ /* @__PURE__ */ t.createElement("span", { className: "k-button-text" }, l.toLanguageString(oe, r[oe]))
155
+ )) : null, [a, i, l]), Ce = t.useCallback(() => {
156
156
  if (a.typing)
157
157
  return /* @__PURE__ */ t.createElement("div", { className: "k-chat-bubble k-bubble" }, /* @__PURE__ */ t.createElement("div", { className: "k-bubble-content" }, /* @__PURE__ */ t.createElement("div", { className: "k-typing-indicator" }, /* @__PURE__ */ t.createElement("span", null), /* @__PURE__ */ t.createElement("span", null), /* @__PURE__ */ t.createElement("span", null))));
158
158
  if (f) {
@@ -163,18 +163,18 @@ const je = t.forwardRef(
163
163
  "div",
164
164
  {
165
165
  className: O("k-chat-bubble", "k-bubble", {
166
- "k-bubble-expandable": g,
167
- "k-expanded": g && w,
166
+ "k-bubble-expandable": p,
167
+ "k-expanded": p && I,
168
168
  "k-selected": o,
169
169
  "k-active": G
170
170
  }),
171
- onClick: () => p(o ? void 0 : a.selectionIndex),
172
- onContextMenu: L
171
+ onClick: () => g(o ? void 0 : a.selectionIndex),
172
+ onContextMenu: z
173
173
  },
174
- /* @__PURE__ */ t.createElement("div", { className: "k-bubble-content" }, h ? /* @__PURE__ */ t.createElement(h, { item: a }) : /* @__PURE__ */ t.createElement(t.Fragment, null, (a.text || a.isDeleted || a.replyToId) && /* @__PURE__ */ t.createElement("span", { className: "k-chat-bubble-text" }, !a.isDeleted && te(), ne(
174
+ /* @__PURE__ */ t.createElement("div", { className: "k-bubble-content" }, v ? /* @__PURE__ */ t.createElement(v, { item: a }) : /* @__PURE__ */ t.createElement(t.Fragment, null, (a.text || a.isDeleted || a.replyToId) && /* @__PURE__ */ t.createElement("span", { className: "k-chat-bubble-text" }, !a.isDeleted && te(), ne(
175
175
  T(a, H(u, a))
176
176
  )), a.files && a.files.length > 0 && /* @__PURE__ */ t.createElement(
177
- Pe,
177
+ Be,
178
178
  {
179
179
  files: a.files,
180
180
  message: a,
@@ -184,89 +184,85 @@ const je = t.forwardRef(
184
184
  fileActions: q
185
185
  }
186
186
  ), ae())),
187
- g && /* @__PURE__ */ t.createElement(
187
+ p && /* @__PURE__ */ t.createElement(
188
188
  "span",
189
189
  {
190
190
  className: "k-bubble-expandable-indicator",
191
- onClick: z,
191
+ onClick: L,
192
192
  role: "button",
193
- "aria-label": w ? l.toLanguageString(
193
+ "aria-label": I ? l.toLanguageString(
194
194
  ie,
195
- c[ie]
195
+ r[ie]
196
196
  ) : l.toLanguageString(
197
197
  re,
198
- c[re]
198
+ r[re]
199
199
  ),
200
200
  tabIndex: 0,
201
201
  onKeyDown: (e) => {
202
- (e.key === "Enter" || e.key === " ") && (e.preventDefault(), z(e));
202
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), L(e));
203
203
  }
204
204
  },
205
- /* @__PURE__ */ t.createElement(j, { icon: w ? De : Se, size: "medium" })
205
+ /* @__PURE__ */ t.createElement(j, { icon: I ? Se : Fe, size: "medium" })
206
206
  )
207
207
  ), K());
208
208
  return null;
209
209
  }, [
210
210
  a,
211
211
  f,
212
- h,
213
- g,
214
- w,
212
+ v,
213
+ p,
214
+ I,
215
215
  o,
216
216
  G,
217
- p,
218
- L,
217
+ g,
218
+ z,
219
219
  te,
220
220
  T,
221
221
  u,
222
222
  Y,
223
223
  q,
224
224
  ae,
225
- z,
225
+ L,
226
226
  l,
227
227
  K,
228
228
  i
229
- ]), Ce = t.useCallback(() => {
229
+ ]), Ee = t.useCallback(() => {
230
230
  let e = null;
231
- if (a.timestamp) {
232
- const s = y === "onFocus" && o;
233
- y === "hidden" || (e = /* @__PURE__ */ t.createElement("time", { className: "k-message-time", "aria-hidden": !s }, Q.formatDate(a.timestamp, U)));
234
- }
235
- return e;
236
- }, [a.timestamp, o, U, y, Q]), Ee = t.useCallback(() => {
231
+ return a.timestamp && (F === "hidden" || (e = /* @__PURE__ */ t.createElement("time", { className: "k-message-time" }, Q.formatDate(a.timestamp, U)))), e;
232
+ }, [a.timestamp, U, F, Q]), xe = t.useCallback(() => {
237
233
  if (!a.status)
238
234
  return null;
239
235
  let e;
240
- if (F)
241
- e = t.createElement(F, { item: a });
236
+ if (S)
237
+ e = t.createElement(S, { item: a });
242
238
  else {
243
239
  const s = typeof a.status == "object" && a.status !== null;
244
- let n, r, m;
240
+ let n, c, m;
245
241
  if (s) {
246
242
  const B = a.status;
247
- n = B.text, r = B.icon, m = B.svgIcon;
243
+ n = B.text, c = B.icon, m = B.svgIcon;
248
244
  } else
249
245
  n = a.status;
250
246
  let P = null;
251
- r ? P = /* @__PURE__ */ t.createElement(ve, { name: r, size: "xsmall" }) : m && (P = /* @__PURE__ */ t.createElement(j, { icon: m, size: "xsmall" })), e = /* @__PURE__ */ t.createElement(t.Fragment, null, P, n);
247
+ c ? P = /* @__PURE__ */ t.createElement(ve, { name: c, size: "xsmall" }) : m && (P = /* @__PURE__ */ t.createElement(j, { icon: m, size: "xsmall" })), e = /* @__PURE__ */ t.createElement(t.Fragment, null, P, n);
252
248
  }
253
249
  return /* @__PURE__ */ t.createElement("span", { className: "k-message-status" }, e);
254
- }, [a, F]), xe = t.useCallback(() => {
250
+ }, [a, S]), ye = t.useCallback(() => {
255
251
  let e = null;
256
252
  if (a.isFailed) {
257
253
  const s = l.toLanguageString(
258
254
  ce,
259
- c[ce]
255
+ r[ce]
260
256
  );
261
- e = /* @__PURE__ */ t.createElement("span", { className: "k-message-failed-content" }, /* @__PURE__ */ t.createElement(j, { icon: Fe, size: "xsmall" }), /* @__PURE__ */ t.createElement("span", { className: "k-message-failed-text" }, s));
257
+ e = /* @__PURE__ */ t.createElement("span", { className: "k-message-failed-content" }, /* @__PURE__ */ t.createElement(j, { icon: Ae, size: "xsmall" }), /* @__PURE__ */ t.createElement("span", { className: "k-message-failed-text" }, s));
262
258
  }
263
259
  return e;
264
- }, [a, l]), ye = t.useCallback(() => {
260
+ }, [a, l]), Ie = t.useCallback(() => {
265
261
  let e = null;
266
262
  if (a.isFailed) {
267
263
  const s = l.toLanguageString(
268
264
  ue,
269
- c[ue]
265
+ r[ue]
270
266
  );
271
267
  e = /* @__PURE__ */ t.createElement(
272
268
  W,
@@ -274,11 +270,11 @@ const je = t.forwardRef(
274
270
  fillMode: "clear",
275
271
  size: "xs",
276
272
  className: "k-resend-button",
277
- svgIcon: Ae,
273
+ svgIcon: Re,
278
274
  "aria-label": s,
279
275
  title: s,
280
276
  onClick: (n) => {
281
- n.stopPropagation(), S && S({
277
+ n.stopPropagation(), D && D({
282
278
  message: a,
283
279
  syntheticEvent: n,
284
280
  nativeEvent: n.nativeEvent,
@@ -289,53 +285,72 @@ const je = t.forwardRef(
289
285
  );
290
286
  }
291
287
  return e;
292
- }, [a, l, S]), Ie = t.useCallback(() => O(
288
+ }, [a, l, D]), we = t.useCallback(() => O(
293
289
  {
294
290
  "k-focus": o,
295
291
  "k-message-removed": a.isDeleted,
296
292
  "k-message-failed": a.isFailed
297
293
  },
298
294
  "k-message"
299
- ), [o, a.isDeleted, a.isFailed]), we = t.useCallback(() => b && b.length > 0 && /* @__PURE__ */ t.createElement(Te, { className: "k-chat-message-toolbar", fillMode: "flat", size: "small" }, b.map((e) => e.id === "delete" && !C ? null : /* @__PURE__ */ t.createElement(
300
- W,
295
+ ), [o, a.isDeleted, a.isFailed]), Te = t.useCallback(() => b && b.length > 0 && /* @__PURE__ */ t.createElement(
296
+ he,
301
297
  {
302
- key: e.id,
298
+ className: "k-chat-message-toolbar",
303
299
  fillMode: "flat",
304
- size: "xs",
305
- className: "k-toolbar-button",
306
- icon: e.icon,
307
- svgIcon: e.svgIcon,
308
- onClick: (s) => {
309
- s.stopPropagation(), e.id === "copy" && !a.isDeleted ? v() : e.id === "reply" && E(a), N && N(e, s, a);
310
- },
311
- onMouseDown: (s) => s.preventDefault()
312
- }
313
- ))), [v, C, a, b, N, E]);
300
+ ariaLabel: l.toLanguageString(
301
+ me,
302
+ r[me]
303
+ )
304
+ },
305
+ b.map((e) => e.id === "delete" && !C ? null : /* @__PURE__ */ t.createElement(
306
+ W,
307
+ {
308
+ key: e.id,
309
+ fillMode: "flat",
310
+ className: "k-toolbar-button",
311
+ icon: e.icon,
312
+ svgIcon: e.svgIcon,
313
+ "aria-label": e.label,
314
+ onClick: (s) => {
315
+ s.stopPropagation(), e.id === "copy" && !a.isDeleted ? w() : e.id === "reply" && E(a), M && M(e, s, a);
316
+ },
317
+ onMouseDown: (s) => s.preventDefault()
318
+ }
319
+ ))
320
+ ), [
321
+ w,
322
+ C,
323
+ a,
324
+ l,
325
+ b,
326
+ M,
327
+ E
328
+ ]);
314
329
  return /* @__PURE__ */ t.createElement(
315
330
  "div",
316
331
  {
317
332
  key: a.id,
318
333
  "data-message-id": a.id,
319
- className: Ie(),
320
- tabIndex: de,
321
- onMouseDown: ge,
322
- onKeyDown: be,
334
+ className: we(),
335
+ tabIndex: fe,
336
+ onMouseDown: be,
337
+ onKeyDown: ke,
323
338
  onFocus: (e) => {
324
- pe && p(a.selectionIndex);
339
+ pe && g(a.selectionIndex);
325
340
  },
326
341
  ref: (e) => {
327
342
  V.current = e, typeof d == "function" ? d(e) : d && (d.current = e);
328
343
  },
329
- onContextMenu: f ? L : void 0
344
+ onContextMenu: f ? z : void 0
330
345
  },
331
- ye(),
332
- ke(),
333
- (a.status || a.timestamp && y !== "hidden" || a.isFailed) && /* @__PURE__ */ t.createElement("div", { className: "k-message-info" }, Ee(), Ce(), xe()),
334
- we()
346
+ Ie(),
347
+ Ce(),
348
+ (a.status || a.timestamp && F !== "hidden" || a.isFailed) && /* @__PURE__ */ t.createElement("div", { className: "k-message-info" }, xe(), Ee(), ye()),
349
+ Te()
335
350
  );
336
351
  }
337
352
  );
338
- je.displayName = "ChatMessage";
353
+ We.displayName = "ChatMessage";
339
354
  export {
340
- je as ChatMessage
355
+ We as ChatMessage
341
356
  };
@@ -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 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;
8
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const nt=require("react"),rt=require("../utils.js");function ct(b){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const q in b)if(q!=="default"){const e=Object.getOwnPropertyDescriptor(b,q);Object.defineProperty(n,q,e.get?e:{enumerable:!0,get:()=>b[q]})}}return n.default=b,Object.freeze(n)}const r=ct(nt),ut=50,W=100,lt=({scrollMode:b,processedMessages:n,total:q,pageSize:e=ut,startIndex:N,endIndex:Z,onLoadMoreMessages:u,onReferencedMessageClick:j,viewItemsWrapperRef:l,authorId:Y})=>{const k=r.useRef(!1),m=b==="endless",i=q!=null?q:n.length,E=m&&n.length===i&&!k.current,h=m&&(n.length<i||k.current);h&&(k.current=!0);const[D,B]=r.useState(-1),[x,O]=r.useState(-1),v=r.useRef(D),d=r.useRef(x);v.current=D,d.current=x;const o=r.useRef(!1),P=r.useRef(0),w=r.useRef(0),g=r.useRef(0),y=r.useRef(!1),I=r.useRef(i),C=r.useRef(Y);C.current=Y;const $=r.useRef(!1),G=r.useRef(null),U=r.useRef(!1),J=r.useRef(!1),K=r.useRef(!0),Q=r.useRef(i);r.useEffect(()=>{if(E){if(k.current){(D===-1||x===-1)&&(B(0),O(n.length));return}if(D===-1||x===-1){const t=Math.max(0,n.length-e),c=n.length;B(t),O(c)}else if(x<n.length){const t=I.current;if(d.current>=t)O(n.length);else if(n.length>t&&n.slice(t).some(f=>{var T;return((T=f.author)==null?void 0:T.id)!==void 0&&String(f.author.id)===String(C.current)})){const f=Math.max(0,n.length-e);B(f),O(n.length),U.current=!0}}I.current=i}},[E,n.length,e,D,x,i]);const _=N!=null?N:0,R=Z!=null?Z:n.length,z=r.useCallback(()=>{const t=l.current;t&&(P.current=t.scrollHeight,w.current=t.scrollTop,g.current=t.querySelectorAll("[data-message-id]").length)},[l]),A=r.useCallback(t=>{var a,f,T;const c=(a=l.current)==null?void 0:a.closest(".k-chat"),S=((T=(f=l.current)==null?void 0:f.querySelector(".k-message-pinned"))==null?void 0:T.offsetHeight)||0;rt.scrollToMessageById(t,c,S)},[l]);r.useLayoutEffect(()=>{if(!y.current)return;const t=l.current;if(!t){y.current=!1;return}if(t.querySelectorAll("[data-message-id]").length<=g.current)return;const S=t.scrollHeight-P.current;S>0&&(t.scrollTop=w.current+S),y.current=!1,o.current=!1}),r.useLayoutEffect(()=>{if(!U.current)return;const t=l.current;if(!t){U.current=!1;return}x>=n.length&&x>0&&(U.current=!1,t.scrollTop=t.scrollHeight-t.clientHeight)});const L=r.useRef(!1);r.useLayoutEffect(()=>{if(!m||L.current)return;const t=l.current;t&&t.querySelector("[data-message-id]")&&(t.scrollTop=t.scrollHeight-t.clientHeight,L.current=!0)}),r.useEffect(()=>{if(!m)return;const t=l.current;if(!t)return;let c=t.scrollTop;const S=()=>{const{scrollTop:a,scrollHeight:f,clientHeight:T}=t,X=a<c,tt=a>c;if(c=a,!o.current){if(X&&a<=W){if(E){const H=v.current;if(H>0){const F=Math.max(0,H-e);y.current=!0,z(),B(F),u==null||u({startIndex:F,endIndex:d.current})}}else if(h&&_>0){o.current=!0;const H=Math.max(0,_-e);y.current=!0,z(),u==null||u({startIndex:H,endIndex:R})}}if(tt&&f-a-T<=W){if(E){const H=d.current;if(H<n.length){const F=Math.min(n.length,H+e);J.current=!0,O(F),u==null||u({startIndex:v.current,endIndex:F})}}else if(h&&R<i){o.current=!0,J.current=!0;const H=Math.min(i,R+e);u==null||u({startIndex:_,endIndex:H})}}}};return t.addEventListener("scroll",S,{passive:!0}),()=>t.removeEventListener("scroll",S)},[m,E,h,l,e,n.length,_,R,i,u]),r.useEffect(()=>{var a;const t=R>=i;if(!h){Q.current=i,K.current=t;return}const c=Q.current,S=K.current;if(Q.current=i,K.current=t,i>c&&!S&&t){const f=n[n.length-1];C.current!==void 0&&((a=f==null?void 0:f.author)==null?void 0:a.id)!==void 0&&String(f.author.id)===String(C.current)&&($.current=!0,J.current=!0)}},[h,i,R,n]),r.useEffect(()=>{!h||!$.current||($.current=!1,o.current=!1,requestAnimationFrame(()=>{const t=l.current;t&&(t.scrollTop=t.scrollHeight-t.clientHeight)}))},[h,n,l]),r.useEffect(()=>{if(!h||G.current===null)return;const t=G.current,c=l.current;if(!c)return;c.querySelector(`[data-message-id="${t}"]`)&&(G.current=null,o.current=!1,requestAnimationFrame(()=>{A(t)}))},[h,n,l,A]),r.useEffect(()=>{h&&o.current&&!y.current&&(o.current=!1)},[h,_,R]);const s=r.useMemo(()=>{if(E){const t=Math.max(0,D),c=Math.min(n.length,x);if(t>=c){const S=Math.max(0,n.length-e);return n.slice(S)}return n.slice(t,c)}return n},[E,n,D,x,e]),V=r.useMemo(()=>m?E?x>=n.length:R>=i:!0,[m,E,x,n.length,R,i]),p=r.useCallback(()=>{if(!m||V){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-e);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){$.current=!0,y.current=!1,o.current=!0;const t=Math.max(0,i-e);u==null||u({startIndex:t,endIndex:i})}}},[m,E,h,V,n.length,e,i,u,l]),M=r.useCallback(t=>{if(!m)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 a=n.findIndex(f=>f.id===t||String(f.id)===String(t));if(a>=0){const f=Math.floor(e/2),T=Math.max(0,a-f),X=Math.min(n.length,T+e);o.current=!0,B(T),O(X),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;G.current=t,y.current=!1,o.current=!0}}j==null||j({id:t})},[m,E,h,l,n,e,j,A]);return{renderedMessages:s,handleScrollToBottom:p,handleReferencedMessageClick:M,isEndless:m,isOnLastBatch:V,skipAutoScrollRef:J}};exports.useEndlessScroll=lt;