@faasjs/ant-design 0.0.2-beta.405 → 0.0.2-beta.407

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,7 +6,12 @@ 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
+ } from "react";
13
+ import { ConfigProvider as AntdConfigProvider } from "antd";
14
+ import { defaultsDeep } from "lodash";
10
15
  import { jsx } from "react/jsx-runtime";
11
16
  var isZH = /^zh/i.test(navigator.language);
12
17
  var common = isZH ? {
@@ -29,6 +34,7 @@ var common = isZH ? {
29
34
  required: "is required"
30
35
  };
31
36
  var baseConfig = {
37
+ antd: {},
32
38
  lang: "en",
33
39
  common,
34
40
  Blank: { text: common.blank },
@@ -36,7 +42,8 @@ var baseConfig = {
36
42
  Title: {
37
43
  separator: " - ",
38
44
  suffix: ""
39
- }
45
+ },
46
+ Link: { style: {} }
40
47
  };
41
48
  var ConfigContext = createContext(baseConfig);
42
49
  function ConfigProvider({
@@ -44,11 +51,11 @@ function ConfigProvider({
44
51
  children
45
52
  }) {
46
53
  return /* @__PURE__ */ jsx(ConfigContext.Provider, {
47
- value: {
48
- ...baseConfig,
49
- ...config
50
- },
51
- children
54
+ value: defaultsDeep(config, baseConfig),
55
+ children: /* @__PURE__ */ jsx(AntdConfigProvider, {
56
+ ...config.antd,
57
+ children
58
+ })
52
59
  });
53
60
  }
54
61
  function useConfigContext() {
@@ -58,10 +65,10 @@ function useConfigContext() {
58
65
  // src/Blank.tsx
59
66
  import { jsx as jsx2 } from "react/jsx-runtime";
60
67
  function Blank(options) {
61
- const config = useConfigContext();
68
+ const { Blank: Blank2 } = useConfigContext();
62
69
  return !options || isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ jsx2(Typography.Text, {
63
70
  disabled: true,
64
- children: (options == null ? void 0 : options.text) || config.Blank.text
71
+ children: (options == null ? void 0 : options.text) || Blank2.text
65
72
  }) : options.value;
66
73
  }
67
74
 
@@ -291,6 +298,7 @@ var TimePicker = forwardRef((props, ref) => {
291
298
  TimePicker.displayName = "TimePicker";
292
299
 
293
300
  // src/FormItem.tsx
301
+ import dayjs2, { isDayjs } from "dayjs";
294
302
  import { Fragment as Fragment2, jsx as jsx6, jsxs } from "react/jsx-runtime";
295
303
  function processProps(propsCopy, config) {
296
304
  if (!propsCopy.title)
@@ -338,19 +346,45 @@ function processProps(propsCopy, config) {
338
346
  }
339
347
  return propsCopy;
340
348
  }
349
+ function DateItem(options) {
350
+ const [value, setValue] = useState3();
351
+ useEffect2(() => {
352
+ setValue(options.value && !isDayjs(options.value) ? dayjs2(options.value) : null);
353
+ }, [options.value]);
354
+ return /* @__PURE__ */ jsx6(DatePicker, {
355
+ ...options,
356
+ value
357
+ });
358
+ }
359
+ function TimeItem(options) {
360
+ const [value, setValue] = useState3();
361
+ useEffect2(() => {
362
+ setValue(options.value && !isDayjs(options.value) ? dayjs2(options.value) : null);
363
+ }, [options.value]);
364
+ return /* @__PURE__ */ jsx6(TimePicker, {
365
+ ...options,
366
+ value
367
+ });
368
+ }
341
369
  function FormItem(props) {
342
370
  var _a;
343
371
  const [computedProps, setComputedProps] = useState3();
372
+ const [extendTypes, setExtendTypes] = useState3();
344
373
  const config = useConfigContext();
345
374
  useEffect2(() => {
346
- setComputedProps(processProps({ ...props }, config));
375
+ const propsCopy = { ...props };
376
+ if (propsCopy.extendTypes) {
377
+ setExtendTypes(propsCopy.extendTypes);
378
+ delete propsCopy.extendTypes;
379
+ }
380
+ setComputedProps(processProps(propsCopy, config));
347
381
  }, [props]);
348
382
  if (!computedProps)
349
383
  return null;
350
- if (computedProps.extendTypes && computedProps.extendTypes[computedProps.type])
384
+ if (extendTypes && extendTypes[computedProps.type])
351
385
  return /* @__PURE__ */ jsx6(AntdForm.Item, {
352
386
  ...computedProps,
353
- children: computedProps.extendTypes[computedProps.type].children
387
+ children: extendTypes[computedProps.type].children
354
388
  });
355
389
  if (computedProps.children)
356
390
  return /* @__PURE__ */ jsx6(AntdForm.Item, {
@@ -535,14 +569,14 @@ function FormItem(props) {
535
569
  case "date":
536
570
  return /* @__PURE__ */ jsx6(AntdForm.Item, {
537
571
  ...computedProps,
538
- children: /* @__PURE__ */ jsx6(DatePicker, {
572
+ children: /* @__PURE__ */ jsx6(DateItem, {
539
573
  ...computedProps.input
540
574
  })
541
575
  });
542
576
  case "time":
543
577
  return /* @__PURE__ */ jsx6(AntdForm.Item, {
544
578
  ...computedProps,
545
- children: /* @__PURE__ */ jsx6(TimePicker, {
579
+ children: /* @__PURE__ */ jsx6(TimeItem, {
546
580
  ...computedProps.input
547
581
  })
548
582
  });
@@ -631,6 +665,7 @@ function Form(props) {
631
665
  const [loading, setLoading] = useState4(false);
632
666
  const [computedProps, setComputedProps] = useState4();
633
667
  const config = useConfigContext();
668
+ const [extendTypes, setExtendTypes] = useState4();
634
669
  useEffect3(() => {
635
670
  var _a2;
636
671
  const propsCopy = { ...props };
@@ -659,6 +694,10 @@ function Form(props) {
659
694
  } : values);
660
695
  };
661
696
  }
697
+ if (propsCopy.extendTypes) {
698
+ setExtendTypes(propsCopy.extendTypes);
699
+ delete propsCopy.extendTypes;
700
+ }
662
701
  setComputedProps(propsCopy);
663
702
  }, []);
664
703
  if (!computedProps)
@@ -669,7 +708,7 @@ function Form(props) {
669
708
  computedProps.beforeItems,
670
709
  (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ jsx7(FormItem, {
671
710
  ...item,
672
- extendTypes: computedProps.extendTypes
711
+ extendTypes
673
712
  }, item.id)),
674
713
  computedProps.children,
675
714
  computedProps.submit !== false && /* @__PURE__ */ jsx7(Button2, {
@@ -685,10 +724,33 @@ function Form(props) {
685
724
  Form.useForm = AntdForm2.useForm;
686
725
  Form.Item = FormItem;
687
726
 
727
+ // src/Link.tsx
728
+ import { Link as RouterLink } from "react-router-dom";
729
+ import { jsx as jsx8 } from "react/jsx-runtime";
730
+ function Link({
731
+ href,
732
+ target,
733
+ text,
734
+ children,
735
+ style
736
+ }) {
737
+ const { Link: Link2 } = useConfigContext();
738
+ style = Object.assign({ cursor: "pointer" }, style);
739
+ return /* @__PURE__ */ jsx8(RouterLink, {
740
+ to: href,
741
+ target: target || (Link2 == null ? void 0 : Link2.target),
742
+ style: {
743
+ ...Link2.style,
744
+ ...style || {}
745
+ },
746
+ children: text || children
747
+ });
748
+ }
749
+
688
750
  // src/Modal.tsx
689
751
  import { Modal } from "antd";
690
752
  import { useState as useState5 } from "react";
691
- import { jsx as jsx8 } from "react/jsx-runtime";
753
+ import { jsx as jsx9 } from "react/jsx-runtime";
692
754
  function useModal(init) {
693
755
  const [props, setProps] = useState5({
694
756
  visible: false,
@@ -699,7 +761,7 @@ function useModal(init) {
699
761
  ...init
700
762
  });
701
763
  return {
702
- modal: /* @__PURE__ */ jsx8(Modal, {
764
+ modal: /* @__PURE__ */ jsx9(Modal, {
703
765
  ...props
704
766
  }),
705
767
  modalProps: props,
@@ -721,10 +783,10 @@ import {
721
783
  Routes as OriginRoutes,
722
784
  Route
723
785
  } from "react-router-dom";
724
- import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
786
+ import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
725
787
  function NotFound() {
726
788
  const config = useConfigContext();
727
- return /* @__PURE__ */ jsx9(Result, {
789
+ return /* @__PURE__ */ jsx10(Result, {
728
790
  status: "404",
729
791
  title: config.common.pageNotFound
730
792
  });
@@ -732,21 +794,21 @@ function NotFound() {
732
794
  function Routes(props) {
733
795
  return /* @__PURE__ */ jsxs3(OriginRoutes, {
734
796
  children: [
735
- props.routes.map((r) => /* @__PURE__ */ jsx9(Route, {
797
+ props.routes.map((r) => /* @__PURE__ */ jsx10(Route, {
736
798
  ...r,
737
- element: r.element || /* @__PURE__ */ jsx9(Suspense, {
738
- fallback: props.fallback || /* @__PURE__ */ jsx9("div", {
799
+ element: r.element || /* @__PURE__ */ jsx10(Suspense, {
800
+ fallback: props.fallback || /* @__PURE__ */ jsx10("div", {
739
801
  style: { padding: "24px" },
740
- children: /* @__PURE__ */ jsx9(Skeleton2, {
802
+ children: /* @__PURE__ */ jsx10(Skeleton2, {
741
803
  active: true
742
804
  })
743
805
  }),
744
- children: /* @__PURE__ */ jsx9(r.page, {})
806
+ children: /* @__PURE__ */ jsx10(r.page, {})
745
807
  })
746
808
  }, r.path)),
747
- /* @__PURE__ */ jsx9(Route, {
809
+ /* @__PURE__ */ jsx10(Route, {
748
810
  path: "*",
749
- element: props.notFound || /* @__PURE__ */ jsx9(NotFound, {})
811
+ element: props.notFound || /* @__PURE__ */ jsx10(NotFound, {})
750
812
  }, "*")
751
813
  ]
752
814
  });
@@ -763,11 +825,11 @@ import {
763
825
  Radio,
764
826
  Skeleton as Skeleton3
765
827
  } from "antd";
766
- import dayjs2 from "dayjs";
828
+ import dayjs3 from "dayjs";
767
829
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
768
830
  import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
769
831
  import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
770
- import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
832
+ import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
771
833
  function processValue(item, value) {
772
834
  var _a;
773
835
  if (typeof value !== "undefined" && value !== null) {
@@ -792,7 +854,7 @@ function processValue(item, value) {
792
854
  if (["date", "time"].includes(item.type)) {
793
855
  if (typeof value === "number" && value.toString().length === 10)
794
856
  value = value * 1e3;
795
- value = dayjs2(value).format(dayjsFormat);
857
+ value = dayjs3(value).format(dayjsFormat);
796
858
  }
797
859
  }
798
860
  return value;
@@ -856,12 +918,12 @@ function Table(props) {
856
918
  item.onFilter = (value, row) => row[item.id].includes(value);
857
919
  break;
858
920
  case "boolean":
859
- item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ jsx10(Blank, {}) : value ? /* @__PURE__ */ jsx10(CheckOutlined2, {
921
+ item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ jsx11(Blank, {}) : value ? /* @__PURE__ */ jsx11(CheckOutlined2, {
860
922
  style: {
861
923
  marginTop: "4px",
862
924
  color: "#52c41a"
863
925
  }
864
- }) : /* @__PURE__ */ jsx10(CloseOutlined2, {
926
+ }) : /* @__PURE__ */ jsx11(CloseOutlined2, {
865
927
  style: {
866
928
  marginTop: "4px",
867
929
  color: "#ff4d4f"
@@ -881,28 +943,28 @@ function Table(props) {
881
943
  confirm();
882
944
  },
883
945
  children: [
884
- /* @__PURE__ */ jsx10(Radio.Button, {
946
+ /* @__PURE__ */ jsx11(Radio.Button, {
885
947
  children: config.common.all
886
948
  }),
887
- /* @__PURE__ */ jsx10(Radio.Button, {
949
+ /* @__PURE__ */ jsx11(Radio.Button, {
888
950
  value: "true",
889
- children: /* @__PURE__ */ jsx10(CheckOutlined2, {
951
+ children: /* @__PURE__ */ jsx11(CheckOutlined2, {
890
952
  style: {
891
953
  color: "#52c41a",
892
954
  verticalAlign: "middle"
893
955
  }
894
956
  })
895
957
  }),
896
- /* @__PURE__ */ jsx10(Radio.Button, {
958
+ /* @__PURE__ */ jsx11(Radio.Button, {
897
959
  value: "false",
898
- children: /* @__PURE__ */ jsx10(CloseOutlined2, {
960
+ children: /* @__PURE__ */ jsx11(CloseOutlined2, {
899
961
  style: {
900
962
  verticalAlign: "middle",
901
963
  color: "#ff4d4f"
902
964
  }
903
965
  })
904
966
  }),
905
- /* @__PURE__ */ jsx10(Radio.Button, {
967
+ /* @__PURE__ */ jsx11(Radio.Button, {
906
968
  value: "empty",
907
969
  children: config.common.blank
908
970
  })
@@ -925,12 +987,12 @@ function Table(props) {
925
987
  case "date":
926
988
  item.render = (value) => processValue(item, value);
927
989
  if (!item.onFilter)
928
- item.onFilter = (value, row) => dayjs2(row[item.id]).isSame(dayjs2(value));
990
+ item.onFilter = (value, row) => dayjs3(row[item.id]).isSame(dayjs3(value));
929
991
  break;
930
992
  case "time":
931
993
  item.render = (value) => processValue(item, value);
932
994
  if (!item.onFilter)
933
- item.onFilter = (value, row) => dayjs2(row[item.id]).isSame(dayjs2(value));
995
+ item.onFilter = (value, row) => dayjs3(row[item.id]).isSame(dayjs3(value));
934
996
  break;
935
997
  default:
936
998
  item.render = (value) => processValue(item, value);
@@ -944,14 +1006,14 @@ function Table(props) {
944
1006
  if (!columns)
945
1007
  return null;
946
1008
  if (!props.faasData)
947
- return /* @__PURE__ */ jsx10(AntdTable, {
1009
+ return /* @__PURE__ */ jsx11(AntdTable, {
948
1010
  ...props,
949
1011
  rowKey: props.rowKey || "id",
950
1012
  columns,
951
1013
  dataSource: props.dataSource
952
1014
  });
953
- return /* @__PURE__ */ jsx10(FaasDataWrapper2, {
954
- fallback: props.faasData.fallback || /* @__PURE__ */ jsx10(Skeleton3, {
1015
+ return /* @__PURE__ */ jsx11(FaasDataWrapper2, {
1016
+ fallback: props.faasData.fallback || /* @__PURE__ */ jsx11(Skeleton3, {
955
1017
  active: true
956
1018
  }),
957
1019
  render: ({
@@ -960,20 +1022,20 @@ function Table(props) {
960
1022
  reload
961
1023
  }) => {
962
1024
  if (!data)
963
- return /* @__PURE__ */ jsx10(AntdTable, {
1025
+ return /* @__PURE__ */ jsx11(AntdTable, {
964
1026
  ...props,
965
1027
  rowKey: props.rowKey || "id",
966
1028
  columns,
967
1029
  dataSource: []
968
1030
  });
969
1031
  if (Array.isArray(data))
970
- return /* @__PURE__ */ jsx10(AntdTable, {
1032
+ return /* @__PURE__ */ jsx11(AntdTable, {
971
1033
  ...props,
972
1034
  rowKey: props.rowKey || "id",
973
1035
  columns,
974
1036
  dataSource: data
975
1037
  });
976
- return /* @__PURE__ */ jsx10(AntdTable, {
1038
+ return /* @__PURE__ */ jsx11(AntdTable, {
977
1039
  ...props,
978
1040
  rowKey: props.rowKey || "id",
979
1041
  columns,
@@ -1008,7 +1070,7 @@ function Table(props) {
1008
1070
 
1009
1071
  // src/Title.tsx
1010
1072
  import { useEffect as useEffect5, cloneElement as cloneElement3 } from "react";
1011
- import { jsx as jsx11 } from "react/jsx-runtime";
1073
+ import { jsx as jsx12 } from "react/jsx-runtime";
1012
1074
  function Title(props) {
1013
1075
  const config = useConfigContext();
1014
1076
  useEffect5(() => {
@@ -1017,10 +1079,10 @@ function Title(props) {
1017
1079
  }, []);
1018
1080
  if (props.h1) {
1019
1081
  if (typeof props.h1 === "boolean")
1020
- return /* @__PURE__ */ jsx11("h1", {
1082
+ return /* @__PURE__ */ jsx12("h1", {
1021
1083
  children: Array.isArray(props.title) ? props.title[0] : props.title
1022
1084
  });
1023
- return /* @__PURE__ */ jsx11("h1", {
1085
+ return /* @__PURE__ */ jsx12("h1", {
1024
1086
  className: props.h1.className,
1025
1087
  style: props.h1.style,
1026
1088
  children: Array.isArray(props.title) ? props.title[0] : props.title
@@ -1040,6 +1102,7 @@ export {
1040
1102
  Drawer,
1041
1103
  Form,
1042
1104
  FormItem,
1105
+ Link,
1043
1106
  Modal,
1044
1107
  Routes,
1045
1108
  Table,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.405",
3
+ "version": "0.0.2-beta.407",
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.405",
31
+ "@faasjs/react": "^0.0.2-beta.407",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },