Socket
Socket
Sign inDemoInstall

@mantine/form

Package Overview
Dependencies
Maintainers
1
Versions
217
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mantine/form - npm Package Compare versions

Comparing version 7.0.0-alpha.21 to 7.0.0-alpha.22

28

cjs/Form/Form.js

@@ -42,15 +42,21 @@ 'use strict';

};
const Form = React.forwardRef((_a, ref) => {
var _b = _a, { form, onSubmit, onReset } = _b, others = __objRest(_b, ["form", "onSubmit", "onReset"]);
return /* @__PURE__ */ React__default.createElement("form", __spreadProps(__spreadValues({}, others), {
onSubmit: form.onSubmit(onSubmit),
onReset: (event) => {
onReset == null ? void 0 : onReset(event);
form.onReset(event);
},
ref
}));
});
const Form = React.forwardRef(
(_a, ref) => {
var _b = _a, { form, onSubmit, onReset } = _b, others = __objRest(_b, ["form", "onSubmit", "onReset"]);
return /* @__PURE__ */ React__default.createElement(
"form",
__spreadProps(__spreadValues({}, others), {
onSubmit: form.onSubmit(typeof onSubmit === "function" ? onSubmit : () => {
}),
onReset: (event) => {
onReset == null ? void 0 : onReset(event);
form.onReset(event);
},
ref
})
);
}
);
exports.Form = Form;
//# sourceMappingURL=Form.js.map

@@ -15,5 +15,3 @@ 'use strict';

function FormProvider({ form, children }) {
return /* @__PURE__ */ React__default.createElement(FormContext.Provider, {
value: form
}, children);
return /* @__PURE__ */ React__default.createElement(FormContext.Provider, { value: form }, children);
}

@@ -20,0 +18,0 @@ function useFormContext() {

@@ -0,1 +1,2 @@

'use client';
'use strict';

@@ -2,0 +3,0 @@

@@ -37,3 +37,3 @@ 'use strict';

const cloned = __spreadValues({}, clearedErrors);
const changedKeys = new Set();
const changedKeys = /* @__PURE__ */ new Set();
Object.entries(clearedErrors).filter(([key]) => {

@@ -50,3 +50,6 @@ if (!key.startsWith(`${pathString}.`)) {

const currIndex = getIndexFromKeyAfterPath(key, pathString);
const newKey = key.replace(`${pathString}.${currIndex}`, `${pathString}.${currIndex + change}`);
const newKey = key.replace(
`${pathString}.${currIndex}`,
`${pathString}.${currIndex + change}`
);
cloned[newKey] = value;

@@ -53,0 +56,0 @@ changedKeys.add(newKey);

@@ -13,3 +13,7 @@ 'use strict';

}
return setPath.setPath(path, currentValue.filter((_, itemIndex) => itemIndex !== index), values);
return setPath.setPath(
path,
currentValue.filter((_, itemIndex) => itemIndex !== index),
values
);
}

@@ -16,0 +20,0 @@

@@ -70,3 +70,6 @@ 'use strict';

};
const setErrors = React.useCallback((errs) => _setErrors((current) => filterErrors.filterErrors(typeof errs === "function" ? errs(current) : errs)), []);
const setErrors = React.useCallback(
(errs) => _setErrors((current) => filterErrors.filterErrors(typeof errs === "function" ? errs(current) : errs)),
[]
);
const clearErrors = React.useCallback(() => _setErrors({}), []);

@@ -80,19 +83,28 @@ const reset = React.useCallback(() => {

}, []);
const setFieldError = React.useCallback((path, error) => setErrors((current) => __spreadProps(__spreadValues({}, current), { [path]: error })), []);
const clearFieldError = React.useCallback((path) => setErrors((current) => {
if (typeof path !== "string") {
return current;
}
const clone = __spreadValues({}, current);
delete clone[path];
return clone;
}), []);
const clearFieldDirty = React.useCallback((path) => setDirty((current) => {
if (typeof path !== "string") {
return current;
}
const result = clearListState.clearListState(path, current);
delete result[path];
return result;
}), []);
const setFieldError = React.useCallback(
(path, error) => setErrors((current) => __spreadProps(__spreadValues({}, current), { [path]: error })),
[]
);
const clearFieldError = React.useCallback(
(path) => setErrors((current) => {
if (typeof path !== "string") {
return current;
}
const clone = __spreadValues({}, current);
delete clone[path];
return clone;
}),
[]
);
const clearFieldDirty = React.useCallback(
(path) => setDirty((current) => {
if (typeof path !== "string") {
return current;
}
const result = clearListState.clearListState(path, current);
delete result[path];
return result;
}),
[]
);
const setFieldValue = React.useCallback((path, value) => {

@@ -139,7 +151,10 @@ const shouldValidate = shouldValidateOnChange.shouldValidateOnChange(path, validateInputOnChange);

}, [values, rules]);
const validateField = React.useCallback((path) => {
const results = validateFieldValue.validateFieldValue(path, rules, values);
results.hasError ? setFieldError(path, results.error) : clearFieldError(path);
return results;
}, [values, rules]);
const validateField = React.useCallback(
(path) => {
const results = validateFieldValue.validateFieldValue(path, rules, values);
results.hasError ? setFieldError(path, results.error) : clearFieldError(path);
return results;
},
[values, rules]
);
const getInputProps = (path, { type = "input", withError = true, withFocus = true } = {}) => {

@@ -197,4 +212,10 @@ const onChange = getInputOnChange.getInputOnChange((value) => setFieldValue(path, value));

};
const isTouched = React.useCallback((path) => getStatus.getStatus(touched, path), [touched]);
const isValid = React.useCallback((path) => path ? !validateFieldValue.validateFieldValue(path, rules, values).hasError : !validateValues.validateValues(rules, values).hasErrors, [values, rules]);
const isTouched = React.useCallback(
(path) => getStatus.getStatus(touched, path),
[touched]
);
const isValid = React.useCallback(
(path) => path ? !validateFieldValue.validateFieldValue(path, rules, values).hasError : !validateValues.validateValues(rules, values).hasErrors,
[values, rules]
);
return {

@@ -201,0 +222,0 @@ values,

@@ -12,3 +12,5 @@ 'use strict';

const results = validateValues.validateValues(rules, values);
const pathInError = Object.keys(results.errors).find((errorKey) => path.split(".").every((pathPart, i) => pathPart === errorKey.split(".")[i]));
const pathInError = Object.keys(results.errors).find(
(errorKey) => path.split(".").every((pathPart, i) => pathPart === errorKey.split(".")[i])
);
return { hasError: !!pathInError, error: pathInError ? results.errors[pathInError] : null };

@@ -15,0 +17,0 @@ }

@@ -26,3 +26,5 @@ 'use strict';

arrayValidation = true;
value.forEach((_item, index) => validateRulesRecord(rule, values, `${rulePath}.${index}`, acc));
value.forEach(
(_item, index) => validateRulesRecord(rule, values, `${rulePath}.${index}`, acc)
);
}

