Skip to content

Add Drag and Drop Functionality#28

Open
ctsstc wants to merge 8 commits into
lovasoa:mainfrom
ctsstc:drag-and-drop
Open

Add Drag and Drop Functionality#28
ctsstc wants to merge 8 commits into
lovasoa:mainfrom
ctsstc:drag-and-drop

Conversation

@ctsstc
Copy link
Copy Markdown
Contributor

@ctsstc ctsstc commented Jan 20, 2026

Overview

This adds drop and drop functionality to help order items as well as move them into or out of nested items like objects or lists.

Preview

drag.and.drop.json.schema.editor.mov

Hurdles

  • There were two write operations happening at the same time which made it so that the inner child node would duplicate.
    • This required some consolidation to get them into a single operation.

Notes

  • This clears up lint issues, runs the formatter, and runs the fix script.
    • I'm planning to get into a separate PR and get those merged into main so it helps clear up some of the noise here.
    • I'll likely have to handle some conflicts afterwards.
    • Opened Fix Check Errors #29 hopefully that can get merged soon and I can rebase this branch to clean it up some.
  • 🔥 This is still a WIP. I need to do a walk-through giving it a once-over (probably tomorrow [Tuesday]), but it seems to be functioning fine now.
    • Any feedback would be great though.
  • I'm glad it's working how I wanted it to finally, but I do wonder if there might have been a library that could have made this much more simple. Also given how heavy this change is, it feels like maybe some of it should be extracted out potentially?
  • I think this change may open up copying (it was already happening as a bug for a moment 😆 )

Resolutions

Still need to patch duplication that occurs when moving an item from a child to another location outside of its current container.
There were two write operations happening at the same time which made it so that the inner child node would duplicate. This had to do some consolidation to get them into a single operation.
This really ought to have happened before I started, but here we are. Maybe I can run it off of main on its own branch, but it'll surely be conflict city. Hopefully not too bad.
Not sure why this isn't picked up by the check. Ah, the check script must not cover this or do type checking. But there is a typecheck script.
@ctsstc
Copy link
Copy Markdown
Contributor Author

ctsstc commented Jan 22, 2026

Some research has me thinking maybe I should have went the direction of utilizing a library like:

@Maximax67
Copy link
Copy Markdown
Contributor

Hi @ctsstc, just wanted to ask if you're still working on this PR. The feature looks really useful.

@ctsstc
Copy link
Copy Markdown
Contributor Author

ctsstc commented Mar 3, 2026

I think this was at a point of working fine. I just never got back to this.
I had since worked on a project and had a similar drag and drop solution that I was going to reach for Jira's that I had found here:

But then I ran across this which was less heavy, more flexible, and integrated with more:

Part of me wonders about coming at this again and utilizing DNDKit

Need to at least get the conflicts resolved.

ctsstc and others added 2 commits March 3, 2026 19:02
Replace home-rolled HTML5 DnD with @atlaskit/pragmatic-drag-and-drop:
- Rewrite DragContext to simplified { draggingId, overId, overEdge } state
- SchemaPropertyEditor: useEffect registers draggable() + dropTargetForElements()
  via refs (propsRef pattern prevents re-registration during active drags);
  canDrop guards prevent self-drop and dropping onto descendants
- SchemaFieldList: single global monitorForElements drives all visual state
  (setDragging, setOver) via onDragStart/onDrag/onDrop — avoids false
  onDragLeave events from child elements; resolveTarget() skips ancestor
  containers so nested items stay nested during reorder
- ObjectEditor: remove all manual drag handlers and drag props
- tsconfig.test.json: add paths aliases so tsx (Node ESM) resolves
  Pragmatic DnD subpath exports to CJS dist files

Net: -233 lines. Cross-container drag and nested reorder both work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ctsstc
Copy link
Copy Markdown
Contributor Author

ctsstc commented Mar 4, 2026

I tried having Claude Code switch over to DNDKit, but it just didn't want to work out unfortunately; I had big hopes for it, but the nested DND just didn't want to work out well :( So I had it try porting over to Atlassian's Pragmatic DND which ended up working after a bit of guidance.

I've updated this PR to utilize the pragmatic variation -- it does reduce the lines from the html5 implementation, but honestly the HTML5 implementation was working just fine (and didn't require any dependencies - just some additional management was all).

Here are the 3 tries

@ctsstc ctsstc marked this pull request as ready for review March 4, 2026 03:17
@ctsstc
Copy link
Copy Markdown
Contributor Author

ctsstc commented Mar 4, 2026

Looks like one commit where I merged main back in brought some local shenanigans (pnpm, etc) that I can remove.

Both were incorrectly changed during the merge in 6307976.
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.

Feature Request: Allow re-ordering of fields

3 participants