@esvndev/es-react-template-chat 0.0.90 → 0.0.91
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/dist/index.js +94 -184
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -184
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -72139,7 +72139,7 @@ const ChatLog = (props) => {
|
|
|
72139
72139
|
const prevListLength = React.useRef(0);
|
|
72140
72140
|
React.useState(0);
|
|
72141
72141
|
React.useState(true);
|
|
72142
|
-
React.useState(new Set());
|
|
72142
|
+
const [expandedMessages, setExpandedMessages] = React.useState(new Set());
|
|
72143
72143
|
const [clickedImageFile, setClickedImageFile] = React.useState(null);
|
|
72144
72144
|
React.useState(false);
|
|
72145
72145
|
React.useState(new Set());
|
|
@@ -72184,7 +72184,7 @@ const ChatLog = (props) => {
|
|
|
72184
72184
|
scrollToBottom();
|
|
72185
72185
|
}
|
|
72186
72186
|
}, [messageByGroup, checkScroll]);
|
|
72187
|
-
React.useMemo(() => {
|
|
72187
|
+
const mentionItems = React.useMemo(() => {
|
|
72188
72188
|
if (!groupChatUsers) {
|
|
72189
72189
|
return [];
|
|
72190
72190
|
}
|
|
@@ -72202,7 +72202,7 @@ const ChatLog = (props) => {
|
|
|
72202
72202
|
});
|
|
72203
72203
|
return [{ id: "all", name: "All" }, ...mappedUsers];
|
|
72204
72204
|
}, [groupChatUsers]);
|
|
72205
|
-
React.useCallback((mes) => {
|
|
72205
|
+
const handlePreview = React.useCallback((mes) => {
|
|
72206
72206
|
setSelectedMessage(mes);
|
|
72207
72207
|
setOpenModalPreview(true);
|
|
72208
72208
|
}, []);
|
|
@@ -72335,187 +72335,97 @@ const ChatLog = (props) => {
|
|
|
72335
72335
|
}
|
|
72336
72336
|
}
|
|
72337
72337
|
}, []);
|
|
72338
|
-
|
|
72339
|
-
|
|
72340
|
-
|
|
72341
|
-
|
|
72342
|
-
|
|
72343
|
-
|
|
72344
|
-
|
|
72345
|
-
|
|
72346
|
-
|
|
72347
|
-
|
|
72348
|
-
|
|
72349
|
-
|
|
72350
|
-
|
|
72351
|
-
|
|
72352
|
-
|
|
72353
|
-
|
|
72354
|
-
|
|
72355
|
-
|
|
72356
|
-
|
|
72357
|
-
|
|
72358
|
-
|
|
72359
|
-
|
|
72360
|
-
|
|
72361
|
-
|
|
72362
|
-
|
|
72363
|
-
|
|
72364
|
-
|
|
72365
|
-
|
|
72366
|
-
|
|
72367
|
-
|
|
72368
|
-
|
|
72369
|
-
|
|
72370
|
-
|
|
72371
|
-
|
|
72372
|
-
|
|
72373
|
-
|
|
72374
|
-
|
|
72375
|
-
|
|
72376
|
-
|
|
72377
|
-
|
|
72378
|
-
|
|
72379
|
-
|
|
72380
|
-
|
|
72381
|
-
|
|
72382
|
-
|
|
72383
|
-
|
|
72384
|
-
|
|
72385
|
-
|
|
72386
|
-
|
|
72387
|
-
|
|
72388
|
-
|
|
72389
|
-
|
|
72390
|
-
|
|
72391
|
-
|
|
72392
|
-
|
|
72393
|
-
|
|
72394
|
-
|
|
72395
|
-
|
|
72396
|
-
|
|
72397
|
-
|
|
72398
|
-
|
|
72399
|
-
|
|
72400
|
-
|
|
72401
|
-
|
|
72402
|
-
|
|
72403
|
-
|
|
72404
|
-
|
|
72405
|
-
|
|
72406
|
-
|
|
72407
|
-
|
|
72408
|
-
|
|
72409
|
-
|
|
72410
|
-
|
|
72411
|
-
|
|
72412
|
-
|
|
72413
|
-
|
|
72414
|
-
|
|
72415
|
-
|
|
72416
|
-
|
|
72417
|
-
|
|
72418
|
-
|
|
72419
|
-
|
|
72420
|
-
|
|
72421
|
-
|
|
72422
|
-
|
|
72423
|
-
|
|
72424
|
-
|
|
72425
|
-
|
|
72426
|
-
|
|
72427
|
-
|
|
72428
|
-
|
|
72429
|
-
// })
|
|
72430
|
-
// result = processedArray
|
|
72431
|
-
// }
|
|
72432
|
-
// })
|
|
72433
|
-
// // Add expand/collapse functionality
|
|
72434
|
-
// if (isTruncated || (isExpanded && text.length > maxLength)) {
|
|
72435
|
-
// const expandButton = (
|
|
72436
|
-
// <span
|
|
72437
|
-
// key={`expand-${messageId}`}
|
|
72438
|
-
// onClick={() => toggleExpanded(messageId)}
|
|
72439
|
-
// style={{
|
|
72440
|
-
// color: '#006edc',
|
|
72441
|
-
// cursor: 'pointer',
|
|
72442
|
-
// fontWeight: 500,
|
|
72443
|
-
// marginLeft: 5
|
|
72444
|
-
// }}
|
|
72445
|
-
// >
|
|
72446
|
-
// {isExpanded ? ' Thu gọn' : '... Mở rộng'}
|
|
72447
|
-
// </span>
|
|
72448
|
-
// )
|
|
72449
|
-
// if (Array.isArray(result)) {
|
|
72450
|
-
// result.push(expandButton)
|
|
72451
|
-
// } else {
|
|
72452
|
-
// result = [result, expandButton]
|
|
72453
|
-
// }
|
|
72454
|
-
// }
|
|
72455
|
-
// return result
|
|
72456
|
-
// }
|
|
72457
|
-
// return (
|
|
72458
|
-
// <>
|
|
72459
|
-
// <div>
|
|
72460
|
-
// <div>
|
|
72461
|
-
// {chat.path && chat.path.length === 1 && (
|
|
72462
|
-
// <div className="image-container">
|
|
72463
|
-
// {img && <img src={img} alt="" />}
|
|
72464
|
-
// </div>
|
|
72465
|
-
// )}
|
|
72466
|
-
// {isValidUrl(chat.msg) && renderLinkPreview(chat.msg)}
|
|
72467
|
-
// {chat.msg && !isValidUrl(chat.msg) ? (
|
|
72468
|
-
// <div>{formatMentionsReact(chat.msg, mentionItems, chat.id)}</div>
|
|
72469
|
-
// ) : (
|
|
72470
|
-
// <></>
|
|
72471
|
-
// )}
|
|
72472
|
-
// {chat.path && chat.path.length > 1 && (
|
|
72473
|
-
// <div className="group-image">
|
|
72474
|
-
// {chat.path.map((it: any, index: any) => {
|
|
72475
|
-
// return (
|
|
72476
|
-
// <div
|
|
72477
|
-
// key={index}
|
|
72478
|
-
// className="group-image-item image-container"
|
|
72479
|
-
// >
|
|
72480
|
-
// <img
|
|
72481
|
-
// style={{ maxWidth: "100%", maxHeight: 360 }}
|
|
72482
|
-
// src={`${CDN_URL_VIEW}/${it.path.trim()}`}
|
|
72483
|
-
// onClick={() => handlePreview(it)}
|
|
72484
|
-
// alt=""
|
|
72485
|
-
// />
|
|
72486
|
-
// </div>
|
|
72487
|
-
// )
|
|
72488
|
-
// })}
|
|
72489
|
-
// </div>
|
|
72490
|
-
// )}
|
|
72491
|
-
// <div className="" style={{ fontSize: "12px", color: "#476285" }}>
|
|
72492
|
-
// {moment(chat.time).format("HH:mm")}
|
|
72493
|
-
// </div>
|
|
72494
|
-
// </div>
|
|
72495
|
-
// </div>
|
|
72496
|
-
// </>
|
|
72497
|
-
// )
|
|
72498
|
-
// }, [expandedMessages, handlePreview, mentionItems])
|
|
72499
|
-
// const getLinkPreviewData = (urlString: string) => {
|
|
72500
|
-
// try {
|
|
72501
|
-
// const hasProtocol = /^https?:\/\//i.test(urlString)
|
|
72502
|
-
// const href = hasProtocol ? urlString : `https://${urlString}`
|
|
72503
|
-
// const url = new URL(href)
|
|
72504
|
-
// const displayUrl =
|
|
72505
|
-
// urlString.length > 80 ? `${urlString.slice(0, 77)}...` : urlString
|
|
72506
|
-
// return {
|
|
72507
|
-
// href,
|
|
72508
|
-
// displayUrl,
|
|
72509
|
-
// host: url.host
|
|
72510
|
-
// }
|
|
72511
|
-
// } catch (e) {
|
|
72512
|
-
// return {
|
|
72513
|
-
// href: urlString,
|
|
72514
|
-
// displayUrl: urlString,
|
|
72515
|
-
// host: ''
|
|
72516
|
-
// }
|
|
72517
|
-
// }
|
|
72518
|
-
// }
|
|
72338
|
+
React.useCallback((chat) => {
|
|
72339
|
+
const isPath = Array.isArray(chat?.path) && typeof chat.path[0]?.path === "string" ? chat.path[0].path.trim() : "";
|
|
72340
|
+
const img = isPath ? `${CDN_URL_VIEW}/${isPath}` : "";
|
|
72341
|
+
const toggleExpanded = (messageId) => {
|
|
72342
|
+
const newExpanded = new Set(expandedMessages);
|
|
72343
|
+
if (newExpanded.has(messageId)) {
|
|
72344
|
+
newExpanded.delete(messageId);
|
|
72345
|
+
}
|
|
72346
|
+
else {
|
|
72347
|
+
newExpanded.add(messageId);
|
|
72348
|
+
}
|
|
72349
|
+
setExpandedMessages(newExpanded);
|
|
72350
|
+
};
|
|
72351
|
+
const formatMentionsReact = (text, mentions, messageId) => {
|
|
72352
|
+
if (!text || !mentions || mentions.length === 0) {
|
|
72353
|
+
return text;
|
|
72354
|
+
}
|
|
72355
|
+
const maxLength = 200;
|
|
72356
|
+
const isExpanded = expandedMessages.has(messageId);
|
|
72357
|
+
let displayText = text;
|
|
72358
|
+
let isTruncated = false;
|
|
72359
|
+
if (!isExpanded && text.length > maxLength) {
|
|
72360
|
+
displayText = text.substring(0, maxLength);
|
|
72361
|
+
isTruncated = true;
|
|
72362
|
+
}
|
|
72363
|
+
// Chỉ highlight những mention có trong danh sách
|
|
72364
|
+
let result = displayText;
|
|
72365
|
+
// Hàm helper để xử lý mention trong cả string và array
|
|
72366
|
+
const processMention = (text, mention) => {
|
|
72367
|
+
const escapedName = mention?.name?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
72368
|
+
const mentionRegex = new RegExp(`@${escapedName}(?=\\s|$|[.,;:!?()[\\]{}'"\`~@])`, 'g');
|
|
72369
|
+
const parts = text.split(mentionRegex);
|
|
72370
|
+
const matches = text.match(mentionRegex) || [];
|
|
72371
|
+
if (matches.length === 0) {
|
|
72372
|
+
return text;
|
|
72373
|
+
}
|
|
72374
|
+
const newParts = [];
|
|
72375
|
+
parts.forEach((part, index) => {
|
|
72376
|
+
newParts.push(part);
|
|
72377
|
+
if (matches[index]) {
|
|
72378
|
+
newParts.push(jsxRuntime.jsx("span", { className: "chat-mention", children: matches[index] }, `mention-${messageId}-${mention.id || mention.name}-${index}`));
|
|
72379
|
+
}
|
|
72380
|
+
});
|
|
72381
|
+
return newParts;
|
|
72382
|
+
};
|
|
72383
|
+
mentions.forEach((mention) => {
|
|
72384
|
+
if (typeof result === 'string') {
|
|
72385
|
+
result = processMention(result, mention);
|
|
72386
|
+
}
|
|
72387
|
+
else if (Array.isArray(result)) {
|
|
72388
|
+
// Xử lý từng phần tử trong array
|
|
72389
|
+
const processedArray = [];
|
|
72390
|
+
result.forEach((item) => {
|
|
72391
|
+
if (typeof item === 'string') {
|
|
72392
|
+
const processed = processMention(item, mention);
|
|
72393
|
+
if (Array.isArray(processed)) {
|
|
72394
|
+
processedArray.push(...processed);
|
|
72395
|
+
}
|
|
72396
|
+
else {
|
|
72397
|
+
processedArray.push(processed);
|
|
72398
|
+
}
|
|
72399
|
+
}
|
|
72400
|
+
else {
|
|
72401
|
+
// Giữ nguyên các React elements đã được xử lý
|
|
72402
|
+
processedArray.push(item);
|
|
72403
|
+
}
|
|
72404
|
+
});
|
|
72405
|
+
result = processedArray;
|
|
72406
|
+
}
|
|
72407
|
+
});
|
|
72408
|
+
// Add expand/collapse functionality
|
|
72409
|
+
if (isTruncated || (isExpanded && text.length > maxLength)) {
|
|
72410
|
+
const expandButton = (jsxRuntime.jsx("span", { onClick: () => toggleExpanded(messageId), style: {
|
|
72411
|
+
color: '#006edc',
|
|
72412
|
+
cursor: 'pointer',
|
|
72413
|
+
fontWeight: 500,
|
|
72414
|
+
marginLeft: 5
|
|
72415
|
+
}, children: isExpanded ? ' Thu gọn' : '... Mở rộng' }, `expand-${messageId}`));
|
|
72416
|
+
if (Array.isArray(result)) {
|
|
72417
|
+
result.push(expandButton);
|
|
72418
|
+
}
|
|
72419
|
+
else {
|
|
72420
|
+
result = [result, expandButton];
|
|
72421
|
+
}
|
|
72422
|
+
}
|
|
72423
|
+
return result;
|
|
72424
|
+
};
|
|
72425
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { children: jsxRuntime.jsxs("div", { children: [chat.path && chat.path.length === 1 && (jsxRuntime.jsx("div", { className: "image-container", children: img && jsxRuntime.jsx("img", { src: img, alt: "" }) })), isValidUrl(chat.msg) && renderLinkPreview(chat.msg), chat.msg && !isValidUrl(chat.msg) ? (jsxRuntime.jsx("div", { children: formatMentionsReact(chat.msg, mentionItems, chat.id) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, {})), chat.path && chat.path.length > 1 && (jsxRuntime.jsx("div", { className: "group-image", children: chat.path.map((it, index) => {
|
|
72426
|
+
return (jsxRuntime.jsx("div", { className: "group-image-item image-container", children: jsxRuntime.jsx("img", { style: { maxWidth: "100%", maxHeight: 360 }, src: `${CDN_URL_VIEW}/${it.path.trim()}`, onClick: () => handlePreview(it), alt: "" }) }, index));
|
|
72427
|
+
}) })), jsxRuntime.jsx("div", { className: "", style: { fontSize: "12px", color: "#476285" }, children: moment(chat.time).format("HH:mm") })] }) }) }));
|
|
72428
|
+
}, [expandedMessages, handlePreview, mentionItems]);
|
|
72519
72429
|
// const renderLinkPreview = (urlString: string) => {
|
|
72520
72430
|
// const { href, displayUrl, host } = getLinkPreviewData(urlString)
|
|
72521
72431
|
// return (
|