feat(ui): add measured level buttons and suspend modal hosts during scene editing

This commit is contained in:
Codex
2026-11-04 17:13:43 +03:00
parent bbbfa8912f
commit 8ff33a6a17
11 changed files with 130 additions and 14 deletions
+20 -7
View File
@@ -1,4 +1,5 @@
import {
useCallback,
useEffect,
useId,
useLayoutEffect,
@@ -11,6 +12,7 @@ import {
import { createPortal } from "react-dom";
import { InspectorSelectPolicyContext } from "./InspectorContext.js";
import { LoadingContext } from "./LoadingContext.js";
import { WindowSuspensionContext } from "./WindowSuspensionContext.js";
import { cn } from "./cn.js";
import { Icon } from "./Icon.js";
import { IconButton } from "./Button.js";
@@ -82,6 +84,9 @@ export function Window({
style,
...props
}: WindowProps) {
const [suspensions, setSuspensions] = useState(0);
const suspend = useCallback(() => {setSuspensions(value => value + 1); return () => setSuspensions(value => Math.max(0, value - 1));}, []);
const suspended = suspensions > 0;
const titleId = useId();
const descriptionId = useId();
const dialogRef = useRef<HTMLDivElement>(null);
@@ -100,10 +105,10 @@ export function Window({
const isFloating = floating && allowFloating && placement === "center";
const freeGeometry = isFloating || (resizable && placement === "end");
const canDrag = draggable || freeGeometry;
const shouldLockBodyScroll = !isFloating && (lockBodyScroll ?? placement === "center");
const shouldTrapFocus = !isFloating && (trapFocus ?? placement === "center");
const modeRef = useRef({ shouldTrapFocus, isFloating });
modeRef.current = { shouldTrapFocus, isFloating };
const shouldLockBodyScroll = !suspended && !isFloating && (lockBodyScroll ?? placement === "center");
const shouldTrapFocus = !suspended && !isFloating && (trapFocus ?? placement === "center");
const modeRef = useRef({ shouldTrapFocus, isFloating, suspended });
modeRef.current = { shouldTrapFocus, isFloating, suspended };
onCloseRef.current = onClose;
useEffect(() => {
@@ -116,7 +121,15 @@ export function Window({
});
const handleKeyDown = (event: KeyboardEvent) => {
if (event.defaultPrevented) return;
if (event.defaultPrevented || modeRef.current.suspended) return;
// Portalled child dialogs own their Escape/Tab keys. A parent listener
// can run first, so event.defaultPrevented alone cannot guard nesting.
const focusedDialog = document.activeElement?.closest('[role="dialog"]');
if (focusedDialog && focusedDialog !== dialogRef.current) return;
if (!focusedDialog) {
const topModal = Array.from(document.querySelectorAll<HTMLElement>('[role="dialog"][aria-modal="true"]')).filter(dialog => dialog.getClientRects().length > 0).at(-1);
if (topModal && topModal !== dialogRef.current) return;
}
if (event.key === "Escape" && closeOnEscape && (!modeRef.current.isFloating || dialogRef.current?.contains(document.activeElement))) {
event.preventDefault();
onCloseRef.current();
@@ -227,7 +240,7 @@ export function Window({
return createPortal(
<LoadingContext.Provider value={null}><InspectorSelectPolicyContext.Provider value={false}>
<div className="nodedc-overlay nodedc-ui-root" data-placement={placement} data-floating={isFloating || undefined} onPointerDown={handleBackdropPointerDown}>
<WindowSuspensionContext.Provider value={suspend}><div className="nodedc-overlay nodedc-ui-root" style={suspended ? {display:"none"} : undefined} data-placement={placement} data-floating={isFloating || undefined} onPointerDown={handleBackdropPointerDown}>
<div
ref={dialogRef}
className={cn("nodedc-window nodedc-glass-material nodedc-material-rim", className)}
@@ -298,7 +311,7 @@ export function Window({
{footer ? <footer className="nodedc-window__footer">{footer}</footer> : null}
</div>
</div>
</InspectorSelectPolicyContext.Provider></LoadingContext.Provider>,
</WindowSuspensionContext.Provider></InspectorSelectPolicyContext.Provider></LoadingContext.Provider>,
document.fullscreenElement ?? document.body,
);
}