@infinilabs/doc-detail 0.0.10 → 0.0.11

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infinilabs/doc-detail",
3
3
  "private": false,
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "main": "dist/doc-detail.cjs",
7
7
  "module": "dist/doc-detail.js",
@@ -25,6 +25,7 @@
25
25
  "@ant-design/x": "^2.1.3",
26
26
  "@ant-design/x-markdown": "^2.1.3",
27
27
  "@infinilabs/markdown": "^0.0.2",
28
+ "ahooks": "^3.9.6",
28
29
  "antd": "^6.0.0",
29
30
  "clsx": "^2.1.1",
30
31
  "docx-preview": "^0.3.7",
package/src/App.tsx CHANGED
@@ -12,11 +12,16 @@ const App = () => {
12
12
  },
13
13
  category: "report",
14
14
  title: "Q3 Business Report",
15
- icon: "https://picsum.photos/seed/file-icon/40/40",
15
+ icon: "https://dev.infini.cloud:27200/assets/icons/connector/s3/file.png",
16
16
  size: 1048576,
17
- url: "/document/dce0c5efb29bf5647c34eb58ecabca93/raw_content/1%E5%88%86%E9%92%9F%E8%83%BD%E5%81%9A%E4%BB%80%E4%B9%88%EF%BC%9F%E4%B8%8D%E5%8F%AF%E6%80%9D%E8%AE%AE%E7%9A%84_%E6%88%98%E6%8B%96_%E5%BF%83%E7%90%86%E5%AD%A6_(%E7%BE%8E)%E6%9D%B0%E5%A4%AB%C2%B7%E6%88%B4%E7%BB%B4%E6%A3%AE_%E6%96%B0%E4%B8%96%E7%95%8C_2013.5.pdf",
17
+ // url: "/document/dce0c5efb29bf5647c34eb58ecabca93/raw_content/1%E5%8z8%86%E9%92%9F%E8%83%BD%E5%81%9A%E4%BB%80%E4%B9%88%EF%BC%9F%E4%B8%8D%E5%8F%AF%E6%80%9D%E8%AE%AE%E7%9A%84_%E6%88%98%E6%8B%96_%E5%BF%83%E7%90%86%E5%AD%A6_(%E7%BE%8E)%E6%9D%B0%E5%A4%AB%C2%B7%E6%88%B4%E7%BB%B4%E6%A3%AE_%E6%96%B0%E4%B8%96%E7%95%8C_2013.5.pdf",
18
+ url: "/document/3fbcffdbdf044ad2cf9edc3b0e1741d3/raw_content/106347408.jpg",
19
+ thumbnail:
20
+ "https://dev.infini.cloud:27200/attachment/d5itnq14d9v3mq6oucag",
18
21
  metadata: {
19
- content_type: "pdf",
22
+ content_type: "image",
23
+ width: 3062,
24
+ height: 2041,
20
25
  },
21
26
  owner: {
22
27
  title: "Alice Johnson",
@@ -0,0 +1,54 @@
1
+ import { useMemo, useRef, useState, type FC } from "react";
2
+ import { Image as AntdImage, Skeleton } from "antd";
3
+ import { useSize } from "ahooks";
4
+
5
+ import type { DocDetailProps } from "@/components/DocDetail";
6
+
7
+ const Image: FC<DocDetailProps> = (props) => {
8
+ const { data } = props;
9
+ const containerRef = useRef<HTMLDivElement>(null);
10
+ const containerSize = useSize(containerRef);
11
+ const [failed, setFailed] = useState(false);
12
+
13
+ const calcHeight = useMemo(() => {
14
+ const containerWidth = containerSize?.width;
15
+ const originalWidth = data?.metadata?.width;
16
+ const originalHeight = data?.metadata?.height;
17
+
18
+ if (!containerWidth || !originalWidth || !originalHeight) {
19
+ return void 0;
20
+ }
21
+
22
+ return containerWidth * (originalHeight / originalWidth);
23
+ }, [containerSize?.width, data?.metadata?.width, data?.metadata?.height]);
24
+
25
+ return (
26
+ <div
27
+ ref={containerRef}
28
+ className="w-full"
29
+ style={{
30
+ height: calcHeight,
31
+ }}
32
+ >
33
+ <AntdImage
34
+ preview={false}
35
+ rootClassName="size-full"
36
+ placeholder={
37
+ <Skeleton.Node
38
+ active
39
+ classNames={{
40
+ root: "size-full!",
41
+ content: "size-full!",
42
+ }}
43
+ />
44
+ }
45
+ src={failed ? data?.thumbnail : data?.url}
46
+ onError={() => {
47
+ setFailed(true);
48
+ }}
49
+ />
50
+ </div>
51
+ );
52
+ };
53
+
54
+ export default Image;
@@ -9,6 +9,7 @@ import Markdown from "@infinilabs/markdown";
9
9
  import Pdf from "./components/Pdf";
10
10
  import Docx from "./components/Docx";
11
11
  import Pptx from "./components/Pptx";
12
+ import Image from "./components/Image";
12
13
 
13
14
  const Preview: FC<DocDetailProps> = (props) => {
14
15
  const { data, i18n } = props;
@@ -40,7 +41,7 @@ const Preview: FC<DocDetailProps> = (props) => {
40
41
  if (!type || !url) return;
41
42
 
42
43
  if (type === "image") {
43
- return <img src={url} className="w-full" />;
44
+ return <Image {...props} />;
44
45
  }
45
46
 
46
47
  if (type === "video") {