@progress/kendo-react-conversational-ui 14.3.3-develop.2 → 14.4.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.
@@ -13,19 +13,19 @@ import { xMarkSmOutlineIcon as ae } from "@progress/kendo-svg-icons";
13
13
  import { useChatContext as re } from "./ChatContext.mjs";
14
14
  import { useLocalization as le } from "@progress/kendo-react-intl";
15
15
  import { getDeletedMessageText as ce, isAuthor as se } from "../utils.mjs";
16
- import { closeReply as y, messages as l, chatStopGenerating as E, newMessageSendButton as w, newMessageMessageInput as X, attachFile as L } from "../../messages/index.mjs";
17
- import { PromptBoxUploadButton as ue } from "../../prompt-box/PromptBoxUploadButton.mjs";
18
- import { PromptBox as ie } from "../../prompt-box/PromptBox.mjs";
16
+ import { closeReply as y, messages as l, chatStopGenerating as w, newMessageSendButton as E, newMessageMessageInput as X, attachFile as L } from "../../messages/index.mjs";
17
+ import { PromptBoxUploadButton as ie } from "../../prompt-box/PromptBoxUploadButton.mjs";
18
+ import { PromptBox as ue } from "../../prompt-box/PromptBox.mjs";
19
19
  const Y = t.memo(
20
- ({ affixProps: R, uploadConfig: p, localizationService: s, onFilesSelect: g, onFileRemove: C }) => {
20
+ ({ affixProps: R, uploadConfig: p, localizationService: c, onFilesSelect: g, onFileRemove: C }) => {
21
21
  const A = typeof p == "object" ? p : {};
22
22
  return p !== !1 ? /* @__PURE__ */ t.createElement(
23
- ue,
23
+ ie,
24
24
  {
25
25
  ...R.uploadButtonProps,
26
26
  fillMode: "clear",
27
- "aria-label": s.toLanguageString(L, l[L]),
28
- title: s.toLanguageString(L, l[L]),
27
+ "aria-label": c.toLanguageString(L, l[L]),
28
+ title: c.toLanguageString(L, l[L]),
29
29
  ...A,
30
30
  onSelectAttachments: g,
31
31
  onRemoveAttachment: C
@@ -36,14 +36,14 @@ const Y = t.memo(
36
36
  Y.displayName = "UploadButtonAffix";
37
37
  const fe = t.forwardRef((R, p) => {
38
38
  const {
39
- onSendMessage: s,
39
+ onSendMessage: c,
40
40
  isDirectionRightToLeft: g,
41
41
  placeholder: C,
42
42
  MessageBox: A,
43
43
  suggestions: h,
44
44
  onSuggestionClick: Z,
45
- inputValue: F,
46
- onInputValueChange: u,
45
+ inputValue: N,
46
+ onInputValueChange: s,
47
47
  suggestionTemplate: _,
48
48
  sendButtonConfig: k,
49
49
  onInputClick: P,
@@ -51,15 +51,15 @@ const fe = t.forwardRef((R, p) => {
51
51
  dir: B,
52
52
  messageBoxSettings: e,
53
53
  loading: b
54
- } = R, { replyToMessage: r, setReplyToMessage: v, user: x, speechToTextConfig: V, uploadConfig: D } = re(), [ee, U] = t.useState(""), [M, I] = t.useState([]), N = t.useRef(null), o = le(), d = F !== void 0, T = d ? F : ee, c = t.useCallback(() => {
55
- N.current !== null && N.current.focus();
54
+ } = R, { replyToMessage: r, setReplyToMessage: v, user: x, speechToTextConfig: V, uploadConfig: D } = re(), [ee, U] = t.useState(""), [M, F] = t.useState([]), I = t.useRef(null), o = le(), d = N !== void 0, T = d ? N : ee, i = t.useCallback(() => {
55
+ I.current !== null && I.current.focus();
56
56
  }, []);
57
57
  t.useEffect(() => {
58
- r && c();
59
- }, [r, c]);
58
+ r && i();
59
+ }, [r, i]);
60
60
  const z = t.useCallback(
61
61
  (n) => {
62
- if (n.preventDefault(), s) {
62
+ if (n.preventDefault(), c) {
63
63
  const m = {
64
64
  id: "",
65
65
  author: x,
@@ -73,30 +73,30 @@ const fe = t.forwardRef((R, p) => {
73
73
  rawFile: f.getRawFile ? f.getRawFile() : f
74
74
  }))
75
75
  };
76
- v(null), s(m, n), I([]), d || U(""), u && u(""), c();
76
+ v(null), c(m, n), F([]), d || U(""), s && s(""), i();
77
77
  }
78
78
  },
79
79
  [
80
- s,
80
+ c,
81
81
  T,
82
82
  x,
83
83
  r,
84
84
  M,
85
85
  v,
86
- u,
87
- c,
86
+ s,
87
+ i,
88
88
  d
89
89
  ]
90
90
  );
91
91
  t.useImperativeHandle(
92
92
  p,
93
93
  () => ({
94
- focusInput: c
94
+ focusInput: i
95
95
  }),
96
- [c]
96
+ [i]
97
97
  );
98
98
  const H = t.useCallback((n) => {
99
- I((a) => a.filter((m) => m.name !== n));
99
+ F((a) => a.filter((m) => m.name !== n));
100
100
  }, []), S = t.useCallback(
101
101
  (n, a) => n.isDeleted ? ce(a, o) : n.text,
102
102
  [o]
@@ -129,25 +129,21 @@ const fe = t.forwardRef((R, p) => {
129
129
  }, [r, x, S, v, o]), G = t.useCallback((n) => {
130
130
  try {
131
131
  const a = Array.from(n.allFiles);
132
- I(a);
132
+ F(a);
133
133
  } catch {
134
134
  }
135
- }, []);
136
- t.useEffect(() => {
137
- c();
138
- }, [F, c]);
139
- const O = t.useCallback(
135
+ }, []), O = t.useCallback(
140
136
  (n) => {
141
137
  const a = n.value;
142
- d || U(a), u && u(a || "");
138
+ d || U(a), s && s(a || "");
143
139
  },
144
- [d, u]
140
+ [d, s]
145
141
  ), q = t.useCallback(
146
142
  (n) => {
147
143
  z(n.syntheticEvent);
148
144
  },
149
145
  [z]
150
- ), i = t.useCallback((n) => n ? typeof n == "function" ? n() : n : null, []), J = t.useCallback(
146
+ ), u = t.useCallback((n) => n ? typeof n == "function" ? n() : n : null, []), J = t.useCallback(
151
147
  (n) => /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement(
152
148
  Y,
153
149
  {
@@ -157,33 +153,33 @@ const fe = t.forwardRef((R, p) => {
157
153
  onFilesSelect: G,
158
154
  onFileRemove: H
159
155
  }
160
- ), i(e == null ? void 0 : e.startAffix)),
156
+ ), u(e == null ? void 0 : e.startAffix)),
161
157
  [
162
158
  D,
163
159
  o,
164
160
  G,
165
161
  H,
166
162
  e == null ? void 0 : e.startAffix,
167
- i
163
+ u
168
164
  ]
169
165
  ), K = t.useCallback(
170
- () => i(e == null ? void 0 : e.endAffix),
171
- [e == null ? void 0 : e.endAffix, i]
166
+ () => u(e == null ? void 0 : e.endAffix),
167
+ [e == null ? void 0 : e.endAffix, u]
172
168
  ), Q = t.useCallback(
173
- () => i(e == null ? void 0 : e.topAffix),
174
- [e == null ? void 0 : e.topAffix, i]
169
+ () => u(e == null ? void 0 : e.topAffix),
170
+ [e == null ? void 0 : e.topAffix, u]
175
171
  ), W = t.useMemo(() => {
176
172
  const n = typeof k == "object" ? k : {}, m = k !== !1 ? {
177
- "aria-label": b ? o.toLanguageString(E, l[E]) : o.toLanguageString(w, l[w]),
178
- title: b ? o.toLanguageString(E, l[E]) : o.toLanguageString(w, l[w]),
173
+ "aria-label": b ? o.toLanguageString(w, l[w]) : o.toLanguageString(E, l[E]),
174
+ title: b ? o.toLanguageString(w, l[w]) : o.toLanguageString(E, l[E]),
179
175
  dir: g ? "rtl" : void 0,
180
176
  ...n
181
177
  } : !1;
182
178
  return /* @__PURE__ */ t.createElement(
183
- ie,
179
+ ue,
184
180
  {
185
181
  header: j(),
186
- ref: N,
182
+ ref: I,
187
183
  placeholder: C,
188
184
  value: T,
189
185
  onChange: O,
@@ -14,6 +14,7 @@ interface PinnedMessageProps {
14
14
  message: Message;
15
15
  onUnpin?: (message: Message) => void;
16
16
  user?: User;
17
+ onReferencedMessageClick?: (messageId: string | number) => void;
17
18
  }
18
19
  /**
19
20
  * @hidden
@@ -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 k=require("react"),C=require("@progress/kendo-react-common"),M=require("@progress/kendo-react-buttons"),u=require("@progress/kendo-svg-icons"),h=require("@progress/kendo-react-intl"),a=require("../../utils.js"),v=require("../ChatContext.js");function b(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const c=b(k),q=n=>{const{message:e,onUnpin:t,user:s}=n,d=h.useLocalization(),{internalScrollContainerRef:r}=v.useChatContext(),i=c.useRef(null),f=s&&a.isAuthor(s,e),g=c.useCallback(o=>{var l;o.preventDefault(),o.stopPropagation();const p=r==null?void 0:r.current,m=((l=i.current)==null?void 0:l.offsetHeight)||0;a.scrollToMessageById(e.id,p,m)},[e.id,r]);return c.createElement("div",{ref:i,className:`k-message-reference ${f?"k-message-reference-sender":"k-message-reference-receiver"} k-message-pinned`,onClick:g},c.createElement(C.IconWrap,{icon:u.pinOutlineIcon}),c.createElement("div",{className:"k-message-reference-content"},e!=null&&e.isDeleted?s&&a.getDeletedMessageText(a.isAuthor(s,e),d):e==null?void 0:e.text),c.createElement("span",{className:"k-spacer"}),c.createElement(M.Button,{fillMode:"flat",svgIcon:u.xMarkSmOutlineIcon,onClick:o=>{o.stopPropagation(),t==null||t(e)}}))};module.exports=q;
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;
@@ -6,44 +6,40 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import * as t from "react";
9
- import { IconWrap as g } from "@progress/kendo-react-common";
10
- import { Button as k } from "@progress/kendo-react-buttons";
11
- import { pinOutlineIcon as M, xMarkSmOutlineIcon as h } from "@progress/kendo-svg-icons";
12
- import { useLocalization as v } from "@progress/kendo-react-intl";
13
- import { isAuthor as i, scrollToMessageById as C, getDeletedMessageText as x } from "../../utils.mjs";
14
- import { useChatContext as E } from "../ChatContext.mjs";
15
- const H = (l) => {
16
- const { message: e, onUnpin: r, user: n } = l, m = v(), { internalScrollContainerRef: s } = E(), a = t.useRef(null), f = n && i(n, e), p = t.useCallback(
9
+ import { IconWrap as f } from "@progress/kendo-react-common";
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(
17
16
  (o) => {
18
- var c;
19
- o.preventDefault(), o.stopPropagation();
20
- const d = s == null ? void 0 : s.current, u = ((c = a.current) == null ? void 0 : c.offsetHeight) || 0;
21
- C(e.id, d, u);
17
+ o.preventDefault(), o.stopPropagation(), r == null || r(e.id);
22
18
  },
23
- [e.id, s]
19
+ [e.id, r]
24
20
  );
25
21
  return /* @__PURE__ */ t.createElement(
26
22
  "div",
27
23
  {
28
- ref: a,
29
- className: `k-message-reference ${f ? "k-message-reference-sender" : "k-message-reference-receiver"} k-message-pinned`,
24
+ ref: l,
25
+ className: `k-message-reference ${m ? "k-message-reference-sender" : "k-message-reference-receiver"} k-message-pinned`,
30
26
  onClick: p
31
27
  },
32
- /* @__PURE__ */ t.createElement(g, { icon: M }),
33
- /* @__PURE__ */ t.createElement("div", { className: "k-message-reference-content" }, e != null && e.isDeleted ? n && x(i(n, e), m) : e == null ? void 0 : e.text),
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),
34
30
  /* @__PURE__ */ t.createElement("span", { className: "k-spacer" }),
35
31
  /* @__PURE__ */ t.createElement(
36
- k,
32
+ d,
37
33
  {
38
34
  fillMode: "flat",
39
- svgIcon: h,
35
+ svgIcon: k,
40
36
  onClick: (o) => {
41
- o.stopPropagation(), r == null || r(e);
37
+ o.stopPropagation(), a == null || a(e);
42
38
  }
43
39
  }
44
40
  )
45
41
  );
46
42
  };
47
43
  export {
48
- H as default
44
+ C as default
49
45
  };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ *-------------------------------------------------------------------------------------------
4
+ * Copyright © 2026 Progress Software Corporation. All rights reserved.
5
+ * Licensed under commercial license. See LICENSE.md in the package root for more information
6
+ *-------------------------------------------------------------------------------------------
7
+ */
8
+ import { Message } from '../../api/message.interface.js';
9
+ import { ChatLoadMoreMessagesEvent, ChatReferencedMessageClickEvent } from '../Events.js';
10
+ import { ScrollMode } from '../ChatPropsAndState.js';
11
+ import * as React from 'react';
12
+ /** @hidden */
13
+ export interface UseEndlessScrollProps {
14
+ scrollMode?: ScrollMode;
15
+ processedMessages: Message[];
16
+ total?: number;
17
+ pageSize?: number;
18
+ startIndex?: number;
19
+ endIndex?: number;
20
+ onLoadMoreMessages?: (event: ChatLoadMoreMessagesEvent) => void;
21
+ onReferencedMessageClick?: (event: ChatReferencedMessageClickEvent) => void;
22
+ viewItemsWrapperRef: React.RefObject<HTMLDivElement | null>;
23
+ authorId?: string | number;
24
+ }
25
+ /** @hidden */
26
+ export interface UseEndlessScrollReturn {
27
+ /** The messages that should actually be rendered in the DOM. */
28
+ renderedMessages: Message[];
29
+ /** Handler for scroll-to-bottom button click in endless mode. */
30
+ handleScrollToBottom: () => void;
31
+ /** Handler for referenced message (pin) click. Works for both modes. */
32
+ handleReferencedMessageClick: (messageId: string | number) => void;
33
+ /** Whether endless scroll mode is active. */
34
+ isEndless: boolean;
35
+ /** Whether the newest messages are currently in the rendered DOM. */
36
+ isOnLastBatch: boolean;
37
+ /** Ref that signals useMessageAutoScroll to skip the next auto-scroll.
38
+ * Set when the rendered window extends downward via scroll-loading. */
39
+ skipAutoScrollRef: React.RefObject<boolean>;
40
+ }
41
+ /**
42
+ * Hook that manages the endless scroll behavior for the Chat component.
43
+ *
44
+ * Built-in mode: messages.length === total — Chat manages rendering internally.
45
+ * Remote mode: messages.length < total — Chat fires onLoadMoreMessages, consumer manages data.
46
+ *
47
+ * @hidden
48
+ */
49
+ export declare const useEndlessScroll: ({ scrollMode, processedMessages, total, pageSize, startIndex: startIndexProp, endIndex: endIndexProp, onLoadMoreMessages, onReferencedMessageClick, viewItemsWrapperRef, authorId }: UseEndlessScrollProps) => UseEndlessScrollReturn;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ *-------------------------------------------------------------------------------------------
4
+ * Copyright © 2026 Progress Software Corporation. All rights reserved.
5
+ * Licensed under commercial license. See LICENSE.md in the package root for more information
6
+ *-------------------------------------------------------------------------------------------
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;
@@ -0,0 +1,267 @@
1
+ /**
2
+ * @license
3
+ *-------------------------------------------------------------------------------------------
4
+ * Copyright © 2026 Progress Software Corporation. All rights reserved.
5
+ * Licensed under commercial license. See LICENSE.md in the package root for more information
6
+ *-------------------------------------------------------------------------------------------
7
+ */
8
+ import * as r from "react";
9
+ import { scrollToMessageById as tt } from "../utils.mjs";
10
+ const nt = 50, s = 100, ct = ({
11
+ scrollMode: I,
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
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);
29
+ r.useEffect(() => {
30
+ if (a) {
31
+ if (F.current) {
32
+ (D === -1 || S === -1) && (B(0), A(n.length));
33
+ return;
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);
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);
46
+ }
47
+ )) {
48
+ const e = Math.max(0, n.length - i);
49
+ B(e), A(n.length), G.current = !0;
50
+ }
51
+ }
52
+ g.current = l;
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(
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);
63
+ },
64
+ [u]
65
+ );
66
+ r.useLayoutEffect(() => {
67
+ if (!q.current)
68
+ return;
69
+ const t = u.current;
70
+ if (!t) {
71
+ q.current = !1;
72
+ return;
73
+ }
74
+ const c = t.scrollHeight - L.current;
75
+ c > 0 && (t.scrollTop = v.current + c), q.current = !1, o.current = !1;
76
+ }), r.useLayoutEffect(() => {
77
+ if (!G.current)
78
+ return;
79
+ const t = u.current;
80
+ if (!t) {
81
+ G.current = !1;
82
+ return;
83
+ }
84
+ S >= n.length && S > 0 && (G.current = !1, t.scrollTop = t.scrollHeight - t.clientHeight);
85
+ });
86
+ const w = r.useRef(!1);
87
+ r.useLayoutEffect(() => {
88
+ if (!E || w.current)
89
+ return;
90
+ const t = u.current;
91
+ t && t.querySelector("[data-message-id]") && (t.scrollTop = t.scrollHeight - t.clientHeight, w.current = !0);
92
+ }), r.useEffect(() => {
93
+ if (!E)
94
+ return;
95
+ const t = u.current;
96
+ if (!t)
97
+ return;
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);
108
+ }
109
+ } else if (f && O > 0) {
110
+ o.current = !0;
111
+ const R = Math.max(0, O - i);
112
+ q.current = !0, P(), T == null || T({ startIndex: R, endIndex: O });
113
+ }
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);
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 });
126
+ }
127
+ }
128
+ }
129
+ };
130
+ return t.addEventListener("scroll", m, { passive: !0 }), () => t.removeEventListener("scroll", m);
131
+ }, [
132
+ E,
133
+ a,
134
+ f,
135
+ u,
136
+ i,
137
+ n.length,
138
+ O,
139
+ H,
140
+ l,
141
+ T
142
+ ]), r.useEffect(() => {
143
+ var h;
144
+ const t = H >= l;
145
+ if (!f) {
146
+ N.current = l, K.current = t;
147
+ return;
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);
153
+ }
154
+ }, [f, l, H, n]), r.useEffect(() => {
155
+ !f || !_.current || (_.current = !1, o.current = !1, requestAnimationFrame(() => {
156
+ const t = u.current;
157
+ t && (t.scrollTop = t.scrollHeight - t.clientHeight);
158
+ }));
159
+ }, [f, n, u]), r.useEffect(() => {
160
+ if (!f || $.current === null)
161
+ return;
162
+ const t = $.current, c = u.current;
163
+ if (!c)
164
+ return;
165
+ c.querySelector(`[data-message-id="${t}"]`) && ($.current = null, o.current = !1, requestAnimationFrame(() => {
166
+ y(t);
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);
174
+ if (t >= c) {
175
+ const m = Math.max(0, n.length - i);
176
+ return n.slice(m);
177
+ }
178
+ return n.slice(t, c);
179
+ }
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;
184
+ t && t.scrollTo({ top: t.scrollHeight - t.clientHeight, behavior: "smooth" });
185
+ return;
186
+ }
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;
192
+ c && (c.scrollTop = c.scrollHeight - c.clientHeight);
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 });
198
+ }
199
+ }
200
+ }, [
201
+ E,
202
+ a,
203
+ f,
204
+ Q,
205
+ n.length,
206
+ i,
207
+ l,
208
+ T,
209
+ u
210
+ ]), M = r.useCallback(
211
+ (t) => {
212
+ if (!E)
213
+ y(t);
214
+ else if (a) {
215
+ const c = u.current;
216
+ if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
217
+ y(t);
218
+ else {
219
+ if (o.current)
220
+ return;
221
+ const h = n.findIndex(
222
+ (e) => e.id === t || String(e.id) === String(t)
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(() => {
227
+ requestAnimationFrame(() => {
228
+ y(t), o.current = !1;
229
+ });
230
+ });
231
+ }
232
+ }
233
+ } else if (f) {
234
+ const c = u.current;
235
+ if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
236
+ y(t);
237
+ else {
238
+ if (o.current)
239
+ return;
240
+ $.current = t, q.current = !1, o.current = !0;
241
+ }
242
+ }
243
+ b == null || b({ id: t });
244
+ },
245
+ [
246
+ E,
247
+ a,
248
+ f,
249
+ u,
250
+ n,
251
+ i,
252
+ b,
253
+ y
254
+ ]
255
+ );
256
+ return {
257
+ renderedMessages: z,
258
+ handleScrollToBottom: W,
259
+ handleReferencedMessageClick: M,
260
+ isEndless: E,
261
+ isOnLastBatch: Q,
262
+ skipAutoScrollRef: U
263
+ };
264
+ };
265
+ export {
266
+ ct as useEndlessScroll
267
+ };
@@ -10,12 +10,15 @@ import * as React from 'react';
10
10
  /** @hidden */
