UNPKG

phx-react

Version:

PHX REACT

144 lines (143 loc) 5.16 kB
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedEditor, SerializedLexicalNode, Spread } from 'lexical'; import { DecoratorNode } from 'lexical'; import * as React from 'react'; export type Position = 'left' | 'right' | 'full' | 'center' | undefined; export interface InlineImagePayload { altText: string; caption?: LexicalEditor; height?: number; key?: NodeKey; showCaption?: boolean; src: string; width?: number; position?: Position; } export interface UpdateInlineImagePayload { altText?: string; showCaption?: boolean; position?: Position; } export type SerializedInlineImageNode = Spread<{ altText: string; caption: SerializedEditor; height?: number; showCaption: boolean; src: string; width?: number; position?: Position; }, SerializedLexicalNode>; export declare class InlineImageNode extends DecoratorNode<React.JSX.Element> { __src: string; __altText: string; __width: 'inherit' | number; __height: 'inherit' | number; __showCaption: boolean; __caption: LexicalEditor; __position: Position; /** * Gets the Lexical node type for inline image nodes. * @returns Inline image node type. */ static getType(): string; /** * Clones an existing inline image node. * @param node Inline image node to clone. * @returns Cloned inline image node. */ static clone(node: InlineImageNode): InlineImageNode; /** * Imports a serialized inline image node into the editor state. * @param serializedNode Serialized inline image node payload. * @returns Hydrated inline image node. */ static importJSON(serializedNode: SerializedInlineImageNode): InlineImageNode; /** * Defines DOM import conversions for inline image elements. * @returns DOM conversion map for inline image imports. */ static importDOM(): DOMConversionMap | null; /** * Creates an inline image node instance. * @param src Image source URL. * @param altText Accessible alt text. * @param position Inline image alignment position. * @param width Initial image width. * @param height Initial image height. * @param showCaption Whether the caption editor is visible. * @param caption Nested caption editor. * @param key Optional Lexical node key. */ constructor(src: string, altText: string, position: Position, width?: 'inherit' | number, height?: 'inherit' | number, showCaption?: boolean, caption?: LexicalEditor, key?: NodeKey); /** * Exports this inline image node to DOM. * @returns DOM export output containing the inline image wrapper. */ exportDOM(): DOMExportOutput; /** * Serializes this inline image node. * @returns Serialized inline image node payload. */ exportJSON(): SerializedInlineImageNode; /** * Gets the image source URL. * @returns Image source URL. */ getSrc(): string; /** * Gets the image alt text. * @returns Image alt text. */ getAltText(): string; /** * Gets whether the caption editor is visible. * @returns True when caption is shown. */ getShowCaption(): boolean; /** * Gets the current inline image alignment position. * @returns Current inline image position. */ getPosition(): Position; /** * Updates the stored image dimensions. * @param width Next image width. * @param height Next image height. */ setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void; /** * Updates mutable inline image fields. * @param payload Partial inline image update payload. */ update(payload: UpdateInlineImagePayload): void; /** * Creates the DOM wrapper for this inline image node. * @param config Lexical editor config. * @returns Inline image wrapper element. */ createDOM(config: EditorConfig): HTMLElement; /** * Updates the DOM wrapper when node state changes. * @param prevNode Previous inline image node state. * @param dom Existing inline image wrapper element. * @param config Lexical editor config. * @returns False because the existing DOM element is reused. */ updateDOM(prevNode: InlineImageNode, dom: HTMLElement, config: EditorConfig): false; /** * Renders the React decorator for this inline image node. * @returns Inline image decorator element. */ decorate(): React.JSX.Element; } /** * Creates and inserts a replacement inline image node. * @param payload Inline image node creation payload. * @returns Created inline image node. */ export declare function $createInlineImageNode({ altText, caption, height, key, position, showCaption, src, width, }: InlineImagePayload): InlineImageNode; /** * Checks whether a Lexical node is an InlineImageNode. * @param node Node to test. * @returns True when the node is an InlineImageNode. */ export declare function $isInlineImageNode(node: LexicalNode | null | undefined): node is InlineImageNode;