The Visual Editor API is designed for experienced CloudCannon developers. If you need help with custom integrations or your CloudCannon setup in general, please contact our friendly support team.
CloudCannon's Visual Editor API CloudCannon's Visual Editor API is a public JavaScript API for building custom integrations with the Visual Editor. It lets you run your own code inside the Visual Editor to read and write content, listen for changes, and upload files using code running inside your website files.Visual Editor API
This article assumes you know how to initialize the Visual Editor API. For custom inline editing, read Create custom inline editing with the Visual Editor API. For a complete list of API objects and methods, please read our reference documentation on the Visual Editor API.
Control the loading state#
Calling CloudCannon's visual editing interface provides a user-friendly way of updating your website files on an interactive preview of your webpage. You can navigate around your website preview using links/buttons, as you would on the live version, and edit your content inline on the page, or with the data panel or sidebar. What you see in the Visual Editor is what your website visitors will see on your live webpages.*.setLoading() allows you to show or hide the Visual EditorVisual Editor
const api = window.CloudCannonAPI.useVersion('v1', true);
await api.setLoading('Initializing custom integration...');
// Do async setup work
await api.setLoading(undefined); Pass a string to api.setLoading() to show the loading indicator with a message.
Pass undefined to clear the loading indicator when your integration is ready.
Upload a file#
Calling *.uploadFile() allows you to upload a file through CloudCannon's file handling system.
const input = document.querySelector('input[type="file"]');
const file = input.files[0];
const path = await api.uploadFile(file, undefined);
console.log('Uploaded to:', path);Get the file input element from the DOM.
Get the selected file from the input.
Call api.uploadFile() to upload the file. Pass undefined as the second argument to use default upload behavior, or pass an Input configuration object (the same shape as an Input in your CloudCannon Configuration File) to control where the file is uploaded and which asset sources or DAMs are offered.
Get a preview URL#
Calling *.getPreviewUrl() allows you to get a working URL for a file that may not yet be committed to your Site, such as an image uploaded in the current editing session. Use this instead of the source path directly when displaying images in the Visual Editor.
const previewUrl = await api.getPreviewUrl('/images/hero.jpg'); Pass a source path to api.getPreviewUrl() to get a URL that works within the Visual Editor, including for files that haven't yet been committed to the Site.