UNPKG

@ckeditor/ckeditor5-editor-decoupled

Version:

Decoupled editor implementation for CKEditor 5.

4 lines 4.22 kB
/*! * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md. */(()=>{var e={237:e=>{"use strict";e.exports=CKEditor5.dll},311:(e,t,i)=>{e.exports=i(237)("./src/ui.js")},584:(e,t,i)=>{e.exports=i(237)("./src/utils.js")},782:(e,t,i)=>{e.exports=i(237)("./src/core.js")},783:(e,t,i)=>{e.exports=i(237)("./src/engine.js")}},t={};function i(o){var r=t[o];if(void 0!==r)return r.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,i),n.exports}i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";i.r(o),i.d(o,{DecoupledEditor:()=>c});var e=i(782),t=i(584),r=i(311),n=i(783);class s extends r.EditorUI{view;constructor(e,t){super(e),this.view=t}init(){const e=this.editor,t=this.view,i=e.editing.view,o=t.editable,r=i.document.getRoot();o.name=r.rootName,t.render();const n=o.element;this.setEditableElement(o.name,n),t.editable.bind("isFocused").to(this.focusTracker),i.attachDomRoot(n),this._initPlaceholder(),this._initToolbar(),this.initMenuBar(this.view.menuBarView),this.fire("ready")}destroy(){super.destroy();const e=this.view,t=this.editor.editing.view;t.getDomRoot(e.editable.name)&&t.detachDomRoot(e.editable.name),e.destroy()}_initToolbar(){const e=this.editor,t=this.view;t.toolbar.fillFromConfig(e.config.get("toolbar"),this.componentFactory),this.addToolbar(t.toolbar)}_initPlaceholder(){const e=this.editor,t=e.editing.view,i=t.document.getRoot(),o=e.config.get("placeholder");if(o){const e="string"==typeof o?o:o[i.rootName];e&&(i.placeholder=e)}(0,n.enablePlaceholder)({view:t,element:i,isDirectHost:!1,keepOnFocus:!0})}}class l extends r.EditorUIView{toolbar;editable;menuBarView;constructor(e,t,i={}){super(e),this.toolbar=new r.ToolbarView(e,{shouldGroupWhenFull:i.shouldToolbarGroupWhenFull}),this.menuBarView=new r.MenuBarView(e),this.editable=new r.InlineEditableUIView(e,t,i.editableElement,{label:i.label}),this.toolbar.extendTemplate({attributes:{class:["ck-reset_all","ck-rounded-corners"],dir:e.uiLanguageDirection}}),this.menuBarView.extendTemplate({attributes:{class:["ck-reset_all","ck-rounded-corners"],dir:e.uiLanguageDirection}})}render(){super.render(),this.registerChild([this.menuBarView,this.toolbar,this.editable])}}function a(e){return function(e){return"object"==typeof e&&null!==e}(e)&&1===e.nodeType&&!function(e){if("object"!=typeof e)return!1;if(null==e)return!1;if(null===Object.getPrototypeOf(e))return!0;if("[object Object]"!==Object.prototype.toString.call(e)){const t=e[Symbol.toStringTag];return null!=t&&(!!Object.getOwnPropertyDescriptor(e,Symbol.toStringTag)?.writable&&e.toString()===`[object ${t}]`)}let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}(e)}class c extends((0,e.ElementApiMixin)(e.Editor)){static get editorName(){return"DecoupledEditor"}ui;constructor(i,o={}){if(!d(i)&&void 0!==o.initialData)throw new t.CKEditorError("editor-create-initial-data",null);super(o),void 0===this.config.get("initialData")&&this.config.set("initialData",function(e){return d(e)?(0,t.getDataFromElement)(e):e}(i)),d(i)&&(this.sourceElement=i,(0,e.secureSourceElement)(this,i)),this.model.document.createRoot();const r=!this.config.get("toolbar.shouldNotGroupWhenFull"),n=new l(this.locale,this.editing.view,{editableElement:this.sourceElement,shouldToolbarGroupWhenFull:r,label:this.config.get("label")});this.ui=new s(this,n)}destroy(){const e=this.getData();return this.ui.destroy(),super.destroy().then((()=>{this.sourceElement&&this.updateSourceElement(e)}))}static create(e,i={}){return new Promise((o=>{if(d(e)&&"TEXTAREA"===e.tagName)throw new t.CKEditorError("editor-wrong-element",null);const r=new this(e,i);o(r.initPlugins().then((()=>r.ui.init())).then((()=>r.data.init(r.config.get("initialData")))).then((()=>r.fire("ready"))).then((()=>r)))}))}}function d(e){return a(e)}})(),(window.CKEditor5=window.CKEditor5||{}).editorDecoupled=o})();