@cloudquery/plugin-config-ui-connector
Version:
Plugin configuration UI connector for CloudQuery Cloud App
1 lines • 1.94 kB
JavaScript
!function(e,s){if("object"==typeof exports&&"object"==typeof module)module.exports=s();else if("function"==typeof define&&define.amd)define([],s);else{var t=s();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,(()=>(()=>{"use strict";var e={d:(s,t)=>{for(var n in t)e.o(t,n)&&!e.o(s,n)&&Object.defineProperty(s,n,{enumerable:!0,get:t[n]})},o:(e,s)=>Object.prototype.hasOwnProperty.call(e,s),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},s={};e.r(s),e.d(s,{MessageHandler:()=>o,formMessageTypes:()=>a,getPluginUiMessageHandler:()=>i,pluginUiMessageTypes:()=>n});const t="plugin-ui-connector-iframe",n=["loaded","ready","go_to_previous_step","delete","cancel","submitted","show_toast"],a=["init","auth_connector_result"];class o{constructor(e,s,t){this.callbacks=new Map,this.sendMessageTypes=new Set,this.receiveMessageTypes=new Set,this.sendMessageTypes=new Set(e),this.receiveMessageTypes=new Set(s),this.sendMessageWindow=t,window.addEventListener("message",this.handleMessage.bind(this))}sendMessage(e,...s){if(!this.sendMessageTypes.has(e))throw new Error(`Unknown send message type: ${String(e)}`);this.sendMessageWindow.postMessage({type:e,payload:s[0],id:t},"*")}subscribeToMessage(e,s){if(!this.receiveMessageTypes.has(e))throw new Error(`Unknown receive message type: ${String(e)}`);const t=this.callbacks.get(e);return t?t.push(s):this.callbacks.set(e,[s]),()=>{const t=this.callbacks.get(e);t&&this.callbacks.set(e,t.filter((e=>e!==s)))}}subscribeToMessageOnce(e,s){const t=n=>{s(n);const a=this.callbacks.get(e);a&&this.callbacks.set(e,a.filter((e=>e!==t)))};return this.subscribeToMessage(e,t)}handleMessage(e){const{id:s}=e.data;if(s!==t)return;const n=e.data.type,a=this.callbacks.get(n);if(a)for(const s of a)s(e.data.payload)}}function i(){return new o(n,a,window.parent)}return s})()));