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

NameTypeDescription
funcfunctionCustom import function

Custom function signature

NameTypeDescription
docFileFileDocument file to import
bOverwritebooleanWhether to overwrite the current content

Return value

KeyTypeDescription
serializedDatanumber[]Document model serialized after conversion
importPathstringBrowser-accessible path to the converted file
importImageMapObjectMap 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);
    });
});