import { DOMNode, Element } from 'html-react-parser'; import { HeadlessConfig } from '../types.js'; export type isAnchorTagOptions = { /** * If true, will check if the anchor tag contains a valid internal link. * * if target="_blank" then this option is not taken into account */ isInternalLink?: boolean; }; /** * Checks if the node is an Element. * * We rely on this function to avoid issues with instanceof. * * @see https://github.com/10up/headstartwp/issues/504 * * @param node The dom node * * @returns Whether the node is of type element or not */ export declare function isElement(node: DOMNode): node is Element; /** * A small helper function that should probably be removed * * @param attribs The attributes of the element * * @internal * * @returns */ export declare function getAttributes(attribs: Element['attribs']): Record; /** * Checks if the provided node is an valid anchor tag * * This function expects to be used with `DOMNode` objects from `html-react-parser`, which is * the underlying parser used by {@link BlocksRenderer}. * * #### Usage * * ```tsx * import { isAnchorTag } from '@headstartwp/core'; * import { LinkBlock } from '@10up/headless-next'; * * * isAnchorTag(node, { isInternalLink: true})} /> * * ``` * * @param node The node to test * @param options Supported options * * @param site * @category DOM Helpers * * @returns Whether it's an anchor tag according to the options passed */ export declare function isAnchorTag(node: DOMNode, options?: isAnchorTagOptions, site?: HeadlessConfig | undefined): node is Element; export type isImageTagOptions = { /** * If true, will check if the image tag contains width and height attributes */ hasDimensions?: boolean; }; /** * Checks if the provided node is an valid image tag * * This function expects to be used with `DOMNode` objects from `html-react-parser`, which is * the underlying parser used by {@link BlocksRenderer}. * * #### Usage * * ```tsx * import { isImageTag, ImageBlock } from '@headstartwp/core'; * import { ImageComponent } from '@10up/headless-next'; * * * isImageTag(node, { hasDimensions: true})} * component={ImageComponent} * /> * * ``` * * @param node The node to test * @param options Supported options. * * @category DOM Helpers * * @returns Whether it's an image tag or not according to the options passed */ export declare function isImageTag(node: DOMNode, options?: isImageTagOptions): string | boolean; export declare const youtubeEmbedRegex: RegExp; /** * Checks if the node is an youtube embed * * This function expects to be used with `DOMNode` objects from `html-react-parser`, which is * the underlying parser used by {@link BlocksRenderer}. * * #### Usage * * ```tsx * import { isYoutubeEmbed } from '@headstartwp/core'; * * * * * ``` * * @param node The node to test * * @category DOM Helpers * * @returns true if the node is a youtube embed */ export declare function isYoutubeEmbed(node: DOMNode): boolean; /** * Checks if the node is an twitter embed * * This function expects to be used with `DOMNode` objects from `html-react-parser`, which is * the underlying parser used by {@link BlocksRenderer}. * * #### Usage * * ```tsx * import { isTwitterEmbed } from '@headstartwp/core'; * * * * * ``` * * @param node The node to test * * @category DOM Helpers * * @returns true if the node is a twitter embed */ export declare function isTwitterEmbed(node: DOMNode): boolean; export type isBlockOptions = { /** * The tagName to check for */ tagName?: string; /** * A single or array of classNames to check for * * If an array of class names is passed, * the block will be considered valid if all of the class names are found */ className?: string | string[]; }; /** * Tests a node by tagName and/or className * * This function expects to be used with `DOMNode` objects from `html-react-parser`, which is * the underlying parser used by {@link BlocksRenderer}. * * #### Usage * * ```tsx * import { isBlock } from '@headstartwp/core'; * * * isBlock(node, { tagName: 'div', classList: ['block-class-name'] })} * /> * * ``` * * @param node The node to test * * @param _options * @category DOM Helpers * * @returns true if the node passes the test */ export declare function isBlock(node: DOMNode, _options: isBlockOptions): boolean; /** * Tests a node by block name. This requires the Headless WP Plugin to be installed. * * The Headless WP Plugin will append `data-wp-block-name` and `data-wp-block` to every block, * this function relies on those attributes to determine if the node is a block. * * This function expects to be used with `DOMNode` objects from `html-react-parser`, which is * the underlying parser used by {@link BlocksRenderer}. * * #### Usage * * ```tsx * import { isBlockByName } from '@headstartwp/core'; * * * isBlock(node, 'core/paragraph')} * /> * * ``` * * @param node The node to test * @param name The block name * * @category DOM Helpers * * @returns true if the node passes the test */ export declare function isBlockByName(node: DOMNode, name: string): boolean; export * from './wpKsesPost.js'; export * from './stripTags.js'; export * from './parseBlockAttributes.js';