diff --git a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte index 21d872a88e..53de2bec24 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte @@ -11,6 +11,9 @@ import { Utils, memo } from "@budibase/frontend-core" import { selectedAutomation, automationStore } from "stores/builder" + // CSS classes that, on mouse down, will trigger the view drag behaviour + export let draggableClasses = [] + export function toFocus() { viewToFocusEle() } @@ -161,6 +164,10 @@ // Scale prop for the icon let dotDefault = 0.006 + let viewDragStart = { x: 0, y: 0 } + let viewDragOffset = [0, 0] + let startPos = [0, 0] + $: bgSize = Math.max(bgDim * $view.scale, 10) $: bgWidth = bgSize $: bgHeight = bgSize @@ -275,14 +282,17 @@ y, })) - if (down && !$view.dragging && dragOffset) { + if (down && !$view.dragging) { + // Determine how much the view has moved since + viewDragOffset = [x - viewDragStart.x, y - viewDragStart.y] + contentPos.update(state => ({ ...state, - x: x - dragOffset[0], - y: y - dragOffset[1], + x: startPos[0] + viewDragOffset[0], + y: startPos[1] + viewDragOffset[1], })) - offsetX = x - dragOffset[0] - offsetY = y - dragOffset[1] + offsetX = startPos[0] + viewDragOffset[0] + offsetY = startPos[1] + viewDragOffset[1] } const clearScrollInterval = () => { @@ -367,6 +377,9 @@ const globalMouseUp = () => { down = false + viewDragStart = { x: 0, y: 0 } + viewDragOffset = [0, 0] + if ($view.dragging) { dragOffset = [0, 0] view.update(state => ({ @@ -482,6 +495,11 @@ dragOffset = [Math.abs(x - $contentPos.x), Math.abs(y - $contentPos.y)] } + const isDraggable = e => { + const draggable = ["draggable-view", ...draggableClasses] + return draggable.some(cls => e.target.classList.contains(cls)) + } + const viewToFocusEle = () => { if ($focusElement) { const viewWidth = viewDims.width @@ -566,31 +584,31 @@