@faasjs/ant-design 0.0.3-beta.2 → 0.0.3-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.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: /* @__PURE__ */ jsx(AntdConfigProvider, {
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, { value: computedProps.value });
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.common.required}`));
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.common.required}`
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 config = useConfigContext();
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 = (_, cur) => {
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
- return show;
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, config));
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: config.common.delete
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
- config.common.add,
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((item) => item.id === key)) == null ? void 0 : _a2.type,
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
- children: /* @__PURE__ */ jsx7("a", {
821
- href,
822
- target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
823
- style: {
824
- ...Link2.style,
825
- ...style || {}
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 || children
849
+ children: text != null ? text : children
838
850
  });
839
851
  }
840
852
  if (button)
841
- return /* @__PURE__ */ jsx7(Button3, {
842
- ...button,
843
- children: /* @__PURE__ */ jsx7(RouterLink, {
844
- to: href,
845
- target: target || (Link2 == null ? void 0 : Link2.target),
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 || children
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 || children
872
+ children: text != null ? text : children
861
873
  });
862
874
  }
863
875
 
@@ -947,7 +959,9 @@ import {
947
959
  uniqBy,
948
960
  upperFirst as upperFirst4
949
961
  } from "lodash-es";
950
- import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
962
+ import {
963
+ FaasDataWrapper as FaasDataWrapper2
964
+ } from "@faasjs/react";
951
965
  import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
952
966
  function processValue(item, value) {
953
967
  var _a;
@@ -992,10 +1006,19 @@ function Table(props) {
992
1006
  item.filters = item.options.map((o) => ({
993
1007
  text: o.label,
994
1008
  value: o.value
995
- }));
1009
+ })).concat({
1010
+ text: /* @__PURE__ */ jsx10(Blank, {}),
1011
+ value: null
1012
+ });
996
1013
  }
997
1014
  if (item.children)
