PromucFlow_constructor/app/client/src/pages/common/CanvasDraggingArena.tsx
Ashok Kumar M f19ebbafe9
[Feature] Widget grouping - Allow Drag and Drop of multiple widgets. (#5389)
* dip

* dip

* scroll

* fixes

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* dip

* solve for canvas glitches

* dip

* dip

* dip

* adjust scroll speed

* dip

* dip(code clean up)

* dip

* dip

* ---dip

* dip

* dip

* dip

* middle ware for dropping multiple widgets.

* adding scroll to drag for canvas selection.

* fixing drag disabled and modal widget(detach from layout) drops

* firefox and safari fixes

* rebase conflicts.

* fixing broken specs.

* fixing specs and adding jest tests.

* show border and disable resize when multiple widgets are selected.

* selection box grab cursor

* merge conflicts.

* code clean up

* fixing specs.

* fixed a bug and failed specs.

* fixing rerenders.

* code clean up

* code review comments

* always have the drag point inside the widget.

* fetching snap spaces instead of calculating.

* remove widget_move action

* fixing bugs with add widget parent height updation.

* fixing specs.

* List widget conflict fixes.

* fixing canvas drop persistence.

* Adding click to drag for modals and fixing few issues.
2021-08-12 11:15:38 +05:30

76 lines
1.9 KiB
TypeScript

import { theme } from "constants/DefaultTheme";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
import React, { useMemo } from "react";
import styled from "styled-components";
import { useCanvasDragging } from "utils/hooks/useCanvasDragging";
const StyledSelectionCanvas = styled.div<{ paddingBottom: number }>`
position: absolute;
top: 0px;
left: 0px;
height: calc(100% + ${(props) => props.paddingBottom}px);
width: 100%;
image-rendering: -moz-crisp-edges;
image-rendering: -webkit-crisp-edges;
image-rendering: pixelated;
image-rendering: crisp-edges;
overflow-y: auto;
`;
export interface SelectedArenaDimensions {
top: number;
left: number;
width: number;
height: number;
}
export interface CanvasDraggingArenaProps {
canExtend: boolean;
detachFromLayout?: boolean;
dropDisabled?: boolean;
noPad?: boolean;
snapColumnSpace: number;
snapRows: number;
snapRowSpace: number;
widgetId: string;
}
export function CanvasDraggingArena({
canExtend,
dropDisabled = false,
noPad,
snapColumnSpace,
snapRows,
snapRowSpace,
widgetId,
}: CanvasDraggingArenaProps) {
const needsPadding = useMemo(() => {
return widgetId === MAIN_CONTAINER_WIDGET_ID;
}, [widgetId]);
const canvasRef = React.useRef<HTMLDivElement>(null);
const canvasDrawRef = React.useRef<HTMLCanvasElement>(null);
const { showCanvas } = useCanvasDragging(canvasRef, canvasDrawRef, {
canExtend,
dropDisabled,
noPad,
snapColumnSpace,
snapRows,
snapRowSpace,
widgetId,
});
return showCanvas ? (
<>
<canvas ref={canvasDrawRef} />
<StyledSelectionCanvas
data-testid={`canvas-dragging-${widgetId}`}
id={`canvas-dragging-${widgetId}`}
paddingBottom={needsPadding ? theme.canvasBottomPadding : 0}
ref={canvasRef}
/>
</>
) : null;
}
CanvasDraggingArena.displayName = "CanvasDraggingArena";