@wordpress/blocks
Version:
Block API for WordPress.
121 lines • 4.83 kB
TypeScript
import type { Block, BlockType, BlockTypeIcon, BlockTypeIconDescriptor, BlockAttribute } from '../types';
/**
* Determines whether the block's attributes are equal to the default attributes
* which means the block is unmodified.
*
* @param block Block Object.
* @param role Optional role to filter attributes for modification check.
*
* @return Whether the block is an unmodified block.
*/
export declare function isUnmodifiedBlock(block: Block, role?: string): boolean;
/**
* Determines whether the block is a default block and its attributes are equal
* to the default attributes which means the block is unmodified.
*
* @param block Block Object
* @param role Optional role to filter attributes for modification check.
*
* @return Whether the block is an unmodified default block.
*/
export declare function isUnmodifiedDefaultBlock(block: Block, role?: string): boolean;
/**
* Function that checks if the parameter is a valid icon.
*
* @param icon Parameter to be checked.
*
* @return True if the parameter is a valid icon and false otherwise.
*/
export declare function isValidIcon(icon: unknown): boolean;
/**
* Function that receives an icon as set by the blocks during the registration
* and returns a new icon object that is normalized so we can rely on just on possible icon structure
* in the codebase.
*
* @param icon Render behavior of a block type icon;
* one of a Dashicon slug, an element, or a component.
*
* @return Object describing the icon.
*/
export declare function normalizeIconObject(icon: BlockTypeIcon | undefined): BlockTypeIconDescriptor;
/**
* Normalizes block type passed as param. When string is passed then
* it converts it to the matching block type object.
* It passes the original object otherwise.
*
* @param blockTypeOrName Block type or name.
*
* @return Block type.
*/
export declare function normalizeBlockType(blockTypeOrName: string | BlockType): BlockType | undefined;
/**
* Get the label for the block, usually this is either the block title,
* or the value of the block's `label` function when that's specified.
*
* @param blockType The block type.
* @param attributes The values of the block's attributes.
* @param context The intended use for the label.
*
* @return The block label.
*/
export declare function getBlockLabel(blockType: BlockType, attributes: Record<string, unknown>, context?: string): string;
/**
* Get a label for the block for use by screenreaders, this is more descriptive
* than the visual label and includes the block title and the value of the
* `getLabel` function if it's specified.
*
* @param blockType The block type.
* @param attributes The values of the block's attributes.
* @param position The position of the block in the block list.
* @param direction The direction of the block layout.
*
* @return The block label.
*/
export declare function getAccessibleBlockLabel(blockType: BlockType | undefined | null, attributes: Record<string, unknown>, position?: number, direction?: string): string;
export declare function getDefault(attributeSchema: BlockAttribute): unknown;
/**
* Check if a block is registered.
*
* @param name The block's name.
*
* @return Whether the block is registered.
*/
export declare function isBlockRegistered(name: string): boolean;
/**
* Ensure attributes contains only values defined by block type, and merge
* default values for missing attributes.
*
* @param name The block's name.
* @param attributes The block's attributes.
* @return The sanitized attributes.
*/
export declare function __experimentalSanitizeBlockAttributes(name: string, attributes: Record<string, unknown>): Record<string, unknown>;
/**
* Filter block attributes by `role` and return their names.
*
* @param name Block attribute's name.
* @param role The role of a block attribute.
*
* @return The attribute names that have the provided role.
*/
export declare function getBlockAttributesNamesByRole(name: string, role?: string): string[];
export declare const __experimentalGetBlockAttributesNamesByRole: (...args: Parameters<typeof getBlockAttributesNamesByRole>) => string[];
/**
* Checks if a block is a content block by examining its attributes.
* A block is considered a content block if it has at least one attribute
* with a role of 'content'.
*
* @param name The name of the block to check.
* @return Whether the block is a content block.
*/
export declare function isContentBlock(name: string): boolean;
/**
* Return a new object with the specified keys omitted.
*
* @param object Original object.
* @param keys Keys to be omitted.
*
* @return Object with omitted keys.
*/
export declare function omit<T extends Record<string, unknown>>(object: T, keys: string | string[]): T;
//# sourceMappingURL=utils.d.ts.map