Skip to main content
Language

Configuring Callbacks

In this example, we will show you how to configure the CreativeEditor SDK.

Explore a full code sample on Stackblitz or view the code on Github.

Callbacks#

The CE.SDK offers several different callbacks that are triggered by user interaction. Follow this guide to see some examples with descriptions.

In this example, all corresponding navigational elements in the user interface are enabled so that the callbacks can be tested.

General#

  • onUnsupportedBrowser: () => void will be triggered when the browser version or type is unsupported. If this handle is not configured, CE.SDK shows a native window.alert explaining that the current browser is unsupported and showing the list of supported ones. Alternatively a [separate method can be imported and used to check browser support](../shared/_partials/integrate-with-vanilla-js.
  • onBack: () => void | Promise<void> allows the registration of a function that is called when the back action is triggered by the user. When a Promise<void> is returned, a loading indicator will be shown on the 'Back'-button until the Promise resolves.
  • onClose: () => void | Promise<void> allows the registration of a function that is called when the close action is triggered by the user. When a Promise<void> is returned, a loading indicator will be shown on the 'Close'-button until the Promise resolves.

Scene Load & Save#

  • onSave: (scene: string) => Promise<void> allows the registration of a function that is called when the save button is triggered by the user. It contains the information of the current scene as a string that can be stored and reloaded at a later time. The user flow is continued when the returned Promise<void> is resolved.
  • onDownload: 'download' | (scene: string) => Promise<void> allows the registration of a function that is called when the download button is triggered by the user. It contains the information of the current scene as a string and thus is similar to the onSave callback. The purpose here is to download the scene to the client and is most useful in developer settings. If the callback is set to the string download instead of a function, the current scene is automatically downloaded.
  • onLoad: () => Promise<string> allows the registration of a function that is called when the load button is triggered by the user. It returns a Promise<string> with the scene as string as payload.

Export & Upload#

  • onExport: (blobs: Blob[], options: ExportOptions) => void allows the registration of a function that is called when the export button is triggered by the user. It'll receive an array of Blob objects, one for each page that was selected for export. ExportOptions contains the mimeType, quality settings and pages that where selected for export. See Exporting Pages for details.
  • onUpload: (file: File, onProgress: (progress: number) => void, context: UploadCallbackContext) => Promise<AssetDefinition> allows the registration of a function that is called when the upload button is triggered by the user. The file parameter contains the data being uploaded via the upload dialog. The onProgress callback can be used to indicate progress to the UI, where a number of 1.0 equals 100 percent completion. The callback must return a Promise that must contain a unique id: string, the uri: string of the uploaded data, and the thumbUri: string. See Uploading Images for details.