import{EditorUI as g,normalizeToolbarConfig as b,DialogView as u,BoxedEditorUIView as m,StickyPanelView as w,ToolbarView as y,MenuBarView as _,InlineEditableUIView as v}from"@ckeditor/ckeditor5-ui";import{enableViewPlaceholder as P}from"@ckeditor/ckeditor5-engine";import{ElementReplacer as T,Rect as c,CKEditorError as S,getDataFromElement as C}from"@ckeditor/ckeditor5-utils";import{ElementApiMixin as V,Editor as x,attachToForm as B}from"@ckeditor/ckeditor5-core";/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class f extends g{view;_toolbarConfig;_elementReplacer;constructor(t,e){super(t),this.view=e,this._toolbarConfig=b(t.config.get("toolbar")),this._elementReplacer=new T,this.listenTo(t.editing.view,"scrollToTheSelection",this._handleScrollToTheSelectionWithStickyPanel.bind(this))}get element(){return this.view.element}init(t){const e=this.editor,i=this.view,r=e.editing.view,o=i.editable,s=r.document.getRoot();o.name=s.rootName,i.render();const l=o.element;this.setEditableElement(o.name,l),i.editable.bind("isFocused").to(this.focusTracker),r.attachDomRoot(l),t&&this._elementReplacer.replace(t,this.element),this._initPlaceholder(),this._initToolbar(),i.menuBarView&&this.initMenuBar(i.menuBarView),this._initDialogPluginIntegration(),this._initContextualBalloonIntegration(),this.fire("ready")}destroy(){super.destroy();const t=this.view,e=this.editor.editing.view;this._elementReplacer.restore(),e.getDomRoot(t.editable.name)&&e.detachDomRoot(t.editable.name),t.destroy()}_initToolbar(){const t=this.view;t.stickyPanel.bind("isActive").to(this.focusTracker,"isFocused"),t.stickyPanel.limiterElement=t.element,t.stickyPanel.bind("viewportTopOffset").to(this,"viewportOffset",({visualTop:e})=>e||0),t.toolbar.fillFromConfig(this._toolbarConfig,this.componentFactory),this.addToolbar(t.toolbar)}_initPlaceholder(){const t=this.editor,e=t.editing.view,i=e.document.getRoot(),r=t.sourceElement;let o;const s=t.config.get("placeholder");s&&(o=typeof s=="string"?s:s[this.view.editable.name]),!o&&r&&r.tagName.toLowerCase()==="textarea"&&(o=r.getAttribute("placeholder")),o&&(i.placeholder=o),P({view:e,element:i,isDirectHost:!1,keepOnFocus:!0})}_initContextualBalloonIntegration(){if(!this.editor.plugins.has("ContextualBalloon"))return;const{stickyPanel:t}=this.view,e=this.editor.plugins.get("ContextualBalloon");e.on("getPositionOptions",r=>{const o=r.return;if(!o||!t.isSticky||!t.element)return;const s=new c(t.element).height,l=typeof o.target=="function"?o.target():o.target,d=typeof o.limiter=="function"?o.limiter():o.limiter;if(l&&d&&new c(l).height>=new c(d).height-s)return;const h={...o.viewportOffsetConfig},p=(h.top||0)+s;r.return={...o,viewportOffsetConfig:{...h,top:p}}},{priority:"low"});const i=()=>{e.visibleView&&e.updatePosition()};this.listenTo(t,"change:isSticky",i),this.listenTo(this.editor.ui,"change:viewportOffset",i)}_handleScrollToTheSelectionWithStickyPanel(t,e,i){const r=this.view.stickyPanel;if(r.isSticky){const o=new c(r.element).height;e.viewportOffset.top+=o}else{const o=()=>{this.editor.editing.view.scrollToTheSelection(i)};this.listenTo(r,"change:isSticky",o),setTimeout(()=>{this.stopListening(r,"change:isSticky",o)},20)}}_initDialogPluginIntegration(){if(!this.editor.plugins.has("Dialog"))return;const t=this.view.stickyPanel,e=this.editor.plugins.get("Dialog");e.on("show",()=>{const i=e.view;i.on("moveTo",(r,o)=>{if(!t.isSticky||i.wasMoved||i.isModal)return;const s=new c(t.contentPanelElement);o[1]<s.bottom+u.defaultOffset&&(o[1]=s.bottom+u.defaultOffset)},{priority:"high"})},{priority:"low"})}}function O(n,{insertAt:t}={}){if(typeof document>"u")return;const e=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",window.litNonce&&i.setAttribute("nonce",window.litNonce),t==="top"&&e.firstChild?e.insertBefore(i,e.firstChild):e.appendChild(i),i.styleSheet?i.styleSheet.cssText=n:i.appendChild(document.createTextNode(n))}O(".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:solid var(--ck-color-base-border);border-radius:0;border-width:1px 1px 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.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)}");/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class k extends m{stickyPanel;toolbar;editable;constructor(t,e,i={}){super(t),this.stickyPanel=new w(t),this.toolbar=new y(t,{shouldGroupWhenFull:i.shouldToolbarGroupWhenFull}),i.useMenuBar&&(this.menuBarView=new _(t)),this.editable=new v(t,e,void 0,{label:i.label})}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)}}function E(n){return typeof n=="object"&&n!==null}function R(n){if(typeof n!="object"||n==null)return!1;if(Object.getPrototypeOf(n)===null)return!0;if(Object.prototype.toString.call(n)!=="[object Object]"){const e=n[Symbol.toStringTag];return e==null||!Object.getOwnPropertyDescriptor(n,Symbol.toStringTag)?.writable?!1:n.toString()===`[object ${e}]`}let t=n;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(n)===t}function I(n){return E(n)&&n.nodeType===1&&!R(n)}/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class F extends V(x){static get editorName(){return"ClassicEditor"}ui;constructor(t,e={}){if(!a(t)&&e.initialData!==void 0)throw new S("editor-create-initial-data",null);super(e),this.config.define("menuBar.isVisible",!1),this.config.get("initialData")===void 0&&this.config.set("initialData",D(t)),a(t)&&(this.sourceElement=t),this.model.document.createRoot();const i=!this.config.get("toolbar.shouldNotGroupWhenFull"),r=this.config.get("menuBar"),o=new k(this.locale,this.editing.view,{shouldToolbarGroupWhenFull:i,useMenuBar:r.isVisible,label:this.config.get("label")});this.ui=new f(this,o),B(this)}destroy(){return this.sourceElement&&this.updateSourceElement(),this.ui.destroy(),super.destroy()}static create(t,e={}){return new Promise(i=>{const r=new this(t,e);i(r.initPlugins().then(()=>r.ui.init(a(t)?t:null)).then(()=>r.data.init(r.config.get("initialData"))).then(()=>r.fire("ready")).then(()=>r))})}}function D(n){return a(n)?C(n):n}function a(n){return I(n)}export{F as ClassicEditor,f as ClassicEditorUI,k as ClassicEditorUIView};
