vue3-router-tab 1.0.8 → 1.0.9

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