@progress/kendo-react-conversational-ui 14.4.1-develop.9 → 14.5.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.
@@ -6,9 +6,9 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import { SVGIcon } from '@progress/kendo-react-common';
9
- import { Action } from './action.interface.js';
10
- import { Attachment, AttachmentLayout } from './attachment.interface.js';
11
- import { User } from './user.interface.js';
9
+ import { Action } from './action.interface';
10
+ import { Attachment, AttachmentLayout } from './attachment.interface';
11
+ import { User } from './user.interface';
12
12
  /**
13
13
  * Configuration for message status display with optional icon.
14
14
  */
@@ -6,11 +6,11 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import { Message, ChatActionExecuteEvent, ChatSendMessageEvent, ChatResendMessageEvent, PromptBoxMode } from '../index.js';
9
- import { ChatLoadMoreMessagesEvent, ChatReferencedMessageClickEvent } from './Events.js';
9
+ import { ChatLoadMoreMessagesEvent, ChatReferencedMessageClickEvent } from './Events';
10
10
  import { ChatMessageProps, ChatMessageTemplateProps, FileAction, MessageAction } from './components/ChatMessage.js';
11
11
  import { ChatSuggestion, SuggestionTemplateProps } from './components/SuggestionsGroup.js';
12
12
  import { ButtonProps, SpeechToTextButtonProps } from '@progress/kendo-react-buttons';
13
- import { UploadButtonProps } from '../prompt-box/interfaces/PromptBoxProps.js';
13
+ import { UploadButtonProps } from '../prompt-box/interfaces/PromptBoxProps';
14
14
  import { DateMarker } from './ViewItem.js';
15
15
  /**
16
16
  * Represents the properties available to the `statusTemplate` custom component.
@@ -666,8 +666,7 @@ export interface ChatProps extends FieldMappingConfig {
666
666
  /**
667
667
  * The total number of messages in the conversation.
668
668
  * Used to determine the mode: when `messages.length === total`, the Chat manages rendering
669
- * internally (built-in mode); when `messages.length < total`, the Chat fires `onLoadMoreMessages`
670
- * for the consumer to fetch data (remote mode).
669
+ * internally (built-in mode); when `messages.length < total`, the consumer manages data (remote mode).
671
670
  */
672
671
  total?: number;
673
672
  /**
@@ -687,8 +686,11 @@ export interface ChatProps extends FieldMappingConfig {
687
686
  */
688
687
  endIndex?: number;
689
688
  /**
690
- * Fires only in remote mode (`messages.length < total`) when the user scrolls near the edge
689
+ * Fires in both built-in and remote endless scroll modes when the user scrolls near the edge
691
690
  * of the rendered message window.
691
+ * In built-in mode, the Chat manages rendering internally and this callback is informational.
692
+ * In remote mode (`messages.length < total`), the consumer must provide the requested range.
693
+ * The event contains the full range that should be rendered (not just the delta).
692
694
  */
693
695
  onLoadMoreMessages?: (event: ChatLoadMoreMessagesEvent) => void;
694
696
  /**
package/chat/Events.d.ts CHANGED
@@ -59,13 +59,13 @@ export interface ChatToolbarActionExecuteEvent extends BaseEvent<React.Component
59
59
  }
60
60
  /**
61
61
  * Arguments for the `onLoadMoreMessages` event of the Chat.
62
- * Fires in remote mode (`messages.length < total`) when the user scrolls near the edge
62
+ * Fires in endless scroll mode when the user scrolls near the edge
63
63
  * of the rendered message window.
64
64
  */
65
65
  export interface ChatLoadMoreMessagesEvent {
66
- /** The start index of the requested message range (inclusive). */
66
+ /** The start index of the full message range that should be rendered (inclusive). */
67
67
  startIndex: number;
68
- /** The end index of the requested message range (exclusive). */
68
+ /** The end index of the full message range that should be rendered (exclusive). */
69
69
  endIndex: number;
70
70
  }
