Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/classes/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
for (const callback of callbacks) {
if (typeof callback === 'function') {
try {
callback(element, relation);
await callback(element, relation);
} catch (e) {
console.warn(e);
}
}
});
}
}

applyChartCallbacks(
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Diagram extends Shape {

async clone(): Promise<void> {
await this.setTargetElement();
this.applyCallbacks(this.callbacks, this.targetElement);
await this.applyCallbacks(this.callbacks, this.targetElement);
}

async updateRelIds() {
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/hyperlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/shapes/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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<void> {
await this.applyCallbacks(
this.callbacks,
this.targetElement,
this.createdRelation,
Expand Down
2 changes: 1 addition & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type ShapeModificationCallback = (
element: XmlElement,
relation?: XmlElement,
info?: ElementInfo
) => void;
) => void | Promise<void>;
export type ChartModificationCallback = (
element: XmlElement,
chart?: XmlDocument,
Expand Down