Skip to content

Commit

Permalink
Merge pull request #47 from reedsy/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
alecgibson authored Jun 2, 2023
2 parents 1ebb5ff + b338e26 commit 87a2696
Show file tree
Hide file tree
Showing 33 changed files with 808 additions and 721 deletions.
43 changes: 27 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"plugins": ["prettier", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"settings": {
"import/resolver": {
"webpack": {
"config": "_develop/webpack.config.js"
}
}
},
"ignorePatterns": ["**/*.d.ts", "**/*.js", "website/**/*"],
"ignorePatterns": [
"website/**/*",
"*.js",
"!test/helpers/**/*.js",
"!test/unit/**/*.js"
],
"rules": {
"arrow-parens": ["error", "as-needed"],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-use-before-define": ["error", { "functions": false, "classes": false }],
"prettier/prettier": "error"
}
},
"overrides": [
{
"files": ["test/helpers/**/*.js", "test/unit/**/*.js"],
"plugins": ["prettier"]
},
{
"files": ["**/*.ts"],
"extends": ["plugin:@typescript-eslint/recommended"],
"excludedFiles": "*.d.ts",
"plugins": ["prettier", "@typescript-eslint"],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}
2 changes: 1 addition & 1 deletion blots/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Block extends BlockBlot {
return this.cache.length;
}

moveChildren(target, ref) {
moveChildren(target, ref?) {
super.moveChildren(target, ref);
this.cache = {};
}
Expand Down
49 changes: 36 additions & 13 deletions core/editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import rfdc from 'rfdc';
import isEqual from 'fast-deep-equal';
import merge from 'lodash.merge';
import { LeafBlot, Scope } from 'parchment';
import { LeafBlot, EmbedBlot, Scope } from 'parchment';
import Delta, { AttributeMap, Op } from '@reedsy/quill-delta';
import Block, { BlockEmbed, bubbleFormats } from '../blots/block';
import Break from '../blots/break';
Expand Down Expand Up @@ -32,17 +32,17 @@ class Editor {
normalizedOps.reduce((index, op) => {
const length = Op.length(op);
let attributes = op.attributes || {};
let addedNewline = false;
let isImplicitNewlinePrepended = false;
let isImplicitNewlineAppended = false;
if (op.insert != null) {
deleteDelta.retain(length);
if (typeof op.insert === 'string') {
const text = op.insert;
// @ts-expect-error TODO: Fix this the next time the file is edited.
addedNewline =
isImplicitNewlineAppended =
!text.endsWith('\n') &&
(scrollLength <= index ||
// @ts-expect-error
this.scroll.descendant(BlockEmbed, index)[0]);
!!this.scroll.descendant(BlockEmbed, index)[0]);
this.scroll.insertAt(index, text);
const [line, offset] = this.scroll.line(index);
let formats = merge({}, bubbleFormats(line));
Expand All @@ -55,12 +55,33 @@ class Editor {
} else if (typeof op.insert === 'object') {
const key = Object.keys(op.insert)[0]; // There should only be one key
if (key == null) return index;
// @ts-expect-error TODO: Fix this the next time the file is edited.
addedNewline =
this.scroll.query(key, Scope.INLINE) != null &&
(scrollLength <= index ||
const isInlineEmbed = this.scroll.query(key, Scope.INLINE) != null;
if (isInlineEmbed) {
if (
scrollLength <= index ||
// @ts-expect-error
this.scroll.descendant(BlockEmbed, index)[0]);
!!this.scroll.descendant(BlockEmbed, index)[0]
) {
isImplicitNewlineAppended = true;
}
const [leaf] = this.scroll.leaf(index);
const formats = merge({}, bubbleFormats(leaf));
attributes = AttributeMap.diff(formats, attributes) || {};
} else if (index > 0) {
// @ts-expect-error
const [leaf, offset] = this.scroll.descendant(LeafBlot, index - 1);
if (leaf instanceof TextBlot) {
const text = leaf.value();
if (text[offset] !== '\n') {
isImplicitNewlinePrepended = true;
}
} else if (
leaf instanceof EmbedBlot &&
leaf.statics.scope === Scope.INLINE_BLOT
) {
isImplicitNewlinePrepended = true;
}
}
this.scroll.insertAt(index, key, op.insert[key]);
}
scrollLength += length;
Expand All @@ -76,10 +97,12 @@ class Editor {
Object.keys(attributes).forEach(name => {
this.scroll.formatAt(index, length, name, attributes[name]);
});
const addedLength = addedNewline ? 1 : 0;
scrollLength += addedLength;
const prependedLength = isImplicitNewlinePrepended ? 1 : 0;
const addedLength = isImplicitNewlineAppended ? 1 : 0;
scrollLength += prependedLength + addedLength;
deleteDelta.retain(prependedLength);
deleteDelta.delete(addedLength);
return index + length + addedLength;
return index + length + prependedLength + addedLength;
}, 0);
deleteDelta.reduce((index, op) => {
if (typeof op.delete === 'number') {
Expand Down
8 changes: 4 additions & 4 deletions core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ class Quill {
return this.editor.getContents(index, length);
}

getFormat(index: number, length?: number);
getFormat(range: { index: number; length: number });
getFormat(index?: number, length?: number);
getFormat(range?: { index: number; length: number });
getFormat(
index: { index: number; length: number } | number = this.getSelection(true),
length = 0,
Expand Down Expand Up @@ -498,8 +498,8 @@ class Quill {
return this.editor.getHTML(index, length);
}

getText(range: { index: number; length: number }): string;
getText(index: number, length?: number): string;
getText(range?: { index: number; length: number }): string;
getText(index?: number, length?: number): string;
getText(
index: { index: number; length: number } | number = 0,
length?: number,
Expand Down
6 changes: 6 additions & 0 deletions modules/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ class Clipboard extends Module<ClipboardOptions> {
);
}

dangerouslyPasteHTML(html: string, source?: EmitterSource): void;
dangerouslyPasteHTML(
index: number,
html: string,
source?: EmitterSource,
): void;
dangerouslyPasteHTML(
index: number | string,
html: string,
source: EmitterSource = Quill.sources.API,
) {
if (typeof index === 'string') {
Expand Down
Loading

0 comments on commit 87a2696

Please sign in to comment.