|
|
@@ -1,6 +1,6 @@
|
|
|
-import { useSlots as se, ref as c, computed as g, provide as ce, watch as I, nextTick as k, onMounted as fe, onBeforeUnmount as de, resolveComponent as M, openBlock as _, createElementBlock as C, normalizeClass as V, createVNode as $, createCommentVNode as z, createElementVNode as F, withModifiers as R, Fragment as ve, renderList as pe, withKeys as j, toDisplayString as be, renderSlot as he } from "vue";
|
|
|
+import { useSlots as se, ref as c, computed as h, provide as ce, watch as M, nextTick as K, onMounted as de, onBeforeUnmount as fe, resolveComponent as V, openBlock as k, createElementBlock as _, normalizeClass as $, createVNode as z, createCommentVNode as F, createElementVNode as j, withModifiers as L, Fragment as ve, renderList as pe, withKeys as G, toDisplayString as be, renderSlot as he } from "vue";
|
|
|
import { n as ye } from "./index2.js";
|
|
|
-const ge = ["disabled", "title"], me = ["data-value", "aria-selected", "tabindex", "onClick", "onKeydown"], we = ["disabled", "title"], G = 8, Ke = 5, ke = /* @__PURE__ */ Object.assign({ name: "STab" }, {
|
|
|
+const ge = ["disabled", "title"], me = ["data-value", "aria-selected", "tabindex", "onClick", "onKeydown"], we = ["disabled", "title"], H = 8, Ke = 5, ke = /* @__PURE__ */ Object.assign({ name: "STab" }, {
|
|
|
__name: "STab",
|
|
|
props: {
|
|
|
// 用法一的数据源:[{ label, value }];字段名可用 tabKey 改
|
|
|
@@ -30,214 +30,211 @@ const ge = ["disabled", "title"], me = ["data-value", "aria-selected", "tabindex
|
|
|
}
|
|
|
},
|
|
|
emits: ["update:activeKey", "change"],
|
|
|
- setup(H, { expose: Y, emit: q }) {
|
|
|
- const u = H, m = q, U = se(), r = c(null), X = c(null), N = c(!1), O = c(!1), f = c(!1), l = c(u.activeKey), A = c(!1), d = g(() => u.tabs || []), J = g(() => u.tabKey && u.tabKey.value || "value"), Q = g(() => u.tabKey && u.tabKey.label || "label"), D = g(() => !!U.default);
|
|
|
+ setup(Y, { expose: q, emit: U }) {
|
|
|
+ const u = Y, y = U, J = se(), r = c(null), N = c(null), O = c(!1), P = c(!1), g = c(!1), l = c(u.activeKey), R = c(!1), d = h(() => u.tabs || []), Q = h(() => u.tabKey && u.tabKey.value || "value"), Z = h(() => u.tabKey && u.tabKey.label || "label"), D = h(() => !!J.default);
|
|
|
function s(e, t) {
|
|
|
- const n = e && e[J.value];
|
|
|
+ const n = e && e[Q.value];
|
|
|
return n == null ? t : n;
|
|
|
}
|
|
|
- function Z(e) {
|
|
|
+ function ee(e) {
|
|
|
var n, a;
|
|
|
if (!e) return "";
|
|
|
- const t = e[Q.value];
|
|
|
+ const t = e[Z.value];
|
|
|
return t == null ? (a = (n = e.label) != null ? n : e.tab) != null ? a : "" : t;
|
|
|
}
|
|
|
- const S = (e) => e === "" || e === void 0 || e === null;
|
|
|
- function ee() {
|
|
|
+ const C = (e) => e === "" || e === void 0 || e === null;
|
|
|
+ function te() {
|
|
|
if (!D.value && d.value.length) return s(d.value[0], 0);
|
|
|
- const e = v();
|
|
|
+ const e = f();
|
|
|
return e.length ? e[0].dataset.value : "";
|
|
|
}
|
|
|
- function te() {
|
|
|
- return S(u.defaultActiveKey) ? ee() : u.defaultActiveKey;
|
|
|
+ function ne() {
|
|
|
+ return C(u.defaultActiveKey) ? te() : u.defaultActiveKey;
|
|
|
}
|
|
|
- function L() {
|
|
|
- if (!S(l.value)) return !1;
|
|
|
- const e = te();
|
|
|
- return S(e) ? !1 : (l.value = e, !0);
|
|
|
+ function A() {
|
|
|
+ if (!C(l.value)) return !1;
|
|
|
+ const e = ne();
|
|
|
+ return C(e) ? !1 : (l.value = e, !0);
|
|
|
}
|
|
|
- function v() {
|
|
|
- const e = X.value;
|
|
|
+ function f() {
|
|
|
+ const e = N.value;
|
|
|
return e ? Array.from(e.querySelectorAll(".s-tab-item")) : [];
|
|
|
}
|
|
|
- function w() {
|
|
|
- return v().findIndex((e) => e.dataset.value === String(l.value));
|
|
|
+ function m() {
|
|
|
+ return f().findIndex((e) => e.dataset.value === String(l.value));
|
|
|
}
|
|
|
- function K() {
|
|
|
+ function w() {
|
|
|
const e = r.value;
|
|
|
- e && (f.value = e.scrollWidth - e.clientWidth > 1, N.value = e.scrollLeft > 1, O.value = e.scrollLeft + e.clientWidth < e.scrollWidth - 1);
|
|
|
+ e && (g.value = e.scrollWidth - e.clientWidth > 1, O.value = e.scrollLeft > 1, P.value = e.scrollLeft + e.clientWidth < e.scrollWidth - 1);
|
|
|
}
|
|
|
- function ne(e) {
|
|
|
+ function le(e) {
|
|
|
const t = r.value;
|
|
|
if (!t || !e) return;
|
|
|
const n = t.getBoundingClientRect(), a = e.getBoundingClientRect();
|
|
|
let o = null;
|
|
|
- a.left < n.left ? o = t.scrollLeft + (a.left - n.left) - G : a.right > n.right && (o = t.scrollLeft + (a.right - n.right) + G), o !== null && t.scrollTo({ left: Math.max(0, o), behavior: "smooth" });
|
|
|
+ a.left < n.left ? o = t.scrollLeft + (a.left - n.left) - H : a.right > n.right && (o = t.scrollLeft + (a.right - n.right) + H), o !== null && t.scrollTo({ left: Math.max(0, o), behavior: "smooth" });
|
|
|
}
|
|
|
- function p() {
|
|
|
- const e = w();
|
|
|
- e >= 0 && ne(v()[e]);
|
|
|
+ function v() {
|
|
|
+ const e = m();
|
|
|
+ e >= 0 && le(f()[e]);
|
|
|
}
|
|
|
function W(e) {
|
|
|
const t = r.value;
|
|
|
t && t.scrollBy({ left: e * t.clientWidth * u.stepRatio, behavior: "smooth" });
|
|
|
}
|
|
|
- function x(e) {
|
|
|
+ function E(e) {
|
|
|
if (e === l.value) return;
|
|
|
- l.value = e, m("update:activeKey", e);
|
|
|
+ l.value = e, y("update:activeKey", e);
|
|
|
const t = d.value.findIndex((n, a) => s(n, a) === e);
|
|
|
- m("change", e, t >= 0 ? d.value[t] : void 0), k(p);
|
|
|
+ y("change", e, t >= 0 ? d.value[t] : void 0), K(v);
|
|
|
}
|
|
|
- function P() {
|
|
|
- const e = v(), t = w();
|
|
|
+ function T() {
|
|
|
+ const e = f(), t = m();
|
|
|
if (t > 0) {
|
|
|
- x(e[t - 1].dataset.value);
|
|
|
+ E(e[t - 1].dataset.value);
|
|
|
return;
|
|
|
}
|
|
|
W(-1);
|
|
|
}
|
|
|
- function T() {
|
|
|
- const e = v(), t = w();
|
|
|
+ function X() {
|
|
|
+ const e = f(), t = m();
|
|
|
if (t >= 0 && t < e.length - 1) {
|
|
|
- x(e[t + 1].dataset.value);
|
|
|
+ E(e[t + 1].dataset.value);
|
|
|
return;
|
|
|
}
|
|
|
W(1);
|
|
|
}
|
|
|
- function le(e) {
|
|
|
+ function ae(e) {
|
|
|
const t = r.value;
|
|
|
- if (!t || !f.value) return;
|
|
|
+ if (!t || !g.value) return;
|
|
|
const n = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
|
|
|
t.scrollLeft += n;
|
|
|
}
|
|
|
- let i = null, E = !1;
|
|
|
- function ae(e) {
|
|
|
- E = !1, !(!r.value || !f.value) && e.pointerType !== "touch" && e.button === 0 && (i = { id: e.pointerId, startX: e.clientX, lastX: e.clientX, moved: !1 }, window.addEventListener("pointerup", b, !0), window.addEventListener("pointercancel", b, !0));
|
|
|
- }
|
|
|
+ let i = null, S = !1;
|
|
|
function re(e) {
|
|
|
+ S = !1, !(!r.value || !g.value) && e.pointerType !== "touch" && e.button === 0 && (i = { id: e.pointerId, startX: e.clientX, lastX: e.clientX, moved: !1 }, R.value = !0, window.addEventListener("pointermove", B, !0), window.addEventListener("pointerup", x, !0), window.addEventListener("pointercancel", x, !0));
|
|
|
+ }
|
|
|
+ function B(e) {
|
|
|
var n;
|
|
|
if (!i || e.pointerId !== i.id) return;
|
|
|
const t = r.value;
|
|
|
if (t) {
|
|
|
if (!i.moved) {
|
|
|
if (Math.abs(e.clientX - i.startX) < Ke) return;
|
|
|
- i.moved = !0, A.value = !0, (n = t.setPointerCapture) == null || n.call(t, e.pointerId);
|
|
|
+ i.moved = !0, (n = t.setPointerCapture) == null || n.call(t, e.pointerId);
|
|
|
}
|
|
|
t.scrollLeft -= e.clientX - i.lastX, i.lastX = e.clientX;
|
|
|
}
|
|
|
}
|
|
|
- function b() {
|
|
|
+ function x() {
|
|
|
var a;
|
|
|
- if (B(), !i) return;
|
|
|
+ if (I(), !i) return;
|
|
|
const e = r.value, { moved: t, id: n } = i;
|
|
|
- i = null, A.value = !1, (a = e == null ? void 0 : e.hasPointerCapture) != null && a.call(e, n) && e.releasePointerCapture(n), t && (E = !0);
|
|
|
+ i = null, R.value = !1, (a = e == null ? void 0 : e.hasPointerCapture) != null && a.call(e, n) && e.releasePointerCapture(n), t && (S = !0);
|
|
|
}
|
|
|
- function B() {
|
|
|
- window.removeEventListener("pointerup", b, !0), window.removeEventListener("pointercancel", b, !0);
|
|
|
+ function I() {
|
|
|
+ window.removeEventListener("pointermove", B, !0), window.removeEventListener("pointerup", x, !0), window.removeEventListener("pointercancel", x, !0);
|
|
|
}
|
|
|
function oe(e) {
|
|
|
- E && (E = !1, e.preventDefault(), e.stopPropagation());
|
|
|
+ S && (S = !1, e.preventDefault(), e.stopPropagation());
|
|
|
}
|
|
|
- const ie = g(() => w() > 0 || N.value), ue = g(() => {
|
|
|
- const e = w();
|
|
|
- return e >= 0 && e < v().length - 1 || O.value;
|
|
|
+ const ie = h(() => m() > 0 || O.value), ue = h(() => {
|
|
|
+ const e = m();
|
|
|
+ return e >= 0 && e < f().length - 1 || P.value;
|
|
|
});
|
|
|
ce("sTabContext", {
|
|
|
activeValue: l,
|
|
|
- select: x,
|
|
|
- prev: P,
|
|
|
- next: T
|
|
|
- }), I(
|
|
|
+ select: E,
|
|
|
+ prev: T,
|
|
|
+ next: X
|
|
|
+ }), M(
|
|
|
() => u.activeKey,
|
|
|
(e) => {
|
|
|
if (e !== l.value) {
|
|
|
- if (S(e)) {
|
|
|
- L() && m("update:activeKey", l.value), k(p);
|
|
|
+ if (C(e)) {
|
|
|
+ A() && y("update:activeKey", l.value), K(v);
|
|
|
return;
|
|
|
}
|
|
|
- l.value = e, k(p);
|
|
|
+ l.value = e, K(v);
|
|
|
}
|
|
|
}
|
|
|
- ), I(
|
|
|
+ ), M(
|
|
|
() => d.value,
|
|
|
() => {
|
|
|
- k(() => {
|
|
|
- K(), L() && m("update:activeKey", l.value), p();
|
|
|
+ K(() => {
|
|
|
+ w(), A() && y("update:activeKey", l.value), v();
|
|
|
});
|
|
|
},
|
|
|
{ deep: !0 }
|
|
|
);
|
|
|
- let h = null;
|
|
|
- return fe(() => {
|
|
|
- k(() => {
|
|
|
- K(), L() && m("update:activeKey", l.value), p();
|
|
|
- }), window.ResizeObserver && r.value && (h = new ResizeObserver(() => K()), h.observe(r.value), r.value.firstElementChild && h.observe(r.value.firstElementChild));
|
|
|
- }), de(() => {
|
|
|
- B(), h && (h.disconnect(), h = null);
|
|
|
- }), Y({ syncArrow: K, scrollToActive: p, scrollRef: r }), (e, t) => {
|
|
|
- const n = M("left-outlined"), a = M("right-outlined");
|
|
|
- return _(), C("div", {
|
|
|
- class: V(["s-tab", { "is-overflow": f.value, dragging: A.value }])
|
|
|
+ let p = null;
|
|
|
+ return de(() => {
|
|
|
+ K(() => {
|
|
|
+ w(), A() && y("update:activeKey", l.value), v();
|
|
|
+ }), window.ResizeObserver && r.value && (p = new ResizeObserver(() => w()), p.observe(r.value), r.value.firstElementChild && p.observe(r.value.firstElementChild));
|
|
|
+ }), fe(() => {
|
|
|
+ I(), p && (p.disconnect(), p = null);
|
|
|
+ }), q({ syncArrow: w, scrollToActive: v, scrollRef: r }), (e, t) => {
|
|
|
+ const n = V("left-outlined"), a = V("right-outlined");
|
|
|
+ return k(), _("div", {
|
|
|
+ class: $(["s-tab", { dragging: R.value }])
|
|
|
}, [
|
|
|
- f.value ? (_(), C("button", {
|
|
|
+ g.value ? (k(), _("button", {
|
|
|
key: 0,
|
|
|
type: "link",
|
|
|
class: "s-tab-arrow prev",
|
|
|
disabled: !ie.value,
|
|
|
title: e.$l("上一个"),
|
|
|
- onClick: P
|
|
|
+ onClick: T
|
|
|
}, [
|
|
|
- $(n)
|
|
|
- ], 8, ge)) : z("", !0),
|
|
|
- F("div", {
|
|
|
+ z(n)
|
|
|
+ ], 8, ge)) : F("", !0),
|
|
|
+ j("div", {
|
|
|
ref_key: "scrollRef",
|
|
|
ref: r,
|
|
|
class: "s-tab-scroll",
|
|
|
role: "tablist",
|
|
|
- onScroll: K,
|
|
|
- onWheel: R(le, ["prevent"]),
|
|
|
- onPointerdown: ae,
|
|
|
- onPointermove: re,
|
|
|
- onPointerup: b,
|
|
|
- onPointercancel: b,
|
|
|
- onDragstart: t[0] || (t[0] = R(() => {
|
|
|
+ onScroll: w,
|
|
|
+ onWheel: L(ae, ["prevent"]),
|
|
|
+ onPointerdown: re,
|
|
|
+ onDragstart: t[0] || (t[0] = L(() => {
|
|
|
}, ["prevent"])),
|
|
|
onClickCapture: oe
|
|
|
}, [
|
|
|
- F("div", {
|
|
|
+ j("div", {
|
|
|
ref_key: "trackRef",
|
|
|
- ref: X,
|
|
|
+ ref: N,
|
|
|
class: "s-tab-track"
|
|
|
}, [
|
|
|
- D.value ? he(e.$slots, "default", {}, void 0, !0, 1) : (_(!0), C(ve, { key: 0 }, pe(d.value, (o, y) => (_(), C("a", {
|
|
|
- key: s(o, y),
|
|
|
- class: V(["s-tab-item", { active: s(o, y) === l.value }]),
|
|
|
- "data-value": s(o, y),
|
|
|
+ D.value ? he(e.$slots, "default", {}, void 0, !0, 1) : (k(!0), _(ve, { key: 0 }, pe(d.value, (o, b) => (k(), _("a", {
|
|
|
+ key: s(o, b),
|
|
|
+ class: $(["s-tab-item", { active: s(o, b) === l.value }]),
|
|
|
+ "data-value": s(o, b),
|
|
|
role: "tab",
|
|
|
- "aria-selected": s(o, y) === l.value,
|
|
|
- tabindex: s(o, y) === l.value ? 0 : -1,
|
|
|
- onClick: (_e) => x(s(o, y)),
|
|
|
+ "aria-selected": s(o, b) === l.value,
|
|
|
+ tabindex: s(o, b) === l.value ? 0 : -1,
|
|
|
+ onClick: (_e) => E(s(o, b)),
|
|
|
onKeydown: [
|
|
|
- j(R(P, ["prevent"]), ["left"]),
|
|
|
- j(R(T, ["prevent"]), ["right"])
|
|
|
+ G(L(T, ["prevent"]), ["left"]),
|
|
|
+ G(L(X, ["prevent"]), ["right"])
|
|
|
]
|
|
|
- }, be(Z(o)), 43, me))), 128))
|
|
|
+ }, be(ee(o)), 43, me))), 128))
|
|
|
], 512)
|
|
|
], 544),
|
|
|
- f.value ? (_(), C("button", {
|
|
|
+ g.value ? (k(), _("button", {
|
|
|
key: 1,
|
|
|
type: "link",
|
|
|
class: "s-tab-arrow next",
|
|
|
disabled: !ue.value,
|
|
|
title: e.$l("下一个"),
|
|
|
- onClick: T
|
|
|
+ onClick: X
|
|
|
}, [
|
|
|
- $(a)
|
|
|
- ], 8, we)) : z("", !0)
|
|
|
+ z(a)
|
|
|
+ ], 8, we)) : F("", !0)
|
|
|
], 2);
|
|
|
};
|
|
|
}
|
|
|
-}), xe = /* @__PURE__ */ ye(ke, [["__scopeId", "data-v-328b8dcc"]]);
|
|
|
+}), Se = /* @__PURE__ */ ye(ke, [["__scopeId", "data-v-ac556582"]]);
|
|
|
export {
|
|
|
- xe as default
|
|
|
+ Se as default
|
|
|
};
|