File size: 1,078 Bytes
1187b53 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | export type ToolboxTabCard = {
title: string;
desc: string;
key: string;
};
function normalize(input: string): string {
return String(input || "").trim().toLowerCase();
}
export function isEditableElement(target: EventTarget | null): boolean {
if (!(target instanceof HTMLElement)) return false;
const tag = target.tagName.toLowerCase();
const contentEditableAttr = String(target.getAttribute("contenteditable") || "").toLowerCase();
const contentEditable = target.isContentEditable || contentEditableAttr === "true" || contentEditableAttr === "plaintext-only";
return contentEditable || tag === "input" || tag === "textarea" || tag === "select";
}
export function filterToolboxTabs<T extends ToolboxTabCard>(tabs: T[], query: string): T[] {
const q = normalize(query);
if (!q) return tabs;
return tabs.filter((tab) => {
const hay = normalize(`${tab.title} ${tab.desc} ${tab.key}`);
return hay.includes(q);
});
}
export function shortcutLabel(index: number): string {
if (index < 0 || index > 8) return "";
return `Alt+${index + 1}`;
}
|