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