@progress/kendo-react-conversational-ui 14.3.0-develop.1 → 14.3.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.
@@ -6,222 +6,237 @@
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
8
  import { classNames as te } from "@progress/kendo-react-common";
9
- import * as e from "react";
10
- import { Button as oe } from "@progress/kendo-react-buttons";
11
- import { SuggestionGroup as ne } from "./SuggestionsGroup.mjs";
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 se } from "./ChatContext.mjs";
14
- import { useLocalization as re } from "@progress/kendo-react-intl";
15
- import { getDeletedMessageText as le, isAuthor as ce } from "../utils.mjs";
16
- import { closeReply as y, messages as r, chatStopGenerating as v, newMessageSendButton as w, newMessageMessageInput as W, attachFile as E } 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
- const X = e.memo(
20
- ({ affixProps: A, uploadConfig: g, localizationService: i, onFilesSelect: d, onFileRemove: h }) => {
21
- const C = typeof g == "object" ? g : {};
22
- return g !== !1 ? /* @__PURE__ */ e.createElement(
23
- ie,
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
- ...A.uploadButtonProps,
25
+ ...R.uploadButtonProps,
26
26
  fillMode: "clear",
27
- "aria-label": i.toLanguageString(E, r[E]),
28
- title: i.toLanguageString(E, r[E]),
29
- ...C,
30
- onSelectAttachments: d,
31
- onRemoveAttachment: h
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
- X.displayName = "UploadButtonAffix";
37
- const me = e.forwardRef((A, g) => {
36
+ Y.displayName = "UploadButtonAffix";
37
+ const fe = t.forwardRef((R, p) => {
38
38
  const {
39
- onSendMessage: i,
40
- isDirectionRightToLeft: d,
41
- placeholder: h,
42
- MessageBox: C,
43
- suggestions: x,
44
- onSuggestionClick: Y,
45
- inputValue: L,
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: Z,
48
- sendButtonConfig: S,
49
- onInputClick: I,
50
- suggestionsLayout: _,
51
- dir: $,
52
- messageBoxSettings: a,
53
- loading: k
54
- } = A, { replyToMessage: s, setReplyToMessage: T, user: b, messageListScrollContainerRef: c, speechToTextConfig: N, uploadConfig: P } = se(), [ee, V] = e.useState(""), [B, R] = e.useState([]), [D, H] = e.useState(!1), F = e.useRef(null), o = re(), p = L !== void 0, M = p ? L : ee, l = e.useCallback(() => {
55
- F.current !== null && F.current.focus();
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
- e.useEffect(() => {
58
- s && l();
59
- }, [s, l]), e.useLayoutEffect(() => {
60
- D && (c != null && c.current) && (c.current.scrollTop = c.current.scrollHeight - c.current.clientHeight, H(!1));
61
- }, [D, c]);
62
- const U = e.useCallback(
63
- (t) => {
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: b,
68
- text: M || "",
65
+ author: x,
66
+ text: T || "",
69
67
  timestamp: /* @__PURE__ */ new Date(),
70
- replyToId: s ? s.id : void 0,
71
- files: B.map((m) => ({
72
- name: m.name,
73
- size: m.size,
74
- type: m.extension,
75
- rawFile: m.getRawFile ? m.getRawFile() : m
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
- T(null), i(f, t), R([]), p || V(""), u && u(""), H(!0), l();
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
- l,
90
- p
87
+ c,
88
+ d
91
89
  ]
92
90
  );
93
- e.useImperativeHandle(
94
- g,
91
+ t.useImperativeHandle(
92
+ p,
95
93
  () => ({
96
- focusInput: l
94
+ focusInput: c
97
95
  }),
98
- [l]
96
+ [c]
99
97
  );
100
- const z = e.useCallback((t) => {
101
- R((n) => n.filter((f) => f.name !== t));
102
- }, []), j = e.useCallback(
103
- (t, n) => t.isDeleted ? le(n, o) : t.text,
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
- ), G = e.useCallback(() => {
106
- if (s) {
107
- const t = ce(b, s);
108
- return /* @__PURE__ */ e.createElement(
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
- t ? "k-message-reference-sender" : "k-message-reference-receiver"
111
+ n ? "k-message-reference-sender" : "k-message-reference-receiver"
114
112
  )
115
113
  },
116
- /* @__PURE__ */ e.createElement("div", { className: "k-message-reference-content" }, j(s, t)),
117
- /* @__PURE__ */ e.createElement("span", { className: "k-spacer" }),
118
- /* @__PURE__ */ e.createElement(
119
- oe,
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: () => T(null),
124
- "aria-label": o.toLanguageString(y, r[y]),
125
- title: o.toLanguageString(y, r[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
- }, [s, b, j, T, o]), O = e.useCallback((t) => {
129
+ }, [r, x, S, v, o]), G = t.useCallback((n) => {
132
130
  try {
133
- const n = Array.from(t.allFiles);
134
- R(n);
131
+ const a = Array.from(n.allFiles);
132
+ I(a);
135
133
  } catch {
136
134
  }
137
135
  }, []);
138
- e.useEffect(() => {
139
- l();
140
- }, [L, l]);
141
- const q = e.useCallback(
142
- (t) => {
143
- const n = t.value;
144
- p || V(n), u && u(n || "");
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
- [p, u]
147
- ), J = e.useCallback(
148
- (t) => {
149
- U(t.syntheticEvent);
144
+ [d, u]
145
+ ), q = t.useCallback(
146
+ (n) => {
147
+ z(n.syntheticEvent);
150
148
  },
151
- [U]
152
- ), K = e.useCallback(
153
- (t) => /* @__PURE__ */ e.createElement(
154
- X,
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: t,
157
- uploadConfig: P,
154
+ affixProps: n,
155
+ uploadConfig: D,
158
156
  localizationService: o,
159
- onFilesSelect: O,
160
- onFileRemove: z
157
+ onFilesSelect: G,
158
+ onFileRemove: H
161
159
  }
162
- ),
163
- [P, o, O, z]
164
- ), Q = e.useMemo(() => {
165
- const t = typeof S == "object" ? S : {}, f = S !== !1 ? {
166
- "aria-label": k ? o.toLanguageString(v, r[v]) : o.toLanguageString(w, r[w]),
167
- title: k ? o.toLanguageString(v, r[v]) : o.toLanguageString(w, r[w]),
168
- dir: d ? "rtl" : void 0,
169
- ...t
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__ */ e.createElement(
172
- ue,
182
+ return /* @__PURE__ */ t.createElement(
183
+ ie,
173
184
  {
174
- header: G(),
175
- ref: F,
176
- placeholder: h,
177
- value: M,
178
- onChange: q,
179
- onPromptAction: J,
180
- mode: (a == null ? void 0 : a.mode) || "multi",
181
- rows: (a == null ? void 0 : a.rows) || 2,
182
- maxTextAreaHeight: (a == null ? void 0 : a.maxTextAreaHeight) || "110",
183
- loading: k,
184
- speechToTextButtonConfig: N,
185
- actionButtonConfig: f,
186
- attachments: B,
187
- startAffix: K,
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: I,
202
+ onClick: P,
190
203
  "aria-label": o.toLanguageString(
191
- W,
192
- r[W]
204
+ X,
205
+ l[X]
193
206
  )
194
207
  }
195
208
  }
196
209
  );
197
210
  }, [
198
- h,
199
- M,
211
+ C,
212
+ T,
213
+ O,
200
214
  q,
201
- J,
202
- a,
215
+ e,
216
+ b,
217
+ V,
203
218
  k,
204
- N,
205
- S,
206
- B,
207
- G,
219
+ M,
220
+ j,
221
+ J,
208
222
  K,
223
+ Q,
209
224
  o,
210
- d,
211
- I
225
+ g,
226
+ P
212
227
  ]);
213
- return /* @__PURE__ */ e.createElement("div", { className: "k-message-box-wrapper" }, x && x.length > 0 && /* @__PURE__ */ e.createElement(
214
- ne,
228
+ return /* @__PURE__ */ t.createElement("div", { className: "k-message-box-wrapper" }, h && h.length > 0 && /* @__PURE__ */ t.createElement(
229
+ oe,
215
230
  {
216
- onSuggestionClick: Y,
217
- suggestions: x,
218
- suggestionTemplate: Z,
219
- suggestionsLayout: _,
220
- dir: $
231
+ onSuggestionClick: Z,
232
+ suggestions: h,
233
+ suggestionTemplate: _,
234
+ suggestionsLayout: $,
235
+ dir: B
221
236
  }
222
- ), C ? /* @__PURE__ */ e.createElement(C, { messageInput: Q }) : Q);
237
+ ), A ? /* @__PURE__ */ t.createElement(A, { messageInput: W }) : W);
223
238
  });
224
- me.displayName = "NewMessage";
239
+ fe.displayName = "NewMessage";
225
240
  export {
226
- me as default
241
+ fe as default
227
242
  };
@@ -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.MutableRefObject<boolean>;
15
+ isKeyboardNavigationActiveRef: React.RefObject<boolean>;
14
16
  processedMessages: Message[];
15
- suggestions?: ChatSuggestion[];
17
+ authorId?: AutoScrollThresholdValue;
18
+ autoScrollThreshold?: AutoScrollThresholdValue;
16
19
  }
17
20
  /**
18
- *
19
- *An internal custom hook to manage chat scrolling behavior, including:
20
- *- Initial scroll to bottom on mount
21
- *- Auto-scroll on new messages
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, suggestions }: UseChatScrollProps) => void;
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
- * A custom hook that detects whether a scrollbar is present on an element.
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
  */
@@ -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 _=require("react");function A(n){const d=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const o in n)if(o!=="default"){const i=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(d,o,i.get?i:{enumerable:!0,get:()=>n[o]})}}return d.default=n,Object.freeze(d)}const c=A(_),H=50,x=250,y=50,B=100,q=({viewItemsWrapperRef:n,isKeyboardNavigationActiveRef:d,processedMessages:o,suggestions:i})=>{const l=c.useCallback(()=>{n.current&&(n.current.scrollTop=n.current.scrollHeight-n.current.clientHeight)},[n]),u=c.useCallback(()=>{if(!n.current)return!0;const t=n.current,{scrollTop:e,scrollHeight:r,clientHeight:s}=t,f=H+25;return r-e-s<f},[n]),b=c.useCallback(t=>t===0?16:t<=2?32*t:Math.min(50*t,200),[]),T=c.useCallback((t,e)=>{const r=b(t);setTimeout(()=>{!u()&&n.current&&e(t+1)},r)},[b,u,n]),h=c.useCallback(()=>{const t=(e=0)=>{e>5||requestAnimationFrame(()=>{l(),T(e,t)})};t()},[l,T]),C=c.useCallback(()=>{l(),setTimeout(()=>{!u()&&n.current&&l()},50)},[l,u,n]),g=c.useCallback(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(C)})})},[C]),O=c.useCallback(()=>{l(),setTimeout(()=>{!u()&&n.current&&h()},25)},[l,u,n,h]),a=c.useCallback((t=!1)=>{if(!n.current||d.current)return;u()&&(t?O():g())},[u,O,g,n,d]);c.useEffect(()=>{const t=window.setTimeout(()=>l(),x);return()=>{clearTimeout(t)}},[l]),c.useEffect(()=>{h()},[o.length,h]);const E=c.useRef(new Map);c.useEffect(()=>{const t=new Map;let e=!1;o.forEach(r=>{if(r.id!==void 0){const s=r.id,f=!!r.typing,S=E.current.get(s);t.set(s,f),S===!0&&f===!1&&(e=!0)}}),E.current=t,e&&h()},[o,h]),c.useEffect(()=>{const t=window.setTimeout(()=>{a()},y);return()=>{clearTimeout(t)}},[o,a]),c.useEffect(()=>{if(o.length>0){const t=o[o.length-1],e=(t==null?void 0:t.text)||"";(e.includes("```")||e.includes(`
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;