@blocknote/core 0.12.1 → 0.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.js +5 -5
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +1 -1
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -2
- package/src/editor/editor.css +0 -1
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +4 -7
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
`;else throw new Error("unexpected");else i={type:"text",text:`
|
|
5
5
|
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&t[r.type.name]){i&&(o.push(i),i=void 0),o.push(mt(r,t,e));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const c=e[l.type.name];if(!c)throw new Error(`style ${l.type.name} not found in styleSchema`);if(c.propSchema==="boolean")s[c.type]=!0;else if(c.propSchema==="string")s[c.type]=l.attrs.stringValue;else throw new L(c.propSchema)}i?K(i)?a?(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):JSON.stringify(i.styles)===JSON.stringify(s)?i.text+=r.textContent:(o.push(i),i={type:"text",text:r.textContent,styles:s}):dt(i)&&(a?i.href===a.attrs.href?JSON.stringify(i.content[i.content.length-1].styles)===JSON.stringify(s)?i.content[i.content.length-1].text+=r.textContent:i.content.push({type:"text",text:r.textContent,styles:s}):(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):(o.push(i),i={type:"text",text:r.textContent,styles:s})):a?i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}:i={type:"text",text:r.textContent,styles:s}}),i&&o.push(i),o}function mt(n,t,e){if(n.type.name==="text"||n.type.name==="link")throw new Error("unexpected");const o={},i=t[n.type.name];for(const[a,l]of Object.entries(n.attrs)){if(!i)throw Error("ic node is of an unrecognized type: "+n.type.name);const c=i.propSchema;a in c&&(o[a]=l)}let r;return i.content==="styled"?r=ot(n,t,e):r=void 0,{type:n.type.name,props:o,content:r}}function S(n,t,e,o,i){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const r=i==null?void 0:i.get(n);if(r)return r;const s=Ft(n);let a=s.id;a===null&&(a=G.options.generateID());const l={};for(const[m,g]of Object.entries({...n.attrs,...s.contentNode.attrs})){const E=t[s.contentType.name];if(!E)throw Error("Block is of an unrecognized type: "+s.contentType.name);const I=E.propSchema;m in I&&(l[m]=g)}const c=t[s.contentType.name],h=[];for(let m=0;m<s.numChildBlocks;m++)h.push(S(n.lastChild.child(m),t,e,o,i));let p;if(c.content==="inline")p=ot(s.contentNode,e,o);else if(c.content==="table")p=kn(s.contentNode,e,o);else if(c.content==="none")p=void 0;else throw new L(c.content);const f={id:a,type:c.type,props:l,content:p,children:h};return i==null||i.set(n,f),f}function yn(n){return n.document||window.document}const $t=(n,t,e,o,i)=>{if(!e.nodes[n.type.name])throw new Error("Serializer is missing a node type: "+n.type.name);const{dom:r,contentDOM:s}=y.DOMSerializer.renderSpec(yn(t),e.nodes[n.type.name](n));if(s){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(n.type.name==="blockContainer"){const a=n.childCount>0&&n.firstChild.type.spec.group==="blockContent"?n.firstChild:void 0,l=n.childCount>0&&n.lastChild.type.spec.group==="blockGroup"?n.lastChild:void 0;if(a!==void 0){const c=o.blockImplementations[a.type.name].implementation,p=(i?c.toExternalHTML:c.toInternalHTML)(S(n,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache),o);if(p.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");p.contentDOM.appendChild(e.serializeFragment(a.content,t))}s.appendChild(p.dom)}l!==void 0&&e.serializeFragment(y.Fragment.from(l),t,s)}else e.serializeFragment(n.content,t,s)}return r},Gt=(n,t)=>{const e=t.serializeFragment(n),o=document.createElement("div");return o.appendChild(e),o.innerHTML};function wn(n){const t=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),e=o=>{var s;if(o.children.length===1&&((s=o.children[0].properties)==null?void 0:s.dataNodeType)==="blockGroup"){const a=o.children[0];o.children.pop(),o.children.push(...a.children)}let i=o.children.length,r;for(let a=0;a<i;a++){const c=o.children[a].children[0],h=c.children[0],p=c.children.length===2?c.children[1]:null,f=t.has(h.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(h.properties.dataContentType)?"ol":"ul":null;if(p!==null&&e(p),r&&r.tagName!==m){o.children.splice(a-r.children.length,r.children.length,r);const g=r.children.length-1;a-=g,i-=g,r=void 0}if(f){r||(r=Dt.fromDom(document.createElement(m)));const g=Dt.fromDom(document.createElement("li"));g.children.push(h.children[0]),p!==null&&g.children.push(...p.children),r.children.push(g)}else if(p!==null){o.children.splice(a+1,0,...p.children),o.children[a]=h.children[0];const g=p.children.length;a+=g,i+=g}else o.children[a]=h.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return e}const Z=(n,t)=>{const e=y.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>$t(o,i,e,t,!0),e.exportProseMirrorFragment=o=>ct.unified().use(Ut.default,{fragment:!0}).use(wn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(Rt.default).processSync(Gt(o,e)).value,e.exportBlocks=o=>{const i=o.map(s=>N(s,n,t.schema.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.exportProseMirrorFragment(y.Fragment.from(r))},e},ft=(n,t)=>{const e=y.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>$t(o,i,e,t,!1),e.serializeProseMirrorFragment=o=>Gt(o,e),e.serializeBlocks=o=>{const i=o.map(s=>N(s,n,t.schema.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.serializeProseMirrorFragment(y.Fragment.from(r))},e},vn=async n=>{const t=new FormData;return t.append("file",n),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},Kt=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function V(n){return Kt()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function O(...n){return n.filter(t=>t).join(" ")}const En=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function tt(n,t,e,o){const i=document.createElement("div");i.className=O("bn-block-content",e.class),i.setAttribute("data-content-type",n);for(const[s,a]of Object.entries(e))s!=="class"&&i.setAttribute(s,a);const r=document.createElement(t);r.className=O("bn-inline-content",o.class);for(const[s,a]of Object.entries(o))s!=="class"&&r.setAttribute(s,a);return i.appendChild(r),{dom:i,contentDOM:r}}const jt=(n,t)=>{const e=N(n,t._tiptapEditor.schema,t.schema.styleSchema).firstChild,o=t._tiptapEditor.schema.nodes[e.type.name].spec.toDOM;if(o===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const i=o(e);if(typeof i!="object"||!("dom"in i))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return i},C={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},gt=["backgroundColor","textColor"];function et(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function bt(n){const t={};return Object.entries(n).filter(([e,o])=>!gt.includes(e)).forEach(([e,o])=>{t[e]={default:o.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(et(e));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[e]!==o.default?{[et(e)]:i[e]}:{}}}),t}function Wt(n,t,e,o){if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const i=n(),s=e.state.doc.resolve(i).node().attrs.id,a=t.getBlock(s);if(a.type!==o)throw new Error("Block type does not match");return a}function it(n,t,e,o,i){const r=document.createElement("div");if(i!==void 0)for(const[s,a]of Object.entries(i))s!=="class"&&r.setAttribute(s,a);r.className=O("bn-block-content",(i==null?void 0:i.class)||""),r.setAttribute("data-content-type",t);for(const[s,a]of Object.entries(e))!gt.includes(s)&&a!==o[s].default&&r.setAttribute(et(s),a);return r.appendChild(n.dom),n.contentDOM!==void 0&&(n.contentDOM.className=O("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function q(n){return b.Node.create(n)}function kt(n,t){return{config:n,implementation:t}}function j(n,t,e){return kt({type:n.name,content:n.config.content==="inline*"?"inline":n.config.content==="tableRow+"?"table":"none",propSchema:t},{node:n,requiredExtensions:e,toInternalHTML:jt,toExternalHTML:jt})}function yt(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function Jt(n,t){const e=[{tag:"[data-content-type="+n.type+"]",contentElement:"[data-editable]"}];return t&&e.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const i=t==null?void 0:t(o);return i===void 0?!1:i}}),e}function Xt(n,t){const e=q({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return bt(n.propSchema)},parseHTML(){return Jt(n,t.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const i=this.options.editor,r=Wt(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=t.render(r,i);return it(a,r.type,r.props,n.propSchema,s)}}});if(e.name!==n.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return kt(n,{node:e,toInternalHTML:(o,i)=>{var a;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{},s=t.render(o,i);return it(s,o.type,o.props,n.propSchema,r)},toExternalHTML:(o,i)=>{var a,l;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{};let s=(l=t.toExternalHTML)==null?void 0:l.call(t,o,i);return s===void 0&&(s=t.render(o,i)),it(s,o.type,o.props,n.propSchema,r)}})}function Yt(n,t,e,o){return n.dom.setAttribute("data-inline-content-type",t),Object.entries(e).filter(([i,r])=>r!==o[i].default).map(([i,r])=>[et(i),r]).forEach(([i,r])=>n.dom.setAttribute(i,r)),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Qt(n){return{Backspace:({editor:t})=>{const e=t.state.selection.$from;return t.state.selection.empty&&e.node().type.name===n.type&&e.parentOffset===0}}}function Zt(n,t){return{config:n,implementation:t}}function te(n,t){return Zt({type:n.name,propSchema:t,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function wt(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function ee(n){return[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function Sn(n,t){const e=b.Node.create({name:n.type,inline:!0,group:"inline",selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return bt(n.propSchema)},addKeyboardShortcuts(){return Qt(n)},parseHTML(){return ee(n)},renderHTML({node:o}){const i=this.options.editor,r=t.render(mt(o,i.schema.inlineContentSchema,i.schema.styleSchema));return Yt(r,n.type,o.attrs,n.propSchema)}});return te(e,n.propSchema)}function ne(n){return n==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:t=>t.getAttribute("data-value"),renderHTML:t=>t.stringValue!==void 0?{"data-value":t.stringValue}:{}}}}function oe(n,t,e,o){return n.dom.setAttribute("data-style-type",t),o==="string"&&n.dom.setAttribute("data-value",e),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function vt(n,t){return{config:n,implementation:t}}function U(n,t){return vt({type:n.name,propSchema:t},{mark:n})}function Et(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function ie(n){return[{tag:`[data-style-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function Cn(n,t){const e=b.Mark.create({name:n.type,addAttributes(){return ne(n.propSchema)},parseHTML(){return ie(n)},renderHTML({mark:o}){let i;if(n.propSchema==="boolean")i=t.render();else if(n.propSchema==="string")i=t.render(o.attrs.stringValue);else throw new L(n.propSchema);return oe(i,n.type,o.attrs.stringValue,n.propSchema)}});return vt(n,{mark:e})}const Tn=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{stringValue:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),xn=U(Tn,"string"),Bn=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{stringValue:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Mn=U(Bn,"string"),A=n=>{const{contentType:t}=w(n.state.doc,n.state.selection.from);return t.spec.content},In={...C,level:{default:1,values:[1,2,3]}},Ln=q({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:n=>{const t=n.getAttribute("data-level"),e=parseInt(t);if(isFinite(e))return e},renderHTML:n=>({"data-level":n.level.toString()})}}},addInputRules(){return[...[1,2,3].map(n=>new b.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:t,chain:e,range:o})=>{A(this.editor)==="inline*"&&e().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:n=>typeof n=="string"?!1:{level:n.getAttribute("data-level")}},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:n,HTMLAttributes:t}){var e,o;return tt(this.name,`h${n.attrs.level}`,{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...t},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),Pn=j(Ln,In),Nn={textAlignment:C.textAlignment,backgroundColor:C.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},re=n=>{switch(n){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},se=64,An=Xt({type:"image",propSchema:Nn,content:"none"},{render:(n,t)=>{const e=document.createElement("div");e.className="bn-image-block-content-wrapper",e.style.alignItems=re(n.props.textAlignment);const o=document.createElement("div");o.className="bn-add-image-button";const i=document.createElement("div");i.className="bn-add-image-button-icon";const r=document.createElement("p");r.className="bn-add-image-button-text",r.innerText="Add Image";const s=document.createElement("div");s.className="bn-image-and-caption-wrapper";const a=document.createElement("div");a.className="bn-image-wrapper";const l=document.createElement("img");l.className="bn-image",l.src=n.props.url,l.alt="placeholder",l.contentEditable="false",l.draggable=!1,l.style.width=`${Math.min(n.props.width,t.domElement.firstElementChild.clientWidth)}px`;const c=document.createElement("div");c.className="bn-image-resize-handle",c.style.left="4px";const h=document.createElement("div");h.className="bn-image-resize-handle",h.style.right="4px";const p=document.createElement("p");p.className="bn-image-caption",p.innerText=n.props.caption,p.style.padding=n.props.caption?"4px":"";const f=()=>{var Ht;const v=((Ht=t.getSelection())==null?void 0:Ht.blocks)||[];[t.getTextCursorPosition().block,...v].find(lt=>lt.id===n.id)!==void 0?(o.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(o.style.outline="",s.style.outline="")};t.onEditorContentChange(f),t.onEditorSelectionChange(f);let m;const g=v=>{if(!m){!t.isEditable&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h));return}let _;re(n.props.textAlignment)==="center"?m.handleUsed==="left"?_=m.initialWidth+(m.initialClientX-v.clientX)*2:_=m.initialWidth+(v.clientX-m.initialClientX)*2:m.handleUsed==="left"?_=m.initialWidth+m.initialClientX-v.clientX:_=m.initialWidth+v.clientX-m.initialClientX,_<se?l.style.width=`${se}px`:_>t.domElement.firstElementChild.clientWidth?l.style.width=`${t.domElement.firstElementChild.clientWidth}px`:l.style.width=`${_}px`},E=v=>{(!v.target||!a.contains(v.target)||!t.isEditable)&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h)),m&&(m=void 0,t.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},I=v=>{v.preventDefault()},D=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(t.imagePanel.plugin,{block:n}))},B=()=>{t.isEditable&&(a.appendChild(c),a.appendChild(h))},$=v=>{v.relatedTarget===c||v.relatedTarget===h||m||t.isEditable&&a.contains(c)&&a.contains(h)&&(a.removeChild(c),a.removeChild(h))},Y=v=>{v.preventDefault(),a.appendChild(c),a.appendChild(h),m={handleUsed:"left",initialWidth:n.props.width,initialClientX:v.clientX}},nt=v=>{v.preventDefault(),a.appendChild(c),a.appendChild(h),m={handleUsed:"right",initialWidth:n.props.width,initialClientX:v.clientX}};return o.appendChild(i),o.appendChild(r),s.appendChild(a),a.appendChild(l),s.appendChild(p),n.props.url===""?e.appendChild(o):e.appendChild(s),window.addEventListener("mousemove",g),window.addEventListener("mouseup",E),o.addEventListener("mousedown",I),o.addEventListener("click",D),l.addEventListener("mouseenter",B),l.addEventListener("mouseleave",$),c.addEventListener("mousedown",Y),h.addEventListener("mousedown",nt),{dom:e,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",E),o.removeEventListener("mousedown",I),o.removeEventListener("click",D),c.removeEventListener("mousedown",Y),h.removeEventListener("mousedown",nt)}}},toExternalHTML:n=>{if(n.props.url===""){const o=document.createElement("p");return o.innerHTML="Add Image",{dom:o}}const t=document.createElement("figure"),e=document.createElement("img");if(e.src=n.props.url,t.appendChild(e),n.props.caption!==""){const o=document.createElement("figcaption");o.innerHTML=n.props.caption,t.appendChild(o)}return{dom:t}},parse:n=>{if(n.tagName==="FIGURE"){const t=n.querySelector("img"),e=n.querySelector("figcaption");return{url:(t==null?void 0:t.getAttribute("src"))||"",caption:(e==null?void 0:e.textContent)||(t==null?void 0:t.getAttribute("alt"))||void 0}}else if(n.tagName==="IMG")return{url:n.getAttribute("src")||"",caption:n.getAttribute("alt")||void 0}}}),St=n=>{const{node:t,contentType:e}=w(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!(e.name==="bulletListItem"||e.name==="numberedListItem")||!o?!1:n.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={...C},Dn=q({name:"bulletListItem",content:"inline*",group:"blockContent",addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:t,range:e})=>{A(this.editor)==="inline*"&&t().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>St(this.editor),"Mod-Shift-8":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="UL"||t.tagName==="DIV"&&t.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),_n=j(Dn,Hn),On=new k.PluginKey("numbered-list-indexing"),Un=()=>new k.Plugin({key:On,appendTransaction:(n,t,e)=>{const o=e.tr;o.setMeta("numberedListIndexing",!0);let i=!1;return e.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,c=w(o.doc,s+1);if(c===void 0)return;if(!l){const f=w(o.doc,s-2);if(f===void 0)return;if(!(c.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const D=g.attrs.index;a=(parseInt(D)+1).toString()}}}c.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),Rn={...C},zn=q({name:"numberedListItem",content:"inline*",group:"blockContent",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:t,range:e})=>{A(this.editor)==="inline*"&&t().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>St(this.editor),"Mod-Shift-7":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[Un()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="OL"||t.tagName==="DIV"&&t.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Fn=j(zn,Rn),Vn={...C},qn=q({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{Enter:()=>St(this.editor),"Mod-Alt-0":()=>A(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"paragraph",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),$n=j(qn,Vn),Gn=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[_t.columnResizing({cellMinWidth:100}),_t.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.setHardBreak(),!0):!1,Backspace:()=>{const n=this.editor.state.selection,t=n.empty,e=n.$head.parentOffset===0,o=n.$head.node().type.name==="tableParagraph";return t&&e&&o}}},extendNodeSchema(n){const t={name:n.name,options:n.options,storage:n.storage};return{tableRole:b.callOrReturn(b.getExtensionField(n,"tableRole",t))}}}),Kn={...C},jn=q({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var t,e;return tt(this.name,"table",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Wn=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",b.mergeAttributes(this.options.HTMLAttributes,n),0]}}),Jn=j(jn,Kn,[Gn,Wn,qe.TableHeader.extend({content:"tableContent"}),Ve.TableCell.extend({content:"tableContent"}),$e.TableRow]),Ct={paragraph:$n,heading:Pn,bulletListItem:_n,numberedListItem:Fn,image:An,table:Jn},ae=yt(Ct),Tt={bold:U(on.default,"boolean"),italic:U(sn.default,"boolean"),underline:U(ln.default,"boolean"),strike:U(an.default,"boolean"),code:U(rn.default,"boolean"),textColor:Mn,backgroundColor:xn},Xn=Et(Tt),xt={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Yn=wt(xt);function P(n,t){return n in t.schema.blockSchema&&t.schema.blockSchema[n]===ae[n]}function Qn(n,t,e){return t.type===n&&t.type in e.schema.blockSchema&&P(t.type,e)}function le(n,t,e){return t in e.schema.blockSchema&&n in e.schema.blockSchema[t].propSchema&&e.schema.blockSchema[t].propSchema[n]===C[n]}function Zn(n,t,e){return le(n,t.type,e)}function Bt(n,t){let e,o;if(t.firstChild.descendants((i,r)=>e?!1:i.type.name!=="blockContainer"||i.attrs.id!==n?!0:(e=i,o=r+1,!1)),e===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:o}}function to(n,t,e="before",o){const i=o._tiptapEditor,r=typeof t=="string"?t:t.id,s=[];for(const h of n)s.push(N(h,i.schema,o.schema.styleSchema));const{node:a,posBeforeNode:l}=Bt(r,i.state.doc);if(e==="before"&&i.view.dispatch(i.state.tr.insert(l,s)),e==="after"&&i.view.dispatch(i.state.tr.insert(l+a.nodeSize,s)),e==="nested"&&a.childCount<2){const h=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(l+a.firstChild.nodeSize+1,h))}const c=[];for(const h of s)c.push(S(h,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache));return c}function eo(n,t,e){const o=e._tiptapEditor,i=typeof n=="string"?n:n.id,{posBeforeNode:r}=Bt(i,o.state.doc);o.commands.BNUpdateBlock(r+1,t);const s=o.state.doc.resolve(r+1).node();return S(s,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache)}function ce(n,t,e){const o=t._tiptapEditor,i=o.state.tr,r=new Set(n.map(l=>typeof l=="string"?l:l.id)),s=[];let a=0;if(o.state.doc.descendants((l,c)=>{if(r.size===0)return!1;if(l.type.name!=="blockContainer"||!r.has(l.attrs.id))return!0;s.push(S(l,t.schema.blockSchema,t.schema.inlineContentSchema,t.schema.styleSchema,t.blockCache)),r.delete(l.attrs.id),a=(e==null?void 0:e(l,c,i,a))||a;const h=i.doc.nodeSize;i.delete(c-a-1,c-a+l.nodeSize+1);const p=i.doc.nodeSize;return a+=h-p,!1}),r.size>0){const l=[...r].join(`
|
|
6
6
|
`);throw Error("Blocks with the following IDs could not be found in the editor: "+l)}return o.view.dispatch(i),s}function no(n,t){return ce(n,t)}function oo(n,t,e){const o=e._tiptapEditor,i=[];for(const l of t)i.push(N(l,o.schema,e.schema.styleSchema));const r=typeof n[0]=="string"?n[0]:n[0].id,s=ce(n,e,(l,c,h,p)=>{if(l.attrs.id===r){const f=h.doc.nodeSize;h.insert(c,i);const m=h.doc.nodeSize;return p+f-m}return p}),a=[];for(const l of i)a.push(S(l,e.schema.blockSchema,e.schema.inlineContentSchema,e.schema.styleSchema,e.blockCache));return{insertedBlocks:a,removedBlocks:s}}function io(n,t,e,o={updateSelection:!0}){const i=e._tiptapEditor,r=i.state.tr;let{from:s,to:a}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},l=!0,c=!0,h="";if(t.forEach(p=>{p.check(),l&&p.isText&&p.marks.length===0?h+=p.text:l=!1,c=c?p.isBlock:!1}),s===a&&c){const{parent:p}=r.doc.resolve(s);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(s-=1,a+=1)}return l?r.insertText(h,s,a):r.replaceWith(s,a,t),o.updateSelection&&b.selectionToInsertionEnd(r,r.steps.length-1,-1),i.view.dispatch(r),!0}function ro(){const n=t=>{let e=t.children.length;for(let o=0;o<e;o++){const i=t.children[o];if(i.type==="element"&&(n(i),i.tagName==="u"))if(i.children.length>0){t.children.splice(o,1,...i.children);const r=i.children.length-1;e+=r,o+=r}else t.children.splice(o,1),e--,o--}};return n}function Mt(n){return ct.unified().use(Ut.default,{fragment:!0}).use(ro).use(cn.default).use(zt.default).use(dn.default).processSync(n).value}function so(n,t,e){const i=Z(t,e).exportBlocks(n);return Mt(i)}function ao(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function lo(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function co(n){n.querySelectorAll("li > ul, li > ol").forEach(t=>{const e=ao(t),o=t.parentElement,i=Array.from(o.childNodes).slice(e+1);t.remove(),i.forEach(r=>{r.remove()}),o.insertAdjacentElement("afterend",t),i.reverse().forEach(r=>{if(lo(r))return;const s=document.createElement("li");s.append(r),t.insertAdjacentElement("afterend",s)}),o.childNodes.length===0&&o.remove()})}function uo(n){n.querySelectorAll("li + ul, li + ol").forEach(t=>{var r,s;const e=t.previousElementSibling,o=document.createElement("div");e.insertAdjacentElement("afterend",o),o.append(e);const i=document.createElement("div");for(i.setAttribute("data-node-type","blockGroup"),o.append(i);((r=o.nextElementSibling)==null?void 0:r.nodeName)==="UL"||((s=o.nextElementSibling)==null?void 0:s.nodeName)==="OL";)i.append(o.nextElementSibling)})}let de=null;function ho(){return de||(de=document.implementation.createHTMLDocument("title"))}function ue(n){if(typeof n=="string"){const t=ho().createElement("div");t.innerHTML=n,n=t}return co(n),uo(n),n}async function he(n,t,e,o,i){const r=ue(n),a=y.DOMParser.fromSchema(i).parse(r,{topNode:i.nodes.blockGroup.create()}),l=[];for(let c=0;c<a.childCount;c++)l.push(S(a.child(c),t,e,o));return l}function po(n,t){const e=t.value?t.value+`
|
|
7
|
-
`:"",o={};t.lang&&(o["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),n.patch(t,i),i=n.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(t,i),i}function mo(n,t,e,o,i){const r=ct.unified().use(un.default).use(zt.default).use(hn.default,{handlers:{...Ot.defaultHandlers,code:po}}).use(Rt.default).processSync(n);return he(r.value,t,e,o,i)}class W{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 o=this.callbacks[t];o&&o.forEach(i=>i.apply(this,e))}off(t,e){const o=this.callbacks[t];o&&(e?this.callbacks[t]=o.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class pe{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({state:t})=>!t.selection.empty);u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",t=>{var o;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragHandler),e.dom.addEventListener("dragover",this.dragHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var f,m;const{state:o,composing:i}=t,{doc:r,selection:s}=o,a=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,c=Math.min(...l.map(g=>g.$from.pos)),h=Math.max(...l.map(g=>g.$to.pos)),p=(f=this.shouldShow)==null?void 0:f.call(this,{view:t,state:o,from:c,to:h});if(this.editor.isEditable&&!this.preventShow&&(p||this.preventHide)){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((m=this.state)!=null&&m.show&&!this.preventHide&&(!p||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),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:o}=e,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const me=new k.PluginKey("FormattingToolbarPlugin");class fe extends W{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new k.Plugin({key:me,view:o=>(this.view=new pe(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class fo{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredLinkMark");u(this,"mouseHoveredLinkMarkRange");u(this,"keyboardHoveredLinkMark");u(this,"keyboardHoveredLinkMarkRange");u(this,"linkMark");u(this,"linkMarkRange");u(this,"mouseOverHandler",t=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=s,this.mouseHoveredLinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var o;const e=this.pmView.dom.parentElement;this.linkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;this.linkMark!==void 0&&(t=this.state)!=null&&t.show&&(this.state.referencePos=b.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},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)}editLink(t,e){var i;const o=this.pmView.state.tr.insertText(e,this.linkMarkRange.from,this.linkMarkRange.to);o.addMark(this.linkMarkRange.from,this.linkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.state)!=null&&i.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=i,this.keyboardHoveredLinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable){this.state={show:!0,referencePos:b.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},this.emitUpdate();return}if((e=this.state)!=null&&e.show&&t&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const ge=new k.PluginKey("LinkToolbarPlugin");class be extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"editLink",(e,o)=>{this.view.editLink(e,o)});u(this,"deleteLink",()=>{this.view.deleteLink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new k.Plugin({key:ge,view:o=>(this.view=new fo(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}const go=b.findParentNode(n=>n.type.name==="blockContainer");class bo{constructor(t,e){u(this,"state");u(this,"emitUpdate");u(this,"pluginState");u(this,"handleScroll",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.view.state.tr.setMeta(R,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-(this.pluginState.fromUserInput?this.pluginState.triggerCharacter.length:0),to:this.editor._tiptapEditor.state.selection.from}).run()});this.editor=t,this.pluginState=void 0,this.emitUpdate=o=>{if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");e(o,this.state)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const o=R.getState(e),i=R.getState(t.state),r=o===void 0&&i!==void 0,s=o!==void 0&&i===void 0;if(!r&&!(o!==void 0&&i!==void 0)&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.state.show=!1,this.emitUpdate(this.pluginState.triggerCharacter);return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){document.removeEventListener("scroll",this.handleScroll)}}const R=new k.PluginKey("SuggestionMenuPlugin");class ke extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)});u(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==e)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new k.Plugin({key:R,view:()=>(this.view=new bo(e,(i,r)=>{this.emit(`update ${i}`,r)}),this.view),state:{init(){},apply(i,r,s,a){if(i.getMeta("orderedListIndexing")!==void 0)return r;const l=i.getMeta(R);if(typeof l=="object"&&l!==null&&r===void 0)return{triggerCharacter:l.triggerCharacter,fromUserInput:l.fromUserInput!==!1,queryStartPos:a.selection.from,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(r===void 0)return r;if(a.selection.from!==a.selection.to||l===null||i.getMeta("focus")||i.getMeta("blur")||i.getMeta("pointer")||r.triggerCharacter!==void 0&&a.selection.from<r.queryStartPos)return;const c={...r};return c.query=a.doc.textBetween(r.queryStartPos,a.selection.from),c}},props:{handleKeyDown(i,r){const s=this.getState(i.state);return o.includes(r.key)&&s===void 0?(r.preventDefault(),i.dispatch(i.state.tr.insertText(r.key).scrollIntoView().setMeta(R,{triggerCharacter:r.key})),!0):!1},decorations(i){const r=this.getState(i);if(r===void 0)return null;if(!r.fromUserInput){const s=go(i.selection);if(s)return x.DecorationSet.create(i.doc,[x.Decoration.node(s.pos,s.pos+s.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}return x.DecorationSet.create(i.doc,[x.Decoration.inline(r.queryStartPos-r.triggerCharacter.length,r.queryStartPos,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}}})}onUpdate(e,o){return this.triggerCharacters.includes(e)||this.addTriggerCharacter(e),this.on(`update ${e}`,o)}}function ko(n,t){n.suggestionMenus.addTriggerCharacter(t)}class J extends k.Selection{constructor(e,o){super(e,o);u(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(e,o,i=o){return new J(e.resolve(o),e.resolve(i))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof J)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?k.Selection.near(e.resolve(i.pos)):i.deleted?k.Selection.near(e.resolve(r.pos)):new J(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let z;function rt(n,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(n);if(!e)return;let o=t.domAtPos(e.pos).node;if(o!==t.dom){for(;o&&o.parentNode&&o.parentNode!==t.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function yo(n,t){const e=rt(n,t);if(e&&e.node.nodeType===1){const o=t.docView,i=o.nearestDesc(e.node,!0);return!i||i===o?null:i.posBefore}return null}function wo(n,t){let e,o;const i=t.resolve(n.from).node().type.spec.group==="blockContent",r=t.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);e=t.resolve(a-1).pos,o=t.resolve(l+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function ye(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),i=n.domAtPos(t).node,r=(h,p)=>Array.prototype.indexOf.call(h.children,p),s=r(i,n.domAtPos(t+1).node.parentElement),a=r(i,n.domAtPos(e-1).node.parentElement);for(let h=i.childElementCount-1;h>=0;h--)(h>a||h<s)&&o.removeChild(o.children[h]);we(),z=o;const c=n.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");z.className=z.className+" bn-drag-preview "+c,document.body.appendChild(z)}function we(){z!==void 0&&(document.body.removeChild(z),z=void 0)}function vo(n,t){if(!n.dataTransfer)return;const e=t.prosemirrorView,o=e.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=yo(i,e);if(r!=null){const s=e.state.selection,a=e.state.doc,{from:l,to:c}=wo(s,a),h=l<=r&&r<c,p=s.$anchor.node()!==s.$head.node()||s instanceof J;h&&p?(e.dispatch(e.state.tr.setSelection(J.create(a,l,c))),ye(e,l,c)):(e.dispatch(e.state.tr.setSelection(k.NodeSelection.create(e.state.doc,r))),ye(e,r));const f=e.state.selection.content(),m=t._tiptapEditor.schema,E=ft(m,t).serializeProseMirrorFragment(f.content),D=Z(m,t).exportProseMirrorFragment(f.content),B=Mt(D);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",E),n.dataTransfer.setData("text/html",D),n.dataTransfer.setData("text/plain",B),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(z,0,0),e.dragging={slice:f,move:!0}}}class ve{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");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 o=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});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 o=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onKeyDown",t=>{var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseDown",t=>{this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseMove",t=>{var c,h,p,f,m;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=o.left&&t.clientX<=o.right&&t.clientY>=o.top&&t.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},a=rt(s,this.pmView);if(!a||!this.editor.isEditable){(h=this.state)!=null&&h.show&&(this.state.show=!1,this.emitUpdate(this.state));return}if((p=this.state)!=null&&p.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.state={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.emitUpdate(this.state)}});u(this,"onScroll",()=>{var t;if((t=this.state)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.state.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.emitUpdate(this.state)}});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},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("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate(this.state)),document.body.removeEventListener("mousemove",this.onMouseMove,!0),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("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.state)!=null&&l.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const i=w(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,startPos:s,endPos:a}=i;if(r.type.spec.content!=="inline*"||r.textContent.length!==0){const c=a+1,h=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).setTextSelection(h).run()}else this.editor._tiptapEditor.commands.setTextSelection(s+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(R,{triggerCharacter:"/",fromUserInput:!1}))}}const Ee=new k.PluginKey("SideMenuPlugin");class Se extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"addBlock",()=>this.view.addBlock());u(this,"blockDragStart",e=>{this.view.isDragging=!0,vo(e,this.editor)});u(this,"blockDragEnd",()=>we());u(this,"freezeMenu",()=>this.view.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.view.menuFrozen=!1);this.editor=e,this.plugin=new k.Plugin({key:Ee,view:o=>(this.view=new ve(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class Ce{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"prevWasEditable",null);u(this,"mouseDownHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"dragstartHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"blurHandler",t=>{var o;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate()}});this.pluginKey=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image panel");o(this.state)},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 o=this.pluginKey.getState(t.state);if(!((i=this.state)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.state={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate())}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 It=new k.PluginKey("ImagePanelPlugin");class Te extends W{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new k.Plugin({key:It,view:o=>(this.view=new Ce(It,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(It))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}let M;function xe(){M||(M=document.createElement("div"),M.innerHTML="_",M.style.opacity="0",M.style.height="1px",M.style.width="1px",document.body.appendChild(M))}function Eo(){M&&(document.body.removeChild(M),M=void 0)}function st(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function So(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Co(n){n.forEach(t=>{const e=document.getElementsByClassName(t);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"})}class Be{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"menuFrozen",!1);u(this,"prevWasEditable",null);u(this,"mouseMoveHandler",t=>{var c;if(this.menuFrozen)return;const e=So(t.target);if(!e||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate());return}const o=st(e),i=st(e.parentElement),r=e.getBoundingClientRect(),s=e.parentElement.parentElement.getBoundingClientRect(),a=rt(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((h,p)=>typeof l<"u"?!1:h.type.name!=="blockContainer"||h.attrs.id!==a.id?!0:(l=S(h,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache),this.tablePos=p+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.emitUpdate(),!1});u(this,"dragOverHandler",t=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",Co(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const e={left:Math.min(Math.max(t.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(t.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(e.left,e.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=st(i.parentElement),a=st(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,h=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const p=this.state.draggingState.draggedCellOrientation==="row"?e.top:e.left;this.state.draggingState.mousePos!==p&&(this.state.draggingState.mousePos=p,r=!0),r&&this.emitUpdate(),h&&this.pmView.dispatch(this.pmView.state.tr.setMeta(X,!0))});u(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const e=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=e[this.state.draggingState.originalIndex];e.splice(this.state.draggingState.originalIndex,1),e.splice(this.state.rowIndex,0,o)}else{const o=e.map(i=>i.cells[this.state.draggingState.originalIndex]);e.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:e}})});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=e.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=e.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.emitUpdate()}});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},e.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const X=new k.PluginKey("TableHandlesPlugin");class Me extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"colDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),xe(),e.dataTransfer.setDragImage(M,0,0),e.dataTransfer.effectAllowed="move"});u(this,"rowDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),xe(),e.dataTransfer.setDragImage(M,0,0),e.dataTransfer.effectAllowed="copyMove"});u(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,null)),Eo()});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});this.editor=e,this.plugin=new k.Plugin({key:X,view:o=>(this.view=new Be(e,o,i=>{this.emit("update",i)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return x.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),c=l.node();for(let h=0;h<c.childCount;h++){const p=o.doc.resolve(l.posAtIndex(h)+1),f=p.node(),m=p.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(x.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const c=o.doc.resolve(s.posAtIndex(l)+1),h=o.doc.resolve(c.posAtIndex(i)+1),p=h.node(),f=h.pos+(i>this.view.state.draggingState.originalIndex?p.nodeSize-2:0);r.push(x.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return x.DecorationSet.create(o.doc,r)}}})}onUpdate(e){return this.on("update",e)}}function Ie(n,t){const e=n.state.selection.content().content,i=ft(n.state.schema,t).serializeProseMirrorFragment(e),s=Z(n.state.schema,t).exportProseMirrorFragment(e),a=Mt(s);return{internalHTML:i,externalHTML:s,plainText:a}}const To=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{copy(t,e){e.preventDefault(),e.clipboardData.clearData(),"node"in t.state.selection&&t.state.selection.node.type.spec.group==="blockContent"&&t.dispatch(t.state.tr.setSelection(new k.NodeSelection(t.state.doc.resolve(t.state.selection.from-1))));const{internalHTML:o,externalHTML:i,plainText:r}=Ie(t,n);return e.clipboardData.setData("blocknote/html",o),e.clipboardData.setData("text/html",i),e.clipboardData.setData("text/plain",r),!0},dragstart(t,e){if(!("node"in t.state.selection)||t.state.selection.node.type.spec.group!=="blockContent")return;t.dispatch(t.state.tr.setSelection(new k.NodeSelection(t.state.doc.resolve(t.state.selection.from-1)))),e.preventDefault(),e.dataTransfer.clearData();const{internalHTML:o,externalHTML:i,plainText:r}=Ie(t,n);return e.dataTransfer.setData("blocknote/html",o),e.dataTransfer.setData("text/html",i),e.dataTransfer.setData("text/plain",r),!0}}}})]}}),xo=["blocknote/html","text/html","text/plain"],Bo=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{paste(t,e){e.preventDefault();let o=null;for(const i of xo)if(e.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=e.clipboardData.getData(o);o==="text/html"&&(i=ue(i.trim()).innerHTML),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),Mo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:C.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):C.backgroundColor.default,renderHTML:n=>n.backgroundColor!==C.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),Io=new k.PluginKey("blocknote-placeholder"),Lo=b.Extension.create({name:"placeholder",addOptions(){return{placeholders:{default:"Enter text or type '/' for commands",heading:"Heading",bulletListItem:"List",numberedListItem:"List"}}},addProseMirrorPlugins(){const n=this.options.placeholders;return[new k.Plugin({key:Io,view:()=>{const t=document.createElement("style");document.head.appendChild(t);const e=t.sheet,o=(r="")=>`.bn-block-content${r} .bn-inline-content:has(> .ProseMirror-trailingBreak):before`,i=(r,s=!0)=>{const a=s?"[data-is-empty-and-focused]":"";if(r==="default")return o(a);const l=`[data-content-type="${r}"]`;return o(a+l)};for(const[r,s]of Object.entries(n)){const a=r==="default";e.insertRule(`${i(r,a)}{ content: ${JSON.stringify(s)}; }`),a||e.insertRule(`${i(r,!0)}{ content: ${JSON.stringify(s)}; }`)}return{destroy:()=>{document.head.removeChild(t)}}},props:{decorations:t=>{const{doc:e,selection:o}=t;if(!this.editor.isEditable||!o.empty)return;const r=o.$anchor,s=r.parent;if(s.content.size>0)return null;const a=r.before(),l=x.Decoration.node(a,a+s.nodeSize,{"data-is-empty-and-focused":"true"});return x.DecorationSet.create(e,[l])}}})]}}),Po=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),No=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:C.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):C.textColor.default,renderHTML:n=>n.textColor!==C.textColor.default&&{"data-text-color":n.textColor}}}}]}}),Ao=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,c=s.nodes.blockContainer,h=s.nodes.paragraph;if(a)return r.insert(l,c.create(void 0,h.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Ho=new k.PluginKey("non-editable-block"),Do=()=>new k.Plugin({key:Ho,props:{handleKeyDown:(n,t)=>{"node"in n.state.selection&&t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&!t.shiftKey&&t.preventDefault()}}}),Le=new k.PluginKey("previous-blocks"),_o={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Oo=()=>{let n;return new k.Plugin({key:Le,view(t){return{update:async(e,o)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(Le,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(i.doc))return e;const r={},s=b.findChildren(o.doc,c=>c.attrs.id),a=new Map(s.map(c=>[c.node.attrs.id,c])),l=b.findChildren(i.doc,c=>c.attrs.id);for(const c of l){const h=a.get(c.node.attrs.id),p=h==null?void 0:h.node.firstChild,f=c.node.firstChild;if(h&&p&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(c.pos).depth};let g={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:o.doc.resolve(h.pos).depth};r[c.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(c.node.attrs.id in e.prevTransactionOldBlockAttrs&&(g=e.prevTransactionOldBlockAttrs[c.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),e.currentTransactionOldBlockAttrs[c.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,e.updatedBlocks.add(c.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[c,h]of Object.entries(s))a["data-prev-"+_o[c]]=h||"none";const l=x.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),x.DecorationSet.create(t.doc,o)}}})},Uo={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ro=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const t={};for(const[e,o]of Object.entries(Uo))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:n}){var i;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);const e={...((i=this.options.domAttributes)==null?void 0:i.block)||{},...n},o=document.createElement("div");o.className=O("bn-block",e.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(e))r!=="class"&&o.setAttribute(r,s);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:t,dispatch:e})=>{const o=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:t,dispatch:e})=>{const o=w(t.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,t)=>({state:e,dispatch:o})=>{const i=w(e.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(t.children!==void 0){const f=[];for(const m of t.children)f.push(N(m,e.schema,this.options.editor.schema.styleSchema));a.childCount===2?e.tr.replace(r+l.nodeSize+1,s-1,new y.Slice(y.Fragment.from(f),0,0)):e.tr.insert(r+l.nodeSize,e.schema.nodes.blockGroup.create({},f))}const c=l.type.name,h=t.type||c;let p="keep";if(t.content)if(typeof t.content=="string")p=[e.schema.text(t.content)];else if(Array.isArray(t.content))p=Q(t.content,e.schema,this.options.editor.schema.styleSchema);else if(t.content.type==="tableContent")p=pt(t.content,e.schema,this.options.editor.schema.styleSchema);else throw new L(t.content.type);else{const f=e.schema.nodes[c].spec.content,m=e.schema.nodes[h].spec.content;f===""||m!==f&&(p=[])}p==="keep"?e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...l.attrs,...t.props}):e.tr.replaceWith(r,s,e.schema.nodes[h].create({...l.attrs,...t.props},p)).setSelection(e.schema.nodes[h].spec.content===""?new k.NodeSelection(e.tr.doc.resolve(r)):e.schema.nodes[h].spec.content==="inline*"?new k.TextSelection(e.tr.doc.resolve(r)):new k.TextSelection(e.tr.doc.resolve(r+4))),e.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...t.props})}return!0},BNMergeBlocks:n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n+1).node().type.name==="blockContainer",i=t.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=w(t.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:c,depth:h}=r;if(s.childCount===2){const m=t.doc.resolve(l+a.nodeSize+1),g=t.doc.resolve(c-1),E=m.blockRange(g);e&&t.tr.lift(E,h-1)}let p=n-1,f=w(t.doc,p);for(;f.numChildBlocks>0;)if(p--,f=w(t.doc,p),f===void 0)return!1;return e&&(e(t.tr.deleteRange(l,l+a.nodeSize).replace(p-1,l,new y.Slice(a.content,0,0)).scrollIntoView()),t.tr.setSelection(new k.TextSelection(t.doc.resolve(p-1)))),!0},BNSplitBlock:(n,t)=>({state:e,dispatch:o})=>{const i=w(e.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:c}=i,h=e.doc.cut(a+1,n),p=e.doc.cut(n,l-1),f=e.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(e.tr.insert(m,f),e.tr.replace(g,g+1,p.content.size>0?new y.Slice(y.Fragment.from(p),c+2,c+2):void 0),t&&e.tr.setBlockType(g,g,e.schema.node(s).type,r.attrs),e.tr.setSelection(new k.TextSelection(e.doc.resolve(g))),e.tr.replace(a+1,l-1,h.content.size>0?new y.Slice(y.Fragment.from(h),c+2,c+2):void 0)),!0}}},addProseMirrorPlugins(){return[Oo(),Do()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=w(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=w(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=w(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,c=s===2,h=s-1;return!c&&a&&l&&r===2?o.BNMergeBlocks(h):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=w(i.doc,i.selection.from),l=a===i.doc.nodeSize-4,c=i.selection.from===a-1,h=i.selection.empty,p=r.childCount===2;if(!l&&c&&h&&!p){let f=s,m=a+2,g=i.doc.resolve(m).depth;for(;g<f;)f=g,m+=2,g=i.doc.resolve(m).depth;return o.BNMergeBlocks(m-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=w(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,c=r.textContent.length===0,h=s>2;return a&&l&&c&&h?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=w(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,c=i.selection.anchor===i.selection.head,h=s.textContent.length===0;if(l&&c&&h){const p=a+1,f=p+2;return r().BNCreateBlock(p).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=w(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0)}}}),zo=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},e=document.createElement("div");e.className=O("bn-block-group",t.class),e.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(t))i!=="class"&&e.setAttribute(i,r);return{dom:e,contentDOM:e}}}),Fo=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Pe=n=>{var e;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Qe.Gapcursor,Lo.configure({...n.placeholders!==void 0?{placeholders:n.placeholders}:{}}),G.configure({types:["blockContainer"]}),Ze.HardBreak,nn.Text,en.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),No,Mo,Po,Fo,Ro.configure({editor:n.editor,domAttributes:n.domAttributes}),zo.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),To(n.editor),Bo(n.editor),Ye.Dropcursor.configure({width:5,color:"#ddeeff"}),Ao];if(n.collaboration){if(t.push(pn.default.configure({fragment:n.collaboration.fragment})),(e=n.collaboration.provider)!=null&&e.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};t.push(mn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else t.push(tn.History);return t};function Vo(n,t){const e=[];return n.forEach((o,i,r)=>{r!==t&&e.push(o)}),y.Fragment.from(e)}function qo(n,t){let e=y.Fragment.from(n.content);for(let o=0;o<e.childCount;o++)if(e.child(o).type.spec.group==="blockContent"){const i=[e.child(o)];if(o+1<e.childCount&&e.child(o+1).type.spec.group==="blockGroup"){const s=e.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(e.child(o+1)),e=Vo(e,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,i);e=e.replaceChild(o,r)}return new y.Slice(e,n.openStart,n.openEnd)}class at{constructor(t){u(this,"blockSpecs");u(this,"inlineContentSpecs");u(this,"styleSpecs");u(this,"blockSchema");u(this,"inlineContentSchema");u(this,"styleSchema");u(this,"BlockNoteEditor","only for types");u(this,"Block","only for types");u(this,"PartialBlock","only for types");this.blockSpecs=(t==null?void 0:t.blockSpecs)||Ct,this.inlineContentSpecs=(t==null?void 0:t.inlineContentSpecs)||xt,this.styleSpecs=(t==null?void 0:t.styleSpecs)||Tt,this.blockSchema=yt(this.blockSpecs),this.inlineContentSchema=wt(this.inlineContentSpecs),this.styleSchema=Et(this.styleSpecs)}static create(t){return new at(t)}}class $o extends b.Editor{constructor(e,o){super({...e,content:void 0});u(this,"_state");u(this,"mount",e=>{e?(this.options.element=e,this.createViewAlternative()):this.destroy()});const i=this.schema;let r;const s=i.nodes.doc.createAndFill;i.nodes.doc.createAndFill=(...l)=>{if(r)return r;const c=s.apply(i.nodes.doc,l),h=JSON.parse(JSON.stringify(c.toJSON()));return h.content[0].content[0].attrs.id="initialBlockId",r=y.Node.fromJSON(i,h),r};let a;try{const l=e==null?void 0:e.content.map(c=>N(c,this.schema,o).toJSON());a=b.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(e.content))}this._state=k.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}createView(){}createViewAlternative(){queueMicrotask(()=>{this.view=new x.EditorView(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:this.state});const e=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(e),this.createNodeViews()})}}const Zo="",ti="",Go={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Lt{constructor(t){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"formattingToolbar");u(this,"linkToolbar");u(this,"sideMenu");u(this,"suggestionMenus");u(this,"imagePanel");u(this,"tableHandles");u(this,"uploadFile");var l,c,h,p,f,m,g,E;this.options=t;const e=t;if(e.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(e.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(e.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(e.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");const o={defaultStyles:!0,schema:t.schema||at.create(),...t};this.schema=o.schema,this.blockImplementations=o.schema.blockSpecs,this.inlineContentImplementations=o.schema.inlineContentSpecs,this.styleImplementations=o.schema.styleSpecs,this.formattingToolbar=new fe(this),this.linkToolbar=new be(this),this.sideMenu=new Se(this),this.suggestionMenus=new ke(this),P("image",this)&&(this.imagePanel=new Te(this)),P("table",this)&&(this.tableHandles=new Me(this));const i=Pe({editor:this,placeholders:o.placeholders,domAttributes:o.domAttributes||{},blockSchema:this.schema.blockSchema,blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:o.collaboration}),r=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.formattingToolbar.plugin,this.linkToolbar.plugin,this.sideMenu.plugin,this.suggestionMenus.plugin,...this.imagePanel?[this.imagePanel.plugin]:[],...this.tableHandles?[this.tableHandles.plugin]:[]]});i.push(r),this.uploadFile=o.uploadFile,o.collaboration&&o.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const s=o.initialContent||(t.collaboration?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:G.options.generateID()}]);if(!Array.isArray(s)||s.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+s);const a={...Go,...o._tiptapOptions,content:s,extensions:o.enableBlockNoteExtensions===!1?((l=o._tiptapOptions)==null?void 0:l.extensions)||[]:[...((c=o._tiptapOptions)==null?void 0:c.extensions)||[],...i],editorProps:{...(h=o._tiptapOptions)==null?void 0:h.editorProps,attributes:{...(f=(p=o._tiptapOptions)==null?void 0:p.editorProps)==null?void 0:f.attributes,...(m=o.domAttributes)==null?void 0:m.editor,class:O("bn-editor",o.defaultStyles?"bn-default-styles":"",((E=(g=o.domAttributes)==null?void 0:g.editor)==null?void 0:E.class)||"")},transformPasted:qo}};this._tiptapEditor=new $o(a,this.schema.styleSchema)}static create(t={}){return new Lt(t)}mount(t){this._tiptapEditor.mount(t)}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(){return this.topLevelBlocks}get document(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(S(e,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(o=S(i,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),!1)),o}forEachBlock(t,e=!1){const o=this.document.slice();e&&o.reverse();function i(r){for(const s of r){if(!t(s))return!1;const a=e?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:o,endPos:i}=w(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 a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:S(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:S(a,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:S(l,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)}}setTextCursorPosition(t,e="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:i}=Bt(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=w(this._tiptapEditor.state.doc,i+2),a=this.schema.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")e==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new L(a)}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,o)=>e.type.spec.group!=="blockContent"||o+e.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(S(this._tiptapEditor.state.doc.resolve(o).node(),this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,e,o="before"){return to(t,e,o,this)}updateBlock(t,e){return eo(t,e,this)}removeBlocks(t){return no(t,this)}replaceBlocks(t,e){return oo(t,e,this)}insertInlineContent(t){const e=Q(t,this._tiptapEditor.schema,this.schema.styleSchema);io({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},e,this)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks();for(const o of e){const i=this.schema.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?t[i.type]=!0:t[i.type]=o.attrs.stringValue}return t}addStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.schema.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(e,{stringValue:o});else throw new L(i.propSchema)}}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.schema.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(e,{stringValue:o});else throw new L(i.propSchema)}}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:o,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,o,i).addMark(o,o+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=w(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}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.document){return Z(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return he(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.document){return so(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return mo(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,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)}onChange(t){const e=()=>{t(this)};return this._tiptapEditor.on("update",e),()=>{this._tiptapEditor.off("update",e)}}onSelectionChange(t){const e=()=>{t(this)};return this._tiptapEditor.on("selectionUpdate",e),()=>{this._tiptapEditor.off("selectionUpdate",e)}}}function Ko(n){let t=n.getTextCursorPosition().block,e=n.schema.blockSchema[t.type].content;for(;e==="none";)t=n.getTextCursorPosition().nextBlock,e=n.schema.blockSchema[t.type].content,n.setTextCursorPosition(t,"end")}function H(n,t){const e=n.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(e.content)&&(e.content.length===1&&K(e.content[0])&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0)?n.updateBlock(e,t):(n.insertBlocks([t],e,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return Ko(n),o}function jo(n){const t=[];return P("heading",n)&&t.push({title:"Heading 1",onItemClick:()=>{H(n,{type:"heading",props:{level:1}})},subtext:"Used for a top-level heading",badge:V("Mod-Alt-1"),aliases:["h","heading1","h1"],group:"Headings"},{title:"Heading 2",onItemClick:()=>{H(n,{type:"heading",props:{level:2}})},subtext:"Used for key sections",badge:V("Mod-Alt-2"),aliases:["h2","heading2","subheading"],group:"Headings"},{title:"Heading 3",onItemClick:()=>{H(n,{type:"heading",props:{level:3}})},subtext:"Used for subsections and group headings",badge:V("Mod-Alt-3"),aliases:["h3","heading3","subheading"],group:"Headings"}),P("numberedListItem",n)&&t.push({title:"Numbered List",onItemClick:()=>{H(n,{type:"numberedListItem"})},subtext:"Used to display a numbered list",badge:V("Mod-Shift-7"),aliases:["ol","li","list","numberedlist","numbered list"],group:"Basic blocks"}),P("bulletListItem",n)&&t.push({title:"Bullet List",onItemClick:()=>{H(n,{type:"bulletListItem"})},subtext:"Used to display an unordered list",badge:V("Mod-Shift-8"),aliases:["ul","li","list","bulletlist","bullet list"],group:"Basic blocks"}),P("paragraph",n)&&t.push({title:"Paragraph",onItemClick:()=>{H(n,{type:"paragraph"})},subtext:"Used for the body of your document",badge:V("Mod-Alt-0"),aliases:["p","paragraph"],group:"Basic blocks"}),P("table",n)&&t.push({title:"Table",onItemClick:()=>{H(n,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},subtext:"Used for for tables",aliases:["table"],group:"Advanced",badge:void 0}),P("image",n)&&t.push({title:"Image",onItemClick:()=>{const e=H(n,{type:"image"});n.prosemirrorView.dispatch(n._tiptapEditor.state.tr.setMeta(n.imagePanel.plugin,{block:e}))},subtext:"Insert an image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],group:"Media"}),t}function Wo(n,t){return n.filter(({title:e,aliases:o})=>e.toLowerCase().startsWith(t.toLowerCase())||o&&o.filter(i=>i.toLowerCase().startsWith(t.toLowerCase())).length!==0)}function Pt(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function Ne(n){return typeof n=="string"?Pt(n):Array.isArray(n)?n.flatMap(t=>typeof t=="string"?Pt(t):ut(t)?{...t,content:Pt(t.content)}:K(t)?t:{props:{},...t,content:Ne(t.content)}):n}function Jo(n,t){return t.map(e=>Nt(n,e))}function Nt(n,t){const e={id:"",type:t.type,props:{},content:n[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(n[t.type].propSchema).forEach(([o,i])=>{e.props[o]===void 0&&(e.props[o]=i.default)}),{...e,content:Ne(e.content),children:e.children.map(o=>Nt(n,o))}}function Ae(n){n.id||(n.id=G.options.generateID()),n.children&&He(n.children)}function He(n){for(const t of n)Ae(t)}d.BlockNoteEditor=Lt,d.BlockNoteSchema=at,d.FormattingToolbarProsemirrorPlugin=fe,d.FormattingToolbarView=pe,d.ImagePanelProsemirrorPlugin=Te,d.ImagePanelView=Ce,d.LinkToolbarProsemirrorPlugin=be,d.SideMenuProsemirrorPlugin=Se,d.SideMenuView=ve,d.SuggestionMenuProseMirrorPlugin=ke,d.TableHandlesProsemirrorPlugin=Me,d.TableHandlesView=Be,d.UniqueID=G,d.UnreachableCaseError=L,d.addIdsToBlock=Ae,d.addIdsToBlocks=He,d.addInlineContentAttributes=Yt,d.addInlineContentKeyboardShortcuts=Qt,d.addStyleAttributes=oe,d.blockToNode=N,d.camelToDataKebab=et,d.checkBlockHasDefaultProp=Zn,d.checkBlockIsDefaultType=Qn,d.checkBlockTypeHasDefaultProp=le,d.checkDefaultBlockTypeInSchema=P,d.contentNodeToInlineContent=ot,d.createBlockSpec=Xt,d.createBlockSpecFromStronglyTypedTiptapNode=j,d.createExternalHTMLExporter=Z,d.createInlineContentSpec=Sn,d.createInlineContentSpecFromTipTapNode=te,d.createInternalBlockSpec=kt,d.createInternalHTMLSerializer=ft,d.createInternalInlineContentSpec=Zt,d.createInternalStyleSpec=vt,d.createStronglyTypedTiptapNode=q,d.createStyleSpec=Cn,d.createStyleSpecFromTipTapMark=U,d.createSuggestionMenu=ko,d.defaultBlockSchema=ae,d.defaultBlockSpecs=Ct,d.defaultInlineContentSchema=Yn,d.defaultInlineContentSpecs=xt,d.defaultProps=C,d.defaultStyleSchema=Xn,d.defaultStyleSpecs=Tt,d.filterSuggestionItems=Wo,d.formatKeyboardShortcut=V,d.formattingToolbarPluginKey=me,d.getBlockFromPos=Wt,d.getBlockNoteExtensions=Pe,d.getBlockSchemaFromSpecs=yt,d.getDefaultSlashMenuItems=jo,d.getDraggableBlockFromCoords=rt,d.getInlineContentParseRules=ee,d.getInlineContentSchemaFromSpecs=wt,d.getParseRules=Jt,d.getStyleParseRules=ie,d.getStyleSchemaFromSpecs=Et,d.inheritedProps=gt,d.inlineContentToNodes=Q,d.insertOrUpdateBlock=H,d.isAppleOS=Kt,d.isLinkInlineContent=dt,d.isPartialLinkInlineContent=ut,d.isSafari=En,d.isStyledTextInlineContent=K,d.linkToolbarPluginKey=ge,d.mergeCSSClasses=O,d.nodeToBlock=S,d.nodeToCustomInlineContent=mt,d.partialBlockToBlockForTesting=Nt,d.partialBlocksToBlocksForTesting=Jo,d.propsToAttributes=bt,d.sideMenuPluginKey=Ee,d.stylePropsToAttributes=ne,d.suggestionMenuPluginKey=R,d.tableContentToNodes=pt,d.tableHandlesPluginKey=X,d.uploadToTmpFilesDotOrg_DEV_ONLY=vn,d.wrapInBlockStructure=it,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
7
|
+
`:"",o={};t.lang&&(o["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),n.patch(t,i),i=n.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(t,i),i}function mo(n,t,e,o,i){const r=ct.unified().use(un.default).use(zt.default).use(hn.default,{handlers:{...Ot.defaultHandlers,code:po}}).use(Rt.default).processSync(n);return he(r.value,t,e,o,i)}class W{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 o=this.callbacks[t];o&&o.forEach(i=>i.apply(this,e))}off(t,e){const o=this.callbacks[t];o&&(e?this.callbacks[t]=o.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class pe{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({state:t})=>!t.selection.empty);u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",t=>{var o;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragHandler),e.dom.addEventListener("dragover",this.dragHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var f,m;const{state:o,composing:i}=t,{doc:r,selection:s}=o,a=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,c=Math.min(...l.map(g=>g.$from.pos)),h=Math.max(...l.map(g=>g.$to.pos)),p=(f=this.shouldShow)==null?void 0:f.call(this,{view:t,state:o,from:c,to:h});if(this.editor.isEditable&&!this.preventShow&&(p||this.preventHide)){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((m=this.state)!=null&&m.show&&!this.preventHide&&(!p||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),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:o}=e,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const me=new k.PluginKey("FormattingToolbarPlugin");class fe extends W{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new k.Plugin({key:me,view:o=>(this.view=new pe(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class fo{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredLinkMark");u(this,"mouseHoveredLinkMarkRange");u(this,"keyboardHoveredLinkMark");u(this,"keyboardHoveredLinkMarkRange");u(this,"linkMark");u(this,"linkMarkRange");u(this,"mouseOverHandler",t=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=s,this.mouseHoveredLinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var o;const e=this.pmView.dom.parentElement;this.linkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;this.linkMark!==void 0&&(t=this.state)!=null&&t.show&&(this.state.referencePos=b.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},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)}editLink(t,e){var i;const o=this.pmView.state.tr.insertText(e,this.linkMarkRange.from,this.linkMarkRange.to);o.addMark(this.linkMarkRange.from,this.linkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.state)!=null&&i.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=i,this.keyboardHoveredLinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable){this.state={show:!0,referencePos:b.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},this.emitUpdate();return}if((e=this.state)!=null&&e.show&&t&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const ge=new k.PluginKey("LinkToolbarPlugin");class be extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"editLink",(e,o)=>{this.view.editLink(e,o)});u(this,"deleteLink",()=>{this.view.deleteLink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new k.Plugin({key:ge,view:o=>(this.view=new fo(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}const go=b.findParentNode(n=>n.type.name==="blockContainer");class bo{constructor(t,e){u(this,"state");u(this,"emitUpdate");u(this,"pluginState");u(this,"handleScroll",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.view.state.tr.setMeta(R,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-(this.pluginState.fromUserInput?this.pluginState.triggerCharacter.length:0),to:this.editor._tiptapEditor.state.selection.from}).run()});this.editor=t,this.pluginState=void 0,this.emitUpdate=o=>{if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");e(o,this.state)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const o=R.getState(e),i=R.getState(t.state),r=o===void 0&&i!==void 0,s=o!==void 0&&i===void 0;if(!r&&!(o!==void 0&&i!==void 0)&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.state.show=!1,this.emitUpdate(this.pluginState.triggerCharacter);return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){document.removeEventListener("scroll",this.handleScroll)}}const R=new k.PluginKey("SuggestionMenuPlugin");class ke extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)});u(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==e)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new k.Plugin({key:R,view:()=>(this.view=new bo(e,(i,r)=>{this.emit(`update ${i}`,r)}),this.view),state:{init(){},apply(i,r,s,a){if(i.getMeta("orderedListIndexing")!==void 0)return r;const l=i.getMeta(R);if(typeof l=="object"&&l!==null&&r===void 0)return{triggerCharacter:l.triggerCharacter,fromUserInput:l.fromUserInput!==!1,queryStartPos:a.selection.from,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(r===void 0)return r;if(a.selection.from!==a.selection.to||l===null||i.getMeta("focus")||i.getMeta("blur")||i.getMeta("pointer")||r.triggerCharacter!==void 0&&a.selection.from<r.queryStartPos)return;const c={...r};return c.query=a.doc.textBetween(r.queryStartPos,a.selection.from),c}},props:{handleTextInput(i,r,s,a){const l=this.getState(i.state);return o.includes(a)&&l===void 0?(i.dispatch(i.state.tr.insertText(a).scrollIntoView().setMeta(R,{triggerCharacter:a})),!0):!1},decorations(i){const r=this.getState(i);if(r===void 0)return null;if(!r.fromUserInput){const s=go(i.selection);if(s)return x.DecorationSet.create(i.doc,[x.Decoration.node(s.pos,s.pos+s.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}return x.DecorationSet.create(i.doc,[x.Decoration.inline(r.queryStartPos-r.triggerCharacter.length,r.queryStartPos,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}}})}onUpdate(e,o){return this.triggerCharacters.includes(e)||this.addTriggerCharacter(e),this.on(`update ${e}`,o)}}function ko(n,t){n.suggestionMenus.addTriggerCharacter(t)}class J extends k.Selection{constructor(e,o){super(e,o);u(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(e,o,i=o){return new J(e.resolve(o),e.resolve(i))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof J)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?k.Selection.near(e.resolve(i.pos)):i.deleted?k.Selection.near(e.resolve(r.pos)):new J(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let z;function rt(n,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(n);if(!e)return;let o=t.domAtPos(e.pos).node;if(o!==t.dom){for(;o&&o.parentNode&&o.parentNode!==t.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function yo(n,t){const e=rt(n,t);if(e&&e.node.nodeType===1){const o=t.docView,i=o.nearestDesc(e.node,!0);return!i||i===o?null:i.posBefore}return null}function wo(n,t){let e,o;const i=t.resolve(n.from).node().type.spec.group==="blockContent",r=t.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);e=t.resolve(a-1).pos,o=t.resolve(l+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function ye(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),i=n.domAtPos(t).node,r=(h,p)=>Array.prototype.indexOf.call(h.children,p),s=r(i,n.domAtPos(t+1).node.parentElement),a=r(i,n.domAtPos(e-1).node.parentElement);for(let h=i.childElementCount-1;h>=0;h--)(h>a||h<s)&&o.removeChild(o.children[h]);we(),z=o;const c=n.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");z.className=z.className+" bn-drag-preview "+c,document.body.appendChild(z)}function we(){z!==void 0&&(document.body.removeChild(z),z=void 0)}function vo(n,t){if(!n.dataTransfer)return;const e=t.prosemirrorView,o=e.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=yo(i,e);if(r!=null){const s=e.state.selection,a=e.state.doc,{from:l,to:c}=wo(s,a),h=l<=r&&r<c,p=s.$anchor.node()!==s.$head.node()||s instanceof J;h&&p?(e.dispatch(e.state.tr.setSelection(J.create(a,l,c))),ye(e,l,c)):(e.dispatch(e.state.tr.setSelection(k.NodeSelection.create(e.state.doc,r))),ye(e,r));const f=e.state.selection.content(),m=t._tiptapEditor.schema,E=ft(m,t).serializeProseMirrorFragment(f.content),D=Z(m,t).exportProseMirrorFragment(f.content),B=Mt(D);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",E),n.dataTransfer.setData("text/html",D),n.dataTransfer.setData("text/plain",B),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(z,0,0),e.dragging={slice:f,move:!0}}}class ve{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");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 o=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});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 o=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onKeyDown",t=>{var e;(e=this.state)!=null&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseDown",t=>{this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate(this.state)),this.menuFrozen=!1});u(this,"onMouseMove",t=>{var c,h,p,f,m;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=o.left&&t.clientX<=o.right&&t.clientY>=o.top&&t.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},a=rt(s,this.pmView);if(!a||!this.editor.isEditable){(h=this.state)!=null&&h.show&&(this.state.show=!1,this.emitUpdate(this.state));return}if((p=this.state)!=null&&p.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.state={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.emitUpdate(this.state)}});u(this,"onScroll",()=>{var t;if((t=this.state)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.state.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.emitUpdate(this.state)}});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},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("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate(this.state)),document.body.removeEventListener("mousemove",this.onMouseMove,!0),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("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.state)!=null&&l.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const i=w(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,startPos:s,endPos:a}=i;if(r.type.spec.content!=="inline*"||r.textContent.length!==0){const c=a+1,h=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).setTextSelection(h).run()}else this.editor._tiptapEditor.commands.setTextSelection(s+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(R,{triggerCharacter:"/",fromUserInput:!1}))}}const Ee=new k.PluginKey("SideMenuPlugin");class Se extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"addBlock",()=>this.view.addBlock());u(this,"blockDragStart",e=>{this.view.isDragging=!0,vo(e,this.editor)});u(this,"blockDragEnd",()=>we());u(this,"freezeMenu",()=>this.view.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.view.menuFrozen=!1);this.editor=e,this.plugin=new k.Plugin({key:Ee,view:o=>(this.view=new ve(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class Ce{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"prevWasEditable",null);u(this,"mouseDownHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"dragstartHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"blurHandler",t=>{var o;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate()}});this.pluginKey=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image panel");o(this.state)},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 o=this.pluginKey.getState(t.state);if(!((i=this.state)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.state={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate())}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 It=new k.PluginKey("ImagePanelPlugin");class Te extends W{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new k.Plugin({key:It,view:o=>(this.view=new Ce(It,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(It))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}let M;function xe(){M||(M=document.createElement("div"),M.innerHTML="_",M.style.opacity="0",M.style.height="1px",M.style.width="1px",document.body.appendChild(M))}function Eo(){M&&(document.body.removeChild(M),M=void 0)}function st(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function So(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Co(n){n.forEach(t=>{const e=document.getElementsByClassName(t);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"})}class Be{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"menuFrozen",!1);u(this,"prevWasEditable",null);u(this,"mouseMoveHandler",t=>{var c;if(this.menuFrozen)return;const e=So(t.target);if(!e||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate());return}const o=st(e),i=st(e.parentElement),r=e.getBoundingClientRect(),s=e.parentElement.parentElement.getBoundingClientRect(),a=rt(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((h,p)=>typeof l<"u"?!1:h.type.name!=="blockContainer"||h.attrs.id!==a.id?!0:(l=S(h,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache),this.tablePos=p+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.emitUpdate(),!1});u(this,"dragOverHandler",t=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",Co(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const e={left:Math.min(Math.max(t.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(t.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(e.left,e.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=st(i.parentElement),a=st(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,h=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const p=this.state.draggingState.draggedCellOrientation==="row"?e.top:e.left;this.state.draggingState.mousePos!==p&&(this.state.draggingState.mousePos=p,r=!0),r&&this.emitUpdate(),h&&this.pmView.dispatch(this.pmView.state.tr.setMeta(X,!0))});u(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const e=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=e[this.state.draggingState.originalIndex];e.splice(this.state.draggingState.originalIndex,1),e.splice(this.state.rowIndex,0,o)}else{const o=e.map(i=>i.cells[this.state.draggingState.originalIndex]);e.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:e}})});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=e.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=e.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.emitUpdate()}});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},e.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const X=new k.PluginKey("TableHandlesPlugin");class Me extends W{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"colDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),xe(),e.dataTransfer.setDragImage(M,0,0),e.dataTransfer.effectAllowed="move"});u(this,"rowDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),xe(),e.dataTransfer.setDragImage(M,0,0),e.dataTransfer.effectAllowed="copyMove"});u(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(X,null)),Eo()});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});this.editor=e,this.plugin=new k.Plugin({key:X,view:o=>(this.view=new Be(e,o,i=>{this.emit("update",i)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return x.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),c=l.node();for(let h=0;h<c.childCount;h++){const p=o.doc.resolve(l.posAtIndex(h)+1),f=p.node(),m=p.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(x.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const c=o.doc.resolve(s.posAtIndex(l)+1),h=o.doc.resolve(c.posAtIndex(i)+1),p=h.node(),f=h.pos+(i>this.view.state.draggingState.originalIndex?p.nodeSize-2:0);r.push(x.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return x.DecorationSet.create(o.doc,r)}}})}onUpdate(e){return this.on("update",e)}}function Ie(n,t){const e=n.state.selection.content().content,i=ft(n.state.schema,t).serializeProseMirrorFragment(e),s=Z(n.state.schema,t).exportProseMirrorFragment(e),a=Mt(s);return{internalHTML:i,externalHTML:s,plainText:a}}const To=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{copy(t,e){e.preventDefault(),e.clipboardData.clearData(),"node"in t.state.selection&&t.state.selection.node.type.spec.group==="blockContent"&&t.dispatch(t.state.tr.setSelection(new k.NodeSelection(t.state.doc.resolve(t.state.selection.from-1))));const{internalHTML:o,externalHTML:i,plainText:r}=Ie(t,n);return e.clipboardData.setData("blocknote/html",o),e.clipboardData.setData("text/html",i),e.clipboardData.setData("text/plain",r),!0},dragstart(t,e){if(!("node"in t.state.selection)||t.state.selection.node.type.spec.group!=="blockContent")return;t.dispatch(t.state.tr.setSelection(new k.NodeSelection(t.state.doc.resolve(t.state.selection.from-1)))),e.preventDefault(),e.dataTransfer.clearData();const{internalHTML:o,externalHTML:i,plainText:r}=Ie(t,n);return e.dataTransfer.setData("blocknote/html",o),e.dataTransfer.setData("text/html",i),e.dataTransfer.setData("text/plain",r),!0}}}})]}}),xo=["blocknote/html","text/html","text/plain"],Bo=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{paste(t,e){e.preventDefault();let o=null;for(const i of xo)if(e.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=e.clipboardData.getData(o);o==="text/html"&&(i=ue(i.trim()).innerHTML),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),Mo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:C.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):C.backgroundColor.default,renderHTML:n=>n.backgroundColor!==C.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),Io=new k.PluginKey("blocknote-placeholder"),Lo=b.Extension.create({name:"placeholder",addOptions(){return{placeholders:{default:"Enter text or type '/' for commands",heading:"Heading",bulletListItem:"List",numberedListItem:"List"}}},addProseMirrorPlugins(){const n=this.options.placeholders;return[new k.Plugin({key:Io,view:()=>{const t=document.createElement("style");document.head.appendChild(t);const e=t.sheet,o=(r="")=>`.bn-block-content${r} .bn-inline-content:has(> .ProseMirror-trailingBreak):before`,i=(r,s=!0)=>{const a=s?"[data-is-empty-and-focused]":"";if(r==="default")return o(a);const l=`[data-content-type="${r}"]`;return o(a+l)};for(const[r,s]of Object.entries(n)){const a=r==="default";e.insertRule(`${i(r,a)}{ content: ${JSON.stringify(s)}; }`),a||e.insertRule(`${i(r,!0)}{ content: ${JSON.stringify(s)}; }`)}return{destroy:()=>{document.head.removeChild(t)}}},props:{decorations:t=>{const{doc:e,selection:o}=t;if(!this.editor.isEditable||!o.empty)return;const r=o.$anchor,s=r.parent;if(s.content.size>0)return null;const a=r.before(),l=x.Decoration.node(a,a+s.nodeSize,{"data-is-empty-and-focused":"true"});return x.DecorationSet.create(e,[l])}}})]}}),Po=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),No=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:C.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):C.textColor.default,renderHTML:n=>n.textColor!==C.textColor.default&&{"data-text-color":n.textColor}}}}]}}),Ao=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,c=s.nodes.blockContainer,h=s.nodes.paragraph;if(a)return r.insert(l,c.create(void 0,h.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Ho=new k.PluginKey("non-editable-block"),Do=()=>new k.Plugin({key:Ho,props:{handleKeyDown:(n,t)=>{"node"in n.state.selection&&t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&!t.shiftKey&&t.preventDefault()}}}),Le=new k.PluginKey("previous-blocks"),_o={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Oo=()=>{let n;return new k.Plugin({key:Le,view(t){return{update:async(e,o)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(Le,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(i.doc))return e;const r={},s=b.findChildren(o.doc,c=>c.attrs.id),a=new Map(s.map(c=>[c.node.attrs.id,c])),l=b.findChildren(i.doc,c=>c.attrs.id);for(const c of l){const h=a.get(c.node.attrs.id),p=h==null?void 0:h.node.firstChild,f=c.node.firstChild;if(h&&p&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(c.pos).depth};let g={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:o.doc.resolve(h.pos).depth};r[c.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(c.node.attrs.id in e.prevTransactionOldBlockAttrs&&(g=e.prevTransactionOldBlockAttrs[c.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),e.currentTransactionOldBlockAttrs[c.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,e.updatedBlocks.add(c.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[c,h]of Object.entries(s))a["data-prev-"+_o[c]]=h||"none";const l=x.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),x.DecorationSet.create(t.doc,o)}}})},Uo={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ro=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const t={};for(const[e,o]of Object.entries(Uo))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:n}){var i;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);const e={...((i=this.options.domAttributes)==null?void 0:i.block)||{},...n},o=document.createElement("div");o.className=O("bn-block",e.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(e))r!=="class"&&o.setAttribute(r,s);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:t,dispatch:e})=>{const o=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:t,dispatch:e})=>{const o=w(t.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,t)=>({state:e,dispatch:o})=>{const i=w(e.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(t.children!==void 0){const f=[];for(const m of t.children)f.push(N(m,e.schema,this.options.editor.schema.styleSchema));a.childCount===2?e.tr.replace(r+l.nodeSize+1,s-1,new y.Slice(y.Fragment.from(f),0,0)):e.tr.insert(r+l.nodeSize,e.schema.nodes.blockGroup.create({},f))}const c=l.type.name,h=t.type||c;let p="keep";if(t.content)if(typeof t.content=="string")p=[e.schema.text(t.content)];else if(Array.isArray(t.content))p=Q(t.content,e.schema,this.options.editor.schema.styleSchema);else if(t.content.type==="tableContent")p=pt(t.content,e.schema,this.options.editor.schema.styleSchema);else throw new L(t.content.type);else{const f=e.schema.nodes[c].spec.content,m=e.schema.nodes[h].spec.content;f===""||m!==f&&(p=[])}p==="keep"?e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...l.attrs,...t.props}):e.tr.replaceWith(r,s,e.schema.nodes[h].create({...l.attrs,...t.props},p)).setSelection(e.schema.nodes[h].spec.content===""?new k.NodeSelection(e.tr.doc.resolve(r)):e.schema.nodes[h].spec.content==="inline*"?new k.TextSelection(e.tr.doc.resolve(r)):new k.TextSelection(e.tr.doc.resolve(r+4))),e.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...t.props})}return!0},BNMergeBlocks:n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n+1).node().type.name==="blockContainer",i=t.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=w(t.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:c,depth:h}=r;if(s.childCount===2){const m=t.doc.resolve(l+a.nodeSize+1),g=t.doc.resolve(c-1),E=m.blockRange(g);e&&t.tr.lift(E,h-1)}let p=n-1,f=w(t.doc,p);for(;f.numChildBlocks>0;)if(p--,f=w(t.doc,p),f===void 0)return!1;return e&&(e(t.tr.deleteRange(l,l+a.nodeSize).replace(p-1,l,new y.Slice(a.content,0,0)).scrollIntoView()),t.tr.setSelection(new k.TextSelection(t.doc.resolve(p-1)))),!0},BNSplitBlock:(n,t)=>({state:e,dispatch:o})=>{const i=w(e.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:c}=i,h=e.doc.cut(a+1,n),p=e.doc.cut(n,l-1),f=e.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(e.tr.insert(m,f),e.tr.replace(g,g+1,p.content.size>0?new y.Slice(y.Fragment.from(p),c+2,c+2):void 0),t&&e.tr.setBlockType(g,g,e.schema.node(s).type,r.attrs),e.tr.setSelection(new k.TextSelection(e.doc.resolve(g))),e.tr.replace(a+1,l-1,h.content.size>0?new y.Slice(y.Fragment.from(h),c+2,c+2):void 0)),!0}}},addProseMirrorPlugins(){return[Oo(),Do()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=w(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=w(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=w(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,c=s===2,h=s-1;return!c&&a&&l&&r===2?o.BNMergeBlocks(h):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=w(i.doc,i.selection.from),l=a===i.doc.nodeSize-4,c=i.selection.from===a-1,h=i.selection.empty,p=r.childCount===2;if(!l&&c&&h&&!p){let f=s,m=a+2,g=i.doc.resolve(m).depth;for(;g<f;)f=g,m+=2,g=i.doc.resolve(m).depth;return o.BNMergeBlocks(m-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=w(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,c=r.textContent.length===0,h=s>2;return a&&l&&c&&h?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=w(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,c=i.selection.anchor===i.selection.head,h=s.textContent.length===0;if(l&&c&&h){const p=a+1,f=p+2;return r().BNCreateBlock(p).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=w(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0)}}}),zo=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},e=document.createElement("div");e.className=O("bn-block-group",t.class),e.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(t))i!=="class"&&e.setAttribute(i,r);return{dom:e,contentDOM:e}}}),Fo=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Pe=n=>{var e;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Qe.Gapcursor,Lo.configure({...n.placeholders!==void 0?{placeholders:n.placeholders}:{}}),G.configure({types:["blockContainer"]}),Ze.HardBreak,nn.Text,en.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),No,Mo,Po,Fo,Ro.configure({editor:n.editor,domAttributes:n.domAttributes}),zo.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),To(n.editor),Bo(n.editor),Ye.Dropcursor.configure({width:5,color:"#ddeeff"}),Ao];if(n.collaboration){if(t.push(pn.default.configure({fragment:n.collaboration.fragment})),(e=n.collaboration.provider)!=null&&e.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};t.push(mn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else t.push(tn.History);return t};function Vo(n,t){const e=[];return n.forEach((o,i,r)=>{r!==t&&e.push(o)}),y.Fragment.from(e)}function qo(n,t){let e=y.Fragment.from(n.content);for(let o=0;o<e.childCount;o++)if(e.child(o).type.spec.group==="blockContent"){const i=[e.child(o)];if(o+1<e.childCount&&e.child(o+1).type.spec.group==="blockGroup"){const s=e.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(e.child(o+1)),e=Vo(e,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,i);e=e.replaceChild(o,r)}return new y.Slice(e,n.openStart,n.openEnd)}class at{constructor(t){u(this,"blockSpecs");u(this,"inlineContentSpecs");u(this,"styleSpecs");u(this,"blockSchema");u(this,"inlineContentSchema");u(this,"styleSchema");u(this,"BlockNoteEditor","only for types");u(this,"Block","only for types");u(this,"PartialBlock","only for types");this.blockSpecs=(t==null?void 0:t.blockSpecs)||Ct,this.inlineContentSpecs=(t==null?void 0:t.inlineContentSpecs)||xt,this.styleSpecs=(t==null?void 0:t.styleSpecs)||Tt,this.blockSchema=yt(this.blockSpecs),this.inlineContentSchema=wt(this.inlineContentSpecs),this.styleSchema=Et(this.styleSpecs)}static create(t){return new at(t)}}class $o extends b.Editor{constructor(e,o){super({...e,content:void 0});u(this,"_state");u(this,"mount",e=>{e?(this.options.element=e,this.createViewAlternative()):this.destroy()});const i=this.schema;let r;const s=i.nodes.doc.createAndFill;i.nodes.doc.createAndFill=(...l)=>{if(r)return r;const c=s.apply(i.nodes.doc,l),h=JSON.parse(JSON.stringify(c.toJSON()));return h.content[0].content[0].attrs.id="initialBlockId",r=y.Node.fromJSON(i,h),r};let a;try{const l=e==null?void 0:e.content.map(c=>N(c,this.schema,o).toJSON());a=b.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(e.content))}this._state=k.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}createView(){}createViewAlternative(){queueMicrotask(()=>{this.view=new x.EditorView(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:this.state});const e=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(e),this.createNodeViews()})}}const Zo="",ti="",Go={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Lt{constructor(t){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"formattingToolbar");u(this,"linkToolbar");u(this,"sideMenu");u(this,"suggestionMenus");u(this,"imagePanel");u(this,"tableHandles");u(this,"uploadFile");var l,c,h,p,f,m,g,E;this.options=t;const e=t;if(e.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(e.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(e.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(e.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");const o={defaultStyles:!0,schema:t.schema||at.create(),...t};this.schema=o.schema,this.blockImplementations=o.schema.blockSpecs,this.inlineContentImplementations=o.schema.inlineContentSpecs,this.styleImplementations=o.schema.styleSpecs,this.formattingToolbar=new fe(this),this.linkToolbar=new be(this),this.sideMenu=new Se(this),this.suggestionMenus=new ke(this),P("image",this)&&(this.imagePanel=new Te(this)),P("table",this)&&(this.tableHandles=new Me(this));const i=Pe({editor:this,placeholders:o.placeholders,domAttributes:o.domAttributes||{},blockSchema:this.schema.blockSchema,blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:o.collaboration}),r=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.formattingToolbar.plugin,this.linkToolbar.plugin,this.sideMenu.plugin,this.suggestionMenus.plugin,...this.imagePanel?[this.imagePanel.plugin]:[],...this.tableHandles?[this.tableHandles.plugin]:[]]});i.push(r),this.uploadFile=o.uploadFile,o.collaboration&&o.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const s=o.initialContent||(t.collaboration?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:G.options.generateID()}]);if(!Array.isArray(s)||s.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+s);const a={...Go,...o._tiptapOptions,content:s,extensions:o.enableBlockNoteExtensions===!1?((l=o._tiptapOptions)==null?void 0:l.extensions)||[]:[...((c=o._tiptapOptions)==null?void 0:c.extensions)||[],...i],editorProps:{...(h=o._tiptapOptions)==null?void 0:h.editorProps,attributes:{...(f=(p=o._tiptapOptions)==null?void 0:p.editorProps)==null?void 0:f.attributes,...(m=o.domAttributes)==null?void 0:m.editor,class:O("bn-editor",o.defaultStyles?"bn-default-styles":"",((E=(g=o.domAttributes)==null?void 0:g.editor)==null?void 0:E.class)||"")},transformPasted:qo}};this._tiptapEditor=new $o(a,this.schema.styleSchema)}static create(t={}){return new Lt(t)}mount(t){this._tiptapEditor.mount(t)}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(){return this.topLevelBlocks}get document(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(S(e,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(o=S(i,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),!1)),o}forEachBlock(t,e=!1){const o=this.document.slice();e&&o.reverse();function i(r){for(const s of r){if(!t(s))return!1;const a=e?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:o,endPos:i}=w(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 a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:S(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:S(a,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:S(l,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)}}setTextCursorPosition(t,e="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:i}=Bt(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=w(this._tiptapEditor.state.doc,i+2),a=this.schema.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")e==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new L(a)}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,o)=>e.type.spec.group!=="blockContent"||o+e.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(S(this._tiptapEditor.state.doc.resolve(o).node(),this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,e,o="before"){return to(t,e,o,this)}updateBlock(t,e){return eo(t,e,this)}removeBlocks(t){return no(t,this)}replaceBlocks(t,e){return oo(t,e,this)}insertInlineContent(t){const e=Q(t,this._tiptapEditor.schema,this.schema.styleSchema);io({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},e,this)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks();for(const o of e){const i=this.schema.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?t[i.type]=!0:t[i.type]=o.attrs.stringValue}return t}addStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.schema.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(e,{stringValue:o});else throw new L(i.propSchema)}}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.schema.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(e,{stringValue:o});else throw new L(i.propSchema)}}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:o,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,o,i).addMark(o,o+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=w(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}=w(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.document){return Z(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return he(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.document){return so(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return mo(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,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)}onChange(t){const e=()=>{t(this)};return this._tiptapEditor.on("update",e),()=>{this._tiptapEditor.off("update",e)}}onSelectionChange(t){const e=()=>{t(this)};return this._tiptapEditor.on("selectionUpdate",e),()=>{this._tiptapEditor.off("selectionUpdate",e)}}}function Ko(n){let t=n.getTextCursorPosition().block,e=n.schema.blockSchema[t.type].content;for(;e==="none";)t=n.getTextCursorPosition().nextBlock,e=n.schema.blockSchema[t.type].content,n.setTextCursorPosition(t,"end")}function H(n,t){const e=n.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(e.content)&&(e.content.length===1&&K(e.content[0])&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0)?n.updateBlock(e,t):(n.insertBlocks([t],e,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return Ko(n),o}function jo(n){const t=[];return P("heading",n)&&t.push({title:"Heading 1",onItemClick:()=>{H(n,{type:"heading",props:{level:1}})},subtext:"Used for a top-level heading",badge:V("Mod-Alt-1"),aliases:["h","heading1","h1"],group:"Headings"},{title:"Heading 2",onItemClick:()=>{H(n,{type:"heading",props:{level:2}})},subtext:"Used for key sections",badge:V("Mod-Alt-2"),aliases:["h2","heading2","subheading"],group:"Headings"},{title:"Heading 3",onItemClick:()=>{H(n,{type:"heading",props:{level:3}})},subtext:"Used for subsections and group headings",badge:V("Mod-Alt-3"),aliases:["h3","heading3","subheading"],group:"Headings"}),P("numberedListItem",n)&&t.push({title:"Numbered List",onItemClick:()=>{H(n,{type:"numberedListItem"})},subtext:"Used to display a numbered list",badge:V("Mod-Shift-7"),aliases:["ol","li","list","numberedlist","numbered list"],group:"Basic blocks"}),P("bulletListItem",n)&&t.push({title:"Bullet List",onItemClick:()=>{H(n,{type:"bulletListItem"})},subtext:"Used to display an unordered list",badge:V("Mod-Shift-8"),aliases:["ul","li","list","bulletlist","bullet list"],group:"Basic blocks"}),P("paragraph",n)&&t.push({title:"Paragraph",onItemClick:()=>{H(n,{type:"paragraph"})},subtext:"Used for the body of your document",badge:V("Mod-Alt-0"),aliases:["p","paragraph"],group:"Basic blocks"}),P("table",n)&&t.push({title:"Table",onItemClick:()=>{H(n,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},subtext:"Used for for tables",aliases:["table"],group:"Advanced",badge:void 0}),P("image",n)&&t.push({title:"Image",onItemClick:()=>{const e=H(n,{type:"image"});n.prosemirrorView.dispatch(n._tiptapEditor.state.tr.setMeta(n.imagePanel.plugin,{block:e}))},subtext:"Insert an image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],group:"Media"}),t}function Wo(n,t){return n.filter(({title:e,aliases:o})=>e.toLowerCase().startsWith(t.toLowerCase())||o&&o.filter(i=>i.toLowerCase().startsWith(t.toLowerCase())).length!==0)}function Pt(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function Ne(n){return typeof n=="string"?Pt(n):Array.isArray(n)?n.flatMap(t=>typeof t=="string"?Pt(t):ut(t)?{...t,content:Pt(t.content)}:K(t)?t:{props:{},...t,content:Ne(t.content)}):n}function Jo(n,t){return t.map(e=>Nt(n,e))}function Nt(n,t){const e={id:"",type:t.type,props:{},content:n[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(n[t.type].propSchema).forEach(([o,i])=>{e.props[o]===void 0&&(e.props[o]=i.default)}),{...e,content:Ne(e.content),children:e.children.map(o=>Nt(n,o))}}function Ae(n){n.id||(n.id=G.options.generateID()),n.children&&He(n.children)}function He(n){for(const t of n)Ae(t)}d.BlockNoteEditor=Lt,d.BlockNoteSchema=at,d.FormattingToolbarProsemirrorPlugin=fe,d.FormattingToolbarView=pe,d.ImagePanelProsemirrorPlugin=Te,d.ImagePanelView=Ce,d.LinkToolbarProsemirrorPlugin=be,d.SideMenuProsemirrorPlugin=Se,d.SideMenuView=ve,d.SuggestionMenuProseMirrorPlugin=ke,d.TableHandlesProsemirrorPlugin=Me,d.TableHandlesView=Be,d.UniqueID=G,d.UnreachableCaseError=L,d.addIdsToBlock=Ae,d.addIdsToBlocks=He,d.addInlineContentAttributes=Yt,d.addInlineContentKeyboardShortcuts=Qt,d.addStyleAttributes=oe,d.blockToNode=N,d.camelToDataKebab=et,d.checkBlockHasDefaultProp=Zn,d.checkBlockIsDefaultType=Qn,d.checkBlockTypeHasDefaultProp=le,d.checkDefaultBlockTypeInSchema=P,d.contentNodeToInlineContent=ot,d.createBlockSpec=Xt,d.createBlockSpecFromStronglyTypedTiptapNode=j,d.createExternalHTMLExporter=Z,d.createInlineContentSpec=Sn,d.createInlineContentSpecFromTipTapNode=te,d.createInternalBlockSpec=kt,d.createInternalHTMLSerializer=ft,d.createInternalInlineContentSpec=Zt,d.createInternalStyleSpec=vt,d.createStronglyTypedTiptapNode=q,d.createStyleSpec=Cn,d.createStyleSpecFromTipTapMark=U,d.createSuggestionMenu=ko,d.defaultBlockSchema=ae,d.defaultBlockSpecs=Ct,d.defaultInlineContentSchema=Yn,d.defaultInlineContentSpecs=xt,d.defaultProps=C,d.defaultStyleSchema=Xn,d.defaultStyleSpecs=Tt,d.filterSuggestionItems=Wo,d.formatKeyboardShortcut=V,d.formattingToolbarPluginKey=me,d.getBlockFromPos=Wt,d.getBlockNoteExtensions=Pe,d.getBlockSchemaFromSpecs=yt,d.getDefaultSlashMenuItems=jo,d.getDraggableBlockFromCoords=rt,d.getInlineContentParseRules=ee,d.getInlineContentSchemaFromSpecs=wt,d.getParseRules=Jt,d.getStyleParseRules=ie,d.getStyleSchemaFromSpecs=Et,d.inheritedProps=gt,d.inlineContentToNodes=Q,d.insertOrUpdateBlock=H,d.isAppleOS=Kt,d.isLinkInlineContent=dt,d.isPartialLinkInlineContent=ut,d.isSafari=En,d.isStyledTextInlineContent=K,d.linkToolbarPluginKey=ge,d.mergeCSSClasses=O,d.nodeToBlock=S,d.nodeToCustomInlineContent=mt,d.partialBlockToBlockForTesting=Nt,d.partialBlocksToBlocksForTesting=Jo,d.propsToAttributes=bt,d.sideMenuPluginKey=Ee,d.stylePropsToAttributes=ne,d.suggestionMenuPluginKey=R,d.tableContentToNodes=pt,d.tableHandlesPluginKey=X,d.uploadToTmpFilesDotOrg_DEV_ONLY=vn,d.wrapInBlockStructure=it,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
8
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|