Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
'use client';
'use strict';
function filterErrors(errors) {
if (errors === null || typeof errors !== "object") {
return {};
}
return Object.keys(errors).reduce((acc, key) => {
const errorValue = errors[key];
if (errorValue !== void 0 && errorValue !== null && errorValue !== false) {
acc[key] = errorValue;
}
return acc;
}, {});
}
exports.filterErrors = filterErrors;
//# sourceMappingURL=filter-errors.cjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"filter-errors.cjs","sources":["../../../../src/hooks/use-form-errors/filter-errors/filter-errors.ts"],"sourcesContent":["import type { FormErrors } from '../../../types';\n\nexport function filterErrors(errors: FormErrors): FormErrors {\n if (errors === null || typeof errors !== 'object') {\n return {};\n }\n\n return Object.keys(errors).reduce<FormErrors>((acc, key) => {\n const errorValue = errors[key];\n\n if (errorValue !== undefined && errorValue !== null && errorValue !== false) {\n acc[key] = errorValue;\n }\n\n return acc;\n }, {});\n}\n"],"names":[],"mappings":";;;AAEO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgC,CAAA;AAC3D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,MAAA,CAAA,CAAA,CAAA,CAAA,CAAW,CAAA,CAAA,CAAA,CAAA,IAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,CAAA;AACjD,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAC,CAAA;AAAA,CAAA,CACV,CAAA;AAEA,CAAA,CAAA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+1,51 @@
'use client';
'use strict';
var react = require('react');
var filterErrors = require('./filter-errors/filter-errors.cjs');
function useFormErrors(initialErrors) {
const [errorsState, setErrorsState] = react.useState(filterErrors.filterErrors(initialErrors));
const errorsRef = react.useRef(errorsState);
const setErrors = react.useCallback((errors) => {
setErrorsState((current) => {
const newErrors = filterErrors.filterErrors(typeof errors === "function" ? errors(current) : errors);
errorsRef.current = newErrors;
return newErrors;
});
}, []);
const clearErrors = react.useCallback(() => setErrors({}), []);
const clearFieldError = react.useCallback(
(path) => {
if (errorsRef.current[path] === void 0) {
return;
}
setErrors((current) => {
const errors = { ...current };
delete errors[path];
return errors;
});
},
[errorsState]
);
const setFieldError = react.useCallback(
(path, error) => {
if (error == null || error === false) {
clearFieldError(path);
} else if (errorsRef.current[path] !== error) {
setErrors((current) => ({ ...current, [path]: error }));
}
},
[errorsState]
);
return {
errorsState,
setErrors,
clearErrors,
setFieldError,
clearFieldError
};
}
exports.useFormErrors = useFormErrors;
//# sourceMappingURL=use-form-errors.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,53 @@
'use client';
'use strict';
var react = require('react');
var changeErrorIndices = require('../../lists/change-error-indices.cjs');
var reorderErrors = require('../../lists/reorder-errors.cjs');
require('klona/full');
var reorderPath = require('../../paths/reorder-path.cjs');
var insertPath = require('../../paths/insert-path.cjs');
var removePath = require('../../paths/remove-path.cjs');
var replacePath = require('../../paths/replace-path.cjs');
function useFormList({
$values,
$errors,
$status
}) {
const reorderListItem = react.useCallback((path, payload) => {
$status.clearFieldDirty(path);
$errors.setErrors((errs) => reorderErrors.reorderErrors(path, payload, errs));
$values.setValues({
values: reorderPath.reorderPath(path, payload, $values.refValues.current),
updateState: true
});
}, []);
const removeListItem = react.useCallback((path, index) => {
$status.clearFieldDirty(path);
$errors.setErrors((errs) => changeErrorIndices.changeErrorIndices(path, index, errs, -1));
$values.setValues({
values: removePath.removePath(path, index, $values.refValues.current),
updateState: true
});
}, []);
const insertListItem = react.useCallback((path, item, index) => {
$status.clearFieldDirty(path);
$errors.setErrors((errs) => changeErrorIndices.changeErrorIndices(path, index, errs, 1));
$values.setValues({
values: insertPath.insertPath(path, item, index, $values.refValues.current),
updateState: true
});
}, []);
const replaceListItem = react.useCallback((path, index, item) => {
$status.clearFieldDirty(path);
$values.setValues({
values: replacePath.replacePath(path, item, index, $values.refValues.current),
updateState: true
});
}, []);
return { reorderListItem, removeListItem, insertListItem, replaceListItem };
}
exports.useFormList = useFormList;
//# sourceMappingURL=use-form-list.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,130 @@
'use client';
'use strict';
var react = require('react');
var isEqual = require('fast-deep-equal');
var getStatus = require('../../get-status/get-status.cjs');
var clearListState = require('../../lists/clear-list-state.cjs');
var getPath = require('../../paths/get-path.cjs');
require('klona/full');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
function useFormStatus({
initialDirty,
initialTouched,
mode,
$values
}) {
const [touchedState, setTouchedState] = react.useState(initialTouched);
const [dirtyState, setDirtyState] = react.useState(initialDirty);
const touchedRef = react.useRef(initialTouched);
const dirtyRef = react.useRef(initialDirty);
const setTouched = react.useCallback((values) => {
const resolvedValues = typeof values === "function" ? values(touchedRef.current) : values;
touchedRef.current = resolvedValues;
if (mode === "controlled") {
setTouchedState(resolvedValues);
}
}, []);
const setDirty = react.useCallback(
(values, forceUpdate = false) => {
const resolvedValues = typeof values === "function" ? values(dirtyRef.current) : values;
dirtyRef.current = resolvedValues;
if (mode === "controlled" || forceUpdate) {
setDirtyState(resolvedValues);
}
},
[]
);
const resetTouched = react.useCallback(() => setTouched({}), []);
const resetDirty = react.useCallback((values) => {
const newSnapshot = values ? { ...$values.refValues.current, ...values } : $values.refValues.current;
$values.setValuesSnapshot(newSnapshot);
setDirty({});
}, []);
const setFieldTouched = react.useCallback((path, touched) => {
setTouched((currentTouched) => {
if (getStatus.getStatus(currentTouched, path) === touched) {
return currentTouched;
}
return { ...currentTouched, [path]: touched };
});
}, []);
const setFieldDirty = react.useCallback((path, dirty, forceUpdate) => {
setDirty((currentDirty) => {
if (getStatus.getStatus(currentDirty, path) === dirty) {
return currentDirty;
}
return { ...currentDirty, [path]: dirty };
}, forceUpdate);
}, []);
const setCalculatedFieldDirty = react.useCallback((path, value) => {
const currentDirty = getStatus.getStatus(dirtyRef.current, path);
const dirty = !isEqual__default.default(getPath.getPath(path, $values.getValuesSnapshot()), value);
const clearedState = clearListState.clearListState(path, dirtyRef.current);
clearedState[path] = dirty;
setDirty(clearedState, currentDirty !== dirty);
}, []);
const isTouched = react.useCallback(
(path) => getStatus.getStatus(touchedRef.current, path),
[]
);
const clearFieldDirty = react.useCallback(
(path) => setDirty((current) => {
if (typeof path !== "string") {
return current;
}
const result = clearListState.clearListState(path, current);
delete result[path];
if (isEqual__default.default(result, current)) {
return current;
}
return result;
}),
[]
);
const isDirty = react.useCallback((path) => {
if (path) {
const overriddenValue = getPath.getPath(path, dirtyRef.current);
if (typeof overriddenValue === "boolean") {
return overriddenValue;
}
const sliceOfValues = getPath.getPath(path, $values.refValues.current);
const sliceOfInitialValues = getPath.getPath(path, $values.valuesSnapshot.current);
return !isEqual__default.default(sliceOfValues, sliceOfInitialValues);
}
const isOverridden = Object.keys(dirtyRef.current).length > 0;
if (isOverridden) {
return getStatus.getStatus(dirtyRef.current);
}
return !isEqual__default.default($values.refValues.current, $values.valuesSnapshot.current);
}, []);
const getDirty = react.useCallback(() => dirtyRef.current, []);
const getTouched = react.useCallback(() => touchedRef.current, []);
return {
touchedState,
dirtyState,
touchedRef,
dirtyRef,
setTouched,
setDirty,
resetDirty,
resetTouched,
isTouched,
setFieldTouched,
setFieldDirty,
setTouchedState,
setDirtyState,
clearFieldDirty,
isDirty,
getDirty,
getTouched,
setCalculatedFieldDirty
};
}
exports.useFormStatus = useFormStatus;
//# sourceMappingURL=use-form-status.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,109 @@
'use client';
'use strict';
var react = require('react');
var getPath = require('../../paths/get-path.cjs');
var setPath = require('../../paths/set-path.cjs');
function useFormValues({
initialValues,
onValuesChange,
mode
}) {
const initialized = react.useRef(false);
const [stateValues, setStateValues] = react.useState(initialValues || {});
const refValues = react.useRef(stateValues);
const valuesSnapshot = react.useRef(stateValues);
const setValues = react.useCallback(
({
values,
subscribers,
updateState = true,
mergeWithPreviousValues = true
}) => {
const previousValues = refValues.current;
const resolvedValues = values instanceof Function ? values(refValues.current) : values;
const updatedValues = mergeWithPreviousValues ? { ...previousValues, ...resolvedValues } : resolvedValues;
refValues.current = updatedValues;
if (updateState) {
setStateValues(updatedValues);
if (mode === "uncontrolled") {
refValues.current = updatedValues;
}
}
onValuesChange?.(updatedValues, previousValues);
subscribers?.filter(Boolean).forEach((subscriber) => subscriber({ updatedValues, previousValues }));
},
[onValuesChange]
);
const setFieldValue = react.useCallback(
(payload) => {
const currentValue = getPath.getPath(payload.path, refValues.current);
const updatedValue = payload.value instanceof Function ? payload.value(currentValue) : payload.value;
if (currentValue !== updatedValue) {
const previousValues = refValues.current;
const updatedValues = setPath.setPath(payload.path, updatedValue, refValues.current);
setValues({ values: updatedValues, updateState: payload.updateState });
payload.subscribers?.filter(Boolean).forEach(
(subscriber) => subscriber({ path: payload.path, updatedValues, previousValues })
);
}
},
[setValues]
);
const setValuesSnapshot = react.useCallback((payload) => {
valuesSnapshot.current = payload;
}, []);
const initialize = react.useCallback(
(values, onInitialize) => {
if (!initialized.current) {
initialized.current = true;
setValues({ values, updateState: mode === "controlled" });
setValuesSnapshot(values);
onInitialize();
}
},
[setValues]
);
const resetValues = react.useCallback(() => {
setValues({
values: valuesSnapshot.current,
updateState: true,
mergeWithPreviousValues: false
});
}, [setValues]);
const getValues = react.useCallback(() => refValues.current, []);
const getValuesSnapshot = react.useCallback(() => valuesSnapshot.current, []);
const resetField = react.useCallback(
(path, subscribers) => {
const snapshotValue = getPath.getPath(path, valuesSnapshot.current);
if (typeof snapshotValue === "undefined") {
return;
}
setFieldValue({
path,
value: snapshotValue,
updateState: mode === "controlled",
subscribers
});
},
[setFieldValue, mode]
);
return {
initialized,
stateValues,
refValues,
valuesSnapshot,
setValues,
setFieldValue,
resetValues,
setValuesSnapshot,
initialize,
getValues,
getValuesSnapshot,
resetField
};
}
exports.useFormValues = useFormValues;
//# sourceMappingURL=use-form-values.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
'use client';
'use strict';
var react = require('react');
var getPath = require('../../paths/get-path.cjs');
require('klona/full');
function useFormWatch({
$status,
cascadeUpdates
}) {
const subscribers = react.useRef(
{}
);
const watch = react.useCallback((path, callback) => {
react.useEffect(() => {
subscribers.current[path] = subscribers.current[path] || [];
subscribers.current[path].push(callback);
return () => {
subscribers.current[path] = subscribers.current[path].filter((cb) => cb !== callback);
};
}, [callback]);
}, []);
const getFieldSubscribers = react.useCallback((path) => {
const result = subscribers.current[path]?.map(
(callback) => (input) => callback({
previousValue: getPath.getPath(path, input.previousValues),
value: getPath.getPath(path, input.updatedValues),
touched: $status.isTouched(path),
dirty: $status.isDirty(path)
})
) ?? [];
if (cascadeUpdates) {
for (const subscriptionKey in subscribers.current) {
if (subscriptionKey.startsWith(`${path}.`) || path.startsWith(`${subscriptionKey}.`)) {
result.push(
...subscribers.current[subscriptionKey].map(
(cb) => (input) => cb({
previousValue: getPath.getPath(subscriptionKey, input.previousValues),
value: getPath.getPath(subscriptionKey, input.updatedValues),
touched: $status.isTouched(subscriptionKey),
dirty: $status.isDirty(subscriptionKey)
})
)
);
}
}
}
return result;
}, []);
return {
subscribers,
watch,
getFieldSubscribers
};
}
exports.useFormWatch = useFormWatch;
//# sourceMappingURL=use-form-watch.cjs.map

File diff suppressed because one or more lines are too long