-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix enter and copy past behaviour not respects allowedBlocks and child blocks restrictions #7230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import { get, reduce, size, castArray, first, last, noop } from 'lodash'; | ||
import { get, reduce, size, castArray, filter, first, last, noop } from 'lodash'; | ||
import tinymce from 'tinymce'; | ||
|
||
/** | ||
|
@@ -60,6 +60,7 @@ export class BlockListBlock extends Component { | |
|
||
this.setBlockListRef = this.setBlockListRef.bind( this ); | ||
this.bindBlockNode = this.bindBlockNode.bind( this ); | ||
this.canInsertSibling = this.canInsertSibling.bind( this ); | ||
this.setAttributes = this.setAttributes.bind( this ); | ||
this.maybeHover = this.maybeHover.bind( this ); | ||
this.hideHoverEffects = this.hideHoverEffects.bind( this ); | ||
|
@@ -123,6 +124,11 @@ export class BlockListBlock extends Component { | |
} | ||
} | ||
|
||
canInsertSibling( blockName ) { | ||
const { canInsertBlockType, rootUID } = this.props; | ||
return canInsertBlockType( blockName, rootUID ); | ||
} | ||
|
||
setBlockListRef( node ) { | ||
// Disable reason: The root return element uses a component to manage | ||
// event nesting, but the parent block list layout needs the raw DOM | ||
|
@@ -562,6 +568,7 @@ export class BlockListBlock extends Component { | |
id={ uid } | ||
isSelectionEnabled={ this.props.isSelectionEnabled } | ||
toggleSelection={ this.props.toggleSelection } | ||
canInsertSibling={ this.canInsertSibling } | ||
/> | ||
) } | ||
{ isValid && mode === 'html' && ( | ||
|
@@ -607,6 +614,7 @@ export class BlockListBlock extends Component { | |
|
||
const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => { | ||
const { | ||
canInsertBlockType, | ||
isBlockSelected, | ||
getPreviousBlockUid, | ||
getNextBlockUid, | ||
|
@@ -651,6 +659,7 @@ const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => { | |
block, | ||
isSelected, | ||
hasFixedToolbar, | ||
canInsertBlockType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm passing here the selector, because we need to use it, with parameters that we don't know yet here. I think this has no implications because the reference should always be the same but it is something we should keep an eye on. I'm also open to suggestions to avoid passing the selector directly. |
||
}; | ||
} ); | ||
|
||
|
@@ -674,7 +683,8 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { | |
selectBlock( uid, initialPosition ); | ||
}, | ||
onInsertBlocks( blocks, index ) { | ||
const { rootUID, layout } = ownProps; | ||
const { canInsertBlockType, rootUID, layout } = ownProps; | ||
blocks = filter( blocks, ( { name } ) => canInsertBlockType( name, rootUID ) ); | ||
blocks = blocks.map( ( block ) => cloneBlock( block, { layout } ) ); | ||
insertBlocks( blocks, index, rootUID ); | ||
}, | ||
|
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.
Would there be any way to move this to
block-list
insideinsertBlocksAfter
to avoid having the block implementor care about this? I feel like this logic should be part of core, not the block.