@progress/kendo-react-conversational-ui 14.3.3-develop.1 → 14.4.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.
- package/ai-prompt/AIPromptContent.js +1 -1
- package/ai-prompt/AIPromptContent.mjs +2 -2
- package/ai-prompt/views/AIPromptOutputView.js +1 -1
- package/ai-prompt/views/AIPromptOutputView.mjs +63 -36
- package/chat/ChatPropsAndState.d.ts +65 -0
- package/chat/Events.d.ts +19 -0
- package/chat/components/Chat.js +1 -1
- package/chat/components/Chat.mjs +373 -314
- package/chat/components/ChatContext.d.ts +2 -0
- package/chat/components/ChatMessage.js +1 -1
- package/chat/components/ChatMessage.mjs +174 -175
- package/chat/components/elements/PinnedMessage.d.ts +1 -0
- package/chat/components/elements/PinnedMessage.js +1 -1
- package/chat/components/elements/PinnedMessage.mjs +17 -21
- package/chat/hooks/useEndlessScroll.d.ts +49 -0
- package/chat/hooks/useEndlessScroll.js +8 -0
- package/chat/hooks/useEndlessScroll.mjs +267 -0
- package/chat/utils/scroll.d.ts +5 -2
- package/chat/utils/scroll.js +1 -1
- package/chat/utils/scroll.mjs +89 -83
- package/dist/cdn/js/kendo-react-conversational-ui.js +1 -1
- package/package-metadata.js +1 -1
- package/package-metadata.mjs +2 -2
- package/package.json +11 -11
|
@@ -6,44 +6,40 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
import * as t from "react";
|
|
9
|
-
import { IconWrap as
|
|
10
|
-
import { Button as
|
|
11
|
-
import { pinOutlineIcon as
|
|
12
|
-
import { useLocalization as
|
|
13
|
-
import { isAuthor as
|
|
14
|
-
|
|
15
|
-
const
|
|
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
|
-
|
|
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,
|
|
19
|
+
[e.id, r]
|
|
24
20
|
);
|
|
25
21
|
return /* @__PURE__ */ t.createElement(
|
|
26
22
|
"div",
|
|
27
23
|
{
|
|
28
|
-
ref:
|
|
29
|
-
className: `k-message-reference ${
|
|
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(
|
|
33
|
-
/* @__PURE__ */ t.createElement("div", { className: "k-message-reference-content" }, e != null && e.isDeleted ? n &&
|
|
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
|
-
|
|
32
|
+
d,
|
|
37
33
|
{
|
|
38
34
|
fillMode: "flat",
|
|
39
|
-
svgIcon:
|
|
35
|
+
svgIcon: k,
|
|
40
36
|
onClick: (o) => {
|
|
41
|
-
o.stopPropagation(),
|
|
37
|
+
o.stopPropagation(), a == null || a(e);
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
)
|
|
45
41
|
);
|
|
46
42
|
};
|
|
47
43
|
export {
|
|
48
|
-
|
|
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 { ChatLoadMoreEvent, 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
|
+
onLoadMore?: (event: ChatLoadMoreEvent) => 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 onLoadMore, consumer manages data.
|
|
46
|
+
*
|
|
47
|
+
* @hidden
|
|
48
|
+
*/
|
|
49
|
+
export declare const useEndlessScroll: ({ scrollMode, processedMessages, total, pageSize, startIndex: startIndexProp, endIndex: endIndexProp, onLoadMore, 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(q){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(q){for(const g in q)if(g!=="default"){const e=Object.getOwnPropertyDescriptor(q,g);Object.defineProperty(n,g,e.get?e:{enumerable:!0,get:()=>q[g]})}}return n.default=q,Object.freeze(n)}const r=rt(tt),ct=50,I=100,ut=({scrollMode:q,processedMessages:n,total:g,pageSize:e=ct,startIndex:G,endIndex:U,onLoadMore:m,onReferencedMessageClick:B,viewItemsWrapperRef:u,authorId:V})=>{const d=r.useRef(!1),s=q==="endless",l=g!=null?g:n.length,a=s&&n.length===l&&!d.current,f=s&&(n.length<l||d.current);f&&(d.current=!0);const[b,O]=r.useState(-1),[S,y]=r.useState(-1),X=r.useRef(b),C=r.useRef(S);X.current=b,C.current=S;const o=r.useRef(!1),Y=r.useRef(0),v=r.useRef(0),R=r.useRef(!1),L=r.useRef(l),_=r.useRef(V);_.current=V;const F=r.useRef(!1),j=r.useRef(null),k=r.useRef(!1),$=r.useRef(!1),J=r.useRef(!0),N=r.useRef(l);r.useEffect(()=>{if(a){if(d.current){(b===-1||S===-1)&&(O(0),y(n.length));return}if(b===-1||S===-1){const t=Math.max(0,n.length-e),c=n.length;O(t),y(c)}else if(S<n.length){const t=L.current;if(C.current>=t)y(n.length);else if(n.length>t&&n.slice(t).some(i=>{var T;return((T=i.author)==null?void 0:T.id)!==void 0&&String(i.author.id)===String(_.current)})){const i=Math.max(0,n.length-e);O(i),y(n.length),k.current=!0}}L.current=l}},[a,n.length,e,b,S,l]);const A=G!=null?G:0,x=U!=null?U:n.length,P=r.useCallback(()=>{const t=u.current;t&&(Y.current=t.scrollHeight,v.current=t.scrollTop)},[u]),D=r.useCallback(t=>{var h,i,T;const c=(h=u.current)==null?void 0:h.closest(".k-chat"),E=((T=(i=u.current)==null?void 0:i.querySelector(".k-message-pinned"))==null?void 0:T.offsetHeight)||0;nt.scrollToMessageById(t,c,E)},[u]);r.useLayoutEffect(()=>{if(!R.current)return;const t=u.current;if(!t){R.current=!1;return}const c=t.scrollHeight-Y.current;c>0&&(t.scrollTop=v.current+c),R.current=!1,o.current=!1}),r.useLayoutEffect(()=>{if(!k.current)return;const t=u.current;if(!t){k.current=!1;return}S>=n.length&&S>0&&(k.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 E=()=>{const{scrollTop:h,scrollHeight:i,clientHeight:T}=t,K=h<c,p=h>c;if(c=h,!o.current){if(K&&h<=I){if(a){const H=X.current;if(H>0){const Q=Math.max(0,H-e);R.current=!0,P(),O(Q)}}else if(f&&A>0){o.current=!0;const H=Math.max(0,A-e);R.current=!0,P(),m==null||m({startIndex:H,endIndex:A})}}if(p&&i-h-T<=I){if(a){const H=C.current;if(H<n.length){const Q=Math.min(n.length,H+e);$.current=!0,y(Q)}}else if(f&&x<l){o.current=!0,$.current=!0;const H=Math.min(l,x+e);m==null||m({startIndex:x,endIndex:H})}}}};return t.addEventListener("scroll",E,{passive:!0}),()=>t.removeEventListener("scroll",E)},[s,a,f,u,e,n.length,A,x,l,m]),r.useEffect(()=>{var h;const t=x>=l;if(!f){N.current=l,J.current=t;return}const c=N.current,E=J.current;if(N.current=l,J.current=t,l>c&&!E&&t){const i=n[n.length-1];_.current!==void 0&&((h=i==null?void 0:i.author)==null?void 0:h.id)!==void 0&&String(i.author.id)===String(_.current)&&(F.current=!0,$.current=!0)}},[f,l,x,n]),r.useEffect(()=>{!f||!F.current||(F.current=!1,o.current=!1,requestAnimationFrame(()=>{const t=u.current;t&&(t.scrollTop=t.scrollHeight-t.clientHeight)}))},[f,n,u]),r.useEffect(()=>{if(!f||j.current===null)return;const t=j.current,c=u.current;if(!c)return;c.querySelector(`[data-message-id="${t}"]`)&&(j.current=null,o.current=!1,requestAnimationFrame(()=>{D(t)}))},[f,n,u,D]),r.useEffect(()=>{f&&o.current&&!R.current&&(o.current=!1)},[f,A,x]);const z=r.useMemo(()=>{if(a){const t=Math.max(0,b),c=Math.min(n.length,S);if(t>=c){const E=Math.max(0,n.length-e);return n.slice(E)}return n.slice(t,c)}return n},[a,n,b,S,e]),Z=r.useMemo(()=>s?a?S>=n.length:x>=l:!0,[s,a,S,n.length,x,l]),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-e);O(t),y(n.length),requestAnimationFrame(()=>{const c=u.current;c&&(c.scrollTop=c.scrollHeight-c.clientHeight)})}else if(f){F.current=!0,R.current=!1,o.current=!0;const t=Math.max(0,l-e);m==null||m({startIndex:t,endIndex:l})}}},[s,a,f,Z,n.length,e,l,m,u]),M=r.useCallback(t=>{if(!s)D(t);else if(a){const c=u.current;if(c==null?void 0:c.querySelector(`[data-message-id="${t}"]`))D(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(e/2),T=Math.max(0,h-i),K=Math.min(n.length,T+e);o.current=!0,O(T),y(K),requestAnimationFrame(()=>{requestAnimationFrame(()=>{D(t),o.current=!1})})}}}else if(f){const c=u.current;if(c==null?void 0:c.querySelector(`[data-message-id="${t}"]`))D(t);else{if(o.current)return;j.current=t,R.current=!1,o.current=!0}}B==null||B({id:t})},[s,a,f,u,n,e,B,D]);return{renderedMessages:z,handleScrollToBottom:W,handleReferencedMessageClick:M,isEndless:s,isOnLastBatch:Z,skipAutoScrollRef:$}};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, w = 100, ct = ({
|
|
11
|
+
scrollMode: I,
|
|
12
|
+
processedMessages: n,
|
|
13
|
+
total: G,
|
|
14
|
+
pageSize: i = nt,
|
|
15
|
+
startIndex: U,
|
|
16
|
+
endIndex: C,
|
|
17
|
+
onLoadMore: m,
|
|
18
|
+
onReferencedMessageClick: B,
|
|
19
|
+
viewItemsWrapperRef: u,
|
|
20
|
+
authorId: V
|
|
21
|
+
}) => {
|
|
22
|
+
const O = r.useRef(!1), s = I === "endless", l = G != null ? G : n.length, a = s && n.length === l && !O.current, f = s && (n.length < l || O.current);
|
|
23
|
+
f && (O.current = !0);
|
|
24
|
+
const [q, A] = r.useState(-1), [E, D] = r.useState(-1), X = r.useRef(q), J = r.useRef(E);
|
|
25
|
+
X.current = q, J.current = E;
|
|
26
|
+
const o = r.useRef(!1), Y = r.useRef(0), d = r.useRef(0), R = r.useRef(!1), L = r.useRef(l), b = r.useRef(V);
|
|
27
|
+
b.current = V;
|
|
28
|
+
const F = r.useRef(!1), k = r.useRef(null), _ = r.useRef(!1), $ = r.useRef(!1), Z = r.useRef(!0), j = r.useRef(l);
|
|
29
|
+
r.useEffect(() => {
|
|
30
|
+
if (a) {
|
|
31
|
+
if (O.current) {
|
|
32
|
+
(q === -1 || E === -1) && (A(0), D(n.length));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (q === -1 || E === -1) {
|
|
36
|
+
const t = Math.max(0, n.length - i), c = n.length;
|
|
37
|
+
A(t), D(c);
|
|
38
|
+
} else if (E < n.length) {
|
|
39
|
+
const t = L.current;
|
|
40
|
+
if (J.current >= t)
|
|
41
|
+
D(n.length);
|
|
42
|
+
else if (n.length > t && n.slice(t).some(
|
|
43
|
+
(e) => {
|
|
44
|
+
var T;
|
|
45
|
+
return ((T = e.author) == null ? void 0 : T.id) !== void 0 && String(e.author.id) === String(b.current);
|
|
46
|
+
}
|
|
47
|
+
)) {
|
|
48
|
+
const e = Math.max(0, n.length - i);
|
|
49
|
+
A(e), D(n.length), _.current = !0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
L.current = l;
|
|
53
|
+
}
|
|
54
|
+
}, [a, n.length, i, q, E, l]);
|
|
55
|
+
const y = U != null ? U : 0, x = C != null ? C : n.length, v = r.useCallback(() => {
|
|
56
|
+
const t = u.current;
|
|
57
|
+
t && (Y.current = t.scrollHeight, d.current = t.scrollTop);
|
|
58
|
+
}, [u]), g = r.useCallback(
|
|
59
|
+
(t) => {
|
|
60
|
+
var h, e, T;
|
|
61
|
+
const c = (h = u.current) == null ? void 0 : h.closest(".k-chat"), S = ((T = (e = u.current) == null ? void 0 : e.querySelector(".k-message-pinned")) == null ? void 0 : T.offsetHeight) || 0;
|
|
62
|
+
tt(t, c, S);
|
|
63
|
+
},
|
|
64
|
+
[u]
|
|
65
|
+
);
|
|
66
|
+
r.useLayoutEffect(() => {
|
|
67
|
+
if (!R.current)
|
|
68
|
+
return;
|
|
69
|
+
const t = u.current;
|
|
70
|
+
if (!t) {
|
|
71
|
+
R.current = !1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const c = t.scrollHeight - Y.current;
|
|
75
|
+
c > 0 && (t.scrollTop = d.current + c), R.current = !1, o.current = !1;
|
|
76
|
+
}), r.useLayoutEffect(() => {
|
|
77
|
+
if (!_.current)
|
|
78
|
+
return;
|
|
79
|
+
const t = u.current;
|
|
80
|
+
if (!t) {
|
|
81
|
+
_.current = !1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
E >= n.length && E > 0 && (_.current = !1, t.scrollTop = t.scrollHeight - t.clientHeight);
|
|
85
|
+
});
|
|
86
|
+
const P = r.useRef(!1);
|
|
87
|
+
r.useLayoutEffect(() => {
|
|
88
|
+
if (!s || P.current)
|
|
89
|
+
return;
|
|
90
|
+
const t = u.current;
|
|
91
|
+
t && t.querySelector("[data-message-id]") && (t.scrollTop = t.scrollHeight - t.clientHeight, P.current = !0);
|
|
92
|
+
}), r.useEffect(() => {
|
|
93
|
+
if (!s)
|
|
94
|
+
return;
|
|
95
|
+
const t = u.current;
|
|
96
|
+
if (!t)
|
|
97
|
+
return;
|
|
98
|
+
let c = t.scrollTop;
|
|
99
|
+
const S = () => {
|
|
100
|
+
const { scrollTop: h, scrollHeight: e, clientHeight: T } = t, N = h < c, p = h > c;
|
|
101
|
+
if (c = h, !o.current) {
|
|
102
|
+
if (N && h <= w) {
|
|
103
|
+
if (a) {
|
|
104
|
+
const H = X.current;
|
|
105
|
+
if (H > 0) {
|
|
106
|
+
const Q = Math.max(0, H - i);
|
|
107
|
+
R.current = !0, v(), A(Q);
|
|
108
|
+
}
|
|
109
|
+
} else if (f && y > 0) {
|
|
110
|
+
o.current = !0;
|
|
111
|
+
const H = Math.max(0, y - i);
|
|
112
|
+
R.current = !0, v(), m == null || m({ startIndex: H, endIndex: y });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (p && e - h - T <= w) {
|
|
116
|
+
if (a) {
|
|
117
|
+
const H = J.current;
|
|
118
|
+
if (H < n.length) {
|
|
119
|
+
const Q = Math.min(n.length, H + i);
|
|
120
|
+
$.current = !0, D(Q);
|
|
121
|
+
}
|
|
122
|
+
} else if (f && x < l) {
|
|
123
|
+
o.current = !0, $.current = !0;
|
|
124
|
+
const H = Math.min(l, x + i);
|
|
125
|
+
m == null || m({ startIndex: x, endIndex: H });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return t.addEventListener("scroll", S, { passive: !0 }), () => t.removeEventListener("scroll", S);
|
|
131
|
+
}, [
|
|
132
|
+
s,
|
|
133
|
+
a,
|
|
134
|
+
f,
|
|
135
|
+
u,
|
|
136
|
+
i,
|
|
137
|
+
n.length,
|
|
138
|
+
y,
|
|
139
|
+
x,
|
|
140
|
+
l,
|
|
141
|
+
m
|
|
142
|
+
]), r.useEffect(() => {
|
|
143
|
+
var h;
|
|
144
|
+
const t = x >= l;
|
|
145
|
+
if (!f) {
|
|
146
|
+
j.current = l, Z.current = t;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const c = j.current, S = Z.current;
|
|
150
|
+
if (j.current = l, Z.current = t, l > c && !S && t) {
|
|
151
|
+
const e = n[n.length - 1];
|
|
152
|
+
b.current !== void 0 && ((h = e == null ? void 0 : e.author) == null ? void 0 : h.id) !== void 0 && String(e.author.id) === String(b.current) && (F.current = !0, $.current = !0);
|
|
153
|
+
}
|
|
154
|
+
}, [f, l, x, n]), r.useEffect(() => {
|
|
155
|
+
!f || !F.current || (F.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 || k.current === null)
|
|
161
|
+
return;
|
|
162
|
+
const t = k.current, c = u.current;
|
|
163
|
+
if (!c)
|
|
164
|
+
return;
|
|
165
|
+
c.querySelector(`[data-message-id="${t}"]`) && (k.current = null, o.current = !1, requestAnimationFrame(() => {
|
|
166
|
+
g(t);
|
|
167
|
+
}));
|
|
168
|
+
}, [f, n, u, g]), r.useEffect(() => {
|
|
169
|
+
f && o.current && !R.current && (o.current = !1);
|
|
170
|
+
}, [f, y, x]);
|
|
171
|
+
const z = r.useMemo(() => {
|
|
172
|
+
if (a) {
|
|
173
|
+
const t = Math.max(0, q), c = Math.min(n.length, E);
|
|
174
|
+
if (t >= c) {
|
|
175
|
+
const S = Math.max(0, n.length - i);
|
|
176
|
+
return n.slice(S);
|
|
177
|
+
}
|
|
178
|
+
return n.slice(t, c);
|
|
179
|
+
}
|
|
180
|
+
return n;
|
|
181
|
+
}, [a, n, q, E, i]), K = r.useMemo(() => s ? a ? E >= n.length : x >= l : !0, [s, a, E, n.length, x, l]), W = r.useCallback(() => {
|
|
182
|
+
if (!s || K) {
|
|
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
|
+
A(t), D(n.length), requestAnimationFrame(() => {
|
|
191
|
+
const c = u.current;
|
|
192
|
+
c && (c.scrollTop = c.scrollHeight - c.clientHeight);
|
|
193
|
+
});
|
|
194
|
+
} else if (f) {
|
|
195
|
+
F.current = !0, R.current = !1, o.current = !0;
|
|
196
|
+
const t = Math.max(0, l - i);
|
|
197
|
+
m == null || m({ startIndex: t, endIndex: l });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, [
|
|
201
|
+
s,
|
|
202
|
+
a,
|
|
203
|
+
f,
|
|
204
|
+
K,
|
|
205
|
+
n.length,
|
|
206
|
+
i,
|
|
207
|
+
l,
|
|
208
|
+
m,
|
|
209
|
+
u
|
|
210
|
+
]), M = r.useCallback(
|
|
211
|
+
(t) => {
|
|
212
|
+
if (!s)
|
|
213
|
+
g(t);
|
|
214
|
+
else if (a) {
|
|
215
|
+
const c = u.current;
|
|
216
|
+
if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
|
|
217
|
+
g(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), T = Math.max(0, h - e), N = Math.min(n.length, T + i);
|
|
226
|
+
o.current = !0, A(T), D(N), requestAnimationFrame(() => {
|
|
227
|
+
requestAnimationFrame(() => {
|
|
228
|
+
g(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
|
+
g(t);
|
|
237
|
+
else {
|
|
238
|
+
if (o.current)
|
|
239
|
+
return;
|
|
240
|
+
k.current = t, R.current = !1, o.current = !0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
B == null || B({ id: t });
|
|
244
|
+
},
|
|
245
|
+
[
|
|
246
|
+
s,
|
|
247
|
+
a,
|
|
248
|
+
f,
|
|
249
|
+
u,
|
|
250
|
+
n,
|
|
251
|
+
i,
|
|
252
|
+
B,
|
|
253
|
+
g
|
|
254
|
+
]
|
|
255
|
+
);
|
|
256
|
+
return {
|
|
257
|
+
renderedMessages: z,
|
|
258
|
+
handleScrollToBottom: W,
|
|
259
|
+
handleReferencedMessageClick: M,
|
|
260
|
+
isEndless: s,
|
|
261
|
+
isOnLastBatch: K,
|
|
262
|
+
skipAutoScrollRef: $
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
export {
|
|
266
|
+
ct as useEndlessScroll
|
|
267
|
+
};
|
package/chat/utils/scroll.d.ts
CHANGED
|
@@ -10,12 +10,15 @@ import * as React from 'react';
|
|
|
10
10
|
/** @hidden */
|
|
11
11
|
type AutoScrollThresholdValue = number | string;
|
|
12
12
|
/** @hidden */
|
|
13
|
-
interface
|
|
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
|
|
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
|
}
|
package/chat/utils/scroll.js
CHANGED
|
@@ -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
|
|
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;
|