import{ElementApiMixin as u,Editor as h,secureSourceElement as g}from"@ckeditor/ckeditor5-core";import{CKEditorError as a,getDataFromElement as f}from"@ckeditor/ckeditor5-utils";import{EditorUI as b,EditorUIView as m,ToolbarView as w,MenuBarView as p,InlineEditableUIView as y}from"@ckeditor/ckeditor5-ui";import{enableViewPlaceholder as E}from"@ckeditor/ckeditor5-engine";/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class d extends b{view;constructor(e,i){super(e),this.view=i}init(){const e=this.editor,i=this.view,n=e.editing.view,o=i.editable,r=n.document.getRoot();o.name=r.rootName,i.render();const l=o.element;this.setEditableElement(o.name,l),i.editable.bind("isFocused").to(this.focusTracker),n.attachDomRoot(l),this._initPlaceholder(),this._initToolbar(),this.initMenuBar(this.view.menuBarView),this.fire("ready")}destroy(){super.destroy();const e=this.view,i=this.editor.editing.view;i.getDomRoot(e.editable.name)&&i.detachDomRoot(e.editable.name),e.destroy()}_initToolbar(){const e=this.editor,i=this.view;i.toolbar.fillFromConfig(e.config.get("toolbar"),this.componentFactory),this.addToolbar(i.toolbar)}_initPlaceholder(){const e=this.editor,i=e.editing.view,n=i.document.getRoot(),o=e.config.get("placeholder");if(o){const r=typeof o=="string"?o:o[n.rootName];r&&(n.placeholder=r)}E({view:i,element:n,isDirectHost:!1,keepOnFocus:!0})}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class c extends m{toolbar;editable;menuBarView;constructor(e,i,n={}){super(e),this.toolbar=new w(e,{shouldGroupWhenFull:n.shouldToolbarGroupWhenFull}),this.menuBarView=new p(e),this.editable=new y(e,i,n.editableElement,{label:n.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 T(t){return typeof t=="object"&&t!==null}function V(t){if(typeof t!="object"||t==null)return!1;if(Object.getPrototypeOf(t)===null)return!0;if(Object.prototype.toString.call(t)!=="[object Object]"){const i=t[Symbol.toStringTag];return i==null||!Object.getOwnPropertyDescriptor(t,Symbol.toStringTag)?.writable?!1:t.toString()===`[object ${i}]`}let e=t;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}function v(t){return T(t)&&t.nodeType===1&&!V(t)}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class P extends u(h){static get editorName(){return"DecoupledEditor"}ui;constructor(e,i={}){if(!s(e)&&i.initialData!==void 0)throw new a("editor-create-initial-data",null);super(i),this.config.get("initialData")===void 0&&this.config.set("initialData",R(e)),s(e)&&(this.sourceElement=e,g(this,e)),this.model.document.createRoot();const n=!this.config.get("toolbar.shouldNotGroupWhenFull"),o=new c(this.locale,this.editing.view,{editableElement:this.sourceElement,shouldToolbarGroupWhenFull:n,label:this.config.get("label")});this.ui=new d(this,o)}destroy(){const e=this.getData();return this.ui.destroy(),super.destroy().then(()=>{this.sourceElement&&this.updateSourceElement(e)})}static create(e,i={}){return new Promise(n=>{if(s(e)&&e.tagName==="TEXTAREA")throw new a("editor-wrong-element",null);const o=new this(e,i);n(o.initPlugins().then(()=>o.ui.init()).then(()=>o.data.init(o.config.get("initialData"))).then(()=>o.fire("ready")).then(()=>o))})}}function R(t){return s(t)?f(t):t}function s(t){return v(t)}export{P as DecoupledEditor,d as DecoupledEditorUI,c as DecoupledEditorUIView};
