/* esm.sh - prosemirror-schema-list@1.5.1 */
import{findWrapping as A,ReplaceAroundStep as w,canSplit as L,liftTarget as b,canJoin as k}from"../../../prosemirror-transform@^1.7.3?deps=prosemirror-model@1.25.12&target=es2022";import{NodeRange as C,Fragment as u,Slice as y}from"../../../prosemirror-model@1.25.12/es2022/prosemirror-model.mjs";import{Selection as D}from"../../../prosemirror-state@^1.0.0?deps=prosemirror-model@1.25.12&target=es2022";var S=["ol",0],v=["ul",0],R=["li",0],z={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs(o){return{order:o.hasAttribute("start")?+o.getAttribute("start"):1}}}],toDOM(o){return o.attrs.order==1?S:["ol",{start:o.attrs.order},0]}},B={parseDOM:[{tag:"ul"}],toDOM(){return v}},V={parseDOM:[{tag:"li"}],toDOM(){return R},defining:!0};function O(o,e){let n={};for(let r in o)n[r]=o[r];for(let r in e)n[r]=e[r];return n}function q(o,e,n){return o.append({ordered_list:O(z,{content:"list_item+",group:n}),bullet_list:O(B,{content:"list_item+",group:n}),list_item:O(V,{content:e})})}function H(o,e=null){return function(n,r){let{$from:t,$to:l}=n.selection,i=t.blockRange(l);if(!i)return!1;let f=r?n.tr:null;return _(f,i,o,e)?(r&&r(f.scrollIntoView()),!0):!1}}function _(o,e,n,r=null){let t=!1,l=e,i=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(n)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let d=i.resolve(e.start-2);l=new C(d,d,e.depth),e.endIndex<e.parent.childCount&&(e=new C(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),t=!0}let f=A(l,n,r,e);return f?(o&&P(o,e,f,t,n),!0):!1}function P(o,e,n,r,t){let l=u.empty;for(let s=n.length-1;s>=0;s--)l=u.from(n[s].type.create(n[s].attrs,l));o.step(new w(e.start-(r?2:0),e.end,e.start,e.end,new y(l,0,0),n.length,!0));let i=0;for(let s=0;s<n.length;s++)n[s].type==t&&(i=s+1);let f=n.length-i,d=e.start+n.length-(r?2:0),p=e.parent;for(let s=e.startIndex,c=e.endIndex,a=!0;s<c;s++,a=!1)!a&&L(o.doc,d,f)&&(o.split(d,f),d+=2*f),d+=p.child(s).nodeSize;return o}function F(o,e){return function(n,r){let{$from:t,$to:l,node:i}=n.selection;if(i&&i.isBlock||t.depth<2||!t.sameParent(l))return!1;let f=t.node(-1);if(f.type!=o)return!1;if(t.parent.content.size==0&&t.node(-1).childCount==t.indexAfter(-1)){if(t.depth==3||t.node(-3).type!=o||t.index(-2)!=t.node(-2).childCount-1)return!1;if(r){let c=u.empty,a=t.index(-1)?1:t.index(-2)?2:3;for(let x=t.depth-a;x>=t.depth-3;x--)c=u.from(t.node(x).copy(c));let m=t.indexAfter(-1)<t.node(-2).childCount?1:t.indexAfter(-2)<t.node(-3).childCount?2:3;c=c.append(u.from(o.createAndFill()));let I=t.before(t.depth-(a-1)),h=n.tr.replace(I,t.after(-m),new y(c,4-a,0)),$=-1;h.doc.nodesBetween(I,h.doc.content.size,(x,M)=>{if($>-1)return!1;x.isTextblock&&x.content.size==0&&($=M+1)}),$>-1&&h.setSelection(D.near(h.doc.resolve($))),r(h.scrollIntoView())}return!0}let d=l.pos==t.end()?f.contentMatchAt(0).defaultType:null,p=n.tr.delete(t.pos,l.pos),s=d?[e?{type:o,attrs:e}:null,{type:d}]:void 0;return L(p.doc,t.pos,2,s)?(r&&r(p.split(t.pos,2,s).scrollIntoView()),!0):!1}}function Q(o,e){let n=F(o,e);return(r,t)=>n(r,t&&(l=>{let i=r.storedMarks||r.selection.$to.parentOffset&&r.selection.$from.marks();i&&l.ensureMarks(i),t(l)}))}function U(o){return function(e,n){let{$from:r,$to:t}=e.selection,l=r.blockRange(t,i=>i.childCount>0&&i.firstChild.type==o);return l?n?r.node(l.depth-1).type==o?J(e,n,o,l):N(e,n,l):!0:!1}}function J(o,e,n,r){let t=o.tr,l=r.end,i=r.$to.end(r.depth);l<i&&(t.step(new w(l-1,i,l,i,new y(u.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new C(t.doc.resolve(r.$from.pos),t.doc.resolve(i),r.depth));let f=b(r);if(f==null)return!1;t.lift(r,f);let d=t.doc.resolve(t.mapping.map(l,-1)-1);return k(t.doc,d.pos)&&d.nodeBefore.type==d.nodeAfter.type&&t.join(d.pos),e(t.scrollIntoView()),!0}function N(o,e,n){let r=o.tr,t=n.parent;for(let m=n.end,I=n.endIndex-1,h=n.startIndex;I>h;I--)m-=t.child(I).nodeSize,r.delete(m-1,m+1);let l=r.doc.resolve(n.start),i=l.nodeAfter;if(r.mapping.map(n.end)!=n.start+l.nodeAfter.nodeSize)return!1;let f=n.startIndex==0,d=n.endIndex==t.childCount,p=l.node(-1),s=l.index(-1);if(!p.canReplace(s+(f?0:1),s+1,i.content.append(d?u.empty:u.from(t))))return!1;let c=l.pos,a=c+i.nodeSize;return r.step(new w(c-(f?1:0),a+(d?1:0),c+1,a-1,new y((f?u.empty:u.from(t.copy(u.empty))).append(d?u.empty:u.from(t.copy(u.empty))),f?0:1,d?0:1),f?0:1)),e(r.scrollIntoView()),!0}function X(o){return function(e,n){let{$from:r,$to:t}=e.selection,l=r.blockRange(t,p=>p.childCount>0&&p.firstChild.type==o);if(!l)return!1;let i=l.startIndex;if(i==0)return!1;let f=l.parent,d=f.child(i-1);if(d.type!=o)return!1;if(n){let p=d.lastChild&&d.lastChild.type==f.type,s=u.from(p?o.create():null),c=new y(u.from(o.create(null,u.from(f.type.create(null,s)))),p?3:1,0),a=l.start,m=l.end;n(e.tr.step(new w(a-(p?3:1),m,a,m,c,1,!0)).scrollIntoView())}return!0}}export{q as addListNodes,B as bulletList,U as liftListItem,V as listItem,z as orderedList,X as sinkListItem,F as splitListItem,Q as splitListItemKeepMarks,H as wrapInList,_ as wrapRangeInList};
//# sourceMappingURL=prosemirror-schema-list.mjs.map