onKeyDown( event ) { const { keyCode } = event; const { insertBlocksAfter } = this.props; if ( keyCode === ENTER ) { insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] ); } }
export function insertDefaultBlock( attributes, rootUID, index ) { const block = createBlock( getDefaultBlockName(), attributes ); return { ...insertBlock( block, index, rootUID ), isProvisional: true, }; }
withSelect( ( select, ownProps ) => { const { getBlockCount, getBlock, getEditorSettings, getTemplateLock } = select( 'core/editor' ); const { isTipVisible } = select( 'core/nux' ); const isEmpty = ! getBlockCount( ownProps.rootClientId ); const lastBlock = getBlock( ownProps.lastBlockClientId ); const isLastBlockDefault = get( lastBlock, [ 'name' ] ) === getDefaultBlockName(); const { bodyPlaceholder } = getEditorSettings(); return { isVisible: isEmpty || ! isLastBlockDefault, showPrompt: isEmpty, isLocked: !! getTemplateLock( ownProps.rootClientId ), placeholder: bodyPlaceholder, hasTip: isTipVisible( 'core/editor.inserter' ), }; } ),
function setDefaultCompleters( completers, blockName ) { if ( ! completers ) { // Provide copies so filters may directly modify them. completers = defaultAutocompleters.map( clone ); // Add blocks autocompleter for Paragraph block if ( blockName === getDefaultBlockName() ) { completers.push( clone( blockAutocompleter ) ); /* * NOTE: This is a hack to help ensure shared blocks are loaded * so they may be included in the block completer. It can be removed * once we have a way for completers to Promise options while * store-based data dependencies are being resolved. */ fetchSharedBlocks(); } } return completers; }
const itemsWithoutDefaultBlock = filter( items, ( item ) => item.name !== getDefaultBlockName() || ! isEmpty( item.initialAttributes )