Forks in the panes view: Shift+Enter or a modified click opens beside, not instead
The store's trail becomes the focused branch of the tree of forks. Shift+Enter, Shift-, Ctrl-, Cmd- or middle-click opens a pane as a new fork; a plain open replaces the focused fork, or focuses a fork already open. Right of a pane with forks the space divides into rows that share the height down to a third each and then scroll, the pane they came from staying at the top; the strip still scrolls sideways as one. The parent marks each fork's row, link or words, the focused one as before. [ and ] move between forks, back where the reader was; q closes a whole fork at its end. A click in another fork focuses it. Too short or narrow a window draws only the focused branch and says which fork it is. A plain trail renders exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
e733e131bb
commit
207002410b
9 files changed
+860
-140
No files matched your search
@@ -0,0 +1,311 @@
|
||||
/**
|
||||
* Forks in the panes view: a modified open (Shift+Enter, Shift-, Ctrl- or middle-click) opens its
|
||||
* pane beside what is to the right instead of replacing it, and the space right of the pane
|
||||
* divides into rows, one per fork. Same build, mock model, mock Wikipedia and shared library as
|
||||
* the other specs; the documents are hoisted to (z) as in panes.spec.ts.
|
||||
*/
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { focusedTitle, jump, keys, seedLinks, selected, settle, state } from "./helpers";
|
||||
|
||||
/** The tree of panes by title, the picked child starred: [title, [children]] or a leaf's title. */
|
||||
const tree = (page: Page) =>
|
||||
state(page, (s) => {
|
||||
const name = (p: any) => (p.kind === "node" ? s.snap.nodes[p.id]?.title || s.snap.nodes[p.id]?.anchors[0]?.text : `W:${p.title}${p.sec ? `#${p.sec}` : ""}`);
|
||||
const go = (n: any): unknown => (n.kids.length ? [name(n.ref), n.kids.map((k: any, j: number) => (j === n.pick ? ["*", go(k)] : go(k)))] : name(n.ref));
|
||||
return go(s.tree);
|
||||
});
|
||||
/** The focused branch, by title. */
|
||||
const trail = (page: Page) => state(page, (s) => s.trail.map((p: any) => (p.kind === "node" ? s.snap.nodes[p.id]?.title || s.snap.nodes[p.id]?.anchors[0]?.text : `W:${p.title}${p.sec ? `#${p.sec}` : ""}`)));
|
||||
/** The rows right of the first pane with forks, each as the titles of its panes, left to right. */
|
||||
const forkRows = (page: Page) =>
|
||||
page.evaluate(() =>
|
||||
[...document.querySelectorAll(".strip .forks")][0]
|
||||
? [...document.querySelector(".strip .forks")!.children].map((row) =>
|
||||
[...row.querySelectorAll(".pane")].map((p) => p.querySelector(".wiki-head h2, .pane-head h2, .top h1")?.textContent?.trim() ?? ""),
|
||||
)
|
||||
: [],
|
||||
);
|
||||
/** A section's child sections, by title. */
|
||||
const childTitles = (page: Page, title: string) =>
|
||||
page.evaluate((t) => {
|
||||
const s = (globalThis as any).__ie;
|
||||
const n = (Object.values(s.snap.nodes) as any[]).find((x) => x.title === t);
|
||||
return n.children.filter((c: string) => s.snap.nodes[c].kind === "section").map((c: string) => s.snap.nodes[c].title) as string[];
|
||||
}, title);
|
||||
|
||||
async function open(page: Page) {
|
||||
await page.goto("/doc/infinite-expand");
|
||||
await page.waitForSelector(".strip > .pane");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
await expect(page.locator(".strip > .pane")).toHaveCount(2);
|
||||
await page.keyboard.press("z");
|
||||
await expect(page.locator(".strip > .pane")).toHaveCount(1);
|
||||
}
|
||||
|
||||
/** Tab through the focused text's marked spans until the selection is these words. */
|
||||
async function tabTo(page: Page, words: string) {
|
||||
for (let i = 0; i < 14; i++) {
|
||||
await page.keyboard.press("Tab");
|
||||
if ((await state(page, (s) => s.selectedText())) === words) return;
|
||||
}
|
||||
throw new Error(`Tab never reached “${words}”`);
|
||||
}
|
||||
|
||||
/** Whether an element's box is inside the strip's visible box. */
|
||||
const inView = (page: Page, sel: string) =>
|
||||
page.evaluate((sel) => {
|
||||
const strip = document.querySelector<HTMLElement>(".strip")!.getBoundingClientRect();
|
||||
const r = document.querySelector(sel)!.getBoundingClientRect();
|
||||
return r.top >= strip.top - 1 && r.bottom <= strip.bottom + 1;
|
||||
}, sel);
|
||||
|
||||
test.use({ viewport: { width: 1920, height: 1080 } });
|
||||
test.describe.configure({ mode: "serial" });
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
await seedLinks(request);
|
||||
});
|
||||
test.beforeEach(async ({ context }) => {
|
||||
await context.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
|
||||
});
|
||||
test.afterEach(({ page }) => settle(page));
|
||||
|
||||
test("Shift+Enter on a section row opens a fork beside the pane to the right; Enter still replaces, and focuses a fork already open", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "l l l"); // Expansion by depth showing; the focus on its first row
|
||||
// Nothing to the right yet: a fork is a plain open, and a plain trail is drawn as before.
|
||||
await keys(page, "Shift+Enter");
|
||||
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Expansion by depth", [["*", "Levels of a node"]]]]]]);
|
||||
await expect(page.locator(".strip:not(.forked) > .pane")).toHaveCount(3);
|
||||
await expect(page.locator(".forks")).toHaveCount(0);
|
||||
await keys(page, "j Shift+Enter");
|
||||
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Pre-generated depth"]]);
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Pre-generated depth"]);
|
||||
// The rows divide the height; both start in the column next to the pane they came from.
|
||||
const [a, b, parent] = await Promise.all([
|
||||
page.locator(".forks > .fork").nth(0).locator(".pane").boundingBox(),
|
||||
page.locator(".forks > .fork").nth(1).locator(".pane").boundingBox(),
|
||||
page.locator('.pane[data-pane-index="1"]').boundingBox(),
|
||||
]);
|
||||
expect(a!.x).toBeCloseTo(b!.x, 0);
|
||||
expect(b!.y).toBeGreaterThanOrEqual(a!.y + a!.height - 1);
|
||||
expect(a!.x).toBeGreaterThan(parent!.x);
|
||||
expect(a!.height).toBeGreaterThan(300);
|
||||
// The pane they came from marks both, the focused one as before and the other lightly.
|
||||
await expect(page.locator('.pane[data-pane-index="1"] .node.showing > .row')).toHaveText([/Pre-generated depth/]);
|
||||
await expect(page.locator('.pane[data-pane-index="1"] .node.forked > .row')).toHaveText([/Levels of a node/]);
|
||||
// A plain Enter replaces only the focused fork.
|
||||
await keys(page, "j Enter");
|
||||
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Generation on demand"]]);
|
||||
// Enter (or Shift+Enter) on the row of a fork already open focuses that fork: no second copy.
|
||||
await keys(page, "k k Enter");
|
||||
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Generation on demand"]]);
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Levels of a node"]);
|
||||
await keys(page, "j j Shift+Enter");
|
||||
expect(await forkRows(page)).toEqual([["Levels of a node"], ["Generation on demand"]]);
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand"]);
|
||||
});
|
||||
|
||||
test("Shift-, Ctrl- and middle-click fork from section rows; a click in another fork makes it the focused one", async ({ page }) => {
|
||||
await open(page);
|
||||
const kids = await childTitles(page, "Borrowed from Gwern");
|
||||
expect(kids.length).toBeGreaterThanOrEqual(3);
|
||||
const row = (t: string) => page.locator(".pane .row", { hasText: t }).first();
|
||||
await row("Borrowed from Gwern").click();
|
||||
await row(kids[0]).click({ modifiers: ["Shift"] }); // nothing right of it yet: a plain open
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Borrowed from Gwern", kids[0]]);
|
||||
await row(kids[1]).click({ modifiers: ["Control"] });
|
||||
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Borrowed from Gwern", [kids[0], ["*", kids[1]]]]]]]);
|
||||
await row(kids[2]).click({ button: "middle" });
|
||||
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Borrowed from Gwern", [kids[0], kids[1], ["*", kids[2]]]]]]]);
|
||||
// A Shift-click selected no text on the way.
|
||||
expect(await page.evaluate(() => window.getSelection()?.isCollapsed ?? true)).toBe(true);
|
||||
// A click anywhere in the first fork's pane focuses that fork.
|
||||
await page.locator(".forks > .fork").nth(0).locator(".pane-head").click();
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Borrowed from Gwern", kids[0]]);
|
||||
expect(await focusedTitle(page)).toBe(kids[0]);
|
||||
await expect(page.locator(".forks > .fork.on")).toHaveCount(1);
|
||||
expect(await page.locator(".forks > .fork").nth(0).getAttribute("class")).toContain("on");
|
||||
// A plain click on a row replaces the focused fork, and a Shift-click on the focused row whose pane shows does not close it.
|
||||
await row("Display forms").click({ modifiers: ["Shift"] }); // the first pane forks too: a stack right of it
|
||||
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(2);
|
||||
await expect(page.locator(".strip > .forks > .fork").nth(0).locator(".forks > .fork")).toHaveCount(3);
|
||||
await row("Display forms").click({ modifiers: ["Shift"] });
|
||||
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(2);
|
||||
await row("Editing and regeneration").click();
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Editing and regeneration"]);
|
||||
await expect(page.locator(".strip > .forks > .fork").nth(1).locator(".pane-head h2")).toHaveText("Editing and regeneration");
|
||||
});
|
||||
|
||||
test("from a Wikipedia link, a node link and a link inside an article: forks, each marked where it was opened", async ({ page }) => {
|
||||
await page.goto("/doc/fixed-points");
|
||||
await page.waitForSelector(".strip > .pane");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
await jump(page, "Recursion without names");
|
||||
await tabTo(page, "fixed-point combinator");
|
||||
await keys(page, "Enter");
|
||||
await expect(page.locator(".wiki-pane .wiki-head h2")).toHaveText("Fixed-point combinator");
|
||||
await keys(page, "h"); // back to the words
|
||||
expect(await selected(page)).toBe("fixed-point combinator");
|
||||
await tabTo(page, "Y combinator");
|
||||
await keys(page, "Shift+Enter");
|
||||
expect(await forkRows(page)).toEqual([["Fixed-point combinator"], ["How Y works"]]);
|
||||
// In the text it came from, both links are marked, the focused fork's more strongly.
|
||||
const from = page.locator('.pane[data-pane-index="2"]');
|
||||
await expect(from.locator(".lnk.forked.picked")).toHaveText("Y combinator");
|
||||
await expect(from.locator(".lnk.forked:not(.picked)")).toHaveText("fixed-point combinator");
|
||||
// [ goes up to the article's row; its sections open as rows, as before.
|
||||
await keys(page, "[");
|
||||
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names", "W:Fixed-point combinator"]);
|
||||
expect(await state(page, (s) => s.aux)).toMatchObject({ kind: "wiki", host: "p3", row: { t: "head" } });
|
||||
await expect(from.locator(".lnk.forked.picked")).toHaveText("fixed-point combinator");
|
||||
await expect(page.locator(".wiki-pane .wrow").first()).toBeVisible();
|
||||
await keys(page, "j j l");
|
||||
expect((await trail(page)).at(-1)).toBe("W:Fixed-point combinator#2");
|
||||
// A Shift-click on a link in the article's text forks beside that section.
|
||||
const art = page.locator(".forks > .fork").nth(0).locator(".wiki-pane").first();
|
||||
await art.locator('.wiki-text a[data-wiki="Haskell Curry"]').click({ modifiers: ["Shift"] });
|
||||
const article = ["W:Fixed-point combinator", ["W:Fixed-point combinator#2", ["*", "W:Haskell Curry"]]];
|
||||
const recursion = ["Recursion without names", [["*", article], "How Y works"]];
|
||||
expect(await tree(page)).toEqual(["Library", [["*", ["Fixed points", [["*", recursion]]]]]]);
|
||||
await expect(art.locator(".wrow.forked > .row .title")).toHaveText("Y combinator");
|
||||
await expect(art.locator('.wiki-text a.forked.picked[data-wiki="Haskell Curry"]')).toHaveCount(1);
|
||||
// And Shift+Enter on a link selected by Tab in the article's text: a third fork of the article.
|
||||
await keys(page, "h");
|
||||
for (let i = 0; i < 6 && (await state(page, (s) => s.aux?.host)) !== "p3"; i++) await keys(page, "h");
|
||||
await keys(page, "k k k");
|
||||
await tabTo(page, "lambda calculus");
|
||||
await keys(page, "Shift+Enter");
|
||||
await expect(page.locator(".wiki-pane .wiki-head h2", { hasText: "Lambda calculus" })).toHaveCount(1);
|
||||
expect(await trail(page)).toEqual(["Library", "Fixed points", "Recursion without names", "W:Fixed-point combinator", "W:Lambda calculus"]);
|
||||
const stack = page.locator(".forks > .fork").nth(0).locator(".forks > .fork");
|
||||
await expect(stack).toHaveCount(3);
|
||||
});
|
||||
|
||||
test("three forks of one pane, one forked again: [ and ] move between them, q closes a fork, and the last but one leaves a plain trail", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "l l l Shift+Enter j Shift+Enter j Shift+Enter");
|
||||
await keys(page, "l Shift+Enter j Shift+Enter"); // into Generation on demand, and fork from it too
|
||||
expect(await tree(page)).toEqual([
|
||||
"Infinispand",
|
||||
[["*", ["Expansion by depth", ["Levels of a node", "Pre-generated depth", ["*", ["Generation on demand", ["Deepening a leaf", ["*", "Expanding a selection"]]]]]]]],
|
||||
]);
|
||||
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(3);
|
||||
await expect(page.locator(".strip > .forks > .fork").nth(2).locator(".forks > .fork")).toHaveCount(2);
|
||||
await keys(page, "]");
|
||||
await expect(page.locator(".status .message")).toContainText("No fork below");
|
||||
// Up, row by row, in the order they are drawn: the nearest fork first.
|
||||
await keys(page, "[");
|
||||
expect((await trail(page)).at(-1)).toBe("Deepening a leaf");
|
||||
expect(await focusedTitle(page)).toBe("Deepening a leaf");
|
||||
await keys(page, "[");
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Pre-generated depth"]);
|
||||
expect(await focusedTitle(page)).toBe("Pre-generated depth");
|
||||
await keys(page, "[");
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Levels of a node"]);
|
||||
await keys(page, "[");
|
||||
await expect(page.locator(".status .message")).toContainText("No fork above");
|
||||
// Down again; back in a fork, the focus is where it was left.
|
||||
await keys(page, "] ]");
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand", "Deepening a leaf"]);
|
||||
expect(await focusedTitle(page)).toBe("Deepening a leaf");
|
||||
// q at the end of a fork closes that fork; the other stays, as a plain trail.
|
||||
await keys(page, "q");
|
||||
expect(await tree(page)).toEqual([
|
||||
"Infinispand",
|
||||
[["*", ["Expansion by depth", ["Levels of a node", "Pre-generated depth", ["*", ["Generation on demand", [["*", "Expanding a selection"]]]]]]]],
|
||||
]);
|
||||
// In a fork with panes right of the one being read, q closes those, as it always has.
|
||||
await keys(page, "h");
|
||||
expect(await focusedTitle(page)).toBe("Generation on demand");
|
||||
await keys(page, "q");
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Generation on demand"]);
|
||||
// With nothing right of it, the whole fork.
|
||||
await keys(page, "q");
|
||||
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Expansion by depth", ["Levels of a node", ["*", "Pre-generated depth"]]]]]]);
|
||||
await keys(page, "[ q");
|
||||
expect(await tree(page)).toEqual(["Infinispand", [["*", ["Expansion by depth", [["*", "Pre-generated depth"]]]]]]);
|
||||
await expect(page.locator(".forks")).toHaveCount(0);
|
||||
await expect(page.locator(".strip:not(.forked) > .pane")).toHaveCount(3);
|
||||
await keys(page, "]");
|
||||
await expect(page.locator(".status .message")).toContainText("No forks open");
|
||||
});
|
||||
|
||||
test("many forks: the rows scroll down with the focused one in view; a reload brings the tree back", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "j Shift+Enter");
|
||||
for (let i = 0; i < 5; i++) await keys(page, "j Shift+Enter");
|
||||
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(6);
|
||||
const strip = page.locator(".strip");
|
||||
expect(await strip.evaluate((el) => el.scrollHeight > el.clientHeight + 100)).toBe(true);
|
||||
// Each row is a third of the strip's height; the last, focused, is in view, and the first pane stays at the top.
|
||||
const h = await strip.evaluate((el) => el.clientHeight);
|
||||
const rowH = (await page.locator(".forks > .fork").nth(2).boundingBox())!.height;
|
||||
expect(Math.abs(rowH - Math.floor(h / 3))).toBeLessThanOrEqual(2);
|
||||
await expect.poll(() => inView(page, ".forks > .fork.on")).toBe(true);
|
||||
await expect.poll(() => strip.evaluate((el) => el.scrollTop)).toBeGreaterThan(100);
|
||||
const first = await page.locator(".strip > .pane").first().boundingBox();
|
||||
const sbox = (await strip.boundingBox())!;
|
||||
expect(Math.abs(first!.y - sbox.y)).toBeLessThanOrEqual(1);
|
||||
// Up to the first fork: the strip scrolls back.
|
||||
await keys(page, "[ [ [ [ [");
|
||||
await expect.poll(() => inView(page, ".forks > .fork.on")).toBe(true);
|
||||
await expect.poll(() => strip.evaluate((el) => el.scrollTop)).toBeLessThan(5);
|
||||
const before = await tree(page);
|
||||
const was = await trail(page);
|
||||
await page.reload();
|
||||
await page.waitForSelector(".strip > .pane");
|
||||
expect(await tree(page)).toEqual(before);
|
||||
expect(await trail(page)).toEqual(was);
|
||||
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(6);
|
||||
});
|
||||
|
||||
test("a fork whose node is deleted closes, and the others stay", async ({ page, request }) => {
|
||||
// A section of its own to delete, written as another writer would.
|
||||
const tree0 = await (await request.get("/api/tree")).json();
|
||||
const depth = Object.values(tree0.nodes as Record<string, { id: string; title: string }>).find((n) => n.title === "Expansion by depth")!.id;
|
||||
const made = await request.post("/api/ops", { data: { author: "another", message: "Add a section", ops: [{ op: "create", parent: depth, title: "A section to delete", body: "Soon gone." }] } });
|
||||
expect(made.ok()).toBe(true);
|
||||
await open(page);
|
||||
await keys(page, "l l l Shift+Enter");
|
||||
const kids = await childTitles(page, "Expansion by depth");
|
||||
for (let i = 1; i < kids.indexOf("A section to delete"); i++) await keys(page, "j");
|
||||
await keys(page, "j Shift+Enter");
|
||||
expect(await forkRows(page)).toEqual([["Levels of a node"], ["A section to delete"]]);
|
||||
await keys(page, "[");
|
||||
const id = await state(page, (s) => (Object.values(s.snap.nodes) as any[]).find((n) => n.title === "A section to delete").id);
|
||||
const res = await request.post("/api/ops", { data: { author: "another", message: "Delete it", ops: [{ op: "delete", id }] } });
|
||||
expect(res.ok()).toBe(true);
|
||||
// The fork that was not focused goes; the focused one stays, now a plain trail.
|
||||
await expect.poll(() => page.locator(".forks").count()).toBe(0);
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Expansion by depth", "Levels of a node"]);
|
||||
});
|
||||
|
||||
test("a window too short for rows shows only the focused branch, and says which fork it is and how to switch", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 480 });
|
||||
await open(page);
|
||||
await keys(page, "l l l Shift+Enter j Shift+Enter");
|
||||
await expect(page.locator(".forks")).toHaveCount(0);
|
||||
await expect(page.locator(".strip > .pane")).toHaveCount(3);
|
||||
await expect(page.locator(".fork-note")).toContainText("fork 2 of 2");
|
||||
await keys(page, "[");
|
||||
await expect(page.locator(".fork-note")).toContainText("fork 1 of 2");
|
||||
expect((await trail(page)).at(-1)).toBe("Levels of a node");
|
||||
// With room again, the rows come back.
|
||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||
await expect(page.locator(".strip > .forks > .fork")).toHaveCount(2);
|
||||
await expect(page.locator(".fork-note")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("in the column a modified open is a plain open, and the status line says why once", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await page.goto("/doc/fixed-points");
|
||||
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
||||
await jump(page, "Recursion without names");
|
||||
await keys(page, "Shift+Enter");
|
||||
await expect(page.locator(".status .message")).toContainText("panes view");
|
||||
await keys(page, "Shift+Enter Shift+Enter");
|
||||
expect(await state(page, (s) => s.log.filter((l: any) => l.text.includes("panes view")).length)).toBe(1);
|
||||
await keys(page, "[");
|
||||
await expect(page.locator(".status .message")).toContainText("panes view");
|
||||
});
|
||||
+27
-15
@@ -3,6 +3,7 @@ import { ancestors, ancestorsInDoc, docOf, label, sections, staleness, type Conf
|
||||
import { verifyHistory, type Commit } from "../core/repo";
|
||||
import { clip, plain, sentences } from "../core/text";
|
||||
import { hostOf } from "../core/ref";
|
||||
import { nodeRef } from "../core/links";
|
||||
import { HELP, handleKey } from "./keys";
|
||||
import { DocBar, DocsPanel } from "./Menu";
|
||||
import { LinkCard, LinkPicker, NodeBacklinks, NodeRelated, TargetRow } from "./Links";
|
||||
@@ -506,22 +507,23 @@ export function App() {
|
||||
if (!store.ready) return <div class="loading">Loading…</div>;
|
||||
|
||||
const panes = store.panes;
|
||||
const onClick = (e: MouseEvent) => {
|
||||
// Shift-, Ctrl- or Cmd-click (and a middle click) opens a fork: beside what is open, not instead of it.
|
||||
const onClick = (e: MouseEvent) => store.withFork(e.shiftKey || e.ctrlKey || e.metaKey || e.button === 1, () => click(e));
|
||||
const click = (e: MouseEvent) => {
|
||||
if (store.mode === "edit") return;
|
||||
const target = e.target as HTMLElement;
|
||||
const paneEl = target.closest<HTMLElement>("[data-pane-index]");
|
||||
const paneIndex = paneEl ? Number(paneEl.dataset.paneIndex) : store.paneAt;
|
||||
// A pane in another fork: that fork becomes the focused branch first, then the click does what it would there.
|
||||
const tid = paneEl ? Number(paneEl.dataset.tid) : undefined;
|
||||
if (tid !== undefined && store.branchNodes[paneIndex]?.id !== tid) store.enterFork(tid);
|
||||
// A covered pane's spine brings that pane back by focusing it.
|
||||
const spine = target.closest<HTMLElement>("[data-spine]");
|
||||
if (spine) {
|
||||
const i = Number(spine.dataset.spine);
|
||||
const p = store.trail[i];
|
||||
store.paneAt = i;
|
||||
if (p?.kind === "node") return store.setFocus({ node: p.id, grain: "node" });
|
||||
return store.setFocus(store.focus, { kind: "wiki", host: `p${i}`, row: { t: "head" } });
|
||||
}
|
||||
if (spine) return store.land(Number(spine.dataset.spine));
|
||||
// Article text: a link to another article opens it next; a link out leaves in a new tab (the HTML says so); nothing else navigates.
|
||||
const host = target.closest<HTMLElement>("[data-host]")?.dataset.host;
|
||||
const named = target.closest<HTMLElement>("[data-host]")?.dataset.host;
|
||||
// An article pane off the branch is named by its place in the tree; on the branch, by its column.
|
||||
const host = named?.startsWith("f") ? `p${paneIndex}` : named;
|
||||
const a = target.closest<HTMLAnchorElement>("a");
|
||||
if (a && host) {
|
||||
if (a.dataset.wiki) {
|
||||
@@ -548,6 +550,11 @@ export function App() {
|
||||
store.paneAt = paneIndex;
|
||||
return store.openLinking(linking.dataset.linking as NodeId);
|
||||
}
|
||||
const related = target.closest<HTMLElement>("[data-related]");
|
||||
if (related) {
|
||||
store.paneAt = paneIndex;
|
||||
return store.follow(nodeRef(store.snap, related.dataset.related as NodeId));
|
||||
}
|
||||
const targetRow = target.closest<HTMLElement>("[data-target]");
|
||||
if (targetRow) {
|
||||
store.paneAt = paneIndex;
|
||||
@@ -578,7 +585,7 @@ export function App() {
|
||||
return;
|
||||
}
|
||||
// A drag selection inside one body becomes the focus range.
|
||||
if (selection && !selection.isCollapsed) {
|
||||
if (selection && !selection.isCollapsed && !store.forking) {
|
||||
const a = locate(selection.anchorNode, selection.anchorOffset);
|
||||
const b = locate(selection.focusNode, selection.focusOffset);
|
||||
if (a && b && a.id === b.id && a.at !== b.at) {
|
||||
@@ -618,10 +625,9 @@ export function App() {
|
||||
if (panes && id !== store.top) {
|
||||
// In panes a click shows the row's pane: focus it and open it next. On the focused row whose pane is showing, it closes that pane.
|
||||
const next = store.trail[paneIndex + 1];
|
||||
if (store.focus.node === id && store.focus.grain === "node" && next?.kind === "node" && next.id === id) {
|
||||
store.trail = store.trail.slice(0, paneIndex + 1);
|
||||
store.saveView();
|
||||
return store.emit();
|
||||
if (!store.forking && store.focus.node === id && store.focus.grain === "node" && next?.kind === "node" && next.id === id) {
|
||||
store.closeRow(paneIndex, id);
|
||||
return;
|
||||
}
|
||||
store.paneAt = paneIndex;
|
||||
store.go(id);
|
||||
@@ -658,7 +664,13 @@ export function App() {
|
||||
|
||||
return (
|
||||
<div class={`app mode-${store.mode}${store.mode === "history" || store.mode === "docs" ? " with-panel" : ""}${panes ? " view-panes" : ""}`} onMouseOver={onOver}>
|
||||
<main class="page" onClick={onClick}>
|
||||
<main
|
||||
class="page"
|
||||
onClick={onClick}
|
||||
onAuxClick={(e) => e.button === 1 && (e.preventDefault(), onClick(e))}
|
||||
// A Shift-click would extend the text selection, and a middle press scrolls or pastes: neither, when they open a fork.
|
||||
onMouseDown={(e) => (e.shiftKey || e.button === 1) && !(e.target as HTMLElement).closest("input, textarea") && e.preventDefault()}
|
||||
>
|
||||
<DocBar />
|
||||
{store.preview && (
|
||||
<div class="banner">
|
||||
|
||||
+23
-4
@@ -3,8 +3,8 @@
|
||||
* icons: W for Wikipedia, § for another note in this library, ↗ for the web), the card a popup or
|
||||
* an inset shows, a node's own target, the "Linked from" list, and the link picker.
|
||||
*/
|
||||
import { Fragment } from "preact";
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||
import { Fragment, createContext } from "preact";
|
||||
import { useContext, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||
import { ownerSection, resolveNode } from "../core/links";
|
||||
import { docOf, isLink, label, type NodeId } from "../core/model";
|
||||
import { describeTarget, hostOf, parseTarget, validateRef, wikiTitle, type Ref } from "../core/ref";
|
||||
@@ -139,11 +139,29 @@ export function TargetRow({ id }: { id: NodeId }) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** The pane (its id in the tree of forks) that what is drawn inside it belongs to; none in the column. */
|
||||
export const PaneCtx = createContext<number | undefined>(undefined);
|
||||
|
||||
/**
|
||||
* In a pane with forks, what marks the words, rows and links its forks were opened from: each open
|
||||
* child is "forked", the focused one "forked picked". By the keys a pane's child goes by (refKey).
|
||||
*/
|
||||
export function useForkMark(): ((...keys: (string | undefined)[]) => string) | null {
|
||||
const marks = store.forkMarks(useContext(PaneCtx));
|
||||
if (!marks) return null;
|
||||
return (...keys) => {
|
||||
for (const k of keys) if (k && marks.has(k)) return marks.get(k) ? "forked picked" : "forked";
|
||||
return "";
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* "Linked from": the nodes that link here, each as its section's title and its document. Collapsed
|
||||
* to nothing when there are none. The same list, for an article, is "Mentioned in".
|
||||
*/
|
||||
export function Backlinks({ ids, title, focusedAt }: { ids: NodeId[]; title: string; focusedAt: (i: number) => boolean }) {
|
||||
const forkMark = useForkMark();
|
||||
if (!ids.length) return null;
|
||||
const s = store.snap;
|
||||
return (
|
||||
@@ -155,7 +173,7 @@ export function Backlinks({ ids, title, focusedAt }: { ids: NodeId[]; title: str
|
||||
const d = docOf(s, id);
|
||||
const n = s.nodes[id];
|
||||
return (
|
||||
<li key={id} class={focusedAt(i) ? "focused" : ""} data-linking={id}>
|
||||
<li key={id} class={[focusedAt(i) && "focused", forkMark?.(`n:${sec}`)].filter(Boolean).join(" ")} data-linking={id}>
|
||||
<span class="bl-title">{label(s, sec)}</span>
|
||||
<span class="bl-doc">{d && d !== sec ? s.nodes[d].title : "document"}</span>
|
||||
{n.kind === "note" && <span class="bl-quote">“{clip(n.anchors[0]?.text ?? "", 60)}”</span>}
|
||||
@@ -185,13 +203,14 @@ export function SuggestionCard({ sg }: { sg: Sugg }) {
|
||||
*/
|
||||
export function NodeRelated({ id }: { id: NodeId }) {
|
||||
const rows = store.relatedShown(id) ? store.relatedOf(id) : [];
|
||||
const forkMark = useForkMark();
|
||||
if (!rows.length) return null;
|
||||
return (
|
||||
<section class="related-list">
|
||||
<h3>Related</h3>
|
||||
<ul>
|
||||
{rows.map((r, i) => (
|
||||
<li key={r.node} data-related={r.node}>
|
||||
<li key={r.node} class={forkMark?.(`n:${r.node}`) || undefined} data-related={r.node}>
|
||||
<span class="bl-key">{i + 1}</span>
|
||||
<span class="bl-title">{r.title}</span>
|
||||
<span class="bl-doc">{r.doc}</span>
|
||||
|
||||
+3
-1
@@ -6,7 +6,7 @@ import type { Ref } from "../core/ref";
|
||||
import { clip, overlaps, paragraphs, plain, type Form, type Range } from "../core/text";
|
||||
import { streamView } from "../core/marks";
|
||||
import { ownerSection } from "../core/links";
|
||||
import { ChoiceRows, LinkMark, LinkPreview, NodeBacklinks, NodeRelated, SuggestionCard, TargetRow, articleChoice, sectionChoice, useWikiSuggest, type Choice } from "./Links";
|
||||
import { ChoiceRows, LinkMark, useForkMark, LinkPreview, NodeBacklinks, NodeRelated, SuggestionCard, TargetRow, articleChoice, sectionChoice, useWikiSuggest, type Choice } from "./Links";
|
||||
import { store, type Pending } from "./store";
|
||||
|
||||
// ---- inline text ----
|
||||
@@ -47,6 +47,7 @@ const MARK = /\*([^*\n]+)\*|`([^`\n]+)`/g;
|
||||
function Para(props: { id: NodeId; range: Range; notes: VNote[]; inline: boolean; inNote: boolean; first: boolean }) {
|
||||
const { id, range, notes, inline } = props;
|
||||
const snap = store.snap;
|
||||
const forkMark = useForkMark();
|
||||
const body = snap.nodes[id].body;
|
||||
const [ps, pe] = range;
|
||||
const cuts = new Set<number>([ps, pe]);
|
||||
@@ -104,6 +105,7 @@ function Para(props: { id: NodeId; range: Range; notes: VNote[]; inline: boolean
|
||||
note?.open && "on",
|
||||
note?.pending && "writing",
|
||||
link?.link && !note && `lnk l-${link.ref!.kind}${link.open ? " on" : ""}`,
|
||||
forkMark && (note ?? link)?.id && forkMark(`n:${(note ?? link)!.id}`, link?.ref && store.targetKey(link.ref)),
|
||||
sel && sel[0] <= a && sel[1] >= b && `sel ${f.grain}`,
|
||||
within(srcRanges, a, b) && "src",
|
||||
sugg && `sugg${sugg.tier === "auto" ? " sure" : ""}`,
|
||||
|
||||
+163
-47
@@ -1,34 +1,47 @@
|
||||
/**
|
||||
* The panes view: a trail of panes, side by side, in the manner of Andy Matuschak's notes. It
|
||||
* starts as the path down from the top node; a link followed from a pane opens its target in the
|
||||
* next pane (another document's node, a Wikipedia article, a section of one), replacing what was
|
||||
* to the right. Moving back left closes nothing: the trail stays until something else is opened
|
||||
* from an earlier pane, or q closes panes. Earlier panes stay pinned at the left as narrow spines
|
||||
* when later ones slide over them.
|
||||
* The panes view: panes side by side, in the manner of Andy Matuschak's notes. It starts as the
|
||||
* path down from the top node; a link followed from a pane opens its target in the next pane
|
||||
* (another document's node, a Wikipedia article, a section of one), replacing what was to the
|
||||
* right. Moving back left closes nothing: the panes stay until something else is opened from an
|
||||
* earlier pane, or q closes them. Earlier panes stay pinned at the left as narrow spines when later
|
||||
* ones slide over them.
|
||||
*
|
||||
* The trail is `store.trail`; which pane holds the focus is `store.paneAt`. Clicks are handled by
|
||||
* the page (App.tsx), exactly as in the column view.
|
||||
* A modified open (Shift+Enter, Shift- or Ctrl-click) makes a fork instead: the new pane opens
|
||||
* beside what was to the right, and the space right of the pane divides into rows, one per fork,
|
||||
* each continuing its own trail (forks.ts). The panes are `store.tree`; its focused branch is
|
||||
* `store.trail`, and which pane on it holds the focus is `store.paneAt`. Clicks are handled by the
|
||||
* page (App.tsx), exactly as in the column view; a click in another fork first makes it the
|
||||
* focused branch.
|
||||
*/
|
||||
import { Component } from "preact";
|
||||
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
||||
import { Component, type ComponentChildren } from "preact";
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||
import { docOf, label, sections, staleness, type NodeId } from "../core/model";
|
||||
import { NodeBacklinks, NodeRelated, TargetRow } from "./Links";
|
||||
import { leaves } from "./forks";
|
||||
import { NodeBacklinks, NodeRelated, PaneCtx, TargetRow } from "./Links";
|
||||
import { Flags, NodeBody, PendingSections, Row, TitleEditor, TopMatter } from "./Node";
|
||||
import { store, type Aux, type PaneRef } from "./store";
|
||||
import { refKey, store, type Aux, type Pane as PaneNode, type PaneRef } from "./store";
|
||||
import { WikiView } from "./Wiki";
|
||||
import { article } from "./wiki";
|
||||
|
||||
interface PaneProps {
|
||||
t: PaneNode;
|
||||
p: PaneRef;
|
||||
/** The pane it was opened from, the one to its left. */
|
||||
parent?: PaneRef;
|
||||
index: number;
|
||||
/** The child whose pane is open to the right of this one, if any. */
|
||||
showing?: NodeId;
|
||||
/** Its children, and which is picked, as a key (redraw when they change). */
|
||||
kids: string;
|
||||
/** Off the focused branch: drawn, but the keys are elsewhere; a click brings its fork onto the branch (App.tsx). Only an article pane draws differently (how its article is named). */
|
||||
off: boolean;
|
||||
/** In the narrow layout, where only the focused branch is drawn: which fork of how many this pane starts, if it starts one. */
|
||||
forkOf?: [number, number];
|
||||
/** The aux focus, when this pane holds it. */
|
||||
aux: Aux | null;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
const key = (p: PaneProps) => `${p.p.kind === "node" ? p.p.id : `${p.p.title}#${p.p.sec ?? ""}`}|${p.index}|${p.showing ?? ""}|${p.active}|${JSON.stringify(p.aux)}`;
|
||||
// `off` is left out: a node pane draws the same on the branch or off it, and moving between forks should redraw only what changed.
|
||||
const key = (p: PaneProps) => `${refKey(p.p)}|${p.index}|${p.kids}|${p.active}|${p.forkOf ?? ""}|${JSON.stringify(p.aux)}`;
|
||||
|
||||
/** Redraws a pane only when something drawn in it changed (see `store.paneDirty`). An article pane is cheap to redraw: its HTML is set once. */
|
||||
class Pane extends Component<PaneProps> {
|
||||
@@ -39,11 +52,30 @@ class Pane extends Component<PaneProps> {
|
||||
}
|
||||
render() {
|
||||
const p = this.props.p;
|
||||
return p.kind === "node" ? <NodePane {...this.props} id={p.id} /> : <WikiPane {...this.props} />;
|
||||
return <PaneCtx.Provider value={this.props.t.id}>{p.kind === "node" ? <NodePane {...this.props} id={p.id} /> : <WikiPane {...this.props} />}</PaneCtx.Provider>;
|
||||
}
|
||||
}
|
||||
|
||||
function NodePane({ id, index, showing, active }: PaneProps & { id: NodeId }) {
|
||||
/** The attributes every pane has: which it is, its column, and its place in the tree. */
|
||||
const paneAttrs = (props: PaneProps, name: string) => ({
|
||||
"data-pane": name,
|
||||
"data-pane-index": props.index,
|
||||
"data-tid": props.t.id,
|
||||
style: { left: `calc(${props.index} * var(--spine))` },
|
||||
});
|
||||
|
||||
/** In the narrow layout, a pane that starts a fork says so, and how to get to the others. */
|
||||
function ForkNote({ of }: { of?: [number, number] }) {
|
||||
if (!of) return null;
|
||||
return (
|
||||
<div class="fork-note">
|
||||
fork {of[0] + 1} of {of[1]} · <kbd>[</kbd> <kbd>]</kbd> for the others
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NodePane(props: PaneProps & { id: NodeId }) {
|
||||
const { id, index, active, t, parent } = props;
|
||||
const snap = store.snap;
|
||||
const n = snap.nodes[id];
|
||||
if (!n) return null;
|
||||
@@ -53,18 +85,21 @@ function NodePane({ id, index, showing, active }: PaneProps & { id: NodeId }) {
|
||||
const kids = sections(snap, id);
|
||||
const focused = active && !store.aux && store.focus.node === id;
|
||||
const editing = store.edit?.node === id && store.edit.field === "title";
|
||||
const jump = index > 0 && !store.continues(index);
|
||||
const jump = index > 0 && !store.continuesFrom(props.p, parent);
|
||||
// Its children open to the right: the picked one's row is marked as showing; other forks' rows as forked.
|
||||
const kid = t.kids[t.pick];
|
||||
const showing = kid?.ref.kind === "node" && store.continuesFrom(kid.ref, props.p) ? kid.ref.id : undefined;
|
||||
const forked = new Set(t.kids.flatMap((k, j) => (j !== t.pick && k.ref.kind === "node" && store.continuesFrom(k.ref, props.p) ? [k.ref.id] : [])));
|
||||
return (
|
||||
<article
|
||||
class={`pane${top ? " root" : ""}${page && !top ? " doc" : ""}${jump ? " jumped" : ""}${n.kind === "note" ? " note-pane" : ""}${store.preview ? " preview" : ""}`}
|
||||
data-pane={id}
|
||||
data-pane-index={index}
|
||||
style={{ left: `calc(${index} * var(--spine))` }}
|
||||
{...paneAttrs(props, id)}
|
||||
>
|
||||
<div class="spine" data-spine={index} title={label(snap, id)}>
|
||||
<span>{label(snap, id)}</span>
|
||||
</div>
|
||||
<div class="pane-scroll">
|
||||
<ForkNote of={props.forkOf} />
|
||||
{page ? (
|
||||
<TopMatter id={id} />
|
||||
) : (
|
||||
@@ -80,7 +115,7 @@ function NodePane({ id, index, showing, active }: PaneProps & { id: NodeId }) {
|
||||
{kids.length > 0 && (
|
||||
<ul class="outline rows">
|
||||
{kids.map((k) => (
|
||||
<PaneRow key={k} id={k} showing={k === showing} active={active} />
|
||||
<PaneRow key={k} id={k} showing={k === showing} forked={forked.has(k)} active={active} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
@@ -93,26 +128,29 @@ function NodePane({ id, index, showing, active }: PaneProps & { id: NodeId }) {
|
||||
);
|
||||
}
|
||||
|
||||
function WikiPane({ p, index }: PaneProps) {
|
||||
function WikiPane(props: PaneProps) {
|
||||
const { p, index } = props;
|
||||
if (p.kind !== "wiki") return null;
|
||||
const a = article(p.title, p.lang);
|
||||
const sec = p.sec && a.state === "ready" ? a.value.sections.find((x) => x.id === p.sec) : undefined;
|
||||
const title = sec ? `${sec.heading} · ${p.title}` : a.state === "ready" ? a.value.title : p.title;
|
||||
return (
|
||||
<article class={`pane wiki-pane${p.from ? " jumped" : ""}`} data-pane={`w:${p.title}${p.sec ? `#${p.sec}` : ""}`} data-pane-index={index} style={{ left: `calc(${index} * var(--spine))` }}>
|
||||
<article class={`pane wiki-pane${p.from ? " jumped" : ""}`} {...paneAttrs(props, `w:${p.title}${p.sec ? `#${p.sec}` : ""}`)}>
|
||||
<div class="spine" data-spine={index} title={`Wikipedia: ${title}`}>
|
||||
<span>
|
||||
<b class="wmark">W</b> {title}
|
||||
</span>
|
||||
</div>
|
||||
<div class="pane-scroll">
|
||||
<WikiView host={`p${index}`} />
|
||||
<ForkNote of={props.forkOf} />
|
||||
{/* On the focused branch an article pane is named by its column; off it, by its place in the tree. */}
|
||||
<WikiView host={props.off ? `f${props.t.id}` : `p${index}`} />
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function PaneRow({ id, showing, active }: { id: NodeId; showing: boolean; active: boolean }) {
|
||||
function PaneRow({ id, showing, forked, active }: { id: NodeId; showing: boolean; forked: boolean; active: boolean }) {
|
||||
const snap = store.snap;
|
||||
const n = snap.nodes[id];
|
||||
const open = store.isOpen(id);
|
||||
@@ -122,7 +160,7 @@ function PaneRow({ id, showing, active }: { id: NodeId; showing: boolean; active
|
||||
// While its pane is showing, the title is edited at the head of that pane instead.
|
||||
const editing = !showing && store.edit?.node === id && store.edit.field === "title";
|
||||
return (
|
||||
<li class={`node d${Math.min(n.depth - (snap.library ? 1 : 0), 6)}${open ? " open" : ""}${focused ? " focused" : ""}${showing ? " showing" : ""}${st.up || st.down ? " stale" : ""}`} data-node={id}>
|
||||
<li class={`node d${Math.min(n.depth - (snap.library ? 1 : 0), 6)}${open ? " open" : ""}${focused ? " focused" : ""}${showing ? " showing" : ""}${forked ? " forked" : ""}${st.up || st.down ? " stale" : ""}`} data-node={id}>
|
||||
<Row id={id} open={open} leaf={leaf} editing={editing} />
|
||||
</li>
|
||||
);
|
||||
@@ -145,28 +183,57 @@ const setAttr = (el: HTMLElement | undefined, name: string, on: boolean) => {
|
||||
if (el && el.hasAttribute(name) !== on) on ? el.setAttribute(name, "") : el.removeAttribute(name);
|
||||
};
|
||||
|
||||
/** The least height a fork's row gets, on any window; below it the rows scroll. */
|
||||
const ROW_FLOOR = 220;
|
||||
/** Rows share the strip's height equally down to a third of it each (never below ROW_FLOOR); past that the stack of rows scrolls. */
|
||||
const rowMin = (h: number) => Math.max(ROW_FLOOR, Math.floor(h / 3));
|
||||
/** Whether forks can be drawn as rows: room for two rows, and for a fork's pane beside the pane it came from. */
|
||||
const roomy = (w: number, h: number, pane: number) => h >= 2 * ROW_FLOOR && w >= 2 * pane;
|
||||
|
||||
const kidsKey = (t: PaneNode) => `${t.pick}:${t.kids.map((k) => refKey(k.ref)).join(",")}`;
|
||||
|
||||
/** The panes drawn, by their id in the tree. */
|
||||
const paneEls = (el: HTMLElement) => {
|
||||
const m = new Map<number, HTMLElement>();
|
||||
for (const e of el.querySelectorAll<HTMLElement>(".pane[data-tid]")) m.set(Number(e.dataset.tid), e);
|
||||
return m;
|
||||
};
|
||||
|
||||
export function Panes() {
|
||||
store.syncTrail();
|
||||
const trail = store.trail;
|
||||
const tree = store.tree;
|
||||
const strip = useRef<HTMLDivElement>(null);
|
||||
const followed = useRef("");
|
||||
const [room, setRoom] = useState(true);
|
||||
// Forks are drawn as rows when there is room; otherwise only the focused branch is.
|
||||
const rows = room && store.hasForks();
|
||||
|
||||
/**
|
||||
* Mark how far each pane is covered by the next. Any overlap gives the upper pane a shadow edge
|
||||
* (data-over); once too little of the pane is left to read its own heading, it shows as a spine
|
||||
* with its title (data-covered).
|
||||
* with its title (data-covered). A pane's forks all start at the same column.
|
||||
*/
|
||||
const measure = () => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
const panes = Array.from(el.children) as HTMLElement[];
|
||||
if (!panes.length) return;
|
||||
const w = panes[0].offsetWidth;
|
||||
const lefts = panes.map((p) => p.getBoundingClientRect().left);
|
||||
for (let i = 0; i < panes.length; i++) {
|
||||
const visible = i + 1 < panes.length ? lefts[i + 1] - lefts[i] : w;
|
||||
setAttr(panes[i], "data-covered", visible < w * 0.4);
|
||||
setAttr(panes[i + 1], "data-over", visible < w - 1);
|
||||
const t = store.tree;
|
||||
if (!el || !t) return;
|
||||
const els = paneEls(el);
|
||||
const first = els.get(t.id);
|
||||
if (!first) return;
|
||||
const w = first.offsetWidth;
|
||||
const marks: [HTMLElement, number, HTMLElement[]][] = [];
|
||||
const visit = (n: PaneNode) => {
|
||||
const e = els.get(n.id);
|
||||
if (!e) return;
|
||||
const kids = n.kids.flatMap((k) => els.get(k.id) ?? []);
|
||||
const next = els.get(n.kids[n.pick]?.id) ?? kids[0];
|
||||
marks.push([e, next ? next.getBoundingClientRect().left - e.getBoundingClientRect().left : w, kids]);
|
||||
n.kids.forEach(visit);
|
||||
};
|
||||
visit(t);
|
||||
for (const [e, visible, kids] of marks) {
|
||||
setAttr(e, "data-covered", visible < w * 0.4);
|
||||
for (const k of kids) setAttr(k, "data-over", visible < w - 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -174,17 +241,20 @@ export function Panes() {
|
||||
* Keep the focus in view. Vertically, the pane holding the focus scrolls to its focused row,
|
||||
* selection or link. Horizontally, the strip scrolls as little as it can so that pane is fully
|
||||
* visible and, when there is room, so is the pane beside it: for a row whose pane is showing,
|
||||
* that pane; otherwise the pane before.
|
||||
* that pane; otherwise the pane before. With forks, the strip also scrolls down or up as little
|
||||
* as it can to show the focused branch's row.
|
||||
*/
|
||||
const follow = () => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
const f = store.focus;
|
||||
const at = store.paneAt;
|
||||
const key = `${f.node}|${f.grain}|${f.range?.join()}|${JSON.stringify(store.aux)}|${at}|${store.trail.length}|${el.clientWidth}|${store.mode === "edit"}`;
|
||||
const nodes = store.branchNodes;
|
||||
const key = `${f.node}|${f.grain}|${f.range?.join()}|${JSON.stringify(store.aux)}|${at}|${nodes.map((n) => n.id).join(",")}|${el.clientWidth}|${el.clientHeight}|${store.mode === "edit"}`;
|
||||
if (key === followed.current) return;
|
||||
followed.current = key;
|
||||
const panes = Array.from(el.children) as HTMLElement[];
|
||||
const els = paneEls(el);
|
||||
const panes = nodes.flatMap((n) => els.get(n.id) ?? []);
|
||||
if (!panes.length) return;
|
||||
const next = store.trail[at + 1];
|
||||
const a0 = store.aux;
|
||||
@@ -203,14 +273,37 @@ export function Panes() {
|
||||
if (lo > a * (w - spine)) a = b;
|
||||
const hi = a * (w - spine);
|
||||
const target = Math.max(0, Math.min(el.scrollWidth - view, Math.min(Math.max(el.scrollLeft, lo), hi)));
|
||||
// The row the branch ends in holds every pane of the branch (a pane with forks stays at the top while its rows scroll).
|
||||
let top = el.scrollTop;
|
||||
const row = panes[panes.length - 1].closest<HTMLElement>(".fork");
|
||||
if (row) {
|
||||
const r = row.getBoundingClientRect();
|
||||
const c = el.getBoundingClientRect().top;
|
||||
if (r.top < c) top += r.top - c;
|
||||
else if (r.bottom > c + el.clientHeight) top += Math.min(r.bottom - c - el.clientHeight, r.top - c);
|
||||
}
|
||||
// Down or up to another row at once: a smooth scroll that way repaints every row's panes on each frame, which costs frames on a slow machine.
|
||||
if (Math.abs(top - el.scrollTop) > 1) el.scrollTop = top;
|
||||
if (Math.abs(target - el.scrollLeft) > 1) el.scrollTo({ left: target, behavior: reducedMotion() ? "auto" : "smooth" });
|
||||
};
|
||||
|
||||
/** The rows' sizes follow the strip's height; whether there is room for rows at all, its size and a pane's width. */
|
||||
const size = () => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
el.style.setProperty("--strip-h", `${el.clientHeight}px`);
|
||||
el.style.setProperty("--row-min", `${rowMin(el.clientHeight)}px`);
|
||||
const pane = el.querySelector<HTMLElement>(".pane")?.offsetWidth ?? 0;
|
||||
setRoom(roomy(el.clientWidth, el.clientHeight, pane));
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
follow();
|
||||
measure();
|
||||
});
|
||||
|
||||
useLayoutEffect(size, []);
|
||||
|
||||
useEffect(() => {
|
||||
const el = strip.current!;
|
||||
let frame = 0;
|
||||
@@ -218,6 +311,7 @@ export function Panes() {
|
||||
if (!frame) frame = requestAnimationFrame(() => ((frame = 0), measure()));
|
||||
};
|
||||
const onResize = () => {
|
||||
size();
|
||||
followed.current = "";
|
||||
follow();
|
||||
measure();
|
||||
@@ -233,13 +327,35 @@ export function Panes() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const onBranch = new Set(store.branchNodes.map((n) => n.id));
|
||||
/**
|
||||
* A pane and what is right of it. A plain trail is a flat run of panes, as before; to the right of
|
||||
* a pane with forks, a stack of rows, one per fork in the order they were opened, each holding
|
||||
* that fork's panes (and perhaps a stack of its own). Without room for rows, only the picked fork.
|
||||
*/
|
||||
const draw = (t: PaneNode, depth: number, parent?: PaneRef, forkOf?: [number, number]): ComponentChildren[] => {
|
||||
const off = !onBranch.has(t.id);
|
||||
const active = !off && store.paneAt === depth;
|
||||
const out: ComponentChildren[] = [
|
||||
<Pane key={t.id} t={t} p={t.ref} parent={parent} index={depth} kids={kidsKey(t)} off={off} forkOf={forkOf} active={active} aux={active ? store.aux : null} />,
|
||||
];
|
||||
if (!t.kids.length) return out;
|
||||
if (t.kids.length === 1 || !rows) return [...out, ...draw(t.kids[t.pick], depth + 1, t.ref, t.kids.length > 1 ? [t.pick, t.kids.length] : undefined)];
|
||||
out.push(
|
||||
<div key={`f${t.id}`} class="forks" style={`--leaves:${leaves(t)}`}>
|
||||
{t.kids.map((k) => (
|
||||
<div key={k.id} class={`fork${onBranch.has(k.id) ? " on" : ""}`} style={`--leaves:${leaves(k)}`}>
|
||||
{draw(k, depth + 1, t.ref)}
|
||||
</div>
|
||||
))}
|
||||
</div>,
|
||||
);
|
||||
return out;
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="strip" ref={strip}>
|
||||
{trail.map((p, i) => {
|
||||
const next = trail[i + 1];
|
||||
const showing = p.kind === "node" && next?.kind === "node" && store.continues(i + 1) ? next.id : undefined;
|
||||
return <Pane key={`${i}:${p.kind === "node" ? p.id : `${p.title}#${p.sec ?? ""}`}`} p={p} index={i} showing={showing} active={store.paneAt === i} aux={store.paneAt === i ? store.aux : null} />;
|
||||
})}
|
||||
<div class={`strip${rows ? " forked" : ""}`} ref={strip}>
|
||||
{tree && draw(tree, 0)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+16
-10
@@ -10,11 +10,12 @@
|
||||
* text ends with its attribution.
|
||||
*/
|
||||
import { h, type ComponentChildren } from "preact";
|
||||
import { useContext } from "preact/hooks";
|
||||
import type { NodeId } from "../core/model";
|
||||
import { wikiKey } from "../core/ref";
|
||||
import { clip, type Range } from "../core/text";
|
||||
import type { Block } from "./articleText";
|
||||
import { Attribution, Backlinks } from "./Links";
|
||||
import { Attribution, Backlinks, PaneCtx, useForkMark } from "./Links";
|
||||
import { NodeBody, NoteView, type VNote } from "./Node";
|
||||
import { sameAux, store, type WRow } from "./store";
|
||||
import { article, articleText, known, revisionUrl, sectionsUnder, sensesOf, summary, type Article } from "./wiki";
|
||||
@@ -26,6 +27,8 @@ interface Ctx {
|
||||
sel: { grain: string; range: Range } | null;
|
||||
/** The focused link's words, when the selection is exactly a link. */
|
||||
link: Range | null;
|
||||
/** In a pane with forks: the mark for a link whose article is open as one of them. */
|
||||
fork: ((...keys: string[]) => string) | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,10 +51,11 @@ function ArticleTextView({ host, row, sec, html, article, lang }: { host: string
|
||||
if (p.sec === sec) notes.push({ key: id, id, form: n.form ?? "note", ranges: [p.range], open: store.open.has(id), lens: n.lens });
|
||||
}
|
||||
const key = wikiKey(lang, article.title);
|
||||
const fork = useForkMark();
|
||||
for (const p of store.pending.values()) if (p.art?.key === key && p.art.sec === sec && p.range) notes.push({ key: p.key, form: p.form ?? "note", ranges: [p.range], open: true, pending: p, lens: p.lens });
|
||||
return (
|
||||
<div class="wiki-text" data-wtext={row.t === "sec" ? row.id : "head"}>
|
||||
<Blocks bs={at.blocks} c={{ text: at.text, notes, sel, link }} />
|
||||
<Blocks bs={at.blocks} c={{ text: at.text, notes, sel, link, fork }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -95,7 +99,11 @@ function APara({ b, c }: { b: Para; c: Ctx }) {
|
||||
{c.text.slice(x, y)}
|
||||
</span>
|
||||
);
|
||||
for (const m of [...run.marks].reverse()) el = h(m.tag, { key: x, ...Object.fromEntries(m.attrs), class: m.tag === "a" && c.link && meets(c.link, x, y, false) ? "wfocus" : undefined }, el);
|
||||
for (const m of [...run.marks].reverse()) {
|
||||
const attrs = Object.fromEntries(m.attrs);
|
||||
const cls = m.tag === "a" ? [c.link && meets(c.link, x, y, false) && "wfocus", c.fork && attrs["data-wiki"] && c.fork(`w:${attrs["data-wiki"]}`)].filter(Boolean).join(" ") : "";
|
||||
el = h(m.tag, { key: x, ...attrs, class: cls || undefined }, el);
|
||||
}
|
||||
out.push(el);
|
||||
}
|
||||
for (const n of notes) {
|
||||
@@ -162,6 +170,7 @@ function Problem({ message }: { message: string }) {
|
||||
|
||||
/** One article view. `host` says which (see Aux in store.ts); a pane passes its index. */
|
||||
export function WikiView({ host }: { host: string }) {
|
||||
const tid = useContext(PaneCtx);
|
||||
const h = store.wikiHost(host);
|
||||
if (!h) return null;
|
||||
const a = store.aux;
|
||||
@@ -204,11 +213,8 @@ export function WikiView({ host }: { host: string }) {
|
||||
}
|
||||
const v = art.value;
|
||||
const sec = h.sec ? v.sections.find((x) => x.id === h.sec) : undefined;
|
||||
const showing = (id: number) => {
|
||||
const i = host.startsWith("p") ? +host.slice(1) : store.paneAt;
|
||||
const next = store.trail[i + 1];
|
||||
return !!store.panes && next?.kind === "wiki" && next.title === h.title && next.sec === id;
|
||||
};
|
||||
// A section open as a pane to the right is marked: the picked child "showing", another fork "forked".
|
||||
const showing = (id: number) => (store.panes ? store.kidMark(tid, (r) => r.kind === "wiki" && r.title === h.title && r.sec === id) : undefined);
|
||||
return (
|
||||
<section class={`wiki${embedded ? " embedded" : ""}`} data-host={host}>
|
||||
<Head title={v.title} sub={sec?.heading} focused={at({ t: "head" })} />
|
||||
@@ -223,7 +229,7 @@ export function WikiView({ host }: { host: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
function Rows(props: { article: Article; host: string; lang: string; parent: number; nested: boolean; at: (r: WRow) => boolean; showing: (id: number) => boolean }) {
|
||||
function Rows(props: { article: Article; host: string; lang: string; parent: number; nested: boolean; at: (r: WRow) => boolean; showing: (id: number) => "showing" | "forked" | undefined }) {
|
||||
const { article: v, host, lang, parent, nested, at, showing } = props;
|
||||
const kids = sectionsUnder(v, parent);
|
||||
if (!kids.length) return null;
|
||||
@@ -234,7 +240,7 @@ function Rows(props: { article: Article; host: string; lang: string; parent: num
|
||||
const open = nested && store.colOpen.has(x.id);
|
||||
const leaf = !sectionsUnder(v, x.id).length;
|
||||
return (
|
||||
<li key={x.id} class={`wrow${at(row) ? " focused" : ""}${open ? " open" : ""}${showing(x.id) ? " showing" : ""}`}>
|
||||
<li key={x.id} class={`wrow${at(row) ? " focused" : ""}${open ? " open" : ""}${showing(x.id) ? ` ${showing(x.id)}` : ""}`}>
|
||||
<div class="row" data-wrow={x.id}>
|
||||
<span class="mark">{open ? "▾" : leaf && !x.html ? "·" : "▸"}</span>
|
||||
<span class="title">{x.heading}</span>
|
||||
|
||||
+13
-3
@@ -15,7 +15,9 @@ export const HELP: [string, [string, string][]][] = [
|
||||
["/", "jump to a section by name, in any document"],
|
||||
["z", "hoist: make this node the whole page (again, or h or Esc at its top, to step out)"],
|
||||
["v", "view: one column ↔ panes side by side (in panes, j k move among siblings)"],
|
||||
["q", "in panes: close the panes right of the focus (with none, the focused one); moving left never closes anything"],
|
||||
["q", "in panes: close the panes right of the one being read, every fork among them; with none, close that one, or in a fork the whole fork. Moving left never closes anything"],
|
||||
["Shift+Enter", "in panes: open a fork: what Enter opens goes in a new row beside the pane to the right instead of replacing it (Shift-, Ctrl- or Cmd-click, or a middle click, does the same). With nothing open to the right it is a plain Enter; on something already open as a fork, it focuses that fork"],
|
||||
["[ ]", "in panes: the fork above / below (back where you were in it, or its pane nearest your column)"],
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -342,10 +344,12 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
store.aux = { kind: "wiki", host: store.panes ? `p${store.paneAt}` : "col", row: { t: "head" } };
|
||||
}
|
||||
// An Enter after a Tab that is waiting for its article to arrive waits with it.
|
||||
if (store.aux && store.holdKey(k)) return done();
|
||||
if (store.aux && store.holdKey(k, e.shiftKey)) return done();
|
||||
// Shift+Enter opens a fork: whatever Enter opens, it opens beside what is there.
|
||||
const fork = k === "Enter" && e.shiftKey;
|
||||
// Words selected in an article's text take the same keys as words of a node.
|
||||
if (store.aux && !store.inArticleText) {
|
||||
if (auxKey(k, e.shiftKey) || commonKey(k, hooks)) return done();
|
||||
if (store.withFork(fork, () => auxKey(k, e.shiftKey)) || commonKey(k, hooks)) return done();
|
||||
const why = store.aux.kind === "wiki" ? store.articleRefuses(k, false) : null;
|
||||
if (why) (store.say(why), done());
|
||||
return;
|
||||
@@ -388,9 +392,11 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
break;
|
||||
case "Enter":
|
||||
case " ":
|
||||
store.withFork(fork, () => {
|
||||
if (selecting) store.enterOrExpand();
|
||||
else if (store.snap.nodes[store.focus.node]?.kind === "note" && store.targetOf(store.focus.node)) store.followOwn();
|
||||
else store.toggle();
|
||||
});
|
||||
break;
|
||||
case "w":
|
||||
store.openPicker();
|
||||
@@ -492,6 +498,10 @@ function commonKey(k: string, hooks: KeyHooks): boolean {
|
||||
case "q":
|
||||
if (store.panes) store.closePane();
|
||||
return true;
|
||||
case "[":
|
||||
case "]":
|
||||
store.focusFork(k === "[" ? -1 : 1);
|
||||
return true;
|
||||
case "v":
|
||||
store.cycleView();
|
||||
return true;
|
||||
|
||||
+272
-59
@@ -36,6 +36,7 @@ import { remoteLLM } from "./remote";
|
||||
import { Session } from "./session";
|
||||
import { refreshAfterCalls } from "./usage";
|
||||
import { Linker, type AutoMode, type JobState, type Sugg } from "./linker";
|
||||
import { all, chain, closeAt, closeChild, closeRight, open as openIn, path, prune, restore as restoreTree, save as saveTree, select, sibling, trace, update, withBranch, type Tree } from "./forks";
|
||||
import { stripMarks, type Mark } from "../core/marks";
|
||||
import { SEED_SLUG } from "../core/seed";
|
||||
|
||||
@@ -48,10 +49,10 @@ export interface Focus {
|
||||
export type Mode = "normal" | "edit" | "command" | "history" | "help" | "jump" | "docs" | "link" | "review";
|
||||
|
||||
/**
|
||||
* A pane of the panes view. The strip is a trail: it starts with the path down from the top node,
|
||||
* and a link followed from a pane opens its target in the next pane, so it may hold another
|
||||
* document's node, a Wikipedia article or a section of one. `from` is where a jump was made from,
|
||||
* which h returns to.
|
||||
* A pane of the panes view. The panes are a tree of forks (forks.ts) whose focused branch is the
|
||||
* trail: it starts with the path down from the top node, and a link followed from a pane opens its
|
||||
* target in the next pane, so it may hold another document's node, a Wikipedia article or a section
|
||||
* of one. `from` is where a jump was made from, which h returns to.
|
||||
*/
|
||||
export type PaneRef =
|
||||
| { kind: "node"; id: NodeId; from?: Back }
|
||||
@@ -61,6 +62,17 @@ export interface Back {
|
||||
aux: Aux | null;
|
||||
pane: number;
|
||||
}
|
||||
/** A pane in the tree of forks; `seen` is where the reader was when they last left its fork. */
|
||||
export type Pane = Tree<PaneRef, Back>;
|
||||
/** Whether two panes show the same thing (a node, or an article or one of its sections). */
|
||||
export const sameRef = (a: PaneRef, b: PaneRef): boolean =>
|
||||
a.kind === b.kind && (a.kind === "node" ? a.id === (b as { id: NodeId }).id : a.title === (b as { title: string }).title && a.sec === (b as { sec?: number }).sec);
|
||||
/** What a pane shows, as a key: `n:<node id>`, or `w:<title>` with `#<section>`. A link's target has the same key as the pane it opens. */
|
||||
export const refKey = (p: PaneRef): string => (p.kind === "node" ? `n:${p.id}` : `w:${p.title}${p.sec !== undefined ? `#${p.sec}` : ""}`);
|
||||
const isPaneRef = (r: unknown): r is PaneRef => {
|
||||
const o = r as Record<string, unknown> | null;
|
||||
return !!o && typeof o === "object" && ((o.kind === "node" && typeof o.id === "string") || (o.kind === "wiki" && typeof o.title === "string" && typeof o.lang === "string"));
|
||||
};
|
||||
/** A row of a Wikipedia view: its head (the lead), a section, a sense of a disambiguation page, a "Mentioned in" entry. */
|
||||
export type WRow = { t: "head" } | { t: "sec"; id: number } | { t: "sense"; i: number } | { t: "back"; i: number };
|
||||
/**
|
||||
@@ -232,9 +244,28 @@ class Store {
|
||||
/** Replicas of pre-library documents whose edits never reached the server. */
|
||||
oldReplicas: OldReplica[] = [];
|
||||
|
||||
/** The panes, left to right, and which one holds the focus. */
|
||||
trail: PaneRef[] = [];
|
||||
/** The panes as a tree of forks; its focused branch is `trail`, and `paneAt` is the pane on it that holds the focus. */
|
||||
tree: Pane | null = null;
|
||||
paneAt = 0;
|
||||
/** Set while a modified open (Shift+Enter, Shift-, Ctrl- or middle-click) runs: it opens a fork beside what is there. */
|
||||
forking = false;
|
||||
private toldForks = false;
|
||||
private memo: { tree: Pane | null; nodes: Pane[]; trail: PaneRef[]; index?: Map<number, { node: Pane; depth: number }>; ids?: Set<NodeId> } = { tree: null, nodes: [], trail: [] };
|
||||
private get branch() {
|
||||
if (this.memo.tree !== this.tree) {
|
||||
const nodes = path(this.tree);
|
||||
this.memo = { tree: this.tree, nodes, trail: nodes.map((n) => n.ref) };
|
||||
}
|
||||
return this.memo;
|
||||
}
|
||||
/** The focused branch: the panes the keys move along, left to right. */
|
||||
get trail(): PaneRef[] {
|
||||
return this.branch.trail;
|
||||
}
|
||||
/** The focused branch as nodes of the tree. */
|
||||
get branchNodes(): Pane[] {
|
||||
return this.branch.nodes;
|
||||
}
|
||||
aux: Aux | null = null;
|
||||
colWiki: ColWiki | null = null;
|
||||
/** Sections of the column's article page that are open. */
|
||||
@@ -398,58 +429,219 @@ class Store {
|
||||
|
||||
/** Whether pane i continues the one before it (a section opened from its row) rather than being a jump. */
|
||||
continues(i: number): boolean {
|
||||
const p = this.trail[i];
|
||||
const q = this.trail[i - 1];
|
||||
return this.continuesFrom(this.trail[i], this.trail[i - 1]);
|
||||
}
|
||||
/** Whether pane p continues pane q, the one it was opened from. */
|
||||
continuesFrom(p: PaneRef | undefined, q: PaneRef | undefined): boolean {
|
||||
if (!p || !q || p.from) return false;
|
||||
if (p.kind === "node") return q.kind === "node" && this.snap.nodes[p.id]?.parent === q.id && this.snap.nodes[p.id].kind === "section";
|
||||
return p.sec !== undefined && (q.kind === "wiki" ? q.title === p.title : this.targetOf(q.id)?.kind === "wiki");
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether pane i holds a focus: its node's text (a selection, a note in it), one of its rows, or
|
||||
* its head when it is not a continuation (a continuation's node is focused as the row it was
|
||||
* opened from, in the pane before).
|
||||
*/
|
||||
/** Pane i of the focused branch holds a focus (see holdsIn). */
|
||||
private holds(i: number, f: Focus): boolean {
|
||||
const p = this.trail[i];
|
||||
return this.holdsIn(this.trail[i], this.trail[i - 1], i === 0, `p${i}`, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a pane (p, opened from q; host: how its article is named) holds a focus: its node's
|
||||
* text (a selection, a note in it), one of its rows, or its head when it is not a continuation (a
|
||||
* continuation's node is focused as the row it was opened from, in the pane before).
|
||||
*/
|
||||
private holdsIn(p: PaneRef | undefined, q: PaneRef | undefined, first: boolean, host: string, f: Focus): boolean {
|
||||
const s = this.snap;
|
||||
const n = s.nodes[f.node];
|
||||
// An annotation is held by the pane showing its article.
|
||||
if (p && n && inArticles(s, f.node)) return this.shows(p.kind === "wiki" ? `p${i}` : `n${p.id}`, f.node);
|
||||
if (p && n && inArticles(s, f.node)) return this.shows(p.kind === "wiki" ? host : `n${p.id}`, f.node);
|
||||
if (!p || p.kind !== "node" || !n) return false;
|
||||
if (f.grain !== "node" || n.kind === "note") return ownerSection(s, f.node) === p.id || f.node === p.id;
|
||||
if (f.node === p.id) return i === 0 || !this.continues(i);
|
||||
if (f.node === p.id) return first || !this.continuesFrom(p, q);
|
||||
return n.parent === p.id;
|
||||
}
|
||||
|
||||
/** A pane off the focused branch that holds a focus: the tree with it on the branch, and its column. */
|
||||
private forkHolding(f: Focus): { tree: Pane; depth: number } | null {
|
||||
const t = this.tree;
|
||||
if (!t) return null;
|
||||
const on = new Set(this.branchNodes.map((n) => n.id));
|
||||
const find = (n: Pane, q: PaneRef | undefined, d: number): { id: number; depth: number } | null => {
|
||||
if (!on.has(n.id) && this.holdsIn(n.ref, q, d === 0, `f${n.id}`, f)) return { id: n.id, depth: d };
|
||||
for (const k of n.kids) {
|
||||
const hit = find(k, n.ref, d + 1);
|
||||
if (hit) return hit;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const hit = find(t, undefined, 0);
|
||||
return hit ? { tree: select(t, hit.id)!, depth: hit.depth } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the tree. When the focused branch leaves a fork that stays open, the fork remembers
|
||||
* where the reader was in it, for [ and ] to come back to.
|
||||
*/
|
||||
private setTree(next: Pane | null, remember = true) {
|
||||
const old = this.branchNodes;
|
||||
if (next && remember && old.length) {
|
||||
const now = path(next);
|
||||
const d = old.findIndex((n, k) => now[k]?.id !== n.id);
|
||||
if (d > 0 && trace(next, old[d].id)) {
|
||||
const here = this.backHere();
|
||||
next = update(next, old[d].id, (n) => ({ ...n, seen: here }));
|
||||
}
|
||||
}
|
||||
this.tree = next;
|
||||
}
|
||||
|
||||
/** The panes as a plain trail down to the focus (open sections on the way). */
|
||||
private pathRefs(): PaneRef[] {
|
||||
return this.panePath().map((id) => ({ kind: "node" as const, id }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the trail holding the focus. Moving within the panes (back left, along a pane's rows)
|
||||
* leaves the trail as it is; only when the focus lands somewhere no pane holds (a jump from the
|
||||
* search box, a reload at an address) is the trail made again as the path down to it.
|
||||
* leaves the trail as it is. When the focus lands somewhere the focused branch does not hold, a
|
||||
* fork that holds it becomes the focused branch (Back to a pane in it, a click in it); failing
|
||||
* that (a jump from the search box, a reload at an address) the branch is made again as the path
|
||||
* down to it, keeping whatever forks are off that path. Panes of deleted nodes close, in any fork.
|
||||
*/
|
||||
syncTrail() {
|
||||
if (!this.panes || !this.session) return;
|
||||
const s = this.snap;
|
||||
if (!this.trail.length || this.trail[0].kind !== "node" || this.trail[0].id !== this.top) this.trail = this.panePath().map((id) => ({ kind: "node" as const, id }));
|
||||
const gone = this.trail.findIndex((p) => p.kind === "node" && !s.nodes[p.id]);
|
||||
if (gone > 0) this.trail = this.trail.slice(0, gone);
|
||||
let t = prune(this.tree, (p) => p.kind === "wiki" || !!s.nodes[p.id]);
|
||||
if (!t || t.ref.kind !== "node" || t.ref.id !== this.top) t = chain(this.pathRefs());
|
||||
if (t !== this.tree) this.setTree(t, false);
|
||||
this.paneAt = Math.max(0, Math.min(this.paneAt, this.trail.length - 1));
|
||||
if (this.aux) return;
|
||||
const n = this.trail.length;
|
||||
const order = [this.paneAt, this.paneAt + 1, this.paneAt - 1, ...Array.from({ length: n }, (_, i) => i)];
|
||||
for (const i of order) if (i >= 0 && i < n && this.holds(i, this.focus)) return void (this.paneAt = i);
|
||||
this.trail = this.panePath().map((id) => ({ kind: "node" as const, id }));
|
||||
const fork = this.forkHolding(this.focus);
|
||||
if (fork) {
|
||||
this.setTree(fork.tree, false);
|
||||
this.paneAt = fork.depth;
|
||||
return;
|
||||
}
|
||||
this.setTree(withBranch(this.tree, this.pathRefs(), sameRef), false);
|
||||
const at = this.trail.findIndex((_, i) => this.holds(i, this.focus));
|
||||
this.paneAt = at >= 0 ? at : this.trail.length - 1;
|
||||
}
|
||||
|
||||
/** Open something in the pane after pane i: what was to the right of it goes, unless it is already there. */
|
||||
openPane(i: number, ref: PaneRef) {
|
||||
const next = this.trail[i + 1];
|
||||
const same = next && next.kind === ref.kind && (next.kind === "node" ? next.id === (ref as { id: NodeId }).id : next.title === (ref as { title: string }).title && next.sec === (ref as { sec?: number }).sec);
|
||||
if (!same) this.trail = [...this.trail.slice(0, i + 1), ref];
|
||||
/**
|
||||
* Open something to the right of pane i. If it is already open there, as any fork, that fork is
|
||||
* focused. Otherwise a plain open replaces what was to the right; a fork (`forking`) opens it
|
||||
* beside that, as a new row below. Returns the pane it is in.
|
||||
*/
|
||||
openPane(i: number, ref: PaneRef): number {
|
||||
this.setTree(this.tree ? openIn(this.tree, i, ref, this.forking, sameRef) : chain([ref]));
|
||||
this.saveView();
|
||||
this.emit();
|
||||
return Math.min(i + 1, this.trail.length - 1);
|
||||
}
|
||||
|
||||
/** Close the pane that shows this node to the right of pane i (whichever fork it is). */
|
||||
closeRow(i: number, id: NodeId) {
|
||||
if (!this.tree) return;
|
||||
this.setTree(closeChild(this.tree, i, { kind: "node", id }, sameRef));
|
||||
this.saveView();
|
||||
this.emit();
|
||||
}
|
||||
|
||||
/** Run an open with or without a fork. In the column a fork is a plain open, and the status line says so once. */
|
||||
withFork<T>(fork: boolean, fn: () => T): T {
|
||||
if (fork && !this.panes && !this.toldForks) {
|
||||
this.toldForks = true;
|
||||
this.say("Forks (Shift+Enter, Shift- or Ctrl-click) open side by side in the panes view; in one column this opens as usual.");
|
||||
}
|
||||
const was = this.forking;
|
||||
this.forking = fork && this.panes;
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
this.forking = was;
|
||||
}
|
||||
}
|
||||
|
||||
/** The tree's panes by id, with their columns. */
|
||||
forkNode(id: number): { node: Pane; depth: number } | undefined {
|
||||
const m = this.branch;
|
||||
if (!m.index) m.index = new Map(all(this.tree).map((x) => [x.node.id, x]));
|
||||
return m.index.get(id);
|
||||
}
|
||||
|
||||
/** Whether any pane in the tree shows this node. */
|
||||
private paneShows(id: NodeId): boolean {
|
||||
const m = this.branch;
|
||||
if (!m.ids) m.ids = new Set(all(this.tree).flatMap((x) => (x.node.ref.kind === "node" ? [x.node.ref.id] : [])));
|
||||
return m.ids.has(id);
|
||||
}
|
||||
|
||||
/** Whether some pane has forks. */
|
||||
hasForks(): boolean {
|
||||
return all(this.tree).some((x) => x.node.kids.length > 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a pane with forks: its children by what they show (refKey), each true if it is the picked
|
||||
* one. Null for a pane with one child or none, which marks nothing new (its row is marked as before).
|
||||
*/
|
||||
forkMarks(tid: number | undefined): Map<string, boolean> | null {
|
||||
const n = tid === undefined ? undefined : this.forkNode(tid)?.node;
|
||||
if (!n || n.kids.length < 2) return null;
|
||||
return new Map(n.kids.map((k, j) => [refKey(k.ref), j === n.pick]));
|
||||
}
|
||||
|
||||
/** A link's target by the key of the pane it opens (refKey); none for a web page or a node that is gone. */
|
||||
targetKey(r: Ref): string | undefined {
|
||||
if (r.kind === "wiki") return `w:${r.title}`;
|
||||
if (r.kind !== "node") return undefined;
|
||||
const id = resolveNode(this.snap, r);
|
||||
return id ? `n:${id}` : undefined;
|
||||
}
|
||||
|
||||
/** How a child is marked in the pane it was opened from: "showing" (the picked child), "forked" (another fork), or not open. */
|
||||
kidMark(tid: number | undefined, match: (r: PaneRef) => boolean): "showing" | "forked" | undefined {
|
||||
const n = tid === undefined ? undefined : this.forkNode(tid)?.node;
|
||||
const k = n ? n.kids.findIndex((c) => match(c.ref)) : -1;
|
||||
return k < 0 ? undefined : k === n!.pick ? "showing" : "forked";
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the focus on pane c of the focused branch: on its node (for a continuation, that is the row
|
||||
* it was opened from, in the pane before), or on an article's head.
|
||||
*/
|
||||
land(c: number) {
|
||||
const p = this.trail[c];
|
||||
if (!p) return;
|
||||
this.paneAt = c;
|
||||
if (p.kind === "node") this.setFocus({ node: p.id, grain: "node" });
|
||||
else this.setFocus(this.focus, { kind: "wiki", host: `p${c}`, row: { t: "head" } });
|
||||
}
|
||||
|
||||
/** A click in a pane off the focused branch: its fork becomes the focused branch, with the focus on that pane. */
|
||||
enterFork(id: number) {
|
||||
const hit = this.forkNode(id);
|
||||
const t = this.tree && select(this.tree, id);
|
||||
if (!hit || !t || t === this.tree) return;
|
||||
this.setTree(t);
|
||||
this.land(hit.depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* [ and ]: the fork above or below, in the order the rows are drawn (the nearest pane, from the
|
||||
* branch's end leftwards, that has another fork that way). The focus goes back where it was in
|
||||
* that fork, or to its pane nearest the column the reader was in.
|
||||
*/
|
||||
focusFork(delta: number) {
|
||||
if (!this.panes) return this.say("Forks are side by side in the panes view (v); one column shows one page.");
|
||||
this.syncTrail();
|
||||
const s = this.tree && sibling(this.tree, delta);
|
||||
if (!s) return this.say(this.hasForks() ? `No fork ${delta < 0 ? "above" : "below"} this one.` : "No forks open. Shift+Enter, or a Shift- or Ctrl-click, opens one beside the pane to the right.");
|
||||
const col = this.paneAt + (this.showingFocus() ? 1 : 0);
|
||||
this.setTree(s.tree);
|
||||
const b = this.branchNodes[s.depth].seen;
|
||||
if (b && b.pane >= s.depth && b.pane < this.trail.length && this.snap.nodes[b.focus.node] && (b.aux ? this.auxValid(b.aux) : this.holds(b.pane, b.focus))) return this.restore(b);
|
||||
this.land(Math.max(s.depth, Math.min(col, this.trail.length - 1)));
|
||||
}
|
||||
|
||||
/** Whether the focus is a row whose pane is open next to it (so that pane is the one the reader is looking at). */
|
||||
@@ -459,27 +651,34 @@ class Store {
|
||||
}
|
||||
|
||||
/**
|
||||
* q: close the panes to the right of the one the reader is looking at (for a row, the pane it
|
||||
* shows); with none there, close that pane and step left.
|
||||
* q, on the pane the reader is looking at (for a row, the pane it shows): close the panes to its
|
||||
* right, every fork among them. With none there, close it and step left; in a fork, that closes
|
||||
* the whole fork (from where it branched off to its end), and the others stay.
|
||||
*/
|
||||
closePane() {
|
||||
const showing = this.showingFocus();
|
||||
const i = this.paneAt + (showing ? 1 : 0);
|
||||
if (!this.tree) return;
|
||||
if (i + 1 < this.trail.length) {
|
||||
this.trail = this.trail.slice(0, i + 1);
|
||||
this.setTree(closeRight(this.tree, i));
|
||||
this.saveView();
|
||||
return this.emit();
|
||||
}
|
||||
if (i === 0) return this.say("The first pane stays; h or Esc at its top steps out of it.");
|
||||
const from = this.trail[i].from;
|
||||
this.trail = this.trail.slice(0, i);
|
||||
// The nearest pane to the left with forks: the fork the reader is in starts right of it.
|
||||
const nodes = this.branchNodes;
|
||||
let j = i - 1;
|
||||
while (j >= 0 && nodes[j].kids.length < 2) j--;
|
||||
const k = j >= 0 ? j + 1 : i;
|
||||
if (k === 0) return this.say("The first pane stays; h or Esc at its top steps out of it.");
|
||||
const from = this.trail[k].from;
|
||||
this.setTree(closeAt(this.tree, k));
|
||||
this.saveView();
|
||||
if (showing) return this.emit();
|
||||
this.paneAt = i - 1;
|
||||
if (from && from.pane < i) return this.restore(from);
|
||||
const p = this.trail[i - 1];
|
||||
if (showing && k === i) return this.emit();
|
||||
this.paneAt = k - 1;
|
||||
if (from && from.pane < k) return this.restore(from);
|
||||
const p = this.trail[k - 1];
|
||||
if (p.kind === "node") this.setFocus({ node: p.id, grain: "node" });
|
||||
else this.setFocus(this.focus, { kind: "wiki", host: `p${i - 1}`, row: { t: "head" } });
|
||||
else this.setFocus(this.focus, { kind: "wiki", host: `p${k - 1}`, row: { t: "head" } });
|
||||
}
|
||||
|
||||
/** Go back to where a jump was made from. */
|
||||
@@ -520,7 +719,7 @@ class Store {
|
||||
* top, a pane's node), not under every open node, which would fill the page with lists.
|
||||
*/
|
||||
relatedShown(id: NodeId): boolean {
|
||||
if (this.panes) return this.trail.some((p) => p.kind === "node" && p.id === id);
|
||||
if (this.panes) return this.paneShows(id);
|
||||
return id === this.focus.node || id === this.top;
|
||||
}
|
||||
|
||||
@@ -567,14 +766,18 @@ class Store {
|
||||
if (a.kind !== "wiki") return !!this.snap.nodes[a.of];
|
||||
if (a.host === "col") return !!this.colWiki;
|
||||
if (a.host.startsWith("p")) return this.trail[+a.host.slice(1)]?.kind === "wiki";
|
||||
if (a.host.startsWith("f")) return false;
|
||||
return !!this.snap.nodes[a.host.slice(1) as NodeId];
|
||||
}
|
||||
|
||||
/** The article a Wikipedia host shows, and how. */
|
||||
/**
|
||||
* The article a Wikipedia host shows, and how. `p<i>` is the article pane at column i of the
|
||||
* focused branch, `f<id>` an article pane off it (by its id in the tree of forks).
|
||||
*/
|
||||
wikiHost(host: string): { title: string; lang: string; sec: number; embedded?: NodeId; nested?: boolean; mentions?: boolean } | null {
|
||||
if (host === "col") return this.colWiki ? { title: this.colWiki.title, lang: this.colWiki.lang, sec: 0, nested: true, mentions: true } : null;
|
||||
if (host.startsWith("p")) {
|
||||
const p = this.trail[+host.slice(1)];
|
||||
if (host.startsWith("p") || host.startsWith("f")) {
|
||||
const p = host.startsWith("p") ? this.trail[+host.slice(1)] : this.forkNode(+host.slice(1))?.node.ref;
|
||||
return p?.kind === "wiki" ? { title: p.title, lang: p.lang, sec: p.sec ?? 0, mentions: p.sec === undefined } : null;
|
||||
}
|
||||
const id = host.slice(1) as NodeId;
|
||||
@@ -627,8 +830,7 @@ class Store {
|
||||
openCommentary(note: NodeId) {
|
||||
if (this.panes) {
|
||||
const from = this.backHere();
|
||||
this.openPane(this.paneAt, { kind: "node", id: note, from });
|
||||
this.paneAt = this.trail.length - 1;
|
||||
this.paneAt = this.openPane(this.paneAt, { kind: "node", id: note, from });
|
||||
return this.setFocus({ node: note, grain: "node" });
|
||||
}
|
||||
this.colWiki = null;
|
||||
@@ -703,8 +905,7 @@ class Store {
|
||||
if (!id) return this.say(`The node this links to is gone${r.path?.length ? ` (it was “${r.path.join(" › ")}” in ${r.doc ?? "this document"})` : ""}, and nothing at its old place was found.`);
|
||||
if (this.panes) {
|
||||
const from = this.backHere();
|
||||
this.openPane(this.paneAt, { kind: "node", id, from });
|
||||
this.paneAt = this.trail.length - 1;
|
||||
this.paneAt = this.openPane(this.paneAt, { kind: "node", id, from });
|
||||
// Not reveal: that would unhoist, and the trail starts at the top node. A jump pane can show anything.
|
||||
for (const a of ancestors(this.snap, id)) this.open.add(a);
|
||||
this.setFocus({ node: id, grain: "node" });
|
||||
@@ -716,8 +917,7 @@ class Store {
|
||||
}
|
||||
if (this.panes) {
|
||||
const from = this.backHere();
|
||||
this.openPane(this.paneAt, { kind: "wiki", title: r.title, lang: r.lang, from });
|
||||
this.paneAt = this.trail.length - 1;
|
||||
this.paneAt = this.openPane(this.paneAt, { kind: "wiki", title: r.title, lang: r.lang, from });
|
||||
return this.setFocus(this.focus, { kind: "wiki", host: `p${this.paneAt}`, row: { t: "head" } });
|
||||
}
|
||||
this.openColWiki(r.title, r.lang, true);
|
||||
@@ -948,17 +1148,20 @@ class Store {
|
||||
}
|
||||
private restoreView() {
|
||||
const s = this.doc.snap();
|
||||
const v = lsGet<{ open: NodeId[]; focus: Focus | null; hoist: NodeId | null; trail?: PaneRef[]; paneAt?: number }>(this.viewKey(), { open: [], focus: null, hoist: null });
|
||||
const v = lsGet<{ open: NodeId[]; focus: Focus | null; hoist: NodeId | null; forks?: unknown; trail?: PaneRef[]; paneAt?: number }>(this.viewKey(), { open: [], focus: null, hoist: null });
|
||||
this.open = new Set(v.open.filter((id) => s.nodes[id]));
|
||||
this.hoist = v.hoist && s.nodes[v.hoist] ? v.hoist : null;
|
||||
this.focus = v.focus && s.nodes[v.focus.node] ? v.focus : { node: this.top, grain: "node" };
|
||||
this.trail = (v.trail ?? []).filter((p) => p.kind === "wiki" || s.nodes[p.id]);
|
||||
// The tree of forks; a view saved before there were forks has only its trail, which loads as one branch.
|
||||
this.tree = prune(restoreTree<PaneRef, Back>(v.forks, v.trail, isPaneRef), (p) => p.kind === "wiki" || !!s.nodes[p.id]);
|
||||
this.paneAt = Math.min(v.paneAt ?? 0, Math.max(0, this.trail.length - 1));
|
||||
this.aux = null;
|
||||
this.repairView();
|
||||
}
|
||||
saveView() {
|
||||
lsSet(this.viewKey(), { open: [...this.open], focus: this.focus, hoist: this.hoist, trail: this.trail.map((p) => ({ ...p, from: undefined })), paneAt: this.paneAt });
|
||||
const bare = (p: PaneRef): PaneRef => ({ ...p, from: undefined });
|
||||
// The trail too, for a build from before forks.
|
||||
lsSet(this.viewKey(), { open: [...this.open], focus: this.focus, hoist: this.hoist, forks: saveTree(this.tree, bare), trail: this.trail.map(bare), paneAt: this.paneAt });
|
||||
}
|
||||
/** Keep focus on something that exists and is on screen. */
|
||||
private repairView() {
|
||||
@@ -1049,8 +1252,13 @@ class Store {
|
||||
if (this.panes && s.nodes[found.node].kind === "section") this.open.add(found.node);
|
||||
this.focus = { node: found.node, grain: "node" };
|
||||
this.aux = null;
|
||||
// A pane in another fork that shows it brings that fork onto the branch.
|
||||
const at = this.trail.findIndex((p) => p.kind === "node" && p.id === found.node);
|
||||
if (this.panes && at < 0) this.trail = this.panePath().map((id) => ({ kind: "node" as const, id }));
|
||||
const fork = at < 0 && this.panes ? all(this.tree).find((x) => x.node.ref.kind === "node" && x.node.ref.id === found.node) : undefined;
|
||||
if (fork && this.tree) {
|
||||
this.setTree(select(this.tree, fork.node.id), false);
|
||||
this.paneAt = fork.depth;
|
||||
} else if (this.panes && at < 0) this.setTree(withBranch(this.tree, this.pathRefs(), sameRef), false);
|
||||
else if (at >= 0) this.paneAt = at;
|
||||
}
|
||||
this.repairView();
|
||||
@@ -1275,9 +1483,8 @@ class Store {
|
||||
if (!this.panes) return;
|
||||
this.syncTrail();
|
||||
const p = this.trail[this.paneAt];
|
||||
const next = this.trail[this.paneAt + 1];
|
||||
if (open && p?.kind === "node" && this.snap.nodes[id]?.parent === p.id && this.snap.nodes[id].kind === "section") this.openPane(this.paneAt, { kind: "node", id });
|
||||
else if (!open && next?.kind === "node" && next.id === id) this.trail = this.trail.slice(0, this.paneAt + 1);
|
||||
else if (!open && this.tree) this.setTree(closeChild(this.tree, this.paneAt, { kind: "node", id }, sameRef));
|
||||
}
|
||||
|
||||
setOpen(id: NodeId, open: boolean) {
|
||||
@@ -1294,6 +1501,13 @@ class Store {
|
||||
toggle(id = this.focus.node) {
|
||||
if (id === this.top) return this.toggleFold(id);
|
||||
if (this.listing(id)) return this.openDoc(id);
|
||||
// In panes, a row whose pane is open as a fork that is not the focused one, or any row opened as a fork, opens (focuses) its pane rather than closing it.
|
||||
if (this.panes) {
|
||||
this.syncTrail();
|
||||
const n = this.branchNodes[this.paneAt];
|
||||
const k = n ? n.kids.findIndex((c) => c.ref.kind === "node" && c.ref.id === id) : -1;
|
||||
if ((k >= 0 && k !== n.pick) || this.forking) return this.setOpen(id, true);
|
||||
}
|
||||
this.setOpen(id, !this.isOpen(id));
|
||||
}
|
||||
|
||||
@@ -2250,11 +2464,11 @@ class Store {
|
||||
held: { aux: Aux; keys: string[] } | null = null;
|
||||
|
||||
/** Whether a key on the aux focus is to wait for a held Tab. Any other key drops what was held. */
|
||||
holdKey(k: string): boolean {
|
||||
holdKey(k: string, shift = false): boolean {
|
||||
const h = this.held;
|
||||
if (!h) return false;
|
||||
if ((k === "Enter" || k === "i") && sameAux(h.aux, this.aux)) {
|
||||
h.keys.push(k);
|
||||
h.keys.push(k === "Enter" && shift ? "S-Enter" : k);
|
||||
return true;
|
||||
}
|
||||
if (k !== "Tab") this.held = null;
|
||||
@@ -2271,7 +2485,7 @@ class Store {
|
||||
this.held = null;
|
||||
if (art?.state !== "ready") return;
|
||||
for (const k of h.keys) {
|
||||
if (k === "Enter") this.inArticleText ? this.enterArticle() : this.auxActivate();
|
||||
if (k === "Enter" || k === "S-Enter") this.withFork(k === "S-Enter", () => (this.inArticleText ? this.enterArticle() : this.auxActivate()));
|
||||
else if (k === "i") this.descend();
|
||||
else this.auxTab(k === "Tab" ? 1 : -1);
|
||||
}
|
||||
@@ -2383,8 +2597,7 @@ class Store {
|
||||
else this.reveal(focus.node);
|
||||
if (this.panes) {
|
||||
const from = this.backHere();
|
||||
this.openPane(this.paneAt, { kind: "node", id: owner, from });
|
||||
this.paneAt = this.trail.length - 1;
|
||||
this.paneAt = this.openPane(this.paneAt, { kind: "node", id: owner, from });
|
||||
} else this.colWiki = null;
|
||||
this.setFocus(focus);
|
||||
this.remember(true);
|
||||
|
||||
+32
-1
@@ -347,7 +347,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: var(--rule) transparent;
|
||||
}
|
||||
.pane { position: sticky; flex: none; width: var(--pane); width: round(down, var(--pane), 1px); height: 100%; background: var(--bg); border-left: 1px solid var(--hair); }
|
||||
.pane:first-child { border-left-color: transparent; }
|
||||
.strip > .pane:first-child { border-left-color: transparent; }
|
||||
.pane[data-over] { border-left-color: var(--rule); box-shadow: -14px 0 20px -12px var(--shade); }
|
||||
.pane-scroll {
|
||||
height: 100%; overflow-x: hidden; overflow-y: auto; padding: 1.9rem var(--pane-pad) 30vh var(--spine);
|
||||
@@ -381,6 +381,37 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.node.showing > .row .mark { color: var(--fg); }
|
||||
.node.showing > .row::after { content: "→"; flex: none; margin-left: auto; padding-left: 0.8em; font-family: var(--sans); font-size: 0.72em; color: var(--dim); }
|
||||
|
||||
/*
|
||||
* Forks (src/ui/forks.ts): right of a pane with several children, one row per fork, top to bottom
|
||||
* in the order they were opened, divided by a line; a row holds its fork's panes and perhaps a
|
||||
* stack of rows of its own. Rows share the strip's height down to --row-min each (a stack needs a
|
||||
* row's worth per fork at its far right, --leaves); past that the strip scrolls down, and a pane
|
||||
* with forks stays at the top while its rows go by. Sideways the strip scrolls as one, so a fork's
|
||||
* pane is always in the column next to the pane it came from.
|
||||
*/
|
||||
.strip.forked { overflow-y: auto; overscroll-behavior-y: contain; }
|
||||
.forks { flex: none; display: flex; flex-direction: column; min-height: calc(var(--row-min) * var(--leaves)); }
|
||||
.fork { flex: 1 1 0; display: flex; min-height: calc(var(--row-min) * var(--leaves)); }
|
||||
.fork + .fork { border-top: 1px solid var(--rule); }
|
||||
/* The line is drawn on the row's panes too: a pane slid sideways over the row's edge would cover it. */
|
||||
.fork + .fork .pane { border-top: 1px solid var(--rule); }
|
||||
/* The focused fork: its first pane's left edge in the text's colour. */
|
||||
.fork.on > .pane:first-child { border-left-color: var(--fg); }
|
||||
.strip.forked .pane { height: auto; max-height: var(--strip-h); top: 0; }
|
||||
/* A row's height is only known after the rows are laid out, so a pane's own scroller is fitted to the pane rather than sized by percent. */
|
||||
.strip.forked .pane-scroll { position: absolute; inset: 0; height: auto; padding-bottom: min(30vh, calc(var(--row-min) / 2)); }
|
||||
/* What each fork was opened from, in the pane it came from: the focused fork's row, words or link marked as before, the others lightly. */
|
||||
.node.forked > .row::after, .wrow.forked > .row::after { content: "→"; flex: none; margin-left: auto; padding-left: 0.8em; font-family: var(--sans); font-size: 0.72em; color: var(--faint); }
|
||||
.wrow.forked > .row:has(.wnum)::after { margin-left: 0.5em; }
|
||||
.node.forked > .row .mark { color: var(--dim); }
|
||||
:is(.lnk, .anchor, .wiki-text a).forked { background-color: color-mix(in srgb, var(--link) 12%, transparent); }
|
||||
:is(.lnk, .anchor, .wiki-text a).forked.picked { background-color: color-mix(in srgb, var(--link) 30%, transparent); }
|
||||
:is(.backlinks, .related-list) li.forked { box-shadow: inset 2px 0 0 var(--rule); }
|
||||
:is(.backlinks, .related-list) li.forked.picked { box-shadow: inset 2px 0 0 var(--fg); }
|
||||
/* Where there is no room for rows only the focused branch is drawn; a pane that starts a fork says so. */
|
||||
.fork-note { margin: -1.1rem 0 0.9rem; font-family: var(--sans); font-size: 0.62rem; letter-spacing: 0.03em; color: var(--dim); }
|
||||
.fork-note kbd { font-size: 0.95em; }
|
||||
|
||||
/* The first pane keeps the page title, set from the left so it stays readable when the pane is partly covered. */
|
||||
.pane.root .top h1, .pane.root .byline, .pane.doc .top h1, .pane.doc .byline { text-align: left; }
|
||||
.pane.root .rows, .pane.doc .rows { margin-top: 0; padding-top: 0; border-top: 0; }
|
||||
|
||||
Reference in new issue
Block a user