@ckeditor/ckeditor5-watchdog 38.1.1 → 38.2.0-alpha.1

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.
@@ -1,155 +1,155 @@
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
- * The editor configuration.
41
- */
42
- private _config?;
43
- /**
44
- * The creation method.
45
- *
46
- * @see #setCreator
47
- */
48
- protected _creator: EditorCreatorFunction<TEditor>;
49
- /**
50
- * The destruction method.
51
- *
52
- * @see #setDestructor
53
- */
54
- protected _destructor: (editor: Editor) => Promise<unknown>;
55
- private _excludedProps?;
56
- /**
57
- * @param Editor The editor class.
58
- * @param watchdogConfig The watchdog plugin configuration.
59
- */
60
- constructor(Editor: {
61
- create(...args: any): Promise<TEditor>;
62
- } | null, watchdogConfig?: WatchdogConfig);
63
- /**
64
- * The current editor instance.
65
- */
66
- get editor(): TEditor | null;
67
- /**
68
- * @internal
69
- */
70
- get _item(): TEditor | null;
71
- /**
72
- * Sets the function that is responsible for the editor creation.
73
- * It expects a function that should return a promise.
74
- *
75
- * ```ts
76
- * watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
77
- * ```
78
- */
79
- setCreator(creator: EditorCreatorFunction<TEditor>): void;
80
- /**
81
- * Sets the function that is responsible for the editor destruction.
82
- * Overrides the default destruction function, which destroys only the editor instance.
83
- * It expects a function that should return a promise or `undefined`.
84
- *
85
- * ```ts
86
- * watchdog.setDestructor( editor => {
87
- * // Do something before the editor is destroyed.
88
- *
89
- * return editor
90
- * .destroy()
91
- * .then( () => {
92
- * // Do something after the editor is destroyed.
93
- * } );
94
- * } );
95
- * ```
96
- */
97
- setDestructor(destructor: (editor: Editor) => Promise<unknown>): void;
98
- /**
99
- * Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
100
- * the state to `initializing`.
101
- *
102
- * @fires restart
103
- */
104
- protected _restart(): Promise<unknown>;
105
- /**
106
- * Creates the editor instance and keeps it running, using the defined creator and destructor.
107
- *
108
- * @param elementOrData The editor source element or the editor data.
109
- * @param config The editor configuration.
110
- * @param context A context for the editor.
111
- */
112
- create(elementOrData?: HTMLElement | string | Record<string, string>, config?: EditorConfig, context?: Context): Promise<unknown>;
113
- /**
114
- * Destroys the watchdog and the current editor instance. It fires the callback
115
- * registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
116
- * It also sets the state to `destroyed`.
117
- */
118
- destroy(): Promise<unknown>;
119
- private _destroy;
120
- /**
121
- * Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
122
- * the moment of the crash.
123
- */
124
- private _save;
125
- /**
126
- * @internal
127
- */
128
- _setExcludedProperties(props: Set<unknown>): void;
129
- /**
130
- * Returns the editor data.
131
- */
132
- private _getData;
133
- /**
134
- * Traverses the error context and the current editor to find out whether these structures are connected
135
- * to each other via properties.
136
- *
137
- * @internal
138
- */
139
- _isErrorComingFromThisItem(error: CKEditorError): boolean;
140
- /**
141
- * Clones the editor configuration.
142
- */
143
- private _cloneEditorConfiguration;
144
- }
145
- /**
146
- * Fired after the watchdog restarts the error in case of a crash.
147
- *
148
- * @eventName ~EditorWatchdog#restart
149
- */
150
- export type EditorWatchdogRestartEvent = {
151
- name: 'restart';
152
- args: [];
153
- return: undefined;
154
- };
155
- export type EditorCreatorFunction<TEditor = Editor> = (elementOrData: HTMLElement | string | Record<string, string>, 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.js';
9
+ import type { Editor, EditorConfig, Context } from 'ckeditor5/src/core.js';
10
+ import Watchdog, { type WatchdogConfig } 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 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
+ * The editor configuration.
41
+ */
42
+ private _config?;
43
+ /**
44
+ * The creation method.
45
+ *
46
+ * @see #setCreator
47
+ */
48
+ protected _creator: EditorCreatorFunction<TEditor>;
49
+ /**
50
+ * The destruction method.
51
+ *
52
+ * @see #setDestructor
53
+ */
54
+ protected _destructor: (editor: Editor) => Promise<unknown>;
55
+ private _excludedProps?;
56
+ /**
57
+ * @param Editor The editor class.
58
+ * @param watchdogConfig The watchdog plugin configuration.
59
+ */
60
+ constructor(Editor: {
61
+ create(...args: any): Promise<TEditor>;
62
+ } | null, watchdogConfig?: WatchdogConfig);
63
+ /**
64
+ * The current editor instance.
65
+ */
66
+ get editor(): TEditor | null;
67
+ /**
68
+ * @internal
69
+ */
70
+ get _item(): TEditor | null;
71
+ /**
72
+ * Sets the function that is responsible for the editor creation.
73
+ * It expects a function that should return a promise.
74
+ *
75
+ * ```ts
76
+ * watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
77
+ * ```
78
+ */
79
+ setCreator(creator: EditorCreatorFunction<TEditor>): void;
80
+ /**
81
+ * Sets the function that is responsible for the editor destruction.
82
+ * Overrides the default destruction function, which destroys only the editor instance.
83
+ * It expects a function that should return a promise or `undefined`.
84
+ *
85
+ * ```ts
86
+ * watchdog.setDestructor( editor => {
87
+ * // Do something before the editor is destroyed.
88
+ *
89
+ * return editor
90
+ * .destroy()
91
+ * .then( () => {
92
+ * // Do something after the editor is destroyed.
93
+ * } );
94
+ * } );
95
+ * ```
96
+ */
97
+ setDestructor(destructor: (editor: Editor) => Promise<unknown>): void;
98
+ /**
99
+ * Restarts the editor instance. This method is called whenever an editor error occurs. It fires the `restart` event and changes
100
+ * the state to `initializing`.
101
+ *
102
+ * @fires restart
103
+ */
104
+ protected _restart(): Promise<unknown>;
105
+ /**
106
+ * Creates the editor instance and keeps it running, using the defined creator and destructor.
107
+ *
108
+ * @param elementOrData The editor source element or the editor data.
109
+ * @param config The editor configuration.
110
+ * @param context A context for the editor.
111
+ */
112
+ create(elementOrData?: HTMLElement | string | Record<string, string>, config?: EditorConfig, context?: Context): Promise<unknown>;
113
+ /**
114
+ * Destroys the watchdog and the current editor instance. It fires the callback
115
+ * registered in {@link #setDestructor `setDestructor()`} and uses it to destroy the editor instance.
116
+ * It also sets the state to `destroyed`.
117
+ */
118
+ destroy(): Promise<unknown>;
119
+ private _destroy;
120
+ /**
121
+ * Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at
122
+ * the moment of the crash.
123
+ */
124
+ private _save;
125
+ /**
126
+ * @internal
127
+ */
128
+ _setExcludedProperties(props: Set<unknown>): void;
129
+ /**
130
+ * Returns the editor data.
131
+ */
132
+ private _getData;
133
+ /**
134
+ * Traverses the error context and the current editor to find out whether these structures are connected
135
+ * to each other via properties.
136
+ *
137
+ * @internal
138
+ */
139
+ _isErrorComingFromThisItem(error: CKEditorError): boolean;
140
+ /**
141
+ * Clones the editor configuration.
142
+ */
143
+ private _cloneEditorConfiguration;
144
+ }
145
+ /**
146
+ * Fired after the watchdog restarts the error in case of a crash.
147
+ *
148
+ * @eventName ~EditorWatchdog#restart
149
+ */
150
+ export type EditorWatchdogRestartEvent = {
151
+ name: 'restart';
152
+ args: [];
153
+ return: undefined;
154
+ };
155
+ export type EditorCreatorFunction<TEditor = Editor> = (elementOrData: HTMLElement | string | Record<string, string>, config: EditorConfig) => Promise<TEditor>;