import{Plugin as h,MultiCommand as B,Command as L}from"@ckeditor/ckeditor5-core";import{ButtonView as U,MenuBarMenuListItemButtonView as S}from"@ckeditor/ckeditor5-ui";import{IconIndent as C,IconOutdent as A}from"@ckeditor/ckeditor5-icons";import{addMarginStylesRules as v}from"@ckeditor/ckeditor5-engine";import{first as O}from"@ckeditor/ckeditor5-utils";import{_isListItemBlock as _}from"@ckeditor/ckeditor5-list";/**
* @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 x extends h{static get pluginName(){return"IndentEditing"}static get isOfficialPlugin(){return!0}init(){const t=this.editor;t.commands.add("indent",new B(t)),t.commands.add("outdent",new B(t))}}/**
* @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 E extends h{static get pluginName(){return"IndentUI"}static get isOfficialPlugin(){return!0}init(){const t=this.editor,e=t.locale,n=t.t,s=e.uiLanguageDirection=="ltr"?C:A,i=e.uiLanguageDirection=="ltr"?A:C;this._defineButton("indent",n("Increase indent"),s),this._defineButton("outdent",n("Decrease indent"),i)}_defineButton(t,e,n){const s=this.editor;s.ui.componentFactory.add(t,()=>{const i=this._createButton(U,t,e,n);return i.set({tooltip:!0}),i}),s.ui.componentFactory.add("menuBar:"+t,()=>this._createButton(S,t,e,n))}_createButton(t,e,n,s){const i=this.editor,o=i.commands.get(e),r=new t(i.locale);return r.set({label:n,icon:s}),r.bind("isEnabled").to(o,"isEnabled"),this.listenTo(r,"execute",()=>{i.execute(e),i.editing.view.focus()}),r}}/**
* @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 D extends h{static get pluginName(){return"Indent"}static get isOfficialPlugin(){return!0}static get requires(){return[x,E]}}/**
* @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 L{_indentBehavior;constructor(t,e){super(t),this._indentBehavior=e}refresh(){const e=this.editor.model,n=O(e.document.selection.getSelectedBlocks());if(!n||!this._isIndentationChangeAllowed(n)){this.isEnabled=!1;return}this.isEnabled=this._indentBehavior.checkEnabled(n.getAttribute("blockIndent"))}execute(){const t=this.editor.model,e=this._getBlocksToChange();t.change(n=>{for(const s of e){const i=s.getAttribute("blockIndent"),o=this._indentBehavior.getNextIndent(i);o?n.setAttribute("blockIndent",o,s):n.removeAttribute("blockIndent",s)}})}_getBlocksToChange(){const e=this.editor.model.document.selection;return Array.from(e.getSelectedBlocks()).filter(s=>this._isIndentationChangeAllowed(s))}_isIndentationChangeAllowed(t){const e=this.editor;return e.model.schema.checkAttribute(t,"blockIndent")?!e.plugins.has("ListUtils")||!this._indentBehavior.isForward?!0:!e.plugins.get("ListUtils").isListItemBlock(t):!1}}/**
* @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 m{isForward;offset;unit;constructor(t){this.isForward=t.direction==="forward",this.offset=t.offset,this.unit=t.unit}checkEnabled(t){const e=parseFloat(t||"0");return this.isForward||e>0}getNextIndent(t){const e=parseFloat(t||"0"),n=!t||t.endsWith(this.unit);if(e<0)return;if(!n)return this.isForward?this.offset+this.unit:void 0;const s=this.isForward?this.offset:-this.offset,i=e+s;return i>0?i+this.unit:void 0}}/**
* @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{isForward;classes;constructor(t){this.isForward=t.direction==="forward",this.classes=t.classes}checkEnabled(t){const e=this.classes.indexOf(t);return this.isForward?e<this.classes.length-1:e>=0}getNextIndent(t){const e=this.classes.indexOf(t),n=this.isForward?1:-1,s=e+n,i=Math.min(s,this.classes.length-1);return this.classes[i]}}/**
* @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 b extends L{_indentBehavior;constructor(t,e){super(t),this._indentBehavior=e}refresh(){const t=this._getFirstListItemIfSelectionIsAtListStart(this.editor.model.document.selection);this.isEnabled=!!t&&this._indentBehavior.checkEnabled(t.getAttribute("blockIndentList"))}execute(t={}){const n=this.editor.model,s=n.document.selection;n.change(i=>{const o=this._getFirstListItemIfSelectionIsAtListStart(s),r=[];if(t.firstListOnly)r.push(o);else{const c=Array.from(s.getSelectedBlocks());for(const l of c)_(l)&&l.getAttribute("listIndent")===0&&n.schema.checkAttribute(l,"blockIndentList")&&r.push(l)}for(const c of r){const l=c.getAttribute("blockIndentList"),a=this._indentBehavior.getNextIndent(l);a?i.setAttribute("blockIndentList",a,c):i.removeAttribute("blockIndentList",c)}})}_getFirstListItemIfSelectionIsAtListStart(t){const e=t.getFirstPosition(),n=this.editor.plugins.get("ListUtils"),s=e.parent,i=this.editor.model.schema;return e.isAtStart&&_(s)&&s.getAttribute("listIndent")==0&&i.checkAttribute(s,"blockIndentList")&&n.isFirstListItemInList(s)?s:null}}/**
* @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 L{_indentBehavior;constructor(t,e){super(t),this._indentBehavior=e}refresh(){this.isEnabled=this._getAffectedListItems().length>0}execute(){this.editor.model.change(n=>{for(const s of this._getAffectedListItems())n.removeAttribute("blockIndentListItem",s)})}_getAffectedListItems(){const e=this.editor.model.document.selection,n=this.editor.plugins.get("ListUtils"),s=Array.from(e.getSelectedBlocks());return n.expandListBlocksToCompleteItems(s).filter(o=>this._isIndentationChangeAllowed(o))}_isIndentationChangeAllowed(t){if(!t.hasAttribute("blockIndentListItem"))return!1;const e=parseFloat(t.getAttribute("blockIndentListItem"));return isNaN(e)?!this._indentBehavior.isForward:this._indentBehavior.isForward&&e<0||!this._indentBehavior.isForward&&e>0}}/**
* @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 h{static get pluginName(){return"IndentBlockListIntegration"}static get isOfficialPlugin(){return!0}init(){const t=this.editor;if(!this.editor.plugins.has("ListEditing"))return;const e=t.config.get("indentBlock");e.classes&&e.classes.length?(this._setupConversionUsingClassesForListBlock(e.classes),this._setupConversionUsingClassesForListItemBlock(e.classes),t.commands.add("indentBlockList",new b(t,new f({direction:"forward",classes:e.classes}))),t.commands.add("outdentBlockList",new b(t,new f({direction:"backward",classes:e.classes}))),t.commands.add("indentBlockListItem",new k(t,new f({direction:"forward",classes:e.classes}))),t.commands.add("outdentBlockListItem",new k(t,new f({direction:"backward",classes:e.classes})))):(t.data.addStyleProcessorRules(v),this._setupConversionUsingOffsetForListBlock(),this._setupConversionUsingOffsetForListItemBlock(),t.commands.add("indentBlockList",new b(t,new m({direction:"forward",offset:e.offset,unit:e.unit}))),t.commands.add("outdentBlockList",new b(t,new m({direction:"backward",offset:e.offset,unit:e.unit}))),t.commands.add("indentBlockListItem",new k(t,new m({direction:"forward",offset:e.offset,unit:e.unit}))),t.commands.add("outdentBlockListItem",new k(t,new m({direction:"backward",offset:e.offset,unit:e.unit})))),t.plugins.get("ListEditing").on("postFixer",(s,{listNodes:i,writer:o})=>{for(const{node:r,previousNodeInList:c}of i)c&&c.getAttribute("listType")==r.getAttribute("listType")&&(y("blockIndentList",r,c,o)&&(s.return=!0),c.getAttribute("listItemId")==r.getAttribute("listItemId")&&y("blockIndentListItem",r,c,o)&&(s.return=!0))}),this.listenTo(t.editing.view.document,"tab",(s,i)=>{const o=i.shiftKey?"outdentBlockList":"indentBlockList";this.editor.commands.get(o).isEnabled&&(t.execute(o,{firstListOnly:!0}),i.stopPropagation(),i.preventDefault(),s.stop())},{context:"li",priority:"high"})}afterInit(){const t=this.editor,e=t.model,n=e.schema;if(!t.plugins.has("ListEditing"))return;n.extend("$listItem",{allowAttributes:["blockIndentList","blockIndentListItem"]}),n.setAttributeProperties("blockIndentList",{isFormatting:!0}),n.setAttributeProperties("blockIndentListItem",{isFormatting:!0}),e.schema.addAttributeCheck(l=>{if(!l.last.getAttribute("listItemId"))return!1},"blockIndentList"),e.schema.addAttributeCheck(l=>{if(!l.last.getAttribute("listItemId"))return!1},"blockIndentListItem");const s=(l,a)=>{t.model.change(u=>{for(const g of a)g.hasAttribute("listItemId")&&(g.hasAttribute("blockIndentList")&&u.removeAttribute("blockIndentList",g),g.hasAttribute("blockIndentListItem")&&u.removeAttribute("blockIndentListItem",g))})},i=t.commands.get("indentList"),o=t.commands.get("outdentList");i&&this.listenTo(i,"afterExecute",s),o&&this.listenTo(o,"afterExecute",s);const r=t.commands.get("indent"),c=t.commands.get("outdent");r.registerChildCommand(t.commands.get("indentBlockList")),c.registerChildCommand(t.commands.get("outdentBlockList")),r.registerChildCommand(t.commands.get("indentBlockListItem")),c.registerChildCommand(t.commands.get("outdentBlockListItem"))}_setupConversionUsingOffsetForListBlock(){const t=this.editor,e=t.conversion,s=t.locale.contentLanguageDirection==="rtl"?"margin-right":"margin-left",i=t.plugins.get("ListEditing");e.for("upcast").add(o=>{o.on("element:ol",w("blockIndentList",s)),o.on("element:ul",w("blockIndentList",s))}),i.registerDowncastStrategy({scope:"list",attributeName:"blockIndentList",setAttributeOnDowncast(o,r,c){r&&o.setStyle(s,r,c)}})}_setupConversionUsingOffsetForListItemBlock(){const t=this.editor,e=t.locale,n=t.conversion,s=e.contentLanguageDirection==="rtl"?"margin-right":"margin-left",i=t.plugins.get("ListEditing");n.for("upcast").add(o=>{o.on("element:li",w("blockIndentListItem",s),{priority:"low"})}),i.registerDowncastStrategy({scope:"item",attributeName:"blockIndentListItem",setAttributeOnDowncast(o,r,c){r&&o.setStyle(s,r,c)}})}_setupConversionUsingClassesForListBlock(t){const e=this.editor,n=e.conversion,s=e.plugins.get("ListEditing");n.for("upcast").add(i=>{i.on("element:ol",p("blockIndentList",t)),i.on("element:ul",p("blockIndentList",t))}),s.registerDowncastStrategy({scope:"list",attributeName:"blockIndentList",setAttributeOnDowncast(i,o,r){o&&i.addClass(o,r)}})}_setupConversionUsingClassesForListItemBlock(t){const e=this.editor,n=e.conversion,s=e.plugins.get("ListEditing");n.for("upcast").add(i=>{i.on("element:li",p("blockIndentListItem",t),{priority:"low"})}),s.registerDowncastStrategy({scope:"item",attributeName:"blockIndentListItem",setAttributeOnDowncast(i,o,r){o&&i.addClass(o,r)}})}}function p(d,t){return(e,n,s)=>{const{writer:i,consumable:o}=s;n.modelRange||Object.assign(n,s.convertChildren(n.viewItem,n.modelCursor));const r=Array.from(n.viewItem.getClassNames()),c=t.find(u=>r.includes(u));if(c===void 0)return;let l=!1,a;for(const u of n.modelRange.getItems({shallow:!0}))a===void 0&&(a=u.getAttribute("listIndent")),!u.hasAttribute(d)&&u.getAttribute("listIndent")===a&&(i.setAttribute(d,c,u),l=!0);l&&o.consume(n.viewItem,{classes:c})}}function w(d,t){return(e,n,s)=>{const{writer:i,consumable:o}=s;n.modelRange||Object.assign(n,s.convertChildren(n.viewItem,n.modelCursor));const r=n.viewItem.getStyle(t);let c=!1,l;for(const a of n.modelRange.getItems({shallow:!0}))l===void 0&&(l=a.getAttribute("listIndent")),!a.hasAttribute(d)&&a.getAttribute("listIndent")===l&&(i.setAttribute(d,r,a),c=!0);c&&o.consume(n.viewItem,{styles:t})}}function y(d,t,e,n){const s=e.getAttribute(d);return t.getAttribute(d)===s?!1:(s?n.setAttribute(d,s,t):n.removeAttribute(d,t),!0)}/**
* @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
*/const T=["paragraph","heading1","heading2","heading3","heading4","heading5","heading6"];class P extends h{constructor(t){super(t),t.config.define("indentBlock",{offset:40,unit:"px"})}static get pluginName(){return"IndentBlock"}static get isOfficialPlugin(){return!0}static get requires(){return[F]}init(){const t=this.editor,e=t.config.get("indentBlock");e.classes&&e.classes.length?(this._setupConversionUsingClasses(e.classes),t.commands.add("indentBlock",new I(t,new f({direction:"forward",classes:e.classes}))),t.commands.add("outdentBlock",new I(t,new f({direction:"backward",classes:e.classes})))):(t.data.addStyleProcessorRules(v),this._setupConversionUsingOffset(),t.commands.add("indentBlock",new I(t,new m({direction:"forward",offset:e.offset,unit:e.unit}))),t.commands.add("outdentBlock",new I(t,new m({direction:"backward",offset:e.offset,unit:e.unit}))))}afterInit(){const t=this.editor,e=t.model.schema,n=t.commands.get("indent"),s=t.commands.get("outdent"),i=t.config.get("heading.options");(i&&i.map(c=>c.model)||T).forEach(c=>{e.isRegistered(c)&&e.extend(c,{allowAttributes:"blockIndent"})}),e.setAttributeProperties("blockIndent",{isFormatting:!0}),n.registerChildCommand(t.commands.get("indentBlock")),s.registerChildCommand(t.commands.get("outdentBlock"))}_setupConversionUsingOffset(){const t=this.editor.conversion,n=this.editor.locale.contentLanguageDirection==="rtl"?"margin-right":"margin-left";t.for("upcast").attributeToAttribute({view:{styles:{[n]:/[\s\S]+/}},model:{key:"blockIndent",value:s=>{if(!s.is("element","li"))return s.getStyle(n)}}}),t.for("downcast").attributeToAttribute({model:"blockIndent",view:s=>({key:"style",value:{[n]:s}})})}_setupConversionUsingClasses(t){const e={model:{key:"blockIndent",values:[]},view:{}};for(const n of t)e.model.values.push(n),e.view[n]={key:"class",value:[n]};this.editor.conversion.attributeToAttribute(e)}}export{D as Indent,P as IndentBlock,I as IndentBlockCommand,b as IndentBlockListCommand,F as IndentBlockListIntegration,k as IndentBlockListItemCommand,x as IndentEditing,E as IndentUI,f as _IndentUsingClasses,m as _IndentUsingOffset};
