@droppii-org/chat-sdk 0.1.49 → 0.1.50

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.
Files changed (33) hide show
  1. package/dist/assets/svg/expand.d.ts +7 -0
  2. package/dist/assets/svg/expand.d.ts.map +1 -0
  3. package/dist/assets/svg/expand.js +2 -0
  4. package/dist/assets/svg/expand.tsx +44 -0
  5. package/dist/assets/svg/index.d.ts +1 -0
  6. package/dist/assets/svg/index.d.ts.map +1 -1
  7. package/dist/assets/svg/index.js +1 -0
  8. package/dist/assets/svg/index.ts +1 -0
  9. package/dist/components/biz-thread-detail/BizAttachmentPreview.d.ts.map +1 -1
  10. package/dist/components/biz-thread-detail/BizAttachmentPreview.js +1 -5
  11. package/dist/components/biz-thread-detail/BizLinkMessageCard.d.ts +3 -2
  12. package/dist/components/biz-thread-detail/BizLinkMessageCard.d.ts.map +1 -1
  13. package/dist/components/biz-thread-detail/BizLinkMessageCard.js +4 -8
  14. package/dist/components/biz-thread-detail/BizMessageContent.d.ts.map +1 -1
  15. package/dist/components/biz-thread-detail/BizMessageContent.js +59 -5
  16. package/dist/components/biz-thread-detail/BizThreadDetailInput.d.ts.map +1 -1
  17. package/dist/components/biz-thread-detail/BizThreadDetailInput.js +13 -1
  18. package/dist/components/biz-thread-detail/BizVideoViewer.d.ts +8 -0
  19. package/dist/components/biz-thread-detail/BizVideoViewer.d.ts.map +1 -0
  20. package/dist/components/biz-thread-detail/BizVideoViewer.js +103 -0
  21. package/dist/hooks/message/useSendMessage.d.ts +5 -4
  22. package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
  23. package/dist/hooks/message/useSendMessage.js +62 -71
  24. package/dist/styles/global.css +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/dist/types/chat.d.ts +8 -1
  27. package/dist/types/chat.d.ts.map +1 -1
  28. package/dist/utils/bizMessage.d.ts.map +1 -1
  29. package/dist/utils/bizMessage.js +1 -0
  30. package/dist/utils/common.d.ts +1 -0
  31. package/dist/utils/common.d.ts.map +1 -1
  32. package/dist/utils/common.js +7 -0
  33. package/package.json +1 -1
