@esvndev/es-react-template-chat 0.0.91 → 0.0.92

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 CHANGED
@@ -72426,141 +72426,83 @@ const ChatLog = (props) => {
72426
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
72427
  }) })), jsxRuntime.jsx("div", { className: "", style: { fontSize: "12px", color: "#476285" }, children: moment(chat.time).format("HH:mm") })] }) }) }));
72428
72428
  }, [expandedMessages, handlePreview, mentionItems]);
72429
- // const renderLinkPreview = (urlString: string) => {
72430
- // const { href, displayUrl, host } = getLinkPreviewData(urlString)
72431
- // return (
72432
- // <>
72433
- // <a
72434
- // href={href}
72435
- // target="_blank"
72436
- // rel="noreferrer"
72437
- // style={{
72438
- // textDecoration: 'none',
72439
- // color: 'inherit'
72440
- // }}
72441
- // >
72442
- // <div
72443
- // style={{
72444
- // marginTop: 4,
72445
- // marginBottom: 4,
72446
- // padding: '8px 10px',
72447
- // borderRadius: 8,
72448
- // backgroundColor: '#eef5ff',
72449
- // border: '1px solid #d3e2ff',
72450
- // maxWidth: 420
72451
- // }}
72452
- // >
72453
- // <div
72454
- // style={{
72455
- // fontSize: 14,
72456
- // fontWeight: 500,
72457
- // color: '#1d4f91',
72458
- // wordBreak: 'break-word'
72459
- // }}
72460
- // >
72461
- // {displayUrl}
72462
- // </div>
72463
- // {host && (
72464
- // <div
72465
- // style={{
72466
- // marginTop: 4,
72467
- // fontSize: 12,
72468
- // color: '#6f6b7d'
72469
- // }}
72470
- // >
72471
- // {host}
72472
- // </div>
72473
- // )}
72474
- // </div>
72475
- // </a>
72476
- // </>
72477
- // )
72478
- // }
72479
- // const renderNotifyLeaveGroup = useCallback((chat: any) => {
72480
- // const msg = JSON.parse(chat?.msg)
72481
- // if (chat?.createdById === dataProfile?.id) {
72482
- // return (
72483
- // <>
72484
- // <div>
72485
- // <span style={{ fontWeight: "bold", marginRight: "5px" }}>
72486
- // {msg?.name}
72487
- // </span>
72488
- // <span>được bạn xoá khỏi nhóm</span>
72489
- // </div>
72490
- // </>
72491
- // )
72492
- // }
72493
- // if (chat?.createdById === msg?.id) {
72494
- // return (
72495
- // <>
72496
- // <div>
72497
- // <span style={{ fontWeight: "bold", marginRight: "5px" }}>
72498
- // {msg?.name}
72499
- // </span>
72500
- // <span>đã rời khỏi nhóm</span>
72501
- // </div>
72502
- // </>
72503
- // )
72504
- // }
72505
- // return (
72506
- // <>
72507
- // <div>
72508
- // <span style={{ fontWeight: "bold", marginRight: "5px" }}>
72509
- // {msg?.name}
72510
- // </span>
72511
- // <span>được <span style={{ fontWeight: "bold", marginRight: "5px" }}>{chat?.createdBy?.name}</span> xoá khỏi nhóm</span>
72512
- // </div>
72513
- // </>
72514
- // )
72515
- // }, [dataProfile])
72516
- // const renderChatNotification = useCallback((chat: any) => {
72517
- // const parseChatMsg = (msg: string) => {
72518
- // if (!msg) { return [] }
72519
- // try {
72520
- // const parsed = typeof msg === 'string' ? JSON.parse(msg) : msg
72521
- // return Array.isArray(parsed) ? parsed : [parsed]
72522
- // } catch (err) {
72523
- // console.error('JSON parse error:', err)
72524
- // return []
72525
- // }
72526
- // }
72527
- // const dataParse = parseChatMsg(chat.msg)
72528
- // // ✅ FIX: Kiểm tra array trước khi dùng slice
72529
- // if (!Array.isArray(dataParse) || dataParse.length === 0) {
72530
- // return (
72531
- // <div>
72532
- // <span>Đã có thay đổi trong nhóm</span>
72533
- // </div>
72534
- // )
72535
- // }
72536
- // const displayedItems = dataParse.slice(0, 2)
72537
- // const extraCount = Math.max(0, dataParse.length - displayedItems.length)
72538
- // return (
72539
- // <>
72540
- // <div>
72541
- // {displayedItems.map((item: any, index: any) => (
72542
- // <strong key={index}>
72543
- // {item.name}
72544
- // {index < displayedItems.length - 1 && ", "}
72545
- // </strong>
72546
- // ))}
72547
- // {dataParse.length > 3 && (
72548
- // <strong>
72549
- // <span style={{ fontWeight: "normal" }}>{" và "}</span>{" "}
72550
- // {extraCount} người khác
72551
- // </strong>
72552
- // )}
72553
- // {" được "}
72554
- // {chat?.createdBy?.id === dataProfile?.id ? (
72555
- // <span>bạn </span>
72556
- // ) : (
72557
- // <strong style={{ marginRight: "5px" }}>{chat?.createdByName}</strong>
72558
- // )}
72559
- // thêm vào nhóm
72560
- // </div>
72561
- // </>
72562
- // )
72563
- // }, [dataProfile])
72429
+ const getLinkPreviewData = (urlString) => {
72430
+ try {
72431
+ const hasProtocol = /^https?:\/\//i.test(urlString);
72432
+ const href = hasProtocol ? urlString : `https://${urlString}`;
72433
+ const url = new URL(href);
72434
+ const displayUrl = urlString.length > 80 ? `${urlString.slice(0, 77)}...` : urlString;
72435
+ return {
72436
+ href,
72437
+ displayUrl,
72438
+ host: url.host
72439
+ };
72440
+ }
72441
+ catch (e) {
72442
+ return {
72443
+ href: urlString,
72444
+ displayUrl: urlString,
72445
+ host: ''
72446
+ };
72447
+ }
72448
+ };
72449
+ const renderLinkPreview = (urlString) => {
72450
+ const { href, displayUrl, host } = getLinkPreviewData(urlString);
72451
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("a", { href: href, target: "_blank", rel: "noreferrer", style: {
72452
+ textDecoration: 'none',
72453
+ color: 'inherit'
72454
+ }, children: jsxRuntime.jsxs("div", { style: {
72455
+ marginTop: 4,
72456
+ marginBottom: 4,
72457
+ padding: '8px 10px',
72458
+ borderRadius: 8,
72459
+ backgroundColor: '#eef5ff',
72460
+ border: '1px solid #d3e2ff',
72461
+ maxWidth: 420
72462
+ }, children: [jsxRuntime.jsx("div", { style: {
72463
+ fontSize: 14,
72464
+ fontWeight: 500,
72465
+ color: '#1d4f91',
72466
+ wordBreak: 'break-word'
72467
+ }, children: displayUrl }), host && (jsxRuntime.jsx("div", { style: {
72468
+ marginTop: 4,
72469
+ fontSize: 12,
72470
+ color: '#6f6b7d'
72471
+ }, children: host }))] }) }) }));
72472
+ };
72473
+ React.useCallback((chat) => {
72474
+ const msg = JSON.parse(chat?.msg);
72475
+ if (chat?.createdById === dataProfile?.id) {
72476
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("span", { style: { fontWeight: "bold", marginRight: "5px" }, children: msg?.name }), jsxRuntime.jsx("span", { children: "\u0111\u01B0\u1EE3c b\u1EA1n xo\u00E1 kh\u1ECFi nh\u00F3m" })] }) }));
72477
+ }
72478
+ if (chat?.createdById === msg?.id) {
72479
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("span", { style: { fontWeight: "bold", marginRight: "5px" }, children: msg?.name }), jsxRuntime.jsx("span", { children: "\u0111\u00E3 r\u1EDDi kh\u1ECFi nh\u00F3m" })] }) }));
72480
+ }
72481
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("span", { style: { fontWeight: "bold", marginRight: "5px" }, children: msg?.name }), jsxRuntime.jsxs("span", { children: ["\u0111\u01B0\u1EE3c ", jsxRuntime.jsx("span", { style: { fontWeight: "bold", marginRight: "5px" }, children: chat?.createdBy?.name }), " xo\u00E1 kh\u1ECFi nh\u00F3m"] })] }) }));
72482
+ }, [dataProfile]);
72483
+ React.useCallback((chat) => {
72484
+ const parseChatMsg = (msg) => {
72485
+ if (!msg) {
72486
+ return [];
72487
+ }
72488
+ try {
72489
+ const parsed = typeof msg === 'string' ? JSON.parse(msg) : msg;
72490
+ return Array.isArray(parsed) ? parsed : [parsed];
72491
+ }
72492
+ catch (err) {
72493
+ console.error('JSON parse error:', err);
72494
+ return [];
72495
+ }
72496
+ };
72497
+ const dataParse = parseChatMsg(chat.msg);
72498
+ // ✅ FIX: Kiểm tra array trước khi dùng slice
72499
+ if (!Array.isArray(dataParse) || dataParse.length === 0) {
72500
+ return (jsxRuntime.jsx("div", { children: jsxRuntime.jsx("span", { children: "\u0110\u00E3 c\u00F3 thay \u0111\u1ED5i trong nh\u00F3m" }) }));
72501
+ }
72502
+ const displayedItems = dataParse.slice(0, 2);
72503
+ const extraCount = Math.max(0, dataParse.length - displayedItems.length);
72504
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { children: [displayedItems.map((item, index) => (jsxRuntime.jsxs("strong", { children: [item.name, index < displayedItems.length - 1 && ", "] }, index))), dataParse.length > 3 && (jsxRuntime.jsxs("strong", { children: [jsxRuntime.jsx("span", { style: { fontWeight: "normal" }, children: " và " }), " ", extraCount, " ng\u01B0\u1EDDi kh\u00E1c"] })), " được ", chat?.createdBy?.id === dataProfile?.id ? (jsxRuntime.jsx("span", { children: "b\u1EA1n " })) : (jsxRuntime.jsx("strong", { style: { marginRight: "5px" }, children: chat?.createdByName })), "th\u00EAm v\u00E0o nh\u00F3m"] }) }));
72505
+ }, [dataProfile]);
72564
72506
  // const renderChatImage = useCallback((chat: any) => {
72565
72507
  // const files = chat.path
72566
72508
  // if (!files || !Array.isArray(files) || files.length === 0) {