From eb946980b3cb56133236fafd16b555ae773debca Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 17 Nov 2026 04:02:02 -0500 Subject: [PATCH] Pages: below 900 px `auto` shows the panes one column at a time, swiped like pages The same forest of forks, laid out a column per page as wide as the screen, each column's panes stacked down it as on a wide screen (tabs a finger high). A tap on a row, a link or a section opens it and goes to it; a swipe ends on a page and makes its pane the active one (read at scrollend, never per frame); the active pane's page is always the one on screen. The trail at the foot names the focused branch in the panes' colours; its map lists every open pane to go to, pin or close. No curves: what a pane was opened from takes its colour. Each step from pane to pane is an entry in the browser's history, so Back goes back a pane and a swipe back is Back. Crossing 900 px keeps the forest and the active pane. Pane buttons always shown, 40 px; status line detail, key hints and `?` left to the menus; safe areas, 100dvh, the on-screen keyboard; a long press on a link shows its card above its menu. `/view panes` and `/view column` as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab --- index.html | 2 +- src/ui/App.tsx | 41 +++++++++- src/ui/Mouse.tsx | 27 ++++--- src/ui/Pages.tsx | 172 ++++++++++++++++++++++++++++++++++++++++++ src/ui/Panes.tsx | 166 ++++++++++++++++++++++++++++++++++++---- src/ui/actions.ts | 8 +- src/ui/store.ts | 170 +++++++++++++++++++++++++++++++++++------ src/ui/style.css | 153 +++++++++++++++++++++++++++++++++---- tests/actions.test.ts | 3 + 9 files changed, 671 insertions(+), 71 deletions(-) create mode 100644 src/ui/Pages.tsx 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 (