@hkyhy/marsun-components-core 0.1.123 → 0.1.125

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.
Files changed (67) hide show
  1. package/README.md +1 -0
  2. package/dist/_virtual/index.js +5 -5
  3. package/dist/_virtual/index2.js +5 -5
  4. package/dist/components/File/FileItem/index.js +65 -55
  5. package/dist/components/File/FileItem/index.js.map +1 -1
  6. package/dist/components/File/FilePreview/FilePreviewContent.js +114 -90
  7. package/dist/components/File/FilePreview/FilePreviewContent.js.map +1 -1
  8. package/dist/components/File/FilePreview/index.js +43 -33
  9. package/dist/components/File/FilePreview/index.js.map +1 -1
  10. package/dist/components/File/index.d.ts +1 -0
  11. package/dist/components/File/utils/authedFetch.d.ts +12 -0
  12. package/dist/components/File/utils/authedFetch.js +50 -0
  13. package/dist/components/File/utils/authedFetch.js.map +1 -0
  14. package/dist/components/Form/index.d.ts +1 -1
  15. package/dist/components/Form/kneFormInfo.d.ts +2 -0
  16. package/dist/components/Form/kneFormInfo.js +30 -27
  17. package/dist/components/Form/kneFormInfo.js.map +1 -1
  18. package/dist/components/FormInfo/fields.d.ts +2 -0
  19. package/dist/components/FormInfo/fields.js +22 -19
  20. package/dist/components/FormInfo/fields.js.map +1 -1
  21. package/dist/components/FormInfo/index.d.ts +1 -1
  22. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionForm.d.ts +8 -1
  23. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionForm.js +148 -142
  24. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionForm.js.map +1 -1
  25. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionForm.module.scss.js +5 -4
  26. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionForm.module.scss.js.map +1 -1
  27. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionModal.d.ts +10 -2
  28. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionModal.js +122 -116
  29. package/dist/components/Tools/ActionTracking/CreateAction/CreateActionModal.js.map +1 -1
  30. package/dist/components/Tools/ActionTracking/CreateAction/PersonRoleCascaderField.js +20 -31
  31. package/dist/components/Tools/ActionTracking/CreateAction/PersonRoleCascaderField.js.map +1 -1
  32. package/dist/components/Tools/ActionTracking/CreateAction/PersonRoleCascaderField.module.scss.js +1 -2
  33. package/dist/components/Tools/ActionTracking/CreateAction/PersonRoleCascaderField.module.scss.js.map +1 -1
  34. package/dist/components/Tools/ActionTracking/CreateAction/index.d.ts +1 -1
  35. package/dist/components/Tools/ActionTracking/CreateAction/submitHelpers.d.ts +5 -0
  36. package/dist/components/Tools/ActionTracking/CreateAction/submitHelpers.js +37 -18
  37. package/dist/components/Tools/ActionTracking/CreateAction/submitHelpers.js.map +1 -1
  38. package/dist/components/Tools/ActionTracking/CreateAction/types.d.ts +9 -0
  39. package/dist/components/Tools/ActionTracking/index.d.ts +1 -1
  40. package/dist/components/Tools/Inbox/InboxBell/InboxBell.d.ts +43 -3
  41. package/dist/components/Tools/Inbox/InboxBell/InboxBell.js +345 -130
  42. package/dist/components/Tools/Inbox/InboxBell/InboxBell.js.map +1 -1
  43. package/dist/components/Tools/Inbox/InboxBell/emphasizeQuoted.d.ts +3 -0
  44. package/dist/components/Tools/Inbox/InboxBell/emphasizeQuoted.js +13 -0
  45. package/dist/components/Tools/Inbox/InboxBell/emphasizeQuoted.js.map +1 -0
  46. package/dist/components/Tools/Inbox/InboxBell/inboxItemActions.d.ts +37 -0
  47. package/dist/components/Tools/Inbox/InboxBell/inboxItemActions.js +97 -0
  48. package/dist/components/Tools/Inbox/InboxBell/inboxItemActions.js.map +1 -0
  49. package/dist/components/Tools/Inbox/InboxBell/index.d.ts +2 -0
  50. package/dist/components/Tools/Inbox/InboxBell/style.module.scss.js +58 -26
  51. package/dist/components/Tools/Inbox/InboxBell/style.module.scss.js.map +1 -1
  52. package/dist/components/Tools/Inbox/InboxBell/toastPrefs.d.ts +10 -0
  53. package/dist/components/Tools/Inbox/InboxBell/toastPrefs.js +46 -0
  54. package/dist/components/Tools/Inbox/InboxBell/toastPrefs.js.map +1 -0
  55. package/dist/components/Tools/Inbox/index.d.ts +2 -0
  56. package/dist/components/Tools/index.d.ts +3 -2
  57. package/dist/file.js +24 -19
  58. package/dist/file.js.map +1 -1
  59. package/dist/form-info.js +46 -45
  60. package/dist/index.js +517 -504
  61. package/dist/index.js.map +1 -1
  62. package/dist/marsun-components-core.css +1 -1
  63. package/dist/node_modules/@antv/g-lite/dist/index.esm.js +1 -1
  64. package/dist/node_modules/@antv/g2/esm/data/kde.js +1 -1
  65. package/dist/node_modules/eventemitter3/index.js +1 -1
  66. package/dist/styles/global.css +1 -1
  67. package/package.json +1 -1
package/README.md CHANGED
@@ -136,6 +136,7 @@ node scripts/version-check.mjs --apply # → 0.1.99
136
136
 
137
137
  也可在 Actions 中手动运行 **Publish npm**,填写已有 tag 重新发布。
138
138
 
139
+ - 2026-10-09:`v0.1.124` — CreateAction FormInfo DatePicker 与 scopeMode=none(token 刷新后重发)
139
140
  - 2026-09-23:`v0.1.122` — ActionListTable 默认 scrollX 对齐长状态列(0.1.121 已发后补发)
140
141
 
141
142
  ## 后续接入 maoyang
