How to use the @wordpress/blocks.getBlockSupport 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 DefinitelyTyped / DefinitelyTyped / types / wordpress__blocks / wordpress__blocks-tests.tsx View on Github external
// $ExpectType string | BlockInstance<{ [k: string]: any; }>[]
blocks.pasteHandler({ HTML: '<p>hello world</p>' });

// $ExpectType BlockInstance&lt;{ [k: string]: any; }&gt;[]
blocks.rawHandler({ HTML: '<p>hello world</p>' });

//
// registration
// ----------------------------------------------------------------------------

// $ExpectType unknown
blocks.getBlockSupport(BLOCK, 'align');

// $ExpectType unknown
blocks.getBlockSupport('core/paragraph', 'anchor');

// $ExpectType string
blocks.getBlockSupport('core/paragraph', 'inserter', 'Hello World');

// $ExpectType number
blocks.getBlockSupport('core/paragraph', 'inserter', 1234);

// $ExpectType { foo: string; }
blocks.getBlockSupport('core/paragraph', 'inserter', { foo: 'bar' });

// $ExpectType Block | undefined
blocks.getBlockType('core/paragraph');

// $ExpectType Block[]
blocks.getBlockTypes();
github DefinitelyTyped / DefinitelyTyped / types / wordpress__blocks / wordpress__blocks-tests.tsx View on Github external
// $ExpectType BlockInstance&lt;{ [k: string]: any; }&gt;[]
blocks.rawHandler({ HTML: '<p>hello world</p>' });

//
// registration
// ----------------------------------------------------------------------------

// $ExpectType unknown
blocks.getBlockSupport(BLOCK, 'align');

// $ExpectType unknown
blocks.getBlockSupport('core/paragraph', 'anchor');

// $ExpectType string
blocks.getBlockSupport('core/paragraph', 'inserter', 'Hello World');

// $ExpectType number
blocks.getBlockSupport('core/paragraph', 'inserter', 1234);

// $ExpectType { foo: string; }
blocks.getBlockSupport('core/paragraph', 'inserter', { foo: 'bar' });

// $ExpectType Block | undefined
blocks.getBlockType('core/paragraph');

// $ExpectType Block[]
blocks.getBlockTypes();

// $ExpectType string[]
blocks.getChildBlockNames('core/columns');
github DefinitelyTyped / DefinitelyTyped / types / wordpress__blocks / wordpress__blocks-tests.tsx View on Github external
//
// registration
// ----------------------------------------------------------------------------

// $ExpectType unknown
blocks.getBlockSupport(BLOCK, 'align');

// $ExpectType unknown
blocks.getBlockSupport('core/paragraph', 'anchor');

// $ExpectType string
blocks.getBlockSupport('core/paragraph', 'inserter', 'Hello World');

// $ExpectType number
blocks.getBlockSupport('core/paragraph', 'inserter', 1234);

// $ExpectType { foo: string; }
blocks.getBlockSupport('core/paragraph', 'inserter', { foo: 'bar' });

// $ExpectType Block | undefined
blocks.getBlockType('core/paragraph');

// $ExpectType Block[]
blocks.getBlockTypes();

// $ExpectType string[]
blocks.getChildBlockNames('core/columns');

// $ExpectType string | undefined
blocks.getDefaultBlockName();
github WordPress / gutenberg / editor / hooks / align.js View on Github external
export function getBlockValidAlignments( blockName ) {
	// Explicitly defined array set of valid alignments
	const blockAlign = getBlockSupport( blockName, 'align' );
	if ( Array.isArray( blockAlign ) ) {
		return blockAlign;
	}

	const validAlignments = [];
	if ( true === blockAlign ) {
		// `true` includes all alignments...
		validAlignments.push( 'left', 'center', 'right' );

		// ...including wide alignments unless explicitly `false`.
		if ( getBlockSupport( blockName, 'wideAlign' ) === false ) {
			deprecated( 'supports.wideAlign in Block API', {
				version: '3.6',
				alternative: 'supports.alignWide',
				plugin: 'Gutenberg',
			} );
github WordPress / gutenberg / packages / block-editor / src / hooks / align.js View on Github external
( props ) => {
			const { name: blockName } = props;
			// Compute valid alignments without taking into account,
			// if the theme supports wide alignments or not.
			// BlockAlignmentToolbar takes into account the theme support.
			const validAlignments = getValidAlignments(
				getBlockSupport( blockName, 'align' ),
				hasBlockSupport( blockName, 'alignWide', true ),
			);

			const updateAlignment = ( nextAlign ) => {
				if ( ! nextAlign ) {
					const blockType = getBlockType( props.name );
					const blockDefaultAlign = get( blockType, [ 'attributes', 'align', 'default' ] );
					if ( blockDefaultAlign ) {
						nextAlign = '';
					}
				}
				props.setAttributes( { align: nextAlign } );
			};

			return [
				validAlignments.length > 0 && props.isSelected && (
github WordPress / gutenberg / packages / block-editor / src / hooks / align.js View on Github external
export function addAssignedAlign( props, blockType, attributes ) {
	const { align } = attributes;
	const blockAlign = getBlockSupport( blockType, 'align' );
	const hasWideBlockSupport = hasBlockSupport( blockType, 'alignWide', true );
	const isAlignValid = includes(
		// Compute valid alignments without taking into account,
		// if the theme supports wide alignments or not.
		// This way changing themes does not impacts the block save.
		getValidAlignments( blockAlign, hasWideBlockSupport ),
		align
	);
	if ( isAlignValid ) {
		props.className = classnames( `align${ align }`, props.className );
	}

	return props;
}
github godaddy-wordpress / coblocks / src / hooks / columns.js View on Github external
BlockEdit =&gt; props =&gt; {
		const { name: blockName, attributes, setAttributes } = props;
		const blockSupport = getBlockSupport( blockName, SUPPORTS_NAME );
		return [
			blockSupport &amp;&amp; (
				
					
						 setAttributes( { coblockColumns } ) }
						/&gt;
						{ attributes.coblockColumns &gt; 1 &amp;&amp; (