fix(10.1): WR-02 disable plugin stylesheets on screens that are not controller views
The router now drives stylesheet activation after every confirmed navigation: the list, create and record routes enable their controller's links, and settings, login, not-found and a controller whose schema has not arrived yet enable none. Rebuilt the embedded admin dist.
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
// {base}/assets/; they load when that controller's view opens, never
|
||||
// earlier. Every script loads once per URL as a module script, and a script
|
||||
// that fails to load is forgotten, so a later navigation can try again.
|
||||
// Stylesheet links belong to one controller: opening another controller
|
||||
// disables them, so plugin CSS never styles a view it was not written for.
|
||||
// Stylesheet links belong to one controller: the router disables them on
|
||||
// every navigation to another controller or to a screen that is not a
|
||||
// controller view, so plugin CSS never styles a view it was not written for.
|
||||
// Files load only through script and link elements; nothing here fetches.
|
||||
import type { ControllerAssets } from '../api/types'
|
||||
import { runtime } from './runtime'
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { createRouter, createWebHistory, type RouterHistory } from 'vue-router'
|
||||
import { createRouter, createWebHistory, type RouteLocationNormalized, type RouterHistory } from 'vue-router'
|
||||
import { controllerIdFromParams } from './controllerRoutes'
|
||||
import { activateStyles } from './pluginAssets'
|
||||
import { runtime } from './runtime'
|
||||
import { currentUser } from '../state/useAuth'
|
||||
import { homePath } from '../state/useNavigation'
|
||||
@@ -32,6 +34,23 @@ export function safeRedirect(value: unknown): string | null {
|
||||
return value
|
||||
}
|
||||
|
||||
const CONTROLLER_ROUTES = new Set(['list', 'create', 'record'])
|
||||
|
||||
/**
|
||||
* The controller a route shows, or '' for every other screen (settings,
|
||||
* login, not found). Plugin stylesheets follow it (D-16, T-10.1-16).
|
||||
*/
|
||||
export function routeControllerId(route: RouteLocationNormalized): string {
|
||||
if (typeof route.name !== 'string' || !CONTROLLER_ROUTES.has(route.name)) {
|
||||
return ''
|
||||
}
|
||||
const { vendor, plugin, controller } = route.params
|
||||
if (typeof vendor !== 'string' || typeof plugin !== 'string' || typeof controller !== 'string') {
|
||||
return ''
|
||||
}
|
||||
return controllerIdFromParams({ vendor, plugin, controller })
|
||||
}
|
||||
|
||||
export function createAdminRouter(history: RouterHistory = createWebHistory(runtime.base)) {
|
||||
const router = createRouter({
|
||||
history,
|
||||
@@ -66,5 +85,12 @@ export function createAdminRouter(history: RouterHistory = createWebHistory(runt
|
||||
}
|
||||
return true
|
||||
})
|
||||
// Plugin CSS is global: enable only the links of the controller on screen,
|
||||
// and none on any other screen (D-16, T-10.1-16).
|
||||
router.afterEach((to, _from, failure) => {
|
||||
if (!failure) {
|
||||
activateStyles(routeControllerId(to))
|
||||
}
|
||||
})
|
||||
return router
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user