@@ -29,0 +31,0 @@ if (typeof rule === "object" && typeof value === "object" && value !== null) {

@@ -34,15 +34,21 @@ import React, { forwardRef } from 'react';

};
const Form = forwardRef((_a, ref) => {
var _b = _a, { form, onSubmit, onReset } = _b, others = __objRest(_b, ["form", "onSubmit", "onReset"]);
return /* @__PURE__ */ React.createElement("form", __spreadProps(__spreadValues({}, others), {
onSubmit: form.onSubmit(onSubmit),
onReset: (event) => {
onReset == null ? void 0 : onReset(event);
form.onReset(event);
},
ref
}));
});
const Form = forwardRef(
(_a, ref) => {
var _b = _a, { form, onSubmit, onReset } = _b, others = __objRest(_b, ["form", "onSubmit", "onReset"]);
return /* @__PURE__ */ React.createElement(
"form",
__spreadProps(__spreadValues({}, others), {
onSubmit: form.onSubmit(typeof onSubmit === "function" ? onSubmit : () => {
}),
onReset: (event) => {
onReset == null ? void 0 : onReset(event);
form.onReset(event);
},
ref
})
);
}
);
export { Form };
//# sourceMappingURL=Form.js.map

@@ -7,5 +7,3 @@ import React, { createContext, useContext } from 'react';

function FormProvider({ form, children }) {
return /* @__PURE__ */ React.createElement(FormContext.Provider, {
value: form
}, children);
return /* @__PURE__ */ React.createElement(FormContext.Provider, { value: form }, children);
}

