Skip to content
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

Add: Content lock ability. #43037

Merged
merged 24 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4ef07e9
Add: Content lock ability.
jorgefilipecosta Jul 25, 2022
b378271
Update packages/block-editor/src/components/list-view/index.js
jorgefilipecosta Aug 12, 2022
550b414
ListViewBranch: rename back processedBlocks to filteredBlocks
oandregal Aug 16, 2022
a5067a5
ListViewBranch: refactor to make flattenBlockTree function a reducer
oandregal Aug 16, 2022
e3e84e3
ListViewBranch: filter the blocks that need rendering
oandregal Aug 16, 2022
79ca57c
ListViewBlock: no longer needs to know anything about content locking
oandregal Aug 16, 2022
2246004
Remove log
oandregal Aug 17, 2022
ffcadfc
Refactor: rename isTemporarlyEditingAsBlocks to isEditingAsBlocks
oandregal Aug 18, 2022
ecb2460
templateLock: remove logic from lock.content
oandregal Aug 19, 2022
4437647
templateLock:noContent should prevent drag&drop
oandregal Aug 19, 2022
48ae7f6
templateLock:noContent sync innerblocks template if blocks changed
oandregal Aug 19, 2022
337a4bf
templateLock:noContent update docs for InnerBlocks
oandregal Aug 19, 2022
0912b1f
templateLock: substitute lock.content by templateLock to get the lock…
oandregal Aug 19, 2022
ec65df3
templateLock: substitute lock.content by templateLock in ListView
oandregal Aug 19, 2022
03a5f31
templateLock: substitute lock.content by templateLock in Block toolbar
oandregal Aug 19, 2022
9e9d8df
templateLock: add noContent as a new state att in blocks that use it
oandregal Aug 22, 2022
e0ff4d5
Fix lint issues
oandregal Aug 23, 2022
3d3ecee
Enhacements
jorgefilipecosta Aug 23, 2022
de082f8
Remove inspector on content lock
jorgefilipecosta Aug 23, 2022
70047c4
Continued the iterations
jorgefilipecosta Aug 24, 2022
a1861ed
Fixed toolbar margin and modify button padding
jorgefilipecosta Aug 25, 2022
4b55b2c
Fix linting and tests
jorgefilipecosta Aug 25, 2022
7ff1b2e
Highlight all the block in spotlight mode. Switch to spotlight mode o…
jorgefilipecosta Aug 25, 2022
82aaa8f
applied feedback
jorgefilipecosta Aug 31, 2022
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
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import deprecated from '@wordpress/deprecated';
*/
import BlockIcon from '../block-icon';

