@faasjs/ant-design 8.0.0-beta.2 → 8.0.0-beta.21

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