@@ -1,8 +1,8 @@
1
- import { getDefaultExportFromCjs as t } from "./_commonjsHelpers.js";
2
- import { __require as e } from "../node_modules/eventemitter3/index2.js";
3
- var r = e();
4
- const i = /* @__PURE__ */ t(r);
1
+ import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
+ import { __require as o } from "../node_modules/pdfast/src/index.js";
3
+ var t = o();
4
+ const s = /* @__PURE__ */ r(t);
5
5
  export {
6
- i as default
6
+ s as default
7
7
  };
8
8
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
1
- import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as o } from "../node_modules/pdfast/src/index.js";
3
- var t = o();
4
- const s = /* @__PURE__ */ r(t);
1
+ import { getDefaultExportFromCjs as t } from "./_commonjsHelpers.js";
2
+ import { __require as e } from "../node_modules/eventemitter3/index2.js";
3
+ var r = e();
4
+ const i = /* @__PURE__ */ t(r);
5
5
  export {
6
- s as default
6
+ i as default
7
7
  };
8
8
  //# sourceMappingURL=index2.js.map
@@ -1,106 +1,116 @@
1
- import { jsxs as o, Fragment as C, jsx as i } from "react/jsx-runtime";
2
- import { formatFileSize as T } from "../../../utils/format.js";
3
- import { Tooltip as z, Button as x } from "antd";
4
- import { useState as b } from "react";
5
- import I from "../FilePreviewModal/index.js";
6
- import { normalizeFileDisplayItem as P, getFileTypeName as j, getFileIcon as A } from "../fileDisplay.js";
7
- import l from "./style.module.scss.js";
8
- import t from "classnames";
9
- import O from "../../Tag/FileTags.js";
1
+ import { jsxs as r, Fragment as U, jsx as i } from "react/jsx-runtime";
2
+ import { formatFileSize as z } from "../../../utils/format.js";
3
+ import { Tooltip as j, Button as x, message as A } from "antd";
4
+ import { useState as E } from "react";
5
+ import L from "../FilePreviewModal/index.js";
6
+ import { normalizeFileDisplayItem as O, getFileTypeName as R, getFileIcon as I } from "../fileDisplay.js";
7
+ import { useFileAuthHeaders as P, fetchWithMarsunAuth as H } from "../utils/authedFetch.js";
8
+ import t from "./style.module.scss.js";
9
+ import l from "classnames";
10
+ import M from "../../Tag/FileTags.js";
10
11
  import { Eye as S } from "../../Icons/Eye.js";
11
12
  import { Download as B } from "../../Icons/Download.js";
12
13
  import { Trash2 as D } from "../../Icons/Trash2.js";
