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

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