@wordpress/blocks
Version:
Block API for WordPress.
96 lines • 3.92 kB
TypeScript
import type { BlockAttribute, BlockType } from '../../types';
/**
* Higher-order hpq matcher which enhances an attribute matcher to return true
* or false depending on whether the original matcher returns undefined. This
* is useful for boolean attributes (e.g. disabled) whose attribute values may
* be technically falsey (empty string), though their mere presence should be
* enough to infer as true.
*
* @param matcher Original hpq matcher.
*
* @return Enhanced hpq matcher.
*/
export declare const toBooleanAttributeMatcher: (matcher: (value: unknown) => unknown) => (value: unknown) => boolean;
/**
* Returns true if value is of the given JSON schema type, or false otherwise.
*
* @see http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.25
*
* @param value Value to test.
* @param type Type to test.
*
* @return Whether value is of type.
*/
export declare function isOfType(value: unknown, type: string): boolean;
/**
* Returns true if value is of an array of given JSON schema types, or false
* otherwise.
*
* @see http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.25
*
* @param value Value to test.
* @param types Types to test.
*
* @return Whether value is of types.
*/
export declare function isOfTypes(value: unknown, types: string[]): boolean;
/**
* Given an attribute key, an attribute's schema, a block's raw content and the
* commentAttributes returns the attribute value depending on its source
* definition of the given attribute key.
*
* @param attributeKey Attribute key.
* @param attributeSchema Attribute's schema.
* @param innerDOM Parsed DOM of block's inner HTML.
* @param commentAttributes Block's comment attributes.
* @param innerHTML Raw HTML from block node's innerHTML property.
*
* @return Attribute value.
*/
export declare function getBlockAttribute(attributeKey: string, attributeSchema: BlockAttribute, innerDOM: Node, commentAttributes: Record<string, unknown>, innerHTML: string | Node): unknown;
/**
* Returns true if value is valid per the given block attribute schema type
* definition, or false otherwise.
*
* @see https://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.1
*
* @param value Value to test.
* @param type Block attribute schema type.
*
* @return Whether value is valid.
*/
export declare function isValidByType(value: unknown, type: string | string[] | undefined): boolean;
/**
* Returns true if value is valid per the given block attribute schema enum
* definition, or false otherwise.
*
* @see https://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.2
*
* @param value Value to test.
* @param enumSet Block attribute schema enum.
*
* @return Whether value is valid.
*/
export declare function isValidByEnum(value: unknown, enumSet: unknown[] | undefined): boolean;
export declare const matcherFromSource: ((sourceConfig: BlockAttribute) => ((domNode: Element) => unknown) | undefined) & import("memize").MemizeMemoizedFunction;
/**
* Given a block's raw content and an attribute's schema returns the attribute's
* value depending on its source.
*
* @param innerHTML Block's raw content.
* @param attributeSchema Attribute's schema.
*
* @return Attribute value.
*/
export declare function parseWithAttributeSchema(innerHTML: string | Node, attributeSchema: BlockAttribute): unknown;
/**
* Returns the block attributes of a registered block node given its type.
*
* @param blockTypeOrName Block type or name.
* @param innerHTML Raw block content.
* @param attributes Known block attributes (from delimiters).
*
* @return All block attributes.
*/
export declare function getBlockAttributes(blockTypeOrName: string | BlockType, innerHTML: string | Node, attributes?: Record<string, unknown>): Record<string, unknown>;
//# sourceMappingURL=get-block-attributes.d.ts.map