Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: upgrade quill to 2.0

thecodrrc44b09a3ac2c
diff --git a/apps/web/package.json b/apps/web/package.json
index 2e38a7f39..8e8ac94b8 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -20,7 +20,7 @@
"localforage-getitems": "https://github.com/thecodrr/localForage-getItems.git",
"notes-core": "npm:@streetwriters/notesnook-core@latest",
"qclone": "^1.0.4",
- "quill": "https://github.com/thecodrr/quill.git#1.3.7",
+ "quill": "https://github.com/thecodrr/quill.git#develop",
"quill-magic-url": "^1.0.3",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.6",
diff --git a/apps/web/src/components/deltatransformer/index.js b/apps/web/src/components/deltatransformer/index.js
new file mode 100644
index 000000000..01825e51e
--- /dev/null
+++ b/apps/web/src/components/deltatransformer/index.js
@@ -0,0 +1,30 @@
+import Quill from "quill";
+
+const Delta = Quill.import("delta");
+
+class DeltaTransformer {
+ highlightDifference(first, second, color) {
+ const firstDelta = new Delta(first);
+ const secondDelta = new Delta(second);
+ const diff = secondDelta.diff(firstDelta);
+ const colored = diff.map((op) => {
+ if (op.insert) {
+ if (!op.attributes) op.attributes = {};
+ if (op.attributes.background) return op;
+ op.attributes.diff = color;
+ }
+ return op;
+ });
+ return secondDelta.compose(new Delta(colored));
+ }
+
+ cleanDifference(delta) {
+ return delta.ops.map((op) => {
+ if (op.attributes && op.attributes.diff) {
+ delete op.attributes.diff;
+ }
+ return op;
+ });
+ }
+}
+export default DeltaTransformer;
diff --git a/apps/web/src/components/editor/editor.css b/apps/web/src/components/editor/editor.css
index 9bd7fc16c..643abb16e 100644
--- a/apps/web/src/components/editor/editor.css
+++ b/apps/web/src/components/editor/editor.css
@@ -192,6 +192,7 @@
.ql-editor.ql-blank::before {
color: var(--placeholder) !important;
+ font-family: sans-serif;
}
.ql-editor .ql-syntax,
@@ -226,6 +227,11 @@ code {
font-weight: 700 !important;
}
+.ql-editor code,
+pre > * {
+ font-family: monospace !important;
+}
+
.ql-editor ul[data-checked="false"] > li::before,
.ql-editor ul[data-checked="true"] > li::before {
font-size: 20px;
diff --git a/apps/web/src/components/editor/modules/betterlist/index.js b/apps/web/src/components/editor/modules/betterlist/index.js
index 32ae7ceb2..c9a55eb01 100644
--- a/apps/web/src/components/editor/modules/betterlist/index.js
+++ b/apps/web/src/components/editor/modules/betterlist/index.js
@@ -3,8 +3,8 @@ import Quill from "quill";
const List = Quill.import("formats/list");
class BetterList extends List {
- constructor(el) {
- super(el);
+ constructor(_scroll, el) {
+ super(_scroll, el);
const isCheckList = el.hasAttribute("data-checked");
el.addEventListener("touchstart", (e) => {
diff --git a/apps/web/src/components/editor/modules/focus/focus.css b/apps/web/src/components/editor/modules/focus/focus.css
index 8ff34a871..dd6628349 100644
--- a/apps/web/src/components/editor/modules/focus/focus.css
+++ b/apps/web/src/components/editor/modules/focus/focus.css
@@ -2,7 +2,7 @@
transition: opacity 300ms;
}
-.quill-focus .ql-editor :not(.focused-blot) {
+.quill-focus .ql-editor > :not(.focused-blot) {
opacity: 0.7;
}
diff --git a/apps/web/src/components/editor/modules/markdown/index.js b/apps/web/src/components/editor/modules/markdown/index.js
index 684dc4599..d191a582d 100644
--- a/apps/web/src/components/editor/modules/markdown/index.js
+++ b/apps/web/src/components/editor/modules/markdown/index.js
@@ -67,20 +67,8 @@ class MarkdownShortcuts {
const { matchedText, annotatedText, startIndex } = matchInfo;
setTimeout(() => {
- this.quill.deleteText(startIndex, annotatedText.length);
- if (!commit) this.quill.insertText(startIndex, " ");
- this.quill.insertText(
- startIndex + (commit ? 0 : 1),
- commit ? matchedText : annotatedText.trim(),
- inlineStyle
- );
- if (commit)
- this.quill.insertText(this.quill.getSelection(), trigger, {
- bold: false,
- italic: false,
- strike: false,
- code: false,
- });
+ this.quill.deleteText(startIndex, annotatedText.trim().length);
+ this.quill.insertText(startIndex, matchedText, inlineStyle);
}, 0);
};
}
@@ -141,7 +129,7 @@ class MarkdownShortcuts {
},
{
name: "code-block",
- pattern: /^`{3}/g,
+ pattern: /^`{3}(\s+|)$/g,
action: (text, selection, _pattern, lineStart, commit, trigger) => {
if (!commit) return;
// Need to defer this action https://github.com/quilljs/quill/issues/1134
diff --git a/apps/web/src/components/editor/react-quill.js b/apps/web/src/components/editor/react-quill.js
index c27b05476..d2ab9ac2e 100644
--- a/apps/web/src/components/editor/react-quill.js
+++ b/apps/web/src/components/editor/react-quill.js
@@ -114,7 +114,7 @@ const quillModules = (isSimple, isFocusMode, isMobile) => ({
keyboard: {
bindings: {
linebreak: {
- key: 13,
+ key: "Enter",
shiftKey: true,
handler: function (range) {
// let currentLeaf = this.quill.getLeaf(range.index)[0];
diff --git a/apps/web/src/components/spliteditor/deltatoggle.js b/apps/web/src/components/spliteditor/deltatoggle.js
index a1f0d5d7c..a5963d8a1 100644
--- a/apps/web/src/components/spliteditor/deltatoggle.js
+++ b/apps/web/src/components/spliteditor/deltatoggle.js
@@ -1,10 +1,10 @@
import React, { useCallback } from "react";
import { Flex, Text, Button } from "rebass";
import { timeConverter } from "../../utils/time";
-import DeltaTransformer from "quill/core/delta";
import { store as notestore } from "../../stores/note-store";
import { db } from "../../common";
import { hashNavigate } from "../../navigation";
+import DeltaTransformer from "../deltatransformer";
const deltaTransformer = new DeltaTransformer();
diff --git a/apps/web/src/components/spliteditor/index.js b/apps/web/src/components/spliteditor/index.js
index 7a070e0be..dba3888f4 100644
--- a/apps/web/src/components/spliteditor/index.js
+++ b/apps/web/src/components/spliteditor/index.js
@@ -1,12 +1,12 @@
import React, { useState, useRef, useEffect } from "react";
import { Flex, Box, Text } from "rebass";
import SimpleEditor from "./simpleeditor";
-import DeltaTransformer from "quill/core/delta";
import DeltaToggle from "./deltatoggle";
import { store as notesStore } from "../../stores/note-store";
import { db } from "../../common";
import { useStore as useAppStore } from "../../stores/app-store";
import { hashNavigate } from "../../navigation";
+import DeltaTransformer from "../deltatransformer";
const deltaTransformer = new DeltaTransformer();
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index a59f2068f..84d385ec9 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -1599,11 +1599,6 @@
resolved "https://registry.yarnpkg.com/@mdi/react/-/react-1.4.0.tgz#7f6bad1bd8801226d0e5bad91659b215ce68a93f"
integrity sha512-OUH9RhfDJPhybQL3owwrSDIXz2yVKXg5lYeOZjyRCiT9wqywNK0FeYyDByOwNIZnnIQoQYmuSrMv+pOX0Uqkmw==
-"@mdi/svg@^5.0.45":
- version "5.8.55"
- resolved "https://registry.yarnpkg.com/@mdi/svg/-/svg-5.8.55.tgz#10826b2f68c9169a87bac6b4b78150891858533e"
- integrity sha512-RUs3xUOWFouCy+TXG8m0I3JREIyd8TI2mVEdcx/iwdXkdGC5hAcd3NWO4yFqfPceZAS9hbzxhYOig7WXvmg9Ag==
-
"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
@@ -3717,11 +3712,6 @@ clone-deep@^4.0.1:
kind-of "^6.0.2"
shallow-clone "^3.0.0"
-clone@^2.1.1:
- version "2.1.2"
- resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
- integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=
-
cnbuilder@^2.5.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/cnbuilder/-/cnbuilder-2.6.0.tgz#309b4f34371be80ad5452f983b7bac1af4f09ac8"
@@ -5263,11 +5253,6 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
-eventemitter3@^2.0.3:
- version "2.0.3"
- resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-2.0.3.tgz#b5e1079b59fb5e1ba2771c0a993be060a58c99ba"
- integrity sha1-teEHm1n7XhuidxwKmTvgYKWMmbo=
-
eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
@@ -8420,6 +8405,11 @@ lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
+lodash.merge@^4.5.0:
+ version "4.6.2"
+ resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
+ integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
+
lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
@@ -9001,7 +8991,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
version "5.4.1"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#9fdce8498fca3194d995c4181e86b7ebd36e7e77"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#6738252643874d5fad77661657d99cf1b28b6cc4"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
@@ -9407,7 +9397,12 @@ param-case@^3.0.3:
dot-case "^3.0.3"
tslib "^1.10.0"
-parchment@^1.1.2, parchment@^1.1.4:
+ version "2.0.0-dev.2"
+ resolved "https://registry.yarnpkg.com/parchment/-/parchment-2.0.0-dev.2.tgz#9d6fe57b3721317bd1c481ea38ffa9b287d496b8"
+ integrity sha512-4fgRny4pPISoML08Zp7poi52Dff3E2G1ORTi2D/acJ/RiROdDAMDB6VcQNfBcmehrX5Wixp6dxh6JjLyE5yUNQ==
+
+parchment@^1.1.2:
version "1.1.4"
resolved "https://registry.yarnpkg.com/parchment/-/parchment-1.1.4.tgz#aeded7ab938fe921d4c34bc339ce1168bc2ffde5"
integrity sha512-J5FBQt/pM2inLzg4hEWmzQx/8h8D0CiDxaG3vyp9rKrQRSDgBlhjdP5jQGgosEajXPSQouXGHOmVdgo7QmJuOg==
@@ -10663,6 +10658,15 @@ quill-delta-to-html@^0.12.0:
version "0.7.0"
resolved "https://github.com/streetwriters/quill-delta-to-markdown#8854bc4882f99f5229cfbd22cf0697d14e725755"
[email protected], quill-delta@^4.0.1:
+ version "4.2.2"
+ resolved "https://registry.yarnpkg.com/quill-delta/-/quill-delta-4.2.2.tgz#015397d046e0a3bed087cd8a51f98c11a1b8f351"
+ integrity sha512-qjbn82b/yJzOjstBgkhtBjN2TNK+ZHP/BgUQO+j6bRhWQQdmj2lH6hXG7+nwwLF41Xgn//7/83lxs9n2BkTtTg==
+ dependencies:
+ fast-diff "1.2.0"
+ lodash.clonedeep "^4.5.0"
+ lodash.isequal "^4.5.0"
+
quill-delta@^3.6.2:
version "3.6.3"
resolved "https://registry.yarnpkg.com/quill-delta/-/quill-delta-3.6.3.tgz#b19fd2b89412301c60e1ff213d8d860eac0f1032"
@@ -10672,15 +10676,6 @@ quill-delta@^3.6.2:
extend "^3.0.2"
fast-diff "1.1.2"
-quill-delta@^4.0.1:
- version "4.2.2"
- resolved "https://registry.yarnpkg.com/quill-delta/-/quill-delta-4.2.2.tgz#015397d046e0a3bed087cd8a51f98c11a1b8f351"
- integrity sha512-qjbn82b/yJzOjstBgkhtBjN2TNK+ZHP/BgUQO+j6bRhWQQdmj2lH6hXG7+nwwLF41Xgn//7/83lxs9n2BkTtTg==
- dependencies:
- fast-diff "1.2.0"
- lodash.clonedeep "^4.5.0"
- lodash.isequal "^4.5.0"
-
quill-magic-url@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/quill-magic-url/-/quill-magic-url-1.0.3.tgz#ff74a3cc6ce8fcc2a2e2968e9b1cd2c632352d7f"
@@ -10690,17 +10685,16 @@ quill-magic-url@^1.0.3:
normalize-url "^3.0.1"
quill-delta "^3.6.2"
-"quill@https://github.com/thecodrr/quill.git#1.3.7":
- version "1.3.7"
- resolved "https://github.com/thecodrr/quill.git#adbb4f12348764ceca69deaf3c507d8601fdea6e"
+"quill@https://github.com/thecodrr/quill.git#develop":
+ version "2.0.0-dev.4"
+ resolved "https://github.com/thecodrr/quill.git#86f978ccc26af8d4e44d641d565ac0d07fd6a40c"
dependencies:
- "@mdi/svg" "^5.0.45"
- clone "^2.1.1"
- deep-equal "^1.0.1"
- eventemitter3 "^2.0.3"
- extend "^3.0.2"
- parchment "^1.1.4"
- quill-delta "^3.6.2"
+ eventemitter3 "^4.0.0"
+ lodash.clonedeep "^4.5.0"
+ lodash.isequal "^4.5.0"
+ lodash.merge "^4.5.0"
+ parchment "2.0.0-dev.2"
+ quill-delta "4.2.2"
raf@^3.4.1:
version "3.4.1"