import { aC as Me, H as Ae, aD as Ce, aE as ie, aF as Ee, d as y, aG as he, i as Le, u as qe, aH as Ie, aI as Se, aJ as je, c as Ve, _ as le, M as $, O as z, Q as se, N as oe, f as _e, e as Q, P as ue, aK as Te, aL as Z } from "./index2.js"; import { ref as ve, unref as _, reactive as Ne, shallowRef as Re, watch as U, toRaw as de, nextTick as xe, defineComponent as De, computed as P, createVNode as $e } from "vue"; import { c as Be, g as Ge, a as ze, d as ee, v as We, e as Fe, _ as Ke, u as He, f as Je, h as ce, t as Y, i as fe, j as Qe } from "./FormItem.js"; import { s as Ue } from "./index3.js"; import { i as Ye, a as be, b as Xe, c as Pe, 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 Me(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 k = e[m]; F = dt(k.length, F), p[m] = a >= 120 && k.length >= 120 ? new Ce(m && k) : void 0; } k = e[0]; var A = -1, C = p[0]; e: for (; ++A < a && O.length < F; ) { var E = k[A], M = E; if (E = E !== 0 ? E : 0, !(C ? ie(C, M) : s(O, M))) { for (m = o; --m; ) { var q = p[m]; if (!(q ? ie(q, M) : s(e[m], M))) continue e; } C && C.push(M), O.push(E); } } return O; } function ft(e) { return ot(e) ? e : []; } var mt = lt(function(e) { var t = be(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 = Pe(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, bt = 2, Pt = 4, pt = rt(function(e, t) { var n = {}; if (e == null) return n; var s = !1; t = be(t, function(o) { return o = Pe(o, e), s || (s = o.length > 1), o; }), Be(e, Ge(e), n), s && (n = ze(n, Ft | bt | Pt, 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 = Ne({}), 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 b = 0; b < l.length; b++) { const v = l[b], 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(k(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((b) => { const v = b.filter((L) => L && L.errors.length); return v.length ? Promise.reject({ values: g, errorFields: v, outOfDate: F !== d }) : Promise.resolve(g); }); return I.catch((b) => b), I; }, k = 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 b = d.filter((v) => v && v.errors.length); a[l].validateStatus = b.length ? "error" : "success", a[l].help = b.length ? b.map((v) => v.errors) : null, (I = n == null ? void 0 : n.onValidate) === null || I === void 0 || I.call(n, l, !b.length, b.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 M = s, q = !0; const W = (l) => { const i = []; o.value.forEach((c) => { const h = te(l, c, !1), g = te(M, 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, M = ee(de(l)); }, N = 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, N && N.wait ? nt(W, N.wait, pt(N, ["wait"])) : W, { immediate: n && !!n.immediate, deep: !0 }), { modelRef: e, rulesRef: t, initialModel: s, validateInfos: a, resetFields: m, validate: A, validateField: k, mergeValidateInfo: E, clearValidate: C }; } const wt = () => ({ layout: ue.oneOf(Te("horizontal", "inline", "vertical")), labelCol: Q(), wrapperCol: Q(), colon: z(), labelAlign: se(), labelWrap: z(), prefixCls: String, requiredMark: oe([String, Boolean]), /** @deprecated Will warning in future branch. Pls use `requiredMark` instead. */ hideRequiredMark: z(), model: ue.object, rules: Q(), validateMessages: Q(), validateOnRuleChange: z(), // 提交失败自动滚动到第一个错误字段 scrollToFirstError: _e(), onSubmit: $(), name: String, validateTrigger: oe([String, Array]), size: se(), disabled: z(), onValuesChange: $(), onFieldsChange: $(), onFinish: $(), onFinishFailed: $(), onValidate: $() }); function Ot(e, t) { return he(Y(e), Y(t)); } const T = 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: k } = qe("form", e), A = P(() => e.requiredMark === "" || e.requiredMark), C = P(() => { 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(k); const E = P(() => { var r, u; return (r = e.colon) !== null && r !== void 0 ? r : (u = F.value) === null || u === void 0 ? void 0 : u.colon; }), { validateMessages: M } = je(), q = P(() => y(y(y({}, Fe), M.value), e.validateMessages)), [W, N] = He(m), K = P(() => 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 }, N.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(); }); }, b = (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 G; if (f || w.push(S.namePath.value), !(!((G = S.rules) === null || G === void 0) && G.value.length)) return; const V = S.namePath.value; if (!f || Qe(w, V)) { const ye = S.validateRules(y({ validateMessages: q.value }, u)); j.push(ye.then(() => ({ name: V, errors: [], warnings: [] })).catch((we) => { const J = [], X = []; return we.forEach((Oe) => { let { rule: { warningOnly: ke }, errors: ae } = Oe; ke ? X.push(...ae) : J.push(...ae); }), J.length ? Promise.reject({ name: V, errors: J, warnings: X }) : { name: V, errors: J, 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 G = S.filter((V) => V && V.errors.length); return Promise.reject({ values: R(w), errorFields: G, 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) => { b(f); }); }; return a({ resetFields: d, clearValidate: I, validateFields: x, getFieldsValue: R, validate: v, scrollToField: L }), Je({ model: P(() => e.model), name: P(() => e.name), labelAlign: P(() => e.labelAlign), labelCol: P(() => e.labelCol), labelWrap: P(() => e.labelWrap), wrapperCol: P(() => e.wrapperCol), vertical: P(() => e.layout === "vertical"), colon: E, requiredMark: C, validateTrigger: P(() => e.validateTrigger), rules: P(() => 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)])); }; } }); T.useInjectFormItemContext = it; T.ItemRest = re; T.install = function(e) { return e.component(T.name, T), e.component(T.Item.name, T.Item), e.component(re.name, re), e; }; export { T as F };