@faasjs/ant-design 0.0.2-beta.406 → 0.0.2-beta.408

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.mjs CHANGED
@@ -6,10 +6,17 @@ import { Typography } from "antd";
6
6
  import { isNil } from "lodash";
7
7
 
8
8
  // src/Config.tsx
9
- import { createContext, useContext } from "react";
9
+ import {
10
+ createContext,
11
+ useContext,
12
+ useEffect,
13
+ useState
14
+ } from "react";
15
+ import { ConfigProvider as AntdConfigProvider } from "antd";
16
+ import { defaultsDeep } from "lodash";
10
17
  import { jsx } from "react/jsx-runtime";
11
18
  var isZH = /^zh/i.test(navigator.language);
12
- var common = isZH ? {
19
+ var zh = {
13
20
  lang: "zh",
14
21
  blank: "\u7A7A",
15
22
  all: "\u5168\u90E8",
@@ -18,7 +25,8 @@ var common = isZH ? {
18
25
  add: "\u6DFB\u52A0",
19
26
  delete: "\u5220\u9664",
20
27
  required: "\u5FC5\u586B"
21
- } : {
28
+ };
29
+ var en = {
22
30
  lang: "en",
23
31
  blank: "Empty",
24
32
  all: "All",
@@ -28,7 +36,9 @@ var common = isZH ? {
28
36
  delete: "Delete",
29
37
  required: "is required"
30
38
  };
39
+ var common = isZH ? zh : en;
31
40
  var baseConfig = {
41
+ antd: {},
32
42
  lang: "en",
33
43
  common,
34
44
  Blank: { text: common.blank },
@@ -36,19 +46,32 @@ var baseConfig = {
36
46
  Title: {
37
47
  separator: " - ",
38
48
  suffix: ""
39
- }
49
+ },
50
+ Link: { style: {} }
40
51
  };
41
52
  var ConfigContext = createContext(baseConfig);
42
53
  function ConfigProvider({
43
54
  config,
44
55
  children
45
56
  }) {
57
+ const [values, setValues] = useState(baseConfig);
58
+ useEffect(() => {
59
+ if (config.lang === "zh") {
60
+ setValues(defaultsDeep(config, {
61
+ lang: "zh",
62
+ common: zh,
63
+ Blank: { text: zh.blank },
64
+ Form: { submit: { text: zh.submit } }
65
+ }, baseConfig));
66
+ } else
67
+ setValues(values);
68
+ }, []);
46
69
  return /* @__PURE__ */ jsx(ConfigContext.Provider, {
47
- value: {
48
- ...baseConfig,
49
- ...config
50
- },
51
- children
70
+ value: values,
71
+ children: /* @__PURE__ */ jsx(AntdConfigProvider, {
72
+ ...config.antd,
73
+ children
74
+ })
52
75
  });
53
76
  }
54
77
  function useConfigContext() {
@@ -58,10 +81,10 @@ function useConfigContext() {
58
81
  // src/Blank.tsx
59
82
  import { jsx as jsx2 } from "react/jsx-runtime";
60
83
  function Blank(options) {
61
- const config = useConfigContext();
84
+ const { Blank: Blank2 } = useConfigContext();
62
85
  return !options || isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ jsx2(Typography.Text, {
63
86
  disabled: true,
64
- children: (options == null ? void 0 : options.text) || config.Blank.text
87
+ children: (options == null ? void 0 : options.text) || Blank2.text
65
88
  }) : options.value;
66
89
  }
67
90
 
@@ -97,15 +120,15 @@ import {
97
120
  import { upperFirst as upperFirst2 } from "lodash";
98
121
  import {
99
122
  cloneElement,
100
- useEffect,
101
- useState
123
+ useEffect as useEffect2,
124
+ useState as useState2
102
125
  } from "react";
103
126
  import dayjs from "dayjs";
104
127
  import { FaasDataWrapper } from "@faasjs/react";
105
128
  import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
106
129
  function DescriptionItemContent(props) {
107
- const [computedProps, setComputedProps] = useState();
108
- useEffect(() => {
130
+ const [computedProps, setComputedProps] = useState2();
131
+ useEffect2(() => {
109
132
  var _a, _b;
110
133
  const propsCopy = { ...props };
111
134
  if (!propsCopy.item.title)
@@ -226,10 +249,10 @@ function Description(props) {
226
249
 
227
250
  // src/Drawer.tsx
228
251
  import { Drawer } from "antd";
229
- import { useState as useState2 } from "react";
252
+ import { useState as useState3 } from "react";
230
253
  import { jsx as jsx4 } from "react/jsx-runtime";
231
254
  function useDrawer(init) {
232
- const [props, setProps] = useState2({
255
+ const [props, setProps] = useState3({
233
256
  visible: false,
234
257
  onClose: () => setProps((prev) => ({
235
258
  ...prev,
@@ -258,8 +281,8 @@ import {
258
281
  Form as AntdForm2
259
282
  } from "antd";
260
283
  import {
261
- useEffect as useEffect3,
262
- useState as useState4
284
+ useEffect as useEffect4,
285
+ useState as useState5
263
286
  } from "react";
264
287
 
265
288
  // src/FormItem.tsx
@@ -274,7 +297,7 @@ import {
274
297
  Select
275
298
  } from "antd";
276
299
  import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
277
- import { useEffect as useEffect2, useState as useState3 } from "react";
300
+ import { useEffect as useEffect3, useState as useState4 } from "react";
278
301
  import { upperFirst as upperFirst3 } from "lodash";
279
302
 
280
303
  // src/TimePicker.tsx
@@ -340,8 +363,8 @@ function processProps(propsCopy, config) {
340
363
  return propsCopy;
341
364
  }
342
365
  function DateItem(options) {
343
- const [value, setValue] = useState3();
344
- useEffect2(() => {
366
+ const [value, setValue] = useState4();
367
+ useEffect3(() => {
345
368
  setValue(options.value && !isDayjs(options.value) ? dayjs2(options.value) : null);
346
369
  }, [options.value]);
347
370
  return /* @__PURE__ */ jsx6(DatePicker, {
@@ -350,8 +373,8 @@ function DateItem(options) {
350
373
  });
351
374
  }
352
375
  function TimeItem(options) {
353
- const [value, setValue] = useState3();
354
- useEffect2(() => {
376
+ const [value, setValue] = useState4();
377
+ useEffect3(() => {
355
378
  setValue(options.value && !isDayjs(options.value) ? dayjs2(options.value) : null);
356
379
  }, [options.value]);
357
380
  return /* @__PURE__ */ jsx6(TimePicker, {
@@ -361,10 +384,10 @@ function TimeItem(options) {
361
384
  }
362
385
  function FormItem(props) {
363
386
  var _a;
364
- const [computedProps, setComputedProps] = useState3();
365
- const [extendTypes, setExtendTypes] = useState3();
387
+ const [computedProps, setComputedProps] = useState4();
388
+ const [extendTypes, setExtendTypes] = useState4();
366
389
  const config = useConfigContext();
367
- useEffect2(() => {
390
+ useEffect3(() => {
368
391
  const propsCopy = { ...props };
369
392
  if (propsCopy.extendTypes) {
370
393
  setExtendTypes(propsCopy.extendTypes);
@@ -655,11 +678,11 @@ function FormItem(props) {
655
678
  import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
656
679
  function Form(props) {
657
680
  var _a, _b;
658
- const [loading, setLoading] = useState4(false);
659
- const [computedProps, setComputedProps] = useState4();
681
+ const [loading, setLoading] = useState5(false);
682
+ const [computedProps, setComputedProps] = useState5();
660
683
  const config = useConfigContext();
661
- const [extendTypes, setExtendTypes] = useState4();
662
- useEffect3(() => {
684
+ const [extendTypes, setExtendTypes] = useState5();
685
+ useEffect4(() => {
663
686
  var _a2;
664
687
  const propsCopy = { ...props };
665
688
  if (propsCopy.onFinish) {
@@ -681,10 +704,11 @@ function Form(props) {
681
704
  };
682
705
  } else if (propsCopy.submit && ((_a2 = propsCopy.submit.to) == null ? void 0 : _a2.action)) {
683
706
  propsCopy.onFinish = async (values) => {
684
- return await faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
707
+ setLoading(true);
708
+ return faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
685
709
  ...values,
686
710
  ...propsCopy.submit.to.params
687
- } : values);
711
+ } : values).finally(() => setLoading(false));
688
712
  };
689
713
  }
690
714
  if (propsCopy.extendTypes) {
@@ -717,12 +741,50 @@ function Form(props) {
717
741
  Form.useForm = AntdForm2.useForm;
718
742
  Form.Item = FormItem;
719
743
 
744
+ // src/Link.tsx
745
+ import { Link as RouterLink } from "react-router-dom";
746
+ import { Button as Button3 } from "antd";
747
+ import { jsx as jsx8 } from "react/jsx-runtime";
748
+ function Link({
749
+ href,
750
+ target,
751
+ text,
752
+ children,
753
+ style,
754
+ button
755
+ }) {
756
+ const { Link: Link2 } = useConfigContext();
757
+ style = Object.assign({ cursor: "pointer" }, style);
758
+ if (button)
759
+ return /* @__PURE__ */ jsx8(Button3, {
760
+ ...button,
761
+ children: /* @__PURE__ */ jsx8(RouterLink, {
762
+ to: href,
763
+ target: target || (Link2 == null ? void 0 : Link2.target),
764
+ style: {
765
+ ...Link2.style,
766
+ ...style || {}
767
+ },
768
+ children: text || children
769
+ })
770
+ });
771
+ return /* @__PURE__ */ jsx8(RouterLink, {
772
+ to: href,
773
+ target: target || (Link2 == null ? void 0 : Link2.target),
774
+ style: {
775
+ ...Link2.style,
776
+ ...style || {}
777
+ },
778
+ children: text || children
779
+ });
780
+ }
781
+
720
782
  // src/Modal.tsx
721
783
  import { Modal } from "antd";
722
- import { useState as useState5 } from "react";
723
- import { jsx as jsx8 } from "react/jsx-runtime";
784
+ import { useState as useState6 } from "react";
785
+ import { jsx as jsx9 } from "react/jsx-runtime";
724
786
  function useModal(init) {
725
- const [props, setProps] = useState5({
787
+ const [props, setProps] = useState6({
726
788
  visible: false,
727
789
  onCancel: () => setProps((prev) => ({
728
790
  ...prev,
@@ -731,7 +793,7 @@ function useModal(init) {
731
793
  ...init
732
794
  });
733
795
  return {
734
- modal: /* @__PURE__ */ jsx8(Modal, {
796
+ modal: /* @__PURE__ */ jsx9(Modal, {
735
797
  ...props
736
798
  }),
737
799
  modalProps: props,
@@ -753,10 +815,10 @@ import {
753
815
  Routes as OriginRoutes,
754
816
  Route
755
817
  } from "react-router-dom";
756
- import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
757
- function NotFound() {
818
+ import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
819
+ function PageNotFound() {
758
820
  const config = useConfigContext();
759
- return /* @__PURE__ */ jsx9(Result, {
821
+ return /* @__PURE__ */ jsx10(Result, {
760
822
  status: "404",
761
823
  title: config.common.pageNotFound
762
824
  });
@@ -764,21 +826,21 @@ function NotFound() {
764
826
  function Routes(props) {
765
827
  return /* @__PURE__ */ jsxs3(OriginRoutes, {
766
828
  children: [
767
- props.routes.map((r) => /* @__PURE__ */ jsx9(Route, {
829
+ props.routes.map((r) => /* @__PURE__ */ jsx10(Route, {
768
830
  ...r,
769
- element: r.element || /* @__PURE__ */ jsx9(Suspense, {
770
- fallback: props.fallback || /* @__PURE__ */ jsx9("div", {
831
+ element: r.element || /* @__PURE__ */ jsx10(Suspense, {
832
+ fallback: props.fallback || /* @__PURE__ */ jsx10("div", {
771
833
  style: { padding: "24px" },
772
- children: /* @__PURE__ */ jsx9(Skeleton2, {
834
+ children: /* @__PURE__ */ jsx10(Skeleton2, {
773
835
  active: true
774
836
  })
775
837
  }),
776
- children: /* @__PURE__ */ jsx9(r.page, {})
838
+ children: /* @__PURE__ */ jsx10(r.page, {})
777
839
  })
778
840
  }, r.path)),
779
- /* @__PURE__ */ jsx9(Route, {
841
+ /* @__PURE__ */ jsx10(Route, {
780
842
  path: "*",
781
- element: props.notFound || /* @__PURE__ */ jsx9(NotFound, {})
843
+ element: props.notFound || /* @__PURE__ */ jsx10(PageNotFound, {})
782
844
  }, "*")
783
845
  ]
784
846
  });
@@ -786,8 +848,8 @@ function Routes(props) {
786
848
 
787
849
  // src/Table.tsx
788
850
  import {
789
- useState as useState6,
790
- useEffect as useEffect4,
851
+ useState as useState7,
852
+ useEffect as useEffect5,
791
853
  cloneElement as cloneElement2
792
854
  } from "react";
793
855
  import {
@@ -799,7 +861,7 @@ import dayjs3 from "dayjs";
799
861
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
800
862
  import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
801
863
  import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
802
- import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
864
+ import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
803
865
  function processValue(item, value) {
804
866
  var _a;
805
867
  if (typeof value !== "undefined" && value !== null) {
@@ -830,9 +892,9 @@ function processValue(item, value) {
830
892
  return value;
831
893
  }
832
894
  function Table(props) {
833
- const [columns, setColumns] = useState6();
895
+ const [columns, setColumns] = useState7();
834
896
  const config = useConfigContext();
835
- useEffect4(() => {
897
+ useEffect5(() => {
836
898
  var _a;
837
899
  for (const item of props.items) {
838
900
  if (!item.key)
@@ -888,12 +950,12 @@ function Table(props) {
888
950
  item.onFilter = (value, row) => row[item.id].includes(value);
889
951
  break;
890
952
  case "boolean":
891
- item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ jsx10(Blank, {}) : value ? /* @__PURE__ */ jsx10(CheckOutlined2, {
953
+ item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ jsx11(Blank, {}) : value ? /* @__PURE__ */ jsx11(CheckOutlined2, {
892
954
  style: {
893
955
  marginTop: "4px",
894
956
  color: "#52c41a"
895
957
  }
896
- }) : /* @__PURE__ */ jsx10(CloseOutlined2, {
958
+ }) : /* @__PURE__ */ jsx11(CloseOutlined2, {
897
959
  style: {
898
960
  marginTop: "4px",
899
961
  color: "#ff4d4f"
@@ -913,28 +975,28 @@ function Table(props) {
913
975
  confirm();
914
976
  },
915
977
  children: [
916
- /* @__PURE__ */ jsx10(Radio.Button, {
978
+ /* @__PURE__ */ jsx11(Radio.Button, {
917
979
  children: config.common.all
918
980
  }),
919
- /* @__PURE__ */ jsx10(Radio.Button, {
981
+ /* @__PURE__ */ jsx11(Radio.Button, {
920
982
  value: "true",
921
- children: /* @__PURE__ */ jsx10(CheckOutlined2, {
983
+ children: /* @__PURE__ */ jsx11(CheckOutlined2, {
922
984
  style: {
923
985
  color: "#52c41a",
924
986
  verticalAlign: "middle"
925
987
  }
926
988
  })
927
989
  }),
928
- /* @__PURE__ */ jsx10(Radio.Button, {
990
+ /* @__PURE__ */ jsx11(Radio.Button, {
929
991
  value: "false",
930
- children: /* @__PURE__ */ jsx10(CloseOutlined2, {
992
+ children: /* @__PURE__ */ jsx11(CloseOutlined2, {
931
993
  style: {
932
994
  verticalAlign: "middle",
933
995
  color: "#ff4d4f"
934
996
  }
935
997
  })
936
998
  }),
937
- /* @__PURE__ */ jsx10(Radio.Button, {
999
+ /* @__PURE__ */ jsx11(Radio.Button, {
938
1000
  value: "empty",
939
1001
  children: config.common.blank
940
1002
  })
@@ -976,14 +1038,14 @@ function Table(props) {
976
1038
  if (!columns)
977
1039
  return null;
978
1040
  if (!props.faasData)
979
- return /* @__PURE__ */ jsx10(AntdTable, {
1041
+ return /* @__PURE__ */ jsx11(AntdTable, {
980
1042
  ...props,
981
1043
  rowKey: props.rowKey || "id",
982
1044
  columns,
983
1045
  dataSource: props.dataSource
984
1046
  });
985
- return /* @__PURE__ */ jsx10(FaasDataWrapper2, {
986
- fallback: props.faasData.fallback || /* @__PURE__ */ jsx10(Skeleton3, {
1047
+ return /* @__PURE__ */ jsx11(FaasDataWrapper2, {
1048
+ fallback: props.faasData.fallback || /* @__PURE__ */ jsx11(Skeleton3, {
987
1049
  active: true
988
1050
  }),
989
1051
  render: ({
@@ -992,20 +1054,20 @@ function Table(props) {
992
1054
  reload
993
1055
  }) => {
994
1056
  if (!data)
995
- return /* @__PURE__ */ jsx10(AntdTable, {
1057
+ return /* @__PURE__ */ jsx11(AntdTable, {
996
1058
  ...props,
997
1059
  rowKey: props.rowKey || "id",
998
1060
  columns,
999
1061
  dataSource: []
1000
1062
  });
1001
1063
  if (Array.isArray(data))
1002
- return /* @__PURE__ */ jsx10(AntdTable, {
1064
+ return /* @__PURE__ */ jsx11(AntdTable, {
1003
1065
  ...props,
1004
1066
  rowKey: props.rowKey || "id",
1005
1067
  columns,
1006
1068
  dataSource: data
1007
1069
  });
1008
- return /* @__PURE__ */ jsx10(AntdTable, {
1070
+ return /* @__PURE__ */ jsx11(AntdTable, {
1009
1071
  ...props,
1010
1072
  rowKey: props.rowKey || "id",
1011
1073
  columns,
@@ -1039,20 +1101,20 @@ function Table(props) {
1039
1101
  }
1040
1102
 
1041
1103
  // src/Title.tsx
1042
- import { useEffect as useEffect5, cloneElement as cloneElement3 } from "react";
1043
- import { jsx as jsx11 } from "react/jsx-runtime";
1104
+ import { useEffect as useEffect6, cloneElement as cloneElement3 } from "react";
1105
+ import { jsx as jsx12 } from "react/jsx-runtime";
1044
1106
  function Title(props) {
1045
1107
  const config = useConfigContext();
1046
- useEffect5(() => {
1108
+ useEffect6(() => {
1047
1109
  const title = Array.isArray(props.title) ? props.title : [props.title];
1048
1110
  document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
1049
1111
  }, []);
1050
1112
  if (props.h1) {
1051
1113
  if (typeof props.h1 === "boolean")
1052
- return /* @__PURE__ */ jsx11("h1", {
1114
+ return /* @__PURE__ */ jsx12("h1", {
1053
1115
  children: Array.isArray(props.title) ? props.title[0] : props.title
1054
1116
  });
1055
- return /* @__PURE__ */ jsx11("h1", {
1117
+ return /* @__PURE__ */ jsx12("h1", {
1056
1118
  className: props.h1.className,
1057
1119
  style: props.h1.style,
1058
1120
  children: Array.isArray(props.title) ? props.title[0] : props.title
@@ -1072,7 +1134,9 @@ export {
1072
1134
  Drawer,
1073
1135
  Form,
1074
1136
  FormItem,
1137
+ Link,
1075
1138
  Modal,
1139
+ PageNotFound,
1076
1140
  Routes,
1077
1141
  Table,
1078
1142
  TimePicker,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.406",
3
+ "version": "0.0.2-beta.408",
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.406",
31
+ "@faasjs/react": "^0.0.2-beta.408",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },