UNPKG

@aplus-frontend/ui

Version:

171 lines (170 loc) 5.83 kB
import { defineComponent as P, ref as S, computed as C, unref as a, watchEffect as U, createElementBlock as g, openBlock as m, normalizeClass as c, createCommentVNode as b, createElementVNode as z, normalizeStyle as T, createBlock as D, resolveDynamicComponent as F, createVNode as B } from "vue"; import { UpOutlined as A, DownOutlined as R, LeftOutlined as $, RightOutlined as j } from "@ant-design/icons-vue"; import "../config-provider/index.mjs"; import { useNamespace as q } from "../config-provider/hooks/use-namespace.mjs"; const G = ["aria-valuenow", "aria-valuemin", "aria-valuemax"], W = /* @__PURE__ */ P({ name: "SplitBar", __name: "SplitBar", props: { index: {}, active: { type: Boolean }, resizable: { type: Boolean }, startCollapsible: { type: Boolean }, endCollapsible: { type: Boolean }, onOffsetStart: { type: Function }, onOffsetUpdate: { type: Function }, onOffsetEnd: {}, onCollapse: { type: Function }, vertical: { type: Boolean }, ariaNow: {}, ariaMin: {}, ariaMax: {}, lazy: { type: Boolean }, containerSize: {}, draggerIcon: {}, collapsibleIcon: {}, showStartCollapsibleIcon: { type: [Boolean, String] }, showEndCollapsibleIcon: { type: [Boolean, String] } }, setup(L) { function y(e) { return typeof e == "number" && !Number.isNaN(e) ? Math.round(e) : 0; } const o = L, { b: t, cssVar: N } = q("splitter-bar"), w = S(null), d = S(0), k = C(() => o.vertical ? 0 : a(d)), x = C(() => o.vertical ? a(d) : 0), V = (e) => { o.resizable && e.currentTarget && (w.value = [e.pageX, e.pageY], o.onOffsetStart(o.index)); }, X = (e) => { if (o.resizable && e.touches.length === 1) { const n = e.touches[0]; w.value = [n.pageX, n.pageY], o.onOffsetStart(o.index); } }, Y = (e) => { const { containerSize: n, ariaMax: s, ariaMin: r, ariaNow: i } = o, l = n * i / 100, u = l + e, p = Math.max(0, n * r / 100), f = Math.max(n, n * s / 100); return Math.max(p, Math.min(f, u)) - l; }, O = (e, n) => { const s = Y(o.vertical ? n : e); d.value = s; }, E = () => { o.onOffsetUpdate(o.index, a(k), a(x)), d.value = 0; }, M = (e) => { switch (e) { case !0: return t("collapse-bar-always-visible"); case !1: return t("collapse-bar-always-hidden"); case "auto": return t("collapse-bar-hover-only"); } }; U((e) => { const n = a(w); if (n) { const s = (u) => { const { pageX: p, pageY: f } = u, v = p - n[0], I = f - n[1]; o.lazy ? O(v, I) : o.onOffsetUpdate(o.index, v, I); }, r = () => { o.lazy && E(), w.value = null, o.onOffsetEnd(); }, i = (u) => { if (u.touches.length === 1) { const p = u.touches[0], f = p.pageX - n[0], v = p.pageY - n[1]; o.lazy ? O(f, v) : o.onOffsetUpdate(o.index, f, v); } }, l = () => { o.lazy && E(), w.value = null, o.onOffsetEnd(); }; window.addEventListener("touchmove", i), window.addEventListener("touchend", l), window.addEventListener("mousemove", s), window.addEventListener("mouseup", r), e(() => { window.removeEventListener("touchmove", i), window.removeEventListener("touchend", l), window.removeEventListener("mousemove", s), window.removeEventListener("mouseup", r); }); } }, { flush: "post" }); const h = C(() => { const { collapsibleIcon: e, vertical: n } = o; let s = null, r = null; const i = e?.start !== void 0, l = e?.end !== void 0; return n ? (s = i ? () => e.start : A, r = l ? () => e.end : R) : (s = i ? () => e.start : $, r = l ? () => e.end : j), { startIcon: s, endIcon: r, startCustomize: i, endCustomize: l }; }); return (e, n) => (m(), g("div", { class: c(a(t)()), role: "separator", "aria-valuenow": y(o.ariaNow), "aria-valuemin": y(o.ariaMin), "aria-valuemax": y(o.ariaMax) }, [o.lazy ? (m(), g("div", { key: 0, class: c([a(t)("preview"), { [a(t)("preview-active")]: !!d.value }]), style: T(a(N)({ "preview-offset": `${d.value}px` })) }, null, 6)) : b("", !0), z("div", { class: c([a(t)("dragger"), { [a(t)("dragger-disabled")]: !e.resizable, [a(t)("dragger-active")]: e.active, [a(t)("dragger-customize")]: e.draggerIcon !== void 0 }]), onMousedown: V, onTouchstart: X }, [e.draggerIcon !== void 0 ? (m(), g("div", { key: 0, class: c(a(t)("dragger-icon")) }, [(m(), D(F(e.draggerIcon)))], 2)) : b("", !0)], 34), e.startCollapsible ? (m(), g("div", { key: 1, class: c([a(t)("collapse-bar"), a(t)("collapse-bar-start"), h.value.startCustomize ? a(t)("collapse-bar-customize") : "", M(e.showStartCollapsibleIcon)]), onClick: n[0] || (n[0] = () => e.onCollapse(e.index, "start")) }, [z("span", { class: c([a(t)("collapse-icon"), a(t)("collapse-start")]) }, [B(a(h).startIcon)], 2)], 2)) : b("", !0), e.endCollapsible ? (m(), g("div", { key: 2, class: c([a(t)("collapse-bar"), a(t)("collapse-bar-end"), h.value.endCustomize ? a(t)("collapse-bar-customize") : "", M(e.showEndCollapsibleIcon)]), onClick: n[1] || (n[1] = () => e.onCollapse(e.index, "end")) }, [z("span", { class: c([a(t)("collapse-icon"), a(t)("collapse-end")]) }, [B(a(h).endIcon)], 2)], 2)) : b("", !0)], 10, G)); } }); export { W as default };