3 lines
9.4 KiB
JavaScript
3 lines
9.4 KiB
JavaScript
import{i as A,j as S,M as G,k as H}from"./EditorOutline-CZg3-0Pd.chunk.mjs";var I=200,u=function(){};u.prototype.append=function(n){return n.length?(n=u.from(n),!this.length&&n||n.length<I&&this.leafAppend(n)||this.length<I&&n.leafPrepend(this)||this.appendInner(n)):this},u.prototype.prepend=function(n){return n.length?u.from(n).append(this):this},u.prototype.appendInner=function(n){return new z(this,n)},u.prototype.slice=function(n,t){return n===void 0&&(n=0),t===void 0&&(t=this.length),n>=t?u.empty:this.sliceInner(Math.max(0,n),Math.min(this.length,t))},u.prototype.get=function(n){if(!(n<0||n>=this.length))return this.getInner(n)},u.prototype.forEach=function(n,t,e){t===void 0&&(t=0),e===void 0&&(e=this.length),t<=e?this.forEachInner(n,t,e,0):this.forEachInvertedInner(n,t,e,0)},u.prototype.map=function(n,t,e){t===void 0&&(t=0),e===void 0&&(e=this.length);var i=[];return this.forEach(function(r,s){return i.push(n(r,s))},t,e),i},u.from=function(n){return n instanceof u?n:n&&n.length?new k(n):u.empty};var k=(function(n){function t(i){n.call(this),this.values=i}n&&(t.__proto__=n),t.prototype=Object.create(n&&n.prototype),t.prototype.constructor=t;var e={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(i,r){return i==0&&r==this.length?this:new t(this.values.slice(i,r))},t.prototype.getInner=function(i){return this.values[i]},t.prototype.forEachInner=function(i,r,s,o){for(var p=r;p<s;p++)if(i(this.values[p],o+p)===!1)return!1},t.prototype.forEachInvertedInner=function(i,r,s,o){for(var p=r-1;p>=s;p--)if(i(this.values[p],o+p)===!1)return!1},t.prototype.leafAppend=function(i){if(this.length+i.length<=I)return new t(this.values.concat(i.flatten()))},t.prototype.leafPrepend=function(i){if(this.length+i.length<=I)return new t(i.flatten().concat(this.values))},e.length.get=function(){return this.values.length},e.depth.get=function(){return 0},Object.defineProperties(t.prototype,e),t})(u);u.empty=new k([]);var z=(function(n){function t(e,i){n.call(this),this.left=e,this.right=i,this.length=e.length+i.length,this.depth=Math.max(e.depth,i.depth)+1}return n&&(t.__proto__=n),t.prototype=Object.create(n&&n.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,i,r,s){var o=this.left.length;if(i<o&&this.left.forEachInner(e,i,Math.min(r,o),s)===!1||r>o&&this.right.forEachInner(e,Math.max(i-o,0),Math.min(this.length,r)-o,s+o)===!1)return!1},t.prototype.forEachInvertedInner=function(e,i,r,s){var o=this.left.length;if(i>o&&this.right.forEachInvertedInner(e,i-o,Math.max(r,o)-o,s+o)===!1||r<o&&this.left.forEachInvertedInner(e,Math.min(i,o),r,s)===!1)return!1},t.prototype.sliceInner=function(e,i){if(e==0&&i==this.length)return this;var r=this.left.length;return i<=r?this.left.slice(e,i):e>=r?this.right.slice(e-r,i-r):this.left.slice(e,r).append(this.right.slice(0,i-r))},t.prototype.leafAppend=function(e){var i=this.right.leafAppend(e);if(i)return new t(this.left,i)},t.prototype.leafPrepend=function(e){var i=this.left.leafPrepend(e);if(i)return new t(i,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t})(u),x=u;const F=500;class m{constructor(t,e){this.items=t,this.eventCount=e}popEvent(t,e){if(this.eventCount==0)return null;let i=this.items.length;for(;;i--)if(this.items.get(i-1).selection){--i;break}let r,s;e&&(r=this.remapping(i,this.items.length),s=r.maps.length);let o=t.tr,p,a,f=[],c=[];return this.items.forEach((l,h)=>{if(!l.step){r||(r=this.remapping(i,h+1),s=r.maps.length),s--,c.push(l);return}if(r){c.push(new g(l.map));let d=l.step.map(r.slice(s)),y;d&&o.maybeStep(d).doc&&(y=o.mapping.maps[o.mapping.maps.length-1],f.push(new g(y,void 0,void 0,f.length+c.length))),s--,y&&r.appendMap(y,s)}else o.maybeStep(l.step);if(l.selection)return p=r?l.selection.map(r.slice(s)):l.selection,a=new m(this.items.slice(0,i).append(c.reverse().concat(f)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:p}}addTransform(t,e,i,r){let s=[],o=this.eventCount,p=this.items,a=!r&&p.length?p.get(p.length-1):null;for(let c=0;c<t.steps.length;c++){let l=t.steps[c].invert(t.docs[c]),h=new g(t.mapping.maps[c],l,e),d;(d=a&&a.merge(h))&&(h=d,c?s.pop():p=p.slice(0,p.length-1)),s.push(h),e&&(o++,e=void 0),r||(a=h)}let f=o-i.depth;return f>B&&(p=_(p,f),o-=f),new m(p.append(s),o)}remapping(t,e){let i=new G;return this.items.forEach((r,s)=>{let o=r.mirrorOffset!=null&&s-r.mirrorOffset>=t?i.maps.length-r.mirrorOffset:void 0;i.appendMap(r.map,o)},t,e),i}addMaps(t){return this.eventCount==0?this:new m(this.items.append(t.map(e=>new g(e))),this.eventCount)}rebased(t,e){if(!this.eventCount)return this;let i=[],r=Math.max(0,this.items.length-e),s=t.mapping,o=t.steps.length,p=this.eventCount;this.items.forEach(h=>{h.selection&&p--},r);let a=e;this.items.forEach(h=>{let d=s.getMirror(--a);if(d==null)return;o=Math.min(o,d);let y=s.maps[d];if(h.step){let j=t.steps[d].invert(t.docs[d]),T=h.selection&&h.selection.map(s.slice(a+1,d));T&&p++,i.push(new g(y,j,T))}else i.push(new g(y))},r);let f=[];for(let h=e;h<o;h++)f.push(new g(s.maps[h]));let c=this.items.slice(0,r).append(f).append(i),l=new m(c,p);return l.emptyItemCount()>F&&(l=l.compress(this.items.length-i.length)),l}emptyItemCount(){let t=0;return this.items.forEach(e=>{e.step||t++}),t}compress(t=this.items.length){let e=this.remapping(0,t),i=e.maps.length,r=[],s=0;return this.items.forEach((o,p)=>{if(p>=t)r.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(e.slice(i)),f=a&&a.getMap();if(i--,f&&e.appendMap(f,i),a){let c=o.selection&&o.selection.map(e.slice(i));c&&s++;let l=new g(f.invert(),a,c),h,d=r.length-1;(h=r.length&&r[d].merge(l))?r[d]=h:r.push(l)}}else o.map&&i--},this.items.length,0),new m(x.from(r.reverse()),s)}}m.empty=new m(x.empty,0);function _(n,t){let e;return n.forEach((i,r)=>{if(i.selection&&t--==0)return e=r,!1}),n.slice(e)}class g{constructor(t,e,i,r){this.map=t,this.step=e,this.selection=i,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let e=t.step.merge(this.step);if(e)return new g(e.getMap().invert(),e,this.selection)}}}class v{constructor(t,e,i,r,s){this.done=t,this.undone=e,this.prevRanges=i,this.prevTime=r,this.prevComposition=s}}const B=20;function K(n,t,e,i){let r=e.getMeta(w),s;if(r)return r.historyState;e.getMeta(J)&&(n=new v(n.done,n.undone,null,0,-1));let o=e.getMeta("appendedTransaction");if(e.steps.length==0)return n;if(o&&o.getMeta(w))return o.getMeta(w).redo?new v(n.done.addTransform(e,void 0,i,M(t)),n.undone,b(e.mapping.maps),n.prevTime,n.prevComposition):new v(n.done,n.undone.addTransform(e,void 0,i,M(t)),null,n.prevTime,n.prevComposition);if(e.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let p=e.getMeta("composition"),a=n.prevTime==0||!o&&n.prevComposition!=p&&(n.prevTime<(e.time||0)-i.newGroupDelay||!U(e,n.prevRanges)),f=o?E(n.prevRanges,e.mapping):b(e.mapping.maps);return new v(n.done.addTransform(e,a?t.selection.getBookmark():void 0,i,M(t)),m.empty,f,e.time,p??n.prevComposition)}else return(s=e.getMeta("rebased"))?new v(n.done.rebased(e,s),n.undone.rebased(e,s),E(n.prevRanges,e.mapping),n.prevTime,n.prevComposition):new v(n.done.addMaps(e.mapping.maps),n.undone.addMaps(e.mapping.maps),E(n.prevRanges,e.mapping),n.prevTime,n.prevComposition)}function U(n,t){if(!t)return!1;if(!n.docChanged)return!0;let e=!1;return n.mapping.maps[0].forEach((i,r)=>{for(let s=0;s<t.length;s+=2)i<=t[s+1]&&r>=t[s]&&(e=!0)}),e}function b(n){let t=[];for(let e=n.length-1;e>=0&&t.length==0;e--)n[e].forEach((i,r,s,o)=>t.push(s,o));return t}function E(n,t){if(!n)return null;let e=[];for(let i=0;i<n.length;i+=2){let r=t.map(n[i],1),s=t.map(n[i+1],-1);r<=s&&e.push(r,s)}return e}function V(n,t,e){let i=M(t),r=w.get(t).spec.config,s=(e?n.undone:n.done).popEvent(t,i);if(!s)return null;let o=s.selection.resolve(s.transform.doc),p=(e?n.done:n.undone).addTransform(s.transform,t.selection.getBookmark(),r,i),a=new v(e?p:s.remaining,e?s.remaining:p,null,0,-1);return s.transform.setSelection(o).setMeta(w,{redo:e,historyState:a})}let C=!1,O=null;function M(n){let t=n.plugins;if(O!=t){C=!1,O=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){C=!0;break}}return C}const w=new S("history"),J=new S("closeHistory");function L(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new A({key:w,state:{init(){return new v(m.empty,m.empty,null,0,-1)},apply(t,e,i){return K(e,i,t,n)}},config:n,props:{handleDOMEvents:{beforeinput(t,e){let i=e.inputType,r=i=="historyUndo"?D:i=="historyRedo"?R:null;return r?(e.preventDefault(),r(t.state,t.dispatch)):!1}}}})}function P(n,t){return(e,i)=>{let r=w.getState(e);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(i){let s=V(r,e,n);s&&i(t?s.scrollIntoView():s)}return!0}}const D=P(!1,!0),R=P(!0,!0),Q=H.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:t})=>D(n,t),redo:()=>({state:n,dispatch:t})=>R(n,t)}},addProseMirrorPlugins(){return[L(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{Q as H};
|
|
//# sourceMappingURL=index-DbAfJFk8.chunk.mjs.map
|