Floating Window Update (#2964)
This commit is contained in:
@@ -60,7 +60,7 @@ function WindowsButton(props: {
|
|||||||
<button
|
<button
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
onClick={props.disabled ? undefined : props.onClick}
|
onClick={props.disabled ? undefined : props.onClick}
|
||||||
className="flex h-[0.8rem] w-[0.8rem] items-center justify-center gap-2 text-white opacity-80 hover:opacity-100"
|
className="flex h-[0.8rem] w-[0.8rem] items-center justify-center gap-2 p-3 text-white opacity-80 hover:bg-[rgba(255,255,255,0.2)] hover:opacity-100"
|
||||||
style={{ opacity: props.disabled ? 0.5 : 1 }}
|
style={{ opacity: props.disabled ? 0.5 : 1 }}
|
||||||
title={props.tip}
|
title={props.tip}
|
||||||
>
|
>
|
||||||
@@ -97,6 +97,7 @@ function getOs(): OS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function FloatingWindow({
|
function FloatingWindow({
|
||||||
|
bounded,
|
||||||
children,
|
children,
|
||||||
initialWidth,
|
initialWidth,
|
||||||
initialHeight,
|
initialHeight,
|
||||||
@@ -109,6 +110,7 @@ function FloatingWindow({
|
|||||||
// --
|
// --
|
||||||
onInteract,
|
onInteract,
|
||||||
}: {
|
}: {
|
||||||
|
bounded?: boolean;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
initialHeight?: number;
|
initialHeight?: number;
|
||||||
initialWidth?: number;
|
initialWidth?: number;
|
||||||
@@ -134,12 +136,16 @@ function FloatingWindow({
|
|||||||
height: initialHeight ?? Constants.MinHeight,
|
height: initialHeight ?? Constants.MinHeight,
|
||||||
width: initialWidth ?? Constants.MinWidth,
|
width: initialWidth ?? Constants.MinWidth,
|
||||||
});
|
});
|
||||||
const [sizeBeforeMaximize, setSizeBeforeMaximize] = useState({
|
const [restoreSize, setRestoreSize] = useState({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
height: initialHeight ?? Constants.MinHeight,
|
height: initialHeight ?? Constants.MinHeight,
|
||||||
width: initialWidth ?? Constants.MinWidth,
|
width: initialWidth ?? Constants.MinWidth,
|
||||||
});
|
});
|
||||||
|
const [minimizedPosition, setMinimizedPosition] = useState<{
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
} | null>(null);
|
||||||
const [isMaximized, setIsMaximized] = useState(maximized ?? false);
|
const [isMaximized, setIsMaximized] = useState(maximized ?? false);
|
||||||
const [isMinimized, setIsMinimized] = useState(false);
|
const [isMinimized, setIsMinimized] = useState(false);
|
||||||
const parentRef = useRef<HTMLDivElement>(null);
|
const parentRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -263,6 +269,10 @@ function FloatingWindow({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isMinimized) {
|
||||||
|
setMinimizedPosition({ x: position.x, y: position.y });
|
||||||
|
}
|
||||||
|
|
||||||
setPosition({ x: position.x, y: position.y });
|
setPosition({ x: position.x, y: position.y });
|
||||||
|
|
||||||
setSize({
|
setSize({
|
||||||
@@ -288,8 +298,14 @@ function FloatingWindow({
|
|||||||
setIsMinimized(false);
|
setIsMinimized(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMinimize = () => {
|
const toggleMinimized = () => {
|
||||||
setIsMinimized(true);
|
if (!isMinimized) {
|
||||||
|
minimize();
|
||||||
|
} else {
|
||||||
|
restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsMaximized(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const maximize = () => {
|
const maximize = () => {
|
||||||
@@ -300,13 +316,16 @@ function FloatingWindow({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSizeBeforeMaximize({
|
if (!isMinimized) {
|
||||||
...size,
|
setRestoreSize({
|
||||||
left: position.x,
|
...size,
|
||||||
top: position.y,
|
left: position.x,
|
||||||
});
|
top: position.y,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setIsMaximized(true);
|
setIsMaximized(true);
|
||||||
|
setIsMinimized(false);
|
||||||
|
|
||||||
setSize({
|
setSize({
|
||||||
left: 0,
|
left: 0,
|
||||||
@@ -319,9 +338,42 @@ function FloatingWindow({
|
|||||||
setPosition({ x: 0, y: 0 });
|
setPosition({ x: 0, y: 0 });
|
||||||
};
|
};
|
||||||
|
|
||||||
const restore = () => {
|
const minimize = () => {
|
||||||
const restoreSize = sizeBeforeMaximize;
|
const parent = parentRef.current;
|
||||||
|
|
||||||
|
if (!parent) {
|
||||||
|
console.warn("No parent - cannot minimize.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isMaximized) {
|
||||||
|
setRestoreSize({
|
||||||
|
...size,
|
||||||
|
left: position.x,
|
||||||
|
top: position.y,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsMaximized(false);
|
||||||
|
setIsMinimized(true);
|
||||||
|
|
||||||
|
const defaultLeft = 0;
|
||||||
|
const parentBottom = parentRef.current?.offsetHeight;
|
||||||
|
const defaultTop = parentBottom - Constants.MinHeight - 16;
|
||||||
|
const left = minimizedPosition?.x ?? defaultLeft;
|
||||||
|
const top = minimizedPosition?.y ?? defaultTop;
|
||||||
|
|
||||||
|
setSize({
|
||||||
|
left,
|
||||||
|
top,
|
||||||
|
width: Constants.MinWidth,
|
||||||
|
height: Constants.MinHeight,
|
||||||
|
});
|
||||||
|
|
||||||
|
setPosition({ x: left, y: top });
|
||||||
|
};
|
||||||
|
|
||||||
|
const restore = () => {
|
||||||
const position = isDragging
|
const position = isDragging
|
||||||
? { left: 0, top: 0 }
|
? { left: 0, top: 0 }
|
||||||
: {
|
: {
|
||||||
@@ -339,6 +391,7 @@ function FloatingWindow({
|
|||||||
setPosition({ x: position.left, y: position.top });
|
setPosition({ x: position.left, y: position.top });
|
||||||
|
|
||||||
setIsMaximized(false);
|
setIsMaximized(false);
|
||||||
|
setIsMinimized(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,7 +444,7 @@ function FloatingWindow({
|
|||||||
onStart={() => setIsDragging(true)}
|
onStart={() => setIsDragging(true)}
|
||||||
onDrag={(_, data) => onDrag(data)}
|
onDrag={(_, data) => onDrag(data)}
|
||||||
onStop={() => setIsDragging(false)}
|
onStop={() => setIsDragging(false)}
|
||||||
bounds="parent"
|
bounds={bounded ?? true ? "parent" : undefined}
|
||||||
disabled={isResizing}
|
disabled={isResizing}
|
||||||
>
|
>
|
||||||
<Resizable
|
<Resizable
|
||||||
@@ -430,6 +483,7 @@ function FloatingWindow({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsMinimized(false);
|
||||||
setIsResizing(true);
|
setIsResizing(true);
|
||||||
setDragStartSize({ ...size, left: position.x, top: position.y });
|
setDragStartSize({ ...size, left: position.x, top: position.y });
|
||||||
}}
|
}}
|
||||||
@@ -467,7 +521,11 @@ function FloatingWindow({
|
|||||||
toggleMaximized();
|
toggleMaximized();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="my-window-header flex h-[3rem] w-full cursor-move items-center justify-start gap-2 bg-[#031827] p-3">
|
<div
|
||||||
|
className={cn(
|
||||||
|
"my-window-header flex h-[3rem] w-full cursor-move items-center justify-start gap-2 bg-[#031827] p-3",
|
||||||
|
)}
|
||||||
|
>
|
||||||
{os === "macOS" ? (
|
{os === "macOS" ? (
|
||||||
<>
|
<>
|
||||||
<div className="buttons-container flex items-center gap-2">
|
<div className="buttons-container flex items-center gap-2">
|
||||||
@@ -482,9 +540,10 @@ function FloatingWindow({
|
|||||||
{showMinimizeButton && (
|
{showMinimizeButton && (
|
||||||
<MacOsButton
|
<MacOsButton
|
||||||
color="#FFBD44"
|
color="#FFBD44"
|
||||||
disabled={true}
|
tip={
|
||||||
tip="minimize"
|
isMaximized || isMinimized ? "restore" : "minimize"
|
||||||
onClick={onMinimize}
|
}
|
||||||
|
onClick={toggleMinimized}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showMaximizeButton && (
|
{showMaximizeButton && (
|
||||||
@@ -502,10 +561,25 @@ function FloatingWindow({
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div>{title}</div>
|
<div>{title}</div>
|
||||||
<div className="buttons-container ml-auto flex h-full items-center gap-4">
|
<div className="buttons-container ml-auto flex h-full items-center gap-2">
|
||||||
|
{showMinimizeButton && (
|
||||||
|
<WindowsButton
|
||||||
|
onClick={toggleMinimized}
|
||||||
|
tip={
|
||||||
|
isMaximized || isMinimized ? "restore" : "minimize"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div>—</div>
|
||||||
|
</WindowsButton>
|
||||||
|
)}
|
||||||
{showMaximizeButton && (
|
{showMaximizeButton && (
|
||||||
<WindowsButton onClick={toggleMaximized}>
|
<WindowsButton
|
||||||
<div>{isMaximized ? "-" : "□"}</div>
|
onClick={toggleMaximized}
|
||||||
|
tip={
|
||||||
|
isMaximized || isMinimized ? "restore" : "maximize"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div>□</div>
|
||||||
</WindowsButton>
|
</WindowsButton>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -186,17 +186,17 @@ const nodeLibraryItems: Array<{
|
|||||||
title: "Upload to S3 Block",
|
title: "Upload to S3 Block",
|
||||||
description: "Upload files to AWS S3",
|
description: "Upload files to AWS S3",
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// nodeType: "download",
|
nodeType: "download",
|
||||||
// icon: (
|
icon: (
|
||||||
// <WorkflowBlockIcon
|
<WorkflowBlockIcon
|
||||||
// workflowBlockType={WorkflowBlockTypes.DownloadToS3}
|
workflowBlockType={WorkflowBlockTypes.DownloadToS3}
|
||||||
// className="size-6"
|
className="size-6"
|
||||||
// />
|
/>
|
||||||
// ),
|
),
|
||||||
// title: "Download from S3 Block",
|
title: "Download from S3 Block",
|
||||||
// description: "Download files from AWS S3",
|
description: "Download files from AWS S3",
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
nodeType: "fileUpload",
|
nodeType: "fileUpload",
|
||||||
icon: (
|
icon: (
|
||||||
|
|||||||
Reference in New Issue
Block a user