@faasjs/ant-design 0.0.3-beta.1 → 0.0.3-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/README.md +11 -76
- package/dist/index.d.ts +3 -3
- package/dist/index.js +132 -87
- package/dist/index.mjs +122 -75
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -48,9 +48,7 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
|
|
|
48
48
|
- [BaseItemProps](#baseitemprops)
|
|
49
49
|
- [BaseOption](#baseoption)
|
|
50
50
|
- [BlankProps](#blankprops)
|
|
51
|
-
- [CalendarProps](#calendarprops)
|
|
52
51
|
- [ConfigProviderProps](#configproviderprops)
|
|
53
|
-
- [DatePickerProps](#datepickerprops)
|
|
54
52
|
- [DescriptionItemProps](#descriptionitemprops)
|
|
55
53
|
- [DescriptionProps](#descriptionprops)
|
|
56
54
|
- [DrawerProps](#drawerprops)
|
|
@@ -71,7 +69,6 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
|
|
|
71
69
|
- [RoutesProps](#routesprops)
|
|
72
70
|
- [TableItemProps](#tableitemprops)
|
|
73
71
|
- [TableProps](#tableprops)
|
|
74
|
-
- [TimePickerProps](#timepickerprops)
|
|
75
72
|
- [TitleProps](#titleprops)
|
|
76
73
|
- [setDrawerProps](#setdrawerprops)
|
|
77
74
|
- [setModalProps](#setmodalprops)
|
|
@@ -79,12 +76,10 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
|
|
|
79
76
|
### Variables
|
|
80
77
|
|
|
81
78
|
- [ConfigContext](#configcontext)
|
|
82
|
-
- [DatePicker](#datepicker)
|
|
83
79
|
|
|
84
80
|
### Functions
|
|
85
81
|
|
|
86
82
|
- [Blank](#blank)
|
|
87
|
-
- [Calendar](#calendar)
|
|
88
83
|
- [ConfigProvider](#configprovider)
|
|
89
84
|
- [Description](#description)
|
|
90
85
|
- [Form](#form)
|
|
@@ -93,7 +88,6 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
|
|
|
93
88
|
- [PageNotFound](#pagenotfound)
|
|
94
89
|
- [Routes](#routes)
|
|
95
90
|
- [Table](#table)
|
|
96
|
-
- [TimePicker](#timepicker)
|
|
97
91
|
- [Title](#title)
|
|
98
92
|
- [transferOptions](#transferoptions)
|
|
99
93
|
- [transferValue](#transfervalue)
|
|
@@ -136,12 +130,6 @@ ___
|
|
|
136
130
|
|
|
137
131
|
___
|
|
138
132
|
|
|
139
|
-
### CalendarProps
|
|
140
|
-
|
|
141
|
-
Ƭ **CalendarProps**: `AntdProps`<`Dayjs`\>
|
|
142
|
-
|
|
143
|
-
___
|
|
144
|
-
|
|
145
133
|
### ConfigProviderProps
|
|
146
134
|
|
|
147
135
|
Ƭ **ConfigProviderProps**: `Object`
|
|
@@ -176,12 +164,6 @@ ___
|
|
|
176
164
|
|
|
177
165
|
___
|
|
178
166
|
|
|
179
|
-
### DatePickerProps
|
|
180
|
-
|
|
181
|
-
Ƭ **DatePickerProps**: `PickerDateProps`<`Dayjs`\>
|
|
182
|
-
|
|
183
|
-
___
|
|
184
|
-
|
|
185
167
|
### DescriptionItemProps
|
|
186
168
|
|
|
187
169
|
Ƭ **DescriptionItemProps**<`T`\>: { `children?`: `JSX.Element` ; `if?`: (`values`: `Record`<`string`, `any`\>) => `boolean` ; `render?`: (`value`: `T`, `values`: `any`) => `ReactNode` \| `JSX.Element` } & [`FaasItemProps`](#faasitemprops) & { `object?`: [`DescriptionItemProps`](#descriptionitemprops)[] }
|
|
@@ -333,7 +315,7 @@ ___
|
|
|
333
315
|
|
|
334
316
|
### FormProps
|
|
335
317
|
|
|
336
|
-
Ƭ **FormProps**<`Values`, `ExtendItemProps`\>: { `beforeItems?`: `JSX.Element` \| `JSX.Element`[] ; `children?`: `ReactNode` ; `extendTypes?`: [`ExtendTypes`](#extendtypes) ; `footer?`: `JSX.Element` \| `JSX.Element`[] ; `initialValues?`: `Values` ; `items?`: ([`FormItemProps`](#formitemprops) \| `ExtendItemProps`)[] ; `onFinish?`: (`values`: `Values`, `submit?`: (`values`: `any`) => `Promise`<`any`\>) => `Promise`<`any`\> ; `submit?`: ``false`` \| { `text?`: `string` ; `to?`: { `action`: `string` ; `params?`: `Record`<`string`, `any`\> } } } & `Omit`<`AntdFormProps`<`Values`\>, ``"onFinish"`` \| ``"children"`` \| ``"initialValues"``\>
|
|
318
|
+
Ƭ **FormProps**<`Values`, `ExtendItemProps`\>: { `beforeItems?`: `JSX.Element` \| `JSX.Element`[] ; `children?`: `ReactNode` ; `extendTypes?`: [`ExtendTypes`](#extendtypes) ; `footer?`: `JSX.Element` \| `JSX.Element`[] ; `initialValues?`: `Values` ; `items?`: ([`FormItemProps`](#formitemprops) \| `ExtendItemProps` \| `JSX.Element`)[] ; `onFinish?`: (`values`: `Values`, `submit?`: (`values`: `any`) => `Promise`<`any`\>) => `Promise`<`any`\> ; `submit?`: ``false`` \| { `text?`: `string` ; `to?`: { `action`: `string` ; `params?`: `Record`<`string`, `any`\> } } } & `Omit`<`AntdFormProps`<`Values`\>, ``"onFinish"`` \| ``"children"`` \| ``"initialValues"``\>
|
|
337
319
|
|
|
338
320
|
#### Type parameters
|
|
339
321
|
|
|
@@ -406,12 +388,6 @@ ___
|
|
|
406
388
|
|
|
407
389
|
___
|
|
408
390
|
|
|
409
|
-
### TimePickerProps
|
|
410
|
-
|
|
411
|
-
Ƭ **TimePickerProps**: `Omit`<`PickerTimeProps`<`Dayjs`\>, ``"picker"``\>
|
|
412
|
-
|
|
413
|
-
___
|
|
414
|
-
|
|
415
391
|
### TitleProps
|
|
416
392
|
|
|
417
393
|
Ƭ **TitleProps**: `Object`
|
|
@@ -422,7 +398,6 @@ ___
|
|
|
422
398
|
| :------ | :------ | :------ |
|
|
423
399
|
| `children?` | `JSX.Element` | return children |
|
|
424
400
|
| `h1?` | `boolean` \| { `className?`: `string` ; `style?`: `React.CSSProperties` } | return a h1 element |
|
|
425
|
-
| `header?` | `PageHeaderProps` | return a PageHeader element |
|
|
426
401
|
| `plain?` | `boolean` | return a pure text element |
|
|
427
402
|
| `separator?` | `string` | ` - ` as default |
|
|
428
403
|
| `suffix?` | `string` | - |
|
|
@@ -474,12 +449,6 @@ ___
|
|
|
474
449
|
|
|
475
450
|
• `Const` **ConfigContext**: `Context`<[`ConfigProviderProps`](#configproviderprops)\>
|
|
476
451
|
|
|
477
|
-
___
|
|
478
|
-
|
|
479
|
-
### DatePicker
|
|
480
|
-
|
|
481
|
-
• `Const` **DatePicker**: `PickerComponentClass`<`Object`, `unknown`\> & {}
|
|
482
|
-
|
|
483
452
|
## Functions
|
|
484
453
|
|
|
485
454
|
### Blank
|
|
@@ -504,25 +473,9 @@ If value is undefined or null, return text, otherwise return value.
|
|
|
504
473
|
|
|
505
474
|
___
|
|
506
475
|
|
|
507
|
-
### Calendar
|
|
508
|
-
|
|
509
|
-
▸ **Calendar**(`props`): `Element`
|
|
510
|
-
|
|
511
|
-
#### Parameters
|
|
512
|
-
|
|
513
|
-
| Name | Type |
|
|
514
|
-
| :------ | :------ |
|
|
515
|
-
| `props` | `CalendarProps`<`Dayjs`\> |
|
|
516
|
-
|
|
517
|
-
#### Returns
|
|
518
|
-
|
|
519
|
-
`Element`
|
|
520
|
-
|
|
521
|
-
___
|
|
522
|
-
|
|
523
476
|
### ConfigProvider
|
|
524
477
|
|
|
525
|
-
▸ **ConfigProvider**(
|
|
478
|
+
▸ **ConfigProvider**(`«destructured»`): `Element`
|
|
526
479
|
|
|
527
480
|
Config for @faasjs/ant-design components.
|
|
528
481
|
|
|
@@ -540,9 +493,9 @@ Config for @faasjs/ant-design components.
|
|
|
540
493
|
|
|
541
494
|
| Name | Type |
|
|
542
495
|
| :------ | :------ |
|
|
543
|
-
|
|
|
544
|
-
| `
|
|
545
|
-
| `
|
|
496
|
+
| `«destructured»` | `Object` |
|
|
497
|
+
| › `children` | `ReactNode` |
|
|
498
|
+
| › `config` | [`ConfigProviderProps`](#configproviderprops) |
|
|
546
499
|
|
|
547
500
|
#### Returns
|
|
548
501
|
|
|
@@ -608,10 +561,10 @@ FormItem, can be used without Form.
|
|
|
608
561
|
|
|
609
562
|
```ts
|
|
610
563
|
// use inline type
|
|
611
|
-
<FormItem
|
|
564
|
+
<FormItem type='string' id='name' />
|
|
612
565
|
|
|
613
566
|
// use custom type
|
|
614
|
-
<FormItem
|
|
567
|
+
<FormItem id='password'>
|
|
615
568
|
<Input.Password />
|
|
616
569
|
</>
|
|
617
570
|
```
|
|
@@ -636,7 +589,7 @@ ___
|
|
|
636
589
|
|
|
637
590
|
### Link
|
|
638
591
|
|
|
639
|
-
▸ **Link**(
|
|
592
|
+
▸ **Link**(`«destructured»`): `Element`
|
|
640
593
|
|
|
641
594
|
```ts
|
|
642
595
|
// pure link
|
|
@@ -650,7 +603,7 @@ ___
|
|
|
650
603
|
|
|
651
604
|
| Name | Type |
|
|
652
605
|
| :------ | :------ |
|
|
653
|
-
|
|
|
606
|
+
| `«destructured»` | [`LinkProps`](#linkprops) |
|
|
654
607
|
|
|
655
608
|
#### Returns
|
|
656
609
|
|
|
@@ -731,24 +684,6 @@ https://ant.design/components/table/
|
|
|
731
684
|
|
|
732
685
|
___
|
|
733
686
|
|
|
734
|
-
### TimePicker
|
|
735
|
-
|
|
736
|
-
▸ **TimePicker**(`props`): `ReactElement`<`any`, `string` \| `JSXElementConstructor`<`any`\>\>
|
|
737
|
-
|
|
738
|
-
**NOTE**: Exotic components are not callable.
|
|
739
|
-
|
|
740
|
-
#### Parameters
|
|
741
|
-
|
|
742
|
-
| Name | Type |
|
|
743
|
-
| :------ | :------ |
|
|
744
|
-
| `props` | [`TimePickerProps`](#timepickerprops) & `RefAttributes`<`any`\> |
|
|
745
|
-
|
|
746
|
-
#### Returns
|
|
747
|
-
|
|
748
|
-
`ReactElement`<`any`, `string` \| `JSXElementConstructor`<`any`\>\>
|
|
749
|
-
|
|
750
|
-
___
|
|
751
|
-
|
|
752
687
|
### Title
|
|
753
688
|
|
|
754
689
|
▸ **Title**(`props`): `JSX.Element`
|
|
@@ -834,7 +769,7 @@ Hook style drawer.
|
|
|
834
769
|
|
|
835
770
|
| Name | Type | Description |
|
|
836
771
|
| :------ | :------ | :------ |
|
|
837
|
-
| `init?` | [`DrawerProps`](#drawerprops) | initial props
|
|
772
|
+
| `init?` | [`DrawerProps`](#drawerprops) | initial props ```ts function Example() { const { drawer, setDrawerProps } = useDrawer() return <> <Button onClick={ () => setDrawerProps(prev => ({ open: !prev.open})) }> Toggle </Button> {drawer} </> } ``` |
|
|
838
773
|
|
|
839
774
|
#### Returns
|
|
840
775
|
|
|
@@ -858,7 +793,7 @@ Hook style modal.
|
|
|
858
793
|
|
|
859
794
|
| Name | Type | Description |
|
|
860
795
|
| :------ | :------ | :------ |
|
|
861
|
-
| `init?` | [`ModalProps`](#modalprops) | initial props
|
|
796
|
+
| `init?` | [`ModalProps`](#modalprops) | initial props ```ts function Example() { const { modal, setModalProps } = useModal() return <> <Button onClick={() => setModalProps({ open: true })}>Open Modal</Button> {modal}</> } ``` |
|
|
862
797
|
|
|
863
798
|
#### Returns
|
|
864
799
|
|
package/dist/index.d.ts
CHANGED
|
@@ -240,10 +240,10 @@ type FormItemProps<T = any> = {
|
|
|
240
240
|
*
|
|
241
241
|
* ```ts
|
|
242
242
|
* // use inline type
|
|
243
|
-
* <FormItem
|
|
243
|
+
* <FormItem type='string' id='name' />
|
|
244
244
|
*
|
|
245
245
|
* // use custom type
|
|
246
|
-
* <FormItem
|
|
246
|
+
* <FormItem id='password'>
|
|
247
247
|
* <Input.Password />
|
|
248
248
|
* </>
|
|
249
249
|
* ```
|
|
@@ -251,7 +251,7 @@ type FormItemProps<T = any> = {
|
|
|
251
251
|
declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
|
|
252
252
|
|
|
253
253
|
type FormProps<Values extends Record<string, any> = any, ExtendItemProps = any> = {
|
|
254
|
-
items?: (FormItemProps | ExtendItemProps)[];
|
|
254
|
+
items?: (FormItemProps | ExtendItemProps | JSX.Element)[];
|
|
255
255
|
/** Default: { text: 'Submit' }, set false to disable it */
|
|
256
256
|
submit?: false | {
|
|
257
257
|
/** Default: Submit */
|
package/dist/index.js
CHANGED
|
@@ -52,12 +52,12 @@ var import_react = __toESM(require("react"));
|
|
|
52
52
|
|
|
53
53
|
// src/Blank.tsx
|
|
54
54
|
var import_antd2 = require("antd");
|
|
55
|
-
var
|
|
55
|
+
var import_lodash_es2 = require("lodash-es");
|
|
56
56
|
|
|
57
57
|
// src/Config.tsx
|
|
58
58
|
var import_react2 = require("react");
|
|
59
59
|
var import_antd = require("antd");
|
|
60
|
-
var
|
|
60
|
+
var import_lodash_es = require("lodash-es");
|
|
61
61
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
62
62
|
var isZH = /^zh/i.test(navigator.language);
|
|
63
63
|
var zh = {
|
|
@@ -105,7 +105,7 @@ function ConfigProvider({
|
|
|
105
105
|
const [values, setValues] = (0, import_react2.useState)(baseConfig);
|
|
106
106
|
(0, import_react2.useEffect)(() => {
|
|
107
107
|
if (config.lang === "zh") {
|
|
108
|
-
setValues((0,
|
|
108
|
+
setValues((0, import_lodash_es.defaultsDeep)(config, {
|
|
109
109
|
lang: "zh",
|
|
110
110
|
common: zh,
|
|
111
111
|
Blank: { text: zh.blank },
|
|
@@ -130,20 +130,20 @@ function useConfigContext() {
|
|
|
130
130
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
131
131
|
function Blank(options) {
|
|
132
132
|
const { Blank: Blank2 } = useConfigContext();
|
|
133
|
-
return !options || (0,
|
|
133
|
+
return !options || (0, import_lodash_es2.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd2.Typography.Text, {
|
|
134
134
|
disabled: true,
|
|
135
135
|
children: (options == null ? void 0 : options.text) || Blank2.text
|
|
136
136
|
}) : options.value;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// src/data.ts
|
|
140
|
-
var
|
|
140
|
+
var import_lodash_es3 = require("lodash-es");
|
|
141
141
|
var import_dayjs = __toESM(require("dayjs"));
|
|
142
142
|
function transferOptions(options) {
|
|
143
143
|
if (!options)
|
|
144
144
|
return [];
|
|
145
145
|
return options.map((item) => typeof item === "object" ? item : {
|
|
146
|
-
label: (0,
|
|
146
|
+
label: (0, import_lodash_es3.upperFirst)(item.toString()),
|
|
147
147
|
value: item
|
|
148
148
|
});
|
|
149
149
|
}
|
|
@@ -166,7 +166,7 @@ function transferValue(type, value) {
|
|
|
166
166
|
// src/Description.tsx
|
|
167
167
|
var import_icons = require("@ant-design/icons");
|
|
168
168
|
var import_antd3 = require("antd");
|
|
169
|
-
var
|
|
169
|
+
var import_lodash_es4 = require("lodash-es");
|
|
170
170
|
var import_react3 = require("react");
|
|
171
171
|
var import_react4 = require("@faasjs/react");
|
|
172
172
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -177,7 +177,7 @@ function DescriptionItemContent(props) {
|
|
|
177
177
|
var _a2, _b;
|
|
178
178
|
const propsCopy = { ...props };
|
|
179
179
|
if (!propsCopy.item.title)
|
|
180
|
-
propsCopy.item.title = (0,
|
|
180
|
+
propsCopy.item.title = (0, import_lodash_es4.upperFirst)(propsCopy.item.id);
|
|
181
181
|
if (!propsCopy.item.type)
|
|
182
182
|
propsCopy.item.type = "string";
|
|
183
183
|
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
@@ -282,10 +282,10 @@ function Description(props) {
|
|
|
282
282
|
if (!props.faasData)
|
|
283
283
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
|
|
284
284
|
...props,
|
|
285
|
-
title: (0,
|
|
285
|
+
title: (0, import_lodash_es4.isFunction)(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
|
|
286
286
|
children: props.items.map((item) => {
|
|
287
287
|
return !item.if || item.if(props.dataSource) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
|
|
288
|
-
label: item.title || (0,
|
|
288
|
+
label: item.title || (0, import_lodash_es4.upperFirst)(item.id),
|
|
289
289
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
|
|
290
290
|
item,
|
|
291
291
|
value: props.dataSource[item.id],
|
|
@@ -302,10 +302,10 @@ function Description(props) {
|
|
|
302
302
|
render: ({ data }) => {
|
|
303
303
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
|
|
304
304
|
...props,
|
|
305
|
-
title: (0,
|
|
305
|
+
title: (0, import_lodash_es4.isFunction)(props.renderTitle) ? props.renderTitle(data) : props.title,
|
|
306
306
|
children: props.items.map((item) => {
|
|
307
307
|
return !item.if || item.if(data) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
|
|
308
|
-
label: item.title || (0,
|
|
308
|
+
label: item.title || (0, import_lodash_es4.upperFirst)(item.id),
|
|
309
309
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
|
|
310
310
|
item,
|
|
311
311
|
value: data[item.id],
|
|
@@ -356,11 +356,11 @@ var import_react8 = require("react");
|
|
|
356
356
|
var import_antd5 = require("antd");
|
|
357
357
|
var import_icons2 = require("@ant-design/icons");
|
|
358
358
|
var import_react6 = require("react");
|
|
359
|
-
var
|
|
359
|
+
var import_lodash_es5 = require("lodash-es");
|
|
360
360
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
361
361
|
function processProps(propsCopy, config) {
|
|
362
362
|
if (!propsCopy.title)
|
|
363
|
-
propsCopy.title = (0,
|
|
363
|
+
propsCopy.title = (0, import_lodash_es5.upperFirst)(propsCopy.id);
|
|
364
364
|
if (!propsCopy.label && propsCopy.label !== false)
|
|
365
365
|
propsCopy.label = propsCopy.title;
|
|
366
366
|
if (!propsCopy.name)
|
|
@@ -375,13 +375,13 @@ function processProps(propsCopy, config) {
|
|
|
375
375
|
required: true,
|
|
376
376
|
validator: async (_, values) => {
|
|
377
377
|
if (!values || values.length < 1)
|
|
378
|
-
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.
|
|
378
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
|
|
379
379
|
}
|
|
380
380
|
});
|
|
381
381
|
else
|
|
382
382
|
propsCopy.rules.push({
|
|
383
383
|
required: true,
|
|
384
|
-
message: `${propsCopy.label || propsCopy.title} ${config.
|
|
384
|
+
message: `${propsCopy.label || propsCopy.title} ${config.required}`
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
387
|
if (!propsCopy.input)
|
|
@@ -408,8 +408,8 @@ function FormItem(props) {
|
|
|
408
408
|
var _a;
|
|
409
409
|
const [computedProps, setComputedProps] = (0, import_react6.useState)();
|
|
410
410
|
const [extendTypes, setExtendTypes] = (0, import_react6.useState)();
|
|
411
|
-
const
|
|
412
|
-
const [hidden, setHidden] = (0, import_react6.useState)(false);
|
|
411
|
+
const { common: common2 } = useConfigContext();
|
|
412
|
+
const [hidden, setHidden] = (0, import_react6.useState)(props.hidden || false);
|
|
413
413
|
(0, import_react6.useEffect)(() => {
|
|
414
414
|
const propsCopy = { ...props };
|
|
415
415
|
if (propsCopy.extendTypes) {
|
|
@@ -418,14 +418,18 @@ function FormItem(props) {
|
|
|
418
418
|
}
|
|
419
419
|
if (propsCopy.if) {
|
|
420
420
|
const condition = propsCopy.if;
|
|
421
|
-
propsCopy.shouldUpdate
|
|
421
|
+
const originShouldUpdate = propsCopy.shouldUpdate;
|
|
422
|
+
propsCopy.shouldUpdate = (prev, cur) => {
|
|
422
423
|
const show = condition(cur);
|
|
424
|
+
const shouldUpdate = hidden !== show;
|
|
423
425
|
setHidden(!show);
|
|
424
|
-
|
|
426
|
+
const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
|
|
427
|
+
return shouldUpdate || origin;
|
|
425
428
|
};
|
|
426
429
|
delete propsCopy.if;
|
|
430
|
+
delete propsCopy.hidden;
|
|
427
431
|
}
|
|
428
|
-
setComputedProps(processProps(propsCopy,
|
|
432
|
+
setComputedProps(processProps(propsCopy, common2));
|
|
429
433
|
}, [props]);
|
|
430
434
|
if (!computedProps)
|
|
431
435
|
return null;
|
|
@@ -672,7 +676,7 @@ function FormItem(props) {
|
|
|
672
676
|
danger: true,
|
|
673
677
|
type: "link",
|
|
674
678
|
onClick: () => remove(field.name),
|
|
675
|
-
children:
|
|
679
|
+
children: common2.delete
|
|
676
680
|
})
|
|
677
681
|
]
|
|
678
682
|
})
|
|
@@ -697,7 +701,7 @@ function FormItem(props) {
|
|
|
697
701
|
onClick: () => add(),
|
|
698
702
|
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
|
|
699
703
|
children: [
|
|
700
|
-
|
|
704
|
+
common2.add,
|
|
701
705
|
" ",
|
|
702
706
|
computedProps.label
|
|
703
707
|
]
|
|
@@ -732,11 +736,19 @@ function Form(props) {
|
|
|
732
736
|
form
|
|
733
737
|
};
|
|
734
738
|
if (propsCopy.initialValues) {
|
|
735
|
-
for (const key in propsCopy.initialValues)
|
|
739
|
+
for (const key in propsCopy.initialValues) {
|
|
736
740
|
propsCopy.initialValues[key] = transferValue(
|
|
737
|
-
(_a2 = propsCopy.items.find((
|
|
741
|
+
(_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
|
|
738
742
|
propsCopy.initialValues[key]
|
|
739
743
|
);
|
|
744
|
+
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
745
|
+
if (item == null ? void 0 : item.if)
|
|
746
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
747
|
+
}
|
|
748
|
+
for (const item of propsCopy.items) {
|
|
749
|
+
if (item.if)
|
|
750
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
751
|
+
}
|
|
740
752
|
setInitialValues(propsCopy.initialValues);
|
|
741
753
|
delete propsCopy.initialValues;
|
|
742
754
|
}
|
|
@@ -773,6 +785,7 @@ function Form(props) {
|
|
|
773
785
|
setComputedProps(propsCopy);
|
|
774
786
|
}, [props]);
|
|
775
787
|
const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
|
|
788
|
+
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
776
789
|
if (props.onValuesChange) {
|
|
777
790
|
props.onValuesChange(changedValues, allValues);
|
|
778
791
|
}
|
|
@@ -787,6 +800,7 @@ function Form(props) {
|
|
|
787
800
|
(0, import_react8.useEffect)(() => {
|
|
788
801
|
if (!initialValues)
|
|
789
802
|
return;
|
|
803
|
+
console.debug("Form:initialValues", initialValues);
|
|
790
804
|
form.setFieldsValue(initialValues);
|
|
791
805
|
setInitialValues(null);
|
|
792
806
|
}, [computedProps]);
|
|
@@ -797,7 +811,7 @@ function Form(props) {
|
|
|
797
811
|
onValuesChange,
|
|
798
812
|
children: [
|
|
799
813
|
computedProps.beforeItems,
|
|
800
|
-
(_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
|
|
814
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => (0, import_react8.isValidElement)(item) ? item : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
|
|
801
815
|
...item,
|
|
802
816
|
extendTypes
|
|
803
817
|
}, item.id)),
|
|
@@ -832,15 +846,13 @@ function Link({
|
|
|
832
846
|
if (button)
|
|
833
847
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
|
|
834
848
|
...button,
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
style
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
children: text || children
|
|
843
|
-
})
|
|
849
|
+
target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
|
|
850
|
+
style: {
|
|
851
|
+
...Link2.style,
|
|
852
|
+
...style || {}
|
|
853
|
+
},
|
|
854
|
+
href,
|
|
855
|
+
children: text || children
|
|
844
856
|
});
|
|
845
857
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
|
|
846
858
|
href,
|
|
@@ -853,11 +865,11 @@ function Link({
|
|
|
853
865
|
});
|
|
854
866
|
}
|
|
855
867
|
if (button)
|
|
856
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
868
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
|
|
869
|
+
to: href,
|
|
870
|
+
target: target || (Link2 == null ? void 0 : Link2.target),
|
|
871
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
|
|
872
|
+
...button,
|
|
861
873
|
style: {
|
|
862
874
|
...Link2.style,
|
|
863
875
|
...style || {}
|
|
@@ -943,7 +955,7 @@ var import_react11 = require("react");
|
|
|
943
955
|
var import_antd10 = require("antd");
|
|
944
956
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
945
957
|
var import_icons3 = require("@ant-design/icons");
|
|
946
|
-
var
|
|
958
|
+
var import_lodash_es6 = require("lodash-es");
|
|
947
959
|
var import_react12 = require("@faasjs/react");
|
|
948
960
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
949
961
|
function processValue(item, value) {
|
|
@@ -972,7 +984,7 @@ function processValue(item, value) {
|
|
|
972
984
|
}
|
|
973
985
|
function Table(props) {
|
|
974
986
|
const [columns, setColumns] = (0, import_react11.useState)();
|
|
975
|
-
const { common: common2 } = useConfigContext();
|
|
987
|
+
const { common: common2, antd } = useConfigContext();
|
|
976
988
|
(0, import_react11.useEffect)(() => {
|
|
977
989
|
var _a;
|
|
978
990
|
for (const item of props.items) {
|
|
@@ -981,7 +993,7 @@ function Table(props) {
|
|
|
981
993
|
if (!item.dataIndex)
|
|
982
994
|
item.dataIndex = item.id;
|
|
983
995
|
if (!item.title)
|
|
984
|
-
item.title = (0,
|
|
996
|
+
item.title = (0, import_lodash_es6.upperFirst)(item.id);
|
|
985
997
|
if (!item.type)
|
|
986
998
|
item.type = "string";
|
|
987
999
|
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
@@ -1014,6 +1026,8 @@ function Table(props) {
|
|
|
1014
1026
|
item.render = (value) => processValue(item, value);
|
|
1015
1027
|
if (!item.onFilter)
|
|
1016
1028
|
item.onFilter = (value, row) => {
|
|
1029
|
+
if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
|
|
1030
|
+
return true;
|
|
1017
1031
|
if (!row[item.id])
|
|
1018
1032
|
return false;
|
|
1019
1033
|
return row[item.id].toLowerCase().includes(value.toLowerCase());
|
|
@@ -1042,6 +1056,8 @@ function Table(props) {
|
|
|
1042
1056
|
item.render = (value) => processValue(item, value);
|
|
1043
1057
|
if (!item.onFilter)
|
|
1044
1058
|
item.onFilter = (value, row) => {
|
|
1059
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1060
|
+
return true;
|
|
1045
1061
|
if (!row[item.id] || !row[item.id].length)
|
|
1046
1062
|
return false;
|
|
1047
1063
|
return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
|
|
@@ -1071,7 +1087,11 @@ function Table(props) {
|
|
|
1071
1087
|
if (!item.sorter)
|
|
1072
1088
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
1073
1089
|
if (!item.onFilter)
|
|
1074
|
-
item.onFilter = (value, row) =>
|
|
1090
|
+
item.onFilter = (value, row) => {
|
|
1091
|
+
if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
|
|
1092
|
+
return true;
|
|
1093
|
+
return value === row[item.id];
|
|
1094
|
+
};
|
|
1075
1095
|
if (!item.filters && item.filterDropdown !== false)
|
|
1076
1096
|
item.filterDropdown = ({
|
|
1077
1097
|
setSelectedKeys,
|
|
@@ -1095,7 +1115,13 @@ function Table(props) {
|
|
|
1095
1115
|
if (!item.render)
|
|
1096
1116
|
item.render = (value) => processValue(item, value).join(", ");
|
|
1097
1117
|
if (!item.onFilter)
|
|
1098
|
-
item.onFilter = (value, row) =>
|
|
1118
|
+
item.onFilter = (value, row) => {
|
|
1119
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1120
|
+
return true;
|
|
1121
|
+
if (!row[item.id] || !row[item.id].length)
|
|
1122
|
+
return false;
|
|
1123
|
+
return row[item.id].includes(value);
|
|
1124
|
+
};
|
|
1099
1125
|
if (!item.filters && item.filterDropdown !== false)
|
|
1100
1126
|
item.filterDropdown = ({
|
|
1101
1127
|
setSelectedKeys,
|
|
@@ -1173,11 +1199,11 @@ function Table(props) {
|
|
|
1173
1199
|
item.onFilter = (value, row) => {
|
|
1174
1200
|
switch (value) {
|
|
1175
1201
|
case "true":
|
|
1176
|
-
return !(0,
|
|
1202
|
+
return !(0, import_lodash_es6.isNil)(row[item.id]) && !!row[item.id];
|
|
1177
1203
|
case "false":
|
|
1178
|
-
return !(0,
|
|
1204
|
+
return !(0, import_lodash_es6.isNil)(row[item.id]) && !row[item.id];
|
|
1179
1205
|
case "empty":
|
|
1180
|
-
return (0,
|
|
1206
|
+
return (0, import_lodash_es6.isNil)(row[item.id]);
|
|
1181
1207
|
default:
|
|
1182
1208
|
return true;
|
|
1183
1209
|
}
|
|
@@ -1219,7 +1245,11 @@ function Table(props) {
|
|
|
1219
1245
|
if (!item.render)
|
|
1220
1246
|
item.render = (value) => processValue(item, value);
|
|
1221
1247
|
if (!item.onFilter)
|
|
1222
|
-
item.onFilter = (value, row) =>
|
|
1248
|
+
item.onFilter = (value, row) => {
|
|
1249
|
+
if (value === null && (0, import_lodash_es6.isNil)(row[item.id]))
|
|
1250
|
+
return true;
|
|
1251
|
+
return value === row[item.id];
|
|
1252
|
+
};
|
|
1223
1253
|
break;
|
|
1224
1254
|
}
|
|
1225
1255
|
}
|
|
@@ -1233,10 +1263,13 @@ function Table(props) {
|
|
|
1233
1263
|
setColumns((prev) => {
|
|
1234
1264
|
const newColumns = [...prev];
|
|
1235
1265
|
const index = newColumns.findIndex((item) => item.id === column.id);
|
|
1236
|
-
newColumns[index].filters = (0,
|
|
1266
|
+
newColumns[index].filters = (0, import_lodash_es6.uniqBy)(props.dataSource, column.id).map((v) => ({
|
|
1237
1267
|
text: v[column.id],
|
|
1238
1268
|
value: v[column.id]
|
|
1239
|
-
}))
|
|
1269
|
+
})).concat({
|
|
1270
|
+
text: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {}),
|
|
1271
|
+
value: null
|
|
1272
|
+
});
|
|
1240
1273
|
return newColumns;
|
|
1241
1274
|
});
|
|
1242
1275
|
}
|
|
@@ -1245,11 +1278,14 @@ function Table(props) {
|
|
|
1245
1278
|
if (!columns)
|
|
1246
1279
|
return null;
|
|
1247
1280
|
if (!props.faasData)
|
|
1248
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.
|
|
1249
|
-
...
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1281
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
|
|
1282
|
+
...antd,
|
|
1283
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
|
|
1284
|
+
...props,
|
|
1285
|
+
rowKey: props.rowKey || "id",
|
|
1286
|
+
columns,
|
|
1287
|
+
dataSource: props.dataSource
|
|
1288
|
+
})
|
|
1253
1289
|
});
|
|
1254
1290
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react12.FaasDataWrapper, {
|
|
1255
1291
|
fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Skeleton, {
|
|
@@ -1261,46 +1297,55 @@ function Table(props) {
|
|
|
1261
1297
|
reload
|
|
1262
1298
|
}) => {
|
|
1263
1299
|
if (!data)
|
|
1264
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.
|
|
1265
|
-
...
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
|
|
1301
|
+
...antd,
|
|
1302
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
|
|
1303
|
+
...props,
|
|
1304
|
+
rowKey: props.rowKey || "id",
|
|
1305
|
+
columns,
|
|
1306
|
+
dataSource: []
|
|
1307
|
+
})
|
|
1269
1308
|
});
|
|
1270
1309
|
if (Array.isArray(data))
|
|
1271
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.
|
|
1310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
|
|
1311
|
+
...antd,
|
|
1312
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
|
|
1313
|
+
...props,
|
|
1314
|
+
rowKey: props.rowKey || "id",
|
|
1315
|
+
columns,
|
|
1316
|
+
dataSource: data
|
|
1317
|
+
})
|
|
1318
|
+
});
|
|
1319
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.ConfigProvider, {
|
|
1320
|
+
...antd,
|
|
1321
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
|
|
1272
1322
|
...props,
|
|
1273
1323
|
rowKey: props.rowKey || "id",
|
|
1274
1324
|
columns,
|
|
1275
|
-
dataSource: data
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1325
|
+
dataSource: data.rows,
|
|
1326
|
+
pagination: {
|
|
1327
|
+
...props.pagination,
|
|
1328
|
+
...data.pagination
|
|
1329
|
+
},
|
|
1330
|
+
onChange: (pagination, filters, sorter, extra) => {
|
|
1331
|
+
if (props.onChange) {
|
|
1332
|
+
const processed = props.onChange(pagination, filters, sorter, extra);
|
|
1333
|
+
reload({
|
|
1334
|
+
...params,
|
|
1335
|
+
pagination: processed.pagination,
|
|
1336
|
+
filters: processed.filters,
|
|
1337
|
+
sorter: processed.sorter
|
|
1338
|
+
});
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1289
1341
|
reload({
|
|
1290
1342
|
...params,
|
|
1291
|
-
pagination
|
|
1292
|
-
filters
|
|
1293
|
-
sorter
|
|
1343
|
+
pagination,
|
|
1344
|
+
filters,
|
|
1345
|
+
sorter
|
|
1294
1346
|
});
|
|
1295
|
-
return;
|
|
1296
1347
|
}
|
|
1297
|
-
|
|
1298
|
-
...params,
|
|
1299
|
-
pagination,
|
|
1300
|
-
filters,
|
|
1301
|
-
sorter
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1348
|
+
})
|
|
1304
1349
|
});
|
|
1305
1350
|
},
|
|
1306
1351
|
...props.faasData
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import React from "react";
|
|
|
3
3
|
|
|
4
4
|
// src/Blank.tsx
|
|
5
5
|
import { Typography } from "antd";
|
|
6
|
-
import { isNil } from "lodash";
|
|
6
|
+
import { isNil } from "lodash-es";
|
|
7
7
|
|
|
8
8
|
// src/Config.tsx
|
|
9
9
|
import {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
useState
|
|
14
14
|
} from "react";
|
|
15
15
|
import { ConfigProvider as AntdConfigProvider } from "antd";
|
|
16
|
-
import { defaultsDeep } from "lodash";
|
|
16
|
+
import { defaultsDeep } from "lodash-es";
|
|
17
17
|
import { jsx } from "react/jsx-runtime";
|
|
18
18
|
var isZH = /^zh/i.test(navigator.language);
|
|
19
19
|
var zh = {
|
|
@@ -93,7 +93,7 @@ function Blank(options) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// src/data.ts
|
|
96
|
-
import { upperFirst } from "lodash";
|
|
96
|
+
import { upperFirst } from "lodash-es";
|
|
97
97
|
import dayjs from "dayjs";
|
|
98
98
|
function transferOptions(options) {
|
|
99
99
|
if (!options)
|
|
@@ -126,7 +126,7 @@ import {
|
|
|
126
126
|
Skeleton,
|
|
127
127
|
Space
|
|
128
128
|
} from "antd";
|
|
129
|
-
import { isFunction, upperFirst as upperFirst2 } from "lodash";
|
|
129
|
+
import { isFunction, upperFirst as upperFirst2 } from "lodash-es";
|
|
130
130
|
import {
|
|
131
131
|
cloneElement,
|
|
132
132
|
useEffect as useEffect2,
|
|
@@ -320,7 +320,8 @@ import {
|
|
|
320
320
|
import {
|
|
321
321
|
useEffect as useEffect4,
|
|
322
322
|
useState as useState5,
|
|
323
|
-
useCallback
|
|
323
|
+
useCallback,
|
|
324
|
+
isValidElement
|
|
324
325
|
} from "react";
|
|
325
326
|
|
|
326
327
|
// src/FormItem.tsx
|
|
@@ -341,7 +342,7 @@ import {
|
|
|
341
342
|
useEffect as useEffect3,
|
|
342
343
|
useState as useState4
|
|
343
344
|
} from "react";
|
|
344
|
-
import { upperFirst as upperFirst3 } from "lodash";
|
|
345
|
+
import { upperFirst as upperFirst3 } from "lodash-es";
|
|
345
346
|
import { Fragment as Fragment2, jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
346
347
|
function processProps(propsCopy, config) {
|
|
347
348
|
if (!propsCopy.title)
|
|
@@ -360,13 +361,13 @@ function processProps(propsCopy, config) {
|
|
|
360
361
|
required: true,
|
|
361
362
|
validator: async (_, values) => {
|
|
362
363
|
if (!values || values.length < 1)
|
|
363
|
-
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.
|
|
364
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
|
|
364
365
|
}
|
|
365
366
|
});
|
|
366
367
|
else
|
|
367
368
|
propsCopy.rules.push({
|
|
368
369
|
required: true,
|
|
369
|
-
message: `${propsCopy.label || propsCopy.title} ${config.
|
|
370
|
+
message: `${propsCopy.label || propsCopy.title} ${config.required}`
|
|
370
371
|
});
|
|
371
372
|
}
|
|
372
373
|
if (!propsCopy.input)
|
|
@@ -393,8 +394,8 @@ function FormItem(props) {
|
|
|
393
394
|
var _a;
|
|
394
395
|
const [computedProps, setComputedProps] = useState4();
|
|
395
396
|
const [extendTypes, setExtendTypes] = useState4();
|
|
396
|
-
const
|
|
397
|
-
const [hidden, setHidden] = useState4(false);
|
|
397
|
+
const { common: common2 } = useConfigContext();
|
|
398
|
+
const [hidden, setHidden] = useState4(props.hidden || false);
|
|
398
399
|
useEffect3(() => {
|
|
399
400
|
const propsCopy = { ...props };
|
|
400
401
|
if (propsCopy.extendTypes) {
|
|
@@ -403,14 +404,18 @@ function FormItem(props) {
|
|
|
403
404
|
}
|
|
404
405
|
if (propsCopy.if) {
|
|
405
406
|
const condition = propsCopy.if;
|
|
406
|
-
propsCopy.shouldUpdate
|
|
407
|
+
const originShouldUpdate = propsCopy.shouldUpdate;
|
|
408
|
+
propsCopy.shouldUpdate = (prev, cur) => {
|
|
407
409
|
const show = condition(cur);
|
|
410
|
+
const shouldUpdate = hidden !== show;
|
|
408
411
|
setHidden(!show);
|
|
409
|
-
|
|
412
|
+
const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
|
|
413
|
+
return shouldUpdate || origin;
|
|
410
414
|
};
|
|
411
415
|
delete propsCopy.if;
|
|
416
|
+
delete propsCopy.hidden;
|
|
412
417
|
}
|
|
413
|
-
setComputedProps(processProps(propsCopy,
|
|
418
|
+
setComputedProps(processProps(propsCopy, common2));
|
|
414
419
|
}, [props]);
|
|
415
420
|
if (!computedProps)
|
|
416
421
|
return null;
|
|
@@ -657,7 +662,7 @@ function FormItem(props) {
|
|
|
657
662
|
danger: true,
|
|
658
663
|
type: "link",
|
|
659
664
|
onClick: () => remove(field.name),
|
|
660
|
-
children:
|
|
665
|
+
children: common2.delete
|
|
661
666
|
})
|
|
662
667
|
]
|
|
663
668
|
})
|
|
@@ -682,7 +687,7 @@ function FormItem(props) {
|
|
|
682
687
|
onClick: () => add(),
|
|
683
688
|
icon: /* @__PURE__ */ jsx5(PlusOutlined, {}),
|
|
684
689
|
children: [
|
|
685
|
-
|
|
690
|
+
common2.add,
|
|
686
691
|
" ",
|
|
687
692
|
computedProps.label
|
|
688
693
|
]
|
|
@@ -717,11 +722,19 @@ function Form(props) {
|
|
|
717
722
|
form
|
|
718
723
|
};
|
|
719
724
|
if (propsCopy.initialValues) {
|
|
720
|
-
for (const key in propsCopy.initialValues)
|
|
725
|
+
for (const key in propsCopy.initialValues) {
|
|
721
726
|
propsCopy.initialValues[key] = transferValue(
|
|
722
|
-
(_a2 = propsCopy.items.find((
|
|
727
|
+
(_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
|
|
723
728
|
propsCopy.initialValues[key]
|
|
724
729
|
);
|
|
730
|
+
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
731
|
+
if (item == null ? void 0 : item.if)
|
|
732
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
733
|
+
}
|
|
734
|
+
for (const item of propsCopy.items) {
|
|
735
|
+
if (item.if)
|
|
736
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
737
|
+
}
|
|
725
738
|
setInitialValues(propsCopy.initialValues);
|
|
726
739
|
delete propsCopy.initialValues;
|
|
727
740
|
}
|
|
@@ -758,6 +771,7 @@ function Form(props) {
|
|
|
758
771
|
setComputedProps(propsCopy);
|
|
759
772
|
}, [props]);
|
|
760
773
|
const onValuesChange = useCallback((changedValues, allValues) => {
|
|
774
|
+
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
761
775
|
if (props.onValuesChange) {
|
|
762
776
|
props.onValuesChange(changedValues, allValues);
|
|
763
777
|
}
|
|
@@ -772,6 +786,7 @@ function Form(props) {
|
|
|
772
786
|
useEffect4(() => {
|
|
773
787
|
if (!initialValues)
|
|
774
788
|
return;
|
|
789
|
+
console.debug("Form:initialValues", initialValues);
|
|
775
790
|
form.setFieldsValue(initialValues);
|
|
776
791
|
setInitialValues(null);
|
|
777
792
|
}, [computedProps]);
|
|
@@ -782,7 +797,7 @@ function Form(props) {
|
|
|
782
797
|
onValuesChange,
|
|
783
798
|
children: [
|
|
784
799
|
computedProps.beforeItems,
|
|
785
|
-
(_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ jsx6(FormItem, {
|
|
800
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => isValidElement(item) ? item : /* @__PURE__ */ jsx6(FormItem, {
|
|
786
801
|
...item,
|
|
787
802
|
extendTypes
|
|
788
803
|
}, item.id)),
|
|
@@ -817,15 +832,13 @@ function Link({
|
|
|
817
832
|
if (button)
|
|
818
833
|
return /* @__PURE__ */ jsx7(Button3, {
|
|
819
834
|
...button,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
style
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
children: text || children
|
|
828
|
-
})
|
|
835
|
+
target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
|
|
836
|
+
style: {
|
|
837
|
+
...Link2.style,
|
|
838
|
+
...style || {}
|
|
839
|
+
},
|
|
840
|
+
href,
|
|
841
|
+
children: text || children
|
|
829
842
|
});
|
|
830
843
|
return /* @__PURE__ */ jsx7("a", {
|
|
831
844
|
href,
|
|
@@ -838,11 +851,11 @@ function Link({
|
|
|
838
851
|
});
|
|
839
852
|
}
|
|
840
853
|
if (button)
|
|
841
|
-
return /* @__PURE__ */ jsx7(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
854
|
+
return /* @__PURE__ */ jsx7(RouterLink, {
|
|
855
|
+
to: href,
|
|
856
|
+
target: target || (Link2 == null ? void 0 : Link2.target),
|
|
857
|
+
children: /* @__PURE__ */ jsx7(Button3, {
|
|
858
|
+
...button,
|
|
846
859
|
style: {
|
|
847
860
|
...Link2.style,
|
|
848
861
|
...style || {}
|
|
@@ -938,7 +951,8 @@ import {
|
|
|
938
951
|
Table as AntdTable,
|
|
939
952
|
Radio,
|
|
940
953
|
Skeleton as Skeleton3,
|
|
941
|
-
Input as Input2
|
|
954
|
+
Input as Input2,
|
|
955
|
+
ConfigProvider as ConfigProvider2
|
|
942
956
|
} from "antd";
|
|
943
957
|
import dayjs2 from "dayjs";
|
|
944
958
|
import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
|
|
@@ -946,7 +960,7 @@ import {
|
|
|
946
960
|
isNil as isNil2,
|
|
947
961
|
uniqBy,
|
|
948
962
|
upperFirst as upperFirst4
|
|
949
|
-
} from "lodash";
|
|
963
|
+
} from "lodash-es";
|
|
950
964
|
import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
|
|
951
965
|
import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
952
966
|
function processValue(item, value) {
|
|
@@ -975,7 +989,7 @@ function processValue(item, value) {
|
|
|
975
989
|
}
|
|
976
990
|
function Table(props) {
|
|
977
991
|
const [columns, setColumns] = useState7();
|
|
978
|
-
const { common: common2 } = useConfigContext();
|
|
992
|
+
const { common: common2, antd } = useConfigContext();
|
|
979
993
|
useEffect5(() => {
|
|
980
994
|
var _a;
|
|
981
995
|
for (const item of props.items) {
|
|
@@ -1017,6 +1031,8 @@ function Table(props) {
|
|
|
1017
1031
|
item.render = (value) => processValue(item, value);
|
|
1018
1032
|
if (!item.onFilter)
|
|
1019
1033
|
item.onFilter = (value, row) => {
|
|
1034
|
+
if (value === null && isNil2(row[item.id]))
|
|
1035
|
+
return true;
|
|
1020
1036
|
if (!row[item.id])
|
|
1021
1037
|
return false;
|
|
1022
1038
|
return row[item.id].toLowerCase().includes(value.toLowerCase());
|
|
@@ -1045,6 +1061,8 @@ function Table(props) {
|
|
|
1045
1061
|
item.render = (value) => processValue(item, value);
|
|
1046
1062
|
if (!item.onFilter)
|
|
1047
1063
|
item.onFilter = (value, row) => {
|
|
1064
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1065
|
+
return true;
|
|
1048
1066
|
if (!row[item.id] || !row[item.id].length)
|
|
1049
1067
|
return false;
|
|
1050
1068
|
return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
|
|
@@ -1074,7 +1092,11 @@ function Table(props) {
|
|
|
1074
1092
|
if (!item.sorter)
|
|
1075
1093
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
1076
1094
|
if (!item.onFilter)
|
|
1077
|
-
item.onFilter = (value, row) =>
|
|
1095
|
+
item.onFilter = (value, row) => {
|
|
1096
|
+
if (value === null && isNil2(row[item.id]))
|
|
1097
|
+
return true;
|
|
1098
|
+
return value === row[item.id];
|
|
1099
|
+
};
|
|
1078
1100
|
if (!item.filters && item.filterDropdown !== false)
|
|
1079
1101
|
item.filterDropdown = ({
|
|
1080
1102
|
setSelectedKeys,
|
|
@@ -1098,7 +1120,13 @@ function Table(props) {
|
|
|
1098
1120
|
if (!item.render)
|
|
1099
1121
|
item.render = (value) => processValue(item, value).join(", ");
|
|
1100
1122
|
if (!item.onFilter)
|
|
1101
|
-
item.onFilter = (value, row) =>
|
|
1123
|
+
item.onFilter = (value, row) => {
|
|
1124
|
+
if (value === null && (!row[item.id] || !row[item.id].length))
|
|
1125
|
+
return true;
|
|
1126
|
+
if (!row[item.id] || !row[item.id].length)
|
|
1127
|
+
return false;
|
|
1128
|
+
return row[item.id].includes(value);
|
|
1129
|
+
};
|
|
1102
1130
|
if (!item.filters && item.filterDropdown !== false)
|
|
1103
1131
|
item.filterDropdown = ({
|
|
1104
1132
|
setSelectedKeys,
|
|
@@ -1222,7 +1250,11 @@ function Table(props) {
|
|
|
1222
1250
|
if (!item.render)
|
|
1223
1251
|
item.render = (value) => processValue(item, value);
|
|
1224
1252
|
if (!item.onFilter)
|
|
1225
|
-
item.onFilter = (value, row) =>
|
|
1253
|
+
item.onFilter = (value, row) => {
|
|
1254
|
+
if (value === null && isNil2(row[item.id]))
|
|
1255
|
+
return true;
|
|
1256
|
+
return value === row[item.id];
|
|
1257
|
+
};
|
|
1226
1258
|
break;
|
|
1227
1259
|
}
|
|
1228
1260
|
}
|
|
@@ -1239,7 +1271,10 @@ function Table(props) {
|
|
|
1239
1271
|
newColumns[index].filters = uniqBy(props.dataSource, column.id).map((v) => ({
|
|
1240
1272
|
text: v[column.id],
|
|
1241
1273
|
value: v[column.id]
|
|
1242
|
-
}))
|
|
1274
|
+
})).concat({
|
|
1275
|
+
text: /* @__PURE__ */ jsx10(Blank, {}),
|
|
1276
|
+
value: null
|
|
1277
|
+
});
|
|
1243
1278
|
return newColumns;
|
|
1244
1279
|
});
|
|
1245
1280
|
}
|
|
@@ -1248,11 +1283,14 @@ function Table(props) {
|
|
|
1248
1283
|
if (!columns)
|
|
1249
1284
|
return null;
|
|
1250
1285
|
if (!props.faasData)
|
|
1251
|
-
return /* @__PURE__ */ jsx10(
|
|
1252
|
-
...
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1286
|
+
return /* @__PURE__ */ jsx10(ConfigProvider2, {
|
|
1287
|
+
...antd,
|
|
1288
|
+
children: /* @__PURE__ */ jsx10(AntdTable, {
|
|
1289
|
+
...props,
|
|
1290
|
+
rowKey: props.rowKey || "id",
|
|
1291
|
+
columns,
|
|
1292
|
+
dataSource: props.dataSource
|
|
1293
|
+
})
|
|
1256
1294
|
});
|
|
1257
1295
|
return /* @__PURE__ */ jsx10(FaasDataWrapper2, {
|
|
1258
1296
|
fallback: props.faasData.fallback || /* @__PURE__ */ jsx10(Skeleton3, {
|
|
@@ -1264,46 +1302,55 @@ function Table(props) {
|
|
|
1264
1302
|
reload
|
|
1265
1303
|
}) => {
|
|
1266
1304
|
if (!data)
|
|
1267
|
-
return /* @__PURE__ */ jsx10(
|
|
1268
|
-
...
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1305
|
+
return /* @__PURE__ */ jsx10(ConfigProvider2, {
|
|
1306
|
+
...antd,
|
|
1307
|
+
children: /* @__PURE__ */ jsx10(AntdTable, {
|
|
1308
|
+
...props,
|
|
1309
|
+
rowKey: props.rowKey || "id",
|
|
1310
|
+
columns,
|
|
1311
|
+
dataSource: []
|
|
1312
|
+
})
|
|
1272
1313
|
});
|
|
1273
1314
|
if (Array.isArray(data))
|
|
1274
|
-
return /* @__PURE__ */ jsx10(
|
|
1315
|
+
return /* @__PURE__ */ jsx10(ConfigProvider2, {
|
|
1316
|
+
...antd,
|
|
1317
|
+
children: /* @__PURE__ */ jsx10(AntdTable, {
|
|
1318
|
+
...props,
|
|
1319
|
+
rowKey: props.rowKey || "id",
|
|
1320
|
+
columns,
|
|
1321
|
+
dataSource: data
|
|
1322
|
+
})
|
|
1323
|
+
});
|
|
1324
|
+
return /* @__PURE__ */ jsx10(ConfigProvider2, {
|
|
1325
|
+
...antd,
|
|
1326
|
+
children: /* @__PURE__ */ jsx10(AntdTable, {
|
|
1275
1327
|
...props,
|
|
1276
1328
|
rowKey: props.rowKey || "id",
|
|
1277
1329
|
columns,
|
|
1278
|
-
dataSource: data
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1330
|
+
dataSource: data.rows,
|
|
1331
|
+
pagination: {
|
|
1332
|
+
...props.pagination,
|
|
1333
|
+
...data.pagination
|
|
1334
|
+
},
|
|
1335
|
+
onChange: (pagination, filters, sorter, extra) => {
|
|
1336
|
+
if (props.onChange) {
|
|
1337
|
+
const processed = props.onChange(pagination, filters, sorter, extra);
|
|
1338
|
+
reload({
|
|
1339
|
+
...params,
|
|
1340
|
+
pagination: processed.pagination,
|
|
1341
|
+
filters: processed.filters,
|
|
1342
|
+
sorter: processed.sorter
|
|
1343
|
+
});
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1292
1346
|
reload({
|
|
1293
1347
|
...params,
|
|
1294
|
-
pagination
|
|
1295
|
-
filters
|
|
1296
|
-
sorter
|
|
1348
|
+
pagination,
|
|
1349
|
+
filters,
|
|
1350
|
+
sorter
|
|
1297
1351
|
});
|
|
1298
|
-
return;
|
|
1299
1352
|
}
|
|
1300
|
-
|
|
1301
|
-
...params,
|
|
1302
|
-
pagination,
|
|
1303
|
-
filters,
|
|
1304
|
-
sorter
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1353
|
+
})
|
|
1307
1354
|
});
|
|
1308
1355
|
},
|
|
1309
1356
|
...props.faasData
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@ant-design/icons": "*",
|
|
27
27
|
"antd": "*",
|
|
28
|
-
"lodash": "*",
|
|
28
|
+
"lodash-es": "*",
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*",
|
|
31
|
-
"@faasjs/react": "^0.0.3-beta.
|
|
31
|
+
"@faasjs/react": "^0.0.3-beta.11",
|
|
32
32
|
"react-router-dom": "*",
|
|
33
33
|
"dayjs": "*"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/lodash": "*",
|
|
36
|
+
"@types/lodash-es": "*",
|
|
37
37
|
"@testing-library/jest-dom": "*",
|
|
38
38
|
"@testing-library/react": "*",
|
|
39
39
|
"@testing-library/user-event": "*"
|