feat: allow access to reference element in onclone (#2584)

This commit is contained in:
Niklas von Hertzen 2021-07-14 21:07:10 +08:00 committed by GitHub
parent 92fa448913
commit 58b4591174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ import {getQuote} from '../css/property-descriptors/quotes';
export interface CloneOptions { export interface CloneOptions {
id: string; id: string;
ignoreElements?: (element: Element) => boolean; ignoreElements?: (element: Element) => boolean;
onclone?: (document: Document) => void; onclone?: (document: Document, element: HTMLElement) => void;
} }
export type CloneConfigurations = CloneOptions & { export type CloneConfigurations = CloneOptions & {
@ -89,7 +89,9 @@ export class DocumentCloner {
const onclone = this.options.onclone; 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`); return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`);
} }
@ -103,7 +105,7 @@ export class DocumentCloner {
if (typeof onclone === 'function') { if (typeof onclone === 'function') {
return Promise.resolve() return Promise.resolve()
.then(() => onclone(documentClone)) .then(() => onclone(documentClone, referenceElement))
.then(() => iframe); .then(() => iframe);
} }