Skip to content

Commit

Permalink
Update templateLock value from noContent to contentOnly (#44131)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored Sep 14, 2022
1 parent c32c738 commit 05aa913
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/block-api/block-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ add_action( 'init', 'myplugin_register_template' );

_Options:_

- `noContent` — prevents all operations. Additionally, the block types that don't have content are hidden from the list view and can't gain focus within the block list. Unlike the other lock types, this is not overrideable by children.
- `contentOnly` — prevents all operations. Additionally, the block types that don't have content are hidden from the list view and can't gain focus within the block list. Unlike the other lock types, this is not overrideable by children.
- `all` — prevents all operations. It is not possible to insert new blocks, move existing blocks, or delete blocks.
- `insert` — prevents inserting or removing blocks, but allows moving existing blocks.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
selectedBlockName: _selectedBlockName,
blockType: _blockType,
topLevelLockedBlock:
getTemplateLock( _selectedBlockClientId ) === 'noContent'
getTemplateLock( _selectedBlockClientId ) === 'contentOnly'
? _selectedBlockClientId
: __unstableGetContentLockingParent(
_selectedBlockClientId
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function BlockListBlock( {
),
hasContentLockedParent: _hasContentLockedParent,
isContentLocking:
getTemplateLock( clientId ) === 'noContent' &&
getTemplateLock( clientId ) === 'contentOnly' &&
! _hasContentLockedParent,
isTemporarilyEditingAsBlocks:
__unstableGetTemporarilyEditingAsBlocks() === clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function useBlockLock( clientId ) {
canMove,
canRemove,
canLock: canLockBlockType( getBlockName( clientId ) ),
isContentLocked: getTemplateLock( clientId ) === 'noContent',
isContentLocked: getTemplateLock( clientId ) === 'contentOnly',
isLocked: ! canEdit || ! canMove || ! canRemove,
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/inner-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ Template locking of `InnerBlocks` is similar to [Custom Post Type templates lock
Template locking allows locking the `InnerBlocks` area for the current template.
_Options:_

- `noContent` — prevents all operations. Additionally, the block types that don't have content are hidden from the list view and can't gain focus within the block list. Unlike the other lock types, this is not overrideable by children.
- `contentOnly` — prevents all operations. Additionally, the block types that don't have content are hidden from the list view and can't gain focus within the block list. Unlike the other lock types, this is not overrideable by children.
- `'all'` — prevents all operations. It is not possible to insert new blocks. Move existing blocks or delete them.
- `'insert'` — prevents inserting or removing blocks, but allows moving existing ones.
- `false` — prevents locking from being applied to an `InnerBlocks` area even if a parent block contains locking. ( Boolean )

If locking is not set in an `InnerBlocks` area: the locking of the parent `InnerBlocks` area is used. Note that `noContent` can't be overriden: it's present, the `templateLock` value of any children is ignored.
If locking is not set in an `InnerBlocks` area: the locking of the parent `InnerBlocks` area is used. Note that `contentOnly` can't be overriden: it's present, the `templateLock` value of any children is ignored.

If the block is a top level block: the locking of the Custom Post Type is used.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { store as blockEditorStore } from '../../store';
* This hook makes sure that a block's inner blocks stay in sync with the given
* block "template". The template is a block hierarchy to which inner blocks must
* conform. If the blocks get "out of sync" with the template and the template
* is meant to be locked (e.g. templateLock = "all" or templateLock = "noContent"),
* is meant to be locked (e.g. templateLock = "all" or templateLock = "contentOnly"),
* then we replace the inner blocks with the correct value after synchronizing it with the template.
*
* @param {string} clientId The block client ID.
Expand Down Expand Up @@ -52,11 +52,11 @@ export default function useInnerBlockTemplateSync(
const existingTemplate = useRef( null );
useLayoutEffect( () => {
// Only synchronize innerBlocks with template if innerBlocks are empty
// or a locking "all" or "noContent" exists directly on the block.
// or a locking "all" or "contentOnly" exists directly on the block.
if (
innerBlocks.length === 0 ||
templateLock === 'all' ||
templateLock === 'noContent'
templateLock === 'contentOnly'
) {
const hasTemplateChanged = ! isEqual(
template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function useNestedSettingsUpdate(
const newSettings = {
allowedBlocks: _allowedBlocks,
templateLock:
templateLock === undefined || parentLock === 'noContent'
templateLock === undefined || parentLock === 'contentOnly'
? parentLock
: templateLock,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function ListViewBranch( props ) {
return !! (
parentId &&
select( blockEditorStore ).getTemplateLock( parentId ) ===
'noContent'
'contentOnly'
);
},
[ parentId ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function useBlockDropZone( {
} = select( blockEditorStore );
const templateLock = getTemplateLock( targetRootClientId );
return (
[ 'all', 'noContent' ].some(
[ 'all', 'contentOnly' ].some(
( lock ) => lock === templateLock
) ||
__unstableHasActiveBlockOverlayActive( targetRootClientId ) ||
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/hooks/content-lock-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const withBlockControls = createHigherOrderComponent(
__unstableSetTemporarilyEditingAsBlocks,
} = useDispatch( blockEditorStore );
const isContentLocked =
! isLockedByParent && templateLock === 'noContent';
! isLockedByParent && templateLock === 'contentOnly';
const {
__unstableMarkNextChangeAsNotPersistent,
updateBlockAttributes,
Expand All @@ -81,11 +81,11 @@ export const withBlockControls = createHigherOrderComponent(
const stopEditingAsBlock = useCallback( () => {
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes( props.clientId, {
templateLock: 'noContent',
templateLock: 'contentOnly',
} );
updateBlockListSettings( props.clientId, {
...getBlockListSettings( props.clientId ),
templateLock: 'noContent',
templateLock: 'contentOnly',
} );
updateSettings( { focusMode: focusModeToRevert.current } );
__unstableSetTemporarilyEditingAsBlocks();
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ export const __unstableGetContentLockingParent = createSelector(
let result;
while ( !! state.blocks.parents[ current ] ) {
current = state.blocks.parents[ current ];
if ( getTemplateLock( state, current ) === 'noContent' ) {
if ( getTemplateLock( state, current ) === 'contentOnly' ) {
result = current;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "noContent", false ]
"enum": [ "all", "insert", "contentOnly", false ]
}
},
"supports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "noContent", false ]
"enum": [ "all", "insert", "contentOnly", false ]
}
},
"usesContext": [ "postId", "postType" ],
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "noContent", false ]
"enum": [ "all", "insert", "contentOnly", false ]
},
"layout": {
"type": "object",
Expand Down

0 comments on commit 05aa913

Please sign in to comment.