@faasjs/ant-design 0.0.3-beta.27 → 0.0.3-beta.29

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 CHANGED
@@ -42,6 +42,7 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
42
42
  ### Namespaces
43
43
 
44
44
  - [Form](modules/Form.md)
45
+ - [FormItem](modules/FormItem.md)
45
46
 
46
47
  ### Interfaces
47
48
 
@@ -75,6 +76,7 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
75
76
  - [FaasDataWrapperProps](#faasdatawrapperprops)
76
77
  - [FaasItemType](#faasitemtype)
77
78
  - [FaasItemTypeValue](#faasitemtypevalue)
79
+ - [FormSubmitProps](#formsubmitprops)
78
80
  - [TableProps](#tableprops)
79
81
  - [setDrawerProps](#setdrawerprops)
80
82
  - [setModalProps](#setmodalprops)
@@ -253,6 +255,24 @@ FaasItemType's value type
253
255
 
254
256
  ___
255
257
 
258
+ ### FormSubmitProps
259
+
260
+ Ƭ **FormSubmitProps**: `Object`
261
+
262
+ #### Type declaration
263
+
264
+ | Name | Type | Description |
265
+ | :------ | :------ | :------ |
266
+ | `text?` | `string` | Default: Submit |
267
+ | `to?` | { `action`: `string` ; `catch?`: (`error`: `any`) => `void` ; `finally?`: () => `void` ; `params?`: `Record`<`string`, `any`\> ; `then?`: (`result`: `any`) => `void` } | Submit to FaasJS server. If use onFinish, you should call submit manually. ```ts { submit: { to: { action: 'action_name' } }, onFinish: (values, submit) => { // do something before submit // submit await submit({ ...values, extraProps: 'some extra props' }) // do something after submit } } ``` |
268
+ | `to.action` | `string` | - |
269
+ | `to.catch?` | (`error`: `any`) => `void` | - |
270
+ | `to.finally?` | () => `void` | - |
271
+ | `to.params?` | `Record`<`string`, `any`\> | params will overwrite form values before submit |
272
+ | `to.then?` | (`result`: `any`) => `void` | - |
273
+
274
+ ___
275
+
256
276
  ### TableProps
257
277
 
258
278
  Ƭ **TableProps**<`T`, `ExtendTypes`\>: { `extendTypes?`: { `[key: string]`: [`ExtendTableTypeProps`](#extendtabletypeprops); } ; `faasData?`: [`FaasDataWrapperProps`](#faasdatawrapperprops)<`T`\> ; `items`: ([`TableItemProps`](interfaces/TableItemProps.md) \| `ExtendTypes` & [`ExtendTableItemProps`](#extendtableitemprops))[] ; `onChange?`: (`pagination`: `TablePaginationConfig`, `filters`: `Record`<`string`, `FilterValue` \| ``null``\>, `sorter`: `SorterResult`<`T`\> \| `SorterResult`<`T`\>[], `extra`: `TableCurrentDataSource`<`T`\>) => { `extra`: `TableCurrentDataSource`<`T`\> ; `filters`: `Record`<`string`, `FilterValue` \| ``null``\> ; `pagination`: `TablePaginationConfig` ; `sorter`: `SorterResult`<`T`\> \| `SorterResult`<`T`\>[] } } & `AntdTableProps`<`T`\>
@@ -513,7 +533,7 @@ Loading component based on Spin
513
533
  | Name | Type |
514
534
  | :------ | :------ |
515
535
  | `props` | `Object` |
516
- | `props.size?` | ``"small"`` \| ``"default"`` \| ``"large"`` |
536
+ | `props.size?` | ``"default"`` \| ``"small"`` \| ``"large"`` |
517
537
  | `props.style?` | `CSSProperties` |
518
538
 
519
539
  #### Returns
package/dist/index.d.ts CHANGED
@@ -232,43 +232,47 @@ declare namespace FormItem {
232
232
  };
233
233
  }
234
234
 
235
+ type FormSubmitProps = {
236
+ /** Default: Submit */
237
+ text?: string;
238
+ /**
239
+ * Submit to FaasJS server.
240
+ *
241
+ * If use onFinish, you should call submit manually.
242
+ * ```ts
243
+ * {
244
+ * submit: {
245
+ * to: {
246
+ * action: 'action_name'
247
+ * }
248
+ * },
249
+ * onFinish: (values, submit) => {
250
+ * // do something before submit
251
+ *
252
+ * // submit
253
+ * await submit({
254
+ * ...values,
255
+ * extraProps: 'some extra props'
256
+ * })
257
+ *
258
+ * // do something after submit
259
+ * }
260
+ * }
261
+ * ```
262
+ */
263
+ to?: {
264
+ action: string;
265
+ /** params will overwrite form values before submit */
266
+ params?: Record<string, any>;
267
+ then?: (result: any) => void;
268
+ catch?: (error: any) => void;
269
+ finally?: () => void;
270
+ };
271
+ };
235
272
  interface FormProps<Values extends Record<string, any> = any, ExtendItemProps = any> extends Omit<FormProps$1<Values>, 'onFinish' | 'children' | 'initialValues'> {
236
273
  items?: (FormItemProps | ExtendItemProps | JSX.Element)[];
237
274
  /** Default: { text: 'Submit' }, set false to disable it */
238
- submit?: false | {
239
- /** Default: Submit */
240
- text?: string;
241
- /**
242
- * Submit to FaasJS server.
243
- *
244
- * If use onFinish, you should call submit manually.
245
- * ```ts
246
- * {
247
- * submit: {
248
- * to: {
249
- * action: 'action_name'
250
- * }
251
- * },
252
- * onFinish: (values, submit) => {
253
- * // do something before submit
254
- *
255
- * // submit
256
- * await submit({
257
- * ...values,
258
- * extraProps: 'some extra props'
259
- * })
260
- *
261
- * // do something after submit
262
- * }
263
- * }
264
- * ```
265
- */
266
- to?: {
267
- action: string;
268
- /** params will overwrite form values before submit */
269
- params?: Record<string, any>;
270
- };
271
- };
275
+ submit?: false | FormSubmitProps;
272
276
  onFinish?: (values: Values, submit?: (values: any) => Promise<any>) => Promise<any>;
273
277
  beforeItems?: JSX.Element | JSX.Element[];
274
278
  footer?: JSX.Element | JSX.Element[];
@@ -438,4 +442,4 @@ interface TitleProps {
438
442
  */
439
443
  declare function Title(props: TitleProps): JSX.Element;
440
444
 
441
- export { BaseItemProps, BaseOption, Blank, BlankProps, ConfigContext, ConfigProvider, ConfigProviderProps, Description, DescriptionItemContentProps, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasDataWrapper, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Link, LinkProps, Loading, ModalProps, PageNotFound, Routes, RoutesProps, Table, TableItemProps, TableProps, Title, TitleProps, setDrawerProps, setModalProps, transferOptions, transferValue, useConfigContext, useDrawer, useModal };
445
+ export { BaseItemProps, BaseOption, Blank, BlankProps, ConfigContext, ConfigProvider, ConfigProviderProps, Description, DescriptionItemContentProps, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasDataWrapper, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, FormSubmitProps, Link, LinkProps, Loading, ModalProps, PageNotFound, Routes, RoutesProps, Table, TableItemProps, TableProps, Title, TitleProps, setDrawerProps, setModalProps, transferOptions, transferValue, useConfigContext, useDrawer, useModal };
package/dist/index.js CHANGED
@@ -31,9 +31,7 @@ __export(src_exports, {
31
31
  ConfigProvider: () => ConfigProvider,
32
32
  Description: () => Description,
33
33
  Drawer: () => import_antd5.Drawer,
34
- FaasDataInjection: () => import_react3.FaasDataInjection,
35
34
  FaasDataWrapper: () => FaasDataWrapper,
36
- FaasDataWrapperProps: () => import_react3.FaasDataWrapperProps,
37
35
  Form: () => Form,
38
36
  FormItem: () => FormItem,
39
37
  Link: () => Link,
@@ -768,15 +766,15 @@ function Form(props) {
768
766
  const [form] = import_antd7.Form.useForm(props.form);
769
767
  const [initialValues, setInitialValues] = (0, import_react8.useState)(props.initialValues);
770
768
  (0, import_react8.useEffect)(() => {
771
- var _a2, _b2;
769
+ var _a2, _b2, _c;
772
770
  const propsCopy = {
773
771
  ...props,
774
772
  form
775
773
  };
776
- if (propsCopy.initialValues) {
774
+ if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
777
775
  for (const key in propsCopy.initialValues) {
778
776
  propsCopy.initialValues[key] = transferValue(
779
- (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
777
+ (_b2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _b2.type,
780
778
  propsCopy.initialValues[key]
781
779
  );
782
780
  const item = propsCopy.items.find((item2) => item2.id === key);
@@ -807,13 +805,25 @@ function Form(props) {
807
805
  }
808
806
  setLoading(false);
809
807
  };
810
- } else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
808
+ } else if (propsCopy.submit && ((_c = propsCopy.submit.to) == null ? void 0 : _c.action)) {
811
809
  propsCopy.onFinish = async (values) => {
812
810
  setLoading(true);
813
811
  return (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
814
812
  ...values,
815
813
  ...propsCopy.submit.to.params
816
- } : values).finally(() => setLoading(false));
814
+ } : values).then((result) => {
815
+ if (propsCopy.submit.to.then)
816
+ propsCopy.submit.to.then(result);
817
+ return result;
818
+ }).catch((error) => {
819
+ if (propsCopy.submit.to.catch)
820
+ propsCopy.submit.to.catch(error);
821
+ return Promise.reject(error);
822
+ }).finally(() => {
823
+ if (propsCopy.submit.to.finally)
824
+ propsCopy.submit.to.finally();
825
+ setLoading(false);
826
+ });
817
827
  };
818
828
  }
819
829
  if (propsCopy.extendTypes) {
@@ -1473,9 +1483,7 @@ function Title(props) {
1473
1483
  ConfigProvider,
1474
1484
  Description,
1475
1485
  Drawer,
1476
- FaasDataInjection,
1477
1486
  FaasDataWrapper,
1478
- FaasDataWrapperProps,
1479
1487
  Form,
1480
1488
  FormItem,
1481
1489
  Link,
package/dist/index.mjs CHANGED
@@ -130,11 +130,7 @@ import {
130
130
  } from "react";
131
131
 
132
132
  // src/FaasDataWrapper.tsx
133
- import {
134
- FaasDataWrapper as Origin,
135
- FaasDataWrapperProps,
136
- FaasDataInjection
137
- } from "@faasjs/react";
133
+ import { FaasDataWrapper as Origin } from "@faasjs/react";
138
134
 
139
135
  // src/Loading.tsx
140
136
  import { Spin } from "antd";
@@ -754,15 +750,15 @@ function Form(props) {
754
750
  const [form] = AntdForm2.useForm(props.form);
755
751
  const [initialValues, setInitialValues] = useState5(props.initialValues);
756
752
  useEffect4(() => {
757
- var _a2, _b2;
753
+ var _a2, _b2, _c;
758
754
  const propsCopy = {
759
755
  ...props,
760
756
  form
761
757
  };
762
- if (propsCopy.initialValues) {
758
+ if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
763
759
  for (const key in propsCopy.initialValues) {
764
760
  propsCopy.initialValues[key] = transferValue(
765
- (_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
761
+ (_b2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _b2.type,
766
762
  propsCopy.initialValues[key]
767
763
  );
768
764
  const item = propsCopy.items.find((item2) => item2.id === key);
@@ -793,13 +789,25 @@ function Form(props) {
793
789
  }
794
790
  setLoading(false);
795
791
  };
796
- } else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
792
+ } else if (propsCopy.submit && ((_c = propsCopy.submit.to) == null ? void 0 : _c.action)) {
797
793
  propsCopy.onFinish = async (values) => {
798
794
  setLoading(true);
799
795
  return faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
800
796
  ...values,
801
797
  ...propsCopy.submit.to.params
802
- } : values).finally(() => setLoading(false));
798
+ } : values).then((result) => {
799
+ if (propsCopy.submit.to.then)
800
+ propsCopy.submit.to.then(result);
801
+ return result;
802
+ }).catch((error) => {
803
+ if (propsCopy.submit.to.catch)
804
+ propsCopy.submit.to.catch(error);
805
+ return Promise.reject(error);
806
+ }).finally(() => {
807
+ if (propsCopy.submit.to.finally)
808
+ propsCopy.submit.to.finally();
809
+ setLoading(false);
810
+ });
803
811
  };
804
812
  }
805
813
  if (propsCopy.extendTypes) {
@@ -1480,9 +1488,7 @@ export {
1480
1488
  ConfigProvider,
1481
1489
  Description,
1482
1490
  Drawer,
1483
- FaasDataInjection,
1484
1491
  FaasDataWrapper,
1485
- FaasDataWrapperProps,
1486
1492
  Form,
1487
1493
  FormItem,
1488
1494
  Link,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.3-beta.27",
3
+ "version": "0.0.3-beta.29",
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.27",
31
+ "@faasjs/react": "^0.0.3-beta.29",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },