@glodon-aiot/react-components 3.11.0-snapshot.1765331441 → 3.11.0-snapshot.1765331448

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