@apideck/vault-react
Version:
React hook for the Apideck Vault component.
2 lines (1 loc) • 1.75 kB
JavaScript
(function(l,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(l=typeof globalThis<"u"?globalThis:l||self,d(l["vault-react"]={}))})(this,function(l){"use strict";function d(r,a){if(r==null)return{};var i={},n=Object.keys(r),o,e;for(e=0;e<n.length;e++)o=n[e],!(a.indexOf(o)>=0)&&(i[o]=r[o]);return i}var h=["onClose","onReady","onConnectionChange","onConnectionDelete"],g=function(){var a="https://vaultjs.apideck.com",i=function(){var e=document.createElement("iframe");return e.style.display="none",e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.border="none",e.style.zIndex="9999",e.src=a,e},n=null;return{open:function(e){var c=e.onClose,u=e.onReady,f=e.onConnectionChange,y=e.onConnectionDelete,b=d(e,h);n=i(),document.body.appendChild(n);var k=function w(t){var v;if(n!==null){if(t.data==="on-ready"){var p;n.style.display="block",(p=n.contentWindow)==null||p.postMessage(b,a),u==null||u()}if(t.data==="on-close"&&(window.removeEventListener("message",w),c==null||c(),setTimeout(function(){n!==null&&(document.body.removeChild(n),n=null)},300)),typeof t.data=="object"&&(v=t.data)!=null&&v.data){var m;switch((m=t.data)==null?void 0:m.type){case"on-connection-change":f==null||f(t.data.data);break;case"on-connection-delete":y==null||y(t.data.data);break}}}};window.addEventListener("message",k)},close:function(){var e,c;(e=n)==null||(c=e.contentWindow)==null||c.postMessage({type:"close"},a),setTimeout(function(){n!==null&&(document.body.removeChild(n),n=null)},500)}}},s=g();const C=()=>({open:i=>{s.open(i)},close:()=>{s.close()}});l.useVault=C,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});