@ckeditor/ckeditor5-autosave 48.8.1-alpha.4 → 49.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.
Files changed (157) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/augmentation.d.ts +16 -16
  3. package/dist/autosave.d.ts +216 -216
  4. package/dist/index-content.css +3 -0
  5. package/dist/index-content.css.map +1 -0
  6. package/dist/index-editor.css +3 -0
  7. package/dist/index-editor.css.map +1 -0
  8. package/dist/index.d.ts +7 -7
  9. package/dist/index.js +224 -244
  10. package/dist/index.js.map +1 -1
  11. package/dist/translations/af.js +1 -1
  12. package/dist/translations/af.umd.js +5 -3
  13. package/dist/translations/ar.js +1 -1
  14. package/dist/translations/ar.umd.js +5 -3
  15. package/dist/translations/ast.js +1 -1
  16. package/dist/translations/ast.umd.js +5 -3
  17. package/dist/translations/az.js +1 -1
  18. package/dist/translations/az.umd.js +5 -3
  19. package/dist/translations/be.js +1 -1
  20. package/dist/translations/be.umd.js +5 -3
  21. package/dist/translations/bg.js +1 -1
  22. package/dist/translations/bg.umd.js +5 -3
  23. package/dist/translations/bn.js +1 -1
  24. package/dist/translations/bn.umd.js +5 -3
  25. package/dist/translations/bs.js +1 -1
  26. package/dist/translations/bs.umd.js +5 -3
  27. package/dist/translations/ca.js +1 -1
  28. package/dist/translations/ca.umd.js +5 -3
  29. package/dist/translations/cs.js +1 -1
  30. package/dist/translations/cs.umd.js +5 -3
  31. package/dist/translations/da.js +1 -1
  32. package/dist/translations/da.umd.js +5 -3
  33. package/dist/translations/de-ch.js +1 -1
  34. package/dist/translations/de-ch.umd.js +5 -3
  35. package/dist/translations/de.js +1 -1
  36. package/dist/translations/de.umd.js +5 -3
  37. package/dist/translations/el.js +1 -1
  38. package/dist/translations/el.umd.js +5 -3
  39. package/dist/translations/en-au.js +1 -1
  40. package/dist/translations/en-au.umd.js +5 -3
  41. package/dist/translations/en-gb.js +1 -1
  42. package/dist/translations/en-gb.umd.js +5 -3
  43. package/dist/translations/en.js +1 -1
  44. package/dist/translations/en.umd.js +5 -3
  45. package/dist/translations/eo.js +1 -1
  46. package/dist/translations/eo.umd.js +5 -3
  47. package/dist/translations/es-co.js +1 -1
  48. package/dist/translations/es-co.umd.js +5 -3
  49. package/dist/translations/es.js +1 -1
  50. package/dist/translations/es.umd.js +5 -3
  51. package/dist/translations/et.js +1 -1
  52. package/dist/translations/et.umd.js +5 -3
  53. package/dist/translations/eu.js +1 -1
  54. package/dist/translations/eu.umd.js +5 -3
  55. package/dist/translations/fa.js +1 -1
  56. package/dist/translations/fa.umd.js +5 -3
  57. package/dist/translations/fi.js +1 -1
  58. package/dist/translations/fi.umd.js +5 -3
  59. package/dist/translations/fr.js +1 -1
  60. package/dist/translations/fr.umd.js +5 -3
  61. package/dist/translations/gl.js +1 -1
  62. package/dist/translations/gl.umd.js +5 -3
  63. package/dist/translations/gu.js +1 -1
  64. package/dist/translations/gu.umd.js +5 -3
  65. package/dist/translations/he.js +1 -1
  66. package/dist/translations/he.umd.js +5 -3
  67. package/dist/translations/hi.js +1 -1
  68. package/dist/translations/hi.umd.js +5 -3
  69. package/dist/translations/hr.js +1 -1
  70. package/dist/translations/hr.umd.js +5 -3
  71. package/dist/translations/hu.js +1 -1
  72. package/dist/translations/hu.umd.js +5 -3
  73. package/dist/translations/hy.js +1 -1
  74. package/dist/translations/hy.umd.js +5 -3
  75. package/dist/translations/id.js +1 -1
  76. package/dist/translations/id.umd.js +5 -3
  77. package/dist/translations/it.js +1 -1
  78. package/dist/translations/it.umd.js +5 -3
  79. package/dist/translations/ja.js +1 -1
  80. package/dist/translations/ja.umd.js +5 -3
  81. package/dist/translations/jv.js +1 -1
  82. package/dist/translations/jv.umd.js +5 -3
  83. package/dist/translations/kk.js +1 -1
  84. package/dist/translations/kk.umd.js +5 -3
  85. package/dist/translations/km.js +1 -1
  86. package/dist/translations/km.umd.js +5 -3
  87. package/dist/translations/kn.js +1 -1
  88. package/dist/translations/kn.umd.js +5 -3
  89. package/dist/translations/ko.js +1 -1
  90. package/dist/translations/ko.umd.js +5 -3
  91. package/dist/translations/ku.js +1 -1
  92. package/dist/translations/ku.umd.js +5 -3
  93. package/dist/translations/lt.js +1 -1
  94. package/dist/translations/lt.umd.js +5 -3
  95. package/dist/translations/lv.js +1 -1
  96. package/dist/translations/lv.umd.js +5 -3
  97. package/dist/translations/ms.js +1 -1
  98. package/dist/translations/ms.umd.js +5 -3
  99. package/dist/translations/nb.js +1 -1
  100. package/dist/translations/nb.umd.js +5 -3
  101. package/dist/translations/ne.js +1 -1
  102. package/dist/translations/ne.umd.js +5 -3
  103. package/dist/translations/nl.js +1 -1
  104. package/dist/translations/nl.umd.js +5 -3
  105. package/dist/translations/no.js +1 -1
  106. package/dist/translations/no.umd.js +5 -3
  107. package/dist/translations/oc.js +1 -1
  108. package/dist/translations/oc.umd.js +5 -3
  109. package/dist/translations/pl.js +1 -1
  110. package/dist/translations/pl.umd.js +5 -3
  111. package/dist/translations/pt-br.js +1 -1
  112. package/dist/translations/pt-br.umd.js +5 -3
  113. package/dist/translations/pt.js +1 -1
  114. package/dist/translations/pt.umd.js +5 -3
  115. package/dist/translations/ro.js +1 -1
  116. package/dist/translations/ro.umd.js +5 -3
  117. package/dist/translations/ru.js +1 -1
  118. package/dist/translations/ru.umd.js +5 -3
  119. package/dist/translations/si.js +1 -1
  120. package/dist/translations/si.umd.js +5 -3
  121. package/dist/translations/sk.js +1 -1
  122. package/dist/translations/sk.umd.js +5 -3
  123. package/dist/translations/sl.js +1 -1
  124. package/dist/translations/sl.umd.js +5 -3
  125. package/dist/translations/sq.js +1 -1
  126. package/dist/translations/sq.umd.js +5 -3
  127. package/dist/translations/sr-latn.js +1 -1
  128. package/dist/translations/sr-latn.umd.js +5 -3
  129. package/dist/translations/sr.js +1 -1
  130. package/dist/translations/sr.umd.js +5 -3
  131. package/dist/translations/sv.js +1 -1
  132. package/dist/translations/sv.umd.js +5 -3
  133. package/dist/translations/th.js +1 -1
  134. package/dist/translations/th.umd.js +5 -3
  135. package/dist/translations/ti.js +1 -1
  136. package/dist/translations/ti.umd.js +5 -3
  137. package/dist/translations/tk.js +1 -1
  138. package/dist/translations/tk.umd.js +5 -3
  139. package/dist/translations/tr.js +1 -1
  140. package/dist/translations/tr.umd.js +5 -3
  141. package/dist/translations/tt.js +1 -1
  142. package/dist/translations/tt.umd.js +5 -3
  143. package/dist/translations/ug.js +1 -1
  144. package/dist/translations/ug.umd.js +5 -3
  145. package/dist/translations/uk.js +1 -1
  146. package/dist/translations/uk.umd.js +5 -3
  147. package/dist/translations/ur.js +1 -1
  148. package/dist/translations/ur.umd.js +5 -3
  149. package/dist/translations/uz.js +1 -1
  150. package/dist/translations/uz.umd.js +5 -3
  151. package/dist/translations/vi.js +1 -1
  152. package/dist/translations/vi.umd.js +5 -3
  153. package/dist/translations/zh-cn.js +1 -1
  154. package/dist/translations/zh-cn.umd.js +5 -3
  155. package/dist/translations/zh.js +1 -1
  156. package/dist/translations/zh.umd.js +5 -3
  157. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -2,251 +2,231 @@
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- import { Plugin, PendingActions } from '@ckeditor/ckeditor5-core/dist/index.js';
6
- import { DomEmitterMixin } from '@ckeditor/ckeditor5-utils/dist/index.js';
7
- import { debounce } from 'es-toolkit/compat';
5
+ import { PendingActions, Plugin } from "@ckeditor/ckeditor5-core";
6
+ import { DomEmitterMixin } from "@ckeditor/ckeditor5-utils";
7
+ import { debounce } from "es-toolkit/compat";
8
8
 
