@ckeditor/ckeditor5-watchdog 44.3.0-alpha.7 → 45.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/contextwatchdog.js +32 -22
- package/src/editorwatchdog.js +44 -20
- package/src/watchdog.js +43 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-watchdog",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "45.0.0-alpha.0",
|
|
4
4
|
"description": "A watchdog feature for CKEditor 5 editors. It keeps a CKEditor 5 editor instance running.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-core": "
|
|
16
|
-
"@ckeditor/ckeditor5-editor-multi-root": "
|
|
17
|
-
"@ckeditor/ckeditor5-engine": "
|
|
18
|
-
"@ckeditor/ckeditor5-utils": "
|
|
19
|
-
"
|
|
15
|
+
"@ckeditor/ckeditor5-core": "45.0.0-alpha.0",
|
|
16
|
+
"@ckeditor/ckeditor5-editor-multi-root": "45.0.0-alpha.0",
|
|
17
|
+
"@ckeditor/ckeditor5-engine": "45.0.0-alpha.0",
|
|
18
|
+
"@ckeditor/ckeditor5-utils": "45.0.0-alpha.0",
|
|
19
|
+
"es-toolkit": "1.32.0"
|
|
20
20
|
},
|
|
21
21
|
"author": "CKSource (http://cksource.com/)",
|
|
22
22
|
"license": "SEE LICENSE IN LICENSE.md",
|
package/src/contextwatchdog.js
CHANGED
|
@@ -18,6 +18,35 @@ const mainQueueId = Symbol('MainQueueId');
|
|
|
18
18
|
* how to use it.
|
|
19
19
|
*/
|
|
20
20
|
export default class ContextWatchdog extends Watchdog {
|
|
21
|
+
/**
|
|
22
|
+
* A map of internal watchdogs for added items.
|
|
23
|
+
*/
|
|
24
|
+
_watchdogs = new Map();
|
|
25
|
+
/**
|
|
26
|
+
* The watchdog configuration.
|
|
27
|
+
*/
|
|
28
|
+
_watchdogConfig;
|
|
29
|
+
/**
|
|
30
|
+
* The current context instance.
|
|
31
|
+
*/
|
|
32
|
+
_context = null;
|
|
33
|
+
/**
|
|
34
|
+
* Context properties (nodes/references) that are gathered during the initial context creation
|
|
35
|
+
* and are used to distinguish the origin of an error.
|
|
36
|
+
*/
|
|
37
|
+
_contextProps = new Set();
|
|
38
|
+
/**
|
|
39
|
+
* An action queue, which is used to handle async functions queuing.
|
|
40
|
+
*/
|
|
41
|
+
_actionQueues = new ActionQueues();
|
|
42
|
+
/**
|
|
43
|
+
* The configuration for the {@link module:core/context~Context}.
|
|
44
|
+
*/
|
|
45
|
+
_contextConfig;
|
|
46
|
+
/**
|
|
47
|
+
* The watched item.
|
|
48
|
+
*/
|
|
49
|
+
_item;
|
|
21
50
|
/**
|
|
22
51
|
* The context watchdog class constructor.
|
|
23
52
|
*
|
|
@@ -36,23 +65,6 @@ export default class ContextWatchdog extends Watchdog {
|
|
|
36
65
|
*/
|
|
37
66
|
constructor(Context, watchdogConfig = {}) {
|
|
38
67
|
super(watchdogConfig);
|
|
39
|
-
/**
|
|
40
|
-
* A map of internal watchdogs for added items.
|
|
41
|
-
*/
|
|
42
|
-
this._watchdogs = new Map();
|
|
43
|
-
/**
|
|
44
|
-
* The current context instance.
|
|
45
|
-
*/
|
|
46
|
-
this._context = null;
|
|
47
|
-
/**
|
|
48
|
-
* Context properties (nodes/references) that are gathered during the initial context creation
|
|
49
|
-
* and are used to distinguish the origin of an error.
|
|
50
|
-
*/
|
|
51
|
-
this._contextProps = new Set();
|
|
52
|
-
/**
|
|
53
|
-
* An action queue, which is used to handle async functions queuing.
|
|
54
|
-
*/
|
|
55
|
-
this._actionQueues = new ActionQueues();
|
|
56
68
|
this._watchdogConfig = watchdogConfig;
|
|
57
69
|
// Default creator and destructor.
|
|
58
70
|
this._creator = contextConfig => Context.create(contextConfig);
|
|
@@ -360,11 +372,9 @@ export default class ContextWatchdog extends Watchdog {
|
|
|
360
372
|
* Manager of action queues that allows queuing async functions.
|
|
361
373
|
*/
|
|
362
374
|
class ActionQueues {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this._activeActions = 0;
|
|
367
|
-
}
|
|
375
|
+
_onEmptyCallbacks = [];
|
|
376
|
+
_queues = new Map();
|
|
377
|
+
_activeActions = 0;
|
|
368
378
|
/**
|
|
369
379
|
* Used to register callbacks that will be run when the queue becomes empty.
|
|
370
380
|
*
|
package/src/editorwatchdog.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module watchdog/editorwatchdog
|
|
7
7
|
*/
|
|
8
8
|
/* globals console */
|
|
9
|
-
import { throttle, cloneDeepWith, isElement } from '
|
|
9
|
+
import { throttle, cloneDeepWith, isElement } from 'es-toolkit/compat';
|
|
10
10
|
import areConnectedThroughProperties from './utils/areconnectedthroughproperties.js';
|
|
11
11
|
import Watchdog from './watchdog.js';
|
|
12
12
|
/**
|
|
@@ -16,31 +16,53 @@ import Watchdog from './watchdog.js';
|
|
|
16
16
|
* how to use it.
|
|
17
17
|
*/
|
|
18
18
|
export default class EditorWatchdog extends Watchdog {
|
|
19
|
+
/**
|
|
20
|
+
* The current editor instance.
|
|
21
|
+
*/
|
|
22
|
+
_editor = null;
|
|
23
|
+
/**
|
|
24
|
+
* A promise associated with the life cycle of the editor (creation or destruction processes).
|
|
25
|
+
*
|
|
26
|
+
* It is used to prevent the initialization of the editor if the previous instance has not been destroyed yet,
|
|
27
|
+
* and conversely, to prevent the destruction of the editor if it has not been initialized.
|
|
28
|
+
*/
|
|
29
|
+
_lifecyclePromise = null;
|
|
30
|
+
/**
|
|
31
|
+
* Throttled save method. The `save()` method is called the specified `saveInterval` after `throttledSave()` is called,
|
|
32
|
+
* unless a new action happens in the meantime.
|
|
33
|
+
*/
|
|
34
|
+
_throttledSave;
|
|
35
|
+
/**
|
|
36
|
+
* The latest saved editor data represented as a root name -> root data object.
|
|
37
|
+
*/
|
|
38
|
+
_data;
|
|
39
|
+
/**
|
|
40
|
+
* The last document version.
|
|
41
|
+
*/
|
|
42
|
+
_lastDocumentVersion;
|
|
43
|
+
/**
|
|
44
|
+
* The editor source element or data.
|
|
45
|
+
*/
|
|
46
|
+
_elementOrData;
|
|
47
|
+
/**
|
|
48
|
+
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
|
|
49
|
+
*/
|
|
50
|
+
_initUsingData = true;
|
|
51
|
+
/**
|
|
52
|
+
* The latest record of the editor editable elements. Used to restart the editor.
|
|
53
|
+
*/
|
|
54
|
+
_editables = {};
|
|
55
|
+
/**
|
|
56
|
+
* The editor configuration.
|
|
57
|
+
*/
|
|
58
|
+
_config;
|
|
59
|
+
_excludedProps;
|
|
19
60
|
/**
|
|
20
61
|
* @param Editor The editor class.
|
|
21
62
|
* @param watchdogConfig The watchdog plugin configuration.
|
|
22
63
|
*/
|
|
23
64
|
constructor(Editor, watchdogConfig = {}) {
|
|
24
65
|
super(watchdogConfig);
|
|
25
|
-
/**
|
|
26
|
-
* The current editor instance.
|
|
27
|
-
*/
|
|
28
|
-
this._editor = null;
|
|
29
|
-
/**
|
|
30
|
-
* A promise associated with the life cycle of the editor (creation or destruction processes).
|
|
31
|
-
*
|
|
32
|
-
* It is used to prevent the initialization of the editor if the previous instance has not been destroyed yet,
|
|
33
|
-
* and conversely, to prevent the destruction of the editor if it has not been initialized.
|
|
34
|
-
*/
|
|
35
|
-
this._lifecyclePromise = null;
|
|
36
|
-
/**
|
|
37
|
-
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
|
|
38
|
-
*/
|
|
39
|
-
this._initUsingData = true;
|
|
40
|
-
/**
|
|
41
|
-
* The latest record of the editor editable elements. Used to restart the editor.
|
|
42
|
-
*/
|
|
43
|
-
this._editables = {};
|
|
44
66
|
// this._editorClass = Editor;
|
|
45
67
|
this._throttledSave = throttle(this._save.bind(this), typeof watchdogConfig.saveInterval === 'number' ? watchdogConfig.saveInterval : 5000);
|
|
46
68
|
// Set default creator and destructor functions:
|
|
@@ -340,6 +362,8 @@ export default class EditorWatchdog extends Watchdog {
|
|
|
340
362
|
* based on the `editor.config._watchdogInitialData` data.
|
|
341
363
|
*/
|
|
342
364
|
class EditorWatchdogInitPlugin {
|
|
365
|
+
editor;
|
|
366
|
+
_data;
|
|
343
367
|
constructor(editor) {
|
|
344
368
|
this.editor = editor;
|
|
345
369
|
this._data = editor.config.get('_watchdogInitialData');
|
package/src/watchdog.js
CHANGED
|
@@ -10,37 +10,53 @@
|
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export default class Watchdog {
|
|
13
|
+
/**
|
|
14
|
+
* An array of crashes saved as an object with the following properties:
|
|
15
|
+
*
|
|
16
|
+
* * `message`: `String`,
|
|
17
|
+
* * `stack`: `String`,
|
|
18
|
+
* * `date`: `Number`,
|
|
19
|
+
* * `filename`: `String | undefined`,
|
|
20
|
+
* * `lineno`: `Number | undefined`,
|
|
21
|
+
* * `colno`: `Number | undefined`,
|
|
22
|
+
*/
|
|
23
|
+
crashes = [];
|
|
24
|
+
/**
|
|
25
|
+
* Specifies the state of the item watched by the watchdog. The state can be one of the following values:
|
|
26
|
+
*
|
|
27
|
+
* * `initializing` – Before the first initialization, and after crashes, before the item is ready.
|
|
28
|
+
* * `ready` – A state when the user can interact with the item.
|
|
29
|
+
* * `crashed` – A state when an error occurs. It quickly changes to `initializing` or `crashedPermanently`
|
|
30
|
+
* depending on how many and how frequent errors have been caught recently.
|
|
31
|
+
* * `crashedPermanently` – A state when the watchdog stops reacting to errors and keeps the item it is watching crashed,
|
|
32
|
+
* * `destroyed` – A state when the item is manually destroyed by the user after calling `watchdog.destroy()`.
|
|
33
|
+
*/
|
|
34
|
+
state = 'initializing';
|
|
35
|
+
/**
|
|
36
|
+
* @see module:watchdog/watchdog~WatchdogConfig
|
|
37
|
+
*/
|
|
38
|
+
_crashNumberLimit;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the result of the `Date.now()` call. It can be overridden in tests to mock time as some popular
|
|
41
|
+
* approaches like `sinon.useFakeTimers()` do not work well with error handling.
|
|
42
|
+
*/
|
|
43
|
+
_now = Date.now;
|
|
44
|
+
/**
|
|
45
|
+
* @see module:watchdog/watchdog~WatchdogConfig
|
|
46
|
+
*/
|
|
47
|
+
_minimumNonErrorTimePeriod;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if the event error comes from the underlying item and restarts the item.
|
|
50
|
+
*/
|
|
51
|
+
_boundErrorHandler;
|
|
52
|
+
/**
|
|
53
|
+
* A dictionary of event emitter listeners.
|
|
54
|
+
*/
|
|
55
|
+
_listeners;
|
|
13
56
|
/**
|
|
14
57
|
* @param {module:watchdog/watchdog~WatchdogConfig} config The watchdog plugin configuration.
|
|
15
58
|
*/
|
|
16
59
|
constructor(config) {
|
|
17
|
-
/**
|
|
18
|
-
* An array of crashes saved as an object with the following properties:
|
|
19
|
-
*
|
|
20
|
-
* * `message`: `String`,
|
|
21
|
-
* * `stack`: `String`,
|
|
22
|
-
* * `date`: `Number`,
|
|
23
|
-
* * `filename`: `String | undefined`,
|
|
24
|
-
* * `lineno`: `Number | undefined`,
|
|
25
|
-
* * `colno`: `Number | undefined`,
|
|
26
|
-
*/
|
|
27
|
-
this.crashes = [];
|
|
28
|
-
/**
|
|
29
|
-
* Specifies the state of the item watched by the watchdog. The state can be one of the following values:
|
|
30
|
-
*
|
|
31
|
-
* * `initializing` – Before the first initialization, and after crashes, before the item is ready.
|
|
32
|
-
* * `ready` – A state when the user can interact with the item.
|
|
33
|
-
* * `crashed` – A state when an error occurs. It quickly changes to `initializing` or `crashedPermanently`
|
|
34
|
-
* depending on how many and how frequent errors have been caught recently.
|
|
35
|
-
* * `crashedPermanently` – A state when the watchdog stops reacting to errors and keeps the item it is watching crashed,
|
|
36
|
-
* * `destroyed` – A state when the item is manually destroyed by the user after calling `watchdog.destroy()`.
|
|
37
|
-
*/
|
|
38
|
-
this.state = 'initializing';
|
|
39
|
-
/**
|
|
40
|
-
* Returns the result of the `Date.now()` call. It can be overridden in tests to mock time as some popular
|
|
41
|
-
* approaches like `sinon.useFakeTimers()` do not work well with error handling.
|
|
42
|
-
*/
|
|
43
|
-
this._now = Date.now;
|
|
44
60
|
this.crashes = [];
|
|
45
61
|
this._crashNumberLimit = typeof config.crashNumberLimit === 'number' ? config.crashNumberLimit : 3;
|
|
46
62
|
this._minimumNonErrorTimePeriod = typeof config.minimumNonErrorTimePeriod === 'number' ? config.minimumNonErrorTimePeriod : 5000;
|