@glodon-aiot/react-components 3.11.0-snapshot.1765331443 → 3.11.0-snapshot.1765331449
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/es/components/DocumentViewer/components/FileRenderers.mjs +1 -0
- package/dist/es/components/DocumentViewer/components/PdfRenderer.mjs +5 -4
- package/dist/es/components/DocumentViewer/components/ZipRenderer.mjs +20 -15
- package/dist/es/components/DocumentViewer/hooks/useZipViewer.mjs +62 -60
- package/dist/es/components/DocumentViewer/index.mjs +131 -129
- package/dist/es/index.mjs +1 -1
- package/dist/lib/index.js +10 -10
- package/dist/src/components/DocumentViewer/components/PdfRenderer.d.ts +1 -0
- package/dist/src/components/DocumentViewer/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import { Spin as m, Alert as n } from "antd";
|
|
3
3
|
import { DownloadButton as s } from "./DownloadButton.mjs";
|
|
4
|
-
const
|
|
4
|
+
const f = ({
|
|
5
5
|
pdfBlobUrl: r,
|
|
6
6
|
pdfLoading: c,
|
|
7
7
|
pdfError: i,
|
|
8
8
|
url: t,
|
|
9
|
-
fileName: o
|
|
9
|
+
fileName: o,
|
|
10
|
+
page: a = 1
|
|
10
11
|
}) => c ? /* @__PURE__ */ e("div", {
|
|
11
12
|
className: "document-viewer-loading",
|
|
12
13
|
children: /* @__PURE__ */ e(m, {
|
|
@@ -25,7 +26,7 @@ const u = ({
|
|
|
25
26
|
}) : r ? /* @__PURE__ */ e("div", {
|
|
26
27
|
className: "document-viewer-pdf",
|
|
27
28
|
children: /* @__PURE__ */ e("iframe", {
|
|
28
|
-
src: r
|
|
29
|
+
src: `${r}#page=${a}`,
|
|
29
30
|
className: "document-viewer-iframe",
|
|
30
31
|
title: "PDF Preview"
|
|
31
32
|
})
|
|
@@ -40,5 +41,5 @@ const u = ({
|
|
|
40
41
|
})
|
|
41
42
|
});
|
|
42
43
|
export {
|
|
43
|
-
|
|
44
|
+
f as PdfRenderer
|
|
44
45
|
};
|
|
@@ -3,11 +3,11 @@ import { Spin as m, Alert as d, Table as f } from "antd";
|
|
|
3
3
|
import h from "../index.mjs";
|
|
4
4
|
import { formatFileSize as p } from "../utils.mjs";
|
|
5
5
|
const v = ({
|
|
6
|
-
zipFiles:
|
|
6
|
+
zipFiles: t,
|
|
7
7
|
zipLoading: a,
|
|
8
|
-
zipError:
|
|
9
|
-
selectedZipFile:
|
|
10
|
-
zipFileContent:
|
|
8
|
+
zipError: i,
|
|
9
|
+
selectedZipFile: n,
|
|
10
|
+
zipFileContent: o,
|
|
11
11
|
onFileClick: s,
|
|
12
12
|
url: c
|
|
13
13
|
}) => a ? /* @__PURE__ */ e("div", {
|
|
@@ -16,10 +16,10 @@ const v = ({
|
|
|
16
16
|
size: "large",
|
|
17
17
|
tip: "加载 ZIP 文件..."
|
|
18
18
|
})
|
|
19
|
-
}) :
|
|
19
|
+
}) : i && t.length === 0 ? /* @__PURE__ */ e(d, {
|
|
20
20
|
className: "document-viewer-alert-full",
|
|
21
21
|
message: "ZIP 加载失败",
|
|
22
|
-
description:
|
|
22
|
+
description: i,
|
|
23
23
|
type: "error",
|
|
24
24
|
showIcon: !0,
|
|
25
25
|
action: /* @__PURE__ */ e("a", {
|
|
@@ -30,10 +30,10 @@ const v = ({
|
|
|
30
30
|
})
|
|
31
31
|
}) : /* @__PURE__ */ r("div", {
|
|
32
32
|
className: "document-viewer-zip",
|
|
33
|
-
children: [
|
|
33
|
+
children: [i && t.length > 0 && /* @__PURE__ */ e(d, {
|
|
34
34
|
className: "document-viewer-alert-full",
|
|
35
35
|
message: "提示",
|
|
36
|
-
description:
|
|
36
|
+
description: i,
|
|
37
37
|
type: "warning",
|
|
38
38
|
showIcon: !0,
|
|
39
39
|
style: {
|
|
@@ -60,7 +60,7 @@ const v = ({
|
|
|
60
60
|
borderBottom: "1px solid #e8e8e8",
|
|
61
61
|
flexShrink: 0
|
|
62
62
|
},
|
|
63
|
-
children: ["文件列表 (",
|
|
63
|
+
children: ["文件列表 (", t.length, ")"]
|
|
64
64
|
}), /* @__PURE__ */ e("div", {
|
|
65
65
|
style: {
|
|
66
66
|
flex: 1,
|
|
@@ -68,7 +68,7 @@ const v = ({
|
|
|
68
68
|
minHeight: 0
|
|
69
69
|
},
|
|
70
70
|
children: /* @__PURE__ */ e(f, {
|
|
71
|
-
dataSource:
|
|
71
|
+
dataSource: t,
|
|
72
72
|
size: "small",
|
|
73
73
|
pagination: !1,
|
|
74
74
|
scroll: {
|
|
@@ -78,7 +78,7 @@ const v = ({
|
|
|
78
78
|
onClick: () => s(l.name),
|
|
79
79
|
style: {
|
|
80
80
|
cursor: "pointer",
|
|
81
|
-
backgroundColor:
|
|
81
|
+
backgroundColor: n === l.name ? "#e6f7ff" : "transparent"
|
|
82
82
|
}
|
|
83
83
|
}),
|
|
84
84
|
columns: [{
|
|
@@ -106,7 +106,7 @@ const v = ({
|
|
|
106
106
|
display: "flex",
|
|
107
107
|
flexDirection: "column"
|
|
108
108
|
},
|
|
109
|
-
children:
|
|
109
|
+
children: n && o ? /* @__PURE__ */ r("div", {
|
|
110
110
|
style: {
|
|
111
111
|
display: "flex",
|
|
112
112
|
flexDirection: "column",
|
|
@@ -119,7 +119,7 @@ const v = ({
|
|
|
119
119
|
fontWeight: "bold",
|
|
120
120
|
flexShrink: 0
|
|
121
121
|
},
|
|
122
|
-
children:
|
|
122
|
+
children: o.name
|
|
123
123
|
}), /* @__PURE__ */ e("div", {
|
|
124
124
|
style: {
|
|
125
125
|
flex: 1,
|
|
@@ -127,8 +127,13 @@ const v = ({
|
|
|
127
127
|
padding: "16px"
|
|
128
128
|
},
|
|
129
129
|
children: /* @__PURE__ */ e(h, {
|
|
130
|
-
url:
|
|
131
|
-
fileName:
|
|
130
|
+
url: o.blobUrl,
|
|
131
|
+
fileName: o.name,
|
|
132
|
+
showToolbar: !1,
|
|
133
|
+
style: {
|
|
134
|
+
height: "100%",
|
|
135
|
+
width: "100%"
|
|
136
|
+
}
|
|
132
137
|
})
|
|
133
138
|
})]
|
|
134
139
|
}) : /* @__PURE__ */ e("div", {
|
|
@@ -1,46 +1,48 @@
|
|
|
1
|
-
var U = (c,
|
|
2
|
-
var
|
|
1
|
+
var U = (c, Z, f) => new Promise((I, u) => {
|
|
2
|
+
var P = (w) => {
|
|
3
3
|
try {
|
|
4
|
-
|
|
5
|
-
} catch (
|
|
6
|
-
u(
|
|
4
|
+
E(f.next(w));
|
|
5
|
+
} catch (t) {
|
|
6
|
+
u(t);
|
|
7
7
|
}
|
|
8
8
|
}, p = (w) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
} catch (
|
|
12
|
-
u(
|
|
10
|
+
E(f.throw(w));
|
|
11
|
+
} catch (t) {
|
|
12
|
+
u(t);
|
|
13
13
|
}
|
|
14
|
-
},
|
|
15
|
-
|
|
14
|
+
}, E = (w) => w.done ? I(w.value) : Promise.resolve(w.value).then(P, p);
|
|
15
|
+
E((f = f.apply(c, Z)).next());
|
|
16
16
|
});
|
|
17
|
-
import { useState as h, useEffect as
|
|
18
|
-
import { configure as
|
|
19
|
-
import { ZIP_CHUNK_SIZE as
|
|
20
|
-
import { checkRangeSupport as j, getFileSize as
|
|
21
|
-
import { getFileExtension as
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
import { useState as h, useEffect as _, useCallback as M } from "react";
|
|
18
|
+
import { configure as A, BlobReader as L, ZipReader as R, HttpRangeReader as k, BlobWriter as H } from "@zip.js/zip.js";
|
|
19
|
+
import { ZIP_CHUNK_SIZE as O, MAX_FALLBACK_SIZE as y, MAX_ZIP_FILES as m, ZIP_ENTRIES_TIMEOUT as B, MAX_ZIP_FILE_SIZE as C, SAFE_FILE_TYPES as D } from "../constants.mjs";
|
|
20
|
+
import { checkRangeSupport as j, getFileSize as v } from "../utils.mjs";
|
|
21
|
+
import { getFileExtension as x, getFileType as W } from "../../../utils/file.mjs";
|
|
22
|
+
const S = {
|
|
23
|
+
filenameEncoding: "utf-8"
|
|
24
|
+
}, Q = (c) => {
|
|
25
|
+
const [Z, f] = h([]), [I, u] = h(!0), [P, p] = h(null), [E, w] = h(null), [t, T] = h(null);
|
|
26
|
+
_(() => {
|
|
25
27
|
if (!c) {
|
|
26
28
|
p("文件URL不能为空"), u(!1);
|
|
27
29
|
return;
|
|
28
30
|
}
|
|
29
|
-
u(!0), p(null), f([]), w(null),
|
|
31
|
+
u(!0), p(null), f([]), w(null), t != null && t.blobUrl && (URL.revokeObjectURL(t.blobUrl), T(null));
|
|
30
32
|
let e = null;
|
|
31
33
|
U(void 0, null, function* () {
|
|
32
34
|
try {
|
|
33
|
-
|
|
34
|
-
chunkSize:
|
|
35
|
+
A({
|
|
36
|
+
chunkSize: O,
|
|
35
37
|
useWebWorkers: !1
|
|
36
38
|
});
|
|
37
39
|
const {
|
|
38
40
|
supportsRange: n,
|
|
39
|
-
fileSize:
|
|
41
|
+
fileSize: r
|
|
40
42
|
} = yield j(c);
|
|
41
43
|
if (n) {
|
|
42
44
|
const o = new k(c);
|
|
43
|
-
e = new
|
|
45
|
+
e = new R(o, S);
|
|
44
46
|
const b = (yield Promise.race([e.getEntries(), new Promise((i, a) => setTimeout(() => a(new Error("读取 ZIP 目录结构超时")), B))])).filter((i) => !i.directory).map((i) => ({
|
|
45
47
|
name: i.filename,
|
|
46
48
|
size: i.uncompressedSize || 0,
|
|
@@ -48,13 +50,13 @@ const J = (c) => {
|
|
|
48
50
|
}));
|
|
49
51
|
b.sort((i, a) => i.name.localeCompare(a.name)), b.length > m ? (p(`ZIP 文件包含 ${b.length} 个文件,仅显示前 ${m} 个`), f(b.slice(0, m))) : f(b);
|
|
50
52
|
} else {
|
|
51
|
-
if (
|
|
52
|
-
throw new Error(`服务器不支持 HTTP Range 请求,且文件过大(${Math.round(
|
|
53
|
+
if (r > y)
|
|
54
|
+
throw new Error(`服务器不支持 HTTP Range 请求,且文件过大(${Math.round(r / 1024 / 1024)}MB),无法预览。请下载后查看。`);
|
|
53
55
|
const o = yield fetch(c);
|
|
54
56
|
if (!o.ok)
|
|
55
57
|
throw new Error(`HTTP error! status: ${o.status}`);
|
|
56
|
-
const g = yield o.blob(), b = new
|
|
57
|
-
e = new
|
|
58
|
+
const g = yield o.blob(), b = new L(g);
|
|
59
|
+
e = new R(b, S);
|
|
58
60
|
const a = (yield e.getEntries()).filter((s) => !s.directory).map((s) => ({
|
|
59
61
|
name: s.filename,
|
|
60
62
|
size: s.uncompressedSize || 0,
|
|
@@ -69,83 +71,83 @@ const J = (c) => {
|
|
|
69
71
|
yield e.close();
|
|
70
72
|
} catch (o) {
|
|
71
73
|
}
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
+
const r = n.message || n.toString() || "加载 ZIP 文件失败";
|
|
75
|
+
if (r.includes("Range") || r.includes("range") || r.includes("HTTP Range not supported") || r.includes("超时"))
|
|
74
76
|
try {
|
|
75
|
-
const o = yield
|
|
77
|
+
const o = yield v(c);
|
|
76
78
|
if (o > y)
|
|
77
79
|
throw new Error(`文件过大(${Math.round(o / 1024 / 1024)}MB),无法通过 Range 请求加载,且文件过大无法下载整个文件预览。请下载后查看。`);
|
|
78
80
|
const g = yield fetch(c);
|
|
79
81
|
if (!g.ok)
|
|
80
82
|
throw new Error(`HTTP error! status: ${g.status}`);
|
|
81
|
-
const b = yield g.blob(), i = new
|
|
82
|
-
e = new
|
|
83
|
+
const b = yield g.blob(), i = new L(b);
|
|
84
|
+
e = new R(i, S);
|
|
83
85
|
const s = (yield e.getEntries()).filter((l) => !l.directory).map((l) => ({
|
|
84
86
|
name: l.filename,
|
|
85
87
|
size: l.uncompressedSize || 0,
|
|
86
88
|
isDirectory: !1
|
|
87
89
|
}));
|
|
88
|
-
s.sort((l,
|
|
90
|
+
s.sort((l, d) => l.name.localeCompare(d.name)), s.length > m ? (p(`ZIP 文件包含 ${s.length} 个文件,仅显示前 ${m} 个`), f(s.slice(0, m))) : f(s), e && (yield e.close()), u(!1);
|
|
89
91
|
return;
|
|
90
92
|
} catch (o) {
|
|
91
93
|
const g = o.message || o.toString();
|
|
92
|
-
p(`ZIP 文件加载失败: ${
|
|
94
|
+
p(`ZIP 文件加载失败: ${r}。Fallback 方案也失败: ${g}`);
|
|
93
95
|
}
|
|
94
96
|
else
|
|
95
|
-
p(
|
|
97
|
+
p(r);
|
|
96
98
|
u(!1);
|
|
97
99
|
}
|
|
98
100
|
});
|
|
99
101
|
}, [c]);
|
|
100
|
-
const z =
|
|
101
|
-
if (
|
|
102
|
-
w(null),
|
|
102
|
+
const z = M((e) => U(void 0, null, function* () {
|
|
103
|
+
if (E === e && t) {
|
|
104
|
+
w(null), t.blobUrl && URL.revokeObjectURL(t.blobUrl), T(null);
|
|
103
105
|
return;
|
|
104
106
|
}
|
|
105
107
|
w(e);
|
|
106
108
|
try {
|
|
107
|
-
let n = null,
|
|
109
|
+
let n = null, r;
|
|
108
110
|
try {
|
|
109
111
|
const s = new k(c);
|
|
110
|
-
n = new
|
|
112
|
+
n = new R(s, S), r = (yield n.getEntries()).find((d) => d.filename === e);
|
|
111
113
|
} catch (s) {
|
|
112
114
|
const l = yield fetch(c);
|
|
113
115
|
if (!l.ok)
|
|
114
116
|
throw new Error(`HTTP error! status: ${l.status}`);
|
|
115
|
-
const
|
|
116
|
-
n = new S
|
|
117
|
+
const d = yield l.blob(), $ = new L(d);
|
|
118
|
+
n = new R($, S), r = (yield n.getEntries()).find((F) => F.filename === e);
|
|
117
119
|
}
|
|
118
|
-
if (!
|
|
120
|
+
if (!r)
|
|
119
121
|
throw new Error("文件不存在");
|
|
120
|
-
if (
|
|
122
|
+
if (r.directory)
|
|
121
123
|
throw new Error("无法预览目录");
|
|
122
|
-
if ((
|
|
124
|
+
if ((r.uncompressedSize || 0) > C)
|
|
123
125
|
throw new Error("文件过大(超过 100MB),无法预览");
|
|
124
|
-
const g = yield
|
|
125
|
-
if (!
|
|
126
|
+
const g = yield r.getData(new H()), b = URL.createObjectURL(g), i = x(e), a = W(i);
|
|
127
|
+
if (!D.includes(a))
|
|
126
128
|
throw new Error(`不支持预览 ${i || "未知"} 格式的文件`);
|
|
127
|
-
|
|
129
|
+
T({
|
|
128
130
|
name: e,
|
|
129
131
|
blobUrl: b,
|
|
130
132
|
type: a
|
|
131
133
|
}), n && (yield n.close());
|
|
132
134
|
} catch (n) {
|
|
133
|
-
const
|
|
134
|
-
p(
|
|
135
|
+
const r = n.message || n.toString() || "预览文件失败";
|
|
136
|
+
p(r);
|
|
135
137
|
}
|
|
136
|
-
}), [c,
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
}, [
|
|
140
|
-
zipFiles:
|
|
141
|
-
zipLoading:
|
|
142
|
-
zipError:
|
|
143
|
-
selectedZipFile:
|
|
144
|
-
zipFileContent:
|
|
138
|
+
}), [c, E, t]);
|
|
139
|
+
return _(() => () => {
|
|
140
|
+
t != null && t.blobUrl && URL.revokeObjectURL(t.blobUrl);
|
|
141
|
+
}, [t]), {
|
|
142
|
+
zipFiles: Z,
|
|
143
|
+
zipLoading: I,
|
|
144
|
+
zipError: P,
|
|
145
|
+
selectedZipFile: E,
|
|
146
|
+
zipFileContent: t,
|
|
145
147
|
handleFileClick: z,
|
|
146
148
|
setSelectedZipFile: w
|
|
147
149
|
};
|
|
148
150
|
};
|
|
149
151
|
export {
|
|
150
|
-
|
|
152
|
+
Q as useZipViewer
|
|
151
153
|
};
|