Panes by column: a forest of panes, curves between them, close, pin and an active rule
The tree of forks becomes a forest: a pinned pane stays open when a pane it was opened from closes, as an orphan in its own column. Close takes a pane and what was opened from it, pinned panes excepted; pin and unpin; [ and ] move to the pane above or below in a column. The panes view is laid out by column: column d holds every pane at depth d and divides its own height among them, a short pane taking only what its text needs; when they do not fit, all but the focused branch's pane (and pinned ones) fold into one-line tabs. A faint curve runs from the words, row or link each pane was opened from to its title, the focused branch's in a stronger ink; curves through one gutter take lanes side by side, ordered to cross least. Every pane has the same hairline right and bottom. The active pane has a heavy rule across its top, the rest of the focused branch a hairline. Each pane has a pin and a x at its top right (the x also on its spine); q closes the active pane, whatever it shows (it used to close a whole fork from wherever the fork began, which closed the node an article was opened from); P pins it. /curves off hides the curves. 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
2f8ca98207
commit
3298cc430c
20 files changed
+1822
-783
No files matched your search
+7
-1
@@ -512,6 +512,9 @@ export function App() {
|
||||
const click = (e: MouseEvent) => {
|
||||
if (store.mode === "edit") return;
|
||||
const target = e.target as HTMLElement;
|
||||
// A pane's × and pin act on that pane, wherever the focus is.
|
||||
const ctl = target.closest<HTMLElement>("[data-close], [data-pin]");
|
||||
if (ctl) return ctl.dataset.close ? store.closePane(Number(ctl.dataset.close)) : store.togglePanePin(Number(ctl.dataset.pin));
|
||||
const paneEl = target.closest<HTMLElement>("[data-pane-index]");
|
||||
const paneIndex = paneEl ? Number(paneEl.dataset.paneIndex) : store.paneAt;
|
||||
// A pane in another fork: that fork becomes the focused branch first, then the click does what it would there.
|
||||
@@ -647,7 +650,10 @@ export function App() {
|
||||
if (hit) return store.go(at.id, "sentence", hit);
|
||||
}
|
||||
const node = target.closest<HTMLElement>("[data-node]");
|
||||
if (node) store.go(node.dataset.node as NodeId);
|
||||
if (!node) return;
|
||||
// A pane's head makes that pane the active one.
|
||||
if (panes && paneEl && node.matches(".pane-head, .top")) store.paneAt = paneIndex;
|
||||
store.go(node.dataset.node as NodeId);
|
||||
};
|
||||
|
||||
const onOver = (e: MouseEvent) => {
|
||||
|
||||
+8
-4
@@ -9,7 +9,7 @@ import { ownerSection, resolveNode } from "../core/links";
|
||||
import { docOf, isLink, label, type NodeId } from "../core/model";
|
||||
import { describeTarget, hostOf, parseTarget, validateRef, wikiTitle, type Ref } from "../core/ref";
|
||||
import { clip, plain } from "../core/text";
|
||||
import { sameAux, store, type Aux } from "./store";
|
||||
import { kidClass, sameAux, store, type Aux } from "./store";
|
||||
import type { Sugg } from "./linker";
|
||||
import { suggest, summary, wikiConfig, type Attribution as Attr, type Suggestion } from "./wiki";
|
||||
|
||||
@@ -144,14 +144,18 @@ export function TargetRow({ id }: { id: NodeId }) {
|
||||
export const PaneCtx = createContext<number | undefined>(undefined);
|
||||
|
||||
/**
|
||||
* In a pane with forks, what marks the words, rows and links its forks were opened from: each open
|
||||
* child is "forked", the focused one "forked picked". By the keys a pane's child goes by (refKey).
|
||||
* In a pane with children, what marks the words, rows and links they were opened from: with forks,
|
||||
* each open child is "forked", the focused one "forked picked"; always, a class named after the
|
||||
* child (kidClass), which the curves start from. By the keys a pane's child goes by (refKey).
|
||||
*/
|
||||
export function useForkMark(): ((...keys: (string | undefined)[]) => string) | null {
|
||||
const marks = store.forkMarks(useContext(PaneCtx));
|
||||
if (!marks) return null;
|
||||
return (...keys) => {
|
||||
for (const k of keys) if (k && marks.has(k)) return marks.get(k) ? "forked picked" : "forked";
|
||||
for (const k of keys) {
|
||||
const m = k && marks.get(k);
|
||||
if (m) return `${m.many ? (m.picked ? "forked picked " : "forked ") : ""}${kidClass(k!)}`;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
}
|
||||
|
||||
+507
-167
@@ -3,23 +3,26 @@
|
||||
* path down from the top node; a link followed from a pane opens its target in the next pane
|
||||
* (another document's node, a Wikipedia article, a section of one), replacing what was to the
|
||||
* right. Moving back left closes nothing: the panes stay until something else is opened from an
|
||||
* earlier pane, or q closes them. Earlier panes stay pinned at the left as narrow spines when later
|
||||
* ones slide over them.
|
||||
* earlier pane, or q or a pane's × closes them. Earlier columns stay at the left as narrow spines
|
||||
* when later ones slide over them.
|
||||
*
|
||||
* A modified open (Shift+Enter, Shift- or Ctrl-click) makes a fork instead: the new pane opens
|
||||
* beside what was to the right, and the space right of the pane divides into rows, one per fork,
|
||||
* each continuing its own trail (forks.ts). The panes are `store.tree`; its focused branch is
|
||||
* `store.trail`, and which pane on it holds the focus is `store.paneAt`. Clicks are handled by the
|
||||
* page (App.tsx), exactly as in the column view; a click in another fork first makes it the
|
||||
* focused branch.
|
||||
* below what was in the next column. The panes are a forest (forks.ts) and the screen is laid out
|
||||
* by column: column d holds every open pane at depth d, top to bottom in tree order, and divides
|
||||
* its own height among them; when they do not fit, all but the pane on the focused branch (and any
|
||||
* pinned one) fold into one-line tabs. A faint curve runs from what each pane was opened from to
|
||||
* its title. The focused branch is `store.trail`, and the pane on it holding the focus, the active
|
||||
* pane, is `store.paneAt`. Clicks are handled by the page (App.tsx), exactly as in the column
|
||||
* view; a click in a pane off the branch first brings it onto the branch.
|
||||
*/
|
||||
import { Component, type ComponentChildren } from "preact";
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
||||
import { docOf, label, sections, staleness, type NodeId } from "../core/model";
|
||||
import { leaves } from "./forks";
|
||||
import type { Placed } from "./forks";
|
||||
import { LANES, LANE_FIRST, LANE_LAST, LANE_PITCH, laneOrder } from "./lanes";
|
||||
import { NodeBacklinks, NodeRelated, PaneCtx, TargetRow } from "./Links";
|
||||
import { Flags, NodeBody, PendingSections, Row, TitleEditor, TopMatter } from "./Node";
|
||||
import { refKey, store, type Aux, type Pane as PaneNode, type PaneRef } from "./store";
|
||||
import { kidClass, refKey, store, type Aux, type Back, type Pane as PaneNode, type PaneRef } from "./store";
|
||||
import { WikiView } from "./Wiki";
|
||||
import { article } from "./wiki";
|
||||
|
||||
@@ -28,20 +31,24 @@ interface PaneProps {
|
||||
p: PaneRef;
|
||||
/** The pane it was opened from, the one to its left. */
|
||||
parent?: PaneRef;
|
||||
/** Its depth in its tree: its place on the focused branch, when its tree is focused. */
|
||||
index: number;
|
||||
/** Its children, and which is picked, as a key (redraw when they change). */
|
||||
kids: string;
|
||||
/** Off the focused branch: drawn, but the keys are elsewhere; a click brings its fork onto the branch (App.tsx). Only an article pane draws differently (how its article is named). */
|
||||
/** Off the focused branch: drawn, but the keys are elsewhere; a click brings it onto the branch (App.tsx). Only an article pane draws differently (how its article is named). */
|
||||
off: boolean;
|
||||
/** In the narrow layout, where only the focused branch is drawn: which fork of how many this pane starts, if it starts one. */
|
||||
forkOf?: [number, number];
|
||||
/** The aux focus, when this pane holds it. */
|
||||
aux: Aux | null;
|
||||
/** The pane the keys act on. */
|
||||
active: boolean;
|
||||
/** The first tree's root: the top node's pane. */
|
||||
root: boolean;
|
||||
/** An orphan's root: a pinned pane whose source has closed. */
|
||||
orphan: boolean;
|
||||
}
|
||||
|
||||
// `off` is left out: a node pane draws the same on the branch or off it, and moving between forks should redraw only what changed.
|
||||
const key = (p: PaneProps) => `${refKey(p.p)}|${p.index}|${p.kids}|${p.active}|${p.forkOf ?? ""}|${JSON.stringify(p.aux)}`;
|
||||
const key = (p: PaneProps) => `${refKey(p.p)}|${p.index}|${p.kids}|${p.active}|${!!p.t.pinned}|${p.root}|${p.orphan}|${JSON.stringify(p.aux)}`;
|
||||
|
||||
/** Redraws a pane only when something drawn in it changed (see `store.paneDirty`). An article pane is cheap to redraw: its HTML is set once. */
|
||||
class Pane extends Component<PaneProps> {
|
||||
@@ -56,73 +63,108 @@ class Pane extends Component<PaneProps> {
|
||||
}
|
||||
}
|
||||
|
||||
/** The attributes every pane has: which it is, its column, and its place in the tree. */
|
||||
/** The attributes every pane has: which it is, its place in its tree, and its id there. */
|
||||
const paneAttrs = (props: PaneProps, name: string) => ({
|
||||
"data-pane": name,
|
||||
"data-pane-index": props.index,
|
||||
"data-tid": props.t.id,
|
||||
style: { left: `calc(${props.index} * var(--spine))` },
|
||||
});
|
||||
const paneClass = (props: PaneProps) => `${props.active ? " active" : ""}${props.t.pinned ? " pinned" : ""}${props.orphan ? " orphaned" : ""}`;
|
||||
|
||||
/** In the narrow layout, a pane that starts a fork says so, and how to get to the others. */
|
||||
function ForkNote({ of }: { of?: [number, number] }) {
|
||||
if (!of) return null;
|
||||
/**
|
||||
* What every pane carries besides its text: its spine (its title set vertically, shown when later
|
||||
* columns cover it), its tab (one line, shown when its column folds it), and, top right, its pin
|
||||
* and its ×. Clicks on them are handled by the page (App.tsx).
|
||||
*/
|
||||
function Chrome({ props, title, mark }: { props: PaneProps; title: string; mark?: ComponentChildren }) {
|
||||
const tid = props.t.id;
|
||||
const pinned = !!props.t.pinned;
|
||||
return (
|
||||
<div class="fork-note">
|
||||
fork {of[0] + 1} of {of[1]} · <kbd>[</kbd> <kbd>]</kbd> for the others
|
||||
</div>
|
||||
<>
|
||||
<div class="spine" data-spine={props.index} title={title}>
|
||||
<span role="button" class="pane-btn close" data-close={tid} title="Close this pane and what was opened from it (q)" aria-label="Close">
|
||||
<svg viewBox="0 0 12 12" aria-hidden="true">
|
||||
<path d="M3 3l6 6M9 3l-6 6" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="spine-title">
|
||||
{mark}
|
||||
{mark && " "}
|
||||
{title}
|
||||
</span>
|
||||
</div>
|
||||
<div class="tabline" data-spine={props.index} title={title}>
|
||||
{mark}
|
||||
<span class="tabtitle">{title}</span>
|
||||
</div>
|
||||
<div class="pane-ctl">
|
||||
<span role="button" class={`pane-btn pin${pinned ? " on" : ""}`} data-pin={tid} title={pinned ? "Unpin this pane (P)" : "Pin this pane: it stays when what opened it closes, and never folds away (P)"} aria-label={pinned ? "Unpin" : "Pin"}>
|
||||
<svg viewBox="0 0 12 12" aria-hidden="true">
|
||||
<path d="M4 1.5h4M4.6 1.5v3.6L2.8 7.2h6.4L7.4 5.1V1.5M6 7.2V11" />
|
||||
</svg>
|
||||
</span>
|
||||
<span role="button" class="pane-btn close" data-close={tid} title="Close this pane and what was opened from it (q)" aria-label="Close">
|
||||
<svg viewBox="0 0 12 12" aria-hidden="true">
|
||||
<path d="M3 3l6 6M9 3l-6 6" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** An orphan says, quietly, that what it was opened from has closed. */
|
||||
const Orphaned = ({ on }: { on: boolean }) => (on ? <div class="pane-from orphan-note">opened from a pane since closed</div> : null);
|
||||
|
||||
function NodePane(props: PaneProps & { id: NodeId }) {
|
||||
const { id, index, active, t, parent } = props;
|
||||
const { id, active, t, parent } = props;
|
||||
const snap = store.snap;
|
||||
const n = snap.nodes[id];
|
||||
if (!n) return null;
|
||||
const top = id === store.top && index === 0;
|
||||
const top = props.root && id === store.top;
|
||||
// A document's pane is a page of its own, headed like one.
|
||||
const page = top || docOf(snap, id) === id;
|
||||
const kids = sections(snap, id);
|
||||
const focused = active && !store.aux && store.focus.node === id;
|
||||
const editing = store.edit?.node === id && store.edit.field === "title";
|
||||
const jump = index > 0 && !store.continuesFrom(props.p, parent);
|
||||
const jump = !props.root && !props.orphan && !store.continuesFrom(props.p, parent);
|
||||
// Its children open to the right: the picked one's row is marked as showing; other forks' rows as forked.
|
||||
const kid = t.kids[t.pick];
|
||||
const showing = kid?.ref.kind === "node" && store.continuesFrom(kid.ref, props.p) ? kid.ref.id : undefined;
|
||||
const forked = new Set(t.kids.flatMap((k, j) => (j !== t.pick && k.ref.kind === "node" && store.continuesFrom(k.ref, props.p) ? [k.ref.id] : [])));
|
||||
return (
|
||||
<article
|
||||
class={`pane${top ? " root" : ""}${page && !top ? " doc" : ""}${jump ? " jumped" : ""}${n.kind === "note" ? " note-pane" : ""}${store.preview ? " preview" : ""}`}
|
||||
class={`pane${top ? " root" : ""}${page && !top ? " doc" : ""}${jump ? " jumped" : ""}${n.kind === "note" ? " note-pane" : ""}${store.preview ? " preview" : ""}${paneClass(props)}`}
|
||||
{...paneAttrs(props, id)}
|
||||
>
|
||||
<div class="spine" data-spine={index} title={label(snap, id)}>
|
||||
<span>{label(snap, id)}</span>
|
||||
</div>
|
||||
<Chrome props={props} title={label(snap, id)} />
|
||||
<div class="pane-scroll">
|
||||
<ForkNote of={props.forkOf} />
|
||||
{page ? (
|
||||
<TopMatter id={id} />
|
||||
) : (
|
||||
<>
|
||||
{jump && <div class="pane-from">{docOf(snap, id) ? snap.nodes[docOf(snap, id)!].title : "the library"}</div>}
|
||||
<header class={`pane-head${focused ? " focused" : ""}`} data-node={id}>
|
||||
{editing ? <TitleEditor id={id} /> : <h2>{n.title || (n.kind === "note" ? label(snap, id) : <i class="untitled">untitled</i>)}</h2>}
|
||||
<Flags id={id} />
|
||||
</header>
|
||||
<NodeBody id={id} />
|
||||
</>
|
||||
)}
|
||||
{kids.length > 0 && (
|
||||
<ul class="outline rows">
|
||||
{kids.map((k) => (
|
||||
<PaneRow key={k} id={k} showing={k === showing} forked={forked.has(k)} active={active} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<PendingSections id={id} />
|
||||
{store.articleUnder(id) ? <WikiView host={`n${id}`} /> : <TargetRow id={id} />}
|
||||
<NodeBacklinks id={id} />
|
||||
<NodeRelated id={id} />
|
||||
<div class="pane-body">
|
||||
<Orphaned on={props.orphan} />
|
||||
{page ? (
|
||||
<TopMatter id={id} />
|
||||
) : (
|
||||
<>
|
||||
{jump && <div class="pane-from">{docOf(snap, id) ? snap.nodes[docOf(snap, id)!].title : "the library"}</div>}
|
||||
<header class={`pane-head${focused ? " focused" : ""}`} data-node={id}>
|
||||
{editing ? <TitleEditor id={id} /> : <h2>{n.title || (n.kind === "note" ? label(snap, id) : <i class="untitled">untitled</i>)}</h2>}
|
||||
<Flags id={id} />
|
||||
</header>
|
||||
<NodeBody id={id} />
|
||||
</>
|
||||
)}
|
||||
{kids.length > 0 && (
|
||||
<ul class="outline rows">
|
||||
{kids.map((k) => (
|
||||
<PaneRow key={k} id={k} showing={k === showing} forked={forked.has(k)} active={active} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<PendingSections id={id} />
|
||||
{store.articleUnder(id) ? <WikiView host={`n${id}`} /> : <TargetRow id={id} />}
|
||||
<NodeBacklinks id={id} />
|
||||
<NodeRelated id={id} />
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
@@ -135,16 +177,14 @@ function WikiPane(props: PaneProps) {
|
||||
const sec = p.sec && a.state === "ready" ? a.value.sections.find((x) => x.id === p.sec) : undefined;
|
||||
const title = sec ? `${sec.heading} · ${p.title}` : a.state === "ready" ? a.value.title : p.title;
|
||||
return (
|
||||
<article class={`pane wiki-pane${p.from ? " jumped" : ""}`} {...paneAttrs(props, `w:${p.title}${p.sec ? `#${p.sec}` : ""}`)}>
|
||||
<div class="spine" data-spine={index} title={`Wikipedia: ${title}`}>
|
||||
<span>
|
||||
<b class="wmark">W</b> {title}
|
||||
</span>
|
||||
</div>
|
||||
<article class={`pane wiki-pane${p.from ? " jumped" : ""}${paneClass(props)}`} {...paneAttrs(props, `w:${p.title}${p.sec ? `#${p.sec}` : ""}`)}>
|
||||
<Chrome props={props} title={title} mark={<b class="wmark">W</b>} />
|
||||
<div class="pane-scroll">
|
||||
<ForkNote of={props.forkOf} />
|
||||
{/* On the focused branch an article pane is named by its column; off it, by its place in the tree. */}
|
||||
<WikiView host={props.off ? `f${props.t.id}` : `p${index}`} />
|
||||
<div class="pane-body">
|
||||
<Orphaned on={props.orphan} />
|
||||
{/* On the focused branch an article pane is named by its column; off it, by its place in the tree. */}
|
||||
<WikiView host={props.off ? `f${props.t.id}` : `p${index}`} />
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
@@ -160,7 +200,10 @@ function PaneRow({ id, showing, forked, active }: { id: NodeId; showing: boolean
|
||||
// While its pane is showing, the title is edited at the head of that pane instead.
|
||||
const editing = !showing && store.edit?.node === id && store.edit.field === "title";
|
||||
return (
|
||||
<li class={`node d${Math.min(n.depth - (snap.library ? 1 : 0), 6)}${open ? " open" : ""}${focused ? " focused" : ""}${showing ? " showing" : ""}${forked ? " forked" : ""}${st.up || st.down ? " stale" : ""}`} data-node={id}>
|
||||
<li
|
||||
class={`node d${Math.min(n.depth - (snap.library ? 1 : 0), 6)}${open ? " open" : ""}${focused ? " focused" : ""}${showing ? " showing" : ""}${forked ? " forked" : ""}${showing || forked ? ` ${kidClass(`n:${id}`)}` : ""}${st.up || st.down ? " stale" : ""}`}
|
||||
data-node={id}
|
||||
>
|
||||
<Row id={id} open={open} leaf={leaf} editing={editing} />
|
||||
</li>
|
||||
);
|
||||
@@ -179,70 +222,186 @@ function nearestY(el: Element | null | false) {
|
||||
else if (r.bottom > c.bottom - pad) box.scrollTop += Math.min(r.bottom - c.bottom + pad, r.top - c.top - pad);
|
||||
}
|
||||
|
||||
const setAttr = (el: HTMLElement | undefined, name: string, on: boolean) => {
|
||||
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 fork's row gets, on any window; below it the rows scroll. */
|
||||
const ROW_FLOOR = 220;
|
||||
/** Rows share the strip's height equally down to a third of it each (never below ROW_FLOOR); past that the stack of rows scrolls. */
|
||||
const rowMin = (h: number) => Math.max(ROW_FLOOR, Math.floor(h / 3));
|
||||
/** Whether forks can be drawn as rows: room for two rows, and for a fork's pane beside the pane it came from. */
|
||||
const roomy = (w: number, h: number, pane: number) => h >= 2 * ROW_FLOOR && w >= 2 * pane;
|
||||
/** The least height a pane keeps in a column while all its panes fit; below it, the column folds all but one into tabs. */
|
||||
export const PANE_MIN = 260;
|
||||
/** A folded pane's tab. */
|
||||
export const TAB = 30;
|
||||
|
||||
const kidsKey = (t: PaneNode) => `${t.pick}:${t.kids.map((k) => refKey(k.ref)).join(",")}`;
|
||||
/**
|
||||
* Heights for the panes of one column of height h, from what each needs to show all it holds:
|
||||
* each gets that, or an equal share of what is left, whichever is less; what no pane needs goes to
|
||||
* the one that needs most. So short panes are no taller than their text, and long ones share the rest.
|
||||
*/
|
||||
export function fill(h: number, needs: number[]): number[] {
|
||||
const out = needs.map(() => 0);
|
||||
const order = needs.map((_, i) => i).sort((a, b) => needs[a] - needs[b]);
|
||||
let rest = h;
|
||||
order.forEach((i, k) => {
|
||||
const share = rest / (order.length - k);
|
||||
out[i] = Math.floor(k === order.length - 1 ? rest : Math.min(needs[i], share));
|
||||
rest -= out[i];
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The panes drawn, by their id in the tree. */
|
||||
/** The panes drawn, by their id in the forest. */
|
||||
const paneEls = (el: HTMLElement) => {
|
||||
const m = new Map<number, HTMLElement>();
|
||||
for (const e of el.querySelectorAll<HTMLElement>(".pane[data-tid]")) m.set(Number(e.dataset.tid), e);
|
||||
return m;
|
||||
};
|
||||
|
||||
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 tree = store.tree;
|
||||
const strip = useRef<HTMLDivElement>(null);
|
||||
const svg = useRef<SVGSVGElement>(null);
|
||||
const followed = useRef("");
|
||||
const [room, setRoom] = useState(true);
|
||||
// Forks are drawn as rows when there is room; otherwise only the focused branch is.
|
||||
const rows = room && store.hasForks();
|
||||
/** Per column, the pane last on the focused branch there: the one a folded column keeps open 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. */
|
||||
const later = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
/** 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). */
|
||||
const latest = useRef<(all?: boolean) => void>(() => {});
|
||||
/** 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 order = [...cols.keys()].sort((a, b) => a - b);
|
||||
|
||||
/**
|
||||
* Mark how far each pane is covered by the next. Any overlap gives the upper pane a shadow edge
|
||||
* (data-over); once too little of the pane is left to read its own heading, it shows as a spine
|
||||
* with its title (data-covered). A pane's forks all start at the same column.
|
||||
* 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.
|
||||
*/
|
||||
const layout = (all = false) => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
const colEls = [...el.children].filter((c): c is HTMLElement => c.classList.contains("col"));
|
||||
if (!colEls.length) return;
|
||||
clearTimeout(later.current);
|
||||
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;
|
||||
});
|
||||
for (const c of colEls) {
|
||||
const ps = [...c.children] as HTMLElement[];
|
||||
if (ps.length < 2) {
|
||||
for (const p of ps) {
|
||||
setAttr(p, "data-tab", false);
|
||||
if (p.style.height) (p.style.height = ""), (p.style.flex = "");
|
||||
}
|
||||
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 tids = ps.map((p) => Number(p.dataset.tid));
|
||||
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;
|
||||
});
|
||||
const pinned = ps.map((p) => p.classList.contains("pinned"));
|
||||
const fits = 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]));
|
||||
}
|
||||
// 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.
|
||||
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;
|
||||
}
|
||||
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");
|
||||
});
|
||||
}
|
||||
// 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);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
const measure = () => {
|
||||
const el = strip.current;
|
||||
const t = store.tree;
|
||||
if (!el || !t) return;
|
||||
const els = paneEls(el);
|
||||
const first = els.get(t.id);
|
||||
if (!first) return;
|
||||
const w = first.offsetWidth;
|
||||
const marks: [HTMLElement, number, HTMLElement[]][] = [];
|
||||
const visit = (n: PaneNode) => {
|
||||
const e = els.get(n.id);
|
||||
if (!e) return;
|
||||
const kids = n.kids.flatMap((k) => els.get(k.id) ?? []);
|
||||
const next = els.get(n.kids[n.pick]?.id) ?? kids[0];
|
||||
marks.push([e, next ? next.getBoundingClientRect().left - e.getBoundingClientRect().left : w, kids]);
|
||||
n.kids.forEach(visit);
|
||||
};
|
||||
visit(t);
|
||||
for (const [e, visible, kids] of marks) {
|
||||
setAttr(e, "data-covered", visible < w * 0.4);
|
||||
for (const k of kids) setAttr(k, "data-over", visible < w - 1);
|
||||
}
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Keep the focus in view. Vertically, the pane holding the focus scrolls to its focused row,
|
||||
* selection or link. Horizontally, the strip scrolls as little as it can so that pane is fully
|
||||
* visible and, when there is room, so is the pane beside it: for a row whose pane is showing,
|
||||
* that pane; otherwise the pane before. With forks, the strip also scrolls down or up as little
|
||||
* as it can to show the focused branch's 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.
|
||||
*/
|
||||
const follow = () => {
|
||||
const el = strip.current;
|
||||
@@ -250,7 +409,7 @@ export function Panes() {
|
||||
const f = store.focus;
|
||||
const at = store.paneAt;
|
||||
const nodes = store.branchNodes;
|
||||
const key = `${f.node}|${f.grain}|${f.range?.join()}|${JSON.stringify(store.aux)}|${at}|${nodes.map((n) => n.id).join(",")}|${el.clientWidth}|${el.clientHeight}|${store.mode === "edit"}`;
|
||||
const key = `${f.node}|${f.grain}|${f.range?.join()}|${JSON.stringify(store.aux)}|${at}|${nodes.map((n) => n.id).join(",")}|${el.clientWidth}|${el.clientHeight}|${store.mode === "edit"}|${lefts.current.join(",")}`;
|
||||
if (key === followed.current) return;
|
||||
followed.current = key;
|
||||
const els = paneEls(el);
|
||||
@@ -263,99 +422,280 @@ export function Panes() {
|
||||
const pane = panes[at];
|
||||
nearestY(pane?.querySelector(".sel, .wfocus, .node.focused > .row, .wrow.focused > .row, .backlinks li.focused, .target-row.focused, .wiki-head.focused, .pane-head.focused, .focused"));
|
||||
}
|
||||
const w = panes[0].offsetWidth;
|
||||
const spine = (panes[0].querySelector(".spine") as HTMLElement | null)?.offsetWidth ?? 0;
|
||||
const colEls = [...el.querySelectorAll<HTMLElement>(":scope > .col")];
|
||||
const colOf = (p: HTMLElement | undefined) => (p ? colEls.indexOf(p.parentElement as HTMLElement) : -1);
|
||||
const w = colEls[0].offsetWidth;
|
||||
const view = el.clientWidth;
|
||||
const b = Math.min(panes.length - 1, showing ? at + 1 : at);
|
||||
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;
|
||||
// Pane i starts at i·w. It is uncovered while scrollLeft ≤ i·(w − spine), and its right edge is in view while scrollLeft ≥ (i+1)·w − view.
|
||||
// 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 - spine)) a = b;
|
||||
const hi = a * (w - spine);
|
||||
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)));
|
||||
// The row the branch ends in holds every pane of the branch (a pane with forks stays at the top while its rows scroll).
|
||||
let top = el.scrollTop;
|
||||
const row = panes[panes.length - 1].closest<HTMLElement>(".fork");
|
||||
if (row) {
|
||||
const r = row.getBoundingClientRect();
|
||||
const c = el.getBoundingClientRect().top;
|
||||
if (r.top < c) top += r.top - c;
|
||||
else if (r.bottom > c + el.clientHeight) top += Math.min(r.bottom - c - el.clientHeight, r.top - c);
|
||||
}
|
||||
// Down or up to another row at once: a smooth scroll that way repaints every row's panes on each frame, which costs frames on a slow machine.
|
||||
if (Math.abs(top - el.scrollTop) > 1) el.scrollTop = top;
|
||||
if (Math.abs(target - el.scrollLeft) > 1) el.scrollTo({ left: target, behavior: reducedMotion() ? "auto" : "smooth" });
|
||||
};
|
||||
|
||||
/** The rows' sizes follow the strip's height; whether there is room for rows at all, its size and a pane's width. */
|
||||
const size = () => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
el.style.setProperty("--strip-h", `${el.clientHeight}px`);
|
||||
el.style.setProperty("--row-min", `${rowMin(el.clientHeight)}px`);
|
||||
const pane = el.querySelector<HTMLElement>(".pane")?.offsetWidth ?? 0;
|
||||
setRoom(roomy(el.clientWidth, el.clientHeight, pane));
|
||||
/** Draw the curves on the next frame (after the layout this frame settles). */
|
||||
const schedule = () => {
|
||||
if (!frame.current)
|
||||
frame.current = requestAnimationFrame(() => {
|
||||
frame.current = 0;
|
||||
curves(strip.current, svg.current);
|
||||
});
|
||||
};
|
||||
|
||||
latest.current = layout;
|
||||
useLayoutEffect(() => {
|
||||
layout();
|
||||
follow();
|
||||
measure();
|
||||
schedule();
|
||||
});
|
||||
|
||||
useLayoutEffect(size, []);
|
||||
|
||||
useEffect(() => {
|
||||
const el = strip.current!;
|
||||
let frame = 0;
|
||||
const onScroll = () => {
|
||||
if (!frame) frame = requestAnimationFrame(() => ((frame = 0), measure()));
|
||||
const wrap = el.parentElement!;
|
||||
const onScroll = (e: Event) => {
|
||||
if (e.target === el) measure();
|
||||
schedule();
|
||||
};
|
||||
const onResize = () => {
|
||||
size();
|
||||
latest.current(true);
|
||||
followed.current = "";
|
||||
follow();
|
||||
measure();
|
||||
schedule();
|
||||
};
|
||||
el.addEventListener("scroll", onScroll, { passive: true });
|
||||
// The strip changes width with the window and when the history panel opens or closes.
|
||||
// Panes 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);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
el.removeEventListener("scroll", onScroll);
|
||||
cancelAnimationFrame(frame.current);
|
||||
clearTimeout(later.current);
|
||||
wrap.removeEventListener("scroll", onScroll, { capture: true });
|
||||
sizes.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const onBranch = new Set(store.branchNodes.map((n) => n.id));
|
||||
/**
|
||||
* A pane and what is right of it. A plain trail is a flat run of panes, as before; to the right of
|
||||
* a pane with forks, a stack of rows, one per fork in the order they were opened, each holding
|
||||
* that fork's panes (and perhaps a stack of its own). Without room for rows, only the picked fork.
|
||||
*/
|
||||
const draw = (t: PaneNode, depth: number, parent?: PaneRef, forkOf?: [number, number]): ComponentChildren[] => {
|
||||
const off = !onBranch.has(t.id);
|
||||
const active = !off && store.paneAt === depth;
|
||||
const out: ComponentChildren[] = [
|
||||
<Pane key={t.id} t={t} p={t.ref} parent={parent} index={depth} kids={kidsKey(t)} off={off} forkOf={forkOf} active={active} aux={active ? store.aux : null} />,
|
||||
];
|
||||
if (!t.kids.length) return out;
|
||||
if (t.kids.length === 1 || !rows) return [...out, ...draw(t.kids[t.pick], depth + 1, t.ref, t.kids.length > 1 ? [t.pick, t.kids.length] : undefined)];
|
||||
out.push(
|
||||
<div key={`f${t.id}`} class="forks" style={`--leaves:${leaves(t)}`}>
|
||||
{t.kids.map((k) => (
|
||||
<div key={k.id} class={`fork${onBranch.has(k.id) ? " on" : ""}`} style={`--leaves:${leaves(k)}`}>
|
||||
{draw(k, depth + 1, t.ref)}
|
||||
</div>
|
||||
))}
|
||||
</div>,
|
||||
);
|
||||
return out;
|
||||
};
|
||||
|
||||
return (
|
||||
<div class={`strip${rows ? " forked" : ""}`} ref={strip}>
|
||||
{tree && draw(tree, 0)}
|
||||
<div class="panes">
|
||||
<div class="strip" ref={strip}>
|
||||
{order.map((c) => {
|
||||
const items = cols.get(c)!;
|
||||
return (
|
||||
<div key={c} class={`col${items.length > 1 ? " split" : ""}`} data-col={c} data-pinned={items.some((x) => x.node.pinned) || undefined}>
|
||||
{items.map((x) => {
|
||||
const off = !onBranch.has(x.node.id);
|
||||
const active = x.node.id === activeId;
|
||||
return (
|
||||
<Pane
|
||||
key={x.node.id}
|
||||
t={x.node}
|
||||
p={x.node.ref}
|
||||
parent={x.parent?.ref}
|
||||
index={x.depth}
|
||||
kids={kidsKey(x.node)}
|
||||
off={off}
|
||||
active={active}
|
||||
aux={active ? store.aux : null}
|
||||
root={x.ti === 0 && x.depth === 0}
|
||||
orphan={x.ti > 0 && x.depth === 0}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<svg class="curves" ref={svg} aria-hidden="true" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** One curve, measured: where it leaves its source (y, and x where the lead-out starts), the edge of the source's text, where it arrives, and the gutter it runs down. */
|
||||
interface Edge {
|
||||
from: number;
|
||||
to: number;
|
||||
/** The child's column: the gutter, just inside its left edge. */
|
||||
gutter: number;
|
||||
left: number;
|
||||
sx: number;
|
||||
sy: number;
|
||||
/** For words: the right end of their underline, which a short step joins to the lead-out. */
|
||||
under?: { x: number; y: number };
|
||||
textRight: number;
|
||||
ex: number;
|
||||
ey: number;
|
||||
on: boolean;
|
||||
lost: boolean;
|
||||
}
|
||||
|
||||
/** A font's descent, by its CSS font string: where its baseline sits above the bottom of an inline box. */
|
||||
const descents = new Map<string, number>();
|
||||
let measurer: CanvasRenderingContext2D | null | undefined;
|
||||
/** Where the underline of linked or annotated words runs, given their last line's box: a link's under the baseline by its offset; a note's dotted rule at the box's foot. */
|
||||
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);
|
||||
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);
|
||||
}
|
||||
const off = parseFloat(cs.textUnderlineOffset);
|
||||
return r.bottom - d + (Number.isFinite(off) ? off : 0.1 * fs) + 0.5;
|
||||
}
|
||||
|
||||
/** Where a curve arrives, from its column's left edge: just short of the title. */
|
||||
const ARRIVE = 36;
|
||||
|
||||
/** The lane order last used in each gutter, by the curves' keys. */
|
||||
const lanesUsed = new Map<number, string[]>();
|
||||
|
||||
/**
|
||||
* The curves: one per pane opened from another, from what it was opened from to its title. A
|
||||
* curve leaves its source sideways, through the gap under the line (an extended
|
||||
* underline, for words) to the edge of the text, turns into a lane of the gutter just inside the
|
||||
* next column, and turns again into the child's title. Curves through one gutter run side by side
|
||||
* in lanes, like a ribbon cable, ordered so they cross as little as they can; past the lanes there
|
||||
* is room for, the rest share the outermost. On the focused branch a curve is drawn in a stronger
|
||||
* ink, last. A source scrolled out of its pane, folded into a tab or under the next column is held
|
||||
* at the pane's edge and the curve dotted; a curve into or out of a column covered down to its
|
||||
* spines is not drawn.
|
||||
*/
|
||||
function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
if (!el || !svg) return;
|
||||
if (!store.settings.curves) {
|
||||
if (svg.firstChild) svg.replaceChildren();
|
||||
return;
|
||||
}
|
||||
const box = svg.getBoundingClientRect();
|
||||
const els = paneEls(el);
|
||||
const colEls = [...el.children] as HTMLElement[];
|
||||
const branch = new Set(store.branchNodes.map((n) => n.id));
|
||||
const edges: Edge[] = [];
|
||||
for (const x of store.panesPlaced) {
|
||||
const parent = x.parent;
|
||||
if (!parent) continue;
|
||||
const pe = els.get(parent.id);
|
||||
const ce = els.get(x.node.id);
|
||||
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 cbox = ce.getBoundingClientRect();
|
||||
let ey: number;
|
||||
if (ce.hasAttribute("data-tab")) 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;
|
||||
}
|
||||
// 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")) {
|
||||
sy = pbox.top + TAB / 2;
|
||||
lost = true;
|
||||
} else {
|
||||
const sc = pe.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
const cands = pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`);
|
||||
let src: HTMLElement | undefined;
|
||||
for (const c of cands) {
|
||||
const r = c.getBoundingClientRect();
|
||||
if (r.height && r.bottom > sc.top && r.top < sc.bottom) {
|
||||
src = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
src ??= cands[0];
|
||||
const head = pe.querySelector<HTMLElement>(".pane-head h2, .top h1, .wiki-head h2");
|
||||
const s = src ?? head;
|
||||
if (!s) continue;
|
||||
const row = s.matches("li") ? s.querySelector<HTMLElement>(":scope > .row") : null;
|
||||
const rects = (row ?? s).getClientRects();
|
||||
const r = rects[rects.length - 1] ?? (row ?? s).getBoundingClientRect();
|
||||
if (row || s === head) {
|
||||
// A row is left from its right end, mid-height.
|
||||
sy = r.top + r.height / 2;
|
||||
sx = Math.min(r.right + 4, textRight);
|
||||
} else {
|
||||
// Words: from just under their last line, in the gap before the next, joined by a short step to the end of their underline.
|
||||
sy = r.bottom + 1;
|
||||
const uy = underline(s, r);
|
||||
const j = Math.max(2, sy - uy);
|
||||
under = { x: r.right, y: uy };
|
||||
sx = r.right + 2 * j;
|
||||
}
|
||||
if (sy < sc.top + 2 || sy > sc.bottom - 2 || sx > textRight + 1) {
|
||||
lost = true;
|
||||
under = undefined;
|
||||
sx = textRight;
|
||||
sy = Math.max(sc.top + 2, Math.min(sc.bottom - 2, sy));
|
||||
}
|
||||
}
|
||||
const gutter = colEls.indexOf(ccol);
|
||||
edges.push({ from: parent.id, to: x.node.id, gutter, left: left - box.left, sx: sx - box.left, sy: sy - box.top, under: under && { x: under.x - box.left, y: under.y - box.top }, textRight: textRight - box.left, ex: left + ARRIVE - box.left, ey: ey - box.top, on: branch.has(x.node.id) && branch.has(parent.id), lost });
|
||||
}
|
||||
// Lanes, gutter by gutter.
|
||||
const lane = new Map<Edge, number>();
|
||||
const gutters = new Map<number, Edge[]>();
|
||||
for (const e of edges) gutters.set(e.gutter, [...(gutters.get(e.gutter) ?? []), e]);
|
||||
for (const [g, es] of gutters) {
|
||||
const keyed = es.map((e) => ({ e, key: `${e.from}>${e.to}`, sy: e.sy, ey: e.ey }));
|
||||
const order = laneOrder(keyed, lanesUsed.get(g));
|
||||
lanesUsed.set(
|
||||
g,
|
||||
order.map((o) => o.key),
|
||||
);
|
||||
order.forEach((o, i) => lane.set(o.e, Math.min(i, LANES - 1)));
|
||||
}
|
||||
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[] = [];
|
||||
edges.sort((a, b) => Number(a.on) - Number(b.on));
|
||||
for (const e of edges) {
|
||||
const i = lane.get(e)!;
|
||||
// Lane 0 is nearest the panes, the last nearest the column's edge.
|
||||
const g = e.left + LANE_LAST - i * LANE_PITCH;
|
||||
const dy = e.ey - e.sy;
|
||||
let d: string;
|
||||
const join = e.under ? `M${fx(e.under.x)} ${fx(e.under.y)}C${fx((e.under.x + e.sx) / 2)} ${fx(e.under.y)} ${fx((e.under.x + e.sx) / 2)} ${fx(e.sy)} ${fx(e.sx)} ${fx(e.sy)}` : `M${fx(e.sx)} ${fx(e.sy)}`;
|
||||
if (Math.abs(dy) < 1.5) d = `${join}H${fx(e.ex)}`;
|
||||
else {
|
||||
// A lead-out to the lane, a quarter turn, the lane, a quarter turn into the title. Each turn's radius grows by a pitch per lane outwards, so a bundle turning together stays parallel; a turn never starts inside the text.
|
||||
const sg = Math.sign(dy);
|
||||
const r1 = Math.max(1, Math.min(Math.abs(dy) / 2, g - Math.max(e.sx, e.textRight), 8 + (LANE_LAST - LANE_FIRST) - i * LANE_PITCH));
|
||||
const r2 = Math.max(1, Math.min(Math.abs(dy) / 2, e.ex - g - 1));
|
||||
const k = 0.552;
|
||||
d =
|
||||
`${join}H${fx(g - r1)}` +
|
||||
`C${fx(g - r1 + k * r1)} ${fx(e.sy)} ${fx(g)} ${fx(e.sy + sg * r1 * (1 - k))} ${fx(g)} ${fx(e.sy + sg * r1)}` +
|
||||
`V${fx(e.ey - sg * r2)}` +
|
||||
`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}"/>`);
|
||||
}
|
||||
const html = out.join("");
|
||||
if (svg.innerHTML !== html) svg.innerHTML = html;
|
||||
}
|
||||
+2
-2
@@ -214,7 +214,7 @@ export function WikiView({ host }: { host: string }) {
|
||||
const v = art.value;
|
||||
const sec = h.sec ? v.sections.find((x) => x.id === h.sec) : undefined;
|
||||
// A section open as a pane to the right is marked: the picked child "showing", another fork "forked".
|
||||
const showing = (id: number) => (store.panes ? store.kidMark(tid, (r) => r.kind === "wiki" && r.title === h.title && r.sec === id) : undefined);
|
||||
const showing = (id: number): string | undefined => (store.panes ? store.kidMark(tid, (r) => r.kind === "wiki" && r.title === h.title && r.sec === id) : undefined);
|
||||
return (
|
||||
<section class={`wiki${embedded ? " embedded" : ""}`} data-host={host}>
|
||||
<Head title={v.title} sub={sec?.heading} focused={at({ t: "head" })} />
|
||||
@@ -229,7 +229,7 @@ export function WikiView({ host }: { host: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
function Rows(props: { article: Article; host: string; lang: string; parent: number; nested: boolean; at: (r: WRow) => boolean; showing: (id: number) => "showing" | "forked" | undefined }) {
|
||||
function Rows(props: { article: Article; host: string; lang: string; parent: number; nested: boolean; at: (r: WRow) => boolean; showing: (id: number) => string | undefined }) {
|
||||
const { article: v, host, lang, parent, nested, at, showing } = props;
|
||||
const kids = sectionsUnder(v, parent);
|
||||
if (!kids.length) return null;
|
||||
|
||||
+259
-111
@@ -1,13 +1,17 @@
|
||||
/**
|
||||
* The panes view's panes as a tree. Each pane may have several children ("forks"), each of which
|
||||
* continues its own trail to the right and may fork again. Every node remembers which child is
|
||||
* picked; following the picks from the root gives the focused branch, the trail the keys move along
|
||||
* (`store.trail`), so there is always exactly one. A plain trail is the tree with one child
|
||||
* everywhere.
|
||||
* The panes view's panes as a forest. Each pane may have several children ("forks"), each of which
|
||||
* continues its own trail to the right and may fork again; a pane's column is its depth. The first
|
||||
* tree starts at the top node; the others are orphans: pinned panes that stayed open when a pane
|
||||
* they were opened from closed, each keeping the column it was in.
|
||||
*
|
||||
* Every node remembers which child is picked; following the picks from the root of the focused
|
||||
* tree gives the focused branch, the trail the keys move along (`store.trail`), so there is always
|
||||
* exactly one. A plain trail is one tree with one child everywhere.
|
||||
*
|
||||
* Pure functions on immutable trees: an operation copies the path it changes and shares the rest,
|
||||
* so a tree that did not change is the same object (the store memoises on identity). A node's `id`
|
||||
* names the pane for as long as it is open (keys, the hosts of article panes off the branch).
|
||||
* so a forest that did not change is the same object (the store memoises on identity). A node's
|
||||
* `id` names the pane for as long as it is open (keys, curves, the hosts of article panes off the
|
||||
* branch).
|
||||
*/
|
||||
|
||||
export interface Tree<R, S = unknown> {
|
||||
@@ -16,8 +20,18 @@ export interface Tree<R, S = unknown> {
|
||||
/** Which child the branch goes on to (0 with none): the focused one, or the one last focused. */
|
||||
pick: number;
|
||||
id: number;
|
||||
/** Where the reader was when they last left this fork (to come back to). */
|
||||
/** Where the reader was when they last left this pane by [ or ] (to come back to). */
|
||||
seen?: S;
|
||||
/** Pinned: stays open when a pane it was opened from closes, is never replaced by a plain open, and never collapses. */
|
||||
pinned?: boolean;
|
||||
/** On the root of an orphan: the column it stays in. */
|
||||
col?: number;
|
||||
}
|
||||
|
||||
/** The trees, the first starting at the top node; `at` is the one the focused branch is in. */
|
||||
export interface Forest<R, S = unknown> {
|
||||
trees: Tree<R, S>[];
|
||||
at: number;
|
||||
}
|
||||
|
||||
export type Same<R> = (a: R, b: R) => boolean;
|
||||
@@ -32,14 +46,26 @@ export function chain<R, S>(refs: R[]): Tree<R, S> | null {
|
||||
return t;
|
||||
}
|
||||
|
||||
/** The nodes of the focused branch, from the root. */
|
||||
/** A forest of one tree (none for no refs). */
|
||||
export const plain = <R, S>(refs: R[]): Forest<R, S> => {
|
||||
const t = chain<R, S>(refs);
|
||||
return { trees: t ? [t] : [], at: 0 };
|
||||
};
|
||||
|
||||
/** The column a tree's root is in. */
|
||||
export const colOf = (t: Tree<unknown, unknown>) => t.col ?? 0;
|
||||
|
||||
/** The focused tree. */
|
||||
export const focused = <R, S>(f: Forest<R, S>): Tree<R, S> | null => f.trees[f.at] ?? null;
|
||||
|
||||
/** The nodes of a tree's focused branch, from the root. */
|
||||
export function path<R, S>(t: Tree<R, S> | null): Tree<R, S>[] {
|
||||
const out: Tree<R, S>[] = [];
|
||||
for (let n: Tree<R, S> | undefined = t ?? undefined; n; n = n.kids[n.pick]) out.push(n);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Replace the node at depth i of the focused branch with f(node), copying the path above it. */
|
||||
/** Replace the node at depth i of a tree's focused branch with f(node), copying the path above it. */
|
||||
function at<R, S>(t: Tree<R, S>, i: number, f: (n: Tree<R, S>) => Tree<R, S>): Tree<R, S> {
|
||||
if (i <= 0) return f(t);
|
||||
const kid = t.kids[t.pick];
|
||||
@@ -49,7 +75,7 @@ function at<R, S>(t: Tree<R, S>, i: number, f: (n: Tree<R, S>) => Tree<R, S>): T
|
||||
return { ...t, kids };
|
||||
}
|
||||
|
||||
/** The path of nodes from the root to the node with this id, or null. */
|
||||
/** The path of nodes from a tree's root to the node with this id, or null. */
|
||||
export function trace<R, S>(t: Tree<R, S> | null, id: number): Tree<R, S>[] | null {
|
||||
if (!t) return null;
|
||||
if (t.id === id) return [t];
|
||||
@@ -60,17 +86,34 @@ export function trace<R, S>(t: Tree<R, S> | null, id: number): Tree<R, S>[] | nu
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Every node, depth first, top row first, with its depth (its column). */
|
||||
export function all<R, S>(t: Tree<R, S> | null, depth = 0, out: { node: Tree<R, S>; depth: number }[] = []) {
|
||||
if (!t) return out;
|
||||
out.push({ node: t, depth });
|
||||
for (const k of t.kids) all(k, depth + 1, out);
|
||||
return out;
|
||||
/** Where a pane is: its tree, and the path to it from that tree's root. */
|
||||
export function find<R, S>(f: Forest<R, S>, id: number): { ti: number; path: Tree<R, S>[] } | null {
|
||||
for (let ti = 0; ti < f.trees.length; ti++) {
|
||||
const p = trace(f.trees[ti], id);
|
||||
if (p) return { ti, path: p };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** How many leaves (rows at the far right) a subtree has. */
|
||||
export function leaves<R, S>(t: Tree<R, S>): number {
|
||||
return t.kids.length ? t.kids.reduce((n, k) => n + leaves(k), 0) : 1;
|
||||
export interface Placed<R, S> {
|
||||
node: Tree<R, S>;
|
||||
/** Its depth in its own tree (its place on that tree's branch, when the tree is focused). */
|
||||
depth: number;
|
||||
/** Its column on screen. */
|
||||
col: number;
|
||||
ti: number;
|
||||
parent?: Tree<R, S>;
|
||||
}
|
||||
|
||||
/** Every pane, tree by tree, depth first, earlier forks first: the order panes stand in a column, top to bottom. */
|
||||
export function all<R, S>(f: Forest<R, S>): Placed<R, S>[] {
|
||||
const out: Placed<R, S>[] = [];
|
||||
const go = (node: Tree<R, S>, depth: number, col: number, ti: number, parent?: Tree<R, S>) => {
|
||||
out.push({ node, depth, col, ti, parent });
|
||||
for (const k of node.kids) go(k, depth + 1, col + 1, ti, node);
|
||||
};
|
||||
f.trees.forEach((t, ti) => go(t, 0, colOf(t), ti));
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Change the node with this id, copying the path to it. */
|
||||
@@ -85,50 +128,15 @@ export function update<R, S>(t: Tree<R, S>, id: number, f: (n: Tree<R, S>) => Tr
|
||||
return changed ? { ...t, kids } : t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open something to the right of pane i of the focused branch. If it is already open there (as any
|
||||
* of the forks) that fork is picked and kept as it is. Otherwise a fork adds a child below the
|
||||
* others; a plain open replaces the picked child (and everything right of it), or adds the first.
|
||||
*/
|
||||
export function open<R, S>(t: Tree<R, S>, i: number, ref: R, fork: boolean, same: Same<R>): Tree<R, S> {
|
||||
return at(t, i, (n) => {
|
||||
const k = n.kids.findIndex((c) => same(c.ref, ref));
|
||||
if (k >= 0) return k === n.pick ? n : { ...n, pick: k };
|
||||
if (!n.kids.length) return { ...n, kids: [leaf(ref)], pick: 0 };
|
||||
if (fork) return { ...n, kids: [...n.kids, leaf(ref)], pick: n.kids.length };
|
||||
const kids = n.kids.slice();
|
||||
kids[n.pick] = leaf(ref);
|
||||
return { ...n, kids };
|
||||
});
|
||||
/** Change the node with this id, in whichever tree it is. */
|
||||
export function updateIn<R, S>(f: Forest<R, S>, id: number, fn: (n: Tree<R, S>) => Tree<R, S>): Forest<R, S> {
|
||||
const hit = find(f, id);
|
||||
if (!hit) return f;
|
||||
const t = update(f.trees[hit.ti], id, fn);
|
||||
return t === f.trees[hit.ti] ? f : { ...f, trees: f.trees.map((x, j) => (j === hit.ti ? t : x)) };
|
||||
}
|
||||
|
||||
/** Close everything right of pane i of the focused branch, every fork of it included. */
|
||||
export function closeRight<R, S>(t: Tree<R, S>, i: number): Tree<R, S> {
|
||||
return at(t, i, (n) => (n.kids.length ? { ...n, kids: [], pick: 0 } : n));
|
||||
}
|
||||
|
||||
/** Remove a child of a node, picking the one that takes its place (the one below, else the one above). */
|
||||
function dropKid<R, S>(n: Tree<R, S>, k: number): Tree<R, S> {
|
||||
const kids = n.kids.filter((_, j) => j !== k);
|
||||
const pick = k < n.pick ? n.pick - 1 : Math.max(0, Math.min(n.pick, kids.length - 1));
|
||||
return { ...n, kids, pick };
|
||||
}
|
||||
|
||||
/** Close pane i of the focused branch (i ≥ 1) and everything right of it. Its siblings stay. */
|
||||
export function closeAt<R, S>(t: Tree<R, S>, i: number): Tree<R, S> {
|
||||
if (i < 1) return t;
|
||||
return at(t, i - 1, (n) => (n.kids.length ? dropKid(n, n.pick) : n));
|
||||
}
|
||||
|
||||
/** Close the child of pane i of the focused branch that shows this (whichever fork it is). */
|
||||
export function closeChild<R, S>(t: Tree<R, S>, i: number, ref: R, same: Same<R>): Tree<R, S> {
|
||||
return at(t, i, (n) => {
|
||||
const k = n.kids.findIndex((c) => same(c.ref, ref));
|
||||
return k < 0 ? n : dropKid(n, k);
|
||||
});
|
||||
}
|
||||
|
||||
/** Make the node with this id lie on the focused branch (its own picks below it kept). */
|
||||
/** Make the node with this id lie on its tree's focused branch (its own picks below it kept). */
|
||||
export function select<R, S>(t: Tree<R, S>, id: number): Tree<R, S> | null {
|
||||
if (t.id === id) return t;
|
||||
for (let k = 0; k < t.kids.length; k++) {
|
||||
@@ -138,72 +146,196 @@ export function select<R, S>(t: Tree<R, S>, id: number): Tree<R, S> | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The fork above (delta −1) or below (+1) the focused branch, in the order the rows are drawn: from
|
||||
* the branch's last pane leftwards, the nearest pane with a sibling in that direction. Returns the
|
||||
* tree with that sibling picked and the depth it is at, or null at the top or bottom.
|
||||
*/
|
||||
export function sibling<R, S>(t: Tree<R, S>, delta: number): { tree: Tree<R, S>; depth: number } | null {
|
||||
const p = path(t);
|
||||
for (let d = p.length - 1; d >= 1; d--) {
|
||||
const parent = p[d - 1];
|
||||
const k = parent.pick + delta;
|
||||
if (k >= 0 && k < parent.kids.length) return { tree: at(t, d - 1, (n) => ({ ...n, pick: k })), depth: d };
|
||||
}
|
||||
return null;
|
||||
/** Make the pane with this id lie on the focused branch: its tree focused, and picked down to it. */
|
||||
export function focus<R, S>(f: Forest<R, S>, id: number): Forest<R, S> {
|
||||
const hit = find(f, id);
|
||||
if (!hit) return f;
|
||||
const t = select(f.trees[hit.ti], id)!;
|
||||
if (t === f.trees[hit.ti] && hit.ti === f.at) return f;
|
||||
return { trees: t === f.trees[hit.ti] ? f.trees : f.trees.map((x, j) => (j === hit.ti ? t : x)), at: hit.ti };
|
||||
}
|
||||
|
||||
/** Drop every pane whose ref fails `keep` (with everything right of it). Null if the root goes. Unchanged trees are returned as they are. */
|
||||
export function prune<R, S>(t: Tree<R, S> | null, keep: (r: R) => boolean): Tree<R, S> | null {
|
||||
if (!t || !keep(t.ref)) return null;
|
||||
let changed = false;
|
||||
// The picked child, or the one that takes its place: as many kept children before it.
|
||||
let pick = 0;
|
||||
const kids: Tree<R, S>[] = [];
|
||||
t.kids.forEach((k, j) => {
|
||||
const p = prune(k, keep);
|
||||
if (p !== k) changed = true;
|
||||
if (p) kids.push(p);
|
||||
if (j === t.pick) pick = kids.length - (p ? 1 : 0);
|
||||
/**
|
||||
* What stays open when a pane closes: the pinned panes inside it (topmost first, each with what it
|
||||
* opened), as orphans in the columns they were in. `self`: whether the pane itself may stay.
|
||||
*/
|
||||
function survivors<R, S>(n: Tree<R, S>, col: number, self: boolean): Tree<R, S>[] {
|
||||
if (self && n.pinned) return [{ ...n, col }];
|
||||
return n.kids.flatMap((k) => survivors(k, col + 1, true));
|
||||
}
|
||||
|
||||
/** Put a tree in place of tree ti (null removes it), with orphans right after it. The focused tree stays focused. */
|
||||
function replace<R, S>(f: Forest<R, S>, ti: number, t: Tree<R, S> | null, orphans: Tree<R, S>[]): Forest<R, S> {
|
||||
if (t === f.trees[ti] && !orphans.length) return f;
|
||||
const trees = [...f.trees.slice(0, ti), ...(t ? [t] : []), ...orphans, ...f.trees.slice(ti + 1)];
|
||||
const was = f.trees[f.at];
|
||||
const at = trees.indexOf(was);
|
||||
return { trees, at: at >= 0 ? at : Math.min(ti, trees.length - 1) };
|
||||
}
|
||||
|
||||
/** Remove a child of a node, picking the one that takes its place (the one below, else the one above). */
|
||||
function dropKid<R, S>(n: Tree<R, S>, k: number): Tree<R, S> {
|
||||
const kids = n.kids.filter((_, j) => j !== k);
|
||||
const pick = k < n.pick ? n.pick - 1 : Math.max(0, Math.min(n.pick, kids.length - 1));
|
||||
return { ...n, kids, pick };
|
||||
}
|
||||
|
||||
/**
|
||||
* Open something to the right of pane i of the focused branch. If it is already open there (as any
|
||||
* of the forks) that fork is picked and kept as it is. Otherwise a fork adds a child below the
|
||||
* others; a plain open replaces the picked child (and everything right of it), or adds the first.
|
||||
* A pinned child is never replaced: a plain open beside it is a fork. Pinned panes in what is
|
||||
* replaced stay, as orphans.
|
||||
*/
|
||||
export function open<R, S>(f: Forest<R, S>, i: number, ref: R, fork: boolean, same: Same<R>): Forest<R, S> {
|
||||
const t = focused(f);
|
||||
if (!t) return plain([ref]);
|
||||
const orphans: Tree<R, S>[] = [];
|
||||
const next = at(t, i, (n) => {
|
||||
const k = n.kids.findIndex((c) => same(c.ref, ref));
|
||||
if (k >= 0) return k === n.pick ? n : { ...n, pick: k };
|
||||
if (!n.kids.length) return { ...n, kids: [leaf(ref)], pick: 0 };
|
||||
if (fork || n.kids[n.pick].pinned) return { ...n, kids: [...n.kids, leaf(ref)], pick: n.kids.length };
|
||||
orphans.push(...survivors(n.kids[n.pick], colOf(t) + i + 1, true));
|
||||
const kids = n.kids.slice();
|
||||
kids[n.pick] = leaf(ref);
|
||||
return { ...n, kids };
|
||||
});
|
||||
if (!changed) return t;
|
||||
return { ...t, kids, pick: Math.max(0, Math.min(pick, kids.length - 1)) };
|
||||
return replace(f, f.at, next, orphans);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the focused branch this list of refs, keeping every pane that is already on the way: where a
|
||||
* ref is already a child it is picked; where it is not, the picked child is replaced by the rest of
|
||||
* the list. Panes right of the list's end close. A different root starts again.
|
||||
* Close a pane and everything opened from it, except pinned panes, which stay where they are as
|
||||
* orphans (with what they opened). The first tree's root never closes. `active` is the pane the keys
|
||||
* act on; returned is the forest, with the active pane on its focused branch, and that pane: the
|
||||
* same one if it is still open, else the closed pane's parent, else (for an orphan's root) the
|
||||
* nearest pane of the tree before it.
|
||||
*/
|
||||
export function withBranch<R, S>(t: Tree<R, S> | null, refs: R[], same: Same<R>): Tree<R, S> | null {
|
||||
if (!refs.length) return null;
|
||||
if (!t || !same(t.ref, refs[0])) return chain(refs);
|
||||
export function close<R, S>(f: Forest<R, S>, id: number, active: number): { forest: Forest<R, S>; active: number } {
|
||||
const hit = find(f, id);
|
||||
if (!hit || (hit.ti === 0 && hit.path.length === 1 && !f.trees[0].col)) return { forest: f, active };
|
||||
const t = f.trees[hit.ti];
|
||||
const node = hit.path[hit.path.length - 1];
|
||||
const col = colOf(t) + hit.path.length - 1;
|
||||
const orphans = survivors(node, col, false);
|
||||
let g: Forest<R, S>;
|
||||
let fallback: number;
|
||||
if (hit.path.length === 1) {
|
||||
g = replace(f, hit.ti, null, orphans);
|
||||
const before = g.trees[Math.max(0, hit.ti - 1)];
|
||||
const p = path(before);
|
||||
fallback = p[Math.max(0, Math.min(p.length - 1, col - 1 - colOf(before)))].id;
|
||||
} else {
|
||||
const parent = hit.path[hit.path.length - 2];
|
||||
g = replace(f, hit.ti, update(t, parent.id, (n) => dropKid(n, n.kids.indexOf(node))), orphans);
|
||||
fallback = parent.id;
|
||||
}
|
||||
const still = find(g, active) ? active : fallback;
|
||||
return { forest: focus(g, still), active: still };
|
||||
}
|
||||
|
||||
/** Pin or unpin a pane. */
|
||||
export const pin = <R, S>(f: Forest<R, S>, id: number, on: boolean): Forest<R, S> => updateIn(f, id, (n) => (!!n.pinned === on ? n : { ...n, pinned: on || undefined }));
|
||||
|
||||
/** The pane above (−1) or below (+1) this one in its column, or null at the top or bottom. */
|
||||
export function besideInColumn<R, S>(f: Forest<R, S>, id: number, delta: number): number | null {
|
||||
const placed = all(f);
|
||||
const me = placed.find((x) => x.node.id === id);
|
||||
if (!me) return null;
|
||||
const col = placed.filter((x) => x.col === me.col);
|
||||
return col[col.indexOf(me) + delta]?.node.id ?? null;
|
||||
}
|
||||
|
||||
/** Drop every pane whose ref fails `keep` (with everything right of it but pinned panes, which stay as orphans). Unchanged forests are returned as they are. */
|
||||
export function prune<R, S>(f: Forest<R, S>, keep: (r: R) => boolean): Forest<R, S> {
|
||||
const go = (t: Tree<R, S>, col: number, out: Tree<R, S>[]): Tree<R, S> | null => {
|
||||
if (!keep(t.ref)) {
|
||||
for (const s of survivors(t, col, false)) {
|
||||
const p = go(s, s.col!, out);
|
||||
if (p) out.push(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
let changed = false;
|
||||
// The picked child, or the one that takes its place: as many kept children before it.
|
||||
let pick = 0;
|
||||
const kids: Tree<R, S>[] = [];
|
||||
t.kids.forEach((k, j) => {
|
||||
const p = go(k, col + 1, out);
|
||||
if (p !== k) changed = true;
|
||||
if (p) kids.push(p);
|
||||
if (j === t.pick) pick = kids.length - (p ? 1 : 0);
|
||||
});
|
||||
if (!changed) return t;
|
||||
return { ...t, kids, pick: Math.max(0, Math.min(pick, kids.length - 1)) };
|
||||
};
|
||||
let g = f;
|
||||
for (let ti = f.trees.length - 1; ti >= 0; ti--) {
|
||||
const t = f.trees[ti];
|
||||
const out: Tree<R, S>[] = [];
|
||||
const p = go(t, colOf(t), out);
|
||||
if (p !== t || out.length) g = replace(g, g.trees.indexOf(t), p, out);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
/** Whether the first tree is the one starting at this ref (not missing, not an orphan). */
|
||||
export const rooted = <R, S>(f: Forest<R, S>, ref: R, same: Same<R>) => !!f.trees[0] && !f.trees[0].col && same(f.trees[0].ref, ref);
|
||||
|
||||
/**
|
||||
* Make the focused branch the first tree's path along this list of refs, keeping every pane that is
|
||||
* already on the way: where a ref is already a child it is picked; where it is not, the picked child
|
||||
* is replaced by the rest of the list (a pinned one is kept beside it). Panes right of the list's
|
||||
* end close, but pinned ones. A different root starts again. Orphans stay; pinned panes in what
|
||||
* closes become orphans.
|
||||
*/
|
||||
export function withBranch<R, S>(f: Forest<R, S>, refs: R[], same: Same<R>): Forest<R, S> {
|
||||
if (!refs.length) return f;
|
||||
const orphans: Tree<R, S>[] = [];
|
||||
if (!rooted(f, refs[0], same)) {
|
||||
const old = f.trees[0] && !f.trees[0].col ? f.trees[0] : null;
|
||||
if (old) orphans.push(...survivors(old, 0, false));
|
||||
const rest = old ? f.trees.slice(1) : f.trees;
|
||||
return { trees: [chain<R, S>(refs)!, ...orphans, ...rest], at: 0 };
|
||||
}
|
||||
const go = (n: Tree<R, S>, i: number): Tree<R, S> => {
|
||||
if (i === refs.length) return n.kids.length ? { ...n, kids: [], pick: 0 } : n;
|
||||
if (i === refs.length) {
|
||||
const kept = n.kids.filter((k) => k.pinned);
|
||||
if (kept.length === n.kids.length) return n;
|
||||
for (const k of n.kids) if (!k.pinned) orphans.push(...survivors(k, i, true));
|
||||
return { ...n, kids: kept, pick: 0 };
|
||||
}
|
||||
const k = n.kids.findIndex((c) => same(c.ref, refs[i]));
|
||||
if (k < 0) {
|
||||
const rest = chain<R, S>(refs.slice(i))!;
|
||||
const kids = n.kids.length ? n.kids.map((c, j) => (j === n.pick ? rest : c)) : [rest];
|
||||
return { ...n, kids, pick: n.kids.length ? n.pick : 0 };
|
||||
if (!n.kids.length) return { ...n, kids: [rest], pick: 0 };
|
||||
if (n.kids[n.pick].pinned) return { ...n, kids: [...n.kids, rest], pick: n.kids.length };
|
||||
orphans.push(...survivors(n.kids[n.pick], i, true));
|
||||
return { ...n, kids: n.kids.map((c, j) => (j === n.pick ? rest : c)) };
|
||||
}
|
||||
const sub = go(n.kids[k], i + 1);
|
||||
return sub === n.kids[k] && k === n.pick ? n : { ...n, kids: n.kids.map((c, j) => (j === k ? sub : c)), pick: k };
|
||||
};
|
||||
return go(t, 1);
|
||||
const t = go(f.trees[0], 1);
|
||||
const g = replace(f, 0, t, orphans);
|
||||
return g.at === 0 ? g : { ...g, at: 0 };
|
||||
}
|
||||
|
||||
/** As stored: refs (made storable by the caller), children and picks; no ids, nothing remembered. */
|
||||
/** As stored: refs (made storable by the caller), children, picks, pins and an orphan's column; no ids, nothing remembered. */
|
||||
export interface Saved<R> {
|
||||
ref: R;
|
||||
kids?: Saved<R>[];
|
||||
pick?: number;
|
||||
pin?: 1;
|
||||
col?: number;
|
||||
}
|
||||
|
||||
export function save<R, S, O>(t: Tree<R, S> | null, ref: (r: R) => O): Saved<O> | null {
|
||||
if (!t) return null;
|
||||
export function save<R, S, O>(t: Tree<R, S>, ref: (r: R) => O): Saved<O> {
|
||||
const out: Saved<O> = { ref: ref(t.ref) };
|
||||
if (t.kids.length) out.kids = t.kids.map((k) => save(k, ref)!);
|
||||
if (t.kids.length) out.kids = t.kids.map((k) => save(k, ref));
|
||||
if (t.pick) out.pick = t.pick;
|
||||
if (t.pinned) out.pin = 1;
|
||||
if (t.col) out.col = t.col;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -213,23 +345,39 @@ export function load<R, S>(o: unknown, ok: (r: unknown) => r is R): Tree<R, S> |
|
||||
const s = o as Saved<unknown>;
|
||||
const kids = (Array.isArray(s.kids) ? s.kids : []).map((k) => load<R, S>(k, ok)).filter((k): k is Tree<R, S> => !!k);
|
||||
const pick = Math.max(0, Math.min(typeof s.pick === "number" ? Math.floor(s.pick) : 0, kids.length - 1));
|
||||
return { ref: s.ref as R, kids, pick, id: ++ids };
|
||||
const t: Tree<R, S> = { ref: s.ref as R, kids, pick, id: ++ids };
|
||||
if (s.pin) t.pinned = true;
|
||||
if (typeof s.col === "number" && s.col >= 1) t.col = Math.floor(s.col);
|
||||
return t;
|
||||
}
|
||||
|
||||
/** What was stored: the tree, or, from before there were forks, the trail as a tree with one branch. */
|
||||
export function restore<R, S>(saved: unknown, trail: unknown[] | undefined, ok: (r: unknown) => r is R): Tree<R, S> | null {
|
||||
return saved ? load<R, S>(saved, ok) : chain<R, S>((trail ?? []).filter(ok));
|
||||
/**
|
||||
* What was stored: the forest; from before orphans, one tree; from before forks, the trail as a
|
||||
* tree with one branch. An orphan stored first (its tree's root gone) is dropped.
|
||||
*/
|
||||
export function restore<R, S>(saved: { forest?: unknown; at?: unknown; forks?: unknown; trail?: unknown[] }, ok: (r: unknown) => r is R): Forest<R, S> {
|
||||
if (Array.isArray(saved.forest)) {
|
||||
const trees = saved.forest.map((o) => load<R, S>(o, ok)).filter((t): t is Tree<R, S> => !!t);
|
||||
const first = trees.findIndex((t) => !t.col);
|
||||
const kept = first < 0 ? trees.filter((t) => t.col) : [trees[first], ...trees.filter((t, j) => j !== first && t.col)];
|
||||
const at = typeof saved.at === "number" ? Math.floor(saved.at) : 0;
|
||||
return { trees: kept, at: at >= 0 && at < kept.length ? at : 0 };
|
||||
}
|
||||
const t = saved.forks ? load<R, S>(saved.forks, ok) : chain<R, S>((saved.trail ?? []).filter(ok));
|
||||
return { trees: t ? [t] : [], at: 0 };
|
||||
}
|
||||
|
||||
/** Whether a tree is well formed: picks in range, no pane twice among siblings, ids unique. */
|
||||
export function valid<R, S>(t: Tree<R, S> | null, same: Same<R>): boolean {
|
||||
/** Whether a forest is well formed: picks in range, no pane twice among siblings, ids unique, orphans in a column right of the first, the focused tree there. */
|
||||
export function valid<R, S>(f: Forest<R, S>, same: Same<R>): boolean {
|
||||
const seen = new Set<number>();
|
||||
const ok = (n: Tree<R, S>): boolean => {
|
||||
if (seen.has(n.id)) return false;
|
||||
seen.add(n.id);
|
||||
if (n.pick < 0 || n.pick >= Math.max(1, n.kids.length) || !Number.isInteger(n.pick)) return false;
|
||||
for (let a = 0; a < n.kids.length; a++) for (let b = a + 1; b < n.kids.length; b++) if (same(n.kids[a].ref, n.kids[b].ref)) return false;
|
||||
return n.kids.every(ok);
|
||||
return n.kids.every((k) => k.col === undefined && ok(k));
|
||||
};
|
||||
return !t || ok(t);
|
||||
if (!f.trees.length) return f.at === 0;
|
||||
if (f.at < 0 || f.at >= f.trees.length) return false;
|
||||
return f.trees.every((t, ti) => (ti === 0 ? !t.col : (t.col ?? 0) >= 1) && ok(t));
|
||||
}
|
||||
+8
-3
@@ -15,9 +15,10 @@ export const HELP: [string, [string, string][]][] = [
|
||||
["/", "jump to a section by name, in any document"],
|
||||
["z", "hoist: make this node the whole page (again, or h or Esc at its top, to step out)"],
|
||||
["v", "view: one column ↔ panes side by side (in panes, j k move among siblings)"],
|
||||
["q", "in panes: close the panes right of the one being read, every fork among them; with none, close that one, or in a fork the whole fork. Moving left never closes anything"],
|
||||
["Shift+Enter", "in panes: open a fork: what Enter opens goes in a new row beside the pane to the right instead of replacing it (Shift-, Ctrl- or Cmd-click, or a middle click, does the same). With nothing open to the right it is a plain Enter; on something already open as a fork, it focuses that fork"],
|
||||
["[ ]", "in panes: the fork above / below (back where you were in it, or its pane nearest your column)"],
|
||||
["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"],
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -112,6 +113,7 @@ export const HELP: [string, [string, string][]][] = [
|
||||
["/auto on|off", "reconcile automatically after edits"],
|
||||
["/speculate on|off", "start writing the focused sentence's expansion early"],
|
||||
["/view mode", "page layout: auto, column or panes; auto shows panes on windows 1600 px wide or more"],
|
||||
["/curves on|off", "in panes: the faint curves from where each pane was opened to it"],
|
||||
["/user name", "set the name on your commits"],
|
||||
["/new title", "new blank document"],
|
||||
["/open name", "open a document by title or id"],
|
||||
@@ -498,6 +500,9 @@ function commonKey(k: string, hooks: KeyHooks): boolean {
|
||||
case "q":
|
||||
if (store.panes) store.closePane();
|
||||
return true;
|
||||
case "P":
|
||||
store.togglePanePin();
|
||||
return true;
|
||||
case "[":
|
||||
case "]":
|
||||
store.focusFork(k === "[" ? -1 : 1);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Lanes for the panes view's curves (Panes.tsx): where several curves run down one gutter, each gets
|
||||
* a lane of its own, side by side like a ribbon cable, in the order that crosses least.
|
||||
*/
|
||||
|
||||
/** Lanes in a gutter: vertical runs this far apart, from just inside the column's edge to just short of its titles. */
|
||||
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;
|
||||
|
||||
/**
|
||||
* How many times curves in one gutter cross, for an order of lanes (rightmost first): a lead-out
|
||||
* comes in from the left at its source's height, crossing the lanes left of its own still running
|
||||
* there; an arrival goes right at its title's height, crossing the lanes right of its own.
|
||||
*/
|
||||
export function crossings(order: { sy: number; ey: number }[]): number {
|
||||
const runs = (c: { sy: number; ey: number }, y: number) => y > Math.min(c.sy, c.ey) && y < Math.max(c.sy, c.ey);
|
||||
let n = 0;
|
||||
for (let i = 0; i < order.length; i++)
|
||||
for (let j = i + 1; j < order.length; j++) {
|
||||
// order[i] is right of order[j].
|
||||
if (runs(order[j], order[i].sy)) n++;
|
||||
if (runs(order[i], order[j].ey)) n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* The order of a gutter's lanes, rightmost first, so that curves cross as little as they can: the
|
||||
* curve with the shortest way to go takes the lane nearest the panes, and the rest outwards. Starting from the order last used, with new curves put
|
||||
* where that rule puts them, a curve is moved to another lane only while that removes crossings, so a
|
||||
* scroll or an open elsewhere does not reshuffle the bundle.
|
||||
*/
|
||||
export function laneOrder<T extends { key: string; sy: number; ey: number }>(edges: T[], last: string[] = []): T[] {
|
||||
const rule = [...edges].sort((a, b) => {
|
||||
const da = a.ey >= a.sy ? a.ey - a.sy : a.sy - a.ey;
|
||||
const db = b.ey >= b.sy ? b.ey - b.sy : b.sy - b.ey;
|
||||
return da - db;
|
||||
});
|
||||
const byKey = new Map(edges.map((e) => [e.key, e]));
|
||||
const order = last.flatMap((k) => byKey.get(k) ?? []);
|
||||
for (const e of rule) {
|
||||
if (order.includes(e)) continue;
|
||||
const r = rule.indexOf(e);
|
||||
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).
|
||||
let best = crossings(order);
|
||||
for (let pass = 0, better = true; better && pass < order.length; pass++) {
|
||||
better = false;
|
||||
for (let i = 0; i < order.length && best; i++)
|
||||
for (let j = 0; j < order.length; j++) {
|
||||
if (j === i) continue;
|
||||
const moved = order.slice();
|
||||
moved.splice(j, 0, ...moved.splice(i, 1));
|
||||
const n = crossings(moved);
|
||||
if (n < best) {
|
||||
order.splice(0, order.length, ...moved);
|
||||
best = n;
|
||||
better = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
+142
-123
@@ -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, chain, closeAt, closeChild, closeRight, open as openIn, path, prune, restore as restoreTree, save as saveTree, select, sibling, trace, update, withBranch, type Tree } from "./forks";
|
||||
import { 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 { stripMarks, type Mark } from "../core/marks";
|
||||
import { SEED_SLUG } from "../core/seed";
|
||||
|
||||
@@ -62,8 +62,14 @@ export interface Back {
|
||||
aux: Aux | null;
|
||||
pane: number;
|
||||
}
|
||||
/** A pane in the tree of forks; `seen` is where the reader was when they last left its fork. */
|
||||
/** A pane in the forest of forks; `seen` is where the reader was when they last left it by [ or ]. */
|
||||
export type Pane = Tree<PaneRef, Back>;
|
||||
/** The DOM class that marks, in a pane, what a child pane of it was opened from (a row, a link, words): by what the child shows. */
|
||||
export const kidClass = (key: string) => {
|
||||
let h = 5381;
|
||||
for (let i = 0; i < key.length; i++) h = ((h * 33) ^ key.charCodeAt(i)) >>> 0;
|
||||
return `k${h.toString(36)}`;
|
||||
};
|
||||
/** Whether two panes show the same thing (a node, or an article or one of its sections). */
|
||||
export const sameRef = (a: PaneRef, b: PaneRef): boolean =>
|
||||
a.kind === b.kind && (a.kind === "node" ? a.id === (b as { id: NodeId }).id : a.title === (b as { title: string }).title && a.sec === (b as { sec?: number }).sec);
|
||||
@@ -223,7 +229,7 @@ class Store {
|
||||
branchFrom: Commit | null = null;
|
||||
/** A note being previewed on hover, and where to draw it. */
|
||||
popup: { note: NodeId; x: number; top: number; bottom: number } | null = null;
|
||||
settings: { auto: boolean; speculate: boolean; view: View; autolink: AutoMode } = { auto: true, speculate: false, view: "auto", autolink: "suggest", ...lsGet("ie:settings", {}) };
|
||||
settings: { auto: boolean; speculate: boolean; view: View; autolink: AutoMode; curves: boolean } = { auto: true, speculate: false, view: "auto", autolink: "suggest", curves: true, ...lsGet("ie:settings", {}) };
|
||||
/** Link discovery: scans after writes, suggestions, Related, the background job. */
|
||||
links = new Linker({
|
||||
doc: () => this.doc,
|
||||
@@ -244,20 +250,29 @@ class Store {
|
||||
/** Replicas of pre-library documents whose edits never reached the server. */
|
||||
oldReplicas: OldReplica[] = [];
|
||||
|
||||
/** The panes as a tree of forks; its focused branch is `trail`, and `paneAt` is the pane on it that holds the focus. */
|
||||
tree: Pane | null = null;
|
||||
/** The panes as a forest of forks (forks.ts); its focused branch is `trail`, and `paneAt` is the pane on it that holds the focus: the active pane. */
|
||||
forest: Forest<PaneRef, Back> = { trees: [], at: 0 };
|
||||
paneAt = 0;
|
||||
/** The focused tree. */
|
||||
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: { tree: Pane | null; nodes: Pane[]; trail: PaneRef[]; index?: Map<number, { node: Pane; depth: number }>; ids?: Set<NodeId> } = { tree: null, nodes: [], trail: [] };
|
||||
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: [] };
|
||||
private get branch() {
|
||||
if (this.memo.tree !== this.tree) {
|
||||
if (this.memo.forest !== this.forest) {
|
||||
const nodes = path(this.tree);
|
||||
this.memo = { tree: this.tree, nodes, trail: nodes.map((n) => n.ref) };
|
||||
this.memo = { forest: this.forest, nodes, trail: nodes.map((n) => n.ref) };
|
||||
}
|
||||
return this.memo;
|
||||
}
|
||||
/** Every pane, with its column, in the order panes stand in a column. */
|
||||
get panesPlaced(): Placed<PaneRef, Back>[] {
|
||||
const m = this.branch;
|
||||
return (m.placed ??= all(this.forest));
|
||||
}
|
||||
/** The focused branch: the panes the keys move along, left to right. */
|
||||
get trail(): PaneRef[] {
|
||||
return this.branch.trail;
|
||||
@@ -438,59 +453,37 @@ class Store {
|
||||
return p.sec !== undefined && (q.kind === "wiki" ? q.title === p.title : this.targetOf(q.id)?.kind === "wiki");
|
||||
}
|
||||
|
||||
/** Pane i of the focused branch holds a focus (see holdsIn). */
|
||||
/** Pane i of the focused branch holds a focus (see holdsIn); a continuation's head only while it is the active pane. */
|
||||
private holds(i: number, f: Focus): boolean {
|
||||
return this.holdsIn(this.trail[i], this.trail[i - 1], i === 0, `p${i}`, f);
|
||||
return this.holdsIn(this.trail[i], this.trail[i - 1], i === 0 || i === this.paneAt, `p${i}`, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a pane (p, opened from q; host: how its article is named) holds a focus: its node's
|
||||
* text (a selection, a note in it), one of its rows, or its head when it is not a continuation (a
|
||||
* continuation's node is focused as the row it was opened from, in the pane before).
|
||||
* continuation's node is focused as the row it was opened from, in the pane before), or when
|
||||
* `head` says it may (the first pane, or the active pane, landed on by [ ] or a click).
|
||||
*/
|
||||
private holdsIn(p: PaneRef | undefined, q: PaneRef | undefined, first: boolean, host: string, f: Focus): boolean {
|
||||
private holdsIn(p: PaneRef | undefined, q: PaneRef | undefined, head: boolean, host: string, f: Focus): boolean {
|
||||
const s = this.snap;
|
||||
const n = s.nodes[f.node];
|
||||
// An annotation is held by the pane showing its article.
|
||||
if (p && n && inArticles(s, f.node)) return this.shows(p.kind === "wiki" ? host : `n${p.id}`, f.node);
|
||||
if (!p || p.kind !== "node" || !n) return false;
|
||||
if (f.grain !== "node" || n.kind === "note") return ownerSection(s, f.node) === p.id || f.node === p.id;
|
||||
if (f.node === p.id) return first || !this.continuesFrom(p, q);
|
||||
if (f.node === p.id) return head || !this.continuesFrom(p, q);
|
||||
return n.parent === p.id;
|
||||
}
|
||||
|
||||
/** A pane off the focused branch that holds a focus: the tree with it on the branch, and its column. */
|
||||
private forkHolding(f: Focus): { tree: Pane; depth: number } | null {
|
||||
const t = this.tree;
|
||||
if (!t) return null;
|
||||
/** A pane off the focused branch that holds a focus: the forest with it on the branch, and its depth. */
|
||||
private forkHolding(f: Focus): { forest: Forest<PaneRef, Back>; depth: number } | null {
|
||||
const on = new Set(this.branchNodes.map((n) => n.id));
|
||||
const find = (n: Pane, q: PaneRef | undefined, d: number): { id: number; depth: number } | null => {
|
||||
if (!on.has(n.id) && this.holdsIn(n.ref, q, d === 0, `f${n.id}`, f)) return { id: n.id, depth: d };
|
||||
for (const k of n.kids) {
|
||||
const hit = find(k, n.ref, d + 1);
|
||||
if (hit) return hit;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const hit = find(t, undefined, 0);
|
||||
return hit ? { tree: select(t, hit.id)!, depth: hit.depth } : null;
|
||||
const hit = this.panesPlaced.find((x) => !on.has(x.node.id) && this.holdsIn(x.node.ref, x.parent?.ref, x.depth === 0, `f${x.node.id}`, f));
|
||||
return hit ? { forest: focusIn(this.forest, hit.node.id), depth: hit.depth } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the tree. When the focused branch leaves a fork that stays open, the fork remembers
|
||||
* where the reader was in it, for [ and ] to come back to.
|
||||
*/
|
||||
private setTree(next: Pane | null, remember = true) {
|
||||
const old = this.branchNodes;
|
||||
if (next && remember && old.length) {
|
||||
const now = path(next);
|
||||
const d = old.findIndex((n, k) => now[k]?.id !== n.id);
|
||||
if (d > 0 && trace(next, old[d].id)) {
|
||||
const here = this.backHere();
|
||||
next = update(next, old[d].id, (n) => ({ ...n, seen: here }));
|
||||
}
|
||||
}
|
||||
this.tree = next;
|
||||
private setForest(next: Forest<PaneRef, Back>) {
|
||||
this.forest = next;
|
||||
}
|
||||
|
||||
/** The panes as a plain trail down to the focus (open sections on the way). */
|
||||
@@ -508,9 +501,9 @@ class Store {
|
||||
syncTrail() {
|
||||
if (!this.panes || !this.session) return;
|
||||
const s = this.snap;
|
||||
let t = prune(this.tree, (p) => p.kind === "wiki" || !!s.nodes[p.id]);
|
||||
if (!t || t.ref.kind !== "node" || t.ref.id !== this.top) t = chain(this.pathRefs());
|
||||
if (t !== this.tree) this.setTree(t, false);
|
||||
let f = prune(this.forest, (p) => p.kind === "wiki" || !!s.nodes[p.id]);
|
||||
if (!rooted(f, { kind: "node", id: this.top }, sameRef)) f = withBranch(f, this.pathRefs(), sameRef);
|
||||
if (f !== this.forest) this.setForest(f);
|
||||
this.paneAt = Math.max(0, Math.min(this.paneAt, this.trail.length - 1));
|
||||
if (this.aux) return;
|
||||
const n = this.trail.length;
|
||||
@@ -518,22 +511,22 @@ class Store {
|
||||
for (const i of order) if (i >= 0 && i < n && this.holds(i, this.focus)) return void (this.paneAt = i);
|
||||
const fork = this.forkHolding(this.focus);
|
||||
if (fork) {
|
||||
this.setTree(fork.tree, false);
|
||||
this.setForest(fork.forest);
|
||||
this.paneAt = fork.depth;
|
||||
return;
|
||||
}
|
||||
this.setTree(withBranch(this.tree, this.pathRefs(), sameRef), false);
|
||||
this.setForest(withBranch(this.forest, this.pathRefs(), sameRef));
|
||||
const at = this.trail.findIndex((_, i) => this.holds(i, this.focus));
|
||||
this.paneAt = at >= 0 ? at : this.trail.length - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open something to the right of pane i. If it is already open there, as any fork, that fork is
|
||||
* focused. Otherwise a plain open replaces what was to the right; a fork (`forking`) opens it
|
||||
* beside that, as a new row below. Returns the pane it is in.
|
||||
* 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.
|
||||
*/
|
||||
openPane(i: number, ref: PaneRef): number {
|
||||
this.setTree(this.tree ? openIn(this.tree, i, ref, this.forking, sameRef) : chain([ref]));
|
||||
this.setForest(openIn(this.forest, i, ref, this.forking, sameRef));
|
||||
this.saveView();
|
||||
this.emit();
|
||||
return Math.min(i + 1, this.trail.length - 1);
|
||||
@@ -541,10 +534,9 @@ class Store {
|
||||
|
||||
/** Close the pane that shows this node to the right of pane i (whichever fork it is). */
|
||||
closeRow(i: number, id: NodeId) {
|
||||
if (!this.tree) return;
|
||||
this.setTree(closeChild(this.tree, i, { kind: "node", id }, sameRef));
|
||||
this.saveView();
|
||||
this.emit();
|
||||
const kid = this.branchNodes[i]?.kids.find((k) => k.ref.kind === "node" && k.ref.id === id);
|
||||
if (!kid) return;
|
||||
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. */
|
||||
@@ -562,33 +554,28 @@ class Store {
|
||||
}
|
||||
}
|
||||
|
||||
/** The tree's panes by id, with their columns. */
|
||||
forkNode(id: number): { node: Pane; depth: number } | undefined {
|
||||
/** A pane of the forest by its id: its node, depth in its tree, column, tree and parent. */
|
||||
forkNode(id: number): Placed<PaneRef, Back> | undefined {
|
||||
const m = this.branch;
|
||||
if (!m.index) m.index = new Map(all(this.tree).map((x) => [x.node.id, x]));
|
||||
if (!m.index) m.index = new Map(this.panesPlaced.map((x) => [x.node.id, x]));
|
||||
return m.index.get(id);
|
||||
}
|
||||
|
||||
/** Whether any pane in the tree shows this node. */
|
||||
/** Whether any pane shows this node. */
|
||||
private paneShows(id: NodeId): boolean {
|
||||
const m = this.branch;
|
||||
if (!m.ids) m.ids = new Set(all(this.tree).flatMap((x) => (x.node.ref.kind === "node" ? [x.node.ref.id] : [])));
|
||||
if (!m.ids) m.ids = new Set(this.panesPlaced.flatMap((x) => (x.node.ref.kind === "node" ? [x.node.ref.id] : [])));
|
||||
return m.ids.has(id);
|
||||
}
|
||||
|
||||
/** Whether some pane has forks. */
|
||||
hasForks(): boolean {
|
||||
return all(this.tree).some((x) => x.node.kids.length > 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a pane with forks: its children by what they show (refKey), each true if it is the picked
|
||||
* one. Null for a pane with one child or none, which marks nothing new (its row is marked as before).
|
||||
* For a pane with children: its children by what they show (refKey), each with whether it is the
|
||||
* picked one and whether there are several (forks, marked as such).
|
||||
*/
|
||||
forkMarks(tid: number | undefined): Map<string, boolean> | null {
|
||||
forkMarks(tid: number | undefined): Map<string, { picked: boolean; many: boolean }> | null {
|
||||
const n = tid === undefined ? undefined : this.forkNode(tid)?.node;
|
||||
if (!n || n.kids.length < 2) return null;
|
||||
return new Map(n.kids.map((k, j) => [refKey(k.ref), j === n.pick]));
|
||||
if (!n || !n.kids.length) return null;
|
||||
return new Map(n.kids.map((k, j) => [refKey(k.ref), { picked: j === n.pick, many: n.kids.length > 1 }]));
|
||||
}
|
||||
|
||||
/** A link's target by the key of the pane it opens (refKey); none for a web page or a node that is gone. */
|
||||
@@ -599,16 +586,16 @@ class Store {
|
||||
return id ? `n:${id}` : undefined;
|
||||
}
|
||||
|
||||
/** How a child is marked in the pane it was opened from: "showing" (the picked child), "forked" (another fork), or not open. */
|
||||
kidMark(tid: number | undefined, match: (r: PaneRef) => boolean): "showing" | "forked" | undefined {
|
||||
/** How a child is marked in the pane it was opened from: "showing" (the picked child), "forked" (another fork), or not open; with the class that names it. */
|
||||
kidMark(tid: number | undefined, match: (r: PaneRef) => boolean): string | undefined {
|
||||
const n = tid === undefined ? undefined : this.forkNode(tid)?.node;
|
||||
const k = n ? n.kids.findIndex((c) => match(c.ref)) : -1;
|
||||
return k < 0 ? undefined : k === n!.pick ? "showing" : "forked";
|
||||
return k < 0 ? undefined : `${k === n!.pick ? "showing" : "forked"} ${kidClass(refKey(n!.kids[k].ref))}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the focus on pane c of the focused branch: on its node (for a continuation, that is the row
|
||||
* it was opened from, in the pane before), or on an article's head.
|
||||
* Put the focus on pane c of the focused branch, making it the active pane: on its node (its head;
|
||||
* a continuation's too, while it is active), or on an article's head.
|
||||
*/
|
||||
land(c: number) {
|
||||
const p = this.trail[c];
|
||||
@@ -618,30 +605,34 @@ class Store {
|
||||
else this.setFocus(this.focus, { kind: "wiki", host: `p${c}`, row: { t: "head" } });
|
||||
}
|
||||
|
||||
/** A click in a pane off the focused branch: its fork becomes the focused branch, with the focus on that pane. */
|
||||
/** A click in a pane off the focused branch (or a tab): that pane comes onto the focused branch, with the focus on it. */
|
||||
enterFork(id: number) {
|
||||
const f = focusIn(this.forest, id);
|
||||
const hit = this.forkNode(id);
|
||||
const t = this.tree && select(this.tree, id);
|
||||
if (!hit || !t || t === this.tree) return;
|
||||
this.setTree(t);
|
||||
if (!hit || f === this.forest) return;
|
||||
this.setForest(f);
|
||||
this.land(hit.depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* [ and ]: the fork above or below, in the order the rows are drawn (the nearest pane, from the
|
||||
* branch's end leftwards, that has another fork that way). The focus goes back where it was in
|
||||
* that fork, or to its pane nearest the column the reader was in.
|
||||
* [ and ]: the pane above or below the active one in its column (whichever fork or tree it is in).
|
||||
* The focus goes back where it was when that pane was last left this way, or to the pane's head.
|
||||
*/
|
||||
focusFork(delta: number) {
|
||||
if (!this.panes) return this.say("Forks are side by side in the panes view (v); one column shows one page.");
|
||||
this.syncTrail();
|
||||
const s = this.tree && sibling(this.tree, delta);
|
||||
if (!s) return this.say(this.hasForks() ? `No fork ${delta < 0 ? "above" : "below"} this one.` : "No forks open. Shift+Enter, or a Shift- or Ctrl-click, opens one beside the pane to the right.");
|
||||
const col = this.paneAt + (this.showingFocus() ? 1 : 0);
|
||||
this.setTree(s.tree);
|
||||
const b = this.branchNodes[s.depth].seen;
|
||||
if (b && b.pane >= s.depth && b.pane < this.trail.length && this.snap.nodes[b.focus.node] && (b.aux ? this.auxValid(b.aux) : this.holds(b.pane, b.focus))) return this.restore(b);
|
||||
this.land(Math.max(s.depth, Math.min(col, this.trail.length - 1)));
|
||||
const here = this.branchNodes[this.paneAt];
|
||||
const next = here && besideInColumn(this.forest, here.id, delta);
|
||||
if (next === null || next === undefined) {
|
||||
const alone = here && besideInColumn(this.forest, here.id, -delta) === null;
|
||||
return this.say(alone ? "This is the only pane in its column. Shift+Enter, or a Shift- or Ctrl-click, opens a fork below the pane to the right." : `No pane ${delta < 0 ? "above" : "below"} this one in its column.`);
|
||||
}
|
||||
const seen = this.backHere();
|
||||
this.setForest(focusIn(updateIn(this.forest, here.id, (n) => ({ ...n, seen })), next));
|
||||
const hit = this.forkNode(next)!;
|
||||
const b = hit.node.seen;
|
||||
if (b && b.pane === hit.depth && this.snap.nodes[b.focus.node] && (b.aux ? this.auxValid(b.aux) : this.holds(b.pane, b.focus))) return this.restore(b);
|
||||
this.land(hit.depth);
|
||||
}
|
||||
|
||||
/** Whether the focus is a row whose pane is open next to it (so that pane is the one the reader is looking at). */
|
||||
@@ -651,34 +642,53 @@ class Store {
|
||||
}
|
||||
|
||||
/**
|
||||
* q, on the pane the reader is looking at (for a row, the pane it shows): close the panes to its
|
||||
* right, every fork among them. With none there, close it and step left; in a fork, that closes
|
||||
* the whole fork (from where it branched off to its end), and the others stay.
|
||||
* q (on the active pane) or a pane's ×: close the pane and everything opened from it, except
|
||||
* pinned panes, which stay where they are. If the focus was in what closed, it goes back to where
|
||||
* the pane was opened from (its row, its link, the article section) in the pane before.
|
||||
*/
|
||||
closePane() {
|
||||
const showing = this.showingFocus();
|
||||
const i = this.paneAt + (showing ? 1 : 0);
|
||||
if (!this.tree) return;
|
||||
if (i + 1 < this.trail.length) {
|
||||
this.setTree(closeRight(this.tree, i));
|
||||
this.saveView();
|
||||
closePane(id = this.branchNodes[this.paneAt]?.id) {
|
||||
const hit = id === undefined ? undefined : this.forkNode(id);
|
||||
if (!hit) return;
|
||||
if (hit.ti === 0 && hit.depth === 0) return this.say("The first pane stays; h or Esc at its top steps out of it.");
|
||||
const active = this.branchNodes[this.paneAt];
|
||||
const wasAt = this.paneAt;
|
||||
const r = closeIn(this.forest, hit.node.id, active.id);
|
||||
this.setForest(r.forest);
|
||||
this.saveView();
|
||||
const now = this.forkNode(r.active)!;
|
||||
this.paneAt = now.depth;
|
||||
if (r.active === active.id) {
|
||||
// Still open; an article pane that became an orphan's root is named by its new place.
|
||||
const a = this.aux;
|
||||
if (now.depth !== wasAt && a?.kind === "wiki" && a.host === `p${wasAt}`) this.aux = { ...a, host: `p${now.depth}` };
|
||||
return this.emit();
|
||||
}
|
||||
// The nearest pane to the left with forks: the fork the reader is in starts right of it.
|
||||
const nodes = this.branchNodes;
|
||||
let j = i - 1;
|
||||
while (j >= 0 && nodes[j].kids.length < 2) j--;
|
||||
const k = j >= 0 ? j + 1 : i;
|
||||
if (k === 0) return this.say("The first pane stays; h or Esc at its top steps out of it.");
|
||||
const from = this.trail[k].from;
|
||||
this.setTree(closeAt(this.tree, k));
|
||||
if (hit.parent && r.active === hit.parent.id) return this.toSource(hit.node.ref, now.depth);
|
||||
this.land(now.depth);
|
||||
}
|
||||
|
||||
/** Back in pane i to where a pane (shown by ref, opened from pane i) was opened from: the jump's place, the row it continues, or the article's section row. */
|
||||
private toSource(ref: PaneRef, i: number) {
|
||||
const q = this.trail[i];
|
||||
if (ref.from && ref.from.pane === i) return this.restore(ref.from);
|
||||
this.paneAt = i;
|
||||
if (ref.kind === "node" && q?.kind === "node" && this.continuesFrom(ref, q) && this.snap.nodes[ref.id]) return this.setFocus({ node: ref.id, grain: "node" });
|
||||
if (ref.kind === "wiki" && ref.sec !== undefined && q) {
|
||||
const host = q.kind === "wiki" ? `p${i}` : `n${q.id}`;
|
||||
return this.setFocus(q.kind === "node" ? { node: q.id, grain: "node" } : this.focus, { kind: "wiki", host, row: { t: "sec", id: ref.sec } });
|
||||
}
|
||||
this.land(i);
|
||||
}
|
||||
|
||||
/** 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).");
|
||||
const hit = id === undefined ? undefined : this.forkNode(id);
|
||||
if (!hit) return;
|
||||
const on = !hit.node.pinned;
|
||||
this.setForest(pinIn(this.forest, hit.node.id, on));
|
||||
this.saveView();
|
||||
if (showing && k === i) return this.emit();
|
||||
this.paneAt = k - 1;
|
||||
if (from && from.pane < k) return this.restore(from);
|
||||
const p = this.trail[k - 1];
|
||||
if (p.kind === "node") this.setFocus({ node: p.id, grain: "node" });
|
||||
else this.setFocus(this.focus, { kind: "wiki", host: `p${k - 1}`, row: { t: "head" } });
|
||||
this.say(on ? "Pinned: this pane stays open when what it was opened from closes, and never folds away. P again unpins it." : "Unpinned.");
|
||||
}
|
||||
|
||||
/** Go back to where a jump was made from. */
|
||||
@@ -1148,12 +1158,12 @@ class Store {
|
||||
}
|
||||
private restoreView() {
|
||||
const s = this.doc.snap();
|
||||
const v = lsGet<{ open: NodeId[]; focus: Focus | null; hoist: NodeId | null; forks?: unknown; trail?: PaneRef[]; paneAt?: number }>(this.viewKey(), { open: [], focus: null, hoist: null });
|
||||
const v = lsGet<{ open: NodeId[]; focus: Focus | null; hoist: NodeId | null; forest?: unknown; at?: number; forks?: unknown; trail?: PaneRef[]; paneAt?: number }>(this.viewKey(), { open: [], focus: null, hoist: null });
|
||||
this.open = new Set(v.open.filter((id) => s.nodes[id]));
|
||||
this.hoist = v.hoist && s.nodes[v.hoist] ? v.hoist : null;
|
||||
this.focus = v.focus && s.nodes[v.focus.node] ? v.focus : { node: this.top, grain: "node" };
|
||||
// The tree of forks; a view saved before there were forks has only its trail, which loads as one branch.
|
||||
this.tree = prune(restoreTree<PaneRef, Back>(v.forks, v.trail, isPaneRef), (p) => p.kind === "wiki" || !!s.nodes[p.id]);
|
||||
// The forest of forks; a view saved before orphans has one tree, and before forks only its trail, which loads as one branch.
|
||||
this.forest = prune(restoreForest<PaneRef, Back>(v, isPaneRef), (p) => p.kind === "wiki" || !!s.nodes[p.id]);
|
||||
this.paneAt = Math.min(v.paneAt ?? 0, Math.max(0, this.trail.length - 1));
|
||||
this.aux = null;
|
||||
this.repairView();
|
||||
@@ -1161,7 +1171,7 @@ class Store {
|
||||
saveView() {
|
||||
const bare = (p: PaneRef): PaneRef => ({ ...p, from: undefined });
|
||||
// The trail too, for a build from before forks.
|
||||
lsSet(this.viewKey(), { open: [...this.open], focus: this.focus, hoist: this.hoist, forks: saveTree(this.tree, bare), trail: this.trail.map(bare), paneAt: this.paneAt });
|
||||
lsSet(this.viewKey(), { open: [...this.open], focus: this.focus, hoist: this.hoist, forest: this.forest.trees.map((t) => saveTree(t, bare)), at: this.forest.at, trail: this.trail.map(bare), paneAt: this.paneAt });
|
||||
}
|
||||
/** Keep focus on something that exists and is on screen. */
|
||||
private repairView() {
|
||||
@@ -1254,11 +1264,11 @@ class Store {
|
||||
this.aux = null;
|
||||
// A pane in another fork that shows it brings that fork onto the branch.
|
||||
const at = this.trail.findIndex((p) => p.kind === "node" && p.id === found.node);
|
||||
const fork = at < 0 && this.panes ? all(this.tree).find((x) => x.node.ref.kind === "node" && x.node.ref.id === found.node) : undefined;
|
||||
if (fork && this.tree) {
|
||||
this.setTree(select(this.tree, fork.node.id), false);
|
||||
const fork = at < 0 && this.panes ? this.panesPlaced.find((x) => x.node.ref.kind === "node" && x.node.ref.id === found.node) : undefined;
|
||||
if (fork) {
|
||||
this.setForest(focusIn(this.forest, fork.node.id));
|
||||
this.paneAt = fork.depth;
|
||||
} else if (this.panes && at < 0) this.setTree(withBranch(this.tree, this.pathRefs(), sameRef), false);
|
||||
} else if (this.panes && at < 0) this.setForest(withBranch(this.forest, this.pathRefs(), sameRef));
|
||||
else if (at >= 0) this.paneAt = at;
|
||||
}
|
||||
this.repairView();
|
||||
@@ -1411,7 +1421,9 @@ class Store {
|
||||
const next = this.trail[i + 1];
|
||||
if (next?.kind === "node" && next.id === f.node && this.continues(i + 1)) {
|
||||
const rows = this.paneRows(i + 1);
|
||||
// Into its first row; with none, onto its head, which makes it the active pane.
|
||||
if (rows[0]) this.focusRow(rows[0], i + 1);
|
||||
else this.land(i + 1);
|
||||
return;
|
||||
}
|
||||
this.open.add(f.node);
|
||||
@@ -1463,7 +1475,11 @@ class Store {
|
||||
this.syncTrail();
|
||||
const i = this.paneAt;
|
||||
const p = this.trail[i];
|
||||
if (p?.kind === "node" && p.id !== f.node) return this.setFocus({ node: p.id, grain: "node" });
|
||||
// From a row to its pane's node: for a continuation, that is its row in the pane before.
|
||||
if (p?.kind === "node" && (p.id !== f.node || (i > 0 && this.continues(i)))) {
|
||||
if (i > 0 && this.continues(i)) this.paneAt = i - 1;
|
||||
return this.setFocus({ node: p.id, grain: "node" });
|
||||
}
|
||||
if (i > 0) {
|
||||
const from = this.trail[i].from;
|
||||
if (from && from.pane < i) return this.restore(from);
|
||||
@@ -1484,7 +1500,7 @@ class Store {
|
||||
this.syncTrail();
|
||||
const p = this.trail[this.paneAt];
|
||||
if (open && p?.kind === "node" && this.snap.nodes[id]?.parent === p.id && this.snap.nodes[id].kind === "section") this.openPane(this.paneAt, { kind: "node", id });
|
||||
else if (!open && this.tree) this.setTree(closeChild(this.tree, this.paneAt, { kind: "node", id }, sameRef));
|
||||
else if (!open) this.closeRow(this.paneAt, id);
|
||||
}
|
||||
|
||||
setOpen(id: NodeId, open: boolean) {
|
||||
@@ -1501,6 +1517,8 @@ class Store {
|
||||
toggle(id = this.focus.node) {
|
||||
if (id === this.top) return this.toggleFold(id);
|
||||
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.
|
||||
if (this.panes) {
|
||||
this.syncTrail();
|
||||
@@ -2102,6 +2120,7 @@ class Store {
|
||||
},
|
||||
auto: () => this.set("auto", arg !== "off"),
|
||||
speculate: () => this.set("speculate", arg !== "off"),
|
||||
curves: () => (this.set("curves", arg !== "off"), this.emit()),
|
||||
view: () => (["auto", "column", "panes"].includes(arg) ? this.setView(arg as View) : this.say(`/view auto, column or panes (now ${this.settings.view}, showing ${this.panes ? "panes" : "column"})`)),
|
||||
resolve: () => this.resolveAll(),
|
||||
new: () => (arg ? this.newDoc(arg) : this.openMenu("new")),
|
||||
@@ -2705,7 +2724,7 @@ class Store {
|
||||
this.setView(this.panes ? "column" : "panes");
|
||||
}
|
||||
|
||||
private set(key: "auto" | "speculate", on: boolean) {
|
||||
private set(key: "auto" | "speculate" | "curves", on: boolean) {
|
||||
this.settings = { ...this.settings, [key]: on };
|
||||
lsSet("ie:settings", this.settings);
|
||||
this.say(`${key} ${on ? "on" : "off"}`);
|
||||
|
||||
+68
-35
@@ -322,9 +322,12 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
/* ---- end usage ---- */
|
||||
|
||||
/* ---- panes view (src/ui/Panes.tsx) ----
|
||||
* The path to the focus as a strip of panes, side by side, after notes.andymatuschak.org. Pane i
|
||||
* sticks i spines from the left edge, so later panes slide over earlier ones and leave each a
|
||||
* narrow spine that carries its title. Each pane scrolls on its own; only the strip scrolls sideways.
|
||||
* The panes as columns, side by side, after notes.andymatuschak.org. Column i sticks i spines from
|
||||
* the left edge (a pinned pane's column, a whole pane), so later columns slide over earlier ones
|
||||
* and leave each a narrow spine that carries its title. A column holds every pane at its depth, top
|
||||
* to bottom, sharing its height (Panes.tsx sets the heights); folded panes are one-line tabs. Each
|
||||
* pane scrolls on its own; only the strip scrolls sideways. Every pane has the same hairline on its
|
||||
* right and bottom, so neighbours share one line and the outer edges meet the bars above and below.
|
||||
*/
|
||||
:root {
|
||||
--pane-text: 34rem;
|
||||
@@ -332,9 +335,17 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
--pane-pad: 1.8rem;
|
||||
--pane: calc(var(--spine) + var(--pane-text) + var(--pane-pad));
|
||||
--shade: rgb(0 0 0 / 0.2);
|
||||
--pane-rule: #d9d9d9;
|
||||
--curve: rgb(0 0 0 / 0.17);
|
||||
--curve-on: color-mix(in srgb, var(--link) 62%, transparent);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root { --shade: rgb(0 0 0 / 0.6); }
|
||||
:root {
|
||||
--shade: rgb(0 0 0 / 0.6);
|
||||
--pane-rule: #3a3a3a;
|
||||
--curve: rgb(255 255 255 / 0.16);
|
||||
--curve-on: color-mix(in srgb, var(--link) 62%, transparent);
|
||||
}
|
||||
}
|
||||
.view-panes .page {
|
||||
position: fixed; top: 0; left: 0; right: 0; bottom: 1.75rem;
|
||||
@@ -342,22 +353,30 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
}
|
||||
.view-panes.with-panel .page { right: min(440px, 92vw); }
|
||||
.view-panes .banner { flex: none; width: auto; margin: 0; }
|
||||
.panes { flex: 1; min-height: 0; display: flex; position: relative; }
|
||||
.strip {
|
||||
flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden;
|
||||
flex: 1; min-width: 0; display: flex; overflow-x: auto; overflow-y: hidden;
|
||||
overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: var(--rule) transparent;
|
||||
}
|
||||
.pane { position: sticky; flex: none; width: var(--pane); width: round(down, var(--pane), 1px); height: 100%; background: var(--bg); border-left: 1px solid var(--hair); }
|
||||
.strip > .pane:first-child { border-left-color: transparent; }
|
||||
.pane[data-over] { border-left-color: var(--rule); box-shadow: -14px 0 20px -12px var(--shade); }
|
||||
.col { position: sticky; flex: none; width: var(--pane); width: round(down, var(--pane), 1px); height: 100%; display: flex; flex-direction: column; background: var(--bg); }
|
||||
.col.split { overflow-y: auto; scrollbar-width: none; }
|
||||
.pane { position: relative; flex: none; width: 100%; height: 100%; overflow: hidden; color: var(--fg); background: var(--bg); border-right: 1px solid var(--pane-rule); border-bottom: 1px solid var(--pane-rule); }
|
||||
.col.split > .pane { height: auto; flex: 1 1 0; min-height: 0; }
|
||||
.strip[data-flush] .pane:last-child { border-bottom-color: transparent; }
|
||||
.col[data-over] { box-shadow: -14px 0 20px -12px var(--shade); }
|
||||
.col[data-over]::before { content: ""; position: absolute; z-index: 4; top: 0; bottom: 0; left: 0; width: 1px; background: var(--rule); }
|
||||
.pane-scroll {
|
||||
height: 100%; overflow-x: hidden; overflow-y: auto; padding: 1.9rem var(--pane-pad) 30vh var(--spine);
|
||||
scrollbar-width: thin; scrollbar-color: var(--hair) transparent;
|
||||
}
|
||||
/* In a shared column a pane is only as tall as its text needs, so it scrolls no further than its end. */
|
||||
.col.split .pane-scroll { padding-bottom: 1.4rem; }
|
||||
|
||||
/* The spine: a covered pane's title, set vertically in the left gutter. */
|
||||
.spine { position: absolute; top: 0; bottom: 0; left: 0; width: var(--spine); z-index: 2; background: var(--bg); opacity: 0; pointer-events: none; cursor: pointer; transition: opacity 0.12s; }
|
||||
.pane[data-covered] .spine { opacity: 1; pointer-events: auto; }
|
||||
.spine span {
|
||||
.spine { position: absolute; top: 0; bottom: 0; left: 0; width: var(--spine); z-index: 2; background: inherit; opacity: 0; pointer-events: none; cursor: pointer; transition: opacity 0.12s; }
|
||||
.col[data-covered] .spine { opacity: 1; pointer-events: auto; }
|
||||
.spine .pane-btn { position: absolute; top: 0.3rem; left: 50%; margin-left: -0.65rem; }
|
||||
.spine-title {
|
||||
display: block; max-height: 100%; padding: 1.95rem 0 1.2rem; writing-mode: vertical-rl; line-height: var(--spine);
|
||||
font-family: var(--sans); font-size: 0.74rem; letter-spacing: 0.03em; color: var(--dim);
|
||||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||
@@ -367,6 +386,41 @@ 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. */
|
||||
.tabline {
|
||||
display: none; align-items: center; gap: 0.4em; height: 100%; padding: 0 3.4rem 0 var(--spine); cursor: pointer;
|
||||
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; }
|
||||
|
||||
/* 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; }
|
||||
.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); }
|
||||
.pane .pane-btn:hover { color: var(--fg); background: var(--sel); }
|
||||
.pane-btn.pin.on { color: var(--fg); }
|
||||
.pane-btn.pin.on svg { fill: currentColor; }
|
||||
|
||||
/*
|
||||
* The active pane, where the keys act: a heavy rule across its top, as gwern sets a heading's;
|
||||
* the other panes on the focused branch, a hairline in the text's colour. The status line's mode
|
||||
* badge is set in the same ink.
|
||||
*/
|
||||
.pane::after { content: ""; position: absolute; z-index: 3; top: 0; left: 0; right: 0; height: 0; background: var(--fg); pointer-events: none; }
|
||||
.pane.active::after { height: 3px; }
|
||||
.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; }
|
||||
.curves path { fill: none; stroke: var(--curve); stroke-width: 1; }
|
||||
.curves path.on { stroke: var(--curve-on); }
|
||||
.curves path.lost { stroke-dasharray: 1 3; }
|
||||
|
||||
/* A pane's head: a section heading, smaller than the page title the first pane keeps. */
|
||||
.pane-head { display: flex; align-items: baseline; gap: 0.6em; margin: 0 0 0.85rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--faint); cursor: pointer; }
|
||||
.pane-head.focused { border-bottom-color: var(--fg); }
|
||||
@@ -381,25 +435,6 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.node.showing > .row .mark { color: var(--fg); }
|
||||
.node.showing > .row::after { content: "→"; flex: none; margin-left: auto; padding-left: 0.8em; font-family: var(--sans); font-size: 0.72em; color: var(--dim); }
|
||||
|
||||
/*
|
||||
* Forks (src/ui/forks.ts): right of a pane with several children, one row per fork, top to bottom
|
||||
* in the order they were opened, divided by a line; a row holds its fork's panes and perhaps a
|
||||
* stack of rows of its own. Rows share the strip's height down to --row-min each (a stack needs a
|
||||
* row's worth per fork at its far right, --leaves); past that the strip scrolls down, and a pane
|
||||
* with forks stays at the top while its rows go by. Sideways the strip scrolls as one, so a fork's
|
||||
* pane is always in the column next to the pane it came from.
|
||||
*/
|
||||
.strip.forked { overflow-y: auto; overscroll-behavior-y: contain; }
|
||||
.forks { flex: none; display: flex; flex-direction: column; min-height: calc(var(--row-min) * var(--leaves)); }
|
||||
.fork { flex: 1 1 0; display: flex; min-height: calc(var(--row-min) * var(--leaves)); }
|
||||
.fork + .fork { border-top: 1px solid var(--rule); }
|
||||
/* The line is drawn on the row's panes too: a pane slid sideways over the row's edge would cover it. */
|
||||
.fork + .fork .pane { border-top: 1px solid var(--rule); }
|
||||
/* The focused fork: its first pane's left edge in the text's colour. */
|
||||
.fork.on > .pane:first-child { border-left-color: var(--fg); }
|
||||
.strip.forked .pane { height: auto; max-height: var(--strip-h); top: 0; }
|
||||
/* A row's height is only known after the rows are laid out, so a pane's own scroller is fitted to the pane rather than sized by percent. */
|
||||
.strip.forked .pane-scroll { position: absolute; inset: 0; height: auto; padding-bottom: min(30vh, calc(var(--row-min) / 2)); }
|
||||
/* What each fork was opened from, in the pane it came from: the focused fork's row, words or link marked as before, the others lightly. */
|
||||
.node.forked > .row::after, .wrow.forked > .row::after { content: "→"; flex: none; margin-left: auto; padding-left: 0.8em; font-family: var(--sans); font-size: 0.72em; color: var(--faint); }
|
||||
.wrow.forked > .row:has(.wnum)::after { margin-left: 0.5em; }
|
||||
@@ -408,9 +443,8 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
:is(.lnk, .anchor, .wiki-text a).forked.picked { background-color: color-mix(in srgb, var(--link) 30%, transparent); }
|
||||
:is(.backlinks, .related-list) li.forked { box-shadow: inset 2px 0 0 var(--rule); }
|
||||
:is(.backlinks, .related-list) li.forked.picked { box-shadow: inset 2px 0 0 var(--fg); }
|
||||
/* Where there is no room for rows only the focused branch is drawn; a pane that starts a fork says so. */
|
||||
.fork-note { margin: -1.1rem 0 0.9rem; font-family: var(--sans); font-size: 0.62rem; letter-spacing: 0.03em; color: var(--dim); }
|
||||
.fork-note kbd { font-size: 0.95em; }
|
||||
/* An orphan: a pinned pane whose source has closed. */
|
||||
.orphan-note { text-transform: none; letter-spacing: 0.02em; font-style: italic; }
|
||||
|
||||
/* The first pane keeps the page title, set from the left so it stays readable when the pane is partly covered. */
|
||||
.pane.root .top h1, .pane.root .byline, .pane.doc .top h1, .pane.doc .byline { text-align: left; }
|
||||
@@ -512,8 +546,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
* Its own ground, its own face (the bundled sans), a W at its head, its licence at its foot.
|
||||
*/
|
||||
.wiki { font-family: var(--sans); color: var(--soft); }
|
||||
.wiki-pane .pane-scroll, .wiki-pane .spine { background: var(--wiki-bg); }
|
||||
.wiki-pane { border-left-color: var(--wiki-rule); }
|
||||
.pane.wiki-pane { background: var(--wiki-bg); }
|
||||
.wiki-pane .spine span { color: var(--dim); }
|
||||
.wiki-pane .spine .wmark { font-weight: 600; }
|
||||
.wiki-head { margin: 0 0 0.8rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--wiki-rule); cursor: pointer; }
|
||||
|
||||
Reference in new issue
Block a user