@progress/kendo-react-conversational-ui 14.3.0-develop.8 → 14.3.0

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.
@@ -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 c from "react";
9
- const A = 50, x = 250, C = 50, H = 100, _ = ({
10
- viewItemsWrapperRef: n,
11
- isKeyboardNavigationActiveRef: T,
12
- processedMessages: s,
13
- suggestions: d
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
- const o = c.useCallback(() => {
16
- n.current && (n.current.scrollTop = n.current.scrollHeight - n.current.clientHeight);
17
- }, [n]), l = c.useCallback(() => {
18
- if (!n.current)
19
- return !0;
20
- const t = n.current, { scrollTop: e, scrollHeight: r, clientHeight: u } = t, a = A + 25;
21
- return r - e - u < a;
22
- }, [n]), h = c.useCallback((t) => t === 0 ? 16 : t <= 2 ? 32 * t : Math.min(50 * t, 200), []), b = c.useCallback(
23
- (t, e) => {
24
- const r = h(t);
25
- setTimeout(() => {
26
- !l() && n.current && e(t + 1);
27
- }, r);
28
- },
29
- [h, l, n]
30
- ), f = c.useCallback(() => {
31
- const t = (e = 0) => {
32
- e > 5 || requestAnimationFrame(() => {
33
- o(), b(e, t);
34
- });
35
- };
36
- t();
37
- }, [o, b]), y = c.useCallback(() => {
38
- o(), setTimeout(() => {
39
- !l() && n.current && o();
40
- }, 50);
41
- }, [o, l, n]), E = c.useCallback(() => {
42
- requestAnimationFrame(() => {
43
- requestAnimationFrame(() => {
44
- requestAnimationFrame(y);
45
- });
46
- });
47
- }, [y]), L = c.useCallback(() => {
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
- }, [s, i]), c.useEffect(() => {
98
- if (d && d.length > 0) {
99
- const t = window.setTimeout(() => {
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
- }, [d, i]), c.useEffect(() => {
107
- if (!n.current)
108
- return () => {
109
- };
110
- let t;
111
- const e = new ResizeObserver(() => {
112
- t && clearTimeout(t), t = window.setTimeout(() => {
113
- i();
114
- }, C);
115
- }), r = n.current.querySelector(".k-message-list-content");
116
- return r && e.observe(r), () => {
117
- e.disconnect();
118
- };
119
- }, [i, n]);
120
- const g = c.useCallback((t) => {
121
- var r;
122
- if (t.type !== "characterData" && t.type !== "childList")
123
- return !1;
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
- e = a;
156
- const { shouldScroll: S, hasSignificantChange: m } = k(u);
157
- S && l() && D(m, t);
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 r.observe(n.current, {
106
+ return o.observe(t, {
160
107
  childList: !0,
161
108
  subtree: !0,
162
- characterData: !0,
163
- attributes: !0,
164
- attributeFilter: ["class", "style"]
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
- }, [l, k, D, n]);
169
- }, B = ({ elementRef: n }) => {
170
- const [T, s] = c.useState(!1);
171
- return c.useEffect(() => {
172
- const d = n.current;
173
- if (!d)
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 o = () => {
176
- const b = d.scrollHeight > d.clientHeight;
177
- s(b);
120
+ const l = () => {
121
+ n(c.scrollHeight > c.clientHeight);
178
122
  };
179
- o();
180
- const l = new ResizeObserver(() => {
181
- o();
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(o);
127
+ requestAnimationFrame(l);
186
128
  });
187
- return h.observe(d, {
129
+ return h.observe(c, {
188
130
  childList: !0,
189
131
  subtree: !0,
190
132
  characterData: !0
191
133
  }), () => {
192
- l.disconnect(), h.disconnect();
134
+ u.disconnect(), h.disconnect();
193
135
  };
194
- }, [n]), T;
136
+ }, [e]), r;
195
137
  };
196
138
  export {
197
- _ as useChatScroll,
198
- B as useHasScrollbar
139
+ j as useChatScroll,
140
+ w as useHasScrollbar
199
141
  };