import{Command as m,Plugin as E}from"@ckeditor/ckeditor5-core";import{Observer as k,BubblingEventInfo as S,ViewDocumentDomEventData as y}from"@ckeditor/ckeditor5-engine";import{env as C}from"@ckeditor/ckeditor5-utils";/**
* @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
*/function*d(s,e){for(const t of e)t&&s.getAttributeProperties(t[0]).copyOnEnter&&(yield 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 m{execute(){this.editor.model.change(e=>{this.enterBlock(e),this.fire("afterExecute",{writer:e})})}enterBlock(e){const t=this.editor.model,n=t.document.selection,i=t.schema,o=n.isCollapsed,r=n.getFirstRange(),a=r.start.parent,c=r.end.parent;if(i.isLimit(a)||i.isLimit(c))return!o&&a==c&&t.deleteContent(n),!1;if(o){const l=d(e.model.schema,n.getAttributes());return h(e,r.start),e.setSelectionAttribute(l),!0}else{const l=!(r.start.isAtStart&&r.end.isAtEnd),v=a==c;if(t.deleteContent(n,{leaveUnmerged:l}),l){if(v)return h(e,n.focus),!0;e.setSelection(c,0)}}return!1}}function h(s,e){s.split(e),s.setSelection(e.parent.nextSibling,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
*/const T={insertParagraph:{isSoft:!1},insertLineBreak:{isSoft:!0}};class f extends k{constructor(e){super(e);const t=this.document;let n=!1;t.on("keydown",(i,o)=>{n=o.shiftKey}),t.on("beforeinput",(i,o)=>{if(!this.isEnabled)return;let r=o.inputType;C.isSafari&&n&&r=="insertParagraph"&&(r="insertLineBreak");const a=o.domEvent,c=T[r];if(!c)return;const l=new S(t,"enter",o.targetRanges[0]);t.fire(l,new y(e,a,{isSoft:c.isSoft})),l.stop.called&&i.stop()})}observe(){}stopObserving(){}}/**
* @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 x extends E{static get pluginName(){return"Enter"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.editing.view,n=t.document,i=this.editor.t;t.addObserver(f),e.commands.add("enter",new p(e)),this.listenTo(n,"enter",(o,r)=>{n.isComposing||r.preventDefault(),!r.isSoft&&(e.execute("enter"),t.scrollToTheSelection())},{priority:"low"}),e.accessibility.addKeystrokeInfos({keystrokes:[{label:i("Insert a hard break (a new paragraph)"),keystroke:"Enter"}]})}}/**
* @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 g extends m{execute(){const e=this.editor.model,t=e.document;e.change(n=>{B(e,n,t.selection),this.fire("afterExecute",{writer:n})})}refresh(){const e=this.editor.model,t=e.document;this.isEnabled=A(e.schema,t.selection)}}function A(s,e){if(e.rangeCount>1)return!1;const t=e.anchor;if(!t||!s.checkChild(t,"softBreak"))return!1;const n=e.getFirstRange(),i=n.start.parent,o=n.end.parent;return!((u(i,s)||u(o,s))&&i!==o)}function B(s,e,t){const n=t.isCollapsed,i=t.getFirstRange(),o=i.start.parent,r=i.end.parent,a=o==r;if(n){const c=d(s.schema,t.getAttributes());b(s,e,i.end),e.removeSelectionAttribute(t.getAttributeKeys()),e.setSelectionAttribute(c)}else{const c=!(i.start.isAtStart&&i.end.isAtEnd);s.deleteContent(t,{leaveUnmerged:c}),a?b(s,e,t.focus):c&&e.setSelection(r,0)}}function b(s,e,t){const n=e.createElement("softBreak");s.insertContent(n,t),e.setSelection(n,"after")}function u(s,e){return s.is("rootElement")?!1:e.isLimit(s)||u(s.parent,e)}/**
* @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 O extends E{static get pluginName(){return"ShiftEnter"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.model.schema,n=e.conversion,i=e.editing.view,o=i.document,r=this.editor.t;t.register("softBreak",{allowWhere:"$text",isInline:!0}),n.for("upcast").elementToElement({model:"softBreak",view:"br"}),n.for("downcast").elementToElement({model:"softBreak",view:(a,{writer:c})=>c.createEmptyElement("br")}),i.addObserver(f),e.commands.add("shiftEnter",new g(e)),this.listenTo(o,"enter",(a,c)=>{o.isComposing||c.preventDefault(),c.isSoft&&(e.execute("shiftEnter"),i.scrollToTheSelection())},{priority:"low"}),e.accessibility.addKeystrokeInfos({keystrokes:[{label:r("Insert a soft break (a <code>&lt;br&gt;</code> element)"),keystroke:"Shift+Enter"}]})}}export{x as Enter,p as EnterCommand,f as EnterObserver,O as ShiftEnter,g as ShiftEnterCommand,d as _getCopyOnEnterAttributes};
