Skip to content

Commit

Permalink
Move allowRightClickOverrides to an editor setting instead of a stabl…
Browse files Browse the repository at this point in the history
…e prop on ListView
  • Loading branch information
andrewserong committed May 13, 2022
1 parent 78b0533 commit 8fd68db
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 38 deletions.
7 changes: 6 additions & 1 deletion packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import useBlockDisplayInformation from '../use-block-display-information';
import { useBlockLock } from '../block-lock';

function ListViewBlock( {
allowRightClickOverrides,
block,
isDragged,
isSelected,
Expand Down Expand Up @@ -73,6 +72,12 @@ function ListViewBlock( {
( select ) => select( blockEditorStore ).getBlockName( clientId ),
[ clientId ]
);
const { allowRightClickOverrides } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return {
allowRightClickOverrides: getSettings().allowRightClickOverrides,
};
} );

// When a block hides its toolbar it also hides the block settings menu,
// since that menu is part of the toolbar in the editor canvas.
Expand Down
4 changes: 0 additions & 4 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const countReducer = (

function ListViewBranch( props ) {
const {
allowRightClickOverrides,
blocks,
selectBlock,
showBlockMovers,
Expand Down Expand Up @@ -145,9 +144,6 @@ function ListViewBranch( props ) {
<AsyncModeProvider key={ clientId } value={ ! isSelected }>
{ showBlock && (
<ListViewBlock
allowRightClickOverrides={
allowRightClickOverrides
}
block={ block }
selectBlock={ selectBlock }
isSelected={ isSelected }
Expand Down
22 changes: 7 additions & 15 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,15 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
/**
* Show a hierarchical list of blocks.
*
* @param {Object} props Components props.
* @param {boolean} props.allowRightClickOverrides Flag to enable right click contextual menu.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {boolean} props.showBlockMovers Flag to enable block movers
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
* @param {Object} ref Forwarded ref
* @param {Object} props Components props.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {boolean} props.showBlockMovers Flag to enable block movers
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
* @param {Object} ref Forwarded ref
*/
function ListView(
{
allowRightClickOverrides,
id,
blocks,
showBlockMovers = false,
isExpanded = false,
},
{ id, blocks, showBlockMovers = false, isExpanded = false },
ref
) {
const {
Expand Down Expand Up @@ -198,7 +191,6 @@ function ListView(
>
<ListViewContext.Provider value={ contextValue }>
<ListViewBranch
allowRightClickOverrides={ allowRightClickOverrides }
blocks={ clientIdsTree }
selectBlock={ selectEditorBlock }
showBlockMovers={ showBlockMovers }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useInstanceId,
useMergeRefs,
} from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';
import { ESCAPE } from '@wordpress/keycodes';
Expand All @@ -25,9 +25,6 @@ export default function ListViewSidebar() {
const focusOnMountRef = useFocusOnMount( 'firstElement' );
const headerFocusReturnRef = useFocusReturn();
const contentFocusReturnRef = useFocusReturn();
const allowRightClickOverrides = useSelect( ( select ) =>
select( editPostStore ).isFeatureActive( 'allowRightClickOverrides' )
);

function closeOnEscape( event ) {
if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
Expand Down Expand Up @@ -64,9 +61,7 @@ export default function ListViewSidebar() {
focusOnMountRef,
] ) }
>
<ListView
allowRightClickOverrides={ allowRightClickOverrides }
/>
<ListView />
</div>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Editor( {
...props
} ) {
const {
allowRightClickOverrides,
hasFixedToolbar,
focusMode,
hasReducedUI,
Expand Down Expand Up @@ -80,6 +81,9 @@ function Editor( {
const isViewable = getPostType( postType )?.viewable ?? false;

return {
allowRightClickOverrides: isFeatureActive(
'allowRightClickOverrides'
),
hasFixedToolbar:
isFeatureActive( 'fixedToolbar' ) ||
__experimentalGetPreviewDeviceType() !== 'Desktop',
Expand Down Expand Up @@ -118,6 +122,7 @@ function Editor( {
hasFixedToolbar,
focusMode,
hasReducedUI,
allowRightClickOverrides,

// This is marked as experimental to give time for the quick inserter to mature.
__experimentalSetIsInserterOpened: setIsInserterOpened,
Expand Down Expand Up @@ -145,6 +150,7 @@ function Editor( {

return result;
}, [
allowRightClickOverrides,
settings,
hasFixedToolbar,
focusMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import {
useInstanceId,
useMergeRefs,
} from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';
import { ESCAPE } from '@wordpress/keycodes';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand All @@ -26,12 +25,6 @@ export default function ListViewSidebar() {
const focusOnMountRef = useFocusOnMount( 'firstElement' );
const headerFocusReturnRef = useFocusReturn();
const contentFocusReturnRef = useFocusReturn();
const allowRightClickOverrides = useSelect( ( select ) =>
select( preferencesStore ).get(
'core/edit-site',
'allowRightClickOverrides'
)
);

function closeOnEscape( event ) {
if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
Expand Down Expand Up @@ -67,9 +60,7 @@ export default function ListViewSidebar() {
focusOnMountRef,
] ) }
>
<ListView
allowRightClickOverrides={ allowRightClickOverrides }
/>
<ListView />
</div>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export const getSettings = createSelector(
state,
'showIconLabels'
),
allowRightClickOverrides: !! __unstableGetPreference(
state,
'allowRightClickOverrides'
),
__experimentalSetIsInserterOpened: setIsInserterOpen,
__experimentalReusableBlocks: getReusableBlocks( state ),
__experimentalPreferPatternsOnRoot:
Expand Down Expand Up @@ -155,6 +159,7 @@ export const getSettings = createSelector(
__unstableGetPreference( state, 'fixedToolbar' ),
__unstableGetPreference( state, 'keepCaretInsideBlock' ),
__unstableGetPreference( state, 'showIconLabels' ),
__unstableGetPreference( state, 'allowRightClickOverrides' ),
getReusableBlocks( state ),
getEditedPostType( state ),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
'__unstableGalleryWithImageBlocks',
'alignWide',
'allowedBlockTypes',
'allowRightClickOverrides',
'bodyPlaceholder',
'canLockBlocks',
'codeEditingEnabled',
Expand Down

0 comments on commit 8fd68db

Please sign in to comment.