vue3-router-tab 1.2.6 → 1.2.8

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,7 +1,7 @@
1
1
  import './vue3-router-tab.css';
2
- import { reactive as le, ref as K, shallowRef as qe, computed as h, watch as x, nextTick as se, inject as ge, getCurrentInstance as De, onMounted as ue, defineComponent as Be, provide as Qe, onBeforeUnmount as Xe, resolveComponent as Ze, createElementBlock as I, openBlock as w, createElementVNode as S, createCommentVNode as M, renderSlot as ne, createVNode as J, TransitionGroup as et, mergeProps as G, withCtx as W, Fragment as oe, renderList as ye, withModifiers as H, normalizeClass as he, toDisplayString as Te, normalizeProps as tt, Transition as ke, createBlock as ae, KeepAlive as nt, resolveDynamicComponent as Ce, normalizeStyle as ot } from "vue";
3
- import { RouterView as at } from "vue-router";
4
- function it(e = {}) {
2
+ import { reactive as ge, ref as $, shallowRef as bt, computed as k, watch as A, nextTick as L, inject as Ae, getCurrentInstance as Oe, onMounted as me, defineComponent as Ue, provide as pt, onBeforeUnmount as gt, resolveComponent as mt, createElementBlock as I, openBlock as P, createElementVNode as U, createCommentVNode as V, normalizeClass as J, renderSlot as ue, createVNode as q, TransitionGroup as vt, mergeProps as Q, withCtx as Z, Fragment as ce, renderList as Ee, withModifiers as fe, toDisplayString as Ke, normalizeProps as yt, Transition as Ie, createBlock as de, KeepAlive as ht, resolveDynamicComponent as xe, normalizeStyle as Tt, isRef as kt, isReadonly as wt } from "vue";
3
+ import { RouterView as Ct } from "vue-router";
4
+ function Rt(e = {}) {
5
5
  return {
6
6
  initialTabs: e.initialTabs ?? [],
7
7
  keepAlive: e.keepAlive ?? !0,
@@ -11,244 +11,261 @@ function it(e = {}) {
11
11
  defaultRoute: e.defaultRoute ?? "/"
12
12
  };
13
13
  }
14
- function _(e, n) {
14
+ function N(e, n) {
15
15
  const o = e.resolve(n);
16
16
  if (!o || !o.matched.length)
17
17
  throw new Error(`[RouterTabs] Unable to resolve route: ${String(n)}`);
18
18
  return o;
19
19
  }
20
- const rt = {
20
+ const Pt = {
21
21
  path: (e) => e.path,
22
22
  fullpath: (e) => e.fullPath,
23
23
  fullname: (e) => e.fullPath,
24
24
  full: (e) => e.fullPath,
25
25
  name: (e) => e.name ? String(e.name) : e.fullPath
26
26
  };
27
- function j(e) {
27
+ function _(e) {
28
28
  const n = e.meta?.key;
29
29
  if (typeof n == "function") {
30
30
  const o = n(e);
31
31
  if (typeof o == "string" && o.length) return o;
32
32
  } else if (typeof n == "string" && n.length) {
33
- const o = rt[n.toLowerCase()];
33
+ const o = Pt[n.toLowerCase()];
34
34
  return o ? o(e) : n;
35
35
  }
36
36
  return e.fullPath;
37
37
  }
38
- function ce(e, n) {
38
+ function ve(e, n) {
39
39
  const o = e.meta?.keepAlive;
40
40
  return typeof o == "boolean" ? o : n;
41
41
  }
42
- function fe(e, n) {
42
+ function ye(e, n) {
43
43
  const o = e.meta?.reuse;
44
44
  return typeof o == "boolean" ? o : n;
45
45
  }
46
- function $e(e) {
46
+ function Ve(e) {
47
47
  const n = e.meta ?? {}, o = {};
48
48
  return "title" in n && (o.title = n.title), "tips" in n && (o.tips = n.tips), "icon" in n && (o.icon = n.icon), "closable" in n && (o.closable = n.closable), "tabClass" in n && (o.tabClass = n.tabClass), "target" in n && (o.target = n.target), "href" in n && (o.href = n.href), o;
49
49
  }
50
- function q(e, n, o) {
51
- const i = $e(e);
50
+ function ee(e, n, o) {
51
+ const l = Ve(e);
52
52
  return {
53
- id: j(e),
53
+ id: _(e),
54
54
  to: e.fullPath,
55
55
  fullPath: e.fullPath,
56
56
  matched: e,
57
- alive: ce(e, o),
58
- reusable: fe(e, !1),
59
- closable: i.closable ?? !0,
60
- ...i,
57
+ alive: ve(e, o),
58
+ reusable: ye(e, !1),
59
+ closable: l.closable ?? !0,
60
+ renderKey: typeof n.renderKey == "number" ? n.renderKey : 0,
61
+ ...l,
61
62
  ...n
62
63
  };
63
64
  }
64
- function ie(e, n, o, i) {
65
- e.find((p) => p.id === n.id) || e.push(n);
65
+ function be(e, n, o, l) {
66
+ if (!e.find((p) => p.id === n.id)) {
67
+ if (o === "next" && l) {
68
+ const p = e.findIndex((T) => T.id === l);
69
+ if (p !== -1) {
70
+ e.splice(p + 1, 0, n);
71
+ return;
72
+ }
73
+ }
74
+ e.push(n);
75
+ }
66
76
  }
67
- function Re(e, n, o) {
77
+ function Se(e, n, o) {
68
78
  if (!n || n <= 0) return;
69
- const i = e.filter((a) => a.alive);
70
- for (; i.length > n; ) {
71
- const a = i.shift();
72
- if (!a || a.id === o) continue;
73
- const p = e.findIndex((y) => y.id === a.id);
79
+ const l = e.filter((i) => i.alive);
80
+ for (; l.length > n; ) {
81
+ const i = l.shift();
82
+ if (!i || i.id === o) continue;
83
+ const p = e.findIndex((T) => T.id === i.id);
74
84
  p > -1 && (e[p].alive = !1);
75
85
  }
76
86
  }
77
- function lt(e) {
87
+ function At(e) {
78
88
  return {
79
89
  to: e.to,
80
90
  title: e.title,
81
91
  tips: e.tips,
82
92
  icon: e.icon,
83
93
  tabClass: e.tabClass,
84
- closable: e.closable
94
+ closable: e.closable,
95
+ renderKey: e.renderKey
85
96
  };
86
97
  }
87
- function st(e) {
98
+ function Et(e) {
88
99
  const n = {};
89
- 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;
100
+ return "title" in e && (n.title = e.title), "tips" in e && (n.tips = e.tips), "icon" in e && (n.icon = e.icon), "tabClass" in e && (n.tabClass = e.tabClass), "closable" in e && (n.closable = e.closable), "renderKey" in e && typeof e.renderKey == "number" && (n.renderKey = e.renderKey), n;
90
101
  }
91
- function ut(e, n = {}) {
92
- const o = it(n), i = le([]), a = K(null), p = qe(), y = K(null), s = h(() => i.filter((l) => l.alive).map((l) => l.id));
93
- let u = !1;
94
- function m(l) {
95
- const f = typeof l.matched == "object" ? l : _(e, l);
102
+ function Kt(e, n = {}) {
103
+ const o = Rt(n), l = ge([]), i = $(null), p = bt(), T = $(null), s = k(
104
+ () => l.filter((r) => r.alive).map((r) => `${r.id}::${r.renderKey}`)
105
+ );
106
+ let c = !1;
107
+ function g(r) {
108
+ const d = typeof r.matched == "object" ? r : N(e, r);
96
109
  return {
97
- key: j(f),
98
- fullPath: f.fullPath,
99
- alive: ce(f, o.keepAlive),
100
- reusable: fe(f, !1),
101
- matched: f
110
+ key: _(d),
111
+ fullPath: d.fullPath,
112
+ alive: ve(d, o.keepAlive),
113
+ reusable: ye(d, !1),
114
+ matched: d
102
115
  };
103
116
  }
104
- function k(l) {
105
- const f = j(l);
106
- let d = i.find((v) => v.id === f);
107
- return d ? (d.fullPath = l.fullPath, d.to = l.fullPath, d.matched = l, d.alive = ce(l, o.keepAlive), d.reusable = fe(l, d.reusable), Object.assign(d, $e(l)), d) : (d = q(l, {}, o.keepAlive), ie(i, d, o.appendPosition, a.value), Re(i, o.maxAlive, a.value), d);
117
+ function R(r) {
118
+ const d = _(r);
119
+ let b = l.find((h) => h.id === d);
120
+ return b ? (b.fullPath = r.fullPath, b.to = r.fullPath, b.matched = r, b.alive = ve(r, o.keepAlive), b.reusable = ye(r, b.reusable), Object.assign(b, Ve(r)), b) : (b = ee(r, {}, o.keepAlive), be(l, b, o.appendPosition, i.value), Se(l, o.maxAlive, i.value), b);
108
121
  }
109
- async function B(l, f = !1, d = !0) {
110
- const v = _(e, l), P = j(v), D = a.value === P;
111
- d === "sameTab" && (d = D), d && await L(P, !0), await e[f ? "replace" : "push"](v), D && await N();
122
+ async function S(r, d = !1, b = !0) {
123
+ const h = N(e, r), w = _(h), E = i.value === w;
124
+ b === "sameTab" && (b = E), b && await j(w, !0), await e[d ? "replace" : "push"](h), E && await y();
112
125
  }
113
- function O(l) {
114
- const f = i.findIndex(($) => $.id === l);
115
- if (f === -1) return o.defaultRoute;
116
- const d = i[f + 1], v = i[f - 1], P = i.find(($) => $.id !== l), D = d || v || P;
117
- return D ? D.to : o.defaultRoute;
126
+ function B(r) {
127
+ const d = l.findIndex((x) => x.id === r);
128
+ if (d === -1) return o.defaultRoute;
129
+ const b = l[d + 1], h = l[d - 1], w = l.find((x) => x.id !== r), E = b || h || w;
130
+ return E ? E.to : o.defaultRoute;
118
131
  }
119
- async function A(l = a.value, f = {}) {
120
- if (!l) return;
121
- if (!f.force && o.keepLastTab && i.length === 1)
132
+ async function z(r = i.value, d = {}) {
133
+ if (!r) return;
134
+ if (!d.force && o.keepLastTab && l.length === 1)
122
135
  throw new Error("[RouterTabs] Unable to close the final tab when keepLastTab is true.");
123
- const v = a.value === l && f.redirect !== null, P = v ? f.redirect ?? O(l) : null;
124
- await z(l, { force: f.force }), f.redirect !== null && v && P && await e.replace(P);
136
+ const h = i.value === r && d.redirect !== null, w = h ? d.redirect ?? B(r) : null;
137
+ await Y(r, { force: d.force }), d.redirect !== null && h && w && await e.replace(w);
125
138
  }
126
- async function z(l, f = {}) {
127
- const d = i.findIndex((v) => v.id === l);
128
- d !== -1 && (i.splice(d, 1), y.value === l && (y.value = null), a.value === l && (a.value = null, p.value = void 0));
139
+ async function Y(r, d = {}) {
140
+ const b = l.findIndex((h) => h.id === r);
141
+ b !== -1 && (l.splice(b, 1), T.value === r && (T.value = null), i.value === r && (i.value = null, p.value = void 0));
129
142
  }
130
- async function L(l = a.value ?? void 0, f = !1) {
131
- l && (y.value = l, await se(), f || await se(), y.value = null);
143
+ async function j(r = i.value ?? void 0, d = !1) {
144
+ if (!r) return;
145
+ const b = l.find((w) => w.id === r);
146
+ if (!b) return;
147
+ const h = o.keepAlive && b.alive;
148
+ h && (b.alive = !1, await L()), b.renderKey = (b.renderKey ?? 0) + 1, h && (b.alive = !0, await L()), T.value = r, await L(), d || await L(), T.value = null;
132
149
  }
133
- async function R(l = !1) {
134
- for (const f of i)
135
- await L(f.id, l);
150
+ async function ae(r = !1) {
151
+ for (const d of l)
152
+ await j(d.id, r);
136
153
  }
137
- async function g(l = o.defaultRoute) {
138
- i.splice(0, i.length), a.value = null, p.value = void 0;
139
- for (const f of o.initialTabs) {
140
- const d = _(e, f.to), v = q(d, f, o.keepAlive);
141
- i.push(v);
154
+ async function ie(r = o.defaultRoute) {
155
+ l.splice(0, l.length), i.value = null, p.value = void 0;
156
+ for (const d of o.initialTabs) {
157
+ const b = N(e, d.to), h = ee(b, d, o.keepAlive);
158
+ l.push(h);
142
159
  }
143
- await e.replace(l);
160
+ await e.replace(r);
144
161
  }
145
- async function N() {
146
- const l = a.value;
147
- l && await L(l, !0);
162
+ async function y() {
163
+ const r = i.value;
164
+ r && await j(r, !0);
148
165
  }
149
- function U(l) {
150
- return typeof l.matched == "object" ? j(l) : j(_(e, l));
166
+ function G(r) {
167
+ return typeof r.matched == "object" ? _(r) : _(N(e, r));
151
168
  }
152
- function Y() {
153
- const l = i.find((f) => f.id === a.value);
169
+ function M() {
170
+ const r = l.find((d) => d.id === i.value);
154
171
  return {
155
- tabs: i.map(lt),
156
- active: l ? l.to : null
172
+ tabs: l.map(At),
173
+ active: r ? r.to : null
157
174
  };
158
175
  }
159
- async function F(l) {
160
- u = !0, i.splice(0, i.length), a.value = null, p.value = void 0;
161
- const f = l?.tabs ?? [];
162
- for (const v of f)
176
+ async function D(r) {
177
+ c = !0, l.splice(0, l.length), i.value = null, p.value = void 0;
178
+ const d = r?.tabs ?? [];
179
+ for (const h of d)
163
180
  try {
164
- const P = _(e, v.to), D = st(v), $ = q(P, D, o.keepAlive);
165
- ie(i, $, "last", null);
181
+ const w = N(e, h.to), E = Et(h), x = ee(w, E, o.keepAlive);
182
+ be(l, x, "last", null);
166
183
  } catch {
167
184
  }
168
- u = !1;
169
- const d = l?.active ?? f[f.length - 1]?.to ?? o.defaultRoute;
170
- if (d)
185
+ c = !1;
186
+ const b = r?.active ?? d[d.length - 1]?.to ?? o.defaultRoute;
187
+ if (b)
171
188
  try {
172
- await e.replace(d);
189
+ await e.replace(b);
173
190
  } catch {
174
191
  }
175
192
  }
176
- return x(
193
+ return A(
177
194
  () => e.currentRoute.value,
178
- (l) => {
179
- if (u) return;
180
- const f = k(l);
181
- a.value = f.id, p.value = f, Re(i, o.maxAlive, a.value);
195
+ (r) => {
196
+ if (c) return;
197
+ const d = R(r);
198
+ i.value = d.id, p.value = d, Se(l, o.maxAlive, i.value);
182
199
  },
183
200
  { immediate: !0 }
184
- ), o.initialTabs.length && o.initialTabs.forEach((l) => {
185
- const f = _(e, l.to), d = q(f, l, o.keepAlive);
186
- ie(i, d);
201
+ ), o.initialTabs.length && o.initialTabs.forEach((r) => {
202
+ const d = N(e, r.to), b = ee(d, r, o.keepAlive);
203
+ be(l, b, "last", null);
187
204
  }), {
188
205
  options: o,
189
- tabs: i,
190
- activeId: a,
206
+ tabs: l,
207
+ activeId: i,
191
208
  current: p,
192
209
  includeKeys: s,
193
- refreshingKey: y,
194
- openTab: B,
195
- closeTab: A,
196
- removeTab: z,
197
- refreshTab: L,
198
- refreshAll: R,
199
- reset: g,
200
- reload: N,
201
- getRouteKey: U,
202
- matchRoute: m,
203
- snapshot: Y,
204
- hydrate: F
210
+ refreshingKey: T,
211
+ openTab: S,
212
+ closeTab: z,
213
+ removeTab: Y,
214
+ refreshTab: j,
215
+ refreshAll: ae,
216
+ reset: ie,
217
+ reload: y,
218
+ getRouteKey: G,
219
+ matchRoute: g,
220
+ snapshot: M,
221
+ hydrate: D
205
222
  };
206
223
  }
207
- function we(e) {
224
+ function De(e) {
208
225
  return e ? typeof e == "string" ? { name: e } : e : {};
209
226
  }
210
- const X = Symbol("RouterTabsContext"), Q = "router-tabs:snapshot";
211
- function Pe(e = {}) {
212
- const { optional: n = !1 } = e, o = ge(X, null);
227
+ const oe = Symbol("RouterTabsContext"), ne = "router-tabs:snapshot";
228
+ function $e(e = {}) {
229
+ const { optional: n = !1 } = e, o = Ae(oe, null);
213
230
  if (o) return o;
214
- const i = ge("$tabs", null);
215
- if (i) return i;
216
- const p = De()?.appContext.config.globalProperties.$tabs;
231
+ const l = Ae("$tabs", null);
232
+ if (l) return l;
233
+ const p = Oe()?.appContext.config.globalProperties.$tabs;
217
234
  if (p) return p;
218
235
  if (!n)
219
236
  throw new Error("[RouterTabs] useRouterTabs must be used within <router-tab>.");
220
237
  return null;
221
238
  }
222
- const ct = 864e5;
223
- function ft(e) {
239
+ const It = 864e5;
240
+ function xt(e) {
224
241
  if (typeof document > "u") return null;
225
242
  const n = `${encodeURIComponent(e)}=`, o = document.cookie ? document.cookie.split("; ") : [];
226
- for (const i of o)
227
- if (i.startsWith(n))
228
- return decodeURIComponent(i.slice(n.length));
243
+ for (const l of o)
244
+ if (l.startsWith(n))
245
+ return decodeURIComponent(l.slice(n.length));
229
246
  return null;
230
247
  }
231
- function Ae(e, n, o) {
248
+ function Be(e, n, o) {
232
249
  if (typeof document > "u") return;
233
250
  const {
234
- expiresInDays: i = 7,
235
- path: a = "/",
251
+ expiresInDays: l = 7,
252
+ path: i = "/",
236
253
  domain: p,
237
- secure: y,
254
+ secure: T,
238
255
  sameSite: s = "lax"
239
- } = o, u = [`${encodeURIComponent(e)}=${encodeURIComponent(n)}`];
240
- if (i !== 1 / 0) {
241
- const m = new Date(Date.now() + i * ct).toUTCString();
242
- u.push(`Expires=${m}`);
256
+ } = o, c = [`${encodeURIComponent(e)}=${encodeURIComponent(n)}`];
257
+ if (l !== 1 / 0) {
258
+ const g = new Date(Date.now() + l * It).toUTCString();
259
+ c.push(`Expires=${g}`);
243
260
  }
244
- a && u.push(`Path=${a}`), p && u.push(`Domain=${p}`), y && u.push("Secure"), s && u.push(`SameSite=${s.charAt(0).toUpperCase()}${s.slice(1)}`), document.cookie = u.join("; ");
261
+ i && c.push(`Path=${i}`), p && c.push(`Domain=${p}`), T && c.push("Secure"), s && c.push(`SameSite=${s.charAt(0).toUpperCase()}${s.slice(1)}`), document.cookie = c.join("; ");
245
262
  }
246
- function Ee(e, n) {
263
+ function Me(e, n) {
247
264
  if (typeof document > "u") return;
248
- const { path: o = "/", domain: i } = n, a = [`${encodeURIComponent(e)}=`];
249
- a.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"), o && a.push(`Path=${o}`), i && a.push(`Domain=${i}`), document.cookie = a.join("; ");
265
+ const { path: o = "/", domain: l } = n, i = [`${encodeURIComponent(e)}=`];
266
+ i.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"), o && i.push(`Path=${o}`), l && i.push(`Domain=${l}`), document.cookie = i.join("; ");
250
267
  }
251
- const dt = (e) => JSON.stringify(e ?? null), bt = (e) => {
268
+ const St = (e) => JSON.stringify(e ?? null), Dt = (e) => {
252
269
  if (!e) return null;
253
270
  try {
254
271
  return JSON.parse(e);
@@ -256,62 +273,65 @@ const dt = (e) => JSON.stringify(e ?? null), bt = (e) => {
256
273
  return null;
257
274
  }
258
275
  };
259
- function Ke(e = {}) {
276
+ function Ne(e = {}) {
260
277
  const {
261
- cookieKey: n = Q,
262
- serialize: o = dt,
263
- deserialize: i = bt
264
- } = e, a = Pe({ optional: !0 }), p = K(!0), y = (s) => {
265
- ue(async () => {
266
- const u = i(ft(n));
267
- if (u && u.tabs?.length)
278
+ cookieKey: n = ne,
279
+ serialize: o = St,
280
+ deserialize: l = Dt
281
+ } = e, i = $e({ optional: !0 }), p = $(!0), T = (s) => {
282
+ me(async () => {
283
+ const c = l(xt(n));
284
+ if (c && c.tabs?.length)
268
285
  try {
269
- if (p.value = !0, await s.hydrate(u), u.active) {
270
- await se();
271
- const k = s.tabs.find((B) => B.to === u.active);
272
- k && (s.activeId.value = k.id, s.current.value = k);
286
+ if (p.value = !0, await s.hydrate(c), c.active) {
287
+ await L();
288
+ const R = s.tabs.find((S) => S.to === c.active);
289
+ R && (s.activeId.value = R.id, s.current.value = R);
273
290
  }
274
291
  } finally {
275
292
  p.value = !1;
276
293
  }
277
- else
294
+ else if (Object.prototype.hasOwnProperty.call(e, "fallbackRoute"))
278
295
  try {
279
296
  p.value = !0;
280
- const k = e.fallbackRoute ?? s.options.defaultRoute;
281
- await s.reset(k);
297
+ const R = e.fallbackRoute ?? s.options.defaultRoute;
298
+ await s.reset(R);
282
299
  } finally {
283
300
  p.value = !1;
284
301
  }
285
- const m = s.snapshot();
286
- m.tabs.length ? Ae(n, o(m), e) : Ee(n, e), p.value = !1;
287
- }), x(
302
+ else
303
+ p.value = !1;
304
+ const g = s.snapshot();
305
+ g.tabs.length ? Be(n, o(g), e) : Me(n, e), p.value = !1;
306
+ }), A(
288
307
  () => ({
289
- tabs: s.tabs.map((u) => ({
290
- to: u.to,
291
- title: u.title,
292
- tips: u.tips,
293
- icon: u.icon,
294
- tabClass: u.tabClass,
295
- closable: u.closable
308
+ tabs: s.tabs.map((c) => ({
309
+ to: c.to,
310
+ title: c.title,
311
+ tips: c.tips,
312
+ icon: c.icon,
313
+ tabClass: c.tabClass,
314
+ closable: c.closable,
315
+ renderKey: c.renderKey
296
316
  })),
297
317
  active: s.activeId.value
298
318
  }),
299
319
  () => {
300
320
  if (p.value) return;
301
- const u = s.snapshot();
302
- u.tabs.length ? Ae(n, o(u), e) : Ee(n, e);
321
+ const c = s.snapshot();
322
+ c.tabs.length ? Be(n, o(c), e) : Me(n, e);
303
323
  },
304
324
  { deep: !0 }
305
325
  );
306
326
  };
307
- a ? y(a) : ue(() => {
308
- const s = Pe({ optional: !0 });
309
- s && y(s);
327
+ i ? T(i) : me(() => {
328
+ const s = $e({ optional: !0 });
329
+ s && T(s);
310
330
  });
311
331
  }
312
- const pt = Be({
332
+ const $t = Ue({
313
333
  name: "RouterTab",
314
- components: { RouterView: at },
334
+ components: { RouterView: Ct },
315
335
  props: {
316
336
  tabs: {
317
337
  type: Array,
@@ -351,7 +371,7 @@ const pt = Be({
351
371
  },
352
372
  cookieKey: {
353
373
  type: String,
354
- default: Q
374
+ default: ne
355
375
  },
356
376
  persistence: {
357
377
  type: Object,
@@ -364,13 +384,13 @@ const pt = Be({
364
384
  },
365
385
  emits: ["tab-sort", "tab-sorted"],
366
386
  setup(e, { emit: n }) {
367
- const o = De();
387
+ const o = Oe();
368
388
  if (!o)
369
389
  throw new Error("[RouterTab] component must be used within a Vue application context.");
370
- const i = o.appContext.app.config.globalProperties.$router;
371
- if (!i)
390
+ const l = o.appContext.app.config.globalProperties.$router;
391
+ if (!l)
372
392
  throw new Error("[RouterTab] Vue Router is required. Make sure to call app.use(router) before RouterTab.");
373
- const a = ut(i, {
393
+ const i = Kt(l, {
374
394
  initialTabs: e.tabs,
375
395
  keepAlive: e.keepAlive,
376
396
  maxAlive: e.maxAlive,
@@ -378,105 +398,105 @@ const pt = Be({
378
398
  appendPosition: e.append,
379
399
  defaultRoute: e.defaultPage
380
400
  });
381
- Qe(X, a), o.appContext.config.globalProperties.$tabs = a;
382
- const p = h(() => !!o?.slots?.default), y = K(0), s = h(() => {
383
- y.value;
401
+ pt(oe, i), o.appContext.config.globalProperties.$tabs = i;
402
+ const p = k(() => !!o?.slots?.default), T = k(() => !!o?.slots?.start), s = k(() => !!o?.slots?.end), c = $(0), g = k(() => {
403
+ c.value;
384
404
  const t = {};
385
- return a.tabs.forEach((r) => {
386
- const b = typeof r.title == "string" ? r.title : String(r.title || Z(r));
387
- t[r.id] = b;
405
+ return i.tabs.forEach((a) => {
406
+ const f = typeof a.title == "string" ? a.title : String(a.title || re(a));
407
+ t[a.id] = f;
388
408
  }), t;
389
409
  });
390
- function u() {
391
- y.value++;
392
- }
393
- const m = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map();
394
- function B(t, r) {
395
- if (!r || m.has(t)) return;
396
- m.set(t, r);
397
- const b = a.tabs.find((E) => a.getRouteKey(E.to) === t);
398
- if (!b) return;
399
- const T = [];
400
- if (r.routeTabTitle !== void 0) {
401
- const E = x(
410
+ function R() {
411
+ c.value++;
412
+ }
413
+ const S = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map();
414
+ function z(t, a) {
415
+ if (!a || S.has(t)) return;
416
+ S.set(t, a);
417
+ const f = i.tabs.find((v) => i.getRouteKey(v.to) === t);
418
+ if (!f) return;
419
+ const m = [];
420
+ if (a.routeTabTitle !== void 0) {
421
+ const v = A(
402
422
  () => {
403
- const c = r.routeTabTitle;
404
- return c && typeof c == "object" && "value" in c ? c.value : c;
423
+ const u = a.routeTabTitle;
424
+ return u && typeof u == "object" && "value" in u ? u.value : u;
405
425
  },
406
- (c) => {
407
- if (c != null) {
408
- const me = String(c);
409
- b.title = me, u();
426
+ (u) => {
427
+ if (u != null) {
428
+ const O = String(u);
429
+ f.title = O, R();
410
430
  }
411
431
  },
412
432
  { immediate: !0 }
413
433
  );
414
- T.push(E);
434
+ m.push(v);
415
435
  }
416
- if (r.routeTabIcon !== void 0) {
417
- const E = x(
436
+ if (a.routeTabIcon !== void 0) {
437
+ const v = A(
418
438
  () => {
419
- const c = r.routeTabIcon;
420
- return c && typeof c == "object" && "value" in c ? c.value : c;
439
+ const u = a.routeTabIcon;
440
+ return u && typeof u == "object" && "value" in u ? u.value : u;
421
441
  },
422
- (c) => {
423
- c != null && (b.icon = String(c), u());
442
+ (u) => {
443
+ u != null && (f.icon = String(u), R());
424
444
  },
425
445
  { immediate: !0 }
426
446
  );
427
- T.push(E);
447
+ m.push(v);
428
448
  }
429
- if (r.routeTabClosable !== void 0) {
430
- const E = x(
449
+ if (a.routeTabClosable !== void 0) {
450
+ const v = A(
431
451
  () => {
432
- const c = r.routeTabClosable;
433
- return c && typeof c == "object" && "value" in c ? c.value : c;
452
+ const u = a.routeTabClosable;
453
+ return u && typeof u == "object" && "value" in u ? u.value : u;
434
454
  },
435
- (c) => {
436
- c != null && (b.closable = !!c, u());
455
+ (u) => {
456
+ u != null && (f.closable = !!u, R());
437
457
  },
438
458
  { immediate: !0 }
439
459
  );
440
- T.push(E);
460
+ m.push(v);
441
461
  }
442
- if (r.routeTabMeta !== void 0) {
443
- const E = x(
462
+ if (a.routeTabMeta !== void 0) {
463
+ const v = A(
444
464
  () => {
445
- const c = r.routeTabMeta;
446
- return c && typeof c == "object" && "value" in c ? c.value : c;
465
+ const u = a.routeTabMeta;
466
+ return u && typeof u == "object" && "value" in u ? u.value : u;
447
467
  },
448
- (c) => {
449
- c && typeof c == "object" && (Object.assign(b, c), u());
468
+ (u) => {
469
+ u && typeof u == "object" && (Object.assign(f, u), R());
450
470
  },
451
471
  { immediate: !0, deep: !0 }
452
472
  );
453
- T.push(E);
473
+ m.push(v);
454
474
  }
455
- k.set(t, T);
475
+ B.set(t, m);
456
476
  }
457
- function O(t) {
458
- const r = k.get(t);
459
- r && (r.forEach((b) => b()), k.delete(t)), m.delete(t);
477
+ function Y(t) {
478
+ const a = B.get(t);
479
+ a && (a.forEach((f) => f()), B.delete(t)), S.delete(t);
460
480
  }
461
- function A(t, r) {
462
- t ? t.routeTabTitle !== void 0 || t.routeTabIcon !== void 0 || t.routeTabClosable !== void 0 ? B(r, t) : t.$ && (t.$.routeTabTitle !== void 0 || t.$.routeTabIcon !== void 0 || t.$.routeTabClosable !== void 0) && B(r, t.$) : t === null && O(r);
481
+ function j(t, a) {
482
+ t ? t.routeTabTitle !== void 0 || t.routeTabIcon !== void 0 || t.routeTabClosable !== void 0 ? z(a, t) : t.$ && (t.$.routeTabTitle !== void 0 || t.$.routeTabIcon !== void 0 || t.$.routeTabClosable !== void 0) && z(a, t.$) : t === null && Y(a);
463
483
  }
464
484
  if (e.cookieKey !== null || e.persistence) {
465
485
  const t = {
466
486
  ...e.persistence ?? {}
467
487
  };
468
- e.cookieKey !== null ? t.cookieKey = e.cookieKey || Q : t.cookieKey || (t.cookieKey = Q), Ke(t);
488
+ e.cookieKey !== null ? t.cookieKey = e.cookieKey || ne : t.cookieKey || (t.cookieKey = ne), Ne(t);
469
489
  }
470
- const z = h(() => we(e.tabTransition)), L = h(() => we(e.pageTransition)), R = le({
490
+ const ae = k(() => De(e.tabTransition)), ie = k(() => De(e.pageTransition)), y = ge({
471
491
  visible: !1,
472
492
  target: null,
473
493
  position: { x: 0, y: 0 }
474
- }), g = le({
494
+ }), G = $(null), M = $([]), D = $(-1), r = ge({
475
495
  dragging: !1,
476
496
  dragIndex: -1,
477
497
  dropIndex: -1,
478
498
  dragTab: null
479
- }), N = [
499
+ }), d = [
480
500
  "refresh",
481
501
  "refreshAll",
482
502
  "close",
@@ -484,302 +504,416 @@ const pt = Be({
484
504
  "closeRights",
485
505
  "closeOthers"
486
506
  ];
487
- function U(t) {
488
- return a.tabs.findIndex((r) => r.id === t);
507
+ function b(t) {
508
+ return i.tabs.findIndex((a) => a.id === t);
489
509
  }
490
- function Y(t) {
491
- const r = U(t.id);
492
- return r > 0 ? a.tabs.slice(0, r) : [];
493
- }
494
- function F(t) {
495
- const r = U(t.id);
496
- return r > -1 ? a.tabs.slice(r + 1) : [];
497
- }
498
- function l(t) {
499
- return a.tabs.filter((r) => r.id !== t.id);
500
- }
501
- async function f(t, r) {
502
- const b = t.filter((T) => T.closable !== !1);
503
- if (b.length) {
504
- for (const T of b)
505
- a.activeId.value === T.id ? await a.closeTab(T.id, { redirect: r.to, force: !0 }) : await a.removeTab(T.id, { force: !0 });
506
- a.activeId.value !== r.id && await a.openTab(r.to, !0, !1);
510
+ function h(t) {
511
+ const a = b(t.id);
512
+ return a > 0 ? i.tabs.slice(0, a) : [];
513
+ }
514
+ function w(t) {
515
+ const a = b(t.id);
516
+ return a > -1 ? i.tabs.slice(a + 1) : [];
517
+ }
518
+ function E(t) {
519
+ return i.tabs.filter((a) => a.id !== t.id);
520
+ }
521
+ async function x(t, a) {
522
+ const f = t.filter((m) => m.closable !== !1);
523
+ if (f.length) {
524
+ for (const m of f)
525
+ i.activeId.value === m.id ? await i.closeTab(m.id, { redirect: a.to, force: !0 }) : await i.removeTab(m.id, { force: !0 });
526
+ i.activeId.value !== a.id && await i.openTab(a.to, !0, !1);
507
527
  }
508
528
  }
509
- const d = {
529
+ const He = {
510
530
  refresh: {
511
531
  label: "Refresh",
512
532
  handler: async ({ target: t }) => {
513
- await a.refreshTab(t.id, !0);
533
+ await i.refreshTab(t.id, !0);
514
534
  }
515
535
  },
516
536
  refreshAll: {
517
537
  label: "Refresh All",
518
538
  handler: async () => {
519
- await a.refreshAll(!0);
539
+ await i.refreshAll(!0);
520
540
  }
521
541
  },
522
542
  close: {
523
543
  label: "Close",
524
544
  handler: async ({ target: t }) => {
525
- await a.closeTab(t.id);
545
+ await i.closeTab(t.id);
526
546
  },
527
- enable: ({ target: t }) => ee(t)
547
+ enable: ({ target: t }) => le(t)
528
548
  },
529
549
  closeLefts: {
530
550
  label: "Close to the Left",
531
551
  handler: async ({ target: t }) => {
532
- await f(Y(t), t);
552
+ await x(h(t), t);
533
553
  },
534
- enable: ({ target: t }) => Y(t).some((r) => r.closable !== !1)
554
+ enable: ({ target: t }) => h(t).some((a) => a.closable !== !1)
535
555
  },
536
556
  closeRights: {
537
557
  label: "Close to the Right",
538
558
  handler: async ({ target: t }) => {
539
- await f(F(t), t);
559
+ await x(w(t), t);
540
560
  },
541
- enable: ({ target: t }) => F(t).some((r) => r.closable !== !1)
561
+ enable: ({ target: t }) => w(t).some((a) => a.closable !== !1)
542
562
  },
543
563
  closeOthers: {
544
564
  label: "Close Others",
545
565
  handler: async ({ target: t }) => {
546
- await f(l(t), t);
566
+ await x(E(t), t);
547
567
  },
548
- enable: ({ target: t }) => l(t).some((r) => r.closable !== !1)
568
+ enable: ({ target: t }) => E(t).some((a) => a.closable !== !1)
549
569
  }
550
570
  };
551
- function v() {
552
- R.visible = !1, R.target = null;
553
- }
554
- function P(t, r) {
555
- e.contextmenu && (R.visible = !0, R.target = t, R.position.x = r.clientX, R.position.y = r.clientY, document.addEventListener("click", v, { once: !0 }));
556
- }
557
- function D(t, r) {
558
- const b = typeof t == "string" ? { id: t } : t, T = d[b.id], E = b.label ?? T?.label ?? String(b.id), c = b.visible ?? T?.visible ?? !0;
559
- if (!(typeof c == "function" ? c(r) : c !== !1)) return null;
560
- const te = b.enable ?? T?.enable ?? !0, We = typeof te == "function" ? te(r) : te !== !1, ve = b.handler ?? T?.handler;
561
- if (!ve) return null;
562
- const He = async () => {
563
- await Promise.resolve(ve(r));
571
+ function K() {
572
+ y.visible = !1, y.target = null, D.value = -1, M.value = [];
573
+ }
574
+ function Je(t, a) {
575
+ e.contextmenu && (y.visible = !0, y.target = t, y.position.x = a.clientX, y.position.y = a.clientY, document.addEventListener("click", K, { once: !0 }), L(() => {
576
+ Ge();
577
+ }));
578
+ }
579
+ function We(t, a) {
580
+ const f = typeof t == "string" ? { id: t } : t, m = He[f.id], v = f.label ?? m?.label ?? String(f.id), u = f.visible ?? m?.visible ?? !0;
581
+ if (!(typeof u == "function" ? u(a) : u !== !1)) return null;
582
+ const se = f.enable ?? m?.enable ?? !0, ft = typeof se == "function" ? se(a) : se !== !1, Pe = f.handler ?? m?.handler;
583
+ if (!Pe) return null;
584
+ const dt = async () => {
585
+ await Promise.resolve(Pe(a));
564
586
  };
565
587
  return {
566
- id: String(b.id),
567
- label: E,
568
- disabled: !We,
569
- action: He
588
+ id: String(f.id),
589
+ label: v,
590
+ disabled: !ft,
591
+ action: dt
570
592
  };
571
593
  }
572
- const $ = h(() => {
573
- if (!R.visible || !R.target || e.contextmenu === !1) return [];
574
- const t = Array.isArray(e.contextmenu) ? e.contextmenu : N, r = { target: R.target, controller: a };
575
- return t.map((b) => D(b, r)).filter((b) => !!b);
594
+ const F = k(() => {
595
+ if (!y.visible || !y.target || e.contextmenu === !1) return [];
596
+ const t = Array.isArray(e.contextmenu) ? e.contextmenu : d, a = { target: y.target, controller: i };
597
+ return t.map((f) => We(f, a)).filter((f) => !!f);
576
598
  });
577
- async function Me(t) {
578
- t.disabled || (v(), await t.action());
599
+ function Ge() {
600
+ const t = G.value;
601
+ if (!t) return;
602
+ const a = 8, { innerWidth: f, innerHeight: m } = window, v = t.getBoundingClientRect();
603
+ let u = y.position.x, O = y.position.y;
604
+ v.right > f - a && (u = Math.max(a, f - v.width - a)), v.bottom > m - a && (O = Math.max(a, m - v.height - a)), (u !== y.position.x || O !== y.position.y) && (y.position.x = u, y.position.y = O);
605
+ }
606
+ function Xe(t, a) {
607
+ M.value[a] = t ?? null;
608
+ }
609
+ function qe(t) {
610
+ if (t < 0) return;
611
+ M.value[t]?.focus({ preventScroll: !0 });
612
+ }
613
+ function X(t, a, f = F.value) {
614
+ if (!f.length) return -1;
615
+ const m = f.length;
616
+ let v = t;
617
+ for (let u = 0; u < m; u++)
618
+ if (v = (v + a + m) % m, !f[v].disabled) return v;
619
+ return -1;
620
+ }
621
+ function H(t) {
622
+ D.value = t, !(t < 0) && L(() => qe(t));
623
+ }
624
+ function ke(t) {
625
+ const a = X(D.value, t);
626
+ a !== -1 && H(a);
627
+ }
628
+ function Qe(t) {
629
+ if (!y.visible) return;
630
+ const a = t.key, f = F.value;
631
+ if (!f.length) return;
632
+ if (a === "Tab") {
633
+ K();
634
+ return;
635
+ }
636
+ if ([
637
+ "ArrowDown",
638
+ "ArrowUp",
639
+ "ArrowRight",
640
+ "ArrowLeft",
641
+ "Home",
642
+ "End",
643
+ "Enter",
644
+ " ",
645
+ "Spacebar",
646
+ "Escape"
647
+ ].includes(a))
648
+ switch (t.preventDefault(), a) {
649
+ case "ArrowDown":
650
+ case "ArrowRight":
651
+ ke(1);
652
+ break;
653
+ case "ArrowUp":
654
+ case "ArrowLeft":
655
+ ke(-1);
656
+ break;
657
+ case "Home":
658
+ H(X(-1, 1));
659
+ break;
660
+ case "End":
661
+ H(X(f.length, -1));
662
+ break;
663
+ case "Enter":
664
+ case " ":
665
+ case "Spacebar": {
666
+ const v = D.value;
667
+ if (v > -1) {
668
+ const u = f[v];
669
+ u.disabled || we(u);
670
+ }
671
+ break;
672
+ }
673
+ case "Escape":
674
+ K();
675
+ break;
676
+ }
677
+ }
678
+ async function we(t) {
679
+ t.disabled || (K(), await t.action());
579
680
  }
580
- function Z(t) {
681
+ function re(t) {
581
682
  return typeof t.title == "string" && t.title.trim() ? t.title : Array.isArray(t.title) && t.title.length && String(t.title[0]).trim() ? String(t.title[0]) : "Untitled";
582
683
  }
583
- function _e(t) {
584
- return s.value[t.id] || Z(t);
684
+ function Ze(t) {
685
+ return g.value[t.id] || re(t);
585
686
  }
586
- function ee(t) {
587
- return !(t.closable === !1 || a.options.keepLastTab && a.tabs.length <= 1);
687
+ function Ce(t) {
688
+ const a = i.getRouteKey(t), m = i.tabs.find((v) => v.id === a)?.renderKey ?? 0;
689
+ return `${a}::${m}`;
588
690
  }
589
- async function je(t) {
590
- await a.closeTab(t.id);
691
+ function et(t) {
692
+ return `${Ce(t)}::refresh`;
591
693
  }
592
- function Oe(t) {
593
- a.activeId.value !== t.id && a.openTab(t.to, !1);
694
+ function le(t) {
695
+ return !(t.closable === !1 || i.options.keepLastTab && i.tabs.length <= 1);
594
696
  }
595
- function Ue(t) {
697
+ async function tt(t) {
698
+ await i.closeTab(t.id);
699
+ }
700
+ function nt(t) {
701
+ if (t.href && typeof window < "u") {
702
+ t.target && t.target !== "_self" ? window.open(t.href, t.target) : window.location.assign(t.href);
703
+ return;
704
+ }
705
+ i.activeId.value !== t.id && i.openTab(t.to, !1);
706
+ }
707
+ function ot(t) {
596
708
  return [
597
709
  "router-tab__item",
598
710
  {
599
- "is-active": a.activeId.value === t.id,
600
- "is-closable": ee(t),
601
- "is-dragging": g.dragging && g.dragTab?.id === t.id,
602
- "is-drag-over": g.dropIndex === U(t.id)
711
+ "is-active": i.activeId.value === t.id,
712
+ "is-closable": le(t),
713
+ "is-dragging": r.dragging && r.dragTab?.id === t.id,
714
+ "is-drag-over": r.dropIndex === b(t.id)
603
715
  },
604
716
  t.tabClass
605
717
  ];
606
718
  }
607
- function Ve(t) {
608
- return a.refreshingKey.value === a.getRouteKey(t);
719
+ function at(t) {
720
+ return i.refreshingKey.value === i.getRouteKey(t);
609
721
  }
610
- function ze(t, r, b) {
611
- e.sortable && (g.dragging = !0, g.dragIndex = r, g.dragTab = t, b.dataTransfer && (b.dataTransfer.effectAllowed = "move", b.dataTransfer.setData("text/plain", t.id)), n("tab-sort", { tab: t, index: r }));
722
+ function it(t, a, f) {
723
+ e.sortable && (r.dragging = !0, r.dragIndex = a, r.dragTab = t, f.dataTransfer && (f.dataTransfer.effectAllowed = "move", f.dataTransfer.setData("text/plain", t.id)), n("tab-sort", { tab: t, index: a }));
612
724
  }
613
- function Ne(t, r) {
614
- !e.sortable || !g.dragging || (r.preventDefault(), r.dataTransfer && (r.dataTransfer.dropEffect = "move"));
725
+ function rt(t, a) {
726
+ !e.sortable || !r.dragging || (a.preventDefault(), a.dataTransfer && (a.dataTransfer.dropEffect = "move"));
615
727
  }
616
- function Ye(t) {
617
- !e.sortable || !g.dragging || (g.dropIndex = t);
728
+ function lt(t) {
729
+ !e.sortable || !r.dragging || (r.dropIndex = t);
618
730
  }
619
- function Fe() {
620
- !e.sortable || g.dragging;
731
+ function st() {
732
+ !e.sortable || r.dragging;
621
733
  }
622
- function Je(t, r) {
623
- if (!(!e.sortable || !g.dragging)) {
624
- if (r.preventDefault(), g.dragIndex !== -1 && g.dragIndex !== t) {
625
- const b = a.tabs.splice(g.dragIndex, 1)[0];
626
- a.tabs.splice(t, 0, b), n("tab-sorted", {
627
- tab: b,
628
- fromIndex: g.dragIndex,
734
+ function ut(t, a) {
735
+ if (!(!e.sortable || !r.dragging)) {
736
+ if (a.preventDefault(), r.dragIndex !== -1 && r.dragIndex !== t) {
737
+ const f = i.tabs.splice(r.dragIndex, 1)[0];
738
+ i.tabs.splice(t, 0, f), n("tab-sorted", {
739
+ tab: f,
740
+ fromIndex: r.dragIndex,
629
741
  toIndex: t
630
742
  });
631
743
  }
632
- pe();
744
+ Re();
633
745
  }
634
746
  }
635
- function pe() {
636
- g.dragging = !1, g.dragIndex = -1, g.dropIndex = -1, g.dragTab = null;
747
+ function Re() {
748
+ r.dragging = !1, r.dragIndex = -1, r.dropIndex = -1, r.dragTab = null;
637
749
  }
638
- ue(() => {
639
- document.addEventListener("keydown", v);
640
- }), Xe(() => {
641
- document.removeEventListener("keydown", v), o.appContext.config.globalProperties.$tabs = null, k.forEach((t) => {
642
- t.forEach((r) => r());
643
- }), k.clear(), m.clear();
644
- }), x(
750
+ me(() => {
751
+ document.addEventListener("keydown", K);
752
+ }), gt(() => {
753
+ document.removeEventListener("keydown", K), o.appContext.config.globalProperties.$tabs = null, B.forEach((t) => {
754
+ t.forEach((a) => a());
755
+ }), B.clear(), S.clear();
756
+ }), A(
645
757
  () => e.keepAlive,
646
758
  (t) => {
647
- a.options.keepAlive = t;
759
+ i.options.keepAlive = t;
648
760
  }
649
- ), x(
650
- () => a.activeId.value,
651
- () => v()
652
- ), x(
761
+ ), A(
762
+ () => i.activeId.value,
763
+ () => K()
764
+ ), A(
653
765
  () => e.contextmenu,
654
766
  (t) => {
655
- t || v();
767
+ t || K();
656
768
  }
657
- ), x(
658
- () => $.value.length,
769
+ ), A(
770
+ () => F.value.length,
659
771
  (t) => {
660
- R.visible && t === 0 && v();
772
+ y.visible && t === 0 && K();
773
+ }
774
+ ), A(F, (t) => {
775
+ if (M.value = new Array(t.length).fill(null), !y.visible) return;
776
+ const a = X(-1, 1, t);
777
+ H(a);
778
+ }), A(
779
+ () => y.visible,
780
+ (t) => {
781
+ t || (D.value = -1, M.value = []);
661
782
  }
662
783
  );
663
- const Ge = a.includeKeys;
784
+ const ct = i.includeKeys;
664
785
  return {
665
- controller: a,
666
- tabs: a.tabs,
667
- includeKeys: Ge,
668
- tabTransitionProps: z,
669
- pageTransitionProps: L,
670
- buildTabClass: Ue,
671
- activate: Oe,
672
- close: je,
673
- context: R,
674
- menuItems: $,
675
- handleMenuAction: Me,
676
- showContextMenu: P,
677
- hideContextMenu: v,
678
- getTabTitle: Z,
679
- isClosable: ee,
680
- isRefreshing: Ve,
786
+ controller: i,
787
+ tabs: i.tabs,
788
+ includeKeys: ct,
789
+ tabTransitionProps: ae,
790
+ pageTransitionProps: ie,
791
+ buildTabClass: ot,
792
+ activate: nt,
793
+ close: tt,
794
+ context: y,
795
+ menuItems: F,
796
+ handleMenuAction: we,
797
+ showContextMenu: Je,
798
+ hideContextMenu: K,
799
+ getTabTitle: re,
800
+ isClosable: le,
801
+ isRefreshing: at,
681
802
  hasCustomSlot: p,
682
- onDragStart: ze,
683
- onDragOver: Ne,
684
- onDragEnter: Ye,
685
- onDragLeave: Fe,
686
- onDrop: Je,
687
- onDragEnd: pe,
688
- setupComponentWatching: B,
689
- cleanupComponentWatching: O,
690
- handleComponentRef: A,
691
- getReactiveTabTitle: _e,
692
- triggerTabUpdate: u
803
+ hasStartSlot: T,
804
+ hasEndSlot: s,
805
+ onDragStart: it,
806
+ onDragOver: rt,
807
+ onDragEnter: lt,
808
+ onDragLeave: st,
809
+ onDrop: ut,
810
+ onDragEnd: Re,
811
+ setupComponentWatching: z,
812
+ cleanupComponentWatching: Y,
813
+ handleComponentRef: j,
814
+ getReactiveTabTitle: Ze,
815
+ getComponentCacheKey: Ce,
816
+ getRefreshComponentKey: et,
817
+ triggerTabUpdate: R,
818
+ menuRef: G,
819
+ highlightedIndex: D,
820
+ setMenuItemRef: Xe,
821
+ onMenuKeydown: Qe,
822
+ highlightMenuIndex: H
693
823
  };
694
824
  }
695
- }), mt = (e, n) => {
825
+ }), Bt = (e, n) => {
696
826
  const o = e.__vccOpts || e;
697
- for (const [i, a] of n)
698
- o[i] = a;
827
+ for (const [l, i] of n)
828
+ o[l] = i;
699
829
  return o;
700
- }, vt = { class: "router-tab" }, gt = { class: "router-tab__header" }, yt = { class: "router-tab__slot-start" }, ht = { class: "router-tab__scroll" }, Tt = ["data-title", "draggable", "onClick", "onAuxclick", "onContextmenu", "onDragstart", "onDragover", "onDragenter", "onDrop"], kt = ["title"], Ct = ["onClick"], Rt = { class: "router-tab__slot-end" }, wt = { class: "router-tab__container" }, Pt = ["aria-disabled", "onClick"];
701
- function At(e, n, o, i, a, p) {
702
- const y = Ze("RouterView");
703
- return w(), I("div", vt, [
704
- S("header", gt, [
705
- S("div", yt, [
706
- ne(e.$slots, "start")
707
- ]),
708
- S("div", ht, [
709
- J(et, G({
830
+ }, Mt = { class: "router-tab" }, Lt = { class: "router-tab__header" }, jt = { class: "router-tab__scroll" }, Ot = ["data-title", "draggable", "onClick", "onAuxclick", "onContextmenu", "onDragstart", "onDragover", "onDragenter", "onDrop"], Ut = ["title"], Vt = ["onClick"], Nt = { class: "router-tab__container" }, _t = ["aria-disabled", "disabled", "tabindex", "onMouseenter", "onClick"];
831
+ function zt(e, n, o, l, i, p) {
832
+ const T = mt("RouterView");
833
+ return P(), I("div", Mt, [
834
+ U("header", Lt, [
835
+ U("div", {
836
+ class: J(["router-tab__slot-start", { "has-content": e.hasStartSlot }])
837
+ }, [
838
+ ue(e.$slots, "start")
839
+ ], 2),
840
+ U("div", jt, [
841
+ q(vt, Q({
710
842
  tag: "ul",
711
843
  class: "router-tab__nav"
712
844
  }, e.tabTransitionProps), {
713
- default: W(() => [
714
- (w(!0), I(oe, null, ye(e.tabs, (s, u) => (w(), I("li", {
845
+ default: Z(() => [
846
+ (P(!0), I(ce, null, Ee(e.tabs, (s, c) => (P(), I("li", {
715
847
  key: s.id,
716
- class: he(e.buildTabClass(s)),
848
+ class: J(e.buildTabClass(s)),
717
849
  "data-title": e.getTabTitle(s),
718
850
  draggable: e.sortable,
719
- onClick: (m) => e.activate(s),
720
- onAuxclick: H((m) => e.close(s), ["middle", "prevent"]),
721
- onContextmenu: H((m) => e.showContextMenu(s, m), ["prevent"]),
722
- onDragstart: (m) => e.onDragStart(s, u, m),
723
- onDragover: (m) => e.onDragOver(u, m),
724
- onDragenter: (m) => e.onDragEnter(u),
725
- onDragleave: n[0] || (n[0] = (...m) => e.onDragLeave && e.onDragLeave(...m)),
726
- onDrop: (m) => e.onDrop(u, m),
727
- onDragend: n[1] || (n[1] = (...m) => e.onDragEnd && e.onDragEnd(...m))
851
+ onClick: (g) => e.activate(s),
852
+ onAuxclick: fe((g) => e.close(s), ["middle", "prevent"]),
853
+ onContextmenu: fe((g) => e.showContextMenu(s, g), ["prevent"]),
854
+ onDragstart: (g) => e.onDragStart(s, c, g),
855
+ onDragover: (g) => e.onDragOver(c, g),
856
+ onDragenter: (g) => e.onDragEnter(c),
857
+ onDragleave: n[0] || (n[0] = (...g) => e.onDragLeave && e.onDragLeave(...g)),
858
+ onDrop: (g) => e.onDrop(c, g),
859
+ onDragend: n[1] || (n[1] = (...g) => e.onDragEnd && e.onDragEnd(...g))
728
860
  }, [
729
- s.icon ? (w(), I("i", {
861
+ s.icon ? (P(), I("i", {
730
862
  key: 0,
731
- class: he(["router-tab__item-icon", s.icon])
732
- }, null, 2)) : M("", !0),
733
- S("span", {
863
+ class: J(["router-tab__item-icon", s.icon])
864
+ }, null, 2)) : V("", !0),
865
+ U("span", {
734
866
  class: "router-tab__item-title",
735
867
  title: e.getReactiveTabTitle(s)
736
- }, Te(e.getReactiveTabTitle(s)), 9, kt),
737
- e.isClosable(s) ? (w(), I("a", {
868
+ }, Ke(e.getReactiveTabTitle(s)), 9, Ut),
869
+ e.isClosable(s) ? (P(), I("a", {
738
870
  key: 1,
739
871
  class: "router-tab__item-close",
740
- onClick: H((m) => e.close(s), ["stop"])
741
- }, null, 8, Ct)) : M("", !0)
742
- ], 42, Tt))), 128))
872
+ onClick: fe((g) => e.close(s), ["stop"])
873
+ }, null, 8, Vt)) : V("", !0)
874
+ ], 42, Ot))), 128))
743
875
  ]),
744
876
  _: 1
745
877
  }, 16)
746
878
  ]),
747
- S("div", Rt, [
748
- ne(e.$slots, "end")
749
- ])
879
+ U("div", {
880
+ class: J(["router-tab__slot-end", { "has-content": e.hasEndSlot }])
881
+ }, [
882
+ ue(e.$slots, "end")
883
+ ], 2)
750
884
  ]),
751
- S("div", wt, [
752
- J(y, null, {
753
- default: W((s) => [
754
- e.hasCustomSlot ? ne(e.$slots, "default", tt(G({ key: 0 }, {
885
+ U("div", Nt, [
886
+ q(T, null, {
887
+ default: Z((s) => [
888
+ e.hasCustomSlot ? ue(e.$slots, "default", yt(Q({ key: 0 }, {
755
889
  ...s,
756
890
  controller: e.controller,
757
891
  // Expose a ref binder so custom slots can keep reactivity
758
- pageRef: (u) => e.handleComponentRef(u, e.controller.getRouteKey(s.route))
759
- }))) : (w(), I(oe, { key: 1 }, [
760
- J(ke, G(e.pageTransitionProps, { appear: "" }), {
761
- default: W(() => [
762
- e.controller.options.keepAlive ? (w(), ae(nt, {
892
+ pageRef: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route))
893
+ }))) : (P(), I(ce, { key: 1 }, [
894
+ q(Ie, Q(e.pageTransitionProps, { appear: "" }), {
895
+ default: Z(() => [
896
+ e.controller.options.keepAlive ? (P(), de(ht, {
763
897
  key: 0,
764
898
  include: e.includeKeys,
765
899
  max: e.controller.options.maxAlive || void 0
766
900
  }, [
767
- e.isRefreshing(s.route) ? M("", !0) : (w(), ae(Ce(s.Component), {
768
- key: e.controller.getRouteKey(s.route),
769
- ref: (u) => e.handleComponentRef(u, e.controller.getRouteKey(s.route)),
901
+ e.isRefreshing(s.route) ? V("", !0) : (P(), de(xe(s.Component), {
902
+ key: e.getComponentCacheKey(s.route),
903
+ ref: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route)),
770
904
  class: "router-tab-page"
771
905
  }))
772
- ], 1032, ["include", "max"])) : M("", !0)
906
+ ], 1032, ["include", "max"])) : V("", !0)
773
907
  ]),
774
908
  _: 2
775
909
  }, 1040),
776
- J(ke, G(e.pageTransitionProps, { appear: "" }), {
777
- default: W(() => [
778
- !e.controller.options.keepAlive || e.isRefreshing(s.route) ? (w(), ae(Ce(s.Component), {
779
- key: e.controller.getRouteKey(s.route) + (e.isRefreshing(s.route) ? "-refresh" : ""),
780
- ref: (u) => e.handleComponentRef(u, e.controller.getRouteKey(s.route)),
910
+ q(Ie, Q(e.pageTransitionProps, { appear: "" }), {
911
+ default: Z(() => [
912
+ !e.controller.options.keepAlive || e.isRefreshing(s.route) ? (P(), de(xe(s.Component), {
913
+ key: e.getRefreshComponentKey(s.route),
914
+ ref: (c) => e.handleComponentRef(c, e.controller.getRouteKey(s.route)),
781
915
  class: "router-tab-page"
782
- })) : M("", !0)
916
+ })) : V("", !0)
783
917
  ]),
784
918
  _: 2
785
919
  }, 1040)
@@ -788,24 +922,33 @@ function At(e, n, o, i, a, p) {
788
922
  _: 3
789
923
  })
790
924
  ]),
791
- e.context.visible && e.context.target ? (w(), I("div", {
925
+ e.context.visible && e.context.target ? (P(), I("div", {
792
926
  key: 0,
927
+ ref: "menuRef",
793
928
  class: "router-tab__contextmenu",
794
- style: ot({ left: e.context.position.x + "px", top: e.context.position.y + "px" })
929
+ role: "menu",
930
+ onKeydown: n[2] || (n[2] = (...s) => e.onMenuKeydown && e.onMenuKeydown(...s)),
931
+ style: Tt({ left: e.context.position.x + "px", top: e.context.position.y + "px" })
795
932
  }, [
796
- (w(!0), I(oe, null, ye(e.menuItems, (s) => (w(), I("a", {
933
+ (P(!0), I(ce, null, Ee(e.menuItems, (s, c) => (P(), I("a", {
797
934
  key: s.id,
798
- class: "router-tab__contextmenu-item",
935
+ role: "menuitem",
936
+ class: J(["router-tab__contextmenu-item", { "is-focused": c === e.highlightedIndex }]),
799
937
  "aria-disabled": s.disabled,
800
- onClick: H((u) => e.handleMenuAction(s), ["prevent"])
801
- }, Te(s.label), 9, Pt))), 128))
802
- ], 4)) : M("", !0)
938
+ disabled: s.disabled,
939
+ tabindex: s.disabled ? -1 : c === e.highlightedIndex ? 0 : -1,
940
+ ref_for: !0,
941
+ ref: (g) => e.setMenuItemRef(g, c),
942
+ onMouseenter: (g) => !s.disabled && e.highlightMenuIndex(c),
943
+ onClick: (g) => e.handleMenuAction(s)
944
+ }, Ke(s.label), 43, _t))), 128))
945
+ ], 36)) : V("", !0)
803
946
  ]);
804
947
  }
805
- const Ie = /* @__PURE__ */ mt(pt, [["render", At]]), Et = {
948
+ const Le = /* @__PURE__ */ Bt($t, [["render", zt]]), Yt = {
806
949
  class: "router-tabs",
807
950
  "aria-hidden": "true"
808
- }, re = /* @__PURE__ */ Be({
951
+ }, pe = /* @__PURE__ */ Ue({
809
952
  name: "RouterTabs",
810
953
  __name: "RouterTabs",
811
954
  props: {
@@ -820,10 +963,10 @@ const Ie = /* @__PURE__ */ mt(pt, [["render", At]]), Et = {
820
963
  fallbackRoute: {}
821
964
  },
822
965
  setup(e) {
823
- return Ke(e), (o, i) => (w(), I("span", Et));
966
+ return Ne(e), (o, l) => (P(), I("span", Yt));
824
967
  }
825
- }), Le = "tab-theme-style", It = "tab-theme-primary-color", xt = "system", Dt = "(prefers-color-scheme: dark)";
826
- let V = null;
968
+ }), _e = "tab-theme-style", ze = "tab-theme-primary-color", Ft = "system", Ye = "(prefers-color-scheme: dark)";
969
+ let W = null;
827
970
  const C = {
828
971
  primary: "#034960",
829
972
  background: "#ffffff",
@@ -838,7 +981,7 @@ const C = {
838
981
  activeButtonBackground: "#034960",
839
982
  activeButtonColor: "#ffffff",
840
983
  iconColor: "#475569"
841
- }, Bt = {
984
+ }, Ht = {
842
985
  primary: "#38bdf8",
843
986
  background: "#0f172a",
844
987
  text: "#f1f5f9",
@@ -854,110 +997,155 @@ const C = {
854
997
  activeButtonColor: "#0f172a",
855
998
  iconColor: "#cbd5e1"
856
999
  };
857
- function de(e) {
1000
+ function Jt(e) {
1001
+ if (typeof window > "u") return null;
1002
+ const n = window.localStorage.getItem(e);
1003
+ if (!n) return null;
1004
+ try {
1005
+ const o = JSON.parse(n);
1006
+ return o && typeof o == "object" ? o : null;
1007
+ } catch {
1008
+ return null;
1009
+ }
1010
+ }
1011
+ function he(e) {
858
1012
  typeof document > "u" || (document.documentElement.style.setProperty("--router-tab-primary", e.primary ?? C.primary), document.documentElement.style.setProperty("--router-tab-header-bg", e.headerBackground ?? C.headerBackground), document.documentElement.style.setProperty("--router-tab-background", e.background ?? C.background), document.documentElement.style.setProperty("--router-tab-active-background", e.activeBackground ?? C.activeBackground), document.documentElement.style.setProperty("--router-tab-text", e.text ?? C.text), document.documentElement.style.setProperty("--router-tab-active-text", e.activeText ?? C.activeText), document.documentElement.style.setProperty("--router-tab-border", e.border ?? C.border), document.documentElement.style.setProperty("--router-tab-active-border", e.activeBorder ?? C.activeBorder), document.documentElement.style.setProperty("--router-tab-button-color", e.buttonColor ?? C.buttonColor), document.documentElement.style.setProperty("--router-tab-active-button-color", e.activeButtonColor ?? C.activeButtonColor), document.documentElement.style.setProperty("--router-tab-button-background", e.buttonBackground ?? C.buttonBackground), document.documentElement.style.setProperty("--router-tab-active-button-background", e.activeButtonBackground ?? C.activeButtonBackground), document.documentElement.style.setProperty("--router-tab-icon-color", e.iconColor ?? C.iconColor));
859
1013
  }
860
- function Se(e) {
1014
+ function Fe(e) {
861
1015
  if (typeof document > "u") return;
862
- const n = document.documentElement, o = window.matchMedia(Dt), i = () => {
1016
+ const n = document.documentElement, o = window.matchMedia(Ye), l = () => {
863
1017
  n.dataset.theme = o.matches ? "dark" : "light";
864
1018
  };
865
- V && (o.removeEventListener("change", V), V = null), e === "system" ? (i(), V = () => i(), o.addEventListener("change", V)) : n.dataset.theme = e;
1019
+ W && (o.removeEventListener("change", W), W = null), e === "system" ? (l(), W = () => l(), o.addEventListener("change", W)) : n.dataset.theme = e;
866
1020
  }
867
- function $t(e = {}) {
1021
+ function Wt(e = {}) {
868
1022
  if (typeof window > "u") return;
869
1023
  const {
870
- styleKey: n = Le,
871
- defaultStyle: o = xt
872
- } = e, i = window.localStorage.getItem(n) ?? o;
873
- Se(i), de(i === "dark" ? Bt : C);
1024
+ styleKey: n = _e,
1025
+ primaryKey: o = ze,
1026
+ defaultStyle: l = Ft,
1027
+ defaultPrimary: i
1028
+ } = e, p = window.localStorage.getItem(n) ?? l;
1029
+ Fe(p);
1030
+ const s = p === "dark" || p === "system" && window.matchMedia(Ye).matches ? { ...Ht } : { ...C };
1031
+ i && (s.primary = i);
1032
+ const c = Jt(o);
1033
+ he(c ? {
1034
+ ...s,
1035
+ ...c
1036
+ } : s);
874
1037
  }
875
- function St(e, n) {
1038
+ function qt(e, n) {
876
1039
  if (typeof window > "u") return;
877
- const o = n?.styleKey ?? Le;
878
- window.localStorage.setItem(o, e), Se(e);
1040
+ const o = n?.styleKey ?? _e;
1041
+ window.localStorage.setItem(o, e), Fe(e);
879
1042
  }
880
- function Mt(e, n) {
1043
+ function Qt(e, n) {
881
1044
  if (typeof window > "u") return;
882
- const o = n?.primaryKey ?? It;
883
- window.localStorage.setItem(o, JSON.stringify(e)), de(e);
1045
+ const o = n?.primaryKey ?? ze;
1046
+ window.localStorage.setItem(o, JSON.stringify(e)), he(e);
884
1047
  }
885
- function be(e = {}) {
886
- const n = K(e.title || "Untitled"), o = K(e.icon || "mdi-tab"), i = K(e.closable !== !1), a = K(e.meta || {}), p = typeof e.title == "function" ? h(e.title) : n, y = typeof e.icon == "function" ? h(e.icon) : o, s = typeof e.closable == "function" ? h(e.closable) : i, u = typeof e.meta == "function" ? h(e.meta) : a;
1048
+ function te(e, n) {
1049
+ if (kt(e)) {
1050
+ const l = !wt(e);
1051
+ return {
1052
+ value: e,
1053
+ update: l ? (i) => {
1054
+ e.value = i;
1055
+ } : () => {
1056
+ }
1057
+ };
1058
+ }
1059
+ if (typeof e == "function")
1060
+ return {
1061
+ value: k(e),
1062
+ update: () => {
1063
+ }
1064
+ };
1065
+ const o = $(
1066
+ e === void 0 ? n : e
1067
+ );
887
1068
  return {
888
- routeTabTitle: p,
889
- routeTabIcon: y,
890
- routeTabClosable: s,
891
- routeTabMeta: u,
892
- updateTitle: (A) => {
893
- "value" in n && (n.value = A);
894
- },
895
- updateIcon: (A) => {
896
- "value" in o && (o.value = A);
897
- },
898
- updateClosable: (A) => {
899
- "value" in i && (i.value = A);
900
- },
901
- updateMeta: (A) => {
902
- "value" in a && (a.value = A);
1069
+ value: o,
1070
+ update: (l) => {
1071
+ o.value = l;
903
1072
  }
904
1073
  };
905
1074
  }
906
- function _t(e, n = "Page") {
907
- return be({
908
- title: h(() => e.value ? "Loading..." : n),
909
- icon: h(() => e.value ? "mdi-loading mdi-spin" : "mdi-page"),
910
- closable: h(() => !e.value)
1075
+ function Te(e = {}) {
1076
+ const n = te(e.title, "Untitled"), o = te(e.icon, ""), l = te(e.closable, !0), i = te(e.meta, {});
1077
+ return {
1078
+ routeTabTitle: n.value,
1079
+ routeTabIcon: o.value,
1080
+ routeTabClosable: l.value,
1081
+ routeTabMeta: i.value,
1082
+ updateTitle: n.update,
1083
+ updateIcon: o.update,
1084
+ updateClosable: l.update,
1085
+ updateMeta: i.update
1086
+ };
1087
+ }
1088
+ function Zt(e, n = "Page") {
1089
+ return Te({
1090
+ title: k(() => e.value ? "Loading..." : n),
1091
+ icon: k(() => e.value ? "mdi-loading mdi-spin" : "mdi-page"),
1092
+ closable: k(() => !e.value)
911
1093
  });
912
1094
  }
913
- function jt(e, n = "Page", o = "mdi-page") {
914
- return be({
915
- title: h(() => e.value > 0 ? `${n} (${e.value})` : n),
916
- icon: h(() => e.value > 0 ? "mdi-bell-badge" : o)
1095
+ function en(e, n = "Page", o = "mdi-page") {
1096
+ return Te({
1097
+ title: k(() => e.value > 0 ? `${n} (${e.value})` : n),
1098
+ icon: k(() => e.value > 0 ? "mdi-bell-badge" : o)
917
1099
  });
918
1100
  }
919
- function Ot(e, n = "Page") {
1101
+ function tn(e, n = "Page") {
920
1102
  const o = {
921
1103
  normal: { suffix: "", icon: "mdi-page" },
922
1104
  loading: { suffix: " - Loading", icon: "mdi-loading mdi-spin" },
923
1105
  error: { suffix: " - Error", icon: "mdi-alert" },
924
1106
  success: { suffix: " - Success", icon: "mdi-check-circle" }
925
1107
  };
926
- return be({
927
- title: h(() => n + o[e.value].suffix),
928
- icon: h(() => o[e.value].icon),
929
- closable: h(() => e.value !== "loading")
1108
+ return Te({
1109
+ title: k(() => n + o[e.value].suffix),
1110
+ icon: k(() => o[e.value].icon),
1111
+ closable: k(() => e.value !== "loading")
930
1112
  });
931
1113
  }
932
- const xe = {
933
- install(e) {
934
- if (xe._installed) return;
935
- xe._installed = !0, $t();
936
- const n = Ie.name || "RouterTab", o = re.name || "RouterTabs";
937
- e.component(n, Ie), e.component(o, re), o !== "router-tabs" && e.component("router-tabs", re), Object.defineProperty(e.config.globalProperties, "$tabs", {
1114
+ let je = !1;
1115
+ const nn = {
1116
+ install(e, n) {
1117
+ if (je) return;
1118
+ je = !0;
1119
+ const {
1120
+ initTheme: o = !0,
1121
+ themeOptions: l,
1122
+ componentName: i = Le.name || "RouterTab",
1123
+ tabsComponentName: p = pe.name || "RouterTabs"
1124
+ } = n ?? {};
1125
+ o && Wt(l ?? {}), e.component(i, Le), e.component(p, pe), p.toLowerCase() !== "router-tabs" && e.component("router-tabs", pe), Object.defineProperty(e.config.globalProperties, "$tabs", {
938
1126
  configurable: !0,
939
1127
  enumerable: !1,
940
1128
  get() {
941
- return e._context.provides[X];
1129
+ return e._context.provides[oe];
942
1130
  },
943
- set(i) {
944
- i && e.provide(X, i);
1131
+ set(T) {
1132
+ T && e.provide(oe, T);
945
1133
  }
946
1134
  });
947
1135
  }
948
1136
  };
949
1137
  export {
950
- Ie as RouterTab,
951
- re as RouterTabs,
952
- xe as default,
953
- $t as initRouterTabsTheme,
954
- X as routerTabsKey,
955
- Mt as setRouterTabsPrimary,
956
- St as setRouterTabsTheme,
957
- _t as useLoadingTab,
958
- jt as useNotificationTab,
959
- be as useReactiveTab,
960
- Pe as useRouterTabs,
961
- Ke as useRouterTabsPersistence,
962
- Ot as useStatusTab
1138
+ Le as RouterTab,
1139
+ pe as RouterTabs,
1140
+ nn as default,
1141
+ Wt as initRouterTabsTheme,
1142
+ oe as routerTabsKey,
1143
+ Qt as setRouterTabsPrimary,
1144
+ qt as setRouterTabsTheme,
1145
+ Zt as useLoadingTab,
1146
+ en as useNotificationTab,
1147
+ Te as useReactiveTab,
1148
+ $e as useRouterTabs,
1149
+ Ne as useRouterTabsPersistence,
1150
+ tn as useStatusTab
963
1151
  };