Panes: edges dragged by the mouse side by side, and the active pane shown whole
Side by side, the mouse near an edge between two panes of a column, or between two columns, takes it (row-resize, col-resize) and drags it: down a column the same splitter as a page's, across the strip the columns' widths. Only a pinned pane's size, and the width of a column holding one, stick; the others are the layout's again once another pane is the active one. Esc puts the edge back; a double click lays it out automatically. A column whose share would cut the active pane short now stacks side by side too, as a page already did: the active pane is shown whole and the others give way. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
5c867b2eef
commit
a3f25fbdcc
8 files changed
+615
-81
No files matched your search
@@ -178,9 +178,11 @@ Press `?` for every key. The short version:
|
|||||||
opened from: by where their parents stand, then by where in the parent each was opened from, so a
|
opened from: by where their parents stand, then by where in the parent each was opened from, so a
|
||||||
pane opened from higher up stands higher (and curves cross as little as they can). A column divides
|
pane opened from higher up stands higher (and curves cross as little as they can). A column divides
|
||||||
its own height among its panes, a short pane taking only what its text needs. When they do not all
|
its own height among its panes, a short pane taking only what its text needs. When they do not all
|
||||||
fit, the column stacks them the way the strip stacks columns: the pane on the focused branch shown
|
fit, or when its share would cut the active pane short (a definition whose article's card has
|
||||||
whole, those before it stuck a tab apart above it and those after it a tab apart at the column's
|
just arrived, say), the column stacks them the way the strip stacks columns: the pane on the
|
||||||
foot, partly covered and at the limit down to a one-line tab, so every pane shows at least its tab.
|
focused branch shown whole, those before it stuck a tab apart above it and those after it a tab
|
||||||
|
apart at the column's foot, partly covered and at the limit down to a one-line tab, so every pane
|
||||||
|
shows at least its tab.
|
||||||
A pane scrolled past its own title shows the same tab at its top, over its text; a pane shows its
|
A pane scrolled past its own title shows the same tab at its top, over its text; a pane shows its
|
||||||
tab only while the rule under its title does not show, never both. A click anywhere
|
tab only while the rule under its title does not show, never both. A click anywhere
|
||||||
in a pane that is not text, a row or a link makes it the active pane; a click anywhere else, or
|
in a pane that is not text, a row or a link makes it the active pane; a click anywhere else, or
|
||||||
@@ -192,6 +194,19 @@ Press `?` for every key. The short version:
|
|||||||
it up or down its column; Esc cancels; `Alt+Shift+k` `Alt+Shift+j` (or the pane menu's Move this
|
it up or down its column; Esc cancels; `Alt+Shift+k` `Alt+Shift+j` (or the pane menu's Move this
|
||||||
pane up and down) move the active pane a place; the column keeps that order, and a pane opened
|
pane up and down) move the active pane a place; the column keeps that order, and a pane opened
|
||||||
later goes in just after the one before it in its own order.
|
later goes in just after the one before it in its own order.
|
||||||
|
- **Resizing by the edges.** The mouse near the edge between two panes of a column shows an up and
|
||||||
|
down arrow, near the edge between two columns side by side a left and right one; pressed and
|
||||||
|
dragged, the edge follows it, as a finger drags a pane's top edge on a phone: down a column the
|
||||||
|
panes either side give and take (a tab at the limit pushed along, never less than a tab, a pane
|
||||||
|
left barely taller than its tab folds), across the strip the column after the edge gives what the
|
||||||
|
one before takes (never narrower than 240 px, one at the limit pushed along). The column's top
|
||||||
|
and foot, the strip's outer edges and an edge a column covers are not edges. Esc while dragging
|
||||||
|
puts the edge back; a double click on an edge lays its column (across, the strip) out
|
||||||
|
automatically again. Only a pinned pane's size sticks: once another pane is the active one, or a
|
||||||
|
pane opens or closes in that column, the column is laid out automatically again but for its
|
||||||
|
pinned panes, which keep their heights, the others sharing the rest (the active pane first, as
|
||||||
|
far as a tab for each of the others allows); likewise a column keeps its width only while it
|
||||||
|
holds a pinned pane. Sizes by hand are not kept across a reload.
|
||||||
- **Between panes, by keys.** `Alt+h` goes to the pane this one was opened from, `Alt+l` to one
|
- **Between panes, by keys.** `Alt+h` goes to the pane this one was opened from, `Alt+l` to one
|
||||||
opened from it (the one opened from the focused row or link, if it is open, else the one last
|
opened from it (the one opened from the focused row or link, if it is open, else the one last
|
||||||
visited there), `Alt+k` and `Alt+j` (or `Alt+↑` `Alt+↓`, or `[` `]`) to the pane above and below
|
visited there), `Alt+k` and `Alt+j` (or `Alt+↑` `Alt+↓`, or `[` `]`) to the pane above and below
|
||||||
@@ -370,7 +385,8 @@ What is sent where:
|
|||||||
the store's `trail` is its focused branch); `stack.ts` is the stacking shared by the strip and its
|
the store's `trail` is its focused branch); `stack.ts` is the stacking shared by the strip and its
|
||||||
columns (and how a column shares or stacks its height), `lanes.ts` orders the curves' lanes. The
|
columns (and how a column shares or stacks its height), `lanes.ts` orders the curves' lanes. The
|
||||||
pages layout is the same panes (`Panes.tsx`, which also glides the strip and carries a pane held
|
pages layout is the same panes (`Panes.tsx`, which also glides the strip and carries a pane held
|
||||||
or resizes one by touch, the sizes by hand being `stack.ts` `resize`, `release` and `fit`) laid out a column per page, with `Pages.tsx` (the trail and the map) and `pages.ts`
|
or resizes one by touch, or side by side by the mouse at its edges, the sizes by hand being
|
||||||
|
`stack.ts` `resize`, `release`, `fit` and `share`) laid out a column per page, with `Pages.tsx` (the trail and the map) and `pages.ts`
|
||||||
(which pane a page brings forward, the history entries a pane per step, and the map's tree lines,
|
(which pane a page brings forward, the history entries a pane per step, and the map's tree lines,
|
||||||
pure functions).
|
pure functions).
|
||||||
|
|
||||||
|
|||||||
@@ -540,6 +540,10 @@ test("a pane is dragged by its grip, or its tab, up or down its column; the orde
|
|||||||
await page.reload();
|
await page.reload();
|
||||||
await page.waitForSelector(".strip .pane");
|
await page.waitForSelector(".strip .pane");
|
||||||
expect((await columns(page))[1]).toEqual([kids[4], ...kids.slice(0, 4)]);
|
expect((await columns(page))[1]).toEqual([kids[4], ...kids.slice(0, 4)]);
|
||||||
|
// The active pane back in the first column, so this one shares its height again (the active pane, cut short by a share, would stack it).
|
||||||
|
await pane(page, "Explicata").locator(".top h1, .pane-head h2").first().dispatchEvent("click");
|
||||||
|
await expect.poll(() => page.locator(".strip > .col").nth(1).getAttribute("class")).not.toContain("crowded");
|
||||||
|
await still(page);
|
||||||
// Downward, reaching the top of a pane below is enough: the dragged pane lands after it.
|
// Downward, reaching the top of a pane below is enough: the dragged pane lands after it.
|
||||||
await drag(kids[4], kids[1]);
|
await drag(kids[4], kids[1]);
|
||||||
expect((await columns(page))[1]).toEqual([kids[0], kids[1], kids[4], kids[2], kids[3]]);
|
expect((await columns(page))[1]).toEqual([kids[0], kids[1], kids[4], kids[2], kids[3]]);
|
||||||
@@ -558,6 +562,150 @@ test("a pane is dragged by its grip, or its tab, up or down its column; the orde
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** The columns measured, left to right: each one's box, whether it is sized by hand, and its panes' tops and heights, whether active, and titles. */
|
||||||
|
const measured = (page: Page) =>
|
||||||
|
page.evaluate(() =>
|
||||||
|
[...document.querySelectorAll<HTMLElement>(".strip > .col")].map((col) => {
|
||||||
|
const c = col.getBoundingClientRect();
|
||||||
|
return {
|
||||||
|
left: c.left,
|
||||||
|
right: c.right,
|
||||||
|
w: c.width,
|
||||||
|
top: c.top,
|
||||||
|
bottom: c.bottom,
|
||||||
|
h: col.clientHeight,
|
||||||
|
sized: col.classList.contains("sized"),
|
||||||
|
panes: [...col.querySelectorAll<HTMLElement>(":scope > .pane")].map((p) => {
|
||||||
|
const r = p.getBoundingClientRect();
|
||||||
|
return { top: r.top, h: r.height, active: p.classList.contains("active"), title: p.querySelector(".pane-head h2")?.textContent?.trim() ?? "" };
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
/** The mouse put here: the cursor it shows. */
|
||||||
|
async function cursorAt(page: Page, x: number, y: number) {
|
||||||
|
await page.mouse.move(x, y);
|
||||||
|
return page.evaluate(([x, y]) => getComputedStyle(document.elementFromPoint(x, y)!).cursor, [x, y]);
|
||||||
|
}
|
||||||
|
/** The mouse pressed at (x, y), moved by (dx, dy) a step at a time, then let go (unless `up` is false). */
|
||||||
|
async function mouseDrag(page: Page, x: number, y: number, dx: number, dy: number, up = true) {
|
||||||
|
await page.mouse.move(x, y);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(x + dx, y + dy, { steps: 8 });
|
||||||
|
if (up) await page.mouse.up();
|
||||||
|
await frames(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
test("side by side, the mouse resizes panes by their edges: the cursor says which way, the panes either side give and take, down a column and across the strip; only a pinned pane's size, and its column's width, outlive a move to another pane", async ({ page }) => {
|
||||||
|
await open(page);
|
||||||
|
await keys(page, "j Enter j Enter");
|
||||||
|
await expect.poll(async () => (await columns(page))[1]?.length).toBe(2);
|
||||||
|
await still(page);
|
||||||
|
let [c0, c1] = await measured(page);
|
||||||
|
const W0 = c0.w;
|
||||||
|
const W1 = c1.w;
|
||||||
|
const x = c1.left + c1.w / 2;
|
||||||
|
/** A height away from the edges between the panes: the middle of the tallest. */
|
||||||
|
const away = (c: typeof c1) => {
|
||||||
|
const p = c.panes.reduce((a, b) => (b.h > a.h ? b : a));
|
||||||
|
return p.top + p.h / 2;
|
||||||
|
};
|
||||||
|
let mid = away(c1);
|
||||||
|
// The edge between the two panes, up and down; the column's top and foot are no edges.
|
||||||
|
let y = c1.panes[1].top;
|
||||||
|
expect(await cursorAt(page, x, y)).toBe("row-resize");
|
||||||
|
expect(await cursorAt(page, x, y + 3)).toBe("row-resize");
|
||||||
|
expect(await cursorAt(page, x, y - 3)).toBe("row-resize");
|
||||||
|
expect(await cursorAt(page, x, y + 40)).not.toContain("resize");
|
||||||
|
expect(await cursorAt(page, x, c1.top + 2)).not.toContain("resize");
|
||||||
|
expect(await cursorAt(page, x, c1.bottom - 2)).not.toContain("resize");
|
||||||
|
// The edge between the two columns, either side; the strip's outer edges are none.
|
||||||
|
expect(await cursorAt(page, c1.left, mid)).toBe("col-resize");
|
||||||
|
expect(await cursorAt(page, c1.left - 3, mid)).toBe("col-resize");
|
||||||
|
expect(await cursorAt(page, c1.left + 3, mid)).toBe("col-resize");
|
||||||
|
expect(await cursorAt(page, c1.left + 30, mid)).not.toContain("resize");
|
||||||
|
expect(await cursorAt(page, c0.left + 2, mid)).not.toContain("resize");
|
||||||
|
expect(await cursorAt(page, c1.right - 2, mid)).not.toContain("resize");
|
||||||
|
|
||||||
|
// Dragged, the edge between the panes follows the mouse: the pane on one side grows, the other gives, filling the column.
|
||||||
|
const before = await state(page, (s) => ({ pane: s.paneAt, node: s.focus.node, grain: s.focus.grain }));
|
||||||
|
const dir = c1.panes[0].h > c1.panes[1].h ? -1 : 1;
|
||||||
|
await page.mouse.move(x, y);
|
||||||
|
await page.mouse.down();
|
||||||
|
for (const d of [30, 90, 150]) {
|
||||||
|
await page.mouse.move(x, y + dir * d, { steps: 2 });
|
||||||
|
await frames(page);
|
||||||
|
const now = (await measured(page))[1];
|
||||||
|
expect(now.sized).toBe(true);
|
||||||
|
expect(Math.abs(now.panes[1].top - (y + dir * d)), `at ${dir * d}`).toBeLessThanOrEqual(1.5);
|
||||||
|
expect(Math.abs(now.panes[0].h + now.panes[1].h - now.h)).toBeLessThanOrEqual(1);
|
||||||
|
}
|
||||||
|
await page.mouse.up();
|
||||||
|
await frames(page);
|
||||||
|
c1 = (await measured(page))[1];
|
||||||
|
expect(Math.abs(c1.panes[1].top - (y + dir * 150))).toBeLessThanOrEqual(1.5);
|
||||||
|
// The press was not a click: the active pane and the focus are as they were, and no text was selected.
|
||||||
|
expect(await state(page, (s) => ({ pane: s.paneAt, node: s.focus.node, grain: s.focus.grain }))).toEqual(before);
|
||||||
|
expect(await page.evaluate(() => window.getSelection()?.isCollapsed ?? true)).toBe(true);
|
||||||
|
// Esc while dragging puts the edge back.
|
||||||
|
y = c1.panes[1].top;
|
||||||
|
await mouseDrag(page, x, y, 0, dir * 80, false);
|
||||||
|
expect(Math.abs((await measured(page))[1].panes[1].top - (y + dir * 80))).toBeLessThanOrEqual(1.5);
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
await page.mouse.up();
|
||||||
|
await frames(page);
|
||||||
|
expect(Math.abs((await measured(page))[1].panes[1].top - y)).toBeLessThanOrEqual(1.5);
|
||||||
|
|
||||||
|
// The edge between the columns: the column before takes what the one after gives.
|
||||||
|
mid = away(c1);
|
||||||
|
await mouseDrag(page, c1.left, mid, 120, 0);
|
||||||
|
[c0, c1] = await measured(page);
|
||||||
|
expect(Math.abs(c0.w - (W0 + 120))).toBeLessThanOrEqual(1);
|
||||||
|
expect(Math.abs(c1.w - (W1 - 120))).toBeLessThanOrEqual(1);
|
||||||
|
expect(Math.abs(c1.left - c0.right)).toBeLessThanOrEqual(1);
|
||||||
|
expect(await state(page, (s) => s.paneAt)).toBe(before.pane);
|
||||||
|
await expect(page.locator(".panes[data-edge]")).toHaveCount(1);
|
||||||
|
await page.mouse.move(x + 60, mid + 100);
|
||||||
|
await expect(page.locator(".panes[data-edge]")).toHaveCount(0);
|
||||||
|
|
||||||
|
// Nothing pinned: the focus moved to another pane (the one opened from the focused row), the column and the strip are laid out automatically again.
|
||||||
|
expect(c0.panes[0].active).toBe(true);
|
||||||
|
await keys(page, "Alt+l");
|
||||||
|
await expect.poll(async () => (await measured(page))[1].panes.some((p) => p.active)).toBe(true);
|
||||||
|
await expect.poll(async () => (await measured(page))[1].sized).toBe(false);
|
||||||
|
[c0, c1] = await measured(page);
|
||||||
|
expect(Math.abs(c0.w - W0)).toBeLessThanOrEqual(1);
|
||||||
|
expect(Math.abs(c1.w - W1)).toBeLessThanOrEqual(1);
|
||||||
|
|
||||||
|
// The first pane pinned (by its pin: the active pane stays), then both edges dragged: once the focus moves, its height and its column's width stay; the other pane has the rest of the column, the other column its own width.
|
||||||
|
await pane(page, c1.panes[0].title).locator(".pane-ctl .pane-btn.pin").click();
|
||||||
|
await expect(pane(page, c1.panes[0].title)).toHaveClass(/pinned/);
|
||||||
|
await still(page);
|
||||||
|
c1 = (await measured(page))[1];
|
||||||
|
const dir2 = c1.panes[0].h > c1.panes[1].h ? -1 : 1;
|
||||||
|
await mouseDrag(page, x, c1.panes[1].top, 0, dir2 * 120);
|
||||||
|
mid = away((await measured(page))[1]);
|
||||||
|
await mouseDrag(page, c1.left, mid, -80, 0);
|
||||||
|
[c0, c1] = await measured(page);
|
||||||
|
expect(c1.sized).toBe(true);
|
||||||
|
expect(Math.abs(c1.w - (W1 + 80))).toBeLessThanOrEqual(1);
|
||||||
|
const kept = c1.panes[0].h;
|
||||||
|
const back = c1.panes.findIndex((p) => !p.active);
|
||||||
|
await keys(page, back === 0 ? "[" : "]");
|
||||||
|
await expect.poll(async () => (await measured(page))[1].panes[back].active).toBe(true);
|
||||||
|
await still(page);
|
||||||
|
[c0, c1] = await measured(page);
|
||||||
|
expect(c1.sized).toBe(true);
|
||||||
|
expect(Math.abs(c1.panes[0].h - kept)).toBeLessThanOrEqual(1);
|
||||||
|
expect(Math.abs(c1.panes[1].h - (c1.h - kept))).toBeLessThanOrEqual(1);
|
||||||
|
expect(Math.abs(c1.w - (W1 + 80))).toBeLessThanOrEqual(1);
|
||||||
|
expect(Math.abs(c0.w - W0)).toBeLessThanOrEqual(1);
|
||||||
|
|
||||||
|
// A double click on the edge: the column laid out automatically again.
|
||||||
|
await page.mouse.dblclick(x, c1.panes[1].top);
|
||||||
|
await expect.poll(async () => (await measured(page))[1].sized).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
test("a pinned pane is not covered in its column, and outlives a closed parent as an orphan in its column", async ({ page }) => {
|
test("a pinned pane is not covered in its column, and outlives a closed parent as an orphan in its column", async ({ page }) => {
|
||||||
const kids = await five(page);
|
const kids = await five(page);
|
||||||
// Pin the second fork, by its button: it opens beside the focused one and stays open as the focus moves up and down the column.
|
// Pin the second fork, by its button: it opens beside the focused one and stays open as the focus moves up and down the column.
|
||||||
@@ -770,3 +918,23 @@ test("in the column a Shift open is a plain open, and the status line says why o
|
|||||||
await keys(page, "[");
|
await keys(page, "[");
|
||||||
await expect(page.locator(".status .message")).toContainText("panes view");
|
await expect(page.locator(".status .message")).toContainText("panes view");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("side by side, a crowded column's edges resize too: the column is laid out by hand from what showed of each pane, one under another, the tabs kept", async ({ page }) => {
|
||||||
|
await five(page);
|
||||||
|
await expect(page.locator(".strip > .col").nth(1)).toHaveClass(/crowded/);
|
||||||
|
let c = (await measured(page))[1];
|
||||||
|
const x = c.left + c.w / 2;
|
||||||
|
const n = c.panes.length;
|
||||||
|
// Between two tabs stuck at the column's top, and where the pane shown whole begins: edges.
|
||||||
|
expect(await cursorAt(page, x, c.panes[2].top)).toBe("row-resize");
|
||||||
|
const y = c.panes[n - 1].top;
|
||||||
|
expect(await cursorAt(page, x, y)).toBe("row-resize");
|
||||||
|
const shown = c.panes.map((p, i) => (i < n - 1 ? c.panes[i + 1].top : c.bottom) - p.top);
|
||||||
|
await mouseDrag(page, x, y, 0, 200);
|
||||||
|
c = (await measured(page))[1];
|
||||||
|
expect(c.sized).toBe(true);
|
||||||
|
expect(Math.abs(c.panes[n - 1].top - (y + 200))).toBeLessThanOrEqual(1.5);
|
||||||
|
expect(Math.abs(c.panes[n - 2].h - (shown[n - 2] + 200))).toBeLessThanOrEqual(1.5);
|
||||||
|
for (let i = 0; i < n - 2; i++) expect(Math.abs(c.panes[i].h - shown[i])).toBeLessThanOrEqual(1.5);
|
||||||
|
for (let i = 1; i < n; i++) expect(Math.abs(c.panes[i].top - (c.panes[i - 1].top + c.panes[i - 1].h))).toBeLessThanOrEqual(1);
|
||||||
|
});
|
||||||
+65
-3
@@ -1,7 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* The panes view: a click anywhere in a pane makes it active and anywhere clears a
|
* The panes view: a click anywhere in a pane makes it active and anywhere clears a
|
||||||
* selection; a column's panes stand in the order of their sources; every pane in a crowded column
|
* selection; a column's panes stand in the order of their sources; every pane in a crowded column
|
||||||
* shows at least its tab, above or below; a pane cut off for any reason peeks out whole; the curves
|
* shows at least its tab, above or below; the active pane is never cut short by its share of a
|
||||||
|
* column; a pane cut off for any reason peeks out whole; the curves
|
||||||
* keep to their sources and landing lines through every kind of layout change (curveFaults); the
|
* keep to their sources and landing lines through every kind of layout change (curveFaults); the
|
||||||
* selection bar keeps clear of a tab; a dotted curve turns toward its source; Alt with h j k l moves
|
* selection bar keeps clear of a tab; a dotted curve turns toward its source; Alt with h j k l moves
|
||||||
* between panes. Same build, mock model and mock Wikipedia as the others.
|
* between panes. Same build, mock model and mock Wikipedia as the others.
|
||||||
@@ -142,6 +143,67 @@ test("every pane of a crowded column shows at least its tab, above or below the
|
|||||||
expect(stubs).toBe(0);
|
expect(stubs).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("the active pane is never cut short by its share of a column: the others give way, folding to their tabs, as its Wikipedia card arrives; once the active pane is elsewhere, the column shares again", async ({ page }) => {
|
||||||
|
await library(page);
|
||||||
|
await clickOpen(page, "Library", "Octopus minds");
|
||||||
|
await clickOpen(page, "Octopus minds", "A separate experiment");
|
||||||
|
await clickOpen(page, "Octopus minds", "A body with many minds");
|
||||||
|
await clickOpen(page, "A body with many minds", "Counting neurons");
|
||||||
|
// A definition beside it, active: its line and then, once it has arrived, the article's card.
|
||||||
|
await clickOpen(page, "A separate experiment", "cephalopod", ".lnk, .anchor");
|
||||||
|
await page.mouse.move(5, 500);
|
||||||
|
/** The panes of the column holding Counting neurons: what each needs, its height, what shows of it. */
|
||||||
|
const column = () =>
|
||||||
|
pane(page, "Counting neurons").evaluate((el) => {
|
||||||
|
const col = el.parentElement!;
|
||||||
|
const c = col.getBoundingClientRect();
|
||||||
|
const ps = [...col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||||
|
return {
|
||||||
|
crowded: col.classList.contains("crowded"),
|
||||||
|
h: c.height,
|
||||||
|
panes: ps.map((p, i) => {
|
||||||
|
const r = p.getBoundingClientRect();
|
||||||
|
const sc = getComputedStyle(p.querySelector(".pane-scroll")!);
|
||||||
|
return {
|
||||||
|
t: p.querySelector(".pane-head h2, .top h1")?.textContent?.trim(),
|
||||||
|
active: p.classList.contains("active"),
|
||||||
|
height: r.height,
|
||||||
|
shown: Math.min(ps[i + 1]?.getBoundingClientRect().top ?? Infinity, c.bottom) - Math.max(r.top, c.top),
|
||||||
|
need: p.querySelector<HTMLElement>(".pane-body")!.offsetHeight + parseFloat(sc.paddingTop) + parseFloat(sc.paddingBottom),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
/** The active pane shows all it needs, up to the column less a tab for each other pane; every other pane shows at least its tab. */
|
||||||
|
const whole = async (label: string) => {
|
||||||
|
await still(page);
|
||||||
|
await expect
|
||||||
|
.poll(async () => {
|
||||||
|
const c = await column();
|
||||||
|
const a = c.panes.find((p) => p.active)!;
|
||||||
|
return a.shown >= Math.min(a.need, c.h - (c.panes.length - 1) * TAB) - 2 && c.panes.every((p) => p.shown >= TAB - 1);
|
||||||
|
}, label)
|
||||||
|
.toBe(true);
|
||||||
|
};
|
||||||
|
await whole("the definition active");
|
||||||
|
let c = await column();
|
||||||
|
expect(c.panes.map((p) => p.t)).toEqual(["“cephalopod”", "Counting neurons"]);
|
||||||
|
// Its card is in (it needs more than half the column, which an even share would give it), and the column stacks to show it whole.
|
||||||
|
expect(c.panes[0].need).toBeGreaterThan(c.h / 2);
|
||||||
|
expect(c.crowded).toBe(true);
|
||||||
|
await noFaults(page, "the definition active");
|
||||||
|
// The other pane active: it is the one shown whole.
|
||||||
|
await pane(page, "Counting neurons").locator(".pane-head h2").dispatchEvent("click");
|
||||||
|
await whole("Counting neurons active");
|
||||||
|
// The active pane in another column: this one shares its height as before, each pane what it needs or an even share.
|
||||||
|
await pane(page, "A body with many minds").locator(".pane-head h2").dispatchEvent("click");
|
||||||
|
await still(page);
|
||||||
|
c = await column();
|
||||||
|
expect(c.crowded).toBe(false);
|
||||||
|
for (const p of c.panes) expect(p.height, p.t).toBeGreaterThanOrEqual(Math.min(p.need, c.h / 2) - 2);
|
||||||
|
await noFaults(page, "the active pane elsewhere");
|
||||||
|
});
|
||||||
|
|
||||||
test("a pane cut off for any reason peeks out whole, across and down, and the curves follow it: covered from below or above, by its share, by the column's foot, beside a pinned pane, and with its column covered", async ({ page }) => {
|
test("a pane cut off for any reason peeks out whole, across and down, and the curves follow it: covered from below or above, by its share, by the column's foot, beside a pinned pane, and with its column covered", async ({ page }) => {
|
||||||
await page.setViewportSize({ width: 1920, height: 700 });
|
await page.setViewportSize({ width: 1920, height: 700 });
|
||||||
await library(page);
|
await library(page);
|
||||||
@@ -210,13 +272,13 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
|
|||||||
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
|
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
|
||||||
expect(await sweep("column covered", true)).toBeGreaterThan(0);
|
expect(await sweep("column covered", true)).toBeGreaterThan(0);
|
||||||
|
|
||||||
// By its share of a column that is not crowded: a tall window, two top-level trees, one longer than its share.
|
// By its share of a column that is not crowded: a tall window, two top-level trees, one longer than its share, the active pane in another column (the active one is never cut short by its share).
|
||||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||||
await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).forEach((k) => localStorage.removeItem(k)));
|
await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).forEach((k) => localStorage.removeItem(k)));
|
||||||
await library(page);
|
await library(page);
|
||||||
await clickOpen(page, "Library", "Explicata");
|
await clickOpen(page, "Library", "Explicata");
|
||||||
await clickOpen(page, "Library", "Octopus minds");
|
await clickOpen(page, "Library", "Octopus minds");
|
||||||
await pane(page, "Octopus minds").locator(".pane-head h2").dispatchEvent("click");
|
await pane(page, "Library").locator(".top h1").dispatchEvent("click");
|
||||||
await still(page);
|
await still(page);
|
||||||
expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false);
|
expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false);
|
||||||
expect(await sweep("by share", false)).toBeGreaterThan(0);
|
expect(await sweep("by share", false)).toBeGreaterThan(0);
|
||||||
|
|||||||
+279
-63
@@ -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, crowds, fill, fit, folded, mark, offsets, release, resize, reveal, setAttr, starts, stick, unmark, whole } from "./stack";
|
import { ACROSS, DOWN, crowds, fill, fit, folded, mark, offsets, release, resize, reveal, setAttr, share, 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 { Close, Pin, W } from "./Pages";
|
import { Close, Pin, W } from "./Pages";
|
||||||
@@ -336,9 +336,9 @@ const PEEK_MS = 200;
|
|||||||
|
|
||||||
/** As pages, how far a finger moves on a pane's handle before its direction is known: up or down resizes the pane, sideways is the browser's (the page turns). */
|
/** As pages, how far a finger moves on a pane's handle before its direction is known: up or down resizes the pane, sideways is the browser's (the page turns). */
|
||||||
const LOCK_PX = 8;
|
const LOCK_PX = 8;
|
||||||
/** As pages, a pane sized by hand left less than this much taller than its tab folds to it when the finger lifts. */
|
/** A pane sized by hand left less than this much taller than its tab folds to it when the finger lifts (side by side, the mouse lets go). */
|
||||||
const FOLD_SNAP = 40;
|
const FOLD_SNAP = 40;
|
||||||
/** As pages, how long a released edge takes to come to rest at a fold, easing out. */
|
/** How long a released edge takes to come to rest at a fold, easing out. */
|
||||||
const SNAP_MS = 120;
|
const SNAP_MS = 120;
|
||||||
/** As pages, two taps on a pane's handle this close together put its page back to the automatic sizes. */
|
/** As pages, two taps on a pane's handle this close together put its page back to the automatic sizes. */
|
||||||
const DOUBLE_TAP_MS = 320;
|
const DOUBLE_TAP_MS = 320;
|
||||||
@@ -356,30 +356,70 @@ interface Hand {
|
|||||||
sizes: Map<number, number>;
|
sizes: Map<number, number>;
|
||||||
here: number | undefined;
|
here: number | undefined;
|
||||||
}
|
}
|
||||||
const hands = new Map<number, Hand>();
|
/**
|
||||||
/** The page whose released edge is easing to rest: laid out by its animation alone meanwhile. */
|
* The columns sized by hand, as pages and as panes side by side (by the mouse, an edge between two
|
||||||
|
* panes dragged; there `here` is the active pane when they were sized, and the rule is `deskSizes`'s).
|
||||||
|
* Kept apart, so a phone turned wide and back finds its pages as it left them.
|
||||||
|
*/
|
||||||
|
const handsBy = { pages: new Map<number, Hand>(), panes: new Map<number, Hand>() };
|
||||||
|
const hands = () => (store.pages ? handsBy.pages : handsBy.panes);
|
||||||
|
/** The page (side by side, the column) whose released edge is easing to rest: laid out by its animation alone meanwhile. */
|
||||||
let easing: HTMLElement | null = null;
|
let easing: HTMLElement | null = null;
|
||||||
const setOf = (tids: number[]) => [...tids].sort((a, b) => a - b).join();
|
const setOf = (tids: number[]) => [...tids].sort((a, b) => a - b).join();
|
||||||
|
|
||||||
/** A column's sizes by hand, fitted to its height, if they hold (else they are dropped). */
|
/** Sizes by hand fitted to a column of height h (and kept so); null if a tab each does not fit. */
|
||||||
|
function fitHand(m: Hand, tids: number[], h: number): number[] | null {
|
||||||
|
const hs = tids.map((t) => m.sizes.get(t) ?? TAB);
|
||||||
|
if (Math.abs(hs.reduce((a, b) => a + b, 0) - h) < 0.5) return hs;
|
||||||
|
const f = fit(hs, h, TAB);
|
||||||
|
if (f) tids.forEach((t, i) => m.sizes.set(t, f[i]));
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** As pages, a column's sizes by hand, fitted to its height, if they hold (else they are dropped). */
|
||||||
function handSizes(col: number, tids: number[], here: number | undefined, h: number): number[] | null {
|
function handSizes(col: number, tids: number[], here: number | undefined, h: number): number[] | null {
|
||||||
const m = hands.get(col);
|
const m = handsBy.pages.get(col);
|
||||||
if (!m) return null;
|
if (!m) return null;
|
||||||
const drop = () => (hands.delete(col), null);
|
const drop = () => (handsBy.pages.delete(col), null);
|
||||||
if (m.set !== setOf(tids)) return drop();
|
if (m.set !== setOf(tids)) return drop();
|
||||||
if (here !== m.here) {
|
if (here !== m.here) {
|
||||||
if (here === undefined || folded(m.sizes.get(here) ?? 0, TAB)) return drop();
|
if (here === undefined || folded(m.sizes.get(here) ?? 0, TAB)) return drop();
|
||||||
m.here = here;
|
m.here = here;
|
||||||
}
|
}
|
||||||
let hs = tids.map((t) => m.sizes.get(t) ?? TAB);
|
return fitHand(m, tids, h) ?? drop();
|
||||||
if (Math.abs(hs.reduce((a, b) => a + b, 0) - h) >= 0.5) {
|
|
||||||
const f = fit(hs, h, TAB);
|
|
||||||
if (!f) return drop();
|
|
||||||
hs = f;
|
|
||||||
tids.forEach((t, i) => m.sizes.set(t, f[i]));
|
|
||||||
}
|
}
|
||||||
return hs;
|
|
||||||
|
/**
|
||||||
|
* As panes side by side, a column's sizes by hand: only a pinned pane's size sticks. Once another
|
||||||
|
* pane is the active one, or a pane opens or closes in the column, the sizes of its unpinned panes
|
||||||
|
* are the layout's again (undefined here: `share` gives them what the pinned ones leave) and, with
|
||||||
|
* no pinned pane sized there, so is the column (null). Fitted to its height while they hold.
|
||||||
|
*/
|
||||||
|
function deskSizes(col: number, tids: number[], pinned: boolean[], active: number | undefined, h: number): (number | undefined)[] | null {
|
||||||
|
const m = handsBy.panes.get(col);
|
||||||
|
if (!m) return null;
|
||||||
|
const drop = () => (handsBy.panes.delete(col), null);
|
||||||
|
if (m.here !== active || m.set !== setOf(tids)) {
|
||||||
|
m.here = active;
|
||||||
|
m.set = setOf(tids);
|
||||||
|
for (const t of [...m.sizes.keys()]) if (!pinned[tids.indexOf(t)]) m.sizes.delete(t);
|
||||||
|
if (!m.sizes.size) return drop();
|
||||||
}
|
}
|
||||||
|
if (tids.some((t) => !m.sizes.has(t))) return tids.map((t) => m.sizes.get(t));
|
||||||
|
return fitHand(m, tids, h) ?? drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As panes side by side, columns sized by hand (the edge between two dragged, stack.ts `resize`
|
||||||
|
* across): each column's width by its number, and the active pane when they were set. A column
|
||||||
|
* holding a pinned pane keeps its width; the others' are the layout's again once another pane is
|
||||||
|
* the active one.
|
||||||
|
*/
|
||||||
|
const widths = { sizes: new Map<number, number>(), here: undefined as number | undefined };
|
||||||
|
/** The least width a column is dragged to. */
|
||||||
|
const COL_MIN = 240;
|
||||||
|
/** As panes side by side, how near an edge between two panes, or two columns, the mouse takes it (each side). */
|
||||||
|
const EDGE_PX = 4;
|
||||||
|
|
||||||
/** Set the panes' heights, and show the tab of each folded to it. Only heights: nothing is measured. */
|
/** Set the panes' heights, and show the tab of each folded to it. Only heights: nothing is measured. */
|
||||||
function setHeights(ps: HTMLElement[], hs: number[]) {
|
function setHeights(ps: HTMLElement[], hs: number[]) {
|
||||||
@@ -460,9 +500,10 @@ export function Panes() {
|
|||||||
/**
|
/**
|
||||||
* Lay out the stacks (stack.ts). Across: each column stuck a spine after the one before (a pinned
|
* Lay out the stacks (stack.ts). Across: each column stuck a spine after the one before (a pinned
|
||||||
* pane's column, its whole width). Down: a column with several panes divides its height among
|
* pane's column, its whole width). Down: a column with several panes divides its height among
|
||||||
* them, a pane taking what its text needs; when they do not all fit, it becomes a stack of its
|
* them, a pane taking what its text needs; when they do not all fit, or a share would cut short
|
||||||
* own, each pane stuck a tab below the one before (a pinned one, its height) and the column
|
* the active pane (as pages, the pane looked at on the page), it becomes a stack of its own, each
|
||||||
* scrolled to show whole the pane on the focused branch, or the one last on it there.
|
* pane stuck a tab below the one before (a pinned one, its height) and the column scrolled to
|
||||||
|
* show whole the pane on the focused branch, or the one last on it there.
|
||||||
*/
|
*/
|
||||||
const layout = (all = false) => {
|
const layout = (all = false) => {
|
||||||
const el = strip.current;
|
const el = strip.current;
|
||||||
@@ -471,17 +512,30 @@ export function Panes() {
|
|||||||
if (!colEls.length) return;
|
if (!colEls.length) return;
|
||||||
clearTimeout(later.current);
|
clearTimeout(later.current);
|
||||||
const activeCol = activeId === undefined ? null : paneEls(el).get(activeId)?.parentElement;
|
const activeCol = activeId === undefined ? null : paneEls(el).get(activeId)?.parentElement;
|
||||||
const w = colEls[0].offsetWidth;
|
|
||||||
const spine = colEls[0].querySelector<HTMLElement>(".spine")?.offsetWidth ?? 0;
|
const spine = colEls[0].querySelector<HTMLElement>(".spine")?.offsetWidth ?? 0;
|
||||||
// With no scrollbar under the panes (none needed, or one drawn over them) their last bottom edge meets the status line's: one line, not two.
|
// With no scrollbar under the panes (none needed, or one drawn over them) their last bottom edge meets the status line's: one line, not two.
|
||||||
setAttr(el, "data-flush", el.offsetHeight - el.clientHeight < 1);
|
setAttr(el, "data-flush", el.offsetHeight - el.clientHeight < 1);
|
||||||
if (pages) {
|
if (pages) {
|
||||||
// As pages nothing is stacked across: each column is a page of its own.
|
// As pages nothing is stacked across: each column is a page of its own, as wide as the screen.
|
||||||
lefts.current = colEls.map(() => 0);
|
lefts.current = colEls.map(() => 0);
|
||||||
for (const c of colEls) if (c.style.left) c.style.left = "";
|
for (const c of colEls) {
|
||||||
|
if (c.style.left) c.style.left = "";
|
||||||
|
if (c.style.width) c.style.width = "";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Widths by hand: a column holding a pinned pane keeps its own; the others', once another pane is the active one, are the layout's again.
|
||||||
|
const at = new Set(colEls.map((c) => Number(c.dataset.col)));
|
||||||
|
const keep = new Set(colEls.filter((c) => c.hasAttribute("data-pinned")).map((c) => Number(c.dataset.col)));
|
||||||
|
const moved = widths.here !== activeId;
|
||||||
|
widths.here = activeId;
|
||||||
|
for (const k of [...widths.sizes.keys()]) if (!at.has(k) || (moved && !keep.has(k))) widths.sizes.delete(k);
|
||||||
|
for (const c of colEls) {
|
||||||
|
const by = widths.sizes.get(Number(c.dataset.col));
|
||||||
|
const v = by === undefined ? "" : `${by}px`;
|
||||||
|
if (c.style.width !== v) c.style.width = v;
|
||||||
|
}
|
||||||
lefts.current = offsets(
|
lefts.current = offsets(
|
||||||
colEls.map(() => w),
|
colEls.map((c) => c.offsetWidth),
|
||||||
colEls.map((c) => c.hasAttribute("data-pinned")),
|
colEls.map((c) => c.hasAttribute("data-pinned")),
|
||||||
spine,
|
spine,
|
||||||
el.clientWidth,
|
el.clientWidth,
|
||||||
@@ -491,22 +545,41 @@ export function Panes() {
|
|||||||
let deferred = false;
|
let deferred = false;
|
||||||
for (const c of colEls) {
|
for (const c of colEls) {
|
||||||
const ps = [...c.children].filter((p): p is HTMLElement => p.classList.contains("pane"));
|
const ps = [...c.children].filter((p): p is HTMLElement => p.classList.contains("pane"));
|
||||||
|
const col = Number(c.dataset.col);
|
||||||
if (ps.length < 2) {
|
if (ps.length < 2) {
|
||||||
for (const p of ps) if (p.style.height) (p.style.height = ""), (p.style.flex = ""), (p.style.top = ""), (p.style.bottom = "");
|
for (const p of ps) if (p.style.height) (p.style.height = ""), (p.style.flex = ""), (p.style.top = ""), (p.style.bottom = "");
|
||||||
c.classList.remove("crowded", "sized", "tight");
|
c.classList.remove("crowded", "sized", "tight");
|
||||||
unmark(ps);
|
unmark(ps);
|
||||||
|
// Side by side, a pane alone in its column has no edge to have been sized by.
|
||||||
|
if (!pages) handsBy.panes.delete(col);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const h = c.clientHeight;
|
const h = c.clientHeight;
|
||||||
const col = Number(c.dataset.col);
|
|
||||||
const tids = ps.map((p) => Number(p.dataset.tid));
|
const tids = ps.map((p) => Number(p.dataset.tid));
|
||||||
// The pane to show whole: on the focused branch, or the one last on it here.
|
// The pane to show whole: on the focused branch, or the one last on it here.
|
||||||
const here = paneOfPage(tids, onBranch, lastIn.current.get(col))!;
|
const here = paneOfPage(tids, onBranch, lastIn.current.get(col))!;
|
||||||
const sig = tids.map((t, i) => `${t}${ps[i].classList.contains("pinned") ? "^" : ""}`).join();
|
const pinned = ps.map((p) => p.classList.contains("pinned"));
|
||||||
|
const sig = tids.map((t, i) => `${t}${pinned[i] ? "^" : ""}`).join();
|
||||||
// As pages, a page too short for a tab for each of its panes is never sized by hand (its handles scroll it).
|
// As pages, a page too short for a tab for each of its panes is never sized by hand (its handles scroll it).
|
||||||
c.classList.toggle("tight", pages && ps.length * TAB > h);
|
c.classList.toggle("tight", pages && ps.length * TAB > h);
|
||||||
// As pages, sized by hand (a pane's handle dragged): those sizes, while they hold.
|
/** What each pane needs to show all it holds; a buried pane is not laid out, so it keeps what it last needed. */
|
||||||
const hand = pages ? handSizes(col, tids, here, h) : null;
|
const measureNeeds = () => {
|
||||||
|
const cs = getComputedStyle(ps[0].querySelector<HTMLElement>(".pane-scroll")!);
|
||||||
|
const pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom) + 1;
|
||||||
|
return ps.map((p, i) => {
|
||||||
|
if (p.hasAttribute("data-buried") && needs.current.has(tids[i])) return needs.current.get(tids[i])!;
|
||||||
|
const n = p.querySelector<HTMLElement>(".pane-body")!.offsetHeight + pad;
|
||||||
|
needs.current.set(tids[i], n);
|
||||||
|
return n;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
// The pane looked at, which a share must not cut short: as pages the page's; side by side the active pane, in its column (elsewhere none: those columns share as they will).
|
||||||
|
const k = tids.indexOf(here);
|
||||||
|
const first = pages || here === activeId ? k : undefined;
|
||||||
|
// Sized by hand (as pages a pane's handle dragged, side by side an edge): those sizes, while they hold; side by side, the panes not pinned share what the pinned ones leave, the active one first.
|
||||||
|
const by: (number | undefined)[] | null = pages ? handSizes(col, tids, here, h) : deskSizes(col, tids, pinned, activeId, h);
|
||||||
|
const hand = by?.includes(undefined) ? share(by, measureNeeds(), h, TAB, first) : (by as number[] | null);
|
||||||
|
if (by && !hand) handsBy.panes.delete(col);
|
||||||
if (hand) {
|
if (hand) {
|
||||||
if (easing !== c) sizeBy(c, ps, hand);
|
if (easing !== c) sizeBy(c, ps, hand);
|
||||||
laid.current.set(c, sig);
|
laid.current.set(c, sig);
|
||||||
@@ -514,20 +587,9 @@ export function Panes() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
c.classList.remove("sized");
|
c.classList.remove("sized");
|
||||||
const sc = ps[0].querySelector<HTMLElement>(".pane-scroll")!;
|
const need = measureNeeds();
|
||||||
const cs = getComputedStyle(sc);
|
// The pane looked at has the column's height whenever a share would cut it short (as pages, the screen's): the others fold to their tabs.
|
||||||
const pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom) + 1;
|
const crowded = crowds(h, need, PANE_MIN, first);
|
||||||
// What each pane needs to show all it holds; a buried pane is not laid out, so it keeps what it last needed.
|
|
||||||
const need = ps.map((p, i) => {
|
|
||||||
if (p.hasAttribute("data-buried") && needs.current.has(tids[i])) return needs.current.get(tids[i])!;
|
|
||||||
const n = p.querySelector<HTMLElement>(".pane-body")!.offsetHeight + pad;
|
|
||||||
needs.current.set(tids[i], n);
|
|
||||||
return n;
|
|
||||||
});
|
|
||||||
const pinned = ps.map((p) => p.classList.contains("pinned"));
|
|
||||||
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. */
|
||||||
@@ -646,7 +708,9 @@ export function Panes() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const w = colEls[0].offsetWidth;
|
// Each column's width (one sized by hand has its own), and where it starts when nothing is stuck.
|
||||||
|
const w = colEls.map((c) => c.offsetWidth);
|
||||||
|
const x = starts(w);
|
||||||
const view = el.clientWidth;
|
const view = el.clientWidth;
|
||||||
const max = el.scrollWidth - view;
|
const max = el.scrollWidth - view;
|
||||||
const L = lefts.current;
|
const L = lefts.current;
|
||||||
@@ -655,11 +719,11 @@ export function Panes() {
|
|||||||
const here = colOf(panes[at]);
|
const here = colOf(panes[at]);
|
||||||
const was = lastCol.current;
|
const was = lastCol.current;
|
||||||
lastCol.current = here;
|
lastCol.current = here;
|
||||||
if (here === was && whole(el.scrollLeft, view, b * w, w, L[b] ?? 0)) return;
|
if (here === was && whole(el.scrollLeft, view, x[b], w[b], L[b] ?? 0)) return;
|
||||||
// Column i starts at i·w: show b whole, and the one before it too when both fit.
|
// Show b whole, and the one before it too when both fit.
|
||||||
const a = b > 0 && (showing || f.grain === "node") ? b - 1 : b;
|
const a = b > 0 && (showing || f.grain === "node") ? b - 1 : b;
|
||||||
const both = reveal(el.scrollLeft, view, a * w, (b + 1 - a) * w, L[a] ?? 0, max);
|
const both = reveal(el.scrollLeft, view, x[a], x[b] + w[b] - x[a], L[a] ?? 0, max);
|
||||||
const target = whole(both, view, b * w, w, L[b] ?? 0) && whole(both, view, a * w, w, L[a] ?? 0) ? both : reveal(el.scrollLeft, view, b * w, w, L[b] ?? 0, max);
|
const target = whole(both, view, x[b], w[b], L[b] ?? 0) && whole(both, view, x[a], w[a], L[a] ?? 0) ? both : reveal(el.scrollLeft, view, x[b], w[b], L[b] ?? 0, max);
|
||||||
if (Math.abs(target - el.scrollLeft) > 1) el.scrollTo({ left: target, behavior: reducedMotion() ? "auto" : "smooth" });
|
if (Math.abs(target - el.scrollLeft) > 1) el.scrollTo({ left: target, behavior: reducedMotion() ? "auto" : "smooth" });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -893,6 +957,8 @@ export function Panes() {
|
|||||||
};
|
};
|
||||||
const onMove = (e: PointerEvent) => {
|
const onMove = (e: PointerEvent) => {
|
||||||
if (e.pointerType !== "mouse" || e.buttons || drag) return;
|
if (e.pointerType !== "mouse" || e.buttons || drag) return;
|
||||||
|
// On an edge between panes (below): it is pressed to resize, not peeked through.
|
||||||
|
if (wrap.dataset.edge) return unpeek();
|
||||||
const pane = (e.target as HTMLElement).closest<HTMLElement>(".pane");
|
const pane = (e.target as HTMLElement).closest<HTMLElement>(".pane");
|
||||||
if (pane && (pane === peekedFor || pane === pending)) return;
|
if (pane && (pane === peekedFor || pane === pending)) return;
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
@@ -914,7 +980,6 @@ export function Panes() {
|
|||||||
if (now.length) peek(pane, now);
|
if (now.length) peek(pane, now);
|
||||||
}, PEEK_MS);
|
}, PEEK_MS);
|
||||||
};
|
};
|
||||||
el.addEventListener("pointermove", onMove, { signal });
|
|
||||||
el.addEventListener("pointerleave", unpeek, { signal });
|
el.addEventListener("pointerleave", unpeek, { signal });
|
||||||
window.addEventListener("keydown", unpeek, { capture: true, signal });
|
window.addEventListener("keydown", unpeek, { capture: true, signal });
|
||||||
|
|
||||||
@@ -934,7 +999,7 @@ export function Panes() {
|
|||||||
return handle && pane && col && col.children.length > 1 ? { handle, pane, col } : null;
|
return handle && pane && col && col.children.length > 1 ? { handle, pane, col } : null;
|
||||||
};
|
};
|
||||||
const onDown = (e: PointerEvent) => {
|
const onDown = (e: PointerEvent) => {
|
||||||
if (e.button !== 0 || (e.pointerType === "touch" && store.pages)) return;
|
if (e.button !== 0 || (e.pointerType === "touch" && store.pages) || edging) return;
|
||||||
const h = handleAt(e.target);
|
const h = handleAt(e.target);
|
||||||
if (!h) return;
|
if (!h) return;
|
||||||
const { handle, pane, col } = h;
|
const { handle, pane, col } = h;
|
||||||
@@ -1064,13 +1129,18 @@ export function Panes() {
|
|||||||
* down resizes (the handles' touch-action leaves only sideways to the browser, so nothing
|
* down resizes (the handles' touch-action leaves only sideways to the browser, so nothing
|
||||||
* scrolls first), sideways is the browser's, a swipe that turns the page. During the drag only
|
* scrolls first), sideways is the browser's, a swipe that turns the page. During the drag only
|
||||||
* the panes' heights are set. When the finger lifts, a pane left barely taller than its tab
|
* the panes' heights are set. When the finger lifts, a pane left barely taller than its tab
|
||||||
* folds (SNAP_MS). The sizes hold as `hands` says; a double tap on a handle drops them.
|
* folds (SNAP_MS). The sizes hold as `handSizes` says; a double tap on a handle drops them.
|
||||||
|
* Side by side, the mouse drags the same edge (below), and the sizes hold as `deskSizes` says.
|
||||||
*/
|
*/
|
||||||
let press: { x: number; y: number; id: number; pane: HTMLElement; col: HTMLElement; i: number; lock: "v" | null; start: number[]; ps: HTMLElement[]; now: number[]; dy: number } | null = null;
|
/** An edge being dragged, by a finger or the mouse: the pane below it (i, in ps), the sizes the drag began with, those now, and how far it has moved. */
|
||||||
|
type Resizing = { pane: HTMLElement; col: HTMLElement; i: number; start: number[]; ps: HTMLElement[]; now: number[]; dy: number };
|
||||||
|
/** A finger on a handle: where it went down, and whether it has turned into a resize (lock). */
|
||||||
|
type Press = Resizing & { x: number; y: number; id: number; lock: "v" | null };
|
||||||
|
let press: Press | null = null;
|
||||||
let lastTap: { col: HTMLElement; t: number; x: number; y: number } | null = null;
|
let lastTap: { col: HTMLElement; t: number; x: number; y: number } | null = null;
|
||||||
let snapping = 0;
|
let snapping = 0;
|
||||||
/** The handle's page laid out by hand from what shows of each pane now (no jump): false if it cannot be (a tab each does not fit). */
|
/** The handle's page (side by side, the edge's column) laid out by hand from what shows of each pane now (no jump): false if it cannot be (a tab each does not fit). */
|
||||||
const startResize = (r: NonNullable<typeof press>): boolean => {
|
const startResize = (r: Resizing): boolean => {
|
||||||
const ps = [...r.col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
const ps = [...r.col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||||
const h = r.col.clientHeight;
|
const h = r.col.clientHeight;
|
||||||
if (r.i < 1 || ps.length * TAB > h || !ps.includes(r.pane)) return false;
|
if (r.i < 1 || ps.length * TAB > h || !ps.includes(r.pane)) return false;
|
||||||
@@ -1084,27 +1154,29 @@ export function Panes() {
|
|||||||
easing = null;
|
easing = null;
|
||||||
unpeek();
|
unpeek();
|
||||||
const tids = ps.map((p) => Number(p.dataset.tid));
|
const tids = ps.map((p) => Number(p.dataset.tid));
|
||||||
const was = hands.get(Number(r.col.dataset.col));
|
const was = hands().get(Number(r.col.dataset.col));
|
||||||
hands.set(Number(r.col.dataset.col), { set: setOf(tids), sizes: new Map(tids.map((t, k) => [t, start[k]])), here: was?.here ?? shown.current.get(r.col) });
|
// As pages, the pane looked at on the page; side by side, the active pane (deskSizes).
|
||||||
|
const here = store.pages ? (was?.here ?? shown.current.get(r.col)) : store.branchNodes[store.paneAt]?.id;
|
||||||
|
hands().set(Number(r.col.dataset.col), { set: setOf(tids), sizes: new Map(tids.map((t, k) => [t, start[k]])), here });
|
||||||
sizeBy(r.col, ps, start);
|
sizeBy(r.col, ps, start);
|
||||||
Object.assign(r, { ps, start, now: start, i: ps.indexOf(r.pane) });
|
Object.assign(r, { ps, start, now: start, i: ps.indexOf(r.pane) });
|
||||||
wrap.classList.add("resizing");
|
wrap.classList.add("resizing");
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const moveResize = (r: NonNullable<typeof press>, dy: number) => {
|
const moveResize = (r: Resizing, dy: number) => {
|
||||||
r.dy = dy;
|
r.dy = dy;
|
||||||
r.now = resize(r.start, r.i, dy, TAB);
|
r.now = resize(r.start, r.i, dy, TAB);
|
||||||
setHeights(r.ps, r.now);
|
setHeights(r.ps, r.now);
|
||||||
const m = hands.get(Number(r.col.dataset.col));
|
const m = hands().get(Number(r.col.dataset.col));
|
||||||
if (m) r.ps.forEach((p, k) => m.sizes.set(Number(p.dataset.tid), r.now[k]));
|
if (m) r.ps.forEach((p, k) => m.sizes.set(Number(p.dataset.tid), r.now[k]));
|
||||||
};
|
};
|
||||||
/** The finger lifted: the edge comes to rest, at a fold if a pane is left barely taller than its tab; a pane looked at folded away hands that to the pane across the edge. */
|
/** The finger lifted (the mouse let go): the edge comes to rest, at a fold if a pane is left barely taller than its tab; as pages, a pane looked at folded away hands that to the pane across the edge. */
|
||||||
const endResize = (r: NonNullable<typeof press>) => {
|
const endResize = (r: Resizing) => {
|
||||||
wrap.classList.remove("resizing");
|
wrap.classList.remove("resizing");
|
||||||
const to = release(r.start, r.i, r.dy, TAB, FOLD_SNAP);
|
const to = release(r.start, r.i, r.dy, TAB, FOLD_SNAP);
|
||||||
const tids = r.ps.map((p) => Number(p.dataset.tid));
|
const tids = r.ps.map((p) => Number(p.dataset.tid));
|
||||||
const col = Number(r.col.dataset.col);
|
const col = Number(r.col.dataset.col);
|
||||||
const m = hands.get(col);
|
const m = hands().get(col);
|
||||||
// Dropped while the finger was down (its panes changed): laid out automatically.
|
// Dropped while the finger was down (its panes changed): laid out automatically.
|
||||||
if (!m) return relayout();
|
if (!m) return relayout();
|
||||||
tids.forEach((t, k) => m.sizes.set(t, to[k]));
|
tids.forEach((t, k) => m.sizes.set(t, to[k]));
|
||||||
@@ -1120,13 +1192,17 @@ export function Panes() {
|
|||||||
const p = Math.min(1, (now - t0) / SNAP_MS);
|
const p = Math.min(1, (now - t0) / SNAP_MS);
|
||||||
const e = 1 - (1 - p) ** 3;
|
const e = 1 - (1 - p) ** 3;
|
||||||
// Its panes changed meanwhile: the layout has it now.
|
// Its panes changed meanwhile: the layout has it now.
|
||||||
if (!r.ps.every((x) => x.isConnected) || !hands.has(col)) return void (easing = null, latest.current(true));
|
if (!r.ps.every((x) => x.isConnected) || !hands().has(col)) return void (easing = null, latest.current(true));
|
||||||
setHeights(r.ps, p < 1 ? from.map((x, k) => x + (to[k] - x) * e) : to);
|
setHeights(r.ps, p < 1 ? from.map((x, k) => x + (to[k] - x) * e) : to);
|
||||||
|
// Side by side, the curves go with the edge.
|
||||||
|
if (!store.pages) schedule();
|
||||||
if (p < 1) snapping = requestAnimationFrame(step);
|
if (p < 1) snapping = requestAnimationFrame(step);
|
||||||
else easing = null;
|
else easing = null;
|
||||||
};
|
};
|
||||||
snapping = requestAnimationFrame(step);
|
snapping = requestAnimationFrame(step);
|
||||||
}
|
}
|
||||||
|
// Side by side a pane folded to its tab stays where the keys are: nothing has to be looked at whole.
|
||||||
|
if (!store.pages) return;
|
||||||
const active = store.branchNodes[store.paneAt]?.id;
|
const active = store.branchNodes[store.paneAt]?.id;
|
||||||
const a = active === undefined ? -1 : tids.indexOf(active);
|
const a = active === undefined ? -1 : tids.indexOf(active);
|
||||||
if (a < 0 || !folded(to[a], TAB)) return;
|
if (a < 0 || !folded(to[a], TAB)) return;
|
||||||
@@ -1135,9 +1211,9 @@ export function Panes() {
|
|||||||
m.here = tids[k];
|
m.here = tids[k];
|
||||||
store.toPane(tids[k]);
|
store.toPane(tids[k]);
|
||||||
};
|
};
|
||||||
/** A double tap on a handle: the page laid out automatically again. */
|
/** A double tap on a handle (a double click on an edge): the page, or column, laid out automatically again. */
|
||||||
const unsize = (col: HTMLElement) => {
|
const unsize = (col: HTMLElement) => {
|
||||||
if (!hands.delete(Number(col.dataset.col))) return;
|
if (!hands().delete(Number(col.dataset.col))) return;
|
||||||
cancelAnimationFrame(snapping);
|
cancelAnimationFrame(snapping);
|
||||||
easing = null;
|
easing = null;
|
||||||
relayout();
|
relayout();
|
||||||
@@ -1225,11 +1301,142 @@ export function Panes() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
|
* As panes side by side, by the mouse (or a pen): near an edge between two panes of a column, or
|
||||||
|
* between two columns side by side, the pointer takes the edge (EDGE_PX each side; data-edge on
|
||||||
|
* the panes sets the cursor, row-resize or col-resize, and keeps a press there from selecting
|
||||||
|
* text). Pressed and moved, it drags that edge as a finger drags a pane's top edge as pages:
|
||||||
|
* down a column the same splitter (startResize, moveResize, endResize: the pane below the edge
|
||||||
|
* and the one above give and take, a tab pushed along at the limit, a pane left barely taller
|
||||||
|
* than its tab folding), across the strip the columns' widths (stack.ts `resize`: the column
|
||||||
|
* after the edge gives what the one before takes, one at COL_MIN pushed along; nothing folds).
|
||||||
|
* A press there is never a click on a pane; a double click on an edge lays its column, or the
|
||||||
|
* strip, out automatically again; Esc puts the edge back. An outer edge, or one a column covers
|
||||||
|
* (stuck over the one before it), is no edge. The sizes hold as `deskSizes` and `widths` say: a
|
||||||
|
* pinned pane's size, and the width of a column holding one, stick; the others' are the
|
||||||
|
* layout's again once another pane is the active one.
|
||||||
|
*/
|
||||||
|
type EdgeAt = { axis: "row"; col: HTMLElement; pane: HTMLElement; i: number } | { axis: "col"; i: number };
|
||||||
|
type Edging = { at: EdgeAt; x: number; y: number; d: number; on: boolean; dead?: boolean; r?: Resizing; was?: Hand; widths?: Map<number, number>; start?: number[]; cols?: HTMLElement[] };
|
||||||
|
let edging: Edging | null = null;
|
||||||
|
/** The edge the pointer is near, if any: between two panes of the column under it, or between that column and one beside it where they meet. */
|
||||||
|
const edgeAt = (x: number, y: number, t: EventTarget | null): EdgeAt | null => {
|
||||||
|
const target = t as HTMLElement | null;
|
||||||
|
if (store.pages || !target?.closest || target.closest(".pane-ctl, .selbar, [data-peek]")) return null;
|
||||||
|
const col = target.closest<HTMLElement>(".strip > .col");
|
||||||
|
if (!col) return null;
|
||||||
|
const cols = [...el.querySelectorAll<HTMLElement>(":scope > .col")];
|
||||||
|
const k = cols.indexOf(col);
|
||||||
|
let best: EdgeAt | null = null;
|
||||||
|
let near = EDGE_PX + 1;
|
||||||
|
// Across: its left edge against the column before, its right against the one after, only where they meet.
|
||||||
|
for (const j of [k, k + 1]) {
|
||||||
|
if (j < 1 || j >= cols.length) continue;
|
||||||
|
const a = cols[j - 1].getBoundingClientRect();
|
||||||
|
const b = cols[j].getBoundingClientRect();
|
||||||
|
const d = Math.abs(x - b.left);
|
||||||
|
if (Math.abs(a.right - b.left) <= 1 && d < near) (best = { axis: "col", i: j }), (near = d);
|
||||||
|
}
|
||||||
|
// Down: the top of each pane but the first, where it shows in the column (in a crowded one, where it covers the pane before).
|
||||||
|
const ps = [...col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||||
|
const c = col.getBoundingClientRect();
|
||||||
|
for (let i = 1; i < ps.length; i++) {
|
||||||
|
const top = ps[i].getBoundingClientRect().top;
|
||||||
|
const d = Math.abs(y - top);
|
||||||
|
if (top > c.top + 1 && top < c.bottom - 1 && d < near) (best = { axis: "row", col, pane: ps[i], i }), (near = d);
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
};
|
||||||
|
const showEdge = (at: EdgeAt | null) => {
|
||||||
|
const v = at?.axis;
|
||||||
|
if (wrap.dataset.edge !== v) v ? (wrap.dataset.edge = v) : delete wrap.dataset.edge;
|
||||||
|
};
|
||||||
|
const onEdgeHover = (e: PointerEvent) => {
|
||||||
|
if (edging || e.pointerType === "touch") return;
|
||||||
|
showEdge(e.buttons || drag ? null : edgeAt(e.clientX, e.clientY, e.target));
|
||||||
|
};
|
||||||
|
const onEdgeDown = (e: PointerEvent) => {
|
||||||
|
if (e.button !== 0 || e.pointerType === "touch") return;
|
||||||
|
const at = edgeAt(e.clientX, e.clientY, e.target);
|
||||||
|
if (!at) return;
|
||||||
|
e.preventDefault();
|
||||||
|
el.setPointerCapture(e.pointerId);
|
||||||
|
unpeek();
|
||||||
|
showEdge(at);
|
||||||
|
edging = { at, x: e.clientX, y: e.clientY, d: 0, on: false };
|
||||||
|
};
|
||||||
|
/** The edge's column, or the strip's columns, laid out by hand from where they are now; false if they cannot be. */
|
||||||
|
const startEdge = (g: Edging): boolean => {
|
||||||
|
const at = g.at;
|
||||||
|
if (at.axis === "row") {
|
||||||
|
const m = handsBy.panes.get(Number(at.col.dataset.col));
|
||||||
|
const was = m && { ...m, sizes: new Map(m.sizes) };
|
||||||
|
const r: Resizing = { pane: at.pane, col: at.col, i: at.i, start: [], ps: [], now: [], dy: 0 };
|
||||||
|
if (!startResize(r)) return false;
|
||||||
|
Object.assign(g, { r, was });
|
||||||
|
} else {
|
||||||
|
const cols = [...el.querySelectorAll<HTMLElement>(":scope > .col")];
|
||||||
|
Object.assign(g, { cols, start: cols.map((c) => c.offsetWidth), widths: new Map(widths.sizes) });
|
||||||
|
wrap.classList.add("resizing");
|
||||||
|
}
|
||||||
|
return (g.on = true);
|
||||||
|
};
|
||||||
|
/** The columns' widths as the edge between column i - 1 and column i, moved by dx, leaves them (whole pixels); only those that changed, or were set by hand already, are kept. */
|
||||||
|
const widen = (g: Edging, dx: number) => {
|
||||||
|
const now = release(g.start!, g.at.i, dx, COL_MIN, 0);
|
||||||
|
g.cols!.forEach((c, k) => {
|
||||||
|
const n = Number(c.dataset.col);
|
||||||
|
if (now[k] !== g.start![k] || widths.sizes.has(n)) widths.sizes.set(n, now[k]);
|
||||||
|
});
|
||||||
|
relayout();
|
||||||
|
};
|
||||||
|
const onEdgeMove = (e: PointerEvent) => {
|
||||||
|
const g = edging;
|
||||||
|
if (!g || g.dead) return;
|
||||||
|
const d = g.at.axis === "row" ? e.clientY - g.y : e.clientX - g.x;
|
||||||
|
if (!g.on && (Math.abs(d) < 2 || !startEdge(g))) return;
|
||||||
|
g.d = d;
|
||||||
|
if (g.r) (moveResize(g.r, d), schedule());
|
||||||
|
else widen(g, d);
|
||||||
|
};
|
||||||
|
/** The edge let go (keep) or put back where the drag began (Esc, a cancelled pointer). */
|
||||||
|
const endEdge = (g: Edging, keep: boolean) => {
|
||||||
|
wrap.classList.remove("resizing");
|
||||||
|
if (keep && g.r) return void (endResize(g.r), schedule());
|
||||||
|
if (keep) return widen(g, g.d);
|
||||||
|
if (!g.r) widths.sizes = g.widths!;
|
||||||
|
else {
|
||||||
|
const col = Number(g.r.col.dataset.col);
|
||||||
|
g.was ? handsBy.panes.set(col, g.was) : handsBy.panes.delete(col);
|
||||||
|
}
|
||||||
|
relayout();
|
||||||
|
};
|
||||||
|
const onEdgeUp = (e: PointerEvent) => {
|
||||||
|
const g = edging;
|
||||||
|
if (!g) return;
|
||||||
|
edging = null;
|
||||||
|
// The click this press ends with is not a click on a pane.
|
||||||
|
swallow = true;
|
||||||
|
setTimeout(() => (swallow = false), 0);
|
||||||
|
if (g.on && !g.dead) endEdge(g, e.type === "pointerup");
|
||||||
|
};
|
||||||
|
// A double click on an edge: its column (or, across, the strip) laid out automatically again. (The pointer was held by the strip, so what is under it is asked for.)
|
||||||
|
const onEdgeDouble = (e: MouseEvent) => {
|
||||||
|
const at = edgeAt(e.clientX, e.clientY, document.elementFromPoint(e.clientX, e.clientY));
|
||||||
|
if (!at) return;
|
||||||
|
e.preventDefault();
|
||||||
|
if (at.axis === "row") unsize(at.col);
|
||||||
|
else if (widths.sizes.size) (widths.sizes.clear(), relayout());
|
||||||
|
};
|
||||||
const onKey = (e: KeyboardEvent) => {
|
const onKey = (e: KeyboardEvent) => {
|
||||||
if (drag?.on && e.key === "Escape") {
|
const g = edging?.on && !edging.dead ? edging : null;
|
||||||
|
if (e.key !== "Escape" || !(drag?.on || g)) return;
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
end(false);
|
if (drag?.on) end(false);
|
||||||
|
else if (g) {
|
||||||
|
endEdge(g, false);
|
||||||
|
g.dead = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// The click that ends a drag is not a click on the pane.
|
// The click that ends a drag is not a click on the pane.
|
||||||
@@ -1247,6 +1454,15 @@ export function Panes() {
|
|||||||
// 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);
|
||||||
|
// The edges first: a press on one is not a grip's, and the peek goes from under it.
|
||||||
|
el.addEventListener("pointermove", onEdgeHover, { signal });
|
||||||
|
el.addEventListener("pointermove", onMove, { signal });
|
||||||
|
el.addEventListener("pointerleave", () => !edging && showEdge(null), { signal });
|
||||||
|
el.addEventListener("pointerdown", onEdgeDown, { signal });
|
||||||
|
el.addEventListener("pointermove", onEdgeMove, { signal });
|
||||||
|
el.addEventListener("pointerup", onEdgeUp, { signal });
|
||||||
|
el.addEventListener("pointercancel", onEdgeUp, { signal });
|
||||||
|
el.addEventListener("dblclick", onEdgeDouble, { signal });
|
||||||
el.addEventListener("pointerdown", onDown, { signal });
|
el.addEventListener("pointerdown", onDown, { signal });
|
||||||
el.addEventListener("pointerdown", onPress, { signal });
|
el.addEventListener("pointerdown", onPress, { signal });
|
||||||
el.addEventListener("click", afterClick, { signal });
|
el.addEventListener("click", afterClick, { signal });
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ export const HELP: [string, [string, string][]][] = [
|
|||||||
["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)"],
|
["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. The edge between two panes, or two columns, dragged by the mouse resizes them (Esc puts it back, a double click lays them out again); only a pinned pane's size, and the width of its column, stay once another pane is the active one. A faint curve runs from where each pane was opened to its title"],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|||||||
+27
-4
@@ -60,9 +60,9 @@ export function fill(h: number, needs: number[]): number[] {
|
|||||||
/**
|
/**
|
||||||
* Whether a column of height h stacks its panes (each folding to a tab but the one looked at)
|
* 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`
|
* 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
|
* each, or less where a pane needs less); and, given `here`, the pane looked at (as pages, the
|
||||||
* phone), also whenever sharing would leave that pane shorter than what it needs, so it gets the
|
* page's; side by side, the active pane), also whenever sharing would leave that pane shorter than
|
||||||
* column's height and the others fold.
|
* 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 {
|
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;
|
if (needs.reduce((s, x) => s + Math.min(x, least), 0) > h) return true;
|
||||||
@@ -85,7 +85,8 @@ const fromEdges = (e: number[]) => e.slice(1).map((x, k) => Math.round(x) - Math
|
|||||||
* pushed up as a tab, and so on; moved down, the dragged pane gives, then the ones below it. The
|
* pushed up as a tab, and so on; moved down, the dragged pane gives, then the ones below it. The
|
||||||
* pane on the other side of the edge takes what is given (a tab there opens). Always from the sizes
|
* pane on the other side of the edge takes what is given (a tab there opens). Always from the sizes
|
||||||
* the drag began with, so moving back gives back what was pushed. The first pane's top is the
|
* the drag began with, so moving back gives back what was pushed. The first pane's top is the
|
||||||
* column's: it has no edge to move.
|
* column's: it has no edge to move. As panes side by side the same, by the mouse, down a column and
|
||||||
|
* across the strip (the columns' widths, where `min` is a column's least width).
|
||||||
*/
|
*/
|
||||||
export function resize(start: number[], i: number, dy: number, min: number): number[] {
|
export function resize(start: number[], i: number, dy: number, min: number): number[] {
|
||||||
const n = start.length;
|
const n = start.length;
|
||||||
@@ -132,6 +133,28 @@ export function fit(sizes: number[], h: number, min: number): number[] | null {
|
|||||||
return fromEdges([...starts(out), h]);
|
return fromEdges([...starts(out), h]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As panes side by side, a column some of whose panes keep their sizes by hand (`fixed`, the rest
|
||||||
|
* undefined): the others share what is left of its height h as the layout shares a column (`fill`,
|
||||||
|
* from what each needs); null if what is left cannot hold `min` for each of them. Given `here`, the
|
||||||
|
* active pane, when it is one of them and its share would cut it short (as `crowds`), it has what
|
||||||
|
* it needs, up to what leaves the others `min` each, and they share the rest.
|
||||||
|
*/
|
||||||
|
export function share(fixed: (number | undefined)[], needs: number[], h: number, min: number, here?: number): number[] | null {
|
||||||
|
const free = fixed.flatMap((x, i) => (x === undefined ? [i] : []));
|
||||||
|
const room = h - sum(fixed.map((x) => x ?? 0));
|
||||||
|
if (room < free.length * min) return null;
|
||||||
|
const want = free.map((i) => Math.max(min, needs[i]));
|
||||||
|
let got = fill(room, want);
|
||||||
|
const j = here === undefined ? -1 : free.indexOf(here);
|
||||||
|
if (j >= 0 && free.length > 1 && got[j] < want[j] - 1) {
|
||||||
|
const mine = Math.floor(Math.min(want[j], room - (free.length - 1) * min));
|
||||||
|
const rest = fill(room - mine, want.filter((_, k) => k !== j));
|
||||||
|
got = [...rest.slice(0, j), mine, ...rest.slice(j)];
|
||||||
|
}
|
||||||
|
return fixed.map((x, i) => x ?? got[free.indexOf(i)]);
|
||||||
|
}
|
||||||
|
|
||||||
/** Whether a pane of this height, sized by hand, is folded to its tab. */
|
/** Whether a pane of this height, sized by hand, is folded to its tab. */
|
||||||
export const folded = (size: number, min: number) => size <= min + 1;
|
export const folded = (size: number, min: number) => size <= min + 1;
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -453,6 +453,14 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
|||||||
.col:not(.split) .grip, .col.crowded > .pane[data-tab] > .grip, .col.sized > .pane[data-tab] > .grip { display: none; }
|
.col:not(.split) .grip, .col.crowded > .pane[data-tab] > .grip, .col.sized > .pane[data-tab] > .grip { display: none; }
|
||||||
.tabline { touch-action: none; }
|
.tabline { touch-action: none; }
|
||||||
.panes.dragging, .panes.dragging * { cursor: grabbing !important; user-select: none; }
|
.panes.dragging, .panes.dragging * { cursor: grabbing !important; user-select: none; }
|
||||||
|
/*
|
||||||
|
* The mouse near an edge between two panes of a column, or two columns side by side (Panes.tsx
|
||||||
|
* edgeAt): the cursor says which way the edge drags, and a press there selects no text. A column
|
||||||
|
* sized by hand lays its panes one under another, filling it, nothing stacked.
|
||||||
|
*/
|
||||||
|
.panes[data-edge="row"], .panes[data-edge="row"] * { cursor: row-resize !important; user-select: none; -webkit-user-select: none; }
|
||||||
|
.panes[data-edge="col"], .panes[data-edge="col"] * { cursor: col-resize !important; user-select: none; -webkit-user-select: none; }
|
||||||
|
.col.sized { overflow-y: hidden; }
|
||||||
.drop-line { position: absolute; z-index: 7; height: 2px; background: var(--link); pointer-events: none; }
|
.drop-line { position: absolute; z-index: 7; height: 2px; background: var(--link); pointer-events: none; }
|
||||||
|
|
||||||
/* A pane's pin and ×, top right, in the margin above its title: quiet until pointed at. A pinned pane's pin is filled. */
|
/* A pane's pin and ×, top right, in the margin above its title: quiet until pointed at. A pinned pane's pin is filled. */
|
||||||
@@ -975,10 +983,9 @@ html { scroll-padding-top: 48px; }
|
|||||||
* Moved up or down at once, the handle of any pane but a page's first drags the pane's top edge
|
* Moved up or down at once, the handle of any pane but a page's first drags the pane's top edge
|
||||||
* (Panes.tsx): so the browser may only pan it sideways, a swipe that turns the page. A page too
|
* (Panes.tsx): so the browser may only pan it sideways, a swipe that turns the page. A page too
|
||||||
* short for a tab for each of its panes (tight) is never sized so: its handles scroll it, as before.
|
* short for a tab for each of its panes (tight) is never sized so: its handles scroll it, as before.
|
||||||
* A page sized by hand lays its panes one under another, filling it, nothing stacked.
|
* A page sized by hand lays its panes one under another, filling it, nothing stacked (.col.sized, above).
|
||||||
*/
|
*/
|
||||||
.panes[data-layout="pages"] .col.split:not(.tight) > .pane:not(:first-child) > :is(.grip, .tabline) { touch-action: pan-x; }
|
.panes[data-layout="pages"] .col.split:not(.tight) > .pane:not(:first-child) > :is(.grip, .tabline) { touch-action: pan-x; }
|
||||||
.panes[data-layout="pages"] .col.sized { overflow-y: hidden; }
|
|
||||||
.panes.resizing, .panes.resizing * { user-select: none; -webkit-user-select: none; }
|
.panes.resizing, .panes.resizing * { user-select: none; -webkit-user-select: none; }
|
||||||
/* Lifted: the pane fades where it is; its tab rides just above the finger; a line shows where it will go. */
|
/* 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; }
|
.pane[data-lifted] { opacity: 0.4; }
|
||||||
|
|||||||
+46
-4
@@ -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, crowds, fill, fit, folded, offsets, release, resize, reveal, starts, whole } from "../src/ui/stack";
|
import { coverage, crowds, fill, fit, folded, offsets, release, resize, reveal, share, 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", () => {
|
||||||
@@ -42,12 +42,15 @@ describe("stack", () => {
|
|||||||
expect(fill(700, [300, 2000, 300])).toEqual([233, 234, 233]);
|
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", () => {
|
it("a column stacks when its panes do not fit at their least; also whenever a share would cut the pane looked at (the active pane; as pages, the page's) short", () => {
|
||||||
// Wide screen: shared while they fit at their least, whoever is looked at.
|
// No pane looked at (side by side, a column without the active pane): shared while they fit at their least.
|
||||||
expect(crowds(850, [1000, 1000], 260)).toBe(false);
|
expect(crowds(850, [1000, 1000], 260)).toBe(false);
|
||||||
expect(crowds(850, [1000, 1000, 1000], 260)).toBe(false);
|
expect(crowds(850, [1000, 1000, 1000], 260)).toBe(false);
|
||||||
expect(crowds(850, [1000, 1000, 1000, 1000], 260)).toBe(true);
|
expect(crowds(850, [1000, 1000, 1000, 1000], 260)).toBe(true);
|
||||||
// As pages: the long pane looked at gets the height.
|
// A tall column of five that all fit at their least, the short active one (a definition and its card) cut short by an equal share: it stacks.
|
||||||
|
expect(crowds(1360, [400, 300, 300, 300, 240], 260)).toBe(false);
|
||||||
|
expect(crowds(1360, [400, 300, 300, 300, 240], 260, 0)).toBe(true);
|
||||||
|
// The long pane looked at gets the height.
|
||||||
expect(crowds(720, [1000, 1000], 260, 0)).toBe(true);
|
expect(crowds(720, [1000, 1000], 260, 0)).toBe(true);
|
||||||
expect(crowds(720, [1000, 1000], 260, 1)).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.
|
// A short pane looked at, shown whole by the share, leaves the long one beside it.
|
||||||
@@ -115,4 +118,43 @@ describe("stack", () => {
|
|||||||
// Too short for a tab each: none.
|
// Too short for a tab each: none.
|
||||||
expect(fit([44, 44, 44], 120, T)).toBeNull();
|
expect(fit([44, 44, 44], 120, T)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("side by side, an edge between two columns dragged by the mouse moves their widths as the splitter does: the column after gives, one at the least pushed along, nothing folds", () => {
|
||||||
|
const W = 240;
|
||||||
|
expect(release([606, 606, 606], 1, 100, W, 0)).toEqual([706, 506, 606]);
|
||||||
|
expect(release([606, 606, 606], 1, -100.4, W, 0)).toEqual([506, 706, 606]);
|
||||||
|
// Past the next column's least: it is pushed along, the one after it gives.
|
||||||
|
expect(release([606, 606, 606], 1, 600, W, 0)).toEqual([1206, 240, 372]);
|
||||||
|
// Never past the least, either way.
|
||||||
|
expect(release([606, 606, 606], 2, -2000, W, 0)).toEqual([240, 240, 1338]);
|
||||||
|
// Close to the least, nothing folds: where the mouse left it.
|
||||||
|
expect(release([606, 606], 1, 350, W, 0)).toEqual([956, 256]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("side by side, a column whose pinned panes keep their sizes by hand: the others share what is left as the layout shares a column", () => {
|
||||||
|
const T = 30;
|
||||||
|
// The pinned first pane keeps 300 of 900; the other two share 600 by what they need.
|
||||||
|
expect(share([300, undefined, undefined], [500, 100, 2000], 900, T)).toEqual([300, 100, 500]);
|
||||||
|
// A short pane takes only what it needs; the rest goes to the one that needs most.
|
||||||
|
expect(share([undefined, 400], [120, 3000], 900, T)).toEqual([500, 400]);
|
||||||
|
// What a pane needs is never taken as less than a tab.
|
||||||
|
expect(share([300, undefined, undefined], [500, 5, 2000], 900, T)).toEqual([300, 30, 570]);
|
||||||
|
// The sizes fill the column exactly.
|
||||||
|
const s = share([123, undefined, 77, undefined], [400, 900, 50, 333], 1001, T)!;
|
||||||
|
expect(s.reduce((a, b) => a + b, 0)).toBe(1001);
|
||||||
|
// No room for a tab each of the others: none.
|
||||||
|
expect(share([880, undefined], [500, 500], 900, T)).toBeNull();
|
||||||
|
// The active pane among the others, cut short by its share, has what it needs; the rest share what it leaves.
|
||||||
|
expect(share([300, undefined, undefined], [500, 400, 2000], 900, T)).toEqual([300, 300, 300]);
|
||||||
|
expect(share([300, undefined, undefined], [500, 400, 2000], 900, T, 1)).toEqual([300, 400, 200]);
|
||||||
|
// Needing more than there is, it has all but a tab for each of the others.
|
||||||
|
expect(share([300, undefined, undefined], [500, 3000, 2000], 900, T, 1)).toEqual([300, 570, 30]);
|
||||||
|
// Whole by its share already, or pinned (kept by hand), or alone: as without it.
|
||||||
|
expect(share([300, undefined, undefined], [500, 100, 2000], 900, T, 1)).toEqual([300, 100, 500]);
|
||||||
|
expect(share([300, undefined, undefined], [500, 400, 2000], 900, T, 0)).toEqual([300, 300, 300]);
|
||||||
|
expect(share([300, undefined], [500, 3000], 900, T, 1)).toEqual([300, 600]);
|
||||||
|
const a = share([123, undefined, 77, undefined, undefined], [400, 900, 50, 333, 700], 1001, T, 4)!;
|
||||||
|
expect(a[4]).toBe(700);
|
||||||
|
expect(a.reduce((x, y) => x + y, 0)).toBe(1001);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user