y-design-ssr
Version:
SSR component library of YUI with Vue3
137 lines (136 loc) • 3.44 kB
JavaScript
import { ref as g, reactive as h, getCurrentInstance as m, provide as O, isVNode as _, inject as j, onUnmounted as A, computed as l, defineComponent as v, createVNode as y } from "vue";
const f = (e, t) => t ? typeof t == "string" ? ` ${e}--${t}` : Array.isArray(t) ? t.reduce((n, r) => n + f(e, r), "") : Object.keys(t).reduce(
(n, r) => n + (t[r] ? f(e, r) : ""),
""
) : "", L = (e) => (t, n) => {
let r = t, i = n;
return r && typeof r != "string" && (i = r, r = ""), r = r ? `${e}__${r}` : e, `${r}${f(r, i)}`;
}, P = () => (e, t) => t ? `${f(`y-${e}`, t)}` : `y-${e}`, T = {
"pull-refresh": {
pulling: "下拉刷新...",
loosing: "释放刷新...",
loading: "数据加载中...",
success: "数据已更新",
failed: "数据跟新失败,请稍后再试"
},
"form-item": {
validateMessage: "请输入正确内容"
}
};
g("zh-CN");
h({
"zh-CN": T
});
const $ = (e) => {
const t = `y-${e}`;
return [t, L(t), P()];
};
var C = /* @__PURE__ */ ((e) => (e.Top = "top", e.Middle = "middle", e.Bottom = "bottom", e))(C || {}), b = /* @__PURE__ */ ((e) => (e.Start = "start", e.Center = "center", e.End = "end", e.SpaceBetween = "space-between", e.SpaceAround = "space-around", e))(b || {});
const B = (e) => {
const t = [], n = (r) => {
Array.isArray(r) && r.forEach((i) => {
var a;
_(i) && (t.push(i), (a = i.component) != null && a.subTree && n(i.component.subTree.children), i.children && n(i.children));
});
};
return n(e), t;
}, I = (e, t) => {
const n = B(t.subTree.children);
e.sort((r, i) => n.indexOf(r.vnode) - n.indexOf(i.vnode));
}, M = (e) => {
const t = m(), n = h([]);
return {
children: n,
initProvide: (i) => {
O(e, {
addChild: (s) => {
s.proxy && (n.push(s), t && I(n, t));
},
removeChild: (s) => {
const c = n.indexOf(s);
n.splice(c, 1);
},
children: n,
...i
});
}
};
}, z = (e) => {
const t = j(e, null), n = m();
if (t && n) {
const { children: r, addChild: i, removeChild: a } = t;
return i(n), A(() => a(n)), {
index: l(() => r.indexOf(n)),
parent: t
};
}
return {
parent: null,
index: g(-1)
};
}, [x, D] = $("row"), N = x;
C.Top, b.Start;
const [G, R] = $("col"), U = /* @__PURE__ */ v({
name: G,
props: {
// 列数
span: {
type: [String, Number],
default: 0
},
// 栅格左侧的间隔格数
offset: {
type: [String, Number],
default: 0
}
},
setup(e, {
slots: t
}) {
const {
parent: n,
index: r
} = z(N), i = l(() => {
if (!n)
return {};
const {
spaceList: a
} = n, o = a.value;
if (o.length === 0)
return {};
const {
left: s,
right: c
} = o[r.value] || {};
return {
paddingLeft: s ? `${s}px` : 0,
paddingRight: c ? `${c}px` : 0
};
});
return () => {
var s;
const {
span: a,
offset: o
} = e;
return y("div", {
style: i.value,
class: R({
[a]: a,
[`offset-${o}`]: o
})
}, [(s = t.default) == null ? void 0 : s.call(t)]);
};
}
});
function V(e) {
const t = e;
return t.install = (n) => {
const { name: r } = e;
r && n.component(r, e);
}, t;
}
const k = V(U);
export {
k as default
};