Files
MajoorWaldi-ComfyUI-Majoor-…/js/features/panel/controllers/contextController.js
T
Ewald b6931d21a6 feat(grid): enhance keyboard navigation and selection handling
- Implemented functions to retrieve all assets and grid columns dynamically.
- Added keyboard navigation support for arrow keys and Home/End keys with Shift for range selection.
- Improved asset selection logic and scrolling to selected asset.
- Integrated selection state management with grid container.
- Updated rating shortcuts to be conditionally active based on hotkey state.

feat(panel): enhance Assets Manager and sidebar functionality

- Introduced summary bar disposal mechanism for better resource management.
- Added sidebar refresh logic to update active asset details.
- Improved settings change handling to selectively refresh grid and sidebar.
- Enhanced grid reload mechanism to prevent concurrent reloads.

feat(viewer): add FPS detection for video assets

- Implemented functions to parse and emit detected FPS from asset metadata.
- Attached FPS detection to video elements during metadata loading and runtime.

style(theme): update theme variables and styles

- Added new CSS variables for card hover, selection, rating, and tag colors.
- Enhanced asset card styles for selection and hover states.
- Improved badge colors for better visibility and consistency.

fix(status): improve status indicator feedback

- Added status highlight function to provide visual feedback based on status tone.
- Updated status dot and section styles to reflect current status accurately.

refactor(context): streamline context controller actions

- Added badge CSS variable application to keep UI consistent with live settings.
2026-02-09 14:49:30 +01:00

256 lines
8.3 KiB
JavaScript

import { normalizeQuery } from "./query.js";
import { APP_CONFIG } from "../../../app/config.js";
const _safeSetValue = (el, value) => {
if (!el) return;
try {
el.value = value;
} catch {}
};
const _safeSetChecked = (el, checked) => {
if (!el) return;
try {
el.checked = !!checked;
} catch {}
};
export function createContextController({
state,
gridContainer,
filterBtn,
sortBtn,
collectionsBtn,
searchInputEl,
kindSelect,
wfCheckbox,
ratingSelect,
dateRangeSelect,
dateExactInput,
scopeController,
sortController,
updateSummaryBar,
reloadGrid,
extraActions = null,
getExtraContext = null
} = {}) {
const applyBadgeCssVars = () => {
try {
const root =
gridContainer?.closest?.(".mjr-assets-manager")
|| document.querySelector?.(".mjr-assets-manager")
|| document.documentElement;
if (!root?.style?.setProperty) return;
root.style.setProperty("--mjr-star-active", String(APP_CONFIG.BADGE_STAR_COLOR || "#FFD45A"));
root.style.setProperty("--mjr-badge-image", String(APP_CONFIG.BADGE_IMAGE_COLOR || "#2196F3"));
root.style.setProperty("--mjr-badge-video", String(APP_CONFIG.BADGE_VIDEO_COLOR || "#9C27B0"));
root.style.setProperty("--mjr-badge-audio", String(APP_CONFIG.BADGE_AUDIO_COLOR || "#FF9800"));
root.style.setProperty("--mjr-badge-model3d", String(APP_CONFIG.BADGE_MODEL3D_COLOR || "#4CAF50"));
} catch {}
};
const actions = {
clearQuery: async () => {
try {
_safeSetValue(searchInputEl, "");
state.searchQuery = "";
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearCollection: async () => {
try {
state.collectionId = "";
state.collectionName = "";
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearScope: async () => {
let didSetScope = false;
try {
state.customRootId = "";
state.subfolder = "";
delete gridContainer?.dataset?.mjrSubfolder;
if (typeof scopeController?.setScope === "function") {
await scopeController.setScope("output");
didSetScope = true;
} else {
state.scope = "output";
scopeController?.setActiveTabStyles?.();
}
} catch {}
try {
if (!didSetScope) await reloadGrid?.();
} catch {}
},
clearCustomRoot: async () => {
let didSetScope = false;
try {
state.customRootId = "";
if (String(state.scope || "").toLowerCase() === "custom") {
if (typeof scopeController?.setScope === "function") {
await scopeController.setScope("output");
didSetScope = true;
} else {
state.scope = "output";
scopeController?.setActiveTabStyles?.();
}
}
} catch {}
try {
if (!didSetScope) await reloadGrid?.();
} catch {}
},
clearFolder: async () => {
try {
// Ensure state is cleared so it doesn't get restored
state.subfolder = "";
delete gridContainer?.dataset?.mjrSubfolder;
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearKind: async () => {
try {
state.kindFilter = "";
_safeSetValue(kindSelect, "");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearMinRating: async () => {
try {
state.minRating = 0;
_safeSetValue(ratingSelect, "0");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearWorkflowOnly: async () => {
try {
state.workflowOnly = false;
_safeSetChecked(wfCheckbox, false);
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearDateRange: async () => {
try {
state.dateRangeFilter = "";
_safeSetValue(dateRangeSelect, "");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearDateExact: async () => {
try {
state.dateExactFilter = "";
_safeSetValue(dateExactInput, "");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearSort: async () => {
try {
state.sort = "mtime_desc";
sortController?.setSortIcon?.(state.sort);
sortController?.renderSortMenu?.();
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearAll: async () => {
let didSetScope = false;
try {
_safeSetValue(searchInputEl, "");
} catch {}
try {
state.collectionId = "";
state.collectionName = "";
state.kindFilter = "";
state.workflowOnly = false;
state.minRating = 0;
state.dateRangeFilter = "";
state.dateExactFilter = "";
state.sort = "mtime_desc";
state.customRootId = "";
state.subfolder = "";
delete gridContainer?.dataset?.mjrSubfolder;
if (typeof scopeController?.setScope === "function") {
await scopeController.setScope("output");
didSetScope = true;
} else {
state.scope = "output";
scopeController?.setActiveTabStyles?.();
}
} catch {}
try {
_safeSetValue(kindSelect, "");
_safeSetChecked(wfCheckbox, false);
_safeSetValue(ratingSelect, "0");
_safeSetValue(dateRangeSelect, "");
_safeSetValue(dateExactInput, "");
} catch {}
try {
sortController?.setSortIcon?.(state.sort);
sortController?.renderSortMenu?.();
} catch {}
try {
if (!didSetScope) await reloadGrid?.();
} catch {}
}
};
if (extraActions && typeof extraActions === "object") {
try {
Object.assign(actions, extraActions);
} catch {}
}
const update = () => {
const rawQuery = String(searchInputEl?.value || "").trim();
const normalizedQuery = normalizeQuery(searchInputEl);
const filterActive = !!(
(state?.kindFilter || "")
|| state?.workflowOnly
|| (Number(state?.minRating || 0) || 0) > 0
|| (state?.dateRangeFilter || "")
|| (state?.dateExactFilter || "")
);
const sortActive = String(state?.sort || "mtime_desc") !== "mtime_desc";
const collectionsActive = !!(state?.collectionId || "");
try {
filterBtn?.classList?.toggle?.("mjr-context-active", filterActive);
sortBtn?.classList?.toggle?.("mjr-context-active", sortActive);
collectionsBtn?.classList?.toggle?.("mjr-context-active", collectionsActive);
} catch {}
try {
const extraContext = (typeof getExtraContext === "function" ? (getExtraContext() || {}) : {}) || {};
updateSummaryBar?.({
state,
gridContainer,
context: { rawQuery: rawQuery || normalizedQuery, ...extraContext },
actions
});
} catch {}
// Keep badge CSS vars aligned with live settings/theme changes.
applyBadgeCssVars();
};
return { update, actions };
}