Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move multiple nodes at once #341

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions packages/renderer-vue/src/editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,22 @@

<div class="node-container" :style="nodeContainerStyle">
<transition-group name="fade">
<template v-for="node in nodes" :key="node.id + counter.toString()">
<slot name="node" :node="node" :selected="selectedNodes.includes(node)" @select="selectNode(node)">
<Node :node="node" :selected="selectedNodes.includes(node)" @select="selectNode(node)" />
<template v-for="(node, idx) in nodes" :key="node.id + counter.toString()">
<slot
name="node"
:node="node"
:selected="selectedNodes.includes(node)"
:dragging="dragMoves[idx].dragging.value"
@select="selectNode(node)"
@start-drag="startDrag"
>
<Node
:node="node"
:selected="selectedNodes.includes(node)"
:dragging="dragMoves[idx].dragging.value"
@select="selectNode(node)"
@start-drag="startDrag"
/>
</slot>
</template>
</transition-group>
Expand All @@ -67,7 +80,7 @@ import { AbstractNode } from "@baklavajs/core";
import { IBaklavaViewModel } from "../viewModel";
import { usePanZoom } from "./panZoom";
import { useTemporaryConnection } from "./temporaryConnection";
import { providePlugin } from "../utility";
import { providePlugin, useDragMove } from "../utility";

import Background from "./Background.vue";
import Node from "../node/Node.vue";
Expand All @@ -89,6 +102,7 @@ const el = ref<HTMLElement | null>(null);
provide("editorEl", el);

const nodes = computed(() => props.viewModel.displayedGraph.nodes);
const dragMoves = computed(() => props.viewModel.displayedGraph.nodes.map((n) => useDragMove(toRef(n, "position"))));
const connections = computed(() => props.viewModel.displayedGraph.connections);
const selectedNodes = computed(() => props.viewModel.displayedGraph.selectedNodes);

Expand Down Expand Up @@ -147,4 +161,28 @@ const selectNode = (node: AbstractNode) => {
const unselectAllNodes = () => {
props.viewModel.displayedGraph.selectedNodes = [];
};

const startDrag = (ev: PointerEvent) => {
for (const selectedNode of props.viewModel.displayedGraph.selectedNodes) {
const idx = nodes.value.indexOf(selectedNode);
const dragMove = dragMoves.value[idx];
dragMove.onPointerDown(ev);

document.addEventListener("pointermove", dragMove.onPointerMove);
}

document.addEventListener("pointerup", stopDrag);
};

const stopDrag = () => {
for (const selectedNode of props.viewModel.displayedGraph.selectedNodes) {
const idx = nodes.value.indexOf(selectedNode);
const dragMove = dragMoves.value[idx];
dragMove.onPointerUp();

document.removeEventListener("pointermove", dragMove.onPointerMove);
}

document.removeEventListener("pointerup", stopDrag);
};
</script>
22 changes: 9 additions & 13 deletions packages/renderer-vue/src/node/Node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
</template>

<script setup lang="ts">
import { ref, computed, toRef, nextTick, onUpdated, onMounted } from "vue";
import { ref, computed, nextTick, onUpdated, onMounted } from "vue";
import { AbstractNode, GRAPH_NODE_TYPE_PREFIX, IGraphNode } from "@baklavajs/core";
import { useDragMove, useGraph, useViewModel } from "../utility";
import { useGraph, useViewModel } from "../utility";

import ContextMenu from "../components/ContextMenu.vue";
import VerticalDots from "../icons/VerticalDots.vue";
Expand All @@ -76,17 +76,18 @@ const props = withDefaults(
defineProps<{
node: AbstractNode;
selected?: boolean;
dragging?: boolean;
}>(),
{ selected: false },
);

const emit = defineEmits<{
(e: "select"): void;
(e: "start-drag", ev: PointerEvent): void;
}>();

const { viewModel } = useViewModel();
const { graph, switchGraph } = useGraph();
const dragMove = useDragMove(toRef(props.node, "position"));

const el = ref<HTMLElement | null>(null);
const renaming = ref(false);
Expand All @@ -109,7 +110,7 @@ const contextMenuItems = computed(() => {

const classes = computed(() => ({
"--selected": props.selected,
"--dragging": dragMove.dragging.value,
"--dragging": props.dragging,
"--two-column": !!props.node.twoColumn,
}));

Expand All @@ -127,16 +128,11 @@ const select = () => {
};

const startDrag = (ev: PointerEvent) => {
dragMove.onPointerDown(ev);
document.addEventListener("pointermove", dragMove.onPointerMove);
document.addEventListener("pointerup", stopDrag);
select();
};
if (!props.selected) {
select();
}

const stopDrag = () => {
dragMove.onPointerUp();
document.removeEventListener("pointermove", dragMove.onPointerMove);
document.removeEventListener("pointerup", stopDrag);
emit("start-drag", ev);
};

const openContextMenu = () => {
Expand Down