From 58b45911741c0dbbccd462b2976560bb3999eaef Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Wed, 14 Jul 2021 21:07:10 +0800 Subject: [PATCH] feat: allow access to reference element in onclone (#2584) --- src/dom/document-cloner.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index 779ad4b..b4a234e 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -24,7 +24,7 @@ import {getQuote} from '../css/property-descriptors/quotes'; export interface CloneOptions { id: string; ignoreElements?: (element: Element) => boolean; - onclone?: (document: Document) => void; + onclone?: (document: Document, element: HTMLElement) => void; } export type CloneConfigurations = CloneOptions & { @@ -89,7 +89,9 @@ export class DocumentCloner { const onclone = this.options.onclone; - if (typeof this.clonedReferenceElement === 'undefined') { + const referenceElement = this.clonedReferenceElement; + + if (typeof referenceElement === 'undefined') { return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`); } @@ -103,7 +105,7 @@ export class DocumentCloner { if (typeof onclone === 'function') { return Promise.resolve() - .then(() => onclone(documentClone)) + .then(() => onclone(documentClone, referenceElement)) .then(() => iframe); }