vue3-router-tab 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +529 -47
- package/dist/vue3-router-tab.css +1 -1
- package/dist/vue3-router-tab.js +765 -659
- package/dist/vue3-router-tab.umd.cjs +1 -1
- package/lib/components/RouterTab.vue +246 -103
- package/lib/core/createRouterTabs.ts +37 -7
- package/lib/core/types.ts +5 -0
- package/lib/scss/index.scss +22 -1
- package/package.json +1 -1
|
@@ -318,6 +318,35 @@ export function createRouterTabs(
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
+
// Programmatic control: set whether a tab is kept alive
|
|
322
|
+
function setTabAlive(id: string, alive: boolean) {
|
|
323
|
+
const tab = tabs.find(t => t.id === id)
|
|
324
|
+
if (!tab) return
|
|
325
|
+
tab.alive = Boolean(alive)
|
|
326
|
+
// enforce max alive if turning alive on
|
|
327
|
+
if (tab.alive) enforceMaxAlive(tabs, options.maxAlive, activeId.value)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Evict a tab from the KeepAlive cache and increment renderKey so it mounts fresh
|
|
331
|
+
function evictCache(id: string) {
|
|
332
|
+
const tab = tabs.find(t => t.id === id)
|
|
333
|
+
if (!tab) return
|
|
334
|
+
if (tab.alive) tab.alive = false
|
|
335
|
+
// bump renderKey to ensure a fresh key when re-enabled
|
|
336
|
+
tab.renderKey = (tab.renderKey ?? 0) + 1
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Clear keep-alive for all tabs
|
|
340
|
+
function clearCache() {
|
|
341
|
+
tabs.forEach(tab => {
|
|
342
|
+
tab.alive = false
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function getCacheKeys() {
|
|
347
|
+
return includeKeys.value.slice()
|
|
348
|
+
}
|
|
349
|
+
|
|
321
350
|
async function reset(route: RouteLocationRaw = options.defaultRoute) {
|
|
322
351
|
tabs.splice(0, tabs.length)
|
|
323
352
|
activeId.value = null
|
|
@@ -368,9 +397,7 @@ export function createRouterTabs(
|
|
|
368
397
|
const tab = createTabFromRoute(route, base, options.keepAlive)
|
|
369
398
|
insertTab(tabs, tab, 'last', null)
|
|
370
399
|
} catch (error) {
|
|
371
|
-
|
|
372
|
-
console.warn('[RouterTabs] Failed to restore tab', record, error)
|
|
373
|
-
}
|
|
400
|
+
console.warn('[RouterTabs] Failed to restore tab', record, error)
|
|
374
401
|
}
|
|
375
402
|
}
|
|
376
403
|
|
|
@@ -381,9 +408,7 @@ export function createRouterTabs(
|
|
|
381
408
|
try {
|
|
382
409
|
await router.replace(target)
|
|
383
410
|
} catch (error) {
|
|
384
|
-
|
|
385
|
-
console.warn('[RouterTabs] Failed to navigate to restored route', target, error)
|
|
386
|
-
}
|
|
411
|
+
console.warn('[RouterTabs] Failed to navigate to restored route', target, error)
|
|
387
412
|
}
|
|
388
413
|
}
|
|
389
414
|
}
|
|
@@ -420,11 +445,16 @@ export function createRouterTabs(
|
|
|
420
445
|
removeTab,
|
|
421
446
|
refreshTab,
|
|
422
447
|
refreshAll,
|
|
448
|
+
setTabAlive,
|
|
449
|
+
evictCache,
|
|
450
|
+
clearCache,
|
|
451
|
+
getCacheKeys,
|
|
423
452
|
reset,
|
|
424
453
|
reload,
|
|
425
454
|
getRouteKey,
|
|
426
455
|
matchRoute,
|
|
427
456
|
snapshot,
|
|
428
|
-
hydrate
|
|
457
|
+
hydrate,
|
|
458
|
+
ensureTab
|
|
429
459
|
}
|
|
430
460
|
}
|
package/lib/core/types.ts
CHANGED
|
@@ -115,6 +115,11 @@ export interface RouterTabsContext {
|
|
|
115
115
|
matchRoute: (route: RouteLocationNormalizedLoaded | RouteLocationRaw) => RouteMatchResult
|
|
116
116
|
snapshot: () => RouterTabsSnapshot
|
|
117
117
|
hydrate: (snapshot: RouterTabsSnapshot) => Promise<void>
|
|
118
|
+
setTabAlive: (id: string, alive: boolean) => void
|
|
119
|
+
evictCache: (id: string) => void
|
|
120
|
+
clearCache: () => void
|
|
121
|
+
getCacheKeys: () => string[]
|
|
122
|
+
ensureTab: (route: RouteLocationNormalizedLoaded) => TabRecord | undefined
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
export interface RouterTabsPersistenceOptions {
|
package/lib/scss/index.scss
CHANGED
|
@@ -70,7 +70,28 @@
|
|
|
70
70
|
position: relative;
|
|
71
71
|
flex: 1 1 0px;
|
|
72
72
|
height: 100%;
|
|
73
|
-
overflow:
|
|
73
|
+
overflow-x: auto;
|
|
74
|
+
overflow-y: hidden;
|
|
75
|
+
scroll-behavior: smooth;
|
|
76
|
+
scrollbar-width: thin;
|
|
77
|
+
scrollbar-color: var(--router-tab-border) transparent;
|
|
78
|
+
|
|
79
|
+
&::-webkit-scrollbar {
|
|
80
|
+
height: 4px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&::-webkit-scrollbar-track {
|
|
84
|
+
background: transparent;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&::-webkit-scrollbar-thumb {
|
|
88
|
+
background: var(--router-tab-border);
|
|
89
|
+
border-radius: 2px;
|
|
90
|
+
|
|
91
|
+
&:hover {
|
|
92
|
+
background: color-mix(in srgb, var(--router-tab-primary) 50%, transparent);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
74
95
|
|
|
75
96
|
&-container {
|
|
76
97
|
width: 100%;
|