Skip to content

Commit 31300fa

Browse files
dab246hoangdat
authored andcommitted
Set drag and drop event listener
Signed-off-by: dab246 <[email protected]>
1 parent 9e04123 commit 31300fa

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

lib/src/html_editor_controller_mobile.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,7 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
298298

299299
@override
300300
void removeSignature() {}
301+
302+
@override
303+
void setOnDragDropEvent() {}
301304
}

lib/src/html_editor_controller_unsupported.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,7 @@ class HtmlEditorController {
195195

196196
/// Update body direction on web
197197
void updateBodyDirection(String direction) {}
198+
199+
/// Set drag and drop event listener
200+
void setOnDragDropEvent() {}
198201
}

lib/src/html_editor_controller_web.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,9 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
400400
void updateBodyDirection(String direction) {
401401
_evaluateJavascriptWeb(data: {'type': 'toIframe: updateBodyDirection', 'direction': direction});
402402
}
403+
404+
@override
405+
void setOnDragDropEvent() {
406+
_evaluateJavascriptWeb(data: {'type': 'toIframe: onDragDropEvent'});
407+
}
403408
}

lib/src/widgets/html_editor_widget_web.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,15 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
480480
const contentsEditor = document.getElementsByClassName('note-editable')[0].innerHTML;
481481
window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onChangeContent", "contents": contentsEditor}), "*");
482482
}
483+
if (data["type"].includes("onDragDropEvent")) {
484+
document.getElementsByClassName('note-editor')[0].addEventListener("dragenter", function(event) {
485+
window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragEnter"}), "*");
486+
});
487+
488+
document.getElementsByClassName('note-editor')[0].addEventListener("dragleave", function(event) {
489+
window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onDragLeave"}), "*");
490+
});
491+
}
483492
$userScripts
484493
}
485494
}
@@ -934,6 +943,12 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
934943
if (data['type'].contains('onTextFontSizeChanged')) {
935944
c.onTextFontSizeChanged!.call(data['size']);
936945
}
946+
if (data['type'].contains('onDragEnter') && c.onDragEnter != null) {
947+
c.onDragEnter!.call();
948+
}
949+
if (data['type'].contains('onDragLeave') && c.onDragLeave != null) {
950+
c.onDragLeave!.call();
951+
}
937952
}
938953
});
939954
}

lib/utils/callbacks.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Callbacks {
2626
this.onPaste,
2727
this.onScroll,
2828
this.onTextFontSizeChanged,
29+
this.onDragEnter,
30+
this.onDragLeave,
2931
});
3032

3133
/// Called before certain commands are fired and the editor is in rich text view.
@@ -188,4 +190,8 @@ class Callbacks {
188190

189191
/// Called whenever the mouse/finger is released and the editor is in rich text view.
190192
void Function(int?)? onTextFontSizeChanged;
193+
194+
void Function()? onDragEnter;
195+
196+
void Function()? onDragLeave;
191197
}

0 commit comments

Comments
 (0)