13
- const V = ({
14
- file: p,
15
- status: a,
16
- showDownload: d = !0,
17
- showDelete: h = !1,
18
- showPreview: u = !0,
19
- actions: w,
20
- onDownload: n,
21
- onDelete: s,
22
- onPreview: c
14
+ const ie = ({
15
+ file: u,
16
+ status: n,
17
+ showDownload: w = !0,
18
+ showDelete: y = !1,
19
+ showPreview: N = !0,
20
+ actions: g,
21
+ onDownload: c,
22
+ onDelete: f,
23
+ onPreview: p
23
24
  }) => {
24
- const [N, f] = b(!1), e = P(p), y = () => {
25
- if (n) {
26
- n(e);
25
+ const [v, d] = E(!1), e = O(u), k = P(), b = () => {
26
+ if (c) {
27
+ c(e);
27
28
  return;
28
29
  }
29
- e.url && window.open(e.url, "_blank");
30
- }, g = () => {
31
- c ? c(e) : f(!0);
32
- }, r = [];
33
- u && r.push({
30
+ e.url && (async () => {
31
+ try {
32
+ const o = await H(e.url, k);
33
+ if (!o.ok) throw new Error(`下载失败 (${o.status})`);
34
+ const m = await o.blob(), h = URL.createObjectURL(m), s = document.createElement("a");
35
+ s.href = h, s.download = e.name || "download", s.click(), URL.revokeObjectURL(h);
36
+ } catch (o) {
37
+ A.error(o instanceof Error ? o.message : "下载失败");
38
+ }
39
+ })();
40
+ }, F = () => {
41
+ p ? p(e) : d(!0);
42
+ }, a = [];
43
+ N && a.push({
34
44
  key: "preview",
35
45
  icon: /* @__PURE__ */ i(S, {}),
36
46
  tooltip: "预览",
37
- onClick: () => g()
38
- }), d && r.push({
47
+ onClick: () => F()
48
+ }), w && a.push({
39
49
  key: "download",
40
50
  icon: /* @__PURE__ */ i(B, {}),
41
51
  tooltip: "下载",
42
- onClick: () => y()
43
- }), h && s && r.push({
52
+ onClick: () => b()
53
+ }), y && f && a.push({
44
54
  key: "delete",
45
55
  icon: /* @__PURE__ */ i(D, {}),
46
56
  tooltip: "删除",
47
- onClick: () => s(e)
57
+ onClick: () => f(e)
48
58
  });
49
- const v = [...r, ...w ?? []], k = j(e.name, e.mimeType);
50
- return /* @__PURE__ */ o(C, { children: [
51
- /* @__PURE__ */ i("div", { className: t("file-item-root", l["file-item-root"]), children: /* @__PURE__ */ o("div", { className: t("file-item-container", l["file-item-container"]), children: [
52
- /* @__PURE__ */ o("div", { className: t("file-item-wrapper", l["file-item-wrapper"]), children: [
53
- /* @__PURE__ */ i("span", { className: t("file-item-inner", l["file-item-inner"]), children: A(e.name, e.mimeType) }),
54
- /* @__PURE__ */ o("div", { className: t("file-item-header", l["file-item-header"]), children: [
55
- /* @__PURE__ */ o("div", { className: t("file-item-body", l["file-item-body"]), children: [
59
+ const C = [...a, ...g ?? []], T = R(e.name, e.mimeType);
60
+ return /* @__PURE__ */ r(U, { children: [
61
+ /* @__PURE__ */ i("div", { className: l("file-item-root", t["file-item-root"]), children: /* @__PURE__ */ r("div", { className: l("file-item-container", t["file-item-container"]), children: [
62
+ /* @__PURE__ */ r("div", { className: l("file-item-wrapper", t["file-item-wrapper"]), children: [
63
+ /* @__PURE__ */ i("span", { className: l("file-item-inner", t["file-item-inner"]), children: I(e.name, e.mimeType) }),
64
+ /* @__PURE__ */ r("div", { className: l("file-item-header", t["file-item-header"]), children: [
65
+ /* @__PURE__ */ r("div", { className: l("file-item-body", t["file-item-body"]), children: [
56
66
  /* @__PURE__ */ i(
57
67
  "span",
58
68
  {
59
- className: t("file-item-footer", l["file-item-footer"]),
69
+ className: l("file-item-footer", t["file-item-footer"]),
60
70
  title: e.name,
61
71
  children: e.name
62
72
  }
63
73
  ),
64
- /* @__PURE__ */ i("span", { className: t("file-item-row", l["file-item-row"]), children: k }),
65
- e.size != null && /* @__PURE__ */ i("span", { className: t("file-item-row", l["file-item-row"]), children: T(e.size) })
74
+ /* @__PURE__ */ i("span", { className: l("file-item-row", t["file-item-row"]), children: T }),
75
+ e.size != null && /* @__PURE__ */ i("span", { className: l("file-item-row", t["file-item-row"]), children: z(e.size) })
66
76
  ] }),
67
77
  e.tags && e.tags.length > 0 && /* @__PURE__ */ i(
68
- O,
78
+ M,
69
79
  {
70
80
  tags: e.tags,
71
- className: t("file-item-col", l["file-item-col"])
81
+ className: l("file-item-col", t["file-item-col"])
72
82
  }
73
83
  )
74
84
  ] })
75
85
  ] }),
76
- /* @__PURE__ */ o("div", { className: t("file-item-wrap", l["file-item-wrap"]), children: [
77
- a && /* @__PURE__ */ i("span", { className: t("file-item-panel", l["file-item-panel"]), children: a }),
78
- /* @__PURE__ */ i("div", { className: t("file-item-action-group", l["file-item-action-group"]), children: v.map((m) => /* @__PURE__ */ i(z, { title: m.tooltip, children: /* @__PURE__ */ i(
86
+ /* @__PURE__ */ r("div", { className: l("file-item-wrap", t["file-item-wrap"]), children: [
87
+ n && /* @__PURE__ */ i("span", { className: l("file-item-panel", t["file-item-panel"]), children: n }),
88
+ /* @__PURE__ */ i("div", { className: l("file-item-action-group", t["file-item-action-group"]), children: C.map((o) => /* @__PURE__ */ i(j, { title: o.tooltip, children: /* @__PURE__ */ i(
79
89
  x,
80
90
  {
81
91
  type: "text",
82
92
  size: "small",
83
- icon: m.icon,
84
- onClick: (F) => {
85
- F.stopPropagation(), m.onClick(e);
93
+ icon: o.icon,
94
+ onClick: (m) => {
95
+ m.stopPropagation(), o.onClick(e);
86
96
  }
87
97
  }
88
- ) }, m.key)) })
98
+ ) }, o.key)) })
89
99
  ] })
90
100
  ] }) }),
91
101
  /* @__PURE__ */ i(
92
- I,
102
+ L,
93
103
  {
94
- open: N,
104
+ open: v,
95
105
  file: e,
96
106
  url: e.url,
97
107
  downloadUrl: e.url,
98
- onClose: () => f(!1)
108
+ onClose: () => d(!1)
99
109
  }
100
110
  )
101
111
  ] });
102
112
  };
103
113
  export {
104
- V as FileItem
114
+ ie as FileItem
105
115
  };
106
116
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/components/File/FileItem/index.tsx"],"sourcesContent":["import { FileTags } from '@/components/Tag';\nimport { Trash2, Download, Eye } from '@/components/Icons';\nimport { formatFileSize } from '@/utils/format';\nimport { Button, Tooltip } from 'antd';\nimport React, { useState } from 'react';\nimport FilePreviewModal from '../FilePreviewModal';\nimport { getFileIcon, getFileTypeName, normalizeFileDisplayItem } from '../fileDisplay';\nimport type { FileDisplayItem } from '../types';\nimport styles from './style.module.scss';\nimport classNames from 'classnames';\n\nexport interface FileItemAction {\n key: string;\n icon: React.ReactNode;\n tooltip: string;\n onClick: (file: FileDisplayItem) => void;\n}\n\nexport interface FileItemProps {\n file: FileDisplayItem;\n status?: React.ReactNode;\n showDownload?: boolean;\n showDelete?: boolean;\n showPreview?: boolean;\n actions?: FileItemAction[];\n onDownload?: (file: FileDisplayItem) => void;\n onDelete?: (file: FileDisplayItem) => void;\n onPreview?: (file: FileDisplayItem) => void;\n}\n\nconst FileItem: React.FC<FileItemProps> = ({\n file,\n status,\n showDownload = true,\n showDelete = false,\n showPreview = true,\n actions,\n onDownload,\n onDelete,\n onPreview,\n}) => {\n const [previewOpen, setPreviewOpen] = useState(false);\n const resolvedFile = normalizeFileDisplayItem(file);\n\n const handleDownload = () => {\n if (onDownload) {\n onDownload(resolvedFile);\n return;\n }\n if (resolvedFile.url) window.open(resolvedFile.url, '_blank');\n };\n\n const handlePreview = () => {\n if (onPreview) onPreview(resolvedFile);\n else setPreviewOpen(true);\n };\n\n const defaultActions: FileItemAction[] = [];\n if (showPreview) {\n defaultActions.push({\n key: 'preview',\n icon: <Eye />,\n tooltip: '预览',\n onClick: () => handlePreview(),\n });\n }\n if (showDownload) {\n defaultActions.push({\n key: 'download',\n icon: <Download />,\n tooltip: '下载',\n onClick: () => handleDownload(),\n });\n }\n if (showDelete && onDelete) {\n defaultActions.push({\n key: 'delete',\n icon: <Trash2 />,\n tooltip: '删除',\n onClick: () => onDelete(resolvedFile),\n });\n }\n\n const allActions = [...defaultActions, ...(actions ?? [])];\n const typeName = getFileTypeName(resolvedFile.name, resolvedFile.mimeType);\n\n return (\n <>\n <div className={classNames('file-item-root', styles['file-item-root'])}>\n <div className={classNames('file-item-container', styles['file-item-container'])}>\n <div className={classNames('file-item-wrapper', styles['file-item-wrapper'])}>\n <span className={classNames('file-item-inner', styles['file-item-inner'])}>\n {getFileIcon(resolvedFile.name, resolvedFile.mimeType)}\n </span>\n <div className={classNames('file-item-header', styles['file-item-header'])}>\n <div className={classNames('file-item-body', styles['file-item-body'])}>\n <span\n className={classNames('file-item-footer', styles['file-item-footer'])}\n title={resolvedFile.name}\n >\n {resolvedFile.name}\n </span>\n <span className={classNames('file-item-row', styles['file-item-row'])}>\n {typeName}\n </span>\n {resolvedFile.size != null && (\n <span className={classNames('file-item-row', styles['file-item-row'])}>\n {formatFileSize(resolvedFile.size)}\n </span>\n )}\n </div>\n {resolvedFile.tags && resolvedFile.tags.length > 0 && (\n <FileTags\n tags={resolvedFile.tags}\n className={classNames('file-item-col', styles['file-item-col'])}\n />\n )}\n </div>\n </div>\n\n <div className={classNames('file-item-wrap', styles['file-item-wrap'])}>\n {status && (\n <span className={classNames('file-item-panel', styles['file-item-panel'])}>\n {status}\n </span>\n )}\n <div className={classNames('file-item-action-group', styles['file-item-action-group'])}>\n {allActions.map((action) => (\n <Tooltip key={action.key} title={action.tooltip}>\n <Button\n type=\"text\"\n size=\"small\"\n icon={action.icon}\n onClick={(e) => {\n e.stopPropagation();\n action.onClick(resolvedFile);\n }}\n />\n </Tooltip>\n ))}\n </div>\n </div>\n </div>\n </div>\n <FilePreviewModal\n open={previewOpen}\n file={resolvedFile}\n url={resolvedFile.url}\n downloadUrl={resolvedFile.url}\n onClose={() => setPreviewOpen(false)}\n />\n </>\n );\n};\n\nexport { FileItem };\nexport default FileItem;\n"],"names":["FileItem","file","status","showDownload","showDelete","showPreview","actions","onDownload","onDelete","onPreview","previewOpen","setPreviewOpen","useState","resolvedFile","normalizeFileDisplayItem","handleDownload","handlePreview","defaultActions","Eye","Download","Trash2","allActions","typeName","getFileTypeName","jsxs","Fragment","jsx","classNames","styles","getFileIcon","formatFileSize","FileTags","action","Tooltip","Button","e","FilePreviewModal"],"mappings":";;;;;;;;;;;;AA8BA,MAAMA,IAAoC,CAAC;AAAA,EACzC,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,YAAAC,IAAa;AAAA,EACb,aAAAC,IAAc;AAAA,EACd,SAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AACF,MAAM;AACJ,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAAS,EAAK,GAC9CC,IAAeC,EAAyBb,CAAI,GAE5Cc,IAAiB,MAAM;AAC3B,QAAIR,GAAY;AACd,MAAAA,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EAAO;AAAA,YACb,SAAS,CAACG,MAAM;AACd,cAAAA,EAAE,gBAAA,GACFH,EAAO,QAAQnB,CAAY;AAAA,YAC7B;AAAA,UAAA;AAAA,QAAA,KARUmB,EAAO,GAUrB,CACD,EAAA,CACH;AAAA,MAAA,EAAA,CACF;AAAA,IAAA,EAAA,CACF,EAAA,CACF;AAAA,IACA,gBAAAN;AAAA,MAACU;AAAA,MAAA;AAAA,QACC,MAAM1B;AAAA,QACN,MAAMG;AAAA,QACN,KAAKA,EAAa;AAAA,QAClB,aAAaA,EAAa;AAAA,QAC1B,SAAS,MAAMF,EAAe,EAAK;AAAA,MAAA;AAAA,IAAA;AAAA,EACrC,GACF;AAEJ;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/File/FileItem/index.tsx"],"sourcesContent":["import { FileTags } from '@/components/Tag';\nimport { Trash2, Download, Eye } from '@/components/Icons';\nimport { formatFileSize } from '@/utils/format';\nimport { Button, Tooltip, message } from 'antd';\nimport React, { useState } from 'react';\nimport FilePreviewModal from '../FilePreviewModal';\nimport { getFileIcon, getFileTypeName, normalizeFileDisplayItem } from '../fileDisplay';\nimport type { FileDisplayItem } from '../types';\nimport { fetchWithMarsunAuth, useFileAuthHeaders } from '../utils/authedFetch';\nimport styles from './style.module.scss';\nimport classNames from 'classnames';\n\nexport interface FileItemAction {\n key: string;\n icon: React.ReactNode;\n tooltip: string;\n onClick: (file: FileDisplayItem) => void;\n}\n\nexport interface FileItemProps {\n file: FileDisplayItem;\n status?: React.ReactNode;\n showDownload?: boolean;\n showDelete?: boolean;\n showPreview?: boolean;\n actions?: FileItemAction[];\n onDownload?: (file: FileDisplayItem) => void;\n onDelete?: (file: FileDisplayItem) => void;\n onPreview?: (file: FileDisplayItem) => void;\n}\n\nconst FileItem: React.FC<FileItemProps> = ({\n file,\n status,\n showDownload = true,\n showDelete = false,\n showPreview = true,\n actions,\n onDownload,\n onDelete,\n onPreview,\n}) => {\n const [previewOpen, setPreviewOpen] = useState(false);\n const resolvedFile = normalizeFileDisplayItem(file);\n const authHeaders = useFileAuthHeaders();\n\n const handleDownload = () => {\n if (onDownload) {\n onDownload(resolvedFile);\n return;\n }\n if (!resolvedFile.url) return;\n void (async () => {\n try {\n const res = await fetchWithMarsunAuth(resolvedFile.url!, authHeaders);\n if (!res.ok) throw new Error(`下载失败 (${res.status})`);\n const blob = await res.blob();\n const blobUrl = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = blobUrl;\n a.download = resolvedFile.name || 'download';\n a.click();\n URL.revokeObjectURL(blobUrl);\n } catch (err) {\n message.error(err instanceof Error ? err.message : '下载失败');\n }\n })();\n };\n\n const handlePreview = () => {\n if (onPreview) onPreview(resolvedFile);\n else setPreviewOpen(true);\n };\n\n const defaultActions: FileItemAction[] = [];\n if (showPreview) {\n defaultActions.push({\n key: 'preview',\n icon: <Eye />,\n tooltip: '预览',\n onClick: () => handlePreview(),\n });\n }\n if (showDownload) {\n defaultActions.push({\n key: 'download',\n icon: <Download />,\n tooltip: '下载',\n onClick: () => handleDownload(),\n });\n }\n if (showDelete && onDelete) {\n defaultActions.push({\n key: 'delete',\n icon: <Trash2 />,\n tooltip: '删除',\n onClick: () => onDelete(resolvedFile),\n });\n }\n\n const allActions = [...defaultActions, ...(actions ?? [])];\n const typeName = getFileTypeName(resolvedFile.name, resolvedFile.mimeType);\n\n return (\n <>\n <div className={classNames('file-item-root', styles['file-item-root'])}>\n <div className={classNames('file-item-container', styles['file-item-container'])}>\n <div className={classNames('file-item-wrapper', styles['file-item-wrapper'])}>\n <span className={classNames('file-item-inner', styles['file-item-inner'])}>\n {getFileIcon(resolvedFile.name, resolvedFile.mimeType)}\n </span>\n <div className={classNames('file-item-header', styles['file-item-header'])}>\n <div className={classNames('file-item-body', styles['file-item-body'])}>\n <span\n className={classNames('file-item-footer', styles['file-item-footer'])}\n title={resolvedFile.name}\n >\n {resolvedFile.name}\n </span>\n <span className={classNames('file-item-row', styles['file-item-row'])}>\n {typeName}\n </span>\n {resolvedFile.size != null && (\n <span className={classNames('file-item-row', styles['file-item-row'])}>\n {formatFileSize(resolvedFile.size)}\n </span>\n )}\n </div>\n {resolvedFile.tags && resolvedFile.tags.length > 0 && (\n <FileTags\n tags={resolvedFile.tags}\n className={classNames('file-item-col', styles['file-item-col'])}\n />\n )}\n </div>\n </div>\n\n <div className={classNames('file-item-wrap', styles['file-item-wrap'])}>\n {status && (\n <span className={classNames('file-item-panel', styles['file-item-panel'])}>\n {status}\n </span>\n )}\n <div className={classNames('file-item-action-group', styles['file-item-action-group'])}>\n {allActions.map((action) => (\n <Tooltip key={action.key} title={action.tooltip}>\n <Button\n type=\"text\"\n size=\"small\"\n icon={action.icon}\n onClick={(e) => {\n e.stopPropagation();\n action.onClick(resolvedFile);\n }}\n />\n </Tooltip>\n ))}\n </div>\n </div>\n </div>\n </div>\n <FilePreviewModal\n open={previewOpen}\n file={resolvedFile}\n url={resolvedFile.url}\n downloadUrl={resolvedFile.url}\n onClose={() => setPreviewOpen(false)}\n />\n </>\n );\n};\n\nexport { FileItem };\nexport default FileItem;\n"],"names":["FileItem","file","status","showDownload","showDelete","showPreview","actions","onDownload","onDelete","onPreview","previewOpen","setPreviewOpen","useState","resolvedFile","normalizeFileDisplayItem","authHeaders","useFileAuthHeaders","handleDownload","res","fetchWithMarsunAuth","blob","blobUrl","a","err","message","handlePreview","defaultActions","Eye","Download","Trash2","allActions","typeName","getFileTypeName","jsxs","Fragment","jsx","classNames","styles","getFileIcon","formatFileSize","FileTags","action","Tooltip","Button","e","FilePreviewModal"],"mappings":";;;;;;;;;;;;;AA+BA,MAAMA,KAAoC,CAAC;AAAA,EACzC,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,YAAAC,IAAa;AAAA,EACb,aAAAC,IAAc;AAAA,EACd,SAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AACF,MAAM;AACJ,QAAM,CAACC,GAAaC,CAAc,IAA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C,MAAM3B,EAAa;AAAA,cACnB,WAAWuB,EAAW,iBAAiBC,EAAO,eAAe,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,QAChE,EAAA,CAEJ;AAAA,MAAA,GACF;AAAA,MAEA,gBAAAJ,EAAC,SAAI,WAAWG,EAAW,kBAAkBC,EAAO,gBAAgB,CAAC,GAClE,UAAA;AAAA,QAAAnC,KACC,gBAAAiC,EAAC,UAAK,WAAWC,EAAW,mBAAmBC,EAAO,iBAAiB,CAAC,GACrE,UAAAnC,EAAA,CACH;AAAA,0BAED,OAAA,EAAI,WAAWkC,EAAW,0BAA0BC,EAAO,wBAAwB,CAAC,GAClF,UAAAP,EAAW,IAAI,CAACW,wBACdC,GAAA,EAAyB,OAAOD,EAAO,SACtC,UAAA,gBAAAN;AAAA,UAACQ;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,MAAK;AAAA,YACL,MAAMF,EAAO;AAAA,YACb,SAAS,CAACG,MAAM;AACd,cAAAA,EAAE,gBAAA,GACFH,EAAO,QAAQ5B,CAAY;AAAA,YAC7B;AAAA,UAAA;AAAA,QAAA,KARU4B,EAAO,GAUrB,CACD,EAAA,CACH;AAAA,MAAA,EAAA,CACF;AAAA,IAAA,EAAA,CACF,EAAA,CACF;AAAA,IACA,gBAAAN;AAAA,MAACU;AAAA,MAAA;AAAA,QACC,MAAMnC;AAAA,QACN,MAAMG;AAAA,QACN,KAAKA,EAAa;AAAA,QAClB,aAAaA,EAAa;AAAA,QAC1B,SAAS,MAAMF,EAAe,EAAK;AAAA,MAAA;AAAA,IAAA;AAAA,EACrC,GACF;AAEJ;"}
@@ -1,97 +1,119 @@
1
- import { jsx as a } from "react/jsx-runtime";
2
- import { Empty as p, Spin as W } from "antd";
3
- import { useRef as y, useState as v, useEffect as N } from "react";
4
- import { getPreviewKind as b, needsBlobPreview as P } from "../previewKind.js";
5
- import c from "./style.module.scss.js";
6
- import B from "classnames";
7
- async function H(r) {
8
- const e = await fetch(r);
9
- if (!e.ok) throw new Error(`预览加载失败 (${e.status})`);
10
- return e.arrayBuffer();
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { Empty as h, Spin as g } from "antd";
3
+ import { useRef as N, useState as y, useEffect as A } from "react";
4
+ import { getPreviewKind as S, needsBlobPreview as T } from "../previewKind.js";
5
+ import { useFileAuthHeaders as H, useFileAuthHeaderKey as L, fetchAuthedObjectUrl as j, fetchAuthedArrayBuffer as B } from "../utils/authedFetch.js";
6
+ import l from "./style.module.scss.js";
7
+ import M from "classnames";
8
+ function C(r) {
9
+ const e = H(), t = L(), [o, a] = y(void 0), [n, d] = y(!1), [u, f] = y(null);
10
+ return A(() => {
11
+ if (!r) {
12
+ a(void 0), f(null), d(!1);
13
+ return;
14
+ }
15
+ let i = !1, v;
16
+ return d(!0), f(null), (async () => {
17
+ try {
18
+ const p = await j(r, e);
19
+ if (i) {
20
+ p.revoke();
21
+ return;
22
+ }
23
+ v = p.revoke, a(p.objectUrl);
24
+ } catch (p) {
25
+ i || (a(void 0), f(p instanceof Error ? p.message : "预览加载失败"));
26
+ } finally {
27
+ i || d(!1);
28
+ }
29
+ })(), () => {
30
+ i = !0, v == null || v();
31
+ };
32
+ }, [r, t]), { src: o, loading: n, error: u };
11
33
  }
12
- function h(r, e) {
34
+ function E(r, e) {
13
35
  const t = r instanceof Error ? r.message : String(r ?? "");
14
36
  return e === "excel" && /anchors/i.test(t) ? "该 Excel 含图表/绘图等对象,当前预览引擎无法解析,请下载后用本地软件打开" : e === "word" && /ole|compound|docfile|not a valid/i.test(t) ? "旧版 Word(.doc)暂无法排版预览,请下载后用 Word 打开" : t && !/^Cannot read properties/i.test(t) && !/^undefined/i.test(t) ? t : e === "excel" ? "Excel 预览失败,请下载后查看" : e === "word" ? "Word 预览失败,请下载后查看" : "预览加载失败";
15
37
  }
16
- async function L(r) {
38
+ async function D(r) {
17
39
  try {
18
- const { default: e } = await import("../../../_virtual/jszip.min.js").then((i) => i.j), t = await e.loadAsync(r), n = Object.keys(t.files), o = n.filter(
19
- (i) => i.startsWith("xl/drawings/") || i.startsWith("xl/charts/") || i.startsWith("xl/diagrams/") || /drawing[0-9]*\.xml$/i.test(i)
40
+ const { default: e } = await import("../../../_virtual/jszip.min.js").then((n) => n.j), t = await e.loadAsync(r), o = Object.keys(t.files), a = o.filter(
41
+ (n) => n.startsWith("xl/drawings/") || n.startsWith("xl/charts/") || n.startsWith("xl/diagrams/") || /drawing[0-9]*\.xml$/i.test(n)
20
42
  );
21
- if (o.length === 0) return null;
22
- for (const i of o)
23
- t.remove(i);
43
+ if (a.length === 0) return null;
44
+ for (const n of a)
45
+ t.remove(n);
24
46
  return await Promise.all(
25
- n.filter((i) => /^xl\/worksheets\/[^/]+\.xml$/i.test(i) && t.file(i)).map(async (i) => {
26
- const w = t.file(i);
27
- if (!w) return;
28
- const d = await w.async("string"), f = d.replace(/<drawing[^>]*\/>/gi, "").replace(/<drawing[^>]*>[\s\S]*?<\/drawing>/gi, "");
29
- f !== d && t.file(i, f);
47
+ o.filter((n) => /^xl\/worksheets\/[^/]+\.xml$/i.test(n) && t.file(n)).map(async (n) => {
48
+ const d = t.file(n);
49
+ if (!d) return;
50
+ const u = await d.async("string"), f = u.replace(/<drawing[^>]*\/>/gi, "").replace(/<drawing[^>]*>[\s\S]*?<\/drawing>/gi, "");
51
+ f !== u && t.file(n, f);
30
52
  })
31
53
  ), t.generateAsync({ type: "arraybuffer" });
32
54
  } catch {
33
55
  return null;
34
56
  }
35
57
  }
36
- async function x(r, e, t) {
37
- const n = r.init(e);
58
+ async function b(r, e, t) {
59
+ const o = r.init(e);
38
60
  try {
39
- return await n.preview(t), () => n.destroy();
40
- } catch (o) {
61
+ return await o.preview(t), () => o.destroy();
62
+ } catch (a) {
41
63
  try {
42
- n.destroy();
64
+ o.destroy();
43
65
  } catch {
44
66
  }
45
- throw o;
67
+ throw a;
46
68
  }
47
69
  }
48
- async function T(r, e) {
49
- var o;
70
+ async function K(r, e) {
71
+ var a;
50
72
  const [{ default: t }] = await Promise.all([
51
73
  import("@js-preview/excel"),
52
74
  Promise.resolve({ })
53
- ]), n = Math.max(
54
- ((o = r.parentElement) == null ? void 0 : o.clientHeight) ?? 0,
75
+ ]), o = Math.max(
76
+ ((a = r.parentElement) == null ? void 0 : a.clientHeight) ?? 0,
55
77
  Math.round(window.innerHeight * 0.65),
56
78
  480
57
79
  );
58
- r.style.height = `${n}px`;
80
+ r.style.height = `${o}px`;
59
81
  try {
60
- return await x(t, r, e);
61
- } catch (i) {
62
- const w = i instanceof Error ? i.message : String(i ?? "");
63
- if (!/anchors/i.test(w))
64
- throw i instanceof Error ? i : new Error(h(i, "excel"));
65
- const d = await L(e);
66
- if (!d)
67
- throw i instanceof Error ? i : new Error(h(i, "excel"));
82
+ return await b(t, r, e);
83
+ } catch (n) {
84
+ const d = n instanceof Error ? n.message : String(n ?? "");
85
+ if (!/anchors/i.test(d))
86
+ throw n instanceof Error ? n : new Error(E(n, "excel"));
87
+ const u = await D(e);
88
+ if (!u)
89
+ throw n instanceof Error ? n : new Error(E(n, "excel"));
68
90
  r.innerHTML = "";
69
91
  try {
70
- return await x(t, r, d);
92
+ return await b(t, r, u);
71
93
  } catch (f) {
72
- throw f instanceof Error ? f : new Error(h(f, "excel"));
94
+ throw f instanceof Error ? f : new Error(E(f, "excel"));
73
95
  }
74
96
  }
75
97
  }
76
- function S(r) {
98
+ function O(r) {
77
99
  const e = new Uint8Array(r);
78
100
  return e.length >= 2 && e[0] === 80 && e[1] === 75;
79
101
  }
80
- function A(r) {
102
+ function k(r) {
81
103
  const e = new Uint8Array(r);
82
104
  return e.length >= 4 && e[0] === 208 && e[1] === 207 && e[2] === 17 && e[3] === 224;
83
105
  }
84
- function M(r) {
106
+ function F(r) {
85
107
  const e = new Uint8Array(r.byteLength > 64 ? r.slice(0, 64) : r);
86
108
  let t = 0;
87
109
  e.length >= 3 && e[0] === 239 && e[1] === 187 && e[2] === 191 && (t = 3);
88
- const n = new TextDecoder("utf-8").decode(e.subarray(t)).trimStart().toLowerCase();
89
- return n.startsWith("<!doctype") || n.startsWith("<html") || n.startsWith("<pre") || n.startsWith("<div") || n.startsWith("<article");
110
+ const o = new TextDecoder("utf-8").decode(e.subarray(t)).trimStart().toLowerCase();
111
+ return o.startsWith("<!doctype") || o.startsWith("<html") || o.startsWith("<pre") || o.startsWith("<div") || o.startsWith("<article");
90
112
  }
91
- async function C(r, e) {
92
- if (S(e)) {
93
- const { renderAsync: t } = await import("docx-preview"), n = new Blob([e]);
94
- await t(n, r, r, {
113
+ async function $(r, e) {
114
+ if (O(e)) {
115
+ const { renderAsync: t } = await import("docx-preview"), o = new Blob([e]);
116
+ await t(o, r, r, {
95
117
  inWrapper: !0,
96
118
  ignoreWidth: !1,
97
119
  ignoreHeight: !1,
@@ -99,64 +121,66 @@ async function C(r, e) {
99
121
  });
100
122
  return;
101
123
  }
102
- if (M(e)) {
124
+ if (F(e)) {
103
125
  r.innerHTML = new TextDecoder("utf-8").decode(e);
104
126
  return;
105
127
  }
106
- throw A(e) ? new Error("旧版 Word(.doc)暂无法排版预览,请下载后用 Word 打开") : new Error("无法识别的 Word 文件格式,请下载后查看");
128
+ throw k(e) ? new Error("旧版 Word(.doc)暂无法排版预览,请下载后用 Word 打开") : new Error("无法识别的 Word 文件格式,请下载后查看");
107
129
  }
108
- async function j(r, e, t) {
109
- const { init: n } = await import("pptx-preview"), o = n(r, { width: t, height: Math.round(t * 0.5625), mode: "list" });
110
- return await o.preview(e), () => o.destroy();
130
+ async function Z(r, e, t) {
131
+ const { init: o } = await import("pptx-preview"), a = o(r, { width: t, height: Math.round(t * 0.5625), mode: "list" });
132
+ return await a.preview(e), () => a.destroy();
111
133
  }
112
- function D(r, e) {
113
- const t = new TextDecoder("utf-8"), n = document.createElement("pre");
114
- n.className = c["file-preview-text"], n.textContent = t.decode(e), r.appendChild(n);
134
+ function z(r, e) {
135
+ const t = new TextDecoder("utf-8"), o = document.createElement("pre");
136
+ o.className = l["file-preview-text"], o.textContent = t.decode(e), r.appendChild(o);
115
137
  }
116
- const K = ({
138
+ const Y = ({
117
139
  file: r,
118
140
  previewUrl: e,
119
141
  unsupportedMessage: t = "暂不支持预览此文件类型"
120
142
  }) => {
121
- const n = y(null), o = y(void 0), [i, w] = v(!1), [d, f] = v(null), s = b(r);
122
- return N(() => {
123
- var g;
124
- const u = n.current;
125
- if (!u || !e) return;
126
- let m = !1;
127
- return (g = o.current) == null || g.call(o), o.current = void 0, u.innerHTML = "", f(null), (async () => {
128
- if (s !== "image" && !(s === "pdf" || s === "iframe") && !(s === "video" || s === "audio") && s !== "unsupported") {
129
- w(!0);
143
+ const o = N(null), a = N(void 0), [n, d] = y(!1), [u, f] = y(null), i = S(r), v = H(), p = L(), c = C(
144
+ i === "image" || i === "pdf" || i === "iframe" || i === "video" || i === "audio" ? e : void 0
145
+ );
146
+ return A(() => {
147
+ var W;
148
+ const w = o.current;
149
+ if (!w || !e) return;
150
+ let x = !1;
151
+ return (W = a.current) == null || W.call(a), a.current = void 0, w.innerHTML = "", f(null), (async () => {
152
+ if (i !== "image" && !(i === "pdf" || i === "iframe") && !(i === "video" || i === "audio") && i !== "unsupported") {
153
+ d(!0);
130
154
  try {
131
- const l = await H(e);
132
- if (m) return;
133
- if (s === "excel")
134
- o.current = await T(u, l);
135
- else if (s === "word")
136
- await C(u, l);
137
- else if (s === "ppt") {
138
- const E = u.clientWidth || 852;
139
- o.current = await j(u, l, E);
140
- } else s === "text" && D(u, l);
141
- } catch (l) {
142
- m || f(h(l, s));
155
+ const m = await B(e, v);
156
+ if (x) return;
157
+ if (i === "excel")
158
+ a.current = await K(w, m);
159
+ else if (i === "word")
160
+ await $(w, m);
161
+ else if (i === "ppt") {
162
+ const P = w.clientWidth || 852;
163
+ a.current = await Z(w, m, P);
164
+ } else i === "text" && z(w, m);
165
+ } catch (m) {
166
+ x || f(E(m, i));
143
167
  } finally {
144
- m || w(!1);
168
+ x || d(!1);
145
169
  }
146
170
  }
147
171
  })(), () => {
148
- var l;
149
- m = !0, (l = o.current) == null || l.call(o), o.current = void 0, u.innerHTML = "";
172
+ var m;
173
+ x = !0, (m = a.current) == null || m.call(a), a.current = void 0, w.innerHTML = "";
150
174
  };
151
- }, [e, s, r.id, r.name]), e ? s === "image" ? /* @__PURE__ */ a("div", { className: c["file-preview-media-wrap"], children: /* @__PURE__ */ a("img", { src: e, alt: r.name, className: c["file-preview-image"] }) }) : s === "pdf" || s === "iframe" ? /* @__PURE__ */ a("iframe", { src: e, title: r.name, className: c["file-preview-iframe"] }) : s === "video" ? /* @__PURE__ */ a("div", { className: c["file-preview-media-wrap"], children: /* @__PURE__ */ a("video", { src: e, controls: !0, className: c["file-preview-video"] }) }) : s === "audio" ? /* @__PURE__ */ a("div", { className: c["file-preview-audio-wrap"], children: /* @__PURE__ */ a("audio", { src: e, controls: !0, className: c["file-preview-audio"] }) }) : s === "unsupported" ? /* @__PURE__ */ a(p, { description: t }) : P(s) ? /* @__PURE__ */ a(
175
+ }, [e, i, r.id, r.name, p]), e ? i === "image" ? c.loading ? /* @__PURE__ */ s("div", { className: l["file-preview-media-wrap"], children: /* @__PURE__ */ s(g, {}) }) : c.error || !c.src ? /* @__PURE__ */ s(h, { description: c.error || "预览加载失败" }) : /* @__PURE__ */ s("div", { className: l["file-preview-media-wrap"], children: /* @__PURE__ */ s("img", { src: c.src, alt: r.name, className: l["file-preview-image"] }) }) : i === "pdf" || i === "iframe" ? c.loading ? /* @__PURE__ */ s("div", { className: l["file-preview-media-wrap"], children: /* @__PURE__ */ s(g, {}) }) : c.error || !c.src ? /* @__PURE__ */ s(h, { description: c.error || "预览加载失败" }) : /* @__PURE__ */ s("iframe", { src: c.src, title: r.name, className: l["file-preview-iframe"] }) : i === "video" ? c.loading ? /* @__PURE__ */ s("div", { className: l["file-preview-media-wrap"], children: /* @__PURE__ */ s(g, {}) }) : c.error || !c.src ? /* @__PURE__ */ s(h, { description: c.error || "预览加载失败" }) : /* @__PURE__ */ s("div", { className: l["file-preview-media-wrap"], children: /* @__PURE__ */ s("video", { src: c.src, controls: !0, className: l["file-preview-video"] }) }) : i === "audio" ? c.loading ? /* @__PURE__ */ s("div", { className: l["file-preview-audio-wrap"], children: /* @__PURE__ */ s(g, {}) }) : c.error || !c.src ? /* @__PURE__ */ s(h, { description: c.error || "预览加载失败" }) : /* @__PURE__ */ s("div", { className: l["file-preview-audio-wrap"], children: /* @__PURE__ */ s("audio", { src: c.src, controls: !0, className: l["file-preview-audio"] }) }) : i === "unsupported" ? /* @__PURE__ */ s(h, { description: t }) : T(i) ? /* @__PURE__ */ s(
152
176
  "div",
153
177
  {
154
- className: B(c["file-preview-office"], c["file-preview-office-wrap"]),
155
- children: /* @__PURE__ */ a(W, { spinning: i, classNames: { root: c["file-preview-office-spin"] }, children: d ? /* @__PURE__ */ a(p, { description: d }) : /* @__PURE__ */ a("div", { ref: n, className: c["file-preview-office-inner"] }) })
178
+ className: M(l["file-preview-office"], l["file-preview-office-wrap"]),
179
+ children: /* @__PURE__ */ s(g, { spinning: n, classNames: { root: l["file-preview-office-spin"] }, children: u ? /* @__PURE__ */ s(h, { description: u }) : /* @__PURE__ */ s("div", { ref: o, className: l["file-preview-office-inner"] }) })
156
180
  }
157
- ) : /* @__PURE__ */ a(p, { description: t }) : /* @__PURE__ */ a(p, { description: "无可预览地址" });
181
+ ) : /* @__PURE__ */ s(h, { description: t }) : /* @__PURE__ */ s(h, { description: "无可预览地址" });
158
182
  };
159
183
  export {
160
- K as default
184
+ Y as default
161
185
  };
162
186
  //# sourceMappingURL=FilePreviewContent.js.map