How to use the @wordpress/blocks.getBlockTypes function in @wordpress/blocks

To help you get started, we’ve selected a few @wordpress/blocks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / test / integration / full-content / full-content.spec.js View on Github external
it( 'should be present for each block', () => {
		const errors = [];

		getBlockTypes()
			.map( ( block ) => block.name )
			// We don't want tests for each oembed provider, which all have the same
			// `save` functions and attributes.
			// The `core/template` is not worth testing here because it's never saved, it's covered better in e2e tests.
			.filter( ( name ) => name.indexOf( 'core-embed' ) !== 0 && name !== 'core/template' )
			.forEach( ( name ) => {
				const nameToFilename = blockNameToFixtureBasename( name );
				const foundFixtures = blockBasenames
					.filter( ( basename ) => (
						basename === nameToFilename ||
						startsWith( basename, nameToFilename + '__' )
					) )
					.map( ( basename ) => {
						const {
							filename: htmlFixtureFileName,
						} = getBlockFixtureHTML( basename );
github ampproject / amp-wp / assets / src / stories-editor / index.js View on Github external
domReady( () => {
	// Ensure that the default block is page when no block is selected.
	setDefaultBlockName( 'amp/amp-story-page' );

	// Remove all blocks that aren't whitelisted.
	const disallowedBlockTypes = getBlockTypes().filter( ( { name } ) => ! ALLOWED_BLOCKS.includes( name ) );

	for ( const blockType of disallowedBlockTypes ) {
		unregisterBlockType( blockType.name );
	}

	const allBlocks = getBlocksByClientId( getClientIdsWithDescendants() );

	// Set initially shown page.
	const firstPage = allBlocks.find( ( { name } ) => name === 'amp/amp-story-page' );
	setCurrentPage( firstPage ? firstPage.clientId : undefined );

	for ( const block of allBlocks ) {
		// Load all needed fonts.
		if ( block.attributes.ampFontFamily ) {
			maybeEnqueueFontStyle( block.attributes.ampFontFamily );
		}
github WordPress / gutenberg / editor / components / autocompleters / block.js View on Github external
options: once( function options() {
		return Promise.resolve(
			// Prioritize common category in block type options
			sortBy(
				getBlockTypes(),
				( { category } ) => 'common' !== category
			)
		);
	} ),
	getOptionKeywords( blockSettings ) {
github Gaya / ab-testing-for-wp / src / js / core / allowedBlockTypes.ts View on Github external
export default function allowedBlockTypes(disallowedTypes: string[] = defaultDisallowed): string[] {
  return getBlockTypes()
    .map((type) => type.name)
    .filter((typeName) => disallowedTypes.indexOf(typeName) === -1);
}
github GraphQLAPI / graphql-api-for-wp / blocks / access-control / src / access-control.js View on Github external
const AccessControl = ( props ) => {
	const { className, isIndividualControlForSchemaModeEnabled } = props;
	/**
	 * Only allow blocks under the "Access Control" category, except for this self block
	 */
	const allowedBlocks = getBlockTypes().filter(
		blockType => blockType.category == ACCESS_CONTROL_BLOCK_CATEGORY && blockType.name != ACCESS_CONTROL_BLOCK_NAME
	).map(blockType => blockType.name)
	/**
	 * Add component SchemaMode only if option "individual schema mode" is enabled
	 */
	return (
		<>
			{ isIndividualControlForSchemaModeEnabled &&
				<div>
					
				</div>
			}
github wordpress-mobile / gutenberg-mobile / src / block-management / block-picker.js View on Github external
/**
 * Internal dependencies
 */
import styles from './block-picker.scss';

type PropsType = {
	style?: StyleSheet,
	isReplacement: boolean,
	onValueSelected: ( itemValue: string ) =&gt; void,
	onDismiss: () =&gt; void,
	addExtraBottomPadding: boolean,
};

export default class BlockPicker extends Component {
	availableBlockTypes = getBlockTypes().filter( ( { name } ) =&gt; name !== getUnregisteredTypeHandlerName() );

	render() {
		const numberOfColumns = this.calculateNumberOfColumns();
		const bottomPadding = this.props.addExtraBottomPadding &amp;&amp; styles.contentBottomPadding;

		return (
github WordPress / gutenberg / src / block-management / block-picker.js View on Github external
/**
 * Internal dependencies
 */
import styles from './block-picker.scss';

type PropsType = {
	style?: StyleSheet,
	isReplacement: boolean,
	onValueSelected: ( itemValue: string ) =&gt; void,
	onDismiss: () =&gt; void,
	addExtraBottomPadding: boolean,
};

export default class BlockPicker extends Component {
	availableBlockTypes = getBlockTypes().filter( ( { name } ) =&gt; name !== getUnregisteredTypeHandlerName() );

	render() {
		const numberOfColumns = this.calculateNumberOfColumns();
		const bottomPadding = this.props.addExtraBottomPadding &amp;&amp; styles.contentBottomPadding;

		return (
github WordPress / gutenberg / packages / block-editor / src / store / selectors.js View on Github external
return {
				id,
				name: 'core/block',
				initialAttributes: { ref: reusableBlock.id },
				title: reusableBlock.title,
				icon: referencedBlockType ? referencedBlockType.icon : templateIcon,
				category: 'reusable',
				keywords: [],
				isDisabled: false,
				utility,
				frecency,
			};
		};

		const blockTypeInserterItems = getBlockTypes()
			.filter( ( blockType ) => canIncludeBlockTypeInInserter( state, blockType, rootClientId ) )
			.map( buildBlockTypeInserterItem );

		const reusableBlockInserterItems = canInsertBlockTypeUnmemoized( state, 'core/block', rootClientId ) ?
			getReusableBlocks( state ).map( buildReusableBlockInserterItem ) :
			[];

		return orderBy(
			[ ...blockTypeInserterItems, ...reusableBlockInserterItems ],
			[ 'utility', 'frecency' ],
			[ 'desc', 'desc' ]
		);
	},
	( state, rootClientId ) => [
github godaddy-wordpress / coblocks / src / sidebars / block-manager / components / modal.js View on Github external
constructor() {
		super( ...arguments );

		//assign blocks per category
		const blocksPerCategory = {};
		{ map( getCategories(), ( category ) => {
			blocksPerCategory[ category.slug ] = category;
			blocksPerCategory[ category.slug ].blocks = {};
		} ); }

		{ map( getBlockTypes(), ( block ) => {
			if ( ! [ 'core/paragraph' ].includes( block.name ) && ! block.parent ) {
				blocksPerCategory[ block.category ].blocks[ block.name ] = block;
			}
		} ); }

		this.state = {
			settings: '',
			isOpen: false,
			isSaving: false,
			isLoaded: false,
			searchValue: '',
			allBlocks: blocksPerCategory,
			getBlockTypes: getBlockTypes(),
			searchResults: {},
		};
github WordPress / gutenberg / editor / block-switcher / index.js View on Github external
function BlockSwitcher( { blocks, onTransform } ) {
	if ( ! blocks || ! blocks[ 0 ] ) {
		return null;
	}
	const isMultiBlock = blocks.length > 1;
	const sourceBlockName = blocks[ 0 ].name;

	if ( isMultiBlock && ! every( blocks, ( block ) => ( block.name === sourceBlockName ) ) ) {
		return null;
	}

	const blockType = getBlockType( sourceBlockName );
	const blocksToBeTransformedFrom = reduce( getBlockTypes(), ( memo, type ) => {
		const transformFrom = get( type, 'transforms.from', [] );
		const transformation = find(
			transformFrom,
			t => t.type === 'block' && t.blocks.indexOf( sourceBlockName ) !== -1 &&
				( ! isMultiBlock || t.isMultiBlock )
		);
		return transformation ? memo.concat( [ type.name ] ) : memo;
	}, [] );
	const blocksToBeTransformedTo = get( blockType, 'transforms.to', [] )
		.reduce(
			( memo, transformation ) =>
				memo.concat( ! isMultiBlock || transformation.isMultiBlock ? transformation.blocks : [] ),
			[]
		);
	const allowedBlocks = uniq( blocksToBeTransformedFrom.concat( blocksToBeTransformedTo ) )
		.reduce( ( memo, name ) => {