@redneckz/wildless-cms-uni-blocks 0.14.896 → 0.14.897
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/bundle/bundle.umd.js +29 -2
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/hooks/useForm/useForm.d.ts +2 -0
- package/bundle/ui-kit/FormField/RefWrapper.d.ts +7 -0
- package/dist/hooks/useForm/useForm.d.ts +2 -0
- package/dist/hooks/useForm/useForm.js +17 -0
- package/dist/hooks/useForm/useForm.js.map +1 -1
- package/dist/ui-kit/FormField/RefWrapper.d.ts +7 -0
- package/dist/ui-kit/FormField/RefWrapper.js +16 -0
- package/dist/ui-kit/FormField/RefWrapper.js.map +1 -0
- package/dist/ui-kit/FormField/getField.js +2 -1
- package/dist/ui-kit/FormField/getField.js.map +1 -1
- package/lib/components/OfficesAtmsMap/OfficesAtmsMapLayout.d.ts +1 -1
- package/lib/hooks/useForm/useForm.d.ts +2 -0
- package/lib/hooks/useForm/useForm.js +17 -0
- package/lib/hooks/useForm/useForm.js.map +1 -1
- package/lib/ui-kit/FormField/RefWrapper.d.ts +7 -0
- package/lib/ui-kit/FormField/RefWrapper.js +14 -0
- package/lib/ui-kit/FormField/RefWrapper.js.map +1 -0
- package/lib/ui-kit/FormField/getField.js +2 -1
- package/lib/ui-kit/FormField/getField.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +29 -2
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/hooks/useForm/useForm.d.ts +2 -0
- package/mobile/bundle/ui-kit/FormField/RefWrapper.d.ts +7 -0
- package/mobile/dist/hooks/useForm/useForm.d.ts +2 -0
- package/mobile/dist/hooks/useForm/useForm.js +17 -0
- package/mobile/dist/hooks/useForm/useForm.js.map +1 -1
- package/mobile/dist/ui-kit/FormField/RefWrapper.d.ts +7 -0
- package/mobile/dist/ui-kit/FormField/RefWrapper.js +16 -0
- package/mobile/dist/ui-kit/FormField/RefWrapper.js.map +1 -0
- package/mobile/dist/ui-kit/FormField/getField.js +2 -1
- package/mobile/dist/ui-kit/FormField/getField.js.map +1 -1
- package/mobile/lib/hooks/useForm/useForm.d.ts +2 -0
- package/mobile/lib/hooks/useForm/useForm.js +17 -0
- package/mobile/lib/hooks/useForm/useForm.js.map +1 -1
- package/mobile/lib/ui-kit/FormField/RefWrapper.d.ts +7 -0
- package/mobile/lib/ui-kit/FormField/RefWrapper.js +14 -0
- package/mobile/lib/ui-kit/FormField/RefWrapper.js.map +1 -0
- package/mobile/lib/ui-kit/FormField/getField.js +2 -1
- package/mobile/lib/ui-kit/FormField/getField.js.map +1 -1
- package/mobile/src/hooks/useForm/useForm.ts +31 -2
- package/mobile/src/ui-kit/FormField/RefWrapper.tsx +20 -0
- package/mobile/src/ui-kit/FormField/getField.tsx +3 -2
- package/package.json +1 -1
- package/src/hooks/useForm/useForm.ts +31 -2
- package/src/ui-kit/FormField/RefWrapper.tsx +20 -0
- package/src/ui-kit/FormField/getField.tsx +3 -2
package/bundle/bundle.umd.js
CHANGED
|
@@ -1244,6 +1244,7 @@
|
|
|
1244
1244
|
|
|
1245
1245
|
function useForm(initialState, { resetOnSubmit, formValidator, normalizer, onChange, onSubmit } = {}) {
|
|
1246
1246
|
const [formState, setFormState] = useNormalizedFormState(initialState, normalizer, onChange);
|
|
1247
|
+
const fieldRefs = useRef(getRefsObject(initialState));
|
|
1247
1248
|
const [isDirtyForm, { setTrue: markAsDirty, setFalse: markAsClean }] = useBool(false);
|
|
1248
1249
|
const dirtyFieldsMap = useRef({});
|
|
1249
1250
|
const [fieldValidatorsMap, { isValid, errors }] = useFormValidator(formState, formValidator);
|
|
@@ -1254,6 +1255,12 @@
|
|
|
1254
1255
|
const fieldValidator = options?.validator ?? fieldValidatorsMap[fieldName];
|
|
1255
1256
|
const fieldErrors = isDirty && fieldValidator ? fieldValidator(value) : [];
|
|
1256
1257
|
return {
|
|
1258
|
+
setFieldRef: (_) => {
|
|
1259
|
+
if (fieldRefs.current) {
|
|
1260
|
+
fieldRefs.current[fieldName] = _;
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
fieldRef: fieldRefs.current?.[fieldName],
|
|
1257
1264
|
value: format ? format(value) : value,
|
|
1258
1265
|
isDirty,
|
|
1259
1266
|
errors: fieldValidator && fieldErrors,
|
|
@@ -1283,11 +1290,21 @@
|
|
|
1283
1290
|
onSubmit?.(formState, ev);
|
|
1284
1291
|
}
|
|
1285
1292
|
else {
|
|
1293
|
+
const errorFieldName = getErrorFieldName(formState, fieldValidatorsMap);
|
|
1286
1294
|
markAsDirty();
|
|
1295
|
+
field(errorFieldName).fieldRef?.scrollIntoView({ behavior: 'smooth' });
|
|
1287
1296
|
}
|
|
1288
1297
|
}, [resetOnSubmit, formState, isValid, reset, onSubmit]);
|
|
1289
1298
|
return [formState, { errors, field, update, reset, onSubmit: handleSubmit }];
|
|
1290
1299
|
}
|
|
1300
|
+
const getRefsObject = (initialState) => Object.keys(initialState).reduce((acc, key) => ({ ...acc, [key]: null }), {});
|
|
1301
|
+
const getErrorFieldName = (formState, fieldValidatorsMap = {}) => {
|
|
1302
|
+
const [errorFieldName = ''] = Object.entries(formState).find(([fieldName, value]) => {
|
|
1303
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1304
|
+
return fieldValidatorsMap[fieldName]?.(value)?.length;
|
|
1305
|
+
}) ?? [];
|
|
1306
|
+
return errorFieldName;
|
|
1307
|
+
};
|
|
1291
1308
|
|
|
1292
1309
|
function copy(source, target) {
|
|
1293
1310
|
for (const [k, v] of source.entries()) {
|
|
@@ -2939,6 +2956,16 @@
|
|
|
2939
2956
|
|
|
2940
2957
|
const ConsentToReceiveMaterialsField = JSX(({ field, input }) => (jsx(Checkbox, { text: "\u0421\u043E\u0433\u043B\u0430\u0441\u0435\u043D \u043D\u0430 \u043F\u043E\u043B\u0443\u0447\u0435\u043D\u0438\u0435 \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u043E\u043D\u043D\u044B\u0445 \u0438 \u0430\u043D\u0430\u043B\u0438\u0442\u0438\u0447\u0435\u0441\u043A\u0438\u0445 \u043C\u0430\u0442\u0435\u0440\u0438\u0430\u043B\u043E\u0432 \u043F\u043E \u044D\u043B\u0435\u043A\u0442\u0440\u043E\u043D\u043D\u043E\u0439 \u043F\u043E\u0447\u0442\u0435", ...field(input?.name ?? '') })));
|
|
2941
2958
|
|
|
2959
|
+
const RefWrapper = JSX(({ onFieldRef = noop, children }) => {
|
|
2960
|
+
const ref = useRef(null);
|
|
2961
|
+
useEffect(() => {
|
|
2962
|
+
if (ref.current) {
|
|
2963
|
+
onFieldRef(ref.current);
|
|
2964
|
+
}
|
|
2965
|
+
}, []);
|
|
2966
|
+
return jsx("div", { ref: ref, children: children });
|
|
2967
|
+
});
|
|
2968
|
+
|
|
2942
2969
|
function shouldRenderField({ input, field, }) {
|
|
2943
2970
|
const { condition } = input;
|
|
2944
2971
|
const { value } = field(condition?.name || '');
|
|
@@ -2999,7 +3026,7 @@
|
|
|
2999
3026
|
...externalInputs,
|
|
3000
3027
|
};
|
|
3001
3028
|
const Component = fieldsRegister[String(input.name)];
|
|
3002
|
-
return shouldRenderField({ input, field }) && Component ? (jsx(
|
|
3029
|
+
return shouldRenderField({ input, field }) && Component ? (jsx(RefWrapper, { onFieldRef: field(input.name ?? '').setFieldRef, children: jsx(Component, { field: field, input: input, params: params }) }, String(i))) : null;
|
|
3003
3030
|
};
|
|
3004
3031
|
|
|
3005
3032
|
const inputColumnStyles = (column) => column === 2 ? '@xl:grid-cols-2 gap-x-m' : '@xl:grid-cols-1 gap-x-0';
|
|
@@ -11671,7 +11698,7 @@
|
|
|
11671
11698
|
slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
|
|
11672
11699
|
});
|
|
11673
11700
|
|
|
11674
|
-
const packageVersion = "0.14.
|
|
11701
|
+
const packageVersion = "0.14.896";
|
|
11675
11702
|
|
|
11676
11703
|
exports.Blocks = Blocks;
|
|
11677
11704
|
exports.ContentPage = ContentPage;
|