@ckeditor/ckeditor5-watchdog 47.6.1 → 48.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/ckeditor5-metadata.json +1 -1
- package/{src → dist}/contextwatchdog.d.ts +13 -8
- package/{src → dist}/editorwatchdog.d.ts +37 -4
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +209 -59
- package/dist/index.js.map +1 -1
- package/dist/utils/normalizerootsconfig.d.ts +18 -0
- package/package.json +22 -42
- package/src/actionsrecorder.js +0 -627
- package/src/actionsrecorderconfig.js +0 -5
- package/src/augmentation.js +0 -5
- package/src/contextwatchdog.js +0 -423
- package/src/editorwatchdog.js +0 -470
- package/src/index.js +0 -12
- package/src/utils/areconnectedthroughproperties.js +0 -59
- package/src/utils/getsubnodes.js +0 -79
- package/src/watchdog.js +0 -201
- /package/{src → dist}/actionsrecorder.d.ts +0 -0
- /package/{src → dist}/actionsrecorderconfig.d.ts +0 -0
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/utils/areconnectedthroughproperties.d.ts +0 -0
- /package/{src → dist}/utils/getsubnodes.d.ts +0 -0
- /package/{src → dist}/watchdog.d.ts +0 -0
package/src/editorwatchdog.js
DELETED
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module watchdog/editorwatchdog
|
|
7
|
-
*/
|
|
8
|
-
import { throttle, cloneDeepWith, isElement } from 'es-toolkit/compat';
|
|
9
|
-
import { areConnectedThroughProperties } from './utils/areconnectedthroughproperties.js';
|
|
10
|
-
import { Watchdog } from './watchdog.js';
|
|
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 class EditorWatchdog extends Watchdog {
|
|
18
|
-
/**
|
|
19
|
-
* The current editor instance.
|
|
20
|
-
*/
|
|
21
|
-
_editor = null;
|
|
22
|
-
/**
|
|
23
|
-
* A promise associated with the life cycle of the editor (creation or destruction processes).
|
|
24
|
-
*
|
|
25
|
-
* It is used to prevent the initialization of the editor if the previous instance has not been destroyed yet,
|
|
26
|
-
* and conversely, to prevent the destruction of the editor if it has not been initialized.
|
|
27
|
-
*/
|
|
28
|
-
_lifecyclePromise = null;
|
|
29
|
-
/**
|
|
30
|
-
* Throttled save method. The `save()` method is called the specified `saveInterval` after `throttledSave()` is called,
|
|
31
|
-
* unless a new action happens in the meantime.
|
|
32
|
-
*/
|
|
33
|
-
_throttledSave;
|
|
34
|
-
/**
|
|
35
|
-
* The latest saved editor data represented as a root name -> root data object.
|
|
36
|
-
*/
|
|
37
|
-
_data;
|
|
38
|
-
/**
|
|
39
|
-
* The last document version.
|
|
40
|
-
*/
|
|
41
|
-
_lastDocumentVersion;
|
|
42
|
-
/**
|
|
43
|
-
* The editor source element or data.
|
|
44
|
-
*/
|
|
45
|
-
_elementOrData;
|
|
46
|
-
/**
|
|
47
|
-
* Specifies whether the editor was initialized using document data (`true`) or HTML elements (`false`).
|
|
48
|
-
*/
|
|
49
|
-
_initUsingData = true;
|
|
50
|
-
/**
|
|
51
|
-
* The latest record of the editor editable elements. Used to restart the editor.
|
|
52
|
-
*/
|
|
53
|
-
_editables = {};
|
|
54
|
-
/**
|
|
55
|
-
* The editor configuration.
|
|
56
|
-
*/
|
|
57
|
-
_config;
|
|
58
|
-
_excludedProps;
|
|
59
|
-
/**
|
|
60
|
-
* @param Editor The editor class.
|
|
61
|
-
* @param watchdogConfig The watchdog plugin configuration.
|
|
62
|
-
*/
|
|
63
|
-
constructor(Editor, watchdogConfig = {}) {
|
|
64
|
-
super(watchdogConfig);
|
|
65
|
-
// this._editorClass = Editor;
|
|
66
|
-
this._throttledSave = throttle(this._save.bind(this), typeof watchdogConfig.saveInterval === 'number' ? watchdogConfig.saveInterval : 5000);
|
|
67
|
-
// Set default creator and destructor functions:
|
|
68
|
-
if (Editor) {
|
|
69
|
-
this._creator = ((elementOrData, config) => Editor.create(elementOrData, config));
|
|
70
|
-
}
|
|
71
|
-
this._destructor = editor => editor.destroy();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* The current editor instance.
|
|
75
|
-
*/
|
|
76
|
-
get editor() {
|
|
77
|
-
return this._editor;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @internal
|
|
81
|
-
*/
|
|
82
|
-
get _item() {
|
|
83
|
-
return this._editor;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Sets the function that is responsible for the editor creation.
|
|
87
|
-
* It expects a function that should return a promise.
|
|
88
|
-
*
|
|
89
|
-
* ```ts
|
|
90
|
-
* watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
setCreator(creator) {
|
|
94
|
-
this._creator = creator;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Sets the function that is responsible for the editor destruction.
|
|
98
|
-
* Overrides the default destruction function, which destroys only the editor instance.
|
|
99
|
-
* It expects a function that should return a promise or `undefined`.
|
|
100
|
-
*
|
|
101
|
-
* ```ts
|
|
102
|
-
* watchdog.setDestructor( editor => {
|
|
103
|
-
* // Do something before the editor is destroyed.
|
|
104
|
-
*
|
|
105
|
-
* return editor
|
|
106
|
-
* .destroy()
|
|
107
|
-
* .then( () => {
|
|
108
|
-
* // Do something after the editor is destroyed.
|
|
109
|
-
* } );
|
|
110
|
-
* } );
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
setDestructor(destructor) {
|
|
114
|
-
this._destructor = destructor;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
|
|
118
|
-
* the state to `initializing`.
|
|
119
|
-
*
|
|
120
|
-
* @fires restart
|
|
121
|
-
*/
|
|
122
|
-
_restart() {
|
|
123
|
-
return Promise.resolve()
|
|
124
|
-
.then(() => {
|
|
125
|
-
this.state = 'initializing';
|
|
126
|
-
this._fire('stateChange');
|
|
127
|
-
return this._destroy();
|
|
128
|
-
})
|
|
129
|
-
.catch(err => {
|
|
130
|
-
console.error('An error happened during the editor destroying.', err);
|
|
131
|
-
})
|
|
132
|
-
.then(() => {
|
|
133
|
-
// Pre-process some data from the original editor config.
|
|
134
|
-
// Our goal here is to make sure that the restarted editor will be reinitialized with correct set of roots.
|
|
135
|
-
// We are not interested in any data set in config or in `.create()` first parameter. It will be replaced anyway.
|
|
136
|
-
// But we need to set them correctly to make sure that proper roots are created.
|
|
137
|
-
//
|
|
138
|
-
// Since a different set of roots will be created, `lazyRoots` and `rootsAttributes` properties must be managed too.
|
|
139
|
-
// Keys are root names, values are ''. Used when the editor was initialized by setting the first parameter to document data.
|
|
140
|
-
const existingRoots = {};
|
|
141
|
-
// Keeps lazy roots. They may be different when compared to initial config if some of the roots were loaded.
|
|
142
|
-
const lazyRoots = [];
|
|
143
|
-
// Roots attributes from the old config. Will be referred when setting new attributes.
|
|
144
|
-
const oldRootsAttributes = this._config.rootsAttributes || {};
|
|
145
|
-
// New attributes to be set. Is filled only for roots that still exist in the document.
|
|
146
|
-
const rootsAttributes = {};
|
|
147
|
-
// Traverse through the roots saved when the editor crashed and set up the discussed values.
|
|
148
|
-
for (const [rootName, rootData] of Object.entries(this._data.roots)) {
|
|
149
|
-
if (rootData.isLoaded) {
|
|
150
|
-
existingRoots[rootName] = '';
|
|
151
|
-
rootsAttributes[rootName] = oldRootsAttributes[rootName] || {};
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
lazyRoots.push(rootName);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const updatedConfig = {
|
|
158
|
-
...this._config,
|
|
159
|
-
extraPlugins: this._config.extraPlugins || [],
|
|
160
|
-
lazyRoots,
|
|
161
|
-
rootsAttributes,
|
|
162
|
-
_watchdogInitialData: this._data
|
|
163
|
-
};
|
|
164
|
-
// Delete `initialData` as it is not needed. Data will be set by the watchdog based on `_watchdogInitialData`.
|
|
165
|
-
// First parameter of the editor `.create()` will be used to set up initial roots.
|
|
166
|
-
delete updatedConfig.initialData;
|
|
167
|
-
updatedConfig.extraPlugins.push(EditorWatchdogInitPlugin);
|
|
168
|
-
if (this._initUsingData) {
|
|
169
|
-
return this.create(existingRoots, updatedConfig, updatedConfig.context);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
// Set correct editables to make sure that proper roots are created and linked with DOM elements.
|
|
173
|
-
// No need to set initial data, as it would be discarded anyway.
|
|
174
|
-
//
|
|
175
|
-
// If one element was initially set in `elementOrData`, then use that original element to restart the editor.
|
|
176
|
-
// This is for compatibility purposes with single-root editor types.
|
|
177
|
-
if (isElement(this._elementOrData)) {
|
|
178
|
-
return this.create(this._elementOrData, updatedConfig, updatedConfig.context);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return this.create(this._editables, updatedConfig, updatedConfig.context);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
.then(() => {
|
|
186
|
-
this._fire('restart');
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Creates the editor instance and keeps it running, using the defined creator and destructor.
|
|
191
|
-
*
|
|
192
|
-
* @param elementOrData The editor source element or the editor data.
|
|
193
|
-
* @param config The editor configuration.
|
|
194
|
-
* @param context A context for the editor.
|
|
195
|
-
*/
|
|
196
|
-
create(elementOrData = this._elementOrData, config = this._config, context) {
|
|
197
|
-
this._lifecyclePromise = Promise.resolve(this._lifecyclePromise)
|
|
198
|
-
.then(() => {
|
|
199
|
-
super._startErrorHandling();
|
|
200
|
-
this._elementOrData = elementOrData;
|
|
201
|
-
// Use document data in the first parameter of the editor `.create()` call only if it was used like this originally.
|
|
202
|
-
// Use document data if a string or object with strings was passed.
|
|
203
|
-
this._initUsingData = typeof elementOrData == 'string' ||
|
|
204
|
-
(Object.keys(elementOrData).length > 0 && typeof Object.values(elementOrData)[0] == 'string');
|
|
205
|
-
// Clone configuration because it might be shared within multiple watchdog instances. Otherwise,
|
|
206
|
-
// when an error occurs in one of these editors, the watchdog will restart all of them.
|
|
207
|
-
this._config = this._cloneEditorConfiguration(config) || {};
|
|
208
|
-
this._config.context = context;
|
|
209
|
-
return this._creator(elementOrData, this._config);
|
|
210
|
-
})
|
|
211
|
-
.then(editor => {
|
|
212
|
-
this._editor = editor;
|
|
213
|
-
editor.model.document.on('change:data', this._throttledSave);
|
|
214
|
-
this._lastDocumentVersion = editor.model.document.version;
|
|
215
|
-
this._data = this._getData();
|
|
216
|
-
if (!this._initUsingData) {
|
|
217
|
-
this._editables = this._getEditables();
|
|
218
|
-
}
|
|
219
|
-
this.state = 'ready';
|
|
220
|
-
this._fire('stateChange');
|
|
221
|
-
}).finally(() => {
|
|
222
|
-
this._lifecyclePromise = null;
|
|
223
|
-
});
|
|
224
|
-
return this._lifecyclePromise;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Destroys the watchdog and the current editor instance. It fires the callback
|
|
228
|
-
* registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
|
|
229
|
-
* It also sets the state to `destroyed`.
|
|
230
|
-
*/
|
|
231
|
-
destroy() {
|
|
232
|
-
this._lifecyclePromise = Promise.resolve(this._lifecyclePromise)
|
|
233
|
-
.then(() => {
|
|
234
|
-
this.state = 'destroyed';
|
|
235
|
-
this._fire('stateChange');
|
|
236
|
-
super.destroy();
|
|
237
|
-
return this._destroy();
|
|
238
|
-
}).finally(() => {
|
|
239
|
-
this._lifecyclePromise = null;
|
|
240
|
-
});
|
|
241
|
-
return this._lifecyclePromise;
|
|
242
|
-
}
|
|
243
|
-
_destroy() {
|
|
244
|
-
return Promise.resolve()
|
|
245
|
-
.then(() => {
|
|
246
|
-
this._stopErrorHandling();
|
|
247
|
-
this._throttledSave.cancel();
|
|
248
|
-
const editor = this._editor;
|
|
249
|
-
this._editor = null;
|
|
250
|
-
// Remove the `change:data` listener before destroying the editor.
|
|
251
|
-
// Incorrectly written plugins may trigger firing `change:data` events during the editor destruction phase
|
|
252
|
-
// causing the watchdog to call `editor.getData()` when some parts of editor are already destroyed.
|
|
253
|
-
editor.model.document.off('change:data', this._throttledSave);
|
|
254
|
-
return this._destructor(editor);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
|
|
259
|
-
* the moment of the crash.
|
|
260
|
-
*/
|
|
261
|
-
_save() {
|
|
262
|
-
const version = this._editor.model.document.version;
|
|
263
|
-
try {
|
|
264
|
-
this._data = this._getData();
|
|
265
|
-
if (!this._initUsingData) {
|
|
266
|
-
this._editables = this._getEditables();
|
|
267
|
-
}
|
|
268
|
-
this._lastDocumentVersion = version;
|
|
269
|
-
}
|
|
270
|
-
catch (err) {
|
|
271
|
-
console.error(err, 'An error happened during restoring editor data. ' +
|
|
272
|
-
'Editor will be restored from the previously saved data.');
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* @internal
|
|
277
|
-
*/
|
|
278
|
-
_setExcludedProperties(props) {
|
|
279
|
-
this._excludedProps = props;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Gets all data that is required to reinitialize editor instance.
|
|
283
|
-
*/
|
|
284
|
-
_getData() {
|
|
285
|
-
const editor = this._editor;
|
|
286
|
-
const roots = editor.model.document.roots.filter(root => root.isAttached() && root.rootName != '$graveyard');
|
|
287
|
-
const { plugins } = editor;
|
|
288
|
-
// `as any` to avoid linking from external private repo.
|
|
289
|
-
const commentsRepository = plugins.has('CommentsRepository') && plugins.get('CommentsRepository');
|
|
290
|
-
const trackChanges = plugins.has('TrackChanges') && plugins.get('TrackChanges');
|
|
291
|
-
const data = {
|
|
292
|
-
roots: {},
|
|
293
|
-
markers: {},
|
|
294
|
-
commentThreads: JSON.stringify([]),
|
|
295
|
-
suggestions: JSON.stringify([])
|
|
296
|
-
};
|
|
297
|
-
roots.forEach(root => {
|
|
298
|
-
data.roots[root.rootName] = {
|
|
299
|
-
content: JSON.stringify(Array.from(root.getChildren())),
|
|
300
|
-
attributes: JSON.stringify(Array.from(root.getAttributes())),
|
|
301
|
-
isLoaded: root._isLoaded
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
for (const marker of editor.model.markers) {
|
|
305
|
-
if (!marker._affectsData) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
data.markers[marker.name] = {
|
|
309
|
-
rangeJSON: marker.getRange().toJSON(),
|
|
310
|
-
usingOperation: marker._managedUsingOperations,
|
|
311
|
-
affectsData: marker._affectsData
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
if (commentsRepository) {
|
|
315
|
-
data.commentThreads = JSON.stringify(commentsRepository.getCommentThreads({ toJSON: true, skipNotAttached: true }));
|
|
316
|
-
}
|
|
317
|
-
if (trackChanges) {
|
|
318
|
-
data.suggestions = JSON.stringify(trackChanges.getSuggestions({ toJSON: true, skipNotAttached: true }));
|
|
319
|
-
}
|
|
320
|
-
return data;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* For each attached model root, returns its HTML editable element (if available).
|
|
324
|
-
*/
|
|
325
|
-
_getEditables() {
|
|
326
|
-
const editables = {};
|
|
327
|
-
for (const rootName of this.editor.model.document.getRootNames()) {
|
|
328
|
-
const editable = this.editor.ui.getEditableElement(rootName);
|
|
329
|
-
if (editable) {
|
|
330
|
-
editables[rootName] = editable;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return editables;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Traverses the error context and the current editor to find out whether these structures are connected
|
|
337
|
-
* to each other via properties.
|
|
338
|
-
*
|
|
339
|
-
* @internal
|
|
340
|
-
*/
|
|
341
|
-
_isErrorComingFromThisItem(error) {
|
|
342
|
-
return areConnectedThroughProperties(this._editor, error.context, this._excludedProps);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Clones the editor configuration.
|
|
346
|
-
*/
|
|
347
|
-
_cloneEditorConfiguration(config) {
|
|
348
|
-
return cloneDeepWith(config, (value, key) => {
|
|
349
|
-
// Leave DOM references.
|
|
350
|
-
if (isElement(value)) {
|
|
351
|
-
return value;
|
|
352
|
-
}
|
|
353
|
-
if (key === 'context') {
|
|
354
|
-
return value;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Internal plugin that is used to stop the default editor initialization and restoring the editor state
|
|
361
|
-
* based on the `editor.config._watchdogInitialData` data.
|
|
362
|
-
*/
|
|
363
|
-
class EditorWatchdogInitPlugin {
|
|
364
|
-
editor;
|
|
365
|
-
_data;
|
|
366
|
-
constructor(editor) {
|
|
367
|
-
this.editor = editor;
|
|
368
|
-
this._data = editor.config.get('_watchdogInitialData');
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* @inheritDoc
|
|
372
|
-
*/
|
|
373
|
-
init() {
|
|
374
|
-
// Stops the default editor initialization and use the saved data to restore the editor state.
|
|
375
|
-
// Some of data could not be initialize as a config properties. It is important to keep the data
|
|
376
|
-
// in the same form as it was before the restarting.
|
|
377
|
-
this.editor.data.on('init', evt => {
|
|
378
|
-
evt.stop();
|
|
379
|
-
this.editor.model.enqueueChange({ isUndoable: false }, writer => {
|
|
380
|
-
this._restoreCollaborationData();
|
|
381
|
-
this._restoreEditorData(writer);
|
|
382
|
-
});
|
|
383
|
-
this.editor.data.fire('ready');
|
|
384
|
-
// Keep priority `'high' - 1` to be sure that RTC initialization will be first.
|
|
385
|
-
}, { priority: 1000 - 1 });
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Creates a model node (element or text) based on provided JSON.
|
|
389
|
-
*/
|
|
390
|
-
_createNode(writer, jsonNode) {
|
|
391
|
-
if ('name' in jsonNode) {
|
|
392
|
-
// If child has name property, it is an Element.
|
|
393
|
-
const element = writer.createElement(jsonNode.name, jsonNode.attributes);
|
|
394
|
-
if (jsonNode.children) {
|
|
395
|
-
for (const child of jsonNode.children) {
|
|
396
|
-
element._appendChild(this._createNode(writer, child));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return element;
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
// Otherwise, it is a Text node.
|
|
403
|
-
return writer.createText(jsonNode.data, jsonNode.attributes);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Restores the editor by setting the document data, roots attributes and markers.
|
|
408
|
-
*/
|
|
409
|
-
_restoreEditorData(writer) {
|
|
410
|
-
const editor = this.editor;
|
|
411
|
-
Object.entries(this._data.roots).forEach(([rootName, { content, attributes }]) => {
|
|
412
|
-
const parsedNodes = JSON.parse(content);
|
|
413
|
-
const parsedAttributes = JSON.parse(attributes);
|
|
414
|
-
const rootElement = editor.model.document.getRoot(rootName);
|
|
415
|
-
for (const [key, value] of parsedAttributes) {
|
|
416
|
-
writer.setAttribute(key, value, rootElement);
|
|
417
|
-
}
|
|
418
|
-
for (const child of parsedNodes) {
|
|
419
|
-
const node = this._createNode(writer, child);
|
|
420
|
-
writer.insert(node, rootElement, 'end');
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
Object.entries(this._data.markers).forEach(([markerName, markerOptions]) => {
|
|
424
|
-
const { document } = editor.model;
|
|
425
|
-
const { rangeJSON: { start, end }, ...options } = markerOptions;
|
|
426
|
-
const root = document.getRoot(start.root);
|
|
427
|
-
const startPosition = writer.createPositionFromPath(root, start.path, start.stickiness);
|
|
428
|
-
const endPosition = writer.createPositionFromPath(root, end.path, end.stickiness);
|
|
429
|
-
const range = writer.createRange(startPosition, endPosition);
|
|
430
|
-
writer.addMarker(markerName, {
|
|
431
|
-
range,
|
|
432
|
-
...options
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Restores the editor collaboration data - comment threads and suggestions.
|
|
438
|
-
*/
|
|
439
|
-
_restoreCollaborationData() {
|
|
440
|
-
// `as any` to avoid linking from external private repo.
|
|
441
|
-
const parsedCommentThreads = JSON.parse(this._data.commentThreads);
|
|
442
|
-
const parsedSuggestions = JSON.parse(this._data.suggestions);
|
|
443
|
-
if (this.editor.plugins.has('CommentsRepository')) {
|
|
444
|
-
const commentsRepository = this.editor.plugins.get('CommentsRepository');
|
|
445
|
-
// First, remove the existing comments that were created by integration plugins during initialization.
|
|
446
|
-
// These comments may be outdated, and new instances will be created in the next step based on the saved data.
|
|
447
|
-
for (const commentThread of commentsRepository.getCommentThreads()) {
|
|
448
|
-
// Use the internal API since it removes the comment thread directly and does not trigger events
|
|
449
|
-
// that could cause side effects, such as removing markers.
|
|
450
|
-
commentsRepository._removeCommentThread({ threadId: commentThread.id });
|
|
451
|
-
}
|
|
452
|
-
parsedCommentThreads.forEach(commentThreadData => {
|
|
453
|
-
const channelId = this.editor.config.get('collaboration.channelId');
|
|
454
|
-
const commentsRepository = this.editor.plugins.get('CommentsRepository');
|
|
455
|
-
commentsRepository.addCommentThread({ channelId, ...commentThreadData });
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
if (this.editor.plugins.has('TrackChangesEditing')) {
|
|
459
|
-
const trackChangesEditing = this.editor.plugins.get('TrackChangesEditing');
|
|
460
|
-
// First, remove the existing suggestions that were created by integration plugins during initialization.
|
|
461
|
-
// These suggestions may be outdated, and new instances will be created in the next step based on the saved data.
|
|
462
|
-
for (const suggestion of trackChangesEditing.getSuggestions()) {
|
|
463
|
-
trackChangesEditing._removeSuggestion(suggestion);
|
|
464
|
-
}
|
|
465
|
-
parsedSuggestions.forEach(suggestionData => {
|
|
466
|
-
trackChangesEditing.addSuggestionData(suggestionData);
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module watchdog
|
|
7
|
-
*/
|
|
8
|
-
export { ContextWatchdog } from './contextwatchdog.js';
|
|
9
|
-
export { EditorWatchdog } from './editorwatchdog.js';
|
|
10
|
-
export { Watchdog } from './watchdog.js';
|
|
11
|
-
export { ActionsRecorder } from './actionsrecorder.js';
|
|
12
|
-
import './augmentation.js';
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module watchdog/utils/areconnectedthroughproperties
|
|
7
|
-
*/
|
|
8
|
-
import { getSubNodes } from './getsubnodes.js';
|
|
9
|
-
/**
|
|
10
|
-
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export function areConnectedThroughProperties(target1, target2, excludedNodes = new Set()) {
|
|
15
|
-
if (target1 === target2 && isObject(target1)) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
// @if CK_DEBUG_WATCHDOG // return checkConnectionBetweenProps( target1, target2, excludedNodes );
|
|
19
|
-
const subNodes1 = getSubNodes(target1, excludedNodes);
|
|
20
|
-
const subNodes2 = getSubNodes(target2, excludedNodes);
|
|
21
|
-
for (const node of subNodes1) {
|
|
22
|
-
if (subNodes2.has(node)) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
/* istanbul ignore next -- @preserve */
|
|
29
|
-
// eslint-disable-next-line
|
|
30
|
-
function checkConnectionBetweenProps(target1, target2, excludedNodes) {
|
|
31
|
-
const { subNodes: subNodes1, prevNodeMap: prevNodeMap1 } = getSubNodes(target1, excludedNodes.subNodes);
|
|
32
|
-
const { subNodes: subNodes2, prevNodeMap: prevNodeMap2 } = getSubNodes(target2, excludedNodes.subNodes);
|
|
33
|
-
for (const sharedNode of subNodes1) {
|
|
34
|
-
if (subNodes2.has(sharedNode)) {
|
|
35
|
-
const connection = [];
|
|
36
|
-
connection.push(sharedNode);
|
|
37
|
-
let node = prevNodeMap1.get(sharedNode);
|
|
38
|
-
while (node && node !== target1) {
|
|
39
|
-
connection.push(node);
|
|
40
|
-
node = prevNodeMap1.get(node);
|
|
41
|
-
}
|
|
42
|
-
node = prevNodeMap2.get(sharedNode);
|
|
43
|
-
while (node && node !== target2) {
|
|
44
|
-
connection.unshift(node);
|
|
45
|
-
node = prevNodeMap2.get(node);
|
|
46
|
-
}
|
|
47
|
-
console.log('--------');
|
|
48
|
-
console.log({ target1 });
|
|
49
|
-
console.log({ sharedNode });
|
|
50
|
-
console.log({ target2 });
|
|
51
|
-
console.log({ connection });
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
function isObject(structure) {
|
|
58
|
-
return typeof structure === 'object' && structure !== null;
|
|
59
|
-
}
|
package/src/utils/getsubnodes.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module watchdog/utils/getsubnodes
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function getSubNodes(head, excludedProperties = new Set()) {
|
|
12
|
-
const nodes = [head];
|
|
13
|
-
// @if CK_DEBUG_WATCHDOG // const prevNodeMap = new Map();
|
|
14
|
-
// Nodes are stored to prevent infinite looping.
|
|
15
|
-
const subNodes = new Set();
|
|
16
|
-
let nodeIndex = 0;
|
|
17
|
-
while (nodes.length > nodeIndex) {
|
|
18
|
-
// Incrementing the iterator is much faster than changing size of the array with Array.prototype.shift().
|
|
19
|
-
const node = nodes[nodeIndex++];
|
|
20
|
-
if (subNodes.has(node) || !shouldNodeBeIncluded(node) || excludedProperties.has(node)) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
subNodes.add(node);
|
|
24
|
-
// Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
|
|
25
|
-
if (Symbol.iterator in node) {
|
|
26
|
-
// The custom editor iterators might cause some problems if the editor is crashed.
|
|
27
|
-
try {
|
|
28
|
-
for (const n of node) {
|
|
29
|
-
nodes.push(n);
|
|
30
|
-
// @if CK_DEBUG_WATCHDOG // if ( !prevNodeMap.has( n ) ) {
|
|
31
|
-
// @if CK_DEBUG_WATCHDOG // prevNodeMap.set( n, node );
|
|
32
|
-
// @if CK_DEBUG_WATCHDOG // }
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
// Do not log errors for broken structures
|
|
37
|
-
// since we are in the error handling process already.
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
for (const key in node) {
|
|
42
|
-
// We share a reference via the protobuf library within the editors,
|
|
43
|
-
// hence the shared value should be skipped. Although, it's not a perfect
|
|
44
|
-
// solution since new places like that might occur in the future.
|
|
45
|
-
if (key === 'defaultValue') {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
nodes.push(node[key]);
|
|
49
|
-
// @if CK_DEBUG_WATCHDOG // if ( !prevNodeMap.has( node[ key ] ) ) {
|
|
50
|
-
// @if CK_DEBUG_WATCHDOG // prevNodeMap.set( node[ key ], node );
|
|
51
|
-
// @if CK_DEBUG_WATCHDOG // }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// @if CK_DEBUG_WATCHDOG // return { subNodes, prevNodeMap } as any;
|
|
56
|
-
return subNodes;
|
|
57
|
-
}
|
|
58
|
-
function shouldNodeBeIncluded(node) {
|
|
59
|
-
const type = Object.prototype.toString.call(node);
|
|
60
|
-
const typeOfNode = typeof node;
|
|
61
|
-
return !(typeOfNode === 'number' ||
|
|
62
|
-
typeOfNode === 'boolean' ||
|
|
63
|
-
typeOfNode === 'string' ||
|
|
64
|
-
typeOfNode === 'symbol' ||
|
|
65
|
-
typeOfNode === 'function' ||
|
|
66
|
-
type === '[object Date]' ||
|
|
67
|
-
type === '[object RegExp]' ||
|
|
68
|
-
type === '[object Module]' ||
|
|
69
|
-
node === undefined ||
|
|
70
|
-
node === null ||
|
|
71
|
-
// This flag is meant to exclude singletons shared across editor instances. So when an error is thrown in one editor,
|
|
72
|
-
// the other editors connected through the reference to the same singleton are not restarted. This is a temporary workaround
|
|
73
|
-
// until a better solution is found.
|
|
74
|
-
// More in https://github.com/ckeditor/ckeditor5/issues/12292.
|
|
75
|
-
node._watchdogExcluded ||
|
|
76
|
-
// Skip native DOM objects, e.g. Window, nodes, events, etc.
|
|
77
|
-
node instanceof EventTarget ||
|
|
78
|
-
node instanceof Event);
|
|
79
|
-
}
|