Skip to content

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

refactor: cleanup premium commands detection logic

thecodrr96e461d5e587
diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.js
index baf3b0455..ea1eabde6 100644
--- a/apps/web/src/components/editor/tinymce.js
+++ b/apps/web/src/components/editor/tinymce.js
@@ -223,23 +223,15 @@ function TinyMCE(props) {
},
}}
onBeforeExecCommand={async (command) => {
- if (
- premiumCommands.some((cmd) => {
- let isPremium = command.command === cmd && !command?.value?.paste;
- if (
- command.command === "mceInsertContent" &&
- !command?.value?.paste
- ) {
- isPremium =
- command.value.startsWith(`<pre`) ||
- command.value.startsWith(`<table`) ||
- command.value.startsWith(`<img`) ||
- command.value.includes("tox-checklist");
- }
- return isPremium;
- }) &&
- !isUserPremium
- ) {
+ const isPremiumCommand = premiumCommands.some((cmd) => {
+ const { value, command: commandName } = command;
+ let isPremium = commandName === cmd && !value?.paste;
+ if (commandName === "mceInsertContent" && !value?.paste) {
+ isPremium = /^<(?:pre|table|img)|tox-checklist/gm.test(value);
+ }
+ return isPremium;
+ });
+ if (isPremiumCommand && !isUserPremium) {
command.preventDefault();
command.stopImmediatePropagation();
command.stopPropagation();