@blocknote/core 0.8.1 → 0.8.2

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.
Files changed (24) hide show
  1. package/dist/blocknote.js +199 -174
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +3 -3
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/package.json +3 -3
  6. package/src/BlockNoteEditor.ts +14 -0
  7. package/src/extensions/Blocks/nodes/BlockContainer.ts +12 -3
  8. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +2 -2
  9. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +22 -29
  10. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +4 -6
  11. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +20 -19
  12. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +2 -2
  13. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +22 -13
  14. package/src/shared/EditorElement.ts +3 -3
  15. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +23 -17
  16. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +2 -2
  17. package/types/src/BlockNoteEditor.d.ts +1 -0
  18. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +1 -1
  19. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +1 -1
  20. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -3
  21. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +2 -3
  22. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +1 -1
  23. package/types/src/shared/EditorElement.d.ts +3 -3
  24. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +1 -1
@@ -1,7 +1,7 @@
1
- (function(f,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@tiptap/core"),require("prosemirror-state"),require("prosemirror-model"),require("uuid"),require("rehype-parse"),require("rehype-remark"),require("rehype-stringify"),require("remark-gfm"),require("remark-parse"),require("remark-rehype"),require("remark-stringify"),require("unified"),require("hast-util-from-dom"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-collaboration"),require("@tiptap/extension-collaboration-cursor"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-italic"),require("@tiptap/extension-link"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-view")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","prosemirror-state","prosemirror-model","uuid","rehype-parse","rehype-remark","rehype-stringify","remark-gfm","remark-parse","remark-rehype","remark-stringify","unified","hast-util-from-dom","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-link","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-view"],h):(f=typeof globalThis<"u"?globalThis:f||self,h(f.blocknote={},f.core,f.prosemirrorState,f.prosemirrorModel,f.uuid,f.rehypeParse,f.rehypeRemark,f.rehypeStringify,f.remarkGfm,f.remarkParse,f.remarkRehype,f.remarkStringify,f.unified,f.hastUtilFromDom,f.extensionBold,f.extensionCode,f.Collaboration,f.CollaborationCursor,f.extensionDropcursor,f.extensionGapcursor,f.extensionHardBreak,f.extensionHistory,f.extensionItalic,f.extensionLink,f.extensionStrike,f.extensionText,f.extensionUnderline,f.pv))})(this,function(f,h,k,E,wt,St,_t,Pt,It,Nt,At,Lt,D,G,Ht,Ot,Dt,Ft,Rt,zt,Ut,qt,jt,K,$t,Gt,Kt,B){"use strict";var on=Object.defineProperty;var rn=(f,h,k)=>h in f?on(f,h,{enumerable:!0,configurable:!0,writable:!0,value:k}):f[h]=k;var p=(f,h,k)=>(rn(f,typeof h!="symbol"?h+"":h,k),k);const T=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Wt(n){if(n&&typeof n=="object"&&"default"in n)return n;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const W=T(St),Yt=T(_t),Y=T(Pt),V=T(It),Vt=T(Nt),Jt=T(At),Xt=T(Lt),Zt=T(Dt),Qt=T(Ft),te=Wt(B),J="_blockOuter_xgzwr_5",X="_block_xgzwr_5",Z="_reactNodeViewRenderer_xgzwr_17",Q="_blockContent_xgzwr_22",tt="_blockGroup_xgzwr_42",et="_isEmpty_xgzwr_240",nt="_inlineContent_xgzwr_240",ot="_isFilter_xgzwr_241",rt="_hasAnchor_xgzwr_263",v={blockOuter:J,block:X,reactNodeViewRenderer:Z,blockContent:Q,blockGroup:tt,isEmpty:et,inlineContent:nt,isFilter:ot,hasAnchor:rt},ee=Object.freeze(Object.defineProperty({__proto__:null,block:X,blockContent:Q,blockGroup:tt,blockOuter:J,default:v,hasAnchor:rt,inlineContent:nt,isEmpty:et,isFilter:ot,reactNodeViewRenderer:Z},Symbol.toStringTag,{value:"Module"}));function F(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function it(n){const e={};return Object.entries(n.propSchema).forEach(([t,o])=>{e[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>r.getAttribute(F(t)),renderHTML:r=>r[t]!==o.default?{[F(t)]:r[t]}:{}}}),e}function st(n){return[{tag:"div[data-content-type="+n.type+"]"}]}function at(n,e){const t=document.createElement("div");t.setAttribute("data-content-type",n.type);for(const[r,i]of Object.entries(e))t.setAttribute(r,i);let o;return n.containsInlineContent?(o=document.createElement("div"),t.appendChild(o)):o=void 0,o!==void 0?{dom:t,contentDOM:o}:{dom:t}}function ne(n){return{node:P({name:n.type,content:n.containsInlineContent?"inline*":"",selectable:n.containsInlineContent,addOptions(){return{editor:void 0}},addAttributes(){return it(n)},parseHTML(){return st(n)},renderHTML({HTMLAttributes:t}){return at(n,t)},addNodeView(){return({HTMLAttributes:t,getPos:o})=>{const r=document.createElement("div");r.className=v.blockContent,r.setAttribute("data-content-type",n.type);for(const[m,g]of Object.entries(t))r.setAttribute(m,g);const i=this.options.editor;if(typeof o=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const s=o(),d=i._tiptapEditor.state.doc.resolve(s).node().attrs.id,c=i.getBlock(d);if(c.type!==n.type)throw new Error("Block type does not match");const u=n.render(c,i);return"contentDOM"in u&&(u.contentDOM.className=`${u.contentDOM.className?u.contentDOM.className+" ":""}${v.inlineContent}`),r.appendChild(u.dom),"contentDOM"in u?{dom:r,contentDOM:u.contentDOM}:{dom:r}}}}),propSchema:n.propSchema}}function P(n){return h.Node.create({...n,group:"blockContent"})}const oe=P({name:"heading",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:n=>n.getAttribute("data-level"),renderHTML:n=>({"data-level":n.level})}}},addInputRules(){return[...["1","2","3"].map(n=>new h.InputRule({find:new RegExp(`^(#{${parseInt(n)}})\\s$`),handler:({state:e,chain:t,range:o})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"heading"},{tag:"h2",attrs:{level:"2"},node:"heading"},{tag:"h3",attrs:{level:"3"},node:"heading"}]},renderHTML({node:n,HTMLAttributes:e}){return["div",h.mergeAttributes(e,{class:v.blockContent,"data-content-type":this.name}),["h"+n.attrs.level,{class:v.inlineContent},0]]}});function b(n,e){if(e<0||e>n.nodeSize)return;const t=n.resolve(e),o=t.depth;let r=t.node(o),i=o;for(;;){if(i<0)return;if(r.type.name==="blockContainer")break;i-=1,r=t.node(i)}const s=r.attrs.id,a=r.firstChild,l=a.type,d=r.childCount===2?r.lastChild.childCount:0,c=t.start(i),u=t.end(i);return{id:s,node:r,contentNode:a,contentType:l,numChildBlocks:d,startPos:c,endPos:u,depth:i}}const lt=n=>{const{node:e,contentType:t}=b(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!t.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:r,chain:i,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},re=P({name:"bulletListItem",content:"inline*",addInputRules(){return[new h.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>lt(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:v.blockContent,"data-content-type":this.name}),["p",{class:v.inlineContent},0]]}}),ie=new k.PluginKey("numbered-list-indexing"),se=()=>new k.Plugin({key:ie,appendTransaction:(n,e,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((i,s)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,d=b(o.doc,s+1);if(d===void 0)return;if(!l){const m=b(o.doc,s-2);if(m===void 0)return;if(!(d.depth!==m.depth)){const y=m.contentNode;if(m.contentType.name==="numberedListItem"){const j=y.attrs.index;a=(parseInt(j)+1).toString()}}}d.contentNode.attrs.index!==a&&(r=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),r?o:null}}),ae=P({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new h.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>lt(this.editor)}},addProseMirrorPlugins(){return[se()]},parseHTML(){return[{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:v.blockContent,"data-content-type":this.name}),["p",{class:v.inlineContent},0]]}}),le=P({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:v.blockContent,"data-content-type":this.name}),["p",{class:v.inlineContent},0]]}}),I={backgroundColor:{default:"transparent"},textColor:{default:"black"},textAlignment:{default:"left",values:["left","center","right","justify"]}},dt={paragraph:{propSchema:I,node:le},heading:{propSchema:{...I,level:{default:"1",values:["1","2","3"]}},node:oe},bulletListItem:{propSchema:I,node:re},numberedListItem:{propSchema:I,node:ae}};function de(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function ce(n){const e=n.filter((o,r)=>n.indexOf(o)!==r);return de(e)}const R=h.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>window.__TEST_OPTIONS?(window.__TEST_OPTIONS.mockID===void 0?window.__TEST_OPTIONS.mockID=0:window.__TEST_OPTIONS.mockID++,window.__TEST_OPTIONS.mockID.toString()):wt.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:n=>n.getAttribute(`data-${this.options.attributeName}`),renderHTML:n=>({[`data-${this.options.attributeName}`]:n[this.options.attributeName]})}}}]},onCreate(){if(this.editor.extensionManager.extensions.find(l=>l.name==="collaboration"))return;const{view:n,state:e}=this.editor,{tr:t,doc:o}=e,{types:r,attributeName:i,generateID:s}=this.options;h.findChildren(o,l=>r.includes(l.type.name)&&l.attrs[i]===null).forEach(({node:l,pos:d})=>{t.setNodeMarkup(d,void 0,{...l.attrs,[i]:s()})}),t.setMeta("addToHistory",!1),n.dispatch(t)},addProseMirrorPlugins(){let n=null,e=!1;return[new k.Plugin({key:new k.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const i=t.some(y=>y.docChanged)&&!o.doc.eq(r.doc),s=this.options.filterTransaction&&t.some(y=>{var x,C;return!(!((C=(x=this.options).filterTransaction)===null||C===void 0)&&C.call(x,y))});if(!i||s)return;const{tr:a}=r,{types:l,attributeName:d,generateID:c}=this.options,u=h.combineTransactionSteps(o.doc,t),{mapping:m}=u;if(h.getChangedRanges(u).forEach(({newRange:y})=>{const x=h.findChildrenInRange(r.doc,y,S=>l.includes(S.type.name)),C=x.map(({node:S})=>S.attrs[d]).filter(S=>S!==null),j=ce(C);x.forEach(({node:S,pos:O})=>{var $;const Mt=($=a.doc.nodeAt(O))===null||$===void 0?void 0:$.attrs[d];if(Mt===null){a.setNodeMarkup(O,void 0,{...S.attrs,[d]:c()});return}const{deleted:nn}=m.invert().mapResult(O);nn&&j.includes(Mt)&&a.setNodeMarkup(O,void 0,{...S.attrs,[d]:c()})})}),!!a.steps.length)return a},view(t){const o=r=>{var i;n=!((i=t.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{var r;return(n!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(n=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:o,attributeName:r}=this.options,i=s=>{const a=[];return s.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(i(l.content)));return}const d=l.type.create({...l.attrs,[r]:null},i(l.content),l.marks);a.push(d)}),E.Fragment.from(a)};return e=!1,new E.Slice(i(t.content),t.openStart,t.openEnd)}}})]}});class ue extends Error{constructor(e){super(`Unreachable case: ${e}`)}}const ct=new Set(["bold","italic","underline","strike","code"]),ut=new Set(["textColor","backgroundColor"]);function ht(n,e){const t=[];for(const[o,r]of Object.entries(n.styles))ct.has(o)?t.push(e.mark(o)):ut.has(o)&&t.push(e.mark(o,{color:r}));return n.text.split(/(\n)/g).filter(o=>o.length>0).map(o=>o===`
1
+ (function(f,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@tiptap/core"),require("prosemirror-state"),require("prosemirror-model"),require("uuid"),require("rehype-parse"),require("rehype-remark"),require("rehype-stringify"),require("remark-gfm"),require("remark-parse"),require("remark-rehype"),require("remark-stringify"),require("unified"),require("hast-util-from-dom"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-collaboration"),require("@tiptap/extension-collaboration-cursor"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-italic"),require("@tiptap/extension-link"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-view")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","prosemirror-state","prosemirror-model","uuid","rehype-parse","rehype-remark","rehype-stringify","remark-gfm","remark-parse","remark-rehype","remark-stringify","unified","hast-util-from-dom","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-link","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-view"],h):(f=typeof globalThis<"u"?globalThis:f||self,h(f.blocknote={},f.core,f.prosemirrorState,f.prosemirrorModel,f.uuid,f.rehypeParse,f.rehypeRemark,f.rehypeStringify,f.remarkGfm,f.remarkParse,f.remarkRehype,f.remarkStringify,f.unified,f.hastUtilFromDom,f.extensionBold,f.extensionCode,f.Collaboration,f.CollaborationCursor,f.extensionDropcursor,f.extensionGapcursor,f.extensionHardBreak,f.extensionHistory,f.extensionItalic,f.extensionLink,f.extensionStrike,f.extensionText,f.extensionUnderline,f.pv))})(this,function(f,h,k,v,Mt,St,Pt,_t,It,At,Nt,Lt,D,G,Ht,Ot,Dt,Ft,Rt,zt,Ut,qt,jt,K,$t,Gt,Kt,B){"use strict";var on=Object.defineProperty;var rn=(f,h,k)=>h in f?on(f,h,{enumerable:!0,configurable:!0,writable:!0,value:k}):f[h]=k;var p=(f,h,k)=>(rn(f,typeof h!="symbol"?h+"":h,k),k);const w=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Wt(n){if(n&&typeof n=="object"&&"default"in n)return n;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const W=w(St),Vt=w(Pt),V=w(_t),Y=w(It),Yt=w(At),Jt=w(Nt),Xt=w(Lt),Zt=w(Dt),Qt=w(Ft),te=Wt(B),J="_blockOuter_xgzwr_5",X="_block_xgzwr_5",Z="_reactNodeViewRenderer_xgzwr_17",Q="_blockContent_xgzwr_22",tt="_blockGroup_xgzwr_42",et="_isEmpty_xgzwr_240",nt="_inlineContent_xgzwr_240",ot="_isFilter_xgzwr_241",rt="_hasAnchor_xgzwr_263",E={blockOuter:J,block:X,reactNodeViewRenderer:Z,blockContent:Q,blockGroup:tt,isEmpty:et,inlineContent:nt,isFilter:ot,hasAnchor:rt},ee=Object.freeze(Object.defineProperty({__proto__:null,block:X,blockContent:Q,blockGroup:tt,blockOuter:J,default:E,hasAnchor:rt,inlineContent:nt,isEmpty:et,isFilter:ot,reactNodeViewRenderer:Z},Symbol.toStringTag,{value:"Module"}));function F(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function it(n){const e={};return Object.entries(n.propSchema).forEach(([t,o])=>{e[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>r.getAttribute(F(t)),renderHTML:r=>r[t]!==o.default?{[F(t)]:r[t]}:{}}}),e}function st(n){return[{tag:"div[data-content-type="+n.type+"]"}]}function at(n,e){const t=document.createElement("div");t.setAttribute("data-content-type",n.type);for(const[r,i]of Object.entries(e))t.setAttribute(r,i);let o;return n.containsInlineContent?(o=document.createElement("div"),t.appendChild(o)):o=void 0,o!==void 0?{dom:t,contentDOM:o}:{dom:t}}function ne(n){return{node:_({name:n.type,content:n.containsInlineContent?"inline*":"",selectable:n.containsInlineContent,addOptions(){return{editor:void 0}},addAttributes(){return it(n)},parseHTML(){return st(n)},renderHTML({HTMLAttributes:t}){return at(n,t)},addNodeView(){return({HTMLAttributes:t,getPos:o})=>{const r=document.createElement("div");r.className=E.blockContent,r.setAttribute("data-content-type",n.type);for(const[m,g]of Object.entries(t))r.setAttribute(m,g);const i=this.options.editor;if(typeof o=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const s=o(),d=i._tiptapEditor.state.doc.resolve(s).node().attrs.id,c=i.getBlock(d);if(c.type!==n.type)throw new Error("Block type does not match");const u=n.render(c,i);return"contentDOM"in u&&(u.contentDOM.className=`${u.contentDOM.className?u.contentDOM.className+" ":""}${E.inlineContent}`),r.appendChild(u.dom),"contentDOM"in u?{dom:r,contentDOM:u.contentDOM}:{dom:r}}}}),propSchema:n.propSchema}}function _(n){return h.Node.create({...n,group:"blockContent"})}const oe=_({name:"heading",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:n=>n.getAttribute("data-level"),renderHTML:n=>({"data-level":n.level})}}},addInputRules(){return[...["1","2","3"].map(n=>new h.InputRule({find:new RegExp(`^(#{${parseInt(n)}})\\s$`),handler:({state:e,chain:t,range:o})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"heading"},{tag:"h2",attrs:{level:"2"},node:"heading"},{tag:"h3",attrs:{level:"3"},node:"heading"}]},renderHTML({node:n,HTMLAttributes:e}){return["div",h.mergeAttributes(e,{class:E.blockContent,"data-content-type":this.name}),["h"+n.attrs.level,{class:E.inlineContent},0]]}});function b(n,e){if(e<0||e>n.nodeSize)return;const t=n.resolve(e),o=t.depth;let r=t.node(o),i=o;for(;;){if(i<0)return;if(r.type.name==="blockContainer")break;i-=1,r=t.node(i)}const s=r.attrs.id,a=r.firstChild,l=a.type,d=r.childCount===2?r.lastChild.childCount:0,c=t.start(i),u=t.end(i);return{id:s,node:r,contentNode:a,contentType:l,numChildBlocks:d,startPos:c,endPos:u,depth:i}}const lt=n=>{const{node:e,contentType:t}=b(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!t.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:r,chain:i,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},re=_({name:"bulletListItem",content:"inline*",addInputRules(){return[new h.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>lt(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:E.blockContent,"data-content-type":this.name}),["p",{class:E.inlineContent},0]]}}),ie=new k.PluginKey("numbered-list-indexing"),se=()=>new k.Plugin({key:ie,appendTransaction:(n,e,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((i,s)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,d=b(o.doc,s+1);if(d===void 0)return;if(!l){const m=b(o.doc,s-2);if(m===void 0)return;if(!(d.depth!==m.depth)){const y=m.contentNode;if(m.contentType.name==="numberedListItem"){const j=y.attrs.index;a=(parseInt(j)+1).toString()}}}d.contentNode.attrs.index!==a&&(r=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),r?o:null}}),ae=_({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new h.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>lt(this.editor)}},addProseMirrorPlugins(){return[se()]},parseHTML(){return[{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:E.blockContent,"data-content-type":this.name}),["p",{class:E.inlineContent},0]]}}),le=_({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:E.blockContent,"data-content-type":this.name}),["p",{class:E.inlineContent},0]]}}),I={backgroundColor:{default:"transparent"},textColor:{default:"black"},textAlignment:{default:"left",values:["left","center","right","justify"]}},dt={paragraph:{propSchema:I,node:le},heading:{propSchema:{...I,level:{default:"1",values:["1","2","3"]}},node:oe},bulletListItem:{propSchema:I,node:re},numberedListItem:{propSchema:I,node:ae}};function de(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function ce(n){const e=n.filter((o,r)=>n.indexOf(o)!==r);return de(e)}const R=h.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>window.__TEST_OPTIONS?(window.__TEST_OPTIONS.mockID===void 0?window.__TEST_OPTIONS.mockID=0:window.__TEST_OPTIONS.mockID++,window.__TEST_OPTIONS.mockID.toString()):Mt.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:n=>n.getAttribute(`data-${this.options.attributeName}`),renderHTML:n=>({[`data-${this.options.attributeName}`]:n[this.options.attributeName]})}}}]},onCreate(){if(this.editor.extensionManager.extensions.find(l=>l.name==="collaboration"))return;const{view:n,state:e}=this.editor,{tr:t,doc:o}=e,{types:r,attributeName:i,generateID:s}=this.options;h.findChildren(o,l=>r.includes(l.type.name)&&l.attrs[i]===null).forEach(({node:l,pos:d})=>{t.setNodeMarkup(d,void 0,{...l.attrs,[i]:s()})}),t.setMeta("addToHistory",!1),n.dispatch(t)},addProseMirrorPlugins(){let n=null,e=!1;return[new k.Plugin({key:new k.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const i=t.some(y=>y.docChanged)&&!o.doc.eq(r.doc),s=this.options.filterTransaction&&t.some(y=>{var x,C;return!(!((C=(x=this.options).filterTransaction)===null||C===void 0)&&C.call(x,y))});if(!i||s)return;const{tr:a}=r,{types:l,attributeName:d,generateID:c}=this.options,u=h.combineTransactionSteps(o.doc,t),{mapping:m}=u;if(h.getChangedRanges(u).forEach(({newRange:y})=>{const x=h.findChildrenInRange(r.doc,y,S=>l.includes(S.type.name)),C=x.map(({node:S})=>S.attrs[d]).filter(S=>S!==null),j=ce(C);x.forEach(({node:S,pos:O})=>{var $;const Tt=($=a.doc.nodeAt(O))===null||$===void 0?void 0:$.attrs[d];if(Tt===null){a.setNodeMarkup(O,void 0,{...S.attrs,[d]:c()});return}const{deleted:nn}=m.invert().mapResult(O);nn&&j.includes(Tt)&&a.setNodeMarkup(O,void 0,{...S.attrs,[d]:c()})})}),!!a.steps.length)return a},view(t){const o=r=>{var i;n=!((i=t.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{var r;return(n!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(n=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:o,attributeName:r}=this.options,i=s=>{const a=[];return s.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(i(l.content)));return}const d=l.type.create({...l.attrs,[r]:null},i(l.content),l.marks);a.push(d)}),v.Fragment.from(a)};return e=!1,new v.Slice(i(t.content),t.openStart,t.openEnd)}}})]}});class ue extends Error{constructor(e){super(`Unreachable case: ${e}`)}}const ct=new Set(["bold","italic","underline","strike","code"]),ut=new Set(["textColor","backgroundColor"]);function ht(n,e){const t=[];for(const[o,r]of Object.entries(n.styles))ct.has(o)?t.push(e.mark(o)):ut.has(o)&&t.push(e.mark(o,{color:r}));return n.text.split(/(\n)/g).filter(o=>o.length>0).map(o=>o===`
2
2
  `?e.nodes.hardBreak.create():e.text(o,t))}function he(n,e){const t=e.marks.link.create({href:n.href});return pt(n.content,e).map(o=>{if(o.type.name==="text")return o.mark([...o.marks,t]);if(o.type.name==="hardBreak")return o;throw new Error("unexpected node type")})}function pt(n,e){let t=[];if(typeof n=="string")return t.push(...ht({type:"text",text:n,styles:{}},e)),t;for(const o of n)t.push(...ht(o,e));return t}function ft(n,e){let t=[];for(const o of n)if(o.type==="link")t.push(...he(o,e));else if(o.type==="text")t.push(...pt([o],e));else throw new ue(o);return t}function H(n,e){let t=n.id;t===void 0&&(t=R.options.generateID());let o=n.type;o===void 0&&(o="paragraph");let r;if(!n.content)r=e.nodes[o].create(n.props);else if(typeof n.content=="string")r=e.nodes[o].create(n.props,e.text(n.content));else{const a=ft(n.content,e);r=e.nodes[o].create(n.props,a)}const i=[];if(n.children)for(const a of n.children)i.push(H(a,e));const s=e.nodes.blockGroup.create({},i);return e.nodes.blockContainer.create({id:t,...n.props},i.length>0?[r,s]:r)}function pe(n){const e=[];let t;return n.content.forEach(o=>{if(o.type.name==="hardBreak"){t?t.type==="text"?t.text+=`
3
3
  `:t.type==="link"&&(t.content[t.content.length-1].text+=`
4
4
  `):t={type:"text",text:`
5
- `,styles:{}};return}const r={};let i;for(const s of o.marks)if(s.type.name==="link")i=s;else if(ct.has(s.type.name))r[s.type.name]=!0;else if(ut.has(s.type.name))r[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);t?t.type==="text"?i?(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]}):JSON.stringify(t.styles)===JSON.stringify(r)?t.text+=o.textContent:(e.push(t),t={type:"text",text:o.textContent,styles:r}):t.type==="link"&&(i?t.href===i.attrs.href?JSON.stringify(t.content[t.content.length-1].styles)===JSON.stringify(r)?t.content[t.content.length-1].text+=o.textContent:t.content.push({type:"text",text:o.textContent,styles:r}):(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]}):(e.push(t),t={type:"text",text:o.textContent,styles:r})):i?t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]}:t={type:"text",text:o.textContent,styles:r}}),t&&e.push(t),e}function M(n,e,t){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const o=t==null?void 0:t.get(n);if(o)return o;const r=b(n,0);let i=r.id;i===null&&(i=R.options.generateID());const s={};for(const[c,u]of Object.entries({...r.node.attrs,...r.contentNode.attrs})){const m=e[r.contentType.name];if(!m)throw Error("Block is of an unrecognized type: "+r.contentType.name);const g=m.propSchema;c in g?s[c]=u:c!=="id"&&!(c in I)&&console.warn("Block has an unrecognized attribute: "+c)}const a=pe(r.contentNode),l=[];for(let c=0;c<r.numChildBlocks;c++)l.push(M(r.node.lastChild.child(c),e,t));const d={id:i,type:r.contentType.name,props:s,content:a,children:l};return t==null||t.set(n,d),d}function z(n,e){let t,o;if(e.firstChild.descendants((r,i)=>t?!1:r.type.name!=="blockContainer"||r.attrs.id!==n?!0:(t=r,o=i+1,!1)),t===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:o}}function mt(n,e,t="before",o){const r=typeof e=="string"?e:e.id,i=[];for(const d of n)i.push(H(d,o.schema));let s=-1;const{node:a,posBeforeNode:l}=z(r,o.state.doc);if(t==="before"&&(s=l),t==="after"&&(s=l+a.nodeSize),t==="nested"){if(a.childCount<2){s=l+a.firstChild.nodeSize+1;const d=o.state.schema.nodes.blockGroup.create({},i);o.view.dispatch(o.state.tr.insert(s,d));return}s=l+a.firstChild.nodeSize+2}o.view.dispatch(o.state.tr.insert(s,i))}function fe(n,e,t){const o=typeof n=="string"?n:n.id,{posBeforeNode:r}=z(o,t.state.doc);t.commands.BNUpdateBlock(r+1,e)}function gt(n,e){const t=new Set(n.map(r=>typeof r=="string"?r:r.id));let o=0;if(e.state.doc.descendants((r,i)=>{if(t.size===0)return!1;if(r.type.name!=="blockContainer"||!t.has(r.attrs.id))return!0;t.delete(r.attrs.id);const s=e.state.doc.nodeSize;e.commands.BNDeleteBlock(i-o+1);const a=e.state.doc.nodeSize;return o+=s-a,!1}),t.size>0){let r=[...t].join(`
6
- `);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function me(n,e,t){mt(e,n[0],"before",t),gt(n,t)}function ge(){const n=e=>{let t=e.children.length;for(let o=0;o<t;o++){const r=e.children[o];if(r.type==="element"&&(n(r),r.tagName==="u"))if(r.children.length>0){e.children.splice(o,1,...r.children);const i=r.children.length-1;t+=i,o+=i}else e.children.splice(o,1),t--,o--}};return n}function ke(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{let r=o.children.length,i;for(let s=0;s<r;s++){const l=o.children[s].children[0],d=l.children[0],c=l.children.length===2?l.children[1]:null,u=e.has(d.properties.dataContentType),m=u?n.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(c!==null&&t(c),i&&i.tagName!==m){o.children.splice(s-i.children.length,i.children.length,i);const g=i.children.length-1;s-=g,r-=g,i=void 0}if(u){i||(i=G.fromDom(document.createElement(m)));const g=G.fromDom(document.createElement("li"));g.children.push(d.children[0]),c!==null&&g.children.push(...c.children),i.children.push(g)}else if(c!==null){o.children.splice(s+1,0,...c.children),o.children[s]=d.children[0];const g=c.children.length;s+=g,r+=g}else o.children[s]=d.children[0]}i&&o.children.splice(r-i.children.length,i.children.length,i)};return t}async function kt(n,e){const t=document.createElement("div"),o=E.DOMSerializer.fromSchema(e);for(const i of n){const s=H(i,e),a=o.serializeNode(s);t.appendChild(a)}return(await D.unified().use(W.default,{fragment:!0}).use(ke,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(Y.default).process(t.innerHTML)).value}async function yt(n,e,t){const o=document.createElement("div");o.innerHTML=n.trim();const i=E.DOMParser.fromSchema(t).parse(o),s=[];for(let a=0;a<i.firstChild.childCount;a++)s.push(M(i.firstChild.child(a),e));return s}async function ye(n,e){return(await D.unified().use(W.default,{fragment:!0}).use(ge).use(Yt.default).use(V.default).use(Xt.default).process(await kt(n,e))).value}async function be(n,e,t){const o=await D.unified().use(Vt.default).use(V.default).use(Jt.default).use(Y.default).process(n);return yt(o.value,e,t)}const N={bnEditor:"_bnEditor_4vj2p_3",bnRoot:"_bnRoot_4vj2p_20",defaultStyles:"_defaultStyles_4vj2p_35",dragPreview:"_dragPreview_4vj2p_68","collaboration-cursor__caret":"_collaboration-cursor__caret_4vj2p_74","collaboration-cursor__label":"_collaboration-cursor__label_4vj2p_85"},ve=h.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:"default",parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):"default",renderHTML:n=>n.backgroundColor!=="default"&&{"data-background-color":n.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(n,e)=>({state:t,view:o})=>{const r=b(t.doc,n);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"backgroundColor",e),o.focus(),!0)}}}}),Ee=h.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.color})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{color:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]},addCommands(){return{setBackgroundColor:n=>({commands:e})=>n!=="default"?e.setMark(this.name,{color:n}):e.unsetMark(this.name)}}}),bt=new k.PluginKey("previous-blocks"),Ce={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},xe=()=>{let n;return new k.Plugin({key:bt,view(e){return{update:async(t,o)=>{var r;((r=this.key)==null?void 0:r.getState(t.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(bt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,o,r){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||o.doc.eq(r.doc))return t;const i={},s=h.findChildren(o.doc,d=>d.attrs.id),a=new Map(s.map(d=>[d.node.attrs.id,d])),l=h.findChildren(r.doc,d=>d.attrs.id);for(let d of l){const c=a.get(d.node.attrs.id),u=c==null?void 0:c.node.firstChild,m=d.node.firstChild;if(c&&u&&m){const g={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:r.doc.resolve(d.pos).depth};let y={index:u.attrs.index,level:u.attrs.level,type:u.type.name,depth:o.doc.resolve(c.pos).depth};i[d.node.attrs.id]=y,e.getMeta("numberedListIndexing")&&(d.node.attrs.id in t.prevTransactionOldBlockAttrs&&(y=t.prevTransactionOldBlockAttrs[d.node.attrs.id]),g.type==="numberedListItem"&&(y.index=g.index)),t.currentTransactionOldBlockAttrs[d.node.attrs.id]=y,JSON.stringify(y)!==JSON.stringify(g)&&(y["depth-change"]=y.depth-g.depth,t.updatedBlocks.add(d.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=i,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const o=[];return e.doc.descendants((r,i)=>{if(!r.attrs.id||!t.updatedBlocks.has(r.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[r.attrs.id],a={};for(let[d,c]of Object.entries(s))a["data-prev-"+Ce[d]]=c||"none";const l=B.Decoration.node(i,i+r.nodeSize,{...a});o.push(l)}),B.DecorationSet.create(e.doc,o)}}})},Be={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Te=h.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const e={};for(let[t,o]of Object.entries(Be))n.getAttribute(o)&&(e[t]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:v.blockOuter,"data-node-type":"block-outer"}),["div",h.mergeAttributes(n,{class:v.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:n=>({state:e,dispatch:t})=>{const o=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:e,dispatch:t})=>{const o=b(e.doc,n);if(o===void 0)return!1;const{startPos:r,endPos:i}=o;return t&&e.tr.deleteRange(r,i),!0},BNUpdateBlock:(n,e)=>({state:t,dispatch:o})=>{const r=b(t.doc,n);if(r===void 0)return!1;const{startPos:i,endPos:s,node:a,contentNode:l}=r;if(o){if(e.children!==void 0){const d=[];for(const c of e.children)d.push(H(c,t.schema));a.childCount===2?t.tr.replace(i+l.nodeSize+1,s-1,new E.Slice(E.Fragment.from(d),0,0)):t.tr.insert(i+l.nodeSize,t.schema.nodes.blockGroup.create({},d))}if(e.content!==void 0){let d=[];typeof e.content=="string"?d.push(t.schema.text(e.content)):d=ft(e.content,t.schema),t.tr.replace(i+1,i+l.nodeSize-1,new E.Slice(E.Fragment.from(d),0,0))}t.tr.setNodeMarkup(i,e.type===void 0?void 0:t.schema.nodes[e.type],{...l.attrs,...e.props}),t.tr.setNodeMarkup(i-1,void 0,{...a.attrs,...e.props})}return!0},BNMergeBlocks:n=>({state:e,dispatch:t})=>{const o=e.doc.resolve(n+1).node().type.name==="blockContainer",r=e.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!r)return!1;const i=b(e.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:d,depth:c}=i;if(s.childCount===2){const g=e.doc.resolve(l+a.nodeSize+1),y=e.doc.resolve(d-1),x=g.blockRange(y);t&&e.tr.lift(x,c-1)}let u=n-1,m=b(e.doc,u);for(;m.numChildBlocks>0;)if(u--,m=b(e.doc,u),m===void 0)return!1;return t&&(e.tr.deleteRange(l,l+a.nodeSize),e.tr.insertText(a.textContent,u-1),e.tr.setSelection(new k.TextSelection(e.doc.resolve(u-1)))),!0},BNSplitBlock:(n,e)=>({state:t,dispatch:o})=>{const r=b(t.doc,n);if(r===void 0)return!1;const{contentNode:i,contentType:s,startPos:a,endPos:l,depth:d}=r,c=t.doc.cut(a+1,n),u=t.doc.cut(n,l-1),m=t.schema.nodes.blockContainer.createAndFill(),g=l+1,y=g+2;return o&&(t.tr.insert(g,m),t.tr.replace(y,y+1,u.content.size>0?new E.Slice(E.Fragment.from(u),d+2,d+2):void 0),e&&t.tr.setBlockType(y,y,t.schema.node(s).type,i.attrs),t.tr.setSelection(new k.TextSelection(t.doc.resolve(y))),t.tr.replace(a+1,l-1,c.content.size>0?new E.Slice(E.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[xe()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:o})=>{const{contentType:r}=b(o.doc,o.selection.from),i=o.selection.$anchor.parentOffset===0,s=r.name==="paragraph";return i&&!s?t.BNUpdateBlock(o.selection.from,{type:"paragraph",props:{}}):!1}),()=>t.command(({state:o})=>o.selection.$anchor.parentOffset===0?t.liftListItem("blockContainer"):!1),()=>t.command(({state:o})=>{const{depth:r,startPos:i}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,a=o.selection.anchor===o.selection.head,l=i===2,d=i-1;return!l&&s&&a&&r===2?t.BNMergeBlocks(d):!1})]),Enter:()=>this.editor.commands.first(({commands:t})=>[()=>t.command(({state:o})=>{const{node:r,depth:i}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,a=o.selection.anchor===o.selection.head,l=r.textContent.length===0,d=i>2;return s&&a&&l&&d?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:o,chain:r})=>{const{node:i,endPos:s}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,l=o.selection.anchor===o.selection.head,d=i.textContent.length===0;if(a&&l&&d){const c=s+1,u=c+2;return r().BNCreateBlock(c).setTextSelection(u).run(),!0}return!1}),()=>t.command(({state:o,chain:r})=>{const{node:i}=b(o.doc,o.selection.from);return i.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(o.selection.from,!1).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2),"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:"1"}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:"2"}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:"3"}}),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}}),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}}}),Me=h.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(this.options.HTMLAttributes,n,{class:v.blockGroup,"data-node-type":"blockGroup"}),0]}}),we=[Te,Me,h.Node.create({name:"doc",topNode:!0,content:"blockGroup"})],Se=n=>{const e=E.DOMSerializer.fromSchema(n);return new E.DOMSerializer({...e.nodes},e.marks)},vt=h.Extension.create({addProseMirrorPlugins(){return[new k.Plugin({props:{clipboardSerializer:Se(this.editor.schema)}})]}}),_e=h.findParentNode(n=>n.type.name==="blockContainer");function U(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}class Pe{constructor({editor:e,pluginKey:t,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");p(this,"handleScroll",()=>{this.pluginKey.getState(this.editor._tiptapEditor.state).active&&this.suggestionsMenu.render(this.getDynamicParams(),!1)});this.editor=e,this.pluginKey=t,this.pluginState=U(),this.itemCallback=i=>{e._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-this.pluginState.triggerCharacter.length,to:e._tiptapEditor.state.selection.from}).run(),o({item:i,editor:e})},this.suggestionsMenu=r(this.getStaticParams()),document.addEventListener("scroll",this.handleScroll)}update(e,t){const o=this.pluginKey.getState(t),r=this.pluginKey.getState(e.state),i=!o.active&&r.active,s=o.active&&!r.active,a=o.active&&r.active;!i&&!a&&!s||(this.pluginState=s?o:r,(s||!this.editor.isEditable)&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",l=>l.preventDefault())),a&&this.suggestionsMenu.render(this.getDynamicParams(),!1),i&&this.editor.isEditable&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",l=>l.preventDefault())))}destroy(){document.removeEventListener("scroll",this.handleScroll)}getStaticParams(){return{itemCallback:e=>this.itemCallback(e)}}getDynamicParams(){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);return{items:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex,referenceRect:e.getBoundingClientRect()}}}function Ie({pluginKey:n,editor:e,defaultTriggerCharacter:t,suggestionsMenuFactory:o,onSelectItem:r=()=>{},items:i=()=>[]}){if(t.length!==1)throw new Error("'char' should be a single character");const s=a=>{a.dispatch(a.state.tr.setMeta(n,{deactivate:!0}))};return new k.Plugin({key:n,view:a=>new Pe({editor:e,pluginKey:n,onSelectItem:l=>{s(a),r(l)},suggestionsMenuFactory:o}),state:{init(){return U()},apply(a,l,d,c){var m,g,y,x;if(a.getMeta("orderedListIndexing")!==void 0)return l;if((m=a.getMeta(n))!=null&&m.activate)return{active:!0,triggerCharacter:((g=a.getMeta(n))==null?void 0:g.triggerCharacter)||"",queryStartPos:c.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!l.active)return l;const u={...l};if(u.items=i(c.doc.textBetween(l.queryStartPos,c.selection.from)),u.notFoundCount=0,u.items.length===0&&(u.notFoundCount=Math.max(0,l.notFoundCount+(c.selection.from-d.selection.from))),c.selection.from!==c.selection.to||(y=a.getMeta(n))!=null&&y.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||l.active&&c.selection.from<l.queryStartPos||u.notFoundCount>3)return U();if(((x=a.getMeta(n))==null?void 0:x.selectedItemIndexChanged)!==void 0){let C=a.getMeta(n).selectedItemIndexChanged;C<0?C=l.items.length-1:C>=l.items.length&&(C=0),u.keyboardHoveredItemIndex=C}return u}},props:{handleKeyDown(a,l){const d=this.getState(a.state).active;if(l.key===t&&!d)return a.dispatch(a.state.tr.insertText(t).scrollIntoView().setMeta(n,{activate:!0,triggerCharacter:t})),!0;if(!d)return!1;const{triggerCharacter:c,queryStartPos:u,items:m,keyboardHoveredItemIndex:g}=n.getState(a.state);return l.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(n,{selectedItemIndexChanged:g-1})),!0):l.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(n,{selectedItemIndexChanged:g+1})),!0):l.key==="Enter"?(s(a),e._tiptapEditor.chain().focus().deleteRange({from:u-c.length,to:e._tiptapEditor.state.selection.from}).run(),r({item:m[g],editor:e}),!0):l.key==="Escape"?(s(a),!0):!1},handleClick(a){s(a)},decorations(a){const{active:l,decorationId:d,queryStartPos:c,triggerCharacter:u}=this.getState(a);if(!l)return null;if(u===""){const m=_e(a.selection);if(m)return B.DecorationSet.create(a.doc,[B.Decoration.node(m.pos,m.pos+m.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":d})])}return B.DecorationSet.create(a.doc,[B.Decoration.inline(c-u.length,c,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":d})])}}})}const q=new k.PluginKey("suggestions-slash-commands"),Ne=()=>h.Extension.create({name:"slash-command",addOptions(){return{editor:void 0,commands:void 0,slashMenuFactory:void 0}},addProseMirrorPlugins(){if(!this.options.slashMenuFactory||!this.options.commands)throw new Error("required args not defined for SlashMenuExtension");const n=this.options.commands;return[Ie({pluginKey:q,editor:this.options.editor,defaultTriggerCharacter:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:e=>n.filter(t=>t.match(e)),onSelectItem:({item:e,editor:t})=>{e.execute(t)}})]}});class A extends k.Selection{constructor(t,o){super(t,o);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(i,s,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(i),!1})}static create(t,o,r=o){return new A(t.resolve(o),t.resolve(r))}content(){return new E.Slice(E.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof A)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){let r=o.mapResult(this.from),i=o.mapResult(this.to);return i.deleted?k.Selection.near(t.resolve(r.pos)):r.deleted?k.Selection.near(t.resolve(i.pos)):new A(t.resolve(r.pos),t.resolve(i.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Ae=te.__serializeForClipboard;let w;function Et(n,e){var r;if(!e.dom.isConnected)return;let t=e.posAtCoords(n);if(!t)return;let o=e.domAtPos(t.pos).node;if(o!==e.dom){for(;o&&o.parentNode&&o.parentNode!==e.dom&&!((r=o.hasAttribute)!=null&&r.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function Le(n,e){let t=Et(n,e);if(t&&t.node.nodeType===1){const o=e.docView;let r=o.nearestDesc(t.node,!0);return!r||r===o?null:r.posBefore}return null}function He(n,e){let t,o;const r=e.resolve(n.from).node().type.spec.group==="blockContent",i=e.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(r&&i){const a=n.$from.start(s-1),l=n.$to.end(s-1);t=e.resolve(a-1).pos,o=e.resolve(l+1).pos}else t=n.from,o=n.to;return{from:t,to:o}}function Ct(n,e,t=e){e===t&&(t+=n.state.doc.resolve(e+1).node().nodeSize);const o=n.domAtPos(e).node.cloneNode(!0),r=n.domAtPos(e).node,i=(c,u)=>Array.prototype.indexOf.call(c.children,u),s=i(r,n.domAtPos(e+1).node.parentElement),a=i(r,n.domAtPos(t-1).node.parentElement);for(let c=r.childElementCount-1;c>=0;c--)(c>a||c<s)&&o.removeChild(o.children[c]);xt(),w=o;const d=n.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");w.className=w.className+" "+N.dragPreview+" "+d,document.body.appendChild(w)}function xt(){w!==void 0&&(document.body.removeChild(w),w=void 0)}function Oe(n,e){if(!n.dataTransfer)return;const t=e.dom.getBoundingClientRect();let o={left:t.left+t.width/2,top:n.clientY},r=Le(o,e);if(r!=null){const i=e.state.selection,s=e.state.doc,{from:a,to:l}=He(i,s),d=a<=r&&r<l,c=i.$anchor.node()!==i.$head.node()||i instanceof A;d&&c?(e.dispatch(e.state.tr.setSelection(A.create(s,a,l))),Ct(e,a,l)):(e.dispatch(e.state.tr.setSelection(k.NodeSelection.create(e.state.doc,r))),Ct(e,r));let u=e.state.selection.content(),{dom:m,text:g}=Ae(e,u);n.dataTransfer.clearData(),n.dataTransfer.setData("text/html",m.innerHTML),n.dataTransfer.setData("text/plain",g),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(w,0,0),e.dragging={slice:u,move:!0}}}class De{constructor({tiptapEditor:e,editor:t,blockMenuFactory:o,horizontalPosAnchoredAtRoot:r}){p(this,"editor");p(this,"ttEditor");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"blockMenu");p(this,"hoveredBlock");p(this,"isDragging",!1);p(this,"menuOpen",!1);p(this,"menuFrozen",!1);p(this,"onDragStart",()=>{this.isDragging=!0});p(this,"onDrop",e=>{if(e.synthetic||!this.isDragging)return;let t=this.ttEditor.view.posAtCoords({left:e.clientX,top:e.clientY});if(this.isDragging=!1,!t||t.inside===-1){const o=new Event("drop",e),r=this.ttEditor.view.dom.firstChild.getBoundingClientRect();o.clientX=r.left+r.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.ttEditor.view.dom.dispatchEvent(o)}});p(this,"onDragOver",e=>{if(e.synthetic||!this.isDragging)return;let t=this.ttEditor.view.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const o=new Event("dragover",e),r=this.ttEditor.view.dom.firstChild.getBoundingClientRect();o.clientX=r.left+r.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.ttEditor.view.dom.dispatchEvent(o)}});p(this,"onKeyDown",e=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1});p(this,"onMouseDown",e=>{var t;(t=this.blockMenu.element)!=null&&t.contains(e.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)});p(this,"onMouseMove",e=>{var l,d,c;if(this.menuFrozen)return;const t=this.ttEditor.view.dom.firstChild.getBoundingClientRect(),o=this.ttEditor.view.dom.getBoundingClientRect();if(e.clientX>=o.left&&e.clientX<=o.right&&e.clientY>=o.top&&e.clientY<=o.bottom&&e&&e.target&&this.ttEditor.view.dom!==e.target&&!this.ttEditor.view.dom.contains(e.target)&&this.blockMenu.element!==e.target&&!((l=this.blockMenu.element)!=null&&l.contains(e.target))){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}this.horizontalPosAnchor=t.x;const i={left:t.left+t.width/2,top:e.clientY},s=Et(i,this.ttEditor.view);if(!s||!this.editor.isEditable){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}this.menuOpen&&((d=this.hoveredBlock)!=null&&d.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===s.id||(this.hoveredBlock=s.node,!s.node.firstChild)||this.editor.isEditable&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))});p(this,"onScroll",()=>{const e=this.ttEditor.view.dom.firstChild.getBoundingClientRect();this.horizontalPosAnchor=e.x,this.menuOpen&&this.blockMenu.render(this.getDynamicParams(),!1)});this.editor=t,this.ttEditor=e,this.horizontalPosAnchoredAtRoot=r,this.horizontalPosAnchor=this.ttEditor.view.dom.firstChild.getBoundingClientRect().x,this.blockMenu=o(this.getStaticParams()),document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.ttEditor.view.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.ttEditor.view.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop),document.body.removeEventListener("mousedown",this.onMouseDown),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("keydown",this.onKeyDown)}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const t=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.ttEditor.view.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!o)return;const r=b(this.ttEditor.state.doc,o.pos);if(r===void 0)return;const{contentNode:i,endPos:s}=r;if(i.textContent.length!==0){const a=s+1,l=a+2;this.ttEditor.chain().BNCreateBlock(a).BNUpdateBlock(l,{type:"paragraph",props:{}}).setTextSelection(l).run()}else this.ttEditor.commands.setTextSelection(s);this.ttEditor.view.focus(),this.ttEditor.view.dispatch(this.ttEditor.view.state.tr.scrollIntoView().setMeta(q,{activate:!0,type:"drag"}))}getStaticParams(){return{editor:this.editor,addBlock:()=>this.addBlock(),blockDragStart:e=>{this.isDragging=!0,Oe(e,this.ttEditor.view)},blockDragEnd:()=>xt(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1}}}getDynamicParams(){const t=this.hoveredBlock.firstChild.getBoundingClientRect();return{block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id")),referenceRect:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:t.x,t.y,t.width,t.height)}}}const Fe=n=>new k.Plugin({key:new k.PluginKey("DraggableBlocksPlugin"),view:()=>new De({tiptapEditor:n.tiptapEditor,editor:n.editor,blockMenuFactory:n.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),Re=()=>h.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[Fe({tiptapEditor:this.editor,editor:this.options.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}});class ze{constructor({editor:e,tiptapEditor:t,formattingToolbarFactory:o,view:r}){p(this,"editor");p(this,"ttEditor");p(this,"view");p(this,"formattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"toolbarIsOpen",!1);p(this,"prevWasEditable",null);p(this,"shouldShow",({view:e,state:t,from:o,to:r})=>{const{doc:i,selection:s}=t,{empty:a}=s,l=!i.textBetween(o,r).length&&h.isTextSelection(t.selection);return!(!e.hasFocus()||a||l)});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.ttEditor.view))});p(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.ttEditor.view))});p(this,"blurHandler",({event:e})=>{var t;if(this.preventHide){this.preventHide=!1;return}e&&e.relatedTarget&&(this.formattingToolbar.element===e.relatedTarget||(t=this.formattingToolbar.element)!=null&&t.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});p(this,"scrollHandler",()=>{this.toolbarIsOpen&&this.formattingToolbar.render(this.getDynamicParams(),!1)});this.editor=e,this.ttEditor=t,this.view=r,this.formattingToolbar=o(this.getStaticParams()),this.view.dom.addEventListener("mousedown",this.viewMousedownHandler),this.view.dom.addEventListener("mouseup",this.viewMouseupHandler),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.ttEditor.on("focus",this.focusHandler),this.ttEditor.on("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var m;const{state:o,composing:r}=e,{doc:i,selection:s}=o,a=t&&t.doc.eq(i)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(r||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,d=Math.min(...l.map(g=>g.$from.pos)),c=Math.max(...l.map(g=>g.$to.pos)),u=(m=this.shouldShow)==null?void 0:m.call(this,{view:e,state:o,from:d,to:c});if(this.editor.isEditable&&!this.toolbarIsOpen&&!this.preventShow&&(u||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!0),this.toolbarIsOpen=!0;return}if(this.toolbarIsOpen&&!this.preventShow&&(u||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!u||this.preventShow||!this.editor.isEditable)){this.formattingToolbar.hide(),this.toolbarIsOpen=!1;return}}destroy(){this.view.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.view.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),this.ttEditor.off("focus",this.focusHandler),this.ttEditor.off("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:e}=this.ttEditor.view,{selection:t}=e,{ranges:o}=t,r=Math.min(...o.map(s=>s.$from.pos)),i=Math.max(...o.map(s=>s.$to.pos));if(h.isNodeSelection(t)){const s=this.ttEditor.view.nodeDOM(r);if(s)return s.getBoundingClientRect()}return h.posToDOMRect(this.ttEditor.view,r,i)}getStaticParams(){return{editor:this.editor}}getDynamicParams(){return{referenceRect:this.getSelectionBoundingBox()}}}const Ue=n=>new k.Plugin({key:new k.PluginKey("FormattingToolbarPlugin"),view:e=>new ze({view:e,...n})}),qe=()=>h.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory||!this.options.editor)throw new Error("required args not defined for FormattingToolbarExtension");return[Ue({tiptapEditor:this.editor,editor:this.options.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new k.PluginKey("FormattingToolbarPlugin")})]}}),je=new k.PluginKey("HyperlinkToolbarPlugin");class $e{constructor({editor:e,hyperlinkToolbarFactory:t}){p(this,"editor");p(this,"hyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");p(this,"mouseOverHandler",e=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),e.target instanceof HTMLAnchorElement&&e.target.nodeName==="A"){const t=e.target,o=this.editor.view.posAtDOM(t,0)+1,r=this.editor.state.doc.resolve(o),i=r.marks();for(const s of i)if(s.type.name===this.editor.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=h.getMarkRange(r,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",e=>{var t;this.hyperlinkMark&&e&&e.target&&this.editor.view.dom!==e.target&&!this.editor.view.dom.contains(e.target)&&this.hyperlinkToolbar.element!==e.target&&!((t=this.hyperlinkToolbar.element)!=null&&t.contains(e.target))&&this.hyperlinkToolbar.hide()});p(this,"scrollHandler",()=>{this.hyperlinkMark!==void 0&&this.hyperlinkToolbar.render(this.getDynamicParams(),!1)});this.editor=e,this.hyperlinkToolbar=t(this.getStaticParams()),this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.editor.view.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}update(){var t,o,r,i;if(!this.editor.view.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.editor.state.selection.empty){const s=this.editor.state.selection.$from.marks();for(const a of s)if(a.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=a,this.keyboardHoveredHyperlinkMarkRange=h.getMarkRange(this.editor.state.selection.$from,a.type,a.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(t=this.hyperlinkToolbar.element)==null||t.addEventListener("mouseleave",this.startMenuUpdateTimer),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1);return}if(e&&(!this.hyperlinkMark||!this.editor.isEditable)){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(i=this.hyperlinkToolbar.element)==null||i.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}destroy(){this.editor.view.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler)}getStaticParams(){return{editHyperlink:(e,t)=>{const o=this.editor.view.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.editor.schema.mark("link",{href:e})),this.editor.view.dispatch(o),this.editor.view.focus(),this.hyperlinkToolbar.hide()},deleteHyperlink:()=>{this.editor.view.dispatch(this.editor.view.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.editor.view.focus(),this.hyperlinkToolbar.hide()}}}getDynamicParams(){return{url:this.hyperlinkMark.attrs.href,text:this.editor.view.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),referenceRect:h.posToDOMRect(this.editor.view,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)}}}const Ge=(n,e)=>new k.Plugin({key:je,view:()=>new $e({editor:n,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),Ke=K.Link.extend({priority:500,addProseMirrorPlugins(){var n;if(!this.options.hyperlinkToolbarFactory)throw new Error("UI Element factory not defined for HyperlinkMark");return[...((n=this.parent)==null?void 0:n.call(this))||[],Ge(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),We=new k.PluginKey("blocknote-placeholder"),Ye=h.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new k.Plugin({key:We,props:{decorations:n=>{const{doc:e,selection:t}=n,o=q.getState(n),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,s=[];if(r)return e.descendants((a,l)=>{const d=i>=l&&i<=l+a.nodeSize,c=!a.isLeaf&&!a.childCount;if((d||!this.options.showOnlyCurrent)&&c){const u=[this.options.emptyNodeClass];this.editor.isEmpty&&u.push(this.options.emptyEditorClass),d&&u.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&u.push(this.options.isFilterClass);const m=B.Decoration.node(l,l+a.nodeSize,{class:u.join(" ")});s.push(m)}return this.options.includeChildren}),B.DecorationSet.create(e,s)}}})]}});class Ve{constructor(e,t){this.name=e,this.match=t}}class _ extends Ve{constructor(e,t,o=[]){super(e,r=>this.name.toLowerCase().startsWith(r.toLowerCase())||this.aliases.filter(i=>i.toLowerCase().startsWith(r.toLowerCase())).length!==0),this.name=e,this.execute=t,this.aliases=o}}function L(n,e){const t=n.getTextCursorPosition().block;t.content.length===1&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0?n.updateBlock(t,e):(n.insertBlocks([e],t,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock))}const Bt=[new _("Heading",n=>L(n,{type:"heading",props:{level:"1"}}),["h","heading1","h1"]),new _("Heading 2",n=>L(n,{type:"heading",props:{level:"2"}}),["h2","heading2","subheading"]),new _("Heading 3",n=>L(n,{type:"heading",props:{level:"3"}}),["h3","heading3","subheading"]),new _("Numbered List",n=>L(n,{type:"numberedListItem"}),["li","list","numberedlist","numbered list"]),new _("Bullet List",n=>L(n,{type:"bulletListItem"}),["ul","list","bulletlist","bullet list"]),new _("Paragraph",n=>L(n,{type:"paragraph"}),["p"])],Je=h.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]},addCommands(){return{setTextAlignment:n=>({state:e})=>{const t=[],o=b(e.doc,e.selection.from);if(o===void 0)return!1;let r=o.startPos;for(;r<e.selection.to;)e.doc.resolve(r).node().type.spec.group==="blockContent"?(t.push(r-1),r+=e.doc.resolve(r).node().nodeSize-1):r+=1;for(const i of t)e.tr.setNodeAttribute(i,"textAlignment",n);return!0}}}}),Xe=h.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:"default",parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):"default",renderHTML:n=>n.textColor!=="default"&&{"data-text-color":n.textColor}}}}]},addCommands(){return{setBlockTextColor:(n,e)=>({state:t,view:o})=>{const r=b(t.doc,n);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"textColor",e),o.focus(),!0)}}}}),Ze=h.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.color})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{color:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]},addCommands(){return{setTextColor:n=>({commands:e})=>n!=="default"?e.setMark(this.name,{color:n}):e.unsetMark(this.name)}}}),Qe=h.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(e,t,o)=>{const{doc:r,tr:i,schema:s}=o,a=n.getState(o),l=r.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(a)return i.insert(l,d.create(void 0,c.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let o=e.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");return o.nodeSize>4}}})]}}),Tt=n=>{const e=[h.extensions.ClipboardTextSerializer,h.extensions.Commands,h.extensions.Editable,h.extensions.FocusEvents,h.extensions.Tabindex,zt.Gapcursor,Ye.configure({emptyNodeClass:v.isEmpty,hasAnchorClass:v.hasAnchor,isFilterClass:v.isFilter,includeChildren:!0,showOnlyCurrent:!1}),R.configure({types:["blockContainer"]}),Ut.HardBreak,Gt.Text,Ht.Bold,Ot.Code,jt.Italic,$t.Strike,Kt.Underline,Ze,Xe,Ee,ve,Je,...we,...Object.values(n.blockSchema).map(t=>t.node.configure({editor:n.editor})),vt,Rt.Dropcursor.configure({width:5,color:"#ddeeff"}),Qe];if(n.collaboration){e.push(Zt.default.configure({fragment:n.collaboration.fragment}));const t=o=>{const r=document.createElement("span");r.classList.add(N["collaboration-cursor__caret"]),r.setAttribute("style",`border-color: ${o.color}`);const i=document.createElement("span");i.classList.add(N["collaboration-cursor__label"]),i.setAttribute("style",`background-color: ${o.color}`),i.insertBefore(document.createTextNode(o.name),null);const s=document.createTextNode("⁠"),a=document.createTextNode("⁠");return r.insertBefore(s,null),r.insertBefore(i,null),r.insertBefore(a,null),r};e.push(Qt.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||t,provider:n.collaboration.provider}))}else e.push(qt.History);return n.uiFactories.blockSideMenuFactory&&e.push(Re().configure({editor:n.editor,blockSideMenuFactory:n.uiFactories.blockSideMenuFactory})),n.uiFactories.formattingToolbarFactory&&e.push(qe().configure({editor:n.editor,formattingToolbarFactory:n.uiFactories.formattingToolbarFactory})),n.uiFactories.hyperlinkToolbarFactory?e.push(Ke.configure({hyperlinkToolbarFactory:n.uiFactories.hyperlinkToolbarFactory})):e.push(K.Link),n.uiFactories.slashMenuFactory&&e.push(Ne().configure({editor:n.editor,commands:n.slashCommands,slashMenuFactory:n.uiFactories.slashMenuFactory})),e},tn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class en{constructor(e={}){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);p(this,"schema");var i,s,a;this.options=e;const t={defaultStyles:!0,blockSchema:e.blockSchema||dt,...e},o=Tt({editor:this,uiFactories:t.uiFactories||{},slashCommands:t.slashCommands||Bt,blockSchema:t.blockSchema,collaboration:t.collaboration});this.schema=t.blockSchema;const r={...tn,...t._tiptapOptions,onCreate:()=>{var l;(l=t.onEditorReady)==null||l.call(t,this),t.initialContent&&this.replaceBlocks(this.topLevelBlocks,t.initialContent)},onUpdate:()=>{var l;(l=t.onEditorContentChange)==null||l.call(t,this)},onSelectionUpdate:()=>{var l;(l=t.onTextCursorPositionChange)==null||l.call(t,this)},editable:e.editable===void 0?!0:e.editable,extensions:t.enableBlockNoteExtensions===!1?(i=t._tiptapOptions)==null?void 0:i.extensions:[...((s=t._tiptapOptions)==null?void 0:s.extensions)||[],...o],editorProps:{attributes:{"data-theme":e.theme||"light",...t.editorDOMAttributes||{},class:[N.bnEditor,N.bnRoot,t.defaultStyles?N.defaultStyles:"",((a=t.editorDOMAttributes)==null?void 0:a.class)||""].join(" ")}}};t.parentElement&&(r.element=t.parentElement),this._tiptapEditor=new h.Editor(r)}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){const e=[];return this._tiptapEditor.state.doc.firstChild.descendants(t=>(e.push(M(t,this.schema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(r=>typeof o<"u"?!1:r.type.name!=="blockContainer"||r.attrs.id!==t?!0:(o=M(r,this.schema,this.blockCache),!1)),o}forEachBlock(e,t=!1){const o=this.topLevelBlocks.slice();t&&o.reverse();function r(i){for(const s of i){if(!e(s))return!1;const a=t?s.children.slice().reverse():s.children;if(!r(a))return!1}return!0}r(o)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:o,endPos:r}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),i=this._tiptapEditor.state.doc.resolve(r).index(t-1),s=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let a;i>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return i<s-1&&(l=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:M(e,this.schema,this.blockCache),prevBlock:a===void 0?void 0:M(a,this.schema,this.blockCache),nextBlock:l===void 0?void 0:M(l,this.schema,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:r}=z(o,this._tiptapEditor.state.doc),{startPos:i,contentNode:s}=b(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,o)=>t.type.spec.group!=="blockContent"||o+t.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(e.push(M(this._tiptapEditor.state.doc.resolve(o).node(),this.schema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,o="before"){mt(e,t,o,this._tiptapEditor)}updateBlock(e,t){fe(e,t,this._tiptapEditor)}removeBlocks(e){gt(e,this._tiptapEditor)}replaceBlocks(e,t){me(e,t,this._tiptapEditor)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks(),o=new Set(["bold","italic","underline","strike","code"]),r=new Set(["textColor","backgroundColor"]);for(const i of t)o.has(i.type.name)?e[i.type.name]=!0:r.has(i.type.name)&&(e[i.type.name]=i.attrs.color);return e}addStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),o=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.setMark(r):o.has(r)&&this._tiptapEditor.commands.setMark(r,{color:i})}removeStyles(e){this._tiptapEditor.view.focus();for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),o=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.toggleMark(r):o.has(r)&&this._tiptapEditor.commands.toggleMark(r,{color:i})}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(e,t){if(e==="")return;let{from:o,to:r}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(o,r));const i=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,o,r).addMark(o,o+t.length,i))}canNestBlock(){const{startPos:e,depth:t}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(e).index(t-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:e}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(e){return kt(e,this._tiptapEditor.schema)}async HTMLToBlocks(e){return yt(e,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(e){return ye(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return be(e,this.schema,this._tiptapEditor.schema)}updateCollaborationUserInfo(e){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(e)}}f.BaseSlashMenuItem=_,f.BlockNoteEditor=en,f.CustomBlockSerializerExtension=vt,f.blockStyles=ee,f.camelToDataKebab=F,f.createBlockSpec=ne,f.createTipTapBlock=P,f.defaultBlockSchema=dt,f.defaultProps=I,f.defaultSlashMenuItems=Bt,f.getBlockNoteExtensions=Tt,f.parse=st,f.propsToAttributes=it,f.render=at,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
5
+ `,styles:{}};return}const r={};let i;for(const s of o.marks)if(s.type.name==="link")i=s;else if(ct.has(s.type.name))r[s.type.name]=!0;else if(ut.has(s.type.name))r[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);t?t.type==="text"?i?(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]}):JSON.stringify(t.styles)===JSON.stringify(r)?t.text+=o.textContent:(e.push(t),t={type:"text",text:o.textContent,styles:r}):t.type==="link"&&(i?t.href===i.attrs.href?JSON.stringify(t.content[t.content.length-1].styles)===JSON.stringify(r)?t.content[t.content.length-1].text+=o.textContent:t.content.push({type:"text",text:o.textContent,styles:r}):(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]}):(e.push(t),t={type:"text",text:o.textContent,styles:r})):i?t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]}:t={type:"text",text:o.textContent,styles:r}}),t&&e.push(t),e}function T(n,e,t){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const o=t==null?void 0:t.get(n);if(o)return o;const r=b(n,0);let i=r.id;i===null&&(i=R.options.generateID());const s={};for(const[c,u]of Object.entries({...r.node.attrs,...r.contentNode.attrs})){const m=e[r.contentType.name];if(!m)throw Error("Block is of an unrecognized type: "+r.contentType.name);const g=m.propSchema;c in g?s[c]=u:c!=="id"&&!(c in I)&&console.warn("Block has an unrecognized attribute: "+c)}const a=pe(r.contentNode),l=[];for(let c=0;c<r.numChildBlocks;c++)l.push(T(r.node.lastChild.child(c),e,t));const d={id:i,type:r.contentType.name,props:s,content:a,children:l};return t==null||t.set(n,d),d}function z(n,e){let t,o;if(e.firstChild.descendants((r,i)=>t?!1:r.type.name!=="blockContainer"||r.attrs.id!==n?!0:(t=r,o=i+1,!1)),t===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:o}}function mt(n,e,t="before",o){const r=typeof e=="string"?e:e.id,i=[];for(const d of n)i.push(H(d,o.schema));let s=-1;const{node:a,posBeforeNode:l}=z(r,o.state.doc);if(t==="before"&&(s=l),t==="after"&&(s=l+a.nodeSize),t==="nested"){if(a.childCount<2){s=l+a.firstChild.nodeSize+1;const d=o.state.schema.nodes.blockGroup.create({},i);o.view.dispatch(o.state.tr.insert(s,d));return}s=l+a.firstChild.nodeSize+2}o.view.dispatch(o.state.tr.insert(s,i))}function fe(n,e,t){const o=typeof n=="string"?n:n.id,{posBeforeNode:r}=z(o,t.state.doc);t.commands.BNUpdateBlock(r+1,e)}function gt(n,e){const t=new Set(n.map(r=>typeof r=="string"?r:r.id));let o=0;if(e.state.doc.descendants((r,i)=>{if(t.size===0)return!1;if(r.type.name!=="blockContainer"||!t.has(r.attrs.id))return!0;t.delete(r.attrs.id);const s=e.state.doc.nodeSize;e.commands.BNDeleteBlock(i-o+1);const a=e.state.doc.nodeSize;return o+=s-a,!1}),t.size>0){let r=[...t].join(`
6
+ `);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function me(n,e,t){mt(e,n[0],"before",t),gt(n,t)}function ge(){const n=e=>{let t=e.children.length;for(let o=0;o<t;o++){const r=e.children[o];if(r.type==="element"&&(n(r),r.tagName==="u"))if(r.children.length>0){e.children.splice(o,1,...r.children);const i=r.children.length-1;t+=i,o+=i}else e.children.splice(o,1),t--,o--}};return n}function ke(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{let r=o.children.length,i;for(let s=0;s<r;s++){const l=o.children[s].children[0],d=l.children[0],c=l.children.length===2?l.children[1]:null,u=e.has(d.properties.dataContentType),m=u?n.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(c!==null&&t(c),i&&i.tagName!==m){o.children.splice(s-i.children.length,i.children.length,i);const g=i.children.length-1;s-=g,r-=g,i=void 0}if(u){i||(i=G.fromDom(document.createElement(m)));const g=G.fromDom(document.createElement("li"));g.children.push(d.children[0]),c!==null&&g.children.push(...c.children),i.children.push(g)}else if(c!==null){o.children.splice(s+1,0,...c.children),o.children[s]=d.children[0];const g=c.children.length;s+=g,r+=g}else o.children[s]=d.children[0]}i&&o.children.splice(r-i.children.length,i.children.length,i)};return t}async function kt(n,e){const t=document.createElement("div"),o=v.DOMSerializer.fromSchema(e);for(const i of n){const s=H(i,e),a=o.serializeNode(s);t.appendChild(a)}return(await D.unified().use(W.default,{fragment:!0}).use(ke,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(V.default).process(t.innerHTML)).value}async function yt(n,e,t){const o=document.createElement("div");o.innerHTML=n.trim();const i=v.DOMParser.fromSchema(t).parse(o),s=[];for(let a=0;a<i.firstChild.childCount;a++)s.push(T(i.firstChild.child(a),e));return s}async function ye(n,e){return(await D.unified().use(W.default,{fragment:!0}).use(ge).use(Vt.default).use(Y.default).use(Xt.default).process(await kt(n,e))).value}async function be(n,e,t){const o=await D.unified().use(Yt.default).use(Y.default).use(Jt.default).use(V.default).process(n);return yt(o.value,e,t)}const A={bnEditor:"_bnEditor_4vj2p_3",bnRoot:"_bnRoot_4vj2p_20",defaultStyles:"_defaultStyles_4vj2p_35",dragPreview:"_dragPreview_4vj2p_68","collaboration-cursor__caret":"_collaboration-cursor__caret_4vj2p_74","collaboration-cursor__label":"_collaboration-cursor__label_4vj2p_85"},ve=h.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:"default",parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):"default",renderHTML:n=>n.backgroundColor!=="default"&&{"data-background-color":n.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(n,e)=>({state:t,view:o})=>{const r=b(t.doc,n);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"backgroundColor",e),o.focus(),!0)}}}}),Ee=h.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.color})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{color:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]},addCommands(){return{setBackgroundColor:n=>({commands:e})=>n!=="default"?e.setMark(this.name,{color:n}):e.unsetMark(this.name)}}}),bt=new k.PluginKey("previous-blocks"),Ce={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},xe=()=>{let n;return new k.Plugin({key:bt,view(e){return{update:async(t,o)=>{var r;((r=this.key)==null?void 0:r.getState(t.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(bt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,o,r){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||o.doc.eq(r.doc))return t;const i={},s=h.findChildren(o.doc,d=>d.attrs.id),a=new Map(s.map(d=>[d.node.attrs.id,d])),l=h.findChildren(r.doc,d=>d.attrs.id);for(let d of l){const c=a.get(d.node.attrs.id),u=c==null?void 0:c.node.firstChild,m=d.node.firstChild;if(c&&u&&m){const g={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:r.doc.resolve(d.pos).depth};let y={index:u.attrs.index,level:u.attrs.level,type:u.type.name,depth:o.doc.resolve(c.pos).depth};i[d.node.attrs.id]=y,e.getMeta("numberedListIndexing")&&(d.node.attrs.id in t.prevTransactionOldBlockAttrs&&(y=t.prevTransactionOldBlockAttrs[d.node.attrs.id]),g.type==="numberedListItem"&&(y.index=g.index)),t.currentTransactionOldBlockAttrs[d.node.attrs.id]=y,JSON.stringify(y)!==JSON.stringify(g)&&(y["depth-change"]=y.depth-g.depth,t.updatedBlocks.add(d.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=i,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const o=[];return e.doc.descendants((r,i)=>{if(!r.attrs.id||!t.updatedBlocks.has(r.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[r.attrs.id],a={};for(let[d,c]of Object.entries(s))a["data-prev-"+Ce[d]]=c||"none";const l=B.Decoration.node(i,i+r.nodeSize,{...a});o.push(l)}),B.DecorationSet.create(e.doc,o)}}})},Be={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},we=h.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const e={};for(let[t,o]of Object.entries(Be))n.getAttribute(o)&&(e[t]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(n,{class:E.blockOuter,"data-node-type":"block-outer"}),["div",h.mergeAttributes(n,{class:E.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:n=>({state:e,dispatch:t})=>{const o=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:e,dispatch:t})=>{const o=b(e.doc,n);if(o===void 0)return!1;const{startPos:r,endPos:i}=o;return t&&e.tr.deleteRange(r,i),!0},BNUpdateBlock:(n,e)=>({state:t,dispatch:o})=>{const r=b(t.doc,n);if(r===void 0)return!1;const{startPos:i,endPos:s,node:a,contentNode:l}=r;if(o){if(e.children!==void 0){const d=[];for(const c of e.children)d.push(H(c,t.schema));a.childCount===2?t.tr.replace(i+l.nodeSize+1,s-1,new v.Slice(v.Fragment.from(d),0,0)):t.tr.insert(i+l.nodeSize,t.schema.nodes.blockGroup.create({},d))}if(e.content!==void 0){let d=[];typeof e.content=="string"?d.push(t.schema.text(e.content)):d=ft(e.content,t.schema),t.tr.replace(i+1,i+l.nodeSize-1,new v.Slice(v.Fragment.from(d),0,0))}t.tr.setNodeMarkup(i,e.type===void 0?void 0:t.schema.nodes[e.type],{...l.attrs,...e.props}),t.tr.setNodeMarkup(i-1,void 0,{...a.attrs,...e.props})}return!0},BNMergeBlocks:n=>({state:e,dispatch:t})=>{const o=e.doc.resolve(n+1).node().type.name==="blockContainer",r=e.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!r)return!1;const i=b(e.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:d,depth:c}=i;if(s.childCount===2){const g=e.doc.resolve(l+a.nodeSize+1),y=e.doc.resolve(d-1),x=g.blockRange(y);t&&e.tr.lift(x,c-1)}let u=n-1,m=b(e.doc,u);for(;m.numChildBlocks>0;)if(u--,m=b(e.doc,u),m===void 0)return!1;return t&&(t(e.tr.deleteRange(l,l+a.nodeSize).replace(u-1,l,new v.Slice(a.content,0,0)).scrollIntoView()),e.tr.setSelection(new k.TextSelection(e.doc.resolve(u-1)))),!0},BNSplitBlock:(n,e)=>({state:t,dispatch:o})=>{const r=b(t.doc,n);if(r===void 0)return!1;const{contentNode:i,contentType:s,startPos:a,endPos:l,depth:d}=r,c=t.doc.cut(a+1,n),u=t.doc.cut(n,l-1),m=t.schema.nodes.blockContainer.createAndFill(),g=l+1,y=g+2;return o&&(t.tr.insert(g,m),t.tr.replace(y,y+1,u.content.size>0?new v.Slice(v.Fragment.from(u),d+2,d+2):void 0),e&&t.tr.setBlockType(y,y,t.schema.node(s).type,i.attrs),t.tr.setSelection(new k.TextSelection(t.doc.resolve(y))),t.tr.replace(a+1,l-1,c.content.size>0?new v.Slice(v.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[xe()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:o})=>{const{contentType:r}=b(o.doc,o.selection.from),i=o.selection.$anchor.parentOffset===0,s=r.name==="paragraph";return i&&!s?t.BNUpdateBlock(o.selection.from,{type:"paragraph",props:{}}):!1}),()=>t.command(({state:o})=>o.selection.$anchor.parentOffset===0?t.liftListItem("blockContainer"):!1),()=>t.command(({state:o})=>{const{depth:r,startPos:i}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,a=o.selection.anchor===o.selection.head,l=i===2,d=i-1;return!l&&s&&a&&r===2?t.BNMergeBlocks(d):!1})]),Enter:()=>this.editor.commands.first(({commands:t})=>[()=>t.command(({state:o})=>{const{node:r,depth:i}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,a=o.selection.anchor===o.selection.head,l=r.textContent.length===0,d=i>2;return s&&a&&l&&d?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:o,chain:r})=>{const{node:i,endPos:s}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,l=o.selection.anchor===o.selection.head,d=i.textContent.length===0;if(a&&l&&d){const c=s+1,u=c+2;return r().BNCreateBlock(c).setTextSelection(u).run(),!0}return!1}),()=>t.command(({state:o,chain:r})=>{const{node:i}=b(o.doc,o.selection.from);return i.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(o.selection.from,!1).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2),"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:"1"}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:"2"}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:"3"}}),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}}),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}}}),Te=h.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){return["div",h.mergeAttributes(this.options.HTMLAttributes,n,{class:E.blockGroup,"data-node-type":"blockGroup"}),0]}}),Me=[we,Te,h.Node.create({name:"doc",topNode:!0,content:"blockGroup"})],Se=n=>{const e=v.DOMSerializer.fromSchema(n);return new v.DOMSerializer({...e.nodes},e.marks)},vt=h.Extension.create({addProseMirrorPlugins(){return[new k.Plugin({props:{clipboardSerializer:Se(this.editor.schema)}})]}}),Pe=h.findParentNode(n=>n.type.name==="blockContainer");function U(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}class _e{constructor({editor:e,pluginKey:t,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");p(this,"lastPosition");this.editor=e,this.pluginKey=t,this.pluginState=U(),this.itemCallback=i=>{e._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-this.pluginState.triggerCharacter.length,to:e._tiptapEditor.state.selection.from}).run(),o({item:i,editor:e})},this.suggestionsMenu=r(this.getStaticParams())}update(e,t){const o=this.pluginKey.getState(t),r=this.pluginKey.getState(e.state),i=!o.active&&r.active,s=o.active&&!r.active,a=o.active&&r.active;!i&&!a&&!s||(this.pluginState=s?o:r,(s||!this.editor.isEditable)&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",l=>l.preventDefault())),a&&this.suggestionsMenu.render(this.getDynamicParams(),!1),i&&this.editor.isEditable&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",l=>l.preventDefault())))}getStaticParams(){return{itemCallback:e=>this.itemCallback(e),getReferenceRect:()=>{const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!e){if(this.lastPosition===void 0)throw new Error("Attempted to access trigger character reference rect before rendering suggestions menu.");return this.lastPosition}const t=e.getBoundingClientRect();return this.lastPosition=t,t}}}getDynamicParams(){return{items:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex}}}function Ie({pluginKey:n,editor:e,defaultTriggerCharacter:t,suggestionsMenuFactory:o,onSelectItem:r=()=>{},items:i=()=>[]}){if(t.length!==1)throw new Error("'char' should be a single character");const s=a=>{a.dispatch(a.state.tr.setMeta(n,{deactivate:!0}))};return new k.Plugin({key:n,view:a=>new _e({editor:e,pluginKey:n,onSelectItem:l=>{s(a),r(l)},suggestionsMenuFactory:o}),state:{init(){return U()},apply(a,l,d,c){var m,g,y,x;if(a.getMeta("orderedListIndexing")!==void 0)return l;if((m=a.getMeta(n))!=null&&m.activate)return{active:!0,triggerCharacter:((g=a.getMeta(n))==null?void 0:g.triggerCharacter)||"",queryStartPos:c.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!l.active)return l;const u={...l};if(u.items=i(c.doc.textBetween(l.queryStartPos,c.selection.from)),u.notFoundCount=0,u.items.length===0&&(u.notFoundCount=Math.max(0,l.notFoundCount+(c.selection.from-d.selection.from))),c.selection.from!==c.selection.to||(y=a.getMeta(n))!=null&&y.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||l.active&&c.selection.from<l.queryStartPos||u.notFoundCount>3)return U();if(((x=a.getMeta(n))==null?void 0:x.selectedItemIndexChanged)!==void 0){let C=a.getMeta(n).selectedItemIndexChanged;C<0?C=l.items.length-1:C>=l.items.length&&(C=0),u.keyboardHoveredItemIndex=C}return u}},props:{handleKeyDown(a,l){const d=this.getState(a.state).active;if(l.key===t&&!d)return a.dispatch(a.state.tr.insertText(t).scrollIntoView().setMeta(n,{activate:!0,triggerCharacter:t})),!0;if(!d)return!1;const{triggerCharacter:c,queryStartPos:u,items:m,keyboardHoveredItemIndex:g}=n.getState(a.state);return l.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(n,{selectedItemIndexChanged:g-1})),!0):l.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(n,{selectedItemIndexChanged:g+1})),!0):l.key==="Enter"?(s(a),e._tiptapEditor.chain().focus().deleteRange({from:u-c.length,to:e._tiptapEditor.state.selection.from}).run(),r({item:m[g],editor:e}),!0):l.key==="Escape"?(s(a),!0):!1},handleClick(a){s(a)},decorations(a){const{active:l,decorationId:d,queryStartPos:c,triggerCharacter:u}=this.getState(a);if(!l)return null;if(u===""){const m=Pe(a.selection);if(m)return B.DecorationSet.create(a.doc,[B.Decoration.node(m.pos,m.pos+m.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":d})])}return B.DecorationSet.create(a.doc,[B.Decoration.inline(c-u.length,c,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":d})])}}})}const q=new k.PluginKey("suggestions-slash-commands"),Ae=()=>h.Extension.create({name:"slash-command",addOptions(){return{editor:void 0,commands:void 0,slashMenuFactory:void 0}},addProseMirrorPlugins(){if(!this.options.slashMenuFactory||!this.options.commands)throw new Error("required args not defined for SlashMenuExtension");const n=this.options.commands;return[Ie({pluginKey:q,editor:this.options.editor,defaultTriggerCharacter:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:e=>n.filter(t=>t.match(e)),onSelectItem:({item:e,editor:t})=>{e.execute(t)}})]}});class N extends k.Selection{constructor(t,o){super(t,o);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(i,s,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(i),!1})}static create(t,o,r=o){return new N(t.resolve(o),t.resolve(r))}content(){return new v.Slice(v.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof N)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){let r=o.mapResult(this.from),i=o.mapResult(this.to);return i.deleted?k.Selection.near(t.resolve(r.pos)):r.deleted?k.Selection.near(t.resolve(i.pos)):new N(t.resolve(r.pos),t.resolve(i.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Ne=te.__serializeForClipboard;let M;function Et(n,e){var r;if(!e.dom.isConnected)return;let t=e.posAtCoords(n);if(!t)return;let o=e.domAtPos(t.pos).node;if(o!==e.dom){for(;o&&o.parentNode&&o.parentNode!==e.dom&&!((r=o.hasAttribute)!=null&&r.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function Le(n,e){let t=Et(n,e);if(t&&t.node.nodeType===1){const o=e.docView;let r=o.nearestDesc(t.node,!0);return!r||r===o?null:r.posBefore}return null}function He(n,e){let t,o;const r=e.resolve(n.from).node().type.spec.group==="blockContent",i=e.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(r&&i){const a=n.$from.start(s-1),l=n.$to.end(s-1);t=e.resolve(a-1).pos,o=e.resolve(l+1).pos}else t=n.from,o=n.to;return{from:t,to:o}}function Ct(n,e,t=e){e===t&&(t+=n.state.doc.resolve(e+1).node().nodeSize);const o=n.domAtPos(e).node.cloneNode(!0),r=n.domAtPos(e).node,i=(c,u)=>Array.prototype.indexOf.call(c.children,u),s=i(r,n.domAtPos(e+1).node.parentElement),a=i(r,n.domAtPos(t-1).node.parentElement);for(let c=r.childElementCount-1;c>=0;c--)(c>a||c<s)&&o.removeChild(o.children[c]);xt(),M=o;const d=n.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");M.className=M.className+" "+A.dragPreview+" "+d,document.body.appendChild(M)}function xt(){M!==void 0&&(document.body.removeChild(M),M=void 0)}function Oe(n,e){if(!n.dataTransfer)return;const t=e.dom.getBoundingClientRect();let o={left:t.left+t.width/2,top:n.clientY},r=Le(o,e);if(r!=null){const i=e.state.selection,s=e.state.doc,{from:a,to:l}=He(i,s),d=a<=r&&r<l,c=i.$anchor.node()!==i.$head.node()||i instanceof N;d&&c?(e.dispatch(e.state.tr.setSelection(N.create(s,a,l))),Ct(e,a,l)):(e.dispatch(e.state.tr.setSelection(k.NodeSelection.create(e.state.doc,r))),Ct(e,r));let u=e.state.selection.content(),{dom:m,text:g}=Ne(e,u);n.dataTransfer.clearData(),n.dataTransfer.setData("text/html",m.innerHTML),n.dataTransfer.setData("text/plain",g),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(M,0,0),e.dragging={slice:u,move:!0}}}class De{constructor({tiptapEditor:e,editor:t,blockMenuFactory:o,horizontalPosAnchoredAtRoot:r}){p(this,"editor");p(this,"ttEditor");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"blockMenu");p(this,"hoveredBlock");p(this,"isDragging",!1);p(this,"menuOpen",!1);p(this,"menuFrozen",!1);p(this,"lastPosition");p(this,"onDragStart",()=>{this.isDragging=!0});p(this,"onDrop",e=>{if(e.synthetic||!this.isDragging)return;let t=this.ttEditor.view.posAtCoords({left:e.clientX,top:e.clientY});if(this.isDragging=!1,!t||t.inside===-1){const o=new Event("drop",e),r=this.ttEditor.view.dom.firstChild.getBoundingClientRect();o.clientX=r.left+r.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.ttEditor.view.dom.dispatchEvent(o)}});p(this,"onDragOver",e=>{if(e.synthetic||!this.isDragging)return;let t=this.ttEditor.view.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const o=new Event("dragover",e),r=this.ttEditor.view.dom.firstChild.getBoundingClientRect();o.clientX=r.left+r.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.ttEditor.view.dom.dispatchEvent(o)}});p(this,"onKeyDown",e=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1});p(this,"onMouseDown",e=>{var t;(t=this.blockMenu.element)!=null&&t.contains(e.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)});p(this,"onMouseMove",e=>{var l,d,c;if(this.menuFrozen)return;const t=this.ttEditor.view.dom.firstChild.getBoundingClientRect(),o=this.ttEditor.view.dom.getBoundingClientRect();if(e.clientX>=o.left&&e.clientX<=o.right&&e.clientY>=o.top&&e.clientY<=o.bottom&&e&&e.target&&this.ttEditor.view.dom!==e.target&&!this.ttEditor.view.dom.contains(e.target)&&this.blockMenu.element!==e.target&&!((l=this.blockMenu.element)!=null&&l.contains(e.target))){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}this.horizontalPosAnchor=t.x;const i={left:t.left+t.width/2,top:e.clientY},s=Et(i,this.ttEditor.view);if(!s||!this.editor.isEditable){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}this.menuOpen&&((d=this.hoveredBlock)!=null&&d.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===s.id||(this.hoveredBlock=s.node,!s.node.firstChild)||this.editor.isEditable&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))});this.editor=t,this.ttEditor=e,this.horizontalPosAnchoredAtRoot=r,this.horizontalPosAnchor=this.ttEditor.view.dom.firstChild.getBoundingClientRect().x,this.blockMenu=o(this.getStaticParams()),document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.ttEditor.view.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.ttEditor.view.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop),document.body.removeEventListener("mousedown",this.onMouseDown),document.body.removeEventListener("keydown",this.onKeyDown)}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const t=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.ttEditor.view.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!o)return;const r=b(this.ttEditor.state.doc,o.pos);if(r===void 0)return;const{contentNode:i,endPos:s}=r;if(i.textContent.length!==0){const a=s+1,l=a+2;this.ttEditor.chain().BNCreateBlock(a).BNUpdateBlock(l,{type:"paragraph",props:{}}).setTextSelection(l).run()}else this.ttEditor.commands.setTextSelection(s);this.ttEditor.view.focus(),this.ttEditor.view.dispatch(this.ttEditor.view.state.tr.scrollIntoView().setMeta(q,{activate:!0,type:"drag"}))}getStaticParams(){return{editor:this.editor,addBlock:()=>this.addBlock(),blockDragStart:e=>{this.isDragging=!0,Oe(e,this.ttEditor.view)},blockDragEnd:()=>xt(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1},getReferenceRect:()=>{if(!this.menuOpen){if(this.lastPosition===void 0)throw new Error("Attempted to access block reference rect before rendering block side menu.");return this.lastPosition}const t=this.hoveredBlock.firstChild.getBoundingClientRect();return this.horizontalPosAnchoredAtRoot&&(t.x=this.horizontalPosAnchor),this.lastPosition=t,t}}}getDynamicParams(){return{block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))}}}const Fe=n=>new k.Plugin({key:new k.PluginKey("DraggableBlocksPlugin"),view:()=>new De({tiptapEditor:n.tiptapEditor,editor:n.editor,blockMenuFactory:n.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),Re=()=>h.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[Fe({tiptapEditor:this.editor,editor:this.options.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}});class ze{constructor({editor:e,tiptapEditor:t,formattingToolbarFactory:o,view:r}){p(this,"editor");p(this,"ttEditor");p(this,"view");p(this,"formattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"toolbarIsOpen",!1);p(this,"prevWasEditable",null);p(this,"lastPosition");p(this,"shouldShow",({view:e,state:t,from:o,to:r})=>{const{doc:i,selection:s}=t,{empty:a}=s,l=!i.textBetween(o,r).length&&h.isTextSelection(t.selection);return!(!e.hasFocus()||a||l)});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.ttEditor.view))});p(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.ttEditor.view))});p(this,"blurHandler",({event:e})=>{var t;if(this.preventHide){this.preventHide=!1;return}e&&e.relatedTarget&&(this.formattingToolbar.element===e.relatedTarget||(t=this.formattingToolbar.element)!=null&&t.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});this.editor=e,this.ttEditor=t,this.view=r,this.formattingToolbar=o(this.getStaticParams()),this.view.dom.addEventListener("mousedown",this.viewMousedownHandler),this.view.dom.addEventListener("mouseup",this.viewMouseupHandler),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.ttEditor.on("focus",this.focusHandler),this.ttEditor.on("blur",this.blurHandler)}update(e,t){var m;const{state:o,composing:r}=e,{doc:i,selection:s}=o,a=t&&t.doc.eq(i)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(r||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,d=Math.min(...l.map(g=>g.$from.pos)),c=Math.max(...l.map(g=>g.$to.pos)),u=(m=this.shouldShow)==null?void 0:m.call(this,{view:e,state:o,from:d,to:c});if(this.editor.isEditable&&!this.toolbarIsOpen&&!this.preventShow&&(u||this.preventHide)){this.formattingToolbar.render({},!0),this.toolbarIsOpen=!0;return}if(this.toolbarIsOpen&&!this.preventShow&&(u||this.preventHide)){this.formattingToolbar.render({},!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!u||this.preventShow||!this.editor.isEditable)){this.formattingToolbar.hide(),this.toolbarIsOpen=!1;return}}destroy(){this.view.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.view.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),this.ttEditor.off("focus",this.focusHandler),this.ttEditor.off("blur",this.blurHandler)}getSelectionBoundingBox(){const{state:e}=this.ttEditor.view,{selection:t}=e,{ranges:o}=t,r=Math.min(...o.map(s=>s.$from.pos)),i=Math.max(...o.map(s=>s.$to.pos));if(h.isNodeSelection(t)){const s=this.ttEditor.view.nodeDOM(r);if(s)return s.getBoundingClientRect()}return h.posToDOMRect(this.ttEditor.view,r,i)}getStaticParams(){return{editor:this.editor,getReferenceRect:()=>{if(!this.toolbarIsOpen){if(this.lastPosition===void 0)throw new Error("Attempted to access selection reference rect before rendering formatting toolbar.");return this.lastPosition}const e=this.getSelectionBoundingBox();return this.lastPosition=e,e}}}}const Ue=n=>new k.Plugin({key:new k.PluginKey("FormattingToolbarPlugin"),view:e=>new ze({view:e,...n})}),qe=()=>h.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory||!this.options.editor)throw new Error("required args not defined for FormattingToolbarExtension");return[Ue({tiptapEditor:this.editor,editor:this.options.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new k.PluginKey("FormattingToolbarPlugin")})]}}),je=new k.PluginKey("HyperlinkToolbarPlugin");class $e{constructor({editor:e,hyperlinkToolbarFactory:t}){p(this,"editor");p(this,"hyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");p(this,"lastPosition");p(this,"mouseOverHandler",e=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),e.target instanceof HTMLAnchorElement&&e.target.nodeName==="A"){const t=e.target,o=this.editor.view.posAtDOM(t,0)+1,r=this.editor.state.doc.resolve(o),i=r.marks();for(const s of i)if(s.type.name===this.editor.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=h.getMarkRange(r,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",e=>{var t;this.hyperlinkMark&&e&&e.target&&this.editor.view.dom!==e.target&&!this.editor.view.dom.contains(e.target)&&this.hyperlinkToolbar.element!==e.target&&!((t=this.hyperlinkToolbar.element)!=null&&t.contains(e.target))&&this.hyperlinkToolbar.hide()});this.editor=e,this.hyperlinkToolbar=t(this.getStaticParams()),this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.editor.view.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0)}update(){var t,o,r,i;if(!this.editor.view.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.editor.state.selection.empty){const s=this.editor.state.selection.$from.marks();for(const a of s)if(a.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=a,this.keyboardHoveredHyperlinkMarkRange=h.getMarkRange(this.editor.state.selection.$from,a.type,a.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(t=this.hyperlinkToolbar.element)==null||t.addEventListener("mouseleave",this.startMenuUpdateTimer),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1);return}if(e&&(!this.hyperlinkMark||!this.editor.isEditable)){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(i=this.hyperlinkToolbar.element)==null||i.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}destroy(){this.editor.view.dom.removeEventListener("mouseover",this.mouseOverHandler)}getStaticParams(){return{editHyperlink:(e,t)=>{const o=this.editor.view.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.editor.schema.mark("link",{href:e})),this.editor.view.dispatch(o),this.editor.view.focus(),this.hyperlinkToolbar.hide()},deleteHyperlink:()=>{this.editor.view.dispatch(this.editor.view.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.editor.view.focus(),this.hyperlinkToolbar.hide()},getReferenceRect:()=>{if(!this.hyperlinkMark){if(this.lastPosition===void 0)throw new Error("Attempted to access hyperlink reference rect before rendering hyperlink toolbar.");return this.lastPosition}const e=h.posToDOMRect(this.editor.view,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);return this.lastPosition=e,e}}}getDynamicParams(){return{url:this.hyperlinkMark.attrs.href,text:this.editor.view.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)}}}const Ge=(n,e)=>new k.Plugin({key:je,view:()=>new $e({editor:n,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),Ke=K.Link.extend({priority:500,addProseMirrorPlugins(){var n;if(!this.options.hyperlinkToolbarFactory)throw new Error("UI Element factory not defined for HyperlinkMark");return[...((n=this.parent)==null?void 0:n.call(this))||[],Ge(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),We=new k.PluginKey("blocknote-placeholder"),Ve=h.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new k.Plugin({key:We,props:{decorations:n=>{const{doc:e,selection:t}=n,o=q.getState(n),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,s=[];if(r)return e.descendants((a,l)=>{const d=i>=l&&i<=l+a.nodeSize,c=!a.isLeaf&&!a.childCount;if((d||!this.options.showOnlyCurrent)&&c){const u=[this.options.emptyNodeClass];this.editor.isEmpty&&u.push(this.options.emptyEditorClass),d&&u.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&u.push(this.options.isFilterClass);const m=B.Decoration.node(l,l+a.nodeSize,{class:u.join(" ")});s.push(m)}return this.options.includeChildren}),B.DecorationSet.create(e,s)}}})]}});class Ye{constructor(e,t){this.name=e,this.match=t}}class P extends Ye{constructor(e,t,o=[]){super(e,r=>this.name.toLowerCase().startsWith(r.toLowerCase())||this.aliases.filter(i=>i.toLowerCase().startsWith(r.toLowerCase())).length!==0),this.name=e,this.execute=t,this.aliases=o}}function L(n,e){const t=n.getTextCursorPosition().block;t.content.length===1&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0?n.updateBlock(t,e):(n.insertBlocks([e],t,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock))}const Bt=[new P("Heading",n=>L(n,{type:"heading",props:{level:"1"}}),["h","heading1","h1"]),new P("Heading 2",n=>L(n,{type:"heading",props:{level:"2"}}),["h2","heading2","subheading"]),new P("Heading 3",n=>L(n,{type:"heading",props:{level:"3"}}),["h3","heading3","subheading"]),new P("Numbered List",n=>L(n,{type:"numberedListItem"}),["li","list","numberedlist","numbered list"]),new P("Bullet List",n=>L(n,{type:"bulletListItem"}),["ul","list","bulletlist","bullet list"]),new P("Paragraph",n=>L(n,{type:"paragraph"}),["p"])],Je=h.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]},addCommands(){return{setTextAlignment:n=>({state:e})=>{const t=[],o=b(e.doc,e.selection.from);if(o===void 0)return!1;let r=o.startPos;for(;r<e.selection.to;)e.doc.resolve(r).node().type.spec.group==="blockContent"?(t.push(r-1),r+=e.doc.resolve(r).node().nodeSize-1):r+=1;for(const i of t)e.tr.setNodeAttribute(i,"textAlignment",n);return!0}}}}),Xe=h.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:"default",parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):"default",renderHTML:n=>n.textColor!=="default"&&{"data-text-color":n.textColor}}}}]},addCommands(){return{setBlockTextColor:(n,e)=>({state:t,view:o})=>{const r=b(t.doc,n);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"textColor",e),o.focus(),!0)}}}}),Ze=h.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.color})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{color:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]},addCommands(){return{setTextColor:n=>({commands:e})=>n!=="default"?e.setMark(this.name,{color:n}):e.unsetMark(this.name)}}}),Qe=h.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(e,t,o)=>{const{doc:r,tr:i,schema:s}=o,a=n.getState(o),l=r.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(a)return i.insert(l,d.create(void 0,c.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let o=e.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");return o.nodeSize>4}}})]}}),wt=n=>{const e=[h.extensions.ClipboardTextSerializer,h.extensions.Commands,h.extensions.Editable,h.extensions.FocusEvents,h.extensions.Tabindex,zt.Gapcursor,Ve.configure({emptyNodeClass:E.isEmpty,hasAnchorClass:E.hasAnchor,isFilterClass:E.isFilter,includeChildren:!0,showOnlyCurrent:!1}),R.configure({types:["blockContainer"]}),Ut.HardBreak,Gt.Text,Ht.Bold,Ot.Code,jt.Italic,$t.Strike,Kt.Underline,Ze,Xe,Ee,ve,Je,...Me,...Object.values(n.blockSchema).map(t=>t.node.configure({editor:n.editor})),vt,Rt.Dropcursor.configure({width:5,color:"#ddeeff"}),Qe];if(n.collaboration){e.push(Zt.default.configure({fragment:n.collaboration.fragment}));const t=o=>{const r=document.createElement("span");r.classList.add(A["collaboration-cursor__caret"]),r.setAttribute("style",`border-color: ${o.color}`);const i=document.createElement("span");i.classList.add(A["collaboration-cursor__label"]),i.setAttribute("style",`background-color: ${o.color}`),i.insertBefore(document.createTextNode(o.name),null);const s=document.createTextNode("⁠"),a=document.createTextNode("⁠");return r.insertBefore(s,null),r.insertBefore(i,null),r.insertBefore(a,null),r};e.push(Qt.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||t,provider:n.collaboration.provider}))}else e.push(qt.History);return n.uiFactories.blockSideMenuFactory&&e.push(Re().configure({editor:n.editor,blockSideMenuFactory:n.uiFactories.blockSideMenuFactory})),n.uiFactories.formattingToolbarFactory&&e.push(qe().configure({editor:n.editor,formattingToolbarFactory:n.uiFactories.formattingToolbarFactory})),n.uiFactories.hyperlinkToolbarFactory?e.push(Ke.configure({hyperlinkToolbarFactory:n.uiFactories.hyperlinkToolbarFactory})):e.push(K.Link),n.uiFactories.slashMenuFactory&&e.push(Ae().configure({editor:n.editor,commands:n.slashCommands,slashMenuFactory:n.uiFactories.slashMenuFactory})),e},tn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class en{constructor(e={}){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);p(this,"schema");p(this,"ready",!1);var i,s,a;this.options=e;const t={defaultStyles:!0,blockSchema:e.blockSchema||dt,...e},o=wt({editor:this,uiFactories:t.uiFactories||{},slashCommands:t.slashCommands||Bt,blockSchema:t.blockSchema,collaboration:t.collaboration});this.schema=t.blockSchema;const r={...tn,...t._tiptapOptions,onCreate:()=>{var l;(l=t.onEditorReady)==null||l.call(t,this),t.initialContent&&this.replaceBlocks(this.topLevelBlocks,t.initialContent),this.ready=!0},onUpdate:()=>{var l;this.ready&&((l=t.onEditorContentChange)==null||l.call(t,this))},onSelectionUpdate:()=>{var l;this.ready&&((l=t.onTextCursorPositionChange)==null||l.call(t,this))},editable:e.editable===void 0?!0:e.editable,extensions:t.enableBlockNoteExtensions===!1?(i=t._tiptapOptions)==null?void 0:i.extensions:[...((s=t._tiptapOptions)==null?void 0:s.extensions)||[],...o],editorProps:{attributes:{"data-theme":e.theme||"light",...t.editorDOMAttributes||{},class:[A.bnEditor,A.bnRoot,t.defaultStyles?A.defaultStyles:"",((a=t.editorDOMAttributes)==null?void 0:a.class)||""].join(" ")}}};t.parentElement&&(r.element=t.parentElement),this._tiptapEditor=new h.Editor(r)}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){const e=[];return this._tiptapEditor.state.doc.firstChild.descendants(t=>(e.push(T(t,this.schema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(r=>typeof o<"u"?!1:r.type.name!=="blockContainer"||r.attrs.id!==t?!0:(o=T(r,this.schema,this.blockCache),!1)),o}forEachBlock(e,t=!1){const o=this.topLevelBlocks.slice();t&&o.reverse();function r(i){for(const s of i){if(!e(s))return!1;const a=t?s.children.slice().reverse():s.children;if(!r(a))return!1}return!0}r(o)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:o,endPos:r}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),i=this._tiptapEditor.state.doc.resolve(r).index(t-1),s=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let a;i>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return i<s-1&&(l=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:T(e,this.schema,this.blockCache),prevBlock:a===void 0?void 0:T(a,this.schema,this.blockCache),nextBlock:l===void 0?void 0:T(l,this.schema,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:r}=z(o,this._tiptapEditor.state.doc),{startPos:i,contentNode:s}=b(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,o)=>t.type.spec.group!=="blockContent"||o+t.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(e.push(T(this._tiptapEditor.state.doc.resolve(o).node(),this.schema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,o="before"){mt(e,t,o,this._tiptapEditor)}updateBlock(e,t){fe(e,t,this._tiptapEditor)}removeBlocks(e){gt(e,this._tiptapEditor)}replaceBlocks(e,t){me(e,t,this._tiptapEditor)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks(),o=new Set(["bold","italic","underline","strike","code"]),r=new Set(["textColor","backgroundColor"]);for(const i of t)o.has(i.type.name)?e[i.type.name]=!0:r.has(i.type.name)&&(e[i.type.name]=i.attrs.color);return e}addStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),o=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.setMark(r):o.has(r)&&this._tiptapEditor.commands.setMark(r,{color:i})}removeStyles(e){this._tiptapEditor.view.focus();for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),o=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.toggleMark(r):o.has(r)&&this._tiptapEditor.commands.toggleMark(r,{color:i})}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(e,t){if(e==="")return;let{from:o,to:r}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(o,r));const i=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,o,r).addMark(o,o+t.length,i))}canNestBlock(){const{startPos:e,depth:t}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(e).index(t-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:e}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(e){return kt(e,this._tiptapEditor.schema)}async HTMLToBlocks(e){return yt(e,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(e){return ye(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return be(e,this.schema,this._tiptapEditor.schema)}updateCollaborationUserInfo(e){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(e)}}f.BaseSlashMenuItem=P,f.BlockNoteEditor=en,f.CustomBlockSerializerExtension=vt,f.blockStyles=ee,f.camelToDataKebab=F,f.createBlockSpec=ne,f.createTipTapBlock=_,f.defaultBlockSchema=dt,f.defaultProps=I,f.defaultSlashMenuItems=Bt,f.getBlockNoteExtensions=wt,f.parse=st,f.propsToAttributes=it,f.render=at,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
7
7
  //# sourceMappingURL=blocknote.umd.cjs.map