-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Experiment: Make unsynced patterns content only by default #71512
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
Changes from all commits
cb2b37c
e4b5aa9
fcb9d90
110543e
8b2215a
7ef7e40
a418ac2
06b32fc
361f633
5641787
f7ed41e
cbdced9
73b967f
53b33c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import { useBlockVariationTransforms } from './block-variation-transformations'; | |
| import BlockStylesMenu from './block-styles-menu'; | ||
| import PatternTransformationsMenu from './pattern-transformations-menu'; | ||
| import useBlockDisplayTitle from '../block-title/use-block-display-title'; | ||
| import { unlock } from '../../lock-unlock'; | ||
|
|
||
| function BlockSwitcherDropdownMenuContents( { | ||
| onClose, | ||
|
|
@@ -196,6 +197,7 @@ export const BlockSwitcher = ( { clientIds } ) => { | |
| isReusable, | ||
| isTemplate, | ||
| isDisabled, | ||
| isSection, | ||
| } = useSelect( | ||
| ( select ) => { | ||
| const { | ||
|
|
@@ -204,7 +206,8 @@ export const BlockSwitcher = ( { clientIds } ) => { | |
| getBlockAttributes, | ||
| canRemoveBlocks, | ||
| getBlockEditingMode, | ||
| } = select( blockEditorStore ); | ||
| isSectionBlock, | ||
| } = unlock( select( blockEditorStore ) ); | ||
| const { getBlockStyles, getBlockType, getActiveBlockVariation } = | ||
| select( blocksStore ); | ||
| const _blocks = getBlocksByClientId( clientIds ); | ||
|
|
@@ -250,6 +253,7 @@ export const BlockSwitcher = ( { clientIds } ) => { | |
| _isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ), | ||
| hasContentOnlyLocking: _hasTemplateLock, | ||
| isDisabled: editingMode !== 'default', | ||
| isSection: isSectionBlock( clientIds[ 0 ] ), | ||
|
Member
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. Do we need to check for multi-selection? Maybe it should use the same condition as the template and synced pattern.
Member
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.
Member
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. Trying to address this here:
Member
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. This condition - Current logic will return true if the first block in the multi-selection is a section block. Not sure if that's the result we want.
Member
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. Ah got it, thanks!
Member
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. I think #71708 should take care of this since it turns off block switching in a multi-selection if any block is a section. |
||
| }; | ||
| }, | ||
| [ clientIds ] | ||
|
|
@@ -278,7 +282,10 @@ export const BlockSwitcher = ( { clientIds } ) => { | |
| ? blockTitle | ||
| : undefined; | ||
|
|
||
| const hideTransformsForSections = | ||
| window?.__experimentalContentOnlyPatternInsertion && isSection; | ||
| const hideDropdown = | ||
| hideTransformsForSections || | ||
| isDisabled || | ||
| ( ! hasBlockStyles && ! canRemove ) || | ||
| hasContentOnlyLocking; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,32 +139,40 @@ function VariationsToggleGroupControl( { | |
|
|
||
| function __experimentalBlockVariationTransforms( { blockClientId } ) { | ||
| const { updateBlockAttributes } = useDispatch( blockEditorStore ); | ||
| const { activeBlockVariation, variations, isContentOnly } = useSelect( | ||
| ( select ) => { | ||
| const { getActiveBlockVariation, getBlockVariations } = | ||
| select( blocksStore ); | ||
|
|
||
| const { getBlockName, getBlockAttributes, getBlockEditingMode } = | ||
| select( blockEditorStore ); | ||
|
|
||
| const name = blockClientId && getBlockName( blockClientId ); | ||
|
|
||
| const { hasContentRoleAttribute } = unlock( select( blocksStore ) ); | ||
| const isContentBlock = hasContentRoleAttribute( name ); | ||
|
|
||
| return { | ||
| activeBlockVariation: getActiveBlockVariation( | ||
| name, | ||
| getBlockAttributes( blockClientId ) | ||
| ), | ||
| variations: name && getBlockVariations( name, 'transform' ), | ||
| isContentOnly: | ||
| getBlockEditingMode( blockClientId ) === 'contentOnly' && | ||
| ! isContentBlock, | ||
| }; | ||
| }, | ||
| [ blockClientId ] | ||
| ); | ||
| const { activeBlockVariation, variations, isContentOnly, isSection } = | ||
| useSelect( | ||
| ( select ) => { | ||
| const { getActiveBlockVariation, getBlockVariations } = | ||
| select( blocksStore ); | ||
|
|
||
| const { | ||
| getBlockName, | ||
| getBlockAttributes, | ||
| getBlockEditingMode, | ||
| isSectionBlock, | ||
| } = unlock( select( blockEditorStore ) ); | ||
|
|
||
| const name = blockClientId && getBlockName( blockClientId ); | ||
|
|
||
| const { hasContentRoleAttribute } = unlock( | ||
| select( blocksStore ) | ||
| ); | ||
| const isContentBlock = hasContentRoleAttribute( name ); | ||
|
|
||
| return { | ||
| activeBlockVariation: getActiveBlockVariation( | ||
| name, | ||
| getBlockAttributes( blockClientId ) | ||
| ), | ||
| variations: name && getBlockVariations( name, 'transform' ), | ||
| isContentOnly: | ||
| getBlockEditingMode( blockClientId ) === | ||
| 'contentOnly' && ! isContentBlock, | ||
| isSection: isSectionBlock( blockClientId ), | ||
| }; | ||
| }, | ||
| [ blockClientId ] | ||
| ); | ||
|
|
||
| const selectedValue = activeBlockVariation?.name; | ||
|
|
||
|
|
@@ -189,7 +197,10 @@ function __experimentalBlockVariationTransforms( { blockClientId } ) { | |
| } ); | ||
| }; | ||
|
|
||
| if ( ! variations?.length || isContentOnly ) { | ||
| const hideVariationsForSections = | ||
|
Contributor
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.
Contributor
Author
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. It hides the variations on the block card for groups. Only remembered this one is still there after doing it 😄 .
Contributor
Author
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. Pushed a commit that should address this. |
||
| window?.__experimentalContentOnlyPatternInsertion && isSection; | ||
|
|
||
| if ( ! variations?.length || isContentOnly || hideVariationsForSections ) { | ||
| return null; | ||
| } | ||
|
|
||
|
|
||



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.
This is working well now!
One thing that would also be good to fix is having theme patterns appear in the slash inserter; currently they don't. But that can be addressed separately!
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.
Yep, lets treat is as separate, I'm not sure if there's a reason they're omitted.
If we can include them I think it would help tidy up some of the Inserter code.