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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): one way to be a summoned drawer, so the agent's slides like the other one
esenginecc33eb8505c3
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsxindex 083dfe852..8cc5e4512 100644--- a/desktop/src/App.tsx+++ b/desktop/src/App.tsx@@ -299,10 +299,12 @@ export function App() {<ErrorBoundary label="activitybar"><Perf id="activitybar"><ActivityBar /></Perf></ErrorBoundary><DockLayout /><ErrorBoundary label="agentcheckpoint"><AgentCheckpoint /></ErrorBoundary>+ {/* Both summoned drawers live INSIDE the workspace: they cover the+ panels and leave the chrome around them live. */}+ <ErrorBoundary label="contentdrawer"><Perf id="contentdrawer"><ContentDrawer /></Perf></ErrorBoundary><ErrorBoundary label="agentdrawer"><Perf id="agentdrawer"><AgentDrawer /></Perf></ErrorBoundary></main><ErrorBoundary label="statusbar"><Perf id="statusbar"><StatusBar /></Perf></ErrorBoundary>- <ErrorBoundary label="contentdrawer"><Perf id="contentdrawer"><ContentDrawer /></Perf></ErrorBoundary><PerfRealmBridge />{buildOpen && <BuildDialog />}{settingsOpen && <SettingsDialog />}diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 5d18c0bd9..8d528dcbe 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -43,6 +43,7 @@ import { secretStatus, subscribeSecrets, secretRevision } from '@/store/SecretStimport { useSettings } from '@/store/settingsStore';import { MarkdownView } from '@/components/MarkdownView';import { AgentMark } from '@/components/AgentMark';+import { OverlayDrawer } from '@/components/OverlayDrawer';import { dockApi } from '@/layout/dockApi';import { EditorHistory, type HistoryMark } from '@/engine/EditorHistory';import { useSelection } from '@/store/selectionStore';@@ -1000,27 +1001,21 @@ export function AgentPanel({ docked }: { docked?: boolean }) {}/** The summoned overlay: covers the right-hand panels rather than squeezing the- * viewport, and dismisses on Esc or an outside click. */+ * viewport. Everything about being a drawer — the slide, Esc, the outside+ * click, keeping focus inside — is the shared paradigm's (OverlayDrawer). */export function AgentDrawer() {const open = useEditorStore((s) => s.agentDrawer);const setOpen = useEditorStore((s) => s.setAgentDrawer);-- useEffect(() => {- if (!open) return;- const onKey = (e: KeyboardEvent) => {- if (e.key === 'Escape') setOpen(false);- };- window.addEventListener('keydown', onKey);- return () => window.removeEventListener('keydown', onKey);- }, [open, setOpen]);-- if (!open) return null;return (- <div className="ag-scrim open" onMouseDown={() => setOpen(false)}>- <div className="ag-drawer" onMouseDown={(e) => e.stopPropagation()}>- <AgentPanel />- </div>- </div>+ <OverlayDrawer+ open={open}+ onClose={() => setOpen(false)}+ side="right"+ className="drawer--agent"+ label={t('agent.title')}+ >+ <AgentPanel />+ </OverlayDrawer>);}diff --git a/desktop/src/components/OverlayDrawer.tsx b/desktop/src/components/OverlayDrawer.tsxnew file mode 100644index 000000000..8e0a8b393--- /dev/null+++ b/desktop/src/components/OverlayDrawer.tsx@@ -0,0 +1,85 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file OverlayDrawer.tsx+ * @brief A surface you SUMMON: a scrim over the workspace and a panel that+ * slides in from one edge, dismissed by Esc or a click outside.+ *+ * There are two of these — the Content Browser from the bottom, the agent from+ * the right — and there was one implementation and a half. The second wrote the+ * scrim and the Esc key again, and got the slide and the focus handling by not+ * having them: it cut in and out rather than moving, and Tab walked out of it+ * into the panels the scrim had just made unclickable. What actually differs+ * between the two is an edge and a size, so that is what this takes.+ *+ * The shell stays MOUNTED, because a panel React has already removed has+ * nothing left to slide out with. Its CONTENT does not: it is held one+ * transition past close and then dropped, so a shut drawer costs nothing while+ * an opening one is never a jump cut.+ *+ * Deliberately not `aria-modal`: the menu bar, toolbar and status bar sit+ * OUTSIDE the scrim and stay live on purpose — the status bar is where a+ * running agent reports progress, and dimming it would hide the thing saying+ * work is happening. Focus is still kept inside, because everything the scrim+ * covers is out of reach of the pointer and should be out of reach of Tab.+ */+import { useEffect, useRef, useState, type ReactNode } from 'react';+import { useDialogFocus } from '@/components/dialogFocus';++/** The panel's transform transition (--t-slow), in ms. */+const EXIT_MS = 240;++export function OverlayDrawer({ open, onClose, side, className, label, children }: {+ open: boolean;+ onClose: () => void;+ /** The edge it comes from. */+ side: 'right' | 'bottom';+ /** On the sliding panel — its size and surface, which are its own business. */+ className?: string;+ /** What it is, for anyone who cannot see the panel it opens. */+ label: string;+ children: ReactNode;+}) {+ const ref = useRef<HTMLDivElement>(null);+ const held = useHeldOpen(open, EXIT_MS);+ useDialogFocus(ref, open);++ useEffect(() => {+ if (!open) return;+ const onKey = (e: KeyboardEvent) => {+ if (e.key === 'Escape') onClose();+ };+ window.addEventListener('keydown', onKey);+ return () => window.removeEventListener('keydown', onKey);+ }, [open, onClose]);++ return (+ <div className={`scrim scrim--${side}${open ? ' open' : ''}`} onMouseDown={onClose}>+ <div+ ref={ref}+ role="dialog"+ aria-label={label}+ tabIndex={-1}+ className={`drawer${className ? ` ${className}` : ''}`}+ onMouseDown={(e) => e.stopPropagation()}+ >+ {held && children}+ </div>+ </div>+ );+}++/** True while `open`, and for one exit transition after it goes false. */+function useHeldOpen(open: boolean, ms: number): boolean {+ const [held, setHeld] = useState(open);+ // Adjusted during render rather than from an effect, so the content is in the+ // DOM in the SAME commit that opens the drawer. From an effect it would mount+ // one paint later, and the focus seed would land on an empty shell.+ if (open && !held) setHeld(true);+ useEffect(() => {+ if (open) return;+ const id = setTimeout(() => setHeld(false), ms);+ return () => clearTimeout(id);+ }, [open, ms]);+ return held;+}diff --git a/desktop/src/components/dialogFocus.ts b/desktop/src/components/dialogFocus.tsindex d497158b2..a7ca8ee65 100644--- a/desktop/src/components/dialogFocus.ts+++ b/desktop/src/components/dialogFocus.ts@@ -23,11 +23,15 @@ function focusables(container: HTMLElement): HTMLElement[] {* Modal focus management for the container behind `ref` (give it tabIndex={-1}* so it can take the seed focus). Runs for the container's whole mount — mount* a dialog only while it is open.+ *+ * `active` is for the shells that CANNOT do that: a drawer keeps its frame+ * mounted so it has something to animate out, and passing `open` here is how it+ * still gets the same trap for exactly as long as it is a dialog.*/-export function useDialogFocus(ref: RefObject<HTMLElement | null>): void {+export function useDialogFocus(ref: RefObject<HTMLElement | null>, active = true): void {useEffect(() => {const container = ref.current;- if (!container) return;+ if (!container || !active) return;// 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;@@ -66,5 +70,5 @@ export function useDialogFocus(ref: RefObject<HTMLElement | null>): void {if (opener?.isConnected) opener.focus();};// eslint-disable-next-line react-hooks/exhaustive-deps- }, []);+ }, [active]);}diff --git a/desktop/src/layout/ContentDrawer.tsx b/desktop/src/layout/ContentDrawer.tsxindex 941f49efa..bcb9e0007 100644--- a/desktop/src/layout/ContentDrawer.tsx+++ b/desktop/src/layout/ContentDrawer.tsx@@ -1,44 +1,41 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team// Content Drawer — the Content Browser slides up over the workspace as a quick-// overlay (Ctrl+Space), on top of the docked Content Browser tab. Dismisses on-// outside click or Esc.-import { useEffect } from 'react';+// overlay (Ctrl+Space), on top of the docked Content Browser tab. Being a+// drawer is the shared paradigm's (components/OverlayDrawer.tsx); this is the+// head and the panel it summons.import { FolderOpen, X } from 'lucide-react';import { useEditorStore } from '@/store/editorStore';+import { OverlayDrawer } from '@/components/OverlayDrawer';import { ContentBrowser } from '@/panels/ContentBrowser';import { t } from '@/i18n';export function ContentDrawer() {const open = useEditorStore((s) => s.contentDrawer);const setOpen = useEditorStore((s) => s.setContentDrawer);-- useEffect(() => {- if (!open) return;- const onKey = (e: KeyboardEvent) => {- if (e.key === 'Escape') setOpen(false);- };- window.addEventListener('keydown', onKey);- return () => window.removeEventListener('keydown', onKey);- }, [open, setOpen]);+ const close = () => setOpen(false);return (- <div className={`scrim${open ? ' open' : ''}`} onMouseDown={() => setOpen(false)}>- <div className="drawer" onMouseDown={(e) => e.stopPropagation()}>- <div className="drawer-head">- <span className="drawer-title">- <span className="ic">- <FolderOpen size={16} strokeWidth={1.8} />- </span>- {t('layout.panel.contentBrowser')}+ <OverlayDrawer+ open={open}+ onClose={close}+ side="bottom"+ className="drawer--content"+ label={t('layout.panel.contentBrowser')}+ >+ <div className="drawer-head">+ <span className="drawer-title">+ <span className="ic">+ <FolderOpen size={16} strokeWidth={1.8} /></span>- <span className="drawer-sp" />- <button type="button" className="drawer-x" title={t('layout.closeEsc')} onClick={() => setOpen(false)}>- <X size={15} strokeWidth={2} />- </button>- </div>- <div className="drawer-body">{open && <ContentBrowser />}</div>+ {t('layout.panel.contentBrowser')}+ </span>+ <span className="drawer-sp" />+ <button type="button" className="drawer-x" title={t('layout.closeEsc')} onClick={close}>+ <X size={15} strokeWidth={2} />+ </button></div>- </div>+ <div className="drawer-body"><ContentBrowser /></div>+ </OverlayDrawer>);}diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex 3e369d594..3f27997ca 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -15,28 +15,13 @@/* Floating: it covers the right-hand panels rather than squeezing the viewport.You look at properties or you talk to the agent — the two naturally alternate,- and a viewport that resizes under a conversation is the worse trade. */-.ag-scrim {- /* Absolute, not fixed: bounded to the workspace row, so the menubar, toolbar- and status bar stay live. The status bar in particular is where the agent- reports progress — dimming it would hide the thing that says work is- happening. */- position: absolute;- inset: 0;- z-index: var(--z-drawer);- background: var(--overlay);- display: flex;- justify-content: flex-end;-}-.ag-drawer {+ and a viewport that resizes under a conversation is the worse trade. The+ drawer itself is the shared paradigm's (chrome.css); this is only its width+ and its surface. */+.drawer--agent {width: 384px;- max-width: 100vw;- flex: none;- min-height: 0;- height: 100%;+ max-width: 100%;background: var(--panel);- /* The accent edge every summoned surface leads with (cf. the Content Drawer). */- border-left: 2px solid var(--acc);}.ag-head {@@ -661,7 +646,7 @@/* Docked, it is an ordinary panel: the shell owns the frame. */.ag-panel { display: flex; flex-direction: column; min-height: 0; height: 100%; background: var(--panel); }-.ag-drawer .ag-panel { height: 100%; }+.drawer--agent .ag-panel { height: 100%; }/* Docked, the dock tab carries the title, so the head is just its actions. */.ag-head.docked { height: 30px; border-bottom: 1px solid var(--line-soft); }diff --git a/desktop/src/theme/chrome.css b/desktop/src/theme/chrome.cssindex 749a313b7..aafd11e51 100644--- a/desktop/src/theme/chrome.css+++ b/desktop/src/theme/chrome.css@@ -252,37 +252,44 @@.act-spacer { flex: 1; }.act-sep { width: 20px; height: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; }-/* ── Content Drawer (slides up over the workspace) ── */+/* ── Summoned drawers (components/OverlayDrawer.tsx) ─────────────────────────+ Bounded to the workspace rather than to the window: the menu bar, toolbar and+ status bar stay live underneath a summoned surface. The status bar in+ particular is where a running agent reports progress, and dimming it would+ hide the thing that says work is happening.++ Every one of them leads with the accent edge and slides from the side it+ belongs to. Its SIZE and surface are its own (.drawer--content, --agent). */.scrim {- position: fixed;- top: 0;- left: 0;- right: 0;- bottom: var(--h-status);+ position: absolute;+ inset: 0;z-index: var(--z-drawer);+ display: flex;background: var(--overlay);opacity: 0;pointer-events: none;transition: opacity var(--t) var(--e-out);}.scrim.open { opacity: 1; pointer-events: auto; }+.scrim--bottom { align-items: flex-end; }+.scrim--right { justify-content: flex-end; }.drawer {- position: fixed;- left: 0;- right: 0;- bottom: var(--h-status);- z-index: calc(var(--z-drawer) + 1);- height: 46vh;- min-height: 320px;- background: var(--srf-2);- border-top: 2px solid var(--acc);- box-shadow: var(--shadow-3);+ flex: none;+ min-height: 0;+ max-height: 100%;display: flex;flex-direction: column;- transform: translateY(calc(100% + var(--h-status)));+ background: var(--srf-2);+ box-shadow: var(--shadow-3);transition: transform var(--t-slow) var(--e-spring);}-.scrim.open .drawer { transform: translateY(0); }+.scrim--bottom > .drawer { width: 100%; border-top: 2px solid var(--acc); transform: translateY(100%); }+.scrim--right > .drawer { height: 100%; border-left: 2px solid var(--acc); transform: translateX(100%); }+.scrim.open > .drawer { transform: none; }+@media (prefers-reduced-motion: reduce) {+ .scrim, .drawer { transition: none; }+}+.drawer--content { height: 46%; min-height: min(320px, 100%); }.drawer-head {height: 42px;flex-shrink: 0;diff --git a/desktop/src/theme/tokens.css b/desktop/src/theme/tokens.cssindex 10ae5e419..236193a4a 100644--- a/desktop/src/theme/tokens.css+++ b/desktop/src/theme/tokens.css@@ -153,7 +153,7 @@stacking (z 1–20) stays literal. Same-tier surfaces resolve by DOMorder (a menu summoned from a dialog mounts later, so it wins). — */--z-toolbar: 40; /* sticky shell chrome above panel content */- --z-drawer: 100; /* content-drawer scrim; drawer +1; statusbar +3 */+ --z-drawer: 100; /* summoned-drawer scrim (its panel is a child); statusbar +3 */--z-dialog: 124; /* dialog/palette scrims + windows (Settings, Modal, pickers) */--z-tooltip: 135; /* hover cards — above dialogs, below interactive floats */--z-popover: 150; /* anchored popovers/dropdowns */