@faasjs/ant-design 8.0.0-beta.1 → 8.0.0-beta.11

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.cjs CHANGED
@@ -1,903 +1,1064 @@
1
- 'use strict';
2
-
3
- var react = require('@faasjs/react');
4
- var antd = require('antd');
5
- var reactRouterDom = require('react-router-dom');
6
- var lodashEs = require('lodash-es');
7
- var react$1 = require('react');
8
- var jsxRuntime = require('react/jsx-runtime');
9
- var icons = require('@ant-design/icons');
10
- var dayjs2 = require('dayjs');
11
-
12
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
13
27
 
14
- var dayjs2__default = /*#__PURE__*/_interopDefault(dayjs2);
28
+ //#endregion
29
+ let _faasjs_react = require("@faasjs/react");
30
+ let antd = require("antd");
31
+ let react_router_dom = require("react-router-dom");
32
+ let lodash_es = require("lodash-es");
33
+ let react = require("react");
34
+ let react_jsx_runtime = require("react/jsx-runtime");
35
+ let _ant_design_icons = require("@ant-design/icons");
36
+ let dayjs = require("dayjs");
37
+ dayjs = __toESM(dayjs);
15
38
 
16
- // src/App.tsx
39
+ //#region src/Loading.tsx
40
+ /**
41
+ * Loading component based on Spin
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * <Loading /> // display loading
46
+ *
47
+ * <Loading loading={ !remoteData }>
48
+ * <div>{remoteData}</div>
49
+ * </Loading>
50
+ * ```
51
+ */
17
52
  function Loading(props) {
18
- if (props.loading === false) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
19
- return /* @__PURE__ */ jsxRuntime.jsx(
20
- "div",
21
- {
22
- style: {
23
- ...props.style || {},
24
- ...!props.size || props.size === "large" ? {
25
- margin: "20vh auto",
26
- textAlign: "center"
27
- } : {}
28
- },
29
- children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { size: props.size || "large" })
30
- }
31
- );
53
+ if (props.loading === false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: props.children });
54
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
55
+ style: {
56
+ ...props.style || {},
57
+ ...!props.size || props.size === "large" ? {
58
+ margin: "20vh auto",
59
+ textAlign: "center"
60
+ } : {}
61
+ },
62
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Spin, { size: props.size || "large" })
63
+ });
32
64
  }
33
- Loading.whyDidYouRender = true;
65
+
66
+ //#endregion
67
+ //#region src/FaasDataWrapper.tsx
68
+ /**
69
+ * FaasDataWrapper component with Loading
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * function MyComponent (props: FaasDataInjection) {
74
+ * return <div>{ props.data }</div>
75
+ * }
76
+ *
77
+ * function MyPage () {
78
+ * return <FaasDataWrapper action="test" params={{ a: 1 }}>
79
+ * <MyComponent />
80
+ * </FaasDataWrapper>
81
+ * }
82
+ * ```
83
+ */
34
84
  function FaasDataWrapper(props) {
35
- return /* @__PURE__ */ jsxRuntime.jsx(
36
- react.FaasDataWrapper,
37
- {
38
- fallback: props.loading || /* @__PURE__ */ jsxRuntime.jsx(Loading, { ...props.loadingProps }),
39
- ...props
40
- }
41
- );
85
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_faasjs_react.FaasDataWrapper, {
86
+ fallback: props.loading || /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Loading, { ...props.loadingProps }),
87
+ ...props
88
+ });
42
89
  }
43
- FaasDataWrapper.whyDidYouRender = true;
90
+ /**
91
+ * HOC to wrap a component with FaasDataWrapper and Loading
92
+ *
93
+ * @example
94
+ * ```tsx
95
+ * const MyComponent = withFaasData(({ data }) => <div>{data.name}</div>, { action: 'test', params: { a: 1 } })
96
+ * ```
97
+ */
44
98
  function withFaasData(Component, faasProps) {
45
- return react.withFaasData(Component, {
46
- fallback: faasProps.loading || /* @__PURE__ */ jsxRuntime.jsx(Loading, { ...faasProps.loadingProps }),
47
- ...faasProps
48
- });
99
+ return (0, _faasjs_react.withFaasData)(Component, {
100
+ fallback: faasProps.loading || /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Loading, { ...faasProps.loadingProps }),
101
+ ...faasProps
102
+ });
49
103
  }
50
- var zh = {
51
- lang: "zh",
52
- blank: "\u7A7A",
53
- all: "\u5168\u90E8",
54
- submit: "\u63D0\u4EA4",
55
- pageNotFound: "\u9875\u9762\u672A\u627E\u5230",
56
- add: "\u6DFB\u52A0",
57
- delete: "\u5220\u9664",
58
- required: "\u5FC5\u586B",
59
- search: "\u641C\u7D22",
60
- reset: "\u91CD\u7F6E"
104
+
105
+ //#endregion
106
+ //#region src/Config.tsx
107
+ const zh = {
108
+ lang: "zh",
109
+ blank: "",
110
+ all: "全部",
111
+ submit: "提交",
112
+ pageNotFound: "页面未找到",
113
+ add: "添加",
114
+ delete: "删除",
115
+ required: "必填",
116
+ search: "搜索",
117
+ reset: "重置"
61
118
  };
62
- var en = {
63
- lang: "en",
64
- blank: "Empty",
65
- all: "All",
66
- submit: "Submit",
67
- pageNotFound: "Page Not Found",
68
- add: "Add",
69
- delete: "Delete",
70
- required: "is required",
71
- search: "Search",
72
- reset: "Reset"
119
+ const en = {
120
+ lang: "en",
121
+ blank: "Empty",
122
+ all: "All",
123
+ submit: "Submit",
124
+ pageNotFound: "Page Not Found",
125
+ add: "Add",
126
+ delete: "Delete",
127
+ required: "is required",
128
+ search: "Search",
129
+ reset: "Reset"
73
130
  };
74
- var baseTheme = {
75
- lang: "en",
76
- common: en,
77
- Blank: { text: en.blank },
78
- Form: { submit: { text: en.submit } },
79
- Title: {
80
- separator: " - ",
81
- suffix: ""
82
- },
83
- Link: { style: {} }
131
+ const baseTheme = {
132
+ lang: "en",
133
+ common: en,
134
+ Blank: { text: en.blank },
135
+ Form: { submit: { text: en.submit } },
136
+ Title: {
137
+ separator: " - ",
138
+ suffix: ""
139
+ },
140
+ Link: { style: {} }
84
141
  };
85
- var ConfigContext = react$1.createContext({
86
- theme: baseTheme
87
- });
142
+ const ConfigContext = (0, react.createContext)({ theme: baseTheme });
143
+ /**
144
+ * Config for `@faasjs/ant-design` components.
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * import { ConfigProvider } from '@faasjs/ant-design'
149
+ *
150
+ * <ConfigProvider theme={{ common: { blank: 'Empty' } }}>
151
+ * <Blank />
152
+ * </ConfigProvider>
153
+ * ```
154
+ */
88
155
  function ConfigProvider(props) {
89
- const [theme2, setTheme] = react$1.useState();
90
- react.useEqualEffect(() => {
91
- const lang = props.theme?.lang || (!props.theme?.lang && /^zh/i.test(navigator.language) ? "zh" : "en");
92
- if (lang === "zh") {
93
- setTheme(
94
- lodashEs.defaultsDeep(
95
- props.theme,
96
- {
97
- lang: "zh",
98
- common: zh,
99
- Blank: { text: zh.blank },
100
- Form: { submit: { text: zh.submit } }
101
- },
102
- baseTheme
103
- )
104
- );
105
- } else setTheme(lodashEs.defaultsDeep(props.theme, baseTheme));
106
- if (props.faasClientOptions) react.FaasReactClient(props.faasClientOptions);
107
- }, [props.theme]);
108
- if (!theme2) return null;
109
- return /* @__PURE__ */ jsxRuntime.jsx(ConfigContext.Provider, { value: { theme: theme2 }, children: props.children });
156
+ const [theme, setTheme] = (0, react.useState)();
157
+ (0, _faasjs_react.useEqualEffect)(() => {
158
+ if ((props.theme?.lang || (!props.theme?.lang && /^zh/i.test(navigator.language) ? "zh" : "en")) === "zh") setTheme((0, lodash_es.defaultsDeep)(props.theme, {
159
+ lang: "zh",
160
+ common: zh,
161
+ Blank: { text: zh.blank },
162
+ Form: { submit: { text: zh.submit } }
163
+ }, baseTheme));
164
+ else setTheme((0, lodash_es.defaultsDeep)(props.theme, baseTheme));
165
+ if (props.faasClientOptions) (0, _faasjs_react.FaasReactClient)(props.faasClientOptions);
166
+ }, [props.theme]);
167
+ if (!theme) return null;
168
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigContext.Provider, {
169
+ value: { theme },
170
+ children: props.children
171
+ });
110
172
  }
111
173
  function useConfigContext() {
112
- return react$1.useContext(ConfigContext);
174
+ return (0, react.useContext)(ConfigContext);
113
175
  }
114
- var Drawer = antd.Drawer;
115
- Drawer.whyDidYouRender = true;
176
+
177
+ //#endregion
178
+ //#region src/Drawer.tsx
179
+ /**
180
+ * Hook style drawer
181
+ *
182
+ * ```tsx
183
+ * function Example() {
184
+ * const { drawer, setDrawerProps } = useDrawer()
185
+ *
186
+ * return <>
187
+ * <Button onClick={ () => setDrawerProps(prev => ({ open: !prev.open})) }>
188
+ * Toggle
189
+ * </Button>
190
+ * {drawer}
191
+ * </>
192
+ * }
193
+ * ```
194
+ */
116
195
  function useDrawer(init) {
117
- const [props, setProps] = react$1.useState({
118
- open: false,
119
- ...init
120
- });
121
- const setDrawerProps = react.useEqualCallback(
122
- (changes) => {
123
- const changed = typeof changes === "function" ? changes(props) : changes;
124
- setProps((prev) => ({ ...prev, ...changed }));
125
- },
126
- [setProps]
127
- );
128
- return {
129
- drawer: /* @__PURE__ */ jsxRuntime.jsx(
130
- Drawer,
131
- {
132
- onClose: () => setProps((prev) => ({
133
- ...prev,
134
- open: false
135
- })),
136
- ...props
137
- }
138
- ),
139
- drawerProps: props,
140
- setDrawerProps
141
- };
196
+ const [props, setProps] = (0, react.useState)({
197
+ open: false,
198
+ ...init
199
+ });
200
+ const setDrawerProps = (0, _faasjs_react.useEqualCallback)((changes) => {
201
+ const changed = typeof changes === "function" ? changes(props) : changes;
202
+ setProps((prev) => ({
203
+ ...prev,
204
+ ...changed
205
+ }));
206
+ }, [setProps]);
207
+ return {
208
+ drawer: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Drawer, {
209
+ onClose: () => setProps((prev) => ({
210
+ ...prev,
211
+ open: false
212
+ })),
213
+ ...props
214
+ }),
215
+ drawerProps: props,
216
+ setDrawerProps
217
+ };
142
218
  }
219
+
220
+ //#endregion
221
+ //#region src/ErrorBoundary.tsx
143
222
  function ErrorChildren(props) {
144
- return /* @__PURE__ */ jsxRuntime.jsx(
145
- antd.Alert,
146
- {
147
- type: "error",
148
- message: props.errorMessage,
149
- description: /* @__PURE__ */ jsxRuntime.jsx(
150
- "pre",
151
- {
152
- style: {
153
- fontSize: "0.9em",
154
- overflowX: "auto"
155
- },
156
- children: props.errorDescription
157
- }
158
- )
159
- }
160
- );
223
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Alert, {
224
+ type: "error",
225
+ message: props.errorMessage,
226
+ description: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
227
+ style: {
228
+ fontSize: "0.9em",
229
+ overflowX: "auto"
230
+ },
231
+ children: props.errorDescription
232
+ })
233
+ });
161
234
  }
235
+ /**
236
+ * Styled error boundary.
237
+ */
162
238
  function ErrorBoundary(props) {
163
- return /* @__PURE__ */ jsxRuntime.jsx(react.ErrorBoundary, { errorChildren: /* @__PURE__ */ jsxRuntime.jsx(ErrorChildren, {}), ...props });
239
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_faasjs_react.ErrorBoundary, {
240
+ errorChildren: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorChildren, {}),
241
+ ...props
242
+ });
164
243
  }
165
- ErrorBoundary.whyDidYouRender = true;
166
- var Modal = antd.Modal;
167
- Modal.whyDidYouRender = true;
244
+
245
+ //#endregion
246
+ //#region src/Modal.tsx
247
+ /**
248
+ * Hook style modal
249
+ *
250
+ * ```tsx
251
+ * function Example() {
252
+ * const { modal, setModalProps } = useModal()
253
+ *
254
+ * return <>
255
+ * <Button onClick={() => setModalProps({ open: true })}>Open Modal</Button>
256
+ * {modal}
257
+ * </>
258
+ * }
259
+ * ```
260
+ */
168
261
  function useModal(init) {
169
- const [props, setProps] = react$1.useState({ open: false, ...init });
170
- const setModalProps = react.useEqualCallback(
171
- (changes) => {
172
- const changed = typeof changes === "function" ? changes(props) : changes;
173
- setProps((prev) => ({ ...prev, ...changed }));
174
- },
175
- [setProps]
176
- );
177
- return {
178
- modal: /* @__PURE__ */ jsxRuntime.jsx(
179
- Modal,
180
- {
181
- onCancel: () => setProps((prev) => ({
182
- ...prev,
183
- open: false
184
- })),
185
- ...props
186
- }
187
- ),
188
- modalProps: props,
189
- setModalProps
190
- };
262
+ const [props, setProps] = (0, react.useState)({
263
+ open: false,
264
+ ...init
265
+ });
266
+ const setModalProps = (0, _faasjs_react.useEqualCallback)((changes) => {
267
+ const changed = typeof changes === "function" ? changes(props) : changes;
268
+ setProps((prev) => ({
269
+ ...prev,
270
+ ...changed
271
+ }));
272
+ }, [setProps]);
273
+ return {
274
+ modal: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Modal, {
275
+ onCancel: () => setProps((prev) => ({
276
+ ...prev,
277
+ open: false
278
+ })),
279
+ ...props
280
+ }),
281
+ modalProps: props,
282
+ setModalProps
283
+ };
191
284
  }
192
- var AppContext = react.createSplittingContext([
193
- "message",
194
- "notification",
195
- "modalProps",
196
- "setModalProps",
197
- "drawerProps",
198
- "setDrawerProps"
285
+
286
+ //#endregion
287
+ //#region src/App.tsx
288
+ const AppContext = (0, _faasjs_react.createSplittingContext)([
289
+ "message",
290
+ "notification",
291
+ "modalProps",
292
+ "setModalProps",
293
+ "drawerProps",
294
+ "setDrawerProps"
199
295
  ]);
200
296
  function RoutesApp(props) {
201
- const location = reactRouterDom.useLocation();
202
- const { drawerProps, setDrawerProps, modalProps, setModalProps } = useApp();
203
- react.useEqualEffect(() => {
204
- console.debug("location", location);
205
- if (drawerProps.open) setDrawerProps({ open: false });
206
- if (modalProps.open) setModalProps({ open: false });
207
- }, [location]);
208
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
297
+ const location = (0, react_router_dom.useLocation)();
298
+ const { drawerProps, setDrawerProps, modalProps, setModalProps } = useApp();
299
+ (0, _faasjs_react.useEqualEffect)(() => {
300
+ console.debug("location", location);
301
+ if (drawerProps.open) setDrawerProps({ open: false });
302
+ if (modalProps.open) setModalProps({ open: false });
303
+ }, [location]);
304
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: props.children });
209
305
  }
