A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix editor is sometimes null
ammarahm-ed3ea0afa7c925
diff --git a/apps/mobile/android/app/src/main/assets/constants.js b/apps/mobile/android/app/src/main/assets/constants.jsindex a0d5f6616..093b7ac0d 100644--- a/apps/mobile/android/app/src/main/assets/constants.js+++ b/apps/mobile/android/app/src/main/assets/constants.js@@ -22,25 +22,38 @@ let pageTheme = {};function dark() {- if (!editor) return;- editor.dom.styleSheetLoader.unload('dist/skins/notesnook/content.min.css');- editor.dom.styleSheetLoader.load('dist/skins/notesnook-dark/content.min.css');- editor.ui.styleSheetLoader.unload('dist/skins/notesnook/skin.min.css');- editor.ui.styleSheetLoader.load('dist/skins/notesnook-dark/skin.min.css');+ if (!tinymce.activeEditor) return;+ tinymce.activeEditor.dom.styleSheetLoader.unload(+ 'dist/skins/notesnook/content.min.css',+ );+ tinymce.activeEditor.dom.styleSheetLoader.load(+ 'dist/skins/notesnook-dark/content.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.unload(+ 'dist/skins/notesnook/skin.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.load(+ 'dist/skins/notesnook-dark/skin.min.css',+ );}function light() {- if (!editor) return;- editor.dom.styleSheetLoader.unload(+ if (!tinymce.activeEditor) return;+ tinymce.activeEditor.dom.styleSheetLoader.unload('dist/skins/notesnook-dark/content.min.css',);- editor.dom.styleSheetLoader.load('dist/skins/notesnook/content.min.css');- editor.ui.styleSheetLoader.unload('dist/skins/notesnook-dark/skin.min.css');- editor.ui.styleSheetLoader.load('dist/skins/notesnook/skin.min.css');+ tinymce.activeEditor.dom.styleSheetLoader.load(+ 'dist/skins/notesnook/content.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.unload(+ 'dist/skins/notesnook-dark/skin.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.load(+ 'dist/skins/notesnook/skin.min.css',+ );}function setTheme() {-if (pageTheme.colors.night) {dark();} else {@@ -100,16 +113,14 @@ var minifyImg = function (});};--function loadImage() {let fileInput = document.querySelector('#image-input');let listener = () => {if (fileInput.files != null && fileInput.files[0] != null) {let reader = new FileReader();- console.log(reader.readyState,"READY STATE");+ console.log(reader.readyState, 'READY STATE');let load = (e) => {- console.log(e,'loaded error');+ console.log(e, 'loaded error');minifyImg(reader.result,600,@@ -132,14 +143,13 @@ function loadImage() {};reader.onabort = () => {console.log('abort');- }+ };reader.addEventListener('load', load);reader.addEventListener('error', error);reader.readAsDataURL(fileInput.files[0]);}};-fileInput.addEventListener('change', listener);fileInput.click();}diff --git a/apps/mobile/android/app/src/main/assets/init.js b/apps/mobile/android/app/src/main/assets/init.jsindex 4133d7a4f..f50abe5ca 100644--- a/apps/mobile/android/app/src/main/assets/init.js+++ b/apps/mobile/android/app/src/main/assets/init.js@@ -13,7 +13,7 @@ function reactNativeEventHandler(type, value) {let changeTimer = null;let isLoading = true;-+let editor = null;function init_tiny(size) {tinymce.init({selector: '#tiny_textarea',@@ -53,23 +53,23 @@ function init_tiny(size) {return;}changeTimer = setTimeout(() => {- if (editor.plugins.wordcount.getCount() === 0) return;+ if (tinymce.activeEditor.plugins.wordcount.getCount() === 0) return;selectchange();reactNativeEventHandler('tiny', editor.getContent());reactNativeEventHandler('history', {- undo: editor.undoManager.hasUndo(),- redo: editor.undoManager.hasRedo(),+ undo: tinymce.activeEditor.undoManager.hasUndo(),+ redo: tinymce.activeEditor.undoManager.hasRedo(),});}, 5);});editor.on('focus', () => {reactNativeEventHandler('focus', 'editor');});- editor.on("SetContent", event => {+ editor.on('SetContent', (event) => {if (!event.paste) {reactNativeEventHandler('noteLoaded', true);}- })+ });editor.on('Change', function (e) {clearTimeout(changeTimer);if (isLoading) {@@ -78,18 +78,15 @@ function init_tiny(size) {}changeTimer = setTimeout(() => {- if (editor.plugins.wordcount.getCount() === 0) return;+ if (tinymce.activeEditor.plugins.wordcount.getCount() === 0) return;selectchange();- reactNativeEventHandler('tiny', editor.getContent());+ reactNativeEventHandler('tiny', tinymce.activeEditor.getContent());reactNativeEventHandler('history', {- undo: editor.undoManager.hasUndo(),- redo: editor.undoManager.hasRedo(),+ undo: tinymce.activeEditor.undoManager.hasUndo(),+ redo: tinymce.activeEditor.undoManager.hasRedo(),});}, 5);});- editor.on('ExecCommand', function (e) {- //reactNativeEventHandler(e);- });},});}@@ -108,24 +105,24 @@ function getNodeBg(element) {return null;}-function selectchange() {+function selectchange(editor) {info = document.querySelector('.info-bar');info.querySelector('#infowords').innerText =- editor.plugins.wordcount.getCount() + ' words';+ tinymce.activeEditor.plugins.wordcount.getCount() + ' words';- let formats = Object.keys(editor.formatter.get());+ let formats = Object.keys(tinymce.activeEditor.formatter.get());let currentFormats = {};- editor.formatter+ tinymce.activeEditor.formatter.matchAll(formats).forEach((format) => (currentFormats[format] = true));- let node = editor.selection.getNode();+ let node = tinymce.activeEditor.selection.getNode();currentFormats.hilitecolor = getNodeBg(node);currentFormats.forecolor = getNodeColor(node);if (!currentFormats.hilitecolor || !currentFormats.forecolor) {for (var i = 0; i < node.children.length; i++) {- let item = editor.selection.getNode().children.item(i);+ let item = tinymce.activeEditor.selection.getNode().children.item(i);currentFormats.hilitecolor = getNodeBg(item);currentFormats.forecolor = getNodeColor(item);}@@ -161,15 +158,15 @@ function selectchange() {currentFormats.link = node.getAttribute('href');}- currentFormats.fontname = editor.selection.getNode().style.fontFamily;+ currentFormats.fontname = tinymce.activeEditor.selection.getNode().style.fontFamily;if (/^(LI|UL|OL|DL)$/.test(node.nodeName)) {- let listElm = editor.selection.getNode();+ let listElm = tinymce.activeEditor.selection.getNode();if (listElm.nodeName === 'LI') {- listElm = editor.dom.getParent(listElm, 'ol,ul');+ listElm = tinymce.activeEditor.dom.getParent(listElm, 'ol,ul');}- let style = editor.dom.getStyle(listElm, 'listStyleType');+ let style = tinymce.activeEditor.dom.getStyle(listElm, 'listStyleType');if (style === '') {style = 'default';}diff --git a/apps/mobile/android/app/src/main/assets/listeners.js b/apps/mobile/android/app/src/main/assets/listeners.jsindex a78bea696..52ebe87f0 100644--- a/apps/mobile/android/app/src/main/assets/listeners.js+++ b/apps/mobile/android/app/src/main/assets/listeners.js@@ -8,37 +8,42 @@ function attachTitleInputListeners() {'DOMContentLoaded',() => {autosize();- document- .body.onscroll = (event) => {- if (scrollTimer) {- clearTimeout(scrollTimer);- scrollTimer = null;- }- scrollTimer = setTimeout(() => {- window.ReactNativeWebView.postMessage(- JSON.stringify({- visible: event.target.documentElement.scrollTop.scrollTop,- title: document.getElementById("titleInput").value,- type: 'scroll',- }),- );- }, 100);+ document.body.onscroll = (event) => {+ if (scrollTimer) {+ clearTimeout(scrollTimer);+ scrollTimer = null;}+ scrollTimer = setTimeout(() => {+ window.ReactNativeWebView.postMessage(+ JSON.stringify({+ visible: event.target.documentElement.scrollTop.scrollTop,+ title: document.getElementById('titleInput').value,+ type: 'scroll',+ }),+ );+ }, 100);+ };},false,);document.getElementById('formBox').onsubmit = function (evt) {evt.preventDefault();- editor.focus();- editor.setSelection(editor.getText().length - 1, 0);+ if (tinymce.activeEditor) {+ tinymce.activeEditor && tinymce.activeEditor.focus();+ }+onTitleChange();};titleInput.onkeypress = function (evt) {if (evt.keyCode === 13 || evt.which === 13) {evt.preventDefault();- editor.focus();+ if (tinymce.activeEditor) {+ tinymce.activeEditor && tinymce.activeEditor.focus();+ }++onTitleChange();return false;}@@ -68,14 +73,17 @@ function attachTitleInputListeners() {}function onTitleChange(ele) {- if (isLoading) return;+ if (isLoading) return;let titleMessage = {type: 'title',value: titleInput.value,};+info = document.querySelector(infoBar);- info.querySelector('#infowords').innerText =- editor.plugins.wordcount.getCount() + ' words';+ if (tinymce.activeEditor) {+ info.querySelector('#infowords').innerText =+ tinymce.activeEditor.plugins.wordcount.getCount() + ' words';+ }autosize();if (titleMessage && typeof titleMessage.value === 'string') {diff --git a/apps/mobile/html/Web.bundle/site/constants.js b/apps/mobile/html/Web.bundle/site/constants.jsindex a0d5f6616..093b7ac0d 100644--- a/apps/mobile/html/Web.bundle/site/constants.js+++ b/apps/mobile/html/Web.bundle/site/constants.js@@ -22,25 +22,38 @@ let pageTheme = {};function dark() {- if (!editor) return;- editor.dom.styleSheetLoader.unload('dist/skins/notesnook/content.min.css');- editor.dom.styleSheetLoader.load('dist/skins/notesnook-dark/content.min.css');- editor.ui.styleSheetLoader.unload('dist/skins/notesnook/skin.min.css');- editor.ui.styleSheetLoader.load('dist/skins/notesnook-dark/skin.min.css');+ if (!tinymce.activeEditor) return;+ tinymce.activeEditor.dom.styleSheetLoader.unload(+ 'dist/skins/notesnook/content.min.css',+ );+ tinymce.activeEditor.dom.styleSheetLoader.load(+ 'dist/skins/notesnook-dark/content.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.unload(+ 'dist/skins/notesnook/skin.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.load(+ 'dist/skins/notesnook-dark/skin.min.css',+ );}function light() {- if (!editor) return;- editor.dom.styleSheetLoader.unload(+ if (!tinymce.activeEditor) return;+ tinymce.activeEditor.dom.styleSheetLoader.unload('dist/skins/notesnook-dark/content.min.css',);- editor.dom.styleSheetLoader.load('dist/skins/notesnook/content.min.css');- editor.ui.styleSheetLoader.unload('dist/skins/notesnook-dark/skin.min.css');- editor.ui.styleSheetLoader.load('dist/skins/notesnook/skin.min.css');+ tinymce.activeEditor.dom.styleSheetLoader.load(+ 'dist/skins/notesnook/content.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.unload(+ 'dist/skins/notesnook-dark/skin.min.css',+ );+ tinymce.activeEditor.ui.styleSheetLoader.load(+ 'dist/skins/notesnook/skin.min.css',+ );}function setTheme() {-if (pageTheme.colors.night) {dark();} else {@@ -100,16 +113,14 @@ var minifyImg = function (});};--function loadImage() {let fileInput = document.querySelector('#image-input');let listener = () => {if (fileInput.files != null && fileInput.files[0] != null) {let reader = new FileReader();- console.log(reader.readyState,"READY STATE");+ console.log(reader.readyState, 'READY STATE');let load = (e) => {- console.log(e,'loaded error');+ console.log(e, 'loaded error');minifyImg(reader.result,600,@@ -132,14 +143,13 @@ function loadImage() {};reader.onabort = () => {console.log('abort');- }+ };reader.addEventListener('load', load);reader.addEventListener('error', error);reader.readAsDataURL(fileInput.files[0]);}};-fileInput.addEventListener('change', listener);fileInput.click();}diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.jsindex 4133d7a4f..f50abe5ca 100644--- a/apps/mobile/html/Web.bundle/site/init.js+++ b/apps/mobile/html/Web.bundle/site/init.js@@ -13,7 +13,7 @@ function reactNativeEventHandler(type, value) {let changeTimer = null;let isLoading = true;-+let editor = null;function init_tiny(size) {tinymce.init({selector: '#tiny_textarea',@@ -53,23 +53,23 @@ function init_tiny(size) {return;}changeTimer = setTimeout(() => {- if (editor.plugins.wordcount.getCount() === 0) return;+ if (tinymce.activeEditor.plugins.wordcount.getCount() === 0) return;selectchange();reactNativeEventHandler('tiny', editor.getContent());reactNativeEventHandler('history', {- undo: editor.undoManager.hasUndo(),- redo: editor.undoManager.hasRedo(),+ undo: tinymce.activeEditor.undoManager.hasUndo(),+ redo: tinymce.activeEditor.undoManager.hasRedo(),});}, 5);});editor.on('focus', () => {reactNativeEventHandler('focus', 'editor');});- editor.on("SetContent", event => {+ editor.on('SetContent', (event) => {if (!event.paste) {reactNativeEventHandler('noteLoaded', true);}- })+ });editor.on('Change', function (e) {clearTimeout(changeTimer);if (isLoading) {@@ -78,18 +78,15 @@ function init_tiny(size) {}changeTimer = setTimeout(() => {- if (editor.plugins.wordcount.getCount() === 0) return;+ if (tinymce.activeEditor.plugins.wordcount.getCount() === 0) return;selectchange();- reactNativeEventHandler('tiny', editor.getContent());+ reactNativeEventHandler('tiny', tinymce.activeEditor.getContent());reactNativeEventHandler('history', {- undo: editor.undoManager.hasUndo(),- redo: editor.undoManager.hasRedo(),+ undo: tinymce.activeEditor.undoManager.hasUndo(),+ redo: tinymce.activeEditor.undoManager.hasRedo(),});}, 5);});- editor.on('ExecCommand', function (e) {- //reactNativeEventHandler(e);- });},});}@@ -108,24 +105,24 @@ function getNodeBg(element) {return null;}-function selectchange() {+function selectchange(editor) {info = document.querySelector('.info-bar');info.querySelector('#infowords').innerText =- editor.plugins.wordcount.getCount() + ' words';+ tinymce.activeEditor.plugins.wordcount.getCount() + ' words';- let formats = Object.keys(editor.formatter.get());+ let formats = Object.keys(tinymce.activeEditor.formatter.get());let currentFormats = {};- editor.formatter+ tinymce.activeEditor.formatter.matchAll(formats).forEach((format) => (currentFormats[format] = true));- let node = editor.selection.getNode();+ let node = tinymce.activeEditor.selection.getNode();currentFormats.hilitecolor = getNodeBg(node);currentFormats.forecolor = getNodeColor(node);if (!currentFormats.hilitecolor || !currentFormats.forecolor) {for (var i = 0; i < node.children.length; i++) {- let item = editor.selection.getNode().children.item(i);+ let item = tinymce.activeEditor.selection.getNode().children.item(i);currentFormats.hilitecolor = getNodeBg(item);currentFormats.forecolor = getNodeColor(item);}@@ -161,15 +158,15 @@ function selectchange() {currentFormats.link = node.getAttribute('href');}- currentFormats.fontname = editor.selection.getNode().style.fontFamily;+ currentFormats.fontname = tinymce.activeEditor.selection.getNode().style.fontFamily;if (/^(LI|UL|OL|DL)$/.test(node.nodeName)) {- let listElm = editor.selection.getNode();+ let listElm = tinymce.activeEditor.selection.getNode();if (listElm.nodeName === 'LI') {- listElm = editor.dom.getParent(listElm, 'ol,ul');+ listElm = tinymce.activeEditor.dom.getParent(listElm, 'ol,ul');}- let style = editor.dom.getStyle(listElm, 'listStyleType');+ let style = tinymce.activeEditor.dom.getStyle(listElm, 'listStyleType');if (style === '') {style = 'default';}diff --git a/apps/mobile/html/Web.bundle/site/listeners.js b/apps/mobile/html/Web.bundle/site/listeners.jsindex a78bea696..52ebe87f0 100644--- a/apps/mobile/html/Web.bundle/site/listeners.js+++ b/apps/mobile/html/Web.bundle/site/listeners.js@@ -8,37 +8,42 @@ function attachTitleInputListeners() {'DOMContentLoaded',() => {autosize();- document- .body.onscroll = (event) => {- if (scrollTimer) {- clearTimeout(scrollTimer);- scrollTimer = null;- }- scrollTimer = setTimeout(() => {- window.ReactNativeWebView.postMessage(- JSON.stringify({- visible: event.target.documentElement.scrollTop.scrollTop,- title: document.getElementById("titleInput").value,- type: 'scroll',- }),- );- }, 100);+ document.body.onscroll = (event) => {+ if (scrollTimer) {+ clearTimeout(scrollTimer);+ scrollTimer = null;}+ scrollTimer = setTimeout(() => {+ window.ReactNativeWebView.postMessage(+ JSON.stringify({+ visible: event.target.documentElement.scrollTop.scrollTop,+ title: document.getElementById('titleInput').value,+ type: 'scroll',+ }),+ );+ }, 100);+ };},false,);document.getElementById('formBox').onsubmit = function (evt) {evt.preventDefault();- editor.focus();- editor.setSelection(editor.getText().length - 1, 0);+ if (tinymce.activeEditor) {+ tinymce.activeEditor && tinymce.activeEditor.focus();+ }+onTitleChange();};titleInput.onkeypress = function (evt) {if (evt.keyCode === 13 || evt.which === 13) {evt.preventDefault();- editor.focus();+ if (tinymce.activeEditor) {+ tinymce.activeEditor && tinymce.activeEditor.focus();+ }++onTitleChange();return false;}@@ -68,14 +73,17 @@ function attachTitleInputListeners() {}function onTitleChange(ele) {- if (isLoading) return;+ if (isLoading) return;let titleMessage = {type: 'title',value: titleInput.value,};+info = document.querySelector(infoBar);- info.querySelector('#infowords').innerText =- editor.plugins.wordcount.getCount() + ' words';+ if (tinymce.activeEditor) {+ info.querySelector('#infowords').innerText =+ tinymce.activeEditor.plugins.wordcount.getCount() + ' words';+ }autosize();if (titleMessage && typeof titleMessage.value === 'string') {