tiny-markdown-editor 0.2.6 → 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.
package/README.md CHANGED
@@ -363,9 +363,11 @@ npm install
363
363
  npm run build
364
364
  ```
365
365
 
366
- The latter command generates the `dist` directory. You will find the following files there:
366
+ The latter command generates the `dist` and `lib` directories. You will find the following files there:
367
367
 
368
368
  - `dist/tiny-mde.css` and `dist/tiny-mde.min.css`: CSS files to style the editor. These can be edited at will to make the editor look like you want to. `dist/tiny-mde.min.css` has the same content as `dist/tiny-mde.css`, it's just minified. You will only need to use one of the files on your page. If you want to edit the CSS file, it's easier to edit `dist/tiny-mde.css` and then minify the edited version.
369
369
  - `dist/tiny-mde.js`: Debug version of the editor. The JS file is not minified and contains a sourcemap. It is not recommended to use this in production settings, since the file is large.
370
370
  - `dist/tiny-mde.min.js`: Minified JS file for most use cases. Simply copy this to your project to use it.
371
371
  - `dist/tiny-mde.tiny.js`: Minified and stripped-down JS file. Contains only the editor itself, not the toolbar.
372
+ - `lib/*.js`: Plain JavaScript versions of the code, transpiled from the TypeScript source, for use by bundlers.
373
+ - `lib/*.d.ts`: TypeScript type declarations.
@@ -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;