@@ -0,0 +1,7 @@
1
+ interface ISvgProps {
2
+ size?: number;
3
+ className?: string;
4
+ }
5
+ export declare const ExpandIcon: ({ size, className }: ISvgProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
7
+ //# sourceMappingURL=expand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../../../src/assets/svg/expand.tsx"],"names":[],"mappings":"AAAA,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,UAAU,GAAI,qBAA0B,SAAS,4CAsC7D,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export const ExpandIcon = ({ size = 20, className }) => (_jsxs("svg", { width: size, height: size, viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: className, children: [_jsx("path", { d: "M2 7V2H7", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M18 7V2H13", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M2 13V18H7", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M18 13V18H13", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] }));
@@ -0,0 +1,44 @@
1
+ interface ISvgProps {
2
+ size?: number;
3
+ className?: string;
4
+ }
5
+
6
+ export const ExpandIcon = ({ size = 20, className }: ISvgProps) => (
7
+ <svg
8
+ width={size}
9
+ height={size}
10
+ viewBox="0 0 20 20"
11
+ fill="none"
12
+ xmlns="http://www.w3.org/2000/svg"
13
+ className={className}
14
+ >
15
+ <path
16
+ d="M2 7V2H7"
17
+ stroke="currentColor"
18
+ strokeWidth="1.5"
19
+ strokeLinecap="round"
20
+ strokeLinejoin="round"
21
+ />
22
+ <path
23
+ d="M18 7V2H13"
24
+ stroke="currentColor"
25
+ strokeWidth="1.5"
26
+ strokeLinecap="round"
27
+ strokeLinejoin="round"
28
+ />
29
+ <path
30
+ d="M2 13V18H7"
31
+ stroke="currentColor"
32
+ strokeWidth="1.5"
33
+ strokeLinecap="round"
34
+ strokeLinejoin="round"
35
+ />
36
+ <path
37
+ d="M18 13V18H13"
38
+ stroke="currentColor"
39
+ strokeWidth="1.5"
40
+ strokeLinecap="round"
41
+ strokeLinejoin="round"
42
+ />
43
+ </svg>
44
+ );
@@ -1,3 +1,4 @@
1
1
  export * from "./document";
2
2
  export * from "./canned-response";
3
+ export * from "./expand";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/assets/svg/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/assets/svg/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./document";
2
2
  export * from "./canned-response";
3
+ export * from "./expand";
@@ -1,2 +1,3 @@
1
1
  export * from "./document";
2
2
  export * from "./canned-response";
3
+ export * from "./expand";
@@ -1 +1 @@
1
- {"version":3,"file":"BizAttachmentPreview.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizAttachmentPreview.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAmJlC,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,QAAA,MAAM,oBAAoB,GAAI,oCAI3B,yBAAyB,mDAuB3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"BizAttachmentPreview.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizAttachmentPreview.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA8IlC,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,QAAA,MAAM,oBAAoB,GAAI,oCAI3B,yBAAyB,mDAuB3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -5,11 +5,7 @@ import { Icon } from "../../components/icon";
5
5
  import { documentIcon } from "../../assets/svg";
6
6
  import { shortenFileName } from "../../components/message/footer/FilePreview";
7
7
  import { DOCUMENT_MIME_TYPES } from "../../utils/fileValidation";
8
- const formatDuration = (seconds) => {
9
- const minutes = Math.floor(seconds / 60);
10
- const secs = Math.floor(seconds % 60);
11
- return `${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
12
- };
8
+ import { formatDuration } from "../../utils/common";
13
9
  const formatFileSize = (bytes) => {
14
10
  if (bytes === 0)
15
11
  return "0 B";
@@ -1,6 +1,7 @@
1
+ import type { UrlMetadataInfo } from "../../types/chat";
1
2
  export interface BizLinkMessageCardProps {
2
- url: string;
3
+ metadata: UrlMetadataInfo;
3
4
  }
4
- declare const BizLinkMessageCard: ({ url }: BizLinkMessageCardProps) => import("react/jsx-runtime").JSX.Element | null;
5
+ declare const BizLinkMessageCard: ({ metadata }: BizLinkMessageCardProps) => import("react/jsx-runtime").JSX.Element | null;
5
6
  export default BizLinkMessageCard;
6
7
  //# sourceMappingURL=BizLinkMessageCard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BizLinkMessageCard.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizLinkMessageCard.tsx"],"names":[],"mappings":"AAOA,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,QAAA,MAAM,kBAAkB,GAAI,SAAS,uBAAuB,mDA+D3D,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"BizLinkMessageCard.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizLinkMessageCard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,QAAA,MAAM,kBAAkB,GAAI,cAAc,uBAAuB,mDA8ChE,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -1,21 +1,17 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useTranslation } from "react-i18next";
4
- import { useFetchUrlMetadata } from "../../hooks/common/useFetchUrlMetadata";
5
4
  import { getHostLabel } from "../../utils/bizLink";
6
5
  import { openBizLink } from "../../utils/openBizLink";
7
- const BizLinkMessageCard = ({ url }) => {
6
+ const BizLinkMessageCard = ({ metadata }) => {
8
7
  const { t } = useTranslation("biz-inbox");
9
- const { data, isLoading } = useFetchUrlMetadata(url);
10
- if (isLoading) {
11
- return (_jsxs("div", { "data-testid": "biz-link-message-card-loading", className: "flex w-full max-w-[292px] flex-col overflow-hidden rounded-[12px] border border-[rgba(57,62,64,0.1)] bg-white", children: [_jsx("div", { className: "flex aspect-[1920/1080] w-full items-center justify-center bg-[#EAF5FF]", children: _jsx("div", { className: "h-6 w-6 animate-spin rounded-full border-2 border-[#1B3FE4] border-t-transparent" }) }), _jsxs("div", { className: "flex flex-col gap-1 px-3 py-2", children: [_jsx("div", { className: "h-4 w-2/3 animate-pulse rounded bg-[#EFEFEF]" }), _jsx("div", { className: "h-3 w-1/3 animate-pulse rounded bg-[#EFEFEF]" })] })] }));
12
- }
13
- if (!(data === null || data === void 0 ? void 0 : data.title) && !(data === null || data === void 0 ? void 0 : data.description) && !(data === null || data === void 0 ? void 0 : data.image)) {
8
+ const { url, title, description, image } = metadata;
9
+ if (!title && !description && !image) {
14
10
  return null;
15
11
  }
16
12
  const handleOpen = () => {
17
13
  openBizLink(url, t);
18
14
  };
19
- return (_jsxs("button", { type: "button", onClick: handleOpen, "data-testid": "biz-link-message-card", className: "flex w-full max-w-[292px] flex-col overflow-hidden rounded-[12px] border border-[rgba(57,62,64,0.1)] bg-white text-left", children: [(data === null || data === void 0 ? void 0 : data.image) && (_jsx("div", { className: "aspect-[16/9] w-full overflow-hidden", children: _jsx("img", { src: data.image, alt: "", className: "h-full w-full object-cover" }) })), _jsxs("div", { className: "flex flex-col px-3 py-2", children: [(data === null || data === void 0 ? void 0 : data.title) && (_jsx("p", { className: "truncate text-[14px] font-medium leading-[1.6] text-[#393E40]", children: data.title })), _jsx("p", { className: "truncate text-[12px] font-medium leading-[1.6] tracking-[0.12px] text-[#1B3FE4]", children: getHostLabel(url) }), (data === null || data === void 0 ? void 0 : data.description) && (_jsx("p", { className: "line-clamp-2 text-[12px] leading-[1.6] text-[#5C6366]", children: data.description }))] })] }));
15
+ return (_jsxs("button", { type: "button", onClick: handleOpen, "data-testid": "biz-link-message-card", className: "flex w-full max-w-[292px] flex-col overflow-hidden rounded-[12px] border border-[rgba(57,62,64,0.1)] bg-white text-left", children: [image && (_jsx("div", { className: "aspect-[16/9] w-full overflow-hidden", children: _jsx("img", { src: image, alt: "", className: "h-full w-full object-cover" }) })), _jsxs("div", { className: "flex flex-col px-3 py-2", children: [title && (_jsx("p", { className: "truncate text-[14px] font-medium leading-[1.6] text-[#393E40]", children: title })), _jsx("p", { className: "truncate text-[12px] font-medium leading-[1.6] tracking-[0.12px] text-[#1B3FE4]", children: getHostLabel(url) }), description && (_jsx("p", { className: "line-clamp-2 text-[12px] leading-[1.6] text-[#5C6366]", children: description }))] })] }));
20
16
  };
21
17
  export default BizLinkMessageCard;
@@ -1 +1 @@
1
- {"version":3,"file":"BizMessageContent.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizMessageContent.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAA8B,MAAM,yBAAyB,CAAC;AAOlF,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC;CACtB;AAuGD,QAAA,MAAM,iBAAiB,GAAI,aAAa,sBAAsB,mDA4C7D,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"BizMessageContent.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizMessageContent.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAA8B,MAAM,yBAAyB,CAAC;AAalF,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC;CACtB;AAgND,QAAA,MAAM,iBAAiB,GAAI,aAAa,sBAAsB,mDAyD7D,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -4,10 +4,15 @@ import { useState } from "react";
4
4
  import clsx from "clsx";
5
5
  import { MessageStatus, MessageType } from "@openim/wasm-client-sdk";
6
6
  import { Image, Spin } from "antd";
7
+ import { Icon } from "../../components/icon";
8
+ import { documentIcon } from "../../assets/svg";
9
+ import { shortenFileName } from "../../components/message/footer/FilePreview";
7
10
  import BizLinkMessageCard from "./BizLinkMessageCard";
8
11
  import BizLinkTextContent from "./BizLinkTextContent";
9
12
  import BizImageViewer from "./BizImageViewer";
13
+ import BizVideoViewer from "./BizVideoViewer";
10
14
  import { extractBizLinkUrls } from "../../utils/bizLink";
15
+ import { formatDuration, renderFileSize } from "../../utils/common";
11
16
  const MERGE_IMAGE_GRID_COLS_CLASS = {
12
17
  1: "grid-cols-[repeat(1,100px)]",
13
18
  2: "grid-cols-[repeat(2,100px)]",
@@ -43,21 +48,70 @@ const BizMergeImageMessage = ({ message }) => {
43
48
  return (_jsx("div", { className: "cursor-pointer", onClick: () => setViewerIndex(index), children: _jsx(Image, { src: sourceUrl, width: 100, height: 100, className: "rounded-xl object-cover", preview: false, placeholder: _jsx("div", { className: "flex h-[100px] w-[100px] items-center justify-center rounded-xl bg-black/10", children: _jsx(Spin, {}) }) }) }, item.clientMsgID));
44
49
  }) }) }), viewerIndex !== null && (_jsx(BizImageViewer, { images: imageUrls, initialIndex: viewerIndex, onClose: () => setViewerIndex(null) }))] }));
45
50
  };
51
+ const BizVideoMessage = ({ message }) => {
52
+ var _a;
53
+ const [viewerVisible, setViewerVisible] = useState(false);
54
+ const videoElem = message.videoElem;
55
+ const videoUrl = (videoElem === null || videoElem === void 0 ? void 0 : videoElem.videoUrl) || "";
56
+ const posterUrl = (videoElem === null || videoElem === void 0 ? void 0 : videoElem.snapshotUrl) || "";
57
+ const durationSeconds = ((_a = videoElem === null || videoElem === void 0 ? void 0 : videoElem.duration) !== null && _a !== void 0 ? _a : 0) / 1000;
58
+ const isSending = message.status === MessageStatus.Sending;
59
+ return (_jsxs("div", { className: "-mx-1", children: [_jsx(Spin, { spinning: isSending, children: _jsxs("div", { className: "relative h-[150px] w-[215px] cursor-pointer overflow-hidden rounded-xl", onClick: () => setViewerVisible(true), children: [_jsx("img", { src: posterUrl, alt: "", className: "h-full w-full object-cover" }), _jsx("div", { className: "absolute bottom-1 right-1 flex h-[18px] w-9 items-center justify-center rounded-xl bg-black/70", children: _jsx("span", { className: "text-[10px] leading-[1.6] text-white", children: formatDuration(durationSeconds) }) }), _jsx("div", { className: "absolute left-1/2 top-1/2 flex h-[50px] w-[50px] -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-2xl bg-black/60", children: _jsx(Icon, { icon: "play-b", size: 24, className: "text-white" }) })] }) }), viewerVisible && (_jsx(BizVideoViewer, { videoUrl: videoUrl, posterUrl: posterUrl, onClose: () => setViewerVisible(false) }))] }));
60
+ };
61
+ const BizFileMessage = ({ message }) => {
62
+ var _a;
63
+ const fileElem = message.fileElem;
64
+ const fileName = (fileElem === null || fileElem === void 0 ? void 0 : fileElem.fileName) || "";
65
+ const fileSize = (_a = fileElem === null || fileElem === void 0 ? void 0 : fileElem.fileSize) !== null && _a !== void 0 ? _a : 0;
66
+ const sourceUrl = (fileElem === null || fileElem === void 0 ? void 0 : fileElem.sourceUrl) || "";
67
+ const isSending = message.status === MessageStatus.Sending;
68
+ const hasUrl = !!sourceUrl;
69
+ const handleView = () => {
70
+ if (!hasUrl)
71
+ return;
72
+ window.open(sourceUrl, "_blank", "noopener,noreferrer");
73
+ };
74
+ const handleDownload = () => {
75
+ if (!hasUrl)
76
+ return;
77
+ const link = document.createElement("a");
78
+ link.href = sourceUrl;
79
+ link.setAttribute("download", fileName);
80
+ link.setAttribute("target", "_blank");
81
+ link.setAttribute("rel", "noopener noreferrer");
82
+ document.body.appendChild(link);
83
+ link.click();
84
+ link.remove();
85
+ };
86
+ return (_jsx(Spin, { spinning: isSending, children: _jsxs("div", { className: "flex h-[51px] w-[292px] items-center gap-3 rounded-xl border border-[rgba(168,173,175,0.2)] bg-white px-3 py-1", children: [_jsx("div", { className: "flex h-6 w-6 shrink-0 items-center justify-center overflow-hidden [&>svg]:h-6 [&>svg]:w-6", children: documentIcon }), _jsxs("div", { className: "flex min-w-0 w-[168px] flex-col justify-center", children: [_jsx("span", { className: "truncate text-[14px] font-medium leading-[160%] text-[#393E40]", children: shortenFileName(fileName) }), _jsx("span", { className: "truncate text-[13px] leading-[160%] text-[#5C6366]", children: renderFileSize(fileSize) })] }), _jsxs("div", { className: "flex w-[52px] shrink-0 items-center justify-end gap-3", children: [_jsx("button", { type: "button", onClick: handleView, disabled: !hasUrl, "aria-label": "Xem file", className: !hasUrl ? "opacity-30" : undefined, children: _jsx(Icon, { icon: "eye-o", size: 20, className: "text-[#393E40]" }) }), _jsx("button", { type: "button", onClick: handleDownload, disabled: !hasUrl, "aria-label": "T\u1EA3i xu\u1ED1ng", className: !hasUrl ? "opacity-30" : undefined, children: _jsx(Icon, { icon: "download-o", size: 20, className: "text-[#393E40]" }) })] })] }) }));
87
+ };
46
88
  const BizMessageContent = ({ message }) => {
47
- var _a, _b, _c, _d, _e, _f, _g;
89
+ var _a, _b, _c, _d, _e;
48
90
  if (message.contentType === MessageType.PictureMessage) {
49
91
  return _jsx(BizPictureMessage, { message: message });
50
92
  }
93
+ if (message.contentType === MessageType.FileMessage) {
94
+ return _jsx(BizFileMessage, { message: message });
95
+ }
96
+ if (message.contentType === MessageType.VideoMessage) {
97
+ return _jsx(BizVideoMessage, { message: message });
98
+ }
51
99
  if (message.contentType === MessageType.MergeMessage) {
52
100
  return _jsx(BizMergeImageMessage, { message: message });
53
101
  }
54
102
  const text = (_e = (_d = (_b = (_a = message.textElem) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : (_c = message.urlTextElem) === null || _c === void 0 ? void 0 : _c.content) !== null && _d !== void 0 ? _d : message.content) !== null && _e !== void 0 ? _e : "";
55
103
  const hasLinks = text ? extractBizLinkUrls(text).length > 0 : false;
56
104
  if (message.contentType === MessageType.UrlTextMessage) {
57
- const urls = (_g = (_f = message.urlTextElem) === null || _f === void 0 ? void 0 : _f.urls) !== null && _g !== void 0 ? _g : [];
58
- const singleLink = urls.length === 1 ? urls[0] : null;
59
- if (singleLink) {
60
- return (_jsxs("div", { className: "flex max-w-[292px] flex-col gap-2", children: [text && _jsx(BizLinkTextContent, { text: text }), _jsx(BizLinkMessageCard, { url: singleLink })] }));
105
+ let urlMetadata;
106
+ try {
107
+ const ex = JSON.parse(message.ex || "{}");
108
+ urlMetadata = ex.urlMetadata;
109
+ }
110
+ catch (_f) {
111
+ urlMetadata = undefined;
112
+ }
113
+ if (urlMetadata === null || urlMetadata === void 0 ? void 0 : urlMetadata.url) {
114
+ return (_jsxs("div", { className: "flex max-w-[292px] flex-col gap-2", children: [text && _jsx(BizLinkTextContent, { text: text }), _jsx(BizLinkMessageCard, { metadata: urlMetadata })] }));
61
115
  }
62
116
  return text ? _jsx(BizLinkTextContent, { text: text }) : null;
63
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BizThreadDetailInput.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizThreadDetailInput.tsx"],"names":[],"mappings":"AA8BA,MAAM,WAAW,yBAAyB;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,QAAA,MAAM,oBAAoB,GAAI,gDAI3B,yBAAyB,4CAkY3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"BizThreadDetailInput.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizThreadDetailInput.tsx"],"names":[],"mappings":"AA+BA,MAAM,WAAW,yBAAyB;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,QAAA,MAAM,oBAAoB,GAAI,gDAI3B,yBAAyB,4CAiZ3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -13,6 +13,7 @@ import useBizMessageDraftStore from "../../store/bizMessageDraft";
13
13
  import { resolveBizAvatarUrl, resolveBizDisplayName, } from "../../utils/bizConversation";
14
14
  import { emit } from "../../utils/events";
15
15
  import { extractBizLinkUrls } from "../../utils/bizLink";
16
+ import { useFetchUrlMetadata } from "../../hooks/common/useFetchUrlMetadata";
16
17
  import { processAndValidateDocuments, processAndValidateFiles, } from "../../utils/fileValidation";
17
18
  import BizAttachmentPreview from "./BizAttachmentPreview";
18
19
  import BizLinkInputPreview from "./BizLinkInputPreview";
@@ -58,10 +59,12 @@ const BizThreadDetailInput = ({ placeholder, onSendMessage, onInputChange, }) =>
58
59
  const [previewDismissed, setPreviewDismissed] = useState(false);
59
60
  const [isMoreOptionOpen, { setFalse: closeMoreOption, toggle: toggleMoreOption },] = useBoolean(false);
60
61
  const previewUrl = useMemo(() => {
62
+ var _a;
61
63
  const urls = extractBizLinkUrls(value);
62
- return urls.length === 1 ? urls[0] : null;
64
+ return (_a = urls[0]) !== null && _a !== void 0 ? _a : null;
63
65
  }, [value]);
64
66
  const showLinkPreview = !!previewUrl && !previewDismissed;
67
+ const { data: previewMetadata } = useFetchUrlMetadata(previewUrl !== null && previewUrl !== void 0 ? previewUrl : "", showLinkPreview);
65
68
  useEffect(() => {
66
69
  setPreviewDismissed(false);
67
70
  }, [previewUrl]);
@@ -192,10 +195,19 @@ const BizThreadDetailInput = ({ placeholder, onSendMessage, onInputChange, }) =>
192
195
  setListUploadFiles([]);
193
196
  }
194
197
  else {
198
+ const urlMetadata = showLinkPreview && previewUrl && previewMetadata
199
+ ? {
200
+ url: previewUrl,
201
+ title: previewMetadata.title,
202
+ description: previewMetadata.description,
203
+ image: previewMetadata.image,
204
+ }
205
+ : undefined;
195
206
  const sent = await sendTextMessage({
196
207
  plainText: text,
197
208
  richText: "",
198
209
  isInternal: false,
210
+ urlMetadata,
199
211
  });
200
212
  if (!sent)
201
213
  return;
@@ -0,0 +1,8 @@
1
+ interface BizVideoViewerProps {
2
+ videoUrl: string;
3
+ posterUrl?: string;
4
+ onClose: () => void;
5
+ }
6
+ declare const BizVideoViewer: ({ videoUrl, posterUrl, onClose }: BizVideoViewerProps) => import("react").ReactPortal;
7
+ export default BizVideoViewer;
8
+ //# sourceMappingURL=BizVideoViewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BizVideoViewer.d.ts","sourceRoot":"","sources":["../../../src/components/biz-thread-detail/BizVideoViewer.tsx"],"names":[],"mappings":"AAQA,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAID,QAAA,MAAM,cAAc,GAAI,kCAAkC,mBAAmB,gCAyM5E,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,103 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { createPortal } from "react-dom";
5
+ import { Icon } from "../../components/icon";
6
+ import { ExpandIcon } from "../../assets/svg";
7
+ import { formatDuration } from "../../utils/common";
8
+ const SKIP_SECONDS = 10;
9
+ const BizVideoViewer = ({ videoUrl, posterUrl, onClose }) => {
10
+ var _a;
11
+ const containerRef = useRef(null);
12
+ const videoRef = useRef(null);
13
+ const [isPlaying, setIsPlaying] = useState(false);
14
+ const [isMuted, setIsMuted] = useState(false);
15
+ const [isFullscreen, setIsFullscreen] = useState(false);
16
+ const [currentTime, setCurrentTime] = useState(0);
17
+ const [duration, setDuration] = useState(0);
18
+ const togglePlay = () => {
19
+ const video = videoRef.current;
20
+ if (!video)
21
+ return;
22
+ if (video.paused) {
23
+ void video.play();
24
+ }
25
+ else {
26
+ video.pause();
27
+ }
28
+ };
29
+ const skip = (seconds) => {
30
+ const video = videoRef.current;
31
+ if (!video)
32
+ return;
33
+ const max = video.duration || Infinity;
34
+ video.currentTime = Math.min(Math.max(video.currentTime + seconds, 0), max);
35
+ setCurrentTime(video.currentTime);
36
+ };
37
+ const toggleFullscreen = () => {
38
+ var _a, _b;
39
+ const el = containerRef.current;
40
+ if (!el)
41
+ return;
42
+ if (!document.fullscreenElement) {
43
+ void ((_a = el.requestFullscreen) === null || _a === void 0 ? void 0 : _a.call(el));
44
+ }
45
+ else {
46
+ void ((_b = document.exitFullscreen) === null || _b === void 0 ? void 0 : _b.call(document));
47
+ }
48
+ };
49
+ useEffect(() => {
50
+ const handleKeyDown = (event) => {
51
+ if (event.key === "Escape")
52
+ onClose();
53
+ if (event.key === " ") {
54
+ event.preventDefault();
55
+ togglePlay();
56
+ }
57
+ if (event.key === "ArrowLeft")
58
+ skip(-SKIP_SECONDS);
59
+ if (event.key === "ArrowRight")
60
+ skip(SKIP_SECONDS);
61
+ };
62
+ document.addEventListener("keydown", handleKeyDown);
63
+ return () => document.removeEventListener("keydown", handleKeyDown);
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ }, [onClose]);
66
+ useEffect(() => {
67
+ const handleFullscreenChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
68
+ document.addEventListener("fullscreenchange", handleFullscreenChange);
69
+ return () => document.removeEventListener("fullscreenchange", handleFullscreenChange);
70
+ }, []);
71
+ useEffect(() => {
72
+ var _a;
73
+ (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play().catch(() => { });
74
+ }, []);
75
+ const toggleMute = () => {
76
+ const video = videoRef.current;
77
+ if (!video)
78
+ return;
79
+ video.muted = !video.muted;
80
+ setIsMuted(video.muted);
81
+ };
82
+ const handleSeek = (event) => {
83
+ const video = videoRef.current;
84
+ if (!video)
85
+ return;
86
+ const value = Number(event.target.value);
87
+ video.currentTime = value;
88
+ setCurrentTime(value);
89
+ };
90
+ const handleDownload = () => {
91
+ const filename = videoUrl.substring(videoUrl.lastIndexOf("/") + 1) || "video";
92
+ const link = document.createElement("a");
93
+ link.href = videoUrl;
94
+ link.download = filename;
95
+ document.body.appendChild(link);
96
+ link.click();
97
+ document.body.removeChild(link);
98
+ };
99
+ const remainingTime = Math.max(duration - currentTime, 0);
100
+ const container = (_a = document.querySelector('[data-testid="biz-thread-detail-root"]')) !== null && _a !== void 0 ? _a : document.body;
101
+ return createPortal(_jsxs("div", { ref: containerRef, className: "absolute inset-0 z-[999] flex flex-col bg-black", children: [_jsxs("div", { className: "flex items-center justify-between px-4 pt-12 pb-4", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx("button", { type: "button", className: "flex h-10 w-10 items-center justify-center text-white", onClick: onClose, "aria-label": "\u0110\u00F3ng", children: _jsx(Icon, { icon: "close-b", size: 24 }) }), _jsx("button", { type: "button", className: "flex h-10 w-10 items-center justify-center text-white", onClick: toggleFullscreen, "aria-label": isFullscreen ? "Thu nhỏ" : "Toàn màn hình", children: _jsx(ExpandIcon, { size: 20 }) })] }), _jsx("button", { type: "button", className: "flex h-10 w-10 items-center justify-center text-white", onClick: handleDownload, "aria-label": "T\u1EA3i xu\u1ED1ng", children: _jsx(Icon, { icon: "download-o", size: 24 }) })] }), _jsxs("div", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden px-4", children: [_jsx("video", { ref: videoRef, src: videoUrl, poster: posterUrl, className: "max-h-full max-w-full rounded-[24px] object-contain", onPlay: () => setIsPlaying(true), onPause: () => setIsPlaying(false), onTimeUpdate: (event) => setCurrentTime(event.currentTarget.currentTime), onLoadedMetadata: (event) => setDuration(event.currentTarget.duration), onClick: togglePlay }), _jsxs("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-between px-8", children: [_jsx("button", { type: "button", className: "pointer-events-auto relative flex h-9 w-9 items-center justify-center text-white", onClick: () => skip(-SKIP_SECONDS), "aria-label": "L\u00F9i 10 gi\u00E2y", children: _jsx(Icon, { icon: "arrow-reload-o", size: 30 }) }), !isPlaying && (_jsx("button", { type: "button", className: "pointer-events-auto flex h-[50px] w-[50px] shrink-0 items-center justify-center rounded-2xl bg-black/60", onClick: togglePlay, "aria-label": "Ph\u00E1t", children: _jsx(Icon, { icon: "play-b", size: 24, className: "text-white" }) })), _jsx("button", { type: "button", className: "pointer-events-auto relative flex h-9 w-9 items-center justify-center text-white", onClick: () => skip(SKIP_SECONDS), "aria-label": "Ti\u1EBFn 10 gi\u00E2y", children: _jsx(Icon, { icon: "arrow-reload-o", size: 30, className: "-scale-x-100" }) })] })] }), _jsx("div", { className: "flex flex-col gap-2 px-4 pb-8 pt-4", children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "w-9 shrink-0 text-xs text-white", children: formatDuration(currentTime) }), _jsx("input", { type: "range", min: 0, max: duration || 0, step: 0.1, value: currentTime, onChange: handleSeek, className: "h-1 flex-1 cursor-pointer appearance-none rounded-full bg-white/30 accent-white" }), _jsxs("span", { className: "w-9 shrink-0 text-right text-xs text-white", children: ["-", formatDuration(remainingTime)] }), _jsx("button", { type: "button", onClick: toggleMute, className: "flex h-6 w-6 shrink-0 items-center justify-center text-white", "aria-label": "\u00C2m l\u01B0\u1EE3ng", children: _jsx(Icon, { icon: isMuted ? "volume-off-o" : "volume-up-o", size: 20 }) })] }) })] }), container);
102
+ };
103
+ export default BizVideoViewer;
@@ -1,5 +1,5 @@
1
1
  import { MergerMsgParams, MessageItem } from "@openim/wasm-client-sdk";
2
- import { ExtendMessageInfo, FileMsgParamsByFile, ImageMsgParamsByFile, VideoMsgParamsByFile } from "../../types/chat";
2
+ import { ExtendMessageInfo, FileMsgParamsByFile, ImageMsgParamsByFile, UrlMetadataInfo, VideoMsgParamsByFile } from "../../types/chat";
3
3
  import { UploadFile } from "antd";
4
4
  import { ISessionResponse } from "../../types/dto";
5
5
  export declare const isMediaResendable: (message: {
@@ -27,11 +27,12 @@ export interface UseSendMessageOptions {
27
27
  }) => OfflinePushMeta;
28
28
  }
29
29
  export declare const useSendMessage: (options?: UseSendMessageOptions) => {
30
- sendTextMessage: ({ plainText, richText, currentSession, isInternal, }: {
30
+ sendTextMessage: ({ plainText, richText, currentSession, isInternal, urlMetadata, }: {
31
31
  plainText: string;
32
32
  richText: string;
33
33
  currentSession?: ISessionResponse;
34
34
  isInternal: boolean;
35
+ urlMetadata?: UrlMetadataInfo;
35
36
  }) => Promise<boolean>;
36
37
  sendMergeMessage: ({ richText, plainText, files, currentSession, isInternal, }: {
37
38
  richText: string;
@@ -42,9 +43,9 @@ export declare const useSendMessage: (options?: UseSendMessageOptions) => {
42
43
  }) => Promise<void>;
43
44
  resendMessage: (failedMessage: MessageItem) => Promise<void>;
44
45
  };
45
- export declare const generateExtendMessageInfo: ({ richText, plainText, currentSession, }: {
46
+ export declare const generateExtendMessageInfo: ({ richText, urlMetadata, currentSession, }: {
46
47
  richText?: string;
47
- plainText?: string;
48
+ urlMetadata?: UrlMetadataInfo;
48
49
  currentSession?: ISessionResponse;
49
50
  }) => ExtendMessageInfo;
50
51
  //# sourceMappingURL=useSendMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAWtB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAUlC,OAAO,EAAgB,gBAAgB,EAAyB,MAAM,aAAa,CAAC;AAkBpF,eAAO,MAAM,iBAAiB,GAAI,SAAS;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,YAE0C,CAAC;AAE5C,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,gCAanD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAU,iBAAiB,eAAe,gCAazE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,MAAM,mBAAmB,gCAatE,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,gCActE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GA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