function BlockCard( { title, icon, description, blockType } ) {
function BlockCard( { title, icon, description, blockType, backButton } ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this unused back button at #43806

if ( blockType ) {
deprecated( '`blockType` property in `BlockCard component`', {
since: '5.7',
Expand All @@ -18,7 +18,7 @@ function BlockCard( { title, icon, description, blockType } ) {
}
return (
<div className="block-editor-block-card">
<BlockIcon icon={ icon } showColors />
{ backButton ? backButton : <BlockIcon icon={ icon } showColors /> }
<div className="block-editor-block-card__content">
<h2 className="block-editor-block-card__title">{ title }</h2>
<span className="block-editor-block-card__description">
Expand Down
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/block-edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export const Edit = ( props ) => {
const generatedClassName = hasBlockSupport( blockType, 'className', true )
? getBlockDefaultClassName( name )
: null;
const className = classnames( generatedClassName, attributes.className );
const className = classnames(
generatedClassName,
attributes.className,
props.className
);

return (
<Component { ...props } context={ context } className={ className } />
Expand Down
136 changes: 127 additions & 9 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import {
import {
PanelBody,
__experimentalUseSlot as useSlot,
FlexItem,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
Button,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useMemo, useCallback } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -29,19 +34,116 @@ import DefaultStylePicker from '../default-style-picker';
import BlockVariationTransforms from '../block-variation-transforms';
import useBlockDisplayInformation from '../use-block-display-information';
import { store as blockEditorStore } from '../../store';
import BlockIcon from '../block-icon';

function useContentBlocks( blockTypes, block ) {
const contenBlocksObjectAux = useMemo( () => {
return blockTypes.reduce( ( result, blockType ) => {
if (
Object.entries( blockType.attributes ).some(
( [ , { __experimentalRole } ] ) =>
__experimentalRole === 'content'
)
) {
result[ blockType.name ] = true;
}
return result;
}, {} );
}, [ blockTypes ] );
const isContentBlock = useCallback(
( blockName ) => {
return !! contenBlocksObjectAux[ blockName ];
},
[ blockTypes ]
);
return useMemo( () => {
return getContentBlocks( [ block ], isContentBlock );
}, [ block, isContentBlock ] );
}

function getContentBlocks( blocks, isContentBlock ) {
const result = [];
for ( const block of blocks ) {
if ( isContentBlock( block.name ) ) {
result.push( block );
}
result.push( ...getContentBlocks( block.innerBlocks, isContentBlock ) );
}
return result;
}

function BlockNavigationButton( { blockTypes, block, selectedBlock } ) {
const { selectBlock } = useDispatch( blockEditorStore );
const blockType = blockTypes.find( ( { name } ) => name === block.name );
const isSelected =
selectedBlock && selectedBlock.clientId === block.clientId;
return (
<Button
isPressed={ isSelected }
onClick={ () => selectBlock( block.clientId ) }
>
<HStack justify="flex-start">
<BlockIcon icon={ blockType.icon } />
<FlexItem>{ blockType.title }</FlexItem>
</HStack>
</Button>
);
}

function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
const { blockTypes, block, selectedBlock } = useSelect(
( select ) => {
return {
blockTypes: select( blocksStore ).getBlockTypes(),
block: select( blockEditorStore ).getBlock(
topLevelLockedBlock
),
selectedBlock: select( blockEditorStore ).getSelectedBlock(),
};
},
[ topLevelLockedBlock ]
);
const blockInformation = useBlockDisplayInformation( topLevelLockedBlock );
const contentBlocks = useContentBlocks( blockTypes, block );
return (
<div className="block-editor-block-inspector">
<BlockCard { ...blockInformation } />
<BlockVariationTransforms blockClientId={ topLevelLockedBlock } />
<VStack
spacing={ 1 }
padding={ 4 }
className="block-editor-block-inspector__block-buttons-container"
>
<h2 className="block-editor-block-card__title">
{ __( 'Content' ) }
</h2>
{ contentBlocks.map( ( contentBlock ) => (
<BlockNavigationButton
selectedBlock={ selectedBlock }
key={ contentBlock.clientId }
block={ contentBlock }
blockTypes={ blockTypes }
/>
) ) }
</VStack>
</div>
);
}

const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
const {
count,
hasBlockStyles,
selectedBlockName,
selectedBlockClientId,
blockType,
topLevelLockedBlock,
} = useSelect( ( select ) => {
const {
getSelectedBlockClientId,
getSelectedBlockCount,
getBlockName,
__unstableGetContentLockingParent,
getTemplateLock,
} = select( blockEditorStore );
const { getBlockStyles } = select( blocksStore );

Expand All @@ -59,6 +161,12 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
selectedBlockName: _selectedBlockName,
blockType: _blockType,
hasBlockStyles: blockStyles && blockStyles.length > 0,
topLevelLockedBlock:
getTemplateLock( _selectedBlockClientId ) === 'noContent'
? _selectedBlockClientId
: __unstableGetContentLockingParent(
_selectedBlockClientId
),
};
}, [] );

Expand Down Expand Up @@ -109,24 +217,34 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
}
return null;
}
if ( topLevelLockedBlock ) {
return (
<BlockInspectorLockedBlocks
topLevelLockedBlock={ topLevelLockedBlock }
/>
);
}
return (
<BlockInspectorSingleBlock
clientId={ selectedBlockClientId }
blockName={ blockType.name }
hasBlockStyles={ hasBlockStyles }
/>
);
};

const BlockInspectorSingleBlock = ( {
clientId,
blockName,
hasBlockStyles,
} ) => {
const BlockInspectorSingleBlock = ( { clientId, blockName, backButton } ) => {
const hasBlockStyles = useSelect(
( select ) => {
const { getBlockStyles } = select( blocksStore );
const blockStyles = getBlockStyles( blockName );
return blockStyles && blockStyles.length > 0;
},
[ blockName ]
);
const blockInformation = useBlockDisplayInformation( clientId );
return (
<div className="block-editor-block-inspector">
<BlockCard { ...blockInformation } />
<BlockCard backButton={ backButton } { ...blockInformation } />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some small leftovers of previous iterations of this PR, such as the back button, that we ended up not using. #43806 removes them.

<BlockVariationTransforms blockClientId={ clientId } />
{ hasBlockStyles && (
<div>
Expand Down
14 changes: 14 additions & 0 deletions packages/block-editor/src/components/block-inspector/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@
padding: ($grid-unit-20 * 2) $grid-unit-20;
text-align: center;
}


.block-editor-block-inspector__block-buttons-container {
border-top: $border-width solid $gray-200;
padding: $grid-unit-20;
}

.block-editor-block-inspector__block-type-type {
font-weight: 500;
&.block-editor-block-inspector__block-type-type {
line-height: $button-size-small;
margin: 0 0 $grid-unit-05;
}
}
Loading