diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d065aff55..0306aa787c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - **Clipboard** Add support for Quill v1 list attributes - Fix overload declarations for `quill.formatText()` and other methods +- Expose Bounds type for getBounds() +- Expose Range type # 2.0.0-rc.4 diff --git a/packages/quill/src/core.ts b/packages/quill/src/core.ts index 77816b5644..cdf5724768 100644 --- a/packages/quill/src/core.ts +++ b/packages/quill/src/core.ts @@ -1,5 +1,6 @@ import Quill, { Parchment, Range } from './core/quill.js'; import type { + Bounds, DebugLevel, EmitterSource, ExpandedQuillOptions, @@ -24,7 +25,13 @@ import Input from './modules/input.js'; import UINode from './modules/uiNode.js'; export { Delta, Op, OpIterator, AttributeMap, Parchment, Range }; -export type { DebugLevel, EmitterSource, ExpandedQuillOptions, QuillOptions }; +export type { + Bounds, + DebugLevel, + EmitterSource, + ExpandedQuillOptions, + QuillOptions, +}; Quill.register({ 'blots/block': Block, diff --git a/packages/quill/src/core/quill.ts b/packages/quill/src/core/quill.ts index 59da9d0513..b88a4f5fa4 100644 --- a/packages/quill/src/core/quill.ts +++ b/packages/quill/src/core/quill.ts @@ -402,7 +402,7 @@ class Quill { } formatText( - range: { index: number; length: number }, + range: Range, name: string, value: unknown, source?: EmitterSource, @@ -421,7 +421,7 @@ class Quill { source?: EmitterSource, ): Delta; formatText( - index: number | { index: number; length: number }, + index: number | Range, length: number | string, name: string | unknown, value?: unknown | EmitterSource, @@ -473,11 +473,11 @@ class Quill { } getFormat(index?: number, length?: number): { [format: string]: unknown }; - getFormat(range?: { index: number; length: number }): { + getFormat(range?: Range): { [format: string]: unknown; }; getFormat( - index: { index: number; length: number } | number = this.getSelection(true), + index: Range | number = this.getSelection(true), length = 0, ): { [format: string]: unknown } { if (typeof index === 'number') { @@ -502,10 +502,10 @@ class Quill { return this.scroll.line(index); } - getLines(range: { index: number; length: number }): (Block | BlockEmbed)[]; + getLines(range: Range): (Block | BlockEmbed)[]; getLines(index?: number, length?: number): (Block | BlockEmbed)[]; getLines( - index: { index: number; length: number } | number = 0, + index: Range | number = 0, length = Number.MAX_VALUE, ): (Block | BlockEmbed)[] { if (typeof index !== 'number') { @@ -526,12 +526,9 @@ class Quill { return this.selection.getRange()[0]; } - getSemanticHTML(range: { index: number; length: number }): string; + getSemanticHTML(range: Range): string; getSemanticHTML(index?: number, length?: number): string; - getSemanticHTML( - index: { index: number; length: number } | number = 0, - length?: number, - ) { + getSemanticHTML(index: Range | number = 0, length?: number) { if (typeof index === 'number') { length = length ?? this.getLength() - index; } @@ -540,12 +537,9 @@ class Quill { return this.editor.getHTML(index, length); } - getText(range?: { index: number; length: number }): string; + getText(range?: Range): string; getText(index?: number, length?: number): string; - getText( - index: { index: number; length: number } | number = 0, - length?: number, - ): string { + getText(index: Range | number = 0, length?: number): string { if (typeof index === 'number') { length = length ?? this.getLength() - index; } @@ -1033,7 +1027,7 @@ function shiftRange( return new Range(start, end - start); } -export type { DebugLevel, EmitterSource }; +export type { Bounds, DebugLevel, EmitterSource }; export { Parchment, Range }; export { globalRegistry, expandConfig, overload, Quill as default }; diff --git a/packages/quill/src/core/selection.ts b/packages/quill/src/core/selection.ts index 5fc45cf70a..79ed119fe5 100644 --- a/packages/quill/src/core/selection.ts +++ b/packages/quill/src/core/selection.ts @@ -28,7 +28,7 @@ export interface Bounds { width: number; } -class Range { +export class Range { constructor( public index: number, public length = 0, @@ -484,4 +484,4 @@ function contains(parent: Node, descendant: Node) { return parent.contains(descendant); } -export { Range, Selection as default }; +export default Selection; diff --git a/packages/quill/src/quill.ts b/packages/quill/src/quill.ts index bc2535b1b8..0c3626fd8a 100644 --- a/packages/quill/src/quill.ts +++ b/packages/quill/src/quill.ts @@ -1,5 +1,6 @@ import Quill, { Parchment, Range } from './core.js'; import type { + Bounds, DebugLevel, EmitterSource, ExpandedQuillOptions, @@ -114,7 +115,13 @@ Quill.register( true, ); -export type { DebugLevel, EmitterSource, ExpandedQuillOptions, QuillOptions }; +export type { + Bounds, + DebugLevel, + EmitterSource, + ExpandedQuillOptions, + QuillOptions, +}; export { Parchment, Range }; export default Quill; diff --git a/packages/quill/test/types/quill.test-d.ts b/packages/quill/test/types/quill.test-d.ts index d7ae524188..1d65de3823 100644 --- a/packages/quill/test/types/quill.test-d.ts +++ b/packages/quill/test/types/quill.test-d.ts @@ -179,6 +179,9 @@ const quill = new Quill('#editor'); { quill.scrollRectIntoView({ left: 0, right: 0, top: 0, bottom: 0 }); + quill.scrollRectIntoView( + document.createElement('div').getBoundingClientRect(), + ); } {