setCustomImportFunction
Release 3.2.2507+
Registers a custom function for handling document imports. When set, the editor's built-in import logic is bypassed and your function is called instead.
Parameters
| Name | Type | Description |
|---|---|---|
func | function | Custom import function |
Custom function signature
| Name | Type | Description |
|---|---|---|
docFile | File | Document file to import |
bOverwrite | boolean | Whether to overwrite the current content |
Return value
| Key | Type | Description |
|---|---|---|
serializedData | number[] | Document model serialized after conversion |
importPath | string | Browser-accessible path to the converted file |
importImageMap | Object | Map of converted image resources → accessible image URLs |
The custom import function MUST return the serialized document model data, a URL/path the browser can use to access the imported file, and the converted image-resource map.
Example
// Synchronous example
editor.setCustomImportFunction((docFile, bOverwrite) => {
// perform import
return { serializedData, importPath, importImageMap };
});
Release 3.2.2507+
// Async example (async/await)
editor.setCustomImportFunction(async (docFile, bOverwrite) => {
const { serializedData, importPath, importImageMap } =
await new Promise(resolve => setTimeout(resolve, 1000)); // perform import
return { serializedData, importPath, importImageMap };
});
// Async example (Promise)
editor.setCustomImportFunction((docFile, bOverwrite) => {
return new Promise((resolve, reject) => { // perform import
setTimeout(() => {
resolve({ serializedData, importPath, importImageMap });
}, 1000);
});
});