-
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
Block editor: remove root appender #60697
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d544ad7
Block editor: remove root appender
ellatrix 506a5d0
Still show for empty editor
ellatrix 14eb9a3
Fix e2e tests
ellatrix 19b6769
Try appending on bottom padding click
ellatrix 1f8497f
Polish: select last block if empty default block
ellatrix a78fe15
Move to edit-post
ellatrix 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
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
66 changes: 66 additions & 0 deletions
66
packages/edit-post/src/components/visual-editor/use-padding-appender.js
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,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRegistry } from '@wordpress/data'; | ||
import { useRefEffect } from '@wordpress/compose'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; | ||
|
||
export function usePaddingAppender() { | ||
const registry = useRegistry(); | ||
return useRefEffect( | ||
( node ) => { | ||
function onMouseDown( event ) { | ||
if ( event.target !== node ) { | ||
return; | ||
} | ||
|
||
const { ownerDocument } = node; | ||
const { defaultView } = ownerDocument; | ||
|
||
const paddingBottom = defaultView.parseInt( | ||
defaultView.getComputedStyle( node ).paddingBottom, | ||
10 | ||
); | ||
|
||
if ( ! paddingBottom ) { | ||
return; | ||
} | ||
|
||
// only handle clicks under the last child | ||
const lastChild = node.lastElementChild; | ||
if ( ! lastChild ) { | ||
return; | ||
} | ||
|
||
const lastChildRect = lastChild.getBoundingClientRect(); | ||
if ( event.clientY < lastChildRect.bottom ) { | ||
return; | ||
} | ||
|
||
event.preventDefault(); | ||
|
||
const blockOrder = registry | ||
.select( blockEditorStore ) | ||
.getBlockOrder( '' ); | ||
const lastBlockClientId = blockOrder[ blockOrder.length - 1 ]; | ||
const lastBlock = registry | ||
.select( blockEditorStore ) | ||
.getBlock( lastBlockClientId ); | ||
const { selectBlock, insertDefaultBlock } = | ||
registry.dispatch( blockEditorStore ); | ||
|
||
if ( isUnmodifiedDefaultBlock( lastBlock ) ) { | ||
selectBlock( lastBlockClientId ); | ||
} else { | ||
insertDefaultBlock(); | ||
} | ||
} | ||
node.addEventListener( 'mousedown', onMouseDown ); | ||
return () => { | ||
node.removeEventListener( 'mousedown', onMouseDown ); | ||
}; | ||
}, | ||
[ registry ] | ||
); | ||
} |
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
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.
Should we move this one (and the padding bottom) to the "editor" package (VisualEditor component) instead? That way the same behavior would apply to pages (in non preview mode) in the site editor too.