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

Dragging content from sidebar #10298

Closed
SofiaSousa opened this issue Oct 3, 2018 · 6 comments
Closed

Dragging content from sidebar #10298

SofiaSousa opened this issue Oct 3, 2018 · 6 comments
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks [Type] Enhancement A suggestion for improvement.
Milestone

Comments

@SofiaSousa
Copy link
Contributor

Since gutenberg editor already has the drag and drop feature for blocks inside the page, I think would be great to apply the same concept for the content of the blocks.

Here is an example for what we have in StoryPage (which is a prototype using standalone-gutenberg editor)

2018-10-03 09 59 14
(Try it here https://storypage.devz.no/pages/new?template=minerva)

I'm available to share our approach and hope we can have a produtive discuss. What are your thoughts about this?

@designsimply designsimply added [Type] Question Questions about the design or development of the editor. [Feature] Drag and Drop Drag and drop functionality when working with blocks labels Oct 3, 2018
@mtias
Copy link
Member

mtias commented Oct 3, 2018

Also related #1511

@mtias mtias added Future and removed [Type] Question Questions about the design or development of the editor. labels Oct 3, 2018
@chrisvanpatten
Copy link
Contributor

@SofiaSousa I can think of a few cases where I'd use this. Would be very interested to see how you accomplished this.

@perandre
Copy link

perandre commented Oct 4, 2018

I guess this is a question not about introducing it into core, but providing a cleaner way to accomplish a similar result. Currently, some messy overrides are needed to make it work.

@SofiaSousa
Copy link
Contributor Author

We've tried 2 different options for drag and drop from the sidebar scenario:

  1. Inserting a new block
  2. Updating an existing block

StoryPage is using Gutenberg@3.2.0 via gutenberg-js@1.2.1 (where we implemented the overrides). Many changes have been made in code so far, but the flow is the same.

First we've created the PostItemDraggable, which was inspired in BlockDraggable component, and added a list of those items to sidebar.

1. Inserting a new block

  • We used createdBlock to create the new block inside PostItemDraggable and passed it through a new blocks property in transferDataobject
  • Overrided onDrop in BlockDropZone and check if blocks come with dataTransfer before insertBlocks

2. Updating an existing block

  • Instead of creating a block, we only had to add attributes to transferDataobject
  • Overrided BlockListBlock to pass uid to BlockDropZone
  • Overrided onDrop in BlockDropZone and check if attributes come with dataTransfer before updateBlockAttributes

@mtias mtias added this to the Future: Phase 2 milestone Oct 12, 2018
@youknowriad youknowriad modified the milestone: Future Mar 25, 2019
@brentjett
Copy link

brentjett commented Apr 6, 2020

Has there been any movement on this? It appears BlockDropZone is no longer a component (looking at 7.8 codebase) and has been replaced by an experimental useBlockDropZone() hook. Its unclear if there's a way to listen for onDrop calls anywhere.

As an aside, the block-editor/src/components/block-drop-zone/README.md could use an update as it doesn't appear there's any support for the editor.BlockDropZone hook any longer.

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Aug 1, 2023
@t-hamano
Copy link
Contributor

We believe that the proposal in this issue can be achieved in the current Gutenberg API by using the following two components:

The video below shows how to drag and drop an element wrapped in a Draggable component into a DropZone component.

205f97af8a3a6bcce013710d6e4a1558.mp4

Specifically, the implementation should be as follows:

  • Inject some content into the sidebar via registerPlugin or similar.
  • Add the elements you want to make draggable to it, and wrap them in the Draggable component.
  • Create a custom block.
  • Add the DrozZone component into the Edit component.
  • When a file is dragged and dropped, perform some processing via the onDrop prop or similar.

I would like to close this issue, but please leave a comment if there is anything that can't be achieved with the current API.

@t-hamano t-hamano closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

9 participants