Trilium Frontend API
    Preparing search index...

    Class EditorWatchdog<TEditor>

    A watchdog for CKEditor 5 editors.

    See the {@glink features/watchdog Watchdog feature guide} to learn the rationale behind it and how to use it.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    The creation method.

    #setCreator

    _destructor: (editor: Editor) => Promise<unknown>

    The destruction method.

    #setDestructor

    crashes: {
        colno?: number;
        date: number;
        filename?: string;
        lineno?: number;
        message: string;
        stack?: string;
    }[]

    An array of crashes saved as an object with the following properties:

    • message: String,
    • stack: String,
    • date: Number,
    • filename: String | undefined,
    • lineno: Number | undefined,
    • colno: Number | undefined,

    Specifies the state of the item watched by the watchdog. The state can be one of the following values:

    • initializing – Before the first initialization, and after crashes, before the item is ready.
    • ready – A state when the user can interact with the item.
    • crashed – A state when an error occurs. It quickly changes to initializing or crashedPermanently depending on how many and how frequent errors have been caught recently.
    • crashedPermanently – A state when the watchdog stops reacting to errors and keeps the item it is watching crashed,
    • destroyed – A state when the item is manually destroyed by the user after calling watchdog.destroy().

    Accessors

    • get _item(): TEditor
      Internal

      Returns TEditor

    • get editor(): TEditor

      The current editor instance.

      Returns TEditor

    Methods

    • Fires an event with a given event name and arguments.

      Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.

      Type Parameters

      Parameters

      Returns void

    • Internal

      Traverses the error context and the current editor to find out whether these structures are connected to each other via properties.

      Parameters

      Returns boolean

    • Restarts the editor instance. This method is called whenever an editor error occurs. It fires the restart event and changes the state to initializing.

      Returns Promise<unknown>

      restart

    • Internal

      Parameters

      • props: Set<unknown>

      Returns void

    • Starts error handling by attaching global error handlers.

      Returns void

    • Stops error handling by detaching global error handlers.

      Returns void

    • Creates the editor instance and keeps it running, using the defined creator and destructor.

      Parameters

      • OptionalelementOrData: string | Record<string, string> | HTMLElement | Record<string, HTMLElement>

        The editor source element or the editor data.

      • Optionalconfig: EditorConfig

        The editor configuration.

      • Optionalcontext: Context

        A context for the editor.

      Returns Promise<unknown>

    • Destroys the watchdog and the current editor instance. It fires the callback registered in #setDestructor setDestructor() and uses it to destroy the editor instance. It also sets the state to destroyed.

      Returns Promise<unknown>

    • Stops listening to the specified event name by removing the callback from event listeners.

      Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.

      Parameters

      • eventName: keyof WatchdogEventMap

        The event name.

      • callback: unknown

        A callback which will be removed from event listeners.

      Returns void

    • Starts listening to a specific event name by registering a callback that will be executed whenever an event with a given name fires.

      Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.

      Type Parameters

      Parameters

      Returns void

    • Sets the function that is responsible for the editor creation. It expects a function that should return a promise.

      watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
      

      Returns void

    • Sets the function that is responsible for the editor destruction. Overrides the default destruction function, which destroys only the editor instance. It expects a function that should return a promise or undefined.

      watchdog.setDestructor( editor => {
      // Do something before the editor is destroyed.

      return editor
      .destroy()
      .then( () => {
      // Do something after the editor is destroyed.
      } );
      } );

      Parameters

      • destructor: (editor: Editor) => Promise<unknown>

      Returns void