@faasjs/ant-design 0.0.3-beta.3 → 0.0.3-beta.5

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
@@ -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) {
@@ -425,7 +425,7 @@ function FormItem(props) {
425
425
  };
426
426
  delete propsCopy.if;
427
427
  }
428
- setComputedProps(processProps(propsCopy, config));
428
+ setComputedProps(processProps(propsCopy, common2));
429
429
  }, [props]);
430
430
  if (!computedProps)
431
431
  return null;
@@ -672,7 +672,7 @@ function FormItem(props) {
672
672
  danger: true,
673
673
  type: "link",
674
674
  onClick: () => remove(field.name),
675
- children: config.common.delete
675
+ children: common2.delete
676
676
  })
677
677
  ]
678
678
  })
@@ -697,7 +697,7 @@ function FormItem(props) {
697
697
  onClick: () => add(),
698
698
  icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
699
699
  children: [
700
- config.common.add,
700
+ common2.add,
701
701
  " ",
702
702
  computedProps.label
703
703
  ]
@@ -732,11 +732,19 @@ function Form(props) {
732
732
  form
733
733
  };
734
734
  if (propsCopy.initialValues) {
735
- for (const key in propsCopy.initialValues)
735
+ for (const key in propsCopy.initialValues) {
736
736
  propsCopy.initialValues[key] = transferValue(
737
- (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
737
+ (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
738
738
  propsCopy.initialValues[key]
739
739
  );
740
+ const item = propsCopy.items.find((item2) => item2.id === key);
741
+ if (item == null ? void 0 : item.if)
742
+ item.hidden = !item.if(propsCopy.initialValues);
743
+ }
744
+ for (const item of propsCopy.items) {
745
+ if (item.if)
746
+ item.hidden = !item.if(propsCopy.initialValues);
747
+ }
740
748
  setInitialValues(propsCopy.initialValues);
741
749
  delete propsCopy.initialValues;
742
750
  }
@@ -773,6 +781,7 @@ function Form(props) {
773
781
  setComputedProps(propsCopy);
774
782
  }, [props]);
775
783
  const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
784
+ console.debug("Form:onValuesChange", changedValues, allValues);
776
785
  if (props.onValuesChange) {
777
786
  props.onValuesChange(changedValues, allValues);
778
787
  }
@@ -787,6 +796,7 @@ function Form(props) {
787
796
  (0, import_react8.useEffect)(() => {
788
797
  if (!initialValues)
789
798
  return;
799
+ console.debug("Form:initialValues", initialValues);
790
800
  form.setFieldsValue(initialValues);
791
801
  setInitialValues(null);
792
802
  }, [computedProps]);
@@ -797,7 +807,7 @@ function Form(props) {
797
807
  onValuesChange,
798
808
  children: [
799
809
  computedProps.beforeItems,
800
- (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
810
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => (0, import_react8.isValidElement)(item) ? item : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
801
811
  ...item,
802
812
  extendTypes
803
813
  }, item.id)),
@@ -972,7 +982,7 @@ function processValue(item, value) {
972
982
  }
973
983
  function Table(props) {
974
984
  const [columns, setColumns] = (0, import_react11.useState)();
975
- const { common: common2 } = useConfigContext();
985
+ const { common: common2, antd } = useConfigContext();
976
986
  (0, import_react11.useEffect)(() => {
977
987
  var _a;
978
988
  for (const item of props.items) {
@@ -1266,11 +1276,14 @@ function Table(props) {
1266
1276
  if (!columns)
1267
1277
  return null;
1268
1278
  if (!props.faasData)
1269
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1270
- ...props,
1271
- rowKey: props.rowKey || "id",
1272
- columns,
1273
- dataSource: props.dataSource
1279
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1280
+ ...antd,
1281
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1282
+ ...props,
1283
+ rowKey: props.rowKey || "id",
1284
+ columns,
1285
+ dataSource: props.dataSource
1286
+ })
1274
1287
  });
1275
1288
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react12.FaasDataWrapper, {
1276
1289
  fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Skeleton, {
@@ -1282,46 +1295,55 @@ function Table(props) {
1282
1295
  reload
1283
1296
  }) => {
1284
1297
  if (!data)
1285
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1286
- ...props,
1287
- rowKey: props.rowKey || "id",
1288
- columns,
1289
- dataSource: []
1298
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1299
+ ...antd,
1300
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1301
+ ...props,
1302
+ rowKey: props.rowKey || "id",
1303
+ columns,
1304
+ dataSource: []
1305
+ })
1290
1306
  });
1291
1307
  if (Array.isArray(data))
1292
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1308
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1309
+ ...antd,
1310
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1311
+ ...props,
1312
+ rowKey: props.rowKey || "id",
1313
+ columns,
1314
+ dataSource: data
1315
+ })
1316
+ });
1317
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
1318
+ ...antd,
1319
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1293
1320
  ...props,
