@wordpress/blocks
Version:
Block API for WordPress.
126 lines • 4.82 kB
TypeScript
import type { Block, BlockType, BlockTransform } from '../types';
/**
* Returns a block object given its type and attributes.
*
* @param name Block name.
* @param attributes Block attributes.
* @param innerBlocks Nested blocks.
*
* @return Block object.
*/
export declare function createBlock(name: string, attributes?: Record<string, unknown>, innerBlocks?: Block[]): Block;
/**
* Given an array of InnerBlocks templates or Block Objects,
* returns an array of created Blocks from them.
* It handles the case of having InnerBlocks as Blocks by
* converting them to the proper format to continue recursively.
*
* @param innerBlocksOrTemplate Nested blocks or InnerBlocks templates.
*
* @return Array of Block objects.
*/
export declare function createBlocksFromInnerBlocksTemplate(innerBlocksOrTemplate?: Array<Block | [string, Record<string, unknown>?, Array<unknown>?]>): Block[];
/**
* Given a block object, returns a copy of the block object while sanitizing its attributes,
* optionally merging new attributes and/or replacing its inner blocks.
*
* @param block Block instance.
* @param mergeAttributes Block attributes.
* @param newInnerBlocks Nested blocks.
*
* @return A cloned block.
*/
export declare function __experimentalCloneSanitizedBlock(block: Block, mergeAttributes?: Record<string, unknown>, newInnerBlocks?: Block[]): Block;
/**
* Given a block object, returns a copy of the block object,
* optionally merging new attributes and/or replacing its inner blocks.
*
* @param block Block instance.
* @param mergeAttributes Block attributes.
* @param newInnerBlocks Nested blocks.
*
* @return A cloned block.
*/
export declare function cloneBlock(block: Block, mergeAttributes?: Record<string, unknown>, newInnerBlocks?: Block[]): Block;
/**
* Determines whether transform is a "block" type
* and if so whether it is a "wildcard" transform
* ie: targets "any" block type
*
* @param t the Block transform object
*
* @return whether transform is a wildcard transform
*/
export declare const isWildcardBlockTransform: (t: BlockTransform | null | undefined) => boolean;
/**
* Determines whether the given Block is the core Block which
* acts as a container Block for other Blocks as part of the
* Grouping mechanics
*
* @param name the name of the Block to test against
*
* @return whether or not the Block is the container Block type
*/
export declare const isContainerGroupBlock: (name: string) => boolean;
/**
* Returns an array of block types that the set of blocks received as argument
* can be transformed into.
*
* @param blocks Blocks array.
*
* @return Block types that the blocks argument can be transformed to.
*/
export declare function getPossibleBlockTransformations(blocks: Block[]): BlockType[];
/**
* Given an array of transforms, returns the highest-priority transform where
* the predicate function returns a truthy value. A higher-priority transform
* is one with a lower priority value (i.e. first in priority order). Returns
* null if the transforms set is empty or the predicate function returns a
* falsey value for all entries.
*
* @param transforms Transforms to search.
* @param predicate Function returning true on matching transform.
*
* @return Highest-priority transform candidate.
*/
export declare function findTransform(transforms: BlockTransform[], predicate: (transform: BlockTransform) => boolean): BlockTransform | null;
/**
* Returns normal block transforms for a given transform direction, optionally
* for a specific block by name, or an empty array if there are no transforms.
* If no block name is provided, returns transforms for all blocks. A normal
* transform object includes `blockName` as a property.
*
* @param direction Transform direction ("to", "from").
* @param blockTypeOrName Block type or name.
*
* @return Block transforms for direction.
*/
export declare function getBlockTransforms(direction: 'to' | 'from', blockTypeOrName?: string | BlockType): BlockTransform[];
/**
* Switch one or more blocks into one or more blocks of the new block type.
*
* @param blocks Blocks array or block object.
* @param name Block name.
*
* @return Array of blocks or null.
*/
export declare function switchToBlockType(blocks: Block[] | Block, name: string): Block[] | null;
/**
* Create a block object from the example API.
*
* @param name
* @param example
*
* @return block.
*/
type BlockExample = {
attributes?: Record<string, unknown>;
innerBlocks?: Array<{
name: string;
attributes?: Record<string, unknown>;
innerBlocks?: BlockExample['innerBlocks'];
}>;
};
export declare const getBlockFromExample: (name: string, example: BlockExample) => Block;
export {};
//# sourceMappingURL=factory.d.ts.map