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