tiny-markdown-editor 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ import { GrammarRule } from "./grammar";
2
+ export interface EditorProps {
3
+ element?: string | HTMLElement;
4
+ editor?: string | HTMLElement;
5
+ content?: string;
6
+ textarea?: string | HTMLTextAreaElement;
7
+ customInlineGrammar?: Record<string, GrammarRule>;
8
+ }
9
+ export interface Position {
10
+ row: number;
11
+ col: number;
12
+ }
13
+ export interface HistoryState {
14
+ content: string;
15
+ selection: Position | null;
16
+ anchor: Position | null;
17
+ }
18
+ export interface ChangeEvent {
19
+ content: string;
20
+ linesDirty: boolean[];
21
+ }
22
+ export interface SelectionEvent {
23
+ focus: Position;
24
+ anchor: Position;
25
+ commandState: Record<string, boolean | null>;
26
+ }
27
+ export interface DropEvent {
28
+ dataTransfer: DataTransfer;
29
+ }
30
+ type EventType = 'change' | 'selection' | 'drop';
31
+ type EventHandler<T> = (event: T) => void;
32
+ export declare class Editor {
33
+ e: HTMLDivElement | null;
34
+ textarea: HTMLTextAreaElement | null;
35
+ lines: string[];
36
+ lineElements: NodeListOf<ChildNode> | HTMLCollection | ChildNode[];
37
+ lineTypes: string[];
38
+ lineCaptures: RegExpExecArray[];
39
+ lineReplacements: string[];
40
+ linkLabels: string[];
41
+ lineDirty: boolean[];
42
+ lastCommandState: Record<string, boolean | null> | null;
43
+ private customInlineGrammar;
44
+ private mergedInlineGrammar;
45
+ private hasFocus;
46
+ listeners: {
47
+ change: EventHandler<ChangeEvent>[];
48
+ selection: EventHandler<SelectionEvent>[];
49
+ drop: EventHandler<DropEvent>[];
50
+ };
51
+ private undoStack;
52
+ private redoStack;
53
+ private isRestoringHistory;
54
+ private maxHistory;
55
+ constructor(props?: EditorProps);
56
+ get canUndo(): boolean;
57
+ get canRedo(): boolean;
58
+ private pushHistory;
59
+ private pushCurrentState;
60
+ undo(): void;
61
+ redo(): void;
62
+ private handleUndoRedoKey;
63
+ private createEditorElement;
64
+ setContent(content: string): void;
65
+ getContent(): string;
66
+ private updateFormatting;
67
+ private updateLinkLabels;
68
+ private replace;
69
+ private applyLineTypes;
70
+ private updateLineTypes;
71
+ getSelection(getAnchor?: boolean): Position | null;
72
+ setSelection(focus: Position, anchor?: Position | null): void;
73
+ paste(text: string, anchor?: Position | null, focus?: Position | null): void;
74
+ wrapSelection(pre: string, post: string, focus?: Position | null, anchor?: Position | null): void;
75
+ addEventListener<T extends EventType>(type: T, listener: T extends 'change' ? EventHandler<ChangeEvent> : T extends 'selection' ? EventHandler<SelectionEvent> : T extends 'drop' ? EventHandler<DropEvent> : never): void;
76
+ private fireChange;
77
+ /**
78
+ * beforeinput handler, exclusively to handle insertParagraph and
79
+ * insertLineBreak events. These used to be handled in the input event,
80
+ * but that caused issues with Firefox where the input event would be
81
+ * sometimes not be fired for these input types.
82
+ * @param event The input event
83
+ * @returns nothing
84
+ */
85
+ private handleBeforeInputEvent;
86
+ private handleInputEvent;
87
+ private handleSelectionChangeEvent;
88
+ private handlePaste;
89
+ private handleDrop;
90
+ private processInlineStyles;
91
+ private computeColumn;
92
+ private computeNodeAndOffset;
93
+ private updateLineContentsAndFormatting;
94
+ private clearDirtyFlag;
95
+ private updateLineContents;
96
+ private spliceLines;
97
+ private fixNodeHierarchy;
98
+ private parseLinkOrImage;
99
+ private computeCommonAncestor;
100
+ private computeEnclosingMarkupNode;
101
+ getCommandState(focus?: Position | null, anchor?: Position | null): Record<string, boolean | null>;
102
+ setCommandState(command: string, state: boolean): void;
103
+ private isInlineFormattingAllowed;
104
+ toggleCommandState(command: string): void;
105
+ private fireDrop;
106
+ private fireSelection;
107
+ }
108
+ export default Editor;