/* esm.sh - prosemirror-commands@1.7.2 */
import{liftTarget as M,replaceStep as $,ReplaceStep as X,canJoin as I,joinPoint as N,canSplit as C,ReplaceAroundStep as P,findWrapping as Y}from"../../../prosemirror-transform@^1.10.2?deps=prosemirror-model@1.25.12&target=es2022";import{Slice as B,Fragment as A}from"../../../prosemirror-model@1.25.12/es2022/prosemirror-model.mjs";import{NodeSelection as x,Selection as T,TextSelection as V,AllSelection as v,SelectionRange as E}from"../../../prosemirror-state@^1.0.0?deps=prosemirror-model@1.25.12&target=es2022";var K=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function J(t,e){let{$cursor:r}=t.selection;return!r||(e?!e.endOfTextblock("backward",t):r.parentOffset>0)?null:r}var Z=(t,e,r)=>{let o=J(t,r);if(!o)return!1;let n=j(o);if(!n){let i=o.blockRange(),f=i&&M(i);return f==null?!1:(e&&e(t.tr.lift(i,f).scrollIntoView()),!0)}let l=n.nodeBefore;if(H(t,n,e,-1))return!0;if(o.parent.content.size==0&&(h(l,"end")||x.isSelectable(l)))for(let i=o.depth;;i--){let f=$(t.doc,o.before(i),o.after(i),B.empty);if(f&&f.slice.size<f.to-f.from){if(e){let s=t.tr.step(f);s.setSelection(h(l,"end")?T.findFrom(s.doc.resolve(s.mapping.map(n.pos,-1)),-1):x.create(s.doc,n.pos-l.nodeSize)),e(s.scrollIntoView())}return!0}if(i==1||o.node(i-1).childCount>1)break}return l.isAtom&&n.depth==o.depth-1?(e&&e(t.tr.delete(n.pos-l.nodeSize,n.pos).scrollIntoView()),!0):!1},we=(t,e,r)=>{let o=J(t,r);if(!o)return!1;let n=j(o);return n?_(t,n,e):!1},Se=(t,e,r)=>{let o=q(t,r);if(!o)return!1;let n=R(o);return n?_(t,n,e):!1};function _(t,e,r){let o=e.nodeBefore,n=o,l=e.pos-1;for(;!n.isTextblock;l--){if(n.type.spec.isolating)return!1;let a=n.lastChild;if(!a)return!1;n=a}let i=e.nodeAfter,f=i,s=e.pos+1;for(;!f.isTextblock;s++){if(f.type.spec.isolating)return!1;let a=f.firstChild;if(!a)return!1;f=a}let u=$(t.doc,l,s,B.empty);if(!u||u.from!=l||u instanceof X&&u.slice.size>=s-l)return!1;if(r){let a=t.tr.step(u);a.setSelection(V.create(a.doc,l)),r(a.scrollIntoView())}return!0}function h(t,e,r=!1){for(let o=t;o;o=e=="start"?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(r&&o.childCount!=1)return!1}return!1}var ee=(t,e,r)=>{let{$head:o,empty:n}=t.selection,l=o;if(!n)return!1;if(o.parent.isTextblock){if(r?!r.endOfTextblock("backward",t):o.parentOffset>0)return!1;l=j(o)}let i=l&&l.nodeBefore;return!i||!x.isSelectable(i)?!1:(e&&e(t.tr.setSelection(x.create(t.doc,l.pos-i.nodeSize)).scrollIntoView()),!0)};function j(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function q(t,e){let{$cursor:r}=t.selection;return!r||(e?!e.endOfTextblock("forward",t):r.parentOffset<r.parent.content.size)?null:r}var te=(t,e,r)=>{let o=q(t,r);if(!o)return!1;let n=R(o);if(!n)return!1;let l=n.nodeAfter;if(H(t,n,e,1))return!0;if(o.parent.content.size==0&&(h(l,"start")||x.isSelectable(l))){let i=$(t.doc,o.before(),o.after(),B.empty);if(i&&i.slice.size<i.to-i.from){if(e){let f=t.tr.step(i);f.setSelection(h(l,"start")?T.findFrom(f.doc.resolve(f.mapping.map(n.pos)),1):x.create(f.doc,f.mapping.map(n.pos))),e(f.scrollIntoView())}return!0}}return l.isAtom&&n.depth==o.depth-1?(e&&e(t.tr.delete(n.pos,n.pos+l.nodeSize).scrollIntoView()),!0):!1},re=(t,e,r)=>{let{$head:o,empty:n}=t.selection,l=o;if(!n)return!1;if(o.parent.isTextblock){if(r?!r.endOfTextblock("forward",t):o.parentOffset<o.parent.content.size)return!1;l=R(o)}let i=l&&l.nodeAfter;return!i||!x.isSelectable(i)?!1:(e&&e(t.tr.setSelection(x.create(t.doc,l.pos)).scrollIntoView()),!0)};function R(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let r=t.node(e);if(t.index(e)+1<r.childCount)return t.doc.resolve(t.after(e+1));if(r.type.spec.isolating)break}return null}var he=(t,e)=>{let r=t.selection,o=r instanceof x,n;if(o){if(r.node.isTextblock||!I(t.doc,r.from))return!1;n=r.from}else if(n=N(t.doc,r.from,-1),n==null)return!1;if(e){let l=t.tr.join(n);o&&l.setSelection(x.create(l.doc,n-t.doc.resolve(n).nodeBefore.nodeSize)),e(l.scrollIntoView())}return!0},ye=(t,e)=>{let r=t.selection,o;if(r instanceof x){if(r.node.isTextblock||!I(t.doc,r.to))return!1;o=r.to}else if(o=N(t.doc,r.to,1),o==null)return!1;return e&&e(t.tr.join(o).scrollIntoView()),!0},Ae=(t,e)=>{let{$from:r,$to:o}=t.selection,n=r.blockRange(o),l=n&&M(n);return l==null?!1:(e&&e(t.tr.lift(n,l).scrollIntoView()),!0)},ne=(t,e)=>{let{$head:r,$anchor:o}=t.selection;return!r.parent.type.spec.code||!r.sameParent(o)?!1:(e&&e(t.tr.insertText(`
`).scrollIntoView()),!0)};function D(t){for(let e=0;e<t.edgeCount;e++){let{type:r}=t.edge(e);if(r.isTextblock&&!r.hasRequiredAttrs())return r}return null}var oe=(t,e)=>{let{$head:r,$anchor:o}=t.selection;if(!r.parent.type.spec.code||!r.sameParent(o))return!1;let n=r.node(-1),l=r.indexAfter(-1),i=D(n.contentMatchAt(l));if(!i||!n.canReplaceWith(l,l,i))return!1;if(e){let f=r.after(),s=t.tr.replaceWith(f,f,i.createAndFill());s.setSelection(T.near(s.doc.resolve(f),1)),e(s.scrollIntoView())}return!0},le=(t,e)=>{let r=t.selection,{$from:o,$to:n}=r;if(r instanceof v||o.parent.inlineContent||n.parent.inlineContent)return!1;let l=D(n.parent.contentMatchAt(n.indexAfter()));if(!l||!l.isTextblock)return!1;if(e){let i=(!o.parentOffset&&n.index()<n.parent.childCount?o:n).pos,f=t.tr.insert(i,l.createAndFill());f.setSelection(V.create(f.doc,i+1)),e(f.scrollIntoView())}return!0},ie=(t,e)=>{let{$cursor:r}=t.selection;if(!r||r.parent.content.size)return!1;if(r.depth>1&&r.after()!=r.end(-1)){let l=r.before();if(C(t.doc,l))return e&&e(t.tr.split(l).scrollIntoView()),!0}let o=r.blockRange(),n=o&&M(o);return n==null?!1:(e&&e(t.tr.lift(o,n).scrollIntoView()),!0)};function fe(t){return(e,r)=>{if(e.selection instanceof x&&e.selection.node.isBlock){let{$from:c}=e.selection;return!c.parentOffset||!C(e.doc,c.pos)?!1:(r&&r(e.tr.split(c.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let o=e.tr;!e.selection.empty&&(e.selection instanceof V||e.selection instanceof v)&&o.deleteSelection();let{$from:n}=o.selection,l=o.steps.length,i=[],f,s,u=!1,a=!1;for(let c=n.depth;;c--)if(n.node(c).isBlock){u=n.end(c)==n.pos+(n.depth-c),a=n.start(c)==n.pos-(n.depth-c),s=D(n.node(c-1).contentMatchAt(n.indexAfter(c-1)));let d=t&&t(n.parent,u,n);i.unshift(d||(u&&s?{type:s}:null)),f=c;break}else{if(c==1)return!1;i.unshift(null)}let m=n.pos,k=C(o.doc,m,i.length,i);if(k||(i[0]=s?{type:s}:null,k=C(o.doc,m,i.length,i)),!k)return!1;if(o.split(m,i.length,i),!u&&a&&n.node(f).type!=s){let c=o.mapping.slice(l),p=c.map(n.before(f)),d=o.doc.resolve(p);s&&n.node(f-1).canReplaceWith(d.index(),d.index()+1,s)&&o.setNodeMarkup(c.map(n.before(f)),s)}return r&&r(o.scrollIntoView()),!0}}var G=fe(),Be=(t,e)=>G(t,e&&(r=>{let o=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();o&&r.ensureMarks(o),e(r)})),Ie=(t,e)=>{let{$from:r,to:o}=t.selection,n,l=r.sharedDepth(o);return l==0?!1:(n=r.before(l),e&&e(t.tr.setSelection(x.create(t.doc,n))),!0)},se=(t,e)=>(e&&e(t.tr.setSelection(new v(t.doc))),!0);function ce(t,e,r){let o=e.nodeBefore,n=e.nodeAfter,l=e.index();return!o||!n||!o.type.compatibleContent(n.type)?!1:!o.content.size&&e.parent.canReplace(l-1,l)?(r&&r(t.tr.delete(e.pos-o.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(l,l+1)||!(n.isTextblock||I(t.doc,e.pos))?!1:(r&&r(t.tr.join(e.pos).scrollIntoView()),!0)}function H(t,e,r,o){let n=e.nodeBefore,l=e.nodeAfter,i,f,s=n.type.spec.isolating||l.type.spec.isolating;if(!s&&ce(t,e,r))return!0;let u=!s&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(i=(f=n.contentMatchAt(n.childCount)).findWrapping(l.type))&&f.matchType(i[0]||l.type).validEnd){if(r){let c=e.pos+l.nodeSize,p=A.empty;for(let b=i.length-1;b>=0;b--)p=A.from(i[b].create(null,p));p=A.from(n.copy(p));let d=t.tr.step(new P(e.pos-1,c,e.pos,c,new B(p,1,0),i.length,!0)),g=d.doc.resolve(c+2*i.length);g.nodeAfter&&g.nodeAfter.type==n.type&&I(d.doc,g.pos)&&d.join(g.pos),r(d.scrollIntoView())}return!0}let a=l.type.spec.isolating||o>0&&s?null:T.findFrom(e,1),m=a&&a.$from.blockRange(a.$to),k=m&&M(m);if(k!=null&&k>=e.depth)return r&&r(t.tr.lift(m,k).scrollIntoView()),!0;if(u&&h(l,"start",!0)&&h(n,"end")){let c=n,p=[];for(;p.push(c),!c.isTextblock;)c=c.lastChild;let d=l,g=1;for(;!d.isTextblock;d=d.firstChild)g++;if(c.canReplace(c.childCount,c.childCount,d.content)){if(r){let b=A.empty;for(let S=p.length-1;S>=0;S--)b=A.from(p[S].copy(b));let y=t.tr.step(new P(e.pos-p.length,e.pos+l.nodeSize,e.pos+g,e.pos+l.nodeSize-g,new B(b,p.length,0),0,!0));r(y.scrollIntoView())}return!0}}return!1}function U(t){return function(e,r){let o=e.selection,n=t<0?o.$from:o.$to,l=n.depth;for(;n.node(l).isInline;){if(!l)return!1;l--}return n.node(l).isTextblock?(r&&r(e.tr.setSelection(V.create(e.doc,t<0?n.start(l):n.end(l)))),!0):!1}}var ae=U(-1),ue=U(1);function Ce(t,e=null){return function(r,o){let{$from:n,$to:l}=r.selection,i=n.blockRange(l),f=i&&Y(i,t,e);return f?(o&&o(r.tr.wrap(i,f).scrollIntoView()),!0):!1}}function Me(t,e=null){return function(r,o){let n=!1;for(let l=0;l<r.selection.ranges.length&&!n;l++){let{$from:{pos:i},$to:{pos:f}}=r.selection.ranges[l];r.doc.nodesBetween(i,f,(s,u)=>{if(n)return!1;if(!(!s.isTextblock||s.hasMarkup(t,e)))if(s.type==t)n=!0;else{let a=r.doc.resolve(u),m=a.index();n=a.parent.canReplaceWith(m,m+1,t)}})}if(!n)return!1;if(o){let l=r.tr;for(let i=0;i<r.selection.ranges.length;i++){let{$from:{pos:f},$to:{pos:s}}=r.selection.ranges[i];l.setBlockType(f,s,t,e)}o(l.scrollIntoView())}return!0}}function pe(t,e,r,o){for(let n=0;n<e.length;n++){let{$from:l,$to:i}=e[n],f=l.depth==0?t.inlineContent&&t.type.allowsMarkType(r):!1;if(t.nodesBetween(l.pos,i.pos,(s,u)=>{if(f||!o&&s.isAtom&&s.isInline&&u>=l.pos&&u+s.nodeSize<=i.pos)return!1;f=s.inlineContent&&s.type.allowsMarkType(r)}),f)return!0}return!1}function de(t){let e=[];for(let r=0;r<t.length;r++){let{$from:o,$to:n}=t[r];o.doc.nodesBetween(o.pos,n.pos,(l,i)=>{if(l.isAtom&&l.content.size&&l.isInline&&i>=o.pos&&i+l.nodeSize<=n.pos)return i+1>o.pos&&e.push(new E(o,o.doc.resolve(i+1))),o=o.doc.resolve(i+1+l.content.size),!1}),o.pos<n.pos&&e.push(new E(o,n))}return e}function Te(t,e=null,r){let o=(r&&r.removeWhenPresent)!==!1,n=(r&&r.enterInlineAtoms)!==!1,l=!(r&&r.includeWhitespace);return function(i,f){let{empty:s,$cursor:u,ranges:a}=i.selection;if(s&&!u||!pe(i.doc,a,t,n))return!1;if(f)if(u)t.isInSet(i.storedMarks||u.marks())?f(i.tr.removeStoredMark(t)):f(i.tr.addStoredMark(t.create(e)));else{let m,k=i.tr;n||(a=de(a)),o?m=!a.some(c=>i.doc.rangeHasMark(c.$from.pos,c.$to.pos,t)):m=!a.every(c=>{let p=!1;return k.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,g,b)=>{if(p)return!1;p=!t.isInSet(d.marks)&&!!b&&b.type.allowsMarkType(t)&&!(d.isText&&/^\s*$/.test(d.textBetween(Math.max(0,c.$from.pos-g),Math.min(d.nodeSize,c.$to.pos-g))))}),!p});for(let c=0;c<a.length;c++){let{$from:p,$to:d}=a[c];if(!m)k.removeMark(p.pos,d.pos,t);else{let g=p.pos,b=d.pos,y=p.nodeAfter,S=d.nodeBefore,F=l&&y&&y.isText?/^\s*/.exec(y.text)[0].length:0,Q=l&&S&&S.isText?/\s*$/.exec(S.text)[0].length:0;g+F<b&&(g+=F,b-=Q),k.addMark(g,b,t.create(e))}}f(k.scrollIntoView())}return!0}}function me(t,e){return r=>{if(!r.isGeneric)return t(r);let o=[];for(let l=0;l<r.mapping.maps.length;l++){let i=r.mapping.maps[l];for(let f=0;f<o.length;f++)o[f]=i.map(o[f]);i.forEach((f,s,u,a)=>o.push(u,a))}let n=[];for(let l=0;l<o.length;l+=2){let i=o[l],f=o[l+1],s=r.doc.resolve(i),u=s.sharedDepth(f),a=s.node(u);for(let m=s.indexAfter(u),k=s.after(u+1);k<=f;++m){let c=a.maybeChild(m);if(!c)break;if(m&&n.indexOf(k)==-1){let p=a.child(m-1);p.type==c.type&&e(p,c)&&n.push(k)}k+=c.nodeSize}}n.sort((l,i)=>l-i);for(let l=n.length-1;l>=0;l--)I(r.doc,n[l])&&r.join(n[l]);t(r)}}function Ve(t,e){let r=Array.isArray(e)?o=>e.indexOf(o.type.name)>-1:e;return(o,n,l)=>t(o,n&&me(n,r),l)}function O(...t){return function(e,r,o){for(let n=0;n<t.length;n++)if(t[n](e,r,o))return!0;return!1}}var z=O(K,Z,ee),W=O(K,te,re),w={Enter:O(ne,le,ie,G),"Mod-Enter":oe,Backspace:z,"Mod-Backspace":z,"Shift-Backspace":z,Delete:W,"Mod-Delete":W,"Mod-a":se},L={"Ctrl-h":w.Backspace,"Alt-Backspace":w["Mod-Backspace"],"Ctrl-d":w.Delete,"Ctrl-Alt-Backspace":w["Mod-Delete"],"Alt-Delete":w["Mod-Delete"],"Alt-d":w["Mod-Delete"],"Ctrl-a":ae,"Ctrl-e":ue};for(let t in w)L[t]=w[t];var ke=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,ze=ke?L:w;export{Ve as autoJoin,ze as baseKeymap,O as chainCommands,le as createParagraphNear,K as deleteSelection,oe as exitCode,Z as joinBackward,ye as joinDown,te as joinForward,we as joinTextblockBackward,Se as joinTextblockForward,he as joinUp,Ae as lift,ie as liftEmptyBlock,L as macBaseKeymap,ne as newlineInCode,w as pcBaseKeymap,se as selectAll,ee as selectNodeBackward,re as selectNodeForward,Ie as selectParentNode,ue as selectTextblockEnd,ae as selectTextblockStart,Me as setBlockType,G as splitBlock,fe as splitBlockAs,Be as splitBlockKeepMarks,Te as toggleMark,Ce as wrapIn};
//# sourceMappingURL=prosemirror-commands.mjs.map