From 6972e06bbb19fbaa9d0894dc447423180b140ebc Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Fri, 27 Oct 2023 13:31:50 +0800 Subject: [PATCH] fix: block position when dragged into the editor (#1401) --- src/newtab/pages/workflows/[id].vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/newtab/pages/workflows/[id].vue b/src/newtab/pages/workflows/[id].vue index b4e8f5d0..0ee74c19 100644 --- a/src/newtab/pages/workflows/[id].vue +++ b/src/newtab/pages/workflows/[id].vue @@ -1239,12 +1239,15 @@ function onDragoverEditor({ target }) { } function onDropInEditor({ dataTransfer, clientX, clientY, target }) { const savedBlocks = parseJSON(dataTransfer.getData('savedBlocks'), null); + + const editorRect = editor.value.viewportRef.value.getBoundingClientRect(); + const position = editor.value.project({ + y: clientY - editorRect.top, + x: clientX - editorRect.left, + }); + if (savedBlocks && !isPackage) { if (savedBlocks.settings.asBlock) { - const position = editor.value.project({ - x: clientX - 360, - y: clientY - 18, - }); editor.value.addNodes([ { position, @@ -1285,7 +1288,6 @@ function onDropInEditor({ dataTransfer, clientX, clientY, target }) { return; } - const position = editor.value.project({ x: clientX - 360, y: clientY - 18 }); const nodeId = nanoid(); const newNode = { position,