I’m getting an unexpected situation where dropping a Node from Palette onto Diagram works on first drop, but then on 2nd drop, the same target (orange prepend) Node no longer takes the drop.
Do I need to run some update/redraw method on every drop?
No, between transactions everything should be correct and up-to-date.
It’s odd that your code is assuming that the “prependLink” is the first link data object and the “firstNode” is the second node data object, but maybe that’s because the code is experimental and you haven’t yet transformed the drop point into document coordinates so that you can find the Node or Link that was dropped upon (if any) via Diagram.findPartAt.
Looking at the code example you referenced and the DiagramEvent.html#name Docs, do I really need to reference the actual div element in order to add the “drop” event? I don’t see a drop DiagramEventName listed…
The main difference I noticed is that your code example adds the event listeners directly to the Diagram whereas I am adding them on the mouseDrop prop of a go.Node template.
I’m trying my best to stick to ReactDiagram design and avoid working on the native HTML element but I’m implementing your code example because I honestly don’t know what else to do to make it work.
The ‘drop’ event handler is not firing on any type of drop from the Palette.
As previously stated, adding this div.addEventListener("drop", mouseDrop) HTML drop event handler is not firing and I’m not sure how my logic behavior would be any different after a Drop event using this event handler as opposed to the GoJs event diagram.addDiagramListener('ExternalObjectsDropped', externalObjectsDropped);
We feel that it is a Diagram re-drawing issue… after a drop the mouse hovers act erratically and the more Palette Nodes I drop the weirder it gets… what would be a force re-draw method to call after calling Model.set()?
Calling Model methods to modify model state causes some updates of GraphObjects and the Diagram, but really the bulk of the updating only happens at the end of a transaction.
As you have seen in the HTML Drag and Drop sample, HTML Drag and Drop, and external Clipboard pasting, the “drop” code makes changes to the model within a transaction. The code that you have quoted seems perfectly reasonable to me.
As far as the “drop” HTML DOM event is concerned, you’ll want to check that you are adding the event handler on the actual Div, not on any virtual DOM element.
I had actually already tried that but I looked closely and still no luck after first Drop.
I also tried the method calls removeLinkData() addLinkDataCollection() commitTransaction() calls inside the commit() method but it’s always the same behaviour.
Executing a transaction within a transaction is OK, just wasteful, so I would remove that call to commit and just call set directly. But this suggestion does not change any behavior.
I’m sorry I cannot help more without more knowledge about the situation.
Maybe you could experiment with an HTML button that calls this code, so that you can make sure this code works correctly. Afterwards you can concentrate on getting the drag-and-drop to work.
I’m working on a freshly created create-react-app app and a bare-bone ReactDiagram & ReactPalette configuration.
I have a question: for ReactDiagram & ReactPalette to work as you’d expect, does the app state MUST be updated through the onModelChange callback?
I want to feed the initial nodeDataArray from a static object in a .ts file and keep the components stateless because I want to remove everything that is NOT required for GoJs to work as it’s expected.
I put together this public repo and info steps in its README to share with you so you can see the issue which I am still seeing even when I take your suggested code base and add my mouse drop logic to it… the issue persists.
The problem is that your link has a very large strokeWidth and ends up covering the “prepend” node.
Your diagram starts with the node being on top of the link. When you drop the first node, the newly created link ends up on top of the node due to its large strokeWidth.
A simple solution is to put your links in the background layer.
WOW! it’d have taken me months to figure that out :-( thank you and happy holidays! hopefully I won’t be posting again until January… I’m off to vacations this Friday :-)