@faasjs/ant-design 0.0.3-beta.4 → 0.0.3-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -10
- package/dist/index.mjs +22 -11
- package/package.json +2 -2
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
|
@@ -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) {
|
|
@@ -425,7 +425,7 @@ function FormItem(props) {
|
|
|
425
425
|
};
|
|
426
426
|
delete propsCopy.if;
|
|
427
427
|
}
|
|
428
|
-
setComputedProps(processProps(propsCopy,
|
|
428
|
+
setComputedProps(processProps(propsCopy, common2));
|
|
429
429
|
}, [props]);
|
|
430
430
|
if (!computedProps)
|
|
431
431
|
return null;
|
|
@@ -672,7 +672,7 @@ function FormItem(props) {
|
|
|
672
672
|
danger: true,
|
|
673
673
|
type: "link",
|
|
674
674
|
onClick: () => remove(field.name),
|
|
675
|
-
children:
|
|
675
|
+
children: common2.delete
|
|
676
676
|
})
|
|
677
677
|
]
|
|
678
678
|
})
|
|
@@ -697,7 +697,7 @@ function FormItem(props) {
|
|
|
697
697
|
onClick: () => add(),
|
|
698
698
|
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
|
|
699
699
|
children: [
|
|
700
|
-
|
|
700
|
+
common2.add,
|
|
701
701
|
" ",
|
|
702
702
|
computedProps.label
|
|
703
703
|
]
|
|
@@ -732,11 +732,19 @@ function Form(props) {
|
|
|
732
732
|
form
|
|
733
733
|
};
|
|
734
734
|
if (propsCopy.initialValues) {
|
|
735
|
-
for (const key in propsCopy.initialValues)
|
|
735
|
+
for (const key in propsCopy.initialValues) {
|
|
736
736
|
propsCopy.initialValues[key] = transferValue(
|
|
737
|
-
(_a2 = propsCopy.items.find((
|
|
737
|
+
(_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
|
|
738
738
|
propsCopy.initialValues[key]
|
|
739
739
|
);
|
|
740
|
+
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
741
|
+
if (item == null ? void 0 : item.if)
|
|
742
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
743
|
+
}
|
|
744
|
+
for (const item of propsCopy.items) {
|
|
745
|
+
if (item.if)
|
|
746
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
747
|
+
}
|
|
740
748
|
setInitialValues(propsCopy.initialValues);
|
|
741
749
|
delete propsCopy.initialValues;
|
|
742
750
|
}
|
|
@@ -773,6 +781,7 @@ function Form(props) {
|
|
|
773
781
|
setComputedProps(propsCopy);
|
|
774
782
|
}, [props]);
|
|
775
783
|
const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
|
|
784
|
+
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
776
785
|
if (props.onValuesChange) {
|
|
777
786
|
props.onValuesChange(changedValues, allValues);
|
|
778
787
|
}
|
|
@@ -787,6 +796,7 @@ function Form(props) {
|
|
|
787
796
|
(0, import_react8.useEffect)(() => {
|
|
788
797
|
if (!initialValues)
|
|
789
798
|
return;
|
|
799
|
+
console.debug("Form:initialValues", initialValues);
|
|
790
800
|
form.setFieldsValue(initialValues);
|
|
791
801
|
setInitialValues(null);
|
|
792
802
|
}, [computedProps]);
|
|
@@ -797,7 +807,7 @@ function Form(props) {
|
|
|
797
807
|
onValuesChange,
|
|
798
808
|
children: [
|
|
799
809
|
computedProps.beforeItems,
|
|
800
|
-
(_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
|
|
810
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => (0, import_react8.isValidElement)(item) ? item : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
|
|
801
811
|
...item,
|
|
802
812
|
extendTypes
|
|
803
813
|
}, item.id)),
|
package/dist/index.mjs
CHANGED
|
@@ -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
|
|
@@ -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) {
|
|
@@ -410,7 +411,7 @@ function FormItem(props) {
|
|
|
410
411
|
};
|
|
411
412
|
delete propsCopy.if;
|
|
412
413
|
}
|
|
413
|
-
setComputedProps(processProps(propsCopy,
|
|
414
|
+
setComputedProps(processProps(propsCopy, common2));
|
|
414
415
|
}, [props]);
|
|
415
416
|
if (!computedProps)
|
|
416
417
|
return null;
|
|
@@ -657,7 +658,7 @@ function FormItem(props) {
|
|
|
657
658
|
danger: true,
|
|
658
659
|
type: "link",
|
|
659
660
|
onClick: () => remove(field.name),
|
|
660
|
-
children:
|
|
661
|
+
children: common2.delete
|
|
661
662
|
})
|
|
662
663
|
]
|
|
663
664
|
})
|
|
@@ -682,7 +683,7 @@ function FormItem(props) {
|
|
|
682
683
|
onClick: () => add(),
|
|
683
684
|
icon: /* @__PURE__ */ jsx5(PlusOutlined, {}),
|
|
684
685
|
children: [
|
|
685
|
-
|
|
686
|
+
common2.add,
|
|
686
687
|
" ",
|
|
687
688
|
computedProps.label
|
|
688
689
|
]
|
|
@@ -717,11 +718,19 @@ function Form(props) {
|
|
|
717
718
|
form
|
|
718
719
|
};
|
|
719
720
|
if (propsCopy.initialValues) {
|
|
720
|
-
for (const key in propsCopy.initialValues)
|
|
721
|
+
for (const key in propsCopy.initialValues) {
|
|
721
722
|
propsCopy.initialValues[key] = transferValue(
|
|
722
|
-
(_a2 = propsCopy.items.find((
|
|
723
|
+
(_a2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _a2.type,
|
|
723
724
|
propsCopy.initialValues[key]
|
|
724
725
|
);
|
|
726
|
+
const item = propsCopy.items.find((item2) => item2.id === key);
|
|
727
|
+
if (item == null ? void 0 : item.if)
|
|
728
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
729
|
+
}
|
|
730
|
+
for (const item of propsCopy.items) {
|
|
731
|
+
if (item.if)
|
|
732
|
+
item.hidden = !item.if(propsCopy.initialValues);
|
|
733
|
+
}
|
|
725
734
|
setInitialValues(propsCopy.initialValues);
|
|
726
735
|
delete propsCopy.initialValues;
|
|
727
736
|
}
|
|
@@ -758,6 +767,7 @@ function Form(props) {
|
|
|
758
767
|
setComputedProps(propsCopy);
|
|
759
768
|
}, [props]);
|
|
760
769
|
const onValuesChange = useCallback((changedValues, allValues) => {
|
|
770
|
+
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
761
771
|
if (props.onValuesChange) {
|
|
762
772
|
props.onValuesChange(changedValues, allValues);
|
|
763
773
|
}
|
|
@@ -772,6 +782,7 @@ function Form(props) {
|
|
|
772
782
|
useEffect4(() => {
|
|
773
783
|
if (!initialValues)
|
|
774
784
|
return;
|
|
785
|
+
console.debug("Form:initialValues", initialValues);
|
|
775
786
|
form.setFieldsValue(initialValues);
|
|
776
787
|
setInitialValues(null);
|
|
777
788
|
}, [computedProps]);
|
|
@@ -782,7 +793,7 @@ function Form(props) {
|
|
|
782
793
|
onValuesChange,
|
|
783
794
|
children: [
|
|
784
795
|
computedProps.beforeItems,
|
|
785
|
-
(_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ jsx6(FormItem, {
|
|
796
|
+
(_a = computedProps.items) == null ? void 0 : _a.map((item) => isValidElement(item) ? item : /* @__PURE__ */ jsx6(FormItem, {
|
|
786
797
|
...item,
|
|
787
798
|
extendTypes
|
|
788
799
|
}, item.id)),
|
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.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lodash-es": "*",
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*",
|
|
31
|
-
"@faasjs/react": "^0.0.3-beta.
|
|
31
|
+
"@faasjs/react": "^0.0.3-beta.6",
|
|
32
32
|
"react-router-dom": "*",
|
|
33
33
|
"dayjs": "*"
|
|
34
34
|
},
|