71
71
  /**
@@ -6,7 +6,7 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import { ActionGroup as ActionGroupModel } from '../ViewItem.js';
9
- import { QuickActionsLayoutMode } from '../ChatPropsAndState.js';
9
+ import { QuickActionsLayoutMode } from '../ChatPropsAndState';
10
10
  import * as React from 'react';
11
11
  /**
12
12
  * @hidden
@@ -5,7 +5,7 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { ChatProps } from '../ChatPropsAndState.js';
8
+ import { ChatProps } from '../ChatPropsAndState';
9
9
  import * as React from 'react';
10
10
  /**
11
11
  * Represents the [KendoReact Chat component](https://www.telerik.com/kendo-react-ui/components/conversational-ui).
@@ -5,13 +5,13 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { Message } from '../../api/message.interface.js';
9
- import { User } from '../../api/user.interface.js';
8
+ import { Message } from '../../api/message.interface';
9
+ import { User } from '../../api/user.interface';
10
10
  import { FileAction, MessageAction } from './ChatMessage.js';
11
- import { StatusTemplateProps, UserStatusTemplateProps, ChatFile, FilesLayoutMode, TimestampVisibilityMode } from '../ChatPropsAndState.js';
11
+ import { StatusTemplateProps, UserStatusTemplateProps, ChatFile, FilesLayoutMode, TimestampVisibilityMode } from '../ChatPropsAndState';
12
12
  import { SpeechToTextButtonProps } from '@progress/kendo-react-buttons';
13
- import { UploadButtonProps } from '../../prompt-box/interfaces/PromptBoxProps.js';
14
- import { ChatResendMessageEvent } from '../Events.js';
13
+ import { UploadButtonProps } from '../../prompt-box/interfaces/PromptBoxProps';
14
+ import { ChatResendMessageEvent } from '../Events';
15
15
  import * as React from 'react';
16
16
  /**
17
17
  * @hidden
@@ -5,11 +5,11 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { ChatMessageBoxProps, MessageBoxSettings } from '../ChatPropsAndState.js';
8
+ import { ChatMessageBoxProps, MessageBoxSettings } from '../ChatPropsAndState';
9
9
  import { MessageAction, FileAction } from './ChatMessage.js';
10
10
  import { ButtonProps } from '@progress/kendo-react-buttons';
11
11
  import { ChatSuggestion, SuggestionTemplateProps } from './SuggestionsGroup.js';
12
- import { Message } from '../../api/message.interface.js';
12
+ import { Message } from '../../api/message.interface';
13
13
  import * as React from 'react';
14
14
  /**
15
15
  * @hidden
@@ -5,7 +5,7 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { SuggestionsLayoutMode } from '../ChatPropsAndState.js';
8
+ import { SuggestionsLayoutMode } from '../ChatPropsAndState';
9
9
  import * as React from 'react';
10
10
  /**
11
11
  * Represents the rendering options for suggestions in the AI Prompt component.
@@ -5,9 +5,9 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { Message } from '../../api/message.interface.js';
9
- import { ChatLoadMoreMessagesEvent, ChatReferencedMessageClickEvent } from '../Events.js';
10
- import { ScrollMode } from '../ChatPropsAndState.js';
8
+ import { Message } from '../../api/message.interface';
9
+ import { ChatLoadMoreMessagesEvent, ChatReferencedMessageClickEvent } from '../Events';
10
+ import { ScrollMode } from '../ChatPropsAndState';
11
11
  import * as React from 'react';
12
12
  /** @hidden */
13
13
  export interface UseEndlessScrollProps {
@@ -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 {
@@ -5,8 +5,8 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { Message } from '../../api/message.interface.js';
9
- import { FieldMappingConfig } from '../ChatPropsAndState.js';
8
+ import { Message } from '../../api/message.interface';
9
+ import { FieldMappingConfig } from '../ChatPropsAndState';
10
10
  /**
11
11
  * Default field mapping configuration.
12
12
  * These are the standard field names expected by the Chat component.