Skip to content

Commit

Permalink
prep build 10/25
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Oct 25, 2024
2 parents 7443c33 + 6347583 commit 54dfb57
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 161 deletions.
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7643.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7643

* https://github.com/WordPress/gutenberg/pull/66432
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function gutenberg_register_packages_styles( $styles ) {
$styles,
'wp-edit-site',
gutenberg_url( 'build/edit-site/style.css' ),
array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-commands', 'wp-preferences' ),
array( 'wp-components', 'wp-block-editor', 'wp-editor', 'common', 'forms', 'wp-commands', 'wp-preferences' ),
$version
);
$styles->add_data( 'wp-edit-site', 'rtl', 'replace' );
Expand Down
133 changes: 133 additions & 0 deletions packages/block-editor/src/components/block-toolbar/change-design.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* WordPress dependencies
*/
import {
ToolbarButton,
ToolbarGroup,
Dropdown,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { cloneBlock } from '@wordpress/blocks';
import { useMemo } from '@wordpress/element';
import { useAsyncList } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import BlockPatternsList from '../block-patterns-list';

const EMPTY_ARRAY = [];
const MAX_PATTERNS_TO_SHOW = 6;
const POPOVER_PROPS = {
placement: 'bottom-start',
};

export default function ChangeDesign( { clientId } ) {
const { categories, currentPatternName, patterns } = useSelect(
( select ) => {
const {
getBlockAttributes,
getBlockRootClientId,
__experimentalGetAllowedPatterns,
} = select( blockEditorStore );
const attributes = getBlockAttributes( clientId );
const _categories = attributes?.metadata?.categories || EMPTY_ARRAY;
const rootBlock = getBlockRootClientId( clientId );

// Calling `__experimentalGetAllowedPatterns` is expensive.
// Checking if the block can be changed prevents unnecessary selector calls.
// See: https://github.com/WordPress/gutenberg/pull/64736.
const _patterns =
_categories.length > 0
? __experimentalGetAllowedPatterns( rootBlock )
: EMPTY_ARRAY;
return {
categories: _categories,
currentPatternName: attributes?.metadata?.patternName,
patterns: _patterns,
};
},
[ clientId ]
);
const { replaceBlocks } = useDispatch( blockEditorStore );
const sameCategoryPatternsWithSingleWrapper = useMemo( () => {
if ( categories.length === 0 || ! patterns || patterns.length === 0 ) {
return EMPTY_ARRAY;
}
return patterns
.filter( ( pattern ) => {
const isCorePattern =
pattern.source === 'core' ||
( pattern.source?.startsWith( 'pattern-directory' ) &&
pattern.source !== 'pattern-directory/theme' );
return (
// Check if the pattern has only one top level block,
// otherwise we may switch to a pattern that doesn't have replacement suggestions.
pattern.blocks.length === 1 &&
// We exclude the core patterns and pattern directory patterns that are not theme patterns.
! isCorePattern &&
// Exclude current pattern.
currentPatternName !== pattern.name &&
pattern.categories?.some( ( category ) => {
return categories.includes( category );
} ) &&
// Check if the pattern is not a synced pattern.
( pattern.syncStatus === 'unsynced' || ! pattern.id )
);
} )
.slice( 0, MAX_PATTERNS_TO_SHOW );
}, [ categories, currentPatternName, patterns ] );

const currentShownPatterns = useAsyncList(
sameCategoryPatternsWithSingleWrapper
);

if ( sameCategoryPatternsWithSingleWrapper.length < 2 ) {
return null;
}

const onClickPattern = ( pattern ) => {
const newBlocks = ( pattern.blocks ?? [] ).map( ( block ) => {
return cloneBlock( block );
} );
newBlocks[ 0 ].attributes.metadata = {
...newBlocks[ 0 ].attributes.metadata,
categories,
};
replaceBlocks( clientId, newBlocks );
};

return (
<Dropdown
popoverProps={ POPOVER_PROPS }
renderToggle={ ( { onToggle, isOpen } ) => {
return (
<ToolbarGroup>
<ToolbarButton
onClick={ () => onToggle( ! isOpen ) }
aria-expanded={ isOpen }
>
{ __( 'Change design' ) }
</ToolbarButton>
</ToolbarGroup>
);
} }
renderContent={ () => (
<DropdownContentWrapper
className="block-editor-block-toolbar-change-design-content-wrapper"
paddingSize="none"
>
<BlockPatternsList
shownPatterns={ currentShownPatterns }
blockPatterns={ sameCategoryPatternsWithSingleWrapper }
onClickPattern={ onClickPattern }
showTitle={ false }
/>
</DropdownContentWrapper>
) }
/>
);
}
11 changes: 3 additions & 8 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
isReusableBlock,
isTemplatePart,
} from '@wordpress/blocks';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { ToolbarGroup } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -35,7 +35,7 @@ import { store as blockEditorStore } from '../../store';
import __unstableBlockNameContext from './block-name-context';
import NavigableToolbar from '../navigable-toolbar';
import { useHasBlockToolbar } from './use-has-block-toolbar';
import Shuffle from './shuffle';
import ChangeDesign from './change-design';
import { unlock } from '../../lock-unlock';