306
+ /**
307
+ * App component with Ant Design & FaasJS
308
+ *
309
+ * - Based on Ant Design's [ConfigProvider](https://ant.design/components/config-provider/).
310
+ * - Integrated Ant Design's [Message](https://ant.design/components/message/) and [Notification](https://ant.design/components/notification/).
311
+ * - Based on FaasJS's [ConfigProvider](https://faasjs.com/doc/ant-design/#configprovider).
312
+ * - Integrated FaasJS's [Modal](https://faasjs.com/doc/ant-design/#usemodal), [Drawer](https://faasjs.com/doc/ant-design/#usedrawer) and [ErrorBoundary](https://faasjs.com/doc/ant-design/#errorboundary).
313
+ * - Integrated React Router's [BrowserRouter](https://api.reactrouter.com/v7/interfaces/react_router.BrowserRouterProps.html).
314
+ *
315
+ * @example
316
+ * ```tsx
317
+ * import { App } from '@faasjs/ant-design'
318
+ *
319
+ * export default function () {
320
+ * return (
321
+ * <App
322
+ * configProviderProps={{}} // https://ant.design/components/config-provider/#API
323
+ * browserRouterProps={{}} // https://api.reactrouter.com/v7/interfaces/react_router.BrowserRouterProps.html
324
+ * errorBoundaryProps={{}} // https://faasjs.com/doc/ant-design/#errorboundary
325
+ * faasConfigProviderProps={{}} // https://faasjs.com/doc/ant-design/#configprovider
326
+ * >
327
+ * <div>content</div>
328
+ * </App>
329
+ * )
330
+ * }
331
+ * ```
332
+ */
210
333
  function App(props) {
211
- const [messageApi, messageContextHolder] = antd.message.useMessage();
212
- const [notificationApi, notificationContextHolder] = antd.notification.useNotification();
213
- const { modal, modalProps, setModalProps } = useModal();
214
- const { drawer, drawerProps, setDrawerProps } = useDrawer();
215
- return /* @__PURE__ */ jsxRuntime.jsx(
216
- react.OptionalWrapper,
217
- {
218
- condition: !!props.configProviderProps,
219
- Wrapper: antd.ConfigProvider,
220
- wrapperProps: props.configProviderProps,
221
- children: /* @__PURE__ */ jsxRuntime.jsx(
222
- AppContext.Provider,
223
- {
224
- value: {
225
- message: messageApi,
226
- notification: notificationApi,
227
- drawerProps,
228
- setDrawerProps,
229
- modalProps,
230
- setModalProps
231
- },
232
- children: /* @__PURE__ */ jsxRuntime.jsx(
233
- ConfigProvider,
234
- {
235
- ...props.faasConfigProviderProps,
236
- faasClientOptions: {
237
- onError: (action) => async (res) => {
238
- if ("message" in res && res.toString().includes("AbortError"))
239
- return;
240
- console.error(`[FaasJS][${action}]`, res);
241
- messageApi.error("message" in res ? res.message : "Unknown error");
242
- },
243
- ...props.faasConfigProviderProps ? props.faasConfigProviderProps.faasClientOptions : {}
244
- },
245
- children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxRuntime.jsxs(
246
- react.OptionalWrapper,
247
- {
248
- condition: typeof document !== "undefined" && props.browserRouterProps !== false,
249
- Wrapper: reactRouterDom.BrowserRouter,
250
- wrapperProps: props.browserRouterProps,
251
- children: [
252
- messageContextHolder,
253
- notificationContextHolder,
254
- modal,
255
- drawer,
256
- props.browserRouterProps !== false ? /* @__PURE__ */ jsxRuntime.jsx(RoutesApp, { children: props.children }) : props.children
257
- ]
258
- }
259
- ) })
260
- }
261
- )
262
- }
263
- )
264
- }
265
- );
334
+ const [messageApi, messageContextHolder] = antd.message.useMessage();
335
+ const [notificationApi, notificationContextHolder] = antd.notification.useNotification();
336
+ const { modal, modalProps, setModalProps } = useModal();
337
+ const { drawer, drawerProps, setDrawerProps } = useDrawer();
338
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_faasjs_react.OptionalWrapper, {
339
+ condition: !!props.configProviderProps,
340
+ Wrapper: antd.ConfigProvider,
341
+ wrapperProps: props.configProviderProps,
342
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppContext.Provider, {
343
+ value: {
344
+ message: messageApi,
345
+ notification: notificationApi,
346
+ drawerProps,
347
+ setDrawerProps,
348
+ modalProps,
349
+ setModalProps
350
+ },
351
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigProvider, {
352
+ ...props.faasConfigProviderProps,
353
+ faasClientOptions: {
354
+ onError: (action) => async (res) => {
355
+ if ("message" in res && res.toString().includes("AbortError")) return;
356
+ console.error(`[FaasJS][${action}]`, res);
357
+ messageApi.error("message" in res ? res.message : "Unknown error");
358
+ },
359
+ ...props.faasConfigProviderProps ? props.faasConfigProviderProps.faasClientOptions : {}
360
+ },
361
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBoundary, {
362
+ ...props.errorBoundaryProps,
363
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_faasjs_react.OptionalWrapper, {
364
+ condition: typeof document !== "undefined" && props.browserRouterProps !== false,
365
+ Wrapper: react_router_dom.BrowserRouter,
366
+ wrapperProps: props.browserRouterProps,
367
+ children: [
368
+ messageContextHolder,
369
+ notificationContextHolder,
370
+ modal,
371
+ drawer,
372
+ props.browserRouterProps !== false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RoutesApp, { children: props.children }) : props.children
373
+ ]
374
+ })
375
+ })
376
+ })
377
+ })
378
+ });
266
379
  }
267
- var useApp = AppContext.use;
380
+ /**
381
+ * Get app context.
382
+ *
383
+ * ```ts
384
+ * import { useApp } from '@faasjs/ant-design'
385
+ *
386
+ * const { message, notification, setModalProps, setDrawerProps } = useApp()
387
+ * ```
388
+ */
389
+ const useApp = AppContext.use;
268
390
  App.useApp = useApp;
269
- App.whyDidYouRender = true;
391
+
392
+ //#endregion
393
+ //#region src/Blank.tsx
394
+ /**
395
+ * Blank component.
396
+ *
397
+ * If value is undefined or null, return text, otherwise return value.
398
+ *
399
+ * @example
400
+ * ```tsx
401
+ * import { Blank } from '@faasjs/ant-design'
402
+ *
403
+ * <Blank value={undefined} text="Empty" />
404
+ * ```
405
+ */
270
406
  function Blank(options) {
271
- const { theme: theme2 } = useConfigContext();
272
- return !options || options.value === void 0 || options.value === null || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ jsxRuntime.jsx(antd.Typography.Text, { disabled: true, children: options?.text || theme2.Blank.text }) : options.value;
407
+ const { theme } = useConfigContext();
408
+ return !options || options.value === void 0 || options.value === null || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Typography.Text, {
409
+ disabled: true,
410
+ children: options?.text || theme.Blank.text
411
+ }) : options.value;
273
412
  }
274
- Blank.whyDidYouRender = true;
413
+
414
+ //#endregion
415
+ //#region src/data.ts
416
+ /**
417
+ * Converts an identifier string to a title case string.
418
+ *
419
+ * This function takes an identifier string with words separated by underscores,
420
+ * capitalizes the first letter of each word, and joins them together without spaces.
421
+ *
422
+ * @param id - The identifier string to convert.
423
+ * @returns The converted title case string.
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * idToTitle('example_id'); // returns 'ExampleId'
428
+ * ```
429
+ */
275
430
  function idToTitle(id) {
276
- if (typeof id === "number") return id.toString();
277
- const splitted = id.split(/(\s|_|-)/).filter((word) => !/(\s|_|-)/.test(word)).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
278
- return splitted.charAt(0).toUpperCase() + splitted.slice(1);
431
+ if (typeof id === "number") return id.toString();
432
+ const splitted = id.split(/(\s|_|-)/).filter((word) => !/(\s|_|-)/.test(word)).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
433
+ return splitted.charAt(0).toUpperCase() + splitted.slice(1);
279
434
  }
435
+ /**
436
+ * convert string[] or number[] to { label, value }[]
437
+ */
280
438
  function transferOptions(options) {
281
- if (!options) return [];
282
- return options.map(
283
- (item) => typeof item === "object" ? item : {
284
- label: idToTitle(item.toString()),
285
- value: item
286
- }
287
- );
439
+ if (!options) return [];
440
+ return options.map((item) => typeof item === "object" ? item : {
441
+ label: idToTitle(item.toString()),
442
+ value: item
443
+ });
288
444
  }
289
445
  function transferValue(type, value) {
290
- if (!type) type = "string";
291
- if (!type.endsWith("[]") && (typeof value === "undefined" || value === null || value === "" || value === "null" || value === "undefined"))
292
- return null;
293
- if (type.endsWith("[]")) {
294
- if (!value) value = [];
295
- if (typeof value === "string") value = value.split(",").filter(Boolean);
296
- if (!Array.isArray(value)) value = [value];
297
- value = value.map(
298
- (item) => transferValue(type.replace("[]", ""), item)
299
- );
300
- }
301
- switch (type) {
302
- case "boolean":
303
- if (typeof value === "string") value = value === "true";
304
- break;
305
- case "number":
306
- if (typeof value === "string") value = Number(value);
307
- break;
308
- case "date":
309
- case "time":
310
- if (typeof value === "number" && value.toString().length === 10)
311
- value = value * 1e3;
312
- if (!dayjs2__default.default.isDayjs(value)) value = dayjs2__default.default(value);
313
- break;
314
- }
315
- return value;
446
+ if (!type) type = "string";
447
+ if (!type.endsWith("[]") && (typeof value === "undefined" || value === null || value === "" || value === "null" || value === "undefined")) return null;
448
+ if (type.endsWith("[]")) {
449
+ if (!value) value = [];
450
+ if (typeof value === "string") value = value.split(",").filter(Boolean);
451
+ if (!Array.isArray(value)) value = [value];
452
+ value = value.map((item) => transferValue(type.replace("[]", ""), item));
453
+ }
454
+ switch (type) {
455
+ case "boolean":
456
+ if (typeof value === "string") value = value === "true";
457
+ break;
458
+ case "number":
459
+ if (typeof value === "string") value = Number(value);
460
+ break;
461
+ case "date":
462
+ case "time":
463
+ if (typeof value === "number" && value.toString().length === 10) value = value * 1e3;
464
+ if (!dayjs.default.isDayjs(value)) value = (0, dayjs.default)(value);
465
+ break;
466
+ }
467
+ return value;
316
468
  }
469
+ /**
470
+ * Clone a UnionFaasItemElement with the given props.
471
+ *
472
+ * This function takes a UnionFaasItemElement and props, and returns a cloned element.
473
+ * If the provided element is a valid React element, it clones it with the new props.
474
+ * Otherwise, it creates a new element from the provided element and props.
475
+ *
476
+ * @param element - The UnionFaasItemElement to be cloned.
477
+ * @param props - The props to be applied to the cloned element.
478
+ * @returns The cloned element with the applied props.
479
+ */
317
480
  function cloneUnionFaasItemElement(element, props) {
318
- return react$1.cloneElement(
319
- react$1.isValidElement(element) ? element : react$1.createElement(element),
320
- props
321
- );
481
+ return (0, react.cloneElement)((0, react.isValidElement)(element) ? element : (0, react.createElement)(element), props);
322
482
  }
