From b54d7da6724b3ff1581bba375b4fe1bfe707c925 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 10 Jul 2024 12:12:20 +0700 Subject: [PATCH 1/2] Pass types data when performing drag & drop Signed-off-by: dab246 --- lib/src/widgets/html_editor_widget_web.dart | 10 ++++++---- lib/utils/callbacks.dart | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/widgets/html_editor_widget_web.dart b/lib/src/widgets/html_editor_widget_web.dart index 0c1251e2..2989ec9f 100644 --- a/lib/src/widgets/html_editor_widget_web.dart +++ b/lib/src/widgets/html_editor_widget_web.dart @@ -488,11 +488,13 @@ class _HtmlEditorWidgetWebState extends State { } if (data["type"].includes("onDragDropEvent")) { document.getElementsByClassName('note-editor')[0].addEventListener("dragenter", function(event) { - window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragEnter"}), "*"); + event.preventDefault(); + window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragEnter", "types": event.dataTransfer.types}), "*"); }); document.getElementsByClassName('note-editor')[0].addEventListener("dragleave", function(event) { - window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragLeave"}), "*"); + event.preventDefault(); + window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragLeave", "types": event.dataTransfer.types}), "*"); }); } $userScripts @@ -886,10 +888,10 @@ class _HtmlEditorWidgetWebState extends State { c.onTextFontSizeChanged!.call(data['size']); } if (data['type'].contains('onDragEnter') && c.onDragEnter != null) { - c.onDragEnter!.call(); + c.onDragEnter!.call(data['types']); } if (data['type'].contains('onDragLeave') && c.onDragLeave != null) { - c.onDragLeave!.call(); + c.onDragLeave!.call(data['types']); } } diff --git a/lib/utils/callbacks.dart b/lib/utils/callbacks.dart index 1972f453..06206341 100644 --- a/lib/utils/callbacks.dart +++ b/lib/utils/callbacks.dart @@ -191,7 +191,7 @@ class Callbacks { /// Called whenever the mouse/finger is released and the editor is in rich text view. void Function(int?)? onTextFontSizeChanged; - void Function()? onDragEnter; + void Function(List? types)? onDragEnter; - void Function()? onDragLeave; + void Function(List? types)? onDragLeave; } From 720268eec9d5e9018ecfd477cf928800b44b02de Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 10 Jul 2024 12:12:24 +0700 Subject: [PATCH 2/2] Update source flutter_inappwebview in `index.html` file of example Signed-off-by: dab246 --- example/web/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/web/index.html b/example/web/index.html index 6faca9f3..c1436121 100644 --- a/example/web/index.html +++ b/example/web/index.html @@ -29,7 +29,7 @@ example - +