diff --git a/blocks/library/heading/index.js b/blocks/library/heading/index.js
index 972638871d592..9fbca6f3c4bda 100644
--- a/blocks/library/heading/index.js
+++ b/blocks/library/heading/index.js
@@ -151,13 +151,17 @@ registerBlockType( 'core/heading', {
onFocus={ setFocus }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
- onSplit={ ( before, after, ...blocks ) => {
- setAttributes( { content: before } );
- insertBlocksAfter( [
- ...blocks,
- createBlock( 'core/paragraph', { content: after } ),
- ] );
- } }
+ onSplit={
+ insertBlocksAfter ?
+ ( before, after, ...blocks ) => {
+ setAttributes( { content: before } );
+ insertBlocksAfter( [
+ ...blocks,
+ createBlock( 'core/paragraph', { content: after } ),
+ ] );
+ } :
+ undefined
+ }
style={ { textAlign: align } }
placeholder={ placeholder || __( 'Write heading…' ) }
/>,
diff --git a/blocks/library/list/index.js b/blocks/library/list/index.js
index ead16de6ce29c..724a43cf6d29e 100644
--- a/blocks/library/list/index.js
+++ b/blocks/library/list/index.js
@@ -332,21 +332,25 @@ registerBlockType( 'core/list', {
wrapperClassName="blocks-list"
placeholder={ __( 'Write list…' ) }
onMerge={ mergeBlocks }
- onSplit={ ( before, after, ...blocks ) => {
- if ( ! blocks.length ) {
- blocks.push( createBlock( 'core/paragraph' ) );
- }
-
- if ( after.length ) {
- blocks.push( createBlock( 'core/list', {
- nodeName,
- values: after,
- } ) );
- }
-
- setAttributes( { values: before } );
- insertBlocksAfter( blocks );
- } }
+ onSplit={
+ insertBlocksAfter ?
+ ( before, after, ...blocks ) => {
+ if ( ! blocks.length ) {
+ blocks.push( createBlock( 'core/paragraph' ) );
+ }
+
+ if ( after.length ) {
+ blocks.push( createBlock( 'core/list', {
+ nodeName,
+ values: after,
+ } ) );
+ }
+
+ setAttributes( { values: before } );
+ insertBlocksAfter( blocks );
+ } :
+ undefined
+ }
/>,
];
}
diff --git a/blocks/library/paragraph/index.js b/blocks/library/paragraph/index.js
index 88fc473f0c6a8..983661ce52446 100644
--- a/blocks/library/paragraph/index.js
+++ b/blocks/library/paragraph/index.js
@@ -170,13 +170,16 @@ class ParagraphBlock extends Component {
} }
focus={ focus }
onFocus={ setFocus }
- onSplit={ ( before, after, ...blocks ) => {
- setAttributes( { content: before } );
- insertBlocksAfter( [
- ...blocks,
- createBlock( 'core/paragraph', { content: after } ),
- ] );
- } }
+ onSplit={ insertBlocksAfter ?
+ ( before, after, ...blocks ) => {
+ setAttributes( { content: before } );
+ insertBlocksAfter( [
+ ...blocks,
+ createBlock( 'core/paragraph', { content: after } ),
+ ] );
+ } :
+ undefined
+ }
onMerge={ mergeBlocks }
onReplace={ onReplace }
placeholder={ placeholder || __( 'Add text or type / to insert content' ) }
diff --git a/editor/components/block-drop-zone/index.js b/editor/components/block-drop-zone/index.js
index ef8da49f0e459..832ad2f5f7ed2 100644
--- a/editor/components/block-drop-zone/index.js
+++ b/editor/components/block-drop-zone/index.js
@@ -2,12 +2,12 @@
* External Dependencies
*/
import { connect } from 'react-redux';
-import { reduce, get, find } from 'lodash';
+import { reduce, get, find, flow } from 'lodash';
/**
* WordPress dependencies
*/
-import { DropZone } from '@wordpress/components';
+import { DropZone, withContext } from '@wordpress/components';
import { getBlockTypes } from '@wordpress/blocks';
/**
@@ -15,7 +15,11 @@ import { getBlockTypes } from '@wordpress/blocks';
*/
import { insertBlocks } from '../../actions';
-function BlockDropZone( { index, ...props } ) {
+function BlockDropZone( { index, isLocked, ...props } ) {
+ if ( isLocked ) {
+ return null;
+ }
+
const dropFiles = ( files, position ) => {
const transformation = reduce( getBlockTypes(), ( ret, blockType ) => {
if ( ret ) {
@@ -45,7 +49,16 @@ function BlockDropZone( { index, ...props } ) {
);
}
-export default connect(
- undefined,
- { insertBlocks }
+export default flow(
+ connect(
+ undefined,
+ { insertBlocks }
+ ),
+ withContext( 'editor' )( ( settings ) => {
+ const { templateLock } = settings;
+
+ return {
+ isLocked: !! templateLock,
+ };
+ } )
)( BlockDropZone );
diff --git a/editor/components/block-list/block.js b/editor/components/block-list/block.js
index bb0f7a9d74cb1..429a79440c563 100644
--- a/editor/components/block-list/block.js
+++ b/editor/components/block-list/block.js
@@ -11,7 +11,7 @@ import { get, partial, reduce, size } from 'lodash';
import { Component, compose, createElement } from '@wordpress/element';
import { keycodes } from '@wordpress/utils';
import { getBlockType, BlockEdit, getBlockDefaultClassname, createBlock, hasBlockSupport } from '@wordpress/blocks';
-import { withFilters } from '@wordpress/components';
+import { withFilters, withContext } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
/**
@@ -296,7 +296,7 @@ class BlockListBlock extends Component {
case ENTER:
// Insert default block after current block if enter and event
// not already handled by descendant.
- if ( target === this.node ) {
+ if ( target === this.node && ! this.props.isLocked ) {
event.preventDefault();
this.props.onInsertBlocks( [
@@ -318,12 +318,14 @@ class BlockListBlock extends Component {
case DELETE:
// Remove block on backspace.
if ( target === this.node ) {
+ const { uid, onRemove, previousBlock, onFocus, isLocked } = this.props;
event.preventDefault();
- const { uid, onRemove, previousBlock, onFocus } = this.props;
- onRemove( uid );
+ if ( ! isLocked ) {
+ onRemove( uid );
- if ( previousBlock ) {
- onFocus( previousBlock.uid, { offset: -1 } );
+ if ( previousBlock ) {
+ onFocus( previousBlock.uid, { offset: -1 } );
+ }
}
}
break;
@@ -340,7 +342,7 @@ class BlockListBlock extends Component {
}
render() {
- const { block, order, mode, showContextualToolbar } = this.props;
+ const { block, order, mode, showContextualToolbar, isLocked } = this.props;
const { name: blockName, isValid } = block;
const blockType = getBlockType( blockName );
// translators: %s: Type of block (i.e. Text, Image etc)
@@ -410,10 +412,10 @@ class BlockListBlock extends Component {
focus={ focus }
attributes={ block.attributes }
setAttributes={ this.setAttributes }
- insertBlocksAfter={ this.insertBlocksAfter }
- onReplace={ onReplace }
+ insertBlocksAfter={ isLocked ? undefined : this.insertBlocksAfter }
+ onReplace={ isLocked ? undefined : onReplace }
setFocus={ partial( onFocus, block.uid ) }
- mergeBlocks={ this.mergeBlocks }
+ mergeBlocks={ isLocked ? undefined : this.mergeBlocks }
className={ className }
id={ block.uid }
isSelectionEnabled={ this.props.isSelectionEnabled }
@@ -524,5 +526,12 @@ const mapDispatchToProps = ( dispatch, ownProps ) => ( {
export default compose(
withFilters( 'Editor.BlockItem' ),
- connect( mapStateToProps, mapDispatchToProps )
+ connect( mapStateToProps, mapDispatchToProps ),
+ withContext( 'editor' )( ( settings ) => {
+ const { templateLock } = settings;
+
+ return {
+ isLocked: !! templateLock,
+ };
+ } ),
)( BlockListBlock );
diff --git a/editor/components/block-mover/index.js b/editor/components/block-mover/index.js
index 0d3430f26b437..ad1d5b2650580 100644
--- a/editor/components/block-mover/index.js
+++ b/editor/components/block-mover/index.js
@@ -2,13 +2,13 @@
* External dependencies
*/
import { connect } from 'react-redux';
-import { first, last } from 'lodash';
+import { first, last, flow } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
-import { IconButton } from '@wordpress/components';
+import { IconButton, withContext } from '@wordpress/components';
import { getBlockType } from '@wordpress/blocks';
/**
@@ -19,7 +19,11 @@ import { getBlockMoverLabel } from './mover-label';
import { isFirstBlock, isLastBlock, getBlockIndex, getBlock } from '../../selectors';
import { selectBlock } from '../../actions';
-export function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast, uids, blockType, firstIndex } ) {
+export function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast, uids, blockType, firstIndex, isLocked } ) {
+ if ( isLocked ) {
+ return null;
+ }
+
// We emulate a disabled state because forcefully applying the `disabled`
// attribute on the button while it has focus causes the screen to change
// to an unfocused state (body as active element) without firing blur on,
@@ -60,37 +64,46 @@ export function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast, uids, block
);
}
-export default connect(
- ( state, ownProps ) => {
- const block = getBlock( state, first( ownProps.uids ) );
-
- return ( {
- isFirst: isFirstBlock( state, first( ownProps.uids ) ),
- isLast: isLastBlock( state, last( ownProps.uids ) ),
- firstIndex: getBlockIndex( state, first( ownProps.uids ) ),
- blockType: block ? getBlockType( block.name ) : null,
- } );
- },
- ( dispatch, ownProps ) => ( {
- onMoveDown() {
- if ( ownProps.uids.length === 1 ) {
- dispatch( selectBlock( first( ownProps.uids ) ) );
- }
+export default flow(
+ connect(
+ ( state, ownProps ) => {
+ const block = getBlock( state, first( ownProps.uids ) );
- dispatch( {
- type: 'MOVE_BLOCKS_DOWN',
- uids: ownProps.uids,
+ return ( {
+ isFirst: isFirstBlock( state, first( ownProps.uids ) ),
+ isLast: isLastBlock( state, last( ownProps.uids ) ),
+ firstIndex: getBlockIndex( state, first( ownProps.uids ) ),
+ blockType: block ? getBlockType( block.name ) : null,
} );
},
- onMoveUp() {
- if ( ownProps.uids.length === 1 ) {
- dispatch( selectBlock( first( ownProps.uids ) ) );
- }
+ ( dispatch, ownProps ) => ( {
+ onMoveDown() {
+ if ( ownProps.uids.length === 1 ) {
+ dispatch( selectBlock( first( ownProps.uids ) ) );
+ }
- dispatch( {
- type: 'MOVE_BLOCKS_UP',
- uids: ownProps.uids,
- } );
- },
- } )
+ dispatch( {
+ type: 'MOVE_BLOCKS_DOWN',
+ uids: ownProps.uids,
+ } );
+ },
+ onMoveUp() {
+ if ( ownProps.uids.length === 1 ) {
+ dispatch( selectBlock( first( ownProps.uids ) ) );
+ }
+
+ dispatch( {
+ type: 'MOVE_BLOCKS_UP',
+ uids: ownProps.uids,
+ } );
+ },
+ } )
+ ),
+ withContext( 'editor' )( ( settings ) => {
+ const { templateLock } = settings;
+
+ return {
+ isLocked: templateLock === 'all',
+ };
+ } ),
)( BlockMover );
diff --git a/editor/components/block-mover/test/index.js b/editor/components/block-mover/test/index.js
index 32d0c221624f3..f6f785b24b7e1 100644
--- a/editor/components/block-mover/test/index.js
+++ b/editor/components/block-mover/test/index.js
@@ -16,6 +16,11 @@ describe( 'BlockMover', () => {
title: 'yolo-block',
};
+ it( 'should not render if the editor is locked', () => {
+ const wrapper = shallow(