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

Minimal drag and drop patch based on PR 292 #307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

beekhof
Copy link

@beekhof beekhof commented Sep 17, 2023

Add basic drag-and-drop functionality

@beekhof beekhof mentioned this pull request Sep 17, 2023
@riyasat-ali
Copy link

riyasat-ali commented Oct 5, 2023

@beekhof How can we use that functionality of drag and drop for #307? Is there any Stackblitz or code-sandbox for that? Please let me know.

@bumbeishvili

@A7medMo7ammed20
Copy link

A7medMo7ammed20 commented Oct 13, 2023

How can i use your updated version (Drag and Drop Functionality) ?

};
if (
(cP.x1 > cPInner.x0 && cP.x0 < cPInner.x1) &&
(cP.y1 > cPInner.y0 && cP.y0 < cPInner.y1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into issues here where a node would have collisions with multiple nodes.
Ideally we want a collision with one node.

So in my code I changed this condition to account for the width of the node.

Basically if the sourceNode is halfway over the targetNode I then assign it as the target node.

cP.x1 - event.width / 2 > cPInner.x0 &&
cP.x0 + event.width / 2 < cPInner.x1 &&
cP.y1 - event.height / 2 > cPInner.y0 &&
cP.y0 + event.height / 2 < cPInner.y1

Using the half way mark is my best approach because the sourceNode could never be halfway over multiple target nodes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also store halfWidth and halfHeight on cP so that you don't have to keep calculating inside the condition

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const cP = {
    x0: d.x,
    y0: d.y,
    x1: d.x + event.width,
    y1: d.y + event.height,
    midX: d.x + event.width / 2,
    midY: d.y + event.height / 2
};



cP.midX > cPInner.x0 &&
cP.midX < cPInner.x1 &&
cP.midY > cPInner.y0 &&
cP.midY < cPInner.y1

@seanpmaxwell
Copy link

I second this, please implement this feature.

@bumbeishvili
Copy link
Owner

@seanpmaxwell

image

To implement this feature, I have to discard paid projects and lose about 1500-2500$ , so if someone who needs it is willing to pay this amount, I am happy to implement it and include it in the build

@joelcoxokc
Copy link

joelcoxokc commented Jan 18, 2024

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app.
https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it.
Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled.
So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

@seanpmaxwell
Copy link

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app. https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it. Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled. So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

Thanks so much for this.

@joelcoxokc
Copy link

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app. https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it. Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled. So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

Thanks so much for this.

There is an open PR that has more defined code.

@seanpmaxwell
Copy link

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app. https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it. Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled. So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

Thanks so much for this.

There is an open PR that has more defined code.

More than the stackblitz example? I saw that but it does it also require the html buttons that the stackblitz example did?

@joelcoxokc
Copy link

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app. https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it. Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled. So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

Thanks so much for this.

There is an open PR that has more defined code.

More than the stackblitz example? I saw that but it does it also require the html buttons that the stackblitz example did?

The PR is for adding the code to the library. So it is probably not useful to you until @bumbeishvili merges it.

The example in the stack blitz is an implementation on top of the existing library that requires much more code on your side.
I am currently using the stackblitx example in my own production codebase.

Though I am using angular, and not HTML buttons and selectors

@seanpmaxwell
Copy link

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app. https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it. Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled. So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

Thanks so much for this.

There is an open PR that has more defined code.

More than the stackblitz example? I saw that but it does it also require the html buttons that the stackblitz example did?

The PR is for adding the code to the library. So it is probably not useful to you until @bumbeishvili merges it.

The example in the stack blitz is an implementation on top of the existing library that requires much more code on your side. I am currently using the stackblitx example in my own production codebase.

Though I am using angular, and not HTML buttons and selectors

Hmm, so I can probably replicate what's in stackblitz in my own code if I can rewrite in in Html? Thanks. I'll message again if I have any other questions.

@seanpmaxwell
Copy link

@bumbeishvili @seanpmaxwell @riyasat-ali @A7medMo7ammed20 @beekhof

Here is my drag example.. I copied what I could from our production app. https://stackblitz.com/edit/js-bmyjfc?file=index.html

This has undo/redo/cancel built into it. Also each node can be draggable or droppable.

I made a button to start the drag process.. otherwise there are all kinds of issues when trying to pan while dragging is enabled. So you have to click organize to start the drag-drop.

@bumbeishvili Feel free to fork this and add it to the examples

Thanks so much for this.

There is an open PR that has more defined code.

More than the stackblitz example? I saw that but it does it also require the html buttons that the stackblitz example did?

The PR is for adding the code to the library. So it is probably not useful to you until @bumbeishvili merges it.

The example in the stack blitz is an implementation on top of the existing library that requires much more code on your side. I am currently using the stackblitx example in my own production codebase.

Though I am using angular, and not HTML buttons and selectors

Dude your sample code is amazing, I'm almost done with drag and drop. One thing though, it always inserts at the beginning on the siblings. Any idea how I can get it to insert at the end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants