mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-11-22 00:11:17 +01:00
feat(window): add drag and drop position
This commit is contained in:
4 files changed
+34
-16
No files matched your search
@@ -28,4 +28,3 @@
|
||||
---
|
||||
|
||||
Fixes docs.rs build by enabling the `tauri/dox` feature flag.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"window-js": "minor"
|
||||
---
|
||||
|
||||
Add position information to file drop events.
|
||||
@@ -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,
|
||||
|
||||
@@ -1 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var i=Object.defineProperty,n=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},t=(e,i,n)=>{if(!i.has(e))throw TypeError("Cannot "+n)},l=(e,i,n)=>(t(e,i,"read from private field"),n?n.call(e):i.get(e)),a=(e,i,n,l)=>(t(e,i,"write to private field"),l?l.call(e,n):i.set(e,n),n);function s(e,i=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${n}`;return Object.defineProperty(window,t,{value:n=>(i&&Reflect.deleteProperty(window,t),e?.(n)),writable:!1,configurable:!0}),n}n({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,i,n)=>{if(i.has(e))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(e):i.set(e,n)})(this,r,(()=>{})),this.id=s((e=>{l(this,r).call(this,e)}))}set onmessage(e){a(this,r,e)}get onmessage(){return l(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var _=class{constructor(e,i,n){this.plugin=e,this.event=i,this.channelId=n}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,i,n){let t=new o;return t.onmessage=n,u(`plugin:${e}|register_listener`,{event:i,handler:t}).then((()=>new _(e,i,t.id)))}async function u(e,i={}){return new Promise(((n,t)=>{let l=s((e=>{n(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=s((e=>{t(e),Reflect.deleteProperty(window,`_${l}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:l,error:a,...i})}))}function c(e,i="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${i}.localhost/${n}`:`${i}://localhost/${n}`}n({},{TauriEvent:()=>h,emit:()=>b,listen:()=>y,once:()=>I});var d,h=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(h||{});async function p(e,i){await u("plugin:event|unlisten",{event:e,eventId:i})}async function y(e,i,n){return u("plugin:event|listen",{event:e,windowLabel:n?.target,handler:s(i)}).then((i=>async()=>p(e,i)))}async function I(e,i,n){return y(e,(n=>{i(n),p(e,n.id).catch((()=>{}))}),n)}async function b(e,i,n){await u("plugin:event|emit",{event:e,windowLabel:n?.target,payload:i})}class g{constructor(e,i){this.type="Logical",this.width=e,this.height=i}}class E{constructor(e,i){this.type="Physical",this.width=e,this.height=i}toLogical(e){return new g(this.width/e,this.height/e)}}class O{constructor(e,i){this.type="Logical",this.x=e,this.y=i}}class A{constructor(e,i){this.type="Physical",this.x=e,this.y=i}toLogical(e){return new O(this.x/e,this.y/e)}}e.UserAttentionType=void 0,(d=e.UserAttentionType||(e.UserAttentionType={}))[d.Critical=1]="Critical",d[d.Informational=2]="Informational";class m{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function R(){return new T(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})}function N(){return window.__TAURI_METADATA__.__windows.map((e=>new T(e.label,{skip:!0})))}const v=["tauri://created","tauri://error"];class T{constructor(e,i={}){this.label=e,this.listeners=Object.create(null),(null==i?void 0:i.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...i,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return N().some((i=>i.label===e))?new T(e,{skip:!0}):null}static getCurrent(){return R()}static getAll(){return N()}static async getFocusedWindow(){for(const e of N())if(await e.isFocused())return e;return null}async listen(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)})):y(e,i,{target:this.label})}async once(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)})):I(e,i,{target:this.label})}async emit(e,i){if(v.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,windowLabel:this.label,payload:i});return Promise.resolve()}return b(e,i,{target:this.label})}_handleTauriEvent(e,i){return!!v.includes(e)&&(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0)}async scaleFactor(){return window.__TAURI_INVOKE__("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return window.__TAURI_INVOKE__("plugin:window|inner_position",{label:thLine truncated
|
||||
if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var i=Object.defineProperty,t=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},n=(e,i,t)=>{if(!i.has(e))throw TypeError("Cannot "+t)},l=(e,i,t)=>(n(e,i,"read from private field"),t?t.call(e):i.get(e)),a=(e,i,t,l)=>(n(e,i,"write to private field"),l?l.call(e,t):i.set(e,t),t);function s(e,i=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],n=`_${t}`;return Object.defineProperty(window,n,{value:t=>(i&&Reflect.deleteProperty(window,n),e?.(t)),writable:!1,configurable:!0}),t}t({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,i,t)=>{if(i.has(e))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(e):i.set(e,t)})(this,r,(()=>{})),this.id=s((e=>{l(this,r).call(this,e)}))}set onmessage(e){a(this,r,e)}get onmessage(){return l(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var _=class{constructor(e,i,t){this.plugin=e,this.event=i,this.channelId=t}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,i,t){let n=new o;return n.onmessage=t,u(`plugin:${e}|register_listener`,{event:i,handler:n}).then((()=>new _(e,i,n.id)))}async function u(e,i={}){return new Promise(((t,n)=>{let l=s((e=>{t(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=s((e=>{n(e),Reflect.deleteProperty(window,`_${l}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:l,error:a,...i})}))}function c(e,i="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${i}.localhost/${t}`:`${i}://localhost/${t}`}t({},{TauriEvent:()=>h,emit:()=>b,listen:()=>y,once:()=>I});var d,h=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(h||{});async function p(e,i){await u("plugin:event|unlisten",{event:e,eventId:i})}async function y(e,i,t){return u("plugin:event|listen",{event:e,windowLabel:t?.target,handler:s(i)}).then((i=>async()=>p(e,i)))}async function I(e,i,t){return y(e,(t=>{i(t),p(e,t.id).catch((()=>{}))}),t)}async function b(e,i,t){await u("plugin:event|emit",{event:e,windowLabel:t?.target,payload:i})}class g{constructor(e,i){this.type="Logical",this.width=e,this.height=i}}class E{constructor(e,i){this.type="Physical",this.width=e,this.height=i}toLogical(e){return new g(this.width/e,this.height/e)}}class O{constructor(e,i){this.type="Logical",this.x=e,this.y=i}}class A{constructor(e,i){this.type="Physical",this.x=e,this.y=i}toLogical(e){return new O(this.x/e,this.y/e)}}e.UserAttentionType=void 0,(d=e.UserAttentionType||(e.UserAttentionType={}))[d.Critical=1]="Critical",d[d.Informational=2]="Informational";class m{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function R(){return new T(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})}function N(){return window.__TAURI_METADATA__.__windows.map((e=>new T(e.label,{skip:!0})))}const v=["tauri://created","tauri://error"];class T{constructor(e,i={}){this.label=e,this.listeners=Object.create(null),(null==i?void 0:i.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...i,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return N().some((i=>i.label===e))?new T(e,{skip:!0}):null}static getCurrent(){return R()}static getAll(){return N()}static async getFocusedWindow(){for(const e of N())if(await e.isFocused())return e;return null}async listen(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const t=this.listeners[e];t.splice(t.indexOf(i),1)})):y(e,i,{target:this.label})}async once(e,i){return this._handleTauriEvent(e,i)?Promise.resolve((()=>{const t=this.listeners[e];t.splice(t.indexOf(i),1)})):I(e,i,{target:this.label})}async emit(e,i){if(v.includes(e)){for(const t of this.listeners[e]||[])t({event:e,id:-1,windowLabel:this.label,payload:i});return Promise.resolve()}return b(e,i,{target:this.label})}_handleTauriEvent(e,i){return!!v.includes(e)&&(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0)}async scaleFactor(){return window.__TAURI_INVOKE__("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return window.__TAURI_INVOKE__("plugin:window|inner_position",{label:thLine truncated
|
||||
Reference in new issue
Block a user