@faasjs/ant-design 2.7.0 → 2.8.0

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
@@ -109,3 +109,4 @@ type FaasItemProps = {
109
109
  - [useDrawer](functions/useDrawer.md)
110
110
  - [useFaas](functions/useFaas.md)
111
111
  - [useModal](functions/useModal.md)
112
+ - [withFaasData](functions/withFaasData.md)
package/dist/index.d.mts CHANGED
@@ -9,13 +9,14 @@ import * as antd_es_modal_PurePanel from 'antd/es/modal/PurePanel';
9
9
  import * as antd_es_modal_useModal from 'antd/es/modal/useModal';
10
10
  import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
11
11
  import * as react from 'react';
12
- import { Dispatch, SetStateAction, CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
12
+ import { Dispatch, SetStateAction, CSSProperties, ComponentProps, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
13
13
  export { lazy } from 'react';
14
14
  import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, FormInstance, InputProps, SelectProps, RadioProps, InputNumberProps, SwitchProps, DatePickerProps, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
15
15
  import { BrowserRouterProps, RouteProps } from 'react-router-dom';
16
16
  import { Dayjs } from 'dayjs';
17
17
  import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
18
18
  import { RuleObject } from 'rc-field-form/lib/interface';
19
+ import { FaasAction } from '@faasjs/types';
19
20
  import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface';
20
21
  import * as antd_es_form_context from 'antd/es/form/context';
21
22
  import * as antd_es_form from 'antd/es/form';
@@ -384,6 +385,15 @@ declare function FaasDataWrapper<T = any>(props: FaasDataWrapperProps<T>): JSX.E
384
385
  declare namespace FaasDataWrapper {
385
386
  var whyDidYouRender: boolean;
386
387
  }
388
+ /**
389
+ * HOC to wrap a component with FaasDataWrapper and Loading
390
+ *
391
+ * @example
392
+ * ```tsx
393
+ * const MyComponent = withFaasData(MyComponent, { action: 'test', params: { a: 1 } })
394
+ * ```
395
+ */
396
+ declare function withFaasData<TComponent extends React.FC<any>, PathOrData extends FaasAction>(Component: TComponent, faasProps: FaasDataWrapperProps<PathOrData>): (props: ComponentProps<TComponent> & {}) => react_jsx_runtime.JSX.Element;
387
397
 
388
398
  interface ExtendDescriptionTypeProps<T = any> {
389
399
  children?: UnionFaasItemElement<T>;
@@ -604,7 +614,7 @@ interface LinkProps {
604
614
  text?: string | number;
605
615
  children?: ReactNode;
606
616
  style?: CSSProperties;
607
- button?: ButtonProps;
617
+ button?: ButtonProps | boolean;
608
618
  block?: boolean;
609
619
  /** only use for text without button */
610
620
  copyable?: boolean;
@@ -737,4 +747,4 @@ declare namespace Title {
737
747
  var whyDidYouRender: boolean;
738
748
  }
739
749
 
740
- export { App, type AppProps, type BaseItemProps, type BaseOption, Blank, type BlankProps, ConfigContext, ConfigProvider, type ConfigProviderProps, Description, type DescriptionItemContentProps, type DescriptionItemProps, type DescriptionProps, Drawer, type DrawerProps, ErrorBoundary, type ExtendDescriptionItemProps, type ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, type ExtendTableItemProps, type ExtendTableTypeProps, type ExtendTypes, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasItemProps, type FaasItemType, type FaasItemTypeValue, Form, FormItem, type FormItemProps, type FormProps, type FormSubmitProps, Link, type LinkProps, Loading, type LoadingProps, Modal, type ModalProps, PageNotFound, Routes, type RoutesProps, type TabProps, Table, type TableItemProps, type TableProps, Tabs, type TabsProps, Title, type TitleProps, type UnionFaasItemElement, type UnionFaasItemInjection, type UnionFaasItemProps, type UnionFaasItemRender, type UnionScene, type setDrawerProps, type setModalProps, transferOptions, transferValue, useApp, type useAppProps, useConfigContext, useDrawer, useModal };
750
+ export { App, type AppProps, type BaseItemProps, type BaseOption, Blank, type BlankProps, ConfigContext, ConfigProvider, type ConfigProviderProps, Description, type DescriptionItemContentProps, type DescriptionItemProps, type DescriptionProps, Drawer, type DrawerProps, ErrorBoundary, type ExtendDescriptionItemProps, type ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, type ExtendTableItemProps, type ExtendTableTypeProps, type ExtendTypes, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasItemProps, type FaasItemType, type FaasItemTypeValue, Form, FormItem, type FormItemProps, type FormProps, type FormSubmitProps, Link, type LinkProps, Loading, type LoadingProps, Modal, type ModalProps, PageNotFound, Routes, type RoutesProps, type TabProps, Table, type TableItemProps, type TableProps, Tabs, type TabsProps, Title, type TitleProps, type UnionFaasItemElement, type UnionFaasItemInjection, type UnionFaasItemProps, type UnionFaasItemRender, type UnionScene, type setDrawerProps, type setModalProps, transferOptions, transferValue, useApp, type useAppProps, useConfigContext, useDrawer, useModal, withFaasData };
package/dist/index.d.ts CHANGED
@@ -9,13 +9,14 @@ import * as antd_es_modal_PurePanel from 'antd/es/modal/PurePanel';
9
9
  import * as antd_es_modal_useModal from 'antd/es/modal/useModal';
10
10
  import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
11
11
  import * as react from 'react';
12
- import { Dispatch, SetStateAction, CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
12
+ import { Dispatch, SetStateAction, CSSProperties, ComponentProps, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
13
13
  export { lazy } from 'react';
14
14
  import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, FormInstance, InputProps, SelectProps, RadioProps, InputNumberProps, SwitchProps, DatePickerProps, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
15
15
  import { BrowserRouterProps, RouteProps } from 'react-router-dom';
16
16
  import { Dayjs } from 'dayjs';
17
17
  import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
18
18
  import { RuleObject } from 'rc-field-form/lib/interface';
19
+ import { FaasAction } from '@faasjs/types';
19
20
  import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface';
20
21
  import * as antd_es_form_context from 'antd/es/form/context';
21
22
  import * as antd_es_form from 'antd/es/form';
@@ -384,6 +385,15 @@ declare function FaasDataWrapper<T = any>(props: FaasDataWrapperProps<T>): JSX.E
384
385
  declare namespace FaasDataWrapper {
385
386
  var whyDidYouRender: boolean;
386
387
  }
388
+ /**
389
+ * HOC to wrap a component with FaasDataWrapper and Loading
390
+ *
391
+ * @example
392
+ * ```tsx
393
+ * const MyComponent = withFaasData(MyComponent, { action: 'test', params: { a: 1 } })
394
+ * ```
395
+ */
396
+ declare function withFaasData<TComponent extends React.FC<any>, PathOrData extends FaasAction>(Component: TComponent, faasProps: FaasDataWrapperProps<PathOrData>): (props: ComponentProps<TComponent> & {}) => react_jsx_runtime.JSX.Element;
387
397
 
388
398
  interface ExtendDescriptionTypeProps<T = any> {
389
399
  children?: UnionFaasItemElement<T>;
@@ -604,7 +614,7 @@ interface LinkProps {
604
614
  text?: string | number;
605
615
  children?: ReactNode;
606
616
  style?: CSSProperties;
607
- button?: ButtonProps;
617
+ button?: ButtonProps | boolean;
608
618
  block?: boolean;
609
619
  /** only use for text without button */
610
620
  copyable?: boolean;
@@ -737,4 +747,4 @@ declare namespace Title {
737
747
  var whyDidYouRender: boolean;
738
748
  }
739
749
 
740
- export { App, type AppProps, type BaseItemProps, type BaseOption, Blank, type BlankProps, ConfigContext, ConfigProvider, type ConfigProviderProps, Description, type DescriptionItemContentProps, type DescriptionItemProps, type DescriptionProps, Drawer, type DrawerProps, ErrorBoundary, type ExtendDescriptionItemProps, type ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, type ExtendTableItemProps, type ExtendTableTypeProps, type ExtendTypes, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasItemProps, type FaasItemType, type FaasItemTypeValue, Form, FormItem, type FormItemProps, type FormProps, type FormSubmitProps, Link, type LinkProps, Loading, type LoadingProps, Modal, type ModalProps, PageNotFound, Routes, type RoutesProps, type TabProps, Table, type TableItemProps, type TableProps, Tabs, type TabsProps, Title, type TitleProps, type UnionFaasItemElement, type UnionFaasItemInjection, type UnionFaasItemProps, type UnionFaasItemRender, type UnionScene, type setDrawerProps, type setModalProps, transferOptions, transferValue, useApp, type useAppProps, useConfigContext, useDrawer, useModal };
750
+ export { App, type AppProps, type BaseItemProps, type BaseOption, Blank, type BlankProps, ConfigContext, ConfigProvider, type ConfigProviderProps, Description, type DescriptionItemContentProps, type DescriptionItemProps, type DescriptionProps, Drawer, type DrawerProps, ErrorBoundary, type ExtendDescriptionItemProps, type ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, type ExtendTableItemProps, type ExtendTableTypeProps, type ExtendTypes, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasItemProps, type FaasItemType, type FaasItemTypeValue, Form, FormItem, type FormItemProps, type FormProps, type FormSubmitProps, Link, type LinkProps, Loading, type LoadingProps, Modal, type ModalProps, PageNotFound, Routes, type RoutesProps, type TabProps, Table, type TableItemProps, type TableProps, Tabs, type TabsProps, Title, type TitleProps, type UnionFaasItemElement, type UnionFaasItemInjection, type UnionFaasItemProps, type UnionFaasItemRender, type UnionScene, type setDrawerProps, type setModalProps, transferOptions, transferValue, useApp, type useAppProps, useConfigContext, useDrawer, useModal, withFaasData };
package/dist/index.js CHANGED
@@ -307,6 +307,9 @@ function FaasDataWrapper(props) {
307
307
  );
308
308
  }
309
309
  FaasDataWrapper.whyDidYouRender = true;
310
+ function withFaasData(Component, faasProps) {
311
+ return (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props }) });
312
+ }
310
313
  function DescriptionItemContent(props) {
311
314
  var _a, _b;
312
315
  const [computedProps, setComputedProps] = react$1.useState();
@@ -891,9 +894,10 @@ Form.List = antd.Form.List;
891
894
  Form.ErrorList = antd.Form.ErrorList;
892
895
  Form.Provider = antd.Form.Provider;
893
896
  function Link(props) {
894
- var _a, _b, _c, _d, _e, _f, _g;
897
+ var _a, _b, _c;
895
898
  const { theme } = useConfigContext();
896
899
  const navigate = reactRouterDom.useNavigate();
900
+ const target = props.target || ((_a = theme.Link) == null ? void 0 : _a.target) || (props.href.startsWith("http") ? "_blank" : void 0);
897
901
  let computedStyle = {
898
902
  ...theme.Link.style || {},
899
903
  cursor: "pointer",
@@ -907,85 +911,39 @@ function Link(props) {
907
911
  },
908
912
  computedStyle
909
913
  );
910
- if (props.href.startsWith("http")) {
911
- if (props.button)
912
- return /* @__PURE__ */ jsxRuntime.jsx(
913
- antd.Button,
914
- {
915
- ...props.button,
916
- target: props.target || ((_a = theme.Link) == null ? void 0 : _a.target) || "_blank",
917
- style: computedStyle,
918
- href: props.href,
919
- onClick: props.onClick,
920
- children: (_b = props.text) != null ? _b : props.children
921
- }
922
- );
923
- if (props.children)
924
- return /* @__PURE__ */ jsxRuntime.jsx(
925
- "a",
926
- {
927
- href: props.href,
928
- target: props.target || ((_c = theme.Link) == null ? void 0 : _c.target),
929
- style: computedStyle,
930
- onClick: props.onClick,
931
- children: props.children
932
- }
933
- );
934
- return /* @__PURE__ */ jsxRuntime.jsx(
935
- antd.Typography.Link,
936
- {
937
- href: props.href,
938
- target: props.target || ((_d = theme.Link) == null ? void 0 : _d.target) || "_blank",
939
- style: computedStyle,
940
- copyable: props.copyable,
941
- onClick: props.onClick,
942
- children: props.text
943
- }
944
- );
945
- }
946
914
  if (props.button)
947
915
  return /* @__PURE__ */ jsxRuntime.jsx(
948
916
  antd.Button,
949
917
  {
950
- ...props.button,
918
+ ...props.button || {},
951
919
  style: computedStyle,
952
920
  onClick: (e) => {
953
- var _a2;
954
- return props.onClick ? props.onClick(e) : (props.target || ((_a2 = theme.Link) == null ? void 0 : _a2.target)) === "_blank" ? window.open(props.href) : navigate(props.href);
921
+ props.onClick ? props.onClick(e) : target === "_blank" ? window.open(props.href) : navigate(props.href);
922
+ e.preventDefault();
955
923
  },
956
- children: (_e = props.text) != null ? _e : props.children
957
- }
958
- );
959
- if (props.children)
960
- return /* @__PURE__ */ jsxRuntime.jsx(
961
- reactRouterDom.Link,
962
- {
963
- to: props.href,
964
- target: props.target || ((_f = theme.Link) == null ? void 0 : _f.target),
965
- style: computedStyle,
966
- onClick: props.onClick,
967
- children: props.children
924
+ children: (_b = props.children) != null ? _b : props.text
968
925
  }
969
926
  );
970
927
  return /* @__PURE__ */ jsxRuntime.jsx(
971
928
  antd.Typography.Link,
972
929
  {
973
930
  href: props.href,
974
- target: props.target || ((_g = theme.Link) == null ? void 0 : _g.target),
931
+ target,
975
932
  style: computedStyle,
976
933
  copyable: props.copyable,
977
934
  onClick: (e) => {
978
- var _a2;
935
+ e.preventDefault();
979
936
  if (props.onClick) {
980
937
  props.onClick(e);
981
938
  return;
982
939
  }
983
- if ((props.target || ((_a2 = theme.Link) == null ? void 0 : _a2.target)) !== "_blank") {
984
- e.preventDefault();
985
- navigate(props.href);
940
+ if (target === "_blank") {
941
+ window.open(props.href);
942
+ return;
986
943
  }
944
+ navigate(props.href);
987
945
  },
988
- children: props.text
946
+ children: (_c = props.children) != null ? _c : props.text
989
947
  }
990
948
  );
991
949
  }
@@ -1649,3 +1607,4 @@ exports.useApp = useApp;
1649
1607
  exports.useConfigContext = useConfigContext;
1650
1608
  exports.useDrawer = useDrawer;
1651
1609
  exports.useModal = useModal;
1610
+ exports.withFaasData = withFaasData;
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { legacyLogicalPropertiesTransformer, StyleProvider } from '@ant-design/c
5
5
  import { createContext, useState, useCallback, useEffect, useContext, useMemo, cloneElement, Suspense } from 'react';
6
6
  export { lazy } from 'react';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
- import { BrowserRouter, useNavigate, Link as Link$1, Routes as Routes$1, Route, useLocation } from 'react-router-dom';
8
+ import { BrowserRouter, useNavigate, Routes as Routes$1, Route, useLocation } from 'react-router-dom';
9
9
  import { defaultsDeep, isNil, upperFirst, isFunction, cloneDeep, uniqBy } from 'lodash-es';
10
10
  import dayjs2 from 'dayjs';
11
11
  import { PlusOutlined, MinusCircleOutlined, CheckOutlined, CloseOutlined } from '@ant-design/icons';
@@ -303,6 +303,9 @@ function FaasDataWrapper(props) {
303
303
  );
304
304
  }
305
305
  FaasDataWrapper.whyDidYouRender = true;
306
+ function withFaasData(Component, faasProps) {
307
+ return (props) => /* @__PURE__ */ jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsx(Component, { ...props }) });
308
+ }
306
309
  function DescriptionItemContent(props) {
307
310
  var _a, _b;
308
311
  const [computedProps, setComputedProps] = useState();
@@ -887,9 +890,10 @@ Form.List = Form$1.List;
887
890
  Form.ErrorList = Form$1.ErrorList;
888
891
  Form.Provider = Form$1.Provider;
889
892
  function Link(props) {
890
- var _a, _b, _c, _d, _e, _f, _g;
893
+ var _a, _b, _c;
891
894
  const { theme } = useConfigContext();
892
895
  const navigate = useNavigate();
896
+ const target = props.target || ((_a = theme.Link) == null ? void 0 : _a.target) || (props.href.startsWith("http") ? "_blank" : void 0);
893
897
  let computedStyle = {
894
898
  ...theme.Link.style || {},
895
899
  cursor: "pointer",
@@ -903,85 +907,39 @@ function Link(props) {
903
907
  },
904
908
  computedStyle
905
909
  );
906
- if (props.href.startsWith("http")) {
907
- if (props.button)
908
- return /* @__PURE__ */ jsx(
909
- Button,
910
- {
911
- ...props.button,
912
- target: props.target || ((_a = theme.Link) == null ? void 0 : _a.target) || "_blank",
913
- style: computedStyle,
914
- href: props.href,
915
- onClick: props.onClick,
916
- children: (_b = props.text) != null ? _b : props.children
917
- }
918
- );
919
- if (props.children)
920
- return /* @__PURE__ */ jsx(
921
- "a",
922
- {
923
- href: props.href,
924
- target: props.target || ((_c = theme.Link) == null ? void 0 : _c.target),
925
- style: computedStyle,
926
- onClick: props.onClick,
927
- children: props.children
928
- }
929
- );
930
- return /* @__PURE__ */ jsx(
931
- Typography.Link,
932
- {
933
- href: props.href,
934
- target: props.target || ((_d = theme.Link) == null ? void 0 : _d.target) || "_blank",
935
- style: computedStyle,
936
- copyable: props.copyable,
937
- onClick: props.onClick,
938
- children: props.text
939
- }
940
- );
941
- }
942
910
  if (props.button)
943
911
  return /* @__PURE__ */ jsx(
944
912
  Button,
945
913
  {
946
- ...props.button,
914
+ ...props.button || {},
947
915
  style: computedStyle,
948
916
  onClick: (e) => {
949
- var _a2;
950
- return props.onClick ? props.onClick(e) : (props.target || ((_a2 = theme.Link) == null ? void 0 : _a2.target)) === "_blank" ? window.open(props.href) : navigate(props.href);
917
+ props.onClick ? props.onClick(e) : target === "_blank" ? window.open(props.href) : navigate(props.href);
918
+ e.preventDefault();
951
919
  },
952
- children: (_e = props.text) != null ? _e : props.children
953
- }
954
- );
955
- if (props.children)
956
- return /* @__PURE__ */ jsx(
957
- Link$1,
958
- {
959
- to: props.href,
960
- target: props.target || ((_f = theme.Link) == null ? void 0 : _f.target),
961
- style: computedStyle,
962
- onClick: props.onClick,
963
- children: props.children
920
+ children: (_b = props.children) != null ? _b : props.text
964
921
  }
965
922
  );
966
923
  return /* @__PURE__ */ jsx(
967
924
  Typography.Link,
968
925
  {
969
926
  href: props.href,
970
- target: props.target || ((_g = theme.Link) == null ? void 0 : _g.target),
927
+ target,
971
928
  style: computedStyle,
972
929
  copyable: props.copyable,
973
930
  onClick: (e) => {
974
- var _a2;
931
+ e.preventDefault();
975
932
  if (props.onClick) {
976
933
  props.onClick(e);
977
934
  return;
978
935
  }
979
- if ((props.target || ((_a2 = theme.Link) == null ? void 0 : _a2.target)) !== "_blank") {
980
- e.preventDefault();
981
- navigate(props.href);
936
+ if (target === "_blank") {
937
+ window.open(props.href);
938
+ return;
982
939
  }
940
+ navigate(props.href);
983
941
  },
984
- children: props.text
942
+ children: (_c = props.children) != null ? _c : props.text
985
943
  }
986
944
  );
987
945
  }
@@ -1609,4 +1567,4 @@ function Title(props) {
1609
1567
  }
1610
1568
  Title.whyDidYouRender = true;
1611
1569
 
1612
- export { App, Blank, ConfigContext, ConfigProvider, Description, Drawer, ErrorBoundary, FaasDataWrapper, Form, FormItem, Link, Loading, Modal, PageNotFound, Routes, Table, Tabs, Title, transferOptions, transferValue, useApp, useConfigContext, useDrawer, useModal };
1570
+ export { App, Blank, ConfigContext, ConfigProvider, Description, Drawer, ErrorBoundary, FaasDataWrapper, Form, FormItem, Link, Loading, Modal, PageNotFound, Routes, Table, Tabs, Title, transferOptions, transferValue, useApp, useConfigContext, useDrawer, useModal, withFaasData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -38,7 +38,7 @@
38
38
  "lodash-es": "*"
39
39
  },
40
40
  "peerDependencies": {
41
- "@faasjs/react": "2.7.0",
41
+ "@faasjs/react": "2.8.0",
42
42
  "antd": "*",
43
43
  "react": "*",
44
44
  "react-dom": "*",
@@ -46,11 +46,7 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/lodash-es": "*",
49
- "@testing-library/jest-dom": "*",
50
- "@testing-library/react": "*",
51
- "@testing-library/user-event": "*",
52
- "@welldone-software/why-did-you-render": "*",
53
- "@faasjs/react": "2.7.0",
49
+ "@faasjs/react": "2.8.0",
54
50
  "antd": "*",
55
51
  "react": "*",
56
52
  "react-dom": "*",