@progress/kendo-react-conversational-ui 14.4.0-develop.1 → 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.
- package/NOTICE.txt +366 -82
- package/chat/ChatPropsAndState.d.ts +4 -4
- package/chat/Events.d.ts +2 -2
- package/chat/components/Chat.js +1 -1
- package/chat/components/Chat.mjs +3 -3
- package/chat/components/NewMessage.js +1 -1
- package/chat/components/NewMessage.mjs +37 -41
- package/chat/hooks/useEndlessScroll.d.ts +4 -4
- package/chat/hooks/useEndlessScroll.js +1 -1
- package/chat/hooks/useEndlessScroll.mjs +108 -108
- 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
package/chat/components/Chat.mjs
CHANGED
|
@@ -102,7 +102,7 @@ const Je = t.forwardRef((Qe, b) => {
|
|
|
102
102
|
pageSize: dt,
|
|
103
103
|
startIndex: gt,
|
|
104
104
|
endIndex: ft,
|
|
105
|
-
|
|
105
|
+
onLoadMoreMessages: pt,
|
|
106
106
|
pinnedMessages: D,
|
|
107
107
|
repliedToMessages: Be,
|
|
108
108
|
onReferencedMessageClick: ht,
|
|
@@ -177,7 +177,7 @@ const Je = t.forwardRef((Qe, b) => {
|
|
|
177
177
|
pageSize: dt,
|
|
178
178
|
startIndex: gt,
|
|
179
179
|
endIndex: ft,
|
|
180
|
-
|
|
180
|
+
onLoadMoreMessages: pt,
|
|
181
181
|
onReferencedMessageClick: ht,
|
|
182
182
|
viewItemsWrapperRef: i,
|
|
183
183
|
authorId: a
|
|
@@ -564,7 +564,7 @@ Je.propTypes = {
|
|
|
564
564
|
pageSize: o.number,
|
|
565
565
|
startIndex: o.number,
|
|
566
566
|
endIndex: o.number,
|
|
567
|
-
|
|
567
|
+
onLoadMoreMessages: o.func,
|
|
568
568
|
pinnedMessages: o.arrayOf(o.object),
|
|
569
569
|
repliedToMessages: o.arrayOf(o.object),
|
|
570
570
|
onReferencedMessageClick: o.func
|
|
@@ -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 Z=require("@progress/kendo-react-common"),$=require("react"),ee=require("@progress/kendo-react-buttons"),te=require("./SuggestionsGroup.js"),ne=require("@progress/kendo-svg-icons"),ae=require("./ChatContext.js"),oe=require("@progress/kendo-react-intl"),H=require("../utils.js"),n=require("../../messages/index.js"),re=require("../../prompt-box/PromptBoxUploadButton.js"),se=require("../../prompt-box/PromptBox.js");function le(l){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const r in l)if(r!=="default"){const
|
|
8
|
+
"use strict";const Z=require("@progress/kendo-react-common"),$=require("react"),ee=require("@progress/kendo-react-buttons"),te=require("./SuggestionsGroup.js"),ne=require("@progress/kendo-svg-icons"),ae=require("./ChatContext.js"),oe=require("@progress/kendo-react-intl"),H=require("../utils.js"),n=require("../../messages/index.js"),re=require("../../prompt-box/PromptBoxUploadButton.js"),se=require("../../prompt-box/PromptBox.js");function le(l){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const r in l)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(l,r);Object.defineProperty(c,r,i.get?i:{enumerable:!0,get:()=>l[r]})}}return c.default=l,Object.freeze(c)}const t=le($),_=t.memo(({affixProps:l,uploadConfig:c,localizationService:r,onFilesSelect:i,onFileRemove:C})=>{const k=typeof c=="object"?c:{};return c!==!1?t.createElement(re.PromptBoxUploadButton,{...l.uploadButtonProps,fillMode:"clear","aria-label":r.toLanguageString(n.attachFile,n.messages[n.attachFile]),title:r.toLanguageString(n.attachFile,n.messages[n.attachFile]),...k,onSelectAttachments:i,onRemoveAttachment:C}):null});_.displayName="UploadButtonAffix";const J=t.forwardRef((l,c)=>{const{onSendMessage:r,isDirectionRightToLeft:i,placeholder:C,MessageBox:k,suggestions:b,onSuggestionClick:K,inputValue:E,onInputValueChange:f,suggestionTemplate:Q,sendButtonConfig:A,onInputClick:F,suggestionsLayout:W,dir:X,messageBoxSettings:e,loading:M}=l,{replyToMessage:u,setReplyToMessage:y,user:x,speechToTextConfig:P,uploadConfig:S}=ae.useChatContext(),[Y,I]=t.useState(""),[w,v]=t.useState([]),T=t.useRef(null),o=oe.useLocalization(),m=E!==void 0,R=m?E:Y,p=t.useCallback(()=>{T.current!==null&&T.current.focus()},[]);t.useEffect(()=>{u&&p()},[u,p]);const L=t.useCallback(a=>{if(a.preventDefault(),r){const h={id:"",author:x,text:R||"",timestamp:new Date,replyToId:u?u.id:void 0,files:w.map(g=>({name:g.name,size:g.size,type:g.extension,rawFile:g.getRawFile?g.getRawFile():g}))};y(null),r(h,a),v([]),m||I(""),f&&f(""),p()}},[r,R,x,u,w,y,f,p,m]);t.useImperativeHandle(c,()=>({focusInput:p}),[p]);const q=t.useCallback(a=>{v(s=>s.filter(h=>h.name!==a))},[]),N=t.useCallback((a,s)=>a.isDeleted?H.getDeletedMessageText(s,o):a.text,[o]),D=t.useCallback(()=>{if(u){const a=H.isAuthor(x,u);return t.createElement("div",{className:Z.classNames("k-message-reference",a?"k-message-reference-sender":"k-message-reference-receiver")},t.createElement("div",{className:"k-message-reference-content"},N(u,a)),t.createElement("span",{className:"k-spacer"}),t.createElement(ee.Button,{fillMode:"flat",svgIcon:ne.xMarkSmOutlineIcon,onClick:()=>y(null),"aria-label":o.toLanguageString(n.closeReply,n.messages[n.closeReply]),title:o.toLanguageString(n.closeReply,n.messages[n.closeReply])}))}return null},[u,x,N,y,o]),j=t.useCallback(a=>{try{const s=Array.from(a.allFiles);v(s)}catch{}},[]),B=t.useCallback(a=>{const s=a.value;m||I(s),f&&f(s||"")},[m,f]),G=t.useCallback(a=>{L(a.syntheticEvent)},[L]),d=t.useCallback(a=>a?typeof a=="function"?a():a:null,[]),O=t.useCallback(a=>t.createElement(t.Fragment,null,t.createElement(_,{affixProps:a,uploadConfig:S,localizationService:o,onFilesSelect:j,onFileRemove:q}),d(e==null?void 0:e.startAffix)),[S,o,j,q,e==null?void 0:e.startAffix,d]),U=t.useCallback(()=>d(e==null?void 0:e.endAffix),[e==null?void 0:e.endAffix,d]),V=t.useCallback(()=>d(e==null?void 0:e.topAffix),[e==null?void 0:e.topAffix,d]),z=t.useMemo(()=>{const a=typeof A=="object"?A:{},h=A!==!1?{"aria-label":M?o.toLanguageString(n.chatStopGenerating,n.messages[n.chatStopGenerating]):o.toLanguageString(n.newMessageSendButton,n.messages[n.newMessageSendButton]),title:M?o.toLanguageString(n.chatStopGenerating,n.messages[n.chatStopGenerating]):o.toLanguageString(n.newMessageSendButton,n.messages[n.newMessageSendButton]),dir:i?"rtl":void 0,...a}:!1;return t.createElement(se.PromptBox,{header:D(),ref:T,placeholder:C,value:R,onChange:B,onPromptAction:G,mode:(e==null?void 0:e.mode)||"multi",rows:(e==null?void 0:e.rows)||2,maxTextAreaHeight:(e==null?void 0:e.maxTextAreaHeight)||"110",loading:M,speechToTextButtonConfig:P,actionButtonConfig:h,attachments:w,startAffix:O,endAffix:e!=null&&e.endAffix?U:void 0,topAffix:e!=null&&e.topAffix?V:void 0,inputAttributes:{onClick:F,"aria-label":o.toLanguageString(n.newMessageMessageInput,n.messages[n.newMessageMessageInput])}})},[C,R,B,G,e,M,P,A,w,D,O,U,V,o,i,F]);return t.createElement("div",{className:"k-message-box-wrapper"},b&&b.length>0&&t.createElement(te.SuggestionGroup,{onSuggestionClick:K,suggestions:b,suggestionTemplate:Q,suggestionsLayout:W,dir:X}),k?t.createElement(k,{messageInput:z}):z)});J.displayName="NewMessage";module.exports=J;
|
|
@@ -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
|
|
17
|
-
import { PromptBoxUploadButton as
|
|
18
|
-
import { PromptBox as
|
|
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:
|
|
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
|
-
|
|
23
|
+
ie,
|
|
24
24
|
{
|
|
25
25
|
...R.uploadButtonProps,
|
|
26
26
|
fillMode: "clear",
|
|
27
|
-
"aria-label":
|
|
28
|
-
title:
|
|
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:
|
|
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:
|
|
46
|
-
onInputValueChange:
|
|
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,
|
|
55
|
-
|
|
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 &&
|
|
59
|
-
}, [r,
|
|
58
|
+
r && i();
|
|
59
|
+
}, [r, i]);
|
|
60
60
|
const z = t.useCallback(
|
|
61
61
|
(n) => {
|
|
62
|
-
if (n.preventDefault(),
|
|
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),
|
|
76
|
+
v(null), c(m, n), F([]), d || U(""), s && s(""), i();
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
[
|
|
80
|
-
|
|
80
|
+
c,
|
|
81
81
|
T,
|
|
82
82
|
x,
|
|
83
83
|
r,
|
|
84
84
|
M,
|
|
85
85
|
v,
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
s,
|
|
87
|
+
i,
|
|
88
88
|
d
|
|
89
89
|
]
|
|
90
90
|
);
|
|
91
91
|
t.useImperativeHandle(
|
|
92
92
|
p,
|
|
93
93
|
() => ({
|
|
94
|
-
focusInput:
|
|
94
|
+
focusInput: i
|
|
95
95
|
}),
|
|
96
|
-
[
|
|
96
|
+
[i]
|
|
97
97
|
);
|
|
98
98
|
const H = t.useCallback((n) => {
|
|
99
|
-
|
|
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
|
-
|
|
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),
|
|
138
|
+
d || U(a), s && s(a || "");
|
|
143
139
|
},
|
|
144
|
-
[d,
|
|
140
|
+
[d, s]
|
|
145
141
|
), q = t.useCallback(
|
|
146
142
|
(n) => {
|
|
147
143
|
z(n.syntheticEvent);
|
|
148
144
|
},
|
|
149
145
|
[z]
|
|
150
|
-
),
|
|
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
|
-
),
|
|
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
|
-
|
|
163
|
+
u
|
|
168
164
|
]
|
|
169
165
|
), K = t.useCallback(
|
|
170
|
-
() =>
|
|
171
|
-
[e == null ? void 0 : e.endAffix,
|
|
166
|
+
() => u(e == null ? void 0 : e.endAffix),
|
|
167
|
+
[e == null ? void 0 : e.endAffix, u]
|
|
172
168
|
), Q = t.useCallback(
|
|
173
|
-
() =>
|
|
174
|
-
[e == null ? void 0 : e.topAffix,
|
|
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(
|
|
178
|
-
title: b ? o.toLanguageString(
|
|
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
|
-
|
|
179
|
+
ue,
|
|
184
180
|
{
|
|
185
181
|
header: j(),
|
|
186
|
-
ref:
|
|
182
|
+
ref: I,
|
|
187
183
|
placeholder: C,
|
|
188
184
|
value: T,
|
|
189
185
|
onChange: O,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
import { Message } from '../../api/message.interface.js';
|
|
9
|
-
import {
|
|
9
|
+
import { ChatLoadMoreMessagesEvent, ChatReferencedMessageClickEvent } from '../Events.js';
|
|
10
10
|
import { ScrollMode } from '../ChatPropsAndState.js';
|
|
11
11
|
import * as React from 'react';
|
|
12
12
|
/** @hidden */
|
|
@@ -17,7 +17,7 @@ export interface UseEndlessScrollProps {
|
|
|
17
17
|
pageSize?: number;
|
|
18
18
|
startIndex?: number;
|
|
19
19
|
endIndex?: number;
|
|
20
|
-
|
|
20
|
+
onLoadMoreMessages?: (event: ChatLoadMoreMessagesEvent) => void;
|
|
21
21
|
onReferencedMessageClick?: (event: ChatReferencedMessageClickEvent) => void;
|
|
22
22
|
viewItemsWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
23
23
|
authorId?: string | number;
|
|
@@ -42,8 +42,8 @@ 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
|
|
45
|
+
* Remote mode: messages.length < total — Chat fires onLoadMoreMessages, consumer manages data.
|
|
46
46
|
*
|
|
47
47
|
* @hidden
|
|
48
48
|
*/
|
|
49
|
-
export declare const useEndlessScroll: ({ scrollMode, processedMessages, total, pageSize, startIndex: startIndexProp, endIndex: endIndexProp,
|
|
49
|
+
export declare const useEndlessScroll: ({ scrollMode, processedMessages, total, pageSize, startIndex: startIndexProp, endIndex: endIndexProp, onLoadMoreMessages, onReferencedMessageClick, viewItemsWrapperRef, authorId }: UseEndlessScrollProps) => UseEndlessScrollReturn;
|
|
@@ -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(
|
|
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;
|