Skip to content

Commit

Permalink
feat: allow access to reference element in onclone (#2584)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvh committed Jul 14, 2021
1 parent 92fa448 commit 58b4591
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/dom/document-cloner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -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`);
}

Expand All @@ -103,7 +105,7 @@ export class DocumentCloner {

if (typeof onclone === 'function') {
return Promise.resolve()
.then(() => onclone(documentClone))
.then(() => onclone(documentClone, referenceElement))
.then(() => iframe);
}

Expand Down

0 comments on commit 58b4591

Please sign in to comment.