@@ -12,0 +10,0 @@ function useFormContext() {

@@ -0,1 +1,2 @@

'use client';
export { useForm } from './use-form.js';

@@ -2,0 +3,0 @@ export { createFormContext } from './FormProvider/FormProvider.js';

@@ -33,3 +33,3 @@ import { clearListState } from './clear-list-state.js';

const cloned = __spreadValues({}, clearedErrors);
const changedKeys = new Set();
const changedKeys = /* @__PURE__ */ new Set();
Object.entries(clearedErrors).filter(([key]) => {

@@ -46,3 +46,6 @@ if (!key.startsWith(`${pathString}.`)) {

const currIndex = getIndexFromKeyAfterPath(key, pathString);
const newKey = key.replace(`${pathString}.${currIndex}`, `${pathString}.${currIndex + change}`);
const newKey = key.replace(
`${pathString}.${currIndex}`,
`${pathString}.${currIndex + change}`
);
cloned[newKey] = value;

@@ -49,0 +52,0 @@ changedKeys.add(newKey);

@@ -9,3 +9,7 @@ import { getPath } from './get-path.js';

}
return setPath(path, currentValue.filter((_, itemIndex) => itemIndex !== index), values);
return setPath(
path,
currentValue.filter((_, itemIndex) => itemIndex !== index),
values
);
}

@@ -12,0 +16,0 @@

@@ -62,3 +62,6 @@ import { useState, useRef, useCallback } from 'react';

};
const setErrors = useCallback((errs) => _setErrors((current) => filterErrors(typeof errs === "function" ? errs(current) : errs)), []);
const setErrors = useCallback(
(errs) => _setErrors((current) => filterErrors(typeof errs === "function" ? errs(current) : errs)),
[]
);
const clearErrors = useCallback(() => _setErrors({}), []);

@@ -72,19 +75,28 @@ const reset = useCallback(() => {

}, []);
const setFieldError = useCallback((path, error) => setErrors((current) => __spreadProps(__spreadValues({}, current), { [path]: error })), []);
const clearFieldError = useCallback((path) => setErrors((current) => {
if (typeof path !== "string") {
return current;
}
const clone = __spreadValues({}, current);
delete clone[path];
return clone;
}), []);
const clearFieldDirty = useCallback((path) => setDirty((current) => {
if (typeof path !== "string") {
return current;
}
const result = clearListState(path, current);
delete result[path];
return result;
}), []);
const setFieldError = useCallback(
(path, error) => setErrors((current) => __spreadProps(__spreadValues({}, current), { [path]: error })),
[]
);
const clearFieldError = useCallback(
(path) => setErrors((current) => {
if (typeof path !== "string") {
return current;
}
const clone = __spreadValues({}, current);
delete clone[path];
return clone;
}),
[]
);
const clearFieldDirty = useCallback(
(path) => setDirty((current) => {
if (typeof path !== "string") {
return current;
}
const result = clearListState(path, current);
delete result[path];
return result;
}),
[]
);
const setFieldValue = useCallback((path, value) => {

@@ -131,7 +143,10 @@ const shouldValidate = shouldValidateOnChange(path, validateInputOnChange);

}, [values, rules]);
const validateField = useCallback((path) => {
const results = validateFieldValue(path, rules, values);
results.hasError ? setFieldError(path, results.error) : clearFieldError(path);
return results;
}, [values, rules]);
const validateField = useCallback(
(path) => {
const results = validateFieldValue(path, rules, values);
results.hasError ? setFieldError(path, results.error) : clearFieldError(path);
return results;
},
[values, rules]
);
const getInputProps = (path, { type = "input", withError = true, withFocus = true } = {}) => {

@@ -189,4 +204,10 @@ const onChange = getInputOnChange((value) => setFieldValue(path, value));

};
const isTouched = useCallback((path) => getStatus(touched, path), [touched]);
const isValid = useCallback((path) => path ? !validateFieldValue(path, rules, values).hasError : !validateValues(rules, values).hasErrors, [values, rules]);
const isTouched = useCallback(
(path) => getStatus(touched, path),
[touched]
);
const isValid = useCallback(
(path) => path ? !validateFieldValue(path, rules, values).hasError : !validateValues(rules, values).hasErrors,
[values, rules]
);
return {

@@ -193,0 +214,0 @@ values,

@@ -8,3 +8,5 @@ import { validateValues } from './validate-values.js';

const results = validateValues(rules, values);
const pathInError = Object.keys(results.errors).find((errorKey) => path.split(".").every((pathPart, i) => pathPart === errorKey.split(".")[i]));
const pathInError = Object.keys(results.errors).find(
(errorKey) => path.split(".").every((pathPart, i) => pathPart === errorKey.split(".")[i])
);
return { hasError: !!pathInError, error: pathInError ? results.errors[pathInError] : null };

@@ -11,0 +13,0 @@ }

@@ -22,3 +22,5 @@ import { filterErrors } from '../filter-errors/filter-errors.js';

arrayValidation = true;
value.forEach((_item, index) => validateRulesRecord(rule, values, `${rulePath}.${index}`, acc));
value.forEach(
(_item, index) => validateRulesRecord(rule, values, `${rulePath}.${index}`, acc)
);
}

@@ -25,0 +27,0 @@ if (typeof rule === "object" && typeof value === "object" && value !== null) {

{
"name": "@mantine/form",
"description": "Mantine form management library",
"version": "7.0.0-alpha.21",
"version": "7.0.0-alpha.22",
"types": "./lib/index.d.ts",

@@ -6,0 +6,0 @@ "exports": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc