Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function initializeEditor() {
// register and setup blocks
registerCoreBlocks();
// disable Code and More blocks for the release
// eslint-disable-next-line no-undef
if ( typeof __DEV__ === 'undefined' || ! __DEV__ ) {
unregisterBlockType( 'core/code' );
unregisterBlockType( 'core/more' );
}
}
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 );
}
maybeRemoveDeprecatedSetting( block );
}
export function initializeEditor() {
// register and setup blocks
registerCoreBlocks();
// disable Code and More blocks for the release
// eslint-disable-next-line no-undef
if ( typeof __DEV__ === 'undefined' || ! __DEV__ ) {
unregisterBlockType( 'core/code' );
unregisterBlockType( 'core/more' );
}
}
}
} );
}
} else if ( ! available && registered ) {
if ( childBlocks ) {
childBlocks.forEach( ( { name: childName } ) => {
const childBlock = getBlockType( `jetpack/${ childName }` );
const otherParents = without( childBlock.parent, blockName );
// Are any of the other parents currently registered?
if ( ! otherParents.some( getBlockType ) ) {
unregisterBlockType( `jetpack/${ childName }` );
}
} );
}
unregisterBlockType( blockName );
}
}
} );
}
unregister: ( { name } ) => unregisterBlockType( name ),
before: storeSelectedBlock,
map( optionSettings, ( visible, block ) => {
if ( visible && ! block.includes( 'mainCategory-' ) && ! blockNames[ block ] ) {
unregisterBlockType( block );
}
} );
}
this.props.downloadableBlocksToUninstall.forEach( ( blockType ) => {
this.props.uninstallBlock( blockType, noop, () => {
this.props.createWarningNotice(
__( 'Block previews can\'t uninstall.' ), {
id: UNINSTALL_ERROR_NOTICE_ID,
} );
} );
unregisterBlockType( blockType.name );
} );
}
return;
}
if ( settingsState[ key ] ) {
settingsState[ key ] = ! settingsState[ key ];
} else {
settingsState[ key ] = true;
}
//disable selected block
if ( settingsState[ key ] ) {
//return if toggled and already enabled
if ( all && ! toggle ) {
settingsState[ key ] = false;
} else {
unregisterBlockType( key );
}
} else {
//return if toggled and already disabled
if ( all && toggle ) {
settingsState[ key ] = true;
} else {
{ map( this.props.allBlocks[ category ].blocks, ( block ) => {
if ( block.name === key ) {
registerBlockType( key, block );
//change toggle off when block enabled
if ( settingsState[ 'mainCategory-' + category ] ) {
settingsState[ 'mainCategory-' + category ] = false;
}
}
} ); }
WPCOM_UNSUPPORTED_CORE_BLOCKS.forEach( blockName => unregisterBlockType( blockName ) );