Skip to content

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

feat: make our own react-quill

thecodrr2dac6e472c12
diff --git a/apps/web/package.json b/apps/web/package.json
index 3e48dd497..4a4ef06d9 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -9,6 +9,7 @@
"immer": "^5.3.6",
"localforage": "^1.7.3",
"notes-core": "npm:@streetwriters/notesnook-core@latest",
+ "quill": "^1.3.6",
"quill-magic-url": "^1.0.3",
"quill-markdown-shortcuts": "^0.0.10",
"react": "^16.11.0",
diff --git a/apps/web/src/components/editor/react-quill.js b/apps/web/src/components/editor/react-quill.js
index e69de29bb..1e59fe19d 100644
--- a/apps/web/src/components/editor/react-quill.js
+++ b/apps/web/src/components/editor/react-quill.js
@@ -0,0 +1,98 @@
+import React, { Component } from "react";
+import { Box } from "rebass";
+import Quill from "quill";
+import "quill/dist/quill.snow.css";
+import MarkdownShortcuts from "./modules/markdown";
+import MagicUrl from "quill-magic-url";
+
+Quill.register("modules/markdownShortcuts", MarkdownShortcuts);
+Quill.register("modules/magicUrl", MagicUrl);
+
+const modules = {
+ toolbar: [
+ [{ header: [1, 2, 3, 4, 5, 6] }],
+ ["bold", "italic", "underline", "strike", "blockquote"],
+ [
+ { align: "" },
+ { align: "center" },
+ { align: "right" },
+ { align: "justify" }
+ ],
+ [
+ { list: "ordered" },
+ { list: "bullet" },
+ { indent: "-1" },
+ { indent: "+1" }
+ ],
+ [{ size: ["small", false, "large", "huge"] }],
+ ["code-block", { script: "sub" }, { script: "super" }],
+ [{ color: [] }, { background: [] }],
+ ["link", "image", "video"],
+ [{ direction: "rtl" }, "clean"]
+ ],
+ syntax: true,
+ markdownShortcuts: {},
+ magicUrl: true
+};
+
+export default class ReactQuill extends Component {
+ quill;
+ getEditor() {
+ return this.quill.editor;
+ }
+
+ shouldComponentUpdate(nextProps) {
+ return this.props.readOnly !== nextProps.readOnly || nextProps.refresh;
+ }
+
+ componentDidUpdate(prevProps) {
+ if (this.props.refresh) {
+ this.quill.setContents(this.props.initialContent);
+ const text = this.quill.getText();
+ if (text.trim().length <= 0) return;
+ if (text[text.length - 1] !== " ") {
+ this.quill.insertText(text.length - 1, " ");
+ }
+ this.quill.setSelection(text.length, 0);
+ }
+ }
+
+ componentDidMount() {
+ const {
+ placeholder,
+ container,
+ readOnly,
+ initialContent,
+ onChange
+ } = this.props;
+
+ this.quill = new Quill("#quill", {
+ placeholder,
+ bounds: container,
+ modules,
+ theme: "snow",
+ readOnly
+ });
+ if (initialContent) {
+ this.quill.setContents(initialContent);
+ }
+
+ if (onChange) {
+ this.quill.on("text-change", this.textChangeHandler);
+ }
+ }
+
+ componentWillUnmount() {
+ this.quill.off("text-change", this.textChangeHandler);
+ }
+
+ textChangeHandler = (delta, oldDelta, source) => {
+ if (source === "api") return;
+ this.props.onChange(this.quill);
+ };
+
+ render() {
+ console.log("rendering + ", this.props.refresh);
+ return <pre id="quill" />;
+ }
+}
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index d142d8479..b792699da 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -6955,7 +6955,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@https://github.com/thecodrr/notes-core.git":
version "1.1.0"
- resolved "https://github.com/thecodrr/notes-core.git#47caff445840c830a29818f3a666f40e1e361684"
+ resolved "https://github.com/thecodrr/notes-core.git#2fe2fe821d6d7cccc381bc876e221398db5a061c"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"
@@ -8449,7 +8449,7 @@ quill-markdown-shortcuts@^0.0.10:
dependencies:
quill "^1.3.1"
-quill@^1.3.1:
+quill@^1.3.1, quill@^1.3.6:
version "1.3.7"
resolved "https://registry.yarnpkg.com/quill/-/quill-1.3.7.tgz#da5b2f3a2c470e932340cdbf3668c9f21f9286e8"
integrity sha512-hG/DVzh/TiknWtE6QmWAF/pxoZKYxfe3J/d/+ShUWkDvvkZQVTPeVmUJVu1uE6DDooC4fWTiCLh84ul89oNz5g==