feat(outline): drag-reorder + zoom — S6 (#112)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Pointer drag of a block run into any sibling seam or onto a block to nest as its child (wf113 variant A: fat-gap 30/40/30 bands, seam line at the future bullet column); the block selection rides the drag, the moved run becomes the selection, and Esc cancels mid-gesture. Double-click any bullet zooms to its children with breadcrumbs back out. New OutlineTree extract/insertRun splice subtrees id-preserving; the live row's NSTextView moved to OutlineRowTextView. Audit round: the gesture is self-contained from arm time (strong window + callback captures — a mid-drag scroll that drops the origin row cannot strand drag state), a second arming cancels a stuck predecessor, rowFrames prefers the grip frame, hitTestDrop is y-up only, and the rails read DropGeometry. Pinned in OutlineDragTests (monitors fire on sendEvent with a real window number). [Generated by AI]
This commit is contained in:
1 parent
d722820fc8
commit
21e2f27450
14 files changed
+2196
-256
No files matched your search
@@ -0,0 +1,666 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
PROTOTYPE — throwaway. Wayfinder ticket #113 (map #110): drag + zoom interaction prototype.
|
||||
Feeds S6 (#112) its interaction parameters; calibrated live with Alexander.
|
||||
Substrate = the landed outliner (ADR-0013, wf105 verdict "B"): a real tree of blocks,
|
||||
chrome bullets + per-level vertical rules, block-granular selection, storage = nested-bullet
|
||||
markdown (#101). This file reuses wf105's visual language so calibration is about the NEW
|
||||
interactions only.
|
||||
|
||||
Stated assumptions (not calibration axes):
|
||||
- Rows are static text. Editing, Enter-split, Tab/⌥ keys are SETTLED (#105/S3) — not exercised.
|
||||
- Folds are skipped entirely (session-scoped per ADR-0013, orthogonal to drag/zoom;
|
||||
drag-onto-a-folded-block = last child is an S6 implementation detail, noted).
|
||||
- Selection mirrors the app's anchor↔focus model, mapped to mouse: click = single select,
|
||||
⇧click = extend; ↑/↓ single-select, ⇧↑/⇧↓ extend. No ⌘click (not in the app).
|
||||
|
||||
The ONE variant axis — how the drop zone is signalled and who picks the landing depth:
|
||||
A "Fat gaps" — seams between blocks insert (depth auto = following block's depth,
|
||||
shown by the line's left edge); block-middle = drop as LAST child (ring).
|
||||
Context-driven depth: shallow-biased.
|
||||
B "Row bands" — every row split in thirds: top edge = insert before (at row's depth),
|
||||
bottom edge = insert after row's subtree (at row's depth), middle = last
|
||||
child. Row-driven depth: precise, every row offers both moves.
|
||||
C "X-nest" — seams insert like A, but the pointer's X picks the landing depth within the
|
||||
seam: shallow end = sibling of the following block; dragging right walks down
|
||||
the real position ladder (each level = one step deeper) to the deepest legal
|
||||
spot = last child of the block above. The line's indent IS the preview.
|
||||
No sibling-stealing: every dial position is a place in the CURRENT tree
|
||||
(line-insertion semantics — a drop can never absorb blocks).
|
||||
|
||||
Fixed defaults for the common machinery (calibration probes in the aside):
|
||||
drag = subtree travels; grip ⋮⋮ drags (batch if the row is selected, solo if not);
|
||||
body-drag works on already-selected rows; after a drop the moved run IS the selection;
|
||||
zoom-in = double-click a bullet, zoom-out = breadcrumb click or Esc; invalid targets
|
||||
(own subtree, relative-to-moving-block) show a dashed indicator and no-op.
|
||||
|
||||
Ceilings (ponytail: named, upgrade path in the app): hit-testing reads cached row rects
|
||||
(no scroll-mid-drag compensation — keep the doc short); pointer events only, no HTML5 DnD;
|
||||
no animation on the indicator (the app calibrates spring feel natively).
|
||||
NOTE: all innerHTML writes receive esc()-escaped text first — no untrusted HTML enters the DOM.
|
||||
-->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>wf113 — drag + zoom prototype</title>
|
||||
<style>
|
||||
:root {
|
||||
--chrome: #FAF9F3; --paper: #FFFEFB; --ink: #26251F; --muted: #8A867A;
|
||||
--hairline: rgba(38,37,31,.12); --rust: #C96442;
|
||||
--serif: "Valkyrie OT", "Iowan Old Style", Georgia, serif;
|
||||
--mono: "Ubuntu Mono", "SF Mono", Menlo, monospace;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; height: 100%; }
|
||||
body { background: var(--chrome); color: var(--ink); font-family: var(--serif); font-size: 17px; line-height: 1.5; }
|
||||
|
||||
.layout { display: grid; grid-template-columns: 1fr 340px; height: 100vh; }
|
||||
main { display: flex; flex-direction: column; min-width: 0; }
|
||||
.docwrap { flex: 1; display: flex; justify-content: center; overflow: auto; padding: 28px 24px 120px; }
|
||||
.doc { width: 100%; max-width: 640px; background: var(--paper); border: 1px solid var(--hairline);
|
||||
border-radius: 10px; padding: 36px 40px 60px; box-shadow: 0 1px 2px rgba(38,37,31,.04); }
|
||||
|
||||
h1 { font-size: 22px; font-weight: 600; margin: 0 0 2px; }
|
||||
.meta { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
|
||||
|
||||
/* breadcrumb (zoom chrome) */
|
||||
#crumbs { display: none; font-family: var(--mono); font-size: 12px; color: var(--muted);
|
||||
margin: 0 0 16px; line-height: 1.6; }
|
||||
#crumbs.on { display: block; }
|
||||
#crumbs .crumb { cursor: pointer; border-bottom: 1px dotted transparent; padding: 1px 2px; }
|
||||
#crumbs .crumb:hover { color: var(--ink); border-bottom-color: var(--muted); }
|
||||
#crumbs .here { color: var(--rust); cursor: default; }
|
||||
#crumbs .here:hover { color: var(--rust); border-bottom-color: transparent; }
|
||||
#crumbs .sep { margin: 0 5px; opacity: .6; }
|
||||
#crumbs .out { color: var(--rust); cursor: pointer; margin-right: 8px; }
|
||||
#crumbs .out:hover { color: var(--ink); }
|
||||
|
||||
/* ---------- rows (wf105 variant B language = the landed ADR-0013 surface) ---------- */
|
||||
.rows { position: relative; user-select: none; }
|
||||
.row { display: flex; align-items: flex-start; padding: 0 0 1px; position: relative; border-radius: 4px; }
|
||||
.row .pad { flex: none; }
|
||||
.bullet { flex: none; width: 22px; height: 27px; display: flex; align-items: center; justify-content: center;
|
||||
color: var(--muted); cursor: default; border-radius: 4px; }
|
||||
.bullet:hover { color: var(--ink); background: rgba(196,175,138,.15); }
|
||||
.bullet.foldable::before { content: "●"; font-size: 7px; }
|
||||
.bullet.leaf::before { content: "◦"; font-size: 10px; }
|
||||
.row .txt { flex: 1; min-width: 0; padding: 3px 0; }
|
||||
.b-code { font-family: var(--mono); font-size: 14px; background: rgba(38,37,31,.05); border-radius: 3px; padding: 0 3px; }
|
||||
.row .txt strong { font-weight: 640; }
|
||||
.wikichip { font-family: var(--mono); font-size: 13px; color: var(--muted); border-bottom: 1px dotted var(--muted); }
|
||||
.guide { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--hairline); }
|
||||
|
||||
/* grip — the drag affordance, left margin, appears on row hover */
|
||||
.grip { position: absolute; left: -26px; top: 2px; width: 20px; height: 22px; display: flex; align-items: center;
|
||||
justify-content: center; font-family: var(--mono); font-size: 12px; color: var(--muted);
|
||||
opacity: 0; cursor: grab; border-radius: 4px; }
|
||||
.row:hover .grip { opacity: .85; }
|
||||
.grip:hover { color: var(--ink); background: rgba(196,175,138,.2); }
|
||||
|
||||
/* block selection (app's anchor↔focus highlight, mapped to mouse) */
|
||||
.row.sel { background: rgba(196,175,138,.16); box-shadow: inset 2px 0 0 var(--rust); }
|
||||
.row.lifted { opacity: .3; }
|
||||
|
||||
/* ---------- drop indicators ---------- */
|
||||
#dropline { position: absolute; height: 0; border-top: 2px solid var(--rust); border-radius: 2px;
|
||||
pointer-events: none; display: none; }
|
||||
#dropline.bad { border-top-style: dashed; border-top-color: var(--muted); }
|
||||
.row.ring { outline: 2px solid var(--rust); outline-offset: -2px; background: rgba(201,100,66,.08); }
|
||||
.row.ring.bad { outline-style: dashed; outline-color: var(--muted); background: transparent; }
|
||||
|
||||
/* ghost */
|
||||
#ghost { position: fixed; top: 0; left: 0; z-index: 40; pointer-events: none; display: none; max-width: 320px;
|
||||
background: var(--paper); border: 1px solid var(--rust); border-radius: 8px;
|
||||
box-shadow: 0 10px 26px rgba(38,37,31,.22); padding: 8px 12px; font-size: 14px; line-height: 1.45; }
|
||||
#ghost .gchip { font-family: var(--mono); font-size: 10.5px; color: var(--rust); margin-bottom: 3px; }
|
||||
#ghost .gline { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
#ghost .gline.sub { color: var(--muted); font-size: 13px; }
|
||||
|
||||
/* ---------- rail, notes (house pattern) ---------- */
|
||||
aside { border-left: 1px solid var(--hairline); background: var(--chrome); padding: 20px 18px; overflow: auto; }
|
||||
aside h2 { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
|
||||
color: var(--muted); font-weight: 400; margin: 0 0 10px; }
|
||||
#rail { font-family: var(--mono); font-size: 11.5px; line-height: 1.7; white-space: pre-wrap; color: var(--ink);
|
||||
background: var(--paper); border: 1px solid var(--hairline); border-radius: 8px; padding: 12px; }
|
||||
#railnote { font-family: var(--mono); font-size: 11px; color: var(--rust); min-height: 16px; margin-top: 8px; }
|
||||
.keys { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
|
||||
.key { font-family: var(--mono); font-size: 11px; color: var(--muted); border: 1px solid var(--hairline);
|
||||
border-radius: 99px; padding: 2px 9px; background: var(--paper); }
|
||||
.verdictq { margin-top: 18px; font-size: 13px; line-height: 1.55; color: var(--ink); }
|
||||
.verdictq em { color: var(--rust); font-style: normal; }
|
||||
.notes { font-size: 12.5px; color: var(--muted); margin-top: 12px; line-height: 1.55; }
|
||||
.diffhead { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--rust); margin: 16px 0 4px; }
|
||||
button.reset { font-family: var(--mono); font-size: 11px; margin-top: 16px; padding: 4px 10px; border: 1px solid var(--hairline);
|
||||
border-radius: 6px; background: var(--paper); color: var(--muted); cursor: pointer; }
|
||||
|
||||
/* ---------- floating variant switcher ---------- */
|
||||
#switcher { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px;
|
||||
background: #1F1E1A; color: #F5F2E8; border-radius: 99px; padding: 8px 14px; font-family: var(--mono); font-size: 12px;
|
||||
box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 10; }
|
||||
#switcher button { background: none; border: none; color: #F5F2E8; font-size: 14px; cursor: pointer; padding: 0 4px; }
|
||||
#switcher .vlabel b { color: #E8A587; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layout">
|
||||
<main>
|
||||
<div class="docwrap"><div class="doc">
|
||||
<h1>The Long Desk — quarterly essay</h1>
|
||||
<div class="meta">type: outline · prototype wf113 · <span id="vname"></span></div>
|
||||
<div id="crumbs"></div>
|
||||
<div id="stage" class="rows"></div>
|
||||
</div></div>
|
||||
</main>
|
||||
<aside>
|
||||
<h2>Live markdown (storage)</h2>
|
||||
<div id="rail"></div>
|
||||
<div id="railnote"></div>
|
||||
<div class="keys" id="keyrow"></div>
|
||||
<div class="diffhead" id="diffhead"></div>
|
||||
<div class="notes" id="diffnotes"></div>
|
||||
<div class="verdictq" id="verdictq"></div>
|
||||
<button class="reset" id="reset">reset document</button>
|
||||
</aside>
|
||||
</div>
|
||||
<div id="switcher">
|
||||
<button id="prev" title="previous variant">←</button>
|
||||
<span class="vlabel">variant <b id="vkey">A</b> — <span id="vtitle"></span></span>
|
||||
<button id="next" title="next variant">→</button>
|
||||
</div>
|
||||
<div id="ghost"></div>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
// ---------- shared: the document (same SAMPLE as wf105) ----------
|
||||
const SAMPLE = [
|
||||
"- thesis",
|
||||
" - the desk is not furniture, it is a **promise about time**",
|
||||
" - long desks outlast the projects they were built for",
|
||||
" - evidence",
|
||||
" - the monastery scriptorium: standing desks, chained books, silence as infrastructure",
|
||||
" - Darwin's study at Down House — same desk for forty years, the Beagle voyage compressed into a room (this line is deliberately long so you can feel subtree moves over wrapped text)",
|
||||
" - [[drafts/sand-walk]] as the walking counterpart",
|
||||
" - counterargument",
|
||||
" - standing desks as fashion, not discipline",
|
||||
" - reply: fashion fades, the `posture` persists",
|
||||
"- structure",
|
||||
" - open on the physical object, close on the habit",
|
||||
" - three movements, one per century",
|
||||
"- cuts from the first draft",
|
||||
" - the `typewriter` paragraph — keep for the epigraph file",
|
||||
" - everything about [[reading-rooms]]",
|
||||
].join("\n");
|
||||
|
||||
const UNITS = 2;
|
||||
const esc = s => s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");
|
||||
function inlineMD(s){
|
||||
return esc(s)
|
||||
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
||||
.replace(/`([^`]+)`/g, '<span class="b-code">$1</span>')
|
||||
.replace(/\[\[([^\]]+)\]\]/g, '<span class="wikichip">[[$1]]</span>');
|
||||
}
|
||||
|
||||
// ---------- tree model (wf105 B machinery; ops are path-addressed like the real OutlineTree) ----------
|
||||
let root = null, uid = 0;
|
||||
function parse(){
|
||||
root = { id: uid++, text: "", children: [] };
|
||||
const stack = [{ d: -1, n: root }];
|
||||
for (const l of SAMPLE.split("\n")){
|
||||
const m = l.match(/^(\s*)[-*] (.*)$/); if (!m) continue;
|
||||
const d = Math.floor(m[1].length / UNITS);
|
||||
const node = { id: uid++, text: m[2], children: [] };
|
||||
while (stack[stack.length - 1].d >= d) stack.pop();
|
||||
stack[stack.length - 1].n.children.push(node);
|
||||
stack.push({ d, n: node });
|
||||
}
|
||||
}
|
||||
function serialize(){
|
||||
const out = [];
|
||||
(function walk(nodes, d){
|
||||
for (const n of nodes){ out.push(" ".repeat(d * UNITS) + "- " + n.text); walk(n.children, d + 1); }
|
||||
})(root.children, 0);
|
||||
return out.join("\n");
|
||||
}
|
||||
function findNode(id){ // → {node, parentArray, index} | null
|
||||
const stack = [{ arr: root.children, node: null }];
|
||||
// DFS with explicit frame
|
||||
const rec = (arr) => { for (let k = 0; k < arr.length; k++){ if (arr[k].id === id) return { node: arr[k], parentArray: arr, index: k }; const r = rec(arr[k].children); if (r) return r; } return null; };
|
||||
return rec(root.children);
|
||||
}
|
||||
function ancestorsOf(id){ // node chain from root.children level down to the node's parent []
|
||||
const chain = [];
|
||||
(function walk(nodes){
|
||||
for (const n of nodes){
|
||||
if (n.id === id) return true;
|
||||
chain.push(n);
|
||||
if (walk(n.children)) return true;
|
||||
chain.pop();
|
||||
}
|
||||
return false;
|
||||
})(root.children);
|
||||
return chain;
|
||||
}
|
||||
function preorderIds(nodes, out){
|
||||
for (const n of nodes){ out.push(n.id); preorderIds(n.children, out); }
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---------- projection (zoom = presenter rooted at a node) ----------
|
||||
let zoomId = null; // null = whole document
|
||||
let rows = []; // visible projection: {id, node, d (display depth), el, rect, parentArray, index}
|
||||
function project(){
|
||||
rows = [];
|
||||
const base = zoomId == null ? root : findNode(zoomId)?.node;
|
||||
if (!base){ zoomId = null; return project(); }
|
||||
(function walk(nodes, d, parentArray){
|
||||
for (let k = 0; k < nodes.length; k++){
|
||||
const n = nodes[k];
|
||||
rows.push({ id: n.id, node: n, d, el: null, rect: null, parentArray: nodes, index: k });
|
||||
walk(n.children, d + 1, n.children);
|
||||
}
|
||||
})(base.children, 0, base.children);
|
||||
}
|
||||
const rowOf = id => rows.find(r => r.id === id);
|
||||
const visibleIds = () => rows.map(r => r.id);
|
||||
|
||||
// ---------- selection (the app's anchor↔focus, mapped to mouse) ----------
|
||||
let selection = new Set(), anchorId = null, focusId = null;
|
||||
function selectSingle(id){ selection = new Set([id]); anchorId = id; focusId = id; }
|
||||
function extendTo(id){
|
||||
if (anchorId == null || !rowOf(anchorId)){ selectSingle(id); return; }
|
||||
const vis = visibleIds();
|
||||
const a = vis.indexOf(anchorId), f = vis.indexOf(id);
|
||||
if (a < 0 || f < 0) return;
|
||||
const [lo, hi] = a < f ? [a, f] : [f, a];
|
||||
selection = new Set(vis.slice(lo, hi + 1));
|
||||
focusId = id;
|
||||
}
|
||||
function clearSelection(){ selection = new Set(); anchorId = null; focusId = null; }
|
||||
|
||||
// ---------- render ----------
|
||||
let stage = null, dropline = null;
|
||||
function render(){
|
||||
stage.innerHTML = "";
|
||||
for (const r of rows){
|
||||
const row = document.createElement("div");
|
||||
row.className = "row" + (selection.has(r.id) ? " sel" : "");
|
||||
for (let g = 0; g < r.d; g++){
|
||||
const guide = document.createElement("div"); guide.className = "guide";
|
||||
guide.style.left = (g * UNITS * 9 + 11) + "px"; row.appendChild(guide);
|
||||
}
|
||||
const pad = document.createElement("div"); pad.className = "pad"; pad.style.width = (r.d * UNITS * 9) + "px"; row.appendChild(pad);
|
||||
const grip = document.createElement("div"); grip.className = "grip"; grip.textContent = "⋮⋮"; grip.title = "drag block (with subtree)";
|
||||
row.appendChild(grip);
|
||||
const bullet = document.createElement("div");
|
||||
bullet.className = "bullet " + (r.node.children.length ? "foldable" : "leaf");
|
||||
bullet.title = "double-click: zoom in";
|
||||
row.appendChild(bullet);
|
||||
const txt = document.createElement("div"); txt.className = "txt"; txt.innerHTML = inlineMD(r.node.text);
|
||||
row.appendChild(txt);
|
||||
stage.appendChild(row);
|
||||
r.el = row;
|
||||
}
|
||||
stage.appendChild(dropline); // absolute-positioned against .rows (position:relative)
|
||||
// measure rects relative to the rows container
|
||||
const baseRect = stage.getBoundingClientRect();
|
||||
for (const r of rows) r.rect = { top: r.el.getBoundingClientRect().top - baseRect.top,
|
||||
bottom: r.el.getBoundingClientRect().bottom - baseRect.top,
|
||||
rowLeft: r.el.getBoundingClientRect().left, h: r.el.getBoundingClientRect().height };
|
||||
drawCrumbs();
|
||||
rail();
|
||||
}
|
||||
function drawCrumbs(){
|
||||
const c = document.getElementById("crumbs");
|
||||
if (zoomId == null){ c.className = ""; c.innerHTML = ""; return; }
|
||||
const chain = ancestorsOf(zoomId);
|
||||
const here = findNode(zoomId)?.node;
|
||||
let html = `<span class="out" data-zoom="root" title="zoom all the way out">⟵ zoom out</span>`;
|
||||
html += `<span class="crumb" data-zoom="root">The Long Desk</span>`;
|
||||
for (const n of chain) html += `<span class="sep">/</span><span class="crumb" data-zoom="${n.id}">${esc(short(n.text))}</span>`;
|
||||
if (here) html += `<span class="sep">/</span><span class="here">${esc(short(here.text))}</span>`;
|
||||
c.className = "on"; c.innerHTML = html;
|
||||
}
|
||||
const short = t => { t = t.replace(/[*`[\]]/g, ""); return t.length > 26 ? t.slice(0, 25) + "…" : t; };
|
||||
function rail(){ document.getElementById("rail").textContent = serialize(); }
|
||||
function note(msg){ document.getElementById("railnote").textContent = msg; }
|
||||
|
||||
// ---------- zoom ----------
|
||||
function zoomTo(id){
|
||||
zoomId = id;
|
||||
project();
|
||||
// selection survives only if fully visible
|
||||
const vis = new Set(visibleIds());
|
||||
for (const sid of [...selection]) if (!vis.has(sid)) { clearSelection(); break; }
|
||||
render();
|
||||
note(id == null ? "zoom: whole document" : `zoom: rooted at “${short(findNode(id).node.text)}” — depths re-based, breadcrumb above`);
|
||||
}
|
||||
|
||||
// ---------- drag ----------
|
||||
let drag = null; // {ids, ghostEl, target, bad}
|
||||
function draggedSet(fromId){
|
||||
let ids;
|
||||
if (selection.has(fromId)){
|
||||
// the selection rides: preorder order, descendants of selected ancestors deduped
|
||||
const sel = selection;
|
||||
ids = [];
|
||||
(function walk(nodes, under){
|
||||
for (const n of nodes){
|
||||
const hit = sel.has(n.id);
|
||||
if (hit && !under){ ids.push(n.id); }
|
||||
walk(n.children, under || hit);
|
||||
}
|
||||
})(root.children, false);
|
||||
} else ids = [fromId];
|
||||
return ids;
|
||||
}
|
||||
function startDrag(ids, x, y){
|
||||
drag = { ids, target: null, bad: false };
|
||||
for (const r of rows) if (drag.ids.includes(r.id)) r.el.classList.add("lifted");
|
||||
const g = document.getElementById("ghost");
|
||||
let desc = 0;
|
||||
for (const id of ids){ const f = findNode(id); desc += preorderIds(f.node.children, []).length; }
|
||||
g.innerHTML = `<div class="gchip">${ids.length} block${ids.length > 1 ? "s" : ""}${desc ? " · " + desc + " descendant" + (desc > 1 ? "s" : "") : ""}</div>` +
|
||||
ids.slice(0, 3).map((id, k) => `<div class="gline${k ? " sub" : ""}">${esc(short(findNode(id).node.text))}</div>`).join("") +
|
||||
(ids.length > 3 ? `<div class="gline sub">…</div>` : "");
|
||||
g.style.display = "block";
|
||||
moveGhost(x, y);
|
||||
note(`dragging ${ids.length} block${ids.length > 1 ? "s" : ""} (+${desc}) — Esc cancels`);
|
||||
}
|
||||
function moveGhost(x, y){
|
||||
const g = document.getElementById("ghost");
|
||||
g.style.transform = `translate(${x + 14}px, ${y + 12}px)`;
|
||||
}
|
||||
function endDragVisual(){
|
||||
document.getElementById("ghost").style.display = "none";
|
||||
dropline.style.display = "none";
|
||||
document.querySelectorAll(".row.ring, .row.absorb").forEach(el => el.classList.remove("ring", "absorb", "bad"));
|
||||
document.querySelectorAll(".row.lifted").forEach(el => el.classList.remove("lifted"));
|
||||
}
|
||||
|
||||
// ----- hit testing: pointer → target, per-variant policy -----
|
||||
// target vocabulary (references by NODE ID, resolved AFTER extraction — the app's re-resolve-by-id discipline):
|
||||
// {kind:"before", ref} insert before ref (as sibling) — depth shown = ref's depth
|
||||
// {kind:"after", ref} insert after ref's subtree (as next sibling)
|
||||
// {kind:"onto", ref} last child of ref
|
||||
// walk up the REAL ancestor chain of the row's node: nearest row above at display depth d that is an ancestor
|
||||
function ancestorRowAt(rowId, d){
|
||||
const r = rowOf(rowId); if (!r) return null;
|
||||
if (r.d === d) return r;
|
||||
for (let i = rows.indexOf(r) - 1; i >= 0; i--){
|
||||
if (rows[i].d === d && isAncestor(rows[i].id, rowId)) return rows[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function isAncestor(maybeAnc, id){
|
||||
return ancestorsOf(id).some(n => n.id === maybeAnc);
|
||||
}
|
||||
|
||||
function hitTest(px, py){
|
||||
// py relative to rows container; px absolute (client)
|
||||
if (!rows.length) return null;
|
||||
const first = rows[0], last = rows[rows.length - 1];
|
||||
if (py < first.rect.top + 6) return seamTarget(null, rows[0]); // above the first block
|
||||
if (py > last.rect.bottom - 6) return seamTarget(rows[rows.length - 1], null); // below the last
|
||||
for (const r of rows){
|
||||
const { top, bottom, h } = r.rect;
|
||||
if (py < top || py >= bottom) continue;
|
||||
const rel = (py - top) / h;
|
||||
if (VARIANT === "A"){
|
||||
if (rel < 0.30){ const i = rows.indexOf(r); return seamTarget(rows[i - 1] || null, r); }
|
||||
if (rel > 0.70){ const i = rows.indexOf(r); return seamTarget(r, rows[i + 1] || null); }
|
||||
return { kind: "onto", ref: r.id };
|
||||
} else if (VARIANT === "B"){
|
||||
if (rel < 0.33){ return { kind: "before", ref: r.id }; }
|
||||
if (rel > 0.67){ return { kind: "after", ref: r.id }; }
|
||||
return { kind: "onto", ref: r.id };
|
||||
} else { // C — A's bands (seam / onto / seam), but seams resolve through the x-dial ladder
|
||||
const i = rows.indexOf(r);
|
||||
const seam = rel < 0.30
|
||||
? xDepth(seamTarget(rows[i - 1] || null, r), px)
|
||||
: (rel > 0.70 ? xDepth(seamTarget(r, rows[i + 1] || null), px) : null);
|
||||
return seam || { kind: "onto", ref: r.id };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// seam (U,L) → A-rule target: insert before L at L's depth; end seam → after U; top seam → before first
|
||||
function seamTarget(U, L){
|
||||
if (L) return { kind: "before", ref: L.id };
|
||||
if (U) return { kind: "after", ref: U.id };
|
||||
return null;
|
||||
}
|
||||
// C-rule: the seam between U and L offers a LADDER of real positions: rung 0 = insert before L;
|
||||
// each next rung = LAST CHILD of the next node on U's ancestor chain (C1 = child of L's-level
|
||||
// ancestor containing U, down to U itself). Pointer x walks the rungs; every rung is a real
|
||||
// spot in the current tree — a drop can never steal siblings (line-insertion semantics).
|
||||
function xDepth(seam, px){
|
||||
if (!seam) return null;
|
||||
if (seam.kind !== "before") return seam; // end seam: fixed position
|
||||
const L = rowOf(seam.ref); if (!L) return seam;
|
||||
const U = rows[rows.indexOf(L) - 1] || null;
|
||||
if (!U) return { kind: "before", ref: L.id };
|
||||
const rungs = [{ kind: "before", ref: L.id }];
|
||||
for (let k = L.d + 1; k <= U.d; k++){
|
||||
const node = ancestorRowAt(U.id, k); // k = U.d → U itself
|
||||
if (node) rungs.push({ kind: "onto", ref: node.id });
|
||||
}
|
||||
const baseX = L.rect.rowLeft + 11 + L.d * UNITS * 9; // L's marker column; +18px per rung
|
||||
let idx = Math.round((px - baseX) / (UNITS * 9));
|
||||
idx = Math.max(0, Math.min(rungs.length - 1, idx));
|
||||
return rungs[idx];
|
||||
}
|
||||
|
||||
// ----- target → narration + indicator geometry -----
|
||||
function describeTarget(t){
|
||||
if (!t) return { text: "", bad: false };
|
||||
const name = id => short(findNode(id)?.node?.text || "?");
|
||||
const bad = targetIsInvalid(t);
|
||||
let text;
|
||||
if (t.kind === "before") text = `drop: insert before “${name(t.ref)}” · depth ${rowOf(t.ref)?.d ?? "?"}`;
|
||||
else if (t.kind === "after") text = `drop: insert after “${name(t.ref)}” subtree · depth ${rowOf(t.ref)?.d ?? "?"}`;
|
||||
else text = `drop: last child of “${name(t.ref)}”${findNode(t.ref)?.node.children.length ? "" : " (empty — first child)"}`;
|
||||
return { text: bad ? text + " ✕ inside moved subtree — no-op" : text, bad };
|
||||
}
|
||||
function targetIsInvalid(t){
|
||||
if (!t) return false;
|
||||
const ids = drag ? drag.ids : [];
|
||||
if (!ids.length) return false;
|
||||
// target relative to a moving block, or inside one?
|
||||
if (["before", "after", "onto"].includes(t.kind) && ids.includes(t.ref)) return true;
|
||||
if (ancestorsOf(t.ref).some(n => ids.includes(n.id))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function showTarget(t, bad){
|
||||
dropline.style.display = "none";
|
||||
document.querySelectorAll(".row.ring, .row.absorb").forEach(el => el.classList.remove("ring", "absorb", "bad"));
|
||||
if (!t) return;
|
||||
if (t.kind === "onto"){
|
||||
const r = rowOf(t.ref);
|
||||
if (r){ r.el.classList.add("ring"); if (bad) r.el.classList.add("bad"); }
|
||||
return;
|
||||
}
|
||||
let y, d;
|
||||
if (t.kind === "before" || t.kind === "after"){
|
||||
const r = rowOf(t.ref); if (!r) return;
|
||||
y = t.kind === "before" ? r.rect.top : r.rect.bottom;
|
||||
d = r.d;
|
||||
}
|
||||
const leftPx = 11 + d * UNITS * 9; // the dropped block's bullet column at the resulting depth
|
||||
const w = stage.clientWidth;
|
||||
dropline.style.display = "block";
|
||||
dropline.style.top = (y - 1) + "px";
|
||||
dropline.style.left = leftPx + "px";
|
||||
dropline.style.width = (w - leftPx - 4) + "px";
|
||||
dropline.className = bad ? "bad" : "";
|
||||
}
|
||||
|
||||
// ----- the drop: extract moved subtrees, re-resolve refs by id, splice -----
|
||||
function drop(){
|
||||
const t = drag.target;
|
||||
const ids = drag.ids;
|
||||
if (!t || targetIsInvalid(t)){ endDragVisual(); note(t ? "drop cancelled — target inside the moved subtree" : "drop cancelled"); drag = null; return; }
|
||||
|
||||
// capture semantics BEFORE extraction
|
||||
const ontoNode = t.kind === "onto" ? findNode(t.ref).node : null;
|
||||
|
||||
// extract the moved subtrees (preorder)
|
||||
const moved = [];
|
||||
for (const id of ids){
|
||||
const f = findNode(id);
|
||||
if (f){ f.parentArray.splice(f.index, 1); moved.push(f.node); }
|
||||
}
|
||||
|
||||
const land = (arr, idx) => arr.splice(idx, 0, ...moved);
|
||||
|
||||
let msg = "";
|
||||
if (ontoNode){ land(ontoNode.children, ontoNode.children.length); msg = `child of “${short(ontoNode.text)}”`; }
|
||||
else if (t.kind === "before"){
|
||||
const f = findNode(t.ref); if (!f){ restore(moved); return; }
|
||||
land(f.parentArray, f.index); msg = `before “${short(f.node.text)}”`;
|
||||
}
|
||||
else if (t.kind === "after"){
|
||||
const f = findNode(t.ref); if (!f){ restore(moved); return; }
|
||||
land(f.parentArray, f.index + 1); msg = `after “${short(f.node.text)}”`;
|
||||
}
|
||||
|
||||
project();
|
||||
// selection = the moved run (drop hands the run to the next op)
|
||||
selection = new Set(moved.map(n => n.id));
|
||||
anchorId = moved[0]?.id ?? null; focusId = anchorId;
|
||||
render();
|
||||
endDragVisual();
|
||||
drag = null;
|
||||
note(`drop: ${ids.length} block${ids.length > 1 ? "s" : ""} → ${msg} — selection = the moved run; storage rail moved`);
|
||||
}
|
||||
function restore(moved){ root.children.push(...moved); project(); render(); note("drop failed — restored"); }
|
||||
|
||||
// ---------- pointer plumbing ----------
|
||||
function armDrag(e, id, fromGrip){
|
||||
const startX = e.clientX, startY = e.clientY;
|
||||
let active = false;
|
||||
const ids = draggedSet(id);
|
||||
const move = ev => {
|
||||
if (!active){
|
||||
if (Math.hypot(ev.clientX - startX, ev.clientY - startY) < 4) return;
|
||||
active = true;
|
||||
startDrag(ids, ev.clientX, ev.clientY);
|
||||
}
|
||||
ev.preventDefault();
|
||||
moveGhost(ev.clientX, ev.clientY);
|
||||
const stageRect = stage.getBoundingClientRect();
|
||||
const t = hitTest(ev.clientX, ev.clientY - stageRect.top);
|
||||
const { text, bad } = describeTarget(t);
|
||||
drag.target = t;
|
||||
showTarget(t, bad);
|
||||
note(text || "dragging — no target");
|
||||
};
|
||||
const up = ev => {
|
||||
window.removeEventListener("pointermove", move);
|
||||
window.removeEventListener("pointerup", up);
|
||||
if (active){ if (drag) drop(); }
|
||||
else if (!fromGrip){ /* plain click on row: handled by click listener */ }
|
||||
};
|
||||
window.addEventListener("pointermove", move);
|
||||
window.addEventListener("pointerup", up);
|
||||
}
|
||||
|
||||
function wire(){
|
||||
stage.addEventListener("pointerdown", e => {
|
||||
const rowEl = e.target.closest(".row"); if (!rowEl) return;
|
||||
const r = rows.find(x => x.el === rowEl); if (!r) return;
|
||||
const onGrip = e.target.closest(".grip");
|
||||
if (e.button !== 0) return;
|
||||
if (onGrip){ e.preventDefault(); armDrag(e, r.id, true); return; }
|
||||
if (e.shiftKey){ e.preventDefault(); extendTo(r.id); render(); return; }
|
||||
if (selection.has(r.id)){ armDrag(e, r.id, false); return; } // body-drag on a selected row
|
||||
selectSingle(r.id); render(); // click = fresh single select
|
||||
});
|
||||
stage.addEventListener("dblclick", e => {
|
||||
if (e.target.closest(".bullet")){
|
||||
const rowEl = e.target.closest(".row");
|
||||
const r = rows.find(x => x.el === rowEl);
|
||||
if (r) zoomTo(r.id);
|
||||
}
|
||||
});
|
||||
document.getElementById("crumbs").addEventListener("click", e => {
|
||||
const c = e.target.closest(".crumb, .out"); if (!c) return;
|
||||
zoomTo(c.dataset.zoom === "root" ? null : +c.dataset.zoom);
|
||||
});
|
||||
document.addEventListener("keydown", e => {
|
||||
if (e.key === "Escape"){
|
||||
if (drag){ endDragVisual(); drag = null; note("drag cancelled (Esc)"); return; }
|
||||
if (selection.size){ clearSelection(); render(); note("selection cleared"); return; }
|
||||
if (zoomId != null){ zoomTo(ancestorsOf(zoomId).pop()?.id ?? null); return; }
|
||||
return;
|
||||
}
|
||||
if (drag) return; // no variant cycling / selection keys mid-drag
|
||||
if (e.key === "ArrowUp" || e.key === "ArrowDown"){
|
||||
const dir = e.key === "ArrowUp" ? -1 : 1;
|
||||
const vis = visibleIds();
|
||||
const i = focusId != null ? vis.indexOf(focusId) : -1;
|
||||
let j = i < 0 ? (dir > 0 ? 0 : vis.length - 1) : Math.max(0, Math.min(vis.length - 1, i + dir));
|
||||
if (i === j) return;
|
||||
e.preventDefault();
|
||||
if (e.shiftKey) extendTo(vis[j]); else selectSingle(vis[j]);
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (!(e.target.isContentEditable || e.target.tagName === "INPUT")){
|
||||
if (e.key === "ArrowLeft" || e.key === "ArrowRight") cycle(e.key === "ArrowRight" ? 1 : -1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- variant plumbing ----------
|
||||
const VARIANTS = ["A", "B", "C"];
|
||||
let VARIANT = new URLSearchParams(location.search).get("variant") || "A";
|
||||
if (!VARIANTS.includes(VARIANT)) VARIANT = "A";
|
||||
const META = {
|
||||
A: {
|
||||
title: "Fat gaps",
|
||||
keys: `click select · ⇧click extend · drag ⋮⋮ (batch if selected) · drag a selected row · dblclick ● zoom in · crumb/Esc out · ←/→ variant`,
|
||||
diff: `Seams between blocks insert; the landing depth is picked FOR you (the following block's depth — context-biased shallow) and shown by the line's left edge. The middle band of a block = drop as last child (ring). Never absorbs. Simplest mental model: <em>the seam inserts, the block nests</em>.`,
|
||||
q: `A — enough control? Feel the seam between a deep block and a shallow one: you always land shallow.`
|
||||
},
|
||||
B: {
|
||||
title: "Row bands",
|
||||
keys: `click select · ⇧click extend · drag ⋮⋮ (batch if selected) · drag a selected row · dblclick ● zoom in · crumb/Esc out · ←/→ variant`,
|
||||
diff: `Every row is three bands: top edge = insert before at the row's depth, bottom edge = insert after its subtree, middle = last child. No seams to hunt — precision comes from the row you hover. Never absorbs. Row-biased: bottom of a deep row lands you deep.`,
|
||||
q: `B — are the thirds discoverable without being told? Twitchy or precise?`
|
||||
},
|
||||
C: {
|
||||
title: "X-nest (depth dial)",
|
||||
keys: `click select · ⇧click extend · drag ⋮⋮ (batch if selected) · drag a selected row · dblclick ● zoom in · crumb/Esc out · ←/→ variant · drag RIGHT in a seam to nest`,
|
||||
diff: `Like A, but the pointer's X is a depth dial inside the seam: shallow end = sibling of the block below; drag right and the line walks down one real level at a time to the deepest legal spot — last child of the block above. Every dial position is a place in the current tree: a drop can <em>never</em> steal siblings (line-insertion semantics), so the line's indent is the whole truth.`,
|
||||
q: `C — is the dial worth the x-sensitivity? Feel the ladder between two same-level blocks vs the seam above a deep subtree.`
|
||||
}
|
||||
};
|
||||
function showVariant(v){
|
||||
VARIANT = v;
|
||||
const url = new URL(location.href); url.searchParams.set("variant", v); history.replaceState(null, "", url);
|
||||
document.getElementById("vkey").textContent = v;
|
||||
document.getElementById("vtitle").textContent = META[v].title;
|
||||
document.getElementById("vname").textContent = `variant ${v} — ${META[v].title}`;
|
||||
document.getElementById("diffhead").textContent = `drop model ${v}`;
|
||||
document.getElementById("diffnotes").innerHTML = META[v].diff;
|
||||
document.getElementById("verdictq").innerHTML = `<em>calibration probes:</em> drop model A/B/C? · line-at-resulting-depth + live rail note = enough auto-nest feedback? · grip = batch-when-selected, solo-when-not — right? · body-drag on selected rows — keep? · zoom: dblclick-bullet in, crumb/Esc out — or single-click? · dashed = no-op, enough? — then: <em>${META[v].q}</em>`;
|
||||
document.getElementById("keyrow").innerHTML = META[v].keys.split("·").map(k => `<span class="key">${k.trim()}</span>`).join("");
|
||||
note("");
|
||||
parse(); project(); clearSelection(); zoomId = null; render();
|
||||
}
|
||||
const cycle = d => { const i = VARIANTS.indexOf(VARIANT); showVariant(VARIANTS[(i + d + VARIANTS.length) % VARIANTS.length]); };
|
||||
document.getElementById("prev").onclick = () => cycle(-1);
|
||||
document.getElementById("next").onclick = () => cycle(1);
|
||||
document.getElementById("reset").onclick = () => { note("reset"); parse(); project(); clearSelection(); render(); };
|
||||
|
||||
// ---------- boot ----------
|
||||
stage = document.getElementById("stage");
|
||||
dropline = document.createElement("div");
|
||||
dropline.id = "dropline";
|
||||
wire();
|
||||
showVariant(VARIANT);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user