* feat(workspace): group saved negative variants in native library (#208) * fix(library): preserve full name order and batch previews (#208)
46 lines
2.4 KiB
JavaScript
46 lines
2.4 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' },
|
|
{ id: 'tags', label: 'Tags & categories', 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' },
|
|
];
|
|
|
|
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];
|
|
});
|
|
}
|
|
|
|
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);
|
|
}
|