The mouse and touch: a bar on a clicked sentence, ⋯ and right-click menus, a top bar
- One <Menu>: a popover by the pointer or its button, a sheet from the foot on touch; arrows, Home, End, Enter and Esc, closes on a press outside, and gives the focus back. Its items come from actions.ts and press their keys. - A single click on a sentence selects it (as before) and shows a bar over it: expand e · define d · why y · example x · challenge c · ask : | link w · ⋯, each with its key. A drag or a double click shows it for those words. In an article's text too, without link. On a phone it docks at the foot, with ×. - ⋯ on section rows, a pane's pin and ×, the page's byline and note boxes, shown when pointed at or focused, never moving the text. A stale flag, clicked, opens the node's menu, its remedies first. - Right-click on words, a row, a link, a note or a pane: its menu, Copy first; the copy key copies the app's selection too. Shift+right-click and text boxes keep the browser's menu. - The top bar: undo, redo when there is something to redo, and menu (documents, jump, history, links, layout, settings, command line, help), sticky in the column too. - Key hints in the status line, the history and documents panels and a suggestion's card are buttons. - A first visit is told, once, in the status line, that a click on a sentence offers actions and ? lists the keys. Browser tests: the bar on a click and on a drag, each ⋯ menu, right-click with Copy, Shift+right-click untouched, the menu's keys, the sticky bar, Lock naming, the phone's dock and sheet, and links, Shift-clicks, drags and peeks beside it. 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
9b73cdb15e
commit
32efa17294
9 files changed
+1269
-55
No files matched your search
@@ -0,0 +1,443 @@
|
||||
/**
|
||||
* The mouse and touch: the selection bar on a click or a drag, the ⋯ menus, the right-click menu
|
||||
* (Copy first; Shift+right-click left to the browser), the menu's keys, the top bar, key hints as
|
||||
* buttons, the phone's docked bar and sheet, the Lock naming, and that links, Shift-clicks, pane
|
||||
* drags and peeks still work with all of it. These tests work in "Tuning and temperament", which no
|
||||
* other spec uses, and undo what they write.
|
||||
*/
|
||||
import { expect, test, type Locator, type Page } from "@playwright/test";
|
||||
import { command, idle, keys, settle, state } from "./helpers";
|
||||
|
||||
const DOC = "/doc/tuning-and-temperament";
|
||||
const FIRST = "Two notes sound smooth together when their frequencies stand in a simple ratio such as 2 to 1 or 3 to 2.";
|
||||
|
||||
async function open(page: Page, path = DOC) {
|
||||
await page.goto(path);
|
||||
await page.waitForSelector("article .outline, .strip .pane");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
}
|
||||
const row = (page: Page, title: string) => page.locator(".row", { has: page.locator(`.title:text-is("${title}")`) }).first();
|
||||
/** The open section's own text (the column). */
|
||||
const bodyOf = (page: Page, title: string) => page.locator(".node.open", { has: page.locator(`:scope > .row .title:text-is("${title}")`) }).locator(":scope > .content > .body .para").first();
|
||||
const menu = (page: Page) => page.locator(".menu");
|
||||
const item = (page: Page, label: string) => page.locator(".menu .mi", { has: page.locator(`.lbl:text-is("${label}")`) });
|
||||
/** The box of some words in an element's text. */
|
||||
const wordsBox = (el: Locator, words: string) =>
|
||||
el.evaluate((root, w) => {
|
||||
const walk = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
||||
let text = "";
|
||||
const nodes: [Text, number][] = [];
|
||||
for (let n = walk.nextNode() as Text | null; n; n = walk.nextNode() as Text | null) nodes.push([n, text.length]), (text += n.data);
|
||||
const at = text.indexOf(w);
|
||||
if (at < 0) throw new Error(`no “${w}”`);
|
||||
const pos = (o: number) => {
|
||||
const [n, s] = nodes.findLast(([, s]) => s <= o)!;
|
||||
return [n, o - s] as const;
|
||||
};
|
||||
const r = document.createRange();
|
||||
r.setStart(...pos(at));
|
||||
r.setEnd(...pos(at + w.length));
|
||||
const b = r.getBoundingClientRect();
|
||||
return { x: b.x, y: b.y, w: b.width, h: b.height };
|
||||
}, words);
|
||||
|
||||
test.describe.configure({ mode: "serial" });
|
||||
test.beforeAll(async ({ request }) => {
|
||||
// A link on "simple ratio" (to the mock Wikipedia's Octopus), once.
|
||||
const s = await (await request.get("/api/tree")).json();
|
||||
const doc = s.nodes[s.root].children.find((c: string) => s.nodes[c].slug === "tuning-and-temperament");
|
||||
const sec = s.nodes[doc].children.find((c: string) => s.nodes[c].title === "Why some intervals sound smooth");
|
||||
if (s.nodes[sec].children.some((c: string) => s.nodes[c].ref)) return;
|
||||
const res = await request.post("/api/ops", { data: { author: "mouse", message: "A link for the mouse tests", ops: [{ op: "create", parent: sec, kind: "note", quote: "simple ratio", ref: { kind: "wiki", title: "Octopus", lang: "en" } }] } });
|
||||
expect(res.ok()).toBe(true);
|
||||
});
|
||||
test.beforeEach(async ({ context }) => {
|
||||
await context.route(/wikipedia\.org|wikimedia\.org/, (r) => r.abort());
|
||||
});
|
||||
test.afterEach(({ page }) => settle(page));
|
||||
|
||||
test("a single click on a sentence selects it and shows the bar by it, each item with its key; an item does what its key does; fast", async ({ page }) => {
|
||||
await open(page);
|
||||
// A newcomer is told, once, quietly, in the status line.
|
||||
await expect(page.locator(".status .firstrun")).toContainText("Click a sentence");
|
||||
await row(page, "Why some intervals sound smooth").click();
|
||||
await expect(page.locator(".status .firstrun")).toHaveCount(0);
|
||||
const para = bodyOf(page, "Why some intervals sound smooth");
|
||||
// How long the click takes to paint, as the browser measures it (only events of 16 ms or more are recorded).
|
||||
await page.evaluate(() => {
|
||||
(window as any).__clicks = [];
|
||||
new PerformanceObserver((l) => (window as any).__clicks.push(...l.getEntries().filter((e) => e.name === "click").map((e) => e.duration))).observe({ type: "event", durationThreshold: 16 } as PerformanceObserverInit);
|
||||
});
|
||||
await para.click({ position: { x: 30, y: 10 } });
|
||||
const bar = page.locator(".selbar");
|
||||
await expect(bar).toBeVisible();
|
||||
expect(await state(page, (s) => [s.focus.grain, s.selectedText()])).toEqual(["sentence", FIRST]);
|
||||
await expect(bar.locator("button .k")).toHaveText(["e", "d", "y", "x", "c", ":", "w"]);
|
||||
await expect(bar.locator("button[data-key]")).toHaveText(["expande", "defined", "whyy", "examplex", "challengec", "ask…:", "link…w"]);
|
||||
// Over the words, not on them.
|
||||
const b = (await bar.boundingBox())!;
|
||||
const sel = (await page.locator(".sel").first().boundingBox())!;
|
||||
expect(b.y + b.height).toBeLessThanOrEqual(sel.y + 1);
|
||||
// The status line's hints are buttons too.
|
||||
await expect(page.locator(".status .message .key")).toHaveCount(7);
|
||||
await page.waitForTimeout(100);
|
||||
expect(Math.max(0, ...(await page.evaluate(() => (window as any).__clicks as number[])))).toBeLessThan(150);
|
||||
// "why" does what y does: a note answering why, on these words; the bar goes.
|
||||
await bar.locator('button[data-key="y"]').click();
|
||||
await expect(bar).toHaveCount(0);
|
||||
await idle(page);
|
||||
const lens = await state(page, (s) => {
|
||||
const n = s.snap.nodes[s.focus.node];
|
||||
return n.children.map((c: string) => s.snap.nodes[c]).find((c: any) => c.kind === "note" && c.anchors[0]?.text === s.selectedText())?.lens;
|
||||
});
|
||||
expect(lens).toBe("why");
|
||||
await keys(page, "u");
|
||||
await expect.poll(() => state(page, (s) => s.snap.nodes[s.focus.node].children.filter((c: string) => s.snap.nodes[c].lens === "why").length)).toBe(0);
|
||||
// A key hint in the status line presses its key.
|
||||
await para.click({ position: { x: 30, y: 10 } });
|
||||
await page.locator(".status .message .key", { hasText: "define" }).click();
|
||||
await idle(page);
|
||||
expect(await state(page, (s) => s.snap.nodes[s.focus.node].children.some((c: string) => s.snap.nodes[c].lens === "define"))).toBe(true);
|
||||
await keys(page, "u");
|
||||
await idle(page);
|
||||
});
|
||||
|
||||
test("a drag across words shows the bar for those words; a double click, for the word", async ({ page }) => {
|
||||
await open(page);
|
||||
await row(page, "Why some intervals sound smooth").click();
|
||||
const para = bodyOf(page, "Why some intervals sound smooth");
|
||||
const w = await wordsBox(para, "their frequencies stand");
|
||||
await page.mouse.move(w.x + 1, w.y + w.h / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(w.x + w.w / 2, w.y + w.h / 2, { steps: 4 });
|
||||
await page.mouse.move(w.x + w.w - 1, w.y + w.h / 2, { steps: 4 });
|
||||
await page.mouse.up();
|
||||
await expect(page.locator(".selbar")).toBeVisible();
|
||||
expect(await state(page, (s) => [s.focus.grain, s.selectedText()])).toEqual(["word", "their frequencies stand"]);
|
||||
// The browser's own selection was taken over: nothing is left selected twice.
|
||||
expect(await page.evaluate(() => window.getSelection()?.isCollapsed)).toBe(true);
|
||||
const d = await wordsBox(para, "smooth");
|
||||
await page.mouse.dblclick(d.x + d.w / 2, d.y + d.h / 2);
|
||||
await expect(page.locator(".selbar")).toBeVisible();
|
||||
expect((await state(page, (s) => s.selectedText()))?.trim()).toBe("smooth");
|
||||
// A key moves on: the bar goes.
|
||||
await keys(page, "L");
|
||||
await expect(page.locator(".selbar")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("the ⋯ menus: a row's, the page's, a note's, a stale flag's", async ({ page }) => {
|
||||
await open(page);
|
||||
// A row's ⋯ shows when the row is pointed at; its menu is the section's, and an item does what its key does.
|
||||
const r = row(page, "The comma");
|
||||
const more = r.locator(".more");
|
||||
expect(await more.evaluate((el) => getComputedStyle(el).opacity)).toBe("0");
|
||||
await r.hover();
|
||||
await expect.poll(() => more.evaluate((el) => getComputedStyle(el).opacity)).toBe("1");
|
||||
await more.click();
|
||||
await expect(menu(page)).toBeVisible();
|
||||
await expect(page.locator(".menu .mh").first()).toHaveText("The comma");
|
||||
for (const l of ["Write more", "Edit text", "Rename", "Add a section inside", "Lock", "Delete"]) await expect(item(page, l)).toHaveCount(1);
|
||||
await expect(page.locator(".menu .choices", { hasText: "Move" })).toBeVisible();
|
||||
await item(page, "Rename").click();
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
await expect(page.locator(".title-editor")).toBeFocused();
|
||||
await keys(page, "Escape");
|
||||
// The page's ⋯, in its byline: the document's items too. Esc closes it and the focus goes back to the ⋯.
|
||||
const pageMore = page.locator(".top .byline .more");
|
||||
await page.locator(".top").hover();
|
||||
await pageMore.click();
|
||||
await expect(item(page, "Save a copy")).toHaveCount(1);
|
||||
await expect(item(page, "Export as .md")).toHaveCount(1);
|
||||
await keys(page, "Escape");
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
expect(await page.evaluate(() => (document.activeElement as HTMLElement)?.dataset.more)).toBe("page");
|
||||
// A note's ⋯: open the note on "all at once", in Overtones.
|
||||
await row(page, "Why some intervals sound smooth").click();
|
||||
await row(page, "Overtones").click();
|
||||
await page.locator(".anchor", { hasText: "all at once" }).first().click();
|
||||
const note = page.locator(".sidenote, .inset").filter({ hasText: "Touch a guitar string" }).first();
|
||||
await expect(note).toBeVisible();
|
||||
await note.hover();
|
||||
await note.locator(":scope > .more").click();
|
||||
await expect(item(page, "Change its form")).toHaveCount(1);
|
||||
await expect(item(page, "Edit text")).toHaveCount(1);
|
||||
expect(await state(page, (s) => s.snap.nodes[s.focus.node].kind)).toBe("note");
|
||||
await keys(page, "Escape");
|
||||
// A stale flag: edit a section's text with reconciling off, and its sections' rows say their parent changed; a click on the flag offers what to do.
|
||||
await command(page, "/auto off");
|
||||
await row(page, "Why some intervals sound smooth").click({ button: "right" });
|
||||
await item(page, "Edit text").click();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type(" An added sentence.");
|
||||
await keys(page, "Escape");
|
||||
const flag = row(page, "Overtones").locator(".flags");
|
||||
await expect(flag).toHaveText("parent changed");
|
||||
await flag.click();
|
||||
await expect(page.locator(".menu .mh").first()).toHaveText("Overtones · its parent changed");
|
||||
await item(page, "Accept as it stands").click();
|
||||
await expect(row(page, "Overtones").locator(".flags")).toHaveCount(0);
|
||||
await command(page, "/auto on");
|
||||
// Put it back: the edit and the acceptances, undone.
|
||||
for (let i = 0; i < 6 && (await state(page, (s) => s.snap.nodes[s.focus.node].body.includes("An added sentence") || Object.values(s.snap.nodes).some((n: any) => n.body?.includes("An added sentence")))); i++) await keys(page, "u");
|
||||
expect(await state(page, (s) => Object.values(s.snap.nodes).some((n: any) => n.body?.includes("An added sentence")))).toBe(false);
|
||||
});
|
||||
|
||||
test("a right-click: the app's menu for what it is on, Copy first where there is text; Shift+right-click is the browser's", async ({ page, context }) => {
|
||||
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
await open(page);
|
||||
await page.evaluate(() => window.addEventListener("contextmenu", (e) => ((window as any).__ctx = e.defaultPrevented)));
|
||||
await row(page, "Why some intervals sound smooth").click();
|
||||
const para = bodyOf(page, "Why some intervals sound smooth");
|
||||
await para.click({ position: { x: 30, y: 10 }, button: "right" });
|
||||
await expect(menu(page)).toBeVisible();
|
||||
expect(await page.evaluate(() => (window as any).__ctx)).toBe(true);
|
||||
expect(await state(page, (s) => s.selectedText())).toBe(FIRST);
|
||||
await expect(page.locator(".menu .mi").first().locator(".lbl")).toHaveText("Copy");
|
||||
await page.locator(".menu .mi").first().click();
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(FIRST);
|
||||
// The copy key copies the words selected too.
|
||||
await page.evaluate(() => navigator.clipboard.writeText(""));
|
||||
await page.keyboard.press("Control+c");
|
||||
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(FIRST);
|
||||
// A row: the section's menu.
|
||||
await row(page, "The comma").click({ button: "right" });
|
||||
await expect(page.locator(".menu .mh").first()).toHaveText("The comma");
|
||||
await expect(item(page, "Rename")).toHaveCount(1);
|
||||
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("The comma");
|
||||
await keys(page, "Escape");
|
||||
// A link: open it, on wikipedia.org, retarget, remove; its words are selected.
|
||||
await page.locator(".lnk", { hasText: "simple ratio" }).first().click({ button: "right" });
|
||||
for (const l of ["Copy", "Open the link", "Open on wikipedia.org", "Retarget…", "Remove the link"]) await expect(item(page, l)).toHaveCount(1);
|
||||
expect(await state(page, (s) => s.selectedText())).toBe("simple ratio");
|
||||
await keys(page, "Escape");
|
||||
// Shift+right-click: the browser's menu, not ours.
|
||||
const p = (await para.boundingBox())!;
|
||||
await page.keyboard.down("Shift");
|
||||
await page.mouse.click(p.x + 60, p.y + 10, { button: "right" });
|
||||
await page.keyboard.up("Shift");
|
||||
expect(await page.evaluate(() => (window as any).__ctx)).toBe(false);
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
// Text being typed in keeps the browser's menu.
|
||||
await keys(page, ":");
|
||||
await page.locator(".command input").click({ button: "right" });
|
||||
expect(await page.evaluate(() => (window as any).__ctx)).toBe(false);
|
||||
await keys(page, "Escape");
|
||||
});
|
||||
|
||||
test("the menu's keys: ↑ ↓ Home End move, Enter runs, Esc closes and gives the focus back; keys do not reach the page; a press outside closes it", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "j");
|
||||
const before = await state(page, (s) => s.focus.node);
|
||||
await page.locator(".docbar .tool[aria-haspopup]").click();
|
||||
await expect(menu(page)).toBeFocused();
|
||||
await keys(page, "j k");
|
||||
expect(await state(page, (s) => s.focus.node)).toBe(before);
|
||||
await expect(menu(page)).toBeVisible();
|
||||
const focused = () => page.evaluate(() => document.activeElement?.querySelector(".lbl")?.textContent ?? document.activeElement?.textContent);
|
||||
await keys(page, "ArrowDown");
|
||||
expect(await focused()).toBe("Documents…");
|
||||
await keys(page, "ArrowDown");
|
||||
expect(await focused()).toBe("Jump to a section…");
|
||||
await keys(page, "ArrowUp ArrowUp");
|
||||
expect(await focused()).toBe("Keys and help");
|
||||
await keys(page, "Home");
|
||||
expect(await focused()).toBe("Documents…");
|
||||
await keys(page, "End Enter");
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
await expect(page.locator(".help")).toBeVisible();
|
||||
await keys(page, "Escape");
|
||||
// Esc gives the focus back to what opened it.
|
||||
const r = row(page, "The comma");
|
||||
await r.hover();
|
||||
await r.locator(".more").click();
|
||||
await expect(menu(page)).toBeFocused();
|
||||
await keys(page, "Escape");
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
await expect(r.locator(".more")).toBeFocused();
|
||||
// A press outside closes it.
|
||||
await r.locator(".more").click();
|
||||
await expect(menu(page)).toBeVisible();
|
||||
await page.mouse.click(5, 400);
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
// The top bar: undo, and redo once there is something to redo.
|
||||
await expect(page.locator(".docbar .tool", { hasText: "redo" })).toHaveCount(0);
|
||||
await expect(page.locator(".docbar .tool", { hasText: "undo" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("the top bar stays at the top of the column as the page scrolls", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 500 });
|
||||
await open(page);
|
||||
await keys(page, "o");
|
||||
await page.evaluate(() => window.scrollTo(0, 700));
|
||||
await expect.poll(() => page.evaluate(() => window.scrollY)).toBeGreaterThan(400);
|
||||
const bar = (await page.locator(".docbar").boundingBox())!;
|
||||
expect(bar.y).toBeLessThanOrEqual(1);
|
||||
await expect(page.locator(".docbar .tool", { hasText: "menu" })).toBeVisible();
|
||||
await keys(page, "O");
|
||||
});
|
||||
|
||||
test("Lock: the menu, the badge, the status line and the help say lock; pin is a pane's", async ({ page }) => {
|
||||
await open(page);
|
||||
await row(page, "The comma").click({ button: "right" });
|
||||
await expect(item(page, "Lock")).toHaveAttribute("aria-checked", "false");
|
||||
await item(page, "Lock").click();
|
||||
const flags = row(page, "The comma").locator(".flags");
|
||||
await expect(flags).toHaveText("locked");
|
||||
expect(await flags.evaluate((el) => (el as HTMLElement).innerText)).toBe("LOCKED");
|
||||
await expect(page.locator(".status .message")).toContainText("Locked: the model will not rewrite this node.");
|
||||
await row(page, "The comma").click({ button: "right" });
|
||||
await expect(item(page, "Lock")).toHaveAttribute("aria-checked", "true");
|
||||
expect(await page.locator(".menu").innerText()).not.toMatch(/\bpin/i);
|
||||
await keys(page, "Escape p");
|
||||
await expect(flags).toHaveCount(0);
|
||||
await expect(page.locator(".status .message")).toContainText("Unlocked");
|
||||
await keys(page, "?");
|
||||
await expect(page.locator(".help")).toContainText("lock or unlock");
|
||||
await expect(page.locator(".help")).not.toContainText("pin or unpin: pinned nodes");
|
||||
await keys(page, "Escape");
|
||||
});
|
||||
|
||||
test.describe("panes", () => {
|
||||
test.use({ viewport: { width: 1920, height: 1080 } });
|
||||
|
||||
const paneOf = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.pane-head h2, .top h1):text-is("${title}")`) }).first();
|
||||
const trail = (page: Page) => state(page, (s) => s.trail.map((p: any) => (p.kind === "wiki" ? `W:${p.title}` : s.snap.nodes[p.id].title)));
|
||||
|
||||
test("a pane's ⋯: its node's items and the pane's own; pin from it", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "z j Enter");
|
||||
const p = paneOf(page, "Why some intervals sound smooth");
|
||||
await expect(p.locator(".pane-head h2")).toHaveText("Why some intervals sound smooth");
|
||||
await p.hover();
|
||||
await p.locator(".pane-btn.more").click();
|
||||
await expect(page.locator(".menu .mh").first()).toHaveText("Why some intervals sound smooth");
|
||||
for (const l of ["Write more", "Rename", "Pin this pane", "Close this pane", "Show as one column"]) await expect(item(page, l)).toHaveCount(1);
|
||||
await item(page, "Pin this pane").click();
|
||||
await expect(p).toHaveClass(/pinned/);
|
||||
await p.locator(".pane-btn.more").click();
|
||||
await expect(item(page, "Pin this pane")).toHaveAttribute("aria-checked", "true");
|
||||
await item(page, "Pin this pane").click();
|
||||
await expect(p).not.toHaveClass(/pinned/);
|
||||
// Right-click in the pane's empty foot: the pane's menu.
|
||||
const box = (await p.boundingBox())!;
|
||||
await page.mouse.click(box.x + box.width / 2, box.y + box.height - 40, { button: "right" });
|
||||
await expect(item(page, "Close this pane")).toHaveCount(1);
|
||||
await keys(page, "Escape");
|
||||
});
|
||||
|
||||
test("links, Shift-clicks, dragging and peeking work as before beside the bar and the ⋯", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "z j Enter");
|
||||
const sec = paneOf(page, "Why some intervals sound smooth");
|
||||
// A click on a sentence shows the bar; a click on a link opens its article beside, and shows no bar.
|
||||
await sec.locator(".pane-body .para").first().click({ position: { x: 30, y: 10 } });
|
||||
await expect(page.locator(".selbar")).toBeVisible();
|
||||
await sec.locator(".lnk", { hasText: "simple ratio" }).click();
|
||||
await expect(page.locator(".selbar")).toHaveCount(0);
|
||||
await expect.poll(() => trail(page)).toEqual(["Tuning and temperament", "Why some intervals sound smooth", "W:Octopus"]);
|
||||
// In the article: a click on a sentence selects it and shows the bar, without linking (an article's words are not linked by hand).
|
||||
const art = page.locator(".strip .pane.wiki-pane");
|
||||
await art.locator(".wiki-text .wpara").first().click({ position: { x: 40, y: 8 } });
|
||||
await expect(page.locator(".selbar")).toBeVisible();
|
||||
await expect(page.locator(".selbar button .k")).toHaveText(["e", "d", "y", "x", "c", ":"]);
|
||||
expect(await state(page, (s) => s.inArticleText)).toBe(true);
|
||||
await art.locator(".wiki-text .wpara").first().click({ position: { x: 60, y: 8 }, button: "right" });
|
||||
await expect(page.locator(".menu .mi").first().locator(".lbl")).toHaveText("Copy");
|
||||
await keys(page, "Escape");
|
||||
// A Shift-click on a row opens it in place of the pane there.
|
||||
await paneOf(page, "Tuning and temperament").locator(".row", { hasText: "The comma" }).click({ modifiers: ["Shift"] });
|
||||
await expect.poll(() => trail(page)).toEqual(["Tuning and temperament", "The comma"]);
|
||||
// Five panes in one column: a covered one peeks under the mouse; with room, a pane drags by its grip (the ⋯ beside it does not drag).
|
||||
await page.evaluate(() => localStorage.clear());
|
||||
await open(page);
|
||||
await keys(page, "z j Enter j Enter j Enter j Enter j Enter");
|
||||
const col = page.locator(".strip > .col").nth(1);
|
||||
await expect.poll(() => col.locator(":scope > .pane").count()).toBe(5);
|
||||
await expect(col).toHaveClass(/crowded/);
|
||||
const covered = col.locator(":scope > .pane[data-covered]").first();
|
||||
await expect(covered).toHaveCount(1);
|
||||
await covered.locator(".tabline").hover();
|
||||
await expect(covered).toHaveAttribute("data-peek", "");
|
||||
await page.mouse.move(5, 500);
|
||||
await page.setViewportSize({ width: 1920, height: 2000 });
|
||||
await expect.poll(() => col.getAttribute("class")).not.toContain("crowded");
|
||||
const order = () => col.locator(":scope > .pane .pane-head h2").allTextContents();
|
||||
const was = await order();
|
||||
const last = col.locator(":scope > .pane").last();
|
||||
await last.hover();
|
||||
await last.locator(".pane-btn.more").click();
|
||||
await expect(menu(page)).toBeVisible();
|
||||
await keys(page, "Escape");
|
||||
expect(await order()).toEqual(was);
|
||||
const g = (await last.locator(".grip").boundingBox())!;
|
||||
const t = (await col.locator(":scope > .pane").first().boundingBox())!;
|
||||
await page.mouse.move(g.x + g.width / 2, g.y + g.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(g.x + g.width / 2, g.y + 20, { steps: 3 });
|
||||
await page.mouse.move(g.x + g.width / 2, t.y + 8, { steps: 6 });
|
||||
await page.mouse.up();
|
||||
await expect.poll(order).toEqual([was[was.length - 1], ...was.slice(0, -1)]);
|
||||
await expect(menu(page)).toHaveCount(0);
|
||||
await expect(page.locator(".selbar")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("on a phone", () => {
|
||||
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
|
||||
|
||||
test("a tap on a sentence docks the bar at the foot, keys left out; its ⋯ and the top menu are sheets; × puts the bar away", async ({ page }) => {
|
||||
await open(page);
|
||||
expect(await page.evaluate(() => matchMedia("(hover: none)").matches)).toBe(true);
|
||||
await expect(page.locator(".status .firstrun")).toContainText("Tap a sentence");
|
||||
await row(page, "Why some intervals sound smooth").tap();
|
||||
const para = bodyOf(page, "Why some intervals sound smooth");
|
||||
const tapFirst = async () => {
|
||||
await para.scrollIntoViewIfNeeded();
|
||||
const p = (await para.boundingBox())!;
|
||||
await page.touchscreen.tap(p.x + 30, p.y + 10);
|
||||
};
|
||||
const near = (a: number, b: number) => expect(Math.abs(a - b)).toBeLessThan(2);
|
||||
await tapFirst();
|
||||
const bar = page.locator(".selbar.docked");
|
||||
await expect(bar).toBeVisible();
|
||||
expect(await state(page, (s) => s.selectedText())).toBe(FIRST);
|
||||
const b = (await bar.boundingBox())!;
|
||||
const status = (await page.locator(".status").boundingBox())!;
|
||||
near(b.width, 390);
|
||||
near(b.y + b.height, status.y);
|
||||
await expect(bar.locator(".k").first()).toBeHidden();
|
||||
// The words are not left under it.
|
||||
const sel = (await page.locator(".sel").last().boundingBox())!;
|
||||
expect(sel.y + sel.height).toBeLessThanOrEqual(b.y);
|
||||
// Its ⋯: a sheet from the foot, full width.
|
||||
await bar.locator(".bar-more").tap();
|
||||
const sheet = page.locator(".menu.sheet");
|
||||
await expect(sheet).toBeVisible();
|
||||
const s = (await sheet.boundingBox())!;
|
||||
near(s.width, 390);
|
||||
near(s.y + s.height, status.y);
|
||||
await expect(sheet.locator(".mi").first().locator(".lbl")).toHaveText("Copy");
|
||||
// A tap outside puts it away (on the status line, where a tap does nothing else).
|
||||
const outside = () => page.touchscreen.tap(150, status.y + status.height / 2);
|
||||
await outside();
|
||||
await expect(sheet).toHaveCount(0);
|
||||
// × puts the bar away and widens back to the node.
|
||||
await tapFirst();
|
||||
await expect(bar).toBeVisible();
|
||||
await bar.locator(".bar-done").tap();
|
||||
await expect(bar).toHaveCount(0);
|
||||
expect(await state(page, (s) => s.focus.grain)).toBe("node");
|
||||
// The focused row's ⋯ is there to tap (no hover on a phone); its menu is a sheet.
|
||||
const more = row(page, "Why some intervals sound smooth").locator(".more");
|
||||
await expect.poll(() => more.evaluate((el) => getComputedStyle(el).opacity)).toBe("1");
|
||||
await more.tap();
|
||||
await expect(page.locator(".menu.sheet .mh").first()).toHaveText("Why some intervals sound smooth");
|
||||
await outside();
|
||||
await expect(page.locator(".menu.sheet")).toHaveCount(0);
|
||||
// The top bar's menu, a sheet too.
|
||||
await page.locator(".docbar .tool[aria-haspopup]").tap();
|
||||
await expect(page.locator(".menu.sheet")).toBeVisible();
|
||||
await expect(item(page, "Documents…")).toHaveCount(1);
|
||||
});
|
||||
});
|
||||
+74
-50
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useLayoutEffect, useReducer, useRef, useState } from "preact/hooks";
|
||||
import { ancestors, ancestorsInDoc, docOf, label, sections, staleness, type Conflict, type NodeId } from "../core/model";
|
||||
import { verifyHistory, type Commit } from "../core/repo";
|
||||
import { clip, plain, sentences } from "../core/text";
|
||||
import { clip, plain } from "../core/text";
|
||||
import { hostOf } from "../core/ref";
|
||||
import { nodeRef } from "../core/links";
|
||||
import { HELP, handleKey } from "./keys";
|
||||
@@ -12,6 +12,7 @@ import { Panes } from "./Panes";
|
||||
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";
|
||||
|
||||
function Page() {
|
||||
if (store.colWiki) return <WikiPage />;
|
||||
@@ -98,7 +99,9 @@ function HistoryPanel({ verdict }: { verdict: string }) {
|
||||
<aside class="panel" ref={ref}>
|
||||
<div class="panel-head">
|
||||
<span>History{store.historyFilter && store.currentDoc ? ` · ${clip(store.snap.nodes[store.currentDoc]?.title ?? "", 30)}` : " · the library"}</span>
|
||||
<span class="keys">j k · Enter · r revert{store.currentDoc ? " this document" : ""} · n branch · m merge · f {store.historyFilter ? "everything" : "this document"} · v verify · Esc</span>
|
||||
<span class="keys">
|
||||
<Hints hint={["j k", ["Enter", "view"], ["r", `revert${store.currentDoc ? " this document" : ""}`], ["n", "branch"], ["m", "merge"], ["f", store.historyFilter ? "everything" : "this document"], ["v", "verify"], ["Escape", "close"]]} />
|
||||
</span>
|
||||
</div>
|
||||
{verdict && <div class="verdict">{verdict}</div>}
|
||||
{items.map((it, i) => {
|
||||
@@ -367,37 +370,41 @@ function StatusLine() {
|
||||
const st = staleness(snap, f.node);
|
||||
const path = [...ancestors(snap, f.node).reverse(), f.node].map((id) => clip(label(snap, id), 28)).join(" › ");
|
||||
const selecting = f.grain !== "node";
|
||||
const hint = store.aux
|
||||
const lensHint: Hint = [["e", `expand${store.generating ? "" : " (no model)"}`], ["d", "define"], ["y", "why"], ["x", "example"], ["c", "challenge"], [":", "ask"]];
|
||||
const sugg = selecting && store.focusedSuggestion();
|
||||
const commentary = selecting && store.commentaryAt(f.range);
|
||||
const noteHere = selecting && store.noteAt(f.range);
|
||||
const hint: Hint = store.aux
|
||||
? store.aux.kind === "wiki"
|
||||
? store.inArticleText
|
||||
? store.articleNoteHere()
|
||||
? "Enter open/enter the note · e toggle · D delete note · Tab next"
|
||||
? [["Enter", "open/enter the note"], ["e", "toggle"], ["D", "delete note"], ["Tab", "next"]]
|
||||
: store.auxLink(store.aux)
|
||||
? `Enter opens “${clip(store.auxLink(store.aux)!.title, 40)}” · e d y x c annotate · W on wikipedia.org`
|
||||
: `e expand${store.generating ? "" : " (no model)"} · d define · y why · x example · c challenge · : ask · Esc widen`
|
||||
: `Wikipedia · j k rows · l open · h back · i select words · Tab links and notes · W on wikipedia.org${store.panes ? " · q close" : ""}`
|
||||
: store.aux.kind === "target" ? "Enter opens what this is about"
|
||||
: "Enter goes to the linking note"
|
||||
? [["Enter", `opens “${clip(store.auxLink(store.aux)!.title, 40)}”`], "e d y x c annotate", ["W", "on wikipedia.org"]]
|
||||
: [...lensHint, ["Escape", "widen"]]
|
||||
: ["Wikipedia · j k rows", ["l", "open"], ["h", "back"], ["i", "select words"], ["Tab", "links and notes"], ["W", "on wikipedia.org"], ...(store.panes ? [["q", "close"] as [string, string]] : [])]
|
||||
: store.aux.kind === "target" ? [["Enter", "opens what this is about"]]
|
||||
: [["Enter", "goes to the linking note"]]
|
||||
: store.preview
|
||||
? "read-only · r revert to this · n branch from this · Esc back to now"
|
||||
: selecting && store.focusedSuggestion()
|
||||
? `suggested link → ${clip(store.focusedSuggestion()!.title, 40)} · y link · n decline · Tab next · S review all`
|
||||
? ["read-only", ["r", "revert to this"], ["n", "branch from this"], ["Escape", "back to now"]]
|
||||
: sugg
|
||||
? [`suggested link → ${clip(sugg.title, 40)}`, ["y", "link"], ["n", "decline"], ["Tab", "next"], ["S", "review all"]]
|
||||
: selecting
|
||||
? store.commentaryAt(f.range)
|
||||
? `Enter opens the note with ${store.targetOf(store.commentaryAt(f.range)!)!.kind === "wiki" ? "its article" : "what it links to"} · e shows the note here · D delete note · w retarget`
|
||||
: store.noteAt(f.range)
|
||||
? store.snap.nodes[store.noteAt(f.range)!].ref
|
||||
? `Enter open the link · w retarget · D remove${store.snap.nodes[store.noteAt(f.range)!].ref!.kind === "wiki" ? " · W on Wikipedia" : ""}`
|
||||
: "Enter open/enter · e toggle · D delete note · w link it"
|
||||
: `e expand${store.generating ? "" : " (no model)"} · d define · y why · x example · c challenge · : ask · w link`
|
||||
? commentary
|
||||
? [["Enter", `opens the note with ${store.targetOf(commentary)!.kind === "wiki" ? "its article" : "what it links to"}`], ["e", "shows the note here"], ["D", "delete note"], ["w", "retarget"]]
|
||||
: noteHere
|
||||
? store.snap.nodes[noteHere].ref
|
||||
? [["Enter", "open the link"], ["w", "retarget"], ["D", "remove"], ...(store.snap.nodes[noteHere].ref!.kind === "wiki" ? [["W", "on Wikipedia"] as [string, string]] : [])]
|
||||
: [["Enter", "open/enter"], ["e", "toggle"], ["D", "delete note"], ["w", "link it"]]
|
||||
: [...lensHint, ["w", "link"]]
|
||||
: st.up || st.down
|
||||
? `stale · ${n.pinned ? "b accept · p unlock" : "R reconcile · b accept"}`
|
||||
: "";
|
||||
? ["stale", ...((n.pinned ? [["b", "accept"], ["p", "unlock"]] : [["R", "reconcile"], ["b", "accept"]]) as [string, string][])]
|
||||
: [];
|
||||
return (
|
||||
<footer class="status">
|
||||
<span class={`grain ${store.aux ? "aux" : f.grain}`}>{store.preview ? "history" : store.mode === "review" ? "review" : store.aux ? (store.aux.kind === "wiki" ? "article" : store.aux.kind === "back" ? "linked" : "target") : f.grain}</span>
|
||||
<span class="path">{path}</span>
|
||||
<span class="message">{store.status || hint}</span>
|
||||
<span class="message">{store.status || (hint.length ? <Hints hint={hint} /> : <FirstRun />)}</span>
|
||||
<span class="right">
|
||||
{store.links.job?.state === "running" && (
|
||||
<span class="job" title={store.jobText(store.links.job)}>
|
||||
@@ -409,7 +416,9 @@ function StatusLine() {
|
||||
<span title="branch">{store.repo.current}</span>
|
||||
<span title="model">{store.llm.kind === "off" ? "no model" : store.llm.model}</span>
|
||||
<span class={`dot ${store.online ? "on" : "off"}`} title={store.online ? "synced with the local server" : "offline: changes are kept locally"} />
|
||||
<span class="q">? keys</span>
|
||||
<span class="q">
|
||||
<Key k="?" what="keys" />
|
||||
</span>
|
||||
</span>
|
||||
</footer>
|
||||
);
|
||||
@@ -417,22 +426,6 @@ function StatusLine() {
|
||||
|
||||
// ---- the app ----
|
||||
|
||||
/** The offset in its text of a DOM position inside a piece marked with data-o. */
|
||||
function locateIn(node: Node, offset: number): number | null {
|
||||
const el = node instanceof Element ? node : node.parentElement;
|
||||
const piece = el?.closest<HTMLElement>("[data-o]");
|
||||
return piece ? Number(piece.dataset.o) + (node instanceof Text ? offset : 0) : null;
|
||||
}
|
||||
|
||||
/** Map a DOM position inside a body to (node, offset). */
|
||||
function locate(node: Node | null, offset: number): { id: NodeId; at: number } | null {
|
||||
const el = node instanceof Element ? node : node?.parentElement;
|
||||
const piece = el?.closest<HTMLElement>("[data-o]");
|
||||
const body = el?.closest<HTMLElement>("[data-body]");
|
||||
if (!piece || !body) return null;
|
||||
return { id: body.dataset.body as NodeId, at: Number(piece.dataset.o) + (node instanceof Text ? offset : 0) };
|
||||
}
|
||||
|
||||
let hover: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
export function App() {
|
||||
@@ -442,8 +435,17 @@ export function App() {
|
||||
useEffect(() => store.subscribe(() => tick(0)), []);
|
||||
|
||||
useEffect(() => {
|
||||
setPrompt((text) => {
|
||||
setPrefill(text);
|
||||
store.setMode("command");
|
||||
});
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
clearTimeout(hover);
|
||||
// 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();
|
||||
if (menuShown()) closeMenu(false);
|
||||
}
|
||||
if (store.popup) {
|
||||
store.popup = null;
|
||||
store.emit(store.top);
|
||||
@@ -464,8 +466,19 @@ export function App() {
|
||||
},
|
||||
});
|
||||
};
|
||||
// The copy key copies the words selected, when the browser has none of its own selected.
|
||||
const onCopy = (e: ClipboardEvent) => {
|
||||
const words = store.mode === "normal" && window.getSelection()?.isCollapsed !== false ? store.selectedText() : null;
|
||||
if (!words || !e.clipboardData) return;
|
||||
e.clipboardData.setData("text/plain", plain(words));
|
||||
e.preventDefault();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
document.addEventListener("copy", onCopy);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKey);
|
||||
document.removeEventListener("copy", onCopy);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// `auto` picks the layout from the window's width, so follow the width.
|
||||
@@ -512,6 +525,9 @@ export function App() {
|
||||
const click = (e: MouseEvent) => {
|
||||
if (store.mode === "edit") return;
|
||||
const target = e.target as HTMLElement;
|
||||
// A ⋯ (a row's, a pane's, the page's, a note's): its menu, for what it is on.
|
||||
const more = target.closest<HTMLElement>("[data-more]");
|
||||
if (more) return void menuAt(more, more);
|
||||
// A pane's × and pin act on that pane, wherever the focus is.
|
||||
const ctl = target.closest<HTMLElement>("[data-close], [data-pin]");
|
||||
if (ctl) return ctl.dataset.close ? store.closePane(Number(ctl.dataset.close)) : store.togglePanePin(Number(ctl.dataset.pin));
|
||||
@@ -579,12 +595,13 @@ export function App() {
|
||||
const b = selection && !selection.isCollapsed ? at(selection.focusNode, selection.focusOffset) : null;
|
||||
if (a !== null && b !== null && a !== b) {
|
||||
selection!.removeAllRanges();
|
||||
return store.selectInArticle(host, row, [Math.min(a, b), Math.max(a, b)], "word");
|
||||
store.selectInArticle(host, row, [Math.min(a, b), Math.max(a, b)], "word");
|
||||
return showBar();
|
||||
}
|
||||
const note = target.closest<HTMLElement>("[data-note]")?.dataset.note as NodeId | undefined;
|
||||
if (note) return store.toggleAnnotation(host, row, note);
|
||||
const o = selection ? at(selection.anchorNode, selection.anchorOffset) : null;
|
||||
if (o !== null) return store.selectInArticle(host, row, [o, o], "sentence");
|
||||
if (o !== null) return store.selectInArticle(host, row, [o, o], "sentence"), showBar();
|
||||
return;
|
||||
}
|
||||
// A drag selection inside one body becomes the focus range.
|
||||
@@ -594,7 +611,7 @@ export function App() {
|
||||
if (a && b && a.id === b.id && a.at !== b.at) {
|
||||
store.go(a.id, "word", [Math.min(a.at, b.at), Math.max(a.at, b.at)]);
|
||||
selection.removeAllRanges();
|
||||
return;
|
||||
return showBar();
|
||||
}
|
||||
}
|
||||
const anchor = target.closest<HTMLElement>("[data-note]");
|
||||
@@ -639,11 +656,9 @@ export function App() {
|
||||
return;
|
||||
}
|
||||
const at = selection && locate(selection.anchorNode, selection.anchorOffset);
|
||||
if (at) {
|
||||
const all = sentences(store.snap.nodes[at.id].body);
|
||||
const hit = all.find((r) => at.at >= r[0] && at.at <= r[1]);
|
||||
if (hit) return store.go(at.id, "sentence", hit);
|
||||
}
|
||||
// A click in a node's text selects the sentence, and the bar offers what can be done with it.
|
||||
const hit = at && store.sentenceAt(at.id, at.at);
|
||||
if (at && hit) return store.go(at.id, "sentence", hit), showBar();
|
||||
const node = target.closest<HTMLElement>("[data-node]");
|
||||
if (!node) return;
|
||||
// A pane's head makes that pane the active one.
|
||||
@@ -651,6 +666,13 @@ export function App() {
|
||||
store.go(node.dataset.node as NodeId);
|
||||
};
|
||||
|
||||
// A right-click on a node, words, a row, a link or a pane: the app's menu for it, Copy first where there is text. Shift+right-click is the browser's.
|
||||
const onContext = (e: MouseEvent) => {
|
||||
const t = e.target as HTMLElement;
|
||||
if (e.shiftKey || store.mode === "edit" || t.closest("input, textarea, [contenteditable]") || !t.closest(".page")) return;
|
||||
if (menuAt(t, { x: e.clientX, y: e.clientY })) e.preventDefault();
|
||||
};
|
||||
|
||||
const onOver = (e: MouseEvent) => {
|
||||
const anchor = (e.target as HTMLElement).closest<HTMLElement>("[data-note]");
|
||||
clearTimeout(hover);
|
||||
@@ -664,13 +686,13 @@ export function App() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div class={`app mode-${store.mode}${store.mode === "history" || store.mode === "docs" ? " with-panel" : ""}${panes ? " view-panes" : ""}`} onMouseOver={onOver}>
|
||||
<div class={`app mode-${store.mode}${store.mode === "history" || store.mode === "docs" ? " with-panel" : ""}${panes ? " view-panes" : ""}`} onMouseOver={onOver} onContextMenu={onContext}>
|
||||
<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()}
|
||||
onMouseDown={(e) => ((e.shiftKey && e.button === 0) || e.button === 1) && !(e.target as HTMLElement).closest("input, textarea") && e.preventDefault()}
|
||||
>
|
||||
<DocBar />
|
||||
{store.preview && (
|
||||
@@ -688,6 +710,8 @@ export function App() {
|
||||
{store.mode === "link" && store.picker && <LinkPicker />}
|
||||
<Popup />
|
||||
<FocusPopup />
|
||||
<SelBar />
|
||||
<MenuHost />
|
||||
<AgentPanel />
|
||||
<StatusLine />
|
||||
</div>
|
||||
|
||||
+4
-1
@@ -11,6 +11,7 @@ import { describeTarget, hostOf, parseTarget, validateRef, wikiTitle, type Ref }
|
||||
import { clip, plain } from "../core/text";
|
||||
import { kidClass, sameAux, store, type Aux } from "./store";
|
||||
import type { Sugg } from "./linker";
|
||||
import { Hints } from "./Mouse";
|
||||
import { suggest, summary, wikiConfig, type Attribution as Attr, type Suggestion } from "./wiki";
|
||||
|
||||
const MARK: Record<Ref["kind"], string> = { wiki: "W", node: "§", url: "↗" };
|
||||
@@ -193,7 +194,9 @@ export function Backlinks({ ids, title, focusedAt }: { ids: NodeId[]; title: str
|
||||
export function SuggestionCard({ sg }: { sg: Sugg }) {
|
||||
return (
|
||||
<span class={`inset lpreview suggestion l-${sg.target.kind}`} data-suggestion={sg.id}>
|
||||
<span class="meta">suggested link{sg.tier === "auto" ? " (sure)" : ""} · y links · n declines{store.review ? " · s skips" : " · S reviews them all"}</span>
|
||||
<span class="meta">
|
||||
<Hints hint={[`suggested link${sg.tier === "auto" ? " (sure)" : ""}`, ["y", "links"], ["n", "declines"], store.review ? ["s", "skips"] : ["S", "reviews them all"]]} />
|
||||
</span>
|
||||
<LinkCard r={sg.target} compact />
|
||||
<span class="meta why">{sg.why}</span>
|
||||
</span>
|
||||
|
||||
+31
-1
@@ -1,8 +1,14 @@
|
||||
/** The top bar (where the reader is, and whether it is saved) and the documents menu it opens (m). */
|
||||
import { useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||
import { clip } from "../core/text";
|
||||
import { topEntries } from "./actions";
|
||||
import { Hints, act, showMenu } from "./Mouse";
|
||||
import { press } from "./press";
|
||||
import { store } from "./store";
|
||||
|
||||
/** A press on a tool keeps the focus where it was (the keys stay with the page). */
|
||||
const keep = (e: MouseEvent) => e.preventDefault();
|
||||
|
||||
const SAVE_LABEL = { saved: "saved", saving: "saving…", offline: "offline · kept in this browser", foreign: "not saved · reload the page" };
|
||||
const SAVE_TITLE = {
|
||||
saved: "Every edit is saved as you make it. The server has all of them.",
|
||||
@@ -32,6 +38,30 @@ export function DocBar() {
|
||||
<span class={`save-state ${state}`} title={SAVE_TITLE[state]}>
|
||||
{SAVE_LABEL[state]}
|
||||
</span>
|
||||
<span class="tools">
|
||||
<button type="button" class="tool" title="Undo the last edit made in this tab (u)" onMouseDown={keep} onClick={(e) => (e.stopPropagation(), press("u"))}>
|
||||
undo
|
||||
</button>
|
||||
{store.canRedo() && (
|
||||
<button type="button" class="tool" title="Redo (U)" onMouseDown={keep} onClick={(e) => (e.stopPropagation(), press("U"))}>
|
||||
redo
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
class="tool"
|
||||
aria-haspopup="menu"
|
||||
title="Documents, history, layout and settings"
|
||||
onMouseDown={keep}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
const s = store.settings;
|
||||
showMenu(topEntries({ view: s.view, autolink: s.autolink, auto: s.auto, speculate: s.speculate, curves: s.curves, panes: store.panes, doc: !!store.currentDoc, canRedo: store.canRedo() }, act), e.currentTarget as HTMLElement);
|
||||
}}
|
||||
>
|
||||
menu<span class="chev" />
|
||||
</button>
|
||||
</span>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -96,7 +126,7 @@ export function DocsPanel() {
|
||||
<div class="panel-head">
|
||||
<span>Documents</span>
|
||||
<span class="keys">
|
||||
{typing ? "type to filter · ↑ ↓ · Enter open · Esc for actions" : "j k · Enter open · n new · r rename · s save as · D delete · x export · i import · / filter · Esc"}
|
||||
<Hints hint={typing ? ["type to filter · ↑ ↓", ["Enter", "open"], ["Escape", "for actions"]] : ["j k", ["Enter", "open"], ["n", "new"], ["r", "rename"], ["s", "save as"], ["D", "delete"], ["x", "export"], ["i", "import"], ["/", "filter"], ["Escape", "close"]]} />
|
||||
</span>
|
||||
</div>
|
||||
<input
|
||||
|
||||
@@ -0,0 +1,560 @@
|
||||
/**
|
||||
* The mouse and touch: the one menu (a popover, or a sheet from the bottom on touch), the
|
||||
* selection bar over words a click or a drag selected, key hints that are buttons, and the line a
|
||||
* newcomer sees once. What each offers is built in actions.ts from what is focused, and every item
|
||||
* acts by pressing its key (press.ts), so the keyboard and the mouse cannot disagree.
|
||||
*
|
||||
* A right-click or a ⋯ first focuses what it is on, as a click would (without opening or toggling
|
||||
* anything), then shows the menu for what is focused.
|
||||
*/
|
||||
import { Fragment, type ComponentChildren } from "preact";
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||
import { docOf, isLibraryRoot, label, staleness, type NodeId } from "../core/model";
|
||||
import { plain } from "../core/text";
|
||||
import { articleRowEntries, barItems, nodeEntries, pageAct, pageEntries, paneEntries, selectionEntries, topEntries, type Entry, type Item, type NodeCtx, type SelCtx } from "./actions";
|
||||
import { press } from "./press";
|
||||
import { store, type WRow } from "./store";
|
||||
|
||||
// ---- where a pointer is, in the text ----
|
||||
|
||||
/** The offset in its text of a DOM position inside a piece marked with data-o. */
|
||||
export function locateIn(node: Node, offset: number): number | null {
|
||||
const el = node instanceof Element ? node : node.parentElement;
|
||||
const piece = el?.closest<HTMLElement>("[data-o]");
|
||||
return piece ? Number(piece.dataset.o) + (node instanceof Text ? offset : 0) : null;
|
||||
}
|
||||
|
||||
/** Map a DOM position inside a body to (node, offset). */
|
||||
export function locate(node: Node | null, offset: number): { id: NodeId; at: number } | null {
|
||||
const el = node instanceof Element ? node : node?.parentElement;
|
||||
const piece = el?.closest<HTMLElement>("[data-o]");
|
||||
const body = el?.closest<HTMLElement>("[data-body]");
|
||||
if (!piece || !body) return null;
|
||||
return { id: body.dataset.body as NodeId, at: Number(piece.dataset.o) + (node instanceof Text ? offset : 0) };
|
||||
}
|
||||
|
||||
/** The text position under a point. */
|
||||
function caretAt(x: number, y: number): { node: Node; offset: number } | null {
|
||||
const d = document as Document & { caretPositionFromPoint?(x: number, y: number): { offsetNode: Node; offset: number } | null; caretRangeFromPoint?(x: number, y: number): Range | null };
|
||||
if (d.caretPositionFromPoint) {
|
||||
const p = d.caretPositionFromPoint(x, y);
|
||||
return p && { node: p.offsetNode, offset: p.offset };
|
||||
}
|
||||
const r = d.caretRangeFromPoint?.(x, y);
|
||||
return r ? { node: r.startContainer, offset: r.startOffset } : null;
|
||||
}
|
||||
|
||||
/** On a touch screen (no hover): the bar docks at the foot and menus are sheets. */
|
||||
export const touch = () => typeof matchMedia === "function" && matchMedia("(hover: none)").matches;
|
||||
|
||||
// ---- acting ----
|
||||
|
||||
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);
|
||||
export const act = pageAct({ command: (t) => store.command(t), prompt: (p) => promptHook(p) });
|
||||
|
||||
// ---- what is focused, for the menus ----
|
||||
|
||||
function nodeCtx(id: NodeId): NodeCtx {
|
||||
const s = store.snap;
|
||||
const n = s.nodes[id];
|
||||
const st = staleness(s, id);
|
||||
return {
|
||||
title: label(s, id),
|
||||
text: [n.title, plain(n.body)].filter((x) => x.trim()).join("\n\n"),
|
||||
note: n.kind === "note",
|
||||
stale: st.down ? "parent" : st.up ? "sections" : undefined,
|
||||
locked: n.pinned,
|
||||
target: !!store.targetOf(id),
|
||||
library: isLibraryRoot(s, id),
|
||||
doc: docOf(s, id) === id,
|
||||
generating: store.generating,
|
||||
};
|
||||
}
|
||||
|
||||
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 };
|
||||
const f = store.focus;
|
||||
const id = store.noteAt(f.range);
|
||||
const r = id ? store.targetOf(id) : undefined;
|
||||
return {
|
||||
text,
|
||||
article: false,
|
||||
link: r?.kind,
|
||||
note: !!id && !!s.nodes[id].body.trim(),
|
||||
suggestion: store.focusedSuggestion()?.title,
|
||||
related: store.relatedOf(f.node).map((x) => ({ title: x.title, doc: s.nodes[docOf(s, x.node) ?? x.node]?.title })),
|
||||
panes: store.panes,
|
||||
};
|
||||
}
|
||||
|
||||
/** Which menu a place asks for: what is focused there, or the pane it is in, or the page's head. */
|
||||
export type Where = "auto" | "pane" | "page";
|
||||
|
||||
/** The menu for what is focused now. */
|
||||
export function menuHere(where: Where): Entry[] {
|
||||
if (store.mode !== "normal") return [];
|
||||
if (store.selectedText() !== null) return selectionEntries(selCtx(), act);
|
||||
const a = store.aux;
|
||||
const pinned = !!store.branchNodes[store.paneAt]?.pinned;
|
||||
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);
|
||||
return [];
|
||||
}
|
||||
if (a) return [];
|
||||
const id = store.focus.node;
|
||||
if (!store.snap.nodes[id]) return [];
|
||||
if (where === "pane" && store.panes) return paneEntries({ node: nodeCtx(id), pinned }, act);
|
||||
if (where === "page") return pageEntries(nodeCtx(id), act);
|
||||
return nodeEntries(nodeCtx(id), act);
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus what a right-click or a ⋯ is on, as a click would but opening nothing: the words under it
|
||||
* (the selection if it is in it, the words dragged over, a link's or a note's words, else the
|
||||
* sentence), a row, a note's box, a pane's head or the pane, an article's row or text. Returns
|
||||
* which menu to show, or null where the browser's own menu belongs.
|
||||
*/
|
||||
export function focusAt(target: HTMLElement, x: number, y: number): Where | null {
|
||||
if (store.mode !== "normal") return null;
|
||||
const more = !!target.closest("[data-more]");
|
||||
const paneEl = target.closest<HTMLElement>("[data-pane-index]");
|
||||
const paneIndex = paneEl ? Number(paneEl.dataset.paneIndex) : store.paneAt;
|
||||
const tid = paneEl ? Number(paneEl.dataset.tid) : undefined;
|
||||
const intoPane = () => {
|
||||
if (!paneEl) return;
|
||||
if (tid !== undefined && store.branchNodes[paneIndex]?.id !== tid) store.enterFork(tid);
|
||||
store.paneAt = paneIndex;
|
||||
};
|
||||
const named = target.closest<HTMLElement>("[data-host]")?.dataset.host;
|
||||
const host = named?.startsWith("f") ? `p${paneIndex}` : named;
|
||||
if (!more) {
|
||||
// In the selection: keep it.
|
||||
if (target.closest(".sel") && store.selectedText() !== null) return "auto";
|
||||
// Words dragged over, not yet taken (a long press on a touch screen selects a word this way).
|
||||
const sel = window.getSelection();
|
||||
if (sel && !sel.isCollapsed) {
|
||||
const a = locate(sel.anchorNode, sel.anchorOffset);
|
||||
const b = locate(sel.focusNode, sel.focusOffset);
|
||||
if (a && b && a.id === b.id && a.at !== b.at) {
|
||||
intoPane();
|
||||
store.go(a.id, "word", [Math.min(a.at, b.at), Math.max(a.at, b.at)]);
|
||||
sel.removeAllRanges();
|
||||
return "auto";
|
||||
}
|
||||
}
|
||||
// An article's text: the sentence there.
|
||||
const wtext = target.closest<HTMLElement>("[data-wtext]");
|
||||
if (host && wtext && !target.closest("[data-node]")) {
|
||||
const row = (wtext.dataset.wtext === "head" ? { t: "head" } : { t: "sec", id: Number(wtext.dataset.wtext) }) as WRow;
|
||||
const at = caretAt(x, y);
|
||||
const o = at && wtext.contains(at.node) ? locateIn(at.node, at.offset) : null;
|
||||
if (o === null) return null;
|
||||
intoPane();
|
||||
store.selectInArticle(host, row, [o, o], "sentence");
|
||||
return "auto";
|
||||
}
|
||||
const wrow = target.closest<HTMLElement>("[data-wrow]");
|
||||
if (host && wrow) {
|
||||
intoPane();
|
||||
store.setFocus(store.focus, { kind: "wiki", host, row: { t: "sec", id: Number(wrow.dataset.wrow) } });
|
||||
return "auto";
|
||||
}
|
||||
// A link's or a note's words.
|
||||
const anchor = target.closest<HTMLElement>("[data-note]");
|
||||
const n = anchor?.dataset.note ? store.snap.nodes[anchor.dataset.note as NodeId] : undefined;
|
||||
if (n?.parent && n.anchors[0] && !anchor!.closest("[data-wtext]")) {
|
||||
intoPane();
|
||||
store.go(n.parent, "word", [n.anchors[0].start, n.anchors[0].end]);
|
||||
return "auto";
|
||||
}
|
||||
// A node's text: the sentence there.
|
||||
if (target.closest("[data-body]")) {
|
||||
const at = caretAt(x, y);
|
||||
const p = at && locate(at.node, at.offset);
|
||||
const hit = p && store.sentenceAt(p.id, p.at);
|
||||
if (p && hit) {
|
||||
intoPane();
|
||||
store.go(p.id, "sentence", hit);
|
||||
return "auto";
|
||||
}
|
||||
}
|
||||
}
|
||||
const row = target.closest<HTMLElement>("[data-row]");
|
||||
if (row) {
|
||||
intoPane();
|
||||
store.go(row.dataset.row as NodeId);
|
||||
return row.closest(".top") ? (paneEl ? "pane" : "page") : "auto";
|
||||
}
|
||||
if (host && target.closest(".wiki-head")) {
|
||||
intoPane();
|
||||
store.setFocus(store.focus, { kind: "wiki", host, row: { t: "head" } });
|
||||
return "pane";
|
||||
}
|
||||
const node = target.closest<HTMLElement>("[data-node]");
|
||||
if (node?.dataset.node && store.snap.nodes[node.dataset.node as NodeId]) {
|
||||
intoPane();
|
||||
store.go(node.dataset.node as NodeId);
|
||||
return node.matches(".pane-head") || (paneEl && node.matches(".top")) ? "pane" : node.matches(".top") ? "page" : "auto";
|
||||
}
|
||||
if (paneEl && (more || target.closest(".pane-scroll, .pane-ctl"))) {
|
||||
intoPane();
|
||||
if (paneEl.classList.contains("wiki-pane")) store.setFocus(store.focus, { kind: "wiki", host: `p${paneIndex}`, row: { t: "head" } });
|
||||
else if (store.snap.nodes[paneEl.dataset.pane as NodeId]) store.go(paneEl.dataset.pane as NodeId);
|
||||
return "pane";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** A right-click or a ⋯: focus what it is on, and show its menu. Returns whether it did (else the browser's menu shows). */
|
||||
export function menuAt(target: HTMLElement, at: { x: number; y: number } | HTMLElement): boolean {
|
||||
const p = at instanceof HTMLElement ? at.getBoundingClientRect() : null;
|
||||
const where = focusAt(target, p ? p.left + p.width / 2 : (at as { x: number }).x, p ? p.top + p.height / 2 : (at as { y: number }).y);
|
||||
if (!where) return false;
|
||||
const entries = menuHere(where);
|
||||
if (!entries.length) return false;
|
||||
showMenu(entries, at);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- the one menu ----
|
||||
|
||||
interface Shown {
|
||||
entries: Entry[];
|
||||
at: { x: number; y: number } | HTMLElement;
|
||||
/** Where the focus was, to go back to when the menu closes. */
|
||||
restore: HTMLElement | null;
|
||||
}
|
||||
let shown: Shown | null = null;
|
||||
const watchers = new Set<() => void>();
|
||||
const changed = () => watchers.forEach((f) => f());
|
||||
|
||||
export function showMenu(entries: Entry[], at: Shown["at"]) {
|
||||
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 };
|
||||
if (at instanceof HTMLElement) at.setAttribute("aria-expanded", "true");
|
||||
changed();
|
||||
}
|
||||
|
||||
export function closeMenu(refocus = true) {
|
||||
if (!shown) return;
|
||||
const was = shown;
|
||||
shown = null;
|
||||
if (was.at instanceof HTMLElement) was.at.removeAttribute("aria-expanded");
|
||||
changed();
|
||||
if (refocus && was.restore?.isConnected) was.restore.focus({ preventScroll: true });
|
||||
else if (document.activeElement?.closest(".menu")) (document.activeElement as HTMLElement).blur();
|
||||
}
|
||||
|
||||
export const menuShown = () => !!shown;
|
||||
|
||||
const KEY_TEXT: Record<string, string> = { Enter: "⏎", Escape: "Esc", ArrowUp: "↑", ArrowDown: "↓" };
|
||||
/** How a key is written beside what it does. */
|
||||
export const keyText = (k: string) => KEY_TEXT[k] ?? k;
|
||||
|
||||
/**
|
||||
* A menu: a small list of text, every item with its key. A popover by the pointer or the button it
|
||||
* 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 }) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
const el = ref.current!;
|
||||
if (!sheet) {
|
||||
const w = el.offsetWidth;
|
||||
const h = el.offsetHeight;
|
||||
const foot = window.innerHeight - 28;
|
||||
// Below what it hangs from, or above where only that fits; where neither does, as low as it fits.
|
||||
const r = at instanceof HTMLElement ? at.getBoundingClientRect() : { left: at.x, right: at.x, top: at.y, bottom: at.y };
|
||||
const gap = at instanceof HTMLElement ? 4 : 0;
|
||||
const left = at instanceof HTMLElement ? r.right - w : r.left;
|
||||
const top = r.bottom + gap + h <= foot ? r.bottom + gap : r.top - gap - h >= 8 ? r.top - gap - h : foot - h;
|
||||
el.style.left = `${Math.round(Math.max(8, Math.min(window.innerWidth - w - 8, left)))}px`;
|
||||
el.style.top = `${Math.round(Math.max(8, Math.min(foot - h, top)))}px`;
|
||||
}
|
||||
el.focus({ preventScroll: true });
|
||||
}, [entries, at, sheet]);
|
||||
// Registered as it is drawn (an effect after paint can come late, and a press outside would be missed).
|
||||
useLayoutEffect(() => {
|
||||
const outside = (e: Event) => !ref.current?.contains(e.target as Node) && onClose(false);
|
||||
// A scroll closes it too, but not the one that brought what it is about into view as it opened.
|
||||
const opened = performance.now();
|
||||
const scrolled = (e: Event) => performance.now() - opened > 250 && outside(e);
|
||||
const away = () => onClose(false);
|
||||
document.addEventListener("pointerdown", outside, true);
|
||||
document.addEventListener("scroll", scrolled, true);
|
||||
window.addEventListener("resize", away);
|
||||
window.addEventListener("blur", away);
|
||||
return () => {
|
||||
document.removeEventListener("pointerdown", outside, true);
|
||||
document.removeEventListener("scroll", scrolled, true);
|
||||
window.removeEventListener("resize", away);
|
||||
window.removeEventListener("blur", away);
|
||||
};
|
||||
}, [onClose]);
|
||||
const cells = () => [...ref.current!.querySelectorAll<HTMLElement>("[data-mi]:not([aria-disabled='true'])")];
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
// The menu has the keys while it is open: none reach the page's handler.
|
||||
e.stopPropagation();
|
||||
const all = cells();
|
||||
const i = all.indexOf(document.activeElement as HTMLElement);
|
||||
const go = (j: number) => (e.preventDefault(), all[(j + all.length) % all.length]?.focus());
|
||||
if (e.key === "Escape") return e.preventDefault(), onClose(true);
|
||||
if (e.key === "Tab") return e.preventDefault(), onClose(true);
|
||||
if (e.key === "ArrowDown" || (e.key === "ArrowRight" && i >= 0 && all[i].closest(".choices"))) return go(i + 1);
|
||||
if (e.key === "ArrowUp" || (e.key === "ArrowLeft" && i >= 0 && all[i].closest(".choices"))) return go(i < 0 ? -1 : i - 1);
|
||||
if (e.key === "Home") return go(0);
|
||||
if (e.key === "End") return go(-1);
|
||||
if ((e.key === "Enter" || e.key === " ") && i < 0) e.preventDefault();
|
||||
};
|
||||
const run = (it: { disabled?: boolean; run: () => void }) => (e: MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (it.disabled) return;
|
||||
onClose(true);
|
||||
it.run();
|
||||
};
|
||||
return (
|
||||
<div class={`menu${sheet ? " sheet" : ""}`} role="menu" tabIndex={-1} ref={ref} onKeyDown={onKey} onContextMenu={(e) => e.preventDefault()} onMouseDown={(e) => e.preventDefault()}>
|
||||
{entries.map((x, i) => {
|
||||
if (x.t === "sep") return <div key={i} class="sep" role="separator" />;
|
||||
if (x.t === "head") return <div key={i} class="mh">{x.text}</div>;
|
||||
if (x.t === "choices")
|
||||
return (
|
||||
<div key={i} class="choices" role="group" aria-label={x.label}>
|
||||
<span class="lbl">{x.label}</span>
|
||||
{x.options.map((o) => (
|
||||
<button key={o.label} type="button" data-mi role="menuitemradio" aria-checked={o.on ?? false} class={o.on ? "on" : undefined} tabIndex={-1} title={o.key ? `${o.label} (${o.key})` : undefined} onClick={run(o)}>
|
||||
{o.label}
|
||||
{o.key && <span class="k">{keyText(o.key)}</span>}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
return <MenuItem key={i} it={x} onClick={run(x)} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MenuItem({ it, onClick }: { it: Item; onClick: (e: MouseEvent) => void }) {
|
||||
const k = it.keyText ?? (it.key ? keyText(it.key) : "");
|
||||
return (
|
||||
<button type="button" class="mi" data-mi role={it.checked !== undefined ? "menuitemcheckbox" : "menuitem"} aria-checked={it.checked} aria-disabled={it.disabled || undefined} tabIndex={-1} onClick={onClick} data-key={it.key}>
|
||||
{it.checked !== undefined && <span class="chk">{it.checked ? "✓" : ""}</span>}
|
||||
<span class="lbl">{it.label}</span>
|
||||
{it.sub && <span class="sub">{it.sub}</span>}
|
||||
{k && <span class="k">{k}</span>}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** Where the open menu is drawn (App.tsx). */
|
||||
export function MenuHost() {
|
||||
const [, tick] = useState(0);
|
||||
useEffect(() => {
|
||||
const f = () => tick((x) => x + 1);
|
||||
watchers.add(f);
|
||||
return () => void watchers.delete(f);
|
||||
}, []);
|
||||
if (!shown) return null;
|
||||
return <Menu entries={shown.entries} at={shown.at} sheet={touch()} onClose={closeMenu} />;
|
||||
}
|
||||
|
||||
// ---- the selection bar ----
|
||||
|
||||
/** The focus the bar was shown for: it shows while the focus is still that, and goes when anything else is focused. */
|
||||
let barFor: string | null = null;
|
||||
const focusKey = () => JSON.stringify([store.focus, store.aux, store.paneAt]);
|
||||
/** A click or a drag has just selected words: show the bar by them (and the status line's hints for them, not an old message). */
|
||||
export const showBar = () => {
|
||||
barFor = focusKey();
|
||||
store.status = "";
|
||||
};
|
||||
export const hideBar = () => void (barFor = null);
|
||||
|
||||
/** Put the bar over the selection's first line (under its last, where there is no room above), centred on it. */
|
||||
function placeBar(el: HTMLElement | null, shown = false) {
|
||||
if (!el) return;
|
||||
const sels = [...document.querySelectorAll<HTMLElement>(".sel")].filter((x) => x.offsetParent);
|
||||
if (el.classList.contains("docked")) {
|
||||
// Docked at the foot: the words it is about are not left under it.
|
||||
const r = sels[0]?.getBoundingClientRect();
|
||||
const top = el.getBoundingClientRect().top;
|
||||
if (shown && r && r.bottom > top - 8) (sels[0].closest(".pane-scroll") ?? document.scrollingElement)?.scrollBy({ top: r.bottom - top + 48 });
|
||||
return;
|
||||
}
|
||||
if (!sels.length) return void (el.style.visibility = "hidden");
|
||||
const rects = sels.flatMap((s) => [...s.getClientRects()]).filter((r) => r.width);
|
||||
if (!rects.length) return void (el.style.visibility = "hidden");
|
||||
const first = rects[0];
|
||||
const last = rects[rects.length - 1];
|
||||
const left = Math.min(...rects.map((r) => r.left));
|
||||
const right = Math.max(...rects.map((r) => r.right));
|
||||
const w = el.offsetWidth;
|
||||
const h = el.offsetHeight;
|
||||
const bar = document.querySelector(".docbar")?.getBoundingClientRect().bottom ?? 0;
|
||||
const below = first.top - h - 9 < bar + 4;
|
||||
const top = below ? last.bottom + 9 : first.top - h - 9;
|
||||
const mid = (left + right) / 2;
|
||||
const x = Math.round(Math.max(8, Math.min(window.innerWidth - w - 8, mid - w / 2)));
|
||||
el.classList.toggle("below", below);
|
||||
el.style.left = `${x}px`;
|
||||
el.style.top = `${Math.round(top)}px`;
|
||||
el.style.setProperty("--tick", `${Math.round(Math.max(10, Math.min(w - 10, mid - x)))}px`);
|
||||
// Scrolled out of its pane or the window: out of sight with it.
|
||||
const clip = sels[0].closest(".pane-scroll")?.getBoundingClientRect();
|
||||
const gone = top < bar || top + h > window.innerHeight - 28 || (clip && (last.bottom < clip.top || first.top > clip.bottom));
|
||||
el.style.visibility = gone ? "hidden" : "visible";
|
||||
}
|
||||
|
||||
/**
|
||||
* The selection bar: shown by words a click (a sentence) or a drag (the words dragged over)
|
||||
* selected, in a node's text or an article's; each item shows its key quietly, so it teaches the
|
||||
* keys. On touch it is docked at the foot of the screen, with a way to put it away.
|
||||
*/
|
||||
export function SelBar() {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const on = barFor !== null && store.mode === "normal" && barFor === focusKey() && store.selectedText() !== null;
|
||||
const docked = touch();
|
||||
const was = useRef(false);
|
||||
useLayoutEffect(() => {
|
||||
if (on) placeBar(ref.current, !was.current);
|
||||
was.current = on;
|
||||
});
|
||||
useLayoutEffect(() => {
|
||||
let frame = 0;
|
||||
const again = () => {
|
||||
if (!frame)
|
||||
frame = requestAnimationFrame(() => {
|
||||
frame = 0;
|
||||
placeBar(ref.current);
|
||||
});
|
||||
};
|
||||
document.addEventListener("scroll", again, true);
|
||||
window.addEventListener("resize", again);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
document.removeEventListener("scroll", again, true);
|
||||
window.removeEventListener("resize", again);
|
||||
};
|
||||
}, []);
|
||||
if (!on) return null;
|
||||
const c = selCtx();
|
||||
const groups = barItems(c, act);
|
||||
const go = (it: Item) => () => {
|
||||
hideBar();
|
||||
it.run();
|
||||
};
|
||||
return (
|
||||
<div class={`selbar${docked ? " docked" : ""}`} role="toolbar" aria-label="Ask about the selected words" ref={ref} style={docked ? undefined : { visibility: "hidden" }} onMouseDown={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}>
|
||||
{groups.map((g, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <span class="bar-sep" />}
|
||||
{g.map((it) => (
|
||||
<button key={it.key} type="button" title={`${it.label} (${keyText(it.key!)})`} data-key={it.key} onClick={go(it)}>
|
||||
{it.short ?? it.label}
|
||||
<span class="k">{keyText(it.key!)}</span>
|
||||
</button>
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
<button type="button" class="bar-more" title="More: copy, select less or more, related sections (right-click works too)" aria-haspopup="menu" onClick={(e) => showMenu(selectionEntries(selCtx(), act), e.currentTarget as HTMLElement)}>
|
||||
⋯
|
||||
</button>
|
||||
{docked && (
|
||||
<button
|
||||
type="button"
|
||||
class="bar-done"
|
||||
aria-label="Done"
|
||||
title="Done (Esc)"
|
||||
onClick={() => {
|
||||
hideBar();
|
||||
press("Escape");
|
||||
}}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---- key hints as buttons ----
|
||||
|
||||
/** A hint: words, or a key and what it does. */
|
||||
export type Hint = (string | [key: string, what: string])[];
|
||||
|
||||
/** A key hint that is a button: a click does what the key does. */
|
||||
export function Key({ k, what, shift }: { k: string; what: ComponentChildren; shift?: boolean }) {
|
||||
return (
|
||||
<button type="button" class="key" data-key={k} title={`${keyText(k)}`} onMouseDown={(e) => e.preventDefault()} onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
// A box being typed in (the documents filter) gives the key back to the page.
|
||||
if ((document.activeElement as HTMLElement | null)?.matches?.("input, textarea")) (document.activeElement as HTMLElement).blur();
|
||||
press(k, shift);
|
||||
}}
|
||||
>
|
||||
<kbd>{keyText(k)}</kbd>
|
||||
<span class="lbl">{what}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** Hints, joined by middle dots: each key a button. */
|
||||
export function Hints({ hint }: { hint: Hint }) {
|
||||
return (
|
||||
<span class="hints">
|
||||
{hint.map((h, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <span class="hsep"> · </span>}
|
||||
{typeof h === "string" ? <span>{h}</span> : <Key k={h[0]} what={h[1]} />}
|
||||
</Fragment>
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// ---- the first visit ----
|
||||
|
||||
const FIRST = "ie:firstrun";
|
||||
const seen = () => {
|
||||
try {
|
||||
return localStorage.getItem(FIRST) === "done";
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
let firstRun = typeof window !== "undefined" && !seen();
|
||||
if (firstRun) {
|
||||
const done = () => {
|
||||
firstRun = false;
|
||||
try {
|
||||
localStorage.setItem(FIRST, "done");
|
||||
} catch {
|
||||
/* storage may be unavailable: it shows again next time */
|
||||
}
|
||||
window.removeEventListener("pointerdown", done, true);
|
||||
window.removeEventListener("keydown", done, true);
|
||||
};
|
||||
window.addEventListener("pointerdown", done, true);
|
||||
window.addEventListener("keydown", done, true);
|
||||
}
|
||||
|
||||
/** The one line a newcomer sees, in the status line, until they first click or press a key. */
|
||||
export function FirstRun() {
|
||||
if (!firstRun) return null;
|
||||
return (
|
||||
<span class="firstrun">
|
||||
{touch() ? "Tap a sentence for what you can do with it" : <>Click a sentence for what you can do with it · <Key k="?" what="lists every key" /></>}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
export const isFirstRun = () => firstRun;
|
||||
+9
-1
@@ -182,6 +182,7 @@ export function NoteView({ v, inNote }: { v: VNote; inNote: boolean }) {
|
||||
const kids = v.id ? sections(snap, v.id) : [];
|
||||
return (
|
||||
<span class={`${v.form === "passage" || inNote ? "inset" : "sidenote"}${cls}`} data-node={v.id}>
|
||||
{v.id && <button type="button" class="more" data-more="note" tabIndex={-1} aria-haspopup="menu" title="More for this note (right-click works too)">⋯</button>}
|
||||
{meta}
|
||||
{content}
|
||||
{kids.length > 0 && <Outline ids={kids} />}
|
||||
@@ -357,7 +358,12 @@ export function Flags({ id }: { id: NodeId }) {
|
||||
n.pinned && n.parent && "locked",
|
||||
].filter(Boolean) as string[];
|
||||
if (!flags.length) return null;
|
||||
return <span class={`flags${st.up || st.down || conflict ? " attn" : ""}`}>{flags.join(" · ")}</span>;
|
||||
// A stale flag says what to do about it when clicked: the node's menu, its remedies first.
|
||||
return (
|
||||
<span class={`flags${st.up || st.down || conflict ? " attn" : ""}`} data-more={st.up || st.down ? "flag" : undefined} title={st.up || st.down ? "What to do about it" : undefined}>
|
||||
{flags.join(" · ")}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** Redraws a section only when something in its subtree changed. */
|
||||
@@ -378,6 +384,7 @@ export function Row({ id, open, leaf, editing }: { id: NodeId; open: boolean; le
|
||||
<span class="mark">{open ? "▾" : leaf ? "·" : "▸"}</span>
|
||||
{editing ? <TitleEditor id={id} /> : <span class="title">{n.title || <i class="untitled">untitled</i>}</span>}
|
||||
<Flags id={id} />
|
||||
<button type="button" class="more" data-more="row" tabIndex={-1} aria-haspopup="menu" title="More for this section (right-click works too)">⋯</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -456,6 +463,7 @@ export function TopMatter({ id }: { id: NodeId }) {
|
||||
: `${library ? `${kids.length} document${kids.length === 1 ? "" : "s"}` : `${kids.length} section${kids.length === 1 ? "" : "s"}`} · ${count} nodes`}{" "}
|
||||
· branch {store.repo.current}
|
||||
<Flags id={id} />
|
||||
<button type="button" class="more" data-more="page" tabIndex={-1} aria-haspopup="menu" title="More for this page (right-click works too)">⋯</button>
|
||||
</div>
|
||||
</header>
|
||||
<div class={`abstract${prompt ? " seed" : ""}${folded ? " folded" : ""}`} onClick={folded ? () => store.toggleFold(id) : undefined}>
|
||||
|
||||
@@ -99,6 +99,9 @@ function Chrome({ props, title, mark }: { props: PaneProps; title: string; mark?
|
||||
<span class="tabtitle">{title}</span>
|
||||
</div>
|
||||
<div class="pane-ctl">
|
||||
<span role="button" class="pane-btn more" data-more="pane" aria-haspopup="menu" title="More for this pane (right-click works too)" aria-label="More">
|
||||
⋯
|
||||
</span>
|
||||
<span role="button" class={`pane-btn pin${pinned ? " on" : ""}`} data-pin={tid} title={pinned ? "Unpin this pane (P)" : "Pin this pane: it stays when what opened it closes, and never folds away (P)"} aria-label={pinned ? "Unpin" : "Pin"}>
|
||||
<svg viewBox="0 0 12 12" aria-hidden="true">
|
||||
<path d="M4 1.5h4M4.6 1.5v3.6L2.8 7.2h6.4L7.4 5.1V1.5M6 7.2V11" />
|
||||
|
||||
@@ -1655,6 +1655,12 @@ class Store {
|
||||
this.setFocus({ node: f.node, grain: "word", range: next });
|
||||
}
|
||||
|
||||
/** The sentence of a node's text at an offset (where a click or a right-click lands). */
|
||||
sentenceAt(id: NodeId, at: number): Range | undefined {
|
||||
const n = this.snap.nodes[id];
|
||||
return n ? sentences(n.body).find((r) => at >= r[0] && at <= r[1]) : undefined;
|
||||
}
|
||||
|
||||
noteAt(range: Range | undefined, node = this.focus.node): NodeId | undefined {
|
||||
if (!range) return;
|
||||
const s = this.snap;
|
||||
@@ -1975,6 +1981,10 @@ class Store {
|
||||
}
|
||||
return u;
|
||||
}
|
||||
/** Whether U would redo something (the top bar offers redo only then). */
|
||||
canRedo(): boolean {
|
||||
return !this.preview && this.undoManager().canRedo();
|
||||
}
|
||||
/** u: undo the last edit made in this tab, wherever in the library it was. */
|
||||
undoLast(redo = false) {
|
||||
if (!this.writable()) return;
|
||||
|
||||
+135
-2
@@ -398,7 +398,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.col.crowded > .pane[data-over]::before { content: ""; position: absolute; z-index: 4; top: 0; left: 0; right: 0; height: 1px; background: var(--rule); }
|
||||
.tabline {
|
||||
position: absolute; z-index: 2; top: 0; left: 0; right: 0; height: var(--tab); display: flex; align-items: center; gap: 0.4em;
|
||||
padding: 0 3.4rem 0 var(--spine); background: inherit; border-bottom: 1px solid var(--pane-rule); opacity: 0; pointer-events: none; cursor: pointer; transition: opacity 0.12s;
|
||||
padding: 0 4.6rem 0 var(--spine); background: inherit; border-bottom: 1px solid var(--pane-rule); opacity: 0; pointer-events: none; cursor: pointer; transition: opacity 0.12s;
|
||||
font-family: var(--sans); font-size: 0.74rem; letter-spacing: 0.02em; color: var(--dim); white-space: nowrap;
|
||||
}
|
||||
.tabline .tabtitle { overflow: hidden; text-overflow: ellipsis; }
|
||||
@@ -416,7 +416,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.col[data-peek] .spine, .col.crowded > .pane[data-peek] > .tabline { opacity: 0; pointer-events: none; }
|
||||
|
||||
/* Dragging a pane in its column: its grip, quiet until pointed at; the line where it will go. */
|
||||
.grip { position: absolute; z-index: 3; top: 0; left: var(--spine); right: 3.6rem; height: 1.15rem; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
|
||||
.grip { position: absolute; z-index: 3; top: 0; left: var(--spine); right: 4.6rem; height: 1.15rem; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
|
||||
.grip::before { content: ""; position: absolute; left: 50%; top: 0.42rem; width: 1.1rem; margin-left: -0.55rem; height: 3px; border-top: 1px solid var(--faint); border-bottom: 1px solid var(--faint); opacity: 0; transition: opacity 0.12s; }
|
||||
.col.split .grip:hover::before { opacity: 0.8; }
|
||||
.col:not(.split) .grip, .col.crowded > .pane[data-covered] > .grip { display: none; }
|
||||
@@ -657,3 +657,136 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.completer .t { color: var(--fg); font-weight: 600; }
|
||||
.completer .p { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
:is(.backlinks, .related-list) .bl-key { color: var(--link); font-family: var(--mono, monospace); font-size: 0.7rem; min-width: 0.8em; }
|
||||
|
||||
/* ---- the mouse and touch (src/ui/Mouse.tsx, actions.ts) ----
|
||||
* Every function is reachable without the keys, and nothing shows until it is wanted: key hints
|
||||
* are buttons, a click on a sentence brings a bar of words over it, a ⋯ (shown when its row, pane,
|
||||
* page or note is pointed at or focused) and a right-click bring a menu. Each item names its key.
|
||||
*/
|
||||
|
||||
/* Key hints: a key named in the status line or a panel's head is a button that does what the key does. */
|
||||
.key {
|
||||
font: inherit; color: inherit; background: none; border: 0; border-radius: 2px; padding: 0 0.15em; margin: 0 -0.15em;
|
||||
cursor: pointer; white-space: nowrap;
|
||||
}
|
||||
.key kbd { font-size: 0.86em; padding: 0 0.25em; margin-right: 0.3em; border-bottom-width: 1px; color: var(--dim); }
|
||||
.key:hover { background: var(--sel); border: 0; }
|
||||
.key:hover .lbl { text-decoration: underline 1px dotted; text-underline-offset: 0.18em; }
|
||||
.key:focus-visible { outline: 1px solid var(--fg); outline-offset: 1px; }
|
||||
.hsep { color: var(--faint); }
|
||||
.status .q .key kbd { margin-right: 0.2em; }
|
||||
.panel-head .keys .key { font-size: inherit; }
|
||||
.firstrun { color: var(--faint); font-style: italic; }
|
||||
.firstrun .key { font-style: normal; }
|
||||
|
||||
/* The one menu: a small list of text, every item with its key. */
|
||||
.menu {
|
||||
position: fixed; z-index: 30; min-width: 15rem; max-width: 24rem; padding: 0.3rem 0;
|
||||
background: var(--bg); border: 3px double var(--rule); box-shadow: 1px 2px 8px 0 color-mix(in srgb, var(--fg) 16%, transparent);
|
||||
font-family: var(--sans); font-size: 0.74rem; line-height: 1.35; color: var(--fg); outline: none;
|
||||
}
|
||||
.menu .mh { padding: 0.35rem 0.85rem 0.15rem 1.1rem; font-size: 0.58rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.menu .mi {
|
||||
position: relative; display: flex; align-items: baseline; gap: 1.2em; width: 100%; padding: 0.24rem 0.85rem 0.24rem 1.1rem; margin: 0;
|
||||
font: inherit; color: inherit; text-align: left; background: none; border: 0; border-radius: 0; cursor: pointer;
|
||||
}
|
||||
.menu .mi:hover, .menu .mi:focus-visible { background: var(--sel); outline: none; }
|
||||
.menu .mi[aria-disabled="true"] { color: var(--faint); cursor: default; background: none; }
|
||||
.menu .mi .lbl { flex: none; }
|
||||
.menu .mi .k { margin-left: auto; flex: none; font-family: var(--mono); font-size: 0.62rem; color: var(--faint); }
|
||||
.menu .mi .sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.62rem; color: var(--faint); }
|
||||
.menu .mi .chk { position: absolute; left: 0.3rem; color: var(--dim); }
|
||||
.menu .sep { height: 0; border-top: 1px solid var(--hair); margin: 0.3rem 0; }
|
||||
/* A row of choices in one item: move up, down, in, out; a setting's values. */
|
||||
.menu .choices { display: flex; align-items: baseline; gap: 0.15rem; padding: 0.2rem 0.85rem 0.2rem 1.1rem; }
|
||||
.menu .choices .lbl { color: var(--fg); margin-right: auto; padding-right: 0.8em; }
|
||||
.menu .choices button { font: inherit; font-size: 0.68rem; border: 1px solid transparent; border-radius: 2px; background: none; padding: 0.05rem 0.4rem; color: var(--soft); }
|
||||
.menu .choices button:hover, .menu .choices button:focus-visible { border-color: var(--rule); outline: none; }
|
||||
.menu .choices button.on { border-color: var(--fg); color: var(--fg); }
|
||||
.menu .choices button .k { font-family: var(--mono); font-size: 0.9em; color: var(--faint); margin-left: 0.25em; }
|
||||
|
||||
/* The selection bar: what can be asked about the words selected with the pointer, as words, over them. */
|
||||
.selbar {
|
||||
position: fixed; z-index: 16; display: flex; align-items: baseline; padding: 0.12rem 0.25rem;
|
||||
background: var(--bg); border: 1px solid var(--rule); border-radius: 2px;
|
||||
box-shadow: 1px 2px 8px 0 color-mix(in srgb, var(--fg) 14%, transparent);
|
||||
font-family: var(--sans); font-size: 0.72rem; white-space: nowrap;
|
||||
}
|
||||
.selbar button {
|
||||
font: inherit; color: var(--fg); background: none; border: 0; border-radius: 2px; padding: 0.12rem 0.42rem;
|
||||
font-variant-caps: all-small-caps; letter-spacing: 0.05em; font-size: 0.82rem; line-height: 1.2;
|
||||
}
|
||||
.selbar button:hover { background: var(--sel); }
|
||||
.selbar button .k { font-family: var(--mono); font-variant-caps: normal; font-size: 0.62rem; letter-spacing: 0; color: var(--faint); margin-left: 0.3em; }
|
||||
.selbar .bar-sep { align-self: stretch; width: 0; border-left: 1px solid var(--hair); margin: 0.2rem 0.2rem; }
|
||||
.selbar::after { /* a hairline tick pointing at the words */
|
||||
content: ""; position: absolute; left: var(--tick, 50%); bottom: -5px; width: 8px; height: 8px; margin-left: -4px;
|
||||
background: var(--bg); border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); transform: rotate(45deg);
|
||||
}
|
||||
.selbar.below::after { bottom: auto; top: -5px; transform: rotate(225deg); }
|
||||
|
||||
/* The ⋯ by a row, a pane's head, a page's head or a note: invisible until wanted, never moving the text. */
|
||||
.more {
|
||||
flex: none; font: inherit; font-family: var(--sans); font-size: 0.9em; line-height: 1; letter-spacing: 0.05em;
|
||||
color: var(--faint); background: none; border: 0; border-radius: 2px; padding: 0.15em 0.4em; margin: 0 -0.2em 0 0.4em;
|
||||
opacity: 0; cursor: pointer;
|
||||
}
|
||||
.row:hover > .more, .node.focused > .row > .more, .more[aria-expanded="true"], .more:focus-visible,
|
||||
.top:hover .more, .top.focused .more,
|
||||
:is(.sidenote, .inset):hover > .more, :is(.sidenote, .inset).focused > .more { opacity: 1; }
|
||||
.more:hover, .more[aria-expanded="true"] { color: var(--fg); background: var(--sel); border: 0; }
|
||||
.row > .title + .more { margin-left: auto; }
|
||||
.row > .flags + .more { margin-left: 0.5em; }
|
||||
/* After the arrow of a row whose pane is open. */
|
||||
.node.showing > .row > .more, .node.forked > .row > .more { order: 1; margin-left: 0.4em; }
|
||||
.flags[data-more] { cursor: pointer; }
|
||||
.flags[data-more]:hover { text-decoration: underline 1px dotted; text-underline-offset: 0.2em; }
|
||||
.byline .more { margin: 0 -0.4em 0 0.5em; font-size: 1.2em; }
|
||||
:is(.sidenote, .inset) > .more { position: absolute; top: 0.15rem; right: 0.15rem; margin: 0; font-size: 0.82rem; }
|
||||
.inset { position: relative; }
|
||||
/* A pane's own ⋯ stands for its page's. */
|
||||
.pane .top .more { display: none; }
|
||||
.pane-btn.more { display: flex; align-items: center; justify-content: center; padding: 0; font-family: var(--sans); font-size: 0.8rem; line-height: 1; letter-spacing: 0.04em; }
|
||||
.pane-btn.more[aria-expanded="true"] { color: var(--fg); background: var(--sel); }
|
||||
|
||||
/* The top bar stays at the top, in the column too: undo, redo when there is one, and the menu. */
|
||||
.docbar {
|
||||
position: sticky; top: 0; z-index: 4; margin: -44px 0 16px; padding: 14px 0 6px;
|
||||
background: var(--bg); box-shadow: 0 0 0 100vmax var(--bg); clip-path: inset(0 -100vmax);
|
||||
}
|
||||
.view-panes .docbar { position: relative; box-shadow: none; clip-path: none; background: none; }
|
||||
.docbar .tools { margin-left: auto; display: flex; align-items: baseline; gap: 1.1em; }
|
||||
.docbar .tool { font: inherit; color: var(--dim); background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: 0.02em; }
|
||||
.docbar .tool:hover, .docbar .tool[aria-expanded="true"] { color: var(--fg); text-decoration: underline 1px dotted; text-underline-offset: 0.2em; }
|
||||
.docbar .tool .chev { display: inline-block; width: 0; height: 0; border: 0.38em solid transparent; border-top: 0.46em solid var(--faint); border-bottom: 0; margin-left: 0.3em; vertical-align: 0.1em; }
|
||||
|
||||
/* Touch: no hover, no right-click, no keys. The bar docks at the foot; a menu is a sheet. */
|
||||
.selbar.docked {
|
||||
left: 0; right: 0; bottom: 1.75rem; top: auto !important; border-width: 1px 0 0; border-radius: 0; box-shadow: none;
|
||||
padding: 0.3rem 0.4rem; background: var(--bg); flex-wrap: wrap; justify-content: center;
|
||||
}
|
||||
.selbar.docked::after, .selbar.docked .k, .selbar.docked .bar-sep { display: none; }
|
||||
.selbar.docked button { padding: 0.45rem 0.6rem; font-size: 0.95rem; }
|
||||
.menu.sheet {
|
||||
left: 0; right: 0; bottom: 1.75rem; top: auto; max-width: none; max-height: 70vh; overflow-y: auto;
|
||||
border-width: 3px 0 0; padding-bottom: 0.4rem; font-size: 0.86rem; box-shadow: 0 -2px 10px 0 color-mix(in srgb, var(--fg) 12%, transparent);
|
||||
}
|
||||
.menu.sheet .mi { padding: 0.62rem 1rem; }
|
||||
.menu.sheet .choices { padding: 0.45rem 1rem; }
|
||||
.menu.sheet .choices button { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
|
||||
@media (hover: none) {
|
||||
.more { pointer-events: none; padding: 0.45em 0.6em; margin: -0.3em -0.4em -0.3em 0.3em; }
|
||||
.node.focused > .row > .more, .top.focused .more, :is(.sidenote, .inset).focused > .more { opacity: 1; pointer-events: auto; }
|
||||
.pane .pane-btn { color: var(--faint); }
|
||||
.status .key { padding: 0.35rem 0.2em; }
|
||||
.docbar .tool { padding: 0.4rem 0; }
|
||||
}
|
||||
/* A phone has no keys to teach in the status line: the bar and the menus say what there is. */
|
||||
@media (hover: none) and (max-width: 720px) {
|
||||
.status .message .hints { display: none; }
|
||||
}
|
||||
/* The way to every key is never hidden, however narrow the window. */
|
||||
@media (max-width: 720px) {
|
||||
.status .q { display: inline; }
|
||||
}
|
||||
/* ---- end mouse ---- */
|
||||
Reference in new issue
Block a user