import { aH as ke, H as Ae, aI as Ce, aJ as ie, aK as Ee, d as y, aL as he, i as Le, u as qe, aM as Ie, aN as Se, aO as je, c as Ve, _ as le, M as $, O as G, Q as se, N as oe, f as _e, e as J, P as ue, aP as Ne, aQ as Z } from "./index2.js"; import { ref as ve, unref as _, reactive as Te, shallowRef as Re, watch as U, toRaw as de, nextTick as xe, defineComponent as De, computed as b, createVNode as $e } from "vue"; import { c as Be, g as ze, a as Ge, d as ee, v as We, e as Fe, _ as Ke, u as He, f as Qe, h as ce, t as Y, i as fe, j as Je } from "./FormItem.js"; import { s as Ue } from "./index3.js"; import { i as Ye, a as Pe, b as Xe, c as be, t as Ze } from "./hasIn.js"; import { s as et, o as tt, f as rt } from "./_flatRest.js"; import { d as nt } from "./debounce.js"; import { i as at } from "./isPlainObject.js"; import { u as it, a as re } from "./FormItemContext.js"; function lt(e, t) { return et(tt(e, t, Ye), e + ""); } function st(e, t, n) { var s = -1, a = e.length; t < 0 && (t = -t > a ? 0 : a + t), n = n > a ? a : n, n < 0 && (n += a), a = t > n ? 0 : n - t >>> 0, t >>>= 0; for (var o = Array(a); ++s < a; ) o[s] = e[s + t]; return o; } function ot(e) { return ke(e) && Ae(e); } function ut(e) { var t = e == null ? 0 : e.length; return t ? e[t - 1] : void 0; } var dt = Math.min; function ct(e, t, n) { for (var s = Ee, a = e[0].length, o = e.length, m = o, p = Array(o), F = 1 / 0, O = []; m--; ) { var M = e[m]; F = dt(M.length, F), p[m] = a >= 120 && M.length >= 120 ? new Ce(m && M) : void 0; } M = e[0]; var A = -1, C = p[0]; e: for (; ++A < a && O.length < F; ) { var E = M[A], k = E; if (E = E !== 0 ? E : 0, !(C ? ie(C, k) : s(O, k))) { for (m = o; --m; ) { var q = p[m]; if (!(q ? ie(q, k) : s(e[m], k))) continue e; } C && C.push(k), O.push(E); } } return O; } function ft(e) { return ot(e) ? e : []; } var mt = lt(function(e) { var t = Pe(e, ft); return t.length && t[0] === e[0] ? ct(t) : []; }); function gt(e, t) { return t.length < 2 ? e : Xe(e, st(t, 0, -1)); } function ht(e, t) { return t = be(t, e), e = gt(e, t), e == null || delete e[Ze(ut(t))]; } function vt(e) { return at(e) ? void 0 : e; } var Ft = 1, Pt = 2, bt = 4, pt = rt(function(e, t) { var n = {}; if (e == null) return n; var s = !1; t = Pe(t, function(o) { return o = be(o, e), s || (s = o.length > 1), o; }), Be(e, ze(e), n), s && (n = Ge(n, Ft | Pt | bt, vt)); for (var a = t.length; a--; ) ht(n, t[a]); return n; }); function pe(e) { let t = !1, n = e.length; const s = []; return e.length ? new Promise((a, o) => { e.forEach((m, p) => { m.catch((F) => (t = !0, F)).then((F) => { n -= 1, s[p] = F, !(n > 0) && (t && o(s), a(s)); }); }); }) : Promise.resolve([]); } function me(e) { let t = !1; return e && e.length && e.every((n) => n.required ? (t = !0, !1) : !0), t; } function ge(e) { return e == null ? [] : Array.isArray(e) ? e : [e]; } function te(e, t, n) { let s = e; t = t.replace(/\[(\w+)\]/g, ".$1"), t = t.replace(/^\./, ""); const a = t.split("."); let o = 0; for (let m = a.length; o < m - 1 && !(!s && !n); ++o) { const p = a[o]; if (p in s) s = s[p]; else { if (n) throw new Error("please transfer a valid name path to validate!"); break; } } return { o: s, k: a[o], v: s ? s[a[o]] : null, isValid: s && a[o] in s }; } function yt(e) { let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ve({}), n = arguments.length > 2 ? arguments[2] : void 0; const s = ee(_(e)), a = Te({}), o = Re([]), m = (l) => { y(_(e), y(y({}, ee(s)), l)), xe(() => { Object.keys(a).forEach((i) => { a[i] = { autoLink: !1, required: me(_(t)[i]) }; }); }); }, p = function() { let l = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], i = arguments.length > 1 ? arguments[1] : void 0; return i.length ? l.filter((c) => { const h = ge(c.trigger || "change"); return mt(h, i).length; }) : l; }; let F = null; const O = function(l) { let i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, c = arguments.length > 2 ? arguments[2] : void 0; const h = [], g = {}; for (let P = 0; P < l.length; P++) { const v = l[P], L = te(_(e), v, c); if (!L.isValid) continue; g[v] = L.v; const R = p(_(t)[v], ge(i && i.trigger)); R.length && h.push(M(v, L.v, R, i || {}).then(() => ({ name: v, errors: [], warnings: [] })).catch((x) => { const D = [], B = []; return x.forEach((r) => { let { rule: { warningOnly: u }, errors: f } = r; u ? B.push(...f) : D.push(...f); }), D.length ? Promise.reject({ name: v, errors: D, warnings: B }) : { name: v, errors: D, warnings: B }; })); } const d = pe(h); F = d; const I = d.then(() => F === d ? Promise.resolve(g) : Promise.reject([])).catch((P) => { const v = P.filter((L) => L && L.errors.length); return v.length ? Promise.reject({ values: g, errorFields: v, outOfDate: F !== d }) : Promise.resolve(g); }); return I.catch((P) => P), I; }, M = function(l, i, c) { let h = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}; const g = We([l], i, c, y({ validateMessages: Fe }, h), !!h.validateFirst); return a[l] ? (a[l].validateStatus = "validating", g.catch((d) => d).then(function() { let d = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []; var I; if (a[l].validateStatus === "validating") { const P = d.filter((v) => v && v.errors.length); a[l].validateStatus = P.length ? "error" : "success", a[l].help = P.length ? P.map((v) => v.errors) : null, (I = n == null ? void 0 : n.onValidate) === null || I === void 0 || I.call(n, l, !P.length, P.length ? de(a[l].help[0]) : null); } }), g) : g.catch((d) => d); }, A = (l, i) => { let c = [], h = !0; l ? Array.isArray(l) ? c = l : c = [l] : (h = !1, c = o.value); const g = O(c, i || {}, h); return g.catch((d) => d), g; }, C = (l) => { let i = []; l ? Array.isArray(l) ? i = l : i = [l] : i = o.value, i.forEach((c) => { a[c] && y(a[c], { validateStatus: "", help: null }); }); }, E = (l) => { const i = { autoLink: !1 }, c = [], h = Array.isArray(l) ? l : [l]; for (let g = 0; g < h.length; g++) { const d = h[g]; (d == null ? void 0 : d.validateStatus) === "error" && (i.validateStatus = "error", d.help && c.push(d.help)), i.required = i.required || (d == null ? void 0 : d.required); } return i.help = c, i; }; let k = s, q = !0; const W = (l) => { const i = []; o.value.forEach((c) => { const h = te(l, c, !1), g = te(k, c, !1); (q && (n == null ? void 0 : n.immediate) && h.isValid || !he(h.v, g.v)) && i.push(c); }), A(i, { trigger: "change" }), q = !1, k = ee(de(l)); }, T = n == null ? void 0 : n.debounce; let K = !0; return U(t, () => { o.value = t ? Object.keys(_(t)) : [], !K && n && n.validateOnRuleChange && A(), K = !1; }, { deep: !0, immediate: !0 }), U(o, () => { const l = {}; o.value.forEach((i) => { l[i] = y({}, a[i], { autoLink: !1, required: me(_(t)[i]) }), delete a[i]; }); for (const i in a) Object.prototype.hasOwnProperty.call(a, i) && delete a[i]; y(a, l); }, { immediate: !0 }), U(e, T && T.wait ? nt(W, T.wait, pt(T, ["wait"])) : W, { immediate: n && !!n.immediate, deep: !0 }), { modelRef: e, rulesRef: t, initialModel: s, validateInfos: a, resetFields: m, validate: A, validateField: M, mergeValidateInfo: E, clearValidate: C }; } const wt = () => ({ layout: ue.oneOf(Ne("horizontal", "inline", "vertical")), labelCol: J(), wrapperCol: J(), colon: G(), labelAlign: se(), labelWrap: G(), prefixCls: String, requiredMark: oe([String, Boolean]), /** @deprecated Will warning in future branch. Pls use `requiredMark` instead. */ hideRequiredMark: G(), model: ue.object, rules: J(), validateMessages: J(), validateOnRuleChange: G(), // 提交失败自动滚动到第一个错误字段 scrollToFirstError: _e(), onSubmit: $(), name: String, validateTrigger: oe([String, Array]), size: se(), disabled: G(), onValuesChange: $(), onFieldsChange: $(), onFinish: $(), onFinishFailed: $(), onValidate: $() }); function Ot(e, t) { return he(Y(e), Y(t)); } const N = De({ compatConfig: { MODE: 3 }, name: "AForm", inheritAttrs: !1, props: Le(wt(), { layout: "horizontal", hideRequiredMark: !1, colon: !0 }), Item: Ke, useForm: yt, // emits: ['finishFailed', 'submit', 'finish', 'validate'], setup(e, t) { let { emit: n, slots: s, expose: a, attrs: o } = t; const { prefixCls: m, direction: p, form: F, size: O, disabled: M } = qe("form", e), A = b(() => e.requiredMark === "" || e.requiredMark), C = b(() => { var r; return A.value !== void 0 ? A.value : F && ((r = F.value) === null || r === void 0 ? void 0 : r.requiredMark) !== void 0 ? F.value.requiredMark : !e.hideRequiredMark; }); Ie(O), Se(M); const E = b(() => { var r, u; return (r = e.colon) !== null && r !== void 0 ? r : (u = F.value) === null || u === void 0 ? void 0 : u.colon; }), { validateMessages: k } = je(), q = b(() => y(y(y({}, Fe), k.value), e.validateMessages)), [W, T] = He(m), K = b(() => Ve(m.value, { [`${m.value}-${e.layout}`]: !0, [`${m.value}-hide-required-mark`]: C.value === !1, [`${m.value}-rtl`]: p.value === "rtl", [`${m.value}-${O.value}`]: O.value }, T.value)), l = ve(), i = {}, c = (r, u) => { i[r] = u; }, h = (r) => { delete i[r]; }, g = (r) => { const u = !!r, f = u ? Y(r).map(fe) : []; return u ? Object.values(i).filter((w) => f.findIndex((j) => Ot(j, w.fieldName.value)) > -1) : Object.values(i); }, d = (r) => { if (!e.model) { Z(!1, "Form", "model is required for resetFields to work."); return; } g(r).forEach((u) => { u.resetField(); }); }, I = (r) => { g(r).forEach((u) => { u.clearValidate(); }); }, P = (r) => { const { scrollToFirstError: u } = e; if (n("finishFailed", r), u && r.errorFields.length) { let f = {}; typeof u == "object" && (f = u), L(r.errorFields[0].name, f); } }, v = function() { return D(...arguments); }, L = function(r) { let u = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; const f = g(r ? [r] : void 0); if (f.length) { const w = f[0].fieldId.value, j = w ? document.getElementById(w) : null; j && Ue(j, y({ scrollMode: "if-needed", block: "nearest" }, u)); } }, R = function() { let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : !0; if (r === !0) { const u = []; return Object.values(i).forEach((f) => { let { namePath: w } = f; u.push(w.value); }), ce(e.model, u); } else return ce(e.model, r); }, x = (r, u) => { if (Z(!(r instanceof Function), "Form", "validateFields/validateField/validate not support callback, please use promise instead"), !e.model) return Z(!1, "Form", "model is required for validateFields to work."), Promise.reject("Form `model` is required for validateFields to work."); const f = !!r, w = f ? Y(r).map(fe) : [], j = []; Object.values(i).forEach((S) => { var z; if (f || w.push(S.namePath.value), !(!((z = S.rules) === null || z === void 0) && z.value.length)) return; const V = S.namePath.value; if (!f || Je(w, V)) { const ye = S.validateRules(y({ validateMessages: q.value }, u)); j.push(ye.then(() => ({ name: V, errors: [], warnings: [] })).catch((we) => { const Q = [], X = []; return we.forEach((Oe) => { let { rule: { warningOnly: Me }, errors: ae } = Oe; Me ? X.push(...ae) : Q.push(...ae); }), Q.length ? Promise.reject({ name: V, errors: Q, warnings: X }) : { name: V, errors: Q, warnings: X }; })); } }); const H = pe(j); l.value = H; const ne = H.then(() => l.value === H ? Promise.resolve(R(w)) : Promise.reject([])).catch((S) => { const z = S.filter((V) => V && V.errors.length); return Promise.reject({ values: R(w), errorFields: z, outOfDate: l.value !== H }); }); return ne.catch((S) => S), ne; }, D = function() { return x(...arguments); }, B = (r) => { r.preventDefault(), r.stopPropagation(), n("submit", r), e.model && x().then((f) => { n("finish", f); }).catch((f) => { P(f); }); }; return a({ resetFields: d, clearValidate: I, validateFields: x, getFieldsValue: R, validate: v, scrollToField: L }), Qe({ model: b(() => e.model), name: b(() => e.name), labelAlign: b(() => e.labelAlign), labelCol: b(() => e.labelCol), labelWrap: b(() => e.labelWrap), wrapperCol: b(() => e.wrapperCol), vertical: b(() => e.layout === "vertical"), colon: E, requiredMark: C, validateTrigger: b(() => e.validateTrigger), rules: b(() => e.rules), addField: c, removeField: h, onValidate: (r, u, f) => { n("validate", r, u, f); }, validateMessages: q }), U(() => e.rules, () => { e.validateOnRuleChange && x(); }), () => { var r; return W($e("form", le(le({}, o), {}, { onSubmit: B, class: [K.value, o.class] }), [(r = s.default) === null || r === void 0 ? void 0 : r.call(s)])); }; } }); N.useInjectFormItemContext = it; N.ItemRest = re; N.install = function(e) { return e.component(N.name, N), e.component(N.Item.name, N.Item), e.component(re.name, re), e; }; export { N as F };