Skip to content

Commit

Permalink
Expose Range type
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Apr 4, 2024
1 parent 91a7346 commit 1021587
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- **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

Expand Down
26 changes: 10 additions & 16 deletions packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class Quill {
}

formatText(
range: { index: number; length: number },
range: Range,
name: string,
value: unknown,
source?: EmitterSource,
Expand All @@ -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,
Expand Down Expand Up @@ -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') {
Expand All @@ -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') {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/quill/src/core/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Bounds {
width: number;
}

class Range {
export class Range {
constructor(
public index: number,
public length = 0,
Expand Down Expand Up @@ -484,4 +484,4 @@ function contains(parent: Node, descendant: Node) {
return parent.contains(descendant);
}

export { Range, Selection as default };
export default Selection;

0 comments on commit 1021587

Please sign in to comment.