UNPKG

@coderlt/form-designer

Version:

基于vue3的设计器,可视化开发页面表单

439 lines (438 loc) 13.7 kB
import { inject as I, computed as p, getCurrentInstance as W, watch as j, nextTick as H, ref as w, toRaw as U, defineComponent as E, useSlots as J, openBlock as C, createBlock as Q, resolveDynamicComponent as X, unref as n, normalizeClass as x, withCtx as Y, createElementVNode as A, withDirectives as $, createElementBlock as y, isRef as V, vModelCheckbox as F, renderSlot as P, Fragment as re, createTextVNode as Z, toDisplayString as _, createCommentVNode as z, normalizeStyle as de, provide as ce, toRefs as be } from "vue"; import { A as ve, bE as me, B as fe, a9 as ee, au as G, aC as K, aL as M, ax as N, an as D, aE as he, ab as le, a5 as B, bx as ke, ae as q, aa as T, ah as R, a6 as pe, a7 as ge, aG as xe, bD as ae } from "./index-74b7090f.js"; import { u as O, a as ne } from "./use-form-item-18802e58.js"; import { i as Ce } from "./isEqual-10a53e21.js"; import { h as ye } from "./hasIn-61ab08dc.js"; import { f as Se } from "./_flatRest-cdc31ace.js"; function Ee(e, u, i) { for (var a = -1, h = u.length, c = {}; ++a < h; ) { var b = u[a], t = ve(e, b); i(t, b) && me(c, fe(b, e), t); } return c; } function Le(e, u) { return Ee(e, u, function(i, a) { return ye(e, a); }); } var Be = Se(function(e, u) { return e == null ? {} : Le(e, u); }); const Ie = Be, te = { modelValue: { type: [Number, String, Boolean], default: void 0 }, label: { type: [String, Boolean, Number, Object] }, indeterminate: Boolean, disabled: Boolean, checked: Boolean, name: { type: String, default: void 0 }, trueLabel: { type: [String, Number], default: void 0 }, falseLabel: { type: [String, Number], default: void 0 }, id: { type: String, default: void 0 }, controls: { type: String, default: void 0 }, border: Boolean, size: ee, tabindex: [String, Number], validateEvent: { type: Boolean, default: !0 } }, oe = { [G]: (e) => K(e) || M(e) || N(e), change: (e) => K(e) || M(e) || N(e) }, L = Symbol("checkboxGroupContextKey"), $e = ({ model: e, isChecked: u }) => { const i = I(L, void 0), a = p(() => { var c, b; const t = (c = i == null ? void 0 : i.max) == null ? void 0 : c.value, v = (b = i == null ? void 0 : i.min) == null ? void 0 : b.value; return !D(t) && e.value.length >= t && !u.value || !D(v) && e.value.length <= v && u.value; }); return { isDisabled: he(p(() => (i == null ? void 0 : i.disabled.value) || a.value)), isLimitDisabled: a }; }, Ve = (e, { model: u, isLimitExceeded: i, hasOwnLabel: a, isDisabled: h, isLabeledByFormItem: c }) => { const b = I(L, void 0), { formItem: t } = O(), { emit: v } = W(); function l(s) { var r, d; return s === e.trueLabel || s === !0 ? (r = e.trueLabel) != null ? r : !0 : (d = e.falseLabel) != null ? d : !1; } function m(s, r) { v("change", l(s), r); } function k(s) { if (i.value) return; const r = s.target; v("change", l(r.checked), s); } async function S(s) { i.value || !a.value && !h.value && c.value && (s.composedPath().some((f) => f.tagName === "LABEL") || (u.value = l([!1, e.falseLabel].includes(u.value)), await H(), m(u.value, s))); } const o = p(() => (b == null ? void 0 : b.validateEvent) || e.validateEvent); return j(() => e.modelValue, () => { o.value && (t == null || t.validate("change").catch((s) => le(s))); }), { handleChange: k, onClickRoot: S }; }, Fe = (e) => { const u = w(!1), { emit: i } = W(), a = I(L, void 0), h = p(() => D(a) === !1), c = w(!1); return { model: p({ get() { var t, v; return h.value ? (t = a == null ? void 0 : a.modelValue) == null ? void 0 : t.value : (v = e.modelValue) != null ? v : u.value; }, set(t) { var v, l; h.value && B(t) ? (c.value = ((v = a == null ? void 0 : a.max) == null ? void 0 : v.value) !== void 0 && t.length > (a == null ? void 0 : a.max.value), c.value === !1 && ((l = a == null ? void 0 : a.changeEvent) == null || l.call(a, t))) : (i(G, t), u.value = t); } }), isGroup: h, isLimitExceeded: c }; }, Ge = (e, u, { model: i }) => { const a = I(L, void 0), h = w(!1), c = p(() => { const l = i.value; return N(l) ? l : B(l) ? ke(e.label) ? l.map(U).some((m) => Ce(m, e.label)) : l.map(U).includes(e.label) : l != null ? l === e.trueLabel : !!l; }), b = q(p(() => { var l; return (l = a == null ? void 0 : a.size) == null ? void 0 : l.value; }), { prop: !0 }), t = q(p(() => { var l; return (l = a == null ? void 0 : a.size) == null ? void 0 : l.value; })), v = p(() => !!(u.default || e.label)); return { checkboxButtonSize: b, isChecked: c, isFocused: h, checkboxSize: t, hasOwnLabel: v }; }, we = (e, { model: u }) => { function i() { B(u.value) && !u.value.includes(e.label) ? u.value.push(e.label) : u.value = e.trueLabel || !0; } e.checked && i(); }, se = (e, u) => { const { formItem: i } = O(), { model: a, isGroup: h, isLimitExceeded: c } = Fe(e), { isFocused: b, isChecked: t, checkboxButtonSize: v, checkboxSize: l, hasOwnLabel: m } = Ge(e, u, { model: a }), { isDisabled: k } = $e({ model: a, isChecked: t }), { inputId: S, isLabeledByFormItem: o } = ne(e, { formItemContext: i, disableIdGeneration: m, disableIdManagement: h }), { handleChange: s, onClickRoot: r } = Ve(e, { model: a, isLimitExceeded: c, hasOwnLabel: m, isDisabled: k, isLabeledByFormItem: o }); return we(e, { model: a }), { inputId: S, isLabeledByFormItem: o, isChecked: t, isDisabled: k, isFocused: b, checkboxButtonSize: v, checkboxSize: l, hasOwnLabel: m, model: a, handleChange: s, onClickRoot: r }; }, ze = ["tabindex", "role", "aria-checked"], Ne = ["id", "aria-hidden", "name", "tabindex", "disabled", "true-value", "false-value"], De = ["id", "aria-hidden", "disabled", "value", "name", "tabindex"], Pe = E({ name: "ElCheckbox" }), Te = /* @__PURE__ */ E({ ...Pe, props: te, emits: oe, setup(e) { const u = e, i = J(), { inputId: a, isLabeledByFormItem: h, isChecked: c, isDisabled: b, isFocused: t, checkboxSize: v, hasOwnLabel: l, model: m, handleChange: k, onClickRoot: S } = se(u, i), o = T("checkbox"), s = p(() => [ o.b(), o.m(v.value), o.is("disabled", b.value), o.is("bordered", u.border), o.is("checked", c.value) ]), r = p(() => [ o.e("input"), o.is("disabled", b.value), o.is("checked", c.value), o.is("indeterminate", u.indeterminate), o.is("focus", t.value) ]); return (d, f) => (C(), Q(X(!n(l) && n(h) ? "span" : "label"), { class: x(n(s)), "aria-controls": d.indeterminate ? d.controls : null, onClick: n(S) }, { default: Y(() => [ A("span", { class: x(n(r)), tabindex: d.indeterminate ? 0 : void 0, role: d.indeterminate ? "checkbox" : void 0, "aria-checked": d.indeterminate ? "mixed" : void 0 }, [ d.trueLabel || d.falseLabel ? $((C(), y("input", { key: 0, id: n(a), "onUpdate:modelValue": f[0] || (f[0] = (g) => V(m) ? m.value = g : null), class: x(n(o).e("original")), type: "checkbox", "aria-hidden": d.indeterminate ? "true" : "false", name: d.name, tabindex: d.tabindex, disabled: n(b), "true-value": d.trueLabel, "false-value": d.falseLabel, onChange: f[1] || (f[1] = (...g) => n(k) && n(k)(...g)), onFocus: f[2] || (f[2] = (g) => t.value = !0), onBlur: f[3] || (f[3] = (g) => t.value = !1) }, null, 42, Ne)), [ [F, n(m)] ]) : $((C(), y("input", { key: 1, id: n(a), "onUpdate:modelValue": f[4] || (f[4] = (g) => V(m) ? m.value = g : null), class: x(n(o).e("original")), type: "checkbox", "aria-hidden": d.indeterminate ? "true" : "false", disabled: n(b), value: d.label, name: d.name, tabindex: d.tabindex, onChange: f[5] || (f[5] = (...g) => n(k) && n(k)(...g)), onFocus: f[6] || (f[6] = (g) => t.value = !0), onBlur: f[7] || (f[7] = (g) => t.value = !1) }, null, 42, De)), [ [F, n(m)] ]), A("span", { class: x(n(o).e("inner")) }, null, 2) ], 10, ze), n(l) ? (C(), y("span", { key: 0, class: x(n(o).e("label")) }, [ P(d.$slots, "default"), d.$slots.default ? z("v-if", !0) : (C(), y(re, { key: 0 }, [ Z(_(d.label), 1) ], 64)) ], 2)) : z("v-if", !0) ]), _: 3 }, 8, ["class", "aria-controls", "onClick"])); } }); var Re = /* @__PURE__ */ R(Te, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/checkbox/src/checkbox.vue"]]); const Oe = ["name", "tabindex", "disabled", "true-value", "false-value"], Ue = ["name", "tabindex", "disabled", "value"], Ae = E({ name: "ElCheckboxButton" }), Ke = /* @__PURE__ */ E({ ...Ae, props: te, emits: oe, setup(e) { const u = e, i = J(), { isFocused: a, isChecked: h, isDisabled: c, checkboxButtonSize: b, model: t, handleChange: v } = se(u, i), l = I(L, void 0), m = T("checkbox"), k = p(() => { var o, s, r, d; const f = (s = (o = l == null ? void 0 : l.fill) == null ? void 0 : o.value) != null ? s : ""; return { backgroundColor: f, borderColor: f, color: (d = (r = l == null ? void 0 : l.textColor) == null ? void 0 : r.value) != null ? d : "", boxShadow: f ? `-1px 0 0 0 ${f}` : void 0 }; }), S = p(() => [ m.b("button"), m.bm("button", b.value), m.is("disabled", c.value), m.is("checked", h.value), m.is("focus", a.value) ]); return (o, s) => (C(), y("label", { class: x(n(S)) }, [ o.trueLabel || o.falseLabel ? $((C(), y("input", { key: 0, "onUpdate:modelValue": s[0] || (s[0] = (r) => V(t) ? t.value = r : null), class: x(n(m).be("button", "original")), type: "checkbox", name: o.name, tabindex: o.tabindex, disabled: n(c), "true-value": o.trueLabel, "false-value": o.falseLabel, onChange: s[1] || (s[1] = (...r) => n(v) && n(v)(...r)), onFocus: s[2] || (s[2] = (r) => a.value = !0), onBlur: s[3] || (s[3] = (r) => a.value = !1) }, null, 42, Oe)), [ [F, n(t)] ]) : $((C(), y("input", { key: 1, "onUpdate:modelValue": s[4] || (s[4] = (r) => V(t) ? t.value = r : null), class: x(n(m).be("button", "original")), type: "checkbox", name: o.name, tabindex: o.tabindex, disabled: n(c), value: o.label, onChange: s[5] || (s[5] = (...r) => n(v) && n(v)(...r)), onFocus: s[6] || (s[6] = (r) => a.value = !0), onBlur: s[7] || (s[7] = (r) => a.value = !1) }, null, 42, Ue)), [ [F, n(t)] ]), o.$slots.default || o.label ? (C(), y("span", { key: 2, class: x(n(m).be("button", "inner")), style: de(n(h) ? n(k) : void 0) }, [ P(o.$slots, "default", {}, () => [ Z(_(o.label), 1) ]) ], 6)) : z("v-if", !0) ], 2)); } }); var ue = /* @__PURE__ */ R(Ke, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/checkbox/src/checkbox-button.vue"]]); const Me = pe({ modelValue: { type: ge(Array), default: () => [] }, disabled: Boolean, min: Number, max: Number, size: ee, label: String, fill: String, textColor: String, tag: { type: String, default: "div" }, validateEvent: { type: Boolean, default: !0 } }), qe = { [G]: (e) => B(e), change: (e) => B(e) }, We = E({ name: "ElCheckboxGroup" }), je = /* @__PURE__ */ E({ ...We, props: Me, emits: qe, setup(e, { emit: u }) { const i = e, a = T("checkbox"), { formItem: h } = O(), { inputId: c, isLabeledByFormItem: b } = ne(i, { formItemContext: h }), t = async (l) => { u(G, l), await H(), u("change", l); }, v = p({ get() { return i.modelValue; }, set(l) { t(l); } }); return ce(L, { ...Ie(be(i), [ "size", "min", "max", "disabled", "validateEvent", "fill", "textColor" ]), modelValue: v, changeEvent: t }), j(() => i.modelValue, () => { i.validateEvent && (h == null || h.validate("change").catch((l) => le(l))); }), (l, m) => { var k; return C(), Q(X(l.tag), { id: n(c), class: x(n(a).b("group")), role: "group", "aria-label": n(b) ? void 0 : l.label || "checkbox-group", "aria-labelledby": n(b) ? (k = n(h)) == null ? void 0 : k.labelId : void 0 }, { default: Y(() => [ P(l.$slots, "default") ]), _: 3 }, 8, ["id", "class", "aria-label", "aria-labelledby"]); }; } }); var ie = /* @__PURE__ */ R(je, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/checkbox/src/checkbox-group.vue"]]); const _e = xe(Re, { CheckboxButton: ue, CheckboxGroup: ie }), el = ae(ue), ll = ae(ie); export { _e as E, Me as a, oe as b, qe as c, te as d, L as e, el as f, ll as g };