tiny-markdown-editor
Version:
TinyMDE: A tiny, ultra low dependency, embeddable HTML/JavaScript Markdown editor.
101 lines (100 loc) • 3.41 kB
TypeScript
import { GrammarRule } from "./grammar";
export interface EditorProps {
element?: string | HTMLElement;
editor?: string | HTMLElement;
content?: string;
textarea?: string | HTMLTextAreaElement;
customInlineGrammar?: Record<string, GrammarRule>;
}
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<string, boolean | null>;
}
export interface DropEvent {
dataTransfer: DataTransfer;
}
type EventType = 'change' | 'selection' | 'drop';
type EventHandler<T> = (event: T) => void;
export declare class Editor {
e: HTMLDivElement | null;
textarea: HTMLTextAreaElement | null;
lines: string[];
lineElements: NodeListOf<ChildNode> | HTMLCollection | ChildNode[];
lineTypes: string[];
lineCaptures: RegExpExecArray[];
lineReplacements: string[];
linkLabels: string[];
lineDirty: boolean[];
lastCommandState: Record<string, boolean | null> | null;
private customInlineGrammar;
private mergedInlineGrammar;
private hasFocus;
listeners: {
change: EventHandler<ChangeEvent>[];
selection: EventHandler<SelectionEvent>[];
drop: EventHandler<DropEvent>[];
};
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 updateFormatting;
private updateLinkLabels;
private replace;
private applyLineTypes;
private updateLineTypes;
getSelection(getAnchor?: boolean): Position | null;
setSelection(focus: Position, anchor?: Position | null): void;
paste(text: string, anchor?: Position | null, focus?: Position | null): void;
wrapSelection(pre: string, post: string, focus?: Position | null, anchor?: Position | null): void;
addEventListener<T extends EventType>(type: T, listener: T extends 'change' ? EventHandler<ChangeEvent> : T extends 'selection' ? EventHandler<SelectionEvent> : T extends 'drop' ? EventHandler<DropEvent> : never): void;
private fireChange;
private handleInputEvent;
private handleSelectionChangeEvent;
private handlePaste;
private handleDrop;
private processInlineStyles;
private computeColumn;
private computeNodeAndOffset;
private updateLineContentsAndFormatting;
private clearDirtyFlag;
private updateLineContents;
private processNewParagraph;
private spliceLines;
private fixNodeHierarchy;
private parseLinkOrImage;
private computeCommonAncestor;
private computeEnclosingMarkupNode;
getCommandState(focus?: Position | null, anchor?: Position | null): Record<string, boolean | null>;
setCommandState(command: string, state: boolean): void;
private isInlineFormattingAllowed;
toggleCommandState(command: string): void;
private fireDrop;
private fireSelection;
}
export default Editor;