- Implemented useGridState to manage grid state, including asset selection and loading states. - Created useVirtualGrid to centralize virtualization helpers for improved performance. - Added createVueApp for isolated Vue 3 + Pinia application instances. - Introduced Vite configuration for building the ComfyUI-Majoor-AssetsManager with external dependencies.
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import { EVENTS } from "../../app/events.js";
|
|
import { getViewerInstance } from "../../components/Viewer.js";
|
|
|
|
function normalizeViewerMode(mode) {
|
|
const normalized = String(mode || "").trim().toLowerCase();
|
|
if (normalized === "ab" || normalized === "sidebyside") return normalized;
|
|
return "";
|
|
}
|
|
|
|
function normalizeAssets(assets, asset) {
|
|
const list = Array.isArray(assets) ? assets.filter(Boolean) : [];
|
|
if (list.length) return list;
|
|
return asset ? [asset] : [];
|
|
}
|
|
|
|
export function requestViewerOpen({ assets = [], asset = null, index = 0, mode = "" } = {}) {
|
|
const list = normalizeAssets(assets, asset);
|
|
if (!list.length) return false;
|
|
const safeIndex = Math.max(0, Math.min(Number(index) || 0, list.length - 1));
|
|
const viewerMode = normalizeViewerMode(mode);
|
|
|
|
try {
|
|
window.dispatchEvent(
|
|
new CustomEvent(EVENTS.OPEN_VIEWER, {
|
|
detail: {
|
|
assets: list,
|
|
index: safeIndex,
|
|
mode: viewerMode,
|
|
},
|
|
}),
|
|
);
|
|
return true;
|
|
} catch (e) {
|
|
console.debug?.(e);
|
|
}
|
|
|
|
try {
|
|
const viewer = getViewerInstance();
|
|
viewer.open(list, safeIndex);
|
|
if (viewerMode) viewer.setMode?.(viewerMode);
|
|
return true;
|
|
} catch (e) {
|
|
console.debug?.(e);
|
|
}
|
|
return false;
|
|
}
|