1 | import { Blot } from "parchment/dist/src/blot/abstract/blot";
|
2 | import Delta from "quill-delta";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export type DeltaOperation =
|
12 | & { insert?: any; delete?: number | undefined; retain?: number | undefined }
|
13 | & OptionalAttributes;
|
14 | interface SourceMap {
|
15 | API: "api";
|
16 | SILENT: "silent";
|
17 | USER: "user";
|
18 | }
|
19 | export type Sources = "api" | "user" | "silent";
|
20 |
|
21 | export interface Key {
|
22 | key: string | number;
|
23 | shortKey?: boolean | null | undefined;
|
24 | shiftKey?: boolean | null | undefined;
|
25 | altKey?: boolean | null | undefined;
|
26 | metaKey?: boolean | null | undefined;
|
27 | ctrlKey?: boolean | null | undefined;
|
28 | }
|
29 |
|
30 | export interface StringMap {
|
31 | [key: string]: any;
|
32 | }
|
33 |
|
34 | export interface OptionalAttributes {
|
35 | attributes?: StringMap | undefined;
|
36 | }
|
37 |
|
38 | export type TextChangeHandler = (delta: Delta, oldContents: Delta, source: Sources) => any;
|
39 | export type SelectionChangeHandler = (range: RangeStatic, oldRange: RangeStatic, source: Sources) => any;
|
40 | export type EditorChangeHandler =
|
41 | | ((name: "text-change", delta: Delta, oldContents: Delta, source: Sources) => any)
|
42 | | ((name: "selection-change", range: RangeStatic, oldRange: RangeStatic, source: Sources) => any);
|
43 |
|
44 | export interface KeyboardStatic {
|
45 | addBinding(key: Key, callback: (range: RangeStatic, context: any) => void): void;
|
46 | addBinding(key: Key, context: any, callback: (range: RangeStatic, context: any) => void): void;
|
47 | }
|
48 |
|
49 | export type ClipboardMatcherCallback = (node: any, delta: Delta) => Delta;
|
50 | export type ClipboardMatcherNode = string | number;
|
51 |
|
52 | export interface ClipboardStatic {
|
53 | matchers: Array<[ClipboardMatcherNode, ClipboardMatcherCallback]>;
|
54 | convert(content?: { html?: string | undefined; text?: string | undefined }, formats?: StringMap): Delta;
|
55 | addMatcher(selectorOrNodeType: ClipboardMatcherNode, callback: ClipboardMatcherCallback): void;
|
56 | dangerouslyPasteHTML(html: string, source?: Sources): void;
|
57 | dangerouslyPasteHTML(index: number, html: string, source?: Sources): void;
|
58 | }
|
59 |
|
60 | export interface QuillOptionsStatic {
|
61 | debug?: string | boolean | undefined;
|
62 | modules?: StringMap | undefined;
|
63 | placeholder?: string | undefined;
|
64 | readOnly?: boolean | undefined;
|
65 | theme?: string | undefined;
|
66 | formats?: string[] | undefined;
|
67 | bounds?: HTMLElement | string | undefined;
|
68 | scrollingContainer?: HTMLElement | string | undefined;
|
69 | strict?: boolean | undefined;
|
70 | }
|
71 |
|
72 | export interface BoundsStatic {
|
73 | bottom: number;
|
74 | left: number;
|
75 | right: number;
|
76 | top: number;
|
77 | height: number;
|
78 | width: number;
|
79 | }
|
80 |
|
81 | export interface RangeStatic {
|
82 | index: number;
|
83 | length: number;
|
84 | }
|
85 |
|
86 | export class RangeStatic implements RangeStatic {
|
87 | constructor();
|
88 | index: number;
|
89 | length: number;
|
90 | }
|
91 |
|
92 | export interface History {
|
93 | clear(): void;
|
94 | cutoff(): void;
|
95 | undo(): void;
|
96 | redo(): void;
|
97 | }
|
98 |
|
99 | export interface EventEmitter {
|
100 | on(eventName: "text-change", handler: TextChangeHandler): EventEmitter;
|
101 | on(eventName: "selection-change", handler: SelectionChangeHandler): EventEmitter;
|
102 | on(eventName: "editor-change", handler: EditorChangeHandler): EventEmitter;
|
103 | once(eventName: "text-change", handler: TextChangeHandler): EventEmitter;
|
104 | once(eventName: "selection-change", handler: SelectionChangeHandler): EventEmitter;
|
105 | once(eventName: "editor-change", handler: EditorChangeHandler): EventEmitter;
|
106 | off(eventName: "text-change", handler: TextChangeHandler): EventEmitter;
|
107 | off(eventName: "selection-change", handler: SelectionChangeHandler): EventEmitter;
|
108 | off(eventName: "editor-change", handler: EditorChangeHandler): EventEmitter;
|
109 | }
|
110 |
|
111 | export class Quill implements EventEmitter {
|
112 | |
113 |
|
114 |
|
115 | root: HTMLDivElement;
|
116 | clipboard: ClipboardStatic;
|
117 | scroll: Blot;
|
118 | keyboard: KeyboardStatic;
|
119 | history: History;
|
120 | constructor(container: string | Element, options?: QuillOptionsStatic);
|
121 | deleteText(index: number, length: number, source?: Sources): Delta;
|
122 | disable(): void;
|
123 | enable(enabled?: boolean): void;
|
124 | isEnabled(): boolean;
|
125 | getContents(index?: number, length?: number): Delta;
|
126 | getLength(): number;
|
127 | getText(index?: number, length?: number): string;
|
128 | insertEmbed(index: number, type: string, value: any, source?: Sources): Delta;
|
129 | insertText(index: number, text: string, source?: Sources): Delta;
|
130 | insertText(index: number, text: string, format: string, value: any, source?: Sources): Delta;
|
131 | insertText(index: number, text: string, formats: StringMap, source?: Sources): Delta;
|
132 | /**
|
133 | * @deprecated Remove in 2.0. Use clipboard.dangerouslyPasteHTML(index: number, html: string, source: Sources)
|
134 | */
|
135 | pasteHTML(index: number, html: string, source?: Sources): string;
|
136 | /**
|
137 | * @deprecated Remove in 2.0. Use clipboard.dangerouslyPasteHTML(html: string, source: Sources): void;
|
138 | */
|
139 | pasteHTML(html: string, source?: Sources): string;
|
140 | setContents(delta: Delta, source?: Sources): Delta;
|
141 | setText(text: string, source?: Sources): Delta;
|
142 | update(source?: Sources): void;
|
143 | updateContents(delta: Delta, source?: Sources): Delta;
|
144 |
|
145 | static readonly sources: SourceMap;
|
146 |
|
147 | format(name: string, value: any, source?: Sources): Delta;
|
148 | formatLine(index: number, length: number, source?: Sources): Delta;
|
149 | formatLine(index: number, length: number, format: string, value: any, source?: Sources): Delta;
|
150 | formatLine(index: number, length: number, formats: StringMap, source?: Sources): Delta;
|
151 | formatText(index: number, length: number, source?: Sources): Delta;
|
152 | formatText(index: number, length: number, format: string, value: any, source?: Sources): Delta;
|
153 | formatText(index: number, length: number, formats: StringMap, source?: Sources): Delta;
|
154 | formatText(range: RangeStatic, format: string, value: any, source?: Sources): Delta;
|
155 | formatText(range: RangeStatic, formats: StringMap, source?: Sources): Delta;
|
156 | getFormat(range?: RangeStatic): StringMap;
|
157 | getFormat(index: number, length?: number): StringMap;
|
158 | removeFormat(index: number, length: number, source?: Sources): Delta;
|
159 |
|
160 | blur(): void;
|
161 | focus(): void;
|
162 | getBounds(index: number, length?: number): BoundsStatic;
|
163 | getSelection(focus: true): RangeStatic;
|
164 | getSelection(focus?: false): RangeStatic | null;
|
165 | hasFocus(): boolean;
|
166 | setSelection(index: number, length: number, source?: Sources): void;
|
167 | setSelection(range: RangeStatic, source?: Sources): void;
|
168 |
|
169 | // static methods: debug, import, register, find
|
170 | static debug(level: string | boolean): void;
|
171 | static import(path: string): any;
|
172 | static register(path: string, def: any, suppressWarning?: boolean): void;
|
173 | static register(defs: StringMap, suppressWarning?: boolean): void;
|
174 | static find(domNode: Node, bubble?: boolean): Quill | any;
|
175 |
|
176 | addContainer(classNameOrDomNode: string | Node, refNode?: Node): any;
|
177 | getModule(name: string): any;
|
178 |
|
179 | // Blot interface is not exported on Parchment
|
180 | getIndex(blot: any): number;
|
181 | getLeaf(index: number): any;
|
182 | getLine(index: number): [any, number];
|
183 | getLines(index?: number, length?: number): any[];
|
184 | getLines(range: RangeStatic): any[];
|
185 |
|
186 | // EventEmitter methods
|
187 | on(eventName: "text-change", handler: TextChangeHandler): EventEmitter;
|
188 | on(eventName: "selection-change", handler: SelectionChangeHandler): EventEmitter;
|
189 | on(eventName: "editor-change", handler: EditorChangeHandler): EventEmitter;
|
190 | once(eventName: "text-change", handler: TextChangeHandler): EventEmitter;
|
191 | once(eventName: "selection-change", handler: SelectionChangeHandler): EventEmitter;
|
192 | once(eventName: "editor-change", handler: EditorChangeHandler): EventEmitter;
|
193 | off(eventName: "text-change", handler: TextChangeHandler): EventEmitter;
|
194 | off(eventName: "selection-change", handler: SelectionChangeHandler): EventEmitter;
|
195 | off(eventName: "editor-change", handler: EditorChangeHandler): EventEmitter;
|
196 | }
|
197 |
|
198 | export default Quill;
|