diff --git a/server/shell.ts b/server/shell.ts
index ecf2294..469a51f 100644
--- a/server/shell.ts
+++ b/server/shell.ts
@@ -227,7 +227,7 @@ export function renderShell(opts: ShellOptions): string {
-
-
@@ -281,16 +286,16 @@ export function renderShell(opts: ShellOptions): string {
window.__rspaceInstallPrompt = () => { e.prompt(); return e.userChoice; };
window.dispatchEvent(new CustomEvent("rspace-install-available"));
});
- // ── Settings panel toggle ──
+ // ── Settings panel toggle (close history first) ──
document.getElementById('settings-btn')?.addEventListener('click', () => {
- const panel = document.querySelector('rstack-space-settings');
- if (panel) panel.toggle();
+ document.querySelector('rstack-history-panel')?.close();
+ document.querySelector('rstack-space-settings')?.toggle();
});
- // ── History panel toggle ──
+ // ── History panel toggle (close settings first) ──
document.getElementById('history-btn')?.addEventListener('click', () => {
- const panel = document.querySelector('rstack-history-panel');
- if (panel) panel.toggle();
+ document.querySelector('rstack-space-settings')?.close();
+ document.querySelector('rstack-history-panel')?.toggle();
});
// Wire history panel to offline runtime doc (module pages)
diff --git a/shared/components/rstack-history-panel.ts b/shared/components/rstack-history-panel.ts
index cf1908b..20148ac 100644
--- a/shared/components/rstack-history-panel.ts
+++ b/shared/components/rstack-history-panel.ts
@@ -51,17 +51,28 @@ export class RStackHistoryPanel extends HTMLElement {
}
}
+ private _clickOutsideHandler = (e: MouseEvent) => {
+ const path = e.composedPath();
+ if (!path.includes(this) && !path.includes(document.getElementById("history-btn")!)) {
+ this.close();
+ }
+ };
+
connectedCallback() {
if (!this.shadowRoot) this.attachShadow({ mode: "open" });
this._render();
}
+ disconnectedCallback() {
+ document.removeEventListener("click", this._clickOutsideHandler, true);
+ }
+
open() {
this._open = true;
this._refreshHistory();
this._render();
- // Toggle active state on button
document.getElementById("history-btn")?.classList.add("active");
+ document.addEventListener("click", this._clickOutsideHandler, true);
}
close() {
@@ -69,6 +80,7 @@ export class RStackHistoryPanel extends HTMLElement {
this._timeMachineSnapshot = null;
this._render();
document.getElementById("history-btn")?.classList.remove("active");
+ document.removeEventListener("click", this._clickOutsideHandler, true);
}
toggle() {
@@ -277,7 +289,6 @@ export class RStackHistoryPanel extends HTMLElement {
this.shadowRoot.innerHTML = `
-