@glodon-aiot/react-components 3.11.0-snapshot.1765331440 → 3.11.0-snapshot.1765331443

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.
@@ -1,236 +1,365 @@
1
- var x = (a, e, t) => new Promise((w, m) => {
2
- var n = (o) => {
1
+ var y = (o, e, r) => new Promise((b, p) => {
2
+ var C = (c) => {
3
3
  try {
4
- d(t.next(o));
5
- } catch (l) {
6
- m(l);
4
+ u(r.next(c));
5
+ } catch (v) {
6
+ p(v);
7
7
  }
8
- }, h = (o) => {
8
+ }, s = (c) => {
9
9
  try {
10
- d(t.throw(o));
11
- } catch (l) {
12
- m(l);
10
+ u(r.throw(c));
11
+ } catch (v) {
12
+ p(v);
13
13
  }
14
- }, d = (o) => o.done ? w(o.value) : Promise.resolve(o.value).then(n, h);
15
- d((t = t.apply(a, e)).next());
14
+ }, u = (c) => c.done ? b(c.value) : Promise.resolve(c.value).then(C, s);
15
+ u((r = r.apply(o, e)).next());
16
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";
17
+ import { jsxs as x, jsx as t } from "react/jsx-runtime";
18
+ import { useMemo as g, useState as w, useEffect as ie, useCallback as z } from "react";
19
+ import { message as h, Space as ae, Button as se, Dropdown as ce, Spin as le, Alert as de } from "antd";
20
+ import { DownloadOutlined as ue, CopyOutlined as pe } from "@ant-design/icons";
21
+ import { getFileExtension as A, getFileType as me } from "../../utils/file.mjs";
22
+ import { MAX_FILE_SIZE as S } from "./constants.mjs";
23
+ import { usePdfViewer as fe } from "./hooks/usePdfViewer.mjs";
24
+ import { useZipViewer as we } from "./hooks/useZipViewer.mjs";
25
+ import { TextRenderer as P, CodeRenderer as he, XmlRenderer as ve, HtmlRenderer as ye, MarkdownRenderer as xe, JsonlRenderer as be, TsvRenderer as ge, CsvRenderer as Ce, JsonRenderer as ke } from "./components/FileRenderers.mjs";
26
+ import { AudioRenderer as Re, VideoRenderer as Fe, ImageRenderer as Te } from "./components/MediaRenderers.mjs";
27
+ import { PdfRenderer as Ee } from "./components/PdfRenderer.mjs";
28
+ import { ZipRenderer as Ne } from "./components/ZipRenderer.mjs";
29
+ import { ErrorAlert as ze } from "./components/ErrorAlert.mjs";
29
30
  import "./style.less.mjs";
30
- const oe = (a) => {
31
+ const Se = (o) => {
32
+ if (!o)
33
+ return "unknown";
34
+ const e = o.split(";")[0].trim().toLowerCase();
35
+ return e.startsWith("image/") ? "image" : e.startsWith("video/") ? "video" : e.startsWith("audio/") ? "audio" : e === "application/pdf" ? "pdf" : e === "text/markdown" || e === "text/x-markdown" ? "markdown" : e === "application/json" ? "json" : e === "application/jsonl" ? "jsonl" : e === "text/csv" || e === "application/csv" ? "csv" : e === "text/tab-separated-values" ? "tsv" : e === "application/javascript" || e === "text/javascript" ? "code" : e === "application/xml" || e === "text/xml" ? "xml" : e === "text/html" || e === "application/xhtml+xml" ? "html" : e === "text/plain" ? "text" : "unknown";
36
+ }, Be = (o) => !o || Number.isNaN(o) ? "大小未知" : o < 1024 ? `${o}B` : o < 1024 * 1024 ? `${(o / 1024).toFixed(1)}KB` : o < 1024 * 1024 * 1024 ? `${(o / 1024 / 1024).toFixed(1)}MB` : `${(o / 1024 / 1024 / 1024).toFixed(1)}GB`, Le = (o, e) => {
37
+ if (e)
38
+ return e;
39
+ try {
40
+ const p = new URL(o).pathname.split("/").filter(Boolean).pop();
41
+ return decodeURIComponent(p || o);
42
+ } catch (r) {
43
+ return o;
44
+ }
45
+ }, je = (o) => {
31
46
  const {
32
47
  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);
48
+ fileName: r,
49
+ className: b,
50
+ style: p,
51
+ showToolbar: C = !0
52
+ } = o, s = g(() => {
53
+ const a = A(e), n = r ? A(r) : void 0;
54
+ return me(a || n);
55
+ }, [e, r]), [u, c] = w(s), {
56
+ pdfBlobUrl: v,
57
+ pdfLoading: V,
58
+ pdfError: W
59
+ } = fe(s === "pdf" ? e : ""), {
60
+ zipFiles: H,
61
+ zipLoading: Z,
62
+ zipError: _,
63
+ selectedZipFile: J,
64
+ zipFileContent: X,
65
+ handleFileClick: G
66
+ } = we(s === "zip" ? e : ""), [K, d] = w(!0), [B, m] = w(null), [i, L] = w(null), [l, j] = w(0), [q, M] = w(!1), $ = g(() => Le(e, r), [r, e]), Q = g(() => Be(l), [l]), k = !!(i != null && i.content), Y = !k && !e, ee = g(() => [{
67
+ key: "copy-content",
68
+ label: "复制内容",
69
+ disabled: !k
70
+ }, {
71
+ key: "copy-url",
72
+ label: "复制地址",
73
+ disabled: !e
74
+ }], [k, e]);
75
+ ie(() => {
76
+ if (c(s), s === "pdf" || s === "zip") {
77
+ d(!1);
54
78
  return;
55
79
  }
56
80
  if (!e) {
57
- f("文件URL不能为空"), c(!1);
81
+ m("文件URL不能为空"), d(!1);
58
82
  return;
59
83
  }
60
- if (["image", "video", "audio", "office", "unknown"].includes(n)) {
61
- c(!1);
84
+ if (["image", "video", "audio", "office"].includes(s)) {
85
+ d(!1);
62
86
  return;
63
87
  }
64
- c(!0), f(null), x(void 0, null, function* () {
88
+ d(!0), m(null), y(void 0, null, function* () {
65
89
  try {
66
- const z = (yield fetch(e, {
90
+ if (e.startsWith("blob:") || e.startsWith("data:")) {
91
+ const f = yield fetch(e);
92
+ if (!f.ok)
93
+ throw new Error(`HTTP error! status: ${f.status}`);
94
+ const O = yield f.blob(), N = O.size;
95
+ if (j(N), N > S) {
96
+ m(`文件过大(${Math.round(N / 1024 / 1024)}MB),无法预览。请下载后查看。`), d(!1);
97
+ return;
98
+ }
99
+ const oe = yield O.text();
100
+ s === "unknown" && c("text"), L({
101
+ content: oe
102
+ }), d(!1);
103
+ return;
104
+ }
105
+ const n = yield fetch(e, {
67
106
  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);
107
+ }), F = n.headers.get("Content-Length"), ne = n.headers.get("Content-Type"), T = F ? parseInt(F, 10) : 0;
108
+ if (j(T), s === "unknown") {
109
+ const f = Se(ne);
110
+ f !== "unknown" && c(f);
111
+ }
112
+ if (T > S) {
113
+ m(`文件过大(${Math.round(T / 1024 / 1024)}MB),无法预览。请下载后查看。`), d(!1);
71
114
  return;
72
115
  }
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);
116
+ const E = yield fetch(e);
117
+ if (!E.ok)
118
+ throw new Error(`HTTP error! status: ${E.status}`);
119
+ const D = yield E.text(), I = new Blob([D]).size;
120
+ if (I > S) {
121
+ m(`文件过大(${Math.round(I / 1024 / 1024)}MB),无法预览。请下载后查看。`), d(!1);
79
122
  return;
80
123
  }
81
- T({
82
- content: E
83
- }), c(!1);
84
- } catch (u) {
85
- f(u.message || "加载文件失败"), c(!1);
124
+ u === "unknown" && c("text"), L({
125
+ content: D
126
+ }), d(!1);
127
+ } catch (a) {
128
+ m(a.message || "加载文件失败"), d(!1);
86
129
  }
87
130
  });
88
- }, [e, n]);
89
- const $ = () => {
90
- if (I)
91
- return /* @__PURE__ */ r("div", {
131
+ }, [e, s]);
132
+ const R = z(() => y(void 0, null, function* () {
133
+ var a;
134
+ if (!(i != null && i.content)) {
135
+ h.warning("暂无可复制的内容");
136
+ return;
137
+ }
138
+ try {
139
+ if (M(!0), (a = navigator == null ? void 0 : navigator.clipboard) != null && a.writeText)
140
+ yield navigator.clipboard.writeText(i.content);
141
+ else {
142
+ const n = document.createElement("textarea");
143
+ n.value = i.content, n.style.position = "fixed", n.style.opacity = "0", document.body.appendChild(n), n.select(), document.execCommand("copy"), document.body.removeChild(n);
144
+ }
145
+ h.success("内容已复制到剪贴板");
146
+ } catch (n) {
147
+ h.error((n == null ? void 0 : n.message) || "复制失败,请手动复制");
148
+ } finally {
149
+ M(!1);
150
+ }
151
+ }), [i]), U = z(() => y(void 0, null, function* () {
152
+ var a;
153
+ if (!e) {
154
+ h.warning("暂无可复制的地址");
155
+ return;
156
+ }
157
+ try {
158
+ if ((a = navigator == null ? void 0 : navigator.clipboard) != null && a.writeText)
159
+ yield navigator.clipboard.writeText(e);
160
+ else {
161
+ const n = document.createElement("textarea");
162
+ n.value = e, n.style.position = "fixed", n.style.opacity = "0", document.body.appendChild(n), n.select(), document.execCommand("copy"), document.body.removeChild(n);
163
+ }
164
+ h.success("链接已复制到剪贴板");
165
+ } catch (n) {
166
+ h.error((n == null ? void 0 : n.message) || "复制失败,请手动复制");
167
+ }
168
+ }), [e]), te = z((n) => y(void 0, [n], function* ({
169
+ key: a
170
+ }) {
171
+ a === "copy-content" && (yield R()), a === "copy-url" && (yield U());
172
+ }), [R, U]), re = () => {
173
+ if (K)
174
+ return /* @__PURE__ */ t("div", {
92
175
  className: "document-viewer-loading",
93
- children: /* @__PURE__ */ r(U, {
176
+ children: /* @__PURE__ */ t(le, {
94
177
  size: "large",
95
178
  tip: "加载中..."
96
179
  })
97
180
  });
98
- if (R)
99
- return /* @__PURE__ */ r(ne, {
181
+ if (B)
182
+ return /* @__PURE__ */ t(ze, {
100
183
  message: "加载失败",
101
- description: R,
184
+ description: B,
102
185
  url: e,
103
- fileName: t
186
+ fileName: r
104
187
  });
105
- switch (n) {
188
+ if (u === "unknown" && (i != null && i.content))
189
+ return /* @__PURE__ */ t(P, {
190
+ fileContent: i,
191
+ fileSize: l,
192
+ url: e,
193
+ fileName: r
194
+ });
195
+ switch (u) {
106
196
  case "text":
107
- return /* @__PURE__ */ r(Q, {
197
+ return /* @__PURE__ */ t(P, {
108
198
  fileContent: i,
109
- fileSize: s,
199
+ fileSize: l,
110
200
  url: e,
111
- fileName: t
201
+ fileName: r
112
202
  });
113
203
  case "json":
114
- return /* @__PURE__ */ r(K, {
204
+ return /* @__PURE__ */ t(ke, {
115
205
  fileContent: i,
116
- fileSize: s,
206
+ fileSize: l,
117
207
  url: e,
118
- fileName: t
208
+ fileName: r
119
209
  });
120
210
  case "csv":
121
- return /* @__PURE__ */ r(G, {
211
+ return /* @__PURE__ */ t(Ce, {
122
212
  fileContent: i,
123
- fileSize: s,
213
+ fileSize: l,
124
214
  url: e,
125
- fileName: t
215
+ fileName: r
126
216
  });
127
217
  case "tsv":
128
- return /* @__PURE__ */ r(q, {
218
+ return /* @__PURE__ */ t(ge, {
129
219
  fileContent: i,
130
- fileSize: s,
220
+ fileSize: l,
131
221
  url: e,
132
- fileName: t
222
+ fileName: r
133
223
  });
134
224
  case "jsonl":
135
- return /* @__PURE__ */ r(X, {
225
+ return /* @__PURE__ */ t(be, {
136
226
  fileContent: i,
137
- fileSize: s,
227
+ fileSize: l,
138
228
  url: e,
139
- fileName: t
229
+ fileName: r
140
230
  });
141
231
  case "markdown":
142
- return /* @__PURE__ */ r(O, {
232
+ return /* @__PURE__ */ t(xe, {
143
233
  fileContent: i,
144
- fileSize: s,
234
+ fileSize: l,
145
235
  url: e,
146
- fileName: t
236
+ fileName: r
147
237
  });
148
238
  case "html":
149
- return /* @__PURE__ */ r(J, {
239
+ return /* @__PURE__ */ t(ye, {
150
240
  fileContent: i,
151
- fileSize: s,
241
+ fileSize: l,
152
242
  url: e,
153
- fileName: t
243
+ fileName: r
154
244
  });
155
245
  case "xml":
156
- return /* @__PURE__ */ r(_, {
246
+ return /* @__PURE__ */ t(ve, {
157
247
  fileContent: i,
158
- fileSize: s,
248
+ fileSize: l,
159
249
  url: e,
160
- fileName: t
250
+ fileName: r
161
251
  });
162
252
  case "code":
163
- return /* @__PURE__ */ r(H, {
253
+ return /* @__PURE__ */ t(he, {
164
254
  fileContent: i,
165
- fileSize: s,
255
+ fileSize: l,
166
256
  url: e,
167
- fileName: t
257
+ fileName: r
168
258
  });
169
259
  case "image":
170
- return /* @__PURE__ */ r(ee, {
260
+ return /* @__PURE__ */ t(Te, {
171
261
  url: e,
172
- fileName: t
262
+ fileName: r
173
263
  });
174
264
  case "video":
175
- return /* @__PURE__ */ r(Y, {
265
+ return /* @__PURE__ */ t(Fe, {
176
266
  url: e,
177
- fileName: t
267
+ fileName: r
178
268
  });
179
269
  case "audio":
180
- return /* @__PURE__ */ r(W, {
270
+ return /* @__PURE__ */ t(Re, {
181
271
  url: e,
182
- fileName: t
272
+ fileName: r
183
273
  });
184
274
  case "pdf":
185
- return /* @__PURE__ */ r(re, {
186
- pdfBlobUrl: h,
187
- pdfLoading: d,
188
- pdfError: o,
275
+ return /* @__PURE__ */ t(Ee, {
276
+ pdfBlobUrl: v,
277
+ pdfLoading: V,
278
+ pdfError: W,
189
279
  url: e,
190
- fileName: t
280
+ fileName: r
191
281
  });
192
282
  case "office":
193
- return /* @__PURE__ */ r(ie, {
283
+ return /* @__PURE__ */ t(Me, {
194
284
  url: e
195
285
  });
196
286
  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,
287
+ return /* @__PURE__ */ t(Ne, {
288
+ zipFiles: H,
289
+ zipLoading: Z,
290
+ zipError: _,
291
+ selectedZipFile: J,
292
+ zipFileContent: X,
293
+ onFileClick: G,
204
294
  url: e
205
295
  });
206
296
  case "unknown":
207
297
  default:
208
- return /* @__PURE__ */ r(se, {
298
+ return /* @__PURE__ */ t($e, {
209
299
  url: e
210
300
  });
211
301
  }
212
302
  };
213
- return /* @__PURE__ */ r("div", {
214
- className: `document-viewer ${w || ""}`,
215
- style: m,
216
- children: $()
303
+ return /* @__PURE__ */ x("div", {
304
+ className: `document-viewer ${b || ""}`,
305
+ style: p,
306
+ children: [C && /* @__PURE__ */ x("div", {
307
+ className: "document-viewer-toolbar",
308
+ children: [/* @__PURE__ */ x("div", {
309
+ className: "document-viewer-toolbar-meta",
310
+ children: [/* @__PURE__ */ t("span", {
311
+ className: "document-viewer-toolbar-name",
312
+ title: $,
313
+ children: $
314
+ }), /* @__PURE__ */ t("span", {
315
+ className: "document-viewer-toolbar-size",
316
+ children: Q
317
+ })]
318
+ }), /* @__PURE__ */ x(ae, {
319
+ size: 8,
320
+ wrap: !0,
321
+ children: [/* @__PURE__ */ t(se, {
322
+ icon: /* @__PURE__ */ t(ue, {}),
323
+ size: "small",
324
+ href: e,
325
+ target: "_blank",
326
+ rel: "noopener noreferrer",
327
+ download: r || void 0,
328
+ children: "下载"
329
+ }), /* @__PURE__ */ t(ce.Button, {
330
+ size: "small",
331
+ icon: /* @__PURE__ */ t(pe, {}),
332
+ menu: {
333
+ items: ee,
334
+ onClick: te
335
+ },
336
+ disabled: Y,
337
+ loading: q,
338
+ onClick: R,
339
+ children: "复制"
340
+ })]
341
+ })]
342
+ }), /* @__PURE__ */ t("div", {
343
+ className: "document-viewer-body",
344
+ children: re()
345
+ })]
217
346
  });
218
- }, ie = ({
219
- url: a
347
+ }, Me = ({
348
+ url: o
220
349
  }) => {
221
- const e = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(a)}`;
222
- return /* @__PURE__ */ b("div", {
350
+ const e = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(o)}`;
351
+ return /* @__PURE__ */ x("div", {
223
352
  className: "document-viewer-office",
224
- children: [/* @__PURE__ */ r("iframe", {
353
+ children: [/* @__PURE__ */ t("iframe", {
225
354
  src: e,
226
355
  className: "document-viewer-iframe",
227
356
  title: "Office Document Preview"
228
- }), /* @__PURE__ */ r("div", {
357
+ }), /* @__PURE__ */ t("div", {
229
358
  className: "document-viewer-fallback",
230
- children: /* @__PURE__ */ r(j, {
359
+ children: /* @__PURE__ */ t(de, {
231
360
  message: "预览可能不可用",
232
- description: /* @__PURE__ */ r("a", {
233
- href: a,
361
+ description: /* @__PURE__ */ t("a", {
362
+ href: o,
234
363
  target: "_blank",
235
364
  rel: "noopener noreferrer",
236
365
  children: "点击下载文件"
@@ -240,16 +369,16 @@ const oe = (a) => {
240
369
  })
241
370
  })]
242
371
  });
243
- }, se = ({
244
- url: a
245
- }) => /* @__PURE__ */ r("div", {
372
+ }, $e = ({
373
+ url: o
374
+ }) => /* @__PURE__ */ t("div", {
246
375
  className: "document-viewer-unknown",
247
- children: /* @__PURE__ */ r("iframe", {
248
- src: a,
376
+ children: /* @__PURE__ */ t("iframe", {
377
+ src: o,
249
378
  className: "document-viewer-iframe",
250
379
  title: "File Preview"
251
380
  })
252
- }), Ee = oe;
381
+ }), qe = je;
253
382
  export {
254
- Ee as default
383
+ qe as default
255
384
  };