Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop branch to main #3994

Merged
merged 554 commits into from Feb 3, 2024
Merged

Merge develop branch to main #3994

merged 554 commits into from Feb 3, 2024

Conversation

luin
Copy link
Member

@luin luin commented Feb 3, 2024

...as Quill 2.0 is in RC state.

luin and others added 30 commits June 1, 2023 06:39
`Quill.getText()` is allowed to be called with no arguments, since it
[defaults][1] to returning the whole document.

However, the overload declarations require arguments, resulting in a
compilation error when trying to call `getText()` with no arguments:

```
(method) Quill.getText(range: {
    index: number;
    length: number;
}): string (+1 overload)
Expected 1-2 arguments, but got 0.ts(2554)
```

This change makes all the arguments in the overloads optional to match
the implementation.

[1]: https://github.com/quilljs/quill/blob/d2f689fb4744cdada96c632a8bccf6d476932d7b/core/quill.ts#L501-L502
The `Block` blot inherits from `parchment`'s `ParentBlot`, where the
`ref` argument [is optional][1].

This change updates the `Block` signature to match its parent.

[1]: https://github.com/quilljs/parchment/blob/634e50f4d73a3351952250146510332dbc0af961/src/blot/abstract/parent.ts#L238
`Quill.getFormat()` is allowed to be called with no arguments, since it
[defaults][1] to just getting the current selection.

However, the overload declarations require arguments, resulting in a
compilation error when trying to call `getFormat()` with no arguments:

```
(method) Quill.getFormat(index: number, length?: number): any (+1 overload)
Expected 1-2 arguments, but got 0.ts(2554)
```

This change makes all the arguments in the overloads optional to match
the implementation.

[1]: https://github.com/quilljs/quill/blob/d2f689fb4744cdada96c632a8bccf6d476932d7b/core/quill.ts#L435
`Clipboard.dangerouslyPasteHTML()` is allowed to be called without an
index as its first argument.

At the moment, doing this results in a compilation error:

```
(method) Clipboard.dangerouslyPasteHTML(index: number, html: string, source?: EmitterSource): void
Expected 2-3 arguments, but got 1.ts(2554)
```

This change adds the overload to allow this.
Consider a document with a single piece of bold text. As a `Delta`, this
would be represented as:

```js
const doc = new Delta().insert('a', {bold: true})
```

Now consider the following `Delta` being applied:

```js
const delta = new Delta().insert('\n1')
```

The above `Delta` will:

  - prepend the document with a newline
  - follow that newline with an **unformatted** string

Indeed, using `doc.compose(delta)` yields:

```js
const result = new Delta()
  .insert('\n1')
  .insert('a', {bold: true})
```

However, the same result is not reached when using the Quill
`editor.applyDelta()`, which instead results in bold formatting being
incorrectly applied to our unformatted string:

```js
const badResult = new Delta()
  .insert('\n')
  .insert('1a', {bold: true})
```

This happens because Quill does an insert of the whole insertion, but
doesn't handle the line splitting.

This change fixes this issue by splitting ops on newlines, and handling
them separately, which applies the correct formatting.
At the moment we try to reassign `lines: Blot` and `leaves: Blot` to
`lines: {}` and `leaves: {}`.

This change just creates new variables, so that we don't have these
compiler errors.
At the moment, since `@ts-expect-error` [doesn't apply][1] to type
definitions, we get a downstream compilation error:

```
TS2416: Property 'addModule' in type 'BaseTheme' is not assignable to the same property in base type 'Theme'.
  Type '(name: string) => unknown' is not assignable to type '{ (name: "clipboard"): Clipboard; (name: "keyboard"): Keyboard; (name: "uploader"): Uploader; (name: "history"): History; (name: "selection"): Selection; (name: string): unknown; }'.
    Type '{}' is missing the following properties from type 'Clipboard': matchers, addMatcher, convert, convertHTML, and 8 more.

10     addModule(name: string): unknown;
```

This change updates the `Base` class to have the same signature as
for `addModule()` as its parent class.

[1]: microsoft/TypeScript#38628
At the moment, the `BaseTooltip.edit()` signature has type:

```ts
declare class BaseTooltip extends Tooltip {
  edit(mode?: string, preview?: null): void;
}
```

This change tweaks the signature to be more accurate:

```ts
declare class BaseTooltip extends Tooltip {
  edit(mode?: string, preview?: string | null): void;
}
```
luin and others added 29 commits January 24, 2024 11:40
At the moment, if you paste the following HTML, the newline between the
`<span>` elements is incorrectly discarded.

```html
<span>foo</span>
<span>bar</span>
```

This will currently insert `foobar` into Quill, when we'd expect
`foo bar`, since newlines should [treated as spaces][1] between inline
elements (such as `<span>`).

This change updates the `matchText()` clipboard matcher to check if the
text node is between inline elements or not before early-returning.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace
@luin luin merged commit 640c599 into main Feb 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet