@faasjs/ant-design 0.0.2-development → 0.0.3-beta.10

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/index.js ADDED
@@ -0,0 +1,1405 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ Blank: () => Blank,
30
+ ConfigContext: () => ConfigContext,
31
+ ConfigProvider: () => ConfigProvider,
32
+ Description: () => Description,
33
+ Drawer: () => import_antd4.Drawer,
34
+ Form: () => Form,
35
+ FormItem: () => FormItem,
36
+ Link: () => Link,
37
+ Modal: () => import_antd8.Modal,
38
+ PageNotFound: () => PageNotFound,
39
+ Routes: () => Routes,
40
+ Table: () => Table,
41
+ Title: () => Title,
42
+ transferOptions: () => transferOptions,
43
+ transferValue: () => transferValue,
44
+ useConfigContext: () => useConfigContext,
45
+ useDrawer: () => useDrawer,
46
+ useModal: () => useModal
47
+ });
48
+ module.exports = __toCommonJS(src_exports);
49
+
50
+ // react-shim.js
51
+ var import_react = __toESM(require("react"));
52
+
53
+ // src/Blank.tsx
54
+ var import_antd2 = require("antd");
55
+ var import_lodash_es2 = require("lodash-es");
56
+
57
+ // src/Config.tsx
58
+ var import_react2 = require("react");
59
+ var import_antd = require("antd");
60
+ var import_lodash_es = require("lodash-es");
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ var isZH = /^zh/i.test(navigator.language);
63
+ var zh = {
64
+ lang: "zh",
65
+ blank: "\u7A7A",
66
+ all: "\u5168\u90E8",
67
+ submit: "\u63D0\u4EA4",
68
+ pageNotFound: "\u9875\u9762\u672A\u627E\u5230",
69
+ add: "\u6DFB\u52A0",
70
+ delete: "\u5220\u9664",
71
+ required: "\u5FC5\u586B",
72
+ search: "\u641C\u7D22",
73
+ reset: "\u91CD\u7F6E"
74
+ };
75
+ var en = {
76
+ lang: "en",
77
+ blank: "Empty",
78
+ all: "All",
79
+ submit: "Submit",
80
+ pageNotFound: "Page Not Found",
81
+ add: "Add",
82
+ delete: "Delete",
83
+ required: "is required",
84
+ search: "Search",
85
+ reset: "Reset"
86
+ };
87
+ var common = isZH ? zh : en;
88
+ var baseConfig = {
89
+ antd: {},
90
+ lang: "en",
91
+ common,
92
+ Blank: { text: common.blank },
93
+ Form: { submit: { text: common.submit } },
94
+ Title: {
95
+ separator: " - ",
96
+ suffix: ""
97
+ },
98
+ Link: { style: {} }
99
+ };
100
+ var ConfigContext = (0, import_react2.createContext)(baseConfig);
101
+ function ConfigProvider({
102
+ config,
103
+ children
104
+ }) {
105
+ const [values, setValues] = (0, import_react2.useState)(baseConfig);
106
+ (0, import_react2.useEffect)(() => {
107
+ if (config.lang === "zh") {
108
+ setValues((0, import_lodash_es.defaultsDeep)(config, {
109
+ lang: "zh",
110
+ common: zh,
111
+ Blank: { text: zh.blank },
112
+ Form: { submit: { text: zh.submit } }
113
+ }, baseConfig));
114
+ } else
115
+ setValues(values);
116
+ }, []);
117
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigContext.Provider, {
118
+ value: values,
119
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.ConfigProvider, {
120
+ ...config.antd,
121
+ children
122
+ })
123
+ });
124
+ }
125
+ function useConfigContext() {
126
+ return (0, import_react2.useContext)(ConfigContext);
127
+ }
128
+
129
+ // src/Blank.tsx
130
+ var import_jsx_runtime = require("react/jsx-runtime");
131
+ function Blank(options) {
132
+ const { Blank: Blank2 } = useConfigContext();
133
+ return !options || (0, import_lodash_es2.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd2.Typography.Text, {
134
+ disabled: true,
135
+ children: (options == null ? void 0 : options.text) || Blank2.text
136
+ }) : options.value;
137
+ }
138
+
139
+ // src/data.ts
140
+ var import_lodash_es3 = require("lodash-es");
141
+ var import_dayjs = __toESM(require("dayjs"));
142
+ function transferOptions(options) {
143
+ if (!options)
144
+ return [];
145
+ return options.map((item) => typeof item === "object" ? item : {
146
+ label: (0, import_lodash_es3.upperFirst)(item.toString()),
147
+ value: item
148
+ });
149
+ }
150
+ function transferValue(type, value) {
151
+ if (typeof value === "undefined" || value === null || value === "" || value === "null" || value === "undefined")
152
+ return null;
153
+ if (!type)
154
+ type = "string";
155
+ if (type.endsWith("[]") && typeof value === "string")
156
+ value = value.split(",").filter(Boolean);
157
+ if (["date", "time"].includes(type)) {
158
+ if (typeof value === "number" && value.toString().length === 10)
159
+ value = value * 1e3;
160
+ if (!import_dayjs.default.isDayjs(value))
161
+ value = (0, import_dayjs.default)(value);
162
+ }
163
+ return value;
164
+ }
165
+
166
+ // src/Description.tsx
167
+ var import_icons = require("@ant-design/icons");
168
+ var import_antd3 = require("antd");
169
+ var import_lodash_es4 = require("lodash-es");
170
+ var import_react3 = require("react");
171
+ var import_react4 = require("@faasjs/react");
172
+ var import_jsx_runtime = require("react/jsx-runtime");
173
+ function DescriptionItemContent(props) {
174
+ var _a;
175
+ const [computedProps, setComputedProps] = (0, import_react3.useState)();
176
+ (0, import_react3.useEffect)(() => {
177
+ var _a2, _b;
178
+ const propsCopy = { ...props };
179
+ if (!propsCopy.item.title)
180
+ propsCopy.item.title = (0, import_lodash_es4.upperFirst)(propsCopy.item.id);
181
+ if (!propsCopy.item.type)
182
+ propsCopy.item.type = "string";
183
+ if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
184
+ propsCopy.item.options = transferOptions(propsCopy.item.options);
185
+ }
186
+ propsCopy.value = transferValue(propsCopy.item.type, propsCopy.value);
187
+ if (propsCopy.item.options && propsCopy.value !== null) {
188
+ if (propsCopy.item.type.endsWith("[]"))
189
+ propsCopy.value = propsCopy.value.map((v) => {
190
+ var _a3;
191
+ return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
192
+ });
193
+ else if ([
194
+ "string",
195
+ "number",
196
+ "boolean"
197
+ ].includes(propsCopy.item.type))
198
+ propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
199
+ }
200
+ setComputedProps(propsCopy);
201
+ }, [props]);
202
+ if (!computedProps)
203
+ return null;
204
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
205
+ if (computedProps.extendTypes[computedProps.item.type].children)
206
+ return (0, import_react3.cloneElement)(
207
+ computedProps.extendTypes[computedProps.item.type].children,
208
+ {
209
+ value: computedProps.value,
210
+ values: computedProps.values
211
+ }
212
+ );
213
+ else if (computedProps.extendTypes[computedProps.item.type].render)
214
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
215
+ children: computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values)
216
+ });
217
+ else
218
+ throw Error(computedProps.item.type + " requires children or render");
219
+ if (computedProps.item.children)
220
+ return (0, import_react3.cloneElement)(computedProps.item.children, { value: computedProps.value });
221
+ if (computedProps.item.render)
222
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
223
+ children: computedProps.item.render(computedProps.value, computedProps.values)
224
+ });
225
+ if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length)
226
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
227
+ switch (computedProps.item.type) {
228
+ case "string[]":
229
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
230
+ children: computedProps.value.join(", ")
231
+ });
232
+ case "number":
233
+ return computedProps.value || null;
234
+ case "number[]":
235
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
236
+ children: computedProps.value.join(", ")
237
+ });
238
+ case "boolean":
239
+ return computedProps.value ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CheckOutlined, {
240
+ style: {
241
+ marginTop: "4px",
242
+ color: "#52c41a"
243
+ }
244
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CloseOutlined, {
245
+ style: {
246
+ marginTop: "4px",
247
+ color: "#ff4d4f"
248
+ }
249
+ });
250
+ case "time":
251
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
252
+ children: computedProps.value.format("YYYY-MM-DD HH:mm:ss")
253
+ });
254
+ case "date":
255
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
256
+ children: computedProps.value.format("YYYY-MM-DD")
257
+ });
258
+ case "object":
259
+ if (!computedProps.value)
260
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
261
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
262
+ items: computedProps.item.object,
263
+ dataSource: computedProps.value,
264
+ column: 1
265
+ });
266
+ case "object[]":
267
+ if (!((_a = computedProps.value) == null ? void 0 : _a.length))
268
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
269
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Space, {
270
+ direction: "vertical",
271
+ children: computedProps.value.map((value, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
272
+ items: computedProps.item.object,
273
+ dataSource: value,
274
+ column: 1
275
+ }, index))
276
+ });
277
+ default:
278
+ return computedProps.value || null;
279
+ }
280
+ }
281
+ function Description(props) {
282
+ if (!props.faasData)
283
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
284
+ ...props,
285
+ title: (0, import_lodash_es4.isFunction)(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
286
+ children: props.items.map((item) => {
287
+ return !item.if || item.if(props.dataSource) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
288
+ label: item.title || (0, import_lodash_es4.upperFirst)(item.id),
289
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
290
+ item,
291
+ value: props.dataSource[item.id],
292
+ values: props.dataSource,
293
+ extendTypes: props.extendTypes
294
+ })
295
+ }, item.id) : null;
296
+ }).filter(Boolean)
297
+ });
298
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react4.FaasDataWrapper, {
299
+ fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Skeleton, {
300
+ active: true
301
+ }),
302
+ render: ({ data }) => {
303
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
304
+ ...props,
305
+ title: (0, import_lodash_es4.isFunction)(props.renderTitle) ? props.renderTitle(data) : props.title,
306
+ children: props.items.map((item) => {
307
+ return !item.if || item.if(data) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
308
+ label: item.title || (0, import_lodash_es4.upperFirst)(item.id),
309
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
310
+ item,
311
+ value: data[item.id],
312
+ values: data,
313
+ extendTypes: props.extendTypes
314
+ })
315
+ }, item.id) : null;
316
+ }).filter(Boolean)
317
+ });
318
+ },
319
+ ...props.faasData
320
+ });
321
+ }
322
+
323
+ // src/Drawer.tsx
324
+ var import_antd4 = require("antd");
325
+ var import_react5 = require("react");
326
+ var import_jsx_runtime = require("react/jsx-runtime");
327
+ function useDrawer(init) {
328
+ const [props, setProps] = (0, import_react5.useState)({
329
+ open: false,
330
+ onClose: () => setProps((prev) => ({
331
+ ...prev,
332
+ open: false
333
+ })),
334
+ ...init
335
+ });
336
+ return {
337
+ drawer: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd4.Drawer, {
338
+ ...props
339
+ }),
340
+ drawerProps: props,
341
+ setDrawerProps(changes) {
342
+ setProps((prev) => ({
343
+ ...prev,
344
+ ...changes
345
+ }));
346
+ }
347
+ };
348
+ }
349
+
350
+ // src/Form.tsx
351
+ var import_react7 = require("@faasjs/react");
352
+ var import_antd6 = require("antd");
353
+ var import_react8 = require("react");
354
+
355
+ // src/FormItem.tsx
356
+ var import_antd5 = require("antd");
357
+ var import_icons2 = require("@ant-design/icons");
358
+ var import_react6 = require("react");
359
+ var import_lodash_es5 = require("lodash-es");
360
+ var import_jsx_runtime = require("react/jsx-runtime");
361
+ function processProps(propsCopy, config) {
362
+ if (!propsCopy.title)
363
+ propsCopy.title = (0, import_lodash_es5.upperFirst)(propsCopy.id);
364
+ if (!propsCopy.label && propsCopy.label !== false)
365
+ propsCopy.label = propsCopy.title;
366
+ if (!propsCopy.name)
367
+ propsCopy.name = propsCopy.id;
368
+ if (!propsCopy.type)
369
+ propsCopy.type = "string";
370
+ if (!propsCopy.rules)
371
+ propsCopy.rules = [];
372
+ if (propsCopy.required) {
373
+ if (propsCopy.type.endsWith("[]"))
374
+ propsCopy.rules.push({
375
+ required: true,
376
+ validator: async (_, values) => {
377
+ if (!values || values.length < 1)
378
+ return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
379
+ }
380
+ });
381
+ else
382
+ propsCopy.rules.push({
383
+ required: true,
384
+ message: `${propsCopy.label || propsCopy.title} ${config.required}`
385
+ });
386
+ }
387
+ if (!propsCopy.input)
388
+ propsCopy.input = {};
389
+ if (propsCopy.options)
390
+ propsCopy.input.options = transferOptions(propsCopy.options);
391
+ switch (propsCopy.type) {
392
+ case "boolean":
393
+ propsCopy.valuePropName = "checked";
394
+ break;
395
+ case "object":
396
+ if (!Array.isArray(propsCopy.name))
397
+ propsCopy.name = [propsCopy.name];
398
+ for (const sub of propsCopy.object) {
399
+ if (!sub.name)
400
+ sub.name = propsCopy.name.concat(sub.id);
401
+ processProps(sub, config);
402
+ }
403
+ break;
404
+ }
405
+ return propsCopy;
406
+ }
407
+ function FormItem(props) {
408
+ var _a;
409
+ const [computedProps, setComputedProps] = (0, import_react6.useState)();
410
+ const [extendTypes, setExtendTypes] = (0, import_react6.useState)();
411
+ const { common: common2 } = useConfigContext();
412
+ const [hidden, setHidden] = (0, import_react6.useState)(props.hidden || false);
413
+ (0, import_react6.useEffect)(() => {
414
+ const propsCopy = { ...props };
415
+ if (propsCopy.extendTypes) {
416
+ setExtendTypes(propsCopy.extendTypes);
417
+ delete propsCopy.extendTypes;
418
+ }
419
+ if (propsCopy.if) {
420
+ const condition = propsCopy.if;
421
+ const originShouldUpdate = propsCopy.shouldUpdate;
422
+ propsCopy.shouldUpdate = (prev, cur) => {
423
+ const show = condition(cur);
424
+ const shouldUpdate = hidden !== show;
425
+ setHidden(!show);
426
+ const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
427
+ return shouldUpdate || origin;
428
+ };
429
+ delete propsCopy.if;
430
+ delete propsCopy.hidden;
431
+ }
432
+ setComputedProps(processProps(propsCopy, common2));
433
+ }, [props]);
434
+ if (!computedProps)
435
+ return null;
436
+ if (hidden)
437
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
438
+ ...computedProps,
439
+ noStyle: true,
440
+ rules: [],
441
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
442
+ hidden: true
443
+ })
444
+ });
445
+ if (extendTypes && extendTypes[computedProps.type])
446
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
447
+ ...computedProps,
448
+ children: extendTypes[computedProps.type].children
449
+ });
450
+ if (computedProps.children)
451
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
452
+ ...computedProps,
453
+ children: computedProps.children
454
+ });
455
+ if (computedProps.render)
456
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
457
+ ...computedProps,
458
+ children: computedProps.render()
459
+ });
460
+ switch (computedProps.type) {
461
+ case "string":
462
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
463
+ ...computedProps,
464
+ children: computedProps.options ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
465
+ ...computedProps.input
466
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
467
+ ...computedProps.input
468
+ })
469
+ });
470
+ case "string[]":
471
+ if (computedProps.options)
472
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
473
+ ...computedProps,
474
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
475
+ mode: "multiple",
476
+ ...computedProps.input
477
+ })
478
+ });
479
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
480
+ name: computedProps.name,
481
+ rules: computedProps.rules,
482
+ children: (fields, { add, remove }, { errors }) => {
483
+ var _a2;
484
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
485
+ children: [
486
+ computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
487
+ className: "ant-form-item-label",
488
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
489
+ className: computedProps.rules.find((r) => r.required) && "ant-form-item-required",
490
+ children: computedProps.label
491
+ })
492
+ }),
493
+ fields.map((field) => {
494
+ var _a3;
495
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
496
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Row, {
497
+ gutter: 24,
498
+ style: { flexFlow: "row nowrap" },
499
+ children: [
500
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
501
+ span: 23,
502
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
503
+ ...field,
504
+ noStyle: true,
505
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
506
+ ...computedProps.input
507
+ })
508
+ })
509
+ }),
510
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
511
+ span: 1,
512
+ children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
513
+ danger: true,
514
+ type: "link",
515
+ style: { float: "right" },
516
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.MinusCircleOutlined, {}),
517
+ onClick: () => remove(field.name)
518
+ })
519
+ })
520
+ ]
521
+ })
522
+ }, field.key);
523
+ }),
524
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
525
+ children: [
526
+ !((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
527
+ type: "dashed",
528
+ block: true,
529
+ onClick: () => add(),
530
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {})
531
+ }),
532
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
533
+ errors
534
+ })
535
+ ]
536
+ })
537
+ ]
538
+ });
539
+ }
540
+ });
541
+ case "number":
542
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
543
+ ...computedProps,
544
+ children: computedProps.options ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
545
+ ...computedProps.input
546
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.InputNumber, {
547
+ style: { width: "100%" },
548
+ ...computedProps.input
549
+ })
550
+ });
551
+ case "number[]":
552
+ if (computedProps.options)
553
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
554
+ ...computedProps,
555
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
556
+ mode: "multiple",
557
+ ...computedProps.input
558
+ })
559
+ });
560
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
561
+ name: computedProps.name,
562
+ rules: computedProps.rules,
563
+ children: (fields, { add, remove }, { errors }) => {
564
+ var _a2, _b;
565
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
566
+ children: [
567
+ computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
568
+ className: "ant-form-item-label",
569
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
570
+ className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required",
571
+ children: computedProps.label
572
+ })
573
+ }),
574
+ fields.map((field) => {
575
+ var _a3;
576
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
577
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Row, {
578
+ gutter: 24,
579
+ style: { flexFlow: "row nowrap" },
580
+ children: [
581
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
582
+ span: 23,
583
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
584
+ ...field,
585
+ noStyle: true,
586
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.InputNumber, {
587
+ style: { width: "100%" },
588
+ ...computedProps.input
589
+ })
590
+ })
591
+ }),
592
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
593
+ span: 1,
594
+ children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
595
+ danger: true,
596
+ type: "link",
597
+ style: { float: "right" },
598
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.MinusCircleOutlined, {}),
599
+ onClick: () => remove(field.name)
600
+ })
601
+ })
602
+ ]
603
+ })
604
+ }, field.key);
605
+ }),
606
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
607
+ children: [
608
+ !((_b = computedProps.input) == null ? void 0 : _b.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
609
+ type: "dashed",
610
+ block: true,
611
+ onClick: () => add(),
612
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {})
613
+ }),
614
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
615
+ errors
616
+ })
617
+ ]
618
+ })
619
+ ]
620
+ });
621
+ }
622
+ });
623
+ case "boolean":
624
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
625
+ ...computedProps,
626
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Switch, {
627
+ ...computedProps.input
628
+ })
629
+ });
630
+ case "date":
631
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
632
+ ...computedProps,
633
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.DatePicker, {
634
+ ...computedProps.input
635
+ })
636
+ });
637
+ case "time":
638
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
639
+ ...computedProps,
640
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.TimePicker, {
641
+ ...computedProps.input
642
+ })
643
+ });
644
+ case "object":
645
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
646
+ children: [
647
+ computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
648
+ className: "ant-form-item-label",
649
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
650
+ className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required",
651
+ children: computedProps.label
652
+ })
653
+ }),
654
+ computedProps.object.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
655
+ ...o
656
+ }, o.id))
657
+ ]
658
+ });
659
+ case "object[]":
660
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
661
+ name: computedProps.name,
662
+ rules: computedProps.rules,
663
+ children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
664
+ children: [
665
+ fields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
666
+ style: { marginBottom: 0 },
667
+ children: [
668
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
669
+ className: "ant-form-item-label",
670
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
671
+ children: [
672
+ computedProps.label,
673
+ " ",
674
+ field.name + 1,
675
+ !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
676
+ danger: true,
677
+ type: "link",
678
+ onClick: () => remove(field.name),
679
+ children: common2.delete
680
+ })
681
+ ]
682
+ })
683
+ }),
684
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Row, {
685
+ gutter: 24,
686
+ children: computedProps.object.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
687
+ span: o.col || 24,
688
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
689
+ ...o,
690
+ name: [field.name, o.id]
691
+ })
692
+ }, o.id))
693
+ })
694
+ ]
695
+ }, field.key)),
696
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
697
+ children: [
698
+ !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Button, {
699
+ type: "dashed",
700
+ block: true,
701
+ onClick: () => add(),
702
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
703
+ children: [
704
+ common2.add,
705
+ " ",
706
+ computedProps.label
707
+ ]
708
+ }),
709
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
710
+ errors
711
+ })
712
+ ]
713
+ })
714
+ ]
715
+ })
716
+ });
717
+ default:
718
+ return null;
719
+ }
720
+ }
721
+
722
+ // src/Form.tsx
723
+ var import_jsx_runtime = require("react/jsx-runtime");
724
+ function Form(props) {
725
+ var _a, _b;
726
+ const [loading, setLoading] = (0, import_react8.useState)(false);
727
+ const [computedProps, setComputedProps] = (0, import_react8.useState)();
728
+ const config = useConfigContext();
729
+ const [extendTypes, setExtendTypes] = (0, import_react8.useState)();
730
+ const [form] = import_antd6.Form.useForm(props.form);
731
+ const [initialValues, setInitialValues] = (0, import_react8.useState)(props.initialValues);
732
+ (0, import_react8.useEffect)(() => {
733
+ var _a2, _b2;
734
+ const propsCopy = {
735
+ ...props,
736
+ form
737
+ };
738
+ if (propsCopy.initialValues) {
739
+ for (const key in propsCopy.initialValues) {
740
+ propsCopy.initialValues[key] = transferValue(
741
+ (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
742
+ propsCopy.initialValues[key]
743
+ );
744
+ const item = propsCopy.items.find((item2) => item2.id === key);
745
+ if (item == null ? void 0 : item.if)
746
+ item.hidden = !item.if(propsCopy.initialValues);
747
+ }
748
+ for (const item of propsCopy.items) {
749
+ if (item.if)
750
+ item.hidden = !item.if(propsCopy.initialValues);
751
+ }
752
+ setInitialValues(propsCopy.initialValues);
753
+ delete propsCopy.initialValues;
754
+ }
755
+ if (propsCopy.onFinish) {
756
+ propsCopy.onFinish = async (values) => {
757
+ var _a3;
758
+ setLoading(true);
759
+ try {
760
+ if (propsCopy.submit && ((_a3 = propsCopy.submit.to) == null ? void 0 : _a3.action)) {
761
+ await props.onFinish(values, async (values2) => (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
762
+ ...values2,
763
+ ...propsCopy.submit.to.params
764
+ } : values2));
765
+ } else
766
+ await props.onFinish(values);
767
+ } catch (error) {
768
+ console.error(error);
769
+ }
770
+ setLoading(false);
771
+ };
772
+ } else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
773
+ propsCopy.onFinish = async (values) => {
774
+ setLoading(true);
775
+ return (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
776
+ ...values,
777
+ ...propsCopy.submit.to.params
778
+ } : values).finally(() => setLoading(false));
779
+ };
780
+ }
781
+ if (propsCopy.extendTypes) {
782
+ setExtendTypes(propsCopy.extendTypes);
783
+ delete propsCopy.extendTypes;
784
+ }
785
+ setComputedProps(propsCopy);
786
+ }, [props]);
787
+ const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
788
+ console.debug("Form:onValuesChange", changedValues, allValues);
789
+ if (props.onValuesChange) {
790
+ props.onValuesChange(changedValues, allValues);
791
+ }
792
+ if (!props.items)
793
+ return;
794
+ for (const key in changedValues) {
795
+ const item = computedProps.items.find((i) => i.id === key);
796
+ if (item == null ? void 0 : item.onValueChange)
797
+ item.onValueChange(changedValues[key], allValues, form);
798
+ }
799
+ }, [computedProps]);
800
+ (0, import_react8.useEffect)(() => {
801
+ if (!initialValues)
802
+ return;
803
+ console.debug("Form:initialValues", initialValues);
804
+ form.setFieldsValue(initialValues);
805
+ setInitialValues(null);
806
+ }, [computedProps]);
807
+ if (!computedProps)
808
+ return null;
809
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd6.Form, {
810
+ ...computedProps,
811
+ onValuesChange,
812
+ children: [
813
+ computedProps.beforeItems,
814
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => (0, import_react8.isValidElement)(item) ? item : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
815
+ ...item,
816
+ extendTypes
817
+ }, item.id)),
818
+ computedProps.children,
819
+ computedProps.submit !== false && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd6.Button, {
820
+ htmlType: "submit",
821
+ type: "primary",
822
+ loading,
823
+ children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text
824
+ }),
825
+ computedProps.footer
826
+ ]
827
+ });
828
+ }
829
+ Form.useForm = import_antd6.Form.useForm;
830
+
831
+ // src/Link.tsx
832
+ var import_react_router_dom = require("react-router-dom");
833
+ var import_antd7 = require("antd");
834
+ var import_jsx_runtime = require("react/jsx-runtime");
835
+ function Link({
836
+ href,
837
+ target,
838
+ text,
839
+ children,
840
+ style,
841
+ button
842
+ }) {
843
+ const { Link: Link2 } = useConfigContext();
844
+ style = Object.assign({ cursor: "pointer" }, style);
845
+ if (href.startsWith("http")) {
846
+ if (button)
847
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
848
+ ...button,
849
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
850
+ href,
851
+ target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
852
+ style: {
853
+ ...Link2.style,
854
+ ...style || {}
855
+ },
856
+ children: text || children
857
+ })
858
+ });
859
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
860
+ href,
861
+ target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
862
+ style: {
863
+ ...Link2.style,
864
+ ...style || {}
865
+ },
866
+ children: text || children
867
+ });
868
+ }
869
+ if (button)
870
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
871
+ ...button,
872
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
873
+ to: href,
874
+ target: target || (Link2 == null ? void 0 : Link2.target),
875
+ style: {
876
+ ...Link2.style,
877
+ ...style || {}
878
+ },
879
+ children: text || children
880
+ })
881
+ });
882
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
883
+ to: href,
884
+ target: target || (Link2 == null ? void 0 : Link2.target),
885
+ style: {
886
+ ...Link2.style,
887
+ ...style || {}
888
+ },
889
+ children: text || children
890
+ });
891
+ }
892
+
893
+ // src/Modal.tsx
894
+ var import_antd8 = require("antd");
895
+ var import_react9 = require("react");
896
+ var import_jsx_runtime = require("react/jsx-runtime");
897
+ function useModal(init) {
898
+ const [props, setProps] = (0, import_react9.useState)({
899
+ open: false,
900
+ onCancel: () => setProps((prev) => ({
901
+ ...prev,
902
+ open: false
903
+ })),
904
+ ...init
905
+ });
906
+ return {
907
+ modal: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd8.Modal, {
908
+ ...props
909
+ }),
910
+ modalProps: props,
911
+ setModalProps(changes) {
912
+ setProps((prev) => ({
913
+ ...prev,
914
+ ...changes
915
+ }));
916
+ }
917
+ };
918
+ }
919
+
920
+ // src/Routers.tsx
921
+ var import_antd9 = require("antd");
922
+ var import_react10 = require("react");
923
+ var import_react_router_dom2 = require("react-router-dom");
924
+ var import_jsx_runtime = require("react/jsx-runtime");
925
+ function PageNotFound() {
926
+ const config = useConfigContext();
927
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd9.Result, {
928
+ status: "404",
929
+ title: config.common.pageNotFound
930
+ });
931
+ }
932
+ function Routes(props) {
933
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_router_dom2.Routes, {
934
+ children: [
935
+ props.routes.map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom2.Route, {
936
+ ...r,
937
+ element: r.element || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react10.Suspense, {
938
+ fallback: props.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
939
+ style: { padding: "24px" },
940
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd9.Skeleton, {
941
+ active: true
942
+ })
943
+ }),
944
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(r.page, {})
945
+ })
946
+ }, r.path)),
947
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom2.Route, {
948
+ path: "*",
949
+ element: props.notFound || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageNotFound, {})
950
+ }, "*")
951
+ ]
952
+ });
953
+ }
954
+
955
+ // src/Table.tsx
956
+ var import_react11 = require("react");
957
+ var import_antd10 = require("antd");
958
+ var import_dayjs2 = __toESM(require("dayjs"));
959
+ var import_icons3 = require("@ant-design/icons");
960
+ var import_lodash_es6 = require("lodash-es");
961
+ var import_react12 = require("@faasjs/react");
962
+ var import_jsx_runtime = require("react/jsx-runtime");
963
+ function processValue(item, value) {
964
+ var _a;
965
+ const transferred = transferValue(item.type, value);
966
+ if (transferred === null || Array.isArray(transferred) && transferred.length === 0)
967
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
968
+ if (item.options) {
969
+ if (item.type.endsWith("[]"))
970
+ return transferred.map((v) => {
971
+ var _a2;
972
+ return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
973
+ }).join(", ");
974
+ if ([
975
+ "string",
976
+ "number",
977
+ "boolean"
978
+ ].includes(item.type))
979
+ return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
980
+ }
981
+ if (item.type.endsWith("[]"))
982
+ return transferred.join(", ");
983
+ if (["date", "time"].includes(item.type))
984
+ return transferred.format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
985
+ return value;
986
+ }
987
+ function Table(props) {
988
+ const [columns, setColumns] = (0, import_react11.useState)();
989
+ const { common: common2, antd } = useConfigContext();
990
+ (0, import_react11.useEffect)(() => {
991
+ var _a;
992
+ for (const item of props.items) {
993
+ if (!item.key)
994
+ item.key = item.id;
995
+ if (!item.dataIndex)
996
+ item.dataIndex = item.id;
997
+ if (!item.title)
998
+ item.title = (0, import_lodash_es6.upperFirst)(item.id);
999
+ if (!item.type)
1000
+ item.type = "string";
1001
+ if ((_a = item.options) == null ? void 0 : _a.length) {
1002
+ item.options = transferOptions(item.options);
1003
+ item.filters = item.options.map((o) => ({
1004
+ text: o.label,
1005
+ value: o.value
1006
+ }));
1007
+ }
1008
+ if (item.children)
1009
+ delete item.children;
1010
+ if (props.extendTypes && props.extendTypes[item.type]) {
1011
+ if (props.extendTypes[item.type].children)
1012
+ item.render = (value, values) => (0, import_react11.cloneElement)(
1013
+ props.extendTypes[item.type].children,
1014
+ {
1015
+ value,
1016
+ values
1017
+ }
1018
+ );
1019
+ else if (props.extendTypes[item.type].render)
1020
+ item.render = props.extendTypes[item.type].render;
1021
+ else
1022
+ throw Error(item.type + " requires children or render");
1023
+ continue;
1024
+ }
1025
+ switch (item.type) {
1026
+ case "string":
1027
+ if (!item.render)
1028
+ item.render = (value) => processValue(item, value);
1029
+ if (!item.onFilter)
1030
+ item.onFilter = (value, row) => {
1031
+ if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
1032
+ return true;
1033
+ if (!row[item.id])
1034
+ return false;
1035
+ return row[item.id].toLowerCase().includes(value.toLowerCase());
1036
+ };
1037
+ if (!item.filters && item.filterDropdown !== false && item.optionsType !== "auto")
1038
+ item.filterDropdown = ({
1039
+ setSelectedKeys,
1040
+ confirm,
1041
+ clearFilters
1042
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1043
+ placeholder: `${common2.search} ${item.title}`,
1044
+ allowClear: true,
1045
+ onSearch: (v) => {
1046
+ if (v) {
1047
+ setSelectedKeys([v]);
1048
+ } else {
1049
+ setSelectedKeys([]);
1050
+ clearFilters();
1051
+ }
1052
+ confirm();
1053
+ }
1054
+ });
1055
+ break;
1056
+ case "string[]":
1057
+ if (!item.render)
1058
+ item.render = (value) => processValue(item, value);
1059
+ if (!item.onFilter)
1060
+ item.onFilter = (value, row) => {
1061
+ if (value === null && (!row[item.id] || !row[item.id].length))
1062
+ return true;
1063
+ if (!row[item.id] || !row[item.id].length)
1064
+ return false;
1065
+ return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
1066
+ };
1067
+ if (!item.filters && item.filterDropdown !== false)
1068
+ item.filterDropdown = ({
1069
+ setSelectedKeys,
1070
+ confirm,
1071
+ clearFilters
1072
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1073
+ placeholder: `${common2.search} ${item.title}`,
1074
+ allowClear: true,
1075
+ onSearch: (v) => {
1076
+ if (v) {
1077
+ setSelectedKeys([v]);
1078
+ } else {
1079
+ setSelectedKeys([]);
1080
+ clearFilters();
1081
+ }
1082
+ confirm();
1083
+ }
1084
+ });
1085
+ break;
1086
+ case "number":
1087
+ if (!item.render)
1088
+ item.render = (value) => processValue(item, value);
1089
+ if (!item.sorter)
1090
+ item.sorter = (a, b) => a[item.id] - b[item.id];
1091
+ if (!item.onFilter)
1092
+ item.onFilter = (value, row) => {
1093
+ if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
1094
+ return true;
1095
+ return value === row[item.id];
1096
+ };
1097
+ if (!item.filters && item.filterDropdown !== false)
1098
+ item.filterDropdown = ({
1099
+ setSelectedKeys,
1100
+ confirm,
1101
+ clearFilters
1102
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1103
+ placeholder: `${common2.search} ${item.title}`,
1104
+ allowClear: true,
1105
+ onSearch: (v) => {
1106
+ if (v) {
1107
+ setSelectedKeys([Number(v)]);
1108
+ } else {
1109
+ setSelectedKeys([]);
1110
+ clearFilters();
1111
+ }
1112
+ confirm();
1113
+ }
1114
+ });
1115
+ break;
1116
+ case "number[]":
1117
+ if (!item.render)
1118
+ item.render = (value) => processValue(item, value).join(", ");
1119
+ if (!item.onFilter)
1120
+ item.onFilter = (value, row) => {
1121
+ if (value === null && (!row[item.id] || !row[item.id].length))
1122
+ return true;
1123
+ if (!row[item.id] || !row[item.id].length)
1124
+ return false;
1125
+ return row[item.id].includes(value);
1126
+ };
1127
+ if (!item.filters && item.filterDropdown !== false)
1128
+ item.filterDropdown = ({
1129
+ setSelectedKeys,
1130
+ confirm,
1131
+ clearFilters
1132
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1133
+ placeholder: `${common2.search} ${item.title}`,
1134
+ allowClear: true,
1135
+ onSearch: (v) => {
1136
+ if (v) {
1137
+ setSelectedKeys([Number(v)]);
1138
+ } else {
1139
+ setSelectedKeys([]);
1140
+ clearFilters();
1141
+ }
1142
+ confirm();
1143
+ }
1144
+ });
1145
+ break;
1146
+ case "boolean":
1147
+ if (!item.render)
1148
+ item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {}) : value ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CheckOutlined, {
1149
+ style: {
1150
+ marginTop: "4px",
1151
+ color: "#52c41a"
1152
+ }
1153
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CloseOutlined, {
1154
+ style: {
1155
+ marginTop: "4px",
1156
+ color: "#ff4d4f"
1157
+ }
1158
+ });
1159
+ if (item.filterDropdown !== false)
1160
+ item.filterDropdown = ({
1161
+ setSelectedKeys,
1162
+ selectedKeys,
1163
+ confirm
1164
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd10.Radio.Group, {
1165
+ style: { padding: 8 },
1166
+ buttonStyle: "solid",
1167
+ value: selectedKeys[0],
1168
+ onChange: (e) => {
1169
+ setSelectedKeys(e.target.value ? [e.target.value] : []);
1170
+ confirm();
1171
+ },
1172
+ children: [
1173
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1174
+ children: common2.all
1175
+ }),
1176
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1177
+ value: "true",
1178
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CheckOutlined, {
1179
+ style: {
1180
+ color: "#52c41a",
1181
+ verticalAlign: "middle"
1182
+ }
1183
+ })
1184
+ }),
1185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1186
+ value: "false",
1187
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CloseOutlined, {
1188
+ style: {
1189
+ verticalAlign: "middle",
1190
+ color: "#ff4d4f"
1191
+ }
1192
+ })
1193
+ }),
1194
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1195
+ value: "empty",
1196
+ children: common2.blank
1197
+ })
1198
+ ]
1199
+ });
1200
+ if (!item.onFilter)
1201
+ item.onFilter = (value, row) => {
1202
+ switch (value) {
1203
+ case "true":
1204
+ return !(0, import_lodash_es6.isNil)(row[item.id]) && !!row[item.id];
1205
+ case "false":
1206
+ return !(0, import_lodash_es6.isNil)(row[item.id]) && !row[item.id];
1207
+ case "empty":
1208
+ return (0, import_lodash_es6.isNil)(row[item.id]);
1209
+ default:
1210
+ return true;
1211
+ }
1212
+ };
1213
+ break;
1214
+ case "date":
1215
+ if (!item.render)
1216
+ item.render = (value) => processValue(item, value);
1217
+ if (!item.onFilter)
1218
+ item.onFilter = (value, row) => (0, import_dayjs2.default)(row[item.id]).isSame((0, import_dayjs2.default)(value));
1219
+ if (!item.sorter)
1220
+ item.sorter = (a, b) => (0, import_dayjs2.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1221
+ break;
1222
+ case "time":
1223
+ if (!item.render)
1224
+ item.render = (value) => processValue(item, value);
1225
+ if (!item.onFilter)
1226
+ item.onFilter = (value, row) => (0, import_dayjs2.default)(row[item.id]).isSame((0, import_dayjs2.default)(value));
1227
+ if (!item.sorter)
1228
+ item.sorter = (a, b) => (0, import_dayjs2.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1229
+ break;
1230
+ case "object":
1231
+ if (!item.render)
1232
+ item.render = (value) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
1233
+ items: item.object,
1234
+ dataSource: value || {},
1235
+ column: 1
1236
+ });
1237
+ break;
1238
+ case "object[]":
1239
+ if (!item.render)
1240
+ item.render = (value) => value.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
1241
+ items: item.object,
1242
+ dataSource: v || [],
1243
+ column: 1
1244
+ }, i));
1245
+ break;
1246
+ default:
1247
+ if (!item.render)
1248
+ item.render = (value) => processValue(item, value);
1249
+ if (!item.onFilter)
1250
+ item.onFilter = (value, row) => {
1251
+ if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
1252
+ return true;
1253
+ return value === row[item.id];
1254
+ };
1255
+ break;
1256
+ }
1257
+ }
1258
+ setColumns(props.items);
1259
+ }, [props.items]);
1260
+ (0, import_react11.useEffect)(() => {
1261
+ if (!props.dataSource || !columns)
1262
+ return;
1263
+ for (const column of columns) {
1264
+ if (column.optionsType === "auto" && !column.options && !column.filters) {
1265
+ setColumns((prev) => {
1266
+ const newColumns = [...prev];
1267
+ const index = newColumns.findIndex((item) => item.id === column.id);
1268
+ newColumns[index].filters = (0, import_lodash_es6.uniqBy)(props.dataSource, column.id).map((v) => ({
1269
+ text: v[column.id],
1270
+ value: v[column.id]
1271
+ })).concat({
1272
+ text: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {}),
1273
+ value: null
1274
+ });
1275
+ return newColumns;
1276
+ });
1277
+ }
1278
+ }
1279
+ }, [props.dataSource, columns]);
1280
+ if (!columns)
1281
+ return null;
1282
+ if (!props.faasData)
1283
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1284
+ ...antd,
1285
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1286
+ ...props,
1287
+ rowKey: props.rowKey || "id",
1288
+ columns,
1289
+ dataSource: props.dataSource
1290
+ })
1291
+ });
1292
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react12.FaasDataWrapper, {
1293
+ fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Skeleton, {
1294
+ active: true
1295
+ }),
1296
+ render: ({
1297
+ data,
1298
+ params,
1299
+ reload
1300
+ }) => {
1301
+ if (!data)
1302
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1303
+ ...antd,
1304
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1305
+ ...props,
1306
+ rowKey: props.rowKey || "id",
1307
+ columns,
1308
+ dataSource: []
1309
+ })
1310
+ });
1311
+ if (Array.isArray(data))
1312
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1313
+ ...antd,
1314
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1315
+ ...props,
1316
+ rowKey: props.rowKey || "id",
1317
+ columns,
1318
+ dataSource: data
1319
+ })
1320
+ });
1321
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1322
+ ...antd,
1323
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1324
+ ...props,
1325
+ rowKey: props.rowKey || "id",
1326
+ columns,
1327
+ dataSource: data.rows,
1328
+ pagination: {
1329
+ ...props.pagination,
1330
+ ...data.pagination
1331
+ },
1332
+ onChange: (pagination, filters, sorter, extra) => {
1333
+ if (props.onChange) {
1334
+ const processed = props.onChange(pagination, filters, sorter, extra);
1335
+ reload({
1336
+ ...params,
1337
+ pagination: processed.pagination,
1338
+ filters: processed.filters,
1339
+ sorter: processed.sorter
1340
+ });
1341
+ return;
1342
+ }
1343
+ reload({
1344
+ ...params,
1345
+ pagination,
1346
+ filters,
1347
+ sorter
1348
+ });
1349
+ }
1350
+ })
1351
+ });
1352
+ },
1353
+ ...props.faasData
1354
+ });
1355
+ }
1356
+
1357
+ // src/Title.tsx
1358
+ var import_react13 = require("react");
1359
+ var import_jsx_runtime = require("react/jsx-runtime");
1360
+ function Title(props) {
1361
+ const { Title: Title2 } = useConfigContext();
1362
+ (0, import_react13.useEffect)(() => {
1363
+ const title = Array.isArray(props.title) ? props.title : [props.title];
1364
+ document.title = title.concat(props.suffix || Title2.suffix).filter((t) => !!t).join(props.separator || Title2.separator);
1365
+ }, [props]);
1366
+ if (props.h1) {
1367
+ if (typeof props.h1 === "boolean")
1368
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
1369
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1370
+ });
1371
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
1372
+ className: props.h1.className,
1373
+ style: props.h1.style,
1374
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1375
+ });
1376
+ }
1377
+ if (props.plain)
1378
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
1379
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1380
+ });
1381
+ if (props.children)
1382
+ return (0, import_react13.cloneElement)(props.children, { title: props.title });
1383
+ return null;
1384
+ }
1385
+ // Annotate the CommonJS export names for ESM import in node:
1386
+ 0 && (module.exports = {
1387
+ Blank,
1388
+ ConfigContext,
1389
+ ConfigProvider,
1390
+ Description,
1391
+ Drawer,
1392
+ Form,
1393
+ FormItem,
1394
+ Link,
1395
+ Modal,
1396
+ PageNotFound,
1397
+ Routes,
1398
+ Table,
1399
+ Title,
1400
+ transferOptions,
1401
+ transferValue,
1402
+ useConfigContext,
1403
+ useDrawer,
1404
+ useModal
1405
+ });