11
11
  type AutoScrollThresholdValue = number | string;
12
12
  /** @hidden */
13
- interface UseChatScrollProps {
13
+ interface UseMessageAutoScrollProps {
14
14
  viewItemsWrapperRef: React.RefObject<HTMLDivElement | null>;
15
15
  isKeyboardNavigationActiveRef: React.RefObject<boolean>;
16
16
  processedMessages: Message[];
17
17
  authorId?: AutoScrollThresholdValue;
18
18
  autoScrollThreshold?: AutoScrollThresholdValue;
19
+ isEndless?: boolean;
20
+ isOnLastBatch?: boolean;
21
+ skipAutoScrollRef?: React.RefObject<boolean>;
19
22
  }
20
23
  /**
21
24
  * New-message detection is based on the **last message's `id`** rather than
@@ -25,7 +28,7 @@ interface UseChatScrollProps {
25
28
  *
26
29
  * @hidden
27
30
  */
28
- export declare const useChatScroll: ({ viewItemsWrapperRef, isKeyboardNavigationActiveRef, processedMessages, authorId, autoScrollThreshold }: UseChatScrollProps) => void;
31
+ export declare const useMessageAutoScroll: ({ viewItemsWrapperRef, isKeyboardNavigationActiveRef, processedMessages, authorId, autoScrollThreshold, isEndless, isOnLastBatch, skipAutoScrollRef }: UseMessageAutoScrollProps) => void;
29
32
  interface UseHasScrollbarProps {
30
33
  elementRef: React.RefObject<HTMLElement | null>;
31
34
  }
@@ -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 B=require("react");function P(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const c=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,c.get?c:{enumerable:!0,get:()=>t[n]})}}return r.default=t,Object.freeze(r)}const s=P(B),j=250,I=100,z="20%",U=t=>{const r=t.querySelector(".k-message-pinned");return r?r.offsetHeight:0},w=(t,r)=>{const n=t!=null?t:z;let c;if(typeof n=="number")c=n;else{const l=/^(-?\d+(?:\.\d+)?)%$/.exec(String(n));if(l)c=Number.parseFloat(l[1])/100*r;else{const u=Number.parseFloat(String(n));c=Number.isNaN(u)?.2*r:u}}return Math.min(c,r)},V=t=>{const{scrollHeight:r,scrollTop:n,clientHeight:c}=t;return!(r>c)||r-n-c<=I},v=t=>{t.scrollTop=t.scrollHeight-t.clientHeight},Y=t=>{const r=t.querySelectorAll(".k-message");return r.length>0?r[r.length-1]:null},$=({viewItemsWrapperRef:t,isKeyboardNavigationActiveRef:r,processedMessages:n,authorId:c,autoScrollThreshold:l})=>{var E;const u=s.useRef(c),h=s.useRef(l);s.useEffect(()=>{u.current=c}),s.useEffect(()=>{h.current=l}),s.useEffect(()=>{const e=globalThis.setTimeout(()=>{t.current&&v(t.current)},j);return()=>clearTimeout(e)},[t]);const H=s.useRef(void 0),L=s.useRef(0),M=s.useRef(!0),R=s.useRef(!0),a=s.useRef(!1),f=s.useRef(null),F=(n.length>0?(E=n.at(-1))==null?void 0:E.id:void 0)!==H.current,N=n.length>L.current;if(F||N){const e=t.current;R.current=e?V(e):!0}s.useEffect(()=>{var A,D;const e=n.length,b=e>0?(A=n[e-1])==null?void 0:A.id:void 0,p=H.current,d=L.current,S=M.current;if(H.current=b,L.current=e,M.current=!1,e===0)return;const o=t.current;if(!o||r.current)return;if(!(!S&&b!==p)){(S||e>d)&&(v(o),a.current=!1,f.current=null);return}const i=n[e-1];if(u.current!==void 0&&((D=i==null?void 0:i.author)==null?void 0:D.id)!==void 0&&String(i.author.id)===String(u.current)){v(o),a.current=!1,f.current=null;return}if(!R.current){a.current=!1,f.current=null;return}const m=Y(o);if(!m)return;const T=U(o),x=Math.max(0,o.clientHeight-T),y=w(h.current,x),k=m.getBoundingClientRect().top-o.getBoundingClientRect().top+o.scrollTop,C=Math.max(0,k-y-T),q=Math.max(0,o.scrollHeight-o.clientHeight),_=Math.min(C,q);_>o.scrollTop&&o.scrollTo({top:_,behavior:"smooth"}),f.current=C,a.current=!0},[n,t,r]),s.useEffect(()=>{const e=t.current;if(!e)return;let b=e.querySelectorAll(".k-message").length,p=e.scrollHeight,d=e.scrollTop;const S=()=>{const g=e.scrollTop;a.current&&g<d&&(a.current=!1,f.current=null),d=g},o=new MutationObserver(()=>{if(r.current)return;const g=e.querySelectorAll(".k-message").length,i=e.scrollHeight;if(g===b&&i>p&&a.current){const O=i-e.clientHeight,m=f.current,T=m===null?O:Math.min(O,m);T>e.scrollTop&&(e.scrollTop=T),d=e.scrollTop}b=g,p=i});return o.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener("scroll",S,{passive:!0}),()=>{o.disconnect(),e.removeEventListener("scroll",S)}},[t,r])},G=({elementRef:t})=>{const[r,n]=s.useState(!1);return s.useEffect(()=>{const c=t.current;if(!c)return;const l=()=>{n(c.scrollHeight>c.clientHeight)};l();const u=new ResizeObserver(l);u.observe(c);const h=new MutationObserver(()=>{requestAnimationFrame(l)});return h.observe(c,{childList:!0,subtree:!0,characterData:!0}),()=>{u.disconnect(),h.disconnect()}},[t]),r};exports.useChatScroll=$;exports.useHasScrollbar=G;
8
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("react");function V(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const c=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,c.get?c:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const s=V(I),$=100,G="20%",J=t=>{const e=t.querySelector(".k-message-pinned");return e?e.offsetHeight:0},Q=(t,e)=>{const n=t!=null?t:G;let c;if(typeof n=="number")c=n;else{const l=/^(-?\d+(?:\.\d+)?)%$/.exec(String(n));if(l)c=Number.parseFloat(l[1])/100*e;else{const u=Number.parseFloat(String(n));c=Number.isNaN(u)?.2*e:u}}return Math.min(c,e)},X=t=>{const{scrollHeight:e,scrollTop:n,clientHeight:c}=t;return!(e>c)||e-n-c<=$},P=t=>{t.scrollTop=t.scrollHeight-t.clientHeight},Y=t=>{const e=t.querySelectorAll(".k-message");return e.length>0?e[e.length-1]:null},Z=({viewItemsWrapperRef:t,isKeyboardNavigationActiveRef:e,processedMessages:n,authorId:c,autoScrollThreshold:l,isEndless:u=!1,isOnLastBatch:h=!0,skipAutoScrollRef:H})=>{var x;const M=s.useRef(c),E=s.useRef(l),O=s.useRef(u),_=s.useRef(h);s.useEffect(()=>{M.current=c,E.current=l,O.current=u,_.current=h});const C=s.useRef(!1);s.useEffect(()=>{u||!t.current||n.length===0||C.current||(P(t.current),C.current=!0)},[t,u,n.length]);const R=s.useRef(void 0),p=s.useRef(0),D=s.useRef(!0),F=s.useRef(!0),a=s.useRef(!1),f=s.useRef(null),j=(n.length>0?(x=n.at(-1))==null?void 0:x.id:void 0)!==R.current,z=n.length>p.current;if(j||z){const r=t.current;F.current=r?X(r):!0}s.useEffect(()=>{var q,B;const r=n.length,b=r>0?(q=n[r-1])==null?void 0:q.id:void 0,v=R.current,m=p.current,d=D.current;if(R.current=b,p.current=r,D.current=!1,r===0)return;const o=t.current;if(!o||e.current)return;if(!(!d&&b!==v)){!O.current&&(d||r>m)&&(P(o),a.current=!1,f.current=null);return}if(O.current&&!_.current)return;if(H!=null&&H.current){H.current=!1;return}const i=n[r-1];if(M.current!==void 0&&((B=i==null?void 0:i.author)==null?void 0:B.id)!==void 0&&String(i.author.id)===String(M.current)){o.scrollTo({top:o.scrollHeight-o.clientHeight,behavior:"smooth"}),a.current=!1,f.current=null;return}if(!F.current){a.current=!1,f.current=null;return}const S=Y(o);if(!S)return;const T=J(o),A=Math.max(0,o.clientHeight-T),w=Q(E.current,A),U=S.getBoundingClientRect().top-o.getBoundingClientRect().top+o.scrollTop,y=Math.max(0,U-w-T),k=Math.max(0,o.scrollHeight-o.clientHeight),N=Math.min(y,k);N>o.scrollTop&&o.scrollTo({top:N,behavior:"smooth"}),f.current=y,a.current=!0},[n,t,e]),s.useEffect(()=>{const r=t.current;if(!r)return;let b=r.querySelectorAll(".k-message").length,v=r.scrollHeight,m=r.scrollTop;const d=()=>{const g=r.scrollTop;a.current&&g<m&&(a.current=!1,f.current=null),m=g},o=new MutationObserver(()=>{if(e.current)return;const g=r.querySelectorAll(".k-message").length,i=r.scrollHeight;if(g===b&&i>v&&a.current){const L=i-r.clientHeight,S=f.current,T=S===null?L:Math.min(L,S);T>r.scrollTop&&(r.scrollTop=T),m=r.scrollTop}b=g,v=i});return o.observe(r,{childList:!0,subtree:!0,characterData:!0}),r.addEventListener("scroll",d,{passive:!0}),()=>{o.disconnect(),r.removeEventListener("scroll",d)}},[t,e])},K=({elementRef:t})=>{const[e,n]=s.useState(!1);return s.useEffect(()=>{const c=t.current;if(!c)return;const l=()=>{n(c.scrollHeight>c.clientHeight)};l();const u=new ResizeObserver(l);u.observe(c);const h=new MutationObserver(()=>{requestAnimationFrame(l)});return h.observe(c,{childList:!0,subtree:!0,characterData:!0}),()=>{u.disconnect(),h.disconnect()}},[t]),e};exports.useHasScrollbar=K;exports.useMessageAutoScroll=Z;