@glodon-aiot/react-components 3.9.0-beta.9 → 3.11.0-snapshot.1765331440
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/aiot-react-components.js +20191 -0
- package/dist/aiot-react-components.umd.cjs +183 -0
- package/dist/es/components/DocumentViewer/components/DownloadButton.mjs +18 -0
- package/dist/es/components/DocumentViewer/components/ErrorAlert.mjs +27 -0
- package/dist/es/components/DocumentViewer/components/FileRenderers.mjs +476 -0
- package/dist/es/components/DocumentViewer/components/MediaRenderers.mjs +41 -0
- package/dist/es/components/DocumentViewer/components/PdfRenderer.mjs +44 -0
- package/dist/es/components/DocumentViewer/components/ZipRenderer.mjs +147 -0
- package/dist/es/components/DocumentViewer/constants.mjs +21 -0
- package/dist/es/components/DocumentViewer/hooks/usePdfViewer.mjs +31 -0
- package/dist/es/components/DocumentViewer/hooks/useZipViewer.mjs +151 -0
- package/dist/es/components/DocumentViewer/index.mjs +255 -0
- package/dist/es/components/DocumentViewer/style.less.mjs +4 -0
- package/dist/es/components/DocumentViewer/utils.mjs +60 -0
- package/dist/es/index.mjs +36 -34
- package/dist/es/utils/file.mjs +17 -0
- package/dist/lib/index.js +10 -2
- package/dist/src/components/DocumentViewer/components/DownloadButton.d.ts +7 -0
- package/dist/src/components/DocumentViewer/components/ErrorAlert.d.ts +10 -0
- package/dist/src/components/DocumentViewer/components/FileRenderers.d.ts +23 -0
- package/dist/src/components/DocumentViewer/components/MediaRenderers.d.ts +9 -0
- package/dist/src/components/DocumentViewer/components/PdfRenderer.d.ts +10 -0
- package/dist/src/components/DocumentViewer/components/ZipRenderer.d.ts +22 -0
- package/dist/src/components/DocumentViewer/components/index.d.ts +9 -0
- package/dist/src/components/DocumentViewer/constants.d.ts +21 -0
- package/dist/src/components/DocumentViewer/hooks/index.d.ts +5 -0
- package/dist/src/components/DocumentViewer/hooks/usePdfViewer.d.ts +7 -0
- package/dist/src/components/DocumentViewer/hooks/useZipViewer.d.ts +21 -0
- package/dist/src/components/DocumentViewer/index.d.ts +9 -0
- package/dist/src/components/DocumentViewer/utils.d.ts +18 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/utils/file.d.ts +16 -0
- package/dist/style.css +1 -0
- package/package.json +15 -11
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { jsx as e, jsxs as i } from "react/jsx-runtime";
|
|
2
|
+
import { Spin as f, Alert as d, Table as m } from "antd";
|
|
3
|
+
import h from "../index.mjs";
|
|
4
|
+
import { formatFileSize as p } from "../utils.mjs";
|
|
5
|
+
const v = ({
|
|
6
|
+
zipFiles: r,
|
|
7
|
+
zipLoading: a,
|
|
8
|
+
zipError: t,
|
|
9
|
+
selectedZipFile: o,
|
|
10
|
+
zipFileContent: n,
|
|
11
|
+
onFileClick: s,
|
|
12
|
+
url: c
|
|
13
|
+
}) => a ? /* @__PURE__ */ e("div", {
|
|
14
|
+
className: "document-viewer-loading",
|
|
15
|
+
children: /* @__PURE__ */ e(f, {
|
|
16
|
+
size: "large",
|
|
17
|
+
tip: "加载 ZIP 文件..."
|
|
18
|
+
})
|
|
19
|
+
}) : t && r.length === 0 ? /* @__PURE__ */ e(d, {
|
|
20
|
+
message: "ZIP 加载失败",
|
|
21
|
+
description: t,
|
|
22
|
+
type: "error",
|
|
23
|
+
showIcon: !0,
|
|
24
|
+
action: /* @__PURE__ */ e("a", {
|
|
25
|
+
href: c,
|
|
26
|
+
target: "_blank",
|
|
27
|
+
rel: "noopener noreferrer",
|
|
28
|
+
children: "下载文件"
|
|
29
|
+
})
|
|
30
|
+
}) : /* @__PURE__ */ i("div", {
|
|
31
|
+
className: "document-viewer-zip",
|
|
32
|
+
children: [t && r.length > 0 && /* @__PURE__ */ e(d, {
|
|
33
|
+
message: "提示",
|
|
34
|
+
description: t,
|
|
35
|
+
type: "warning",
|
|
36
|
+
showIcon: !0,
|
|
37
|
+
style: {
|
|
38
|
+
marginBottom: 16
|
|
39
|
+
}
|
|
40
|
+
}), /* @__PURE__ */ i("div", {
|
|
41
|
+
style: {
|
|
42
|
+
display: "flex",
|
|
43
|
+
height: "100%",
|
|
44
|
+
gap: "16px"
|
|
45
|
+
},
|
|
46
|
+
children: [/* @__PURE__ */ i("div", {
|
|
47
|
+
style: {
|
|
48
|
+
width: "300px",
|
|
49
|
+
borderRight: "1px solid #e8e8e8",
|
|
50
|
+
overflow: "auto",
|
|
51
|
+
display: "flex",
|
|
52
|
+
flexDirection: "column"
|
|
53
|
+
},
|
|
54
|
+
children: [/* @__PURE__ */ i("div", {
|
|
55
|
+
style: {
|
|
56
|
+
padding: "12px",
|
|
57
|
+
fontWeight: "bold",
|
|
58
|
+
borderBottom: "1px solid #e8e8e8",
|
|
59
|
+
flexShrink: 0
|
|
60
|
+
},
|
|
61
|
+
children: ["文件列表 (", r.length, ")"]
|
|
62
|
+
}), /* @__PURE__ */ e("div", {
|
|
63
|
+
style: {
|
|
64
|
+
flex: 1,
|
|
65
|
+
overflow: "auto",
|
|
66
|
+
minHeight: 0
|
|
67
|
+
},
|
|
68
|
+
children: /* @__PURE__ */ e(m, {
|
|
69
|
+
dataSource: r,
|
|
70
|
+
size: "small",
|
|
71
|
+
pagination: !1,
|
|
72
|
+
scroll: {
|
|
73
|
+
y: "100%"
|
|
74
|
+
},
|
|
75
|
+
onRow: (l) => ({
|
|
76
|
+
onClick: () => s(l.name),
|
|
77
|
+
style: {
|
|
78
|
+
cursor: "pointer",
|
|
79
|
+
backgroundColor: o === l.name ? "#e6f7ff" : "transparent"
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
columns: [{
|
|
83
|
+
title: "文件名",
|
|
84
|
+
dataIndex: "name",
|
|
85
|
+
key: "name",
|
|
86
|
+
ellipsis: !0,
|
|
87
|
+
render: (l) => /* @__PURE__ */ e("span", {
|
|
88
|
+
title: l,
|
|
89
|
+
children: l.split("/").pop()
|
|
90
|
+
})
|
|
91
|
+
}, {
|
|
92
|
+
title: "大小",
|
|
93
|
+
dataIndex: "size",
|
|
94
|
+
key: "size",
|
|
95
|
+
width: 80,
|
|
96
|
+
render: (l) => p(l)
|
|
97
|
+
}]
|
|
98
|
+
})
|
|
99
|
+
})]
|
|
100
|
+
}), /* @__PURE__ */ e("div", {
|
|
101
|
+
style: {
|
|
102
|
+
flex: 1,
|
|
103
|
+
overflow: "auto",
|
|
104
|
+
display: "flex",
|
|
105
|
+
flexDirection: "column"
|
|
106
|
+
},
|
|
107
|
+
children: o && n ? /* @__PURE__ */ i("div", {
|
|
108
|
+
style: {
|
|
109
|
+
display: "flex",
|
|
110
|
+
flexDirection: "column",
|
|
111
|
+
height: "100%"
|
|
112
|
+
},
|
|
113
|
+
children: [/* @__PURE__ */ e("div", {
|
|
114
|
+
style: {
|
|
115
|
+
padding: "12px",
|
|
116
|
+
borderBottom: "1px solid #e8e8e8",
|
|
117
|
+
fontWeight: "bold",
|
|
118
|
+
flexShrink: 0
|
|
119
|
+
},
|
|
120
|
+
children: n.name
|
|
121
|
+
}), /* @__PURE__ */ e("div", {
|
|
122
|
+
style: {
|
|
123
|
+
flex: 1,
|
|
124
|
+
overflow: "auto",
|
|
125
|
+
padding: "16px"
|
|
126
|
+
},
|
|
127
|
+
children: /* @__PURE__ */ e(h, {
|
|
128
|
+
url: n.blobUrl,
|
|
129
|
+
fileName: n.name
|
|
130
|
+
})
|
|
131
|
+
})]
|
|
132
|
+
}) : /* @__PURE__ */ e("div", {
|
|
133
|
+
style: {
|
|
134
|
+
display: "flex",
|
|
135
|
+
alignItems: "center",
|
|
136
|
+
justifyContent: "center",
|
|
137
|
+
height: "100%",
|
|
138
|
+
color: "#999"
|
|
139
|
+
},
|
|
140
|
+
children: "请从左侧列表中选择文件进行预览"
|
|
141
|
+
})
|
|
142
|
+
})]
|
|
143
|
+
})]
|
|
144
|
+
});
|
|
145
|
+
export {
|
|
146
|
+
v as ZipRenderer
|
|
147
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const _ = 5242880, I = 2097152, S = 2097152, o = 5242880, t = 5242880, E = 2097152, s = 2097152, n = 2097152, A = 2097152, c = 104857600, M = 104857600, X = 1e4, Z = 1e4, L = 5e3, e = 1e3, N = 5242880, P = 3e4, F = ["text", "json", "csv", "tsv", "markdown", "html", "xml", "jsonl", "image", "pdf", "code"];
|
|
2
|
+
export {
|
|
3
|
+
Z as MAX_CSV_ROWS,
|
|
4
|
+
o as MAX_CSV_SIZE,
|
|
5
|
+
X as MAX_DISPLAY_LINES,
|
|
6
|
+
I as MAX_DISPLAY_SIZE,
|
|
7
|
+
c as MAX_FALLBACK_SIZE,
|
|
8
|
+
_ as MAX_FILE_SIZE,
|
|
9
|
+
A as MAX_HIGHLIGHT_SIZE,
|
|
10
|
+
L as MAX_JSONL_LINES,
|
|
11
|
+
E as MAX_JSONL_SIZE,
|
|
12
|
+
S as MAX_JSON_SIZE,
|
|
13
|
+
s as MAX_MARKDOWN_SIZE,
|
|
14
|
+
t as MAX_TSV_SIZE,
|
|
15
|
+
n as MAX_XML_SIZE,
|
|
16
|
+
e as MAX_ZIP_FILES,
|
|
17
|
+
M as MAX_ZIP_FILE_SIZE,
|
|
18
|
+
F as SAFE_FILE_TYPES,
|
|
19
|
+
N as ZIP_CHUNK_SIZE,
|
|
20
|
+
P as ZIP_ENTRIES_TIMEOUT
|
|
21
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState as f, useRef as d, useEffect as i } from "react";
|
|
2
|
+
const L = (t) => {
|
|
3
|
+
const [l, u] = f(null), [s, n] = f(!0), [a, o] = f(null), r = d(null);
|
|
4
|
+
return i(() => {
|
|
5
|
+
if (!t) {
|
|
6
|
+
o("文件URL不能为空"), n(!1);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return r.current && (URL.revokeObjectURL(r.current), r.current = null, u(null)), n(!0), o(null), fetch(t).then((e) => {
|
|
10
|
+
if (!e.ok)
|
|
11
|
+
throw new Error(`HTTP error! status: ${e.status}`);
|
|
12
|
+
return e.blob();
|
|
13
|
+
}).then((e) => {
|
|
14
|
+
if (e.type && e.type !== "application/pdf" && !t.toLowerCase().endsWith(".pdf"))
|
|
15
|
+
throw new Error("文件不是有效的 PDF 格式");
|
|
16
|
+
const c = URL.createObjectURL(e);
|
|
17
|
+
r.current = c, u(c), n(!1);
|
|
18
|
+
}).catch((e) => {
|
|
19
|
+
o(e.message || "加载 PDF 失败"), n(!1);
|
|
20
|
+
}), () => {
|
|
21
|
+
r.current && (URL.revokeObjectURL(r.current), r.current = null);
|
|
22
|
+
};
|
|
23
|
+
}, [t]), {
|
|
24
|
+
pdfBlobUrl: l,
|
|
25
|
+
pdfLoading: s,
|
|
26
|
+
pdfError: a
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
L as usePdfViewer
|
|
31
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var U = (c, R, f) => new Promise((Z, u) => {
|
|
2
|
+
var I = (w) => {
|
|
3
|
+
try {
|
|
4
|
+
d(f.next(w));
|
|
5
|
+
} catch (r) {
|
|
6
|
+
u(r);
|
|
7
|
+
}
|
|
8
|
+
}, p = (w) => {
|
|
9
|
+
try {
|
|
10
|
+
d(f.throw(w));
|
|
11
|
+
} catch (r) {
|
|
12
|
+
u(r);
|
|
13
|
+
}
|
|
14
|
+
}, d = (w) => w.done ? Z(w.value) : Promise.resolve(w.value).then(I, p);
|
|
15
|
+
d((f = f.apply(c, R)).next());
|
|
16
|
+
});
|
|
17
|
+
import { useState as h, useEffect as L, useCallback as F } from "react";
|
|
18
|
+
import { configure as M, BlobReader as T, ZipReader as S, HttpRangeReader as k, BlobWriter as H } from "@zip.js/zip.js";
|
|
19
|
+
import { ZIP_CHUNK_SIZE as A, 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 O } from "../constants.mjs";
|
|
20
|
+
import { checkRangeSupport as j, getFileSize as D } from "../utils.mjs";
|
|
21
|
+
import { getFileExtension as v, getFileType as x } from "../../../utils/file.mjs";
|
|
22
|
+
const J = (c) => {
|
|
23
|
+
const [R, f] = h([]), [Z, u] = h(!0), [I, p] = h(null), [d, w] = h(null), [r, P] = h(null);
|
|
24
|
+
L(() => {
|
|
25
|
+
if (!c) {
|
|
26
|
+
p("文件URL不能为空"), u(!1);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
u(!0), p(null), f([]), w(null), r != null && r.blobUrl && (URL.revokeObjectURL(r.blobUrl), P(null));
|
|
30
|
+
let e = null;
|
|
31
|
+
U(void 0, null, function* () {
|
|
32
|
+
try {
|
|
33
|
+
M({
|
|
34
|
+
chunkSize: A,
|
|
35
|
+
useWebWorkers: !1
|
|
36
|
+
});
|
|
37
|
+
const {
|
|
38
|
+
supportsRange: n,
|
|
39
|
+
fileSize: t
|
|
40
|
+
} = yield j(c);
|
|
41
|
+
if (n) {
|
|
42
|
+
const o = new k(c);
|
|
43
|
+
e = new S(o);
|
|
44
|
+
const b = (yield Promise.race([e.getEntries(), new Promise((i, a) => setTimeout(() => a(new Error("读取 ZIP 目录结构超时")), B))])).filter((i) => !i.directory).map((i) => ({
|
|
45
|
+
name: i.filename,
|
|
46
|
+
size: i.uncompressedSize || 0,
|
|
47
|
+
isDirectory: !1
|
|
48
|
+
}));
|
|
49
|
+
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
|
+
} else {
|
|
51
|
+
if (t > y)
|
|
52
|
+
throw new Error(`服务器不支持 HTTP Range 请求,且文件过大(${Math.round(t / 1024 / 1024)}MB),无法预览。请下载后查看。`);
|
|
53
|
+
const o = yield fetch(c);
|
|
54
|
+
if (!o.ok)
|
|
55
|
+
throw new Error(`HTTP error! status: ${o.status}`);
|
|
56
|
+
const g = yield o.blob(), b = new T(g);
|
|
57
|
+
e = new S(b);
|
|
58
|
+
const a = (yield e.getEntries()).filter((s) => !s.directory).map((s) => ({
|
|
59
|
+
name: s.filename,
|
|
60
|
+
size: s.uncompressedSize || 0,
|
|
61
|
+
isDirectory: !1
|
|
62
|
+
}));
|
|
63
|
+
a.sort((s, l) => s.name.localeCompare(l.name)), a.length > m ? (p(`ZIP 文件包含 ${a.length} 个文件,仅显示前 ${m} 个`), f(a.slice(0, m))) : f(a);
|
|
64
|
+
}
|
|
65
|
+
e && (yield e.close()), u(!1);
|
|
66
|
+
} catch (n) {
|
|
67
|
+
if (e)
|
|
68
|
+
try {
|
|
69
|
+
yield e.close();
|
|
70
|
+
} catch (o) {
|
|
71
|
+
}
|
|
72
|
+
const t = n.message || n.toString() || "加载 ZIP 文件失败";
|
|
73
|
+
if (t.includes("Range") || t.includes("range") || t.includes("HTTP Range not supported") || t.includes("超时"))
|
|
74
|
+
try {
|
|
75
|
+
const o = yield D(c);
|
|
76
|
+
if (o > y)
|
|
77
|
+
throw new Error(`文件过大(${Math.round(o / 1024 / 1024)}MB),无法通过 Range 请求加载,且文件过大无法下载整个文件预览。请下载后查看。`);
|
|
78
|
+
const g = yield fetch(c);
|
|
79
|
+
if (!g.ok)
|
|
80
|
+
throw new Error(`HTTP error! status: ${g.status}`);
|
|
81
|
+
const b = yield g.blob(), i = new T(b);
|
|
82
|
+
e = new S(i);
|
|
83
|
+
const s = (yield e.getEntries()).filter((l) => !l.directory).map((l) => ({
|
|
84
|
+
name: l.filename,
|
|
85
|
+
size: l.uncompressedSize || 0,
|
|
86
|
+
isDirectory: !1
|
|
87
|
+
}));
|
|
88
|
+
s.sort((l, E) => l.name.localeCompare(E.name)), s.length > m ? (p(`ZIP 文件包含 ${s.length} 个文件,仅显示前 ${m} 个`), f(s.slice(0, m))) : f(s), e && (yield e.close()), u(!1);
|
|
89
|
+
return;
|
|
90
|
+
} catch (o) {
|
|
91
|
+
const g = o.message || o.toString();
|
|
92
|
+
p(`ZIP 文件加载失败: ${t}。Fallback 方案也失败: ${g}`);
|
|
93
|
+
}
|
|
94
|
+
else
|
|
95
|
+
p(t);
|
|
96
|
+
u(!1);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}, [c]);
|
|
100
|
+
const z = F((e) => U(void 0, null, function* () {
|
|
101
|
+
if (d === e && r) {
|
|
102
|
+
w(null), r.blobUrl && URL.revokeObjectURL(r.blobUrl), P(null);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
w(e);
|
|
106
|
+
try {
|
|
107
|
+
let n = null, t;
|
|
108
|
+
try {
|
|
109
|
+
const s = new k(c);
|
|
110
|
+
n = new S(s), t = (yield n.getEntries()).find((E) => E.filename === e);
|
|
111
|
+
} catch (s) {
|
|
112
|
+
const l = yield fetch(c);
|
|
113
|
+
if (!l.ok)
|
|
114
|
+
throw new Error(`HTTP error! status: ${l.status}`);
|
|
115
|
+
const E = yield l.blob(), _ = new T(E);
|
|
116
|
+
n = new S(_), t = (yield n.getEntries()).find(($) => $.filename === e);
|
|
117
|
+
}
|
|
118
|
+
if (!t)
|
|
119
|
+
throw new Error("文件不存在");
|
|
120
|
+
if (t.directory)
|
|
121
|
+
throw new Error("无法预览目录");
|
|
122
|
+
if ((t.uncompressedSize || 0) > C)
|
|
123
|
+
throw new Error("文件过大(超过 100MB),无法预览");
|
|
124
|
+
const g = yield t.getData(new H()), b = URL.createObjectURL(g), i = v(e), a = x(i);
|
|
125
|
+
if (!O.includes(a))
|
|
126
|
+
throw new Error(`不支持预览 ${i || "未知"} 格式的文件`);
|
|
127
|
+
P({
|
|
128
|
+
name: e,
|
|
129
|
+
blobUrl: b,
|
|
130
|
+
type: a
|
|
131
|
+
}), n && (yield n.close());
|
|
132
|
+
} catch (n) {
|
|
133
|
+
const t = n.message || n.toString() || "预览文件失败";
|
|
134
|
+
p(t);
|
|
135
|
+
}
|
|
136
|
+
}), [c, d, r]);
|
|
137
|
+
return L(() => () => {
|
|
138
|
+
r != null && r.blobUrl && URL.revokeObjectURL(r.blobUrl);
|
|
139
|
+
}, [r]), {
|
|
140
|
+
zipFiles: R,
|
|
141
|
+
zipLoading: Z,
|
|
142
|
+
zipError: I,
|
|
143
|
+
selectedZipFile: d,
|
|
144
|
+
zipFileContent: r,
|
|
145
|
+
handleFileClick: z,
|
|
146
|
+
setSelectedZipFile: w
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
export {
|
|
150
|
+
J as useZipViewer
|
|
151
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
var x = (a, e, t) => new Promise((w, m) => {
|
|
2
|
+
var n = (o) => {
|
|
3
|
+
try {
|
|
4
|
+
d(t.next(o));
|
|
5
|
+
} catch (l) {
|
|
6
|
+
m(l);
|
|
7
|
+
}
|
|
8
|
+
}, h = (o) => {
|
|
9
|
+
try {
|
|
10
|
+
d(t.throw(o));
|
|
11
|
+
} catch (l) {
|
|
12
|
+
m(l);
|
|
13
|
+
}
|
|
14
|
+
}, d = (o) => o.done ? w(o.value) : Promise.resolve(o.value).then(n, h);
|
|
15
|
+
d((t = t.apply(a, e)).next());
|
|
16
|
+
});
|
|
17
|
+
import { jsx as r, jsxs as b } from "react/jsx-runtime";
|
|
18
|
+
import { useMemo as A, useState as p, useEffect as P } from "react";
|
|
19
|
+
import { Spin as U, Alert as j } from "antd";
|
|
20
|
+
import { getFileExtension as F, getFileType as B } from "../../utils/file.mjs";
|
|
21
|
+
import { MAX_FILE_SIZE as L } from "./constants.mjs";
|
|
22
|
+
import { usePdfViewer as D } from "./hooks/usePdfViewer.mjs";
|
|
23
|
+
import { useZipViewer as Z } from "./hooks/useZipViewer.mjs";
|
|
24
|
+
import { CodeRenderer as H, XmlRenderer as _, HtmlRenderer as J, MarkdownRenderer as O, JsonlRenderer as X, TsvRenderer as q, CsvRenderer as G, JsonRenderer as K, TextRenderer as Q } from "./components/FileRenderers.mjs";
|
|
25
|
+
import { AudioRenderer as W, VideoRenderer as Y, ImageRenderer as ee } from "./components/MediaRenderers.mjs";
|
|
26
|
+
import { PdfRenderer as re } from "./components/PdfRenderer.mjs";
|
|
27
|
+
import { ZipRenderer as te } from "./components/ZipRenderer.mjs";
|
|
28
|
+
import { ErrorAlert as ne } from "./components/ErrorAlert.mjs";
|
|
29
|
+
import "./style.less.mjs";
|
|
30
|
+
const oe = (a) => {
|
|
31
|
+
const {
|
|
32
|
+
url: e,
|
|
33
|
+
fileName: t,
|
|
34
|
+
className: w,
|
|
35
|
+
style: m
|
|
36
|
+
} = a, n = A(() => {
|
|
37
|
+
const u = t ? F(t) : F(e);
|
|
38
|
+
return B(u);
|
|
39
|
+
}, [e, t]), {
|
|
40
|
+
pdfBlobUrl: h,
|
|
41
|
+
pdfLoading: d,
|
|
42
|
+
pdfError: o
|
|
43
|
+
} = D(n === "pdf" ? e : ""), {
|
|
44
|
+
zipFiles: l,
|
|
45
|
+
zipLoading: C,
|
|
46
|
+
zipError: S,
|
|
47
|
+
selectedZipFile: N,
|
|
48
|
+
zipFileContent: M,
|
|
49
|
+
handleFileClick: y
|
|
50
|
+
} = Z(n === "zip" ? e : ""), [I, c] = p(!0), [R, f] = p(null), [i, T] = p(null), [s, V] = p(0);
|
|
51
|
+
P(() => {
|
|
52
|
+
if (n === "pdf" || n === "zip") {
|
|
53
|
+
c(!1);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!e) {
|
|
57
|
+
f("文件URL不能为空"), c(!1);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (["image", "video", "audio", "office", "unknown"].includes(n)) {
|
|
61
|
+
c(!1);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
c(!0), f(null), x(void 0, null, function* () {
|
|
65
|
+
try {
|
|
66
|
+
const z = (yield fetch(e, {
|
|
67
|
+
method: "HEAD"
|
|
68
|
+
})).headers.get("Content-Length"), g = z ? parseInt(z, 10) : 0;
|
|
69
|
+
if (V(g), g > L) {
|
|
70
|
+
f(`文件过大(${Math.round(g / 1024 / 1024)}MB),无法预览。请下载后查看。`), c(!1);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const v = yield fetch(e);
|
|
74
|
+
if (!v.ok)
|
|
75
|
+
throw new Error(`HTTP error! status: ${v.status}`);
|
|
76
|
+
const E = yield v.text(), k = new Blob([E]).size;
|
|
77
|
+
if (k > L) {
|
|
78
|
+
f(`文件过大(${Math.round(k / 1024 / 1024)}MB),无法预览。请下载后查看。`), c(!1);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
T({
|
|
82
|
+
content: E
|
|
83
|
+
}), c(!1);
|
|
84
|
+
} catch (u) {
|
|
85
|
+
f(u.message || "加载文件失败"), c(!1);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}, [e, n]);
|
|
89
|
+
const $ = () => {
|
|
90
|
+
if (I)
|
|
91
|
+
return /* @__PURE__ */ r("div", {
|
|
92
|
+
className: "document-viewer-loading",
|
|
93
|
+
children: /* @__PURE__ */ r(U, {
|
|
94
|
+
size: "large",
|
|
95
|
+
tip: "加载中..."
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
if (R)
|
|
99
|
+
return /* @__PURE__ */ r(ne, {
|
|
100
|
+
message: "加载失败",
|
|
101
|
+
description: R,
|
|
102
|
+
url: e,
|
|
103
|
+
fileName: t
|
|
104
|
+
});
|
|
105
|
+
switch (n) {
|
|
106
|
+
case "text":
|
|
107
|
+
return /* @__PURE__ */ r(Q, {
|
|
108
|
+
fileContent: i,
|
|
109
|
+
fileSize: s,
|
|
110
|
+
url: e,
|
|
111
|
+
fileName: t
|
|
112
|
+
});
|
|
113
|
+
case "json":
|
|
114
|
+
return /* @__PURE__ */ r(K, {
|
|
115
|
+
fileContent: i,
|
|
116
|
+
fileSize: s,
|
|
117
|
+
url: e,
|
|
118
|
+
fileName: t
|
|
119
|
+
});
|
|
120
|
+
case "csv":
|
|
121
|
+
return /* @__PURE__ */ r(G, {
|
|
122
|
+
fileContent: i,
|
|
123
|
+
fileSize: s,
|
|
124
|
+
url: e,
|
|
125
|
+
fileName: t
|
|
126
|
+
});
|
|
127
|
+
case "tsv":
|
|
128
|
+
return /* @__PURE__ */ r(q, {
|
|
129
|
+
fileContent: i,
|
|
130
|
+
fileSize: s,
|
|
131
|
+
url: e,
|
|
132
|
+
fileName: t
|
|
133
|
+
});
|
|
134
|
+
case "jsonl":
|
|
135
|
+
return /* @__PURE__ */ r(X, {
|
|
136
|
+
fileContent: i,
|
|
137
|
+
fileSize: s,
|
|
138
|
+
url: e,
|
|
139
|
+
fileName: t
|
|
140
|
+
});
|
|
141
|
+
case "markdown":
|
|
142
|
+
return /* @__PURE__ */ r(O, {
|
|
143
|
+
fileContent: i,
|
|
144
|
+
fileSize: s,
|
|
145
|
+
url: e,
|
|
146
|
+
fileName: t
|
|
147
|
+
});
|
|
148
|
+
case "html":
|
|
149
|
+
return /* @__PURE__ */ r(J, {
|
|
150
|
+
fileContent: i,
|
|
151
|
+
fileSize: s,
|
|
152
|
+
url: e,
|
|
153
|
+
fileName: t
|
|
154
|
+
});
|
|
155
|
+
case "xml":
|
|
156
|
+
return /* @__PURE__ */ r(_, {
|
|
157
|
+
fileContent: i,
|
|
158
|
+
fileSize: s,
|
|
159
|
+
url: e,
|
|
160
|
+
fileName: t
|
|
161
|
+
});
|
|
162
|
+
case "code":
|
|
163
|
+
return /* @__PURE__ */ r(H, {
|
|
164
|
+
fileContent: i,
|
|
165
|
+
fileSize: s,
|
|
166
|
+
url: e,
|
|
167
|
+
fileName: t
|
|
168
|
+
});
|
|
169
|
+
case "image":
|
|
170
|
+
return /* @__PURE__ */ r(ee, {
|
|
171
|
+
url: e,
|
|
172
|
+
fileName: t
|
|
173
|
+
});
|
|
174
|
+
case "video":
|
|
175
|
+
return /* @__PURE__ */ r(Y, {
|
|
176
|
+
url: e,
|
|
177
|
+
fileName: t
|
|
178
|
+
});
|
|
179
|
+
case "audio":
|
|
180
|
+
return /* @__PURE__ */ r(W, {
|
|
181
|
+
url: e,
|
|
182
|
+
fileName: t
|
|
183
|
+
});
|
|
184
|
+
case "pdf":
|
|
185
|
+
return /* @__PURE__ */ r(re, {
|
|
186
|
+
pdfBlobUrl: h,
|
|
187
|
+
pdfLoading: d,
|
|
188
|
+
pdfError: o,
|
|
189
|
+
url: e,
|
|
190
|
+
fileName: t
|
|
191
|
+
});
|
|
192
|
+
case "office":
|
|
193
|
+
return /* @__PURE__ */ r(ie, {
|
|
194
|
+
url: e
|
|
195
|
+
});
|
|
196
|
+
case "zip":
|
|
197
|
+
return /* @__PURE__ */ r(te, {
|
|
198
|
+
zipFiles: l,
|
|
199
|
+
zipLoading: C,
|
|
200
|
+
zipError: S,
|
|
201
|
+
selectedZipFile: N,
|
|
202
|
+
zipFileContent: M,
|
|
203
|
+
onFileClick: y,
|
|
204
|
+
url: e
|
|
205
|
+
});
|
|
206
|
+
case "unknown":
|
|
207
|
+
default:
|
|
208
|
+
return /* @__PURE__ */ r(se, {
|
|
209
|
+
url: e
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return /* @__PURE__ */ r("div", {
|
|
214
|
+
className: `document-viewer ${w || ""}`,
|
|
215
|
+
style: m,
|
|
216
|
+
children: $()
|
|
217
|
+
});
|
|
218
|
+
}, ie = ({
|
|
219
|
+
url: a
|
|
220
|
+
}) => {
|
|
221
|
+
const e = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(a)}`;
|
|
222
|
+
return /* @__PURE__ */ b("div", {
|
|
223
|
+
className: "document-viewer-office",
|
|
224
|
+
children: [/* @__PURE__ */ r("iframe", {
|
|
225
|
+
src: e,
|
|
226
|
+
className: "document-viewer-iframe",
|
|
227
|
+
title: "Office Document Preview"
|
|
228
|
+
}), /* @__PURE__ */ r("div", {
|
|
229
|
+
className: "document-viewer-fallback",
|
|
230
|
+
children: /* @__PURE__ */ r(j, {
|
|
231
|
+
message: "预览可能不可用",
|
|
232
|
+
description: /* @__PURE__ */ r("a", {
|
|
233
|
+
href: a,
|
|
234
|
+
target: "_blank",
|
|
235
|
+
rel: "noopener noreferrer",
|
|
236
|
+
children: "点击下载文件"
|
|
237
|
+
}),
|
|
238
|
+
type: "info",
|
|
239
|
+
showIcon: !0
|
|
240
|
+
})
|
|
241
|
+
})]
|
|
242
|
+
});
|
|
243
|
+
}, se = ({
|
|
244
|
+
url: a
|
|
245
|
+
}) => /* @__PURE__ */ r("div", {
|
|
246
|
+
className: "document-viewer-unknown",
|
|
247
|
+
children: /* @__PURE__ */ r("iframe", {
|
|
248
|
+
src: a,
|
|
249
|
+
className: "document-viewer-iframe",
|
|
250
|
+
title: "File Preview"
|
|
251
|
+
})
|
|
252
|
+
}), Ee = oe;
|
|
253
|
+
export {
|
|
254
|
+
Ee as default
|
|
255
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var i = (s, n, e) => new Promise((t, c) => {
|
|
2
|
+
var o = (a) => {
|
|
3
|
+
try {
|
|
4
|
+
r(e.next(a));
|
|
5
|
+
} catch (g) {
|
|
6
|
+
c(g);
|
|
7
|
+
}
|
|
8
|
+
}, h = (a) => {
|
|
9
|
+
try {
|
|
10
|
+
r(e.throw(a));
|
|
11
|
+
} catch (g) {
|
|
12
|
+
c(g);
|
|
13
|
+
}
|
|
14
|
+
}, r = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(o, h);
|
|
15
|
+
r((e = e.apply(s, n)).next());
|
|
16
|
+
});
|
|
17
|
+
const p = (s) => {
|
|
18
|
+
if (s === 0)
|
|
19
|
+
return "0 B";
|
|
20
|
+
const n = 1024, e = ["B", "KB", "MB", "GB"], t = Math.floor(Math.log(s) / Math.log(n));
|
|
21
|
+
return Math.round(s / Math.pow(n, t) * 100) / 100 + " " + e[t];
|
|
22
|
+
}, d = (s) => i(void 0, null, function* () {
|
|
23
|
+
let n = !1, e = 0;
|
|
24
|
+
try {
|
|
25
|
+
const t = yield fetch(s, {
|
|
26
|
+
method: "HEAD",
|
|
27
|
+
headers: {
|
|
28
|
+
Range: "bytes=0-0"
|
|
29
|
+
}
|
|
30
|
+
}), c = t.headers.get("Accept-Ranges"), o = t.headers.get("Content-Range"), h = t.headers.get("Content-Length");
|
|
31
|
+
if (o) {
|
|
32
|
+
const r = o.match(/bytes \d+-\d+\/(\d+)/);
|
|
33
|
+
r && (e = parseInt(r[1], 10));
|
|
34
|
+
} else
|
|
35
|
+
h && (e = parseInt(h, 10));
|
|
36
|
+
return n = t.status === 206 || c === "bytes" || o !== null && o.startsWith("bytes"), {
|
|
37
|
+
supportsRange: n,
|
|
38
|
+
fileSize: e
|
|
39
|
+
};
|
|
40
|
+
} catch (t) {
|
|
41
|
+
return console.warn("Range 支持检测失败:", t), {
|
|
42
|
+
supportsRange: !1,
|
|
43
|
+
fileSize: 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}), f = (s) => i(void 0, null, function* () {
|
|
47
|
+
try {
|
|
48
|
+
const e = (yield fetch(s, {
|
|
49
|
+
method: "HEAD"
|
|
50
|
+
})).headers.get("Content-Length");
|
|
51
|
+
return e ? parseInt(e, 10) : 0;
|
|
52
|
+
} catch (n) {
|
|
53
|
+
return console.warn("无法获取文件大小:", n), 0;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export {
|
|
57
|
+
d as checkRangeSupport,
|
|
58
|
+
p as formatFileSize,
|
|
59
|
+
f as getFileSize
|
|
60
|
+
};
|