Skip to content

Commit

Permalink
Zoom-out: Rely on zoom-level instead of zoom-out mode (WordPress#66141)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: jeryj <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: draganescu <[email protected]>
  • Loading branch information
7 people authored and karthick-murugan committed Nov 13, 2024
1 parent 21477d8 commit ab3d32f
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 201 deletions.
6 changes: 3 additions & 3 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ function Items( {
__unstableGetVisibleBlocks,
getTemplateLock,
getBlockEditingMode,
__unstableGetEditorMode,
isSectionBlock,
isZoomOut: _isZoomOut,
} = unlock( select( blockEditorStore ) );

const _order = getBlockOrder( rootClientId );
Expand All @@ -200,13 +200,13 @@ function Items( {
order: _order,
selectedBlocks: getSelectedBlockClientIds(),
visibleBlocks: __unstableGetVisibleBlocks(),
isZoomOut: __unstableGetEditorMode() === 'zoom-out',
isZoomOut: _isZoomOut(),
shouldRenderAppender:
! isSectionBlock( rootClientId ) &&
getBlockEditingMode( rootClientId ) !== 'disabled' &&
! getTemplateLock( rootClientId ) &&
hasAppender &&
__unstableGetEditorMode() !== 'zoom-out' &&
! _isZoomOut() &&
( hasCustomAppender ||
rootClientId === selectedBlockClientId ||
( ! rootClientId &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useSelect } from '@wordpress/data';
*/
import { isInsideRootBlock } from '../../../utils/dom';
import { store as blockEditorStore } from '../../../store';
import { unlock } from '../../../lock-unlock';

/** @typedef {import('@wordpress/element').RefObject} RefObject */

Expand All @@ -28,15 +29,16 @@ import { store as blockEditorStore } from '../../../store';
*/
export function useFocusFirstElement( { clientId, initialPosition } ) {
const ref = useRef();
const { isBlockSelected, isMultiSelecting, __unstableGetEditorMode } =
useSelect( blockEditorStore );
const { isBlockSelected, isMultiSelecting, isZoomOut } = unlock(
useSelect( blockEditorStore )
);

useEffect( () => {
// Check if the block is still selected at the time this effect runs.
if (
! isBlockSelected( clientId ) ||
isMultiSelecting() ||
__unstableGetEditorMode() === 'zoom-out'
isZoomOut()
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ import { unlock } from '../../../lock-unlock';
* @param {string} clientId Block client ID.
*/
export function useEventHandlers( { clientId, isSelected } ) {
const {
getBlockRootClientId,
getBlockIndex,
isZoomOut,
__unstableGetEditorMode,
} = unlock( useSelect( blockEditorStore ) );
const {
insertAfterBlock,
removeBlock,
__unstableSetEditorMode,
resetZoomLevel,
} = unlock( useDispatch( blockEditorStore ) );
const { getBlockRootClientId, getBlockIndex, isZoomOut } = unlock(
useSelect( blockEditorStore )
);
const { insertAfterBlock, removeBlock, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);

return useRefEffect(
( node ) => {
Expand Down Expand Up @@ -66,12 +60,7 @@ export function useEventHandlers( { clientId, isSelected } ) {

event.preventDefault();

if (
keyCode === ENTER &&
__unstableGetEditorMode() === 'zoom-out' &&
isZoomOut()
) {
__unstableSetEditorMode( 'edit' );
if ( keyCode === ENTER && isZoomOut() ) {
resetZoomLevel();
} else if ( keyCode === ENTER ) {
insertAfterBlock( clientId );
Expand Down Expand Up @@ -105,8 +94,6 @@ export function useEventHandlers( { clientId, isSelected } ) {
getBlockIndex,
insertAfterBlock,
removeBlock,
__unstableGetEditorMode,
__unstableSetEditorMode,
isZoomOut,
resetZoomLevel,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,13 @@ import { unlock } from '../../../lock-unlock';
* Allows Zoom Out mode to be exited by double clicking in the selected block.
*/
export function useZoomOutModeExit() {
const { getSettings, isZoomOut, __unstableGetEditorMode } = unlock(
useSelect( blockEditorStore )
);

const { __unstableSetEditorMode, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);
const { getSettings, isZoomOut } = unlock( useSelect( blockEditorStore ) );
const { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );

return useRefEffect(
( node ) => {
function onDoubleClick( event ) {
// In "compose" mode.
const composeMode =
__unstableGetEditorMode() === 'zoom-out' && isZoomOut();

if ( ! composeMode ) {
if ( ! isZoomOut() ) {
return;
}

Expand All @@ -43,7 +34,6 @@ export function useZoomOutModeExit() {
) {
__experimentalSetIsInserterOpened( false );
}
__unstableSetEditorMode( 'edit' );
resetZoomLevel();
}
}
Expand All @@ -54,12 +44,6 @@ export function useZoomOutModeExit() {
node.removeEventListener( 'dblclick', onDoubleClick );
};
},
[
getSettings,
__unstableSetEditorMode,
__unstableGetEditorMode,
isZoomOut,
resetZoomLevel,
]
[ getSettings, isZoomOut, resetZoomLevel ]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function useInBetweenInserter() {
const isInBetweenInserterDisabled = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().isDistractionFree ||
select( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',
unlock( select( blockEditorStore ) ).isZoomOut(),
[]
);
const {
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function PrivateBlockToolbar( {
getBlockParentsByBlockName,
getTemplateLock,
getParentSectionBlock,
isZoomOutMode,
isZoomOut,
} = unlock( select( blockEditorStore ) );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand Down Expand Up @@ -122,7 +122,7 @@ export function PrivateBlockToolbar( {
shouldShowVisualToolbar: isValid && isVisual,
toolbarKey: `${ selectedBlockClientId }${ parentClientId }`,
showParentSelector:
! isZoomOutMode() &&
! isZoomOut() &&
parentBlockType &&
getBlockEditingMode( parentClientId ) !== 'disabled' &&
hasBlockSupport(
Expand All @@ -134,7 +134,7 @@ export function PrivateBlockToolbar( {
isUsingBindings: _isUsingBindings,
hasParentPattern: _hasParentPattern,
hasContentOnlyLocking: _hasTemplateLock,
showShuffleButton: isZoomOutMode(),
showShuffleButton: isZoomOut(),
};
}, [] );

Expand Down
6 changes: 2 additions & 4 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@ function selector( select ) {
getSelectedBlockClientId,
getFirstMultiSelectedBlockClientId,
getSettings,
__unstableGetEditorMode,
isTyping,
isDragging,
isZoomOut,
} = unlock( select( blockEditorStore ) );

const clientId =
getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId();

const editorMode = __unstableGetEditorMode();

return {
clientId,
hasFixedToolbar: getSettings().hasFixedToolbar,
isTyping: isTyping(),
isZoomOutMode: editorMode === 'zoom-out',
isZoomOutMode: isZoomOut(),
isDragging: isDragging(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Inserter from '../inserter';
import { store as blockEditorStore } from '../../store';
import BlockPopoverInbetween from '../block-popover/inbetween';
import BlockDropZonePopover from '../block-popover/drop-zone';
import { unlock } from '../../lock-unlock';

export const InsertionPointOpenRef = createContext();

Expand Down Expand Up @@ -47,8 +48,8 @@ function InbetweenInsertionPointPopover( {
getPreviousBlockClientId,
getNextBlockClientId,
getSettings,
__unstableGetEditorMode,
} = select( blockEditorStore );
isZoomOut,
} = unlock( select( blockEditorStore ) );
const insertionPoint = getBlockInsertionPoint();
const order = getBlockOrder( insertionPoint.rootClientId );

Expand Down Expand Up @@ -78,7 +79,7 @@ function InbetweenInsertionPointPopover( {
rootClientId: insertionPoint.rootClientId,
isDistractionFree: settings.isDistractionFree,
isInserterShown: insertionPoint?.__unstableWithInserter,
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
isZoomOutMode: isZoomOut(),
};
}, [] );
const { getBlockEditingMode } = useSelect( blockEditorStore );
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
( select ) => {
const {
getBlockName,
__unstableGetEditorMode,
isZoomOut,
getTemplateLock,
getBlockRootClientId,
getBlockEditingMode,
Expand All @@ -216,7 +216,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) {

_isDropZoneDisabled = blockEditingMode === 'disabled';

if ( __unstableGetEditorMode() === 'zoom-out' ) {
if ( isZoomOut() ) {
// In zoom out mode, we want to disable the drop zone for the sections.
// The inner blocks belonging to the section drop zone is
// already disabled by the blocks themselves being disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
INSERTER_PATTERN_TYPES,
} from './utils';
import { store as blockEditorStore } from '../../../store';
import { unlock } from '../../../lock-unlock';

const noop = () => {};

Expand All @@ -45,8 +46,7 @@ export function PatternCategoryPreviews( {
showTitlesAsTooltip,
} ) {
const isZoomOutMode = useSelect(
( select ) =>
select( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',
( select ) => unlock( select( blockEditorStore ) ).isZoomOut(),
[]
);
const [ allPatterns, , onClickPattern ] = usePatternsState(
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import useInsertionPoint from './hooks/use-insertion-point';
import { store as blockEditorStore } from '../../store';
import TabbedSidebar from '../tabbed-sidebar';
import { useZoomOut } from '../../hooks/use-zoom-out';
import { unlock } from '../../lock-unlock';

const NOOP = () => {};
function InserterMenu(
Expand All @@ -54,8 +55,7 @@ function InserterMenu(
ref
) {
const isZoomOutMode = useSelect(
( select ) =>
select( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',
( select ) => unlock( select( blockEditorStore ) ).isZoomOut(),
[]
);
const [ filterValue, setFilterValue, delayedFilterValue ] =
Expand Down
11 changes: 5 additions & 6 deletions packages/block-editor/src/components/list-view/appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useBlockDisplayTitle from '../block-title/use-block-display-title';
import { useListViewContext } from './context';
import Inserter from '../inserter';
import AriaReferencedText from './aria-referenced-text';
import { unlock } from '../../lock-unlock';

export const Appender = forwardRef(
( { nestingLevel, blockCount, clientId, ...props }, ref ) => {
Expand All @@ -23,13 +24,11 @@ export const Appender = forwardRef(
const instanceId = useInstanceId( Appender );
const hideInserter = useSelect(
( select ) => {
const { getTemplateLock, __unstableGetEditorMode } =
select( blockEditorStore );

return (
!! getTemplateLock( clientId ) ||
__unstableGetEditorMode() === 'zoom-out'
const { getTemplateLock, isZoomOut } = unlock(
select( blockEditorStore )
);

return !! getTemplateLock( clientId ) || isZoomOut();
},
[ clientId ]
);
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/components/tool-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ToolSelector( props, ref ) {
( select ) => select( blockEditorStore ).__unstableGetEditorMode(),
[]
);
const { resetZoomLevel, __unstableSetEditorMode } = unlock(
const { __unstableSetEditorMode } = unlock(
useDispatch( blockEditorStore )
);

Expand Down Expand Up @@ -68,7 +68,6 @@ function ToolSelector( props, ref ) {
mode === 'navigation' ? 'navigation' : 'edit'
}
onSelect={ ( newMode ) => {
resetZoomLevel();
__unstableSetEditorMode( newMode );
} }
choices={ [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export default function useBlockDropZone( {
getAllowedBlocks,
isDragging,
isGroupable,
isZoomOutMode,
isZoomOut,
getSectionRootClientId,
} = unlock( useSelect( blockEditorStore ) );
const {
Expand Down Expand Up @@ -383,7 +383,7 @@ export default function useBlockDropZone( {
// do not allow dropping as the drop target is not within the root (that which is
// treated as "the content" by Zoom Out Mode).
if (
isZoomOutMode() &&
isZoomOut() &&
sectionRootClientId !== targetRootClientId
) {
return;
Expand Down Expand Up @@ -439,7 +439,7 @@ export default function useBlockDropZone( {
const [ targetIndex, operation, nearestSide ] =
dropTargetPosition;

if ( isZoomOutMode() && operation !== 'insert' ) {
if ( isZoomOut() && operation !== 'insert' ) {
return;
}

Expand Down Expand Up @@ -514,7 +514,7 @@ export default function useBlockDropZone( {
getDraggedBlockClientIds,
getBlockType,
getSectionRootClientId,
isZoomOutMode,
isZoomOut,
getBlocks,
getBlockListSettings,
dropZoneElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function useTabNav() {
getLastFocus,
getSectionRootClientId,
isZoomOut,
__unstableGetEditorMode,
} = unlock( useSelect( blockEditorStore ) );
const { setLastFocus } = unlock( useDispatch( blockEditorStore ) );

Expand All @@ -54,7 +53,7 @@ export default function useTabNav() {
}
}
// In "compose" mode without a selected ID, we want to place focus on the section root when tabbing to the canvas.
else if ( __unstableGetEditorMode() === 'zoom-out' && isZoomOut() ) {
else if ( isZoomOut() ) {
const sectionRootClientId = getSectionRootClientId();
const sectionBlocks = getBlockOrder( sectionRootClientId );

Expand Down
Loading

0 comments on commit ab3d32f

Please sign in to comment.