UNPKG

react-email-builder

Version:
80 lines (79 loc) 2.51 kB
import type { EmailBuilderBlock, EmailBuilderConfig, EmailBuilderState } from '../types'; export type TagAttributes = Record<string, string | null | undefined>; export type ReplaceVariableFn = (key: string, placeholder: string) => string; export interface RenderTagOptions { /** * The attributes to add. Can be a object or an array of attributes. * Any non-string value will skipped. */ attrs?: TagAttributes; /** * Specify the children of the tag. */ children?: string | string[]; } export interface GenerateOptions { /** * The email builder config. */ config: EmailBuilderConfig; /** * The email builder state. */ state: EmailBuilderState; /** * Extra MJML tags to add as the children of the `<mj-head>` tag. */ extraHeadTags?: string[]; /** * Specify the function to replace the variables in the code. */ replaceVariable?: ReplaceVariableFn; } /** * Render MJML tag. * * @param tagName The tag name. i.e. `mj-image`. * @param options The render options. * @returns The rendered string. */ export declare function renderTag(tagName: string, options?: RenderTagOptions): string; /** * Add `px` suffix to the value. If the value is `null` or `undefined`, * returns `null`. */ export declare function px(value?: number | null): string | null; /** * Normalize the color value. */ export declare function color(value?: string | null): string | null; /** * Render padding array. * * @example * * // '10px 20px 10px 20px' * padding([10, 20, 10, 20]) */ export declare function padding(value?: (number | null | undefined)[] | null): string | null; /** * Combines multiple arrays of strings into a single string, with each string * in the arrays separated by newlines. Null or undefined inputs are ignored. */ export declare function lines(...text: (string[] | null | undefined)[]): string; /** * Create block attrs and merge the extra attrs into it. */ export declare function createBlockAttrs(block: EmailBuilderBlock, extra?: TagAttributes): TagAttributes; /** * Generate MJML code from EmailBuilderState. */ export declare function generateMJML(options: GenerateOptions): string; /** * Render the block to MJML code. */ export declare function renderBlock(block: EmailBuilderBlock, options: GenerateOptions): string; /** * Replace variables in the html code. */ export declare function replaceHtmlVariables(html?: string, replace?: ReplaceVariableFn): string | undefined;