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

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,1358 @@
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.common.required}`));
379
+ }
380
+ });
381
+ else
382
+ propsCopy.rules.push({
383
+ required: true,
384
+ message: `${propsCopy.label || propsCopy.title} ${config.common.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 config = useConfigContext();
412
+ const [hidden, setHidden] = (0, import_react6.useState)(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
+ propsCopy.shouldUpdate = (_, cur) => {
422
+ const show = condition(cur);
423
+ setHidden(!show);
424
+ return show;
425
+ };
426
+ delete propsCopy.if;
427
+ }
428
+ setComputedProps(processProps(propsCopy, config));
429
+ }, [props]);
430
+ if (!computedProps)
431
+ return null;
432
+ if (hidden)
433
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
434
+ ...computedProps,
435
+ noStyle: true,
436
+ rules: [],
437
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
438
+ hidden: true
439
+ })
440
+ });
441
+ if (extendTypes && extendTypes[computedProps.type])
442
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
443
+ ...computedProps,
444
+ children: extendTypes[computedProps.type].children
445
+ });
446
+ if (computedProps.children)
447
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
448
+ ...computedProps,
449
+ children: computedProps.children
450
+ });
451
+ if (computedProps.render)
452
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
453
+ ...computedProps,
454
+ children: computedProps.render()
455
+ });
456
+ switch (computedProps.type) {
457
+ case "string":
458
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
459
+ ...computedProps,
460
+ children: computedProps.options ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
461
+ ...computedProps.input
462
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
463
+ ...computedProps.input
464
+ })
465
+ });
466
+ case "string[]":
467
+ if (computedProps.options)
468
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
469
+ ...computedProps,
470
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
471
+ mode: "multiple",
472
+ ...computedProps.input
473
+ })
474
+ });
475
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
476
+ name: computedProps.name,
477
+ rules: computedProps.rules,
478
+ children: (fields, { add, remove }, { errors }) => {
479
+ var _a2;
480
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
481
+ children: [
482
+ computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
483
+ className: "ant-form-item-label",
484
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
485
+ className: computedProps.rules.find((r) => r.required) && "ant-form-item-required",
486
+ children: computedProps.label
487
+ })
488
+ }),
489
+ fields.map((field) => {
490
+ var _a3;
491
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
492
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Row, {
493
+ gutter: 24,
494
+ style: { flexFlow: "row nowrap" },
495
+ children: [
496
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
497
+ span: 23,
498
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
499
+ ...field,
500
+ noStyle: true,
501
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
502
+ ...computedProps.input
503
+ })
504
+ })
505
+ }),
506
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
507
+ span: 1,
508
+ 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, {
509
+ danger: true,
510
+ type: "link",
511
+ style: { float: "right" },
512
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.MinusCircleOutlined, {}),
513
+ onClick: () => remove(field.name)
514
+ })
515
+ })
516
+ ]
517
+ })
518
+ }, field.key);
519
+ }),
520
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
521
+ children: [
522
+ !((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
523
+ type: "dashed",
524
+ block: true,
525
+ onClick: () => add(),
526
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {})
527
+ }),
528
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
529
+ errors
530
+ })
531
+ ]
532
+ })
533
+ ]
534
+ });
535
+ }
536
+ });
537
+ case "number":
538
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
539
+ ...computedProps,
540
+ children: computedProps.options ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
541
+ ...computedProps.input
542
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.InputNumber, {
543
+ style: { width: "100%" },
544
+ ...computedProps.input
545
+ })
546
+ });
547
+ case "number[]":
548
+ if (computedProps.options)
549
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
550
+ ...computedProps,
551
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
552
+ mode: "multiple",
553
+ ...computedProps.input
554
+ })
555
+ });
556
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
557
+ name: computedProps.name,
558
+ rules: computedProps.rules,
559
+ children: (fields, { add, remove }, { errors }) => {
560
+ var _a2, _b;
561
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
562
+ children: [
563
+ computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
564
+ className: "ant-form-item-label",
565
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
566
+ className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required",
567
+ children: computedProps.label
568
+ })
569
+ }),
570
+ fields.map((field) => {
571
+ var _a3;
572
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
573
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Row, {
574
+ gutter: 24,
575
+ style: { flexFlow: "row nowrap" },
576
+ children: [
577
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
578
+ span: 23,
579
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
580
+ ...field,
581
+ noStyle: true,
582
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.InputNumber, {
583
+ style: { width: "100%" },
584
+ ...computedProps.input
585
+ })
586
+ })
587
+ }),
588
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
589
+ span: 1,
590
+ 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, {
591
+ danger: true,
592
+ type: "link",
593
+ style: { float: "right" },
594
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.MinusCircleOutlined, {}),
595
+ onClick: () => remove(field.name)
596
+ })
597
+ })
598
+ ]
599
+ })
600
+ }, field.key);
601
+ }),
602
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
603
+ children: [
604
+ !((_b = computedProps.input) == null ? void 0 : _b.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
605
+ type: "dashed",
606
+ block: true,
607
+ onClick: () => add(),
608
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {})
609
+ }),
610
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
611
+ errors
612
+ })
613
+ ]
614
+ })
615
+ ]
616
+ });
617
+ }
618
+ });
619
+ case "boolean":
620
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
621
+ ...computedProps,
622
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Switch, {
623
+ ...computedProps.input
624
+ })
625
+ });
626
+ case "date":
627
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
628
+ ...computedProps,
629
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.DatePicker, {
630
+ ...computedProps.input
631
+ })
632
+ });
633
+ case "time":
634
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
635
+ ...computedProps,
636
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.TimePicker, {
637
+ ...computedProps.input
638
+ })
639
+ });
640
+ case "object":
641
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
642
+ children: [
643
+ computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
644
+ className: "ant-form-item-label",
645
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
646
+ className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required",
647
+ children: computedProps.label
648
+ })
649
+ }),
650
+ computedProps.object.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
651
+ ...o
652
+ }, o.id))
653
+ ]
654
+ });
655
+ case "object[]":
656
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
657
+ name: computedProps.name,
658
+ rules: computedProps.rules,
659
+ children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
660
+ children: [
661
+ fields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
662
+ style: { marginBottom: 0 },
663
+ children: [
664
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
665
+ className: "ant-form-item-label",
666
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
667
+ children: [
668
+ computedProps.label,
669
+ " ",
670
+ field.name + 1,
671
+ !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
672
+ danger: true,
673
+ type: "link",
674
+ onClick: () => remove(field.name),
675
+ children: config.common.delete
676
+ })
677
+ ]
678
+ })
679
+ }),
680
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Row, {
681
+ gutter: 24,
682
+ children: computedProps.object.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
683
+ span: o.col || 24,
684
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
685
+ ...o,
686
+ name: [field.name, o.id]
687
+ })
688
+ }, o.id))
689
+ })
690
+ ]
691
+ }, field.key)),
692
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
693
+ children: [
694
+ !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Button, {
695
+ type: "dashed",
696
+ block: true,
697
+ onClick: () => add(),
698
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
699
+ children: [
700
+ config.common.add,
701
+ " ",
702
+ computedProps.label
703
+ ]
704
+ }),
705
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
706
+ errors
707
+ })
708
+ ]
709
+ })
710
+ ]
711
+ })
712
+ });
713
+ default:
714
+ return null;
715
+ }
716
+ }
717
+
718
+ // src/Form.tsx
719
+ var import_jsx_runtime = require("react/jsx-runtime");
720
+ function Form(props) {
721
+ var _a, _b;
722
+ const [loading, setLoading] = (0, import_react8.useState)(false);
723
+ const [computedProps, setComputedProps] = (0, import_react8.useState)();
724
+ const config = useConfigContext();
725
+ const [extendTypes, setExtendTypes] = (0, import_react8.useState)();
726
+ const [form] = import_antd6.Form.useForm(props.form);
727
+ const [initialValues, setInitialValues] = (0, import_react8.useState)(props.initialValues);
728
+ (0, import_react8.useEffect)(() => {
729
+ var _a2, _b2;
730
+ const propsCopy = {
731
+ ...props,
732
+ form
733
+ };
734
+ if (propsCopy.initialValues) {
735
+ for (const key in propsCopy.initialValues)
736
+ propsCopy.initialValues[key] = transferValue(
737
+ (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
738
+ propsCopy.initialValues[key]
739
+ );
740
+ setInitialValues(propsCopy.initialValues);
741
+ delete propsCopy.initialValues;
742
+ }
743
+ if (propsCopy.onFinish) {
744
+ propsCopy.onFinish = async (values) => {
745
+ var _a3;
746
+ setLoading(true);
747
+ try {
748
+ if (propsCopy.submit && ((_a3 = propsCopy.submit.to) == null ? void 0 : _a3.action)) {
749
+ await props.onFinish(values, async (values2) => (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
750
+ ...values2,
751
+ ...propsCopy.submit.to.params
752
+ } : values2));
753
+ } else
754
+ await props.onFinish(values);
755
+ } catch (error) {
756
+ console.error(error);
757
+ }
758
+ setLoading(false);
759
+ };
760
+ } else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
761
+ propsCopy.onFinish = async (values) => {
762
+ setLoading(true);
763
+ return (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
764
+ ...values,
765
+ ...propsCopy.submit.to.params
766
+ } : values).finally(() => setLoading(false));
767
+ };
768
+ }
769
+ if (propsCopy.extendTypes) {
770
+ setExtendTypes(propsCopy.extendTypes);
771
+ delete propsCopy.extendTypes;
772
+ }
773
+ setComputedProps(propsCopy);
774
+ }, [props]);
775
+ const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
776
+ if (props.onValuesChange) {
777
+ props.onValuesChange(changedValues, allValues);
778
+ }
779
+ if (!props.items)
780
+ return;
781
+ for (const key in changedValues) {
782
+ const item = computedProps.items.find((i) => i.id === key);
783
+ if (item == null ? void 0 : item.onValueChange)
784
+ item.onValueChange(changedValues[key], allValues, form);
785
+ }
786
+ }, [computedProps]);
787
+ (0, import_react8.useEffect)(() => {
788
+ if (!initialValues)
789
+ return;
790
+ form.setFieldsValue(initialValues);
791
+ setInitialValues(null);
792
+ }, [computedProps]);
793
+ if (!computedProps)
794
+ return null;
795
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd6.Form, {
796
+ ...computedProps,
797
+ onValuesChange,
798
+ children: [
799
+ computedProps.beforeItems,
800
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
801
+ ...item,
802
+ extendTypes
803
+ }, item.id)),
804
+ computedProps.children,
805
+ computedProps.submit !== false && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd6.Button, {
806
+ htmlType: "submit",
807
+ type: "primary",
808
+ loading,
809
+ children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text
810
+ }),
811
+ computedProps.footer
812
+ ]
813
+ });
814
+ }
815
+ Form.useForm = import_antd6.Form.useForm;
816
+
817
+ // src/Link.tsx
818
+ var import_react_router_dom = require("react-router-dom");
819
+ var import_antd7 = require("antd");
820
+ var import_jsx_runtime = require("react/jsx-runtime");
821
+ function Link({
822
+ href,
823
+ target,
824
+ text,
825
+ children,
826
+ style,
827
+ button
828
+ }) {
829
+ const { Link: Link2 } = useConfigContext();
830
+ style = Object.assign({ cursor: "pointer" }, style);
831
+ if (href.startsWith("http")) {
832
+ if (button)
833
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
834
+ ...button,
835
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
836
+ href,
837
+ target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
838
+ style: {
839
+ ...Link2.style,
840
+ ...style || {}
841
+ },
842
+ children: text || children
843
+ })
844
+ });
845
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
846
+ href,
847
+ target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
848
+ style: {
849
+ ...Link2.style,
850
+ ...style || {}
851
+ },
852
+ children: text || children
853
+ });
854
+ }
855
+ if (button)
856
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
857
+ ...button,
858
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
859
+ to: href,
860
+ target: target || (Link2 == null ? void 0 : Link2.target),
861
+ style: {
862
+ ...Link2.style,
863
+ ...style || {}
864
+ },
865
+ children: text || children
866
+ })
867
+ });
868
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
869
+ to: href,
870
+ target: target || (Link2 == null ? void 0 : Link2.target),
871
+ style: {
872
+ ...Link2.style,
873
+ ...style || {}
874
+ },
875
+ children: text || children
876
+ });
877
+ }
878
+
879
+ // src/Modal.tsx
880
+ var import_antd8 = require("antd");
881
+ var import_react9 = require("react");
882
+ var import_jsx_runtime = require("react/jsx-runtime");
883
+ function useModal(init) {
884
+ const [props, setProps] = (0, import_react9.useState)({
885
+ open: false,
886
+ onCancel: () => setProps((prev) => ({
887
+ ...prev,
888
+ open: false
889
+ })),
890
+ ...init
891
+ });
892
+ return {
893
+ modal: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd8.Modal, {
894
+ ...props
895
+ }),
896
+ modalProps: props,
897
+ setModalProps(changes) {
898
+ setProps((prev) => ({
899
+ ...prev,
900
+ ...changes
901
+ }));
902
+ }
903
+ };
904
+ }
905
+
906
+ // src/Routers.tsx
907
+ var import_antd9 = require("antd");
908
+ var import_react10 = require("react");
909
+ var import_react_router_dom2 = require("react-router-dom");
910
+ var import_jsx_runtime = require("react/jsx-runtime");
911
+ function PageNotFound() {
912
+ const config = useConfigContext();
913
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd9.Result, {
914
+ status: "404",
915
+ title: config.common.pageNotFound
916
+ });
917
+ }
918
+ function Routes(props) {
919
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_router_dom2.Routes, {
920
+ children: [
921
+ props.routes.map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom2.Route, {
922
+ ...r,
923
+ element: r.element || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react10.Suspense, {
924
+ fallback: props.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
925
+ style: { padding: "24px" },
926
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd9.Skeleton, {
927
+ active: true
928
+ })
929
+ }),
930
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(r.page, {})
931
+ })
932
+ }, r.path)),
933
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom2.Route, {
934
+ path: "*",
935
+ element: props.notFound || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageNotFound, {})
936
+ }, "*")
937
+ ]
938
+ });
939
+ }
940
+
941
+ // src/Table.tsx
942
+ var import_react11 = require("react");
943
+ var import_antd10 = require("antd");
944
+ var import_dayjs2 = __toESM(require("dayjs"));
945
+ var import_icons3 = require("@ant-design/icons");
946
+ var import_lodash_es6 = require("lodash-es");
947
+ var import_react12 = require("@faasjs/react");
948
+ var import_jsx_runtime = require("react/jsx-runtime");
949
+ function processValue(item, value) {
950
+ var _a;
951
+ const transferred = transferValue(item.type, value);
952
+ if (transferred === null || Array.isArray(transferred) && transferred.length === 0)
953
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
954
+ if (item.options) {
955
+ if (item.type.endsWith("[]"))
956
+ return transferred.map((v) => {
957
+ var _a2;
958
+ return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
959
+ }).join(", ");
960
+ if ([
961
+ "string",
962
+ "number",
963
+ "boolean"
964
+ ].includes(item.type))
965
+ return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
966
+ }
967
+ if (item.type.endsWith("[]"))
968
+ return transferred.join(", ");
969
+ if (["date", "time"].includes(item.type))
970
+ return transferred.format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
971
+ return value;
972
+ }
973
+ function Table(props) {
974
+ const [columns, setColumns] = (0, import_react11.useState)();
975
+ const { common: common2 } = useConfigContext();
976
+ (0, import_react11.useEffect)(() => {
977
+ var _a;
978
+ for (const item of props.items) {
979
+ if (!item.key)
980
+ item.key = item.id;
981
+ if (!item.dataIndex)
982
+ item.dataIndex = item.id;
983
+ if (!item.title)
984
+ item.title = (0, import_lodash_es6.upperFirst)(item.id);
985
+ if (!item.type)
986
+ item.type = "string";
987
+ if ((_a = item.options) == null ? void 0 : _a.length) {
988
+ item.options = transferOptions(item.options);
989
+ item.filters = item.options.map((o) => ({
990
+ text: o.label,
991
+ value: o.value
992
+ }));
993
+ }
994
+ if (item.children)
995
+ delete item.children;
996
+ if (props.extendTypes && props.extendTypes[item.type]) {
997
+ if (props.extendTypes[item.type].children)
998
+ item.render = (value, values) => (0, import_react11.cloneElement)(
999
+ props.extendTypes[item.type].children,
1000
+ {
1001
+ value,
1002
+ values
1003
+ }
1004
+ );
1005
+ else if (props.extendTypes[item.type].render)
1006
+ item.render = props.extendTypes[item.type].render;
1007
+ else
1008
+ throw Error(item.type + " requires children or render");
1009
+ continue;
1010
+ }
1011
+ switch (item.type) {
1012
+ case "string":
1013
+ if (!item.render)
1014
+ item.render = (value) => processValue(item, value);
1015
+ if (!item.onFilter)
1016
+ item.onFilter = (value, row) => {
1017
+ if (!row[item.id])
1018
+ return false;
1019
+ return row[item.id].toLowerCase().includes(value.toLowerCase());
1020
+ };
1021
+ if (!item.filters && item.filterDropdown !== false && item.optionsType !== "auto")
1022
+ item.filterDropdown = ({
1023
+ setSelectedKeys,
1024
+ confirm,
1025
+ clearFilters
1026
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1027
+ placeholder: `${common2.search} ${item.title}`,
1028
+ allowClear: true,
1029
+ onSearch: (v) => {
1030
+ if (v) {
1031
+ setSelectedKeys([v]);
1032
+ } else {
1033
+ setSelectedKeys([]);
1034
+ clearFilters();
1035
+ }
1036
+ confirm();
1037
+ }
1038
+ });
1039
+ break;
1040
+ case "string[]":
1041
+ if (!item.render)
1042
+ item.render = (value) => processValue(item, value);
1043
+ if (!item.onFilter)
1044
+ item.onFilter = (value, row) => {
1045
+ if (!row[item.id] || !row[item.id].length)
1046
+ return false;
1047
+ return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
1048
+ };
1049
+ if (!item.filters && item.filterDropdown !== false)
1050
+ item.filterDropdown = ({
1051
+ setSelectedKeys,
1052
+ confirm,
1053
+ clearFilters
1054
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1055
+ placeholder: `${common2.search} ${item.title}`,
1056
+ allowClear: true,
1057
+ onSearch: (v) => {
1058
+ if (v) {
1059
+ setSelectedKeys([v]);
1060
+ } else {
1061
+ setSelectedKeys([]);
1062
+ clearFilters();
1063
+ }
1064
+ confirm();
1065
+ }
1066
+ });
1067
+ break;
1068
+ case "number":
1069
+ if (!item.render)
1070
+ item.render = (value) => processValue(item, value);
1071
+ if (!item.sorter)
1072
+ item.sorter = (a, b) => a[item.id] - b[item.id];
1073
+ if (!item.onFilter)
1074
+ item.onFilter = (value, row) => value === row[item.id];
1075
+ if (!item.filters && item.filterDropdown !== false)
1076
+ item.filterDropdown = ({
1077
+ setSelectedKeys,
1078
+ confirm,
1079
+ clearFilters
1080
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1081
+ placeholder: `${common2.search} ${item.title}`,
1082
+ allowClear: true,
1083
+ onSearch: (v) => {
1084
+ if (v) {
1085
+ setSelectedKeys([Number(v)]);
1086
+ } else {
1087
+ setSelectedKeys([]);
1088
+ clearFilters();
1089
+ }
1090
+ confirm();
1091
+ }
1092
+ });
1093
+ break;
1094
+ case "number[]":
1095
+ if (!item.render)
1096
+ item.render = (value) => processValue(item, value).join(", ");
1097
+ if (!item.onFilter)
1098
+ item.onFilter = (value, row) => row[item.id].includes(value);
1099
+ if (!item.filters && item.filterDropdown !== false)
1100
+ item.filterDropdown = ({
1101
+ setSelectedKeys,
1102
+ confirm,
1103
+ clearFilters
1104
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1105
+ placeholder: `${common2.search} ${item.title}`,
1106
+ allowClear: true,
1107
+ onSearch: (v) => {
1108
+ if (v) {
1109
+ setSelectedKeys([Number(v)]);
1110
+ } else {
1111
+ setSelectedKeys([]);
1112
+ clearFilters();
1113
+ }
1114
+ confirm();
1115
+ }
1116
+ });
1117
+ break;
1118
+ case "boolean":
1119
+ if (!item.render)
1120
+ item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {}) : value ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CheckOutlined, {
1121
+ style: {
1122
+ marginTop: "4px",
1123
+ color: "#52c41a"
1124
+ }
1125
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CloseOutlined, {
1126
+ style: {
1127
+ marginTop: "4px",
1128
+ color: "#ff4d4f"
1129
+ }
1130
+ });
1131
+ if (item.filterDropdown !== false)
1132
+ item.filterDropdown = ({
1133
+ setSelectedKeys,
1134
+ selectedKeys,
1135
+ confirm
1136
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd10.Radio.Group, {
1137
+ style: { padding: 8 },
1138
+ buttonStyle: "solid",
1139
+ value: selectedKeys[0],
1140
+ onChange: (e) => {
1141
+ setSelectedKeys(e.target.value ? [e.target.value] : []);
1142
+ confirm();
1143
+ },
1144
+ children: [
1145
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1146
+ children: common2.all
1147
+ }),
1148
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1149
+ value: "true",
1150
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CheckOutlined, {
1151
+ style: {
1152
+ color: "#52c41a",
1153
+ verticalAlign: "middle"
1154
+ }
1155
+ })
1156
+ }),
1157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1158
+ value: "false",
1159
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CloseOutlined, {
1160
+ style: {
1161
+ verticalAlign: "middle",
1162
+ color: "#ff4d4f"
1163
+ }
1164
+ })
1165
+ }),
1166
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1167
+ value: "empty",
1168
+ children: common2.blank
1169
+ })
1170
+ ]
1171
+ });
1172
+ if (!item.onFilter)
1173
+ item.onFilter = (value, row) => {
1174
+ switch (value) {
1175
+ case "true":
1176
+ return !(0, import_lodash_es6.isNil)(row[item.id]) && !!row[item.id];
1177
+ case "false":
1178
+ return !(0, import_lodash_es6.isNil)(row[item.id]) && !row[item.id];
1179
+ case "empty":
1180
+ return (0, import_lodash_es6.isNil)(row[item.id]);
1181
+ default:
1182
+ return true;
1183
+ }
1184
+ };
1185
+ break;
1186
+ case "date":
1187
+ if (!item.render)
1188
+ item.render = (value) => processValue(item, value);
1189
+ if (!item.onFilter)
1190
+ item.onFilter = (value, row) => (0, import_dayjs2.default)(row[item.id]).isSame((0, import_dayjs2.default)(value));
1191
+ if (!item.sorter)
1192
+ item.sorter = (a, b) => (0, import_dayjs2.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1193
+ break;
1194
+ case "time":
1195
+ if (!item.render)
1196
+ item.render = (value) => processValue(item, value);
1197
+ if (!item.onFilter)
1198
+ item.onFilter = (value, row) => (0, import_dayjs2.default)(row[item.id]).isSame((0, import_dayjs2.default)(value));
1199
+ if (!item.sorter)
1200
+ item.sorter = (a, b) => (0, import_dayjs2.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1201
+ break;
1202
+ case "object":
1203
+ if (!item.render)
1204
+ item.render = (value) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
1205
+ items: item.object,
1206
+ dataSource: value || {},
1207
+ column: 1
1208
+ });
1209
+ break;
1210
+ case "object[]":
1211
+ if (!item.render)
1212
+ item.render = (value) => value.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
1213
+ items: item.object,
1214
+ dataSource: v || [],
1215
+ column: 1
1216
+ }, i));
1217
+ break;
1218
+ default:
1219
+ if (!item.render)
1220
+ item.render = (value) => processValue(item, value);
1221
+ if (!item.onFilter)
1222
+ item.onFilter = (value, row) => value === row[item.id];
1223
+ break;
1224
+ }
1225
+ }
1226
+ setColumns(props.items);
1227
+ }, [props.items]);
1228
+ (0, import_react11.useEffect)(() => {
1229
+ if (!props.dataSource || !columns)
1230
+ return;
1231
+ for (const column of columns) {
1232
+ if (column.optionsType === "auto" && !column.options && !column.filters) {
1233
+ setColumns((prev) => {
1234
+ const newColumns = [...prev];
1235
+ const index = newColumns.findIndex((item) => item.id === column.id);
1236
+ newColumns[index].filters = (0, import_lodash_es6.uniqBy)(props.dataSource, column.id).map((v) => ({
1237
+ text: v[column.id],
1238
+ value: v[column.id]
1239
+ }));
1240
+ return newColumns;
1241
+ });
1242
+ }
1243
+ }
1244
+ }, [props.dataSource, columns]);
1245
+ if (!columns)
1246
+ return null;
1247
+ if (!props.faasData)
1248
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1249
+ ...props,
1250
+ rowKey: props.rowKey || "id",
1251
+ columns,
1252
+ dataSource: props.dataSource
1253
+ });
1254
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react12.FaasDataWrapper, {
1255
+ fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Skeleton, {
1256
+ active: true
1257
+ }),
1258
+ render: ({
1259
+ data,
1260
+ params,
1261
+ reload
1262
+ }) => {
1263
+ if (!data)
1264
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1265
+ ...props,
1266
+ rowKey: props.rowKey || "id",
1267
+ columns,
1268
+ dataSource: []
1269
+ });
1270
+ if (Array.isArray(data))
1271
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1272
+ ...props,
1273
+ rowKey: props.rowKey || "id",
1274
+ columns,
1275
+ dataSource: data
1276
+ });
1277
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1278
+ ...props,
1279
+ rowKey: props.rowKey || "id",
1280
+ columns,
1281
+ dataSource: data.rows,
1282
+ pagination: {
1283
+ ...props.pagination,
1284
+ ...data.pagination
1285
+ },
1286
+ onChange: (pagination, filters, sorter, extra) => {
1287
+ if (props.onChange) {
1288
+ const processed = props.onChange(pagination, filters, sorter, extra);
1289
+ reload({
1290
+ ...params,
1291
+ pagination: processed.pagination,
1292
+ filters: processed.filters,
1293
+ sorter: processed.sorter
1294
+ });
1295
+ return;
1296
+ }
1297
+ reload({
1298
+ ...params,
1299
+ pagination,
1300
+ filters,
1301
+ sorter
1302
+ });
1303
+ }
1304
+ });
1305
+ },
1306
+ ...props.faasData
1307
+ });
1308
+ }
1309
+
1310
+ // src/Title.tsx
1311
+ var import_react13 = require("react");
1312
+ var import_jsx_runtime = require("react/jsx-runtime");
1313
+ function Title(props) {
1314
+ const { Title: Title2 } = useConfigContext();
1315
+ (0, import_react13.useEffect)(() => {
1316
+ const title = Array.isArray(props.title) ? props.title : [props.title];
1317
+ document.title = title.concat(props.suffix || Title2.suffix).filter((t) => !!t).join(props.separator || Title2.separator);
1318
+ }, [props]);
1319
+ if (props.h1) {
1320
+ if (typeof props.h1 === "boolean")
1321
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
1322
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1323
+ });
1324
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
1325
+ className: props.h1.className,
1326
+ style: props.h1.style,
1327
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1328
+ });
1329
+ }
1330
+ if (props.plain)
1331
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
1332
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1333
+ });
1334
+ if (props.children)
1335
+ return (0, import_react13.cloneElement)(props.children, { title: props.title });
1336
+ return null;
1337
+ }
1338
+ // Annotate the CommonJS export names for ESM import in node:
1339
+ 0 && (module.exports = {
1340
+ Blank,
1341
+ ConfigContext,
1342
+ ConfigProvider,
1343
+ Description,
1344
+ Drawer,
1345
+ Form,
1346
+ FormItem,
1347
+ Link,
1348
+ Modal,
1349
+ PageNotFound,
1350
+ Routes,
1351
+ Table,
1352
+ Title,
1353
+ transferOptions,
1354
+ transferValue,
1355
+ useConfigContext,
1356
+ useDrawer,
1357
+ useModal
1358
+ });