Panes open beside by default; columns stack as the strip does; peek and drag
Enter, l and a click (a Ctrl-, Cmd- or middle click too) open into the next column beside what is there; Shift+Enter and a Shift-click open in place of the focused branch's pane there. Opening what is open focuses it; a second Enter on an open row keeps it. A document from the menu or /open still opens in place. A crowded column now stacks its panes the way the strip stacks columns, by the same code (stack.ts): each pane stuck a tab below the one before, the one looked at whole, the others slid under it, partly and at the limit down to a tab, a pinned one never covered. What is covered down to its strip is not painted. The mouse resting on a covered pane, tab or spine peeks it out over its neighbours; a click makes it the active pane. A pane's grip, the band above its title, or its tab drags it up or down its column (Esc cancels). Curves from words start at the end of their underline. Curves keep their elements and are drawn on a layer of their own, so a change repaints only what moved; with many curves in a gutter, lanes are ordered by swapping neighbours. 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
7a2df56440
commit
3789255147
13 files changed
+783
-254
No files matched your search
+4
-9
@@ -507,8 +507,8 @@ export function App() {
|
||||
if (!store.ready) return <div class="loading">Loading…</div>;
|
||||
|
||||
const panes = store.panes;
|
||||
// Shift-, Ctrl- or Cmd-click (and a middle click) opens a fork: beside what is open, not instead of it.
|
||||
const onClick = (e: MouseEvent) => store.withFork(e.shiftKey || e.ctrlKey || e.metaKey || e.button === 1, () => click(e));
|
||||
// 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 click = (e: MouseEvent) => {
|
||||
if (store.mode === "edit") return;
|
||||
const target = e.target as HTMLElement;
|
||||
@@ -588,7 +588,7 @@ export function App() {
|
||||
return;
|
||||
}
|
||||
// A drag selection inside one body becomes the focus range.
|
||||
if (selection && !selection.isCollapsed && !store.forking) {
|
||||
if (selection && !selection.isCollapsed && !store.replacing) {
|
||||
const a = locate(selection.anchorNode, selection.anchorOffset);
|
||||
const b = locate(selection.focusNode, selection.focusOffset);
|
||||
if (a && b && a.id === b.id && a.at !== b.at) {
|
||||
@@ -626,12 +626,7 @@ export function App() {
|
||||
if (row) {
|
||||
const id = row.dataset.row as NodeId;
|
||||
if (panes && id !== store.top) {
|
||||
// In panes a click shows the row's pane: focus it and open it next. On the focused row whose pane is showing, it closes that pane.
|
||||
const next = store.trail[paneIndex + 1];
|
||||
if (!store.forking && store.focus.node === id && store.focus.grain === "node" && next?.kind === "node" && next.id === id) {
|
||||
store.closeRow(paneIndex, id);
|
||||
return;
|
||||
}
|
||||
// In panes a click shows the row's pane: focus it and open it next (or focus it where it is open).
|
||||
store.paneAt = paneIndex;
|
||||
store.go(id);
|
||||
store.open.add(id);
|
||||
|
||||
+3
-3
@@ -117,7 +117,7 @@ export function DocsPanel() {
|
||||
e.preventDefault();
|
||||
// The selection as it is now: the filter may have changed since this was drawn.
|
||||
const now = store.menuSelected();
|
||||
if (now) store.openDoc(now.node);
|
||||
if (now) store.openDoc(now.node, true);
|
||||
} else if (k === "Escape" || k === "Tab") {
|
||||
e.preventDefault();
|
||||
m.focus = "list";
|
||||
@@ -161,7 +161,7 @@ export function DocsPanel() {
|
||||
(document.activeElement as HTMLElement | null)?.blur();
|
||||
store.emit();
|
||||
}}
|
||||
onDblClick={() => store.openDoc(d.node)}
|
||||
onDblClick={() => store.openDoc(d.node, true)}
|
||||
>
|
||||
<div class="line">
|
||||
<span class="title">{d.title || "Untitled"}</span>
|
||||
@@ -170,7 +170,7 @@ export function DocsPanel() {
|
||||
<div class="sub">{d.excerpt || "No text yet."}</div>
|
||||
{selected && (
|
||||
<div class="actions">
|
||||
{d.node !== current && <button onClick={act(() => store.openDoc(d.node))}>open</button>}
|
||||
{d.node !== current && <button onClick={act(() => store.openDoc(d.node, true))}>open</button>}
|
||||
<button onClick={act(() => store.menuPrompt("rename"))}>rename</button>
|
||||
<button onClick={act(() => store.menuPrompt("duplicate"))}>save as</button>
|
||||
<button onClick={act(() => store.exportDocument(d.node))}>export .md</button>
|
||||
|
||||
+284
-107
@@ -18,11 +18,11 @@
|
||||
import { Component, type ComponentChildren } from "preact";
|
||||
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
||||
import { docOf, label, sections, staleness, type NodeId } from "../core/model";
|
||||
import type { Placed } from "./forks";
|
||||
import { LANES, LANE_FIRST, LANE_LAST, LANE_PITCH, laneOrder } from "./lanes";
|
||||
import { ACROSS, DOWN, mark, offsets, reveal, starts, stick, unmark, whole } from "./stack";
|
||||
import { NodeBacklinks, NodeRelated, PaneCtx, TargetRow } from "./Links";
|
||||
import { Flags, NodeBody, PendingSections, Row, TitleEditor, TopMatter } from "./Node";
|
||||
import { kidClass, refKey, store, type Aux, type Back, type Pane as PaneNode, type PaneRef } from "./store";
|
||||
import { kidClass, refKey, store, type Aux, type Pane as PaneNode, type PaneRef } from "./store";
|
||||
import { WikiView } from "./Wiki";
|
||||
import { article } from "./wiki";
|
||||
|
||||
@@ -93,6 +93,7 @@ function Chrome({ props, title, mark }: { props: PaneProps; title: string; mark?
|
||||
{title}
|
||||
</span>
|
||||
</div>
|
||||
<div class="grip" data-grip={tid} title="Drag to move this pane up or down its column" />
|
||||
<div class="tabline" data-spine={props.index} title={title}>
|
||||
{mark}
|
||||
<span class="tabtitle">{title}</span>
|
||||
@@ -226,10 +227,12 @@ const setAttr = (el: Element | undefined, name: string, on: boolean) => {
|
||||
if (el && el.hasAttribute(name) !== on) on ? el.setAttribute(name, "") : el.removeAttribute(name);
|
||||
};
|
||||
|
||||
/** The least height a pane keeps in a column while all its panes fit; below it, the column folds all but one into tabs. */
|
||||
/** The least height a pane keeps in a column while all its panes fit; below it, the column stacks them. */
|
||||
export const PANE_MIN = 260;
|
||||
/** A folded pane's tab. */
|
||||
/** A covered pane's tab, the strip a pane leaves down a crowded column (as a spine does across). */
|
||||
export const TAB = 30;
|
||||
/** How long the mouse rests on a covered pane before it peeks out. */
|
||||
export const PEEK_MS = 200;
|
||||
|
||||
/**
|
||||
* Heights for the panes of one column of height h, from what each needs to show all it holds:
|
||||
@@ -257,22 +260,22 @@ const paneEls = (el: HTMLElement) => {
|
||||
|
||||
const kidsKey = (t: PaneNode) => `${t.pick}:${t.kids.map((k) => refKey(k.ref)).join(",")}`;
|
||||
|
||||
type Spot = Placed<PaneRef, Back>;
|
||||
|
||||
export function Panes() {
|
||||
store.syncTrail();
|
||||
const strip = useRef<HTMLDivElement>(null);
|
||||
const svg = useRef<SVGSVGElement>(null);
|
||||
const followed = useRef("");
|
||||
/** Per column, the pane last on the focused branch there: the one a folded column keeps open when the branch is elsewhere. */
|
||||
/** Per column, the pane last on the focused branch there: the one a crowded column shows whole when the branch is elsewhere. */
|
||||
const lastIn = useRef(new Map<number, number>());
|
||||
/** What each pane last needed to show all it holds (a folded pane cannot be measured). */
|
||||
const needs = useRef(new Map<number, number>());
|
||||
/** Each column's sticky left edge, in px, as last set. */
|
||||
const lefts = useRef<number[]>([]);
|
||||
const frame = useRef(0);
|
||||
/** A pending layout of the columns other than the active pane's. */
|
||||
/** A pending reveal in the columns other than the active pane's. */
|
||||
const later = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
/** What each pane last needed to show all it holds. */
|
||||
const needs = useRef(new Map<number, number>());
|
||||
/** The pane each crowded column was last scrolled to show whole. */
|
||||
const shown = useRef(new Map<HTMLElement, number>());
|
||||
/** Each column's panes when last laid out. */
|
||||
const laid = useRef(new Map<HTMLElement, string>());
|
||||
/** The layout of the latest render (a pending one uses it). */
|
||||
@@ -280,21 +283,18 @@ export function Panes() {
|
||||
/** The active pane's column when the strip last followed it. */
|
||||
const lastCol = useRef(-1);
|
||||
|
||||
const placed = store.panesPlaced;
|
||||
const branch = store.branchNodes;
|
||||
const onBranch = new Set(branch.map((n) => n.id));
|
||||
const activeId = branch[store.paneAt]?.id;
|
||||
const cols = new Map<number, Spot[]>();
|
||||
for (const x of placed) {
|
||||
const c = cols.get(x.col);
|
||||
if (c) c.push(x);
|
||||
else cols.set(x.col, [x]);
|
||||
}
|
||||
const cols = store.paneColumns;
|
||||
const order = [...cols.keys()].sort((a, b) => a - b);
|
||||
|
||||
/**
|
||||
* Lay out the columns: each column's sticky left edge (every column before it leaves a spine, or
|
||||
* the whole of a pinned pane's column), and the heights of the panes in each column with several.
|
||||
* 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
|
||||
* them, a pane taking what its text needs; when they do not all fit, it becomes a stack of its
|
||||
* own, each 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 el = strip.current;
|
||||
@@ -305,103 +305,101 @@ export function Panes() {
|
||||
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 view = el.clientWidth;
|
||||
const n = colEls.length;
|
||||
// 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);
|
||||
let left = 0;
|
||||
lefts.current = colEls.map((c, i) => {
|
||||
// Far enough left that the columns after it can still all be scrolled to.
|
||||
const l = Math.round(Math.min(left, Math.max(i * spine, view - w - (n - 1 - i) * spine)));
|
||||
if (c.style.left !== `${l}px`) c.style.left = `${l}px`;
|
||||
left += c.hasAttribute("data-pinned") ? w : spine;
|
||||
return l;
|
||||
});
|
||||
lefts.current = offsets(
|
||||
colEls.map(() => w),
|
||||
colEls.map((c) => c.hasAttribute("data-pinned")),
|
||||
spine,
|
||||
el.clientWidth,
|
||||
);
|
||||
stick(colEls, lefts.current, ACROSS);
|
||||
let deferred = false;
|
||||
for (const c of colEls) {
|
||||
const ps = [...c.children] as HTMLElement[];
|
||||
const ps = [...c.children].filter((p): p is HTMLElement => p.classList.contains("pane"));
|
||||
if (ps.length < 2) {
|
||||
for (const p of ps) {
|
||||
setAttr(p, "data-tab", false);
|
||||
if (p.style.height) (p.style.height = ""), (p.style.flex = "");
|
||||
}
|
||||
for (const p of ps) if (p.style.height) (p.style.height = ""), (p.style.flex = ""), (p.style.top = "");
|
||||
c.classList.remove("crowded");
|
||||
unmark(ps);
|
||||
continue;
|
||||
}
|
||||
const h = c.clientHeight;
|
||||
const col = Number(c.dataset.col);
|
||||
const pad = (() => {
|
||||
const s = ps.find((p) => !p.hasAttribute("data-tab"))?.querySelector<HTMLElement>(".pane-scroll");
|
||||
if (!s) return 60;
|
||||
const cs = getComputedStyle(s);
|
||||
return parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom) + 1;
|
||||
})();
|
||||
const sc = ps[0].querySelector<HTMLElement>(".pane-scroll")!;
|
||||
const cs = getComputedStyle(sc);
|
||||
const pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom) + 1;
|
||||
const tids = ps.map((p) => Number(p.dataset.tid));
|
||||
// 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) => {
|
||||
const body = p.hasAttribute("data-tab") ? null : p.querySelector<HTMLElement>(".pane-body");
|
||||
if (body) needs.current.set(tids[i], body.offsetHeight + pad);
|
||||
return needs.current.get(tids[i]) ?? PANE_MIN;
|
||||
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 fits = need.reduce((s, x) => s + Math.min(x, PANE_MIN), 0) <= h;
|
||||
const crowded = need.reduce((s, x) => s + Math.min(x, PANE_MIN), 0) > h;
|
||||
let heights: number[];
|
||||
let tab: boolean[];
|
||||
if (fits) {
|
||||
tab = ps.map(() => false);
|
||||
heights = fill(h, need);
|
||||
} else {
|
||||
// Too many to share the height: the pane on the focused branch (or the one last on it here) keeps it, pinned panes keep their least, the rest fold.
|
||||
const here = tids.find((t) => onBranch.has(t));
|
||||
const keep = here ?? (tids.includes(lastIn.current.get(col)!) ? lastIn.current.get(col)! : tids[0]);
|
||||
tab = tids.map((t, i) => t !== keep && !pinned[i]);
|
||||
const folded = tab.filter(Boolean).length;
|
||||
const kept = tids.map((t, i) => (!tab[i] && t !== keep ? Math.min(need[i], PANE_MIN) : 0));
|
||||
const rest = h - folded * TAB - kept.reduce((s, x) => s + x, 0);
|
||||
heights = tids.map((t, i) => (tab[i] ? TAB : t === keep ? Math.max(PANE_MIN, rest) : kept[i]));
|
||||
let tops: number[] = [];
|
||||
if (!crowded) heights = fill(h, need);
|
||||
else {
|
||||
// Each pane what its text needs, up to the column less a tab for each other pane; a pinned one, at most a third of it, but its least.
|
||||
const pin = need.map((x, i) => (pinned[i] ? Math.min(x, Math.max(PANE_MIN, Math.floor(h / 3))) : 0));
|
||||
const free = h - pin.reduce((s, x) => s + x, 0) - (pinned.filter((x) => !x).length - 1) * TAB;
|
||||
heights = need.map((x, i) => (pinned[i] ? pin[i] : Math.min(x, Math.max(PANE_MIN, free))));
|
||||
tops = offsets(heights, pinned, TAB, h);
|
||||
}
|
||||
// Folding and unfolding repaints whole panes: as the focus moves, in the active pane's column at once, in the others once the keys pause.
|
||||
c.classList.toggle("crowded", crowded);
|
||||
ps.forEach((p, i) => {
|
||||
if (p.style.height !== `${heights[i]}px`) (p.style.height = `${heights[i]}px`), (p.style.flex = "none");
|
||||
});
|
||||
if (crowded) stick(ps, tops, DOWN);
|
||||
else for (const p of ps) p.style.top = "";
|
||||
// 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 want = crowded ? reveal(c.scrollTop, h, 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.
|
||||
const sig = tids.map((t, i) => `${t}${pinned[i] ? "^" : ""}`).join();
|
||||
const same = laid.current.get(c) === sig;
|
||||
laid.current.set(c, sig);
|
||||
if (!all && same && c !== activeCol && ps.some((p, i) => p.hasAttribute("data-tab") !== tab[i])) {
|
||||
later.current = setTimeout(() => {
|
||||
latest.current(true);
|
||||
schedule();
|
||||
}, 150);
|
||||
continue;
|
||||
const moved = shown.current.get(c) !== here;
|
||||
if (Math.abs(c.scrollTop - want) > 1 && !all && same && moved && c !== activeCol) deferred = true;
|
||||
else {
|
||||
if (Math.abs(c.scrollTop - want) > 1) c.scrollTop = want;
|
||||
shown.current.set(c, here);
|
||||
}
|
||||
ps.forEach((p, i) => {
|
||||
setAttr(p, "data-tab", tab[i]);
|
||||
if (p.style.height !== `${heights[i]}px`) (p.style.height = `${heights[i]}px`), (p.style.flex = "none");
|
||||
});
|
||||
}
|
||||
if (deferred)
|
||||
later.current = setTimeout(() => {
|
||||
latest.current(true);
|
||||
measure();
|
||||
schedule();
|
||||
}, 150);
|
||||
// The focused branch's panes, marked without redrawing them.
|
||||
for (const [id, p] of paneEls(el)) p.classList.toggle("on-branch", onBranch.has(id));
|
||||
for (const x of placed) if (onBranch.has(x.node.id)) lastIn.current.set(x.col, x.node.id);
|
||||
for (const [col, ps] of cols) for (const x of ps) if (onBranch.has(x.node.id)) lastIn.current.set(col, x.node.id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark how far each column is covered by the next. Any overlap gives the column above a shadow
|
||||
* edge (data-over); once too little of it is left to read its own heading, its panes show as
|
||||
* spines with their titles (data-covered).
|
||||
* Mark how far each item is covered by the next, across the strip and down each crowded column
|
||||
* (stack.ts): an overlapped item gives the one over it a shadow edge (data-over); one with too
|
||||
* little left to read its heading shows its spine or tab (data-covered).
|
||||
*/
|
||||
const measure = () => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
const colEls = el.querySelectorAll<HTMLElement>(":scope > .col");
|
||||
if (!colEls.length) return;
|
||||
const w = colEls[0].offsetWidth;
|
||||
const xs = [...colEls].map((c) => c.getBoundingClientRect().left);
|
||||
colEls.forEach((c, i) => {
|
||||
const visible = i + 1 < xs.length ? xs[i + 1] - xs[i] : w;
|
||||
setAttr(c, "data-covered", visible < w * 0.4);
|
||||
setAttr(colEls[i + 1], "data-over", visible < w - 1);
|
||||
});
|
||||
const colEls = [...el.querySelectorAll<HTMLElement>(":scope > .col")];
|
||||
mark(el, colEls, ACROSS, false, colEls[0]?.querySelector<HTMLElement>(".spine")?.offsetWidth ?? 0);
|
||||
for (const c of colEls) if (c.classList.contains("crowded")) mark(c, [...c.querySelectorAll<HTMLElement>(":scope > .pane")], DOWN, true, TAB);
|
||||
};
|
||||
|
||||
/**
|
||||
* Keep the focus in view. Vertically, the pane holding the focus scrolls to its focused row,
|
||||
* selection or link. Horizontally, the strip scrolls as little as it can so that pane's column is
|
||||
* fully visible and, when there is room, so is the column beside it: for a row whose pane is
|
||||
* showing, that pane's; otherwise the one before.
|
||||
* whole and, when there is room, so is the column beside it: for a row whose pane is showing,
|
||||
* that pane's; otherwise the one before. Up and down a column it stays still while the pane looked
|
||||
* at is whole.
|
||||
*/
|
||||
const follow = () => {
|
||||
const el = strip.current;
|
||||
@@ -426,20 +424,18 @@ export function Panes() {
|
||||
const colOf = (p: HTMLElement | undefined) => (p ? colEls.indexOf(p.parentElement as HTMLElement) : -1);
|
||||
const w = colEls[0].offsetWidth;
|
||||
const view = el.clientWidth;
|
||||
const max = el.scrollWidth - view;
|
||||
const L = lefts.current;
|
||||
const b = colOf(panes[Math.min(panes.length - 1, showing ? at + 1 : at)]);
|
||||
if (b < 0) return;
|
||||
// Up and down a column (or within a pane) the strip stays still while the pane looked at is fully in view.
|
||||
const here = colOf(panes[at]);
|
||||
const was = lastCol.current;
|
||||
lastCol.current = here;
|
||||
if (here === was && el.scrollLeft >= (b + 1) * colEls[0].offsetWidth - el.clientWidth - 1 && el.scrollLeft <= b * colEls[0].offsetWidth - (lefts.current[b] ?? 0) + 1) return;
|
||||
let a = b > 0 && (showing || f.grain === "node") ? b - 1 : b;
|
||||
// Column i starts at i·w. It is uncovered while scrollLeft ≤ i·w − its sticky left, and its right edge is in view while scrollLeft ≥ (i+1)·w − view.
|
||||
const lo = (b + 1) * w - view;
|
||||
if (lo > a * w - (L[a] ?? 0)) a = b;
|
||||
const hi = a * w - (L[a] ?? 0);
|
||||
const target = Math.max(0, Math.min(el.scrollWidth - view, Math.min(Math.max(el.scrollLeft, lo), hi)));
|
||||
if (here === was && whole(el.scrollLeft, view, b * w, w, L[b] ?? 0)) return;
|
||||
// Column i starts at i·w: show b whole, and the one before it too when both fit.
|
||||
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 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);
|
||||
if (Math.abs(target - el.scrollLeft) > 1) el.scrollTo({ left: target, behavior: reducedMotion() ? "auto" : "smooth" });
|
||||
};
|
||||
|
||||
@@ -464,7 +460,10 @@ export function Panes() {
|
||||
const el = strip.current!;
|
||||
const wrap = el.parentElement!;
|
||||
const onScroll = (e: Event) => {
|
||||
if (e.target === el) measure();
|
||||
const t = e.target as HTMLElement;
|
||||
if (t === el || t.classList?.contains("col")) measure();
|
||||
// What peeks is placed for where things were: put it back (one waiting to peek still may).
|
||||
if (peeked) hide();
|
||||
schedule();
|
||||
};
|
||||
const onResize = () => {
|
||||
@@ -474,17 +473,168 @@ export function Panes() {
|
||||
measure();
|
||||
schedule();
|
||||
};
|
||||
// Panes scroll on their own: their scroll events are caught on the way down.
|
||||
// Panes and crowded columns scroll on their own: their scroll events are caught on the way down.
|
||||
wrap.addEventListener("scroll", onScroll, { passive: true, capture: true });
|
||||
// The strip changes size with the window and when the history panel opens or closes.
|
||||
const sizes = new ResizeObserver(onResize);
|
||||
sizes.observe(el);
|
||||
document.fonts?.ready.then(onResize);
|
||||
|
||||
/*
|
||||
* Peeking: a pane the stacks have covered, wholly or in part (its column across the strip, or
|
||||
* the pane down a crowded column), slides out over its neighbours while the mouse rests on it
|
||||
* (after PEEK_MS, so passing across does not flicker), raised and, if it runs past the column's
|
||||
* foot, lifted into view; nothing else moves. A click makes it the active pane, which uncovers
|
||||
* it for good. Not for touch, the keyboard, or while dragging.
|
||||
*/
|
||||
let peeked: HTMLElement | null = null;
|
||||
let pending: HTMLElement | null = null;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
function hide() {
|
||||
if (!peeked) return;
|
||||
peeked.removeAttribute("data-peek");
|
||||
peeked.style.transform = "";
|
||||
peeked = null;
|
||||
}
|
||||
function unpeek() {
|
||||
clearTimeout(timer);
|
||||
pending = null;
|
||||
hide();
|
||||
}
|
||||
const peekable = (pane: HTMLElement): HTMLElement | null => {
|
||||
const col = pane.parentElement as HTMLElement;
|
||||
if (col.hasAttribute("data-covered") || (col.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over")) return col;
|
||||
if (!col.classList.contains("crowded")) return null;
|
||||
const r = pane.getBoundingClientRect();
|
||||
const c = col.getBoundingClientRect();
|
||||
if (pane.hasAttribute("data-covered") || (pane.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over") || r.bottom > c.bottom + 1) return pane;
|
||||
return null;
|
||||
};
|
||||
const peek = (it: HTMLElement) => {
|
||||
peeked = it;
|
||||
it.setAttribute("data-peek", "");
|
||||
if (it.classList.contains("pane")) {
|
||||
const r = it.getBoundingClientRect();
|
||||
const c = (it.parentElement as HTMLElement).getBoundingClientRect();
|
||||
const dy = Math.max(c.top - r.top, Math.min(0, c.bottom - r.bottom));
|
||||
if (dy) it.style.transform = `translateY(${Math.round(dy)}px)`;
|
||||
}
|
||||
};
|
||||
const onMove = (e: PointerEvent) => {
|
||||
if (e.pointerType !== "mouse" || e.buttons || drag) return;
|
||||
const pane = (e.target as HTMLElement).closest<HTMLElement>(".pane");
|
||||
const it = pane && (pane === peeked || pane.parentElement === peeked ? peeked : peekable(pane));
|
||||
if (it === peeked && it) return;
|
||||
if (it === pending && it) return;
|
||||
unpeek();
|
||||
if (!it) return;
|
||||
pending = it;
|
||||
timer = setTimeout(() => {
|
||||
if (pending !== it) return;
|
||||
pending = null;
|
||||
const pane = it.classList.contains("pane") ? it : it.querySelector<HTMLElement>(".pane");
|
||||
if (pane && peekable(pane)) peek(it);
|
||||
}, PEEK_MS);
|
||||
};
|
||||
el.addEventListener("pointermove", onMove);
|
||||
el.addEventListener("pointerleave", unpeek);
|
||||
window.addEventListener("keydown", unpeek, true);
|
||||
|
||||
/*
|
||||
* 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
|
||||
* its own (forks.ts `reorder`), kept with the panes.
|
||||
*/
|
||||
let drag: { tid: number; col: HTMLElement; y0: number; on: boolean; before: number | null; line: HTMLElement | null } | null = null;
|
||||
let swallow = false;
|
||||
const onDown = (e: PointerEvent) => {
|
||||
if (e.button !== 0) return;
|
||||
const t = e.target as HTMLElement;
|
||||
if (t.closest("[data-close], [data-pin]")) 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.children.length < 2) return;
|
||||
drag = { tid: Number(pane.dataset.tid), col, y0: e.clientY, on: false, before: null, line: null };
|
||||
handle.setPointerCapture(e.pointerId);
|
||||
};
|
||||
const onDrag = (e: PointerEvent) => {
|
||||
if (!drag) return;
|
||||
if (!drag.on) {
|
||||
if (Math.abs(e.clientY - drag.y0) < 5) return;
|
||||
drag.on = true;
|
||||
unpeek();
|
||||
wrap.classList.add("dragging");
|
||||
drag.line = document.createElement("div");
|
||||
drag.line.className = "drop-line";
|
||||
wrap.appendChild(drag.line);
|
||||
}
|
||||
const others = [...drag.col.querySelectorAll<HTMLElement>(":scope > .pane")].filter((p) => Number(p.dataset.tid) !== drag!.tid);
|
||||
const c = drag.col.getBoundingClientRect();
|
||||
const tops = others.map((p) => Math.max(c.top, Math.min(c.bottom, p.getBoundingClientRect().top)));
|
||||
const ends = others.map((p, i) => Math.min(tops[i + 1] ?? c.bottom, Math.max(c.top, Math.min(c.bottom, p.getBoundingClientRect().bottom))));
|
||||
const i = others.findIndex((_, k) => e.clientY < (tops[k] + ends[k]) / 2);
|
||||
drag.before = i < 0 ? null : Number(others[i].dataset.tid);
|
||||
const y = i < 0 ? (ends[ends.length - 1] ?? c.top) : tops[i];
|
||||
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` });
|
||||
};
|
||||
const end = (keep: boolean) => {
|
||||
if (!drag) return;
|
||||
const d = drag;
|
||||
drag = null;
|
||||
d.line?.remove();
|
||||
wrap.classList.remove("dragging");
|
||||
if (d.on) {
|
||||
swallow = true;
|
||||
setTimeout(() => (swallow = false), 0);
|
||||
if (keep) store.reorderPane(d.tid, d.before);
|
||||
}
|
||||
};
|
||||
const onUp = () => end(true);
|
||||
const onCancel = () => end(false);
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (drag?.on && e.key === "Escape") {
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
end(false);
|
||||
}
|
||||
};
|
||||
// The click that ends a drag is not a click on the pane.
|
||||
const onClick = (e: MouseEvent) => {
|
||||
if (!swallow) return;
|
||||
swallow = false;
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
};
|
||||
// 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 && peeked.contains(e.target as Node)) && unpeek();
|
||||
const afterClick = () => peeked && requestAnimationFrame(unpeek);
|
||||
el.addEventListener("pointerdown", onDown);
|
||||
el.addEventListener("pointerdown", onPress);
|
||||
el.addEventListener("click", afterClick);
|
||||
el.addEventListener("pointermove", onDrag);
|
||||
el.addEventListener("pointerup", onUp);
|
||||
el.addEventListener("pointercancel", onCancel);
|
||||
window.addEventListener("keydown", onKey, true);
|
||||
window.addEventListener("click", onClick, true);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame.current);
|
||||
clearTimeout(later.current);
|
||||
clearTimeout(timer);
|
||||
wrap.removeEventListener("scroll", onScroll, { capture: true });
|
||||
sizes.disconnect();
|
||||
el.removeEventListener("pointermove", onMove);
|
||||
el.removeEventListener("pointerleave", unpeek);
|
||||
window.removeEventListener("keydown", unpeek, true);
|
||||
el.removeEventListener("pointerdown", onDown);
|
||||
el.removeEventListener("pointerdown", onPress);
|
||||
el.removeEventListener("click", afterClick);
|
||||
el.removeEventListener("pointermove", onDrag);
|
||||
el.removeEventListener("pointerup", onUp);
|
||||
el.removeEventListener("pointercancel", onCancel);
|
||||
window.removeEventListener("keydown", onKey, true);
|
||||
window.removeEventListener("click", onClick, true);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -549,12 +699,14 @@ function underline(s: HTMLElement, r: DOMRect): number {
|
||||
const cs = getComputedStyle(s);
|
||||
const fs = parseFloat(cs.fontSize) || 16;
|
||||
if (s.matches(".anchor")) return r.bottom - 0.08 * fs - 0.5;
|
||||
let d = descents.get(cs.font);
|
||||
const font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
|
||||
let d = descents.get(font);
|
||||
if (d === undefined) {
|
||||
measurer ??= document.createElement("canvas").getContext("2d");
|
||||
if (measurer) measurer.font = cs.font;
|
||||
d = measurer?.measureText("x").fontBoundingBoxDescent ?? 0.25 * fs;
|
||||
descents.set(cs.font, d);
|
||||
if (measurer) measurer.font = font;
|
||||
d = measurer?.measureText("x").fontBoundingBoxDescent ?? 0.3 * fs;
|
||||
// Kept once the face has arrived; measured before, it is the fallback's.
|
||||
if (document.fonts?.check(font) !== false) descents.set(font, d);
|
||||
}
|
||||
const off = parseFloat(cs.textUnderlineOffset);
|
||||
return r.bottom - d + (Number.isFinite(off) ? off : 0.1 * fs) + 0.5;
|
||||
@@ -596,28 +748,36 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
const pcol = pe?.parentElement;
|
||||
const ccol = ce?.parentElement;
|
||||
if (!pe || !ce || !pcol || !ccol || pcol.hasAttribute("data-covered") || ccol.hasAttribute("data-covered")) continue;
|
||||
const left = ccol.getBoundingClientRect().left;
|
||||
// Where it arrives: just before the child's title, or its tab's.
|
||||
const ccolBox = ccol.getBoundingClientRect();
|
||||
const left = ccolBox.left;
|
||||
// Where it arrives: just before the child's title, or its tab's; below a crowded column's foot, at the foot.
|
||||
const cbox = ce.getBoundingClientRect();
|
||||
let ey: number;
|
||||
if (ce.hasAttribute("data-tab")) ey = cbox.top + TAB / 2;
|
||||
let lost = false;
|
||||
if (ce.hasAttribute("data-covered")) ey = cbox.top + TAB / 2;
|
||||
else {
|
||||
const scroll = ce.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
const tr = ce.querySelector<HTMLElement>(".pane-head h2, .top h1, .wiki-head h2")?.getBoundingClientRect();
|
||||
ey = tr && tr.bottom > scroll.top + 4 ? Math.max(scroll.top + 6, tr.top + Math.min(tr.height, 32) / 2) : scroll.top + 14;
|
||||
}
|
||||
if (ey > ccolBox.bottom - 4) {
|
||||
ey = ccolBox.bottom - 4;
|
||||
lost = true;
|
||||
}
|
||||
// Where it starts: the words, row or link it was opened from. The text's edge: the pane's right padding, or the next column where it covers the pane.
|
||||
const pbox = pe.getBoundingClientRect();
|
||||
const textRight = Math.min(pbox.right - 33, left - 2);
|
||||
let sx = textRight;
|
||||
let sy: number;
|
||||
let under: { x: number; y: number } | undefined;
|
||||
let lost = false;
|
||||
if (pe.hasAttribute("data-tab")) {
|
||||
if (pe.hasAttribute("data-covered")) {
|
||||
sy = pbox.top + TAB / 2;
|
||||
lost = true;
|
||||
} else {
|
||||
const sc = pe.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
// What of the pane shows: its own scroll box, less what the pane after it in a crowded column covers, down to the column's foot.
|
||||
const box = pe.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
const nextTop = pcol.classList.contains("crowded") ? (pe.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top : undefined;
|
||||
const sc = { top: box.top, bottom: Math.min(box.bottom, nextTop ?? Infinity, pcol.getBoundingClientRect().bottom) };
|
||||
const cands = pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`);
|
||||
let src: HTMLElement | undefined;
|
||||
for (const c of cands) {
|
||||
@@ -671,7 +831,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
}
|
||||
for (const g of [...lanesUsed.keys()]) if (!gutters.has(g)) lanesUsed.delete(g);
|
||||
const fx = (n: number) => Math.round(n * 2) / 2;
|
||||
const out: string[] = [];
|
||||
const out: { key: string; from: number; to: number; lane: number; cls: string; d: string }[] = [];
|
||||
edges.sort((a, b) => Number(a.on) - Number(b.on));
|
||||
for (const e of edges) {
|
||||
const i = lane.get(e)!;
|
||||
@@ -694,8 +854,25 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
`C${fx(g)} ${fx(e.ey - sg * r2 * (1 - k))} ${fx(g + r2 - k * r2)} ${fx(e.ey)} ${fx(g + r2)} ${fx(e.ey)}` +
|
||||
`H${fx(e.ex)}`;
|
||||
}
|
||||
out.push(`<path data-from="${e.from}" data-to="${e.to}" data-lane="${i}" class="${e.on ? "on" : ""}${e.lost ? " lost" : ""}" d="${d}"/>`);
|
||||
out.push({ key: `${e.from}>${e.to}`, from: e.from, to: e.to, lane: i, cls: `${e.on ? "on" : ""}${e.lost ? " lost" : ""}`, d });
|
||||
}
|
||||
const html = out.join("");
|
||||
if (svg.innerHTML !== html) svg.innerHTML = html;
|
||||
// Each curve keeps its element, changed only where it changed, so only what moved is painted again.
|
||||
const had = new Map<string, SVGPathElement>();
|
||||
for (const p of svg.querySelectorAll<SVGPathElement>("path")) had.set(p.dataset.key!, p);
|
||||
out.forEach((c, k) => {
|
||||
let p = had.get(c.key);
|
||||
had.delete(c.key);
|
||||
if (!p) {
|
||||
p = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
||||
p.dataset.key = c.key;
|
||||
p.dataset.from = String(c.from);
|
||||
p.dataset.to = String(c.to);
|
||||
}
|
||||
if (p.getAttribute("d") !== c.d) p.setAttribute("d", c.d);
|
||||
if (p.getAttribute("class") !== c.cls) p.setAttribute("class", c.cls);
|
||||
if (p.dataset.lane !== String(c.lane)) p.dataset.lane = String(c.lane);
|
||||
// In drawing order: the focused branch's last, on top.
|
||||
if (svg.children[k] !== p) svg.insertBefore(p, svg.children[k] ?? null);
|
||||
});
|
||||
for (const p of had.values()) p.remove();
|
||||
}
|
||||
+12
-12
@@ -15,11 +15,11 @@ export const HELP: [string, [string, string][]][] = [
|
||||
["/", "jump to a section by name, in any document"],
|
||||
["z", "hoist: make this node the whole page (again, or h or Esc at its top, to step out)"],
|
||||
["v", "view: one column ↔ panes side by side (in panes, j k move among siblings)"],
|
||||
["q", "in panes: close the active pane (the one under the heavy rule, whatever it shows) and every pane opened from it, except pinned ones; the focus goes back to where it was opened from. A pane's × does the same. Moving left never closes anything"],
|
||||
["P", "in panes: pin or unpin the active pane (or its pin, top right). A pinned pane stays where it is when a pane it came from closes, is never replaced by a plain open, and never folds into a tab or a spine"],
|
||||
["Shift+Enter", "in panes: open a fork: what Enter opens goes in the next column below what is open there, instead of replacing it (Shift-, Ctrl- or Cmd-click, or a middle click, does the same). With nothing open to the right it is a plain Enter; on something already open as a fork, it focuses that fork"],
|
||||
["[ ]", "in panes: the pane above / below in the same column, whichever fork it belongs to (back where you were in it, or at its head); at the top or bottom of the column nothing moves. A faint curve runs from where each pane was opened to its title"],
|
||||
],
|
||||
["q", "in panes: close the active pane (the one under the heavy rule, whatever it shows) and every pane opened from it, except pinned ones; the focus goes back to where it was opened from. A pane's x does the same. Moving left never closes anything"],
|
||||
["P", "in panes: pin or unpin the active pane (or its pin, top right). A pinned pane stays where it is when a pane it came from closes, is never replaced by a Shift open, and is never covered, in its column or along the strip"],
|
||||
["Enter l", "in panes: open into the next column, beside what is open there (so does a click, and a Ctrl-, Cmd- or middle click); on something open already, focus it"],
|
||||
["Shift+Enter", "in panes: open in place of the focused branch's pane in the next column (so does a Shift-click)"],
|
||||
["[ ]", "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"], ],
|
||||
],
|
||||
[
|
||||
"Links",
|
||||
@@ -41,7 +41,7 @@ export const HELP: [string, [string, string][]][] = [
|
||||
"Expand",
|
||||
[
|
||||
["e", "go deeper: open → open children → generate"],
|
||||
["Enter", "on a section: toggle. On a selection: open its note, or step into it"],
|
||||
["Enter", "on a section: toggle (in panes: open its pane, or focus it where it is open). On a selection: open its note, or step into it"],
|
||||
["H L", "shrink / grow the selection by one unit"],
|
||||
["d y x c", "on a selection: define · why · example · challenge"],
|
||||
[":", "on a selection: ask your own question about it"],
|
||||
@@ -237,7 +237,7 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
// The filter box is not focused (a key typed before it took focus, or after a click
|
||||
// elsewhere in the panel): keys still mean what they would there.
|
||||
if (k === "Escape" || k === "Tab") m.focus = "list";
|
||||
else if (k === "Enter") return d && (e.preventDefault(), store.openDoc(d.node));
|
||||
else if (k === "Enter") return d && (e.preventDefault(), store.openDoc(d.node, true));
|
||||
else if (k === "ArrowDown" || k === "ArrowUp") return e.preventDefault(), store.menuMove(k === "ArrowDown" ? 1 : -1);
|
||||
else if (k.length === 1) return e.preventDefault(), store.menuFilter(m.filter + k);
|
||||
else return;
|
||||
@@ -265,7 +265,7 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
store.menuMove(-1);
|
||||
break;
|
||||
case "Enter":
|
||||
if (d) store.openDoc(d.node);
|
||||
if (d) store.openDoc(d.node, true);
|
||||
break;
|
||||
case "/":
|
||||
m.focus = "filter";
|
||||
@@ -347,11 +347,11 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
}
|
||||
// An Enter after a Tab that is waiting for its article to arrive waits with it.
|
||||
if (store.aux && store.holdKey(k, e.shiftKey)) return done();
|
||||
// Shift+Enter opens a fork: whatever Enter opens, it opens beside what is there.
|
||||
const fork = k === "Enter" && e.shiftKey;
|
||||
// Enter opens beside what is in the next column; Shift+Enter in place of the focused branch's pane there.
|
||||
const replace = k === "Enter" && e.shiftKey;
|
||||
// Words selected in an article's text take the same keys as words of a node.
|
||||
if (store.aux && !store.inArticleText) {
|
||||
if (store.withFork(fork, () => auxKey(k, e.shiftKey)) || commonKey(k, hooks)) return done();
|
||||
if (store.withReplace(replace, () => auxKey(k, e.shiftKey)) || commonKey(k, hooks)) return done();
|
||||
const why = store.aux.kind === "wiki" ? store.articleRefuses(k, false) : null;
|
||||
if (why) (store.say(why), done());
|
||||
return;
|
||||
@@ -394,7 +394,7 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
break;
|
||||
case "Enter":
|
||||
case " ":
|
||||
store.withFork(fork, () => {
|
||||
store.withReplace(replace, () => {
|
||||
if (selecting) store.enterOrExpand();
|
||||
else if (store.snap.nodes[store.focus.node]?.kind === "note" && store.targetOf(store.focus.node)) store.followOwn();
|
||||
else store.toggle();
|
||||
|
||||
+7
-3
@@ -8,6 +8,8 @@ export const LANE_PITCH = 4;
|
||||
export const LANE_FIRST = 5;
|
||||
export const LANE_LAST = 29;
|
||||
export const LANES = Math.floor((LANE_LAST - LANE_FIRST) / LANE_PITCH) + 1;
|
||||
/** Up to this many curves in a gutter, every lane is tried for each; past it, only the neighbouring lanes. */
|
||||
const MOVES = 8;
|
||||
|
||||
/**
|
||||
* How many times curves in one gutter cross, for an order of lanes (rightmost first): a lead-out
|
||||
@@ -46,12 +48,14 @@ export function laneOrder<T extends { key: string; sy: number; ey: number }>(edg
|
||||
const at = order.findIndex((o) => rule.indexOf(o) > r);
|
||||
order.splice(at < 0 ? order.length : at, 0, e);
|
||||
}
|
||||
// Move one curve to another lane while that removes crossings (a few curves per gutter: cheap).
|
||||
// Move one curve to another lane while that removes crossings: a few curves per gutter, every place
|
||||
// tried; many (past MOVES), only neighbours swapped, which stays cheap enough for every frame.
|
||||
let best = crossings(order);
|
||||
for (let pass = 0, better = true; better && pass < order.length; pass++) {
|
||||
const far = order.length <= MOVES;
|
||||
for (let pass = 0, better = best > 0; better && pass < order.length; pass++) {
|
||||
better = false;
|
||||
for (let i = 0; i < order.length && best; i++)
|
||||
for (let j = 0; j < order.length; j++) {
|
||||
for (let j = far ? 0 : i + 1; j < (far ? order.length : Math.min(order.length, i + 2)); j++) {
|
||||
if (j === i) continue;
|
||||
const moved = order.slice();
|
||||
moved.splice(j, 0, ...moved.splice(i, 1));
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Stacking, after Andy Matuschak's notes, along either axis of the panes view (Panes.tsx). Items
|
||||
* stand side by side in a scrolling box, each stuck (position: sticky) a strip's width after the one
|
||||
* before, so that a later item slides over an earlier one and leaves it a strip: across the strip,
|
||||
* the columns, leaving spines; down a crowded column, its panes, leaving tabs. A pinned item leaves
|
||||
* its whole size instead, so nothing after it covers it. How far each item is covered sets its
|
||||
* state: overlapped (a shadow edge on the item over it), covered (only its strip is worth showing),
|
||||
* and the box scrolls as little as it can to show the item looked at whole.
|
||||
*
|
||||
* This module is that model and its computation, for both axes; Panes.tsx sizes the items (a
|
||||
* column is a pane's width; a pane in a crowded column, what its text needs up to the column's
|
||||
* height less a tab for each other pane) and applies what comes back.
|
||||
*/
|
||||
|
||||
export interface Axis {
|
||||
/** The sticky inset, and the start and end of a box along the axis. */
|
||||
start: "left" | "top";
|
||||
end: "right" | "bottom";
|
||||
size: "offsetWidth" | "offsetHeight";
|
||||
client: "clientWidth" | "clientHeight";
|
||||
scroll: "scrollLeft" | "scrollTop";
|
||||
scrollSize: "scrollWidth" | "scrollHeight";
|
||||
}
|
||||
/** Across: the columns of the strip. */
|
||||
export const ACROSS: Axis = { start: "left", end: "right", size: "offsetWidth", client: "clientWidth", scroll: "scrollLeft", scrollSize: "scrollWidth" };
|
||||
/** Down: the panes of a crowded column. */
|
||||
export const DOWN: Axis = { start: "top", end: "bottom", size: "offsetHeight", client: "clientHeight", scroll: "scrollTop", scrollSize: "scrollHeight" };
|
||||
|
||||
/** An item covered to less than this share of its size shows only its strip (spine or tab). */
|
||||
export const COVERED = 0.4;
|
||||
|
||||
/**
|
||||
* Each item's sticky offset: every item before it leaves its strip, a pinned one its whole size;
|
||||
* never so far that the items after it could not all still be scrolled to.
|
||||
*/
|
||||
export function offsets(sizes: number[], pinned: boolean[], strip: number, view: number): number[] {
|
||||
const n = sizes.length;
|
||||
let at = 0;
|
||||
return sizes.map((s, i) => {
|
||||
const o = Math.round(Math.min(at, Math.max(i * strip, view - s - (n - 1 - i) * strip)));
|
||||
at += pinned[i] ? s : strip;
|
||||
return o;
|
||||
});
|
||||
}
|
||||
|
||||
/** 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));
|
||||
|
||||
/**
|
||||
* How covered each item is, from where each begins on screen now, its size and where the box ends:
|
||||
* an item shows up to where the next begins (or the box's end); overlapped when any of it is
|
||||
* hidden, covered when less than COVERED of it shows, buried when no more than its strip does (what
|
||||
* is under the strip need not be painted).
|
||||
*/
|
||||
export function coverage(at: number[], sizes: number[], end: number, strip = 0): { over: boolean[]; covered: boolean[]; buried: boolean[] } {
|
||||
const shown = at.map((a, i) => Math.max(0, Math.min(at[i + 1] ?? Infinity, end) - a));
|
||||
return { over: shown.map((s, i) => s < sizes[i] - 1), covered: shown.map((s, i) => s < sizes[i] * COVERED), buried: shown.map((s) => s <= strip + 2) };
|
||||
}
|
||||
|
||||
/**
|
||||
* The scroll, as near the present one as it can be, that shows an item whole: its far edge inside
|
||||
* the box, and itself not yet stuck under the items before it.
|
||||
*/
|
||||
export function reveal(scroll: number, view: number, start: number, size: number, stuck: number, max: number): number {
|
||||
return Math.max(0, Math.min(max, Math.min(Math.max(scroll, start + size - view), start - stuck)));
|
||||
}
|
||||
|
||||
/** Whether an item is shown whole at this scroll. */
|
||||
export const whole = (scroll: number, view: number, start: number, size: number, stuck: number) => scroll >= start + size - view - 1 && scroll <= start - stuck + 1;
|
||||
|
||||
const setAttr = (el: Element | undefined, name: string, on: boolean) => {
|
||||
if (el && el.hasAttribute(name) !== on) on ? el.setAttribute(name, "") : el.removeAttribute(name);
|
||||
};
|
||||
|
||||
/** Stick a box's items at their offsets. */
|
||||
export function stick(items: HTMLElement[], offs: number[], axis: Axis) {
|
||||
items.forEach((el, i) => {
|
||||
const v = `${offs[i]}px`;
|
||||
if (el.style[axis.start] !== v) el.style[axis.start] = v;
|
||||
});
|
||||
}
|
||||
|
||||
/** Clear the marks of items no longer stacked. */
|
||||
export function unmark(items: Element[]) {
|
||||
for (const el of items) {
|
||||
setAttr(el, "data-covered", false);
|
||||
setAttr(el, "data-over", false);
|
||||
setAttr(el, "data-buried", false);
|
||||
}
|
||||
}
|
||||
|
||||
/** Mark a box's items with how covered they are now (data-over, data-covered); `edge`: whether the box's far edge covers too (down a column it does; across, a column beyond the window is simply further on). */
|
||||
export function mark(box: HTMLElement, items: HTMLElement[], axis: Axis, edge: boolean, strip: number) {
|
||||
if (!items.length) return;
|
||||
const at = items.map((el) => el.getBoundingClientRect()[axis.start]);
|
||||
const { over, covered, buried } = coverage(
|
||||
at,
|
||||
items.map((el) => el[axis.size]),
|
||||
edge ? box.getBoundingClientRect()[axis.start] + box[axis.client] : Infinity,
|
||||
strip,
|
||||
);
|
||||
items.forEach((el, i) => {
|
||||
setAttr(el, "data-covered", covered[i]);
|
||||
setAttr(el, "data-buried", buried[i]);
|
||||
// The shadow edge is drawn by the item over an overlapped one.
|
||||
setAttr(items[i + 1], "data-over", over[i] && i + 1 < items.length);
|
||||
});
|
||||
}
|
||||
+43
-29
@@ -36,7 +36,7 @@ import { remoteLLM } from "./remote";
|
||||
import { Session } from "./session";
|
||||
import { refreshAfterCalls } from "./usage";
|
||||
import { Linker, type AutoMode, type JobState, type Sugg } from "./linker";
|
||||
import { all, besideInColumn, close as closeIn, focus as focusIn, focused, open as openIn, path, pin as pinIn, prune, restore as restoreForest, rooted, save as saveTree, updateIn, withBranch, type Forest, type Placed, type Tree } from "./forks";
|
||||
import { all, besideInColumn, close as closeIn, columns as columnsOf, reorder, focus as focusIn, focused, open as openIn, path, pin as pinIn, prune, restore as restoreForest, rooted, save as saveTree, updateIn, withBranch, type Forest, type Placed, type Tree } from "./forks";
|
||||
import { stripMarks, type Mark } from "../core/marks";
|
||||
import { SEED_SLUG } from "../core/seed";
|
||||
|
||||
@@ -290,10 +290,10 @@ class Store {
|
||||
get tree(): Pane | null {
|
||||
return focused(this.forest);
|
||||
}
|
||||
/** Set while a modified open (Shift+Enter, Shift-, Ctrl- or middle-click) runs: it opens a fork beside what is there. */
|
||||
forking = false;
|
||||
private toldForks = false;
|
||||
private memo: { forest: Forest<PaneRef, Back> | null; nodes: Pane[]; trail: PaneRef[]; placed?: Placed<PaneRef, Back>[]; index?: Map<number, Placed<PaneRef, Back>>; ids?: Set<NodeId> } = { forest: null, nodes: [], trail: [] };
|
||||
/** Set while a Shift open (Shift+Enter, Shift-click) runs: it opens in place of what is in the next column instead of beside it. */
|
||||
replacing = false;
|
||||
private toldReplace = false;
|
||||
private memo: { forest: Forest<PaneRef, Back> | null; nodes: Pane[]; trail: PaneRef[]; placed?: Placed<PaneRef, Back>[]; cols?: Map<number, Placed<PaneRef, Back>[]>; index?: Map<number, Placed<PaneRef, Back>>; ids?: Set<NodeId> } = { forest: null, nodes: [], trail: [] };
|
||||
private get branch() {
|
||||
if (this.memo.forest !== this.forest) {
|
||||
const nodes = path(this.tree);
|
||||
@@ -301,11 +301,16 @@ class Store {
|
||||
}
|
||||
return this.memo;
|
||||
}
|
||||
/** Every pane, with its column, in the order panes stand in a column. */
|
||||
/** Every pane, with its column, tree by tree, depth first. */
|
||||
get panesPlaced(): Placed<PaneRef, Back>[] {
|
||||
const m = this.branch;
|
||||
return (m.placed ??= all(this.forest));
|
||||
}
|
||||
/** The panes of each column, top to bottom (forks.ts `columns`). */
|
||||
get paneColumns(): Map<number, Placed<PaneRef, Back>[]> {
|
||||
const m = this.branch;
|
||||
return (m.cols ??= columnsOf(this.forest));
|
||||
}
|
||||
/** The focused branch: the panes the keys move along, left to right. */
|
||||
get trail(): PaneRef[] {
|
||||
return this.branch.trail;
|
||||
@@ -555,11 +560,12 @@ class Store {
|
||||
|
||||
/**
|
||||
* Open something to the right of pane i. If it is already open there, as any fork, that fork is
|
||||
* focused. Otherwise a plain open replaces what was to the right (a pinned pane stays beside it);
|
||||
* a fork (`forking`) opens it beside that, below in the next column. Returns the pane it is in.
|
||||
* focused. Otherwise it opens beside what is there, a new pane in the next column; a Shift open
|
||||
* (`replacing`) opens it in place of the focused branch's pane there instead (a pinned pane stays
|
||||
* beside it). Returns the pane it is in.
|
||||
*/
|
||||
openPane(i: number, ref: PaneRef): number {
|
||||
this.setForest(openIn(this.forest, i, ref, this.forking, sameRef));
|
||||
this.setForest(openIn(this.forest, i, ref, !this.replacing, sameRef));
|
||||
this.saveView();
|
||||
this.emit();
|
||||
return Math.min(i + 1, this.trail.length - 1);
|
||||
@@ -572,18 +578,18 @@ class Store {
|
||||
this.closePane(kid.id);
|
||||
}
|
||||
|
||||
/** Run an open with or without a fork. In the column a fork is a plain open, and the status line says so once. */
|
||||
withFork<T>(fork: boolean, fn: () => T): T {
|
||||
if (fork && !this.panes && !this.toldForks) {
|
||||
this.toldForks = true;
|
||||
this.say("Forks (Shift+Enter, Shift- or Ctrl-click) open side by side in the panes view; in one column this opens as usual.");
|
||||
/** Run an open beside what is there, or in its place (Shift). In the column there is only the one way, and the status line says so once. */
|
||||
withReplace<T>(replace: boolean, fn: () => T): T {
|
||||
if (replace && !this.panes && !this.toldReplace) {
|
||||
this.toldReplace = true;
|
||||
this.say("Shift+Enter and Shift-click open in place of the pane to the right in the panes view; in one column this opens as usual.");
|
||||
}
|
||||
const was = this.forking;
|
||||
this.forking = fork && this.panes;
|
||||
const was = this.replacing;
|
||||
this.replacing = replace && this.panes;
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
this.forking = was;
|
||||
this.replacing = was;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,6 +719,15 @@ class Store {
|
||||
this.land(i);
|
||||
}
|
||||
|
||||
/** A pane dragged up or down its column, to just above another (or to the bottom). */
|
||||
reorderPane(id: number, before: number | null) {
|
||||
const f = reorder(this.forest, id, before);
|
||||
if (f === this.forest) return;
|
||||
this.setForest(f);
|
||||
this.saveView();
|
||||
this.emit();
|
||||
}
|
||||
|
||||
/** P (on the active pane) or a pane's pin: pin or unpin it. */
|
||||
togglePanePin(id = this.branchNodes[this.paneAt]?.id) {
|
||||
if (!this.panes) return this.say("Panes are pinned in the panes view (v).");
|
||||
@@ -1352,7 +1367,8 @@ class Store {
|
||||
}
|
||||
|
||||
/** Open a document: hoist to it in the column, show it in the next pane in panes. */
|
||||
openDoc(id: NodeId) {
|
||||
/** Open a document: from its row in the library, beside what is open; from the menu, a command or an address (`nav`), in place of it. */
|
||||
openDoc(id: NodeId, nav = false) {
|
||||
const s = this.doc.snap();
|
||||
if (!s.nodes[id]) return;
|
||||
void this.links.loadDoc(id);
|
||||
@@ -1365,7 +1381,7 @@ class Store {
|
||||
this.open.add(id);
|
||||
this.focus = { node: id, grain: "node" };
|
||||
this.syncTrail();
|
||||
if (s.nodes[id].parent === this.top) this.openPane(this.paneAt, { kind: "node", id });
|
||||
if (s.nodes[id].parent === this.top) this.withReplace(nav || this.replacing, () => this.openPane(this.paneAt, { kind: "node", id }));
|
||||
} else this.hoist = id;
|
||||
this.focus = { node: id, grain: "node" };
|
||||
this.saveView();
|
||||
@@ -1552,12 +1568,10 @@ class Store {
|
||||
if (this.listing(id)) return this.openDoc(id);
|
||||
// The head of a pane other than the first: Enter steps into its rows, as l does.
|
||||
if (this.panes && this.paneAt > 0 && this.paneHead(id)) return this.into();
|
||||
// In panes, a row whose pane is open as a fork that is not the focused one, or any row opened as a fork, opens (focuses) its pane rather than closing it.
|
||||
// In panes a row opens its pane, or focuses it where it is open already: closing is q's, or the pane's x.
|
||||
if (this.panes) {
|
||||
this.syncTrail();
|
||||
const n = this.branchNodes[this.paneAt];
|
||||
const k = n ? n.kids.findIndex((c) => c.ref.kind === "node" && c.ref.id === id) : -1;
|
||||
if ((k >= 0 && k !== n.pick) || this.forking) return this.setOpen(id, true);
|
||||
return this.setOpen(id, true);
|
||||
}
|
||||
this.setOpen(id, !this.isOpen(id));
|
||||
}
|
||||
@@ -2537,7 +2551,7 @@ class Store {
|
||||
this.held = null;
|
||||
if (art?.state !== "ready") return;
|
||||
for (const k of h.keys) {
|
||||
if (k === "Enter" || k === "S-Enter") this.withFork(k === "S-Enter", () => (this.inArticleText ? this.enterArticle() : this.auxActivate()));
|
||||
if (k === "Enter" || k === "S-Enter") this.withReplace(k === "S-Enter", () => (this.inArticleText ? this.enterArticle() : this.auxActivate()));
|
||||
else if (k === "i") this.descend();
|
||||
else this.auxTab(k === "Tab" ? 1 : -1);
|
||||
}
|
||||
@@ -3062,7 +3076,7 @@ class Store {
|
||||
if (!title) return this.say("A new document needs a title: /new <title>");
|
||||
this.docWrite(() => {
|
||||
const id = createDoc(this.doc, title, this.user);
|
||||
this.openDoc(id);
|
||||
this.openDoc(id, true);
|
||||
this.say(`Created “${clip(title, 60)}”: c writes its opening text, a adds a section.`);
|
||||
});
|
||||
}
|
||||
@@ -3084,7 +3098,7 @@ class Store {
|
||||
if (!title) return this.say("The copy needs a title.");
|
||||
this.docWrite(() => {
|
||||
const copy = duplicateDoc(this.doc, id, title, this.user);
|
||||
this.openDoc(copy);
|
||||
this.openDoc(copy, true);
|
||||
this.say(`Saved a copy as “${clip(title, 60)}”; this is the copy.`);
|
||||
});
|
||||
}
|
||||
@@ -3144,7 +3158,7 @@ class Store {
|
||||
const slug = freeSlug(file.name.replace(/\.(md|markdown|txt)$/i, ""), new Set(documents(s).map((d) => s.nodes[d].slug)));
|
||||
try {
|
||||
const id = importDoc(this.doc, text, file.name, { creator: this.user, slug });
|
||||
this.openDoc(id);
|
||||
this.openDoc(id, true);
|
||||
this.say(`Imported ${file.name} as “${clip(this.doc.snap().nodes[id].title, 60)}”.`);
|
||||
// Imported text is scanned like any other writing: by a background job, once the server has it.
|
||||
if (this.settings.autolink !== "off") void this.whenSynced().then(() => this.linkJob("doc", id, true));
|
||||
@@ -3165,7 +3179,7 @@ class Store {
|
||||
all.find((x) => x.slug === q) ?? all.find((x) => x.title.toLowerCase() === q) ?? all.find((x) => x.title.toLowerCase().startsWith(q)) ??
|
||||
all.find((x) => `${x.title} ${x.slug}`.toLowerCase().includes(q));
|
||||
if (!d) return this.say(`No document matches “${name}”. m lists them.`);
|
||||
this.openDoc(d.node);
|
||||
this.openDoc(d.node, true);
|
||||
this.say(`Opened “${clip(d.title, 60)}”.`);
|
||||
}
|
||||
|
||||
@@ -3384,7 +3398,7 @@ class Store {
|
||||
this.aux = null;
|
||||
this.colWiki = null;
|
||||
const s = this.snap;
|
||||
if (s.library && s.nodes[id]?.parent === s.root) return this.openDoc(id);
|
||||
if (s.library && s.nodes[id]?.parent === s.root) return this.openDoc(id, true);
|
||||
this.reveal(id);
|
||||
this.focus = { node: id, grain: "node" };
|
||||
this.saveView();
|
||||
|
||||
+35
-6
@@ -334,6 +334,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
--spine: 2.1rem;
|
||||
--pane-pad: 1.8rem;
|
||||
--pane: calc(var(--spine) + var(--pane-text) + var(--pane-pad));
|
||||
--tab: 30px;
|
||||
--shade: rgb(0 0 0 / 0.2);
|
||||
--pane-rule: #d9d9d9;
|
||||
--curve: rgb(0 0 0 / 0.17);
|
||||
@@ -386,19 +387,46 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.spine { transition: none; }
|
||||
}
|
||||
|
||||
/* A folded pane: one line, its title (and W for an article), its pin and ×; a click opens it. */
|
||||
/*
|
||||
* Down a crowded column the panes stack as the columns do across the strip (stack.ts): each stuck
|
||||
* a tab below the one before, a later one sliding up over an earlier along a hairline (a shadow
|
||||
* there costs too much painting, with many panes) and, covered to its tab, its title on one line,
|
||||
* as a covered column shows its spine.
|
||||
*/
|
||||
.col.crowded { overflow-y: auto; overscroll-behavior-y: contain; scrollbar-width: thin; scrollbar-color: var(--hair) transparent; }
|
||||
.col.crowded > .pane { position: sticky; }
|
||||
.col.crowded > .pane[data-over]::before { content: ""; position: absolute; z-index: 4; top: 0; left: 0; right: 0; height: 1px; background: var(--rule); }
|
||||
.tabline {
|
||||
display: none; align-items: center; gap: 0.4em; height: 100%; padding: 0 3.4rem 0 var(--spine); cursor: pointer;
|
||||
position: absolute; z-index: 2; top: 0; left: 0; right: 0; height: var(--tab); display: flex; align-items: center; gap: 0.4em;
|
||||
padding: 0 3.4rem 0 var(--spine); background: inherit; border-bottom: 1px solid var(--pane-rule); opacity: 0; pointer-events: none; cursor: pointer; transition: opacity 0.12s;
|
||||
font-family: var(--sans); font-size: 0.74rem; letter-spacing: 0.02em; color: var(--dim); white-space: nowrap;
|
||||
}
|
||||
.tabline .tabtitle { overflow: hidden; text-overflow: ellipsis; }
|
||||
.tabline:hover { color: var(--fg); }
|
||||
.pane[data-tab] > .tabline { display: flex; }
|
||||
.pane[data-tab] > .pane-scroll, .pane[data-tab] > .spine { display: none; }
|
||||
.col.crowded > .pane[data-covered] > .tabline { opacity: 1; pointer-events: auto; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.tabline { transition: none; }
|
||||
}
|
||||
|
||||
/* A pane or column covered down to its tab or spine has nothing else on show: it is not painted, until it peeks. */
|
||||
.col[data-buried]:not([data-peek]) .pane-scroll, .col.crowded > .pane[data-buried]:not([data-peek]) > .pane-scroll { content-visibility: hidden; }
|
||||
|
||||
/* Peeking: a covered pane or column, the mouse resting on it, raised over its neighbours whole. */
|
||||
.col[data-peek], .pane[data-peek] { z-index: 6; box-shadow: 0 3px 18px 0 var(--shade); }
|
||||
.col[data-peek] .spine, .col.crowded > .pane[data-peek] > .tabline { opacity: 0; pointer-events: none; }
|
||||
|
||||
/* Dragging a pane in its column: its grip, quiet until pointed at; the line where it will go. */
|
||||
.grip { position: absolute; z-index: 3; top: 0; left: var(--spine); right: 3.6rem; height: 1.15rem; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
|
||||
.grip::before { content: ""; position: absolute; left: 50%; top: 0.42rem; width: 1.1rem; margin-left: -0.55rem; height: 3px; border-top: 1px solid var(--faint); border-bottom: 1px solid var(--faint); opacity: 0; transition: opacity 0.12s; }
|
||||
.col.split .grip:hover::before { opacity: 0.8; }
|
||||
.col:not(.split) .grip, .col.crowded > .pane[data-covered] > .grip { display: none; }
|
||||
.tabline { touch-action: none; }
|
||||
.panes.dragging, .panes.dragging * { cursor: grabbing !important; user-select: 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. */
|
||||
.pane-ctl { position: absolute; z-index: 3; top: 0.25rem; right: 0.3rem; display: flex; gap: 0.05rem; }
|
||||
.pane[data-tab] > .pane-ctl { top: 2px; }
|
||||
.col.crowded > .pane[data-covered] > .pane-ctl { top: 2px; }
|
||||
.pane-btn { display: block; width: 1.3rem; height: 1.3rem; padding: 0.3rem; border-radius: 2px; cursor: pointer; color: var(--rule); }
|
||||
.pane-btn svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.pane:hover .pane-btn { color: var(--faint); }
|
||||
@@ -416,7 +444,8 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.pane.on-branch:not(.active)::after { height: 1px; background: var(--faint); }
|
||||
|
||||
/* The curves: from what each pane was opened from to its title, behind nothing but in the gaps between lines. */
|
||||
.curves { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; overflow: hidden; }
|
||||
/* A layer of its own, so that drawing a curve again does not paint the panes under it again. */
|
||||
.curves { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; overflow: hidden; will-change: transform; }
|
||||
.curves path { fill: none; stroke: var(--curve); stroke-width: 1; }
|
||||
.curves path.on { stroke: var(--curve-on); }
|
||||
.curves path.lost { stroke-dasharray: 1 3; }
|
||||
|
||||
Reference in new issue
Block a user