Skip to content

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

feat: add drag and drop support for attachments (#197)

Muhammad Ali895b6497d749
diff --git a/apps/web/src/components/editor/plugins/picker.js b/apps/web/src/components/editor/plugins/picker.js
index 4ccce6d4c..ef36afe0c 100644
--- a/apps/web/src/components/editor/plugins/picker.js
+++ b/apps/web/src/components/editor/plugins/picker.js
@@ -36,6 +36,15 @@ async function insertAttachment(editor, type) {
const selectedFile = await showFilePicker({
acceptedFileTypes: type || "*/*",
});
+
+ attachFile(editor,selectedFile);
+}
+
+export async function attachFile(editor, selectedFile) {
+ if (!isUserPremium()) {
+ await showBuyDialog();
+ return;
+ }
if (selectedFile.type.startsWith("image/")) {
const image = await pickImage(selectedFile);
editor.execCommand("mceAttachImage", image);
diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.js
index 2d111b3ec..23487fdb2 100644
--- a/apps/web/src/components/editor/tinymce.js
+++ b/apps/web/src/components/editor/tinymce.js
@@ -33,7 +33,7 @@ import "@streetwritersco/tinymce-plugins/keyboardquirks";
import "@streetwritersco/tinymce-plugins/attachmentshandler";
import "@streetwritersco/tinymce-plugins/contenthandler";
import "@streetwritersco/tinymce-plugins/bettertable";
-import "./plugins/picker";
+import { attachFile } from "./plugins/picker";
import "./plugins/icons";
import "./plugins/attachmentshandler.css";
import "@streetwritersco/tinymce-plugins/blockescape";
@@ -203,6 +203,10 @@ function TinyMCE(props) {
id={sessionId}
ref={tinymceRef}
onFocus={onFocus}
+ onDrop={(e,editor) => {
+ for (let file of e.dataTransfer.files) {
+ attachFile(editor, file)
+ }}}
init={{
//experimental
keep_styles: false,