* feat(inspect): local adapter seams in the shared inspector and viewer
The inspection loader calls adapter.read when an adapter reads by itself, so a
file chosen in this browser never reaches the API. The full inspector shows the
D66 local provenance (no Path row, no Show in folder, local association line),
and the viewer uses adapter.mediaUrl exactly, so a blob: URL is never given the
_pm_viewer cache-buster and Retry media reuses it. Rooted and recorded-history
adapters keep their api.get paths and cache-busted originals.
* feat(inspect): owned local selection session
createLocalSession owns one chosen File at a time: it classifies the bytes,
creates the blob: URL only for a classified image or video, and reads it
through a real inspection controller with the local adapter. Replacement,
dispose, parent abort and pagehide each release the URL, the handle and the
record once; a released handle (and every copy) is foreign to the adapter, and
every await is fenced by a generation counter so a replaced read never
publishes. Empty, multiple and directory drops keep the previous selection.
Baseline entry for local-session.mjs; branch floors raised for the touched
inspection-state.mjs and local-inspection.mjs.
* feat(inspect): native Inspect a file page
#/inspect is now the concept's "Inspect a file" page instead of the legacy
handoff. One chosen or dropped image or video previews inline, and the one
heading action, "Open file metadata", opens the shared viewer with the full
inspector on a record read entirely in this browser. Nothing is uploaded,
imported or stored; only an explicit Send crosses the host bridge.
- inspect.mjs mounts the concept DOM (surface, file-drop, #local-preview)
under the shell heading, owns one local session and the shared viewer and
prompt sender, and releases media before the session revokes its URL on
replacement, route change, page leave and dispose (D60-D65).
- A file that cannot be read after choosing opens the inspector's
unreadable state when the browser declares a supported type, instead of
the "unsupported" copy; the local adapter maps a browser read failure to
an unreadable record.
- The route is native; Overview keeps its card to the legacy metadata page,
which is unchanged.
- workspace-inspect.spec.mjs covers the chooser and viewer rail against the
Images rail for the same bytes, drop, cancel and reselect, unsupported and
unreadable files, video, URL ownership, mid-read replacement, exact send
and the no-request/no-storage rule.
* test(inspect): concept parity and managed-host send for local files
Compare the native Inspect a file page with the immutable concept's
#metadata at 1600x1100 and 390x844 in both themes (initial, selected,
viewer-open), mapping D60-D66 and pinning the concept's CSS values and
the chooser's displayed file name, with a mutation check. Send a local
PNG (explicitly empty negative) and core-tags.webm to a real Prompt
Manager (+/-) node across Classic and Nodes 2.0 switches and reloads;
a connected input rejects the send unchanged. Document D60-D66, the
legacy-floor dispositions and the commands in TESTING.md.
* fix(inspect): reset a released preview video in the next task
On WebKit (GStreamer) a video replaced while its pipeline was still
starting blocked the page: pause, src removal and load() in one task
never returned, so the next chooser selection hung (CI page workflows
webkit shard 2/2, "URLs and media end with their owning session").
The src is still dropped before the URL is revoked; only the load()
reset moves to the next task. A fresh-page regression replaces the
first video as soon as it shows, fifteen times.
* fix(inspect): never reset a preview video that is still starting
Deferring load() to the next task was not enough: CI on b7db4c3 hung
WebKit one step later in the fresh-page regression. Reset with load()
only a settled video (metadata read, or failed); a starting one is
paused, loses its src before the URL is revoked and is removed, then
left to be collected. The ownership workflow waits for the video to
settle before asserting the reset.
* fix(inspect): final review round for the local Inspect page
- Each inline preview owns its listeners, so a released node is never
pinned; a video released while still starting is reset with load()
once it reports metadata or an error (I1).
- The viewer's video teardown on a just-started local video is guarded
by a 15-page WebKit test; it needed no change (I2).
- The chooser keeps naming the current file after a cancelled picker
and names the dropped file after an accepted drop (I3).
- The unrelated activity-scan.mjs floor raise is reverted (I4).
- The page owns pagehide: the viewer closes and the inline media goes
before the session revokes the URL, and the chooser is cleared (M1,
M2); the session gains clear() and the viewer close().
- The "metadata is available" toast shows only for readable metadata
(M3); a rejected drop is a second, transient alert that never
replaces the selection's status (M4).
- TESTING.md: D62/D63 updates, the WebKit loadstart follow-up and the
pair-node follow-up (M5).
132 lines
6.8 KiB
JavaScript
132 lines
6.8 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' },
|
||
// Native screen (#249 local Inspect); the href stays for Overview's card to the legacy metadata page.
|
||
{ id: 'inspect', label: 'Inspect a file', href: '/prompt_manager/gallery.html',
|
||
description: 'A standalone file uses the same image viewer and prompt actions.', action: 'Open existing metadata inspector' },
|
||
{ id: 'overview', label: 'Overview' },
|
||
// SAVED VIEWS' first row (#249 D51): Images filtered to favorites. No href, so Overview lists no card for it.
|
||
{ id: 'favorites', label: 'Favorites' },
|
||
// The concept's Activity (app.js renderActivity 732–738): this server session's jobs. No href: no Overview card.
|
||
{ id: 'activity', label: 'Activity' },
|
||
{ 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', 'inspect', 'overview', 'saved', 'favorites', 'activity']);
|
||
|
||
/** A saved view (#249 D16): the shell resolves its id to the view's page, name and state. */
|
||
const SAVED_ROUTE = Object.freeze({ id: 'saved', label: 'Saved view' });
|
||
|
||
/** 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 saved = /^#\/saved\/([1-9]\d*)$/.exec(hash);
|
||
if (saved && Number.isSafeInteger(Number(saved[1]))) return {...SAVED_ROUTE, savedId:Number(saved[1]), hash};
|
||
// One job of the Activity page (its id is the registry's uuid4 hex).
|
||
const job = /^#\/activity\/([0-9a-f]{32})$/.exec(hash);
|
||
if (job) return {...routes.find(route => route.id === 'activity'), jobId:job[1], 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. Favorites (D51) is the
|
||
// Favorites page's own listing, so its count is what that page lists.
|
||
const NAV_COUNT_SOURCES = Object.freeze([
|
||
['images', '/prompt_manager/images/output?mode=workspace&limit=1'],
|
||
['favorites', '/prompt_manager/images/output?mode=workspace&favorites=1&limit=1'],
|
||
['library', '/prompt_manager/library?limit=1'],
|
||
['tags', '/prompt_manager/vocabulary/tags?limit=1'],
|
||
]);
|
||
|
||
/** Route id -> count for the sidebar 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 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 sidebar routes that carry a count (WORKSPACE, plus SAVED VIEWS' Favorites). */
|
||
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']);
|
||
|
||
/** The count a confirmed favorite change can change. */
|
||
export const FAVORITE_WRITE_COUNTS = Object.freeze(['favorites']);
|
||
// Trailing delay that coalesces quick star toggles into one Favorites count read (#249 M1).
|
||
export const FAVORITE_COUNT_DELAY_MS = 300;
|
||
|
||
/** Read the given sidebar 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)));
|
||
}
|
||
|
||
/** Fired on the window to render the current route again, where setting the same hash fires no `hashchange`. */
|
||
const ROUTE_REFRESH_EVENT = 'prompt-manager:route-refresh';
|
||
|
||
/** The concept's `go()` (app.js 292–297): a link to the route already shown re-renders it instead of doing nothing. */
|
||
export function navigateTo(hash, win = window) {
|
||
if (win.location.hash === hash) win.dispatchEvent(new Event(ROUTE_REFRESH_EVENT));
|
||
else win.location.hash = hash;
|
||
}
|
||
|
||
export function mountRouter(win, onRoute) {
|
||
let current;
|
||
const refresh = () => {
|
||
current = undefined;
|
||
update();
|
||
};
|
||
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 && current?.savedId === route.savedId &&
|
||
current?.jobId === route.jobId) return;
|
||
current = route;
|
||
onRoute(route);
|
||
};
|
||
win.addEventListener('hashchange', update);
|
||
win.addEventListener(ROUTE_REFRESH_EVENT, refresh);
|
||
update();
|
||
return () => {
|
||
win.removeEventListener('hashchange', update);
|
||
win.removeEventListener(ROUTE_REFRESH_EVENT, refresh);
|
||
};
|
||
}
|