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

WIP (DO NOT MERGE): A bunch of ideas into one #65070

Closed
wants to merge 5 commits into from
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 @@ -16,6 +16,11 @@
}
}

#tabs-8-allPatterns,
#tabs-8-myPatterns {
display: none !important;
}

.block-editor-block-patterns-list__item {
height: 100%;
// This is derived from the top padding set on
Expand Down Expand Up @@ -57,6 +62,9 @@
@include reduce-motion("transition");
}

.block-editor-patterns__pattern-details {
display: none !important;
}
.block-editor-patterns__pattern-details:not(:empty) {
align-items: center;
margin-top: $grid-unit-10;
Expand Down
45 changes: 29 additions & 16 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,31 @@ function BlockSwitcherDropdownMenuContents( {
);
}

const BlockIndicator = ( { icon, showTitle, blockTitle } ) => (
<>
<BlockIcon
className="block-editor-block-switcher__toggle"
icon={ icon }
showColors
/>
{ showTitle && blockTitle && (
<span className="block-editor-block-switcher__toggle-text">
{ blockTitle }
</span>
) }
</>
);
const BlockIndicator = ( { icon, showTitle, blockTitle } ) => {
const mode = useSelect(
( select ) => select( blockEditorStore ).__unstableGetEditorMode(),
[]
);

if ( mode === 'zoom-out' ) {
return null;
}

return (
<>
<BlockIcon
className="block-editor-block-switcher__toggle"
icon={ icon }
showColors
/>
{ showTitle && blockTitle && (
<span className="block-editor-block-switcher__toggle-text">
{ blockTitle }
</span>
) }
</>
);
};

export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const {
Expand All @@ -204,9 +215,10 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
invalidBlocks,
isReusable,
isTemplate,
mode,
} = useSelect(
( select ) => {
const { getBlocksByClientId, getBlockAttributes, canRemoveBlocks } =
const { getBlocksByClientId, getBlockAttributes, canRemoveBlocks, __unstableGetEditorMode } =
select( blockEditorStore );
const { getBlockStyles, getBlockType, getActiveBlockVariation } =
select( blocksStore );
Expand Down Expand Up @@ -244,6 +256,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
_isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ),
isTemplate:
_isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ),
mode: __unstableGetEditorMode(),
};
},
[ clientIds ]
Expand All @@ -252,7 +265,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
clientId: clientIds?.[ 0 ],
maximumLength: 35,
} );
if ( invalidBlocks ) {
if ( invalidBlocks || mode === 'zoom-out' ) {
return null;
}

Expand Down
100 changes: 64 additions & 36 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useShowHoveredOrFocusedGestures } from './utils';
import { store as blockEditorStore } from '../../store';
import __unstableBlockNameContext from './block-name-context';
import NavigableToolbar from '../navigable-toolbar';
import Shuffle from './shuffle';
import { useHasBlockToolbar } from './use-has-block-toolbar';