/**
Expand Down Expand Up @@ -220,12 +220,7 @@ export function PrivateBlockToolbar( {
isMultiToolbar &&
showGroupButtons && <BlockGroupToolbar /> }
{ showShuffleButton && (
<ToolbarGroup>
<Shuffle
clientId={ blockClientIds[ 0 ] }
as={ ToolbarButton }
/>
</ToolbarGroup>
<ChangeDesign clientId={ blockClientIds[ 0 ] } />
) }
{ shouldShowVisualToolbar && showSlots && (
<>
Expand Down
111 changes: 0 additions & 111 deletions packages/block-editor/src/components/block-toolbar/shuffle.js

This file was deleted.

16 changes: 16 additions & 0 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,19 @@
}
}
}

.block-editor-block-toolbar-change-design-content-wrapper {
padding: $grid-unit-15;
width: 320px;
.block-editor-block-patterns-list {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: $grid-unit-15;
.block-editor-block-patterns-list__list-item {
margin-bottom: 0;
}
.block-editor-inserter__media-list__list-item {
min-height: 100px;
}
}
}
6 changes: 4 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDebouncedInput } from '@wordpress/compose';
import { useDebouncedInput, useViewportMatch } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';

/**
Expand Down Expand Up @@ -67,6 +67,8 @@ function InserterMenu(
const [ patternFilter, setPatternFilter ] = useState( 'all' );
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const isLargeViewport = useViewportMatch( 'large' );

function getInitialTab() {
if ( __experimentalInitialTab ) {
return __experimentalInitialTab;
Expand All @@ -80,7 +82,7 @@ function InserterMenu(

const shouldUseZoomOut =
selectedTab === 'patterns' || selectedTab === 'media';
useZoomOut( shouldUseZoomOut );
useZoomOut( shouldUseZoomOut && isLargeViewport );

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down
8 changes: 3 additions & 5 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useEffect } from '@wordpress/element';
*/
import { store as blockEditorStore } from '../store';
import { unlock } from '../lock-unlock';
import { useViewportMatch } from '@wordpress/compose';

/**
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
Expand All @@ -21,13 +20,12 @@ export function useZoomOut( zoomOut = true ) {
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );
const isWideViewport = useViewportMatch( 'large' );

useEffect( () => {
const isZoomOutOnMount = isZoomOut();

return () => {
if ( isZoomOutOnMount && isWideViewport ) {
if ( isZoomOutOnMount ) {
setZoomLevel( 'auto-scaled' );
} else {
resetZoomLevel();
Expand All @@ -36,10 +34,10 @@ export function useZoomOut( zoomOut = true ) {
}, [] );

useEffect( () => {
if ( zoomOut && isWideViewport ) {
if ( zoomOut ) {
setZoomLevel( 'auto-scaled' );
} else {
resetZoomLevel();
}
}, [ zoomOut, setZoomLevel, resetZoomLevel, isWideViewport ] );
}, [ zoomOut, setZoomLevel, resetZoomLevel ] );
}
Loading

0 comments on commit 54dfb57

Please sign in to comment.