feat(ui): remember expanded media geometry independently
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodedc/ui-react",
|
||||
"version": "0.7.9",
|
||||
"version": "0.7.10",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -44,6 +44,9 @@ export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title
|
||||
headerLayout?: "inline" | "adaptive";
|
||||
/** Temporarily enlarge within the viewport; restoring retains prior geometry and presentation. */
|
||||
expanded?: boolean;
|
||||
/** Separate durable layout for expanded media, committed only after a user gesture. */
|
||||
expandedRect?: WindowRect;
|
||||
onExpandedRectCommit?: (rect: WindowRect) => void;
|
||||
/** Keep contextual actions immediately before close when requested. */
|
||||
headerActionsPlacement?: "before-move" | "before-close";
|
||||
size?: WindowSize;
|
||||
@@ -78,6 +81,8 @@ export function Window({
|
||||
headerActions,
|
||||
headerLayout = "inline",
|
||||
expanded = false,
|
||||
expandedRect,
|
||||
onExpandedRectCommit,
|
||||
headerActionsPlacement = "before-move",
|
||||
size = "md",
|
||||
placement = "center",
|
||||
@@ -119,7 +124,7 @@ export function Window({
|
||||
const expansionRestoreRef = useRef<WindowRect | null>(null);
|
||||
const commitRef = useRef(onRectCommit);
|
||||
// Temporary media expansion never replaces the application-owned window layout.
|
||||
commitRef.current = expanded ? undefined : onRectCommit;
|
||||
commitRef.current = expanded ? onExpandedRectCommit : onRectCommit;
|
||||
const changeRect = (next: WindowRect | null) => { rectRef.current = next; setFloatingRect(next); };
|
||||
const gestureChanged = useRef(false);
|
||||
const resizeRef = useRef<{ pointerId: number; x: number; y: number; rect: WindowRect; edge: ResizeEdge } | null>(null);
|
||||
@@ -226,7 +231,9 @@ export function Window({
|
||||
const bounds=dialogRef.current?.getBoundingClientRect();
|
||||
if(bounds){
|
||||
expansionRestoreRef.current=rectRef.current??{left:bounds.left,top:bounds.top,width:bounds.width,height:bounds.height};
|
||||
changeRect(fitWindow({left:16,top:16,width:viewport.width-32,height:viewport.height-32},viewport,minimumRef.current));
|
||||
const width=Math.min(960,viewport.width*0.8),height=Math.min(800,viewport.height*0.82);
|
||||
const prior=expansionRestoreRef.current;
|
||||
changeRect(fitWindow(expandedRect??{left:prior.left+(prior.width-width)/2,top:prior.top+(prior.height-height)/2,width,height},viewport,minimumRef.current));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -292,10 +299,10 @@ export function Window({
|
||||
|
||||
useEffect(() => {
|
||||
if (!freeGeometry || !open) return;
|
||||
const fit = () => { if(rectRef.current) changeRect(fitWindow((expanded ? null : rect) ?? rectRef.current, { width: window.innerWidth, height: window.innerHeight },minimumRef.current)); };
|
||||
const fit = () => { if(rectRef.current) changeRect(fitWindow((expanded ? expandedRect : rect) ?? rectRef.current, { width: window.innerWidth, height: window.innerHeight },minimumRef.current)); };
|
||||
window.addEventListener("resize", fit);
|
||||
return () => window.removeEventListener("resize", fit);
|
||||
}, [freeGeometry, open, rect, expanded]);
|
||||
}, [freeGeometry, open, rect, expanded, expandedRect]);
|
||||
|
||||
if (!open || typeof document === "undefined") return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user