Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open inserter sidebar when clicking on inserter buttons on zoom-out mode #61434

Merged
merged 18 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,11 @@
.is-dragging-components-draggable .components-tooltip {
display: none;
}

.components-popover.block-editor-block-popover__inbetween .block-editor-button-pattern-inserter__button {
pointer-events: all;
position: absolute;
transform: translateX(-50%) translateY(-50%);
top: 50%;
left: 50%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,41 @@
*/
import { useSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { plus } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BlockPopoverInbetween from '../block-popover/inbetween';
import { store as blockEditorStore } from '../../store';
import Inserter from '../inserter';
import { unlock } from '../../lock-unlock';

function ZoomOutModeInserters( { __unstableContentRef } ) {
function ZoomOutModeInserters() {
const [ isReady, setIsReady ] = useState( false );
const blockOrder = useSelect( ( select ) => {
const { sectionRootClientId } = unlock(
select( blockEditorStore ).getSettings()
);
return select( blockEditorStore ).getBlockOrder( sectionRootClientId );
const {
blockOrder,
sectionRootClientId,
insertionPoint,
setInserterIsOpened,
} = useSelect( ( select ) => {
const { getSettings, getBlockOrder } = 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
// block-editor store. I'm not sure what it was ever moved to the editor
// store, because all the inserter components all live in the
// block-editor package.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const editor = select( 'core/editor' );
return {
blockOrder: getBlockOrder( root ),
insertionPoint: unlock( editor ).getInsertionPoint(),
sectionRootClientId: root,
setInserterIsOpened:
getSettings().__experimentalSetIsInserterOpened,
};
}, [] );

// Defer the initial rendering to avoid the jumps due to the animation.
Expand All @@ -41,15 +60,39 @@ function ZoomOutModeInserters( { __unstableContentRef } ) {
key={ index }
previousClientId={ clientId }
nextClientId={ blockOrder[ index ] }
__unstableContentRef={ __unstableContentRef }
className="block-editor-button-pattern-inserter"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this class name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it can go

>
<div className="block-editor-block-list__insertion-point-inserter is-with-inserter">
<Inserter
position="bottom center"
clientId={ blockOrder[ index ] }
__experimentalIsQuick
{ insertionPoint.insertionIndex === index && (
<div
style={ {
opacity: 1,
height: '4px',
width: '100%',
transform: 'translateY(-50%)',
} }
className="block-editor-block-list__insertion-point-indicator"
/>
) }
{ insertionPoint.insertionIndex !== index && (
<Button
variant="primary"
icon={ plus }
size="compact"
className="block-editor-button-pattern-inserter__button"
onClick={ () => {
setInserterIsOpened( {
rootClientId: sectionRootClientId,
insertionIndex: index,
tab: 'patterns',
category: 'all',
} );
} }
label={ _x(
'Add pattern',
'Generic label for pattern inserter button'
) }
/>
</div>
) }
</BlockPopoverInbetween>
);
} );
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function InserterLibrary(
showInserterHelpPanel,
showMostUsedBlocks = false,
__experimentalInsertionIndex,
__experimentalInitialTab,
__experimentalInitialCategory,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
onSelect = noop,
Expand Down Expand Up @@ -53,6 +55,8 @@ function InserterLibrary(
__experimentalOnPatternCategorySelection={
__experimentalOnPatternCategorySelection
}
__experimentalInitialTab={ __experimentalInitialTab }
__experimentalInitialCategory={ __experimentalInitialCategory }
shouldFocusBlock={ shouldFocusBlock }
ref={ ref }
onClose={ onClose }
Expand Down
14 changes: 11 additions & 3 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function InserterMenu(
shouldFocusBlock = true,
__experimentalOnPatternCategorySelection = NOOP,
onClose,
__experimentalInitialTab,
__experimentalInitialCategory,
},
ref
) {
Expand All @@ -59,12 +61,15 @@ function InserterMenu(
const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );
const [ selectedPatternCategory, setSelectedPatternCategory ] =
useState( null );
const [ selectedPatternCategory, setSelectedPatternCategory ] = useState(
__experimentalInitialCategory
);
const [ patternFilter, setPatternFilter ] = useState( 'all' );
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const [ selectedTab, setSelectedTab ] = useState( 'blocks' );
const [ selectedTab, setSelectedTab ] = useState(
__experimentalInitialTab
);

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down Expand Up @@ -231,6 +236,7 @@ function InserterMenu(
category={ selectedPatternCategory }
patternFilter={ patternFilter }
showTitlesAsTooltip
initialCategory={ __experimentalInitialCategory }
/>
) }
</BlockPatternsTab>
Expand All @@ -243,6 +249,7 @@ function InserterMenu(
patternFilter,
selectedPatternCategory,
showPatternPanel,
__experimentalInitialCategory,
] );

const mediaTab = useMemo( () => {
Expand Down Expand Up @@ -306,6 +313,7 @@ function InserterMenu(
ref={ tabsRef }
onSelect={ handleSetSelectedTab }
onClose={ onClose }
selectedTab={ selectedTab }
>
{ inserterSearch }
{ selectedTab === 'blocks' &&
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/inserter/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const mediaTab = {
title: __( 'Media' ),
};

function InserterTabs( { onSelect, children, onClose }, ref ) {
function InserterTabs( { onClose, onSelect, children, selectedTab }, ref ) {
const tabs = [ blocksTab, patternsTab, mediaTab ];

return (
<div className="block-editor-inserter__tabs" ref={ ref }>
<Tabs onSelect={ onSelect }>
<Tabs onSelect={ onSelect } selectedTabId={ selectedTab }>
<div className="block-editor-inserter-sidebar__header">
<Button
className="block-editor-inserter-sidebar__close-button"
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default function InserterSidebar( {
__experimentalInsertionIndex={
insertionPoint.insertionIndex
}
__experimentalInitialTab={ insertionPoint.tab }
__experimentalInitialCategory={ insertionPoint.category }
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
Expand Down
Loading