9
9
  /**
10
- * The {@link module:autosave/autosave~Autosave} plugin allows you to automatically save the data (e.g. send it to the server)
11
- * when needed (when the user changed the content).
12
- *
13
- * It listens to the {@link module:engine/model/document~ModelDocument#event:change:data `editor.model.document#change:data`}
14
- * and `window#beforeunload` events and calls the
15
- * {@link module:autosave/autosave~AutosaveAdapter#save `config.autosave.save()`} function.
16
- *
17
- * ```ts
18
- * ClassicEditor
19
- * .create( {
20
- * attachTo: document.querySelector( '#editor' ),
21
- * plugins: [ ArticlePluginSet, Autosave ],
22
- * toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
23
- * image: {
24
- * toolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],
25
- * },
26
- * autosave: {
27
- * save( editor: Editor ) {
28
- * // The saveData() function must return a promise
29
- * // which should be resolved when the data is successfully saved.
30
- * return saveData( editor.getData() );
31
- * }
32
- * }
33
- * } );
34
- * ```
35
- *
36
- * Read more about this feature in the {@glink features/autosave Autosave} feature guide.
37
- */ class Autosave extends Plugin {
38
- /**
39
- * The adapter is an object with a `save()` method. That method will be called whenever
40
- * the data changes. It might be called some time after the change,
41
- * since the event is throttled for performance reasons.
42
- */ adapter;
43
- /**
44
- * Debounced save method. The `save()` method is called the specified `waitingTime` after `debouncedSave()` is called,
45
- * unless a new action happens in the meantime.
46
- */ _debouncedSave;
47
- /**
48
- * The last saved document version.
49
- */ _lastDocumentVersion;
50
- /**
51
- * Promise used for asynchronous save calls.
52
- *
53
- * Created to handle the autosave call to an external data source. It resolves when that call is finished. It is re-used if
54
- * save is called before the promise has been resolved. It is set to `null` if there is no call in progress.
55
- */ _savePromise;
56
- /**
57
- * DOM emitter.
58
- */ _domEmitter;
59
- /**
60
- * The configuration of this plugins.
61
- */ _config;
62
- /**
63
- * Editor's pending actions manager.
64
- */ _pendingActions;
65
- /**
66
- * Informs whether there should be another autosave callback performed, immediately after current autosave callback finishes.
67
- *
68
- * This is set to `true` when there is a save request while autosave callback is already being processed
69
- * and the model has changed since the last save.
70
- */ _makeImmediateSave;
71
- /**
72
- * An action that will be added to the pending action manager for actions happening in that plugin.
73
- */ _action = null;
74
- /**
75
- * @inheritDoc
76
- */ static get pluginName() {
77
- return 'Autosave';
78
- }
79
- /**
80
- * @inheritDoc
81
- */ static get isOfficialPlugin() {
82
- return true;
83
- }
84
- /**
85
- * @inheritDoc
86
- */ static get requires() {
87
- return [
88
- PendingActions
89
- ];
90
- }
91
- /**
92
- * @inheritDoc
93
- */ constructor(editor){
94
- super(editor);
95
- const config = editor.config.get('autosave') || {};
96
- // A minimum amount of time that needs to pass after the last action.
97
- // After that time the provided save callbacks are being called.
98
- const waitingTime = config.waitingTime || 1000;
99
- this.set('state', 'synchronized');
100
- this._debouncedSave = debounce(this._save.bind(this), waitingTime);
101
- this._lastDocumentVersion = editor.model.document.version;
102
- this._savePromise = null;
103
- this._domEmitter = new (DomEmitterMixin())();
104
- this._config = config;
105
- this._pendingActions = editor.plugins.get(PendingActions);
106
- this._makeImmediateSave = false;
107
- }
108
- /**
109
- * @inheritDoc
110
- */ init() {
111
- const editor = this.editor;
112
- const doc = editor.model.document;
113
- // Add the listener only after the editor is initialized to prevent firing save callback on data init.
114
- this.listenTo(editor, 'ready', ()=>{
115
- this.listenTo(doc, 'change:data', (evt, batch)=>{
116
- if (!this._saveCallbacks.length) {
117
- return;
118
- }
119
- if (!batch.isLocal) {
120
- return;
121
- }
122
- if (this.state === 'synchronized') {
123
- this.state = 'waiting';
124
- // Set pending action already when we are waiting for the autosave callback.
125
- this._setPendingAction();
126
- }
127
- if (this.state === 'waiting') {
128
- this._debouncedSave();
129
- }
130
- // If the plugin is in `saving` state, it will change its state later basing on the `document.version`.
131
- // If the `document.version` will be higher than stored `#_lastDocumentVersion`, then it means, that some `change:data`
132
- // event has fired in the meantime.
133
- });
134
- });
135
- // Flush on the editor's destroy listener with the highest priority to ensure that
136
- // `editor.getData()` will be called before plugins are destroyed.
137
- this.listenTo(editor, 'destroy', ()=>this._flush(), {
138
- priority: 'highest'
139
- });
140
- // It's not possible to easy test it because karma uses `beforeunload` event
141
- // to warn before full page reload and this event cannot be dispatched manually.
142
- /* istanbul ignore next -- @preserve */ this._domEmitter.listenTo(window, 'beforeunload', (evtInfo, domEvt)=>{
143
- if (this._pendingActions.hasAny) {
144
- domEvt.returnValue = this._pendingActions.first.message;
145
- }
146
- });
147
- }
148
- /**
149
- * @inheritDoc
150
- */ destroy() {
151
- // There's no need for canceling or flushing the throttled save, as
152
- // it's done on the editor's destroy event with the highest priority.
153
- this._domEmitter.stopListening();
154
- super.destroy();
155
- }
156
- /**
157
- * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave
158
- * callback in progress, then the requested save will be performed immediately after the current callback finishes.
159
- *
160
- * @returns A promise that will be resolved when the autosave callback is finished.
161
- */ save() {
162
- this._debouncedSave.cancel();
163
- return this._save();
164
- }
165
- /**
166
- * Invokes the remaining `_save()` method call.
167
- */ _flush() {
168
- this._debouncedSave.flush();
169
- }
170
- /**
171
- * If the adapter is set and a new document version exists,
172
- * the `_save()` method creates a pending action and calls the `adapter.save()` method.
173
- * It waits for the result and then removes the created pending action.
174
- *
175
- * @returns A promise that will be resolved when the autosave callback is finished.
176
- */ _save() {
177
- if (this._savePromise) {
178
- this._makeImmediateSave = this.editor.model.document.version > this._lastDocumentVersion;
179
- return this._savePromise;
180
- }
181
- // Make sure there is a pending action (in case if `_save()` was called through manual `save()` call).
182
- this._setPendingAction();
183
- this.state = 'saving';
184
- this._lastDocumentVersion = this.editor.model.document.version;
185
- // Wait one promise cycle to be sure that save callbacks are not called inside a conversion or when the editor's state changes.
186
- this._savePromise = Promise.resolve()// Make autosave callback.
187
- .then(()=>Promise.all(this._saveCallbacks.map((cb)=>cb(this.editor))))// When the autosave callback is finished, always clear `this._savePromise`, no matter if it was successful or not.
188
- .finally(()=>{
189
- this._savePromise = null;
190
- })// If the save was successful, we have three scenarios:
191
- //
192
- // 1. If a save was requested when an autosave callback was already processed, we need to immediately call
193
- // another autosave callback. In this case, `this._savePromise` will not be resolved until the next callback is done.
194
- // 2. Otherwise, if changes happened to the model, make a delayed autosave callback (like the change just happened).
195
- // 3. If no changes happened to the model, return to the `synchronized` state.
196
- .then(()=>{
197
- if (this._makeImmediateSave) {
198
- this._makeImmediateSave = false;
199
- // Start another autosave callback. Return a promise that will be resolved after the new autosave callback.
200
- // This way promises returned by `_save()` will not be resolved until all changes are saved.
201
- //
202
- // If `save()` was called when another (most often automatic) autosave callback was already processed,
203
- // the promise returned by `save()` call will be resolved only after new changes have been saved.
204
- //
205
- // Note that it would not work correctly if `this._savePromise` is not cleared.
206
- return this._save();
207
- } else {
208
- if (this.editor.model.document.version > this._lastDocumentVersion) {
209
- this.state = 'waiting';
210
- this._debouncedSave();
211
- } else {
212
- this.state = 'synchronized';
213
- this._pendingActions.remove(this._action);
214
- this._action = null;
215
- }
216
- }
217
- })// In case of an error, retry the autosave callback after a delay (and also throw the original error).
218
- .catch((err)=>{
219
- // Change state to `error` so that listeners handling autosave error can be called.
220
- this.state = 'error';
221
- // Then, immediately change to the `saving` state as described above.
222
- // Being in the `saving` state ensures that the autosave callback won't be delayed further by the `change:data` listener.
223
- this.state = 'saving';
224
- this._debouncedSave();
225
- throw err;
226
- });
227
- return this._savePromise;
228
- }
229
- /**
230
- * Creates a pending action if it is not set already.
231
- */ _setPendingAction() {
232
- const t = this.editor.t;
233
- if (!this._action) {
234
- this._action = this._pendingActions.add(t('Saving changes'));
235
- }
236
- }
237
- /**
238
- * Saves callbacks.
239
- */ get _saveCallbacks() {
240
- const saveCallbacks = [];
241
- if (this.adapter && this.adapter.save) {
242
- saveCallbacks.push(this.adapter.save);
243
- }
244
- if (this._config.save) {
245
- saveCallbacks.push(this._config.save);
246
- }
247
- return saveCallbacks;
248
- }
249
- }
10
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
11
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
12
+ */
13
+ /**
14
+ * @module autosave/autosave
15
+ */
16
+ /**
17
+ * The {@link module:autosave/autosave~Autosave} plugin allows you to automatically save the data (e.g. send it to the server)
18
+ * when needed (when the user changed the content).
19
+ *
20
+ * It listens to the {@link module:engine/model/document~ModelDocument#event:change:data `editor.model.document#change:data`}
21
+ * and `window#beforeunload` events and calls the
22
+ * {@link module:autosave/autosave~AutosaveAdapter#save `config.autosave.save()`} function.
23
+ *
24
+ * ```ts
25
+ * ClassicEditor
26
+ * .create( {
27
+ * attachTo: document.querySelector( '#editor' ),
28
+ * plugins: [ ArticlePluginSet, Autosave ],
29
+ * toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
30
+ * image: {
31
+ * toolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],
32
+ * },
33
+ * autosave: {
34
+ * save( editor: Editor ) {
35
+ * // The saveData() function must return a promise
36
+ * // which should be resolved when the data is successfully saved.
37
+ * return saveData( editor.getData() );
38
+ * }
39
+ * }
40
+ * } );
41
+ * ```
42
+ *
43
+ * Read more about this feature in the {@glink features/autosave Autosave} feature guide.
44
+ */
45
+ var Autosave = class extends Plugin {
46
+ /**
47
+ * The adapter is an object with a `save()` method. That method will be called whenever
48
+ * the data changes. It might be called some time after the change,
49
+ * since the event is throttled for performance reasons.
50
+ */
51
+ adapter;
52
+ /**
53
+ * Debounced save method. The `save()` method is called the specified `waitingTime` after `debouncedSave()` is called,
54
+ * unless a new action happens in the meantime.
55
+ */
56
+ _debouncedSave;
57
+ /**
58
+ * The last saved document version.
59
+ */
60
+ _lastDocumentVersion;
61
+ /**
62
+ * Promise used for asynchronous save calls.
63
+ *
64
+ * Created to handle the autosave call to an external data source. It resolves when that call is finished. It is re-used if
65
+ * save is called before the promise has been resolved. It is set to `null` if there is no call in progress.
66
+ */
67
+ _savePromise;
68
+ /**
69
+ * DOM emitter.
70
+ */
71
+ _domEmitter;
72
+ /**
73
+ * The configuration of this plugins.
74
+ */
75
+ _config;
76
+ /**
77
+ * Editor's pending actions manager.
78
+ */
79
+ _pendingActions;
80
+ /**
81
+ * Informs whether there should be another autosave callback performed, immediately after current autosave callback finishes.
82
+ *
83
+ * This is set to `true` when there is a save request while autosave callback is already being processed
84
+ * and the model has changed since the last save.
85
+ */
86
+ _makeImmediateSave;
87
+ /**
88
+ * An action that will be added to the pending action manager for actions happening in that plugin.
89
+ */
90
+ _action = null;
91
+ /**
92
+ * @inheritDoc
93
+ */
94
+ static get pluginName() {
95
+ return "Autosave";
96
+ }
97
+ /**
98
+ * @inheritDoc
99
+ */
100
+ static get isOfficialPlugin() {
101
+ return true;
102
+ }
103
+ /**
104
+ * @inheritDoc
105
+ */
106
+ static get requires() {
107
+ return [PendingActions];
108
+ }
109
+ /**
110
+ * @inheritDoc
111
+ */
112
+ constructor(editor) {
113
+ super(editor);
114
+ const config = editor.config.get("autosave") || {};
115
+ const waitingTime = config.waitingTime || 1e3;
116
+ this.set("state", "synchronized");
117
+ this._debouncedSave = debounce(this._save.bind(this), waitingTime);
118
+ this._lastDocumentVersion = editor.model.document.version;
119
+ this._savePromise = null;
120
+ this._domEmitter = new (DomEmitterMixin())();
121
+ this._config = config;
122
+ this._pendingActions = editor.plugins.get(PendingActions);
123
+ this._makeImmediateSave = false;
124
+ }
125
+ /**
126
+ * @inheritDoc
127
+ */
128
+ init() {
129
+ const editor = this.editor;
130
+ const doc = editor.model.document;
131
+ this.listenTo(editor, "ready", () => {
132
+ this.listenTo(doc, "change:data", (evt, batch) => {
133
+ if (!this._saveCallbacks.length) return;
134
+ if (!batch.isLocal) return;
135
+ if (this.state === "synchronized") {
136
+ this.state = "waiting";
137
+ this._setPendingAction();
138
+ }
139
+ if (this.state === "waiting") this._debouncedSave();
140
+ });
141
+ });
142
+ this.listenTo(editor, "destroy", () => this._flush(), { priority: "highest" });
143
+ /* v8 ignore next -- @preserve */
144
+ this._domEmitter.listenTo(window, "beforeunload", (evtInfo, domEvt) => {
145
+ if (this._pendingActions.hasAny) domEvt.returnValue = this._pendingActions.first.message;
146
+ });
147
+ }
148
+ /**
149
+ * @inheritDoc
150
+ */
151
+ destroy() {
152
+ this._domEmitter.stopListening();
153
+ super.destroy();
154
+ }
155
+ /**
156
+ * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave
157
+ * callback in progress, then the requested save will be performed immediately after the current callback finishes.
158
+ *
159
+ * @returns A promise that will be resolved when the autosave callback is finished.
160
+ */
161
+ save() {
162
+ this._debouncedSave.cancel();
163
+ return this._save();
164
+ }
165
+ /**
166
+ * Invokes the remaining `_save()` method call.
167
+ */
168
+ _flush() {
169
+ this._debouncedSave.flush();
170
+ }
171
+ /**
172
+ * If the adapter is set and a new document version exists,
173
+ * the `_save()` method creates a pending action and calls the `adapter.save()` method.
174
+ * It waits for the result and then removes the created pending action.
175
+ *
176
+ * @returns A promise that will be resolved when the autosave callback is finished.
177
+ */
178
+ _save() {
179
+ if (this._savePromise) {
180
+ this._makeImmediateSave = this.editor.model.document.version > this._lastDocumentVersion;
181
+ return this._savePromise;
182
+ }
183
+ this._setPendingAction();
184
+ this.state = "saving";
185
+ this._lastDocumentVersion = this.editor.model.document.version;
186
+ this._savePromise = Promise.resolve().then(() => Promise.all(this._saveCallbacks.map((cb) => cb(this.editor)))).finally(() => {
187
+ this._savePromise = null;
188
+ }).then(() => {
189
+ if (this._makeImmediateSave) {
190
+ this._makeImmediateSave = false;
191
+ return this._save();
192
+ } else if (this.editor.model.document.version > this._lastDocumentVersion) {
193
+ this.state = "waiting";
194
+ this._debouncedSave();
195
+ } else {
196
+ this.state = "synchronized";
197
+ this._pendingActions.remove(this._action);
198
+ this._action = null;
199
+ }
200
+ }).catch((err) => {
201
+ this.state = "error";
202
+ this.state = "saving";
203
+ this._debouncedSave();
204
+ throw err;
205
+ });
206
+ return this._savePromise;
207
+ }
208
+ /**
209
+ * Creates a pending action if it is not set already.
210
+ */
211
+ _setPendingAction() {
212
+ const t = this.editor.t;
213
+ if (!this._action) this._action = this._pendingActions.add(t("Saving changes"));
214
+ }
215
+ /**
216
+ * Saves callbacks.
217
+ */
218
+ get _saveCallbacks() {
219
+ const saveCallbacks = [];
220
+ if (this.adapter && this.adapter.save) saveCallbacks.push(this.adapter.save);
221
+ if (this._config.save) saveCallbacks.push(this._config.save);
222
+ return saveCallbacks;
223
+ }
224
+ };
225
+
226
+ /**
227
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
228
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
229
+ */
250
230
 
251
231
  export { Autosave };
252
- //# sourceMappingURL=index.js.map
232
+ //# sourceMappingURL=index.js.map