Ver código fonte

fix: block position when dragged into the editor (#1401)

Ahmad Kholid 1 ano atrás
pai
commit
6972e06bbb
1 arquivos alterados com 7 adições e 5 exclusões
  1. 7 5
      src/newtab/pages/workflows/[id].vue

+ 7 - 5
src/newtab/pages/workflows/[id].vue

@@ -1239,12 +1239,15 @@ function onDragoverEditor({ target }) {
 }
 }
 function onDropInEditor({ dataTransfer, clientX, clientY, target }) {
 function onDropInEditor({ dataTransfer, clientX, clientY, target }) {
   const savedBlocks = parseJSON(dataTransfer.getData('savedBlocks'), null);
   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 && !isPackage) {
     if (savedBlocks.settings.asBlock) {
     if (savedBlocks.settings.asBlock) {
-      const position = editor.value.project({
-        x: clientX - 360,
-        y: clientY - 18,
-      });
       editor.value.addNodes([
       editor.value.addNodes([
         {
         {
           position,
           position,
@@ -1285,7 +1288,6 @@ function onDropInEditor({ dataTransfer, clientX, clientY, target }) {
     return;
     return;
   }
   }
 
 
-  const position = editor.value.project({ x: clientX - 360, y: clientY - 18 });
   const nodeId = nanoid();
   const nodeId = nanoid();
   const newNode = {
   const newNode = {
     position,
     position,