@hkyhy/marsun-components-core 0.1.62 → 0.1.65
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/components/File/FilePreview/FilePreviewContent.js +98 -75
- package/dist/components/File/FilePreview/FilePreviewContent.js.map +1 -1
- package/dist/components/Form/index.d.ts +1 -0
- package/dist/components/Form/kneFormInfo.d.ts +7 -1
- package/dist/components/Form/kneFormInfo.js +39 -21
- package/dist/components/Form/kneFormInfo.js.map +1 -1
- package/dist/components/Form/normalizeLabelTips.d.ts +14 -0
- package/dist/components/Form/normalizeLabelTips.js +40 -0
- package/dist/components/Form/normalizeLabelTips.js.map +1 -0
- package/dist/components/StateBar/StateBar.d.ts +17 -2
- package/dist/components/StateBar/StateBar.js +74 -33
- package/dist/components/StateBar/StateBar.js.map +1 -1
- package/dist/components/StateBar/index.d.ts +1 -1
- package/dist/components/StateBar/style.module.scss.js +10 -8
- package/dist/components/StateBar/style.module.scss.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +627 -622
- package/dist/index.js.map +1 -1
- package/dist/marsun-components-core.css +1 -1
- package/dist/styles/global.css +1 -1
- package/dist/utils/user/employeeId.d.ts +10 -2
- package/dist/utils/user/employeeId.js +11 -9
- package/dist/utils/user/employeeId.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Empty as p, Spin as
|
|
3
|
-
import { useRef as
|
|
4
|
-
import { getPreviewKind as b, needsBlobPreview as
|
|
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
5
|
import c from "./style.module.scss.js";
|
|
6
|
-
import
|
|
7
|
-
async function
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
return
|
|
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();
|
|
11
11
|
}
|
|
12
|
-
function h(
|
|
13
|
-
const t =
|
|
14
|
-
return
|
|
12
|
+
function h(r, e) {
|
|
13
|
+
const t = r instanceof Error ? r.message : String(r ?? "");
|
|
14
|
+
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
15
|
}
|
|
16
|
-
async function
|
|
16
|
+
async function L(r) {
|
|
17
17
|
try {
|
|
18
|
-
const { default:
|
|
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
19
|
(i) => i.startsWith("xl/drawings/") || i.startsWith("xl/charts/") || i.startsWith("xl/diagrams/") || /drawing[0-9]*\.xml$/i.test(i)
|
|
20
20
|
);
|
|
21
|
-
if (
|
|
22
|
-
for (const i of
|
|
21
|
+
if (o.length === 0) return null;
|
|
22
|
+
for (const i of o)
|
|
23
23
|
t.remove(i);
|
|
24
24
|
return await Promise.all(
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
const d = await
|
|
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
29
|
f !== d && t.file(i, f);
|
|
30
30
|
})
|
|
31
31
|
), t.generateAsync({ type: "arraybuffer" });
|
|
@@ -33,107 +33,130 @@ async function B(e) {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
async function x(
|
|
37
|
-
const
|
|
36
|
+
async function x(r, e, t) {
|
|
37
|
+
const n = r.init(e);
|
|
38
38
|
try {
|
|
39
|
-
return await
|
|
40
|
-
} catch (
|
|
39
|
+
return await n.preview(t), () => n.destroy();
|
|
40
|
+
} catch (o) {
|
|
41
41
|
try {
|
|
42
|
-
|
|
42
|
+
n.destroy();
|
|
43
43
|
} catch {
|
|
44
44
|
}
|
|
45
|
-
throw
|
|
45
|
+
throw o;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
async function
|
|
49
|
-
var
|
|
48
|
+
async function T(r, e) {
|
|
49
|
+
var o;
|
|
50
50
|
const [{ default: t }] = await Promise.all([
|
|
51
51
|
import("@js-preview/excel"),
|
|
52
52
|
Promise.resolve({ })
|
|
53
|
-
]),
|
|
54
|
-
((
|
|
53
|
+
]), n = Math.max(
|
|
54
|
+
((o = r.parentElement) == null ? void 0 : o.clientHeight) ?? 0,
|
|
55
55
|
Math.round(window.innerHeight * 0.65),
|
|
56
56
|
480
|
|
57
57
|
);
|
|
58
|
-
|
|
58
|
+
r.style.height = `${n}px`;
|
|
59
59
|
try {
|
|
60
|
-
return await x(t,
|
|
60
|
+
return await x(t, r, e);
|
|
61
61
|
} catch (i) {
|
|
62
|
-
const
|
|
63
|
-
if (!/anchors/i.test(
|
|
62
|
+
const w = i instanceof Error ? i.message : String(i ?? "");
|
|
63
|
+
if (!/anchors/i.test(w))
|
|
64
64
|
throw i instanceof Error ? i : new Error(h(i, "excel"));
|
|
65
|
-
const d = await
|
|
65
|
+
const d = await L(e);
|
|
66
66
|
if (!d)
|
|
67
67
|
throw i instanceof Error ? i : new Error(h(i, "excel"));
|
|
68
|
-
|
|
68
|
+
r.innerHTML = "";
|
|
69
69
|
try {
|
|
70
|
-
return await x(t,
|
|
70
|
+
return await x(t, r, d);
|
|
71
71
|
} catch (f) {
|
|
72
72
|
throw f instanceof Error ? f : new Error(h(f, "excel"));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
inWrapper: !0,
|
|
80
|
-
ignoreWidth: !1,
|
|
81
|
-
ignoreHeight: !1,
|
|
82
|
-
breakPages: !0
|
|
83
|
-
});
|
|
76
|
+
function S(r) {
|
|
77
|
+
const e = new Uint8Array(r);
|
|
78
|
+
return e.length >= 2 && e[0] === 80 && e[1] === 75;
|
|
84
79
|
}
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
return
|
|
80
|
+
function A(r) {
|
|
81
|
+
const e = new Uint8Array(r);
|
|
82
|
+
return e.length >= 4 && e[0] === 208 && e[1] === 207 && e[2] === 17 && e[3] === 224;
|
|
88
83
|
}
|
|
89
|
-
function
|
|
90
|
-
const
|
|
91
|
-
|
|
84
|
+
function M(r) {
|
|
85
|
+
const e = new Uint8Array(r.byteLength > 64 ? r.slice(0, 64) : r);
|
|
86
|
+
let t = 0;
|
|
87
|
+
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");
|
|
92
90
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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, {
|
|
95
|
+
inWrapper: !0,
|
|
96
|
+
ignoreWidth: !1,
|
|
97
|
+
ignoreHeight: !1,
|
|
98
|
+
breakPages: !0
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (M(e)) {
|
|
103
|
+
r.innerHTML = new TextDecoder("utf-8").decode(e);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
throw A(e) ? new Error("旧版 Word(.doc)暂无法排版预览,请下载后用 Word 打开") : new Error("无法识别的 Word 文件格式,请下载后查看");
|
|
107
|
+
}
|
|
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();
|
|
111
|
+
}
|
|
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);
|
|
115
|
+
}
|
|
116
|
+
const K = ({
|
|
117
|
+
file: r,
|
|
118
|
+
previewUrl: e,
|
|
96
119
|
unsupportedMessage: t = "暂不支持预览此文件类型"
|
|
97
120
|
}) => {
|
|
98
|
-
const
|
|
99
|
-
return
|
|
121
|
+
const n = y(null), o = y(void 0), [i, w] = v(!1), [d, f] = v(null), s = b(r);
|
|
122
|
+
return N(() => {
|
|
100
123
|
var g;
|
|
101
|
-
const u =
|
|
102
|
-
if (!u || !
|
|
103
|
-
let
|
|
104
|
-
return (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 () => {
|
|
105
128
|
if (s !== "image" && !(s === "pdf" || s === "iframe") && !(s === "video" || s === "audio") && s !== "unsupported") {
|
|
106
|
-
|
|
129
|
+
w(!0);
|
|
107
130
|
try {
|
|
108
|
-
const l = await
|
|
109
|
-
if (
|
|
131
|
+
const l = await H(e);
|
|
132
|
+
if (m) return;
|
|
110
133
|
if (s === "excel")
|
|
111
|
-
|
|
134
|
+
o.current = await T(u, l);
|
|
112
135
|
else if (s === "word")
|
|
113
|
-
await
|
|
136
|
+
await C(u, l);
|
|
114
137
|
else if (s === "ppt") {
|
|
115
138
|
const E = u.clientWidth || 852;
|
|
116
|
-
|
|
117
|
-
} else s === "text" &&
|
|
139
|
+
o.current = await j(u, l, E);
|
|
140
|
+
} else s === "text" && D(u, l);
|
|
118
141
|
} catch (l) {
|
|
119
|
-
|
|
142
|
+
m || f(h(l, s));
|
|
120
143
|
} finally {
|
|
121
|
-
|
|
144
|
+
m || w(!1);
|
|
122
145
|
}
|
|
123
146
|
}
|
|
124
147
|
})(), () => {
|
|
125
148
|
var l;
|
|
126
|
-
|
|
149
|
+
m = !0, (l = o.current) == null || l.call(o), o.current = void 0, u.innerHTML = "";
|
|
127
150
|
};
|
|
128
|
-
}, [
|
|
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(
|
|
129
152
|
"div",
|
|
130
153
|
{
|
|
131
|
-
className:
|
|
132
|
-
children: /* @__PURE__ */
|
|
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"] }) })
|
|
133
156
|
}
|
|
134
|
-
) : /* @__PURE__ */
|
|
157
|
+
) : /* @__PURE__ */ a(p, { description: t }) : /* @__PURE__ */ a(p, { description: "无可预览地址" });
|
|
135
158
|
};
|
|
136
159
|
export {
|
|
137
|
-
|
|
160
|
+
K as default
|
|
138
161
|
};
|
|
139
162
|
//# sourceMappingURL=FilePreviewContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilePreviewContent.js","sources":["../../../../src/components/File/FilePreview/FilePreviewContent.tsx"],"sourcesContent":["import { Empty, Spin } from 'antd';\nimport React, { useEffect, useRef, useState } from 'react';\nimport { getPreviewKind, needsBlobPreview } from '../previewKind';\nimport type { FileDisplayItem } from '../types';\nimport styles from './style.module.scss';\nimport classNames from 'classnames';\n\ninterface FilePreviewContentProps {\n file: FileDisplayItem;\n previewUrl?: string;\n unsupportedMessage?: string;\n}\n\nasync function fetchPreviewBlob(url: string): Promise<ArrayBuffer> {\n const res = await fetch(url);\n if (!res.ok) throw new Error(`预览加载失败 (${res.status})`);\n return res.arrayBuffer();\n}\n\nfunction mapPreviewError(err: unknown, kind: string): string {\n const raw = err instanceof Error ? err.message : String(err ?? '');\n if (kind === 'excel' && /anchors/i.test(raw)) {\n return '该 Excel 含图表/绘图等对象,当前预览引擎无法解析,请下载后用本地软件打开';\n }\n if (raw && !/^Cannot read properties/i.test(raw) && !/^undefined/i.test(raw)) {\n return raw;\n }\n return kind === 'excel' ? 'Excel 预览失败,请下载后查看' : '预览加载失败';\n}\n\n/** exceljs/@js-preview 对部分含 drawing/chart 的 xlsx 会在 reconcile 时读 anchors 崩溃;去掉绘图部件后重试。 */\nasync function stripExcelDrawings(data: ArrayBuffer): Promise<ArrayBuffer | null> {\n try {\n const { default: JSZip } = await import('jszip');\n const zip = await JSZip.loadAsync(data);\n const names = Object.keys(zip.files);\n const drop = names.filter(\n (n) =>\n n.startsWith('xl/drawings/') ||\n n.startsWith('xl/charts/') ||\n n.startsWith('xl/diagrams/') ||\n /drawing[0-9]*\\.xml$/i.test(n),\n );\n if (drop.length === 0) return null;\n for (const n of drop) {\n zip.remove(n);\n }\n // 清理 worksheet 中的 drawing 引用,避免指向已删部件\n await Promise.all(\n names\n .filter((n) => /^xl\\/worksheets\\/[^/]+\\.xml$/i.test(n) && zip.file(n))\n .map(async (n) => {\n const file = zip.file(n);\n if (!file) return;\n const xml = await file.async('string');\n const cleaned = xml\n .replace(/<drawing[^>]*\\/>/gi, '')\n .replace(/<drawing[^>]*>[\\s\\S]*?<\\/drawing>/gi, '');\n if (cleaned !== xml) zip.file(n, cleaned);\n }),\n );\n return zip.generateAsync({ type: 'arraybuffer' });\n } catch {\n return null;\n }\n}\n\nasync function previewExcelBuffer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n jsPreviewExcel: { init: (el: HTMLElement) => any },\n container: HTMLElement,\n data: ArrayBuffer,\n) {\n const instance = jsPreviewExcel.init(container);\n try {\n await instance.preview(data);\n return () => instance.destroy();\n } catch (err) {\n try {\n instance.destroy();\n } catch {\n // ignore\n }\n throw err;\n }\n}\n\nasync function renderExcel(container: HTMLElement, data: ArrayBuffer) {\n const [{ default: jsPreviewExcel }] = await Promise.all([\n import('@js-preview/excel'),\n import('@js-preview/excel/lib/index.css'),\n ]);\n const height = Math.max(\n container.parentElement?.clientHeight ?? 0,\n Math.round(window.innerHeight * 0.65),\n 480,\n );\n container.style.height = `${height}px`;\n\n try {\n return await previewExcelBuffer(jsPreviewExcel, container, data);\n } catch (firstErr) {\n const msg = firstErr instanceof Error ? firstErr.message : String(firstErr ?? '');\n if (!/anchors/i.test(msg)) {\n throw firstErr instanceof Error ? firstErr : new Error(mapPreviewError(firstErr, 'excel'));\n }\n const stripped = await stripExcelDrawings(data);\n if (!stripped) {\n throw firstErr instanceof Error ? firstErr : new Error(mapPreviewError(firstErr, 'excel'));\n }\n container.innerHTML = '';\n try {\n return await previewExcelBuffer(jsPreviewExcel, container, stripped);\n } catch (retryErr) {\n throw retryErr instanceof Error ? retryErr : new Error(mapPreviewError(retryErr, 'excel'));\n }\n }\n}\n\nasync function renderWord(container: HTMLElement, data: ArrayBuffer) {\n const { renderAsync } = await import('docx-preview');\n const blob = new Blob([data]);\n await renderAsync(blob, container, container, {\n inWrapper: true,\n ignoreWidth: false,\n ignoreHeight: false,\n breakPages: true,\n });\n}\n\nasync function renderPpt(container: HTMLElement, data: ArrayBuffer, width: number) {\n const { init } = await import('pptx-preview');\n const previewer = init(container, { width, height: Math.round(width * 0.5625), mode: 'list' });\n await previewer.preview(data);\n return () => previewer.destroy();\n}\n\nfunction renderText(container: HTMLElement, data: ArrayBuffer) {\n const decoder = new TextDecoder('utf-8');\n const pre = document.createElement('pre');\n pre.className = styles['file-preview-text'] ?? '';\n pre.textContent = decoder.decode(data);\n container.appendChild(pre);\n}\n\nconst FilePreviewContent: React.FC<FilePreviewContentProps> = ({\n file,\n previewUrl,\n unsupportedMessage = '暂不支持预览此文件类型',\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const cleanupRef = useRef<(() => void) | void>(undefined);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const kind = getPreviewKind(file);\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container || !previewUrl) return undefined;\n\n let cancelled = false;\n cleanupRef.current?.();\n cleanupRef.current = undefined;\n container.innerHTML = '';\n setError(null);\n\n const run = async () => {\n if (kind === 'image') return;\n if (kind === 'pdf' || kind === 'iframe') return;\n if (kind === 'video' || kind === 'audio') return;\n if (kind === 'unsupported') return;\n\n setLoading(true);\n try {\n const data = await fetchPreviewBlob(previewUrl);\n if (cancelled) return;\n\n if (kind === 'excel') {\n cleanupRef.current = await renderExcel(container, data);\n } else if (kind === 'word') {\n await renderWord(container, data);\n } else if (kind === 'ppt') {\n const width = container.clientWidth || 852;\n cleanupRef.current = await renderPpt(container, data, width);\n } else if (kind === 'text') {\n renderText(container, data);\n }\n } catch (err) {\n if (!cancelled) {\n setError(mapPreviewError(err, kind));\n }\n } finally {\n if (!cancelled) setLoading(false);\n }\n };\n\n void run();\n\n return () => {\n cancelled = true;\n cleanupRef.current?.();\n cleanupRef.current = undefined;\n container.innerHTML = '';\n };\n }, [previewUrl, kind, file.id, file.name]);\n\n if (!previewUrl) {\n return <Empty description=\"无可预览地址\" />;\n }\n\n if (kind === 'image') {\n return (\n <div className={styles['file-preview-media-wrap']}>\n <img src={previewUrl} alt={file.name} className={styles['file-preview-image']} />\n </div>\n );\n }\n\n if (kind === 'pdf' || kind === 'iframe') {\n return <iframe src={previewUrl} title={file.name} className={styles['file-preview-iframe']} />;\n }\n\n if (kind === 'video') {\n return (\n <div className={styles['file-preview-media-wrap']}>\n <video src={previewUrl} controls className={styles['file-preview-video']} />\n </div>\n );\n }\n\n if (kind === 'audio') {\n return (\n <div className={styles['file-preview-audio-wrap']}>\n <audio src={previewUrl} controls className={styles['file-preview-audio']} />\n </div>\n );\n }\n\n if (kind === 'unsupported') {\n return <Empty description={unsupportedMessage} />;\n }\n\n if (needsBlobPreview(kind)) {\n return (\n <div\n className={classNames(styles['file-preview-office'], styles['file-preview-office-wrap'])}\n >\n <Spin spinning={loading} classNames={{ root: styles['file-preview-office-spin'] }}>\n {error ? (\n <Empty description={error} />\n ) : (\n <div ref={containerRef} className={styles['file-preview-office-inner']} />\n )}\n </Spin>\n </div>\n );\n }\n\n return <Empty description={unsupportedMessage} />;\n};\n\nexport default FilePreviewContent;\n"],"names":["fetchPreviewBlob","url","res","mapPreviewError","err","kind","raw","stripExcelDrawings","data","JSZip","n","zip","names","drop","file","xml","cleaned","previewExcelBuffer","jsPreviewExcel","container","instance","renderExcel","height","_a","firstErr","msg","stripped","retryErr","renderWord","renderAsync","blob","renderPpt","width","init","previewer","renderText","decoder","pre","styles","FilePreviewContent","previewUrl","unsupportedMessage","containerRef","useRef","cleanupRef","loading","setLoading","useState","error","setError","getPreviewKind","useEffect","cancelled","jsx","Empty","needsBlobPreview","classNames","Spin"],"mappings":";;;;;;AAaA,eAAeA,EAAiBC,GAAmC;AACjE,QAAMC,IAAM,MAAM,MAAMD,CAAG;AAC3B,MAAI,CAACC,EAAI,GAAI,OAAM,IAAI,MAAM,WAAWA,EAAI,MAAM,GAAG;AACrD,SAAOA,EAAI,YAAA;AACb;AAEA,SAASC,EAAgBC,GAAcC,GAAsB;AAC3D,QAAMC,IAAMF,aAAe,QAAQA,EAAI,UAAU,OAAOA,KAAO,EAAE;AACjE,SAAIC,MAAS,WAAW,WAAW,KAAKC,CAAG,IAClC,6CAELA,KAAO,CAAC,2BAA2B,KAAKA,CAAG,KAAK,CAAC,cAAc,KAAKA,CAAG,IAClEA,IAEFD,MAAS,UAAU,sBAAsB;AAClD;AAGA,eAAeE,EAAmBC,GAAgD;AAChF,MAAI;AACF,UAAM,EAAE,SAASC,MAAU,MAAM,OAAO,gCAAO,EAAA,KAAA,CAAAC,MAAAA,EAAA,CAAA,GACzCC,IAAM,MAAMF,EAAM,UAAUD,CAAI,GAChCI,IAAQ,OAAO,KAAKD,EAAI,KAAK,GAC7BE,IAAOD,EAAM;AAAA,MACjB,CAACF,MACCA,EAAE,WAAW,cAAc,KAC3BA,EAAE,WAAW,YAAY,KACzBA,EAAE,WAAW,cAAc,KAC3B,uBAAuB,KAAKA,CAAC;AAAA,IAAA;AAEjC,QAAIG,EAAK,WAAW,EAAG,QAAO;AAC9B,eAAWH,KAAKG;AACd,MAAAF,EAAI,OAAOD,CAAC;AAGd,iBAAM,QAAQ;AAAA,MACZE,EACG,OAAO,CAACF,MAAM,gCAAgC,KAAKA,CAAC,KAAKC,EAAI,KAAKD,CAAC,CAAC,EACpE,IAAI,OAAOA,MAAM;AAChB,cAAMI,IAAOH,EAAI,KAAKD,CAAC;AACvB,YAAI,CAACI,EAAM;AACX,cAAMC,IAAM,MAAMD,EAAK,MAAM,QAAQ,GAC/BE,IAAUD,EACb,QA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ilePreview/FilePreviewContent.tsx"],"sourcesContent":["import { Empty, Spin } from 'antd';\nimport React, { useEffect, useRef, useState } from 'react';\nimport { getPreviewKind, needsBlobPreview } from '../previewKind';\nimport type { FileDisplayItem } from '../types';\nimport styles from './style.module.scss';\nimport classNames from 'classnames';\n\ninterface FilePreviewContentProps {\n file: FileDisplayItem;\n previewUrl?: string;\n unsupportedMessage?: string;\n}\n\nasync function fetchPreviewBlob(url: string): Promise<ArrayBuffer> {\n const res = await fetch(url);\n if (!res.ok) throw new Error(`预览加载失败 (${res.status})`);\n return res.arrayBuffer();\n}\n\nfunction mapPreviewError(err: unknown, kind: string): string {\n const raw = err instanceof Error ? err.message : String(err ?? '');\n if (kind === 'excel' && /anchors/i.test(raw)) {\n return '该 Excel 含图表/绘图等对象,当前预览引擎无法解析,请下载后用本地软件打开';\n }\n if (kind === 'word' && /ole|compound|docfile|not a valid/i.test(raw)) {\n return '旧版 Word(.doc)暂无法排版预览,请下载后用 Word 打开';\n }\n if (raw && !/^Cannot read properties/i.test(raw) && !/^undefined/i.test(raw)) {\n return raw;\n }\n return kind === 'excel'\n ? 'Excel 预览失败,请下载后查看'\n : kind === 'word'\n ? 'Word 预览失败,请下载后查看'\n : '预览加载失败';\n}\n\n/** exceljs/@js-preview 对部分含 drawing/chart 的 xlsx 会在 reconcile 时读 anchors 崩溃;去掉绘图部件后重试。 */\nasync function stripExcelDrawings(data: ArrayBuffer): Promise<ArrayBuffer | null> {\n try {\n const { default: JSZip } = await import('jszip');\n const zip = await JSZip.loadAsync(data);\n const names = Object.keys(zip.files);\n const drop = names.filter(\n (n) =>\n n.startsWith('xl/drawings/') ||\n n.startsWith('xl/charts/') ||\n n.startsWith('xl/diagrams/') ||\n /drawing[0-9]*\\.xml$/i.test(n),\n );\n if (drop.length === 0) return null;\n for (const n of drop) {\n zip.remove(n);\n }\n // 清理 worksheet 中的 drawing 引用,避免指向已删部件\n await Promise.all(\n names\n .filter((n) => /^xl\\/worksheets\\/[^/]+\\.xml$/i.test(n) && zip.file(n))\n .map(async (n) => {\n const file = zip.file(n);\n if (!file) return;\n const xml = await file.async('string');\n const cleaned = xml\n .replace(/<drawing[^>]*\\/>/gi, '')\n .replace(/<drawing[^>]*>[\\s\\S]*?<\\/drawing>/gi, '');\n if (cleaned !== xml) zip.file(n, cleaned);\n }),\n );\n return zip.generateAsync({ type: 'arraybuffer' });\n } catch {\n return null;\n }\n}\n\nasync function previewExcelBuffer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n jsPreviewExcel: { init: (el: HTMLElement) => any },\n container: HTMLElement,\n data: ArrayBuffer,\n) {\n const instance = jsPreviewExcel.init(container);\n try {\n await instance.preview(data);\n return () => instance.destroy();\n } catch (err) {\n try {\n instance.destroy();\n } catch {\n // ignore\n }\n throw err;\n }\n}\n\nasync function renderExcel(container: HTMLElement, data: ArrayBuffer) {\n const [{ default: jsPreviewExcel }] = await Promise.all([\n import('@js-preview/excel'),\n import('@js-preview/excel/lib/index.css'),\n ]);\n const height = Math.max(\n container.parentElement?.clientHeight ?? 0,\n Math.round(window.innerHeight * 0.65),\n 480,\n );\n container.style.height = `${height}px`;\n\n try {\n return await previewExcelBuffer(jsPreviewExcel, container, data);\n } catch (firstErr) {\n const msg = firstErr instanceof Error ? firstErr.message : String(firstErr ?? '');\n if (!/anchors/i.test(msg)) {\n throw firstErr instanceof Error ? firstErr : new Error(mapPreviewError(firstErr, 'excel'));\n }\n const stripped = await stripExcelDrawings(data);\n if (!stripped) {\n throw firstErr instanceof Error ? firstErr : new Error(mapPreviewError(firstErr, 'excel'));\n }\n container.innerHTML = '';\n try {\n return await previewExcelBuffer(jsPreviewExcel, container, stripped);\n } catch (retryErr) {\n throw retryErr instanceof Error ? retryErr : new Error(mapPreviewError(retryErr, 'excel'));\n }\n }\n}\n\nfunction isZipBuffer(data: ArrayBuffer): boolean {\n const u = new Uint8Array(data);\n return u.length >= 2 && u[0] === 0x50 && u[1] === 0x4b; // PK\n}\n\nfunction isOleBuffer(data: ArrayBuffer): boolean {\n const u = new Uint8Array(data);\n return u.length >= 4 && u[0] === 0xd0 && u[1] === 0xcf && u[2] === 0x11 && u[3] === 0xe0;\n}\n\n/** 服务端把旧版 .doc 转成 HTML 后,预览响应不再是 OLE */\nfunction isLikelyHtmlBuffer(data: ArrayBuffer): boolean {\n const u = new Uint8Array(data.byteLength > 64 ? data.slice(0, 64) : data);\n let offset = 0;\n if (u.length >= 3 && u[0] === 0xef && u[1] === 0xbb && u[2] === 0xbf) offset = 3;\n const head = new TextDecoder('utf-8').decode(u.subarray(offset)).trimStart().toLowerCase();\n return (\n head.startsWith('<!doctype') ||\n head.startsWith('<html') ||\n head.startsWith('<pre') ||\n head.startsWith('<div') ||\n head.startsWith('<article')\n );\n}\n\nasync function renderWord(container: HTMLElement, data: ArrayBuffer) {\n // 误命名为 .doc 的真实 docx(ZIP)仍走 docx-preview\n if (isZipBuffer(data)) {\n const { renderAsync } = await import('docx-preview');\n const blob = new Blob([data]);\n await renderAsync(blob, container, container, {\n inWrapper: true,\n ignoreWidth: false,\n ignoreHeight: false,\n breakPages: true,\n });\n return;\n }\n\n // Assets 等对旧版 .doc 预览返回的 HTML\n if (isLikelyHtmlBuffer(data)) {\n container.innerHTML = new TextDecoder('utf-8').decode(data);\n return;\n }\n\n if (isOleBuffer(data)) {\n throw new Error('旧版 Word(.doc)暂无法排版预览,请下载后用 Word 打开');\n }\n\n throw new Error('无法识别的 Word 文件格式,请下载后查看');\n}\n\nasync function renderPpt(container: HTMLElement, data: ArrayBuffer, width: number) {\n const { init } = await import('pptx-preview');\n const previewer = init(container, { width, height: Math.round(width * 0.5625), mode: 'list' });\n await previewer.preview(data);\n return () => previewer.destroy();\n}\n\nfunction renderText(container: HTMLElement, data: ArrayBuffer) {\n const decoder = new TextDecoder('utf-8');\n const pre = document.createElement('pre');\n pre.className = styles['file-preview-text'] ?? '';\n pre.textContent = decoder.decode(data);\n container.appendChild(pre);\n}\n\nconst FilePreviewContent: React.FC<FilePreviewContentProps> = ({\n file,\n previewUrl,\n unsupportedMessage = '暂不支持预览此文件类型',\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const cleanupRef = useRef<(() => void) | void>(undefined);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const kind = getPreviewKind(file);\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container || !previewUrl) return undefined;\n\n let cancelled = false;\n cleanupRef.current?.();\n cleanupRef.current = undefined;\n container.innerHTML = '';\n setError(null);\n\n const run = async () => {\n if (kind === 'image') return;\n if (kind === 'pdf' || kind === 'iframe') return;\n if (kind === 'video' || kind === 'audio') return;\n if (kind === 'unsupported') return;\n\n setLoading(true);\n try {\n const data = await fetchPreviewBlob(previewUrl);\n if (cancelled) return;\n\n if (kind === 'excel') {\n cleanupRef.current = await renderExcel(container, data);\n } else if (kind === 'word') {\n await renderWord(container, data);\n } else if (kind === 'ppt') {\n const width = container.clientWidth || 852;\n cleanupRef.current = await renderPpt(container, data, width);\n } else if (kind === 'text') {\n renderText(container, data);\n }\n } catch (err) {\n if (!cancelled) {\n setError(mapPreviewError(err, kind));\n }\n } finally {\n if (!cancelled) setLoading(false);\n }\n };\n\n void run();\n\n return () => {\n cancelled = true;\n cleanupRef.current?.();\n cleanupRef.current = undefined;\n container.innerHTML = '';\n };\n }, [previewUrl, kind, file.id, file.name]);\n\n if (!previewUrl) {\n return <Empty description=\"无可预览地址\" />;\n }\n\n if (kind === 'image') {\n return (\n <div className={styles['file-preview-media-wrap']}>\n <img src={previewUrl} alt={file.name} className={styles['file-preview-image']} />\n </div>\n );\n }\n\n if (kind === 'pdf' || kind === 'iframe') {\n return <iframe src={previewUrl} title={file.name} className={styles['file-preview-iframe']} />;\n }\n\n if (kind === 'video') {\n return (\n <div className={styles['file-preview-media-wrap']}>\n <video src={previewUrl} controls className={styles['file-preview-video']} />\n </div>\n );\n }\n\n if (kind === 'audio') {\n return (\n <div className={styles['file-preview-audio-wrap']}>\n <audio src={previewUrl} controls className={styles['file-preview-audio']} />\n </div>\n );\n }\n\n if (kind === 'unsupported') {\n return <Empty description={unsupportedMessage} />;\n }\n\n if (needsBlobPreview(kind)) {\n return (\n <div\n className={classNames(styles['file-preview-office'], styles['file-preview-office-wrap'])}\n >\n <Spin spinning={loading} classNames={{ root: styles['file-preview-office-spin'] }}>\n {error ? (\n <Empty description={error} />\n ) : (\n <div ref={containerRef} className={styles['file-preview-office-inner']} />\n )}\n </Spin>\n </div>\n );\n }\n\n return <Empty description={unsupportedMessage} />;\n};\n\nexport default FilePreviewContent;\n"],"names":["fetchPreviewBlob","url","res","mapPreviewError","err","kind","raw","stripExcelDrawings","data","JSZip","n","zip","names","drop","file","xml","cleaned","previewExcelBuffer","jsPreviewExcel","container","instance","renderExcel","height","_a","firstErr","msg","stripped","retryErr","isZipBuffer","u","isOleBuffer","isLikelyHtmlBuffer","offset","head","renderWord","renderAsync","blob","renderPpt","width","init","previewer","renderText","decoder","pre","styles","FilePreviewContent","previewUrl","unsupportedMessage","containerRef","useRef","cleanupRef","loading","setLoading","useState","error","setError","getPreviewKind","useEffect","cancelled","jsx","Empty","needsBlobPreview","classNames","Spin"],"mappings":";;;;;;AAaA,eAAeA,EAAiBC,GAAmC;AACjE,QAAMC,IAAM,MAAM,MAAMD,CAAG;AAC3B,MAAI,CAACC,EAAI,GAAI,OAAM,IAAI,MAAM,WAAWA,EAAI,MAAM,GAAG;AACrD,SAAOA,EAAI,YAAA;AACb;AAEA,SAASC,EAAgBC,GAAcC,GAAsB;AAC3D,QAAMC,IAAMF,aAAe,QAAQA,EAAI,UAAU,OAAOA,KAAO,EAAE;AACjE,SAAIC,MAAS,WAAW,WAAW,KAAKC,CAAG,IAClC,6CAELD,MAAS,UAAU,oCAAoC,KAAKC,CAAG,IAC1D,uCAELA,KAAO,CAAC,2BAA2B,KAAKA,CAAG,KAAK,CAAC,cAAc,KAAKA,CAAG,IAClEA,IAEFD,MAAS,UACZ,sBACAA,MAAS,SACP,qBACA;AACR;AAGA,e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AA,EAAM,aAAab,EAAA,CAAoB,IAG7Cc,EAAiBxD,CAAI,IAErB,gBAAAsD;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWG,EAAWlB,EAAO,qBAAqB,GAAGA,EAAO,0BAA0B,CAAC;AAAA,MAEvF,UAAA,gBAAAe,EAACI,GAAA,EAAK,UAAUZ,GAAS,YAAY,EAAE,MAAMP,EAAO,0BAA0B,EAAA,GAC3E,UAAAU,sBACEM,GAAA,EAAM,aAAaN,GAAO,IAE3B,gBAAAK,EAAC,OAAA,EAAI,KAAKX,GAAc,WAAWJ,EAAO,2BAA2B,EAAA,CAAG,EAAA,CAE5E;AAAA,IAAA;AAAA,EAAA,IAKC,gBAAAe,EAACC,GAAA,EAAM,aAAab,EAAA,CAAoB,IAnDtC,gBAAAY,EAACC,GAAA,EAAM,aAAY,SAAA,CAAS;AAoDvC;"}
|
|
@@ -11,6 +11,7 @@ export type { FormDataSyncProps } from './FormDataSync';
|
|
|
11
11
|
/** @kne/form-info — 业务从包根导入,勿直连 @kne/form-info */
|
|
12
12
|
export { FormInfo, Form, FormModal, FormSteps, FormStepsModal, List, TableList, MultiField, Input, TextArea, Select, TreeSelect, InputNumber, Switch, RadioGroup, SubmitButton, ResetButton, CancelButton, } from './kneFormInfo';
|
|
13
13
|
export type { FormInfoProps, FormProps, FormModalProps, FormStepsProps, FormStepsModalProps, ListProps, TableListProps, MultiFieldProps, } from './kneFormInfo';
|
|
14
|
+
export { normalizeLabelTips, withNormalizedLabelTips } from './normalizeLabelTips';
|
|
14
15
|
/** @kne/react-form — 引擎 API;默认组件为 ReactForm(勿与 FormInfo 的 Form 混淆) */
|
|
15
16
|
export { ReactForm, GroupList, useField, useFormApi, useFormContext, useGroup, useSubmit, useReset, RULES, preset, interceptors, compileErrMsg, computedFieldValueFromFormData, computedFormDataFormState, filterEmpty, findField, formUtils, isEmpty, isNotEmpty, matchFields, stateToError, stateToIsPass, } from './kneReactForm';
|
|
16
17
|
export type { GroupListRenderProps } from './kneReactForm';
|
|
@@ -3,6 +3,8 @@ import { ComponentType, FC, ReactNode } from 'react';
|
|
|
3
3
|
type FieldProps = {
|
|
4
4
|
name: string;
|
|
5
5
|
label?: ReactNode;
|
|
6
|
+
/** 字符串自动变 Info 悬停;也可传 ReactNode / (props)=>ReactNode 自定义 */
|
|
7
|
+
labelTips?: ReactNode | ((props: FieldProps) => ReactNode);
|
|
6
8
|
rule?: string;
|
|
7
9
|
placeholder?: string;
|
|
8
10
|
disabled?: boolean;
|
|
@@ -37,7 +39,10 @@ export declare const TableList: FC<Omit<TableListProps, "itemTitle"> & {
|
|
|
37
39
|
itemTitle?: (ctx: ItemTitleCtx) => string;
|
|
38
40
|
}>;
|
|
39
41
|
export declare const MultiField: FC<MultiFieldProps>;
|
|
40
|
-
|
|
42
|
+
type KneInputType = ComponentType<FieldProps> & {
|
|
43
|
+
Password: ComponentType<FieldProps>;
|
|
44
|
+
};
|
|
45
|
+
export declare const Input: KneInputType;
|
|
41
46
|
export declare const TextArea: ComponentType<FieldProps>;
|
|
42
47
|
export declare const Select: ComponentType<FieldProps>;
|
|
43
48
|
export declare const TreeSelect: ComponentType<FieldProps>;
|
|
@@ -47,3 +52,4 @@ export declare const RadioGroup: ComponentType<FieldProps>;
|
|
|
47
52
|
export declare const SubmitButton: ComponentType<ButtonProps>;
|
|
48
53
|
export declare const ResetButton: ComponentType<ButtonProps>;
|
|
49
54
|
export declare const CancelButton: ComponentType<ButtonProps>;
|
|
55
|
+
export { normalizeLabelTips, withNormalizedLabelTips } from './normalizeLabelTips';
|
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
/* empty css */
|
|
2
|
-
import
|
|
3
|
-
import { CancelButton as u,
|
|
4
|
-
|
|
2
|
+
import s, { Form as e, FormModal as n, FormSteps as a, FormStepsModal as r, List as c, MultiField as i, TableList as m } from "@kne/form-info";
|
|
3
|
+
import { CancelButton as u, ResetButton as l, SubmitButton as p, Input as S, TextArea as d, Select as F, TreeSelect as $, InputNumber as b, Switch as T, RadioGroup as B } from "@kne/react-form-antd";
|
|
4
|
+
import { withNormalizedLabelTips as t } from "./normalizeLabelTips.js";
|
|
5
|
+
import { normalizeLabelTips as H } from "./normalizeLabelTips.js";
|
|
6
|
+
const R = s, x = e, h = n, N = a, A = r, C = c, G = m, z = i, o = S, I = t(o), P = Object.assign(I, {
|
|
7
|
+
Password: t(o.Password)
|
|
8
|
+
}), g = t(
|
|
9
|
+
d
|
|
10
|
+
), j = t(
|
|
11
|
+
F
|
|
12
|
+
), y = t(
|
|
13
|
+
$
|
|
14
|
+
), K = t(
|
|
15
|
+
b
|
|
16
|
+
), O = t(
|
|
17
|
+
T
|
|
18
|
+
), W = t(
|
|
19
|
+
B
|
|
20
|
+
), k = p, q = l, v = u;
|
|
5
21
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
v as CancelButton,
|
|
23
|
+
x as Form,
|
|
24
|
+
R as FormInfo,
|
|
25
|
+
h as FormModal,
|
|
26
|
+
N as FormSteps,
|
|
27
|
+
A as FormStepsModal,
|
|
28
|
+
P as Input,
|
|
29
|
+
K as InputNumber,
|
|
30
|
+
C as List,
|
|
31
|
+
z as MultiField,
|
|
32
|
+
W as RadioGroup,
|
|
33
|
+
q as ResetButton,
|
|
34
|
+
j as Select,
|
|
35
|
+
k as SubmitButton,
|
|
36
|
+
O as Switch,
|
|
37
|
+
G as TableList,
|
|
38
|
+
g as TextArea,
|
|
39
|
+
y as TreeSelect,
|
|
40
|
+
H as normalizeLabelTips,
|
|
41
|
+
t as withNormalizedLabelTips
|
|
24
42
|
};
|
|
25
43
|
//# sourceMappingURL=kneFormInfo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kneFormInfo.js","sources":["../../../src/components/Form/kneFormInfo.ts"],"sourcesContent":["/**\n * 经 core 再导出 @kne/form-info(业务唯一入口)。\n * 布局组件来自 @kne/form-info;字段组件须从 @kne/react-form-antd 具名导入\n * (form-info 的 `export *` 在 Vite 下经 namespace 读取时常为 undefined)。\n */\nimport '@kne/form-info/dist/index.css';\nimport FormInfoBase, {\n Form as KneForm,\n FormModal as KneFormModal,\n FormSteps as KneFormSteps,\n FormStepsModal as KneFormStepsModal,\n List as KneList,\n MultiField as KneMultiField,\n TableList as KneTableList,\n type FormModalProps,\n type FormProps,\n type FormStepsModalProps,\n type FormStepsProps,\n type ListProps,\n type MultiFieldProps,\n type TableListProps,\n type FormInfoProps,\n} from '@kne/form-info';\nimport {\n CancelButton as KneCancelButton,\n Input as KneInput,\n InputNumber as KneInputNumber,\n RadioGroup as KneRadioGroup,\n ResetButton as KneResetButton,\n Select as KneSelect,\n SubmitButton as KneSubmitButton,\n Switch as KneSwitch,\n TextArea as KneTextArea,\n TreeSelect as KneTreeSelect,\n} from '@kne/react-form-antd';\nimport type { ComponentType, FC, ReactNode } from 'react';\n\ntype FieldProps = {\n name: string;\n label?: ReactNode;\n rule?: string;\n placeholder?: string;\n disabled?: boolean;\n block?: boolean;\n rows?: number;\n options?: unknown[];\n [key: string]: unknown;\n};\n\ntype ButtonProps = {\n children?: ReactNode;\n type?: string;\n loading?: boolean;\n [key: string]: unknown;\n};\n\ntype ItemTitleCtx = { index: number; data?: Record<string, unknown> };\n\nexport type {\n FormInfoProps,\n FormProps,\n FormModalProps,\n FormStepsProps,\n FormStepsModalProps,\n ListProps,\n TableListProps,\n MultiFieldProps,\n};\n\nexport const FormInfo = FormInfoBase;\nexport const Form = KneForm;\nexport const FormModal = KneFormModal as FC<FormModalProps & { children?: ReactNode }>;\nexport const FormSteps = KneFormSteps as FC<FormStepsProps>;\nexport const FormStepsModal = KneFormStepsModal as FC<FormStepsModalProps>;\n\nexport const List = KneList as FC<\n Omit<ListProps, 'itemTitle'> & {\n maxLength?: number;\n itemTitle?: (ctx: ItemTitleCtx) => string;\n }\n>;\nexport const TableList = KneTableList as FC<\n Omit<TableListProps, 'itemTitle'> & {\n itemTitle?: (ctx: ItemTitleCtx) => string;\n }\n>;\nexport const MultiField = KneMultiField as FC<MultiFieldProps>;\n\nexport const Input =
|
|
1
|
+
{"version":3,"file":"kneFormInfo.js","sources":["../../../src/components/Form/kneFormInfo.ts"],"sourcesContent":["/**\n * 经 core 再导出 @kne/form-info(业务唯一入口)。\n * 布局组件来自 @kne/form-info;字段组件须从 @kne/react-form-antd 具名导入\n * (form-info 的 `export *` 在 Vite 下经 namespace 读取时常为 undefined)。\n *\n * 字段 `labelTips`:字符串由 {@link withNormalizedLabelTips} 统一包成 Info+TooltipInfo。\n */\nimport '@kne/form-info/dist/index.css';\nimport FormInfoBase, {\n Form as KneForm,\n FormModal as KneFormModal,\n FormSteps as KneFormSteps,\n FormStepsModal as KneFormStepsModal,\n List as KneList,\n MultiField as KneMultiField,\n TableList as KneTableList,\n type FormModalProps,\n type FormProps,\n type FormStepsModalProps,\n type FormStepsProps,\n type ListProps,\n type MultiFieldProps,\n type TableListProps,\n type FormInfoProps,\n} from '@kne/form-info';\nimport {\n CancelButton as KneCancelButton,\n Input as KneInput,\n InputNumber as KneInputNumber,\n RadioGroup as KneRadioGroup,\n ResetButton as KneResetButton,\n Select as KneSelect,\n SubmitButton as KneSubmitButton,\n Switch as KneSwitch,\n TextArea as KneTextArea,\n TreeSelect as KneTreeSelect,\n} from '@kne/react-form-antd';\nimport type { ComponentType, FC, ReactNode } from 'react';\nimport { withNormalizedLabelTips } from './normalizeLabelTips';\n\ntype FieldProps = {\n name: string;\n label?: ReactNode;\n /** 字符串自动变 Info 悬停;也可传 ReactNode / (props)=>ReactNode 自定义 */\n labelTips?: ReactNode | ((props: FieldProps) => ReactNode);\n rule?: string;\n placeholder?: string;\n disabled?: boolean;\n block?: boolean;\n rows?: number;\n options?: unknown[];\n [key: string]: unknown;\n};\n\ntype ButtonProps = {\n children?: ReactNode;\n type?: string;\n loading?: boolean;\n [key: string]: unknown;\n};\n\ntype ItemTitleCtx = { index: number; data?: Record<string, unknown> };\n\nexport type {\n FormInfoProps,\n FormProps,\n FormModalProps,\n FormStepsProps,\n FormStepsModalProps,\n ListProps,\n TableListProps,\n MultiFieldProps,\n};\n\nexport const FormInfo = FormInfoBase;\nexport const Form = KneForm;\nexport const FormModal = KneFormModal as FC<FormModalProps & { children?: ReactNode }>;\nexport const FormSteps = KneFormSteps as FC<FormStepsProps>;\nexport const FormStepsModal = KneFormStepsModal as FC<FormStepsModalProps>;\n\nexport const List = KneList as FC<\n Omit<ListProps, 'itemTitle'> & {\n maxLength?: number;\n itemTitle?: (ctx: ItemTitleCtx) => string;\n }\n>;\nexport const TableList = KneTableList as FC<\n Omit<TableListProps, 'itemTitle'> & {\n itemTitle?: (ctx: ItemTitleCtx) => string;\n }\n>;\nexport const MultiField = KneMultiField as FC<MultiFieldProps>;\n\ntype KneInputType = ComponentType<FieldProps> & { Password: ComponentType<FieldProps> };\nconst KneInputTyped = KneInput as unknown as KneInputType;\nconst InputWrapped = withNormalizedLabelTips(KneInputTyped);\nexport const Input = Object.assign(InputWrapped, {\n Password: withNormalizedLabelTips(KneInputTyped.Password),\n}) as KneInputType;\n\nexport const TextArea = withNormalizedLabelTips(\n KneTextArea as ComponentType<FieldProps>,\n) as ComponentType<FieldProps>;\nexport const Select = withNormalizedLabelTips(\n KneSelect as ComponentType<FieldProps>,\n) as ComponentType<FieldProps>;\nexport const TreeSelect = withNormalizedLabelTips(\n KneTreeSelect as ComponentType<FieldProps>,\n) as ComponentType<FieldProps>;\nexport const InputNumber = withNormalizedLabelTips(\n KneInputNumber as ComponentType<FieldProps>,\n) as ComponentType<FieldProps>;\nexport const Switch = withNormalizedLabelTips(\n KneSwitch as ComponentType<FieldProps>,\n) as ComponentType<FieldProps>;\nexport const RadioGroup = withNormalizedLabelTips(\n KneRadioGroup as ComponentType<FieldProps>,\n) as ComponentType<FieldProps>;\n\nexport const SubmitButton = KneSubmitButton as ComponentType<ButtonProps>;\nexport const ResetButton = KneResetButton as ComponentType<ButtonProps>;\nexport const CancelButton = KneCancelButton as ComponentType<ButtonProps>;\n\nexport { normalizeLabelTips, withNormalizedLabelTips } from './normalizeLabelTips';\n"],"names":["FormInfo","FormInfoBase","Form","KneForm","FormModal","KneFormModal","FormSteps","KneFormSteps","FormStepsModal","KneFormStepsModal","List","KneList","TableList","KneTableList","MultiField","KneMultiField","KneInputTyped","KneInput","InputWrapped","withNormalizedLabelTips","Input","TextArea","KneTextArea","Select","KneSelect","TreeSelect","KneTreeSelect","InputNumber","KneInputNumber","Switch","KneSwitch","RadioGroup","KneRadioGroup","SubmitButton","KneSubmitButton","ResetButton","KneResetButton","CancelButton","KneCancelButton"],"mappings":";;;;;AA0EO,MAAMA,IAAWC,GACXC,IAAOC,GACPC,IAAYC,GACZC,IAAYC,GACZC,IAAiBC,GAEjBC,IAAOC,GAMPC,IAAYC,GAKZC,IAAaC,GAGpBC,IAAgBC,GAChBC,IAAeC,EAAwBH,CAAa,GAC7CI,IAAQ,OAAO,OAAOF,GAAc;AAAA,EAC/C,UAAUC,EAAwBH,EAAc,QAAQ;AAC1D,CAAC,GAEYK,IAAWF;AAAA,EACtBG;AACF,GACaC,IAASJ;AAAA,EACpBK;AACF,GACaC,IAAaN;AAAA,EACxBO;AACF,GACaC,IAAcR;AAAA,EACzBS;AACF,GACaC,IAASV;AAAA,EACpBW;AACF,GACaC,IAAaZ;AAAA,EACxBa;AACF,GAEaC,IAAeC,GACfC,IAAcC,GACdC,IAAeC;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* kne 原生会把字符串 `labelTips` 直接拼进 label 旁正文。
|
|
4
|
+
* core 约定:字符串 / 数字 → Info + TooltipInfo(悬停说明);
|
|
5
|
+
* 已是 ReactNode / function → 原样透传(业务可自定义)。
|
|
6
|
+
* 必填仍用 `rule="REQ"`,不要把「必填/选填」写进 tip。
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeLabelTips(labelTips: unknown): ReactNode | undefined;
|
|
9
|
+
type WithLabelTips = {
|
|
10
|
+
labelTips?: unknown;
|
|
11
|
+
};
|
|
12
|
+
/** 包装 kne 字段:拦截 labelTips 字符串并规范化 */
|
|
13
|
+
export declare function withNormalizedLabelTips<P extends WithLabelTips>(Comp: ComponentType<P>): ComponentType<P>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import s from "../TooltipInfo/TooltipInfo.js";
|
|
3
|
+
import { Info as f } from "../Icons/Info.js";
|
|
4
|
+
function l(t) {
|
|
5
|
+
if (!(t == null || t === !1)) {
|
|
6
|
+
if (typeof t == "string" || typeof t == "number") {
|
|
7
|
+
const i = String(t).trim();
|
|
8
|
+
return i ? /* @__PURE__ */ r(
|
|
9
|
+
s,
|
|
10
|
+
{
|
|
11
|
+
type: "note",
|
|
12
|
+
note: { title: "说明", description: i },
|
|
13
|
+
minWidth: 220,
|
|
14
|
+
maxWidth: 360,
|
|
15
|
+
children: /* @__PURE__ */ r(
|
|
16
|
+
f,
|
|
17
|
+
{
|
|
18
|
+
size: 14,
|
|
19
|
+
"aria-label": "说明",
|
|
20
|
+
style: { marginLeft: 4, cursor: "pointer", verticalAlign: "-2px" }
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
) : void 0;
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function u(t) {
|
|
30
|
+
const i = (o) => {
|
|
31
|
+
const { labelTips: a, ...m } = o, e = l(a);
|
|
32
|
+
return /* @__PURE__ */ r(t, { ...m, ...e !== void 0 ? { labelTips: e } : {} });
|
|
33
|
+
}, n = t.displayName || t.name || "Field";
|
|
34
|
+
return i.displayName = `WithNormalizedLabelTips(${n})`, i;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
l as normalizeLabelTips,
|
|
38
|
+
u as withNormalizedLabelTips
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=normalizeLabelTips.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeLabelTips.js","sources":["../../../src/components/Form/normalizeLabelTips.tsx"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport { Info } from '@/components/Icons';\nimport { TooltipInfo } from '@/components/TooltipInfo';\n\n/**\n * kne 原生会把字符串 `labelTips` 直接拼进 label 旁正文。\n * core 约定:字符串 / 数字 → Info + TooltipInfo(悬停说明);\n * 已是 ReactNode / function → 原样透传(业务可自定义)。\n * 必填仍用 `rule=\"REQ\"`,不要把「必填/选填」写进 tip。\n */\nexport function normalizeLabelTips(labelTips: unknown): ReactNode | undefined {\n if (labelTips == null || labelTips === false) {\n return undefined;\n }\n if (typeof labelTips === 'string' || typeof labelTips === 'number') {\n const text = String(labelTips).trim();\n if (!text) {\n return undefined;\n }\n return (\n <TooltipInfo\n type=\"note\"\n note={{ title: '说明', description: text }}\n minWidth={220}\n maxWidth={360}\n >\n <Info\n size={14}\n aria-label=\"说明\"\n style={{ marginLeft: 4, cursor: 'pointer', verticalAlign: '-2px' }}\n />\n </TooltipInfo>\n );\n }\n return labelTips as ReactNode;\n}\n\ntype WithLabelTips = { labelTips?: unknown };\n\n/** 包装 kne 字段:拦截 labelTips 字符串并规范化 */\nexport function withNormalizedLabelTips<P extends WithLabelTips>(\n Comp: ComponentType<P>,\n): ComponentType<P> {\n const Wrapped = (props: P) => {\n const { labelTips, ...rest } = props;\n const next = normalizeLabelTips(labelTips);\n return <Comp {...(rest as P)} {...(next !== undefined ? { labelTips: next } : {})} />;\n };\n const name = Comp.displayName || Comp.name || 'Field';\n Wrapped.displayName = `WithNormalizedLabelTips(${name})`;\n return Wrapped;\n}\n"],"names":["normalizeLabelTips","labelTips","text","jsx","TooltipInfo","Info","withNormalizedLabelTips","Comp","Wrapped","props","rest","next","name"],"mappings":";;;AAUO,SAASA,EAAmBC,GAA2C;AAC5E,MAAI,EAAAA,KAAa,QAAQA,MAAc,KAGvC;AAAA,QAAI,OAAOA,KAAc,YAAY,OAAOA,KAAc,UAAU;AAClE,YAAMC,IAAO,OAAOD,CAAS,EAAE,KAAA;AAC/B,aAAKC,IAIH,gBAAAC;AAAA,QAACC;AAAA,QAAA;AAAA,UACC,MAAK;AAAA,UACL,MAAM,EAAE,OAAO,MAAM,aAAaF,EAAA;AAAA,UAClC,UAAU;AAAA,UACV,UAAU;AAAA,UAEV,UAAA,gBAAAC;AAAA,YAACE;AAAA,YAAA;AAAA,cACC,MAAM;AAAA,cACN,cAAW;AAAA,cACX,OAAO,EAAE,YAAY,GAAG,QAAQ,WAAW,eAAe,OAAA;AAAA,YAAO;AAAA,UAAA;AAAA,QACnE;AAAA,MAAA,IAbF;AAAA,IAgBJ;AACA,WAAOJ;AAAA;AACT;AAKO,SAASK,EACdC,GACkB;AAClB,QAAMC,IAAU,CAACC,MAAa;AAC5B,UAAM,EAAE,WAAAR,GAAW,GAAGS,EAAA,IAASD,GACzBE,IAAOX,EAAmBC,CAAS;AACzC,WAAO,gBAAAE,EAACI,GAAA,EAAM,GAAIG,GAAa,GAAIC,MAAS,SAAY,EAAE,WAAWA,EAAA,IAAS,CAAA,EAAC,CAAI;AAAA,EACrF,GACMC,IAAOL,EAAK,eAAeA,EAAK,QAAQ;AAC9C,SAAAC,EAAQ,cAAc,2BAA2BI,CAAI,KAC9CJ;AACT;"}
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { TabsProps } from 'antd';
|
|
2
|
-
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import { CSSProperties, MouseEvent, ReactNode } from 'react';
|
|
3
|
+
import { IconName } from '../Icons';
|
|
3
4
|
import { DescriptionItem } from '../Descriptions/CommonDescriptions';
|
|
4
5
|
export type StateBarType = 'tab' | 'radio' | 'step';
|
|
6
|
+
/** Tab 项旁操作(icon + 可选文案提示 + 点击) */
|
|
7
|
+
export type StateBarActionItem = {
|
|
8
|
+
/** Icons 注册表名,如 `Info` / `Plus` / `Pencil` */
|
|
9
|
+
iconType: IconName;
|
|
10
|
+
/** Tooltip 文案;缺省不包 Tooltip */
|
|
11
|
+
label?: string;
|
|
12
|
+
onClick?: (e: MouseEvent<HTMLElement>) => void;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
/** 图标尺寸,默认 14 */
|
|
16
|
+
size?: number;
|
|
17
|
+
};
|
|
5
18
|
export type StateBarOption = {
|
|
6
19
|
key: string;
|
|
7
20
|
/** 选项卡标题(优先于 label) */
|
|
8
21
|
tab?: ReactNode;
|
|
9
22
|
label?: ReactNode;
|
|
10
|
-
/** 标题旁 Info + TooltipInfo(对齐 Modal/InteractiveBlock);为空不展示
|
|
23
|
+
/** 标题旁 Info + TooltipInfo(对齐 Modal/InteractiveBlock);为空不展示 */
|
|
11
24
|
info?: DescriptionItem[];
|
|
25
|
+
/** 标题旁额外操作图标(可与 info 并存) */
|
|
26
|
+
actions?: StateBarActionItem[];
|
|
12
27
|
children?: ReactNode;
|
|
13
28
|
disabled?: boolean;
|
|
14
29
|
className?: string;
|