-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Reorder blocks via drag & drop (v1. using React-dnd). #4056
Closed
chriskmnds
wants to merge
12
commits into
WordPress:master
from
chriskmnds:add/drag-n-drop-for-blocks
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cca62d7
Drag & Drop for blocks: Added react-dnd dependencies.
chriskmnds 264d3cb
Drag & Drop: Added functionality for reindexing blocks.
chriskmnds b00ec8c
Drag & Drop for blocks: Added wrappers to the react-dnd higher order …
chriskmnds 2bfc54f
Drag & Drop for blocks: Updated constants to add draggable types.
chriskmnds 20f0c9d
Drag & Drop for blocks: Added a draggable component set for specifyin…
chriskmnds e629af0
Drag & Drop for blocks: Added state flag for keeping track of drag op…
chriskmnds 93bdd74
Drag & Drop for blocks: Added drag source and drop target components …
chriskmnds 6ea53a4
Drag & Drop for blocks: Added react-dnd-html5-mixed-backend dependenc…
chriskmnds 9cd6578
Drag & Drop for blocks: Some cleanup, reenabled drop zone with flag.
chriskmnds 866238a
Drag & Drop for blocks: Fixed block reordering issue with reduntant c…
chriskmnds de1b3fd
Drag & Drop for blocks: Updated block reindex reducer and added respe…
chriskmnds 6ee16a4
Drag & Drop for blocks: Fixed indendation errors.
chriskmnds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# withDragAndDrop | ||
|
||
// @todo :clk:doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { DragDropContext, DragSource, DropTarget } from 'react-dnd'; | ||
import MixedHTML5Backend from 'react-dnd-html5-mixed-backend'; | ||
// import HTML5Backend from 'react-dnd-html5-backend'; | ||
|
||
/** | ||
* A wrapper around react-dnd DragDropContext higher order component. | ||
* @param { Function } WrappedComponent Component to be wrapped with drag & drop context. | ||
* @return { Function } A component wrapped with the react-dnd HOC. | ||
*/ | ||
export default function withDragAndDropContext( WrappedComponent ) { | ||
return DragDropContext( MixedHTML5Backend )( WrappedComponent ); | ||
} | ||
|
||
/** | ||
* @todo :clk:doc | ||
* A wrapper around react-dnd DragSource higher order component. | ||
* @param {[type]} itemType [description] | ||
* @param {[type]} sourceSpec [description] | ||
* @param {[type]} sourceCollect [description] | ||
* @return {[type]} [description] | ||
*/ | ||
export function withDragSource( itemType, sourceSpec, sourceCollect ) { | ||
return ( WrappedComponent ) => { | ||
return DragSource( itemType, sourceSpec, sourceCollect )( WrappedComponent ); | ||
}; | ||
} | ||
|
||
/** | ||
* @todo :clk:doc | ||
* A wrapper around react-dnd DropTarget higher order component. | ||
* @param {[type]} itemType [description] | ||
* @param {[type]} targetSpec [description] | ||
* @param {[type]} targetCollect [description] | ||
* @return {[type]} [description] | ||
*/ | ||
export function withDropTarget( itemType, targetSpec, targetCollect ) { | ||
return ( WrappedComponent ) => { | ||
return DropTarget( itemType, targetSpec, targetCollect )( WrappedComponent ); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// @todo :clk:tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component, compose } from '@wordpress/element'; | ||
import { withDragSource } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import { startReordering, stopReordering } from '../../actions'; | ||
|
||
|
||
/** | ||
* @todo :clk:doc | ||
* Collector - properties to inject in the wrapped component | ||
* @param {[type]} connect [description] | ||
* @param {[type]} monitor [description] | ||
* @return {[type]} [description] | ||
*/ | ||
function sourceCollect( connect, monitor ) { | ||
return { | ||
connectDragSource: connect.dragSource(), | ||
isDragging: monitor.isDragging() | ||
}; | ||
} | ||
|
||
/** | ||
* @todo :clk:doc | ||
* [sourceSpec description] | ||
* @type {Object} | ||
*/ | ||
const sourceSpec = { | ||
beginDrag( props ) { | ||
props.startReordering(); | ||
|
||
return { | ||
dragSourceUid: props.dragSourceUid, | ||
index: props.index, | ||
}; | ||
}, | ||
|
||
// every drag is [guaranteed] to fire this endDrag callback | ||
endDrag( props ) { | ||
setTimeout( props.stopReordering, 500 ); | ||
// props.hideDropIndicator(); | ||
}, | ||
|
||
}; | ||
|
||
class DragSource extends Component { | ||
constructor( props ) { | ||
super( props ); | ||
} | ||
|
||
render() { | ||
const classes = classnames( 'draggable-drag-source'); | ||
|
||
return this.props.connectDragSource( | ||
<div className={ classes }> | ||
{ this.props.children } | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapDispatchToProps = ( dispatch ) => ( { | ||
startReordering() { | ||
dispatch( startReordering() ); | ||
}, | ||
|
||
stopReordering() { | ||
dispatch( stopReordering() ); | ||
}, | ||
|
||
} ); | ||
|
||
export default compose( | ||
connect( undefined, mapDispatchToProps ), | ||
withDragSource( props => props.draggableType, sourceSpec, sourceCollect ), | ||
)( DragSource ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the gist of it, part 2. A component that we can drop to.