Gate a module with shouldInitialize

A module can stay registered but inactive until its option says otherwise. When shouldInitialize() returns false, the editor skips initialize and external API calls to that module return nothing.

Enabled module

Enabled editor content.

Disabled module

Disabled editor content.

Comparison output
Ready.
Example configuration - Conditional Modules
class ReviewBanner {
  shouldInitialize() {
    return Boolean(this.context.options.enableReviewBanner);
  }

  initialize() {
    this.banner = document.createElement('div');
  }

  destroy() {
    this.banner.remove();
  }
}

summernote.create('#module-conditional-enabled', {
  enableReviewBanner: true,
  modules: {
    reviewBanner: ReviewBanner,
  },
});

summernote.create('#module-conditional-disabled', {
  enableReviewBanner: false,
  modules: {
    reviewBanner: ReviewBanner,
  },
});