@faasjs/ant-design 0.0.3-beta.2 → 0.0.3-beta.20
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/README.md +51 -314
- package/dist/index.d.ts +59 -100
- package/dist/index.js +177 -139
- package/dist/index.mjs +87 -48
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
useEffect,
|
|
13
13
|
useState
|
|
14
14
|
} from "react";
|
|
15
|
-
import { ConfigProvider as AntdConfigProvider } from "antd";
|
|
16
15
|
import { defaultsDeep } from "lodash-es";
|
|
17
16
|
import { jsx } from "react/jsx-runtime";
|
|
18
17
|
var isZH = /^zh/i.test(navigator.language);
|
|
@@ -72,10 +71,7 @@ function ConfigProvider({
|
|
|
72
71
|
}, []);
|
|
73
72
|
return /* @__PURE__ */ jsx(ConfigContext.Provider, {
|
|
74
73
|
value: values,
|
|
75
|
-
children
|
|
76
|
-
...config.antd,
|
|
77
|
-
children
|
|
78
|
-
})
|
|
74
|
+
children
|
|
79
75
|
});
|
|
80
76
|
}
|
|
81
77
|
function useConfigContext() {
|
|
@@ -181,7 +177,10 @@ function DescriptionItemContent(props) {
|
|
|
181
177
|
else
|
|
182
178
|
throw Error(computedProps.item.type + " requires children or render");
|
|
183
179
|
if (computedProps.item.children)
|
|
184
|
-
return cloneElement(computedProps.item.children, {
|
|
180
|
+
return cloneElement(computedProps.item.children, {
|
|
181
|
+
value: computedProps.value,
|
|
182
|
+
values: computedProps.values
|
|
183
|
+
});
|
|
185
184
|
if (computedProps.item.render)
|
|
186
185
|
return /* @__PURE__ */ jsx3(Fragment, {
|
|
187
186
|
children: computedProps.item.render(computedProps.value, computedProps.values)
|
|
@@ -320,7 +319,8 @@ import {
|
|
|
320
319
|
import {
|
|
321
320
|
useEffect as useEffect4,
|
|
322
321
|
useState as useState5,
|
|
323
|
-
useCallback
|
|
322
|
+
useCallback,
|
|
323
|
+
isValidElement
|
|
324
324
|
} from "react";
|
|
325
325
|
|
|
326
326
|
// src/FormItem.tsx
|
|
@@ -360,13 +360,13 @@ function processProps(propsCopy, config) {
|
|
|
360
360
|
required: true,
|
|
361
361
|
validator: async (_, values) => {
|
|
362
362
|
if (!values || values.length < 1)
|
|
363
|
-
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.
|
|
363
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
|
|
364
364
|
}
|
|
365
365
|
});
|
|
366
366
|
else
|
|
367
367
|
propsCopy.rules.push({
|
|
368
368
|
required: true,
|
|
369
|
-
message: `${propsCopy.label || propsCopy.title} ${config.
|
|
369
|
+
message: `${propsCopy.label || propsCopy.title} ${config.required}`
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
372
|
if (!propsCopy.input)
|
|
@@ -393,8 +393,8 @@ function FormItem(props) {
|
|
|
393
393
|
var _a;
|
|
394
394
|
const [computedProps, setComputedProps] = useState4();
|
|
395
395
|
const [extendTypes, setExtendTypes] = useState4();
|
|
396
|
-
const
|
|
397
|
-
const [hidden, setHidden] = useState4(false);
|
|
396
|
+
const { common: common2 } = useConfigContext();
|
|
397
|
+
const [hidden, setHidden] = useState4(props.hidden || false);
|
|
398
398
|
useEffect3(() => {
|
|
399
399
|
const propsCopy = { ...props };
|
|
400
400
|
if (propsCopy.extendTypes) {
|
|
@@ -403,14 +403,18 @@ function FormItem(props) {
|
|
|
403
403
|
}
|
|
404
404
|
if (propsCopy.if) {
|
|
405
405
|
const condition = propsCopy.if;
|
|
406
|
-
propsCopy.shouldUpdate
|
|
406
|
+
const originShouldUpdate = propsCopy.shouldUpdate;
|
|
407
|
+
propsCopy.shouldUpdate = (prev, cur) => {
|
|
407
408
|
const show = condition(cur);
|
|
409
|
+
const shouldUpdate = hidden !== show;
|
|
408
410
|
setHidden(!show);
|
|
409
|
-
|
|
411
|
+
const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
|
|
412
|
+
return shouldUpdate || origin;
|
|
410
413
|
};
|
|
411
414
|
delete propsCopy.if;
|
|
415
|
+
delete propsCopy.hidden;
|
|
412
416
|
}
|
|
413
|
-
setComputedProps(processProps(propsCopy,
|
|
417
|
+
setComputedProps(processProps(propsCopy, common2));
|
|
414
418
|
}, [props]);
|
|
415
419
|
if (!computedProps)
|
|
416
420
|
return null;
|
|
@@ -657,7 +661,7 @@ function FormItem(props) {
|
|
|
657
661
|
danger: true,
|
|
658
662
|
type: "link",
|
|
659
663
|
onClick: () => remove(field.name),
|
|
660
|
-
children:
|
|
664
|
+
children: common2.delete
|
|
661
665
|
})
|
|
662
666
|
]
|
|
663
667
|
})
|
|
@@ -682,7 +686,7 @@ function FormItem(props) {
|
|
|
682
686
|
onClick: () => add(),
|
|
683
687
|
icon: /* @__PURE__ */ jsx5(PlusOutlined, {}),
|
|
684
688
|
children: [
|
|
685
|
-
|
|
689
|
+
common2.add,
|
|
686
690
|
" ",
|
|
687
691
|
computedProps.label
|
|
688
692
|
]
|
|
@@ -717,11 +721,19 @@ function Form(props) {
|
|
|
717
721
|
form
|
|
718
722
|
};
|
|
719
723
|
if (propsCopy.initialValues) {
|
|
720
|
-
for (const key in propsCopy.initialValues)
|
|
724
|
+
for (const key in propsCopy.initialValues) {
|
|
721
725
|
propsCopy.initialValues[key] = transferValue(
|
|
722
|
-
(_a2 = propsCopy.items.find((
|
|
726
|
+
(_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
|
|
723
727
|
propsCopy.initialValues[key]
|
|
724
728
|
);
|
|
729
|
+
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
730
|
+
if (item == null ? void 0 : item.if)
|
|
731
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
732
|
+
}
|
|
733
|
+
for (const item of propsCopy.items) {
|
|
734
|
+
if (item.if)
|
|
735
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
736
|
+
}
|
|
725
737
|
setInitialValues(propsCopy.initialValues);
|
|
726
738
|
delete propsCopy.initialValues;
|
|
727
739
|
}
|
|
@@ -758,6 +770,7 @@ function Form(props) {
|
|
|
758
770
|
setComputedProps(propsCopy);
|
|
759
771
|
}, [props]);
|
|
760
772
|
const onValuesChange = useCallback((changedValues, allValues) => {
|
|
773
|
+
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
761
774
|
if (props.onValuesChange) {
|
|
762
775
|
props.onValuesChange(changedValues, allValues);
|
|
763
776
|
}
|
|
@@ -772,6 +785,7 @@ function Form(props) {
|
|
|
772
785
|
useEffect4(() => {
|
|
773
786
|
if (!initialValues)
|
|
774
787
|
return;
|
|
788
|
+
console.debug("Form:initialValues", initialValues);
|
|
775
789
|
form.setFieldsValue(initialValues);
|
|
776
790
|
setInitialValues(null);
|
|
777
791
|
}, [computedProps]);
|
|
@@ -782,7 +796,7 @@ function Form(props) {
|
|
|
782
796
|
onValuesChange,
|
|
783
797
|
children: [
|
|
784
798
|
computedProps.beforeItems,
|
|
785
|
-
(_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ jsx6(FormItem, {
|
|
799
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => isValidElement(item) ? item : /* @__PURE__ */ jsx6(FormItem, {
|
|
786
800
|
...item,
|
|
787
801
|
extendTypes
|
|
788
802
|
}, item.id)),
|
|
@@ -817,15 +831,13 @@ function Link({
|
|
|
817
831
|
if (button)
|
|
818
832
|
return /* @__PURE__ */ jsx7(Button3, {
|
|
819
833
|
...button,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
style
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
children: text || children
|
|
828
|
-
})
|
|
834
|
+
target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
|
|
835
|
+
style: {
|
|
836
|
+
...Link2.style,
|
|
837
|
+
...style || {}
|
|
838
|
+
},
|
|
839
|
+
href,
|
|
840
|
+
children: text != null ? text : children
|
|
829
841
|
});
|
|
830
842
|
return /* @__PURE__ */ jsx7("a", {
|
|
831
843
|
href,
|
|
@@ -834,20 +846,20 @@ function Link({
|
|
|
834
846
|
...Link2.style,
|
|
835
847
|
...style || {}
|
|
836
848
|
},
|
|
837
|
-
children: text
|
|
849
|
+
children: text != null ? text : children
|
|
838
850
|
});
|
|
839
851
|
}
|
|
840
852
|
if (button)
|
|
841
|
-
return /* @__PURE__ */ jsx7(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
853
|
+
return /* @__PURE__ */ jsx7(RouterLink, {
|
|
854
|
+
to: href,
|
|
855
|
+
target: target || (Link2 == null ? void 0 : Link2.target),
|
|
856
|
+
children: /* @__PURE__ */ jsx7(Button3, {
|
|
857
|
+
...button,
|
|
846
858
|
style: {
|
|
847
859
|
...Link2.style,
|
|
848
860
|
...style || {}
|
|
849
861
|
},
|
|
850
|
-
children: text
|
|
862
|
+
children: text != null ? text : children
|
|
851
863
|
})
|
|
852
864
|
});
|
|
853
865
|
return /* @__PURE__ */ jsx7(RouterLink, {
|
|
@@ -857,7 +869,7 @@ function Link({
|
|
|
857
869
|
...Link2.style,
|
|
858
870
|
...style || {}
|
|
859
871
|
},
|
|
860
|
-
children: text
|
|
872
|
+
children: text != null ? text : children
|
|
861
873
|
});
|
|
862
874
|
}
|
|
863
875
|
|
|
@@ -995,7 +1007,13 @@ function Table(props) {
|
|
|
995
1007
|
}));
|
|
996
1008
|
}
|
|
997
1009
|
if (item.children)
|
|
998
|
-
|
|
1010
|
+
item.render = (value, values) => cloneElement2(
|
|
1011
|
+
item.children,
|
|
1012
|
+
{
|
|
1013
|
+
value,
|
|
1014
|
+
values
|
|
1015
|
+
}
|
|
1016
|
+
);
|
|
999
1017
|
if (props.extendTypes && props.extendTypes[item.type]) {
|
|
1000
1018
|
if (props.extendTypes[item.type].children)
|
|
1001
1019
|
item.render = (value, values) => cloneElement2(
|
|
@@ -1015,8 +1033,10 @@ function Table(props) {
|
|
|
1015
1033
|
case "string":
|
|
1016
1034
|
if (!item.render)
|
|
1017
1035
|
item.render = (value) => processValue(item, value);
|
|
1018
|
-
if (!item.onFilter)
|
|
1036
|
+
if (!props.faasData && !item.onFilter)
|
|
1019
1037
|
item.onFilter = (value, row) => {
|
|
1038
|
+
if (value === null && isNil2(row[item.id]))
|
|
1039
|
+
return true;
|
|
1020
1040
|
if (!row[item.id])
|
|
1021
1041
|
return false;
|
|
1022
1042
|
return row[item.id].toLowerCase().includes(value.toLowerCase());
|
|
@@ -1043,8 +1063,10 @@ function Table(props) {
|
|
|
1043
1063
|
case "string[]":
|
|
1044
1064
|
if (!item.render)
|
|
1045
1065
|
item.render = (value) => processValue(item, value);
|
|
1046
|
-
if (!item.onFilter)
|
|
1066
|
+
if (!props.faasData && !item.onFilter)
|
|
1047
1067
|
item.onFilter = (value, row) => {
|
|
1068
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1069
|
+
return true;
|
|
1048
1070
|
if (!row[item.id] || !row[item.id].length)
|
|
1049
1071
|
return false;
|
|
1050
1072
|
return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
|
|
@@ -1073,8 +1095,12 @@ function Table(props) {
|
|
|
1073
1095
|
item.render = (value) => processValue(item, value);
|
|
1074
1096
|
if (!item.sorter)
|
|
1075
1097
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
1076
|
-
if (!item.onFilter)
|
|
1077
|
-
item.onFilter = (value, row) =>
|
|
1098
|
+
if (!props.faasData && !item.onFilter)
|
|
1099
|
+
item.onFilter = (value, row) => {
|
|
1100
|
+
if (value === null && isNil2(row[item.id]))
|
|
1101
|
+
return true;
|
|
1102
|
+
return value == row[item.id];
|
|
1103
|
+
};
|
|
1078
1104
|
if (!item.filters && item.filterDropdown !== false)
|
|
1079
1105
|
item.filterDropdown = ({
|
|
1080
1106
|
setSelectedKeys,
|
|
@@ -1097,8 +1123,14 @@ function Table(props) {
|
|
|
1097
1123
|
case "number[]":
|
|
1098
1124
|
if (!item.render)
|
|
1099
1125
|
item.render = (value) => processValue(item, value).join(", ");
|
|
1100
|
-
if (!item.onFilter)
|
|
1101
|
-
item.onFilter = (value, row) =>
|
|
1126
|
+
if (!props.faasData && !item.onFilter)
|
|
1127
|
+
item.onFilter = (value, row) => {
|
|
1128
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1129
|
+
return true;
|
|
1130
|
+
if (!row[item.id] || !row[item.id].length)
|
|
1131
|
+
return false;
|
|
1132
|
+
return row[item.id].includes(Number(value));
|
|
1133
|
+
};
|
|
1102
1134
|
if (!item.filters && item.filterDropdown !== false)
|
|
1103
1135
|
item.filterDropdown = ({
|
|
1104
1136
|
setSelectedKeys,
|
|
@@ -1172,7 +1204,7 @@ function Table(props) {
|
|
|
1172
1204
|
})
|
|
1173
1205
|
]
|
|
1174
1206
|
});
|
|
1175
|
-
if (!item.onFilter)
|
|
1207
|
+
if (!props.faasData && !item.onFilter)
|
|
1176
1208
|
item.onFilter = (value, row) => {
|
|
1177
1209
|
switch (value) {
|
|
1178
1210
|
case "true":
|
|
@@ -1189,7 +1221,7 @@ function Table(props) {
|
|
|
1189
1221
|
case "date":
|
|
1190
1222
|
if (!item.render)
|
|
1191
1223
|
item.render = (value) => processValue(item, value);
|
|
1192
|
-
if (!item.onFilter)
|
|
1224
|
+
if (!props.faasData && !item.onFilter)
|
|
1193
1225
|
item.onFilter = (value, row) => dayjs2(row[item.id]).isSame(dayjs2(value));
|
|
1194
1226
|
if (!item.sorter)
|
|
1195
1227
|
item.sorter = (a, b) => dayjs2(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
|
|
@@ -1197,7 +1229,7 @@ function Table(props) {
|
|
|
1197
1229
|
case "time":
|
|
1198
1230
|
if (!item.render)
|
|
1199
1231
|
item.render = (value) => processValue(item, value);
|
|
1200
|
-
if (!item.onFilter)
|
|
1232
|
+
if (!props.faasData && !item.onFilter)
|
|
1201
1233
|
item.onFilter = (value, row) => dayjs2(row[item.id]).isSame(dayjs2(value));
|
|
1202
1234
|
if (!item.sorter)
|
|
1203
1235
|
item.sorter = (a, b) => dayjs2(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
|
|
@@ -1222,7 +1254,11 @@ function Table(props) {
|
|
|
1222
1254
|
if (!item.render)
|
|
1223
1255
|
item.render = (value) => processValue(item, value);
|
|
1224
1256
|
if (!item.onFilter)
|
|
1225
|
-
item.onFilter = (value, row) =>
|
|
1257
|
+
item.onFilter = (value, row) => {
|
|
1258
|
+
if (value === null && isNil2(row[item.id]))
|
|
1259
|
+
return true;
|
|
1260
|
+
return value === row[item.id];
|
|
1261
|
+
};
|
|
1226
1262
|
break;
|
|
1227
1263
|
}
|
|
1228
1264
|
}
|
|
@@ -1239,7 +1275,10 @@ function Table(props) {
|
|
|
1239
1275
|
newColumns[index].filters = uniqBy(props.dataSource, column.id).map((v) => ({
|
|
1240
1276
|
text: v[column.id],
|
|
1241
1277
|
value: v[column.id]
|
|
1242
|
-
}))
|
|
1278
|
+
})).concat({
|
|
1279
|
+
text: /* @__PURE__ */ jsx10(Blank, {}),
|
|
1280
|
+
value: null
|
|
1281
|
+
});
|
|
1243
1282
|
return newColumns;
|
|
1244
1283
|
});
|
|
1245
1284
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lodash-es": "*",
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*",
|
|
31
|
-
"@faasjs/react": "^0.0.3-beta.
|
|
31
|
+
"@faasjs/react": "^0.0.3-beta.20",
|
|
32
32
|
"react-router-dom": "*",
|
|
33
33
|
"dayjs": "*"
|
|
34
34
|
},
|