@progress/kendo-react-conversational-ui 14.5.0-develop.9 → 15.0.0-develop.2

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.
@@ -6,12 +6,12 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import * as r from "react";
9
- import { scrollToMessageById as tt } from "../utils.mjs";
10
- const nt = 50, L = 100, ct = ({
9
+ import { scrollToMessageById as nt } from "../utils.mjs";
10
+ const rt = 50, L = 100, ut = ({
11
11
  scrollMode: W,
12
12
  processedMessages: n,
13
13
  total: Z,
14
- pageSize: e = nt,
14
+ pageSize: f = rt,
15
15
  startIndex: j,
16
16
  endIndex: K,
17
17
  onLoadMoreMessages: u,
@@ -19,121 +19,123 @@ const nt = 50, L = 100, ct = ({
19
19
  viewItemsWrapperRef: l,
20
20
  authorId: v
21
21
  }) => {
22
- const k = r.useRef(!1), x = W === "endless", i = Z != null ? Z : n.length, S = x && n.length === i && !k.current, h = x && (n.length < i || k.current);
22
+ const k = r.useRef(!1), m = W === "endless", i = Z != null ? Z : n.length, x = m && n.length === i && !k.current, h = m && (n.length < i || k.current);
23
23
  h && (k.current = !0);
24
- const [A, a] = r.useState(-1), [m, y] = r.useState(-1), N = r.useRef(A), _ = r.useRef(m);
25
- N.current = A, _.current = m;
26
- const o = r.useRef(!1), P = r.useRef(0), w = r.useRef(0), D = r.useRef(!1), I = r.useRef(i), $ = r.useRef(v);
27
- $.current = v;
28
- const G = r.useRef(!1), U = r.useRef(null), C = r.useRef(!1), J = r.useRef(!1), Q = r.useRef(!0), V = r.useRef(i);
24
+ const [A, B] = r.useState(-1), [T, D] = r.useState(-1), N = r.useRef(A), C = r.useRef(T);
25
+ N.current = A, C.current = T;
26
+ const o = r.useRef(!1), d = r.useRef(0), P = r.useRef(0), w = r.useRef(0), q = r.useRef(!1), I = r.useRef(i), _ = r.useRef(v);
27
+ _.current = v;
28
+ const $ = r.useRef(!1), G = r.useRef(null), U = r.useRef(!1), J = r.useRef(!1), Q = r.useRef(!0), V = r.useRef(i);
29
29
  r.useEffect(() => {
30
- if (S) {
30
+ if (x) {
31
31
  if (k.current) {
32
- (A === -1 || m === -1) && (a(0), y(n.length));
32
+ (A === -1 || T === -1) && (B(0), D(n.length));
33
33
  return;
34
34
  }
35
- if (A === -1 || m === -1) {
36
- const t = Math.max(0, n.length - e), c = n.length;
37
- a(t), y(c);
38
- } else if (m < n.length) {
35
+ if (A === -1 || T === -1) {
36
+ const t = Math.max(0, n.length - f), c = n.length;
37
+ B(t), D(c);
38
+ } else if (T < n.length) {
39
39
  const t = I.current;
40
- if (_.current >= t)
41
- y(n.length);
40
+ if (C.current >= t)
41
+ D(n.length);
42
42
  else if (n.length > t && n.slice(t).some(
43
- (f) => {
43
+ (e) => {
44
44
  var H;
45
- return ((H = f.author) == null ? void 0 : H.id) !== void 0 && String(f.author.id) === String($.current);
45
+ return ((H = e.author) == null ? void 0 : H.id) !== void 0 && String(e.author.id) === String(_.current);
46
46
  }
47
47
  )) {
48
- const f = Math.max(0, n.length - e);
49
- a(f), y(n.length), C.current = !0;
48
+ const e = Math.max(0, n.length - f);
49
+ B(e), D(n.length), U.current = !0;
50
50
  }
51
51
  }
52
52
  I.current = i;
53
53
  }
54
- }, [S, n.length, e, A, m, i]);
55
- const O = j != null ? j : 0, R = K != null ? K : n.length, d = r.useCallback(() => {
54
+ }, [x, n.length, f, A, T, i]);
55
+ const O = j != null ? j : 0, R = K != null ? K : n.length, g = r.useCallback(() => {
56
56
  const t = l.current;
57
- t && (P.current = t.scrollHeight, w.current = t.scrollTop);
58
- }, [l]), B = r.useCallback(
57
+ t && (d.current = t.scrollHeight, P.current = t.scrollTop, w.current = t.querySelectorAll("[data-message-id]").length);
58
+ }, [l]), y = r.useCallback(
59
59
  (t) => {
60
- var E, f, H;
61
- const c = (E = l.current) == null ? void 0 : E.closest(".k-chat"), T = ((H = (f = l.current) == null ? void 0 : f.querySelector(".k-message-pinned")) == null ? void 0 : H.offsetHeight) || 0;
62
- tt(t, c, T);
60
+ var E, e, H;
61
+ const c = (E = l.current) == null ? void 0 : E.closest(".k-chat"), S = ((H = (e = l.current) == null ? void 0 : e.querySelector(".k-message-pinned")) == null ? void 0 : H.offsetHeight) || 0;
62
+ nt(t, c, S);
63
63
  },
64
64
  [l]
65
65
  );
66
66
  r.useLayoutEffect(() => {
67
- if (!D.current)
67
+ if (!q.current)
68
68
  return;
69
69
  const t = l.current;
70
70
  if (!t) {
71
- D.current = !1;
71
+ q.current = !1;
72
72
  return;
73
73
  }
74
- const c = t.scrollHeight - P.current;
75
- c > 0 && (t.scrollTop = w.current + c), D.current = !1, o.current = !1;
74
+ if (t.querySelectorAll("[data-message-id]").length <= w.current)
75
+ return;
76
+ const S = t.scrollHeight - d.current;
77
+ S > 0 && (t.scrollTop = P.current + S), q.current = !1, o.current = !1;
76
78
  }), r.useLayoutEffect(() => {
77
- if (!C.current)
79
+ if (!U.current)
78
80
  return;
79
81
  const t = l.current;
80
82
  if (!t) {
81
- C.current = !1;
83
+ U.current = !1;
82
84
  return;
83
85
  }
84
- m >= n.length && m > 0 && (C.current = !1, t.scrollTop = t.scrollHeight - t.clientHeight);
86
+ T >= n.length && T > 0 && (U.current = !1, t.scrollTop = t.scrollHeight - t.clientHeight);
85
87
  });
86
88
  const z = r.useRef(!1);
87
89
  r.useLayoutEffect(() => {
88
- if (!x || z.current)
90
+ if (!m || z.current)
89
91
  return;
90
92
  const t = l.current;
91
93
  t && t.querySelector("[data-message-id]") && (t.scrollTop = t.scrollHeight - t.clientHeight, z.current = !0);
92
94
  }), r.useEffect(() => {
93
- if (!x)
95
+ if (!m)
94
96
  return;
95
97
  const t = l.current;
96
98
  if (!t)
97
99
  return;
98
100
  let c = t.scrollTop;
99
- const T = () => {
100
- const { scrollTop: E, scrollHeight: f, clientHeight: H } = t, Y = E < c, M = E > c;
101
+ const S = () => {
102
+ const { scrollTop: E, scrollHeight: e, clientHeight: H } = t, Y = E < c, tt = E > c;
101
103
  if (c = E, !o.current) {
102
104
  if (Y && E <= L) {
103
- if (S) {
104
- const q = N.current;
105
- if (q > 0) {
106
- const b = Math.max(0, q - e);
107
- D.current = !0, d(), a(b), u == null || u({ startIndex: b, endIndex: _.current });
105
+ if (x) {
106
+ const a = N.current;
107
+ if (a > 0) {
108
+ const b = Math.max(0, a - f);
109
+ q.current = !0, g(), B(b), u == null || u({ startIndex: b, endIndex: C.current });
108
110
  }
109
111
  } else if (h && O > 0) {
110
112
  o.current = !0;
111
- const q = Math.max(0, O - e);
112
- D.current = !0, d(), u == null || u({ startIndex: q, endIndex: R });
113
+ const a = Math.max(0, O - f);
114
+ q.current = !0, g(), u == null || u({ startIndex: a, endIndex: R });
113
115
  }
114
116
  }
115
- if (M && f - E - H <= L) {
116
- if (S) {
117
- const q = _.current;
118
- if (q < n.length) {
119
- const b = Math.min(n.length, q + e);
120
- J.current = !0, y(b), u == null || u({ startIndex: N.current, endIndex: b });
117
+ if (tt && e - E - H <= L) {
118
+ if (x) {
119
+ const a = C.current;
120
+ if (a < n.length) {
121
+ const b = Math.min(n.length, a + f);
122
+ J.current = !0, D(b), u == null || u({ startIndex: N.current, endIndex: b });
121
123
  }
122
124
  } else if (h && R < i) {
123
125
  o.current = !0, J.current = !0;
124
- const q = Math.min(i, R + e);
125
- u == null || u({ startIndex: O, endIndex: q });
126
+ const a = Math.min(i, R + f);
127
+ u == null || u({ startIndex: O, endIndex: a });
126
128
  }
127
129
  }
128
130
  }
129
131
  };
130
- return t.addEventListener("scroll", T, { passive: !0 }), () => t.removeEventListener("scroll", T);
132
+ return t.addEventListener("scroll", S, { passive: !0 }), () => t.removeEventListener("scroll", S);
131
133
  }, [
134
+ m,
132
135
  x,
133
- S,
134
136
  h,
135
137
  l,
136
- e,
138
+ f,
137
139
  n.length,
138
140
  O,
139
141
  R,
@@ -146,86 +148,86 @@ const nt = 50, L = 100, ct = ({
146
148
  V.current = i, Q.current = t;
147
149
  return;
148
150
  }
149
- const c = V.current, T = Q.current;
150
- if (V.current = i, Q.current = t, i > c && !T && t) {
151
- const f = n[n.length - 1];
152
- $.current !== void 0 && ((E = f == null ? void 0 : f.author) == null ? void 0 : E.id) !== void 0 && String(f.author.id) === String($.current) && (G.current = !0, J.current = !0);
151
+ const c = V.current, S = Q.current;
152
+ if (V.current = i, Q.current = t, i > c && !S && t) {
153
+ const e = n[n.length - 1];
154
+ _.current !== void 0 && ((E = e == null ? void 0 : e.author) == null ? void 0 : E.id) !== void 0 && String(e.author.id) === String(_.current) && ($.current = !0, J.current = !0);
153
155
  }
154
156
  }, [h, i, R, n]), r.useEffect(() => {
155
- !h || !G.current || (G.current = !1, o.current = !1, requestAnimationFrame(() => {
157
+ !h || !$.current || ($.current = !1, o.current = !1, requestAnimationFrame(() => {
156
158
  const t = l.current;
157
159
  t && (t.scrollTop = t.scrollHeight - t.clientHeight);
158
160
  }));
159
161
  }, [h, n, l]), r.useEffect(() => {
160
- if (!h || U.current === null)
162
+ if (!h || G.current === null)
161
163
  return;
162
- const t = U.current, c = l.current;
164
+ const t = G.current, c = l.current;
163
165
  if (!c)
164
166
  return;
165
- c.querySelector(`[data-message-id="${t}"]`) && (U.current = null, o.current = !1, requestAnimationFrame(() => {
166
- B(t);
167
+ c.querySelector(`[data-message-id="${t}"]`) && (G.current = null, o.current = !1, requestAnimationFrame(() => {
168
+ y(t);
167
169
  }));
168
- }, [h, n, l, B]), r.useEffect(() => {
169
- h && o.current && !D.current && (o.current = !1);
170
+ }, [h, n, l, y]), r.useEffect(() => {
171
+ h && o.current && !q.current && (o.current = !1);
170
172
  }, [h, O, R]);
171
- const g = r.useMemo(() => {
172
- if (S) {
173
- const t = Math.max(0, A), c = Math.min(n.length, m);
173
+ const s = r.useMemo(() => {
174
+ if (x) {
175
+ const t = Math.max(0, A), c = Math.min(n.length, T);
174
176
  if (t >= c) {
175
- const T = Math.max(0, n.length - e);
176
- return n.slice(T);
177
+ const S = Math.max(0, n.length - f);
178
+ return n.slice(S);
177
179
  }
178
180
  return n.slice(t, c);
179
181
  }
180
182
  return n;
181
- }, [S, n, A, m, e]), X = r.useMemo(() => x ? S ? m >= n.length : R >= i : !0, [x, S, m, n.length, R, i]), s = r.useCallback(() => {
182
- if (!x || X) {
183
+ }, [x, n, A, T, f]), X = r.useMemo(() => m ? x ? T >= n.length : R >= i : !0, [m, x, T, n.length, R, i]), p = r.useCallback(() => {
184
+ if (!m || X) {
183
185
  const t = l.current;
184
186
  t && t.scrollTo({ top: t.scrollHeight - t.clientHeight, behavior: "smooth" });
185
187
  return;
186
188
  }
187
189
  if (!o.current) {
188
- if (S) {
189
- const t = Math.max(0, n.length - e);
190
- a(t), y(n.length), u == null || u({ startIndex: t, endIndex: n.length }), requestAnimationFrame(() => {
190
+ if (x) {
191
+ const t = Math.max(0, n.length - f);
192
+ B(t), D(n.length), u == null || u({ startIndex: t, endIndex: n.length }), requestAnimationFrame(() => {
191
193
  const c = l.current;
192
194
  c && (c.scrollTop = c.scrollHeight - c.clientHeight);
193
195
  });
194
196
  } else if (h) {
195
- G.current = !0, D.current = !1, o.current = !0;
196
- const t = Math.max(0, i - e);
197
+ $.current = !0, q.current = !1, o.current = !0;
198
+ const t = Math.max(0, i - f);
197
199
  u == null || u({ startIndex: t, endIndex: i });
198
200
  }
199
201
  }
200
202
  }, [
203
+ m,
201
204
  x,
202
- S,
203
205
  h,
204
206
  X,
205
207
  n.length,
206
- e,
208
+ f,
207
209
  i,
208
210
  u,
209
211
  l
210
- ]), p = r.useCallback(
212
+ ]), M = r.useCallback(
211
213
  (t) => {
212
- if (!x)
213
- B(t);
214
- else if (S) {
214
+ if (!m)
215
+ y(t);
216
+ else if (x) {
215
217
  const c = l.current;
216
218
  if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
217
- B(t);
219
+ y(t);
218
220
  else {
219
221
  if (o.current)
220
222
  return;
221
223
  const E = n.findIndex(
222
- (f) => f.id === t || String(f.id) === String(t)
224
+ (e) => e.id === t || String(e.id) === String(t)
223
225
  );
224
226
  if (E >= 0) {
225
- const f = Math.floor(e / 2), H = Math.max(0, E - f), Y = Math.min(n.length, H + e);
226
- o.current = !0, a(H), y(Y), requestAnimationFrame(() => {
227
+ const e = Math.floor(f / 2), H = Math.max(0, E - e), Y = Math.min(n.length, H + f);
228
+ o.current = !0, B(H), D(Y), requestAnimationFrame(() => {
227
229
  requestAnimationFrame(() => {
228
- B(t), o.current = !1;
230
+ y(t), o.current = !1;
229
231
  });
230
232
  });
231
233
  }
@@ -233,35 +235,35 @@ const nt = 50, L = 100, ct = ({
233
235
  } else if (h) {
234
236
  const c = l.current;
235
237
  if (c == null ? void 0 : c.querySelector(`[data-message-id="${t}"]`))
236
- B(t);
238
+ y(t);
237
239
  else {
238
240
  if (o.current)
239
241
  return;
240
- U.current = t, D.current = !1, o.current = !0;
242
+ G.current = t, q.current = !1, o.current = !0;
241
243
  }
242
244
  }
243
245
  F == null || F({ id: t });
244
246
  },
245
247
  [
248
+ m,
246
249
  x,
247
- S,
248
250
  h,
249
251
  l,
250
252
  n,
251
- e,
253
+ f,
252
254
  F,
253
- B
255
+ y
254
256
  ]
255
257
  );
256
258
  return {
257
- renderedMessages: g,
258
- handleScrollToBottom: s,
259
- handleReferencedMessageClick: p,
260
- isEndless: x,
259
+ renderedMessages: s,
260
+ handleScrollToBottom: p,
261
+ handleReferencedMessageClick: M,
262
+ isEndless: m,
261
263
  isOnLastBatch: X,
262
264
  skipAutoScrollRef: J
263
265
  };
264
266
  };
265
267
  export {
266
- ct as useEndlessScroll
268
+ ut as useEndlessScroll
267
269
  };