diff --git a/index.html b/index.html index dddd738..cd81ccf 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - + Infinispand diff --git a/src/ui/App.tsx b/src/ui/App.tsx index ca97735..5749662 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -9,10 +9,11 @@ import { DocBar, LibrariesPanel } from "./Menu"; import { LinkCard, LinkPicker, LinksPanel, NodeBacklinks, NodeRelated, TargetRow } from "./Links"; import { NodeBody, Outline, PendingSections, TopMatter } from "./Node"; import { Panes } from "./Panes"; +import { PaneMap, Trail } from "./Pages"; import { PANES_MIN_WIDTH, store, type Aux, type WRow } from "./store"; import { WikiPage, WikiView } from "./Wiki"; import { Usage } from "./Usage"; -import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, hideBar, locate, locateIn, menuAt, menuShown, setPrompt, showBar, type Hint } from "./Mouse"; +import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, hideBar, locate, locateIn, menuAt, menuShown, setCard, setPrompt, showBar, type Hint } from "./Mouse"; import { press } from "./press"; function Page() { @@ -479,8 +480,15 @@ export function App() { setPrefill(text); store.setMode("command"); }); + // A long press on a link (touch) shows what it opens above its menu. + setCard((note) => ); const onKey = (e: KeyboardEvent) => { clearTimeout(hover); + // Esc puts the map of panes away first. + if (e.key === "Escape" && store.paneMap) { + e.preventDefault(); + return store.showMap(false); + } // The keys take over from the pointer: its bar and menu go (not for a modifier, or the copy key). if (!e.ctrlKey && !e.metaKey && !e.altKey && !["Shift", "Control", "Alt", "Meta"].includes(e.key)) { hideBar(); @@ -527,10 +535,29 @@ export function App() { const wide = window.innerWidth >= PANES_MIN_WIDTH; if (wide === store.wide) return; store.wide = wide; + store.paneMap = false; if (store.settings.view === "auto") store.emit(); }; window.addEventListener("resize", onResize); - return () => window.removeEventListener("resize", onResize); + // An on-screen keyboard covers the foot of the screen without resizing the page (iOS): what sits + // at the foot (the status line, the command line, the selection bar) is raised above it. + const vv = window.visualViewport; + const onViewport = () => { + if (!vv) return; + const typing = (document.activeElement as HTMLElement | null)?.matches?.("input, textarea, [contenteditable]"); + const kb = typing && Math.abs(vv.scale - 1) < 0.01 ? Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop)) : 0; + const v = `${kb}px`; + if (document.documentElement.style.getPropertyValue("--kb") !== v) document.documentElement.style.setProperty("--kb", v); + }; + vv?.addEventListener("resize", onViewport); + window.addEventListener("focusin", onViewport); + window.addEventListener("focusout", onViewport); + return () => { + window.removeEventListener("resize", onResize); + vv?.removeEventListener("resize", onViewport); + window.removeEventListener("focusin", onViewport); + window.removeEventListener("focusout", onViewport); + }; }, []); // Keep the focused thing in view, and time keypress → paint. @@ -696,7 +723,11 @@ export function App() { store.go(id); store.open.add(id); const holder = store.trail[paneIndex]; - if (store.snap.nodes[id]?.kind === "section" && holder?.kind === "node" && store.snap.nodes[id].parent === holder.id) store.openPane(paneIndex, { kind: "node", id }); + if (store.snap.nodes[id]?.kind === "section" && holder?.kind === "node" && store.snap.nodes[id].parent === holder.id) { + store.openPane(paneIndex, { kind: "node", id }); + // As pages, a tap on a row goes to its pane: the next page. + if (store.pages) store.land(paneIndex + 1); + } return; } store.go(id); @@ -740,7 +771,7 @@ export function App() { }; return ( -
+
)} {panes ? : } + {store.pages && }
+ {store.mode === "history" && } {store.mode === "review" && } {store.mode === "help" && } diff --git a/src/ui/Mouse.tsx b/src/ui/Mouse.tsx index 634f7de..aa81b09 100644 --- a/src/ui/Mouse.tsx +++ b/src/ui/Mouse.tsx @@ -53,6 +53,9 @@ export const touch = () => typeof matchMedia === "function" && matchMedia("(hove let promptHook: (prefill: string) => void = () => {}; /** The page's command bar, to open with text already typed (App.tsx). */ export const setPrompt = (fn: (prefill: string) => void) => (promptHook = fn); +let cardHook: (note: NodeId) => ComponentChildren = () => null; +/** What a link's card is drawn with, above a menu on touch (App.tsx: the hover preview's body). */ +export const setCard = (fn: (note: NodeId) => ComponentChildren) => (cardHook = fn); export const act = pageAct({ command: (t) => store.command(t), prompt: (p) => promptHook(p) }); // ---- what is focused, for the menus ---- @@ -77,7 +80,7 @@ function selCtx(): SelCtx { const text = plain(store.selectedText() ?? ""); const s = store.snap; const a = store.aux; - if (a?.kind === "wiki") return { text, article: true, link: store.auxLink(a) ? "wiki" : undefined, note: !!store.articleNoteHere(), panes: store.panes }; + if (a?.kind === "wiki") return { text, article: true, link: store.auxLink(a) ? "wiki" : undefined, note: !!store.articleNoteHere(), panes: store.panes, pages: store.pages }; const f = store.focus; const id = store.noteAt(f.range); const r = id ? store.targetOf(id) : undefined; @@ -92,6 +95,7 @@ function selCtx(): SelCtx { return { title: x.title, where: t && t !== x.node ? s.nodes[t].title : undefined }; }), panes: store.panes, + pages: store.pages, }; } @@ -107,7 +111,7 @@ export function menuHere(where: Where): Entry[] { if (a?.kind === "wiki") { const h = store.wikiHost(a.host); if (store.panes && (where === "pane" || a.row.t === "head")) return paneEntries(a.host.startsWith("n") ? { node: nodeCtx(a.host.slice(1) as NodeId), pinned } : { article: h?.title, pinned }, act); - if (a.row.t === "sec" || a.row.t === "sense") return articleRowEntries(h?.title ?? "Wikipedia", store.panes, act); + if (a.row.t === "sec" || a.row.t === "sense") return articleRowEntries(h?.title ?? "Wikipedia", store.panes, act, store.pages); return []; } if (a) return []; @@ -221,7 +225,9 @@ export function menuAt(target: HTMLElement, at: { x: number; y: number } | HTMLE if (!where) return false; const entries = menuHere(where); if (!entries.length) return false; - showMenu(entries, at); + // On touch there is no hover to preview a link: a long press on one shows what it opens above its menu. + const note = touch() && !store.aux && store.selectedText() !== null ? store.noteAt(store.focus.range) : undefined; + showMenu(entries, at, note && store.snap.nodes[note]?.ref ? note : undefined); return true; } @@ -230,6 +236,8 @@ export function menuAt(target: HTMLElement, at: { x: number; y: number } | HTMLE interface Shown { entries: Entry[]; at: { x: number; y: number } | HTMLElement; + /** A link whose card shows above the items (a long press on it, on touch). */ + card?: NodeId; /** Where the focus was, to go back to when the menu closes. */ restore: HTMLElement | null; } @@ -240,12 +248,12 @@ const changed = () => watchers.forEach((f) => f()); /** The button whose menu a press on it just closed: the click that follows that press is not one to open it again. */ let closedBy: { el: HTMLElement; at: number } | null = null; -export function showMenu(entries: Entry[], at: Shown["at"]) { +export function showMenu(entries: Entry[], at: Shown["at"], card?: NodeId) { if (at instanceof HTMLElement && closedBy?.el === at && performance.now() - closedBy.at < 1000) return void (closedBy = null); closedBy = null; if (shown?.at instanceof HTMLElement) shown.at.removeAttribute("aria-expanded"); const active = document.activeElement as HTMLElement | null; - shown = { entries, at, restore: active && active !== document.body && !active.closest(".menu") ? active : shown?.restore ?? null }; + shown = { entries, at, card, restore: active && active !== document.body && !active.closest(".menu") ? active : shown?.restore ?? null }; if (at instanceof HTMLElement) at.setAttribute("aria-expanded", "true"); changed(); } @@ -271,7 +279,7 @@ export const keyText = (k: string) => KEY_TEXT[k] ?? (k.startsWith("A-") ? `Alt+ * hangs from; on touch, a sheet from the foot of the screen. ↑ ↓ (and Home End) move, Enter runs, * Esc closes and puts the focus back where it was; a press outside closes it too. */ -export function Menu({ entries, at, sheet, onClose }: { entries: Entry[]; at: Shown["at"]; sheet: boolean; onClose: (refocus: boolean) => void }) { +export function Menu({ entries, at, sheet, card, onClose }: { entries: Entry[]; at: Shown["at"]; sheet: boolean; card?: NodeId; onClose: (refocus: boolean) => void }) { const ref = useRef(null); useLayoutEffect(() => { const el = ref.current!; @@ -335,6 +343,7 @@ export function Menu({ entries, at, sheet, onClose }: { entries: Entry[]; at: Sh }; return (