@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
58 lines (51 loc) • 1.22 kB
text/typescript
/**
* External dependencies
*/
import createSelector from 'rememo';
/**
* WordPress dependencies
*/
import { createRegistrySelector } from '@wordpress/data';
/**
* Internal dependencies
*/
import type { State } from './selectors';
import { STORE_NAME } from './name';
type EntityRecordKey = string | number;
/**
* Returns the previous edit from the current undo offset
* for the entity records edits history, if any.
*
* @param state State tree.
*
* @return The undo manager.
*/
export function getUndoManager( state: State ) {
return state.undoManager;
}
/**
* Retrieve the fallback Navigation.
*
* @param state Data state.
* @return The ID for the fallback Navigation post.
*/
export function getNavigationFallbackId(
state: State
): EntityRecordKey | undefined {
return state.navigationFallbackId;
}
export const getBlockPatternsForPostType = createRegistrySelector(
( select: any ) =>
createSelector(
( state, postType ) =>
select( STORE_NAME )
.getBlockPatterns()
.filter(
( { postTypes } ) =>
! postTypes ||
( Array.isArray( postTypes ) &&
postTypes.includes( postType ) )
),
() => [ select( STORE_NAME ).getBlockPatterns() ]
)
);