2021-08-12 05:45:38 +00:00
|
|
|
import { PositionedContainerProps } from "components/designSystems/appsmith/PositionedContainer";
|
|
|
|
|
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";
|
2021-08-12 05:45:38 +00:00
|
|
|
import { useSelector } from "store";
|
|
|
|
|
|
|
|
|
|
export const usePositionedContainerZIndex = (
|
|
|
|
|
props: PositionedContainerProps,
|
2021-09-09 15:10:22 +00:00
|
|
|
droppableWidget: boolean,
|
2021-08-12 05:45:38 +00:00
|
|
|
) => {
|
|
|
|
|
const isDragging = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
|
|
|
);
|
2022-09-14 06:55:08 +00:00
|
|
|
const isSelected = useSelector(isWidgetSelected(props.widgetId));
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
return props.focused
|
|
|
|
|
? Layers.focusedWidget
|
|
|
|
|
: props.selected
|
|
|
|
|
? Layers.selectedWidget
|
|
|
|
|
: Layers.positionedWidget;
|
|
|
|
|
}
|
|
|
|
|
}, [
|
|
|
|
|
isDragging,
|
|
|
|
|
isThisWidgetDragging,
|
|
|
|
|
droppableWidget,
|
|
|
|
|
props.selected,
|
|
|
|
|
props.focused,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|