Skip to content

Commit

Permalink
Remove iframe-resizer package (#34)
Browse files Browse the repository at this point in the history
* wip

* Replace `iframe-resizer` with our own implementation

* Bump version
  • Loading branch information
hwhmeikle committed May 17, 2023
1 parent 9c9056b commit d0c55fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@authsignal/browser",
"version": "0.1.3",
"version": "0.1.4",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand All @@ -24,7 +24,6 @@
"@fingerprintjs/fingerprintjs": "^3.3.6",
"@simplewebauthn/browser": "^7.2.0",
"a11y-dialog": "^7.5.2",
"iframe-resizer": "^4.3.6",
"ky": "^0.33.3",
"uuid": "^9.0.0"
},
Expand Down
27 changes: 13 additions & 14 deletions src/popup-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import A11yDialog from "a11y-dialog";
import "iframe-resizer/js/iframeResizer";
import "iframe-resizer/js/iframeResizer.contentWindow";

const CONTAINER_ID = "__authsignal-popup-container";
const CONTENT_ID = "__authsignal-popup-content";
Expand All @@ -24,7 +22,6 @@ type PopupHandlerOptions = {

class PopupHandler {
private popup: A11yDialog | null = null;
private isHeightAutoResized = true;

constructor({width}: PopupHandlerOptions) {
if (document.querySelector(`#${CONTAINER_ID}`)) {
Expand Down Expand Up @@ -124,6 +121,8 @@ class PopupHandler {
document.body.removeChild(dialogEl);
document.head.removeChild(styleEl);
}

window.removeEventListener("message", resizeIframe);
}

show({url}: PopupShowInput) {
Expand All @@ -146,17 +145,9 @@ class PopupHandler {
dialogContent.appendChild(iframe);
}

// @ts-expect-error can't get typescript import to behave nicely, this works though
iFrameResize(
{
checkOrigin: false,
scrolling: true,
onInit: () => {
this.popup?.show();
},
},
iframe
);
window.addEventListener("message", resizeIframe);

this.popup?.show();
}

close() {
Expand All @@ -176,4 +167,12 @@ class PopupHandler {
}
}

function resizeIframe(event: MessageEvent) {
const iframeEl = document.querySelector<HTMLIFrameElement>(`#${IFRAME_ID}`);

if (iframeEl && event.data.height) {
iframeEl.style.height = event.data.height + "px";
}
}

export {PopupHandler};

0 comments on commit d0c55fe

Please sign in to comment.