diff --git a/dist/index.global.js b/dist/index.global.js index a662213..8be1118 100644 --- a/dist/index.global.js +++ b/dist/index.global.js @@ -1 +1 @@ -"use strict";var CordovaWeb=(()=>{var q=Object.create;var O=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var U=(n,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of H(e))!B.call(n,s)&&s!==o&&O(n,s,{get:()=>e[s],enumerable:!(r=z(e,s))||r.enumerable});return n};var R=(n,e,o)=>(o=n!=null?q($(n)):{},U(e||!n||!n.__esModule?O(o,"default",{value:n,enumerable:!0}):o,n));var A=G((W,L)=>{"use strict";(function(n,e){typeof W=="object"&&typeof L<"u"?e(W):typeof define=="function"&&define.amd?define(["exports"],e):e((n=typeof globalThis<"u"?globalThis:n||self)["@open-condo/bridge"]={})})(W,function(n){"use strict";let e={CondoWebAppRequestAuth:1e4};function o(b,f){let a=(function(){let t=(function*(){let c=0;for(;;)yield c++})(),d={};return{add(c,l){let i=l||t.next().value;return d[i]=c,i},resolve(c,l,i){let u=d[c];u&&(i(l)?u.resolve(l):u.reject(l),delete d[c])}}})();return f(t=>{if(t&&t.data&&typeof t.data=="object"&&"requestId"in t.data){let d=t.data,{requestId:c}=d,l=(function(i,u){var g={};for(var p in i)Object.prototype.hasOwnProperty.call(i,p)&&u.indexOf(p)<0&&(g[p]=i[p]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function"){var C=0;for(p=Object.getOwnPropertySymbols(i);C!("errorType"in i))}}),function(t,d={},c){let l=c||e[t]||1e3;return Promise.race([new Promise((i,u)=>{let g=a.add({resolve:i,reject:u},d.requestId);b(t,Object.assign(Object.assign({},d),{requestId:g}))}),new Promise((i,u)=>{setTimeout(()=>u((function(g){return{errorType:"client",errorCode:5,errorReason:"TIMEOUT_REACHED",errorMessage:`Request was failed. Response was not received in ${g} ms timeout.`}})(l)),l)})])}}var r="2.3.0";let s=typeof window<"u",v=[...s?["CondoWebAppCloseModalWindow","CondoWebAppGetActiveProgressBars","CondoWebAppGetFragment","CondoWebAppGetLaunchParams","CondoWebAppRedirect","CondoWebAppRequestAuth","CondoWebAppResizeWindow","CondoWebAppShowModalWindow","CondoWebAppShowNotification","CondoWebAppShowProgressBar","CondoWebAppUpdateModalWindow","CondoWebAppUpdateProgressBar"]:[]],w=s?parent:void 0,h=(function(){let b=[];function f(a){b.push(a)}return s&&"addEventListener"in window&&window.addEventListener("message",function(a){let t=a.data;typeof t=="object"&&b.forEach(d=>d(t))}),{send:o(function(a,t){w&&typeof w.postMessage=="function"&&w.postMessage({handler:a,params:t,type:"condo-bridge",version:r},"*")},f),supports:function(a){return v.includes(a)},subscribe:f,unsubscribe:function(a){let t=b.indexOf(a);t>=0&&b.splice(t,1)}}})();n.default=h,Object.defineProperty(n,"__esModule",{value:!0})})});var k=class{constructor(e){this.platformId="web";this.plugins={};for(let o of e)this.plugins[o.name]=o}async _init(){let e=[];for(let o of Object.values(this.plugins))o._init&&e.push(o._init());await Promise.allSettled(e)}};var S=R(A());function m(n,e,o){n.then(e).catch(o)}function y(n,e,o,r=1e3){return new Promise((s,v)=>{let w=`${Date.now()}_${Math.random().toString(36).substring(2,9)}`,h={handler:e,params:{...o,requestId:w},eventType:n,version:"1.0.0-cordova-web-wrapper"},b=setTimeout(()=>{window.removeEventListener("message",f),v(new Error(`PostMessage timeout after ${r}ms for event: ${e}`))},r),f=a=>{let t=a.data;t&&t.data&&t.data.requestId===w&&(clearTimeout(b),window.removeEventListener("message",f),t.data.errorMessage?v(t.data):s(t.data))};window.addEventListener("message",f),window.parent&&window.parent!==window?(console.log("Sending PM to parent window",h),window.parent.postMessage(h,"*")):(clearTimeout(b),window.removeEventListener("message",f),v(new Error("No parent window available")))})}var E=class{constructor(){this.name="condo";this.history={pushState(e,o,r,s){m(y("condo-cordova","CondoWebAppPushHistoryState",{state:e,title:o}),r,s)},replaceState(e,o,r,s){m(y("condo-cordova","CondoWebAppReplaceHistoryState",{state:e,title:o}),r,s)},back(e,o){m(y("condo-cordova","CondoWebAppPopHistoryState",{amount:1}),e,o)},go(e,o,r){m(y("condo-cordova","CondoWebAppPopHistoryState",{amount:-e}),o,r)}}}requestServerAuthorizationByUrl(e,o,r,s){m(S.default.send("CondoWebAppRequestAuth",{url:e}).then(v=>v.response),r,s)}getCurrentResident(e,o){m(y("condo-cordova-legacy","CondoWebAppGetCurrentResident",{},1e4),e,o)}closeApplication(e,o){e(!0)}getLaunchContext(e,o){m(S.default.send("CondoWebAppGetFragment").then(r=>r.fragment??null),e,o)}setInputsEnabled(e,o,r){o(e)}};var M=new Set;function P(n,e,o){let r=new CustomEvent(n,{detail:e});document.dispatchEvent(r),o&&M.add(n),console.debug(`Cordova mock: event "${n}" is fired`)}function j(){window.addEventListener("message",e=>{let o=e.data;o&&typeof o=="object"&&Object.hasOwn(o,"type")&&o.type==="CondoWebAppBackButtonEvent"&&P("backbutton")});let n=document.addEventListener.bind(document);document.addEventListener=function(e,o,r){n(e,o,r),M.has(e)&&typeof o=="function"&&(console.debug(`Cordova mock: Immediately firing "${e}" for late listener`),setTimeout(()=>{let s=new Event(e);o(s)},0))}}var x=R(A());function _(){new ResizeObserver(e=>{e&&e.length&&x.default.send("CondoWebAppResizeWindow",{height:e[0].target.clientHeight})}).observe(document.body)}function I(){if(document.body)document.body.style.height="auto",_();else{let n=new MutationObserver(()=>{document.body&&(n.disconnect(),document.body.style.height="auto",_())});n.observe(document.documentElement,{childList:!0})}}function T(){I(),j(),window.cordova._init().then(()=>P("deviceready",{},!0))}window.cordova=new k([new E]);document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{T()},0)}):setTimeout(()=>{T()},0);})(); +"use strict";var CordovaWeb=(()=>{var q=Object.create;var O=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var U=(n,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of H(e))!B.call(n,s)&&s!==o&&O(n,s,{get:()=>e[s],enumerable:!(r=z(e,s))||r.enumerable});return n};var R=(n,e,o)=>(o=n!=null?q($(n)):{},U(e||!n||!n.__esModule?O(o,"default",{value:n,enumerable:!0}):o,n));var A=G((W,L)=>{"use strict";(function(n,e){typeof W=="object"&&typeof L<"u"?e(W):typeof define=="function"&&define.amd?define(["exports"],e):e((n=typeof globalThis<"u"?globalThis:n||self)["@open-condo/bridge"]={})})(W,function(n){"use strict";let e={CondoWebAppRequestAuth:1e4};function o(b,f){let a=(function(){let t=(function*(){let c=0;for(;;)yield c++})(),d={};return{add(c,l){let i=l||t.next().value;return d[i]=c,i},resolve(c,l,i){let u=d[c];u&&(i(l)?u.resolve(l):u.reject(l),delete d[c])}}})();return f(t=>{if(t&&t.data&&typeof t.data=="object"&&"requestId"in t.data){let d=t.data,{requestId:c}=d,l=(function(i,u){var g={};for(var p in i)Object.prototype.hasOwnProperty.call(i,p)&&u.indexOf(p)<0&&(g[p]=i[p]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function"){var C=0;for(p=Object.getOwnPropertySymbols(i);C!("errorType"in i))}}),function(t,d={},c){let l=c||e[t]||1e3;return Promise.race([new Promise((i,u)=>{let g=a.add({resolve:i,reject:u},d.requestId);b(t,Object.assign(Object.assign({},d),{requestId:g}))}),new Promise((i,u)=>{setTimeout(()=>u((function(g){return{errorType:"client",errorCode:5,errorReason:"TIMEOUT_REACHED",errorMessage:`Request was failed. Response was not received in ${g} ms timeout.`}})(l)),l)})])}}var r="2.3.0";let s=typeof window<"u",v=[...s?["CondoWebAppCloseModalWindow","CondoWebAppGetActiveProgressBars","CondoWebAppGetFragment","CondoWebAppGetLaunchParams","CondoWebAppRedirect","CondoWebAppRequestAuth","CondoWebAppResizeWindow","CondoWebAppShowModalWindow","CondoWebAppShowNotification","CondoWebAppShowProgressBar","CondoWebAppUpdateModalWindow","CondoWebAppUpdateProgressBar"]:[]],w=s?parent:void 0,h=(function(){let b=[];function f(a){b.push(a)}return s&&"addEventListener"in window&&window.addEventListener("message",function(a){let t=a.data;typeof t=="object"&&b.forEach(d=>d(t))}),{send:o(function(a,t){w&&typeof w.postMessage=="function"&&w.postMessage({handler:a,params:t,type:"condo-bridge",version:r},"*")},f),supports:function(a){return v.includes(a)},subscribe:f,unsubscribe:function(a){let t=b.indexOf(a);t>=0&&b.splice(t,1)}}})();n.default=h,Object.defineProperty(n,"__esModule",{value:!0})})});var k=class{constructor(e){this.platformId="web";this.plugins={};for(let o of e)this.plugins[o.name]=o}async _init(){let e=[];for(let o of Object.values(this.plugins))o._init&&e.push(o._init());await Promise.allSettled(e)}};var S=R(A());function m(n,e,o){n.then(e).catch(o)}function y(n,e,o,r=1e3){return new Promise((s,v)=>{let w=`${Date.now()}_${Math.random().toString(36).substring(2,9)}`,h={handler:e,params:{...o,requestId:w},type:n,version:"1.0.0-cordova-web-wrapper"},b=setTimeout(()=>{window.removeEventListener("message",f),v(new Error(`PostMessage timeout after ${r}ms for event: ${e}`))},r),f=a=>{let t=a.data;t&&t.data&&t.data.requestId===w&&(clearTimeout(b),window.removeEventListener("message",f),t.data.errorMessage?v(t.data):s(t.data))};window.addEventListener("message",f),window.parent&&window.parent!==window?(console.log("Sending PM to parent window",h),window.parent.postMessage(h,"*")):(clearTimeout(b),window.removeEventListener("message",f),v(new Error("No parent window available")))})}var E=class{constructor(){this.name="condo";this.history={pushState(e,o,r,s){m(y("condo-cordova","CondoWebAppPushHistoryState",{state:e,title:o}),r,s)},replaceState(e,o,r,s){m(y("condo-cordova","CondoWebAppReplaceHistoryState",{state:e,title:o}),r,s)},back(e,o){m(y("condo-cordova","CondoWebAppPopHistoryState",{amount:1}),e,o)},go(e,o,r){m(y("condo-cordova","CondoWebAppPopHistoryState",{amount:-e}),o,r)}}}requestServerAuthorizationByUrl(e,o,r,s){m(S.default.send("CondoWebAppRequestAuth",{url:e}).then(v=>v.response),r,s)}getCurrentResident(e,o){m(y("condo-cordova-legacy","CondoWebAppGetCurrentResident",{},1e4),e,o)}closeApplication(e,o){e(!0)}getLaunchContext(e,o){m(S.default.send("CondoWebAppGetFragment").then(r=>r.fragment??null),e,o)}setInputsEnabled(e,o,r){o(e)}};var M=new Set;function P(n,e,o){let r=new CustomEvent(n,{detail:e});document.dispatchEvent(r),o&&M.add(n),console.debug(`Cordova mock: event "${n}" is fired`)}function j(){window.addEventListener("message",e=>{let o=e.data;o&&typeof o=="object"&&Object.hasOwn(o,"type")&&o.type==="CondoWebAppBackButtonEvent"&&P("backbutton")});let n=document.addEventListener.bind(document);document.addEventListener=function(e,o,r){n(e,o,r),M.has(e)&&typeof o=="function"&&(console.debug(`Cordova mock: Immediately firing "${e}" for late listener`),setTimeout(()=>{let s=new Event(e);o(s)},0))}}var x=R(A());function _(){new ResizeObserver(e=>{e&&e.length&&x.default.send("CondoWebAppResizeWindow",{height:e[0].target.clientHeight})}).observe(document.body)}function I(){if(document.body)document.body.style.height="auto",_();else{let n=new MutationObserver(()=>{document.body&&(n.disconnect(),document.body.style.height="auto",_())});n.observe(document.documentElement,{childList:!0})}}function T(){I(),j(),window.cordova._init().then(()=>P("deviceready",{},!0))}window.cordova=new k([new E]);document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{T()},0)}):setTimeout(()=>{T()},0);})(); diff --git a/src/cordova/utils.ts b/src/cordova/utils.ts index 7aa4599..e23950d 100644 --- a/src/cordova/utils.ts +++ b/src/cordova/utils.ts @@ -24,7 +24,7 @@ export function sendCordovaMessage( ...eventData, requestId, }, - eventType, + type: eventType, version: '1.0.0-cordova-web-wrapper', }