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
update image controls
ammarahm-ed48c02d651381
diff --git a/apps/mobile/android/app/src/main/assets/init.js b/apps/mobile/android/app/src/main/assets/init.jsindex d506c3fbe..c972bd950 100755--- a/apps/mobile/android/app/src/main/assets/init.js+++ b/apps/mobile/android/app/src/main/assets/init.js@@ -74,13 +74,13 @@ function init_tiny(size) {table_toolbar:'tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',imagetools_toolbar:- 'rotateleft rotateright flipv fliph | imageoptions | deleteimage | imagepreview',+ 'rotateleft rotateright flipv fliph | imageopts ',placeholder: 'Start writing your note here',object_resizing: true,resize: true,mobile: {- resize: true,- object_resizing: true,+ resize: false,+ object_resizing: false,},image_description: false,image_caption: false,@@ -95,10 +95,21 @@ function init_tiny(size) {icon: 'remove',tooltip: 'Remove image',onAction: function () {- tinymce.activeEditor.execCommand('Delete');+ editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});},onclick: function () {- tinymce.activeEditor.execCommand('Delete');+ editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});++ }+ });+ editor.ui.registry.addButton('imageopts', {+ icon: 'image-options',+ tooltip: 'Image properties',+ onAction: function () {+ reactNativeEventHandler("imageoptions");+ },+ onclick: function () {+ reactNativeEventHandler("imageoptions");}});@@ -284,5 +295,6 @@ function selectchange() {}}}+ currentFormats.node = editor.selection.getNode().nodeName;reactNativeEventHandler('selectionchange', currentFormats);}diff --git a/apps/mobile/babel.config.js b/apps/mobile/babel.config.jsindex 7c6341171..05226461e 100644--- a/apps/mobile/babel.config.js+++ b/apps/mobile/babel.config.js@@ -1,6 +1,6 @@module.exports = {presets: ['module:metro-react-native-babel-preset'],plugins: [- "transform-remove-console"+ //"transform-remove-console"]};diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.jsindex d506c3fbe..c972bd950 100755--- a/apps/mobile/html/Web.bundle/site/init.js+++ b/apps/mobile/html/Web.bundle/site/init.js@@ -74,13 +74,13 @@ function init_tiny(size) {table_toolbar:'tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',imagetools_toolbar:- 'rotateleft rotateright flipv fliph | imageoptions | deleteimage | imagepreview',+ 'rotateleft rotateright flipv fliph | imageopts ',placeholder: 'Start writing your note here',object_resizing: true,resize: true,mobile: {- resize: true,- object_resizing: true,+ resize: false,+ object_resizing: false,},image_description: false,image_caption: false,@@ -95,10 +95,21 @@ function init_tiny(size) {icon: 'remove',tooltip: 'Remove image',onAction: function () {- tinymce.activeEditor.execCommand('Delete');+ editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});},onclick: function () {- tinymce.activeEditor.execCommand('Delete');+ editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});++ }+ });+ editor.ui.registry.addButton('imageopts', {+ icon: 'image-options',+ tooltip: 'Image properties',+ onAction: function () {+ reactNativeEventHandler("imageoptions");+ },+ onclick: function () {+ reactNativeEventHandler("imageoptions");}});@@ -284,5 +295,6 @@ function selectchange() {}}}+ currentFormats.node = editor.selection.getNode().nodeName;reactNativeEventHandler('selectionchange', currentFormats);}diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex ee2988115..cdf64406b 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -209,7 +209,7 @@ export const loadNote = async item => {editing.isFocused = false;setTimeout(() => {eSendEvent('webviewreset');- },1)+ }, 1);InteractionManager.runAfterInteractions(async () => {sendNoteEditedEvent({id: id,@@ -306,10 +306,10 @@ export const _onMessage = async evt => {setColors(COLOR_SCHEME);webviewInit = true;webviewOK = true;- if (PremiumService.get()){- tiny.call(EditorWebView,tiny.setMarkdown,true)+ if (PremiumService.get()) {+ tiny.call(EditorWebView, tiny.setMarkdown, true);} else {- tiny.call(EditorWebView,tiny.removeMarkdown,true)+ tiny.call(EditorWebView, tiny.removeMarkdown, true);}loadNoteInEditor();break;@@ -317,9 +317,55 @@ export const _onMessage = async evt => {webviewOK = true;break;case 'imagepreview':- eSendEvent("ImagePreview",message.value)+ eSendEvent('ImagePreview', message.value);- break;+ break;+ case 'imageoptions':+ if (editing.tooltip === 'imageoptions') {+ eSendEvent('showTooltip');+ break;+ }+ editing.tooltip = 'imageoptions';+ eSendEvent('showTooltip', {+ data: [+ {+ format: 'imageResize25',+ text: '25%',+ type: 'format',+ showTitle: false,+ fullname: 'Resize to 25%',+ },+ {+ format: 'imageResize50',+ text: '50%',+ type: 'format',+ showTitle: false,+ fullname: 'Resize to 25%',+ },+ {+ format: 'imageResize100',+ text: '100%',+ type: 'format',+ showTitle: false,+ fullname: 'Resize to 25%',+ },+ {+ format: 'removeimage',+ type: 'format',+ fullname: 'Remove image',+ },+ {+ format: 'imagepreview',+ type: 'format',+ fullname: 'Image preview',+ },+ ],+ title: 'imageoptions',+ default: null,+ type: 'imageoptions',+ pageX: 0,+ });+ break;case 'focus':editing.focusType = message.value;break;@@ -481,10 +527,10 @@ export async function onWebViewLoad(premium, colors) {if (!checkNote()) {Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;}- if (premium){- tiny.call(EditorWebView,tiny.setMarkdown,true)+ if (premium) {+ tiny.call(EditorWebView, tiny.setMarkdown, true);} else {- tiny.call(EditorWebView,tiny.removeMarkdown,true)+ tiny.call(EditorWebView, tiny.removeMarkdown, true);}setColors(colors);}diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.jsindex d562b88a3..c2c015cc4 100644--- a/apps/mobile/src/views/Editor/tiny/tiny.js+++ b/apps/mobile/src/views/Editor/tiny/tiny.js@@ -24,7 +24,7 @@ const setMarkdown = `tinymce.activeEditor.plugins.textpattern.setPatterns(markdownPatterns)`-const keyboardStateChanged = `(() => {+const keyboardStateChanged = `(function() {let node = tinymce.activeEditor.selection.getNode();node.scrollIntoView({behavior: "smooth", block: "end"});})();@@ -35,16 +35,16 @@ const blur = ``;-const pre = `(() => {+const pre = `(function() {function replaceContent(editor, content) {let rng = tinymce.activeEditor.selection.getRng();let node = tinymce.activeEditor.selection.getNode();let innerHTML = node.innerHTML;node.remove();tinymce.activeEditor.undoManager.transact(function () {- setTimeout(() =>+ setTimeout(function() {tinymce.activeEditor.execCommand("mceInsertContent", false, content(innerHTML)),2- );+ });});tinymce.activeEditor.selection.setRng(rng, true);tinymce.activeEditor.nodeChanged();@@ -55,7 +55,7 @@ const pre = `(() => {if (innerTexts.length <= 0) {replaceContent(tinymce.activeEditor,- (html) => {+ function(html) {let replant = html.replace(regex, "<br>");return "<p>" + replant + "</p>"}@@ -66,7 +66,7 @@ const pre = `(() => {})();`;const updateDateEdited = value => `- (() => {+ (function() {info = document.querySelector(infoBar);info.querySelector('#infodate').innerText = "${value}";info.querySelector('#infowords').innerText =@@ -76,7 +76,7 @@ const updateDateEdited = value => ``;const updateSavingState = value => `- (() => {+ (function() {info = document.querySelector(infoBar);info.querySelector('#infosaved').innerText = "${value}";})();@@ -119,7 +119,7 @@ const formatWithValue = (format, value) => {};export const nomenu = enabled => `- (() => {+ (function() {let isenabled = ${enabled};let titleIn = document.getElementById('titlebar');if (isenabled) {@@ -132,7 +132,7 @@ export const nomenu = enabled => `})();`;const updateTheme = value => `-(() => {+(function() {let v = ${value}pageTheme.colors = v;setTheme();diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js b/apps/mobile/src/views/Editor/tiny/toolbar/commands.jsindex 3d81b0593..911429a93 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/commands.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/commands.js@@ -56,16 +56,17 @@ export const execCommands = {magnify: `tinymce.activeEditor.execCommand('SearchReplace');`,table: (r, c) =>`- (() => {+ (function() {let body = tinymce.activeEditor.contentDocument.getElementsByTagName("body")[0];if (body.lastElementChild && body.lastElementChild.innerHTML === tinymce.activeEditor.selection.getNode().innerHTML) {let rng = tinymce.activeEditor.selection.getRng()tinymce.activeEditor.execCommand("mceInsertNewLine")tinymce.activeEditor.nodeChanged()tinymce.activeEditor.selection.setRng(rng)-}- tinymce.activeEditor.execCommand('mceInsertTable', false, { rows: ${r}, columns: ${c} });+ editor.undoManager.transact(function() {+ tinymce.activeEditor.execCommand('mceInsertTable', false, { rows: ${r}, columns: ${c} });+ });})();@@ -123,11 +124,62 @@ export const execCommands = {pre: `tinymce.activeEditor.execCommand('CodeBlock')`,- tableprops:"tinymce.activeEditor.execCommand('mceTableProps');",- tabledelete:"tinymce.activeEditor.execCommand('mceTableDelete');",- tablesplitcell:"tinymce.activeEditor.execCommand('mceTableSplitCells');",- tablemergecell:"tinymce.activeEditor.execCommand('mceTableMergeCells');",- tablerowprops:"tinymce.activeEditor.execCommand('mceTableRowProps');",+ tableprops: "tinymce.activeEditor.execCommand('mceTableProps');",+ tabledelete: "tinymce.activeEditor.execCommand('mceTableDelete');",+ tablesplitcell: "tinymce.activeEditor.execCommand('mceTableSplitCells');",+ tablemergecell: "tinymce.activeEditor.execCommand('mceTableMergeCells');",+ tablerowprops: "tinymce.activeEditor.execCommand('mceTableRowProps');",+ imageResize25: `+ if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {+ tinymce.activeEditor.selection.getNode().style.width = "25%";+ }+ `,+ imageResize50: `+ if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {+ tinymce.activeEditor.selection.getNode().style.width = "75%";+ }+ `,+ imageResize100: `+ if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {+ tinymce.activeEditor.selection.getNode().style.width = "100%";+ }+ `,+ imagepreview: `(function() {+ if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {+ var xhr = new XMLHttpRequest();+ xhr.responseType = 'blob';++ xhr.onload = function () {+ var recoveredBlob = xhr.response;+ var reader = new FileReader();+ reader.onload = function () {+ var blobAsDataUrl = reader.result;+ window.ReactNativeWebView.postMessage(+ JSON.stringify({+ type: 'imagepreview',+ value: blobAsDataUrl,+ })+ );+ reader.abort();+ xhr.abort();+ };+ reader.readAsDataURL(recoveredBlob);+ };+ xhr.open(+ 'GET',+ tinymce.activeEditor.selection.getNode().getAttribute('src'),+ );+ xhr.send();+ }+ })();+ `,+ removeimage: `+ (function() {+ if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {+ editor.undoManager.transact(function() {tinymce.activeEditor.execCommand('Delete');});+ }+ })+ `,};const handleImageResponse = response => {@@ -137,7 +189,7 @@ const handleImageResponse = response => {let b64 = `data:${response.type};base64, ` + response.base64;formatSelection(`- (() => {+ (function() {let pTag = "";let body = tinymce.activeEditor.contentDocument.getElementsByTagName("body")[0];if (body.lastElementChild && body.lastElementChild.innerHTML === tinymce.activeEditor.selection.getNode().innerHTML) {@@ -148,9 +200,9 @@ minifyImg("${b64}",1024,'image/jpeg',- (r) => {+ function(r) {var content = "<img style=" + "max-width:100% !important;" + "src=" + r + ">" + pTag;- editor.undoManager.transact(() => editor.execCommand("mceInsertContent",false,content));+ editor.undoManager.transact(function() {editor.execCommand("mceInsertContent",false,content)});},0.6,);diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/constants.js b/apps/mobile/src/views/Editor/tiny/toolbar/constants.jsindex 111c7ef9c..f6d9bb2f8 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/constants.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/constants.js@@ -177,4 +177,6 @@ export const TOOLBAR_ICONS = {tablerowprops:"table-row",tablecolumnprops:"table-column",tableconfig:"table-cog",+ imagepreview:"fullscreen",+ removeimage:"delete"};diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/item.js b/apps/mobile/src/views/Editor/tiny/toolbar/item.jsindex 6d025f5f9..404d02ed9 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/item.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/item.js@@ -83,6 +83,7 @@ const ToolbarItem = ({});return;}+if (formats.indexOf(format) > -1 && format !== 'removeformat') {if (format === 'forecolor' || format === 'hilitecolor') {if (!data[format]) {@@ -332,7 +333,7 @@ const ToolbarItem = ({? icon: null,}}- size={SIZE.md}>+ size={text.includes("%") ? SIZE.sm : SIZE.md}>{currentText || text}</Paragraph>) : (