@undermuz/use-form
Version:
React library for build forms
108 lines (106 loc) • 2.97 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components/form-context.ts
var form_context_exports = {};
__export(form_context_exports, {
FormContext: () => FormContext,
defaultValidate: () => defaultValidate,
useFormContext: () => useFormContext
});
module.exports = __toCommonJS(form_context_exports);
var import_react = require("react");
var import_getInitialState = require("../useForm/getInitialState.cjs");
var import_reducer = require("../useForm/reducer.cjs");
var defaultValidate = ({ errors = {} }) => errors;
var DEF_VALUES = {
status: import_reducer.EnumFormStatus.Initial,
values: {},
isSending: false,
isCanceling: false,
isSuccess: false,
sendError: null,
tests: [],
validate: (_c) => true,
touched: [],
fields: [],
errors: {},
customErrors: {},
send: () => {
return Promise.resolve();
},
hasFormErrors(_c) {
return [true, {}];
},
isFormValid: (_c) => {
return true;
},
IsFormValid: (_c) => {
return true;
},
setValue: (_name, _value, _silent, _checkOnlyFilled, _type) => {
},
setTouchedByName: (_name, _value, _silent) => {
},
setTouched: (_newTouched, _silent, _checkOnlyFilled) => {
},
setValues: (_newValues, _silent, _checkOnlyFilled, _type) => {
},
getValues: () => {
return {};
},
setTests: (_newTests, _silent, _checkOnlyFilled) => {
},
setValidate: (_newValidate, _silent, _checkOnlyFilled) => {
},
setErrors: (_newErrors) => {
},
getErrors: () => {
return {};
},
setCustomErrors: (_newErrors) => {
},
setCustomErrorByName: (_name, _error) => {
},
store: {
getState: () => {
return (0, import_getInitialState.getInitialState)();
},
dispatch: (..._args) => {
}
},
dispatch: (..._args) => {
}
};
var FormContext = (0, import_react.createContext)(DEF_VALUES);
FormContext.displayName = "FormContext";
var useFormContext = () => {
const ctx = (0, import_react.useContext)(
FormContext
);
if (!ctx) {
throw new Error("You must wrap your component in form provider");
}
return ctx;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FormContext,
defaultValidate,
useFormContext
});