@blocknote/core 0.9.4 → 0.9.5

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.
@@ -1,8 +1,8 @@
1
- (function(m,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@tiptap/core"),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-model"),require("prosemirror-state"),require("uuid"),require("prosemirror-view"),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")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@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-model","prosemirror-state","uuid","prosemirror-view","rehype-parse","rehype-remark","rehype-stringify","remark-gfm","remark-parse","remark-rehype","remark-stringify","unified","hast-util-from-dom"],g):(m=typeof globalThis<"u"?globalThis:m||self,g(m.blocknote={},m.core,m.extensionBold,m.extensionCode,m.Collaboration,m.CollaborationCursor,m.extensionDropcursor,m.extensionGapcursor,m.extensionHardBreak,m.extensionHistory,m.extensionItalic,m.extensionLink,m.extensionStrike,m.extensionText,m.extensionUnderline,m.prosemirrorModel,m.prosemirrorState,m.uuid,m.pv,m.rehypeParse,m.rehypeRemark,m.rehypeStringify,m.remarkGfm,m.remarkParse,m.remarkRehype,m.remarkStringify,m.unified,m.hastUtilFromDom))})(this,function(m,g,L,re,se,ae,le,de,ce,ue,pe,he,me,fe,ge,S,b,ke,I,be,ye,ve,we,Ce,J,Ee,$,Z){"use strict";var Pn=Object.defineProperty;var Hn=(m,g,L)=>g in m?Pn(m,g,{enumerable:!0,configurable:!0,writable:!0,value:L}):m[g]=L;var u=(m,g,L)=>(Hn(m,typeof g!="symbol"?g+"":g,L),L);const A=o=>o&&typeof o=="object"&&"default"in o?o:{default:o};function Se(o){if(o&&typeof o=="object"&&"default"in o)return o;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const Te=A(se),Be=A(ae),xe=Se(I),Q=A(be),Me=A(ye),tt=A(ve),et=A(we),_e=A(Ce),Ie=A(J),Ae=A(Ee),O={bnEditor:"_bnEditor_12je0_3",bnRoot:"_bnRoot_12je0_19",defaultStyles:"_defaultStyles_12je0_34",dragPreview:"_dragPreview_12je0_57","collaboration-cursor__caret":"_collaboration-cursor__caret_12je0_63","collaboration-cursor__label":"_collaboration-cursor__label_12je0_74"};function nt(o){const e=o.attrs.id,t=o.firstChild,n=t.type,i=o.childCount===2?o.lastChild.childCount:0;return{id:e,node:o,contentNode:t,contentType:n,numChildBlocks:i}}function w(o,e){const n=o.nodeSize-2;if(e<=1)for(e=1+1;o.resolve(e).parent.type.name!=="blockContainer"&&e<n;)e++;else if(e>=n)for(e=n-1;o.resolve(e).parent.type.name!=="blockContainer"&&e>1;)e--;o.resolve(e).parent.type.name==="blockGroup"&&e++;const i=o.resolve(e),r=i.depth;let s=i.node(r),l=r;for(;;){if(l<0)throw new Error("Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited.");if(s.type.name==="blockContainer")break;l-=1,s=i.node(l)}const{id:a,contentNode:d,contentType:c,numChildBlocks:f}=nt(s),h=i.start(l),p=i.end(l);return{id:a,node:s,contentNode:d,contentType:c,numChildBlocks:f,startPos:h,endPos:p,depth:l}}const T={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},Pe=g.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:T.backgroundColor.default,parseHTML:o=>o.hasAttribute("data-background-color")?o.getAttribute("data-background-color"):T.backgroundColor.default,renderHTML:o=>o.backgroundColor!==T.backgroundColor.default&&{"data-background-color":o.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(o,e)=>({state:t,view:n})=>{const i=w(t.doc,o);return i===void 0?!1:(t.tr.setNodeAttribute(i.startPos-1,"backgroundColor",e),n.focus(),!0)}}}}),He=g.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-background-color"),renderHTML:o=>({"data-background-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-background-color")?{color:o.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setBackgroundColor:o=>({commands:e})=>o!==T.backgroundColor.default?e.setMark(this.name,{color:o}):e.unsetMark(this.name)}}});function Le(o,e=JSON.stringify){const t={};return o.filter(n=>{const i=e(n);return Object.prototype.hasOwnProperty.call(t,i)?!1:t[i]=!0})}function Ne(o){const e=o.filter((n,i)=>o.indexOf(n)!==i);return Le(e)}const q=g.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const o=window.__TEST_OPTIONS;return o.mockID===void 0?o.mockID=0:o.mockID++,o.mockID.toString()}return ke.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:o=>o.getAttribute(`data-${this.options.attributeName}`),renderHTML:o=>({[`data-${this.options.attributeName}`]:o[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let o=null,e=!1;return[new b.Plugin({key:new b.PluginKey("uniqueID"),appendTransaction:(t,n,i)=>{const r=t.some(k=>k.docChanged)&&!n.doc.eq(i.doc),s=this.options.filterTransaction&&t.some(k=>{let v,E;return!(!((E=(v=this.options).filterTransaction)===null||E===void 0)&&E.call(v,k))});if(!r||s)return;const{tr:l}=i,{types:a,attributeName:d,generateID:c}=this.options,f=g.combineTransactionSteps(n.doc,t),{mapping:h}=f;if(g.getChangedRanges(f).forEach(({newRange:k})=>{const v=g.findChildrenInRange(i.doc,k,M=>a.includes(M.type.name)),E=v.map(({node:M})=>M.attrs[d]).filter(M=>M!==null),B=Ne(E);v.forEach(({node:M,pos:D})=>{let C;const _=(C=l.doc.nodeAt(D))===null||C===void 0?void 0:C.attrs[d];if(_===null){l.setNodeMarkup(D,void 0,{...M.attrs,[d]:c()});return}const{deleted:ie}=h.invert().mapResult(D);ie&&B.includes(_)&&l.setNodeMarkup(D,void 0,{...M.attrs,[d]:c()})})}),!!l.steps.length)return l},view(t){const n=i=>{let r;o=!((r=t.dom.parentElement)===null||r===void 0)&&r.contains(i.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(t,n)=>{let i;return(o!==t.dom.parentElement||((i=n.dataTransfer)===null||i===void 0?void 0:i.effectAllowed)==="copy")&&(o=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:n,attributeName:i}=this.options,r=s=>{const l=[];return s.forEach(a=>{if(a.isText){l.push(a);return}if(!n.includes(a.type.name)){l.push(a.copy(r(a.content)));return}const d=a.type.create({...a.attrs,[i]:null},r(a.content),a.marks);l.push(d)}),S.Fragment.from(l)};return e=!1,new S.Slice(r(t.content),t.openStart,t.openEnd)}}})]}}),ot=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function De(o){return ot()?o.replace("Mod","⌘"):o.replace("Mod","Ctrl")}function x(...o){return o.filter(e=>e).join(" ")}class it extends Error{constructor(e){super(`Unreachable case: ${e}`)}}const rt=new Set(["bold","italic","underline","strike","code"]),st=new Set(["textColor","backgroundColor"]);function at(o,e){const t=[];for(const[n,i]of Object.entries(o.styles))rt.has(n)?t.push(e.mark(n)):st.has(n)&&t.push(e.mark(n,{color:i}));return o.text.split(/(\n)/g).filter(n=>n.length>0).map(n=>n===`
2
- `?e.nodes.hardBreak.create():e.text(n,t))}function Oe(o,e){const t=e.marks.link.create({href:o.href});return lt(o.content,e).map(n=>{if(n.type.name==="text")return n.mark([...n.marks,t]);if(n.type.name==="hardBreak")return n;throw new Error("unexpected node type")})}function lt(o,e){const t=[];if(typeof o=="string")return t.push(...at({type:"text",text:o,styles:{}},e)),t;for(const n of o)t.push(...at(n,e));return t}function dt(o,e){const t=[];for(const n of o)if(n.type==="link")t.push(...Oe(n,e));else if(n.type==="text")t.push(...lt([n],e));else throw new it(n);return t}function F(o,e){let t=o.id;t===void 0&&(t=q.options.generateID());let n=o.type;n===void 0&&(n="paragraph");let i;if(!o.content)i=e.nodes[n].create(o.props);else if(typeof o.content=="string")i=e.nodes[n].create(o.props,e.text(o.content));else{const l=dt(o.content,e);i=e.nodes[n].create(o.props,l)}const r=[];if(o.children)for(const l of o.children)r.push(F(l,e));const s=e.nodes.blockGroup.create({},r);return e.nodes.blockContainer.create({id:t,...o.props},r.length>0?[i,s]:i)}function Re(o){const e=[];let t;return o.content.forEach(n=>{if(n.type.name==="hardBreak"){t?t.type==="text"?t.text+=`
3
- `:t.type==="link"&&(t.content[t.content.length-1].text+=`
4
- `):t={type:"text",text:`
5
- `,styles:{}};return}const i={};let r;for(const s of n.marks)if(s.type.name==="link")r=s;else if(rt.has(s.type.name))i[s.type.name]=!0;else if(st.has(s.type.name))i[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);t?t.type==="text"?r?(e.push(t),t={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}):JSON.stringify(t.styles)===JSON.stringify(i)?t.text+=n.textContent:(e.push(t),t={type:"text",text:n.textContent,styles:i}):t.type==="link"&&(r?t.href===r.attrs.href?JSON.stringify(t.content[t.content.length-1].styles)===JSON.stringify(i)?t.content[t.content.length-1].text+=n.textContent:t.content.push({type:"text",text:n.textContent,styles:i}):(e.push(t),t={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}):(e.push(t),t={type:"text",text:n.textContent,styles:i})):r?t={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}:t={type:"text",text:n.textContent,styles:i}}),t&&e.push(t),e}function P(o,e,t){if(o.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+o.type.name+".");const n=t==null?void 0:t.get(o);if(n)return n;const i=nt(o);let r=i.id;r===null&&(r=q.options.generateID());const s={};for(const[c,f]of Object.entries({...o.attrs,...i.contentNode.attrs})){const h=e[i.contentType.name];if(!h)throw Error("Block is of an unrecognized type: "+i.contentType.name);const p=h.propSchema;c in p?s[c]=f:c!=="id"&&!(c in T)&&console.warn("Block has an unrecognized attribute: "+c)}const l=e[i.contentType.name],a=[];for(let c=0;c<i.numChildBlocks;c++)a.push(P(o.lastChild.child(c),e,t));const d={id:r,type:l.node.name,props:s,content:l.node.config.content==="inline*"?Re(i.contentNode):void 0,children:a};return t==null||t.set(o,d),d}const ct=new b.PluginKey("previous-blocks"),ze={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Ve=()=>{let o;return new b.Plugin({key:ct,view(e){return{update:async(t,n)=>{var i;((i=this.key)==null?void 0:i.getState(t.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(ct,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,n,i){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||n.doc.eq(i.doc))return t;const r={},s=g.findChildren(n.doc,d=>d.attrs.id),l=new Map(s.map(d=>[d.node.attrs.id,d])),a=g.findChildren(i.doc,d=>d.attrs.id);for(const d of a){const c=l.get(d.node.attrs.id),f=c==null?void 0:c.node.firstChild,h=d.node.firstChild;if(c&&f&&h){const p={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:i.doc.resolve(d.pos).depth};let k={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:n.doc.resolve(c.pos).depth};r[d.node.attrs.id]=k,e.getMeta("numberedListIndexing")&&(d.node.attrs.id in t.prevTransactionOldBlockAttrs&&(k=t.prevTransactionOldBlockAttrs[d.node.attrs.id]),p.type==="numberedListItem"&&(k.index=p.index)),t.currentTransactionOldBlockAttrs[d.node.attrs.id]=k,JSON.stringify(k)!==JSON.stringify(p)&&(k["depth-change"]=k.depth-p.depth,t.updatedBlocks.add(d.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=r,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const n=[];return e.doc.descendants((i,r)=>{if(!i.attrs.id||!t.updatedBlocks.has(i.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[i.attrs.id],l={};for(const[d,c]of Object.entries(s))l["data-prev-"+ze[d]]=c||"none";const a=I.Decoration.node(r,r+i.nodeSize,{...l});n.push(a)}),I.DecorationSet.create(e.doc,n)}}})},ut="_blockOuter_xo7pf_5",pt="_block_xo7pf_5",ht="_reactNodeViewRenderer_xo7pf_17",mt="_blockContent_xo7pf_22",ft="_blockGroup_xo7pf_42",gt="_wrapper_xo7pf_226",kt="_addImageButton_xo7pf_234",bt="_addImageButtonIcon_xo7pf_250",yt="_addImageButtonText_xo7pf_256",vt="_imageAndCaptionWrapper_xo7pf_260",wt="_imageWrapper_xo7pf_266",Ct="_image_xo7pf_260",Et="_resizeHandle_xo7pf_279",St="_caption_xo7pf_294",Tt="_isEmpty_xo7pf_300",Bt="_inlineContent_xo7pf_300",xt="_isFilter_xo7pf_301",Mt="_hasAnchor_xo7pf_313",y={blockOuter:ut,block:pt,reactNodeViewRenderer:ht,blockContent:mt,blockGroup:ft,wrapper:gt,addImageButton:kt,addImageButtonIcon:bt,addImageButtonText:yt,imageAndCaptionWrapper:vt,imageWrapper:wt,image:Ct,resizeHandle:Et,caption:St,isEmpty:Tt,inlineContent:Bt,isFilter:xt,hasAnchor:Mt},Fe=Object.freeze(Object.defineProperty({__proto__:null,addImageButton:kt,addImageButtonIcon:bt,addImageButtonText:yt,block:pt,blockContent:mt,blockGroup:ft,blockOuter:ut,caption:St,default:y,hasAnchor:Mt,image:Ct,imageAndCaptionWrapper:vt,imageWrapper:wt,inlineContent:Bt,isEmpty:Tt,isFilter:xt,reactNodeViewRenderer:ht,resizeHandle:Et,wrapper:gt},Symbol.toStringTag,{value:"Module"})),Ue={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},qe=new b.PluginKey("non-editable-block"),We=()=>new b.Plugin({key:qe,props:{handleKeyDown:(o,e)=>{"node"in o.state.selection&&e.preventDefault()}}}),$e=g.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:o=>{if(typeof o=="string")return!1;const e={};for(const[t,n]of Object.entries(Ue))o.getAttribute(n)&&(e[t]=o.getAttribute(n));return o.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:o}){var t;const e=((t=this.options.domAttributes)==null?void 0:t.blockContainer)||{};return["div",g.mergeAttributes(o,{class:y.blockOuter,"data-node-type":"block-outer"}),["div",g.mergeAttributes({...e,class:x(y.block,e.class),"data-node-type":this.name},o),0]]},addCommands(){return{BNCreateBlock:o=>({state:e,dispatch:t})=>{const n=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(o,n),!0},BNDeleteBlock:o=>({state:e,dispatch:t})=>{const n=w(e.doc,o);if(n===void 0)return!1;const{startPos:i,endPos:r}=n;return t&&e.tr.deleteRange(i,r),!0},BNUpdateBlock:(o,e)=>({state:t,dispatch:n})=>{const i=w(t.doc,o);if(i===void 0)return!1;const{startPos:r,endPos:s,node:l,contentNode:a}=i;if(n){if(e.children!==void 0){const p=[];for(const k of e.children)p.push(F(k,t.schema));l.childCount===2?t.tr.replace(r+a.nodeSize+1,s-1,new S.Slice(S.Fragment.from(p),0,0)):t.tr.insert(r+a.nodeSize,t.schema.nodes.blockGroup.create({},p))}if(e.content!==void 0){let p=[];typeof e.content=="string"?p.push(t.schema.text(e.content)):p=dt(e.content,t.schema),t.tr.replace(r+1,r+a.nodeSize-1,new S.Slice(S.Fragment.from(p),0,0))}const d=a.type.name,c=e.type||d,f=t.schema.nodes[d].spec.content,h=t.schema.nodes[c].spec.content;f==="inline*"&&h===""?t.tr.replaceWith(r,s,t.schema.nodes[c].create({...a.attrs,...e.props})).setSelection(new b.NodeSelection(t.tr.doc.resolve(r))):t.tr.setNodeMarkup(r,e.type===void 0?void 0:t.schema.nodes[e.type],{...a.attrs,...e.props}),t.tr.setNodeMarkup(r-1,void 0,{...l.attrs,...e.props})}return!0},BNMergeBlocks:o=>({state:e,dispatch:t})=>{const n=e.doc.resolve(o+1).node().type.name==="blockContainer",i=e.doc.resolve(o-1).node().type.name==="blockContainer";if(!n||!i)return!1;const r=w(e.doc,o+1),{node:s,contentNode:l,startPos:a,endPos:d,depth:c}=r;if(s.childCount===2){const p=e.doc.resolve(a+l.nodeSize+1),k=e.doc.resolve(d-1),v=p.blockRange(k);t&&e.tr.lift(v,c-1)}let f=o-1,h=w(e.doc,f);for(;h.numChildBlocks>0;)if(f--,h=w(e.doc,f),h===void 0)return!1;return t&&(t(e.tr.deleteRange(a,a+l.nodeSize).replace(f-1,a,new S.Slice(l.content,0,0)).scrollIntoView()),e.tr.setSelection(new b.TextSelection(e.doc.resolve(f-1)))),!0},BNSplitBlock:(o,e)=>({state:t,dispatch:n})=>{const i=w(t.doc,o);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:l,endPos:a,depth:d}=i,c=t.doc.cut(l+1,o),f=t.doc.cut(o,a-1),h=t.schema.nodes.blockContainer.createAndFill(),p=a+1,k=p+2;return n&&(t.tr.insert(p,h),t.tr.replace(k,k+1,f.content.size>0?new S.Slice(S.Fragment.from(f),d+2,d+2):void 0),e&&t.tr.setBlockType(k,k,t.schema.node(s).type,r.attrs),t.tr.setSelection(new b.TextSelection(t.doc.resolve(k))),t.tr.replace(l+1,a-1,c.content.size>0?new S.Slice(S.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Ve(),We()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:n})=>{const{contentType:i}=w(n.doc,n.selection.from),r=n.selection.$anchor.parentOffset===0,s=i.name==="paragraph";return r&&!s?t.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1}),()=>t.command(({state:n})=>n.selection.$anchor.parentOffset===0?t.liftListItem("blockContainer"):!1),()=>t.command(({state:n})=>{const{depth:i,startPos:r}=w(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,a=r===2,d=r-1;return!a&&s&&l&&i===2?t.BNMergeBlocks(d):!1})]),Enter:()=>this.editor.commands.first(({commands:t})=>[()=>t.command(({state:n})=>{const{node:i,depth:r}=w(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,a=i.textContent.length===0,d=r>2;return s&&l&&a&&d?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:n,chain:i})=>{const{node:r,endPos:s}=w(n.doc,n.selection.from),l=n.selection.$anchor.parentOffset===0,a=n.selection.anchor===n.selection.head,d=r.textContent.length===0;if(l&&a&&d){const c=s+1,f=c+2;return i().BNCreateBlock(c).setTextSelection(f).run(),!0}return!1}),()=>t.command(({state:n,chain:i})=>{const{node:r}=w(n.doc,n.selection.from);return r.textContent.length===0?!1:(i().deleteSelection().BNSplitBlock(n.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)}}}),Ge=g.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:o=>typeof o=="string"?!1:o.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:o}){var t;const e=((t=this.options.domAttributes)==null?void 0:t.blockGroup)||{};return["div",g.mergeAttributes({...e,class:x(y.blockGroup,e.class),"data-node-type":"blockGroup"},o),0]}}),je=g.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Ke=o=>{const e=S.DOMSerializer.fromSchema(o);return new S.DOMSerializer({...e.nodes},e.marks)},_t=g.Extension.create({addProseMirrorPlugins(){return[new b.Plugin({props:{clipboardSerializer:Ke(this.editor.schema)}})]}});class U{constructor(){u(this,"callbacks",{})}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),()=>this.off(e,t)}emit(e,...t){const n=this.callbacks[e];n&&n.forEach(i=>i.apply(this,t))}off(e,t){const n=this.callbacks[e];n&&(t?this.callbacks[e]=n.filter(i=>i!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}const Xe=g.findParentNode(o=>o.type.name==="blockContainer");class Ye{constructor(e,t,n=()=>{}){u(this,"suggestionsMenuState");u(this,"updateSuggestionsMenu");u(this,"pluginState");u(this,"handleScroll",()=>{var e;if((e=this.suggestionsMenuState)!=null&&e.show){const t=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=t.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=e,this.pluginKey=t,this.pluginState=G(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");n(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(e,t){const n=this.pluginKey.getState(t),i=this.pluginKey.getState(e.state),r=!n.active&&i.active,s=n.active&&!i.active,l=n.active&&i.active;if(!r&&!l&&!s)return;if(this.pluginState=s?n:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const a=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:a.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function G(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const It=(o,e,t,n,i=()=>[],r=()=>{})=>{if(n.length!==1)throw new Error("'char' should be a single character");let s;const l=a=>{a.dispatch(a.state.tr.setMeta(t,{deactivate:!0}))};return{plugin:new b.Plugin({key:t,view:()=>(s=new Ye(o,t,e),s),state:{init(){return G()},apply(a,d,c,f){var p,k,v,E;if(a.getMeta("orderedListIndexing")!==void 0)return d;if((p=a.getMeta(t))!=null&&p.activate)return{active:!0,triggerCharacter:((k=a.getMeta(t))==null?void 0:k.triggerCharacter)||"",queryStartPos:f.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const h={...d};if(h.items=i(f.doc.textBetween(d.queryStartPos,f.selection.from)),h.notFoundCount=0,h.items.length===0&&(h.notFoundCount=Math.max(0,d.notFoundCount+(f.selection.from-c.selection.from))),f.selection.from!==f.selection.to||(v=a.getMeta(t))!=null&&v.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||d.active&&f.selection.from<d.queryStartPos||h.notFoundCount>3)return G();if(((E=a.getMeta(t))==null?void 0:E.selectedItemIndexChanged)!==void 0){let B=a.getMeta(t).selectedItemIndexChanged;B<0?B=d.items.length-1:B>=d.items.length&&(B=0),h.keyboardHoveredItemIndex=B}else c.selection.from!==f.selection.from&&(h.keyboardHoveredItemIndex=0);return h}},props:{handleKeyDown(a,d){const c=this.getState(a.state).active;if(d.key===n&&!c)return a.dispatch(a.state.tr.insertText(n).scrollIntoView().setMeta(t,{activate:!0,triggerCharacter:n})),!0;if(!c)return!1;const{triggerCharacter:f,queryStartPos:h,items:p,keyboardHoveredItemIndex:k}=t.getState(a.state);return d.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(t,{selectedItemIndexChanged:k-1})),!0):d.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(t,{selectedItemIndexChanged:k+1})),!0):d.key==="Enter"?(l(a),o._tiptapEditor.chain().focus().deleteRange({from:h-f.length,to:o._tiptapEditor.state.selection.from}).run(),r({item:p[k],editor:o}),!0):d.key==="Escape"?(l(a),!0):!1},decorations(a){const{active:d,decorationId:c,queryStartPos:f,triggerCharacter:h}=this.getState(a);if(!d)return null;if(h===""){const p=Xe(a.selection);if(p)return I.DecorationSet.create(a.doc,[I.Decoration.node(p.pos,p.pos+p.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}return I.DecorationSet.create(a.doc,[I.Decoration.inline(f-h.length,f,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}}}),itemCallback:a=>{l(o._tiptapEditor.view),o._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:o._tiptapEditor.state.selection.from}).run(),r({item:a,editor:o})}}},W=new b.PluginKey("SlashMenuPlugin");class At extends U{constructor(t,n){super();u(this,"plugin");u(this,"itemCallback");const i=It(t,r=>{this.emit("update",r)},W,"/",r=>n.filter(({name:s,aliases:l})=>s.toLowerCase().startsWith(r.toLowerCase())||l&&l.filter(a=>a.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(t){return this.on("update",t)}}const Je=new b.PluginKey("blocknote-placeholder"),Ze=g.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 b.Plugin({key:Je,props:{decorations:o=>{const{doc:e,selection:t}=o,n=W.getState(o),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(i)return e.descendants((l,a)=>{const d=r>=a&&r<=a+l.nodeSize,c=!l.isLeaf&&!l.childCount;if((d||!this.options.showOnlyCurrent)&&c){const f=[this.options.emptyNodeClass];this.editor.isEmpty&&f.push(this.options.emptyEditorClass),d&&f.push(this.options.hasAnchorClass),(n==null?void 0:n.triggerCharacter)===""&&(n!=null&&n.active)&&f.push(this.options.isFilterClass);const h=I.Decoration.node(a,a+l.nodeSize,{class:f.join(" ")});s.push(h)}return this.options.includeChildren}),I.DecorationSet.create(e,s)}}})]}}),Qe=g.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:o=>o.getAttribute("data-text-alignment"),renderHTML:o=>o.textAlignment!=="left"&&{"data-text-alignment":o.textAlignment}}}}]},addCommands(){return{setTextAlignment:o=>({state:e})=>{const t=[],n=w(e.doc,e.selection.from);if(n===void 0)return!1;let i=n.startPos;for(;i<e.selection.to;)e.doc.resolve(i).node().type.spec.group==="blockContent"?(t.push(i-1),i+=e.doc.resolve(i).node().nodeSize-1):i+=1;for(const r of t)e.tr.setNodeAttribute(r,"textAlignment",o);return!0}}}}),tn=g.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:T.textColor.default,parseHTML:o=>o.hasAttribute("data-text-color")?o.getAttribute("data-text-color"):T.textColor.default,renderHTML:o=>o.textColor!==T.textColor.default&&{"data-text-color":o.textColor}}}}]},addCommands(){return{setBlockTextColor:(o,e)=>({state:t,view:n})=>{const i=w(t.doc,o);return i===void 0?!1:(t.tr.setNodeAttribute(i.startPos-1,"textColor",e),n.focus(),!0)}}}}),en=g.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-text-color"),renderHTML:o=>({"data-text-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-text-color")?{color:o.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setTextColor:o=>({commands:e})=>o!==T.textColor.default?e.setMark(this.name,{color:o}):e.unsetMark(this.name)}}}),nn=g.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const o=new b.PluginKey(this.name);return[new b.Plugin({key:o,appendTransaction:(e,t,n)=>{const{doc:i,tr:r,schema:s}=n,l=o.getState(n),a=i.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(l)return r.insert(a,d.create(void 0,c.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let n=e.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=n.firstChild;if(!i)throw new Error("Expected blockContent");return n.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Pt=o=>{var t;const e=[g.extensions.ClipboardTextSerializer,g.extensions.Commands,g.extensions.Editable,g.extensions.FocusEvents,g.extensions.Tabindex,de.Gapcursor,Ze.configure({emptyNodeClass:y.isEmpty,hasAnchorClass:y.hasAnchor,isFilterClass:y.isFilter,includeChildren:!0,showOnlyCurrent:!1}),q.configure({types:["blockContainer"]}),ce.HardBreak,fe.Text,L.Bold,re.Code,pe.Italic,me.Strike,ge.Underline,he.Link,en,tn,He,Pe,Qe,je,$e.configure({domAttributes:o.domAttributes}),Ge.configure({domAttributes:o.domAttributes}),...Object.values(o.blockSchema).map(n=>n.node.configure({editor:o.editor,domAttributes:o.domAttributes})),_t,le.Dropcursor.configure({width:5,color:"#ddeeff"}),nn];if(o.collaboration){if(e.push(Te.default.configure({fragment:o.collaboration.fragment})),(t=o.collaboration.provider)!=null&&t.awareness){const n=i=>{const r=document.createElement("span");r.classList.add(O["collaboration-cursor__caret"]),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add(O["collaboration-cursor__label"]),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const l=document.createTextNode("⁠"),a=document.createTextNode("⁠");return r.insertBefore(l,null),r.insertBefore(s,null),r.insertBefore(a,null),r};e.push(Be.default.configure({user:o.collaboration.user,render:o.collaboration.renderCursor||n,provider:o.collaboration.provider}))}}else e.push(ue.History);return e};function j(o,e){let t,n;if(e.firstChild.descendants((i,r)=>t?!1:i.type.name!=="blockContainer"||i.attrs.id!==o?!0:(t=i,n=r+1,!1)),t===void 0||n===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:n}}function Ht(o,e,t="before",n){const i=typeof e=="string"?e:e.id,r=[];for(const d of o)r.push(F(d,n.schema));let s=-1;const{node:l,posBeforeNode:a}=j(i,n.state.doc);if(t==="before"&&(s=a),t==="after"&&(s=a+l.nodeSize),t==="nested"){if(l.childCount<2){s=a+l.firstChild.nodeSize+1;const d=n.state.schema.nodes.blockGroup.create({},r);n.view.dispatch(n.state.tr.insert(s,d));return}s=a+l.firstChild.nodeSize+2}n.view.dispatch(n.state.tr.insert(s,r))}function on(o,e,t){const n=typeof o=="string"?o:o.id,{posBeforeNode:i}=j(n,t.state.doc);t.commands.BNUpdateBlock(i+1,e)}function Lt(o,e){const t=new Set(o.map(i=>typeof i=="string"?i:i.id));let n=0;if(e.state.doc.descendants((i,r)=>{if(t.size===0)return!1;if(i.type.name!=="blockContainer"||!t.has(i.attrs.id))return!0;t.delete(i.attrs.id);const s=e.state.doc.nodeSize;e.commands.BNDeleteBlock(r-n+1);const l=e.state.doc.nodeSize;return n+=s-l,!1}),t.size>0){const i=[...t].join(`
6
- `);throw Error("Blocks with the following IDs could not be found in the editor: "+i)}}function rn(o,e,t){Ht(e,o[0],"before",t),Lt(o,t)}function sn(){const o=e=>{let t=e.children.length;for(let n=0;n<t;n++){const i=e.children[n];if(i.type==="element"&&(o(i),i.tagName==="u"))if(i.children.length>0){e.children.splice(n,1,...i.children);const r=i.children.length-1;t+=r,n+=r}else e.children.splice(n,1),t--,n--}};return o}function an(o){const e=new Set([...o.orderedListItemBlockTypes,...o.unorderedListItemBlockTypes]),t=n=>{let i=n.children.length,r;for(let s=0;s<i;s++){const a=n.children[s].children[0],d=a.children[0],c=a.children.length===2?a.children[1]:null,f=e.has(d.properties.dataContentType),h=f?o.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(c!==null&&t(c),r&&r.tagName!==h){n.children.splice(s-r.children.length,r.children.length,r);const p=r.children.length-1;s-=p,i-=p,r=void 0}if(f){r||(r=Z.fromDom(document.createElement(h)));const p=Z.fromDom(document.createElement("li"));p.children.push(d.children[0]),c!==null&&p.children.push(...c.children),r.children.push(p)}else if(c!==null){n.children.splice(s+1,0,...c.children),n.children[s]=d.children[0];const p=c.children.length;s+=p,i+=p}else n.children[s]=d.children[0]}r&&n.children.splice(i-r.children.length,r.children.length,r)};return t}async function Nt(o,e){const t=document.createElement("div"),n=S.DOMSerializer.fromSchema(e);for(const r of o){const s=F(r,e),l=n.serializeNode(s);t.appendChild(l)}return(await $.unified().use(Q.default,{fragment:!0}).use(an,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(tt.default).process(t.innerHTML)).value}async function Dt(o,e,t){const n=document.createElement("div");n.innerHTML=o.trim();const r=S.DOMParser.fromSchema(t).parse(n),s=[];for(let l=0;l<r.firstChild.childCount;l++)s.push(P(r.firstChild.child(l),e));return s}async function ln(o,e){return(await $.unified().use(Q.default,{fragment:!0}).use(sn).use(Me.default).use(et.default).use(Ae.default).process(await Nt(o,e))).value}function dn(o,e){const t=e.value?e.value+`
7
- `:"",n={};e.lang&&(n["data-language"]=e.lang);let i={type:"element",tagName:"code",properties:n,children:[{type:"text",value:t}]};return e.meta&&(i.data={meta:e.meta}),o.patch(e,i),i=o.applyData(e,i),i={type:"element",tagName:"pre",properties:{},children:[i]},o.patch(e,i),i}async function cn(o,e,t){const n=await $.unified().use(_e.default).use(et.default).use(Ie.default,{handlers:{...J.defaultHandlers,code:dn}}).use(tt.default).process(o);return Dt(n.value,e,t)}function K(o){return"data-"+o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Ot(o){const e={};return Object.entries(o.propSchema).forEach(([t,n])=>{e[t]={default:n.default,keepOnSplit:!0,parseHTML:i=>i.getAttribute(K(t)),renderHTML:i=>i[t]!==n.default?{[K(t)]:i[t]}:{}}}),e}function Rt(o){return[{tag:"div[data-content-type="+o.type+"]"}]}function zt(o,e){const t=document.createElement("div");t.setAttribute("data-content-type",o.type);for(const[i,r]of Object.entries(e))t.setAttribute(i,r);let n;return o.containsInlineContent?(n=document.createElement("div"),t.appendChild(n)):n=void 0,n!==void 0?{dom:t,contentDOM:n}:{dom:t}}function Vt(o){return{node:R({name:o.type,content:o.containsInlineContent?"inline*":"",selectable:!0,addAttributes(){return Ot(o)},parseHTML(){return Rt(o)},renderHTML({HTMLAttributes:t}){return zt(o,t)},addNodeView(){return({HTMLAttributes:t,getPos:n})=>{var p,k;const i=document.createElement("div"),r=((p=this.options.domAttributes)==null?void 0:p.blockContent)||{};for(const[v,E]of Object.entries(r))v!=="class"&&i.setAttribute(v,E);i.className=x(y.blockContent,r.class),i.setAttribute("data-content-type",o.type);for(const[v,E]of Object.entries(t))i.setAttribute(v,E);const s=this.options.editor;if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const l=n(),c=s._tiptapEditor.state.doc.resolve(l).node().attrs.id,f=s.getBlock(c);if(f.type!==o.type)throw new Error("Block type does not match");const h=o.render(f,s);if(o.containsInlineContent){const v=h.contentDOM,E=((k=this.options.domAttributes)==null?void 0:k.inlineContent)||{};for(const[B,M]of Object.entries(E))B!=="class"&&v.setAttribute(B,M);v.className=x(v.className,y.inlineContent,E.class)}return i.appendChild(h.dom),"contentDOM"in h?{dom:i,contentDOM:h.contentDOM,destroy:h.destroy}:{dom:i,destroy:h.destroy}}}}),propSchema:o.propSchema}}function R(o){return g.Node.create({...o,group:"blockContent",content:o.content})}const un={...T,level:{default:1,values:[1,2,3]}},pn={node:R({name:"heading",content:"inline*",addAttributes(){return{level:{default:1,parseHTML:o=>o.getAttribute("data-level"),renderHTML:o=>({"data-level":o.level.toString()})}}},addInputRules(){return[...[1,2,3].map(o=>new g.InputRule({find:new RegExp(`^(#{${o}})\\s$`),handler:({state:e,chain:t,range:n})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:o}}).deleteRange({from:n.from,to:n.to})}}))]},addKeyboardShortcuts(){return{"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}})}},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:o,HTMLAttributes:e}){var i,r;const t=((i=this.options.domAttributes)==null?void 0:i.blockContent)||{},n=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",g.mergeAttributes(e,{...t,class:x(y.blockContent,t.class),"data-content-type":this.name}),[`h${o.attrs.level}`,{...n,class:x(y.inlineContent,n.class)},0]]}}),propSchema:un},Ft=o=>{const{node:e,contentType:t}=w(o.state.doc,o.state.selection.from),n=o.state.selection.anchor===o.state.selection.head;return!t.name.endsWith("ListItem")||!n?!1:o.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},hn={...T},mn={node:R({name:"bulletListItem",content:"inline*",addInputRules(){return[new g.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:o,chain:e,range:t})=>{e().BNUpdateBlock(o.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ft(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:o}){var n,i;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes(o,{...e,class:x(y.blockContent,e.class),"data-content-type":this.name}),["p",{...t,class:x(y.inlineContent,t.class)},0]]}}),propSchema:hn},fn=new b.PluginKey("numbered-list-indexing"),gn=()=>new b.Plugin({key:fn,appendTransaction:(o,e,t)=>{const n=t.tr;n.setMeta("numberedListIndexing",!0);let i=!1;return t.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let l="1";const a=s===1,d=w(n.doc,s+1);if(d===void 0)return;if(!a){const h=w(n.doc,s-2);if(h===void 0)return;if(!(d.depth!==h.depth)){const k=h.contentNode;if(h.contentType.name==="numberedListItem"){const B=k.attrs.index;l=(parseInt(B)+1).toString()}}}d.contentNode.attrs.index!==l&&(i=!0,n.setNodeMarkup(s+1,void 0,{index:l}))}}),i?n:null}}),kn={...T},bn={node:R({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:o=>o.getAttribute("data-index"),renderHTML:o=>({"data-index":o.index})}}},addInputRules(){return[new g.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:o,chain:e,range:t})=>{e().BNUpdateBlock(o.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ft(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[gn()]},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:o}){var n,i;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes(o,{...e,class:x(y.blockContent,e.class),"data-content-type":this.name}),["p",{...t,class:x(y.inlineContent,t.class)},0]]}}),propSchema:kn},yn={...T},vn={node:R({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:o}){var n,i;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes({...e,class:x(y.blockContent,e.class),"data-content-type":this.name},o),["p",{...t,class:x(y.inlineContent,t.class)},0]]}}),propSchema:yn};class Ut{constructor(e,t,n){u(this,"imageToolbarState");u(this,"updateImageToolbar");u(this,"prevWasEditable",null);u(this,"shouldShow",e=>"node"in e.selection&&e.selection.node.type.name==="image"&&e.selection.node.attrs.src==="");u(this,"mouseDownHandler",()=>{var e;(e=this.imageToolbarState)!=null&&e.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"dragstartHandler",()=>{var e;(e=this.imageToolbarState)!=null&&e.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"blurHandler",e=>{var n;const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(n=this.imageToolbarState)!=null&&n.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"scrollHandler",()=>{var e;if((e=this.imageToolbarState)!=null&&e.show){const t=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=t.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=e,this.pmView=t,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");n(this.imageToolbarState)},t.dom.addEventListener("mousedown",this.mouseDownHandler),t.dom.addEventListener("dragstart",this.dragstartHandler),t.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var i,r;const n=this.pluginKey.getState(e.state);if(!((i=this.imageToolbarState)!=null&&i.show)&&n.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${n.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:n.block},this.updateImageToolbar();return}(!e.state.selection.eq(t.selection)||!e.state.doc.eq(t.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const z=new b.PluginKey("ImageToolbarPlugin");class qt extends U{constructor(t){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:z,view:n=>(this.view=new Ut(z,n,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:n=>{var r;return{block:(r=n.getMeta(z))==null?void 0:r.block}}}})}onUpdate(t){return this.on("update",t)}}const wn={textAlignment:T.textAlignment,backgroundColor:T.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},Wt=o=>{switch(o){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},$t=64,Cn=Vt({type:"image",propSchema:wn,containsInlineContent:!1,render:(o,e)=>{const t=document.createElement("div");t.className=y.wrapper,t.style.alignItems=Wt(o.props.textAlignment);const n=document.createElement("div");n.className=y.addImageButton,n.style.display=o.props.url===""?"":"none";const i=document.createElement("div");i.className=y.addImageButtonIcon;const r=document.createElement("p");r.className=y.addImageButtonText,r.innerText="Add Image";const s=document.createElement("div");s.className=y.imageAndCaptionWrapper,s.style.display=o.props.url!==""?"":"none";const l=document.createElement("div");l.className=y.imageWrapper,l.style.display=o.props.url!==""?"":"none";const a=document.createElement("img");a.className=y.image,a.src=o.props.url,a.alt="placeholder",a.contentEditable="false",a.draggable=!1,a.style.width=`${Math.min(o.props.width,e.domElement.firstElementChild.clientWidth)}px`;const d=document.createElement("div");d.className=y.resizeHandle,d.style.left="4px";const c=document.createElement("div");c.className=y.resizeHandle,c.style.right="4px";const f=document.createElement("p");f.className=y.caption,f.innerText=o.props.caption,f.style.padding=o.props.caption?"4px":"";const h=()=>{var Y;const C=((Y=e.getSelection())==null?void 0:Y.blocks)||[];[e.getTextCursorPosition().block,...C].find(An=>An.id===o.id)!==void 0?(n.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(n.style.outline="",s.style.outline="")};e.onEditorContentChange(h),e.onEditorSelectionChange(h);let p;const k=C=>{if(!p)return;let _;Wt(o.props.textAlignment)==="center"?p.handleUsed==="left"?_=p.initialWidth+(p.initialClientX-C.clientX)*2:_=p.initialWidth+(C.clientX-p.initialClientX)*2:p.handleUsed==="left"?_=p.initialWidth+p.initialClientX-C.clientX:_=p.initialWidth+C.clientX-p.initialClientX,_<$t?a.style.width=`${$t}px`:_>e.domElement.firstElementChild.clientWidth?a.style.width=`${e.domElement.firstElementChild.clientWidth}px`:a.style.width=`${_}px`},v=C=>{p&&((!C.target||!l.contains(C.target))&&l.contains(d)&&l.contains(c)&&(d.style.display="none",c.style.display="none"),p=void 0,e.updateBlock(o,{type:"image",props:{width:parseFloat(a.style.width.slice(0,-2))}}))},E=C=>{C.preventDefault()},B=()=>{e._tiptapEditor.view.dispatch(e._tiptapEditor.state.tr.setMeta(z,{block:o}))},M=C=>{C.preventDefault(),d.style.display="block",c.style.display="block",p={handleUsed:"left",initialWidth:o.props.width,initialClientX:C.clientX}},D=C=>{C.preventDefault(),d.style.display="block",c.style.display="block",p={handleUsed:"right",initialWidth:o.props.width,initialClientX:C.clientX}};return t.appendChild(n),n.appendChild(i),n.appendChild(r),t.appendChild(s),s.appendChild(l),l.appendChild(a),l.appendChild(d),l.appendChild(c),s.appendChild(f),window.addEventListener("mousemove",k),window.addEventListener("mouseup",v),n.addEventListener("mousedown",E),n.addEventListener("click",B),d.addEventListener("mousedown",M),c.addEventListener("mousedown",D),{dom:t,destroy:()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",v),n.removeEventListener("mousedown",E),n.removeEventListener("click",B),d.removeEventListener("mousedown",M),c.removeEventListener("mousedown",D)}}}}),X={paragraph:vn,heading:pn,bulletListItem:mn,numberedListItem:bn,image:Cn};class Gt{constructor(e,t,n){u(this,"formattingToolbarState");u(this,"updateFormattingToolbar");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({view:e,state:t,from:n,to:i})=>{const{doc:r,selection:s}=t,{empty:l}=s,a=!r.textBetween(n,i).length&&g.isTextSelection(t.selection);return!(!e.hasFocus()||l||a)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragstartHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",e=>{var n;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(n=this.formattingToolbarState)!=null&&n.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"scrollHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=e,this.pmView=t,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");n(this.formattingToolbarState)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.dom.addEventListener("mouseup",this.viewMouseupHandler),t.dom.addEventListener("dragstart",this.dragstartHandler),t.dom.addEventListener("focus",this.focusHandler),t.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var h,p;const{state:n,composing:i}=e,{doc:r,selection:s}=n,l=t&&t.doc.eq(r)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||l))return;this.prevWasEditable=this.editor.isEditable;const{ranges:a}=s,d=Math.min(...a.map(k=>k.$from.pos)),c=Math.max(...a.map(k=>k.$to.pos)),f=(h=this.shouldShow)==null?void 0:h.call(this,{view:e,state:n,from:d,to:c});if(this.editor.isEditable&&!this.preventShow&&(f||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((p=this.formattingToolbarState)!=null&&p.show&&!this.preventHide&&(!f||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:e}=this.pmView,{selection:t}=e,{ranges:n}=t,i=Math.min(...n.map(s=>s.$from.pos)),r=Math.max(...n.map(s=>s.$to.pos));if(g.isNodeSelection(t)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return g.posToDOMRect(this.pmView,i,r)}}const jt=new b.PluginKey("FormattingToolbarPlugin");class Kt extends U{constructor(t){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:jt,view:n=>(this.view=new Gt(t,n,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}class En{constructor(e,t,n){u(this,"hyperlinkToolbarState");u(this,"updateHyperlinkToolbar");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredHyperlinkMark");u(this,"mouseHoveredHyperlinkMarkRange");u(this,"keyboardHoveredHyperlinkMark");u(this,"keyboardHoveredHyperlinkMarkRange");u(this,"hyperlinkMark");u(this,"hyperlinkMarkRange");u(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,n=this.pmView.posAtDOM(t,0)+1,i=this.pmView.state.doc.resolve(n),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=g.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",e=>{var n;const t=this.pmView.dom.parentElement;this.hyperlinkMark&&e&&e.target&&!(t===e.target||t.contains(e.target))&&(n=this.hyperlinkToolbarState)!=null&&n.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});u(this,"scrollHandler",()=>{var e;this.hyperlinkMark!==void 0&&(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.referencePos=g.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=e,this.pmView=t,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");n(this.hyperlinkToolbarState)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(e,t){var i;const n=this.pmView.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);n.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:e})),this.pmView.dispatch(n),this.pmView.focus(),(i=this.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}deleteHyperlink(){var e;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}update(){var t;if(!this.pmView.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const n=this.pmView.state.selection.$from.marks();for(const i of n)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=g.getMarkRange(this.pmView.state.selection.$from,i.type,i.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){this.hyperlinkToolbarState={show:!0,referencePos:g.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.updateHyperlinkToolbar();return}if((t=this.hyperlinkToolbarState)!=null&&t.show&&e&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const Xt=new b.PluginKey("HyperlinkToolbarPlugin");class Yt extends U{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"editHyperlink",(t,n)=>{this.view.editHyperlink(t,n)});u(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new b.Plugin({key:Xt,view:n=>(this.view=new En(t,n,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}class V extends b.Selection{constructor(t,n){super(t,n);u(this,"nodes");const i=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,n.pos,(r,s,l)=>{if(l!==null&&l.eq(i))return this.nodes.push(r),!1})}static create(t,n,i=n){return new V(t.resolve(n),t.resolve(i))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof V)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(t.nodes[n]))return!1;return!0}map(t,n){const i=n.mapResult(this.from),r=n.mapResult(this.to);return r.deleted?b.Selection.near(t.resolve(i.pos)):i.deleted?b.Selection.near(t.resolve(r.pos)):new V(t.resolve(i.pos),t.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Sn=xe.__serializeForClipboard;let H;function Jt(o,e){var i;if(!e.dom.isConnected)return;const t=e.posAtCoords(o);if(!t)return;let n=e.domAtPos(t.pos).node;if(n!==e.dom){for(;n&&n.parentNode&&n.parentNode!==e.dom&&!((i=n.hasAttribute)!=null&&i.call(n,"data-id"));)n=n.parentNode;if(n)return{node:n,id:n.getAttribute("data-id")}}}function Tn(o,e){const t=Jt(o,e);if(t&&t.node.nodeType===1){const n=e.docView,i=n.nearestDesc(t.node,!0);return!i||i===n?null:i.posBefore}return null}function Bn(o,e){let t,n;const i=e.resolve(o.from).node().type.spec.group==="blockContent",r=e.resolve(o.to).node().type.spec.group==="blockContent",s=Math.min(o.$anchor.depth,o.$head.depth);if(i&&r){const l=o.$from.start(s-1),a=o.$to.end(s-1);t=e.resolve(l-1).pos,n=e.resolve(a+1).pos}else t=o.from,n=o.to;return{from:t,to:n}}function Zt(o,e,t=e){e===t&&(t+=o.state.doc.resolve(e+1).node().nodeSize);const n=o.domAtPos(e).node.cloneNode(!0),i=o.domAtPos(e).node,r=(c,f)=>Array.prototype.indexOf.call(c.children,f),s=r(i,o.domAtPos(e+1).node.parentElement),l=r(i,o.domAtPos(t-1).node.parentElement);for(let c=i.childElementCount-1;c>=0;c--)(c>l||c<s)&&n.removeChild(n.children[c]);Qt(),H=n;const d=o.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");H.className=H.className+" "+O.dragPreview+" "+d,document.body.appendChild(H)}function Qt(){H!==void 0&&(document.body.removeChild(H),H=void 0)}function xn(o,e){if(!o.dataTransfer)return;const t=e.dom.getBoundingClientRect(),n={left:t.left+t.width/2,top:o.clientY},i=Tn(n,e);if(i!=null){const r=e.state.selection,s=e.state.doc,{from:l,to:a}=Bn(r,s),d=l<=i&&i<a,c=r.$anchor.node()!==r.$head.node()||r instanceof V;d&&c?(e.dispatch(e.state.tr.setSelection(V.create(s,l,a))),Zt(e,l,a)):(e.dispatch(e.state.tr.setSelection(b.NodeSelection.create(e.state.doc,i))),Zt(e,i));const f=e.state.selection.content(),{dom:h,text:p}=Sn(e,f);o.dataTransfer.clearData(),o.dataTransfer.setData("text/html",h.innerHTML),o.dataTransfer.setData("text/plain",p),o.dataTransfer.effectAllowed="move",o.dataTransfer.setDragImage(H,0,0),e.dragging={slice:f,move:!0}}}class te{constructor(e,t,n){u(this,"sideMenuState");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",e=>{if(this.editor._tiptapEditor.commands.blur(),e.synthetic||!this.isDragging)return;const t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(this.isDragging=!1,!t||t.inside===-1){const n=new Event("drop",e),i=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=i.left+i.width/2,n.clientY=e.clientY,n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onDragOver",e=>{if(e.synthetic||!this.isDragging)return;const t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const n=new Event("dragover",e),i=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=i.left+i.width/2,n.clientY=e.clientY,n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onKeyDown",e=>{var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});u(this,"onMouseMove",e=>{var d,c,f,h,p;if(this.menuFrozen)return;const t=this.pmView.dom.firstChild.getBoundingClientRect(),n=this.pmView.dom.getBoundingClientRect(),i=e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom,r=this.pmView.dom.parentElement;if(i&&e&&e.target&&!(r===e.target||r.contains(e.target))){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=t.x;const s={left:t.left+t.width/2,top:e.clientY},l=Jt(s,this.pmView);if(!l||!this.editor.isEditable){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((f=this.sideMenuState)!=null&&f.show&&((h=this.hoveredBlock)!=null&&h.hasAttribute("data-id"))&&((p=this.hoveredBlock)==null?void 0:p.getAttribute("data-id"))===l.id)return;this.hoveredBlock=l.node;const a=l.node.firstChild;if(a&&this.editor.isEditable){const k=a.getBoundingClientRect();this.sideMenuState={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:k.x,k.y,k.width,k.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateSideMenu(this.sideMenuState)}});u(this,"onScroll",()=>{var e;if((e=this.sideMenuState)!=null&&e.show){const n=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:n.x,n.y,n.width,n.height),this.updateSideMenu(this.sideMenuState)}});this.editor=e,this.pmView=t,this.updateSideMenu=n,this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var e;(e=this.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.sideMenuState)!=null&&l.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!0;const t=this.hoveredBlock.firstChild.getBoundingClientRect(),n=this.pmView.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!n)return;const i=w(this.editor._tiptapEditor.state.doc,n.pos);if(i===void 0)return;const{contentNode:r,endPos:s}=i;if(r.textContent.length!==0){const a=s+1,d=a+2;this.editor._tiptapEditor.chain().BNCreateBlock(a).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.editor._tiptapEditor.commands.setTextSelection(s);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(W,{activate:!0,type:"drag"}))}}const ee=new b.PluginKey("SideMenuPlugin");class ne extends U{constructor(t){super();u(this,"sideMenuView");u(this,"plugin");u(this,"addBlock",()=>this.sideMenuView.addBlock());u(this,"blockDragStart",t=>{this.sideMenuView.isDragging=!0,xn(t,this.editor.prosemirrorView)});u(this,"blockDragEnd",()=>Qt());u(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=t,this.plugin=new b.Plugin({key:ee,view:n=>(this.sideMenuView=new te(t,n,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(t){return this.on("update",t)}}function N(o,e){const t=o.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain inline content.");t.content.length===1&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0?o.updateBlock(t,e):(o.insertBlocks([e],t,"after"),o.setTextCursorPosition(o.getTextCursorPosition().nextBlock))}const oe=(o=X)=>{var t,n,i;const e=[];return"heading"in o&&"level"in o.heading.propSchema&&((t=o.heading.propSchema.level.values)!=null&&t.includes(1)&&e.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>N(r,{type:"heading",props:{level:1}})}),(n=o.heading.propSchema.level.values)!=null&&n.includes(2)&&e.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>N(r,{type:"heading",props:{level:2}})}),(i=o.heading.propSchema.level.values)!=null&&i.includes(3)&&e.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>N(r,{type:"heading",props:{level:3}})})),"bulletListItem"in o&&e.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>N(r,{type:"bulletListItem"})}),"numberedListItem"in o&&e.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>N(r,{type:"numberedListItem"})}),"paragraph"in o&&e.push({name:"Paragraph",aliases:["p"],execute:r=>N(r,{type:"paragraph"})}),"image"in o&&e.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{N(r,{type:"image"}),r.setTextCursorPosition(r.getTextCursorPosition().nextBlock,"start"),r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(z,{block:r.getTextCursorPosition().prevBlock}))}}),e},Mn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class _n{constructor(e={}){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"ready",!1);u(this,"sideMenu");u(this,"formattingToolbar");u(this,"slashMenu");u(this,"hyperlinkToolbar");u(this,"imageToolbar");u(this,"uploadFile");var l,a,d,c,f;this.options=e;const t={defaultStyles:!0,blockSchema:e.blockSchema||X,...e};this.sideMenu=new ne(this),this.formattingToolbar=new Kt(this),this.slashMenu=new At(this,t.slashMenuItems||oe(t.blockSchema)),this.hyperlinkToolbar=new Yt(this),this.imageToolbar=new qt(this);const n=Pt({editor:this,domAttributes:t.domAttributes||{},blockSchema:t.blockSchema,collaboration:t.collaboration}),i=g.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin]});n.push(i),this.schema=t.blockSchema,this.uploadFile=t.uploadFile;const r=t.initialContent||(e.collaboration?void 0:[{type:"paragraph",id:q.options.generateID()}]),s={...Mn,...t._tiptapOptions,onBeforeCreate(h){if(!r)return;const p=h.editor.schema,k=p.node("doc",void 0,p.node("blockGroup",void 0,[F({id:"initialBlock",type:"paragraph"},p)]));h.editor.options.content=k.toJSON()},onCreate:()=>{var h;r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(h=t.onEditorReady)==null||h.call(t,this),this.ready=!0},onUpdate:()=>{var h;this.ready&&((h=t.onEditorContentChange)==null||h.call(t,this))},onSelectionUpdate:()=>{var h;this.ready&&((h=t.onTextCursorPositionChange)==null||h.call(t,this))},editable:e.editable===void 0?!0:e.editable,extensions:t.enableBlockNoteExtensions===!1?(l=t._tiptapOptions)==null?void 0:l.extensions:[...((a=t._tiptapOptions)==null?void 0:a.extensions)||[],...n],editorProps:{attributes:{...(d=t.domAttributes)==null?void 0:d.editor,class:x(O.bnEditor,O.bnRoot,t.defaultStyles?O.defaultStyles:"",((f=(c=t.domAttributes)==null?void 0:c.editor)==null?void 0:f.class)||"")}}};t.parentElement&&(s.element=t.parentElement),this._tiptapEditor=new g.Editor(s)}get prosemirrorView(){return this._tiptapEditor.view}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(P(t,this.schema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let n;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof n<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==t?!0:(n=P(i,this.schema,this.blockCache),!1)),n}forEachBlock(e,t=!1){const n=this.topLevelBlocks.slice();t&&n.reverse();function i(r){for(const s of r){if(!e(s))return!1;const l=t?s.children.slice().reverse():s.children;if(!i(l))return!1}return!0}i(n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:n,endPos:i}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(t-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let l;r>0&&(l=this._tiptapEditor.state.doc.resolve(n-2).node());let a;return r<s-1&&(a=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:P(e,this.schema,this.blockCache),prevBlock:l===void 0?void 0:P(l,this.schema,this.blockCache),nextBlock:a===void 0?void 0:P(a,this.schema,this.blockCache)}}setTextCursorPosition(e,t="start"){const n=typeof e=="string"?e:e.id,{posBeforeNode:i}=j(n,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=w(this._tiptapEditor.state.doc,i+2);if(s.type.spec.content===""){this._tiptapEditor.commands.setNodeSelection(r);return}t==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,n)=>t.type.spec.group!=="blockContent"||n+t.nodeSize<this._tiptapEditor.state.selection.from||n>this._tiptapEditor.state.selection.to?!0:(e.push(P(this._tiptapEditor.state.doc.resolve(n).node(),this.schema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,n="before"){Ht(e,t,n,this._tiptapEditor)}updateBlock(e,t){on(e,t,this._tiptapEditor)}removeBlocks(e){Lt(e,this._tiptapEditor)}replaceBlocks(e,t){rn(e,t,this._tiptapEditor)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks(),n=new Set(["bold","italic","underline","strike","code"]),i=new Set(["textColor","backgroundColor"]);for(const r of t)n.has(r.type.name)?e[r.type.name]=!0:i.has(r.type.name)&&(e[r.type.name]=r.attrs.color);return e}addStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[i,r]of Object.entries(e))t.has(i)?this._tiptapEditor.commands.setMark(i):n.has(i)&&this._tiptapEditor.commands.setMark(i,{color:r})}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"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[i,r]of Object.entries(e))t.has(i)?this._tiptapEditor.commands.toggleMark(i):n.has(i)&&this._tiptapEditor.commands.toggleMark(i,{color:r})}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;const{from:n,to:i}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(n,i));const r=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,n,i).addMark(n,n+t.length,r))}canNestBlock(){const{startPos:e,depth:t}=w(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}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(e){return Nt(e,this._tiptapEditor.schema)}async HTMLToBlocks(e){return Dt(e,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(e){return ln(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return cn(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)}}const In=async o=>{const e=new FormData;return e.append("file",o),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:e})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};m.BlockNoteEditor=_n,m.CustomBlockSerializerExtension=_t,m.FormattingToolbarProsemirrorPlugin=Kt,m.FormattingToolbarView=Gt,m.HyperlinkToolbarProsemirrorPlugin=Yt,m.ImageToolbarProsemirrorPlugin=qt,m.ImageToolbarView=Ut,m.SideMenuProsemirrorPlugin=ne,m.SideMenuView=te,m.SlashMenuProsemirrorPlugin=At,m.UnreachableCaseError=it,m.blockStyles=Fe,m.camelToDataKebab=K,m.createBlockSpec=Vt,m.createTipTapBlock=R,m.defaultBlockSchema=X,m.defaultProps=T,m.formatKeyboardShortcut=De,m.formattingToolbarPluginKey=jt,m.getBlockNoteExtensions=Pt,m.getDefaultSlashMenuItems=oe,m.hyperlinkToolbarPluginKey=Xt,m.imageToolbarPluginKey=z,m.isAppleOS=ot,m.mergeCSSClasses=x,m.parse=Rt,m.propsToAttributes=Ot,m.render=zt,m.setupSuggestionsMenu=It,m.sideMenuPluginKey=ee,m.slashMenuPluginKey=W,m.uploadToTmpFilesDotOrg_DEV_ONLY=In,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@tiptap/core"),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-model"),require("prosemirror-state"),require("uuid"),require("prosemirror-view"),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")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@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-model","prosemirror-state","uuid","prosemirror-view","rehype-parse","rehype-remark","rehype-stringify","remark-gfm","remark-parse","remark-rehype","remark-stringify","unified","hast-util-from-dom"],g):(f=typeof globalThis<"u"?globalThis:f||self,g(f.blocknote={},f.core,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.prosemirrorModel,f.prosemirrorState,f.uuid,f.pv,f.rehypeParse,f.rehypeRemark,f.rehypeStringify,f.remarkGfm,f.remarkParse,f.remarkRehype,f.remarkStringify,f.unified,f.hastUtilFromDom))})(this,function(f,g,H,re,se,ae,le,de,ce,ue,pe,he,me,fe,ge,S,b,ke,I,be,ye,ve,we,Ce,J,Ee,W,Z){"use strict";var Pn=Object.defineProperty;var Nn=(f,g,H)=>g in f?Pn(f,g,{enumerable:!0,configurable:!0,writable:!0,value:H}):f[g]=H;var u=(f,g,H)=>(Nn(f,typeof g!="symbol"?g+"":g,H),H);const A=o=>o&&typeof o=="object"&&"default"in o?o:{default:o};function Se(o){if(o&&typeof o=="object"&&"default"in o)return o;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const Te=A(se),Be=A(ae),xe=Se(I),Q=A(be),Me=A(ye),tt=A(ve),et=A(we),_e=A(Ce),Ie=A(J),Ae=A(Ee),O={bnEditor:"_bnEditor_12je0_3",bnRoot:"_bnRoot_12je0_19",defaultStyles:"_defaultStyles_12je0_34",dragPreview:"_dragPreview_12je0_57","collaboration-cursor__caret":"_collaboration-cursor__caret_12je0_63","collaboration-cursor__label":"_collaboration-cursor__label_12je0_74"};function nt(o){const t=o.attrs.id,e=o.firstChild,n=e.type,i=o.childCount===2?o.lastChild.childCount:0;return{id:t,node:o,contentNode:e,contentType:n,numChildBlocks:i}}function v(o,t){const n=o.nodeSize-2;if(t<=1)for(t=1+1;o.resolve(t).parent.type.name!=="blockContainer"&&t<n;)t++;else if(t>=n)for(t=n-1;o.resolve(t).parent.type.name!=="blockContainer"&&t>1;)t--;o.resolve(t).parent.type.name==="blockGroup"&&t++;const i=o.resolve(t),r=i.depth;let s=i.node(r),l=r;for(;;){if(l<0)throw new Error("Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited.");if(s.type.name==="blockContainer")break;l-=1,s=i.node(l)}const{id:a,contentNode:d,contentType:c,numChildBlocks:m}=nt(s),h=i.start(l),p=i.end(l);return{id:a,node:s,contentNode:d,contentType:c,numChildBlocks:m,startPos:h,endPos:p,depth:l}}const T={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},Pe=g.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:T.backgroundColor.default,parseHTML:o=>o.hasAttribute("data-background-color")?o.getAttribute("data-background-color"):T.backgroundColor.default,renderHTML:o=>o.backgroundColor!==T.backgroundColor.default&&{"data-background-color":o.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(o,t)=>({state:e,view:n})=>{const i=v(e.doc,o);return i===void 0?!1:(e.tr.setNodeAttribute(i.startPos-1,"backgroundColor",t),n.focus(),!0)}}}}),Ne=g.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-background-color"),renderHTML:o=>({"data-background-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-background-color")?{color:o.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setBackgroundColor:o=>({commands:t})=>o!==T.backgroundColor.default?t.setMark(this.name,{color:o}):t.unsetMark(this.name)}}});function He(o,t=JSON.stringify){const e={};return o.filter(n=>{const i=t(n);return Object.prototype.hasOwnProperty.call(e,i)?!1:e[i]=!0})}function Le(o){const t=o.filter((n,i)=>o.indexOf(n)!==i);return He(t)}const q=g.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const o=window.__TEST_OPTIONS;return o.mockID===void 0?o.mockID=0:o.mockID++,o.mockID.toString()}return ke.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:o=>o.getAttribute(`data-${this.options.attributeName}`),renderHTML:o=>({[`data-${this.options.attributeName}`]:o[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let o=null,t=!1;return[new b.Plugin({key:new b.PluginKey("uniqueID"),appendTransaction:(e,n,i)=>{const r=e.some(k=>k.docChanged)&&!n.doc.eq(i.doc),s=this.options.filterTransaction&&e.some(k=>{let w,E;return!(!((E=(w=this.options).filterTransaction)===null||E===void 0)&&E.call(w,k))});if(!r||s)return;const{tr:l}=i,{types:a,attributeName:d,generateID:c}=this.options,m=g.combineTransactionSteps(n.doc,e),{mapping:h}=m;if(g.getChangedRanges(m).forEach(({newRange:k})=>{const w=g.findChildrenInRange(i.doc,k,M=>a.includes(M.type.name)),E=w.map(({node:M})=>M.attrs[d]).filter(M=>M!==null),B=Le(E);w.forEach(({node:M,pos:D})=>{let C;const _=(C=l.doc.nodeAt(D))===null||C===void 0?void 0:C.attrs[d];if(_===null){l.setNodeMarkup(D,void 0,{...M.attrs,[d]:c()});return}const{deleted:ie}=h.invert().mapResult(D);ie&&B.includes(_)&&l.setNodeMarkup(D,void 0,{...M.attrs,[d]:c()})})}),!!l.steps.length)return l},view(e){const n=i=>{let r;o=!((r=e.dom.parentElement)===null||r===void 0)&&r.contains(i.target)?e.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(e,n)=>{let i;return(o!==e.dom.parentElement||((i=n.dataTransfer)===null||i===void 0?void 0:i.effectAllowed)==="copy")&&(o=null,t=!0),!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:n,attributeName:i}=this.options,r=s=>{const l=[];return s.forEach(a=>{if(a.isText){l.push(a);return}if(!n.includes(a.type.name)){l.push(a.copy(r(a.content)));return}const d=a.type.create({...a.attrs,[i]:null},r(a.content),a.marks);l.push(d)}),S.Fragment.from(l)};return t=!1,new S.Slice(r(e.content),e.openStart,e.openEnd)}}})]}}),ot=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function De(o){return ot()?o.replace("Mod","⌘"):o.replace("Mod","Ctrl")}function x(...o){return o.filter(t=>t).join(" ")}class it extends Error{constructor(t){super(`Unreachable case: ${t}`)}}const rt=new Set(["bold","italic","underline","strike","code"]),st=new Set(["textColor","backgroundColor"]);function at(o,t){const e=[];for(const[n,i]of Object.entries(o.styles))rt.has(n)?e.push(t.mark(n)):st.has(n)&&e.push(t.mark(n,{color:i}));return o.text.split(/(\n)/g).filter(n=>n.length>0).map(n=>n===`
2
+ `?t.nodes.hardBreak.create():t.text(n,e))}function Oe(o,t){const e=t.marks.link.create({href:o.href});return lt(o.content,t).map(n=>{if(n.type.name==="text")return n.mark([...n.marks,e]);if(n.type.name==="hardBreak")return n;throw new Error("unexpected node type")})}function lt(o,t){const e=[];if(typeof o=="string")return e.push(...at({type:"text",text:o,styles:{}},t)),e;for(const n of o)e.push(...at(n,t));return e}function dt(o,t){const e=[];for(const n of o)if(n.type==="link")e.push(...Oe(n,t));else if(n.type==="text")e.push(...lt([n],t));else throw new it(n);return e}function F(o,t){let e=o.id;e===void 0&&(e=q.options.generateID());let n=o.type;n===void 0&&(n="paragraph");let i;if(!o.content)i=t.nodes[n].create(o.props);else if(typeof o.content=="string")i=t.nodes[n].create(o.props,t.text(o.content));else{const l=dt(o.content,t);i=t.nodes[n].create(o.props,l)}const r=[];if(o.children)for(const l of o.children)r.push(F(l,t));const s=t.nodes.blockGroup.create({},r);return t.nodes.blockContainer.create({id:e,...o.props},r.length>0?[i,s]:i)}function Re(o){const t=[];let e;return o.content.forEach(n=>{if(n.type.name==="hardBreak"){e?e.type==="text"?e.text+=`
3
+ `:e.type==="link"&&(e.content[e.content.length-1].text+=`
4
+ `):e={type:"text",text:`
5
+ `,styles:{}};return}const i={};let r;for(const s of n.marks)if(s.type.name==="link")r=s;else if(rt.has(s.type.name))i[s.type.name]=!0;else if(st.has(s.type.name))i[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);e?e.type==="text"?r?(t.push(e),e={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}):JSON.stringify(e.styles)===JSON.stringify(i)?e.text+=n.textContent:(t.push(e),e={type:"text",text:n.textContent,styles:i}):e.type==="link"&&(r?e.href===r.attrs.href?JSON.stringify(e.content[e.content.length-1].styles)===JSON.stringify(i)?e.content[e.content.length-1].text+=n.textContent:e.content.push({type:"text",text:n.textContent,styles:i}):(t.push(e),e={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}):(t.push(e),e={type:"text",text:n.textContent,styles:i})):r?e={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}:e={type:"text",text:n.textContent,styles:i}}),e&&t.push(e),t}function P(o,t,e){if(o.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+o.type.name+".");const n=e==null?void 0:e.get(o);if(n)return n;const i=nt(o);let r=i.id;r===null&&(r=q.options.generateID());const s={};for(const[c,m]of Object.entries({...o.attrs,...i.contentNode.attrs})){const h=t[i.contentType.name];if(!h)throw Error("Block is of an unrecognized type: "+i.contentType.name);const p=h.propSchema;c in p?s[c]=m:c!=="id"&&!(c in T)&&console.warn("Block has an unrecognized attribute: "+c)}const l=t[i.contentType.name],a=[];for(let c=0;c<i.numChildBlocks;c++)a.push(P(o.lastChild.child(c),t,e));const d={id:r,type:l.node.name,props:s,content:l.node.config.content==="inline*"?Re(i.contentNode):void 0,children:a};return e==null||e.set(o,d),d}const ct=new b.PluginKey("previous-blocks"),ze={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Ve=()=>{let o;return new b.Plugin({key:ct,view(t){return{update:async(e,n)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(ct,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,n,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||n.doc.eq(i.doc))return e;const r={},s=g.findChildren(n.doc,d=>d.attrs.id),l=new Map(s.map(d=>[d.node.attrs.id,d])),a=g.findChildren(i.doc,d=>d.attrs.id);for(const d of a){const c=l.get(d.node.attrs.id),m=c==null?void 0:c.node.firstChild,h=d.node.firstChild;if(c&&m&&h){const p={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:i.doc.resolve(d.pos).depth};let k={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:n.doc.resolve(c.pos).depth};r[d.node.attrs.id]=k,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in e.prevTransactionOldBlockAttrs&&(k=e.prevTransactionOldBlockAttrs[d.node.attrs.id]),p.type==="numberedListItem"&&(k.index=p.index)),e.currentTransactionOldBlockAttrs[d.node.attrs.id]=k,JSON.stringify(k)!==JSON.stringify(p)&&(k["depth-change"]=k.depth-p.depth,e.updatedBlocks.add(d.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const n=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],l={};for(const[d,c]of Object.entries(s))l["data-prev-"+ze[d]]=c||"none";const a=I.Decoration.node(r,r+i.nodeSize,{...l});n.push(a)}),I.DecorationSet.create(t.doc,n)}}})},ut="_blockOuter_xo7pf_5",pt="_block_xo7pf_5",ht="_reactNodeViewRenderer_xo7pf_17",mt="_blockContent_xo7pf_22",ft="_blockGroup_xo7pf_42",gt="_wrapper_xo7pf_226",kt="_addImageButton_xo7pf_234",bt="_addImageButtonIcon_xo7pf_250",yt="_addImageButtonText_xo7pf_256",vt="_imageAndCaptionWrapper_xo7pf_260",wt="_imageWrapper_xo7pf_266",Ct="_image_xo7pf_260",Et="_resizeHandle_xo7pf_279",St="_caption_xo7pf_294",Tt="_isEmpty_xo7pf_300",Bt="_inlineContent_xo7pf_300",xt="_isFilter_xo7pf_301",Mt="_hasAnchor_xo7pf_313",y={blockOuter:ut,block:pt,reactNodeViewRenderer:ht,blockContent:mt,blockGroup:ft,wrapper:gt,addImageButton:kt,addImageButtonIcon:bt,addImageButtonText:yt,imageAndCaptionWrapper:vt,imageWrapper:wt,image:Ct,resizeHandle:Et,caption:St,isEmpty:Tt,inlineContent:Bt,isFilter:xt,hasAnchor:Mt},Fe=Object.freeze(Object.defineProperty({__proto__:null,addImageButton:kt,addImageButtonIcon:bt,addImageButtonText:yt,block:pt,blockContent:mt,blockGroup:ft,blockOuter:ut,caption:St,default:y,hasAnchor:Mt,image:Ct,imageAndCaptionWrapper:vt,imageWrapper:wt,inlineContent:Bt,isEmpty:Tt,isFilter:xt,reactNodeViewRenderer:ht,resizeHandle:Et,wrapper:gt},Symbol.toStringTag,{value:"Module"})),Ue={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},qe=new b.PluginKey("non-editable-block"),$e=()=>new b.Plugin({key:qe,props:{handleKeyDown:(o,t)=>{"node"in o.state.selection&&t.preventDefault()}}}),We=g.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:o=>{if(typeof o=="string")return!1;const t={};for(const[e,n]of Object.entries(Ue))o.getAttribute(n)&&(t[e]=o.getAttribute(n));return o.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:o}){var e;const t=((e=this.options.domAttributes)==null?void 0:e.blockContainer)||{};return["div",g.mergeAttributes(o,{class:y.blockOuter,"data-node-type":"block-outer"}),["div",g.mergeAttributes({...t,class:x(y.block,t.class),"data-node-type":this.name},o),0]]},addCommands(){return{BNCreateBlock:o=>({state:t,dispatch:e})=>{const n=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(o,n),!0},BNDeleteBlock:o=>({state:t,dispatch:e})=>{const n=v(t.doc,o);if(n===void 0)return!1;const{startPos:i,endPos:r}=n;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(o,t)=>({state:e,dispatch:n})=>{const i=v(e.doc,o);if(i===void 0)return!1;const{startPos:r,endPos:s,node:l,contentNode:a}=i;if(n){if(t.children!==void 0){const p=[];for(const k of t.children)p.push(F(k,e.schema));l.childCount===2?e.tr.replace(r+a.nodeSize+1,s-1,new S.Slice(S.Fragment.from(p),0,0)):e.tr.insert(r+a.nodeSize,e.schema.nodes.blockGroup.create({},p))}if(t.content!==void 0){let p=[];typeof t.content=="string"?p.push(e.schema.text(t.content)):p=dt(t.content,e.schema),e.tr.replace(r+1,r+a.nodeSize-1,new S.Slice(S.Fragment.from(p),0,0))}const d=a.type.name,c=t.type||d,m=e.schema.nodes[d].spec.content,h=e.schema.nodes[c].spec.content;m==="inline*"&&h===""?e.tr.replaceWith(r,s,e.schema.nodes[c].create({...a.attrs,...t.props})).setSelection(new b.NodeSelection(e.tr.doc.resolve(r))):e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...a.attrs,...t.props}),e.tr.setNodeMarkup(r-1,void 0,{...l.attrs,...t.props})}return!0},BNMergeBlocks:o=>({state:t,dispatch:e})=>{const n=t.doc.resolve(o+1).node().type.name==="blockContainer",i=t.doc.resolve(o-1).node().type.name==="blockContainer";if(!n||!i)return!1;const r=v(t.doc,o+1),{node:s,contentNode:l,startPos:a,endPos:d,depth:c}=r;if(s.childCount===2){const p=t.doc.resolve(a+l.nodeSize+1),k=t.doc.resolve(d-1),w=p.blockRange(k);e&&t.tr.lift(w,c-1)}let m=o-1,h=v(t.doc,m);for(;h.numChildBlocks>0;)if(m--,h=v(t.doc,m),h===void 0)return!1;return e&&(e(t.tr.deleteRange(a,a+l.nodeSize).replace(m-1,a,new S.Slice(l.content,0,0)).scrollIntoView()),t.tr.setSelection(new b.TextSelection(t.doc.resolve(m-1)))),!0},BNSplitBlock:(o,t)=>({state:e,dispatch:n})=>{const i=v(e.doc,o);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:l,endPos:a,depth:d}=i,c=e.doc.cut(l+1,o),m=e.doc.cut(o,a-1),h=e.schema.nodes.blockContainer.createAndFill(),p=a+1,k=p+2;return n&&(e.tr.insert(p,h),e.tr.replace(k,k+1,m.content.size>0?new S.Slice(S.Fragment.from(m),d+2,d+2):void 0),t&&e.tr.setBlockType(k,k,e.schema.node(s).type,r.attrs),e.tr.setSelection(new b.TextSelection(e.doc.resolve(k))),e.tr.replace(l+1,a-1,c.content.size>0?new S.Slice(S.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Ve(),$e()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:i})=>{const{contentType:r}=v(i.doc,i.selection.from),s=i.selection.$anchor.parentOffset===0,l=r.name==="paragraph";return s&&!l?n.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>n.command(({state:i})=>i.selection.$anchor.parentOffset===0?n.liftListItem("blockContainer"):!1),()=>n.command(({state:i})=>{const{depth:r,startPos:s}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,a=i.selection.anchor===i.selection.head,d=s===2,c=s-1;return!d&&l&&a&&r===2?n.BNMergeBlocks(c):!1})]),Delete:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.command(({state:i})=>{const{node:r,contentNode:s,depth:l,endPos:a}=v(i.doc,i.selection.from),d=i.selection.$anchor.parentOffset===s.firstChild.nodeSize,c=i.selection.anchor===i.selection.head,m=r.childCount===2;if(d&&c&&!m){let h=l,p=a+2,k=i.doc.resolve(p).depth;for(;k<h;)h=k,p+=2,k=i.doc.resolve(p).depth;return n.BNMergeBlocks(p-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:n})=>[()=>n.command(({state:i})=>{const{node:r,depth:s}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,a=i.selection.anchor===i.selection.head,d=r.textContent.length===0,c=s>2;return l&&a&&d&&c?n.liftListItem("blockContainer"):!1}),()=>n.command(({state:i,chain:r})=>{const{node:s,endPos:l}=v(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,d=i.selection.anchor===i.selection.head,c=s.textContent.length===0;if(a&&d&&c){const m=l+1,h=m+2;return r().BNCreateBlock(m).setTextSelection(h).run(),!0}return!1}),()=>n.command(({state:i,chain:r})=>{const{node:s}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,l).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)}}}),Ge=g.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:o=>typeof o=="string"?!1:o.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:o}){var e;const t=((e=this.options.domAttributes)==null?void 0:e.blockGroup)||{};return["div",g.mergeAttributes({...t,class:x(y.blockGroup,t.class),"data-node-type":"blockGroup"},o),0]}}),je=g.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Ke=o=>{const t=S.DOMSerializer.fromSchema(o);return new S.DOMSerializer({...t.nodes},t.marks)},_t=g.Extension.create({addProseMirrorPlugins(){return[new b.Plugin({props:{clipboardSerializer:Ke(this.editor.schema)}})]}});class U{constructor(){u(this,"callbacks",{})}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),()=>this.off(t,e)}emit(t,...e){const n=this.callbacks[t];n&&n.forEach(i=>i.apply(this,e))}off(t,e){const n=this.callbacks[t];n&&(e?this.callbacks[t]=n.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}const Xe=g.findParentNode(o=>o.type.name==="blockContainer");class Ye{constructor(t,e,n=()=>{}){u(this,"suggestionsMenuState");u(this,"updateSuggestionsMenu");u(this,"pluginState");u(this,"handleScroll",()=>{var t;if((t=this.suggestionsMenuState)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=e.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=t,this.pluginKey=e,this.pluginState=G(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");n(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const n=this.pluginKey.getState(e),i=this.pluginKey.getState(t.state),r=!n.active&&i.active,s=n.active&&!i.active,l=n.active&&i.active;if(!r&&!l&&!s)return;if(this.pluginState=s?n:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const a=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:a.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function G(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const It=(o,t,e,n,i=()=>[],r=()=>{})=>{if(n.length!==1)throw new Error("'char' should be a single character");let s;const l=a=>{a.dispatch(a.state.tr.setMeta(e,{deactivate:!0}))};return{plugin:new b.Plugin({key:e,view:()=>(s=new Ye(o,e,t),s),state:{init(){return G()},apply(a,d,c,m){var p,k,w,E;if(a.getMeta("orderedListIndexing")!==void 0)return d;if((p=a.getMeta(e))!=null&&p.activate)return{active:!0,triggerCharacter:((k=a.getMeta(e))==null?void 0:k.triggerCharacter)||"",queryStartPos:m.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const h={...d};if(h.items=i(m.doc.textBetween(d.queryStartPos,m.selection.from)),h.notFoundCount=0,h.items.length===0&&(h.notFoundCount=Math.max(0,d.notFoundCount+(m.selection.from-c.selection.from))),m.selection.from!==m.selection.to||(w=a.getMeta(e))!=null&&w.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||d.active&&m.selection.from<d.queryStartPos||h.notFoundCount>3)return G();if(((E=a.getMeta(e))==null?void 0:E.selectedItemIndexChanged)!==void 0){let B=a.getMeta(e).selectedItemIndexChanged;B<0?B=d.items.length-1:B>=d.items.length&&(B=0),h.keyboardHoveredItemIndex=B}else c.selection.from!==m.selection.from&&(h.keyboardHoveredItemIndex=0);return h}},props:{handleKeyDown(a,d){const c=this.getState(a.state).active;if(d.key===n&&!c)return a.dispatch(a.state.tr.insertText(n).scrollIntoView().setMeta(e,{activate:!0,triggerCharacter:n})),!0;if(!c)return!1;const{triggerCharacter:m,queryStartPos:h,items:p,keyboardHoveredItemIndex:k}=e.getState(a.state);return d.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(e,{selectedItemIndexChanged:k-1})),!0):d.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(e,{selectedItemIndexChanged:k+1})),!0):d.key==="Enter"?(p.length===0||(l(a),o._tiptapEditor.chain().focus().deleteRange({from:h-m.length,to:o._tiptapEditor.state.selection.from}).run(),r({item:p[k],editor:o})),!0):d.key==="Escape"?(l(a),!0):!1},decorations(a){const{active:d,decorationId:c,queryStartPos:m,triggerCharacter:h}=this.getState(a);if(!d)return null;if(h===""){const p=Xe(a.selection);if(p)return I.DecorationSet.create(a.doc,[I.Decoration.node(p.pos,p.pos+p.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}return I.DecorationSet.create(a.doc,[I.Decoration.inline(m-h.length,m,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}}}),itemCallback:a=>{l(o._tiptapEditor.view),o._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:o._tiptapEditor.state.selection.from}).run(),r({item:a,editor:o})}}},$=new b.PluginKey("SlashMenuPlugin");class At extends U{constructor(e,n){super();u(this,"plugin");u(this,"itemCallback");const i=It(e,r=>{this.emit("update",r)},$,"/",r=>n.filter(({name:s,aliases:l})=>s.toLowerCase().startsWith(r.toLowerCase())||l&&l.filter(a=>a.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(e){return this.on("update",e)}}const Je=new b.PluginKey("blocknote-placeholder"),Ze=g.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 b.Plugin({key:Je,props:{decorations:o=>{const{doc:t,selection:e}=o,n=$.getState(o),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=e,s=[];if(i)return t.descendants((l,a)=>{const d=r>=a&&r<=a+l.nodeSize,c=!l.isLeaf&&!l.childCount;if((d||!this.options.showOnlyCurrent)&&c){const m=[this.options.emptyNodeClass];this.editor.isEmpty&&m.push(this.options.emptyEditorClass),d&&m.push(this.options.hasAnchorClass),(n==null?void 0:n.triggerCharacter)===""&&(n!=null&&n.active)&&m.push(this.options.isFilterClass);const h=I.Decoration.node(a,a+l.nodeSize,{class:m.join(" ")});s.push(h)}return this.options.includeChildren}),I.DecorationSet.create(t,s)}}})]}}),Qe=g.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:o=>o.getAttribute("data-text-alignment"),renderHTML:o=>o.textAlignment!=="left"&&{"data-text-alignment":o.textAlignment}}}}]},addCommands(){return{setTextAlignment:o=>({state:t})=>{const e=[],n=v(t.doc,t.selection.from);if(n===void 0)return!1;let i=n.startPos;for(;i<t.selection.to;)t.doc.resolve(i).node().type.spec.group==="blockContent"?(e.push(i-1),i+=t.doc.resolve(i).node().nodeSize-1):i+=1;for(const r of e)t.tr.setNodeAttribute(r,"textAlignment",o);return!0}}}}),tn=g.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:T.textColor.default,parseHTML:o=>o.hasAttribute("data-text-color")?o.getAttribute("data-text-color"):T.textColor.default,renderHTML:o=>o.textColor!==T.textColor.default&&{"data-text-color":o.textColor}}}}]},addCommands(){return{setBlockTextColor:(o,t)=>({state:e,view:n})=>{const i=v(e.doc,o);return i===void 0?!1:(e.tr.setNodeAttribute(i.startPos-1,"textColor",t),n.focus(),!0)}}}}),en=g.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-text-color"),renderHTML:o=>({"data-text-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-text-color")?{color:o.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setTextColor:o=>({commands:t})=>o!==T.textColor.default?t.setMark(this.name,{color:o}):t.unsetMark(this.name)}}}),nn=g.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const o=new b.PluginKey(this.name);return[new b.Plugin({key:o,appendTransaction:(t,e,n)=>{const{doc:i,tr:r,schema:s}=n,l=o.getState(n),a=i.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(l)return r.insert(a,d.create(void 0,c.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let n=t.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=n.firstChild;if(!i)throw new Error("Expected blockContent");return n.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Pt=o=>{var e;const t=[g.extensions.ClipboardTextSerializer,g.extensions.Commands,g.extensions.Editable,g.extensions.FocusEvents,g.extensions.Tabindex,de.Gapcursor,Ze.configure({emptyNodeClass:y.isEmpty,hasAnchorClass:y.hasAnchor,isFilterClass:y.isFilter,includeChildren:!0,showOnlyCurrent:!1}),q.configure({types:["blockContainer"]}),ce.HardBreak,fe.Text,H.Bold,re.Code,pe.Italic,me.Strike,ge.Underline,he.Link,en,tn,Ne,Pe,Qe,je,We.configure({domAttributes:o.domAttributes}),Ge.configure({domAttributes:o.domAttributes}),...Object.values(o.blockSchema).map(n=>n.node.configure({editor:o.editor,domAttributes:o.domAttributes})),_t,le.Dropcursor.configure({width:5,color:"#ddeeff"}),nn];if(o.collaboration){if(t.push(Te.default.configure({fragment:o.collaboration.fragment})),(e=o.collaboration.provider)!=null&&e.awareness){const n=i=>{const r=document.createElement("span");r.classList.add(O["collaboration-cursor__caret"]),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add(O["collaboration-cursor__label"]),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const l=document.createTextNode("⁠"),a=document.createTextNode("⁠");return r.insertBefore(l,null),r.insertBefore(s,null),r.insertBefore(a,null),r};t.push(Be.default.configure({user:o.collaboration.user,render:o.collaboration.renderCursor||n,provider:o.collaboration.provider}))}}else t.push(ue.History);return t};function j(o,t){let e,n;if(t.firstChild.descendants((i,r)=>e?!1:i.type.name!=="blockContainer"||i.attrs.id!==o?!0:(e=i,n=r+1,!1)),e===void 0||n===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:n}}function Nt(o,t,e="before",n){const i=typeof t=="string"?t:t.id,r=[];for(const d of o)r.push(F(d,n.schema));let s=-1;const{node:l,posBeforeNode:a}=j(i,n.state.doc);if(e==="before"&&(s=a),e==="after"&&(s=a+l.nodeSize),e==="nested"){if(l.childCount<2){s=a+l.firstChild.nodeSize+1;const d=n.state.schema.nodes.blockGroup.create({},r);n.view.dispatch(n.state.tr.insert(s,d));return}s=a+l.firstChild.nodeSize+2}n.view.dispatch(n.state.tr.insert(s,r))}function on(o,t,e){const n=typeof o=="string"?o:o.id,{posBeforeNode:i}=j(n,e.state.doc);e.commands.BNUpdateBlock(i+1,t)}function Ht(o,t){const e=new Set(o.map(i=>typeof i=="string"?i:i.id));let n=0;if(t.state.doc.descendants((i,r)=>{if(e.size===0)return!1;if(i.type.name!=="blockContainer"||!e.has(i.attrs.id))return!0;e.delete(i.attrs.id);const s=t.state.doc.nodeSize;t.commands.BNDeleteBlock(r-n+1);const l=t.state.doc.nodeSize;return n+=s-l,!1}),e.size>0){const i=[...e].join(`
6
+ `);throw Error("Blocks with the following IDs could not be found in the editor: "+i)}}function rn(o,t,e){Nt(t,o[0],"before",e),Ht(o,e)}function sn(){const o=t=>{let e=t.children.length;for(let n=0;n<e;n++){const i=t.children[n];if(i.type==="element"&&(o(i),i.tagName==="u"))if(i.children.length>0){t.children.splice(n,1,...i.children);const r=i.children.length-1;e+=r,n+=r}else t.children.splice(n,1),e--,n--}};return o}function an(o){const t=new Set([...o.orderedListItemBlockTypes,...o.unorderedListItemBlockTypes]),e=n=>{let i=n.children.length,r;for(let s=0;s<i;s++){const a=n.children[s].children[0],d=a.children[0],c=a.children.length===2?a.children[1]:null,m=t.has(d.properties.dataContentType),h=m?o.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(c!==null&&e(c),r&&r.tagName!==h){n.children.splice(s-r.children.length,r.children.length,r);const p=r.children.length-1;s-=p,i-=p,r=void 0}if(m){r||(r=Z.fromDom(document.createElement(h)));const p=Z.fromDom(document.createElement("li"));p.children.push(d.children[0]),c!==null&&p.children.push(...c.children),r.children.push(p)}else if(c!==null){n.children.splice(s+1,0,...c.children),n.children[s]=d.children[0];const p=c.children.length;s+=p,i+=p}else n.children[s]=d.children[0]}r&&n.children.splice(i-r.children.length,r.children.length,r)};return e}async function Lt(o,t){const e=document.createElement("div"),n=S.DOMSerializer.fromSchema(t);for(const r of o){const s=F(r,t),l=n.serializeNode(s);e.appendChild(l)}return(await W.unified().use(Q.default,{fragment:!0}).use(an,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(tt.default).process(e.innerHTML)).value}async function Dt(o,t,e){const n=document.createElement("div");n.innerHTML=o.trim();const r=S.DOMParser.fromSchema(e).parse(n),s=[];for(let l=0;l<r.firstChild.childCount;l++)s.push(P(r.firstChild.child(l),t));return s}async function ln(o,t){return(await W.unified().use(Q.default,{fragment:!0}).use(sn).use(Me.default).use(et.default).use(Ae.default).process(await Lt(o,t))).value}function dn(o,t){const e=t.value?t.value+`
7
+ `:"",n={};t.lang&&(n["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:n,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),o.patch(t,i),i=o.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},o.patch(t,i),i}async function cn(o,t,e){const n=await W.unified().use(_e.default).use(et.default).use(Ie.default,{handlers:{...J.defaultHandlers,code:dn}}).use(tt.default).process(o);return Dt(n.value,t,e)}function K(o){return"data-"+o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Ot(o){const t={};return Object.entries(o.propSchema).forEach(([e,n])=>{t[e]={default:n.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(K(e));if(r===null)return null;if(typeof n.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof n.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[e]!==n.default?{[K(e)]:i[e]}:{}}}),t}function Rt(o){return[{tag:"div[data-content-type="+o.type+"]"}]}function zt(o,t){const e=document.createElement("div");e.setAttribute("data-content-type",o.type);for(const[i,r]of Object.entries(t))e.setAttribute(i,r);let n;return o.containsInlineContent?(n=document.createElement("div"),e.appendChild(n)):n=void 0,n!==void 0?{dom:e,contentDOM:n}:{dom:e}}function Vt(o){return{node:R({name:o.type,content:o.containsInlineContent?"inline*":"",selectable:!0,addAttributes(){return Ot(o)},parseHTML(){return Rt(o)},renderHTML({HTMLAttributes:e}){return zt(o,e)},addNodeView(){return({HTMLAttributes:e,getPos:n})=>{var p,k;const i=document.createElement("div"),r=((p=this.options.domAttributes)==null?void 0:p.blockContent)||{};for(const[w,E]of Object.entries(r))w!=="class"&&i.setAttribute(w,E);i.className=x(y.blockContent,r.class),i.setAttribute("data-content-type",o.type);for(const[w,E]of Object.entries(e))i.setAttribute(w,E);const s=this.options.editor;if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const l=n(),c=s._tiptapEditor.state.doc.resolve(l).node().attrs.id,m=s.getBlock(c);if(m.type!==o.type)throw new Error("Block type does not match");const h=o.render(m,s);if(o.containsInlineContent){const w=h.contentDOM,E=((k=this.options.domAttributes)==null?void 0:k.inlineContent)||{};for(const[B,M]of Object.entries(E))B!=="class"&&w.setAttribute(B,M);w.className=x(w.className,y.inlineContent,E.class)}return i.appendChild(h.dom),"contentDOM"in h?{dom:i,contentDOM:h.contentDOM,destroy:h.destroy}:{dom:i,destroy:h.destroy}}}}),propSchema:o.propSchema}}function R(o){return g.Node.create({...o,group:"blockContent",content:o.content})}const un={...T,level:{default:1,values:[1,2,3]}},pn={node:R({name:"heading",content:"inline*",addAttributes(){return{level:{default:1,parseHTML:o=>o.getAttribute("data-level"),renderHTML:o=>({"data-level":o.level.toString()})}}},addInputRules(){return[...[1,2,3].map(o=>new g.InputRule({find:new RegExp(`^(#{${o}})\\s$`),handler:({state:t,chain:e,range:n})=>{e().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:o}}).deleteRange({from:n.from,to:n.to})}}))]},addKeyboardShortcuts(){return{"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}})}},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:o,HTMLAttributes:t}){var i,r;const e=((i=this.options.domAttributes)==null?void 0:i.blockContent)||{},n=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",g.mergeAttributes(t,{...e,class:x(y.blockContent,e.class),"data-content-type":this.name}),[`h${o.attrs.level}`,{...n,class:x(y.inlineContent,n.class)},0]]}}),propSchema:un},Ft=o=>{const{node:t,contentType:e}=v(o.state.doc,o.state.selection.from),n=o.state.selection.anchor===o.state.selection.head;return!e.name.endsWith("ListItem")||!n?!1:o.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>t.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>t.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},hn={...T},mn={node:R({name:"bulletListItem",content:"inline*",addInputRules(){return[new g.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:o,chain:t,range:e})=>{t().BNUpdateBlock(o.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ft(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:o}){var n,i;const t=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},e=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes(o,{...t,class:x(y.blockContent,t.class),"data-content-type":this.name}),["p",{...e,class:x(y.inlineContent,e.class)},0]]}}),propSchema:hn},fn=new b.PluginKey("numbered-list-indexing"),gn=()=>new b.Plugin({key:fn,appendTransaction:(o,t,e)=>{const n=e.tr;n.setMeta("numberedListIndexing",!0);let i=!1;return e.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let l="1";const a=s===1,d=v(n.doc,s+1);if(d===void 0)return;if(!a){const h=v(n.doc,s-2);if(h===void 0)return;if(!(d.depth!==h.depth)){const k=h.contentNode;if(h.contentType.name==="numberedListItem"){const B=k.attrs.index;l=(parseInt(B)+1).toString()}}}d.contentNode.attrs.index!==l&&(i=!0,n.setNodeMarkup(s+1,void 0,{index:l}))}}),i?n:null}}),kn={...T},bn={node:R({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:o=>o.getAttribute("data-index"),renderHTML:o=>({"data-index":o.index})}}},addInputRules(){return[new g.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:o,chain:t,range:e})=>{t().BNUpdateBlock(o.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ft(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[gn()]},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:o}){var n,i;const t=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},e=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes(o,{...t,class:x(y.blockContent,t.class),"data-content-type":this.name}),["p",{...e,class:x(y.inlineContent,e.class)},0]]}}),propSchema:kn},yn={...T},vn={node:R({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:o}){var n,i;const t=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},e=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes({...t,class:x(y.blockContent,t.class),"data-content-type":this.name},o),["p",{...e,class:x(y.inlineContent,e.class)},0]]}}),propSchema:yn};class Ut{constructor(t,e,n){u(this,"imageToolbarState");u(this,"updateImageToolbar");u(this,"prevWasEditable",null);u(this,"shouldShow",t=>"node"in t.selection&&t.selection.node.type.name==="image"&&t.selection.node.attrs.src==="");u(this,"mouseDownHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"dragstartHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"blurHandler",t=>{var n;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(n=this.imageToolbarState)!=null&&n.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"scrollHandler",()=>{var t;if((t=this.imageToolbarState)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=e.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=t,this.pmView=e,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");n(this.imageToolbarState)},e.dom.addEventListener("mousedown",this.mouseDownHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var i,r;const n=this.pluginKey.getState(t.state);if(!((i=this.imageToolbarState)!=null&&i.show)&&n.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${n.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:n.block},this.updateImageToolbar();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const z=new b.PluginKey("ImageToolbarPlugin");class qt extends U{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:z,view:n=>(this.view=new Ut(z,n,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:n=>{var r;return{block:(r=n.getMeta(z))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}const wn={textAlignment:T.textAlignment,backgroundColor:T.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},$t=o=>{switch(o){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},Wt=64,Cn=Vt({type:"image",propSchema:wn,containsInlineContent:!1,render:(o,t)=>{const e=document.createElement("div");e.className=y.wrapper,e.style.alignItems=$t(o.props.textAlignment);const n=document.createElement("div");n.className=y.addImageButton,n.style.display=o.props.url===""?"":"none";const i=document.createElement("div");i.className=y.addImageButtonIcon;const r=document.createElement("p");r.className=y.addImageButtonText,r.innerText="Add Image";const s=document.createElement("div");s.className=y.imageAndCaptionWrapper,s.style.display=o.props.url!==""?"":"none";const l=document.createElement("div");l.className=y.imageWrapper,l.style.display=o.props.url!==""?"":"none";const a=document.createElement("img");a.className=y.image,a.src=o.props.url,a.alt="placeholder",a.contentEditable="false",a.draggable=!1,a.style.width=`${Math.min(o.props.width,t.domElement.firstElementChild.clientWidth)}px`;const d=document.createElement("div");d.className=y.resizeHandle,d.style.left="4px";const c=document.createElement("div");c.className=y.resizeHandle,c.style.right="4px";const m=document.createElement("p");m.className=y.caption,m.innerText=o.props.caption,m.style.padding=o.props.caption?"4px":"";const h=()=>{var Y;const C=((Y=t.getSelection())==null?void 0:Y.blocks)||[];[t.getTextCursorPosition().block,...C].find(An=>An.id===o.id)!==void 0?(n.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(n.style.outline="",s.style.outline="")};t.onEditorContentChange(h),t.onEditorSelectionChange(h);let p;const k=C=>{if(!p)return;let _;$t(o.props.textAlignment)==="center"?p.handleUsed==="left"?_=p.initialWidth+(p.initialClientX-C.clientX)*2:_=p.initialWidth+(C.clientX-p.initialClientX)*2:p.handleUsed==="left"?_=p.initialWidth+p.initialClientX-C.clientX:_=p.initialWidth+C.clientX-p.initialClientX,_<Wt?a.style.width=`${Wt}px`:_>t.domElement.firstElementChild.clientWidth?a.style.width=`${t.domElement.firstElementChild.clientWidth}px`:a.style.width=`${_}px`},w=C=>{p&&((!C.target||!l.contains(C.target))&&l.contains(d)&&l.contains(c)&&(d.style.display="none",c.style.display="none"),p=void 0,t.updateBlock(o,{type:"image",props:{width:parseFloat(a.style.width.slice(0,-2))}}))},E=C=>{C.preventDefault()},B=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(z,{block:o}))},M=C=>{C.preventDefault(),d.style.display="block",c.style.display="block",p={handleUsed:"left",initialWidth:o.props.width,initialClientX:C.clientX}},D=C=>{C.preventDefault(),d.style.display="block",c.style.display="block",p={handleUsed:"right",initialWidth:o.props.width,initialClientX:C.clientX}};return e.appendChild(n),n.appendChild(i),n.appendChild(r),e.appendChild(s),s.appendChild(l),l.appendChild(a),l.appendChild(d),l.appendChild(c),s.appendChild(m),window.addEventListener("mousemove",k),window.addEventListener("mouseup",w),n.addEventListener("mousedown",E),n.addEventListener("click",B),d.addEventListener("mousedown",M),c.addEventListener("mousedown",D),{dom:e,destroy:()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",w),n.removeEventListener("mousedown",E),n.removeEventListener("click",B),d.removeEventListener("mousedown",M),c.removeEventListener("mousedown",D)}}}}),X={paragraph:vn,heading:pn,bulletListItem:mn,numberedListItem:bn,image:Cn};class Gt{constructor(t,e,n){u(this,"formattingToolbarState");u(this,"updateFormattingToolbar");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({view:t,state:e,from:n,to:i})=>{const{doc:r,selection:s}=e,{empty:l}=s,a=!r.textBetween(n,i).length&&g.isTextSelection(e.selection);return!(!t.hasFocus()||l||a)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragstartHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",t=>{var n;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(n=this.formattingToolbarState)!=null&&n.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"scrollHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=t,this.pmView=e,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");n(this.formattingToolbarState)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var h,p;const{state:n,composing:i}=t,{doc:r,selection:s}=n,l=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||l))return;this.prevWasEditable=this.editor.isEditable;const{ranges:a}=s,d=Math.min(...a.map(k=>k.$from.pos)),c=Math.max(...a.map(k=>k.$to.pos)),m=(h=this.shouldShow)==null?void 0:h.call(this,{view:t,state:n,from:d,to:c});if(this.editor.isEditable&&!this.preventShow&&(m||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((p=this.formattingToolbarState)!=null&&p.show&&!this.preventHide&&(!m||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:e}=t,{ranges:n}=e,i=Math.min(...n.map(s=>s.$from.pos)),r=Math.max(...n.map(s=>s.$to.pos));if(g.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return g.posToDOMRect(this.pmView,i,r)}}const jt=new b.PluginKey("FormattingToolbarPlugin");class Kt extends U{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:jt,view:n=>(this.view=new Gt(e,n,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class En{constructor(t,e,n){u(this,"hyperlinkToolbarState");u(this,"updateHyperlinkToolbar");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredHyperlinkMark");u(this,"mouseHoveredHyperlinkMarkRange");u(this,"keyboardHoveredHyperlinkMark");u(this,"keyboardHoveredHyperlinkMarkRange");u(this,"hyperlinkMark");u(this,"hyperlinkMarkRange");u(this,"mouseOverHandler",t=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,n=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(n),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=g.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var n;const e=this.pmView.dom.parentElement;this.hyperlinkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(n=this.hyperlinkToolbarState)!=null&&n.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});u(this,"scrollHandler",()=>{var t;this.hyperlinkMark!==void 0&&(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.referencePos=g.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=t,this.pmView=e,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");n(this.hyperlinkToolbarState)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(t,e){var i;const n=this.pmView.state.tr.insertText(e,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);n.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(n),this.pmView.focus(),(i=this.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}deleteHyperlink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const n=this.pmView.state.selection.$from.marks();for(const i of n)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=g.getMarkRange(this.pmView.state.selection.$from,i.type,i.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){this.hyperlinkToolbarState={show:!0,referencePos:g.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.updateHyperlinkToolbar();return}if((e=this.hyperlinkToolbarState)!=null&&e.show&&t&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const Xt=new b.PluginKey("HyperlinkToolbarPlugin");class Yt extends U{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"editHyperlink",(e,n)=>{this.view.editHyperlink(e,n)});u(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new b.Plugin({key:Xt,view:n=>(this.view=new En(e,n,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class V extends b.Selection{constructor(e,n){super(e,n);u(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,n.pos,(r,s,l)=>{if(l!==null&&l.eq(i))return this.nodes.push(r),!1})}static create(e,n,i=n){return new V(e.resolve(n),e.resolve(i))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof V)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(e.nodes[n]))return!1;return!0}map(e,n){const i=n.mapResult(this.from),r=n.mapResult(this.to);return r.deleted?b.Selection.near(e.resolve(i.pos)):i.deleted?b.Selection.near(e.resolve(r.pos)):new V(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Sn=xe.__serializeForClipboard;let N;function Jt(o,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(o);if(!e)return;let n=t.domAtPos(e.pos).node;if(n!==t.dom){for(;n&&n.parentNode&&n.parentNode!==t.dom&&!((i=n.hasAttribute)!=null&&i.call(n,"data-id"));)n=n.parentNode;if(n)return{node:n,id:n.getAttribute("data-id")}}}function Tn(o,t){const e=Jt(o,t);if(e&&e.node.nodeType===1){const n=t.docView,i=n.nearestDesc(e.node,!0);return!i||i===n?null:i.posBefore}return null}function Bn(o,t){let e,n;const i=t.resolve(o.from).node().type.spec.group==="blockContent",r=t.resolve(o.to).node().type.spec.group==="blockContent",s=Math.min(o.$anchor.depth,o.$head.depth);if(i&&r){const l=o.$from.start(s-1),a=o.$to.end(s-1);e=t.resolve(l-1).pos,n=t.resolve(a+1).pos}else e=o.from,n=o.to;return{from:e,to:n}}function Zt(o,t,e=t){t===e&&(e+=o.state.doc.resolve(t+1).node().nodeSize);const n=o.domAtPos(t).node.cloneNode(!0),i=o.domAtPos(t).node,r=(c,m)=>Array.prototype.indexOf.call(c.children,m),s=r(i,o.domAtPos(t+1).node.parentElement),l=r(i,o.domAtPos(e-1).node.parentElement);for(let c=i.childElementCount-1;c>=0;c--)(c>l||c<s)&&n.removeChild(n.children[c]);Qt(),N=n;const d=o.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");N.className=N.className+" "+O.dragPreview+" "+d,document.body.appendChild(N)}function Qt(){N!==void 0&&(document.body.removeChild(N),N=void 0)}function xn(o,t){if(!o.dataTransfer)return;const e=t.dom.getBoundingClientRect(),n={left:e.left+e.width/2,top:o.clientY},i=Tn(n,t);if(i!=null){const r=t.state.selection,s=t.state.doc,{from:l,to:a}=Bn(r,s),d=l<=i&&i<a,c=r.$anchor.node()!==r.$head.node()||r instanceof V;d&&c?(t.dispatch(t.state.tr.setSelection(V.create(s,l,a))),Zt(t,l,a)):(t.dispatch(t.state.tr.setSelection(b.NodeSelection.create(t.state.doc,i))),Zt(t,i));const m=t.state.selection.content(),{dom:h,text:p}=Sn(t,m);o.dataTransfer.clearData(),o.dataTransfer.setData("text/html",h.innerHTML),o.dataTransfer.setData("text/plain",p),o.dataTransfer.effectAllowed="move",o.dataTransfer.setDragImage(N,0,0),t.dragging={slice:m,move:!0}}}class te{constructor(t,e,n){u(this,"sideMenuState");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!e||e.inside===-1){const n=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=i.left+i.width/2,n.clientY=t.clientY,n.dataTransfer=t.dataTransfer,n.preventDefault=()=>t.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!e||e.inside===-1){const n=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=i.left+i.width/2,n.clientY=t.clientY,n.dataTransfer=t.dataTransfer,n.preventDefault=()=>t.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onKeyDown",t=>{var e;(e=this.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});u(this,"onMouseMove",t=>{var d,c,m,h,p;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),n=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=n.left&&t.clientX<=n.right&&t.clientY>=n.top&&t.clientY<=n.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},l=Jt(s,this.pmView);if(!l||!this.editor.isEditable){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((m=this.sideMenuState)!=null&&m.show&&((h=this.hoveredBlock)!=null&&h.hasAttribute("data-id"))&&((p=this.hoveredBlock)==null?void 0:p.getAttribute("data-id"))===l.id)return;this.hoveredBlock=l.node;const a=l.node.firstChild;if(a&&this.editor.isEditable){const k=a.getBoundingClientRect();this.sideMenuState={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:k.x,k.y,k.width,k.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateSideMenu(this.sideMenuState)}});u(this,"onScroll",()=>{var t;if((t=this.sideMenuState)!=null&&t.show){const n=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:n.x,n.y,n.width,n.height),this.updateSideMenu(this.sideMenuState)}});this.editor=t,this.pmView=e,this.updateSideMenu=n,this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.sideMenuState)!=null&&l.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),n=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!n)return;const i=v(this.editor._tiptapEditor.state.doc,n.pos);if(i===void 0)return;const{contentNode:r,endPos:s}=i;if(r.textContent.length!==0){const a=s+1,d=a+2;this.editor._tiptapEditor.chain().BNCreateBlock(a).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.editor._tiptapEditor.commands.setTextSelection(s);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta($,{activate:!0,type:"drag"}))}}const ee=new b.PluginKey("SideMenuPlugin");class ne extends U{constructor(e){super();u(this,"sideMenuView");u(this,"plugin");u(this,"addBlock",()=>this.sideMenuView.addBlock());u(this,"blockDragStart",e=>{this.sideMenuView.isDragging=!0,xn(e,this.editor.prosemirrorView)});u(this,"blockDragEnd",()=>Qt());u(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=e,this.plugin=new b.Plugin({key:ee,view:n=>(this.sideMenuView=new te(e,n,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(e){return this.on("update",e)}}function L(o,t){const e=o.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain inline content.");e.content.length===1&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0?o.updateBlock(e,t):(o.insertBlocks([t],e,"after"),o.setTextCursorPosition(o.getTextCursorPosition().nextBlock))}const oe=(o=X)=>{var e,n,i;const t=[];return"heading"in o&&"level"in o.heading.propSchema&&((e=o.heading.propSchema.level.values)!=null&&e.includes(1)&&t.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>L(r,{type:"heading",props:{level:1}})}),(n=o.heading.propSchema.level.values)!=null&&n.includes(2)&&t.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>L(r,{type:"heading",props:{level:2}})}),(i=o.heading.propSchema.level.values)!=null&&i.includes(3)&&t.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>L(r,{type:"heading",props:{level:3}})})),"bulletListItem"in o&&t.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>L(r,{type:"bulletListItem"})}),"numberedListItem"in o&&t.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>L(r,{type:"numberedListItem"})}),"paragraph"in o&&t.push({name:"Paragraph",aliases:["p"],execute:r=>L(r,{type:"paragraph"})}),"image"in o&&t.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{L(r,{type:"image"}),r.setTextCursorPosition(r.getTextCursorPosition().nextBlock,"start"),r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(z,{block:r.getTextCursorPosition().prevBlock}))}}),t},Mn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class _n{constructor(t={}){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"ready",!1);u(this,"sideMenu");u(this,"formattingToolbar");u(this,"slashMenu");u(this,"hyperlinkToolbar");u(this,"imageToolbar");u(this,"uploadFile");var l,a,d,c,m;this.options=t;const e={defaultStyles:!0,blockSchema:t.blockSchema||X,...t};this.sideMenu=new ne(this),this.formattingToolbar=new Kt(this),this.slashMenu=new At(this,e.slashMenuItems||oe(e.blockSchema)),this.hyperlinkToolbar=new Yt(this),this.imageToolbar=new qt(this);const n=Pt({editor:this,domAttributes:e.domAttributes||{},blockSchema:e.blockSchema,collaboration:e.collaboration}),i=g.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin]});n.push(i),this.schema=e.blockSchema,this.uploadFile=e.uploadFile;const r=e.initialContent||(t.collaboration?void 0:[{type:"paragraph",id:q.options.generateID()}]),s={...Mn,...e._tiptapOptions,onBeforeCreate(h){if(!r)return;const p=h.editor.schema,k=p.node("doc",void 0,p.node("blockGroup",void 0,[F({id:"initialBlock",type:"paragraph"},p)]));h.editor.options.content=k.toJSON()},onCreate:()=>{var h;r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(h=e.onEditorReady)==null||h.call(e,this),this.ready=!0},onUpdate:()=>{var h;this.ready&&((h=e.onEditorContentChange)==null||h.call(e,this))},onSelectionUpdate:()=>{var h;this.ready&&((h=e.onTextCursorPositionChange)==null||h.call(e,this))},editable:t.editable===void 0?!0:t.editable,extensions:e.enableBlockNoteExtensions===!1?(l=e._tiptapOptions)==null?void 0:l.extensions:[...((a=e._tiptapOptions)==null?void 0:a.extensions)||[],...n],editorProps:{attributes:{...(d=e.domAttributes)==null?void 0:d.editor,class:x(O.bnEditor,O.bnRoot,e.defaultStyles?O.defaultStyles:"",((m=(c=e.domAttributes)==null?void 0:c.editor)==null?void 0:m.class)||"")}}};e.parentElement&&(s.element=e.parentElement),this._tiptapEditor=new g.Editor(s)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(P(e,this.schema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let n;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof n<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(n=P(i,this.schema,this.blockCache),!1)),n}forEachBlock(t,e=!1){const n=this.topLevelBlocks.slice();e&&n.reverse();function i(r){for(const s of r){if(!t(s))return!1;const l=e?s.children.slice().reverse():s.children;if(!i(l))return!1}return!0}i(n)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:n,endPos:i}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(e-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let l;r>0&&(l=this._tiptapEditor.state.doc.resolve(n-2).node());let a;return r<s-1&&(a=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:P(t,this.schema,this.blockCache),prevBlock:l===void 0?void 0:P(l,this.schema,this.blockCache),nextBlock:a===void 0?void 0:P(a,this.schema,this.blockCache)}}setTextCursorPosition(t,e="start"){const n=typeof t=="string"?t:t.id,{posBeforeNode:i}=j(n,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=v(this._tiptapEditor.state.doc,i+2);if(s.type.spec.content===""){this._tiptapEditor.commands.setNodeSelection(r);return}e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const t=[];return this._tiptapEditor.state.doc.descendants((e,n)=>e.type.spec.group!=="blockContent"||n+e.nodeSize<this._tiptapEditor.state.selection.from||n>this._tiptapEditor.state.selection.to?!0:(t.push(P(this._tiptapEditor.state.doc.resolve(n).node(),this.schema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.setEditable(t)}insertBlocks(t,e,n="before"){Nt(t,e,n,this._tiptapEditor)}updateBlock(t,e){on(t,e,this._tiptapEditor)}removeBlocks(t){Ht(t,this._tiptapEditor)}replaceBlocks(t,e){rn(t,e,this._tiptapEditor)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks(),n=new Set(["bold","italic","underline","strike","code"]),i=new Set(["textColor","backgroundColor"]);for(const r of e)n.has(r.type.name)?t[r.type.name]=!0:i.has(r.type.name)&&(t[r.type.name]=r.attrs.color);return t}addStyles(t){const e=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[i,r]of Object.entries(t))e.has(i)?this._tiptapEditor.commands.setMark(i):n.has(i)&&this._tiptapEditor.commands.setMark(i,{color:r})}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){const e=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[i,r]of Object.entries(t))e.has(i)?this._tiptapEditor.commands.toggleMark(i):n.has(i)&&this._tiptapEditor.commands.toggleMark(i,{color:r})}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(t,e){if(t==="")return;const{from:n,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(n,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,n,i).addMark(n,n+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(e-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(t){return Lt(t,this._tiptapEditor.schema)}async HTMLToBlocks(t){return Dt(t,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(t){return ln(t,this._tiptapEditor.schema)}async markdownToBlocks(t){return cn(t,this.schema,this._tiptapEditor.schema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}}const In=async o=>{const t=new FormData;return t.append("file",o),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};f.BlockNoteEditor=_n,f.CustomBlockSerializerExtension=_t,f.FormattingToolbarProsemirrorPlugin=Kt,f.FormattingToolbarView=Gt,f.HyperlinkToolbarProsemirrorPlugin=Yt,f.ImageToolbarProsemirrorPlugin=qt,f.ImageToolbarView=Ut,f.SideMenuProsemirrorPlugin=ne,f.SideMenuView=te,f.SlashMenuProsemirrorPlugin=At,f.UnreachableCaseError=it,f.blockStyles=Fe,f.camelToDataKebab=K,f.createBlockSpec=Vt,f.createTipTapBlock=R,f.defaultBlockSchema=X,f.defaultProps=T,f.formatKeyboardShortcut=De,f.formattingToolbarPluginKey=jt,f.getBlockNoteExtensions=Pt,f.getDefaultSlashMenuItems=oe,f.hyperlinkToolbarPluginKey=Xt,f.imageToolbarPluginKey=z,f.isAppleOS=ot,f.mergeCSSClasses=x,f.parse=Rt,f.propsToAttributes=Ot,f.render=zt,f.setupSuggestionsMenu=It,f.sideMenuPluginKey=ee,f.slashMenuPluginKey=$,f.uploadToTmpFilesDotOrg_DEV_ONLY=In,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
8
8
  //# sourceMappingURL=blocknote.umd.cjs.map