Skip to content

Commit

Permalink
Pass types data when performing drag & drop
Browse files Browse the repository at this point in the history
Signed-off-by: dab246 <[email protected]>
  • Loading branch information
dab246 authored and hoangdat committed Jul 12, 2024
1 parent ddcfb76 commit 8e4114f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/src/widgets/html_editor_widget_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,13 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
}
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
Expand Down Expand Up @@ -886,10 +888,10 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
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']);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>? types)? onDragEnter;

void Function()? onDragLeave;
void Function(List<dynamic>? types)? onDragLeave;
}

0 comments on commit 8e4114f

Please sign in to comment.