/**
Expand Down Expand Up @@ -65,57 +66,65 @@ export function PrivateBlockToolbar( {
shouldShowVisualToolbar,
showParentSelector,
isUsingBindings,
canRemove,
mode,
patternCategory,
} = useSelect( ( select ) => {
const {
getBlockName,
getBlockMode,
getBlockParents,
getSelectedBlockClientIds,
isBlockValid,
getBlockRootClientId,
getBlockEditingMode,
getBlockAttributes,
canRemoveBlock,
__unstableGetEditorMode,
} = select( blockEditorStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
const parents = getBlockParents( selectedBlockClientId );
const firstParentClientId = parents[ parents.length - 1 ];
const parentBlockName = getBlockName( firstParentClientId );
const parentBlockType = getBlockType( parentBlockName );
const editingMode = getBlockEditingMode( selectedBlockClientId );
const _isDefaultEditingMode = editingMode === 'default';
const _blockName = getBlockName( selectedBlockClientId );
const isValid = selectedBlockClientIds.every( ( id ) =>
isBlockValid( id )
);
const isVisual = selectedBlockClientIds.every(
( id ) => getBlockMode( id ) === 'visual'
);
const _isUsingBindings = selectedBlockClientIds.every(
( clientId ) =>
!! getBlockAttributes( clientId )?.metadata?.bindings
);
const selectedBlockClientIds = getSelectedBlockClientIds() || [];
const selectedBlockClientId = selectedBlockClientIds[0];

if (!selectedBlockClientId) {
console.log('No block selected');
return {};
}

const blockName = getBlockName( selectedBlockClientId );
const blockType = getBlockType( blockName );
const blockAttributes = getBlockAttributes( selectedBlockClientId ) || {};
const metadata = blockAttributes.metadata || {};
const categories = Array.isArray(metadata.categories) ? metadata.categories : [];
const firstCategory = categories[0];

console.log('Selected Block ID:', selectedBlockClientId);
console.log('Block Attributes:', blockAttributes);
console.log('Metadata:', metadata);
console.log('Categories:', categories);
console.log('First Category:', firstCategory);

return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
isContentOnlyEditingMode: editingMode === 'contentOnly',
isDefaultEditingMode: _isDefaultEditingMode,
blockType: selectedBlockClientId && getBlockType( _blockName ),
shouldShowVisualToolbar: isValid && isVisual,
toolbarKey: `${ selectedBlockClientId }${ firstParentClientId }`,
showParentSelector:
parentBlockType &&
getBlockEditingMode( firstParentClientId ) === 'default' &&
hasBlockSupport(
parentBlockType,
'__experimentalParentSelector',
true
) &&
selectedBlockClientIds.length === 1 &&
_isDefaultEditingMode,
isUsingBindings: _isUsingBindings,
isContentOnlyEditingMode: getBlockEditingMode( selectedBlockClientId ) === 'contentOnly',
isDefaultEditingMode: getBlockEditingMode( selectedBlockClientId ) === 'default',
blockType,
toolbarKey: selectedBlockClientId,
shouldShowVisualToolbar: isBlockValid( selectedBlockClientId ),
showParentSelector: (getBlockParents( selectedBlockClientId ) || []).length > 0,
isUsingBindings: !!blockAttributes.__unstableBindings,
canRemove: canRemoveBlock( selectedBlockClientId ),
mode: __unstableGetEditorMode(),
patternCategory: firstCategory,
};
}, [] );

console.log('Rendering PrivateBlockToolbar');
console.log('shouldShowVisualToolbar:', shouldShowVisualToolbar);
// Debugging
console.log('Current mode:', mode);
console.log('Pattern Category:', patternCategory);

const toolbarWrapperRef = useRef( null );

// Handles highlighting the current block outline on hover or focus of the
Expand All @@ -139,13 +148,19 @@ export function PrivateBlockToolbar( {
// Shifts the toolbar to make room for the parent block selector.
const classes = clsx( 'block-editor-block-contextual-toolbar', {
'has-parent': showParentSelector,
'is-zoom-out': mode === 'zoom-out', // Add this line
} );

const innerClasses = clsx( 'block-editor-block-toolbar', {
'is-synced': isSynced,
'is-connected': isUsingBindings,
} );

console.log('Rendering PrivateBlockToolbar');
console.log('shouldShowVisualToolbar:', shouldShowVisualToolbar);
console.log('mode:', mode);
console.log('patternCategory:', patternCategory);

return (
<NavigableToolbar
focusEditorOnEscape
Expand All @@ -162,6 +177,7 @@ export function PrivateBlockToolbar( {
key={ toolbarKey }
>
<div ref={ toolbarWrapperRef } className={ innerClasses }>

{ ! isMultiToolbar &&
isLargeViewport &&
isDefaultEditingMode && <BlockParentSelector /> }
Expand All @@ -181,6 +197,14 @@ export function PrivateBlockToolbar( {
/>
{ isDefaultEditingMode && (
<>
{mode === 'zoom-out' && patternCategory && (
<span
className="block-editor-block-toolbar__pattern-category"
>
{patternCategory}
</span>
)}

{ ! isMultiToolbar && (
<BlockLockToolbar
clientId={ blockClientId }
Expand All @@ -195,10 +219,13 @@ export function PrivateBlockToolbar( {
</ToolbarGroup>
</div>
) }
{ mode === 'zoom-out' ? (
<Shuffle clientId={ blockClientId } />
) : null }
{ shouldShowVisualToolbar && isMultiToolbar && (
<BlockGroupToolbar />
) }
{ shouldShowVisualToolbar && (
{ shouldShowVisualToolbar && mode !== 'zoom-out' && (
<>
<BlockControls.Slot
group="parent"
Expand All @@ -224,6 +251,7 @@ export function PrivateBlockToolbar( {
</__unstableBlockNameContext.Provider>
</>
) }

<BlockEditVisuallyButton clientIds={ blockClientIds } />
{ isDefaultEditingMode && (
<BlockSettingsMenu clientIds={ blockClientIds } />
Expand Down
12 changes: 12 additions & 0 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
}
}

.is-zoom-out .block-editor-block-mover {

}

.block-editor-block-toolbar__pattern-category {
justify-content: center;
display: flex;
align-items: center;
height: auto;
padding-right: 8px;
text-transform: capitalize;
}
.block-editor-block-contextual-toolbar {
position: sticky;
top: 0;
Expand Down
9 changes: 2 additions & 7 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,10 @@ export default function BlockTools( {
/>
) }

{ showZoomOutToolbar && (
<ZoomOutPopover
__unstableContentRef={ __unstableContentRef }
clientId={ clientId }
/>
) }


{ /* Used for the inline rich text toolbar. Until this toolbar is combined into BlockToolbar, someone implementing their own BlockToolbar will also need to use this to see the image caption toolbar. */ }
{ ! isZoomOutMode && ! hasFixedToolbar && (
{ ! hasFixedToolbar && (
<Popover.Slot
name="block-toolbar"
ref={ blockToolbarRef }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@
}
}

.block-editor-block-contextual-toolbar.is-zoom-out .block-editor-block-toolbar__block-controls {
padding-left: 12px;
}

.block-editor-block-toolbar {
overflow: visible;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export function useShowBlockTools() {
showEmptyBlockSideInserter: _showEmptyBlockSideInserter,
showBreadcrumb:
! _showEmptyBlockSideInserter && maybeShowBreadcrumb,
showBlockToolbarPopover: _showBlockToolbarPopover,
showZoomOutToolbar: _showZoomOutToolbar,
showBlockToolbarPopover: true,
showZoomOutToolbar: true,
};
}, [] );
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import clsx from 'clsx';
import { useState } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { plus } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';
import { __, _x } from '@wordpress/i18n';

function ZoomOutModeInserterButton( { isVisible, onClick } ) {
const [
Expand All @@ -20,7 +20,6 @@ function ZoomOutModeInserterButton( { isVisible, onClick } ) {
return (
<Button
variant="primary"
icon={ plus }
size="compact"
className={ clsx(
'block-editor-button-pattern-inserter__button',
Expand All @@ -29,6 +28,7 @@ function ZoomOutModeInserterButton( { isVisible, onClick } ) {
'is-visible': isVisible || zoomOutModeInserterButtonHovered,
}
) }
icon={ plus }
onClick={ onClick }
onMouseOver={ () => {
setZoomOutModeInserterButtonHovered( true );
Expand All @@ -40,7 +40,8 @@ function ZoomOutModeInserterButton( { isVisible, onClick } ) {
'Add pattern',
'Generic label for pattern inserter button'
) }
/>
>
</Button>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ function ZoomOutModeInserters() {

const isSelected =
hasSelection &&
( selectedBlockClientId === previousClientId ||
selectedBlockClientId === nextClientId );

const isHovered =
hoveredBlockClientId === previousClientId ||
hoveredBlockClientId === nextClientId;
( selectedBlockClientId === previousClientId );

return (
<BlockPopoverInbetween
Expand All @@ -99,7 +94,7 @@ function ZoomOutModeInserters() {
) }
{ ! shouldRenderInsertionPoint && (
<ZoomOutModeInserterButton
isVisible={ isSelected || isHovered }
isVisible={ isSelected }
onClick={ () => {
setInserterIsOpened( {
rootClientId: sectionRootClientId,
Expand Down
Loading
Loading