@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
package/chat/utils/scroll.mjs
CHANGED
|
@@ -5,195 +5,137 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import * as
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
import * as s from "react";
|
|
9
|
+
const I = 250, P = 100, y = "20%", z = (e) => {
|
|
10
|
+
const r = e.querySelector(".k-message-pinned");
|
|
11
|
+
return r ? r.offsetHeight : 0;
|
|
12
|
+
}, U = (e, r) => {
|
|
13
|
+
const n = e != null ? e : y;
|
|
14
|
+
let c;
|
|
15
|
+
if (typeof n == "number")
|
|
16
|
+
c = n;
|
|
17
|
+
else {
|
|
18
|
+
const l = /^(-?\d+(?:\.\d+)?)%$/.exec(String(n));
|
|
19
|
+
if (l)
|
|
20
|
+
c = Number.parseFloat(l[1]) / 100 * r;
|
|
21
|
+
else {
|
|
22
|
+
const u = Number.parseFloat(String(n));
|
|
23
|
+
c = Number.isNaN(u) ? 0.2 * r : u;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Math.min(c, r);
|
|
27
|
+
}, V = (e) => {
|
|
28
|
+
const { scrollHeight: r, scrollTop: n, clientHeight: c } = e;
|
|
29
|
+
return !(r > c) || r - n - c <= P;
|
|
30
|
+
}, v = (e) => {
|
|
31
|
+
e.scrollTop = e.scrollHeight - e.clientHeight;
|
|
32
|
+
}, Y = (e) => {
|
|
33
|
+
const r = e.querySelectorAll(".k-message");
|
|
34
|
+
return r.length > 0 ? r[r.length - 1] : null;
|
|
35
|
+
}, j = ({
|
|
36
|
+
viewItemsWrapperRef: e,
|
|
37
|
+
isKeyboardNavigationActiveRef: r,
|
|
38
|
+
processedMessages: n,
|
|
39
|
+
authorId: c,
|
|
40
|
+
autoScrollThreshold: l
|
|
14
41
|
}) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
o(), setTimeout(() => {
|
|
49
|
-
!l() && n.current && f();
|
|
50
|
-
}, 25);
|
|
51
|
-
}, [o, l, n, f]), i = c.useCallback(
|
|
52
|
-
(t = !1) => {
|
|
53
|
-
if (!n.current || T.current)
|
|
54
|
-
return;
|
|
55
|
-
l() && (t ? L() : E());
|
|
56
|
-
},
|
|
57
|
-
[
|
|
58
|
-
l,
|
|
59
|
-
L,
|
|
60
|
-
E,
|
|
61
|
-
n,
|
|
62
|
-
T
|
|
63
|
-
]
|
|
64
|
-
);
|
|
65
|
-
c.useEffect(() => {
|
|
66
|
-
const t = window.setTimeout(() => o(), x);
|
|
67
|
-
return () => {
|
|
68
|
-
clearTimeout(t);
|
|
69
|
-
};
|
|
70
|
-
}, [o]), c.useEffect(() => {
|
|
71
|
-
f();
|
|
72
|
-
}, [s.length, f]);
|
|
73
|
-
const O = c.useRef(/* @__PURE__ */ new Map());
|
|
74
|
-
c.useEffect(() => {
|
|
75
|
-
const t = /* @__PURE__ */ new Map();
|
|
76
|
-
let e = !1;
|
|
77
|
-
s.forEach((r) => {
|
|
78
|
-
if (r.id !== void 0) {
|
|
79
|
-
const u = r.id, a = !!r.typing, S = O.current.get(u);
|
|
80
|
-
t.set(u, a), S === !0 && a === !1 && (e = !0);
|
|
81
|
-
}
|
|
82
|
-
}), O.current = t, e && f();
|
|
83
|
-
}, [s, f]), c.useEffect(() => {
|
|
84
|
-
const t = window.setTimeout(() => {
|
|
85
|
-
i();
|
|
86
|
-
}, C);
|
|
87
|
-
return () => {
|
|
88
|
-
clearTimeout(t);
|
|
89
|
-
};
|
|
90
|
-
}, [s, i]), c.useEffect(() => {
|
|
91
|
-
if (s.length > 0) {
|
|
92
|
-
const t = s[s.length - 1], e = (t == null ? void 0 : t.text) || "";
|
|
93
|
-
(e.includes("```") || e.includes(`
|
|
94
|
-
|
|
95
|
-
`) || e.includes("<pre>") || e.includes("<code>") || e.includes("<table>") || e.length > 500) && i(!0);
|
|
42
|
+
var O;
|
|
43
|
+
const u = s.useRef(c), h = s.useRef(l);
|
|
44
|
+
s.useEffect(() => {
|
|
45
|
+
u.current = c;
|
|
46
|
+
}), s.useEffect(() => {
|
|
47
|
+
h.current = l;
|
|
48
|
+
}), s.useEffect(() => {
|
|
49
|
+
const t = globalThis.setTimeout(() => {
|
|
50
|
+
e.current && v(e.current);
|
|
51
|
+
}, I);
|
|
52
|
+
return () => clearTimeout(t);
|
|
53
|
+
}, [e]);
|
|
54
|
+
const L = s.useRef(void 0), p = s.useRef(0), M = s.useRef(!0), E = s.useRef(!0), a = s.useRef(!1), f = s.useRef(null), _ = (n.length > 0 ? (O = n.at(-1)) == null ? void 0 : O.id : void 0) !== L.current, N = n.length > p.current;
|
|
55
|
+
if (_ || N) {
|
|
56
|
+
const t = e.current;
|
|
57
|
+
E.current = t ? V(t) : !0;
|
|
58
|
+
}
|
|
59
|
+
s.useEffect(() => {
|
|
60
|
+
var A, F;
|
|
61
|
+
const t = n.length, m = t > 0 ? (A = n[t - 1]) == null ? void 0 : A.id : void 0, H = L.current, T = p.current, S = M.current;
|
|
62
|
+
if (L.current = m, p.current = t, M.current = !1, t === 0)
|
|
63
|
+
return;
|
|
64
|
+
const o = e.current;
|
|
65
|
+
if (!o || r.current)
|
|
66
|
+
return;
|
|
67
|
+
if (!(!S && m !== H)) {
|
|
68
|
+
(S || t > T) && (v(o), a.current = !1, f.current = null);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const i = n[t - 1];
|
|
72
|
+
if (u.current !== void 0 && ((F = i == null ? void 0 : i.author) == null ? void 0 : F.id) !== void 0 && String(i.author.id) === String(u.current)) {
|
|
73
|
+
v(o), a.current = !1, f.current = null;
|
|
74
|
+
return;
|
|
96
75
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
i();
|
|
101
|
-
}, H);
|
|
102
|
-
return () => {
|
|
103
|
-
clearTimeout(t);
|
|
104
|
-
};
|
|
76
|
+
if (!E.current) {
|
|
77
|
+
a.current = !1, f.current = null;
|
|
78
|
+
return;
|
|
105
79
|
}
|
|
106
|
-
|
|
107
|
-
if (!
|
|
108
|
-
return
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const e = (r = t.target.textContent) != null ? r : "";
|
|
125
|
-
return e.includes("```") || e.includes(`
|
|
126
|
-
|
|
127
|
-
`) || e.includes("<pre>") || e.includes("<code>") || e.includes("<table>") || t.addedNodes && t.addedNodes.length > 2;
|
|
128
|
-
}, []), k = c.useCallback(
|
|
129
|
-
(t) => {
|
|
130
|
-
let e = !1, r = !1;
|
|
131
|
-
return t.forEach((u) => {
|
|
132
|
-
var a;
|
|
133
|
-
(u.type === "childList" || u.type === "characterData" || u.type === "attributes" && ["class", "style"].includes((a = u.attributeName) != null ? a : "")) && (e = !0, g(u) && (r = !0));
|
|
134
|
-
}), { shouldScroll: e, hasSignificantChange: r };
|
|
135
|
-
},
|
|
136
|
-
[g]
|
|
137
|
-
), D = c.useCallback(
|
|
138
|
-
(t, e) => {
|
|
139
|
-
e.current && clearTimeout(e.current), t ? i(!0) : e.current = window.setTimeout(() => {
|
|
140
|
-
i();
|
|
141
|
-
}, C);
|
|
142
|
-
},
|
|
143
|
-
[i]
|
|
144
|
-
);
|
|
145
|
-
c.useEffect(() => {
|
|
146
|
-
if (!n.current)
|
|
147
|
-
return () => {
|
|
148
|
-
};
|
|
149
|
-
const t = { current: void 0 };
|
|
150
|
-
let e = 0;
|
|
151
|
-
const r = new MutationObserver((u) => {
|
|
152
|
-
const a = Date.now();
|
|
153
|
-
if (a - e < 16)
|
|
80
|
+
const d = Y(o);
|
|
81
|
+
if (!d)
|
|
82
|
+
return;
|
|
83
|
+
const b = z(o), B = Math.max(0, o.clientHeight - b), D = U(h.current, B), k = d.getBoundingClientRect().top - o.getBoundingClientRect().top + o.scrollTop, C = Math.max(0, k - D - b), q = Math.max(0, o.scrollHeight - o.clientHeight), x = Math.min(C, q);
|
|
84
|
+
x > o.scrollTop && o.scrollTo({
|
|
85
|
+
top: x,
|
|
86
|
+
behavior: "smooth"
|
|
87
|
+
}), f.current = C, a.current = !0;
|
|
88
|
+
}, [n, e, r]), s.useEffect(() => {
|
|
89
|
+
const t = e.current;
|
|
90
|
+
if (!t)
|
|
91
|
+
return;
|
|
92
|
+
let m = t.querySelectorAll(".k-message").length, H = t.scrollHeight, T = t.scrollTop;
|
|
93
|
+
const S = () => {
|
|
94
|
+
const g = t.scrollTop;
|
|
95
|
+
a.current && g < T && (a.current = !1, f.current = null), T = g;
|
|
96
|
+
}, o = new MutationObserver(() => {
|
|
97
|
+
if (r.current)
|
|
154
98
|
return;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
99
|
+
const g = t.querySelectorAll(".k-message").length, i = t.scrollHeight;
|
|
100
|
+
if (g === m && i > H && a.current) {
|
|
101
|
+
const R = i - t.clientHeight, d = f.current, b = d === null ? R : Math.min(R, d);
|
|
102
|
+
b > t.scrollTop && (t.scrollTop = b), T = t.scrollTop;
|
|
103
|
+
}
|
|
104
|
+
m = g, H = i;
|
|
158
105
|
});
|
|
159
|
-
return
|
|
106
|
+
return o.observe(t, {
|
|
160
107
|
childList: !0,
|
|
161
108
|
subtree: !0,
|
|
162
|
-
characterData: !0
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}), () => {
|
|
166
|
-
r.disconnect(), t.current && clearTimeout(t.current);
|
|
109
|
+
characterData: !0
|
|
110
|
+
}), t.addEventListener("scroll", S, { passive: !0 }), () => {
|
|
111
|
+
o.disconnect(), t.removeEventListener("scroll", S);
|
|
167
112
|
};
|
|
168
|
-
}, [
|
|
169
|
-
},
|
|
170
|
-
const [
|
|
171
|
-
return
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
113
|
+
}, [e, r]);
|
|
114
|
+
}, w = ({ elementRef: e }) => {
|
|
115
|
+
const [r, n] = s.useState(!1);
|
|
116
|
+
return s.useEffect(() => {
|
|
117
|
+
const c = e.current;
|
|
118
|
+
if (!c)
|
|
174
119
|
return;
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
s(b);
|
|
120
|
+
const l = () => {
|
|
121
|
+
n(c.scrollHeight > c.clientHeight);
|
|
178
122
|
};
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
l.observe(d);
|
|
123
|
+
l();
|
|
124
|
+
const u = new ResizeObserver(l);
|
|
125
|
+
u.observe(c);
|
|
184
126
|
const h = new MutationObserver(() => {
|
|
185
|
-
requestAnimationFrame(
|
|
127
|
+
requestAnimationFrame(l);
|
|
186
128
|
});
|
|
187
|
-
return h.observe(
|
|
129
|
+
return h.observe(c, {
|
|
188
130
|
childList: !0,
|
|
189
131
|
subtree: !0,
|
|
190
132
|
characterData: !0
|
|
191
133
|
}), () => {
|
|
192
|
-
|
|
134
|
+
u.disconnect(), h.disconnect();
|
|
193
135
|
};
|
|
194
|
-
}, [
|
|
136
|
+
}, [e]), r;
|
|
195
137
|
};
|
|
196
138
|
export {
|
|
197
|
-
|
|
198
|
-
|
|
139
|
+
j as useChatScroll,
|
|
140
|
+
w as useHasScrollbar
|
|
199
141
|
};
|