@faasjs/ant-design 0.0.3-beta.28 → 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
@@ -769,8 +769,7 @@ function Form(props) {
769
769
  var _a2, _b2, _c;
770
770
  const propsCopy = {
771
771
  ...props,
772
- form,
773
- items: props.items
772
+ form
774
773
  };
775
774
  if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
776
775
  for (const key in propsCopy.initialValues) {
@@ -812,7 +811,19 @@ function Form(props) {
812
811
  return (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
813
812
  ...values,
814
813
  ...propsCopy.submit.to.params
815
- } : 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
+ });
816
827
  };
817
828
  }
818
829
  if (propsCopy.extendTypes) {
package/dist/index.mjs CHANGED
@@ -753,8 +753,7 @@ function Form(props) {
753
753
  var _a2, _b2, _c;
754
754
  const propsCopy = {
755
755
  ...props,
756
- form,
757
- items: props.items
756
+ form
758
757
  };
759
758
  if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
760
759
  for (const key in propsCopy.initialValues) {
@@ -796,7 +795,19 @@ function Form(props) {
796
795
  return faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
797
796
  ...values,
798
797
  ...propsCopy.submit.to.params
799
- } : 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
+ });
800
811
  };
801
812
  }
802
813
  if (propsCopy.extendTypes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.3-beta.28",
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.28",
31
+ "@faasjs/react": "^0.0.3-beta.29",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },