2021-05-18 18:29:39 +00:00
|
|
|
import {
|
|
|
|
|
useShowPropertyPane,
|
|
|
|
|
useWidgetSelection,
|
|
|
|
|
} from "utils/hooks/dragResizeHooks";
|
2021-03-29 15:47:22 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentWidgetId,
|
|
|
|
|
getIsPropertyPaneVisible,
|
|
|
|
|
} from "selectors/propertyPaneSelectors";
|
|
|
|
|
import { useSelector } from "store";
|
|
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import { APP_MODE } from "reducers/entityReducers/appReducer";
|
|
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
|
|
|
|
|
|
|
|
|
export const useClickOpenPropPane = () => {
|
|
|
|
|
const showPropertyPane = useShowPropertyPane();
|
2021-05-18 18:29:39 +00:00
|
|
|
const { selectWidget } = useWidgetSelection();
|
2021-03-29 15:47:22 +00:00
|
|
|
const isPropPaneVisible = useSelector(getIsPropertyPaneVisible);
|
|
|
|
|
const selectedWidgetId = useSelector(getCurrentWidgetId);
|
|
|
|
|
const focusedWidget = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.focusedWidget,
|
|
|
|
|
);
|
|
|
|
|
// This state tells us whether a `ResizableComponent` is resizing
|
|
|
|
|
const isResizing = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isResizing,
|
|
|
|
|
);
|
|
|
|
|
const appMode = useSelector(getAppMode);
|
|
|
|
|
|
|
|
|
|
// This state tells us whether a `DraggableComponent` is dragging
|
|
|
|
|
const isDragging = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
|
|
|
);
|
2021-05-18 18:29:39 +00:00
|
|
|
const openPropertyPane = (e: any, targetWidgetId: string) => {
|
2021-03-29 15:47:22 +00:00
|
|
|
// ignore click captures if the component was resizing or dragging coz it is handled internally in draggable component
|
2021-05-18 18:29:39 +00:00
|
|
|
if (
|
|
|
|
|
isResizing ||
|
|
|
|
|
isDragging ||
|
|
|
|
|
appMode !== APP_MODE.EDIT ||
|
|
|
|
|
targetWidgetId !== focusedWidget
|
|
|
|
|
)
|
|
|
|
|
return;
|
2021-03-29 15:47:22 +00:00
|
|
|
if (
|
|
|
|
|
(!isPropPaneVisible && selectedWidgetId === focusedWidget) ||
|
|
|
|
|
selectedWidgetId !== focusedWidget
|
|
|
|
|
) {
|
2021-05-18 18:29:39 +00:00
|
|
|
const isMultiSelect = e.metaKey || e.ctrlKey;
|
|
|
|
|
selectWidget(focusedWidget, isMultiSelect);
|
2021-03-29 15:47:22 +00:00
|
|
|
showPropertyPane(focusedWidget, undefined, true);
|
2021-05-18 18:29:39 +00:00
|
|
|
if (isMultiSelect) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}
|
2021-03-29 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return openPropertyPane;
|
|
|
|
|
};
|