@faasjs/ant-design 0.0.2-beta.374 → 0.0.2-beta.375

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
@@ -305,7 +305,7 @@ ___
305
305
 
306
306
  ### FormProps
307
307
 
308
- Ƭ **FormProps**<`Values`, `ExtendItemProps`\>: { `extendTypes?`: { `[type: string]`: [`ExtendFormTypeProps`](#extendformtypeprops); } ; `items?`: ([`FormItemProps`](#formitemprops) \| `ExtendItemProps`)[] ; `submit?`: ``false`` \| { `text?`: `string` } } & `AntdFormProps`<`Values`\>
308
+ Ƭ **FormProps**<`Values`, `ExtendItemProps`\>: { `extendTypes?`: { `[type: string]`: [`ExtendFormTypeProps`](#extendformtypeprops); } ; `items?`: ([`FormItemProps`](#formitemprops) \| `ExtendItemProps`)[] ; `submit?`: ``false`` \| { `text?`: `string` ; `to?`: { `action`: `string` ; `params?`: `Record`<`string`, `any`\> } } ; `onFinish?`: (`values`: `Values`, `submit?`: (`values`: `any`) => `Promise`<`any`\>) => `Promise`<`any`\> } & `Omit`<`AntdFormProps`<`Values`\>, ``"onFinish"``\>
309
309
 
310
310
  #### Type parameters
311
311
 
package/dist/index.d.ts CHANGED
@@ -231,11 +231,42 @@ declare type FormProps<Values = any, ExtendItemProps = any> = {
231
231
  submit?: false | {
232
232
  /** Default: Submit */
233
233
  text?: string;
234
+ /**
235
+ * Submit to FaasJS server.
236
+ *
237
+ * If use onFinish, you should call submit manually.
238
+ * ```ts
239
+ * {
240
+ * submit: {
241
+ * to: {
242
+ * action: 'action_name'
243
+ * }
244
+ * },
245
+ * onFinish: (values, submit) => {
246
+ * // do something before submit
247
+ *
248
+ * // submit
249
+ * await submit({
250
+ * ...values,
251
+ * extraProps: 'some extra props'
252
+ * })
253
+ *
254
+ * // do something after submit
255
+ * }
256
+ * }
257
+ * ```
258
+ */
259
+ to?: {
260
+ action: string;
261
+ /** params will overwrite form values before submit */
262
+ params?: Record<string, any>;
263
+ };
234
264
  };
265
+ onFinish?: (values: Values, submit?: (values: any) => Promise<any>) => Promise<any>;
235
266
  extendTypes?: {
236
267
  [type: string]: ExtendFormTypeProps;
237
268
  };
238
- } & FormProps$1<Values>;
269
+ } & Omit<FormProps$1<Values>, 'onFinish'>;
239
270
  declare function Form<Values = any>(props: FormProps<Values>): JSX.Element;
240
271
  declare namespace Form {
241
272
  var useForm: typeof antd_lib_form_Form.useForm;
package/dist/index.js CHANGED
@@ -261,8 +261,9 @@ function useDrawer(init) {
261
261
  }
262
262
 
263
263
  // src/Form.tsx
264
+ var import_react8 = require("@faasjs/react");
264
265
  var import_antd5 = require("antd");
265
- var import_react8 = require("react");
266
+ var import_react9 = require("react");
266
267
 
267
268
  // src/FormItem.tsx
268
269
  var import_antd4 = require("antd");
@@ -439,44 +440,48 @@ function FormItem(props) {
439
440
  // src/Form.tsx
440
441
  function Form(props) {
441
442
  var _a, _b;
442
- const [loading, setLoading] = (0, import_react8.useState)(false);
443
- const [computedProps, setComputedProps] = (0, import_react8.useState)();
443
+ const [loading, setLoading] = (0, import_react9.useState)(false);
444
+ const [computedProps, setComputedProps] = (0, import_react9.useState)();
444
445
  const [config] = useFaasState();
445
- (0, import_react8.useEffect)(() => {
446
+ (0, import_react9.useEffect)(() => {
446
447
  const propsCopy = __spreadValues({}, props);
447
448
  if (propsCopy.onFinish) {
448
449
  propsCopy.onFinish = async (values) => {
450
+ var _a2;
449
451
  setLoading(true);
450
452
  try {
451
- await propsCopy.onFinish(values);
453
+ if (propsCopy.submit && ((_a2 = propsCopy.submit.to) == null ? void 0 : _a2.action)) {
454
+ await props.onFinish(values, async (values2) => (0, import_react8.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? __spreadValues(__spreadValues({}, values2), propsCopy.submit.to.params) : values2));
455
+ } else
456
+ await propsCopy.onFinish(values);
452
457
  } catch (error) {
453
458
  console.error(error);
454
459
  }
455
460
  setLoading(false);
456
461
  };
457
462
  }
458
- setComputedProps(props);
463
+ setComputedProps(propsCopy);
459
464
  }, []);
460
465
  if (!computedProps)
461
466
  return null;
462
- return /* @__PURE__ */ import_react.default.createElement(import_antd5.Form, __spreadValues({}, computedProps), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({
467
+ return /* @__PURE__ */ import_react.default.createElement(import_antd5.Form, __spreadValues({}, computedProps), (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({
463
468
  key: item.id
464
469
  }, item), {
465
- extendTypes: props.extendTypes
466
- }))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd5.Button, {
470
+ extendTypes: computedProps.extendTypes
471
+ }))), computedProps.children, computedProps.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd5.Button, {
467
472
  htmlType: "submit",
468
473
  type: "primary",
469
474
  loading
470
- }, ((_b = props.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
475
+ }, ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
471
476
  }
472
477
  Form.useForm = import_antd5.Form.useForm;
473
478
  Form.Item = FormItem;
474
479
 
475
480
  // src/Modal.tsx
476
481
  var import_antd6 = require("antd");
477
- var import_react9 = require("react");
482
+ var import_react10 = require("react");
478
483
  function useModal(init) {
479
- const [props, setProps] = (0, import_react9.useState)(__spreadValues({
484
+ const [props, setProps] = (0, import_react10.useState)(__spreadValues({
480
485
  visible: false,
481
486
  onCancel: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
482
487
  visible: false
@@ -493,7 +498,7 @@ function useModal(init) {
493
498
 
494
499
  // src/Routers.tsx
495
500
  var import_antd7 = require("antd");
496
- var import_react10 = require("react");
501
+ var import_react11 = require("react");
497
502
  var import_react_router_dom = require("react-router-dom");
498
503
  function NotFound() {
499
504
  const [config] = useFaasState();
@@ -506,7 +511,7 @@ function Routes(props) {
506
511
  return /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Routes, null, props.routes.map((r) => /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, __spreadProps(__spreadValues({
507
512
  key: r.path
508
513
  }, r), {
509
- element: r.element || /* @__PURE__ */ import_react.default.createElement(import_react10.Suspense, {
514
+ element: r.element || /* @__PURE__ */ import_react.default.createElement(import_react11.Suspense, {
510
515
  fallback: props.fallback || /* @__PURE__ */ import_react.default.createElement("div", {
511
516
  style: { padding: "24px" }
512
517
  }, /* @__PURE__ */ import_react.default.createElement(import_antd7.Skeleton, {
@@ -521,12 +526,12 @@ function Routes(props) {
521
526
  }
522
527
 
523
528
  // src/Table.tsx
524
- var import_react11 = require("react");
529
+ var import_react12 = require("react");
525
530
  var import_antd8 = require("antd");
526
531
  var import_dayjs4 = __toESM(require("dayjs"));
527
532
  var import_icons3 = require("@ant-design/icons");
528
533
  var import_lodash5 = require("lodash");
529
- var import_react12 = require("@faasjs/react");
534
+ var import_react13 = require("@faasjs/react");
530
535
  function processValue(item, value) {
531
536
  var _a;
532
537
  if (typeof value !== "undefined" && value !== null) {
@@ -557,9 +562,9 @@ function processValue(item, value) {
557
562
  return value;
558
563
  }
559
564
  function Table(props) {
560
- const [columns, setColumns] = (0, import_react11.useState)();
565
+ const [columns, setColumns] = (0, import_react12.useState)();
561
566
  const [config] = useFaasState();
562
- (0, import_react11.useEffect)(() => {
567
+ (0, import_react12.useEffect)(() => {
563
568
  var _a;
564
569
  for (const item of props.items) {
565
570
  if (!item.key)
@@ -583,7 +588,7 @@ function Table(props) {
583
588
  delete item.children;
584
589
  if (props.extendTypes && props.extendTypes[item.type]) {
585
590
  if (props.extendTypes[item.type].children) {
586
- item.render = (value, values) => (0, import_react11.cloneElement)(props.extendTypes[item.type].children, {
591
+ item.render = (value, values) => (0, import_react12.cloneElement)(props.extendTypes[item.type].children, {
587
592
  value,
588
593
  values
589
594
  });
@@ -694,7 +699,7 @@ function Table(props) {
694
699
  columns,
695
700
  dataSource: props.dataSource
696
701
  }));
697
- return /* @__PURE__ */ import_react.default.createElement(import_react12.FaasDataWrapper, __spreadValues({
702
+ return /* @__PURE__ */ import_react.default.createElement(import_react13.FaasDataWrapper, __spreadValues({
698
703
  fallback: props.faasData.fallback || /* @__PURE__ */ import_react.default.createElement(import_antd8.Skeleton, {
699
704
  active: true
700
705
  }),
@@ -742,10 +747,10 @@ function Table(props) {
742
747
  }
743
748
 
744
749
  // src/Title.tsx
745
- var import_react13 = require("react");
750
+ var import_react14 = require("react");
746
751
  function Title(props) {
747
752
  const [config] = useFaasState();
748
- (0, import_react13.useEffect)(() => {
753
+ (0, import_react14.useEffect)(() => {
749
754
  const title = Array.isArray(props.title) ? props.title : [props.title];
750
755
  document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
751
756
  }, []);
@@ -758,7 +763,7 @@ function Title(props) {
758
763
  }, Array.isArray(props.title) ? props.title[0] : props.title);
759
764
  }
760
765
  if (props.children)
761
- return (0, import_react13.cloneElement)(props.children, { title: props.title });
766
+ return (0, import_react14.cloneElement)(props.children, { title: props.title });
762
767
  return null;
763
768
  }
764
769
  module.exports = __toCommonJS(src_exports);
package/dist/index.mjs CHANGED
@@ -221,6 +221,7 @@ function useDrawer(init) {
221
221
  }
222
222
 
223
223
  // src/Form.tsx
224
+ import { faas } from "@faasjs/react";
224
225
  import {
225
226
  Button as Button2,
226
227
  Form as AntdForm2
@@ -418,28 +419,32 @@ function Form(props) {
418
419
  const propsCopy = __spreadValues({}, props);
419
420
  if (propsCopy.onFinish) {
420
421
  propsCopy.onFinish = async (values) => {
422
+ var _a2;
421
423
  setLoading(true);
422
424
  try {
423
- await propsCopy.onFinish(values);
425
+ if (propsCopy.submit && ((_a2 = propsCopy.submit.to) == null ? void 0 : _a2.action)) {
426
+ await props.onFinish(values, async (values2) => faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? __spreadValues(__spreadValues({}, values2), propsCopy.submit.to.params) : values2));
427
+ } else
428
+ await propsCopy.onFinish(values);
424
429
  } catch (error) {
425
430
  console.error(error);
426
431
  }
427
432
  setLoading(false);
428
433
  };
429
434
  }
430
- setComputedProps(props);
435
+ setComputedProps(propsCopy);
431
436
  }, []);
432
437
  if (!computedProps)
433
438
  return null;
434
- return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, computedProps), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
439
+ return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, computedProps), (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
435
440
  key: item.id
436
441
  }, item), {
437
- extendTypes: props.extendTypes
438
- }))), props.children, props.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
442
+ extendTypes: computedProps.extendTypes
443
+ }))), computedProps.children, computedProps.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
439
444
  htmlType: "submit",
440
445
  type: "primary",
441
446
  loading
442
- }, ((_b = props.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
447
+ }, ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
443
448
  }
444
449
  Form.useForm = AntdForm2.useForm;
445
450
  Form.Item = FormItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.374",
3
+ "version": "0.0.2-beta.375",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,7 +28,7 @@
28
28
  "lodash": "*",
29
29
  "react": "*",
30
30
  "react-dom": "*",
31
- "@faasjs/react": "^0.0.2-beta.374",
31
+ "@faasjs/react": "^0.0.2-beta.375",
32
32
  "react-use": "*",
33
33
  "react-router-dom": "*",
34
34
  "dayjs": "*"