How to use the @wordpress/blocks.getBlockType 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 Automattic / wp-calypso / packages / jetpack-blocks / src / utils / refresh-registrations.js View on Github external
const { childBlocks, name, settings } = extension;
		const { available } = getJetpackExtensionAvailability( name );

		if ( has( settings, [ 'render' ] ) ) {
			// If the extension has a `render` method, it's not a block but a plugin
			const pluginName = `jetpack-${ name }`;
			const registered = getPlugin( pluginName );

			if ( available && ! registered ) {
				registerPlugin( pluginName, settings );
			} else if ( ! available && registered ) {
				unregisterPlugin( pluginName );
			}
		} else {
			const blockName = `jetpack/${ name }`;
			const registered = getBlockType( blockName );

			if ( available && ! registered ) {
				registerBlockType( blockName, settings );
				if ( childBlocks ) {
					childBlocks.forEach( ( { name: childName, settings: childSettings } ) => {
						// This might have been registered by another parent before
						if ( ! getBlockType( `jetpack/${ childName }` ) ) {
							registerBlockType( `jetpack/${ childName }`, childSettings );
						}
					} );
				}
			} else if ( ! available && registered ) {
				if ( childBlocks ) {
					childBlocks.forEach( ( { name: childName } ) => {
						const childBlock = getBlockType( `jetpack/${ childName }` );
						const otherParents = without( childBlock.parent, blockName );
github Automattic / wp-calypso / client / gutenberg / editor / edit-post / hooks / validate-multiple-use / index.js View on Github external
function getOutboundType( blockName ) {
	// Grab the first outbound transform
	const transform = findTransform(
		getBlockTransforms( 'to', blockName ),
		( { type, blocks } ) => type === 'block' && blocks.length === 1 // What about when .length > 1?
	);

	if ( ! transform ) {
		return null;
	}

	return getBlockType( transform.blocks[ 0 ] );
}
github front / gutenberg-js / src / js / gutenberg-overrides / packages / editor / build-module / components / block-list / block.js View on Github external
setAttributes (attributes) {
    const { block, onChange } = this.props;
    const type = getBlockType(block.name);
    onChange(block.clientId, attributes);

    const metaAttributes = reduce(attributes, (result, value, key) => {
      if (get(type, [ 'attributes', key, 'source' ]) === 'meta') {
        result[ type.attributes[ key ].meta ] = value;
      }

      return result;
    }, {});

    if (size(metaAttributes)) {
      this.props.onMetaChange({
        ...this.props.meta,
        ...metaAttributes,
      });
    }
github WordPress / gutenberg / editor / components / block-settings-menu / block-mode-toggle.js View on Github external
( state, { uid } ) => {
		const block = getBlock( state, uid );

		return {
			mode: getBlockMode( state, uid ),
			blockType: block ? getBlockType( block.name ) : null,
		};
	},
	( dispatch, { onToggle = noop, uid } ) => ( {
github gambitph / Stackable / src / register-block.js View on Github external
const registerBlock = ( name, settings = {} ) => {
	if ( getBlockType( name ) ) {
		return
	}

	const blockName = name.replace( /^\w+\//g, '' )
	const blockSettings = {
		...settings,
		category: supportsBlockCollections() ? settings.category : 'stackable',
		modules: applyFilters( `stackable.${ blockName }.modules`, settings.modules || {} ),
		deprecated: ( settings.deprecated || [] ).map( deprecated => {
			return {
				...deprecated,
				save: withMainClassname( name )( deprecated.save ),
			}
		} ),
	}
github WordPress / gutenberg / packages / block-editor / src / components / block-settings-menu / block-mode-toggle.js View on Github external
withSelect( ( select, { clientId } ) => {
		const { getBlock, getBlockMode, getSettings } = select( 'core/block-editor' );
		const block = getBlock( clientId );
		const isCodeEditingEnabled = getSettings().codeEditingEnabled;

		return {
			mode: getBlockMode( clientId ),
			blockType: block ? getBlockType( block.name ) : null,
			isCodeEditingEnabled,
		};
	} ),
	withDispatch( ( dispatch, { onToggle = noop, clientId } ) => ( {
github Automattic / wp-calypso / packages / jetpack-blocks / src / blocks / contact-form / index.js View on Github external
const getFieldLabel = ( { attributes, name: blockName } ) => {
	return null === attributes.label ? getBlockType( blockName ).title : attributes.label;
};
github Automattic / jetpack / extensions / blocks / contact-form / index.js View on Github external
const getFieldLabel = ( { attributes, name: blockName } ) => {
	return null === attributes.label ? getBlockType( blockName ).title : attributes.label;
};
github ampproject / amp-wp / assets / src / stories-editor / components / block-preview-label.js View on Github external
export default withSelect( ( select, { block, label } ) => {
	if ( ! block ) {
		return {
			content: label,
			icon: null,
		};
	}

	const { getEditedPostAttribute } = select( 'core/editor' );
	const { getAuthors, getMedia } = select( 'core' );

	const blockType = getBlockType( block.name );

	label = blockType.title;
	let content = '';

	switch ( block.name ) {
		case 'core/image':
			if ( block.attributes.url ) {
				content = block.attributes.url.slice( block.attributes.url.lastIndexOf( '/' ) ).slice( 1, 30 );

				if ( content.length > 0 ) {
					label = content;
				}
			}

			if ( block.attributes.id ) {
				const media = getMedia( block.attributes.id );
github WordPress / gutenberg / packages / block-editor / src / components / block-navigation / list.js View on Github external
{ map( omitBy( blocks, isNil ), ( block ) => {
				const blockType = getBlockType( block.name );
				const isSelected = block.clientId === selectedBlockClientId;

				return (
					<li>
						<div>
							<button> selectBlock( block.clientId ) }
							&gt;
								
								{ getBlockDisplayName( blockType, block.attributes ) }
								{ isSelected &amp;&amp; <span>{ __( '(selected block)' ) }</span> }
							</button>
						</div></li>