@volverjs/form-vue
Version:
Vue 3 Forms with @volverjs/ui-vue
932 lines (931 loc) • 27.3 kB
JavaScript
import { computed as e, defineAsyncComponent as t, defineComponent as n, getCurrentInstance as r, h as i, inject as a, isProxy as o, onBeforeUnmount as s, onMounted as c, provide as l, readonly as u, ref as d, resolveComponent as f, toRaw as p, toRefs as m, unref as h, useId as g, watch as _, withModifiers as v } from "vue";
import { throttleFilter as y, watchIgnorable as b } from "@vueuse/core";
import { ZodError as x } from "zod/v3";
import { $ZodError as S, formatError as C, safeParse as w, safeParseAsync as T } from "zod/v4/core";
import { getProperty as E, setProperty as D } from "dot-prop";
//#region src/enums.ts
var O = /* @__PURE__ */ function(e) {
return e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.tel = "tel", e.url = "url", e.search = "search", e.date = "date", e.time = "time", e.datetimeLocal = "datetime-local", e.month = "month", e.week = "week", e.color = "color", e.select = "select", e.checkbox = "checkbox", e.radio = "radio", e.textarea = "textarea", e.radioGroup = "radioGroup", e.checkboxGroup = "checkboxGroup", e.combobox = "combobox", e.custom = "custom", e;
}({}), k = /* @__PURE__ */ function(e) {
return e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.reset = "reset", e.updated = "updated", e.unknown = "unknown", e;
}({});
//#endregion
//#region src/utils.ts
function A(e) {
return Array.isArray(e) ? "array" : e === null ? "null" : typeof e;
}
function j(e, t) {
let n = A(e);
return t.type ? Array.isArray(t.type) ? t.type.some((t) => t === n || t === "integer" && n === "number" && Number.isInteger(e)) : t.type === n || t.type === "integer" && n === "number" && Number.isInteger(e) : !0;
}
var M = (e) => e._def.typeName === "ZodObject", N = (e) => e._zod.def.type === "object", P = (e) => e._def.typeName === "ZodDefault", F = (e) => e._zod.def.type === "default", I = (e) => e._def.typeName === "ZodNullable", L = (e) => e._zod.def.type === "nullable", R = (e) => e._def.typeName === "ZodRecord", z = (e) => e._zod.def.type === "record", B = (e) => e._def.typeName === "ZodArray", ee = (e) => e._zod.def.type === "array", te = (e) => e._def.typeName === "ZodEffects", V = (e) => e._def.typeName === "ZodOptional", H = (e) => e._zod.def.type === "optional", ne = (e) => e._zod.def.type === "pipe", U = (e) => e._zod.def.type === "transform";
function W(e) {
let t = e;
for (; te(t);) t = t.innerType();
return t;
}
function G(e) {
let t = e;
for (; ne(t);) t = U(t._zod.def.out) ? t._zod.def.in : t._zod.def.out;
return t;
}
var re = (e) => {
let t = W(e);
return V(t) && (t = t._def.innerType), t;
}, ie = (e) => {
let t = G(e);
return H(t) && (t = t._zod.def.innerType), t;
}, ae = (e) => !!V(W(e)), oe = (e) => !!H(G(e));
function K(e, t) {
if (e.length === 0) return t ?? void 0;
if (t !== void 0) {
for (let n of e) if (j(t, n)) return q(n, t);
for (let n of e) {
let e = n;
if (!e.type || e.type === "object") return q(e, t);
}
}
return q(e[0], t);
}
function q(e, t) {
if ("const" in e) return e.const;
if (e.anyOf && Array.isArray(e.anyOf)) return K(e.anyOf, t);
if (e.oneOf && Array.isArray(e.oneOf)) return K(e.oneOf, t);
if (e.allOf && Array.isArray(e.allOf)) {
let n = {
...e,
allOf: void 0
};
for (let t of e.allOf) {
let e = t;
e.properties && (n.properties = {
...n.properties,
...e.properties
}), e.type && !n.type && (n.type = e.type);
}
return q(n, t);
}
if (Array.isArray(e.type)) {
if (t === null && e.type.includes("null")) return null;
let n = e.type.find((e) => e !== "null");
return n ? q({
...e,
type: n
}, t) : e.default ?? null;
}
if (e.type !== "object" || !e.properties) switch (e.type) {
case "string": return typeof t == "string" ? t : e.default;
case "number":
case "integer": return typeof t == "number" ? t : e.default;
case "boolean": return typeof t == "boolean" ? t : e.default;
case "null": return t === null ? t : e.default;
case "array": return Array.isArray(t) ? e.items ? t.map((t) => q(e.items, t)) : t : e.default;
default: return e.default;
}
let n = e.properties, r = t && typeof t == "object" && !Array.isArray(t) ? t : void 0, i = {};
for (let e in n) {
let t = r?.[e];
i[e] = q(n[e], t);
}
if (r && e.additionalProperties !== !1) {
let e = new Set(Object.keys(n));
for (let [t, n] of Object.entries(r)) e.has(t) || (i[t] = n);
}
return i;
}
var J = (e) => "_zod" in e, se = {
getInnerType: re,
isObject: M,
hasUnknownKeys: (e) => e._def.unknownKeys === "passthrough",
getShapeEntries: (e) => "shape" in e ? Object.entries(e.shape) : [],
isOptional: ae,
isDefault: P,
getDefaultValue: (e) => e._def.defaultValue(),
getDefaultInnerType: (e) => e._def.innerType,
isNullable: I,
safeParse: (e, t) => e.safeParse(t),
isArray: B,
getArrayElement: (e) => e._def.type,
isRecord: R,
getRecordValue: (e) => e._def.valueType
}, ce = {
getInnerType: ie,
isObject: N,
hasUnknownKeys: (e) => !!(e._zod.def.catchall && e._zod.def.catchall._zod.def.type !== "never"),
getShapeEntries: (e) => "shape" in e._zod.def ? Object.entries(e._zod.def.shape) : [],
isOptional: oe,
isDefault: F,
getDefaultValue: (e) => e._zod.def.defaultValue,
getDefaultInnerType: (e) => e._zod.def.innerType,
isNullable: L,
safeParse: (e, t) => w(e, t),
isArray: ee,
getArrayElement: (e) => e._zod.def.element,
isRecord: z,
getRecordValue: (e) => e._zod.def.valueType
};
function le(e, t, n) {
let r = e.getInnerType(e.getArrayElement(t));
return e.isObject(r) ? n.map((t) => Y(e, r, t)) : n;
}
function ue(e, t, n) {
let r = e.getInnerType(e.getRecordValue(t));
return e.isObject(r) ? Object.keys(n).reduce((t, i) => (t[i] = Y(e, r, n[i]), t), {}) : n;
}
function de(e, t, n, r) {
let i = e.isOptional(n), a = e.getInnerType(n), o;
if (e.isDefault(a) && (o = e.getDefaultValue(a), a = e.getDefaultInnerType(a)), r === null && e.isNullable(a)) return [t, r];
if (r == null && i) return [t, o];
if (a && r !== void 0) {
let i = e.safeParse(n, r);
if (i.success) return [t, i.data ?? o];
}
return e.isArray(a) && Array.isArray(r) ? [t, le(e, a, r)] : e.isRecord(a) && r ? [t, ue(e, a, r)] : e.isObject(a) ? [t, Y(e, a, r && typeof r == "object" ? r : o)] : [t, o];
}
function Y(e, t, n) {
let r = n && typeof n == "object" && !Array.isArray(n) ? n : {};
return {
...e.hasUnknownKeys(t) ? r : {},
...Object.fromEntries(e.getShapeEntries(t).map(([t, n]) => de(e, t, n, r[t])))
};
}
function X(e, t = {}) {
let n = J(e) ? ce : se, r = n.getInnerType(e);
return n.isObject(r) ? Y(n, r, t) : t;
}
var fe = (e, t) => J(e) ? T(e, t) : e.safeParseAsync(t), pe = (e, t) => J(e) ? C(t) : t.format(), me = (e, t) => J(e) ? C(new S(t)) : new x(t).format();
//#endregion
//#region src/VvForm.ts
function he(t, r, a, s, f) {
let m = d(), h = d(), g = e(() => h.value === k.invalid), x = d(), S = d(!1), C, w = (e) => {
let n = X(t, e);
if (a?.class) {
let e = a.class;
return new e(n);
}
return n;
}, T = async (e = x.value, n) => {
if (C = n?.fields, S.value) return !0;
let r = await fe(t, e);
if (!r.success) {
if (h.value = k.invalid, !C?.size) return m.value = pe(t, r.error), !1;
let e = r.error.issues.filter((e) => C?.has(e.path.join(".")));
return e.length ? (m.value = me(t, e), !1) : (m.value = void 0, !0);
}
return m.value = void 0, h.value = k.valid, x.value = w(r.data), !0;
}, E = () => {
m.value = void 0, h.value = void 0, C = void 0;
}, { ignoreUpdates: D, stop: O } = b(x, () => {
h.value = k.updated;
}, {
deep: !0,
eventFilter: y(a?.updateThrottle ?? 500)
}), A = () => {
D(() => {
x.value = w();
}), E(), h.value = k.reset;
}, j = async (e) => S.value || !await T(void 0, e) ? !1 : (h.value = k.submitting, !0), M = u(m), N = u(h);
return {
clear: E,
errors: m,
formData: x,
ignoreUpdates: D,
invalid: g,
readonly: S,
reset: A,
status: h,
wrappers: f,
stopUpdatesWatch: O,
submit: j,
validate: T,
VvForm: n({
name: "VvForm",
props: {
continuousValidation: {
type: Boolean,
default: !1
},
modelValue: {
type: Object,
default: () => ({})
},
readonly: {
type: Boolean,
default: a?.readonly
},
tag: {
type: String,
default: "form"
},
template: {
type: [Array, Function],
default: void 0
},
superRefine: {
type: Function,
default: void 0
},
validateFields: {
type: Array,
default: void 0
}
},
emits: [
"invalid",
"submit",
"update:modelValue",
"update:readonly",
"valid",
"reset"
],
expose: [
"errors",
"invalid",
"readonly",
"status",
"submit",
"tag",
"template",
"valid",
"validate",
"clear",
"reset"
],
slots: Object,
setup(e, { emit: t }) {
return x.value = w(p(e.modelValue)), _(() => e.modelValue, (e) => {
if (e) {
let t = o(e) ? p(e) : e;
if (JSON.stringify(t) === JSON.stringify(p(x.value))) return;
x.value = w(t);
}
}, { deep: !0 }), _(h, async (n) => {
if (n === k.invalid) {
let e = p(m.value);
t("invalid", e), a?.onInvalid?.(e);
return;
}
if (n === k.valid) {
let e = p(x.value);
t("valid", e), a?.onValid?.(e), t("update:modelValue", e), a?.onUpdate?.(e);
return;
}
if (n === k.submitting) {
let e = p(x.value);
t("submit", e), a?.onSubmit?.(e);
return;
}
if (n === k.reset) {
let e = p(x.value);
t("reset", e), a?.onReset?.(e);
return;
}
if (n === k.updated) {
if ((m.value || a?.continuousValidation || e.continuousValidation) && await T(void 0, {
superRefine: e.superRefine,
fields: C ?? new Set(e.validateFields)
}), !x.value || !e.modelValue || JSON.stringify(x.value) !== JSON.stringify(e.modelValue)) {
let e = p(x.value);
t("update:modelValue", e), a?.onUpdate?.(e);
}
h.value === k.updated && (h.value = k.unknown);
}
}), c(() => {
e.readonly !== void 0 && (S.value = e.readonly);
}), _(() => e.readonly, (e) => {
S.value = e;
}), _(S, (n) => {
n !== e.readonly && t("update:readonly", S.value);
}), l(r, {
clear: E,
errors: M,
formData: x,
ignoreUpdates: D,
invalid: g,
readonly: S,
reset: A,
status: N,
stopUpdatesWatch: O,
submit: j,
validate: T,
wrappers: f
}), {
clear: E,
errors: M,
formData: x,
ignoreUpdates: D,
invalid: g,
isReadonly: S,
reset: A,
status: N,
stopUpdatesWatch: O,
submit: () => j({
superRefine: e.superRefine,
fields: new Set(e.validateFields)
}),
validate: T,
wrappers: f
};
},
render() {
let e = () => this.$slots?.default?.({
errors: M.value,
formData: x.value,
invalid: g.value,
readonly: S.value,
status: N.value,
wrappers: f,
clear: E,
ignoreUpdates: D,
reset: A,
stopUpdatesWatch: O,
submit: j,
validate: T
}) ?? this.$slots.default;
return i(this.tag, {
onSubmit: v(this.submit, ["prevent"]),
onReset: v(this.reset, ["prevent"])
}, (this.template ?? a?.template) && s ? [i(s, { schema: this.template ?? a?.template }, { default: e })] : { default: e });
}
})
};
}
//#endregion
//#region src/VvFormField.ts
function ge(r, o, d, p) {
return n({
name: "VvFormField",
props: {
type: {
type: String,
validator: (e) => Object.values(O).includes(e),
default: O.custom
},
is: {
type: [Object, String],
default: void 0
},
name: {
type: [
String,
Number,
Boolean,
Symbol
],
required: !0
},
props: {
type: [Object, Function],
default: () => ({})
},
showValid: {
type: Boolean,
default: !1
},
defaultValue: {
type: [
String,
Number,
Boolean,
Array,
Object
],
default: void 0
},
lazyLoad: {
type: Boolean,
default: !1
},
readonly: {
type: Boolean,
default: void 0
}
},
emits: [
"invalid",
"update:formData",
"update:modelValue",
"valid"
],
expose: [
"component",
"errors",
"hasProps",
"invalid",
"invalidLabel",
"is",
"type"
],
slots: Object,
setup(n, { slots: i, emit: v }) {
let { props: y, name: b } = m(n), x = g(), S = a(o, void 0);
S && S.fields.value.set(x, n.name);
let C = a(r), w = e({
get() {
if (C?.formData) return E(new Object(C.formData.value), String(n.name));
},
set(e) {
C?.formData && (D(new Object(C.formData.value), String(n.name), e), v("update:modelValue", {
newValue: w.value,
formData: C?.formData
}));
}
});
c(() => {
w.value === void 0 && n.defaultValue !== void 0 && (w.value = n.defaultValue);
}), s(() => {
S && S.fields.value.delete(x);
});
let T = e(() => {
if (C?.errors.value) return E(C.errors.value, String(n.name));
}), k = e(() => T.value?._errors), A = e(() => T.value !== void 0), j = _(A, (e) => {
if (e) {
v("invalid", T.value), S && S.errors.value.set(String(n.name), T.value);
return;
}
v("valid", w.value), S && S.errors.value.delete(n.name);
}), M = _(() => C?.formData, () => {
v("update:formData", C?.formData);
}, { deep: !0 });
s(() => {
j(), M();
});
let N = (e) => {
e instanceof InputEvent && (e = e.target.value), w.value = e;
}, P = e(() => {
let e = y.value;
return typeof e == "function" && (e = e(C?.formData)), Object.keys(e).reduce((t, n) => (t[n] = h(e[n]), t), {});
}), F = e(() => C?.readonly.value || S?.readonly.value ? !0 : P.value.readonly ?? n.readonly), I = e(() => ({
...P.value,
name: P.value.name ?? n.name,
invalid: A.value,
valid: n.showValid ? !!(!A.value && w.value) : void 0,
type: ((e) => {
if ([
O.color,
O.date,
O.datetimeLocal,
O.email,
O.month,
O.number,
O.password,
O.search,
O.tel,
O.text,
O.time,
O.url,
O.week
].includes(e)) return e;
})(n.type),
invalidLabel: k.value,
modelValue: w.value,
readonly: F.value,
"onUpdate:modelValue": N
}));
return l(d, {
name: u(b),
errors: u(T)
}), {
component: e(() => {
if (n.type === O.custom) return { render() {
return i.default?.({
errors: u(T).value,
formData: C?.formData.value,
formErrors: C?.errors.value,
invalid: A.value,
invalidLabel: k.value,
modelValue: w.value,
readonly: F.value,
onUpdate: N,
submit: C?.submit,
validate: C?.validate
}) ?? i.default;
} };
if (!(p?.lazyLoad ?? n.lazyLoad)) {
let e;
switch (n.type) {
case O.select:
e = f("VvSelect");
break;
case O.checkbox:
e = f("VvCheckbox");
break;
case O.radio:
e = f("VvRadio");
break;
case O.textarea:
e = f("VvTextarea");
break;
case O.radioGroup:
e = f("VvRadioGroup");
break;
case O.checkboxGroup:
e = f("VvCheckboxGroup");
break;
case O.combobox:
e = f("VvCombobox");
break;
default: e = f("VvInputText");
}
if (typeof e != "string") return e;
console.warn(`[@volverjs/form-vue]: ${e} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`);
}
return t(async () => {
switch (p?.sideEffects && await Promise.resolve(p.sideEffects(n.type)), n.type) {
case O.textarea: return import("@volverjs/ui-vue/vv-textarea");
case O.radio: return import("@volverjs/ui-vue/vv-radio");
case O.radioGroup: return import("@volverjs/ui-vue/vv-radio-group");
case O.checkbox: return import("@volverjs/ui-vue/vv-checkbox");
case O.checkboxGroup: return import("@volverjs/ui-vue/vv-checkbox-group");
case O.select: return import("@volverjs/ui-vue/vv-select");
case O.combobox: return import("@volverjs/ui-vue/vv-combobox");
}
return import("@volverjs/ui-vue/vv-input-text");
});
}),
hasProps: I,
invalid: A
};
},
render() {
return this.is ? i(this.is, this.hasProps, this.$slots) : this.type === O.custom ? i(this.component, null, this.$slots) : i(this.component, this.hasProps, this.$slots);
}
});
}
//#endregion
//#region src/VvFormFieldsGroup.ts
function _e(t, r, o) {
return n({
name: "VvFormFieldsGroup",
props: {
is: {
type: [Object, String],
default: void 0
},
names: {
type: [Array, Object],
required: !0
},
props: {
type: [Object, Function],
default: () => ({})
},
showValid: {
type: Boolean,
default: !1
},
defaultValues: {
type: [Object],
default: void 0
},
readonly: {
type: Boolean,
default: void 0
}
},
emits: [
"invalid",
"update:formData",
"update:modelValue",
"valid"
],
expose: [
"component",
"errors",
"hasProps",
"invalid",
"invalidLabels",
"is"
],
slots: Object,
setup(n, { slots: i, emit: d }) {
let { props: f, names: p, defaultValues: v } = m(n), y = g(), b = e(() => Array.isArray(p.value) ? p.value : Object.values(p.value)), x = e(() => Array.isArray(p.value) ? p.value : Object.keys(p.value)), S = e(() => Array.isArray(p.value) ? p.value.reduce((e, t) => (e[String(t)] = t, e), {}) : p.value), C = e(() => Object.keys(S.value).reduce((e, t) => (e[String(S.value[t])] = t, e), {})), w = a(r, void 0);
w && b.value.forEach((e) => {
w.fields.value.set(`${y}-${e}`, e);
});
let T = a(t), O = e({
get() {
return T?.formData ? x.value.reduce((e, t) => (e[t] = E(new Object(T.formData.value), S.value[t]), e), {}) : {};
},
set(e) {
T?.formData && (x.value.forEach((t) => {
D(new Object(T.formData.value), S.value[t], e?.[t]);
}), d("update:modelValue", {
newValue: O.value,
formData: T?.formData
}));
}
});
c(() => {
v.value && b.value.forEach((e) => {
v.value?.[e] !== void 0 && O.value[e] === void 0 && (O.value = {
...O.value,
[e]: v.value?.[e]
});
});
}), s(() => {
w && b.value.forEach((e) => {
w.fields.value.delete(`${y}-${e}`);
});
});
let k = e(() => {
if (!T?.errors.value) return;
let e = b.value.reduce((e, t) => {
if (!T.errors.value) return e;
let n = E(T.errors.value, String(t));
return n === void 0 || (e[String(t)] = n), e;
}, {});
if (Object.keys(e).length !== 0) return e;
}), A = e(() => {
if (!k.value) return;
let e = Object.keys(k.value).reduce((e, t) => (k.value?.[t] && (e[C.value[t]] = k.value[t]._errors), e), {});
if (Object.keys(e).length !== 0) return e;
}), j = e(() => k.value !== void 0), M = e(() => x.value.reduce((e, t) => (e[t] = !!k.value?.[S.value[t]], e), {})), N = _(j, () => {
if (j.value) {
d("invalid", k.value), w && b.value.forEach((e) => {
if (!k.value?.[e]) {
w.errors.value.delete(e);
return;
}
w.errors.value.set(e, k.value?.[e]);
});
return;
}
d("valid", O.value), w && b.value.forEach((e) => {
w.errors.value.delete(e);
});
}), P = _(() => T?.formData, () => {
d("update:formData", T?.formData);
}, { deep: !0 });
s(() => {
N(), P();
});
let F = (e) => {
O.value = e;
}, I = (e, t) => {
t instanceof InputEvent && (t = t.target.value), x.value.includes(e) && (O.value = {
...O.value,
[e]: t
});
}, L = e(() => {
let e = f.value;
return typeof e == "function" && (e = e(T?.formData)), Object.keys(e).reduce((t, n) => (t[n] = h(e[n]), t), {});
}), R = e(() => T?.readonly.value ? !0 : L.value.readonly ?? n.readonly), z = e(() => x.value.reduce((e, t) => (e[`onUpdate:${t}`] = (e) => {
I(t, e);
}, e), { "onUpdate:modelValue": F })), B = e(() => ({
...z.value,
...L.value,
...O.value,
modelValue: O.value,
names: L.value.name ?? b.value,
invalid: j.value,
invalids: M.value,
valid: n.showValid ? !!(!j.value && O.value) : void 0,
invalidLabels: A.value,
readonly: R.value
}));
return l(o, {
names: u(p),
errors: u(k)
}), {
component: e(() => ({ render() {
return i.default?.({
errors: k.value,
formData: T?.formData.value,
formErrors: T?.errors.value,
invalid: j.value,
invalids: M.value,
invalidLabels: A.value,
modelValue: O.value,
onUpdate: F,
onUpdateField: I,
readonly: R.value,
submit: T?.submit,
validate: T?.validate
}) ?? i.default;
} })),
hasProps: B,
invalid: j
};
},
render() {
return this.is ? i(this.is, this.hasProps, this.$slots) : i(this.component, null, this.$slots);
}
});
}
//#endregion
//#region src/VvFormWrapper.ts
function ve(t, r) {
return n({
name: "VvFormWrapper",
props: {
name: {
type: String,
required: !0
},
tag: {
type: String,
default: void 0
},
readonly: {
type: Boolean,
default: !1
}
},
emits: ["invalid", "valid"],
expose: [
"clear",
"errors",
"fields",
"fieldsErrors",
"formData",
"invalid",
"readonly",
"reset",
"submit",
"tag",
"validate",
"validateWrapper"
],
slots: Object,
setup(n, { emit: i }) {
let o = a(t), f = a(r, void 0), p = d(/* @__PURE__ */ new Map()), h = d(/* @__PURE__ */ new Map()), { name: g } = m(n), v = e(() => o?.invalid.value ? h.value.size > 0 : !1);
_(v, (e) => {
if (e) {
i("invalid");
return;
}
i("valid");
});
let y = e(() => o?.readonly.value || n.readonly), b = {
name: u(g),
errors: h,
invalid: u(v),
readonly: u(y),
fields: p
};
return l(r, b), _(e(() => new Map(p.value)), (e, t) => {
f?.fields && (t.forEach((t, n) => {
e.has(n) || f?.fields.value.delete(n);
}), e.forEach((e, t) => {
f?.fields.value.has(t) || f?.fields.value.set(t, e);
}));
}, { deep: !0 }), _(h, (e) => {
f?.errors && p.value.forEach((t) => {
if (e.has(t) || f.errors.value.delete(t), e.has(t)) {
let n = e.get(t);
n && f.errors.value.set(t, n);
}
});
}, { deep: !0 }), c(() => {
if (!o?.wrappers || !g.value) {
console.warn("[@volverjs/form-vue]: Invalid wrapper registration state");
return;
}
if (o.wrappers.has(g.value)) {
console.warn(`[@volverjs/form-vue]: wrapper name "${g.value}" is already used`);
return;
}
o.wrappers.set(g.value, b);
}), s(() => {
o?.wrappers && g.value && o.wrappers.delete(g.value);
}), {
errors: o?.errors,
fields: p,
fieldsErrors: h,
formData: o?.formData,
invalid: v,
readonly: y,
clear: o?.clear,
reset: o?.reset,
submit: o?.submit,
validate: o?.validate,
validateWrapper: () => o?.validate(void 0, { fields: new Set(p.value.values()) }) ?? Promise.resolve(!0)
};
},
render() {
let e = () => this.$slots.default?.({
errors: this.errors,
fieldsErrors: this.fieldsErrors,
formData: this.formData,
invalid: this.invalid,
readonly: this.readonly,
clear: this.clear,
reset: this.reset,
submit: this.submit,
validate: this.validate,
validateWrapper: this.validateWrapper
});
return this.tag ? i(this.tag, null, { default: e }) : e();
}
});
}
//#endregion
//#region src/VvFormTemplate.ts
function ye(e, t) {
let r = n({
name: "VvFormTemplate",
props: {
schema: {
type: [Array, Function],
required: !0
},
scope: {
type: Object,
default: () => ({})
}
},
slots: Object,
setup(n, { slots: o }) {
let s = a(e);
if (s?.formData) return () => {
let e = typeof n.schema == "function" ? n.schema(s, n.scope) : n.schema, a, c = e.reduce((e, o) => {
let { vvIs: c, vvName: l, vvSlots: u, vvChildren: d, vvIf: f, vvElseIf: p, vvType: m, vvDefaultValue: g, vvShowValid: _, vvContent: v, ...y } = typeof o == "function" ? o(s, n.scope) : o;
if (f !== void 0) {
if (a = typeof f == "string" ? !!E(new Object(s.formData.value), f) : h(typeof f == "function" ? f(s) : f), !a) return e;
} else if (p !== void 0 && a !== void 0) {
if (a || (a = typeof p == "string" ? !!E(new Object(s.formData.value), p) : h(typeof p == "function" ? p(s) : p), !a)) return e;
} else a = void 0;
let b;
return d && (b = typeof c == "string" ? i(r, { schema: d }) : { default: (e) => i(r, {
schema: d,
scope: e
}) }), l ? (e.push(i(t, {
name: l,
is: c,
type: m,
defaultValue: g,
showValid: _,
props: y
}, u ?? b ?? v)), e) : c ? (e.push(i(c, y, u ?? b ?? v)), e) : (b && ("default" in b ? e.push(b.default(n.scope)) : e.push(b)), e);
}, []);
return c.push(o?.default?.({
errors: s?.errors.value,
formData: s?.formData.value,
invalid: s?.invalid.value,
status: s?.status.value,
submit: s?.submit,
validate: s?.validate,
clear: s?.clear,
reset: s?.reset
})), c;
};
}
});
return r;
}
//#endregion
//#region src/index.ts
function Z(e, t = {}) {
let n = Symbol("formInjectionKey"), r = Symbol("formWrapperInjectionKey"), i = Symbol("formFieldInjectionKey"), a = Symbol("formFieldsGroupInjectionKey"), o = ve(n, r), s = ge(n, r, i, t), c = _e(n, r, a), l = ye(n, s), u = /* @__PURE__ */ new Map(), { clear: d, errors: f, formData: p, ignoreUpdates: m, invalid: h, readonly: g, reset: _, status: v, stopUpdatesWatch: y, submit: b, validate: x, VvForm: S } = he(e, n, t, l, u);
return {
clear: d,
errors: f,
formData: p,
formFieldInjectionKey: i,
formInjectionKey: n,
formWrapperInjectionKey: r,
ignoreUpdates: m,
invalid: h,
readonly: g,
reset: _,
status: v,
stopUpdatesWatch: y,
submit: b,
validate: x,
wrappers: u,
VvForm: S,
VvFormField: s,
VvFormFieldsGroup: c,
VvFormTemplate: l,
VvFormWrapper: o
};
}
var Q = Symbol("pluginInjectionKey");
function be(e) {
let t = {};
return e.schema && (t = Z(e.schema, e)), {
...t,
install(n, { global: r = !1 } = {}) {
n.provide(Q, e), r && (n.config.globalProperties.$vvForm = e, t?.VvForm && n.component("VvForm", t.VvForm), t?.VvFormWrapper && n.component("VvFormWrapper", t.VvFormWrapper), t?.VvFormField && n.component("VvFormField", t.VvFormField), t?.VvFormFieldsGroup && n.component("VvFormFieldsGroup", t.VvFormFieldsGroup), t?.VvFormTemplate && n.component("VvFormTemplate", t.VvFormTemplate));
}
};
}
var $ = /* @__PURE__ */ new Map();
function xe(e, t = {}) {
if (t.scope && $.has(t.scope)) return $.get(t.scope);
if (!r()) {
let n = Z(e, t);
return t.scope && $.set(t.scope, n), n;
}
let n = Z(e, {
...a(Q, {}),
...t
});
return t.scope && $.set(t.scope, n), n;
}
function Se(e, t = {}) {
return Z(e, t);
}
//#endregion
export { O as FormFieldType, be as createForm, q as defaultObjectByJSONSchema, X as defaultObjectBySchema, Se as formType, Q as pluginInjectionKey, xe as useForm };