A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
explorer: Allow resizing explorer windows (#14458)
Adam Bratschi-Kaye6572e8e7cf39
diff --git a/crates/explorer/src/index.css b/crates/explorer/src/index.cssindex 59e83c98a8..c7c405222a 100644--- a/crates/explorer/src/index.css+++ b/crates/explorer/src/index.css@@ -29,20 +29,26 @@ body {color: #101010;}-#wat {+#wat,+#clif,+#asm {flex: 1;+ min-width: 0;height: 100%;overflow: scroll;}-#clif {- flex: 1;- height: 100%;- overflow: scroll;+.resize-handle {+ flex: 0 0 5px;+ cursor: col-resize;+ background: #dddddd;}-#asm {- flex: 1;- height: 100%;- overflow: scroll;+.resize-handle:hover {+ background: #999999;+}++body.resizing {+ cursor: col-resize;+ user-select: none;}diff --git a/crates/explorer/src/index.js b/crates/explorer/src/index.jsindex 6732fcb343..a1be813287 100644--- a/crates/explorer/src/index.js+++ b/crates/explorer/src/index.js@@ -218,6 +218,47 @@ const createDivForCode = () => {return div;};+const panes = ["wat", "clif", "asm"]+ .map(id => document.getElementById(id))+ .filter(pane => pane !== null);++for (let i = 0; i < panes.length - 1; i++) {+ const left = panes[i];+ const right = panes[i + 1];+ const handle = document.createElement("div");+ handle.classList.add("resize-handle");+ left.after(handle);++ handle.addEventListener("pointerdown", event => {+ const startX = event.clientX;+ const leftWidth = left.getBoundingClientRect().width;+ const rightWidth = right.getBoundingClientRect().width;+ const totalWidth = leftWidth + rightWidth;++ const resize = event => {+ const newLeftWidth = Math.max(+ 0,+ Math.min(totalWidth, leftWidth + event.clientX - startX),+ );+ left.style.flex = `0 0 ${newLeftWidth}px`;+ right.style.flex = `0 0 ${totalWidth - newLeftWidth}px`;+ };++ const stopResizing = () => {+ handle.removeEventListener("pointermove", resize);+ handle.removeEventListener("pointerup", stopResizing);+ handle.removeEventListener("pointercancel", stopResizing);+ document.body.classList.remove("resizing");+ };++ handle.setPointerCapture(event.pointerId);+ handle.addEventListener("pointermove", resize);+ handle.addEventListener("pointerup", stopResizing);+ handle.addEventListener("pointercancel", stopResizing);+ document.body.classList.add("resizing");+ });+}+// Render the CLIF (if any).const clifElem = document.getElementById("clif");if (clifElem) {