8ba9ff481390e439c83ef366b1ff763e60ce3e12e365237466b2adfc7c9b1b55046c79e7c1f5cb6c81355942e5f559b19e47616450a79c8c4f267de73b0ae4 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import * as Parchment from 'parchment';
  2. import type { Op } from 'quill-delta';
  3. import Delta from 'quill-delta';
  4. import type { BlockEmbed } from '../blots/block.js';
  5. import type Block from '../blots/block.js';
  6. import type Scroll from '../blots/scroll.js';
  7. import type Clipboard from '../modules/clipboard.js';
  8. import type History from '../modules/history.js';
  9. import type Keyboard from '../modules/keyboard.js';
  10. import type Uploader from '../modules/uploader.js';
  11. import Editor from './editor.js';
  12. import Emitter from './emitter.js';
  13. import type { EmitterSource } from './emitter.js';
  14. import type { DebugLevel } from './logger.js';
  15. import Module from './module.js';
  16. import Selection, { Range } from './selection.js';
  17. import type { Bounds } from './selection.js';
  18. import Composition from './composition.js';
  19. import Theme from './theme.js';
  20. import type { ThemeConstructor } from './theme.js';
  21. import type { Rect } from './utils/scrollRectIntoView.js';
  22. declare const globalRegistry: Parchment.Registry;
  23. /**
  24. * Options for initializing a Quill instance
  25. */
  26. export 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. */
  53. export 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. }
  61. declare 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. }
  202. declare function expandConfig(containerOrSelector: HTMLElement | string, options: QuillOptions): ExpandedQuillOptions;
  203. type NormalizedIndexLength = [
  204. number,
  205. number,
  206. Record<string, unknown>,
  207. EmitterSource
  208. ];
  209. declare function overload(index: number, source?: EmitterSource): NormalizedIndexLength;
  210. declare function overload(index: number, length: number, source?: EmitterSource): NormalizedIndexLength;
  211. declare function overload(index: number, length: number, format: string, value: unknown, source?: EmitterSource): NormalizedIndexLength;
  212. declare function overload(index: number, length: number, format: Record<string, unknown>, source?: EmitterSource): NormalizedIndexLength;
  213. declare function overload(range: Range, source?: EmitterSource): NormalizedIndexLength;
  214. declare function overload(range: Range, format: string, value: unknown, source?: EmitterSource): NormalizedIndexLength;
  215. declare function overload(range: Range, format: Record<string, unknown>, source?: EmitterSource): NormalizedIndexLength;
  216. export type { Bounds, DebugLevel, EmitterSource };
  217. export { Parchment, Range };
  218. export { globalRegistry, expandConfig, overload, Quill as default };