vue3-router-tab 1.2.5 → 1.2.7

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