From 424e088123fba515f22ffa172f3a8bcc48caa755 Mon Sep 17 00:00:00 2001 From: DatDang Date: Tue, 19 Nov 2024 10:08:59 +0700 Subject: [PATCH 1/3] Handle additional cases for drag drop in editor --- lib/src/widgets/html_editor_widget_web.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/widgets/html_editor_widget_web.dart b/lib/src/widgets/html_editor_widget_web.dart index af5279b5..b82f949b 100644 --- a/lib/src/widgets/html_editor_widget_web.dart +++ b/lib/src/widgets/html_editor_widget_web.dart @@ -497,6 +497,18 @@ class _HtmlEditorWidgetWebState extends State { event.preventDefault(); window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragLeave", "types": event.dataTransfer.types}), "*"); }); + + document.getElementsByClassName('note-editor')[0].addEventListener("dragover", function(event) { + if (event.dataTransfer.types.includes("Files")) { + event.preventDefault(); + } + }); + + document.getElementsByClassName('note-editor')[0].addEventListener("drop", function(event) { + if (event.dataTransfer.types.includes("Files")) { + event.preventDefault(); + } + }); } $userScripts } From 95ccd5a4a9416fbb3636cdc8fb118e0a167e9651 Mon Sep 17 00:00:00 2001 From: DatDang Date: Wed, 20 Nov 2024 15:38:25 +0700 Subject: [PATCH 2/3] fixup! Handle additional cases for drag drop in editor --- lib/src/widgets/html_editor_widget_web.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/widgets/html_editor_widget_web.dart b/lib/src/widgets/html_editor_widget_web.dart index b82f949b..d987eb80 100644 --- a/lib/src/widgets/html_editor_widget_web.dart +++ b/lib/src/widgets/html_editor_widget_web.dart @@ -501,6 +501,7 @@ class _HtmlEditorWidgetWebState extends State { document.getElementsByClassName('note-editor')[0].addEventListener("dragover", function(event) { if (event.dataTransfer.types.includes("Files")) { event.preventDefault(); + window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragEnter", "types": event.dataTransfer.types}), "*"); } }); From 504f62d15f15b3dc52047f79fa20c7f8818ddffe Mon Sep 17 00:00:00 2001 From: DatDang Date: Mon, 25 Nov 2024 11:43:01 +0700 Subject: [PATCH 3/3] fixup! Handle additional cases for drag drop in editor --- lib/src/widgets/html_editor_widget_web.dart | 5 ++++- lib/utils/callbacks.dart | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/widgets/html_editor_widget_web.dart b/lib/src/widgets/html_editor_widget_web.dart index d987eb80..7b15d907 100644 --- a/lib/src/widgets/html_editor_widget_web.dart +++ b/lib/src/widgets/html_editor_widget_web.dart @@ -501,7 +501,7 @@ class _HtmlEditorWidgetWebState extends State { document.getElementsByClassName('note-editor')[0].addEventListener("dragover", function(event) { if (event.dataTransfer.types.includes("Files")) { event.preventDefault(); - window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragEnter", "types": event.dataTransfer.types}), "*"); + window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragOver", "types": event.dataTransfer.types}), "*"); } }); @@ -909,6 +909,9 @@ class _HtmlEditorWidgetWebState extends State { if (data['type'].contains('onDragEnter') && c.onDragEnter != null) { c.onDragEnter!.call(data['types']); } + if (data['type'].contains('onDragOver') && c.onDragOver != null) { + c.onDragOver!.call(data['types']); + } if (data['type'].contains('onDragLeave') && c.onDragLeave != null) { c.onDragLeave!.call(data['types']); } diff --git a/lib/utils/callbacks.dart b/lib/utils/callbacks.dart index 186642cf..94b991f5 100644 --- a/lib/utils/callbacks.dart +++ b/lib/utils/callbacks.dart @@ -27,6 +27,7 @@ class Callbacks { this.onScroll, this.onTextFontSizeChanged, this.onDragEnter, + this.onDragOver, this.onDragLeave, this.onInitialTextLoadComplete, }); @@ -194,6 +195,8 @@ class Callbacks { void Function(List? types)? onDragEnter; + void Function(List? types)? onDragOver; + void Function(List? types)? onDragLeave; void Function(String initialText)? onInitialTextLoadComplete;