pillardash-ui-react 0.1.138 → 0.1.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Cards/Card.js +1 -1
- package/dist/cjs/components/Cards/Card.js.map +1 -1
- package/dist/cjs/components/Form/TextEditor/ImagePopover.js +2 -0
- package/dist/cjs/components/Form/TextEditor/ImagePopover.js.map +1 -0
- package/dist/cjs/components/Form/TextEditor/LinkPopover.js +2 -0
- package/dist/cjs/components/Form/TextEditor/LinkPopover.js.map +1 -0
- package/dist/cjs/components/Form/TextEditor/TextEditor.js +1 -1
- package/dist/cjs/components/Form/TextEditor/TextEditor.js.map +1 -1
- package/dist/cjs/components/Form/TextEditor/ToolbarGroups.js +2 -0
- package/dist/cjs/components/Form/TextEditor/ToolbarGroups.js.map +1 -0
- package/dist/cjs/components/Form/TextEditor/extensions.js +2 -0
- package/dist/cjs/components/Form/TextEditor/extensions.js.map +1 -0
- package/dist/cjs/components/Form/TextEditor/toolbar.js +2 -0
- package/dist/cjs/components/Form/TextEditor/toolbar.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/core/dist/index.js +1 -1
- package/dist/cjs/node_modules/@tiptap/core/dist/index.js.map +1 -1
- package/dist/cjs/node_modules/@tiptap/extension-list/dist/index.js +1 -1
- package/dist/cjs/node_modules/@tiptap/extension-list/dist/index.js.map +1 -1
- package/dist/cjs/node_modules/@tiptap/extension-table/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-table/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/extension-table-cell/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-table-cell/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/extension-table-header/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-table-header/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/extension-table-row/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-table-row/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/extension-task-item/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-task-item/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/extension-task-list/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-task-list/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/@tiptap/extension-text-align/dist/index.js +2 -0
- package/dist/cjs/node_modules/@tiptap/extension-text-align/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/prosemirror-keymap/dist/index.js +2 -0
- package/dist/cjs/node_modules/prosemirror-keymap/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/prosemirror-model/dist/index.js +1 -1
- package/dist/cjs/node_modules/prosemirror-model/dist/index.js.map +1 -1
- package/dist/cjs/node_modules/prosemirror-tables/dist/index.js +2 -0
- package/dist/cjs/node_modules/prosemirror-tables/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/prosemirror-transform/dist/index.js +1 -1
- package/dist/cjs/node_modules/prosemirror-transform/dist/index.js.map +1 -1
- package/dist/cjs/node_modules/prosemirror-view/dist/index.js +2 -0
- package/dist/cjs/node_modules/prosemirror-view/dist/index.js.map +1 -0
- package/dist/cjs/node_modules/w3c-keyname/index.js +2 -0
- package/dist/cjs/node_modules/w3c-keyname/index.js.map +1 -0
- package/dist/esm/components/Cards/Card.mjs +1 -1
- package/dist/esm/components/Cards/Card.mjs.map +1 -1
- package/dist/esm/components/Form/TextEditor/ImagePopover.mjs +2 -0
- package/dist/esm/components/Form/TextEditor/ImagePopover.mjs.map +1 -0
- package/dist/esm/components/Form/TextEditor/LinkPopover.mjs +2 -0
- package/dist/esm/components/Form/TextEditor/LinkPopover.mjs.map +1 -0
- package/dist/esm/components/Form/TextEditor/TextEditor.mjs +1 -1
- package/dist/esm/components/Form/TextEditor/TextEditor.mjs.map +1 -1
- package/dist/esm/components/Form/TextEditor/ToolbarGroups.mjs +2 -0
- package/dist/esm/components/Form/TextEditor/ToolbarGroups.mjs.map +1 -0
- package/dist/esm/components/Form/TextEditor/extensions.mjs +2 -0
- package/dist/esm/components/Form/TextEditor/extensions.mjs.map +1 -0
- package/dist/esm/components/Form/TextEditor/toolbar.mjs +2 -0
- package/dist/esm/components/Form/TextEditor/toolbar.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/core/dist/index.mjs +1 -1
- package/dist/esm/node_modules/@tiptap/core/dist/index.mjs.map +1 -1
- package/dist/esm/node_modules/@tiptap/extension-list/dist/index.mjs +1 -1
- package/dist/esm/node_modules/@tiptap/extension-list/dist/index.mjs.map +1 -1
- package/dist/esm/node_modules/@tiptap/extension-table/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-table/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/extension-table-cell/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-table-cell/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/extension-table-header/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-table-header/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/extension-table-row/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-table-row/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/extension-task-item/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-task-item/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/extension-task-list/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-task-list/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/@tiptap/extension-text-align/dist/index.mjs +2 -0
- package/dist/esm/node_modules/@tiptap/extension-text-align/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/prosemirror-keymap/dist/index.mjs +2 -0
- package/dist/esm/node_modules/prosemirror-keymap/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/prosemirror-model/dist/index.mjs +1 -1
- package/dist/esm/node_modules/prosemirror-model/dist/index.mjs.map +1 -1
- package/dist/esm/node_modules/prosemirror-tables/dist/index.mjs +2 -0
- package/dist/esm/node_modules/prosemirror-tables/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/prosemirror-transform/dist/index.mjs +1 -1
- package/dist/esm/node_modules/prosemirror-transform/dist/index.mjs.map +1 -1
- package/dist/esm/node_modules/prosemirror-view/dist/index.mjs +2 -0
- package/dist/esm/node_modules/prosemirror-view/dist/index.mjs.map +1 -0
- package/dist/esm/node_modules/w3c-keyname/index.mjs +2 -0
- package/dist/esm/node_modules/w3c-keyname/index.mjs.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/styles.css +1 -1
- package/package.json +9 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Slice as t,ReplaceError as e,Fragment as r,Mark as n,MarkType as i}from"../../prosemirror-model/dist/index.mjs";const s=Math.pow(2,16);function o(t){return 65535&t}class l{constructor(t,e,r){this.pos=t,this.delInfo=e,this.recover=r}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class a{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&a.empty)return a.empty}recover(t){let e=0,r=o(t);if(!this.inverted)for(let t=0;t<r;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*r]+e+function(t){return(t-(65535&t))/s}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,r){let n=0,i=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let p=this.ranges[a]-(this.inverted?n:0);if(p>t)break;let h=this.ranges[a+i],c=this.ranges[a+o],f=p+h;if(t<=f){let i=p+n+((h?t==p?-1:t==f?1:e:e)<0?0:c);if(r)return i;let o=t==(e<0?p:f)?null:a/3+(t-p)*s,d=t==p?2:t==f?1:4;return(e<0?t!=p:t!=f)&&(d|=8),new l(i,d,o)}n+=c-h}return r?t+n:new l(t+n,0,null)}touches(t,e){let r=0,n=o(e),i=this.inverted?2:1,s=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let o=this.ranges[e]-(this.inverted?r:0);if(o>t)break;let l=this.ranges[e+i];if(t<=o+l&&e==3*n)return!0;r+=this.ranges[e+s]-l}return!1}forEach(t){let e=this.inverted?2:1,r=this.inverted?1:2;for(let n=0,i=0;n<this.ranges.length;n+=3){let s=this.ranges[n],o=s-(this.inverted?i:0),l=s+(this.inverted?0:i),a=this.ranges[n+e],p=this.ranges[n+r];t(o,o+a,l,l+p),i+=p-a}}invert(){return new a(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?a.empty:new a(t<0?[0,-t,0]:[0,0,t])}}a.empty=new a([]);class p{constructor(t,e,r=0,n=(t?t.length:0)){this.mirror=e,this.from=r,this.to=n,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new p(this._maps,this.mirror,t,e)}appendMap(t,e){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=e&&this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,r=this._maps.length;e<t._maps.length;e++){let n=t.getMirror(e);this.appendMap(t._maps[e],null!=n&&n<e?r+n:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,r=this._maps.length+t._maps.length;e>=0;e--){let n=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=n&&n>e?r-n-1:void 0)}}invert(){let t=new p;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let r=this.from;r<this.to;r++)t=this._maps[r].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,!1)}_map(t,e,r){let n=0;for(let r=this.from;r<this.to;r++){let i=this._maps[r].mapResult(t,e);if(null!=i.recover){let e=this.getMirror(r);if(null!=e&&e>r&&e<this.to){r=e,t=this._maps[e].recover(i.recover);continue}}n|=i.delInfo,t=i.pos}return r?t:new l(t,n,null)}}const h=Object.create(null);class c{getMap(){return a.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=h[e.stepType];if(!r)throw new RangeError(`No step type ${e.stepType} defined`);return r.fromJSON(t,e)}static jsonID(t,e){if(t in h)throw new RangeError("Duplicate use of step JSON ID "+t);return h[t]=e,e.prototype.jsonID=t,e}}class f{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new f(t,null)}static fail(t){return new f(null,t)}static fromReplace(t,r,n,i){try{return f.ok(t.replace(r,n,i))}catch(t){if(t instanceof e)return f.fail(t.message);throw t}}}function d(t,e,n){let i=[];for(let r=0;r<t.childCount;r++){let s=t.child(r);s.content.size&&(s=s.copy(d(s.content,e,s))),s.isInline&&(s=e(s,n,r)),i.push(s)}return r.fromArray(i)}class u extends c{constructor(t,e,r){super(),this.from=t,this.to=e,this.mark=r}apply(e){let r=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),s=new t(d(r.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),i),r.openStart,r.openEnd);return f.fromReplace(e,this.from,this.to,s)}invert(){return new m(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deleted&&r.deleted||e.pos>=r.pos?null:new u(e.pos,r.pos,this.mark)}merge(t){return t instanceof u&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new u(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new u(e.from,e.to,t.markFromJSON(e.mark))}}c.jsonID("addMark",u);class m extends c{constructor(t,e,r){super(),this.from=t,this.to=e,this.mark=r}apply(e){let r=e.slice(this.from,this.to),n=new t(d(r.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),e),r.openStart,r.openEnd);return f.fromReplace(e,this.from,this.to,n)}invert(){return new u(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deleted&&r.deleted||e.pos>=r.pos?null:new m(e.pos,r.pos,this.mark)}merge(t){return t instanceof m&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new m(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new m(e.from,e.to,t.markFromJSON(e.mark))}}c.jsonID("removeMark",m);class y extends c{constructor(t,e){super(),this.pos=t,this.mark=e}apply(e){let n=e.nodeAt(this.pos);if(!n)return f.fail("No node at mark step's position");let i=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return f.fromReplace(e,this.pos,this.pos+1,new t(r.from(i),0,n.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let r=0;r<e.marks.length;r++)if(!e.marks[r].isInSet(t))return new y(this.pos,e.marks[r]);return new y(this.pos,this.mark)}}return new g(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new y(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new y(e.pos,t.markFromJSON(e.mark))}}c.jsonID("addNodeMark",y);class g extends c{constructor(t,e){super(),this.pos=t,this.mark=e}apply(e){let n=e.nodeAt(this.pos);if(!n)return f.fail("No node at mark step's position");let i=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return f.fromReplace(e,this.pos,this.pos+1,new t(r.from(i),0,n.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new y(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new g(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new g(e.pos,t.markFromJSON(e.mark))}}c.jsonID("removeNodeMark",g);class w extends c{constructor(t,e,r,n=!1){super(),this.from=t,this.to=e,this.slice=r,this.structure=n}apply(t){return this.structure&&v(t,this.from,this.to)?f.fail("Structure replace would overwrite content"):f.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new a([this.from,this.to-this.from,this.slice.size])}invert(t){return new w(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deletedAcross&&r.deletedAcross?null:new w(e.pos,Math.max(e.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof w)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let r=this.slice.size+e.slice.size==0?t.empty:new t(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new w(e.from,this.to,r,this.structure)}}{let r=this.slice.size+e.slice.size==0?t.empty:new t(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new w(this.from,this.to+(e.to-e.from),r,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(e,r){if("number"!=typeof r.from||"number"!=typeof r.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new w(r.from,r.to,t.fromJSON(e,r.slice),!!r.structure)}}c.jsonID("replace",w);class k extends c{constructor(t,e,r,n,i,s,o=!1){super(),this.from=t,this.to=e,this.gapFrom=r,this.gapTo=n,this.slice=i,this.insert=s,this.structure=o}apply(t){if(this.structure&&(v(t,this.from,this.gapFrom)||v(t,this.gapTo,this.to)))return f.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return f.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,e.content);return r?f.fromReplace(t,this.from,this.to,r):f.fail("Content does not fit in gap")}getMap(){return new a([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new k(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),n=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),i=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return e.deletedAcross&&r.deletedAcross||n<e.pos||i>r.pos?null:new k(e.pos,r.pos,n,i,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(e,r){if("number"!=typeof r.from||"number"!=typeof r.to||"number"!=typeof r.gapFrom||"number"!=typeof r.gapTo||"number"!=typeof r.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new k(r.from,r.to,r.gapFrom,r.gapTo,t.fromJSON(e,r.slice),r.insert,!!r.structure)}}function v(t,e,r){let n=t.resolve(e),i=r-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let t=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,i--}}return!1}function S(e,n,i,s=i.contentMatch,o=!0){let l=e.doc.nodeAt(n),a=[],p=n+1;for(let n=0;n<l.childCount;n++){let h=l.child(n),c=p+h.nodeSize,f=s.matchType(h.type);if(f){s=f;for(let t=0;t<h.marks.length;t++)i.allowsMarkType(h.marks[t].type)||e.step(new m(p,c,h.marks[t]));if(o&&h.isText&&"pre"!=i.whitespace){let e,n,s=/\r?\n|\r/g;for(;e=s.exec(h.text);)n||(n=new t(r.from(i.schema.text(" ",i.allowedMarks(h.marks))),0,0)),a.push(new w(p+e.index,p+e.index+e[0].length,n))}}else a.push(new w(p,c,t.empty));p=c}if(!s.validEnd){let n=s.fillBefore(r.empty,!0);e.replace(p,p,new t(n,0,0))}for(let t=a.length-1;t>=0;t--)e.step(a[t])}function M(t,e,r){return(0==e||t.canReplace(e,t.childCount))&&(r==t.childCount||t.canReplace(0,r))}function x(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let n=t.$from.node(r),i=t.$from.index(r),s=t.$to.indexAfter(r);if(r<t.depth&&n.canReplace(i,s,e))return r;if(0==r||n.type.spec.isolating||!M(n,i,s))break}return null}function R(t,e,r=null,n=t){let i=function(t,e){let{parent:r,startIndex:n,endIndex:i}=t,s=r.contentMatchAt(n).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return r.canReplaceWith(n,i,o)?s:null}(t,e),s=i&&function(t,e){let{parent:r,startIndex:n,endIndex:i}=t,s=r.child(n),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let l=(o.length?o[o.length-1]:e).contentMatch;for(let t=n;l&&t<i;t++)l=l.matchType(r.child(t).type);return l&&l.validEnd?o:null}(n,e);return s?i.map(b).concat({type:e,attrs:r}).concat(s.map(b)):null}function b(t){return{type:t,attrs:null}}function C(t,e,r,n){e.forEach(((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let i=t.mapping.slice(n).map(r+1+s+o.index);t.replaceWith(i,i+1,e.type.schema.linebreakReplacement.create())}}}))}function N(t,e,r,n){e.forEach(((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let i=t.mapping.slice(n).map(r+1+s);t.replaceWith(i,i+1,e.type.schema.text("\n"))}}))}function I(t,e,r=1,n){let i=t.resolve(e),s=i.depth-r,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let t=i.depth-1,e=r-2;t>s;t--,e--){let r=i.node(t),s=i.index(t);if(r.type.spec.isolating)return!1;let o=r.content.cutByIndex(s,r.childCount),l=n&&n[e+1];l&&(o=o.replaceChild(0,l.type.create(l.attrs)));let a=n&&n[e]||r;if(!r.canReplace(s+1,r.childCount)||!a.type.validContent(o))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function T(t,e){let r=t.resolve(e),n=r.index();return A(r.nodeBefore,r.nodeAfter)&&r.parent.canReplace(n,n+1)}function A(t,e){return!(!t||!e||t.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let r=t.contentMatchAt(t.childCount),{linebreakReplacement:n}=t.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==n?t.type.schema.nodes.text:s.type;if(r=r.matchType(o),!r)return!1;if(!t.type.allowsMarks(s.marks))return!1}return r.validEnd}(t,e))}function O(t,e,r=-1){let n=t.resolve(e);for(let t=n.depth;;t--){let i,s,o=n.index(t);if(t==n.depth?(i=n.nodeBefore,s=n.nodeAfter):r>0?(i=n.node(t+1),o++,s=n.node(t).maybeChild(o)):(i=n.node(t).maybeChild(o-1),s=n.node(t+1)),i&&!i.isTextblock&&A(i,s)&&n.node(t).canReplace(o,o+1))return e;if(0==t)break;e=r<0?n.before(t):n.after(t)}}function E(t,e,r){let n=t.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),r))return e;if(0==n.parentOffset)for(let t=n.depth-1;t>=0;t--){let e=n.index(t);if(n.node(t).canReplaceWith(e,e,r))return n.before(t+1);if(e>0)return null}if(n.parentOffset==n.parent.content.size)for(let t=n.depth-1;t>=0;t--){let e=n.indexAfter(t);if(n.node(t).canReplaceWith(e,e,r))return n.after(t+1);if(e<n.node(t).childCount)return null}return null}function J(e,r,n=r,i=t.empty){if(r==n&&!i.size)return null;let s=e.resolve(r),o=e.resolve(n);return z(s,o,i)?new w(r,n,i):new F(s,o,i).fit()}function z(t,e,r){return!r.openStart&&!r.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),r.content)}c.jsonID("replaceAround",k);class F{constructor(t,e,n){this.$from=t,this.$to=e,this.unplaced=n,this.frontier=[],this.placed=r.empty;for(let e=0;e<=t.depth;e++){let r=t.node(e);this.frontier.push({type:r.type,match:r.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=r.from(t.node(e).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),r=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&1==s.childCount;)s=s.firstChild.content,o--,l--;let a=new t(s,o,l);return e>-1?new k(n.pos,e,this.$to.pos,this.$to.end(),a,r):a.size||n.pos!=this.$to.pos?new w(n.pos,i.pos,a):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,r=0,n=this.unplaced.openEnd;r<t;r++){let i=e.firstChild;if(e.childCount>1&&(n=0),i.type.spec.isolating&&n<=r){t=r;break}e=i.content}for(let e=1;e<=2;e++)for(let n=1==e?t:this.unplaced.openStart;n>=0;n--){let t,i=null;n?(i=B(this.unplaced.content,n-1).firstChild,t=i.content):t=this.unplaced.content;let s=t.firstChild;for(let t=this.depth;t>=0;t--){let o,{type:l,match:a}=this.frontier[t],p=null;if(1==e&&(s?a.matchType(s.type)||(p=a.fillBefore(r.from(s),!1)):i&&l.compatibleContent(i.type)))return{sliceDepth:n,frontierDepth:t,parent:i,inject:p};if(2==e&&s&&(o=a.findWrapping(s.type)))return{sliceDepth:n,frontierDepth:t,parent:i,wrap:o};if(i&&a.matchType(i.type))break}}}openMore(){let{content:e,openStart:r,openEnd:n}=this.unplaced,i=B(e,r);return!(!i.childCount||i.firstChild.isLeaf)&&(this.unplaced=new t(e,r+1,Math.max(n,i.size+r>=e.size-n?r+1:0)),!0)}dropNode(){let{content:e,openStart:r,openEnd:n}=this.unplaced,i=B(e,r);if(i.childCount<=1&&r>0){let s=e.size-r<=r+i.size;this.unplaced=new t(_(e,r-1,1),r-1,s?r-1:n)}else this.unplaced=new t(_(e,r,1),r,n)}placeNodes({sliceDepth:e,frontierDepth:n,parent:i,inject:s,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let t=0;t<o.length;t++)this.openFrontierNode(o[t]);let l=this.unplaced,a=i?i.content:l.content,p=l.openStart-e,h=0,c=[],{match:f,type:d}=this.frontier[n];if(s){for(let t=0;t<s.childCount;t++)c.push(s.child(t));f=f.matchFragment(s)}let u=a.size+e-(l.content.size-l.openEnd);for(;h<a.childCount;){let t=a.child(h),e=f.matchType(t.type);if(!e)break;h++,(h>1||0==p||t.content.size)&&(f=e,c.push($(t.mark(d.allowedMarks(t.marks)),1==h?p:0,h==a.childCount?u:-1)))}let m=h==a.childCount;m||(u=-1),this.placed=D(this.placed,n,r.from(c)),this.frontier[n].match=f,m&&u<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=a;t<u;t++){let t=e.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),e=t.content}this.unplaced=m?0==e?t.empty:new t(_(l.content,e-1,1),e-1,u<0?l.openEnd:e-1):new t(_(l.content,e,h),l.openStart,l.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,e=this.frontier[this.depth];if(!e.type.isTextblock||!j(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:r}=this.$to,n=this.$to.after(r);for(;r>1&&n==this.$to.end(--r);)++n;return n}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:r,type:n}=this.frontier[e],i=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),s=j(t,e,n,r,i);if(s){for(let r=e-1;r>=0;r--){let{match:e,type:n}=this.frontier[r],i=j(t,r,n,e,!0);if(!i||i.childCount)continue t}return{depth:e,fit:s,move:i?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=D(this.placed,e.depth,e.fit)),t=e.move;for(let r=e.depth+1;r<=t.depth;r++){let e=t.node(r),n=e.type.contentMatch.fillBefore(e.content,!0,t.index(r));this.openFrontierNode(e.type,e.attrs,n)}return t}openFrontierNode(t,e=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(t),this.placed=D(this.placed,this.depth,r.from(t.create(e,n))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(r.empty,!0);t.childCount&&(this.placed=D(this.placed,this.frontier.length,t))}}function _(t,e,r){return 0==e?t.cutByIndex(r,t.childCount):t.replaceChild(0,t.firstChild.copy(_(t.firstChild.content,e-1,r)))}function D(t,e,r){return 0==e?t.append(r):t.replaceChild(t.childCount-1,t.lastChild.copy(D(t.lastChild.content,e-1,r)))}function B(t,e){for(let r=0;r<e;r++)t=t.firstChild.content;return t}function $(t,e,n){if(e<=0)return t;let i=t.content;return e>1&&(i=i.replaceChild(0,$(i.firstChild,e-1,1==i.childCount?n-1:0))),e>0&&(i=t.type.contentMatch.fillBefore(i).append(i),n<=0&&(i=i.append(t.type.contentMatch.matchFragment(i).fillBefore(r.empty,!0)))),t.copy(i)}function j(t,e,r,n,i){let s=t.node(e),o=i?t.indexAfter(e):t.index(e);if(o==s.childCount&&!r.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!function(t,e,r){for(let n=r;n<e.childCount;n++)if(!t.allowsMarks(e.child(n).marks))return!0;return!1}(r,s.content,o)?l:null}function W(t,e,n,i,s){if(e<n){let r=t.firstChild;t=t.replaceChild(0,r.copy(W(r.content,e+1,n,i,r)))}if(e>i){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(r.empty,!0))}return t}function L(t,e){let r=[];for(let n=Math.min(t.depth,e.depth);n>=0;n--){let i=t.start(n);if(i<t.pos-(t.depth-n)||e.end(n)>e.pos+(e.depth-n)||t.node(n).type.spec.isolating||e.node(n).type.spec.isolating)break;(i==e.start(n)||n==t.depth&&n==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&n&&e.start(n-1)==i-1)&&r.push(n)}return r}class q extends c{constructor(t,e,r){super(),this.pos=t,this.attr=e,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return f.fail("No node at attribute step's position");let i=Object.create(null);for(let t in n.attrs)i[t]=n.attrs[t];i[this.attr]=this.value;let s=n.type.create(i,null,n.marks);return f.fromReplace(e,this.pos,this.pos+1,new t(r.from(s),0,n.isLeaf?0:1))}getMap(){return a.empty}invert(t){return new q(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new q(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new q(e.pos,e.attr,e.value)}}c.jsonID("attr",q);class G extends c{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let r in t.attrs)e[r]=t.attrs[r];e[this.attr]=this.value;let r=t.type.create(e,t.content,t.marks);return f.ok(r)}getMap(){return a.empty}invert(t){return new G(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new G(e.attr,e.value)}}c.jsonID("docAttr",G);let H=class extends Error{};H=function t(e){let r=Error.call(this,e);return r.__proto__=t.prototype,r},(H.prototype=Object.create(Error.prototype)).constructor=H,H.prototype.name="TransformError";class K{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new p}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new H(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(e,r=e,n=t.empty){let i=J(this.doc,e,r,n);return i&&this.step(i),this}replaceWith(e,n,i){return this.replace(e,n,new t(r.from(i),0,0))}delete(e,r){return this.replace(e,r,t.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(e,r,n){return function(e,r,n,i){if(!i.size)return e.deleteRange(r,n);let s=e.doc.resolve(r),o=e.doc.resolve(n);if(z(s,o,i))return e.step(new w(r,n,i));let l=L(s,e.doc.resolve(n));0==l[l.length-1]&&l.pop();let a=-(s.depth+1);l.unshift(a);for(let t=s.depth,e=s.pos-1;t>0;t--,e--){let r=s.node(t).type.spec;if(r.defining||r.definingAsContext||r.isolating)break;l.indexOf(t)>-1?a=t:s.before(t)==e&&l.splice(1,0,-t)}let p=l.indexOf(a),h=[],c=i.openStart;for(let t=i.content,e=0;;e++){let r=t.firstChild;if(h.push(r),e==i.openStart)break;t=r.content}for(let t=c-1;t>=0;t--){let e=h[t],r=(f=e.type).spec.defining||f.spec.definingForContent;if(r&&!e.sameMarkup(s.node(Math.abs(a)-1)))c=t;else if(r||!e.type.isTextblock)break}var f;for(let r=i.openStart;r>=0;r--){let a=(r+c+1)%(i.openStart+1),f=h[a];if(f)for(let r=0;r<l.length;r++){let h=l[(r+p)%l.length],c=!0;h<0&&(c=!1,h=-h);let d=s.node(h-1),u=s.index(h-1);if(d.canReplaceWith(u,u,f.type,f.marks))return e.replace(s.before(h),c?o.after(h):n,new t(W(i.content,0,i.openStart,a),a,i.openEnd))}}let d=e.steps.length;for(let t=l.length-1;t>=0&&(e.replace(r,n,i),!(e.steps.length>d));t--){let e=l[t];e<0||(r=s.before(e),n=o.after(e))}}(this,e,r,n),this}replaceRangeWith(e,n,i){return function(e,n,i,s){if(!s.isInline&&n==i&&e.doc.resolve(n).parent.content.size){let t=E(e.doc,n,s.type);null!=t&&(n=i=t)}e.replaceRange(n,i,new t(r.from(s),0,0))}(this,e,n,i),this}deleteRange(t,e){return function(t,e,r){let n=t.doc.resolve(e),i=t.doc.resolve(r),s=L(n,i);for(let e=0;e<s.length;e++){let r=s[e],o=e==s.length-1;if(o&&0==r||n.node(r).type.contentMatch.validEnd)return t.delete(n.start(r),i.end(r));if(r>0&&(o||n.node(r-1).canReplace(n.index(r-1),i.indexAfter(r-1))))return t.delete(n.before(r),i.after(r))}for(let s=1;s<=n.depth&&s<=i.depth;s++)if(e-n.start(s)==n.depth-s&&r>n.end(s)&&i.end(s)-r!=i.depth-s&&n.start(s-1)==i.start(s-1)&&n.node(s-1).canReplace(n.index(s-1),i.index(s-1)))return t.delete(n.before(s),r);t.delete(e,r)}(this,t,e),this}lift(e,n){return function(e,n,i){let{$from:s,$to:o,depth:l}=n,a=s.before(l+1),p=o.after(l+1),h=a,c=p,f=r.empty,d=0;for(let t=l,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,f=r.from(s.node(t).copy(f)),d++):h--;let u=r.empty,m=0;for(let t=l,e=!1;t>i;t--)e||o.after(t+1)<o.end(t)?(e=!0,u=r.from(o.node(t).copy(u)),m++):c++;e.step(new k(h,c,a,p,new t(f.append(u),d,m),f.size-d,!0))}(this,e,n),this}join(e,r=1){return function(e,r,n){let i=null,{linebreakReplacement:s}=e.doc.type.schema,o=e.doc.resolve(r-n),l=o.node().type;if(s&&l.inlineContent){let t="pre"==l.whitespace,e=!!l.contentMatch.matchType(s);t&&!e?i=!1:!t&&e&&(i=!0)}let a=e.steps.length;if(!1===i){let t=e.doc.resolve(r+n);N(e,t.node(),t.before(),a)}l.inlineContent&&S(e,r+n-1,l,o.node().contentMatchAt(o.index()),null==i);let p=e.mapping.slice(a),h=p.map(r-n);if(e.step(new w(h,p.map(r+n,-1),t.empty,!0)),!0===i){let t=e.doc.resolve(h);C(e,t.node(),t.before(),e.steps.length)}}(this,e,r),this}wrap(e,n){return function(e,n,i){let s=r.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=r.from(i[t].type.create(i[t].attrs,s))}let o=n.start,l=n.end;e.step(new k(o,l,o,l,new t(s,0,0),i.length,!0))}(this,e,n),this}setBlockType(e,n=e,i,s=null){return function(e,n,i,s,o){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let l=e.steps.length;e.doc.nodesBetween(n,i,((n,i)=>{let a="function"==typeof o?o(n):o;if(n.isTextblock&&!n.hasMarkup(s,a)&&function(t,e,r){let n=t.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,r)}(e.doc,e.mapping.slice(l).map(i),s)){let o=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?o=!1:!t&&e&&(o=!0)}!1===o&&N(e,n,i,l),S(e,e.mapping.slice(l).map(i,1),s,void 0,null===o);let p=e.mapping.slice(l),h=p.map(i,1),c=p.map(i+n.nodeSize,1);return e.step(new k(h,c,h+1,c-1,new t(r.from(s.create(a,null,n.marks)),0,0),1,!0)),!0===o&&C(e,n,i,l),!1}}))}(this,e,n,i,s),this}setNodeMarkup(e,n,i=null,s){return function(e,n,i,s,o){let l=e.doc.nodeAt(n);if(!l)throw new RangeError("No node at given position");i||(i=l.type);let a=i.create(s,null,o||l.marks);if(l.isLeaf)return e.replaceWith(n,n+l.nodeSize,a);if(!i.validContent(l.content))throw new RangeError("Invalid content for node type "+i.name);e.step(new k(n,n+l.nodeSize,n+1,n+l.nodeSize-1,new t(r.from(a),0,0),1,!0))}(this,e,n,i,s),this}setNodeAttribute(t,e,r){return this.step(new q(t,e,r)),this}setDocAttribute(t,e){return this.step(new G(t,e)),this}addNodeMark(t,e){return this.step(new y(t,e)),this}removeNodeMark(t,e){let r=this.doc.nodeAt(t);if(!r)throw new RangeError("No node at position "+t);if(e instanceof n)e.isInSet(r.marks)&&this.step(new g(t,e));else{let n,i=r.marks,s=[];for(;n=e.isInSet(i);)s.push(new g(t,n)),i=n.removeFromSet(i);for(let t=s.length-1;t>=0;t--)this.step(s[t])}return this}split(e,n=1,i){return function(e,n,i=1,s){let o=e.doc.resolve(n),l=r.empty,a=r.empty;for(let t=o.depth,e=o.depth-i,n=i-1;t>e;t--,n--){l=r.from(o.node(t).copy(l));let e=s&&s[n];a=r.from(e?e.type.create(e.attrs,a):o.node(t).copy(a))}e.step(new w(n,n,new t(l.append(a),i,i),!0))}(this,e,n,i),this}addMark(t,e,r){return function(t,e,r,n){let i,s,o=[],l=[];t.doc.nodesBetween(e,r,((t,a,p)=>{if(!t.isInline)return;let h=t.marks;if(!n.isInSet(h)&&p.type.allowsMarkType(n.type)){let p=Math.max(a,e),c=Math.min(a+t.nodeSize,r),f=n.addToSet(h);for(let t=0;t<h.length;t++)h[t].isInSet(f)||(i&&i.to==p&&i.mark.eq(h[t])?i.to=c:o.push(i=new m(p,c,h[t])));s&&s.to==p?s.to=c:l.push(s=new u(p,c,n))}})),o.forEach((e=>t.step(e))),l.forEach((e=>t.step(e)))}(this,t,e,r),this}removeMark(t,e,r){return function(t,e,r,n){let s=[],o=0;t.doc.nodesBetween(e,r,((t,l)=>{if(!t.isInline)return;o++;let a=null;if(n instanceof i){let e,r=t.marks;for(;e=n.isInSet(r);)(a||(a=[])).push(e),r=e.removeFromSet(r)}else n?n.isInSet(t.marks)&&(a=[n]):a=t.marks;if(a&&a.length){let n=Math.min(l+t.nodeSize,r);for(let t=0;t<a.length;t++){let r,i=a[t];for(let t=0;t<s.length;t++){let e=s[t];e.step==o-1&&i.eq(s[t].style)&&(r=e)}r?(r.to=n,r.step=o):s.push({style:i,from:Math.max(l,e),to:n,step:o})}}})),s.forEach((e=>t.step(new m(e.from,e.to,e.style))))}(this,t,e,r),this}clearIncompatible(t,e,r){return S(this,t,e,r),this}}export{u as AddMarkStep,y as AddNodeMarkStep,q as AttrStep,G as DocAttrStep,l as MapResult,p as Mapping,m as RemoveMarkStep,g as RemoveNodeMarkStep,k as ReplaceAroundStep,w as ReplaceStep,c as Step,a as StepMap,f as StepResult,K as Transform,H as TransformError,T as canJoin,I as canSplit,R as findWrapping,E as insertPoint,O as joinPoint,x as liftTarget,J as replaceStep};
|
|
1
|
+
import{Slice as t,ReplaceError as e,Fragment as r,Mark as n,MarkType as i}from"../../prosemirror-model/dist/index.mjs";const s=Math.pow(2,16);function o(t){return 65535&t}class l{constructor(t,e,r){this.pos=t,this.delInfo=e,this.recover=r}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class a{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&a.empty)return a.empty}recover(t){let e=0,r=o(t);if(!this.inverted)for(let t=0;t<r;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*r]+e+function(t){return(t-(65535&t))/s}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,r){let n=0,i=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let p=this.ranges[a]-(this.inverted?n:0);if(p>t)break;let h=this.ranges[a+i],c=this.ranges[a+o],f=p+h;if(t<=f){let i=p+n+((h?t==p?-1:t==f?1:e:e)<0?0:c);if(r)return i;let o=t==(e<0?p:f)?null:a/3+(t-p)*s,d=t==p?2:t==f?1:4;return(e<0?t!=p:t!=f)&&(d|=8),new l(i,d,o)}n+=c-h}return r?t+n:new l(t+n,0,null)}touches(t,e){let r=0,n=o(e),i=this.inverted?2:1,s=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let o=this.ranges[e]-(this.inverted?r:0);if(o>t)break;let l=this.ranges[e+i];if(t<=o+l&&e==3*n)return!0;r+=this.ranges[e+s]-l}return!1}forEach(t){let e=this.inverted?2:1,r=this.inverted?1:2;for(let n=0,i=0;n<this.ranges.length;n+=3){let s=this.ranges[n],o=s-(this.inverted?i:0),l=s+(this.inverted?0:i),a=this.ranges[n+e],p=this.ranges[n+r];t(o,o+a,l,l+p),i+=p-a}}invert(){return new a(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?a.empty:new a(t<0?[0,-t,0]:[0,0,t])}}a.empty=new a([]);class p{constructor(t,e,r=0,n=(t?t.length:0)){this.mirror=e,this.from=r,this.to=n,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new p(this._maps,this.mirror,t,e)}appendMap(t,e){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=e&&this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,r=this._maps.length;e<t._maps.length;e++){let n=t.getMirror(e);this.appendMap(t._maps[e],null!=n&&n<e?r+n:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,r=this._maps.length+t._maps.length;e>=0;e--){let n=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=n&&n>e?r-n-1:void 0)}}invert(){let t=new p;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let r=this.from;r<this.to;r++)t=this._maps[r].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,!1)}_map(t,e,r){let n=0;for(let r=this.from;r<this.to;r++){let i=this._maps[r].mapResult(t,e);if(null!=i.recover){let e=this.getMirror(r);if(null!=e&&e>r&&e<this.to){r=e,t=this._maps[e].recover(i.recover);continue}}n|=i.delInfo,t=i.pos}return r?t:new l(t,n,null)}}const h=Object.create(null);class c{getMap(){return a.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=h[e.stepType];if(!r)throw new RangeError(`No step type ${e.stepType} defined`);return r.fromJSON(t,e)}static jsonID(t,e){if(t in h)throw new RangeError("Duplicate use of step JSON ID "+t);return h[t]=e,e.prototype.jsonID=t,e}}class f{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new f(t,null)}static fail(t){return new f(null,t)}static fromReplace(t,r,n,i){try{return f.ok(t.replace(r,n,i))}catch(t){if(t instanceof e)return f.fail(t.message);throw t}}}function d(t,e,n){let i=[];for(let r=0;r<t.childCount;r++){let s=t.child(r);s.content.size&&(s=s.copy(d(s.content,e,s))),s.isInline&&(s=e(s,n,r)),i.push(s)}return r.fromArray(i)}class u extends c{constructor(t,e,r){super(),this.from=t,this.to=e,this.mark=r}apply(e){let r=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),s=new t(d(r.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),i),r.openStart,r.openEnd);return f.fromReplace(e,this.from,this.to,s)}invert(){return new m(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deleted&&r.deleted||e.pos>=r.pos?null:new u(e.pos,r.pos,this.mark)}merge(t){return t instanceof u&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new u(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new u(e.from,e.to,t.markFromJSON(e.mark))}}c.jsonID("addMark",u);class m extends c{constructor(t,e,r){super(),this.from=t,this.to=e,this.mark=r}apply(e){let r=e.slice(this.from,this.to),n=new t(d(r.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),e),r.openStart,r.openEnd);return f.fromReplace(e,this.from,this.to,n)}invert(){return new u(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deleted&&r.deleted||e.pos>=r.pos?null:new m(e.pos,r.pos,this.mark)}merge(t){return t instanceof m&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new m(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new m(e.from,e.to,t.markFromJSON(e.mark))}}c.jsonID("removeMark",m);class y extends c{constructor(t,e){super(),this.pos=t,this.mark=e}apply(e){let n=e.nodeAt(this.pos);if(!n)return f.fail("No node at mark step's position");let i=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return f.fromReplace(e,this.pos,this.pos+1,new t(r.from(i),0,n.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let r=0;r<e.marks.length;r++)if(!e.marks[r].isInSet(t))return new y(this.pos,e.marks[r]);return new y(this.pos,this.mark)}}return new g(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new y(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new y(e.pos,t.markFromJSON(e.mark))}}c.jsonID("addNodeMark",y);class g extends c{constructor(t,e){super(),this.pos=t,this.mark=e}apply(e){let n=e.nodeAt(this.pos);if(!n)return f.fail("No node at mark step's position");let i=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return f.fromReplace(e,this.pos,this.pos+1,new t(r.from(i),0,n.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new y(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new g(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new g(e.pos,t.markFromJSON(e.mark))}}c.jsonID("removeNodeMark",g);class w extends c{constructor(t,e,r,n=!1){super(),this.from=t,this.to=e,this.slice=r,this.structure=n}apply(t){return this.structure&&v(t,this.from,this.to)?f.fail("Structure replace would overwrite content"):f.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new a([this.from,this.to-this.from,this.slice.size])}invert(t){return new w(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deletedAcross&&r.deletedAcross?null:new w(e.pos,Math.max(e.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof w)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let r=this.slice.size+e.slice.size==0?t.empty:new t(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new w(e.from,this.to,r,this.structure)}}{let r=this.slice.size+e.slice.size==0?t.empty:new t(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new w(this.from,this.to+(e.to-e.from),r,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(e,r){if("number"!=typeof r.from||"number"!=typeof r.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new w(r.from,r.to,t.fromJSON(e,r.slice),!!r.structure)}}c.jsonID("replace",w);class k extends c{constructor(t,e,r,n,i,s,o=!1){super(),this.from=t,this.to=e,this.gapFrom=r,this.gapTo=n,this.slice=i,this.insert=s,this.structure=o}apply(t){if(this.structure&&(v(t,this.from,this.gapFrom)||v(t,this.gapTo,this.to)))return f.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return f.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,e.content);return r?f.fromReplace(t,this.from,this.to,r):f.fail("Content does not fit in gap")}getMap(){return new a([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new k(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),n=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),i=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return e.deletedAcross&&r.deletedAcross||n<e.pos||i>r.pos?null:new k(e.pos,r.pos,n,i,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(e,r){if("number"!=typeof r.from||"number"!=typeof r.to||"number"!=typeof r.gapFrom||"number"!=typeof r.gapTo||"number"!=typeof r.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new k(r.from,r.to,r.gapFrom,r.gapTo,t.fromJSON(e,r.slice),r.insert,!!r.structure)}}function v(t,e,r){let n=t.resolve(e),i=r-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let t=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,i--}}return!1}function S(e,n,i,s=i.contentMatch,o=!0){let l=e.doc.nodeAt(n),a=[],p=n+1;for(let n=0;n<l.childCount;n++){let h=l.child(n),c=p+h.nodeSize,f=s.matchType(h.type);if(f){s=f;for(let t=0;t<h.marks.length;t++)i.allowsMarkType(h.marks[t].type)||e.step(new m(p,c,h.marks[t]));if(o&&h.isText&&"pre"!=i.whitespace){let e,n,s=/\r?\n|\r/g;for(;e=s.exec(h.text);)n||(n=new t(r.from(i.schema.text(" ",i.allowedMarks(h.marks))),0,0)),a.push(new w(p+e.index,p+e.index+e[0].length,n))}}else a.push(new w(p,c,t.empty));p=c}if(!s.validEnd){let n=s.fillBefore(r.empty,!0);e.replace(p,p,new t(n,0,0))}for(let t=a.length-1;t>=0;t--)e.step(a[t])}function M(t,e,r){return(0==e||t.canReplace(e,t.childCount))&&(r==t.childCount||t.canReplace(0,r))}function x(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let n=t.$from.node(r),i=t.$from.index(r),s=t.$to.indexAfter(r);if(r<t.depth&&n.canReplace(i,s,e))return r;if(0==r||n.type.spec.isolating||!M(n,i,s))break}return null}function R(t,e,r=null,n=t){let i=function(t,e){let{parent:r,startIndex:n,endIndex:i}=t,s=r.contentMatchAt(n).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return r.canReplaceWith(n,i,o)?s:null}(t,e),s=i&&function(t,e){let{parent:r,startIndex:n,endIndex:i}=t,s=r.child(n),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let l=(o.length?o[o.length-1]:e).contentMatch;for(let t=n;l&&t<i;t++)l=l.matchType(r.child(t).type);return l&&l.validEnd?o:null}(n,e);return s?i.map(C).concat({type:e,attrs:r}).concat(s.map(C)):null}function C(t){return{type:t,attrs:null}}function b(t,e,r,n){e.forEach(((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let i=t.mapping.slice(n).map(r+1+s+o.index);t.replaceWith(i,i+1,e.type.schema.linebreakReplacement.create())}}}))}function N(t,e,r,n){e.forEach(((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let i=t.mapping.slice(n).map(r+1+s);t.replaceWith(i,i+1,e.type.schema.text("\n"))}}))}function I(t,e,r=1,n){let i=t.resolve(e),s=i.depth-r,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let t=i.depth-1,e=r-2;t>s;t--,e--){let r=i.node(t),s=i.index(t);if(r.type.spec.isolating)return!1;let o=r.content.cutByIndex(s,r.childCount),l=n&&n[e+1];l&&(o=o.replaceChild(0,l.type.create(l.attrs)));let a=n&&n[e]||r;if(!r.canReplace(s+1,r.childCount)||!a.type.validContent(o))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function T(t,e){let r=t.resolve(e),n=r.index();return A(r.nodeBefore,r.nodeAfter)&&r.parent.canReplace(n,n+1)}function A(t,e){return!(!t||!e||t.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let r=t.contentMatchAt(t.childCount),{linebreakReplacement:n}=t.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==n?t.type.schema.nodes.text:s.type;if(r=r.matchType(o),!r)return!1;if(!t.type.allowsMarks(s.marks))return!1}return r.validEnd}(t,e))}function O(t,e,r=-1){let n=t.resolve(e);for(let t=n.depth;;t--){let i,s,o=n.index(t);if(t==n.depth?(i=n.nodeBefore,s=n.nodeAfter):r>0?(i=n.node(t+1),o++,s=n.node(t).maybeChild(o)):(i=n.node(t).maybeChild(o-1),s=n.node(t+1)),i&&!i.isTextblock&&A(i,s)&&n.node(t).canReplace(o,o+1))return e;if(0==t)break;e=r<0?n.before(t):n.after(t)}}function E(t,e,r){let n=t.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),r))return e;if(0==n.parentOffset)for(let t=n.depth-1;t>=0;t--){let e=n.index(t);if(n.node(t).canReplaceWith(e,e,r))return n.before(t+1);if(e>0)return null}if(n.parentOffset==n.parent.content.size)for(let t=n.depth-1;t>=0;t--){let e=n.indexAfter(t);if(n.node(t).canReplaceWith(e,e,r))return n.after(t+1);if(e<n.node(t).childCount)return null}return null}function J(t,e,r){let n=t.resolve(e);if(!r.content.size)return e;let i=r.content;for(let t=0;t<r.openStart;t++)i=i.firstChild.content;for(let t=1;t<=(0==r.openStart&&r.size?2:1);t++)for(let e=n.depth;e>=0;e--){let r=e==n.depth?0:n.pos<=(n.start(e+1)+n.end(e+1))/2?-1:1,s=n.index(e)+(r>0?1:0),o=n.node(e),l=!1;if(1==t)l=o.canReplace(s,s,i);else{let t=o.contentMatchAt(s).findWrapping(i.firstChild.type);l=t&&o.canReplaceWith(s,s,t[0])}if(l)return 0==r?n.pos:r<0?n.before(e+1):n.after(e+1)}return null}function z(e,r,n=r,i=t.empty){if(r==n&&!i.size)return null;let s=e.resolve(r),o=e.resolve(n);return F(s,o,i)?new w(r,n,i):new _(s,o,i).fit()}function F(t,e,r){return!r.openStart&&!r.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),r.content)}c.jsonID("replaceAround",k);class _{constructor(t,e,n){this.$from=t,this.$to=e,this.unplaced=n,this.frontier=[],this.placed=r.empty;for(let e=0;e<=t.depth;e++){let r=t.node(e);this.frontier.push({type:r.type,match:r.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=r.from(t.node(e).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),r=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&1==s.childCount;)s=s.firstChild.content,o--,l--;let a=new t(s,o,l);return e>-1?new k(n.pos,e,this.$to.pos,this.$to.end(),a,r):a.size||n.pos!=this.$to.pos?new w(n.pos,i.pos,a):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,r=0,n=this.unplaced.openEnd;r<t;r++){let i=e.firstChild;if(e.childCount>1&&(n=0),i.type.spec.isolating&&n<=r){t=r;break}e=i.content}for(let e=1;e<=2;e++)for(let n=1==e?t:this.unplaced.openStart;n>=0;n--){let t,i=null;n?(i=$(this.unplaced.content,n-1).firstChild,t=i.content):t=this.unplaced.content;let s=t.firstChild;for(let t=this.depth;t>=0;t--){let o,{type:l,match:a}=this.frontier[t],p=null;if(1==e&&(s?a.matchType(s.type)||(p=a.fillBefore(r.from(s),!1)):i&&l.compatibleContent(i.type)))return{sliceDepth:n,frontierDepth:t,parent:i,inject:p};if(2==e&&s&&(o=a.findWrapping(s.type)))return{sliceDepth:n,frontierDepth:t,parent:i,wrap:o};if(i&&a.matchType(i.type))break}}}openMore(){let{content:e,openStart:r,openEnd:n}=this.unplaced,i=$(e,r);return!(!i.childCount||i.firstChild.isLeaf)&&(this.unplaced=new t(e,r+1,Math.max(n,i.size+r>=e.size-n?r+1:0)),!0)}dropNode(){let{content:e,openStart:r,openEnd:n}=this.unplaced,i=$(e,r);if(i.childCount<=1&&r>0){let s=e.size-r<=r+i.size;this.unplaced=new t(D(e,r-1,1),r-1,s?r-1:n)}else this.unplaced=new t(D(e,r,1),r,n)}placeNodes({sliceDepth:e,frontierDepth:n,parent:i,inject:s,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let t=0;t<o.length;t++)this.openFrontierNode(o[t]);let l=this.unplaced,a=i?i.content:l.content,p=l.openStart-e,h=0,c=[],{match:f,type:d}=this.frontier[n];if(s){for(let t=0;t<s.childCount;t++)c.push(s.child(t));f=f.matchFragment(s)}let u=a.size+e-(l.content.size-l.openEnd);for(;h<a.childCount;){let t=a.child(h),e=f.matchType(t.type);if(!e)break;h++,(h>1||0==p||t.content.size)&&(f=e,c.push(W(t.mark(d.allowedMarks(t.marks)),1==h?p:0,h==a.childCount?u:-1)))}let m=h==a.childCount;m||(u=-1),this.placed=B(this.placed,n,r.from(c)),this.frontier[n].match=f,m&&u<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=a;t<u;t++){let t=e.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),e=t.content}this.unplaced=m?0==e?t.empty:new t(D(l.content,e-1,1),e-1,u<0?l.openEnd:e-1):new t(D(l.content,e,h),l.openStart,l.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,e=this.frontier[this.depth];if(!e.type.isTextblock||!j(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:r}=this.$to,n=this.$to.after(r);for(;r>1&&n==this.$to.end(--r);)++n;return n}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:r,type:n}=this.frontier[e],i=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),s=j(t,e,n,r,i);if(s){for(let r=e-1;r>=0;r--){let{match:e,type:n}=this.frontier[r],i=j(t,r,n,e,!0);if(!i||i.childCount)continue t}return{depth:e,fit:s,move:i?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=B(this.placed,e.depth,e.fit)),t=e.move;for(let r=e.depth+1;r<=t.depth;r++){let e=t.node(r),n=e.type.contentMatch.fillBefore(e.content,!0,t.index(r));this.openFrontierNode(e.type,e.attrs,n)}return t}openFrontierNode(t,e=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(t),this.placed=B(this.placed,this.depth,r.from(t.create(e,n))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(r.empty,!0);t.childCount&&(this.placed=B(this.placed,this.frontier.length,t))}}function D(t,e,r){return 0==e?t.cutByIndex(r,t.childCount):t.replaceChild(0,t.firstChild.copy(D(t.firstChild.content,e-1,r)))}function B(t,e,r){return 0==e?t.append(r):t.replaceChild(t.childCount-1,t.lastChild.copy(B(t.lastChild.content,e-1,r)))}function $(t,e){for(let r=0;r<e;r++)t=t.firstChild.content;return t}function W(t,e,n){if(e<=0)return t;let i=t.content;return e>1&&(i=i.replaceChild(0,W(i.firstChild,e-1,1==i.childCount?n-1:0))),e>0&&(i=t.type.contentMatch.fillBefore(i).append(i),n<=0&&(i=i.append(t.type.contentMatch.matchFragment(i).fillBefore(r.empty,!0)))),t.copy(i)}function j(t,e,r,n,i){let s=t.node(e),o=i?t.indexAfter(e):t.index(e);if(o==s.childCount&&!r.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!function(t,e,r){for(let n=r;n<e.childCount;n++)if(!t.allowsMarks(e.child(n).marks))return!0;return!1}(r,s.content,o)?l:null}function L(t,e,n,i,s){if(e<n){let r=t.firstChild;t=t.replaceChild(0,r.copy(L(r.content,e+1,n,i,r)))}if(e>i){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(r.empty,!0))}return t}function q(t,e){let r=[];for(let n=Math.min(t.depth,e.depth);n>=0;n--){let i=t.start(n);if(i<t.pos-(t.depth-n)||e.end(n)>e.pos+(e.depth-n)||t.node(n).type.spec.isolating||e.node(n).type.spec.isolating)break;(i==e.start(n)||n==t.depth&&n==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&n&&e.start(n-1)==i-1)&&r.push(n)}return r}class G extends c{constructor(t,e,r){super(),this.pos=t,this.attr=e,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return f.fail("No node at attribute step's position");let i=Object.create(null);for(let t in n.attrs)i[t]=n.attrs[t];i[this.attr]=this.value;let s=n.type.create(i,null,n.marks);return f.fromReplace(e,this.pos,this.pos+1,new t(r.from(s),0,n.isLeaf?0:1))}getMap(){return a.empty}invert(t){return new G(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new G(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new G(e.pos,e.attr,e.value)}}c.jsonID("attr",G);class H extends c{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let r in t.attrs)e[r]=t.attrs[r];e[this.attr]=this.value;let r=t.type.create(e,t.content,t.marks);return f.ok(r)}getMap(){return a.empty}invert(t){return new H(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new H(e.attr,e.value)}}c.jsonID("docAttr",H);let K=class extends Error{};K=function t(e){let r=Error.call(this,e);return r.__proto__=t.prototype,r},(K.prototype=Object.create(Error.prototype)).constructor=K,K.prototype.name="TransformError";class P{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new p}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new K(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(e,r=e,n=t.empty){let i=z(this.doc,e,r,n);return i&&this.step(i),this}replaceWith(e,n,i){return this.replace(e,n,new t(r.from(i),0,0))}delete(e,r){return this.replace(e,r,t.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(e,r,n){return function(e,r,n,i){if(!i.size)return e.deleteRange(r,n);let s=e.doc.resolve(r),o=e.doc.resolve(n);if(F(s,o,i))return e.step(new w(r,n,i));let l=q(s,e.doc.resolve(n));0==l[l.length-1]&&l.pop();let a=-(s.depth+1);l.unshift(a);for(let t=s.depth,e=s.pos-1;t>0;t--,e--){let r=s.node(t).type.spec;if(r.defining||r.definingAsContext||r.isolating)break;l.indexOf(t)>-1?a=t:s.before(t)==e&&l.splice(1,0,-t)}let p=l.indexOf(a),h=[],c=i.openStart;for(let t=i.content,e=0;;e++){let r=t.firstChild;if(h.push(r),e==i.openStart)break;t=r.content}for(let t=c-1;t>=0;t--){let e=h[t],r=(f=e.type).spec.defining||f.spec.definingForContent;if(r&&!e.sameMarkup(s.node(Math.abs(a)-1)))c=t;else if(r||!e.type.isTextblock)break}var f;for(let r=i.openStart;r>=0;r--){let a=(r+c+1)%(i.openStart+1),f=h[a];if(f)for(let r=0;r<l.length;r++){let h=l[(r+p)%l.length],c=!0;h<0&&(c=!1,h=-h);let d=s.node(h-1),u=s.index(h-1);if(d.canReplaceWith(u,u,f.type,f.marks))return e.replace(s.before(h),c?o.after(h):n,new t(L(i.content,0,i.openStart,a),a,i.openEnd))}}let d=e.steps.length;for(let t=l.length-1;t>=0&&(e.replace(r,n,i),!(e.steps.length>d));t--){let e=l[t];e<0||(r=s.before(e),n=o.after(e))}}(this,e,r,n),this}replaceRangeWith(e,n,i){return function(e,n,i,s){if(!s.isInline&&n==i&&e.doc.resolve(n).parent.content.size){let t=E(e.doc,n,s.type);null!=t&&(n=i=t)}e.replaceRange(n,i,new t(r.from(s),0,0))}(this,e,n,i),this}deleteRange(t,e){return function(t,e,r){let n=t.doc.resolve(e),i=t.doc.resolve(r),s=q(n,i);for(let e=0;e<s.length;e++){let r=s[e],o=e==s.length-1;if(o&&0==r||n.node(r).type.contentMatch.validEnd)return t.delete(n.start(r),i.end(r));if(r>0&&(o||n.node(r-1).canReplace(n.index(r-1),i.indexAfter(r-1))))return t.delete(n.before(r),i.after(r))}for(let s=1;s<=n.depth&&s<=i.depth;s++)if(e-n.start(s)==n.depth-s&&r>n.end(s)&&i.end(s)-r!=i.depth-s&&n.start(s-1)==i.start(s-1)&&n.node(s-1).canReplace(n.index(s-1),i.index(s-1)))return t.delete(n.before(s),r);t.delete(e,r)}(this,t,e),this}lift(e,n){return function(e,n,i){let{$from:s,$to:o,depth:l}=n,a=s.before(l+1),p=o.after(l+1),h=a,c=p,f=r.empty,d=0;for(let t=l,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,f=r.from(s.node(t).copy(f)),d++):h--;let u=r.empty,m=0;for(let t=l,e=!1;t>i;t--)e||o.after(t+1)<o.end(t)?(e=!0,u=r.from(o.node(t).copy(u)),m++):c++;e.step(new k(h,c,a,p,new t(f.append(u),d,m),f.size-d,!0))}(this,e,n),this}join(e,r=1){return function(e,r,n){let i=null,{linebreakReplacement:s}=e.doc.type.schema,o=e.doc.resolve(r-n),l=o.node().type;if(s&&l.inlineContent){let t="pre"==l.whitespace,e=!!l.contentMatch.matchType(s);t&&!e?i=!1:!t&&e&&(i=!0)}let a=e.steps.length;if(!1===i){let t=e.doc.resolve(r+n);N(e,t.node(),t.before(),a)}l.inlineContent&&S(e,r+n-1,l,o.node().contentMatchAt(o.index()),null==i);let p=e.mapping.slice(a),h=p.map(r-n);if(e.step(new w(h,p.map(r+n,-1),t.empty,!0)),!0===i){let t=e.doc.resolve(h);b(e,t.node(),t.before(),e.steps.length)}}(this,e,r),this}wrap(e,n){return function(e,n,i){let s=r.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=r.from(i[t].type.create(i[t].attrs,s))}let o=n.start,l=n.end;e.step(new k(o,l,o,l,new t(s,0,0),i.length,!0))}(this,e,n),this}setBlockType(e,n=e,i,s=null){return function(e,n,i,s,o){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let l=e.steps.length;e.doc.nodesBetween(n,i,((n,i)=>{let a="function"==typeof o?o(n):o;if(n.isTextblock&&!n.hasMarkup(s,a)&&function(t,e,r){let n=t.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,r)}(e.doc,e.mapping.slice(l).map(i),s)){let o=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?o=!1:!t&&e&&(o=!0)}!1===o&&N(e,n,i,l),S(e,e.mapping.slice(l).map(i,1),s,void 0,null===o);let p=e.mapping.slice(l),h=p.map(i,1),c=p.map(i+n.nodeSize,1);return e.step(new k(h,c,h+1,c-1,new t(r.from(s.create(a,null,n.marks)),0,0),1,!0)),!0===o&&b(e,n,i,l),!1}}))}(this,e,n,i,s),this}setNodeMarkup(e,n,i=null,s){return function(e,n,i,s,o){let l=e.doc.nodeAt(n);if(!l)throw new RangeError("No node at given position");i||(i=l.type);let a=i.create(s,null,o||l.marks);if(l.isLeaf)return e.replaceWith(n,n+l.nodeSize,a);if(!i.validContent(l.content))throw new RangeError("Invalid content for node type "+i.name);e.step(new k(n,n+l.nodeSize,n+1,n+l.nodeSize-1,new t(r.from(a),0,0),1,!0))}(this,e,n,i,s),this}setNodeAttribute(t,e,r){return this.step(new G(t,e,r)),this}setDocAttribute(t,e){return this.step(new H(t,e)),this}addNodeMark(t,e){return this.step(new y(t,e)),this}removeNodeMark(t,e){let r=this.doc.nodeAt(t);if(!r)throw new RangeError("No node at position "+t);if(e instanceof n)e.isInSet(r.marks)&&this.step(new g(t,e));else{let n,i=r.marks,s=[];for(;n=e.isInSet(i);)s.push(new g(t,n)),i=n.removeFromSet(i);for(let t=s.length-1;t>=0;t--)this.step(s[t])}return this}split(e,n=1,i){return function(e,n,i=1,s){let o=e.doc.resolve(n),l=r.empty,a=r.empty;for(let t=o.depth,e=o.depth-i,n=i-1;t>e;t--,n--){l=r.from(o.node(t).copy(l));let e=s&&s[n];a=r.from(e?e.type.create(e.attrs,a):o.node(t).copy(a))}e.step(new w(n,n,new t(l.append(a),i,i),!0))}(this,e,n,i),this}addMark(t,e,r){return function(t,e,r,n){let i,s,o=[],l=[];t.doc.nodesBetween(e,r,((t,a,p)=>{if(!t.isInline)return;let h=t.marks;if(!n.isInSet(h)&&p.type.allowsMarkType(n.type)){let p=Math.max(a,e),c=Math.min(a+t.nodeSize,r),f=n.addToSet(h);for(let t=0;t<h.length;t++)h[t].isInSet(f)||(i&&i.to==p&&i.mark.eq(h[t])?i.to=c:o.push(i=new m(p,c,h[t])));s&&s.to==p?s.to=c:l.push(s=new u(p,c,n))}})),o.forEach((e=>t.step(e))),l.forEach((e=>t.step(e)))}(this,t,e,r),this}removeMark(t,e,r){return function(t,e,r,n){let s=[],o=0;t.doc.nodesBetween(e,r,((t,l)=>{if(!t.isInline)return;o++;let a=null;if(n instanceof i){let e,r=t.marks;for(;e=n.isInSet(r);)(a||(a=[])).push(e),r=e.removeFromSet(r)}else n?n.isInSet(t.marks)&&(a=[n]):a=t.marks;if(a&&a.length){let n=Math.min(l+t.nodeSize,r);for(let t=0;t<a.length;t++){let r,i=a[t];for(let t=0;t<s.length;t++){let e=s[t];e.step==o-1&&i.eq(s[t].style)&&(r=e)}r?(r.to=n,r.step=o):s.push({style:i,from:Math.max(l,e),to:n,step:o})}}})),s.forEach((e=>t.step(new m(e.from,e.to,e.style))))}(this,t,e,r),this}clearIncompatible(t,e,r){return S(this,t,e,r),this}}export{u as AddMarkStep,y as AddNodeMarkStep,G as AttrStep,H as DocAttrStep,l as MapResult,p as Mapping,m as RemoveMarkStep,g as RemoveNodeMarkStep,k as ReplaceAroundStep,w as ReplaceStep,c as Step,a as StepMap,f as StepResult,P as Transform,K as TransformError,T as canJoin,I as canSplit,J as dropPoint,R as findWrapping,E as insertPoint,O as joinPoint,x as liftTarget,z as replaceStep};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|