UNPKG

@apideck/vault-js

Version:

<img src="https://user-images.githubusercontent.com/8850410/208065819-716c6e02-98c9-4df5-b687-e5acd1e3c4e5.png" width="100%" />

95 lines (90 loc) 3.5 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var _excluded = ["onClose", "onReady", "onConnectionChange", "onConnectionDelete"]; var createApideckVault = function createApideckVault() { var vaultIframeUrl = 'https://vaultjs.apideck.com'; var createModal = function createModal() { var modal = document.createElement('iframe'); modal.style.display = 'none'; modal.style.position = 'fixed'; modal.style.top = '0'; modal.style.left = '0'; modal.style.width = '100%'; modal.style.height = '100%'; modal.style.border = 'none'; modal.style.zIndex = '9999'; modal.src = vaultIframeUrl; return modal; }; var modal = null; return { open: function open(options) { var onClose = options.onClose, onReady = options.onReady, onConnectionChange = options.onConnectionChange, onConnectionDelete = options.onConnectionDelete, otherOptions = _objectWithoutPropertiesLoose(options, _excluded); modal = createModal(); document.body.appendChild(modal); var onMessage = function onMessage(event) { var _event$data; if (modal === null) return; if (event.data === 'on-ready') { var _modal$contentWindow; modal.style.display = 'block'; (_modal$contentWindow = modal.contentWindow) == null ? void 0 : _modal$contentWindow.postMessage(otherOptions, vaultIframeUrl); onReady == null ? void 0 : onReady(); } if (event.data === 'on-close') { window.removeEventListener('message', onMessage); onClose == null ? void 0 : onClose(); // Remove the iframe from the DOM after transition animation setTimeout(function () { if (modal === null) return; document.body.removeChild(modal); modal = null; }, 300); } if (typeof event.data === 'object' && (_event$data = event.data) != null && _event$data.data) { var _event$data2; switch ((_event$data2 = event.data) == null ? void 0 : _event$data2.type) { case 'on-connection-change': onConnectionChange == null ? void 0 : onConnectionChange(event.data.data); break; case 'on-connection-delete': onConnectionDelete == null ? void 0 : onConnectionDelete(event.data.data); break; } } }; window.addEventListener('message', onMessage); }, close: function close() { var _modal, _modal$contentWindow2; (_modal = modal) == null ? void 0 : (_modal$contentWindow2 = _modal.contentWindow) == null ? void 0 : _modal$contentWindow2.postMessage({ type: 'close' }, vaultIframeUrl); // Fallback remove the iframe from the DOM in case the iframe doesn't send a message setTimeout(function () { if (modal === null) return; document.body.removeChild(modal); modal = null; }, 500); } }; }; var ApideckVault = /*#__PURE__*/createApideckVault(); exports.ApideckVault = ApideckVault; //# sourceMappingURL=vault-js.cjs.development.js.map