UNPKG

y-design-ssr

Version:

SSR component library of YUI with Vue3

178 lines (177 loc) 3.91 kB
import { ref as g, reactive as d, inject as y, getCurrentInstance as h, watch as x, onUnmounted as C, provide as v, isVNode as b, defineComponent as V, createVNode as $ } from "vue"; const u = (e, n) => n ? typeof n == "string" ? ` ${e}--${n}` : Array.isArray(n) ? n.reduce((t, r) => t + u(e, r), "") : Object.keys(n).reduce( (t, r) => t + (n[r] ? u(e, r) : ""), "" ) : "", _ = (e) => (n, t) => { let r = n, o = t; return r && typeof r != "string" && (o = r, r = ""), r = r ? `${e}__${r}` : e, `${r}${u(r, o)}`; }, N = () => (e, n) => n ? `${u(`y-${e}`, n)}` : `y-${e}`, O = { "pull-refresh": { pulling: "下拉刷新...", loosing: "释放刷新...", loading: "数据加载中...", success: "数据已更新", failed: "数据跟新失败,请稍后再试" }, "form-item": { validateMessage: "请输入正确内容" } }; g("zh-CN"); d({ "zh-CN": O }); const A = (e) => { const n = `y-${e}`; return [n, _(n), N()]; }, I = "y-form-item", B = () => { const e = y(I, null), n = h(); if (e && (n != null && n.proxy)) { const { setField: t } = e, { resetValidation: r, change: o, validateWithTrigger: i } = e; return x( () => n.proxy.modelValue, () => { e.instance && e.instance.exposed && (r(), o(), i("onChange")); } ), t(n), C(() => t(null)), { parent: e }; } return { parent: null }; }, E = (e) => { const n = [], t = (r) => { Array.isArray(r) && r.forEach((o) => { var i; b(o) && (n.push(o), (i = o.component) != null && i.subTree && t(o.component.subTree.children), o.children && t(o.children)); }); }; return t(e), n; }, z = (e, n) => { const t = E(n.subTree.children); e.sort((r, o) => t.indexOf(r.vnode) - t.indexOf(o.vnode)); }, M = (e) => { const n = h(), t = d([]); return { children: t, initProvide: (o) => { v(e, { addChild: (a) => { a.proxy && (t.push(a), n && z(t, n)); }, removeChild: (a) => { const f = t.indexOf(a); t.splice(f, 1); }, children: t, ...o }); } }; }, P = { /** * @ignore */ modelValue: { type: Array, default: () => [] }, /** * 最多选中数目 */ max: { type: Number, default: null }, /** * 最少选中数目 */ min: { type: Number, default: null }, /** * 禁用 */ disabled: { type: Boolean, default: null }, /** * 是否为方形 */ square: { type: Boolean, default: null }, /** * 选中颜色 */ checkedColor: { type: String, default: null }, /** * 水平排列 */ horizontal: { type: Boolean, default: !1 } }, [p, T] = A("checkbox-group"), k = p, G = /* @__PURE__ */ V({ name: p, props: P, setup(e, { slots: n, emit: t, expose: r }) { const { initProvide: o } = M(k), i = d([]); B(); const s = (l) => { t("update:modelValue", l), t("change", l); }, a = (l) => { const c = [...e.modelValue], m = c.indexOf(l); if (m >= 0) { if (e.min !== null && c.length <= e.min) return; c.splice(m, 1), s(c); } else { if (e.max !== null && c.length >= e.max) return; s([...c, l]); } }; return r({ toggleAll: (l = null) => { s(l === null ? e.modelValue.length === 0 ? i : [] : l ? i : []); } }), o({ props: e, onItemChange: a, allItemNames: i }), () => { var l; return $("div", { class: T({ horizontal: e.horizontal }) }, [(l = n.default) == null ? void 0 : l.call(n)]); }; } }); function F(e) { const n = e; return n.install = (t) => { const { name: r } = e; r && t.component(r, e); }, n; } const j = F(G); export { P as checkboxGroupProps, j as default };