@ckeditor/ckeditor5-watchdog 40.0.0 → 40.2.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/CHANGELOG.md +8 -8
- package/LICENSE.md +3 -3
- package/package.json +1 -1
- package/src/augmentation.d.ts +15 -15
- package/src/augmentation.js +5 -5
- package/src/contextwatchdog.d.ts +333 -333
- package/src/contextwatchdog.js +410 -410
- package/src/editorwatchdog.d.ts +184 -184
- package/src/editorwatchdog.js +423 -423
- package/src/index.d.ts +11 -11
- package/src/index.js +11 -11
- package/src/utils/areconnectedthroughproperties.d.ts +8 -8
- package/src/utils/areconnectedthroughproperties.js +58 -58
- package/src/utils/getsubnodes.d.ts +8 -8
- package/src/utils/getsubnodes.js +78 -78
- package/src/watchdog.d.ts +229 -229
- package/src/watchdog.js +185 -185
package/src/editorwatchdog.d.ts
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module watchdog/editorwatchdog
|
|
7
|
-
*/
|
|
8
|
-
import type { CKEditorError } from 'ckeditor5/src/utils';
|
|
9
|
-
import type { Editor, EditorConfig, Context } from 'ckeditor5/src/core';
|
|
10
|
-
import Watchdog, { type WatchdogConfig } from './watchdog';
|
|
11
|
-
/**
|
|
12
|
-
* A watchdog for CKEditor 5 editors.
|
|
13
|
-
*
|
|
14
|
-
* See the {@glink features/watchdog Watchdog feature guide} to learn the rationale behind it and
|
|
15
|
-
* how to use it.
|
|
16
|
-
*/
|
|
17
|
-
export default class EditorWatchdog<TEditor extends Editor = Editor> extends Watchdog {
|
|
18
|
-
/**
|
|
19
|
-
* The current editor instance.
|
|
20
|
-
*/
|
|
21
|
-
private _editor;
|
|
22
|
-
/**
|
|
23
|
-
* Throttled save method. The `save()` method is called the specified `saveInterval` after `throttledSave()` is called,
|
|
24
|
-
* unless a new action happens in the meantime.
|
|
25
|
-
*/
|
|
26
|
-
private _throttledSave;
|
|
27
|
-
/**
|
|
28
|
-
* The latest saved editor data represented as a root name -> root data object.
|
|
29
|
-
*/
|
|
30
|
-
private _data?;
|
|
31
|
-
/**
|
|
32
|
-
* The last document version.
|
|
33
|
-
*/
|
|
34
|
-
private _lastDocumentVersion?;
|
|
35
|
-
/**
|
|
36
|
-
* The editor source element or data.
|
|
37
|
-
*/
|
|
38
|
-
private _elementOrData?;
|
|
39
|
-
/**
|
|
40
|
-
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
|
|
41
|
-
*/
|
|
42
|
-
private _initUsingData;
|
|
43
|
-
/**
|
|
44
|
-
* The latest record of the editor editable elements. Used to restart the editor.
|
|
45
|
-
*/
|
|
46
|
-
private _editables;
|
|
47
|
-
/**
|
|
48
|
-
* The editor configuration.
|
|
49
|
-
*/
|
|
50
|
-
private _config?;
|
|
51
|
-
/**
|
|
52
|
-
* The creation method.
|
|
53
|
-
*
|
|
54
|
-
* @see #setCreator
|
|
55
|
-
*/
|
|
56
|
-
protected _creator: EditorCreatorFunction<TEditor>;
|
|
57
|
-
/**
|
|
58
|
-
* The destruction method.
|
|
59
|
-
*
|
|
60
|
-
* @see #setDestructor
|
|
61
|
-
*/
|
|
62
|
-
protected _destructor: (editor: Editor) => Promise<unknown>;
|
|
63
|
-
private _excludedProps?;
|
|
64
|
-
/**
|
|
65
|
-
* @param Editor The editor class.
|
|
66
|
-
* @param watchdogConfig The watchdog plugin configuration.
|
|
67
|
-
*/
|
|
68
|
-
constructor(Editor: {
|
|
69
|
-
create(...args: any): Promise<TEditor>;
|
|
70
|
-
} | null, watchdogConfig?: WatchdogConfig);
|
|
71
|
-
/**
|
|
72
|
-
* The current editor instance.
|
|
73
|
-
*/
|
|
74
|
-
get editor(): TEditor | null;
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
get _item(): TEditor | null;
|
|
79
|
-
/**
|
|
80
|
-
* Sets the function that is responsible for the editor creation.
|
|
81
|
-
* It expects a function that should return a promise.
|
|
82
|
-
*
|
|
83
|
-
* ```ts
|
|
84
|
-
* watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
setCreator(creator: EditorCreatorFunction<TEditor>): void;
|
|
88
|
-
/**
|
|
89
|
-
* Sets the function that is responsible for the editor destruction.
|
|
90
|
-
* Overrides the default destruction function, which destroys only the editor instance.
|
|
91
|
-
* It expects a function that should return a promise or `undefined`.
|
|
92
|
-
*
|
|
93
|
-
* ```ts
|
|
94
|
-
* watchdog.setDestructor( editor => {
|
|
95
|
-
* // Do something before the editor is destroyed.
|
|
96
|
-
*
|
|
97
|
-
* return editor
|
|
98
|
-
* .destroy()
|
|
99
|
-
* .then( () => {
|
|
100
|
-
* // Do something after the editor is destroyed.
|
|
101
|
-
* } );
|
|
102
|
-
* } );
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
setDestructor(destructor: (editor: Editor) => Promise<unknown>): void;
|
|
106
|
-
/**
|
|
107
|
-
* Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
|
|
108
|
-
* the state to `initializing`.
|
|
109
|
-
*
|
|
110
|
-
* @fires restart
|
|
111
|
-
*/
|
|
112
|
-
protected _restart(): Promise<unknown>;
|
|
113
|
-
/**
|
|
114
|
-
* Creates the editor instance and keeps it running, using the defined creator and destructor.
|
|
115
|
-
*
|
|
116
|
-
* @param elementOrData The editor source element or the editor data.
|
|
117
|
-
* @param config The editor configuration.
|
|
118
|
-
* @param context A context for the editor.
|
|
119
|
-
*/
|
|
120
|
-
create(elementOrData?: HTMLElement | string | Record<string, string> | Record<string, HTMLElement>, config?: EditorConfig, context?: Context): Promise<unknown>;
|
|
121
|
-
/**
|
|
122
|
-
* Destroys the watchdog and the current editor instance. It fires the callback
|
|
123
|
-
* registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
|
|
124
|
-
* It also sets the state to `destroyed`.
|
|
125
|
-
*/
|
|
126
|
-
destroy(): Promise<unknown>;
|
|
127
|
-
private _destroy;
|
|
128
|
-
/**
|
|
129
|
-
* Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
|
|
130
|
-
* the moment of the crash.
|
|
131
|
-
*/
|
|
132
|
-
private _save;
|
|
133
|
-
/**
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
_setExcludedProperties(props: Set<unknown>): void;
|
|
137
|
-
/**
|
|
138
|
-
* Gets all data that is required to reinitialize editor instance.
|
|
139
|
-
*/
|
|
140
|
-
private _getData;
|
|
141
|
-
/**
|
|
142
|
-
* For each attached model root, returns its HTML editable element (if available).
|
|
143
|
-
*/
|
|
144
|
-
private _getEditables;
|
|
145
|
-
/**
|
|
146
|
-
* Traverses the error context and the current editor to find out whether these structures are connected
|
|
147
|
-
* to each other via properties.
|
|
148
|
-
*
|
|
149
|
-
* @internal
|
|
150
|
-
*/
|
|
151
|
-
_isErrorComingFromThisItem(error: CKEditorError): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Clones the editor configuration.
|
|
154
|
-
*/
|
|
155
|
-
private _cloneEditorConfiguration;
|
|
156
|
-
}
|
|
157
|
-
export type EditorData = {
|
|
158
|
-
roots: Record<string, {
|
|
159
|
-
content: string;
|
|
160
|
-
attributes: string;
|
|
161
|
-
isLoaded: boolean;
|
|
162
|
-
}>;
|
|
163
|
-
markers: Record<string, {
|
|
164
|
-
rangeJSON: {
|
|
165
|
-
start: any;
|
|
166
|
-
end: any;
|
|
167
|
-
};
|
|
168
|
-
usingOperation: boolean;
|
|
169
|
-
affectsData: boolean;
|
|
170
|
-
}>;
|
|
171
|
-
commentThreads: string;
|
|
172
|
-
suggestions: string;
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Fired after the watchdog restarts the error in case of a crash.
|
|
176
|
-
*
|
|
177
|
-
* @eventName ~EditorWatchdog#restart
|
|
178
|
-
*/
|
|
179
|
-
export type EditorWatchdogRestartEvent = {
|
|
180
|
-
name: 'restart';
|
|
181
|
-
args: [];
|
|
182
|
-
return: undefined;
|
|
183
|
-
};
|
|
184
|
-
export type EditorCreatorFunction<TEditor = Editor> = (elementOrData: HTMLElement | string | Record<string, string> | Record<string, HTMLElement>, config: EditorConfig) => Promise<TEditor>;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module watchdog/editorwatchdog
|
|
7
|
+
*/
|
|
8
|
+
import type { CKEditorError } from 'ckeditor5/src/utils';
|
|
9
|
+
import type { Editor, EditorConfig, Context } from 'ckeditor5/src/core';
|
|
10
|
+
import Watchdog, { type WatchdogConfig } from './watchdog';
|
|
11
|
+
/**
|
|
12
|
+
* A watchdog for CKEditor 5 editors.
|
|
13
|
+
*
|
|
14
|
+
* See the {@glink features/watchdog Watchdog feature guide} to learn the rationale behind it and
|
|
15
|
+
* how to use it.
|
|
16
|
+
*/
|
|
17
|
+
export default class EditorWatchdog<TEditor extends Editor = Editor> extends Watchdog {
|
|
18
|
+
/**
|
|
19
|
+
* The current editor instance.
|
|
20
|
+
*/
|
|
21
|
+
private _editor;
|
|
22
|
+
/**
|
|
23
|
+
* Throttled save method. The `save()` method is called the specified `saveInterval` after `throttledSave()` is called,
|
|
24
|
+
* unless a new action happens in the meantime.
|
|
25
|
+
*/
|
|
26
|
+
private _throttledSave;
|
|
27
|
+
/**
|
|
28
|
+
* The latest saved editor data represented as a root name -> root data object.
|
|
29
|
+
*/
|
|
30
|
+
private _data?;
|
|
31
|
+
/**
|
|
32
|
+
* The last document version.
|
|
33
|
+
*/
|
|
34
|
+
private _lastDocumentVersion?;
|
|
35
|
+
/**
|
|
36
|
+
* The editor source element or data.
|
|
37
|
+
*/
|
|
38
|
+
private _elementOrData?;
|
|
39
|
+
/**
|
|
40
|
+
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
|
|
41
|
+
*/
|
|
42
|
+
private _initUsingData;
|
|
43
|
+
/**
|
|
44
|
+
* The latest record of the editor editable elements. Used to restart the editor.
|
|
45
|
+
*/
|
|
46
|
+
private _editables;
|
|
47
|
+
/**
|
|
48
|
+
* The editor configuration.
|
|
49
|
+
*/
|
|
50
|
+
private _config?;
|
|
51
|
+
/**
|
|
52
|
+
* The creation method.
|
|
53
|
+
*
|
|
54
|
+
* @see #setCreator
|
|
55
|
+
*/
|
|
56
|
+
protected _creator: EditorCreatorFunction<TEditor>;
|
|
57
|
+
/**
|
|
58
|
+
* The destruction method.
|
|
59
|
+
*
|
|
60
|
+
* @see #setDestructor
|
|
61
|
+
*/
|
|
62
|
+
protected _destructor: (editor: Editor) => Promise<unknown>;
|
|
63
|
+
private _excludedProps?;
|
|
64
|
+
/**
|
|
65
|
+
* @param Editor The editor class.
|
|
66
|
+
* @param watchdogConfig The watchdog plugin configuration.
|
|
67
|
+
*/
|
|
68
|
+
constructor(Editor: {
|
|
69
|
+
create(...args: any): Promise<TEditor>;
|
|
70
|
+
} | null, watchdogConfig?: WatchdogConfig);
|
|
71
|
+
/**
|
|
72
|
+
* The current editor instance.
|
|
73
|
+
*/
|
|
74
|
+
get editor(): TEditor | null;
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
get _item(): TEditor | null;
|
|
79
|
+
/**
|
|
80
|
+
* Sets the function that is responsible for the editor creation.
|
|
81
|
+
* It expects a function that should return a promise.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
setCreator(creator: EditorCreatorFunction<TEditor>): void;
|
|
88
|
+
/**
|
|
89
|
+
* Sets the function that is responsible for the editor destruction.
|
|
90
|
+
* Overrides the default destruction function, which destroys only the editor instance.
|
|
91
|
+
* It expects a function that should return a promise or `undefined`.
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* watchdog.setDestructor( editor => {
|
|
95
|
+
* // Do something before the editor is destroyed.
|
|
96
|
+
*
|
|
97
|
+
* return editor
|
|
98
|
+
* .destroy()
|
|
99
|
+
* .then( () => {
|
|
100
|
+
* // Do something after the editor is destroyed.
|
|
101
|
+
* } );
|
|
102
|
+
* } );
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
setDestructor(destructor: (editor: Editor) => Promise<unknown>): void;
|
|
106
|
+
/**
|
|
107
|
+
* Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
|
|
108
|
+
* the state to `initializing`.
|
|
109
|
+
*
|
|
110
|
+
* @fires restart
|
|
111
|
+
*/
|
|
112
|
+
protected _restart(): Promise<unknown>;
|
|
113
|
+
/**
|
|
114
|
+
* Creates the editor instance and keeps it running, using the defined creator and destructor.
|
|
115
|
+
*
|
|
116
|
+
* @param elementOrData The editor source element or the editor data.
|
|
117
|
+
* @param config The editor configuration.
|
|
118
|
+
* @param context A context for the editor.
|
|
119
|
+
*/
|
|
120
|
+
create(elementOrData?: HTMLElement | string | Record<string, string> | Record<string, HTMLElement>, config?: EditorConfig, context?: Context): Promise<unknown>;
|
|
121
|
+
/**
|
|
122
|
+
* Destroys the watchdog and the current editor instance. It fires the callback
|
|
123
|
+
* registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
|
|
124
|
+
* It also sets the state to `destroyed`.
|
|
125
|
+
*/
|
|
126
|
+
destroy(): Promise<unknown>;
|
|
127
|
+
private _destroy;
|
|
128
|
+
/**
|
|
129
|
+
* Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
|
|
130
|
+
* the moment of the crash.
|
|
131
|
+
*/
|
|
132
|
+
private _save;
|
|
133
|
+
/**
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
_setExcludedProperties(props: Set<unknown>): void;
|
|
137
|
+
/**
|
|
138
|
+
* Gets all data that is required to reinitialize editor instance.
|
|
139
|
+
*/
|
|
140
|
+
private _getData;
|
|
141
|
+
/**
|
|
142
|
+
* For each attached model root, returns its HTML editable element (if available).
|
|
143
|
+
*/
|
|
144
|
+
private _getEditables;
|
|
145
|
+
/**
|
|
146
|
+
* Traverses the error context and the current editor to find out whether these structures are connected
|
|
147
|
+
* to each other via properties.
|
|
148
|
+
*
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
_isErrorComingFromThisItem(error: CKEditorError): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Clones the editor configuration.
|
|
154
|
+
*/
|
|
155
|
+
private _cloneEditorConfiguration;
|
|
156
|
+
}
|
|
157
|
+
export type EditorData = {
|
|
158
|
+
roots: Record<string, {
|
|
159
|
+
content: string;
|
|
160
|
+
attributes: string;
|
|
161
|
+
isLoaded: boolean;
|
|
162
|
+
}>;
|
|
163
|
+
markers: Record<string, {
|
|
164
|
+
rangeJSON: {
|
|
165
|
+
start: any;
|
|
166
|
+
end: any;
|
|
167
|
+
};
|
|
168
|
+
usingOperation: boolean;
|
|
169
|
+
affectsData: boolean;
|
|
170
|
+
}>;
|
|
171
|
+
commentThreads: string;
|
|
172
|
+
suggestions: string;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Fired after the watchdog restarts the error in case of a crash.
|
|
176
|
+
*
|
|
177
|
+
* @eventName ~EditorWatchdog#restart
|
|
178
|
+
*/
|
|
179
|
+
export type EditorWatchdogRestartEvent = {
|
|
180
|
+
name: 'restart';
|
|
181
|
+
args: [];
|
|
182
|
+
return: undefined;
|
|
183
|
+
};
|
|
184
|
+
export type EditorCreatorFunction<TEditor = Editor> = (elementOrData: HTMLElement | string | Record<string, string> | Record<string, HTMLElement>, config: EditorConfig) => Promise<TEditor>;
|