vue3-router-tab 0.0.1 → 1.0.0

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.
@@ -0,0 +1,809 @@
1
+ import './vue3-router-tab.css';
2
+ import { defineComponent as oe, inject as z, computed as S, unref as Oe, provide as U, ref as J, watch as x, h as Ve, getCurrentInstance as ae, reactive as Ce, shallowRef as Ie, nextTick as se, onMounted as _e, onBeforeUnmount as Ke, resolveComponent as Ne, createElementBlock as A, openBlock as T, createElementVNode as I, createCommentVNode as K, renderSlot as re, createVNode as j, TransitionGroup as $e, mergeProps as Q, withCtx as M, Fragment as le, renderList as ce, withModifiers as B, normalizeClass as ue, createTextVNode as Le, toDisplayString as fe, Transition as de, createBlock as W, KeepAlive as De, resolveDynamicComponent as pe, normalizeStyle as je } from "vue";
3
+ import { defineStore as Me } from "pinia";
4
+ /*!
5
+ * vue-router v4.5.1
6
+ * (c) 2025 Eduardo San Martin Morote
7
+ * @license MIT
8
+ */
9
+ const Be = typeof document < "u", Ge = Object.assign, Ue = Array.isArray;
10
+ function ze(e) {
11
+ const n = Array.from(arguments).slice(1);
12
+ console.warn.apply(console, ["[Vue Router warn]: " + e].concat(n));
13
+ }
14
+ function Je(e, n) {
15
+ return (e.aliasOf || e) === (n.aliasOf || n);
16
+ }
17
+ var be;
18
+ (function(e) {
19
+ e.pop = "pop", e.push = "push";
20
+ })(be || (be = {}));
21
+ var ve;
22
+ (function(e) {
23
+ e.back = "back", e.forward = "forward", e.unknown = "";
24
+ })(ve || (ve = {}));
25
+ Symbol(process.env.NODE_ENV !== "production" ? "navigation failure" : "");
26
+ var he;
27
+ (function(e) {
28
+ e[e.aborted = 4] = "aborted", e[e.cancelled = 8] = "cancelled", e[e.duplicated = 16] = "duplicated";
29
+ })(he || (he = {}));
30
+ const He = Symbol(process.env.NODE_ENV !== "production" ? "router view location matched" : ""), me = Symbol(process.env.NODE_ENV !== "production" ? "router view depth" : "");
31
+ Symbol(process.env.NODE_ENV !== "production" ? "router" : "");
32
+ Symbol(process.env.NODE_ENV !== "production" ? "route location" : "");
33
+ const ye = Symbol(process.env.NODE_ENV !== "production" ? "router view location" : ""), qe = /* @__PURE__ */ oe({
34
+ name: "RouterView",
35
+ // #674 we manually inherit them
36
+ inheritAttrs: !1,
37
+ props: {
38
+ name: {
39
+ type: String,
40
+ default: "default"
41
+ },
42
+ route: Object
43
+ },
44
+ // Better compat for @vue/compat users
45
+ // https://github.com/vuejs/router/issues/1315
46
+ compatConfig: { MODE: 3 },
47
+ setup(e, { attrs: n, slots: a }) {
48
+ process.env.NODE_ENV !== "production" && Ye();
49
+ const t = z(ye), r = S(() => e.route || t.value), u = z(me, 0), d = S(() => {
50
+ let h = Oe(u);
51
+ const { matched: b } = r.value;
52
+ let m;
53
+ for (; (m = b[h]) && !m.components; )
54
+ h++;
55
+ return h;
56
+ }), f = S(() => r.value.matched[d.value]);
57
+ U(me, S(() => d.value + 1)), U(He, f), U(ye, r);
58
+ const p = J();
59
+ return x(() => [p.value, f.value, e.name], ([h, b, m], [k, y, C]) => {
60
+ b && (b.instances[m] = h, y && y !== b && h && h === k && (b.leaveGuards.size || (b.leaveGuards = y.leaveGuards), b.updateGuards.size || (b.updateGuards = y.updateGuards))), h && b && // if there is no instance but to and from are the same this might be
61
+ // the first visit
62
+ (!y || !Je(b, y) || !k) && (b.enterCallbacks[m] || []).forEach((_) => _(h));
63
+ }, { flush: "post" }), () => {
64
+ const h = r.value, b = e.name, m = f.value, k = m && m.components[b];
65
+ if (!k)
66
+ return ge(a.default, { Component: k, route: h });
67
+ const y = m.props[b], C = y ? y === !0 ? h.params : typeof y == "function" ? y(h) : y : null, g = Ve(k, Ge({}, C, n, {
68
+ onVnodeUnmounted: (E) => {
69
+ E.component.isUnmounted && (m.instances[b] = null);
70
+ },
71
+ ref: p
72
+ }));
73
+ if (process.env.NODE_ENV !== "production" && Be && g.ref) {
74
+ const E = {
75
+ depth: d.value,
76
+ name: m.name,
77
+ path: m.path,
78
+ meta: m.meta
79
+ };
80
+ (Ue(g.ref) ? g.ref.map((P) => P.i) : [g.ref.i]).forEach((P) => {
81
+ P.__vrv_devtools = E;
82
+ });
83
+ }
84
+ return (
85
+ // pass the vnode to the slot as a prop.
86
+ // h and <component :is="..."> both accept vnodes
87
+ ge(a.default, { Component: g, route: h }) || g
88
+ );
89
+ };
90
+ }
91
+ });
92
+ function ge(e, n) {
93
+ if (!e)
94
+ return null;
95
+ const a = e(n);
96
+ return a.length === 1 ? a[0] : a;
97
+ }
98
+ const Xe = qe;
99
+ function Ye() {
100
+ const e = ae(), n = e.parent && e.parent.type.name, a = e.parent && e.parent.subTree && e.parent.subTree.type;
101
+ if (n && (n === "KeepAlive" || n.includes("Transition")) && typeof a == "object" && a.name === "RouterView") {
102
+ const t = n === "KeepAlive" ? "keep-alive" : "transition";
103
+ ze(`<router-view> can no longer be used directly inside <transition> or <keep-alive>.
104
+ Use slot props instead:
105
+
106
+ <router-view v-slot="{ Component }">
107
+ <${t}>
108
+ <component :is="Component" />
109
+ </${t}>
110
+ </router-view>`);
111
+ }
112
+ }
113
+ function Fe(e = {}) {
114
+ return {
115
+ initialTabs: e.initialTabs ?? [],
116
+ keepAlive: e.keepAlive ?? !0,
117
+ maxAlive: e.maxAlive ?? 0,
118
+ keepLastTab: e.keepLastTab ?? !0,
119
+ appendPosition: e.appendPosition ?? "last",
120
+ defaultRoute: e.defaultRoute ?? "/"
121
+ };
122
+ }
123
+ function N(e, n) {
124
+ const a = e.resolve(n);
125
+ if (!a || !a.matched.length)
126
+ throw new Error(`[RouterTabs] Unable to resolve route: ${String(n)}`);
127
+ return a;
128
+ }
129
+ const Qe = {
130
+ path: (e) => e.path,
131
+ fullpath: (e) => e.fullPath,
132
+ fullname: (e) => e.fullPath,
133
+ full: (e) => e.fullPath,
134
+ name: (e) => e.name ? String(e.name) : e.fullPath
135
+ };
136
+ function $(e) {
137
+ const n = e.meta?.key;
138
+ if (typeof n == "function") {
139
+ const a = n(e);
140
+ if (typeof a == "string" && a.length) return a;
141
+ } else if (typeof n == "string" && n.length) {
142
+ const a = Qe[n.toLowerCase()];
143
+ return a ? a(e) : n;
144
+ }
145
+ return e.fullPath;
146
+ }
147
+ function te(e, n) {
148
+ const a = e.meta?.keepAlive;
149
+ return typeof a == "boolean" ? a : n;
150
+ }
151
+ function ne(e, n) {
152
+ const a = e.meta?.reuse;
153
+ return typeof a == "boolean" ? a : n;
154
+ }
155
+ function Ae(e) {
156
+ const n = e.meta ?? {}, a = {};
157
+ return "title" in n && (a.title = n.title), "tips" in n && (a.tips = n.tips), "icon" in n && (a.icon = n.icon), "closable" in n && (a.closable = n.closable), "tabClass" in n && (a.tabClass = n.tabClass), "target" in n && (a.target = n.target), "href" in n && (a.href = n.href), a;
158
+ }
159
+ function G(e, n, a) {
160
+ const t = Ae(e);
161
+ return {
162
+ id: $(e),
163
+ to: e.fullPath,
164
+ fullPath: e.fullPath,
165
+ matched: e,
166
+ alive: te(e, a),
167
+ reusable: ne(e, !1),
168
+ closable: t.closable ?? !0,
169
+ ...t,
170
+ ...n
171
+ };
172
+ }
173
+ function Z(e, n, a, t) {
174
+ if (!e.find((u) => u.id === n.id)) {
175
+ if (a === "next" && t) {
176
+ const u = e.findIndex((d) => d.id === t);
177
+ if (u > -1) {
178
+ e.splice(u + 1, 0, n);
179
+ return;
180
+ }
181
+ }
182
+ e.push(n);
183
+ }
184
+ }
185
+ function we(e, n, a) {
186
+ if (!n || n <= 0) return;
187
+ const t = e.filter((r) => r.alive);
188
+ for (; t.length > n; ) {
189
+ const r = t.shift();
190
+ if (!r || r.id === a) continue;
191
+ const u = e.findIndex((d) => d.id === r.id);
192
+ u > -1 && (e[u].alive = !1);
193
+ }
194
+ }
195
+ function We(e) {
196
+ return {
197
+ to: e.to,
198
+ title: e.title,
199
+ tips: e.tips,
200
+ icon: e.icon,
201
+ tabClass: e.tabClass,
202
+ closable: e.closable
203
+ };
204
+ }
205
+ function Ze(e) {
206
+ const n = {};
207
+ 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), n;
208
+ }
209
+ function et(e, n = {}) {
210
+ const a = Fe(n), t = Ce([]), r = J(null), u = Ie(), d = J(null), f = S(() => t.filter((i) => i.alive).map((i) => i.id));
211
+ let p = !1;
212
+ function h(i) {
213
+ const s = typeof i.matched == "object" ? i : N(e, i);
214
+ return {
215
+ key: $(s),
216
+ fullPath: s.fullPath,
217
+ alive: te(s, a.keepAlive),
218
+ reusable: ne(s, !1),
219
+ matched: s
220
+ };
221
+ }
222
+ function b(i) {
223
+ const s = $(i);
224
+ let l = t.find((w) => w.id === s);
225
+ return l ? (l.fullPath = i.fullPath, l.to = i.fullPath, l.matched = i, l.alive = te(i, a.keepAlive), l.reusable = ne(i, l.reusable), Object.assign(l, Ae(i)), l) : (l = G(i, {}, a.keepAlive), Z(t, l, a.appendPosition, r.value), we(t, a.maxAlive, r.value), l);
226
+ }
227
+ async function m(i, s = !1, l = !0) {
228
+ const w = N(e, i), O = $(w), V = r.value === O;
229
+ l === "sameTab" && (l = V), l && await _(O, !0), await e[s ? "replace" : "push"](w), V && await L();
230
+ }
231
+ function k(i) {
232
+ const s = t.findIndex((w) => w.id === i), l = t[s] || t[s - 1] || t[0];
233
+ return l ? l.to : a.defaultRoute;
234
+ }
235
+ async function y(i = r.value, s = {}) {
236
+ if (i) {
237
+ if (!s.force && a.keepLastTab && t.length === 1)
238
+ throw new Error("[RouterTabs] Unable to close the final tab when keepLastTab is true.");
239
+ if (await C(i, { force: s.force }), s.redirect !== null)
240
+ if (r.value === i) {
241
+ const l = s.redirect ?? k(i);
242
+ l && await e.replace(l);
243
+ } else s.redirect && await e.replace(s.redirect);
244
+ }
245
+ }
246
+ async function C(i, s = {}) {
247
+ const l = t.findIndex((w) => w.id === i);
248
+ l !== -1 && (t.splice(l, 1), d.value === i && (d.value = null), r.value === i && (r.value = null, u.value = void 0));
249
+ }
250
+ async function _(i = r.value ?? void 0, s = !1) {
251
+ i && (d.value = i, await se(), s || await se(), d.value = null);
252
+ }
253
+ async function g(i = !1) {
254
+ for (const s of t)
255
+ await _(s.id, i);
256
+ }
257
+ async function E(i = a.defaultRoute) {
258
+ t.splice(0, t.length), r.value = null, u.value = void 0;
259
+ for (const s of a.initialTabs) {
260
+ const l = N(e, s.to), w = G(l, s, a.keepAlive);
261
+ t.push(w);
262
+ }
263
+ await e.replace(i);
264
+ }
265
+ async function L() {
266
+ const i = r.value;
267
+ i && await _(i, !0);
268
+ }
269
+ function P(i) {
270
+ return typeof i.matched == "object" ? $(i) : $(N(e, i));
271
+ }
272
+ function q() {
273
+ const i = t.find((s) => s.id === r.value);
274
+ return {
275
+ tabs: t.map(We),
276
+ active: i ? i.to : null
277
+ };
278
+ }
279
+ async function X(i) {
280
+ p = !0, t.splice(0, t.length), r.value = null, u.value = void 0;
281
+ const s = i?.tabs ?? [];
282
+ for (const w of s)
283
+ try {
284
+ const O = N(e, w.to), V = Ze(w), D = G(O, V, a.keepAlive);
285
+ Z(t, D, "last", null);
286
+ } catch {
287
+ }
288
+ p = !1;
289
+ const l = i?.active ?? s[s.length - 1]?.to ?? a.defaultRoute;
290
+ if (l)
291
+ try {
292
+ await e.replace(l);
293
+ } catch {
294
+ }
295
+ }
296
+ return x(
297
+ () => e.currentRoute.value,
298
+ (i) => {
299
+ if (p) return;
300
+ const s = b(i);
301
+ r.value = s.id, u.value = s, we(t, a.maxAlive, r.value);
302
+ },
303
+ { immediate: !0 }
304
+ ), a.initialTabs.length && a.initialTabs.forEach((i) => {
305
+ const s = N(e, i.to), l = G(s, i, a.keepAlive);
306
+ Z(t, l, "last", null);
307
+ }), {
308
+ options: a,
309
+ tabs: t,
310
+ activeId: r,
311
+ current: u,
312
+ includeKeys: f,
313
+ refreshingKey: d,
314
+ openTab: m,
315
+ closeTab: y,
316
+ removeTab: C,
317
+ refreshTab: _,
318
+ refreshAll: g,
319
+ reset: E,
320
+ reload: L,
321
+ getRouteKey: P,
322
+ matchRoute: h,
323
+ snapshot: q,
324
+ hydrate: X
325
+ };
326
+ }
327
+ function Te(e) {
328
+ return e ? typeof e == "string" ? { name: e } : e : {};
329
+ }
330
+ const H = Symbol("RouterTabsContext"), ee = typeof window < "u" && "sessionStorage" in window, tt = oe({
331
+ name: "RouterTab",
332
+ components: { RouterView: Xe },
333
+ props: {
334
+ tabs: {
335
+ type: Array,
336
+ default: () => []
337
+ },
338
+ keepAlive: {
339
+ type: Boolean,
340
+ default: !0
341
+ },
342
+ maxAlive: {
343
+ type: Number,
344
+ default: 0
345
+ },
346
+ keepLastTab: {
347
+ type: Boolean,
348
+ default: !0
349
+ },
350
+ append: {
351
+ type: String,
352
+ default: "last"
353
+ },
354
+ defaultPage: {
355
+ type: [String, Object],
356
+ default: "/"
357
+ },
358
+ tabTransition: {
359
+ type: [String, Object],
360
+ default: "router-tab-zoom"
361
+ },
362
+ pageTransition: {
363
+ type: [String, Object],
364
+ default: () => ({ name: "router-tab-swap", mode: "out-in" })
365
+ },
366
+ contextmenu: {
367
+ type: [Boolean, Array],
368
+ default: !0
369
+ },
370
+ storage: {
371
+ type: [Boolean, String],
372
+ default: !1
373
+ }
374
+ },
375
+ setup(e) {
376
+ const n = ae();
377
+ if (!n)
378
+ throw new Error("[RouterTab] component must be used within a Vue application context.");
379
+ const a = n.appContext.app.config.globalProperties.$router;
380
+ if (!a)
381
+ throw new Error("[RouterTab] Vue Router is required. Make sure to call app.use(router) before RouterTab.");
382
+ const t = et(a, {
383
+ initialTabs: e.tabs,
384
+ keepAlive: e.keepAlive,
385
+ maxAlive: e.maxAlive,
386
+ keepLastTab: e.keepLastTab,
387
+ appendPosition: e.append,
388
+ defaultRoute: e.defaultPage
389
+ });
390
+ U(H, t), n.appContext.config.globalProperties.$tabs = t;
391
+ const r = S(() => Te(e.tabTransition)), u = S(() => Te(e.pageTransition)), d = Ce({
392
+ visible: !1,
393
+ target: null,
394
+ position: { x: 0, y: 0 }
395
+ }), f = S(() => !e.storage || !ee ? null : typeof e.storage == "string" ? e.storage : `router-tabs:${(a.options?.history?.base ?? "") || "default"}`);
396
+ let p = !!f.value;
397
+ const h = [
398
+ "refresh",
399
+ "refreshAll",
400
+ "close",
401
+ "closeLefts",
402
+ "closeRights",
403
+ "closeOthers"
404
+ ];
405
+ function b(o) {
406
+ return t.tabs.findIndex((c) => c.id === o);
407
+ }
408
+ function m(o) {
409
+ const c = b(o.id);
410
+ return c > 0 ? t.tabs.slice(0, c) : [];
411
+ }
412
+ function k(o) {
413
+ const c = b(o.id);
414
+ return c > -1 ? t.tabs.slice(c + 1) : [];
415
+ }
416
+ function y(o) {
417
+ return t.tabs.filter((c) => c.id !== o.id);
418
+ }
419
+ async function C(o, c) {
420
+ const v = o.filter((R) => R.closable !== !1);
421
+ if (v.length) {
422
+ for (const R of v)
423
+ t.activeId.value === R.id ? await t.closeTab(R.id, { redirect: c.to, force: !0 }) : await t.removeTab(R.id, { force: !0 });
424
+ t.activeId.value !== c.id && await t.openTab(c.to, !0, !1);
425
+ }
426
+ }
427
+ const _ = {
428
+ refresh: {
429
+ label: "Refresh",
430
+ handler: async ({ target: o }) => {
431
+ await t.refreshTab(o.id, !0);
432
+ }
433
+ },
434
+ refreshAll: {
435
+ label: "Refresh All",
436
+ handler: async () => {
437
+ await t.refreshAll(!0);
438
+ }
439
+ },
440
+ close: {
441
+ label: "Close",
442
+ handler: async ({ target: o }) => {
443
+ await t.closeTab(o.id);
444
+ },
445
+ enable: ({ target: o }) => i(o)
446
+ },
447
+ closeLefts: {
448
+ label: "Close to the Left",
449
+ handler: async ({ target: o }) => {
450
+ await C(m(o), o);
451
+ },
452
+ enable: ({ target: o }) => m(o).some((c) => c.closable !== !1)
453
+ },
454
+ closeRights: {
455
+ label: "Close to the Right",
456
+ handler: async ({ target: o }) => {
457
+ await C(k(o), o);
458
+ },
459
+ enable: ({ target: o }) => k(o).some((c) => c.closable !== !1)
460
+ },
461
+ closeOthers: {
462
+ label: "Close Others",
463
+ handler: async ({ target: o }) => {
464
+ await C(y(o), o);
465
+ },
466
+ enable: ({ target: o }) => y(o).some((c) => c.closable !== !1)
467
+ }
468
+ };
469
+ function g() {
470
+ d.visible = !1, d.target = null;
471
+ }
472
+ function E(o, c) {
473
+ e.contextmenu && (d.visible = !0, d.target = o, d.position.x = c.clientX, d.position.y = c.clientY, document.addEventListener("click", g, { once: !0 }));
474
+ }
475
+ function L(o, c) {
476
+ const v = typeof o == "string" ? { id: o } : o, R = _[v.id], Pe = v.label ?? R?.label ?? String(v.id), Y = v.visible ?? R?.visible ?? !0;
477
+ if (!(typeof Y == "function" ? Y(c) : Y !== !1)) return null;
478
+ const F = v.enable ?? R?.enable ?? !0, xe = typeof F == "function" ? F(c) : F !== !1, ie = v.handler ?? R?.handler;
479
+ if (!ie) return null;
480
+ const Ee = async () => {
481
+ await Promise.resolve(ie(c));
482
+ };
483
+ return {
484
+ id: String(v.id),
485
+ label: Pe,
486
+ disabled: !xe,
487
+ action: Ee
488
+ };
489
+ }
490
+ const P = S(() => {
491
+ if (!d.visible || !d.target || e.contextmenu === !1) return [];
492
+ const o = Array.isArray(e.contextmenu) ? e.contextmenu : h, c = { target: d.target, controller: t };
493
+ return o.map((v) => L(v, c)).filter((v) => !!v);
494
+ });
495
+ async function q(o) {
496
+ o.disabled || (g(), await o.action());
497
+ }
498
+ function X(o) {
499
+ return typeof o.title == "string" ? o.title : Array.isArray(o.title) && o.title.length ? String(o.title[0]) : o.fullPath;
500
+ }
501
+ function i(o) {
502
+ return !(o.closable === !1 || t.options.keepLastTab && t.tabs.length <= 1);
503
+ }
504
+ async function s(o) {
505
+ await t.closeTab(o.id);
506
+ }
507
+ function l(o) {
508
+ t.activeId.value !== o.id && t.openTab(o.to, !1);
509
+ }
510
+ function w(o) {
511
+ return [
512
+ "router-tab__item",
513
+ {
514
+ "is-active": t.activeId.value === o.id,
515
+ "is-closable": i(o)
516
+ },
517
+ o.tabClass
518
+ ];
519
+ }
520
+ function O(o) {
521
+ return t.refreshingKey.value === t.getRouteKey(o);
522
+ }
523
+ async function V() {
524
+ const o = f.value;
525
+ if (!o || !ee) return;
526
+ const c = window.sessionStorage.getItem(o);
527
+ if (c)
528
+ try {
529
+ const v = JSON.parse(c);
530
+ if (!v || !Array.isArray(v.tabs)) return;
531
+ p = !0, await t.hydrate(v);
532
+ } catch {
533
+ } finally {
534
+ p = !1, D();
535
+ }
536
+ }
537
+ function D() {
538
+ const o = f.value;
539
+ if (!(!o || !ee || p))
540
+ try {
541
+ const c = t.snapshot();
542
+ window.sessionStorage.setItem(o, JSON.stringify(c));
543
+ } catch {
544
+ }
545
+ }
546
+ _e(() => {
547
+ document.addEventListener("keydown", g), V();
548
+ }), Ke(() => {
549
+ document.removeEventListener("keydown", g), n.appContext.config.globalProperties.$tabs = null, D();
550
+ }), x(
551
+ () => e.keepAlive,
552
+ (o) => {
553
+ t.options.keepAlive = o;
554
+ }
555
+ ), x(
556
+ () => t.activeId.value,
557
+ () => g()
558
+ ), x(
559
+ () => e.contextmenu,
560
+ (o) => {
561
+ o || g();
562
+ }
563
+ ), x(
564
+ () => P.value.length,
565
+ (o) => {
566
+ d.visible && o === 0 && g();
567
+ }
568
+ ), x(
569
+ () => ({
570
+ key: f.value,
571
+ tabs: t.tabs.map((o) => ({
572
+ to: o.to,
573
+ title: o.title,
574
+ tips: o.tips,
575
+ icon: o.icon,
576
+ tabClass: o.tabClass,
577
+ closable: o.closable
578
+ })),
579
+ active: t.activeId.value
580
+ }),
581
+ () => {
582
+ D();
583
+ },
584
+ { deep: !0 }
585
+ );
586
+ const Se = t.includeKeys;
587
+ return {
588
+ controller: t,
589
+ tabs: t.tabs,
590
+ includeKeys: Se,
591
+ tabTransitionProps: r,
592
+ pageTransitionProps: u,
593
+ buildTabClass: w,
594
+ activate: l,
595
+ close: s,
596
+ context: d,
597
+ menuItems: P,
598
+ handleMenuAction: q,
599
+ showContextMenu: E,
600
+ hideContextMenu: g,
601
+ tabTitle: X,
602
+ isClosable: i,
603
+ isRefreshing: O
604
+ };
605
+ }
606
+ }), nt = (e, n) => {
607
+ const a = e.__vccOpts || e;
608
+ for (const [t, r] of n)
609
+ a[t] = r;
610
+ return a;
611
+ }, ot = { class: "router-tab" }, at = { class: "router-tab__header" }, it = { class: "router-tab__slot-start" }, st = { class: "router-tab__scroll" }, rt = ["onClick", "onAuxclick", "onContextmenu"], lt = ["title"], ct = ["onClick"], ut = { class: "router-tab__slot-end" }, ft = { class: "router-tab__container" }, dt = ["aria-disabled", "onClick"];
612
+ function pt(e, n, a, t, r, u) {
613
+ const d = Ne("RouterView");
614
+ return T(), A("div", ot, [
615
+ I("header", at, [
616
+ I("div", it, [
617
+ re(e.$slots, "start")
618
+ ]),
619
+ I("div", st, [
620
+ j($e, Q({
621
+ tag: "ul",
622
+ class: "router-tab__nav"
623
+ }, e.tabTransitionProps), {
624
+ default: M(() => [
625
+ (T(!0), A(le, null, ce(e.tabs, (f) => (T(), A("li", {
626
+ key: f.id,
627
+ class: ue(e.buildTabClass(f)),
628
+ onClick: (p) => e.activate(f),
629
+ onAuxclick: B((p) => e.close(f), ["middle", "prevent"]),
630
+ onContextmenu: B((p) => e.showContextMenu(f, p), ["prevent"])
631
+ }, [
632
+ I("span", {
633
+ class: "router-tab__item-title",
634
+ title: e.tabTitle(f)
635
+ }, [
636
+ f.icon ? (T(), A("i", {
637
+ key: 0,
638
+ class: ue(["router-tab__item-icon", f.icon])
639
+ }, null, 2)) : K("", !0),
640
+ Le(" " + fe(e.tabTitle(f)), 1)
641
+ ], 8, lt),
642
+ e.isClosable(f) ? (T(), A("a", {
643
+ key: 0,
644
+ class: "router-tab__item-close",
645
+ onClick: B((p) => e.close(f), ["stop"])
646
+ }, null, 8, ct)) : K("", !0)
647
+ ], 42, rt))), 128))
648
+ ]),
649
+ _: 1
650
+ }, 16)
651
+ ]),
652
+ I("div", ut, [
653
+ re(e.$slots, "end")
654
+ ])
655
+ ]),
656
+ I("div", ft, [
657
+ j(d, null, {
658
+ default: M(({ Component: f, route: p }) => [
659
+ j(de, Q(e.pageTransitionProps, { appear: "" }), {
660
+ default: M(() => [
661
+ e.controller.options.keepAlive ? (T(), W(De, {
662
+ key: 0,
663
+ include: e.includeKeys,
664
+ max: e.controller.options.maxAlive || void 0
665
+ }, [
666
+ e.isRefreshing(p) ? K("", !0) : (T(), W(pe(f), {
667
+ key: e.controller.getRouteKey(p),
668
+ class: "router-tab-page"
669
+ }))
670
+ ], 1032, ["include", "max"])) : K("", !0)
671
+ ]),
672
+ _: 2
673
+ }, 1040),
674
+ j(de, Q(e.pageTransitionProps, { appear: "" }), {
675
+ default: M(() => [
676
+ !e.controller.options.keepAlive || e.isRefreshing(p) ? (T(), W(pe(f), {
677
+ key: e.controller.getRouteKey(p) + (e.isRefreshing(p) ? "-refresh" : ""),
678
+ class: "router-tab-page"
679
+ })) : K("", !0)
680
+ ]),
681
+ _: 2
682
+ }, 1040)
683
+ ]),
684
+ _: 1
685
+ })
686
+ ]),
687
+ e.context.visible && e.context.target ? (T(), A("div", {
688
+ key: 0,
689
+ class: "router-tab__contextmenu",
690
+ style: je({ left: e.context.position.x + "px", top: e.context.position.y + "px" })
691
+ }, [
692
+ (T(!0), A(le, null, ce(e.menuItems, (f) => (T(), A("a", {
693
+ key: f.id,
694
+ class: "router-tab__contextmenu-item",
695
+ "aria-disabled": f.disabled,
696
+ onClick: B((p) => e.handleMenuAction(f), ["prevent"])
697
+ }, fe(f.label), 9, dt))), 128))
698
+ ], 4)) : K("", !0)
699
+ ]);
700
+ }
701
+ const ke = /* @__PURE__ */ nt(tt, [["render", pt]]);
702
+ function bt(e = {}) {
703
+ const { optional: n = !1 } = e, a = z(H, null);
704
+ if (a) return a;
705
+ const t = z("$tabs", null);
706
+ if (t) return t;
707
+ const u = ae()?.appContext.config.globalProperties.$tabs;
708
+ if (u) return u;
709
+ if (!n)
710
+ throw new Error("[RouterTabs] useRouterTabs must be used within <router-tab>.");
711
+ return null;
712
+ }
713
+ const vt = "router-tabs:persistent";
714
+ function ht(e) {
715
+ return typeof window > "u" ? null : e === void 0 ? window.localStorage ?? null : e;
716
+ }
717
+ function mt(e) {
718
+ const n = ht(e.storage), a = e.storageKey ?? vt;
719
+ return Me(e.storeId ?? "routerTabs", {
720
+ state: () => ({
721
+ snapshot: null
722
+ }),
723
+ actions: {
724
+ load() {
725
+ if (!(!n || this.snapshot))
726
+ try {
727
+ const t = n.getItem(a);
728
+ t && (this.snapshot = JSON.parse(t));
729
+ } catch {
730
+ }
731
+ },
732
+ setSnapshot(t) {
733
+ if (this.snapshot = t, !!n)
734
+ try {
735
+ t && t.tabs.length ? n.setItem(a, JSON.stringify(t)) : n.removeItem(a);
736
+ } catch {
737
+ }
738
+ },
739
+ clear() {
740
+ this.setSnapshot(null);
741
+ }
742
+ }
743
+ });
744
+ }
745
+ function yt(e = {}) {
746
+ const n = bt(), t = (e.store ?? mt(e))(), r = J(!1);
747
+ return _e(async () => {
748
+ t.load();
749
+ const u = t.snapshot;
750
+ if (u)
751
+ try {
752
+ r.value = !0, await n.hydrate(u);
753
+ } finally {
754
+ r.value = !1, t.setSnapshot(n.snapshot());
755
+ }
756
+ }), x(
757
+ () => ({
758
+ tabs: n.tabs.map((u) => ({
759
+ to: u.to,
760
+ title: u.title,
761
+ tips: u.tips,
762
+ icon: u.icon,
763
+ tabClass: u.tabClass,
764
+ closable: u.closable
765
+ })),
766
+ active: n.activeId.value
767
+ }),
768
+ () => {
769
+ r.value || t.setSnapshot(n.snapshot());
770
+ },
771
+ { deep: !0 }
772
+ ), t;
773
+ }
774
+ const gt = {
775
+ class: "router-tabs-pinia",
776
+ "aria-hidden": "true"
777
+ }, Rt = /* @__PURE__ */ oe({
778
+ __name: "RouterTabsPinia",
779
+ props: {
780
+ storeId: {},
781
+ storageKey: {},
782
+ storage: {},
783
+ store: { type: [Function, Object] }
784
+ },
785
+ setup(e) {
786
+ return yt(e), (a, t) => (T(), A("span", gt));
787
+ }
788
+ }), Re = {
789
+ install(e) {
790
+ Re._installed || (Re._installed = !0, e.component(ke.name, ke), Object.defineProperty(e.config.globalProperties, "$tabs", {
791
+ configurable: !0,
792
+ enumerable: !1,
793
+ get() {
794
+ return e._context.provides[H];
795
+ },
796
+ set(n) {
797
+ n && e.provide(H, n);
798
+ }
799
+ }));
800
+ }
801
+ };
802
+ export {
803
+ ke as RouterTab,
804
+ Rt as RouterTabsPinia,
805
+ Re as default,
806
+ H as routerTabsKey,
807
+ bt as useRouterTabs,
808
+ yt as useRouterTabsPiniaPersistence
809
+ };