@faasjs/ant-design 2.3.0 → 2.4.0
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.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +68 -136
- package/dist/index.mjs +68 -136
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -9,11 +9,12 @@ import * as antd_es_modal_PurePanel from 'antd/es/modal/PurePanel';
|
|
|
9
9
|
import * as antd_es_modal_useModal from 'antd/es/modal/useModal';
|
|
10
10
|
import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
|
|
11
11
|
import * as react from 'react';
|
|
12
|
-
import { CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
|
|
12
|
+
import { Dispatch, SetStateAction, CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
|
|
13
13
|
export { lazy } from 'react';
|
|
14
14
|
import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, DatePickerProps, FormInstance, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
|
|
15
15
|
import { BrowserRouterProps, RouteProps } from 'react-router-dom';
|
|
16
16
|
import { Dayjs } from 'dayjs';
|
|
17
|
+
import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
|
|
17
18
|
import { RuleObject } from 'rc-field-form/lib/interface';
|
|
18
19
|
import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface';
|
|
19
20
|
import * as antd_es_form_context from 'antd/es/form/context';
|
|
@@ -32,7 +33,7 @@ declare const Modal: react.FC<ModalProps$1> & antd_es_modal_confirm.ModalStaticF
|
|
|
32
33
|
interface ModalProps extends ModalProps$1 {
|
|
33
34
|
children?: JSX.Element | JSX.Element[] | string;
|
|
34
35
|
}
|
|
35
|
-
type setModalProps =
|
|
36
|
+
type setModalProps = Dispatch<SetStateAction<ModalProps>>;
|
|
36
37
|
/**
|
|
37
38
|
* Hook style modal
|
|
38
39
|
*
|
|
@@ -53,13 +54,13 @@ declare function useModal(init?: ModalProps): {
|
|
|
53
54
|
setModalProps: setModalProps;
|
|
54
55
|
};
|
|
55
56
|
|
|
56
|
-
declare const Drawer:
|
|
57
|
+
declare const Drawer: React.FC<DrawerProps> & {
|
|
57
58
|
whyDidYouRender?: boolean;
|
|
58
59
|
};
|
|
59
60
|
interface DrawerProps extends DrawerProps$1 {
|
|
60
61
|
children?: JSX.Element | JSX.Element[];
|
|
61
62
|
}
|
|
62
|
-
type setDrawerProps =
|
|
63
|
+
type setDrawerProps = Dispatch<SetStateAction<DrawerProps>>;
|
|
63
64
|
/**
|
|
64
65
|
* Hook style drawer
|
|
65
66
|
*
|
|
@@ -274,9 +275,9 @@ declare function FormItem<T = any>(props: FormItemProps<T>): react_jsx_runtime.J
|
|
|
274
275
|
declare namespace FormItem {
|
|
275
276
|
var whyDidYouRender: boolean;
|
|
276
277
|
var useStatus: () => {
|
|
277
|
-
status?:
|
|
278
|
-
errors:
|
|
279
|
-
warnings:
|
|
278
|
+
status?: antd_es_form_FormItem.ValidateStatus;
|
|
279
|
+
errors: React.ReactNode[];
|
|
280
|
+
warnings: React.ReactNode[];
|
|
280
281
|
};
|
|
281
282
|
}
|
|
282
283
|
|
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,12 @@ import * as antd_es_modal_PurePanel from 'antd/es/modal/PurePanel';
|
|
|
9
9
|
import * as antd_es_modal_useModal from 'antd/es/modal/useModal';
|
|
10
10
|
import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
|
|
11
11
|
import * as react from 'react';
|
|
12
|
-
import { CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
|
|
12
|
+
import { Dispatch, SetStateAction, CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
|
|
13
13
|
export { lazy } from 'react';
|
|
14
14
|
import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, DatePickerProps, FormInstance, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
|
|
15
15
|
import { BrowserRouterProps, RouteProps } from 'react-router-dom';
|
|
16
16
|
import { Dayjs } from 'dayjs';
|
|
17
|
+
import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
|
|
17
18
|
import { RuleObject } from 'rc-field-form/lib/interface';
|
|
18
19
|
import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface';
|
|
19
20
|
import * as antd_es_form_context from 'antd/es/form/context';
|
|
@@ -32,7 +33,7 @@ declare const Modal: react.FC<ModalProps$1> & antd_es_modal_confirm.ModalStaticF
|
|
|
32
33
|
interface ModalProps extends ModalProps$1 {
|
|
33
34
|
children?: JSX.Element | JSX.Element[] | string;
|
|
34
35
|
}
|
|
35
|
-
type setModalProps =
|
|
36
|
+
type setModalProps = Dispatch<SetStateAction<ModalProps>>;
|
|
36
37
|
/**
|
|
37
38
|
* Hook style modal
|
|
38
39
|
*
|
|
@@ -53,13 +54,13 @@ declare function useModal(init?: ModalProps): {
|
|
|
53
54
|
setModalProps: setModalProps;
|
|
54
55
|
};
|
|
55
56
|
|
|
56
|
-
declare const Drawer:
|
|
57
|
+
declare const Drawer: React.FC<DrawerProps> & {
|
|
57
58
|
whyDidYouRender?: boolean;
|
|
58
59
|
};
|
|
59
60
|
interface DrawerProps extends DrawerProps$1 {
|
|
60
61
|
children?: JSX.Element | JSX.Element[];
|
|
61
62
|
}
|
|
62
|
-
type setDrawerProps =
|
|
63
|
+
type setDrawerProps = Dispatch<SetStateAction<DrawerProps>>;
|
|
63
64
|
/**
|
|
64
65
|
* Hook style drawer
|
|
65
66
|
*
|
|
@@ -274,9 +275,9 @@ declare function FormItem<T = any>(props: FormItemProps<T>): react_jsx_runtime.J
|
|
|
274
275
|
declare namespace FormItem {
|
|
275
276
|
var whyDidYouRender: boolean;
|
|
276
277
|
var useStatus: () => {
|
|
277
|
-
status?:
|
|
278
|
-
errors:
|
|
279
|
-
warnings:
|
|
278
|
+
status?: antd_es_form_FormItem.ValidateStatus;
|
|
279
|
+
errors: React.ReactNode[];
|
|
280
|
+
warnings: React.ReactNode[];
|
|
280
281
|
};
|
|
281
282
|
}
|
|
282
283
|
|
package/dist/index.js
CHANGED
|
@@ -150,13 +150,10 @@ function ConfigProvider(props) {
|
|
|
150
150
|
baseTheme
|
|
151
151
|
)
|
|
152
152
|
);
|
|
153
|
-
} else
|
|
154
|
-
|
|
155
|
-
if (props.faasClientOptions)
|
|
156
|
-
react.FaasReactClient(props.faasClientOptions);
|
|
153
|
+
} else setTheme(lodashEs.defaultsDeep(props.theme, baseTheme));
|
|
154
|
+
if (props.faasClientOptions) react.FaasReactClient(props.faasClientOptions);
|
|
157
155
|
}, [JSON.stringify(props.theme)]);
|
|
158
|
-
if (!theme)
|
|
159
|
-
return null;
|
|
156
|
+
if (!theme) return null;
|
|
160
157
|
return /* @__PURE__ */ jsxRuntime.jsx(ConfigContext.Provider, { value: { theme }, children: props.children });
|
|
161
158
|
}
|
|
162
159
|
function useConfigContext() {
|
|
@@ -175,10 +172,8 @@ function RoutesApp(props) {
|
|
|
175
172
|
const { drawerProps, setDrawerProps, modalProps, setModalProps } = useApp();
|
|
176
173
|
react$1.useEffect(() => {
|
|
177
174
|
console.debug("location", location);
|
|
178
|
-
if (drawerProps.open)
|
|
179
|
-
|
|
180
|
-
if (modalProps.open)
|
|
181
|
-
setModalProps({ open: false });
|
|
175
|
+
if (drawerProps.open) setDrawerProps({ open: false });
|
|
176
|
+
if (modalProps.open) setModalProps({ open: false });
|
|
182
177
|
}, [location]);
|
|
183
178
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
|
|
184
179
|
}
|
|
@@ -225,8 +220,7 @@ function Blank(options) {
|
|
|
225
220
|
}
|
|
226
221
|
Blank.whyDidYouRender = true;
|
|
227
222
|
function transferOptions(options) {
|
|
228
|
-
if (!options)
|
|
229
|
-
return [];
|
|
223
|
+
if (!options) return [];
|
|
230
224
|
return options.map(
|
|
231
225
|
(item) => typeof item === "object" ? item : {
|
|
232
226
|
label: lodashEs.upperFirst(item.toString()),
|
|
@@ -235,43 +229,35 @@ function transferOptions(options) {
|
|
|
235
229
|
);
|
|
236
230
|
}
|
|
237
231
|
function transferValue(type, value) {
|
|
238
|
-
if (!type)
|
|
239
|
-
type = "string";
|
|
232
|
+
if (!type) type = "string";
|
|
240
233
|
if (!type.endsWith("[]") && (typeof value === "undefined" || value === null || value === "" || value === "null" || value === "undefined"))
|
|
241
234
|
return null;
|
|
242
235
|
if (type.endsWith("[]")) {
|
|
243
|
-
if (!value)
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
value = value.split(",").filter(Boolean);
|
|
247
|
-
if (!Array.isArray(value))
|
|
248
|
-
value = [value];
|
|
236
|
+
if (!value) value = [];
|
|
237
|
+
if (typeof value === "string") value = value.split(",").filter(Boolean);
|
|
238
|
+
if (!Array.isArray(value)) value = [value];
|
|
249
239
|
value = value.map(
|
|
250
240
|
(item) => transferValue(type.replace("[]", ""), item)
|
|
251
241
|
);
|
|
252
242
|
}
|
|
253
243
|
switch (type) {
|
|
254
244
|
case "boolean":
|
|
255
|
-
if (typeof value === "string")
|
|
256
|
-
value = value === "true";
|
|
245
|
+
if (typeof value === "string") value = value === "true";
|
|
257
246
|
break;
|
|
258
247
|
case "number":
|
|
259
|
-
if (typeof value === "string")
|
|
260
|
-
value = Number(value);
|
|
248
|
+
if (typeof value === "string") value = Number(value);
|
|
261
249
|
break;
|
|
262
250
|
case "date":
|
|
263
251
|
case "time":
|
|
264
252
|
if (typeof value === "number" && value.toString().length === 10)
|
|
265
253
|
value = value * 1e3;
|
|
266
|
-
if (!dayjs2__default.default.isDayjs(value))
|
|
267
|
-
value = dayjs2__default.default(value);
|
|
254
|
+
if (!dayjs2__default.default.isDayjs(value)) value = dayjs2__default.default(value);
|
|
268
255
|
break;
|
|
269
256
|
}
|
|
270
257
|
return value;
|
|
271
258
|
}
|
|
272
259
|
function Loading(props) {
|
|
273
|
-
if (props.loading === false)
|
|
274
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
|
|
260
|
+
if (props.loading === false) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
|
|
275
261
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
276
262
|
"div",
|
|
277
263
|
{
|
|
@@ -305,8 +291,7 @@ function DescriptionItemContent(props) {
|
|
|
305
291
|
const propsCopy = { ...props };
|
|
306
292
|
if (!propsCopy.item.title)
|
|
307
293
|
propsCopy.item.title = lodashEs.upperFirst(propsCopy.item.id);
|
|
308
|
-
if (!propsCopy.item.type)
|
|
309
|
-
propsCopy.item.type = "string";
|
|
294
|
+
if (!propsCopy.item.type) propsCopy.item.type = "string";
|
|
310
295
|
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
311
296
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
312
297
|
}
|
|
@@ -324,8 +309,7 @@ function DescriptionItemContent(props) {
|
|
|
324
309
|
}
|
|
325
310
|
setComputedProps(propsCopy);
|
|
326
311
|
}, [props]);
|
|
327
|
-
if (!computedProps)
|
|
328
|
-
return null;
|
|
312
|
+
if (!computedProps) return null;
|
|
329
313
|
if ((_a = computedProps.extendTypes) == null ? void 0 : _a[computedProps.item.type]) {
|
|
330
314
|
if (computedProps.extendTypes[computedProps.item.type].children)
|
|
331
315
|
return react$1.cloneElement(
|
|
@@ -345,16 +329,14 @@ function DescriptionItemContent(props) {
|
|
|
345
329
|
) });
|
|
346
330
|
throw Error(`${computedProps.item.type} requires children or render`);
|
|
347
331
|
}
|
|
348
|
-
if (computedProps.item.descriptionChildren === null)
|
|
349
|
-
return null;
|
|
332
|
+
if (computedProps.item.descriptionChildren === null) return null;
|
|
350
333
|
if (computedProps.item.descriptionChildren)
|
|
351
334
|
return react$1.cloneElement(computedProps.item.descriptionChildren, {
|
|
352
335
|
scene: "description",
|
|
353
336
|
value: computedProps.value,
|
|
354
337
|
values: computedProps.values
|
|
355
338
|
});
|
|
356
|
-
if (computedProps.item.children === null)
|
|
357
|
-
return null;
|
|
339
|
+
if (computedProps.item.children === null) return null;
|
|
358
340
|
if (computedProps.item.children)
|
|
359
341
|
return react$1.cloneElement(computedProps.item.children, {
|
|
360
342
|
scene: "description",
|
|
@@ -407,8 +389,7 @@ function DescriptionItemContent(props) {
|
|
|
407
389
|
case "date":
|
|
408
390
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.format("YYYY-MM-DD") });
|
|
409
391
|
case "object":
|
|
410
|
-
if (!computedProps.value)
|
|
411
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
|
|
392
|
+
if (!computedProps.value) return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
|
|
412
393
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
413
394
|
Description,
|
|
414
395
|
{
|
|
@@ -469,16 +450,12 @@ function Description(props) {
|
|
|
469
450
|
}
|
|
470
451
|
Description.whyDidYouRender = true;
|
|
471
452
|
function processProps(propsCopy, config) {
|
|
472
|
-
if (!propsCopy.title)
|
|
473
|
-
propsCopy.title = lodashEs.upperFirst(propsCopy.id);
|
|
453
|
+
if (!propsCopy.title) propsCopy.title = lodashEs.upperFirst(propsCopy.id);
|
|
474
454
|
if (!propsCopy.label && propsCopy.label !== false)
|
|
475
455
|
propsCopy.label = propsCopy.title;
|
|
476
|
-
if (!propsCopy.name)
|
|
477
|
-
|
|
478
|
-
if (!propsCopy.
|
|
479
|
-
propsCopy.type = "string";
|
|
480
|
-
if (!propsCopy.rules)
|
|
481
|
-
propsCopy.rules = [];
|
|
456
|
+
if (!propsCopy.name) propsCopy.name = propsCopy.id;
|
|
457
|
+
if (!propsCopy.type) propsCopy.type = "string";
|
|
458
|
+
if (!propsCopy.rules) propsCopy.rules = [];
|
|
482
459
|
if (propsCopy.required) {
|
|
483
460
|
if (propsCopy.type.endsWith("[]"))
|
|
484
461
|
propsCopy.rules.push({
|
|
@@ -496,8 +473,7 @@ function processProps(propsCopy, config) {
|
|
|
496
473
|
message: `${propsCopy.label || propsCopy.title} ${config.required}`
|
|
497
474
|
});
|
|
498
475
|
}
|
|
499
|
-
if (!propsCopy.input)
|
|
500
|
-
propsCopy.input = {};
|
|
476
|
+
if (!propsCopy.input) propsCopy.input = {};
|
|
501
477
|
if (propsCopy.options)
|
|
502
478
|
propsCopy.input.options = transferOptions(
|
|
503
479
|
propsCopy.options
|
|
@@ -507,8 +483,7 @@ function processProps(propsCopy, config) {
|
|
|
507
483
|
propsCopy.valuePropName = "checked";
|
|
508
484
|
break;
|
|
509
485
|
case "object":
|
|
510
|
-
if (!Array.isArray(propsCopy.name))
|
|
511
|
-
propsCopy.name = [propsCopy.name];
|
|
486
|
+
if (!Array.isArray(propsCopy.name)) propsCopy.name = [propsCopy.name];
|
|
512
487
|
for (const sub of propsCopy.object) {
|
|
513
488
|
if (!sub.name)
|
|
514
489
|
sub.name = propsCopy.name.concat(sub.id);
|
|
@@ -545,18 +520,15 @@ function FormItem(props) {
|
|
|
545
520
|
}
|
|
546
521
|
setComputedProps(processProps(propsCopy, theme.common));
|
|
547
522
|
}, [props]);
|
|
548
|
-
if (!computedProps)
|
|
549
|
-
return null;
|
|
523
|
+
if (!computedProps) return null;
|
|
550
524
|
if (hidden)
|
|
551
525
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, noStyle: true, rules: [], children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { hidden: true }) });
|
|
552
526
|
if (extendTypes == null ? void 0 : extendTypes[computedProps.type])
|
|
553
527
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: extendTypes[computedProps.type].children });
|
|
554
|
-
if (computedProps.formChildren === null)
|
|
555
|
-
return null;
|
|
528
|
+
if (computedProps.formChildren === null) return null;
|
|
556
529
|
if (computedProps.formChildren)
|
|
557
530
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: react$1.cloneElement(computedProps.formChildren, { scene: "form" }) });
|
|
558
|
-
if (computedProps.children === null)
|
|
559
|
-
return null;
|
|
531
|
+
if (computedProps.children === null) return null;
|
|
560
532
|
if (computedProps.children)
|
|
561
533
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: react$1.cloneElement(computedProps.children, { scene: "form" }) });
|
|
562
534
|
if (computedProps.formRender)
|
|
@@ -784,12 +756,10 @@ function Form(props) {
|
|
|
784
756
|
propsCopy.initialValues[key]
|
|
785
757
|
);
|
|
786
758
|
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
787
|
-
if (item == null ? void 0 : item.if)
|
|
788
|
-
item.hidden = !item.if(propsCopy.initialValues);
|
|
759
|
+
if (item == null ? void 0 : item.if) item.hidden = !item.if(propsCopy.initialValues);
|
|
789
760
|
}
|
|
790
761
|
for (const item of propsCopy.items) {
|
|
791
|
-
if (item.if)
|
|
792
|
-
item.hidden = !item.if(propsCopy.initialValues);
|
|
762
|
+
if (item.if) item.hidden = !item.if(propsCopy.initialValues);
|
|
793
763
|
}
|
|
794
764
|
setInitialValues(propsCopy.initialValues);
|
|
795
765
|
delete propsCopy.initialValues;
|
|
@@ -810,8 +780,7 @@ function Form(props) {
|
|
|
810
780
|
} : values2
|
|
811
781
|
)
|
|
812
782
|
);
|
|
813
|
-
} else
|
|
814
|
-
await props.onFinish(values);
|
|
783
|
+
} else await props.onFinish(values);
|
|
815
784
|
} catch (error) {
|
|
816
785
|
console.error(error);
|
|
817
786
|
}
|
|
@@ -853,8 +822,7 @@ function Form(props) {
|
|
|
853
822
|
if (props.onValuesChange) {
|
|
854
823
|
props.onValuesChange(changedValues, allValues);
|
|
855
824
|
}
|
|
856
|
-
if (!props.items)
|
|
857
|
-
return;
|
|
825
|
+
if (!props.items) return;
|
|
858
826
|
for (const key in changedValues) {
|
|
859
827
|
const item = computedProps.items.find((i) => i.id === key);
|
|
860
828
|
if (item == null ? void 0 : item.onValueChange)
|
|
@@ -864,14 +832,12 @@ function Form(props) {
|
|
|
864
832
|
[computedProps]
|
|
865
833
|
);
|
|
866
834
|
react$1.useEffect(() => {
|
|
867
|
-
if (!initialValues)
|
|
868
|
-
return;
|
|
835
|
+
if (!initialValues) return;
|
|
869
836
|
console.debug("Form:initialValues", initialValues);
|
|
870
837
|
form.setFieldsValue(initialValues);
|
|
871
838
|
setInitialValues(null);
|
|
872
839
|
}, [computedProps]);
|
|
873
|
-
if (!computedProps)
|
|
874
|
-
return null;
|
|
840
|
+
if (!computedProps) return null;
|
|
875
841
|
return /* @__PURE__ */ jsxRuntime.jsxs(antd.Form, { ...computedProps, onValuesChange, children: [
|
|
876
842
|
computedProps.beforeItems,
|
|
877
843
|
(_a = computedProps.items) == null ? void 0 : _a.map(
|
|
@@ -1037,8 +1003,7 @@ function processValue(item, value) {
|
|
|
1037
1003
|
if (["string", "number", "boolean"].includes(item.type))
|
|
1038
1004
|
return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
|
|
1039
1005
|
}
|
|
1040
|
-
if (item.type.endsWith("[]"))
|
|
1041
|
-
return transferred.join(", ");
|
|
1006
|
+
if (item.type.endsWith("[]")) return transferred.join(", ");
|
|
1042
1007
|
if (["date", "time"].includes(item.type))
|
|
1043
1008
|
return transferred.format(
|
|
1044
1009
|
item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss"
|
|
@@ -1049,8 +1014,7 @@ function Table(props) {
|
|
|
1049
1014
|
const [columns, setColumns] = react$1.useState();
|
|
1050
1015
|
const { theme } = useConfigContext();
|
|
1051
1016
|
const generateFilterDropdown = (item) => {
|
|
1052
|
-
if (item.filterDropdown && item.filterDropdown !== true)
|
|
1053
|
-
return;
|
|
1017
|
+
if (item.filterDropdown && item.filterDropdown !== true) return;
|
|
1054
1018
|
if (item.options.length < 11) {
|
|
1055
1019
|
if (!item.filters)
|
|
1056
1020
|
item.filters = item.options.map((o) => ({
|
|
@@ -1082,8 +1046,7 @@ function Table(props) {
|
|
|
1082
1046
|
},
|
|
1083
1047
|
mode: "multiple",
|
|
1084
1048
|
filterOption: (input, option) => {
|
|
1085
|
-
if (!input || !option || !option.label)
|
|
1086
|
-
return true;
|
|
1049
|
+
if (!input || !option || !option.label) return true;
|
|
1087
1050
|
input = input.trim();
|
|
1088
1051
|
return option.value === input || option.label.toString().toLowerCase().includes(input.toLowerCase());
|
|
1089
1052
|
}
|
|
@@ -1097,14 +1060,10 @@ function Table(props) {
|
|
|
1097
1060
|
var _a, _b, _c;
|
|
1098
1061
|
const items = lodashEs.cloneDeep(props.items);
|
|
1099
1062
|
for (const item of items) {
|
|
1100
|
-
if (!item.key)
|
|
1101
|
-
|
|
1102
|
-
if (!item.
|
|
1103
|
-
|
|
1104
|
-
if (!item.title)
|
|
1105
|
-
item.title = lodashEs.upperFirst(item.id);
|
|
1106
|
-
if (!item.type)
|
|
1107
|
-
item.type = "string";
|
|
1063
|
+
if (!item.key) item.key = item.id;
|
|
1064
|
+
if (!item.dataIndex) item.dataIndex = item.id;
|
|
1065
|
+
if (!item.title) item.title = lodashEs.upperFirst(item.id);
|
|
1066
|
+
if (!item.type) item.type = "string";
|
|
1108
1067
|
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
1109
1068
|
item.options = transferOptions(item.options);
|
|
1110
1069
|
item.filters = item.options.map((o) => ({
|
|
@@ -1116,16 +1075,14 @@ function Table(props) {
|
|
|
1116
1075
|
});
|
|
1117
1076
|
generateFilterDropdown(item);
|
|
1118
1077
|
}
|
|
1119
|
-
if (item.tableChildren === null)
|
|
1120
|
-
item.render = () => null;
|
|
1078
|
+
if (item.tableChildren === null) item.render = () => null;
|
|
1121
1079
|
else if (item.tableChildren)
|
|
1122
1080
|
item.render = (value, values) => react$1.cloneElement(item.tableChildren, {
|
|
1123
1081
|
scene: "table",
|
|
1124
1082
|
value,
|
|
1125
1083
|
values
|
|
1126
1084
|
});
|
|
1127
|
-
else if (item.children === null)
|
|
1128
|
-
item.render = () => null;
|
|
1085
|
+
else if (item.children === null) item.render = () => null;
|
|
1129
1086
|
else if (item.children)
|
|
1130
1087
|
item.render = (value, values) => react$1.cloneElement(item.children, {
|
|
1131
1088
|
scene: "table",
|
|
@@ -1141,21 +1098,17 @@ function Table(props) {
|
|
|
1141
1098
|
});
|
|
1142
1099
|
else if (props.extendTypes[item.type].render)
|
|
1143
1100
|
item.render = props.extendTypes[item.type].render;
|
|
1144
|
-
else
|
|
1145
|
-
throw Error(`${item.type} requires children or render`);
|
|
1101
|
+
else throw Error(`${item.type} requires children or render`);
|
|
1146
1102
|
continue;
|
|
1147
1103
|
}
|
|
1148
1104
|
switch (item.type) {
|
|
1149
1105
|
case "string":
|
|
1150
|
-
if (!item.render)
|
|
1151
|
-
item.render = (value) => processValue(item, value);
|
|
1106
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1152
1107
|
if (item.filterDropdown !== false) {
|
|
1153
1108
|
if (!item.onFilter && !props.faasData)
|
|
1154
1109
|
item.onFilter = (value, row) => {
|
|
1155
|
-
if (!value || lodashEs.isNil(value))
|
|
1156
|
-
|
|
1157
|
-
if (lodashEs.isNil(row[item.id]))
|
|
1158
|
-
return false;
|
|
1110
|
+
if (!value || lodashEs.isNil(value)) return true;
|
|
1111
|
+
if (lodashEs.isNil(row[item.id])) return false;
|
|
1159
1112
|
return row[item.id].trim().toLowerCase().includes(value.trim().toLowerCase());
|
|
1160
1113
|
};
|
|
1161
1114
|
if (typeof item.filterDropdown === "undefined" && !item.filters && item.optionsType !== "auto")
|
|
@@ -1182,8 +1135,7 @@ function Table(props) {
|
|
|
1182
1135
|
}
|
|
1183
1136
|
break;
|
|
1184
1137
|
case "string[]":
|
|
1185
|
-
if (!item.render)
|
|
1186
|
-
item.render = (value) => processValue(item, value);
|
|
1138
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1187
1139
|
if (item.filterDropdown !== false) {
|
|
1188
1140
|
if (!item.onFilter && !props.faasData)
|
|
1189
1141
|
item.onFilter = (value, row) => {
|
|
@@ -1219,17 +1171,14 @@ function Table(props) {
|
|
|
1219
1171
|
}
|
|
1220
1172
|
break;
|
|
1221
1173
|
case "number":
|
|
1222
|
-
if (!item.render)
|
|
1223
|
-
item.render = (value) => processValue(item, value);
|
|
1174
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1224
1175
|
if (typeof item.sorter === "undefined")
|
|
1225
1176
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
1226
1177
|
if (item.filterDropdown !== false) {
|
|
1227
1178
|
if (!item.onFilter && !props.faasData)
|
|
1228
1179
|
item.onFilter = (value, row) => {
|
|
1229
|
-
if (value === null)
|
|
1230
|
-
|
|
1231
|
-
if (lodashEs.isNil(row[item.id]))
|
|
1232
|
-
return false;
|
|
1180
|
+
if (value === null) return true;
|
|
1181
|
+
if (lodashEs.isNil(row[item.id])) return false;
|
|
1233
1182
|
return value == row[item.id];
|
|
1234
1183
|
};
|
|
1235
1184
|
if (typeof item.filterDropdown === "undefined" && !item.filters)
|
|
@@ -1263,8 +1212,7 @@ function Table(props) {
|
|
|
1263
1212
|
item.onFilter = (value, row) => {
|
|
1264
1213
|
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1265
1214
|
return true;
|
|
1266
|
-
if (!row[item.id] || !row[item.id].length)
|
|
1267
|
-
return false;
|
|
1215
|
+
if (!row[item.id] || !row[item.id].length) return false;
|
|
1268
1216
|
return row[item.id].includes(Number(value));
|
|
1269
1217
|
};
|
|
1270
1218
|
if (typeof item.filterDropdown === "undefined" && !item.filters)
|
|
@@ -1370,14 +1318,11 @@ function Table(props) {
|
|
|
1370
1318
|
}
|
|
1371
1319
|
break;
|
|
1372
1320
|
case "date":
|
|
1373
|
-
if (!item.render)
|
|
1374
|
-
item.render = (value) => processValue(item, value);
|
|
1321
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1375
1322
|
if (typeof item.sorter === "undefined")
|
|
1376
1323
|
item.sorter = (a, b, order) => {
|
|
1377
|
-
if (lodashEs.isNil(a[item.id]))
|
|
1378
|
-
|
|
1379
|
-
if (lodashEs.isNil(b[item.id]))
|
|
1380
|
-
return order === "ascend" ? -1 : 1;
|
|
1324
|
+
if (lodashEs.isNil(a[item.id])) return order === "ascend" ? 1 : -1;
|
|
1325
|
+
if (lodashEs.isNil(b[item.id])) return order === "ascend" ? -1 : 1;
|
|
1381
1326
|
return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
|
|
1382
1327
|
};
|
|
1383
1328
|
if (item.filterDropdown !== false) {
|
|
@@ -1400,24 +1345,19 @@ function Table(props) {
|
|
|
1400
1345
|
);
|
|
1401
1346
|
if (!item.onFilter && !props.faasData)
|
|
1402
1347
|
item.onFilter = (value, row) => {
|
|
1403
|
-
if (lodashEs.isNil(value[0]))
|
|
1404
|
-
|
|
1405
|
-
if (lodashEs.isNil(row[item.id]))
|
|
1406
|
-
return false;
|
|
1348
|
+
if (lodashEs.isNil(value[0])) return true;
|
|
1349
|
+
if (lodashEs.isNil(row[item.id])) return false;
|
|
1407
1350
|
return dayjs2__default.default(row[item.id]) >= dayjs2__default.default(value[0]) && dayjs2__default.default(row[item.id]) <= dayjs2__default.default(value[1]);
|
|
1408
1351
|
};
|
|
1409
1352
|
}
|
|
1410
1353
|
break;
|
|
1411
1354
|
case "time":
|
|
1412
1355
|
item.width = (_c = item.width) != null ? _c : 200;
|
|
1413
|
-
if (!item.render)
|
|
1414
|
-
item.render = (value) => processValue(item, value);
|
|
1356
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1415
1357
|
if (typeof item.sorter === "undefined")
|
|
1416
1358
|
item.sorter = (a, b, order) => {
|
|
1417
|
-
if (lodashEs.isNil(a[item.id]))
|
|
1418
|
-
|
|
1419
|
-
if (lodashEs.isNil(b[item.id]))
|
|
1420
|
-
return order === "ascend" ? -1 : 1;
|
|
1359
|
+
if (lodashEs.isNil(a[item.id])) return order === "ascend" ? 1 : -1;
|
|
1360
|
+
if (lodashEs.isNil(b[item.id])) return order === "ascend" ? -1 : 1;
|
|
1421
1361
|
return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
|
|
1422
1362
|
};
|
|
1423
1363
|
if (item.filterDropdown !== false) {
|
|
@@ -1440,10 +1380,8 @@ function Table(props) {
|
|
|
1440
1380
|
);
|
|
1441
1381
|
if (!item.onFilter && !props.faasData)
|
|
1442
1382
|
item.onFilter = (value, row) => {
|
|
1443
|
-
if (lodashEs.isNil(value[0]))
|
|
1444
|
-
|
|
1445
|
-
if (lodashEs.isNil(row[item.id]))
|
|
1446
|
-
return false;
|
|
1383
|
+
if (lodashEs.isNil(value[0])) return true;
|
|
1384
|
+
if (lodashEs.isNil(row[item.id])) return false;
|
|
1447
1385
|
return dayjs2__default.default(row[item.id]) >= dayjs2__default.default(value[0]) && dayjs2__default.default(row[item.id]) <= dayjs2__default.default(value[1]);
|
|
1448
1386
|
};
|
|
1449
1387
|
}
|
|
@@ -1472,12 +1410,10 @@ function Table(props) {
|
|
|
1472
1410
|
)) });
|
|
1473
1411
|
break;
|
|
1474
1412
|
default:
|
|
1475
|
-
if (!item.render)
|
|
1476
|
-
item.render = (value) => processValue(item, value);
|
|
1413
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1477
1414
|
if (item.filterDropdown !== false && !item.onFilter && !props.faasData)
|
|
1478
1415
|
item.onFilter = (value, row) => {
|
|
1479
|
-
if (value === null && lodashEs.isNil(row[item.id]))
|
|
1480
|
-
return true;
|
|
1416
|
+
if (value === null && lodashEs.isNil(row[item.id])) return true;
|
|
1481
1417
|
return value === row[item.id];
|
|
1482
1418
|
};
|
|
1483
1419
|
break;
|
|
@@ -1486,8 +1422,7 @@ function Table(props) {
|
|
|
1486
1422
|
setColumns(items);
|
|
1487
1423
|
}, [props.items]);
|
|
1488
1424
|
react$1.useEffect(() => {
|
|
1489
|
-
if (!props.dataSource || !columns)
|
|
1490
|
-
return;
|
|
1425
|
+
if (!props.dataSource || !columns) return;
|
|
1491
1426
|
for (const column of columns) {
|
|
1492
1427
|
if (column.optionsType === "auto" && !column.options && !column.filters) {
|
|
1493
1428
|
const options = lodashEs.uniqBy(props.dataSource, column.id).map((v) => ({
|
|
@@ -1505,8 +1440,7 @@ function Table(props) {
|
|
|
1505
1440
|
}
|
|
1506
1441
|
}
|
|
1507
1442
|
}, [props.dataSource, columns]);
|
|
1508
|
-
if (!columns)
|
|
1509
|
-
return null;
|
|
1443
|
+
if (!columns) return null;
|
|
1510
1444
|
if (props.dataSource)
|
|
1511
1445
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1512
1446
|
antd.Table,
|
|
@@ -1529,8 +1463,7 @@ function FaasDataTable({
|
|
|
1529
1463
|
}) {
|
|
1530
1464
|
const [currentColumns, setCurrentColumns] = react$1.useState(columns);
|
|
1531
1465
|
react$1.useEffect(() => {
|
|
1532
|
-
if (!data || Array.isArray(data))
|
|
1533
|
-
return;
|
|
1466
|
+
if (!data || Array.isArray(data)) return;
|
|
1534
1467
|
setCurrentColumns((prev) => {
|
|
1535
1468
|
var _a;
|
|
1536
1469
|
const newColumns = [...prev];
|
|
@@ -1545,8 +1478,7 @@ function FaasDataTable({
|
|
|
1545
1478
|
value: null
|
|
1546
1479
|
});
|
|
1547
1480
|
column.render = (value) => processValue(column, value);
|
|
1548
|
-
if (column.filterDropdown)
|
|
1549
|
-
delete column.filterDropdown;
|
|
1481
|
+
if (column.filterDropdown) delete column.filterDropdown;
|
|
1550
1482
|
continue;
|
|
1551
1483
|
}
|
|
1552
1484
|
if (column.optionsType === "auto" && !column.options && !column.filters) {
|
package/dist/index.mjs
CHANGED
|
@@ -146,13 +146,10 @@ function ConfigProvider(props) {
|
|
|
146
146
|
baseTheme
|
|
147
147
|
)
|
|
148
148
|
);
|
|
149
|
-
} else
|
|
150
|
-
|
|
151
|
-
if (props.faasClientOptions)
|
|
152
|
-
FaasReactClient(props.faasClientOptions);
|
|
149
|
+
} else setTheme(defaultsDeep(props.theme, baseTheme));
|
|
150
|
+
if (props.faasClientOptions) FaasReactClient(props.faasClientOptions);
|
|
153
151
|
}, [JSON.stringify(props.theme)]);
|
|
154
|
-
if (!theme)
|
|
155
|
-
return null;
|
|
152
|
+
if (!theme) return null;
|
|
156
153
|
return /* @__PURE__ */ jsx(ConfigContext.Provider, { value: { theme }, children: props.children });
|
|
157
154
|
}
|
|
158
155
|
function useConfigContext() {
|
|
@@ -171,10 +168,8 @@ function RoutesApp(props) {
|
|
|
171
168
|
const { drawerProps, setDrawerProps, modalProps, setModalProps } = useApp();
|
|
172
169
|
useEffect(() => {
|
|
173
170
|
console.debug("location", location);
|
|
174
|
-
if (drawerProps.open)
|
|
175
|
-
|
|
176
|
-
if (modalProps.open)
|
|
177
|
-
setModalProps({ open: false });
|
|
171
|
+
if (drawerProps.open) setDrawerProps({ open: false });
|
|
172
|
+
if (modalProps.open) setModalProps({ open: false });
|
|
178
173
|
}, [location]);
|
|
179
174
|
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
180
175
|
}
|
|
@@ -221,8 +216,7 @@ function Blank(options) {
|
|
|
221
216
|
}
|
|
222
217
|
Blank.whyDidYouRender = true;
|
|
223
218
|
function transferOptions(options) {
|
|
224
|
-
if (!options)
|
|
225
|
-
return [];
|
|
219
|
+
if (!options) return [];
|
|
226
220
|
return options.map(
|
|
227
221
|
(item) => typeof item === "object" ? item : {
|
|
228
222
|
label: upperFirst(item.toString()),
|
|
@@ -231,43 +225,35 @@ function transferOptions(options) {
|
|
|
231
225
|
);
|
|
232
226
|
}
|
|
233
227
|
function transferValue(type, value) {
|
|
234
|
-
if (!type)
|
|
235
|
-
type = "string";
|
|
228
|
+
if (!type) type = "string";
|
|
236
229
|
if (!type.endsWith("[]") && (typeof value === "undefined" || value === null || value === "" || value === "null" || value === "undefined"))
|
|
237
230
|
return null;
|
|
238
231
|
if (type.endsWith("[]")) {
|
|
239
|
-
if (!value)
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
value = value.split(",").filter(Boolean);
|
|
243
|
-
if (!Array.isArray(value))
|
|
244
|
-
value = [value];
|
|
232
|
+
if (!value) value = [];
|
|
233
|
+
if (typeof value === "string") value = value.split(",").filter(Boolean);
|
|
234
|
+
if (!Array.isArray(value)) value = [value];
|
|
245
235
|
value = value.map(
|
|
246
236
|
(item) => transferValue(type.replace("[]", ""), item)
|
|
247
237
|
);
|
|
248
238
|
}
|
|
249
239
|
switch (type) {
|
|
250
240
|
case "boolean":
|
|
251
|
-
if (typeof value === "string")
|
|
252
|
-
value = value === "true";
|
|
241
|
+
if (typeof value === "string") value = value === "true";
|
|
253
242
|
break;
|
|
254
243
|
case "number":
|
|
255
|
-
if (typeof value === "string")
|
|
256
|
-
value = Number(value);
|
|
244
|
+
if (typeof value === "string") value = Number(value);
|
|
257
245
|
break;
|
|
258
246
|
case "date":
|
|
259
247
|
case "time":
|
|
260
248
|
if (typeof value === "number" && value.toString().length === 10)
|
|
261
249
|
value = value * 1e3;
|
|
262
|
-
if (!dayjs2.isDayjs(value))
|
|
263
|
-
value = dayjs2(value);
|
|
250
|
+
if (!dayjs2.isDayjs(value)) value = dayjs2(value);
|
|
264
251
|
break;
|
|
265
252
|
}
|
|
266
253
|
return value;
|
|
267
254
|
}
|
|
268
255
|
function Loading(props) {
|
|
269
|
-
if (props.loading === false)
|
|
270
|
-
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
256
|
+
if (props.loading === false) return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
271
257
|
return /* @__PURE__ */ jsx(
|
|
272
258
|
"div",
|
|
273
259
|
{
|
|
@@ -301,8 +287,7 @@ function DescriptionItemContent(props) {
|
|
|
301
287
|
const propsCopy = { ...props };
|
|
302
288
|
if (!propsCopy.item.title)
|
|
303
289
|
propsCopy.item.title = upperFirst(propsCopy.item.id);
|
|
304
|
-
if (!propsCopy.item.type)
|
|
305
|
-
propsCopy.item.type = "string";
|
|
290
|
+
if (!propsCopy.item.type) propsCopy.item.type = "string";
|
|
306
291
|
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
307
292
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
308
293
|
}
|
|
@@ -320,8 +305,7 @@ function DescriptionItemContent(props) {
|
|
|
320
305
|
}
|
|
321
306
|
setComputedProps(propsCopy);
|
|
322
307
|
}, [props]);
|
|
323
|
-
if (!computedProps)
|
|
324
|
-
return null;
|
|
308
|
+
if (!computedProps) return null;
|
|
325
309
|
if ((_a = computedProps.extendTypes) == null ? void 0 : _a[computedProps.item.type]) {
|
|
326
310
|
if (computedProps.extendTypes[computedProps.item.type].children)
|
|
327
311
|
return cloneElement(
|
|
@@ -341,16 +325,14 @@ function DescriptionItemContent(props) {
|
|
|
341
325
|
) });
|
|
342
326
|
throw Error(`${computedProps.item.type} requires children or render`);
|
|
343
327
|
}
|
|
344
|
-
if (computedProps.item.descriptionChildren === null)
|
|
345
|
-
return null;
|
|
328
|
+
if (computedProps.item.descriptionChildren === null) return null;
|
|
346
329
|
if (computedProps.item.descriptionChildren)
|
|
347
330
|
return cloneElement(computedProps.item.descriptionChildren, {
|
|
348
331
|
scene: "description",
|
|
349
332
|
value: computedProps.value,
|
|
350
333
|
values: computedProps.values
|
|
351
334
|
});
|
|
352
|
-
if (computedProps.item.children === null)
|
|
353
|
-
return null;
|
|
335
|
+
if (computedProps.item.children === null) return null;
|
|
354
336
|
if (computedProps.item.children)
|
|
355
337
|
return cloneElement(computedProps.item.children, {
|
|
356
338
|
scene: "description",
|
|
@@ -403,8 +385,7 @@ function DescriptionItemContent(props) {
|
|
|
403
385
|
case "date":
|
|
404
386
|
return /* @__PURE__ */ jsx(Fragment, { children: computedProps.value.format("YYYY-MM-DD") });
|
|
405
387
|
case "object":
|
|
406
|
-
if (!computedProps.value)
|
|
407
|
-
return /* @__PURE__ */ jsx(Blank, {});
|
|
388
|
+
if (!computedProps.value) return /* @__PURE__ */ jsx(Blank, {});
|
|
408
389
|
return /* @__PURE__ */ jsx(
|
|
409
390
|
Description,
|
|
410
391
|
{
|
|
@@ -465,16 +446,12 @@ function Description(props) {
|
|
|
465
446
|
}
|
|
466
447
|
Description.whyDidYouRender = true;
|
|
467
448
|
function processProps(propsCopy, config) {
|
|
468
|
-
if (!propsCopy.title)
|
|
469
|
-
propsCopy.title = upperFirst(propsCopy.id);
|
|
449
|
+
if (!propsCopy.title) propsCopy.title = upperFirst(propsCopy.id);
|
|
470
450
|
if (!propsCopy.label && propsCopy.label !== false)
|
|
471
451
|
propsCopy.label = propsCopy.title;
|
|
472
|
-
if (!propsCopy.name)
|
|
473
|
-
|
|
474
|
-
if (!propsCopy.
|
|
475
|
-
propsCopy.type = "string";
|
|
476
|
-
if (!propsCopy.rules)
|
|
477
|
-
propsCopy.rules = [];
|
|
452
|
+
if (!propsCopy.name) propsCopy.name = propsCopy.id;
|
|
453
|
+
if (!propsCopy.type) propsCopy.type = "string";
|
|
454
|
+
if (!propsCopy.rules) propsCopy.rules = [];
|
|
478
455
|
if (propsCopy.required) {
|
|
479
456
|
if (propsCopy.type.endsWith("[]"))
|
|
480
457
|
propsCopy.rules.push({
|
|
@@ -492,8 +469,7 @@ function processProps(propsCopy, config) {
|
|
|
492
469
|
message: `${propsCopy.label || propsCopy.title} ${config.required}`
|
|
493
470
|
});
|
|
494
471
|
}
|
|
495
|
-
if (!propsCopy.input)
|
|
496
|
-
propsCopy.input = {};
|
|
472
|
+
if (!propsCopy.input) propsCopy.input = {};
|
|
497
473
|
if (propsCopy.options)
|
|
498
474
|
propsCopy.input.options = transferOptions(
|
|
499
475
|
propsCopy.options
|
|
@@ -503,8 +479,7 @@ function processProps(propsCopy, config) {
|
|
|
503
479
|
propsCopy.valuePropName = "checked";
|
|
504
480
|
break;
|
|
505
481
|
case "object":
|
|
506
|
-
if (!Array.isArray(propsCopy.name))
|
|
507
|
-
propsCopy.name = [propsCopy.name];
|
|
482
|
+
if (!Array.isArray(propsCopy.name)) propsCopy.name = [propsCopy.name];
|
|
508
483
|
for (const sub of propsCopy.object) {
|
|
509
484
|
if (!sub.name)
|
|
510
485
|
sub.name = propsCopy.name.concat(sub.id);
|
|
@@ -541,18 +516,15 @@ function FormItem(props) {
|
|
|
541
516
|
}
|
|
542
517
|
setComputedProps(processProps(propsCopy, theme.common));
|
|
543
518
|
}, [props]);
|
|
544
|
-
if (!computedProps)
|
|
545
|
-
return null;
|
|
519
|
+
if (!computedProps) return null;
|
|
546
520
|
if (hidden)
|
|
547
521
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, noStyle: true, rules: [], children: /* @__PURE__ */ jsx(Input, { hidden: true }) });
|
|
548
522
|
if (extendTypes == null ? void 0 : extendTypes[computedProps.type])
|
|
549
523
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: extendTypes[computedProps.type].children });
|
|
550
|
-
if (computedProps.formChildren === null)
|
|
551
|
-
return null;
|
|
524
|
+
if (computedProps.formChildren === null) return null;
|
|
552
525
|
if (computedProps.formChildren)
|
|
553
526
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneElement(computedProps.formChildren, { scene: "form" }) });
|
|
554
|
-
if (computedProps.children === null)
|
|
555
|
-
return null;
|
|
527
|
+
if (computedProps.children === null) return null;
|
|
556
528
|
if (computedProps.children)
|
|
557
529
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneElement(computedProps.children, { scene: "form" }) });
|
|
558
530
|
if (computedProps.formRender)
|
|
@@ -780,12 +752,10 @@ function Form(props) {
|
|
|
780
752
|
propsCopy.initialValues[key]
|
|
781
753
|
);
|
|
782
754
|
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
783
|
-
if (item == null ? void 0 : item.if)
|
|
784
|
-
item.hidden = !item.if(propsCopy.initialValues);
|
|
755
|
+
if (item == null ? void 0 : item.if) item.hidden = !item.if(propsCopy.initialValues);
|
|
785
756
|
}
|
|
786
757
|
for (const item of propsCopy.items) {
|
|
787
|
-
if (item.if)
|
|
788
|
-
item.hidden = !item.if(propsCopy.initialValues);
|
|
758
|
+
if (item.if) item.hidden = !item.if(propsCopy.initialValues);
|
|
789
759
|
}
|
|
790
760
|
setInitialValues(propsCopy.initialValues);
|
|
791
761
|
delete propsCopy.initialValues;
|
|
@@ -806,8 +776,7 @@ function Form(props) {
|
|
|
806
776
|
} : values2
|
|
807
777
|
)
|
|
808
778
|
);
|
|
809
|
-
} else
|
|
810
|
-
await props.onFinish(values);
|
|
779
|
+
} else await props.onFinish(values);
|
|
811
780
|
} catch (error) {
|
|
812
781
|
console.error(error);
|
|
813
782
|
}
|
|
@@ -849,8 +818,7 @@ function Form(props) {
|
|
|
849
818
|
if (props.onValuesChange) {
|
|
850
819
|
props.onValuesChange(changedValues, allValues);
|
|
851
820
|
}
|
|
852
|
-
if (!props.items)
|
|
853
|
-
return;
|
|
821
|
+
if (!props.items) return;
|
|
854
822
|
for (const key in changedValues) {
|
|
855
823
|
const item = computedProps.items.find((i) => i.id === key);
|
|
856
824
|
if (item == null ? void 0 : item.onValueChange)
|
|
@@ -860,14 +828,12 @@ function Form(props) {
|
|
|
860
828
|
[computedProps]
|
|
861
829
|
);
|
|
862
830
|
useEffect(() => {
|
|
863
|
-
if (!initialValues)
|
|
864
|
-
return;
|
|
831
|
+
if (!initialValues) return;
|
|
865
832
|
console.debug("Form:initialValues", initialValues);
|
|
866
833
|
form.setFieldsValue(initialValues);
|
|
867
834
|
setInitialValues(null);
|
|
868
835
|
}, [computedProps]);
|
|
869
|
-
if (!computedProps)
|
|
870
|
-
return null;
|
|
836
|
+
if (!computedProps) return null;
|
|
871
837
|
return /* @__PURE__ */ jsxs(Form$1, { ...computedProps, onValuesChange, children: [
|
|
872
838
|
computedProps.beforeItems,
|
|
873
839
|
(_a = computedProps.items) == null ? void 0 : _a.map(
|
|
@@ -1033,8 +999,7 @@ function processValue(item, value) {
|
|
|
1033
999
|
if (["string", "number", "boolean"].includes(item.type))
|
|
1034
1000
|
return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
|
|
1035
1001
|
}
|
|
1036
|
-
if (item.type.endsWith("[]"))
|
|
1037
|
-
return transferred.join(", ");
|
|
1002
|
+
if (item.type.endsWith("[]")) return transferred.join(", ");
|
|
1038
1003
|
if (["date", "time"].includes(item.type))
|
|
1039
1004
|
return transferred.format(
|
|
1040
1005
|
item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss"
|
|
@@ -1045,8 +1010,7 @@ function Table(props) {
|
|
|
1045
1010
|
const [columns, setColumns] = useState();
|
|
1046
1011
|
const { theme } = useConfigContext();
|
|
1047
1012
|
const generateFilterDropdown = (item) => {
|
|
1048
|
-
if (item.filterDropdown && item.filterDropdown !== true)
|
|
1049
|
-
return;
|
|
1013
|
+
if (item.filterDropdown && item.filterDropdown !== true) return;
|
|
1050
1014
|
if (item.options.length < 11) {
|
|
1051
1015
|
if (!item.filters)
|
|
1052
1016
|
item.filters = item.options.map((o) => ({
|
|
@@ -1078,8 +1042,7 @@ function Table(props) {
|
|
|
1078
1042
|
},
|
|
1079
1043
|
mode: "multiple",
|
|
1080
1044
|
filterOption: (input, option) => {
|
|
1081
|
-
if (!input || !option || !option.label)
|
|
1082
|
-
return true;
|
|
1045
|
+
if (!input || !option || !option.label) return true;
|
|
1083
1046
|
input = input.trim();
|
|
1084
1047
|
return option.value === input || option.label.toString().toLowerCase().includes(input.toLowerCase());
|
|
1085
1048
|
}
|
|
@@ -1093,14 +1056,10 @@ function Table(props) {
|
|
|
1093
1056
|
var _a, _b, _c;
|
|
1094
1057
|
const items = cloneDeep(props.items);
|
|
1095
1058
|
for (const item of items) {
|
|
1096
|
-
if (!item.key)
|
|
1097
|
-
|
|
1098
|
-
if (!item.
|
|
1099
|
-
|
|
1100
|
-
if (!item.title)
|
|
1101
|
-
item.title = upperFirst(item.id);
|
|
1102
|
-
if (!item.type)
|
|
1103
|
-
item.type = "string";
|
|
1059
|
+
if (!item.key) item.key = item.id;
|
|
1060
|
+
if (!item.dataIndex) item.dataIndex = item.id;
|
|
1061
|
+
if (!item.title) item.title = upperFirst(item.id);
|
|
1062
|
+
if (!item.type) item.type = "string";
|
|
1104
1063
|
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
1105
1064
|
item.options = transferOptions(item.options);
|
|
1106
1065
|
item.filters = item.options.map((o) => ({
|
|
@@ -1112,16 +1071,14 @@ function Table(props) {
|
|
|
1112
1071
|
});
|
|
1113
1072
|
generateFilterDropdown(item);
|
|
1114
1073
|
}
|
|
1115
|
-
if (item.tableChildren === null)
|
|
1116
|
-
item.render = () => null;
|
|
1074
|
+
if (item.tableChildren === null) item.render = () => null;
|
|
1117
1075
|
else if (item.tableChildren)
|
|
1118
1076
|
item.render = (value, values) => cloneElement(item.tableChildren, {
|
|
1119
1077
|
scene: "table",
|
|
1120
1078
|
value,
|
|
1121
1079
|
values
|
|
1122
1080
|
});
|
|
1123
|
-
else if (item.children === null)
|
|
1124
|
-
item.render = () => null;
|
|
1081
|
+
else if (item.children === null) item.render = () => null;
|
|
1125
1082
|
else if (item.children)
|
|
1126
1083
|
item.render = (value, values) => cloneElement(item.children, {
|
|
1127
1084
|
scene: "table",
|
|
@@ -1137,21 +1094,17 @@ function Table(props) {
|
|
|
1137
1094
|
});
|
|
1138
1095
|
else if (props.extendTypes[item.type].render)
|
|
1139
1096
|
item.render = props.extendTypes[item.type].render;
|
|
1140
|
-
else
|
|
1141
|
-
throw Error(`${item.type} requires children or render`);
|
|
1097
|
+
else throw Error(`${item.type} requires children or render`);
|
|
1142
1098
|
continue;
|
|
1143
1099
|
}
|
|
1144
1100
|
switch (item.type) {
|
|
1145
1101
|
case "string":
|
|
1146
|
-
if (!item.render)
|
|
1147
|
-
item.render = (value) => processValue(item, value);
|
|
1102
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1148
1103
|
if (item.filterDropdown !== false) {
|
|
1149
1104
|
if (!item.onFilter && !props.faasData)
|
|
1150
1105
|
item.onFilter = (value, row) => {
|
|
1151
|
-
if (!value || isNil(value))
|
|
1152
|
-
|
|
1153
|
-
if (isNil(row[item.id]))
|
|
1154
|
-
return false;
|
|
1106
|
+
if (!value || isNil(value)) return true;
|
|
1107
|
+
if (isNil(row[item.id])) return false;
|
|
1155
1108
|
return row[item.id].trim().toLowerCase().includes(value.trim().toLowerCase());
|
|
1156
1109
|
};
|
|
1157
1110
|
if (typeof item.filterDropdown === "undefined" && !item.filters && item.optionsType !== "auto")
|
|
@@ -1178,8 +1131,7 @@ function Table(props) {
|
|
|
1178
1131
|
}
|
|
1179
1132
|
break;
|
|
1180
1133
|
case "string[]":
|
|
1181
|
-
if (!item.render)
|
|
1182
|
-
item.render = (value) => processValue(item, value);
|
|
1134
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1183
1135
|
if (item.filterDropdown !== false) {
|
|
1184
1136
|
if (!item.onFilter && !props.faasData)
|
|
1185
1137
|
item.onFilter = (value, row) => {
|
|
@@ -1215,17 +1167,14 @@ function Table(props) {
|
|
|
1215
1167
|
}
|
|
1216
1168
|
break;
|
|
1217
1169
|
case "number":
|
|
1218
|
-
if (!item.render)
|
|
1219
|
-
item.render = (value) => processValue(item, value);
|
|
1170
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1220
1171
|
if (typeof item.sorter === "undefined")
|
|
1221
1172
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
1222
1173
|
if (item.filterDropdown !== false) {
|
|
1223
1174
|
if (!item.onFilter && !props.faasData)
|
|
1224
1175
|
item.onFilter = (value, row) => {
|
|
1225
|
-
if (value === null)
|
|
1226
|
-
|
|
1227
|
-
if (isNil(row[item.id]))
|
|
1228
|
-
return false;
|
|
1176
|
+
if (value === null) return true;
|
|
1177
|
+
if (isNil(row[item.id])) return false;
|
|
1229
1178
|
return value == row[item.id];
|
|
1230
1179
|
};
|
|
1231
1180
|
if (typeof item.filterDropdown === "undefined" && !item.filters)
|
|
@@ -1259,8 +1208,7 @@ function Table(props) {
|
|
|
1259
1208
|
item.onFilter = (value, row) => {
|
|
1260
1209
|
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1261
1210
|
return true;
|
|
1262
|
-
if (!row[item.id] || !row[item.id].length)
|
|
1263
|
-
return false;
|
|
1211
|
+
if (!row[item.id] || !row[item.id].length) return false;
|
|
1264
1212
|
return row[item.id].includes(Number(value));
|
|
1265
1213
|
};
|
|
1266
1214
|
if (typeof item.filterDropdown === "undefined" && !item.filters)
|
|
@@ -1366,14 +1314,11 @@ function Table(props) {
|
|
|
1366
1314
|
}
|
|
1367
1315
|
break;
|
|
1368
1316
|
case "date":
|
|
1369
|
-
if (!item.render)
|
|
1370
|
-
item.render = (value) => processValue(item, value);
|
|
1317
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1371
1318
|
if (typeof item.sorter === "undefined")
|
|
1372
1319
|
item.sorter = (a, b, order) => {
|
|
1373
|
-
if (isNil(a[item.id]))
|
|
1374
|
-
|
|
1375
|
-
if (isNil(b[item.id]))
|
|
1376
|
-
return order === "ascend" ? -1 : 1;
|
|
1320
|
+
if (isNil(a[item.id])) return order === "ascend" ? 1 : -1;
|
|
1321
|
+
if (isNil(b[item.id])) return order === "ascend" ? -1 : 1;
|
|
1377
1322
|
return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
|
|
1378
1323
|
};
|
|
1379
1324
|
if (item.filterDropdown !== false) {
|
|
@@ -1396,24 +1341,19 @@ function Table(props) {
|
|
|
1396
1341
|
);
|
|
1397
1342
|
if (!item.onFilter && !props.faasData)
|
|
1398
1343
|
item.onFilter = (value, row) => {
|
|
1399
|
-
if (isNil(value[0]))
|
|
1400
|
-
|
|
1401
|
-
if (isNil(row[item.id]))
|
|
1402
|
-
return false;
|
|
1344
|
+
if (isNil(value[0])) return true;
|
|
1345
|
+
if (isNil(row[item.id])) return false;
|
|
1403
1346
|
return dayjs2(row[item.id]) >= dayjs2(value[0]) && dayjs2(row[item.id]) <= dayjs2(value[1]);
|
|
1404
1347
|
};
|
|
1405
1348
|
}
|
|
1406
1349
|
break;
|
|
1407
1350
|
case "time":
|
|
1408
1351
|
item.width = (_c = item.width) != null ? _c : 200;
|
|
1409
|
-
if (!item.render)
|
|
1410
|
-
item.render = (value) => processValue(item, value);
|
|
1352
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1411
1353
|
if (typeof item.sorter === "undefined")
|
|
1412
1354
|
item.sorter = (a, b, order) => {
|
|
1413
|
-
if (isNil(a[item.id]))
|
|
1414
|
-
|
|
1415
|
-
if (isNil(b[item.id]))
|
|
1416
|
-
return order === "ascend" ? -1 : 1;
|
|
1355
|
+
if (isNil(a[item.id])) return order === "ascend" ? 1 : -1;
|
|
1356
|
+
if (isNil(b[item.id])) return order === "ascend" ? -1 : 1;
|
|
1417
1357
|
return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
|
|
1418
1358
|
};
|
|
1419
1359
|
if (item.filterDropdown !== false) {
|
|
@@ -1436,10 +1376,8 @@ function Table(props) {
|
|
|
1436
1376
|
);
|
|
1437
1377
|
if (!item.onFilter && !props.faasData)
|
|
1438
1378
|
item.onFilter = (value, row) => {
|
|
1439
|
-
if (isNil(value[0]))
|
|
1440
|
-
|
|
1441
|
-
if (isNil(row[item.id]))
|
|
1442
|
-
return false;
|
|
1379
|
+
if (isNil(value[0])) return true;
|
|
1380
|
+
if (isNil(row[item.id])) return false;
|
|
1443
1381
|
return dayjs2(row[item.id]) >= dayjs2(value[0]) && dayjs2(row[item.id]) <= dayjs2(value[1]);
|
|
1444
1382
|
};
|
|
1445
1383
|
}
|
|
@@ -1468,12 +1406,10 @@ function Table(props) {
|
|
|
1468
1406
|
)) });
|
|
1469
1407
|
break;
|
|
1470
1408
|
default:
|
|
1471
|
-
if (!item.render)
|
|
1472
|
-
item.render = (value) => processValue(item, value);
|
|
1409
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1473
1410
|
if (item.filterDropdown !== false && !item.onFilter && !props.faasData)
|
|
1474
1411
|
item.onFilter = (value, row) => {
|
|
1475
|
-
if (value === null && isNil(row[item.id]))
|
|
1476
|
-
return true;
|
|
1412
|
+
if (value === null && isNil(row[item.id])) return true;
|
|
1477
1413
|
return value === row[item.id];
|
|
1478
1414
|
};
|
|
1479
1415
|
break;
|
|
@@ -1482,8 +1418,7 @@ function Table(props) {
|
|
|
1482
1418
|
setColumns(items);
|
|
1483
1419
|
}, [props.items]);
|
|
1484
1420
|
useEffect(() => {
|
|
1485
|
-
if (!props.dataSource || !columns)
|
|
1486
|
-
return;
|
|
1421
|
+
if (!props.dataSource || !columns) return;
|
|
1487
1422
|
for (const column of columns) {
|
|
1488
1423
|
if (column.optionsType === "auto" && !column.options && !column.filters) {
|
|
1489
1424
|
const options = uniqBy(props.dataSource, column.id).map((v) => ({
|
|
@@ -1501,8 +1436,7 @@ function Table(props) {
|
|
|
1501
1436
|
}
|
|
1502
1437
|
}
|
|
1503
1438
|
}, [props.dataSource, columns]);
|
|
1504
|
-
if (!columns)
|
|
1505
|
-
return null;
|
|
1439
|
+
if (!columns) return null;
|
|
1506
1440
|
if (props.dataSource)
|
|
1507
1441
|
return /* @__PURE__ */ jsx(
|
|
1508
1442
|
Table$1,
|
|
@@ -1525,8 +1459,7 @@ function FaasDataTable({
|
|
|
1525
1459
|
}) {
|
|
1526
1460
|
const [currentColumns, setCurrentColumns] = useState(columns);
|
|
1527
1461
|
useEffect(() => {
|
|
1528
|
-
if (!data || Array.isArray(data))
|
|
1529
|
-
return;
|
|
1462
|
+
if (!data || Array.isArray(data)) return;
|
|
1530
1463
|
setCurrentColumns((prev) => {
|
|
1531
1464
|
var _a;
|
|
1532
1465
|
const newColumns = [...prev];
|
|
@@ -1541,8 +1474,7 @@ function FaasDataTable({
|
|
|
1541
1474
|
value: null
|
|
1542
1475
|
});
|
|
1543
1476
|
column.render = (value) => processValue(column, value);
|
|
1544
|
-
if (column.filterDropdown)
|
|
1545
|
-
delete column.filterDropdown;
|
|
1477
|
+
if (column.filterDropdown) delete column.filterDropdown;
|
|
1546
1478
|
continue;
|
|
1547
1479
|
}
|
|
1548
1480
|
if (column.optionsType === "auto" && !column.options && !column.filters) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"lodash-es": "*"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@faasjs/react": "2.
|
|
29
|
+
"@faasjs/react": "2.4.0",
|
|
30
30
|
"antd": "*",
|
|
31
31
|
"react": "*",
|
|
32
32
|
"react-dom": "*",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@testing-library/react": "*",
|
|
39
39
|
"@testing-library/user-event": "*",
|
|
40
40
|
"@welldone-software/why-did-you-render": "*",
|
|
41
|
-
"@faasjs/react": "2.
|
|
41
|
+
"@faasjs/react": "2.4.0",
|
|
42
42
|
"antd": "*",
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-dom": "*",
|