vue3-router-tab 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue3-router-tab.js +235 -224
- package/dist/vue3-router-tab.umd.cjs +1 -1
- package/lib/components/RouterTab.vue +40 -23
- package/package.json +1 -1
package/dist/vue3-router-tab.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './vue3-router-tab.css';
|
|
2
|
-
import { reactive as
|
|
2
|
+
import { reactive as me, ref as S, shallowRef as bt, computed as k, watch as P, nextTick as j, inject as Pe, getCurrentInstance as je, onMounted as ge, defineComponent as Oe, provide as pt, onBeforeUnmount as mt, resolveComponent as gt, createElementBlock as x, openBlock as C, createElementVNode as L, withDirectives as vt, normalizeClass as H, renderSlot as re, createVNode as Ae, TransitionGroup as yt, mergeProps as le, withCtx as se, Fragment as ue, renderList as Ee, withModifiers as ce, createCommentVNode as fe, toDisplayString as Ie, createBlock as J, normalizeProps as ht, Transition as Tt, resolveDynamicComponent as de, KeepAlive as kt, normalizeStyle as wt, vShow as Ct, isRef as Rt, isReadonly as Kt } from "vue";
|
|
3
3
|
import { RouterView as Pt } from "vue-router";
|
|
4
4
|
function At(e = {}) {
|
|
5
5
|
return {
|
|
@@ -17,7 +17,7 @@ function V(e, n) {
|
|
|
17
17
|
throw new Error(`[RouterTabs] Unable to resolve route: ${String(n)}`);
|
|
18
18
|
return o;
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const Et = {
|
|
21
21
|
path: (e) => e.path,
|
|
22
22
|
fullpath: (e) => e.fullPath,
|
|
23
23
|
fullname: (e) => e.fullPath,
|
|
@@ -30,16 +30,16 @@ function N(e) {
|
|
|
30
30
|
const o = n(e);
|
|
31
31
|
if (typeof o == "string" && o.length) return o;
|
|
32
32
|
} else if (typeof n == "string" && n.length) {
|
|
33
|
-
const o =
|
|
33
|
+
const o = Et[n.toLowerCase()];
|
|
34
34
|
return o ? o(e) : n;
|
|
35
35
|
}
|
|
36
36
|
return e.fullPath;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function ve(e, n) {
|
|
39
39
|
const o = e.meta?.keepAlive;
|
|
40
40
|
return typeof o == "boolean" ? o : n;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function ye(e, n) {
|
|
43
43
|
const o = e.meta?.reuse;
|
|
44
44
|
return typeof o == "boolean" ? o : n;
|
|
45
45
|
}
|
|
@@ -54,15 +54,15 @@ function q(e, n, o) {
|
|
|
54
54
|
to: e.fullPath,
|
|
55
55
|
fullPath: e.fullPath,
|
|
56
56
|
matched: e,
|
|
57
|
-
alive:
|
|
58
|
-
reusable:
|
|
57
|
+
alive: ve(e, o),
|
|
58
|
+
reusable: ye(e, !1),
|
|
59
59
|
closable: l.closable ?? !0,
|
|
60
60
|
renderKey: typeof n.renderKey == "number" ? n.renderKey : 0,
|
|
61
61
|
...l,
|
|
62
62
|
...n
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function be(e, n, o, l) {
|
|
66
66
|
if (!e.find((p) => p.id === n.id)) {
|
|
67
67
|
if (o === "next" && l) {
|
|
68
68
|
const p = e.findIndex((T) => T.id === l);
|
|
@@ -84,7 +84,7 @@ function xe(e, n, o) {
|
|
|
84
84
|
p > -1 && (e[p].alive = !1);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function It(e) {
|
|
88
88
|
return {
|
|
89
89
|
to: e.to,
|
|
90
90
|
title: e.title,
|
|
@@ -95,39 +95,39 @@ function Et(e) {
|
|
|
95
95
|
renderKey: e.renderKey
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function xt(e) {
|
|
99
99
|
const n = {};
|
|
100
100
|
return "title" in e && (n.title = e.title), "tips" in e && (n.tips = e.tips), "icon" in e && (n.icon = e.icon), "tabClass" in e && (n.tabClass = e.tabClass), "closable" in e && (n.closable = e.closable), "renderKey" in e && typeof e.renderKey == "number" && (n.renderKey = e.renderKey), n;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
const o = At(n), l =
|
|
102
|
+
function $t(e, n = {}) {
|
|
103
|
+
const o = At(n), l = me([]), i = S(null), p = bt(), T = S(null), s = k(
|
|
104
104
|
() => l.filter((r) => r.alive).map((r) => `${r.id}::${r.renderKey ?? 0}`)
|
|
105
105
|
);
|
|
106
106
|
let c = !1;
|
|
107
|
-
function
|
|
107
|
+
function m(r) {
|
|
108
108
|
const b = typeof r.matched == "object" ? r : V(e, r);
|
|
109
109
|
return {
|
|
110
110
|
key: N(b),
|
|
111
111
|
fullPath: b.fullPath,
|
|
112
|
-
alive:
|
|
113
|
-
reusable:
|
|
112
|
+
alive: ve(b, o.keepAlive),
|
|
113
|
+
reusable: ye(b, !1),
|
|
114
114
|
matched: b
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function K(r) {
|
|
118
118
|
const b = N(r);
|
|
119
119
|
let d = l.find((h) => h.id === b);
|
|
120
|
-
return d ? (d.fullPath = r.fullPath, d.to = r.fullPath, d.matched = r, d.alive =
|
|
120
|
+
return d ? (d.fullPath = r.fullPath, d.to = r.fullPath, d.matched = r, d.alive = ve(r, o.keepAlive), d.reusable = ye(r, d.reusable), typeof d.renderKey != "number" && (d.renderKey = 0), Object.assign(d, Ue(r)), d) : (d = q(r, {}, o.keepAlive), be(l, d, o.appendPosition, i.value), xe(l, o.maxAlive, i.value), d);
|
|
121
121
|
}
|
|
122
|
-
async function
|
|
123
|
-
const h = V(e, r), w = N(h),
|
|
124
|
-
d === "sameTab" && (d =
|
|
122
|
+
async function $(r, b = !1, d = !0) {
|
|
123
|
+
const h = V(e, r), w = N(h), A = i.value === w;
|
|
124
|
+
d === "sameTab" && (d = A), d && await O(w, !0), await e[b ? "replace" : "push"](h), A && await y();
|
|
125
125
|
}
|
|
126
126
|
function B(r) {
|
|
127
127
|
const b = l.findIndex((I) => I.id === r);
|
|
128
128
|
if (b === -1) return o.defaultRoute;
|
|
129
|
-
const d = l[b + 1], h = l[b - 1], w = l.find((I) => I.id !== r),
|
|
130
|
-
return
|
|
129
|
+
const d = l[b + 1], h = l[b - 1], w = l.find((I) => I.id !== r), A = d || h || w;
|
|
130
|
+
return A ? A.to : o.defaultRoute;
|
|
131
131
|
}
|
|
132
132
|
async function z(r = i.value, b = {}) {
|
|
133
133
|
if (!r) return;
|
|
@@ -169,7 +169,7 @@ function xt(e, n = {}) {
|
|
|
169
169
|
function M() {
|
|
170
170
|
const r = l.find((b) => b.id === i.value);
|
|
171
171
|
return {
|
|
172
|
-
tabs: l.map(
|
|
172
|
+
tabs: l.map(It),
|
|
173
173
|
active: r ? r.to : null
|
|
174
174
|
};
|
|
175
175
|
}
|
|
@@ -178,8 +178,8 @@ function xt(e, n = {}) {
|
|
|
178
178
|
const b = r?.tabs ?? [];
|
|
179
179
|
for (const h of b)
|
|
180
180
|
try {
|
|
181
|
-
const w = V(e, h.to),
|
|
182
|
-
|
|
181
|
+
const w = V(e, h.to), A = xt(h), I = q(w, A, o.keepAlive);
|
|
182
|
+
be(l, I, "last", null);
|
|
183
183
|
} catch {
|
|
184
184
|
}
|
|
185
185
|
c = !1;
|
|
@@ -190,17 +190,17 @@ function xt(e, n = {}) {
|
|
|
190
190
|
} catch {
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
return
|
|
193
|
+
return P(
|
|
194
194
|
() => e.currentRoute.value,
|
|
195
195
|
(r) => {
|
|
196
196
|
if (c) return;
|
|
197
|
-
const b =
|
|
197
|
+
const b = K(r);
|
|
198
198
|
i.value = b.id, p.value = b, xe(l, o.maxAlive, i.value);
|
|
199
199
|
},
|
|
200
200
|
{ immediate: !0 }
|
|
201
201
|
), o.initialTabs.length && o.initialTabs.forEach((r) => {
|
|
202
202
|
const b = V(e, r.to), d = q(b, r, o.keepAlive);
|
|
203
|
-
|
|
203
|
+
be(l, d, "last", null);
|
|
204
204
|
}), {
|
|
205
205
|
options: o,
|
|
206
206
|
tabs: l,
|
|
@@ -208,7 +208,7 @@ function xt(e, n = {}) {
|
|
|
208
208
|
current: p,
|
|
209
209
|
includeKeys: s,
|
|
210
210
|
refreshingKey: T,
|
|
211
|
-
openTab:
|
|
211
|
+
openTab: $,
|
|
212
212
|
closeTab: z,
|
|
213
213
|
removeTab: _,
|
|
214
214
|
refreshTab: O,
|
|
@@ -216,19 +216,19 @@ function xt(e, n = {}) {
|
|
|
216
216
|
reset: ne,
|
|
217
217
|
reload: y,
|
|
218
218
|
getRouteKey: G,
|
|
219
|
-
matchRoute:
|
|
219
|
+
matchRoute: m,
|
|
220
220
|
snapshot: M,
|
|
221
221
|
hydrate: D
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
-
function
|
|
224
|
+
function $e(e) {
|
|
225
225
|
return e ? typeof e == "string" ? { name: e } : e : {};
|
|
226
226
|
}
|
|
227
227
|
const ee = Symbol("RouterTabsContext"), Z = "router-tabs:snapshot";
|
|
228
|
-
function
|
|
229
|
-
const { optional: n = !1 } = e, o =
|
|
228
|
+
function De(e = {}) {
|
|
229
|
+
const { optional: n = !1 } = e, o = Pe(ee, null);
|
|
230
230
|
if (o) return o;
|
|
231
|
-
const l =
|
|
231
|
+
const l = Pe("$tabs", null);
|
|
232
232
|
if (l) return l;
|
|
233
233
|
const p = je()?.appContext.config.globalProperties.$tabs;
|
|
234
234
|
if (p) return p;
|
|
@@ -245,7 +245,7 @@ function St(e) {
|
|
|
245
245
|
return decodeURIComponent(l.slice(n.length));
|
|
246
246
|
return null;
|
|
247
247
|
}
|
|
248
|
-
function
|
|
248
|
+
function Se(e, n, o) {
|
|
249
249
|
if (typeof document > "u") return;
|
|
250
250
|
const {
|
|
251
251
|
expiresInDays: l = 7,
|
|
@@ -255,8 +255,8 @@ function $e(e, n, o) {
|
|
|
255
255
|
sameSite: s = "lax"
|
|
256
256
|
} = o, c = [`${encodeURIComponent(e)}=${encodeURIComponent(n)}`];
|
|
257
257
|
if (l !== 1 / 0) {
|
|
258
|
-
const
|
|
259
|
-
c.push(`Expires=${
|
|
258
|
+
const m = new Date(Date.now() + l * Dt).toUTCString();
|
|
259
|
+
c.push(`Expires=${m}`);
|
|
260
260
|
}
|
|
261
261
|
i && c.push(`Path=${i}`), p && c.push(`Domain=${p}`), T && c.push("Secure"), s && c.push(`SameSite=${s.charAt(0).toUpperCase()}${s.slice(1)}`), document.cookie = c.join("; ");
|
|
262
262
|
}
|
|
@@ -265,7 +265,7 @@ function Be(e, n) {
|
|
|
265
265
|
const { path: o = "/", domain: l } = n, i = [`${encodeURIComponent(e)}=`];
|
|
266
266
|
i.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"), o && i.push(`Path=${o}`), l && i.push(`Domain=${l}`), document.cookie = i.join("; ");
|
|
267
267
|
}
|
|
268
|
-
const
|
|
268
|
+
const Bt = (e) => JSON.stringify(e ?? null), Mt = (e) => {
|
|
269
269
|
if (!e) return null;
|
|
270
270
|
try {
|
|
271
271
|
return JSON.parse(e);
|
|
@@ -276,17 +276,17 @@ const $t = (e) => JSON.stringify(e ?? null), Bt = (e) => {
|
|
|
276
276
|
function Ve(e = {}) {
|
|
277
277
|
const {
|
|
278
278
|
cookieKey: n = Z,
|
|
279
|
-
serialize: o =
|
|
280
|
-
deserialize: l =
|
|
281
|
-
} = e, i =
|
|
282
|
-
|
|
279
|
+
serialize: o = Bt,
|
|
280
|
+
deserialize: l = Mt
|
|
281
|
+
} = e, i = De({ optional: !0 }), p = S(!0), T = (s) => {
|
|
282
|
+
ge(async () => {
|
|
283
283
|
const c = l(St(n));
|
|
284
284
|
if (c && c.tabs?.length)
|
|
285
285
|
try {
|
|
286
286
|
if (p.value = !0, await s.hydrate(c), c.active) {
|
|
287
287
|
await j();
|
|
288
|
-
const
|
|
289
|
-
|
|
288
|
+
const K = s.tabs.find(($) => $.to === c.active);
|
|
289
|
+
K && (s.activeId.value = K.id, s.current.value = K);
|
|
290
290
|
}
|
|
291
291
|
} finally {
|
|
292
292
|
p.value = !1;
|
|
@@ -294,16 +294,16 @@ function Ve(e = {}) {
|
|
|
294
294
|
else if (Object.prototype.hasOwnProperty.call(e, "fallbackRoute"))
|
|
295
295
|
try {
|
|
296
296
|
p.value = !0;
|
|
297
|
-
const
|
|
298
|
-
await s.reset(
|
|
297
|
+
const K = e.fallbackRoute ?? s.options.defaultRoute;
|
|
298
|
+
await s.reset(K);
|
|
299
299
|
} finally {
|
|
300
300
|
p.value = !1;
|
|
301
301
|
}
|
|
302
302
|
else
|
|
303
303
|
p.value = !1;
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
}),
|
|
304
|
+
const m = s.snapshot();
|
|
305
|
+
m.tabs.length ? Se(n, o(m), e) : Be(n, e), p.value = !1;
|
|
306
|
+
}), P(
|
|
307
307
|
() => ({
|
|
308
308
|
tabs: s.tabs.map((c) => ({
|
|
309
309
|
to: c.to,
|
|
@@ -319,17 +319,17 @@ function Ve(e = {}) {
|
|
|
319
319
|
() => {
|
|
320
320
|
if (p.value) return;
|
|
321
321
|
const c = s.snapshot();
|
|
322
|
-
c.tabs.length ?
|
|
322
|
+
c.tabs.length ? Se(n, o(c), e) : Be(n, e);
|
|
323
323
|
},
|
|
324
324
|
{ deep: !0 }
|
|
325
325
|
);
|
|
326
326
|
};
|
|
327
|
-
i ? T(i) :
|
|
328
|
-
const s =
|
|
327
|
+
i ? T(i) : ge(() => {
|
|
328
|
+
const s = De({ optional: !0 });
|
|
329
329
|
s && T(s);
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
|
-
const
|
|
332
|
+
const Lt = Oe({
|
|
333
333
|
name: "RouterTab",
|
|
334
334
|
components: { RouterView: Pt },
|
|
335
335
|
props: {
|
|
@@ -390,7 +390,7 @@ const Mt = Oe({
|
|
|
390
390
|
const l = o.appContext.app.config.globalProperties.$router;
|
|
391
391
|
if (!l)
|
|
392
392
|
throw new Error("[RouterTab] Vue Router is required. Make sure to call app.use(router) before RouterTab.");
|
|
393
|
-
const i =
|
|
393
|
+
const i = $t(l, {
|
|
394
394
|
initialTabs: e.tabs,
|
|
395
395
|
keepAlive: e.keepAlive,
|
|
396
396
|
maxAlive: e.maxAlive,
|
|
@@ -398,8 +398,8 @@ const Mt = Oe({
|
|
|
398
398
|
appendPosition: e.append,
|
|
399
399
|
defaultRoute: e.defaultPage
|
|
400
400
|
});
|
|
401
|
-
|
|
402
|
-
const p = k(() => !!o?.slots?.default), T = k(() => !!o?.slots?.start), s = k(() => !!o?.slots?.end), c =
|
|
401
|
+
pt(ee, i), o.appContext.config.globalProperties.$tabs = i;
|
|
402
|
+
const p = k(() => !!o?.slots?.default), T = k(() => !!o?.slots?.start), s = k(() => !!o?.slots?.end), c = S(0), m = k(() => {
|
|
403
403
|
c.value;
|
|
404
404
|
const t = {};
|
|
405
405
|
return i.tabs.forEach((a) => {
|
|
@@ -407,18 +407,18 @@ const Mt = Oe({
|
|
|
407
407
|
t[a.id] = f;
|
|
408
408
|
}), t;
|
|
409
409
|
});
|
|
410
|
-
function
|
|
410
|
+
function K() {
|
|
411
411
|
c.value++;
|
|
412
412
|
}
|
|
413
|
-
const
|
|
413
|
+
const $ = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map();
|
|
414
414
|
function z(t, a) {
|
|
415
|
-
if (!a ||
|
|
416
|
-
|
|
415
|
+
if (!a || $.has(t)) return;
|
|
416
|
+
$.set(t, a);
|
|
417
417
|
const f = i.tabs.find((v) => i.getRouteKey(v.to) === t);
|
|
418
418
|
if (!f) return;
|
|
419
|
-
const
|
|
419
|
+
const g = [];
|
|
420
420
|
if (a.routeTabTitle !== void 0) {
|
|
421
|
-
const v =
|
|
421
|
+
const v = P(
|
|
422
422
|
() => {
|
|
423
423
|
const u = a.routeTabTitle;
|
|
424
424
|
return u && typeof u == "object" && "value" in u ? u.value : u;
|
|
@@ -426,57 +426,57 @@ const Mt = Oe({
|
|
|
426
426
|
(u) => {
|
|
427
427
|
if (u != null) {
|
|
428
428
|
const U = String(u);
|
|
429
|
-
f.title = U,
|
|
429
|
+
f.title = U, K();
|
|
430
430
|
}
|
|
431
431
|
},
|
|
432
432
|
{ immediate: !0 }
|
|
433
433
|
);
|
|
434
|
-
|
|
434
|
+
g.push(v);
|
|
435
435
|
}
|
|
436
436
|
if (a.routeTabIcon !== void 0) {
|
|
437
|
-
const v =
|
|
437
|
+
const v = P(
|
|
438
438
|
() => {
|
|
439
439
|
const u = a.routeTabIcon;
|
|
440
440
|
return u && typeof u == "object" && "value" in u ? u.value : u;
|
|
441
441
|
},
|
|
442
442
|
(u) => {
|
|
443
|
-
u != null && (f.icon = String(u),
|
|
443
|
+
u != null && (f.icon = String(u), K());
|
|
444
444
|
},
|
|
445
445
|
{ immediate: !0 }
|
|
446
446
|
);
|
|
447
|
-
|
|
447
|
+
g.push(v);
|
|
448
448
|
}
|
|
449
449
|
if (a.routeTabClosable !== void 0) {
|
|
450
|
-
const v =
|
|
450
|
+
const v = P(
|
|
451
451
|
() => {
|
|
452
452
|
const u = a.routeTabClosable;
|
|
453
453
|
return u && typeof u == "object" && "value" in u ? u.value : u;
|
|
454
454
|
},
|
|
455
455
|
(u) => {
|
|
456
|
-
u != null && (f.closable = !!u,
|
|
456
|
+
u != null && (f.closable = !!u, K());
|
|
457
457
|
},
|
|
458
458
|
{ immediate: !0 }
|
|
459
459
|
);
|
|
460
|
-
|
|
460
|
+
g.push(v);
|
|
461
461
|
}
|
|
462
462
|
if (a.routeTabMeta !== void 0) {
|
|
463
|
-
const v =
|
|
463
|
+
const v = P(
|
|
464
464
|
() => {
|
|
465
465
|
const u = a.routeTabMeta;
|
|
466
466
|
return u && typeof u == "object" && "value" in u ? u.value : u;
|
|
467
467
|
},
|
|
468
468
|
(u) => {
|
|
469
|
-
u && typeof u == "object" && (Object.assign(f, u),
|
|
469
|
+
u && typeof u == "object" && (Object.assign(f, u), K());
|
|
470
470
|
},
|
|
471
471
|
{ immediate: !0, deep: !0 }
|
|
472
472
|
);
|
|
473
|
-
|
|
473
|
+
g.push(v);
|
|
474
474
|
}
|
|
475
|
-
B.set(t,
|
|
475
|
+
B.set(t, g);
|
|
476
476
|
}
|
|
477
477
|
function _(t) {
|
|
478
478
|
const a = B.get(t);
|
|
479
|
-
a && (a.forEach((f) => f()), B.delete(t)),
|
|
479
|
+
a && (a.forEach((f) => f()), B.delete(t)), $.delete(t);
|
|
480
480
|
}
|
|
481
481
|
function O(t, a) {
|
|
482
482
|
t ? t.routeTabTitle !== void 0 || t.routeTabIcon !== void 0 || t.routeTabClosable !== void 0 ? z(a, t) : t.$ && (t.$.routeTabTitle !== void 0 || t.$.routeTabIcon !== void 0 || t.$.routeTabClosable !== void 0) && z(a, t.$) : t === null && _(a);
|
|
@@ -487,11 +487,11 @@ const Mt = Oe({
|
|
|
487
487
|
};
|
|
488
488
|
e.cookieKey !== null ? t.cookieKey = e.cookieKey || Z : t.cookieKey || (t.cookieKey = Z), Ve(t);
|
|
489
489
|
}
|
|
490
|
-
const te = k(() =>
|
|
490
|
+
const te = k(() => $e(e.tabTransition)), ne = k(() => $e(e.pageTransition)), y = me({
|
|
491
491
|
visible: !1,
|
|
492
492
|
target: null,
|
|
493
493
|
position: { x: 0, y: 0 }
|
|
494
|
-
}), G =
|
|
494
|
+
}), G = S(null), M = S([]), D = S(-1), r = me({
|
|
495
495
|
dragging: !1,
|
|
496
496
|
dragIndex: -1,
|
|
497
497
|
dropIndex: -1,
|
|
@@ -515,14 +515,14 @@ const Mt = Oe({
|
|
|
515
515
|
const a = d(t.id);
|
|
516
516
|
return a > -1 ? i.tabs.slice(a + 1) : [];
|
|
517
517
|
}
|
|
518
|
-
function
|
|
518
|
+
function A(t) {
|
|
519
519
|
return i.tabs.filter((a) => a.id !== t.id);
|
|
520
520
|
}
|
|
521
521
|
async function I(t, a) {
|
|
522
|
-
const f = t.filter((
|
|
522
|
+
const f = t.filter((g) => g.closable !== !1);
|
|
523
523
|
if (f.length) {
|
|
524
|
-
for (const
|
|
525
|
-
i.activeId.value ===
|
|
524
|
+
for (const g of f)
|
|
525
|
+
i.activeId.value === g.id ? await i.closeTab(g.id, { redirect: a.to, force: !0 }) : await i.removeTab(g.id, { force: !0 });
|
|
526
526
|
i.activeId.value !== a.id && await i.openTab(a.to, !0, !1);
|
|
527
527
|
}
|
|
528
528
|
}
|
|
@@ -563,9 +563,9 @@ const Mt = Oe({
|
|
|
563
563
|
closeOthers: {
|
|
564
564
|
label: "Close Others",
|
|
565
565
|
handler: async ({ target: t }) => {
|
|
566
|
-
await I(
|
|
566
|
+
await I(A(t), t);
|
|
567
567
|
},
|
|
568
|
-
enable: ({ target: t }) =>
|
|
568
|
+
enable: ({ target: t }) => A(t).some((a) => a.closable !== !1)
|
|
569
569
|
}
|
|
570
570
|
};
|
|
571
571
|
function E() {
|
|
@@ -579,18 +579,18 @@ const Mt = Oe({
|
|
|
579
579
|
}));
|
|
580
580
|
}
|
|
581
581
|
function Je(t, a) {
|
|
582
|
-
const f = typeof t == "string" ? { id: t } : t,
|
|
582
|
+
const f = typeof t == "string" ? { id: t } : t, g = Fe[f.id], v = f.label ?? g?.label ?? String(f.id), u = f.visible ?? g?.visible ?? !0;
|
|
583
583
|
if (!(typeof u == "function" ? u(a) : u !== !1)) return null;
|
|
584
|
-
const ie = f.enable ??
|
|
585
|
-
if (!
|
|
586
|
-
const
|
|
587
|
-
await Promise.resolve(
|
|
584
|
+
const ie = f.enable ?? g?.enable ?? !0, ft = typeof ie == "function" ? ie(a) : ie !== !1, Ke = f.handler ?? g?.handler;
|
|
585
|
+
if (!Ke) return null;
|
|
586
|
+
const dt = async () => {
|
|
587
|
+
await Promise.resolve(Ke(a));
|
|
588
588
|
};
|
|
589
589
|
return {
|
|
590
590
|
id: String(f.id),
|
|
591
591
|
label: v,
|
|
592
|
-
disabled: !
|
|
593
|
-
action:
|
|
592
|
+
disabled: !ft,
|
|
593
|
+
action: dt
|
|
594
594
|
};
|
|
595
595
|
}
|
|
596
596
|
const Y = k(() => {
|
|
@@ -601,12 +601,13 @@ const Mt = Oe({
|
|
|
601
601
|
function We() {
|
|
602
602
|
const t = G.value;
|
|
603
603
|
if (!t) return;
|
|
604
|
-
const a = 8, { innerWidth: f, innerHeight:
|
|
604
|
+
const a = 8, { innerWidth: f, innerHeight: g } = window, v = t.getBoundingClientRect();
|
|
605
605
|
let u = y.position.x, U = y.position.y;
|
|
606
|
-
v.right > f - a && (u = Math.max(a, f - v.width - a)), v.bottom >
|
|
606
|
+
v.right > f - a && (u = Math.max(a, f - v.width - a)), v.bottom > g - a && (U = Math.max(a, g - v.height - a)), (u !== y.position.x || U !== y.position.y) && (y.position.x = u, y.position.y = U);
|
|
607
607
|
}
|
|
608
608
|
function Ge(t, a) {
|
|
609
|
-
|
|
609
|
+
const f = t?.$el || t;
|
|
610
|
+
M.value[a] = f ?? null;
|
|
610
611
|
}
|
|
611
612
|
function Xe(t) {
|
|
612
613
|
if (t < 0) return;
|
|
@@ -614,16 +615,16 @@ const Mt = Oe({
|
|
|
614
615
|
}
|
|
615
616
|
function X(t, a, f = Y.value) {
|
|
616
617
|
if (!f.length) return -1;
|
|
617
|
-
const
|
|
618
|
+
const g = f.length;
|
|
618
619
|
let v = t;
|
|
619
|
-
for (let u = 0; u <
|
|
620
|
-
if (v = (v + a +
|
|
620
|
+
for (let u = 0; u < g; u++)
|
|
621
|
+
if (v = (v + a + g) % g, !f[v].disabled) return v;
|
|
621
622
|
return -1;
|
|
622
623
|
}
|
|
623
624
|
function F(t) {
|
|
624
625
|
D.value = t, !(t < 0) && j(() => Xe(t));
|
|
625
626
|
}
|
|
626
|
-
function
|
|
627
|
+
function ke(t) {
|
|
627
628
|
const a = X(D.value, t);
|
|
628
629
|
a !== -1 && F(a);
|
|
629
630
|
}
|
|
@@ -650,11 +651,11 @@ const Mt = Oe({
|
|
|
650
651
|
switch (t.preventDefault(), a) {
|
|
651
652
|
case "ArrowDown":
|
|
652
653
|
case "ArrowRight":
|
|
653
|
-
|
|
654
|
+
ke(1);
|
|
654
655
|
break;
|
|
655
656
|
case "ArrowUp":
|
|
656
657
|
case "ArrowLeft":
|
|
657
|
-
|
|
658
|
+
ke(-1);
|
|
658
659
|
break;
|
|
659
660
|
case "Home":
|
|
660
661
|
F(X(-1, 1));
|
|
@@ -668,7 +669,7 @@ const Mt = Oe({
|
|
|
668
669
|
const v = D.value;
|
|
669
670
|
if (v > -1) {
|
|
670
671
|
const u = f[v];
|
|
671
|
-
u.disabled ||
|
|
672
|
+
u.disabled || we(u);
|
|
672
673
|
}
|
|
673
674
|
break;
|
|
674
675
|
}
|
|
@@ -677,21 +678,24 @@ const Mt = Oe({
|
|
|
677
678
|
break;
|
|
678
679
|
}
|
|
679
680
|
}
|
|
680
|
-
async function
|
|
681
|
+
async function we(t) {
|
|
681
682
|
t.disabled || (E(), await t.action());
|
|
682
683
|
}
|
|
683
684
|
function oe(t) {
|
|
684
685
|
return typeof t.title == "string" && t.title.trim() ? t.title : Array.isArray(t.title) && t.title.length && String(t.title[0]).trim() ? String(t.title[0]) : "Untitled";
|
|
685
686
|
}
|
|
686
687
|
function Qe(t) {
|
|
687
|
-
return
|
|
688
|
+
return m.value[t.id] || oe(t);
|
|
688
689
|
}
|
|
689
|
-
function
|
|
690
|
-
const a = i.getRouteKey(t),
|
|
691
|
-
|
|
690
|
+
function Ce(t) {
|
|
691
|
+
const a = i.getRouteKey(t), f = i.tabs.find((v) => v.id === a);
|
|
692
|
+
if (!f)
|
|
693
|
+
return console.warn(`[RouterTab] Tab not found for key: ${a}. This may cause rendering issues.`), `${a}::0`;
|
|
694
|
+
const g = f.renderKey ?? 0;
|
|
695
|
+
return `${a}::${g}`;
|
|
692
696
|
}
|
|
693
697
|
function Ze(t) {
|
|
694
|
-
return `${
|
|
698
|
+
return `${Ce(t)}::refresh`;
|
|
695
699
|
}
|
|
696
700
|
function ae(t) {
|
|
697
701
|
return !(t.closable === !1 || i.options.keepLastTab && i.tabs.length <= 1);
|
|
@@ -721,19 +725,23 @@ const Mt = Oe({
|
|
|
721
725
|
function ot(t) {
|
|
722
726
|
return i.refreshingKey.value === i.getRouteKey(t);
|
|
723
727
|
}
|
|
724
|
-
function at(t
|
|
728
|
+
function at(t) {
|
|
729
|
+
const a = i.getRouteKey(t);
|
|
730
|
+
return i.tabs.some((f) => f.id === a);
|
|
731
|
+
}
|
|
732
|
+
function it(t, a, f) {
|
|
725
733
|
e.sortable && (r.dragging = !0, r.dragIndex = a, r.dragTab = t, f.dataTransfer && (f.dataTransfer.effectAllowed = "move", f.dataTransfer.setData("text/plain", t.id)), n("tab-sort", { tab: t, index: a }));
|
|
726
734
|
}
|
|
727
|
-
function
|
|
735
|
+
function rt(t, a) {
|
|
728
736
|
!e.sortable || !r.dragging || (a.preventDefault(), a.dataTransfer && (a.dataTransfer.dropEffect = "move"));
|
|
729
737
|
}
|
|
730
|
-
function
|
|
738
|
+
function lt(t) {
|
|
731
739
|
!e.sortable || !r.dragging || (r.dropIndex = t);
|
|
732
740
|
}
|
|
733
|
-
function
|
|
741
|
+
function st() {
|
|
734
742
|
!e.sortable || r.dragging;
|
|
735
743
|
}
|
|
736
|
-
function
|
|
744
|
+
function ut(t, a) {
|
|
737
745
|
if (!(!e.sortable || !r.dragging)) {
|
|
738
746
|
if (a.preventDefault(), r.dragIndex !== -1 && r.dragIndex !== t) {
|
|
739
747
|
const f = i.tabs.splice(r.dragIndex, 1)[0];
|
|
@@ -743,54 +751,54 @@ const Mt = Oe({
|
|
|
743
751
|
toIndex: t
|
|
744
752
|
});
|
|
745
753
|
}
|
|
746
|
-
|
|
754
|
+
Re();
|
|
747
755
|
}
|
|
748
756
|
}
|
|
749
|
-
function
|
|
757
|
+
function Re() {
|
|
750
758
|
r.dragging = !1, r.dragIndex = -1, r.dropIndex = -1, r.dragTab = null;
|
|
751
759
|
}
|
|
752
|
-
|
|
760
|
+
ge(() => {
|
|
753
761
|
document.addEventListener("keydown", E);
|
|
754
|
-
}),
|
|
762
|
+
}), mt(() => {
|
|
755
763
|
document.removeEventListener("keydown", E), o.appContext.config.globalProperties.$tabs = null, B.forEach((t) => {
|
|
756
764
|
t.forEach((a) => a());
|
|
757
|
-
}), B.clear(),
|
|
758
|
-
}),
|
|
765
|
+
}), B.clear(), $.clear();
|
|
766
|
+
}), P(
|
|
759
767
|
() => e.keepAlive,
|
|
760
768
|
(t) => {
|
|
761
769
|
i.options.keepAlive = t;
|
|
762
770
|
}
|
|
763
|
-
),
|
|
771
|
+
), P(
|
|
764
772
|
() => i.activeId.value,
|
|
765
773
|
() => E()
|
|
766
|
-
),
|
|
774
|
+
), P(
|
|
767
775
|
() => e.contextmenu,
|
|
768
776
|
(t) => {
|
|
769
777
|
t || E();
|
|
770
778
|
}
|
|
771
|
-
),
|
|
779
|
+
), P(
|
|
772
780
|
() => Y.value.length,
|
|
773
781
|
(t) => {
|
|
774
782
|
y.visible && t === 0 && E();
|
|
775
783
|
},
|
|
776
784
|
{ flush: "post" }
|
|
777
785
|
// Run after component updates to prevent blocking render
|
|
778
|
-
),
|
|
786
|
+
), P(Y, (t) => {
|
|
779
787
|
if (!y.visible) return;
|
|
780
788
|
M.value = new Array(t.length).fill(null);
|
|
781
789
|
const a = X(-1, 1, t);
|
|
782
790
|
F(a);
|
|
783
|
-
}, { flush: "post" }),
|
|
791
|
+
}, { flush: "post" }), P(
|
|
784
792
|
() => y.visible,
|
|
785
793
|
(t) => {
|
|
786
794
|
t || (D.value = -1, M.value = []);
|
|
787
795
|
}
|
|
788
796
|
);
|
|
789
|
-
const
|
|
797
|
+
const ct = i.includeKeys;
|
|
790
798
|
return {
|
|
791
799
|
controller: i,
|
|
792
800
|
tabs: i.tabs,
|
|
793
|
-
includeKeys:
|
|
801
|
+
includeKeys: ct,
|
|
794
802
|
tabTransitionProps: te,
|
|
795
803
|
pageTransitionProps: ne,
|
|
796
804
|
buildTabClass: nt,
|
|
@@ -798,28 +806,29 @@ const Mt = Oe({
|
|
|
798
806
|
close: et,
|
|
799
807
|
context: y,
|
|
800
808
|
menuItems: Y,
|
|
801
|
-
handleMenuAction:
|
|
809
|
+
handleMenuAction: we,
|
|
802
810
|
showContextMenu: He,
|
|
803
811
|
hideContextMenu: E,
|
|
804
812
|
getTabTitle: oe,
|
|
805
813
|
isClosable: ae,
|
|
806
814
|
isRefreshing: ot,
|
|
815
|
+
isTabReady: at,
|
|
807
816
|
hasCustomSlot: p,
|
|
808
817
|
hasStartSlot: T,
|
|
809
818
|
hasEndSlot: s,
|
|
810
|
-
onDragStart:
|
|
811
|
-
onDragOver:
|
|
812
|
-
onDragEnter:
|
|
813
|
-
onDragLeave:
|
|
814
|
-
onDrop:
|
|
815
|
-
onDragEnd:
|
|
819
|
+
onDragStart: it,
|
|
820
|
+
onDragOver: rt,
|
|
821
|
+
onDragEnter: lt,
|
|
822
|
+
onDragLeave: st,
|
|
823
|
+
onDrop: ut,
|
|
824
|
+
onDragEnd: Re,
|
|
816
825
|
setupComponentWatching: z,
|
|
817
826
|
cleanupComponentWatching: _,
|
|
818
827
|
handleComponentRef: O,
|
|
819
828
|
getReactiveTabTitle: Qe,
|
|
820
|
-
getComponentCacheKey:
|
|
829
|
+
getComponentCacheKey: Ce,
|
|
821
830
|
getRefreshComponentKey: Ze,
|
|
822
|
-
triggerTabUpdate:
|
|
831
|
+
triggerTabUpdate: K,
|
|
823
832
|
menuRef: G,
|
|
824
833
|
highlightedIndex: D,
|
|
825
834
|
setMenuItemRef: Ge,
|
|
@@ -827,56 +836,56 @@ const Mt = Oe({
|
|
|
827
836
|
highlightMenuIndex: F
|
|
828
837
|
};
|
|
829
838
|
}
|
|
830
|
-
}),
|
|
839
|
+
}), jt = (e, n) => {
|
|
831
840
|
const o = e.__vccOpts || e;
|
|
832
841
|
for (const [l, i] of n)
|
|
833
842
|
o[l] = i;
|
|
834
843
|
return o;
|
|
835
|
-
},
|
|
836
|
-
function
|
|
844
|
+
}, Ot = { class: "router-tab" }, Ut = { class: "router-tab__header" }, Vt = { class: "router-tab__scroll" }, Nt = ["data-title", "draggable", "onClick", "onAuxclick", "onContextmenu", "onDragstart", "onDragover", "onDragenter", "onDrop"], zt = ["title"], _t = ["onClick"], Yt = { class: "router-tab__container" }, Ft = ["aria-disabled", "disabled", "tabindex", "onMouseenter", "onClick"];
|
|
845
|
+
function Ht(e, n, o, l, i, p) {
|
|
837
846
|
const T = gt("RouterView");
|
|
838
|
-
return
|
|
839
|
-
L("header",
|
|
847
|
+
return C(), x("div", Ot, [
|
|
848
|
+
L("header", Ut, [
|
|
840
849
|
L("div", {
|
|
841
850
|
class: H(["router-tab__slot-start", { "has-content": e.hasStartSlot }])
|
|
842
851
|
}, [
|
|
843
852
|
re(e.$slots, "start")
|
|
844
853
|
], 2),
|
|
845
|
-
L("div",
|
|
846
|
-
|
|
854
|
+
L("div", Vt, [
|
|
855
|
+
Ae(yt, le({
|
|
847
856
|
tag: "ul",
|
|
848
857
|
class: "router-tab__nav"
|
|
849
858
|
}, e.tabTransitionProps), {
|
|
850
859
|
default: se(() => [
|
|
851
|
-
(
|
|
860
|
+
(C(!0), x(ue, null, Ee(e.tabs, (s, c) => (C(), x("li", {
|
|
852
861
|
key: s.id,
|
|
853
862
|
class: H(e.buildTabClass(s)),
|
|
854
863
|
"data-title": e.getTabTitle(s),
|
|
855
864
|
draggable: e.sortable,
|
|
856
|
-
onClick: (
|
|
857
|
-
onAuxclick:
|
|
858
|
-
onContextmenu:
|
|
859
|
-
onDragstart: (
|
|
860
|
-
onDragover: (
|
|
861
|
-
onDragenter: (
|
|
862
|
-
onDragleave: n[0] || (n[0] = (...
|
|
863
|
-
onDrop: (
|
|
864
|
-
onDragend: n[1] || (n[1] = (...
|
|
865
|
+
onClick: (m) => e.activate(s),
|
|
866
|
+
onAuxclick: ce((m) => e.close(s), ["middle", "prevent"]),
|
|
867
|
+
onContextmenu: ce((m) => e.showContextMenu(s, m), ["prevent"]),
|
|
868
|
+
onDragstart: (m) => e.onDragStart(s, c, m),
|
|
869
|
+
onDragover: (m) => e.onDragOver(c, m),
|
|
870
|
+
onDragenter: (m) => e.onDragEnter(c),
|
|
871
|
+
onDragleave: n[0] || (n[0] = (...m) => e.onDragLeave && e.onDragLeave(...m)),
|
|
872
|
+
onDrop: (m) => e.onDrop(c, m),
|
|
873
|
+
onDragend: n[1] || (n[1] = (...m) => e.onDragEnd && e.onDragEnd(...m))
|
|
865
874
|
}, [
|
|
866
|
-
s.icon ? (
|
|
875
|
+
s.icon ? (C(), x("i", {
|
|
867
876
|
key: 0,
|
|
868
877
|
class: H(["router-tab__item-icon", s.icon])
|
|
869
|
-
}, null, 2)) :
|
|
878
|
+
}, null, 2)) : fe("", !0),
|
|
870
879
|
L("span", {
|
|
871
880
|
class: "router-tab__item-title",
|
|
872
881
|
title: e.getReactiveTabTitle(s)
|
|
873
|
-
}, Ie(e.getReactiveTabTitle(s)), 9,
|
|
874
|
-
e.isClosable(s) ? (
|
|
882
|
+
}, Ie(e.getReactiveTabTitle(s)), 9, zt),
|
|
883
|
+
e.isClosable(s) ? (C(), x("a", {
|
|
875
884
|
key: 1,
|
|
876
885
|
class: "router-tab__item-close",
|
|
877
|
-
onClick:
|
|
878
|
-
}, null, 8,
|
|
879
|
-
], 42,
|
|
886
|
+
onClick: ce((m) => e.close(s), ["stop"])
|
|
887
|
+
}, null, 8, _t)) : fe("", !0)
|
|
888
|
+
], 42, Nt))), 128))
|
|
880
889
|
]),
|
|
881
890
|
_: 1
|
|
882
891
|
}, 16)
|
|
@@ -887,35 +896,37 @@ function Ft(e, n, o, l, i, p) {
|
|
|
887
896
|
re(e.$slots, "end")
|
|
888
897
|
], 2)
|
|
889
898
|
]),
|
|
890
|
-
L("div",
|
|
891
|
-
|
|
899
|
+
L("div", Yt, [
|
|
900
|
+
Ae(T, null, {
|
|
892
901
|
default: se((s) => [
|
|
893
|
-
e.hasCustomSlot ? re(e.$slots, "default",
|
|
902
|
+
e.hasCustomSlot ? re(e.$slots, "default", ht(le({ key: 0 }, {
|
|
894
903
|
...s,
|
|
895
904
|
controller: e.controller,
|
|
896
905
|
// Expose a ref binder so custom slots can keep reactivity
|
|
897
906
|
pageRef: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route))
|
|
898
|
-
}))) : (
|
|
907
|
+
}))) : (C(), J(Tt, le({ key: 1 }, e.pageTransitionProps, { appear: "" }), {
|
|
899
908
|
default: se(() => [
|
|
900
|
-
e.
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
909
|
+
s.Component && e.isTabReady(s.route) ? (C(), x(ue, { key: 0 }, [
|
|
910
|
+
e.isRefreshing(s.route) ? (C(), J(de(s.Component), {
|
|
911
|
+
key: e.getRefreshComponentKey(s.route),
|
|
912
|
+
ref: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route)),
|
|
913
|
+
class: "router-tab-page"
|
|
914
|
+
})) : e.controller.options.keepAlive ? (C(), J(kt, {
|
|
915
|
+
key: 1,
|
|
916
|
+
include: e.includeKeys,
|
|
917
|
+
max: e.controller.options.maxAlive || void 0
|
|
918
|
+
}, [
|
|
919
|
+
(C(), J(de(s.Component), {
|
|
920
|
+
key: e.getComponentCacheKey(s.route),
|
|
921
|
+
ref: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route)),
|
|
922
|
+
class: "router-tab-page"
|
|
923
|
+
}))
|
|
924
|
+
], 1032, ["include", "max"])) : (C(), J(de(s.Component), {
|
|
910
925
|
key: e.getComponentCacheKey(s.route),
|
|
911
926
|
ref: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route)),
|
|
912
927
|
class: "router-tab-page"
|
|
913
928
|
}))
|
|
914
|
-
],
|
|
915
|
-
key: e.getComponentCacheKey(s.route),
|
|
916
|
-
ref: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route)),
|
|
917
|
-
class: "router-tab-page"
|
|
918
|
-
}))
|
|
929
|
+
], 64)) : fe("", !0)
|
|
919
930
|
]),
|
|
920
931
|
_: 2
|
|
921
932
|
}, 1040))
|
|
@@ -923,14 +934,14 @@ function Ft(e, n, o, l, i, p) {
|
|
|
923
934
|
_: 3
|
|
924
935
|
})
|
|
925
936
|
]),
|
|
926
|
-
|
|
937
|
+
vt(L("div", {
|
|
927
938
|
ref: "menuRef",
|
|
928
939
|
class: "router-tab__contextmenu",
|
|
929
940
|
role: "menu",
|
|
930
941
|
onKeydown: n[2] || (n[2] = (...s) => e.onMenuKeydown && e.onMenuKeydown(...s)),
|
|
931
|
-
style:
|
|
942
|
+
style: wt({ left: e.context.position.x + "px", top: e.context.position.y + "px" })
|
|
932
943
|
}, [
|
|
933
|
-
(
|
|
944
|
+
(C(!0), x(ue, null, Ee(e.menuItems, (s, c) => (C(), x("a", {
|
|
934
945
|
key: s.id,
|
|
935
946
|
role: "menuitem",
|
|
936
947
|
class: H(["router-tab__contextmenu-item", { "is-focused": c === e.highlightedIndex }]),
|
|
@@ -938,19 +949,19 @@ function Ft(e, n, o, l, i, p) {
|
|
|
938
949
|
disabled: s.disabled,
|
|
939
950
|
tabindex: s.disabled ? -1 : c === e.highlightedIndex ? 0 : -1,
|
|
940
951
|
ref_for: !0,
|
|
941
|
-
ref: (
|
|
942
|
-
onMouseenter: (
|
|
943
|
-
onClick: (
|
|
944
|
-
}, Ie(s.label), 43,
|
|
952
|
+
ref: (m) => e.setMenuItemRef(m, c),
|
|
953
|
+
onMouseenter: (m) => !s.disabled && e.highlightMenuIndex(c),
|
|
954
|
+
onClick: (m) => e.handleMenuAction(s)
|
|
955
|
+
}, Ie(s.label), 43, Ft))), 128))
|
|
945
956
|
], 36), [
|
|
946
|
-
[
|
|
957
|
+
[Ct, e.context.visible && e.context.target]
|
|
947
958
|
])
|
|
948
959
|
]);
|
|
949
960
|
}
|
|
950
|
-
const Me = /* @__PURE__ */ Lt
|
|
961
|
+
const Me = /* @__PURE__ */ jt(Lt, [["render", Ht]]), Jt = {
|
|
951
962
|
class: "router-tabs",
|
|
952
963
|
"aria-hidden": "true"
|
|
953
|
-
},
|
|
964
|
+
}, pe = /* @__PURE__ */ Oe({
|
|
954
965
|
name: "RouterTabs",
|
|
955
966
|
__name: "RouterTabs",
|
|
956
967
|
props: {
|
|
@@ -965,11 +976,11 @@ const Me = /* @__PURE__ */ Lt(Mt, [["render", Ft]]), Ht = {
|
|
|
965
976
|
fallbackRoute: {}
|
|
966
977
|
},
|
|
967
978
|
setup(e) {
|
|
968
|
-
return Ve(e), (o, l) => (
|
|
979
|
+
return Ve(e), (o, l) => (C(), x("span", Jt));
|
|
969
980
|
}
|
|
970
|
-
}), Ne = "tab-theme-style", ze = "tab-theme-primary-color",
|
|
981
|
+
}), Ne = "tab-theme-style", ze = "tab-theme-primary-color", Wt = "system", _e = "(prefers-color-scheme: dark)";
|
|
971
982
|
let W = null;
|
|
972
|
-
const
|
|
983
|
+
const R = {
|
|
973
984
|
primary: "#034960",
|
|
974
985
|
background: "#ffffff",
|
|
975
986
|
text: "#1e293b",
|
|
@@ -983,7 +994,7 @@ const C = {
|
|
|
983
994
|
activeButtonBackground: "#034960",
|
|
984
995
|
activeButtonColor: "#ffffff",
|
|
985
996
|
iconColor: "#475569"
|
|
986
|
-
},
|
|
997
|
+
}, Gt = {
|
|
987
998
|
primary: "#38bdf8",
|
|
988
999
|
background: "#0f172a",
|
|
989
1000
|
text: "#f1f5f9",
|
|
@@ -999,7 +1010,7 @@ const C = {
|
|
|
999
1010
|
activeButtonColor: "#0f172a",
|
|
1000
1011
|
iconColor: "#cbd5e1"
|
|
1001
1012
|
};
|
|
1002
|
-
function
|
|
1013
|
+
function Xt(e) {
|
|
1003
1014
|
if (typeof window > "u") return null;
|
|
1004
1015
|
const n = window.localStorage.getItem(e);
|
|
1005
1016
|
if (!n) return null;
|
|
@@ -1010,8 +1021,8 @@ function Gt(e) {
|
|
|
1010
1021
|
return null;
|
|
1011
1022
|
}
|
|
1012
1023
|
}
|
|
1013
|
-
function
|
|
1014
|
-
typeof document > "u" || (document.documentElement.style.setProperty("--router-tab-primary", e.primary ??
|
|
1024
|
+
function he(e) {
|
|
1025
|
+
typeof document > "u" || (document.documentElement.style.setProperty("--router-tab-primary", e.primary ?? R.primary), document.documentElement.style.setProperty("--router-tab-header-bg", e.headerBackground ?? R.headerBackground), document.documentElement.style.setProperty("--router-tab-background", e.background ?? R.background), document.documentElement.style.setProperty("--router-tab-active-background", e.activeBackground ?? R.activeBackground), document.documentElement.style.setProperty("--router-tab-text", e.text ?? R.text), document.documentElement.style.setProperty("--router-tab-active-text", e.activeText ?? R.activeText), document.documentElement.style.setProperty("--router-tab-border", e.border ?? R.border), document.documentElement.style.setProperty("--router-tab-active-border", e.activeBorder ?? R.activeBorder), document.documentElement.style.setProperty("--router-tab-button-color", e.buttonColor ?? R.buttonColor), document.documentElement.style.setProperty("--router-tab-active-button-color", e.activeButtonColor ?? R.activeButtonColor), document.documentElement.style.setProperty("--router-tab-button-background", e.buttonBackground ?? R.buttonBackground), document.documentElement.style.setProperty("--router-tab-active-button-background", e.activeButtonBackground ?? R.activeButtonBackground), document.documentElement.style.setProperty("--router-tab-icon-color", e.iconColor ?? R.iconColor));
|
|
1015
1026
|
}
|
|
1016
1027
|
function Ye(e) {
|
|
1017
1028
|
if (typeof document > "u") return;
|
|
@@ -1020,36 +1031,36 @@ function Ye(e) {
|
|
|
1020
1031
|
};
|
|
1021
1032
|
W && (o.removeEventListener("change", W), W = null), e === "system" ? (l(), W = () => l(), o.addEventListener("change", W)) : n.dataset.theme = e;
|
|
1022
1033
|
}
|
|
1023
|
-
function
|
|
1034
|
+
function qt(e = {}) {
|
|
1024
1035
|
if (typeof window > "u") return;
|
|
1025
1036
|
const {
|
|
1026
1037
|
styleKey: n = Ne,
|
|
1027
1038
|
primaryKey: o = ze,
|
|
1028
|
-
defaultStyle: l =
|
|
1039
|
+
defaultStyle: l = Wt,
|
|
1029
1040
|
defaultPrimary: i
|
|
1030
1041
|
} = e, p = window.localStorage.getItem(n) ?? l;
|
|
1031
1042
|
Ye(p);
|
|
1032
|
-
const s = p === "dark" || p === "system" && window.matchMedia(_e).matches ? { ...
|
|
1043
|
+
const s = p === "dark" || p === "system" && window.matchMedia(_e).matches ? { ...Gt } : { ...R };
|
|
1033
1044
|
i && (s.primary = i);
|
|
1034
|
-
const c =
|
|
1035
|
-
|
|
1045
|
+
const c = Xt(o);
|
|
1046
|
+
he(c ? {
|
|
1036
1047
|
...s,
|
|
1037
1048
|
...c
|
|
1038
1049
|
} : s);
|
|
1039
1050
|
}
|
|
1040
|
-
function
|
|
1051
|
+
function en(e, n) {
|
|
1041
1052
|
if (typeof window > "u") return;
|
|
1042
1053
|
const o = n?.styleKey ?? Ne;
|
|
1043
1054
|
window.localStorage.setItem(o, e), Ye(e);
|
|
1044
1055
|
}
|
|
1045
|
-
function
|
|
1056
|
+
function tn(e, n) {
|
|
1046
1057
|
if (typeof window > "u") return;
|
|
1047
1058
|
const o = n?.primaryKey ?? ze;
|
|
1048
|
-
window.localStorage.setItem(o, JSON.stringify(e)),
|
|
1059
|
+
window.localStorage.setItem(o, JSON.stringify(e)), he(e);
|
|
1049
1060
|
}
|
|
1050
1061
|
function Q(e, n) {
|
|
1051
|
-
if (
|
|
1052
|
-
const l = !
|
|
1062
|
+
if (Rt(e)) {
|
|
1063
|
+
const l = !Kt(e);
|
|
1053
1064
|
return {
|
|
1054
1065
|
value: e,
|
|
1055
1066
|
update: l ? (i) => {
|
|
@@ -1064,7 +1075,7 @@ function Q(e, n) {
|
|
|
1064
1075
|
update: () => {
|
|
1065
1076
|
}
|
|
1066
1077
|
};
|
|
1067
|
-
const o =
|
|
1078
|
+
const o = S(
|
|
1068
1079
|
e === void 0 ? n : e
|
|
1069
1080
|
);
|
|
1070
1081
|
return {
|
|
@@ -1074,7 +1085,7 @@ function Q(e, n) {
|
|
|
1074
1085
|
}
|
|
1075
1086
|
};
|
|
1076
1087
|
}
|
|
1077
|
-
function
|
|
1088
|
+
function Te(e = {}) {
|
|
1078
1089
|
const n = Q(e.title, "Untitled"), o = Q(e.icon, ""), l = Q(e.closable, !0), i = Q(e.meta, {});
|
|
1079
1090
|
return {
|
|
1080
1091
|
routeTabTitle: n.value,
|
|
@@ -1087,34 +1098,34 @@ function ye(e = {}) {
|
|
|
1087
1098
|
updateMeta: i.update
|
|
1088
1099
|
};
|
|
1089
1100
|
}
|
|
1090
|
-
function
|
|
1091
|
-
return
|
|
1101
|
+
function nn(e, n = "Page") {
|
|
1102
|
+
return Te({
|
|
1092
1103
|
title: k(() => e.value ? "Loading..." : n),
|
|
1093
1104
|
icon: k(() => e.value ? "mdi-loading mdi-spin" : "mdi-page"),
|
|
1094
1105
|
closable: k(() => !e.value)
|
|
1095
1106
|
});
|
|
1096
1107
|
}
|
|
1097
|
-
function
|
|
1098
|
-
return
|
|
1108
|
+
function on(e, n = "Page", o = "mdi-page") {
|
|
1109
|
+
return Te({
|
|
1099
1110
|
title: k(() => e.value > 0 ? `${n} (${e.value})` : n),
|
|
1100
1111
|
icon: k(() => e.value > 0 ? "mdi-bell-badge" : o)
|
|
1101
1112
|
});
|
|
1102
1113
|
}
|
|
1103
|
-
function
|
|
1114
|
+
function an(e, n = "Page") {
|
|
1104
1115
|
const o = {
|
|
1105
1116
|
normal: { suffix: "", icon: "mdi-page" },
|
|
1106
1117
|
loading: { suffix: " - Loading", icon: "mdi-loading mdi-spin" },
|
|
1107
1118
|
error: { suffix: " - Error", icon: "mdi-alert" },
|
|
1108
1119
|
success: { suffix: " - Success", icon: "mdi-check-circle" }
|
|
1109
1120
|
};
|
|
1110
|
-
return
|
|
1121
|
+
return Te({
|
|
1111
1122
|
title: k(() => n + o[e.value].suffix),
|
|
1112
1123
|
icon: k(() => o[e.value].icon),
|
|
1113
1124
|
closable: k(() => e.value !== "loading")
|
|
1114
1125
|
});
|
|
1115
1126
|
}
|
|
1116
1127
|
let Le = !1;
|
|
1117
|
-
const
|
|
1128
|
+
const rn = {
|
|
1118
1129
|
install(e, n) {
|
|
1119
1130
|
if (Le) return;
|
|
1120
1131
|
Le = !0;
|
|
@@ -1122,9 +1133,9 @@ const an = {
|
|
|
1122
1133
|
initTheme: o = !0,
|
|
1123
1134
|
themeOptions: l,
|
|
1124
1135
|
componentName: i = Me.name || "RouterTab",
|
|
1125
|
-
tabsComponentName: p =
|
|
1136
|
+
tabsComponentName: p = pe.name || "RouterTabs"
|
|
1126
1137
|
} = n ?? {};
|
|
1127
|
-
o &&
|
|
1138
|
+
o && qt(l ?? {}), e.component(i, Me), e.component(p, pe), p.toLowerCase() !== "router-tabs" && e.component("router-tabs", pe), Object.defineProperty(e.config.globalProperties, "$tabs", {
|
|
1128
1139
|
configurable: !0,
|
|
1129
1140
|
enumerable: !1,
|
|
1130
1141
|
get() {
|
|
@@ -1138,16 +1149,16 @@ const an = {
|
|
|
1138
1149
|
};
|
|
1139
1150
|
export {
|
|
1140
1151
|
Me as RouterTab,
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1152
|
+
pe as RouterTabs,
|
|
1153
|
+
rn as default,
|
|
1154
|
+
qt as initRouterTabsTheme,
|
|
1144
1155
|
ee as routerTabsKey,
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1156
|
+
tn as setRouterTabsPrimary,
|
|
1157
|
+
en as setRouterTabsTheme,
|
|
1158
|
+
nn as useLoadingTab,
|
|
1159
|
+
on as useNotificationTab,
|
|
1160
|
+
Te as useReactiveTab,
|
|
1161
|
+
De as useRouterTabs,
|
|
1151
1162
|
Ve as useRouterTabsPersistence,
|
|
1152
|
-
|
|
1163
|
+
an as useStatusTab
|
|
1153
1164
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue"),require("vue-router")):typeof define=="function"&&define.amd?define(["exports","vue","vue-router"],n):(w=typeof globalThis<"u"?globalThis:w||self,n(w["vue3-router-tab"]={},w.Vue,w.VueRouter))})(this,(function(w,n,Re){"use strict";function Ee(e={}){return{initialTabs:e.initialTabs??[],keepAlive:e.keepAlive??!0,maxAlive:e.maxAlive??0,keepLastTab:e.keepLastTab??!0,appendPosition:e.appendPosition??"last",defaultRoute:e.defaultRoute??"/"}}function x(e,o){const a=e.resolve(o);if(!a||!a.matched.length)throw new Error(`[RouterTabs] Unable to resolve route: ${String(o)}`);return a}const Pe={path:e=>e.path,fullpath:e=>e.fullPath,fullname:e=>e.fullPath,full:e=>e.fullPath,name:e=>e.name?String(e.name):e.fullPath};function $(e){const o=e.meta?.key;if(typeof o=="function"){const a=o(e);if(typeof a=="string"&&a.length)return a}else if(typeof o=="string"&&o.length){const a=Pe[o.toLowerCase()];return a?a(e):o}return e.fullPath}function G(e,o){const a=e.meta?.keepAlive;return typeof a=="boolean"?a:o}function X(e,o){const a=e.meta?.reuse;return typeof a=="boolean"?a:o}function se(e){const o=e.meta??{},a={};return"title"in o&&(a.title=o.title),"tips"in o&&(a.tips=o.tips),"icon"in o&&(a.icon=o.icon),"closable"in o&&(a.closable=o.closable),"tabClass"in o&&(a.tabClass=o.tabClass),"target"in o&&(a.target=o.target),"href"in o&&(a.href=o.href),a}function _(e,o,a){const s=se(e);return{id:$(e),to:e.fullPath,fullPath:e.fullPath,matched:e,alive:G(e,a),reusable:X(e,!1),closable:s.closable??!0,renderKey:typeof o.renderKey=="number"?o.renderKey:0,...s,...o}}function Q(e,o,a,s){if(!e.find(p=>p.id===o.id)){if(a==="next"&&s){const p=e.findIndex(v=>v.id===s);if(p!==-1){e.splice(p+1,0,o);return}}e.push(o)}}function ce(e,o,a){if(!o||o<=0)return;const s=e.filter(i=>i.alive);for(;s.length>o;){const i=s.shift();if(!i||i.id===a)continue;const p=e.findIndex(v=>v.id===i.id);p>-1&&(e[p].alive=!1)}}function Be(e){return{to:e.to,title:e.title,tips:e.tips,icon:e.icon,tabClass:e.tabClass,closable:e.closable,renderKey:e.renderKey}}function Ke(e){const o={};return"title"in e&&(o.title=e.title),"tips"in e&&(o.tips=e.tips),"icon"in e&&(o.icon=e.icon),"tabClass"in e&&(o.tabClass=e.tabClass),"closable"in e&&(o.closable=e.closable),"renderKey"in e&&typeof e.renderKey=="number"&&(o.renderKey=e.renderKey),o}function Ae(e,o={}){const a=Ee(o),s=n.reactive([]),i=n.ref(null),p=n.shallowRef(),v=n.ref(null),c=n.computed(()=>s.filter(l=>l.alive).map(l=>`${l.id}::${l.renderKey??0}`));let d=!1;function g(l){const m=typeof l.matched=="object"?l:x(e,l);return{key:$(m),fullPath:m.fullPath,alive:G(m,a.keepAlive),reusable:X(m,!1),matched:m}}function E(l){const m=$(l);let b=s.find(k=>k.id===m);return b?(b.fullPath=l.fullPath,b.to=l.fullPath,b.matched=l,b.alive=G(l,a.keepAlive),b.reusable=X(l,b.reusable),typeof b.renderKey!="number"&&(b.renderKey=0),Object.assign(b,se(l)),b):(b=_(l,{},a.keepAlive),Q(s,b,a.appendPosition,i.value),ce(s,a.maxAlive,i.value),b)}async function A(l,m=!1,b=!0){const k=x(e,l),C=$(k),P=i.value===C;b==="sameTab"&&(b=P),b&&await M(C,!0),await e[m?"replace":"push"](k),P&&await T()}function S(l){const m=s.findIndex(K=>K.id===l);if(m===-1)return a.defaultRoute;const b=s[m+1],k=s[m-1],C=s.find(K=>K.id!==l),P=b||k||C;return P?P.to:a.defaultRoute}async function N(l=i.value,m={}){if(!l)return;if(!m.force&&a.keepLastTab&&s.length===1)throw new Error("[RouterTabs] Unable to close the final tab when keepLastTab is true.");const k=i.value===l&&m.redirect!==null,C=k?m.redirect??S(l):null;await O(l,{force:m.force}),m.redirect!==null&&k&&C&&await e.replace(C)}async function O(l,m={}){const b=s.findIndex(k=>k.id===l);b!==-1&&(s.splice(b,1),v.value===l&&(v.value=null),i.value===l&&(i.value=null,p.value=void 0))}async function M(l=i.value??void 0,m=!1){if(!l)return;const b=s.find(C=>C.id===l);if(!b)return;const k=a.keepAlive&&b.alive;k&&(b.alive=!1,await n.nextTick()),b.renderKey=(b.renderKey??0)+1,k&&(b.alive=!0),v.value=l,await n.nextTick(),m||await n.nextTick(),v.value=null}async function oe(l=!1){for(const m of s)await M(m.id,l)}async function ae(l=a.defaultRoute){s.splice(0,s.length),i.value=null,p.value=void 0;for(const m of a.initialTabs){const b=x(e,m.to),k=_(b,m,a.keepAlive);s.push(k)}await e.replace(l)}async function T(){const l=i.value;l&&await M(l,!0)}function W(l){return typeof l.matched=="object"?$(l):$(x(e,l))}function D(){const l=s.find(m=>m.id===i.value);return{tabs:s.map(Be),active:l?l.to:null}}async function I(l){d=!0,s.splice(0,s.length),i.value=null,p.value=void 0;const m=l?.tabs??[];for(const k of m)try{const C=x(e,k.to),P=Ke(k),K=_(C,P,a.keepAlive);Q(s,K,"last",null)}catch{}d=!1;const b=l?.active??m[m.length-1]?.to??a.defaultRoute;if(b)try{await e.replace(b)}catch{}}return n.watch(()=>e.currentRoute.value,l=>{if(d)return;const m=E(l);i.value=m.id,p.value=m,ce(s,a.maxAlive,i.value)},{immediate:!0}),a.initialTabs.length&&a.initialTabs.forEach(l=>{const m=x(e,l.to),b=_(m,l,a.keepAlive);Q(s,b,"last",null)}),{options:a,tabs:s,activeId:i,current:p,includeKeys:c,refreshingKey:v,openTab:A,closeTab:N,removeTab:O,refreshTab:M,refreshAll:oe,reset:ae,reload:T,getRouteKey:W,matchRoute:g,snapshot:D,hydrate:I}}function ue(e){return e?typeof e=="string"?{name:e}:e:{}}const V=Symbol("RouterTabsContext"),Y="router-tabs:snapshot";function Z(e={}){const{optional:o=!1}=e,a=n.inject(V,null);if(a)return a;const s=n.inject("$tabs",null);if(s)return s;const p=n.getCurrentInstance()?.appContext.config.globalProperties.$tabs;if(p)return p;if(!o)throw new Error("[RouterTabs] useRouterTabs must be used within <router-tab>.");return null}const Ie=864e5;function Se(e){if(typeof document>"u")return null;const o=`${encodeURIComponent(e)}=`,a=document.cookie?document.cookie.split("; "):[];for(const s of a)if(s.startsWith(o))return decodeURIComponent(s.slice(o.length));return null}function de(e,o,a){if(typeof document>"u")return;const{expiresInDays:s=7,path:i="/",domain:p,secure:v,sameSite:c="lax"}=a,d=[`${encodeURIComponent(e)}=${encodeURIComponent(o)}`];if(s!==1/0){const g=new Date(Date.now()+s*Ie).toUTCString();d.push(`Expires=${g}`)}i&&d.push(`Path=${i}`),p&&d.push(`Domain=${p}`),v&&d.push("Secure"),c&&d.push(`SameSite=${c.charAt(0).toUpperCase()}${c.slice(1)}`),document.cookie=d.join("; ")}function fe(e,o){if(typeof document>"u")return;const{path:a="/",domain:s}=o,i=[`${encodeURIComponent(e)}=`];i.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"),a&&i.push(`Path=${a}`),s&&i.push(`Domain=${s}`),document.cookie=i.join("; ")}const De=e=>JSON.stringify(e??null),xe=e=>{if(!e)return null;try{return JSON.parse(e)}catch{return null}};function ee(e={}){const{cookieKey:o=Y,serialize:a=De,deserialize:s=xe}=e,i=Z({optional:!0}),p=n.ref(!0),v=c=>{n.onMounted(async()=>{const d=s(Se(o));if(d&&d.tabs?.length)try{if(p.value=!0,await c.hydrate(d),d.active){await n.nextTick();const E=c.tabs.find(A=>A.to===d.active);E&&(c.activeId.value=E.id,c.current.value=E)}}finally{p.value=!1}else if(Object.prototype.hasOwnProperty.call(e,"fallbackRoute"))try{p.value=!0;const E=e.fallbackRoute??c.options.defaultRoute;await c.reset(E)}finally{p.value=!1}else p.value=!1;const g=c.snapshot();g.tabs.length?de(o,a(g),e):fe(o,e),p.value=!1}),n.watch(()=>({tabs:c.tabs.map(d=>({to:d.to,title:d.title,tips:d.tips,icon:d.icon,tabClass:d.tabClass,closable:d.closable,renderKey:d.renderKey})),active:c.activeId.value}),()=>{if(p.value)return;const d=c.snapshot();d.tabs.length?de(o,a(d),e):fe(o,e)},{deep:!0})};i?v(i):n.onMounted(()=>{const c=Z({optional:!0});c&&v(c)})}const $e=n.defineComponent({name:"RouterTab",components:{RouterView:Re.RouterView},props:{tabs:{type:Array,default:()=>[]},keepAlive:{type:Boolean,default:!0},maxAlive:{type:Number,default:0},keepLastTab:{type:Boolean,default:!0},append:{type:String,default:"last"},defaultPage:{type:[String,Object],default:"/"},tabTransition:{type:[String,Object],default:"router-tab-zoom"},pageTransition:{type:[String,Object],default:()=>({name:"router-tab-swap",mode:"out-in"})},contextmenu:{type:[Boolean,Array],default:!0},cookieKey:{type:String,default:Y},persistence:{type:Object,default:null},sortable:{type:Boolean,default:!0}},emits:["tab-sort","tab-sorted"],setup(e,{emit:o}){const a=n.getCurrentInstance();if(!a)throw new Error("[RouterTab] component must be used within a Vue application context.");const s=a.appContext.app.config.globalProperties.$router;if(!s)throw new Error("[RouterTab] Vue Router is required. Make sure to call app.use(router) before RouterTab.");const i=Ae(s,{initialTabs:e.tabs,keepAlive:e.keepAlive,maxAlive:e.maxAlive,keepLastTab:e.keepLastTab,appendPosition:e.append,defaultRoute:e.defaultPage});n.provide(V,i),a.appContext.config.globalProperties.$tabs=i;const p=n.computed(()=>!!a?.slots?.default),v=n.computed(()=>!!a?.slots?.start),c=n.computed(()=>!!a?.slots?.end),d=n.ref(0),g=n.computed(()=>{d.value;const t={};return i.tabs.forEach(r=>{const f=typeof r.title=="string"?r.title:String(r.title||re(r));t[r.id]=f}),t});function E(){d.value++}const A=new Map,S=new Map;function N(t,r){if(!r||A.has(t))return;A.set(t,r);const f=i.tabs.find(y=>i.getRouteKey(y.to)===t);if(!f)return;const h=[];if(r.routeTabTitle!==void 0){const y=n.watch(()=>{const u=r.routeTabTitle;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{if(u!=null){const L=String(u);f.title=L,E()}},{immediate:!0});h.push(y)}if(r.routeTabIcon!==void 0){const y=n.watch(()=>{const u=r.routeTabIcon;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{u!=null&&(f.icon=String(u),E())},{immediate:!0});h.push(y)}if(r.routeTabClosable!==void 0){const y=n.watch(()=>{const u=r.routeTabClosable;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{u!=null&&(f.closable=!!u,E())},{immediate:!0});h.push(y)}if(r.routeTabMeta!==void 0){const y=n.watch(()=>{const u=r.routeTabMeta;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{u&&typeof u=="object"&&(Object.assign(f,u),E())},{immediate:!0,deep:!0});h.push(y)}S.set(t,h)}function O(t){const r=S.get(t);r&&(r.forEach(f=>f()),S.delete(t)),A.delete(t)}function M(t,r){t?t.routeTabTitle!==void 0||t.routeTabIcon!==void 0||t.routeTabClosable!==void 0?N(r,t):t.$&&(t.$.routeTabTitle!==void 0||t.$.routeTabIcon!==void 0||t.$.routeTabClosable!==void 0)&&N(r,t.$):t===null&&O(r)}if(e.cookieKey!==null||e.persistence){const t={...e.persistence??{}};e.cookieKey!==null?t.cookieKey=e.cookieKey||Y:t.cookieKey||(t.cookieKey=Y),ee(t)}const oe=n.computed(()=>ue(e.tabTransition)),ae=n.computed(()=>ue(e.pageTransition)),T=n.reactive({visible:!1,target:null,position:{x:0,y:0}}),W=n.ref(null),D=n.ref([]),I=n.ref(-1),l=n.reactive({dragging:!1,dragIndex:-1,dropIndex:-1,dragTab:null}),m=["refresh","refreshAll","close","closeLefts","closeRights","closeOthers"];function b(t){return i.tabs.findIndex(r=>r.id===t)}function k(t){const r=b(t.id);return r>0?i.tabs.slice(0,r):[]}function C(t){const r=b(t.id);return r>-1?i.tabs.slice(r+1):[]}function P(t){return i.tabs.filter(r=>r.id!==t.id)}async function K(t,r){const f=t.filter(h=>h.closable!==!1);if(f.length){for(const h of f)i.activeId.value===h.id?await i.closeTab(h.id,{redirect:r.to,force:!0}):await i.removeTab(h.id,{force:!0});i.activeId.value!==r.id&&await i.openTab(r.to,!0,!1)}}const tt={refresh:{label:"Refresh",handler:async({target:t})=>{await i.refreshTab(t.id,!0)}},refreshAll:{label:"Refresh All",handler:async()=>{await i.refreshAll(!0)}},close:{label:"Close",handler:async({target:t})=>{await i.closeTab(t.id)},enable:({target:t})=>ie(t)},closeLefts:{label:"Close to the Left",handler:async({target:t})=>{await K(k(t),t)},enable:({target:t})=>k(t).some(r=>r.closable!==!1)},closeRights:{label:"Close to the Right",handler:async({target:t})=>{await K(C(t),t)},enable:({target:t})=>C(t).some(r=>r.closable!==!1)},closeOthers:{label:"Close Others",handler:async({target:t})=>{await K(P(t),t)},enable:({target:t})=>P(t).some(r=>r.closable!==!1)}};function B(){T.visible=!1,T.target=null,I.value=-1,D.value=[]}function nt(t,r){e.contextmenu&&(T.target=t,T.position.x=r.clientX,T.position.y=r.clientY,n.nextTick(()=>{T.visible=!0,document.addEventListener("click",B,{once:!0}),n.nextTick(()=>{at()})}))}function ot(t,r){const f=typeof t=="string"?{id:t}:t,h=tt[f.id],y=f.label??h?.label??String(f.id),u=f.visible??h?.visible??!0;if(!(typeof u=="function"?u(r):u!==!1))return null;const le=f.enable??h?.enable??!0,kt=typeof le=="function"?le(r):le!==!1,Ce=f.handler??h?.handler;if(!Ce)return null;const vt=async()=>{await Promise.resolve(Ce(r))};return{id:String(f.id),label:y,disabled:!kt,action:vt}}const U=n.computed(()=>{if(!T.visible||!T.target||e.contextmenu===!1)return[];const t=Array.isArray(e.contextmenu)?e.contextmenu:m,r={target:T.target,controller:i};return t.map(f=>ot(f,r)).filter(f=>!!f)});function at(){const t=W.value;if(!t)return;const r=8,{innerWidth:f,innerHeight:h}=window,y=t.getBoundingClientRect();let u=T.position.x,L=T.position.y;y.right>f-r&&(u=Math.max(r,f-y.width-r)),y.bottom>h-r&&(L=Math.max(r,h-y.height-r)),(u!==T.position.x||L!==T.position.y)&&(T.position.x=u,T.position.y=L)}function rt(t,r){D.value[r]=t??null}function it(t){if(t<0)return;D.value[t]?.focus({preventScroll:!0})}function q(t,r,f=U.value){if(!f.length)return-1;const h=f.length;let y=t;for(let u=0;u<h;u++)if(y=(y+r+h)%h,!f[y].disabled)return y;return-1}function z(t){I.value=t,!(t<0)&&n.nextTick(()=>it(t))}function Te(t){const r=q(I.value,t);r!==-1&&z(r)}function lt(t){if(!T.visible)return;const r=t.key,f=U.value;if(!f.length)return;if(r==="Tab"){B();return}if(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End","Enter"," ","Spacebar","Escape"].includes(r))switch(t.preventDefault(),r){case"ArrowDown":case"ArrowRight":Te(1);break;case"ArrowUp":case"ArrowLeft":Te(-1);break;case"Home":z(q(-1,1));break;case"End":z(q(f.length,-1));break;case"Enter":case" ":case"Spacebar":{const y=I.value;if(y>-1){const u=f[y];u.disabled||ke(u)}break}case"Escape":B();break}}async function ke(t){t.disabled||(B(),await t.action())}function re(t){return typeof t.title=="string"&&t.title.trim()?t.title:Array.isArray(t.title)&&t.title.length&&String(t.title[0]).trim()?String(t.title[0]):"Untitled"}function st(t){return g.value[t.id]||re(t)}function ve(t){const r=i.getRouteKey(t),h=i.tabs.find(y=>y.id===r)?.renderKey??0;return`${r}::${h}`}function ct(t){return`${ve(t)}::refresh`}function ie(t){return!(t.closable===!1||i.options.keepLastTab&&i.tabs.length<=1)}async function ut(t){await i.closeTab(t.id)}function dt(t){if(t.href&&typeof window<"u"){t.target&&t.target!=="_self"?window.open(t.href,t.target):window.location.assign(t.href);return}i.activeId.value!==t.id&&i.openTab(t.to,!1)}function ft(t){return["router-tab__item",{"is-active":i.activeId.value===t.id,"is-closable":ie(t),"is-dragging":l.dragging&&l.dragTab?.id===t.id,"is-drag-over":l.dropIndex===b(t.id)},t.tabClass]}function bt(t){return i.refreshingKey.value===i.getRouteKey(t)}function mt(t,r,f){e.sortable&&(l.dragging=!0,l.dragIndex=r,l.dragTab=t,f.dataTransfer&&(f.dataTransfer.effectAllowed="move",f.dataTransfer.setData("text/plain",t.id)),o("tab-sort",{tab:t,index:r}))}function pt(t,r){!e.sortable||!l.dragging||(r.preventDefault(),r.dataTransfer&&(r.dataTransfer.dropEffect="move"))}function gt(t){!e.sortable||!l.dragging||(l.dropIndex=t)}function ht(){!e.sortable||l.dragging}function yt(t,r){if(!(!e.sortable||!l.dragging)){if(r.preventDefault(),l.dragIndex!==-1&&l.dragIndex!==t){const f=i.tabs.splice(l.dragIndex,1)[0];i.tabs.splice(t,0,f),o("tab-sorted",{tab:f,fromIndex:l.dragIndex,toIndex:t})}we()}}function we(){l.dragging=!1,l.dragIndex=-1,l.dropIndex=-1,l.dragTab=null}n.onMounted(()=>{document.addEventListener("keydown",B)}),n.onBeforeUnmount(()=>{document.removeEventListener("keydown",B),a.appContext.config.globalProperties.$tabs=null,S.forEach(t=>{t.forEach(r=>r())}),S.clear(),A.clear()}),n.watch(()=>e.keepAlive,t=>{i.options.keepAlive=t}),n.watch(()=>i.activeId.value,()=>B()),n.watch(()=>e.contextmenu,t=>{t||B()}),n.watch(()=>U.value.length,t=>{T.visible&&t===0&&B()},{flush:"post"}),n.watch(U,t=>{if(!T.visible)return;D.value=new Array(t.length).fill(null);const r=q(-1,1,t);z(r)},{flush:"post"}),n.watch(()=>T.visible,t=>{t||(I.value=-1,D.value=[])});const Tt=i.includeKeys;return{controller:i,tabs:i.tabs,includeKeys:Tt,tabTransitionProps:oe,pageTransitionProps:ae,buildTabClass:ft,activate:dt,close:ut,context:T,menuItems:U,handleMenuAction:ke,showContextMenu:nt,hideContextMenu:B,getTabTitle:re,isClosable:ie,isRefreshing:bt,hasCustomSlot:p,hasStartSlot:v,hasEndSlot:c,onDragStart:mt,onDragOver:pt,onDragEnter:gt,onDragLeave:ht,onDrop:yt,onDragEnd:we,setupComponentWatching:N,cleanupComponentWatching:O,handleComponentRef:M,getReactiveTabTitle:st,getComponentCacheKey:ve,getRefreshComponentKey:ct,triggerTabUpdate:E,menuRef:W,highlightedIndex:I,setMenuItemRef:rt,onMenuKeydown:lt,highlightMenuIndex:z}}}),Me=(e,o)=>{const a=e.__vccOpts||e;for(const[s,i]of o)a[s]=i;return a},Le={class:"router-tab"},Ve={class:"router-tab__header"},je={class:"router-tab__scroll"},Ne=["data-title","draggable","onClick","onAuxclick","onContextmenu","onDragstart","onDragover","onDragenter","onDrop"],Oe=["title"],Ue=["onClick"],ze={class:"router-tab__container"},_e=["aria-disabled","disabled","tabindex","onMouseenter","onClick"];function Ye(e,o,a,s,i,p){const v=n.resolveComponent("RouterView");return n.openBlock(),n.createElementBlock("div",Le,[n.createElementVNode("header",Ve,[n.createElementVNode("div",{class:n.normalizeClass(["router-tab__slot-start",{"has-content":e.hasStartSlot}])},[n.renderSlot(e.$slots,"start")],2),n.createElementVNode("div",je,[n.createVNode(n.TransitionGroup,n.mergeProps({tag:"ul",class:"router-tab__nav"},e.tabTransitionProps),{default:n.withCtx(()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(e.tabs,(c,d)=>(n.openBlock(),n.createElementBlock("li",{key:c.id,class:n.normalizeClass(e.buildTabClass(c)),"data-title":e.getTabTitle(c),draggable:e.sortable,onClick:g=>e.activate(c),onAuxclick:n.withModifiers(g=>e.close(c),["middle","prevent"]),onContextmenu:n.withModifiers(g=>e.showContextMenu(c,g),["prevent"]),onDragstart:g=>e.onDragStart(c,d,g),onDragover:g=>e.onDragOver(d,g),onDragenter:g=>e.onDragEnter(d),onDragleave:o[0]||(o[0]=(...g)=>e.onDragLeave&&e.onDragLeave(...g)),onDrop:g=>e.onDrop(d,g),onDragend:o[1]||(o[1]=(...g)=>e.onDragEnd&&e.onDragEnd(...g))},[c.icon?(n.openBlock(),n.createElementBlock("i",{key:0,class:n.normalizeClass(["router-tab__item-icon",c.icon])},null,2)):n.createCommentVNode("",!0),n.createElementVNode("span",{class:"router-tab__item-title",title:e.getReactiveTabTitle(c)},n.toDisplayString(e.getReactiveTabTitle(c)),9,Oe),e.isClosable(c)?(n.openBlock(),n.createElementBlock("a",{key:1,class:"router-tab__item-close",onClick:n.withModifiers(g=>e.close(c),["stop"])},null,8,Ue)):n.createCommentVNode("",!0)],42,Ne))),128))]),_:1},16)]),n.createElementVNode("div",{class:n.normalizeClass(["router-tab__slot-end",{"has-content":e.hasEndSlot}])},[n.renderSlot(e.$slots,"end")],2)]),n.createElementVNode("div",ze,[n.createVNode(v,null,{default:n.withCtx(c=>[e.hasCustomSlot?n.renderSlot(e.$slots,"default",n.normalizeProps(n.mergeProps({key:0},{...c,controller:e.controller,pageRef:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route))}))):(n.openBlock(),n.createBlock(n.Transition,n.mergeProps({key:1},e.pageTransitionProps,{appear:""}),{default:n.withCtx(()=>[e.isRefreshing(c.route)?(n.openBlock(),n.createBlock(n.resolveDynamicComponent(c.Component),{key:e.getRefreshComponentKey(c.route),ref:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route)),class:"router-tab-page"})):e.controller.options.keepAlive?(n.openBlock(),n.createBlock(n.KeepAlive,{key:1,include:e.includeKeys,max:e.controller.options.maxAlive||void 0},[(n.openBlock(),n.createBlock(n.resolveDynamicComponent(c.Component),{key:e.getComponentCacheKey(c.route),ref:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route)),class:"router-tab-page"}))],1032,["include","max"])):(n.openBlock(),n.createBlock(n.resolveDynamicComponent(c.Component),{key:e.getComponentCacheKey(c.route),ref:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route)),class:"router-tab-page"}))]),_:2},1040))]),_:3})]),n.withDirectives(n.createElementVNode("div",{ref:"menuRef",class:"router-tab__contextmenu",role:"menu",onKeydown:o[2]||(o[2]=(...c)=>e.onMenuKeydown&&e.onMenuKeydown(...c)),style:n.normalizeStyle({left:e.context.position.x+"px",top:e.context.position.y+"px"})},[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(e.menuItems,(c,d)=>(n.openBlock(),n.createElementBlock("a",{key:c.id,role:"menuitem",class:n.normalizeClass(["router-tab__contextmenu-item",{"is-focused":d===e.highlightedIndex}]),"aria-disabled":c.disabled,disabled:c.disabled,tabindex:c.disabled?-1:d===e.highlightedIndex?0:-1,ref_for:!0,ref:g=>e.setMenuItemRef(g,d),onMouseenter:g=>!c.disabled&&e.highlightMenuIndex(d),onClick:g=>e.handleMenuAction(c)},n.toDisplayString(c.label),43,_e))),128))],36),[[n.vShow,e.context.visible&&e.context.target]])])}const te=Me($e,[["render",Ye]]),Fe={class:"router-tabs","aria-hidden":"true"},F=n.defineComponent({name:"RouterTabs",__name:"RouterTabs",props:{cookieKey:{},expiresInDays:{},path:{},domain:{},secure:{type:Boolean},sameSite:{},serialize:{type:Function},deserialize:{type:Function},fallbackRoute:{}},setup(e){return ee(e),(a,s)=>(n.openBlock(),n.createElementBlock("span",Fe))}}),be="tab-theme-style",me="tab-theme-primary-color",He="system",pe="(prefers-color-scheme: dark)";let j=null;const R={primary:"#034960",background:"#ffffff",text:"#1e293b",border:"#e2e8f0",activeBackground:"#034960",activeText:"#ffffff",activeBorder:"#034960",headerBackground:"#ffffff",buttonBackground:"#f8fafc",buttonColor:"#034960",activeButtonBackground:"#034960",activeButtonColor:"#ffffff",iconColor:"#475569"},Je={primary:"#38bdf8",background:"#0f172a",text:"#f1f5f9",border:"#334155",activeBackground:"#1e293b",activeText:"#38bdf8",activeBorder:"#38bdf8",headerBackground:"#0c4a6e",buttonBackground:"#1e293b",buttonColor:"#f1f5f9",activeButtonBackground:"#38bdf8",activeButtonColor:"#0f172a",iconColor:"#cbd5e1"};function We(e){if(typeof window>"u")return null;const o=window.localStorage.getItem(e);if(!o)return null;try{const a=JSON.parse(o);return a&&typeof a=="object"?a:null}catch{return null}}function ne(e){typeof document>"u"||(document.documentElement.style.setProperty("--router-tab-primary",e.primary??R.primary),document.documentElement.style.setProperty("--router-tab-header-bg",e.headerBackground??R.headerBackground),document.documentElement.style.setProperty("--router-tab-background",e.background??R.background),document.documentElement.style.setProperty("--router-tab-active-background",e.activeBackground??R.activeBackground),document.documentElement.style.setProperty("--router-tab-text",e.text??R.text),document.documentElement.style.setProperty("--router-tab-active-text",e.activeText??R.activeText),document.documentElement.style.setProperty("--router-tab-border",e.border??R.border),document.documentElement.style.setProperty("--router-tab-active-border",e.activeBorder??R.activeBorder),document.documentElement.style.setProperty("--router-tab-button-color",e.buttonColor??R.buttonColor),document.documentElement.style.setProperty("--router-tab-active-button-color",e.activeButtonColor??R.activeButtonColor),document.documentElement.style.setProperty("--router-tab-button-background",e.buttonBackground??R.buttonBackground),document.documentElement.style.setProperty("--router-tab-active-button-background",e.activeButtonBackground??R.activeButtonBackground),document.documentElement.style.setProperty("--router-tab-icon-color",e.iconColor??R.iconColor))}function ge(e){if(typeof document>"u")return;const o=document.documentElement,a=window.matchMedia(pe),s=()=>{o.dataset.theme=a.matches?"dark":"light"};j&&(a.removeEventListener("change",j),j=null),e==="system"?(s(),j=()=>s(),a.addEventListener("change",j)):o.dataset.theme=e}function he(e={}){if(typeof window>"u")return;const{styleKey:o=be,primaryKey:a=me,defaultStyle:s=He,defaultPrimary:i}=e,p=window.localStorage.getItem(o)??s;ge(p);const c=p==="dark"||p==="system"&&window.matchMedia(pe).matches?{...Je}:{...R};i&&(c.primary=i);const d=We(a);ne(d?{...c,...d}:c)}function qe(e,o){if(typeof window>"u")return;const a=o?.styleKey??be;window.localStorage.setItem(a,e),ge(e)}function Ge(e,o){if(typeof window>"u")return;const a=o?.primaryKey??me;window.localStorage.setItem(a,JSON.stringify(e)),ne(e)}function H(e,o){if(n.isRef(e)){const s=!n.isReadonly(e);return{value:e,update:s?i=>{e.value=i}:()=>{}}}if(typeof e=="function"){const s=e;return{value:n.computed(s),update:()=>{}}}const a=n.ref(e===void 0?o:e);return{value:a,update:s=>{a.value=s}}}function J(e={}){const o=H(e.title,"Untitled"),a=H(e.icon,""),s=H(e.closable,!0),i=H(e.meta,{});return{routeTabTitle:o.value,routeTabIcon:a.value,routeTabClosable:s.value,routeTabMeta:i.value,updateTitle:o.update,updateIcon:a.update,updateClosable:s.update,updateMeta:i.update}}function Xe(e,o="Page"){return J({title:n.computed(()=>e.value?"Loading...":o),icon:n.computed(()=>e.value?"mdi-loading mdi-spin":"mdi-page"),closable:n.computed(()=>!e.value)})}function Qe(e,o="Page",a="mdi-page"){return J({title:n.computed(()=>e.value>0?`${o} (${e.value})`:o),icon:n.computed(()=>e.value>0?"mdi-bell-badge":a)})}function Ze(e,o="Page"){const a={normal:{suffix:"",icon:"mdi-page"},loading:{suffix:" - Loading",icon:"mdi-loading mdi-spin"},error:{suffix:" - Error",icon:"mdi-alert"},success:{suffix:" - Success",icon:"mdi-check-circle"}};return J({title:n.computed(()=>o+a[e.value].suffix),icon:n.computed(()=>a[e.value].icon),closable:n.computed(()=>e.value!=="loading")})}let ye=!1;const et={install(e,o){if(ye)return;ye=!0;const{initTheme:a=!0,themeOptions:s,componentName:i=te.name||"RouterTab",tabsComponentName:p=F.name||"RouterTabs"}=o??{};a&&he(s??{}),e.component(i,te),e.component(p,F),p.toLowerCase()!=="router-tabs"&&e.component("router-tabs",F),Object.defineProperty(e.config.globalProperties,"$tabs",{configurable:!0,enumerable:!1,get(){return e._context.provides[V]},set(v){v&&e.provide(V,v)}})}};w.RouterTab=te,w.RouterTabs=F,w.default=et,w.initRouterTabsTheme=he,w.routerTabsKey=V,w.setRouterTabsPrimary=Ge,w.setRouterTabsTheme=qe,w.useLoadingTab=Xe,w.useNotificationTab=Qe,w.useReactiveTab=J,w.useRouterTabs=Z,w.useRouterTabsPersistence=ee,w.useStatusTab=Ze,Object.defineProperties(w,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1
|
+
(function(w,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue"),require("vue-router")):typeof define=="function"&&define.amd?define(["exports","vue","vue-router"],n):(w=typeof globalThis<"u"?globalThis:w||self,n(w["vue3-router-tab"]={},w.Vue,w.VueRouter))})(this,(function(w,n,Re){"use strict";function Ee(e={}){return{initialTabs:e.initialTabs??[],keepAlive:e.keepAlive??!0,maxAlive:e.maxAlive??0,keepLastTab:e.keepLastTab??!0,appendPosition:e.appendPosition??"last",defaultRoute:e.defaultRoute??"/"}}function $(e,o){const a=e.resolve(o);if(!a||!a.matched.length)throw new Error(`[RouterTabs] Unable to resolve route: ${String(o)}`);return a}const Be={path:e=>e.path,fullpath:e=>e.fullPath,fullname:e=>e.fullPath,full:e=>e.fullPath,name:e=>e.name?String(e.name):e.fullPath};function x(e){const o=e.meta?.key;if(typeof o=="function"){const a=o(e);if(typeof a=="string"&&a.length)return a}else if(typeof o=="string"&&o.length){const a=Be[o.toLowerCase()];return a?a(e):o}return e.fullPath}function G(e,o){const a=e.meta?.keepAlive;return typeof a=="boolean"?a:o}function X(e,o){const a=e.meta?.reuse;return typeof a=="boolean"?a:o}function se(e){const o=e.meta??{},a={};return"title"in o&&(a.title=o.title),"tips"in o&&(a.tips=o.tips),"icon"in o&&(a.icon=o.icon),"closable"in o&&(a.closable=o.closable),"tabClass"in o&&(a.tabClass=o.tabClass),"target"in o&&(a.target=o.target),"href"in o&&(a.href=o.href),a}function _(e,o,a){const s=se(e);return{id:x(e),to:e.fullPath,fullPath:e.fullPath,matched:e,alive:G(e,a),reusable:X(e,!1),closable:s.closable??!0,renderKey:typeof o.renderKey=="number"?o.renderKey:0,...s,...o}}function Q(e,o,a,s){if(!e.find(p=>p.id===o.id)){if(a==="next"&&s){const p=e.findIndex(v=>v.id===s);if(p!==-1){e.splice(p+1,0,o);return}}e.push(o)}}function ce(e,o,a){if(!o||o<=0)return;const s=e.filter(i=>i.alive);for(;s.length>o;){const i=s.shift();if(!i||i.id===a)continue;const p=e.findIndex(v=>v.id===i.id);p>-1&&(e[p].alive=!1)}}function Pe(e){return{to:e.to,title:e.title,tips:e.tips,icon:e.icon,tabClass:e.tabClass,closable:e.closable,renderKey:e.renderKey}}function Ke(e){const o={};return"title"in e&&(o.title=e.title),"tips"in e&&(o.tips=e.tips),"icon"in e&&(o.icon=e.icon),"tabClass"in e&&(o.tabClass=e.tabClass),"closable"in e&&(o.closable=e.closable),"renderKey"in e&&typeof e.renderKey=="number"&&(o.renderKey=e.renderKey),o}function Ae(e,o={}){const a=Ee(o),s=n.reactive([]),i=n.ref(null),p=n.shallowRef(),v=n.ref(null),c=n.computed(()=>s.filter(l=>l.alive).map(l=>`${l.id}::${l.renderKey??0}`));let d=!1;function g(l){const m=typeof l.matched=="object"?l:$(e,l);return{key:x(m),fullPath:m.fullPath,alive:G(m,a.keepAlive),reusable:X(m,!1),matched:m}}function E(l){const m=x(l);let b=s.find(k=>k.id===m);return b?(b.fullPath=l.fullPath,b.to=l.fullPath,b.matched=l,b.alive=G(l,a.keepAlive),b.reusable=X(l,b.reusable),typeof b.renderKey!="number"&&(b.renderKey=0),Object.assign(b,se(l)),b):(b=_(l,{},a.keepAlive),Q(s,b,a.appendPosition,i.value),ce(s,a.maxAlive,i.value),b)}async function A(l,m=!1,b=!0){const k=$(e,l),C=x(k),B=i.value===C;b==="sameTab"&&(b=B),b&&await M(C,!0),await e[m?"replace":"push"](k),B&&await T()}function S(l){const m=s.findIndex(K=>K.id===l);if(m===-1)return a.defaultRoute;const b=s[m+1],k=s[m-1],C=s.find(K=>K.id!==l),B=b||k||C;return B?B.to:a.defaultRoute}async function N(l=i.value,m={}){if(!l)return;if(!m.force&&a.keepLastTab&&s.length===1)throw new Error("[RouterTabs] Unable to close the final tab when keepLastTab is true.");const k=i.value===l&&m.redirect!==null,C=k?m.redirect??S(l):null;await O(l,{force:m.force}),m.redirect!==null&&k&&C&&await e.replace(C)}async function O(l,m={}){const b=s.findIndex(k=>k.id===l);b!==-1&&(s.splice(b,1),v.value===l&&(v.value=null),i.value===l&&(i.value=null,p.value=void 0))}async function M(l=i.value??void 0,m=!1){if(!l)return;const b=s.find(C=>C.id===l);if(!b)return;const k=a.keepAlive&&b.alive;k&&(b.alive=!1,await n.nextTick()),b.renderKey=(b.renderKey??0)+1,k&&(b.alive=!0),v.value=l,await n.nextTick(),m||await n.nextTick(),v.value=null}async function oe(l=!1){for(const m of s)await M(m.id,l)}async function ae(l=a.defaultRoute){s.splice(0,s.length),i.value=null,p.value=void 0;for(const m of a.initialTabs){const b=$(e,m.to),k=_(b,m,a.keepAlive);s.push(k)}await e.replace(l)}async function T(){const l=i.value;l&&await M(l,!0)}function W(l){return typeof l.matched=="object"?x(l):x($(e,l))}function D(){const l=s.find(m=>m.id===i.value);return{tabs:s.map(Pe),active:l?l.to:null}}async function I(l){d=!0,s.splice(0,s.length),i.value=null,p.value=void 0;const m=l?.tabs??[];for(const k of m)try{const C=$(e,k.to),B=Ke(k),K=_(C,B,a.keepAlive);Q(s,K,"last",null)}catch{}d=!1;const b=l?.active??m[m.length-1]?.to??a.defaultRoute;if(b)try{await e.replace(b)}catch{}}return n.watch(()=>e.currentRoute.value,l=>{if(d)return;const m=E(l);i.value=m.id,p.value=m,ce(s,a.maxAlive,i.value)},{immediate:!0}),a.initialTabs.length&&a.initialTabs.forEach(l=>{const m=$(e,l.to),b=_(m,l,a.keepAlive);Q(s,b,"last",null)}),{options:a,tabs:s,activeId:i,current:p,includeKeys:c,refreshingKey:v,openTab:A,closeTab:N,removeTab:O,refreshTab:M,refreshAll:oe,reset:ae,reload:T,getRouteKey:W,matchRoute:g,snapshot:D,hydrate:I}}function ue(e){return e?typeof e=="string"?{name:e}:e:{}}const V=Symbol("RouterTabsContext"),Y="router-tabs:snapshot";function Z(e={}){const{optional:o=!1}=e,a=n.inject(V,null);if(a)return a;const s=n.inject("$tabs",null);if(s)return s;const p=n.getCurrentInstance()?.appContext.config.globalProperties.$tabs;if(p)return p;if(!o)throw new Error("[RouterTabs] useRouterTabs must be used within <router-tab>.");return null}const Ie=864e5;function Se(e){if(typeof document>"u")return null;const o=`${encodeURIComponent(e)}=`,a=document.cookie?document.cookie.split("; "):[];for(const s of a)if(s.startsWith(o))return decodeURIComponent(s.slice(o.length));return null}function de(e,o,a){if(typeof document>"u")return;const{expiresInDays:s=7,path:i="/",domain:p,secure:v,sameSite:c="lax"}=a,d=[`${encodeURIComponent(e)}=${encodeURIComponent(o)}`];if(s!==1/0){const g=new Date(Date.now()+s*Ie).toUTCString();d.push(`Expires=${g}`)}i&&d.push(`Path=${i}`),p&&d.push(`Domain=${p}`),v&&d.push("Secure"),c&&d.push(`SameSite=${c.charAt(0).toUpperCase()}${c.slice(1)}`),document.cookie=d.join("; ")}function fe(e,o){if(typeof document>"u")return;const{path:a="/",domain:s}=o,i=[`${encodeURIComponent(e)}=`];i.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"),a&&i.push(`Path=${a}`),s&&i.push(`Domain=${s}`),document.cookie=i.join("; ")}const De=e=>JSON.stringify(e??null),$e=e=>{if(!e)return null;try{return JSON.parse(e)}catch{return null}};function ee(e={}){const{cookieKey:o=Y,serialize:a=De,deserialize:s=$e}=e,i=Z({optional:!0}),p=n.ref(!0),v=c=>{n.onMounted(async()=>{const d=s(Se(o));if(d&&d.tabs?.length)try{if(p.value=!0,await c.hydrate(d),d.active){await n.nextTick();const E=c.tabs.find(A=>A.to===d.active);E&&(c.activeId.value=E.id,c.current.value=E)}}finally{p.value=!1}else if(Object.prototype.hasOwnProperty.call(e,"fallbackRoute"))try{p.value=!0;const E=e.fallbackRoute??c.options.defaultRoute;await c.reset(E)}finally{p.value=!1}else p.value=!1;const g=c.snapshot();g.tabs.length?de(o,a(g),e):fe(o,e),p.value=!1}),n.watch(()=>({tabs:c.tabs.map(d=>({to:d.to,title:d.title,tips:d.tips,icon:d.icon,tabClass:d.tabClass,closable:d.closable,renderKey:d.renderKey})),active:c.activeId.value}),()=>{if(p.value)return;const d=c.snapshot();d.tabs.length?de(o,a(d),e):fe(o,e)},{deep:!0})};i?v(i):n.onMounted(()=>{const c=Z({optional:!0});c&&v(c)})}const xe=n.defineComponent({name:"RouterTab",components:{RouterView:Re.RouterView},props:{tabs:{type:Array,default:()=>[]},keepAlive:{type:Boolean,default:!0},maxAlive:{type:Number,default:0},keepLastTab:{type:Boolean,default:!0},append:{type:String,default:"last"},defaultPage:{type:[String,Object],default:"/"},tabTransition:{type:[String,Object],default:"router-tab-zoom"},pageTransition:{type:[String,Object],default:()=>({name:"router-tab-swap",mode:"out-in"})},contextmenu:{type:[Boolean,Array],default:!0},cookieKey:{type:String,default:Y},persistence:{type:Object,default:null},sortable:{type:Boolean,default:!0}},emits:["tab-sort","tab-sorted"],setup(e,{emit:o}){const a=n.getCurrentInstance();if(!a)throw new Error("[RouterTab] component must be used within a Vue application context.");const s=a.appContext.app.config.globalProperties.$router;if(!s)throw new Error("[RouterTab] Vue Router is required. Make sure to call app.use(router) before RouterTab.");const i=Ae(s,{initialTabs:e.tabs,keepAlive:e.keepAlive,maxAlive:e.maxAlive,keepLastTab:e.keepLastTab,appendPosition:e.append,defaultRoute:e.defaultPage});n.provide(V,i),a.appContext.config.globalProperties.$tabs=i;const p=n.computed(()=>!!a?.slots?.default),v=n.computed(()=>!!a?.slots?.start),c=n.computed(()=>!!a?.slots?.end),d=n.ref(0),g=n.computed(()=>{d.value;const t={};return i.tabs.forEach(r=>{const f=typeof r.title=="string"?r.title:String(r.title||re(r));t[r.id]=f}),t});function E(){d.value++}const A=new Map,S=new Map;function N(t,r){if(!r||A.has(t))return;A.set(t,r);const f=i.tabs.find(h=>i.getRouteKey(h.to)===t);if(!f)return;const y=[];if(r.routeTabTitle!==void 0){const h=n.watch(()=>{const u=r.routeTabTitle;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{if(u!=null){const L=String(u);f.title=L,E()}},{immediate:!0});y.push(h)}if(r.routeTabIcon!==void 0){const h=n.watch(()=>{const u=r.routeTabIcon;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{u!=null&&(f.icon=String(u),E())},{immediate:!0});y.push(h)}if(r.routeTabClosable!==void 0){const h=n.watch(()=>{const u=r.routeTabClosable;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{u!=null&&(f.closable=!!u,E())},{immediate:!0});y.push(h)}if(r.routeTabMeta!==void 0){const h=n.watch(()=>{const u=r.routeTabMeta;return u&&typeof u=="object"&&"value"in u?u.value:u},u=>{u&&typeof u=="object"&&(Object.assign(f,u),E())},{immediate:!0,deep:!0});y.push(h)}S.set(t,y)}function O(t){const r=S.get(t);r&&(r.forEach(f=>f()),S.delete(t)),A.delete(t)}function M(t,r){t?t.routeTabTitle!==void 0||t.routeTabIcon!==void 0||t.routeTabClosable!==void 0?N(r,t):t.$&&(t.$.routeTabTitle!==void 0||t.$.routeTabIcon!==void 0||t.$.routeTabClosable!==void 0)&&N(r,t.$):t===null&&O(r)}if(e.cookieKey!==null||e.persistence){const t={...e.persistence??{}};e.cookieKey!==null?t.cookieKey=e.cookieKey||Y:t.cookieKey||(t.cookieKey=Y),ee(t)}const oe=n.computed(()=>ue(e.tabTransition)),ae=n.computed(()=>ue(e.pageTransition)),T=n.reactive({visible:!1,target:null,position:{x:0,y:0}}),W=n.ref(null),D=n.ref([]),I=n.ref(-1),l=n.reactive({dragging:!1,dragIndex:-1,dropIndex:-1,dragTab:null}),m=["refresh","refreshAll","close","closeLefts","closeRights","closeOthers"];function b(t){return i.tabs.findIndex(r=>r.id===t)}function k(t){const r=b(t.id);return r>0?i.tabs.slice(0,r):[]}function C(t){const r=b(t.id);return r>-1?i.tabs.slice(r+1):[]}function B(t){return i.tabs.filter(r=>r.id!==t.id)}async function K(t,r){const f=t.filter(y=>y.closable!==!1);if(f.length){for(const y of f)i.activeId.value===y.id?await i.closeTab(y.id,{redirect:r.to,force:!0}):await i.removeTab(y.id,{force:!0});i.activeId.value!==r.id&&await i.openTab(r.to,!0,!1)}}const tt={refresh:{label:"Refresh",handler:async({target:t})=>{await i.refreshTab(t.id,!0)}},refreshAll:{label:"Refresh All",handler:async()=>{await i.refreshAll(!0)}},close:{label:"Close",handler:async({target:t})=>{await i.closeTab(t.id)},enable:({target:t})=>ie(t)},closeLefts:{label:"Close to the Left",handler:async({target:t})=>{await K(k(t),t)},enable:({target:t})=>k(t).some(r=>r.closable!==!1)},closeRights:{label:"Close to the Right",handler:async({target:t})=>{await K(C(t),t)},enable:({target:t})=>C(t).some(r=>r.closable!==!1)},closeOthers:{label:"Close Others",handler:async({target:t})=>{await K(B(t),t)},enable:({target:t})=>B(t).some(r=>r.closable!==!1)}};function P(){T.visible=!1,T.target=null,I.value=-1,D.value=[]}function nt(t,r){e.contextmenu&&(T.target=t,T.position.x=r.clientX,T.position.y=r.clientY,n.nextTick(()=>{T.visible=!0,document.addEventListener("click",P,{once:!0}),n.nextTick(()=>{at()})}))}function ot(t,r){const f=typeof t=="string"?{id:t}:t,y=tt[f.id],h=f.label??y?.label??String(f.id),u=f.visible??y?.visible??!0;if(!(typeof u=="function"?u(r):u!==!1))return null;const le=f.enable??y?.enable??!0,vt=typeof le=="function"?le(r):le!==!1,Ce=f.handler??y?.handler;if(!Ce)return null;const wt=async()=>{await Promise.resolve(Ce(r))};return{id:String(f.id),label:h,disabled:!vt,action:wt}}const U=n.computed(()=>{if(!T.visible||!T.target||e.contextmenu===!1)return[];const t=Array.isArray(e.contextmenu)?e.contextmenu:m,r={target:T.target,controller:i};return t.map(f=>ot(f,r)).filter(f=>!!f)});function at(){const t=W.value;if(!t)return;const r=8,{innerWidth:f,innerHeight:y}=window,h=t.getBoundingClientRect();let u=T.position.x,L=T.position.y;h.right>f-r&&(u=Math.max(r,f-h.width-r)),h.bottom>y-r&&(L=Math.max(r,y-h.height-r)),(u!==T.position.x||L!==T.position.y)&&(T.position.x=u,T.position.y=L)}function rt(t,r){const f=t?.$el||t;D.value[r]=f??null}function it(t){if(t<0)return;D.value[t]?.focus({preventScroll:!0})}function q(t,r,f=U.value){if(!f.length)return-1;const y=f.length;let h=t;for(let u=0;u<y;u++)if(h=(h+r+y)%y,!f[h].disabled)return h;return-1}function z(t){I.value=t,!(t<0)&&n.nextTick(()=>it(t))}function Te(t){const r=q(I.value,t);r!==-1&&z(r)}function lt(t){if(!T.visible)return;const r=t.key,f=U.value;if(!f.length)return;if(r==="Tab"){P();return}if(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End","Enter"," ","Spacebar","Escape"].includes(r))switch(t.preventDefault(),r){case"ArrowDown":case"ArrowRight":Te(1);break;case"ArrowUp":case"ArrowLeft":Te(-1);break;case"Home":z(q(-1,1));break;case"End":z(q(f.length,-1));break;case"Enter":case" ":case"Spacebar":{const h=I.value;if(h>-1){const u=f[h];u.disabled||ke(u)}break}case"Escape":P();break}}async function ke(t){t.disabled||(P(),await t.action())}function re(t){return typeof t.title=="string"&&t.title.trim()?t.title:Array.isArray(t.title)&&t.title.length&&String(t.title[0]).trim()?String(t.title[0]):"Untitled"}function st(t){return g.value[t.id]||re(t)}function ve(t){const r=i.getRouteKey(t),f=i.tabs.find(h=>h.id===r);if(!f)return console.warn(`[RouterTab] Tab not found for key: ${r}. This may cause rendering issues.`),`${r}::0`;const y=f.renderKey??0;return`${r}::${y}`}function ct(t){return`${ve(t)}::refresh`}function ie(t){return!(t.closable===!1||i.options.keepLastTab&&i.tabs.length<=1)}async function ut(t){await i.closeTab(t.id)}function dt(t){if(t.href&&typeof window<"u"){t.target&&t.target!=="_self"?window.open(t.href,t.target):window.location.assign(t.href);return}i.activeId.value!==t.id&&i.openTab(t.to,!1)}function ft(t){return["router-tab__item",{"is-active":i.activeId.value===t.id,"is-closable":ie(t),"is-dragging":l.dragging&&l.dragTab?.id===t.id,"is-drag-over":l.dropIndex===b(t.id)},t.tabClass]}function bt(t){return i.refreshingKey.value===i.getRouteKey(t)}function mt(t){const r=i.getRouteKey(t);return i.tabs.some(f=>f.id===r)}function pt(t,r,f){e.sortable&&(l.dragging=!0,l.dragIndex=r,l.dragTab=t,f.dataTransfer&&(f.dataTransfer.effectAllowed="move",f.dataTransfer.setData("text/plain",t.id)),o("tab-sort",{tab:t,index:r}))}function gt(t,r){!e.sortable||!l.dragging||(r.preventDefault(),r.dataTransfer&&(r.dataTransfer.dropEffect="move"))}function yt(t){!e.sortable||!l.dragging||(l.dropIndex=t)}function ht(){!e.sortable||l.dragging}function Tt(t,r){if(!(!e.sortable||!l.dragging)){if(r.preventDefault(),l.dragIndex!==-1&&l.dragIndex!==t){const f=i.tabs.splice(l.dragIndex,1)[0];i.tabs.splice(t,0,f),o("tab-sorted",{tab:f,fromIndex:l.dragIndex,toIndex:t})}we()}}function we(){l.dragging=!1,l.dragIndex=-1,l.dropIndex=-1,l.dragTab=null}n.onMounted(()=>{document.addEventListener("keydown",P)}),n.onBeforeUnmount(()=>{document.removeEventListener("keydown",P),a.appContext.config.globalProperties.$tabs=null,S.forEach(t=>{t.forEach(r=>r())}),S.clear(),A.clear()}),n.watch(()=>e.keepAlive,t=>{i.options.keepAlive=t}),n.watch(()=>i.activeId.value,()=>P()),n.watch(()=>e.contextmenu,t=>{t||P()}),n.watch(()=>U.value.length,t=>{T.visible&&t===0&&P()},{flush:"post"}),n.watch(U,t=>{if(!T.visible)return;D.value=new Array(t.length).fill(null);const r=q(-1,1,t);z(r)},{flush:"post"}),n.watch(()=>T.visible,t=>{t||(I.value=-1,D.value=[])});const kt=i.includeKeys;return{controller:i,tabs:i.tabs,includeKeys:kt,tabTransitionProps:oe,pageTransitionProps:ae,buildTabClass:ft,activate:dt,close:ut,context:T,menuItems:U,handleMenuAction:ke,showContextMenu:nt,hideContextMenu:P,getTabTitle:re,isClosable:ie,isRefreshing:bt,isTabReady:mt,hasCustomSlot:p,hasStartSlot:v,hasEndSlot:c,onDragStart:pt,onDragOver:gt,onDragEnter:yt,onDragLeave:ht,onDrop:Tt,onDragEnd:we,setupComponentWatching:N,cleanupComponentWatching:O,handleComponentRef:M,getReactiveTabTitle:st,getComponentCacheKey:ve,getRefreshComponentKey:ct,triggerTabUpdate:E,menuRef:W,highlightedIndex:I,setMenuItemRef:rt,onMenuKeydown:lt,highlightMenuIndex:z}}}),Me=(e,o)=>{const a=e.__vccOpts||e;for(const[s,i]of o)a[s]=i;return a},Le={class:"router-tab"},Ve={class:"router-tab__header"},je={class:"router-tab__scroll"},Ne=["data-title","draggable","onClick","onAuxclick","onContextmenu","onDragstart","onDragover","onDragenter","onDrop"],Oe=["title"],Ue=["onClick"],ze={class:"router-tab__container"},_e=["aria-disabled","disabled","tabindex","onMouseenter","onClick"];function Ye(e,o,a,s,i,p){const v=n.resolveComponent("RouterView");return n.openBlock(),n.createElementBlock("div",Le,[n.createElementVNode("header",Ve,[n.createElementVNode("div",{class:n.normalizeClass(["router-tab__slot-start",{"has-content":e.hasStartSlot}])},[n.renderSlot(e.$slots,"start")],2),n.createElementVNode("div",je,[n.createVNode(n.TransitionGroup,n.mergeProps({tag:"ul",class:"router-tab__nav"},e.tabTransitionProps),{default:n.withCtx(()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(e.tabs,(c,d)=>(n.openBlock(),n.createElementBlock("li",{key:c.id,class:n.normalizeClass(e.buildTabClass(c)),"data-title":e.getTabTitle(c),draggable:e.sortable,onClick:g=>e.activate(c),onAuxclick:n.withModifiers(g=>e.close(c),["middle","prevent"]),onContextmenu:n.withModifiers(g=>e.showContextMenu(c,g),["prevent"]),onDragstart:g=>e.onDragStart(c,d,g),onDragover:g=>e.onDragOver(d,g),onDragenter:g=>e.onDragEnter(d),onDragleave:o[0]||(o[0]=(...g)=>e.onDragLeave&&e.onDragLeave(...g)),onDrop:g=>e.onDrop(d,g),onDragend:o[1]||(o[1]=(...g)=>e.onDragEnd&&e.onDragEnd(...g))},[c.icon?(n.openBlock(),n.createElementBlock("i",{key:0,class:n.normalizeClass(["router-tab__item-icon",c.icon])},null,2)):n.createCommentVNode("",!0),n.createElementVNode("span",{class:"router-tab__item-title",title:e.getReactiveTabTitle(c)},n.toDisplayString(e.getReactiveTabTitle(c)),9,Oe),e.isClosable(c)?(n.openBlock(),n.createElementBlock("a",{key:1,class:"router-tab__item-close",onClick:n.withModifiers(g=>e.close(c),["stop"])},null,8,Ue)):n.createCommentVNode("",!0)],42,Ne))),128))]),_:1},16)]),n.createElementVNode("div",{class:n.normalizeClass(["router-tab__slot-end",{"has-content":e.hasEndSlot}])},[n.renderSlot(e.$slots,"end")],2)]),n.createElementVNode("div",ze,[n.createVNode(v,null,{default:n.withCtx(c=>[e.hasCustomSlot?n.renderSlot(e.$slots,"default",n.normalizeProps(n.mergeProps({key:0},{...c,controller:e.controller,pageRef:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route))}))):(n.openBlock(),n.createBlock(n.Transition,n.mergeProps({key:1},e.pageTransitionProps,{appear:""}),{default:n.withCtx(()=>[c.Component&&e.isTabReady(c.route)?(n.openBlock(),n.createElementBlock(n.Fragment,{key:0},[e.isRefreshing(c.route)?(n.openBlock(),n.createBlock(n.resolveDynamicComponent(c.Component),{key:e.getRefreshComponentKey(c.route),ref:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route)),class:"router-tab-page"})):e.controller.options.keepAlive?(n.openBlock(),n.createBlock(n.KeepAlive,{key:1,include:e.includeKeys,max:e.controller.options.maxAlive||void 0},[(n.openBlock(),n.createBlock(n.resolveDynamicComponent(c.Component),{key:e.getComponentCacheKey(c.route),ref:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route)),class:"router-tab-page"}))],1032,["include","max"])):(n.openBlock(),n.createBlock(n.resolveDynamicComponent(c.Component),{key:e.getComponentCacheKey(c.route),ref:d=>e.handleComponentRef(d,e.controller.getRouteKey(c.route)),class:"router-tab-page"}))],64)):n.createCommentVNode("",!0)]),_:2},1040))]),_:3})]),n.withDirectives(n.createElementVNode("div",{ref:"menuRef",class:"router-tab__contextmenu",role:"menu",onKeydown:o[2]||(o[2]=(...c)=>e.onMenuKeydown&&e.onMenuKeydown(...c)),style:n.normalizeStyle({left:e.context.position.x+"px",top:e.context.position.y+"px"})},[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(e.menuItems,(c,d)=>(n.openBlock(),n.createElementBlock("a",{key:c.id,role:"menuitem",class:n.normalizeClass(["router-tab__contextmenu-item",{"is-focused":d===e.highlightedIndex}]),"aria-disabled":c.disabled,disabled:c.disabled,tabindex:c.disabled?-1:d===e.highlightedIndex?0:-1,ref_for:!0,ref:g=>e.setMenuItemRef(g,d),onMouseenter:g=>!c.disabled&&e.highlightMenuIndex(d),onClick:g=>e.handleMenuAction(c)},n.toDisplayString(c.label),43,_e))),128))],36),[[n.vShow,e.context.visible&&e.context.target]])])}const te=Me(xe,[["render",Ye]]),Fe={class:"router-tabs","aria-hidden":"true"},F=n.defineComponent({name:"RouterTabs",__name:"RouterTabs",props:{cookieKey:{},expiresInDays:{},path:{},domain:{},secure:{type:Boolean},sameSite:{},serialize:{type:Function},deserialize:{type:Function},fallbackRoute:{}},setup(e){return ee(e),(a,s)=>(n.openBlock(),n.createElementBlock("span",Fe))}}),be="tab-theme-style",me="tab-theme-primary-color",He="system",pe="(prefers-color-scheme: dark)";let j=null;const R={primary:"#034960",background:"#ffffff",text:"#1e293b",border:"#e2e8f0",activeBackground:"#034960",activeText:"#ffffff",activeBorder:"#034960",headerBackground:"#ffffff",buttonBackground:"#f8fafc",buttonColor:"#034960",activeButtonBackground:"#034960",activeButtonColor:"#ffffff",iconColor:"#475569"},Je={primary:"#38bdf8",background:"#0f172a",text:"#f1f5f9",border:"#334155",activeBackground:"#1e293b",activeText:"#38bdf8",activeBorder:"#38bdf8",headerBackground:"#0c4a6e",buttonBackground:"#1e293b",buttonColor:"#f1f5f9",activeButtonBackground:"#38bdf8",activeButtonColor:"#0f172a",iconColor:"#cbd5e1"};function We(e){if(typeof window>"u")return null;const o=window.localStorage.getItem(e);if(!o)return null;try{const a=JSON.parse(o);return a&&typeof a=="object"?a:null}catch{return null}}function ne(e){typeof document>"u"||(document.documentElement.style.setProperty("--router-tab-primary",e.primary??R.primary),document.documentElement.style.setProperty("--router-tab-header-bg",e.headerBackground??R.headerBackground),document.documentElement.style.setProperty("--router-tab-background",e.background??R.background),document.documentElement.style.setProperty("--router-tab-active-background",e.activeBackground??R.activeBackground),document.documentElement.style.setProperty("--router-tab-text",e.text??R.text),document.documentElement.style.setProperty("--router-tab-active-text",e.activeText??R.activeText),document.documentElement.style.setProperty("--router-tab-border",e.border??R.border),document.documentElement.style.setProperty("--router-tab-active-border",e.activeBorder??R.activeBorder),document.documentElement.style.setProperty("--router-tab-button-color",e.buttonColor??R.buttonColor),document.documentElement.style.setProperty("--router-tab-active-button-color",e.activeButtonColor??R.activeButtonColor),document.documentElement.style.setProperty("--router-tab-button-background",e.buttonBackground??R.buttonBackground),document.documentElement.style.setProperty("--router-tab-active-button-background",e.activeButtonBackground??R.activeButtonBackground),document.documentElement.style.setProperty("--router-tab-icon-color",e.iconColor??R.iconColor))}function ge(e){if(typeof document>"u")return;const o=document.documentElement,a=window.matchMedia(pe),s=()=>{o.dataset.theme=a.matches?"dark":"light"};j&&(a.removeEventListener("change",j),j=null),e==="system"?(s(),j=()=>s(),a.addEventListener("change",j)):o.dataset.theme=e}function ye(e={}){if(typeof window>"u")return;const{styleKey:o=be,primaryKey:a=me,defaultStyle:s=He,defaultPrimary:i}=e,p=window.localStorage.getItem(o)??s;ge(p);const c=p==="dark"||p==="system"&&window.matchMedia(pe).matches?{...Je}:{...R};i&&(c.primary=i);const d=We(a);ne(d?{...c,...d}:c)}function qe(e,o){if(typeof window>"u")return;const a=o?.styleKey??be;window.localStorage.setItem(a,e),ge(e)}function Ge(e,o){if(typeof window>"u")return;const a=o?.primaryKey??me;window.localStorage.setItem(a,JSON.stringify(e)),ne(e)}function H(e,o){if(n.isRef(e)){const s=!n.isReadonly(e);return{value:e,update:s?i=>{e.value=i}:()=>{}}}if(typeof e=="function"){const s=e;return{value:n.computed(s),update:()=>{}}}const a=n.ref(e===void 0?o:e);return{value:a,update:s=>{a.value=s}}}function J(e={}){const o=H(e.title,"Untitled"),a=H(e.icon,""),s=H(e.closable,!0),i=H(e.meta,{});return{routeTabTitle:o.value,routeTabIcon:a.value,routeTabClosable:s.value,routeTabMeta:i.value,updateTitle:o.update,updateIcon:a.update,updateClosable:s.update,updateMeta:i.update}}function Xe(e,o="Page"){return J({title:n.computed(()=>e.value?"Loading...":o),icon:n.computed(()=>e.value?"mdi-loading mdi-spin":"mdi-page"),closable:n.computed(()=>!e.value)})}function Qe(e,o="Page",a="mdi-page"){return J({title:n.computed(()=>e.value>0?`${o} (${e.value})`:o),icon:n.computed(()=>e.value>0?"mdi-bell-badge":a)})}function Ze(e,o="Page"){const a={normal:{suffix:"",icon:"mdi-page"},loading:{suffix:" - Loading",icon:"mdi-loading mdi-spin"},error:{suffix:" - Error",icon:"mdi-alert"},success:{suffix:" - Success",icon:"mdi-check-circle"}};return J({title:n.computed(()=>o+a[e.value].suffix),icon:n.computed(()=>a[e.value].icon),closable:n.computed(()=>e.value!=="loading")})}let he=!1;const et={install(e,o){if(he)return;he=!0;const{initTheme:a=!0,themeOptions:s,componentName:i=te.name||"RouterTab",tabsComponentName:p=F.name||"RouterTabs"}=o??{};a&&ye(s??{}),e.component(i,te),e.component(p,F),p.toLowerCase()!=="router-tabs"&&e.component("router-tabs",F),Object.defineProperty(e.config.globalProperties,"$tabs",{configurable:!0,enumerable:!1,get(){return e._context.provides[V]},set(v){v&&e.provide(V,v)}})}};w.RouterTab=te,w.RouterTabs=F,w.default=et,w.initRouterTabsTheme=ye,w.routerTabsKey=V,w.setRouterTabsPrimary=Ge,w.setRouterTabsTheme=qe,w.useLoadingTab=Xe,w.useNotificationTab=Qe,w.useReactiveTab=J,w.useRouterTabs=Z,w.useRouterTabsPersistence=ee,w.useStatusTab=Ze,Object.defineProperties(w,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
@@ -68,32 +68,35 @@
|
|
|
68
68
|
v-bind="pageTransitionProps"
|
|
69
69
|
appear
|
|
70
70
|
>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
:is="routerSlot.Component"
|
|
74
|
-
:key="getRefreshComponentKey(routerSlot.route)"
|
|
75
|
-
:ref="(el: any) => handleComponentRef(el, controller.getRouteKey(routerSlot.route))"
|
|
76
|
-
class="router-tab-page"
|
|
77
|
-
/>
|
|
78
|
-
<KeepAlive
|
|
79
|
-
v-else-if="controller.options.keepAlive"
|
|
80
|
-
:include="includeKeys"
|
|
81
|
-
:max="controller.options.maxAlive || undefined"
|
|
82
|
-
>
|
|
71
|
+
<!-- Only render if Component is available to prevent blank pages on first load -->
|
|
72
|
+
<template v-if="routerSlot.Component && isTabReady(routerSlot.route)">
|
|
83
73
|
<component
|
|
74
|
+
v-if="isRefreshing(routerSlot.route)"
|
|
75
|
+
:is="routerSlot.Component"
|
|
76
|
+
:key="getRefreshComponentKey(routerSlot.route)"
|
|
77
|
+
:ref="(el: any) => handleComponentRef(el, controller.getRouteKey(routerSlot.route))"
|
|
78
|
+
class="router-tab-page"
|
|
79
|
+
/>
|
|
80
|
+
<KeepAlive
|
|
81
|
+
v-else-if="controller.options.keepAlive"
|
|
82
|
+
:include="includeKeys"
|
|
83
|
+
:max="controller.options.maxAlive || undefined"
|
|
84
|
+
>
|
|
85
|
+
<component
|
|
86
|
+
:is="routerSlot.Component"
|
|
87
|
+
:key="getComponentCacheKey(routerSlot.route)"
|
|
88
|
+
:ref="(el: any) => handleComponentRef(el, controller.getRouteKey(routerSlot.route))"
|
|
89
|
+
class="router-tab-page"
|
|
90
|
+
/>
|
|
91
|
+
</KeepAlive>
|
|
92
|
+
<component
|
|
93
|
+
v-else
|
|
84
94
|
:is="routerSlot.Component"
|
|
85
95
|
:key="getComponentCacheKey(routerSlot.route)"
|
|
86
96
|
:ref="(el: any) => handleComponentRef(el, controller.getRouteKey(routerSlot.route))"
|
|
87
97
|
class="router-tab-page"
|
|
88
98
|
/>
|
|
89
|
-
</
|
|
90
|
-
<component
|
|
91
|
-
v-else
|
|
92
|
-
:is="routerSlot.Component"
|
|
93
|
-
:key="getComponentCacheKey(routerSlot.route)"
|
|
94
|
-
:ref="(el: any) => handleComponentRef(el, controller.getRouteKey(routerSlot.route))"
|
|
95
|
-
class="router-tab-page"
|
|
96
|
-
/>
|
|
99
|
+
</template>
|
|
97
100
|
</transition>
|
|
98
101
|
</template>
|
|
99
102
|
</RouterView>
|
|
@@ -609,8 +612,10 @@ export default defineComponent({
|
|
|
609
612
|
}
|
|
610
613
|
}
|
|
611
614
|
|
|
612
|
-
function setMenuItemRef(el:
|
|
613
|
-
|
|
615
|
+
function setMenuItemRef(el: any, index: number) {
|
|
616
|
+
// Handle both direct elements and component instances
|
|
617
|
+
const element = el?.$el || el
|
|
618
|
+
menuItemRefs.value[index] = (element as HTMLElement) ?? null
|
|
614
619
|
}
|
|
615
620
|
|
|
616
621
|
function focusMenuItem(index: number) {
|
|
@@ -729,7 +734,13 @@ export default defineComponent({
|
|
|
729
734
|
function getComponentCacheKey(route: RouteLocationNormalizedLoaded): string {
|
|
730
735
|
const routeKey = controller.getRouteKey(route)
|
|
731
736
|
const tab = controller.tabs.find(item => item.id === routeKey)
|
|
732
|
-
|
|
737
|
+
|
|
738
|
+
if (!tab) {
|
|
739
|
+
console.warn(`[RouterTab] Tab not found for key: ${routeKey}. This may cause rendering issues.`)
|
|
740
|
+
return `${routeKey}::0`
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const renderKey = tab.renderKey ?? 0
|
|
733
744
|
return `${routeKey}::${renderKey}`
|
|
734
745
|
}
|
|
735
746
|
|
|
@@ -778,6 +789,11 @@ export default defineComponent({
|
|
|
778
789
|
return controller.refreshingKey.value === controller.getRouteKey(route)
|
|
779
790
|
}
|
|
780
791
|
|
|
792
|
+
function isTabReady(route: RouteLocationNormalizedLoaded): boolean {
|
|
793
|
+
const routeKey = controller.getRouteKey(route)
|
|
794
|
+
return controller.tabs.some(tab => tab.id === routeKey)
|
|
795
|
+
}
|
|
796
|
+
|
|
781
797
|
// Drag and drop handlers
|
|
782
798
|
function onDragStart(tab: TabRecord, index: number, event: DragEvent) {
|
|
783
799
|
if (!props.sortable) return
|
|
@@ -919,6 +935,7 @@ export default defineComponent({
|
|
|
919
935
|
getTabTitle,
|
|
920
936
|
isClosable,
|
|
921
937
|
isRefreshing,
|
|
938
|
+
isTabReady,
|
|
922
939
|
hasCustomSlot,
|
|
923
940
|
hasStartSlot,
|
|
924
941
|
hasEndSlot,
|