x-ui-design 0.6.21 → 0.6.22
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.esm.js +23 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Form.tsx +17 -4
- package/lib/components/Form/Item/Item.tsx +10 -1
- package/lib/hooks/useForm.ts +1 -2
- package/package.json +1 -1
- package/src/app/page.tsx +3 -1
package/dist/index.js
CHANGED
|
@@ -832,8 +832,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
832
832
|
}
|
|
833
833
|
function subscribeToFields(names, callback) {
|
|
834
834
|
const fieldCallbacks = names.map(name => subscribeToField(name, () => {
|
|
835
|
-
|
|
836
|
-
callback(updatedValues);
|
|
835
|
+
callback(getFieldsValue(names));
|
|
837
836
|
}));
|
|
838
837
|
return () => {
|
|
839
838
|
fieldCallbacks.forEach(unsubscribe => unsubscribe());
|
|
@@ -1072,6 +1071,7 @@ const FormItemChildComponent = /*#__PURE__*/React.memo(({
|
|
|
1072
1071
|
getFieldsValue,
|
|
1073
1072
|
getFieldValue,
|
|
1074
1073
|
setFieldValue,
|
|
1074
|
+
subscribeToField,
|
|
1075
1075
|
subscribeToFields,
|
|
1076
1076
|
validateFields
|
|
1077
1077
|
} = formContext || {};
|
|
@@ -1081,11 +1081,17 @@ const FormItemChildComponent = /*#__PURE__*/React.memo(({
|
|
|
1081
1081
|
onChange,
|
|
1082
1082
|
value
|
|
1083
1083
|
} = child.props;
|
|
1084
|
-
const fieldValue = value ?? getFieldValue?.(name) ?? initialValue;
|
|
1084
|
+
const [fieldValue, _setFieldValue] = React.useState(value ?? getFieldValue?.(name) ?? initialValue);
|
|
1085
1085
|
React.useEffect(() => {
|
|
1086
1086
|
if (initialValue) {
|
|
1087
1087
|
setFieldValue?.(name, initialValue);
|
|
1088
1088
|
}
|
|
1089
|
+
const unsubscribe = subscribeToField?.(name, value => {
|
|
1090
|
+
_setFieldValue(value);
|
|
1091
|
+
});
|
|
1092
|
+
return () => {
|
|
1093
|
+
unsubscribe?.();
|
|
1094
|
+
};
|
|
1089
1095
|
}, []);
|
|
1090
1096
|
React.useEffect(() => {
|
|
1091
1097
|
if (name && dependencies.length > 0) {
|
|
@@ -1189,6 +1195,7 @@ const Form$1 = ({
|
|
|
1189
1195
|
}
|
|
1190
1196
|
};
|
|
1191
1197
|
const childrenList = React.useMemo(() => flattenChildren(children), [children]);
|
|
1198
|
+
const formClassName = React.useMemo(() => `${prefixCls} ${className}`.trim(), [prefixCls, className]);
|
|
1192
1199
|
React.useEffect(() => {
|
|
1193
1200
|
if (onFieldsChange) {
|
|
1194
1201
|
formInstance.setOnFieldsChange?.(onFieldsChange);
|
|
@@ -1220,15 +1227,25 @@ const Form$1 = ({
|
|
|
1220
1227
|
size: childProps.size || rest.size,
|
|
1221
1228
|
layout: childProps.layout || layout
|
|
1222
1229
|
}));
|
|
1223
|
-
}, [rest.size, layout
|
|
1224
|
-
console.info(
|
|
1230
|
+
}, [rest.size, layout]);
|
|
1231
|
+
console.info({
|
|
1232
|
+
children,
|
|
1233
|
+
form,
|
|
1234
|
+
style,
|
|
1235
|
+
prefixCls,
|
|
1236
|
+
className,
|
|
1237
|
+
initialValues,
|
|
1238
|
+
layout,
|
|
1239
|
+
scrollToFirstError,
|
|
1240
|
+
...rest
|
|
1241
|
+
});
|
|
1225
1242
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
1226
1243
|
value: formInstance
|
|
1227
1244
|
}, /*#__PURE__*/React.createElement("form", {
|
|
1228
1245
|
style: style,
|
|
1229
1246
|
ref: formRef,
|
|
1230
1247
|
onSubmit: handleSubmit,
|
|
1231
|
-
className:
|
|
1248
|
+
className: formClassName
|
|
1232
1249
|
}, React.Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))));
|
|
1233
1250
|
};
|
|
1234
1251
|
Form$1.Item = FormItem$1;
|