483
+
484
+ //#endregion
485
+ //#region src/Description.tsx
323
486
  function DescriptionItemContent(props) {
324
- const [computedProps, setComputedProps] = react$1.useState();
325
- react$1.useEffect(() => {
326
- const propsCopy = { ...props };
327
- propsCopy.item.title = propsCopy.item.title ?? idToTitle(propsCopy.item.id);
328
- if (!propsCopy.item.type) propsCopy.item.type = "string";
329
- if (propsCopy.item.options?.length) {
330
- propsCopy.item.options = transferOptions(propsCopy.item.options);
331
- }
332
- propsCopy.value = transferValue(propsCopy.item.type, propsCopy.value);
333
- if (propsCopy.item.options && propsCopy.value !== null) {
334
- if (propsCopy.item.type.endsWith("[]"))
335
- propsCopy.value = propsCopy.value.map(
336
- (v) => propsCopy.item.options.find((option) => option.value === v)?.label || v
337
- );
338
- else if (["string", "number", "boolean"].includes(propsCopy.item.type))
339
- propsCopy.value = props.item.options.find((option) => option.value === props.value)?.label || props.value;
340
- }
341
- setComputedProps(propsCopy);
342
- }, [props]);
343
- if (!computedProps) return null;
344
- if (computedProps.item.descriptionChildren === null || computedProps.item.children === null || computedProps.item.descriptionRender === null || computedProps.item.render === null)
345
- return null;
346
- const children = computedProps.item.descriptionChildren || computedProps.item.children;
347
- if (children)
348
- return cloneUnionFaasItemElement(children, {
349
- scene: "description",
350
- value: computedProps.value,
351
- values: computedProps.values,
352
- index: 0
353
- });
354
- const render = computedProps.item.descriptionRender || computedProps.item.render;
355
- if (render)
356
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(computedProps.value, computedProps.values, 0, "description") });
357
- if (computedProps.extendTypes?.[computedProps.item.type]) {
358
- if (computedProps.extendTypes[computedProps.item.type].children)
359
- return cloneUnionFaasItemElement(
360
- computedProps.extendTypes[computedProps.item.type].children,
361
- {
362
- scene: "description",
363
- value: computedProps.value,
364
- values: computedProps.values
365
- }
366
- );
367
- if (computedProps.extendTypes[computedProps.item.type].render)
368
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.extendTypes[computedProps.item.type].render(
369
- computedProps.value,
370
- computedProps.values,
371
- 0,
372
- "description"
373
- ) });
374
- throw Error(`${computedProps.item.type} requires children or render`);
375
- }
376
- if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length)
377
- return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
378
- switch (computedProps.item.type) {
379
- case "string[]":
380
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.join(", ") });
381
- case "number":
382
- return computedProps.value || null;
383
- case "number[]":
384
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.join(", ") });
385
- case "boolean":
386
- return computedProps.value ? /* @__PURE__ */ jsxRuntime.jsx(
387
- icons.CheckOutlined,
388
- {
389
- style: {
390
- marginTop: "4px",
391
- color: "#52c41a"
392
- }
393
- }
394
- ) : /* @__PURE__ */ jsxRuntime.jsx(
395
- icons.CloseOutlined,
396
- {
397
- style: {
398
- marginTop: "4px",
399
- color: "#ff4d4f"
400
- }
401
- }
402
- );
403
- case "time":
404
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.format("YYYY-MM-DD HH:mm:ss") });
405
- case "date":
406
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.format("YYYY-MM-DD") });
407
- case "object":
408
- if (!computedProps.value) return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
409
- return /* @__PURE__ */ jsxRuntime.jsx(
410
- Description,
411
- {
412
- items: computedProps.item.object,
413
- dataSource: computedProps.value,
414
- column: 1
415
- }
416
- );
417
- case "object[]":
418
- if (!computedProps.value?.length)
419
- return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
420
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Space, { direction: "vertical", children: computedProps.value.map(
421
- (value, index) => /* @__PURE__ */ jsxRuntime.jsx(
422
- Description,
423
- {
424
- items: computedProps.item.object,
425
- dataSource: value,
426
- column: 1
427
- },
428
- index
429
- )
430
- ) });
431
- default:
432
- return computedProps.value || null;
433
- }
487
+ const [computedProps, setComputedProps] = (0, react.useState)();
488
+ (0, react.useEffect)(() => {
489
+ const propsCopy = { ...props };
490
+ propsCopy.item.title = propsCopy.item.title ?? idToTitle(propsCopy.item.id);
491
+ if (!propsCopy.item.type) propsCopy.item.type = "string";
492
+ if (propsCopy.item.options?.length) propsCopy.item.options = transferOptions(propsCopy.item.options);
493
+ propsCopy.value = transferValue(propsCopy.item.type, propsCopy.value);
494
+ if (propsCopy.item.options && propsCopy.value !== null) {
495
+ if (propsCopy.item.type.endsWith("[]")) propsCopy.value = propsCopy.value.map((v) => propsCopy.item.options.find((option) => option.value === v)?.label || v);
496
+ else if ([
497
+ "string",
498
+ "number",
499
+ "boolean"
500
+ ].includes(propsCopy.item.type)) propsCopy.value = props.item.options.find((option) => option.value === props.value)?.label || props.value;
501
+ }
502
+ setComputedProps(propsCopy);
503
+ }, [props]);
504
+ if (!computedProps) return null;
505
+ const itemType = computedProps.item.type ?? "string";
506
+ if (computedProps.item.descriptionChildren === null || computedProps.item.children === null || computedProps.item.descriptionRender === null || computedProps.item.render === null) return null;
507
+ const children = computedProps.item.descriptionChildren || computedProps.item.children;
508
+ if (children) return cloneUnionFaasItemElement(children, {
509
+ scene: "description",
510
+ value: computedProps.value,
511
+ values: computedProps.values,
512
+ index: 0
513
+ });
514
+ const render = computedProps.item.descriptionRender || computedProps.item.render;
515
+ if (render) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: render(computedProps.value, computedProps.values, 0, "description") });
516
+ if (computedProps.extendTypes?.[itemType]) {
517
+ const extendType = computedProps.extendTypes[itemType];
518
+ if (extendType.children) return cloneUnionFaasItemElement(extendType.children, {
519
+ scene: "description",
520
+ value: computedProps.value,
521
+ values: computedProps.values
522
+ });
523
+ if (extendType.render) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: extendType.render(computedProps.value, computedProps.values, 0, "description") });
524
+ throw Error(`${itemType} requires children or render`);
525
+ }
526
+ if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {});
527
+ switch (itemType) {
528
+ case "string[]": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: computedProps.value.join(", ") });
529
+ case "number": return computedProps.value || null;
530
+ case "number[]": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: computedProps.value.join(", ") });
531
+ case "boolean": return computedProps.value ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CheckOutlined, { style: {
532
+ marginTop: "4px",
533
+ color: "#52c41a"
534
+ } }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CloseOutlined, { style: {
535
+ marginTop: "4px",
536
+ color: "#ff4d4f"
537
+ } });
538
+ case "time": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: computedProps.value.format("YYYY-MM-DD HH:mm:ss") });
539
+ case "date": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: computedProps.value.format("YYYY-MM-DD") });
540
+ case "object":
541
+ if (!computedProps.value) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {});
542
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Description, {
543
+ items: computedProps.item.object || [],
544
+ dataSource: computedProps.value,
545
+ column: 1
546
+ });
547
+ case "object[]":
548
+ if (!computedProps.value?.length) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {});
549
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Space, {
550
+ direction: "vertical",
551
+ children: computedProps.value.map((value, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Description, {
552
+ items: computedProps.item.object || [],
553
+ dataSource: value,
554
+ column: 1
555
+ }, index))
556
+ });
557
+ default: return computedProps.value || null;
558
+ }
434
559
  }
435
560
  DescriptionItemContent.displayName = "DescriptionItemContent";
436
- DescriptionItemContent.whyDidYouRender = true;
437
- function Description({
438
- faasData,
439
- dataSource,
440
- renderTitle,
441
- extendTypes,
442
- ...props
443
- }) {
444
- if (faasData && !dataSource)
445
- return /* @__PURE__ */ jsxRuntime.jsx(
446
- FaasDataWrapper,
447
- {
448
- render: ({ data }) => /* @__PURE__ */ jsxRuntime.jsx(
449
- Description,
450
- {
451
- ...props,
452
- dataSource: data,
453
- renderTitle,
454
- extendTypes
455
- }
456
- ),
457
- ...faasData
458
- }
459
- );
460
- return /* @__PURE__ */ jsxRuntime.jsx(
461
- antd.Descriptions,
462
- {
463
- ...props,
464
- title: typeof renderTitle === "function" ? renderTitle(dataSource) : props.title,
465
- items: props.items.filter(
466
- (item) => item && !(item.descriptionChildren === null || item.children === null || item.descriptionRender === null || item.render === null) && (!item.if || item.if(dataSource))
467
- ).map((item) => ({
468
- ...item,
469
- key: item.id,
470
- label: item.title ?? idToTitle(item.id),
471
- children: /* @__PURE__ */ jsxRuntime.jsx(
472
- DescriptionItemContent,
473
- {
474
- item,
475
- value: dataSource ? dataSource[item.id] : null,
476
- values: dataSource,
477
- extendTypes
478
- }
479
- )
480
- }))
481
- }
482
- );
561
+ /**
562
+ * Description component
563
+ *
564
+ * - Based on [Ant Design Descriptions](https://ant.design/components/descriptions/).
565
+ *
566
+ * @example
567
+ * ```tsx
568
+ * import { Description } from '@faasjs/ant-design'
569
+ *
570
+ * <Description
571
+ * title="Title"
572
+ * items={[
573
+ * {
574
+ * id: 'id',
575
+ * title: 'Title',
576
+ * type: 'string',
577
+ * },
578
+ * ]}
579
+ * dataSource={{ id: 'value' }}
580
+ * />
581
+ * ```
582
+ */
583
+ function Description({ faasData, dataSource, renderTitle, extendTypes, ...props }) {
584
+ if (faasData && !dataSource) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FaasDataWrapper, {
585
+ render: ({ data }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Description, {
586
+ ...props,
587
+ dataSource: data,
588
+ ...renderTitle ? { renderTitle } : {},
589
+ ...extendTypes ? { extendTypes } : {}
590
+ }),
591
+ ...faasData
592
+ });
593
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Descriptions, {
594
+ ...props,
595
+ title: typeof renderTitle === "function" ? renderTitle(dataSource) : props.title,
596
+ items: props.items.filter((item) => item && !(item.descriptionChildren === null || item.children === null || item.descriptionRender === null || item.render === null) && (!item.if || item.if(dataSource))).map((item) => ({
597
+ ...item,
598
+ key: item.id,
599
+ label: item.title ?? idToTitle(item.id),
600
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DescriptionItemContent, {
601
+ item,
602
+ value: dataSource ? dataSource[item.id] : null,
603
+ ...dataSource ? { values: dataSource } : {},
604
+ ...extendTypes ? { extendTypes } : {}
605
+ })
606
+ }))
607
+ });
483
608
  }
484
609
  Description.displayName = "Description";
485
- Description.whyDidYouRender = true;
610
+
611
+ //#endregion
612
+ //#region src/FormItem.tsx
486
613
  function isOptionsProps(item) {
487
- return item && Array.isArray(item.options);
614
+ return item && Array.isArray(item.options);
488
615
  }
489
616
  function processProps(propsCopy, config) {
490
- propsCopy.title = propsCopy.title ?? idToTitle(propsCopy.id);
491
- if (!propsCopy.label && propsCopy.label !== false)
492
- propsCopy.label = propsCopy.title;
493
- if (!propsCopy.name) propsCopy.name = propsCopy.id;
494
- if (!propsCopy.type) propsCopy.type = "string";
495
- if (!propsCopy.rules) propsCopy.rules = [];
496
- if (propsCopy.required) {
497
- if (propsCopy.type.endsWith("[]"))
498
- propsCopy.rules.push({
499
- required: true,
500
- validator: async (_, values) => {
501
- if (!values || values.length < 1)
502
- return Promise.reject(
503
- Error(`${propsCopy.label || propsCopy.title} ${config.required}`)
504
- );
505
- }
506
- });
507
- else
508
- propsCopy.rules.push({
509
- required: true,
510
- message: `${propsCopy.label || propsCopy.title} ${config.required}`
511
- });
512
- }
513
- if (!propsCopy.input) propsCopy.input = {};
514
- if (isOptionsProps(propsCopy))
515
- propsCopy.input.options = transferOptions(propsCopy.options);
516
- switch (propsCopy.type) {
517
- case "boolean":
518
- propsCopy.valuePropName = "checked";
519
- break;
520
- case "object":
521
- if (!Array.isArray(propsCopy.name)) propsCopy.name = [propsCopy.name];
522
- for (const sub of propsCopy.object) {
523
- if (!sub.name) sub.name = propsCopy.name.concat(sub.id);
524
- processProps(sub, config);
525
- }
526
- break;
527
- }
528
- return propsCopy;
617
+ propsCopy.title = propsCopy.title ?? idToTitle(propsCopy.id);
618
+ if (!propsCopy.label && propsCopy.label !== false) propsCopy.label = propsCopy.title;
619
+ if (!propsCopy.name) propsCopy.name = propsCopy.id;
620
+ if (!propsCopy.type) propsCopy.type = "string";
621
+ if (!propsCopy.rules) propsCopy.rules = [];
622
+ if (propsCopy.required) if (propsCopy.type.endsWith("[]")) propsCopy.rules.push({
623
+ required: true,
624
+ validator: async (_, values) => {
625
+ if (!values || values.length < 1) return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
626
+ }
627
+ });
628
+ else propsCopy.rules.push({
629
+ required: true,
630
+ message: `${propsCopy.label || propsCopy.title} ${config.required}`
631
+ });
632
+ if (!propsCopy.input) propsCopy.input = {};
633
+ if (isOptionsProps(propsCopy)) propsCopy.input.options = transferOptions(propsCopy.options);
634
+ switch (propsCopy.type) {
635
+ case "boolean":
636
+ propsCopy.valuePropName = "checked";
637
+ break;
638
+ case "object":
639
+ if (!Array.isArray(propsCopy.name)) propsCopy.name = [propsCopy.name];
640
+ for (const sub of propsCopy.object || []) {
641
+ if (!sub.name) sub.name = propsCopy.name.concat(sub.id);
642
+ processProps(sub, config);
643
+ }
644
+ break;
645
+ }
646
+ return propsCopy;
529
647
  }
