Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
blockType: _blockType,
topLevelLockedBlock:
__unstableGetContentLockingParent( _selectedBlockClientId ) ||
( getTemplateLock( _selectedBlockClientId ) === 'contentOnly'
( getTemplateLock( _selectedBlockClientId ) === 'contentOnly' ||
_selectedBlockName === 'core/block'
? _selectedBlockClientId
: undefined ),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function useInBetweenInserter() {
getTemplateLock,
__unstableIsWithinBlockOverlay,
getBlockEditingMode,
getBlockName,
} = useSelect( blockEditorStore );
const { showInsertionPoint, hideInsertionPoint } =
useDispatch( blockEditorStore );
Expand Down Expand Up @@ -75,7 +76,8 @@ export function useInBetweenInserter() {

if (
getTemplateLock( rootClientId ) ||
getBlockEditingMode( rootClientId ) === 'disabled'
getBlockEditingMode( rootClientId ) === 'disabled' ||
getBlockName( rootClientId ) === 'core/block'
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/block-lock/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import useBlockDisplayInformation from '../use-block-display-information';
import { store as blockEditorStore } from '../../store';

// Entity based blocks which allow edit locking
const ALLOWS_EDIT_LOCKING = [ 'core/block', 'core/navigation' ];
const ALLOWS_EDIT_LOCKING = [ 'core/navigation' ];

function getTemplateLockValue( lock ) {
// Prevents all operations.
Expand Down
5 changes: 3 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2806,8 +2806,9 @@ export const __unstableGetContentLockingParent = createSelector(
while ( state.blocks.parents.has( current ) ) {
current = state.blocks.parents.get( current );
if (
current &&
getTemplateLock( state, current ) === 'contentOnly'
getBlockName( state, current ) === 'core/block' ||
( current &&
getTemplateLock( state, current ) === 'contentOnly' )
) {
result = current;
}
Expand Down
81 changes: 79 additions & 2 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {
useEntityBlockEditor,
useEntityProp,
useEntityRecord,
store as coreStore,
} from '@wordpress/core-data';
import {
Placeholder,
Spinner,
TextControl,
PanelBody,
ToolbarButton,
ToolbarGroup,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
Expand All @@ -27,8 +30,11 @@ import {
useBlockProps,
Warning,
privateApis as blockEditorPrivateApis,
BlockControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useRef, useMemo } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { useRef, useMemo, useState, useEffect } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -38,6 +44,30 @@ import { unlock } from '../lock-unlock';
const { useLayoutClasses } = unlock( blockEditorPrivateApis );
const fullAlignments = [ 'full', 'wide', 'left', 'right' ];

function isPartiallySynced( block ) {
return (
!! block.attributes.connections?.attributes &&
Object.values( block.attributes.connections.attributes ).some(
( connection ) => connection.source === 'pattern_attributes'
)
);
}

function setBlockEditMode( setEditMode, blocks, isEditingSourcePattern ) {
blocks.forEach( ( block ) => {
if ( isEditingSourcePattern ) {
setEditMode( block.clientId, 'default' );
setBlockEditMode( setEditMode, block.innerBlocks );
return;
}
const editMode = isPartiallySynced( block )
? 'contentOnly'
: 'disabled';
setEditMode( block.clientId, editMode );
setBlockEditMode( setEditMode, block.innerBlocks );
} );
}

const useInferredLayout = ( blocks, parentLayout ) => {
const initialInferredAlignmentRef = useRef();

Expand Down Expand Up @@ -71,7 +101,34 @@ export default function ReusableBlockEdit( {
name,
attributes: { ref },
__unstableParentLayout: parentLayout,
clientId: patternClientId,
} ) {
const [ isEditingSourcePattern, setIsEditingSourcePattern ] =
useState( false );
const { setBlockEditingMode } = useDispatch( blockEditorStore );
const { innerBlocks, userCanEdit } = useSelect(
( select ) => {
const { canUser } = select( coreStore );
const { getBlocks } = select( blockEditorStore );
const blocks = getBlocks( patternClientId );
const canEdit = canUser( 'update', 'blocks', ref );

return {
innerBlocks: blocks,
userCanEdit: canEdit,
};
},
[ patternClientId, ref ]
);

useEffect( () => {
setBlockEditMode(
setBlockEditingMode,
innerBlocks,
isEditingSourcePattern
);
}, [ innerBlocks, setBlockEditingMode, isEditingSourcePattern ] );

const hasAlreadyRendered = useHasRecursion( ref );
const { record, hasResolved } = useEntityRecord(
'postType',
Expand Down Expand Up @@ -100,7 +157,10 @@ export default function ReusableBlockEdit( {
className: classnames(
'block-library-block__reusable-block-container',
layout && layoutClasses,
{ [ `align${ alignment }` ]: alignment }
{
[ `align${ alignment }` ]: alignment,
'is-editing-source': isEditingSourcePattern,
}
),
} );

Expand Down Expand Up @@ -141,6 +201,23 @@ export default function ReusableBlockEdit( {

return (
<RecursionProvider uniqueId={ ref }>
{ userCanEdit && (
<BlockControls>
<ToolbarGroup>
<ToolbarButton
onClick={ () =>
setIsEditingSourcePattern(
! isEditingSourcePattern
)
}
>
{ isEditingSourcePattern
? __( 'Stop editing parent' )
: __( 'Edit parent pattern' ) }
</ToolbarButton>
</ToolbarGroup>
</BlockControls>
) }
<InspectorControls>
<PanelBody>
<TextControl
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/block/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
}
}
}

.block-library-block__reusable-block-container.is-editing-source {
box-shadow:
0 0 0 var(--wp-admin-border-width-focus)
var(--wp-block-synced-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { displayShortcut } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { useRef, useState, useEffect } from '@wordpress/element';
import { getQueryArgs, addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
Expand Down Expand Up @@ -144,6 +145,16 @@ function TemplateDocumentActions( { className, onBack } ) {
typeIcon = symbol;
}

const { refererId } = getQueryArgs( window.location.href );

if ( ! onBack && ! isNaN( refererId ) ) {
const url = addQueryArgs( 'post.php', {
action: 'edit',
post: refererId,
} );
onBack = () => ( document.location = url );
}

return (
<BaseDocumentActions
className={ classnames( className, {
Expand Down