antd-crud-table 0.7.0 → 0.8.0
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/README.md +37 -0
- package/dist/CrudImportModal.d.ts +31 -0
- package/dist/CrudTable-BfVtTGYV.cjs +3 -0
- package/dist/CrudTable-jy8Db0uQ.js +1072 -0
- package/dist/CrudTable.cjs +1 -1
- package/dist/CrudTable.d.ts +10 -0
- package/dist/CrudTable.js +1 -1
- package/dist/CrudTableLazy.cjs +1 -1
- package/dist/CrudTableLazy.js +1 -1
- package/dist/core/RestDataSource.d.ts +97 -8
- package/dist/core/index.d.ts +1 -1
- package/dist/core/types.d.ts +8 -0
- package/dist/{en_US-DGCMDOdX.js → en_US-DghHhwRq.js} +19 -0
- package/dist/en_US-Q8nDeJhg.cjs +1 -0
- package/dist/fields/registry.d.ts +12 -0
- package/dist/hooks/useCrudTable.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +50 -7
- package/dist/locale/types.d.ts +38 -0
- package/dist/{useCrudTable-DxjnXVlQ.js → useCrudTable-BVXxakfl.js} +84 -47
- package/dist/useCrudTable-Ex2Imgll.cjs +1 -0
- package/dist/useCrudTable.cjs +1 -1
- package/dist/useCrudTable.js +1 -1
- package/dist/useLocalStorageCrud.cjs +1 -1
- package/dist/useLocalStorageCrud.js +1 -1
- package/dist/utils/importData.d.ts +130 -0
- package/dist/utils/importSpreadsheetML.d.ts +8 -0
- package/dist/utils/importXlsx.d.ts +7 -0
- package/package.json +6 -1
- package/dist/CrudTable-Btf58zof.js +0 -610
- package/dist/CrudTable-DRN70sET.cjs +0 -1
- package/dist/en_US-D3Kl6g3n.cjs +0 -1
- package/dist/useCrudTable-40jpmCkr.cjs +0 -1
|
@@ -0,0 +1,1072 @@
|
|
|
1
|
+
import { n as e, t } from "./useCrudTable-BVXxakfl.js";
|
|
2
|
+
import { t as n } from "./en_US-DghHhwRq.js";
|
|
3
|
+
import { exportData as r } from "./exportData.js";
|
|
4
|
+
import { EllipsisOutlined as i, InboxOutlined as a, PlusOutlined as o } from "@ant-design/icons";
|
|
5
|
+
import { ProConfigProvider as s, ProTable as c, enUSIntl as l, findIntlKeyByAntdLocaleKey as u, intlMap as d } from "@ant-design/pro-components";
|
|
6
|
+
import { Alert as f, Button as p, ColorPicker as m, ConfigProvider as h, DatePicker as g, Dropdown as ee, Form as _, Image as te, Input as v, InputNumber as y, Modal as b, Progress as x, Rate as S, Select as C, Space as w, Switch as ne, Table as re, Tag as T, TimePicker as ie, Typography as E, Upload as D, message as O } from "antd";
|
|
7
|
+
import { useCallback as k, useContext as A, useMemo as j, useRef as M, useState as N } from "react";
|
|
8
|
+
import P from "dayjs";
|
|
9
|
+
import { Fragment as F, jsx as I, jsxs as L } from "react/jsx-runtime";
|
|
10
|
+
import R from "antd/locale/en_US";
|
|
11
|
+
//#region lib/fields/registry.tsx
|
|
12
|
+
var z = (e, t) => t[e.dataIndex], B = (e) => e != null && e !== "", V = (e) => B(e) ? String(e) : "", H = (e) => {
|
|
13
|
+
let t = Number(e);
|
|
14
|
+
return Number.isFinite(t) ? t : 0;
|
|
15
|
+
}, ae = (e) => String(e), U = (e) => {
|
|
16
|
+
let t = e.trim();
|
|
17
|
+
if (t === "") return e;
|
|
18
|
+
let n = Number(t);
|
|
19
|
+
return Number.isFinite(n) ? n : e;
|
|
20
|
+
}, W = /* @__PURE__ */ new Set([
|
|
21
|
+
"yes",
|
|
22
|
+
"true",
|
|
23
|
+
"1",
|
|
24
|
+
"y",
|
|
25
|
+
"t"
|
|
26
|
+
]), G = /* @__PURE__ */ new Set([
|
|
27
|
+
"no",
|
|
28
|
+
"false",
|
|
29
|
+
"0",
|
|
30
|
+
"n",
|
|
31
|
+
"f"
|
|
32
|
+
]), oe = (e) => {
|
|
33
|
+
let t = e.trim().toLowerCase();
|
|
34
|
+
return W.has(t) ? !0 : !G.has(t) && e;
|
|
35
|
+
}, se = ["http", "https"], ce = [
|
|
36
|
+
"http",
|
|
37
|
+
"https",
|
|
38
|
+
"mailto"
|
|
39
|
+
], le = /^([a-z][a-z0-9+.-]*):/i, ue = /^data:image\/(png|jpe?g|gif|webp|avif|bmp|x-icon)[;,]/i, K = (e, t) => {
|
|
40
|
+
let n = e.replace(/[\u0000-\u0020\u007F-\u009F]/g, ""), r = le.exec(n);
|
|
41
|
+
return !r || t.includes(r[1].toLowerCase());
|
|
42
|
+
}, q = (e) => {
|
|
43
|
+
let t = e.replace(/[\u0000-\u0020\u007F-\u009F]/g, "");
|
|
44
|
+
return ue.test(t) ? !0 : K(e, se);
|
|
45
|
+
}, de = "YYYY-MM-DD HH:mm", J = "YYYY-MM-DD", fe = "HH:mm:ss", Y = {
|
|
46
|
+
string: { formControl: (e, t) => /* @__PURE__ */ I(v, { disabled: t }) },
|
|
47
|
+
number: {
|
|
48
|
+
column: (e) => ({
|
|
49
|
+
valueType: "digit",
|
|
50
|
+
render: (t, n) => {
|
|
51
|
+
let r = z(e, n);
|
|
52
|
+
return typeof r == "number" ? r.toLocaleString() : V(r);
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
formControl: (e, t) => /* @__PURE__ */ I(y, {
|
|
56
|
+
style: { width: "100%" },
|
|
57
|
+
disabled: t
|
|
58
|
+
}),
|
|
59
|
+
fromImportValue: U
|
|
60
|
+
},
|
|
61
|
+
date: {
|
|
62
|
+
column: (e, t) => ({
|
|
63
|
+
valueType: "dateTime",
|
|
64
|
+
render: (n, r) => {
|
|
65
|
+
let i = z(e, r);
|
|
66
|
+
if (!i) return t.empty;
|
|
67
|
+
let a = P(V(i));
|
|
68
|
+
return /* @__PURE__ */ I("span", { children: a.isValid() ? a.format(de) : V(i) });
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
formControl: (e, t) => /* @__PURE__ */ I(g, {
|
|
72
|
+
style: { width: "100%" },
|
|
73
|
+
showTime: !0,
|
|
74
|
+
disabled: t
|
|
75
|
+
}),
|
|
76
|
+
toFormValue: (e) => B(e) ? P(V(e)) : e,
|
|
77
|
+
fromFormValue: (e) => P.isDayjs(e) ? e.toISOString() : e,
|
|
78
|
+
fromImportValue: (e) => {
|
|
79
|
+
let t = P(e);
|
|
80
|
+
return t.isValid() ? t.toISOString() : e;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
boolean: {
|
|
84
|
+
column: (e, t) => ({
|
|
85
|
+
valueType: "switch",
|
|
86
|
+
render: (n, r) => /* @__PURE__ */ I(T, {
|
|
87
|
+
color: z(e, r) ? "green" : "red",
|
|
88
|
+
children: z(e, r) ? t.yes : t.no
|
|
89
|
+
})
|
|
90
|
+
}),
|
|
91
|
+
formControl: (e, t) => /* @__PURE__ */ I(ne, { disabled: t }),
|
|
92
|
+
valuePropName: "checked",
|
|
93
|
+
fromImportValue: oe
|
|
94
|
+
},
|
|
95
|
+
enum: {
|
|
96
|
+
column: (e) => ({
|
|
97
|
+
valueType: "select",
|
|
98
|
+
valueEnum: e.enumOptions,
|
|
99
|
+
render: (t, n) => {
|
|
100
|
+
let r = z(e, n), i = e.enumOptions?.[ae(r)];
|
|
101
|
+
return i ? /* @__PURE__ */ I(T, {
|
|
102
|
+
color: i.color,
|
|
103
|
+
children: i.text
|
|
104
|
+
}) : V(r);
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
formControl: (e, t, n) => /* @__PURE__ */ I(C, {
|
|
108
|
+
disabled: t,
|
|
109
|
+
placeholder: n.selectPlaceholder(e.title),
|
|
110
|
+
options: Object.entries(e.enumOptions || {}).map(([e, t]) => ({
|
|
111
|
+
label: t.text,
|
|
112
|
+
value: e
|
|
113
|
+
}))
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
custom: {
|
|
117
|
+
column: (e) => ({ render: (t, n) => e.customRender?.(z(e, n), n) ?? null }),
|
|
118
|
+
formControl: () => null
|
|
119
|
+
},
|
|
120
|
+
textarea: {
|
|
121
|
+
column: () => ({
|
|
122
|
+
valueType: "textarea",
|
|
123
|
+
ellipsis: !0
|
|
124
|
+
}),
|
|
125
|
+
formControl: (e, t) => /* @__PURE__ */ I(v.TextArea, {
|
|
126
|
+
rows: 3,
|
|
127
|
+
disabled: t
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
email: {
|
|
131
|
+
column: (e, t) => ({ render: (n, r) => {
|
|
132
|
+
let i = z(e, r);
|
|
133
|
+
if (!B(i)) return t.empty;
|
|
134
|
+
let a = V(i);
|
|
135
|
+
return K(a, ce) ? /* @__PURE__ */ I("a", {
|
|
136
|
+
href: `mailto:${encodeURIComponent(a)}`,
|
|
137
|
+
children: a
|
|
138
|
+
}) : /* @__PURE__ */ I("span", { children: a });
|
|
139
|
+
} }),
|
|
140
|
+
formControl: (e, t) => /* @__PURE__ */ I(v, {
|
|
141
|
+
type: "email",
|
|
142
|
+
disabled: t
|
|
143
|
+
}),
|
|
144
|
+
rules: (e, t) => [{
|
|
145
|
+
type: "email",
|
|
146
|
+
message: t.invalidEmail
|
|
147
|
+
}]
|
|
148
|
+
},
|
|
149
|
+
url: {
|
|
150
|
+
column: (e, t) => ({ render: (n, r) => {
|
|
151
|
+
let i = z(e, r);
|
|
152
|
+
if (!B(i)) return t.empty;
|
|
153
|
+
let a = V(i);
|
|
154
|
+
return K(a, se) ? /* @__PURE__ */ I("a", {
|
|
155
|
+
href: a,
|
|
156
|
+
target: "_blank",
|
|
157
|
+
rel: "noopener noreferrer",
|
|
158
|
+
children: a
|
|
159
|
+
}) : /* @__PURE__ */ I("span", { children: a });
|
|
160
|
+
} }),
|
|
161
|
+
formControl: (e, t) => /* @__PURE__ */ I(v, { disabled: t }),
|
|
162
|
+
rules: (e, t) => [{
|
|
163
|
+
type: "url",
|
|
164
|
+
message: t.invalidUrl
|
|
165
|
+
}]
|
|
166
|
+
},
|
|
167
|
+
password: {
|
|
168
|
+
column: (e, t) => ({
|
|
169
|
+
search: !1,
|
|
170
|
+
render: (n, r) => B(z(e, r)) ? "••••••••" : t.empty
|
|
171
|
+
}),
|
|
172
|
+
formControl: (e, t) => /* @__PURE__ */ I(v.Password, { disabled: t })
|
|
173
|
+
},
|
|
174
|
+
money: {
|
|
175
|
+
column: () => ({ valueType: "money" }),
|
|
176
|
+
formControl: (e, t) => /* @__PURE__ */ I(y, {
|
|
177
|
+
style: { width: "100%" },
|
|
178
|
+
precision: 2,
|
|
179
|
+
min: 0,
|
|
180
|
+
disabled: t
|
|
181
|
+
}),
|
|
182
|
+
fromImportValue: U
|
|
183
|
+
},
|
|
184
|
+
percent: {
|
|
185
|
+
column: () => ({ valueType: "percent" }),
|
|
186
|
+
formControl: (e, t) => /* @__PURE__ */ I(y, {
|
|
187
|
+
style: { width: "100%" },
|
|
188
|
+
min: 0,
|
|
189
|
+
max: 100,
|
|
190
|
+
addonAfter: "%",
|
|
191
|
+
disabled: t
|
|
192
|
+
}),
|
|
193
|
+
fromImportValue: U
|
|
194
|
+
},
|
|
195
|
+
rating: {
|
|
196
|
+
column: (e) => ({
|
|
197
|
+
search: !1,
|
|
198
|
+
render: (t, n) => /* @__PURE__ */ I(S, {
|
|
199
|
+
disabled: !0,
|
|
200
|
+
allowHalf: !0,
|
|
201
|
+
value: H(z(e, n))
|
|
202
|
+
})
|
|
203
|
+
}),
|
|
204
|
+
formControl: (e, t) => /* @__PURE__ */ I(S, {
|
|
205
|
+
allowHalf: !0,
|
|
206
|
+
disabled: t
|
|
207
|
+
}),
|
|
208
|
+
fromImportValue: U
|
|
209
|
+
},
|
|
210
|
+
progress: {
|
|
211
|
+
column: (e) => ({
|
|
212
|
+
search: !1,
|
|
213
|
+
render: (t, n) => /* @__PURE__ */ I(x, {
|
|
214
|
+
percent: H(z(e, n)),
|
|
215
|
+
size: "small"
|
|
216
|
+
})
|
|
217
|
+
}),
|
|
218
|
+
formControl: (e, t) => /* @__PURE__ */ I(y, {
|
|
219
|
+
style: { width: "100%" },
|
|
220
|
+
min: 0,
|
|
221
|
+
max: 100,
|
|
222
|
+
disabled: t
|
|
223
|
+
}),
|
|
224
|
+
fromImportValue: U
|
|
225
|
+
},
|
|
226
|
+
time: {
|
|
227
|
+
column: () => ({ valueType: "time" }),
|
|
228
|
+
formControl: (e, t) => /* @__PURE__ */ I(ie, {
|
|
229
|
+
style: { width: "100%" },
|
|
230
|
+
disabled: t
|
|
231
|
+
}),
|
|
232
|
+
toFormValue: (e) => B(e) ? P(V(e), fe) : e,
|
|
233
|
+
fromFormValue: (e) => P.isDayjs(e) ? e.format(fe) : e
|
|
234
|
+
},
|
|
235
|
+
dateRange: {
|
|
236
|
+
column: (e, t) => ({
|
|
237
|
+
valueType: "dateRange",
|
|
238
|
+
render: (n, r) => {
|
|
239
|
+
let i = z(e, r);
|
|
240
|
+
if (!Array.isArray(i) || i.length !== 2) return t.empty;
|
|
241
|
+
let [a, o] = i.map((e) => P(V(e)));
|
|
242
|
+
return !a.isValid() || !o.isValid() ? V(i) : `${a.format(J)} ~ ${o.format(J)}`;
|
|
243
|
+
}
|
|
244
|
+
}),
|
|
245
|
+
formControl: (e, t) => /* @__PURE__ */ I(g.RangePicker, {
|
|
246
|
+
style: { width: "100%" },
|
|
247
|
+
disabled: t
|
|
248
|
+
}),
|
|
249
|
+
toFormValue: (e) => Array.isArray(e) ? e.map((e) => B(e) ? P(V(e)) : e) : e,
|
|
250
|
+
fromFormValue: (e) => Array.isArray(e) ? e.map((e) => P.isDayjs(e) ? e.toISOString() : e) : e,
|
|
251
|
+
fromImportValue: (e) => {
|
|
252
|
+
let t = e.split(",").map((e) => e.trim()).filter((e) => e !== "");
|
|
253
|
+
if (t.length !== 2) return e;
|
|
254
|
+
let n = t.map((e) => P(e));
|
|
255
|
+
return n.every((e) => e.isValid()) ? n.map((e) => e.toISOString()) : e;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
tags: {
|
|
259
|
+
column: (e, t) => ({ render: (n, r) => {
|
|
260
|
+
let i = z(e, r);
|
|
261
|
+
return !Array.isArray(i) || i.length === 0 ? t.empty : /* @__PURE__ */ I(F, { children: i.map((e) => /* @__PURE__ */ I(T, { children: V(e) }, V(e))) });
|
|
262
|
+
} }),
|
|
263
|
+
formControl: (e, t, n) => /* @__PURE__ */ I(C, {
|
|
264
|
+
mode: "tags",
|
|
265
|
+
open: !1,
|
|
266
|
+
suffixIcon: null,
|
|
267
|
+
disabled: t,
|
|
268
|
+
placeholder: n.tagsPlaceholder
|
|
269
|
+
}),
|
|
270
|
+
fromImportValue: (e) => e.split(",").map((e) => e.trim()).filter((e) => e !== "")
|
|
271
|
+
},
|
|
272
|
+
image: {
|
|
273
|
+
column: (e, t) => ({
|
|
274
|
+
search: !1,
|
|
275
|
+
render: (n, r) => {
|
|
276
|
+
let i = z(e, r);
|
|
277
|
+
if (!B(i)) return t.empty;
|
|
278
|
+
let a = V(i);
|
|
279
|
+
return q(a) ? /* @__PURE__ */ I(te, {
|
|
280
|
+
src: a,
|
|
281
|
+
width: 48,
|
|
282
|
+
height: 48,
|
|
283
|
+
style: { objectFit: "cover" }
|
|
284
|
+
}) : /* @__PURE__ */ I("span", { children: a });
|
|
285
|
+
}
|
|
286
|
+
}),
|
|
287
|
+
formControl: (e, t) => /* @__PURE__ */ I(v, {
|
|
288
|
+
placeholder: "https://...",
|
|
289
|
+
disabled: t
|
|
290
|
+
}),
|
|
291
|
+
rules: (e, t) => [{
|
|
292
|
+
type: "url",
|
|
293
|
+
message: t.invalidImageUrl
|
|
294
|
+
}]
|
|
295
|
+
},
|
|
296
|
+
color: {
|
|
297
|
+
column: (e, t) => ({
|
|
298
|
+
search: !1,
|
|
299
|
+
render: (n, r) => {
|
|
300
|
+
let i = z(e, r);
|
|
301
|
+
if (!B(i)) return t.empty;
|
|
302
|
+
let a = V(i);
|
|
303
|
+
return /* @__PURE__ */ L("span", {
|
|
304
|
+
style: {
|
|
305
|
+
display: "inline-flex",
|
|
306
|
+
alignItems: "center",
|
|
307
|
+
gap: 8
|
|
308
|
+
},
|
|
309
|
+
children: [/* @__PURE__ */ I("span", { style: {
|
|
310
|
+
display: "inline-block",
|
|
311
|
+
width: 14,
|
|
312
|
+
height: 14,
|
|
313
|
+
borderRadius: 3,
|
|
314
|
+
border: "1px solid rgba(0,0,0,0.15)",
|
|
315
|
+
backgroundColor: a
|
|
316
|
+
} }), a]
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}),
|
|
320
|
+
formControl: (e, t) => /* @__PURE__ */ I(m, {
|
|
321
|
+
showText: !0,
|
|
322
|
+
disabled: t
|
|
323
|
+
}),
|
|
324
|
+
fromFormValue: (e) => e && typeof e == "object" && "toHexString" in e ? e.toHexString() : e
|
|
325
|
+
},
|
|
326
|
+
json: {
|
|
327
|
+
column: (e, t) => ({
|
|
328
|
+
search: !1,
|
|
329
|
+
ellipsis: !0,
|
|
330
|
+
render: (n, r) => {
|
|
331
|
+
let i = z(e, r);
|
|
332
|
+
return i == null ? t.empty : /* @__PURE__ */ I(E.Text, {
|
|
333
|
+
code: !0,
|
|
334
|
+
children: JSON.stringify(i)
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}),
|
|
338
|
+
formControl: (e, t) => /* @__PURE__ */ I(v.TextArea, {
|
|
339
|
+
rows: 4,
|
|
340
|
+
style: { fontFamily: "monospace" },
|
|
341
|
+
disabled: t
|
|
342
|
+
}),
|
|
343
|
+
toFormValue: (e) => typeof e == "string" ? e : JSON.stringify(e, null, 2),
|
|
344
|
+
fromFormValue: (e) => typeof e == "string" && e.trim() !== "" ? JSON.parse(e) : e,
|
|
345
|
+
fromImportValue: (e) => e.trim() === "" ? e : JSON.parse(e),
|
|
346
|
+
rules: (e, t) => [{ validator: async (e, n) => {
|
|
347
|
+
if (n != null && n !== "" && typeof n == "string") try {
|
|
348
|
+
JSON.parse(n);
|
|
349
|
+
} catch {
|
|
350
|
+
throw Error(t.invalidJson);
|
|
351
|
+
}
|
|
352
|
+
} }]
|
|
353
|
+
}
|
|
354
|
+
}, X = (e) => Y[e ?? "string"] ?? Y.string, pe = n, me = (e) => {
|
|
355
|
+
let t = A(h.ConfigContext).locale;
|
|
356
|
+
return j(() => {
|
|
357
|
+
let r = e ? {
|
|
358
|
+
...n,
|
|
359
|
+
...e
|
|
360
|
+
} : n, i = t?.locale ? u(t.locale) : void 0;
|
|
361
|
+
return {
|
|
362
|
+
strings: r,
|
|
363
|
+
intl: i && ((e) => e in d)(i) ? d[i] : l,
|
|
364
|
+
antdLocale: t ? void 0 : R,
|
|
365
|
+
inherited: !!t
|
|
366
|
+
};
|
|
367
|
+
}, [e, t]);
|
|
368
|
+
}, Z = (e, t = ",") => {
|
|
369
|
+
let n = t.charAt(0);
|
|
370
|
+
e.charCodeAt(0) === 65279 && (e = e.slice(1));
|
|
371
|
+
let r = [], i = [], a = "", o = !1, s = 0, c = () => {
|
|
372
|
+
i.push(a), a = "";
|
|
373
|
+
}, l = () => {
|
|
374
|
+
c(), r.push(i), i = [];
|
|
375
|
+
};
|
|
376
|
+
for (; s < e.length;) {
|
|
377
|
+
let t = e[s];
|
|
378
|
+
if (o) {
|
|
379
|
+
if (t === "\"") {
|
|
380
|
+
if (e[s + 1] === "\"") {
|
|
381
|
+
a += "\"", s += 2;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
o = !1, s++;
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
a += t, s++;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
t === "\"" ? (o = !0, s++) : t === n ? (c(), s++) : t === "\n" ? (l(), s++) : t === "\r" ? (l(), s += e[s + 1] === "\n" ? 2 : 1) : (a += t, s++);
|
|
391
|
+
}
|
|
392
|
+
return (a !== "" || i.length > 0) && l(), r.length > 0 && r[r.length - 1].length === 1 && r[r.length - 1][0] === "" && r.pop(), r;
|
|
393
|
+
}, he = (e) => {
|
|
394
|
+
if (e.length === 0) return {
|
|
395
|
+
headers: [],
|
|
396
|
+
rows: []
|
|
397
|
+
};
|
|
398
|
+
let [t, ...n] = e;
|
|
399
|
+
return {
|
|
400
|
+
headers: t.map((e) => String(e ?? "")),
|
|
401
|
+
rows: n
|
|
402
|
+
};
|
|
403
|
+
}, Q = { csv: (e) => he(Z(typeof e == "string" ? e : _e(e))) }, ge = (e, t) => {
|
|
404
|
+
Q[e] = t;
|
|
405
|
+
}, _e = (e) => new TextDecoder("utf-8").decode(e), ve = (e) => {
|
|
406
|
+
let t = e.toLowerCase().split(".").pop();
|
|
407
|
+
if (t === "csv") return "csv";
|
|
408
|
+
if (t === "xls") return "xls";
|
|
409
|
+
if (t === "xlsx") return "xlsx";
|
|
410
|
+
}, ye = async (e, t) => {
|
|
411
|
+
let n = Q[t];
|
|
412
|
+
if (!n) throw Error(`No parser registered for "${t}" import`);
|
|
413
|
+
return n(e);
|
|
414
|
+
}, be = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), xe = (e, t) => {
|
|
415
|
+
let n = t.filter((e) => e.fieldType !== "password"), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
416
|
+
for (let e of n) r.set(be(e.title), e.dataIndex), i.set(be(e.dataIndex), e.dataIndex);
|
|
417
|
+
let a = /* @__PURE__ */ new Set();
|
|
418
|
+
return e.map((e) => {
|
|
419
|
+
let t = be(e), n = r.get(t) ?? i.get(t);
|
|
420
|
+
return n && !a.has(n) ? (a.add(n), n) : null;
|
|
421
|
+
});
|
|
422
|
+
}, Se = (e, t) => {
|
|
423
|
+
if (!t || e in t) return e;
|
|
424
|
+
let n = e.trim().toLowerCase();
|
|
425
|
+
for (let [e, r] of Object.entries(t)) if (r.text.toLowerCase() === n || e.toLowerCase() === n) return e;
|
|
426
|
+
return e;
|
|
427
|
+
}, Ce = (e, t) => {
|
|
428
|
+
if (t.fieldType === "enum") return Se(e, t.enumOptions);
|
|
429
|
+
let { fromImportValue: n } = X(t.fieldType);
|
|
430
|
+
return n ? n(e) : e;
|
|
431
|
+
}, we = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, Te = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, $ = (e, t) => {
|
|
432
|
+
let n = e.message;
|
|
433
|
+
return typeof n == "string" ? n : t;
|
|
434
|
+
}, Ee = async (e, t, n) => {
|
|
435
|
+
if (!e || e.length === 0) return null;
|
|
436
|
+
for (let r of e) {
|
|
437
|
+
if (typeof r == "function") continue;
|
|
438
|
+
let e = r;
|
|
439
|
+
if (e.required && Te(t)) return $(e, `${n} is required`);
|
|
440
|
+
if (!Te(t)) {
|
|
441
|
+
if (e.type === "email" && typeof t == "string" && !we.test(t)) return $(e, `${n} is not a valid email`);
|
|
442
|
+
if (e.type === "url" && typeof t == "string") try {
|
|
443
|
+
new URL(t);
|
|
444
|
+
} catch {
|
|
445
|
+
return $(e, `${n} is not a valid URL`);
|
|
446
|
+
}
|
|
447
|
+
if (e.pattern instanceof RegExp && typeof t == "string" && !e.pattern.test(t)) return $(e, `${n} is invalid`);
|
|
448
|
+
if (typeof e.len == "number" && typeof t == "string" && t.length !== e.len) return $(e, `${n} must be ${e.len} characters`);
|
|
449
|
+
if (typeof e.min == "number" && (typeof t == "number" ? t : String(t).length) < e.min) return $(e, `${n} is too small`);
|
|
450
|
+
if (typeof e.max == "number" && (typeof t == "number" ? t : String(t).length) > e.max) return $(e, `${n} is too large`);
|
|
451
|
+
if (typeof e.validator == "function") try {
|
|
452
|
+
await e.validator(e, t, () => void 0);
|
|
453
|
+
} catch (t) {
|
|
454
|
+
return t instanceof Error && t.message ? t.message : $(e, `${n} is invalid`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return null;
|
|
459
|
+
}, De = async (e, t, n) => {
|
|
460
|
+
let r = new Map(n.map((e) => [e.dataIndex, e])), i = [];
|
|
461
|
+
for (let n = 0; n < e.rows.length; n++) {
|
|
462
|
+
let a = e.rows[n], o = {}, s = [];
|
|
463
|
+
for (let e = 0; e < t.length; e++) {
|
|
464
|
+
let n = t[e];
|
|
465
|
+
if (!n) continue;
|
|
466
|
+
let i = r.get(n);
|
|
467
|
+
if (!i || i.fieldType === "password") continue;
|
|
468
|
+
let c = a[e] ?? "", l;
|
|
469
|
+
try {
|
|
470
|
+
l = Ce(c, i);
|
|
471
|
+
} catch (e) {
|
|
472
|
+
s.push({
|
|
473
|
+
field: n,
|
|
474
|
+
message: e instanceof Error ? e.message : `${i.title} is invalid`
|
|
475
|
+
});
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
Te(l) || (o[n] = l);
|
|
479
|
+
let u = await Ee(i.rules, o[n] ?? l, i.title);
|
|
480
|
+
u && s.push({
|
|
481
|
+
field: n,
|
|
482
|
+
message: u
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
i.push({
|
|
486
|
+
rowNumber: n + 1,
|
|
487
|
+
record: o,
|
|
488
|
+
errors: s
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
return i;
|
|
492
|
+
}, Oe = async (e, t, n = {}) => {
|
|
493
|
+
let r = Math.max(1, n.concurrency ?? 5), i = [], a = e.filter((e) => e.errors.length > 0);
|
|
494
|
+
for (let e of a) i.push({
|
|
495
|
+
rowNumber: e.rowNumber,
|
|
496
|
+
ok: !1,
|
|
497
|
+
error: e.errors.map((e) => e.message).join("; ")
|
|
498
|
+
});
|
|
499
|
+
let o = e.filter((e) => e.errors.length === 0);
|
|
500
|
+
if (t.createMany && o.length > 0) try {
|
|
501
|
+
await t.createMany(o.map((e) => e.record));
|
|
502
|
+
for (let e of o) i.push({
|
|
503
|
+
rowNumber: e.rowNumber,
|
|
504
|
+
ok: !0
|
|
505
|
+
});
|
|
506
|
+
} catch (e) {
|
|
507
|
+
let t = e instanceof Error ? e.message : "Create failed";
|
|
508
|
+
for (let e of o) i.push({
|
|
509
|
+
rowNumber: e.rowNumber,
|
|
510
|
+
ok: !1,
|
|
511
|
+
error: t
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
let e = 0;
|
|
516
|
+
await Promise.all(Array.from({ length: Math.min(r, o.length) }, async () => {
|
|
517
|
+
for (; e < o.length;) {
|
|
518
|
+
let n = o[e++];
|
|
519
|
+
try {
|
|
520
|
+
await t.create(n.record), i.push({
|
|
521
|
+
rowNumber: n.rowNumber,
|
|
522
|
+
ok: !0
|
|
523
|
+
});
|
|
524
|
+
} catch (e) {
|
|
525
|
+
i.push({
|
|
526
|
+
rowNumber: n.rowNumber,
|
|
527
|
+
ok: !1,
|
|
528
|
+
error: e instanceof Error ? e.message : "Create failed"
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
i.sort((e, t) => e.rowNumber - t.rowNumber);
|
|
535
|
+
let s = i.filter((e) => e.ok).length;
|
|
536
|
+
return {
|
|
537
|
+
created: s,
|
|
538
|
+
invalid: a.length,
|
|
539
|
+
failed: i.length - s - a.length,
|
|
540
|
+
outcomes: i
|
|
541
|
+
};
|
|
542
|
+
}, ke = 100, Ae = {
|
|
543
|
+
csv: ".csv",
|
|
544
|
+
xls: ".xls",
|
|
545
|
+
xlsx: ".xlsx"
|
|
546
|
+
}, je = ({ open: e, columns: t, formats: n, sink: r, concurrency: i, locale: o, onImported: s, onClose: c }) => {
|
|
547
|
+
let l = j(() => t.filter((e) => e.fieldType !== "password"), [t]), [u, d] = N(null), [p, m] = N([]), [h, g] = N([]), [ee, _] = N(!1), [te, v] = N(!1), y = k(() => {
|
|
548
|
+
d(null), m([]), g([]), _(!1), v(!1);
|
|
549
|
+
}, []), x = k(() => {
|
|
550
|
+
y(), c();
|
|
551
|
+
}, [y, c]), S = k(async (e, n) => {
|
|
552
|
+
_(!0);
|
|
553
|
+
try {
|
|
554
|
+
g(await De(e, n, t));
|
|
555
|
+
} finally {
|
|
556
|
+
_(!1);
|
|
557
|
+
}
|
|
558
|
+
}, [t]), ne = k(async (e) => {
|
|
559
|
+
let r = ve(e.name);
|
|
560
|
+
if (!r || !n.includes(r)) return O.error(o.importUnsupportedFormat(e.name)), !1;
|
|
561
|
+
try {
|
|
562
|
+
let n = await ye(await e.arrayBuffer(), r), i = xe(n.headers, t);
|
|
563
|
+
d(n), m(i), await S(n, i);
|
|
564
|
+
} catch (e) {
|
|
565
|
+
O.error(o.importParseFailed(e instanceof Error ? e.message : String(e)));
|
|
566
|
+
}
|
|
567
|
+
return !1;
|
|
568
|
+
}, [
|
|
569
|
+
t,
|
|
570
|
+
n,
|
|
571
|
+
o,
|
|
572
|
+
S
|
|
573
|
+
]), ie = k((e, t) => {
|
|
574
|
+
if (!u) return;
|
|
575
|
+
let n = p.slice();
|
|
576
|
+
if (t) for (let e = 0; e < n.length; e++) n[e] === t && (n[e] = null);
|
|
577
|
+
n[e] = t, m(n), S(u, n);
|
|
578
|
+
}, [
|
|
579
|
+
u,
|
|
580
|
+
p,
|
|
581
|
+
S
|
|
582
|
+
]), A = h.filter((e) => e.errors.length === 0).length, M = h.length - A, P = k(async () => {
|
|
583
|
+
if (A === 0) {
|
|
584
|
+
O.warning(o.importNothingValid);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
v(!0);
|
|
588
|
+
try {
|
|
589
|
+
let e = await Oe(h, r, { concurrency: i });
|
|
590
|
+
s({
|
|
591
|
+
created: e.created,
|
|
592
|
+
invalid: e.invalid,
|
|
593
|
+
failed: e.failed
|
|
594
|
+
}), x();
|
|
595
|
+
} finally {
|
|
596
|
+
v(!1);
|
|
597
|
+
}
|
|
598
|
+
}, [
|
|
599
|
+
A,
|
|
600
|
+
h,
|
|
601
|
+
r,
|
|
602
|
+
i,
|
|
603
|
+
o,
|
|
604
|
+
s,
|
|
605
|
+
x
|
|
606
|
+
]), F = j(() => [{
|
|
607
|
+
value: "",
|
|
608
|
+
label: o.importIgnoreColumn
|
|
609
|
+
}, ...l.map((e) => ({
|
|
610
|
+
value: e.dataIndex,
|
|
611
|
+
label: e.title
|
|
612
|
+
}))], [l, o.importIgnoreColumn]), R = j(() => h.slice(0, ke), [h]), z = j(() => p.filter((e) => !!e), [p]), B = j(() => {
|
|
613
|
+
let e = new Map(t.map((e) => [e.dataIndex, e])), n = [{
|
|
614
|
+
title: o.importRowLabel,
|
|
615
|
+
dataIndex: "__row",
|
|
616
|
+
key: "__row",
|
|
617
|
+
width: 64,
|
|
618
|
+
fixed: "left"
|
|
619
|
+
}, {
|
|
620
|
+
title: o.importStatusLabel,
|
|
621
|
+
dataIndex: "__status",
|
|
622
|
+
key: "__status",
|
|
623
|
+
width: 200,
|
|
624
|
+
fixed: "left",
|
|
625
|
+
render: (e, t) => t.errors.length === 0 ? /* @__PURE__ */ I(T, {
|
|
626
|
+
color: "green",
|
|
627
|
+
children: o.importRowValid
|
|
628
|
+
}) : /* @__PURE__ */ I(w, {
|
|
629
|
+
direction: "vertical",
|
|
630
|
+
size: 0,
|
|
631
|
+
children: t.errors.map((e) => /* @__PURE__ */ I(E.Text, {
|
|
632
|
+
type: "danger",
|
|
633
|
+
style: { fontSize: 12 },
|
|
634
|
+
children: e.message
|
|
635
|
+
}, e.field))
|
|
636
|
+
})
|
|
637
|
+
}], r = z.map((t) => ({
|
|
638
|
+
title: e.get(t)?.title ?? t,
|
|
639
|
+
dataIndex: t,
|
|
640
|
+
key: t,
|
|
641
|
+
ellipsis: !0,
|
|
642
|
+
render: (e, n) => {
|
|
643
|
+
let r = n.record[t];
|
|
644
|
+
return r == null ? o.empty : typeof r == "object" ? JSON.stringify(r) : String(r);
|
|
645
|
+
}
|
|
646
|
+
}));
|
|
647
|
+
return [...n, ...r];
|
|
648
|
+
}, [
|
|
649
|
+
t,
|
|
650
|
+
z,
|
|
651
|
+
o
|
|
652
|
+
]), V = n.map((e) => Ae[e]).join(","), H = n.map((e) => e.toUpperCase()).join(", ");
|
|
653
|
+
return /* @__PURE__ */ I(b, {
|
|
654
|
+
title: o.importTitle,
|
|
655
|
+
open: e,
|
|
656
|
+
onCancel: x,
|
|
657
|
+
width: 880,
|
|
658
|
+
okText: o.importRun,
|
|
659
|
+
cancelText: u ? o.importBack : o.cancel,
|
|
660
|
+
onOk: () => void P(),
|
|
661
|
+
okButtonProps: {
|
|
662
|
+
disabled: !u || A === 0 || ee,
|
|
663
|
+
loading: te
|
|
664
|
+
},
|
|
665
|
+
cancelButtonProps: u ? { onClick: y } : void 0,
|
|
666
|
+
destroyOnHidden: !0,
|
|
667
|
+
children: u ? /* @__PURE__ */ L(w, {
|
|
668
|
+
direction: "vertical",
|
|
669
|
+
size: "middle",
|
|
670
|
+
style: { width: "100%" },
|
|
671
|
+
children: [
|
|
672
|
+
/* @__PURE__ */ L("div", { children: [/* @__PURE__ */ I(E.Title, {
|
|
673
|
+
level: 5,
|
|
674
|
+
children: o.importMapColumns
|
|
675
|
+
}), /* @__PURE__ */ I(w, {
|
|
676
|
+
wrap: !0,
|
|
677
|
+
size: [12, 12],
|
|
678
|
+
children: u.headers.map((e, t) => /* @__PURE__ */ L(w, {
|
|
679
|
+
direction: "vertical",
|
|
680
|
+
size: 2,
|
|
681
|
+
children: [/* @__PURE__ */ I(E.Text, {
|
|
682
|
+
type: "secondary",
|
|
683
|
+
style: { fontSize: 12 },
|
|
684
|
+
children: e || `#${t + 1}`
|
|
685
|
+
}), /* @__PURE__ */ I(C, {
|
|
686
|
+
size: "small",
|
|
687
|
+
style: { width: 200 },
|
|
688
|
+
value: p[t] ?? "",
|
|
689
|
+
options: F,
|
|
690
|
+
onChange: (e) => ie(t, e === "" ? null : e)
|
|
691
|
+
})]
|
|
692
|
+
}, `${e}-${t}`))
|
|
693
|
+
})] }),
|
|
694
|
+
/* @__PURE__ */ I(f, {
|
|
695
|
+
type: M > 0 ? "warning" : "success",
|
|
696
|
+
showIcon: !0,
|
|
697
|
+
message: o.importSummary(A, M)
|
|
698
|
+
}),
|
|
699
|
+
/* @__PURE__ */ L("div", { children: [
|
|
700
|
+
/* @__PURE__ */ I(E.Title, {
|
|
701
|
+
level: 5,
|
|
702
|
+
children: o.importPreview
|
|
703
|
+
}),
|
|
704
|
+
/* @__PURE__ */ I(re, {
|
|
705
|
+
size: "small",
|
|
706
|
+
rowKey: "rowNumber",
|
|
707
|
+
loading: ee,
|
|
708
|
+
dataSource: R,
|
|
709
|
+
columns: B,
|
|
710
|
+
pagination: !1,
|
|
711
|
+
scroll: {
|
|
712
|
+
x: "max-content",
|
|
713
|
+
y: 320
|
|
714
|
+
}
|
|
715
|
+
}),
|
|
716
|
+
h.length > ke && /* @__PURE__ */ I(E.Text, {
|
|
717
|
+
type: "secondary",
|
|
718
|
+
children: o.importPreviewTruncated(ke, h.length)
|
|
719
|
+
})
|
|
720
|
+
] })
|
|
721
|
+
]
|
|
722
|
+
}) : /* @__PURE__ */ L(D.Dragger, {
|
|
723
|
+
accept: V,
|
|
724
|
+
multiple: !1,
|
|
725
|
+
showUploadList: !1,
|
|
726
|
+
beforeUpload: (e) => (ne(e), !1),
|
|
727
|
+
children: [
|
|
728
|
+
/* @__PURE__ */ I("p", {
|
|
729
|
+
className: "ant-upload-drawing-icon",
|
|
730
|
+
children: /* @__PURE__ */ I(a, {})
|
|
731
|
+
}),
|
|
732
|
+
/* @__PURE__ */ I("p", {
|
|
733
|
+
className: "ant-upload-text",
|
|
734
|
+
children: o.importSelectFile
|
|
735
|
+
}),
|
|
736
|
+
/* @__PURE__ */ I("p", {
|
|
737
|
+
className: "ant-upload-hint",
|
|
738
|
+
children: o.importAcceptHint(H)
|
|
739
|
+
})
|
|
740
|
+
]
|
|
741
|
+
})
|
|
742
|
+
});
|
|
743
|
+
}, Me = [
|
|
744
|
+
"csv",
|
|
745
|
+
"xls",
|
|
746
|
+
"xlsx"
|
|
747
|
+
], Ne = () => Me.filter((e) => !!Q[e]), Pe = (e, t, n, r) => {
|
|
748
|
+
let { current: i = 1, pageSize: a = 10, ...o } = e, s = {};
|
|
749
|
+
for (let [e, t] of Object.entries(o)) r.has(e) && t !== void 0 && t !== "" && (s[e] = t);
|
|
750
|
+
for (let [e, t] of Object.entries(n)) t && t.length > 0 && r.has(e) && (s[e] = t[0]);
|
|
751
|
+
return {
|
|
752
|
+
page: i,
|
|
753
|
+
pageSize: a,
|
|
754
|
+
sort: Object.entries(t).filter(([, e]) => e === "ascend" || e === "descend").map(([e, t]) => ({
|
|
755
|
+
field: e,
|
|
756
|
+
direction: t
|
|
757
|
+
})),
|
|
758
|
+
filters: s
|
|
759
|
+
};
|
|
760
|
+
}, Fe = (n) => {
|
|
761
|
+
let { columns: a, rowKey: l, title: u, defaultPageSize: d = 10, hookConfig: f, enableBulkOperations: m = !1, enableColumnSettings: g = !0, enableExport: te = !0, enableImport: v = !1, importConcurrency: y, exportScope: x = "all", customActions: S, locale: C } = n, { strings: w, intl: ne, antdLocale: re } = me(C), T = e(l, {
|
|
762
|
+
defaultPageSize: d,
|
|
763
|
+
...f,
|
|
764
|
+
locale: w,
|
|
765
|
+
refreshAfterMutation: !1
|
|
766
|
+
}), [ie, E] = N(!1), [D, A] = N(null), [P, F] = N([]), [R] = _.useForm(), z = M([]), B = M({
|
|
767
|
+
page: 1,
|
|
768
|
+
pageSize: d
|
|
769
|
+
}), [V, H] = N(!1), ae = j(() => new Set(a.map((e) => e.dataIndex)), [a]), U = k((e) => ({
|
|
770
|
+
dataIndex: e.dataIndex,
|
|
771
|
+
title: e.title,
|
|
772
|
+
fieldType: e.fieldType,
|
|
773
|
+
enumOptions: e.enumOptions,
|
|
774
|
+
customRender: e.customRender
|
|
775
|
+
}), []), W = k((e) => {
|
|
776
|
+
if (A(e ?? null), !e) {
|
|
777
|
+
R.resetFields(), E(!0);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
let t = { ...e };
|
|
781
|
+
for (let e of a) {
|
|
782
|
+
let n = e.dataIndex, { toFormValue: r } = X(e.fieldType);
|
|
783
|
+
if (r && t[n] !== void 0) try {
|
|
784
|
+
t[n] = r(t[n]);
|
|
785
|
+
} catch {}
|
|
786
|
+
}
|
|
787
|
+
R.setFieldsValue(t), E(!0);
|
|
788
|
+
}, [a, R]), G = k((e) => {
|
|
789
|
+
b.confirm({
|
|
790
|
+
title: w.confirmDeleteTitle,
|
|
791
|
+
content: w.confirmDeleteContent,
|
|
792
|
+
okText: w.confirmDeleteOk,
|
|
793
|
+
okType: "danger",
|
|
794
|
+
cancelText: w.cancel,
|
|
795
|
+
onOk: async () => {
|
|
796
|
+
await T.remove(e) && T.actionRef.current?.reload();
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}, [T, w]), oe = j(() => {
|
|
800
|
+
let e = a.map((e) => {
|
|
801
|
+
let t = U(e), n = X(e.fieldType);
|
|
802
|
+
return {
|
|
803
|
+
...e,
|
|
804
|
+
dataIndex: e.dataIndex,
|
|
805
|
+
title: e.title,
|
|
806
|
+
search: e.searchable !== !1,
|
|
807
|
+
...n.column?.(t, w)
|
|
808
|
+
};
|
|
809
|
+
});
|
|
810
|
+
return e.push({
|
|
811
|
+
title: w.actions,
|
|
812
|
+
valueType: "option",
|
|
813
|
+
width: 200,
|
|
814
|
+
render: (e, t) => [
|
|
815
|
+
/* @__PURE__ */ I(p, {
|
|
816
|
+
type: "link",
|
|
817
|
+
size: "small",
|
|
818
|
+
onClick: () => W(t),
|
|
819
|
+
children: w.edit
|
|
820
|
+
}, "edit"),
|
|
821
|
+
/* @__PURE__ */ I(p, {
|
|
822
|
+
type: "link",
|
|
823
|
+
size: "small",
|
|
824
|
+
danger: !0,
|
|
825
|
+
onClick: () => G(t[l]),
|
|
826
|
+
children: w.delete
|
|
827
|
+
}, "delete"),
|
|
828
|
+
...S?.(t, T) ?? []
|
|
829
|
+
]
|
|
830
|
+
}), e;
|
|
831
|
+
}, [
|
|
832
|
+
a,
|
|
833
|
+
U,
|
|
834
|
+
W,
|
|
835
|
+
G,
|
|
836
|
+
l,
|
|
837
|
+
S,
|
|
838
|
+
T,
|
|
839
|
+
w
|
|
840
|
+
]), se = async (e, n, r) => {
|
|
841
|
+
try {
|
|
842
|
+
let t = Pe(e, n, r, ae);
|
|
843
|
+
B.current = t;
|
|
844
|
+
let i = await T.dataSource.list(t);
|
|
845
|
+
return z.current = i.items, {
|
|
846
|
+
data: [...i.items],
|
|
847
|
+
success: !0,
|
|
848
|
+
total: i.total
|
|
849
|
+
};
|
|
850
|
+
} catch (e) {
|
|
851
|
+
let n = t(e);
|
|
852
|
+
return f.onError?.("list", n), O.error(n.message), {
|
|
853
|
+
data: [],
|
|
854
|
+
success: !1,
|
|
855
|
+
total: 0
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}, ce = async () => {
|
|
859
|
+
let e;
|
|
860
|
+
try {
|
|
861
|
+
e = await R.validateFields();
|
|
862
|
+
} catch {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
let n = { ...e };
|
|
866
|
+
for (let r of a) {
|
|
867
|
+
let i = r.dataIndex, { fromFormValue: a } = X(r.fieldType);
|
|
868
|
+
if (a && e[i] !== void 0) try {
|
|
869
|
+
n[i] = a(e[i]);
|
|
870
|
+
} catch (e) {
|
|
871
|
+
f.onError?.(D ? "update" : "create", t(e));
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
let o = r.formConfig?.transform;
|
|
875
|
+
o && (n[i] = o(n[i]));
|
|
876
|
+
}
|
|
877
|
+
(D ? await T.update(D[l], n) : await T.create(n)) !== null && (E(!1), T.actionRef.current?.reload());
|
|
878
|
+
}, le = () => {
|
|
879
|
+
if (P.length === 0) {
|
|
880
|
+
O.warning(w.selectItemsToDelete);
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
b.confirm({
|
|
884
|
+
title: w.confirmBulkDeleteTitle(P.length),
|
|
885
|
+
content: w.confirmDeleteContent,
|
|
886
|
+
okText: w.confirmBulkDeleteOk,
|
|
887
|
+
okType: "danger",
|
|
888
|
+
cancelText: w.cancel,
|
|
889
|
+
onOk: async () => {
|
|
890
|
+
let e = await Promise.all(P.map(async (e) => ({
|
|
891
|
+
key: e,
|
|
892
|
+
ok: await T.remove(e)
|
|
893
|
+
}))), t = e.filter((e) => !e.ok);
|
|
894
|
+
F(t.map((e) => e.key)), t.length === 0 ? O.success(w.bulkDeleteSuccess(e.length)) : O.error(w.bulkDeletePartial(e.length - t.length, e.length, t.length)), T.actionRef.current?.reload();
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}, ue = x === "all" && typeof T.dataSource.listAll == "function", K = async (e) => {
|
|
898
|
+
H(!0);
|
|
899
|
+
try {
|
|
900
|
+
let t = ue ? await T.dataSource.listAll({
|
|
901
|
+
sort: B.current.sort,
|
|
902
|
+
filters: B.current.filters
|
|
903
|
+
}) : z.current;
|
|
904
|
+
if (t.length === 0) {
|
|
905
|
+
O.warning(w.nothingToExport);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
let n = a.filter((e) => e.fieldType !== "password").map((e) => ({
|
|
909
|
+
title: e.title,
|
|
910
|
+
dataIndex: String(e.dataIndex),
|
|
911
|
+
fieldType: e.fieldType,
|
|
912
|
+
enumOptions: e.enumOptions
|
|
913
|
+
}));
|
|
914
|
+
r({
|
|
915
|
+
data: [...t],
|
|
916
|
+
columns: n,
|
|
917
|
+
filename: u ? u.toLowerCase().replace(/\s+/g, "-") : "export",
|
|
918
|
+
format: e
|
|
919
|
+
});
|
|
920
|
+
} catch (e) {
|
|
921
|
+
let n = t(e);
|
|
922
|
+
f.onError?.("list", n), O.error(w.exportFailed(n.message));
|
|
923
|
+
} finally {
|
|
924
|
+
H(!1);
|
|
925
|
+
}
|
|
926
|
+
}, q = ue ? w.exportAll : w.exportPage, [de, J] = N(!1), fe = j(() => a.map((e) => {
|
|
927
|
+
let t = X(e.fieldType), n = U(e), r = e.formConfig?.rules ?? (e.formConfig?.required ? [{
|
|
928
|
+
required: !0,
|
|
929
|
+
message: w.requiredField(e.title)
|
|
930
|
+
}] : []);
|
|
931
|
+
return {
|
|
932
|
+
title: e.title,
|
|
933
|
+
dataIndex: String(e.dataIndex),
|
|
934
|
+
fieldType: e.fieldType,
|
|
935
|
+
enumOptions: e.enumOptions,
|
|
936
|
+
rules: [...t.rules?.(n, w) ?? [], ...r]
|
|
937
|
+
};
|
|
938
|
+
}), [
|
|
939
|
+
a,
|
|
940
|
+
U,
|
|
941
|
+
w
|
|
942
|
+
]), Y = j(() => {
|
|
943
|
+
let e = T.dataSource;
|
|
944
|
+
return {
|
|
945
|
+
create: (t) => e.create(t),
|
|
946
|
+
createMany: e.createMany ? (t) => e.createMany(t) : void 0
|
|
947
|
+
};
|
|
948
|
+
}, [T.dataSource]), pe = k((e) => {
|
|
949
|
+
e.failed === 0 && e.invalid === 0 ? O.success(w.importSuccess(e.created)) : O.warning(w.importPartial(e.created, e.created + e.failed + e.invalid, e.failed + e.invalid)), T.actionRef.current?.reload();
|
|
950
|
+
}, [w, T]), Z = /* @__PURE__ */ L(s, {
|
|
951
|
+
needDeps: !0,
|
|
952
|
+
intl: ne,
|
|
953
|
+
children: [
|
|
954
|
+
/* @__PURE__ */ I(c, {
|
|
955
|
+
headerTitle: u,
|
|
956
|
+
rowKey: l,
|
|
957
|
+
rowClassName: (e, t) => t % 2 == 0 ? "row-differentiator" : "",
|
|
958
|
+
actionRef: T.actionRef,
|
|
959
|
+
columns: oe,
|
|
960
|
+
request: se,
|
|
961
|
+
search: { labelWidth: "auto" },
|
|
962
|
+
pagination: {
|
|
963
|
+
pageSize: d,
|
|
964
|
+
showSizeChanger: !0,
|
|
965
|
+
showQuickJumper: !0
|
|
966
|
+
},
|
|
967
|
+
rowSelection: m ? {
|
|
968
|
+
selectedRowKeys: P,
|
|
969
|
+
onChange: F
|
|
970
|
+
} : void 0,
|
|
971
|
+
toolBarRender: () => [
|
|
972
|
+
/* @__PURE__ */ I(p, {
|
|
973
|
+
type: "primary",
|
|
974
|
+
icon: /* @__PURE__ */ I(o, {}),
|
|
975
|
+
onClick: () => W(),
|
|
976
|
+
children: w.create
|
|
977
|
+
}, "add"),
|
|
978
|
+
...m && P.length > 0 ? [/* @__PURE__ */ I(p, {
|
|
979
|
+
danger: !0,
|
|
980
|
+
onClick: le,
|
|
981
|
+
children: w.deleteSelected(P.length)
|
|
982
|
+
}, "bulk-delete")] : [],
|
|
983
|
+
/* @__PURE__ */ I(ee, {
|
|
984
|
+
menu: { items: [
|
|
985
|
+
...v && Ne().length > 0 ? [{
|
|
986
|
+
key: "import",
|
|
987
|
+
label: w.importMenu,
|
|
988
|
+
onClick: () => J(!0)
|
|
989
|
+
}, { type: "divider" }] : [],
|
|
990
|
+
...te ? [
|
|
991
|
+
{
|
|
992
|
+
key: "export-csv",
|
|
993
|
+
label: q("CSV"),
|
|
994
|
+
disabled: V,
|
|
995
|
+
onClick: () => void K("csv")
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
key: "export-json",
|
|
999
|
+
label: q("JSON"),
|
|
1000
|
+
disabled: V,
|
|
1001
|
+
onClick: () => void K("json")
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
key: "export-excel",
|
|
1005
|
+
label: q("Excel"),
|
|
1006
|
+
disabled: V,
|
|
1007
|
+
onClick: () => void K("excel")
|
|
1008
|
+
},
|
|
1009
|
+
{ type: "divider" }
|
|
1010
|
+
] : [],
|
|
1011
|
+
{
|
|
1012
|
+
key: "refresh",
|
|
1013
|
+
label: w.refresh,
|
|
1014
|
+
onClick: () => T.actionRef.current?.reload()
|
|
1015
|
+
}
|
|
1016
|
+
] },
|
|
1017
|
+
children: /* @__PURE__ */ I(p, { children: /* @__PURE__ */ I(i, {}) })
|
|
1018
|
+
}, "menu")
|
|
1019
|
+
],
|
|
1020
|
+
options: {
|
|
1021
|
+
setting: g ? { listsHeight: 400 } : !1,
|
|
1022
|
+
density: g,
|
|
1023
|
+
reload: !0
|
|
1024
|
+
},
|
|
1025
|
+
dateFormatter: "string"
|
|
1026
|
+
}),
|
|
1027
|
+
/* @__PURE__ */ I(b, {
|
|
1028
|
+
title: D ? w.editTitle : w.createTitle,
|
|
1029
|
+
open: ie,
|
|
1030
|
+
onOk: ce,
|
|
1031
|
+
onCancel: () => E(!1),
|
|
1032
|
+
okText: w.ok,
|
|
1033
|
+
cancelText: w.cancel,
|
|
1034
|
+
destroyOnHidden: !0,
|
|
1035
|
+
width: 600,
|
|
1036
|
+
children: /* @__PURE__ */ I(_, {
|
|
1037
|
+
form: R,
|
|
1038
|
+
layout: "vertical",
|
|
1039
|
+
children: a.map((e) => {
|
|
1040
|
+
let t = e.dataIndex, n = !(e.fieldEditable ?? !0), r = X(e.fieldType), i = U(e), a = e.formConfig?.rules ?? (e.formConfig?.required ? [{
|
|
1041
|
+
required: !0,
|
|
1042
|
+
message: w.requiredField(e.title)
|
|
1043
|
+
}] : []), o = [...r.rules?.(i, w) ?? [], ...a], s = e.formConfig?.component ?? r.formControl(i, n, w);
|
|
1044
|
+
return s ? /* @__PURE__ */ I(_.Item, {
|
|
1045
|
+
name: t,
|
|
1046
|
+
label: e.title,
|
|
1047
|
+
rules: o,
|
|
1048
|
+
valuePropName: r.valuePropName,
|
|
1049
|
+
children: s
|
|
1050
|
+
}, t) : null;
|
|
1051
|
+
})
|
|
1052
|
+
})
|
|
1053
|
+
}),
|
|
1054
|
+
v && /* @__PURE__ */ I(je, {
|
|
1055
|
+
open: de,
|
|
1056
|
+
columns: fe,
|
|
1057
|
+
formats: Ne(),
|
|
1058
|
+
sink: Y,
|
|
1059
|
+
concurrency: y,
|
|
1060
|
+
locale: w,
|
|
1061
|
+
onImported: pe,
|
|
1062
|
+
onClose: () => J(!1)
|
|
1063
|
+
})
|
|
1064
|
+
]
|
|
1065
|
+
});
|
|
1066
|
+
return re ? /* @__PURE__ */ I(h, {
|
|
1067
|
+
locale: re,
|
|
1068
|
+
children: Z
|
|
1069
|
+
}) : Z;
|
|
1070
|
+
};
|
|
1071
|
+
//#endregion
|
|
1072
|
+
export { Y as _, _e as a, Q as c, De as d, ge as f, pe as g, me as h, Ce as i, Z as l, he as m, je as n, ve as o, Oe as p, xe as r, Ee as s, Fe as t, ye as u, X as v };
|