648
+ /**
649
+ * FormItem
650
+ *
651
+ * - Based on [Ant Design Form.Item](https://ant.design/components/form#formitem).
652
+ * - Can be used without [Form](https://faasjs.com/doc/ant-design/#form).
653
+ *
654
+ * @example
655
+ * ```tsx
656
+ * // use inline type
657
+ * <FormItem type='string' id='name' />
658
+ *
659
+ * // use custom type
660
+ * <FormItem id='password'>
661
+ * <Input.Password />
662
+ * </>
663
+ * ```
664
+ */
530
665
  function FormItem(props) {
531
- const [computedProps, setComputedProps] = react$1.useState();
532
- const [extendTypes, setExtendTypes] = react$1.useState();
533
- const { theme: theme2 } = useConfigContext();
534
- const [hidden, setHidden] = react$1.useState(props.hidden || false);
535
- react$1.useEffect(() => {
536
- const { extendTypes: extendTypes2, ...propsCopy } = { ...props };
537
- if (extendTypes2) {
538
- setExtendTypes(extendTypes2);
539
- }
540
- if (propsCopy.if) {
541
- const condition = propsCopy.if;
542
- const originShouldUpdate = propsCopy.shouldUpdate;
543
- propsCopy.shouldUpdate = (prev, cur) => {
544
- const show = condition(cur);
545
- const shouldUpdate = hidden !== show;
546
- setHidden(!show);
547
- const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
548
- return shouldUpdate || origin;
549
- };
550
- delete propsCopy.if;
551
- delete propsCopy.hidden;
552
- }
553
- setComputedProps(processProps(propsCopy, theme2.common));
554
- }, [props]);
555
- if (!computedProps) return null;
556
- if (hidden)
557
- return /* @__PURE__ */ jsxRuntime.jsx(
558
- antd.Form.Item,
559
- {
560
- ...computedProps,
561
- id: computedProps.id.toString(),
562
- noStyle: true,
563
- rules: [],
564
- children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { type: "hidden", hidden: true })
565
- }
566
- );
567
- if (computedProps.formChildren === null || computedProps.children === null || computedProps.formRender === null || computedProps.render === null)
568
- return null;
569
- const children = computedProps.formChildren || computedProps.children;
570
- if (children)
571
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: cloneUnionFaasItemElement(children, { scene: "form" }) });
572
- const render = computedProps.formRender || computedProps.render;
573
- if (render)
574
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: render(null, null, 0, "form") });
575
- if (extendTypes?.[computedProps.type])
576
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: cloneUnionFaasItemElement(extendTypes[computedProps.type].children, {
577
- scene: "form"
578
- }) });
579
- switch (computedProps.type) {
580
- case "string":
581
- if (isOptionsProps(computedProps))
582
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: computedProps.options.length > 10 ? /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Group, { ...computedProps.input }) });
583
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { ...computedProps.input }) });
584
- case "string[]":
585
- if (isOptionsProps(computedProps))
586
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { mode: "multiple", ...computedProps.input }) });
587
- return /* @__PURE__ */ jsxRuntime.jsx(
588
- antd.Form.List,
589
- {
590
- name: computedProps.name,
591
- rules: computedProps.rules,
592
- children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
593
- computedProps.label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsx(
594
- "label",
595
- {
596
- className: computedProps.rules.find((r) => r.required) && "ant-form-item-required",
597
- children: computedProps.label
598
- }
599
- ) }),
600
- fields.map((field) => {
601
- const { key, ...fieldProps } = field;
602
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { id: key.toString(), children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Row, { gutter: 24, style: { flexFlow: "row nowrap" }, children: [
603
- /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 23, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...fieldProps, noStyle: true, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { ...computedProps.input }) }) }),
604
- /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 1, children: !computedProps.input?.disabled && (!computedProps.rules.find((r) => r.required) || key > 0) && /* @__PURE__ */ jsxRuntime.jsx(
605
- antd.Button,
606
- {
607
- danger: true,
608
- type: "link",
609
- style: { float: "right" },
610
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusCircleOutlined, {}),
611
- onClick: () => remove(field.name)
612
- }
613
- ) })
614
- ] }) }, key);
615
- }),
616
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Form.Item, { children: [
617
- !computedProps.input?.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxRuntime.jsx(
618
- antd.Button,
619
- {
620
- type: "dashed",
621
- block: true,
622
- onClick: () => add(),
623
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {})
624
- }
625
- ),
626
- computedProps.extra && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
627
- /* @__PURE__ */ jsxRuntime.jsx(antd.Form.ErrorList, { errors })
628
- ] })
629
- ] })
630
- }
631
- );
632
- case "number":
633
- if (computedProps.options)
634
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: computedProps.options.length > 10 ? /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Group, { ...computedProps.input }) });
635
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(
636
- antd.InputNumber,
637
- {
638
- style: { width: "100%" },
639
- ...computedProps.input
640
- }
641
- ) });
642
- case "number[]":
643
- if (computedProps.options)
644
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { mode: "multiple", ...computedProps.input }) });
645
- return /* @__PURE__ */ jsxRuntime.jsx(
646
- antd.Form.List,
647
- {
648
- name: computedProps.name,
649
- rules: computedProps.rules,
650
- children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
651
- computedProps.label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsx(
652
- "label",
653
- {
654
- className: computedProps.rules?.find(
655
- (r) => r.required
656
- ) && "ant-form-item-required",
657
- children: computedProps.label
658
- }
659
- ) }),
660
- fields.map((field) => {
661
- const { key, ...fieldProps } = field;
662
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { id: key.toString(), children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Row, { gutter: 24, style: { flexFlow: "row nowrap" }, children: [
663
- /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 23, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...fieldProps, noStyle: true, children: /* @__PURE__ */ jsxRuntime.jsx(
664
- antd.InputNumber,
665
- {
666
- style: { width: "100%" },
667
- ...computedProps.input
668
- }
669
- ) }) }),
670
- /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 1, children: !computedProps.input?.disabled && (!computedProps.rules.find((r) => r.required) || key > 0) && /* @__PURE__ */ jsxRuntime.jsx(
671
- antd.Button,
672
- {
673
- danger: true,
674
- type: "link",
675
- style: { float: "right" },
676
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusCircleOutlined, {}),
677
- onClick: () => remove(field.name)
678
- }
679
- ) })
680
- ] }) }, key);
681
- }),
682
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Form.Item, { children: [
683
- !computedProps.input?.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxRuntime.jsx(
684
- antd.Button,
685
- {
686
- type: "dashed",
687
- block: true,
688
- onClick: () => add(),
689
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {})
690
- }
691
- ),
692
- computedProps.extra && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
693
- /* @__PURE__ */ jsxRuntime.jsx(antd.Form.ErrorList, { errors })
694
- ] })
695
- ] })
696
- }
697
- );
698
- case "boolean":
699
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(antd.Switch, { ...computedProps.input }) });
700
- case "date":
701
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(antd.DatePicker, { ...computedProps.input }) });
702
- case "time":
703
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, id: computedProps.id.toString(), children: /* @__PURE__ */ jsxRuntime.jsx(
704
- antd.DatePicker,
705
- {
706
- ...{ ...computedProps.input, showTime: true }
707
- }
708
- ) });
709
- case "object":
710
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
711
- computedProps.label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsx(
712
- "label",
713
- {
714
- className: computedProps.rules?.find((r) => r.required) && "ant-form-item-required",
715
- children: computedProps.label
716
- }
717
- ) }),
718
- computedProps.object.map((o) => /* @__PURE__ */ jsxRuntime.jsx(FormItem, { ...o }, o.id))
719
- ] });
720
- case "object[]":
721
- return /* @__PURE__ */ jsxRuntime.jsx(
722
- antd.Form.List,
723
- {
724
- name: computedProps.name,
725
- rules: computedProps.rules,
726
- children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
727
- fields.map((field) => /* @__PURE__ */ jsxRuntime.jsxs(
728
- antd.Form.Item,
729
- {
730
- id: field.key.toString(),
731
- style: { marginBottom: 0 },
732
- children: [
733
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
734
- computedProps.label,
735
- " ",
736
- field.name + 1,
737
- !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsxRuntime.jsx(
738
- antd.Button,
739
- {
740
- danger: true,
741
- type: "link",
742
- onClick: () => remove(field.name),
743
- children: theme2.common.delete
744
- }
745
- )
746
- ] }) }),
747
- /* @__PURE__ */ jsxRuntime.jsx(antd.Row, { gutter: 24, children: computedProps.object.map((o) => /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: o.col || 24, children: /* @__PURE__ */ jsxRuntime.jsx(FormItem, { ...o, name: [field.name, o.id] }) }, o.id)) })
748
- ]
749
- },
750
- field.key
751
- )),
752
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Form.Item, { children: [
753
- !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxRuntime.jsxs(
754
- antd.Button,
755
- {
756
- type: "dashed",
757
- block: true,
758
- onClick: () => add(),
759
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
760
- children: [
761
- theme2.common.add,
762
- " ",
763
- computedProps.label
764
- ]
765
- }
766
- ),
767
- computedProps.extra && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
768
- /* @__PURE__ */ jsxRuntime.jsx(antd.Form.ErrorList, { errors })
769
- ] })
770
- ] })
771
- }
772
- );
773
- default:
774
- return null;
775
- }
666
+ const [computedProps, setComputedProps] = (0, react.useState)();
667
+ const [extendTypes, setExtendTypes] = (0, react.useState)();
668
+ const { theme } = useConfigContext();
669
+ const [hidden, setHidden] = (0, react.useState)(props.hidden || false);
670
+ (0, react.useEffect)(() => {
671
+ const { extendTypes, ...propsCopy } = { ...props };
672
+ if (extendTypes) setExtendTypes(extendTypes);
673
+ if (propsCopy.if) {
674
+ const condition = propsCopy.if;
675
+ const originShouldUpdate = propsCopy.shouldUpdate;
676
+ propsCopy.shouldUpdate = (prev, cur) => {
677
+ const show = condition(cur);
678
+ const shouldUpdate = hidden !== show;
679
+ setHidden(!show);
680
+ const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
681
+ return shouldUpdate || origin;
682
+ };
683
+ delete propsCopy.if;
684
+ delete propsCopy.hidden;
685
+ }
686
+ setComputedProps(processProps(propsCopy, theme.common));
687
+ }, [props]);
688
+ if (!computedProps) return null;
689
+ const itemType = computedProps.type ?? "string";
690
+ if (hidden) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
691
+ ...computedProps,
692
+ id: computedProps.id.toString(),
693
+ noStyle: true,
694
+ rules: [],
695
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input, {
696
+ type: "hidden",
697
+ hidden: true
698
+ })
699
+ });
700
+ if (computedProps.formChildren === null || computedProps.children === null || computedProps.formRender === null || computedProps.render === null) return null;
701
+ const children = computedProps.formChildren || computedProps.children;
702
+ if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
703
+ ...computedProps,
704
+ id: computedProps.id.toString(),
705
+ children: cloneUnionFaasItemElement(children, { scene: "form" })
706
+ });
707
+ const render = computedProps.formRender || computedProps.render;
708
+ if (render) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
709
+ ...computedProps,
710
+ id: computedProps.id.toString(),
711
+ children: render(void 0, Object.create(null), 0, "form")
712
+ });
713
+ const extendType = extendTypes?.[itemType];
714
+ if (extendType?.children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
715
+ ...computedProps,
716
+ id: computedProps.id.toString(),
717
+ children: cloneUnionFaasItemElement(extendType.children, { scene: "form" })
718
+ });
719
+ switch (itemType) {
720
+ case "string":
721
+ if (isOptionsProps(computedProps)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
722
+ ...computedProps,
723
+ id: computedProps.id.toString(),
724
+ children: computedProps.options.length > 10 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Group, { ...computedProps.input })
725
+ });
726
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
727
+ ...computedProps,
728
+ id: computedProps.id.toString(),
729
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input, { ...computedProps.input })
730
+ });
731
+ case "string[]":
732
+ if (isOptionsProps(computedProps)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
733
+ ...computedProps,
734
+ id: computedProps.id.toString(),
735
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Select, {
736
+ mode: "multiple",
737
+ ...computedProps.input
738
+ })
739
+ });
740
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.List, {
741
+ name: computedProps.name,
742
+ rules: computedProps.rules,
743
+ children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
744
+ computedProps.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
745
+ className: "ant-form-item-label",
746
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
747
+ className: (computedProps.rules || []).find((r) => r.required) && "ant-form-item-required",
748
+ children: computedProps.label
749
+ })
750
+ }),
751
+ fields.map((field) => {
752
+ const { key, ...fieldProps } = field;
753
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
754
+ id: key.toString(),
755
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Row, {
756
+ gutter: 24,
757
+ style: { flexFlow: "row nowrap" },
758
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Col, {
759
+ span: 23,
760
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
761
+ ...fieldProps,
762
+ noStyle: true,
763
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input, { ...computedProps.input })
764
+ })
765
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Col, {
766
+ span: 1,
767
+ children: !computedProps.input?.disabled && (!(computedProps.rules || []).find((r) => r.required) || key > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
768
+ danger: true,
769
+ type: "link",
770
+ style: { float: "right" },
771
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.MinusCircleOutlined, {}),
772
+ onClick: () => remove(field.name)
773
+ })
774
+ })]
775
+ })
776
+ }, key);
777
+ }),
778
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Form.Item, { children: [
779
+ !computedProps.input?.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
780
+ type: "dashed",
781
+ block: true,
782
+ onClick: () => add(),
783
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.PlusOutlined, {})
784
+ }),
785
+ computedProps.extra && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
786
+ className: "ant-form-item-extra",
787
+ children: computedProps.extra
788
+ }),
789
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.ErrorList, { errors })
790
+ ] })
791
+ ] })
792
+ });
793
+ case "number":
794
+ if (isOptionsProps(computedProps)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
795
+ ...computedProps,
796
+ id: computedProps.id.toString(),
797
+ children: computedProps.options.length > 10 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Group, { ...computedProps.input })
798
+ });
799
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
800
+ ...computedProps,
801
+ id: computedProps.id.toString(),
802
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.InputNumber, {
803
+ style: { width: "100%" },
804
+ ...computedProps.input
805
+ })
806
+ });
807
+ case "number[]":
808
+ if (isOptionsProps(computedProps)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
809
+ ...computedProps,
810
+ id: computedProps.id.toString(),
811
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Select, {
812
+ mode: "multiple",
813
+ ...computedProps.input
814
+ })
815
+ });
816
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.List, {
817
+ name: computedProps.name,
818
+ rules: computedProps.rules,
819
+ children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
820
+ computedProps.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
821
+ className: "ant-form-item-label",
822
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
823
+ className: computedProps.rules?.find((r) => r.required) && "ant-form-item-required",
824
+ children: computedProps.label
825
+ })
826
+ }),
827
+ fields.map((field) => {
828
+ const { key, ...fieldProps } = field;
829
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
830
+ id: key.toString(),
831
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Row, {
832
+ gutter: 24,
833
+ style: { flexFlow: "row nowrap" },
834
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Col, {
835
+ span: 23,
836
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
837
+ ...fieldProps,
838
+ noStyle: true,
839
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.InputNumber, {
840
+ style: { width: "100%" },
841
+ ...computedProps.input
842
+ })
843
+ })
844
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Col, {
845
+ span: 1,
846
+ children: !computedProps.input?.disabled && (!(computedProps.rules || []).find((r) => r.required) || key > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
847
+ danger: true,
848
+ type: "link",
849
+ style: { float: "right" },
850
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.MinusCircleOutlined, {}),
851
+ onClick: () => remove(field.name)
852
+ })
853
+ })]
854
+ })
855
+ }, key);
856
+ }),
857
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Form.Item, { children: [
858
+ !computedProps.input?.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
859
+ type: "dashed",
860
+ block: true,
861
+ onClick: () => add(),
862
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.PlusOutlined, {})
863
+ }),
864
+ computedProps.extra && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
865
+ className: "ant-form-item-extra",
866
+ children: computedProps.extra
867
+ }),
868
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.ErrorList, { errors })
869
+ ] })
870
+ ] })
871
+ });
872
+ case "boolean": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
873
+ ...computedProps,
874
+ id: computedProps.id.toString(),
875
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Switch, { ...computedProps.input })
876
+ });
877
+ case "date": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
878
+ ...computedProps,
879
+ id: computedProps.id.toString(),
880
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.DatePicker, { ...computedProps.input })
881
+ });
882
+ case "time": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
883
+ ...computedProps,
884
+ id: computedProps.id.toString(),
885
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.DatePicker, {
886
+ ...computedProps.input,
887
+ showTime: true
888
+ })
889
+ });
890
+ case "object": {
891
+ const objectItems = computedProps.object || [];
892
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [computedProps.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
893
+ className: "ant-form-item-label",
894
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
895
+ className: computedProps.rules?.find((r) => r.required) && "ant-form-item-required",
896
+ children: computedProps.label
897
+ })
898
+ }), objectItems.map((o) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItem, { ...o }, o.id))] });
899
+ }
900
+ case "object[]": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.List, {
901
+ name: computedProps.name,
902
+ rules: computedProps.rules,
903
+ children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [fields.map((field) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Form.Item, {
904
+ id: field.key.toString(),
905
+ style: { marginBottom: 0 },
906
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
907
+ className: "ant-form-item-label",
908
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [
909
+ computedProps.label,
910
+ " ",
911
+ field.name + 1,
912
+ !computedProps.disabled && (!(computedProps.rules || []).find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
913
+ danger: true,
914
+ type: "link",
915
+ onClick: () => remove(field.name),
916
+ children: theme.common.delete
917
+ })
918
+ ] })
919
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Row, {
920
+ gutter: 24,
921
+ children: (computedProps.object || []).map((o) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Col, {
922
+ span: o.col || 24,
923
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItem, {
924
+ ...o,
925
+ name: [field.name, o.id]
926
+ })
927
+ }, o.id))
928
+ })]
929
+ }, field.key)), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Form.Item, { children: [
930
+ !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Button, {
931
+ type: "dashed",
932
+ block: true,
933
+ onClick: () => add(),
934
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.PlusOutlined, {}),
935
+ children: [
936
+ theme.common.add,
937
+ " ",
938
+ computedProps.label
939
+ ]
940
+ }),
941
+ computedProps.extra && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
942
+ className: "ant-form-item-extra",
943
+ children: computedProps.extra
944
+ }),
945
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.ErrorList, { errors })
946
+ ] })] })
947
+ });
948
+ default: return null;
949
+ }
776
950
  }
777
- FormItem.whyDidYouRender = true;
778
951
  FormItem.useStatus = antd.Form.Item.useStatus;
952
+
953
+ //#endregion
954
+ //#region src/Form.tsx
779
955
  function isFormItemProps(item) {
780
- return item.id !== void 0;
956
+ return item.id !== void 0;
781
957
  }
