Skip to content

Commit

Permalink
prep build 09/07
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Sep 7, 2024
2 parents a08e95a + 886c2b4 commit f1f2628
Show file tree
Hide file tree
Showing 31 changed files with 1,120 additions and 144 deletions.
22 changes: 0 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
{ ...blockInformation }
className={ blockInformation.isSynced && 'is-synced' }
/>
<BlockVariationTransforms blockClientId={ topLevelLockedBlock } />
<BlockInfo.Slot />
{ hasBlockStyles && (
<BlockStylesPanel clientId={ topLevelLockedBlock } />
Expand Down
21 changes: 21 additions & 0 deletions packages/block-editor/src/components/block-list/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,24 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
margin-bottom: auto;
}
}

.block-editor-block-list__zoom-out-separator {
/* same color as the iframe's background */
background: $gray-300;
// Additional -1px is required to avoid sub pixel rounding errors allowing background to show.
margin-left: -1px;
margin-right: -1px;
transition: background-color 0.3s ease;

&.is-dragged-over {
background: $gray-400;
}
}

// In Post Editor allow the separator to occupy the full width by ignoring (cancelling out) the global padding.
.has-global-padding > .block-editor-block-list__zoom-out-separator,
.block-editor-block-list__layout.is-root-container.has-global-padding > .block-editor-block-list__zoom-out-separator {
max-width: none;
// Additional -1px is required to avoid sub pixel rounding errors allowing background to show.
margin: 0 calc(-1 * var(--wp--style--root--padding-right) - 1px) 0 calc(-1 * var(--wp--style--root--padding-left) - 1px) !important;
}
97 changes: 59 additions & 38 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
DEFAULT_BLOCK_EDIT_CONTEXT,
} from '../block-edit/context';
import { useTypingObserver } from '../observe-typing';
import { ZoomOutSeparator } from './zoom-out-separator';
import { unlock } from '../../lock-unlock';

