import { GrammarRule } from "./grammar"; export interface EditorProps { element?: string | HTMLElement; editor?: string | HTMLElement; content?: string; textarea?: string | HTMLTextAreaElement; customInlineGrammar?: Record; placeholder?: string; } export interface Position { row: number; col: number; } export interface HistoryState { content: string; selection: Position | null; anchor: Position | null; } export interface ChangeEvent { content: string; linesDirty: boolean[]; } export interface SelectionEvent { focus: Position; anchor: Position; commandState: Record; } export interface DropEvent { dataTransfer: DataTransfer; } type EventType = 'change' | 'selection' | 'drop'; type EventHandler = (event: T) => void; export declare class Editor { e: HTMLDivElement | null; textarea: HTMLTextAreaElement | null; lines: string[]; lineElements: NodeListOf | HTMLCollection | ChildNode[]; lineTypes: string[]; lineCaptures: RegExpExecArray[]; lineReplacements: string[]; linkLabels: string[]; lineDirty: boolean[]; lastCommandState: Record | null; private customInlineGrammar; private mergedInlineGrammar; private hasFocus; private lastSelection; private placeholder; listeners: { change: EventHandler[]; selection: EventHandler[]; drop: EventHandler[]; }; private undoStack; private redoStack; private isRestoringHistory; private maxHistory; constructor(props?: EditorProps); get canUndo(): boolean; get canRedo(): boolean; private pushHistory; private pushCurrentState; undo(): void; redo(): void; private handleUndoRedoKey; private createEditorElement; setContent(content: string): void; getContent(): string; private updatePlaceholder; private updateFormatting; private updateLinkLabels; private replace; private applyLineTypes; private updateLineTypes; getSelection(getAnchor?: boolean): Position | null; setSelection(focus: Position, anchor?: Position | null): void; restoreLastSelection(): boolean; paste(text: string, anchor?: Position | null, focus?: Position | null): void; wrapSelection(pre: string, post: string, focus?: Position | null, anchor?: Position | null): void; addEventListener(type: T, listener: T extends 'change' ? EventHandler : T extends 'selection' ? EventHandler : T extends 'drop' ? EventHandler : never): void; private fireChange; /** * beforeinput handler, exclusively to handle insertParagraph, * insertLineBreak, deleteContentBackward, and deleteContentForward events. * These used to be handled in the input event, but that caused issues with * Firefox where the input event would be sometimes not be fired for these * input types. deleteContentBackward/Forward are also handled here to fix a * Firefox-specific bug (#151) where backspacing on an empty line would not * remove it, because Firefox only removes the
inside the empty
* rather than merging the divs, and fixNodeHierarchy() would then re-add the *
, resulting in a no-op. * @param event The input event * @returns nothing */ private handleBeforeInputEvent; private handleInputEvent; private handleSelectionChangeEvent; private handlePaste; private handleDrop; processInlineStyles(originalString: string): string; private computeColumn; private computeNodeAndOffset; private updateLineContentsAndFormatting; private clearDirtyFlag; private updateLineContents; private spliceLines; private fixNodeHierarchy; parseLinkOrImage(originalString: string, isImage: boolean): { output: string; charCount: number; } | false; private computeCommonAncestor; private computeEnclosingMarkupNode; getCommandState(focus?: Position | null, anchor?: Position | null): Record; setCommandState(command: string, state: boolean): void; isInlineFormattingAllowed(): boolean; toggleCommandState(command: string): void; private fireDrop; private fireSelection; } export default Editor;