Pages, from a real phone: the pane gone to has the page's height; dots for a page's panes in the trail; a 140 ms glide; the map as a tree; a held pane moves; a one-row selection bar; a tap on a link only opens it
- A shared page stacks whenever a share would cut the pane looked at short (stack.ts crowds; desktop unchanged). - Each trail step shows a dot per pane on its page, its own filled in its colour; past four, the number. - The strip glides to a page in 140 ms easing out (rAF, snapping off on the way), at once with reduced motion; a finger takes it from a glide. - The map draws tree lines from each parent into each child in the child's colour (pages.ts rails), crisp borders, deep forests indented less. - A press held on a pane's tab or the band above its title picks it up (touch), drop line and ghost, edge scroll, a second finger cancels; Move this pane up/down in the pane menu (Alt+Shift+k j). - The docked selection bar is one row: actions scroll sideways under a fade, the ⋯ and × fixed at its end. - The hover preview is the mouse's only (pointerType), dropped on any press, click or pane change; the keyboard preview is not shown on touch. 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
d3c2ea452a
commit
99aae86dff
14 files changed
+1136
-93
No files matched your search
@@ -437,3 +437,536 @@ for (const [width, height] of [
|
|||||||
expect(await wide()).toBe(true);
|
expect(await wide()).toBe(true);
|
||||||
await shot(page, `19-size-${width}-map`);
|
await shot(page, `19-size-${width}-map`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// ---- the second round: what the owner found on a real phone ----
|
||||||
|
|
||||||
|
/** A press of a finger, by real touch events: down at a point, held, moved through points (each a frame apart), and lifted. */
|
||||||
|
async function press(page: Page, from: { x: number; y: number }, opts: { hold?: number; to?: { x: number; y: number }[]; steps?: number; wait?: number } = {}) {
|
||||||
|
const cdp = await page.context().newCDPSession(page);
|
||||||
|
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [from] });
|
||||||
|
if (opts.hold) await page.waitForTimeout(opts.hold);
|
||||||
|
let at = from;
|
||||||
|
for (const to of opts.to ?? []) {
|
||||||
|
const n = opts.steps ?? 10;
|
||||||
|
for (let k = 1; k <= n; k++) {
|
||||||
|
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: at.x + ((to.x - at.x) * k) / n, y: at.y + ((to.y - at.y) * k) / n }] });
|
||||||
|
await page.waitForTimeout(16);
|
||||||
|
}
|
||||||
|
at = to;
|
||||||
|
}
|
||||||
|
if (opts.wait) await page.waitForTimeout(opts.wait);
|
||||||
|
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||||
|
await cdp.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A tap of a finger at a point, by real touch events (the browser then sends its compatibility mouse events, as a phone's does). */
|
||||||
|
const touchTap = (page: Page, x: number, y: number) => press(page, { x, y }, { hold: 40 });
|
||||||
|
|
||||||
|
/** Open these top-level sections from the library, each in a pane of its own down the second page; the last opened is the active one. */
|
||||||
|
async function stackFromLibrary(page: Page, titles: string[]) {
|
||||||
|
for (const t of titles) {
|
||||||
|
await page.locator(".trail-step", { hasText: "Library" }).tap();
|
||||||
|
await at(page, "Library", 0);
|
||||||
|
await row(page, t).tap();
|
||||||
|
await at(page, t, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The active pane's page, measured: its height, and how much of each pane in it shows (down to what covers it), top to bottom. */
|
||||||
|
const shown = (page: Page) =>
|
||||||
|
page.evaluate(() => {
|
||||||
|
const p = document.querySelector<HTMLElement>(".strip .pane.active")!;
|
||||||
|
const col = p.parentElement!;
|
||||||
|
const c = col.getBoundingClientRect();
|
||||||
|
const ps = [...col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||||
|
const vis = ps.map((q, i) => {
|
||||||
|
const r = q.getBoundingClientRect();
|
||||||
|
const next = col.classList.contains("crowded") ? (ps[i + 1]?.getBoundingClientRect().top ?? Infinity) : Infinity;
|
||||||
|
return Math.round(Math.max(0, Math.min(r.bottom, c.bottom, next) - Math.max(r.top, c.top)));
|
||||||
|
});
|
||||||
|
return { h: Math.round(c.height), vis, active: ps.indexOf(p), crowded: col.classList.contains("crowded"), titles: ps.map((q) => q.querySelector(".tabtitle")!.textContent) };
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const [width, height] of [
|
||||||
|
[390, 844],
|
||||||
|
[360, 640],
|
||||||
|
] as const)
|
||||||
|
test(`at ${width}×${height}, the pane gone to in a shared page has the page's height; the others fold to their tabs (two panes and three)`, async ({ page }) => {
|
||||||
|
await page.setViewportSize({ width, height });
|
||||||
|
await start(page);
|
||||||
|
await stackFromLibrary(page, ["Fixed points", "Octopus minds"]);
|
||||||
|
let s = await shown(page);
|
||||||
|
expect(s.vis).toHaveLength(2);
|
||||||
|
// Two panes, each too long for half the page: the one gone to has all but the other's tab.
|
||||||
|
expect(s.crowded).toBe(true);
|
||||||
|
expect(s.vis[s.active]).toBeGreaterThanOrEqual(s.h - 44 - 2);
|
||||||
|
expect(s.vis[1 - s.active]).toBeLessThanOrEqual(46);
|
||||||
|
await shot(page, `20-two-panes-${width}`);
|
||||||
|
// A tap on the other's tab: it has the height now.
|
||||||
|
const other = page.locator(".strip .pane.active").locator("xpath=..").locator(":scope > .pane:not(.active) > .tabline");
|
||||||
|
await other.first().tap();
|
||||||
|
await expect.poll(async () => (await shown(page)).active).toBe(1 - s.active);
|
||||||
|
s = await shown(page);
|
||||||
|
expect(s.vis[s.active]).toBeGreaterThanOrEqual(s.h - 44 - 2);
|
||||||
|
expect(s.vis[1 - s.active]).toBeLessThanOrEqual(46);
|
||||||
|
await stackFromLibrary(page, ["Where the elements come from"]);
|
||||||
|
s = await shown(page);
|
||||||
|
expect(s.vis).toHaveLength(3);
|
||||||
|
expect(s.vis[s.active]).toBeGreaterThanOrEqual(s.h - 2 * 44 - 2);
|
||||||
|
for (const [i, v] of s.vis.entries()) if (i !== s.active) expect(v).toBeLessThanOrEqual(46);
|
||||||
|
await shot(page, `21-three-panes-${width}`);
|
||||||
|
// Swiped back and forth, the page comes back the same: the active pane whole.
|
||||||
|
await swipe(page, 260);
|
||||||
|
await at(page, "Library", 0);
|
||||||
|
await swipe(page, -260);
|
||||||
|
await expect.poll(async () => (await shown(page)).vis[(await shown(page)).active]).toBeGreaterThanOrEqual(s.h - 2 * 44 - 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("on a wide screen a column still shares its height among panes that fit (the panes view is unchanged)", async ({ page }) => {
|
||||||
|
await page.setViewportSize({ width: 1400, height: 1000 });
|
||||||
|
await seedLinks(page.request);
|
||||||
|
await autoLayout(page);
|
||||||
|
await page.goto("/");
|
||||||
|
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
||||||
|
await expect(page.locator(".panes:not([data-layout])")).toHaveCount(1);
|
||||||
|
for (const t of ["Fixed points", "Octopus minds"]) await page.locator(".pane.root .rows .row", { hasText: t }).first().click();
|
||||||
|
const col = page.locator(".strip > .col").nth(1);
|
||||||
|
await expect(col.locator(":scope > .pane")).toHaveCount(2);
|
||||||
|
await expect(col).not.toHaveClass(/crowded/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the trail says how many panes each page holds: a dot each, the step's own filled; past four, their number; at 360 with a deep trail and long titles", async ({ page }) => {
|
||||||
|
await page.setViewportSize({ width: 360, height: 640 });
|
||||||
|
await start(page);
|
||||||
|
await stackFromLibrary(page, ["Octopus minds", "Fixed points", "Where the elements come from"]);
|
||||||
|
const step = page.locator(".trail-step.here");
|
||||||
|
await expect(step).toHaveAttribute("data-col-panes", "3");
|
||||||
|
await expect(step.locator(".trail-stack i")).toHaveCount(3);
|
||||||
|
const place = (await shown(page)).active;
|
||||||
|
const dots = await step.locator(".trail-stack i").evaluateAll((is) => is.map((i) => i.classList.contains("on")));
|
||||||
|
expect(dots.indexOf(true)).toBe(place);
|
||||||
|
expect(dots.filter(Boolean)).toHaveLength(1);
|
||||||
|
// The filled dot is the step's colour.
|
||||||
|
const fill = await rgb(page, await step.locator(".trail-stack i.on").evaluate((el) => getComputedStyle(el).backgroundColor));
|
||||||
|
const hue = await rgb(page, await step.evaluate((el) => getComputedStyle(el).getPropertyValue("--hue")));
|
||||||
|
expect(fill).toBe(hue);
|
||||||
|
// A page of one pane says nothing.
|
||||||
|
await expect(page.locator(".trail-step", { hasText: "Library" }).locator(".trail-stack, .trail-count")).toHaveCount(0);
|
||||||
|
await expect(step).toHaveAttribute("aria-label", /of 3 panes on its page/);
|
||||||
|
await stackFromLibrary(page, ["What a proof is", "The one merger"]);
|
||||||
|
await expect(page.locator(".trail-step.here")).toHaveAttribute("data-col-panes", "5");
|
||||||
|
await expect(page.locator(".trail-step.here .trail-count")).toHaveText("5");
|
||||||
|
await shot(page, "22-trail-counts-360");
|
||||||
|
// A deep trail with long titles: two panes on the third page, then deeper. The step on screen stays in view, each step a finger wide.
|
||||||
|
const titles = page.locator(".pane.active .rows .row .title");
|
||||||
|
const firstRows = (await titles.allTextContents()).slice(0, 2);
|
||||||
|
await titles.first().tap();
|
||||||
|
await expect.poll(() => active(page)).toBe(firstRows[0]);
|
||||||
|
await page.locator(".trail-step").nth(1).tap();
|
||||||
|
await row(page, firstRows[1]).tap();
|
||||||
|
await expect.poll(() => active(page)).toBe(firstRows[1]);
|
||||||
|
await expect(page.locator(".trail-step.here")).toHaveAttribute("data-col-panes", "2");
|
||||||
|
for (let d = 0; d < 2; d++) {
|
||||||
|
if (!(await titles.count())) break;
|
||||||
|
const t = (await titles.first().textContent())!;
|
||||||
|
await titles.first().tap();
|
||||||
|
await expect.poll(() => active(page)).toBe(t);
|
||||||
|
}
|
||||||
|
const here = (await page.locator(".trail-step.here").boundingBox())!;
|
||||||
|
const trail = (await page.locator(".trail-steps").boundingBox())!;
|
||||||
|
expect(here.x).toBeGreaterThanOrEqual(trail.x - 1);
|
||||||
|
expect(here.x + here.width).toBeLessThanOrEqual(trail.x + trail.width + 1);
|
||||||
|
for (const b of await page.locator(".trail-step").all()) expect(Math.round((await b.boundingBox())!.height)).toBeGreaterThanOrEqual(40);
|
||||||
|
await page.waitForTimeout(400);
|
||||||
|
await shot(page, "23-trail-deep-360");
|
||||||
|
await page.locator(".trail-steps").evaluate((el) => (el.scrollLeft = 0));
|
||||||
|
await shot(page, "23b-trail-deep-360-start");
|
||||||
|
});
|
||||||
|
|
||||||
|
/** How long the strip takes to come to rest on a page after `go`: from the tap's click to its first scroll, and from its first scroll event to its last change. */
|
||||||
|
async function glideTime(page: Page, go: () => Promise<void>): Promise<{ ms: number; lag: number; frames: number }> {
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const s = document.querySelector<HTMLElement>(".strip")!;
|
||||||
|
const w = window as any;
|
||||||
|
w.__glide = { click: 0, first: 0, last: 0, frames: 0, x: s.scrollLeft };
|
||||||
|
document.addEventListener("click", () => (w.__glide.click ||= performance.now()), { capture: true, once: true });
|
||||||
|
s.addEventListener("scroll", () => {
|
||||||
|
const g = w.__glide;
|
||||||
|
const now = performance.now();
|
||||||
|
if (!g.first) g.first = now;
|
||||||
|
if (Math.abs(s.scrollLeft - g.x) > 0.01) (g.last = now), g.frames++, (g.x = s.scrollLeft);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await go();
|
||||||
|
await expect.poll(() => snapped(page)).toBe(true);
|
||||||
|
await page.waitForTimeout(600);
|
||||||
|
return page.evaluate(() => {
|
||||||
|
const g = (window as any).__glide;
|
||||||
|
return { ms: Math.round(g.last - g.first), lag: Math.round(g.first - g.click), frames: g.frames };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test("a tap pages over fast: the strip glides in about 140 ms, easing out (the browser's smooth scroll took 300), at once with reduced motion; a swipe still snaps", async ({ page }) => {
|
||||||
|
await start(page);
|
||||||
|
const t1 = await glideTime(page, () => row(page, "Fixed points").tap());
|
||||||
|
await at(page, "Fixed points", 1);
|
||||||
|
const t2 = await glideTime(page, () => page.locator(".trail-step", { hasText: "Library" }).tap());
|
||||||
|
await at(page, "Library", 0);
|
||||||
|
console.log(`glide: forward ${t1.ms} ms in ${t1.frames} frames (${t1.lag} ms after the click), back ${t2.ms} ms in ${t2.frames} frames`);
|
||||||
|
for (const t of [t1, t2]) {
|
||||||
|
expect(t.ms).toBeLessThanOrEqual(180);
|
||||||
|
expect(t.frames).toBeGreaterThanOrEqual(3);
|
||||||
|
expect(t.lag).toBeLessThan(100);
|
||||||
|
}
|
||||||
|
// Snapping is the browser's again once it lands.
|
||||||
|
await expect(page.locator(".strip[data-gliding]")).toHaveCount(0);
|
||||||
|
expect(await page.locator(".strip").evaluate((el) => getComputedStyle(el).scrollSnapType)).toContain("mandatory");
|
||||||
|
// A finger mid-glide takes the strip from it; where it comes to rest decides.
|
||||||
|
await row(page, "Fixed points").tap();
|
||||||
|
await swipe(page, 200);
|
||||||
|
await expect.poll(() => snapped(page)).toBe(true);
|
||||||
|
await expect.poll(async () => (await pageIndex(page)) === (await state(page, (s) => s.paneAt))).toBe(true);
|
||||||
|
await page.locator(".trail-step", { hasText: "Library" }).tap();
|
||||||
|
await at(page, "Library", 0);
|
||||||
|
// Reduced motion: at once.
|
||||||
|
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||||
|
const t3 = await glideTime(page, () => row(page, "Fixed points").tap());
|
||||||
|
await at(page, "Fixed points", 1);
|
||||||
|
expect(t3.frames).toBeLessThanOrEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the map draws the forest as a tree: a line from each parent's mark down and across into each child's, in the child's colour; an orphan has none into it; a tall forest scrolls", async ({ page }) => {
|
||||||
|
await start(page);
|
||||||
|
await row(page, "Fixed points").tap();
|
||||||
|
await row(page, "Recursion without names").tap();
|
||||||
|
await at(page, "Recursion without names", 2);
|
||||||
|
await page.locator(".pane.active > .pane-ctl > .pin").tap();
|
||||||
|
await stackFromLibrary(page, ["Octopus minds"]);
|
||||||
|
await page.locator(".trail-map").tap();
|
||||||
|
const map = page.locator(".pane-map");
|
||||||
|
await expect(map.locator(".map-t")).toHaveText(["Library", "Fixed points", "Recursion without names", "Octopus minds"]);
|
||||||
|
/** Every row's lines, measured: kind, where (x, top, bottom), its colour and width, and the row's own mark. */
|
||||||
|
const measure = () =>
|
||||||
|
map.locator(".map-row").evaluateAll((rows) =>
|
||||||
|
rows.map((r) => {
|
||||||
|
const rr = r.getBoundingClientRect();
|
||||||
|
return {
|
||||||
|
tid: Number((r as HTMLElement).dataset.map),
|
||||||
|
hue: (r as HTMLElement).dataset.hue,
|
||||||
|
top: rr.top,
|
||||||
|
bottom: rr.bottom,
|
||||||
|
rails: [...r.querySelectorAll<HTMLElement>(".rail")].map((x) => {
|
||||||
|
const b = x.getBoundingClientRect();
|
||||||
|
const cs = getComputedStyle(x);
|
||||||
|
return { kind: x.dataset.rail!, to: Number(x.dataset.to), hue: x.dataset.hue, x: b.left, right: b.right, top: b.top, bottom: b.bottom, mid: rr.top + rr.height / 2, w: parseFloat(cs.borderLeftWidth) || parseFloat(cs.borderBottomWidth), color: cs.borderLeftColor !== "rgba(0, 0, 0, 0)" && parseFloat(cs.borderLeftWidth) ? cs.borderLeftColor : cs.borderBottomColor };
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const rows = await measure();
|
||||||
|
const byTid = new Map(rows.map((r) => [r.tid, r]));
|
||||||
|
const parentOf = await state(page, (s) => Object.fromEntries(s.panesPlaced.map((x: any) => [x.node.id, x.parent?.id ?? null])));
|
||||||
|
for (const r of rows) {
|
||||||
|
const elbow = r.rails.find((x) => x.kind === "elbow");
|
||||||
|
const p = parentOf[r.tid];
|
||||||
|
if (p === null) {
|
||||||
|
expect(elbow, "a root has no line into it").toBeUndefined();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Into a child, in its colour: the elbow drops from the parent's line, at the parent's line's x, to the row's middle.
|
||||||
|
expect(elbow!.hue).toBe(r.hue);
|
||||||
|
const pr = byTid.get(p)!;
|
||||||
|
const down = pr.rails.find((x) => x.kind === "down")!;
|
||||||
|
expect(Math.abs(elbow!.x - down.x)).toBeLessThan(0.5);
|
||||||
|
expect(Math.abs(elbow!.bottom - elbow!.mid)).toBeLessThan(1.5);
|
||||||
|
// Unbroken from the parent's mark to the child's: every row between has the line at that x.
|
||||||
|
for (const q of rows.filter((q) => q.top >= pr.bottom - 0.5 && q.bottom <= r.top + 0.5)) expect(q.rails.some((x) => (x.kind === "pass" || x.kind === "on") && Math.abs(x.x - down.x) < 0.5), `line through ${q.tid}`).toBe(true);
|
||||||
|
// On device pixels: whole CSS pixels, so a 1 or 2 px border lands on whole device pixels at any scale.
|
||||||
|
expect(elbow!.x).toBe(Math.round(elbow!.x));
|
||||||
|
}
|
||||||
|
// The colours are the panes' own: the line into Octopus minds is its pane's colour, at full strength along the focused branch.
|
||||||
|
const oct = rows.find((r) => r.rails.some((x) => x.kind === "elbow") && r.tid === (rows[rows.length - 1].tid))!;
|
||||||
|
const ocol = oct.rails.find((x) => x.kind === "elbow")!;
|
||||||
|
expect(ocol.w).toBe(2);
|
||||||
|
expect(await rgb(page, ocol.color)).toBe(await rgb(page, await page.locator(".trail-step.here").evaluate((el) => getComputedStyle(el).getPropertyValue("--hue"))));
|
||||||
|
await shot(page, "24-map-tree");
|
||||||
|
// An orphan: Fixed points closed, its pinned child stays, with no line into it.
|
||||||
|
await map.locator(".map-row", { hasText: "Fixed points" }).locator(".map-btn.close").tap();
|
||||||
|
await expect(map.locator(".map-t")).toHaveText(["Library", "Octopus minds", "Recursion without names"]);
|
||||||
|
const orphan = map.locator(".map-row", { hasText: "Recursion without names" });
|
||||||
|
await expect(orphan.locator(".rail[data-rail=elbow]")).toHaveCount(0);
|
||||||
|
await expect(orphan.locator(".rail[data-rail=dash]")).toHaveCount(1);
|
||||||
|
await shot(page, "25-map-orphan-tree");
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
// A deep and wide forest: every top-level section, and three levels under the first.
|
||||||
|
await state(page, (s) => {
|
||||||
|
const sec = (id: string) => s.snap.nodes[id].children.filter((c: string) => s.snap.nodes[c].kind === "section");
|
||||||
|
for (const c of sec(s.snap.root)) {
|
||||||
|
s.land(0);
|
||||||
|
s.openPane(0, { kind: "node", id: c });
|
||||||
|
}
|
||||||
|
s.land(0);
|
||||||
|
let id = sec(s.snap.root)[0];
|
||||||
|
s.openPane(0, { kind: "node", id });
|
||||||
|
for (let d = 1; d <= 3 && sec(id).length; d++) {
|
||||||
|
for (const k of sec(id).slice(0, 3)) {
|
||||||
|
s.land(d);
|
||||||
|
s.openPane(d, { kind: "node", id: k });
|
||||||
|
}
|
||||||
|
id = sec(id)[0];
|
||||||
|
s.land(d);
|
||||||
|
s.openPane(d, { kind: "node", id });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await page.locator(".trail-map").tap();
|
||||||
|
await expect.poll(() => map.locator(".map-row").count()).toBeGreaterThan(14);
|
||||||
|
const tall = await map.evaluate((el) => ({ sh: el.scrollHeight, ch: el.clientHeight }));
|
||||||
|
expect(tall.sh).toBeGreaterThan(tall.ch);
|
||||||
|
const deep = await measure();
|
||||||
|
for (const r of deep) for (const x of r.rails.filter((x) => x.kind === "elbow")) expect(x.right).toBeGreaterThan(x.x + 4);
|
||||||
|
await shot(page, "26-map-forest");
|
||||||
|
// A finger scrolls the sheet.
|
||||||
|
await map.evaluate((el) => (el.scrollTop = 0));
|
||||||
|
const m = (await map.boundingBox())!;
|
||||||
|
await swipe(page, 0, -200, { x: 200, y: m.y + m.height - 40 });
|
||||||
|
await expect.poll(() => map.evaluate((el) => el.scrollTop)).toBeGreaterThan(50);
|
||||||
|
await shot(page, "26b-map-forest-scrolled");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a press held on a pane's tab or the band above its title picks it up to move it down its page; a swipe or a tap there does what it did; Move up and down in its ⋯", async ({ page }) => {
|
||||||
|
await start(page);
|
||||||
|
await stackFromLibrary(page, ["Fixed points", "Octopus minds", "Where the elements come from"]);
|
||||||
|
const order = async () => (await shown(page)).titles;
|
||||||
|
const before = await order();
|
||||||
|
expect(before).toHaveLength(3);
|
||||||
|
const col = page.locator(".strip > .col").nth(1);
|
||||||
|
// The first pane's tab, held, then carried to the page's foot.
|
||||||
|
const tab = col.locator(":scope > .pane").first().locator(":scope > .tabline");
|
||||||
|
await expect(tab).toBeVisible();
|
||||||
|
const t = (await tab.boundingBox())!;
|
||||||
|
const c = (await col.boundingBox())!;
|
||||||
|
const from = { x: t.x + 60, y: t.y + t.height / 2 };
|
||||||
|
// Mid-carry: the pane lifted, its tab under the finger, a line where it will go; the page does not turn or scroll.
|
||||||
|
const cdp = await page.context().newCDPSession(page);
|
||||||
|
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [from] });
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
await expect(col.locator(":scope > .pane[data-lifted]")).toHaveCount(1);
|
||||||
|
for (let k = 1; k <= 12; k++) {
|
||||||
|
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: from.x + k, y: from.y + ((c.y + c.height - 20 - from.y) * k) / 12 }] });
|
||||||
|
await page.waitForTimeout(16);
|
||||||
|
}
|
||||||
|
await expect(page.locator(".drag-ghost")).toBeVisible();
|
||||||
|
await expect(page.locator(".drop-line")).toBeVisible();
|
||||||
|
const g = (await page.locator(".drag-ghost").boundingBox())!;
|
||||||
|
// Just above the finger, not under it.
|
||||||
|
expect(g.y + g.height).toBeLessThanOrEqual(c.y + c.height - 20);
|
||||||
|
expect(g.y + g.height).toBeGreaterThan(c.y + c.height - 20 - 60);
|
||||||
|
expect(await pageIndex(page)).toBe(1);
|
||||||
|
await shot(page, "28-carrying");
|
||||||
|
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||||
|
await cdp.detach();
|
||||||
|
await expect.poll(order).toEqual([before[1], before[2], before[0]]);
|
||||||
|
await expect(page.locator(".drag-ghost, .drop-line, .pane[data-lifted]")).toHaveCount(0);
|
||||||
|
expect(await pageIndex(page)).toBe(1);
|
||||||
|
await shot(page, "29-dropped");
|
||||||
|
// The active pane, by the band above its title, carried to the top.
|
||||||
|
const band = page.locator(".strip .pane.active > .grip");
|
||||||
|
await expect(band).toBeVisible();
|
||||||
|
const b = (await band.boundingBox())!;
|
||||||
|
expect(Math.round(b.height)).toBeGreaterThanOrEqual(44);
|
||||||
|
const activeTitle = (await shown(page)).titles[(await shown(page)).active];
|
||||||
|
await press(page, { x: b.x + 40, y: b.y + b.height / 2 }, { hold: 500, to: [{ x: b.x + 40, y: c.y + 10 }] });
|
||||||
|
await expect.poll(async () => (await order())[0]).toBe(activeTitle);
|
||||||
|
// A press held too briefly, then moved, is a swipe: the page turns, nothing moves.
|
||||||
|
const now = await order();
|
||||||
|
const t2 = (await col.locator(":scope > .pane[data-tab]:not(.active) > .tabline").first().boundingBox())!;
|
||||||
|
await press(page, { x: t2.x + 300, y: t2.y + 22 }, { to: [{ x: t2.x + 40, y: t2.y + 22 }] });
|
||||||
|
await expect.poll(() => pageIndex(page)).toBe(1);
|
||||||
|
expect(await order()).toEqual(now);
|
||||||
|
await swipe(page, 260, 0, { x: 80, y: t2.y + 22 });
|
||||||
|
await at(page, "Library", 0);
|
||||||
|
await swipe(page, -260);
|
||||||
|
await expect.poll(() => pageIndex(page)).toBe(1);
|
||||||
|
// A tap on a tab still goes to that pane.
|
||||||
|
const tab3 = col.locator(":scope > .pane[data-tab]:not(.active) > .tabline").first();
|
||||||
|
const name = await tab3.locator(".tabtitle").textContent();
|
||||||
|
await tab3.tap();
|
||||||
|
await expect.poll(() => active(page)).toBe(name);
|
||||||
|
// A second finger puts a held pane back where it was.
|
||||||
|
const keep = await order();
|
||||||
|
const t4 = (await col.locator(":scope > .pane[data-tab]:not(.active) > .tabline").first().boundingBox())!;
|
||||||
|
const cdp2 = await page.context().newCDPSession(page);
|
||||||
|
await cdp2.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x: t4.x + 60, y: t4.y + 22 }] });
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
await cdp2.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: t4.x + 60, y: c.y + c.height - 30 }] });
|
||||||
|
await cdp2.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x: t4.x + 60, y: c.y + c.height - 30 }, { x: 200, y: 300 }] });
|
||||||
|
await expect(page.locator(".drag-ghost")).toHaveCount(0);
|
||||||
|
await cdp2.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||||
|
await cdp2.detach();
|
||||||
|
expect(await order()).toEqual(keep);
|
||||||
|
// The ⋯: Move this pane up / down, a finger's size, and greyed where it cannot go.
|
||||||
|
await page.locator(".pane.active > .pane-ctl > .more").tap();
|
||||||
|
const sheet = page.locator(".menu.sheet");
|
||||||
|
const up = sheet.locator(".mi", { hasText: "Move this pane up" });
|
||||||
|
const down = sheet.locator(".mi", { hasText: "Move this pane down" });
|
||||||
|
await expect(up).toHaveCount(1);
|
||||||
|
await expect(down).toHaveCount(1);
|
||||||
|
for (const m of [up, down]) expect(Math.round((await m.boundingBox())!.height)).toBeGreaterThanOrEqual(40);
|
||||||
|
await down.scrollIntoViewIfNeeded();
|
||||||
|
await shot(page, "30-pane-menu-move");
|
||||||
|
const me = (await shown(page)).active;
|
||||||
|
const was = await order();
|
||||||
|
if (me > 0) {
|
||||||
|
await up.tap();
|
||||||
|
await expect.poll(async () => (await shown(page)).active).toBe(me - 1);
|
||||||
|
} else {
|
||||||
|
await down.tap();
|
||||||
|
await expect.poll(async () => (await shown(page)).active).toBe(me + 1);
|
||||||
|
}
|
||||||
|
expect((await order()).sort()).toEqual(was.sort());
|
||||||
|
// At the top, up is greyed.
|
||||||
|
for (let i = 0; i < 3; i++) await page.keyboard.press("Alt+Shift+k");
|
||||||
|
await expect.poll(async () => (await shown(page)).active).toBe(0);
|
||||||
|
await page.locator(".pane.active > .pane-ctl > .more").tap();
|
||||||
|
await expect(sheet.locator(".mi", { hasText: "Move this pane up" })).toHaveAttribute("aria-disabled", "true");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a held pane near a crowded page's foot scrolls the page under it", async ({ page }) => {
|
||||||
|
await page.setViewportSize({ width: 360, height: 640 });
|
||||||
|
await start(page);
|
||||||
|
await stackFromLibrary(page, ["Fixed points", "Octopus minds", "Where the elements come from", "What a proof is", "The one merger"]);
|
||||||
|
const col = page.locator(".strip > .col").nth(1);
|
||||||
|
await page.locator(".trail-step").nth(1).tap();
|
||||||
|
// The first pane's tab, at the top, carried to the foot and held there.
|
||||||
|
await col.evaluate((el) => (el.scrollTop = 0));
|
||||||
|
await page.keyboard.press("Alt+Shift+k");
|
||||||
|
for (let i = 0; i < 5; i++) await page.keyboard.press("Alt+k");
|
||||||
|
const s0 = await col.evaluate((el) => ({ top: el.scrollTop, max: el.scrollHeight - el.clientHeight }));
|
||||||
|
test.skip(s0.max < 20, "the page has nothing to scroll");
|
||||||
|
const tab = col.locator(":scope > .pane:not(.active) > .tabline").last();
|
||||||
|
const t = (await tab.boundingBox())!;
|
||||||
|
const c = (await col.boundingBox())!;
|
||||||
|
const before = await col.evaluate((el) => el.scrollTop);
|
||||||
|
const toward = t.y > c.y + c.height / 2 ? c.y + 6 : c.y + c.height - 6;
|
||||||
|
await press(page, { x: t.x + 60, y: t.y + 22 }, { hold: 500, to: [{ x: t.x + 60, y: toward }], wait: 600 });
|
||||||
|
expect(Math.abs((await col.evaluate((el) => el.scrollTop)) - before)).toBeGreaterThan(10);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const width of [390, 360])
|
||||||
|
test(`at ${width}: the selection bar is one row, a finger high; its actions scroll sideways and its ⋯ and × stay at its end; above an on-screen keyboard too`, async ({ page }) => {
|
||||||
|
await page.setViewportSize({ width, height: 800 });
|
||||||
|
await start(page);
|
||||||
|
await row(page, "Fixed points").tap();
|
||||||
|
await row(page, "Recursion without names").tap();
|
||||||
|
await at(page, "Recursion without names", 2);
|
||||||
|
const spot = await page.evaluate(() => {
|
||||||
|
const body = document.querySelector(".pane.active .pane-body > .body")!;
|
||||||
|
const walk = document.createTreeWalker(body, NodeFilter.SHOW_TEXT);
|
||||||
|
for (let t = walk.nextNode(); t; t = walk.nextNode()) {
|
||||||
|
const i = t.textContent!.indexOf("cannot call itself");
|
||||||
|
if (i < 0) continue;
|
||||||
|
const r = document.createRange();
|
||||||
|
r.setStart(t, i + 3);
|
||||||
|
r.setEnd(t, i + 5);
|
||||||
|
const b = r.getBoundingClientRect();
|
||||||
|
return { x: b.x + b.width / 2, y: b.y + b.height / 2 };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
await page.touchscreen.tap(spot!.x, spot!.y);
|
||||||
|
const bar = page.locator(".selbar.docked");
|
||||||
|
await expect(bar).toBeVisible();
|
||||||
|
const b = (await bar.boundingBox())!;
|
||||||
|
expect(b.height).toBeLessThanOrEqual(48);
|
||||||
|
expect(Math.round(b.width)).toBe(width);
|
||||||
|
const status = (await page.locator(".status").boundingBox())!;
|
||||||
|
expect(Math.abs(b.y + b.height - status.y)).toBeLessThan(2);
|
||||||
|
for (const x of await bar.locator("button").all()) {
|
||||||
|
const r = (await x.boundingBox())!;
|
||||||
|
expect(Math.round(r.height)).toBeGreaterThanOrEqual(44);
|
||||||
|
expect(Math.round(r.width)).toBeGreaterThanOrEqual(44);
|
||||||
|
}
|
||||||
|
// ⋯ and × at the end, whole on screen, the × last.
|
||||||
|
const more = (await bar.locator(".bar-more").boundingBox())!;
|
||||||
|
const done = (await bar.locator(".bar-done").boundingBox())!;
|
||||||
|
expect(Math.round(done.x + done.width)).toBe(width);
|
||||||
|
expect(Math.round(more.x + more.width)).toBe(Math.round(done.x));
|
||||||
|
// The actions overflow, fade at the end, and a finger scrolls them to link….
|
||||||
|
const acts = bar.locator(".bar-acts");
|
||||||
|
await expect(acts).toHaveAttribute("data-after", "");
|
||||||
|
await shot(page, `31-selbar-${width}`);
|
||||||
|
const a = (await acts.boundingBox())!;
|
||||||
|
await swipe(page, -200, 0, { x: a.x + a.width - 20, y: a.y + a.height / 2 });
|
||||||
|
await expect(acts).toHaveAttribute("data-before", "");
|
||||||
|
const link = (await bar.locator("button[data-key=w]").boundingBox())!;
|
||||||
|
expect(link.x + link.width).toBeLessThanOrEqual(more.x + 1);
|
||||||
|
// Scrolling the bar turned no page and kept the selection.
|
||||||
|
expect(await pageIndex(page)).toBe(2);
|
||||||
|
expect(await state(page, (s) => s.selectedText())).toBeTruthy();
|
||||||
|
await shot(page, `32-selbar-${width}-scrolled`);
|
||||||
|
// An on-screen keyboard raises it with the status line.
|
||||||
|
await page.evaluate(() => document.documentElement.style.setProperty("--kb", "260px"));
|
||||||
|
const b2 = (await bar.boundingBox())!;
|
||||||
|
const s2 = (await page.locator(".status").boundingBox())!;
|
||||||
|
expect(Math.abs(b2.y + b2.height - s2.y)).toBeLessThan(2);
|
||||||
|
expect(Math.round(800 - (s2.y + s2.height))).toBe(260);
|
||||||
|
await page.evaluate(() => document.documentElement.style.removeProperty("--kb"));
|
||||||
|
// Its × puts it away (an action would write into the library the tests share).
|
||||||
|
await bar.locator(".bar-done").tap();
|
||||||
|
await expect(bar).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a tap on a link only opens it: no hover card from the tap's mouse events, and none left over a page that changes; a long press still shows the card", async ({ page }) => {
|
||||||
|
await start(page);
|
||||||
|
await row(page, "Fixed points").tap();
|
||||||
|
await row(page, "Recursion without names").tap();
|
||||||
|
await at(page, "Recursion without names", 2);
|
||||||
|
for (const words of ["fixed-point combinator", "Y combinator"]) {
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const w = window as any;
|
||||||
|
w.__events = [];
|
||||||
|
for (const t of ["pointerover", "pointerdown", "pointerup", "mouseover", "mousemove", "mousedown", "mouseup", "click"]) document.addEventListener(t, (e) => w.__events.push(`${t}${(e as PointerEvent).pointerType ? `:${(e as PointerEvent).pointerType}` : ""}`), true);
|
||||||
|
});
|
||||||
|
const link = page.locator(".pane.active .lnk", { hasText: words }).first();
|
||||||
|
const l = (await link.boundingBox())!;
|
||||||
|
const x = l.x + 12;
|
||||||
|
const y = l.y + l.height / 2;
|
||||||
|
await touchTap(page, x, y);
|
||||||
|
// A phone's browser may send its compatibility mouse events late, after the tap: so does this test.
|
||||||
|
await page.evaluate(([x, y]) => {
|
||||||
|
const t = document.elementFromPoint(x, y) ?? document.body;
|
||||||
|
for (const type of ["mouseover", "mousemove"]) t.dispatchEvent(new MouseEvent(type, { bubbles: true, clientX: x, clientY: y }));
|
||||||
|
}, [x, y]);
|
||||||
|
const want = words === "fixed-point combinator" ? "Fixed-point combinator" : "How Y works";
|
||||||
|
await at(page, want, 3);
|
||||||
|
const events: string[] = await page.evaluate(() => (window as any).__events);
|
||||||
|
// The browser did send mouse events after the tap, as a phone's does.
|
||||||
|
expect(events).toContain("mouseover");
|
||||||
|
await page.waitForTimeout(900);
|
||||||
|
await expect(page.locator(".popup")).toHaveCount(0);
|
||||||
|
if (words === "fixed-point combinator") await shot(page, "27-link-tapped");
|
||||||
|
await swipe(page, 260);
|
||||||
|
await at(page, "Recursion without names", 2);
|
||||||
|
await page.waitForTimeout(600);
|
||||||
|
await expect(page.locator(".popup")).toHaveCount(0);
|
||||||
|
}
|
||||||
|
// A card showing (a mouse resting on a link, on a touch screen with a mouse too) goes when the page changes.
|
||||||
|
await state(page, (s) => {
|
||||||
|
const id = Object.values(s.snap.nodes).find((n: any) => n.kind === "note" && n.ref && n.anchors?.[0]?.text === "Y combinator") as any;
|
||||||
|
s.popup = { note: id.id, x: 100, top: 400, bottom: 420 };
|
||||||
|
s.emit();
|
||||||
|
});
|
||||||
|
await expect(page.locator(".popup")).toHaveCount(1);
|
||||||
|
await page.locator(".trail-step", { hasText: "Library" }).tap();
|
||||||
|
await at(page, "Library", 0);
|
||||||
|
await expect(page.locator(".popup")).toHaveCount(0);
|
||||||
|
// The long press still shows the card, above the menu, and only there.
|
||||||
|
await page.locator(".trail-step", { hasText: "Recursion without names" }).tap();
|
||||||
|
await at(page, "Recursion without names", 2);
|
||||||
|
const link = page.locator(".pane.active .lnk", { hasText: "fixed-point combinator" }).first();
|
||||||
|
const l = (await link.boundingBox())!;
|
||||||
|
await link.dispatchEvent("contextmenu", { clientX: l.x + 10, clientY: l.y + 5, bubbles: true, cancelable: true });
|
||||||
|
await expect(page.locator(".menu.sheet .menu-card .lcard")).toBeVisible();
|
||||||
|
await expect(page.locator(".popup")).toHaveCount(0);
|
||||||
|
});
|
||||||
+25
-5
@@ -13,7 +13,7 @@ import { PaneMap, Trail } from "./Pages";
|
|||||||
import { PANES_MIN_WIDTH, store, type Aux, type WRow } from "./store";
|
import { PANES_MIN_WIDTH, store, type Aux, type WRow } from "./store";
|
||||||
import { WikiPage, WikiView } from "./Wiki";
|
import { WikiPage, WikiView } from "./Wiki";
|
||||||
import { Usage } from "./Usage";
|
import { Usage } from "./Usage";
|
||||||
import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, hideBar, locate, locateIn, menuAt, menuShown, setCard, setPrompt, showBar, type Hint } from "./Mouse";
|
import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, hideBar, locate, locateIn, menuAt, menuShown, setCard, setPrompt, showBar, touch, type Hint } from "./Mouse";
|
||||||
import { press } from "./press";
|
import { press } from "./press";
|
||||||
|
|
||||||
function Page() {
|
function Page() {
|
||||||
@@ -324,7 +324,8 @@ function Popup() {
|
|||||||
*/
|
*/
|
||||||
function FocusPopup() {
|
function FocusPopup() {
|
||||||
const f = store.focus;
|
const f = store.focus;
|
||||||
const note = f.grain !== "node" && store.mode === "normal" && !store.popup && !store.aux ? store.noteAt(f.range) : undefined;
|
// Not on touch: a long press shows the card above its menu, and a tap only opens the link.
|
||||||
|
const note = f.grain !== "node" && store.mode === "normal" && !store.popup && !store.aux && !touch() ? store.noteAt(f.range) : undefined;
|
||||||
const n = note ? store.snap.nodes[note] : undefined;
|
const n = note ? store.snap.nodes[note] : undefined;
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
@@ -466,6 +467,15 @@ function StatusLine() {
|
|||||||
// ---- the app ----
|
// ---- the app ----
|
||||||
|
|
||||||
let hover: ReturnType<typeof setTimeout> | undefined;
|
let hover: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
/** A press or a click: a preview waiting to show does not, and one showing goes. */
|
||||||
|
function dropPopup() {
|
||||||
|
clearTimeout(hover);
|
||||||
|
if (!store.popup) return;
|
||||||
|
store.popup = null;
|
||||||
|
store.emit(store.top);
|
||||||
|
}
|
||||||
|
/** The active pane when last drawn: a preview does not outlive a move to another. */
|
||||||
|
let shownPane = "";
|
||||||
/** The focus last scrolled into view (App's layout effect). */
|
/** The focus last scrolled into view (App's layout effect). */
|
||||||
let shownFocus = "";
|
let shownFocus = "";
|
||||||
|
|
||||||
@@ -570,6 +580,9 @@ export function App() {
|
|||||||
const key = JSON.stringify([f, store.aux, store.mode, store.panes, store.top, store.colWiki?.title]);
|
const key = JSON.stringify([f, store.aux, store.mode, store.panes, store.top, store.colWiki?.title]);
|
||||||
const moved = key !== shownFocus;
|
const moved = key !== shownFocus;
|
||||||
shownFocus = key;
|
shownFocus = key;
|
||||||
|
// Another pane opened or gone to (as pages, another page): no preview stays over it.
|
||||||
|
const pane = store.panes ? `${store.paneAt}|${store.branchNodes[store.paneAt]?.id}` : "";
|
||||||
|
if (pane !== shownPane) (shownPane = pane), dropPopup();
|
||||||
const el =
|
const el =
|
||||||
moved &&
|
moved &&
|
||||||
!store.panes &&
|
!store.panes &&
|
||||||
@@ -594,7 +607,7 @@ export function App() {
|
|||||||
|
|
||||||
const panes = store.panes;
|
const panes = store.panes;
|
||||||
// A click opens beside what is open (so do Ctrl-, Cmd- and middle clicks); a Shift-click in its place.
|
// A click opens beside what is open (so do Ctrl-, Cmd- and middle clicks); a Shift-click in its place.
|
||||||
const onClick = (e: MouseEvent) => store.withReplace(e.shiftKey, () => click(e));
|
const onClick = (e: MouseEvent) => (dropPopup(), store.withReplace(e.shiftKey, () => click(e)));
|
||||||
const click = (e: MouseEvent) => {
|
const click = (e: MouseEvent) => {
|
||||||
if (store.mode === "edit") return;
|
if (store.mode === "edit") return;
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
@@ -758,7 +771,14 @@ export function App() {
|
|||||||
if (menuAt(t, { x: e.clientX, y: e.clientY })) e.preventDefault();
|
if (menuAt(t, { x: e.clientX, y: e.clientY })) e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onOver = (e: MouseEvent) => {
|
/*
|
||||||
|
* The hover preview is the mouse's: a finger's tap also sends pointerover (and the browser's
|
||||||
|
* compatibility mouseover and mousemove after it, sometimes late), and a card from it would open
|
||||||
|
* over the pane the tap opened. So only a mouse pointer's over counts; a long press shows the card
|
||||||
|
* on touch (Mouse.tsx menuAt).
|
||||||
|
*/
|
||||||
|
const onOver = (e: PointerEvent) => {
|
||||||
|
if (e.pointerType !== "mouse") return;
|
||||||
const anchor = (e.target as HTMLElement).closest<HTMLElement>("[data-note]");
|
const anchor = (e.target as HTMLElement).closest<HTMLElement>("[data-note]");
|
||||||
clearTimeout(hover);
|
clearTimeout(hover);
|
||||||
if (!anchor?.dataset.note || store.open.has(anchor.dataset.note as NodeId)) {
|
if (!anchor?.dataset.note || store.open.has(anchor.dataset.note as NodeId)) {
|
||||||
@@ -771,7 +791,7 @@ export function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={`app mode-${store.mode}${store.mode === "history" || store.mode === "review" ? " with-panel" : ""}${store.libs ? " with-left" : ""}${panes ? " view-panes" : ""}${store.pages ? " view-pages" : ""}`} onMouseOver={onOver} onContextMenu={onContext}>
|
<div class={`app mode-${store.mode}${store.mode === "history" || store.mode === "review" ? " with-panel" : ""}${store.libs ? " with-left" : ""}${panes ? " view-panes" : ""}${store.pages ? " view-pages" : ""}`} onPointerOver={onOver} onPointerDown={dropPopup} onContextMenu={onContext}>
|
||||||
<main
|
<main
|
||||||
class="page"
|
class="page"
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
|||||||
+19
-2
@@ -108,16 +108,17 @@ export function menuHere(where: Where): Entry[] {
|
|||||||
if (store.selectedText() !== null) return selectionEntries(selCtx(), act);
|
if (store.selectedText() !== null) return selectionEntries(selCtx(), act);
|
||||||
const a = store.aux;
|
const a = store.aux;
|
||||||
const pinned = !!store.branchNodes[store.paneAt]?.pinned;
|
const pinned = !!store.branchNodes[store.paneAt]?.pinned;
|
||||||
|
const moves = store.paneMoves();
|
||||||
if (a?.kind === "wiki") {
|
if (a?.kind === "wiki") {
|
||||||
const h = store.wikiHost(a.host);
|
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 (store.panes && (where === "pane" || a.row.t === "head")) return paneEntries(a.host.startsWith("n") ? { node: nodeCtx(a.host.slice(1) as NodeId), pinned, ...moves } : { article: h?.title, pinned, ...moves }, act);
|
||||||
if (a.row.t === "sec" || a.row.t === "sense") return articleRowEntries(h?.title ?? "Wikipedia", store.panes, act, store.pages);
|
if (a.row.t === "sec" || a.row.t === "sense") return articleRowEntries(h?.title ?? "Wikipedia", store.panes, act, store.pages);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (a) return [];
|
if (a) return [];
|
||||||
const id = store.focus.node;
|
const id = store.focus.node;
|
||||||
if (!store.snap.nodes[id]) return [];
|
if (!store.snap.nodes[id]) return [];
|
||||||
if (where === "pane" && store.panes) return paneEntries({ node: nodeCtx(id), pinned }, act);
|
if (where === "pane" && store.panes) return paneEntries({ node: nodeCtx(id), pinned, ...moves }, act);
|
||||||
return nodeEntries(nodeCtx(id), act);
|
return nodeEntries(nodeCtx(id), act);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,8 +460,22 @@ export function SelBar() {
|
|||||||
const on = barFor !== null && store.mode === "normal" && barFor === focusKey() && store.selectedText() !== null;
|
const on = barFor !== null && store.mode === "normal" && barFor === focusKey() && store.selectedText() !== null;
|
||||||
const docked = touch();
|
const docked = touch();
|
||||||
const was = useRef(false);
|
const was = useRef(false);
|
||||||
|
/** Docked, the actions are one row that scrolls sideways, its ⋯ and × kept at its end: which ends have more beyond them (a fade says so). */
|
||||||
|
const acts = useRef<HTMLDivElement>(null);
|
||||||
|
const edges = () => {
|
||||||
|
const a = acts.current;
|
||||||
|
if (!a) return;
|
||||||
|
const more = a.scrollWidth - a.clientWidth > 1;
|
||||||
|
a.toggleAttribute("data-before", more && a.scrollLeft > 1);
|
||||||
|
a.toggleAttribute("data-after", more && a.scrollLeft < a.scrollWidth - a.clientWidth - 1);
|
||||||
|
};
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (on) placeBar(ref.current, !was.current);
|
if (on) placeBar(ref.current, !was.current);
|
||||||
|
if (on && docked) {
|
||||||
|
// A new selection starts the row from its first action.
|
||||||
|
if (!was.current && acts.current) acts.current.scrollLeft = 0;
|
||||||
|
edges();
|
||||||
|
}
|
||||||
was.current = on;
|
was.current = on;
|
||||||
});
|
});
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
@@ -491,6 +506,7 @@ export function SelBar() {
|
|||||||
};
|
};
|
||||||
const bar = (
|
const bar = (
|
||||||
<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()}>
|
<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()}>
|
||||||
|
<div class="bar-acts" ref={acts} onScroll={edges}>
|
||||||
{groups.map((g, i) => (
|
{groups.map((g, i) => (
|
||||||
<Fragment key={i}>
|
<Fragment key={i}>
|
||||||
{i > 0 && <span class="bar-sep" />}
|
{i > 0 && <span class="bar-sep" />}
|
||||||
@@ -502,6 +518,7 @@ export function SelBar() {
|
|||||||
))}
|
))}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
|
</div>
|
||||||
<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 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>
|
</button>
|
||||||
|
|||||||
+69
-11
@@ -7,6 +7,7 @@
|
|||||||
import { useLayoutEffect, useRef } from "preact/hooks";
|
import { useLayoutEffect, useRef } from "preact/hooks";
|
||||||
import { label } from "../core/model";
|
import { label } from "../core/model";
|
||||||
import { store, type PaneRef } from "./store";
|
import { store, type PaneRef } from "./store";
|
||||||
|
import { mapStep, rails, type Rail } from "./pages";
|
||||||
import { article } from "./wiki";
|
import { article } from "./wiki";
|
||||||
|
|
||||||
/** What a pane is called: its node's title, or its article's (a section of one by its heading). */
|
/** What a pane is called: its node's title, or its article's (a section of one by its heading). */
|
||||||
@@ -19,6 +20,25 @@ export function paneTitle(p: PaneRef): string {
|
|||||||
|
|
||||||
const W = () => <b class="wmark">W</b>;
|
const W = () => <b class="wmark">W</b>;
|
||||||
|
|
||||||
|
/** Up to this many panes in a column, a trail step shows a dot for each; beyond, their number. */
|
||||||
|
export const STACK_DOTS = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many panes the page of a step holds, when more than one: a dot for each, top to bottom as they
|
||||||
|
* stand down the page, the step's own filled in its colour; beyond STACK_DOTS, their number.
|
||||||
|
*/
|
||||||
|
function Stack({ i, n }: { i: number; n: number }) {
|
||||||
|
if (n < 2) return null;
|
||||||
|
if (n > STACK_DOTS) return <span class="trail-count" aria-hidden="true">{n}</span>;
|
||||||
|
return (
|
||||||
|
<span class="trail-stack" aria-hidden="true">
|
||||||
|
{Array.from({ length: n }, (_, j) => (
|
||||||
|
<i key={j} class={j === i ? "on" : undefined} />
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** The trail: the focused branch, a step per pane, and the map's button. */
|
/** The trail: the focused branch, a step per pane, and the map's button. */
|
||||||
export function Trail() {
|
export function Trail() {
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
@@ -35,18 +55,27 @@ export function Trail() {
|
|||||||
else if (l + el.offsetWidth > row.scrollLeft + row.clientWidth - 8) row.scrollLeft = l + el.offsetWidth - row.clientWidth + 24;
|
else if (l + el.offsetWidth > row.scrollLeft + row.clientWidth - 8) row.scrollLeft = l + el.offsetWidth - row.clientWidth + 24;
|
||||||
}, [here, nodes.length]);
|
}, [here, nodes.length]);
|
||||||
const count = store.panesPlaced.length;
|
const count = store.panesPlaced.length;
|
||||||
|
/** Each pane's place down its column, and how many the column holds. */
|
||||||
|
const down = new Map<number, { i: number; n: number }>();
|
||||||
|
for (const ps of store.paneColumns.values()) ps.forEach((x, i) => down.set(x.node.id, { i, n: ps.length }));
|
||||||
return (
|
return (
|
||||||
<nav class="trail" aria-label="The panes on the way to this one">
|
<nav class="trail" aria-label="The panes on the way to this one">
|
||||||
<div class="trail-steps" ref={ref}>
|
<div class="trail-steps" ref={ref}>
|
||||||
{nodes.map((n, i) => (
|
{nodes.map((n, i) => {
|
||||||
|
const d = down.get(n.id);
|
||||||
|
const t = paneTitle(n.ref);
|
||||||
|
const name = d && d.n > 1 ? `${t} · ${d.i + 1} of ${d.n} panes on its page` : t;
|
||||||
|
return (
|
||||||
<button
|
<button
|
||||||
key={n.id}
|
key={n.id}
|
||||||
type="button"
|
type="button"
|
||||||
class={`trail-step${i === at ? " here" : ""}${i > at ? " ahead" : ""}`}
|
class={`trail-step${i === at ? " here" : ""}${i > at ? " ahead" : ""}`}
|
||||||
data-trail={n.id}
|
data-trail={n.id}
|
||||||
data-hue={n.hue}
|
data-hue={n.hue}
|
||||||
|
data-col-panes={d && d.n > 1 ? d.n : undefined}
|
||||||
aria-current={i === at ? "page" : undefined}
|
aria-current={i === at ? "page" : undefined}
|
||||||
title={paneTitle(n.ref)}
|
aria-label={name}
|
||||||
|
title={name}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
store.showMap(false);
|
store.showMap(false);
|
||||||
@@ -54,9 +83,11 @@ export function Trail() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{n.ref.kind === "wiki" && <W />}
|
{n.ref.kind === "wiki" && <W />}
|
||||||
<span class="trail-t">{paneTitle(n.ref)}</span>
|
<span class="trail-t">{t}</span>
|
||||||
|
{d && <Stack i={d.i} n={d.n} />}
|
||||||
</button>
|
</button>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -87,11 +118,32 @@ const Close = () => (
|
|||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** Where a level's line runs down the map, and where a row's mark starts and ends (px from the row's left). */
|
||||||
|
const MAP_LEFT = 10;
|
||||||
|
const MARK = 14;
|
||||||
|
const markAt = (level: number, step: number) => MAP_LEFT + level * step;
|
||||||
|
const lineAt = (level: number, step: number) => markAt(level, step) + 3;
|
||||||
|
|
||||||
|
/** One stroke of the tree lines (pages.ts `rails`), as a box with borders: crisp on any screen. */
|
||||||
|
function RailLine({ r, step, hue, on }: { r: Rail; step: number; hue?: number; on: boolean }) {
|
||||||
|
const x = lineAt(r.level, step);
|
||||||
|
const style =
|
||||||
|
r.kind === "dash"
|
||||||
|
? { left: `${markAt(r.level, step)}px`, width: `${MARK}px`, top: 0, height: "50%" }
|
||||||
|
: r.kind === "elbow"
|
||||||
|
? { left: `${x}px`, width: `${markAt(r.level + 1, step) + MARK - x}px`, top: 0, height: "50%" }
|
||||||
|
: r.kind === "pass"
|
||||||
|
? { left: `${x}px`, top: 0, bottom: 0 }
|
||||||
|
: { left: `${r.kind === "down" ? lineAt(r.level, step) : x}px`, top: "50%", bottom: 0 };
|
||||||
|
return <span class={`rail r-${r.kind}${on ? " strong" : ""}`} data-hue={hue} data-rail={r.kind} data-to={r.tid} style={style} aria-hidden="true" />;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The map: every open pane, tree by tree, each indented by its column under the pane it was
|
* The map: every open pane, tree by tree, as a tree: each indented by its column under the pane it
|
||||||
* opened from, with its colour; the active pane marked, the focused branch in the text's ink. A
|
* was opened from, a line from the parent's mark down and across into each child's, in the child's
|
||||||
* tap on a pane goes to it; its pin and × act on it where it is. A press outside, Esc or the
|
* colour (stronger along the focused branch), as the curves run on a wide screen; the active pane
|
||||||
* trail's map button puts it away.
|
* marked, the focused branch in the text's ink. A tap on a pane goes to it; its pin and × act on it
|
||||||
|
* where it is. A press outside, Esc or the trail's map button puts it away.
|
||||||
*/
|
*/
|
||||||
export function PaneMap() {
|
export function PaneMap() {
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
@@ -115,6 +167,9 @@ export function PaneMap() {
|
|||||||
const placed = store.panesPlaced;
|
const placed = store.panesPlaced;
|
||||||
const branch = new Set(store.branchNodes.map((n) => n.id));
|
const branch = new Set(store.branchNodes.map((n) => n.id));
|
||||||
const active = store.branchNodes[store.paneAt]?.id;
|
const active = store.branchNodes[store.paneAt]?.id;
|
||||||
|
const lines = rails(placed);
|
||||||
|
const step = mapStep(placed.reduce((m, x) => Math.max(m, x.col), 0));
|
||||||
|
const hues = new Map(placed.map((x) => [x.node.id, x.node.hue]));
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class="pane-map"
|
class="pane-map"
|
||||||
@@ -134,7 +189,7 @@ export function PaneMap() {
|
|||||||
<span class="map-hint">swipe sideways to go from pane to pane</span>
|
<span class="map-hint">swipe sideways to go from pane to pane</span>
|
||||||
</div>
|
</div>
|
||||||
<ul class="map-rows">
|
<ul class="map-rows">
|
||||||
{placed.map((x) => {
|
{placed.map((x, i) => {
|
||||||
const id = x.node.id;
|
const id = x.node.id;
|
||||||
const first = x.ti === 0 && x.depth === 0;
|
const first = x.ti === 0 && x.depth === 0;
|
||||||
const orphan = x.ti > 0 && x.depth === 0;
|
const orphan = x.ti > 0 && x.depth === 0;
|
||||||
@@ -145,10 +200,13 @@ export function PaneMap() {
|
|||||||
class={`map-row${id === active ? " here" : ""}${branch.has(id) ? " on-branch" : ""}${pinned ? " pinned" : ""}`}
|
class={`map-row${id === active ? " here" : ""}${branch.has(id) ? " on-branch" : ""}${pinned ? " pinned" : ""}`}
|
||||||
data-map={id}
|
data-map={id}
|
||||||
data-hue={x.node.hue}
|
data-hue={x.node.hue}
|
||||||
style={{ "--depth": Math.min(x.col, 8) }}
|
data-level={x.col}
|
||||||
|
style={{ paddingLeft: `${markAt(x.col, step) + MARK + 2}px` }}
|
||||||
>
|
>
|
||||||
|
{lines[i].map((r, k) => (
|
||||||
|
<RailLine key={k} r={r} step={step} hue={hues.get(r.tid)} on={branch.has(r.tid)} />
|
||||||
|
))}
|
||||||
<button type="button" class="map-go" aria-current={id === active ? "page" : undefined} onClick={() => (store.showMap(false), store.toPane(id))}>
|
<button type="button" class="map-go" aria-current={id === active ? "page" : undefined} onClick={() => (store.showMap(false), store.toPane(id))}>
|
||||||
<span class="map-dash" aria-hidden="true" />
|
|
||||||
{x.node.ref.kind === "wiki" && <W />}
|
{x.node.ref.kind === "wiki" && <W />}
|
||||||
<span class="map-t">{paneTitle(x.node.ref)}</span>
|
<span class="map-t">{paneTitle(x.node.ref)}</span>
|
||||||
{orphan && <span class="map-sub">its source closed</span>}
|
{orphan && <span class="map-sub">its source closed</span>}
|
||||||
|
|||||||
+219
-51
@@ -19,7 +19,7 @@ import { Component, type ComponentChildren } from "preact";
|
|||||||
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
||||||
import { ancestors, label, sections, staleness, type NodeId } from "../core/model";
|
import { ancestors, label, sections, staleness, type NodeId } from "../core/model";
|
||||||
import { LANES, LANE_FIRST, LANE_LAST, LANE_PITCH, laneOrder } from "./lanes";
|
import { LANES, LANE_FIRST, LANE_LAST, LANE_PITCH, laneOrder } from "./lanes";
|
||||||
import { ACROSS, DOWN, mark, offsets, reveal, starts, stick, unmark, whole } from "./stack";
|
import { ACROSS, DOWN, crowds, fill, mark, offsets, reveal, starts, stick, unmark, whole } from "./stack";
|
||||||
import { NodeBacklinks, NodeRelated, PaneCtx, TargetRow } from "./Links";
|
import { NodeBacklinks, NodeRelated, PaneCtx, TargetRow } from "./Links";
|
||||||
import { pageAt, paneOfPage } from "./pages";
|
import { pageAt, paneOfPage } from "./pages";
|
||||||
import { Abstract, Flags, NodeBody, PendingSections, Row, TitleEditor, TopMatter, isPrompt } from "./Node";
|
import { Abstract, Flags, NodeBody, PendingSections, Row, TitleEditor, TopMatter, isPrompt } from "./Node";
|
||||||
@@ -139,8 +139,8 @@ function Chrome({ props, title, mark }: { props: PaneProps; title: string; mark?
|
|||||||
{title}
|
{title}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="grip" data-grip={tid} title="Drag to move this pane up or down its column" />
|
<div class="grip" data-grip={tid} title="Drag to move this pane up or down its column (on a phone, hold it first)" onTouchMove={onHandleMove} />
|
||||||
<div class="tabline" data-spine={props.index} title={title}>
|
<div class="tabline" data-spine={props.index} title={title} onTouchMove={onHandleMove}>
|
||||||
{mark}
|
{mark}
|
||||||
<span class="tabtitle">{title}</span>
|
<span class="tabtitle">{title}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -262,6 +262,43 @@ function PaneRow({ id, showing, forked, active }: { id: NodeId; showing: boolean
|
|||||||
|
|
||||||
const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As pages, how long the strip takes to glide to a page the page itself goes to (a tap on a row or
|
||||||
|
* a link, the trail, the map, Back): short, easing out. The browser's smooth scroll takes twice as
|
||||||
|
* long or more, at its own pace; a finger's swipe keeps the browser's own snapping.
|
||||||
|
*/
|
||||||
|
export const GLIDE_MS = 140;
|
||||||
|
/** The strip's glide under way: its frame. */
|
||||||
|
const glides = new WeakMap<HTMLElement, number>();
|
||||||
|
/** Whether the strip is gliding (its scroll events are its own, not a finger's). */
|
||||||
|
const gliding = (el: HTMLElement) => glides.has(el);
|
||||||
|
/** Stop a glide where it is (a finger has touched the strip): the snapping is the browser's again. */
|
||||||
|
function stopGlide(el: HTMLElement) {
|
||||||
|
const f = glides.get(el);
|
||||||
|
if (f === undefined) return;
|
||||||
|
cancelAnimationFrame(f);
|
||||||
|
glides.delete(el);
|
||||||
|
el.removeAttribute("data-gliding");
|
||||||
|
}
|
||||||
|
/** Glide the strip to a scroll offset, easing out (a cubic), without snapping on the way (data-gliding), landing exactly there. */
|
||||||
|
function glideTo(el: HTMLElement, to: number, done: () => void, ms = GLIDE_MS) {
|
||||||
|
stopGlide(el);
|
||||||
|
const from = el.scrollLeft;
|
||||||
|
if (ms <= 0 || Math.abs(to - from) < 1) return void ((el.scrollLeft = to), done());
|
||||||
|
el.setAttribute("data-gliding", "");
|
||||||
|
let t0 = -1;
|
||||||
|
const step = (now: number) => {
|
||||||
|
if (t0 < 0) t0 = now - 1000 / 60;
|
||||||
|
const p = Math.min(1, (now - t0) / ms);
|
||||||
|
el.scrollLeft = from + (to - from) * (1 - (1 - p) ** 3);
|
||||||
|
if (p < 1) return void glides.set(el, requestAnimationFrame(step));
|
||||||
|
glides.delete(el);
|
||||||
|
el.removeAttribute("data-gliding");
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
glides.set(el, requestAnimationFrame(step));
|
||||||
|
}
|
||||||
|
|
||||||
/** Scroll a pane vertically, as little as possible, so that an element in it is in view. */
|
/** Scroll a pane vertically, as little as possible, so that an element in it is in view. */
|
||||||
function nearestY(el: Element | null | false) {
|
function nearestY(el: Element | null | false) {
|
||||||
const box = el && el.closest<HTMLElement>(".pane-scroll");
|
const box = el && el.closest<HTMLElement>(".pane-scroll");
|
||||||
@@ -299,26 +336,14 @@ export const PANE_MIN = 260;
|
|||||||
export let TAB = 30;
|
export let TAB = 30;
|
||||||
const DESK_TAB = 30;
|
const DESK_TAB = 30;
|
||||||
export const PAGE_TAB = 44;
|
export const PAGE_TAB = 44;
|
||||||
|
/** As pages, how long a finger is held still on a pane's tab or the band above its title to pick the pane up. */
|
||||||
|
export const HOLD_MS = 380;
|
||||||
|
/** The touch drag's move handler (Panes' effect sets it); the handles call it from their own, blocking, touchmove listeners. */
|
||||||
|
let handleMove: ((e: TouchEvent) => void) | null = null;
|
||||||
|
const onHandleMove = (e: TouchEvent) => handleMove?.(e);
|
||||||
/** How long the mouse rests on a covered pane before it peeks out. */
|
/** How long the mouse rests on a covered pane before it peeks out. */
|
||||||
export const PEEK_MS = 200;
|
export const PEEK_MS = 200;
|
||||||
|
|
||||||
/**
|
|
||||||
* Heights for the panes of one column of height h, from what each needs to show all it holds:
|
|
||||||
* each gets that, or an equal share of what is left, whichever is less; what no pane needs goes to
|
|
||||||
* the one that needs most. So short panes are no taller than their text, and long ones share the rest.
|
|
||||||
*/
|
|
||||||
export function fill(h: number, needs: number[]): number[] {
|
|
||||||
const out = needs.map(() => 0);
|
|
||||||
const order = needs.map((_, i) => i).sort((a, b) => needs[a] - needs[b]);
|
|
||||||
let rest = h;
|
|
||||||
order.forEach((i, k) => {
|
|
||||||
const share = rest / (order.length - k);
|
|
||||||
out[i] = Math.floor(k === order.length - 1 ? rest : Math.min(needs[i], share));
|
|
||||||
rest -= out[i];
|
|
||||||
});
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The panes drawn, by their id in the forest. */
|
/** The panes drawn, by their id in the forest. */
|
||||||
const paneEls = (el: HTMLElement) => {
|
const paneEls = (el: HTMLElement) => {
|
||||||
const m = new Map<number, HTMLElement>();
|
const m = new Map<number, HTMLElement>();
|
||||||
@@ -359,6 +384,8 @@ export function Panes() {
|
|||||||
const instant = useRef(true);
|
const instant = useRef(true);
|
||||||
/** The follow of the latest render (the swipe handlers use it). */
|
/** The follow of the latest render (the swipe handlers use it). */
|
||||||
const followNow = useRef<() => void>(() => {});
|
const followNow = useRef<() => void>(() => {});
|
||||||
|
/** As pages: a finger is on the strip. */
|
||||||
|
const fingers = useRef(false);
|
||||||
/** The layout last drawn: pages or side by side. */
|
/** The layout last drawn: pages or side by side. */
|
||||||
const wasPages = useRef<boolean | null>(null);
|
const wasPages = useRef<boolean | null>(null);
|
||||||
|
|
||||||
@@ -422,7 +449,11 @@ export function Panes() {
|
|||||||
return n;
|
return n;
|
||||||
});
|
});
|
||||||
const pinned = ps.map((p) => p.classList.contains("pinned"));
|
const pinned = ps.map((p) => p.classList.contains("pinned"));
|
||||||
const crowded = need.reduce((s, x) => s + Math.min(x, PANE_MIN), 0) > h;
|
// The pane to show whole: on the focused branch, or the one last on it here.
|
||||||
|
const here = tids.find((t) => onBranch.has(t)) ?? (tids.includes(lastIn.current.get(col)!) ? lastIn.current.get(col)! : tids[0]);
|
||||||
|
const k = tids.indexOf(here);
|
||||||
|
// As pages the pane looked at has the screen's height whenever a share would cut it short: the others fold to their tabs.
|
||||||
|
const crowded = crowds(h, need, PANE_MIN, pages ? k : undefined);
|
||||||
let heights: number[];
|
let heights: number[];
|
||||||
let tops: number[] = [];
|
let tops: number[] = [];
|
||||||
/** What the panes after each leave at the column's foot: a tab each, a pinned one its whole height. */
|
/** What the panes after each leave at the column's foot: a tab each, a pinned one its whole height. */
|
||||||
@@ -450,9 +481,6 @@ export function Panes() {
|
|||||||
if (p.style.bottom !== v) p.style.bottom = v;
|
if (p.style.bottom !== v) p.style.bottom = v;
|
||||||
});
|
});
|
||||||
} else for (const p of ps) (p.style.top = ""), (p.style.bottom = "");
|
} else for (const p of ps) (p.style.top = ""), (p.style.bottom = "");
|
||||||
// The pane to show whole: on the focused branch, or the one last on it here.
|
|
||||||
const here = tids.find((t) => onBranch.has(t)) ?? (tids.includes(lastIn.current.get(col)!) ? lastIn.current.get(col)! : tids[0]);
|
|
||||||
const k = tids.indexOf(here);
|
|
||||||
const st = starts(heights);
|
const st = starts(heights);
|
||||||
const want = crowded ? reveal(c.scrollTop, h - below[k], st[k], heights[k], tops[k], st[st.length - 1] + heights[heights.length - 1] - h) : 0;
|
const want = crowded ? reveal(c.scrollTop, h - below[k], st[k], heights[k], tops[k], st[st.length - 1] + heights[heights.length - 1] - h) : 0;
|
||||||
// As the focus moves, the active pane's column scrolls at once and the others once the keys pause (each brings whole panes into view, which costs a frame's painting); any other change, at once.
|
// As the focus moves, the active pane's column scrolls at once and the others once the keys pause (each brings whole panes into view, which costs a frame's painting); any other change, at once.
|
||||||
@@ -538,8 +566,12 @@ export function Panes() {
|
|||||||
const now = instant.current;
|
const now = instant.current;
|
||||||
instant.current = false;
|
instant.current = false;
|
||||||
if (Math.abs(target - el.scrollLeft) > 1) {
|
if (Math.abs(target - el.scrollLeft) > 1) {
|
||||||
|
// Not under a finger: where the strip comes to rest decides (the swipe's handlers).
|
||||||
|
if (fingers.current) return;
|
||||||
programmatic.current = !now;
|
programmatic.current = !now;
|
||||||
el.scrollTo({ left: target, behavior: now || reducedMotion() ? "auto" : "smooth" });
|
if (now || reducedMotion()) (stopGlide(el), (el.scrollLeft = target));
|
||||||
|
// Landed where it was sent: the scroll was the page's, and is over.
|
||||||
|
else glideTo(el, target, () => (programmatic.current = false));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -628,11 +660,10 @@ export function Panes() {
|
|||||||
* browser has none), never per frame.
|
* browser has none), never per frame.
|
||||||
*/
|
*/
|
||||||
let rest: ReturnType<typeof setTimeout> | undefined;
|
let rest: ReturnType<typeof setTimeout> | undefined;
|
||||||
let touching = false;
|
|
||||||
const settle = () => {
|
const settle = () => {
|
||||||
clearTimeout(rest);
|
clearTimeout(rest);
|
||||||
if (!store.pages) return;
|
if (!store.pages || gliding(el)) return;
|
||||||
if (touching) return void (rest = setTimeout(settle, 120));
|
if (fingers.current) return void (rest = setTimeout(settle, 120));
|
||||||
const colEls = [...el.querySelectorAll<HTMLElement>(":scope > .col")];
|
const colEls = [...el.querySelectorAll<HTMLElement>(":scope > .col")];
|
||||||
const c = colEls[pageAt(el.scrollLeft, el.clientWidth, colEls.length)];
|
const c = colEls[pageAt(el.scrollLeft, el.clientWidth, colEls.length)];
|
||||||
const ours = programmatic.current;
|
const ours = programmatic.current;
|
||||||
@@ -650,10 +681,15 @@ export function Panes() {
|
|||||||
if (id !== undefined) store.toPane(id);
|
if (id !== undefined) store.toPane(id);
|
||||||
};
|
};
|
||||||
const ends = "onscrollend" in window;
|
const ends = "onscrollend" in window;
|
||||||
const onTouch = (e: TouchEvent) => (touching = e.type === "touchstart" || e.touches.length > 0);
|
const onTouch = (e: TouchEvent) => {
|
||||||
|
fingers.current = e.type === "touchstart" || e.touches.length > 0;
|
||||||
|
// A finger on the strip takes it from a glide, where it is.
|
||||||
|
if (e.type === "touchstart") (stopGlide(el), (programmatic.current = false));
|
||||||
|
};
|
||||||
el.addEventListener("touchstart", onTouch, { passive: true });
|
el.addEventListener("touchstart", onTouch, { passive: true });
|
||||||
el.addEventListener("touchend", onTouch, { passive: true });
|
// Its end heard on the window: a touch whose target leaves the page (a pane that closed) ends there too.
|
||||||
el.addEventListener("touchcancel", onTouch, { passive: true });
|
window.addEventListener("touchend", onTouch, { passive: true, capture: true });
|
||||||
|
window.addEventListener("touchcancel", onTouch, { passive: true, capture: true });
|
||||||
if (ends) el.addEventListener("scrollend", settle);
|
if (ends) el.addEventListener("scrollend", settle);
|
||||||
const onScroll = (e: Event) => {
|
const onScroll = (e: Event) => {
|
||||||
const t = e.target as HTMLElement;
|
const t = e.target as HTMLElement;
|
||||||
@@ -810,12 +846,13 @@ export function Panes() {
|
|||||||
/*
|
/*
|
||||||
* Dragging a pane up or down its column, by its grip (the band above its title, beside the pin
|
* Dragging a pane up or down its column, by its grip (the band above its title, beside the pin
|
||||||
* and the x) or its tab: a line shows where it will go; Esc cancels. The column's order is then
|
* and the x) or its tab: a line shows where it will go; Esc cancels. The column's order is then
|
||||||
* its own (forks.ts `reorder`), kept with the panes.
|
* its own (forks.ts `reorder`), kept with the panes. With the mouse (or a pen, or a finger on a
|
||||||
|
* wide screen's panes) by pointer events; as pages, by touch, below.
|
||||||
*/
|
*/
|
||||||
let drag: { tid: number; col: HTMLElement; y0: number; on: boolean; before: number | null; line: HTMLElement | null } | null = null;
|
let drag: { tid: number; col: HTMLElement; y0: number; on: boolean; before: number | null; line: HTMLElement | null; touch?: boolean } | null = null;
|
||||||
let swallow = false;
|
let swallow = false;
|
||||||
const onDown = (e: PointerEvent) => {
|
const onDown = (e: PointerEvent) => {
|
||||||
if (e.button !== 0) return;
|
if (e.button !== 0 || (e.pointerType === "touch" && store.pages)) return;
|
||||||
const t = e.target as HTMLElement;
|
const t = e.target as HTMLElement;
|
||||||
if (t.closest("[data-close], [data-pin]")) return;
|
if (t.closest("[data-close], [data-pin]")) return;
|
||||||
const handle = t.closest<HTMLElement>("[data-grip], .tabline");
|
const handle = t.closest<HTMLElement>("[data-grip], .tabline");
|
||||||
@@ -825,17 +862,17 @@ export function Panes() {
|
|||||||
drag = { tid: Number(pane.dataset.tid), col, y0: e.clientY, on: false, before: null, line: null };
|
drag = { tid: Number(pane.dataset.tid), col, y0: e.clientY, on: false, before: null, line: null };
|
||||||
handle.setPointerCapture(e.pointerId);
|
handle.setPointerCapture(e.pointerId);
|
||||||
};
|
};
|
||||||
const onDrag = (e: PointerEvent) => {
|
const startDrag = () => {
|
||||||
if (!drag) return;
|
drag!.on = true;
|
||||||
if (!drag.on) {
|
|
||||||
if (Math.abs(e.clientY - drag.y0) < 5) return;
|
|
||||||
drag.on = true;
|
|
||||||
unpeek();
|
unpeek();
|
||||||
wrap.classList.add("dragging");
|
wrap.classList.add("dragging");
|
||||||
drag.line = document.createElement("div");
|
drag!.line = document.createElement("div");
|
||||||
drag.line.className = "drop-line";
|
drag!.line.className = "drop-line";
|
||||||
wrap.appendChild(drag.line);
|
wrap.appendChild(drag!.line);
|
||||||
}
|
};
|
||||||
|
/** Where the dragged pane would go with the pointer at y: the line drawn there. */
|
||||||
|
const dropAt = (y0: number) => {
|
||||||
|
if (!drag) return;
|
||||||
const panes = [...drag.col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
const panes = [...drag.col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||||
const mine = panes.findIndex((p) => Number(p.dataset.tid) === drag!.tid);
|
const mine = panes.findIndex((p) => Number(p.dataset.tid) === drag!.tid);
|
||||||
const others = panes.filter((_, k) => k !== mine);
|
const others = panes.filter((_, k) => k !== mine);
|
||||||
@@ -846,28 +883,146 @@ export function Panes() {
|
|||||||
// itself, one that was above lets it in before. So reaching any part of a pane is enough, in
|
// itself, one that was above lets it in before. So reaching any part of a pane is enough, in
|
||||||
// either direction.
|
// either direction.
|
||||||
let k = -1;
|
let k = -1;
|
||||||
while (k + 1 < others.length && tops[k + 1] <= e.clientY) k++;
|
while (k + 1 < others.length && tops[k + 1] <= y0) k++;
|
||||||
const at = k < 0 ? 0 : k >= mine || e.clientY >= ends[k] ? k + 1 : k;
|
const at = k < 0 ? 0 : k >= mine || y0 >= ends[k] ? k + 1 : k;
|
||||||
const i = at < others.length ? at : -1;
|
const i = at < others.length ? at : -1;
|
||||||
drag.before = i < 0 ? null : Number(others[i].dataset.tid);
|
drag.before = i < 0 ? null : Number(others[i].dataset.tid);
|
||||||
const y = at === 0 ? (tops[0] ?? c.top) : ends[at - 1];
|
const y = at === 0 ? (tops[0] ?? c.top) : ends[at - 1];
|
||||||
const box = wrap.getBoundingClientRect();
|
const box = wrap.getBoundingClientRect();
|
||||||
Object.assign(drag.line!.style, { left: `${c.left - box.left}px`, width: `${c.width}px`, top: `${y - box.top - 1}px` });
|
Object.assign(drag.line!.style, { left: `${c.left - box.left}px`, width: `${c.width}px`, top: `${Math.round(Math.max(c.top, Math.min(c.bottom - 3, y)) - box.top - 1)}px` });
|
||||||
|
// The carried tab rides just above the finger, where it is not under it.
|
||||||
|
if (ghost) ghost.style.top = `${Math.round(Math.max(c.top, Math.min(c.bottom - PAGE_TAB, y0 - PAGE_TAB - 18)) - box.top)}px`;
|
||||||
|
};
|
||||||
|
const onDrag = (e: PointerEvent) => {
|
||||||
|
if (!drag || drag.touch) return;
|
||||||
|
if (!drag.on) {
|
||||||
|
if (Math.abs(e.clientY - drag.y0) < 5) return;
|
||||||
|
startDrag();
|
||||||
|
}
|
||||||
|
dropAt(e.clientY);
|
||||||
};
|
};
|
||||||
const end = (keep: boolean) => {
|
const end = (keep: boolean) => {
|
||||||
|
cancelHold();
|
||||||
if (!drag) return;
|
if (!drag) return;
|
||||||
const d = drag;
|
const d = drag;
|
||||||
drag = null;
|
drag = null;
|
||||||
d.line?.remove();
|
d.line?.remove();
|
||||||
wrap.classList.remove("dragging");
|
wrap.classList.remove("dragging");
|
||||||
|
ghost?.remove();
|
||||||
|
ghost = null;
|
||||||
|
cancelAnimationFrame(edge);
|
||||||
|
edge = 0;
|
||||||
|
for (const p of d.col.querySelectorAll(":scope > .pane[data-lifted]")) p.removeAttribute("data-lifted");
|
||||||
if (d.on) {
|
if (d.on) {
|
||||||
swallow = true;
|
// The click a mouse's drag ends with is not a click on the pane (a touch drag's end sends none: its touchend is held back).
|
||||||
|
swallow = !d.touch;
|
||||||
setTimeout(() => (swallow = false), 0);
|
setTimeout(() => (swallow = false), 0);
|
||||||
if (keep) store.reorderPane(d.tid, d.before);
|
if (keep) store.reorderPane(d.tid, d.before);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onUp = () => end(true);
|
const onUp = () => !drag?.touch && end(true);
|
||||||
const onCancel = () => end(false);
|
const onCancel = () => !drag?.touch && end(false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As pages, by touch: a press held still on a pane's tab, or on the band above its title
|
||||||
|
* (HOLD_MS, never moving more than a few pixels, so a swipe still turns the page and a drag down
|
||||||
|
* still scrolls) picks the pane up: it fades where it is, its tab rides with the finger, and the
|
||||||
|
* line shows where it will go. Near the column's top or foot a crowded column scrolls on its
|
||||||
|
* own. Lifting the finger puts it there; a second finger, or the touch being cancelled, puts it
|
||||||
|
* back. Only the handles listen to touchmove blocking (Chrome `onTouchMove`), and only a lifted
|
||||||
|
* pane's moves are held from the browser's scrolling.
|
||||||
|
*/
|
||||||
|
let hold: { timer: ReturnType<typeof setTimeout>; x: number; y: number; id: number; pane: HTMLElement; col: HTMLElement } | null = null;
|
||||||
|
let ghost: HTMLElement | null = null;
|
||||||
|
let edge = 0;
|
||||||
|
let lastY = 0;
|
||||||
|
function cancelHold() {
|
||||||
|
if (!hold) return;
|
||||||
|
clearTimeout(hold.timer);
|
||||||
|
hold = null;
|
||||||
|
}
|
||||||
|
const lift = () => {
|
||||||
|
const h = hold;
|
||||||
|
hold = null;
|
||||||
|
if (!h || !store.pages || !h.pane.isConnected) return;
|
||||||
|
drag = { tid: Number(h.pane.dataset.tid), col: h.col, y0: h.y, on: false, before: null, line: null, touch: true };
|
||||||
|
startDrag();
|
||||||
|
wrap.classList.add("lifting");
|
||||||
|
h.pane.setAttribute("data-lifted", "");
|
||||||
|
ghost = document.createElement("div");
|
||||||
|
ghost.className = "drag-ghost";
|
||||||
|
if (h.pane.dataset.hue !== undefined) ghost.dataset.hue = h.pane.dataset.hue;
|
||||||
|
ghost.innerHTML = h.pane.querySelector(":scope > .tabline")?.innerHTML ?? "";
|
||||||
|
const c = h.col.getBoundingClientRect();
|
||||||
|
const box = wrap.getBoundingClientRect();
|
||||||
|
Object.assign(ghost.style, { left: `${c.left - box.left}px`, width: `${c.width}px` });
|
||||||
|
wrap.appendChild(ghost);
|
||||||
|
lastY = h.y;
|
||||||
|
dropAt(h.y);
|
||||||
|
try {
|
||||||
|
navigator.vibrate?.(8);
|
||||||
|
} catch {
|
||||||
|
/* no vibration here */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** Near a crowded column's top or foot, it scrolls under the lifted pane, faster the nearer. */
|
||||||
|
const edgeScroll = () => {
|
||||||
|
edge = 0;
|
||||||
|
if (!drag?.touch) return;
|
||||||
|
const c = drag.col.getBoundingClientRect();
|
||||||
|
const zone = 56;
|
||||||
|
const v = lastY < c.top + zone ? -(c.top + zone - lastY) / zone : lastY > c.bottom - zone ? (lastY - (c.bottom - zone)) / zone : 0;
|
||||||
|
if (!v || !drag.col.classList.contains("crowded")) return;
|
||||||
|
const was = drag.col.scrollTop;
|
||||||
|
drag.col.scrollTop += Math.round(Math.max(-1, Math.min(1, v)) * 14);
|
||||||
|
dropAt(lastY);
|
||||||
|
if (drag.col.scrollTop !== was) edge = requestAnimationFrame(edgeScroll);
|
||||||
|
};
|
||||||
|
const onHoldStart = (e: TouchEvent) => {
|
||||||
|
if (!store.pages) return;
|
||||||
|
// A second finger: whatever was being picked up or carried goes back.
|
||||||
|
if (e.touches.length > 1) return void (hold || drag?.touch ? end(false) : undefined);
|
||||||
|
const t = e.target as HTMLElement;
|
||||||
|
if (t.closest("[data-close], [data-pin], [data-more]")) return;
|
||||||
|
const handle = t.closest<HTMLElement>("[data-grip], .tabline");
|
||||||
|
const pane = handle?.closest<HTMLElement>(".pane");
|
||||||
|
const col = pane?.parentElement as HTMLElement | undefined;
|
||||||
|
if (!handle || !pane || !col || col.querySelectorAll(":scope > .pane").length < 2) return;
|
||||||
|
const p = e.changedTouches[0];
|
||||||
|
cancelHold();
|
||||||
|
hold = { timer: setTimeout(lift, HOLD_MS), x: p.clientX, y: p.clientY, id: p.identifier, pane, col };
|
||||||
|
};
|
||||||
|
const touchOf = (e: TouchEvent, id: number) => [...e.touches].find((x) => x.identifier === id);
|
||||||
|
// Passive, on the strip: a press that moves before it is held long enough is a swipe or a scroll, and picks nothing up.
|
||||||
|
const onHoldMove = (e: TouchEvent) => {
|
||||||
|
if (!hold) return;
|
||||||
|
const p = touchOf(e, hold.id);
|
||||||
|
if (!p || Math.hypot(p.clientX - hold.x, p.clientY - hold.y) > 8) cancelHold();
|
||||||
|
};
|
||||||
|
// Blocking, on the handles only (Chrome's onTouchMove): a lifted pane follows the finger, and the page does not scroll.
|
||||||
|
handleMove = (e: TouchEvent) => {
|
||||||
|
if (!drag?.touch) return;
|
||||||
|
e.preventDefault();
|
||||||
|
const p = [...e.touches][0];
|
||||||
|
if (!p) return;
|
||||||
|
lastY = p.clientY;
|
||||||
|
dropAt(lastY);
|
||||||
|
if (!edge) edge = requestAnimationFrame(edgeScroll);
|
||||||
|
};
|
||||||
|
const onHoldEnd = (e: TouchEvent) => {
|
||||||
|
if (drag?.touch) {
|
||||||
|
// No click after it: the drop is all it does.
|
||||||
|
if (e.cancelable) e.preventDefault();
|
||||||
|
return end(e.type === "touchend");
|
||||||
|
}
|
||||||
|
cancelHold();
|
||||||
|
};
|
||||||
|
// The browser's own long press (a menu, a callout) has nothing to offer while a pane is held or carried.
|
||||||
|
const onLongPress = (e: Event) => {
|
||||||
|
if (!hold && !drag?.touch) return;
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
};
|
||||||
const onKey = (e: KeyboardEvent) => {
|
const onKey = (e: KeyboardEvent) => {
|
||||||
if (drag?.on && e.key === "Escape") {
|
if (drag?.on && e.key === "Escape") {
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
@@ -882,6 +1037,11 @@ export function Panes() {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
el.addEventListener("touchstart", onHoldStart, { passive: true });
|
||||||
|
el.addEventListener("touchmove", onHoldMove, { passive: true });
|
||||||
|
el.addEventListener("touchend", onHoldEnd);
|
||||||
|
el.addEventListener("touchcancel", onHoldEnd);
|
||||||
|
window.addEventListener("contextmenu", onLongPress, true);
|
||||||
// A press elsewhere puts a peeking pane back; on it, the click goes through to it (and makes it the active pane), and then it goes back.
|
// A press elsewhere puts a peeking pane back; on it, the click goes through to it (and makes it the active pane), and then it goes back.
|
||||||
const onPress = (e: PointerEvent) => !peeked.some((p) => p.contains(e.target as Node)) && unpeek();
|
const onPress = (e: PointerEvent) => !peeked.some((p) => p.contains(e.target as Node)) && unpeek();
|
||||||
const afterClick = () => peeked.length && requestAnimationFrame(unpeek);
|
const afterClick = () => peeked.length && requestAnimationFrame(unpeek);
|
||||||
@@ -894,13 +1054,14 @@ export function Panes() {
|
|||||||
window.addEventListener("keydown", onKey, true);
|
window.addEventListener("keydown", onKey, true);
|
||||||
window.addEventListener("click", onClick, true);
|
window.addEventListener("click", onClick, true);
|
||||||
return () => {
|
return () => {
|
||||||
|
stopGlide(el);
|
||||||
cancelAnimationFrame(frame.current);
|
cancelAnimationFrame(frame.current);
|
||||||
clearTimeout(later.current);
|
clearTimeout(later.current);
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
clearTimeout(rest);
|
clearTimeout(rest);
|
||||||
el.removeEventListener("touchstart", onTouch);
|
el.removeEventListener("touchstart", onTouch);
|
||||||
el.removeEventListener("touchend", onTouch);
|
window.removeEventListener("touchend", onTouch, { capture: true });
|
||||||
el.removeEventListener("touchcancel", onTouch);
|
window.removeEventListener("touchcancel", onTouch, { capture: true });
|
||||||
if (ends) el.removeEventListener("scrollend", settle);
|
if (ends) el.removeEventListener("scrollend", settle);
|
||||||
wrap.removeEventListener("scroll", onScroll, { capture: true });
|
wrap.removeEventListener("scroll", onScroll, { capture: true });
|
||||||
window.removeEventListener(GEOMETRY, schedule);
|
window.removeEventListener(GEOMETRY, schedule);
|
||||||
@@ -920,6 +1081,13 @@ export function Panes() {
|
|||||||
el.removeEventListener("pointercancel", onCancel);
|
el.removeEventListener("pointercancel", onCancel);
|
||||||
window.removeEventListener("keydown", onKey, true);
|
window.removeEventListener("keydown", onKey, true);
|
||||||
window.removeEventListener("click", onClick, true);
|
window.removeEventListener("click", onClick, true);
|
||||||
|
end(false);
|
||||||
|
handleMove = null;
|
||||||
|
el.removeEventListener("touchstart", onHoldStart);
|
||||||
|
el.removeEventListener("touchmove", onHoldMove);
|
||||||
|
el.removeEventListener("touchend", onHoldEnd);
|
||||||
|
el.removeEventListener("touchcancel", onHoldEnd);
|
||||||
|
window.removeEventListener("contextmenu", onLongPress, true);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -201,6 +201,9 @@ export interface PaneCtx {
|
|||||||
/** An article's pane: its title. */
|
/** An article's pane: its title. */
|
||||||
article?: string;
|
article?: string;
|
||||||
pinned: boolean;
|
pinned: boolean;
|
||||||
|
/** Whether it can move up, or down, its column (another pane is above it, or below). */
|
||||||
|
above?: boolean;
|
||||||
|
below?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function paneEntries(c: PaneCtx, act: Act): Entry[] {
|
export function paneEntries(c: PaneCtx, act: Act): Entry[] {
|
||||||
@@ -218,6 +221,8 @@ export function paneEntries(c: PaneCtx, act: Act): Entry[] {
|
|||||||
{ label: "below", key: "A-j", run: () => act.press("A-j") },
|
{ label: "below", key: "A-j", run: () => act.press("A-j") },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
(c.above || c.below) && key(act, "Move this pane up", "A-k", { shift: true, keyText: "Alt+⇧k", disabled: !c.above, sub: "in its column" }),
|
||||||
|
(c.above || c.below) && key(act, "Move this pane down", "A-j", { shift: true, keyText: "Alt+⇧j", disabled: !c.below, sub: "in its column" }),
|
||||||
key(act, "Pin this pane", "P", { checked: c.pinned, sub: "it stays when what opened it closes" }),
|
key(act, "Pin this pane", "P", { checked: c.pinned, sub: "it stays when what opened it closes" }),
|
||||||
key(act, "Close this pane", "q", { sub: "with what was opened from it" }),
|
key(act, "Close this pane", "q", { sub: "with what was opened from it" }),
|
||||||
key(act, "Show as one column", "v"),
|
key(act, "Show as one column", "v"),
|
||||||
|
|||||||
+11
-2
@@ -21,6 +21,7 @@ export const HELP: [string, [string, string][]][] = [
|
|||||||
["Shift+Enter", "in panes: open in place of the focused branch's pane in the next column (so does a Shift-click)"],
|
["Shift+Enter", "in panes: open in place of the focused branch's pane in the next column (so does a Shift-click)"],
|
||||||
["Alt+h Alt+l", "in panes: the pane this one was opened from (left) / one opened from it (right): the one opened from the focused row or link if it is open, else the one last visited; from a node, a selection or an article alike. Left then right comes back"],
|
["Alt+h Alt+l", "in panes: the pane this one was opened from (left) / one opened from it (right): the one opened from the focused row or link if it is open, else the one last visited; from a node, a selection or an article alike. Left then right comes back"],
|
||||||
["Alt+k Alt+j", "in panes: the pane above / below in the same column, across forks (Alt+↑ ↓ and [ ] too)"],
|
["Alt+k Alt+j", "in panes: the pane above / below in the same column, across forks (Alt+↑ ↓ and [ ] too)"],
|
||||||
|
["Alt+Shift+k j", "in panes: move the active pane up / down its column, as dragging it by its grip or tab does (Alt+Shift+↑ ↓ too; the pane's ⋯ menu offers the same)"],
|
||||||
["[ ]", "in panes: the pane above / below in the same column (back where you were in it, or at its head); at the top or bottom nothing moves. A crowded column stacks its panes as the strip stacks columns, covered to a tab; resting the mouse on a covered pane peeks it out; its grip or tab drags it up or down. A faint curve runs from where each pane was opened to its title"], ],
|
["[ ]", "in panes: the pane above / below in the same column (back where you were in it, or at its head); at the top or bottom nothing moves. A crowded column stacks its panes as the strip stacks columns, covered to a tab; resting the mouse on a covered pane peeks it out; its grip or tab drags it up or down. A faint curve runs from where each pane was opened to its title"], ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@@ -30,7 +31,7 @@ export const HELP: [string, [string, string][]][] = [
|
|||||||
["", "right-click (a long press on a phone) on words, a row, a link, a note or a pane: what can be done with it, Copy first. Shift+right-click is the browser's own menu"],
|
["", "right-click (a long press on a phone) on words, a row, a link, a note or a pane: what can be done with it, Copy first. Shift+right-click is the browser's own menu"],
|
||||||
["", "⋯ by a row, a pane's pin, a page's byline or a note (shown when pointed at): the same menu. A stale flag, clicked, offers what to do about it"],
|
["", "⋯ by a row, a pane's pin, a page's byline or a note (shown when pointed at): the same menu. A stale flag, clicked, offers what to do about it"],
|
||||||
["", "the top bar: the library's name (it opens the libraries panel), undo, redo, and menu: libraries, jump, history, links, layout and settings. A key named in the status line or a panel's head is a button that presses it"],
|
["", "the top bar: the library's name (it opens the libraries panel), undo, redo, and menu: libraries, jump, history, links, layout and settings. A key named in the status line or a panel's head is a button that presses it"],
|
||||||
["", "on a phone the panes are pages, a column each: a tap on a row or a link goes to its pane, a swipe sideways goes from page to page, Back goes back a pane. The trail at the foot names the panes on the way, each in its colour (a tap goes there); its map lists every open pane, to go to, pin or close. What a pane was opened from takes its colour. A long press on a link shows what it opens"],
|
["", "on a phone the panes are pages, a column each: a tap on a row or a link goes to its pane, a swipe sideways goes from page to page, Back goes back a pane. The pane gone to has the page's height; the others in its column fold to their tabs. The trail at the foot names the panes on the way, each in its colour (a tap goes there), with a dot for each pane in that page's column, the one on the way filled; its map draws every open pane as a tree, each branch in its colour, to go to, pin or close. What a pane was opened from takes its colour. A long press on a link shows what it opens; a tap on one only opens it. A press held on a pane's tab, or on the band above its title, picks the pane up to move it up or down its page (the pane's ⋯ has Move up and Move down too)"],
|
||||||
["", "in the libraries panel a click on a row opens that library; its ⋯ (or a right-click) offers open, rename, delete and a new library; a press outside the panel closes it"],
|
["", "in the libraries panel a click on a row opens that library; its ⋯ (or a right-click) offers open, rename, delete and a new library; a press outside the panel closes it"],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -166,10 +167,18 @@ const PANE_KEYS: Record<string, () => void> = {
|
|||||||
ArrowDown: () => store.focusFork(1),
|
ArrowDown: () => store.focusFork(1),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Alt+Shift with k j (or ↑ ↓): move the active pane up or down its column. */
|
||||||
|
const PANE_MOVE_KEYS: Record<string, () => void> = {
|
||||||
|
KeyK: () => store.movePane(-1),
|
||||||
|
KeyJ: () => store.movePane(1),
|
||||||
|
ArrowUp: () => store.movePane(-1),
|
||||||
|
ArrowDown: () => store.movePane(1),
|
||||||
|
};
|
||||||
|
|
||||||
export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||||
if (!store.ready || isTyping(e) || e.metaKey || e.ctrlKey) return;
|
if (!store.ready || isTyping(e) || e.metaKey || e.ctrlKey) return;
|
||||||
if (e.altKey) {
|
if (e.altKey) {
|
||||||
const go = !e.shiftKey && store.mode === "normal" ? PANE_KEYS[e.code] : undefined;
|
const go = store.mode === "normal" ? (e.shiftKey ? PANE_MOVE_KEYS : PANE_KEYS)[e.code] : undefined;
|
||||||
if (!go) return;
|
if (!go) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
store.t0 = { what: `A-${e.code}`, at: e.timeStamp };
|
store.t0 = { what: `A-${e.code}`, at: e.timeStamp };
|
||||||
|
|||||||
+47
-3
@@ -8,10 +8,10 @@
|
|||||||
* every open pane.
|
* every open pane.
|
||||||
*
|
*
|
||||||
* The pure parts are here: which pane a page brings forward when it is swiped to, how a pane is
|
* The pure parts are here: which pane a page brings forward when it is swiped to, how a pane is
|
||||||
* named in the browser's history (so Back, the button or the edge swipe, goes back a pane), and the
|
* named in the browser's history (so Back, the button or the edge swipe, goes back a pane), the
|
||||||
* steps of that history.
|
* steps of that history, and the tree lines the map draws.
|
||||||
*/
|
*/
|
||||||
import type { Forest, Tree } from "./forks";
|
import type { Forest, Placed, Tree } from "./forks";
|
||||||
|
|
||||||
/** Which page a scroll offset rests on: the nearest, among `count`. */
|
/** Which page a scroll offset rests on: the nearest, among `count`. */
|
||||||
export function pageAt(scrollLeft: number, width: number, count: number): number {
|
export function pageAt(scrollLeft: number, width: number, count: number): number {
|
||||||
@@ -92,3 +92,47 @@ export function loadVisits(o: unknown): Visits | null {
|
|||||||
// Kept short: what lies far back is reached by the browser's own history anyway.
|
// Kept short: what lies far back is reached by the browser's own history anyway.
|
||||||
return v.keys.length > 200 ? { keys: v.keys.slice(-200), i: Math.max(0, v.i - (v.keys.length - 200)) } : v;
|
return v.keys.length > 200 ? { keys: v.keys.slice(-200), i: Math.max(0, v.i - (v.keys.length - 200)) } : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One stroke of the map's tree lines, in a row of the map, at a level (a column of the panes view,
|
||||||
|
* which is how far the row is indented): `dash`, a root's mark (no line into it: the first pane, or
|
||||||
|
* an orphan, whose source closed); `elbow`, from the row's top down its parent's line and across
|
||||||
|
* into its own mark; `on`, its parent's line going on from the elbow to the row's foot, toward a
|
||||||
|
* later sibling; `pass`, an ancestor's line running through the whole row to a later child of that
|
||||||
|
* ancestor; `down`, the row's own line leaving under its mark for its first child. Each is drawn in
|
||||||
|
* the colour of the pane it leads to (`tid`): a line into a child is the child's branch colour.
|
||||||
|
*/
|
||||||
|
export interface Rail {
|
||||||
|
kind: "dash" | "elbow" | "on" | "pass" | "down";
|
||||||
|
level: number;
|
||||||
|
tid: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The map's tree lines, row by row, for every pane in the map's order (forks.ts `all`: tree by tree, depth first). */
|
||||||
|
export function rails<R, S>(placed: Placed<R, S>[]): Rail[][] {
|
||||||
|
const at = new Map(placed.map((x) => [x.node.id, x]));
|
||||||
|
const next = (x: Placed<R, S>) => {
|
||||||
|
const sibs = x.parent?.kids ?? [];
|
||||||
|
const j = sibs.findIndex((k) => k.id === x.node.id);
|
||||||
|
return j >= 0 ? sibs[j + 1] : undefined;
|
||||||
|
};
|
||||||
|
return placed.map((x) => {
|
||||||
|
const out: Rail[] = [];
|
||||||
|
const parent = x.parent && at.get(x.parent.id);
|
||||||
|
if (parent) {
|
||||||
|
out.push({ kind: "elbow", level: parent.col, tid: x.node.id });
|
||||||
|
const s = next(x);
|
||||||
|
if (s) out.push({ kind: "on", level: parent.col, tid: s.id });
|
||||||
|
} else out.push({ kind: "dash", level: x.col, tid: x.node.id });
|
||||||
|
if (x.node.kids.length) out.push({ kind: "down", level: x.col, tid: x.node.kids[0].id });
|
||||||
|
for (let c = parent; c?.parent; c = at.get(c.parent.id)) {
|
||||||
|
const s = next(c);
|
||||||
|
const p = at.get(c.parent.id);
|
||||||
|
if (s && p) out.push({ kind: "pass", level: p.col, tid: s.id });
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How far each level of the map is indented, in px: a finger's width at most, less in a deep forest so its deepest rows keep room for their titles. */
|
||||||
|
export const mapStep = (deepest: number) => Math.min(16, Math.max(8, Math.floor(140 / Math.max(1, deepest))));
|
||||||
@@ -43,6 +43,35 @@ export function offsets(sizes: number[], pinned: boolean[], strip: number, view:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Heights for the panes of one column of height h, from what each needs to show all it holds:
|
||||||
|
* each gets that, or an equal share of what is left, whichever is less; what no pane needs goes to
|
||||||
|
* the one that needs most. So short panes are no taller than their text, and long ones share the rest.
|
||||||
|
*/
|
||||||
|
export function fill(h: number, needs: number[]): number[] {
|
||||||
|
const out = needs.map(() => 0);
|
||||||
|
const order = needs.map((_, i) => i).sort((a, b) => needs[a] - needs[b]);
|
||||||
|
let rest = h;
|
||||||
|
order.forEach((i, k) => {
|
||||||
|
const share = rest / (order.length - k);
|
||||||
|
out[i] = Math.floor(k === order.length - 1 ? rest : Math.min(needs[i], share));
|
||||||
|
rest -= out[i];
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a column of height h stacks its panes (each folding to a tab but the one looked at)
|
||||||
|
* rather than sharing its height among them: when they do not all fit at their least (`least`
|
||||||
|
* each, or less where a pane needs less); and, given `here`, the pane looked at (as pages, on a
|
||||||
|
* phone), also whenever sharing would leave that pane shorter than what it needs, so it gets the
|
||||||
|
* column's height and the others fold.
|
||||||
|
*/
|
||||||
|
export function crowds(h: number, needs: number[], least: number, here?: number): boolean {
|
||||||
|
if (needs.reduce((s, x) => s + Math.min(x, least), 0) > h) return true;
|
||||||
|
return here !== undefined && needs.length > 1 && fill(h, needs)[here] < needs[here] - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/** Where each item begins when nothing is stuck: one after another. */
|
/** Where each item begins when nothing is stuck: one after another. */
|
||||||
export const starts = (sizes: number[]) => sizes.map((_, i) => sizes.slice(0, i).reduce((a, b) => a + b, 0));
|
export const starts = (sizes: number[]) => sizes.map((_, i) => sizes.slice(0, i).reduce((a, b) => a + b, 0));
|
||||||
|
|
||||||
|
|||||||
@@ -799,6 +799,29 @@ class Store {
|
|||||||
this.emit();
|
this.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether the active pane can move up or down its column (the pane menu offers what it can). */
|
||||||
|
paneMoves(): { above: boolean; below: boolean } {
|
||||||
|
const here = this.branchNodes[this.paneAt];
|
||||||
|
const x = here && this.panesPlaced.find((y) => y.node.id === here.id);
|
||||||
|
const col = x ? (this.paneColumns.get(x.col) ?? []) : [];
|
||||||
|
const i = col.findIndex((y) => y.node.id === here?.id);
|
||||||
|
return { above: i > 0, below: i >= 0 && i < col.length - 1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Alt+Shift+k and Alt+Shift+j (or the pane menu): move the active pane up or down its column, as dragging it does. */
|
||||||
|
movePane(delta: number) {
|
||||||
|
if (!this.panes) return this.say("Panes are moved in the panes view (v).");
|
||||||
|
this.syncTrail();
|
||||||
|
const here = this.branchNodes[this.paneAt];
|
||||||
|
const x = here && this.panesPlaced.find((y) => y.node.id === here.id);
|
||||||
|
if (!x) return;
|
||||||
|
const col = (this.paneColumns.get(x.col) ?? []).map((y) => y.node.id);
|
||||||
|
const i = col.indexOf(here.id);
|
||||||
|
if (col.length < 2) return this.say("This is the only pane in its column.");
|
||||||
|
if (delta < 0 ? i === 0 : i === col.length - 1) return this.say(`This pane is at the ${delta < 0 ? "top" : "foot"} of its column.`);
|
||||||
|
this.reorderPane(here.id, delta < 0 ? col[i - 1] : (col[i + 2] ?? null));
|
||||||
|
}
|
||||||
|
|
||||||
/** P (on the active pane) or a pane's pin: pin or unpin it. */
|
/** P (on the active pane) or a pane's pin: pin or unpin it. */
|
||||||
togglePanePin(id = this.branchNodes[this.paneAt]?.id) {
|
togglePanePin(id = this.branchNodes[this.paneAt]?.id) {
|
||||||
if (!this.panes) return this.say("Panes are pinned in the panes view (v).");
|
if (!this.panes) return this.say("Panes are pinned in the panes view (v).");
|
||||||
|
|||||||
+64
-15
@@ -519,7 +519,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
|||||||
--hue-none: oklch(80% 0 0);
|
--hue-none: oklch(80% 0 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
:where(.pane, .curves path, .trail-step, .map-row) { --hue: var(--hue-none); }
|
:where(.pane, .curves path, .trail-step, .map-row, .drag-ghost, .rail) { --hue: var(--hue-none); }
|
||||||
[data-hue="0"] { --hue: var(--hue-0); }
|
[data-hue="0"] { --hue: var(--hue-0); }
|
||||||
[data-hue="1"] { --hue: var(--hue-1); }
|
[data-hue="1"] { --hue: var(--hue-1); }
|
||||||
[data-hue="2"] { --hue: var(--hue-2); }
|
[data-hue="2"] { --hue: var(--hue-2); }
|
||||||
@@ -528,7 +528,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
|||||||
[data-hue="5"] { --hue: var(--hue-5); }
|
[data-hue="5"] { --hue: var(--hue-5); }
|
||||||
[data-hue="6"] { --hue: var(--hue-6); }
|
[data-hue="6"] { --hue: var(--hue-6); }
|
||||||
/* Fainter off the focused branch. Both are fixed per pane, so moving the branch changes no custom property (which every element in the pane would inherit). */
|
/* Fainter off the focused branch. Both are fixed per pane, so moving the branch changes no custom property (which every element in the pane would inherit). */
|
||||||
.pane, .curves path, .trail-step, .map-row { --hue-faint: color-mix(in oklab, var(--hue) 70%, transparent); }
|
.pane, .curves path, .trail-step, .map-row, .rail { --hue-faint: color-mix(in oklab, var(--hue) 70%, transparent); }
|
||||||
.panes:not([data-colors="off"]) .curves path { stroke: var(--hue-faint); stroke-width: var(--hair, 1px); }
|
.panes:not([data-colors="off"]) .curves path { stroke: var(--hue-faint); stroke-width: var(--hair, 1px); }
|
||||||
.panes:not([data-colors="off"]) .curves path.on { stroke: var(--hue); }
|
.panes:not([data-colors="off"]) .curves path.on { stroke: var(--hue); }
|
||||||
/*
|
/*
|
||||||
@@ -855,12 +855,26 @@ html { scroll-padding-top: 48px; }
|
|||||||
.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; }
|
.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. */
|
/* Touch: no hover, no right-click, no keys. The bar docks at the foot; a menu is a sheet. */
|
||||||
|
/* Over the words, the actions are simply in the bar's row. */
|
||||||
|
.selbar .bar-acts { display: contents; }
|
||||||
|
/*
|
||||||
|
* Docked at the foot (touch): one row, a finger high. The actions scroll sideways under a fade at
|
||||||
|
* whichever end has more beyond it; the ⋯ (the rest: Copy, select less or more, …) and the × that
|
||||||
|
* puts the bar away stay at the row's end.
|
||||||
|
*/
|
||||||
.selbar.docked {
|
.selbar.docked {
|
||||||
left: 0; right: 0; bottom: var(--foot-at); top: auto !important; border-width: 1px 0 0; border-radius: 0; box-shadow: none;
|
left: 0; right: 0; bottom: var(--foot-at); 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;
|
padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); background: var(--bg); flex-wrap: nowrap; align-items: stretch;
|
||||||
}
|
}
|
||||||
.selbar.docked::after, .selbar.docked .k, .selbar.docked .bar-sep { display: none; }
|
.selbar.docked::after, .selbar.docked .k, .selbar.docked .bar-sep { display: none; }
|
||||||
.selbar.docked button { padding: 0.45rem 0.6rem; font-size: 0.95rem; min-height: 44px; min-width: 44px; }
|
.selbar.docked .bar-acts { flex: 1; min-width: 0; display: flex; align-items: stretch; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; padding: 0 4px; }
|
||||||
|
.selbar.docked .bar-acts::-webkit-scrollbar { display: none; }
|
||||||
|
.selbar.docked .bar-acts[data-after] { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }
|
||||||
|
.selbar.docked .bar-acts[data-before] { -webkit-mask-image: linear-gradient(to right, transparent, #000 36px); mask-image: linear-gradient(to right, transparent, #000 36px); }
|
||||||
|
.selbar.docked .bar-acts[data-before][data-after] { -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
|
||||||
|
.selbar.docked button { flex: none; padding: 0 10px; font-size: 0.9rem; min-height: 44px; min-width: 44px; }
|
||||||
|
.selbar.docked :is(.bar-more, .bar-done) { width: 44px; padding: 0; border-left: 1px solid var(--hair); border-radius: 0; font-variant-caps: normal; letter-spacing: 0; }
|
||||||
|
.selbar.docked .bar-done { font-size: 1.15rem; color: var(--dim); }
|
||||||
.menu.sheet {
|
.menu.sheet {
|
||||||
left: 0; right: 0; bottom: var(--foot-at); top: auto; max-width: none; max-height: 70vh; max-height: 70dvh; overflow-y: auto;
|
left: 0; right: 0; bottom: var(--foot-at); top: auto; max-width: none; max-height: 70vh; max-height: 70dvh; 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);
|
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);
|
||||||
@@ -939,6 +953,8 @@ html { scroll-padding-top: 48px; }
|
|||||||
.panes[data-layout="pages"] { --tab: 44px; }
|
.panes[data-layout="pages"] { --tab: 44px; }
|
||||||
.panes[data-layout="pages"] .strip { scroll-snap-type: x mandatory; scrollbar-width: none; }
|
.panes[data-layout="pages"] .strip { scroll-snap-type: x mandatory; scrollbar-width: none; }
|
||||||
.panes[data-layout="pages"] .strip::-webkit-scrollbar { display: none; }
|
.panes[data-layout="pages"] .strip::-webkit-scrollbar { display: none; }
|
||||||
|
/* While the page glides the strip to a page (Panes.tsx glideTo) nothing snaps on the way; it lands on the page exactly. */
|
||||||
|
.panes[data-layout="pages"] .strip[data-gliding] { scroll-snap-type: none; }
|
||||||
.panes[data-layout="pages"] .col { position: relative; width: 100%; scroll-snap-align: start; scroll-snap-stop: always; }
|
.panes[data-layout="pages"] .col { position: relative; width: 100%; scroll-snap-align: start; scroll-snap-stop: always; }
|
||||||
.panes[data-layout="pages"] .pane { border-right: 0; }
|
.panes[data-layout="pages"] .pane { border-right: 0; }
|
||||||
/* Room above the title for the pane's buttons, a finger's size; on a tablet the text keeps its measure. */
|
/* Room above the title for the pane's buttons, a finger's size; on a tablet the text keeps its measure. */
|
||||||
@@ -951,9 +967,23 @@ html { scroll-padding-top: 48px; }
|
|||||||
/* The first pane never closes. */
|
/* The first pane never closes. */
|
||||||
.panes[data-layout="pages"] .pane.root > .pane-ctl > .close { display: none; }
|
.panes[data-layout="pages"] .pane.root > .pane-ctl > .close { display: none; }
|
||||||
.panes[data-layout="pages"] .pane-btn.pin.on { color: var(--fg); }
|
.panes[data-layout="pages"] .pane-btn.pin.on { color: var(--fg); }
|
||||||
.panes[data-layout="pages"] .grip { display: none; }
|
/*
|
||||||
/* A tab: a swipe across it still turns the page; one down it drags the pane up or down its column. */
|
* A pane in a page shared with others is moved up or down it by a press held on its tab or on the
|
||||||
.panes[data-layout="pages"] .tabline { padding: 0 128px 0 var(--spine); font-size: 0.8rem; touch-action: pan-x; }
|
* band above its title, left of its buttons (Panes.tsx): two faint lines mark that band. A swipe
|
||||||
|
* across either still turns the page, and one down still scrolls; held, the pane lifts.
|
||||||
|
*/
|
||||||
|
.panes[data-layout="pages"] .grip { left: var(--spine); right: 132px; height: 44px; touch-action: pan-x pan-y; cursor: default; -webkit-touch-callout: none; }
|
||||||
|
.panes[data-layout="pages"] .grip::before { top: 20px; opacity: 0.6; }
|
||||||
|
.panes[data-layout="pages"] .tabline { padding: 0 128px 0 var(--spine); font-size: 0.8rem; touch-action: pan-x pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
|
||||||
|
/* Lifted: the pane fades where it is; its tab rides just above the finger; a line shows where it will go. */
|
||||||
|
.pane[data-lifted] { opacity: 0.4; }
|
||||||
|
.drag-ghost {
|
||||||
|
position: absolute; z-index: 8; height: 44px; display: flex; align-items: center; gap: 0.4em; padding: 0 16px; pointer-events: none;
|
||||||
|
background: var(--bg); border-top: 1px solid var(--edge-strong); border-bottom: 2px solid var(--hue, var(--fg)); box-shadow: 0 6px 18px -4px var(--shade);
|
||||||
|
font-family: var(--sans); font-size: 0.8rem; letter-spacing: 0.02em; color: var(--fg); white-space: nowrap; overflow: hidden;
|
||||||
|
}
|
||||||
|
.drag-ghost .tabtitle { overflow: hidden; text-overflow: ellipsis; }
|
||||||
|
.panes[data-layout="pages"] .drop-line { z-index: 9; height: 3px; }
|
||||||
/* The heavy rule marks the active pane among others in its column; alone on its page it needs none. */
|
/* The heavy rule marks the active pane among others in its column; alone on its page it needs none. */
|
||||||
.panes[data-layout="pages"] .pane.active::after,
|
.panes[data-layout="pages"] .pane.active::after,
|
||||||
.panes[data-layout="pages"][data-curves="off"] .pane.active::after { bottom: auto; height: 3px; border: 0; background: var(--fg); }
|
.panes[data-layout="pages"][data-curves="off"] .pane.active::after { bottom: auto; height: 3px; border: 0; background: var(--fg); }
|
||||||
@@ -1004,7 +1034,8 @@ html { scroll-padding-top: 48px; }
|
|||||||
position: relative; flex: none; display: flex; align-items: center; gap: 0.3em; min-width: 44px; max-width: 11em; padding: 0 12px;
|
position: relative; flex: none; display: flex; align-items: center; gap: 0.3em; min-width: 44px; max-width: 11em; padding: 0 12px;
|
||||||
font: inherit; color: var(--dim); background: none; border: 0; border-radius: 0; cursor: pointer;
|
font: inherit; color: var(--dim); background: none; border: 0; border-radius: 0; cursor: pointer;
|
||||||
}
|
}
|
||||||
.trail-step:hover { border: 0; color: var(--fg); }
|
.trail-step:hover { border: 0; }
|
||||||
|
@media (hover: hover) { .trail-step:hover { color: var(--fg); } }
|
||||||
.trail-step::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 10px; height: 1px; background: var(--hue-faint); }
|
.trail-step::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 10px; height: 1px; background: var(--hue-faint); }
|
||||||
.trail-step.here { color: var(--fg); font-weight: 600; }
|
.trail-step.here { color: var(--fg); font-weight: 600; }
|
||||||
.trail-step.here::after { height: 2px; background: var(--hue); }
|
.trail-step.here::after { height: 2px; background: var(--hue); }
|
||||||
@@ -1012,13 +1043,20 @@ html { scroll-padding-top: 48px; }
|
|||||||
.trail-step + .trail-step::before { content: "›"; position: absolute; left: -0.2em; color: var(--rule); font-weight: 400; }
|
.trail-step + .trail-step::before { content: "›"; position: absolute; left: -0.2em; color: var(--rule); font-weight: 400; }
|
||||||
.trail-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
.trail-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
.trail-step .wmark { flex: none; font-size: 0.95em; }
|
.trail-step .wmark { flex: none; font-size: 0.95em; }
|
||||||
|
/* How many panes a step's page holds: a dot each, top to bottom, its own filled in its colour; past four, their number. */
|
||||||
|
.trail-stack { flex: none; display: flex; flex-direction: column; gap: 2px; margin: 0 0 2px 1px; }
|
||||||
|
.trail-stack i { display: block; width: 4px; height: 4px; border-radius: 50%; background: var(--rule); }
|
||||||
|
.trail-stack i.on { background: var(--hue); }
|
||||||
|
.trail-count { flex: none; margin-left: 1px; padding: 0 3px; border: 1px solid var(--rule); border-radius: 2px; font-size: 0.6rem; line-height: 1.35; font-weight: 400; color: var(--dim); font-variant-numeric: tabular-nums; }
|
||||||
.trail-map { flex: none; min-width: 64px; padding: 0 14px; font: inherit; color: var(--dim); background: none; border: 0; border-left: 1px solid var(--hair); border-radius: 0; cursor: pointer; }
|
.trail-map { flex: none; min-width: 64px; padding: 0 14px; font: inherit; color: var(--dim); background: none; border: 0; border-left: 1px solid var(--hair); border-radius: 0; cursor: pointer; }
|
||||||
.trail-map:hover, .trail-map[aria-expanded="true"] { border-color: var(--hair); color: var(--fg); }
|
.trail-map:hover { border-color: var(--hair); }
|
||||||
|
.trail-map[aria-expanded="true"] { color: var(--fg); }
|
||||||
|
@media (hover: hover) { .trail-map:hover { color: var(--fg); } }
|
||||||
.trail-n { color: var(--faint); font-variant-numeric: tabular-nums; margin-left: 0.15em; }
|
.trail-n { color: var(--faint); font-variant-numeric: tabular-nums; margin-left: 0.15em; }
|
||||||
|
|
||||||
/* The map: every open pane, as an outline of the forest, in a sheet from the foot. */
|
/* The map: every open pane, as an outline of the forest, in a sheet from the foot. */
|
||||||
.pane-map {
|
.pane-map {
|
||||||
position: fixed; left: 0; right: 0; bottom: var(--foot-at); z-index: 30; max-height: 70vh; max-height: 70dvh; overflow-y: auto; outline: none;
|
position: fixed; left: 0; right: 0; bottom: var(--foot-at); z-index: 30; max-height: 70vh; max-height: 70dvh; overflow-y: auto; overscroll-behavior: contain; outline: none;
|
||||||
background: var(--bg); border-top: 3px double var(--rule); box-shadow: 0 -2px 10px 0 color-mix(in srgb, var(--fg) 12%, transparent);
|
background: var(--bg); border-top: 3px double var(--rule); box-shadow: 0 -2px 10px 0 color-mix(in srgb, var(--fg) 12%, transparent);
|
||||||
padding: 0 env(safe-area-inset-right, 0px) 0.4rem env(safe-area-inset-left, 0px); font-family: var(--sans); font-size: 0.86rem; line-height: 1.35;
|
padding: 0 env(safe-area-inset-right, 0px) 0.4rem env(safe-area-inset-left, 0px); font-family: var(--sans); font-size: 0.86rem; line-height: 1.35;
|
||||||
}
|
}
|
||||||
@@ -1028,11 +1066,20 @@ html { scroll-padding-top: 48px; }
|
|||||||
}
|
}
|
||||||
.map-hint { font-weight: 400; letter-spacing: 0.02em; text-transform: none; text-align: right; }
|
.map-hint { font-weight: 400; letter-spacing: 0.02em; text-transform: none; text-align: right; }
|
||||||
.map-rows { list-style: none; margin: 0; padding: 0; }
|
.map-rows { list-style: none; margin: 0; padding: 0; }
|
||||||
.map-row { display: flex; align-items: stretch; min-height: 44px; padding-left: calc(6px + var(--depth, 0) * 14px); }
|
/* Each row 44 px, indented by its column (Pages.tsx sets it); its tree lines drawn in it (pages.ts rails). */
|
||||||
|
.map-row { position: relative; display: flex; align-items: stretch; height: 44px; }
|
||||||
.map-go { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.55em; padding: 0 8px; font: inherit; color: var(--dim); text-align: left; background: none; border: 0; border-radius: 0; cursor: pointer; }
|
.map-go { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.55em; padding: 0 8px; font: inherit; color: var(--dim); text-align: left; background: none; border: 0; border-radius: 0; cursor: pointer; }
|
||||||
.map-go:hover { border: 0; color: var(--fg); }
|
.map-go:hover { border: 0; }
|
||||||
.map-dash { flex: none; width: 1.1rem; height: 0; border-top: 1px solid var(--hue-faint); }
|
@media (hover: hover) { .map-go:hover { color: var(--fg); } }
|
||||||
.map-row.on-branch .map-dash { border-top: 2px solid var(--hue); }
|
/* A line into a pane in that pane's colour, fainter off the focused branch and stronger on it; over the active row's ground. */
|
||||||
|
.rail { position: absolute; z-index: 1; pointer-events: none; border: 0 solid var(--hue-faint); }
|
||||||
|
.rail.strong { border-color: var(--hue); }
|
||||||
|
.rail.r-dash { border-bottom-width: 1px; }
|
||||||
|
.rail.r-elbow { border-left-width: 1px; border-bottom-width: 1px; }
|
||||||
|
.rail:is(.r-on, .r-pass, .r-down) { border-left-width: 1px; }
|
||||||
|
.rail.strong.r-dash { border-bottom-width: 2px; }
|
||||||
|
.rail.strong.r-elbow { border-left-width: 2px; border-bottom-width: 2px; }
|
||||||
|
.rail.strong:is(.r-on, .r-pass, .r-down) { border-left-width: 2px; }
|
||||||
.map-row.on-branch .map-go { color: var(--fg); }
|
.map-row.on-branch .map-go { color: var(--fg); }
|
||||||
.map-row.here .map-go { font-weight: 600; background: var(--sel); }
|
.map-row.here .map-go { font-weight: 600; background: var(--sel); }
|
||||||
.map-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
.map-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
@@ -1040,7 +1087,9 @@ html { scroll-padding-top: 48px; }
|
|||||||
.map-btn { flex: none; display: block; width: 44px; height: 44px; padding: 14px; color: var(--faint); background: none; border: 0; border-radius: 0; cursor: pointer; }
|
.map-btn { flex: none; display: block; width: 44px; height: 44px; padding: 14px; color: var(--faint); background: none; border: 0; border-radius: 0; cursor: pointer; }
|
||||||
.map-btn.none { cursor: default; }
|
.map-btn.none { cursor: default; }
|
||||||
.map-btn svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
|
.map-btn svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
|
||||||
.map-btn:hover { border: 0; color: var(--fg); background: var(--sel); }
|
/* Pointed at with a mouse only: a finger leaves no hover behind on what comes under it next. */
|
||||||
|
.map-btn:hover { border: 0; }
|
||||||
|
@media (hover: hover) { .map-btn:hover { color: var(--fg); background: var(--sel); } }
|
||||||
.map-btn.pin.on { color: var(--fg); }
|
.map-btn.pin.on { color: var(--fg); }
|
||||||
.map-btn.pin.on svg { fill: currentColor; }
|
.map-btn.pin.on svg { fill: currentColor; }
|
||||||
|
|
||||||
|
|||||||
+21
-1
@@ -28,6 +28,9 @@ const top = (more: Partial<TopCtx> = {}): TopCtx => ({ view: "auto", autolink: "
|
|||||||
/** Every key the page's handler takes, read from keys.ts: an item's key must be one of them. */
|
/** Every key the page's handler takes, read from keys.ts: an item's key must be one of them. */
|
||||||
const handled = new Set([...readFileSync(new URL("../src/ui/keys.ts", import.meta.url), "utf8").matchAll(/case "([^"]+)":/g)].map((m) => m[1]));
|
const handled = new Set([...readFileSync(new URL("../src/ui/keys.ts", import.meta.url), "utf8").matchAll(/case "([^"]+)":/g)].map((m) => m[1]));
|
||||||
|
|
||||||
|
/** The Alt keys the page's handler takes (by the key's place: KeyH, ArrowUp…), written as the menus press them ("A-h"). */
|
||||||
|
const altKeys = new Set([...readFileSync(new URL("../src/ui/keys.ts", import.meta.url), "utf8").matchAll(/^\s+(Key[A-Z]|Arrow\w+): \(\) =>/gm)].map((m) => `A-${m[1].startsWith("Key") ? m[1].slice(3).toLowerCase() : m[1]}`));
|
||||||
|
|
||||||
describe("actions", () => {
|
describe("actions", () => {
|
||||||
it("every item with a key runs by pressing exactly that key, which the key handler takes", () => {
|
it("every item with a key runs by pressing exactly that key, which the key handler takes", () => {
|
||||||
const { act, calls } = recorder();
|
const { act, calls } = recorder();
|
||||||
@@ -38,6 +41,7 @@ describe("actions", () => {
|
|||||||
...items(nodeEntries(node({ library: true }), act)),
|
...items(nodeEntries(node({ library: true }), act)),
|
||||||
...items(paneEntries({ node: node(), pinned: false }, act)),
|
...items(paneEntries({ node: node(), pinned: false }, act)),
|
||||||
...items(paneEntries({ article: "Octopus", pinned: true }, act)),
|
...items(paneEntries({ article: "Octopus", pinned: true }, act)),
|
||||||
|
...items(paneEntries({ node: node(), pinned: false, above: true, below: true }, act)),
|
||||||
...items(articleRowEntries("Octopus", true, act)),
|
...items(articleRowEntries("Octopus", true, act)),
|
||||||
...items(topEntries(top({ canRedo: true }), act)),
|
...items(topEntries(top({ canRedo: true }), act)),
|
||||||
...items(libraryEntries({ title: "Work", current: false, last: false }, act)),
|
...items(libraryEntries({ title: "Work", current: false, last: false }, act)),
|
||||||
@@ -48,7 +52,7 @@ describe("actions", () => {
|
|||||||
calls.length = 0;
|
calls.length = 0;
|
||||||
it.run();
|
it.run();
|
||||||
expect(calls).toEqual([`press ${it.shift ? "S-" : ""}${it.key}`]);
|
expect(calls).toEqual([`press ${it.shift ? "S-" : ""}${it.key}`]);
|
||||||
expect(handled.has(it.key!) || it.key === "Escape", `${it.label}: ${it.key}`).toBe(true);
|
expect(handled.has(it.key!) || it.key === "Escape" || altKeys.has(it.key!), `${it.label}: ${it.key}`).toBe(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,6 +195,22 @@ describe("actions", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("moving a pane in its column", () => {
|
||||||
|
it("the pane menu offers Move this pane up and down (Alt+Shift+k j) only where its column has another pane, greyed where it cannot go", () => {
|
||||||
|
const { act, calls } = recorder();
|
||||||
|
expect(labels(paneEntries({ node: node(), pinned: false }, act))).not.toContain("Move this pane up");
|
||||||
|
const es = paneEntries({ node: node(), pinned: false, above: false, below: true }, act);
|
||||||
|
const up = find(es, "Move this pane up");
|
||||||
|
const down = find(es, "Move this pane down");
|
||||||
|
expect(up.disabled).toBe(true);
|
||||||
|
expect(down.disabled).toBe(false);
|
||||||
|
expect([up.keyText, down.keyText]).toEqual(["Alt+⇧k", "Alt+⇧j"]);
|
||||||
|
down.run();
|
||||||
|
expect(calls).toEqual(["press S-A-j"]);
|
||||||
|
expect(labels(paneEntries({ article: "Octopus", pinned: false, above: true, below: false }, act))).toContain("Move this pane up");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("the libraries panel's state", () => {
|
describe("the libraries panel's state", () => {
|
||||||
const lib = (id: string, title = id): LibraryInfo => ({ id, title, created: "", nodes: 0, branches: ["main"] });
|
const lib = (id: string, title = id): LibraryInfo => ({ id, title, created: "", nodes: 0, branches: ["main"] });
|
||||||
const list = [lib("a"), lib("b"), lib("c")];
|
const list = [lib("a"), lib("b"), lib("c")];
|
||||||
|
|||||||
+46
-2
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { close, open, plain, trace, type Forest } from "../src/ui/forks";
|
import { all, close, open, plain, trace, type Forest } from "../src/ui/forks";
|
||||||
import { arrived, findKey, loadVisits, pageAt, paneKey, paneOfPage, visit, type Visits } from "../src/ui/pages";
|
import { arrived, findKey, loadVisits, mapStep, pageAt, paneKey, paneOfPage, rails, visit, type Visits } from "../src/ui/pages";
|
||||||
|
|
||||||
const same = (a: string, b: string) => a === b;
|
const same = (a: string, b: string) => a === b;
|
||||||
const k = (r: string) => r;
|
const k = (r: string) => r;
|
||||||
@@ -95,4 +95,48 @@ describe("the pages layout", () => {
|
|||||||
expect(v.keys).toHaveLength(200);
|
expect(v.keys).toHaveLength(200);
|
||||||
expect(v.keys[v.i]).toBe("k240");
|
expect(v.keys[v.i]).toBe("k240");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("the map's tree lines: a line into each child from its parent's, on toward a later sibling, through the rows between, and down from a parent to its first child", () => {
|
||||||
|
// top ─ a ─ b
|
||||||
|
// │ └ c
|
||||||
|
// └ d
|
||||||
|
let f: Forest<string> = plain(["top", "a", "b"]);
|
||||||
|
f = open(f, 1, "c", true, same);
|
||||||
|
f = open(f, 0, "d", true, same);
|
||||||
|
const placed = all(f);
|
||||||
|
const name = new Map(placed.map((x) => [x.node.id, x.node.ref]));
|
||||||
|
const lines = rails(placed).map((rs, i) => [placed[i].node.ref, rs.map((r) => `${r.kind}@${r.level}>${name.get(r.tid)}`).sort().join(" ")]);
|
||||||
|
expect(lines).toEqual([
|
||||||
|
["top", "dash@0>top down@0>a"],
|
||||||
|
["a", "down@1>b elbow@0>a on@0>d"],
|
||||||
|
["b", "elbow@1>b on@1>c pass@0>d"],
|
||||||
|
["c", "elbow@1>c pass@0>d"],
|
||||||
|
["d", "elbow@0>d"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("an orphan has no line into it, only its mark; its own children hang from it", () => {
|
||||||
|
let f: Forest<string> = plain(["top", "a", "b", "e"]);
|
||||||
|
const a = f.trees[0].kids[0];
|
||||||
|
const b = a.kids[0];
|
||||||
|
f = { ...f, trees: f.trees.map((t) => ({ ...t, kids: t.kids.map((k) => ({ ...k, kids: k.kids.map((x) => ({ ...x, pinned: true })) })) })) };
|
||||||
|
const g = close(f, a.id, b.id).forest;
|
||||||
|
expect(g.trees).toHaveLength(2);
|
||||||
|
const placed = all(g);
|
||||||
|
const rs = rails(placed);
|
||||||
|
const orphan = placed.findIndex((x) => x.node.ref === "b");
|
||||||
|
expect(placed[orphan].col).toBe(2);
|
||||||
|
expect(rs[orphan].map((r) => `${r.kind}@${r.level}`)).toEqual(["dash@2", "down@2"]);
|
||||||
|
const e = placed.findIndex((x) => x.node.ref === "e");
|
||||||
|
expect(rs[e].map((r) => `${r.kind}@${r.level}`)).toEqual(["elbow@2"]);
|
||||||
|
// Nothing from the first tree runs into the orphan's rows.
|
||||||
|
expect(rs[orphan].some((r) => r.kind === "pass")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("the map indents a finger's width a level, less in a deep forest, never under 8 px", () => {
|
||||||
|
expect(mapStep(0)).toBe(16);
|
||||||
|
expect(mapStep(8)).toBe(16);
|
||||||
|
expect(mapStep(10)).toBe(14);
|
||||||
|
expect(mapStep(40)).toBe(8);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+25
-1
@@ -1,6 +1,6 @@
|
|||||||
/** The stacking shared by the panes view's strip and its crowded columns (src/ui/stack.ts). */
|
/** The stacking shared by the panes view's strip and its crowded columns (src/ui/stack.ts). */
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { coverage, offsets, reveal, starts, whole } from "../src/ui/stack";
|
import { coverage, crowds, fill, offsets, reveal, starts, whole } from "../src/ui/stack";
|
||||||
|
|
||||||
describe("stack", () => {
|
describe("stack", () => {
|
||||||
it("sticks each item a strip after the one before, a pinned one its whole size, never past where the rest can still be reached", () => {
|
it("sticks each item a strip after the one before, a pinned one its whole size, never past where the rest can still be reached", () => {
|
||||||
@@ -34,4 +34,28 @@ describe("stack", () => {
|
|||||||
expect(whole(660, 1920, at[1], 700, 40)).toBe(true);
|
expect(whole(660, 1920, at[1], 700, 40)).toBe(true);
|
||||||
expect(whole(880, 1920, at[1], 700, 40)).toBe(false);
|
expect(whole(880, 1920, at[1], 700, 40)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("a column's height is shared: short panes take what they need, long ones share the rest", () => {
|
||||||
|
expect(fill(700, [200, 1000])).toEqual([200, 500]);
|
||||||
|
expect(fill(700, [1000, 1000])).toEqual([350, 350]);
|
||||||
|
expect(fill(700, [100, 150])).toEqual([100, 600]);
|
||||||
|
expect(fill(700, [300, 2000, 300])).toEqual([233, 234, 233]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("a column stacks when its panes do not fit at their least; as pages, also whenever a share would cut the pane looked at short", () => {
|
||||||
|
// Wide screen: shared while they fit at their least, whoever is looked at.
|
||||||
|
expect(crowds(850, [1000, 1000], 260)).toBe(false);
|
||||||
|
expect(crowds(850, [1000, 1000, 1000], 260)).toBe(false);
|
||||||
|
expect(crowds(850, [1000, 1000, 1000, 1000], 260)).toBe(true);
|
||||||
|
// As pages: the long pane looked at gets the height.
|
||||||
|
expect(crowds(720, [1000, 1000], 260, 0)).toBe(true);
|
||||||
|
expect(crowds(720, [1000, 1000], 260, 1)).toBe(true);
|
||||||
|
// A short pane looked at, shown whole by the share, leaves the long one beside it.
|
||||||
|
expect(crowds(720, [300, 1000], 260, 0)).toBe(false);
|
||||||
|
expect(crowds(720, [300, 1000], 260, 1)).toBe(true);
|
||||||
|
// Both whole: nothing folds.
|
||||||
|
expect(crowds(720, [300, 350], 260, 1)).toBe(false);
|
||||||
|
// One pane: nothing to fold.
|
||||||
|
expect(crowds(720, [3000], 260, 0)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user