// THE POSTS LIBRARY'S KEYS (lane posts-library), one table: the page's // handler, its key bar and the `?` sheet all read it. Plain ESM. export const LIBRARY_KEYS = [ { key: "j", action: "next", label: "next post" }, { key: "k", action: "prev", label: "previous post" }, { key: "a", action: "keep", label: "keep" }, { key: "d", action: "drop", label: "drop" }, { key: "l", action: "later", label: "later" }, { key: "c", action: "clear", label: "clear the judgement" }, { key: "t", action: "scope", label: "judge the post or its whole thread" }, { key: "n", action: "note", label: "note" }, { key: "x", action: "select", label: "select" }, { key: "A", action: "bulk-keep", label: "keep everything in the filter" }, { key: "D", action: "bulk-drop", label: "drop everything in the filter" }, { key: "L", action: "bulk-later", label: "mark everything in the filter later" }, { key: "u", action: "undo", label: "undo the last press" }, { key: "/", action: "search", label: "search" }, { key: "g", action: "gone", label: "only gone from the page" }, { key: "m", action: "media", label: "only with media" }, { key: "?", action: "help", label: "this list" }, ]; const BY_KEY = new Map(LIBRARY_KEYS.map((k) => [k.key, k.action])); /** * The action a key press asks for, or null: nothing while typing in a field, * nothing with Ctrl / Meta / Alt held (the browser's own keys). * @param {{ key: string, ctrlKey?: boolean, metaKey?: boolean, altKey?: boolean, typing?: boolean }} e */ export function libraryAction(e) { if (e.typing || e.ctrlKey || e.metaKey || e.altKey) return null; return BY_KEY.get(e.key) ?? null; } /** Whether a key event's target is a field being typed in. */ export function isTyping(target) { if (!target || typeof target !== "object") return false; const tag = String(target.tagName ?? "").toLowerCase(); return tag === "input" || tag === "textarea" || tag === "select" || target.isContentEditable === true; } /** The judge state an action sets ("undecided" removes the judgement), or null. */ export function stateOfAction(action) { const a = String(action ?? "").replace(/^bulk-/, ""); return a === "keep" || a === "drop" || a === "later" ? a : a === "clear" ? "undecided" : null; }