Public
Edited
Mar 9
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.button("dettach", { reduce: () => domNode.remove() })
Insert cell
Insert cell
Insert cell
Insert cell
reparent_randomly = {
if (random) {
while (true) {
const pick = Math.floor(Math.random() * 3);
document.querySelectorAll("button")[pick].click();
yield new Promise((r) => setTimeout(r, 3000));
}
}
}
Insert cell
Insert cell
preserveFocus = (node) => {
let lastFocused = null;

function onFocus(e) {
if (node.contains(e.target)) {
lastFocused = e.target;
} else {
lastFocused = null;
}
}
function onPointerDown(e) {
if (!node.contains(e.target)) {
lastFocused = null;
}
}

document.addEventListener("pointerdown", onPointerDown, true);
document.addEventListener("focus", onFocus, true);

const stopWatchingConnection = trackParentChain(
node,
() => {
if (lastFocused && node.contains(lastFocused)) {
//console.log("restore focus");
lastFocused.focus();
} else {
// console.log("skip focus", node.contains(lastFocused), lastFocused);
}
},
() => {}
);

// Dispose
return () => {
document.removeEventListener("pointerdown", onPointerDown, true);
document.removeEventListener("focus", onFocus, true);
stopWatchingConnection();
};
}
Insert cell
invalidation.then(preserveFocus(domNode))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more