From 8bfa3edec604e8182f09fb8415d49bbfd9b64aa3 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Sun, 4 Aug 2024 15:24:38 +0700 Subject: [PATCH] feat: make `PasteDropFileOptions#mimeTypes` optional --- package.json | 2 +- src/editors/extensions/pasteDropFile.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ac1a576..f5e6cf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matters/matters-editor", - "version": "0.3.0-alpha.2", + "version": "0.3.0-alpha.3", "description": "Editor for matters.news", "author": "https://github.com/thematters", "homepage": "https://github.com/thematters/matters-editor", diff --git a/src/editors/extensions/pasteDropFile.ts b/src/editors/extensions/pasteDropFile.ts index 9a9a8ef..f6ad51e 100644 --- a/src/editors/extensions/pasteDropFile.ts +++ b/src/editors/extensions/pasteDropFile.ts @@ -12,7 +12,7 @@ type PasteDropFileOptions = { // drop event handler onDrop: (editor: Editor, files: File[], pos: number) => void // accepted mime types - mimeTypes: string[] + mimeTypes?: string[] } const pluginName = 'pasteDropFile' @@ -27,9 +27,11 @@ const makePlugin = ({ key: new PluginKey(pluginName), props: { handleDrop(view, event) { - const files = Array.from(event.dataTransfer?.files || []).filter( - (file) => mimeTypes.includes(file.type), - ) + let files = Array.from(event.dataTransfer?.files || []) + + if (mimeTypes) { + files = files.filter((file) => mimeTypes.includes(file.type)) + } if (files.length <= 0) return @@ -44,9 +46,11 @@ const makePlugin = ({ return true }, handlePaste(view, event) { - const files = Array.from(event.clipboardData?.files || []).filter( - (file) => mimeTypes.includes(file.type), - ) + let files = Array.from(event.clipboardData?.files || []) + + if (mimeTypes) { + files = files.filter((file) => mimeTypes.includes(file.type)) + } if (files.length <= 0) return