antd-import-export 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "antd-import-export",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "description": "Schema-driven Excel import and export for Ant Design: template generation, client-side validation, batched submission, row-level error feedback and cursor-based export",
6
- "main": "./dist/index.mjs",
6
+ "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs"
13
- },
14
- "./worker": {
15
- "import": "./dist/core/excel/worker.mjs"
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
16
14
  },
17
15
  "./package.json": "./package.json"
18
16
  },
@@ -24,7 +22,7 @@
24
22
  ],
25
23
  "sideEffects": false,
26
24
  "scripts": {
27
- "build": "rm -rf dist && npx vite build && npx tsc -p tsconfig.json && mkdir -p dist/core/excel && cp src/core/excel/worker-url.js dist/core/excel/worker-url.js",
25
+ "build": "rm -rf dist && npx vite build && npx tsc -p tsconfig.json",
28
26
  "dev": "npx vite build --watch",
29
27
  "preview": "npm run build && npx vite --config vite.config.preview.ts",
30
28
  "build:preview": "npm run build && npx vite build --config vite.config.preview.ts",
@@ -46,7 +44,6 @@
46
44
  "dependencies": {
47
45
  "dayjs": "^1.11.13",
48
46
  "decimal.js": "^10.6.0",
49
- "comlink": "^4.4.2",
50
47
  "exceljs": "^4.4.0",
51
48
  "file-saver": "^2.0.5"
52
49
  },
@@ -1,8 +0,0 @@
1
- /**
2
- * 这一行会原样拷贝进 dist, 不参与本包打包:
3
- * 只有使用方的打包器看到这里的字面量, 才会把 worker 当作独立入口产出.
4
- * 若由本包打包, vite 会把目标文件当成 worker 入口去解析, 而 worker.mjs 此时还不存在.
5
- */
6
- export function createExcelWorker() {
7
- return new Worker(new URL("./worker.mjs", import.meta.url), { type: "module" });
8
- }
@@ -1,12 +0,0 @@
1
- import type { ImportParseResult } from "./parseSheet";
2
- import type { FieldSchema } from "../schema";
3
- declare const workerAPI: {
4
- /** 在 Worker 里生成 xlsx 文件内容(ExcelJS 只在 Worker 产物里, 不进主包) */
5
- buildExportExcel(data: Record<string, unknown>[], fieldSchemas: FieldSchema[]): Promise<ArrayBuffer>;
6
- /** 在 Worker 里生成导入模板: 列名 + 填写要求(都在表头单元格里), 不写示例行 */
7
- buildImportTemplate(fieldSchemas: FieldSchema[]): Promise<ArrayBuffer>;
8
- /** 在 Worker 里解析并按 fieldSchemas 校验 Excel, 返回可提交的数据与逐行问题 */
9
- parseImportFile(file: File, fieldSchemas: FieldSchema[]): Promise<ImportParseResult>;
10
- };
11
- export type ExcelWorkerAPI = typeof workerAPI;
12
- export {};
@@ -1,119 +0,0 @@
1
- import { a as e, l as t, n, o as r, p as i, r as a, x as o } from "../../worksheet-BEUkpIL-.js";
2
- import * as s from "comlink";
3
- import c from "exceljs";
4
- // src/core/excel/parseSheet.ts
5
- function l(e) {
6
- return !Number.isFinite(e) || e < 1 || e >= 2958466 ? null : new Date(Math.round((e - 25569) * 24 * 3600 * 1e3));
7
- }
8
- function u(e, t = !1) {
9
- let n = String(e.getUTCMonth() + 1).padStart(2, "0"), r = String(e.getUTCDate()).padStart(2, "0"), i = `${e.getUTCFullYear()}-${n}-${r}`;
10
- return t ? `${i} ${String(e.getUTCHours()).padStart(2, "0")}:${String(e.getUTCMinutes()).padStart(2, "0")}` : i;
11
- }
12
- function d(e, t) {
13
- let n = (e) => e.trim() === "" ? null : e.trim(), r = t === "datetime", i = t === "date" || r;
14
- if (e.type === c.ValueType.Null) return null;
15
- if (e.type === c.ValueType.Date) return u(e.value, r);
16
- if (e.type === c.ValueType.Formula) {
17
- if (e.result === null || e.result === void 0) return null;
18
- if (e.result instanceof Date) return u(e.result, r);
19
- if (i && typeof e.result == "number") {
20
- let t = l(e.result);
21
- if (t) return u(t, r);
22
- }
23
- return n(String(e.result));
24
- }
25
- if (e.type === c.ValueType.Number) {
26
- if (i && typeof e.value == "number") {
27
- let t = l(e.value);
28
- if (t) return u(t, r);
29
- }
30
- return n(String(e.value));
31
- }
32
- return n(e.text);
33
- }
34
- function f(e) {
35
- let t = e.property.default_value;
36
- if (t == null) return null;
37
- if (e.type === "boolean") return t ? e.property.true_label : e.property.false_label;
38
- if (Array.isArray(t)) return t.length > 0 ? o(t) : null;
39
- let n = String(t);
40
- return n.trim() === "" ? null : n;
41
- }
42
- function p(e, t) {
43
- let n = new Map(t.map((e) => [e.title, e])), r = [];
44
- for (let t = 1; t <= e.columnCount; t++) {
45
- let i = e.getRow(1).getCell(t).text.split("\n")[0].trim();
46
- r[t - 1] = n.get(i) ?? null;
47
- }
48
- return r;
49
- }
50
- function m(n, a) {
51
- let o = [], s = [], l = [], u = 0, m = !1, h = p(n, a), g = h.filter((e) => e !== null).map((e) => e.key), _ = new Set(g);
52
- if (a.forEach((e) => {
53
- e.property.required && !_.has(e.key) && o.push(`缺少列: ${e.title}`);
54
- }), o.length > 0) return {
55
- headerMessages: o,
56
- formulaMessages: s,
57
- rows: l,
58
- includedKeys: g
59
- };
60
- let v = 0;
61
- return n.eachRow({ includeEmpty: !1 }, (n, p) => {
62
- if (p === 1) return;
63
- let g = {};
64
- if (h.forEach((e, t) => {
65
- e && (g[e.key] = d(n.getCell(t + 1), e.type));
66
- }), h.forEach((e, t) => {
67
- if (!e) return;
68
- let r = n.getCell(t + 1);
69
- r.type === c.ValueType.Formula && (r.result === null || r.result === void 0) && (u += 1, s.length < 20 && s.push(`第 ${p} 行 [${e.title}] 是公式且没有保存计算结果, 请用 Excel 打开并保存后再导入`));
70
- }), Object.values(g).every((e) => e === null)) return;
71
- if (v += 1, v > 2e4) {
72
- m ||= (o.push(`导入数据超出限制(${t} 条), 请分批导入`), !0);
73
- return;
74
- }
75
- let y = {
76
- key: String(l.length),
77
- rowNumber: p,
78
- values: {},
79
- errors: {}
80
- };
81
- a.forEach((t) => {
82
- if (!_.has(t.key)) return;
83
- let n = g[t.key] ?? f(t), a = i(n, t);
84
- a.validateSuccess ? y.values[t.key] = e(t, a.validateValue ?? null) : (y.values[t.key] = r(t, g[t.key] ?? null), y.errors[t.key] = a.validateMessage);
85
- }), l.push(y);
86
- }), u > s.length && s.push(`还有 ${u - s.length} 个公式单元格没有保存计算结果`), {
87
- headerMessages: o,
88
- formulaMessages: s,
89
- rows: l,
90
- includedKeys: g
91
- };
92
- }
93
- // src/core/excel/worker.ts
94
- s.expose({
95
- async buildExportExcel(e, t) {
96
- let r = new c.Workbook(), i = r.addWorksheet("Sheet");
97
- return n(i, e, t), await r.xlsx.writeBuffer();
98
- },
99
- async buildImportTemplate(e) {
100
- let t = new c.Workbook(), n = t.addWorksheet("导入模板");
101
- return a(n, e), await t.xlsx.writeBuffer();
102
- },
103
- async parseImportFile(e, t) {
104
- let n = new c.Workbook();
105
- if (await n.xlsx.load(await e.arrayBuffer()), n.worksheets.length > 1) return {
106
- headerMessages: ["文件包含多个工作表, 只支持单个工作表, 请删除其他工作表后再导入"],
107
- formulaMessages: [],
108
- rows: [],
109
- includedKeys: []
110
- };
111
- let r = n.worksheets[0];
112
- return r ? m(r, t) : {
113
- headerMessages: ["文件里没有工作表"],
114
- formulaMessages: [],
115
- rows: [],
116
- includedKeys: []
117
- };
118
- }
119
- });
@@ -1,467 +0,0 @@
1
- import e from "dayjs";
2
- import t from "decimal.js";
3
- // \0rolldown/runtime.js
4
- var n = Object.create, r = Object.defineProperty, i = Object.getOwnPropertyDescriptor, a = Object.getOwnPropertyNames, o = Object.getPrototypeOf, s = Object.prototype.hasOwnProperty, c = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), l = (e, t, n, o) => {
5
- if (t && typeof t == "object" || typeof t == "function") for (var c = a(t), l = 0, u = c.length, d; l < u; l++) d = c[l], !s.call(e, d) && d !== n && r(e, d, {
6
- get: ((e) => t[e]).bind(null, d),
7
- enumerable: !(o = i(t, d)) || o.enumerable
8
- });
9
- return e;
10
- }, u = (e, t, i) => (i = e == null ? {} : n(o(e)), l(t || !e || !e.__esModule || !s.call(e, "default") ? r(i, "default", {
11
- value: e,
12
- enumerable: !0
13
- }) : i, e)), d = ";", f = /[;;]/;
14
- function p(e) {
15
- return e.map((e) => String(e)).join(";");
16
- }
17
- function m(e) {
18
- return e.split(f).map((e) => e.trim()).filter(Boolean);
19
- }
20
- // src/core/schema/validate.ts
21
- var h = /* @__PURE__ */ u((/* @__PURE__ */ c(((e, t, n) => {
22
- (function(n, r) {
23
- typeof e == "object" && t !== void 0 ? t.exports = r() : typeof define == "function" && define.amd ? define(r) : (n = typeof globalThis < "u" ? globalThis : n || self).dayjs_plugin_customParseFormat = r();
24
- })(n, (function() {
25
- var e = {
26
- LTS: "h:mm:ss A",
27
- LT: "h:mm A",
28
- L: "MM/DD/YYYY",
29
- LL: "MMMM D, YYYY",
30
- LLL: "MMMM D, YYYY h:mm A",
31
- LLLL: "dddd, MMMM D, YYYY h:mm A"
32
- }, t = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g, n = /\d/, r = /\d\d/, i = /\d\d?/, a = /\d*[^-_:/,()\s\d]+/, o = {}, s = function(e) {
33
- return (e = +e) + (e > 68 ? 1900 : 2e3);
34
- }, c = function(e) {
35
- return function(t) {
36
- this[e] = +t;
37
- };
38
- }, l = [/[+-]\d\d:?(\d\d)?|Z/, function(e) {
39
- (this.zone ||= {}).offset = function(e) {
40
- if (!e || e === "Z") return 0;
41
- var t = e.match(/([+-]|\d\d)/g), n = 60 * t[1] + (+t[2] || 0);
42
- return n === 0 ? 0 : t[0] === "+" ? -n : n;
43
- }(e);
44
- }], u = function(e) {
45
- var t = o[e];
46
- return t && (t.indexOf ? t : t.s.concat(t.f));
47
- }, d = function(e, t) {
48
- var n, r = o.meridiem;
49
- if (r) {
50
- for (var i = 1; i <= 24; i += 1) if (e.indexOf(r(i, 0, t)) > -1) {
51
- n = i > 12;
52
- break;
53
- }
54
- } else n = e === (t ? "pm" : "PM");
55
- return n;
56
- }, f = {
57
- A: [a, function(e) {
58
- this.afternoon = d(e, !1);
59
- }],
60
- a: [a, function(e) {
61
- this.afternoon = d(e, !0);
62
- }],
63
- Q: [n, function(e) {
64
- this.month = 3 * (e - 1) + 1;
65
- }],
66
- S: [n, function(e) {
67
- this.milliseconds = 100 * e;
68
- }],
69
- SS: [r, function(e) {
70
- this.milliseconds = 10 * e;
71
- }],
72
- SSS: [/\d{3}/, function(e) {
73
- this.milliseconds = +e;
74
- }],
75
- s: [i, c("seconds")],
76
- ss: [i, c("seconds")],
77
- m: [i, c("minutes")],
78
- mm: [i, c("minutes")],
79
- H: [i, c("hours")],
80
- h: [i, c("hours")],
81
- HH: [i, c("hours")],
82
- hh: [i, c("hours")],
83
- D: [i, c("day")],
84
- DD: [r, c("day")],
85
- Do: [a, function(e) {
86
- var t = o.ordinal, n = e.match(/\d+/);
87
- if (this.day = n[0], t) for (var r = 1; r <= 31; r += 1) t(r).replace(/\[|\]/g, "") === e && (this.day = r);
88
- }],
89
- w: [i, c("week")],
90
- ww: [r, c("week")],
91
- M: [i, c("month")],
92
- MM: [r, c("month")],
93
- MMM: [a, function(e) {
94
- var t = u("months"), n = (u("monthsShort") || t.map((function(e) {
95
- return e.slice(0, 3);
96
- }))).indexOf(e) + 1;
97
- if (n < 1) throw Error();
98
- this.month = n % 12 || n;
99
- }],
100
- MMMM: [a, function(e) {
101
- var t = u("months").indexOf(e) + 1;
102
- if (t < 1) throw Error();
103
- this.month = t % 12 || t;
104
- }],
105
- Y: [/[+-]?\d+/, c("year")],
106
- YY: [r, function(e) {
107
- this.year = s(e);
108
- }],
109
- YYYY: [/\d{4}/, c("year")],
110
- Z: l,
111
- ZZ: l
112
- };
113
- function p(n) {
114
- for (var r = n, i = o && o.formats, a = (n = r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (function(t, n, r) {
115
- var a = r && r.toUpperCase();
116
- return n || i[r] || e[r] || i[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (function(e, t, n) {
117
- return t || n.slice(1);
118
- }));
119
- }))).match(t), s = a.length, c = 0; c < s; c += 1) {
120
- var l = a[c], u = f[l], d = u && u[0], p = u && u[1];
121
- a[c] = p ? {
122
- regex: d,
123
- parser: p
124
- } : l.replace(/^\[|\]$/g, "");
125
- }
126
- return function(e) {
127
- for (var t = {}, n = 0, r = 0; n < s; n += 1) {
128
- var i = a[n];
129
- if (typeof i == "string") r += i.length;
130
- else {
131
- var o = i.regex, c = i.parser, l = e.slice(r), u = o.exec(l)[0];
132
- c.call(t, u), e = e.replace(u, "");
133
- }
134
- }
135
- return function(e) {
136
- var t = e.afternoon;
137
- if (t !== void 0) {
138
- var n = e.hours;
139
- t ? n < 12 && (e.hours += 12) : n === 12 && (e.hours = 0), delete e.afternoon;
140
- }
141
- }(t), t;
142
- };
143
- }
144
- return function(e, t, n) {
145
- n.p.customParseFormat = !0, e && e.parseTwoDigitYear && (s = e.parseTwoDigitYear);
146
- var r = t.prototype, i = r.parse;
147
- r.parse = function(e) {
148
- var t = e.date, r = e.utc, a = e.args;
149
- this.$u = r;
150
- var s = a[1];
151
- if (typeof s == "string") {
152
- var c = !0 === a[2], l = !0 === a[3], u = c || l, d = a[2];
153
- l && (d = a[2]), o = this.$locale(), !c && d && (o = n.Ls[d]), this.$d = function(e, t, n, r) {
154
- try {
155
- if (["x", "X"].indexOf(t) > -1) return /* @__PURE__ */ new Date((t === "X" ? 1e3 : 1) * e);
156
- var i = p(t)(e), a = i.year, o = i.month, s = i.day, c = i.hours, l = i.minutes, u = i.seconds, d = i.milliseconds, f = i.zone, m = i.week, h = /* @__PURE__ */ new Date(), g = s || (a || o ? 1 : h.getDate()), _ = a || h.getFullYear(), v = 0;
157
- a && !o || (v = o > 0 ? o - 1 : h.getMonth());
158
- var y, b = c || 0, x = l || 0, S = u || 0, C = d || 0;
159
- return f ? new Date(Date.UTC(_, v, g, b, x, S, C + 60 * f.offset * 1e3)) : n ? new Date(Date.UTC(_, v, g, b, x, S, C)) : (y = new Date(_, v, g, b, x, S, C), m && (y = r(y).week(m).toDate()), y);
160
- } catch {
161
- return /* @__PURE__ */ new Date("");
162
- }
163
- }(t, s, r, n), this.init(), d && !0 !== d && (this.$L = this.locale(d).$L), u && t != this.format(s) && (this.$d = /* @__PURE__ */ new Date("")), o = {};
164
- } else if (s instanceof Array) for (var f = s.length, m = 1; m <= f; m += 1) {
165
- a[1] = s[m - 1];
166
- var h = n.apply(this, a);
167
- if (h.isValid()) {
168
- this.$d = h.$d, this.$L = h.$L, this.init();
169
- break;
170
- }
171
- m === f && (this.$d = /* @__PURE__ */ new Date(""));
172
- }
173
- else i.call(this, e);
174
- };
175
- };
176
- }));
177
- })))(), 1);
178
- e.extend(h.default);
179
- function g(e, t) {
180
- return e.length > t.property.max_length ? {
181
- validateSuccess: !1,
182
- validateMessage: `长度不能超过 ${t.property.max_length}`
183
- } : {
184
- validateSuccess: !0,
185
- validateValue: e
186
- };
187
- }
188
- function _(e, n) {
189
- let r = Number(e);
190
- if (!Number.isFinite(r)) return {
191
- validateSuccess: !1,
192
- validateMessage: "不是有效数字"
193
- };
194
- let i = n.property.precision, a;
195
- try {
196
- a = new t(e);
197
- } catch {
198
- return {
199
- validateSuccess: !1,
200
- validateMessage: "不是有效数字"
201
- };
202
- }
203
- if (a.decimalPlaces() > i) return {
204
- validateSuccess: !1,
205
- validateMessage: `精度不能超过 ${i} 位小数`
206
- };
207
- let o = n.property.max_digits;
208
- if (o !== void 0) {
209
- let e = a.abs().trunc().toFixed(0).replace(/^0+/, "").length, t = o - i;
210
- if (e > t) return {
211
- validateSuccess: !1,
212
- validateMessage: `整数部分不能超过 ${t} 位`
213
- };
214
- }
215
- return n.property.min_value !== void 0 && r < n.property.min_value ? {
216
- validateSuccess: !1,
217
- validateMessage: `不能小于 ${n.property.min_value}`
218
- } : n.property.max_value !== void 0 && r > n.property.max_value ? {
219
- validateSuccess: !1,
220
- validateMessage: `不能大于 ${n.property.max_value}`
221
- } : {
222
- validateSuccess: !0,
223
- validateValue: r
224
- };
225
- }
226
- function v(e, t) {
227
- return e === t.property.true_label ? {
228
- validateSuccess: !0,
229
- validateValue: !0
230
- } : e === t.property.false_label ? {
231
- validateSuccess: !0,
232
- validateValue: !1
233
- } : {
234
- validateSuccess: !1,
235
- validateMessage: `内容必须是 ${t.property.true_label}|${t.property.false_label}`
236
- };
237
- }
238
- function y(t) {
239
- let n = e(t, "YYYY-MM-DD", !0);
240
- return n.isValid() ? {
241
- validateSuccess: !0,
242
- validateValue: n.format("YYYY-MM-DD")
243
- } : {
244
- validateSuccess: !1,
245
- validateMessage: "不是有效的日期格式 YYYY-MM-DD"
246
- };
247
- }
248
- function b(e) {
249
- let t = /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/.exec(e);
250
- return t ? {
251
- validateSuccess: !0,
252
- validateValue: `${t[1].padStart(2, "0")}:${t[2]}`
253
- } : {
254
- validateSuccess: !1,
255
- validateMessage: "不是有效的日期格式 HH:mm"
256
- };
257
- }
258
- function x(t) {
259
- let n = e(t, "YYYY-MM-DD HH:mm", !0);
260
- return n.isValid() ? {
261
- validateSuccess: !0,
262
- validateValue: n.format("YYYY-MM-DD HH:mm")
263
- } : {
264
- validateSuccess: !1,
265
- validateMessage: "不是有效的日期时间格式 YYYY-MM-DD HH:mm"
266
- };
267
- }
268
- function S(e, t) {
269
- let n = m(e);
270
- if (n.length > t.property.list_max_length) return {
271
- validateSuccess: !1,
272
- validateMessage: `列表长度不能超过 ${t.property.list_max_length}`
273
- };
274
- for (let e of n) if (e.length > t.property.text_max_length) return {
275
- validateSuccess: !1,
276
- validateMessage: `单项文本长度不能超过 ${t.property.text_max_length}`
277
- };
278
- return {
279
- validateSuccess: !0,
280
- validateValue: n
281
- };
282
- }
283
- function C(e, t) {
284
- return e in t.property.option_map ? {
285
- validateSuccess: !0,
286
- validateValue: t.property.option_map[e]
287
- } : {
288
- validateSuccess: !1,
289
- validateMessage: `内容必须是 ${Object.keys(t.property.option_map).join("|")}`
290
- };
291
- }
292
- function w(e, t) {
293
- let n = m(e), r = t.property.option_map, i = [];
294
- for (let e of n) {
295
- if (!(e in r)) return {
296
- validateSuccess: !1,
297
- validateMessage: `内容必须是 ${Object.keys(r).join("|")}`
298
- };
299
- i.push(r[e]);
300
- }
301
- return {
302
- validateSuccess: !0,
303
- validateValue: i
304
- };
305
- }
306
- function T(e, t) {
307
- if (e === null) return t.property.required ? {
308
- validateSuccess: !1,
309
- validateMessage: "不能为空"
310
- } : {
311
- validateSuccess: !0,
312
- validateValue: t.property.default_value
313
- };
314
- if (t.type === "text") return g(e, t);
315
- if (t.type === "number") return _(e, t);
316
- if (t.type === "boolean") return v(e, t);
317
- if (t.type === "date") return y(e);
318
- if (t.type === "time") return b(e);
319
- if (t.type === "datetime") return x(e);
320
- if (t.type === "list") return S(e, t);
321
- if (t.type === "single_choice") return C(e, t);
322
- if (t.type === "multiple_choice") return w(e, t);
323
- throw Error("未知的字段类型");
324
- }
325
- // src/core/limits.ts
326
- var E = 2e4, D = 2e4, O = 20971520;
327
- // src/core/excel/importEditor.ts
328
- function k(e, t) {
329
- if (t != null) {
330
- if (e.type !== "single_choice" && e.type !== "multiple_choice") return String(t);
331
- for (let [n, r] of Object.entries(e.property.option_map)) if (r === t) return n;
332
- return String(t);
333
- }
334
- }
335
- function A(e, t) {
336
- return e.type === "boolean" ? t === !0 ? e.property.true_label : t === !1 ? e.property.false_label : void 0 : e.type === "single_choice" ? k(e, t) : e.type === "multiple_choice" ? Array.isArray(t) ? t.map((t) => k(e, t)).filter(Boolean) : [] : e.type === "list" ? Array.isArray(t) ? p(t) : "" : e.type === "number" ? typeof t == "number" ? t : void 0 : t == null ? "" : String(t);
337
- }
338
- function j(e, t) {
339
- return t === null ? e.type === "multiple_choice" ? [] : "" : e.type === "multiple_choice" ? m(t) : t;
340
- }
341
- function M(e, t) {
342
- return t == null ? "" : e.type === "boolean" || e.type === "single_choice" ? String(t) : (e.type === "multiple_choice" || e.type === "list") && Array.isArray(t) ? p(t) : String(t);
343
- }
344
- // src/core/excel/worksheet.ts
345
- function N(t, n) {
346
- let r = n[t.key];
347
- if (r == null || r === "") return null;
348
- switch (t.type) {
349
- case "datetime": return e(r).format("YYYY-MM-DD HH:mm");
350
- case "boolean": return r ? t.property.true_label : t.property.false_label;
351
- case "single_choice": {
352
- let e = t.property.option_map;
353
- return Object.keys(e).find((t) => e[t] === r) ?? String(r);
354
- }
355
- case "multiple_choice": {
356
- let e = t.property.option_map;
357
- return p((Array.isArray(r) ? r : [r]).map((t) => Object.keys(e).find((n) => e[n] === t) ?? String(t)));
358
- }
359
- case "list": {
360
- let e = Array.isArray(r) ? r : [r], n = t.property.item_key;
361
- return p(e.map((e) => String(n && typeof e == "object" && e ? e[n] ?? "" : e)));
362
- }
363
- default: return r;
364
- }
365
- }
366
- function P(e, t) {
367
- t.forEach((t, n) => {
368
- t.type === "text" && (e.getColumn(n + 1).numFmt = "@");
369
- });
370
- }
371
- function F(e, t, n) {
372
- let r = n.map((e) => e.importable === !1 ? `${e.title}\n(仅导出)` : e.title), i = e.addRow(r);
373
- i.height = 20 + (Math.max(...r.map((e) => e.split("\n").length)) - 1) * 15, i.eachCell({ includeEmpty: !0 }, (e) => {
374
- e.font = {
375
- bold: !0,
376
- size: 14,
377
- color: { argb: "FFFFFFFF" }
378
- }, e.fill = {
379
- type: "pattern",
380
- pattern: "solid",
381
- fgColor: { argb: "FF4472C4" }
382
- }, e.alignment = {
383
- vertical: "middle",
384
- wrapText: !0
385
- };
386
- }), t.forEach((t) => {
387
- e.addRow(n.map((e) => N(e, t))).eachCell({ includeEmpty: !0 }, (e) => {
388
- e.alignment = {
389
- ...e.alignment,
390
- wrapText: !0,
391
- vertical: "top"
392
- };
393
- });
394
- }), P(e, n), R(e);
395
- }
396
- function I(e) {
397
- let t = [e.property.required ? "必填" : "可选"];
398
- switch (e.type) {
399
- case "text":
400
- t.push(`最长 ${e.property.max_length} 个字符`);
401
- break;
402
- case "number":
403
- t.push(`最多 ${e.property.precision} 位小数`), e.property.max_digits !== void 0 && t.push(`整数最多 ${e.property.max_digits - e.property.precision} 位`), e.property.min_value !== void 0 && t.push(`最小 ${e.property.min_value}`), e.property.max_value !== void 0 && t.push(`最大 ${e.property.max_value}`);
404
- break;
405
- case "boolean":
406
- t.push(`填 ${e.property.true_label} 或 ${e.property.false_label}`);
407
- break;
408
- case "date":
409
- t.push("格式 YYYY-MM-DD");
410
- break;
411
- case "time":
412
- t.push("格式 HH:mm");
413
- break;
414
- case "datetime":
415
- t.push("格式 YYYY-MM-DD HH:mm");
416
- break;
417
- case "list":
418
- t.push(`多个值用分号分隔(中英文均可), 最多 ${e.property.list_max_length} 个`);
419
- break;
420
- case "single_choice":
421
- t.push(`填其一: ${Object.keys(e.property.option_map).join(" / ")}`);
422
- break;
423
- case "multiple_choice": t.push(`可多选, 分号分隔(中英文均可): ${Object.keys(e.property.option_map).join(" / ")}`);
424
- }
425
- e.key.endsWith("_name") ? t.push("填对应记录的名称") : e.key.endsWith("_number") && t.push("填对应记录的编号");
426
- let n = N(e, { [e.key]: e.property.default_value });
427
- return t.push(`默认值: ${n == null || n === "" ? "空" : n}`), t.join("\n");
428
- }
429
- function L(e, t) {
430
- let n = t.map((e) => `${e.title}\n\n${I(e)}`), r = e.addRow(n);
431
- r.height = 20 + (Math.max(...n.map((e) => e.split("\n").length)) - 1) * 15, r.eachCell({ includeEmpty: !0 }, (e) => {
432
- e.font = {
433
- bold: !0,
434
- size: 14,
435
- color: { argb: "FFFFFFFF" }
436
- }, e.fill = {
437
- type: "pattern",
438
- pattern: "solid",
439
- fgColor: { argb: "FF4472C4" }
440
- }, e.alignment = {
441
- vertical: "top",
442
- wrapText: !0
443
- };
444
- }), P(e, t), R(e);
445
- }
446
- function R(e, t = 20, n = 60) {
447
- let r = [];
448
- e.eachRow({ includeEmpty: !1 }, (e) => {
449
- e.eachCell({ includeEmpty: !1 }, (e, t) => {
450
- let n = t - 1, i = e.text, a = e.font?.size || 11, o = .8 + a / 11 * .4, s = i.split("\n"), c = 0;
451
- for (let e of s) {
452
- let t = 0;
453
- for (let n of e) {
454
- let e = n.charCodeAt(0);
455
- t += e > 255 || e >= 65280 && e <= 65519 ? 2 : 1;
456
- }
457
- c = Math.max(c, t);
458
- }
459
- let l = c * 7 * (a / 11) * o;
460
- (!r[n] || l > r[n]) && (r[n] = l);
461
- });
462
- }), r.forEach((r, i) => {
463
- let a = r / 7;
464
- e.getColumn(i + 1).width = Math.min(Math.max(a, t), n);
465
- });
466
- }
467
- export { m as S, C as _, A as a, d as b, O as c, y as d, x as f, _ as g, w as h, M as i, E as l, S as m, F as n, j as o, T as p, L as r, D as s, R as t, v as u, g as v, p as x, b as y };