5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 21:20:29 +08:00
wails/v3/internal/runtime/runtime_production_desktop_darwin.js
Mohamed Gharib e419822c77
[v3] Fix default context-menu in selected disabled inputs (#2753)
* [v3] Fix default context-menu in selected disabled inputs

* [v3] Update Task to v3.27.1. Add `wails3 task -version` and `wails3 task taskfile:update`.

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
2023-07-01 10:52:55 +10:00

2 lines
7.4 KiB
JavaScript

(()=>{var oe=Object.defineProperty;var w=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})};var M={};w(M,{SetText:()=>ae,Text:()=>se});var re=window.location.origin+"/wails/runtime";function le(e,t,n){let i=new URL(re);i.searchParams.append("method",e),n&&i.searchParams.append("args",JSON.stringify(n));let o={headers:{}};return t&&(o.headers["x-wails-window-name"]=t),new Promise((l,s)=>{fetch(i,o).then(a=>{if(a.ok)return a.headers.get("Content-Type")&&a.headers.get("Content-Type").indexOf("application/json")!==-1?a.json():a.text();s(Error(a.statusText))}).then(a=>l(a)).catch(a=>s(a))})}function r(e,t){return function(n,i=null){return le(e+"."+n,t,i)}}var D=r("clipboard");function ae(e){D("SetText",{text:e})}function se(){return D("Text")}var S={};w(S,{Hide:()=>ue,Quit:()=>fe,Show:()=>ce});var b=r("application");function ue(){b("Hide")}function ce(){b("Show")}function fe(){b("Quit")}var E={};w(E,{Log:()=>me});var de=r("log");function me(e){return de("Log",e)}var y={};w(y,{GetAll:()=>pe,GetCurrent:()=>ge,GetPrimary:()=>we});var R=r("screens");function pe(){return R("GetAll")}function we(){return R("GetPrimary")}function ge(){return R("GetCurrent")}var he="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var g=(e=21)=>{let t="",n=e;for(;n--;)t+=he[Math.random()*64|0];return t};var xe=r("call"),c=new Map;function ve(){let e;do e=g();while(c.has(e));return e}function T(e,t,n){let i=c.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),c.delete(e))}function A(e,t){let n=c.get(e);n&&(n.reject(t),c.delete(e))}function P(e,t){return new Promise((n,i)=>{let o=ve();t=t||{},t["call-id"]=o,c.set(o,{resolve:n,reject:i}),xe(e,t).catch(l=>{i(l),c.delete(o)})})}function N(e){return P("Call",e)}function H(e,t,...n){return P("Call",{packageName:"wails-plugins",structName:e,methodName:t,args:n})}function F(e){let t=r("window",e);return{Center:()=>void t("Center"),SetTitle:n=>void t("SetTitle",{title:n}),Fullscreen:()=>void t("Fullscreen"),UnFullscreen:()=>void t("UnFullscreen"),SetSize:(n,i)=>t("SetSize",{width:n,height:i}),Size:()=>t("Size"),SetMaxSize:(n,i)=>void t("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>void t("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>void t("SetAlwaysOnTop",{alwaysOnTop:n}),SetRelativePosition:(n,i)=>t("SetRelativePosition",{x:n,y:i}),RelativePosition:()=>t("RelativePosition"),Screen:()=>t("Screen"),Hide:()=>void t("Hide"),Maximise:()=>void t("Maximise"),Show:()=>void t("Show"),Close:()=>void t("Close"),ToggleMaximise:()=>void t("ToggleMaximise"),UnMaximise:()=>void t("UnMaximise"),Minimise:()=>void t("Minimise"),UnMinimise:()=>void t("UnMinimise"),Restore:()=>void t("Restore"),SetBackgroundColour:(n,i,o,l)=>void t("SetBackgroundColour",{r:n,g:i,b:o,a:l})}}var Ce=r("events"),W=class{constructor(t,n,i){this.eventName=t,this.maxCallbacks=i||-1,this.Callback=o=>(n(o),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}},h=class{constructor(t,n=null){this.name=t,this.data=n}},u=new Map;function x(e,t,n){let i=u.get(e)||[],o=new W(e,t,n);return i.push(o),u.set(e,i),()=>Me(o)}function B(e,t){return x(e,t,-1)}function U(e,t){return x(e,t,1)}function Me(e){let t=e.eventName,n=u.get(t).filter(i=>i!==e);n.length===0?u.delete(t):u.set(t,n)}function G(e){let t=u.get(e.name);if(t){let n=[];t.forEach(i=>{i.Callback(e)&&n.push(i)}),n.length>0&&(t=t.filter(i=>!n.includes(i)),t.length===0?u.delete(e.name):u.set(e.name,t))}}function I(e,...t){[e,...t].forEach(i=>{u.delete(i)})}function Y(){u.clear()}function v(e){Ce("Emit",e)}var be=r("dialog"),f=new Map;function Se(){let e;do e=g();while(f.has(e));return e}function X(e,t,n){let i=f.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),f.delete(e))}function j(e,t){let n=f.get(e);n&&(n.reject(t),f.delete(e))}function d(e,t){return new Promise((n,i)=>{let o=Se();t=t||{},t["dialog-id"]=o,f.set(o,{resolve:n,reject:i}),be(e,t).catch(l=>{i(l),f.delete(o)})})}function Q(e){return d("Info",e)}function V(e){return d("Warning",e)}function J(e){return d("Error",e)}function m(e){return d("Question",e)}function q(e){return d("OpenFile",e)}function _(e){return d("SaveFile",e)}var Ee=r("contextmenu");function Re(e,t,n,i){Ee("OpenContextMenu",{id:e,x:t,y:n,data:i})}function K(){window.addEventListener("contextmenu",ye)}function ye(e){let t=e.target,n=window.getComputedStyle(t).getPropertyValue("--custom-contextmenu");if(n=n?n.trim():"",n){e.preventDefault();let i=window.getComputedStyle(t).getPropertyValue("--custom-contextmenu-data");Re(n,e.clientX,e.clientY,i);return}We(e)}function We(e){let t=e.target;switch(window.getComputedStyle(t).getPropertyValue("--default-contextmenu").trim()){case"show":return;case"hide":e.preventDefault();return;default:if(t.isContentEditable)return;let o=window.getSelection(),l=o.toString().length>0;if(l)for(let s=0;s<o.rangeCount;s++){let z=o.getRangeAt(s).getClientRects();for(let C=0;C<z.length;C++){let L=z[C];if(document.elementFromPoint(L.left,L.top)===t)return}}if((t.tagName==="INPUT"||t.tagName==="TEXTAREA")&&(l||!t.readOnly&&!t.disabled))return;e.preventDefault()}}function Z(e,t=null){let n=new h(e,t);v(n)}function ke(){document.querySelectorAll("[data-wml-event]").forEach(function(t){let n=t.getAttribute("data-wml-event"),i=t.getAttribute("data-wml-confirm"),o=t.getAttribute("data-wml-trigger")||"click",l=function(){if(i){m({Title:"Confirm",Message:i,Detached:!1,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(s){s!=="No"&&Z(n)});return}Z(n)};t.removeEventListener(o,l),t.addEventListener(o,l)})}function $(e){wails.Window[e]===void 0&&console.log("Window method "+e+" not found"),wails.Window[e]()}function Oe(){document.querySelectorAll("[data-wml-window]").forEach(function(t){let n=t.getAttribute("data-wml-window"),i=t.getAttribute("data-wml-confirm"),o=t.getAttribute("data-wml-trigger")||"click",l=function(){if(i){m({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(s){s!=="No"&&$(n)});return}$(n)};t.removeEventListener(o,l),t.addEventListener(o,l)})}function k(){ke(),Oe()}var ee=function(e){webkit.messageHandlers.external.postMessage(e)};var ze=new Map;function te(e){let t=new Map;for(let[n,i]of Object.entries(e))typeof i=="object"&&i!==null?t.set(n,te(i)):t.set(n,i);return t}fetch("/wails/flags").then(e=>{e.json().then(t=>{ze=te(t)})});var p=!1;function Le(e){let t=window.getComputedStyle(e.target).getPropertyValue("--webkit-app-region");return t&&(t=t.trim()),t!=="drag"||e.buttons!==1?!1:e.detail===1}function ne(){window.addEventListener("mousedown",De),window.addEventListener("mousemove",Ae),window.addEventListener("mouseup",Te)}function De(e){if(Le(e)){if(e.offsetX>e.target.clientWidth||e.offsetY>e.target.clientHeight)return;p=!0}else p=!1}function Te(e){(e.buttons!==void 0?e.buttons:e.which)>0&&O()}function O(){document.body.style.cursor="default",p=!1}function Ae(e){if(p){p=!1,(e.buttons!==void 0?e.buttons:e.which)>0&&ee("drag");return}}window.wails={...ie(null),Capabilities:{}};fetch("/wails/capabilities").then(e=>{e.json().then(t=>{window.wails.Capabilities=t})});window._wails={dialogCallback:X,dialogErrorCallback:j,dispatchWailsEvent:G,callCallback:T,callErrorCallback:A,endDrag:O};function ie(e){return{Clipboard:{...M},Application:{...S,GetWindowByName(t){return ie(t)}},Log:E,Screens:y,Call:N,Plugin:H,WML:{Reload:k},Dialog:{Info:Q,Warning:V,Error:J,Question:m,OpenFile:q,SaveFile:_},Events:{Emit:v,On:B,Once:U,OnMultiple:x,Off:I,OffAll:Y},Window:F(e)}}K();ne();document.addEventListener("DOMContentLoaded",function(e){k()});})();