Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(editor): pop dock panels out into their own OS windows

yhhff6652a45365
diff --git a/desktop/electron/main.ts b/desktop/electron/main.ts
index cfa423d41..5da7de12a 100644
--- a/desktop/electron/main.ts
+++ b/desktop/electron/main.ts
@@ -70,6 +70,17 @@ protocol.registerSchemesAsPrivileged([
// The app:// renderer origin (host is arbitrary; `local` keeps URLs readable).
const APP_ORIGIN = 'app://local';
+// dockview pops a dock panel into its own window by opening `popout.html` on our
+// origin (http://localhost in dev, app://local when packaged). Match by pathname so
+// the window-open handler can tell a legit panel pop-out from an external link.
+const isPopoutUrl = (url: string): boolean => {
+ try {
+ return new URL(url).pathname.endsWith('/popout.html');
+ } catch {
+ return false;
+ }
+};
+
// The engine's Emscripten/embind glue requires 'unsafe-eval' in the renderer
// CSP (it JIT-compiles call bridges via new Function). That's a deliberate,
// accepted trade-off for this local dev tool, so silence the dev-only warning.
@@ -359,8 +370,26 @@ function createWindow() {
},
});
- // Open external links in the OS browser, never in-app.
win.webContents.setWindowOpenHandler(({ url }) => {
+ // dockview "move panel to new window" opens a same-origin popout.html child. Allow
+ // it as a real OS window the user can drag to another monitor: only the panel's DOM
+ // is re-parented there — its React tree + editor state stay in this opener realm
+ // (same-origin window.open) — so the child needs no bridge, just a native frame.
+ if (isPopoutUrl(url)) {
+ return {
+ action: 'allow',
+ overrideBrowserWindowOptions: {
+ width: 720,
+ height: 560,
+ minWidth: 320,
+ minHeight: 240,
+ backgroundColor: '#0E121B',
+ autoHideMenuBar: true,
+ title: 'Estella',
+ },
+ };
+ }
+ // Everything else is an external link → OS browser, never in-app.
if (url.startsWith('http')) shell.openExternal(url);
return { action: 'deny' };
});
diff --git a/desktop/public/popout.html b/desktop/public/popout.html
new file mode 100644
index 000000000..a5e706d54
--- /dev/null
+++ b/desktop/public/popout.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <!-- Mirror the editor shell's policy so popped-out panels can render the same
+ asset thumbnails (estella:/data:/blob:) and copied-in styles (unsafe-inline). -->
+ <meta
+ http-equiv="Content-Security-Policy"
+ content="default-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; media-src 'self' estella:; font-src 'self' data:; connect-src 'self' ws: estella:; worker-src 'self' blob:; frame-src 'self' estella:;"
+ />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Estella</title>
+ <!-- Host page for a popped-out dock panel (dockview addPopoutGroup). Intentionally
+ script-free: the panel's DOM is re-parented here, but its React tree and all
+ editor state stay in the opener window (same-origin window.open), so this page
+ only needs to be a styled shell. dockview copies the opener's stylesheets in on
+ load; the dark background avoids a white flash before that happens. -->
+ <style>
+ html,
+ body {
+ margin: 0;
+ height: 100%;
+ background: #0e121b;
+ overflow: hidden;
+ }
+ </style>
+ </head>
+ <body></body>
+</html>
diff --git a/desktop/src/components/AddComponentMenu.tsx b/desktop/src/components/AddComponentMenu.tsx
index f85ae8451..8a9184934 100644
--- a/desktop/src/components/AddComponentMenu.tsx
+++ b/desktop/src/components/AddComponentMenu.tsx
@@ -12,6 +12,7 @@ import { createPortal } from 'react-dom';
import { ComponentIcon } from '@/components/icons';
import { SearchField } from '@/components/SearchField';
import { useDialogFocus } from '@/components/dialogFocus';
+import { usePanelWindow } from '@/components/PanelWindow';
import { CATEGORY_ORDER } from '@/engine/schema';
import { t } from '@/i18n';
@@ -51,6 +52,7 @@ export function AddComponentMenu({
onAdd: (name: string) => void;
onClose: () => void;
}) {
+ const win = usePanelWindow();
const [query, setQuery] = useState('');
const [active, setActive] = useState(0);
const inputRef = useRef<HTMLInputElement>(null);
@@ -72,13 +74,13 @@ export function AddComponentMenu({
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
- window.addEventListener('mousedown', close);
- window.addEventListener('keydown', onKey);
+ win.addEventListener('mousedown', close);
+ win.addEventListener('keydown', onKey);
return () => {
- window.removeEventListener('mousedown', close);
- window.removeEventListener('keydown', onKey);
+ win.removeEventListener('mousedown', close);
+ win.removeEventListener('keydown', onKey);
};
- }, [onClose]);
+ }, [onClose, win]);
const filtered = useMemo(() => {
const q = query.trim().toLowerCase();
@@ -175,6 +177,6 @@ export function AddComponentMenu({
</div>
</div>
</div>,
- document.body,
+ win.document.body,
);
}
diff --git a/desktop/src/components/CreatePopover.tsx b/desktop/src/components/CreatePopover.tsx
index 498db997c..8e9640b58 100644
--- a/desktop/src/components/CreatePopover.tsx
+++ b/desktop/src/components/CreatePopover.tsx
@@ -16,6 +16,7 @@ import { ENTITY_SOURCES, userComponentSources, matchSources, CREATE_CATEGORY_ORD
import { ProjectStore } from '@/project/ProjectStore';
import { SearchField } from '@/components/SearchField';
import { useDialogFocus } from '@/components/dialogFocus';
+import { usePanelWindow } from '@/components/PanelWindow';
import { t } from '@/i18n';
/** Group sources by category, ordered by CREATE_CATEGORY_ORDER — sources arrive in
@@ -44,6 +45,7 @@ export function CreatePopover({
onPick: (s: EntitySource) => void;
onClose: () => void;
}) {
+ const win = usePanelWindow();
const [query, setQuery] = useState('');
const [active, setActive] = useState(0);
const inputRef = useRef<HTMLInputElement>(null);
@@ -66,13 +68,13 @@ export function CreatePopover({
useEffect(() => {
const close = () => onClose();
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
- window.addEventListener('mousedown', close);
- window.addEventListener('keydown', onKey);
+ win.addEventListener('mousedown', close);
+ win.addEventListener('keydown', onKey);
return () => {
- window.removeEventListener('mousedown', close);
- window.removeEventListener('keydown', onKey);
+ win.removeEventListener('mousedown', close);
+ win.removeEventListener('keydown', onKey);
};
- }, [onClose]);
+ }, [onClose, win]);
const commit = (s: EntitySource) => {
onClose();
@@ -136,6 +138,6 @@ export function CreatePopover({
</div>
</div>
</div>,
- document.body,
+ win.document.body,
);
}
diff --git a/desktop/src/components/Menu.tsx b/desktop/src/components/Menu.tsx
index bebf5ca16..d12d7f338 100644
--- a/desktop/src/components/Menu.tsx
+++ b/desktop/src/components/Menu.tsx
@@ -10,6 +10,7 @@
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
import { Check, ChevronRight } from 'lucide-react';
+import { usePanelWindow } from '@/components/PanelWindow';
export type MenuItem =
| { sep: true }
@@ -78,7 +79,9 @@ export function handleMenuListKey(e: React.KeyboardEvent, container: HTMLElement
if (!container) return false;
const items = ownMenuItems(container);
if (items.length === 0) return false;
- const idx = items.indexOf(document.activeElement as HTMLButtonElement);
+ // The focused item lives in the container's own document — which is the popout
+ // window's document when this menu was summoned there, not the main window's.
+ const idx = items.indexOf(container.ownerDocument.activeElement as HTMLButtonElement);
const focusAt = (i: number) => items[((i % items.length) + items.length) % items.length].focus();
if (e.key === 'ArrowDown') focusAt(idx + 1);
else if (e.key === 'ArrowUp') focusAt(idx < 0 ? -1 : idx - 1);
@@ -99,11 +102,11 @@ export function handleMenuListKey(e: React.KeyboardEvent, container: HTMLElement
/** Margin kept between any floating menu and the window edge. */
const VIEWPORT_PAD = 8;
-/** Pull a measured floating rect fully inside the viewport on both axes. */
-function clampToViewport(left: number, top: number, width: number, height: number) {
+/** Pull a measured floating rect fully inside `win`'s viewport on both axes. */
+function clampToViewport(left: number, top: number, width: number, height: number, win: Window) {
return {
- left: Math.max(VIEWPORT_PAD, Math.min(left, window.innerWidth - width - VIEWPORT_PAD)),
- top: Math.max(VIEWPORT_PAD, Math.min(top, window.innerHeight - height - VIEWPORT_PAD)),
+ left: Math.max(VIEWPORT_PAD, Math.min(left, win.innerWidth - width - VIEWPORT_PAD)),
+ top: Math.max(VIEWPORT_PAD, Math.min(top, win.innerHeight - height - VIEWPORT_PAD)),
};
}
@@ -125,22 +128,24 @@ export function ContextMenu({
items: MenuItem[];
onClose: () => void;
}) {
+ const win = usePanelWindow();
+ const doc = win.document;
const ref = useRef<HTMLDivElement>(null);
const [pos, setPos] = useState({ left: x, top: y });
// Who had focus when the menu opened (captured at first render, before the
// seed-focus effect steals it) — keyboard focus returns there on close.
- const opener = useRef<HTMLElement | null>(document.activeElement as HTMLElement | null);
+ const opener = useRef<HTMLElement | null>(doc.activeElement as HTMLElement | null);
// Restore focus to the opener — unless the dismissal itself moved focus
// somewhere real (outside-press on another control must keep that focus).
useEffect(
() => () => {
- const cur = document.activeElement;
- const stillOurs = cur == null || cur === document.body || (ref.current?.contains(cur) ?? false);
+ const cur = doc.activeElement;
+ const stillOurs = cur == null || cur === doc.body || (ref.current?.contains(cur) ?? false);
const el = opener.current;
- if (stillOurs && el && document.contains(el)) el.focus();
+ if (stillOurs && el && doc.contains(el)) el.focus();
},
- [],
+ [doc],
);
// Measure the rendered menu and pull it back inside the viewport (runs before
@@ -149,8 +154,8 @@ export function ContextMenu({
const el = ref.current;
if (!el) return;
const r = el.getBoundingClientRect();
- setPos(clampToViewport(x, y, r.width, r.height));
- }, [x, y]);
+ setPos(clampToViewport(x, y, r.width, r.height, win));
+ }, [x, y, win]);
// Seed focus on the first item so arrow keys work immediately (a mouse-opened
// menu shows no ring — :focus-visible only matches keyboard focus).
@@ -163,15 +168,15 @@ export function ContextMenu({
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
- window.addEventListener('mousedown', close);
- window.addEventListener('scroll', close, true);
- window.addEventListener('keydown', onKey);
+ win.addEventListener('mousedown', close);
+ win.addEventListener('scroll', close, true);
+ win.addEventListener('keydown', onKey);
return () => {
- window.removeEventListener('mousedown', close);
- window.removeEventListener('scroll', close, true);
- window.removeEventListener('keydown', onKey);
+ win.removeEventListener('mousedown', close);
+ win.removeEventListener('scroll', close, true);
+ win.removeEventListener('keydown', onKey);
};
- }, [onClose]);
+ }, [onClose, win]);
return createPortal(
<div
@@ -184,7 +189,7 @@ export function ContextMenu({
>
<CtxItems items={items} onClose={onClose} />
</div>,
- document.body,
+ doc.body,
);
}
@@ -276,6 +281,7 @@ function CtxFlyout({
/** ← pressed inside the flyout: close it and refocus the parent item. */
onBack?: () => void;
}) {
+ const win = usePanelWindow();
const ref = useRef<HTMLDivElement>(null);
const [pos, setPos] = useState({ left: 0, top: 0 });
@@ -293,9 +299,9 @@ function CtxFlyout({
// parent item into the flyout unbroken. -5px lines the first flyout item up
// with the anchor row (menu padding + border).
let left = a.right - 4;
- if (left + r.width > window.innerWidth - VIEWPORT_PAD) left = a.left - r.width + 4;
- setPos(clampToViewport(left, a.top - 5, r.width, r.height));
- }, [anchor]);
+ if (left + r.width > win.innerWidth - VIEWPORT_PAD) left = a.left - r.width + 4;
+ setPos(clampToViewport(left, a.top - 5, r.width, r.height, win));
+ }, [anchor, win]);
return (
<div
diff --git a/desktop/src/components/Modal.tsx b/desktop/src/components/Modal.tsx
index 95e63d1e7..743496a1d 100644
--- a/desktop/src/components/Modal.tsx
+++ b/desktop/src/components/Modal.tsx
@@ -11,6 +11,7 @@ import { X } from 'lucide-react';
import { t } from '@/i18n';
import { IconButton } from './IconButton';
import { useDialogFocus } from './dialogFocus';
+import { usePanelWindow } from './PanelWindow';
export function Modal({
title,
@@ -25,6 +26,7 @@ export function Modal({
footer?: ReactNode;
width?: number;
}) {
+ const win = usePanelWindow();
const winRef = useRef<HTMLDivElement>(null);
useDialogFocus(winRef);
@@ -32,9 +34,9 @@ export function Modal({
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
- window.addEventListener('keydown', onKey);
- return () => window.removeEventListener('keydown', onKey);
- }, [onClose]);
+ win.addEventListener('keydown', onKey);
+ return () => win.removeEventListener('keydown', onKey);
+ }, [onClose, win]);
return createPortal(
<div className="modal-backdrop" onMouseDown={onClose}>
@@ -58,6 +60,6 @@ export function Modal({
{footer && <div className="modal__foot">{footer}</div>}
</div>
</div>,
- document.body,
+ win.document.body,
);
}
diff --git a/desktop/src/components/PanelWindow.tsx b/desktop/src/components/PanelWindow.tsx
new file mode 100644
index 000000000..db09d28a2
--- /dev/null
+++ b/desktop/src/components/PanelWindow.tsx
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file PanelWindow.tsx
+ * @brief The Window a subtree's DOM currently lives in — the one seam that makes
+ * every floating primitive (context menus, popovers, tooltips, palettes)
+ * correct once a dock panel is popped out into its own OS window.
+ *
+ * A popped-out panel keeps rendering in the MAIN window's JS realm (dockview
+ * only re-parents its DOM into the child window), so `document`/`window`
+ * globals still point at the main window. A menu that portals into
+ * `document.body` and clamps against `window.innerWidth` would therefore land
+ * in the wrong window at the wrong spot. Each dock panel provides its live
+ * window here (tracked across pop-out / dock-back via onDidLocationChange);
+ * floating UI reads it with `usePanelWindow()` and portals into — and measures
+ * against — that window instead. Anything outside a panel (main-window chrome)
+ * gets the default: the main window.
+ */
+import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
+import type { DockviewPanelApi } from 'dockview';
+
+// The main editor window — resolved defensively so importing this module in a
+// non-DOM context (unit tests run under node) doesn't touch an undefined `window`
+// at load time. In the browser/Electron renderer this is always the real window.
+const mainWindow: Window = (typeof window !== 'undefined' ? window : globalThis) as Window;
+
+const PanelWindowContext = createContext<Window>(mainWindow);
+
+/** The Window the calling subtree's DOM lives in (main window unless popped out). */
+export function usePanelWindow(): Window {
+ return useContext(PanelWindowContext);
+}
+
+const resolveWindow = (api: DockviewPanelApi): Window => {
+ const loc = api.location;
+ return loc.type === 'popout' ? loc.getWindow() : mainWindow;
+};
+
+/** Wrap a dock panel's content so its descendants resolve the right window. */
+export function PanelWindowProvider({ api, children }: { api: DockviewPanelApi; children: ReactNode }) {
+ const [win, setWin] = useState<Window>(() => resolveWindow(api));
+ useEffect(() => {
+ setWin(resolveWindow(api));
+ const d = api.onDidLocationChange(() => setWin(resolveWindow(api)));
+ return () => d.dispose();
+ }, [api]);
+ return <PanelWindowContext.Provider value={win}>{children}</PanelWindowContext.Provider>;
+}
diff --git a/desktop/src/components/Popover.tsx b/desktop/src/components/Popover.tsx
index 96bbeded0..420ffbe84 100644
--- a/desktop/src/components/Popover.tsx
+++ b/desktop/src/components/Popover.tsx
@@ -12,6 +12,7 @@
*/
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
+import { usePanelWindow } from '@/components/PanelWindow';
export function Popover({
anchor,
@@ -30,20 +31,22 @@ export function Popover({
/** Extra class on the `.popover` shell — e.g. a glass variant for overlays. */
className?: string;
}) {
+ const win = usePanelWindow();
+ const doc = win.document;
const ref = useRef<HTMLDivElement>(null);
const [pos, setPos] = useState<{ left: number; top: number }>({ left: anchor.left, top: anchor.bottom + 2 });
// Who had focus when the popover opened (usually the trigger) — keyboard focus
// returns there on close, unless the dismissal itself focused another control.
- const opener = useRef<HTMLElement | null>(document.activeElement as HTMLElement | null);
+ const opener = useRef<HTMLElement | null>(doc.activeElement as HTMLElement | null);
useEffect(
() => () => {
- const cur = document.activeElement;
- const stillOurs = cur == null || cur === document.body || (ref.current?.contains(cur) ?? false);
+ const cur = doc.activeElement;
+ const stillOurs = cur == null || cur === doc.body || (ref.current?.contains(cur) ?? false);
const el = opener.current;
- if (stillOurs && el && document.contains(el)) el.focus();
+ if (stillOurs && el && doc.contains(el)) el.focus();
},
- [],
+ [doc],
);
// Measure then clamp before paint so the first frame is already on-screen.
@@ -53,29 +56,29 @@ export function Popover({
const r = el.getBoundingClientRect();
const pad = 8;
let left = anchor.left;
- if (left + r.width > window.innerWidth - pad) left = Math.max(pad, window.innerWidth - r.width - pad);
+ if (left + r.width > win.innerWidth - pad) left = Math.max(pad, win.innerWidth - r.width - pad);
let top = anchor.bottom + 2;
// No room below → flip above the anchor.
- if (top + r.height > window.innerHeight - pad) top = Math.max(pad, anchor.top - r.height - 2);
+ if (top + r.height > win.innerHeight - pad) top = Math.max(pad, anchor.top - r.height - 2);
setPos({ left, top });
- }, [anchor]);
+ }, [anchor, win]);
useEffect(() => {
const close = () => onClose();
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
- window.addEventListener('mousedown', close);
- window.addEventListener('scroll', close, true);
- window.addEventListener('resize', close);
- window.addEventListener('keydown', onKey);
+ win.addEventListener('mousedown', close);
+ win.addEventListener('scroll', close, true);
+ win.addEventListener('resize', close);
+ win.addEventListener('keydown', onKey);
return () => {
- window.removeEventListener('mousedown', close);
- window.removeEventListener('scroll', close, true);
- window.removeEventListener('resize', close);
- window.removeEventListener('keydown', onKey);
+ win.removeEventListener('mousedown', close);
+ win.removeEventListener('scroll', close, true);
+ win.removeEventListener('resize', close);
+ win.removeEventListener('keydown', onKey);
};
- }, [onClose]);
+ }, [onClose, win]);
return createPortal(
<div
@@ -86,7 +89,7 @@ export function Popover({
>
{children}
</div>,
- document.body,
+ doc.body,
);
}
diff --git a/desktop/src/components/Tooltip.tsx b/desktop/src/components/Tooltip.tsx
index cf0789871..e06c56bf6 100644
--- a/desktop/src/components/Tooltip.tsx
+++ b/desktop/src/components/Tooltip.tsx
@@ -13,6 +13,7 @@
*/
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
+import { usePanelWindow } from '@/components/PanelWindow';
// UE-style hover delay: long enough not to flicker while sweeping over a grid.
const OPEN_DELAY = 450;
@@ -26,6 +27,9 @@ function Tooltip({
onDismiss: () => void;
children: ReactNode;
}) {
+ // Cast exposes the observer constructors (globals, not on the Window interface);
+ // using the panel's own window's observers keeps them correct across a popout.
+ const win = usePanelWindow() as Window & typeof globalThis;
const ref = useRef<HTMLDivElement>(null);
const [pos, setPos] = useState(() => {
const r = anchor.getBoundingClientRect();
@@ -42,43 +46,43 @@ function Tooltip({
const r = el.getBoundingClientRect();
const pad = 8;
let left = a.right + 10;
- if (left + r.width > window.innerWidth - pad) left = Math.max(pad, a.left - r.width - 10);
+ if (left + r.width > win.innerWidth - pad) left = Math.max(pad, a.left - r.width - 10);
let top = a.top;
- if (top + r.height > window.innerHeight - pad) top = Math.max(pad, window.innerHeight - r.height - pad);
+ if (top + r.height > win.innerHeight - pad) top = Math.max(pad, win.innerHeight - r.height - pad);
setPos((p) => (p.left === left && p.top === top ? p : { left, top }));
};
place();
- const ro = new ResizeObserver(place);
+ const ro = new win.ResizeObserver(place);
ro.observe(el);
return () => ro.disconnect();
- }, [anchor]);
+ }, [anchor, win]);
// Dismiss the moment the anchor leaves the screen. The IntersectionObserver is
// the load-bearing part: it reports the anchor non-intersecting when its panel
// is detached on a dock tab switch or collapsed — cases a mouseleave never sees.
useEffect(() => {
- const io = new IntersectionObserver((entries) => {
+ const io = new win.IntersectionObserver((entries) => {
if (entries.some((e) => !e.isIntersecting)) onDismiss();
});
io.observe(anchor);
- window.addEventListener('scroll', onDismiss, true);
- window.addEventListener('wheel', onDismiss, { passive: true });
- window.addEventListener('resize', onDismiss);
- window.addEventListener('blur', onDismiss);
+ win.addEventListener('scroll', onDismiss, true);
+ win.addEventListener('wheel', onDismiss, { passive: true });
+ win.addEventListener('resize', onDismiss);
+ win.addEventListener('blur', onDismiss);
return () => {
io.disconnect();
- window.removeEventListener('scroll', onDismiss, true);
- window.removeEventListener('wheel', onDismiss);
- window.removeEventListener('resize', onDismiss);
- window.removeEventListener('blur', onDismiss);
+ win.removeEventListener('scroll', onDismiss, true);
+ win.removeEventListener('wheel', onDismiss);
+ win.removeEventListener('resize', onDismiss);
+ win.removeEventListener('blur', onDismiss);
};
- }, [anchor, onDismiss]);
+ }, [anchor, onDismiss, win]);
return createPortal(
<div ref={ref} className="tooltip" role="tooltip" style={{ left: pos.left, top: pos.top }}>
{children}
</div>,
- document.body,
+ win.document.body,
);
}
diff --git a/desktop/src/components/dialogFocus.ts b/desktop/src/components/dialogFocus.ts
index 067a8b8f1..d497158b2 100644
--- a/desktop/src/components/dialogFocus.ts
+++ b/desktop/src/components/dialogFocus.ts
@@ -28,11 +28,15 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>): void {
useEffect(() => {
const container = ref.current;
if (!container) return;
- const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
+ // Resolve the container's own document/window — the popout window's when the
+ // dialog was summoned from a popped-out panel, not the main editor window's.
+ const doc = container.ownerDocument;
+ const win = doc.defaultView ?? window;
+ const opener = doc.activeElement instanceof HTMLElement ? doc.activeElement : null;
// Seed focus inside — unless the shell already autofocused its own field
// (command palettes / settings focus their search input on mount).
- if (!container.contains(document.activeElement)) container.focus();
+ if (!container.contains(doc.activeElement)) container.focus();
// Trap Tab: cycle within the container; recapture if focus escaped.
const onKey = (e: KeyboardEvent) => {
@@ -45,7 +49,7 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>): void {
}
const first = items[0];
const last = items[items.length - 1];
- const active = document.activeElement;
+ const active = doc.activeElement;
const inside = active instanceof HTMLElement && container.contains(active);
if (e.shiftKey && (!inside || active === first)) {
e.preventDefault();
@@ -55,9 +59,9 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>): void {
first.focus();
}
};
- window.addEventListener('keydown', onKey, true);
+ win.addEventListener('keydown', onKey, true);
return () => {
- window.removeEventListener('keydown', onKey, true);
+ win.removeEventListener('keydown', onKey, true);
// Hand focus back to whoever opened the dialog (if still in the DOM).
if (opener?.isConnected) opener.focus();
};
diff --git a/desktop/src/i18n/messages/layout.ts b/desktop/src/i18n/messages/layout.ts
index a762376aa..aa9154781 100644
--- a/desktop/src/i18n/messages/layout.ts
+++ b/desktop/src/i18n/messages/layout.ts
@@ -20,6 +20,7 @@ export const layoutMessages = defineMessages({
// — Dock chrome (tabs, collapse chevron) —
'layout.closeTab': { en: 'Close {title}', zh: '关闭 {title}' },
+ 'layout.popOut': { en: 'Move to new window', zh: '移动到新窗口' },
'layout.collapsePanel': { en: 'Collapse panel', zh: '折叠面板' },
'layout.expandPanel': { en: 'Expand panel', zh: '展开面板' },
diff --git a/desktop/src/layout/DockLayout.tsx b/desktop/src/layout/DockLayout.tsx
index 7e5a4702e..0d364e98d 100644
--- a/desktop/src/layout/DockLayout.tsx
+++ b/desktop/src/layout/DockLayout.tsx
@@ -4,11 +4,12 @@ import { useEffect, useState, useSyncExternalStore, type FC, type ReactNode } fr
import {
DockviewReact,
type DockviewReadyEvent,
+ type DockviewPanelApi,
type IDockviewPanelProps,
type IDockviewPanelHeaderProps,
type IDockviewHeaderActionsProps,
} from 'dockview';
-import { ChevronDown, X } from 'lucide-react';
+import { ChevronDown, X, SquareArrowOutUpRight } from 'lucide-react';
import { DirtyDot } from '@/components/DirtyDot';
import { panelDirtySource } from '@/layout/panelDirty';
import { Outliner } from '@/panels/Outliner';
@@ -29,38 +30,48 @@ import { BtTreeEditor } from '@/panels/BtTreeEditor';
import { ProfilerPanel } from '@/panels/ProfilerPanel';
import { Perf } from '@/components/Perf';
import { ErrorBoundary } from '@/components/ErrorBoundary';
-import { dockApi } from '@/layout/dockApi';
+import { PanelWindowProvider } from '@/components/PanelWindow';
+import { dockApi, applyPopoutTheme } from '@/layout/dockApi';
import { t } from '@/i18n';
-const panel = (id: string, node: ReactNode) => (
- <Perf id={id}>
- <ErrorBoundary label={id}>{node}</ErrorBoundary>
- </Perf>
+// Each dock panel is a thin wrapper so dockview owns mount/unmount. The
+// PanelWindowProvider hands the panel's live window down the tree so floating UI
+// (menus, popovers, tooltips) lands in the right OS window once it's popped out.
+const panel = (id: string, api: DockviewPanelApi, node: ReactNode) => (
+ <PanelWindowProvider api={api}>
+ <Perf id={id}>
+ <ErrorBoundary label={id}>{node}</ErrorBoundary>
+ </Perf>
+ </PanelWindowProvider>
);
-// Each dock panel is a thin wrapper so dockview owns mount/unmount.
const components: Record<string, FC<IDockviewPanelProps>> = {
- outliner: () => panel('outliner', <Outliner />),
- viewport: () => panel('viewport', <Viewport />),
- details: () => panel('details', <Details />),
- content: () => panel('content', <ContentBrowser />),
- log: () => panel('log', <OutputLog />),
- sequencer: () => panel('sequencer', <Sequencer />),
- tileset: () => panel('tileset', <TilesetEditor />),
- flipbook: () => panel('flipbook', <FlipbookEditor />),
- audiomixer: () => panel('audiomixer', <AudioMixerPanel />),
- tilemap: () => panel('tilemap', <TilemapPainter />),
- uiWidgets: () => panel('uiWidgets', <UIWidgetsPanel />),
- materialgraph: () => panel('materialgraph', <MaterialGraphEditor />),
- statemachine: () => panel('statemachine', <StateMachineEditor />),
- behaviortree: () => panel('behaviortree', <BtTreeEditor />),
- profiler: () => <ErrorBoundary label="profiler"><ProfilerPanel /></ErrorBoundary>,
+ outliner: (p) => panel('outliner', p.api, <Outliner />),
+ viewport: (p) => panel('viewport', p.api, <Viewport />),
+ details: (p) => panel('details', p.api, <Details />),
+ content: (p) => panel('content', p.api, <ContentBrowser />),
+ log: (p) => panel('log', p.api, <OutputLog />),
+ sequencer: (p) => panel('sequencer', p.api, <Sequencer />),
+ tileset: (p) => panel('tileset', p.api, <TilesetEditor />),
+ flipbook: (p) => panel('flipbook', p.api, <FlipbookEditor />),
+ audiomixer: (p) => panel('audiomixer', p.api, <AudioMixerPanel />),
+ tilemap: (p) => panel('tilemap', p.api, <TilemapPainter />),
+ uiWidgets: (p) => panel('uiWidgets', p.api, <UIWidgetsPanel />),
+ materialgraph: (p) => panel('materialgraph', p.api, <MaterialGraphEditor />),
+ statemachine: (p) => panel('statemachine', p.api, <StateMachineEditor />),
+ behaviortree: (p) => panel('behaviortree', p.api, <BtTreeEditor />),
+ // Profiler skips the Perf wrapper (it must not profile its own render).
+ profiler: (p) => (
+ <PanelWindowProvider api={p.api}>
+ <ErrorBoundary label="profiler"><ProfilerPanel /></ErrorBoundary>
+ </PanelWindowProvider>
+ ),
// The "Game" view (isolated play realm) — added on Play, removed on Stop.
- game: () => panel('game', <GamePanel />),
+ game: (p) => panel('game', p.api, <GamePanel />),
// Multiplayer client realms ("Game P2..N") — session-scoped, keyed by realmId.
gameClient: (props) => {
const realmId = Number((props.params as { realmId?: number } | undefined)?.realmId ?? 0);
- return panel(`game-client-${realmId}`, <GameClientPanel realmId={realmId} />);
+ return panel(`game-client-${realmId}`, props.api, <GameClientPanel realmId={realmId} />);
},
};
@@ -169,14 +180,34 @@ function EstellaTab(props: IDockviewPanelHeaderProps) {
const source = panelDirtySource(props.api.id);
const dirty = useSyncExternalStore(source.subscribe, source.isDirty);
const [title, setTitle] = useState(props.api.title ?? props.api.id);
+ // The pop-out affordance shows only for a poppable panel that's still in the main
+ // grid — once it's in its own window the way back is to close that window.
+ const [docked, setDocked] = useState(() => props.api.location.type === 'grid');
useEffect(() => {
- const d = props.api.onDidTitleChange((e) => setTitle(e.title));
- return () => d.dispose();
+ const dt = props.api.onDidTitleChange((e) => setTitle(e.title));
+ const dl = props.api.onDidLocationChange(() => setDocked(props.api.location.type === 'grid'));
+ return () => { dt.dispose(); dl.dispose(); };
}, [props.api]);
+ const poppable = docked && dockApi.canPopout(props.api.id);
return (
<div className="dv-estella-tab">
<span className="tab-title">{title}</span>
{dirty && <DirtyDot />}
+ {poppable && (
+ <button
+ type="button"
+ className="tab-popout"
+ title={t('layout.popOut')}
+ aria-label={t('layout.popOut')}
+ onPointerDown={(e) => e.stopPropagation()}
+ onClick={(e) => {
+ e.stopPropagation();
+ dockApi.popout(props.api.id);
+ }}
+ >
+ <SquareArrowOutUpRight size={11} strokeWidth={2} />
+ </button>
+ )}
<button
type="button"
className="tab-x"
@@ -199,7 +230,11 @@ function EstellaTab(props: IDockviewPanelHeaderProps) {
// (the center stage isn't an accordion). State follows the live group height, so
// it stays correct after splitter drags and layout restores.
function CollapseHeaderAction(props: IDockviewHeaderActionsProps) {
- const collapsible = !props.panels.some((p) => p.id === 'viewport' || p.id === 'game');
+ // Only grid groups collapse-to-header; a popped-out group owns its whole window,
+ // where a height accordion makes no sense (resize the OS window instead).
+ const collapsible =
+ props.api.location.type === 'grid' &&
+ !props.panels.some((p) => p.id === 'viewport' || p.id === 'game');
const [collapsed, setCollapsed] = useState(() => dockApi.groupCollapsed(props.api));
useEffect(() => {
const d = props.api.onDidDimensionsChange(() => setCollapsed(dockApi.groupCollapsed(props.api)));
@@ -225,6 +260,15 @@ export function DockLayout() {
const { api } = event;
dockApi.set(api); // expose to the activity bar (reveal/focus panels)
+ // Every popout group (a manual pop-out AND one dockview reopens while restoring a
+ // saved layout) is re-themed here: dockview copies only the first `dockview-theme-*`
+ // class into the child window, so re-add our estella override so the popped-out
+ // chrome matches the dock exactly. One hook covers both paths.
+ api.onDidAddGroup((group) => {
+ const loc = group.api.location;
+ if (loc.type === 'popout') applyPopoutTheme(loc.getWindow());
+ });
+
const saved = localStorage.getItem(LAYOUT_KEY);
if (saved) {
try {
diff --git a/desktop/src/layout/dockApi.ts b/desktop/src/layout/dockApi.ts
index b93e9cf56..a9fef2b7f 100644
--- a/desktop/src/layout/dockApi.ts
+++ b/desktop/src/layout/dockApi.ts
@@ -34,6 +34,29 @@ const prefersReducedMotion = (): boolean =>
typeof window.matchMedia === 'function' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
+// Panels bound to the editor's single engine surface can't move to another OS
+// window: the Viewport owns the one WebGL canvas and the Game view hosts the play
+// iframe — a live GL context / iframe doesn't survive being re-parented across
+// documents. Everything else is model/store-driven and pops out cleanly.
+const NON_POPPABLE = new Set(['viewport', 'game']);
+
+// dockview's getDockviewTheme copies only the FIRST `dockview-theme-*` class onto
+// the popout container (our root carries `dockview-theme-abyss dockview-theme-estella`,
+// so only abyss makes it across). Re-add the estella override on the SAME element so
+// the compound `.dockview-theme-abyss.dockview-theme-estella` variable block and every
+// estella chrome selector match in the popped-out window — pixel-identical to the dock.
+// The container only gains its `dv-dockview` class after the child window's load event,
+// so poll a bounded number of that window's frames for it to appear.
+export function applyPopoutTheme(popoutWindow: Window): void {
+ let tries = 0;
+ const add = () => {
+ const el = popoutWindow.document.querySelector('.dv-dockview');
+ if (el) el.classList.add('dockview-theme-estella');
+ else if (tries++ < 60 && !popoutWindow.closed) popoutWindow.requestAnimationFrame(add);
+ };
+ add();
+}
+
export const dockApi = {
set(next: DockviewApi | null) {
api = next;
@@ -42,6 +65,29 @@ export const dockApi = {
reveal(id: string) {
api?.getPanel(id)?.api.setActive();
},
+ /** True when a panel may be popped out into its own OS window (see NON_POPPABLE). */
+ canPopout(id: string): boolean {
+ return !NON_POPPABLE.has(id) && !id.startsWith('game-client-');
+ },
+ /**
+ * Move a docked panel into its own OS window (dockview addPopoutGroup → a real
+ * child window on any monitor). Because the popout is a same-origin `window.open`,
+ * the panel's React tree and every editor store stay in THIS window's JS realm —
+ * only its DOM is re-parented — so a popped-out Inspector/Outliner shares live
+ * selection and edits with the main window with no cross-window messaging. dockview
+ * copies the stylesheets over; applyPopoutTheme re-adds our theme override class so
+ * the popped-out chrome matches exactly. Layout persistence carries popout groups,
+ * so a popped-out panel reopens where it was after a reload.
+ */
+ popout(id: string) {
+ if (!api || !this.canPopout(id)) return;
+ const panel = api.getPanel(id);
+ if (!panel) return;
+ void api.addPopoutGroup(panel, {
+ popoutUrl: '/popout.html',
+ onDidOpen: ({ window: popoutWindow }) => applyPopoutTheme(popoutWindow),
+ });
+ },
/**
* Open (or front) a large editor as a document tab in the CENTER stage beside
* the Viewport — the modern unified-editor home for full editing canvases
diff --git a/desktop/src/panels/OutputLog.tsx b/desktop/src/panels/OutputLog.tsx
index e0ef495d0..4432feebe 100644
--- a/desktop/src/panels/OutputLog.tsx
+++ b/desktop/src/panels/OutputLog.tsx
@@ -12,6 +12,7 @@ import { createPortal } from 'react-dom';
import { Trash2, ArrowDownToLine, Clock, ListFilter, Check } from 'lucide-react';
import { LogStore, type LogLevel, type LogEntry } from '@/store/LogStore';
import { ContextMenu, type MenuItem } from '@/components/Menu';
+import { usePanelWindow } from '@/components/PanelWindow';
import { SearchField } from '@/components/SearchField';
import { Toasts } from '@/store/Toasts';
import { t } from '@/i18n';
@@ -60,6 +61,7 @@ function CategoryMenu({
onHideAll: () => void;
onClose: () => void;
}) {
+ const win = usePanelWindow();
const ref = useRef<HTMLDivElement>(null);
const [pos, setPos] = useState(anchor);
@@ -69,24 +71,24 @@ function CategoryMenu({
const r = el.getBoundingClientRect();
const pad = 8;
const left =
- anchor.left + r.width > window.innerWidth - pad
- ? Math.max(pad, window.innerWidth - r.width - pad)
+ anchor.left + r.width > win.innerWidth - pad
+ ? Math.max(pad, win.innerWidth - r.width - pad)
: anchor.left;
setPos({ left, top: anchor.top });
- }, [anchor]);
+ }, [anchor, win]);
useEffect(() => {
const close = () => onClose();
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
- window.addEventListener('mousedown', close);
- window.addEventListener('scroll', close, true);
- window.addEventListener('keydown', onKey);
+ win.addEventListener('mousedown', close);
+ win.addEventListener('scroll', close, true);
+ win.addEventListener('keydown', onKey);
return () => {
- window.removeEventListener('mousedown', close);
- window.removeEventListener('scroll', close, true);
- window.removeEventListener('keydown', onKey);
+ win.removeEventListener('mousedown', close);
+ win.removeEventListener('scroll', close, true);
+ win.removeEventListener('keydown', onKey);
};
- }, [onClose]);
+ }, [onClose, win]);
return createPortal(
<div
@@ -114,7 +116,7 @@ function CategoryMenu({
</button>
))}
</div>,
- document.body,
+ win.document.body,
);
}
diff --git a/desktop/src/theme/dockview-theme.css b/desktop/src/theme/dockview-theme.css
index 115e5f9f3..9a4bacbb4 100644
--- a/desktop/src/theme/dockview-theme.css
+++ b/desktop/src/theme/dockview-theme.css
@@ -113,21 +113,27 @@
text-overflow: ellipsis;
white-space: nowrap;
}
+.dockview-theme-estella .dv-estella-tab .tab-popout,
.dockview-theme-estella .dv-estella-tab .tab-x {
width: 16px;
height: 16px;
display: grid;
place-items: center;
- margin-right: -6px;
border-radius: var(--r-xs);
color: var(--text-faint);
opacity: 0;
transition: opacity var(--t-fast), color var(--t-fast), background var(--t-fast);
}
+.dockview-theme-estella .dv-estella-tab .tab-x {
+ margin-right: -6px;
+}
+.dockview-theme-estella .dv-tab:hover .tab-popout,
+.dockview-theme-estella .dv-tab.dv-active-tab .tab-popout,
.dockview-theme-estella .dv-tab:hover .tab-x,
.dockview-theme-estella .dv-tab.dv-active-tab .tab-x {
opacity: 1;
}
+.dockview-theme-estella .dv-estella-tab .tab-popout:hover,
.dockview-theme-estella .dv-estella-tab .tab-x:hover {
color: var(--text);
background: var(--srf-4);