export const IntersectionObserver = createContext();
Expand Down Expand Up @@ -174,49 +175,55 @@ function Items( {
// function on every render.
const hasAppender = CustomAppender !== false;
const hasCustomAppender = !! CustomAppender;
const { order, selectedBlocks, visibleBlocks, shouldRenderAppender } =
useSelect(
( select ) => {
const {
getSettings,
getBlockOrder,
getSelectedBlockClientId,
getSelectedBlockClientIds,
__unstableGetVisibleBlocks,
getTemplateLock,
getBlockEditingMode,
__unstableGetEditorMode,
} = select( blockEditorStore );

const _order = getBlockOrder( rootClientId );
const {
order,
isZoomOut,
selectedBlocks,
visibleBlocks,
shouldRenderAppender,
} = useSelect(
( select ) => {
const {
getSettings,
getBlockOrder,
getSelectedBlockClientId,
getSelectedBlockClientIds,
__unstableGetVisibleBlocks,
getTemplateLock,
getBlockEditingMode,
__unstableGetEditorMode,
} = select( blockEditorStore );

if ( getSettings().__unstableIsPreviewMode ) {
return {
order: _order,
selectedBlocks: EMPTY_ARRAY,
visibleBlocks: EMPTY_SET,
};
}
const _order = getBlockOrder( rootClientId );

const selectedBlockClientId = getSelectedBlockClientId();
if ( getSettings().__unstableIsPreviewMode ) {
return {
order: _order,
selectedBlocks: getSelectedBlockClientIds(),
visibleBlocks: __unstableGetVisibleBlocks(),
shouldRenderAppender:
hasAppender &&
__unstableGetEditorMode() !== 'zoom-out' &&
( hasCustomAppender
? ! getTemplateLock( rootClientId ) &&
getBlockEditingMode( rootClientId ) !== 'disabled'
: rootClientId === selectedBlockClientId ||
( ! rootClientId &&
! selectedBlockClientId &&
! _order.length ) ),
selectedBlocks: EMPTY_ARRAY,
visibleBlocks: EMPTY_SET,
};
},
[ rootClientId, hasAppender, hasCustomAppender ]
);
}

const selectedBlockClientId = getSelectedBlockClientId();
return {
order: _order,
selectedBlocks: getSelectedBlockClientIds(),
visibleBlocks: __unstableGetVisibleBlocks(),
isZoomOut: __unstableGetEditorMode() === 'zoom-out',
shouldRenderAppender:
hasAppender &&
__unstableGetEditorMode() !== 'zoom-out' &&
( hasCustomAppender
? ! getTemplateLock( rootClientId ) &&
getBlockEditingMode( rootClientId ) !== 'disabled'
: rootClientId === selectedBlockClientId ||
( ! rootClientId &&
! selectedBlockClientId &&
! _order.length ) ),
};
},
[ rootClientId, hasAppender, hasCustomAppender ]
);

return (
<LayoutProvider value={ layout }>
Expand All @@ -230,10 +237,24 @@ function Items( {
! selectedBlocks.includes( clientId )
}
>
{ isZoomOut && (
<ZoomOutSeparator
clientId={ clientId }
rootClientId={ rootClientId }
position="top"
/>
) }
<BlockListBlock
rootClientId={ rootClientId }
clientId={ clientId }
/>
{ isZoomOut && (
<ZoomOutSeparator
clientId={ clientId }
rootClientId={ rootClientId }
position="bottom"
/>
) }
</AsyncModeProvider>
) ) }
{ order.length < 1 && placeholder }
Expand Down
110 changes: 110 additions & 0 deletions packages/block-editor/src/components/block-list/zoom-out-separator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import {
__unstableMotion as motion,
__unstableAnimatePresence as AnimatePresence,
} from '@wordpress/components';
import { useReducedMotion } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

export function ZoomOutSeparator( {
clientId,
rootClientId = '',
position = 'top',
} ) {
const [ isDraggedOver, setIsDraggedOver ] = useState( false );
const {
sectionRootClientId,
sectionClientIds,
blockInsertionPoint,
blockInsertionPointVisible,
} = useSelect( ( select ) => {
const {
getBlockInsertionPoint,
getBlockOrder,
isBlockInsertionPointVisible,
getSectionRootClientId,
} = unlock( select( blockEditorStore ) );

const root = getSectionRootClientId();
const sectionRootClientIds = getBlockOrder( root );
return {
sectionRootClientId: root,
sectionClientIds: sectionRootClientIds,
blockOrder: getBlockOrder( root ),
blockInsertionPoint: getBlockInsertionPoint(),
blockInsertionPointVisible: isBlockInsertionPointVisible(),
};
}, [] );

const isReducedMotion = useReducedMotion();

if ( ! clientId ) {
return;
}

let isVisible = false;

const isSectionBlock =
rootClientId === sectionRootClientId &&
sectionClientIds &&
sectionClientIds.includes( clientId );

if ( ! isSectionBlock ) {
return null;
}

if ( position === 'top' ) {
isVisible =
blockInsertionPointVisible &&
blockInsertionPoint.index === 0 &&
clientId === sectionClientIds[ blockInsertionPoint.index ];
}

if ( position === 'bottom' ) {
isVisible =
blockInsertionPointVisible &&
clientId === sectionClientIds[ blockInsertionPoint.index - 1 ];
}

return (
<AnimatePresence>
{ isVisible && (
<motion.div
as="button"
layout={ ! isReducedMotion }
initial={ { height: 0 } }
animate={ { height: '120px' } }
exit={ { height: 0 } }
transition={ {
type: 'tween',
duration: 0.2,
ease: [ 0.6, 0, 0.4, 1 ],
} }
className={ clsx(
'block-editor-block-list__zoom-out-separator',
{
'is-dragged-over': isDraggedOver,
}
) }
data-is-insertion-point="true"
onDragOver={ () => setIsDraggedOver( true ) }
onDragLeave={ () => setIsDraggedOver( false ) }
></motion.div>
) }
</AnimatePresence>
);
}
22 changes: 19 additions & 3 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const BlockIndicator = ( { icon, showTitle, blockTitle } ) => (

export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const {
hasContentOnlyLocking,
canRemove,
hasBlockStyles,
icon,
Expand All @@ -206,8 +207,12 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
isTemplate,
} = useSelect(
( select ) => {
const { getBlocksByClientId, getBlockAttributes, canRemoveBlocks } =
select( blockEditorStore );
const {
getTemplateLock,
getBlocksByClientId,
getBlockAttributes,
canRemoveBlocks,
} = select( blockEditorStore );
const { getBlockStyles, getBlockType, getActiveBlockVariation } =
select( blocksStore );
const _blocks = getBlocksByClientId( clientIds );
Expand All @@ -219,16 +224,22 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
const blockType = getBlockType( firstBlockName );

let _icon;
let _hasTemplateLock;
if ( _isSingleBlockSelected ) {
const match = getActiveBlockVariation(
firstBlockName,
getBlockAttributes( clientIds[ 0 ] )
);
// Take into account active block variations.
_icon = match?.icon || blockType.icon;
_hasTemplateLock =
getTemplateLock( clientIds[ 0 ] ) === 'contentOnly';
} else {
const isSelectionOfSameType =
new Set( _blocks.map( ( { name } ) => name ) ).size === 1;
_hasTemplateLock = clientIds.some(
( id ) => getTemplateLock( id ) === 'contentOnly'
);
// When selection consists of blocks of multiple types, display an
// appropriate icon to communicate the non-uniformity.
_icon = isSelectionOfSameType ? blockType.icon : copy;
Expand All @@ -244,6 +255,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
_isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ),
isTemplate:
_isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ),
hasContentOnlyLocking: _hasTemplateLock,
};
},
[ clientIds ]
Expand All @@ -252,6 +264,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
clientId: clientIds?.[ 0 ],
maximumLength: 35,
} );

if ( invalidBlocks ) {
return null;
}
Expand All @@ -261,7 +274,10 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => {
? blockTitle
: __( 'Multiple blocks selected' );

const hideDropdown = disabled || ( ! hasBlockStyles && ! canRemove );
const hideDropdown =
disabled ||
( ! hasBlockStyles && ! canRemove ) ||
hasContentOnlyLocking;

if ( hideDropdown ) {
return (
Expand Down
Loading

0 comments on commit f1f2628

Please sign in to comment.