@faasjs/ant-design 0.0.3-beta.9 → 0.0.3-beta.91

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.
@@ -0,0 +1,557 @@
1
+ import { FaasDataInjection as FaasDataInjection$1, FaasDataWrapperProps as FaasDataWrapperProps$1 } from '@faasjs/react';
2
+ export { faas, useFaas } from '@faasjs/react';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ConfigProviderProps as ConfigProviderProps$1 } from 'antd/es/config-provider';
5
+ import { StyleProviderProps } from '@ant-design/cssinjs/lib/StyleContext';
6
+ import { MessageInstance } from 'antd/es/message/interface';
7
+ import { NotificationInstance } from 'antd/es/notification/interface';
8
+ import { ModalProps as ModalProps$1, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, DatePickerProps, TimePickerProps, FormInstance, DescriptionsProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, FormProps as FormProps$1, ButtonProps, TabsProps as TabsProps$1 } from 'antd';
9
+ export { Drawer, Modal } from 'antd';
10
+ import { BrowserRouterProps, RouteProps } from 'react-router-dom';
11
+ import * as react from 'react';
12
+ import { CSSProperties, ReactNode, ReactElement, Component, LazyExoticComponent, ComponentType } from 'react';
13
+ export { lazy } from 'react';
14
+ import { Dayjs } from 'dayjs';
15
+ import { RuleObject } from 'rc-field-form/lib/interface';
16
+ import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface';
17
+ import * as antd_es_form_context from 'antd/es/form/context';
18
+ import * as antd_es_form from 'antd/es/form';
19
+ import * as rc_field_form_es_useWatch from 'rc-field-form/es/useWatch';
20
+ import * as antd_es_form_hooks_useFormInstance from 'antd/es/form/hooks/useFormInstance';
21
+ import * as antd_es_form_Form from 'antd/es/form/Form';
22
+ import { Tab } from 'rc-tabs/es/interface';
23
+
24
+ interface ModalProps extends ModalProps$1 {
25
+ children?: JSX.Element | JSX.Element[] | string;
26
+ }
27
+ type setModalProps = (changes: Partial<ModalProps>) => void;
28
+ /**
29
+ * Hook style modal.
30
+ * @param init initial props
31
+ *
32
+ * ```ts
33
+ * function Example() {
34
+ * const { modal, setModalProps } = useModal()
35
+ *
36
+ * return <>
37
+ * <Button onClick={() => setModalProps({ open: true })}>Open Modal</Button>
38
+ * {modal}</>
39
+ * }
40
+ * ```
41
+ */
42
+ declare function useModal(init?: ModalProps): {
43
+ modal: react_jsx_runtime.JSX.Element;
44
+ modalProps: ModalProps;
45
+ setModalProps(changes: Partial<ModalProps>): void;
46
+ };
47
+
48
+ interface DrawerProps extends DrawerProps$1 {
49
+ children?: JSX.Element | JSX.Element[];
50
+ }
51
+ type setDrawerProps = (changes: Partial<DrawerProps>) => void;
52
+ /**
53
+ * Hook style drawer.
54
+ *
55
+ * @param init initial props
56
+ *
57
+ * ```ts
58
+ * function Example() {
59
+ * const { drawer, setDrawerProps } = useDrawer()
60
+ *
61
+ * return <>
62
+ * <Button onClick={ () => setDrawerProps(prev => ({ open: !prev.open})) }>
63
+ * Toggle
64
+ * </Button>
65
+ * {drawer}
66
+ * </>
67
+ * }
68
+ * ```
69
+ */
70
+ declare function useDrawer(init?: DrawerProps): {
71
+ drawer: react_jsx_runtime.JSX.Element;
72
+ drawerProps: DrawerProps;
73
+ setDrawerProps(changes: Partial<DrawerProps>): void;
74
+ };
75
+
76
+ interface AppProps {
77
+ children: React.ReactNode;
78
+ styleProviderProps?: StyleProviderProps;
79
+ configProviderProps?: ConfigProviderProps$1;
80
+ browserRouterProps?: BrowserRouterProps;
81
+ }
82
+ interface useAppProps {
83
+ message: MessageInstance;
84
+ notification: NotificationInstance;
85
+ setModalProps: (changes: Partial<ModalProps>) => void;
86
+ setDrawerProps: (changes: Partial<DrawerProps>) => void;
87
+ }
88
+ declare function App(props: AppProps): react_jsx_runtime.JSX.Element;
89
+ declare namespace App {
90
+ var useApp: typeof useApp;
91
+ }
92
+ declare function useApp(): useAppProps;
93
+
94
+ interface BlankProps {
95
+ value?: any;
96
+ text?: string;
97
+ }
98
+ /**
99
+ * Blank component.
100
+ *
101
+ * If value is undefined or null, return text, otherwise return value.
102
+ *
103
+ * @param options {object}
104
+ * @param options.value {any}
105
+ * @param options.text {string} Default is 'Empty'
106
+ * @returns {JSX.Element}
107
+ *
108
+ * ```ts
109
+ * <Blank value={undefined} text="Empty" />
110
+ * ```
111
+ */
112
+ declare function Blank(options?: BlankProps): JSX.Element;
113
+
114
+ interface ConfigProviderProps {
115
+ lang?: string;
116
+ common?: {
117
+ blank?: string;
118
+ all?: string;
119
+ submit?: string;
120
+ pageNotFound?: string;
121
+ add?: string;
122
+ delete?: string;
123
+ required?: string;
124
+ search?: string;
125
+ reset?: string;
126
+ };
127
+ Blank?: {
128
+ text?: string;
129
+ };
130
+ Form?: {
131
+ submit?: {
132
+ text?: string;
133
+ };
134
+ };
135
+ Title?: {
136
+ /** ' - ' as default */
137
+ separator?: string;
138
+ suffix?: string;
139
+ };
140
+ Link?: {
141
+ /** '_blank' as default */
142
+ target?: string;
143
+ style?: CSSProperties;
144
+ };
145
+ }
146
+ declare const ConfigContext: react.Context<ConfigProviderProps>;
147
+ /**
148
+ * Config for @faasjs/ant-design components.
149
+ *
150
+ * ```ts
151
+ * <ConfigProvider config={{
152
+ * common: {
153
+ * blank: 'Empty',
154
+ * },
155
+ * }}>
156
+ * <Blank />
157
+ * </ConfigProvider>
158
+ * ```
159
+ */
160
+ declare function ConfigProvider({ config, children }: {
161
+ config: ConfigProviderProps;
162
+ children: React.ReactNode;
163
+ }): react_jsx_runtime.JSX.Element;
164
+ declare function useConfigContext(): ConfigProviderProps;
165
+
166
+ type ExtendFormTypeProps<T = any> = {
167
+ children?: UnionFaasItemElement<T>;
168
+ };
169
+ type ExtendTypes = {
170
+ [type: string]: ExtendFormTypeProps;
171
+ };
172
+ type ExtendFormItemProps = BaseItemProps & FormItemProps$1;
173
+ interface FormItemProps<T = any> extends FaasItemProps, Omit<FormItemProps$1<T>, 'id' | 'children' | 'render'> {
174
+ input?: InputProps | InputNumberProps | SwitchProps | SelectProps<T> | DatePickerProps | TimePickerProps;
175
+ maxCount?: number;
176
+ object?: FormItemProps[];
177
+ disabled?: boolean;
178
+ required?: boolean;
179
+ col?: number;
180
+ children?: UnionFaasItemElement<T>;
181
+ formChildren?: UnionFaasItemElement<T>;
182
+ render?: UnionFaasItemRender<T>;
183
+ formRender?: UnionFaasItemRender<T>;
184
+ rules?: RuleObject[];
185
+ label?: string | false;
186
+ extendTypes?: ExtendTypes;
187
+ /** trigger when current item's value changed */
188
+ onValueChange?: (value: T, values: any, form: FormInstance) => void;
189
+ /** trigger when any item's value changed */
190
+ if?: (values: Record<string, any>) => boolean;
191
+ }
192
+ /**
193
+ * FormItem, can be used without Form.
194
+ *
195
+ * ```ts
196
+ * // use inline type
197
+ * <FormItem type='string' id='name' />
198
+ *
199
+ * // use custom type
200
+ * <FormItem id='password'>
201
+ * <Input.Password />
202
+ * </>
203
+ * ```
204
+ */
205
+ declare function FormItem<T = any>(props: FormItemProps<T>): react_jsx_runtime.JSX.Element;
206
+ declare namespace FormItem {
207
+ var useStatus: () => {
208
+ status?: "" | "success" | "error" | "warning" | "validating";
209
+ errors: react.ReactNode[];
210
+ warnings: react.ReactNode[];
211
+ };
212
+ }
213
+
214
+ type LoadingProps = {
215
+ style?: React.CSSProperties;
216
+ size?: 'small' | 'default' | 'large';
217
+ loading?: boolean;
218
+ children?: React.ReactNode;
219
+ };
220
+ /**
221
+ * Loading component based on Spin
222
+ *
223
+ * ```tsx
224
+ * <Loading /> // display loading
225
+ *
226
+ * <Loading loading={ !remoteData }>
227
+ * <div>{remoteData}</div>
228
+ * </Loading>
229
+ * ```
230
+ */
231
+ declare function Loading(props: LoadingProps): react_jsx_runtime.JSX.Element;
232
+
233
+ type FaasDataInjection<T = any> = Partial<FaasDataInjection$1<T>>;
234
+ interface FaasDataWrapperProps<T = any> extends FaasDataWrapperProps$1<T> {
235
+ loadingProps?: LoadingProps;
236
+ loading?: JSX.Element;
237
+ }
238
+ /**
239
+ * FaasDataWrapper component with Loading
240
+ *
241
+ * ```tsx
242
+ * function MyComponent (props: FaasDataInjection) {
243
+ * return <div>{ props.data }</div>
244
+ * }
245
+ *
246
+ * function MyPage () {
247
+ * return <FaasDataWrapper action="test" params={{ a: 1 }}>
248
+ * <MyComponent />
249
+ * </FaasDataWrapper>
250
+ * }
251
+ * ```
252
+ */
253
+ declare function FaasDataWrapper<T = any>(props: FaasDataWrapperProps<T>): JSX.Element;
254
+
255
+ interface ExtendDescriptionTypeProps<T = any> {
256
+ children?: UnionFaasItemElement<T>;
257
+ render?: UnionFaasItemRender<T>;
258
+ }
259
+ type ExtendDescriptionItemProps = BaseItemProps;
260
+ interface DescriptionItemProps<T = any> extends FaasItemProps {
261
+ children?: UnionFaasItemElement<T>;
262
+ descriptionChildren?: UnionFaasItemElement<T>;
263
+ render?: UnionFaasItemRender<T>;
264
+ descriptionRender?: UnionFaasItemRender<T>;
265
+ if?: (values: Record<string, any>) => boolean;
266
+ object?: DescriptionItemProps<T>[];
267
+ }
268
+ interface DescriptionProps<T = any, ExtendItemProps = any> extends Omit<DescriptionsProps, 'items'> {
269
+ renderTitle?(values: T): ReactNode;
270
+ items: ((DescriptionItemProps | ExtendItemProps))[];
271
+ extendTypes?: {
272
+ [key: string]: ExtendDescriptionTypeProps;
273
+ };
274
+ dataSource?: T;
275
+ faasData?: FaasDataWrapperProps<T>;
276
+ }
277
+ interface DescriptionItemContentProps<T = any> {
278
+ item: DescriptionItemProps;
279
+ value: T;
280
+ values?: any;
281
+ extendTypes?: {
282
+ [key: string]: ExtendDescriptionTypeProps;
283
+ };
284
+ }
285
+ /**
286
+ * Description component.
287
+ */
288
+ declare function Description<T = any>(props: DescriptionProps<T>): react_jsx_runtime.JSX.Element;
289
+
290
+ interface TableItemProps<T = any> extends FaasItemProps, Omit<TableColumnProps<T>, 'title' | 'children' | 'render'> {
291
+ optionsType?: 'auto';
292
+ children?: UnionFaasItemElement<T>;
293
+ tableChildren?: UnionFaasItemElement<T>;
294
+ render?: UnionFaasItemRender<T>;
295
+ tableRender?: UnionFaasItemRender<T>;
296
+ object?: TableItemProps<T>[];
297
+ }
298
+ type ExtendTableTypeProps<T = any> = {
299
+ children?: JSX.Element;
300
+ render?: UnionFaasItemRender<T>;
301
+ };
302
+ type ExtendTableItemProps<T = any> = BaseItemProps & Omit<TableColumnProps<T>, 'children'>;
303
+ type TableProps<T = any, ExtendTypes = any> = {
304
+ items: (TableItemProps | (ExtendTypes & ExtendTableItemProps))[];
305
+ extendTypes?: {
306
+ [key: string]: ExtendTableTypeProps;
307
+ };
308
+ faasData?: FaasDataWrapperProps<T>;
309
+ onChange?: (pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<T> | SorterResult<T>[], extra: TableCurrentDataSource<T>) => {
310
+ pagination: TablePaginationConfig;
311
+ filters: Record<string, FilterValue | null>;
312
+ sorter: SorterResult<T> | SorterResult<T>[];
313
+ extra: TableCurrentDataSource<T>;
314
+ };
315
+ } & TableProps$1<T>;
316
+ /**
317
+ * Table component with Ant Design & FaasJS
318
+ *
319
+ * @ref https://ant.design/components/table/
320
+ */
321
+ declare function Table<T extends Record<string, any>, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): react_jsx_runtime.JSX.Element;
322
+
323
+ type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean' | 'date' | 'time' | 'object' | 'object[]';
324
+ /** FaasItemType's value type */
325
+ type FaasItemTypeValue = {
326
+ string: string;
327
+ 'string[]': string[];
328
+ number: number;
329
+ 'number[]': number[];
330
+ boolean: boolean;
331
+ date: Dayjs;
332
+ time: Dayjs;
333
+ object: any;
334
+ 'object[]': any[];
335
+ };
336
+ type BaseOption = string | number | {
337
+ label: string;
338
+ value?: any;
339
+ };
340
+ interface BaseItemProps {
341
+ id: string;
342
+ title?: string;
343
+ options?: BaseOption[];
344
+ }
345
+ interface FaasItemProps extends BaseItemProps {
346
+ /**
347
+ * Support string, string[], number, number[], boolean, date, time, object, object[]
348
+ * @default 'string'
349
+ */
350
+ type?: FaasItemType;
351
+ }
352
+ /**
353
+ * convert options to { label, value }[]
354
+ */
355
+ declare function transferOptions(options: BaseOption[]): {
356
+ label: string;
357
+ value?: string | number;
358
+ }[];
359
+ declare function transferValue(type: FaasItemType, value: any): any;
360
+ type UnionScene = 'form' | 'description' | 'table';
361
+ type UnionFaasItemInjection<Value = any, Values = any> = {
362
+ scene?: UnionScene;
363
+ value?: Value;
364
+ values?: Values;
365
+ index?: number;
366
+ };
367
+ type UnionFaasItemRender<Value = any, Values = any> = (value: Value, values: Values, index: number, scene: UnionScene) => React.ReactNode;
368
+ type UnionFaasItemElement<Value = any, Values = any> = ReactElement<UnionFaasItemInjection<Value, Values>> | null;
369
+ interface UnionFaasItemProps<Value = any, Values = any> extends FormItemProps, DescriptionItemProps, TableItemProps {
370
+ children?: UnionFaasItemElement<UnionFaasItemProps<Value, Values>> | null;
371
+ render?: UnionFaasItemRender;
372
+ object?: UnionFaasItemProps<Value, Values>[];
373
+ }
374
+
375
+ interface ErrorBoundaryProps {
376
+ message?: ReactNode;
377
+ description?: ReactNode;
378
+ children?: ReactNode;
379
+ onError?: (error: Error | null, info: any) => ReactNode;
380
+ }
381
+ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
382
+ error?: Error | null;
383
+ info?: {
384
+ componentStack?: string;
385
+ };
386
+ }> {
387
+ constructor(props: ErrorBoundaryProps);
388
+ componentDidCatch(error: Error | null, info: any): void;
389
+ render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
390
+ }
391
+
392
+ type FormSubmitProps = {
393
+ /** Default: Submit */
394
+ text?: string;
395
+ /**
396
+ * Submit to FaasJS server.
397
+ *
398
+ * If use onFinish, you should call submit manually.
399
+ * ```ts
400
+ * {
401
+ * submit: {
402
+ * to: {
403
+ * action: 'action_name'
404
+ * }
405
+ * },
406
+ * onFinish: (values, submit) => {
407
+ * // do something before submit
408
+ *
409
+ * // submit
410
+ * await submit({
411
+ * ...values,
412
+ * extraProps: 'some extra props'
413
+ * })
414
+ *
415
+ * // do something after submit
416
+ * }
417
+ * }
418
+ * ```
419
+ */
420
+ to?: {
421
+ action: string;
422
+ /** params will overwrite form values before submit */
423
+ params?: Record<string, any>;
424
+ then?: (result: any) => void;
425
+ catch?: (error: any) => void;
426
+ finally?: () => void;
427
+ };
428
+ };
429
+ interface FormProps<Values extends Record<string, any> = any, ExtendItemProps = any> extends Omit<FormProps$1<Values>, 'onFinish' | 'children' | 'initialValues'> {
430
+ items?: (FormItemProps | ExtendItemProps | JSX.Element)[];
431
+ /** Default: { text: 'Submit' }, set false to disable it */
432
+ submit?: false | FormSubmitProps;
433
+ onFinish?: (values: Values, submit?: (values: any) => Promise<any>) => Promise<any>;
434
+ beforeItems?: JSX.Element | JSX.Element[];
435
+ footer?: JSX.Element | JSX.Element[];
436
+ extendTypes?: ExtendTypes;
437
+ children?: ReactNode;
438
+ initialValues?: Values;
439
+ }
440
+ /**
441
+ * Form component with Ant Design & FaasJS
442
+ *
443
+ * @ref https://ant.design/components/form/
444
+ */
445
+ declare function Form<Values = any>(props: FormProps<Values>): react_jsx_runtime.JSX.Element;
446
+ declare namespace Form {
447
+ var useForm: typeof antd_es_form_Form.useForm;
448
+ var useFormInstance: typeof antd_es_form_hooks_useFormInstance.default;
449
+ var useWatch: typeof rc_field_form_es_useWatch.default;
450
+ var Item: typeof FormItem;
451
+ var List: react.FC<antd_es_form.FormListProps>;
452
+ var ErrorList: react.FC<antd_es_form.ErrorListProps>;
453
+ var Provider: react.FC<antd_es_form_context.FormProviderProps>;
454
+ }
455
+
456
+ interface LinkProps {
457
+ href: string;
458
+ target?: string;
459
+ text?: string | number;
460
+ children?: ReactNode;
461
+ style?: CSSProperties;
462
+ button?: ButtonProps;
463
+ block?: boolean;
464
+ }
465
+ /**
466
+ * Link component with button.
467
+ *
468
+ * ```ts
469
+ * // pure link
470
+ * <Link href="/">Home</Link>
471
+ *
472
+ * // link with button
473
+ * <Link href="/" button={{ type:'primary' }}>Home</Link>
474
+ * ```
475
+ */
476
+ declare function Link(props: LinkProps): react_jsx_runtime.JSX.Element;
477
+
478
+ declare function PageNotFound(): react_jsx_runtime.JSX.Element;
479
+ interface RoutesProps {
480
+ routes: (RouteProps & {
481
+ page?: LazyExoticComponent<ComponentType<any>>;
482
+ })[];
483
+ fallback?: JSX.Element;
484
+ notFound?: JSX.Element;
485
+ }
486
+ /**
487
+ * Routes with lazy loading and 404 page.
488
+ *
489
+ * ```tsx
490
+ * import { Routes, lazy } from '@faasjs/ant-design'
491
+ * import { BrowserRouter } from 'react-router-dom'
492
+ *
493
+ * export function App () {
494
+ * return <BrowserRouter>
495
+ * <Routes routes={[
496
+ * {
497
+ * path: '/',
498
+ * page: lazy(() => import('./pages/home'))
499
+ * }
500
+ * ]} />
501
+ * </BrowserRouter>
502
+ * }
503
+ * ```
504
+ */
505
+ declare function Routes(props: RoutesProps): react_jsx_runtime.JSX.Element;
506
+
507
+ interface TabProps extends Partial<Tab> {
508
+ id: string;
509
+ title?: React.ReactNode;
510
+ children: React.ReactNode;
511
+ }
512
+ interface TabsProps extends Omit<TabsProps$1, 'items'> {
513
+ /** auto skip null tab */
514
+ items: (TabProps | null)[];
515
+ }
516
+ /**
517
+ * Tabs component with Ant Design & FaasJS
518
+ *
519
+ * @ref https://ant.design/components/tabs/
520
+ */
521
+ declare function Tabs(props: TabsProps): react_jsx_runtime.JSX.Element;
522
+
523
+ interface TitleProps {
524
+ title: string | string[];
525
+ /** ` - ` as default */
526
+ separator?: string;
527
+ suffix?: string;
528
+ /** return a h1 element */
529
+ h1?: boolean | {
530
+ className?: string;
531
+ style?: React.CSSProperties;
532
+ };
533
+ /** return a pure text element */
534
+ plain?: boolean;
535
+ /** return children */
536
+ children?: JSX.Element;
537
+ }
538
+ /**
539
+ * Title is used to change the title of the page.
540
+ * Return null by default.
541
+ *
542
+ * ```ts
543
+ * // return null
544
+ * <Title title='hi' /> // => change the document.title to 'hi'
545
+ * <Title title={['a', 'b']} /> // => change the document.title to 'a - b'
546
+ *
547
+ * // return h1
548
+ * <Title title='hi' h1 /> // => <h1>hi</h1>
549
+ * <Title title={['a', 'b']} h1 /> // => <h1>a</h1>
550
+ *
551
+ * // return children
552
+ * <Title title='hi'><CustomTitle /></Title> // => <CustomTitle />
553
+ * ```
554
+ */
555
+ declare function Title(props: TitleProps): JSX.Element;
556
+
557
+ export { App, AppProps, BaseItemProps, BaseOption, Blank, BlankProps, ConfigContext, ConfigProvider, ConfigProviderProps, Description, DescriptionItemContentProps, DescriptionItemProps, DescriptionProps, DrawerProps, ErrorBoundary, ErrorBoundaryProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, FormSubmitProps, Link, LinkProps, Loading, LoadingProps, ModalProps, PageNotFound, Routes, RoutesProps, TabProps, Table, TableItemProps, TableProps, Tabs, TabsProps, Title, TitleProps, UnionFaasItemElement, UnionFaasItemInjection, UnionFaasItemProps, UnionFaasItemRender, UnionScene, setDrawerProps, setModalProps, transferOptions, transferValue, useApp, useAppProps, useConfigContext, useDrawer, useModal };