- 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.
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
function unwrapCandidate(maybeInput) {
|
|
let current = maybeInput;
|
|
for (let i = 0; i < 3; i += 1) {
|
|
if (!current || typeof current !== "object") break;
|
|
if (!("value" in current)) break;
|
|
const next = current.value;
|
|
if (!next || typeof next !== "object") break;
|
|
current = next;
|
|
}
|
|
return current;
|
|
}
|
|
|
|
function resolveInputElement(maybeInput) {
|
|
const candidate = unwrapCandidate(maybeInput);
|
|
if (!candidate) return null;
|
|
|
|
const tag = String(candidate?.tagName || "").toUpperCase();
|
|
if (tag === "INPUT" || tag === "TEXTAREA") return candidate;
|
|
|
|
try {
|
|
if (typeof candidate?.querySelector === "function") {
|
|
const nested =
|
|
candidate.querySelector("#mjr-search-input") ||
|
|
candidate.querySelector("input.mjr-input") ||
|
|
candidate.querySelector("input[type='text']") ||
|
|
candidate.querySelector("textarea");
|
|
if (nested) return nested;
|
|
}
|
|
} catch (e) {
|
|
console.debug?.(e);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function normalizeQuery(searchInputEl) {
|
|
const input = resolveInputElement(searchInputEl);
|
|
const rawValue = input
|
|
? input.value
|
|
: typeof searchInputEl?.value === "string"
|
|
? searchInputEl.value
|
|
: "";
|
|
const raw = String(rawValue || "").trim();
|
|
return raw || "*";
|
|
}
|