958
+ /**
959
+ * Form component with Ant Design & FaasJS
960
+ *
961
+ * - Based on [Ant Design Form](https://ant.design/components/form/).
962
+ */
782
963
  function Form(props) {
783
- const [loading, setLoading] = react$1.useState(false);
784
- const [computedProps, setComputedProps] = react$1.useState();
785
- const [submit, setSubmit] = react$1.useState();
786
- const config = useConfigContext();
787
- const [extendTypes, setExtendTypes] = react$1.useState();
788
- const [form] = antd.Form.useForm(props.form);
789
- const [initialValues, setInitialValues] = react$1.useState(
790
- props.initialValues || /* @__PURE__ */ Object.create(null)
791
- );
792
- react$1.useEffect(() => {
793
- const { submit: submit2, ...propsCopy } = {
794
- ...props,
795
- form
796
- };
797
- if (typeof submit2 !== "undefined") setSubmit(submit2);
798
- if (propsCopy.initialValues && propsCopy.items?.length) {
799
- for (const key in propsCopy.initialValues) {
800
- propsCopy.initialValues[key] = transferValue(
801
- propsCopy.items.find((item) => isFormItemProps(item) && item.id === key)?.type,
802
- propsCopy.initialValues[key]
803
- );
804
- }
805
- setInitialValues(propsCopy.initialValues);
806
- delete propsCopy.initialValues;
807
- }
808
- if (propsCopy.items?.length)
809
- for (const item of propsCopy.items) {
810
- if (isFormItemProps(item) && item.if)
811
- item.hidden = !item.if(initialValues || /* @__PURE__ */ Object.create(null));
812
- }
813
- if (propsCopy.onFinish) {
814
- propsCopy.onFinish = async (values) => {
815
- setLoading(true);
816
- try {
817
- if (submit2?.to?.action) {
818
- await props.onFinish(
819
- values,
820
- async (values2) => react.faas(
821
- submit2.to.action,
822
- submit2.to.params ? {
823
- ...values2,
824
- ...submit2.to.params
825
- } : values2
826
- )
827
- );
828
- } else await props.onFinish(values);
829
- } catch (error) {
830
- console.error(error);
831
- }
832
- setLoading(false);
833
- };
834
- } else if (submit2 && submit2.to?.action) {
835
- propsCopy.onFinish = async (values) => {
836
- setLoading(true);
837
- return react.faas(
838
- submit2.to.action,
839
- submit2.to.params ? {
840
- ...values,
841
- ...submit2.to.params
842
- } : values
843
- ).then((result) => {
844
- if (submit2.to.then)
845
- submit2.to.then(result);
846
- return result;
847
- }).catch((error) => {
848
- if (submit2.to.catch)
849
- submit2.to.catch(error);
850
- return Promise.reject(error);
851
- }).finally(() => {
852
- if (submit2.to.finally)
853
- submit2.to.finally();
854
- setLoading(false);
855
- });
856
- };
857
- }
858
- if (propsCopy.extendTypes) {
859
- setExtendTypes(propsCopy.extendTypes);
860
- delete propsCopy.extendTypes;
861
- }
862
- setComputedProps(propsCopy);
863
- }, [props]);
864
- const onValuesChange = react.useEqualCallback(
865
- (changedValues, allValues) => {
866
- console.debug("Form:onValuesChange", changedValues, allValues);
867
- if (props.onValuesChange) {
868
- props.onValuesChange(changedValues, allValues);
869
- }
870
- if (!props.items) return;
871
- for (const key in changedValues) {
872
- const item = computedProps.items.find(
873
- (i) => isFormItemProps(i) && i.id === key
874
- );
875
- if (item?.onValueChange)
876
- item.onValueChange(changedValues[key], allValues, form);
877
- }
878
- },
879
- [computedProps]
880
- );
881
- react$1.useEffect(() => {
882
- if (!initialValues) return;
883
- console.debug("Form:initialValues", initialValues);
884
- form.setFieldsValue(initialValues);
885
- setInitialValues(null);
886
- }, [computedProps]);
887
- if (!computedProps) return null;
888
- return /* @__PURE__ */ jsxRuntime.jsxs(antd.Form, { ...computedProps, onValuesChange, children: [
889
- computedProps.beforeItems,
890
- computedProps.items?.map((item) => {
891
- if (isFormItemProps(item))
892
- return /* @__PURE__ */ jsxRuntime.jsx(FormItem, { ...item, extendTypes }, item.id);
893
- return item;
894
- }),
895
- computedProps.children,
896
- typeof submit !== "boolean" && /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { htmlType: "submit", type: "primary", loading, children: submit?.text || config.theme.Form.submit.text }),
897
- computedProps.footer
898
- ] });
964
+ const [loading, setLoading] = (0, react.useState)(false);
965
+ const [computedProps, setComputedProps] = (0, react.useState)();
966
+ const [submit, setSubmit] = (0, react.useState)();
967
+ const config = useConfigContext();
968
+ const [extendTypes, setExtendTypes] = (0, react.useState)();
969
+ const [form] = antd.Form.useForm(props.form);
970
+ const [initialValues, setInitialValues] = (0, react.useState)(props.initialValues || Object.create(null));
971
+ (0, react.useEffect)(() => {
972
+ const { submit, ...propsCopy } = {
973
+ ...props,
974
+ form
975
+ };
976
+ if (typeof submit !== "undefined") setSubmit(submit);
977
+ if (propsCopy.initialValues && propsCopy.items?.length) {
978
+ for (const key in propsCopy.initialValues) propsCopy.initialValues[key] = transferValue(propsCopy.items.find((item) => isFormItemProps(item) && item.id === key)?.type, propsCopy.initialValues[key]);
979
+ setInitialValues(propsCopy.initialValues);
980
+ delete propsCopy.initialValues;
981
+ }
982
+ if (propsCopy.items?.length) {
983
+ for (const item of propsCopy.items) if (isFormItemProps(item) && item.if) item.hidden = !item.if(initialValues || Object.create(null));
984
+ }
985
+ const submitTo = typeof submit === "object" ? submit.to : void 0;
986
+ if (propsCopy.onFinish) {
987
+ const originOnFinish = propsCopy.onFinish;
988
+ propsCopy.onFinish = async (values) => {
989
+ setLoading(true);
990
+ try {
991
+ if (submitTo?.action) await originOnFinish(values, async (nextValues) => (0, _faasjs_react.faas)(submitTo.action, submitTo.params ? {
992
+ ...nextValues,
993
+ ...submitTo.params
994
+ } : nextValues));
995
+ else await originOnFinish(values);
996
+ } catch (error) {
997
+ console.error(error);
998
+ }
999
+ setLoading(false);
1000
+ };
1001
+ } else if (submitTo?.action) propsCopy.onFinish = async (values) => {
1002
+ setLoading(true);
1003
+ return (0, _faasjs_react.faas)(submitTo.action, submitTo.params ? {
1004
+ ...values,
1005
+ ...submitTo.params
1006
+ } : values).then((result) => {
1007
+ submitTo.then?.(result);
1008
+ return result;
1009
+ }).catch((error) => {
1010
+ submitTo.catch?.(error);
1011
+ return Promise.reject(error);
1012
+ }).finally(() => {
1013
+ submitTo.finally?.();
1014
+ setLoading(false);
1015
+ });
1016
+ };
1017
+ if (propsCopy.extendTypes) {
1018
+ setExtendTypes(propsCopy.extendTypes);
1019
+ delete propsCopy.extendTypes;
1020
+ }
1021
+ setComputedProps(propsCopy);
1022
+ }, [props]);
1023
+ const onValuesChange = (0, _faasjs_react.useEqualCallback)((changedValues, allValues) => {
1024
+ console.debug("Form:onValuesChange", changedValues, allValues);
1025
+ if (props.onValuesChange) props.onValuesChange(changedValues, allValues);
1026
+ if (!props.items) return;
1027
+ for (const key in changedValues) {
1028
+ const item = computedProps?.items?.find((i) => isFormItemProps(i) && i.id === key);
1029
+ if (item?.onValueChange) item.onValueChange(changedValues[key], allValues, form);
1030
+ }
1031
+ }, [computedProps]);
1032
+ (0, react.useEffect)(() => {
1033
+ if (!initialValues) return;
1034
+ console.debug("Form:initialValues", initialValues);
1035
+ form.setFieldsValue(initialValues);
1036
+ setInitialValues(null);
1037
+ }, [computedProps]);
1038
+ if (!computedProps) return null;
1039
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Form, {
1040
+ ...computedProps,
1041
+ onValuesChange,
1042
+ children: [
1043
+ computedProps.beforeItems,
1044
+ computedProps.items?.map((item) => {
1045
+ if (isFormItemProps(item)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormItem, {
1046
+ ...item,
1047
+ ...extendTypes ? { extendTypes } : {}
1048
+ }, item.id);
1049
+ return item;
1050
+ }),
1051
+ computedProps.children,
1052
+ typeof submit !== "boolean" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
1053
+ htmlType: "submit",
1054
+ type: "primary",
1055
+ loading,
1056
+ children: submit?.text || config.theme.Form.submit.text
1057
+ }),
1058
+ computedProps.footer
1059
+ ]
1060
+ });
899
1061
  }
900
- Form.whyDidYouRender = true;
901
1062
  Form.useForm = antd.Form.useForm;
902
1063
  Form.useFormInstance = antd.Form.useFormInstance;
903
1064
  Form.useWatch = antd.Form.useWatch;
@@ -905,732 +1066,682 @@ Form.Item = FormItem;
905
1066
  Form.List = antd.Form.List;
906
1067
  Form.ErrorList = antd.Form.ErrorList;
907
1068
  Form.Provider = antd.Form.Provider;
1069
+
1070
+ //#endregion
1071
+ //#region src/Link.tsx
1072
+ /**
1073
+ * Link component with button
1074
+ *
1075
+ * @example
1076
+ * ```tsx
1077
+ * // pure link
1078
+ * <Link href="/">Home</Link>
1079
+ *
1080
+ * // link with button
1081
+ * <Link href="/" button={{ type:'primary' }}>Home</Link>
1082
+ * ```
1083
+ */
908
1084
  function Link(props) {
909
- const { theme: theme2 } = useConfigContext();
910
- const navigate = reactRouterDom.useNavigate();
911
- const target = props.target || theme2.Link?.target || (props.href.startsWith("http") ? "_blank" : void 0);
912
- let computedStyle = {
913
- ...theme2.Link.style || {},
914
- cursor: "pointer",
915
- ...props.style
916
- };
917
- if (props.block)
918
- computedStyle = Object.assign(
919
- {
920
- display: "block",
921
- width: "100%"
922
- },
923
- computedStyle
924
- );
925
- if (props.button)
926
- return /* @__PURE__ */ jsxRuntime.jsx(
927
- antd.Button,
928
- {
929
- ...props.button || {},
930
- style: computedStyle,
931
- onClick: (e) => {
932
- props.onClick ? props.onClick(e) : target === "_blank" ? window.open(props.href) : navigate(props.href);
933
- e.preventDefault();
934
- },
935
- children: props.children ?? props.text
936
- }
937
- );
938
- return /* @__PURE__ */ jsxRuntime.jsx(
939
- antd.Typography.Link,
940
- {
941
- href: props.href,
942
- target,
943
- style: computedStyle,
944
- copyable: props.copyable,
945
- onClick: (e) => {
946
- e.preventDefault();
947
- if (props.onClick) {
948
- props.onClick(e);
949
- return;
950
- }
951
- if (target === "_blank") {
952
- window.open(props.href);
953
- return;
954
- }
955
- navigate(props.href);
956
- },
957
- children: props.children ?? props.text
958
- }
959
- );
1085
+ const { theme } = useConfigContext();
1086
+ const navigate = (0, react_router_dom.useNavigate)();
1087
+ const target = props.target || theme.Link?.target || (props.href.startsWith("http") ? "_blank" : void 0);
1088
+ let computedStyle = {
1089
+ ...theme.Link.style || {},
1090
+ cursor: "pointer",
1091
+ ...props.style
1092
+ };
1093
+ if (props.block) computedStyle = Object.assign({
1094
+ display: "block",
1095
+ width: "100%"
1096
+ }, computedStyle);
1097
+ const buttonProps = props.button && typeof props.button === "object" ? props.button : void 0;
1098
+ const copyableProps = typeof props.copyable === "undefined" ? {} : { copyable: props.copyable };
1099
+ if (props.button) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Button, {
1100
+ ...buttonProps,
1101
+ style: computedStyle,
1102
+ onClick: (e) => {
1103
+ props.onClick ? props.onClick(e) : target === "_blank" ? window.open(props.href) : navigate(props.href);
1104
+ e.preventDefault();
1105
+ },
1106
+ children: props.children ?? props.text
1107
+ });
1108
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Typography.Link, {
1109
+ href: props.href,
1110
+ target,
1111
+ style: computedStyle,
1112
+ ...copyableProps,
1113
+ onClick: (e) => {
1114
+ e.preventDefault();
1115
+ if (props.onClick) {
1116
+ props.onClick(e);
1117
+ return;
1118
+ }
1119
+ if (target === "_blank") {
1120
+ window.open(props.href);
1121
+ return;
1122
+ }
1123
+ navigate(props.href);
1124
+ },
1125
+ children: props.children ?? props.text
1126
+ });
960
1127
  }
961
- Link.whyDidYouRender = true;
1128
+
1129
+ //#endregion
1130
+ //#region src/Routers.tsx
962
1131
  function PageNotFound() {
963
- const { theme: theme2 } = useConfigContext();
964
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Result, { status: "404", title: theme2.common.pageNotFound });
1132
+ const { theme } = useConfigContext();
1133
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Result, {
1134
+ status: "404",
1135
+ title: theme.common.pageNotFound
1136
+ });
965
1137
  }
1138
+ /**
1139
+ * Routes with lazy loading and 404 page.
1140
+ *
1141
+ * @example
1142
+ * ```tsx
1143
+ * import { Routes, lazy } from '@faasjs/ant-design'
1144
+ * import { BrowserRouter } from 'react-router-dom'
1145
+ *
1146
+ * export function App () {
1147
+ * return <BrowserRouter>
1148
+ * <Routes routes={[
1149
+ * {
1150
+ * path: '/',
1151
+ * page: lazy(() => import('./pages/home'))
1152
+ * }
1153
+ * ]} />
1154
+ * </BrowserRouter>
1155
+ * }
1156
+ * ```
1157
+ */
966
1158
  function Routes(props) {
967
- return /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [
968
- props.routes.map((r) => /* @__PURE__ */ jsxRuntime.jsx(
969
- reactRouterDom.Route,
970
- {
971
- ...r,
972
- element: r.element || /* @__PURE__ */ jsxRuntime.jsx(
973
- react$1.Suspense,
974
- {
975
- fallback: props.fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "24px" }, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Skeleton, { active: true }) }),
976
- children: /* @__PURE__ */ jsxRuntime.jsx(r.page, {})
977
- }
978
- )
979
- },
980
- r.path
981
- )),
982
- /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "*", element: props.notFound || /* @__PURE__ */ jsxRuntime.jsx(PageNotFound, {}) }, "*")
983
- ] });
1159
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_router_dom.Routes, { children: [props.routes.map((r) => {
1160
+ const Page = r.page;
1161
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_router_dom.Route, {
1162
+ ...r,
1163
+ element: r.element || (Page ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
1164
+ fallback: props.fallback || /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1165
+ style: { padding: "24px" },
1166
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Skeleton, { active: true })
1167
+ }),
1168
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Page, {})
1169
+ }) : void 0)
1170
+ }, r.path);
1171
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_router_dom.Route, {
1172
+ path: "*",
1173
+ element: props.notFound || /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PageNotFound, {})
1174
+ }, "*")] });
984
1175
  }
985
- Routes.whyDidYouRender = true;
1176
+
1177
+ //#endregion
1178
+ //#region src/Table.tsx
986
1179
  function processValue(item, value) {
987
- const transferred = transferValue(item.type, value);
988
- if (transferred === null || Array.isArray(transferred) && transferred.length === 0)
989
- return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
990
- if (item.options) {
991
- if (item.type.endsWith("[]"))
992
- return transferred.map(
993
- (v) => item.options.find((option) => option.value === v)?.label || v
994
- ).join(", ");
995
- if (["string", "number", "boolean"].includes(item.type))
996
- return item.options.find((option) => option.value === transferred)?.label || transferred;
997
- }
998
- if (item.type.endsWith("[]")) return transferred.join(", ");
999
- if (["date", "time"].includes(item.type))
1000
- return transferred.format(
1001
- item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss"
1002
- );
1003
- return value;
1180
+ const itemType = item.type ?? "string";
1181
+ const transferred = transferValue(itemType, value);
1182
+ if (transferred === null || Array.isArray(transferred) && transferred.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {});
1183
+ if (item.options) {
1184
+ if (itemType.endsWith("[]")) return transferred.map((v) => item.options.find((option) => option.value === v)?.label || v).join(", ");
1185
+ if ([
1186
+ "string",
1187
+ "number",
1188
+ "boolean"
1189
+ ].includes(itemType)) return item.options.find((option) => option.value === transferred)?.label || transferred;
1190
+ }
1191
+ if (itemType.endsWith("[]")) return transferred.join(", ");
1192
+ if (["date", "time"].includes(itemType)) return transferred.format(itemType === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
1193
+ return transferred;
1004
1194
  }
1195
+ /**
1196
+ * Table component with Ant Design & FaasJS
1197
+ *
1198
+ * - Based on [Ant Design Table](https://ant.design/components/table/).
1199
+ * - Support FaasJS injection.
1200
+ * - Auto generate filter dropdown (disable with `filterDropdown: false`).
1201
+ * - Auto generate sorter (disable with `sorter: false`).
1202
+ */
1005
1203
  function Table(props) {
1006
- const [columns, setColumns] = react$1.useState();
1007
- const { theme: theme2 } = useConfigContext();
1008
- const generateFilterDropdown = (item) => {
1009
- if (item.filterDropdown && item.filterDropdown !== true) return;
1010
- if (item.options.length < 11) {
1011
- if (!item.filters)
1012
- item.filters = item.options.map((o) => ({
1013
- text: o.label,
1014
- value: o.value
1015
- }));
1016
- return;
1017
- }
1018
- item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm }) => /* @__PURE__ */ jsxRuntime.jsx(
1019
- "div",
1020
- {
1021
- style: {
1022
- padding: 8,
1023
- width: "200px"
1024
- },
1025
- onKeyDown: (e) => e.stopPropagation(),
1026
- children: /* @__PURE__ */ jsxRuntime.jsx(
1027
- antd.Select,
1028
- {
1029
- options: item.options,
1030
- allowClear: true,
1031
- showSearch: true,
1032
- style: { width: "100%" },
1033
- placeholder: `${theme2.common.search} ${item.title}`,
1034
- value: selectedKeys,
1035
- onChange: (v) => {
1036
- setSelectedKeys(v?.length ? v : []);
1037
- confirm();
1038
- },
1039
- mode: "multiple",
1040
- filterOption: (input, option) => {
1041
- if (!input || !option || !option.label) return true;
1042
- input = input.trim();
1043
- return option.value === input || option.label.toString().toLowerCase().includes(input.toLowerCase());
1044
- }
1045
- }
1046
- )
1047
- }
1048
- );
1049
- return item;
1050
- };
1051
- react$1.useEffect(() => {
1052
- const items = lodashEs.cloneDeep(props.items).filter(
1053
- (item) => !(item.tableChildren === null || item.children === null || item.tableRender === null || item.render === null)
1054
- );
1055
- for (const item of items) {
1056
- if (!item.key) item.key = item.id;
1057
- if (!item.dataIndex) item.dataIndex = item.id;
1058
- item.title = item.title ?? idToTitle(item.id);
1059
- if (!item.type) item.type = "string";
1060
- if (item.options?.length) {
1061
- item.options = transferOptions(item.options);
1062
- item.filters = item.options.map((o) => ({
1063
- text: o.label,
1064
- value: o.value
1065
- })).concat({
1066
- text: /* @__PURE__ */ jsxRuntime.jsx(Blank, {}),
1067
- value: null
1068
- });
1069
- generateFilterDropdown(item);
1070
- }
1071
- const children = item.tableChildren || item.children;
1072
- if (children) {
1073
- item.render = (value, values) => cloneUnionFaasItemElement(children, {
1074
- scene: "table",
1075
- value,
1076
- values,
1077
- index: 0
1078
- });
1079
- delete item.children;
1080
- delete item.tableChildren;
1081
- continue;
1082
- }
1083
- const render = item.tableRender || item.render;
1084
- if (render) {
1085
- item.render = (value, values) => render(value, values, 0, "table");
1086
- delete item.tableRender;
1087
- continue;
1088
- }
1089
- if (props.extendTypes?.[item.type]) {
1090
- if (props.extendTypes[item.type].children) {
1091
- item.render = (value, values) => cloneUnionFaasItemElement(props.extendTypes[item.type].children, {
1092
- scene: "table",
1093
- value,
1094
- values,
1095
- index: 0
1096
- });
1097
- } else if (props.extendTypes[item.type].render)
1098
- item.render = (value, values) => props.extendTypes[item.type].render(value, values, 0, "table");
1099
- else throw Error(`${item.type} requires children or render`);
1100
- continue;
1101
- }
1102
- switch (item.type) {
1103
- case "string":
1104
- if (!item.render) item.render = (value) => processValue(item, value);
1105
- if (item.filterDropdown !== false) {
1106
- if (!item.onFilter && !props.faasData)
1107
- item.onFilter = (value, row) => {
1108
- if (!value || lodashEs.isNil(value)) return true;
1109
- if (lodashEs.isNil(row[item.id])) return false;
1110
- return row[item.id].trim().toLowerCase().includes(value.trim().toLowerCase());
1111
- };
1112
- if (typeof item.filterDropdown === "undefined" && !item.filters && item.optionsType !== "auto")
1113
- item.filterDropdown = ({
1114
- setSelectedKeys,
1115
- confirm,
1116
- clearFilters
1117
- }) => /* @__PURE__ */ jsxRuntime.jsx(
1118
- antd.Input.Search,
1119
- {
1120
- placeholder: `${theme2.common.search} ${item.title}`,
1121
- allowClear: true,
1122
- onSearch: (v) => {
1123
- if (v) {
1124
- setSelectedKeys([v]);
1125
- } else {
1126
- setSelectedKeys([]);
1127
- clearFilters();
1128
- }
1129
- confirm();
1130
- }
1131
- }
1132
- );
1133
- }
1134
- break;
1135
- case "string[]":
1136
- if (!item.render) item.render = (value) => processValue(item, value);
1137
- if (item.filterDropdown !== false) {
1138
- if (!item.onFilter && !props.faasData)
1139
- item.onFilter = (value, row) => {
1140
- if (value === null && (!row[item.id] || !row[item.id].length))
1141
- return true;
1142
- if (!row[item.id] || !row[item.id].length || !value)
1143
- return false;
1144
- return row[item.id].some(
1145
- (v) => v.trim().toLowerCase().includes(value.trim().toLowerCase())
1146
- );
1147
- };
1148
- if (typeof item.filterDropdown === "undefined" && !item.filters && item.optionsType !== "auto")
1149
- item.filterDropdown = ({
1150
- setSelectedKeys,
1151
- confirm,
1152
- clearFilters
1153
- }) => /* @__PURE__ */ jsxRuntime.jsx(
1154
- antd.Input.Search,
1155
- {
1156
- placeholder: `${theme2.common.search} ${item.title}`,
1157
- allowClear: true,
1158
- onSearch: (v) => {
1159
- if (v) {
1160
- setSelectedKeys([v]);
1161
- } else {
1162
- setSelectedKeys([]);
1163
- clearFilters();
1164
- }
1165
- confirm();
1166
- }
1167
- }
1168
- );
1169
- }
1170
- break;
1171
- case "number":
1172
- if (!item.render) item.render = (value) => processValue(item, value);
1173
- if (typeof item.sorter === "undefined")
1174
- item.sorter = (a, b) => a[item.id] - b[item.id];
1175
- if (item.filterDropdown !== false) {
1176
- if (!item.onFilter && !props.faasData)
1177
- item.onFilter = (value, row) => {
1178
- if (value === null) return true;
1179
- if (lodashEs.isNil(row[item.id])) return false;
1180
- return value == row[item.id];
1181
- };
1182
- if (typeof item.filterDropdown === "undefined" && !item.filters)
1183
- item.filterDropdown = ({
1184
- setSelectedKeys,
1185
- confirm,
1186
- clearFilters
1187
- }) => /* @__PURE__ */ jsxRuntime.jsx(
1188
- antd.Input.Search,
1189
- {
1190
- placeholder: `${theme2.common.search} ${item.title}`,
1191
- allowClear: true,
1192
- onSearch: (v) => {
1193
- if (v) {
1194
- setSelectedKeys([Number(v)]);
1195
- } else {
1196
- setSelectedKeys([]);
1197
- clearFilters();
1198
- }
1199
- confirm();
1200
- }
1201
- }
1202
- );
1203
- }
1204
- break;
1205
- case "number[]":
1206
- if (!item.render)
1207
- item.render = (value) => processValue(item, value).join(", ");
1208
- if (item.filterDropdown !== false) {
1209
- if (!item.onFilter && !props.faasData)
1210
- item.onFilter = (value, row) => {
1211
- if (value === null && (!row[item.id] || !row[item.id].length))
1212
- return true;
1213
- if (!row[item.id] || !row[item.id].length) return false;
1214
- return row[item.id].includes(Number(value));
1215
- };
1216
- if (typeof item.filterDropdown === "undefined" && !item.filters)
1217
- item.filterDropdown = ({
1218
- setSelectedKeys,
1219
- confirm,
1220
- clearFilters
1221
- }) => /* @__PURE__ */ jsxRuntime.jsx(
1222
- antd.Input.Search,
1223
- {
1224
- placeholder: `${theme2.common.search} ${item.title}`,
1225
- allowClear: true,
1226
- onSearch: (v) => {
1227
- if (v) {
1228
- setSelectedKeys([Number(v)]);
1229
- } else {
1230
- setSelectedKeys([]);
1231
- clearFilters();
1232
- }
1233
- confirm();
1234
- }
1235
- }
1236
- );
1237
- }
1238
- break;
1239
- case "boolean":
1240
- if (!item.render)
1241
- item.render = (value) => lodashEs.isNil(value) ? /* @__PURE__ */ jsxRuntime.jsx(Blank, {}) : value ? /* @__PURE__ */ jsxRuntime.jsx(
1242
- icons.CheckOutlined,
1243
- {
1244
- style: {
1245
- marginTop: "4px",
1246
- color: "#52c41a"
1247
- }
1248
- }
1249
- ) : /* @__PURE__ */ jsxRuntime.jsx(
1250
- icons.CloseOutlined,
1251
- {
1252
- style: {
1253
- marginTop: "4px",
1254
- color: "#ff4d4f"
1255
- }
1256
- }
1257
- );
1258
- if (item.filterDropdown !== false) {
1259
- if (typeof item.filterDropdown === "undefined")
1260
- item.filterDropdown = ({
1261
- setSelectedKeys,
1262
- selectedKeys,
1263
- confirm
1264
- }) => /* @__PURE__ */ jsxRuntime.jsxs(
1265
- antd.Radio.Group,
1266
- {
1267
- style: { padding: 8 },
1268
- buttonStyle: "solid",
1269
- value: JSON.stringify(selectedKeys[0]),
1270
- onChange: (e) => {
1271
- const Values = {
1272
- true: true,
1273
- false: false,
1274
- null: null
1275
- };
1276
- setSelectedKeys(
1277
- e.target.value ? [Values[e.target.value]] : []
1278
- );
1279
- confirm();
1280
- },
1281
- children: [
1282
- /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { children: theme2.common.all }),
1283
- /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { value: "true", children: /* @__PURE__ */ jsxRuntime.jsx(
1284
- icons.CheckOutlined,
1285
- {
1286
- style: {
1287
- color: "#52c41a",
1288
- verticalAlign: "middle"
1289
- }
1290
- }
1291
- ) }),
1292
- /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { value: "false", children: /* @__PURE__ */ jsxRuntime.jsx(
1293
- icons.CloseOutlined,
1294
- {
1295
- style: {
1296
- verticalAlign: "middle",
1297
- color: "#ff4d4f"
1298
- }
1299
- }
1300
- ) }),
1301
- /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { value: "null", children: theme2.common.blank })
1302
- ]
1303
- }
1304
- );
1305
- if (!item.onFilter && !props.faasData)
1306
- item.onFilter = (value, row) => {
1307
- switch (value) {
1308
- case true:
1309
- return !lodashEs.isNil(row[item.id]) && row[item.id] !== false;
1310
- case false:
1311
- return !lodashEs.isNil(row[item.id]) && !row[item.id];
1312
- default:
1313
- return lodashEs.isNil(row[item.id]);
1314
- }
1315
- };
1316
- }
1317
- break;
1318
- case "date":
1319
- if (!item.render) item.render = (value) => processValue(item, value);
1320
- if (typeof item.sorter === "undefined")
1321
- item.sorter = (a, b, order) => {
1322
- if (lodashEs.isNil(a[item.id])) return order === "ascend" ? 1 : -1;
1323
- if (lodashEs.isNil(b[item.id])) return order === "ascend" ? -1 : 1;
1324
- return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
1325
- };
1326
- if (item.filterDropdown !== false) {
1327
- if (typeof item.filterDropdown === "undefined")
1328
- item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ jsxRuntime.jsx(
1329
- antd.DatePicker.RangePicker,
1330
- {
1331
- onChange: (dates) => {
1332
- setSelectedKeys(
1333
- dates?.[0] && dates[1] ? [
1334
- [
1335
- dates[0].startOf("day").toISOString(),
1336
- dates[1].endOf("day").toISOString()
1337
- ]
1338
- ] : []
1339
- );
1340
- confirm();
1341
- }
1342
- }
1343
- );
1344
- if (!item.onFilter && !props.faasData)
1345
- item.onFilter = (value, row) => {
1346
- if (lodashEs.isNil(value[0])) return true;
1347
- if (lodashEs.isNil(row[item.id])) return false;
1348
- return dayjs2__default.default(row[item.id]) >= dayjs2__default.default(value[0]) && dayjs2__default.default(row[item.id]) <= dayjs2__default.default(value[1]);
1349
- };
1350
- }
1351
- break;
1352
- case "time":
1353
- item.width = item.width ?? 200;
1354
- if (!item.render) item.render = (value) => processValue(item, value);
1355
- if (typeof item.sorter === "undefined")
1356
- item.sorter = (a, b, order) => {
1357
- if (lodashEs.isNil(a[item.id])) return order === "ascend" ? 1 : -1;
1358
- if (lodashEs.isNil(b[item.id])) return order === "ascend" ? -1 : 1;
1359
- return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
1360
- };
1361
- if (item.filterDropdown !== false) {
1362
- if (typeof item.filterDropdown === "undefined")
1363
- item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ jsxRuntime.jsx(
1364
- antd.DatePicker.RangePicker,
1365
- {
1366
- onChange: (dates) => {
1367
- setSelectedKeys(
1368
- dates?.[0] && dates[1] ? [
1369
- [
1370
- dates[0].startOf("day").toISOString(),
1371
- dates[1].endOf("day").toISOString()
1372
- ]
1373
- ] : []
1374
- );
1375
- confirm();
1376
- }
1377
- }
1378
- );
1379
- if (!item.onFilter && !props.faasData)
1380
- item.onFilter = (value, row) => {
1381
- if (lodashEs.isNil(value[0])) return true;
1382
- if (lodashEs.isNil(row[item.id])) return false;
1383
- return dayjs2__default.default(row[item.id]) >= dayjs2__default.default(value[0]) && dayjs2__default.default(row[item.id]) <= dayjs2__default.default(value[1]);
1384
- };
1385
- }
1386
- break;
1387
- case "object":
1388
- if (!item.render)
1389
- item.render = (value) => /* @__PURE__ */ jsxRuntime.jsx(
1390
- Description,
1391
- {
1392
- items: item.object,
1393
- dataSource: value || {},
1394
- column: 1
1395
- }
1396
- );
1397
- break;
1398
- case "object[]":
1399
- if (!item.render)
1400
- item.render = (value) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value.map((v, i) => /* @__PURE__ */ jsxRuntime.jsx(
1401
- Description,
1402
- {
1403
- items: item.object,
1404
- dataSource: v || [],
1405
- column: 1
1406
- },
1407
- i
1408
- )) });
1409
- break;
1410
- default:
1411
- if (!item.render) item.render = (value) => processValue(item, value);
1412
- if (item.filterDropdown !== false && !item.onFilter && !props.faasData)
1413
- item.onFilter = (value, row) => {
1414
- if (value === null && lodashEs.isNil(row[item.id])) return true;
1415
- return value === row[item.id];
1416
- };
1417
- break;
1418
- }
1419
- }
1420
- setColumns(items);
1421
- }, [props.items]);
1422
- react$1.useEffect(() => {
1423
- if (!props.dataSource || !columns) return;
1424
- for (const column of columns) {
1425
- if (column.optionsType === "auto" && !column.options && !column.filters) {
1426
- const options = lodashEs.uniqBy(props.dataSource, column.id).map(
1427
- (v) => ({
1428
- label: v[column.id],
1429
- value: v[column.id]
1430
- })
1431
- );
1432
- if (options.length)
1433
- setColumns((prev) => {
1434
- const newColumns = [...prev];
1435
- const index = newColumns.findIndex((item) => item.id === column.id);
1436
- newColumns[index].options = options;
1437
- generateFilterDropdown(newColumns[index]);
1438
- return newColumns;
1439
- });
1440
- }
1441
- }
1442
- }, [props.dataSource, columns]);
1443
- if (!columns) return null;
1444
- if (props.dataSource)
1445
- return /* @__PURE__ */ jsxRuntime.jsx(
1446
- antd.Table,
1447
- {
1448
- ...props,
1449
- rowKey: props.rowKey || "id",
1450
- columns,
1451
- dataSource: props.dataSource
1452
- }
1453
- );
1454
- return /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { ...props.faasData, children: /* @__PURE__ */ jsxRuntime.jsx(FaasDataTable, { props, columns }) });
1204
+ const [columns, setColumns] = (0, react.useState)();
1205
+ const { theme } = useConfigContext();
1206
+ const generateFilterDropdown = (item) => {
1207
+ if (item.filterDropdown && item.filterDropdown !== true) return;
1208
+ if (!item.options?.length) return;
1209
+ if (item.options.length < 11) {
1210
+ if (!item.filters) item.filters = item.options.map((o) => ({
1211
+ text: o.label,
1212
+ value: o.value
1213
+ }));
1214
+ return;
1215
+ }
1216
+ item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1217
+ style: {
1218
+ padding: 8,
1219
+ width: "200px"
1220
+ },
1221
+ onKeyDown: (e) => e.stopPropagation(),
1222
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Select, {
1223
+ options: item.options,
1224
+ allowClear: true,
1225
+ showSearch: true,
1226
+ style: { width: "100%" },
1227
+ placeholder: `${theme.common.search} ${item.title}`,
1228
+ value: selectedKeys,
1229
+ onChange: (v) => {
1230
+ setSelectedKeys(v?.length ? v : []);
1231
+ confirm();
1232
+ },
1233
+ mode: "multiple",
1234
+ filterOption: (input, option) => {
1235
+ if (!input || !option || !option.label) return true;
1236
+ input = input.trim();
1237
+ return option.value === input || option.label.toString().toLowerCase().includes(input.toLowerCase());
1238
+ }
1239
+ })
1240
+ });
1241
+ return item;
1242
+ };
1243
+ (0, react.useEffect)(() => {
1244
+ const items = (0, lodash_es.cloneDeep)(props.items).filter((item) => !(item.tableChildren === null || item.children === null || item.tableRender === null || item.render === null));
1245
+ for (const item of items) {
1246
+ if (!item.key) item.key = item.id;
1247
+ if (!item.dataIndex) item.dataIndex = item.id;
1248
+ const itemType = item.type ?? "string";
1249
+ item.title = item.title ?? idToTitle(item.id);
1250
+ item.type = itemType;
1251
+ if (item.options?.length) {
1252
+ item.options = transferOptions(item.options);
1253
+ item.filters = item.options.map((o) => ({
1254
+ text: o.label,
1255
+ value: o.value
1256
+ })).concat({
1257
+ text: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {}),
1258
+ value: null
1259
+ });
1260
+ generateFilterDropdown(item);
1261
+ }
1262
+ const children = item.tableChildren || item.children;
1263
+ if (children) {
1264
+ item.render = (value, values) => cloneUnionFaasItemElement(children, {
1265
+ scene: "table",
1266
+ value,
1267
+ values,
1268
+ index: 0
1269
+ });
1270
+ delete item.children;
1271
+ delete item.tableChildren;
1272
+ continue;
1273
+ }
1274
+ const render = item.tableRender || item.render;
1275
+ if (render) {
1276
+ item.render = (value, values) => render(value, values, 0, "table");
1277
+ delete item.tableRender;
1278
+ continue;
1279
+ }
1280
+ const extendType = props.extendTypes?.[itemType];
1281
+ if (extendType) {
1282
+ const extendChildren = extendType.children;
1283
+ if (extendChildren) item.render = (value, values) => cloneUnionFaasItemElement(extendChildren, {
1284
+ scene: "table",
1285
+ value,
1286
+ values,
1287
+ index: 0
1288
+ });
1289
+ else {
1290
+ const extendRender = extendType.render;
1291
+ if (extendRender) item.render = (value, values) => extendRender(value, values, 0, "table");
1292
+ else throw Error(`${itemType} requires children or render`);
1293
+ }
1294
+ continue;
1295
+ }
1296
+ switch (itemType) {
1297
+ case "string":
1298
+ if (!item.render) item.render = (value) => processValue(item, value);
1299
+ if (item.filterDropdown !== false) {
1300
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1301
+ if (!value || (0, lodash_es.isNil)(value)) return true;
1302
+ if ((0, lodash_es.isNil)(row[item.id])) return false;
1303
+ return row[item.id].trim().toLowerCase().includes(value.trim().toLowerCase());
1304
+ };
1305
+ if (typeof item.filterDropdown === "undefined" && !item.filters && item.optionsType !== "auto") item.filterDropdown = ({ setSelectedKeys, confirm, clearFilters }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input.Search, {
1306
+ placeholder: `${theme.common.search} ${item.title}`,
1307
+ allowClear: true,
1308
+ onSearch: (v) => {
1309
+ if (v) setSelectedKeys([v]);
1310
+ else {
1311
+ setSelectedKeys([]);
1312
+ clearFilters?.();
1313
+ }
1314
+ confirm();
1315
+ }
1316
+ });
1317
+ }
1318
+ break;
1319
+ case "string[]":
1320
+ if (!item.render) item.render = (value) => processValue(item, value);
1321
+ if (item.filterDropdown !== false) {
1322
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1323
+ if (value === null && (!row[item.id] || !row[item.id].length)) return true;
1324
+ if (!row[item.id] || !row[item.id].length || !value) return false;
1325
+ return row[item.id].some((v) => v.trim().toLowerCase().includes(value.trim().toLowerCase()));
1326
+ };
1327
+ if (typeof item.filterDropdown === "undefined" && !item.filters && item.optionsType !== "auto") item.filterDropdown = ({ setSelectedKeys, confirm, clearFilters }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input.Search, {
1328
+ placeholder: `${theme.common.search} ${item.title}`,
1329
+ allowClear: true,
1330
+ onSearch: (v) => {
1331
+ if (v) setSelectedKeys([v]);
1332
+ else {
1333
+ setSelectedKeys([]);
1334
+ clearFilters?.();
1335
+ }
1336
+ confirm();
1337
+ }
1338
+ });
1339
+ }
1340
+ break;
1341
+ case "number":
1342
+ if (!item.render) item.render = (value) => processValue(item, value);
1343
+ if (typeof item.sorter === "undefined") item.sorter = (a, b) => a[item.id] - b[item.id];
1344
+ if (item.filterDropdown !== false) {
1345
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1346
+ if (value === null) return true;
1347
+ if ((0, lodash_es.isNil)(row[item.id])) return false;
1348
+ return value == row[item.id];
1349
+ };
1350
+ if (typeof item.filterDropdown === "undefined" && !item.filters) item.filterDropdown = ({ setSelectedKeys, confirm, clearFilters }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input.Search, {
1351
+ placeholder: `${theme.common.search} ${item.title}`,
1352
+ allowClear: true,
1353
+ onSearch: (v) => {
1354
+ if (v) setSelectedKeys([Number(v)]);
1355
+ else {
1356
+ setSelectedKeys([]);
1357
+ clearFilters?.();
1358
+ }
1359
+ confirm();
1360
+ }
1361
+ });
1362
+ }
1363
+ break;
1364
+ case "number[]":
1365
+ if (!item.render) item.render = (value) => processValue(item, value).join(", ");
1366
+ if (item.filterDropdown !== false) {
1367
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1368
+ if (value === null && (!row[item.id] || !row[item.id].length)) return true;
1369
+ if (!row[item.id] || !row[item.id].length) return false;
1370
+ return row[item.id].includes(Number(value));
1371
+ };
1372
+ if (typeof item.filterDropdown === "undefined" && !item.filters) item.filterDropdown = ({ setSelectedKeys, confirm, clearFilters }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input.Search, {
1373
+ placeholder: `${theme.common.search} ${item.title}`,
1374
+ allowClear: true,
1375
+ onSearch: (v) => {
1376
+ if (v) setSelectedKeys([Number(v)]);
1377
+ else {
1378
+ setSelectedKeys([]);
1379
+ clearFilters?.();
1380
+ }
1381
+ confirm();
1382
+ }
1383
+ });
1384
+ }
1385
+ break;
1386
+ case "boolean":
1387
+ if (!item.render) item.render = (value) => (0, lodash_es.isNil)(value) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {}) : value ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CheckOutlined, { style: {
1388
+ marginTop: "4px",
1389
+ color: "#52c41a"
1390
+ } }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CloseOutlined, { style: {
1391
+ marginTop: "4px",
1392
+ color: "#ff4d4f"
1393
+ } });
1394
+ if (item.filterDropdown !== false) {
1395
+ if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Radio.Group, {
1396
+ style: { padding: 8 },
1397
+ buttonStyle: "solid",
1398
+ value: JSON.stringify(selectedKeys[0]),
1399
+ onChange: (e) => {
1400
+ setSelectedKeys(e.target.value ? [{
1401
+ true: true,
1402
+ false: false,
1403
+ null: null
1404
+ }[e.target.value]] : []);
1405
+ confirm();
1406
+ },
1407
+ children: [
1408
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, { children: theme.common.all }),
1409
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, {
1410
+ value: "true",
1411
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CheckOutlined, { style: {
1412
+ color: "#52c41a",
1413
+ verticalAlign: "middle"
1414
+ } })
1415
+ }),
1416
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, {
1417
+ value: "false",
1418
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CloseOutlined, { style: {
1419
+ verticalAlign: "middle",
1420
+ color: "#ff4d4f"
1421
+ } })
1422
+ }),
1423
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, {
1424
+ value: "null",
1425
+ children: theme.common.blank
1426
+ })
1427
+ ]
1428
+ });
1429
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1430
+ switch (value) {
1431
+ case true: return !(0, lodash_es.isNil)(row[item.id]) && row[item.id] !== false;
1432
+ case false: return !(0, lodash_es.isNil)(row[item.id]) && !row[item.id];
1433
+ default: return (0, lodash_es.isNil)(row[item.id]);
1434
+ }
1435
+ };
1436
+ }
1437
+ break;
1438
+ case "date":
1439
+ if (!item.render) item.render = (value) => processValue(item, value);
1440
+ if (typeof item.sorter === "undefined") item.sorter = (a, b, order) => {
1441
+ if ((0, lodash_es.isNil)(a[item.id])) return order === "ascend" ? 1 : -1;
1442
+ if ((0, lodash_es.isNil)(b[item.id])) return order === "ascend" ? -1 : 1;
1443
+ return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
1444
+ };
1445
+ if (item.filterDropdown !== false) {
1446
+ if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.DatePicker.RangePicker, { onChange: (dates) => {
1447
+ setSelectedKeys(dates?.[0] && dates[1] ? [[dates[0].startOf("day").toISOString(), dates[1].endOf("day").toISOString()]] : []);
1448
+ confirm();
1449
+ } });
1450
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1451
+ if ((0, lodash_es.isNil)(value[0])) return true;
1452
+ if ((0, lodash_es.isNil)(row[item.id])) return false;
1453
+ return (0, dayjs.default)(row[item.id]) >= (0, dayjs.default)(value[0]) && (0, dayjs.default)(row[item.id]) <= (0, dayjs.default)(value[1]);
1454
+ };
1455
+ }
1456
+ break;
1457
+ case "time":
1458
+ item.width = item.width ?? 200;
1459
+ if (!item.render) item.render = (value) => processValue(item, value);
1460
+ if (typeof item.sorter === "undefined") item.sorter = (a, b, order) => {
1461
+ if ((0, lodash_es.isNil)(a[item.id])) return order === "ascend" ? 1 : -1;
1462
+ if ((0, lodash_es.isNil)(b[item.id])) return order === "ascend" ? -1 : 1;
1463
+ return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
1464
+ };
1465
+ if (item.filterDropdown !== false) {
1466
+ if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.DatePicker.RangePicker, { onChange: (dates) => {
1467
+ setSelectedKeys(dates?.[0] && dates[1] ? [[dates[0].startOf("day").toISOString(), dates[1].endOf("day").toISOString()]] : []);
1468
+ confirm();
1469
+ } });
1470
+ if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1471
+ if ((0, lodash_es.isNil)(value[0])) return true;
1472
+ if ((0, lodash_es.isNil)(row[item.id])) return false;
1473
+ return (0, dayjs.default)(row[item.id]) >= (0, dayjs.default)(value[0]) && (0, dayjs.default)(row[item.id]) <= (0, dayjs.default)(value[1]);
1474
+ };
1475
+ }
1476
+ break;
1477
+ case "object":
1478
+ if (!item.render) item.render = (value) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Description, {
1479
+ items: item.object || [],
1480
+ dataSource: value || {},
1481
+ column: 1
1482
+ });
1483
+ break;
1484
+ case "object[]":
1485
+ if (!item.render) item.render = (value) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: value.map((v, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Description, {
1486
+ items: item.object || [],
1487
+ dataSource: v || [],
1488
+ column: 1
1489
+ }, i)) });
1490
+ break;
1491
+ default:
1492
+ if (!item.render) item.render = (value) => processValue(item, value);
1493
+ if (item.filterDropdown !== false && !item.onFilter && !props.faasData) item.onFilter = (value, row) => {
1494
+ if (value === null && (0, lodash_es.isNil)(row[item.id])) return true;
1495
+ return value === row[item.id];
1496
+ };
1497
+ break;
1498
+ }
1499
+ }
1500
+ setColumns(items);
1501
+ }, [props.items]);
1502
+ (0, react.useEffect)(() => {
1503
+ if (!props.dataSource || !columns) return;
1504
+ for (const column of columns) if (column.optionsType === "auto" && !column.options && !column.filters) {
1505
+ const options = (0, lodash_es.uniqBy)(props.dataSource, column.id).map((v) => ({
1506
+ label: v[column.id],
1507
+ value: v[column.id]
1508
+ }));
1509
+ if (options.length) setColumns((prev) => {
1510
+ const newColumns = [...prev || []];
1511
+ const index = newColumns.findIndex((item) => item.id === column.id);
1512
+ if (index < 0) return newColumns;
1513
+ newColumns[index].options = options;
1514
+ generateFilterDropdown(newColumns[index]);
1515
+ return newColumns;
1516
+ });
1517
+ }
1518
+ }, [props.dataSource, columns]);
1519
+ if (!columns) return null;
1520
+ if (props.dataSource) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Table, {
1521
+ ...props,
1522
+ rowKey: props.rowKey || "id",
1523
+ columns,
1524
+ dataSource: props.dataSource
1525
+ });
1526
+ if (!props.faasData) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FaasDataTable, {
1527
+ props,
1528
+ columns
1529
+ });
1530
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FaasDataWrapper, {
1531
+ ...props.faasData,
1532
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FaasDataTable, {
1533
+ props,
1534
+ columns
1535
+ })
1536
+ });
1455
1537
  }
1456
- function FaasDataTable({
1457
- props,
1458
- columns,
1459
- data,
1460
- params,
1461
- reload,
1462
- loading
1463
- }) {
1464
- const [currentColumns, setCurrentColumns] = react$1.useState(columns);
1465
- react$1.useEffect(() => {
1466
- if (!data || Array.isArray(data)) return;
1467
- setCurrentColumns((prev) => {
1468
- const newColumns = [...prev];
1469
- for (const column of newColumns) {
1470
- if (data.options?.[column.id]) {
1471
- column.options = transferOptions(data.options[column.id]);
1472
- column.filters = column.options.map((v) => ({
1473
- text: v.label,
1474
- value: v.value
1475
- })).concat({
1476
- text: /* @__PURE__ */ jsxRuntime.jsx(Blank, {}),
1477
- value: null
1478
- });
1479
- column.render = (value) => processValue(column, value);
1480
- if (column.filterDropdown) delete column.filterDropdown;
1481
- continue;
1482
- }
1483
- if (column.optionsType === "auto" && !column.options && !column.filters) {
1484
- const filters = lodashEs.uniqBy(props.dataSource, column.id).map(
1485
- (v) => ({
1486
- text: v[column.id],
1487
- value: v[column.id]
1488
- })
1489
- );
1490
- if (filters.length)
1491
- column.filters = filters.concat({
1492
- text: /* @__PURE__ */ jsxRuntime.jsx(Blank, {}),
1493
- value: null
1494
- });
1495
- }
1496
- }
1497
- return newColumns;
1498
- });
1499
- }, [data, props.dataSource]);
1500
- if (!data)
1501
- return /* @__PURE__ */ jsxRuntime.jsx(
1502
- antd.Table,
1503
- {
1504
- ...props,
1505
- loading,
1506
- rowKey: props.rowKey || "id",
1507
- columns: currentColumns,
1508
- dataSource: []
1509
- }
1510
- );
1511
- if (Array.isArray(data))
1512
- return /* @__PURE__ */ jsxRuntime.jsx(
1513
- antd.Table,
1514
- {
1515
- ...props,
1516
- loading,
1517
- rowKey: props.rowKey || "id",
1518
- columns: currentColumns,
1519
- dataSource: data
1520
- }
1521
- );
1522
- return /* @__PURE__ */ jsxRuntime.jsx(
1523
- antd.Table,
1524
- {
1525
- ...props,
1526
- loading,
1527
- rowKey: props.rowKey || "id",
1528
- columns: currentColumns,
1529
- dataSource: data.rows,
1530
- pagination: props.pagination === false ? false : {
1531
- ...props.pagination || /* @__PURE__ */ Object.create(null),
1532
- ...data.pagination || /* @__PURE__ */ Object.create(null)
1533
- },
1534
- onChange: (pagination, filters, sorter, extra) => {
1535
- if (props.onChange) {
1536
- const processed = props.onChange(pagination, filters, sorter, extra);
1537
- reload({
1538
- ...params || /* @__PURE__ */ Object.create(null),
1539
- pagination: processed.pagination,
1540
- filters: processed.filters,
1541
- sorter: processed.sorter,
1542
- extra: processed.extra
1543
- });
1544
- return;
1545
- }
1546
- reload({
1547
- ...params || /* @__PURE__ */ Object.create(null),
1548
- pagination,
1549
- filters,
1550
- sorter
1551
- });
1552
- }
1553
- }
1554
- );
1538
+ function FaasDataTable({ props, columns, data, params, reload, loading }) {
1539
+ const [currentColumns, setCurrentColumns] = (0, react.useState)(columns);
1540
+ (0, react.useEffect)(() => {
1541
+ if (!data || Array.isArray(data)) return;
1542
+ setCurrentColumns((prev) => {
1543
+ const newColumns = [...prev];
1544
+ for (const column of newColumns) {
1545
+ if (data.options?.[column.id]) {
1546
+ column.options = transferOptions(data.options[column.id]);
1547
+ column.filters = column.options.map((v) => ({
1548
+ text: v.label,
1549
+ value: v.value
1550
+ })).concat({
1551
+ text: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {}),
1552
+ value: null
1553
+ });
1554
+ column.render = (value) => processValue(column, value);
1555
+ if (column.filterDropdown) delete column.filterDropdown;
1556
+ continue;
1557
+ }
1558
+ if (column.optionsType === "auto" && !column.options && !column.filters) {
1559
+ const filters = (0, lodash_es.uniqBy)(props.dataSource, column.id).map((v) => ({
1560
+ text: v[column.id],
1561
+ value: v[column.id]
1562
+ }));
1563
+ if (filters.length) column.filters = filters.concat({
1564
+ text: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Blank, {}),
1565
+ value: null
1566
+ });
1567
+ }
1568
+ }
1569
+ return newColumns;
1570
+ });
1571
+ }, [data, props.dataSource]);
1572
+ if (!data) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Table, {
1573
+ ...props,
1574
+ ...typeof loading === "undefined" ? {} : { loading },
1575
+ rowKey: props.rowKey || "id",
1576
+ columns: currentColumns,
1577
+ dataSource: []
1578
+ });
1579
+ if (Array.isArray(data)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Table, {
1580
+ ...props,
1581
+ ...typeof loading === "undefined" ? {} : { loading },
1582
+ rowKey: props.rowKey || "id",
1583
+ columns: currentColumns,
1584
+ dataSource: data
1585
+ });
1586
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Table, {
1587
+ ...props,
1588
+ ...typeof loading === "undefined" ? {} : { loading },
1589
+ rowKey: props.rowKey || "id",
1590
+ columns: currentColumns,
1591
+ dataSource: data.rows,
1592
+ pagination: props.pagination === false ? false : {
1593
+ ...props.pagination || Object.create(null),
1594
+ ...data.pagination || Object.create(null)
1595
+ },
1596
+ onChange: (pagination, filters, sorter, extra) => {
1597
+ if (!reload) return;
1598
+ if (props.onChange) {
1599
+ const processed = props.onChange(pagination, filters, sorter, extra);
1600
+ reload({
1601
+ ...params || Object.create(null),
1602
+ pagination: processed.pagination,
1603
+ filters: processed.filters,
1604
+ sorter: processed.sorter,
1605
+ extra: processed.extra
1606
+ });
1607
+ return;
1608
+ }
1609
+ reload({
1610
+ ...params || Object.create(null),
1611
+ pagination,
1612
+ filters,
1613
+ sorter
1614
+ });
1615
+ }
1616
+ });
1555
1617
  }
