@faasjs/ant-design 8.0.0-beta.3 → 8.0.0-beta.31

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