Skip to content

Commit a7c8cba

Browse files
Add clearHistory and createUndoPoint to specify the undo behaviour
1 parent 48fa415 commit a7c8cba

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@creatomate/preview",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "Render video and image previews in your web app prior to creating a final MP4, GIF, JPEG or PNG through the API.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/Preview.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class Preview {
130130
iframe.setAttribute('height', '100%');
131131
iframe.setAttribute('scrolling', 'no');
132132
iframe.setAttribute('allow', 'autoplay');
133-
iframe.setAttribute('src', `https://creatomate.com/embed?version=1.5.0&token=${publicToken}`);
133+
iframe.setAttribute('src', `https://creatomate.com/embed?version=1.6.0&token=${publicToken}`);
134134
iframe.style.border = 'none';
135135
iframe.style.display = 'none';
136136

@@ -187,9 +187,12 @@ export class Preview {
187187
* Make sure the template is located in the project from which you are using the public token.
188188
*
189189
* @param templateId The ID of the template.
190+
* @param createUndoPoint Set to 'true' if you wish to add an undo point to be used later with 'undo()' and 'redo()'.
191+
* @see undo()
192+
* @see redo()
190193
*/
191-
async loadTemplate(templateId: string): Promise<void> {
192-
await this._sendCommand({ message: 'setTemplate', templateId }).catch((error) => {
194+
async loadTemplate(templateId: string, createUndoPoint = false): Promise<void> {
195+
await this._sendCommand({ message: 'setTemplate', templateId, createUndoPoint }).catch((error) => {
193196
throw new Error(`Failed to load template: ${error.message}`);
194197
});
195198

@@ -326,7 +329,7 @@ export class Preview {
326329
}
327330

328331
/**
329-
* Reverts the last changes made by 'setSource()', 'applyModifications()', or the user when in interactive mode.
332+
* Reverts the last changes made by 'loadTemplate', 'setSource()', 'applyModifications()', or the user when in interactive mode.
330333
*
331334
* @see setSource()
332335
* @see applyModifications()
@@ -348,6 +351,19 @@ export class Preview {
348351
});
349352
}
350353

354+
/**
355+
* Clears the undo history stack, preventing undoing or redoing previous changes.
356+
*
357+
* @param stack Specify 'undo' or 'redo' to only clear their respective states, or omit this parameter to clear both.
358+
* @see undo()
359+
* @see redo()
360+
*/
361+
async clearHistory(stack?: 'undo' | 'redo'): Promise<void> {
362+
return this._sendCommand({ message: 'clearHistory', stack }).catch((error) => {
363+
throw new Error(`Failed to clear the history: ${error.message}`);
364+
});
365+
}
366+
351367
/**
352368
* Starts playing the video.
353369
*

0 commit comments

Comments
 (0)