@ckeditor/ckeditor5-autosave 38.0.1 → 38.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/build/autosave.js CHANGED
@@ -2,4 +2,4 @@
2
2
  /*!
3
3
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
4
4
  * For licensing, see LICENSE.md.
5
- */(()=>{var t={704:(t,e,i)=>{t.exports=i(79)("./src/core.js")},209:(t,e,i)=>{t.exports=i(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(n){var s=e[n];if(void 0!==s)return s.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";i.r(n),i.d(n,{Autosave:()=>D});var t=i(704),e=i(209);const s=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};const o="object"==typeof global&&global&&global.Object===Object&&global;var r="object"==typeof self&&self&&self.Object===Object&&self;const a=o||r||Function("return this")();const c=function(){return a.Date.now()};var u=/\s/;const l=function(t){for(var e=t.length;e--&&u.test(t.charAt(e)););return e};var d=/^\s+/;const h=function(t){return t?t.slice(0,l(t)+1).replace(d,""):t};const v=a.Symbol;var f=Object.prototype,m=f.hasOwnProperty,g=f.toString,_=v?v.toStringTag:void 0;const p=function(t){var e=m.call(t,_),i=t[_];try{t[_]=void 0;var n=!0}catch(t){}var s=g.call(t);return n&&(e?t[_]=i:delete t[_]),s};var b=Object.prototype.toString;const y=function(t){return b.call(t)};var S=v?v.toStringTag:void 0;const T=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":S&&S in Object(t)?p(t):y(t)};const j=function(t){return null!=t&&"object"==typeof t};const w=function(t){return"symbol"==typeof t||j(t)&&"[object Symbol]"==T(t)};var O=/^[-+]0x[0-9a-f]+$/i,P=/^0b[01]+$/i,A=/^0o[0-7]+$/i,x=parseInt;const E=function(t){if("number"==typeof t)return t;if(w(t))return NaN;if(s(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=s(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=h(t);var i=P.test(t);return i||A.test(t)?x(t.slice(2),i?2:8):O.test(t)?NaN:+t};var N=Math.max,I=Math.min;const C=function(t,e,i){var n,o,r,a,u,l,d=0,h=!1,v=!1,f=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function m(e){var i=n,s=o;return n=o=void 0,d=e,a=t.apply(s,i)}function g(t){var i=t-l;return void 0===l||i>=e||i<0||v&&t-d>=r}function _(){var t=c();if(g(t))return p(t);u=setTimeout(_,function(t){var i=e-(t-l);return v?I(i,r-(t-d)):i}(t))}function p(t){return u=void 0,f&&n?m(t):(n=o=void 0,a)}function b(){var t=c(),i=g(t);if(n=arguments,o=this,l=t,i){if(void 0===u)return function(t){return d=t,u=setTimeout(_,e),h?m(t):a}(l);if(v)return clearTimeout(u),u=setTimeout(_,e),m(l)}return void 0===u&&(u=setTimeout(_,e)),a}return e=E(e)||0,s(i)&&(h=!!i.leading,r=(v="maxWait"in i)?N(E(i.maxWait)||0,e):r,f="trailing"in i?!!i.trailing:f),b.cancel=function(){void 0!==u&&clearTimeout(u),d=0,n=l=o=u=void 0},b.flush=function(){return void 0===u?a:p(c())},b};class D extends t.Plugin{constructor(i){super(i),this._action=null;const n=i.config.get("autosave")||{},s=n.waitingTime||1e3;this.set("state","synchronized"),this._debouncedSave=C(this._save.bind(this),s),this._lastDocumentVersion=i.model.document.version,this._savePromise=null,this._domEmitter=new((0,e.DomEmitterMixin)()),this._config=n,this._pendingActions=i.plugins.get(t.PendingActions),this._makeImmediateSave=!1}static get pluginName(){return"Autosave"}static get requires(){return[t.PendingActions]}init(){const t=this.editor,e=t.model.document;this.listenTo(t,"ready",(()=>{this.listenTo(e,"change:data",((t,e)=>{this._saveCallbacks.length&&e.isLocal&&("synchronized"===this.state&&(this.state="waiting",this._setPendingAction()),"waiting"===this.state&&this._debouncedSave())}))})),this.listenTo(t,"destroy",(()=>this._flush()),{priority:"highest"}),this._domEmitter.listenTo(window,"beforeunload",((t,e)=>{this._pendingActions.hasAny&&(e.returnValue=this._pendingActions.first.message)}))}destroy(){this._domEmitter.stopListening(),super.destroy()}save(){return this._debouncedSave.cancel(),this._save()}_flush(){this._debouncedSave.flush()}_save(){return this._savePromise?(this._makeImmediateSave=this.editor.model.document.version>this._lastDocumentVersion,this._savePromise):(this._setPendingAction(),this.state="saving",this._lastDocumentVersion=this.editor.model.document.version,this._savePromise=Promise.resolve().then((()=>Promise.all(this._saveCallbacks.map((t=>t(this.editor)))))).finally((()=>{this._savePromise=null})).then((()=>{if(this._makeImmediateSave)return this._makeImmediateSave=!1,this._save();this.editor.model.document.version>this._lastDocumentVersion?(this.state="waiting",this._debouncedSave()):(this.state="synchronized",this._pendingActions.remove(this._action),this._action=null)})).catch((t=>{throw this.state="error",this.state="saving",this._debouncedSave(),t})),this._savePromise)}_setPendingAction(){const t=this.editor.t;this._action||(this._action=this._pendingActions.add(t("Saving changes")))}get _saveCallbacks(){const t=[];return this.adapter&&this.adapter.save&&t.push(this.adapter.save),this._config.save&&t.push(this._config.save),t}}})(),(window.CKEditor5=window.CKEditor5||{}).autosave=n})();
5
+ */(()=>{var t={704:(t,e,i)=>{t.exports=i(79)("./src/core.js")},209:(t,e,i)=>{t.exports=i(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(n){var s=e[n];if(void 0!==s)return s.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";i.r(n),i.d(n,{Autosave:()=>D});var t=i(704),e=i(209);const s=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};const o="object"==typeof global&&global&&global.Object===Object&&global;var r="object"==typeof self&&self&&self.Object===Object&&self;const a=o||r||Function("return this")();const c=function(){return a.Date.now()};var u=/\s/;const l=function(t){for(var e=t.length;e--&&u.test(t.charAt(e)););return e};var d=/^\s+/;const h=function(t){return t?t.slice(0,l(t)+1).replace(d,""):t};const v=a.Symbol;var f=Object.prototype,m=f.hasOwnProperty,g=f.toString,_=v?v.toStringTag:void 0;const p=function(t){var e=m.call(t,_),i=t[_];try{t[_]=void 0;var n=!0}catch(t){}var s=g.call(t);return n&&(e?t[_]=i:delete t[_]),s};var b=Object.prototype.toString;const y=function(t){return b.call(t)};var S=v?v.toStringTag:void 0;const T=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":S&&S in Object(t)?p(t):y(t)};const j=function(t){return null!=t&&"object"==typeof t};const w=function(t){return"symbol"==typeof t||j(t)&&"[object Symbol]"==T(t)};var O=/^[-+]0x[0-9a-f]+$/i,P=/^0b[01]+$/i,A=/^0o[0-7]+$/i,x=parseInt;const E=function(t){if("number"==typeof t)return t;if(w(t))return NaN;if(s(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=s(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=h(t);var i=P.test(t);return i||A.test(t)?x(t.slice(2),i?2:8):O.test(t)?NaN:+t};var N=Math.max,I=Math.min;const C=function(t,e,i){var n,o,r,a,u,l,d=0,h=!1,v=!1,f=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function m(e){var i=n,s=o;return n=o=void 0,d=e,a=t.apply(s,i)}function g(t){var i=t-l;return void 0===l||i>=e||i<0||v&&t-d>=r}function _(){var t=c();if(g(t))return p(t);u=setTimeout(_,function(t){var i=e-(t-l);return v?I(i,r-(t-d)):i}(t))}function p(t){return u=void 0,f&&n?m(t):(n=o=void 0,a)}function b(){var t=c(),i=g(t);if(n=arguments,o=this,l=t,i){if(void 0===u)return function(t){return d=t,u=setTimeout(_,e),h?m(t):a}(l);if(v)return clearTimeout(u),u=setTimeout(_,e),m(l)}return void 0===u&&(u=setTimeout(_,e)),a}return e=E(e)||0,s(i)&&(h=!!i.leading,r=(v="maxWait"in i)?N(E(i.maxWait)||0,e):r,f="trailing"in i?!!i.trailing:f),b.cancel=function(){void 0!==u&&clearTimeout(u),d=0,n=l=o=u=void 0},b.flush=function(){return void 0===u?a:p(c())},b};class D extends t.Plugin{static get pluginName(){return"Autosave"}static get requires(){return[t.PendingActions]}constructor(i){super(i),this._action=null;const n=i.config.get("autosave")||{},s=n.waitingTime||1e3;this.set("state","synchronized"),this._debouncedSave=C(this._save.bind(this),s),this._lastDocumentVersion=i.model.document.version,this._savePromise=null,this._domEmitter=new((0,e.DomEmitterMixin)()),this._config=n,this._pendingActions=i.plugins.get(t.PendingActions),this._makeImmediateSave=!1}init(){const t=this.editor,e=t.model.document;this.listenTo(t,"ready",(()=>{this.listenTo(e,"change:data",((t,e)=>{this._saveCallbacks.length&&e.isLocal&&("synchronized"===this.state&&(this.state="waiting",this._setPendingAction()),"waiting"===this.state&&this._debouncedSave())}))})),this.listenTo(t,"destroy",(()=>this._flush()),{priority:"highest"}),this._domEmitter.listenTo(window,"beforeunload",((t,e)=>{this._pendingActions.hasAny&&(e.returnValue=this._pendingActions.first.message)}))}destroy(){this._domEmitter.stopListening(),super.destroy()}save(){return this._debouncedSave.cancel(),this._save()}_flush(){this._debouncedSave.flush()}_save(){return this._savePromise?(this._makeImmediateSave=this.editor.model.document.version>this._lastDocumentVersion,this._savePromise):(this._setPendingAction(),this.state="saving",this._lastDocumentVersion=this.editor.model.document.version,this._savePromise=Promise.resolve().then((()=>Promise.all(this._saveCallbacks.map((t=>t(this.editor)))))).finally((()=>{this._savePromise=null})).then((()=>{if(this._makeImmediateSave)return this._makeImmediateSave=!1,this._save();this.editor.model.document.version>this._lastDocumentVersion?(this.state="waiting",this._debouncedSave()):(this.state="synchronized",this._pendingActions.remove(this._action),this._action=null)})).catch((t=>{throw this.state="error",this.state="saving",this._debouncedSave(),t})),this._savePromise)}_setPendingAction(){const t=this.editor.t;this._action||(this._action=this._pendingActions.add(t("Saving changes")))}get _saveCallbacks(){const t=[];return this.adapter&&this.adapter.save&&t.push(this.adapter.save),this._config.save&&t.push(this._config.save),t}}})(),(window.CKEditor5=window.CKEditor5||{}).autosave=n})();
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["webpack://CKEditor5.autosave/./src/autosave.js","webpack://CKEditor5.autosave/delegated \"./src/core.js\" from dll-reference CKEditor5.dll","webpack://CKEditor5.autosave/delegated \"./src/utils.js\" from dll-reference CKEditor5.dll","webpack://CKEditor5.autosave/external var \"CKEditor5.dll\"","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_Symbol.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_baseGetTag.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_baseTrim.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_freeGlobal.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_getRawTag.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_objectToString.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_root.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/_trimmedEndIndex.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/debounce.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/isObject.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/isObjectLike.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/isSymbol.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/now.js","webpack://CKEditor5.autosave/javascript/node_modules/lodash-es/toNumber.js","webpack://CKEditor5.autosave/webpack/bootstrap","webpack://CKEditor5.autosave/webpack/runtime/define property getters","webpack://CKEditor5.autosave/webpack/runtime/hasOwnProperty shorthand","webpack://CKEditor5.autosave/webpack/runtime/make namespace object","webpack://CKEditor5.autosave/./src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAE4D;AACgB;AACvC;;AAErC;;AAEA;AACA,QAAQ,yCAAyC;AACjD;AACA;AACA,sBAAsB;AACtB;AACA,IAAI,8EAA8E;AAClF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA,wCAAwC;AACxC,mBAAmB,iEAAiE;AACpF;AACA;AACA;AACe,uBAAuB,sDAAM;AAC5C;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,WAAW,8DAAc;AACzB;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,cAAc,0CAA0C;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B,uBAAuB;AACvB,sBAAsB;AACtB;AACA;AACA;AACA;AACA,cAAc,mCAAmC;AACjD;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA,wBAAwB,qDAAQ;;AAEhC;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA,oCAAoC,gEAAe;;AAEnD;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA,cAAc,2CAA2C;AACzD;AACA,6CAA6C,8DAAc;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA,cAAc,QAAQ;AACtB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL,IAAI;;AAEJ;AACA;AACA,2DAA2D,sBAAsB;;AAEjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,cAAc,SAAS;AACvB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,SAAS;AACvB;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,wDAAG,YAAY,gEAAe;;AAE9B;AACA;AACA;AACA,YAAY,gDAAgD;AAC5D;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,WAAW,kCAAkC;AAC7C,aAAa;AACb;;AAEA;AACA,6BAA6B,yDAAyD;AACtF;AACA,iBAAiB,8CAA8C;AAC/D;AACA,YAAY,yCAAyC;AACrD;;AAEA;AACA,6BAA6B,yDAAyD;AACtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,QAAQ,oFAAoF;AAC5F;AACA,6BAA6B,2EAA2E;AACxG;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA,WAAW,kCAAkC;AAC7C,aAAa;AACb;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,YAAY,QAAQ;AACpB;;;;;;;;;;;AC5bA;;;;;;;;;;ACAA;;;;;;;;;;;ACAA;;;;;;;;;;;;;;;;ACA8B;;AAE9B;AACA,aAAa,uDAAW;;AAExB,iEAAe,MAAM,EAAC;;;;;;;;;;;;;;;;;;;ACLY;AACM;AACU;;AAElD;AACA;AACA;;AAEA;AACA,qBAAqB,kDAAM,GAAG,8DAAkB;;AAEhD;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,yDAAS;AACf,MAAM,8DAAc;AACpB;;AAEA,iEAAe,UAAU,EAAC;;;;;;;;;;;;;;;;;AC3B0B;;AAEpD;AACA;;AAEA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa,QAAQ;AACrB;AACA;AACA;AACA,sBAAsB,+DAAe;AACrC;AACA;;AAEA,iEAAe,QAAQ,EAAC;;;;;;;;;;;;;;;;AClBxB;AACA;;AAEA,iEAAe,UAAU,EAAC;;;;;;;;;;;;;;;;;ACHQ;;AAElC;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,qBAAqB,kDAAM,GAAG,8DAAkB;;AAEhD;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,QAAQ;AACrB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;;AAEJ;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;;AAEA,iEAAe,SAAS,EAAC;;;;;;;;;;;;;;;;AC7CzB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,QAAQ;AACrB;AACA;AACA;AACA;;AAEA,iEAAe,cAAc,EAAC;;;;;;;;;;;;;;;;;ACrBY;;AAE1C;AACA;;AAEA;AACA,WAAW,sDAAU;;AAErB,iEAAe,IAAI,EAAC;;;;;;;;;;;;;;;;ACRpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa,QAAQ;AACrB;AACA;AACA;;AAEA;AACA;AACA;;AAEA,iEAAe,eAAe,EAAC;;;;;;;;;;;;;;;;;;;AClBM;AACV;AACU;;AAErC;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,UAAU;AACrB,WAAW,QAAQ;AACnB,WAAW,QAAQ,WAAW;AAC9B,WAAW,SAAS;AACpB;AACA,WAAW,QAAQ;AACnB;AACA,WAAW,SAAS;AACpB;AACA,aAAa,UAAU;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA,+CAA+C,iBAAiB;AAChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS,wDAAQ;AACjB,MAAM,wDAAQ;AACd;AACA;AACA,iCAAiC,wDAAQ;AACzC;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,mDAAG;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,yDAAyD,mDAAG;AAC5D;;AAEA;AACA,eAAe,mDAAG;AAClB;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,iEAAe,QAAQ,EAAC;;;;;;;;;;;;;;;;AC9LxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,SAAS;AACtB;AACA;AACA,gBAAgB;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,iEAAe,QAAQ,EAAC;;;;;;;;;;;;;;;;AC9BxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,SAAS;AACtB;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,iEAAe,YAAY,EAAC;;;;;;;;;;;;;;;;;;AC5Bc;AACG;;AAE7C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,SAAS;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK,4DAAY,WAAW,0DAAU;AACtC;;AAEA,iEAAe,QAAQ,EAAC;;;;;;;;;;;;;;;;;AC5BM;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA,SAAS,yDAAa;AACtB;;AAEA,iEAAe,GAAG,EAAC;;;;;;;;;;;;;;;;;;;ACtBmB;AACD;AACA;;AAErC;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,GAAG;AACd,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,wDAAQ;AACd;AACA;AACA,MAAM,wDAAQ;AACd;AACA,YAAY,wDAAQ;AACpB;AACA;AACA;AACA;AACA,UAAU,wDAAQ;AAClB;AACA;AACA;AACA;AACA;;AAEA,iEAAe,QAAQ,EAAC;;;;;;;UC/DxB;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;ACNA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEiD","file":"autosave.js","sourcesContent":["/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module autosave/autosave\n */\n\nimport { Plugin, PendingActions } from 'ckeditor5/src/core';\nimport { DomEmitterMixin, ObservableMixin, mix } from 'ckeditor5/src/utils';\nimport { debounce } from 'lodash-es';\n\n/* globals window */\n\n/**\n * The {@link module:autosave/autosave~Autosave} plugin allows you to automatically save the data (e.g. send it to the server)\n * when needed (when the user changed the content).\n *\n * It listens to the {@link module:engine/model/document~Document#event:change:data `editor.model.document#change:data`}\n * and `window#beforeunload` events and calls the\n * {@link module:autosave/autosave~AutosaveAdapter#save `config.autosave.save()`} function.\n *\n *\t\tClassicEditor\n *\t\t\t.create( document.querySelector( '#editor' ), {\n *\t\t\t\tplugins: [ ArticlePluginSet, Autosave ],\n *\t\t\t\ttoolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],\n *\t\t\t\timage: {\n *\t\t\t\t\ttoolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],\n *\t\t\t\t},\n *\t\t\t\tautosave: {\n *\t\t\t\t\tsave( editor ) {\n *\t\t\t\t\t\t// The saveData() function must return a promise\n *\t\t\t\t\t\t// which should be resolved when the data is successfully saved.\n *\t\t\t\t\t\treturn saveData( editor.getData() );\n *\t\t\t\t\t}\n *\t\t\t\t}\n *\t\t\t} );\n *\n * Read more about this feature in the {@glink installation/advanced/saving-data#autosave-feature Autosave feature}\n * section of the {@glink installation/advanced/saving-data Saving and getting data}.\n *\n * @extends module:core/plugin~Plugin\n */\nexport default class Autosave extends Plugin {\n\t/**\n\t * @inheritDoc\n\t */\n\tstatic get pluginName() {\n\t\treturn 'Autosave';\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tstatic get requires() {\n\t\treturn [ PendingActions ];\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tconstructor( editor ) {\n\t\tsuper( editor );\n\n\t\tconst config = editor.config.get( 'autosave' ) || {};\n\n\t\t// A minimum amount of time that needs to pass after the last action.\n\t\t// After that time the provided save callbacks are being called.\n\t\tconst waitingTime = config.waitingTime || 1000;\n\n\t\t/**\n\t\t * The adapter is an object with a `save()` method. That method will be called whenever\n\t\t * the data changes. It might be called some time after the change,\n\t\t * since the event is throttled for performance reasons.\n\t\t *\n\t\t * @member {module:autosave/autosave~AutosaveAdapter} #adapter\n\t\t */\n\n\t\t/**\n\t\t * The state of this plugin.\n\t\t *\n\t\t * The plugin can be in the following states:\n\t\t *\n\t\t * * synchronized &ndash; When all changes are saved.\n\t\t * * waiting &ndash; When the plugin is waiting for other changes before calling `adapter#save()` and `config.autosave.save()`.\n\t\t * * saving &ndash; When the provided save method is called and the plugin waits for the response.\n\t\t * * error &ndash When the provided save method will throw an error. This state immediately changes to the `saving` state and\n\t\t * the save method will be called again in the short period of time.\n\t\t *\n\t\t * @readonly\n\t\t * @member {'synchronized'|'waiting'|'saving'} #state\n\t\t */\n\t\tthis.set( 'state', 'synchronized' );\n\n\t\t/**\n\t\t * Debounced save method. The `save()` method is called the specified `waitingTime` after `debouncedSave()` is called,\n\t\t * unless a new action happens in the meantime.\n\t\t *\n\t\t * @private\n\t\t * @type {Function}\n\t\t */\n\t\tthis._debouncedSave = debounce( this._save.bind( this ), waitingTime );\n\n\t\t/**\n\t\t * The last saved document version.\n\t\t *\n\t\t * @private\n\t\t * @type {Number}\n\t\t */\n\t\tthis._lastDocumentVersion = editor.model.document.version;\n\n\t\t/**\n\t\t * Promise used for asynchronous save calls.\n\t\t *\n\t\t * Created to handle the autosave call to an external data source. It resolves when that call is finished. It is re-used if\n\t\t * save is called before the promise has been resolved. It is set to `null` if there is no call in progress.\n\t\t *\n\t\t * @type {Promise|null}\n\t\t * @private\n\t\t */\n\t\tthis._savePromise = null;\n\n\t\t/**\n\t\t * DOM emitter.\n\t\t *\n\t\t * @private\n\t\t * @type {DomEmitterMixin}\n\t\t */\n\t\tthis._domEmitter = Object.create( DomEmitterMixin );\n\n\t\t/**\n\t\t * The configuration of this plugins.\n\t\t *\n\t\t * @private\n\t\t * @type {Object}\n\t\t */\n\t\tthis._config = config;\n\n\t\t/**\n\t\t * Editor's pending actions manager.\n\t\t *\n\t\t * @private\n\t\t * @member {module:core/pendingactions~PendingActions} #_pendingActions\n\t\t */\n\t\tthis._pendingActions = editor.plugins.get( PendingActions );\n\n\t\t/**\n\t\t * Informs whether there should be another autosave callback performed, immediately after current autosave callback finishes.\n\t\t *\n\t\t * This is set to `true` when there is a save request while autosave callback is already being processed\n\t\t * and the model has changed since the last save.\n\t\t *\n\t\t * @private\n\t\t * @type {Boolean}\n\t\t */\n\t\tthis._makeImmediateSave = false;\n\n\t\t/**\n\t\t * An action that will be added to the pending action manager for actions happening in that plugin.\n\t\t *\n\t\t * @private\n\t\t * @member {Object} #_action\n\t\t */\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tinit() {\n\t\tconst editor = this.editor;\n\t\tconst doc = editor.model.document;\n\n\t\t// Add the listener only after the editor is initialized to prevent firing save callback on data init.\n\t\tthis.listenTo( editor, 'ready', () => {\n\t\t\tthis.listenTo( doc, 'change:data', ( evt, batch ) => {\n\t\t\t\tif ( !this._saveCallbacks.length ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( !batch.isLocal ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( this.state === 'synchronized' ) {\n\t\t\t\t\tthis.state = 'waiting';\n\t\t\t\t\t// Set pending action already when we are waiting for the autosave callback.\n\t\t\t\t\tthis._setPendingAction();\n\t\t\t\t}\n\n\t\t\t\tif ( this.state === 'waiting' ) {\n\t\t\t\t\tthis._debouncedSave();\n\t\t\t\t}\n\n\t\t\t\t// If the plugin is in `saving` state, it will change its state later basing on the `document.version`.\n\t\t\t\t// If the `document.version` will be higher than stored `#_lastDocumentVersion`, then it means, that some `change:data`\n\t\t\t\t// event has fired in the meantime.\n\t\t\t} );\n\t\t} );\n\n\t\t// Flush on the editor's destroy listener with the highest priority to ensure that\n\t\t// `editor.getData()` will be called before plugins are destroyed.\n\t\tthis.listenTo( editor, 'destroy', () => this._flush(), { priority: 'highest' } );\n\n\t\t// It's not possible to easy test it because karma uses `beforeunload` event\n\t\t// to warn before full page reload and this event cannot be dispatched manually.\n\t\t/* istanbul ignore next */\n\t\tthis._domEmitter.listenTo( window, 'beforeunload', ( evtInfo, domEvt ) => {\n\t\t\tif ( this._pendingActions.hasAny ) {\n\t\t\t\tdomEvt.returnValue = this._pendingActions.first.message;\n\t\t\t}\n\t\t} );\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tdestroy() {\n\t\t// There's no need for canceling or flushing the throttled save, as\n\t\t// it's done on the editor's destroy event with the highest priority.\n\n\t\tthis._domEmitter.stopListening();\n\t\tsuper.destroy();\n\t}\n\n\t/**\n\t * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave\n\t * callback in progress, then the requested save will be performed immediately after the current callback finishes.\n\t *\n\t * @returns {Promise} A promise that will be resolved when the autosave callback is finished.\n\t */\n\tsave() {\n\t\tthis._debouncedSave.cancel();\n\n\t\treturn this._save();\n\t}\n\n\t/**\n\t * Invokes the remaining `_save()` method call.\n\t *\n\t * @protected\n\t */\n\t_flush() {\n\t\tthis._debouncedSave.flush();\n\t}\n\n\t/**\n\t * If the adapter is set and a new document version exists,\n\t * the `_save()` method creates a pending action and calls the `adapter.save()` method.\n\t * It waits for the result and then removes the created pending action.\n\t *\n\t * @private\n\t * @returns {Promise} A promise that will be resolved when the autosave callback is finished.\n\t */\n\t_save() {\n\t\tif ( this._savePromise ) {\n\t\t\tthis._makeImmediateSave = this.editor.model.document.version > this._lastDocumentVersion;\n\n\t\t\treturn this._savePromise;\n\t\t}\n\n\t\t// Make sure there is a pending action (in case if `_save()` was called through manual `save()` call).\n\t\tthis._setPendingAction();\n\n\t\tthis.state = 'saving';\n\t\tthis._lastDocumentVersion = this.editor.model.document.version;\n\n\t\t// Wait one promise cycle to be sure that save callbacks are not called inside a conversion or when the editor's state changes.\n\t\tthis._savePromise = Promise.resolve()\n\t\t\t// Make autosave callback.\n\t\t\t.then( () => Promise.all(\n\t\t\t\tthis._saveCallbacks.map( cb => cb( this.editor ) )\n\t\t\t) )\n\t\t\t// When the autosave callback is finished, always clear `this._savePromise`, no matter if it was successful or not.\n\t\t\t.finally( () => {\n\t\t\t\tthis._savePromise = null;\n\t\t\t} )\n\t\t\t// If the save was successful, we have three scenarios:\n\t\t\t//\n\t\t\t// 1. If a save was requested when an autosave callback was already processed, we need to immediately call\n\t\t\t// another autosave callback. In this case, `this._savePromise` will not be resolved until the next callback is done.\n\t\t\t// 2. Otherwise, if changes happened to the model, make a delayed autosave callback (like the change just happened).\n\t\t\t// 3. If no changes happened to the model, return to the `synchronized` state.\n\t\t\t.then( () => {\n\t\t\t\tif ( this._makeImmediateSave ) {\n\t\t\t\t\tthis._makeImmediateSave = false;\n\n\t\t\t\t\t// Start another autosave callback. Return a promise that will be resolved after the new autosave callback.\n\t\t\t\t\t// This way promises returned by `_save()` will not be resolved until all changes are saved.\n\t\t\t\t\t//\n\t\t\t\t\t// If `save()` was called when another (most often automatic) autosave callback was already processed,\n\t\t\t\t\t// the promise returned by `save()` call will be resolved only after new changes have been saved.\n\t\t\t\t\t//\n\t\t\t\t\t// Note that it would not work correctly if `this._savePromise` is not cleared.\n\t\t\t\t\treturn this._save();\n\t\t\t\t} else {\n\t\t\t\t\tif ( this.editor.model.document.version > this._lastDocumentVersion ) {\n\t\t\t\t\t\tthis.state = 'waiting';\n\t\t\t\t\t\tthis._debouncedSave();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.state = 'synchronized';\n\t\t\t\t\t\tthis._pendingActions.remove( this._action );\n\t\t\t\t\t\tthis._action = null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} )\n\t\t\t// In case of an error, retry the autosave callback after a delay (and also throw the original error).\n\t\t\t.catch( err => {\n\t\t\t\t// Change state to `error` so that listeners handling autosave error can be called.\n\t\t\t\tthis.state = 'error';\n\t\t\t\t// Then, immediately change to the `saving` state as described above.\n\t\t\t\t// Being in the `saving` state ensures that the autosave callback won't be delayed further by the `change:data` listener.\n\t\t\t\tthis.state = 'saving';\n\n\t\t\t\tthis._debouncedSave();\n\n\t\t\t\tthrow err;\n\t\t\t} );\n\n\t\treturn this._savePromise;\n\t}\n\n\t/**\n\t * Creates a pending action if it is not set already.\n\t *\n\t * @private\n\t */\n\t_setPendingAction() {\n\t\tconst t = this.editor.t;\n\n\t\tif ( !this._action ) {\n\t\t\tthis._action = this._pendingActions.add( t( 'Saving changes' ) );\n\t\t}\n\t}\n\n\t/**\n\t * Saves callbacks.\n\t *\n\t * @private\n\t * @type {Array.<Function>}\n\t */\n\tget _saveCallbacks() {\n\t\tconst saveCallbacks = [];\n\n\t\tif ( this.adapter && this.adapter.save ) {\n\t\t\tsaveCallbacks.push( this.adapter.save );\n\t\t}\n\n\t\tif ( this._config.save ) {\n\t\t\tsaveCallbacks.push( this._config.save );\n\t\t}\n\n\t\treturn saveCallbacks;\n\t}\n}\n\nmix( Autosave, ObservableMixin );\n\n/**\n * An interface that requires the `save()` method.\n *\n * Used by {@link module:autosave/autosave~Autosave#adapter}.\n *\n * @interface module:autosave/autosave~AutosaveAdapter\n */\n\n/**\n * The method that will be called when the data changes. It should return a promise (e.g. in case of saving content to the database),\n * so the autosave plugin will wait for that action before removing it from pending actions.\n *\n * @method #save\n * @param {module:core/editor/editor~Editor} editor The editor instance.\n * @returns {Promise.<*>}\n */\n\n/**\n * The configuration of the {@link module:autosave/autosave~Autosave autosave feature}.\n *\n * Read more in {@link module:autosave/autosave~AutosaveConfig}.\n *\n * @member {module:autosave/autosave~AutosaveConfig} module:core/editor/editorconfig~EditorConfig#autosave\n */\n\n/**\n * The configuration of the {@link module:autosave/autosave~Autosave autosave feature}.\n *\n *\t\tClassicEditor\n *\t\t\t.create( editorElement, {\n *\t\t\t\tautosave: {\n *\t\t\t\t\tsave( editor ) {\n *\t\t\t\t\t\t// The saveData() function must return a promise\n *\t\t\t\t\t\t// which should be resolved when the data is successfully saved.\n *\t\t\t\t\t\treturn saveData( editor.getData() );\n *\t\t\t\t\t}\n *\t\t\t\t}\n *\t\t\t} );\n *\t\t\t.then( ... )\n *\t\t\t.catch( ... );\n *\n * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.\n *\n * See also the demo of the {@glink installation/advanced/saving-data#autosave-feature autosave feature}.\n *\n * @interface AutosaveConfig\n */\n\n/**\n * The callback to be executed when the data needs to be saved.\n *\n * This function must return a promise which should be resolved when the data is successfully saved.\n *\n *\t\tClassicEditor\n *\t\t\t.create( editorElement, {\n *\t\t\t\tautosave: {\n *\t\t\t\t\tsave( editor ) {\n *\t\t\t\t\t\treturn saveData( editor.getData() );\n *\t\t\t\t\t}\n *\t\t\t\t}\n *\t\t\t} );\n *\t\t\t.then( ... )\n *\t\t\t.catch( ... );\n *\n * @method module:autosave/autosave~AutosaveConfig#save\n * @param {module:core/editor/editor~Editor} editor The editor instance.\n * @returns {Promise.<*>}\n */\n\n/**\n * The minimum amount of time that needs to pass after the last action to call the provided callback.\n * By default it is 1000 ms.\n *\n *\t\tClassicEditor\n *\t\t\t.create( editorElement, {\n *\t\t\t\tautosave: {\n *\t\t\t\t\tsave( editor ) {\n *\t\t\t\t\t\treturn saveData( editor.getData() );\n *\t\t\t\t\t},\n *\t\t\t\t\twaitingTime: 2000\n *\t\t\t\t}\n *\t\t\t} );\n *\t\t\t.then( ... )\n *\t\t\t.catch( ... );\n *\n * @member {Number} module:autosave/autosave~AutosaveConfig#waitingTime\n */\n","module.exports = (__webpack_require__(/*! dll-reference CKEditor5.dll */ \"dll-reference CKEditor5.dll\"))(\"./src/core.js\");","module.exports = (__webpack_require__(/*! dll-reference CKEditor5.dll */ \"dll-reference CKEditor5.dll\"))(\"./src/utils.js\");","module.exports = CKEditor5.dll;","import root from './_root.js';\n\n/** Built-in value references. */\nvar Symbol = root.Symbol;\n\nexport default Symbol;\n","import Symbol from './_Symbol.js';\nimport getRawTag from './_getRawTag.js';\nimport objectToString from './_objectToString.js';\n\n/** `Object#toString` result references. */\nvar nullTag = '[object Null]',\n undefinedTag = '[object Undefined]';\n\n/** Built-in value references. */\nvar symToStringTag = Symbol ? Symbol.toStringTag : undefined;\n\n/**\n * The base implementation of `getTag` without fallbacks for buggy environments.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the `toStringTag`.\n */\nfunction baseGetTag(value) {\n if (value == null) {\n return value === undefined ? undefinedTag : nullTag;\n }\n return (symToStringTag && symToStringTag in Object(value))\n ? getRawTag(value)\n : objectToString(value);\n}\n\nexport default baseGetTag;\n","import trimmedEndIndex from './_trimmedEndIndex.js';\n\n/** Used to match leading whitespace. */\nvar reTrimStart = /^\\s+/;\n\n/**\n * The base implementation of `_.trim`.\n *\n * @private\n * @param {string} string The string to trim.\n * @returns {string} Returns the trimmed string.\n */\nfunction baseTrim(string) {\n return string\n ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')\n : string;\n}\n\nexport default baseTrim;\n","/** Detect free variable `global` from Node.js. */\nvar freeGlobal = typeof global == 'object' && global && global.Object === Object && global;\n\nexport default freeGlobal;\n","import Symbol from './_Symbol.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar nativeObjectToString = objectProto.toString;\n\n/** Built-in value references. */\nvar symToStringTag = Symbol ? Symbol.toStringTag : undefined;\n\n/**\n * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the raw `toStringTag`.\n */\nfunction getRawTag(value) {\n var isOwn = hasOwnProperty.call(value, symToStringTag),\n tag = value[symToStringTag];\n\n try {\n value[symToStringTag] = undefined;\n var unmasked = true;\n } catch (e) {}\n\n var result = nativeObjectToString.call(value);\n if (unmasked) {\n if (isOwn) {\n value[symToStringTag] = tag;\n } else {\n delete value[symToStringTag];\n }\n }\n return result;\n}\n\nexport default getRawTag;\n","/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar nativeObjectToString = objectProto.toString;\n\n/**\n * Converts `value` to a string using `Object.prototype.toString`.\n *\n * @private\n * @param {*} value The value to convert.\n * @returns {string} Returns the converted string.\n */\nfunction objectToString(value) {\n return nativeObjectToString.call(value);\n}\n\nexport default objectToString;\n","import freeGlobal from './_freeGlobal.js';\n\n/** Detect free variable `self`. */\nvar freeSelf = typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\nexport default root;\n","/** Used to match a single whitespace character. */\nvar reWhitespace = /\\s/;\n\n/**\n * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace\n * character of `string`.\n *\n * @private\n * @param {string} string The string to inspect.\n * @returns {number} Returns the index of the last non-whitespace character.\n */\nfunction trimmedEndIndex(string) {\n var index = string.length;\n\n while (index-- && reWhitespace.test(string.charAt(index))) {}\n return index;\n}\n\nexport default trimmedEndIndex;\n","import isObject from './isObject.js';\nimport now from './now.js';\nimport toNumber from './toNumber.js';\n\n/** Error message constants. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n timeWaiting = wait - timeSinceLastCall;\n\n return maxing\n ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||\n (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n clearTimeout(timerId);\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\nexport default debounce;\n","/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return value != null && (type == 'object' || type == 'function');\n}\n\nexport default isObject;\n","/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return value != null && typeof value == 'object';\n}\n\nexport default isObjectLike;\n","import baseGetTag from './_baseGetTag.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return typeof value == 'symbol' ||\n (isObjectLike(value) && baseGetTag(value) == symbolTag);\n}\n\nexport default isSymbol;\n","import root from './_root.js';\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function() {\n return root.Date.now();\n};\n\nexport default now;\n","import baseTrim from './_baseTrim.js';\nimport isObject from './isObject.js';\nimport isSymbol from './isSymbol.js';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? (other + '') : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = baseTrim(value);\n var isBinary = reIsBinary.test(value);\n return (isBinary || reIsOctal.test(value))\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : (reIsBadHex.test(value) ? NAN : +value);\n}\n\nexport default toNumber;\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module autosave\n */\n\nexport { default as Autosave } from './autosave';\n"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-autosave",
3
- "version": "38.0.1",
3
+ "version": "38.1.1",
4
4
  "description": "Autosave feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,20 +12,9 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^38.0.1",
15
+ "ckeditor5": "38.1.1",
16
16
  "lodash-es": "^4.17.15"
17
17
  },
18
- "devDependencies": {
19
- "@ckeditor/ckeditor5-core": "^38.0.1",
20
- "@ckeditor/ckeditor5-dev-utils": "^37.0.0",
21
- "@ckeditor/ckeditor5-editor-classic": "^38.0.1",
22
- "@ckeditor/ckeditor5-paragraph": "^38.0.1",
23
- "@ckeditor/ckeditor5-source-editing": "^38.0.1",
24
- "@ckeditor/ckeditor5-theme-lark": "^38.0.1",
25
- "typescript": "^4.8.4",
26
- "webpack": "^5.58.1",
27
- "webpack-cli": "^4.9.0"
28
- },
29
18
  "engines": {
30
19
  "node": ">=16.0.0",
31
20
  "npm": ">=5.7.1"
@@ -48,10 +37,5 @@
48
37
  "ckeditor5-metadata.json",
49
38
  "CHANGELOG.md"
50
39
  ],
51
- "scripts": {
52
- "dll:build": "webpack",
53
- "build": "tsc -p ./tsconfig.json",
54
- "postversion": "npm run build"
55
- },
56
40
  "types": "src/index.d.ts"
57
41
  }
@@ -1,18 +1,18 @@
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
- import type { Autosave, AutosaveConfig } from './index';
6
- declare module '@ckeditor/ckeditor5-core' {
7
- interface PluginsMap {
8
- [Autosave.pluginName]: Autosave;
9
- }
10
- interface EditorConfig {
11
- /**
12
- * The configuration of the {@link module:autosave/autosave~Autosave autosave feature}.
13
- *
14
- * Read more in {@link module:autosave/autosave~AutosaveConfig}.
15
- */
16
- autosave?: AutosaveConfig;
17
- }
18
- }
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
+ import type { Autosave, AutosaveConfig } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface PluginsMap {
8
+ [Autosave.pluginName]: Autosave;
9
+ }
10
+ interface EditorConfig {
11
+ /**
12
+ * The configuration of the {@link module:autosave/autosave~Autosave autosave feature}.
13
+ *
14
+ * Read more in {@link module:autosave/autosave~AutosaveConfig}.
15
+ */
16
+ autosave?: AutosaveConfig;
17
+ }
18
+ }
@@ -1,5 +1,5 @@
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
- export {};
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
+ export {};
package/src/autosave.d.ts CHANGED
@@ -1,220 +1,219 @@
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 autosave/autosave
7
- */
8
- import { Plugin, PendingActions, type Editor } from 'ckeditor5/src/core';
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~Document#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( document.querySelector( '#editor' ), {
20
- * plugins: [ ArticlePluginSet, Autosave ],
21
- * toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
22
- * image: {
23
- * toolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],
24
- * },
25
- * autosave: {
26
- * save( editor: Editor ) {
27
- * // The saveData() function must return a promise
28
- * // which should be resolved when the data is successfully saved.
29
- * return saveData( editor.getData() );
30
- * }
31
- * }
32
- * } );
33
- * ```
34
- *
35
- * Read more about this feature in the {@glink installation/getting-started/getting-and-setting-data#autosave-feature Autosave feature}
36
- * section of the {@glink installation/getting-started/getting-and-setting-data Saving and getting data}.
37
- */
38
- export default class Autosave extends Plugin {
39
- /**
40
- * The adapter is an object with a `save()` method. That method will be called whenever
41
- * the data changes. It might be called some time after the change,
42
- * since the event is throttled for performance reasons.
43
- */
44
- adapter?: AutosaveAdapter;
45
- /**
46
- * The state of this plugin.
47
- *
48
- * The plugin can be in the following states:
49
- *
50
- * * synchronized &ndash; When all changes are saved.
51
- * * waiting &ndash; When the plugin is waiting for other changes before calling `adapter#save()` and `config.autosave.save()`.
52
- * * saving &ndash; When the provided save method is called and the plugin waits for the response.
53
- * * error &ndash When the provided save method will throw an error. This state immediately changes to the `saving` state and
54
- * the save method will be called again in the short period of time.
55
- *
56
- * @observable
57
- * @readonly
58
- */
59
- state: 'synchronized' | 'waiting' | 'saving' | 'error';
60
- /**
61
- * Debounced save method. The `save()` method is called the specified `waitingTime` after `debouncedSave()` is called,
62
- * unless a new action happens in the meantime.
63
- */
64
- private _debouncedSave;
65
- /**
66
- * The last saved document version.
67
- */
68
- private _lastDocumentVersion;
69
- /**
70
- * Promise used for asynchronous save calls.
71
- *
72
- * Created to handle the autosave call to an external data source. It resolves when that call is finished. It is re-used if
73
- * save is called before the promise has been resolved. It is set to `null` if there is no call in progress.
74
- */
75
- private _savePromise;
76
- /**
77
- * DOM emitter.
78
- */
79
- private _domEmitter;
80
- /**
81
- * The configuration of this plugins.
82
- */
83
- private _config;
84
- /**
85
- * Editor's pending actions manager.
86
- */
87
- private _pendingActions;
88
- /**
89
- * Informs whether there should be another autosave callback performed, immediately after current autosave callback finishes.
90
- *
91
- * This is set to `true` when there is a save request while autosave callback is already being processed
92
- * and the model has changed since the last save.
93
- */
94
- private _makeImmediateSave;
95
- /**
96
- * An action that will be added to the pending action manager for actions happening in that plugin.
97
- */
98
- private _action;
99
- /**
100
- * @inheritDoc
101
- */
102
- static get pluginName(): 'Autosave';
103
- /**
104
- * @inheritDoc
105
- */
106
- static get requires(): readonly [typeof PendingActions];
107
- /**
108
- * @inheritDoc
109
- */
110
- constructor(editor: Editor);
111
- /**
112
- * @inheritDoc
113
- */
114
- init(): void;
115
- /**
116
- * @inheritDoc
117
- */
118
- destroy(): void;
119
- /**
120
- * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave
121
- * callback in progress, then the requested save will be performed immediately after the current callback finishes.
122
- *
123
- * @returns A promise that will be resolved when the autosave callback is finished.
124
- */
125
- save(): Promise<void>;
126
- /**
127
- * Invokes the remaining `_save()` method call.
128
- */
129
- private _flush;
130
- /**
131
- * If the adapter is set and a new document version exists,
132
- * the `_save()` method creates a pending action and calls the `adapter.save()` method.
133
- * It waits for the result and then removes the created pending action.
134
- *
135
- * @returns A promise that will be resolved when the autosave callback is finished.
136
- */
137
- private _save;
138
- /**
139
- * Creates a pending action if it is not set already.
140
- */
141
- private _setPendingAction;
142
- /**
143
- * Saves callbacks.
144
- */
145
- private get _saveCallbacks();
146
- }
147
- /**
148
- * An interface that requires the `save()` method.
149
- *
150
- * Used by {@link module:autosave/autosave~Autosave#adapter}.
151
- */
152
- export interface AutosaveAdapter {
153
- /**
154
- * The method that will be called when the data changes. It should return a promise (e.g. in case of saving content to the database),
155
- * so the autosave plugin will wait for that action before removing it from pending actions.
156
- */
157
- save(editor: Editor): Promise<unknown>;
158
- }
159
- /**
160
- * The configuration of the {@link module:autosave/autosave~Autosave autosave feature}.
161
- *
162
- * ```ts
163
- * ClassicEditor
164
- * .create( editorElement, {
165
- * autosave: {
166
- * save( editor: Editor ) {
167
- * // The saveData() function must return a promise
168
- * // which should be resolved when the data is successfully saved.
169
- * return saveData( editor.getData() );
170
- * }
171
- * }
172
- * } );
173
- * .then( ... )
174
- * .catch( ... );
175
- * ```
176
- *
177
- * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
178
- *
179
- * See also the demo of the {@glink installation/getting-started/getting-and-setting-data#autosave-feature autosave feature}.
180
- */
181
- export interface AutosaveConfig {
182
- /**
183
- * The callback to be executed when the data needs to be saved.
184
- *
185
- * This function must return a promise which should be resolved when the data is successfully saved.
186
- *
187
- * ```ts
188
- * ClassicEditor
189
- * .create( editorElement, {
190
- * autosave: {
191
- * save( editor: Editor ) {
192
- * return saveData( editor.getData() );
193
- * }
194
- * }
195
- * } );
196
- * .then( ... )
197
- * .catch( ... );
198
- * ```
199
- */
200
- save?: (editor: Editor) => Promise<unknown>;
201
- /**
202
- * The minimum amount of time that needs to pass after the last action to call the provided callback.
203
- * By default it is 1000 ms.
204
- *
205
- * ```ts
206
- * ClassicEditor
207
- * .create( editorElement, {
208
- * autosave: {
209
- * save( editor: Editor ) {
210
- * return saveData( editor.getData() );
211
- * },
212
- * waitingTime: 2000
213
- * }
214
- * } );
215
- * .then( ... )
216
- * .catch( ... );
217
- * ```
218
- */
219
- waitingTime?: number;
220
- }
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 autosave/autosave
7
+ */
8
+ import { Plugin, PendingActions, type Editor } from 'ckeditor5/src/core';
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~Document#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( document.querySelector( '#editor' ), {
20
+ * plugins: [ ArticlePluginSet, Autosave ],
21
+ * toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
22
+ * image: {
23
+ * toolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],
24
+ * },
25
+ * autosave: {
26
+ * save( editor: Editor ) {
27
+ * // The saveData() function must return a promise
28
+ * // which should be resolved when the data is successfully saved.
29
+ * return saveData( editor.getData() );
30
+ * }
31
+ * }
32
+ * } );
33
+ * ```
34
+ *
35
+ * Read more about this feature in the {@glink features/autosave Autosave} feature guide.
36
+ */
37
+ export default 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
+ */
43
+ adapter?: AutosaveAdapter;
44
+ /**
45
+ * The state of this plugin.
46
+ *
47
+ * The plugin can be in the following states:
48
+ *
49
+ * * synchronized &ndash; When all changes are saved.
50
+ * * waiting &ndash; When the plugin is waiting for other changes before calling `adapter#save()` and `config.autosave.save()`.
51
+ * * saving &ndash; When the provided save method is called and the plugin waits for the response.
52
+ * * error &ndash When the provided save method will throw an error. This state immediately changes to the `saving` state and
53
+ * the save method will be called again in the short period of time.
54
+ *
55
+ * @observable
56
+ * @readonly
57
+ */
58
+ state: 'synchronized' | 'waiting' | 'saving' | 'error';
59
+ /**
60
+ * Debounced save method. The `save()` method is called the specified `waitingTime` after `debouncedSave()` is called,
61
+ * unless a new action happens in the meantime.
62
+ */
63
+ private _debouncedSave;
64
+ /**
65
+ * The last saved document version.
66
+ */
67
+ private _lastDocumentVersion;
68
+ /**
69
+ * Promise used for asynchronous save calls.
70
+ *
71
+ * Created to handle the autosave call to an external data source. It resolves when that call is finished. It is re-used if
72
+ * save is called before the promise has been resolved. It is set to `null` if there is no call in progress.
73
+ */
74
+ private _savePromise;
75
+ /**
76
+ * DOM emitter.
77
+ */
78
+ private _domEmitter;
79
+ /**
80
+ * The configuration of this plugins.
81
+ */
82
+ private _config;
83
+ /**
84
+ * Editor's pending actions manager.
85
+ */
86
+ private _pendingActions;
87
+ /**
88
+ * Informs whether there should be another autosave callback performed, immediately after current autosave callback finishes.
89
+ *
90
+ * This is set to `true` when there is a save request while autosave callback is already being processed
91
+ * and the model has changed since the last save.
92
+ */
93
+ private _makeImmediateSave;
94
+ /**
95
+ * An action that will be added to the pending action manager for actions happening in that plugin.
96
+ */
97
+ private _action;
98
+ /**
99
+ * @inheritDoc
100
+ */
101
+ static get pluginName(): "Autosave";
102
+ /**
103
+ * @inheritDoc
104
+ */
105
+ static get requires(): readonly [typeof PendingActions];
106
+ /**
107
+ * @inheritDoc
108
+ */
109
+ constructor(editor: Editor);
110
+ /**
111
+ * @inheritDoc
112
+ */
113
+ init(): void;
114
+ /**
115
+ * @inheritDoc
116
+ */
117
+ destroy(): void;
118
+ /**
119
+ * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave
120
+ * callback in progress, then the requested save will be performed immediately after the current callback finishes.
121
+ *
122
+ * @returns A promise that will be resolved when the autosave callback is finished.
123
+ */
124
+ save(): Promise<void>;
125
+ /**
126
+ * Invokes the remaining `_save()` method call.
127
+ */
128
+ private _flush;
129
+ /**
130
+ * If the adapter is set and a new document version exists,
131
+ * the `_save()` method creates a pending action and calls the `adapter.save()` method.
132
+ * It waits for the result and then removes the created pending action.
133
+ *
134
+ * @returns A promise that will be resolved when the autosave callback is finished.
135
+ */
136
+ private _save;
137
+ /**
138
+ * Creates a pending action if it is not set already.
139
+ */
140
+ private _setPendingAction;
141
+ /**
142
+ * Saves callbacks.
143
+ */
144
+ private get _saveCallbacks();
145
+ }
146
+ /**
147
+ * An interface that requires the `save()` method.
148
+ *
149
+ * Used by {@link module:autosave/autosave~Autosave#adapter}.
150
+ */
151
+ export interface AutosaveAdapter {
152
+ /**
153
+ * The method that will be called when the data changes. It should return a promise (e.g. in case of saving content to the database),
154
+ * so the autosave plugin will wait for that action before removing it from pending actions.
155
+ */
156
+ save(editor: Editor): Promise<unknown>;
157
+ }
158
+ /**
159
+ * The configuration of the {@link module:autosave/autosave~Autosave autosave feature}.
160
+ *
161
+ * ```ts
162
+ * ClassicEditor
163
+ * .create( editorElement, {
164
+ * autosave: {
165
+ * save( editor: Editor ) {
166
+ * // The saveData() function must return a promise
167
+ * // which should be resolved when the data is successfully saved.
168
+ * return saveData( editor.getData() );
169
+ * }
170
+ * }
171
+ * } );
172
+ * .then( ... )
173
+ * .catch( ... );
174
+ * ```
175
+ *
176
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
177
+ *
178
+ * See also the demo of the {@glink features/autosave autosave feature}.
179
+ */
180
+ export interface AutosaveConfig {
181
+ /**
182
+ * The callback to be executed when the data needs to be saved.
183
+ *
184
+ * This function must return a promise which should be resolved when the data is successfully saved.
185
+ *
186
+ * ```ts
187
+ * ClassicEditor
188
+ * .create( editorElement, {
189
+ * autosave: {
190
+ * save( editor: Editor ) {
191
+ * return saveData( editor.getData() );
192
+ * }
193
+ * }
194
+ * } );
195
+ * .then( ... )
196
+ * .catch( ... );
197
+ * ```
198
+ */
199
+ save?: (editor: Editor) => Promise<unknown>;
200
+ /**
201
+ * The minimum amount of time that needs to pass after the last action to call the provided callback.
202
+ * By default it is 1000 ms.
203
+ *
204
+ * ```ts
205
+ * ClassicEditor
206
+ * .create( editorElement, {
207
+ * autosave: {
208
+ * save( editor: Editor ) {
209
+ * return saveData( editor.getData() );
210
+ * },
211
+ * waitingTime: 2000
212
+ * }
213
+ * } );
214
+ * .then( ... )
215
+ * .catch( ... );
216
+ * ```
217
+ */
218
+ waitingTime?: number;
219
+ }
package/src/autosave.js CHANGED
@@ -1,229 +1,228 @@
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 autosave/autosave
7
- */
8
- import { Plugin, PendingActions } from 'ckeditor5/src/core';
9
- import { DomEmitterMixin } from 'ckeditor5/src/utils';
10
- import { debounce } from 'lodash-es';
11
- /* globals window */
12
- /**
13
- * The {@link module:autosave/autosave~Autosave} plugin allows you to automatically save the data (e.g. send it to the server)
14
- * when needed (when the user changed the content).
15
- *
16
- * It listens to the {@link module:engine/model/document~Document#event:change:data `editor.model.document#change:data`}
17
- * and `window#beforeunload` events and calls the
18
- * {@link module:autosave/autosave~AutosaveAdapter#save `config.autosave.save()`} function.
19
- *
20
- * ```ts
21
- * ClassicEditor
22
- * .create( document.querySelector( '#editor' ), {
23
- * plugins: [ ArticlePluginSet, Autosave ],
24
- * toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
25
- * image: {
26
- * toolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],
27
- * },
28
- * autosave: {
29
- * save( editor: Editor ) {
30
- * // The saveData() function must return a promise
31
- * // which should be resolved when the data is successfully saved.
32
- * return saveData( editor.getData() );
33
- * }
34
- * }
35
- * } );
36
- * ```
37
- *
38
- * Read more about this feature in the {@glink installation/getting-started/getting-and-setting-data#autosave-feature Autosave feature}
39
- * section of the {@glink installation/getting-started/getting-and-setting-data Saving and getting data}.
40
- */
41
- export default class Autosave extends Plugin {
42
- /**
43
- * @inheritDoc
44
- */
45
- static get pluginName() {
46
- return 'Autosave';
47
- }
48
- /**
49
- * @inheritDoc
50
- */
51
- static get requires() {
52
- return [PendingActions];
53
- }
54
- /**
55
- * @inheritDoc
56
- */
57
- constructor(editor) {
58
- super(editor);
59
- /**
60
- * An action that will be added to the pending action manager for actions happening in that plugin.
61
- */
62
- this._action = null;
63
- const config = editor.config.get('autosave') || {};
64
- // A minimum amount of time that needs to pass after the last action.
65
- // After that time the provided save callbacks are being called.
66
- const waitingTime = config.waitingTime || 1000;
67
- this.set('state', 'synchronized');
68
- this._debouncedSave = debounce(this._save.bind(this), waitingTime);
69
- this._lastDocumentVersion = editor.model.document.version;
70
- this._savePromise = null;
71
- this._domEmitter = new (DomEmitterMixin())();
72
- this._config = config;
73
- this._pendingActions = editor.plugins.get(PendingActions);
74
- this._makeImmediateSave = false;
75
- }
76
- /**
77
- * @inheritDoc
78
- */
79
- init() {
80
- const editor = this.editor;
81
- const doc = editor.model.document;
82
- // Add the listener only after the editor is initialized to prevent firing save callback on data init.
83
- this.listenTo(editor, 'ready', () => {
84
- this.listenTo(doc, 'change:data', (evt, batch) => {
85
- if (!this._saveCallbacks.length) {
86
- return;
87
- }
88
- if (!batch.isLocal) {
89
- return;
90
- }
91
- if (this.state === 'synchronized') {
92
- this.state = 'waiting';
93
- // Set pending action already when we are waiting for the autosave callback.
94
- this._setPendingAction();
95
- }
96
- if (this.state === 'waiting') {
97
- this._debouncedSave();
98
- }
99
- // If the plugin is in `saving` state, it will change its state later basing on the `document.version`.
100
- // If the `document.version` will be higher than stored `#_lastDocumentVersion`, then it means, that some `change:data`
101
- // event has fired in the meantime.
102
- });
103
- });
104
- // Flush on the editor's destroy listener with the highest priority to ensure that
105
- // `editor.getData()` will be called before plugins are destroyed.
106
- this.listenTo(editor, 'destroy', () => this._flush(), { priority: 'highest' });
107
- // It's not possible to easy test it because karma uses `beforeunload` event
108
- // to warn before full page reload and this event cannot be dispatched manually.
109
- /* istanbul ignore next -- @preserve */
110
- this._domEmitter.listenTo(window, 'beforeunload', (evtInfo, domEvt) => {
111
- if (this._pendingActions.hasAny) {
112
- domEvt.returnValue = this._pendingActions.first.message;
113
- }
114
- });
115
- }
116
- /**
117
- * @inheritDoc
118
- */
119
- destroy() {
120
- // There's no need for canceling or flushing the throttled save, as
121
- // it's done on the editor's destroy event with the highest priority.
122
- this._domEmitter.stopListening();
123
- super.destroy();
124
- }
125
- /**
126
- * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave
127
- * callback in progress, then the requested save will be performed immediately after the current callback finishes.
128
- *
129
- * @returns A promise that will be resolved when the autosave callback is finished.
130
- */
131
- save() {
132
- this._debouncedSave.cancel();
133
- return this._save();
134
- }
135
- /**
136
- * Invokes the remaining `_save()` method call.
137
- */
138
- _flush() {
139
- this._debouncedSave.flush();
140
- }
141
- /**
142
- * If the adapter is set and a new document version exists,
143
- * the `_save()` method creates a pending action and calls the `adapter.save()` method.
144
- * It waits for the result and then removes the created pending action.
145
- *
146
- * @returns A promise that will be resolved when the autosave callback is finished.
147
- */
148
- _save() {
149
- if (this._savePromise) {
150
- this._makeImmediateSave = this.editor.model.document.version > this._lastDocumentVersion;
151
- return this._savePromise;
152
- }
153
- // Make sure there is a pending action (in case if `_save()` was called through manual `save()` call).
154
- this._setPendingAction();
155
- this.state = 'saving';
156
- this._lastDocumentVersion = this.editor.model.document.version;
157
- // Wait one promise cycle to be sure that save callbacks are not called inside a conversion or when the editor's state changes.
158
- this._savePromise = Promise.resolve()
159
- // Make autosave callback.
160
- .then(() => Promise.all(this._saveCallbacks.map(cb => cb(this.editor))))
161
- // When the autosave callback is finished, always clear `this._savePromise`, no matter if it was successful or not.
162
- .finally(() => {
163
- this._savePromise = null;
164
- })
165
- // If the save was successful, we have three scenarios:
166
- //
167
- // 1. If a save was requested when an autosave callback was already processed, we need to immediately call
168
- // another autosave callback. In this case, `this._savePromise` will not be resolved until the next callback is done.
169
- // 2. Otherwise, if changes happened to the model, make a delayed autosave callback (like the change just happened).
170
- // 3. If no changes happened to the model, return to the `synchronized` state.
171
- .then(() => {
172
- if (this._makeImmediateSave) {
173
- this._makeImmediateSave = false;
174
- // Start another autosave callback. Return a promise that will be resolved after the new autosave callback.
175
- // This way promises returned by `_save()` will not be resolved until all changes are saved.
176
- //
177
- // If `save()` was called when another (most often automatic) autosave callback was already processed,
178
- // the promise returned by `save()` call will be resolved only after new changes have been saved.
179
- //
180
- // Note that it would not work correctly if `this._savePromise` is not cleared.
181
- return this._save();
182
- }
183
- else {
184
- if (this.editor.model.document.version > this._lastDocumentVersion) {
185
- this.state = 'waiting';
186
- this._debouncedSave();
187
- }
188
- else {
189
- this.state = 'synchronized';
190
- this._pendingActions.remove(this._action);
191
- this._action = null;
192
- }
193
- }
194
- })
195
- // In case of an error, retry the autosave callback after a delay (and also throw the original error).
196
- .catch(err => {
197
- // Change state to `error` so that listeners handling autosave error can be called.
198
- this.state = 'error';
199
- // Then, immediately change to the `saving` state as described above.
200
- // Being in the `saving` state ensures that the autosave callback won't be delayed further by the `change:data` listener.
201
- this.state = 'saving';
202
- this._debouncedSave();
203
- throw err;
204
- });
205
- return this._savePromise;
206
- }
207
- /**
208
- * Creates a pending action if it is not set already.
209
- */
210
- _setPendingAction() {
211
- const t = this.editor.t;
212
- if (!this._action) {
213
- this._action = this._pendingActions.add(t('Saving changes'));
214
- }
215
- }
216
- /**
217
- * Saves callbacks.
218
- */
219
- get _saveCallbacks() {
220
- const saveCallbacks = [];
221
- if (this.adapter && this.adapter.save) {
222
- saveCallbacks.push(this.adapter.save);
223
- }
224
- if (this._config.save) {
225
- saveCallbacks.push(this._config.save);
226
- }
227
- return saveCallbacks;
228
- }
229
- }
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 autosave/autosave
7
+ */
8
+ import { Plugin, PendingActions } from 'ckeditor5/src/core';
9
+ import { DomEmitterMixin } from 'ckeditor5/src/utils';
10
+ import { debounce } from 'lodash-es';
11
+ /* globals window */
12
+ /**
13
+ * The {@link module:autosave/autosave~Autosave} plugin allows you to automatically save the data (e.g. send it to the server)
14
+ * when needed (when the user changed the content).
15
+ *
16
+ * It listens to the {@link module:engine/model/document~Document#event:change:data `editor.model.document#change:data`}
17
+ * and `window#beforeunload` events and calls the
18
+ * {@link module:autosave/autosave~AutosaveAdapter#save `config.autosave.save()`} function.
19
+ *
20
+ * ```ts
21
+ * ClassicEditor
22
+ * .create( document.querySelector( '#editor' ), {
23
+ * plugins: [ ArticlePluginSet, Autosave ],
24
+ * toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
25
+ * image: {
26
+ * toolbar: [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ],
27
+ * },
28
+ * autosave: {
29
+ * save( editor: Editor ) {
30
+ * // The saveData() function must return a promise
31
+ * // which should be resolved when the data is successfully saved.
32
+ * return saveData( editor.getData() );
33
+ * }
34
+ * }
35
+ * } );
36
+ * ```
37
+ *
38
+ * Read more about this feature in the {@glink features/autosave Autosave} feature guide.
39
+ */
40
+ export default class Autosave extends Plugin {
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ static get pluginName() {
45
+ return 'Autosave';
46
+ }
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ static get requires() {
51
+ return [PendingActions];
52
+ }
53
+ /**
54
+ * @inheritDoc
55
+ */
56
+ constructor(editor) {
57
+ super(editor);
58
+ /**
59
+ * An action that will be added to the pending action manager for actions happening in that plugin.
60
+ */
61
+ this._action = null;
62
+ const config = editor.config.get('autosave') || {};
63
+ // A minimum amount of time that needs to pass after the last action.
64
+ // After that time the provided save callbacks are being called.
65
+ const waitingTime = config.waitingTime || 1000;
66
+ this.set('state', 'synchronized');
67
+ this._debouncedSave = debounce(this._save.bind(this), waitingTime);
68
+ this._lastDocumentVersion = editor.model.document.version;
69
+ this._savePromise = null;
70
+ this._domEmitter = new (DomEmitterMixin())();
71
+ this._config = config;
72
+ this._pendingActions = editor.plugins.get(PendingActions);
73
+ this._makeImmediateSave = false;
74
+ }
75
+ /**
76
+ * @inheritDoc
77
+ */
78
+ init() {
79
+ const editor = this.editor;
80
+ const doc = editor.model.document;
81
+ // Add the listener only after the editor is initialized to prevent firing save callback on data init.
82
+ this.listenTo(editor, 'ready', () => {
83
+ this.listenTo(doc, 'change:data', (evt, batch) => {
84
+ if (!this._saveCallbacks.length) {
85
+ return;
86
+ }
87
+ if (!batch.isLocal) {
88
+ return;
89
+ }
90
+ if (this.state === 'synchronized') {
91
+ this.state = 'waiting';
92
+ // Set pending action already when we are waiting for the autosave callback.
93
+ this._setPendingAction();
94
+ }
95
+ if (this.state === 'waiting') {
96
+ this._debouncedSave();
97
+ }
98
+ // If the plugin is in `saving` state, it will change its state later basing on the `document.version`.
99
+ // If the `document.version` will be higher than stored `#_lastDocumentVersion`, then it means, that some `change:data`
100
+ // event has fired in the meantime.
101
+ });
102
+ });
103
+ // Flush on the editor's destroy listener with the highest priority to ensure that
104
+ // `editor.getData()` will be called before plugins are destroyed.
105
+ this.listenTo(editor, 'destroy', () => this._flush(), { priority: 'highest' });
106
+ // It's not possible to easy test it because karma uses `beforeunload` event
107
+ // to warn before full page reload and this event cannot be dispatched manually.
108
+ /* istanbul ignore next -- @preserve */
109
+ this._domEmitter.listenTo(window, 'beforeunload', (evtInfo, domEvt) => {
110
+ if (this._pendingActions.hasAny) {
111
+ domEvt.returnValue = this._pendingActions.first.message;
112
+ }
113
+ });
114
+ }
115
+ /**
116
+ * @inheritDoc
117
+ */
118
+ destroy() {
119
+ // There's no need for canceling or flushing the throttled save, as
120
+ // it's done on the editor's destroy event with the highest priority.
121
+ this._domEmitter.stopListening();
122
+ super.destroy();
123
+ }
124
+ /**
125
+ * Immediately calls autosave callback. All previously queued (debounced) callbacks are cleared. If there is already an autosave
126
+ * callback in progress, then the requested save will be performed immediately after the current callback finishes.
127
+ *
128
+ * @returns A promise that will be resolved when the autosave callback is finished.
129
+ */
130
+ save() {
131
+ this._debouncedSave.cancel();
132
+ return this._save();
133
+ }
134
+ /**
135
+ * Invokes the remaining `_save()` method call.
136
+ */
137
+ _flush() {
138
+ this._debouncedSave.flush();
139
+ }
140
+ /**
141
+ * If the adapter is set and a new document version exists,
142
+ * the `_save()` method creates a pending action and calls the `adapter.save()` method.
143
+ * It waits for the result and then removes the created pending action.
144
+ *
145
+ * @returns A promise that will be resolved when the autosave callback is finished.
146
+ */
147
+ _save() {
148
+ if (this._savePromise) {
149
+ this._makeImmediateSave = this.editor.model.document.version > this._lastDocumentVersion;
150
+ return this._savePromise;
151
+ }
152
+ // Make sure there is a pending action (in case if `_save()` was called through manual `save()` call).
153
+ this._setPendingAction();
154
+ this.state = 'saving';
155
+ this._lastDocumentVersion = this.editor.model.document.version;
156
+ // Wait one promise cycle to be sure that save callbacks are not called inside a conversion or when the editor's state changes.
157
+ this._savePromise = Promise.resolve()
158
+ // Make autosave callback.
159
+ .then(() => Promise.all(this._saveCallbacks.map(cb => cb(this.editor))))
160
+ // When the autosave callback is finished, always clear `this._savePromise`, no matter if it was successful or not.
161
+ .finally(() => {
162
+ this._savePromise = null;
163
+ })
164
+ // If the save was successful, we have three scenarios:
165
+ //
166
+ // 1. If a save was requested when an autosave callback was already processed, we need to immediately call
167
+ // another autosave callback. In this case, `this._savePromise` will not be resolved until the next callback is done.
168
+ // 2. Otherwise, if changes happened to the model, make a delayed autosave callback (like the change just happened).
169
+ // 3. If no changes happened to the model, return to the `synchronized` state.
170
+ .then(() => {
171
+ if (this._makeImmediateSave) {
172
+ this._makeImmediateSave = false;
173
+ // Start another autosave callback. Return a promise that will be resolved after the new autosave callback.
174
+ // This way promises returned by `_save()` will not be resolved until all changes are saved.
175
+ //
176
+ // If `save()` was called when another (most often automatic) autosave callback was already processed,
177
+ // the promise returned by `save()` call will be resolved only after new changes have been saved.
178
+ //
179
+ // Note that it would not work correctly if `this._savePromise` is not cleared.
180
+ return this._save();
181
+ }
182
+ else {
183
+ if (this.editor.model.document.version > this._lastDocumentVersion) {
184
+ this.state = 'waiting';
185
+ this._debouncedSave();
186
+ }
187
+ else {
188
+ this.state = 'synchronized';
189
+ this._pendingActions.remove(this._action);
190
+ this._action = null;
191
+ }
192
+ }
193
+ })
194
+ // In case of an error, retry the autosave callback after a delay (and also throw the original error).
195
+ .catch(err => {
196
+ // Change state to `error` so that listeners handling autosave error can be called.
197
+ this.state = 'error';
198
+ // Then, immediately change to the `saving` state as described above.
199
+ // Being in the `saving` state ensures that the autosave callback won't be delayed further by the `change:data` listener.
200
+ this.state = 'saving';
201
+ this._debouncedSave();
202
+ throw err;
203
+ });
204
+ return this._savePromise;
205
+ }
206
+ /**
207
+ * Creates a pending action if it is not set already.
208
+ */
209
+ _setPendingAction() {
210
+ const t = this.editor.t;
211
+ if (!this._action) {
212
+ this._action = this._pendingActions.add(t('Saving changes'));
213
+ }
214
+ }
215
+ /**
216
+ * Saves callbacks.
217
+ */
218
+ get _saveCallbacks() {
219
+ const saveCallbacks = [];
220
+ if (this.adapter && this.adapter.save) {
221
+ saveCallbacks.push(this.adapter.save);
222
+ }
223
+ if (this._config.save) {
224
+ saveCallbacks.push(this._config.save);
225
+ }
226
+ return saveCallbacks;
227
+ }
228
+ }
package/src/index.d.ts CHANGED
@@ -1,9 +1,9 @@
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 autosave
7
- */
8
- export { default as Autosave, type AutosaveConfig } from './autosave';
9
- import './augmentation';
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 autosave
7
+ */
8
+ export { default as Autosave, type AutosaveConfig } from './autosave';
9
+ import './augmentation';
package/src/index.js CHANGED
@@ -1,9 +1,9 @@
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 autosave
7
- */
8
- export { default as Autosave } from './autosave';
9
- import './augmentation';
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 autosave
7
+ */
8
+ export { default as Autosave } from './autosave';
9
+ import './augmentation';