Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@blocknote/server-util

Package Overview
Dependencies
Maintainers
3
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocknote/server-util - npm Package Compare versions

Comparing version
0.41.1
to
0.42.0
+6
-1
dist/blocknote-server-util.cjs

@@ -1,2 +0,7 @@

"use strict";var d=Object.defineProperty;var m=(e,o,r)=>o in e?d(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r;var n=(e,o,r)=>m(e,typeof o!="symbol"?o+"":o,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@blocknote/core"),u=require("@blocknote/react"),h=require("jsdom"),a=require("react"),T=require("react-dom"),p=require("react-dom/client"),c=require("y-prosemirror");function w(e){if(e&&typeof e=="object"&&"default"in e)return e;const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(o,r,t.get?t:{enumerable:!0,get:()=>e[r]})}}return o.default=e,Object.freeze(o)}const y=w(h);class i{constructor(o){n(this,"editor");n(this,"jsdom",new y.JSDOM);this.editor=s.BlockNoteEditor.create(o)}async _withJSDOM(o){const r=globalThis.window,t=globalThis.document;globalThis.document=this.jsdom.window.document,globalThis.window=this.jsdom.window,globalThis.window.__TEST_OPTIONS=r==null?void 0:r.__TEST_OPTIONS;try{return await o()}finally{globalThis.document=t,globalThis.window=r}}static create(o={}){return new i(o)}_prosemirrorNodeToBlocks(o){const r=[];return o.firstChild.descendants(t=>(r.push(s.nodeToBlock(t,this.editor.pmSchema)),!1)),r}_prosemirrorJSONToBlocks(o){const r=this.editor.pmSchema.nodeFromJSON(o);return this._prosemirrorNodeToBlocks(r)}_blocksToProsemirrorNode(o){const r=this.editor.pmSchema,t=o.map(l=>s.blockToNode(l,r));return r.topNodeType.create(null,r.nodes.blockGroup.create(null,t))}yXmlFragmentToBlocks(o){const r=c.yXmlFragmentToProseMirrorRootNode(o,this.editor.pmSchema);return this._prosemirrorNodeToBlocks(r)}blocksToYXmlFragment(o,r){return c.prosemirrorToYXmlFragment(this._blocksToProsemirrorNode(o),r)}yDocToBlocks(o,r="prosemirror"){return this.yXmlFragmentToBlocks(o.getXmlFragment(r))}blocksToYDoc(o,r="prosemirror"){return c.prosemirrorToYDoc(this._blocksToProsemirrorNode(o),r)}async blocksToHTMLLossy(o){return this._withJSDOM(async()=>s.createExternalHTMLExporter(this.editor.pmSchema,this.editor).exportBlocks(o,{document:this.jsdom.window.document}))}async blocksToFullHTML(o){return this._withJSDOM(async()=>s.createInternalHTMLSerializer(this.editor.pmSchema,this.editor).serializeBlocks(o,{document:this.jsdom.window.document}))}async tryParseHTMLToBlocks(o){return this._withJSDOM(async()=>this.editor.tryParseHTMLToBlocks(o))}async blocksToMarkdownLossy(o){return this._withJSDOM(async()=>s.blocksToMarkdown(o,this.editor.pmSchema,this.editor,{document:this.jsdom.window.document}))}async tryParseMarkdownToBlocks(o){return this._withJSDOM(async()=>this.editor.tryParseMarkdownToBlocks(o))}async withReactContext(o,r){return this._withJSDOM(async()=>{const t=p.createRoot(this.jsdom.window.document.createElement("div"));T.flushSync(()=>{t.render(a.createElement(o,{},a.createElement(u.BlockNoteViewRaw,{editor:this.editor})))});try{return await r()}finally{t.unmount()}})}}exports.ServerBlockNoteEditor=i;
"use strict";var Yt=Object.defineProperty;var Qt=(r,t,e)=>t in r?Yt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var tt=(r,t,e)=>Qt(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@blocknote/core"),at=require("y-prosemirror"),V=require("@tiptap/core"),Zt=require("@blocknote/react"),jt=require("jsdom"),kt=require("react"),_t=require("react-dom"),te=require("react-dom/client");function ee(r){if(r&&typeof r=="object"&&"default"in r)return r;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const ne=ee(jt);function Ct(r,t,e){for(let n=0;;n++){if(n==r.childCount||n==t.childCount)return r.childCount==t.childCount?null:e;let o=r.child(n),i=t.child(n);if(o==i){e+=o.nodeSize;continue}if(!o.sameMarkup(i))return e;if(o.isText&&o.text!=i.text){for(let l=0;o.text[l]==i.text[l];l++)e++;return e}if(o.content.size||i.content.size){let l=Ct(o.content,i.content,e+1);if(l!=null)return l}e+=o.nodeSize}}function It(r,t,e,n){for(let o=r.childCount,i=t.childCount;;){if(o==0||i==0)return o==i?null:{a:e,b:n};let l=r.child(--o),s=t.child(--i),a=l.nodeSize;if(l==s){e-=a,n-=a;continue}if(!l.sameMarkup(s))return{a:e,b:n};if(l.isText&&l.text!=s.text){let c=0,u=Math.min(l.text.length,s.text.length);for(;c<u&&l.text[l.text.length-c-1]==s.text[s.text.length-c-1];)c++,e--,n--;return{a:e,b:n}}if(l.content.size||s.content.size){let c=It(l.content,s.content,e-1,n-1);if(c)return c}e-=a,n-=a}}class m{constructor(t,e){if(this.content=t,this.size=e||0,e==null)for(let n=0;n<t.length;n++)this.size+=t[n].nodeSize}nodesBetween(t,e,n,o=0,i){for(let l=0,s=0;s<e;l++){let a=this.content[l],c=s+a.nodeSize;if(c>t&&n(a,o+s,i||null,l)!==!1&&a.content.size){let u=s+1;a.nodesBetween(Math.max(0,t-u),Math.min(a.content.size,e-u),n,o+u)}s=c}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,n,o){let i="",l=!0;return this.nodesBetween(t,e,(s,a)=>{let c=s.isText?s.text.slice(Math.max(t,a)-a,e-a):s.isLeaf?o?typeof o=="function"?o(s):o:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&c||s.isTextblock)&&n&&(l?l=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,n=t.firstChild,o=this.content.slice(),i=0;for(e.isText&&e.sameMarkup(n)&&(o[o.length-1]=e.withText(e.text+n.text),i=1);i<t.content.length;i++)o.push(t.content[i]);return new m(o,this.size+t.size)}cut(t,e=this.size){if(t==0&&e==this.size)return this;let n=[],o=0;if(e>t)for(let i=0,l=0;l<e;i++){let s=this.content[i],a=l+s.nodeSize;a>t&&((l<t||a>e)&&(s.isText?s=s.cut(Math.max(0,t-l),Math.min(s.text.length,e-l)):s=s.cut(Math.max(0,t-l-1),Math.min(s.content.size,e-l-1))),n.push(s),o+=s.nodeSize),l=a}return new m(n,o)}cutByIndex(t,e){return t==e?m.empty:t==0&&e==this.content.length?this:new m(this.content.slice(t,e))}replaceChild(t,e){let n=this.content[t];if(n==e)return this;let o=this.content.slice(),i=this.size+e.nodeSize-n.nodeSize;return o[t]=e,new m(o,i)}addToStart(t){return new m([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new m(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,n=0;e<this.content.length;e++){let o=this.content[e];t(o,n,e),n+=o.nodeSize}}findDiffStart(t,e=0){return Ct(this,t,e)}findDiffEnd(t,e=this.size,n=t.size){return It(this,t,e,n)}findIndex(t){if(t==0)return U(0,t);if(t==this.size)return U(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let e=0,n=0;;e++){let o=this.child(e),i=n+o.nodeSize;if(i>=t)return i==t?U(e+1,i):U(e,n);n=i}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,e){if(!e)return m.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new m(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return m.empty;let e,n=0;for(let o=0;o<t.length;o++){let i=t[o];n+=i.nodeSize,o&&i.isText&&t[o-1].sameMarkup(i)?(e||(e=t.slice(0,o)),e[e.length-1]=i.withText(e[e.length-1].text+i.text)):e&&e.push(i)}return new m(e||t,n)}static from(t){if(!t)return m.empty;if(t instanceof m)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new m([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}m.empty=new m([],0);const et={index:0,offset:0};function U(r,t){return et.index=r,et.offset=t,et}class re extends Error{}class d{constructor(t,e,n){this.content=t,this.openStart=e,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let n=zt(this.content,t+this.openStart,e);return n&&new d(n,this.openStart,this.openEnd)}removeBetween(t,e){return new d(Jt(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,e){if(!e)return d.empty;let n=e.openStart||0,o=e.openEnd||0;if(typeof n!="number"||typeof o!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new d(m.fromJSON(t,e.content),n,o)}static maxOpen(t,e=!0){let n=0,o=0;for(let i=t.firstChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.firstChild)n++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)o++;return new d(t,n,o)}}d.empty=new d(m.empty,0,0);function Jt(r,t,e){let{index:n,offset:o}=r.findIndex(t),i=r.maybeChild(n),{index:l,offset:s}=r.findIndex(e);if(o==t||i.isText){if(s!=e&&!r.child(l).isText)throw new RangeError("Removing non-flat range");return r.cut(0,t).append(r.cut(e))}if(n!=l)throw new RangeError("Removing non-flat range");return r.replaceChild(n,i.copy(Jt(i.content,t-o-1,e-o-1)))}function zt(r,t,e,n){let{index:o,offset:i}=r.findIndex(t),l=r.maybeChild(o);if(i==t||l.isText)return n&&!n.canReplace(o,o,e)?null:r.cut(0,t).append(e).append(r.cut(t));let s=zt(l.content,t-i-1,e,l);return s&&r.replaceChild(o,l.copy(s))}const Rt=65535,Dt=Math.pow(2,16);function oe(r,t){return r+t*Dt}function St(r){return r&Rt}function ie(r){return(r-(r&Rt))/Dt}const Mt=1,Bt=2,W=4,At=8;class bt{constructor(t,e,n){this.pos=t,this.delInfo=e,this.recover=n}get deleted(){return(this.delInfo&At)>0}get deletedBefore(){return(this.delInfo&(Mt|W))>0}get deletedAfter(){return(this.delInfo&(Bt|W))>0}get deletedAcross(){return(this.delInfo&W)>0}}class E{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&E.empty)return E.empty}recover(t){let e=0,n=St(t);if(!this.inverted)for(let o=0;o<n;o++)e+=this.ranges[o*3+2]-this.ranges[o*3+1];return this.ranges[n*3]+e+ie(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,n){let o=0,i=this.inverted?2:1,l=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let a=this.ranges[s]-(this.inverted?o:0);if(a>t)break;let c=this.ranges[s+i],u=this.ranges[s+l],f=a+c;if(t<=f){let p=c?t==a?-1:t==f?1:e:e,h=a+o+(p<0?0:u);if(n)return h;let w=t==(e<0?a:f)?null:oe(s/3,t-a),b=t==a?Bt:t==f?Mt:W;return(e<0?t!=a:t!=f)&&(b|=At),new bt(h,b,w)}o+=u-c}return n?t+o:new bt(t+o,0,null)}touches(t,e){let n=0,o=St(e),i=this.inverted?2:1,l=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let a=this.ranges[s]-(this.inverted?n:0);if(a>t)break;let c=this.ranges[s+i],u=a+c;if(t<=u&&s==o*3)return!0;n+=this.ranges[s+l]-c}return!1}forEach(t){let e=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,i=0;o<this.ranges.length;o+=3){let l=this.ranges[o],s=l-(this.inverted?i:0),a=l+(this.inverted?0:i),c=this.ranges[o+e],u=this.ranges[o+n];t(s,s+c,a,a+u),i+=u-c}}invert(){return new E(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?E.empty:new E(t<0?[0,-t,0]:[0,0,t])}}E.empty=new E([]);const nt=Object.create(null);class v{getMap(){return E.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=nt[e.stepType];if(!n)throw new RangeError(`No step type ${e.stepType} defined`);return n.fromJSON(t,e)}static jsonID(t,e){if(t in nt)throw new RangeError("Duplicate use of step JSON ID "+t);return nt[t]=e,e.prototype.jsonID=t,e}}class y{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new y(t,null)}static fail(t){return new y(null,t)}static fromReplace(t,e,n,o){try{return y.ok(t.replace(e,n,o))}catch(i){if(i instanceof re)return y.fail(i.message);throw i}}}function ct(r,t,e){let n=[];for(let o=0;o<r.childCount;o++){let i=r.child(o);i.content.size&&(i=i.copy(ct(i.content,t,i))),i.isInline&&(i=t(i,e,o)),n.push(i)}return m.fromArray(n)}class J extends v{constructor(t,e,n){super(),this.from=t,this.to=e,this.mark=n}apply(t){let e=t.slice(this.from,this.to),n=t.resolve(this.from),o=n.node(n.sharedDepth(this.to)),i=new d(ct(e.content,(l,s)=>!l.isAtom||!s.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),o),e.openStart,e.openEnd);return y.fromReplace(t,this.from,this.to,i)}invert(){return new z(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deleted&&n.deleted||e.pos>=n.pos?null:new J(e.pos,n.pos,this.mark)}merge(t){return t instanceof J&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new J(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(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new J(e.from,e.to,t.markFromJSON(e.mark))}}v.jsonID("addMark",J);class z extends v{constructor(t,e,n){super(),this.from=t,this.to=e,this.mark=n}apply(t){let e=t.slice(this.from,this.to),n=new d(ct(e.content,o=>o.mark(this.mark.removeFromSet(o.marks)),t),e.openStart,e.openEnd);return y.fromReplace(t,this.from,this.to,n)}invert(){return new J(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deleted&&n.deleted||e.pos>=n.pos?null:new z(e.pos,n.pos,this.mark)}merge(t){return t instanceof z&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new z(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(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new z(e.from,e.to,t.markFromJSON(e.mark))}}v.jsonID("removeMark",z);class R extends v{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return y.fail("No node at mark step's position");let n=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return y.fromReplace(t,this.pos,this.pos+1,new d(m.from(n),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let n=this.mark.addToSet(e.marks);if(n.length==e.marks.length){for(let o=0;o<e.marks.length;o++)if(!e.marks[o].isInSet(n))return new R(this.pos,e.marks[o]);return new R(this.pos,this.mark)}}return new F(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new R(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if(typeof e.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new R(e.pos,t.markFromJSON(e.mark))}}v.jsonID("addNodeMark",R);class F extends v{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return y.fail("No node at mark step's position");let n=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return y.fromReplace(t,this.pos,this.pos+1,new d(m.from(n),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return!e||!this.mark.isInSet(e.marks)?this:new R(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new F(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if(typeof e.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new F(e.pos,t.markFromJSON(e.mark))}}v.jsonID("removeNodeMark",F);class C extends v{constructor(t,e,n,o=!1){super(),this.from=t,this.to=e,this.slice=n,this.structure=o}apply(t){return this.structure&&st(t,this.from,this.to)?y.fail("Structure replace would overwrite content"):y.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new E([this.from,this.to-this.from,this.slice.size])}invert(t){return new C(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deletedAcross&&n.deletedAcross?null:new C(e.pos,Math.max(e.pos,n.pos),this.slice,this.structure)}merge(t){if(!(t instanceof C)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let e=this.slice.size+t.slice.size==0?d.empty:new d(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new C(this.from,this.to+(t.to-t.from),e,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let e=this.slice.size+t.slice.size==0?d.empty:new d(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new C(t.from,this.to,e,this.structure)}else return null}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(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new C(e.from,e.to,d.fromJSON(t,e.slice),!!e.structure)}}v.jsonID("replace",C);class M extends v{constructor(t,e,n,o,i,l,s=!1){super(),this.from=t,this.to=e,this.gapFrom=n,this.gapTo=o,this.slice=i,this.insert=l,this.structure=s}apply(t){if(this.structure&&(st(t,this.from,this.gapFrom)||st(t,this.gapTo,this.to)))return y.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return y.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,e.content);return n?y.fromReplace(t,this.from,this.to,n):y.fail("Content does not fit in gap")}getMap(){return new E([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 M(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),n=t.mapResult(this.to,-1),o=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:t.map(this.gapTo,1);return e.deletedAcross&&n.deletedAcross||o<e.pos||i>n.pos?null:new M(e.pos,n.pos,o,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(t,e){if(typeof e.from!="number"||typeof e.to!="number"||typeof e.gapFrom!="number"||typeof e.gapTo!="number"||typeof e.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new M(e.from,e.to,e.gapFrom,e.gapTo,d.fromJSON(t,e.slice),e.insert,!!e.structure)}}v.jsonID("replaceAround",M);function st(r,t,e){let n=r.resolve(t),o=e-t,i=n.depth;for(;o>0&&i>0&&n.indexAfter(i)==n.node(i).childCount;)i--,o--;if(o>0){let l=n.node(i).maybeChild(n.indexAfter(i));for(;o>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,o--}}return!1}class P extends v{constructor(t,e,n){super(),this.pos=t,this.attr=e,this.value=n}apply(t){let e=t.nodeAt(this.pos);if(!e)return y.fail("No node at attribute step's position");let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let o=e.type.create(n,null,e.marks);return y.fromReplace(t,this.pos,this.pos+1,new d(m.from(o),0,e.isLeaf?0:1))}getMap(){return E.empty}invert(t){return new P(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 P(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if(typeof e.pos!="number"||typeof e.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new P(e.pos,e.attr,e.value)}}v.jsonID("attr",P);class Y extends v{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let o in t.attrs)e[o]=t.attrs[o];e[this.attr]=this.value;let n=t.type.create(e,t.content,t.marks);return y.ok(n)}getMap(){return E.empty}invert(t){return new Y(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(typeof e.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Y(e.attr,e.value)}}v.jsonID("docAttr",Y);let L=class extends Error{};L=function r(t){let e=Error.call(this,t);return e.__proto__=r.prototype,e};L.prototype=Object.create(Error.prototype);L.prototype.constructor=L;L.prototype.name="TransformError";const rt=Object.create(null);class g{constructor(t,e,n){this.$anchor=t,this.$head=e,this.ranges=n||[new se(t.min(e),t.max(e))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,e=d.empty){let n=e.content.lastChild,o=null;for(let s=0;s<e.openEnd;s++)o=n,n=n.lastChild;let i=t.steps.length,l=this.ranges;for(let s=0;s<l.length;s++){let{$from:a,$to:c}=l[s],u=t.mapping.slice(i);t.replaceRange(u.map(a.pos),u.map(c.pos),s?d.empty:e),s==0&&Et(t,i,(n?n.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(t,e){let n=t.steps.length,o=this.ranges;for(let i=0;i<o.length;i++){let{$from:l,$to:s}=o[i],a=t.mapping.slice(n),c=a.map(l.pos),u=a.map(s.pos);i?t.deleteRange(c,u):(t.replaceRangeWith(c,u,e),Et(t,n,e.isInline?-1:1))}}static findFrom(t,e,n=!1){let o=t.parent.inlineContent?new N(t):D(t.node(0),t.parent,t.pos,t.index(),e,n);if(o)return o;for(let i=t.depth-1;i>=0;i--){let l=e<0?D(t.node(0),t.node(i),t.before(i+1),t.index(i),e,n):D(t.node(0),t.node(i),t.after(i+1),t.index(i)+1,e,n);if(l)return l}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new I(t.node(0))}static atStart(t){return D(t,t,0,0,1)||new I(t)}static atEnd(t){return D(t,t,t.content.size,t.childCount,-1)||new I(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=rt[e.type];if(!n)throw new RangeError(`No selection type ${e.type} defined`);return n.fromJSON(t,e)}static jsonID(t,e){if(t in rt)throw new RangeError("Duplicate use of selection JSON ID "+t);return rt[t]=e,e.prototype.jsonID=t,e}getBookmark(){return N.between(this.$anchor,this.$head).getBookmark()}}g.prototype.visible=!0;class se{constructor(t,e){this.$from=t,this.$to=e}}let xt=!1;function vt(r){!xt&&!r.parent.inlineContent&&(xt=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class N extends g{constructor(t,e=t){vt(t),vt(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let n=t.resolve(e.map(this.head));if(!n.parent.inlineContent)return g.near(n);let o=t.resolve(e.map(this.anchor));return new N(o.parent.inlineContent?o:n,n)}replace(t,e=d.empty){if(super.replace(t,e),e==d.empty){let n=this.$from.marksAcross(this.$to);n&&t.ensureMarks(n)}}eq(t){return t instanceof N&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new j(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if(typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new N(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,n=e){let o=t.resolve(e);return new this(o,n==e?o:t.resolve(n))}static between(t,e,n){let o=t.pos-e.pos;if((!n||o)&&(n=o>=0?1:-1),!e.parent.inlineContent){let i=g.findFrom(e,n,!0)||g.findFrom(e,-n,!0);if(i)e=i.$head;else return g.near(e,n)}return t.parent.inlineContent||(o==0?t=e:(t=(g.findFrom(t,-n,!0)||g.findFrom(t,n,!0)).$anchor,t.pos<e.pos!=o<0&&(t=e))),new N(t,e)}}g.jsonID("text",N);class j{constructor(t,e){this.anchor=t,this.head=e}map(t){return new j(t.map(this.anchor),t.map(this.head))}resolve(t){return N.between(t.resolve(this.anchor),t.resolve(this.head))}}class O extends g{constructor(t){let e=t.nodeAfter,n=t.node(0).resolve(t.pos+e.nodeSize);super(t,n),this.node=e}map(t,e){let{deleted:n,pos:o}=e.mapResult(this.anchor),i=t.resolve(o);return n?g.near(i):new O(i)}content(){return new d(m.from(this.node),0,0)}eq(t){return t instanceof O&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ut(this.anchor)}static fromJSON(t,e){if(typeof e.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new O(t.resolve(e.anchor))}static create(t,e){return new O(t.resolve(e))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}O.prototype.visible=!1;g.jsonID("node",O);class ut{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:n}=t.mapResult(this.anchor);return e?new j(n,n):new ut(n)}resolve(t){let e=t.resolve(this.anchor),n=e.nodeAfter;return n&&O.isSelectable(n)?new O(e):g.near(e)}}class I extends g{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=d.empty){if(e==d.empty){t.delete(0,t.doc.content.size);let n=g.atStart(t.doc);n.eq(t.selection)||t.setSelection(n)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new I(t)}map(t){return new I(t)}eq(t){return t instanceof I}getBookmark(){return le}}g.jsonID("all",I);const le={map(){return this},resolve(r){return new I(r)}};function D(r,t,e,n,o,i=!1){if(t.inlineContent)return N.create(r,e);for(let l=n-(o>0?0:1);o>0?l<t.childCount:l>=0;l+=o){let s=t.child(l);if(s.isAtom){if(!i&&O.isSelectable(s))return O.create(r,e-(o<0?s.nodeSize:0))}else{let a=D(r,s,e+o,o<0?s.childCount:0,o,i);if(a)return a}e+=s.nodeSize*o}return null}function Et(r,t,e){let n=r.steps.length-1;if(n<t)return;let o=r.steps[n];if(!(o instanceof C||o instanceof M))return;let i=r.mapping.maps[n],l;i.forEach((s,a,c,u)=>{l==null&&(l=u)}),r.setSelection(g.near(r.doc.resolve(l),e))}function Tt(r,t){return!t||!r?r:r.bind(t)}class X{constructor(t,e,n){this.name=t,this.init=Tt(e.init,n),this.apply=Tt(e.apply,n)}}new X("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new X("selection",{init(r,t){return r.selection||g.atStart(t.doc)},apply(r){return r.selection}}),new X("storedMarks",{init(r){return r.storedMarks||null},apply(r,t,e,n){return n.selection.$cursor?r.storedMarks:null}}),new X("scrollToSelection",{init(){return 0},apply(r,t){return r.scrolledIntoView?t+1:t}});function Pt(r,t,e){for(let n in r){let o=r[n];o instanceof Function?o=o.bind(t):n=="handleDOMEvents"&&(o=Pt(o,t,{})),e[n]=o}return e}class ae{constructor(t){this.spec=t,this.props={},t.props&&Pt(t.props,this,this.props),this.key=t.key?t.key.key:Ft("plugin")}getState(t){return t[this.key]}}const ot=Object.create(null);function Ft(r){return r in ot?r+"$"+ ++ot[r]:(ot[r]=0,r+"$")}class ce{constructor(t="key"){this.key=Ft(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}var K,ue=new Uint8Array(16);function he(){if(!K&&(K=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!K))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return K(ue)}const fe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function pe(r){return typeof r=="string"&&fe.test(r)}var S=[];for(var it=0;it<256;++it)S.push((it+256).toString(16).substr(1));function de(r){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(S[r[t+0]]+S[r[t+1]]+S[r[t+2]]+S[r[t+3]]+"-"+S[r[t+4]]+S[r[t+5]]+"-"+S[r[t+6]]+S[r[t+7]]+"-"+S[r[t+8]]+S[r[t+9]]+"-"+S[r[t+10]]+S[r[t+11]]+S[r[t+12]]+S[r[t+13]]+S[r[t+14]]+S[r[t+15]]).toLowerCase();if(!pe(e))throw TypeError("Stringified UUID is invalid");return e}function me(r,t,e){r=r||{};var n=r.random||(r.rng||he)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,de(n)}function ye(r,t=JSON.stringify){const e={};return r.filter(n=>{const o=t(n);return Object.prototype.hasOwnProperty.call(e,o)?!1:e[o]=!0})}function we(r){const t=r.filter((e,n)=>r.indexOf(e)!==n);return ye(t)}const Lt=V.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const r=window.__TEST_OPTIONS;return r.mockID===void 0?r.mockID=0:r.mockID++,r.mockID.toString()}return me()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:r=>r.getAttribute(`data-${this.options.attributeName}`),renderHTML:r=>{const t={[`data-${this.options.attributeName}`]:r[this.options.attributeName]};return this.options.setIdAttribute?{...t,id:r[this.options.attributeName]}:t}}}}]},addProseMirrorPlugins(){let r=null,t=!1;return[new ae({key:new ce("uniqueID"),appendTransaction:(e,n,o)=>{const i=e.some(h=>h.docChanged)&&!n.doc.eq(o.doc),l=this.options.filterTransaction&&e.some(h=>{var w,b;return!((b=(w=this.options).filterTransaction)!=null&&b.call(w,h))});if(!i||l)return;const{tr:s}=o,{types:a,attributeName:c,generateID:u}=this.options,f=V.combineTransactionSteps(n.doc,e),{mapping:p}=f;if(V.getChangedRanges(f).forEach(({newRange:h})=>{const w=V.findChildrenInRange(o.doc,h,x=>a.includes(x.type.name)),b=w.map(({node:x})=>x.attrs[c]).filter(x=>x!==null),k=we(b);w.forEach(({node:x,pos:T})=>{var G;const B=(G=s.doc.nodeAt(T))==null?void 0:G.attrs[c];if(B===null){const H=n.doc.type.createAndFill().content;if(n.doc.content.findDiffStart(H)===null){const gt=JSON.parse(JSON.stringify(o.doc.toJSON()));if(gt.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(gt.content)===JSON.stringify(H.toJSON())){s.setNodeMarkup(T,void 0,{...x.attrs,[c]:"initialBlockId"});return}}s.setNodeMarkup(T,void 0,{...x.attrs,[c]:u()});return}const{deleted:wt}=p.invert().mapResult(T);wt&&k.includes(B)&&s.setNodeMarkup(T,void 0,{...x.attrs,[c]:u()})})}),!!s.steps.length)return s.setMeta("uniqueID",!0),s},view(e){const n=o=>{let i;r=!((i=e.dom.parentElement)===null||i===void 0)&&i.contains(o.target)?e.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(e,n)=>{let o;return r!==e.dom.parentElement||((o=n.dataTransfer)===null||o===void 0?void 0:o.effectAllowed)==="copy"?t=!0:t=!1,r=null,!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:n,attributeName:o}=this.options,i=l=>{const s=[];return l.forEach(a=>{if(a.isText){s.push(a);return}if(!n.includes(a.type.name)){s.push(a.copy(i(a.content)));return}const c=a.type.create({...a.attrs,[o]:null},i(a.content),a.marks);s.push(c)}),m.from(s)};return t=!1,new d(i(e.content),e.openStart,e.openEnd)}}})]}});function Ot(r){return r.type==="link"}function ge(r){return typeof r!="string"&&r.type==="link"}function q(r){return typeof r!="string"&&r.type==="text"}function ke(r){var t,e,n,o,i;return ht(r)?{...r}:Q(r)?{type:"tableCell",content:[].concat(r.content),props:{backgroundColor:((t=r.props)==null?void 0:t.backgroundColor)??"default",textColor:((e=r.props)==null?void 0:e.textColor)??"default",textAlignment:((n=r.props)==null?void 0:n.textAlignment)??"left",colspan:((o=r.props)==null?void 0:o.colspan)??1,rowspan:((i=r.props)==null?void 0:i.rowspan)??1}}:{type:"tableCell",content:[].concat(r),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function Q(r){return r!=null&&typeof r!="string"&&!Array.isArray(r)&&r.type==="tableCell"}function ht(r){return Q(r)&&r.props!==void 0&&r.content!==void 0}function ft(r){return ht(r)?r.props.colspan??1:1}function Se(r){return ht(r)?r.props.rowspan??1:1}class _ extends Error{constructor(t){super(`Unreachable case: ${t}`)}}function be(r,t){if(!r.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${r.type.name}`);const e=r,n=t,o=n+e.nodeSize,i={node:e,beforePos:n,afterPos:o};if(e.type.name==="blockContainer"){let l,s;if(e.forEach((a,c)=>{if(a.type.spec.group==="blockContent"){const u=a,f=n+c+1,p=f+a.nodeSize;l={node:u,beforePos:f,afterPos:p}}else if(a.type.name==="blockGroup"){const u=a,f=n+c+1,p=f+a.nodeSize;s={node:u,beforePos:f,afterPos:p}}}),!l)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${e}`);return{isBlockContainer:!0,bnBlock:i,blockContent:l,childContainer:s,blockNoteType:l.node.type.name}}else{if(!i.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${i.node}`);return{isBlockContainer:!1,bnBlock:i,childContainer:i,blockNoteType:i.node.type.name}}}function xe(r){return"doc"in r?r.doc.type.schema:r.type.schema}function qt(r){return r.cached.blockNoteEditor}function pt(r){return qt(r).schema}function $t(r){return pt(r).blockSchema}function Gt(r){return pt(r).inlineContentSchema}function $(r){return pt(r).styleSchema}function Ht(r){return qt(r).blockCache}function ve(r,t,e){var n,o;const i={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},l=[];r.content.forEach((s,a,c)=>{const u={cells:[]};c===0&&s.content.forEach(f=>{let p=f.attrs.colwidth;p==null&&(p=new Array(f.attrs.colspan??1).fill(void 0)),i.columnWidths.push(...p)}),u.cells=s.content.content.map((f,p)=>(l[c]||(l[c]=[]),l[c][p]=f.type.name==="tableHeader",{type:"tableCell",content:f.content.content.map(h=>dt(h,t,e)).reduce((h,w)=>{if(!h.length)return w;const b=h[h.length-1],k=w[0];return k&&q(b)&&q(k)&&JSON.stringify(b.styles)===JSON.stringify(k.styles)?(b.text+=`
`+k.text,h.push(...w.slice(1)),h):(h.push(...w),h)},[]),props:{colspan:f.attrs.colspan,rowspan:f.attrs.rowspan,backgroundColor:f.attrs.backgroundColor,textColor:f.attrs.textColor,textAlignment:f.attrs.textAlignment}})),i.rows.push(u)});for(let s=0;s<l.length;s++)(n=l[s])!=null&&n.every(a=>a)&&(i.headerRows=(i.headerRows??0)+1);for(let s=0;s<((o=l[0])==null?void 0:o.length);s++)l!=null&&l.every(a=>a[s])&&(i.headerCols=(i.headerCols??0)+1);return i}function dt(r,t,e){const n=[];let o;return r.content.forEach(i=>{if(i.type.name==="hardBreak"){if(o)if(q(o))o.text+=`
`;else if(Ot(o))o.content[o.content.length-1].text+=`
`;else throw new Error("unexpected");else o={type:"text",text:`
`,styles:{}};return}if(i.type.name!=="link"&&i.type.name!=="text"){if(!t[i.type.name]){console.warn("unrecognized inline content type",i.type.name);return}o&&(n.push(o),o=void 0),n.push(Ee(i,t,e));return}const l={};let s;for(const a of i.marks)if(a.type.name==="link")s=a;else{const c=e[a.type.name];if(!c){if(a.type.spec.blocknoteIgnore)continue;throw new Error(`style ${a.type.name} not found in styleSchema`)}if(c.propSchema==="boolean")l[c.type]=!0;else if(c.propSchema==="string")l[c.type]=a.attrs.stringValue;else throw new _(c.propSchema)}o?q(o)?s?(n.push(o),o={type:"link",href:s.attrs.href,content:[{type:"text",text:i.textContent,styles:l}]}):JSON.stringify(o.styles)===JSON.stringify(l)?o.text+=i.textContent:(n.push(o),o={type:"text",text:i.textContent,styles:l}):Ot(o)&&(s?o.href===s.attrs.href?JSON.stringify(o.content[o.content.length-1].styles)===JSON.stringify(l)?o.content[o.content.length-1].text+=i.textContent:o.content.push({type:"text",text:i.textContent,styles:l}):(n.push(o),o={type:"link",href:s.attrs.href,content:[{type:"text",text:i.textContent,styles:l}]}):(n.push(o),o={type:"text",text:i.textContent,styles:l})):s?o={type:"link",href:s.attrs.href,content:[{type:"text",text:i.textContent,styles:l}]}:o={type:"text",text:i.textContent,styles:l}}),o&&n.push(o),n}function Ee(r,t,e){if(r.type.name==="text"||r.type.name==="link")throw new Error("unexpected");const n={},o=t[r.type.name];for(const[l,s]of Object.entries(r.attrs)){if(!o)throw Error("ic node is of an unrecognized type: "+r.type.name);const a=o.propSchema;l in a&&(n[l]=s)}let i;return o.content==="styled"?i=dt(r,t,e):i=void 0,{type:r.type.name,props:n,content:i}}function Vt(r,t,e=$t(t),n=Gt(t),o=$(t),i=Ht(t)){var l;if(!r.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+r.type.name);const s=i==null?void 0:i.get(r);if(s)return s;const a=be(r,0);let c=a.bnBlock.node.attrs.id;c===null&&(c=Lt.options.generateID());const u=e[a.blockNoteType];if(!u)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const f={};for(const[k,x]of Object.entries({...r.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const T=u.propSchema;k in T&&!(T[k].default===void 0&&x===void 0)&&(f[k]=x)}const p=e[a.blockNoteType],h=[];(l=a.childContainer)==null||l.node.forEach(k=>{h.push(Vt(k,t,e,n,o,i))});let w;if(p.content==="inline"){if(!a.isBlockContainer)throw new Error("impossible");w=dt(a.blockContent.node,n,o)}else if(p.content==="table"){if(!a.isBlockContainer)throw new Error("impossible");w=ve(a.blockContent.node,n,o)}else if(p.content==="none")w=void 0;else throw new _(p.content);const b={id:c,type:p.type,props:f,content:w,children:h};return i==null||i.set(r,b),b}function Ut(r,t=xe(r),e=$t(t),n=Gt(t),o=$(t),i=Ht(t)){const l=[];return r.firstChild&&r.firstChild.descendants(s=>(l.push(Vt(s,t,e,n,o,i)),!1)),l}function Te(r){const{height:t,width:e}=Ne(r),n=new Array(t).fill(!1).map(()=>new Array(e).fill(null)),o=(i,l)=>{for(let s=i;s<t;s++)for(let a=l;a<e;a++)if(!n[s][a])return{row:s,col:a};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let i=0;i<r.content.rows.length;i++)for(let l=0;l<r.content.rows[i].cells.length;l++){const s=ke(r.content.rows[i].cells[l]),a=Se(s),c=ft(s),{row:u,col:f}=o(i,l);for(let p=u;p<u+a;p++)for(let h=f;h<f+c;h++){if(n[p][h])throw new Error(`Unable to create occupancy grid for table, cell at ${p},${h} is already occupied`);n[p][h]={row:i,col:l,rowspan:a,colspan:c,cell:s}}}return n}function Oe(r,t,e=Te(t)){for(let n=0;n<e.length;n++)for(let o=0;o<e[n].length;o++){const i=e[n][o];if(i.row===r.row&&i.col===r.col)return{row:n,col:o,cell:i.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${r.row},${r.col} is not occupied`)}function Ne(r){const t=r.content.rows.length;let e=0;return r.content.rows.forEach(n=>{let o=0;n.cells.forEach(i=>{o+=ft(i)}),e=Math.max(e,o)}),{height:t,width:e}}function Nt(r,t,e,n){const o=[];for(const[i,l]of Object.entries(r.styles||{})){const s=e[i];if(!s)throw new Error(`style ${i} not found in styleSchema`);if(s.propSchema==="boolean")l&&o.push(t.mark(i));else if(s.propSchema==="string")l&&o.push(t.mark(i,{stringValue:l}));else throw new _(s.propSchema)}return!n||!t.nodes[n].spec.code?r.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
`?t.nodes.hardBreak.createChecked():t.text(i,o)):r.text.length>0?[t.text(r.text,o)]:[]}function Ce(r,t,e){const n=t.marks.link.create({href:r.href});return lt(r.content,t,e).map(o=>{if(o.type.name==="text")return o.mark([...o.marks,n]);if(o.type.name==="hardBreak")return o;throw new Error("unexpected node type")})}function lt(r,t,e,n){const o=[];if(typeof r=="string")return o.push(...Nt({text:r,styles:{}},t,e,n)),o;for(const i of r)o.push(...Nt(i,t,e,n));return o}function Z(r,t,e,n=$(t)){const o=[];for(const i of r)typeof i=="string"?o.push(...lt(i,t,n,e)):ge(i)?o.push(...Ce(i,t,n)):q(i)?o.push(...lt([i],t,n,e)):o.push(Xt(i,t,n));return o}function Ie(r,t,e=$(t)){const n=[],o=new Array(r.headerRows??0).fill(!0),i=new Array(r.headerCols??0).fill(!0),l=r.columnWidths??[];for(let s=0;s<r.rows.length;s++){const a=r.rows[s],c=[],u=o[s];for(let p=0;p<a.cells.length;p++){const h=a.cells[p],w=i[p],b=void 0;let k=null;const x=Oe({row:s,col:p},{content:r});let T=l[x.col]?[l[x.col]]:null;if(h)if(typeof h=="string")k=t.text(h);else if(Q(h)){h.content&&(k=Z(h.content,t,"tableParagraph",e));const B=ft(h);B>1&&(T=new Array(B).fill(!1).map((wt,H)=>l[x.col+H]??void 0))}else k=Z(h,t,"tableParagraph",e);const G=t.nodes[w||u?"tableHeader":"tableCell"].createChecked({...Q(h)?h.props:{},colwidth:T},t.nodes.tableParagraph.createChecked(b,k));c.push(G)}const f=t.nodes.tableRow.createChecked({},c);n.push(f)}return n}function Xt(r,t,e){let n,o=r.type;if(o===void 0&&(o="paragraph"),!t.nodes[o])throw new Error(`node type ${o} not found in schema`);if(!r.content)n=t.nodes[o].createChecked(r.props);else if(typeof r.content=="string"){const i=Z([r.content],t,o,e);n=t.nodes[o].createChecked(r.props,i)}else if(Array.isArray(r.content)){const i=Z(r.content,t,o,e);n=t.nodes[o].createChecked(r.props,i)}else if(r.content.type==="tableContent"){const i=Ie(r.content,t,e);n=t.nodes[o].createChecked(r.props,i)}else throw new _(r.content.type);return n}function Kt(r,t,e=$(t)){let n=r.id;n===void 0&&(n=Lt.options.generateID());const o=[];if(r.children)for(const i of r.children)o.push(Kt(i,t,e));if(!r.type||t.nodes[r.type].isInGroup("blockContent")){const i=Xt(r,t,e),l=o.length>0?t.nodes.blockGroup.createChecked({},o):void 0;return t.nodes.blockContainer.createChecked({id:n,...r.props},l?[i,l]:i)}else{if(t.nodes[r.type].isInGroup("bnBlock"))return t.nodes[r.type].createChecked({id:n,...r.props},o);throw new Error(`block type ${r.type} doesn't match blockContent or bnBlock group`)}}function Je(r,t){const e=r.pmSchema.nodeFromJSON(t);return Ut(e)}function mt(r,t){const e=t.map(n=>Kt(n,r.pmSchema));return r.pmSchema.topNodeType.create(null,r.pmSchema.nodes.blockGroup.create(null,e))}function Wt(r,t){const e=at.yXmlFragmentToProseMirrorRootNode(t,r.pmSchema);return Ut(e)}function ze(r,t,e){return at.prosemirrorToYXmlFragment(mt(r,t),e)}function Re(r,t,e="prosemirror"){return Wt(r,t.getXmlFragment(e))}function De(r,t,e="prosemirror"){return at.prosemirrorToYDoc(mt(r,t),e)}class yt{constructor(t){tt(this,"editor");tt(this,"jsdom",new ne.JSDOM);this.editor=A.BlockNoteEditor.create(t)}async _withJSDOM(t){const e=globalThis.window,n=globalThis.document;globalThis.document=this.jsdom.window.document,globalThis.window=this.jsdom.window,globalThis.window.__TEST_OPTIONS=e==null?void 0:e.__TEST_OPTIONS;try{return await t()}finally{globalThis.document=n,globalThis.window=e}}static create(t={}){return new yt(t)}_prosemirrorNodeToBlocks(t){return A.docToBlocks(t)}_prosemirrorJSONToBlocks(t){return Je(this.editor,t)}_blocksToProsemirrorNode(t){return mt(this.editor,t)}yXmlFragmentToBlocks(t){return Wt(this.editor,t)}blocksToYXmlFragment(t,e){return ze(this.editor,t,e)}yDocToBlocks(t,e="prosemirror"){return Re(this.editor,t,e)}blocksToYDoc(t,e="prosemirror"){return De(this.editor,t,e)}async blocksToHTMLLossy(t){return this._withJSDOM(async()=>A.createExternalHTMLExporter(this.editor.pmSchema,this.editor).exportBlocks(t,{document:this.jsdom.window.document}))}async blocksToFullHTML(t){return this._withJSDOM(async()=>A.createInternalHTMLSerializer(this.editor.pmSchema,this.editor).serializeBlocks(t,{document:this.jsdom.window.document}))}async tryParseHTMLToBlocks(t){return this._withJSDOM(async()=>this.editor.tryParseHTMLToBlocks(t))}async blocksToMarkdownLossy(t){return this._withJSDOM(async()=>A.blocksToMarkdown(t,this.editor.pmSchema,this.editor,{document:this.jsdom.window.document}))}async tryParseMarkdownToBlocks(t){return this._withJSDOM(async()=>this.editor.tryParseMarkdownToBlocks(t))}async withReactContext(t,e){return this._withJSDOM(async()=>{const n=te.createRoot(this.jsdom.window.document.createElement("div"));_t.flushSync(()=>{n.render(kt.createElement(t,{},kt.createElement(Zt.BlockNoteViewRaw,{editor:this.editor})))});try{return await e()}finally{n.unmount(),await new Promise(o=>setTimeout(o,3))}})}}exports.ServerBlockNoteEditor=yt;
//# sourceMappingURL=blocknote-server-util.cjs.map
+1
-1

@@ -1,1 +0,1 @@

{"builtAt":1760026139118,"assets":[{"name":"blocknote-server-util.cjs","size":3086},{"name":"blocknote-server-util.cjs.map","size":14031}],"chunks":[{"id":"a1ee98a","entry":true,"initial":true,"files":["blocknote-server-util.cjs"],"names":["blocknote-server-util"]}],"modules":[{"name":"./src/context/ServerBlockNoteEditor.ts","size":8445,"chunks":["a1ee98a"]},{"name":"./src/index.ts","size":0,"chunks":["a1ee98a"]}]}
{"builtAt":1762873633744,"assets":[{"name":"blocknote-server-util.cjs","size":41654},{"name":"blocknote-server-util.cjs.map","size":356218}],"chunks":[{"id":"a1ee98a","entry":true,"initial":true,"files":["blocknote-server-util.cjs"],"names":["blocknote-server-util"]}],"modules":[{"name":"../../node_modules/.pnpm/prosemirror-model@1.25.4/node_modules/prosemirror-model/dist/index.js","size":17858,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/prosemirror-transform@1.10.4/node_modules/prosemirror-transform/dist/index.js","size":27944,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/prosemirror-state@1.4.4/node_modules/prosemirror-state/dist/index.js","size":19441,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/rng.js","size":1025,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/regex.js","size":132,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/validate.js","size":82,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/stringify.js","size":1398,"chunks":["a1ee98a"]},{"name":"../../node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/dist/esm-browser/v4.js","size":319,"chunks":["a1ee98a"]},{"name":"../core/dist/blockToNode-DIfPWLH8.js","size":22149,"chunks":["a1ee98a"]},{"name":"../core/dist/yjs.js","size":647,"chunks":["a1ee98a"]},{"name":"./src/context/ServerBlockNoteEditor.ts","size":7795,"chunks":["a1ee98a"]},{"name":"./src/index.ts","size":0,"chunks":["a1ee98a"]}]}

@@ -14,3 +14,3 @@ {

"license": "MPL-2.0",
"version": "0.41.1",
"version": "0.42.0",
"files": [

@@ -53,6 +53,6 @@ "dist",

"dependencies": {
"@blocknote/core": "0.41.1",
"@blocknote/react": "0.41.1",
"@tiptap/core": "^3.4.3",
"@tiptap/pm": "^3.4.3",
"@blocknote/core": "0.42.0",
"@blocknote/react": "0.42.0",
"@tiptap/core": "^3.10.2",
"@tiptap/pm": "^3.10.2",
"jsdom": "^25.0.1",

@@ -65,12 +65,12 @@ "y-prosemirror": "^1.3.7",

"@types/jsdom": "^21.1.7",
"@types/react": "^19.1.0",
"@types/react-dom": "^19.1.0",
"eslint": "^8.10.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"rollup-plugin-webpack-stats": "^0.2.2",
"typescript": "^5.0.4",
"vite": "^5.3.4",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"eslint": "^8.57.1",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"rollup-plugin-webpack-stats": "^0.2.6",
"typescript": "^5.9.3",
"vite": "^5.4.20",
"vite-plugin-eslint": "^1.8.1",
"vitest": "^2.0.3"
"vitest": "^2.1.9"
},

@@ -77,0 +77,0 @@ "peerDependencies": {

import { Block } from "@blocknote/core";
import { describe, expect, it } from "vitest";
import * as Y from "yjs";
import { ServerBlockNoteEditor } from "./ServerBlockNoteEditor.js";

@@ -107,23 +106,2 @@

it("converts to and from prosemirror (doc)", async () => {
const node = await editor._blocksToProsemirrorNode(blocks);
const blockOutput = await editor._prosemirrorNodeToBlocks(node);
expect(blockOutput).toEqual(blocks);
});
it("converts to and from yjs (doc)", async () => {
const ydoc = await editor.blocksToYDoc(blocks);
const blockOutput = await editor.yDocToBlocks(ydoc);
expect(blockOutput).toEqual(blocks);
});
it("converts to and from yjs (fragment)", async () => {
const doc = new Y.Doc();
const fragment = doc.getXmlFragment("test");
await editor.blocksToYXmlFragment(blocks, fragment);
const blockOutput = await editor.yXmlFragmentToBlocks(fragment);
expect(blockOutput).toEqual(blocks);
});
it("converts to and from HTML (blocksToHTMLLossy)", async () => {

@@ -130,0 +108,0 @@ const html = await editor.blocksToHTMLLossy(blocks);

@@ -12,8 +12,15 @@ import {

StyleSchema,
blockToNode,
blocksToMarkdown,
createExternalHTMLExporter,
createInternalHTMLSerializer,
nodeToBlock,
docToBlocks,
} from "@blocknote/core";
import {
_blocksToProsemirrorNode as blocksToProsemirrorNodeUtil,
_prosemirrorJSONToBlocks as prosemirrorJSONToBlocksUtil,
blocksToYDoc as blocksToYDocUtil,
blocksToYXmlFragment as blocksToYXmlFragmentUtil,
yDocToBlocks as yDocToBlocksUtil,
yXmlFragmentToBlocks as yXmlFragmentToBlocksUtil,
} from "@blocknote/core/yjs";

@@ -27,7 +34,2 @@ import { BlockNoteViewRaw } from "@blocknote/react";

import { createRoot } from "react-dom/client";
import {
prosemirrorToYDoc,
prosemirrorToYXmlFragment,
yXmlFragmentToProseMirrorRootNode,
} from "y-prosemirror";
import type * as Y from "yjs";

@@ -105,12 +107,3 @@

public _prosemirrorNodeToBlocks(pmNode: Node) {
const blocks: Block<BSchema, InlineContentSchema, StyleSchema>[] = [];
// note, this code is similar to editor.document
pmNode.firstChild!.descendants((node) => {
blocks.push(nodeToBlock(node, this.editor.pmSchema));
return false;
});
return blocks;
return docToBlocks(pmNode);
}

@@ -124,6 +117,3 @@

public _prosemirrorJSONToBlocks(json: any) {
// note: theoretically this should also be possible without creating prosemirror nodes,
// but this is definitely the easiest way
const doc = this.editor.pmSchema.nodeFromJSON(json);
return this._prosemirrorNodeToBlocks(doc);
return prosemirrorJSONToBlocksUtil(this.editor, json);
}

@@ -139,10 +129,3 @@

) {
const pmSchema = this.editor.pmSchema;
const pmNodes = blocks.map((b) => blockToNode(b, pmSchema));
const doc = pmSchema.topNodeType.create(
null,
pmSchema.nodes["blockGroup"].create(null, pmNodes),
);
return doc;
return blocksToProsemirrorNodeUtil(this.editor, blocks);
}

@@ -157,7 +140,3 @@

public yXmlFragmentToBlocks(xmlFragment: Y.XmlFragment) {
const pmNode = yXmlFragmentToProseMirrorRootNode(
xmlFragment,
this.editor.pmSchema,
);
return this._prosemirrorNodeToBlocks(pmNode);
return yXmlFragmentToBlocksUtil(this.editor, xmlFragment);
}

@@ -179,6 +158,3 @@

) {
return prosemirrorToYXmlFragment(
this._blocksToProsemirrorNode(blocks),
xmlFragment,
);
return blocksToYXmlFragmentUtil(this.editor, blocks, xmlFragment);
}

@@ -191,3 +167,3 @@

public yDocToBlocks(ydoc: Y.Doc, xmlFragment = "prosemirror") {
return this.yXmlFragmentToBlocks(ydoc.getXmlFragment(xmlFragment));
return yDocToBlocksUtil(this.editor, ydoc, xmlFragment);
}

@@ -206,6 +182,3 @@

) {
return prosemirrorToYDoc(
this._blocksToProsemirrorNode(blocks),
xmlFragment,
);
return blocksToYDocUtil(this.editor, blocks, xmlFragment);
}

@@ -344,2 +317,3 @@

tmpRoot.unmount();
await new Promise((resolve) => setTimeout(resolve, 3));
}

@@ -346,0 +320,0 @@ });

@@ -36,3 +36,3 @@ import { Block, BlockNoteEditor, BlockNoteEditorOptions, BlockSchema, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, InlineContentSchema, PartialBlock, StyleSchema } from "@blocknote/core";

*/
_prosemirrorNodeToBlocks(pmNode: Node): Block<BSchema, InlineContentSchema, StyleSchema>[];
_prosemirrorNodeToBlocks(pmNode: Node): Block<Record<string, import("@blocknote/core").BlockConfig<string, import("@blocknote/core").PropSchema, "inline" | "none" | "table">>, InlineContentSchema, StyleSchema>[];
/**

@@ -43,3 +43,3 @@ * Turn Prosemirror JSON to BlockNote style JSON

*/
_prosemirrorJSONToBlocks(json: any): Block<BSchema, InlineContentSchema, StyleSchema>[];
_prosemirrorJSONToBlocks(json: any): Block<BSchema, ISchema, SSchema>[];
/**

@@ -56,3 +56,3 @@ * Turn BlockNote JSON to Prosemirror node / state

*/
yXmlFragmentToBlocks(xmlFragment: Y.XmlFragment): Block<BSchema, InlineContentSchema, StyleSchema>[];
yXmlFragmentToBlocks(xmlFragment: Y.XmlFragment): Block<BSchema, ISchema, SSchema>[];
/**

@@ -73,3 +73,3 @@ * Convert blocks to a Y.XmlFragment

*/
yDocToBlocks(ydoc: Y.Doc, xmlFragment?: string): Block<BSchema, InlineContentSchema, StyleSchema>[];
yDocToBlocks(ydoc: Y.Doc, xmlFragment?: string): Block<BSchema, ISchema, SSchema>[];
/**

@@ -76,0 +76,0 @@ * This can be used when importing existing content to Y.Doc for the first time,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display