UNPKG

lakelib

Version:

Lake is a rich text editor built for modern applications that require content creation like blog posts, user comments, and email composition.

1,778 lines (1,745 loc) 64 kB
import EventEmitter from 'eventemitter3'; import { LocalizedString } from 'typesafe-i18n'; type KeyValue = Record<string, string>; type ContentStyleValue = string | string[] | RegExp; type ContentStyle = Record<string, ContentStyleValue>; type ContentAttributeValue = string | string[] | RegExp | ContentStyle; type ContentAttribute = Record<string, ContentAttributeValue>; type ContentRules = Record<string, string | ContentAttribute>; interface EventItem { type: string; listener: EventListener; } /** * The Nodes interface represents a collection of the nodes. * It is similar to jQuery, but its implementation is much simpler. * Its methods can be considered aliases of native DOM interfaces, designed to simplify DOM manipulation. */ declare class Nodes { /** * A list of native nodes. */ private readonly nodeList; /** * The number of nodes in the Nodes object. */ readonly length: number; constructor(node?: Node | Node[] | null); /** * The unique ID of the first node. */ get id(): number; /** * The name of the first node. */ get name(): string; /** * A boolean value indicating whether the first node is an element. */ get isElement(): boolean; /** * A boolean value indicating whether the first node is a text. */ get isText(): boolean; /** * A boolean value indicating whether the first node is a block. */ get isBlock(): boolean; /** * A boolean value indicating whether the first node is a mark. */ get isMark(): boolean; /** * A boolean value indicating whether the first node is a void element that cannot have any child nodes. */ get isVoid(): boolean; /** * A boolean value indicating whether the first node is a heading. */ get isHeading(): boolean; /** * A boolean value indicating whether the first node is a list. */ get isList(): boolean; /** * A boolean value indicating whether the first node is a table. */ get isTable(): boolean; /** * A boolean value indicating whether the first node is a bookmark element. */ get isBookmark(): boolean; /** * A boolean value indicating whether the first node is a box element. */ get isBox(): boolean; /** * A boolean value indicating whether the first node is an inline box element. */ get isInlineBox(): boolean; /** * A boolean value indicating whether the first node is a block box element. */ get isBlockBox(): boolean; /** * A boolean value indicating whether the first node is a contenteditable element where users can edit the content. */ get isContainer(): boolean; /** * A boolean value indicating whether the first node does not have an ancestor element which contenteditable attribute is true. */ get isOutside(): boolean; /** * A boolean value indicating whether the first node has an ancestor element which contenteditable attribute is true. */ get isInside(): boolean; /** * A boolean value indicating whether the first node's parent element is an element which contenteditable attribute is true. */ get isTopInside(): boolean; /** * A boolean value indicating whether the first node is editable. */ get isContentEditable(): boolean; /** * A boolean value indicating whether the first node is indivisible. */ get isIndivisible(): boolean; /** * A boolean value indicating whether the first node is empty. */ get isEmpty(): boolean; /** * Returns a native node at the specified index. */ get(index: number): Node; /** * Returns all native nodes. */ getAll(): Node[]; /** * Returns a new Nodes object that includes only the node at the specified index. */ eq(index: number): Nodes; /** * Executes a provided function once for each node. */ each(callback: (node: Node, index: number) => boolean | void): this; /** * Executes a provided function once for each element. */ eachElement(callback: (element: Element, index: number) => boolean | void): this; /** * Returns a new Nodes object with the nodes in reversed order. */ reverse(): Nodes; /** * Tests whether the first node would be selected by the specified CSS selector. */ matches(selector: string): boolean; /** * Returns a boolean value indicating whether the given node is a descendant of the first node, * that is the node itself, one of its direct children (childNodes), one of the children's direct children, and so on. */ contains(otherNode: Nodes): boolean; /** * Returns a boolean value indicating whether the first node and a given node are siblings. */ isSibling(otherNode: Nodes): boolean; /** * Returns the descendants of the first node that match the specified CSS selector or node path. */ find(selector: string | NodePath): Nodes; /** * Traverses the first node and its parents (heading toward the document root) until it finds an element that matches the specified CSS selector. */ closest(selector: string): Nodes; /** * Traverses the first node and its parents until it finds a block element. */ closestBlock(): Nodes; /** * Traverses the first node and its parents until it finds an operable block. */ closestOperableBlock(): Nodes; /** * Traverses the first node and its parents until it finds a div element which contenteditable attribute is true. */ closestContainer(): Nodes; /** * Traverses the first node and its parents until it finds an element which can scroll. */ closestScroller(): Nodes; /** * Returns the parent of the first node. */ parent(): Nodes; /** * Returns the immediately preceding sibling of the first node. */ prev(): Nodes; /** * Returns the immediately following sibling of the first node. */ next(): Nodes; /** * Returns the first child of the first node. */ first(): Nodes; /** * Returns the last child of the first node. */ last(): Nodes; /** * Returns a number indicating the position of the first node relative to its sibling nodes. */ index(): number; /** * Returns the path of the first node. */ path(): NodePath; /** * Returns a list which contains all of the child nodes of the first node. */ children(): Nodes[]; /** * Returns a generator that iterates over the descendants of the first node. */ getWalker(): Generator<Nodes>; /** * Sets up an event listener for each element. */ on(type: string, listener: EventListener): this; /** * Removes event listeners previously registered with on() method. */ off(type?: string, listener?: EventListener): this; /** * Executes all event listeners attached to all nodes for the given event type. */ emit(type: string, event?: Event): this; /** * Returns all event listeners attached to the node at the specified index. */ getEventListeners(index: number): EventItem[]; /** * Sets focus on the specified node, if it can be focused. */ focus(): this; /** * Removes focus from the specified node. */ blur(): this; /** * Returns a copy of the first node. If deep is true, the copy also includes the node's descendants. */ clone(deep?: boolean): Nodes; /** * Returns a boolean value indicating whether the first node has the specified attribute or not. */ hasAttr(attributeName: string): boolean; /** * Returns the value of the specified attribute from the first node, or sets the values of attributes for all elements. */ attr(attributeName: string): string; attr(attributeName: string, value: string): this; attr(attributeName: KeyValue): this; /** * Removes the attribute with the specified name from every element. */ removeAttr(attributeName: string): this; /** * Returns a boolean value indicating whether the first node has the specified class or not. */ hasClass(className: string): boolean; /** * Adds the given class to every element. */ addClass(className: string | string[]): this; /** * Removes the given class from every element. */ removeClass(className: string | string[]): this; /** * Returns the value of the given CSS property of the first node, * after applying active stylesheets and resolving any basic computation this value may contain. */ computedCSS(propertyName: string): string; /** * Returns the value of the given CSS property of the first node, or sets the values of CSS properties for all elements. */ css(propertyName: string): string; css(propertyName: KeyValue): this; css(propertyName: string, value: string): this; /** * Returns the width of of the first node. */ width(): number; /** * Returns the interior width of the first node, which does not include padding. */ innerWidth(): number; /** * Returns the height of of the first node. */ height(): number; /** * Displays all nodes. */ show(displayType?: string): this; /** * Hides all nodes. */ hide(): this; /** * Returns the HTML string contained within the first node, or sets the HTML string for all elements. */ html(): string; html(value: string): this; /** * Returns the rendered text content of the first node, or sets the rendered text content for all elements. */ text(): string; text(value: string): this; /** * Returns the value of the first node, which must be an input element, or sets the value for all input elements. */ value(): string; value(value: string): this; /** * Returns the HTML string describing the first node including its descendants. */ outerHTML(): string; /** * Removes all child nodes for each element. */ empty(): this; /** * Inserts the specified content just inside the first node, before its first child. */ prepend(content: string | Node | DocumentFragment | Nodes): this; /** * Inserts the specified content just inside the first node, after its last child. */ append(content: string | Node | DocumentFragment | Nodes): this; /** * Inserts the specified content before the first node. */ before(content: string | Node | DocumentFragment | Nodes): this; /** * Inserts the specified content after the first node. */ after(content: string | Node | DocumentFragment | Nodes): this; /** * Replaces the first node with the given new content. */ replaceWith(newContent: string | Node | Nodes): this; /** * Removes all nodes from the DOM. */ remove(keepChildren?: boolean): this; /** * Splits the first node, which must be a text node, into two nodes at the specified offset, keeping both as siblings in the tree. */ splitText(offset: number): Nodes; /** * Returns information about the first node, which is used for debugging. */ toString(): string; /** * Prints information about the first node, which is used for debugging. */ info(): void; } interface TwoParts { start: Nodes | null; end: Nodes | null; } interface ThreeParts extends TwoParts { center: Nodes | null; } type NodePath = number[]; interface ActiveItem { node: Nodes; name: string; attributes: KeyValue; styles: KeyValue; } interface SelectionState { activeItems: ActiveItem[]; disabledNameMap?: Map<string, boolean>; selectedNameMap?: Map<string, boolean>; selectedValuesMap?: Map<string, string[]>; } type TranslationFunctions = { toolbar: { /** * Undo (mod+Z) */ undo: () => LocalizedString; /** * Redo (mod+Y) */ redo: () => LocalizedString; /** * Select all (mod+A) */ selectAll: () => LocalizedString; /** * Paragraph */ paragraph: () => LocalizedString; /** * Block quotation */ blockQuote: () => LocalizedString; /** * Numbered list */ numberedList: () => LocalizedString; /** * Bulleted list */ bulletedList: () => LocalizedString; /** * Checklist */ checklist: () => LocalizedString; /** * Align left */ alignLeft: () => LocalizedString; /** * Align center */ alignCenter: () => LocalizedString; /** * Align right */ alignRight: () => LocalizedString; /** * Justify */ alignJustify: () => LocalizedString; /** * Increase indent */ increaseIndent: () => LocalizedString; /** * Decrease indent */ decreaseIndent: () => LocalizedString; /** * Bold (mod+B) */ bold: () => LocalizedString; /** * Italic (mod+I) */ italic: () => LocalizedString; /** * Underline (mod+U) */ underline: () => LocalizedString; /** * Strikethrough */ strikethrough: () => LocalizedString; /** * Superscript */ superscript: () => LocalizedString; /** * Subscript */ subscript: () => LocalizedString; /** * Inline code */ code: () => LocalizedString; /** * Remove format */ removeFormat: () => LocalizedString; /** * Format painter */ formatPainter: () => LocalizedString; /** * Link */ link: () => LocalizedString; /** * Horizontal line */ hr: () => LocalizedString; /** * Video */ video: () => LocalizedString; /** * Code block */ codeBlock: () => LocalizedString; /** * Heading */ heading: () => LocalizedString; /** * Heading 1 */ heading1: () => LocalizedString; /** * Heading 2 */ heading2: () => LocalizedString; /** * Heading 3 */ heading3: () => LocalizedString; /** * Heading 4 */ heading4: () => LocalizedString; /** * Heading 5 */ heading5: () => LocalizedString; /** * Heading 6 */ heading6: () => LocalizedString; /** * List */ list: () => LocalizedString; /** * Table */ table: () => LocalizedString; /** * Alignment */ align: () => LocalizedString; /** * Indent */ indent: () => LocalizedString; /** * Font family */ fontFamily: () => LocalizedString; /** * Font size */ fontSize: () => LocalizedString; /** * More style */ moreStyle: () => LocalizedString; /** * Font color */ fontColor: () => LocalizedString; /** * Highlight */ highlight: () => LocalizedString; /** * Image */ image: () => LocalizedString; /** * File */ file: () => LocalizedString; /** * Emoji */ emoji: () => LocalizedString; /** * Mathematical formula */ equation: () => LocalizedString; /** * X (Twitter) */ twitter: () => LocalizedString; /** * Remove color */ removeColor: () => LocalizedString; }; slash: { /** * Heading 1 */ heading1: () => LocalizedString; /** * Create a heading level 1 */ heading1Desc: () => LocalizedString; /** * Heading 2 */ heading2: () => LocalizedString; /** * Create a heading level 2 */ heading2Desc: () => LocalizedString; /** * Heading 3 */ heading3: () => LocalizedString; /** * Create a heading level 3 */ heading3Desc: () => LocalizedString; /** * Heading 4 */ heading4: () => LocalizedString; /** * Create a heading level 4 */ heading4Desc: () => LocalizedString; /** * Heading 5 */ heading5: () => LocalizedString; /** * Create a heading level 5 */ heading5Desc: () => LocalizedString; /** * Heading 6 */ heading6: () => LocalizedString; /** * Create a heading level 6 */ heading6Desc: () => LocalizedString; /** * Paragraph */ paragraph: () => LocalizedString; /** * Create a paragraph */ paragraphDesc: () => LocalizedString; /** * Block quotation */ blockQuote: () => LocalizedString; /** * Create a block quotation */ blockQuoteDesc: () => LocalizedString; /** * Numbered list */ numberedList: () => LocalizedString; /** * Create a numbered list */ numberedListDesc: () => LocalizedString; /** * Bulleted list */ bulletedList: () => LocalizedString; /** * Create a bulleted list */ bulletedListDesc: () => LocalizedString; /** * Checklist */ checklist: () => LocalizedString; /** * Create a checklist */ checklistDesc: () => LocalizedString; /** * Table */ table: () => LocalizedString; /** * Insert a table */ tableDesc: () => LocalizedString; /** * Info alert */ infoAlert: () => LocalizedString; /** * Create an info alert */ infoAlertDesc: () => LocalizedString; /** * Tip alert */ tipAlert: () => LocalizedString; /** * Create a tip alert */ tipAlertDesc: () => LocalizedString; /** * Warning alert */ warningAlert: () => LocalizedString; /** * Create a warning alert */ warningAlertDesc: () => LocalizedString; /** * Danger alert */ dangerAlert: () => LocalizedString; /** * Create a danger alert */ dangerAlertDesc: () => LocalizedString; /** * Horizontal line */ hr: () => LocalizedString; /** * Insert a horizontal line */ hrDesc: () => LocalizedString; /** * Code block */ codeBlock: () => LocalizedString; /** * Insert a code block */ codeBlockDesc: () => LocalizedString; /** * Video */ video: () => LocalizedString; /** * Insert a video from YouTube */ videoDesc: () => LocalizedString; /** * Mathematical formula */ equation: () => LocalizedString; /** * Insert a TeX expression */ equationDesc: () => LocalizedString; /** * Twitter */ twitter: () => LocalizedString; /** * Insert a post from X (Twitter) */ twitterDesc: () => LocalizedString; /** * Image */ image: () => LocalizedString; /** * Upload an image */ imageDesc: () => LocalizedString; /** * File */ file: () => LocalizedString; /** * Upload a file */ fileDesc: () => LocalizedString; }; link: { /** * New link */ newLink: () => LocalizedString; /** * Link URL */ url: () => LocalizedString; /** * Text to display */ title: () => LocalizedString; /** * Copy link to clipboard */ copy: () => LocalizedString; /** * Open link in new tab */ open: () => LocalizedString; /** * Save */ save: () => LocalizedString; /** * Remove link */ unlink: () => LocalizedString; }; table: { /** * Fit table to page width */ fitTable: () => LocalizedString; /** * Cell background color */ cellBackground: () => LocalizedString; /** * Column */ column: () => LocalizedString; /** * Insert column left */ insertColumnLeft: () => LocalizedString; /** * Insert column right */ insertColumnRight: () => LocalizedString; /** * Delete column */ deleteColumn: () => LocalizedString; /** * Row */ row: () => LocalizedString; /** * Insert row above */ insertRowAbove: () => LocalizedString; /** * Insert row below */ insertRowBelow: () => LocalizedString; /** * Delete row */ deleteRow: () => LocalizedString; /** * Merge cells */ merge: () => LocalizedString; /** * Merge cell up */ mergeUp: () => LocalizedString; /** * Merge cell right */ mergeRight: () => LocalizedString; /** * Merge cell down */ mergeDown: () => LocalizedString; /** * Merge cell left */ mergeLeft: () => LocalizedString; /** * Split cell */ split: () => LocalizedString; /** * Split cell left and right */ splitLeftRight: () => LocalizedString; /** * Split cell top and bottom */ splitTopBottom: () => LocalizedString; /** * Remove table */ remove: () => LocalizedString; }; image: { /** * Full screen */ view: () => LocalizedString; /** * Delete */ remove: () => LocalizedString; /** * Previous */ previous: () => LocalizedString; /** * Next */ next: () => LocalizedString; /** * Close (Esc) */ close: () => LocalizedString; /** * Unable to load image. */ loadingError: () => LocalizedString; /** * Zoom out */ zoomOut: () => LocalizedString; /** * Zoom in */ zoomIn: () => LocalizedString; /** * Alignment */ align: () => LocalizedString; /** * Align left */ alignLeft: () => LocalizedString; /** * Align center */ alignCenter: () => LocalizedString; /** * Align right */ alignRight: () => LocalizedString; /** * Resize image */ resize: () => LocalizedString; /** * Page width */ pageWidth: () => LocalizedString; /** * Original image width */ originalWidth: () => LocalizedString; /** * {0} image width */ imageWidth: (arg0: unknown) => LocalizedString; /** * Open image in new tab */ open: () => LocalizedString; /** * Caption */ caption: () => LocalizedString; /** * Write a caption... */ captionPlaceholder: () => LocalizedString; }; file: { /** * Download */ download: () => LocalizedString; /** * Delete */ remove: () => LocalizedString; }; video: { /** * Embed video */ embed: () => LocalizedString; /** * Delete */ remove: () => LocalizedString; /** * Paste a link to embed a video from YouTube. */ description: () => LocalizedString; /** * Link */ url: () => LocalizedString; /** * Please enter a valid link. */ urlError: () => LocalizedString; }; codeBlock: { /** * Select language */ langType: () => LocalizedString; }; equation: { /** * Done */ save: () => LocalizedString; /** * Supported functions */ help: () => LocalizedString; /** * Type a TeX expression... */ placeholder: () => LocalizedString; }; twitter: { /** * Embed Tweet */ embed: () => LocalizedString; /** * Delete */ remove: () => LocalizedString; /** * Paste a link to embed a post from X. */ description: () => LocalizedString; /** * Link */ url: () => LocalizedString; /** * Please enter a valid link. */ urlError: () => LocalizedString; }; }; type NativeRange = Range; /** * The Range interface represents a fragment of a document that can contain nodes and parts of text nodes. * Its interface is similar to the native Range, with some additional properties and methods specifically designed for more efficient manipulation. */ declare class Range$1 { /** * A native Range object. */ private readonly range; constructor(range?: NativeRange); /** * A node within which the range starts. */ get startNode(): Nodes; /** * A number representing where in the startNode the range starts. */ get startOffset(): number; /** * A node within which the range ends. */ get endNode(): Nodes; /** * A number representing where in the endNode the range ends. */ get endOffset(): number; /** * The deepest node, or the lowest point in the document tree, that contains both boundary points of the range. */ get commonAncestor(): Nodes; /** * A boolean value indicating whether the range's start and end points are at the same position. */ get isCollapsed(): boolean; /** * A boolean value indicating whether the range's start point is in a box. */ get isBox(): boolean; /** * A boolean value indicating whether the commonAncestor is in the start position of a box. */ get isBoxStart(): boolean; /** * A boolean value indicating whether the commonAncestor is in the center position of a box. */ get isBoxCenter(): boolean; /** * A boolean value indicating whether commonAncestor is in the end position of a box. */ get isBoxEnd(): boolean; /** * A boolean value indicating whether commonAncestor is inside the container of a box. */ get isInsideBox(): boolean; /** * A boolean value indicating whether the range is inoperative. */ get isInoperative(): boolean; /** * Returns a native Range object from the range. */ get(): NativeRange; /** * Returns the size and position of the range. */ getRect(): DOMRect; /** * Returns -1, 0, or 1 depending on whether the specified node is before, the same as, or after the range. * −1 if the point is before the range. 0 if the point is in the range. 1 if the point is after the range. */ comparePoint(node: Nodes, offset: number): number; /** * Returns -1, 0, or 1 depending on whether the beginning of the specified node is before, the same as, or after the range. * −1 if the beginning of the node is before the range. 0 if the beginning of the node is in the range. 1 if the beginning of the node is after the range. */ compareBeforeNode(node: Nodes): number; /** * Returns -1, 0, or 1 depending on whether the end of the specified node is before, the same as, or after the range. * −1 if the end of the node is before the range. 0 if the end of the node is in the range. 1 if the end of the node is after the range. */ compareAfterNode(node: Nodes): number; /** * Returns a boolean value indicating whether the specified node is part of the range or intersects the range. */ intersectsNode(node: Nodes): boolean; /** * Sets the start position of the range. */ setStart(node: Nodes, offset: number): void; /** * Sets the start position of the range to the beginning of the specified node. */ setStartBefore(node: Nodes): void; /** * Sets the start position of the range to the end of the specified node. */ setStartAfter(node: Nodes): void; /** * Sets the end position of the range. */ setEnd(node: Nodes, offset: number): void; /** * Sets the end position of the range to the beginning of the specified node. */ setEndBefore(node: Nodes): void; /** * Sets the end position of the range to the end of the specified node. */ setEndAfter(node: Nodes): void; /** * Collapses the range to its start. */ collapseToStart(): void; /** * Collapses the range to its end. */ collapseToEnd(): void; /** * Sets the range to contain the specified node and its contents. */ selectNode(node: Nodes): void; /** * Sets the range to contain the contents of the specified node. */ selectNodeContents(node: Nodes): void; /** * Collapses the range to the center position of the specified box. */ selectBox(boxNode: Nodes): void; /** * Collapses the range to the start position of the specified box. */ selectBoxStart(boxNode: Nodes): void; /** * Collapses the range to the end position of the specified box. */ selectBoxEnd(boxNode: Nodes): void; /** * Collapses the range to the deepest point at the beginning of the contents of the specified node. */ shrinkBefore(node: Nodes): void; /** * Collapses the range to the deepest point at the end of the contents of the specified node. */ shrinkAfter(node: Nodes): void; /** * Sets the start and end positions of the range to the deepest start position and end position of the contents of the specified node. */ shrink(): void; /** * Relocates the start and end positions of the range for boxes. */ adjustBox(): void; /** * Relocates the start and end positions of the range for tables. */ adjustTable(): void; /** * Relocates the start and end positions of the range for blocks. */ adjustBlock(): void; /** * Relocates the start and end positions of the range for boxes, tables, and blocks. */ adjust(): void; /** * Relocates the start and end positions of the range for <br /> elements. */ adjustBr(): void; /** * Returns the node immediately preceding the start position of the range. */ getPrevNode(): Nodes; /** * Returns the node immediately following the end position of the range. */ getNextNode(): Nodes; /** * Returns the boxes contained within or intersected by the range. */ getBoxes(): Nodes[]; /** * Returns the blocks contained within or intersected by the range. */ getBlocks(): Nodes[]; /** * Returns the marks and text nodes contained within or intersected by the range. */ getMarks(hasText?: boolean): Nodes[]; /** * Returns the text from the start position of the closest block to the start position of the range. */ getStartText(): string; /** * Returns the text from the end position of the range to the end position of the closest block. */ getEndText(): string; /** * Returns a new range from the specified character to the start position of the range. * The specified character must be preceded by a whitespace or be at the beginning of a paragraph, * without being adjacent to other characters. It will return null if not. */ getCharacterRange(character: string): Range$1 | null; /** * Returns a copy of the range. */ clone(): Range$1; /** * Returns a DocumentFragment object copying the nodes included in the range. */ cloneContents(): DocumentFragment; /** * Prints information about the range, which is used for debugging. */ info(): void; } /** * Inserts a bookmark at the cursor position or a pair of bookmarks at the beginning and end of the range. */ declare function insertBookmark(range: Range$1): { anchor: Nodes; focus: Nodes; }; /** * Changes the specified range to a range represented by the provided bookmark. */ declare function toBookmark(range: Range$1, bookmark: { anchor: Nodes; focus: Nodes; }): void; /** * The Fragment interface represents a lightweight document object that has no parent. * It is designed for efficient manipulation of document structures without affecting the main DOM. */ declare class Fragment { /** * A native DocumentFragment object. */ private readonly fragment; constructor(fragment?: DocumentFragment); /** * Returns a native DocumentFragment object from the fragment. */ get(): DocumentFragment; /** * Finds and returns descendants of the fragment that match the specified CSS selector. */ find(selector: string): Nodes; /** * Inserts the specified content just inside the fragment, after its last child. */ append(content: string | Node | Nodes): void; } /** * Inserts the specified contents into the range. */ declare function insertContents(range: Range$1, contents: string | Node | DocumentFragment | Nodes | Fragment): void; /** * Removes the contents of the specified range. */ declare function deleteContents(range: Range$1): void; /** * Adds new blocks or changes the target blocks in the specified range. */ declare function setBlocks(range: Range$1, value: string | KeyValue): void; /** * Removes the contents of the specified range and then splits the block node at the point of the collapsed range. */ declare function splitBlock(range: Range$1): TwoParts; /** * Inserts a block into the specified range. */ declare function insertBlock(range: Range$1, value: string | Nodes): Nodes | null; declare function splitMarks(range: Range$1, removeEmptyMark?: boolean): ThreeParts; /** * Adds the specified mark to the texts of the range. */ declare function addMark(range: Range$1, value: string | Nodes): void; /** * Removes the specified marks in the range. */ declare function removeMark(range: Range$1, value?: string): void; /** * Inserts a box into the specified range. */ declare function insertBox(range: Range$1, boxName: string, boxValue?: BoxValue): Box | null; /** * Removes a box that contains the specified range. */ declare function removeBox(range: Range$1): Box | null; /** * The Selection interface represents the range of content selected by the user or the current cursor position. */ declare class Selection { /** * A native Selection object. */ private readonly selection; /** * A contenteditable element where users can edit the content. */ readonly container: Nodes; /** * A Range object that can be added to the native selection later. */ range: Range$1; constructor(container: Nodes); /** * Returns a Range object that is currently selected. */ getCurrentRange(): Range$1; /** * Adds the selection.range to the native selection. */ sync(): void; /** * Replaces the selection.range with the range of the native selection. */ updateByRange(): void; /** * Replaces the selection.range with the range represented by the bookmark. */ updateByBookmark(): void; /** * Returns a list of items related to the current selection. */ getActiveItems(): ActiveItem[]; /** * Creates a deep clone of the current container with its content. * If there is a selection within the container, it ensures the selection is also preserved in the cloned container. */ cloneContainer(): Nodes; /** * Inserts a bookmark at the cursor position or a pair of bookmarks at the selection boundaries. */ insertBookmark(): ReturnType<typeof insertBookmark>; /** * Changes selection.range to the range represented by the provided bookmark. */ toBookmark(bookmark: Parameters<typeof toBookmark>[1]): ReturnType<typeof toBookmark>; /** * Inserts the specified content into the selection. */ insertContents(contents: Parameters<typeof insertContents>[1]): ReturnType<typeof insertContents>; /** * Removes the contents of the selection. */ deleteContents(): ReturnType<typeof deleteContents>; /** * Adds new blocks or changes the target blocks in the selection. */ setBlocks(value: Parameters<typeof setBlocks>[1]): ReturnType<typeof setBlocks>; /** * Removes the contents of the selection and splits the block node at the cursor position. */ splitBlock(): ReturnType<typeof splitBlock>; /** * Inserts a block into the selection. */ insertBlock(value: Parameters<typeof insertBlock>[1]): ReturnType<typeof insertBlock>; /** * Splits text nodes or mark nodes. */ splitMarks(removeEmptyMark?: Parameters<typeof splitMarks>[1]): ReturnType<typeof splitMarks>; /** * Adds the specified mark to the selected text. */ addMark(value: Parameters<typeof addMark>[1]): ReturnType<typeof addMark>; /** * Removes specified marks from the selection. */ removeMark(value?: Parameters<typeof removeMark>[1]): ReturnType<typeof removeMark>; /** * Collapses the selection to the center position of the specified box. */ selectBox(box: Box | Nodes): void; /** * Inserts a box into the selection. */ insertBox(boxName: Parameters<typeof insertBox>[1], boxValue?: Parameters<typeof insertBox>[2]): Box; /** * Removes the specified box. If no parameter is given, the selected box is removed. */ removeBox(box?: Box | Nodes | null): ReturnType<typeof removeBox>; } interface CommandItem { isDisabled?: (activeItems: ActiveItem[]) => boolean; isSelected?: (activeItems: ActiveItem[]) => boolean; selectedValues?: (activeItems: ActiveItem[]) => string[]; execute: (...data: any[]) => void; } /** * The Command interface manages a collection of commands. */ declare class Command { private readonly selection; private readonly commandMap; constructor(selection: Selection); /** * Adds a new command to the collection. */ add(name: string, commandItem: CommandItem): void; /** * Removes a command from the collection by its name. */ delete(name: string): void; /** * Returns the names of all registered commands. */ getNames(): string[]; /** * Checks whether the specified command exists. */ has(name: string): boolean; /** * Returns a command item by its name. */ getItem(name: string): CommandItem; /** * Checks if the specified command is disabled. */ isDisabled(name: string): boolean; /** * Checks if the specified command is selected. */ isSelected(name: string): boolean; /** * Returns the selected values for the specified command. */ selectedValues(name: string): string[]; /** * Executes the specified command. */ execute(name: string, ...data: any[]): void; } interface SaveOptions { inputType?: string; update?: boolean; emitEvent?: boolean; } /** * The History interface manages undo and redo functionality for a container that holds some editable content. * It emits events when actions like save, undo, or redo are performed. */ declare class History { private readonly selection; private readonly container; private canSave; /** * A list in which the current and previous contents are stored. */ readonly list: Nodes[]; /** * A number that always indicates the position at which new content is stored. */ index: number; /** * The maximum length of the history. Once this limit is reached, the earliest item in the list will be removed. */ limit: number; /** * A ContentRules object defining the HTML parsing rules used by HTMLParser. */ contentRules: ContentRules; /** * An EventEmitter object used to set up events. */ readonly event: EventEmitter; constructor(selection: Selection); private removeBookmark; private getValue; private addIdToBoxes; private removeIdfromBoxes; private morphContainer; /** * A boolean value indicating whether the history can be undone. */ get canUndo(): boolean; /** * A boolean value indicating whether the history can be redone. */ get canRedo(): boolean; /** * Undoes to the previous saved content. */ undo(): void; /** * Redoes to the next saved content. */ redo(): void; /** * Resumes the ability to save history. * This method re-enables saving after the pause method has been called. */ continue(): void; /** * Pauses the ability to save history. * This method temporarily disables saving history, which can be resumed later by calling the continue method. */ pause(): void; /** * Saves the current content to the history. * The content is saved only if it is different from the previous content. */ save(options?: SaveOptions): void; } /** * The Keystroke interface provides a way to handle keyboard events and define custom shortcuts for a given container. * It allows you to register hotkeys, bind specific actions to them, and handle their execution. */ declare class Keystroke { private readonly container; private readonly keydownEventList; private readonly keyupEventList; constructor(container: Nodes); /** * Registers a keydown event listener for the specified key combination. * The listener will be triggered when the key combination is pressed. */ setKeydown(type: string, listener: EventListener): void; /** * Registers a keyup event listener for the specified key combination. * The listener will be triggered when the key combination is released. */ setKeyup(type: string, listener: EventListener): void; /** * Triggers all keydown event listeners associated with the specified key combination. */ keydown(type: string): void; /** * Triggers all keyup event listeners associated with the specified key combination. */ keyup(type: string): void; } /** * The BoxManager interface manages a collection of BoxComponent objects. * It allows you to add, remove, and retrieve the names of components. */ declare class BoxManager { /** * Adds a BoxComponent to the collection. */ add(component: BoxComponent): void; /** * Removes a box component from the collection by its name. */ remove(name: string): void; /** * Returns a list of all box component names in the collection. */ getNames(): string[]; } type UnmountPlugin = () => void; type InitializePlugin = (editor: Editor) => UnmountPlugin | void; /** * The Plugin interface manages a collection of plugins. * It allows plugins to be added and loaded into an Editor instance, and it handles the initialization and unmounting of those plugins. */ declare class Plugin { private readonly pluginMap; /** * Registers a plugin using a name as the key. */ add(name: string, plugin: InitializePlugin): void; /** * Loads all registered plugins. */ loadAll(editor: Editor): Map<string, UnmountPlugin>; } type DropdownLocation = 'local' | 'global'; type DropdownDirection = 'top' | 'bottom' | 'auto'; type DropdownMenuType = 'list' | 'icon' | 'character' | 'color'; interface DropdownMenuItem { value: string; icon?: string; text: string | ((locale: TranslationFunctions) => string); } interface DropdownItem { name: string; icon?: string; accentIcon?: string; downIcon?: string; defaultValue?: string; tooltip: string | ((locale: TranslationFunctions) => string); width?: string; menuType: DropdownMenuType; menuItems: DropdownMenuItem[]; menuWidth?: string; menuHeight?: string; menuCheck?: boolean; } interface ToolbarButtonItem { name: string; type: 'button'; icon?: string; tooltip: string | ((locale: TranslationFunctions) => string); isSelected?: (activeItems: ActiveItem[]) => boolean; isDisabled?: (activeItems: ActiveItem[]) => boolean; onClick: (editor: Editor, value: string) => void; } interface ToolbarDropdownItem extends DropdownItem { name: string; type: 'dropdown'; selectedValues?: (activeItems: ActiveItem[]) => string[]; isDisabled?: (activeItems: ActiveItem[]) => boolean; onSelect: (editor: Editor, value: string) => void; } interface ToolbarUploadItem { name: string; type: 'upload'; icon?: string; tooltip: string | ((locale: TranslationFunctions) => string); accept?: string; multiple?: boolean; } type ToolbarItem = ToolbarButtonItem | ToolbarDropdownItem | ToolbarUploadItem; type ToolbarPlacement = 'top' | 'bottom'; interface ToolbarConfig { root?: string | Node | Nodes; items?: (string | ToolbarItem)[]; placement?: ToolbarPlacement; } /** * The Toolbar interface provides properties and methods for rendering and manipulating the toolbar. */ declare class Toolbar { private items; private placement; private allMenuMap; private buttonItemList; private dropdownItemList; private dropdownList; /** * The element to which the toolbar is appended. */ root: Nodes; /** * The element where toolbar items are appended. */ container: Nodes; constructor(config: ToolbarConfig); private appendDivision; private appendNormalButton; private appendDropdown; private appendUploadButton; /** * Updates the state of each toolbar item, such as whether it is selected or disabled. */ updateState(state?: SelectionState): void; /** * Renders the toolbar for the specified editor. */ render(editor: Editor): void; /** * Destroys the toolbar instance, removing it from the DOM. */ unmount(): void; } type ShowMessage = (type: 'success' | 'error' | 'warning', message: string) => void; type DownloadFile = (type: 'image' | 'file', url: string) => void; interface Config { value: string; readonly: boolean; spellcheck: boolean; tabIndex: number; placeholder: string; indentWithTab: boolean; lang: string; contentRules: ContentRules; minChangeSize: number; historySize: number; showMessage: ShowMessage; downloadFile: DownloadFile; [name: string]: any; } interface EditorConfig extends Partial<Config> { root: string | Node | Nodes; toolbar?: Toolbar; } /** * The Editor interface provides properties and methods for rendering and manipulating the editor. */ declare class Editor { /** * A string that has not yet been saved to the history. */ private unsavedInputData; /** * The number of input event calls before saving to the history. */ private unsavedInputCount; /** * The state of the current selection. */ private state; /** * The functions for unmounting plugins. */ private unmountPluginMap; /** * The parent element of the container. */ private readonly containerWrapper; /** * The current version of Lake. */ static readonly version: string; /** * A BoxManager object that manages the box components. */ static readonly box: BoxManager; /** * A Plugin object that manages a collection of plugins. */ static readonly plugin: Plugin; /** * An element to which the editor is appended. */ readonly root: Nodes; /** * The toolbar for the editor. */ readonly toolbar: Toolbar | undefined; /** * The con