@progress/kendo-react-conversational-ui 14.3.0-develop.9 → 14.3.1-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/chat/ChatPropsAndState.d.ts +58 -0
- package/chat/components/Chat.js +1 -1
- package/chat/components/Chat.mjs +314 -306
- package/chat/components/ChatMessage.js +1 -1
- package/chat/components/ChatMessage.mjs +153 -152
- package/chat/components/NewMessage.js +1 -1
- package/chat/components/NewMessage.mjs +166 -151
- package/chat/utils/scroll.d.ts +12 -20
- package/chat/utils/scroll.js +1 -5
- package/chat/utils/scroll.mjs +114 -172
- 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,222 +6,237 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
import { classNames as te } from "@progress/kendo-react-common";
|
|
9
|
-
import * as
|
|
10
|
-
import { Button as
|
|
11
|
-
import { SuggestionGroup as
|
|
9
|
+
import * as t from "react";
|
|
10
|
+
import { Button as ne } from "@progress/kendo-react-buttons";
|
|
11
|
+
import { SuggestionGroup as oe } from "./SuggestionsGroup.mjs";
|
|
12
12
|
import { xMarkSmOutlineIcon as ae } from "@progress/kendo-svg-icons";
|
|
13
|
-
import { useChatContext as
|
|
14
|
-
import { useLocalization as
|
|
15
|
-
import { getDeletedMessageText as
|
|
16
|
-
import { closeReply as y, messages as
|
|
17
|
-
import { PromptBoxUploadButton as
|
|
18
|
-
import { PromptBox as
|
|
19
|
-
const
|
|
20
|
-
({ affixProps:
|
|
21
|
-
const
|
|
22
|
-
return
|
|
23
|
-
|
|
13
|
+
import { useChatContext as re } from "./ChatContext.mjs";
|
|
14
|
+
import { useLocalization as le } from "@progress/kendo-react-intl";
|
|
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";
|
|
19
|
+
const Y = t.memo(
|
|
20
|
+
({ affixProps: R, uploadConfig: p, localizationService: s, onFilesSelect: g, onFileRemove: C }) => {
|
|
21
|
+
const A = typeof p == "object" ? p : {};
|
|
22
|
+
return p !== !1 ? /* @__PURE__ */ t.createElement(
|
|
23
|
+
ue,
|
|
24
24
|
{
|
|
25
|
-
...
|
|
25
|
+
...R.uploadButtonProps,
|
|
26
26
|
fillMode: "clear",
|
|
27
|
-
"aria-label":
|
|
28
|
-
title:
|
|
29
|
-
...
|
|
30
|
-
onSelectAttachments:
|
|
31
|
-
onRemoveAttachment:
|
|
27
|
+
"aria-label": s.toLanguageString(L, l[L]),
|
|
28
|
+
title: s.toLanguageString(L, l[L]),
|
|
29
|
+
...A,
|
|
30
|
+
onSelectAttachments: g,
|
|
31
|
+
onRemoveAttachment: C
|
|
32
32
|
}
|
|
33
33
|
) : null;
|
|
34
34
|
}
|
|
35
35
|
);
|
|
36
|
-
|
|
37
|
-
const
|
|
36
|
+
Y.displayName = "UploadButtonAffix";
|
|
37
|
+
const fe = t.forwardRef((R, p) => {
|
|
38
38
|
const {
|
|
39
|
-
onSendMessage:
|
|
40
|
-
isDirectionRightToLeft:
|
|
41
|
-
placeholder:
|
|
42
|
-
MessageBox:
|
|
43
|
-
suggestions:
|
|
44
|
-
onSuggestionClick:
|
|
45
|
-
inputValue:
|
|
39
|
+
onSendMessage: s,
|
|
40
|
+
isDirectionRightToLeft: g,
|
|
41
|
+
placeholder: C,
|
|
42
|
+
MessageBox: A,
|
|
43
|
+
suggestions: h,
|
|
44
|
+
onSuggestionClick: Z,
|
|
45
|
+
inputValue: F,
|
|
46
46
|
onInputValueChange: u,
|
|
47
|
-
suggestionTemplate:
|
|
48
|
-
sendButtonConfig:
|
|
49
|
-
onInputClick:
|
|
50
|
-
suggestionsLayout:
|
|
51
|
-
dir:
|
|
52
|
-
messageBoxSettings:
|
|
53
|
-
loading:
|
|
54
|
-
} =
|
|
55
|
-
|
|
47
|
+
suggestionTemplate: _,
|
|
48
|
+
sendButtonConfig: k,
|
|
49
|
+
onInputClick: P,
|
|
50
|
+
suggestionsLayout: $,
|
|
51
|
+
dir: B,
|
|
52
|
+
messageBoxSettings: e,
|
|
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();
|
|
56
56
|
}, []);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}, [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (t.preventDefault(), i) {
|
|
65
|
-
const f = {
|
|
57
|
+
t.useEffect(() => {
|
|
58
|
+
r && c();
|
|
59
|
+
}, [r, c]);
|
|
60
|
+
const z = t.useCallback(
|
|
61
|
+
(n) => {
|
|
62
|
+
if (n.preventDefault(), s) {
|
|
63
|
+
const m = {
|
|
66
64
|
id: "",
|
|
67
|
-
author:
|
|
68
|
-
text:
|
|
65
|
+
author: x,
|
|
66
|
+
text: T || "",
|
|
69
67
|
timestamp: /* @__PURE__ */ new Date(),
|
|
70
|
-
replyToId:
|
|
71
|
-
files:
|
|
72
|
-
name:
|
|
73
|
-
size:
|
|
74
|
-
type:
|
|
75
|
-
rawFile:
|
|
68
|
+
replyToId: r ? r.id : void 0,
|
|
69
|
+
files: M.map((f) => ({
|
|
70
|
+
name: f.name,
|
|
71
|
+
size: f.size,
|
|
72
|
+
type: f.extension,
|
|
73
|
+
rawFile: f.getRawFile ? f.getRawFile() : f
|
|
76
74
|
}))
|
|
77
75
|
};
|
|
78
|
-
|
|
76
|
+
v(null), s(m, n), I([]), d || U(""), u && u(""), c();
|
|
79
77
|
}
|
|
80
78
|
},
|
|
81
79
|
[
|
|
82
|
-
i,
|
|
83
|
-
M,
|
|
84
|
-
b,
|
|
85
80
|
s,
|
|
86
|
-
B,
|
|
87
81
|
T,
|
|
82
|
+
x,
|
|
83
|
+
r,
|
|
84
|
+
M,
|
|
85
|
+
v,
|
|
88
86
|
u,
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
c,
|
|
88
|
+
d
|
|
91
89
|
]
|
|
92
90
|
);
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
t.useImperativeHandle(
|
|
92
|
+
p,
|
|
95
93
|
() => ({
|
|
96
|
-
focusInput:
|
|
94
|
+
focusInput: c
|
|
97
95
|
}),
|
|
98
|
-
[
|
|
96
|
+
[c]
|
|
99
97
|
);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
}, []),
|
|
103
|
-
(
|
|
98
|
+
const H = t.useCallback((n) => {
|
|
99
|
+
I((a) => a.filter((m) => m.name !== n));
|
|
100
|
+
}, []), S = t.useCallback(
|
|
101
|
+
(n, a) => n.isDeleted ? ce(a, o) : n.text,
|
|
104
102
|
[o]
|
|
105
|
-
),
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
108
|
-
return /* @__PURE__ */
|
|
103
|
+
), j = t.useCallback(() => {
|
|
104
|
+
if (r) {
|
|
105
|
+
const n = se(x, r);
|
|
106
|
+
return /* @__PURE__ */ t.createElement(
|
|
109
107
|
"div",
|
|
110
108
|
{
|
|
111
109
|
className: te(
|
|
112
110
|
"k-message-reference",
|
|
113
|
-
|
|
111
|
+
n ? "k-message-reference-sender" : "k-message-reference-receiver"
|
|
114
112
|
)
|
|
115
113
|
},
|
|
116
|
-
/* @__PURE__ */
|
|
117
|
-
/* @__PURE__ */
|
|
118
|
-
/* @__PURE__ */
|
|
119
|
-
|
|
114
|
+
/* @__PURE__ */ t.createElement("div", { className: "k-message-reference-content" }, S(r, n)),
|
|
115
|
+
/* @__PURE__ */ t.createElement("span", { className: "k-spacer" }),
|
|
116
|
+
/* @__PURE__ */ t.createElement(
|
|
117
|
+
ne,
|
|
120
118
|
{
|
|
121
119
|
fillMode: "flat",
|
|
122
120
|
svgIcon: ae,
|
|
123
|
-
onClick: () =>
|
|
124
|
-
"aria-label": o.toLanguageString(y,
|
|
125
|
-
title: o.toLanguageString(y,
|
|
121
|
+
onClick: () => v(null),
|
|
122
|
+
"aria-label": o.toLanguageString(y, l[y]),
|
|
123
|
+
title: o.toLanguageString(y, l[y])
|
|
126
124
|
}
|
|
127
125
|
)
|
|
128
126
|
);
|
|
129
127
|
}
|
|
130
128
|
return null;
|
|
131
|
-
}, [
|
|
129
|
+
}, [r, x, S, v, o]), G = t.useCallback((n) => {
|
|
132
130
|
try {
|
|
133
|
-
const
|
|
134
|
-
|
|
131
|
+
const a = Array.from(n.allFiles);
|
|
132
|
+
I(a);
|
|
135
133
|
} catch {
|
|
136
134
|
}
|
|
137
135
|
}, []);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}, [
|
|
141
|
-
const
|
|
142
|
-
(
|
|
143
|
-
const
|
|
144
|
-
|
|
136
|
+
t.useEffect(() => {
|
|
137
|
+
c();
|
|
138
|
+
}, [F, c]);
|
|
139
|
+
const O = t.useCallback(
|
|
140
|
+
(n) => {
|
|
141
|
+
const a = n.value;
|
|
142
|
+
d || U(a), u && u(a || "");
|
|
145
143
|
},
|
|
146
|
-
[
|
|
147
|
-
),
|
|
148
|
-
(
|
|
149
|
-
|
|
144
|
+
[d, u]
|
|
145
|
+
), q = t.useCallback(
|
|
146
|
+
(n) => {
|
|
147
|
+
z(n.syntheticEvent);
|
|
150
148
|
},
|
|
151
|
-
[
|
|
152
|
-
),
|
|
153
|
-
(
|
|
154
|
-
|
|
149
|
+
[z]
|
|
150
|
+
), i = t.useCallback((n) => n ? typeof n == "function" ? n() : n : null, []), J = t.useCallback(
|
|
151
|
+
(n) => /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement(
|
|
152
|
+
Y,
|
|
155
153
|
{
|
|
156
|
-
affixProps:
|
|
157
|
-
uploadConfig:
|
|
154
|
+
affixProps: n,
|
|
155
|
+
uploadConfig: D,
|
|
158
156
|
localizationService: o,
|
|
159
|
-
onFilesSelect:
|
|
160
|
-
onFileRemove:
|
|
157
|
+
onFilesSelect: G,
|
|
158
|
+
onFileRemove: H
|
|
161
159
|
}
|
|
162
|
-
),
|
|
163
|
-
[
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
160
|
+
), i(e == null ? void 0 : e.startAffix)),
|
|
161
|
+
[
|
|
162
|
+
D,
|
|
163
|
+
o,
|
|
164
|
+
G,
|
|
165
|
+
H,
|
|
166
|
+
e == null ? void 0 : e.startAffix,
|
|
167
|
+
i
|
|
168
|
+
]
|
|
169
|
+
), K = t.useCallback(
|
|
170
|
+
() => i(e == null ? void 0 : e.endAffix),
|
|
171
|
+
[e == null ? void 0 : e.endAffix, i]
|
|
172
|
+
), Q = t.useCallback(
|
|
173
|
+
() => i(e == null ? void 0 : e.topAffix),
|
|
174
|
+
[e == null ? void 0 : e.topAffix, i]
|
|
175
|
+
), W = t.useMemo(() => {
|
|
176
|
+
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]),
|
|
179
|
+
dir: g ? "rtl" : void 0,
|
|
180
|
+
...n
|
|
170
181
|
} : !1;
|
|
171
|
-
return /* @__PURE__ */
|
|
172
|
-
|
|
182
|
+
return /* @__PURE__ */ t.createElement(
|
|
183
|
+
ie,
|
|
173
184
|
{
|
|
174
|
-
header:
|
|
175
|
-
ref:
|
|
176
|
-
placeholder:
|
|
177
|
-
value:
|
|
178
|
-
onChange:
|
|
179
|
-
onPromptAction:
|
|
180
|
-
mode: (
|
|
181
|
-
rows: (
|
|
182
|
-
maxTextAreaHeight: (
|
|
183
|
-
loading:
|
|
184
|
-
speechToTextButtonConfig:
|
|
185
|
-
actionButtonConfig:
|
|
186
|
-
attachments:
|
|
187
|
-
startAffix:
|
|
185
|
+
header: j(),
|
|
186
|
+
ref: N,
|
|
187
|
+
placeholder: C,
|
|
188
|
+
value: T,
|
|
189
|
+
onChange: O,
|
|
190
|
+
onPromptAction: q,
|
|
191
|
+
mode: (e == null ? void 0 : e.mode) || "multi",
|
|
192
|
+
rows: (e == null ? void 0 : e.rows) || 2,
|
|
193
|
+
maxTextAreaHeight: (e == null ? void 0 : e.maxTextAreaHeight) || "110",
|
|
194
|
+
loading: b,
|
|
195
|
+
speechToTextButtonConfig: V,
|
|
196
|
+
actionButtonConfig: m,
|
|
197
|
+
attachments: M,
|
|
198
|
+
startAffix: J,
|
|
199
|
+
endAffix: e != null && e.endAffix ? K : void 0,
|
|
200
|
+
topAffix: e != null && e.topAffix ? Q : void 0,
|
|
188
201
|
inputAttributes: {
|
|
189
|
-
onClick:
|
|
202
|
+
onClick: P,
|
|
190
203
|
"aria-label": o.toLanguageString(
|
|
191
|
-
|
|
192
|
-
|
|
204
|
+
X,
|
|
205
|
+
l[X]
|
|
193
206
|
)
|
|
194
207
|
}
|
|
195
208
|
}
|
|
196
209
|
);
|
|
197
210
|
}, [
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
C,
|
|
212
|
+
T,
|
|
213
|
+
O,
|
|
200
214
|
q,
|
|
201
|
-
|
|
202
|
-
|
|
215
|
+
e,
|
|
216
|
+
b,
|
|
217
|
+
V,
|
|
203
218
|
k,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
G,
|
|
219
|
+
M,
|
|
220
|
+
j,
|
|
221
|
+
J,
|
|
208
222
|
K,
|
|
223
|
+
Q,
|
|
209
224
|
o,
|
|
210
|
-
|
|
211
|
-
|
|
225
|
+
g,
|
|
226
|
+
P
|
|
212
227
|
]);
|
|
213
|
-
return /* @__PURE__ */
|
|
214
|
-
|
|
228
|
+
return /* @__PURE__ */ t.createElement("div", { className: "k-message-box-wrapper" }, h && h.length > 0 && /* @__PURE__ */ t.createElement(
|
|
229
|
+
oe,
|
|
215
230
|
{
|
|
216
|
-
onSuggestionClick:
|
|
217
|
-
suggestions:
|
|
218
|
-
suggestionTemplate:
|
|
219
|
-
suggestionsLayout:
|
|
220
|
-
dir:
|
|
231
|
+
onSuggestionClick: Z,
|
|
232
|
+
suggestions: h,
|
|
233
|
+
suggestionTemplate: _,
|
|
234
|
+
suggestionsLayout: $,
|
|
235
|
+
dir: B
|
|
221
236
|
}
|
|
222
|
-
),
|
|
237
|
+
), A ? /* @__PURE__ */ t.createElement(A, { messageInput: W }) : W);
|
|
223
238
|
});
|
|
224
|
-
|
|
239
|
+
fe.displayName = "NewMessage";
|
|
225
240
|
export {
|
|
226
|
-
|
|
241
|
+
fe as default
|
|
227
242
|
};
|
package/chat/utils/scroll.d.ts
CHANGED
|
@@ -6,39 +6,31 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
import { Message } from '../../api/message.interface.js';
|
|
9
|
-
import { ChatSuggestion } from '../components/SuggestionsGroup.js';
|
|
10
9
|
import * as React from 'react';
|
|
10
|
+
/** @hidden */
|
|
11
|
+
type AutoScrollThresholdValue = number | string;
|
|
12
|
+
/** @hidden */
|
|
11
13
|
interface UseChatScrollProps {
|
|
12
14
|
viewItemsWrapperRef: React.RefObject<HTMLDivElement | null>;
|
|
13
|
-
isKeyboardNavigationActiveRef: React.
|
|
15
|
+
isKeyboardNavigationActiveRef: React.RefObject<boolean>;
|
|
14
16
|
processedMessages: Message[];
|
|
15
|
-
|
|
17
|
+
authorId?: AutoScrollThresholdValue;
|
|
18
|
+
autoScrollThreshold?: AutoScrollThresholdValue;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*- Intelligent handling of streaming content with complex formatting
|
|
23
|
-
*- Auto-scroll when suggestions appear
|
|
24
|
-
*- ResizeObserver to detect message bubble size changes
|
|
25
|
-
*- MutationObserver to detect content changes with throttling
|
|
26
|
-
*
|
|
27
|
-
*The hook uses multiple strategies to ensure the chat view remains user-friendly,
|
|
28
|
-
*especially when dealing with dynamic and complex content like code blocks.
|
|
21
|
+
* New-message detection is based on the **last message's `id`** rather than
|
|
22
|
+
* array length. This naturally handles the typing-indicator pattern where a
|
|
23
|
+
* `typing: true` placeholder message is replaced in-place by the real message
|
|
24
|
+
* (different `id`, same array length).
|
|
29
25
|
*
|
|
30
26
|
* @hidden
|
|
31
27
|
*/
|
|
32
|
-
export declare const useChatScroll: ({ viewItemsWrapperRef, isKeyboardNavigationActiveRef, processedMessages,
|
|
28
|
+
export declare const useChatScroll: ({ viewItemsWrapperRef, isKeyboardNavigationActiveRef, processedMessages, authorId, autoScrollThreshold }: UseChatScrollProps) => void;
|
|
33
29
|
interface UseHasScrollbarProps {
|
|
34
30
|
elementRef: React.RefObject<HTMLElement | null>;
|
|
35
31
|
}
|
|
36
32
|
/**
|
|
37
|
-
*
|
|
38
|
-
* Uses ResizeObserver to monitor changes in element dimensions.
|
|
39
|
-
*
|
|
40
|
-
* @param elementRef - Reference to the DOM element to monitor for scrollbar presence
|
|
41
|
-
* @returns boolean indicating whether a vertical scrollbar is visible
|
|
33
|
+
* Detects whether a vertical scrollbar is present on the referenced element.
|
|
42
34
|
*
|
|
43
35
|
* @hidden
|
|
44
36
|
*/
|
package/chat/utils/scroll.js
CHANGED
|
@@ -5,8 +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
|
|
9
|
-
|
|
10
|
-
`)||e.includes("<pre>")||e.includes("<code>")||e.includes("<table>")||e.length>500)&&a(!0)}},[o,a]),c.useEffect(()=>{if(i&&i.length>0){const t=window.setTimeout(()=>{a()},B);return()=>{clearTimeout(t)}}},[i,a]),c.useEffect(()=>{if(!n.current)return()=>{};let t;const e=new ResizeObserver(()=>{t&&clearTimeout(t),t=window.setTimeout(()=>{a()},y)}),r=n.current.querySelector(".k-message-list-content");return r&&e.observe(r),()=>{e.disconnect()}},[a,n]);const L=c.useCallback(t=>{var r;if(t.type!=="characterData"&&t.type!=="childList")return!1;const e=(r=t.target.textContent)!=null?r:"";return e.includes("```")||e.includes(`
|
|
11
|
-
|
|
12
|
-
`)||e.includes("<pre>")||e.includes("<code>")||e.includes("<table>")||t.addedNodes&&t.addedNodes.length>2},[]),k=c.useCallback(t=>{let e=!1,r=!1;return t.forEach(s=>{var f;(s.type==="childList"||s.type==="characterData"||s.type==="attributes"&&["class","style"].includes((f=s.attributeName)!=null?f:""))&&(e=!0,L(s)&&(r=!0))}),{shouldScroll:e,hasSignificantChange:r}},[L]),m=c.useCallback((t,e)=>{e.current&&clearTimeout(e.current),t?a(!0):e.current=window.setTimeout(()=>{a()},y)},[a]);c.useEffect(()=>{if(!n.current)return()=>{};const t={current:void 0};let e=0;const r=new MutationObserver(s=>{const f=Date.now();if(f-e<16)return;e=f;const{shouldScroll:S,hasSignificantChange:D}=k(s);S&&u()&&m(D,t)});return r.observe(n.current,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["class","style"]}),()=>{r.disconnect(),t.current&&clearTimeout(t.current)}},[u,k,m,n])},F=({elementRef:n})=>{const[d,o]=c.useState(!1);return c.useEffect(()=>{const i=n.current;if(!i)return;const l=()=>{const T=i.scrollHeight>i.clientHeight;o(T)};l();const u=new ResizeObserver(()=>{l()});u.observe(i);const b=new MutationObserver(()=>{requestAnimationFrame(l)});return b.observe(i,{childList:!0,subtree:!0,characterData:!0}),()=>{u.disconnect(),b.disconnect()}},[n]),d};exports.useChatScroll=q;exports.useHasScrollbar=F;
|
|
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;
|