admin.html loaded tags-page.js after admin.js, so opening the page at #/tags found no TagsPageManager and rendered nothing; the script order is now theme-bridge, html-escape, api-client, png-metadata, (list-state, sse-stream, data-actions), viewer, comfy-metadata, prompt-list-sort, view-router, tags-page, admin. Route resolution lives in the pure ViewRouter.resolveView(). The auto-tag modal's close buttons called a bare hideModal(), which only gallery.js defines; they call window.admin.hideModal(). PromptAdmin is constructed from startAdmin() on DOMContentLoaded (or immediately when the document is already parsed) instead of at script evaluation time.
28 lines
920 B
JavaScript
28 lines
920 B
JavaScript
/**
|
|
* Hash-route resolution for the admin page: which top-level view a
|
|
* location.hash selects. Kept pure so the #/tags deep link is testable.
|
|
*
|
|
* Loadable in the browser (window.ViewRouter) and in Node for tests.
|
|
*/
|
|
(function (root) {
|
|
"use strict";
|
|
|
|
const VIEWS = Object.freeze(["prompts", "tags"]);
|
|
const TAGS_PREFIX = "#/tags";
|
|
|
|
/**
|
|
* @param {string} hash - window.location.hash, including the leading "#"
|
|
* @returns {"prompts"|"tags"}
|
|
*/
|
|
function resolveView(hash) {
|
|
if (typeof hash !== "string") return "prompts";
|
|
if (hash === TAGS_PREFIX) return "tags";
|
|
if (hash.startsWith(TAGS_PREFIX + "/")) return "tags";
|
|
return "prompts";
|
|
}
|
|
|
|
const api = { resolveView, VIEWS };
|
|
if (typeof module !== "undefined" && module.exports) module.exports = api;
|
|
else root.ViewRouter = api;
|
|
})(typeof window !== "undefined" ? window : globalThis);
|