UNPKG

9.93 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(targets: Record<string, Parchment.RegistryDefinition | Record<string, unknown> | Theme | Module | Function>, overwrite?: boolean): void;
105 static register(target: Parchment.RegistryDefinition, overwrite?: boolean): void;
106 static register(path: string, target: any, overwrite?: boolean): void;
107 container: HTMLElement;
108 root: HTMLDivElement;
109 scroll: Scroll;
110 emitter: Emitter;
111 protected allowReadOnlyEdits: boolean;
112 editor: Editor;
113 composition: Composition;
114 selection: Selection;
115 theme: Theme;
116 keyboard: Keyboard;
117 clipboard: Clipboard;
118 history: History;
119 uploader: Uploader;
120 options: ExpandedQuillOptions;
121 constructor(container: HTMLElement | string, options?: QuillOptions);
122 addContainer(container: string, refNode?: Node | null): HTMLDivElement;
123 addContainer(container: HTMLElement, refNode?: Node | null): HTMLElement;
124 blur(): void;
125 deleteText(range: Range, source?: EmitterSource): Delta;
126 deleteText(index: number, length: number, source?: EmitterSource): Delta;
127 disable(): void;
128 editReadOnly<T>(modifier: () => T): T;
129 enable(enabled?: boolean): void;
130 focus(options?: {
131 preventScroll?: boolean;
132 }): void;
133 format(name: string, value: unknown, source?: EmitterSource): Delta;
134 formatLine(index: number, length: number, formats: Record<string, unknown>, source?: EmitterSource): Delta;
135 formatLine(index: number, length: number, name: string, value?: unknown, source?: EmitterSource): Delta;
136 formatText(range: Range, name: string, value: unknown, source?: EmitterSource): Delta;
137 formatText(index: number, length: number, name: string, value: unknown, source?: EmitterSource): Delta;
138 formatText(index: number, length: number, formats: Record<string, unknown>, source?: EmitterSource): Delta;
139 getBounds(index: number | Range, length?: number): Bounds | null;
140 getContents(index?: number, length?: number): Delta;
141 getFormat(index?: number, length?: number): {
142 [format: string]: unknown;
143 };
144 getFormat(range?: Range): {
145 [format: string]: unknown;
146 };
147 getIndex(blot: Parchment.Blot): number;
148 getLength(): number;
149 getLeaf(index: number): [Parchment.LeafBlot | null, number];
150 getLine(index: number): [Block | BlockEmbed | null, number];
151 getLines(range: Range): (Block | BlockEmbed)[];
152 getLines(index?: number, length?: number): (Block | BlockEmbed)[];
153 getModule(name: string): unknown;
154 getSelection(focus: true): Range;
155 getSelection(focus?: boolean): Range | null;
156 getSemanticHTML(range: Range): string;
157 getSemanticHTML(index?: number, length?: number): string;
158 getText(range?: Range): string;
159 getText(index?: number, length?: number): string;
160 hasFocus(): boolean;
161 insertEmbed(index: number, embed: string, value: unknown, source?: EmitterSource): Delta;
162 insertText(index: number, text: string, source?: EmitterSource): Delta;
163 insertText(index: number, text: string, formats: Record<string, unknown>, source?: EmitterSource): Delta;
164 insertText(index: number, text: string, name: string, value: unknown, source?: EmitterSource): Delta;
165 isEnabled(): boolean;
166 off(...args: Parameters<(typeof Emitter)['prototype']['off']>): Emitter;
167 on(event: (typeof Emitter)['events']['TEXT_CHANGE'], handler: (delta: Delta, oldContent: Delta, source: EmitterSource) => void): Emitter;
168 on(event: (typeof Emitter)['events']['SELECTION_CHANGE'], handler: (range: Range, oldRange: Range, source: EmitterSource) => void): Emitter;
169 on(event: (typeof Emitter)['events']['EDITOR_CHANGE'], handler: (...args: [
170 (typeof Emitter)['events']['TEXT_CHANGE'],
171 Delta,
172 Delta,
173 EmitterSource
174 ] | [
175 (typeof Emitter)['events']['SELECTION_CHANGE'],
176 Range,
177 Range,
178 EmitterSource
179 ]) => void): Emitter;
180 on(event: string, ...args: unknown[]): Emitter;
181 once(...args: Parameters<(typeof Emitter)['prototype']['once']>): Emitter;
182 removeFormat(index: number, length: number, source?: EmitterSource): Delta;
183 scrollRectIntoView(rect: Rect): void;
184 /**
185 * @deprecated Use Quill#scrollSelectionIntoView() instead.
186 */
187 scrollIntoView(): void;
188 /**
189 * Scroll the current selection into the visible area.
190 * If the selection is already visible, no scrolling will occur.
191 */
192 scrollSelectionIntoView(): void;
193 setContents(delta: Delta | Op[], source?: EmitterSource): Delta;
194 setSelection(range: Range | null, source?: EmitterSource): void;
195 setSelection(index: number, source?: EmitterSource): void;
196 setSelection(index: number, length?: number, source?: EmitterSource): void;
197 setSelection(index: number, source?: EmitterSource): void;
198 setText(text: string, source?: EmitterSource): Delta;
199 update(source?: EmitterSource): void;
200 updateContents(delta: Delta | Op[], source?: EmitterSource): Delta;
201}
202declare function expandConfig(containerOrSelector: HTMLElement | string, options: QuillOptions): ExpandedQuillOptions;
203type NormalizedIndexLength = [
204 number,
205 number,
206 Record<string, unknown>,
207 EmitterSource
208];
209declare function overload(index: number, source?: EmitterSource): NormalizedIndexLength;
210declare function overload(index: number, length: number, source?: EmitterSource): NormalizedIndexLength;
211declare function overload(index: number, length: number, format: string, value: unknown, source?: EmitterSource): NormalizedIndexLength;
212declare function overload(index: number, length: number, format: Record<string, unknown>, source?: EmitterSource): NormalizedIndexLength;
213declare function overload(range: Range, source?: EmitterSource): NormalizedIndexLength;
214declare function overload(range: Range, format: string, value: unknown, source?: EmitterSource): NormalizedIndexLength;
215declare function overload(range: Range, format: Record<string, unknown>, source?: EmitterSource): NormalizedIndexLength;
216export type { Bounds, DebugLevel, EmitterSource };
217export { Parchment, Range };
218export { globalRegistry, expandConfig, overload, Quill as default };