998
- delete item.children;
1015
+ item.render = (value, values) => cloneElement2(
1016
+ item.children,
1017
+ {
1018
+ value,
1019
+ values
1020
+ }
1021
+ );
999
1022
  if (props.extendTypes && props.extendTypes[item.type]) {
1000
1023
  if (props.extendTypes[item.type].children)
1001
1024
  item.render = (value, values) => cloneElement2(
@@ -1015,8 +1038,10 @@ function Table(props) {
1015
1038
  case "string":
1016
1039
  if (!item.render)
1017
1040
  item.render = (value) => processValue(item, value);
1018
- if (!item.onFilter)
1041
+ if (!props.faasData && !item.onFilter)
1019
1042
  item.onFilter = (value, row) => {
1043
+ if (value === null && isNil2(row[item.id]))
1044
+ return true;
1020
1045
  if (!row[item.id])
1021
1046
  return false;
1022
1047
  return row[item.id].toLowerCase().includes(value.toLowerCase());
@@ -1043,8 +1068,10 @@ function Table(props) {
1043
1068
  case "string[]":
1044
1069
  if (!item.render)
1045
1070
  item.render = (value) => processValue(item, value);
1046
- if (!item.onFilter)
1071
+ if (!props.faasData && !item.onFilter)
1047
1072
  item.onFilter = (value, row) => {
1073
+ if (value === null && (!row[item.id] || !row[item.id].length))
1074
+ return true;
1048
1075
  if (!row[item.id] || !row[item.id].length)
1049
1076
  return false;
1050
1077
  return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
@@ -1073,8 +1100,12 @@ function Table(props) {
1073
1100
  item.render = (value) => processValue(item, value);
1074
1101
  if (!item.sorter)
1075
1102
  item.sorter = (a, b) => a[item.id] - b[item.id];
1076
- if (!item.onFilter)
1077
- item.onFilter = (value, row) => value === row[item.id];
1103
+ if (!props.faasData && !item.onFilter)
1104
+ item.onFilter = (value, row) => {
1105
+ if (value === null && isNil2(row[item.id]))
1106
+ return true;
1107
+ return value == row[item.id];
1108
+ };
1078
1109
  if (!item.filters && item.filterDropdown !== false)
1079
1110
  item.filterDropdown = ({
1080
1111
  setSelectedKeys,
@@ -1097,8 +1128,14 @@ function Table(props) {
1097
1128
  case "number[]":
1098
1129
  if (!item.render)
1099
1130
  item.render = (value) => processValue(item, value).join(", ");
1100
- if (!item.onFilter)
1101
- item.onFilter = (value, row) => row[item.id].includes(value);
1131
+ if (!props.faasData && !item.onFilter)
1132
+ item.onFilter = (value, row) => {
1133
+ if (value === null && (!row[item.id] || !row[item.id].length))
1134
+ return true;
1135
+ if (!row[item.id] || !row[item.id].length)
1136
+ return false;
1137
+ return row[item.id].includes(Number(value));
1138
+ };
1102
1139
  if (!item.filters && item.filterDropdown !== false)
1103
1140
  item.filterDropdown = ({
1104
1141
  setSelectedKeys,
@@ -1172,7 +1209,7 @@ function Table(props) {
1172
1209
  })
1173
1210
  ]
1174
1211
  });
1175
- if (!item.onFilter)
1212
+ if (!props.faasData && !item.onFilter)
1176
1213
  item.onFilter = (value, row) => {
1177
1214
  switch (value) {
1178
1215
  case "true":
@@ -1189,7 +1226,7 @@ function Table(props) {
1189
1226
  case "date":
1190
1227
  if (!item.render)
1191
1228
  item.render = (value) => processValue(item, value);
1192
- if (!item.onFilter)
1229
+ if (!props.faasData && !item.onFilter)
1193
1230
  item.onFilter = (value, row) => dayjs2(row[item.id]).isSame(dayjs2(value));
1194
1231
  if (!item.sorter)
1195
1232
  item.sorter = (a, b) => dayjs2(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
@@ -1197,7 +1234,7 @@ function Table(props) {
1197
1234
  case "time":
1198
1235
  if (!item.render)
1199
1236
  item.render = (value) => processValue(item, value);
1200
- if (!item.onFilter)
1237
+ if (!props.faasData && !item.onFilter)
1201
1238
  item.onFilter = (value, row) => dayjs2(row[item.id]).isSame(dayjs2(value));
1202
1239
  if (!item.sorter)
1203
1240
  item.sorter = (a, b) => dayjs2(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
@@ -1222,7 +1259,11 @@ function Table(props) {
1222
1259
  if (!item.render)
1223
1260
  item.render = (value) => processValue(item, value);
1224
1261
  if (!item.onFilter)
1225
- item.onFilter = (value, row) => value === row[item.id];
1262
+ item.onFilter = (value, row) => {
1263
+ if (value === null && isNil2(row[item.id]))
1264
+ return true;
1265
+ return value === row[item.id];
1266
+ };
1226
1267
  break;
1227
1268
  }
1228
1269
  }
@@ -1239,7 +1280,10 @@ function Table(props) {
1239
1280
  newColumns[index].filters = uniqBy(props.dataSource, column.id).map((v) => ({
1240
1281
  text: v[column.id],
1241
1282
  value: v[column.id]
1242
- }));
1283
+ })).concat({
1284
+ text: /* @__PURE__ */ jsx10(Blank, {}),
1285
+ value: null
1286
+ });
1243
1287
  return newColumns;
1244
1288
  });
1245
1289
  }
@@ -1258,55 +1302,95 @@ function Table(props) {
1258
1302
  fallback: props.faasData.fallback || /* @__PURE__ */ jsx10(Skeleton3, {
1259
1303
  active: true
1260
1304
  }),
1261
- render: ({
1262
- data,
1263
- params,
1264
- reload
1265
- }) => {
1266
- if (!data)
1267
- return /* @__PURE__ */ jsx10(AntdTable, {
1268
- ...props,
1269
- rowKey: props.rowKey || "id",
1270
- columns,
1271
- dataSource: []
1272
- });
1273
- if (Array.isArray(data))
1274
- return /* @__PURE__ */ jsx10(AntdTable, {
1275
- ...props,
1276
- rowKey: props.rowKey || "id",
1277
- columns,
1278
- dataSource: data
1279
- });
1280
- return /* @__PURE__ */ jsx10(AntdTable, {
1281
- ...props,
1282
- rowKey: props.rowKey || "id",
1283
- columns,
1284
- dataSource: data.rows,
1285
- pagination: {
1286
- ...props.pagination,
1287
- ...data.pagination
1288
- },
1289
- onChange: (pagination, filters, sorter, extra) => {
1290
- if (props.onChange) {
1291
- const processed = props.onChange(pagination, filters, sorter, extra);
1292
- reload({
1293
- ...params,
1294
- pagination: processed.pagination,
1295
- filters: processed.filters,
1296
- sorter: processed.sorter
1297
- });
1298
- return;
1299
- }
1300
- reload({
1301
- ...params,
1302
- pagination,
1303
- filters,
1304
- sorter
1305
+ ...props.faasData,
1306
+ children: /* @__PURE__ */ jsx10(FaasDataTable, {
1307
+ props,
1308
+ columns
1309
+ })
1310
+ });
1311
+ }
1312
+ function FaasDataTable({
1313
+ props,
1314
+ columns,
1315
+ data,
1316
+ params,
1317
+ reload
1318
+ }) {
1319
+ const [currentColumns, setCurrentColumns] = useState7(columns);
1320
+ useEffect5(() => {
1321
+ if (!data || Array.isArray(data))
1322
+ return;
1323
+ setCurrentColumns((prev) => {
1324
+ const newColumns = [...prev];
1325
+ for (const column of newColumns) {
1326
+ if (data["options"][column.id]) {
1327
+ column.options = data["options"][column.id];
1328
+ column.filters = data["options"][column.id].map((v) => ({
1329
+ text: v.label,
1330
+ value: v.value
1331
+ })).concat({
1332
+ text: /* @__PURE__ */ jsx10(Blank, {}),
1333
+ value: null
1305
1334
  });
1335
+ column.render = (value) => processValue(column, value);
1336
+ if (column.filterDropdown)
1337
+ delete column.filterDropdown;
1338
+ continue;
1306
1339
  }
1307
- });
1340
+ if (column.optionsType === "auto" && !column.options && !column.filters) {
1341
+ column.filters = uniqBy(props.dataSource, column.id).map((v) => ({
1342
+ text: v[column.id],
1343
+ value: v[column.id]
1344
+ })).concat({
1345
+ text: /* @__PURE__ */ jsx10(Blank, {}),
1346
+ value: null
1347
+ });
1348
+ }
1349
+ }
1350
+ return newColumns;
1351
+ });
1352
+ }, [columns, data]);
1353
+ if (!data)
1354
+ return /* @__PURE__ */ jsx10(AntdTable, {
1355
+ ...props,
1356
+ rowKey: props.rowKey || "id",
1357
+ columns: currentColumns,
1358
+ dataSource: []
1359
+ });
1360
+ if (Array.isArray(data))
1361
+ return /* @__PURE__ */ jsx10(AntdTable, {
1362
+ ...props,
1363
+ rowKey: props.rowKey || "id",
1364
+ columns: currentColumns,
1365
+ dataSource: data
1366
+ });
1367
+ return /* @__PURE__ */ jsx10(AntdTable, {
1368
+ ...props,
1369
+ rowKey: props.rowKey || "id",
1370
+ columns: currentColumns,
1371
+ dataSource: data.rows,
1372
+ pagination: {
1373
+ ...props.pagination,
1374
+ ...data.pagination
1308
1375
  },
1309
- ...props.faasData
1376
+ onChange: (pagination, filters, sorter, extra) => {
1377
+ if (props.onChange) {
1378
+ const processed = props.onChange(pagination, filters, sorter, extra);
1379
+ reload({
1380
+ ...params,
1381
+ pagination: processed.pagination,
1382
+ filters: processed.filters,
1383
+ sorter: processed.sorter
1384
+ });
1385
+ return;
1386
+ }
1387
+ reload({
1388
+ ...params,
1389
+ pagination,
1390
+ filters,
1391
+ sorter
1392
+ });
1393
+ }
1310
1394
  });
1311
1395
  }
1312
1396
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.3-beta.2",
3
+ "version": "0.0.3-beta.21",
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.2",
31
+ "@faasjs/react": "^0.0.3-beta.21",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },