@faasjs/ant-design 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +70 -15
- package/dist/index.d.ts +70 -15
- package/dist/index.js +68 -41
- package/dist/index.mjs +70 -43
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ type FaasItemProps = {
|
|
|
42
42
|
- [DrawerProps](interfaces/DrawerProps.md)
|
|
43
43
|
- [ErrorBoundaryProps](interfaces/ErrorBoundaryProps.md)
|
|
44
44
|
- [ExtendDescriptionTypeProps](interfaces/ExtendDescriptionTypeProps.md)
|
|
45
|
+
- [ExtendFormItemProps](interfaces/ExtendFormItemProps.md)
|
|
45
46
|
- [FaasDataWrapperProps](interfaces/FaasDataWrapperProps.md)
|
|
46
47
|
- [FaasItemProps](interfaces/FaasItemProps.md)
|
|
47
48
|
- [FormItemProps](interfaces/FormItemProps.md)
|
|
@@ -60,7 +61,6 @@ type FaasItemProps = {
|
|
|
60
61
|
|
|
61
62
|
- [BaseOption](type-aliases/BaseOption.md)
|
|
62
63
|
- [ExtendDescriptionItemProps](type-aliases/ExtendDescriptionItemProps.md)
|
|
63
|
-
- [ExtendFormItemProps](type-aliases/ExtendFormItemProps.md)
|
|
64
64
|
- [ExtendFormTypeProps](type-aliases/ExtendFormTypeProps.md)
|
|
65
65
|
- [ExtendTableItemProps](type-aliases/ExtendTableItemProps.md)
|
|
66
66
|
- [ExtendTableTypeProps](type-aliases/ExtendTableTypeProps.md)
|
package/dist/index.d.mts
CHANGED
|
@@ -11,7 +11,7 @@ import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
|
|
|
11
11
|
import * as react from 'react';
|
|
12
12
|
import { Dispatch, SetStateAction, CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
|
|
13
13
|
export { lazy } from 'react';
|
|
14
|
-
import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps,
|
|
14
|
+
import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, FormInstance, InputProps, SelectProps, RadioProps, InputNumberProps, SwitchProps, DatePickerProps, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
|
|
15
15
|
import { BrowserRouterProps, RouteProps } from 'react-router-dom';
|
|
16
16
|
import { Dayjs } from 'dayjs';
|
|
17
17
|
import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
|
|
@@ -145,16 +145,24 @@ declare function useConfigContext(): Partial<ConfigProviderProps>;
|
|
|
145
145
|
|
|
146
146
|
interface AppProps {
|
|
147
147
|
children: React.ReactNode;
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
/**
|
|
149
|
+
* `false` to disable StyleProvider.
|
|
150
|
+
*
|
|
151
|
+
* @see https://ant.design/docs/react/compatible-style#styleprovider
|
|
152
|
+
*/
|
|
153
|
+
styleProviderProps?: StyleProviderProps | false;
|
|
154
|
+
/** @see https://ant.design/components/config-provider/#API */
|
|
151
155
|
configProviderProps?: ConfigProviderProps$1;
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
/**
|
|
157
|
+
* `false` to disable BrowserRouter.
|
|
158
|
+
*
|
|
159
|
+
* @see https://reactrouter.com/en/router-components/browser-router
|
|
160
|
+
*/
|
|
161
|
+
browserRouterProps?: BrowserRouterProps | false;
|
|
162
|
+
/** @see https://faasjs.com/doc/ant-design/#errorboundary */
|
|
155
163
|
errorBoundaryProps?: Omit<ErrorBoundaryProps, 'children'>;
|
|
156
|
-
/** https://faasjs.com/doc/ant-design/#configprovider */
|
|
157
|
-
faasConfigProviderProps?: Omit<ConfigProviderProps, 'children'
|
|
164
|
+
/** @see https://faasjs.com/doc/ant-design/#configprovider */
|
|
165
|
+
faasConfigProviderProps?: Omit<ConfigProviderProps, 'children'> | false;
|
|
158
166
|
}
|
|
159
167
|
interface useAppProps {
|
|
160
168
|
message: MessageInstance;
|
|
@@ -234,9 +242,20 @@ type ExtendFormTypeProps<T = any> = {
|
|
|
234
242
|
type ExtendTypes = {
|
|
235
243
|
[type: string]: ExtendFormTypeProps;
|
|
236
244
|
};
|
|
237
|
-
type
|
|
238
|
-
|
|
239
|
-
|
|
245
|
+
type InputTypeMap<T> = {
|
|
246
|
+
string: InputProps | SelectProps<T> | RadioProps;
|
|
247
|
+
'string[]': InputProps | SelectProps<T> | RadioProps;
|
|
248
|
+
number: InputNumberProps | SelectProps<T> | RadioProps;
|
|
249
|
+
'number[]': InputNumberProps | SelectProps<T> | RadioProps;
|
|
250
|
+
boolean: SwitchProps;
|
|
251
|
+
date: DatePickerProps;
|
|
252
|
+
time: DatePickerProps;
|
|
253
|
+
object: never;
|
|
254
|
+
'object[]': never;
|
|
255
|
+
};
|
|
256
|
+
interface FormItemProps<T = any> extends BaseItemProps, Omit<FormItemProps$1<T>, 'id' | 'children' | 'render'> {
|
|
257
|
+
type?: FaasItemType;
|
|
258
|
+
input?: InputTypeMap<T>[FaasItemType];
|
|
240
259
|
maxCount?: number;
|
|
241
260
|
object?: FormItemProps[];
|
|
242
261
|
disabled?: boolean;
|
|
@@ -254,6 +273,42 @@ interface FormItemProps<T = any> extends FaasItemProps, Omit<FormItemProps$1<T>,
|
|
|
254
273
|
/** trigger when any item's value changed */
|
|
255
274
|
if?: (values: Record<string, any>) => boolean;
|
|
256
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Extend custom form item types.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import type { ExtendFormItemProps, FormProps } from '@faasjs/ant-design'
|
|
282
|
+
*
|
|
283
|
+
* // define custom type
|
|
284
|
+
* interface ExtendTypes extends ExtendFormItemProps {
|
|
285
|
+
* type: 'password'
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* // extend form
|
|
289
|
+
* function ExtendForm(props: FormProps<any, ExtendTypes>) {
|
|
290
|
+
* return (
|
|
291
|
+
* <Form
|
|
292
|
+
* {...props}
|
|
293
|
+
* extendTypes={{ password: { children: <Input.Password /> } }}
|
|
294
|
+
* />
|
|
295
|
+
* )
|
|
296
|
+
* }
|
|
297
|
+
*
|
|
298
|
+
* // use custom type
|
|
299
|
+
* <ExtendForm
|
|
300
|
+
* items={[
|
|
301
|
+
* {
|
|
302
|
+
* id: 'test',
|
|
303
|
+
* type: 'password',
|
|
304
|
+
* },
|
|
305
|
+
* ]}
|
|
306
|
+
* />
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
interface ExtendFormItemProps extends Omit<FormItemProps, 'type'> {
|
|
310
|
+
type?: string;
|
|
311
|
+
}
|
|
257
312
|
/**
|
|
258
313
|
* FormItem
|
|
259
314
|
*
|
|
@@ -515,8 +570,8 @@ type FormSubmitProps = {
|
|
|
515
570
|
finally?: () => void;
|
|
516
571
|
};
|
|
517
572
|
};
|
|
518
|
-
interface FormProps<Values extends Record<string, any> = any, ExtendItemProps =
|
|
519
|
-
items?: (
|
|
573
|
+
interface FormProps<Values extends Record<string, any> = any, ExtendItemProps extends ExtendFormItemProps = ExtendFormItemProps> extends Omit<FormProps$1<Values>, 'onFinish' | 'children' | 'initialValues'> {
|
|
574
|
+
items?: ((ExtendItemProps extends ExtendFormItemProps ? ExtendItemProps | FormItemProps : FormItemProps) | JSX.Element)[];
|
|
520
575
|
/** Default: { text: 'Submit' }, set false to disable it */
|
|
521
576
|
submit?: false | FormSubmitProps;
|
|
522
577
|
onFinish?: (values: Values, submit?: (values: any) => Promise<any>) => Promise<any>;
|
|
@@ -524,7 +579,7 @@ interface FormProps<Values extends Record<string, any> = any, ExtendItemProps =
|
|
|
524
579
|
footer?: JSX.Element | JSX.Element[];
|
|
525
580
|
extendTypes?: ExtendTypes;
|
|
526
581
|
children?: ReactNode;
|
|
527
|
-
initialValues?: Values
|
|
582
|
+
initialValues?: Partial<Values>;
|
|
528
583
|
}
|
|
529
584
|
/**
|
|
530
585
|
* Form component with Ant Design & FaasJS
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
|
|
|
11
11
|
import * as react from 'react';
|
|
12
12
|
import { Dispatch, SetStateAction, CSSProperties, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
|
|
13
13
|
export { lazy } from 'react';
|
|
14
|
-
import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps,
|
|
14
|
+
import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, FormInstance, InputProps, SelectProps, RadioProps, InputNumberProps, SwitchProps, DatePickerProps, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
|
|
15
15
|
import { BrowserRouterProps, RouteProps } from 'react-router-dom';
|
|
16
16
|
import { Dayjs } from 'dayjs';
|
|
17
17
|
import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
|
|
@@ -145,16 +145,24 @@ declare function useConfigContext(): Partial<ConfigProviderProps>;
|
|
|
145
145
|
|
|
146
146
|
interface AppProps {
|
|
147
147
|
children: React.ReactNode;
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
/**
|
|
149
|
+
* `false` to disable StyleProvider.
|
|
150
|
+
*
|
|
151
|
+
* @see https://ant.design/docs/react/compatible-style#styleprovider
|
|
152
|
+
*/
|
|
153
|
+
styleProviderProps?: StyleProviderProps | false;
|
|
154
|
+
/** @see https://ant.design/components/config-provider/#API */
|
|
151
155
|
configProviderProps?: ConfigProviderProps$1;
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
/**
|
|
157
|
+
* `false` to disable BrowserRouter.
|
|
158
|
+
*
|
|
159
|
+
* @see https://reactrouter.com/en/router-components/browser-router
|
|
160
|
+
*/
|
|
161
|
+
browserRouterProps?: BrowserRouterProps | false;
|
|
162
|
+
/** @see https://faasjs.com/doc/ant-design/#errorboundary */
|
|
155
163
|
errorBoundaryProps?: Omit<ErrorBoundaryProps, 'children'>;
|
|
156
|
-
/** https://faasjs.com/doc/ant-design/#configprovider */
|
|
157
|
-
faasConfigProviderProps?: Omit<ConfigProviderProps, 'children'
|
|
164
|
+
/** @see https://faasjs.com/doc/ant-design/#configprovider */
|
|
165
|
+
faasConfigProviderProps?: Omit<ConfigProviderProps, 'children'> | false;
|
|
158
166
|
}
|
|
159
167
|
interface useAppProps {
|
|
160
168
|
message: MessageInstance;
|
|
@@ -234,9 +242,20 @@ type ExtendFormTypeProps<T = any> = {
|
|
|
234
242
|
type ExtendTypes = {
|
|
235
243
|
[type: string]: ExtendFormTypeProps;
|
|
236
244
|
};
|
|
237
|
-
type
|
|
238
|
-
|
|
239
|
-
|
|
245
|
+
type InputTypeMap<T> = {
|
|
246
|
+
string: InputProps | SelectProps<T> | RadioProps;
|
|
247
|
+
'string[]': InputProps | SelectProps<T> | RadioProps;
|
|
248
|
+
number: InputNumberProps | SelectProps<T> | RadioProps;
|
|
249
|
+
'number[]': InputNumberProps | SelectProps<T> | RadioProps;
|
|
250
|
+
boolean: SwitchProps;
|
|
251
|
+
date: DatePickerProps;
|
|
252
|
+
time: DatePickerProps;
|
|
253
|
+
object: never;
|
|
254
|
+
'object[]': never;
|
|
255
|
+
};
|
|
256
|
+
interface FormItemProps<T = any> extends BaseItemProps, Omit<FormItemProps$1<T>, 'id' | 'children' | 'render'> {
|
|
257
|
+
type?: FaasItemType;
|
|
258
|
+
input?: InputTypeMap<T>[FaasItemType];
|
|
240
259
|
maxCount?: number;
|
|
241
260
|
object?: FormItemProps[];
|
|
242
261
|
disabled?: boolean;
|
|
@@ -254,6 +273,42 @@ interface FormItemProps<T = any> extends FaasItemProps, Omit<FormItemProps$1<T>,
|
|
|
254
273
|
/** trigger when any item's value changed */
|
|
255
274
|
if?: (values: Record<string, any>) => boolean;
|
|
256
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Extend custom form item types.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import type { ExtendFormItemProps, FormProps } from '@faasjs/ant-design'
|
|
282
|
+
*
|
|
283
|
+
* // define custom type
|
|
284
|
+
* interface ExtendTypes extends ExtendFormItemProps {
|
|
285
|
+
* type: 'password'
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* // extend form
|
|
289
|
+
* function ExtendForm(props: FormProps<any, ExtendTypes>) {
|
|
290
|
+
* return (
|
|
291
|
+
* <Form
|
|
292
|
+
* {...props}
|
|
293
|
+
* extendTypes={{ password: { children: <Input.Password /> } }}
|
|
294
|
+
* />
|
|
295
|
+
* )
|
|
296
|
+
* }
|
|
297
|
+
*
|
|
298
|
+
* // use custom type
|
|
299
|
+
* <ExtendForm
|
|
300
|
+
* items={[
|
|
301
|
+
* {
|
|
302
|
+
* id: 'test',
|
|
303
|
+
* type: 'password',
|
|
304
|
+
* },
|
|
305
|
+
* ]}
|
|
306
|
+
* />
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
interface ExtendFormItemProps extends Omit<FormItemProps, 'type'> {
|
|
310
|
+
type?: string;
|
|
311
|
+
}
|
|
257
312
|
/**
|
|
258
313
|
* FormItem
|
|
259
314
|
*
|
|
@@ -515,8 +570,8 @@ type FormSubmitProps = {
|
|
|
515
570
|
finally?: () => void;
|
|
516
571
|
};
|
|
517
572
|
};
|
|
518
|
-
interface FormProps<Values extends Record<string, any> = any, ExtendItemProps =
|
|
519
|
-
items?: (
|
|
573
|
+
interface FormProps<Values extends Record<string, any> = any, ExtendItemProps extends ExtendFormItemProps = ExtendFormItemProps> extends Omit<FormProps$1<Values>, 'onFinish' | 'children' | 'initialValues'> {
|
|
574
|
+
items?: ((ExtendItemProps extends ExtendFormItemProps ? ExtendItemProps | FormItemProps : FormItemProps) | JSX.Element)[];
|
|
520
575
|
/** Default: { text: 'Submit' }, set false to disable it */
|
|
521
576
|
submit?: false | FormSubmitProps;
|
|
522
577
|
onFinish?: (values: Values, submit?: (values: any) => Promise<any>) => Promise<any>;
|
|
@@ -524,7 +579,7 @@ interface FormProps<Values extends Record<string, any> = any, ExtendItemProps =
|
|
|
524
579
|
footer?: JSX.Element | JSX.Element[];
|
|
525
580
|
extendTypes?: ExtendTypes;
|
|
526
581
|
children?: ReactNode;
|
|
527
|
-
initialValues?: Values
|
|
582
|
+
initialValues?: Partial<Values>;
|
|
528
583
|
}
|
|
529
584
|
/**
|
|
530
585
|
* Form component with Ant Design & FaasJS
|
package/dist/index.js
CHANGED
|
@@ -159,7 +159,7 @@ function ConfigProvider(props) {
|
|
|
159
159
|
function useConfigContext() {
|
|
160
160
|
return react$1.useContext(ConfigContext);
|
|
161
161
|
}
|
|
162
|
-
var AppContext = react.
|
|
162
|
+
var AppContext = react.createSplittingContext({
|
|
163
163
|
message: null,
|
|
164
164
|
notification: null,
|
|
165
165
|
modalProps: {},
|
|
@@ -190,26 +190,50 @@ function App(props) {
|
|
|
190
190
|
}),
|
|
191
191
|
[props.styleProviderProps]
|
|
192
192
|
);
|
|
193
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
194
|
-
|
|
193
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
194
|
+
react.OptionalWrapper,
|
|
195
195
|
{
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
196
|
+
condition: props.styleProviderProps !== false,
|
|
197
|
+
Wrapper: cssinjs.StyleProvider,
|
|
198
|
+
wrapperProps: styleProviderProps,
|
|
199
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
200
|
+
react.OptionalWrapper,
|
|
201
|
+
{
|
|
202
|
+
condition: !!props.configProviderProps,
|
|
203
|
+
Wrapper: antd.ConfigProvider,
|
|
204
|
+
wrapperProps: props.configProviderProps,
|
|
205
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
206
|
+
AppContext.Provider,
|
|
207
|
+
{
|
|
208
|
+
value: {
|
|
209
|
+
message: messageApi,
|
|
210
|
+
notification: notificationApi,
|
|
211
|
+
drawerProps,
|
|
212
|
+
setDrawerProps,
|
|
213
|
+
modalProps,
|
|
214
|
+
setModalProps
|
|
215
|
+
},
|
|
216
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ConfigProvider, { ...props.faasConfigProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
217
|
+
react.OptionalWrapper,
|
|
218
|
+
{
|
|
219
|
+
condition: props.browserRouterProps !== false,
|
|
220
|
+
Wrapper: reactRouterDom.BrowserRouter,
|
|
221
|
+
wrapperProps: props.browserRouterProps,
|
|
222
|
+
children: [
|
|
223
|
+
messageContextHolder,
|
|
224
|
+
notificationContextHolder,
|
|
225
|
+
modal,
|
|
226
|
+
drawer,
|
|
227
|
+
props.browserRouterProps !== false ? /* @__PURE__ */ jsxRuntime.jsx(RoutesApp, { children: props.children }) : props.children
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
) }) })
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
)
|
|
211
235
|
}
|
|
212
|
-
)
|
|
236
|
+
);
|
|
213
237
|
}
|
|
214
238
|
var useApp = AppContext.use;
|
|
215
239
|
App.useApp = useApp;
|
|
@@ -449,6 +473,9 @@ function Description(props) {
|
|
|
449
473
|
);
|
|
450
474
|
}
|
|
451
475
|
Description.whyDidYouRender = true;
|
|
476
|
+
function isOptionsProps(item) {
|
|
477
|
+
return item && Array.isArray(item.options);
|
|
478
|
+
}
|
|
452
479
|
function processProps(propsCopy, config) {
|
|
453
480
|
if (!propsCopy.title) propsCopy.title = lodashEs.upperFirst(propsCopy.id);
|
|
454
481
|
if (!propsCopy.label && propsCopy.label !== false)
|
|
@@ -474,10 +501,8 @@ function processProps(propsCopy, config) {
|
|
|
474
501
|
});
|
|
475
502
|
}
|
|
476
503
|
if (!propsCopy.input) propsCopy.input = {};
|
|
477
|
-
if (propsCopy
|
|
478
|
-
propsCopy.input.options = transferOptions(
|
|
479
|
-
propsCopy.options
|
|
480
|
-
);
|
|
504
|
+
if (isOptionsProps(propsCopy))
|
|
505
|
+
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
481
506
|
switch (propsCopy.type) {
|
|
482
507
|
case "boolean":
|
|
483
508
|
propsCopy.valuePropName = "checked";
|
|
@@ -485,8 +510,7 @@ function processProps(propsCopy, config) {
|
|
|
485
510
|
case "object":
|
|
486
511
|
if (!Array.isArray(propsCopy.name)) propsCopy.name = [propsCopy.name];
|
|
487
512
|
for (const sub of propsCopy.object) {
|
|
488
|
-
if (!sub.name)
|
|
489
|
-
sub.name = propsCopy.name.concat(sub.id);
|
|
513
|
+
if (!sub.name) sub.name = propsCopy.name.concat(sub.id);
|
|
490
514
|
processProps(sub, config);
|
|
491
515
|
}
|
|
492
516
|
break;
|
|
@@ -537,11 +561,11 @@ function FormItem(props) {
|
|
|
537
561
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.render(null, null, 0, "form") });
|
|
538
562
|
switch (computedProps.type) {
|
|
539
563
|
case "string":
|
|
540
|
-
if (computedProps
|
|
564
|
+
if (isOptionsProps(computedProps))
|
|
541
565
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.options.length > 10 ? /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Group, { ...computedProps.input }) });
|
|
542
566
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { ...computedProps.input }) });
|
|
543
567
|
case "string[]":
|
|
544
|
-
if (computedProps
|
|
568
|
+
if (isOptionsProps(computedProps))
|
|
545
569
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { mode: "multiple", ...computedProps.input }) });
|
|
546
570
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
547
571
|
antd.Form.List,
|
|
@@ -733,6 +757,9 @@ function FormItem(props) {
|
|
|
733
757
|
}
|
|
734
758
|
FormItem.whyDidYouRender = true;
|
|
735
759
|
FormItem.useStatus = antd.Form.Item.useStatus;
|
|
760
|
+
function isFormItemProps(item) {
|
|
761
|
+
return item.id !== void 0;
|
|
762
|
+
}
|
|
736
763
|
function Form(props) {
|
|
737
764
|
var _a, _b;
|
|
738
765
|
const [loading, setLoading] = react$1.useState(false);
|
|
@@ -752,14 +779,17 @@ function Form(props) {
|
|
|
752
779
|
if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
|
|
753
780
|
for (const key in propsCopy.initialValues) {
|
|
754
781
|
propsCopy.initialValues[key] = transferValue(
|
|
755
|
-
(_b2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _b2.type,
|
|
782
|
+
(_b2 = propsCopy.items.find((item2) => isFormItemProps(item2) && item2.id === key)) == null ? void 0 : _b2.type,
|
|
756
783
|
propsCopy.initialValues[key]
|
|
757
784
|
);
|
|
758
|
-
const item = propsCopy.items.find(
|
|
785
|
+
const item = propsCopy.items.find(
|
|
786
|
+
(item2) => isFormItemProps(item2) && item2.id === key
|
|
787
|
+
);
|
|
759
788
|
if (item == null ? void 0 : item.if) item.hidden = !item.if(propsCopy.initialValues);
|
|
760
789
|
}
|
|
761
790
|
for (const item of propsCopy.items) {
|
|
762
|
-
if (item
|
|
791
|
+
if (isFormItemProps(item) && item.if)
|
|
792
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
763
793
|
}
|
|
764
794
|
setInitialValues(propsCopy.initialValues);
|
|
765
795
|
delete propsCopy.initialValues;
|
|
@@ -824,7 +854,9 @@ function Form(props) {
|
|
|
824
854
|
}
|
|
825
855
|
if (!props.items) return;
|
|
826
856
|
for (const key in changedValues) {
|
|
827
|
-
const item = computedProps.items.find(
|
|
857
|
+
const item = computedProps.items.find(
|
|
858
|
+
(i) => isFormItemProps(i) && i.id === key
|
|
859
|
+
);
|
|
828
860
|
if (item == null ? void 0 : item.onValueChange)
|
|
829
861
|
item.onValueChange(changedValues[key], allValues, form);
|
|
830
862
|
}
|
|
@@ -840,16 +872,11 @@ function Form(props) {
|
|
|
840
872
|
if (!computedProps) return null;
|
|
841
873
|
return /* @__PURE__ */ jsxRuntime.jsxs(antd.Form, { ...computedProps, onValuesChange, children: [
|
|
842
874
|
computedProps.beforeItems,
|
|
843
|
-
(_a = computedProps.items) == null ? void 0 : _a.map(
|
|
844
|
-
|
|
845
|
-
FormItem,
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
extendTypes
|
|
849
|
-
},
|
|
850
|
-
item.id
|
|
851
|
-
)
|
|
852
|
-
),
|
|
875
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => {
|
|
876
|
+
if (isFormItemProps(item))
|
|
877
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormItem, { ...item, extendTypes }, item.id);
|
|
878
|
+
return item;
|
|
879
|
+
}),
|
|
853
880
|
computedProps.children,
|
|
854
881
|
computedProps.submit !== false && /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { htmlType: "submit", type: "primary", loading, children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.theme.Form.submit.text }),
|
|
855
882
|
computedProps.footer
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSplittingContext, ErrorBoundary as ErrorBoundary$1, FaasReactClient, OptionalWrapper, FaasDataWrapper as FaasDataWrapper$1, faas } from '@faasjs/react';
|
|
2
2
|
export { faas, useFaas } from '@faasjs/react';
|
|
3
3
|
import { Form as Form$1, Modal as Modal$1, Drawer as Drawer$1, message, notification, ConfigProvider as ConfigProvider$1, Typography, Spin, Descriptions, Input, Button, Row, Col, DatePicker, Switch, Select, InputNumber, Radio, Result, Skeleton, Table as Table$1, Tabs as Tabs$1, Alert, Space } from 'antd';
|
|
4
4
|
import { legacyLogicalPropertiesTransformer, StyleProvider } from '@ant-design/cssinjs';
|
|
5
|
-
import { createContext, useState, useCallback, useEffect, useContext, useMemo, cloneElement,
|
|
5
|
+
import { createContext, useState, useCallback, useEffect, useContext, useMemo, cloneElement, Suspense } from 'react';
|
|
6
6
|
export { lazy } from 'react';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import { BrowserRouter, useNavigate, Link as Link$1, Routes as Routes$1, Route, useLocation } from 'react-router-dom';
|
|
@@ -155,7 +155,7 @@ function ConfigProvider(props) {
|
|
|
155
155
|
function useConfigContext() {
|
|
156
156
|
return useContext(ConfigContext);
|
|
157
157
|
}
|
|
158
|
-
var AppContext =
|
|
158
|
+
var AppContext = createSplittingContext({
|
|
159
159
|
message: null,
|
|
160
160
|
notification: null,
|
|
161
161
|
modalProps: {},
|
|
@@ -186,26 +186,50 @@ function App(props) {
|
|
|
186
186
|
}),
|
|
187
187
|
[props.styleProviderProps]
|
|
188
188
|
);
|
|
189
|
-
return /* @__PURE__ */ jsx(
|
|
190
|
-
|
|
189
|
+
return /* @__PURE__ */ jsx(
|
|
190
|
+
OptionalWrapper,
|
|
191
191
|
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
192
|
+
condition: props.styleProviderProps !== false,
|
|
193
|
+
Wrapper: StyleProvider,
|
|
194
|
+
wrapperProps: styleProviderProps,
|
|
195
|
+
children: /* @__PURE__ */ jsx(
|
|
196
|
+
OptionalWrapper,
|
|
197
|
+
{
|
|
198
|
+
condition: !!props.configProviderProps,
|
|
199
|
+
Wrapper: ConfigProvider$1,
|
|
200
|
+
wrapperProps: props.configProviderProps,
|
|
201
|
+
children: /* @__PURE__ */ jsx(
|
|
202
|
+
AppContext.Provider,
|
|
203
|
+
{
|
|
204
|
+
value: {
|
|
205
|
+
message: messageApi,
|
|
206
|
+
notification: notificationApi,
|
|
207
|
+
drawerProps,
|
|
208
|
+
setDrawerProps,
|
|
209
|
+
modalProps,
|
|
210
|
+
setModalProps
|
|
211
|
+
},
|
|
212
|
+
children: /* @__PURE__ */ jsx(ConfigProvider, { ...props.faasConfigProviderProps, children: /* @__PURE__ */ jsx(ErrorBoundary, { ...props.errorBoundaryProps, children: /* @__PURE__ */ jsxs(
|
|
213
|
+
OptionalWrapper,
|
|
214
|
+
{
|
|
215
|
+
condition: props.browserRouterProps !== false,
|
|
216
|
+
Wrapper: BrowserRouter,
|
|
217
|
+
wrapperProps: props.browserRouterProps,
|
|
218
|
+
children: [
|
|
219
|
+
messageContextHolder,
|
|
220
|
+
notificationContextHolder,
|
|
221
|
+
modal,
|
|
222
|
+
drawer,
|
|
223
|
+
props.browserRouterProps !== false ? /* @__PURE__ */ jsx(RoutesApp, { children: props.children }) : props.children
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
) }) })
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
)
|
|
207
231
|
}
|
|
208
|
-
)
|
|
232
|
+
);
|
|
209
233
|
}
|
|
210
234
|
var useApp = AppContext.use;
|
|
211
235
|
App.useApp = useApp;
|
|
@@ -445,6 +469,9 @@ function Description(props) {
|
|
|
445
469
|
);
|
|
446
470
|
}
|
|
447
471
|
Description.whyDidYouRender = true;
|
|
472
|
+
function isOptionsProps(item) {
|
|
473
|
+
return item && Array.isArray(item.options);
|
|
474
|
+
}
|
|
448
475
|
function processProps(propsCopy, config) {
|
|
449
476
|
if (!propsCopy.title) propsCopy.title = upperFirst(propsCopy.id);
|
|
450
477
|
if (!propsCopy.label && propsCopy.label !== false)
|
|
@@ -470,10 +497,8 @@ function processProps(propsCopy, config) {
|
|
|
470
497
|
});
|
|
471
498
|
}
|
|
472
499
|
if (!propsCopy.input) propsCopy.input = {};
|
|
473
|
-
if (propsCopy
|
|
474
|
-
propsCopy.input.options = transferOptions(
|
|
475
|
-
propsCopy.options
|
|
476
|
-
);
|
|
500
|
+
if (isOptionsProps(propsCopy))
|
|
501
|
+
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
477
502
|
switch (propsCopy.type) {
|
|
478
503
|
case "boolean":
|
|
479
504
|
propsCopy.valuePropName = "checked";
|
|
@@ -481,8 +506,7 @@ function processProps(propsCopy, config) {
|
|
|
481
506
|
case "object":
|
|
482
507
|
if (!Array.isArray(propsCopy.name)) propsCopy.name = [propsCopy.name];
|
|
483
508
|
for (const sub of propsCopy.object) {
|
|
484
|
-
if (!sub.name)
|
|
485
|
-
sub.name = propsCopy.name.concat(sub.id);
|
|
509
|
+
if (!sub.name) sub.name = propsCopy.name.concat(sub.id);
|
|
486
510
|
processProps(sub, config);
|
|
487
511
|
}
|
|
488
512
|
break;
|
|
@@ -533,11 +557,11 @@ function FormItem(props) {
|
|
|
533
557
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.render(null, null, 0, "form") });
|
|
534
558
|
switch (computedProps.type) {
|
|
535
559
|
case "string":
|
|
536
|
-
if (computedProps
|
|
560
|
+
if (isOptionsProps(computedProps))
|
|
537
561
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.options.length > 10 ? /* @__PURE__ */ jsx(Select, { ...computedProps.input }) : /* @__PURE__ */ jsx(Radio.Group, { ...computedProps.input }) });
|
|
538
562
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(Input, { ...computedProps.input }) });
|
|
539
563
|
case "string[]":
|
|
540
|
-
if (computedProps
|
|
564
|
+
if (isOptionsProps(computedProps))
|
|
541
565
|
return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: /* @__PURE__ */ jsx(Select, { mode: "multiple", ...computedProps.input }) });
|
|
542
566
|
return /* @__PURE__ */ jsx(
|
|
543
567
|
Form$1.List,
|
|
@@ -729,6 +753,9 @@ function FormItem(props) {
|
|
|
729
753
|
}
|
|
730
754
|
FormItem.whyDidYouRender = true;
|
|
731
755
|
FormItem.useStatus = Form$1.Item.useStatus;
|
|
756
|
+
function isFormItemProps(item) {
|
|
757
|
+
return item.id !== void 0;
|
|
758
|
+
}
|
|
732
759
|
function Form(props) {
|
|
733
760
|
var _a, _b;
|
|
734
761
|
const [loading, setLoading] = useState(false);
|
|
@@ -748,14 +775,17 @@ function Form(props) {
|
|
|
748
775
|
if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
|
|
749
776
|
for (const key in propsCopy.initialValues) {
|
|
750
777
|
propsCopy.initialValues[key] = transferValue(
|
|
751
|
-
(_b2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _b2.type,
|
|
778
|
+
(_b2 = propsCopy.items.find((item2) => isFormItemProps(item2) && item2.id === key)) == null ? void 0 : _b2.type,
|
|
752
779
|
propsCopy.initialValues[key]
|
|
753
780
|
);
|
|
754
|
-
const item = propsCopy.items.find(
|
|
781
|
+
const item = propsCopy.items.find(
|
|
782
|
+
(item2) => isFormItemProps(item2) && item2.id === key
|
|
783
|
+
);
|
|
755
784
|
if (item == null ? void 0 : item.if) item.hidden = !item.if(propsCopy.initialValues);
|
|
756
785
|
}
|
|
757
786
|
for (const item of propsCopy.items) {
|
|
758
|
-
if (item
|
|
787
|
+
if (isFormItemProps(item) && item.if)
|
|
788
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
759
789
|
}
|
|
760
790
|
setInitialValues(propsCopy.initialValues);
|
|
761
791
|
delete propsCopy.initialValues;
|
|
@@ -820,7 +850,9 @@ function Form(props) {
|
|
|
820
850
|
}
|
|
821
851
|
if (!props.items) return;
|
|
822
852
|
for (const key in changedValues) {
|
|
823
|
-
const item = computedProps.items.find(
|
|
853
|
+
const item = computedProps.items.find(
|
|
854
|
+
(i) => isFormItemProps(i) && i.id === key
|
|
855
|
+
);
|
|
824
856
|
if (item == null ? void 0 : item.onValueChange)
|
|
825
857
|
item.onValueChange(changedValues[key], allValues, form);
|
|
826
858
|
}
|
|
@@ -836,16 +868,11 @@ function Form(props) {
|
|
|
836
868
|
if (!computedProps) return null;
|
|
837
869
|
return /* @__PURE__ */ jsxs(Form$1, { ...computedProps, onValuesChange, children: [
|
|
838
870
|
computedProps.beforeItems,
|
|
839
|
-
(_a = computedProps.items) == null ? void 0 : _a.map(
|
|
840
|
-
|
|
841
|
-
FormItem,
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
extendTypes
|
|
845
|
-
},
|
|
846
|
-
item.id
|
|
847
|
-
)
|
|
848
|
-
),
|
|
871
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => {
|
|
872
|
+
if (isFormItemProps(item))
|
|
873
|
+
return /* @__PURE__ */ jsx(FormItem, { ...item, extendTypes }, item.id);
|
|
874
|
+
return item;
|
|
875
|
+
}),
|
|
849
876
|
computedProps.children,
|
|
850
877
|
computedProps.submit !== false && /* @__PURE__ */ jsx(Button, { htmlType: "submit", type: "primary", loading, children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.theme.Form.submit.text }),
|
|
851
878
|
computedProps.footer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"lodash-es": "*"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@faasjs/react": "2.
|
|
41
|
+
"@faasjs/react": "2.7.0",
|
|
42
42
|
"antd": "*",
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-dom": "*",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@testing-library/react": "*",
|
|
51
51
|
"@testing-library/user-event": "*",
|
|
52
52
|
"@welldone-software/why-did-you-render": "*",
|
|
53
|
-
"@faasjs/react": "2.
|
|
53
|
+
"@faasjs/react": "2.7.0",
|
|
54
54
|
"antd": "*",
|
|
55
55
|
"react": "*",
|
|
56
56
|
"react-dom": "*",
|