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 nativewindow.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.
Navigation#
onBack: () => void | Promise<void>
allows the registration of a function that is called when theback
action is triggered by the user. When aPromise<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 theclose
action is triggered by the user. When aPromise<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 thesave
button is triggered by the user. It contains the information of the currentscene
as a string that can be stored and reloaded at a later time. The user flow is continued when the returnedPromise<void>
is resolved.
onDownload: 'download' | (scene: string) => Promise<void>
allows the registration of a function that is called when thedownload
button is triggered by the user. It contains the information of the currentscene
as a string and thus is similar to theonSave
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 stringdownload
instead of a function, the current scene is automatically downloaded.
onLoad: () => Promise<string>
allows the registration of a function that is called when theload
button is triggered by the user. It returns aPromise<string>
with thescene
asstring
as payload.
Export & Upload#
onExport: (blobs: Blob[], options: ExportOptions) => void
allows the registration of a function that is called when theexport
button is triggered by the user. It'll receive an array ofBlob
objects, one for each page that was selected for export.ExportOptions
contains themimeType
,quality
settings andpages
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 theupload
button is triggered by the user. Thefile
parameter contains the data being uploaded via the upload dialog. TheonProgress
callback can be used to indicate progress to the UI, where a number of1.0
equals 100 percent completion. The callback must return a Promise that must contain a uniqueid: string
, theuri: string
of the uploaded data, and thethumbUri: string
. See Uploading Images for details.