From 362ca6d320c0c8380b732a952ed40df2f0f042bf Mon Sep 17 00:00:00 2001 From: DaBorsten Date: Fri, 10 Jul 2026 22:54:45 +0200 Subject: [PATCH] fix: await applyCallbacks so cover images replace correctly when placeholder is larger Previously the callback ran without awaiting, so setRelationTargetCover could finish after the slide was already written, leaving the larger placeholder image in place instead of the replacement. --- src/classes/shape.ts | 10 +++++----- src/shapes/diagram.ts | 2 +- src/shapes/generic.ts | 2 +- src/shapes/hyperlink.ts | 2 +- src/shapes/image.ts | 8 ++++---- src/types/types.ts | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/classes/shape.ts b/src/classes/shape.ts index a28d10f..28ce4fd 100644 --- a/src/classes/shape.ts +++ b/src/classes/shape.ts @@ -234,20 +234,20 @@ export class Shape { .setAttribute(this.relAttribute, this.createdRid); } - applyCallbacks( + async applyCallbacks( callbacks: ShapeModificationCallback[], element: XmlElement, relation?: XmlElement, - ): void { - callbacks.forEach((callback) => { + ): Promise { + for (const callback of callbacks) { if (typeof callback === 'function') { try { - callback(element, relation); + await callback(element, relation); } catch (e) { console.warn(e); } } - }); + } } applyChartCallbacks( diff --git a/src/shapes/diagram.ts b/src/shapes/diagram.ts index 0df9b91..0a2f427 100644 --- a/src/shapes/diagram.ts +++ b/src/shapes/diagram.ts @@ -125,7 +125,7 @@ export class Diagram extends Shape { async clone(): Promise { await this.setTargetElement(); - this.applyCallbacks(this.callbacks, this.targetElement); + await this.applyCallbacks(this.callbacks, this.targetElement); } async updateRelIds() { diff --git a/src/shapes/generic.ts b/src/shapes/generic.ts index baae355..7385a2a 100644 --- a/src/shapes/generic.ts +++ b/src/shapes/generic.ts @@ -65,7 +65,7 @@ export class GenericShape extends Shape { // Pass both the element and the relation to applyCallbacks // Use the documentElement property to get the root element of the XML document - this.applyCallbacks(this.callbacks, this.targetElement, slideRelXml.documentElement as XmlElement); + await this.applyCallbacks(this.callbacks, this.targetElement, slideRelXml.documentElement as XmlElement); } /** diff --git a/src/shapes/hyperlink.ts b/src/shapes/hyperlink.ts index b97a729..e845b51 100644 --- a/src/shapes/hyperlink.ts +++ b/src/shapes/hyperlink.ts @@ -46,7 +46,7 @@ export class Hyperlink extends Shape { // Pass both the element and the relation to applyCallbacks // Use the documentElement property to get the root element of the XML document - this.applyCallbacks(this.callbacks, this.targetElement, slideRelXml); + await this.applyCallbacks(this.callbacks, this.targetElement, slideRelXml); return this; } diff --git a/src/shapes/image.ts b/src/shapes/image.ts index 8e7f25e..98bcb1b 100644 --- a/src/shapes/image.ts +++ b/src/shapes/image.ts @@ -82,7 +82,7 @@ export class Image extends Shape implements IImage { await this.updateTargetElementRelId(); await this.processImageRelations(targetTemplate, targetSlideNumber); - this.applyImageCallbacks(); + await this.applyImageCallbacks(); await this.replaceIntoSlideTree(); @@ -99,7 +99,7 @@ export class Image extends Shape implements IImage { await this.updateTargetElementRelId(); await this.processImageRelations(targetTemplate, targetSlideNumber); - this.applyImageCallbacks(); + await this.applyImageCallbacks(); await this.appendToSlideTree(); @@ -208,8 +208,8 @@ export class Image extends Shape implements IImage { * Third argument this.createdRelation is necessery to directly * manipulate relation Target and change the image. */ - applyImageCallbacks() { - this.applyCallbacks( + async applyImageCallbacks(): Promise { + await this.applyCallbacks( this.callbacks, this.targetElement, this.createdRelation, diff --git a/src/types/types.ts b/src/types/types.ts index 5401fe2..d7183d0 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -31,7 +31,7 @@ export type ShapeModificationCallback = ( element: XmlElement, relation?: XmlElement, info?: ElementInfo -) => void; +) => void | Promise; export type ChartModificationCallback = ( element: XmlElement, chart?: XmlDocument,