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
feat: add support for file pasting as attachment
thecodrrcfbc538308d7
diff --git a/apps/web/src/components/editor/plugins/picker.js b/apps/web/src/components/editor/plugins/picker.jsindex e061a9583..b7aae6032 100644--- a/apps/web/src/components/editor/plugins/picker.js+++ b/apps/web/src/components/editor/plugins/picker.js@@ -45,10 +45,11 @@ export async function attachFile(editor, selectedFile) {}if (selectedFile.type.startsWith("image/")) {const image = await pickImage(selectedFile);- console.log(image);+ if (!image) return;editor.execCommand("mceAttachImage", image);} else {const file = await pickFile(selectedFile);+ if (!file) return;editor.execCommand("mceAttachFile", file);}}@@ -203,5 +204,6 @@ async function addAttachment(file, dataurl) {};},});+ if (result instanceof Error) throw result;return result;}diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.jsindex 5679520ac..7dbf5977d 100644--- a/apps/web/src/components/editor/tinymce.js+++ b/apps/web/src/components/editor/tinymce.js@@ -203,9 +203,9 @@ function TinyMCE(props) {id={sessionId}ref={tinymceRef}onFocus={onFocus}- onDrop={(e, editor) => {+ onDrop={async (e, editor) => {for (let file of e.dataTransfer.files) {- attachFile(editor, file);+ await attachFile(editor, file);}}}init={{@@ -286,15 +286,28 @@ function TinyMCE(props) {});}+ async function onPaste(e) {+ if (e.clipboardData?.items?.length) {+ e.preventDefault();+ for (let item of e.clipboardData.items) {+ const file = item.getAsFile();+ if (!file) continue;+ await attachFile(editor, file);+ }+ }+ }+editor.on("ScrollIntoView", onScrollIntoView);editor.on("tap", onTap);editor.on(changeEvents, onEditorChange);editor.on("keyup", onKeyUp);+ editor.on("paste", onPaste);editor.once("remove", () => {editor.off("ScrollIntoView", onScrollIntoView);editor.off("tap", onTap);editor.off(changeEvents, onEditorChange);editor.off("keyup", onKeyUp);+ editor.off("paste", onPaste);});},toolbar_persist: true,