* build(workspace): vendor the approved concept stylesheet with a drift check * refactor(workspace): adopt the concept stylesheet as the workspace base * feat(workspace): concept sidebar with real navigation counts * feat(workspace): concept topbar with Theme and ComfyUI link * refactor(workspace): one concept heading and footer for every route * fix(workspace): keep the canvas link on the proxy mount A resolver failure no longer stops the shell from mounting: the ComfyUI link falls back to the root read from the page's own mount path (never another origin). Tests cover a non-standard /ComfyBackendDirect mount, including that no request escapes it. * test(workspace): concept fixture and shell comparison * test(workspace): concept fixture carries the concept inspector facts * fix(workspace): match the concept brand name and compare shell hover states * test(workspace): shell comparison mutation check and docs Add mutate() to the shared concept inventory and a shell mutation check: a nav-row min-height rule and a removed .breadcrumbs each make the comparison fail with the changed path. Harden the resolver-failure guard test with an injection count, make the overlay lint fail when workspace.css is missing, mark the library.css .row-actions leftovers for PR E, and document the concept CSS base, the overlay lint, the comparison method and the recorded shell deviations in TESTING.md. * fix(workspace): focus the page title on a route change A sidebar or history navigation now focuses #page-title, as the concept does on every hashchange (app.js 1168), so a screen reader announces the page heading instead of the main region. The first render leaves focus alone and the skip link still focuses main. The heading module's comment now describes what the shell does. * fix(workspace): give the Overview nav entry its own home glyph Overview reused the concept's Activity pulse byte for byte, so once the Activity row lands two entries would share one icon. Overview now has an outline home glyph. The shell comparison takes it from the D28 ruling instead of the concept's activity path, and the icon test checks that every approved glyph is distinct. * test(workspace): accept only #249 decision markers and state the lint scope The overlay lint accepted any D-number, so another issue's ruling such as "D5 (#245)" could mark a concept override. A marker now has to be a D-number with no other issue cited; the vocabulary rule that cited #245 reads "#245 decision 5". TESTING.md now states that the lint covers workspace.css only, lists the unmarked overrides still in images.css, and says PRs C and D run the lint over each page sheet they keep. * perf(workspace): re-read only Library and Tags counts after a Library write A confirmed Library or vocabulary write cannot change the Images count, but it re-read all three, including the Images output listing. It now re-reads only the Library and Tags counts. Each count has its own read, so a write never cancels an Images read that is still in flight.
94 lines
4.6 KiB
JavaScript
94 lines
4.6 KiB
JavaScript
export const routes = [
|
|
{ id: 'images', label: 'Images', href: '/prompt_manager/gallery',
|
|
description: 'Browse your images, inspect their metadata and review generated tags.', action: 'Open existing image gallery' },
|
|
{ id: 'library', label: 'Prompt library', href: '/prompt_manager/admin',
|
|
description: 'Find, edit and organize the prompts already in your library.', action: 'Open existing prompt library' },
|
|
// Native screen; `title` is the concept's breadcrumb/title, the href stays for Overview's card.
|
|
{ id: 'tags', label: 'Tags & categories', title: 'Tags', href: '/prompt_manager/admin#/tags',
|
|
description: 'Explore your vocabulary and find the prompts associated with each tag.', action: 'Open existing tag manager' },
|
|
{ id: 'inspect', label: 'Inspect a file', href: '/prompt_manager/gallery.html',
|
|
description: 'Inspect generation metadata from an image or video file.', action: 'Open existing metadata inspector' },
|
|
{ id: 'overview', label: 'Overview' },
|
|
{ id: 'system', label: 'System', href: '/prompt_manager/admin',
|
|
description: 'Open the current dashboard, then choose Settings or Maintenance for configuration, scans, backups and diagnostics.', action: 'Open existing administration' },
|
|
];
|
|
|
|
const NATIVE_ROUTES = new Set(['images', 'library', 'tags', 'overview']);
|
|
|
|
/** Breadcrumb and document title: the concept names a few pages differently from their nav label. */
|
|
export function routeTitle(route) {
|
|
return route.title || route.label;
|
|
}
|
|
|
|
/** Routes the workspace does not render yet show the generic legacy handoff panel. */
|
|
export function isHandoff(route) {
|
|
return !NATIVE_ROUTES.has(route.id);
|
|
}
|
|
|
|
export function resolveRoute(hash) {
|
|
const match = /^#\/library\/([1-9]\d*)$/.exec(hash);
|
|
if (match && Number.isSafeInteger(Number(match[1]))) {
|
|
return {...routes.find(route => route.id === 'library'), positiveId:Number(match[1]), hash};
|
|
}
|
|
return routes.find(route => hash === `#/${route.id}`) || routes[0];
|
|
}
|
|
|
|
export function summarizeStats(stats) {
|
|
return [['Prompts', 'total_prompts'], ['Images', 'total_images'], ['Tags', 'total_tags']]
|
|
.map(([label, key]) => {
|
|
const count = stats?.[key];
|
|
if (!Number.isSafeInteger(count) || count < 0) throw new Error('Invalid library statistics');
|
|
return [label, count];
|
|
});
|
|
}
|
|
|
|
// The sidebar's real counts (D27): one bounded `limit=1` read each, whose `total` is the count.
|
|
const NAV_COUNT_SOURCES = Object.freeze([
|
|
['images', '/prompt_manager/images/output?mode=workspace&limit=1'],
|
|
['library', '/prompt_manager/library?limit=1'],
|
|
['tags', '/prompt_manager/vocabulary/tags?limit=1'],
|
|
]);
|
|
|
|
/** Route id -> count for the WORKSPACE links; null when a page is missing or its total is not a count. */
|
|
export function summarizeNavCounts(pages = {}) {
|
|
return new Map(NAV_COUNT_SOURCES.map(([id]) => {
|
|
const total = pages?.[id]?.total;
|
|
return [id, Number.isSafeInteger(total) && total >= 0 ? total : null];
|
|
}));
|
|
}
|
|
|
|
/**
|
|
* Read the three counts; a failed read yields null for its route only. `onCount(id, count)` runs as each read
|
|
* settles, so a slow listing (the Images output scan) never holds back the cheap Library and Tags counts.
|
|
*/
|
|
/** The WORKSPACE routes that carry a count. */
|
|
export const NAV_COUNT_ROUTES = Object.freeze(NAV_COUNT_SOURCES.map(([id]) => id));
|
|
|
|
/** The counts a confirmed Library or vocabulary write can change; the Images listing cannot. */
|
|
export const LIBRARY_WRITE_COUNTS = Object.freeze(['library', 'tags']);
|
|
|
|
/** Read the given WORKSPACE counts (all by default), reporting each as its own read settles. */
|
|
export async function loadNavCounts(api, signal, onCount = () => {}, ids = NAV_COUNT_ROUTES) {
|
|
const pages = {};
|
|
await Promise.all(NAV_COUNT_SOURCES.filter(([id]) => ids.includes(id)).map(async ([id, url]) => {
|
|
try { pages[id] = await api.get(url, { signal }); } catch { pages[id] = undefined; }
|
|
onCount(id, summarizeNavCounts(pages).get(id));
|
|
}));
|
|
return new Map([...summarizeNavCounts(pages)].filter(([id]) => ids.includes(id)));
|
|
}
|
|
|
|
export function mountRouter(win, onRoute) {
|
|
let current;
|
|
const update = () => {
|
|
const route = resolveRoute(win.location.hash);
|
|
const hash = route.hash || `#/${route.id}`;
|
|
if (win.location.hash !== hash) win.history.replaceState(win.history.state, '', hash);
|
|
if (current?.id === route.id && current?.positiveId === route.positiveId) return;
|
|
current = route;
|
|
onRoute(route);
|
|
};
|
|
win.addEventListener('hashchange', update);
|
|
update();
|
|
return () => win.removeEventListener('hashchange', update);
|
|
}
|