@ckeditor/ckeditor5-watchdog 36.0.0 → 37.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/build/watchdog.js +1 -1
- package/package.json +16 -11
- package/src/contextwatchdog.d.ts +333 -0
- package/src/contextwatchdog.js +389 -547
- package/src/editorwatchdog.d.ts +155 -0
- package/src/editorwatchdog.js +203 -313
- package/src/index.d.ts +10 -0
- package/src/index.js +0 -2
- package/src/utils/areconnectedthroughproperties.d.ts +8 -0
- package/src/utils/areconnectedthroughproperties.js +41 -64
- package/src/utils/getsubnodes.d.ts +8 -0
- package/src/utils/getsubnodes.js +68 -87
- package/src/watchdog.d.ts +229 -0
- package/src/watchdog.js +173 -347
package/build/watchdog.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md.
|
|
4
|
-
*/(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ContextWatchdog:()=>Hr,EditorWatchdog:()=>kr,Watchdog:()=>r});class r{constructor(t){if(this.crashes=[],this.state="initializing",this._crashNumberLimit="number"==typeof t.crashNumberLimit?t.crashNumberLimit:3,this._now=Date.now,this._minimumNonErrorTimePeriod="number"==typeof t.minimumNonErrorTimePeriod?t.minimumNonErrorTimePeriod:5e3,this._boundErrorHandler=t=>{const e=t.error||t.reason;e instanceof Error&&this._handleError(e,t)},this._listeners={},!this._restart)throw new Error("The Watchdog class was split into the abstract `Watchdog` class and the `EditorWatchdog` class. Please, use `EditorWatchdog` if you have used the `Watchdog` class previously.")}setCreator(t){this._creator=t}setDestructor(t){this._destructor=t}destroy(){this._stopErrorHandling(),this._listeners={}}on(t,e){this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e)}off(t,e){this._listeners[t]=this._listeners[t].filter((t=>t!==e))}_fire(t,...e){const r=this._listeners[t]||[];for(const t of r)t.apply(this,[null,...e])}_startErrorHandling(){window.addEventListener("error",this._boundErrorHandler),window.addEventListener("unhandledrejection",this._boundErrorHandler)}_stopErrorHandling(){window.removeEventListener("error",this._boundErrorHandler),window.removeEventListener("unhandledrejection",this._boundErrorHandler)}_handleError(t,e){if(this._shouldReactToError(t)){this.crashes.push({message:t.message,stack:t.stack,filename:e.filename,lineno:e.lineno,colno:e.colno,date:this._now()});const r=this._shouldRestart();this.state="crashed",this._fire("stateChange"),this._fire("error",{error:t,causesRestart:r}),r?this._restart():(this.state="crashedPermanently",this._fire("stateChange"))}}_shouldReactToError(t){return t.is&&t.is("CKEditorError")&&void 0!==t.context&&null!==t.context&&"ready"===this.state&&this._isErrorComingFromThisItem(t)}_shouldRestart(){if(this.crashes.length<=this._crashNumberLimit)return!0;return(this.crashes[this.crashes.length-1].date-this.crashes[this.crashes.length-1-this._crashNumberLimit].date)/this._crashNumberLimit>this._minimumNonErrorTimePeriod}}const n=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};const o="object"==typeof global&&global&&global.Object===Object&&global;var s="object"==typeof self&&self&&self.Object===Object&&self;const i=o||s||Function("return this")();const c=function(){return i.Date.now()};var a=/\s/;const u=function(t){for(var e=t.length;e--&&a.test(t.charAt(e)););return e};var h=/^\s+/;const l=function(t){return t?t.slice(0,u(t)+1).replace(h,""):t};const f=i.Symbol;var d=Object.prototype,_=d.hasOwnProperty,p=d.toString,y=f?f.toStringTag:void 0;const b=function(t){var e=_.call(t,y),r=t[y];try{t[y]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[y]=r:delete t[y]),o};var v=Object.prototype.toString;const g=function(t){return v.call(t)};var m=f?f.toStringTag:void 0;const j=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m in Object(t)?b(t):g(t)};const w=function(t){return null!=t&&"object"==typeof t};const E=function(t){return"symbol"==typeof t||w(t)&&"[object Symbol]"==j(t)};var x=/^[-+]0x[0-9a-f]+$/i,O=/^0b[01]+$/i,A=/^0o[0-7]+$/i,P=parseInt;const S=function(t){if("number"==typeof t)return t;if(E(t))return NaN;if(n(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=n(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=l(t);var r=O.test(t);return r||A.test(t)?P(t.slice(2),r?2:8):x.test(t)?NaN:+t};var C=Math.max,T=Math.min;const I=function(t,e,r){var o,s,i,a,u,h,l=0,f=!1,d=!1,_=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function p(e){var r=o,n=s;return o=s=void 0,l=e,a=t.apply(n,r)}function y(t){return l=t,u=setTimeout(v,e),f?p(t):a}function b(t){var r=t-h;return void 0===h||r>=e||r<0||d&&t-l>=i}function v(){var t=c();if(b(t))return g(t);u=setTimeout(v,function(t){var r=e-(t-h);return d?T(r,i-(t-l)):r}(t))}function g(t){return u=void 0,_&&o?p(t):(o=s=void 0,a)}function m(){var t=c(),r=b(t);if(o=arguments,s=this,h=t,r){if(void 0===u)return y(h);if(d)return clearTimeout(u),u=setTimeout(v,e),p(h)}return void 0===u&&(u=setTimeout(v,e)),a}return e=S(e)||0,n(r)&&(f=!!r.leading,i=(d="maxWait"in r)?C(S(r.maxWait)||0,e):i,_="trailing"in r?!!r.trailing:_),m.cancel=function(){void 0!==u&&clearTimeout(u),l=0,o=h=s=u=void 0},m.flush=function(){return void 0===u?a:g(c())},m};const z=function(t,e,r){var o=!0,s=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return n(r)&&(o="leading"in r?!!r.leading:o,s="trailing"in r?!!r.trailing:s),I(t,e,{leading:o,maxWait:e,trailing:s})};const D=function(){this.__data__=[],this.size=0};const N=function(t,e){return t===e||t!=t&&e!=e};const W=function(t,e){for(var r=t.length;r--;)if(N(t[r][0],e))return r;return-1};var F=Array.prototype.splice;const M=function(t){var e=this.__data__,r=W(e,t);return!(r<0)&&(r==e.length-1?e.pop():F.call(e,r,1),--this.size,!0)};const q=function(t){var e=this.__data__,r=W(e,t);return r<0?void 0:e[r][1]};const U=function(t){return W(this.__data__,t)>-1};const R=function(t,e){var r=this.__data__,n=W(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function $(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}$.prototype.clear=D,$.prototype.delete=M,$.prototype.get=q,$.prototype.has=U,$.prototype.set=R;const k=$;const L=function(){this.__data__=new k,this.size=0};const H=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r};const B=function(t){return this.__data__.get(t)};const Q=function(t){return this.__data__.has(t)};const V=function(t){if(!n(t))return!1;var e=j(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e};const K=i["__core-js_shared__"];var G,Y=(G=/[^.]+$/.exec(K&&K.keys&&K.keys.IE_PROTO||""))?"Symbol(src)_1."+G:"";const J=function(t){return!!Y&&Y in t};var X=Function.prototype.toString;const Z=function(t){if(null!=t){try{return X.call(t)}catch(t){}try{return t+""}catch(t){}}return""};var tt=/^\[object .+?Constructor\]$/,et=Function.prototype,rt=Object.prototype,nt=et.toString,ot=rt.hasOwnProperty,st=RegExp("^"+nt.call(ot).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");const it=function(t){return!(!n(t)||J(t))&&(V(t)?st:tt).test(Z(t))};const ct=function(t,e){return null==t?void 0:t[e]};const at=function(t,e){var r=ct(t,e);return it(r)?r:void 0};const ut=at(i,"Map");const ht=at(Object,"create");const lt=function(){this.__data__=ht?ht(null):{},this.size=0};const ft=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e};var dt=Object.prototype.hasOwnProperty;const _t=function(t){var e=this.__data__;if(ht){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return dt.call(e,t)?e[t]:void 0};var pt=Object.prototype.hasOwnProperty;const yt=function(t){var e=this.__data__;return ht?void 0!==e[t]:pt.call(e,t)};const bt=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=ht&&void 0===e?"__lodash_hash_undefined__":e,this};function vt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}vt.prototype.clear=lt,vt.prototype.delete=ft,vt.prototype.get=_t,vt.prototype.has=yt,vt.prototype.set=bt;const gt=vt;const mt=function(){this.size=0,this.__data__={hash:new gt,map:new(ut||k),string:new gt}};const jt=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};const wt=function(t,e){var r=t.__data__;return jt(e)?r["string"==typeof e?"string":"hash"]:r.map};const Et=function(t){var e=wt(this,t).delete(t);return this.size-=e?1:0,e};const xt=function(t){return wt(this,t).get(t)};const Ot=function(t){return wt(this,t).has(t)};const At=function(t,e){var r=wt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Pt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Pt.prototype.clear=mt,Pt.prototype.delete=Et,Pt.prototype.get=xt,Pt.prototype.has=Ot,Pt.prototype.set=At;const St=Pt;const Ct=function(t,e){var r=this.__data__;if(r instanceof k){var n=r.__data__;if(!ut||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new St(n)}return r.set(t,e),this.size=r.size,this};function Tt(t){var e=this.__data__=new k(t);this.size=e.size}Tt.prototype.clear=L,Tt.prototype.delete=H,Tt.prototype.get=B,Tt.prototype.has=Q,Tt.prototype.set=Ct;const It=Tt;const zt=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};const Dt=function(){try{var t=at(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();const Nt=function(t,e,r){"__proto__"==e&&Dt?Dt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var Wt=Object.prototype.hasOwnProperty;const Ft=function(t,e,r){var n=t[e];Wt.call(t,e)&&N(n,r)&&(void 0!==r||e in t)||Nt(t,e,r)};const Mt=function(t,e,r,n){var o=!r;r||(r={});for(var s=-1,i=e.length;++s<i;){var c=e[s],a=n?n(r[c],t[c],c,r,t):void 0;void 0===a&&(a=t[c]),o?Nt(r,c,a):Ft(r,c,a)}return r};const qt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};const Ut=function(t){return w(t)&&"[object Arguments]"==j(t)};var Rt=Object.prototype,$t=Rt.hasOwnProperty,kt=Rt.propertyIsEnumerable;const Lt=Ut(function(){return arguments}())?Ut:function(t){return w(t)&&$t.call(t,"callee")&&!kt.call(t,"callee")};const Ht=Array.isArray;const Bt=function(){return!1};var Qt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Vt=Qt&&"object"==typeof module&&module&&!module.nodeType&&module,Kt=Vt&&Vt.exports===Qt?i.Buffer:void 0;const Gt=(Kt?Kt.isBuffer:void 0)||Bt;var Yt=/^(?:0|[1-9]\d*)$/;const Jt=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Yt.test(t))&&t>-1&&t%1==0&&t<e};const Xt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991};var Zt={};Zt["[object Float32Array]"]=Zt["[object Float64Array]"]=Zt["[object Int8Array]"]=Zt["[object Int16Array]"]=Zt["[object Int32Array]"]=Zt["[object Uint8Array]"]=Zt["[object Uint8ClampedArray]"]=Zt["[object Uint16Array]"]=Zt["[object Uint32Array]"]=!0,Zt["[object Arguments]"]=Zt["[object Array]"]=Zt["[object ArrayBuffer]"]=Zt["[object Boolean]"]=Zt["[object DataView]"]=Zt["[object Date]"]=Zt["[object Error]"]=Zt["[object Function]"]=Zt["[object Map]"]=Zt["[object Number]"]=Zt["[object Object]"]=Zt["[object RegExp]"]=Zt["[object Set]"]=Zt["[object String]"]=Zt["[object WeakMap]"]=!1;const te=function(t){return w(t)&&Xt(t.length)&&!!Zt[j(t)]};const ee=function(t){return function(e){return t(e)}};var re="object"==typeof exports&&exports&&!exports.nodeType&&exports,ne=re&&"object"==typeof module&&module&&!module.nodeType&&module,oe=ne&&ne.exports===re&&o.process;const se=function(){try{var t=ne&&ne.require&&ne.require("util").types;return t||oe&&oe.binding&&oe.binding("util")}catch(t){}}();var ie=se&&se.isTypedArray;const ce=ie?ee(ie):te;var ae=Object.prototype.hasOwnProperty;const ue=function(t,e){var r=Ht(t),n=!r&&Lt(t),o=!r&&!n&&Gt(t),s=!r&&!n&&!o&&ce(t),i=r||n||o||s,c=i?qt(t.length,String):[],a=c.length;for(var u in t)!e&&!ae.call(t,u)||i&&("length"==u||o&&("offset"==u||"parent"==u)||s&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||Jt(u,a))||c.push(u);return c};var he=Object.prototype;const le=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||he)};const fe=function(t,e){return function(r){return t(e(r))}};const de=fe(Object.keys,Object);var _e=Object.prototype.hasOwnProperty;const pe=function(t){if(!le(t))return de(t);var e=[];for(var r in Object(t))_e.call(t,r)&&"constructor"!=r&&e.push(r);return e};const ye=function(t){return null!=t&&Xt(t.length)&&!V(t)};const be=function(t){return ye(t)?ue(t):pe(t)};const ve=function(t,e){return t&&Mt(e,be(e),t)};const ge=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e};var me=Object.prototype.hasOwnProperty;const je=function(t){if(!n(t))return ge(t);var e=le(t),r=[];for(var o in t)("constructor"!=o||!e&&me.call(t,o))&&r.push(o);return r};const we=function(t){return ye(t)?ue(t,!0):je(t)};const Ee=function(t,e){return t&&Mt(e,we(e),t)};var xe="object"==typeof exports&&exports&&!exports.nodeType&&exports,Oe=xe&&"object"==typeof module&&module&&!module.nodeType&&module,Ae=Oe&&Oe.exports===xe?i.Buffer:void 0,Pe=Ae?Ae.allocUnsafe:void 0;const Se=function(t,e){if(e)return t.slice();var r=t.length,n=Pe?Pe(r):new t.constructor(r);return t.copy(n),n};const Ce=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e};const Te=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,s=[];++r<n;){var i=t[r];e(i,r,t)&&(s[o++]=i)}return s};const Ie=function(){return[]};var ze=Object.prototype.propertyIsEnumerable,De=Object.getOwnPropertySymbols;const Ne=De?function(t){return null==t?[]:(t=Object(t),Te(De(t),(function(e){return ze.call(t,e)})))}:Ie;const We=function(t,e){return Mt(t,Ne(t),e)};const Fe=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t};const Me=fe(Object.getPrototypeOf,Object);const qe=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Fe(e,Ne(t)),t=Me(t);return e}:Ie;const Ue=function(t,e){return Mt(t,qe(t),e)};const Re=function(t,e,r){var n=e(t);return Ht(t)?n:Fe(n,r(t))};const $e=function(t){return Re(t,be,Ne)};const ke=function(t){return Re(t,we,qe)};const Le=at(i,"DataView");const He=at(i,"Promise");const Be=at(i,"Set");const Qe=at(i,"WeakMap");var Ve="[object Map]",Ke="[object Promise]",Ge="[object Set]",Ye="[object WeakMap]",Je="[object DataView]",Xe=Z(Le),Ze=Z(ut),tr=Z(He),er=Z(Be),rr=Z(Qe),nr=j;(Le&&nr(new Le(new ArrayBuffer(1)))!=Je||ut&&nr(new ut)!=Ve||He&&nr(He.resolve())!=Ke||Be&&nr(new Be)!=Ge||Qe&&nr(new Qe)!=Ye)&&(nr=function(t){var e=j(t),r="[object Object]"==e?t.constructor:void 0,n=r?Z(r):"";if(n)switch(n){case Xe:return Je;case Ze:return Ve;case tr:return Ke;case er:return Ge;case rr:return Ye}return e});const or=nr;var sr=Object.prototype.hasOwnProperty;const ir=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&sr.call(t,"index")&&(r.index=t.index,r.input=t.input),r};const cr=i.Uint8Array;const ar=function(t){var e=new t.constructor(t.byteLength);return new cr(e).set(new cr(t)),e};const ur=function(t,e){var r=e?ar(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)};var hr=/\w*$/;const lr=function(t){var e=new t.constructor(t.source,hr.exec(t));return e.lastIndex=t.lastIndex,e};var fr=f?f.prototype:void 0,dr=fr?fr.valueOf:void 0;const _r=function(t){return dr?Object(dr.call(t)):{}};const pr=function(t,e){var r=e?ar(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};const yr=function(t,e,r){var n=t.constructor;switch(e){case"[object ArrayBuffer]":return ar(t);case"[object Boolean]":case"[object Date]":return new n(+t);case"[object DataView]":return ur(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return pr(t,r);case"[object Map]":case"[object Set]":return new n;case"[object Number]":case"[object String]":return new n(t);case"[object RegExp]":return lr(t);case"[object Symbol]":return _r(t)}};var br=Object.create;const vr=function(){function t(){}return function(e){if(!n(e))return{};if(br)return br(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();const gr=function(t){return"function"!=typeof t.constructor||le(t)?{}:vr(Me(t))};const mr=function(t){return w(t)&&"[object Map]"==or(t)};var jr=se&&se.isMap;const wr=jr?ee(jr):mr;const Er=function(t){return w(t)&&"[object Set]"==or(t)};var xr=se&&se.isSet;const Or=xr?ee(xr):Er;var Ar="[object Arguments]",Pr="[object Function]",Sr="[object Object]",Cr={};Cr[Ar]=Cr["[object Array]"]=Cr["[object ArrayBuffer]"]=Cr["[object DataView]"]=Cr["[object Boolean]"]=Cr["[object Date]"]=Cr["[object Float32Array]"]=Cr["[object Float64Array]"]=Cr["[object Int8Array]"]=Cr["[object Int16Array]"]=Cr["[object Int32Array]"]=Cr["[object Map]"]=Cr["[object Number]"]=Cr[Sr]=Cr["[object RegExp]"]=Cr["[object Set]"]=Cr["[object String]"]=Cr["[object Symbol]"]=Cr["[object Uint8Array]"]=Cr["[object Uint8ClampedArray]"]=Cr["[object Uint16Array]"]=Cr["[object Uint32Array]"]=!0,Cr["[object Error]"]=Cr[Pr]=Cr["[object WeakMap]"]=!1;const Tr=function t(e,r,o,s,i,c){var a,u=1&r,h=2&r,l=4&r;if(o&&(a=i?o(e,s,i,c):o(e)),void 0!==a)return a;if(!n(e))return e;var f=Ht(e);if(f){if(a=ir(e),!u)return Ce(e,a)}else{var d=or(e),_=d==Pr||"[object GeneratorFunction]"==d;if(Gt(e))return Se(e,u);if(d==Sr||d==Ar||_&&!i){if(a=h||_?{}:gr(e),!u)return h?Ue(e,Ee(a,e)):We(e,ve(a,e))}else{if(!Cr[d])return i?e:{};a=yr(e,d,u)}}c||(c=new It);var p=c.get(e);if(p)return p;c.set(e,a),Or(e)?e.forEach((function(n){a.add(t(n,r,o,n,e,c))})):wr(e)&&e.forEach((function(n,s){a.set(s,t(n,r,o,s,e,c))}));var y=f?void 0:(l?h?ke:$e:h?we:be)(e);return zt(y||e,(function(n,s){y&&(n=e[s=n]),Ft(a,s,t(n,r,o,s,e,c))})),a};const Ir=function(t,e){return Tr(t,5,e="function"==typeof e?e:void 0)};var zr=Function.prototype,Dr=Object.prototype,Nr=zr.toString,Wr=Dr.hasOwnProperty,Fr=Nr.call(Object);const Mr=function(t){if(!w(t)||"[object Object]"!=j(t))return!1;var e=Me(t);if(null===e)return!0;var r=Wr.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Nr.call(r)==Fr};const qr=function(t){return w(t)&&1===t.nodeType&&!Mr(t)};function Ur(t,e=new Set){const r=[t],n=new Set;let o=0;for(;r.length>o;){const t=r[o++];if(!(n.has(t)||Rr(t)||e.has(t)))if(n.add(t),t[Symbol.iterator])try{for(const e of t)r.push(e)}catch(t){}else for(const e in t)"defaultValue"!==e&&r.push(t[e])}return n}function Rr(t){const e=Object.prototype.toString.call(t),r=typeof t;return"number"===r||"boolean"===r||"string"===r||"symbol"===r||"function"===r||"[object Date]"===e||"[object RegExp]"===e||"[object Module]"===e||null==t||!0===t._watchdogExcluded||t instanceof EventTarget||t instanceof Event}function $r(t,e,r=new Set){if(t===e&&("object"==typeof(n=t)&&null!==n))return!0;var n;const o=Ur(t,r),s=Ur(e,r);for(const t of o)if(s.has(t))return!0;return!1}class kr extends r{constructor(t,e={}){super(e),this._editor=null,this._throttledSave=z(this._save.bind(this),"number"==typeof e.saveInterval?e.saveInterval:5e3),this._creator=(e,r)=>t.create(e,r),this._destructor=t=>t.destroy()}get editor(){return this._editor}get _item(){return this._editor}_restart(){return Promise.resolve().then((()=>(this.state="initializing",this._fire("stateChange"),this._destroy()))).catch((t=>{console.error("An error happened during the editor destroying.",t)})).then((()=>{if("string"==typeof this._elementOrData)return this.create(this._data,this._config,this._config.context);{const t=Object.assign({},this._config,{initialData:this._data});return this.create(this._elementOrData,t,t.context)}})).then((()=>{this._fire("restart")}))}create(t=this._elementOrData,e=this._config,r){return Promise.resolve().then((()=>(super._startErrorHandling(),this._elementOrData=t,this._config=this._cloneEditorConfiguration(e)||{},this._config.context=r,this._creator(t,this._config)))).then((t=>{this._editor=t,t.model.document.on("change:data",this._throttledSave),this._lastDocumentVersion=t.model.document.version,this._data=this._getData(),this.state="ready",this._fire("stateChange")}))}destroy(){return Promise.resolve().then((()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy())))}_destroy(){return Promise.resolve().then((()=>{this._stopErrorHandling(),this._throttledSave.flush();const t=this._editor;return this._editor=null,t.model.document.off("change:data",this._throttledSave),this._destructor(t)}))}_save(){const t=this._editor.model.document.version;try{this._data=this._getData(),this._lastDocumentVersion=t}catch(t){console.error(t,"An error happened during restoring editor data. Editor will be restored from the previously saved data.")}}_setExcludedProperties(t){this._excludedProps=t}_getData(){const t={};for(const e of this._editor.model.document.getRootNames())t[e]=this._editor.data.get({rootName:e});return t}_isErrorComingFromThisItem(t){return $r(this._editor,t.context,this._excludedProps)}_cloneEditorConfiguration(t){return Ir(t,((t,e)=>qr(t)||"context"===e?t:void 0))}}const Lr=Symbol("MainQueueId");class Hr extends r{constructor(t,e={}){super(e),this._watchdogs=new Map,this._watchdogConfig=e,this._context=null,this._contextProps=new Set,this._actionQueues=new Br,this._creator=e=>t.create(e),this._destructor=t=>t.destroy(),this._actionQueues.onEmpty((()=>{"initializing"===this.state&&(this.state="ready",this._fire("stateChange"))}))}get context(){return this._context}create(t={}){return this._actionQueues.enqueue(Lr,(()=>(this._contextConfig=t,this._create())))}getItem(t){return this._getWatchdog(t)._item}getItemState(t){return this._getWatchdog(t).state}add(t){const e=Qr(t);return Promise.all(e.map((t=>this._actionQueues.enqueue(t.id,(()=>{if("destroyed"===this.state)throw new Error("Cannot add items to destroyed watchdog.");if(!this._context)throw new Error("Context was not created yet. You should call the `ContextWatchdog#create()` method first.");let e;if(this._watchdogs.has(t.id))throw new Error(`Item with the given id is already added: '${t.id}'.`);if("editor"===t.type)return e=new kr(this._watchdogConfig),e.setCreator(t.creator),e._setExcludedProperties(this._contextProps),t.destructor&&e.setDestructor(t.destructor),this._watchdogs.set(t.id,e),e.on("error",((r,{error:n,causesRestart:o})=>{this._fire("itemError",{itemId:t.id,error:n}),o&&this._actionQueues.enqueue(t.id,(()=>new Promise((r=>{e.on("restart",function n(){e.off("restart",n),this._fire("itemRestart",{itemId:t.id}),r()}.bind(this))}))))})),e.create(t.sourceElementOrData,t.config,this._context);throw new Error(`Not supported item type: '${t.type}'.`)})))))}remove(t){const e=Qr(t);return Promise.all(e.map((t=>this._actionQueues.enqueue(t,(()=>{const e=this._getWatchdog(t);return this._watchdogs.delete(t),e.destroy()})))))}destroy(){return this._actionQueues.enqueue(Lr,(()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy())))}_restart(){return this._actionQueues.enqueue(Lr,(()=>(this.state="initializing",this._fire("stateChange"),this._destroy().catch((t=>{console.error("An error happened during destroying the context or items.",t)})).then((()=>this._create())).then((()=>this._fire("restart"))))))}_create(){return Promise.resolve().then((()=>(this._startErrorHandling(),this._creator(this._contextConfig)))).then((t=>(this._context=t,this._contextProps=Ur(this._context),Promise.all(Array.from(this._watchdogs.values()).map((t=>(t._setExcludedProperties(this._contextProps),t.create(void 0,void 0,this._context))))))))}_destroy(){return Promise.resolve().then((()=>{this._stopErrorHandling();const t=this._context;return this._context=null,this._contextProps=new Set,Promise.all(Array.from(this._watchdogs.values()).map((t=>t.destroy()))).then((()=>this._destructor(t)))}))}_getWatchdog(t){const e=this._watchdogs.get(t);if(!e)throw new Error(`Item with the given id was not registered: ${t}.`);return e}_isErrorComingFromThisItem(t){for(const e of this._watchdogs.values())if(e._isErrorComingFromThisItem(t))return!1;return $r(this._context,t.context)}}class Br{constructor(){this._onEmptyCallbacks=[],this._queues=new Map,this._actions=new WeakMap,this._lastActionId=0,this._activeActions=0}onEmpty(t){this._onEmptyCallbacks.push(t)}enqueue(t,e){const r=t===Lr;this._activeActions++,this._queues.get(t)||this._queues.set(t,Promise.resolve());const n=(r?Promise.all(this._queues.values()):Promise.all([this._queues.get(Lr),this._queues.get(t)])).then(e),o=n.catch((()=>{}));return this._queues.set(t,o),n.finally((()=>{this._activeActions--,this._queues.get(t)===o&&0===this._activeActions&&this._onEmptyCallbacks.forEach((t=>t()))}))}}function Qr(t){return Array.isArray(t)?t:[t]}(window.CKEditor5=window.CKEditor5||{}).watchdog=e})();
|
|
4
|
+
*/(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ContextWatchdog:()=>Wn,EditorWatchdog:()=>zn,Watchdog:()=>r});class r{constructor(t){if(this.crashes=[],this.state="initializing",this._now=Date.now,this.crashes=[],this._crashNumberLimit="number"==typeof t.crashNumberLimit?t.crashNumberLimit:3,this._minimumNonErrorTimePeriod="number"==typeof t.minimumNonErrorTimePeriod?t.minimumNonErrorTimePeriod:5e3,this._boundErrorHandler=t=>{const e="error"in t?t.error:t.reason;e instanceof Error&&this._handleError(e,t)},this._listeners={},!this._restart)throw new Error("The Watchdog class was split into the abstract `Watchdog` class and the `EditorWatchdog` class. Please, use `EditorWatchdog` if you have used the `Watchdog` class previously.")}destroy(){this._stopErrorHandling(),this._listeners={}}on(t,e){this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e)}off(t,e){this._listeners[t]=this._listeners[t].filter((t=>t!==e))}_fire(t,...e){const r=this._listeners[t]||[];for(const t of r)t.apply(this,[null,...e])}_startErrorHandling(){window.addEventListener("error",this._boundErrorHandler),window.addEventListener("unhandledrejection",this._boundErrorHandler)}_stopErrorHandling(){window.removeEventListener("error",this._boundErrorHandler),window.removeEventListener("unhandledrejection",this._boundErrorHandler)}_handleError(t,e){if(this._shouldReactToError(t)){this.crashes.push({message:t.message,stack:t.stack,filename:e instanceof ErrorEvent?e.filename:void 0,lineno:e instanceof ErrorEvent?e.lineno:void 0,colno:e instanceof ErrorEvent?e.colno:void 0,date:this._now()});const r=this._shouldRestart();this.state="crashed",this._fire("stateChange"),this._fire("error",{error:t,causesRestart:r}),r?this._restart():(this.state="crashedPermanently",this._fire("stateChange"))}}_shouldReactToError(t){return t.is&&t.is("CKEditorError")&&void 0!==t.context&&null!==t.context&&"ready"===this.state&&this._isErrorComingFromThisItem(t)}_shouldRestart(){if(this.crashes.length<=this._crashNumberLimit)return!0;return(this.crashes[this.crashes.length-1].date-this.crashes[this.crashes.length-1-this._crashNumberLimit].date)/this._crashNumberLimit>this._minimumNonErrorTimePeriod}}function n(t,e=new Set){const r=[t],n=new Set;let s=0;for(;r.length>s;){const t=r[s++];if(!n.has(t)&&o(t)&&!e.has(t))if(n.add(t),Symbol.iterator in t)try{for(const e of t)r.push(e)}catch(t){}else for(const e in t)"defaultValue"!==e&&r.push(t[e])}return n}function o(t){const e=Object.prototype.toString.call(t),r=typeof t;return!("number"===r||"boolean"===r||"string"===r||"symbol"===r||"function"===r||"[object Date]"===e||"[object RegExp]"===e||"[object Module]"===e||null==t||t._watchdogExcluded||t instanceof EventTarget||t instanceof Event)}function s(t,e,r=new Set){if(t===e&&("object"==typeof(o=t)&&null!==o))return!0;var o;const s=n(t,r),i=n(e,r);for(const t of s)if(i.has(t))return!0;return!1}const i=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};const c="object"==typeof global&&global&&global.Object===Object&&global;var a="object"==typeof self&&self&&self.Object===Object&&self;const u=c||a||Function("return this")();const h=function(){return u.Date.now()};var l=/\s/;const f=function(t){for(var e=t.length;e--&&l.test(t.charAt(e)););return e};var d=/^\s+/;const _=function(t){return t?t.slice(0,f(t)+1).replace(d,""):t};const p=u.Symbol;var y=Object.prototype,v=y.hasOwnProperty,b=y.toString,g=p?p.toStringTag:void 0;const m=function(t){var e=v.call(t,g),r=t[g];try{t[g]=void 0;var n=!0}catch(t){}var o=b.call(t);return n&&(e?t[g]=r:delete t[g]),o};var j=Object.prototype.toString;const w=function(t){return j.call(t)};var E="[object Null]",x="[object Undefined]",O=p?p.toStringTag:void 0;const A=function(t){return null==t?void 0===t?x:E:O&&O in Object(t)?m(t):w(t)};const P=function(t){return null!=t&&"object"==typeof t};var S="[object Symbol]";const C=function(t){return"symbol"==typeof t||P(t)&&A(t)==S};var T=NaN,I=/^[-+]0x[0-9a-f]+$/i,D=/^0b[01]+$/i,z=/^0o[0-7]+$/i,F=parseInt;const W=function(t){if("number"==typeof t)return t;if(C(t))return T;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=_(t);var r=D.test(t);return r||z.test(t)?F(t.slice(2),r?2:8):I.test(t)?T:+t};var M="Expected a function",N=Math.max,q=Math.min;const U=function(t,e,r){var n,o,s,c,a,u,l=0,f=!1,d=!1,_=!0;if("function"!=typeof t)throw new TypeError(M);function p(e){var r=n,s=o;return n=o=void 0,l=e,c=t.apply(s,r)}function y(t){var r=t-u;return void 0===u||r>=e||r<0||d&&t-l>=s}function v(){var t=h();if(y(t))return b(t);a=setTimeout(v,function(t){var r=e-(t-u);return d?q(r,s-(t-l)):r}(t))}function b(t){return a=void 0,_&&n?p(t):(n=o=void 0,c)}function g(){var t=h(),r=y(t);if(n=arguments,o=this,u=t,r){if(void 0===a)return function(t){return l=t,a=setTimeout(v,e),f?p(t):c}(u);if(d)return clearTimeout(a),a=setTimeout(v,e),p(u)}return void 0===a&&(a=setTimeout(v,e)),c}return e=W(e)||0,i(r)&&(f=!!r.leading,s=(d="maxWait"in r)?N(W(r.maxWait)||0,e):s,_="trailing"in r?!!r.trailing:_),g.cancel=function(){void 0!==a&&clearTimeout(a),l=0,n=u=o=a=void 0},g.flush=function(){return void 0===a?c:b(h())},g};var R="Expected a function";const $=function(t,e,r){var n=!0,o=!0;if("function"!=typeof t)throw new TypeError(R);return i(r)&&(n="leading"in r?!!r.leading:n,o="trailing"in r?!!r.trailing:o),U(t,e,{leading:n,maxWait:e,trailing:o})};const L=function(){this.__data__=[],this.size=0};const k=function(t,e){return t===e||t!=t&&e!=e};const H=function(t,e){for(var r=t.length;r--;)if(k(t[r][0],e))return r;return-1};var B=Array.prototype.splice;const Q=function(t){var e=this.__data__,r=H(e,t);return!(r<0)&&(r==e.length-1?e.pop():B.call(e,r,1),--this.size,!0)};const V=function(t){var e=this.__data__,r=H(e,t);return r<0?void 0:e[r][1]};const K=function(t){return H(this.__data__,t)>-1};const G=function(t,e){var r=this.__data__,n=H(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function Y(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Y.prototype.clear=L,Y.prototype.delete=Q,Y.prototype.get=V,Y.prototype.has=K,Y.prototype.set=G;const J=Y;const X=function(){this.__data__=new J,this.size=0};const Z=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r};const tt=function(t){return this.__data__.get(t)};const et=function(t){return this.__data__.has(t)};var rt="[object AsyncFunction]",nt="[object Function]",ot="[object GeneratorFunction]",st="[object Proxy]";const it=function(t){if(!i(t))return!1;var e=A(t);return e==nt||e==ot||e==rt||e==st};const ct=u["__core-js_shared__"];var at,ut=(at=/[^.]+$/.exec(ct&&ct.keys&&ct.keys.IE_PROTO||""))?"Symbol(src)_1."+at:"";const ht=function(t){return!!ut&&ut in t};var lt=Function.prototype.toString;const ft=function(t){if(null!=t){try{return lt.call(t)}catch(t){}try{return t+""}catch(t){}}return""};var dt=/^\[object .+?Constructor\]$/,_t=Function.prototype,pt=Object.prototype,yt=_t.toString,vt=pt.hasOwnProperty,bt=RegExp("^"+yt.call(vt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");const gt=function(t){return!(!i(t)||ht(t))&&(it(t)?bt:dt).test(ft(t))};const mt=function(t,e){return null==t?void 0:t[e]};const jt=function(t,e){var r=mt(t,e);return gt(r)?r:void 0};const wt=jt(u,"Map");const Et=jt(Object,"create");const xt=function(){this.__data__=Et?Et(null):{},this.size=0};const Ot=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e};var At="__lodash_hash_undefined__",Pt=Object.prototype.hasOwnProperty;const St=function(t){var e=this.__data__;if(Et){var r=e[t];return r===At?void 0:r}return Pt.call(e,t)?e[t]:void 0};var Ct=Object.prototype.hasOwnProperty;const Tt=function(t){var e=this.__data__;return Et?void 0!==e[t]:Ct.call(e,t)};var It="__lodash_hash_undefined__";const Dt=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Et&&void 0===e?It:e,this};function zt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}zt.prototype.clear=xt,zt.prototype.delete=Ot,zt.prototype.get=St,zt.prototype.has=Tt,zt.prototype.set=Dt;const Ft=zt;const Wt=function(){this.size=0,this.__data__={hash:new Ft,map:new(wt||J),string:new Ft}};const Mt=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};const Nt=function(t,e){var r=t.__data__;return Mt(e)?r["string"==typeof e?"string":"hash"]:r.map};const qt=function(t){var e=Nt(this,t).delete(t);return this.size-=e?1:0,e};const Ut=function(t){return Nt(this,t).get(t)};const Rt=function(t){return Nt(this,t).has(t)};const $t=function(t,e){var r=Nt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Lt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Lt.prototype.clear=Wt,Lt.prototype.delete=qt,Lt.prototype.get=Ut,Lt.prototype.has=Rt,Lt.prototype.set=$t;const kt=Lt;var Ht=200;const Bt=function(t,e){var r=this.__data__;if(r instanceof J){var n=r.__data__;if(!wt||n.length<Ht-1)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new kt(n)}return r.set(t,e),this.size=r.size,this};function Qt(t){var e=this.__data__=new J(t);this.size=e.size}Qt.prototype.clear=X,Qt.prototype.delete=Z,Qt.prototype.get=tt,Qt.prototype.has=et,Qt.prototype.set=Bt;const Vt=Qt;const Kt=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};const Gt=function(){try{var t=jt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();const Yt=function(t,e,r){"__proto__"==e&&Gt?Gt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var Jt=Object.prototype.hasOwnProperty;const Xt=function(t,e,r){var n=t[e];Jt.call(t,e)&&k(n,r)&&(void 0!==r||e in t)||Yt(t,e,r)};const Zt=function(t,e,r,n){var o=!r;r||(r={});for(var s=-1,i=e.length;++s<i;){var c=e[s],a=n?n(r[c],t[c],c,r,t):void 0;void 0===a&&(a=t[c]),o?Yt(r,c,a):Xt(r,c,a)}return r};const te=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var ee="[object Arguments]";const re=function(t){return P(t)&&A(t)==ee};var ne=Object.prototype,oe=ne.hasOwnProperty,se=ne.propertyIsEnumerable;const ie=re(function(){return arguments}())?re:function(t){return P(t)&&oe.call(t,"callee")&&!se.call(t,"callee")};const ce=Array.isArray;const ae=function(){return!1};var ue="object"==typeof exports&&exports&&!exports.nodeType&&exports,he=ue&&"object"==typeof module&&module&&!module.nodeType&&module,le=he&&he.exports===ue?u.Buffer:void 0;const fe=(le?le.isBuffer:void 0)||ae;var de=9007199254740991,_e=/^(?:0|[1-9]\d*)$/;const pe=function(t,e){var r=typeof t;return!!(e=null==e?de:e)&&("number"==r||"symbol"!=r&&_e.test(t))&&t>-1&&t%1==0&&t<e};var ye=9007199254740991;const ve=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=ye};var be={};be["[object Float32Array]"]=be["[object Float64Array]"]=be["[object Int8Array]"]=be["[object Int16Array]"]=be["[object Int32Array]"]=be["[object Uint8Array]"]=be["[object Uint8ClampedArray]"]=be["[object Uint16Array]"]=be["[object Uint32Array]"]=!0,be["[object Arguments]"]=be["[object Array]"]=be["[object ArrayBuffer]"]=be["[object Boolean]"]=be["[object DataView]"]=be["[object Date]"]=be["[object Error]"]=be["[object Function]"]=be["[object Map]"]=be["[object Number]"]=be["[object Object]"]=be["[object RegExp]"]=be["[object Set]"]=be["[object String]"]=be["[object WeakMap]"]=!1;const ge=function(t){return P(t)&&ve(t.length)&&!!be[A(t)]};const me=function(t){return function(e){return t(e)}};var je="object"==typeof exports&&exports&&!exports.nodeType&&exports,we=je&&"object"==typeof module&&module&&!module.nodeType&&module,Ee=we&&we.exports===je&&c.process;const xe=function(){try{var t=we&&we.require&&we.require("util").types;return t||Ee&&Ee.binding&&Ee.binding("util")}catch(t){}}();var Oe=xe&&xe.isTypedArray;const Ae=Oe?me(Oe):ge;var Pe=Object.prototype.hasOwnProperty;const Se=function(t,e){var r=ce(t),n=!r&&ie(t),o=!r&&!n&&fe(t),s=!r&&!n&&!o&&Ae(t),i=r||n||o||s,c=i?te(t.length,String):[],a=c.length;for(var u in t)!e&&!Pe.call(t,u)||i&&("length"==u||o&&("offset"==u||"parent"==u)||s&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||pe(u,a))||c.push(u);return c};var Ce=Object.prototype;const Te=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ce)};const Ie=function(t,e){return function(r){return t(e(r))}};const De=Ie(Object.keys,Object);var ze=Object.prototype.hasOwnProperty;const Fe=function(t){if(!Te(t))return De(t);var e=[];for(var r in Object(t))ze.call(t,r)&&"constructor"!=r&&e.push(r);return e};const We=function(t){return null!=t&&ve(t.length)&&!it(t)};const Me=function(t){return We(t)?Se(t):Fe(t)};const Ne=function(t,e){return t&&Zt(e,Me(e),t)};const qe=function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e};var Ue=Object.prototype.hasOwnProperty;const Re=function(t){if(!i(t))return qe(t);var e=Te(t),r=[];for(var n in t)("constructor"!=n||!e&&Ue.call(t,n))&&r.push(n);return r};const $e=function(t){return We(t)?Se(t,!0):Re(t)};const Le=function(t,e){return t&&Zt(e,$e(e),t)};var ke="object"==typeof exports&&exports&&!exports.nodeType&&exports,He=ke&&"object"==typeof module&&module&&!module.nodeType&&module,Be=He&&He.exports===ke?u.Buffer:void 0,Qe=Be?Be.allocUnsafe:void 0;const Ve=function(t,e){if(e)return t.slice();var r=t.length,n=Qe?Qe(r):new t.constructor(r);return t.copy(n),n};const Ke=function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e};const Ge=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,s=[];++r<n;){var i=t[r];e(i,r,t)&&(s[o++]=i)}return s};const Ye=function(){return[]};var Je=Object.prototype.propertyIsEnumerable,Xe=Object.getOwnPropertySymbols;const Ze=Xe?function(t){return null==t?[]:(t=Object(t),Ge(Xe(t),(function(e){return Je.call(t,e)})))}:Ye;const tr=function(t,e){return Zt(t,Ze(t),e)};const er=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t};const rr=Ie(Object.getPrototypeOf,Object);const nr=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)er(e,Ze(t)),t=rr(t);return e}:Ye;const or=function(t,e){return Zt(t,nr(t),e)};const sr=function(t,e,r){var n=e(t);return ce(t)?n:er(n,r(t))};const ir=function(t){return sr(t,Me,Ze)};const cr=function(t){return sr(t,$e,nr)};const ar=jt(u,"DataView");const ur=jt(u,"Promise");const hr=jt(u,"Set");const lr=jt(u,"WeakMap");var fr="[object Map]",dr="[object Promise]",_r="[object Set]",pr="[object WeakMap]",yr="[object DataView]",vr=ft(ar),br=ft(wt),gr=ft(ur),mr=ft(hr),jr=ft(lr),wr=A;(ar&&wr(new ar(new ArrayBuffer(1)))!=yr||wt&&wr(new wt)!=fr||ur&&wr(ur.resolve())!=dr||hr&&wr(new hr)!=_r||lr&&wr(new lr)!=pr)&&(wr=function(t){var e=A(t),r="[object Object]"==e?t.constructor:void 0,n=r?ft(r):"";if(n)switch(n){case vr:return yr;case br:return fr;case gr:return dr;case mr:return _r;case jr:return pr}return e});const Er=wr;var xr=Object.prototype.hasOwnProperty;const Or=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&xr.call(t,"index")&&(r.index=t.index,r.input=t.input),r};const Ar=u.Uint8Array;const Pr=function(t){var e=new t.constructor(t.byteLength);return new Ar(e).set(new Ar(t)),e};const Sr=function(t,e){var r=e?Pr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)};var Cr=/\w*$/;const Tr=function(t){var e=new t.constructor(t.source,Cr.exec(t));return e.lastIndex=t.lastIndex,e};var Ir=p?p.prototype:void 0,Dr=Ir?Ir.valueOf:void 0;const zr=function(t){return Dr?Object(Dr.call(t)):{}};const Fr=function(t,e){var r=e?Pr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)};var Wr="[object Boolean]",Mr="[object Date]",Nr="[object Map]",qr="[object Number]",Ur="[object RegExp]",Rr="[object Set]",$r="[object String]",Lr="[object Symbol]",kr="[object ArrayBuffer]",Hr="[object DataView]",Br="[object Float32Array]",Qr="[object Float64Array]",Vr="[object Int8Array]",Kr="[object Int16Array]",Gr="[object Int32Array]",Yr="[object Uint8Array]",Jr="[object Uint8ClampedArray]",Xr="[object Uint16Array]",Zr="[object Uint32Array]";const tn=function(t,e,r){var n=t.constructor;switch(e){case kr:return Pr(t);case Wr:case Mr:return new n(+t);case Hr:return Sr(t,r);case Br:case Qr:case Vr:case Kr:case Gr:case Yr:case Jr:case Xr:case Zr:return Fr(t,r);case Nr:return new n;case qr:case $r:return new n(t);case Ur:return Tr(t);case Rr:return new n;case Lr:return zr(t)}};var en=Object.create;const rn=function(){function t(){}return function(e){if(!i(e))return{};if(en)return en(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();const nn=function(t){return"function"!=typeof t.constructor||Te(t)?{}:rn(rr(t))};var on="[object Map]";const sn=function(t){return P(t)&&Er(t)==on};var cn=xe&&xe.isMap;const an=cn?me(cn):sn;var un="[object Set]";const hn=function(t){return P(t)&&Er(t)==un};var ln=xe&&xe.isSet;const fn=ln?me(ln):hn;var dn=1,_n=2,pn=4,yn="[object Arguments]",vn="[object Function]",bn="[object GeneratorFunction]",gn="[object Object]",mn={};mn[yn]=mn["[object Array]"]=mn["[object ArrayBuffer]"]=mn["[object DataView]"]=mn["[object Boolean]"]=mn["[object Date]"]=mn["[object Float32Array]"]=mn["[object Float64Array]"]=mn["[object Int8Array]"]=mn["[object Int16Array]"]=mn["[object Int32Array]"]=mn["[object Map]"]=mn["[object Number]"]=mn[gn]=mn["[object RegExp]"]=mn["[object Set]"]=mn["[object String]"]=mn["[object Symbol]"]=mn["[object Uint8Array]"]=mn["[object Uint8ClampedArray]"]=mn["[object Uint16Array]"]=mn["[object Uint32Array]"]=!0,mn["[object Error]"]=mn[vn]=mn["[object WeakMap]"]=!1;const jn=function t(e,r,n,o,s,c){var a,u=r&dn,h=r&_n,l=r&pn;if(n&&(a=s?n(e,o,s,c):n(e)),void 0!==a)return a;if(!i(e))return e;var f=ce(e);if(f){if(a=Or(e),!u)return Ke(e,a)}else{var d=Er(e),_=d==vn||d==bn;if(fe(e))return Ve(e,u);if(d==gn||d==yn||_&&!s){if(a=h||_?{}:nn(e),!u)return h?or(e,Le(a,e)):tr(e,Ne(a,e))}else{if(!mn[d])return s?e:{};a=tn(e,d,u)}}c||(c=new Vt);var p=c.get(e);if(p)return p;c.set(e,a),fn(e)?e.forEach((function(o){a.add(t(o,r,n,o,e,c))})):an(e)&&e.forEach((function(o,s){a.set(s,t(o,r,n,s,e,c))}));var y=f?void 0:(l?h?cr:ir:h?$e:Me)(e);return Kt(y||e,(function(o,s){y&&(o=e[s=o]),Xt(a,s,t(o,r,n,s,e,c))})),a};var wn=1,En=4;const xn=function(t,e){return jn(t,wn|En,e="function"==typeof e?e:void 0)};var On="[object Object]",An=Function.prototype,Pn=Object.prototype,Sn=An.toString,Cn=Pn.hasOwnProperty,Tn=Sn.call(Object);const In=function(t){if(!P(t)||A(t)!=On)return!1;var e=rr(t);if(null===e)return!0;var r=Cn.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Sn.call(r)==Tn};const Dn=function(t){return P(t)&&1===t.nodeType&&!In(t)};class zn extends r{constructor(t,e={}){super(e),this._editor=null,this._throttledSave=$(this._save.bind(this),"number"==typeof e.saveInterval?e.saveInterval:5e3),t&&(this._creator=(e,r)=>t.create(e,r)),this._destructor=t=>t.destroy()}get editor(){return this._editor}get _item(){return this._editor}setCreator(t){this._creator=t}setDestructor(t){this._destructor=t}_restart(){return Promise.resolve().then((()=>(this.state="initializing",this._fire("stateChange"),this._destroy()))).catch((t=>{console.error("An error happened during the editor destroying.",t)})).then((()=>{if("string"==typeof this._elementOrData)return this.create(this._data,this._config,this._config.context);{const t=Object.assign({},this._config,{initialData:this._data});return this.create(this._elementOrData,t,t.context)}})).then((()=>{this._fire("restart")}))}create(t=this._elementOrData,e=this._config,r){return Promise.resolve().then((()=>(super._startErrorHandling(),this._elementOrData=t,this._config=this._cloneEditorConfiguration(e)||{},this._config.context=r,this._creator(t,this._config)))).then((t=>{this._editor=t,t.model.document.on("change:data",this._throttledSave),this._lastDocumentVersion=t.model.document.version,this._data=this._getData(),this.state="ready",this._fire("stateChange")}))}destroy(){return Promise.resolve().then((()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy())))}_destroy(){return Promise.resolve().then((()=>{this._stopErrorHandling(),this._throttledSave.flush();const t=this._editor;return this._editor=null,t.model.document.off("change:data",this._throttledSave),this._destructor(t)}))}_save(){const t=this._editor.model.document.version;try{this._data=this._getData(),this._lastDocumentVersion=t}catch(t){console.error(t,"An error happened during restoring editor data. Editor will be restored from the previously saved data.")}}_setExcludedProperties(t){this._excludedProps=t}_getData(){const t={};for(const e of this._editor.model.document.getRootNames())t[e]=this._editor.data.get({rootName:e});return t}_isErrorComingFromThisItem(t){return s(this._editor,t.context,this._excludedProps)}_cloneEditorConfiguration(t){return xn(t,((t,e)=>Dn(t)||"context"===e?t:void 0))}}const Fn=Symbol("MainQueueId");class Wn extends r{constructor(t,e={}){super(e),this._watchdogs=new Map,this._context=null,this._contextProps=new Set,this._actionQueues=new Mn,this._watchdogConfig=e,this._creator=e=>t.create(e),this._destructor=t=>t.destroy(),this._actionQueues.onEmpty((()=>{"initializing"===this.state&&(this.state="ready",this._fire("stateChange"))}))}setCreator(t){this._creator=t}setDestructor(t){this._destructor=t}get context(){return this._context}create(t={}){return this._actionQueues.enqueue(Fn,(()=>(this._contextConfig=t,this._create())))}getItem(t){return this._getWatchdog(t)._item}getItemState(t){return this._getWatchdog(t).state}add(t){const e=Nn(t);return Promise.all(e.map((t=>this._actionQueues.enqueue(t.id,(()=>{if("destroyed"===this.state)throw new Error("Cannot add items to destroyed watchdog.");if(!this._context)throw new Error("Context was not created yet. You should call the `ContextWatchdog#create()` method first.");let e;if(this._watchdogs.has(t.id))throw new Error(`Item with the given id is already added: '${t.id}'.`);if("editor"===t.type)return e=new zn(null,this._watchdogConfig),e.setCreator(t.creator),e._setExcludedProperties(this._contextProps),t.destructor&&e.setDestructor(t.destructor),this._watchdogs.set(t.id,e),e.on("error",((r,{error:n,causesRestart:o})=>{this._fire("itemError",{itemId:t.id,error:n}),o&&this._actionQueues.enqueue(t.id,(()=>new Promise((r=>{const n=()=>{e.off("restart",n),this._fire("itemRestart",{itemId:t.id}),r()};e.on("restart",n)}))))})),e.create(t.sourceElementOrData,t.config,this._context);throw new Error(`Not supported item type: '${t.type}'.`)})))))}remove(t){const e=Nn(t);return Promise.all(e.map((t=>this._actionQueues.enqueue(t,(()=>{const e=this._getWatchdog(t);return this._watchdogs.delete(t),e.destroy()})))))}destroy(){return this._actionQueues.enqueue(Fn,(()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy())))}_restart(){return this._actionQueues.enqueue(Fn,(()=>(this.state="initializing",this._fire("stateChange"),this._destroy().catch((t=>{console.error("An error happened during destroying the context or items.",t)})).then((()=>this._create())).then((()=>this._fire("restart"))))))}_create(){return Promise.resolve().then((()=>(this._startErrorHandling(),this._creator(this._contextConfig)))).then((t=>(this._context=t,this._contextProps=n(this._context),Promise.all(Array.from(this._watchdogs.values()).map((t=>(t._setExcludedProperties(this._contextProps),t.create(void 0,void 0,this._context))))))))}_destroy(){return Promise.resolve().then((()=>{this._stopErrorHandling();const t=this._context;return this._context=null,this._contextProps=new Set,Promise.all(Array.from(this._watchdogs.values()).map((t=>t.destroy()))).then((()=>this._destructor(t)))}))}_getWatchdog(t){const e=this._watchdogs.get(t);if(!e)throw new Error(`Item with the given id was not registered: ${t}.`);return e}_isErrorComingFromThisItem(t){for(const e of this._watchdogs.values())if(e._isErrorComingFromThisItem(t))return!1;return s(this._context,t.context)}}class Mn{constructor(){this._onEmptyCallbacks=[],this._queues=new Map,this._activeActions=0}onEmpty(t){this._onEmptyCallbacks.push(t)}enqueue(t,e){const r=t===Fn;this._activeActions++,this._queues.get(t)||this._queues.set(t,Promise.resolve());const n=(r?Promise.all(this._queues.values()):Promise.all([this._queues.get(Fn),this._queues.get(t)])).then(e),o=n.catch((()=>{}));return this._queues.set(t,o),n.finally((()=>{this._activeActions--,this._queues.get(t)===o&&0===this._activeActions&&this._onEmptyCallbacks.forEach((t=>t()))}))}}function Nn(t){return Array.isArray(t)?t:[t]}(window.CKEditor5=window.CKEditor5||{}).watchdog=e})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-watchdog",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "37.0.0-alpha.0",
|
|
4
4
|
"description": "A watchdog feature for CKEditor 5 editors. It keeps a CKEditor 5 editor instance running.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"lodash-es": "^4.17.15"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@ckeditor/ckeditor5-core": "^
|
|
18
|
-
"@ckeditor/ckeditor5-dev-utils": "^
|
|
19
|
-
"@ckeditor/ckeditor5-editor-classic": "^
|
|
20
|
-
"@ckeditor/ckeditor5-paragraph": "^
|
|
21
|
-
"@ckeditor/ckeditor5-theme-lark": "^
|
|
22
|
-
"@ckeditor/ckeditor5-utils": "^
|
|
23
|
-
"ckeditor5": "^
|
|
17
|
+
"@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
|
|
18
|
+
"@ckeditor/ckeditor5-dev-utils": "^34.0.0",
|
|
19
|
+
"@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
|
|
20
|
+
"@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
|
|
21
|
+
"@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.0",
|
|
22
|
+
"@ckeditor/ckeditor5-utils": "^37.0.0-alpha.0",
|
|
23
|
+
"ckeditor5": "^37.0.0-alpha.0",
|
|
24
|
+
"typescript": "^4.8.4",
|
|
24
25
|
"webpack": "^5.58.1",
|
|
25
26
|
"webpack-cli": "^4.9.0"
|
|
26
27
|
},
|
|
@@ -39,13 +40,17 @@
|
|
|
39
40
|
},
|
|
40
41
|
"files": [
|
|
41
42
|
"lang",
|
|
42
|
-
"src",
|
|
43
|
+
"src/**/*.js",
|
|
44
|
+
"src/**/*.d.ts",
|
|
43
45
|
"theme",
|
|
44
46
|
"build",
|
|
45
47
|
"ckeditor5-metadata.json",
|
|
46
48
|
"CHANGELOG.md"
|
|
47
49
|
],
|
|
48
50
|
"scripts": {
|
|
49
|
-
"dll:build": "webpack"
|
|
50
|
-
|
|
51
|
+
"dll:build": "webpack",
|
|
52
|
+
"build": "tsc -p ./tsconfig.release.json",
|
|
53
|
+
"postversion": "npm run build"
|
|
54
|
+
},
|
|
55
|
+
"types": "src/index.d.ts"
|
|
51
56
|
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module watchdog/contextwatchdog
|
|
7
|
+
*/
|
|
8
|
+
import type { Context, Editor, EditorConfig, ContextConfig } from 'ckeditor5/src/core';
|
|
9
|
+
import type { ArrayOrItem, CKEditorError } from 'ckeditor5/src/utils';
|
|
10
|
+
import Watchdog, { type WatchdogConfig, type WatchdogState } from './watchdog';
|
|
11
|
+
import EditorWatchdog, { type EditorCreatorFunction } from './editorwatchdog';
|
|
12
|
+
/**
|
|
13
|
+
* A watchdog for the {@link module:core/context~Context} class.
|
|
14
|
+
*
|
|
15
|
+
* See the {@glink features/watchdog Watchdog feature guide} to learn the rationale behind it and
|
|
16
|
+
* how to use it.
|
|
17
|
+
*/
|
|
18
|
+
export default class ContextWatchdog<TContext extends Context = Context> extends Watchdog {
|
|
19
|
+
/**
|
|
20
|
+
* A map of internal watchdogs for added items.
|
|
21
|
+
*/
|
|
22
|
+
protected _watchdogs: Map<string, EditorWatchdog<Editor>>;
|
|
23
|
+
/**
|
|
24
|
+
* The watchdog configuration.
|
|
25
|
+
*/
|
|
26
|
+
private readonly _watchdogConfig;
|
|
27
|
+
/**
|
|
28
|
+
* The current context instance.
|
|
29
|
+
*/
|
|
30
|
+
private _context;
|
|
31
|
+
/**
|
|
32
|
+
* Context properties (nodes/references) that are gathered during the initial context creation
|
|
33
|
+
* and are used to distinguish the origin of an error.
|
|
34
|
+
*/
|
|
35
|
+
private _contextProps;
|
|
36
|
+
/**
|
|
37
|
+
* An action queue, which is used to handle async functions queuing.
|
|
38
|
+
*/
|
|
39
|
+
private _actionQueues;
|
|
40
|
+
/**
|
|
41
|
+
* The configuration for the {@link module:core/context~Context}.
|
|
42
|
+
*/
|
|
43
|
+
private _contextConfig?;
|
|
44
|
+
/**
|
|
45
|
+
* The creation method.
|
|
46
|
+
*
|
|
47
|
+
* @see #setCreator
|
|
48
|
+
*/
|
|
49
|
+
protected _creator: (config: ContextConfig) => Promise<TContext>;
|
|
50
|
+
/**
|
|
51
|
+
* The destruction method.
|
|
52
|
+
*
|
|
53
|
+
* @see #setDestructor
|
|
54
|
+
*/
|
|
55
|
+
protected _destructor: (context: Context) => Promise<unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* The watched item.
|
|
58
|
+
*/
|
|
59
|
+
_item: unknown;
|
|
60
|
+
/**
|
|
61
|
+
* The context watchdog class constructor.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const watchdog = new ContextWatchdog( Context );
|
|
65
|
+
*
|
|
66
|
+
* await watchdog.create( contextConfiguration );
|
|
67
|
+
*
|
|
68
|
+
* await watchdog.add( item );
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* See the {@glink features/watchdog Watchdog feature guide} to learn more how to use this feature.
|
|
72
|
+
*
|
|
73
|
+
* @param Context The {@link module:core/context~Context} class.
|
|
74
|
+
* @param watchdogConfig The watchdog configuration.
|
|
75
|
+
*/
|
|
76
|
+
constructor(Context: {
|
|
77
|
+
create(...args: any): Promise<TContext>;
|
|
78
|
+
}, watchdogConfig?: WatchdogConfig);
|
|
79
|
+
/**
|
|
80
|
+
* Sets the function that is responsible for the context creation.
|
|
81
|
+
* It expects a function that should return a promise (or `undefined`).
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* watchdog.setCreator( config => Context.create( config ) );
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
setCreator(creator: (config: ContextConfig) => Promise<TContext>): void;
|
|
88
|
+
/**
|
|
89
|
+
* Sets the function that is responsible for the context destruction.
|
|
90
|
+
* Overrides the default destruction function, which destroys only the context instance.
|
|
91
|
+
* It expects a function that should return a promise (or `undefined`).
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* watchdog.setDestructor( context => {
|
|
95
|
+
* // Do something before the context is destroyed.
|
|
96
|
+
*
|
|
97
|
+
* return context
|
|
98
|
+
* .destroy()
|
|
99
|
+
* .then( () => {
|
|
100
|
+
* // Do something after the context is destroyed.
|
|
101
|
+
* } );
|
|
102
|
+
* } );
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
setDestructor(destructor: (context: Context) => Promise<unknown>): void;
|
|
106
|
+
/**
|
|
107
|
+
* The context instance. Keep in mind that this property might be changed when the context watchdog restarts,
|
|
108
|
+
* so do not keep this instance internally. Always operate on the `ContextWatchdog#context` property.
|
|
109
|
+
*/
|
|
110
|
+
get context(): Context | null;
|
|
111
|
+
/**
|
|
112
|
+
* Initializes the context watchdog. Once it is created, the watchdog takes care about
|
|
113
|
+
* recreating the context and the provided items, and starts the error handling mechanism.
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* await watchdog.create( {
|
|
117
|
+
* plugins: []
|
|
118
|
+
* } );
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @param contextConfig The context configuration. See {@link module:core/context~Context}.
|
|
122
|
+
*/
|
|
123
|
+
create(contextConfig?: ContextConfig): Promise<unknown>;
|
|
124
|
+
/**
|
|
125
|
+
* Returns an item instance with the given `itemId`.
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* const editor1 = watchdog.getItem( 'editor1' );
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param itemId The item ID.
|
|
132
|
+
* @returns The item instance or `undefined` if an item with a given ID has not been found.
|
|
133
|
+
*/
|
|
134
|
+
getItem(itemId: string): unknown;
|
|
135
|
+
/**
|
|
136
|
+
* Gets the state of the given item. See {@link #state} for a list of available states.
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* const editor1State = watchdog.getItemState( 'editor1' );
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param itemId Item ID.
|
|
143
|
+
* @returns The state of the item.
|
|
144
|
+
*/
|
|
145
|
+
getItemState(itemId: string): WatchdogState;
|
|
146
|
+
/**
|
|
147
|
+
* Adds items to the watchdog. Once created, instances of these items will be available using the {@link #getItem} method.
|
|
148
|
+
*
|
|
149
|
+
* Items can be passed together as an array of objects:
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* await watchdog.add( [ {
|
|
153
|
+
* id: 'editor1',
|
|
154
|
+
* type: 'editor',
|
|
155
|
+
* sourceElementOrData: document.querySelector( '#editor' ),
|
|
156
|
+
* config: {
|
|
157
|
+
* plugins: [ Essentials, Paragraph, Bold, Italic ],
|
|
158
|
+
* toolbar: [ 'bold', 'italic', 'alignment' ]
|
|
159
|
+
* },
|
|
160
|
+
* creator: ( element, config ) => ClassicEditor.create( element, config )
|
|
161
|
+
* } ] );
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* Or one by one as objects:
|
|
165
|
+
*
|
|
166
|
+
* ```ts
|
|
167
|
+
* await watchdog.add( {
|
|
168
|
+
* id: 'editor1',
|
|
169
|
+
* type: 'editor',
|
|
170
|
+
* sourceElementOrData: document.querySelector( '#editor' ),
|
|
171
|
+
* config: {
|
|
172
|
+
* plugins: [ Essentials, Paragraph, Bold, Italic ],
|
|
173
|
+
* toolbar: [ 'bold', 'italic', 'alignment' ]
|
|
174
|
+
* },
|
|
175
|
+
* creator: ( element, config ) => ClassicEditor.create( element, config )
|
|
176
|
+
* ] );
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* Then an instance can be retrieved using the {@link #getItem} method:
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* const editor1 = watchdog.getItem( 'editor1' );
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* Note that this method can be called multiple times, but for performance reasons it is better
|
|
186
|
+
* to pass all items together.
|
|
187
|
+
*
|
|
188
|
+
* @param itemConfigurationOrItemConfigurations An item configuration object or an array of item configurations.
|
|
189
|
+
*/
|
|
190
|
+
add(itemConfigurationOrItemConfigurations: ArrayOrItem<WatchdogItemConfiguration>): Promise<unknown>;
|
|
191
|
+
/**
|
|
192
|
+
* Removes and destroys item(s) with given ID(s).
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* await watchdog.remove( 'editor1' );
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* Or
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* await watchdog.remove( [ 'editor1', 'editor2' ] );
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @param itemIdOrItemIds Item ID or an array of item IDs.
|
|
205
|
+
*/
|
|
206
|
+
remove(itemIdOrItemIds: ArrayOrItem<string>): Promise<unknown>;
|
|
207
|
+
/**
|
|
208
|
+
* Destroys the context watchdog and all added items.
|
|
209
|
+
* Once the context watchdog is destroyed, new items cannot be added.
|
|
210
|
+
*
|
|
211
|
+
* ```ts
|
|
212
|
+
* await watchdog.destroy();
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
destroy(): Promise<unknown>;
|
|
216
|
+
/**
|
|
217
|
+
* Restarts the context watchdog.
|
|
218
|
+
*/
|
|
219
|
+
protected _restart(): Promise<unknown>;
|
|
220
|
+
/**
|
|
221
|
+
* Initializes the context watchdog.
|
|
222
|
+
*/
|
|
223
|
+
private _create;
|
|
224
|
+
/**
|
|
225
|
+
* Destroys the context instance and all added items.
|
|
226
|
+
*/
|
|
227
|
+
private _destroy;
|
|
228
|
+
/**
|
|
229
|
+
* Returns the watchdog for a given item ID.
|
|
230
|
+
*
|
|
231
|
+
* @param itemId Item ID.
|
|
232
|
+
*/
|
|
233
|
+
protected _getWatchdog(itemId: string): Watchdog;
|
|
234
|
+
/**
|
|
235
|
+
* Checks whether an error comes from the context instance and not from the item instances.
|
|
236
|
+
*
|
|
237
|
+
* @internal
|
|
238
|
+
*/
|
|
239
|
+
_isErrorComingFromThisItem(error: CKEditorError): boolean;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Fired after the watchdog restarts the context and the added items because of a crash.
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* watchdog.on( 'restart', () => {
|
|
246
|
+
* console.log( 'The context has been restarted.' );
|
|
247
|
+
* } );
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @eventName restart
|
|
251
|
+
*/
|
|
252
|
+
export type ContextWatchdogRestartEvent = {
|
|
253
|
+
name: 'restart';
|
|
254
|
+
args: [];
|
|
255
|
+
return: undefined;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Fired when a new error occurred in one of the added items.
|
|
259
|
+
*
|
|
260
|
+
* ```ts
|
|
261
|
+
* watchdog.on( 'itemError', ( evt, { error, itemId } ) => {
|
|
262
|
+
* console.log( `An error occurred in an item with the '${ itemId }' ID.` );
|
|
263
|
+
* } );
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @eventName itemError
|
|
267
|
+
*/
|
|
268
|
+
export type ContextWatchdogItemErrorEvent = {
|
|
269
|
+
name: 'itemError';
|
|
270
|
+
args: [ContextWatchdogItemErrorEventData];
|
|
271
|
+
return: undefined;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* The `itemError` event data.
|
|
275
|
+
*/
|
|
276
|
+
export type ContextWatchdogItemErrorEventData = {
|
|
277
|
+
itemId: string;
|
|
278
|
+
error: Error;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Fired after an item has been restarted.
|
|
282
|
+
*
|
|
283
|
+
* ```ts
|
|
284
|
+
* watchdog.on( 'itemRestart', ( evt, { itemId } ) => {
|
|
285
|
+
* console.log( 'An item with with the '${ itemId }' ID has been restarted.' );
|
|
286
|
+
* } );
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @eventName itemRestart
|
|
290
|
+
*/
|
|
291
|
+
export type ContextWatchdogItemRestartEvent = {
|
|
292
|
+
name: 'itemRestart';
|
|
293
|
+
args: [ContextWatchdogItemRestartEventData];
|
|
294
|
+
return: undefined;
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* The `itemRestart` event data.
|
|
298
|
+
*/
|
|
299
|
+
export type ContextWatchdogItemRestartEventData = {
|
|
300
|
+
itemId: string;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* The watchdog item configuration interface.
|
|
304
|
+
*/
|
|
305
|
+
export interface WatchdogItemConfiguration {
|
|
306
|
+
/**
|
|
307
|
+
* id A unique item identificator.
|
|
308
|
+
*/
|
|
309
|
+
id: string;
|
|
310
|
+
/**
|
|
311
|
+
* The type of the item to create. At the moment, only `'editor'` is supported.
|
|
312
|
+
*/
|
|
313
|
+
type: 'editor';
|
|
314
|
+
/**
|
|
315
|
+
* A function that initializes the item (the editor). The function takes editor initialization arguments
|
|
316
|
+
* and should return a promise. For example: `( el, config ) => ClassicEditor.create( el, config )`.
|
|
317
|
+
*/
|
|
318
|
+
creator: EditorCreatorFunction;
|
|
319
|
+
/**
|
|
320
|
+
* A function that destroys the item instance (the editor). The function
|
|
321
|
+
* takes an item and should return a promise. For example: `editor => editor.destroy()`
|
|
322
|
+
*/
|
|
323
|
+
destructor?: (editor: Editor) => Promise<unknown>;
|
|
324
|
+
/**
|
|
325
|
+
* The source element or data that will be passed
|
|
326
|
+
* as the first argument to the `Editor.create()` method.
|
|
327
|
+
*/
|
|
328
|
+
sourceElementOrData: string | HTMLElement;
|
|
329
|
+
/**
|
|
330
|
+
* An editor configuration.
|
|
331
|
+
*/
|
|
332
|
+
config: EditorConfig;
|
|
333
|
+
}
|