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