2021-08-12 05:45:38 +00:00
|
|
|
import { Layers } from "constants/Layers";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
2021-08-12 05:45:38 +00:00
|
|
|
import { useMemo } from "react";
|
2022-08-24 12:16:32 +00:00
|
|
|
import { AppState } from "@appsmith/reducers";
|
2022-09-14 06:55:08 +00:00
|
|
|
import { isWidgetSelected } from "selectors/widgetSelectors";
|
2022-11-28 08:13:17 +00:00
|
|
|
import { useSelector } from "react-redux";
|
2021-08-12 05:45:38 +00:00
|
|
|
|
|
|
|
|
export const usePositionedContainerZIndex = (
|
2021-09-09 15:10:22 +00:00
|
|
|
droppableWidget: boolean,
|
2023-03-04 07:25:54 +00:00
|
|
|
widgetId: string,
|
|
|
|
|
focused?: boolean,
|
|
|
|
|
selected?: boolean,
|
2021-08-12 05:45:38 +00:00
|
|
|
) => {
|
|
|
|
|
const isDragging = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
|
|
|
);
|
2023-03-04 07:25:54 +00:00
|
|
|
const isSelected = useSelector(isWidgetSelected(widgetId));
|
2022-09-14 06:55:08 +00:00
|
|
|
const isThisWidgetDragging = isDragging && isSelected;
|
2021-08-12 05:45:38 +00:00
|
|
|
|
|
|
|
|
const zIndex = useMemo(() => {
|
|
|
|
|
if (isDragging) {
|
|
|
|
|
// dragging mode use cases
|
|
|
|
|
if (!isThisWidgetDragging && droppableWidget) {
|
|
|
|
|
return Layers.positionedWidget + 1;
|
|
|
|
|
} else {
|
|
|
|
|
// all non container widgets should go last into the background to not interfere with mouse move
|
|
|
|
|
// since it is not technically dragged but just drawn on canvas as the mouse moves.
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// common use case when nothing is dragged
|
|
|
|
|
|
2023-03-04 07:25:54 +00:00
|
|
|
return focused
|
2021-08-12 05:45:38 +00:00
|
|
|
? Layers.focusedWidget
|
2023-03-04 07:25:54 +00:00
|
|
|
: selected
|
2021-08-12 05:45:38 +00:00
|
|
|
? Layers.selectedWidget
|
|
|
|
|
: Layers.positionedWidget;
|
|
|
|
|
}
|
2023-03-04 07:25:54 +00:00
|
|
|
}, [isDragging, isThisWidgetDragging, droppableWidget, selected, focused]);
|
2021-08-12 05:45:38 +00:00
|
|
|
|
|
|
|
|
const zIndicesObj = useMemo(() => {
|
|
|
|
|
const onHoverZIndex = isDragging ? zIndex : Layers.positionedWidget + 1;
|
|
|
|
|
return { zIndex, onHoverZIndex };
|
2022-09-14 06:55:08 +00:00
|
|
|
}, [isDragging, zIndex, Layers.positionedWidget]);
|
2021-08-12 05:45:38 +00:00
|
|
|
|
|
|
|
|
return zIndicesObj;
|
|
|
|
|
};
|