Skip to content

Commit

Permalink
Merge branch 'main' into matcher-types
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbhopper committed Mar 26, 2024
2 parents 6623b72 + 16aa1da commit 2a384ed
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 58 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# [Unreleased]

- **Clipboard** Add support for Quill v1 list attributes
- Fix overload declarations for `quill.formatText()` and other methods

# 2.0.0-rc.4

- Include source maps for Parchment
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Instantiate a new Quill object with a css selector for the div that should becom
```html
<!-- Include Quill stylesheet -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.snow.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.snow.css"
rel="stylesheet"
/>

Expand All @@ -61,7 +61,7 @@ Instantiate a new Quill object with a css selector for the div that should becom
</div>

<!-- Include the Quill library -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.js"></script>

<!-- Initialize Quill editor -->
<script>
Expand All @@ -83,24 +83,24 @@ npm install quill@rc

```html
<!-- Main Quill library -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.js"></script>

<!-- Theme included stylesheets -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.snow.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.snow.css"
rel="stylesheet"
/>
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.bubble.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.bubble.css"
rel="stylesheet"
/>

<!-- Core build with no theme, formatting, non-essential modules -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.core.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.core.css"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.core.js"></script>
```

## Community
Expand Down
7 changes: 4 additions & 3 deletions packages/quill/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Quill from './core/quill.js';
import Quill, { Parchment, Range } from './core/quill.js';
import type {
DebugLevel,
EmitterSource,
ExpandedQuillOptions,
QuillOptions,
} from './core/quill.js';
Expand All @@ -22,8 +23,8 @@ import Delta, { Op, OpIterator, AttributeMap } from 'quill-delta';
import Input from './modules/input.js';
import UINode from './modules/uiNode.js';

export { Delta, Op, OpIterator, AttributeMap };
export type { DebugLevel, ExpandedQuillOptions, QuillOptions };
export { Delta, Op, OpIterator, AttributeMap, Parchment, Range };
export type { DebugLevel, EmitterSource, ExpandedQuillOptions, QuillOptions };

Quill.register({
'blots/block': Block,
Expand Down
23 changes: 15 additions & 8 deletions packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,13 @@ class Quill {
length: number,
name: string,
value: unknown,
source: EmitterSource,
source?: EmitterSource,
): Delta;
formatText(
index: number,
length: number,
formats: Record<string, unknown>,
source?: EmitterSource,
): Delta;
formatText(
index: number | { index: number; length: number },
Expand Down Expand Up @@ -568,24 +574,24 @@ class Quill {
);
}

insertText(index: number, text: string, source: EmitterSource): Delta;
insertText(index: number, text: string, source?: EmitterSource): Delta;
insertText(
index: number,
text: string,
formats: Record<string, unknown>,
source: EmitterSource,
source?: EmitterSource,
): Delta;
insertText(
index: number,
text: string,
name: string,
value: unknown,
source: EmitterSource,
source?: EmitterSource,
): Delta;
insertText(
index: number,
text: string,
name: string | Record<string, unknown> | EmitterSource,
name?: string | Record<string, unknown> | EmitterSource,
value?: unknown,
source?: EmitterSource,
): Delta {
Expand Down Expand Up @@ -647,8 +653,8 @@ class Quill {
return this.emitter.once(...args);
}

removeFormat(...args: Parameters<typeof overload>) {
const [index, length, , source] = overload(...args);
removeFormat(index: number, length: number, source?: EmitterSource) {
[index, length, , source] = overload(index, length, source);
return modify.call(
this,
() => {
Expand Down Expand Up @@ -1027,6 +1033,7 @@ function shiftRange(
return new Range(start, end - start);
}

export type { DebugLevel };
export type { DebugLevel, EmitterSource };
export { Parchment, Range };

export { globalRegistry, expandConfig, overload, Quill as default };
8 changes: 7 additions & 1 deletion packages/quill/src/modules/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,13 @@ function matchIndent(node: Node, delta: Delta, scroll: ScrollBlot) {
}

function matchList(node: Element, delta: Delta, scroll: ScrollBlot) {
const list = node.tagName === 'OL' ? 'ordered' : 'bullet';
let list = node.tagName === 'OL' ? 'ordered' : 'bullet';

const checkedAttr = node.getAttribute('data-checked');
if (checkedAttr) {
list = checkedAttr === 'true' ? 'checked' : 'unchecked';
}

return applyFormat(delta, 'list', list, scroll);
}

Expand Down
12 changes: 9 additions & 3 deletions packages/quill/src/quill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Quill from './core.js';
import type { DebugLevel, ExpandedQuillOptions, QuillOptions } from './core.js';
import Quill, { Parchment, Range } from './core.js';
import type {
DebugLevel,
EmitterSource,
ExpandedQuillOptions,
QuillOptions,
} from './core.js';

import { AlignClass, AlignStyle } from './formats/align.js';
import {
Expand Down Expand Up @@ -109,6 +114,7 @@ Quill.register(
true,
);

export type { DebugLevel, ExpandedQuillOptions, QuillOptions };
export type { DebugLevel, EmitterSource, ExpandedQuillOptions, QuillOptions };
export { Parchment, Range };

export default Quill;
211 changes: 211 additions & 0 deletions packages/quill/test/types/quill.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { assertType, expectTypeOf } from 'vitest';
import Quill from '../../src/quill.js';
import type { EmitterSource, Parchment, Range } from '../../src/quill.js';
import Delta from 'quill-delta';
import type { default as Block, BlockEmbed } from '../../src/blots/block.js';

const quill = new Quill('#editor');

{
quill.deleteText(0, 1);
quill.deleteText(0, 1, 'api');
quill.deleteText({ index: 0, length: 1 });
quill.deleteText({ index: 0, length: 1 }, 'api');
}

{
assertType<Delta>(quill.getContents());
assertType<Delta>(quill.getContents(1));
assertType<Delta>(quill.getContents(1, 2));
}

{
assertType<number>(quill.getLength());
}

{
assertType<string>(quill.getSemanticHTML());
assertType<string>(quill.getSemanticHTML(1));
assertType<string>(quill.getSemanticHTML(1, 2));
}

{
quill.insertEmbed(10, 'image', 'https://example.com/logo.png');
quill.insertEmbed(10, 'image', 'https://example.com/logo.png', 'api');
}

{
quill.insertText(0, 'Hello');
quill.insertText(0, 'Hello', 'api');
quill.insertText(0, 'Hello', 'bold', true);
quill.insertText(0, 'Hello', 'bold', true, 'api');
quill.insertText(5, 'Quill', {
color: '#ffff00',
italic: true,
});
quill.insertText(
5,
'Quill',
{
color: '#ffff00',
italic: true,
},
'api',
);
}

{
quill.enable();
quill.enable(true);
}

{
quill.disable();
}

{
assertType<boolean>(quill.editReadOnly(() => true));
assertType<string>(quill.editReadOnly(() => 'success'));
}

{
quill.setText('Hello World!');
quill.setText('Hello World!', 'api');
}

{
quill.updateContents([{ insert: 'Hello World!' }]);
quill.updateContents([{ insert: 'Hello World!' }], 'api');
quill.updateContents(new Delta().insert('Hello World!'));
quill.updateContents(new Delta().insert('Hello World!'), 'api');
}

{
quill.setContents([{ insert: 'Hello World!\n' }]);
quill.setContents([{ insert: 'Hello World!\n' }], 'api');
quill.setContents(new Delta().insert('Hello World!\n'));
quill.setContents(new Delta().insert('Hello World!\n'), 'api');
}

{
quill.format('bold', true);
quill.format('bold', true, 'api');
}

{
quill.formatText(0, 1, 'bold', true);
quill.formatText(0, 1, 'bold', true, 'api');
quill.formatText(0, 5, {
bold: false,
color: 'rgb(0, 0, 255)',
});
quill.formatText(
0,
5,
{
bold: false,
color: 'rgb(0, 0, 255)',
},
'api',
);
}

{
quill.formatLine(0, 1, 'bold', true);
quill.formatLine(0, 1, 'bold', true, 'api');
quill.formatLine(0, 5, {
bold: false,
color: 'rgb(0, 0, 255)',
});
quill.formatLine(
0,
5,
{
bold: false,
color: 'rgb(0, 0, 255)',
},
'api',
);
}

{
quill.getFormat();
quill.getFormat(1);
quill.getFormat(1, 10);
quill.getFormat({ index: 1, length: 1 });
}

{
quill.removeFormat(3, 2);
quill.removeFormat(3, 2, 'user');
}

{
quill.getBounds(3, 2);
}

{
quill.getSelection();
quill.getSelection(true);
}

{
quill.setSelection(1, 2);
quill.setSelection(1, 2, 'api');
quill.setSelection({ index: 1, length: 2 });
quill.setSelection({ index: 1, length: 2 }, 'api');
}

{
quill.scrollSelectionIntoView();
}

{
quill.blur();
}

{
quill.focus();
}

{
assertType<boolean>(quill.hasFocus());
}

{
quill.update();
quill.update('user');
}

{
quill.scrollRectIntoView({ left: 0, right: 0, top: 0, bottom: 0 });
}

{
quill.on('text-change', (delta, oldDelta, source) => {
expectTypeOf<Delta>(delta);
expectTypeOf<Delta>(oldDelta);
expectTypeOf<EmitterSource>(source);
});
}

{
quill.on('selection-change', (range, oldRange, source) => {
expectTypeOf<Range>(range);
expectTypeOf<Range>(oldRange);
expectTypeOf<EmitterSource>(source);
});
}

{
assertType<[Parchment.LeafBlot | null, number]>(quill.getLeaf(0));
}

{
assertType<[BlockEmbed | Block | null, number]>(quill.getLine(0));
}

{
assertType<(BlockEmbed | Block)[]>(quill.getLines(0));
assertType<(BlockEmbed | Block)[]>(quill.getLines(0, 10));
}
Loading

0 comments on commit 2a384ed

Please sign in to comment.