UNPKG

y-design-ssr

Version:

SSR component library of YUI with Vue3

249 lines (248 loc) 6.3 kB
import { ref as $, reactive as O, inject as S, getCurrentInstance as z, watch as w, onUnmounted as I, defineComponent as N, createVNode as i, computed as f, onBeforeUnmount as E } from "vue"; const p = (e, n) => n ? typeof n == "string" ? ` ${e}--${n}` : Array.isArray(n) ? n.reduce((a, t) => a + p(e, t), "") : Object.keys(n).reduce( (a, t) => a + (n[t] ? p(e, t) : ""), "" ) : "", j = (e) => (n, a) => { let t = n, l = a; return t && typeof t != "string" && (l = t, t = ""), t = t ? `${e}__${t}` : e, `${t}${p(t, l)}`; }, M = () => (e, n) => n ? `${p(`y-${e}`, n)}` : `y-${e}`, q = { "pull-refresh": { pulling: "下拉刷新...", loosing: "释放刷新...", loading: "数据加载中...", success: "数据已更新", failed: "数据跟新失败,请稍后再试" }, "form-item": { validateMessage: "请输入正确内容" } }; $("zh-CN"); O({ "zh-CN": q }); const v = (e) => { const n = `y-${e}`; return [n, j(n), M()]; }, B = (e) => isNaN(Number(e)) && typeof e == "string" ? e : `${e}px`, F = "y-form-item", P = () => { const e = S(F, null), n = z(); if (e && (n != null && n.proxy)) { const { setField: a } = e, { resetValidation: t, change: l, validateWithTrigger: u } = e; return w( () => n.proxy.modelValue, () => { e.instance && e.instance.exposed && (t(), l(), u("onChange")); } ), a(n), I(() => a(null)), { parent: e }; } return { parent: null }; }, [R, b] = v("icon"), T = (e) => new RegExp(/\.(https|png|jpg|gif|jpeg|webp|apng)$/).test(e.toLowerCase()), U = /* @__PURE__ */ N({ name: R, props: { dot: { type: Boolean, default: !1 }, name: { type: String, default: "" }, size: { type: [Number, String], default: "" }, info: { type: [Number, String], default: "" }, badge: { type: [Number, String], default: "" }, color: { type: String, default: "" }, subColor: { type: String, default: "" }, subBg: { type: String, default: "" }, classPrefix: { type: String, default: "y-icon" }, /** * @ignore */ tag: { type: String, default: "i" } }, emits: ["click"], setup(e, { slots: n, emit: a }) { const t = T(e.name), l = () => ({ fontSize: B(e.size), color: e.color }), u = (c) => { a("click", c); }; return () => { const { name: c, classPrefix: m, badge: g, dot: y, subColor: C, subBg: o, tag: h } = e; return i(h, { class: `${m}${t ? "" : ` y-icon--${c}`}`, style: l(), onClick: u }, { default: () => { var d; return [t ? i("em", { class: b("node") }, [i("img", { class: b("image"), src: c, alt: "icon" }, null)]) : null, y ? i("em", { class: b("dot"), style: { backgroundColor: o } }, null) : null, g ? i("em", { class: b("badge"), style: { color: C, backgroundColor: o } }, [g]) : null, ((d = n.default) == null ? void 0 : d.call(n)) || null]; } }); }; } }); function V(e) { const n = e; return n.install = (a) => { const { name: t } = e; t && a.component(t, e); }, n; } const A = V(U), K = (e) => { const n = S(e, null), a = z(); if (n && a) { const { children: t, addChild: l, removeChild: u } = n; return l(a), I(() => u(a)), { index: f(() => t.indexOf(a)), parent: n }; } return { parent: null, index: $(-1) }; }, [L, X] = v("checkbox-group"), D = L, [G, k] = v("checkbox"), H = /* @__PURE__ */ N({ name: G, props: { modelValue: { type: Boolean, default: !1 }, name: { type: String, default: null }, disabled: { type: Boolean, default: !1 }, size: { type: [String, Number], default: "middle" }, square: { type: Boolean, default: !0 }, checkedColor: { type: String, default: "" } }, setup(e, { slots: n, emit: a, expose: t }) { const { parent: l } = K(D), u = l === null ? P().parent : null; l && l.allItemNames.push(e.name); const c = (r, s = null) => f(() => l && l.props[r] !== null ? l.props[r] : Object.keys(e).includes(r) ? e[r] : s), m = c("disabled"), g = c("square"), y = c("checkedColor"), C = c("horizontal", !1), o = f(() => l ? l.props.modelValue.includes(e.name) : e.modelValue), h = (r) => { var s; m.value || typeof r < "u" && o.value === r || ((s = l == null ? void 0 : l.onItemChange) == null || s.call(l, e.name), a("update:modelValue", !e.modelValue), a("change", !e.modelValue)); }; t({ toggle: h }); const d = f(() => ["mini", "small", "middle", "large"].includes(e.size.toString() || (u == null ? void 0 : u.getProp("size"))) ? null : B(e.size)), _ = f(() => { const r = {}; return d.value && (r.width = d.value, r.height = d.value), o.value && y.value && (r.backgroundColor = y.value), r; }); return E(() => { if (!l) return; const r = l.allItemNames.indexOf(e.name); r >= 0 && l.allItemNames.splice(r, 1); }), () => { var s, x; const { size: r } = e; return i("div", { class: k({ disabled: m.value, checked: o.value, horizontal: C.value, [r]: ["mini", "small", "middle", "large"].includes(r.toString()) }), onClick: () => h(), role: "checkbox", "aria-checked": o.value }, [((s = n.icon) == null ? void 0 : s.call(n, { checked: o.value })) || i("div", { class: k("icon", { checked: o.value, square: g.value }), style: _.value }, [o.value ? i(A, { name: "done" }, null) : null]), i("div", { class: k("label") }, [(x = n.default) == null ? void 0 : x.call(n)])]); }; } }); const Y = V(H); export { Y as default };