Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Moving atomic blocks #551

Merged
merged 4 commits into from
Dec 30, 2016
Merged

Conversation

delijah
Copy link
Contributor

@delijah delijah commented Jul 21, 2016

To be able to drag and drop atomic blocks around within the editor, it is necessary to have a way to move them within the blockMap. To achieve this goal, this pull request adds the function moveAtomicBlock to AtomicBlockUtils.

This is a copy of #502 since i've mistakenly deleted the pull request branch of that one. Sorry.

delijah added 3 commits July 21, 2016 14:39
- Just use one function called moveAtomicBlock instead of three
- Introduce DraftInsertionType for determining if a fragment shall replace another fragment, or if it shall be inserted before or after another fragment

var blockMap = contentState.getBlockMap();
var blockBefore = blockMap.toSeq().takeUntil(v => v === targetBlock).last();
var blockAfter = blockMap.toSeq().skipUntil(v => v === targetBlock).skip(1).first();

Choose a reason for hiding this comment

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

const targetKey = targetBlock.getKey();
const blockBefore = contentState.getBlockBefore(targetKey);
const blockAfter = contentState.getBlockAfter(targetKey);

@delijah
Copy link
Contributor Author

delijah commented Aug 11, 2016

Hey, any updates on this?

invariant(
insertionMode !== 'replace',
'Replacing blocks is not supported.'
);

Choose a reason for hiding this comment

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

Why is it included in the enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replace is needed in AtomicBlockUtils but not here. Actually i could just implement replace here as well...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually i am not really sure if i should implement the support for "replace" here, since at the moment there is no use case for it.

Actual use case:

  • in "moveBlockInContentState" the insertionMode can be "before" or "after"
  • in "AtomicBlockUtils" the insertionMode can be "before", "after" or "replace"

So i see 3 solutions:

  1. implement "replace" in "moveBlockInContentState" even if there is no use case at the moment
  2. implement 2 different types for "insertionMode", one to use in "moveBlockInContentState" and one to use in "AtomicBlockUtils"
  3. we just leave it as it is at the moment

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest to just leave it as it is at the moment. It makes completely sense in my opinion.

Choose a reason for hiding this comment

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

That sounds fine.

@hellendag
Copy link

One question around the DraftInsertionType enum. Otherwise I think this is fine.

@rodrigopivi
Copy link

Is there any chance this will get merged soon? dragging atomic blocks seem an important feature

@jan4984
Copy link

jan4984 commented Nov 18, 2016

I'm interesting in the working drag and drop demo, or complete d&d support in draft-js. Moving a block can be easily done with the OrderedMap APIs.

@hellendag
Copy link

Sorry for the extremely long wait. Let's go ahead with this. :)

@hellendag hellendag merged commit b7fadff into facebookarchive:master Dec 30, 2016
erykpiast pushed a commit to prezly-forks/draft-js that referenced this pull request Mar 17, 2017
* Implemented moveAtomicBlockBefore and moveAtomicBlockAfter in AtomicBlockUtils

* Renamed EditorChangeType 'change-fragment' to 'move-block' and added to docs

* Changed interface for moving atomic blocks:

- Just use one function called moveAtomicBlock instead of three
- Introduce DraftInsertionType for determining if a fragment shall replace another fragment, or if it shall be inserted before or after another fragment

* Using ES6 variable declaration and getStart/EndKey instead of getAnchor/FocusKey
ouchxp pushed a commit to ouchxp/draft-js that referenced this pull request Apr 7, 2017
* Implemented moveAtomicBlockBefore and moveAtomicBlockAfter in AtomicBlockUtils

* Renamed EditorChangeType 'change-fragment' to 'move-block' and added to docs

* Changed interface for moving atomic blocks:

- Just use one function called moveAtomicBlock instead of three
- Introduce DraftInsertionType for determining if a fragment shall replace another fragment, or if it shall be inserted before or after another fragment

* Using ES6 variable declaration and getStart/EndKey instead of getAnchor/FocusKey
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants