From 1bfd9c0e913f3eefc4593f6c344db1ae1f6e4df4 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Fri, 13 Dec 2024 11:20:53 +0200 Subject: [PATCH] feat(editor): Support adding nodes via drag and drop from node creator on new canvas (#12197) --- .../Node/NodeCreator/ItemTypes/NodeItem.vue | 35 +++++-------------- .../src/components/canvas/Canvas.vue | 35 ++++++++++++------- .../background/CanvasBackground.test.ts | 33 +++++++++++++++++ .../elements/background/CanvasBackground.vue | 24 +++++++++++++ .../CanvasBackgroundStripedPattern.vue | 0 .../CanvasBackground.test.ts.snap | 11 ++++++ packages/editor-ui/src/views/NodeView.v2.vue | 24 +++++++++++++ packages/editor-ui/src/views/NodeView.vue | 5 +-- 8 files changed, 123 insertions(+), 44 deletions(-) create mode 100644 packages/editor-ui/src/components/canvas/elements/background/CanvasBackground.test.ts create mode 100644 packages/editor-ui/src/components/canvas/elements/background/CanvasBackground.vue rename packages/editor-ui/src/components/canvas/elements/{ => background}/CanvasBackgroundStripedPattern.vue (100%) create mode 100644 packages/editor-ui/src/components/canvas/elements/background/__snapshots__/CanvasBackground.test.ts.snap diff --git a/packages/editor-ui/src/components/Node/NodeCreator/ItemTypes/NodeItem.vue b/packages/editor-ui/src/components/Node/NodeCreator/ItemTypes/NodeItem.vue index 9b4a8614d2..b982e4ecee 100644 --- a/packages/editor-ui/src/components/Node/NodeCreator/ItemTypes/NodeItem.vue +++ b/packages/editor-ui/src/components/Node/NodeCreator/ItemTypes/NodeItem.vue @@ -9,7 +9,6 @@ import { } from '@/constants'; import { isCommunityPackageName } from '@/utils/nodeTypesUtils'; -import { getNewNodePosition, NODE_SIZE } from '@/utils/nodeViewUtils'; import { useNodeCreatorStore } from '@/stores/nodeCreator.store'; import NodeIcon from '@/components/NodeIcon.vue'; @@ -93,15 +92,6 @@ const isTrigger = computed(() => { }); function onDragStart(event: DragEvent): void { - /** - * Workaround for firefox, that doesn't attach the pageX and pageY coordinates to "ondrag" event. - * All browsers attach the correct page coordinates to the "dragover" event. - * @bug https://bugzilla.mozilla.org/show_bug.cgi?id=505521 - */ - document.body.addEventListener('dragover', onDragOver); - - const { pageX: x, pageY: y } = event; - if (event.dataTransfer) { event.dataTransfer.effectAllowed = 'copy'; event.dataTransfer.dropEffect = 'copy'; @@ -113,22 +103,9 @@ function onDragStart(event: DragEvent): void { } dragging.value = true; - draggablePosition.value = { x, y }; -} - -function onDragOver(event: DragEvent): void { - if (!dragging.value || (event.pageX === 0 && event.pageY === 0)) { - return; - } - - const [x, y] = getNewNodePosition([], [event.pageX - NODE_SIZE / 2, event.pageY - NODE_SIZE / 2]); - - draggablePosition.value = { x, y }; } function onDragEnd(): void { - document.body.removeEventListener('dragover', onDragOver); - dragging.value = false; setTimeout(() => { draggablePosition.value = { x: -100, y: -100 }; @@ -144,7 +121,7 @@ function onCommunityNodeTooltipClick(event: MouseEvent) { - +