PromucFlow_constructor/app/client/src/components/editorComponents/ResizableUtils.tsx

76 lines
2.0 KiB
TypeScript
Raw Normal View History

import { WidgetProps, WidgetRowCols } from "widgets/BaseWidget";
2020-01-16 11:46:21 +00:00
import { GridDefaults } from "constants/WidgetConstants";
import { XYCord } from "pages/common/CanvasArenas/hooks/useCanvasDragging";
export type UIElementSize = { height: number; width: number };
export const RESIZABLE_CONTAINER_BORDER_THEME_INDEX = 1;
feat: Reflow and Resize while Dragging and Resizing widgets. (#9054) * resize n reflow rough cut * removing warnings * relatively stable changes * minor bug fix * reflow relative collision * working dp cut * fix for reflow of widgets closer next to each other * disabling scroll * Drag with reflow * reflow fix * overlap and retracing fix * On Drop updates. * bug when no displacement but resize update. * temp fix for new widget addition. * reflow bug fixes * new widget addition bug. * stop reflow on leave. * fix corner case overlap * update bottom row when reflowed widgets go beyond bottom boundary. * capture mouse positions on enter * enable container jumps with faster mouse movements. * reflow only for snap changes. * restructured reflow Algorithm * collision check and bug fixes * undo redo fix for new widget drop * resizable fix snapRows fix * directional stability * self collision fix * first round of perf fixes * update bottom row while resizing and resize-reflowing * performance fix and overlapping fix * Remove eslint warning * remove eslint warning * eslint warning * can reflowed Drop Indication Stability * container jumps and force direction on entering canvas * fixing scroll on resize jitters. * reflow when jumping into container. * reflow ux fixes while leaving container * resizing fixes. * fixes for edge move. * restrict container jumps into reflowed containers. * container jump direction reflow * checkbox dimensions fix. * Excess bottom rows not lost post dragging or resizing widgets. * fixing the after drop css glitch. * double first move trigger bug fix. * stop reflow only if reflowing * stabilize container exit directions * using acceleration and speed instead of movement covered to restrict reflow. * fixing modal drops. * remove warnings. * reflow resize styles * moving acceleration and movement logic to a monitoring effect. * adding beta flag for reflow. * fixing jest tests * Adding analytics to beta flag toggle. * Adding placeholder for reflow beta screens. * fixing initial load's screen * few more crashes. * force close onboarding for the session. * fixing bugs in reset canvas. * Beta flag bug fixes. * fixing bugs. * restrict reflow screens during onboarding. * disabling reflow screens in tests. * code review comments. * fixing store based specs. * fixing cypress failures. * fixing specs. * code cleanup * reverting yarn lock changes * removing onboarding screens. * more cleanup and function descriptors * keeping reflow under the hood. Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2022-01-13 13:21:57 +00:00
export type WidgetPosition = {
rightColumn: number;
leftColumn: number;
bottomRow: number;
topRow: number;
parentRowSpace: number;
parentColumnSpace: number;
};
export type WidgetExtendedPosition = WidgetPosition & {
paddingOffset: number;
};
2020-02-18 19:56:58 +00:00
export const computeRowCols = (
delta: UIElementSize,
position: XYCord,
feat: Reflow and Resize while Dragging and Resizing widgets. (#9054) * resize n reflow rough cut * removing warnings * relatively stable changes * minor bug fix * reflow relative collision * working dp cut * fix for reflow of widgets closer next to each other * disabling scroll * Drag with reflow * reflow fix * overlap and retracing fix * On Drop updates. * bug when no displacement but resize update. * temp fix for new widget addition. * reflow bug fixes * new widget addition bug. * stop reflow on leave. * fix corner case overlap * update bottom row when reflowed widgets go beyond bottom boundary. * capture mouse positions on enter * enable container jumps with faster mouse movements. * reflow only for snap changes. * restructured reflow Algorithm * collision check and bug fixes * undo redo fix for new widget drop * resizable fix snapRows fix * directional stability * self collision fix * first round of perf fixes * update bottom row while resizing and resize-reflowing * performance fix and overlapping fix * Remove eslint warning * remove eslint warning * eslint warning * can reflowed Drop Indication Stability * container jumps and force direction on entering canvas * fixing scroll on resize jitters. * reflow when jumping into container. * reflow ux fixes while leaving container * resizing fixes. * fixes for edge move. * restrict container jumps into reflowed containers. * container jump direction reflow * checkbox dimensions fix. * Excess bottom rows not lost post dragging or resizing widgets. * fixing the after drop css glitch. * double first move trigger bug fix. * stop reflow only if reflowing * stabilize container exit directions * using acceleration and speed instead of movement covered to restrict reflow. * fixing modal drops. * remove warnings. * reflow resize styles * moving acceleration and movement logic to a monitoring effect. * adding beta flag for reflow. * fixing jest tests * Adding analytics to beta flag toggle. * Adding placeholder for reflow beta screens. * fixing initial load's screen * few more crashes. * force close onboarding for the session. * fixing bugs in reset canvas. * Beta flag bug fixes. * fixing bugs. * restrict reflow screens during onboarding. * disabling reflow screens in tests. * code review comments. * fixing store based specs. * fixing cypress failures. * fixing specs. * code cleanup * reverting yarn lock changes * removing onboarding screens. * more cleanup and function descriptors * keeping reflow under the hood. Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2022-01-13 13:21:57 +00:00
props: WidgetPosition,
2020-02-18 19:56:58 +00:00
) => {
return {
leftColumn: Math.round(
props.leftColumn + position.x / props.parentColumnSpace,
2020-01-16 11:46:21 +00:00
),
topRow: Math.round(props.topRow + position.y / props.parentRowSpace),
2020-02-18 19:56:58 +00:00
rightColumn: Math.round(
props.rightColumn + (delta.width + position.x) / props.parentColumnSpace,
2020-01-16 11:46:21 +00:00
),
bottomRow: Math.round(
props.bottomRow + (delta.height + position.y) / props.parentRowSpace,
2020-01-16 11:46:21 +00:00
),
};
2020-02-18 19:56:58 +00:00
};
2020-02-18 19:56:58 +00:00
export const computeBoundedRowCols = (rowCols: WidgetRowCols) => {
return {
leftColumn: Math.max(rowCols.leftColumn, 0),
rightColumn: Math.min(
rowCols.rightColumn,
GridDefaults.DEFAULT_GRID_COLUMNS,
),
topRow: rowCols.topRow,
bottomRow: rowCols.bottomRow,
};
};
export const hasRowColsChanged = (
newRowCols: WidgetRowCols,
props: WidgetProps,
) => {
return (
props.leftColumn !== newRowCols.leftColumn ||
props.topRow !== newRowCols.topRow ||
props.bottomRow !== newRowCols.bottomRow ||
props.rightColumn !== newRowCols.rightColumn
2020-02-18 19:56:58 +00:00
);
};
2020-02-18 19:56:58 +00:00
export const computeFinalRowCols = (
delta: UIElementSize,
position: XYCord,
props: WidgetProps,
2020-02-18 19:56:58 +00:00
): WidgetRowCols | false => {
const newRowCols = computeBoundedRowCols(
computeRowCols(delta, position, props),
);
2020-02-18 19:56:58 +00:00
return hasRowColsChanged(newRowCols, props) ? newRowCols : false;
};