-
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
Add: Content lock ability. #43037
Merged
Merged
Add: Content lock ability. #43037
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 b378271
Update packages/block-editor/src/components/list-view/index.js
jorgefilipecosta 550b414
ListViewBranch: rename back processedBlocks to filteredBlocks
oandregal a5067a5
ListViewBranch: refactor to make flattenBlockTree function a reducer
oandregal e3e84e3
ListViewBranch: filter the blocks that need rendering
oandregal 79ca57c
ListViewBlock: no longer needs to know anything about content locking
oandregal 2246004
Remove log
oandregal ffcadfc
Refactor: rename isTemporarlyEditingAsBlocks to isEditingAsBlocks
oandregal ecb2460
templateLock: remove logic from lock.content
oandregal 4437647
templateLock:noContent should prevent drag&drop
oandregal 48ae7f6
templateLock:noContent sync innerblocks template if blocks changed
oandregal 337a4bf
templateLock:noContent update docs for InnerBlocks
oandregal 0912b1f
templateLock: substitute lock.content by templateLock to get the lock…
oandregal ec65df3
templateLock: substitute lock.content by templateLock in ListView
oandregal 03a5f31
templateLock: substitute lock.content by templateLock in Block toolbar
oandregal 9e9d8df
templateLock: add noContent as a new state att in blocks that use it
oandregal e0ff4d5
Fix lint issues
oandregal 3d3ecee
Enhacements
jorgefilipecosta de082f8
Remove inspector on content lock
jorgefilipecosta 70047c4
Continued the iterations
jorgefilipecosta a1861ed
Fixed toolbar margin and modify button padding
jorgefilipecosta 4b55b2c
Fix linting and tests
jorgefilipecosta 7ff1b2e
Highlight all the block in spotlight mode. Switch to spotlight mode o…
jorgefilipecosta 82aaa8f
applied feedback
jorgefilipecosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 ); | ||
|
||
|
@@ -59,6 +161,12 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { | |
selectedBlockName: _selectedBlockName, | ||
blockType: _blockType, | ||
hasBlockStyles: blockStyles && blockStyles.length > 0, | ||
topLevelLockedBlock: | ||
getTemplateLock( _selectedBlockClientId ) === 'noContent' | ||
? _selectedBlockClientId | ||
: __unstableGetContentLockingParent( | ||
_selectedBlockClientId | ||
), | ||
}; | ||
}, [] ); | ||
|
||
|
@@ -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 } /> | ||
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. 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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removing this unused back button at #43806