Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckeditor/ckeditor5-watchdog

Package Overview
Dependencies
Maintainers
1
Versions
767
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-watchdog - npm Package Compare versions

Comparing version 0.0.0-nightly-20241219.0 to 0.0.0-nightly-20241219.1

699

dist/index.js

@@ -11,2 +11,5 @@ /**

*/ /**
* @module watchdog/watchdog
*/ /* globals window */ // eslint-disable-next-line ckeditor5-rules/no-cross-package-imports
/**
* An abstract watchdog class that handles most of the error handling process and the state of the underlying component.

@@ -19,28 +22,40 @@ *

/**
* @param {module:watchdog/watchdog~WatchdogConfig} config The watchdog plugin configuration.
*/ constructor(config){
/**
* 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`,
*/ this.crashes = [];
/**
* 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()`.
*/ this.state = 'initializing';
/**
* Returns the result of the `Date.now()` call. It can be overridden in tests to mock time as some popular
* approaches like `sinon.useFakeTimers()` do not work well with error handling.
*/ this._now = Date.now;
* 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`,
*/ crashes = [];
/**
* 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()`.
*/ state = 'initializing';
/**
* @see module:watchdog/watchdog~WatchdogConfig
*/ _crashNumberLimit;
/**
* Returns the result of the `Date.now()` call. It can be overridden in tests to mock time as some popular
* approaches like `sinon.useFakeTimers()` do not work well with error handling.
*/ _now = Date.now;
/**
* @see module:watchdog/watchdog~WatchdogConfig
*/ _minimumNonErrorTimePeriod;
/**
* Checks if the event error comes from the underlying item and restarts the item.
*/ _boundErrorHandler;
/**
* A dictionary of event emitter listeners.
*/ _listeners;
/**
* @param {module:watchdog/watchdog~WatchdogConfig} config The watchdog plugin configuration.
*/ constructor(config){
this.crashes = [];

@@ -64,4 +79,4 @@ this._crashNumberLimit = typeof config.crashNumberLimit === 'number' ? config.crashNumberLimit : 3;

/**
* Destroys the watchdog and releases the resources.
*/ destroy() {
* Destroys the watchdog and releases the resources.
*/ destroy() {
this._stopErrorHandling();

@@ -71,10 +86,10 @@ this._listeners = {};

/**
* 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.
*
* @param eventName The event name.
* @param callback A callback which will be added to event listeners.
*/ on(eventName, callback) {
* 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.
*
* @param eventName The event name.
* @param callback A callback which will be added to event listeners.
*/ on(eventName, callback) {
if (!this._listeners[eventName]) {

@@ -86,16 +101,16 @@ this._listeners[eventName] = [];

/**
* 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.
*
* @param eventName The event name.
* @param callback A callback which will be removed from event listeners.
*/ off(eventName, callback) {
* 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.
*
* @param eventName The event name.
* @param callback A callback which will be removed from event listeners.
*/ off(eventName, callback) {
this._listeners[eventName] = this._listeners[eventName].filter((cb)=>cb !== callback);
}
/**
* Fires an event with a given event name and arguments.
*
* Note that this method differs from the CKEditor 5's default `EventEmitterMixin` implementation.
*/ _fire(eventName, ...args) {
* Fires an event with a given event name and arguments.
*
* Note that this method differs from the CKEditor 5's default `EventEmitterMixin` implementation.
*/ _fire(eventName, ...args) {
const callbacks = this._listeners[eventName] || [];

@@ -110,4 +125,4 @@ for (const callback of callbacks){

/**
* Starts error handling by attaching global error handlers.
*/ _startErrorHandling() {
* Starts error handling by attaching global error handlers.
*/ _startErrorHandling() {
window.addEventListener('error', this._boundErrorHandler);

@@ -117,4 +132,4 @@ window.addEventListener('unhandledrejection', this._boundErrorHandler);

/**
* Stops error handling by detaching global error handlers.
*/ _stopErrorHandling() {
* Stops error handling by detaching global error handlers.
*/ _stopErrorHandling() {
window.removeEventListener('error', this._boundErrorHandler);

@@ -124,9 +139,9 @@ window.removeEventListener('unhandledrejection', this._boundErrorHandler);

/**
* Checks if an error comes from the watched item and restarts it.
* It reacts to {@link module:utils/ckeditorerror~CKEditorError `CKEditorError` errors} only.
*
* @fires error
* @param error Error.
* @param evt An error event.
*/ _handleError(error, evt) {
* Checks if an error comes from the watched item and restarts it.
* It reacts to {@link module:utils/ckeditorerror~CKEditorError `CKEditorError` errors} only.
*
* @fires error
* @param error Error.
* @param evt An error event.
*/ _handleError(error, evt) {
// @if CK_DEBUG // const err = error as CKEditorError;

@@ -162,6 +177,6 @@ // @if CK_DEBUG // if ( err.is && err.is( 'CKEditorError' ) && err.context === undefined ) {

/**
* Checks whether an error should be handled by the watchdog.
*
* @param error An error that was caught by the error handling process.
*/ _shouldReactToError(error) {
* Checks whether an error should be handled by the watchdog.
*
* @param error An error that was caught by the error handling process.
*/ _shouldReactToError(error) {
return error.is && error.is('CKEditorError') && error.context !== undefined && // In some cases the watched item should not be restarted - e.g. during the item initialization.

@@ -173,4 +188,4 @@ // That's why the `null` was introduced as a correct error context which does cause restarting.

/**
* Checks if the watchdog should restart the underlying item.
*/ _shouldRestart() {
* Checks if the watchdog should restart the underlying item.
*/ _shouldRestart() {
if (this.crashes.length <= this._crashNumberLimit) {

@@ -271,2 +286,8 @@ return true;

/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/ /**
* @module watchdog/editorwatchdog
*/ /* globals console */ // eslint-disable-next-line ckeditor5-rules/no-cross-package-imports
/**
* A watchdog for CKEditor 5 editors.

@@ -278,21 +299,38 @@ *

/**
* @param Editor The editor class.
* @param watchdogConfig The watchdog plugin configuration.
*/ constructor(Editor, watchdogConfig = {}){
* The current editor instance.
*/ _editor = null;
/**
* A promise associated with the life cycle of the editor (creation or destruction processes).
*
* It is used to prevent the initialization of the editor if the previous instance has not been destroyed yet,
* and conversely, to prevent the destruction of the editor if it has not been initialized.
*/ _lifecyclePromise = null;
/**
* Throttled save method. The `save()` method is called the specified `saveInterval` after `throttledSave()` is called,
* unless a new action happens in the meantime.
*/ _throttledSave;
/**
* The latest saved editor data represented as a root name -> root data object.
*/ _data;
/**
* The last document version.
*/ _lastDocumentVersion;
/**
* The editor source element or data.
*/ _elementOrData;
/**
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
*/ _initUsingData = true;
/**
* The latest record of the editor editable elements. Used to restart the editor.
*/ _editables = {};
/**
* The editor configuration.
*/ _config;
_excludedProps;
/**
* @param Editor The editor class.
* @param watchdogConfig The watchdog plugin configuration.
*/ constructor(Editor, watchdogConfig = {}){
super(watchdogConfig);
/**
* The current editor instance.
*/ this._editor = null;
/**
* A promise associated with the life cycle of the editor (creation or destruction processes).
*
* It is used to prevent the initialization of the editor if the previous instance has not been destroyed yet,
* and conversely, to prevent the destruction of the editor if it has not been initialized.
*/ this._lifecyclePromise = null;
/**
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
*/ this._initUsingData = true;
/**
* The latest record of the editor editable elements. Used to restart the editor.
*/ this._editables = {};
// this._editorClass = Editor;

@@ -307,46 +345,46 @@ this._throttledSave = throttle(this._save.bind(this), typeof watchdogConfig.saveInterval === 'number' ? watchdogConfig.saveInterval : 5000);

/**
* The current editor instance.
*/ get editor() {
* The current editor instance.
*/ get editor() {
return this._editor;
}
/**
* @internal
*/ get _item() {
* @internal
*/ get _item() {
return this._editor;
}
/**
* Sets the function that is responsible for the editor creation.
* It expects a function that should return a promise.
*
* ```ts
* watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
* ```
*/ setCreator(creator) {
* Sets the function that is responsible for the editor creation.
* It expects a function that should return a promise.
*
* ```ts
* watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
* ```
*/ setCreator(creator) {
this._creator = creator;
}
/**
* 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`.
*
* ```ts
* watchdog.setDestructor( editor => {
* // Do something before the editor is destroyed.
*
* return editor
* .destroy()
* .then( () => {
* // Do something after the editor is destroyed.
* } );
* } );
* ```
*/ setDestructor(destructor) {
* 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`.
*
* ```ts
* watchdog.setDestructor( editor => {
* // Do something before the editor is destroyed.
*
* return editor
* .destroy()
* .then( () => {
* // Do something after the editor is destroyed.
* } );
* } );
* ```
*/ setDestructor(destructor) {
this._destructor = destructor;
}
/**
* Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
* the state to `initializing`.
*
* @fires restart
*/ _restart() {
* Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
* the state to `initializing`.
*
* @fires restart
*/ _restart() {
return Promise.resolve().then(()=>{

@@ -412,8 +450,8 @@ this.state = 'initializing';

/**
* Creates the editor instance and keeps it running, using the defined creator and destructor.
*
* @param elementOrData The editor source element or the editor data.
* @param config The editor configuration.
* @param context A context for the editor.
*/ create(elementOrData = this._elementOrData, config = this._config, context) {
* Creates the editor instance and keeps it running, using the defined creator and destructor.
*
* @param elementOrData The editor source element or the editor data.
* @param config The editor configuration.
* @param context A context for the editor.
*/ create(elementOrData = this._elementOrData, config = this._config, context) {
this._lifecyclePromise = Promise.resolve(this._lifecyclePromise).then(()=>{

@@ -446,6 +484,6 @@ super._startErrorHandling();

/**
* Destroys the watchdog and the current editor instance. It fires the callback
* registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
* It also sets the state to `destroyed`.
*/ destroy() {
* Destroys the watchdog and the current editor instance. It fires the callback
* registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
* It also sets the state to `destroyed`.
*/ destroy() {
this._lifecyclePromise = Promise.resolve(this._lifecyclePromise).then(()=>{

@@ -475,5 +513,5 @@ this.state = 'destroyed';

/**
* Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
* the moment of the crash.
*/ _save() {
* Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
* the moment of the crash.
*/ _save() {
const version = this._editor.model.document.version;

@@ -491,9 +529,9 @@ try {

/**
* @internal
*/ _setExcludedProperties(props) {
* @internal
*/ _setExcludedProperties(props) {
this._excludedProps = props;
}
/**
* Gets all data that is required to reinitialize editor instance.
*/ _getData() {
* Gets all data that is required to reinitialize editor instance.
*/ _getData() {
const editor = this._editor;

@@ -543,4 +581,4 @@ const roots = editor.model.document.roots.filter((root)=>root.isAttached() && root.rootName != '$graveyard');

/**
* For each attached model root, returns its HTML editable element (if available).
*/ _getEditables() {
* For each attached model root, returns its HTML editable element (if available).
*/ _getEditables() {
const editables = {};

@@ -556,12 +594,12 @@ for (const rootName of this.editor.model.document.getRootNames()){

/**
* Traverses the error context and the current editor to find out whether these structures are connected
* to each other via properties.
*
* @internal
*/ _isErrorComingFromThisItem(error) {
* Traverses the error context and the current editor to find out whether these structures are connected
* to each other via properties.
*
* @internal
*/ _isErrorComingFromThisItem(error) {
return areConnectedThroughProperties(this._editor, error.context, this._excludedProps);
}
/**
* Clones the editor configuration.
*/ _cloneEditorConfiguration(config) {
* Clones the editor configuration.
*/ _cloneEditorConfiguration(config) {
return cloneDeepWith(config, (value, key)=>{

@@ -582,2 +620,4 @@ // Leave DOM references.

*/ class EditorWatchdogInitPlugin {
editor;
_data;
constructor(editor){

@@ -588,4 +628,4 @@ this.editor = editor;

/**
* @inheritDoc
*/ init() {
* @inheritDoc
*/ init() {
// Stops the default editor initialization and use the saved data to restore the editor state.

@@ -609,4 +649,4 @@ // Some of data could not be initialize as a config properties. It is important to keep the data

/**
* Creates a model node (element or text) based on provided JSON.
*/ _createNode(writer, jsonNode) {
* Creates a model node (element or text) based on provided JSON.
*/ _createNode(writer, jsonNode) {
if ('name' in jsonNode) {

@@ -627,4 +667,4 @@ // If child has name property, it is an Element.

/**
* Restores the editor by setting the document data, roots attributes and markers.
*/ _restoreEditorData(writer) {
* Restores the editor by setting the document data, roots attributes and markers.
*/ _restoreEditorData(writer) {
const editor = this.editor;

@@ -657,4 +697,4 @@ Object.entries(this._data.roots).forEach(([rootName, { content, attributes }])=>{

/**
* Restores the editor collaboration data - comment threads and suggestions.
*/ _restoreCollaborationData() {
* Restores the editor collaboration data - comment threads and suggestions.
*/ _restoreCollaborationData() {
// `as any` to avoid linking from external private repo.

@@ -687,2 +727,8 @@ const parsedCommentThreads = JSON.parse(this._data.commentThreads);

/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/ /**
* @module watchdog/contextwatchdog
*/ /* globals console */ // eslint-disable-next-line ckeditor5-rules/no-cross-package-imports
const mainQueueId = Symbol('MainQueueId');

@@ -696,31 +742,40 @@ /**

/**
* The context watchdog class constructor.
*
* ```ts
* const watchdog = new ContextWatchdog( Context );
*
* await watchdog.create( contextConfiguration );
*
* await watchdog.add( item );
* ```
*
* See the {@glink features/watchdog Watchdog feature guide} to learn more how to use this feature.
*
* @param Context The {@link module:core/context~Context} class.
* @param watchdogConfig The watchdog configuration.
*/ constructor(Context, watchdogConfig = {}){
* A map of internal watchdogs for added items.
*/ _watchdogs = new Map();
/**
* The watchdog configuration.
*/ _watchdogConfig;
/**
* The current context instance.
*/ _context = null;
/**
* Context properties (nodes/references) that are gathered during the initial context creation
* and are used to distinguish the origin of an error.
*/ _contextProps = new Set();
/**
* An action queue, which is used to handle async functions queuing.
*/ _actionQueues = new ActionQueues();
/**
* The configuration for the {@link module:core/context~Context}.
*/ _contextConfig;
/**
* The watched item.
*/ _item;
/**
* The context watchdog class constructor.
*
* ```ts
* const watchdog = new ContextWatchdog( Context );
*
* await watchdog.create( contextConfiguration );
*
* await watchdog.add( item );
* ```
*
* See the {@glink features/watchdog Watchdog feature guide} to learn more how to use this feature.
*
* @param Context The {@link module:core/context~Context} class.
* @param watchdogConfig The watchdog configuration.
*/ constructor(Context, watchdogConfig = {}){
super(watchdogConfig);
/**
* A map of internal watchdogs for added items.
*/ this._watchdogs = new Map();
/**
* The current context instance.
*/ this._context = null;
/**
* Context properties (nodes/references) that are gathered during the initial context creation
* and are used to distinguish the origin of an error.
*/ this._contextProps = new Set();
/**
* An action queue, which is used to handle async functions queuing.
*/ this._actionQueues = new ActionQueues();
this._watchdogConfig = watchdogConfig;

@@ -738,48 +793,48 @@ // Default creator and destructor.

/**
* Sets the function that is responsible for the context creation.
* It expects a function that should return a promise (or `undefined`).
*
* ```ts
* watchdog.setCreator( config => Context.create( config ) );
* ```
*/ setCreator(creator) {
* Sets the function that is responsible for the context creation.
* It expects a function that should return a promise (or `undefined`).
*
* ```ts
* watchdog.setCreator( config => Context.create( config ) );
* ```
*/ setCreator(creator) {
this._creator = creator;
}
/**
* Sets the function that is responsible for the context destruction.
* Overrides the default destruction function, which destroys only the context instance.
* It expects a function that should return a promise (or `undefined`).
*
* ```ts
* watchdog.setDestructor( context => {
* // Do something before the context is destroyed.
*
* return context
* .destroy()
* .then( () => {
* // Do something after the context is destroyed.
* } );
* } );
* ```
*/ setDestructor(destructor) {
* Sets the function that is responsible for the context destruction.
* Overrides the default destruction function, which destroys only the context instance.
* It expects a function that should return a promise (or `undefined`).
*
* ```ts
* watchdog.setDestructor( context => {
* // Do something before the context is destroyed.
*
* return context
* .destroy()
* .then( () => {
* // Do something after the context is destroyed.
* } );
* } );
* ```
*/ setDestructor(destructor) {
this._destructor = destructor;
}
/**
* The context instance. Keep in mind that this property might be changed when the context watchdog restarts,
* so do not keep this instance internally. Always operate on the `ContextWatchdog#context` property.
*/ get context() {
* The context instance. Keep in mind that this property might be changed when the context watchdog restarts,
* so do not keep this instance internally. Always operate on the `ContextWatchdog#context` property.
*/ get context() {
return this._context;
}
/**
* Initializes the context watchdog. Once it is created, the watchdog takes care about
* recreating the context and the provided items, and starts the error handling mechanism.
*
* ```ts
* await watchdog.create( {
* plugins: []
* } );
* ```
*
* @param contextConfig The context configuration. See {@link module:core/context~Context}.
*/ create(contextConfig = {}) {
* Initializes the context watchdog. Once it is created, the watchdog takes care about
* recreating the context and the provided items, and starts the error handling mechanism.
*
* ```ts
* await watchdog.create( {
* plugins: []
* } );
* ```
*
* @param contextConfig The context configuration. See {@link module:core/context~Context}.
*/ create(contextConfig = {}) {
return this._actionQueues.enqueue(mainQueueId, ()=>{

@@ -791,11 +846,11 @@ this._contextConfig = contextConfig;

/**
* Returns an item instance with the given `itemId`.
*
* ```ts
* const editor1 = watchdog.getItem( 'editor1' );
* ```
*
* @param itemId The item ID.
* @returns The item instance or `undefined` if an item with a given ID has not been found.
*/ getItem(itemId) {
* Returns an item instance with the given `itemId`.
*
* ```ts
* const editor1 = watchdog.getItem( 'editor1' );
* ```
*
* @param itemId The item ID.
* @returns The item instance or `undefined` if an item with a given ID has not been found.
*/ getItem(itemId) {
const watchdog = this._getWatchdog(itemId);

@@ -805,11 +860,11 @@ return watchdog._item;

/**
* Gets the state of the given item. See {@link #state} for a list of available states.
*
* ```ts
* const editor1State = watchdog.getItemState( 'editor1' );
* ```
*
* @param itemId Item ID.
* @returns The state of the item.
*/ getItemState(itemId) {
* Gets the state of the given item. See {@link #state} for a list of available states.
*
* ```ts
* const editor1State = watchdog.getItemState( 'editor1' );
* ```
*
* @param itemId Item ID.
* @returns The state of the item.
*/ getItemState(itemId) {
const watchdog = this._getWatchdog(itemId);

@@ -819,45 +874,45 @@ return watchdog.state;

/**
* Adds items to the watchdog. Once created, instances of these items will be available using the {@link #getItem} method.
*
* Items can be passed together as an array of objects:
*
* ```ts
* await watchdog.add( [ {
* id: 'editor1',
* type: 'editor',
* sourceElementOrData: document.querySelector( '#editor' ),
* config: {
* plugins: [ Essentials, Paragraph, Bold, Italic ],
* toolbar: [ 'bold', 'italic', 'alignment' ]
* },
* creator: ( element, config ) => ClassicEditor.create( element, config )
* } ] );
* ```
*
* Or one by one as objects:
*
* ```ts
* await watchdog.add( {
* id: 'editor1',
* type: 'editor',
* sourceElementOrData: document.querySelector( '#editor' ),
* config: {
* plugins: [ Essentials, Paragraph, Bold, Italic ],
* toolbar: [ 'bold', 'italic', 'alignment' ]
* },
* creator: ( element, config ) => ClassicEditor.create( element, config )
* ] );
* ```
*
* Then an instance can be retrieved using the {@link #getItem} method:
*
* ```ts
* const editor1 = watchdog.getItem( 'editor1' );
* ```
*
* Note that this method can be called multiple times, but for performance reasons it is better
* to pass all items together.
*
* @param itemConfigurationOrItemConfigurations An item configuration object or an array of item configurations.
*/ add(itemConfigurationOrItemConfigurations) {
* Adds items to the watchdog. Once created, instances of these items will be available using the {@link #getItem} method.
*
* Items can be passed together as an array of objects:
*
* ```ts
* await watchdog.add( [ {
* id: 'editor1',
* type: 'editor',
* sourceElementOrData: document.querySelector( '#editor' ),
* config: {
* plugins: [ Essentials, Paragraph, Bold, Italic ],
* toolbar: [ 'bold', 'italic', 'alignment' ]
* },
* creator: ( element, config ) => ClassicEditor.create( element, config )
* } ] );
* ```
*
* Or one by one as objects:
*
* ```ts
* await watchdog.add( {
* id: 'editor1',
* type: 'editor',
* sourceElementOrData: document.querySelector( '#editor' ),
* config: {
* plugins: [ Essentials, Paragraph, Bold, Italic ],
* toolbar: [ 'bold', 'italic', 'alignment' ]
* },
* creator: ( element, config ) => ClassicEditor.create( element, config )
* ] );
* ```
*
* Then an instance can be retrieved using the {@link #getItem} method:
*
* ```ts
* const editor1 = watchdog.getItem( 'editor1' );
* ```
*
* Note that this method can be called multiple times, but for performance reasons it is better
* to pass all items together.
*
* @param itemConfigurationOrItemConfigurations An item configuration object or an array of item configurations.
*/ add(itemConfigurationOrItemConfigurations) {
const itemConfigurations = toArray(itemConfigurationOrItemConfigurations);

@@ -914,16 +969,16 @@ return Promise.all(itemConfigurations.map((item)=>{

/**
* Removes and destroys item(s) with given ID(s).
*
* ```ts
* await watchdog.remove( 'editor1' );
* ```
*
* Or
*
* ```ts
* await watchdog.remove( [ 'editor1', 'editor2' ] );
* ```
*
* @param itemIdOrItemIds Item ID or an array of item IDs.
*/ remove(itemIdOrItemIds) {
* Removes and destroys item(s) with given ID(s).
*
* ```ts
* await watchdog.remove( 'editor1' );
* ```
*
* Or
*
* ```ts
* await watchdog.remove( [ 'editor1', 'editor2' ] );
* ```
*
* @param itemIdOrItemIds Item ID or an array of item IDs.
*/ remove(itemIdOrItemIds) {
const itemIds = toArray(itemIdOrItemIds);

@@ -939,9 +994,9 @@ return Promise.all(itemIds.map((itemId)=>{

/**
* Destroys the context watchdog and all added items.
* Once the context watchdog is destroyed, new items cannot be added.
*
* ```ts
* await watchdog.destroy();
* ```
*/ destroy() {
* Destroys the context watchdog and all added items.
* Once the context watchdog is destroyed, new items cannot be added.
*
* ```ts
* await watchdog.destroy();
* ```
*/ destroy() {
return this._actionQueues.enqueue(mainQueueId, ()=>{

@@ -955,4 +1010,4 @@ this.state = 'destroyed';

/**
* Restarts the context watchdog.
*/ _restart() {
* Restarts the context watchdog.
*/ _restart() {
return this._actionQueues.enqueue(mainQueueId, ()=>{

@@ -967,4 +1022,4 @@ this.state = 'initializing';

/**
* Initializes the context watchdog.
*/ _create() {
* Initializes the context watchdog.
*/ _create() {
return Promise.resolve().then(()=>{

@@ -983,4 +1038,4 @@ this._startErrorHandling();

/**
* Destroys the context instance and all added items.
*/ _destroy() {
* Destroys the context instance and all added items.
*/ _destroy() {
return Promise.resolve().then(()=>{

@@ -996,6 +1051,6 @@ this._stopErrorHandling();

/**
* Returns the watchdog for a given item ID.
*
* @param itemId Item ID.
*/ _getWatchdog(itemId) {
* Returns the watchdog for a given item ID.
*
* @param itemId Item ID.
*/ _getWatchdog(itemId) {
const watchdog = this._watchdogs.get(itemId);

@@ -1008,6 +1063,6 @@ if (!watchdog) {

/**
* Checks whether an error comes from the context instance and not from the item instances.
*
* @internal
*/ _isErrorComingFromThisItem(error) {
* Checks whether an error comes from the context instance and not from the item instances.
*
* @internal
*/ _isErrorComingFromThisItem(error) {
for (const watchdog of this._watchdogs.values()){

@@ -1024,20 +1079,18 @@ if (watchdog._isErrorComingFromThisItem(error)) {

*/ class ActionQueues {
constructor(){
this._onEmptyCallbacks = [];
this._queues = new Map();
this._activeActions = 0;
}
_onEmptyCallbacks = [];
_queues = new Map();
_activeActions = 0;
/**
* Used to register callbacks that will be run when the queue becomes empty.
*
* @param onEmptyCallback A callback that will be run whenever the queue becomes empty.
*/ onEmpty(onEmptyCallback) {
* Used to register callbacks that will be run when the queue becomes empty.
*
* @param onEmptyCallback A callback that will be run whenever the queue becomes empty.
*/ onEmpty(onEmptyCallback) {
this._onEmptyCallbacks.push(onEmptyCallback);
}
/**
* It adds asynchronous actions (functions) to the proper queue and runs them one by one.
*
* @param queueId The action queue ID.
* @param action A function that should be enqueued.
*/ enqueue(queueId, action) {
* It adds asynchronous actions (functions) to the proper queue and runs them one by one.
*
* @param queueId The action queue ID.
* @param action A function that should be enqueued.
*/ enqueue(queueId, action) {
const isMainAction = queueId === mainQueueId;

@@ -1044,0 +1097,0 @@ this._activeActions++;

{
"name": "@ckeditor/ckeditor5-watchdog",
"version": "0.0.0-nightly-20241219.0",
"version": "0.0.0-nightly-20241219.1",
"description": "A watchdog feature for CKEditor 5 editors. It keeps a CKEditor 5 editor instance running.",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc