@progress/kendo-react-conversational-ui 13.4.0-develop.2 → 13.4.0-develop.4
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/api/message.interface.d.ts +87 -9
- package/chat/ChatPropsAndState.d.ts +108 -9
- package/chat/Events.d.ts +9 -0
- package/chat/components/ActionGroup.js +1 -1
- package/chat/components/ActionGroup.mjs +58 -48
- package/chat/components/Chat.d.ts +1 -1
- package/chat/components/Chat.js +1 -1
- package/chat/components/Chat.mjs +318 -269
- package/chat/components/ChatContext.d.ts +6 -3
- package/chat/components/ChatMessage.js +1 -1
- package/chat/components/ChatMessage.mjs +237 -177
- package/chat/components/Header.js +1 -1
- package/chat/components/Header.mjs +3 -3
- package/chat/components/NewMessage.d.ts +5 -3
- package/chat/components/NewMessage.js +1 -1
- package/chat/components/NewMessage.mjs +174 -226
- package/chat/components/ScrollButtonsWrapper.js +1 -1
- package/chat/components/ScrollButtonsWrapper.mjs +34 -40
- package/chat/components/SuggestionsGroup.js +1 -1
- package/chat/components/SuggestionsGroup.mjs +40 -39
- package/chat/components/elements/FileBox.js +1 -1
- package/chat/components/elements/FileBox.mjs +33 -41
- package/chat/components/elements/PinnedMessage.js +1 -1
- package/chat/components/elements/PinnedMessage.mjs +24 -22
- package/chat/hooks/useScrollWithButtons.d.ts +4 -0
- package/chat/hooks/useScrollWithButtons.js +1 -1
- package/chat/hooks/useScrollWithButtons.mjs +25 -23
- package/chat/utils/fieldMapping.d.ts +1 -1
- package/chat/utils/fieldMapping.js +1 -1
- package/chat/utils/fieldMapping.mjs +37 -34
- package/chat/utils/scroll.d.ts +15 -1
- package/chat/utils/scroll.js +3 -3
- package/chat/utils/scroll.mjs +92 -65
- package/chat/utils.d.ts +4 -1
- package/chat/utils.js +1 -1
- package/chat/utils.mjs +37 -37
- package/dist/cdn/js/kendo-react-conversational-ui.js +1 -1
- package/index.d.mts +6 -0
- package/index.d.ts +6 -0
- package/index.js +1 -1
- package/index.mjs +39 -31
- package/messages/index.d.ts +50 -0
- package/messages/index.js +1 -1
- package/messages/index.mjs +60 -40
- package/package-metadata.js +1 -1
- package/package-metadata.mjs +1 -1
- package/package.json +11 -11
- package/prompt-box/Events.d.ts +66 -0
- package/prompt-box/FileBox.d.ts +22 -0
- package/prompt-box/FileBox.js +8 -0
- package/prompt-box/FileBox.mjs +72 -0
- package/prompt-box/PromptBox.d.ts +35 -0
- package/prompt-box/PromptBox.js +8 -0
- package/prompt-box/PromptBox.mjs +424 -0
- package/prompt-box/PromptBoxActionButton.d.ts +32 -0
- package/prompt-box/PromptBoxActionButton.js +8 -0
- package/prompt-box/PromptBoxActionButton.mjs +14 -0
- package/prompt-box/PromptBoxSpeechToTextButton.d.ts +32 -0
- package/prompt-box/PromptBoxSpeechToTextButton.js +8 -0
- package/prompt-box/PromptBoxSpeechToTextButton.mjs +14 -0
- package/prompt-box/PromptBoxUploadButton.d.ts +108 -0
- package/prompt-box/PromptBoxUploadButton.js +8 -0
- package/prompt-box/PromptBoxUploadButton.mjs +54 -0
- package/prompt-box/interfaces/PromptBoxProps.d.ts +390 -0
package/chat/utils/scroll.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
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
|
|
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
9
|
|
|
10
|
-
`)||e.includes("<pre>")||e.includes("<code>")||e.includes("<table>")||e.length>500)&&
|
|
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
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(
|
|
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;
|
package/chat/utils/scroll.mjs
CHANGED
|
@@ -6,117 +6,117 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
import * as c from "react";
|
|
9
|
-
const A = 50,
|
|
9
|
+
const A = 50, x = 250, C = 50, H = 100, _ = ({
|
|
10
10
|
viewItemsWrapperRef: n,
|
|
11
|
-
isKeyboardNavigationActiveRef:
|
|
12
|
-
processedMessages:
|
|
13
|
-
suggestions:
|
|
11
|
+
isKeyboardNavigationActiveRef: T,
|
|
12
|
+
processedMessages: s,
|
|
13
|
+
suggestions: d
|
|
14
14
|
}) => {
|
|
15
|
-
const
|
|
15
|
+
const o = c.useCallback(() => {
|
|
16
16
|
n.current && (n.current.scrollTop = n.current.scrollHeight - n.current.clientHeight);
|
|
17
|
-
}, [n]),
|
|
17
|
+
}, [n]), l = c.useCallback(() => {
|
|
18
18
|
if (!n.current)
|
|
19
19
|
return !0;
|
|
20
|
-
const t = n.current, { scrollTop: e, scrollHeight: r, clientHeight:
|
|
21
|
-
return r - e -
|
|
22
|
-
}, [n]),
|
|
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
23
|
(t, e) => {
|
|
24
|
-
const r =
|
|
24
|
+
const r = h(t);
|
|
25
25
|
setTimeout(() => {
|
|
26
|
-
!
|
|
26
|
+
!l() && n.current && e(t + 1);
|
|
27
27
|
}, r);
|
|
28
28
|
},
|
|
29
|
-
[
|
|
30
|
-
),
|
|
29
|
+
[h, l, n]
|
|
30
|
+
), f = c.useCallback(() => {
|
|
31
31
|
const t = (e = 0) => {
|
|
32
32
|
e > 5 || requestAnimationFrame(() => {
|
|
33
|
-
|
|
33
|
+
o(), b(e, t);
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
t();
|
|
37
|
-
}, [
|
|
38
|
-
|
|
39
|
-
!
|
|
37
|
+
}, [o, b]), y = c.useCallback(() => {
|
|
38
|
+
o(), setTimeout(() => {
|
|
39
|
+
!l() && n.current && o();
|
|
40
40
|
}, 50);
|
|
41
|
-
}, [
|
|
41
|
+
}, [o, l, n]), E = c.useCallback(() => {
|
|
42
42
|
requestAnimationFrame(() => {
|
|
43
43
|
requestAnimationFrame(() => {
|
|
44
44
|
requestAnimationFrame(y);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
}, [y]), L = c.useCallback(() => {
|
|
48
|
-
|
|
49
|
-
!
|
|
48
|
+
o(), setTimeout(() => {
|
|
49
|
+
!l() && n.current && f();
|
|
50
50
|
}, 25);
|
|
51
|
-
}, [
|
|
51
|
+
}, [o, l, n, f]), i = c.useCallback(
|
|
52
52
|
(t = !1) => {
|
|
53
|
-
if (!n.current ||
|
|
53
|
+
if (!n.current || T.current)
|
|
54
54
|
return;
|
|
55
|
-
|
|
55
|
+
l() && (t ? L() : E());
|
|
56
56
|
},
|
|
57
57
|
[
|
|
58
|
-
|
|
58
|
+
l,
|
|
59
59
|
L,
|
|
60
60
|
E,
|
|
61
61
|
n,
|
|
62
|
-
|
|
62
|
+
T
|
|
63
63
|
]
|
|
64
64
|
);
|
|
65
65
|
c.useEffect(() => {
|
|
66
|
-
const t = window.setTimeout(() =>
|
|
66
|
+
const t = window.setTimeout(() => o(), x);
|
|
67
67
|
return () => {
|
|
68
68
|
clearTimeout(t);
|
|
69
69
|
};
|
|
70
|
-
}, [
|
|
71
|
-
|
|
72
|
-
}, [
|
|
73
|
-
const
|
|
70
|
+
}, [o]), c.useEffect(() => {
|
|
71
|
+
f();
|
|
72
|
+
}, [s.length, f]);
|
|
73
|
+
const O = c.useRef(/* @__PURE__ */ new Map());
|
|
74
74
|
c.useEffect(() => {
|
|
75
75
|
const t = /* @__PURE__ */ new Map();
|
|
76
76
|
let e = !1;
|
|
77
|
-
|
|
77
|
+
s.forEach((r) => {
|
|
78
78
|
if (r.id !== void 0) {
|
|
79
|
-
const
|
|
80
|
-
t.set(
|
|
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
81
|
}
|
|
82
|
-
}),
|
|
83
|
-
}, [
|
|
82
|
+
}), O.current = t, e && f();
|
|
83
|
+
}, [s, f]), c.useEffect(() => {
|
|
84
84
|
const t = window.setTimeout(() => {
|
|
85
|
-
|
|
86
|
-
},
|
|
85
|
+
i();
|
|
86
|
+
}, C);
|
|
87
87
|
return () => {
|
|
88
88
|
clearTimeout(t);
|
|
89
89
|
};
|
|
90
|
-
}, [
|
|
91
|
-
if (
|
|
92
|
-
const t =
|
|
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
93
|
(e.includes("```") || e.includes(`
|
|
94
94
|
|
|
95
|
-
`) || e.includes("<pre>") || e.includes("<code>") || e.includes("<table>") || e.length > 500) &&
|
|
95
|
+
`) || e.includes("<pre>") || e.includes("<code>") || e.includes("<table>") || e.length > 500) && i(!0);
|
|
96
96
|
}
|
|
97
|
-
}, [
|
|
98
|
-
if (
|
|
97
|
+
}, [s, i]), c.useEffect(() => {
|
|
98
|
+
if (d && d.length > 0) {
|
|
99
99
|
const t = window.setTimeout(() => {
|
|
100
|
-
|
|
101
|
-
},
|
|
100
|
+
i();
|
|
101
|
+
}, H);
|
|
102
102
|
return () => {
|
|
103
103
|
clearTimeout(t);
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
}, [
|
|
106
|
+
}, [d, i]), c.useEffect(() => {
|
|
107
107
|
if (!n.current)
|
|
108
108
|
return () => {
|
|
109
109
|
};
|
|
110
110
|
let t;
|
|
111
111
|
const e = new ResizeObserver(() => {
|
|
112
112
|
t && clearTimeout(t), t = window.setTimeout(() => {
|
|
113
|
-
|
|
114
|
-
},
|
|
113
|
+
i();
|
|
114
|
+
}, C);
|
|
115
115
|
}), r = n.current.querySelector(".k-message-list-content");
|
|
116
116
|
return r && e.observe(r), () => {
|
|
117
117
|
e.disconnect();
|
|
118
118
|
};
|
|
119
|
-
}, [
|
|
119
|
+
}, [i, n]);
|
|
120
120
|
const g = c.useCallback((t) => {
|
|
121
121
|
var r;
|
|
122
122
|
if (t.type !== "characterData" && t.type !== "childList")
|
|
@@ -125,22 +125,22 @@ const A = 50, _ = 250, h = 50, m = 100, B = ({
|
|
|
125
125
|
return e.includes("```") || e.includes(`
|
|
126
126
|
|
|
127
127
|
`) || e.includes("<pre>") || e.includes("<code>") || e.includes("<table>") || t.addedNodes && t.addedNodes.length > 2;
|
|
128
|
-
}, []),
|
|
128
|
+
}, []), k = c.useCallback(
|
|
129
129
|
(t) => {
|
|
130
130
|
let e = !1, r = !1;
|
|
131
|
-
return t.forEach((
|
|
132
|
-
var
|
|
133
|
-
(
|
|
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
134
|
}), { shouldScroll: e, hasSignificantChange: r };
|
|
135
135
|
},
|
|
136
136
|
[g]
|
|
137
137
|
), D = c.useCallback(
|
|
138
138
|
(t, e) => {
|
|
139
|
-
e.current && clearTimeout(e.current), t ?
|
|
140
|
-
|
|
141
|
-
},
|
|
139
|
+
e.current && clearTimeout(e.current), t ? i(!0) : e.current = window.setTimeout(() => {
|
|
140
|
+
i();
|
|
141
|
+
}, C);
|
|
142
142
|
},
|
|
143
|
-
[
|
|
143
|
+
[i]
|
|
144
144
|
);
|
|
145
145
|
c.useEffect(() => {
|
|
146
146
|
if (!n.current)
|
|
@@ -148,13 +148,13 @@ const A = 50, _ = 250, h = 50, m = 100, B = ({
|
|
|
148
148
|
};
|
|
149
149
|
const t = { current: void 0 };
|
|
150
150
|
let e = 0;
|
|
151
|
-
const r = new MutationObserver((
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
151
|
+
const r = new MutationObserver((u) => {
|
|
152
|
+
const a = Date.now();
|
|
153
|
+
if (a - e < 16)
|
|
154
154
|
return;
|
|
155
|
-
e =
|
|
156
|
-
const { shouldScroll:
|
|
157
|
-
|
|
155
|
+
e = a;
|
|
156
|
+
const { shouldScroll: S, hasSignificantChange: m } = k(u);
|
|
157
|
+
S && l() && D(m, t);
|
|
158
158
|
});
|
|
159
159
|
return r.observe(n.current, {
|
|
160
160
|
childList: !0,
|
|
@@ -165,8 +165,35 @@ const A = 50, _ = 250, h = 50, m = 100, B = ({
|
|
|
165
165
|
}), () => {
|
|
166
166
|
r.disconnect(), t.current && clearTimeout(t.current);
|
|
167
167
|
};
|
|
168
|
-
}, [
|
|
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)
|
|
174
|
+
return;
|
|
175
|
+
const o = () => {
|
|
176
|
+
const b = d.scrollHeight > d.clientHeight;
|
|
177
|
+
s(b);
|
|
178
|
+
};
|
|
179
|
+
o();
|
|
180
|
+
const l = new ResizeObserver(() => {
|
|
181
|
+
o();
|
|
182
|
+
});
|
|
183
|
+
l.observe(d);
|
|
184
|
+
const h = new MutationObserver(() => {
|
|
185
|
+
requestAnimationFrame(o);
|
|
186
|
+
});
|
|
187
|
+
return h.observe(d, {
|
|
188
|
+
childList: !0,
|
|
189
|
+
subtree: !0,
|
|
190
|
+
characterData: !0
|
|
191
|
+
}), () => {
|
|
192
|
+
l.disconnect(), h.disconnect();
|
|
193
|
+
};
|
|
194
|
+
}, [n]), T;
|
|
169
195
|
};
|
|
170
196
|
export {
|
|
171
|
-
|
|
197
|
+
_ as useChatScroll,
|
|
198
|
+
B as useHasScrollbar
|
|
172
199
|
};
|
package/chat/utils.d.ts
CHANGED
|
@@ -27,8 +27,11 @@ export declare const getMessageById: (messages: Message[], id: string | number)
|
|
|
27
27
|
/**
|
|
28
28
|
* @hidden
|
|
29
29
|
* Scrolls to a message element by its ID
|
|
30
|
+
* @param messageId - The ID of the message to scroll to
|
|
31
|
+
* @param scrollContainer - The scroll container element
|
|
32
|
+
* @param offset - Optional offset in pixels to account for sticky elements (e.g., pinned message height)
|
|
30
33
|
*/
|
|
31
|
-
export declare const scrollToMessageById: (messageId: string | number, scrollContainer?: HTMLElement | null) => void;
|
|
34
|
+
export declare const scrollToMessageById: (messageId: string | number, scrollContainer?: HTMLElement | null, offset?: number) => void;
|
|
32
35
|
/**
|
|
33
36
|
* @hidden
|
|
34
37
|
* Regular expression to detect URLs in text
|
package/chat/utils.js
CHANGED
|
@@ -5,4 +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
|
|
8
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),r=require("../messages/index.js"),g=(e,t)=>e&&t.author&&e.id===t.author.id,u=(e,t)=>{const o=t.toLanguageString("chatSender.deletedMessage",r.messages[r.chatSenderDeletedMessage]),s=t.toLanguageString("chatReceiver.deletedMessage",r.messages[r.chatReceiverDeletedMessage]);return e?o:s},h=e=>{navigator.clipboard.writeText(e)},T=(e,t)=>e.find(o=>o.id===t),p=(e,t,o=0)=>{if(!t)return;const s=t.querySelector(`[data-message-id="${e}"]`);if(!s)return;const n=t.querySelector(".k-message-list");if(n){const a=n.getBoundingClientRect().top,l=s.getBoundingClientRect().top,i=n.scrollTop+(l-a)-o;n.scrollTo({top:i,behavior:"smooth"})}else s.scrollIntoView({behavior:"smooth",block:"start"})},c=/(https?:\/\/[^\s]+)/g,M=e=>{if(!e)return[""];const t=e.split(c),o=[];return t.forEach(s=>{s&&c.test(s)?(c.lastIndex=0,o.push(d.createElement("a",{key:s,href:s,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"}},s))):s&&o.push(s)}),o};exports.URL_REGEX=c;exports.convertTextToLinkedContent=M;exports.copyToClipboard=h;exports.getDeletedMessageText=u;exports.getMessageById=T;exports.isAuthor=g;exports.scrollToMessageById=p;
|
package/chat/utils.mjs
CHANGED
|
@@ -5,63 +5,63 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import { messages as
|
|
10
|
-
const
|
|
11
|
-
const s =
|
|
8
|
+
import d from "react";
|
|
9
|
+
import { messages as c, chatSenderDeletedMessage as g, chatReceiverDeletedMessage as u } from "../messages/index.mjs";
|
|
10
|
+
const p = (e, t) => e && t.author && e.id === t.author.id, m = (e, t) => {
|
|
11
|
+
const s = t.toLanguageString(
|
|
12
12
|
"chatSender.deletedMessage",
|
|
13
|
-
|
|
14
|
-
),
|
|
13
|
+
c[g]
|
|
14
|
+
), o = t.toLanguageString(
|
|
15
15
|
"chatReceiver.deletedMessage",
|
|
16
|
-
|
|
16
|
+
c[u]
|
|
17
17
|
);
|
|
18
|
-
return
|
|
19
|
-
},
|
|
20
|
-
navigator.clipboard.writeText(
|
|
21
|
-
},
|
|
22
|
-
if (!
|
|
18
|
+
return e ? s : o;
|
|
19
|
+
}, T = (e) => {
|
|
20
|
+
navigator.clipboard.writeText(e);
|
|
21
|
+
}, M = (e, t) => e.find((s) => s.id === t), y = (e, t, s = 0) => {
|
|
22
|
+
if (!t)
|
|
23
23
|
return;
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
24
|
+
const o = t.querySelector(`[data-message-id="${e}"]`);
|
|
25
|
+
if (!o)
|
|
26
26
|
return;
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
top:
|
|
27
|
+
const r = t.querySelector(".k-message-list");
|
|
28
|
+
if (r) {
|
|
29
|
+
const a = r.getBoundingClientRect().top, l = o.getBoundingClientRect().top, i = r.scrollTop + (l - a) - s;
|
|
30
|
+
r.scrollTo({
|
|
31
|
+
top: i,
|
|
32
32
|
behavior: "smooth"
|
|
33
33
|
});
|
|
34
34
|
} else
|
|
35
|
-
|
|
35
|
+
o.scrollIntoView({
|
|
36
36
|
behavior: "smooth",
|
|
37
37
|
block: "start"
|
|
38
38
|
});
|
|
39
|
-
},
|
|
40
|
-
if (!
|
|
39
|
+
}, n = /(https?:\/\/[^\s]+)/g, R = (e) => {
|
|
40
|
+
if (!e)
|
|
41
41
|
return [""];
|
|
42
|
-
const
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const t = e.split(n), s = [];
|
|
43
|
+
return t.forEach((o) => {
|
|
44
|
+
o && n.test(o) ? (n.lastIndex = 0, s.push(
|
|
45
|
+
d.createElement(
|
|
46
46
|
"a",
|
|
47
47
|
{
|
|
48
|
-
key:
|
|
49
|
-
href:
|
|
48
|
+
key: o,
|
|
49
|
+
href: o,
|
|
50
50
|
target: "_blank",
|
|
51
51
|
rel: "noopener noreferrer",
|
|
52
52
|
style: { color: "inherit", textDecoration: "underline" }
|
|
53
53
|
},
|
|
54
|
-
|
|
54
|
+
o
|
|
55
55
|
)
|
|
56
|
-
)) :
|
|
56
|
+
)) : o && s.push(o);
|
|
57
57
|
}), s;
|
|
58
58
|
};
|
|
59
59
|
export {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
n as URL_REGEX,
|
|
61
|
+
R as convertTextToLinkedContent,
|
|
62
|
+
T as copyToClipboard,
|
|
63
|
+
m as getDeletedMessageText,
|
|
64
|
+
M as getMessageById,
|
|
65
|
+
p as isAuthor,
|
|
66
|
+
y as scrollToMessageById
|
|
67
67
|
};
|