1294
1321
  rowKey: props.rowKey || "id",
1295
1322
  columns,
1296
- dataSource: data
1297
- });
1298
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1299
- ...props,
1300
- rowKey: props.rowKey || "id",
1301
- columns,
1302
- dataSource: data.rows,
1303
- pagination: {
1304
- ...props.pagination,
1305
- ...data.pagination
1306
- },
1307
- onChange: (pagination, filters, sorter, extra) => {
1308
- if (props.onChange) {
1309
- const processed = props.onChange(pagination, filters, sorter, extra);
1323
+ dataSource: data.rows,
1324
+ pagination: {
1325
+ ...props.pagination,
1326
+ ...data.pagination
1327
+ },
1328
+ onChange: (pagination, filters, sorter, extra) => {
1329
+ if (props.onChange) {
1330
+ const processed = props.onChange(pagination, filters, sorter, extra);
1331
+ reload({
1332
+ ...params,
1333
+ pagination: processed.pagination,
1334
+ filters: processed.filters,
1335
+ sorter: processed.sorter
1336
+ });
1337
+ return;
1338
+ }
1310
1339
  reload({
1311
1340
  ...params,
1312
- pagination: processed.pagination,
1313
- filters: processed.filters,
1314
- sorter: processed.sorter
1341
+ pagination,
1342
+ filters,
1343
+ sorter
1315
1344
  });
1316
- return;
1317
1345
  }
1318
- reload({
1319
- ...params,
1320
- pagination,
1321
- filters,
1322
- sorter
1323
- });
1324
- }
1346
+ })
1325
1347
  });
1326
1348
  },
1327
1349
  ...props.faasData
package/dist/index.mjs CHANGED
@@ -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
@@ -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) {
@@ -410,7 +411,7 @@ function FormItem(props) {
410
411
  };
411
412
  delete propsCopy.if;
412
413
  }
413
- setComputedProps(processProps(propsCopy, config));
414
+ setComputedProps(processProps(propsCopy, common2));
414
415
  }, [props]);
415
416
  if (!computedProps)
416
417
  return null;
@@ -657,7 +658,7 @@ function FormItem(props) {
657
658
  danger: true,
658
659
  type: "link",
659
660
  onClick: () => remove(field.name),
660
- children: config.common.delete
661
+ children: common2.delete
661
662
  })
662
663
  ]
663
664
  })
