How to use the @wordpress/blocks.getDefaultBlockName 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 WordPress / gutenberg / packages / editor / src / store / selectors.js View on Github external
}

		// 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 );
}
github WordPress / gutenberg / editor / hooks / default-autocompleters.js View on Github external
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;
}
github WordPress / gutenberg / packages / block-editor / src / components / inserter-with-shortcuts / index.js View on Github external
const itemsWithoutDefaultBlock = filter( items, ( item ) => {
		return ! item.isDisabled && (
			item.name !== getDefaultBlockName() ||
			! isEmpty( item.initialAttributes )
		);
	} ).slice( 0, 3 );
github WordPress / gutenberg / packages / editor / src / components / block-list / layout.js View on Github external
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 ) => {
github WordPress / gutenberg / packages / block-editor / src / store / actions.js View on Github external
export function insertDefaultBlock( attributes, rootClientId, index ) {
	const block = createBlock( getDefaultBlockName(), attributes );

	return insertBlock( block, index, rootClientId );
}
github WordPress / gutenberg / editor / components / inserter-with-shortcuts / index.js View on Github external
const itemsWithoutDefaultBlock = filter( items, ( item ) =>
		item.name !== getDefaultBlockName() || ! isEmpty( item.initialAttributes )
	).slice( 0, 3 );
github WordPress / gutenberg / packages / block-editor / src / components / default-block-appender / index.js View on Github external
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 ) => {
github front / gutenberg-js / src / js / gutenberg-overrides / packages / editor / build-module / store / actions.js View on Github external
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',
  };
};
github WordPress / gutenberg / packages / block-library / src / more / edit.js View on Github external
onKeyDown( event ) {
		const { keyCode } = event;
		const { insertBlocksAfter } = this.props;
		if ( keyCode === ENTER ) {
			insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] );
		}
	}