Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// $ExpectType string | BlockInstance<{ [k: string]: any; }>[]
blocks.pasteHandler({ HTML: '<p>hello world</p>' });
// $ExpectType BlockInstance<{ [k: string]: any; }>[]
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 BlockInstance<{ [k: string]: any; }>[]
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');
//
// 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();
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',
} );
( 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 && (
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;
}
BlockEdit => props => {
const { name: blockName, attributes, setAttributes } = props;
const blockSupport = getBlockSupport( blockName, SUPPORTS_NAME );
return [
blockSupport && (
setAttributes( { coblockColumns } ) }
/>
{ attributes.coblockColumns > 1 && (