import "/_nuxt/node_modules/.cache/vite/client/deps/chunk-V4OQ3NZ2.js?v=e4f18c29"; // node_modules/vee-validate/dist/vee-validate.esm.js import { getCurrentInstance, inject, warn as warn$1, ref, unref, computed, reactive, watch, onUnmounted, nextTick, onMounted, provide, isRef, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, watchEffect, markRaw } from "/_nuxt/node_modules/vue/dist/vue.runtime.esm-bundler.js?v=e4f18c29"; import { setupDevtoolsPlugin } from "/_nuxt/node_modules/@vue/devtools-api/lib/esm/index.js?v=e4f18c29"; function isCallable(fn) { return typeof fn === "function"; } function isNullOrUndefined(value) { return value === null || value === void 0; } var isObject = (obj) => obj !== null && !!obj && typeof obj === "object" && !Array.isArray(obj); function isIndex(value) { return Number(value) >= 0; } function toNumber(value) { const n = parseFloat(value); return isNaN(n) ? value : n; } var RULES = {}; function defineRule(id, validator) { guardExtend(id, validator); RULES[id] = validator; } function resolveRule(id) { return RULES[id]; } function guardExtend(id, validator) { if (isCallable(validator)) { return; } throw new Error(`Extension Error: The validator '${id}' must be a function.`); } var FormContextKey = Symbol("vee-validate-form"); var FieldContextKey = Symbol("vee-validate-field-instance"); var IS_ABSENT = Symbol("Default empty value"); var isClient = typeof window !== "undefined"; function isLocator(value) { return isCallable(value) && !!value.__locatorRef; } function isYupValidator(value) { return !!value && isCallable(value.validate); } function hasCheckedAttr(type) { return type === "checkbox" || type === "radio"; } function isContainerValue(value) { return isObject(value) || Array.isArray(value); } function isEmptyContainer(value) { if (Array.isArray(value)) { return value.length === 0; } return isObject(value) && Object.keys(value).length === 0; } function isNotNestedPath(path) { return /^\[.+\]$/i.test(path); } function isNativeMultiSelect(el) { return isNativeSelect(el) && el.multiple; } function isNativeSelect(el) { return el.tagName === "SELECT"; } function isNativeMultiSelectNode(tag, attrs) { const hasTruthyBindingValue = ![false, null, void 0, 0].includes(attrs.multiple) && !Number.isNaN(attrs.multiple); return tag === "select" && "multiple" in attrs && hasTruthyBindingValue; } function shouldHaveValueBinding(tag, attrs) { return !isNativeMultiSelectNode(tag, attrs) && attrs.type !== "file" && !hasCheckedAttr(attrs.type); } function isFormSubmitEvent(evt) { return isEvent(evt) && evt.target && "submit" in evt.target; } function isEvent(evt) { if (!evt) { return false; } if (typeof Event !== "undefined" && isCallable(Event) && evt instanceof Event) { return true; } if (evt && evt.srcElement) { return true; } return false; } function isPropPresent(obj, prop) { return prop in obj && obj[prop] !== IS_ABSENT; } function isEqual(a, b) { if (a === b) return true; if (a && b && typeof a === "object" && typeof b === "object") { if (a.constructor !== b.constructor) return false; var length, i, keys; if (Array.isArray(a)) { length = a.length; if (length != b.length) return false; for (i = length; i-- !== 0; ) if (!isEqual(a[i], b[i])) return false; return true; } if (a instanceof Map && b instanceof Map) { if (a.size !== b.size) return false; for (i of a.entries()) if (!b.has(i[0])) return false; for (i of a.entries()) if (!isEqual(i[1], b.get(i[0]))) return false; return true; } if (isFile(a) && isFile(b)) { if (a.size !== b.size) return false; if (a.name !== b.name) return false; if (a.lastModified !== b.lastModified) return false; if (a.type !== b.type) return false; return true; } if (a instanceof Set && b instanceof Set) { if (a.size !== b.size) return false; for (i of a.entries()) if (!b.has(i[0])) return false; return true; } if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) { length = a.length; if (length != b.length) return false; for (i = length; i-- !== 0; ) if (a[i] !== b[i]) return false; return true; } if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; for (i = length; i-- !== 0; ) { var key = keys[i]; if (!isEqual(a[key], b[key])) return false; } return true; } return a !== a && b !== b; } function isFile(a) { if (!isClient) { return false; } return a instanceof File; } var fastDeepEqual = function equal(a, b) { if (a === b) return true; if (a && b && typeof a == "object" && typeof b == "object") { if (a.constructor !== b.constructor) return false; var length, i, keys; if (Array.isArray(a)) { length = a.length; if (length != b.length) return false; for (i = length; i-- !== 0; ) if (!equal(a[i], b[i])) return false; return true; } if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; for (i = length; i-- !== 0; ) { var key = keys[i]; if (!equal(a[key], b[key])) return false; } return true; } return a !== a && b !== b; }; function cleanupNonNestedPath(path) { if (isNotNestedPath(path)) { return path.replace(/\[|\]/gi, ""); } return path; } function getFromPath(object, path, fallback) { if (!object) { return fallback; } if (isNotNestedPath(path)) { return object[cleanupNonNestedPath(path)]; } const resolvedValue = (path || "").split(/\.|\[(\d+)\]/).filter(Boolean).reduce((acc, propKey) => { if (isContainerValue(acc) && propKey in acc) { return acc[propKey]; } return fallback; }, object); return resolvedValue; } function setInPath(object, path, value) { if (isNotNestedPath(path)) { object[cleanupNonNestedPath(path)] = value; return; } const keys = path.split(/\.|\[(\d+)\]/).filter(Boolean); let acc = object; for (let i = 0; i < keys.length; i++) { if (i === keys.length - 1) { acc[keys[i]] = value; return; } if (!(keys[i] in acc) || isNullOrUndefined(acc[keys[i]])) { acc[keys[i]] = isIndex(keys[i + 1]) ? [] : {}; } acc = acc[keys[i]]; } } function unset(object, key) { if (Array.isArray(object) && isIndex(key)) { object.splice(Number(key), 1); return; } if (isObject(object)) { delete object[key]; } } function unsetPath(object, path) { if (isNotNestedPath(path)) { delete object[cleanupNonNestedPath(path)]; return; } const keys = path.split(/\.|\[(\d+)\]/).filter(Boolean); let acc = object; for (let i = 0; i < keys.length; i++) { if (i === keys.length - 1) { unset(acc, keys[i]); break; } if (!(keys[i] in acc) || isNullOrUndefined(acc[keys[i]])) { break; } acc = acc[keys[i]]; } const pathValues = keys.map((_, idx) => { return getFromPath(object, keys.slice(0, idx).join(".")); }); for (let i = pathValues.length - 1; i >= 0; i--) { if (!isEmptyContainer(pathValues[i])) { continue; } if (i === 0) { unset(object, keys[0]); continue; } unset(pathValues[i - 1], keys[i - 1]); } } function keysOf(record) { return Object.keys(record); } function injectWithSelf(symbol, def = void 0) { const vm = getCurrentInstance(); return (vm === null || vm === void 0 ? void 0 : vm.provides[symbol]) || inject(symbol, def); } function warn(message) { warn$1(`[vee-validate]: ${message}`); } function normalizeField(field) { if (Array.isArray(field)) { return field[0]; } return field; } function resolveNextCheckboxValue(currentValue, checkedValue, uncheckedValue) { if (Array.isArray(currentValue)) { const newVal = [...currentValue]; const idx = newVal.findIndex((v) => fastDeepEqual(v, checkedValue)); idx >= 0 ? newVal.splice(idx, 1) : newVal.push(checkedValue); return newVal; } return fastDeepEqual(currentValue, checkedValue) ? uncheckedValue : checkedValue; } function throttle(func, limit) { let inThrottle; let lastResult; return function(...args) { const context = this; if (!inThrottle) { inThrottle = true; setTimeout(() => inThrottle = false, limit); lastResult = func.apply(context, args); } return lastResult; }; } function debounceAsync(inner, ms = 0) { let timer = null; let resolves = []; return function(...args) { if (timer) { window.clearTimeout(timer); } timer = window.setTimeout(() => { const result = inner(...args); resolves.forEach((r) => r(result)); resolves = []; }, ms); return new Promise((resolve) => resolves.push(resolve)); }; } function applyModelModifiers(value, modifiers) { if (!isObject(modifiers)) { return value; } if (modifiers.number) { return toNumber(value); } return value; } function withLatest(fn, onDone) { let latestRun; return async function runLatest(...args) { const pending = fn(...args); latestRun = pending; const result = await pending; if (pending !== latestRun) { return result; } latestRun = void 0; onDone(result, args); return result; }; } var normalizeChildren = (tag, context, slotProps) => { if (!context.slots.default) { return context.slots.default; } if (typeof tag === "string" || !tag) { return context.slots.default(slotProps()); } return { default: () => { var _a, _b; return (_b = (_a = context.slots).default) === null || _b === void 0 ? void 0 : _b.call(_a, slotProps()); } }; }; function getBoundValue(el) { if (hasValueBinding(el)) { return el._value; } return void 0; } function hasValueBinding(el) { return "_value" in el; } function normalizeEventValue(value) { if (!isEvent(value)) { return value; } const input = value.target; if (hasCheckedAttr(input.type) && hasValueBinding(input)) { return getBoundValue(input); } if (input.type === "file" && input.files) { const files = Array.from(input.files); return input.multiple ? files : files[0]; } if (isNativeMultiSelect(input)) { return Array.from(input.options).filter((opt) => opt.selected && !opt.disabled).map(getBoundValue); } if (isNativeSelect(input)) { const selectedOption = Array.from(input.options).find((opt) => opt.selected); return selectedOption ? getBoundValue(selectedOption) : input.value; } return input.value; } function normalizeRules(rules) { const acc = {}; Object.defineProperty(acc, "_$$isNormalized", { value: true, writable: false, enumerable: false, configurable: false }); if (!rules) { return acc; } if (isObject(rules) && rules._$$isNormalized) { return rules; } if (isObject(rules)) { return Object.keys(rules).reduce((prev, curr) => { const params = normalizeParams(rules[curr]); if (rules[curr] !== false) { prev[curr] = buildParams(params); } return prev; }, acc); } if (typeof rules !== "string") { return acc; } return rules.split("|").reduce((prev, rule) => { const parsedRule = parseRule(rule); if (!parsedRule.name) { return prev; } prev[parsedRule.name] = buildParams(parsedRule.params); return prev; }, acc); } function normalizeParams(params) { if (params === true) { return []; } if (Array.isArray(params)) { return params; } if (isObject(params)) { return params; } return [params]; } function buildParams(provided) { const mapValueToLocator = (value) => { if (typeof value === "string" && value[0] === "@") { return createLocator(value.slice(1)); } return value; }; if (Array.isArray(provided)) { return provided.map(mapValueToLocator); } if (provided instanceof RegExp) { return [provided]; } return Object.keys(provided).reduce((prev, key) => { prev[key] = mapValueToLocator(provided[key]); return prev; }, {}); } var parseRule = (rule) => { let params = []; const name = rule.split(":")[0]; if (rule.includes(":")) { params = rule.split(":").slice(1).join(":").split(","); } return { name, params }; }; function createLocator(value) { const locator = (crossTable) => { const val = getFromPath(crossTable, value) || crossTable[value]; return val; }; locator.__locatorRef = value; return locator; } function extractLocators(params) { if (Array.isArray(params)) { return params.filter(isLocator); } return keysOf(params).filter((key) => isLocator(params[key])).map((key) => params[key]); } var DEFAULT_CONFIG = { generateMessage: ({ field }) => `${field} is not valid.`, bails: true, validateOnBlur: true, validateOnChange: true, validateOnInput: false, validateOnModelUpdate: true }; var currentConfig = Object.assign({}, DEFAULT_CONFIG); var getConfig = () => currentConfig; var setConfig = (newConf) => { currentConfig = Object.assign(Object.assign({}, currentConfig), newConf); }; var configure = setConfig; async function validate(value, rules, options = {}) { const shouldBail = options === null || options === void 0 ? void 0 : options.bails; const field = { name: (options === null || options === void 0 ? void 0 : options.name) || "{field}", rules, bails: shouldBail !== null && shouldBail !== void 0 ? shouldBail : true, formData: (options === null || options === void 0 ? void 0 : options.values) || {} }; const result = await _validate(field, value); const errors = result.errors; return { errors, valid: !errors.length }; } async function _validate(field, value) { if (isYupValidator(field.rules)) { return validateFieldWithYup(value, field.rules, { bails: field.bails }); } if (isCallable(field.rules) || Array.isArray(field.rules)) { const ctx = { field: field.name, form: field.formData, value }; const pipeline = Array.isArray(field.rules) ? field.rules : [field.rules]; const length2 = pipeline.length; const errors2 = []; for (let i = 0; i < length2; i++) { const rule = pipeline[i]; const result = await rule(value, ctx); const isValid = typeof result !== "string" && result; if (isValid) { continue; } const message = typeof result === "string" ? result : _generateFieldError(ctx); errors2.push(message); if (field.bails) { return { errors: errors2 }; } } return { errors: errors2 }; } const normalizedContext = Object.assign(Object.assign({}, field), { rules: normalizeRules(field.rules) }); const errors = []; const rulesKeys = Object.keys(normalizedContext.rules); const length = rulesKeys.length; for (let i = 0; i < length; i++) { const rule = rulesKeys[i]; const result = await _test(normalizedContext, value, { name: rule, params: normalizedContext.rules[rule] }); if (result.error) { errors.push(result.error); if (field.bails) { return { errors }; } } } return { errors }; } async function validateFieldWithYup(value, validator, opts) { var _a; const errors = await validator.validate(value, { abortEarly: (_a = opts.bails) !== null && _a !== void 0 ? _a : true }).then(() => []).catch((err) => { if (err.name === "ValidationError") { return err.errors; } throw err; }); return { errors }; } async function _test(field, value, rule) { const validator = resolveRule(rule.name); if (!validator) { throw new Error(`No such validator '${rule.name}' exists.`); } const params = fillTargetValues(rule.params, field.formData); const ctx = { field: field.name, value, form: field.formData, rule: Object.assign(Object.assign({}, rule), { params }) }; const result = await validator(value, params, ctx); if (typeof result === "string") { return { error: result }; } return { error: result ? void 0 : _generateFieldError(ctx) }; } function _generateFieldError(fieldCtx) { const message = getConfig().generateMessage; if (!message) { return "Field is invalid"; } return message(fieldCtx); } function fillTargetValues(params, crossTable) { const normalize = (value) => { if (isLocator(value)) { return value(crossTable); } return value; }; if (Array.isArray(params)) { return params.map(normalize); } return Object.keys(params).reduce((acc, param) => { acc[param] = normalize(params[param]); return acc; }, {}); } async function validateYupSchema(schema, values) { const errorObjects = await schema.validate(values, { abortEarly: false }).then(() => []).catch((err) => { if (err.name !== "ValidationError") { throw err; } return err.inner || []; }); const results = {}; const errors = {}; for (const error of errorObjects) { const messages = error.errors; results[error.path] = { valid: !messages.length, errors: messages }; if (messages.length) { errors[error.path] = messages[0]; } } return { valid: !errorObjects.length, results, errors }; } async function validateObjectSchema(schema, values, opts) { const paths = keysOf(schema); const validations = paths.map(async (path) => { var _a, _b, _c; const fieldResult = await validate(getFromPath(values, path), schema[path], { name: ((_a = opts === null || opts === void 0 ? void 0 : opts.names) === null || _a === void 0 ? void 0 : _a[path]) || path, values, bails: (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.bailsMap) === null || _b === void 0 ? void 0 : _b[path]) !== null && _c !== void 0 ? _c : true }); return Object.assign(Object.assign({}, fieldResult), { path }); }); let isAllValid = true; const validationResults = await Promise.all(validations); const results = {}; const errors = {}; for (const result of validationResults) { results[result.path] = { valid: result.valid, errors: result.errors }; if (!result.valid) { isAllValid = false; errors[result.path] = result.errors[0]; } } return { valid: isAllValid, results, errors }; } function set(obj, key, val) { if (typeof val.value === "object") val.value = klona(val.value); if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") { Object.defineProperty(obj, key, val); } else obj[key] = val.value; } function klona(x) { if (typeof x !== "object") return x; var i = 0, k, list, tmp, str = Object.prototype.toString.call(x); if (str === "[object Object]") { tmp = Object.create(x.__proto__ || null); } else if (str === "[object Array]") { tmp = Array(x.length); } else if (str === "[object Set]") { tmp = /* @__PURE__ */ new Set(); x.forEach(function(val) { tmp.add(klona(val)); }); } else if (str === "[object Map]") { tmp = /* @__PURE__ */ new Map(); x.forEach(function(val, key) { tmp.set(klona(key), klona(val)); }); } else if (str === "[object Date]") { tmp = /* @__PURE__ */ new Date(+x); } else if (str === "[object RegExp]") { tmp = new RegExp(x.source, x.flags); } else if (str === "[object DataView]") { tmp = new x.constructor(klona(x.buffer)); } else if (str === "[object ArrayBuffer]") { tmp = x.slice(0); } else if (str.slice(-6) === "Array]") { tmp = new x.constructor(x); } if (tmp) { for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) { set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i])); } for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) { if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue; set(tmp, k, Object.getOwnPropertyDescriptor(x, k)); } } return tmp || x; } var ID_COUNTER = 0; function useFieldState(path, init) { const { value, initialValue, setInitialValue } = _useFieldValue(path, init.modelValue, init.form); const { errorMessage, errors, setErrors } = _useFieldErrors(path, init.form); const meta = _useFieldMeta(value, initialValue, errors); const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER; function setState(state) { var _a; if ("value" in state) { value.value = state.value; } if ("errors" in state) { setErrors(state.errors); } if ("touched" in state) { meta.touched = (_a = state.touched) !== null && _a !== void 0 ? _a : meta.touched; } if ("initialValue" in state) { setInitialValue(state.initialValue); } } return { id, path, value, initialValue, meta, errors, errorMessage, setState }; } function _useFieldValue(path, modelValue, form) { const modelRef = ref(unref(modelValue)); function resolveInitialValue2() { if (!form) { return unref(modelRef); } return getFromPath(form.meta.value.initialValues, unref(path), unref(modelRef)); } function setInitialValue(value2) { if (!form) { modelRef.value = value2; return; } form.stageInitialValue(unref(path), value2, true); } const initialValue = computed(resolveInitialValue2); if (!form) { const value2 = ref(resolveInitialValue2()); return { value: value2, initialValue, setInitialValue }; } const currentValue = modelValue ? unref(modelValue) : getFromPath(form.values, unref(path), unref(initialValue)); form.stageInitialValue(unref(path), currentValue, true); const value = computed({ get() { return getFromPath(form.values, unref(path)); }, set(newVal) { form.setFieldValue(unref(path), newVal); } }); return { value, initialValue, setInitialValue }; } function _useFieldMeta(currentValue, initialValue, errors) { const meta = reactive({ touched: false, pending: false, valid: true, validated: !!unref(errors).length, initialValue: computed(() => unref(initialValue)), dirty: computed(() => { return !isEqual(unref(currentValue), unref(initialValue)); }) }); watch(errors, (value) => { meta.valid = !value.length; }, { immediate: true, flush: "sync" }); return meta; } function _useFieldErrors(path, form) { function normalizeErrors(messages) { if (!messages) { return []; } return Array.isArray(messages) ? messages : [messages]; } if (!form) { const errors2 = ref([]); return { errors: errors2, errorMessage: computed(() => errors2.value[0]), setErrors: (messages) => { errors2.value = normalizeErrors(messages); } }; } const errors = computed(() => form.errorBag.value[unref(path)] || []); return { errors, errorMessage: computed(() => errors.value[0]), setErrors: (messages) => { form.setFieldErrorBag(unref(path), normalizeErrors(messages)); } }; } function installDevtoolsPlugin(app) { if (true) { setupDevtoolsPlugin({ id: "vee-validate-devtools-plugin", label: "VeeValidate Plugin", packageName: "vee-validate", homepage: "https://vee-validate.logaretm.com/v4", app, logo: "https://vee-validate.logaretm.com/v4/logo.png" }, setupApiHooks); } } var DEVTOOLS_FORMS = {}; var DEVTOOLS_FIELDS = {}; var API; var refreshInspector = throttle(() => { setTimeout(async () => { await nextTick(); API === null || API === void 0 ? void 0 : API.sendInspectorState(INSPECTOR_ID); API === null || API === void 0 ? void 0 : API.sendInspectorTree(INSPECTOR_ID); }, 100); }, 100); function registerFormWithDevTools(form) { const vm = getCurrentInstance(); if (!API) { const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app; if (!app) { return; } installDevtoolsPlugin(app); } DEVTOOLS_FORMS[form.formId] = Object.assign({}, form); DEVTOOLS_FORMS[form.formId]._vm = vm; onUnmounted(() => { delete DEVTOOLS_FORMS[form.formId]; refreshInspector(); }); refreshInspector(); } function registerSingleFieldWithDevtools(field) { const vm = getCurrentInstance(); if (!API) { const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app; if (!app) { return; } installDevtoolsPlugin(app); } DEVTOOLS_FIELDS[field.id] = Object.assign({}, field); DEVTOOLS_FIELDS[field.id]._vm = vm; onUnmounted(() => { delete DEVTOOLS_FIELDS[field.id]; refreshInspector(); }); refreshInspector(); } var INSPECTOR_ID = "vee-validate-inspector"; var COLORS = { error: 12405579, success: 448379, unknown: 5522283, white: 16777215, black: 0, blue: 218007, purple: 12157168, orange: 16099682, gray: 12304330 }; var SELECTED_NODE = null; function setupApiHooks(api) { API = api; api.addInspector({ id: INSPECTOR_ID, icon: "rule", label: "vee-validate", noSelectionText: "Select a vee-validate node to inspect", actions: [ { icon: "done_outline", tooltip: "Validate selected item", action: async () => { if (!SELECTED_NODE) { console.error("There is not a valid selected vee-validate node or component"); return; } const result = await SELECTED_NODE.validate(); console.log(result); } }, { icon: "delete_sweep", tooltip: "Clear validation state of the selected item", action: () => { if (!SELECTED_NODE) { console.error("There is not a valid selected vee-validate node or component"); return; } if ("id" in SELECTED_NODE) { SELECTED_NODE.resetField(); return; } SELECTED_NODE.resetForm(); } } ] }); api.on.getInspectorTree((payload) => { if (payload.inspectorId !== INSPECTOR_ID) { return; } const forms = Object.values(DEVTOOLS_FORMS); const fields = Object.values(DEVTOOLS_FIELDS); payload.rootNodes = [ ...forms.map(mapFormForDevtoolsInspector), ...fields.map((field) => mapFieldForDevtoolsInspector(field)) ]; }); api.on.getInspectorState((payload, ctx) => { if (payload.inspectorId !== INSPECTOR_ID || ctx.currentTab !== `custom-inspector:${INSPECTOR_ID}`) { return; } const { form, field, type } = decodeNodeId(payload.nodeId); if (form && type === "form") { payload.state = buildFormState(form); SELECTED_NODE = form; return; } if (field && type === "field") { payload.state = buildFieldState(field); SELECTED_NODE = field; return; } SELECTED_NODE = null; }); } function mapFormForDevtoolsInspector(form) { const { textColor, bgColor } = getTagTheme(form); const formTreeNodes = {}; Object.values(form.fieldsByPath.value).forEach((field) => { const fieldInstance = Array.isArray(field) ? field[0] : field; if (!fieldInstance) { return; } setInPath(formTreeNodes, unref(fieldInstance.name), mapFieldForDevtoolsInspector(fieldInstance, form)); }); function buildFormTree(tree, path = []) { const key = [...path].pop(); if ("id" in tree) { return Object.assign(Object.assign({}, tree), { label: key || tree.label }); } if (isObject(tree)) { return { id: `${path.join(".")}`, label: key || "", children: Object.keys(tree).map((key2) => buildFormTree(tree[key2], [...path, key2])) }; } if (Array.isArray(tree)) { return { id: `${path.join(".")}`, label: `${key}[]`, children: tree.map((c, idx) => buildFormTree(c, [...path, String(idx)])) }; } return { id: "", label: "", children: [] }; } const { children } = buildFormTree(formTreeNodes); return { id: encodeNodeId(form), label: "Form", children, tags: [ { label: "Form", textColor, backgroundColor: bgColor }, { label: `${Object.keys(form.fieldsByPath.value).length} fields`, textColor: COLORS.white, backgroundColor: COLORS.unknown } ] }; } function mapFieldForDevtoolsInspector(field, form) { const fieldInstance = normalizeField(field); const { textColor, bgColor } = getTagTheme(fieldInstance); const isGroup = Array.isArray(field) && field.length > 1; return { id: encodeNodeId(form, fieldInstance, !isGroup), label: unref(fieldInstance.name), children: Array.isArray(field) ? field.map((fieldItem) => mapFieldForDevtoolsInspector(fieldItem, form)) : void 0, tags: [ isGroup ? void 0 : { label: "Field", textColor, backgroundColor: bgColor }, !form ? { label: "Standalone", textColor: COLORS.black, backgroundColor: COLORS.gray } : void 0, !isGroup && fieldInstance.type === "checkbox" ? { label: "Checkbox", textColor: COLORS.white, backgroundColor: COLORS.blue } : void 0, !isGroup && fieldInstance.type === "radio" ? { label: "Radio", textColor: COLORS.white, backgroundColor: COLORS.purple } : void 0, isGroup ? { label: "Group", textColor: COLORS.black, backgroundColor: COLORS.orange } : void 0 ].filter(Boolean) }; } function encodeNodeId(form, field, encodeIndex = true) { const fieldPath = form ? unref(field === null || field === void 0 ? void 0 : field.name) : field === null || field === void 0 ? void 0 : field.id; const fieldGroup = fieldPath ? form === null || form === void 0 ? void 0 : form.fieldsByPath.value[fieldPath] : void 0; let idx; if (encodeIndex && field && Array.isArray(fieldGroup)) { idx = fieldGroup.indexOf(field); } const idObject = { f: form === null || form === void 0 ? void 0 : form.formId, ff: fieldPath, idx, type: field ? "field" : "form" }; return btoa(JSON.stringify(idObject)); } function decodeNodeId(nodeId) { try { const idObject = JSON.parse(atob(nodeId)); const form = DEVTOOLS_FORMS[idObject.f]; if (!form && idObject.ff) { const field = DEVTOOLS_FIELDS[idObject.ff]; if (!field) { return {}; } return { type: idObject.type, field }; } if (!form) { return {}; } const fieldGroup = form.fieldsByPath.value[idObject.ff]; return { type: idObject.type, form, field: Array.isArray(fieldGroup) ? fieldGroup[idObject.idx || 0] : fieldGroup }; } catch (err) { } return {}; } function buildFieldState(field) { const { errors, meta, value } = field; return { "Field state": [ { key: "errors", value: errors.value }, { key: "initialValue", value: meta.initialValue }, { key: "currentValue", value: value.value }, { key: "touched", value: meta.touched }, { key: "dirty", value: meta.dirty }, { key: "valid", value: meta.valid } ] }; } function buildFormState(form) { const { errorBag, meta, values, isSubmitting, submitCount } = form; return { "Form state": [ { key: "submitCount", value: submitCount.value }, { key: "isSubmitting", value: isSubmitting.value }, { key: "touched", value: meta.value.touched }, { key: "dirty", value: meta.value.dirty }, { key: "valid", value: meta.value.valid }, { key: "initialValues", value: meta.value.initialValues }, { key: "currentValues", value: values }, { key: "errors", value: keysOf(errorBag.value).reduce((acc, key) => { var _a; const message = (_a = errorBag.value[key]) === null || _a === void 0 ? void 0 : _a[0]; if (message) { acc[key] = message; } return acc; }, {}) } ] }; } function getTagTheme(fieldOrForm) { const isValid = "id" in fieldOrForm ? fieldOrForm.meta.valid : fieldOrForm.meta.value.valid; return { bgColor: isValid ? COLORS.success : COLORS.error, textColor: isValid ? COLORS.black : COLORS.white }; } function useField(name, rules, opts) { if (hasCheckedAttr(opts === null || opts === void 0 ? void 0 : opts.type)) { return useCheckboxField(name, rules, opts); } return _useField(name, rules, opts); } function _useField(name, rules, opts) { const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount, modelPropName, syncVModel, form: controlForm } = normalizeOptions(unref(name), opts); const injectedForm = controlled ? injectWithSelf(FormContextKey) : void 0; const form = controlForm || injectedForm; let markedForRemoval = false; const { id, value, initialValue, meta, setState, errors, errorMessage } = useFieldState(name, { modelValue, form }); if (syncVModel) { useVModel({ value, prop: modelPropName, handleChange }); } const handleBlur = () => { meta.touched = true; }; const normalizedRules = computed(() => { let rulesValue = unref(rules); const schema = unref(form === null || form === void 0 ? void 0 : form.schema); if (schema && !isYupValidator(schema)) { rulesValue = extractRuleFromSchema(schema, unref(name)) || rulesValue; } if (isYupValidator(rulesValue) || isCallable(rulesValue) || Array.isArray(rulesValue)) { return rulesValue; } return normalizeRules(rulesValue); }); async function validateCurrentValue(mode) { var _a, _b; if (form === null || form === void 0 ? void 0 : form.validateSchema) { return (_a = (await form.validateSchema(mode)).results[unref(name)]) !== null && _a !== void 0 ? _a : { valid: true, errors: [] }; } return validate(value.value, normalizedRules.value, { name: unref(label) || unref(name), values: (_b = form === null || form === void 0 ? void 0 : form.values) !== null && _b !== void 0 ? _b : {}, bails }); } const validateWithStateMutation = withLatest(async () => { meta.pending = true; meta.validated = true; return validateCurrentValue("validated-only"); }, (result) => { if (markedForRemoval) { result.valid = true; result.errors = []; } setState({ errors: result.errors }); meta.pending = false; return result; }); const validateValidStateOnly = withLatest(async () => { return validateCurrentValue("silent"); }, (result) => { if (markedForRemoval) { result.valid = true; } meta.valid = result.valid; return result; }); function validate$1(opts2) { if ((opts2 === null || opts2 === void 0 ? void 0 : opts2.mode) === "silent") { return validateValidStateOnly(); } return validateWithStateMutation(); } function handleChange(e, shouldValidate = true) { const newValue = normalizeEventValue(e); value.value = newValue; if (!validateOnValueUpdate && shouldValidate) { validateWithStateMutation(); } } onMounted(() => { if (validateOnMount) { return validateWithStateMutation(); } if (!form || !form.validateSchema) { validateValidStateOnly(); } }); function setTouched(isTouched) { meta.touched = isTouched; } let unwatchValue; let lastWatchedValue = klona(value.value); function watchValue() { unwatchValue = watch(value, (val, oldVal) => { if (isEqual(val, oldVal) && isEqual(val, lastWatchedValue)) { return; } const validateFn = validateOnValueUpdate ? validateWithStateMutation : validateValidStateOnly; validateFn(); lastWatchedValue = klona(val); }, { deep: true }); } watchValue(); function resetField(state) { var _a; unwatchValue === null || unwatchValue === void 0 ? void 0 : unwatchValue(); const newValue = state && "value" in state ? state.value : initialValue.value; setState({ value: klona(newValue), initialValue: klona(newValue), touched: (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false, errors: (state === null || state === void 0 ? void 0 : state.errors) || [] }); meta.pending = false; meta.validated = false; validateValidStateOnly(); nextTick(() => { watchValue(); }); } function setValue(newValue) { value.value = newValue; } function setErrors(errors2) { setState({ errors: Array.isArray(errors2) ? errors2 : [errors2] }); } const field = { id, name, label, value, meta, errors, errorMessage, type, checkedValue, uncheckedValue, bails, keepValueOnUnmount, resetField, handleReset: () => resetField(), validate: validate$1, handleChange, handleBlur, setState, setTouched, setErrors, setValue }; provide(FieldContextKey, field); if (isRef(rules) && typeof unref(rules) !== "function") { watch(rules, (value2, oldValue) => { if (isEqual(value2, oldValue)) { return; } meta.validated ? validateWithStateMutation() : validateValidStateOnly(); }, { deep: true }); } if (true) { field._vm = getCurrentInstance(); watch(() => Object.assign(Object.assign({ errors: errors.value }, meta), { value: value.value }), refreshInspector, { deep: true }); if (!form) { registerSingleFieldWithDevtools(field); } } if (!form) { return field; } form.register(field); onBeforeUnmount(() => { markedForRemoval = true; form.unregister(field); }); const dependencies = computed(() => { const rulesVal = normalizedRules.value; if (!rulesVal || isCallable(rulesVal) || isYupValidator(rulesVal) || Array.isArray(rulesVal)) { return {}; } return Object.keys(rulesVal).reduce((acc, rule) => { const deps = extractLocators(rulesVal[rule]).map((dep) => dep.__locatorRef).reduce((depAcc, depName) => { const depValue = getFromPath(form.values, depName) || form.values[depName]; if (depValue !== void 0) { depAcc[depName] = depValue; } return depAcc; }, {}); Object.assign(acc, deps); return acc; }, {}); }); watch(dependencies, (deps, oldDeps) => { if (!Object.keys(deps).length) { return; } const shouldValidate = !isEqual(deps, oldDeps); if (shouldValidate) { meta.validated ? validateWithStateMutation() : validateValidStateOnly(); } }); return field; } function normalizeOptions(name, opts) { const defaults = () => ({ initialValue: void 0, validateOnMount: false, bails: true, label: name, validateOnValueUpdate: true, keepValueOnUnmount: void 0, modelPropName: "modelValue", syncVModel: true, controlled: true }); if (!opts) { return defaults(); } const checkedValue = "valueProp" in opts ? opts.valueProp : opts.checkedValue; const controlled = "standalone" in opts ? !opts.standalone : opts.controlled; return Object.assign(Object.assign(Object.assign({}, defaults()), opts || {}), { controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue }); } function extractRuleFromSchema(schema, fieldName) { if (!schema) { return void 0; } return schema[fieldName]; } function useCheckboxField(name, rules, opts) { const form = !(opts === null || opts === void 0 ? void 0 : opts.standalone) ? injectWithSelf(FormContextKey) : void 0; const checkedValue = opts === null || opts === void 0 ? void 0 : opts.checkedValue; const uncheckedValue = opts === null || opts === void 0 ? void 0 : opts.uncheckedValue; function patchCheckboxApi(field) { const handleChange = field.handleChange; const checked = computed(() => { const currentValue = unref(field.value); const checkedVal = unref(checkedValue); return Array.isArray(currentValue) ? currentValue.findIndex((v) => isEqual(v, checkedVal)) >= 0 : isEqual(checkedVal, currentValue); }); function handleCheckboxChange(e, shouldValidate = true) { var _a; if (checked.value === ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.checked)) { if (shouldValidate) { field.validate(); } return; } let newValue = normalizeEventValue(e); if (!form) { newValue = resolveNextCheckboxValue(unref(field.value), unref(checkedValue), unref(uncheckedValue)); } handleChange(newValue, shouldValidate); } return Object.assign(Object.assign({}, field), { checked, checkedValue, uncheckedValue, handleChange: handleCheckboxChange }); } return patchCheckboxApi(_useField(name, rules, opts)); } function useVModel({ prop, value, handleChange }) { const vm = getCurrentInstance(); if (!vm) { if (true) { console.warn("Failed to setup model events because `useField` was not called in setup."); } return; } const propName = prop || "modelValue"; const emitName = `update:${propName}`; if (!(propName in vm.props)) { return; } watch(value, (newValue) => { if (isEqual(newValue, getCurrentModelValue(vm, propName))) { return; } vm.emit(emitName, newValue); }); watch(() => getCurrentModelValue(vm, propName), (propValue) => { if (propValue === IS_ABSENT && value.value === void 0) { return; } const newValue = propValue === IS_ABSENT ? void 0 : propValue; if (isEqual(newValue, applyModelModifiers(value.value, vm.props.modelModifiers))) { return; } handleChange(newValue); }); } function getCurrentModelValue(vm, propName) { return vm.props[propName]; } var FieldImpl = defineComponent({ name: "Field", inheritAttrs: false, props: { as: { type: [String, Object], default: void 0 }, name: { type: String, required: true }, rules: { type: [Object, String, Function], default: void 0 }, validateOnMount: { type: Boolean, default: false }, validateOnBlur: { type: Boolean, default: void 0 }, validateOnChange: { type: Boolean, default: void 0 }, validateOnInput: { type: Boolean, default: void 0 }, validateOnModelUpdate: { type: Boolean, default: void 0 }, bails: { type: Boolean, default: () => getConfig().bails }, label: { type: String, default: void 0 }, uncheckedValue: { type: null, default: void 0 }, modelValue: { type: null, default: IS_ABSENT }, modelModifiers: { type: null, default: () => ({}) }, "onUpdate:modelValue": { type: null, default: void 0 }, standalone: { type: Boolean, default: false }, keepValue: { type: Boolean, default: void 0 } }, setup(props, ctx) { const rules = toRef(props, "rules"); const name = toRef(props, "name"); const label = toRef(props, "label"); const uncheckedValue = toRef(props, "uncheckedValue"); const keepValue = toRef(props, "keepValue"); const { errors, value, errorMessage, validate: validateField, handleChange, handleBlur, setTouched, resetField, handleReset, meta, checked, setErrors } = useField(name, rules, { validateOnMount: props.validateOnMount, bails: props.bails, standalone: props.standalone, type: ctx.attrs.type, initialValue: resolveInitialValue(props, ctx), // Only for checkboxes and radio buttons checkedValue: ctx.attrs.value, uncheckedValue, label, validateOnValueUpdate: false, keepValueOnUnmount: keepValue }); const onChangeHandler = function handleChangeWithModel(e, shouldValidate = true) { handleChange(e, shouldValidate); ctx.emit("update:modelValue", value.value); }; const handleInput = (e) => { if (!hasCheckedAttr(ctx.attrs.type)) { value.value = normalizeEventValue(e); } }; const onInputHandler = function handleInputWithModel(e) { handleInput(e); ctx.emit("update:modelValue", value.value); }; const fieldProps = computed(() => { const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = resolveValidationTriggers(props); const baseOnBlur = [handleBlur, ctx.attrs.onBlur, validateOnBlur ? validateField : void 0].filter(Boolean); const baseOnInput = [(e) => onChangeHandler(e, validateOnInput), ctx.attrs.onInput].filter(Boolean); const baseOnChange = [(e) => onChangeHandler(e, validateOnChange), ctx.attrs.onChange].filter(Boolean); const attrs = { name: props.name, onBlur: baseOnBlur, onInput: baseOnInput, onChange: baseOnChange }; attrs["onUpdate:modelValue"] = (e) => onChangeHandler(e, validateOnModelUpdate); if (hasCheckedAttr(ctx.attrs.type) && checked) { attrs.checked = checked.value; } const tag = resolveTag(props, ctx); if (shouldHaveValueBinding(tag, ctx.attrs)) { attrs.value = value.value; } return attrs; }); function slotProps() { return { field: fieldProps.value, value: value.value, meta, errors: errors.value, errorMessage: errorMessage.value, validate: validateField, resetField, handleChange: onChangeHandler, handleInput: onInputHandler, handleReset, handleBlur, setTouched, setErrors }; } ctx.expose({ setErrors, setTouched, reset: resetField, validate: validateField, handleChange }); return () => { const tag = resolveDynamicComponent(resolveTag(props, ctx)); const children = normalizeChildren(tag, ctx, slotProps); if (tag) { return h(tag, Object.assign(Object.assign({}, ctx.attrs), fieldProps.value), children); } return children; }; } }); function resolveTag(props, ctx) { let tag = props.as || ""; if (!props.as && !ctx.slots.default) { tag = "input"; } return tag; } function resolveValidationTriggers(props) { var _a, _b, _c, _d; const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = getConfig(); return { validateOnInput: (_a = props.validateOnInput) !== null && _a !== void 0 ? _a : validateOnInput, validateOnChange: (_b = props.validateOnChange) !== null && _b !== void 0 ? _b : validateOnChange, validateOnBlur: (_c = props.validateOnBlur) !== null && _c !== void 0 ? _c : validateOnBlur, validateOnModelUpdate: (_d = props.validateOnModelUpdate) !== null && _d !== void 0 ? _d : validateOnModelUpdate }; } function resolveInitialValue(props, ctx) { if (!hasCheckedAttr(ctx.attrs.type)) { return isPropPresent(props, "modelValue") ? props.modelValue : ctx.attrs.value; } return isPropPresent(props, "modelValue") ? props.modelValue : void 0; } var Field = FieldImpl; var FORM_COUNTER = 0; function useForm(opts) { var _a; const formId = FORM_COUNTER++; const controlledModelPaths = /* @__PURE__ */ new Set(); let RESET_LOCK = false; const fieldsByPath = ref({}); const isSubmitting = ref(false); const submitCount = ref(0); const fieldArrays = []; const formValues = reactive(klona(unref(opts === null || opts === void 0 ? void 0 : opts.initialValues) || {})); const { errorBag, setErrorBag, setFieldErrorBag } = useErrorBag(opts === null || opts === void 0 ? void 0 : opts.initialErrors); const errors = computed(() => { return keysOf(errorBag.value).reduce((acc, key) => { const bag = errorBag.value[key]; if (bag && bag.length) { acc[key] = bag[0]; } return acc; }, {}); }); function getFirstFieldAtPath(path) { const fieldOrGroup = fieldsByPath.value[path]; return Array.isArray(fieldOrGroup) ? fieldOrGroup[0] : fieldOrGroup; } function fieldExists(path) { return !!fieldsByPath.value[path]; } const fieldNames = computed(() => { return keysOf(fieldsByPath.value).reduce((names, path) => { const field = getFirstFieldAtPath(path); if (field) { names[path] = unref(field.label || field.name) || ""; } return names; }, {}); }); const fieldBailsMap = computed(() => { return keysOf(fieldsByPath.value).reduce((map, path) => { var _a2; const field = getFirstFieldAtPath(path); if (field) { map[path] = (_a2 = field.bails) !== null && _a2 !== void 0 ? _a2 : true; } return map; }, {}); }); const initialErrors = Object.assign({}, (opts === null || opts === void 0 ? void 0 : opts.initialErrors) || {}); const keepValuesOnUnmount = (_a = opts === null || opts === void 0 ? void 0 : opts.keepValuesOnUnmount) !== null && _a !== void 0 ? _a : false; const { initialValues, originalInitialValues, setInitialValues } = useFormInitialValues(fieldsByPath, formValues, opts === null || opts === void 0 ? void 0 : opts.initialValues); const meta = useFormMeta(fieldsByPath, formValues, originalInitialValues, errors); const controlledValues = computed(() => { return [...controlledModelPaths, ...keysOf(fieldsByPath.value)].reduce((acc, path) => { const value = getFromPath(formValues, path); setInPath(acc, path, value); return acc; }, {}); }); const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema; const debouncedSilentValidation = debounceAsync(_validateSchema, 5); const debouncedValidation = debounceAsync(_validateSchema, 5); const validateSchema = withLatest(async (mode) => { return await mode === "silent" ? debouncedSilentValidation() : debouncedValidation(); }, (formResult, [mode]) => { const fieldsById = formCtx.fieldsByPath.value || {}; const currentErrorsPaths = keysOf(formCtx.errorBag.value); const paths = [ .../* @__PURE__ */ new Set([...keysOf(formResult.results), ...keysOf(fieldsById), ...currentErrorsPaths]) ]; return paths.reduce((validation, path) => { const field = fieldsById[path]; const messages = (formResult.results[path] || { errors: [] }).errors; const fieldResult = { errors: messages, valid: !messages.length }; validation.results[path] = fieldResult; if (!fieldResult.valid) { validation.errors[path] = fieldResult.errors[0]; } if (!field) { setFieldError(path, messages); return validation; } applyFieldMutation(field, (f) => f.meta.valid = fieldResult.valid); if (mode === "silent") { return validation; } const wasValidated = Array.isArray(field) ? field.some((f) => f.meta.validated) : field.meta.validated; if (mode === "validated-only" && !wasValidated) { return validation; } applyFieldMutation(field, (f) => f.setState({ errors: fieldResult.errors })); return validation; }, { valid: formResult.valid, results: {}, errors: {} }); }); function makeSubmissionFactory(onlyControlled) { return function submitHandlerFactory(fn, onValidationError) { return function submissionHandler(e) { if (e instanceof Event) { e.preventDefault(); e.stopPropagation(); } setTouched(keysOf(fieldsByPath.value).reduce((acc, field) => { acc[field] = true; return acc; }, {})); isSubmitting.value = true; submitCount.value++; return validate2().then((result) => { const values = klona(formValues); if (result.valid && typeof fn === "function") { const controlled = klona(controlledValues.value); return fn(onlyControlled ? controlled : values, { evt: e, controlledValues: controlled, setErrors, setFieldError, setTouched, setFieldTouched, setValues, setFieldValue, resetForm }); } if (!result.valid && typeof onValidationError === "function") { onValidationError({ values, evt: e, errors: result.errors, results: result.results }); } }).then((returnVal) => { isSubmitting.value = false; return returnVal; }, (err) => { isSubmitting.value = false; throw err; }); }; }; } const handleSubmitImpl = makeSubmissionFactory(false); const handleSubmit = handleSubmitImpl; handleSubmit.withControlled = makeSubmissionFactory(true); const formCtx = { formId, fieldsByPath, values: formValues, controlledValues, errorBag, errors, schema, submitCount, meta, isSubmitting, fieldArrays, keepValuesOnUnmount, validateSchema: unref(schema) ? validateSchema : void 0, validate: validate2, register: registerField, unregister: unregisterField, setFieldErrorBag, validateField, setFieldValue, setValues, setErrors, setFieldError, setFieldTouched, setTouched, resetForm, handleSubmit, stageInitialValue, unsetInitialValue, setFieldInitialValue, useFieldModel }; function isFieldGroup(fieldOrGroup) { return Array.isArray(fieldOrGroup); } function applyFieldMutation(fieldOrGroup, mutation) { if (Array.isArray(fieldOrGroup)) { return fieldOrGroup.forEach(mutation); } return mutation(fieldOrGroup); } function mutateAllFields(mutation) { Object.values(fieldsByPath.value).forEach((field) => { if (!field) { return; } applyFieldMutation(field, mutation); }); } function setFieldError(field, message) { setFieldErrorBag(field, message); } function setErrors(fields) { setErrorBag(fields); } function setFieldValue(field, value, { force } = { force: false }) { var _a2; const fieldInstance = fieldsByPath.value[field]; const clonedValue = klona(value); if (!fieldInstance) { setInPath(formValues, field, clonedValue); return; } if (isFieldGroup(fieldInstance) && ((_a2 = fieldInstance[0]) === null || _a2 === void 0 ? void 0 : _a2.type) === "checkbox" && !Array.isArray(value)) { const newValue2 = klona(resolveNextCheckboxValue(getFromPath(formValues, field) || [], value, void 0)); setInPath(formValues, field, newValue2); return; } let newValue = value; if (!isFieldGroup(fieldInstance) && fieldInstance.type === "checkbox" && !force && !RESET_LOCK) { newValue = klona(resolveNextCheckboxValue(getFromPath(formValues, field), value, unref(fieldInstance.uncheckedValue))); } setInPath(formValues, field, newValue); } function setValues(fields) { keysOf(formValues).forEach((key) => { delete formValues[key]; }); keysOf(fields).forEach((path) => { setFieldValue(path, fields[path]); }); fieldArrays.forEach((f) => f && f.reset()); } function createModel(path) { const { value } = _useFieldValue(path, void 0, formCtx); watch(value, () => { if (!fieldExists(unref(path))) { validate2({ mode: "validated-only" }); } }, { deep: true }); controlledModelPaths.add(unref(path)); return value; } function useFieldModel(path) { if (!Array.isArray(path)) { return createModel(path); } return path.map(createModel); } function setFieldTouched(field, isTouched) { const fieldInstance = fieldsByPath.value[field]; if (fieldInstance) { applyFieldMutation(fieldInstance, (f) => f.setTouched(isTouched)); } } function setTouched(fields) { keysOf(fields).forEach((field) => { setFieldTouched(field, !!fields[field]); }); } function resetForm(state) { RESET_LOCK = true; mutateAllFields((f) => f.resetField()); if (state === null || state === void 0 ? void 0 : state.values) { setInitialValues(state.values); setValues(state === null || state === void 0 ? void 0 : state.values); } else { setInitialValues(originalInitialValues.value); setValues(originalInitialValues.value); } if (state === null || state === void 0 ? void 0 : state.touched) { setTouched(state.touched); } setErrors((state === null || state === void 0 ? void 0 : state.errors) || {}); submitCount.value = (state === null || state === void 0 ? void 0 : state.submitCount) || 0; nextTick(() => { RESET_LOCK = false; }); } function insertFieldAtPath(field, path) { const rawField = markRaw(field); const fieldPath = path; if (!fieldsByPath.value[fieldPath]) { fieldsByPath.value[fieldPath] = rawField; return; } const fieldAtPath = fieldsByPath.value[fieldPath]; if (fieldAtPath && !Array.isArray(fieldAtPath)) { fieldsByPath.value[fieldPath] = [fieldAtPath]; } fieldsByPath.value[fieldPath] = [...fieldsByPath.value[fieldPath], rawField]; } function removeFieldFromPath(field, path) { const fieldPath = path; const fieldAtPath = fieldsByPath.value[fieldPath]; if (!fieldAtPath) { return; } if (!isFieldGroup(fieldAtPath) && field.id === fieldAtPath.id) { delete fieldsByPath.value[fieldPath]; return; } if (isFieldGroup(fieldAtPath)) { const idx = fieldAtPath.findIndex((f) => f.id === field.id); if (idx === -1) { return; } fieldAtPath.splice(idx, 1); if (!fieldAtPath.length) { delete fieldsByPath.value[fieldPath]; } } } function registerField(field) { const fieldPath = unref(field.name); insertFieldAtPath(field, fieldPath); if (isRef(field.name)) { watch(field.name, async (newPath, oldPath) => { await nextTick(); removeFieldFromPath(field, oldPath); insertFieldAtPath(field, newPath); if (errors.value[oldPath] || errors.value[newPath]) { setFieldError(oldPath, void 0); validateField(newPath); } await nextTick(); if (!fieldExists(oldPath)) { unsetPath(formValues, oldPath); } }); } const initialErrorMessage = unref(field.errorMessage); if (initialErrorMessage && (initialErrors === null || initialErrors === void 0 ? void 0 : initialErrors[fieldPath]) !== initialErrorMessage) { validateField(fieldPath); } delete initialErrors[fieldPath]; } function unregisterField(field) { const fieldName = unref(field.name); const fieldInstance = fieldsByPath.value[fieldName]; const isGroup = !!fieldInstance && isFieldGroup(fieldInstance); removeFieldFromPath(field, fieldName); nextTick(() => { var _a2; const shouldKeepValue = (_a2 = unref(field.keepValueOnUnmount)) !== null && _a2 !== void 0 ? _a2 : unref(keepValuesOnUnmount); const currentGroupValue = getFromPath(formValues, fieldName); const isSameGroup = isGroup && (fieldInstance === fieldsByPath.value[fieldName] || !fieldsByPath.value[fieldName]); if (isSameGroup && Array.isArray(currentGroupValue) && !shouldKeepValue) { const valueIdx = currentGroupValue.findIndex((i) => isEqual(i, unref(field.checkedValue))); if (valueIdx > -1) { const newVal = [...currentGroupValue]; newVal.splice(valueIdx, 1); setFieldValue(fieldName, newVal, { force: true }); } } if (!fieldExists(fieldName)) { setFieldError(fieldName, void 0); if (shouldKeepValue) { return; } if (isGroup && !isEmptyContainer(getFromPath(formValues, fieldName))) { return; } unsetPath(formValues, fieldName); } }); } async function validate2(opts2) { mutateAllFields((f) => f.meta.validated = true); if (formCtx.validateSchema) { return formCtx.validateSchema((opts2 === null || opts2 === void 0 ? void 0 : opts2.mode) || "force"); } const validations = await Promise.all(Object.values(fieldsByPath.value).map((field) => { const fieldInstance = Array.isArray(field) ? field[0] : field; if (!fieldInstance) { return Promise.resolve({ key: "", valid: true, errors: [] }); } return fieldInstance.validate(opts2).then((result) => { return { key: unref(fieldInstance.name), valid: result.valid, errors: result.errors }; }); })); const results = {}; const errors2 = {}; for (const validation of validations) { results[validation.key] = { valid: validation.valid, errors: validation.errors }; if (validation.errors.length) { errors2[validation.key] = validation.errors[0]; } } return { valid: validations.every((r) => r.valid), results, errors: errors2 }; } async function validateField(field) { const fieldInstance = fieldsByPath.value[field]; if (!fieldInstance) { warn$1(`field with name ${field} was not found`); return Promise.resolve({ errors: [], valid: true }); } if (Array.isArray(fieldInstance)) { return fieldInstance.map((f) => f.validate())[0]; } return fieldInstance.validate(); } function unsetInitialValue(path) { unsetPath(initialValues.value, path); } function stageInitialValue(path, value, updateOriginal = false) { setInPath(formValues, path, value); setFieldInitialValue(path, value); if (updateOriginal && !(opts === null || opts === void 0 ? void 0 : opts.initialValues)) { setInPath(originalInitialValues.value, path, klona(value)); } } function setFieldInitialValue(path, value) { setInPath(initialValues.value, path, klona(value)); } async function _validateSchema() { const schemaValue = unref(schema); if (!schemaValue) { return { valid: true, results: {}, errors: {} }; } const formResult = isYupValidator(schemaValue) ? await validateYupSchema(schemaValue, formValues) : await validateObjectSchema(schemaValue, formValues, { names: fieldNames.value, bailsMap: fieldBailsMap.value }); return formResult; } const submitForm = handleSubmit((_, { evt }) => { if (isFormSubmitEvent(evt)) { evt.target.submit(); } }); onMounted(() => { if (opts === null || opts === void 0 ? void 0 : opts.initialErrors) { setErrors(opts.initialErrors); } if (opts === null || opts === void 0 ? void 0 : opts.initialTouched) { setTouched(opts.initialTouched); } if (opts === null || opts === void 0 ? void 0 : opts.validateOnMount) { validate2(); return; } if (formCtx.validateSchema) { formCtx.validateSchema("silent"); } }); if (isRef(schema)) { watch(schema, () => { var _a2; (_a2 = formCtx.validateSchema) === null || _a2 === void 0 ? void 0 : _a2.call(formCtx, "validated-only"); }); } provide(FormContextKey, formCtx); if (true) { registerFormWithDevTools(formCtx); watch(() => Object.assign(Object.assign({ errors: errorBag.value }, meta.value), { values: formValues, isSubmitting: isSubmitting.value, submitCount: submitCount.value }), refreshInspector, { deep: true }); } return Object.assign(Object.assign({}, formCtx), { handleReset: () => resetForm(), submitForm }); } function useFormMeta(fieldsByPath, currentValues, initialValues, errors) { const MERGE_STRATEGIES = { touched: "some", pending: "some", valid: "every" }; const isDirty = computed(() => { return !isEqual(currentValues, unref(initialValues)); }); function calculateFlags() { const fields = Object.values(fieldsByPath.value).flat(1).filter(Boolean); return keysOf(MERGE_STRATEGIES).reduce((acc, flag) => { const mergeMethod = MERGE_STRATEGIES[flag]; acc[flag] = fields[mergeMethod]((field) => field.meta[flag]); return acc; }, {}); } const flags = reactive(calculateFlags()); watchEffect(() => { const value = calculateFlags(); flags.touched = value.touched; flags.valid = value.valid; flags.pending = value.pending; }); return computed(() => { return Object.assign(Object.assign({ initialValues: unref(initialValues) }, flags), { valid: flags.valid && !keysOf(errors.value).length, dirty: isDirty.value }); }); } function useFormInitialValues(fields, formValues, providedValues) { const initialValues = ref(klona(unref(providedValues)) || {}); const originalInitialValues = ref(klona(unref(providedValues)) || {}); function setInitialValues(values, updateFields = false) { initialValues.value = klona(values); originalInitialValues.value = klona(values); if (!updateFields) { return; } keysOf(fields.value).forEach((fieldPath) => { const field = fields.value[fieldPath]; const wasTouched = Array.isArray(field) ? field.some((f) => f.meta.touched) : field === null || field === void 0 ? void 0 : field.meta.touched; if (!field || wasTouched) { return; } const newValue = getFromPath(initialValues.value, fieldPath); setInPath(formValues, fieldPath, klona(newValue)); }); } if (isRef(providedValues)) { watch(providedValues, (value) => { setInitialValues(value, true); }, { deep: true }); } return { initialValues, originalInitialValues, setInitialValues }; } function useErrorBag(initialErrors) { const errorBag = ref({}); function normalizeErrorItem(message) { return Array.isArray(message) ? message : message ? [message] : []; } function setFieldErrorBag(field, message) { if (!message) { delete errorBag.value[field]; return; } errorBag.value[field] = normalizeErrorItem(message); } function setErrorBag(fields) { errorBag.value = keysOf(fields).reduce((acc, key) => { const message = fields[key]; if (message) { acc[key] = normalizeErrorItem(message); } return acc; }, {}); } if (initialErrors) { setErrorBag(initialErrors); } return { errorBag, setErrorBag, setFieldErrorBag }; } var FormImpl = defineComponent({ name: "Form", inheritAttrs: false, props: { as: { type: String, default: "form" }, validationSchema: { type: Object, default: void 0 }, initialValues: { type: Object, default: void 0 }, initialErrors: { type: Object, default: void 0 }, initialTouched: { type: Object, default: void 0 }, validateOnMount: { type: Boolean, default: false }, onSubmit: { type: Function, default: void 0 }, onInvalidSubmit: { type: Function, default: void 0 }, keepValues: { type: Boolean, default: false } }, setup(props, ctx) { const initialValues = toRef(props, "initialValues"); const validationSchema = toRef(props, "validationSchema"); const keepValues = toRef(props, "keepValues"); const { errors, values, meta, isSubmitting, submitCount, controlledValues, validate: validate2, validateField, handleReset, resetForm, handleSubmit, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched } = useForm({ validationSchema: validationSchema.value ? validationSchema : void 0, initialValues, initialErrors: props.initialErrors, initialTouched: props.initialTouched, validateOnMount: props.validateOnMount, keepValuesOnUnmount: keepValues }); const submitForm = handleSubmit((_, { evt }) => { if (isFormSubmitEvent(evt)) { evt.target.submit(); } }, props.onInvalidSubmit); const onSubmit = props.onSubmit ? handleSubmit(props.onSubmit, props.onInvalidSubmit) : submitForm; function handleFormReset(e) { if (isEvent(e)) { e.preventDefault(); } handleReset(); if (typeof ctx.attrs.onReset === "function") { ctx.attrs.onReset(); } } function handleScopedSlotSubmit(evt, onSubmit2) { const onSuccess = typeof evt === "function" && !onSubmit2 ? evt : onSubmit2; return handleSubmit(onSuccess, props.onInvalidSubmit)(evt); } function slotProps() { return { meta: meta.value, errors: errors.value, values, isSubmitting: isSubmitting.value, submitCount: submitCount.value, controlledValues: controlledValues.value, validate: validate2, validateField, handleSubmit: handleScopedSlotSubmit, handleReset, submitForm, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, resetForm }; } ctx.expose({ setFieldError, setErrors, setFieldValue, setValues, setFieldTouched, setTouched, resetForm, validate: validate2, validateField }); return function renderForm() { const tag = props.as === "form" ? props.as : resolveDynamicComponent(props.as); const children = normalizeChildren(tag, ctx, slotProps); if (!props.as) { return children; } const formAttrs = props.as === "form" ? { // Disables native validation as vee-validate will handle it. novalidate: true } : {}; return h(tag, Object.assign(Object.assign(Object.assign({}, formAttrs), ctx.attrs), { onSubmit, onReset: handleFormReset }), children); }; } }); var Form = FormImpl; function useFieldArray(arrayPath) { const form = injectWithSelf(FormContextKey, void 0); const fields = ref([]); const noOp = () => { }; const noOpApi = { fields, remove: noOp, push: noOp, swap: noOp, insert: noOp, update: noOp, replace: noOp, prepend: noOp, move: noOp }; if (!form) { warn("FieldArray requires being a child of `
` or `useForm` being called before it. Array fields may not work correctly"); return noOpApi; } if (!unref(arrayPath)) { warn("FieldArray requires a field path to be provided, did you forget to pass the `name` prop?"); return noOpApi; } const alreadyExists = form.fieldArrays.find((a) => unref(a.path) === unref(arrayPath)); if (alreadyExists) { return alreadyExists; } let entryCounter = 0; function initFields() { const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(arrayPath), []) || []; fields.value = currentValues.map(createEntry); updateEntryFlags(); } initFields(); function updateEntryFlags() { const fieldsLength = fields.value.length; for (let i = 0; i < fieldsLength; i++) { const entry = fields.value[i]; entry.isFirst = i === 0; entry.isLast = i === fieldsLength - 1; } } function createEntry(value) { const key = entryCounter++; const entry = { key, value: computed({ get() { const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(arrayPath), []) || []; const idx = fields.value.findIndex((e) => e.key === key); return idx === -1 ? value : currentValues[idx]; }, set(value2) { const idx = fields.value.findIndex((e) => e.key === key); if (idx === -1) { warn(`Attempting to update a non-existent array item`); return; } update(idx, value2); } }), isFirst: false, isLast: false }; return entry; } function remove(idx) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); if (!pathValue || !Array.isArray(pathValue)) { return; } const newValue = [...pathValue]; newValue.splice(idx, 1); form === null || form === void 0 ? void 0 : form.unsetInitialValue(pathName + `[${idx}]`); form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue); fields.value.splice(idx, 1); updateEntryFlags(); } function push(value) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue; if (!Array.isArray(normalizedPathValue)) { return; } const newValue = [...normalizedPathValue]; newValue.push(value); form === null || form === void 0 ? void 0 : form.stageInitialValue(pathName + `[${newValue.length - 1}]`, value); form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue); fields.value.push(createEntry(value)); updateEntryFlags(); } function swap(indexA, indexB) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); if (!Array.isArray(pathValue) || !(indexA in pathValue) || !(indexB in pathValue)) { return; } const newValue = [...pathValue]; const newFields = [...fields.value]; const temp = newValue[indexA]; newValue[indexA] = newValue[indexB]; newValue[indexB] = temp; const tempEntry = newFields[indexA]; newFields[indexA] = newFields[indexB]; newFields[indexB] = tempEntry; form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue); fields.value = newFields; updateEntryFlags(); } function insert(idx, value) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); if (!Array.isArray(pathValue) || pathValue.length < idx) { return; } const newValue = [...pathValue]; const newFields = [...fields.value]; newValue.splice(idx, 0, value); newFields.splice(idx, 0, createEntry(value)); form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue); fields.value = newFields; updateEntryFlags(); } function replace(arr) { const pathName = unref(arrayPath); form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, arr); initFields(); } function update(idx, value) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); if (!Array.isArray(pathValue) || pathValue.length - 1 < idx) { return; } form === null || form === void 0 ? void 0 : form.setFieldValue(`${pathName}[${idx}]`, value); } function prepend(value) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue; if (!Array.isArray(normalizedPathValue)) { return; } const newValue = [value, ...normalizedPathValue]; form === null || form === void 0 ? void 0 : form.stageInitialValue(pathName + `[${newValue.length - 1}]`, value); form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue); fields.value.unshift(createEntry(value)); updateEntryFlags(); } function move(oldIdx, newIdx) { const pathName = unref(arrayPath); const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName); const newValue = isNullOrUndefined(pathValue) ? [] : [...pathValue]; if (!Array.isArray(pathValue) || !(oldIdx in pathValue) || !(newIdx in pathValue)) { return; } const newFields = [...fields.value]; const movedItem = newFields[oldIdx]; newFields.splice(oldIdx, 1); newFields.splice(newIdx, 0, movedItem); const movedValue = newValue[oldIdx]; newValue.splice(oldIdx, 1); newValue.splice(newIdx, 0, movedValue); form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue); fields.value = newFields; updateEntryFlags(); } const fieldArrayCtx = { fields, remove, push, swap, insert, update, replace, prepend, move }; form.fieldArrays.push(Object.assign({ path: arrayPath, reset: initFields }, fieldArrayCtx)); onBeforeUnmount(() => { const idx = form.fieldArrays.findIndex((i) => unref(i.path) === unref(arrayPath)); if (idx >= 0) { form.fieldArrays.splice(idx, 1); } }); return fieldArrayCtx; } var FieldArrayImpl = defineComponent({ name: "FieldArray", inheritAttrs: false, props: { name: { type: String, required: true } }, setup(props, ctx) { const { push, remove, swap, insert, replace, update, prepend, move, fields } = useFieldArray(toRef(props, "name")); function slotProps() { return { fields: fields.value, push, remove, swap, insert, update, replace, prepend, move }; } ctx.expose({ push, remove, swap, insert, update, replace, prepend, move }); return () => { const children = normalizeChildren(void 0, ctx, slotProps); return children; }; } }); var FieldArray = FieldArrayImpl; var ErrorMessageImpl = defineComponent({ name: "ErrorMessage", props: { as: { type: String, default: void 0 }, name: { type: String, required: true } }, setup(props, ctx) { const form = inject(FormContextKey, void 0); const message = computed(() => { return form === null || form === void 0 ? void 0 : form.errors.value[props.name]; }); function slotProps() { return { message: message.value }; } return () => { if (!message.value) { return void 0; } const tag = props.as ? resolveDynamicComponent(props.as) : props.as; const children = normalizeChildren(tag, ctx, slotProps); const attrs = Object.assign({ role: "alert" }, ctx.attrs); if (!tag && (Array.isArray(children) || !children) && (children === null || children === void 0 ? void 0 : children.length)) { return children; } if ((Array.isArray(children) || !children) && !(children === null || children === void 0 ? void 0 : children.length)) { return h(tag || "span", attrs, message.value); } return h(tag, attrs, children); }; } }); var ErrorMessage = ErrorMessageImpl; function useResetForm() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return function resetForm(state) { if (!form) { return; } return form.resetForm(state); }; } function useIsFieldDirty(path) { const form = injectWithSelf(FormContextKey); let field = path ? void 0 : inject(FieldContextKey); return computed(() => { if (path) { field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]); } if (!field) { warn(`field with name ${unref(path)} was not found`); return false; } return field.meta.dirty; }); } function useIsFieldTouched(path) { const form = injectWithSelf(FormContextKey); let field = path ? void 0 : inject(FieldContextKey); return computed(() => { if (path) { field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]); } if (!field) { warn(`field with name ${unref(path)} was not found`); return false; } return field.meta.touched; }); } function useIsFieldValid(path) { const form = injectWithSelf(FormContextKey); let field = path ? void 0 : inject(FieldContextKey); return computed(() => { if (path) { field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]); } if (!field) { warn(`field with name ${unref(path)} was not found`); return false; } return field.meta.valid; }); } function useIsSubmitting() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { var _a; return (_a = form === null || form === void 0 ? void 0 : form.isSubmitting.value) !== null && _a !== void 0 ? _a : false; }); } function useValidateField(path) { const form = injectWithSelf(FormContextKey); let field = path ? void 0 : inject(FieldContextKey); return function validateField() { if (path) { field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]); } if (!field) { warn(`field with name ${unref(path)} was not found`); return Promise.resolve({ errors: [], valid: true }); } return field.validate(); }; } function useIsFormDirty() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { var _a; return (_a = form === null || form === void 0 ? void 0 : form.meta.value.dirty) !== null && _a !== void 0 ? _a : false; }); } function useIsFormTouched() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { var _a; return (_a = form === null || form === void 0 ? void 0 : form.meta.value.touched) !== null && _a !== void 0 ? _a : false; }); } function useIsFormValid() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { var _a; return (_a = form === null || form === void 0 ? void 0 : form.meta.value.valid) !== null && _a !== void 0 ? _a : false; }); } function useValidateForm() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return function validateField() { if (!form) { return Promise.resolve({ results: {}, errors: {}, valid: true }); } return form.validate(); }; } function useSubmitCount() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { var _a; return (_a = form === null || form === void 0 ? void 0 : form.submitCount.value) !== null && _a !== void 0 ? _a : 0; }); } function useFieldValue(path) { const form = injectWithSelf(FormContextKey); const field = path ? void 0 : inject(FieldContextKey); return computed(() => { if (path) { return getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(path)); } return unref(field === null || field === void 0 ? void 0 : field.value); }); } function useFormValues() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { return (form === null || form === void 0 ? void 0 : form.values) || {}; }); } function useFormErrors() { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } return computed(() => { return (form === null || form === void 0 ? void 0 : form.errors.value) || {}; }); } function useFieldError(path) { const form = injectWithSelf(FormContextKey); const field = path ? void 0 : inject(FieldContextKey); return computed(() => { if (path) { return form === null || form === void 0 ? void 0 : form.errors.value[unref(path)]; } return field === null || field === void 0 ? void 0 : field.errorMessage.value; }); } function useSubmitForm(cb) { const form = injectWithSelf(FormContextKey); if (!form) { warn("No vee-validate or `useForm` was detected in the component tree"); } const onSubmit = form ? form.handleSubmit(cb) : void 0; return function submitForm(e) { if (!onSubmit) { return; } return onSubmit(e); }; } export { ErrorMessage, Field, FieldArray, FieldContextKey, Form, FormContextKey, IS_ABSENT, configure, defineRule, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useResetForm, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate }; /*! Bundled license information: vee-validate/dist/vee-validate.esm.js: (** * vee-validate v4.7.0 * (c) 2022 Abdelrahman Awad * @license MIT *) */ //# sourceMappingURL=vee-validate.js.map