From 546251ea684717b38d431f4e952be3b6432d3432 Mon Sep 17 00:00:00 2001 From: makhnatkin Date: Mon, 7 Oct 2024 10:05:48 +0200 Subject: [PATCH] feat(srcDoc): added onload arg --- src/runtime/SrcDocIFrameController.ts | 4 +++- src/types.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/SrcDocIFrameController.ts b/src/runtime/SrcDocIFrameController.ts index b762527..b42dd7e 100644 --- a/src/runtime/SrcDocIFrameController.ts +++ b/src/runtime/SrcDocIFrameController.ts @@ -79,7 +79,9 @@ export class SrcDocIFrameController extends Disposable implements IEmbeddedConte this.addAnchorLinkHandlers(); this.handleHashChange(); - this.config.onload?.(this.host); + if (this.config.onload) { + this.dispose.add(() => this.config.onload?.(this.host)); + } } // finds all relative links (href^="#") and changes their click behavior diff --git a/src/types.ts b/src/types.ts index 120ea04..084afff 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,7 +9,7 @@ export interface EmbedsConfig { classNames?: string[]; styles?: Record; isolatedSandboxHostURIOverride?: string; - onload?: (host: HTMLIFrameElement) => void; + onload?: (host: HTMLIFrameElement) => (() => void) | void; } export type Unsubscribe = () => void;