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 note loading in editor
ammarahm-ed168c7855b1d0
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.jsindex 3d7dd0b6e..8a49b3667 100755--- a/apps/mobile/html/Web.bundle/site/init.js+++ b/apps/mobile/html/Web.bundle/site/init.js@@ -263,6 +263,109 @@ function init_tiny(size) {console.error(e);}},+ init_instance_callback: function (_editor) {+ editor = _editor;+ setTheme();++ editor.on('SelectionChange', function (e) {+ selectchange();+ });++ editor.on('ClearUndos', onUndoChange);+ editor.on('Undo', onUndoChange);+ editor.on('Redo', onUndoChange);+ editor.on('TypingUndos', onUndoChange);+ editor.on('BeforeAddUndo', onUndoChange);+ editor.on('AddUndo', onUndoChange);+ editor.on('cut', function () {+ onChange({type: 'cut'});+ onUndoChange();+ });+ editor.on('copy', onUndoChange);+ editor.on('paste', function () {+ onChange({type: 'paste'});+ });++ editor.on('focus', function () {+ reactNativeEventHandler('focus', 'editor');+ });++ editor.on('SetContent', function (event) {+ console.log('content set', event.paste, globalThis.isClearingNoteData);+ if (globalThis.isClearingNoteData) {+ globalThis.isClearingNoteData = false;+ return;+ }+ setTimeout(function () {+ editor.undoManager.transact(function () {});+ }, 1000);+ if (!event.paste) {+ reactNativeEventHandler('noteLoaded', true);+ }+ if (event.paste) {+ isLoading = false;+ onChange(event);+ }+ });++ editor.on('NewBlock', function (e) {+ console.log('New Block');+ const {newBlock} = e;+ let target;+ if (newBlock) {+ target = newBlock.previousElementSibling;+ }+ if (target && target.classList.contains(COLLAPSED_KEY)) {+ target.classList.remove(COLLAPSED_KEY);+ collapseElement(target);+ }+ });++ editor.on('touchstart mousedown', function (e) {+ const {target} = e;+ if (+ e.offsetX < 6 &&+ collapsibleTags[target.tagName] &&+ target.parentElement &&+ target.parentElement.tagName === 'BODY'+ ) {+ e.preventDefault();+ e.stopImmediatePropagation();+ e.stopPropagation();+ editor.undoManager.transact(function () {+ if (target.classList.contains(COLLAPSED_KEY)) {+ target.classList.remove(COLLAPSED_KEY);+ } else {+ target.classList.add(COLLAPSED_KEY);+ }+ collapseElement(target);+ editor.getHTML().then(function (html) {+ reactNativeEventHandler('tiny', html);+ });+ });+ }+ });++ editor.on('tap', function (e) {+ if (+ e.target.classList.contains('mce-content-body') &&+ !e.target.innerText.length > 0+ ) {+ e.preventDefault();+ }+ });+ editor.on('ScrollIntoView', function (e) {+ e.preventDefault();+ e.elm.scrollIntoView({+ behavior: 'smooth',+ block: 'nearest'+ });+ });+ editor.on('input', onChange);+ editor.on('keyup', onChange);+ editor.on('NodeChange', onChange);+ editor.on('compositionend', onChange);+ },setup: function (_editor) {editor = _editor;editor.ui.registry.addButton('deleteimage', {@@ -281,9 +384,7 @@ function init_tiny(size) {});editor.on('init', function (e) {- setTimeout(function () {- reactNativeEventHandler('status', true);- }, 300);+ reactNativeEventHandler('status', true);});editor.ui.registry.addButton('deletevideo', {@@ -366,107 +467,6 @@ function init_tiny(size) {},onclick: function () {}});- },- init_instance_callback: function (_editor) {- editor = _editor;- setTheme();-- editor.on('SelectionChange', function (e) {- selectchange();- });-- editor.on('ClearUndos', onUndoChange);- editor.on('Undo', onUndoChange);- editor.on('Redo', onUndoChange);- editor.on('TypingUndos', onUndoChange);- editor.on('BeforeAddUndo', onUndoChange);- editor.on('AddUndo', onUndoChange);- editor.on('cut', function () {- onChange({type: 'cut'});- onUndoChange();- });- editor.on('copy', onUndoChange);- editor.on('paste', function () {- onChange({type: 'paste'});- });-- if (- e.target.classList.contains("mce-content-body") &&- !e.target.innerText.length > 0- ) {- e.preventDefault();- }-- editor.on('focus', function () {- reactNativeEventHandler('focus', 'editor');- });-- editor.on('SetContent', function (event) {- if (globalThis.isClearingNoteData) {- globalThis.isClearingNoteData = false;- return;- }- setTimeout(function() {- editor.undoManager.transact(function () {});- },1000);- if (!event.paste) {- reactNativeEventHandler('noteLoaded', true);- }- if (event.paste) {- isLoading = false;- onChange(event);- }- });-- editor.on('NewBlock', function (e) {- console.log('New Block');- const {newBlock} = e;- let target;- if (newBlock) {- target = newBlock.previousElementSibling;- }- if (target && target.classList.contains(COLLAPSED_KEY)) {- target.classList.remove(COLLAPSED_KEY);- collapseElement(target);- }- });-- editor.on('touchstart mousedown', function (e) {- const {target} = e;- if (- e.offsetX < 6 &&- collapsibleTags[target.tagName] &&- target.parentElement &&- target.parentElement.tagName === 'BODY'- ) {- e.preventDefault();- e.stopImmediatePropagation();- e.stopPropagation();- editor.undoManager.transact(function () {- if (target.classList.contains(COLLAPSED_KEY)) {- target.classList.remove(COLLAPSED_KEY);- } else {- target.classList.add(COLLAPSED_KEY);- }- collapseElement(target);- editor.getHTML().then(function (html) {- reactNativeEventHandler('tiny', html);- });- });- }- });-- editor.on('ScrollIntoView', function (e) {- e.preventDefault();- e.elm.scrollIntoView({- behavior: 'smooth',- block: 'nearest'- });- });- editor.on('input', onChange);- editor.on('keyup', onChange);- editor.on('NodeChange', onChange);- editor.on('compositionend', onChange);}});}diff --git a/apps/mobile/src/views/Editor/EditorOverlay.js b/apps/mobile/src/views/Editor/EditorOverlay.jsindex 8919c9313..840c1a95a 100644--- a/apps/mobile/src/views/Editor/EditorOverlay.js+++ b/apps/mobile/src/views/Editor/EditorOverlay.js@@ -44,7 +44,6 @@ const EditorOverlay = () => {easing: Easing.in(Easing.ease)}).start();timerClosing = setTimeout(() => {- console.log('clearing now');opacity.setValue(1);setLoading(null);}, 150);diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex e9650ee6b..1bd5e26c2 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -1,8 +1,8 @@-import {createRef} from 'react';-import {Platform} from 'react-native';-import {presentDialog} from '../../components/Dialog/functions';-import {useEditorStore, useMenuStore} from '../../provider/stores';-import {DDS} from '../../services/DeviceDetection';+import { createRef } from 'react';+import { Platform } from 'react-native';+import { presentDialog } from '../../components/Dialog/functions';+import { useEditorStore, useMenuStore } from '../../provider/stores';+import { DDS } from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,@@ -10,24 +10,23 @@ import {} from '../../services/EventManager';import Navigation from '../../services/Navigation';import PremiumService from '../../services/PremiumService';-import {editing} from '../../utils';-import {COLORS_NOTE, COLOR_SCHEME} from '../../utils/Colors';-import {hexToRGBA} from '../../utils/ColorUtils';-import {db} from '../../utils/database';+import { editing } from '../../utils';+import { COLORS_NOTE, COLOR_SCHEME } from '../../utils/Colors';+import { hexToRGBA } from '../../utils/ColorUtils';+import { db } from '../../utils/database';import {eOnLoadNote,eShowGetPremium,eShowMergeDialog} from '../../utils/Events';import filesystem from '../../utils/filesystem';-import {openLinkInBrowser} from '../../utils/functions';-import {MMKV} from '../../utils/mmkv';-import {tabBarRef} from '../../utils/Refs';-import {normalize} from '../../utils/SizeUtils';-import {sleep, timeConverter} from '../../utils/TimeUtils';+import { openLinkInBrowser } from '../../utils/functions';+import { MMKV } from '../../utils/mmkv';+import { tabBarRef } from '../../utils/Refs';+import { normalize } from '../../utils/SizeUtils';+import { sleep, timeConverter } from '../../utils/TimeUtils';import tiny from './tiny/tiny';-import {IMAGE_TOOLTIP_CONFIG} from './tiny/toolbar/config';-import {parse} from 'node-html-parser';+import { IMAGE_TOOLTIP_CONFIG } from './tiny/toolbar/config';export let EditorWebView = createRef();export const editorTitleInput = createRef();@@ -59,6 +58,7 @@ let disableSaving = false;let isSaving = false;let waitForContent = false;let prevNoteContent = null;+let timerForEditor = null;export function startClosingSession() {closingSession = true;@@ -234,7 +234,6 @@ function clearNote() {type: 'tiny'};}-export const loadNote = async item => {console.log('.....OPEN NOTE.....');editing.currentlyEditing = true;@@ -281,6 +280,7 @@ export const loadNote = async item => {if (!webviewInit) {EditorWebView.current?.reload();}+tiny.call(EditorWebView, tiny.notLoading);checkStatus();} else {@@ -651,6 +651,7 @@ export async function onWebViewLoad(premium, colors) {} else {tiny.call(EditorWebView, tiny.removeMarkdown, true);}+if (getNote()?.id) {loadNoteInEditor();}@@ -701,17 +702,18 @@ export const presentResolveConflictDialog = _note => {};const loadNoteInEditor = async (keepHistory = true) => {- console.log('loading note', id, webviewInit);-- if (!webviewInit) return;- saveCounter = 0;- if (note?.id) {- post('title', title);- intent = false;- if (!content || !content.data || content?.data?.length === 0) {- tiny.call(- EditorWebView,- `+ clearTimeout(timerForEditor);+ timerForEditor = setTimeout(async () => {+ if (!webviewInit) return;++ console.log('loading note', id, webviewInit);+ if (note?.id) {+ post('title', title);+ intent = false;+ if (!content || !content.data || content?.data?.length === 0) {+ tiny.call(+ EditorWebView,+ `globalThis.isClearingNoteData = false;window.ReactNativeWebView.postMessage(JSON.stringify({@@ -720,30 +722,30 @@ const loadNoteInEditor = async (keepHistory = true) => {}),);`+ );+ } else {+ console.log('opening in editor', content.data);+ post('html', content.data);+ }+ if (id) {+ db.attachments.downloadImages(id);+ }++ setColors();+ tiny.call(+ EditorWebView,+ tiny.updateDateEdited(timeConverter(note.dateEdited)));+ tiny.call(EditorWebView, tiny.updateSavingState('Saved'));} else {- console.log('opening in editor');- post('html', content.data);+ await restoreEditorState();}- if (id) {- db.attachments.downloadImages(id);+ loadingNote = null;+ disableSaving = false;+ if (keepHistory) {+ tiny.call(EditorWebView, tiny.clearHistory);}-- setColors();- tiny.call(- EditorWebView,- tiny.updateDateEdited(timeConverter(note.dateEdited))- );- tiny.call(EditorWebView, tiny.updateSavingState('Saved'));- } else {- await restoreEditorState();- }- await sleep(500);- loadingNote = null;- disableSaving = false;- if (keepHistory) {- tiny.call(EditorWebView, tiny.clearHistory);- }+ }, 50);};export async function updateNoteInEditor() {