Skip to content

Components

Detailed reference documentation for SuperDoc's components and their APIs.

SuperDoc provides a set of components that can be used individually or together to create a complete document editing experience. This reference documents the API for each component.

SuperDoc Component

The main component that orchestrates document editing, viewing, collaboration, and UI.

Initialization

javascript
import '@harbour-enterprises/superdoc/style.css';
import { SuperDoc } from '@harbour-enterprises/superdoc';

const superdoc = new SuperDoc({
  selector: '#root',
  documents: [
    id: 'pets-123',
    type: 'docx',
    url: 'http://my-document-url.docx',
  ],
  pagination: true,
  licenseKey: 'community-and-eval-agplv3',
  telemetry: { 
    enabled: true,
  } //basic usage metrics and exceptions
})

Configuration Options

PropertyTypeDescriptionRequiredDefault
selectorstring|ElementCSS selector or DOM element where SuperDoc will be rendered-
documentsarrayArray of document objects to load-
superdocIdstringUnique identifier for this SuperDoc instanceRandom UUID
documentModestringInitial mode: 'viewing' or 'editing''viewing'
userobjectCurrent user information{}
toolbarstring|ElementDOM element to render toolbarInternal toolbar
modulesobjectAdditional modules configuration{}

Document Object Properties

PropertyTypeDescriptionRequired
idstringUnique identifier for the document
typestringDocument type: 'docx', 'pdf', or 'html'
dataFile|BlobDocument data as a File or Blob object
urlstringURL to fetch the document
stateobjectInitial document state

User Object Properties

PropertyTypeDescriptionRequired
namestringUser's display name
emailstringUser's email address
imagestringURL for user's avatar
idstringUnique identifier for the user

Modules Configuration

javascript
modules: {
  // Collaboration module configuration
  collaboration: {
    url: 'wss://collaboration-server.example.com',
    token: 'auth-token',
    params: { /* Additional connection parameters */ }
  },
}

Methods

MethodParametersReturnDescription
export()-Promise<Void>Exports the SuperDocs and triggers download
setDocumentMode(mode)mode: 'viewing' or 'editing'-Switches between view and edit modes
on(event, callback)event: string, callback: function-Registers an event listener
off(event, callback)event: string, callback: function-Removes an event listener
getHTML()--Get a list of HTML strings (one per DOCX document)

Hooks

HookParametersDescription
onEditorBeforeCreate-Called before the document editor is created.
onEditorCreate{ editor }Called when the document editor is created.
onEditorDestroy-Called when the document editor is destroyed.
onContentError{ error, editor }Called when there’s an error with document content.
onReady-Called when the document is fully initialized and ready.
onAwarenessUpdate{ users }Called when user presence information changes.
onPdfDocumentReady-Called when the PDF version of the document is ready.
onCollaborationReady{ editor }Called when collaboration is ready.
onException{ error, editor }Called when an exception occurs.

SuperEditor Component

The core editor component that powers DOCX editing in SuperDoc. For advanced use cases, you can use SuperEditor directly.

Initialization

javascript
import '@harbour-enterprises/superdoc/super-editor/style.css';
import { SuperEditor } from '@harbour-enterprises/superdoc/super-editor';

const editor = new SuperEditor({
  selector: '#editor-container',
  fileSource: docxFile,
  state: initialState,
  documentId: 'doc-123',
  options: {
    user: {
      name: 'Editor User',
      email: 'editor@example.com',
    },
    // Additional options...
  },
});

Configuration Options

PropertyTypeDescriptionRequiredDefault
selectorstring|ElementWhere to render the editor-
fileSourceFile|Blob|stringDocument file or URL-
stateobjectInitial document statenull
documentIdstringUnique document ID-
optionsobjectEditor options-

Editor Options

PropertyTypeDescriptionDefault
userobjectCurrent user information{}
colorsobjectTheme color configurationDefault colors
rolestringUser role: 'editor', 'viewer', 'admin''editor'
documentModestring'viewing' or 'editing''viewing'
paginationbooleanEnable paginationtrue
rulersarrayDocument ruler configuration[]
ydocY.DocYjs document for collaborationnull
collaborationProviderobjectCollaboration provider instancenull
isNewFilebooleanWhether this is a new documentfalse
handleImageUploadfunctionCustom image upload handlernull
telemetryobjectTelemetry configurationnull

Methods

MethodParametersReturnDescription
destroy()--Destroys the editor instance
getHTML()-stringGets document content as HTML
getJSON()-objectGets document content as JSON
getPageStyles()-objectGets page style information
focus()--Focuses the editor
blur()--Removes focus from the editor
exportDocx()-Promise<Blob>Exports as DOCX

Hooks

SuperEditor has a variety of hooks

HookParametersDescription
onBeforeCreate-Called before the creation process starts.
onCreate-Called when the document is created.
onUpdate-Called when the document is updated.
onSelectionUpdate-Called when the document selection is updated.
onTransaction-Called during document transactions.
onFocus-Called when the document gains focus.
onBlur-Called when the document loses focus.
onDestroy-Called when the document is destroyed.
onContentError{ error }Called when there's a content error.
onTrackedChangesUpdate-Called when tracked changes are updated.
onCommentsUpdate-Called when comments are updated.
onCommentsLoaded-Called when comments have finished loading.
onCommentClicked-Called when a comment is clicked.
onCommentLocationsUpdate-Called when the locations of comments are updated.
onDocumentLocked-Called when the document lock state changes.
onFirstRender-Called on the first render of the document.
onCollaborationReady-Called when collaboration features are ready.
onPaginationUpdate-Called when pagination is updated.
onException-Called when an exception occurs.

Example: Basic Editor Commands

You can get a list of currently available commands from editor.commands

Next Steps

  • See Integration for framework-specific integration guides
  • Check out Resources for examples, FAQ, and community resources
  • Learn more about Getting Started for basic concepts and setup

SuperDoc Toolbar

The SuperDoc will render into a DOM element of your choosing, allowing for full control of placement and styling over the toolbar. By default, we render a toolbar with all available buttons. You can customize this further by adding a toolbar object to the modules config in the SuperDoc configuration object.

Customization

You can customize the toolbar configuration via the SuperDoc config object.

const config = {
  // ... your SuperDoc config
  modules: {
    toolbar: {
      selector: 'superdoc-toolbar', // The ID of the DOM element you want to render the toolbar into

      toolbarGroups: ['left', 'center', 'right'],

      // Optional: Specify what toolbar buttons to render. Overrides toolbarGroups.
      groups: {
        center: ['bold', 'italic'],
      },

      // Optional: Instead of specifying all the buttons you want, specify which ones to exclude
      excludeItems: ['bold', italic'], // Will exclude these from the standard toolbar

    }
  }
}

Default toolbar buttons

See all buttons in defaultItems.js

© 2025 Harbour Enterprises, Inc. 💙💛