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

Zoomed Out Mode experiments #56806

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
name: Build Gutenberg Plugin Zip

on:
pull_request:
pull_request_target:
types: [opened]
push:
branches: [trunk]
workflow_dispatch:
inputs:
version:
description: 'rc or stable?'
required: true

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// The preview component measures the pixel width of this item, so as to calculate the scale factor.
// But without this baseline width, it collapses to 0.
width: 100%;
height: 100%;

overflow: hidden;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function BlockSettingsDropdown( {
const firstBlockClientId = blockClientIds[ 0 ];
const {
firstParentClientId,
isZoomOutMode,
onlyBlock,
parentBlockType,
previousBlockClientId,
Expand All @@ -109,6 +110,7 @@ export function BlockSettingsDropdown( {
getPreviousBlockClientId,
getSelectedBlockClientIds,
getBlockAttributes,
__unstableGetEditorMode,
} = select( blockEditorStore );

const { getActiveBlockVariation } = select( blocksStore );
Expand All @@ -120,6 +122,7 @@ export function BlockSettingsDropdown( {

return {
firstParentClientId: _firstParentClientId,
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
onlyBlock: 1 === getBlockCount( _firstParentClientId ),
parentBlockType:
_firstParentClientId &&
Expand Down Expand Up @@ -291,7 +294,8 @@ export function BlockSettingsDropdown( {
'core/block-editor/insert-after',
event
) &&
canInsertDefaultBlock
canInsertDefaultBlock &&
! isZoomOutMode
) {
event.preventDefault();
setOpenedBlockSettingsMenu( undefined );
Expand All @@ -301,7 +305,8 @@ export function BlockSettingsDropdown( {
'core/block-editor/insert-before',
event
) &&
canInsertDefaultBlock
canInsertDefaultBlock &&
! isZoomOutMode
) {
event.preventDefault();
setOpenedBlockSettingsMenu( undefined );
Expand Down Expand Up @@ -347,7 +352,7 @@ export function BlockSettingsDropdown( {
{ __( 'Duplicate' ) }
</MenuItem>
) }
{ canInsertDefaultBlock && (
{ canInsertDefaultBlock && ! isZoomOutMode && (
<>
<MenuItem
onClick={ pipe(
Expand Down Expand Up @@ -382,25 +387,31 @@ export function BlockSettingsDropdown( {
</MenuItem>
</MenuGroup>
) }
<BlockSettingsMenuControls.Slot
fillProps={ {
onClose,
canMove,
onMoveTo,
onlyBlock,
count,
firstBlockClientId,
} }
clientIds={ clientIds }
__unstableDisplayLocation={
__unstableDisplayLocation
}
/>
{ typeof children === 'function'
? children( { onClose } )
: Children.map( ( child ) =>
cloneElement( child, { onClose } )
) }
{ ! isZoomOutMode && (
<>
<BlockSettingsMenuControls.Slot
fillProps={ {
onClose,
canMove,
onMoveTo,
onlyBlock,
count,
firstBlockClientId,
} }
clientIds={ clientIds }
__unstableDisplayLocation={
__unstableDisplayLocation
}
/>
{ typeof children === 'function'
? children( { onClose } )
: Children.map( ( child ) =>
cloneElement( child, {
onClose,
} )
) }
</>
) }
{ canRemove && (
<MenuGroup>
<MenuItem
Expand Down
18 changes: 13 additions & 5 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
canRemove,
hasBlockStyles,
icon,
isZoomOutMode,
patterns,
} = useSelect(
( select ) => {
Expand All @@ -48,6 +49,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
canRemoveBlocks,
} = select( blockEditorStore );
const { getBlockStyles, getBlockType } = select( blocksStore );
const { __unstableGetEditorMode } = select( blockEditorStore );
const rootClientId = getBlockRootClientId(
Array.isArray( clientIds ) ? clientIds[ 0 ] : clientIds
);
Expand Down Expand Up @@ -75,6 +77,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
canRemove: canRemoveBlocks( clientIds, rootClientId ),
hasBlockStyles: !! styles?.length,
icon: _icon,
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
patterns: __experimentalGetPatternTransformItems(
blocks,
rootClientId
Expand All @@ -97,6 +100,8 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
const isSingleBlock = blocks.length === 1;
const isReusable = isSingleBlock && isReusableBlock( blocks[ 0 ] );
const isTemplate = isSingleBlock && isTemplatePart( blocks[ 0 ] );
const hasCustomName =
isSingleBlock && !! blocks[ 0 ].attributes.metadata?.name;

function selectForMultipleBlocks( insertedBlocks ) {
if ( insertedBlocks.length > 1 ) {
Expand Down Expand Up @@ -138,11 +143,12 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
const hasPossibleBlockVariationTransformations =
!! blockVariationTransformations?.length;
const hasPatternTransformation = !! patterns?.length && canRemove;
if (
const hasNoMenu =
! hasBlockStyles &&
! hasPossibleBlockTransformations &&
! hasPossibleBlockVariationTransformations
) {
! hasPossibleBlockVariationTransformations;

if ( hasNoMenu || isZoomOutMode ) {
return (
<ToolbarGroup>
<ToolbarButton
Expand All @@ -152,7 +158,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
icon={
<>
<BlockIcon icon={ icon } showColors />
{ ( isReusable || isTemplate ) && (
{ ( isReusable || isTemplate || hasCustomName ) && (
<span className="block-editor-block-switcher__toggle-text">
{ blockTitle }
</span>
Expand Down Expand Up @@ -205,7 +211,9 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
className="block-editor-block-switcher__toggle"
showColors
/>
{ ( isReusable || isTemplate ) && (
{ ( isReusable ||
isTemplate ||
hasCustomName ) && (
<span className="block-editor-block-switcher__toggle-text">
{ blockTitle }
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ export default function useBlockDisplayTitle( {
? getBlockLabel( blockType, attributes, context )
: null;

const blockCustomName = attributes.metadata?.name;
const label = reusableBlockTitle || blockLabel;
// Label will fallback to the title if no label is defined for the current
// label context. If the label is defined we prioritize it over a
// possible block variation title match.
const blockTitle =
label && label !== blockType.title ? label : blockInformation.title;
blockCustomName ||
( label && label !== blockType.title ? label : blockInformation.title );

if (
maximumLength &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ function BlockSelectionButton( { clientId, rootClientId } ) {
<BlockTitle
clientId={ clientId }
maximumLength={ 35 }
context="list-view"
/>
</Button>
</FlexItem>
Expand Down
5 changes: 0 additions & 5 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ export default function BlockTools( {
name="__unstable-block-tools-after"
ref={ blockToolbarAfterRef }
/>
{ isZoomOutMode && (
<ZoomOutModeInserters
__unstableContentRef={ __unstableContentRef }
/>
) }
</InsertionPointOpenRef.Provider>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function SelectedBlockTools( {
resize={ false }
{ ...popoverProps }
>
{ shouldShowContextualToolbar && (
{ shouldShowContextualToolbar ? (
<BlockContextualToolbar
// If the toolbar is being shown because of being forced
// it should focus the toolbar right after the mount.
Expand All @@ -112,12 +112,13 @@ export default function SelectedBlockTools( {
initialToolbarItemIndexRef.current = index;
} }
/>
) }
{ shouldShowBreadcrumb && (
<BlockSelectionButton
clientId={ clientId }
rootClientId={ rootClientId }
/>
) : (
shouldShowBreadcrumb && (
<BlockSelectionButton
clientId={ clientId }
rootClientId={ rootClientId }
/>
)
) }
</BlockPopover>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const defaultRenderToggle = ( {
blockTitle
);
} else if ( ! label && prioritizePatterns ) {
label = __( 'Add pattern' );
label = __( 'Add section' );
} else if ( ! label ) {
label = _x( 'Add block', 'Generic label for block inserter button' );
}
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ function InserterLibrary(
showMostUsedBlocks = false,
__experimentalInsertionIndex,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
__experimentalShouldZoomPatterns = false,
onSelect = noop,
shouldFocusBlock = false,
onSelectTab,
},
ref
) {
Expand All @@ -46,13 +49,20 @@ function InserterLibrary(
return (
<InserterMenu
onSelect={ onSelect }
onSelectTab={ onSelectTab }
rootClientId={ destinationRootClientId }
clientId={ clientId }
isAppender={ isAppender }
showInserterHelpPanel={ showInserterHelpPanel }
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalInsertionIndex={ __experimentalInsertionIndex }
__experimentalFilterValue={ __experimentalFilterValue }
__experimentalOnPatternCategorySelection={
__experimentalOnPatternCategorySelection
}
__experimentalShouldZoomPatterns={
__experimentalShouldZoomPatterns
}
shouldFocusBlock={ shouldFocusBlock }
prioritizePatterns={ prioritizePatterns }
ref={ ref }
Expand Down
16 changes: 14 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function InserterMenu(
__experimentalFilterValue = '',
shouldFocusBlock = true,
prioritizePatterns,
__experimentalOnPatternCategorySelection,
__experimentalShouldZoomPatterns = false,
onSelectTab,
},
ref
) {
Expand Down Expand Up @@ -123,8 +126,9 @@ function InserterMenu(
( patternCategory, filter ) => {
setSelectedPatternCategory( patternCategory );
setPatternFilter( filter );
__experimentalOnPatternCategorySelection?.( patternCategory );
},
[ setSelectedPatternCategory ]
[ setSelectedPatternCategory, __experimentalOnPatternCategorySelection ]
);

const blocksTab = useMemo(
Expand Down Expand Up @@ -209,6 +213,8 @@ function InserterMenu(
focusSearch: () => {
searchRef.current.focus();
},
getSelectedPatternCategory: () => selectedPatternCategory,
selectPatternCategory: onClickPatternCategory,
} ) );

const showPatternPanel =
Expand All @@ -228,11 +234,17 @@ function InserterMenu(
if ( value !== 'patterns' ) {
setSelectedPatternCategory( null );
}

setSelectedTab( value );
onSelectTab?.( value );
};

const className = classnames( 'block-editor-inserter__menu', {
'has-inline-patterns': __experimentalShouldZoomPatterns,
} );

return (
<div className="block-editor-inserter__menu">
<div className={ className }>
<div
className={ classnames( 'block-editor-inserter__main-area', {
'show-as-tabs': showAsTabs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ function InserterSearchResults( {
} ) {
const debouncedSpeak = useDebounce( speak, 500 );

const { prioritizedBlocks } = useSelect(
const { prioritizedBlocks, isZoomOutMode } = useSelect(
( select ) => {
const blockListSettings =
select( blockEditorStore ).getBlockListSettings( rootClientId );
const editorMode =
select( blockEditorStore ).__unstableGetEditorMode();

return {
prioritizedBlocks:
blockListSettings?.prioritizedInserterBlocks || EMPTY_ARRAY,
isZoomOutMode: editorMode === 'zoom-out',
};
},
[ rootClientId ]
Expand Down Expand Up @@ -199,6 +202,14 @@ function InserterSearchResults( {
</InserterPanel>
);

if ( isZoomOutMode ) {
return (
<InserterListbox>
{ patternsUI || <InserterNoResults /> }
</InserterListbox>
);
}

return (
<InserterListbox>
{ ! showBlockDirectory && ! hasItems && <InserterNoResults /> }
Expand Down