Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// There are two conditions under which the optimization cannot be
// assumed, and a fallthrough to getEditedPostContent must occur:
//
// 1. getBlocksForSerialization has special treatment in omitting a
// single unmodified default block.
// 2. Comment delimiters are omitted for a freeform or unregistered
// block in its serialization. The freeform block specifically may
// produce an empty string in its saved output.
//
// For all other content, the single block is assumed to make a post
// non-empty, if only by virtue of its own comment delimiters.
const blockName = blocks[ 0 ].name;
if (
blockName !== getDefaultBlockName() &&
blockName !== getFreeformContentHandlerName()
) {
return false;
}
}
return ! getEditedPostContent( state );
}
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 reusable 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.
*/
fetchReusableBlocks();
}
}
return completers;
}
const itemsWithoutDefaultBlock = filter( items, ( item ) => {
return ! item.isDisabled && (
item.name !== getDefaultBlockName() ||
! isEmpty( item.initialAttributes )
);
} ).slice( 0, 3 );
isSelectionEnabled,
isMultiSelecting,
getMultiSelectedBlocksStartClientId,
getMultiSelectedBlocksEndClientId,
getBlockSelectionStart,
canInsertBlockType,
} = select( 'core/editor' );
const { rootClientId } = ownProps;
return {
selectionStart: getMultiSelectedBlocksStartClientId(),
selectionEnd: getMultiSelectedBlocksEndClientId(),
selectionStartClientId: getBlockSelectionStart(),
isSelectionEnabled: isSelectionEnabled(),
isMultiSelecting: isMultiSelecting(),
canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootClientId ),
};
} ),
withDispatch( ( dispatch ) => {
export function insertDefaultBlock( attributes, rootClientId, index ) {
const block = createBlock( getDefaultBlockName(), attributes );
return insertBlock( block, index, rootClientId );
}
const itemsWithoutDefaultBlock = filter( items, ( item ) =>
item.name !== getDefaultBlockName() || ! isEmpty( item.initialAttributes )
).slice( 0, 3 );
withSelect( ( select, ownProps ) => {
const { getBlockCount, getBlockName, isBlockValid, getSettings, getTemplateLock } = select( 'core/block-editor' );
const isEmpty = ! getBlockCount( ownProps.rootClientId );
const isLastBlockDefault = getBlockName( ownProps.lastBlockClientId ) === getDefaultBlockName();
const isLastBlockValid = isBlockValid( ownProps.lastBlockClientId );
const { bodyPlaceholder } = getSettings();
return {
isVisible: isEmpty || ! isLastBlockDefault || ! isLastBlockValid,
showPrompt: isEmpty,
isLocked: !! getTemplateLock( ownProps.rootClientId ),
placeholder: bodyPlaceholder,
};
} ),
withDispatch( ( dispatch, ownProps ) => {
others.insertDefaultBlock = (attributes, rootClientId, index) => {
const blockName = rootClientId === undefined ? getDefaultBlockName() : 'core/paragraph';
const block = createBlock(blockName, attributes);
return {
...insertBlock(block, index, rootClientId),
isProvisional: blockName === 'core/paragraph',
};
};
onKeyDown( event ) {
const { keyCode } = event;
const { insertBlocksAfter } = this.props;
if ( keyCode === ENTER ) {
insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] );
}
}