import{Command as l,Plugin as d}from"@ckeditor/ckeditor5-core";import{first as u}from"@ckeditor/ckeditor5-utils";import{ButtonView as g}from"@ckeditor/ckeditor5-ui";import{IconParagraph as f}from"@ckeditor/ckeditor5-icons";/**
* @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 h extends l{constructor(e){super(e),this._isEnabledBasedOnSelection=!1}refresh(){const e=this.editor.model,a=e.document,r=u(a.selection.getSelectedBlocks());this.value=!!r&&r.is("element","paragraph"),this.isEnabled=!!r&&m(r,e.schema)}execute(e={}){const a=this.editor.model,r=a.document,t=e.selection||r.selection;a.canEditAt(t)&&a.change(n=>{const o=t.getSelectedBlocks();for(const c of o)!c.is("element","paragraph")&&m(c,a.schema)&&n.rename(c,"paragraph")})}}function m(s,e){return e.checkChild(s.parent,"paragraph")&&!e.isObject(s)}/**
* @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 p extends l{constructor(e){super(e),this._isEnabledBasedOnSelection=!1}execute(e){const a=this.editor.model,r=e.attributes;let t=e.position;return a.canEditAt(t)?a.change(n=>{if(t=this._findPositionToInsertParagraph(t,n),!t)return null;const o=n.createElement("paragraph");return r&&a.schema.setAllowedAttributes(o,r,n),a.insertContent(o,t),n.setSelection(o,"in"),n.createPositionAt(o,0)}):null}_findPositionToInsertParagraph(e,a){const r=this.editor.model;if(r.schema.checkChild(e,"paragraph"))return e;const t=r.schema.findAllowedParent(e,"paragraph");if(!t)return null;const n=e.parent,o=r.schema.checkChild(n,"$text");return n.isEmpty||o&&e.isAtEnd?r.createPositionAfter(n):!n.isEmpty&&o&&e.isAtStart?r.createPositionBefore(n):a.split(e,t).position}}/**
* @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 i extends d{static get pluginName(){return"Paragraph"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,a=e.model;e.commands.add("paragraph",new h(e)),e.commands.add("insertParagraph",new p(e)),a.schema.register("paragraph",{inheritAllFrom:"$block"}),e.conversion.elementToElement({model:"paragraph",view:"p"}),e.conversion.for("upcast").elementToElement({model:(r,{writer:t})=>!i.paragraphLikeElements.has(r.name)||r.isEmpty?null:t.createElement("paragraph"),view:/.+/,converterPriority:"low"})}static paragraphLikeElements=new Set(["blockquote","dd","div","dt","h1","h2","h3","h4","h5","h6","li","p","td","th"])}/**
* @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 P extends d{static get requires(){return[i]}init(){const e=this.editor,a=e.t;e.ui.componentFactory.add("paragraph",r=>{const t=new g(r),n=e.commands.get("paragraph");return t.label=a("Paragraph"),t.icon=f,t.tooltip=!0,t.isToggleable=!0,t.bind("isEnabled").to(n),t.bind("isOn").to(n,"value"),t.on("execute",()=>{e.execute("paragraph")}),t})}}export{p as InsertParagraphCommand,i as Paragraph,P as ParagraphButtonUI,h as ParagraphCommand};
