Skip to content

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

feat: lock editor features

thecodrrd8fd41004919
diff --git a/apps/web/src/components/editor/react-quill.js b/apps/web/src/components/editor/react-quill.js
index 5b8af33b7..55d88122b 100644
--- a/apps/web/src/components/editor/react-quill.js
+++ b/apps/web/src/components/editor/react-quill.js
@@ -1,5 +1,7 @@
import React, { Component } from "react";
import Quill from "quill";
+import Toolbar from "quill/modules/toolbar";
+import BaseTheme from "quill/themes/base";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.core.css";
import "./modules/betterlist";
@@ -8,33 +10,83 @@ import MagicUrl from "quill-magic-url";
import { Text } from "rebass";
import QuillFocus from "./modules/focus";
import { isMobile } from "../../utils/dimensions";
+import { showBuyDialog } from "../dialogs/buy-dialog";
Quill.register("modules/markdownShortcuts", MarkdownShortcuts);
Quill.register("modules/magicUrl", MagicUrl);
Quill.register("modules/focus", QuillFocus);
+function moduleHandlerWrapper(type, isSimple) {
+ return async function (value) {
+ if (isSimple) {
+ await showBuyDialog();
+ return;
+ }
+ handlers[type].call(this, value);
+ };
+}
+
+const handlers = {
+ ...Toolbar.DEFAULTS.handlers,
+ ...BaseTheme.DEFAULTS.modules.toolbar.handlers,
+ color: function (color) {
+ this.quill.format("color", color, "user");
+ },
+ background: function (color) {
+ this.quill.format("background", color, "user");
+ },
+ align: function (position) {
+ this.quill.format("align", position, "user");
+ },
+ "code-block": function (value) {
+ this.quill.format("code-block", value, "user");
+ },
+ size: function (value) {
+ this.quill.format("size", value, "user");
+ },
+ script: function (value) {
+ this.quill.format("script", value, "user");
+ },
+};
+
const quillModules = (isSimple, isFocusMode, isMobile) => ({
toolbar: isMobile
- ? ["bold", "italic", "underline"]
- : [
- ["bold", "italic", "underline", "strike", "blockquote"],
- [{ header: "2" }, { header: "3" }, { header: [false, 4, 5, 6] }],
- [
- { align: "" },
- { align: "center" },
- { align: "right" },
- { align: "justify" },
+ ? [{ header: "2" }, "bold", "italic", "underline", "link", "code-block"]
+ : {
+ container: [
+ ["bold", "italic", "underline", "strike", "blockquote"],
+ [{ header: "2" }, { header: "3" }, { header: [false, 4, 5, 6] }],
+ [
+ { align: "" },
+ { align: "center" },
+ { align: "right" },
+ { align: "justify" },
+ ],
+ [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
+ [{ indent: "-1" }, { indent: "+1" }],
+ [{ size: ["small", false, "large", "huge"] }],
+ ["code-block", { script: "sub" }, { script: "super" }],
+ [{ color: [] }, { background: [] }],
+ ["link", "image", "video"],
+ [{ direction: "rtl" }, "clean"],
],
- [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
- [{ indent: "-1" }, { indent: "+1" }],
- [{ size: ["small", false, "large", "huge"] }],
- ["code-block", { script: "sub" }, { script: "super" }],
- [{ color: [] }, { background: [] }],
- ["link", "image", "video"],
- [{ direction: "rtl" }, "clean"],
- ],
+ handlers: {
+ list: moduleHandlerWrapper("list", isSimple),
+ indent: moduleHandlerWrapper("indent", isSimple),
+ direction: moduleHandlerWrapper("direction", isSimple),
+ image: moduleHandlerWrapper("image", isSimple),
+ video: moduleHandlerWrapper("video", isSimple),
+ formula: moduleHandlerWrapper("formula", isSimple),
+ color: moduleHandlerWrapper("formula", isSimple),
+ background: moduleHandlerWrapper("background", isSimple),
+ align: moduleHandlerWrapper("align", isSimple),
+ "code-block": moduleHandlerWrapper("code-block", isSimple),
+ size: moduleHandlerWrapper("size", isSimple),
+ script: moduleHandlerWrapper("script", isSimple),
+ },
+ },
// syntax: true,
- markdownShortcuts: {},
+ markdownShortcuts: isSimple ? undefined : {},
magicUrl: true,
history: { maxStack: 1000 * 5 },
focus: {
@@ -54,7 +106,6 @@ export default class ReactQuill extends Component {
}
shouldComponentUpdate(nextProps) {
- console.log("should", nextProps.isFocusMode, this.props.isFocusMode);
return (
this.props.readOnly !== nextProps.readOnly ||
this.props.isSimple !== nextProps.isSimple ||