1618
+
1619
+ //#endregion
1620
+ //#region src/Tabs.tsx
1621
+ /**
1622
+ * Tabs component with Ant Design & FaasJS
1623
+ *
1624
+ * - Based on [Ant Design Tabs](https://ant.design/components/tabs/).
1625
+ * - Support auto skip null/false tab item.
1626
+ * - Support `id` as key and label.
1627
+ *
1628
+ * @example
1629
+ * ```tsx
1630
+ * import { Tabs } from '@faasjs/ant-design'
1631
+ *
1632
+ * <Tabs
1633
+ * items={[
1634
+ * {
1635
+ * id: 'id',
1636
+ * children: 'content',
1637
+ * },
1638
+ * 1 === 0 && {
1639
+ * id: 'hidden',
1640
+ * children: 'content',
1641
+ * },
1642
+ * ]}
1643
+ * />
1644
+ * ```
1645
+ */
1556
1646
  function Tabs(props) {
1557
- return /* @__PURE__ */ jsxRuntime.jsx(
1558
- antd.Tabs,
1559
- {
1560
- ...props,
1561
- items: props.items.filter(Boolean).map((i) => ({
1562
- ...i,
1563
- key: i.key ?? i.id,
1564
- label: i.label ?? i.title ?? i.id
1565
- }))
1566
- }
1567
- );
1647
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Tabs, {
1648
+ ...props,
1649
+ items: props.items.filter(Boolean).map((i) => ({
1650
+ ...i,
1651
+ key: i.key ?? i.id,
1652
+ label: i.label ?? i.title ?? i.id
1653
+ }))
1654
+ });
1568
1655
  }
1569
- Tabs.whyDidYouRender = true;
1656
+
1657
+ //#endregion
1658
+ //#region src/Title.tsx
1659
+ /**
1660
+ * Title is used to change the title of the page
1661
+ *
1662
+ * Return null by default.
1663
+ *
1664
+ * ```tsx
1665
+ * // return null
1666
+ * <Title title='hi' /> // => change the document.title to 'hi'
1667
+ * <Title title={['a', 'b']} /> // => change the document.title to 'a - b'
1668
+ *
1669
+ * // return h1
1670
+ * <Title title='hi' h1 /> // => <h1>hi</h1>
1671
+ * <Title title={['a', 'b']} h1 /> // => <h1>a</h1>
1672
+ *
1673
+ * // return children
1674
+ * <Title title='hi'><CustomTitle /></Title> // => <CustomTitle />
1675
+ * ```
1676
+ */
1570
1677
  function Title(props) {
1571
- const { theme: theme2 } = useConfigContext();
1572
- react$1.useEffect(() => {
1573
- const title = Array.isArray(props.title) ? props.title : [props.title];
1574
- document.title = title.concat(props.suffix || theme2.Title.suffix).filter((t) => !!t).join(props.separator || theme2.Title.separator);
1575
- }, [props, theme2.Title]);
1576
- if (props.h1) {
1577
- if (typeof props.h1 === "boolean")
1578
- return /* @__PURE__ */ jsxRuntime.jsx("h1", { children: Array.isArray(props.title) ? props.title[0] : props.title });
1579
- return /* @__PURE__ */ jsxRuntime.jsx("h1", { className: props.h1.className, style: props.h1.style, children: Array.isArray(props.title) ? props.title[0] : props.title });
1580
- }
1581
- if (props.plain)
1582
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: Array.isArray(props.title) ? props.title[0] : props.title });
1583
- if (props.children)
1584
- return react$1.cloneElement(props.children, { title: props.title });
1585
- return null;
1678
+ const { theme } = useConfigContext();
1679
+ (0, react.useEffect)(() => {
1680
+ const title = Array.isArray(props.title) ? props.title : [props.title];
1681
+ document.title = title.concat(props.suffix || theme.Title.suffix).filter((t) => !!t).join(props.separator || theme.Title.separator);
1682
+ }, [props, theme.Title]);
1683
+ if (props.h1) {
1684
+ if (typeof props.h1 === "boolean") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: Array.isArray(props.title) ? props.title[0] : props.title });
1685
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
1686
+ className: props.h1.className,
1687
+ style: props.h1.style,
1688
+ children: Array.isArray(props.title) ? props.title[0] : props.title
1689
+ });
1690
+ }
1691
+ if (props.plain) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: Array.isArray(props.title) ? props.title[0] : props.title });
1692
+ if (props.children) return (0, react.cloneElement)(props.children, { title: props.title });
1693
+ return null;
1586
1694
  }
1587
- Title.whyDidYouRender = true;
1695
+
1696
+ //#endregion
1697
+ //#region src/useThemeToken.ts
1698
+ /**
1699
+ * Hook to retrieve the theme token from the Ant Design theme configuration.
1700
+ *
1701
+ * This function uses the `theme.useToken` method to get the current theme configuration
1702
+ * and returns the `token` property from the configuration.
1703
+ *
1704
+ * @returns {GlobalToken} The theme token from the Ant Design theme configuration.
1705
+ */
1588
1706
  function useThemeToken() {
1589
- const config = antd.theme.useToken();
1590
- return config.token;
1707
+ return antd.theme.useToken().token;
1591
1708
  }
1592
1709
 
1593
- Object.defineProperty(exports, "FaasReactClient", {
1594
- enumerable: true,
1595
- get: function () { return react.FaasReactClient; }
1596
- });
1597
- Object.defineProperty(exports, "faas", {
1598
- enumerable: true,
1599
- get: function () { return react.faas; }
1600
- });
1601
- Object.defineProperty(exports, "useFaas", {
1602
- enumerable: true,
1603
- get: function () { return react.useFaas; }
1604
- });
1605
- Object.defineProperty(exports, "lazy", {
1606
- enumerable: true,
1607
- get: function () { return react$1.lazy; }
1608
- });
1710
+ //#endregion
1609
1711
  exports.App = App;
1610
1712
  exports.Blank = Blank;
1611
1713
  exports.ConfigContext = ConfigContext;
1612
1714
  exports.ConfigProvider = ConfigProvider;
1613
1715
  exports.Description = Description;
1614
- exports.Drawer = Drawer;
1716
+ exports.Drawer = antd.Drawer;
1615
1717
  exports.ErrorBoundary = ErrorBoundary;
1616
1718
  exports.FaasDataWrapper = FaasDataWrapper;
1719
+ exports.FaasReactClient = _faasjs_react.FaasReactClient;
1617
1720
  exports.Form = Form;
1618
1721
  exports.FormItem = FormItem;
1619
1722
  exports.Link = Link;
1620
1723
  exports.Loading = Loading;
1621
- exports.Modal = Modal;
1724
+ exports.Modal = antd.Modal;
1622
1725
  exports.PageNotFound = PageNotFound;
1623
1726
  exports.Routes = Routes;
1624
1727
  exports.Table = Table;
1625
1728
  exports.Tabs = Tabs;
1626
1729
  exports.Title = Title;
1627
1730
  exports.cloneUnionFaasItemElement = cloneUnionFaasItemElement;
1731
+ exports.faas = _faasjs_react.faas;
1628
1732
  exports.idToTitle = idToTitle;
1733
+ Object.defineProperty(exports, 'lazy', {
1734
+ enumerable: true,
1735
+ get: function () {
1736
+ return react.lazy;
1737
+ }
1738
+ });
1629
1739
  exports.transferOptions = transferOptions;
1630
1740
  exports.transferValue = transferValue;
1631
1741
  exports.useApp = useApp;
1632
1742
  exports.useConfigContext = useConfigContext;
1633
1743
  exports.useDrawer = useDrawer;
1744
+ exports.useFaas = _faasjs_react.useFaas;
1634
1745
  exports.useModal = useModal;
1635
1746
  exports.useThemeToken = useThemeToken;
1636
- exports.withFaasData = withFaasData;
1747
+ exports.withFaasData = withFaasData;