@@ -682,7 +683,7 @@ function FormItem(props) {
682
683
  onClick: () => add(),
683
684
  icon: /* @__PURE__ */ jsx5(PlusOutlined, {}),
684
685
  children: [
685
- config.common.add,
686
+ common2.add,
686
687
  " ",
687
688
  computedProps.label
688
689
  ]
@@ -717,11 +718,19 @@ function Form(props) {
717
718
  form
718
719
  };
719
720
  if (propsCopy.initialValues) {
720
- for (const key in propsCopy.initialValues)
721
+ for (const key in propsCopy.initialValues) {
721
722
  propsCopy.initialValues[key] = transferValue(
722
- (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
723
+ (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
723
724
  propsCopy.initialValues[key]
724
725
  );
726
+ const item = propsCopy.items.find((item2) => item2.id === key);
727
+ if (item == null ? void 0 : item.if)
728
+ item.hidden = !item.if(propsCopy.initialValues);
729
+ }
730
+ for (const item of propsCopy.items) {
731
+ if (item.if)
732
+ item.hidden = !item.if(propsCopy.initialValues);
733
+ }
725
734
  setInitialValues(propsCopy.initialValues);
726
735
  delete propsCopy.initialValues;
727
736
  }
@@ -758,6 +767,7 @@ function Form(props) {
758
767
  setComputedProps(propsCopy);
759
768
  }, [props]);
760
769
  const onValuesChange = useCallback((changedValues, allValues) => {
770
+ console.debug("Form:onValuesChange", changedValues, allValues);
761
771
  if (props.onValuesChange) {
762
772
  props.onValuesChange(changedValues, allValues);
763
773
  }
@@ -772,6 +782,7 @@ function Form(props) {
772
782
  useEffect4(() => {
773
783
  if (!initialValues)
774
784
  return;
785
+ console.debug("Form:initialValues", initialValues);
775
786
  form.setFieldsValue(initialValues);
776
787
  setInitialValues(null);
777
788
  }, [computedProps]);
@@ -782,7 +793,7 @@ function Form(props) {
782
793
  onValuesChange,
783
794
  children: [
784
795
  computedProps.beforeItems,
785
- (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ jsx6(FormItem, {
796
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => isValidElement(item) ? item : /* @__PURE__ */ jsx6(FormItem, {
786
797
  ...item,
787
798
  extendTypes
788
799
  }, item.id)),
@@ -938,7 +949,8 @@ import {
938
949
  Table as AntdTable,
939
950
  Radio,
940
951
  Skeleton as Skeleton3,
941
- Input as Input2
952
+ Input as Input2,
953
+ ConfigProvider as ConfigProvider2
942
954
  } from "antd";
943
955
  import dayjs2 from "dayjs";
944
956
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
@@ -975,7 +987,7 @@ function processValue(item, value) {
975
987
  }
976
988
  function Table(props) {
977
989
  const [columns, setColumns] = useState7();
978
- const { common: common2 } = useConfigContext();
990
+ const { common: common2, antd } = useConfigContext();
979
991
  useEffect5(() => {
980
992
  var _a;
981
993
  for (const item of props.items) {
@@ -1269,11 +1281,14 @@ function Table(props) {
1269
1281
  if (!columns)
1270
1282
  return null;
1271
1283
  if (!props.faasData)
1272
- return /* @__PURE__ */ jsx10(AntdTable, {
1273
- ...props,
1274
- rowKey: props.rowKey || "id",
1275
- columns,
1276
- dataSource: props.dataSource
1284
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1285
+ ...antd,
1286
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1287
+ ...props,
1288
+ rowKey: props.rowKey || "id",
1289
+ columns,
1290
+ dataSource: props.dataSource
1291
+ })
1277
1292
  });
1278
1293
  return /* @__PURE__ */ jsx10(FaasDataWrapper2, {
1279
1294
  fallback: props.faasData.fallback || /* @__PURE__ */ jsx10(Skeleton3, {
@@ -1285,46 +1300,55 @@ function Table(props) {
1285
1300
  reload
1286
1301
  }) => {
1287
1302
  if (!data)
1288
- return /* @__PURE__ */ jsx10(AntdTable, {
1289
- ...props,
1290
- rowKey: props.rowKey || "id",
1291
- columns,
1292
- dataSource: []
1303
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1304
+ ...antd,
1305
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1306
+ ...props,
1307
+ rowKey: props.rowKey || "id",
1308
+ columns,
1309
+ dataSource: []
1310
+ })
1293
1311
  });
1294
1312
  if (Array.isArray(data))
1295
- return /* @__PURE__ */ jsx10(AntdTable, {
1313
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1314
+ ...antd,
1315
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1316
+ ...props,
1317
+ rowKey: props.rowKey || "id",
1318
+ columns,
1319
+ dataSource: data
1320
+ })
1321
+ });
1322
+ return /* @__PURE__ */ jsx10(ConfigProvider2, {
1323
+ ...antd,
1324
+ children: /* @__PURE__ */ jsx10(AntdTable, {
1296
1325
  ...props,
1297
1326
  rowKey: props.rowKey || "id",
1298
1327
  columns,
1299
- dataSource: data
1300
- });
1301
- return /* @__PURE__ */ jsx10(AntdTable, {
1302
- ...props,
1303
- rowKey: props.rowKey || "id",
1304
- columns,
1305
- dataSource: data.rows,
1306
- pagination: {
1307
- ...props.pagination,
1308
- ...data.pagination
1309
- },
1310
- onChange: (pagination, filters, sorter, extra) => {
1311
- if (props.onChange) {
1312
- const processed = props.onChange(pagination, filters, sorter, extra);
1328
+ dataSource: data.rows,
1329
+ pagination: {
1330
+ ...props.pagination,
1331
+ ...data.pagination
1332
+ },
1333
+ onChange: (pagination, filters, sorter, extra) => {
1334
+ if (props.onChange) {
1335
+ const processed = props.onChange(pagination, filters, sorter, extra);
1336
+ reload({
1337
+ ...params,
1338
+ pagination: processed.pagination,
1339
+ filters: processed.filters,
1340
+ sorter: processed.sorter
1341
+ });
1342
+ return;
1343
+ }
1313
1344
  reload({
1314
1345
  ...params,
1315
- pagination: processed.pagination,
1316
- filters: processed.filters,
1317
- sorter: processed.sorter
1346
+ pagination,
1347
+ filters,
1348
+ sorter
1318
1349
  });
1319
- return;
1320
1350
  }
1321
- reload({
1322
- ...params,
1323
- pagination,
1324
- filters,
1325
- sorter
1326
- });
1327
- }
1351
+ })
1328
1352
  });
1329
1353
  },
1330
1354
  ...props.faasData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.3-beta.3",
3
+ "version": "0.0.3-beta.5",
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.3",
31
+ "@faasjs/react": "^0.0.3-beta.5",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },