Skip to content

Commit

Permalink
Merge pull request #4099 from quilljs/zh-export-types
Browse files Browse the repository at this point in the history
Expose types needed in public APIs
  • Loading branch information
luin authored Apr 4, 2024
2 parents d5ac335 + 1021587 commit 6b48eca
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion packages/quill/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Quill, { Parchment, Range } from './core/quill.js';
import type {
Bounds,
DebugLevel,
EmitterSource,
ExpandedQuillOptions,
Expand All @@ -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,
Expand Down
28 changes: 11 additions & 17 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 Expand Up @@ -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 };
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;
9 changes: 8 additions & 1 deletion packages/quill/src/quill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Quill, { Parchment, Range } from './core.js';
import type {
Bounds,
DebugLevel,
EmitterSource,
ExpandedQuillOptions,
Expand Down Expand Up @@ -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;
3 changes: 3 additions & 0 deletions packages/quill/test/types/quill.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

{
Expand Down

0 comments on commit 6b48eca

Please sign in to comment.