UNPKG

9.81 kBTypeScriptView Raw
1import * as Parchment from 'parchment';
2import type { Op } from 'quill-delta';
3import Delta from 'quill-delta';
4import type { BlockEmbed } from '../blots/block.js';
5import type Block from '../blots/block.js';
6import type Scroll from '../blots/scroll.js';
7import type Clipboard from '../modules/clipboard.js';
8import type History from '../modules/history.js';
9import type Keyboard from '../modules/keyboard.js';
10import type Uploader from '../modules/uploader.js';
11import Editor from './editor.js';
12import Emitter from './emitter.js';
13import type { EmitterSource } from './emitter.js';
14import type { DebugLevel } from './logger.js';
15import Module from './module.js';
16import Selection, { Range } from './selection.js';
17import type { Bounds } from './selection.js';
18import Composition from './composition.js';
19import Theme from './theme.js';
20import type { ThemeConstructor } from './theme.js';
21import type { Rect } from './utils/scrollRectIntoView.js';
22declare const globalRegistry: Parchment.Registry;
23/**
24 * Options for initializing a Quill instance
25 */
26export interface QuillOptions {
27 theme?: string;
28 debug?: DebugLevel | boolean;
29 registry?: Parchment.Registry;
30 /**
31 * Whether to disable the editing
32 * @default false
33 */
34 readOnly?: boolean;
35 /**
36 * Placeholder text to display when the editor is empty
37 * @default ""
38 */
39 placeholder?: string;
40 bounds?: HTMLElement | string | null;
41 modules?: Record<string, unknown>;
42 /**
43 * A list of formats that are recognized and can exist within the editor contents.
44 * `null` means all formats are allowed.
45 * @default null
46 */
47 formats?: string[] | null;
48}
49/**
50 * Similar to QuillOptions, but with all properties expanded to their default values,
51 * and all selectors resolved to HTMLElements.
52 */
53export interface ExpandedQuillOptions extends Omit<QuillOptions, 'theme' | 'formats'> {
54 theme: ThemeConstructor;
55 registry: Parchment.Registry;
56 container: HTMLElement;
57 modules: Record<string, unknown>;
58 bounds?: HTMLElement | null;
59 readOnly: boolean;
60}
61declare class Quill {
62 static DEFAULTS: {
63 bounds: null;
64 modules: {
65 clipboard: boolean;
66 keyboard: boolean;
67 history: boolean;
68 uploader: boolean;
69 };
70 placeholder: string;
71 readOnly: false;
72 registry: Parchment.Registry;
73 theme: string;
74 };
75 static events: {
76 readonly EDITOR_CHANGE: "editor-change";
77 readonly SCROLL_BEFORE_UPDATE: "scroll-before-update";
78 readonly SCROLL_BLOT_MOUNT: "scroll-blot-mount";
79 readonly SCROLL_BLOT_UNMOUNT: "scroll-blot-unmount";
80 readonly SCROLL_OPTIMIZE: "scroll-optimize";
81 readonly SCROLL_UPDATE: "scroll-update";
82 readonly SCROLL_EMBED_UPDATE: "scroll-embed-update";
83 readonly SELECTION_CHANGE: "selection-change";
84 readonly TEXT_CHANGE: "text-change";
85 readonly COMPOSITION_BEFORE_START: "composition-before-start";
86 readonly COMPOSITION_START: "composition-start";
87 readonly COMPOSITION_BEFORE_END: "composition-before-end";
88 readonly COMPOSITION_END: "composition-end";
89 };
90 static sources: {
91 readonly API: "api";
92 readonly SILENT: "silent";
93 readonly USER: "user";
94 };
95 static version: string;
96 static imports: Record<string, unknown>;
97 static debug(limit: DebugLevel | boolean): void;
98 static find(node: Node, bubble?: boolean): Parchment.Blot | Quill | null;
99 static import(name: 'core/module'): typeof Module;
100 static import(name: `themes/${string}`): typeof Theme;
101 static import(name: 'parchment'): typeof Parchment;
102 static import(name: 'delta'): typeof Delta;
103 static import(name: string): unknown;
104 static register(path: string | Parchment.BlotConstructor | Parchment.Attributor | Record<string, unknown>, target?: Parchment.BlotConstructor | Parchment.Attributor | boolean, overwrite?: boolean): void;
105 container: HTMLElement;
106 root: HTMLDivElement;
107 scroll: Scroll;
108 emitter: Emitter;
109 protected allowReadOnlyEdits: boolean;
110 editor: Editor;
111 composition: Composition;
112 selection: Selection;
113 theme: Theme;
114 keyboard: Keyboard;
115 clipboard: Clipboard;
116 history: History;
117 uploader: Uploader;
118 options: ExpandedQuillOptions;
119 constructor(container: HTMLElement | string, options?: QuillOptions);
120 addContainer(container: string, refNode?: Node | null): HTMLDivElement;
121 addContainer(container: HTMLElement, refNode?: Node | null): HTMLElement;
122 blur(): void;
123 deleteText(range: Range, source?: EmitterSource): Delta;
124 deleteText(index: number, length: number, source?: EmitterSource): Delta;
125 disable(): void;
126 editReadOnly<T>(modifier: () => T): T;
127 enable(enabled?: boolean): void;
128 focus(options?: {
129 preventScroll?: boolean;
130 }): void;
131 format(name: string, value: unknown, source?: EmitterSource): any;
132 formatLine(index: number, length: number, formats: Record<string, unknown>, source?: EmitterSource): Delta;
133 formatLine(index: number, length: number, name: string, value?: unknown, source?: EmitterSource): Delta;
134 formatText(range: Range, name: string, value: unknown, source?: EmitterSource): Delta;
135 formatText(index: number, length: number, name: string, value: unknown, source?: EmitterSource): Delta;
136 formatText(index: number, length: number, formats: Record<string, unknown>, source?: EmitterSource): Delta;
137 getBounds(index: number | Range, length?: number): Bounds | null;
138 getContents(index?: number, length?: number): Delta;
139 getFormat(index?: number, length?: number): {
140 [format: string]: unknown;
141 };
142 getFormat(range?: Range): {
143 [format: string]: unknown;
144 };
145 getIndex(blot: Parchment.Blot): number;
146 getLength(): number;
147 getLeaf(index: number): [Parchment.LeafBlot | null, number];
148 getLine(index: number): [Block | BlockEmbed | null, number];
149 getLines(range: Range): (Block | BlockEmbed)[];
150 getLines(index?: number, length?: number): (Block | BlockEmbed)[];
151 getModule(name: string): unknown;
152 getSelection(focus: true): Range;
153 getSelection(focus?: boolean): Range | null;
154 getSemanticHTML(range: Range): string;
155 getSemanticHTML(index?: number, length?: number): string;
156 getText(range?: Range): string;
157 getText(index?: number, length?: number): string;
158 hasFocus(): boolean;
159 insertEmbed(index: number, embed: string, value: unknown, source?: EmitterSource): any;
160 insertText(index: number, text: string, source?: EmitterSource): Delta;
161 insertText(index: number, text: string, formats: Record<string, unknown>, source?: EmitterSource): Delta;
162 insertText(index: number, text: string, name: string, value: unknown, source?: EmitterSource): Delta;
163 isEnabled(): boolean;
164 off(...args: Parameters<(typeof Emitter)['prototype']['off']>): Emitter;
165 on(event: (typeof Emitter)['events']['TEXT_CHANGE'], handler: (delta: Delta, oldContent: Delta, source: EmitterSource) => void): Emitter;
166 on(event: (typeof Emitter)['events']['SELECTION_CHANGE'], handler: (range: Range, oldRange: Range, source: EmitterSource) => void): Emitter;
167 on(event: (typeof Emitter)['events']['EDITOR_CHANGE'], handler: (...args: [
168 (typeof Emitter)['events']['TEXT_CHANGE'],
169 Delta,
170 Delta,
171 EmitterSource
172 ] | [
173 (typeof Emitter)['events']['SELECTION_CHANGE'],
174 Range,
175 Range,
176 EmitterSource
177 ]) => void): Emitter;
178 on(event: string, ...args: unknown[]): Emitter;
179 once(...args: Parameters<(typeof Emitter)['prototype']['once']>): Emitter;
180 removeFormat(index: number, length: number, source?: EmitterSource): any;
181 scrollRectIntoView(rect: Rect): void;
182 /**
183 * @deprecated Use Quill#scrollSelectionIntoView() instead.
184 */
185 scrollIntoView(): void;
186 /**
187 * Scroll the current selection into the visible area.
188 * If the selection is already visible, no scrolling will occur.
189 */
190 scrollSelectionIntoView(): void;
191 setContents(delta: Delta | Op[], source?: EmitterSource): any;
192 setSelection(range: Range | null, source?: EmitterSource): void;
193 setSelection(index: number, source?: EmitterSource): void;
194 setSelection(index: number, length?: number, source?: EmitterSource): void;
195 setSelection(index: number, source?: EmitterSource): void;
196 setText(text: string, source?: EmitterSource): any;
197 update(source?: EmitterSource): void;
198 updateContents(delta: Delta | Op[], source?: EmitterSource): any;
199}
200declare function expandConfig(containerOrSelector: HTMLElement | string, options: QuillOptions): ExpandedQuillOptions;
201type NormalizedIndexLength = [
202 number,
203 number,
204 Record<string, unknown>,
205 EmitterSource
206];
207declare function overload(index: number, source?: EmitterSource): NormalizedIndexLength;
208declare function overload(index: number, length: number, source?: EmitterSource): NormalizedIndexLength;
209declare function overload(index: number, length: number, format: string, value: unknown, source?: EmitterSource): NormalizedIndexLength;
210declare function overload(index: number, length: number, format: Record<string, unknown>, source?: EmitterSource): NormalizedIndexLength;
211declare function overload(range: Range, source?: EmitterSource): NormalizedIndexLength;
212declare function overload(range: Range, format: string, value: unknown, source?: EmitterSource): NormalizedIndexLength;
213declare function overload(range: Range, format: Record<string, unknown>, source?: EmitterSource): NormalizedIndexLength;
214export type { Bounds, DebugLevel, EmitterSource };
215export { Parchment, Range };
216export { globalRegistry, expandConfig, overload, Quill as default };