@faasjs/ant-design 1.5.0 → 1.6.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
@@ -88,12 +88,14 @@ type FaasItemProps = {
88
88
  - [Blank](functions/Blank.md)
89
89
  - [ConfigProvider](functions/ConfigProvider.md)
90
90
  - [Description](functions/Description.md)
91
+ - [Drawer](functions/Drawer.md)
91
92
  - [ErrorBoundary](functions/ErrorBoundary.md)
92
93
  - [FaasDataWrapper](functions/FaasDataWrapper.md)
93
94
  - [Form](functions/Form.md)
94
95
  - [FormItem](functions/FormItem.md)
95
96
  - [Link](functions/Link.md)
96
97
  - [Loading](functions/Loading.md)
98
+ - [Modal](functions/Modal.md)
97
99
  - [PageNotFound](functions/PageNotFound.md)
98
100
  - [Routes](functions/Routes.md)
99
101
  - [Table](functions/Table.md)
package/dist/index.d.mts CHANGED
@@ -79,7 +79,7 @@ type setDrawerProps = (changes: Partial<DrawerProps> | ((prev: Partial<DrawerPro
79
79
  declare function useDrawer(init?: DrawerProps): {
80
80
  drawer: react_jsx_runtime.JSX.Element;
81
81
  drawerProps: DrawerProps;
82
- setDrawerProps(changes: Parameters<setDrawerProps>[0]): void;
82
+ setDrawerProps: setDrawerProps;
83
83
  };
84
84
 
85
85
  /**
@@ -158,7 +158,9 @@ interface AppProps {
158
158
  interface useAppProps {
159
159
  message: MessageInstance;
160
160
  notification: NotificationInstance;
161
+ modalProps: ModalProps;
161
162
  setModalProps: (changes: Partial<ModalProps>) => void;
163
+ drawerProps: DrawerProps;
162
164
  setDrawerProps: (changes: Partial<DrawerProps>) => void;
163
165
  }
164
166
  /**
@@ -202,7 +204,7 @@ declare namespace App {
202
204
  * const { message, notification, setModalProps, setDrawerProps } = useApp()
203
205
  * ```
204
206
  */
205
- declare function useApp(): useAppProps;
207
+ declare function useApp(): Readonly<useAppProps>;
206
208
 
207
209
  interface BlankProps {
208
210
  value?: any;
package/dist/index.d.ts CHANGED
@@ -79,7 +79,7 @@ type setDrawerProps = (changes: Partial<DrawerProps> | ((prev: Partial<DrawerPro
79
79
  declare function useDrawer(init?: DrawerProps): {
80
80
  drawer: react_jsx_runtime.JSX.Element;
81
81
  drawerProps: DrawerProps;
82
- setDrawerProps(changes: Parameters<setDrawerProps>[0]): void;
82
+ setDrawerProps: setDrawerProps;
83
83
  };
84
84
 
85
85
  /**
@@ -158,7 +158,9 @@ interface AppProps {
158
158
  interface useAppProps {
159
159
  message: MessageInstance;
160
160
  notification: NotificationInstance;
161
+ modalProps: ModalProps;
161
162
  setModalProps: (changes: Partial<ModalProps>) => void;
163
+ drawerProps: DrawerProps;
162
164
  setDrawerProps: (changes: Partial<DrawerProps>) => void;
163
165
  }
164
166
  /**
@@ -202,7 +204,7 @@ declare namespace App {
202
204
  * const { message, notification, setModalProps, setDrawerProps } = useApp()
203
205
  * ```
204
206
  */
205
- declare function useApp(): useAppProps;
207
+ declare function useApp(): Readonly<useAppProps>;
206
208
 
207
209
  interface BlankProps {
208
210
  value?: any;
package/dist/index.js CHANGED
@@ -19,61 +19,57 @@ var Modal = antd.Modal;
19
19
  Modal.whyDidYouRender = true;
20
20
  function useModal(init) {
21
21
  const [props, setProps] = react$1.useState({ open: false, ...init });
22
- const onCancel = react$1.useCallback(() => {
23
- setProps((prev) => ({
24
- ...prev,
25
- open: false
26
- }));
27
- }, []);
28
- const modal = react$1.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx(Modal, { onCancel, ...props }), [props]);
29
- const setModalProps = react$1.useCallback((changes) => {
30
- if (typeof changes === "function") {
31
- setProps((prev) => ({
32
- ...prev,
33
- ...changes(props)
34
- }));
35
- return;
36
- }
37
- setProps((prev) => ({
38
- ...prev,
39
- ...changes
40
- }));
41
- }, []);
22
+ const setModalProps2 = react$1.useCallback(
23
+ (changes) => {
24
+ const changed = typeof changes === "function" ? changes(props) : changes;
25
+ setProps((prev) => ({ ...prev, ...changed }));
26
+ },
27
+ [setProps]
28
+ );
42
29
  return {
43
- modal,
30
+ modal: /* @__PURE__ */ jsxRuntime.jsx(
31
+ Modal,
32
+ {
33
+ onCancel: () => setProps((prev) => ({
34
+ ...prev,
35
+ open: false
36
+ })),
37
+ ...props
38
+ }
39
+ ),
44
40
  modalProps: props,
45
- setModalProps
41
+ setModalProps: setModalProps2
46
42
  };
47
43
  }
48
44
  var Drawer = antd.Drawer;
45
+ Drawer.whyDidYouRender = true;
49
46
  function useDrawer(init) {
50
47
  const [props, setProps] = react$1.useState({
51
48
  open: false,
52
- onClose: () => setProps((prev) => ({
53
- ...prev,
54
- open: false
55
- })),
56
49
  ...init
57
50
  });
51
+ const setDrawerProps2 = react$1.useCallback(
52
+ (changes) => {
53
+ const changed = typeof changes === "function" ? changes(props) : changes;
54
+ setProps((prev) => ({ ...prev, ...changed }));
55
+ },
56
+ [setProps]
57
+ );
58
58
  return {
59
- drawer: /* @__PURE__ */ jsxRuntime.jsx(Drawer, { ...props }),
60
- drawerProps: props,
61
- setDrawerProps(changes) {
62
- if (typeof changes === "function") {
63
- setProps((prev) => ({
59
+ drawer: /* @__PURE__ */ jsxRuntime.jsx(
60
+ Drawer,
61
+ {
62
+ onClose: () => setProps((prev) => ({
64
63
  ...prev,
65
- ...changes(props)
66
- }));
67
- return;
64
+ open: false
65
+ })),
66
+ ...props
68
67
  }
69
- setProps((prev) => ({
70
- ...prev,
71
- ...changes
72
- }));
73
- }
68
+ ),
69
+ drawerProps: props,
70
+ setDrawerProps: setDrawerProps2
74
71
  };
75
72
  }
76
- Drawer.whyDidYouRender = true;
77
73
  function ErrorChildren(props) {
78
74
  return /* @__PURE__ */ jsxRuntime.jsx(
79
75
  antd.Alert,
@@ -166,36 +162,31 @@ function ConfigProvider(props) {
166
162
  function useConfigContext() {
167
163
  return react$1.useContext(ConfigContext);
168
164
  }
169
- var AppContext = react$1.createContext({
170
- message: {},
171
- notification: {},
172
- setModalProps: () => void 0,
173
- setDrawerProps: () => void 0
174
- });
165
+ var MessageContext = react$1.createContext({});
166
+ var NotificationContext = react$1.createContext(
167
+ {}
168
+ );
169
+ var ModalPropsContext = react$1.createContext({});
170
+ var SetModalPropsContext = react$1.createContext(() => void 0);
171
+ var DrawerPropsContext = react$1.createContext({});
172
+ var SetDrawerPropsContext = react$1.createContext(() => void 0);
175
173
  function RoutesApp(props) {
176
174
  const location = reactRouterDom.useLocation();
177
- const { setDrawerProps, setModalProps } = useApp();
175
+ const { drawerProps, setDrawerProps: setDrawerProps2, modalProps, setModalProps: setModalProps2 } = useApp();
178
176
  react$1.useEffect(() => {
179
177
  console.debug("location", location);
180
- setDrawerProps({ open: false });
181
- setModalProps({ open: false });
178
+ if (drawerProps.open)
179
+ setDrawerProps2({ open: false });
180
+ if (modalProps.open)
181
+ setModalProps2({ open: false });
182
182
  }, [location]);
183
183
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
184
184
  }
185
185
  function App(props) {
186
186
  const [messageApi, messageContextHolder] = antd.message.useMessage();
187
187
  const [notificationApi, notificationContextHolder] = antd.notification.useNotification();
188
- const { modal, modalProps, setModalProps } = useModal();
189
- const { drawer, setDrawerProps } = useDrawer();
190
- const memoizedContextValue = react$1.useMemo(
191
- () => ({
192
- message: messageApi,
193
- notification: notificationApi,
194
- setModalProps,
195
- setDrawerProps
196
- }),
197
- [messageApi, notificationApi, setModalProps, setDrawerProps]
198
- );
188
+ const { modal, modalProps, setModalProps: setModalProps2 } = useModal();
189
+ const { drawer, drawerProps, setDrawerProps: setDrawerProps2 } = useDrawer();
199
190
  const styleProviderProps = react$1.useMemo(
200
191
  () => ({
201
192
  ...props.styleProviderProps,
@@ -204,16 +195,37 @@ function App(props) {
204
195
  }),
205
196
  [props.styleProviderProps]
206
197
  );
207
- return /* @__PURE__ */ jsxRuntime.jsx(cssinjs.StyleProvider, { ...styleProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.ConfigProvider, { ...props.configProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(AppContext.Provider, { value: memoizedContextValue, children: /* @__PURE__ */ jsxRuntime.jsx(ConfigProvider, { ...props.faasConfigProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.BrowserRouter, { ...props.browserRouterProps, children: [
198
+ return /* @__PURE__ */ jsxRuntime.jsx(cssinjs.StyleProvider, { ...styleProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.ConfigProvider, { ...props.configProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(MessageContext.Provider, { value: messageApi, children: /* @__PURE__ */ jsxRuntime.jsx(NotificationContext.Provider, { value: notificationApi, children: /* @__PURE__ */ jsxRuntime.jsx(DrawerPropsContext.Provider, { value: drawerProps, children: /* @__PURE__ */ jsxRuntime.jsx(SetDrawerPropsContext.Provider, { value: setDrawerProps2, children: /* @__PURE__ */ jsxRuntime.jsx(ModalPropsContext.Provider, { value: modalProps, children: /* @__PURE__ */ jsxRuntime.jsx(SetModalPropsContext.Provider, { value: setModalProps2, children: /* @__PURE__ */ jsxRuntime.jsx(ConfigProvider, { ...props.faasConfigProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.BrowserRouter, { ...props.browserRouterProps, children: [
208
199
  messageContextHolder,
209
200
  notificationContextHolder,
210
201
  modal,
211
202
  drawer,
212
203
  /* @__PURE__ */ jsxRuntime.jsx(RoutesApp, { children: props.children })
213
- ] }) }) }) }) }) });
204
+ ] }) }) }) }) }) }) }) }) }) }) });
214
205
  }
215
206
  function useApp() {
216
- return react$1.useContext(AppContext);
207
+ return react.useConstant(() => {
208
+ const obj = /* @__PURE__ */ Object.create(null);
209
+ Object.defineProperty(obj, "message", {
210
+ get: () => react$1.useContext(MessageContext)
211
+ });
212
+ Object.defineProperty(obj, "notification", {
213
+ get: () => react$1.useContext(NotificationContext)
214
+ });
215
+ Object.defineProperty(obj, "modalProps", {
216
+ get: () => react$1.useContext(ModalPropsContext)
217
+ });
218
+ Object.defineProperty(obj, "setModalProps", {
219
+ get: () => react$1.useContext(SetModalPropsContext)
220
+ });
221
+ Object.defineProperty(obj, "drawerProps", {
222
+ get: () => react$1.useContext(DrawerPropsContext)
223
+ });
224
+ Object.defineProperty(obj, "setDrawerProps", {
225
+ get: () => react$1.useContext(SetDrawerPropsContext)
226
+ });
227
+ return Object.freeze(obj);
228
+ });
217
229
  }
218
230
  App.useApp = useApp;
219
231
  App.whyDidYouRender = true;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { ErrorBoundary as ErrorBoundary$1, FaasReactClient, FaasDataWrapper as FaasDataWrapper$1, faas } from '@faasjs/react';
1
+ import { ErrorBoundary as ErrorBoundary$1, FaasReactClient, useConstant, FaasDataWrapper as FaasDataWrapper$1, faas } from '@faasjs/react';
2
2
  export { faas, useFaas } from '@faasjs/react';
3
3
  import { Form as Form$1, Modal as Modal$1, Drawer as Drawer$1, message, notification, ConfigProvider as ConfigProvider$1, Typography, Spin, Descriptions, Input, Button, Row, Col, DatePicker, Switch, Select, InputNumber, Radio, Result, Skeleton, Table as Table$1, Tabs as Tabs$1, Alert, Space } from 'antd';
4
4
  import { legacyLogicalPropertiesTransformer, StyleProvider } from '@ant-design/cssinjs';
5
- import { createContext, useState, useCallback, useMemo, useEffect, useContext, cloneElement, isValidElement, Suspense } from 'react';
5
+ import { createContext, useState, useCallback, useEffect, useContext, useMemo, cloneElement, isValidElement, Suspense } from 'react';
6
6
  export { lazy } from 'react';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
8
  import { BrowserRouter, useNavigate, Link as Link$1, Routes as Routes$1, Route, useLocation } from 'react-router-dom';
@@ -15,61 +15,57 @@ var Modal = Modal$1;
15
15
  Modal.whyDidYouRender = true;
16
16
  function useModal(init) {
17
17
  const [props, setProps] = useState({ open: false, ...init });
18
- const onCancel = useCallback(() => {
19
- setProps((prev) => ({
20
- ...prev,
21
- open: false
22
- }));
23
- }, []);
24
- const modal = useMemo(() => /* @__PURE__ */ jsx(Modal, { onCancel, ...props }), [props]);
25
- const setModalProps = useCallback((changes) => {
26
- if (typeof changes === "function") {
27
- setProps((prev) => ({
28
- ...prev,
29
- ...changes(props)
30
- }));
31
- return;
32
- }
33
- setProps((prev) => ({
34
- ...prev,
35
- ...changes
36
- }));
37
- }, []);
18
+ const setModalProps2 = useCallback(
19
+ (changes) => {
20
+ const changed = typeof changes === "function" ? changes(props) : changes;
21
+ setProps((prev) => ({ ...prev, ...changed }));
22
+ },
23
+ [setProps]
24
+ );
38
25
  return {
39
- modal,
26
+ modal: /* @__PURE__ */ jsx(
27
+ Modal,
28
+ {
29
+ onCancel: () => setProps((prev) => ({
30
+ ...prev,
31
+ open: false
32
+ })),
33
+ ...props
34
+ }
35
+ ),
40
36
  modalProps: props,
41
- setModalProps
37
+ setModalProps: setModalProps2
42
38
  };
43
39
  }
44
40
  var Drawer = Drawer$1;
41
+ Drawer.whyDidYouRender = true;
45
42
  function useDrawer(init) {
46
43
  const [props, setProps] = useState({
47
44
  open: false,
48
- onClose: () => setProps((prev) => ({
49
- ...prev,
50
- open: false
51
- })),
52
45
  ...init
53
46
  });
47
+ const setDrawerProps2 = useCallback(
48
+ (changes) => {
49
+ const changed = typeof changes === "function" ? changes(props) : changes;
50
+ setProps((prev) => ({ ...prev, ...changed }));
51
+ },
52
+ [setProps]
53
+ );
54
54
  return {
55
- drawer: /* @__PURE__ */ jsx(Drawer, { ...props }),
56
- drawerProps: props,
57
- setDrawerProps(changes) {
58
- if (typeof changes === "function") {
59
- setProps((prev) => ({
55
+ drawer: /* @__PURE__ */ jsx(
56
+ Drawer,
57
+ {
58
+ onClose: () => setProps((prev) => ({
60
59
  ...prev,
61
- ...changes(props)
62
- }));
63
- return;
60
+ open: false
61
+ })),
62
+ ...props
64
63
  }
65
- setProps((prev) => ({
66
- ...prev,
67
- ...changes
68
- }));
69
- }
64
+ ),
65
+ drawerProps: props,
66
+ setDrawerProps: setDrawerProps2
70
67
  };
71
68
  }
72
- Drawer.whyDidYouRender = true;
73
69
  function ErrorChildren(props) {
74
70
  return /* @__PURE__ */ jsx(
75
71
  Alert,
@@ -162,36 +158,31 @@ function ConfigProvider(props) {
162
158
  function useConfigContext() {
163
159
  return useContext(ConfigContext);
164
160
  }
165
- var AppContext = createContext({
166
- message: {},
167
- notification: {},
168
- setModalProps: () => void 0,
169
- setDrawerProps: () => void 0
170
- });
161
+ var MessageContext = createContext({});
162
+ var NotificationContext = createContext(
163
+ {}
164
+ );
165
+ var ModalPropsContext = createContext({});
166
+ var SetModalPropsContext = createContext(() => void 0);
167
+ var DrawerPropsContext = createContext({});
168
+ var SetDrawerPropsContext = createContext(() => void 0);
171
169
  function RoutesApp(props) {
172
170
  const location = useLocation();
173
- const { setDrawerProps, setModalProps } = useApp();
171
+ const { drawerProps, setDrawerProps: setDrawerProps2, modalProps, setModalProps: setModalProps2 } = useApp();
174
172
  useEffect(() => {
175
173
  console.debug("location", location);
176
- setDrawerProps({ open: false });
177
- setModalProps({ open: false });
174
+ if (drawerProps.open)
175
+ setDrawerProps2({ open: false });
176
+ if (modalProps.open)
177
+ setModalProps2({ open: false });
178
178
  }, [location]);
179
179
  return /* @__PURE__ */ jsx(Fragment, { children: props.children });
180
180
  }
181
181
  function App(props) {
182
182
  const [messageApi, messageContextHolder] = message.useMessage();
183
183
  const [notificationApi, notificationContextHolder] = notification.useNotification();
184
- const { modal, modalProps, setModalProps } = useModal();
185
- const { drawer, setDrawerProps } = useDrawer();
186
- const memoizedContextValue = useMemo(
187
- () => ({
188
- message: messageApi,
189
- notification: notificationApi,
190
- setModalProps,
191
- setDrawerProps
192
- }),
193
- [messageApi, notificationApi, setModalProps, setDrawerProps]
194
- );
184
+ const { modal, modalProps, setModalProps: setModalProps2 } = useModal();
185
+ const { drawer, drawerProps, setDrawerProps: setDrawerProps2 } = useDrawer();
195
186
  const styleProviderProps = useMemo(
196
187
  () => ({
197
188
  ...props.styleProviderProps,
@@ -200,16 +191,37 @@ function App(props) {
200
191
  }),
201
192
  [props.styleProviderProps]
202
193
  );
203
- return /* @__PURE__ */ jsx(StyleProvider, { ...styleProviderProps, children: /* @__PURE__ */ jsx(ConfigProvider$1, { ...props.configProviderProps, children: /* @__PURE__ */ jsx(AppContext.Provider, { value: memoizedContextValue, children: /* @__PURE__ */ jsx(ConfigProvider, { ...props.faasConfigProviderProps, children: /* @__PURE__ */ jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxs(BrowserRouter, { ...props.browserRouterProps, children: [
194
+ return /* @__PURE__ */ jsx(StyleProvider, { ...styleProviderProps, children: /* @__PURE__ */ jsx(ConfigProvider$1, { ...props.configProviderProps, children: /* @__PURE__ */ jsx(MessageContext.Provider, { value: messageApi, children: /* @__PURE__ */ jsx(NotificationContext.Provider, { value: notificationApi, children: /* @__PURE__ */ jsx(DrawerPropsContext.Provider, { value: drawerProps, children: /* @__PURE__ */ jsx(SetDrawerPropsContext.Provider, { value: setDrawerProps2, children: /* @__PURE__ */ jsx(ModalPropsContext.Provider, { value: modalProps, children: /* @__PURE__ */ jsx(SetModalPropsContext.Provider, { value: setModalProps2, children: /* @__PURE__ */ jsx(ConfigProvider, { ...props.faasConfigProviderProps, children: /* @__PURE__ */ jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxs(BrowserRouter, { ...props.browserRouterProps, children: [
204
195
  messageContextHolder,
205
196
  notificationContextHolder,
206
197
  modal,
207
198
  drawer,
208
199
  /* @__PURE__ */ jsx(RoutesApp, { children: props.children })
209
- ] }) }) }) }) }) });
200
+ ] }) }) }) }) }) }) }) }) }) }) });
210
201
  }
211
202
  function useApp() {
212
- return useContext(AppContext);
203
+ return useConstant(() => {
204
+ const obj = /* @__PURE__ */ Object.create(null);
205
+ Object.defineProperty(obj, "message", {
206
+ get: () => useContext(MessageContext)
207
+ });
208
+ Object.defineProperty(obj, "notification", {
209
+ get: () => useContext(NotificationContext)
210
+ });
211
+ Object.defineProperty(obj, "modalProps", {
212
+ get: () => useContext(ModalPropsContext)
213
+ });
214
+ Object.defineProperty(obj, "setModalProps", {
215
+ get: () => useContext(SetModalPropsContext)
216
+ });
217
+ Object.defineProperty(obj, "drawerProps", {
218
+ get: () => useContext(DrawerPropsContext)
219
+ });
220
+ Object.defineProperty(obj, "setDrawerProps", {
221
+ get: () => useContext(SetDrawerPropsContext)
222
+ });
223
+ return Object.freeze(obj);
224
+ });
213
225
  }
214
226
  App.useApp = useApp;
215
227
  App.whyDidYouRender = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -26,7 +26,7 @@
26
26
  "lodash-es": "*"
27
27
  },
28
28
  "peerDependencies": {
29
- "@faasjs/react": "1.5.0",
29
+ "@faasjs/react": "1.6.0",
30
30
  "antd": "*",
31
31
  "react": "*",
32
32
  "react-dom": "*",
@@ -38,7 +38,7 @@
38
38
  "@testing-library/react": "*",
39
39
  "@testing-library/user-event": "*",
40
40
  "@welldone-software/why-did-you-render": "*",
41
- "@faasjs/react": "1.5.0",
41
+ "@faasjs/react": "1.6.0",
42
42
  "antd": "*",
43
43
  "react": "*",
44
44
  "react-dom": "*",