Skip to content

Commit

Permalink
Move all ref selectors to block editor
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Aug 12, 2024
1 parent bf454a0 commit 4cdc026
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 41 deletions.
4 changes: 0 additions & 4 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,6 @@ _Related_

- getInserterItems in core/block-editor store.

### getInserterSearchInputRef

Undocumented declaration.

### getLastMultiSelectedBlockClientId

_Related_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ function ZoomOutModeInserters() {
getSelectedBlockClientId,
getHoveredBlockClientId,
isBlockInsertionPointVisible,
} = select( blockEditorStore );
getInserterSearchInputRef,
} = unlock( select( blockEditorStore ) );

const { sectionRootClientId: root } = unlock( getSettings() );

return {
Expand All @@ -46,8 +48,7 @@ function ZoomOutModeInserters() {
getSettings().__experimentalSetIsInserterOpened,
selectedBlockClientId: getSelectedBlockClientId(),
hoveredBlockClientId: getHoveredBlockClientId(),
inserterSearchInputRef:
getSettings().__experimentalGetInserterSearchInputRef(),
inserterSearchInputRef: getInserterSearchInputRef(),
};
}, [] );

Expand Down
25 changes: 15 additions & 10 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 @@ -50,15 +51,19 @@ function InserterMenu(
onClose,
__experimentalInitialTab,
__experimentalInitialCategory,
__experimentalSearchInputRef,
},
ref
) {
const isZoomOutMode = useSelect(
( select ) =>
select( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',
[]
);
const { isZoomOutMode, inserterSearchInputRef } = useSelect( ( select ) => {
const { __unstableGetEditorMode, getInserterSearchInputRef } = unlock(
select( blockEditorStore )
);
return {
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
inserterSearchInputRef: getInserterSearchInputRef(),
};
}, [] );

const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );
Expand Down Expand Up @@ -105,7 +110,7 @@ function InserterMenu(
}
} );
},
[ onInsertBlocks, onSelect, shouldFocusBlock ]
[ onInsertBlocks, onSelect, ref, shouldFocusBlock ]
);

const onInsertPattern = useCallback(
Expand All @@ -114,7 +119,7 @@ function InserterMenu(
onInsertBlocks( blocks, { patternName } );
onSelect();
},
[ onInsertBlocks, onSelect ]
[ onInsertBlocks, onSelect, onToggleInsertionPoint ]
);

const onHover = useCallback(
Expand Down Expand Up @@ -165,7 +170,7 @@ function InserterMenu(
value={ filterValue }
label={ __( 'Search for blocks and patterns' ) }
placeholder={ __( 'Search' ) }
ref={ __experimentalSearchInputRef }
ref={ inserterSearchInputRef }
/>

{ !! delayedFilterValue && (
Expand All @@ -189,7 +194,7 @@ function InserterMenu(
}, [
selectedTab,
filterValue,
__experimentalSearchInputRef,
inserterSearchInputRef,
delayedFilterValue,
onSelect,
onHover,
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,7 @@ export function getTemporarilyEditingAsBlocks( state ) {
export function getTemporarilyEditingFocusModeToRevert( state ) {
return state.temporarilyEditingFocusModeRevert;
}

export function getInserterSearchInputRef( state ) {
return state.inserterSearchInputRef;
}
5 changes: 5 additions & 0 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,10 @@ export function hoveredBlockClientId( state = false, action ) {
return state;
}

export function inserterSearchInputRef( state = { current: null } ) {
return state;
}

const combinedReducers = combineReducers( {
blocks,
isDragging,
Expand Down Expand Up @@ -2118,6 +2122,7 @@ const combinedReducers = combineReducers( {
openedBlockSettingsMenu,
registeredInserterMediaCategories,
hoveredBlockClientId,
inserterSearchInputRef,
} );

function withAutomaticChangeReset( reducer ) {
Expand Down
7 changes: 1 addition & 6 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ export default function InserterSidebar() {
insertionPoint,
showMostUsedBlocks,
sidebarIsOpened,

inserterSearchInputRef,
} = useSelect( ( select ) => {
const {
getInserterSidebarToggleRef,
getInserterSearchInputRef,

getInsertionPoint,
isPublishSidebarOpened,
} = unlock( select( editorStore ) );
Expand All @@ -57,8 +55,6 @@ export default function InserterSidebar() {
sidebarIsOpened: !! (
getActiveComplementaryArea( 'core' ) || isPublishSidebarOpened()
),

inserterSearchInputRef: getInserterSearchInputRef(),
};
}, [] );
const { setIsInserterOpened } = useDispatch( editorStore );
Expand Down Expand Up @@ -104,7 +100,6 @@ export default function InserterSidebar() {
}
ref={ libraryRef }
onClose={ closeInserterSidebar }
__experimentalSearchInputRef={ inserterSearchInputRef }
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
[ settingsBlockPatternCategories, restBlockPatternCategories ]
);

const { _getInserterSearchInputRef } = useSelect( ( select ) => {
const { getInserterSearchInputRef } = select( editorStore );
return {
_getInserterSearchInputRef: getInserterSearchInputRef,
};
}, [] );

const { undo, setIsInserterOpened } = useDispatch( editorStore );

const { saveEntityRecord } = useDispatch( coreStore );
Expand Down Expand Up @@ -332,7 +325,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
? [ [ 'core/navigation', {}, [] ] ]
: settings.template,
__experimentalSetIsInserterOpened: setIsInserterOpened,
__experimentalGetInserterSearchInputRef: _getInserterSearchInputRef,
};
lock( blockEditorSettings, {
sectionRootClientId,
Expand Down Expand Up @@ -362,7 +354,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
sectionRootClientId,
globalStylesData,
globalStylesLinksData,
_getInserterSearchInputRef,
] );
}

Expand Down
5 changes: 0 additions & 5 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,6 @@ export function inserterSidebarToggleRef( state = { current: null } ) {
return state;
}

export function inserterSearchInputRef( state = { current: null } ) {
return state;
}

export function publishSidebarActive( state = false, action ) {
switch ( action.type ) {
case 'OPEN_PUBLISH_SIDEBAR':
Expand Down Expand Up @@ -408,5 +404,4 @@ export default combineReducers( {
listViewToggleRef,
publishSidebarActive,
dataviews: dataviewsReducer,
inserterSearchInputRef,
} );
4 changes: 0 additions & 4 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,3 @@ export const getPostTypeLabel = createRegistrySelector(
export function isPublishSidebarOpened( state ) {
return state.publishSidebarActive;
}

export function getInserterSearchInputRef( state ) {
return state.inserterSearchInputRef;
}

0 comments on commit 4cdc026

Please sign in to comment.