feat(window): add drag and drop position

This commit is contained in:
Amr Bashir
2023-08-14 06:34:55 +03:00
parent d5a7c77a8d
commit cdae07afe6
4 changed files with 34 additions and 16 deletions
-1
View File
@@ -28,4 +28,3 @@
---
Fixes docs.rs build by enabling the `tauri/dox` feature flag.
+5
View File
@@ -0,0 +1,5 @@
---
"window-js": "minor"
---
Add position information to file drop events.
+28 -14
View File
@@ -63,8 +63,8 @@ interface ScaleFactorChanged {
/** The file drop event types. */
type FileDropEvent =
| { type: "hover"; paths: string[] }
| { type: "drop"; paths: string[] }
| { type: "hover"; paths: string[]; position: PhysicalPosition }
| { type: "drop"; paths: string[]; position: PhysicalPosition }
| { type: "cancel" };
/**
@@ -1901,19 +1901,33 @@ class Window {
async onFileDropEvent(
handler: EventCallback<FileDropEvent>,
): Promise<UnlistenFn> {
const unlistenFileDrop = await this.listen<string[]>(
TauriEvent.WINDOW_FILE_DROP,
(event) => {
handler({ ...event, payload: { type: "drop", paths: event.payload } });
},
);
const unlistenFileDrop = await this.listen<{
paths: string[];
position: PhysicalPosition;
}>(TauriEvent.WINDOW_FILE_DROP, (event) => {
handler({
...event,
payload: {
type: "drop",
paths: event.payload.paths,
position: mapPhysicalPosition(event.payload.position),
},
});
});
const unlistenFileHover = await this.listen<string[]>(
TauriEvent.WINDOW_FILE_DROP_HOVER,
(event) => {
handler({ ...event, payload: { type: "hover", paths: event.payload } });
},
);
const unlistenFileHover = await this.listen<{
paths: string[];
position: PhysicalPosition;
}>(TauriEvent.WINDOW_FILE_DROP_HOVER, (event) => {
handler({
...event,
payload: {
type: "hover",
paths: event.payload.paths,
position: mapPhysicalPosition(event.payload.position),
},
});
});
const unlistenCancel = await this.listen<null>(
TauriEvent.WINDOW_FILE_DROP_CANCELLED,
File diff suppressed because one or more lines are too long