Skip to content

Plugin callbacks

Communication with editor is basically done by using props down and callbacks up. To be able to hook to events happing inside the editor we use callbacks inside TOPOL_OPTIONS to achieve this.

For example:

js
const TOPOL_OPTIONS = {
    //...
    callbacks: {
        onSave(json, html)
    },
    //...
}

On save

Called when "save" button is clicked in Top Bar or when saving is triggered programitcally using TopolPlugin.save() function.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onSave(json, html) {
      // save json and html on your infrastructure
    },
  },
};

On save and close

Called when "save and close" button is clicked in Top Bar.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onSaveAndClose(json, html) {
      // save json and html on your infrastructure and close the editor
    },
  },
};

On test email send

Called when send test email button is clicked in editor preview.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onTestSend(email, json, html) {
      // send an testing email using your sender of choice
    },
  },
};

On file manager open

Called when the user clicks on Choose a file (e.g. as a property of an image). You can read more about the feature here.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onOpenFileManager() {
      // open your custom filemanager dialog
    },
  },
};

On init

Called when the editor is initialized, (e.g. for custom loading integration)

js
const TOPOL_OPTIONS = {
  callbacks: {
    onInit(json, html) {
      // hide the loader or track the usage
    },
  },
};

On loaded

Called when template loading is finished after calling TopolPlugin.load(YOUR_TEMPLATE)

js
const TOPOL_OPTIONS = {
  callbacks: {
    onLoaded(json, html) {
      // hide the loader
    },
  },
};

On block save

Called when user creates new saved block. You can read more here.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onBlockSave(block) {
      // save the block on your infrastructure
    },
  },
};

On block remove

Called when user removes saved block. You can read more here.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onBlockRemove(blockId) {
      // remove the block on your infrastructure
    },
  },
};

On block edit

Called when user edits saved block. You can read more here.

js
const TOPOL_OPTIONS = {
  callbacks: {
    onBlockEdit(blockId) {
      // edit the block on your infrastructure
    },
  },
};

On undo change

Called when user clicks undo button

js
const TOPOL_OPTIONS = {
  callbacks: {
    onUndoChange(count) {},
  },
};

On redo change

Called when user clicks redo button

js
const TOPOL_OPTIONS = {
  callbacks: {
    onRedoChange(count) {},
  },
};

On preview

Called when user want to navigate to preview

js
const TOPOL_OPTIONS = {
  callbacks: {
    onPreview(html) {},
  },
};

On alert

Callend when alerts are explicitly disabled. You read more about the custom alerts here

js
const TOPOL_OPTIONS = {
  callbacks: {
    onAlert(notification) {
      //use your own notification, or create proxy for built-in notifications
    },
  },
};