/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{Extension as e,callOrReturn as t,getExtensionField as o,isNodeEmpty as r,isNodeSelection as s}from"../../core/dist/index.js";import{Plugin as n,PluginKey as i}from"../../../prosemirror-state/dist/index.js";import{dropCursor as d}from"../../../prosemirror-dropcursor/dist/index.js";import{DecorationSet as a,Decoration as c}from"../../../prosemirror-view/dist/index.js";import{gapCursor as l}from"../../../prosemirror-gapcursor/dist/index.js";import{history as p,redo as h,undo as u}from"../../../prosemirror-history/dist/index.js";var m=e.create({name:"characterCount",addOptions:()=>({limit:null,mode:"textSize",textCounter:e=>e.length,wordCounter:e=>e.split(" ").filter(e=>""!==e).length}),addStorage:()=>({characters:()=>0,words:()=>0}),onBeforeCreate(){this.storage.characters=e=>{const t=(null==e?void 0:e.node)||this.editor.state.doc;if("textSize"===((null==e?void 0:e.mode)||this.options.mode)){const e=t.textBetween(0,t.content.size,void 0," ");return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{const t=(null==e?void 0:e.node)||this.editor.state.doc,o=t.textBetween(0,t.content.size," "," ");return this.options.wordCounter(o)}},addProseMirrorPlugins(){let e=!1;return[new n({key:new i("characterCount"),appendTransaction:(t,o,r)=>{if(e)return;const s=this.options.limit;if(null==s||0===s)return void(e=!0);const n=this.storage.characters({node:r.doc});if(n>s){const t=0,o=n-s;console.warn(`[CharacterCount] Initial content exceeded limit of ${s} characters. Content was automatically trimmed.`);const i=r.tr.deleteRange(t,o);return e=!0,i}e=!0},filterTransaction:(e,t)=>{const o=this.options.limit;if(!e.docChanged||0===o||null==o)return!0;const r=this.storage.characters({node:t.doc}),s=this.storage.characters({node:e.doc});if(s<=o)return!0;if(r>o&&s>o&&s<=r)return!0;if(r>o&&s>o&&s>r)return!1;if(!e.getMeta("paste"))return!1;const n=e.selection.$head.pos,i=n-(s-o),d=n;e.deleteRange(i,d);return!(this.storage.characters({node:e.doc})>o)}})]}}),f=e.create({name:"dropCursor",addOptions:()=>({color:"currentColor",width:1,class:void 0}),addProseMirrorPlugins(){return[d(this.options)]}});e.create({name:"focus",addOptions:()=>({className:"has-focus",mode:"all"}),addProseMirrorPlugins(){return[new n({key:new i("focus"),props:{decorations:({doc:e,selection:t})=>{const{isEditable:o,isFocused:r}=this.editor,{anchor:s}=t,n=[];if(!o||!r)return a.create(e,[]);let i=0;"deepest"===this.options.mode&&e.descendants((e,t)=>{if(e.isText)return;if(!(s>=t&&s<=t+e.nodeSize-1))return!1;i+=1});let d=0;return e.descendants((e,t)=>{if(e.isText)return!1;if(!(s>=t&&s<=t+e.nodeSize-1))return!1;d+=1;if("deepest"===this.options.mode&&i-d>0||"shallowest"===this.options.mode&&d>1)return"deepest"===this.options.mode;n.push(c.node(t,t+e.nodeSize,{class:this.options.className}))}),a.create(e,n)}}})]}});var g=e.create({name:"gapCursor",addProseMirrorPlugins:()=>[l()],extendNodeSchema(e){var r;const s={name:e.name,options:e.options,storage:e.storage};return{allowGapCursor:null!=(r=t(o(e,"allowGapCursor",s)))?r:null}}}),y="placeholder";function w(e){return e.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}function C({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||(null==t?void 0:t.type)===e}e.create({name:"placeholder",addOptions:()=>({emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:y,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}),addProseMirrorPlugins(){const e=this.options.dataAttribute?`data-${w(this.options.dataAttribute)}`:`data-${y}`;return[new n({key:new i("placeholder"),props:{decorations:({doc:t,selection:o})=>{const s=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:n}=o,i=[];if(!s)return null;const d=this.editor.isEmpty;return t.descendants((t,o)=>{const s=n>=o&&n<=o+t.nodeSize,a=!t.isLeaf&&r(t);if((s||!this.options.showOnlyCurrent)&&a){const r=[this.options.emptyNodeClass];d&&r.push(this.options.emptyEditorClass);const n=c.node(o,o+t.nodeSize,{class:r.join(" "),[e]:"function"==typeof this.options.placeholder?this.options.placeholder({editor:this.editor,node:t,pos:o,hasAnchor:s}):this.options.placeholder});i.push(n)}return this.options.includeChildren}),a.create(t,i)}}})]}}),e.create({name:"selection",addOptions:()=>({className:"selection"}),addProseMirrorPlugins(){const{editor:e,options:t}=this;return[new n({key:new i("selection"),props:{decorations:o=>o.selection.empty||e.isFocused||!e.isEditable||s(o.selection)||e.view.dragging?null:a.create(o.doc,[c.inline(o.selection.from,o.selection.to,{class:t.className})])}})]}});var x=e.create({name:"trailingNode",addOptions:()=>({node:void 0,notAfter:[]}),addProseMirrorPlugins(){var e;const t=new i(this.name),o=this.options.node||(null==(e=this.editor.schema.topNodeType.contentMatch.defaultType)?void 0:e.name)||"paragraph",r=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(o).includes(e.name));return[new n({key:t,appendTransaction:(e,r,s)=>{const{doc:n,tr:i,schema:d}=s,a=t.getState(s),c=n.content.size,l=d.nodes[o];if(a)return i.insert(c,l.create())},state:{init:(e,t)=>!C({node:t.tr.doc.lastChild,types:r}),apply:(e,t)=>{if(!e.docChanged)return t;if(e.getMeta("__uniqueIDTransaction"))return t;return!C({node:e.doc.lastChild,types:r})}}})]}}),v=e.create({name:"undoRedo",addOptions:()=>({depth:100,newGroupDelay:500}),addCommands:()=>({undo:()=>({state:e,dispatch:t})=>u(e,t),redo:()=>({state:e,dispatch:t})=>h(e,t)}),addProseMirrorPlugins(){return[p(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});export{m as CharacterCount,f as Dropcursor,g as Gapcursor,x as TrailingNode,v as UndoRedo,w as preparePlaceholderAttribute};