@faasjs/ant-design 0.0.3-beta.1 → 0.0.3-beta.10

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.ts CHANGED
@@ -240,10 +240,10 @@ type FormItemProps<T = any> = {
240
240
  *
241
241
  * ```ts
242
242
  * // use inline type
243
- * <FormItem item={{ type: 'string', id: 'name' }} />
243
+ * <FormItem type='string' id='name' />
244
244
  *
245
245
  * // use custom type
246
- * <FormItem item={{ id: 'password' }}>
246
+ * <FormItem id='password'>
247
247
  * <Input.Password />
248
248
  * </>
249
249
  * ```
@@ -251,7 +251,7 @@ type FormItemProps<T = any> = {
251
251
  declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
252
252
 
253
253
  type FormProps<Values extends Record<string, any> = any, ExtendItemProps = any> = {
254
- items?: (FormItemProps | ExtendItemProps)[];
254
+ items?: (FormItemProps | ExtendItemProps | JSX.Element)[];
255
255
  /** Default: { text: 'Submit' }, set false to disable it */
256
256
  submit?: false | {
257
257
  /** Default: Submit */
package/dist/index.js CHANGED
@@ -52,12 +52,12 @@ var import_react = __toESM(require("react"));
52
52
 
53
53
  // src/Blank.tsx
54
54
  var import_antd2 = require("antd");
55
- var import_lodash2 = require("lodash");
55
+ var import_lodash_es2 = require("lodash-es");
56
56
 
57
57
  // src/Config.tsx
58
58
  var import_react2 = require("react");
59
59
  var import_antd = require("antd");
60
- var import_lodash = require("lodash");
60
+ var import_lodash_es = require("lodash-es");
61
61
  var import_jsx_runtime = require("react/jsx-runtime");
62
62
  var isZH = /^zh/i.test(navigator.language);
63
63
  var zh = {
@@ -105,7 +105,7 @@ function ConfigProvider({
105
105
  const [values, setValues] = (0, import_react2.useState)(baseConfig);
106
106
  (0, import_react2.useEffect)(() => {
107
107
  if (config.lang === "zh") {
108
- setValues((0, import_lodash.defaultsDeep)(config, {
108
+ setValues((0, import_lodash_es.defaultsDeep)(config, {
109
109
  lang: "zh",
110
110
  common: zh,
111
111
  Blank: { text: zh.blank },
@@ -130,20 +130,20 @@ function useConfigContext() {
130
130
  var import_jsx_runtime = require("react/jsx-runtime");
131
131
  function Blank(options) {
132
132
  const { Blank: Blank2 } = useConfigContext();
133
- return !options || (0, import_lodash2.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd2.Typography.Text, {
133
+ return !options || (0, import_lodash_es2.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd2.Typography.Text, {
134
134
  disabled: true,
135
135
  children: (options == null ? void 0 : options.text) || Blank2.text
136
136
  }) : options.value;
137
137
  }
138
138
 
139
139
  // src/data.ts
140
- var import_lodash3 = require("lodash");
140
+ var import_lodash_es3 = require("lodash-es");
141
141
  var import_dayjs = __toESM(require("dayjs"));
142
142
  function transferOptions(options) {
143
143
  if (!options)
144
144
  return [];
145
145
  return options.map((item) => typeof item === "object" ? item : {
146
- label: (0, import_lodash3.upperFirst)(item.toString()),
146
+ label: (0, import_lodash_es3.upperFirst)(item.toString()),
147
147
  value: item
148
148
  });
149
149
  }
@@ -166,7 +166,7 @@ function transferValue(type, value) {
166
166
  // src/Description.tsx
167
167
  var import_icons = require("@ant-design/icons");
168
168
  var import_antd3 = require("antd");
169
- var import_lodash4 = require("lodash");
169
+ var import_lodash_es4 = require("lodash-es");
170
170
  var import_react3 = require("react");
171
171
  var import_react4 = require("@faasjs/react");
172
172
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -177,7 +177,7 @@ function DescriptionItemContent(props) {
177
177
  var _a2, _b;
178
178
  const propsCopy = { ...props };
179
179
  if (!propsCopy.item.title)
180
- propsCopy.item.title = (0, import_lodash4.upperFirst)(propsCopy.item.id);
180
+ propsCopy.item.title = (0, import_lodash_es4.upperFirst)(propsCopy.item.id);
181
181
  if (!propsCopy.item.type)
182
182
  propsCopy.item.type = "string";
183
183
  if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
@@ -282,10 +282,10 @@ function Description(props) {
282
282
  if (!props.faasData)
283
283
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
284
284
  ...props,
285
- title: (0, import_lodash4.isFunction)(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
285
+ title: (0, import_lodash_es4.isFunction)(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
286
286
  children: props.items.map((item) => {
287
287
  return !item.if || item.if(props.dataSource) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
288
- label: item.title || (0, import_lodash4.upperFirst)(item.id),
288
+ label: item.title || (0, import_lodash_es4.upperFirst)(item.id),
289
289
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
290
290
  item,
291
291
  value: props.dataSource[item.id],
@@ -302,10 +302,10 @@ function Description(props) {
302
302
  render: ({ data }) => {
303
303
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
304
304
  ...props,
305
- title: (0, import_lodash4.isFunction)(props.renderTitle) ? props.renderTitle(data) : props.title,
305
+ title: (0, import_lodash_es4.isFunction)(props.renderTitle) ? props.renderTitle(data) : props.title,
306
306
  children: props.items.map((item) => {
307
307
  return !item.if || item.if(data) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
308
- label: item.title || (0, import_lodash4.upperFirst)(item.id),
308
+ label: item.title || (0, import_lodash_es4.upperFirst)(item.id),
309
309
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
310
310
  item,
311
311
  value: data[item.id],
@@ -356,11 +356,11 @@ var import_react8 = require("react");
356
356
  var import_antd5 = require("antd");
357
357
  var import_icons2 = require("@ant-design/icons");
358
358
  var import_react6 = require("react");
359
- var import_lodash5 = require("lodash");
359
+ var import_lodash_es5 = require("lodash-es");
360
360
  var import_jsx_runtime = require("react/jsx-runtime");
361
361
  function processProps(propsCopy, config) {
362
362
  if (!propsCopy.title)
363
- propsCopy.title = (0, import_lodash5.upperFirst)(propsCopy.id);
363
+ propsCopy.title = (0, import_lodash_es5.upperFirst)(propsCopy.id);
364
364
  if (!propsCopy.label && propsCopy.label !== false)
365
365
  propsCopy.label = propsCopy.title;
366
366
  if (!propsCopy.name)
@@ -375,13 +375,13 @@ function processProps(propsCopy, config) {
375
375
  required: true,
376
376
  validator: async (_, values) => {
377
377
  if (!values || values.length < 1)
378
- return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.common.required}`));
378
+ return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
379
379
  }
380
380
  });
381
381
  else
382
382
  propsCopy.rules.push({
383
383
  required: true,
384
- message: `${propsCopy.label || propsCopy.title} ${config.common.required}`
384
+ message: `${propsCopy.label || propsCopy.title} ${config.required}`
385
385
  });
386
386
  }
387
387
  if (!propsCopy.input)
@@ -408,8 +408,8 @@ function FormItem(props) {
408
408
  var _a;
409
409
  const [computedProps, setComputedProps] = (0, import_react6.useState)();
410
410
  const [extendTypes, setExtendTypes] = (0, import_react6.useState)();
411
- const config = useConfigContext();
412
- const [hidden, setHidden] = (0, import_react6.useState)(false);
411
+ const { common: common2 } = useConfigContext();
412
+ const [hidden, setHidden] = (0, import_react6.useState)(props.hidden || false);
413
413
  (0, import_react6.useEffect)(() => {
414
414
  const propsCopy = { ...props };
415
415
  if (propsCopy.extendTypes) {
@@ -418,14 +418,18 @@ function FormItem(props) {
418
418
  }
419
419
  if (propsCopy.if) {
420
420
  const condition = propsCopy.if;
421
- propsCopy.shouldUpdate = (_, cur) => {
421
+ const originShouldUpdate = propsCopy.shouldUpdate;
422
+ propsCopy.shouldUpdate = (prev, cur) => {
422
423
  const show = condition(cur);
424
+ const shouldUpdate = hidden !== show;
423
425
  setHidden(!show);
424
- return show;
426
+ const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
427
+ return shouldUpdate || origin;
425
428
  };
426
429
  delete propsCopy.if;
430
+ delete propsCopy.hidden;
427
431
  }
428
- setComputedProps(processProps(propsCopy, config));
432
+ setComputedProps(processProps(propsCopy, common2));
429
433
  }, [props]);
430
434
  if (!computedProps)
431
435
  return null;
@@ -672,7 +676,7 @@ function FormItem(props) {
672
676
  danger: true,
673
677
  type: "link",
674
678
  onClick: () => remove(field.name),
675
- children: config.common.delete
679
+ children: common2.delete
676
680
  })
677
681
  ]
678
682
  })
@@ -697,7 +701,7 @@ function FormItem(props) {
697
701
  onClick: () => add(),
698
702
  icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
699
703
  children: [
700
- config.common.add,
704
+ common2.add,
701
705
  " ",
702
706
  computedProps.label
703
707
  ]
@@ -732,11 +736,19 @@ function Form(props) {
732
736
  form
733
737
  };
734
738
  if (propsCopy.initialValues) {
735
- for (const key in propsCopy.initialValues)
739
+ for (const key in propsCopy.initialValues) {
736
740
  propsCopy.initialValues[key] = transferValue(
737
- (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
741
+ (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
738
742
  propsCopy.initialValues[key]
739
743
  );
744
+ const item = propsCopy.items.find((item2) => item2.id === key);
745
+ if (item == null ? void 0 : item.if)
746
+ item.hidden = !item.if(propsCopy.initialValues);
747
+ }
748
+ for (const item of propsCopy.items) {
749
+ if (item.if)
750
+ item.hidden = !item.if(propsCopy.initialValues);
751
+ }
740
752
  setInitialValues(propsCopy.initialValues);
741
753
  delete propsCopy.initialValues;
742
754
  }
@@ -773,6 +785,7 @@ function Form(props) {
773
785
  setComputedProps(propsCopy);
774
786
  }, [props]);
775
787
  const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
788
+ console.debug("Form:onValuesChange", changedValues, allValues);
776
789
  if (props.onValuesChange) {
777
790
  props.onValuesChange(changedValues, allValues);
778
791
  }
@@ -787,6 +800,7 @@ function Form(props) {
787
800
  (0, import_react8.useEffect)(() => {
788
801
  if (!initialValues)
789
802
  return;
803
+ console.debug("Form:initialValues", initialValues);
790
804
  form.setFieldsValue(initialValues);
791
805
  setInitialValues(null);
792
806
  }, [computedProps]);
@@ -797,7 +811,7 @@ function Form(props) {
797
811
  onValuesChange,
798
812
  children: [
799
813
  computedProps.beforeItems,
800
- (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
814
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => (0, import_react8.isValidElement)(item) ? item : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
801
815
  ...item,
802
816
  extendTypes
803
817
  }, item.id)),
@@ -943,7 +957,7 @@ var import_react11 = require("react");
943
957
  var import_antd10 = require("antd");
944
958
  var import_dayjs2 = __toESM(require("dayjs"));
945
959
  var import_icons3 = require("@ant-design/icons");
946
- var import_lodash6 = require("lodash");
960
+ var import_lodash_es6 = require("lodash-es");
947
961
  var import_react12 = require("@faasjs/react");
948
962
  var import_jsx_runtime = require("react/jsx-runtime");
949
963
  function processValue(item, value) {
@@ -972,7 +986,7 @@ function processValue(item, value) {
972
986
  }
973
987
  function Table(props) {
974
988
  const [columns, setColumns] = (0, import_react11.useState)();
975
- const { common: common2 } = useConfigContext();
989
+ const { common: common2, antd } = useConfigContext();
976
990
  (0, import_react11.useEffect)(() => {
977
991
  var _a;
978
992
  for (const item of props.items) {
@@ -981,7 +995,7 @@ function Table(props) {
981
995
  if (!item.dataIndex)
982
996
  item.dataIndex = item.id;
983
997
  if (!item.title)
984
- item.title = (0, import_lodash6.upperFirst)(item.id);
998
+ item.title = (0, import_lodash_es6.upperFirst)(item.id);
985
999
  if (!item.type)
986
1000
  item.type = "string";
987
1001
  if ((_a = item.options) == null ? void 0 : _a.length) {
@@ -1014,6 +1028,8 @@ function Table(props) {
1014
1028
  item.render = (value) => processValue(item, value);
1015
1029
  if (!item.onFilter)
1016
1030
  item.onFilter = (value, row) => {
1031
+ if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
1032
+ return true;
1017
1033
  if (!row[item.id])
1018
1034
  return false;
1019
1035
  return row[item.id].toLowerCase().includes(value.toLowerCase());
@@ -1042,6 +1058,8 @@ function Table(props) {
1042
1058
  item.render = (value) => processValue(item, value);
1043
1059
  if (!item.onFilter)
1044
1060
  item.onFilter = (value, row) => {
1061
+ if (value === null && (!row[item.id] || !row[item.id].length))
1062
+ return true;
1045
1063
  if (!row[item.id] || !row[item.id].length)
1046
1064
  return false;
1047
1065
  return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
@@ -1071,7 +1089,11 @@ function Table(props) {
1071
1089
  if (!item.sorter)
1072
1090
  item.sorter = (a, b) => a[item.id] - b[item.id];
1073
1091
  if (!item.onFilter)
1074
- item.onFilter = (value, row) => value === row[item.id];
1092
+ item.onFilter = (value, row) => {
1093
+ if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
1094
+ return true;
1095
+ return value === row[item.id];
1096
+ };
1075
1097
  if (!item.filters && item.filterDropdown !== false)
1076
1098
  item.filterDropdown = ({
1077
1099
  setSelectedKeys,
@@ -1095,7 +1117,13 @@ function Table(props) {
1095
1117
  if (!item.render)
1096
1118
  item.render = (value) => processValue(item, value).join(", ");
1097
1119
  if (!item.onFilter)
1098
- item.onFilter = (value, row) => row[item.id].includes(value);
1120
+ item.onFilter = (value, row) => {
1121
+ if (value === null && (!row[item.id] || !row[item.id].length))
1122
+ return true;
1123
+ if (!row[item.id] || !row[item.id].length)
1124
+ return false;
1125
+ return row[item.id].includes(value);
1126
+ };
1099
1127
  if (!item.filters && item.filterDropdown !== false)
1100
1128
  item.filterDropdown = ({
1101
1129
  setSelectedKeys,
@@ -1173,11 +1201,11 @@ function Table(props) {
1173
1201
  item.onFilter = (value, row) => {
1174
1202
  switch (value) {
1175
1203
  case "true":
1176
- return !(0, import_lodash6.isNil)(row[item.id]) && !!row[item.id];
1204
+ return !(0, import_lodash_es6.isNil)(row[item.id]) && !!row[item.id];
1177
1205
  case "false":
1178
- return !(0, import_lodash6.isNil)(row[item.id]) && !row[item.id];
1206
+ return !(0, import_lodash_es6.isNil)(row[item.id]) && !row[item.id];
1179
1207
  case "empty":
1180
- return (0, import_lodash6.isNil)(row[item.id]);
1208
+ return (0, import_lodash_es6.isNil)(row[item.id]);
1181
1209
  default:
1182
1210
  return true;
1183
1211
  }
@@ -1219,7 +1247,11 @@ function Table(props) {
1219
1247
  if (!item.render)
1220
1248
  item.render = (value) => processValue(item, value);
1221
1249
  if (!item.onFilter)
1222
- item.onFilter = (value, row) => value === row[item.id];
1250
+ item.onFilter = (value, row) => {
1251
+ if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
1252
+ return true;
1253
+ return value === row[item.id];
1254
+ };
1223
1255
  break;
1224
1256
  }
1225
1257
  }
@@ -1233,10 +1265,13 @@ function Table(props) {
1233
1265
  setColumns((prev) => {
1234
1266
  const newColumns = [...prev];
1235
1267
  const index = newColumns.findIndex((item) => item.id === column.id);
1236
- newColumns[index].filters = (0, import_lodash6.uniqBy)(props.dataSource, column.id).map((v) => ({
1268
+ newColumns[index].filters = (0, import_lodash_es6.uniqBy)(props.dataSource, column.id).map((v) => ({
1237
1269
  text: v[column.id],
1238
1270
  value: v[column.id]
1239
- }));
1271
+ })).concat({
1272
+ text: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {}),
1273
+ value: null
1274
+ });
1240
1275
  return newColumns;
1241
1276
  });
1242
1277
  }
@@ -1245,11 +1280,14 @@ function Table(props) {
1245
1280
  if (!columns)
1246
1281
  return null;
1247
1282
  if (!props.faasData)
1248
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1249
- ...props,
1250
- rowKey: props.rowKey || "id",
1251
- columns,
1252
- dataSource: props.dataSource
1283
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1284
+ ...antd,
1285
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1286
+ ...props,
1287
+ rowKey: props.rowKey || "id",
1288
+ columns,
1289
+ dataSource: props.dataSource
1290
+ })
1253
1291
  });
1254
1292
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react12.FaasDataWrapper, {
1255
1293
  fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Skeleton, {
@@ -1261,46 +1299,55 @@ function Table(props) {
1261
1299
  reload
1262
1300
  }) => {
1263
1301
  if (!data)
1264
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1265
- ...props,
1266
- rowKey: props.rowKey || "id",
1267
- columns,
1268
- dataSource: []
1302
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1303
+ ...antd,
1304
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1305
+ ...props,
1306
+ rowKey: props.rowKey || "id",
1307
+ columns,
1308
+ dataSource: []
1309
+ })
1269
1310
  });
1270
1311
  if (Array.isArray(data))
1271
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1312
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1313
+ ...antd,
1314
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1315
+ ...props,
1316
+ rowKey: props.rowKey || "id",
1317
+ columns,
1318
+ dataSource: data
1319
+ })
1320
+ });
1321
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1322
+ ...antd,
1323
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1272
1324
  ...props,
1273
1325
  rowKey: props.rowKey || "id",
1274
1326
  columns,
1275
- dataSource: data
1276
- });
1277
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1278
- ...props,
1279
- rowKey: props.rowKey || "id",
1280
- columns,
1281
- dataSource: data.rows,
1282
- pagination: {
1283
- ...props.pagination,
1284
- ...data.pagination
1285
- },
1286
- onChange: (pagination, filters, sorter, extra) => {
1287
- if (props.onChange) {
1288
- const processed = props.onChange(pagination, filters, sorter, extra);
1327
+ dataSource: data.rows,
1328
+ pagination: {
1329
+ ...props.pagination,
1330
+ ...data.pagination
1331
+ },
1332
+ onChange: (pagination, filters, sorter, extra) => {
1333
+ if (props.onChange) {
1334
+ const processed = props.onChange(pagination, filters, sorter, extra);
1335
+ reload({
1336
+ ...params,
1337
+ pagination: processed.pagination,
1338
+ filters: processed.filters,
1339
+ sorter: processed.sorter
1340
+ });
1341
+ return;
1342
+ }
1289
1343
  reload({
1290
1344
  ...params,
1291
- pagination: processed.pagination,
1292
- filters: processed.filters,
1293
- sorter: processed.sorter
1345
+ pagination,
1346
+ filters,
1347
+ sorter
1294
1348
  });
1295
- return;
1296
1349
  }
1297
- reload({
1298
- ...params,
1299
- pagination,
1300
- filters,
1301
- sorter
1302
- });
1303
- }
1350
+ })
1304
1351
  });
1305
1352
  },
1306
1353
  ...props.faasData
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import React from "react";
3
3
 
4
4
  // src/Blank.tsx
5
5
  import { Typography } from "antd";
6
- import { isNil } from "lodash";
6
+ import { isNil } from "lodash-es";
7
7
 
8
8
  // src/Config.tsx
9
9
  import {
@@ -13,7 +13,7 @@ import {
13
13
  useState
14
14
  } from "react";
15
15
  import { ConfigProvider as AntdConfigProvider } from "antd";
16
- import { defaultsDeep } from "lodash";
16
+ import { defaultsDeep } from "lodash-es";
17
17
  import { jsx } from "react/jsx-runtime";
18
18
  var isZH = /^zh/i.test(navigator.language);
19
19
  var zh = {
@@ -93,7 +93,7 @@ function Blank(options) {
93
93
  }
94
94
 
95
95
  // src/data.ts
96
- import { upperFirst } from "lodash";
96
+ import { upperFirst } from "lodash-es";
97
97
  import dayjs from "dayjs";
98
98
  function transferOptions(options) {
99
99
  if (!options)
@@ -126,7 +126,7 @@ import {
126
126
  Skeleton,
127
127
  Space
128
128
  } from "antd";
129
- import { isFunction, upperFirst as upperFirst2 } from "lodash";
129
+ import { isFunction, upperFirst as upperFirst2 } from "lodash-es";
130
130
  import {
131
131
  cloneElement,
132
132
  useEffect as useEffect2,
@@ -320,7 +320,8 @@ import {
320
320
  import {
321
321
  useEffect as useEffect4,
322
322
  useState as useState5,
323
- useCallback
323
+ useCallback,
324
+ isValidElement
324
325
  } from "react";
325
326
 
326
327
  // src/FormItem.tsx
@@ -341,7 +342,7 @@ import {
341
342
  useEffect as useEffect3,
342
343
  useState as useState4
343
344
  } from "react";
344
- import { upperFirst as upperFirst3 } from "lodash";
345
+ import { upperFirst as upperFirst3 } from "lodash-es";
345
346
  import { Fragment as Fragment2, jsx as jsx5, jsxs } from "react/jsx-runtime";
346
347
  function processProps(propsCopy, config) {
347
348
  if (!propsCopy.title)
@@ -360,13 +361,13 @@ function processProps(propsCopy, config) {
360
361
  required: true,
361
362
  validator: async (_, values) => {
362
363
  if (!values || values.length < 1)
363
- return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.common.required}`));
364
+ return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
364
365
  }
365
366
  });
366
367
  else
367
368
  propsCopy.rules.push({
368
369
  required: true,
369
- message: `${propsCopy.label || propsCopy.title} ${config.common.required}`
370
+ message: `${propsCopy.label || propsCopy.title} ${config.required}`
370
371
  });
371
372
  }
372
373
  if (!propsCopy.input)
@@ -393,8 +394,8 @@ function FormItem(props) {
393
394
  var _a;
394
395
  const [computedProps, setComputedProps] = useState4();
395
396
  const [extendTypes, setExtendTypes] = useState4();
396
- const config = useConfigContext();
397
- const [hidden, setHidden] = useState4(false);
397
+ const { common: common2 } = useConfigContext();
398
+ const [hidden, setHidden] = useState4(props.hidden || false);
398
399
  useEffect3(() => {
399
400
  const propsCopy = { ...props };
400
401
  if (propsCopy.extendTypes) {
@@ -403,14 +404,18 @@ function FormItem(props) {
403
404
  }
404
405
  if (propsCopy.if) {
405
406
  const condition = propsCopy.if;
406
- propsCopy.shouldUpdate = (_, cur) => {
407
+ const originShouldUpdate = propsCopy.shouldUpdate;
408
+ propsCopy.shouldUpdate = (prev, cur) => {
407
409
  const show = condition(cur);
410
+ const shouldUpdate = hidden !== show;
408
411
  setHidden(!show);
409
- return show;
412
+ const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
413
+ return shouldUpdate || origin;
410
414
  };
411
415
  delete propsCopy.if;
416
+ delete propsCopy.hidden;
412
417
  }
413
- setComputedProps(processProps(propsCopy, config));
418
+ setComputedProps(processProps(propsCopy, common2));
414
419
  }, [props]);
415
420
  if (!computedProps)
416
421
  return null;
@@ -657,7 +662,7 @@ function FormItem(props) {
657
662
  danger: true,
658
663
  type: "link",
659
664
  onClick: () => remove(field.name),
660
- children: config.common.delete
665
+ children: common2.delete
661
666
  })
662
667
  ]
663
668
  })
@@ -682,7 +687,7 @@ function FormItem(props) {
682
687
  onClick: () => add(),
683
688
  icon: /* @__PURE__ */ jsx5(PlusOutlined, {}),
684
689
  children: [
685
- config.common.add,
690
+ common2.add,
686
691
  " ",
687
692
  computedProps.label
688
693
  ]
@@ -717,11 +722,19 @@ function Form(props) {
717
722
  form
718
723
  };
719
724
  if (propsCopy.initialValues) {
720
- for (const key in propsCopy.initialValues)
725
+ for (const key in propsCopy.initialValues) {
721
726
  propsCopy.initialValues[key] = transferValue(
722
- (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
727
+ (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
723
728
  propsCopy.initialValues[key]
724
729
  );
730
+ const item = propsCopy.items.find((item2) => item2.id === key);
731
+ if (item == null ? void 0 : item.if)
732
+ item.hidden = !item.if(propsCopy.initialValues);
733
+ }
734
+ for (const item of propsCopy.items) {
735
+ if (item.if)
736
+ item.hidden = !item.if(propsCopy.initialValues);
737
+ }
725
738
  setInitialValues(propsCopy.initialValues);
726
739
  delete propsCopy.initialValues;
727
740
  }
@@ -758,6 +771,7 @@ function Form(props) {
758
771
  setComputedProps(propsCopy);
759
772
  }, [props]);
760
773
  const onValuesChange = useCallback((changedValues, allValues) => {
774
+ console.debug("Form:onValuesChange", changedValues, allValues);
761
775
  if (props.onValuesChange) {
762
776
  props.onValuesChange(changedValues, allValues);
763
777
  }
@@ -772,6 +786,7 @@ function Form(props) {
772
786
  useEffect4(() => {
773
787
  if (!initialValues)
774
788
  return;
789
+ console.debug("Form:initialValues", initialValues);
775
790
  form.setFieldsValue(initialValues);
776
791
  setInitialValues(null);
777
792
  }, [computedProps]);
@@ -782,7 +797,7 @@ function Form(props) {
782
797
  onValuesChange,
783
798
  children: [
784
799
  computedProps.beforeItems,
785
- (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ jsx6(FormItem, {
800
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => isValidElement(item) ? item : /* @__PURE__ */ jsx6(FormItem, {
786
801
  ...item,
787
802
  extendTypes
788
803
  }, item.id)),
@@ -938,7 +953,8 @@ import {
938
953
  Table as AntdTable,
939
954
  Radio,
940
955
  Skeleton as Skeleton3,
941
- Input as Input2
956
+ Input as Input2,
957
+ ConfigProvider as ConfigProvider2
942
958
  } from "antd";
943
959
  import dayjs2 from "dayjs";
944
960
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
@@ -946,7 +962,7 @@ import {
946
962
  isNil as isNil2,
947
963
  uniqBy,
948
964
  upperFirst as upperFirst4
949
- } from "lodash";
965
+ } from "lodash-es";
950
966
  import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
951
967
  import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
952
968
  function processValue(item, value) {
@@ -975,7 +991,7 @@ function processValue(item, value) {
975
991
  }
976
992
  function Table(props) {
977
993
  const [columns, setColumns] = useState7();
978
- const { common: common2 } = useConfigContext();
994
+ const { common: common2, antd } = useConfigContext();
979
995
  useEffect5(() => {
980
996
  var _a;
981
997
  for (const item of props.items) {
@@ -1017,6 +1033,8 @@ function Table(props) {
1017
1033
  item.render = (value) => processValue(item, value);
1018
1034
  if (!item.onFilter)
1019
1035
  item.onFilter = (value, row) => {
1036
+ if (value === null && isNil2(row[item.id]))
1037
+ return true;
1020
1038
  if (!row[item.id])
1021
1039
  return false;
1022
1040
  return row[item.id].toLowerCase().includes(value.toLowerCase());
@@ -1045,6 +1063,8 @@ function Table(props) {
1045
1063
  item.render = (value) => processValue(item, value);
1046
1064
  if (!item.onFilter)
1047
1065
  item.onFilter = (value, row) => {
1066
+ if (value === null && (!row[item.id] || !row[item.id].length))
1067
+ return true;
1048
1068
  if (!row[item.id] || !row[item.id].length)
1049
1069
  return false;
1050
1070
  return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
@@ -1074,7 +1094,11 @@ function Table(props) {
1074
1094
  if (!item.sorter)
1075
1095
  item.sorter = (a, b) => a[item.id] - b[item.id];
1076
1096
  if (!item.onFilter)
1077
- item.onFilter = (value, row) => value === row[item.id];
1097
+ item.onFilter = (value, row) => {
1098
+ if (value === null && isNil2(row[item.id]))
1099
+ return true;
1100
+ return value === row[item.id];
1101
+ };
1078
1102
  if (!item.filters && item.filterDropdown !== false)
1079
1103
  item.filterDropdown = ({
1080
1104
  setSelectedKeys,
@@ -1098,7 +1122,13 @@ function Table(props) {
1098
1122
  if (!item.render)
1099
1123
  item.render = (value) => processValue(item, value).join(", ");
1100
1124
  if (!item.onFilter)
1101
- item.onFilter = (value, row) => row[item.id].includes(value);
1125
+ item.onFilter = (value, row) => {
1126
+ if (value === null && (!row[item.id] || !row[item.id].length))
1127
+ return true;
1128
+ if (!row[item.id] || !row[item.id].length)
1129
+ return false;
1130
+ return row[item.id].includes(value);
1131
+ };
1102
1132
  if (!item.filters && item.filterDropdown !== false)
1103
1133
  item.filterDropdown = ({
1104
1134
  setSelectedKeys,
@@ -1222,7 +1252,11 @@ function Table(props) {
1222
1252
  if (!item.render)
1223
1253
  item.render = (value) => processValue(item, value);
1224
1254
  if (!item.onFilter)
1225
- item.onFilter = (value, row) => value === row[item.id];
1255
+ item.onFilter = (value, row) => {
1256
+ if (value === null && isNil2(row[item.id]))
1257
+ return true;
1258
+ return value === row[item.id];
1259
+ };
1226
1260
  break;
1227
1261
  }
1228
1262
  }
@@ -1239,7 +1273,10 @@ function Table(props) {
1239
1273
  newColumns[index].filters = uniqBy(props.dataSource, column.id).map((v) => ({
1240
1274
  text: v[column.id],
1241
1275
  value: v[column.id]
1242
- }));
1276
+ })).concat({
1277
+ text: /* @__PURE__ */ jsx10(Blank, {}),
1278
+ value: null
1279
+ });
1243
1280
  return newColumns;
1244
1281
  });
1245
1282
  }
@@ -1248,11 +1285,14 @@ function Table(props) {
1248
1285
  if (!columns)
1249
1286
  return null;
1250
1287
  if (!props.faasData)
1251
- return /* @__PURE__ */ jsx10(AntdTable, {
1252
- ...props,
1253
- rowKey: props.rowKey || "id",
1254
- columns,
1255
- dataSource: props.dataSource
1288
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1289
+ ...antd,
1290
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1291
+ ...props,
1292
+ rowKey: props.rowKey || "id",
1293
+ columns,
1294
+ dataSource: props.dataSource
1295
+ })
1256
1296
  });
1257
1297
  return /* @__PURE__ */ jsx10(FaasDataWrapper2, {
1258
1298
  fallback: props.faasData.fallback || /* @__PURE__ */ jsx10(Skeleton3, {
@@ -1264,46 +1304,55 @@ function Table(props) {
1264
1304
  reload
1265
1305
  }) => {
1266
1306
  if (!data)
1267
- return /* @__PURE__ */ jsx10(AntdTable, {
1268
- ...props,
1269
- rowKey: props.rowKey || "id",
1270
- columns,
1271
- dataSource: []
1307
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1308
+ ...antd,
1309
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1310
+ ...props,
1311
+ rowKey: props.rowKey || "id",
1312
+ columns,
1313
+ dataSource: []
1314
+ })
1272
1315
  });
1273
1316
  if (Array.isArray(data))
1274
- return /* @__PURE__ */ jsx10(AntdTable, {
1317
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1318
+ ...antd,
1319
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1320
+ ...props,
1321
+ rowKey: props.rowKey || "id",
1322
+ columns,
1323
+ dataSource: data
1324
+ })
1325
+ });
1326
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1327
+ ...antd,
1328
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1275
1329
  ...props,
1276
1330
  rowKey: props.rowKey || "id",
1277
1331
  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);
1332
+ dataSource: data.rows,
1333
+ pagination: {
1334
+ ...props.pagination,
1335
+ ...data.pagination
1336
+ },
1337
+ onChange: (pagination, filters, sorter, extra) => {
1338
+ if (props.onChange) {
1339
+ const processed = props.onChange(pagination, filters, sorter, extra);
1340
+ reload({
1341
+ ...params,
1342
+ pagination: processed.pagination,
1343
+ filters: processed.filters,
1344
+ sorter: processed.sorter
1345
+ });
1346
+ return;
1347
+ }
1292
1348
  reload({
1293
1349
  ...params,
1294
- pagination: processed.pagination,
1295
- filters: processed.filters,
1296
- sorter: processed.sorter
1350
+ pagination,
1351
+ filters,
1352
+ sorter
1297
1353
  });
1298
- return;
1299
1354
  }
1300
- reload({
1301
- ...params,
1302
- pagination,
1303
- filters,
1304
- sorter
1305
- });
1306
- }
1355
+ })
1307
1356
  });
1308
1357
  },
1309
1358
  ...props.faasData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.3-beta.1",
3
+ "version": "0.0.3-beta.10",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,15 +25,15 @@
25
25
  "dependencies": {
26
26
  "@ant-design/icons": "*",
27
27
  "antd": "*",
28
- "lodash": "*",
28
+ "lodash-es": "*",
29
29
  "react": "*",
30
30
  "react-dom": "*",
31
- "@faasjs/react": "^0.0.3-beta.1",
31
+ "@faasjs/react": "^0.0.3-beta.10",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/lodash": "*",
36
+ "@types/lodash-es": "*",
37
37
  "@testing-library/jest-dom": "*",
38
38
  "@testing-library/react": "*",
39
39
  "@testing-library/user-event": "*"