Skip to content

Commit

Permalink
✨ Added node draggable placeholder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Grozav authored and Alex Grozav committed Apr 12, 2022
1 parent 47ebea6 commit e0c6357
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
33 changes: 25 additions & 8 deletions packages/editor-ui/src/components/NodeCreator/NodeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
})
}}
</div>

<div :class="$style.draggable" ref="draggable" v-show="dragging">
<NodeIcon class="node-icon" :nodeType="nodeType" :size="40" :shrink="false" />
</div>
</div>
</div>
</template>
Expand All @@ -49,6 +53,11 @@ export default Vue.extend({
'nodeType',
'bordered',
],
data(): { dragging: boolean; } {
return {
dragging: false,
};
},
computed: {
shortNodeType() {
return this.$locale.shortNodeType(this.nodeType.name);
Expand All @@ -57,18 +66,13 @@ export default Vue.extend({
methods: {
onDragStart(event: DragEvent) {
this.$emit('dragstart', event);
this.$data.dragging = true;
const placeholder = document.createElement('div');
placeholder.innerText = 'DRAG MEEEE';
placeholder.style.position = "absolute";
document.body.appendChild(placeholder);
console.log(this.nodeType);
event.dataTransfer!.setDragImage(placeholder, 0, 0);
event.dataTransfer!.setDragImage(this.$refs.draggable as Element, 0, 0);
},
onDragEnd(event: Event) {
this.$emit('dragend', event);
this.$data.dragging = false;
},
},
// @ts-ignore
Expand Down Expand Up @@ -122,4 +126,17 @@ export default Vue.extend({
display: flex;
}
.draggable {
width: 100px;
height: 100px;
position: fixed;
top: -100px;
left: -100px;
border: 2px solid var(--color-foreground-xdark);
border-radius: var(--border-radius-large);
background-color: var(--color-background-xlight);
display: flex;
justify-content: center;
align-items: center;
}
</style>
7 changes: 1 addition & 6 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1323,13 +1323,8 @@ export default mixins(
// when pulling new connection from node or injecting into a connection
const lastSelectedNode = this.lastSelectedNode;
console.log(this.lastClickPosition, options.position, CanvasHelpers.GRID_SIZE, CanvasHelpers.NODE_SIZE);
if (options.position) {
newNodeData.position = CanvasHelpers.getNewNodePosition(this.nodes, [
options.position[0] - CanvasHelpers.NODE_SIZE / 2,
options.position[1] - CanvasHelpers.NODE_SIZE / 2,
]);
newNodeData.position = CanvasHelpers.getNewNodePosition(this.nodes, options.position);
} else if (lastSelectedNode) {
const lastSelectedConnection = this.lastSelectedConnection;
if (lastSelectedConnection) { // set when injecting into a connection
Expand Down

0 comments on commit e0c6357

Please sign in to comment.