@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.mjs
CHANGED
|
@@ -72110,7 +72110,7 @@ const ChatLog = (props) => {
|
|
|
72110
72110
|
const prevListLength = useRef(0);
|
|
72111
72111
|
useState(0);
|
|
72112
72112
|
useState(true);
|
|
72113
|
-
useState(new Set());
|
|
72113
|
+
const [expandedMessages, setExpandedMessages] = useState(new Set());
|
|
72114
72114
|
const [clickedImageFile, setClickedImageFile] = useState(null);
|
|
72115
72115
|
useState(false);
|
|
72116
72116
|
useState(new Set());
|
|
@@ -72155,7 +72155,7 @@ const ChatLog = (props) => {
|
|
|
72155
72155
|
scrollToBottom();
|
|
72156
72156
|
}
|
|
72157
72157
|
}, [messageByGroup, checkScroll]);
|
|
72158
|
-
useMemo(() => {
|
|
72158
|
+
const mentionItems = useMemo(() => {
|
|
72159
72159
|
if (!groupChatUsers) {
|
|
72160
72160
|
return [];
|
|
72161
72161
|
}
|
|
@@ -72173,7 +72173,7 @@ const ChatLog = (props) => {
|
|
|
72173
72173
|
});
|
|
72174
72174
|
return [{ id: "all", name: "All" }, ...mappedUsers];
|
|
72175
72175
|
}, [groupChatUsers]);
|
|
72176
|
-
useCallback((mes) => {
|
|
72176
|
+
const handlePreview = useCallback((mes) => {
|
|
72177
72177
|
setSelectedMessage(mes);
|
|
72178
72178
|
setOpenModalPreview(true);
|
|
72179
72179
|
}, []);
|
|
@@ -72306,187 +72306,97 @@ const ChatLog = (props) => {
|
|
|
72306
72306
|
}
|
|
72307
72307
|
}
|
|
72308
72308
|
}, []);
|
|
72309
|
-
|
|
72310
|
-
|
|
72311
|
-
|
|
72312
|
-
|
|
72313
|
-
|
|
72314
|
-
|
|
72315
|
-
|
|
72316
|
-
|
|
72317
|
-
|
|
72318
|
-
|
|
72319
|
-
|
|
72320
|
-
|
|
72321
|
-
|
|
72322
|
-
|
|
72323
|
-
|
|
72324
|
-
|
|
72325
|
-
|
|
72326
|
-
|
|
72327
|
-
|
|
72328
|
-
|
|
72329
|
-
|
|
72330
|
-
|
|
72331
|
-
|
|
72332
|
-
|
|
72333
|
-
|
|
72334
|
-
|
|
72335
|
-
|
|
72336
|
-
|
|
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
|
-
// result = processedArray
|
|
72402
|
-
// }
|
|
72403
|
-
// })
|
|
72404
|
-
// // Add expand/collapse functionality
|
|
72405
|
-
// if (isTruncated || (isExpanded && text.length > maxLength)) {
|
|
72406
|
-
// const expandButton = (
|
|
72407
|
-
// <span
|
|
72408
|
-
// key={`expand-${messageId}`}
|
|
72409
|
-
// onClick={() => toggleExpanded(messageId)}
|
|
72410
|
-
// style={{
|
|
72411
|
-
// color: '#006edc',
|
|
72412
|
-
// cursor: 'pointer',
|
|
72413
|
-
// fontWeight: 500,
|
|
72414
|
-
// marginLeft: 5
|
|
72415
|
-
// }}
|
|
72416
|
-
// >
|
|
72417
|
-
// {isExpanded ? ' Thu gọn' : '... Mở rộng'}
|
|
72418
|
-
// </span>
|
|
72419
|
-
// )
|
|
72420
|
-
// if (Array.isArray(result)) {
|
|
72421
|
-
// result.push(expandButton)
|
|
72422
|
-
// } else {
|
|
72423
|
-
// result = [result, expandButton]
|
|
72424
|
-
// }
|
|
72425
|
-
// }
|
|
72426
|
-
// return result
|
|
72427
|
-
// }
|
|
72428
|
-
// return (
|
|
72429
|
-
// <>
|
|
72430
|
-
// <div>
|
|
72431
|
-
// <div>
|
|
72432
|
-
// {chat.path && chat.path.length === 1 && (
|
|
72433
|
-
// <div className="image-container">
|
|
72434
|
-
// {img && <img src={img} alt="" />}
|
|
72435
|
-
// </div>
|
|
72436
|
-
// )}
|
|
72437
|
-
// {isValidUrl(chat.msg) && renderLinkPreview(chat.msg)}
|
|
72438
|
-
// {chat.msg && !isValidUrl(chat.msg) ? (
|
|
72439
|
-
// <div>{formatMentionsReact(chat.msg, mentionItems, chat.id)}</div>
|
|
72440
|
-
// ) : (
|
|
72441
|
-
// <></>
|
|
72442
|
-
// )}
|
|
72443
|
-
// {chat.path && chat.path.length > 1 && (
|
|
72444
|
-
// <div className="group-image">
|
|
72445
|
-
// {chat.path.map((it: any, index: any) => {
|
|
72446
|
-
// return (
|
|
72447
|
-
// <div
|
|
72448
|
-
// key={index}
|
|
72449
|
-
// className="group-image-item image-container"
|
|
72450
|
-
// >
|
|
72451
|
-
// <img
|
|
72452
|
-
// style={{ maxWidth: "100%", maxHeight: 360 }}
|
|
72453
|
-
// src={`${CDN_URL_VIEW}/${it.path.trim()}`}
|
|
72454
|
-
// onClick={() => handlePreview(it)}
|
|
72455
|
-
// alt=""
|
|
72456
|
-
// />
|
|
72457
|
-
// </div>
|
|
72458
|
-
// )
|
|
72459
|
-
// })}
|
|
72460
|
-
// </div>
|
|
72461
|
-
// )}
|
|
72462
|
-
// <div className="" style={{ fontSize: "12px", color: "#476285" }}>
|
|
72463
|
-
// {moment(chat.time).format("HH:mm")}
|
|
72464
|
-
// </div>
|
|
72465
|
-
// </div>
|
|
72466
|
-
// </div>
|
|
72467
|
-
// </>
|
|
72468
|
-
// )
|
|
72469
|
-
// }, [expandedMessages, handlePreview, mentionItems])
|
|
72470
|
-
// const getLinkPreviewData = (urlString: string) => {
|
|
72471
|
-
// try {
|
|
72472
|
-
// const hasProtocol = /^https?:\/\//i.test(urlString)
|
|
72473
|
-
// const href = hasProtocol ? urlString : `https://${urlString}`
|
|
72474
|
-
// const url = new URL(href)
|
|
72475
|
-
// const displayUrl =
|
|
72476
|
-
// urlString.length > 80 ? `${urlString.slice(0, 77)}...` : urlString
|
|
72477
|
-
// return {
|
|
72478
|
-
// href,
|
|
72479
|
-
// displayUrl,
|
|
72480
|
-
// host: url.host
|
|
72481
|
-
// }
|
|
72482
|
-
// } catch (e) {
|
|
72483
|
-
// return {
|
|
72484
|
-
// href: urlString,
|
|
72485
|
-
// displayUrl: urlString,
|
|
72486
|
-
// host: ''
|
|
72487
|
-
// }
|
|
72488
|
-
// }
|
|
72489
|
-
// }
|
|
72309
|
+
useCallback((chat) => {
|
|
72310
|
+
const isPath = Array.isArray(chat?.path) && typeof chat.path[0]?.path === "string" ? chat.path[0].path.trim() : "";
|
|
72311
|
+
const img = isPath ? `${CDN_URL_VIEW}/${isPath}` : "";
|
|
72312
|
+
const toggleExpanded = (messageId) => {
|
|
72313
|
+
const newExpanded = new Set(expandedMessages);
|
|
72314
|
+
if (newExpanded.has(messageId)) {
|
|
72315
|
+
newExpanded.delete(messageId);
|
|
72316
|
+
}
|
|
72317
|
+
else {
|
|
72318
|
+
newExpanded.add(messageId);
|
|
72319
|
+
}
|
|
72320
|
+
setExpandedMessages(newExpanded);
|
|
72321
|
+
};
|
|
72322
|
+
const formatMentionsReact = (text, mentions, messageId) => {
|
|
72323
|
+
if (!text || !mentions || mentions.length === 0) {
|
|
72324
|
+
return text;
|
|
72325
|
+
}
|
|
72326
|
+
const maxLength = 200;
|
|
72327
|
+
const isExpanded = expandedMessages.has(messageId);
|
|
72328
|
+
let displayText = text;
|
|
72329
|
+
let isTruncated = false;
|
|
72330
|
+
if (!isExpanded && text.length > maxLength) {
|
|
72331
|
+
displayText = text.substring(0, maxLength);
|
|
72332
|
+
isTruncated = true;
|
|
72333
|
+
}
|
|
72334
|
+
// Chỉ highlight những mention có trong danh sách
|
|
72335
|
+
let result = displayText;
|
|
72336
|
+
// Hàm helper để xử lý mention trong cả string và array
|
|
72337
|
+
const processMention = (text, mention) => {
|
|
72338
|
+
const escapedName = mention?.name?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
72339
|
+
const mentionRegex = new RegExp(`@${escapedName}(?=\\s|$|[.,;:!?()[\\]{}'"\`~@])`, 'g');
|
|
72340
|
+
const parts = text.split(mentionRegex);
|
|
72341
|
+
const matches = text.match(mentionRegex) || [];
|
|
72342
|
+
if (matches.length === 0) {
|
|
72343
|
+
return text;
|
|
72344
|
+
}
|
|
72345
|
+
const newParts = [];
|
|
72346
|
+
parts.forEach((part, index) => {
|
|
72347
|
+
newParts.push(part);
|
|
72348
|
+
if (matches[index]) {
|
|
72349
|
+
newParts.push(jsx("span", { className: "chat-mention", children: matches[index] }, `mention-${messageId}-${mention.id || mention.name}-${index}`));
|
|
72350
|
+
}
|
|
72351
|
+
});
|
|
72352
|
+
return newParts;
|
|
72353
|
+
};
|
|
72354
|
+
mentions.forEach((mention) => {
|
|
72355
|
+
if (typeof result === 'string') {
|
|
72356
|
+
result = processMention(result, mention);
|
|
72357
|
+
}
|
|
72358
|
+
else if (Array.isArray(result)) {
|
|
72359
|
+
// Xử lý từng phần tử trong array
|
|
72360
|
+
const processedArray = [];
|
|
72361
|
+
result.forEach((item) => {
|
|
72362
|
+
if (typeof item === 'string') {
|
|
72363
|
+
const processed = processMention(item, mention);
|
|
72364
|
+
if (Array.isArray(processed)) {
|
|
72365
|
+
processedArray.push(...processed);
|
|
72366
|
+
}
|
|
72367
|
+
else {
|
|
72368
|
+
processedArray.push(processed);
|
|
72369
|
+
}
|
|
72370
|
+
}
|
|
72371
|
+
else {
|
|
72372
|
+
// Giữ nguyên các React elements đã được xử lý
|
|
72373
|
+
processedArray.push(item);
|
|
72374
|
+
}
|
|
72375
|
+
});
|
|
72376
|
+
result = processedArray;
|
|
72377
|
+
}
|
|
72378
|
+
});
|
|
72379
|
+
// Add expand/collapse functionality
|
|
72380
|
+
if (isTruncated || (isExpanded && text.length > maxLength)) {
|
|
72381
|
+
const expandButton = (jsx("span", { onClick: () => toggleExpanded(messageId), style: {
|
|
72382
|
+
color: '#006edc',
|
|
72383
|
+
cursor: 'pointer',
|
|
72384
|
+
fontWeight: 500,
|
|
72385
|
+
marginLeft: 5
|
|
72386
|
+
}, children: isExpanded ? ' Thu gọn' : '... Mở rộng' }, `expand-${messageId}`));
|
|
72387
|
+
if (Array.isArray(result)) {
|
|
72388
|
+
result.push(expandButton);
|
|
72389
|
+
}
|
|
72390
|
+
else {
|
|
72391
|
+
result = [result, expandButton];
|
|
72392
|
+
}
|
|
72393
|
+
}
|
|
72394
|
+
return result;
|
|
72395
|
+
};
|
|
72396
|
+
return (jsx(Fragment$1, { children: jsx("div", { children: jsxs("div", { children: [chat.path && chat.path.length === 1 && (jsx("div", { className: "image-container", children: img && jsx("img", { src: img, alt: "" }) })), isValidUrl(chat.msg) && renderLinkPreview(chat.msg), chat.msg && !isValidUrl(chat.msg) ? (jsx("div", { children: formatMentionsReact(chat.msg, mentionItems, chat.id) })) : (jsx(Fragment$1, {})), chat.path && chat.path.length > 1 && (jsx("div", { className: "group-image", children: chat.path.map((it, index) => {
|
|
72397
|
+
return (jsx("div", { className: "group-image-item image-container", children: jsx("img", { style: { maxWidth: "100%", maxHeight: 360 }, src: `${CDN_URL_VIEW}/${it.path.trim()}`, onClick: () => handlePreview(it), alt: "" }) }, index));
|
|
72398
|
+
}) })), jsx("div", { className: "", style: { fontSize: "12px", color: "#476285" }, children: moment(chat.time).format("HH:mm") })] }) }) }));
|
|
72399
|
+
}, [expandedMessages, handlePreview, mentionItems]);
|
|
72490
72400
|
// const renderLinkPreview = (urlString: string) => {
|
|
72491
72401
|
// const { href, displayUrl, host } = getLinkPreviewData(urlString)
|
|
72492
72402
|
// return (
|