PromucFlow_constructor/app/client/src/components/editorComponents/DropTargetUtils.ts

25 lines
770 B
TypeScript
Raw Normal View History

2020-01-16 11:46:21 +00:00
import { OccupiedSpace } from "constants/editorConstants";
import { GridDefaults } from "constants/WidgetConstants";
2020-01-16 11:46:21 +00:00
export const calculateDropTargetRows = (
widgetId: string,
widgetBottomRow: number,
defaultRows: number,
2020-01-16 11:46:21 +00:00
occupiedSpacesByChildren?: OccupiedSpace[],
) => {
/* Max bottom row including the existing widgets as well as the widget we just dropped */
let minBottomRow = widgetBottomRow;
if (occupiedSpacesByChildren) {
minBottomRow = occupiedSpacesByChildren.reduce((prev, next) => {
if (next.id !== widgetId) {
return next.bottom > prev ? next.bottom : prev;
}
return prev;
}, widgetBottomRow);
2020-01-16 11:46:21 +00:00
}
return Math.ceil(
Math.max(minBottomRow + GridDefaults.CANVAS_EXTENSION_OFFSET, defaultRows),
);
2020-01-16 11:46:21 +00:00
};