feat(map): add Cesium visual settings and fullscreen-safe scene windows
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodedc/ui-react",
|
||||
"version": "0.7.4",
|
||||
"version": "0.7.5",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -94,6 +94,7 @@ export function Window({
|
||||
const titleId = useId();
|
||||
const descriptionId = useId();
|
||||
const dialogRef = useRef<HTMLDivElement>(null);
|
||||
const portalHostRef = useRef<Element | null>(null);
|
||||
const onCloseRef = useRef(onClose);
|
||||
const dragRef = useRef<{ pointerId: number; offsetX: number; offsetY: number } | null>(null);
|
||||
const [dragPosition, setDragPosition] = useState<{ left: number; top: number } | null>(null);
|
||||
@@ -134,13 +135,17 @@ export function Window({
|
||||
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;
|
||||
}
|
||||
const ownedFullscreen = document.fullscreenElement && dialogRef.current?.contains(document.fullscreenElement);
|
||||
// Escape restores the embedded viewport, never closes its owning form.
|
||||
if (event.key === "Escape" && ownedFullscreen) return;
|
||||
if (event.key === "Escape" && closeOnEscape && (!modeRef.current.isFloating || dialogRef.current?.contains(document.activeElement))) {
|
||||
event.preventDefault();
|
||||
onCloseRef.current();
|
||||
return;
|
||||
}
|
||||
if (event.key !== "Tab" || !modeRef.current.shouldTrapFocus || !dialogRef.current) return;
|
||||
const focusable = Array.from(dialogRef.current.querySelectorAll<HTMLElement>(focusableSelector)).filter(element => element.getClientRects().length > 0);
|
||||
const focusScope = ownedFullscreen ? document.fullscreenElement! : dialogRef.current;
|
||||
const focusable = Array.from(focusScope.querySelectorAll<HTMLElement>(focusableSelector)).filter(element => element.getClientRects().length > 0);
|
||||
if (focusable.length === 0) {
|
||||
event.preventDefault();
|
||||
dialogRef.current.focus();
|
||||
@@ -242,6 +247,12 @@ export function Window({
|
||||
if (allowBackdropClose && event.target === event.currentTarget) onClose();
|
||||
};
|
||||
|
||||
// Keep an owning window in its existing portal while its child is fullscreen.
|
||||
// Reparenting it into that child would form a DOM cycle and remount the renderer.
|
||||
const fullscreen = document.fullscreenElement;
|
||||
if (!portalHostRef.current || !fullscreen || !dialogRef.current?.contains(fullscreen)) {
|
||||
portalHostRef.current = fullscreen ?? document.body;
|
||||
}
|
||||
return createPortal(
|
||||
<LoadingContext.Provider value={null}><InspectorSelectPolicyContext.Provider value={false}>
|
||||
<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}>
|
||||
@@ -249,6 +260,7 @@ export function Window({
|
||||
ref={dialogRef}
|
||||
className={cn("nodedc-window nodedc-glass-material nodedc-material-rim", className)}
|
||||
data-material="glass-v4"
|
||||
data-glass-context={isFloating ? "scene" : undefined}
|
||||
data-size={size === "md" ? undefined : size}
|
||||
data-placement={placement}
|
||||
data-draggable={canDrag ? "true" : undefined}
|
||||
@@ -318,7 +330,7 @@ export function Window({
|
||||
</div>
|
||||
</div>
|
||||
</WindowSuspensionContext.Provider></InspectorSelectPolicyContext.Provider></LoadingContext.Provider>,
|
||||
document.fullscreenElement ?? document.body,
|
||||
portalHostRef.current,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user