2021-09-03 13:25:09 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { innerBlockAreas, RegisteredBlock } from './types';
|
|
|
|
import { registeredBlocks } from './registered-blocks';
|
|
|
|
|
|
|
|
/**
|
2021-10-12 14:23:52 +00:00
|
|
|
* Check if a block/area supports inner block registration.
|
2021-09-03 13:25:09 +00:00
|
|
|
*/
|
2021-09-07 16:01:14 +00:00
|
|
|
export const hasInnerBlocks = ( block: string ): block is innerBlockAreas => {
|
|
|
|
return Object.values( innerBlockAreas ).includes(
|
|
|
|
block as innerBlockAreas
|
2021-09-03 13:25:09 +00:00
|
|
|
);
|
2021-09-07 16:01:14 +00:00
|
|
|
};
|
2021-09-03 13:25:09 +00:00
|
|
|
|
|
|
|
/**
|
2021-10-12 14:23:52 +00:00
|
|
|
* Returns an array of registered block objects available within a specific parent block/area.
|
2021-09-03 13:25:09 +00:00
|
|
|
*/
|
2021-09-07 16:01:14 +00:00
|
|
|
export const getRegisteredBlocks = (
|
|
|
|
block: string
|
|
|
|
): Array< RegisteredBlock > => {
|
|
|
|
return hasInnerBlocks( block )
|
|
|
|
? Object.values( registeredBlocks ).filter( ( { metadata } ) =>
|
|
|
|
( metadata?.parent || [] ).includes( block )
|
|
|
|
)
|
|
|
|
: [];
|
2021-09-03 13:25:09 +00:00
|
|
|
};
|