web: URL routes, deep links and history navigation (L6)
This commit is contained in:
+45
-6
@@ -932,6 +932,11 @@ function pathFromPoints(points) {
|
||||
* page's `prefers-reduced-motion` setting; when false the
|
||||
* active stage keeps a static ring instead of pulsing.
|
||||
* expanded — start with the taller panel.
|
||||
* selectedKey — open the definition pane for this node at mount (the
|
||||
* deep-linked stage route) without a synthetic click.
|
||||
* onSelectionChange — called with the selected node key, or null when the pane
|
||||
* closes, after the in-graph selection changes. The caller
|
||||
* records the URL; it must not rebuild the graph to do so.
|
||||
* onStageTap — called with the node key on a node click. When supplied
|
||||
* (the run tab), the click opens the caller's own stage
|
||||
* pane and no definition pane is drawn.
|
||||
@@ -1157,7 +1162,7 @@ export function mount(container, graph, options = {}) {
|
||||
view.append(row);
|
||||
}
|
||||
|
||||
function selectNode(key) {
|
||||
function selectNode(key, { notify = true } = {}) {
|
||||
state.selectedKey = key;
|
||||
const node = layout.nodes.find((candidate) => candidate.key === key) ?? null;
|
||||
const stage = stagesByKey.get(key) ?? null;
|
||||
@@ -1169,11 +1174,7 @@ export function mount(container, graph, options = {}) {
|
||||
head.append(title, type);
|
||||
const close = el("button", "graph-pane-close", "Close");
|
||||
close.type = "button";
|
||||
close.addEventListener("click", () => {
|
||||
pane.hidden = true;
|
||||
pane.replaceChildren();
|
||||
state.selectedKey = null;
|
||||
});
|
||||
close.addEventListener("click", () => closePane());
|
||||
head.append(close);
|
||||
children.push(head);
|
||||
|
||||
@@ -1200,6 +1201,19 @@ export function mount(container, graph, options = {}) {
|
||||
|
||||
pane.replaceChildren(...children);
|
||||
pane.hidden = false;
|
||||
if (notify && typeof options.onSelectionChange === "function") {
|
||||
options.onSelectionChange(state.selectedKey);
|
||||
}
|
||||
}
|
||||
|
||||
/** Close the definition pane, telling the caller so it can restore the URL. */
|
||||
function closePane({ notify = true } = {}) {
|
||||
pane.hidden = true;
|
||||
pane.replaceChildren();
|
||||
state.selectedKey = null;
|
||||
if (notify && typeof options.onSelectionChange === "function") {
|
||||
options.onSelectionChange(null);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Elapsed badge (live run only) ---------------------------------------
|
||||
@@ -1327,6 +1341,31 @@ export function mount(container, graph, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
// A deep-linked stage opens its pane after the graph is mounted, without a
|
||||
// synthetic click and without notifying the caller (the URL already says so).
|
||||
// Bring the pane itself into view: the graph is tall, so a deep link that only
|
||||
// revealed the pane's header below the fold would not show the stage.
|
||||
if (options.selectedKey != null) {
|
||||
const key = String(options.selectedKey);
|
||||
if (layout.nodes.some((node) => node.key === key)) {
|
||||
selectNode(key, { notify: false });
|
||||
// The pane is still detached while the caller builds the detail, so reveal
|
||||
// it on the next frame, once renderContent has put it in the document. The
|
||||
// sticky top bar must stay clear of the pane head: scroll to the pane's top
|
||||
// minus the bar's own measured height (CSS scroll-margin-top is the
|
||||
// fallback for browsers that reveal it another way).
|
||||
const reveal = () => {
|
||||
if (typeof pane.getBoundingClientRect !== "function") return;
|
||||
const topbar = document.querySelector(".topbar");
|
||||
const bar = topbar?.getBoundingClientRect?.().height ?? 0;
|
||||
const top = pane.getBoundingClientRect().top + (window.scrollY ?? 0) - bar - 12;
|
||||
window.scrollTo?.({ top: Math.max(0, top), behavior: "instant" });
|
||||
};
|
||||
if (typeof requestAnimationFrame === "function") requestAnimationFrame(reveal);
|
||||
else reveal();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
unmount() {
|
||||
if (elapsedTimer != null) {
|
||||
|
||||
Reference in New Issue
Block a user