Skip to content

Commit

Permalink
Zoom out: try click through to disengage
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 10, 2024
1 parent b2d3dca commit e706baf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ function ZoomOutModeInserters() {
sectionRootClientId,
insertionPoint,
setInserterIsOpened,
selectedClientId,
} = useSelect( ( select ) => {
const { getSettings, getBlockOrder } = select( blockEditorStore );
const { getSettings, getBlockOrder, getSelectedBlockClientId } =
select( blockEditorStore );
const { sectionRootClientId: root } = unlock( getSettings() );
// To do: move ZoomOutModeInserters to core/editor.
// Or we perhaps we should move the insertion point state to the
Expand All @@ -37,11 +39,18 @@ function ZoomOutModeInserters() {
sectionRootClientId: root,
setInserterIsOpened:
getSettings().__experimentalSetIsInserterOpened,
selectedClientId: getSelectedBlockClientId(),
};
}, [] );

const isMounted = useRef( false );

useEffect( () => {
if ( selectedClientId && ! blockOrder.includes( selectedClientId ) ) {
setInserterIsOpened( { tab: 'blocks' } );
}
}, [ selectedClientId, blockOrder, setInserterIsOpened ] );

useEffect( () => {
if ( ! isMounted.current ) {
isMounted.current = true;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function InserterLibrary(
showMostUsedBlocks = false,
__experimentalInsertionIndex,
__experimentalInitialTab,
__experimentalSetTab,
__experimentalInitialCategory,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
Expand Down Expand Up @@ -56,6 +57,7 @@ function InserterLibrary(
__experimentalOnPatternCategorySelection
}
__experimentalInitialTab={ __experimentalInitialTab }
__experimentalSetTab={ __experimentalSetTab }
__experimentalInitialCategory={ __experimentalInitialCategory }
shouldFocusBlock={ shouldFocusBlock }
ref={ ref }
Expand Down
6 changes: 2 additions & 4 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function InserterMenu(
shouldFocusBlock = true,
__experimentalOnPatternCategorySelection = NOOP,
onClose,
__experimentalInitialTab,
__experimentalInitialTab: selectedTab = 'blocks',
__experimentalSetTab: setSelectedTab,
__experimentalInitialCategory,
},
ref
Expand All @@ -67,9 +68,6 @@ function InserterMenu(
const [ patternFilter, setPatternFilter ] = useState( 'all' );
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const [ selectedTab, setSelectedTab ] = useState(
__experimentalInitialTab
);

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down
9 changes: 7 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,7 @@ export function __unstableHasActiveBlockOverlayActive( state, clientId ) {
sectionRootClientId
);
if ( sectionClientIds?.includes( clientId ) ) {
return true;
return ! isBlockSelected( state, clientId );
}
} else if ( clientId && ! getBlockRootClientId( state, clientId ) ) {
return true;
Expand Down Expand Up @@ -2898,7 +2898,12 @@ export const getBlockEditingMode = createRegistrySelector(
sectionRootClientId
);
if ( ! sectionsClientIds?.includes( clientId ) ) {
return 'disabled';
return getBlockParents( state, clientId ).some(
( parentClientId ) =>
isBlockSelected( state, parentClientId )
)
? 'default'
: 'disabled';
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export default function InserterSidebar( {
insertionPoint.insertionIndex
}
__experimentalInitialTab={ insertionPoint.tab }
__experimentalSetTab={ ( tab ) => {
setIsInserterOpened( { tab } );
} }
__experimentalInitialCategory={ insertionPoint.category }
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
Expand Down

0 comments on commit e706baf

Please sign in to comment.