Skip to content

Commit

Permalink
Make onPatternCategorySelection private (#62130)
Browse files Browse the repository at this point in the history
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ellatrix <[email protected]>
  • Loading branch information
4 people committed May 30, 2024
1 parent 2302eb7 commit 833d957
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
24 changes: 17 additions & 7 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import InserterMenu from './menu';
import { PrivateInserterMenu } from './menu';
import { store as blockEditorStore } from '../../store';

const noop = () => {};
Expand All @@ -23,7 +23,7 @@ function InserterLibrary(
__experimentalInitialTab,
__experimentalInitialCategory,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
onPatternCategorySelection,
onSelect = noop,
shouldFocusBlock = false,
onClose,
Expand All @@ -43,7 +43,7 @@ function InserterLibrary(
);

return (
<InserterMenu
<PrivateInserterMenu
onSelect={ onSelect }
rootClientId={ destinationRootClientId }
clientId={ clientId }
Expand All @@ -52,9 +52,7 @@ function InserterLibrary(
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalInsertionIndex={ __experimentalInsertionIndex }
__experimentalFilterValue={ __experimentalFilterValue }
__experimentalOnPatternCategorySelection={
__experimentalOnPatternCategorySelection
}
onPatternCategorySelection={ onPatternCategorySelection }
__experimentalInitialTab={ __experimentalInitialTab }
__experimentalInitialCategory={ __experimentalInitialCategory }
shouldFocusBlock={ shouldFocusBlock }
Expand All @@ -64,4 +62,16 @@ function InserterLibrary(
);
}

export default forwardRef( InserterLibrary );
export const PrivateInserterLibrary = forwardRef( InserterLibrary );

function PublicInserterLibrary( props, ref ) {
return (
<PrivateInserterLibrary
{ ...props }
onPatternCategorySelection={ undefined }
ref={ ref }
/>
);
}

export default forwardRef( PublicInserterLibrary );
20 changes: 16 additions & 4 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function InserterMenu(
showMostUsedBlocks,
__experimentalFilterValue = '',
shouldFocusBlock = true,
__experimentalOnPatternCategorySelection = NOOP,
onPatternCategorySelection,
onClose,
__experimentalInitialTab,
__experimentalInitialCategory,
Expand Down Expand Up @@ -128,9 +128,9 @@ function InserterMenu(
( patternCategory, filter ) => {
setSelectedPatternCategory( patternCategory );
setPatternFilter( filter );
__experimentalOnPatternCategorySelection();
onPatternCategorySelection?.();
},
[ setSelectedPatternCategory, __experimentalOnPatternCategorySelection ]
[ setSelectedPatternCategory, onPatternCategorySelection ]
);

const showPatternPanel =
Expand Down Expand Up @@ -341,4 +341,16 @@ function InserterMenu(
);
}

export default forwardRef( InserterMenu );
export const PrivateInserterMenu = forwardRef( InserterMenu );

function PublicInserterMenu( props, ref ) {
return (
<PrivateInserterMenu
{ ...props }
onPatternCategorySelection={ NOOP }
ref={ ref }
/>
);
}

export default forwardRef( PublicInserterMenu );
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import { requiresWrapperOnCopy } from './components/writing-flow/utils';
import { PrivateRichText } from './components/rich-text/';
import { PrivateBlockPopover } from './components/block-popover';
import { PrivateInserterLibrary } from './components/inserter/library';

/**
* Private @wordpress/block-editor APIs.
Expand Down Expand Up @@ -78,6 +79,7 @@ lock( privateApis, {
selectBlockPatternsKey,
requiresWrapperOnCopy,
PrivateRichText,
PrivateInserterLibrary,
reusableBlocksSelectKey,
PrivateBlockPopover,
} );
8 changes: 5 additions & 3 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import { useDispatch, useSelect } from '@wordpress/data';
import {
__experimentalLibrary as Library,
store as blockEditorStore,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import {
useViewportMatch,
Expand All @@ -20,6 +20,8 @@ import { ESCAPE } from '@wordpress/keycodes';
import { unlock } from '../../lock-unlock';
import { store as editorStore } from '../../store';

const { PrivateInserterLibrary } = unlock( blockEditorPrivateApis );

export default function InserterSidebar( {
closeGeneralSidebar,
isRightSidebarOpen,
Expand Down Expand Up @@ -79,7 +81,7 @@ export default function InserterSidebar( {

const inserterContents = (
<div className="editor-inserter-sidebar__content">
<Library
<PrivateInserterLibrary
showMostUsedBlocks={ showMostUsedBlocks }
showInserterHelpPanel
shouldFocusBlock={ isMobileViewport }
Expand All @@ -90,7 +92,7 @@ export default function InserterSidebar( {
__experimentalInitialTab={ insertionPoint.tab }
__experimentalInitialCategory={ insertionPoint.category }
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
onPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
}
ref={ libraryRef }
Expand Down

0 comments on commit 833d957

Please sign in to comment.