@ckeditor/ckeditor5-editor-classic 41.4.2 → 42.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/README.md CHANGED
@@ -9,12 +9,18 @@ The classic editor implementation for CKEditor 5.
9
9
 
10
10
  This package contains the [`ClassicEditor`](https://ckeditor.com/docs/ckeditor5/latest/api/module_editor-classic_classiceditor-ClassicEditor.html) class. Follow there to learn more about this type of editor and how to initialize it.
11
11
 
12
- This package contains the source version of the classic editor. This kind of editor implementation is also available as a ready-to-use [classic build](https://www.npmjs.com/package/@ckeditor/ckeditor5-build-classic). Read more about [CKEditor 5 predefined builds](https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/alternative-setups/predefined-builds.html) in the CKEditor 5 documentation.
12
+ This package contains the source version of the classic editor. This kind of editor implementation is also available as a ready-to-use [classic build](https://www.npmjs.com/package/@ckeditor/ckeditor5-build-classic). Read more about [CKEditor 5 predefined builds](https://ckeditor.com/docs/ckeditor5/latest/getting-started/legacy/advanced/alternative-setups/predefined-builds.html) in the CKEditor 5 documentation.
13
13
 
14
14
  ## Documentation
15
15
 
16
16
  See the [`@ckeditor/ckeditor5-editor-classic` package](https://ckeditor.com/docs/ckeditor5/latest/api/editor-classic.html) page in [CKEditor 5 documentation](https://ckeditor.com/docs/ckeditor5/latest/).
17
17
 
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install ckeditor5
22
+ ```
23
+
18
24
  ## License
19
25
 
20
26
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html). For full details about the license, please check the `LICENSE.md` file or [https://ckeditor.com/legal/ckeditor-oss-license](https://ckeditor.com/legal/ckeditor-oss-license).
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
- */(()=>{var e={662:(e,t,o)=>{"use strict";o.d(t,{A:()=>r});var i=o(935),n=o.n(i)()((function(e){return e[1]}));n.push([e.id,".ck.ck-editor{position:relative}.ck.ck-editor .ck-editor__top .ck-sticky-panel .ck-toolbar{z-index:var(--ck-z-panel)}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content{border-radius:0}.ck-rounded-corners .ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content,.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content.ck-rounded-corners{border-radius:var(--ck-border-radius);border-bottom-left-radius:0;border-bottom-right-radius:0}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content{border:solid var(--ck-color-base-border);border-width:1px 1px 0}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content.ck-sticky-panel__content_sticky{border-bottom-width:1px}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content .ck-menu-bar,.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content .ck-toolbar{border:0}.ck.ck-editor__main>.ck-editor__editable{background:var(--ck-color-base-background);border-radius:0}.ck-rounded-corners .ck.ck-editor__main>.ck-editor__editable,.ck.ck-editor__main>.ck-editor__editable.ck-rounded-corners{border-radius:var(--ck-border-radius);border-top-left-radius:0;border-top-right-radius:0}.ck.ck-editor__main>.ck-editor__editable:not(.ck-focused){border-color:var(--ck-color-base-border)}",""]);const r=n},935:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var o=e(t);return t[2]?"@media ".concat(t[2]," {").concat(o,"}"):o})).join("")},t.i=function(e,o,i){"string"==typeof e&&(e=[[null,e,""]]);var n={};if(i)for(var r=0;r<this.length;r++){var c=this[r][0];null!=c&&(n[c]=!0)}for(var a=0;a<e.length;a++){var s=[].concat(e[a]);i&&n[s[0]]||(o&&(s[2]?s[2]="".concat(o," and ").concat(s[2]):s[2]=o),t.push(s))}},t}},591:(e,t,o)=>{"use strict";var i,n=function(){return void 0===i&&(i=Boolean(window&&document&&document.all&&!window.atob)),i},r=function(){var e={};return function(t){if(void 0===e[t]){var o=document.querySelector(t);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}e[t]=o}return e[t]}}(),c=[];function a(e){for(var t=-1,o=0;o<c.length;o++)if(c[o].identifier===e){t=o;break}return t}function s(e,t){for(var o={},i=[],n=0;n<e.length;n++){var r=e[n],s=t.base?r[0]+t.base:r[0],l=o[s]||0,d="".concat(s," ").concat(l);o[s]=l+1;var u=a(d),h={css:r[1],media:r[2],sourceMap:r[3]};-1!==u?(c[u].references++,c[u].updater(h)):c.push({identifier:d,updater:k(h,t),references:1}),i.push(d)}return i}function l(e){var t=document.createElement("style"),i=e.attributes||{};if(void 0===i.nonce){var n=o.nc;n&&(i.nonce=n)}if(Object.keys(i).forEach((function(e){t.setAttribute(e,i[e])})),"function"==typeof e.insert)e.insert(t);else{var c=r(e.insert||"head");if(!c)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");c.appendChild(t)}return t}var d,u=(d=[],function(e,t){return d[e]=t,d.filter(Boolean).join("\n")});function h(e,t,o,i){var n=o?"":i.media?"@media ".concat(i.media," {").concat(i.css,"}"):i.css;if(e.styleSheet)e.styleSheet.cssText=u(t,n);else{var r=document.createTextNode(n),c=e.childNodes;c[t]&&e.removeChild(c[t]),c.length?e.insertBefore(r,c[t]):e.appendChild(r)}}function p(e,t,o){var i=o.css,n=o.media,r=o.sourceMap;if(n?e.setAttribute("media",n):e.removeAttribute("media"),r&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleSheet)e.styleSheet.cssText=i;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(i))}}var f=null,b=0;function k(e,t){var o,i,n;if(t.singleton){var r=b++;o=f||(f=l(t)),i=h.bind(null,o,r,!1),n=h.bind(null,o,r,!0)}else o=l(t),i=p.bind(null,o,t),n=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(o)};return i(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;i(e=t)}else n()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=n());var o=s(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var i=0;i<o.length;i++){var n=a(o[i]);c[n].references--}for(var r=s(e,t),l=0;l<o.length;l++){var d=a(o[l]);0===c[d].references&&(c[d].updater(),c.splice(d,1))}o=r}}}},782:(e,t,o)=>{e.exports=o(237)("./src/core.js")},783:(e,t,o)=>{e.exports=o(237)("./src/engine.js")},311:(e,t,o)=>{e.exports=o(237)("./src/ui.js")},584:(e,t,o)=>{e.exports=o(237)("./src/utils.js")},602:(e,t,o)=>{e.exports=o(237)("./src/watchdog.js")},237:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function o(i){var n=t[i];if(void 0!==n)return n.exports;var r=t[i]={id:i,exports:{}};return e[i](r,r.exports,o),r.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.nc=void 0;var i={};(()=>{"use strict";o.r(i),o.d(i,{ClassicEditor:()=>V});var e=o(311),t=o(783),n=o(584);class r extends e.EditorUI{constructor(t,o){super(t),this.view=o,this._toolbarConfig=(0,e.normalizeToolbarConfig)(t.config.get("toolbar")),this._elementReplacer=new n.ElementReplacer,this.listenTo(t.editing.view,"scrollToTheSelection",this._handleScrollToTheSelectionWithStickyPanel.bind(this))}get element(){return this.view.element}init(t){const o=this.editor,i=this.view,n=o.editing.view,r=i.editable,c=n.document.getRoot();r.name=c.rootName,i.render();const a=r.element;this.setEditableElement(r.name,a),i.editable.bind("isFocused").to(this.focusTracker),n.attachDomRoot(a),t&&this._elementReplacer.replace(t,this.element),this._initPlaceholder(),this._initToolbar(),i.menuBarView&&(0,e._initMenuBar)(o,i.menuBarView),this._initDialogPluginIntegration(),this.fire("ready")}destroy(){super.destroy();const e=this.view,t=this.editor.editing.view;this._elementReplacer.restore(),t.detachDomRoot(e.editable.name),e.destroy()}_initToolbar(){const e=this.view;e.stickyPanel.bind("isActive").to(this.focusTracker,"isFocused"),e.stickyPanel.limiterElement=e.element,e.stickyPanel.bind("viewportTopOffset").to(this,"viewportOffset",(({top:e})=>e||0)),e.toolbar.fillFromConfig(this._toolbarConfig,this.componentFactory),this.addToolbar(e.toolbar)}_initPlaceholder(){const e=this.editor,o=e.editing.view,i=o.document.getRoot(),n=e.sourceElement;let r;const c=e.config.get("placeholder");c&&(r="string"==typeof c?c:c[this.view.editable.name]),!r&&n&&"textarea"===n.tagName.toLowerCase()&&(r=n.getAttribute("placeholder")),r&&(i.placeholder=r),(0,t.enablePlaceholder)({view:o,element:i,isDirectHost:!1,keepOnFocus:!0})}_handleScrollToTheSelectionWithStickyPanel(e,t,o){const i=this.view.stickyPanel;if(i.isSticky){const e=new n.Rect(i.element).height;t.viewportOffset.top+=e}else{const e=()=>{this.editor.editing.view.scrollToTheSelection(o)};this.listenTo(i,"change:isSticky",e),setTimeout((()=>{this.stopListening(i,"change:isSticky",e)}),20)}}_initDialogPluginIntegration(){if(!this.editor.plugins.has("Dialog"))return;const t=this.view.stickyPanel,o=this.editor.plugins.get("Dialog");o.on("show",(()=>{const i=o.view;i.on("moveTo",((o,r)=>{if(!t.isSticky||i.wasMoved)return;const c=new n.Rect(t.contentPanelElement);r[1]<c.bottom+e.DialogView.defaultOffset&&(r[1]=c.bottom+e.DialogView.defaultOffset)}),{priority:"high"})}),{priority:"low"})}}var c=o(591),a=o.n(c),s=o(662),l={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};a()(s.A,l);s.A.locals;class d extends e.BoxedEditorUIView{constructor(t,o,i={}){super(t),this.stickyPanel=new e.StickyPanelView(t),this.toolbar=new e.ToolbarView(t,{shouldGroupWhenFull:i.shouldToolbarGroupWhenFull}),i.useMenuBar&&(this.menuBarView=new e.MenuBarView(t)),this.editable=new e.InlineEditableUIView(t,o)}render(){super.render(),this.menuBarView?this.stickyPanel.content.addMany([this.menuBarView,this.toolbar]):this.stickyPanel.content.add(this.toolbar),this.top.add(this.stickyPanel),this.main.add(this.editable)}}var u=o(782),h=o(602);const p=function(e){return null!=e&&"object"==typeof e};const f="object"==typeof global&&global&&global.Object===Object&&global;var b="object"==typeof self&&self&&self.Object===Object&&self;const k=(f||b||Function("return this")()).Symbol;var g=Object.prototype,v=g.hasOwnProperty,m=g.toString,y=k?k.toStringTag:void 0;const w=function(e){var t=v.call(e,y),o=e[y];try{e[y]=void 0;var i=!0}catch(e){}var n=m.call(e);return i&&(t?e[y]=o:delete e[y]),n};var _=Object.prototype.toString;const T=function(e){return _.call(e)};var j=k?k.toStringTag:void 0;const S=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":j&&j in Object(e)?w(e):T(e)};const x=function(e,t){return function(o){return e(t(o))}}(Object.getPrototypeOf,Object);var O=Function.prototype,E=Object.prototype,P=O.toString,C=E.hasOwnProperty,M=P.call(Object);const B=function(e){if(!p(e)||"[object Object]"!=S(e))return!1;var t=x(e);if(null===t)return!0;var o=C.call(t,"constructor")&&t.constructor;return"function"==typeof o&&o instanceof o&&P.call(o)==M};const D=function(e){return p(e)&&1===e.nodeType&&!B(e)};class F extends((0,u.ElementApiMixin)(u.Editor)){constructor(e,t={}){if(!R(e)&&void 0!==t.initialData)throw new n.CKEditorError("editor-create-initial-data",null);super(t),this.config.define("menuBar.isVisible",!1),void 0===this.config.get("initialData")&&this.config.set("initialData",function(e){return R(e)?(0,n.getDataFromElement)(e):e}(e)),R(e)&&(this.sourceElement=e),this.model.document.createRoot();const o=!this.config.get("toolbar.shouldNotGroupWhenFull"),i=this.config.get("menuBar"),c=new d(this.locale,this.editing.view,{shouldToolbarGroupWhenFull:o,useMenuBar:i.isVisible});this.ui=new r(this,c),(0,u.attachToForm)(this)}destroy(){return this.sourceElement&&this.updateSourceElement(),this.ui.destroy(),super.destroy()}static create(e,t={}){return new Promise((o=>{const i=new this(e,t);o(i.initPlugins().then((()=>i.ui.init(R(e)?e:null))).then((()=>i.data.init(i.config.get("initialData")))).then((()=>i.fire("ready"))).then((()=>i)))}))}}F.Context=u.Context,F.EditorWatchdog=h.EditorWatchdog,F.ContextWatchdog=h.ContextWatchdog;const V=F;function R(e){return D(e)}})(),(window.CKEditor5=window.CKEditor5||{}).editorClassic=i})();
4
+ */(()=>{var e={662:(e,t,o)=>{"use strict";o.d(t,{A:()=>r});var i=o(935),n=o.n(i)()((function(e){return e[1]}));n.push([e.id,".ck.ck-editor{position:relative}.ck.ck-editor .ck-editor__top .ck-sticky-panel .ck-toolbar{z-index:var(--ck-z-panel)}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content{border-radius:0}.ck-rounded-corners .ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content,.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content.ck-rounded-corners{border-radius:var(--ck-border-radius);border-bottom-left-radius:0;border-bottom-right-radius:0}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content{border:solid var(--ck-color-base-border);border-width:1px 1px 0}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content.ck-sticky-panel__content_sticky{border-bottom-width:1px}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content .ck-menu-bar{border:0;border-bottom:1px solid var(--ck-color-base-border)}.ck.ck-editor__top .ck-sticky-panel .ck-sticky-panel__content .ck-toolbar{border:0}.ck.ck-editor__main>.ck-editor__editable{background:var(--ck-color-base-background);border-radius:0}.ck-rounded-corners .ck.ck-editor__main>.ck-editor__editable,.ck.ck-editor__main>.ck-editor__editable.ck-rounded-corners{border-radius:var(--ck-border-radius);border-top-left-radius:0;border-top-right-radius:0}.ck.ck-editor__main>.ck-editor__editable:not(.ck-focused){border-color:var(--ck-color-base-border)}",""]);const r=n},935:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var o=e(t);return t[2]?"@media ".concat(t[2]," {").concat(o,"}"):o})).join("")},t.i=function(e,o,i){"string"==typeof e&&(e=[[null,e,""]]);var n={};if(i)for(var r=0;r<this.length;r++){var c=this[r][0];null!=c&&(n[c]=!0)}for(var a=0;a<e.length;a++){var s=[].concat(e[a]);i&&n[s[0]]||(o&&(s[2]?s[2]="".concat(o," and ").concat(s[2]):s[2]=o),t.push(s))}},t}},591:(e,t,o)=>{"use strict";var i,n=function(){return void 0===i&&(i=Boolean(window&&document&&document.all&&!window.atob)),i},r=function(){var e={};return function(t){if(void 0===e[t]){var o=document.querySelector(t);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}e[t]=o}return e[t]}}(),c=[];function a(e){for(var t=-1,o=0;o<c.length;o++)if(c[o].identifier===e){t=o;break}return t}function s(e,t){for(var o={},i=[],n=0;n<e.length;n++){var r=e[n],s=t.base?r[0]+t.base:r[0],l=o[s]||0,d="".concat(s," ").concat(l);o[s]=l+1;var u=a(d),h={css:r[1],media:r[2],sourceMap:r[3]};-1!==u?(c[u].references++,c[u].updater(h)):c.push({identifier:d,updater:k(h,t),references:1}),i.push(d)}return i}function l(e){var t=document.createElement("style"),i=e.attributes||{};if(void 0===i.nonce){var n=o.nc;n&&(i.nonce=n)}if(Object.keys(i).forEach((function(e){t.setAttribute(e,i[e])})),"function"==typeof e.insert)e.insert(t);else{var c=r(e.insert||"head");if(!c)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");c.appendChild(t)}return t}var d,u=(d=[],function(e,t){return d[e]=t,d.filter(Boolean).join("\n")});function h(e,t,o,i){var n=o?"":i.media?"@media ".concat(i.media," {").concat(i.css,"}"):i.css;if(e.styleSheet)e.styleSheet.cssText=u(t,n);else{var r=document.createTextNode(n),c=e.childNodes;c[t]&&e.removeChild(c[t]),c.length?e.insertBefore(r,c[t]):e.appendChild(r)}}function p(e,t,o){var i=o.css,n=o.media,r=o.sourceMap;if(n?e.setAttribute("media",n):e.removeAttribute("media"),r&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleSheet)e.styleSheet.cssText=i;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(i))}}var f=null,b=0;function k(e,t){var o,i,n;if(t.singleton){var r=b++;o=f||(f=l(t)),i=h.bind(null,o,r,!1),n=h.bind(null,o,r,!0)}else o=l(t),i=p.bind(null,o,t),n=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(o)};return i(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;i(e=t)}else n()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=n());var o=s(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var i=0;i<o.length;i++){var n=a(o[i]);c[n].references--}for(var r=s(e,t),l=0;l<o.length;l++){var d=a(o[l]);0===c[d].references&&(c[d].updater(),c.splice(d,1))}o=r}}}},782:(e,t,o)=>{e.exports=o(237)("./src/core.js")},783:(e,t,o)=>{e.exports=o(237)("./src/engine.js")},311:(e,t,o)=>{e.exports=o(237)("./src/ui.js")},584:(e,t,o)=>{e.exports=o(237)("./src/utils.js")},237:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function o(i){var n=t[i];if(void 0!==n)return n.exports;var r=t[i]={id:i,exports:{}};return e[i](r,r.exports,o),r.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.nc=void 0;var i={};(()=>{"use strict";o.r(i),o.d(i,{ClassicEditor:()=>D});var e=o(311),t=o(783),n=o(584);class r extends e.EditorUI{constructor(t,o){super(t),this.view=o,this._toolbarConfig=(0,e.normalizeToolbarConfig)(t.config.get("toolbar")),this._elementReplacer=new n.ElementReplacer,this.listenTo(t.editing.view,"scrollToTheSelection",this._handleScrollToTheSelectionWithStickyPanel.bind(this))}get element(){return this.view.element}init(t){const o=this.editor,i=this.view,n=o.editing.view,r=i.editable,c=n.document.getRoot();r.name=c.rootName,i.render();const a=r.element;this.setEditableElement(r.name,a),i.editable.bind("isFocused").to(this.focusTracker),n.attachDomRoot(a),t&&this._elementReplacer.replace(t,this.element),this._initPlaceholder(),this._initToolbar(),i.menuBarView&&(0,e._initMenuBar)(o,i.menuBarView),this._initDialogPluginIntegration(),this.fire("ready")}destroy(){super.destroy();const e=this.view,t=this.editor.editing.view;this._elementReplacer.restore(),t.detachDomRoot(e.editable.name),e.destroy()}_initToolbar(){const e=this.view;e.stickyPanel.bind("isActive").to(this.focusTracker,"isFocused"),e.stickyPanel.limiterElement=e.element,e.stickyPanel.bind("viewportTopOffset").to(this,"viewportOffset",(({top:e})=>e||0)),e.toolbar.fillFromConfig(this._toolbarConfig,this.componentFactory),this.addToolbar(e.toolbar)}_initPlaceholder(){const e=this.editor,o=e.editing.view,i=o.document.getRoot(),n=e.sourceElement;let r;const c=e.config.get("placeholder");c&&(r="string"==typeof c?c:c[this.view.editable.name]),!r&&n&&"textarea"===n.tagName.toLowerCase()&&(r=n.getAttribute("placeholder")),r&&(i.placeholder=r),(0,t.enablePlaceholder)({view:o,element:i,isDirectHost:!1,keepOnFocus:!0})}_handleScrollToTheSelectionWithStickyPanel(e,t,o){const i=this.view.stickyPanel;if(i.isSticky){const e=new n.Rect(i.element).height;t.viewportOffset.top+=e}else{const e=()=>{this.editor.editing.view.scrollToTheSelection(o)};this.listenTo(i,"change:isSticky",e),setTimeout((()=>{this.stopListening(i,"change:isSticky",e)}),20)}}_initDialogPluginIntegration(){if(!this.editor.plugins.has("Dialog"))return;const t=this.view.stickyPanel,o=this.editor.plugins.get("Dialog");o.on("show",(()=>{const i=o.view;i.on("moveTo",((o,r)=>{if(!t.isSticky||i.wasMoved)return;const c=new n.Rect(t.contentPanelElement);r[1]<c.bottom+e.DialogView.defaultOffset&&(r[1]=c.bottom+e.DialogView.defaultOffset)}),{priority:"high"})}),{priority:"low"})}}var c=o(591),a=o.n(c),s=o(662),l={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};a()(s.A,l);s.A.locals;class d extends e.BoxedEditorUIView{constructor(t,o,i={}){super(t),this.stickyPanel=new e.StickyPanelView(t),this.toolbar=new e.ToolbarView(t,{shouldGroupWhenFull:i.shouldToolbarGroupWhenFull}),i.useMenuBar&&(this.menuBarView=new e.MenuBarView(t)),this.editable=new e.InlineEditableUIView(t,o)}render(){super.render(),this.menuBarView?this.stickyPanel.content.addMany([this.menuBarView,this.toolbar]):this.stickyPanel.content.add(this.toolbar),this.top.add(this.stickyPanel),this.main.add(this.editable)}}var u=o(782);const h=function(e){return null!=e&&"object"==typeof e};const p="object"==typeof global&&global&&global.Object===Object&&global;var f="object"==typeof self&&self&&self.Object===Object&&self;const b=(p||f||Function("return this")()).Symbol;var k=Object.prototype,v=k.hasOwnProperty,m=k.toString,g=b?b.toStringTag:void 0;const y=function(e){var t=v.call(e,g),o=e[g];try{e[g]=void 0;var i=!0}catch(e){}var n=m.call(e);return i&&(t?e[g]=o:delete e[g]),n};var w=Object.prototype.toString;const _=function(e){return w.call(e)};var T=b?b.toStringTag:void 0;const S=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":T&&T in Object(e)?y(e):_(e)};const j=function(e,t){return function(o){return e(t(o))}}(Object.getPrototypeOf,Object);var O=Function.prototype,P=Object.prototype,x=O.toString,E=P.hasOwnProperty,C=x.call(Object);const M=function(e){if(!h(e)||"[object Object]"!=S(e))return!1;var t=j(e);if(null===t)return!0;var o=E.call(t,"constructor")&&t.constructor;return"function"==typeof o&&o instanceof o&&x.call(o)==C};const B=function(e){return h(e)&&1===e.nodeType&&!M(e)};class D extends((0,u.ElementApiMixin)(u.Editor)){constructor(e,t={}){if(!F(e)&&void 0!==t.initialData)throw new n.CKEditorError("editor-create-initial-data",null);super(t),this.config.define("menuBar.isVisible",!1),void 0===this.config.get("initialData")&&this.config.set("initialData",function(e){return F(e)?(0,n.getDataFromElement)(e):e}(e)),F(e)&&(this.sourceElement=e),this.model.document.createRoot();const o=!this.config.get("toolbar.shouldNotGroupWhenFull"),i=this.config.get("menuBar"),c=new d(this.locale,this.editing.view,{shouldToolbarGroupWhenFull:o,useMenuBar:i.isVisible});this.ui=new r(this,c),(0,u.attachToForm)(this)}destroy(){return this.sourceElement&&this.updateSourceElement(),this.ui.destroy(),super.destroy()}static create(e,t={}){return new Promise((o=>{const i=new this(e,t);o(i.initPlugins().then((()=>i.ui.init(F(e)?e:null))).then((()=>i.data.init(i.config.get("initialData")))).then((()=>i.fire("ready"))).then((()=>i)))}))}}function F(e){return B(e)}})(),(window.CKEditor5=window.CKEditor5||{}).editorClassic=i})();
package/dist/index.js CHANGED
@@ -2,24 +2,46 @@
2
2
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- import { EditorUI, _initMenuBar, DialogView, normalizeToolbarConfig, BoxedEditorUIView, StickyPanelView, ToolbarView, MenuBarView, InlineEditableUIView } from '@ckeditor/ckeditor5-ui/dist/index.js';
5
+ import { EditorUI, normalizeToolbarConfig, _initMenuBar, DialogView, BoxedEditorUIView, StickyPanelView, ToolbarView, MenuBarView, InlineEditableUIView } from '@ckeditor/ckeditor5-ui/dist/index.js';
6
6
  import { enablePlaceholder } from '@ckeditor/ckeditor5-engine/dist/index.js';
7
- import { Rect, ElementReplacer, CKEditorError, getDataFromElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
- import { ElementApiMixin, Editor, attachToForm, Context } from '@ckeditor/ckeditor5-core/dist/index.js';
9
- import { EditorWatchdog, ContextWatchdog } from '@ckeditor/ckeditor5-watchdog/dist/index.js';
7
+ import { ElementReplacer, Rect, CKEditorError, getDataFromElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
+ import { ElementApiMixin, Editor, attachToForm } from '@ckeditor/ckeditor5-core/dist/index.js';
10
9
  import { isElement as isElement$1 } from 'lodash-es';
11
10
 
12
- class ClassicEditorUI extends EditorUI {
11
+ /**
12
+ * The classic editor UI class.
13
+ */ class ClassicEditorUI extends EditorUI {
14
+ /**
15
+ * The main (top–most) view of the editor UI.
16
+ */ view;
17
+ /**
18
+ * A normalized `config.toolbar` object.
19
+ */ _toolbarConfig;
20
+ /**
21
+ * The element replacer instance used to hide the editor's source element.
22
+ */ _elementReplacer;
23
+ /**
24
+ * Creates an instance of the classic editor UI class.
25
+ *
26
+ * @param editor The editor instance.
27
+ * @param view The view of the UI.
28
+ */ constructor(editor, view){
29
+ super(editor);
30
+ this.view = view;
31
+ this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
32
+ this._elementReplacer = new ElementReplacer();
33
+ this.listenTo(editor.editing.view, 'scrollToTheSelection', this._handleScrollToTheSelectionWithStickyPanel.bind(this));
34
+ }
13
35
  /**
14
- * @inheritDoc
15
- */ get element() {
36
+ * @inheritDoc
37
+ */ get element() {
16
38
  return this.view.element;
17
39
  }
18
40
  /**
19
- * Initializes the UI.
20
- *
21
- * @param replacementElement The DOM element that will be the source for the created editor.
22
- */ init(replacementElement) {
41
+ * Initializes the UI.
42
+ *
43
+ * @param replacementElement The DOM element that will be the source for the created editor.
44
+ */ init(replacementElement) {
23
45
  const editor = this.editor;
24
46
  const view = this.view;
25
47
  const editingView = editor.editing.view;
@@ -61,8 +83,8 @@ class ClassicEditorUI extends EditorUI {
61
83
  this.fire('ready');
62
84
  }
63
85
  /**
64
- * @inheritDoc
65
- */ destroy() {
86
+ * @inheritDoc
87
+ */ destroy() {
66
88
  super.destroy();
67
89
  const view = this.view;
68
90
  const editingView = this.editor.editing.view;
@@ -71,8 +93,8 @@ class ClassicEditorUI extends EditorUI {
71
93
  view.destroy();
72
94
  }
73
95
  /**
74
- * Initializes the editor toolbar.
75
- */ _initToolbar() {
96
+ * Initializes the editor toolbar.
97
+ */ _initToolbar() {
76
98
  const view = this.view;
77
99
  // Set–up the sticky panel with toolbar.
78
100
  view.stickyPanel.bind('isActive').to(this.focusTracker, 'isFocused');
@@ -83,8 +105,8 @@ class ClassicEditorUI extends EditorUI {
83
105
  this.addToolbar(view.toolbar);
84
106
  }
85
107
  /**
86
- * Enable the placeholder text on the editing root.
87
- */ _initPlaceholder() {
108
+ * Enable the placeholder text on the editing root.
109
+ */ _initPlaceholder() {
88
110
  const editor = this.editor;
89
111
  const editingView = editor.editing.view;
90
112
  const editingRoot = editingView.document.getRoot();
@@ -108,15 +130,15 @@ class ClassicEditorUI extends EditorUI {
108
130
  });
109
131
  }
110
132
  /**
111
- * Provides an integration between the sticky toolbar and {@link module:utils/dom/scroll~scrollViewportToShowTarget}.
112
- * It allows the UI-agnostic engine method to consider the geometry of the
113
- * {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#stickyPanel} that pins to the
114
- * edge of the viewport and can obscure the user caret after scrolling the window.
115
- *
116
- * @param evt The `scrollToTheSelection` event info.
117
- * @param data The payload carried by the `scrollToTheSelection` event.
118
- * @param originalArgs The original arguments passed to `scrollViewportToShowTarget()` method (see implementation to learn more).
119
- */ _handleScrollToTheSelectionWithStickyPanel(evt, data, originalArgs) {
133
+ * Provides an integration between the sticky toolbar and {@link module:utils/dom/scroll~scrollViewportToShowTarget}.
134
+ * It allows the UI-agnostic engine method to consider the geometry of the
135
+ * {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#stickyPanel} that pins to the
136
+ * edge of the viewport and can obscure the user caret after scrolling the window.
137
+ *
138
+ * @param evt The `scrollToTheSelection` event info.
139
+ * @param data The payload carried by the `scrollToTheSelection` event.
140
+ * @param originalArgs The original arguments passed to `scrollViewportToShowTarget()` method (see implementation to learn more).
141
+ */ _handleScrollToTheSelectionWithStickyPanel(evt, data, originalArgs) {
120
142
  const stickyPanel = this.view.stickyPanel;
121
143
  if (stickyPanel.isSticky) {
122
144
  const stickyPanelHeight = new Rect(stickyPanel.element).height;
@@ -134,12 +156,12 @@ class ClassicEditorUI extends EditorUI {
134
156
  }
135
157
  }
136
158
  /**
137
- * Provides an integration between the sticky toolbar and {@link module:ui/dialog/dialog the Dialog plugin}.
138
- *
139
- * It moves the dialog down to ensure that the
140
- * {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#stickyPanel sticky panel}
141
- * used by the editor UI will not get obscured by the dialog when the dialog uses one of its automatic positions.
142
- */ _initDialogPluginIntegration() {
159
+ * Provides an integration between the sticky toolbar and {@link module:ui/dialog/dialog the Dialog plugin}.
160
+ *
161
+ * It moves the dialog down to ensure that the
162
+ * {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#stickyPanel sticky panel}
163
+ * used by the editor UI will not get obscured by the dialog when the dialog uses one of its automatic positions.
164
+ */ _initDialogPluginIntegration() {
143
165
  if (!this.editor.plugins.has('Dialog')) {
144
166
  return;
145
167
  }
@@ -163,24 +185,48 @@ class ClassicEditorUI extends EditorUI {
163
185
  priority: 'low'
164
186
  });
165
187
  }
166
- /**
167
- * Creates an instance of the classic editor UI class.
168
- *
169
- * @param editor The editor instance.
170
- * @param view The view of the UI.
171
- */ constructor(editor, view){
172
- super(editor);
173
- this.view = view;
174
- this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
175
- this._elementReplacer = new ElementReplacer();
176
- this.listenTo(editor.editing.view, 'scrollToTheSelection', this._handleScrollToTheSelectionWithStickyPanel.bind(this));
177
- }
178
188
  }
179
189
 
180
- class ClassicEditorUIView extends BoxedEditorUIView {
190
+ /**
191
+ * Classic editor UI view. Uses an inline editable and a sticky toolbar, all
192
+ * enclosed in a boxed UI view.
193
+ */ class ClassicEditorUIView extends BoxedEditorUIView {
194
+ /**
195
+ * Sticky panel view instance. This is a parent view of a {@link #toolbar}
196
+ * that makes toolbar sticky.
197
+ */ stickyPanel;
181
198
  /**
182
- * @inheritDoc
183
- */ render() {
199
+ * Toolbar view instance.
200
+ */ toolbar;
201
+ /**
202
+ * Menu bar view instance.
203
+ */ menuBarView;
204
+ /**
205
+ * Editable UI view.
206
+ */ editable;
207
+ /**
208
+ * Creates an instance of the classic editor UI view.
209
+ *
210
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
211
+ * @param editingView The editing view instance this view is related to.
212
+ * @param options Configuration options for the view instance.
213
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
214
+ * in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
215
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
216
+ */ constructor(locale, editingView, options = {}){
217
+ super(locale);
218
+ this.stickyPanel = new StickyPanelView(locale);
219
+ this.toolbar = new ToolbarView(locale, {
220
+ shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
221
+ });
222
+ if (options.useMenuBar) {
223
+ this.menuBarView = new MenuBarView(locale);
224
+ }
225
+ this.editable = new InlineEditableUIView(locale, editingView);
226
+ }
227
+ /**
228
+ * @inheritDoc
229
+ */ render() {
184
230
  super.render();
185
231
  if (this.menuBarView) {
186
232
  // Set toolbar as a child of a stickyPanel and makes toolbar sticky.
@@ -194,180 +240,29 @@ class ClassicEditorUIView extends BoxedEditorUIView {
194
240
  this.top.add(this.stickyPanel);
195
241
  this.main.add(this.editable);
196
242
  }
197
- /**
198
- * Creates an instance of the classic editor UI view.
199
- *
200
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
201
- * @param editingView The editing view instance this view is related to.
202
- * @param options Configuration options for the view instance.
203
- * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
204
- * in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
205
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
206
- */ constructor(locale, editingView, options = {}){
207
- super(locale);
208
- this.stickyPanel = new StickyPanelView(locale);
209
- this.toolbar = new ToolbarView(locale, {
210
- shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
211
- });
212
- if (options.useMenuBar) {
213
- this.menuBarView = new MenuBarView(locale);
214
- }
215
- this.editable = new InlineEditableUIView(locale, editingView);
216
- }
217
243
  }
218
244
 
219
245
  /**
220
- * The {@glink installation/getting-started/predefined-builds#classic-editor classic editor} implementation.
221
- * It uses an inline editable and a sticky toolbar, all enclosed in a boxed UI.
246
+ * The classic editor implementation. It uses an inline editable and a sticky toolbar, all enclosed in a boxed UI.
222
247
  * See the {@glink examples/builds/classic-editor demo}.
223
248
  *
224
249
  * In order to create a classic editor instance, use the static
225
250
  * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method.
226
- *
227
- * # Classic editor and classic build
228
- *
229
- * The classic editor can be used directly from source (if you installed the
230
- * [`@ckeditor/ckeditor5-editor-classic`](https://www.npmjs.com/package/@ckeditor/ckeditor5-editor-classic) package)
231
- * but it is also available in the {@glink installation/getting-started/predefined-builds#classic-editor classic build}.
232
- *
233
- * {@glink installation/getting-started/predefined-builds Builds}
234
- * are ready-to-use editors with plugins bundled in. When using the editor from
235
- * source you need to take care of loading all plugins by yourself
236
- * (through the {@link module:core/editor/editorconfig~EditorConfig#plugins `config.plugins`} option).
237
- * Using the editor from source gives much better flexibility and allows easier customization.
238
- *
239
- * Read more about initializing the editor from source or as a build in
240
- * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
241
- */ class ClassicEditor extends ElementApiMixin(Editor) {
242
- /**
243
- * Destroys the editor instance, releasing all resources used by it.
244
- *
245
- * Updates the original editor element with the data if the
246
- * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
247
- * configuration option is set to `true`.
248
- */ destroy() {
249
- if (this.sourceElement) {
250
- this.updateSourceElement();
251
- }
252
- this.ui.destroy();
253
- return super.destroy();
254
- }
251
+ */ class ClassicEditor extends /* #__PURE__ */ ElementApiMixin(Editor) {
255
252
  /**
256
- * Creates a new classic editor instance.
257
- *
258
- * There are three ways how the editor can be initialized.
259
- *
260
- * # Replacing a DOM element (and loading data from it)
261
- *
262
- * You can initialize the editor using an existing DOM element:
263
- *
264
- * ```ts
265
- * ClassicEditor
266
- * .create( document.querySelector( '#editor' ) )
267
- * .then( editor => {
268
- * console.log( 'Editor was initialized', editor );
269
- * } )
270
- * .catch( err => {
271
- * console.error( err.stack );
272
- * } );
273
- * ```
274
- *
275
- * The element's content will be used as the editor data and the element will be replaced by the editor UI.
276
- *
277
- * # Creating a detached editor
278
- *
279
- * Alternatively, you can initialize the editor by passing the initial data directly as a string.
280
- * In this case, the editor will render an element that must be inserted into the DOM:
281
- *
282
- * ```ts
283
- * ClassicEditor
284
- * .create( '<p>Hello world!</p>' )
285
- * .then( editor => {
286
- * console.log( 'Editor was initialized', editor );
287
- *
288
- * // Initial data was provided so the editor UI element needs to be added manually to the DOM.
289
- * document.body.appendChild( editor.ui.element );
290
- * } )
291
- * .catch( err => {
292
- * console.error( err.stack );
293
- * } );
294
- * ```
295
- *
296
- * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
297
- * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
298
- *
299
- * # Replacing a DOM element (and data provided in `config.initialData`)
300
- *
301
- * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
302
- *
303
- * ```ts
304
- * ClassicEditor
305
- * .create( document.querySelector( '#editor' ), {
306
- * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
307
- * } )
308
- * .then( editor => {
309
- * console.log( 'Editor was initialized', editor );
310
- * } )
311
- * .catch( err => {
312
- * console.error( err.stack );
313
- * } );
314
- * ```
315
- *
316
- * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
317
- * makes it difficult to set the content of the source element.
318
- *
319
- * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
320
- *
321
- * # Configuring the editor
322
- *
323
- * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
324
- * customizing plugins, toolbar and more.
325
- *
326
- * # Using the editor from source
327
- *
328
- * The code samples listed in the previous sections of this documentation assume that you are using an
329
- * {@glink installation/getting-started/predefined-builds editor build} (for example – `@ckeditor/ckeditor5-build-classic`).
330
- *
331
- * If you want to use the classic editor from source (`@ckeditor/ckeditor5-editor-classic/src/classiceditor`),
332
- * you need to define the list of
333
- * {@link module:core/editor/editorconfig~EditorConfig#plugins plugins to be initialized} and
334
- * {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar items}. Read more about using the editor from
335
- * source in the {@glink installation/advanced/alternative-setups/integrating-from-source-webpack dedicated guide}.
336
- *
337
- * @param sourceElementOrData The DOM element that will be the source for the created editor
338
- * or the editor's initial data.
339
- *
340
- * If a DOM element is passed, its content will be automatically loaded to the editor upon initialization
341
- * and the {@link module:editor-classic/classiceditorui~ClassicEditorUI#element editor element} will replace the passed element
342
- * in the DOM (the original one will be hidden and the editor will be injected next to it).
343
- *
344
- * If the {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
345
- * option is set to `true`, the editor data will be set back to the original element once the editor is destroyed and when a form,
346
- * in which this element is contained, is submitted (if the original element is a `<textarea>`). This ensures seamless integration
347
- * with native web forms.
348
- *
349
- * If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
350
- * It is available under the {@link module:editor-classic/classiceditorui~ClassicEditorUI#element `editor.ui.element`} property.
351
- *
352
- * @param config The editor configuration.
353
- * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
354
- */ static create(sourceElementOrData, config = {}) {
355
- return new Promise((resolve)=>{
356
- const editor = new this(sourceElementOrData, config);
357
- resolve(editor.initPlugins().then(()=>editor.ui.init(isElement(sourceElementOrData) ? sourceElementOrData : null)).then(()=>editor.data.init(editor.config.get('initialData'))).then(()=>editor.fire('ready')).then(()=>editor));
358
- });
359
- }
253
+ * @inheritDoc
254
+ */ ui;
360
255
  /**
361
- * Creates an instance of the classic editor.
362
- *
363
- * **Note:** do not use the constructor to create editor instances. Use the static
364
- * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
365
- *
366
- * @param sourceElementOrData The DOM element that will be the source for the created editor
367
- * or the editor's initial data. For more information see
368
- * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
369
- * @param config The editor configuration.
370
- */ constructor(sourceElementOrData, config = {}){
256
+ * Creates an instance of the classic editor.
257
+ *
258
+ * **Note:** do not use the constructor to create editor instances. Use the static
259
+ * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
260
+ *
261
+ * @param sourceElementOrData The DOM element that will be the source for the created editor
262
+ * or the editor's initial data. For more information see
263
+ * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
264
+ * @param config The editor configuration.
265
+ */ constructor(sourceElementOrData, config = {}){
371
266
  // If both `config.initialData` is set and initial data is passed as the constructor parameter, then throw.
372
267
  if (!isElement(sourceElementOrData) && config.initialData !== undefined) {
373
268
  // Documented in core/editor/editorconfig.jsdoc.
@@ -392,22 +287,114 @@ class ClassicEditorUIView extends BoxedEditorUIView {
392
287
  this.ui = new ClassicEditorUI(this, view);
393
288
  attachToForm(this);
394
289
  }
290
+ /**
291
+ * Destroys the editor instance, releasing all resources used by it.
292
+ *
293
+ * Updates the original editor element with the data if the
294
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
295
+ * configuration option is set to `true`.
296
+ */ destroy() {
297
+ if (this.sourceElement) {
298
+ this.updateSourceElement();
299
+ }
300
+ this.ui.destroy();
301
+ return super.destroy();
302
+ }
303
+ /**
304
+ * Creates a new classic editor instance.
305
+ *
306
+ * There are three ways how the editor can be initialized.
307
+ *
308
+ * # Replacing a DOM element (and loading data from it)
309
+ *
310
+ * You can initialize the editor using an existing DOM element:
311
+ *
312
+ * ```ts
313
+ * ClassicEditor
314
+ * .create( document.querySelector( '#editor' ) )
315
+ * .then( editor => {
316
+ * console.log( 'Editor was initialized', editor );
317
+ * } )
318
+ * .catch( err => {
319
+ * console.error( err.stack );
320
+ * } );
321
+ * ```
322
+ *
323
+ * The element's content will be used as the editor data and the element will be replaced by the editor UI.
324
+ *
325
+ * # Creating a detached editor
326
+ *
327
+ * Alternatively, you can initialize the editor by passing the initial data directly as a string.
328
+ * In this case, the editor will render an element that must be inserted into the DOM:
329
+ *
330
+ * ```ts
331
+ * ClassicEditor
332
+ * .create( '<p>Hello world!</p>' )
333
+ * .then( editor => {
334
+ * console.log( 'Editor was initialized', editor );
335
+ *
336
+ * // Initial data was provided so the editor UI element needs to be added manually to the DOM.
337
+ * document.body.appendChild( editor.ui.element );
338
+ * } )
339
+ * .catch( err => {
340
+ * console.error( err.stack );
341
+ * } );
342
+ * ```
343
+ *
344
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
345
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
346
+ *
347
+ * # Replacing a DOM element (and data provided in `config.initialData`)
348
+ *
349
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
350
+ *
351
+ * ```ts
352
+ * ClassicEditor
353
+ * .create( document.querySelector( '#editor' ), {
354
+ * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
355
+ * } )
356
+ * .then( editor => {
357
+ * console.log( 'Editor was initialized', editor );
358
+ * } )
359
+ * .catch( err => {
360
+ * console.error( err.stack );
361
+ * } );
362
+ * ```
363
+ *
364
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
365
+ * makes it difficult to set the content of the source element.
366
+ *
367
+ * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
368
+ *
369
+ * # Configuring the editor
370
+ *
371
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
372
+ * customizing plugins, toolbar and more.
373
+ *
374
+ * @param sourceElementOrData The DOM element that will be the source for the created editor
375
+ * or the editor's initial data.
376
+ *
377
+ * If a DOM element is passed, its content will be automatically loaded to the editor upon initialization
378
+ * and the {@link module:editor-classic/classiceditorui~ClassicEditorUI#element editor element} will replace the passed element
379
+ * in the DOM (the original one will be hidden and the editor will be injected next to it).
380
+ *
381
+ * If the {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
382
+ * option is set to `true`, the editor data will be set back to the original element once the editor is destroyed and when a form,
383
+ * in which this element is contained, is submitted (if the original element is a `<textarea>`). This ensures seamless integration
384
+ * with native web forms.
385
+ *
386
+ * If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
387
+ * It is available under the {@link module:editor-classic/classiceditorui~ClassicEditorUI#element `editor.ui.element`} property.
388
+ *
389
+ * @param config The editor configuration.
390
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
391
+ */ static create(sourceElementOrData, config = {}) {
392
+ return new Promise((resolve)=>{
393
+ const editor = new this(sourceElementOrData, config);
394
+ resolve(editor.initPlugins().then(()=>editor.ui.init(isElement(sourceElementOrData) ? sourceElementOrData : null)).then(()=>editor.data.init(editor.config.get('initialData'))).then(()=>editor.fire('ready')).then(()=>editor));
395
+ });
396
+ }
395
397
  }
396
- /**
397
- * The {@link module:core/context~Context} class.
398
- *
399
- * Exposed as static editor field for easier access in editor builds.
400
- */ ClassicEditor.Context = Context;
401
- /**
402
- * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class.
403
- *
404
- * Exposed as static editor field for easier access in editor builds.
405
- */ ClassicEditor.EditorWatchdog = EditorWatchdog;
406
- /**
407
- * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class.
408
- *
409
- * Exposed as static editor field for easier access in editor builds.
410
- */ ClassicEditor.ContextWatchdog = ContextWatchdog;
411
398
  function getInitialData(sourceElementOrData) {
412
399
  return isElement(sourceElementOrData) ? getDataFromElement(sourceElementOrData) : sourceElementOrData;
413
400
  }