@blocknote/core 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/blocknote.cjs +7 -7
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +1064 -999
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/dist/webpack-stats.json +1 -1
  7. package/package.json +2 -1
  8. package/src/api/__snapshots__/blocks-moved-down-twice-in-same-parent.json +44 -0
  9. package/src/api/__snapshots__/blocks-moved-insert-changes-sibling-order.json +26 -0
  10. package/src/api/__snapshots__/blocks-moved-nested-sibling-reorder.json +180 -0
  11. package/src/api/__snapshots__/blocks-moved-up-down-in-same-parent.json +44 -0
  12. package/src/api/__snapshots__/blocks-moved-up-down-in-same-transaction.json +44 -0
  13. package/src/api/{nodeUtil.test.ts → getBlocksChangedByTransaction.test.ts} +117 -1
  14. package/src/api/getBlocksChangedByTransaction.ts +422 -0
  15. package/src/api/nodeUtil.ts +0 -250
  16. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +22 -0
  17. package/src/blocks/TableBlockContent/TableBlockContent.ts +26 -2
  18. package/src/editor/BlockNoteEditor.ts +1 -1
  19. package/src/editor/editor.css +5 -0
  20. package/src/extensions/BlockChange/BlockChangePlugin.ts +4 -2
  21. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -5
  22. package/src/index.ts +1 -0
  23. package/types/src/api/getBlocksChangedByTransaction.d.ts +63 -0
  24. package/types/src/api/nodeUtil.d.ts +0 -63
  25. package/types/src/editor/BlockNoteEditor.d.ts +1 -1
  26. package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +1 -1
  27. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +2 -2
  28. package/types/src/index.d.ts +1 -0
  29. package/types/src/schema/inlineContent/internal.d.ts +1 -1
  30. package/dist/tsconfig.tsbuildinfo +0 -1
  31. /package/types/src/api/{nodeUtil.test.d.ts → getBlocksChangedByTransaction.test.d.ts} +0 -0
@@ -1,13 +1,13 @@
1
- "use strict";var yr=Object.create;var rt=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var Cr=Object.getOwnPropertyNames;var vr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Er=(e,n,t)=>n in e?rt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Br=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Cr(n))!Sr.call(e,r)&&r!==t&&rt(e,r,{get:()=>n[r],enumerable:!(o=wr(n,r))||o.enumerable});return e};var K=(e,n,t)=>(t=e!=null?yr(vr(e)):{},Br(n||!e||!e.__esModule?rt(t,"default",{value:e,enumerable:!0}):t,e));var p=(e,n,t)=>Er(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("prosemirror-model"),he=require("prosemirror-transform"),y=require("@tiptap/core"),C=require("prosemirror-state"),fn=require("uuid"),I=require("prosemirror-tables"),Tr=require("prosemirror-highlight"),xr=require("prosemirror-highlight/shiki"),Pr=require("@tiptap/extension-bold"),Mr=require("@tiptap/extension-code"),Ir=require("@tiptap/extension-italic"),Lr=require("@tiptap/extension-strike"),Ar=require("@tiptap/extension-underline"),Nr=require("@tiptap/extension-table-cell"),Dr=require("@tiptap/extension-table-header"),Hr=require("@tiptap/extension-gapcursor"),Or=require("@tiptap/extension-history"),Rr=require("@tiptap/extension-link"),_r=require("@tiptap/extension-text"),D=require("y-prosemirror"),H=require("prosemirror-view"),Vr=require("yjs"),jt=require("prosemirror-history"),Ur=require("prosemirror-dropcursor"),Fr=require("./en-ub2yVBX0.cjs"),Ee=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function $r(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const zr=Ee(Pr),Wr=Ee(Mr),qr=Ee(Ir),Kr=Ee(Lr),jr=Ee(Ar),ie=$r(Vr);function Gr(e,n=JSON.stringify){const t={};return e.filter(o=>{const r=n(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Yr(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return Gr(n)}const Be=y.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const e=window.__TEST_OPTIONS;return e.mockID===void 0?e.mockID=0:e.mockID++,e.mockID.toString()}return fn.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:e=>e.getAttribute(`data-${this.options.attributeName}`),renderHTML:e=>{const n={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...n,id:e[this.options.attributeName]}:n}}}}]},addProseMirrorPlugins(){let e=null,n=!1;return[new C.Plugin({key:new C.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const s=t.some(m=>m.docChanged)&&!o.doc.eq(r.doc),i=this.options.filterTransaction&&t.some(m=>{let g,b;return!(!((b=(g=this.options).filterTransaction)===null||b===void 0)&&b.call(g,m))});if(!s||i)return;const{tr:a}=r,{types:l,attributeName:c,generateID:d}=this.options,u=y.combineTransactionSteps(o.doc,t),{mapping:h}=u;if(y.getChangedRanges(u).forEach(({newRange:m})=>{const g=y.findChildrenInRange(r.doc,m,w=>l.includes(w.type.name)),b=g.map(({node:w})=>w.attrs[c]).filter(w=>w!==null),k=Yr(b);g.forEach(({node:w,pos:v})=>{let E;const _=(E=a.doc.nodeAt(v))===null||E===void 0?void 0:E.attrs[c];if(_===null){const x=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(x)===null){const M=JSON.parse(JSON.stringify(r.doc.toJSON()));if(M.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(M.content)===JSON.stringify(x.toJSON())){a.setNodeMarkup(v,void 0,{...w.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(v,void 0,{...w.attrs,[c]:d()});return}const{deleted:q}=h.invert().mapResult(v);q&&k.includes(_)&&a.setNodeMarkup(v,void 0,{...w.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const o=r=>{let s;e=!((s=t.dom.parentElement)===null||s===void 0)&&s.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let r;return e!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy"?n=!0:n=!1,e=null,!1},paste:()=>(n=!0,!1)},transformPasted:t=>{if(!n)return t;const{types:o,attributeName:r}=this.options,s=i=>{const a=[];return i.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(s(l.content)));return}const c=l.type.create({...l.attrs,[r]:null},s(l.content),l.marks);a.push(c)}),S.Fragment.from(a)};return n=!1,new S.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function lt(e){return e.type==="link"}function St(e){return typeof e!="string"&&e.type==="link"}function oe(e){return typeof e!="string"&&e.type==="text"}function Ue(e){var n,t,o,r,s;return Ke(e)?{...e}:fe(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:((n=e.props)==null?void 0:n.backgroundColor)??"default",textColor:((t=e.props)==null?void 0:t.textColor)??"default",textAlignment:((o=e.props)==null?void 0:o.textAlignment)??"left",colspan:((r=e.props)==null?void 0:r.colspan)??1,rowspan:((s=e.props)==null?void 0:s.rowspan)??1}}:{type:"tableCell",content:[].concat(e),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function fe(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function Ke(e){return fe(e)&&e.props!==void 0&&e.content!==void 0}function me(e){return Ke(e)?e.props.colspan??1:1}function Fe(e){return Ke(e)?e.props.rowspan??1:1}class j extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Jr(e,n=!0){const{"data-test":t,...o}=e;if(Object.keys(o).length>0&&n)throw new Error("Object must be empty "+JSON.stringify(e))}const mn=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function J(e,n="Ctrl"){return mn()?e.replace("Mod","⌘"):e.replace("Mod",n)}function Q(...e){return[...new Set(e.filter(n=>n).join(" ").split(" "))].join(" ")}const Xr=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function $(e,n,t,o){const r=document.createElement("div");r.className=Q("bn-block-content",t.class),r.setAttribute("data-content-type",e);for(const[i,a]of Object.entries(t))i!=="class"&&r.setAttribute(i,a);const s=document.createElement(n);s.className=Q("bn-inline-content",o.class);for(const[i,a]of Object.entries(o))i!=="class"&&s.setAttribute(i,a);return r.appendChild(s),{dom:r,contentDOM:s}}const ct=(e,n)=>{let t=se(e,n.pmSchema);t.type.name==="blockContainer"&&(t=t.firstChild);const o=n.pmSchema.nodes[t.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 r=o(t);if(typeof r!="object"||!("dom"in r))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 r};function gn(e){const n=e.querySelectorAll("p");if(n.length>1){const t=n[0];for(let o=1;o<n.length;o++){const r=n[o];t.innerHTML+="<br>"+r.innerHTML,r.remove()}}}const L={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},Et=["backgroundColor","textColor"];function ve(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Zr(e){const n=e.split("/");return!n.length||n[n.length-1]===""?e:n[n.length-1]}function ge(e){const n={};return Object.entries(e).filter(([t,o])=>!Et.includes(t)).forEach(([t,o])=>{n[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(ve(t));if(s===null)return null;if(o.default===void 0&&o.type==="boolean"||o.default!==void 0&&typeof o.default=="boolean")return s==="true"?!0:s==="false"?!1:null;if(o.default===void 0&&o.type==="number"||o.default!==void 0&&typeof o.default=="number"){const i=parseFloat(s);return!Number.isNaN(i)&&Number.isFinite(i)?i:null}return s},renderHTML:r=>r[t]!==o.default?{[ve(t)]:r[t]}:{}}}),n}function je(e,n,t,o){if(typeof e=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const r=e(),i=t.state.doc.resolve(r).node().attrs.id;if(!i)throw new Error("Block doesn't have id");const a=n.getBlock(i);if(a.type!==o)throw new Error("Block type does not match");return a}function Ce(e,n,t,o,r=!1,s){const i=document.createElement("div");if(s!==void 0)for(const[a,l]of Object.entries(s))a!=="class"&&i.setAttribute(a,l);i.className=Q("bn-block-content",(s==null?void 0:s.class)||""),i.setAttribute("data-content-type",n);for(const[a,l]of Object.entries(t)){const d=o[a].default;!Et.includes(a)&&l!==d&&i.setAttribute(ve(a),l)}return r&&i.setAttribute("data-file-block",""),i.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=Q("bn-inline-content",e.contentDOM.className)),{...e,dom:i}}function G(e){return y.Node.create(e)}function Bt(e,n){return{config:e,implementation:n}}function Z(e,n,t){return Bt({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:ct,toExternalHTML:ct})}function Tt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function bn(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function kn(e,n){const t=[{tag:"[data-content-type="+e.type+"]",contentElement:".bn-inline-content"}];return n&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const r=n==null?void 0:n(o);return r===void 0?!1:r}}),t}function be(e,n){const t=G({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return ge(e.propSchema)},parseHTML(){return kn(e,n.parse)},renderHTML({HTMLAttributes:o}){const r=document.createElement("div");return Ce({dom:r,contentDOM:e.content==="inline"?r:void 0},e.type,{},e.propSchema,e.isFileBlock,o)},addNodeView(){return({getPos:o})=>{var c;const r=this.options.editor,s=je(o,r,this.editor,e.type),i=((c=this.options.domAttributes)==null?void 0:c.blockContent)||{},a=n.render(s,r),l=Ce(a,s.type,s.props,e.propSchema,e.isFileBlock,i);return e.isSelectable===!1&&bn(l,this.editor),l}}});if(t.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return Bt(e,{node:t,toInternalHTML:(o,r)=>{var a;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},i=n.render(o,r);return Ce(i,o.type,o.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(o,r)=>{var a,l;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let i=(l=n.toExternalHTML)==null?void 0:l.call(n,o,r);return i===void 0&&(i=n.render(o,r)),Ce(i,o.type,o.props,e.propSchema,s)}})}function X(e,n){const t=e.resolve(n);if(t.nodeAfter&&t.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:t.pos,node:t.nodeAfter};let o=t.depth,r=t.node(o);for(;o>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:t.before(o),node:r};o--,r=t.node(o)}const s=[];e.descendants((a,l)=>{a.type.isInGroup("bnBlock")&&s.push(l)}),console.warn(`Position ${n} is not within a blockContainer node.`);const i=e.resolve(s.find(a=>a>=n)||s[s.length-1]);return{posBeforeNode:i.pos,node:i.nodeAfter}}function Ge(e,n){if(!e.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${e.type.name}`);const t=e,o=n,r=o+t.nodeSize,s={node:t,beforePos:o,afterPos:r};if(t.type.name==="blockContainer"){let i,a;if(t.forEach((l,c)=>{if(l.type.spec.group==="blockContent"){const d=l,u=o+c+1,h=u+l.nodeSize;i={node:d,beforePos:u,afterPos:h}}else if(l.type.name==="blockGroup"){const d=l,u=o+c+1,h=u+l.nodeSize;a={node:d,beforePos:u,afterPos:h}}}),!i)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${t}`);return{isBlockContainer:!0,bnBlock:s,blockContent:i,childContainer:a,blockNoteType:i.node.type.name}}else{if(!s.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${s.node}`);return{isBlockContainer:!1,bnBlock:s,childContainer:s,blockNoteType:s.node.type.name}}}function ee(e){return Ge(e.node,e.posBeforeNode)}function ke(e){if(!e.nodeAfter)throw new Error(`Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`);return Ge(e.nodeAfter,e.pos)}function B(e){const n=X(e.doc,e.selection.anchor);return ee(n)}function Te(e){const n=X(e.doc,e.selection.anchor);return ee(n)}function R(e){return"doc"in e?e.doc.type.schema:e.type.schema}function yn(e){return e.cached.blockNoteEditor}function ye(e){return yn(e).schema}function Ye(e){return ye(e).blockSchema}function Je(e){return ye(e).inlineContentSchema}function ce(e){return ye(e).styleSchema}function Xe(e){return yn(e).blockCache}function xt(e,n,t){var s,i;const o={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},r=[];e.content.forEach((a,l,c)=>{const d={cells:[]};c===0&&a.content.forEach(u=>{let h=u.attrs.colwidth;h==null&&(h=new Array(u.attrs.colspan??1).fill(void 0)),o.columnWidths.push(...h)}),d.cells=a.content.content.map((u,h)=>(r[c]||(r[c]=[]),r[c][h]=u.type.name==="tableHeader",{type:"tableCell",content:u.content.content.map(m=>xe(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],k=g[0];return k&&oe(b)&&oe(k)&&JSON.stringify(b.styles)===JSON.stringify(k.styles)?(b.text+=`
1
+ "use strict";var yr=Object.create;var rt=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var Cr=Object.getOwnPropertyNames;var vr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Er=(e,n,t)=>n in e?rt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var Br=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Cr(n))!Sr.call(e,r)&&r!==t&&rt(e,r,{get:()=>n[r],enumerable:!(o=wr(n,r))||o.enumerable});return e};var q=(e,n,t)=>(t=e!=null?yr(vr(e)):{},Br(n||!e||!e.__esModule?rt(t,"default",{value:e,enumerable:!0}):t,e));var h=(e,n,t)=>Er(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("prosemirror-model"),he=require("prosemirror-transform"),w=require("@tiptap/core"),C=require("prosemirror-state"),fn=require("uuid"),L=require("prosemirror-tables"),Tr=require("fast-deep-equal"),xr=require("prosemirror-highlight"),Pr=require("prosemirror-highlight/shiki"),Mr=require("@tiptap/extension-bold"),Ir=require("@tiptap/extension-code"),Lr=require("@tiptap/extension-italic"),Ar=require("@tiptap/extension-strike"),Nr=require("@tiptap/extension-underline"),Dr=require("@tiptap/extension-table-cell"),Hr=require("@tiptap/extension-table-header"),Or=require("@tiptap/extension-gapcursor"),_r=require("@tiptap/extension-history"),Rr=require("@tiptap/extension-link"),Vr=require("@tiptap/extension-text"),H=require("y-prosemirror"),O=require("prosemirror-view"),Ur=require("yjs"),jt=require("prosemirror-history"),Fr=require("prosemirror-dropcursor"),$r=require("./en-ub2yVBX0.cjs"),ge=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function Wr(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const zr=ge(Tr),qr=ge(Mr),Kr=ge(Ir),jr=ge(Lr),Gr=ge(Ar),Yr=ge(Nr),ie=Wr(Ur);function Xr(e,n=JSON.stringify){const t={};return e.filter(o=>{const r=n(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Jr(e){const n=e.filter((o,r)=>e.indexOf(o)!==r);return Xr(n)}const Be=w.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const e=window.__TEST_OPTIONS;return e.mockID===void 0?e.mockID=0:e.mockID++,e.mockID.toString()}return fn.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:e=>e.getAttribute(`data-${this.options.attributeName}`),renderHTML:e=>{const n={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...n,id:e[this.options.attributeName]}:n}}}}]},addProseMirrorPlugins(){let e=null,n=!1;return[new C.Plugin({key:new C.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const s=t.some(m=>m.docChanged)&&!o.doc.eq(r.doc),i=this.options.filterTransaction&&t.some(m=>{let g,b;return!(!((b=(g=this.options).filterTransaction)===null||b===void 0)&&b.call(g,m))});if(!s||i)return;const{tr:a}=r,{types:l,attributeName:c,generateID:d}=this.options,u=w.combineTransactionSteps(o.doc,t),{mapping:p}=u;if(w.getChangedRanges(u).forEach(({newRange:m})=>{const g=w.findChildrenInRange(r.doc,m,y=>l.includes(y.type.name)),b=g.map(({node:y})=>y.attrs[c]).filter(y=>y!==null),k=Jr(b);g.forEach(({node:y,pos:S})=>{let v;const P=(v=a.doc.nodeAt(S))===null||v===void 0?void 0:v.attrs[c];if(P===null){const B=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(B)===null){const I=JSON.parse(JSON.stringify(r.doc.toJSON()));if(I.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(I.content)===JSON.stringify(B.toJSON())){a.setNodeMarkup(S,void 0,{...y.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(S,void 0,{...y.attrs,[c]:d()});return}const{deleted:Y}=p.invert().mapResult(S);Y&&k.includes(P)&&a.setNodeMarkup(S,void 0,{...y.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const o=r=>{let s;e=!((s=t.dom.parentElement)===null||s===void 0)&&s.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let r;return e!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy"?n=!0:n=!1,e=null,!1},paste:()=>(n=!0,!1)},transformPasted:t=>{if(!n)return t;const{types:o,attributeName:r}=this.options,s=i=>{const a=[];return i.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(s(l.content)));return}const c=l.type.create({...l.attrs,[r]:null},s(l.content),l.marks);a.push(c)}),E.Fragment.from(a)};return n=!1,new E.Slice(s(t.content),t.openStart,t.openEnd)}}})]}});function lt(e){return e.type==="link"}function St(e){return typeof e!="string"&&e.type==="link"}function oe(e){return typeof e!="string"&&e.type==="text"}function Ue(e){var n,t,o,r,s;return Ke(e)?{...e}:fe(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:((n=e.props)==null?void 0:n.backgroundColor)??"default",textColor:((t=e.props)==null?void 0:t.textColor)??"default",textAlignment:((o=e.props)==null?void 0:o.textAlignment)??"left",colspan:((r=e.props)==null?void 0:r.colspan)??1,rowspan:((s=e.props)==null?void 0:s.rowspan)??1}}:{type:"tableCell",content:[].concat(e),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function fe(e){return e!=null&&typeof e!="string"&&!Array.isArray(e)&&e.type==="tableCell"}function Ke(e){return fe(e)&&e.props!==void 0&&e.content!==void 0}function me(e){return Ke(e)?e.props.colspan??1:1}function Fe(e){return Ke(e)?e.props.rowspan??1:1}class K extends Error{constructor(n){super(`Unreachable case: ${n}`)}}function Zr(e,n=!0){const{"data-test":t,...o}=e;if(Object.keys(o).length>0&&n)throw new Error("Object must be empty "+JSON.stringify(e))}const mn=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function X(e,n="Ctrl"){return mn()?e.replace("Mod","⌘"):e.replace("Mod",n)}function Q(...e){return[...new Set(e.filter(n=>n).join(" ").split(" "))].join(" ")}const Qr=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function $(e,n,t,o){const r=document.createElement("div");r.className=Q("bn-block-content",t.class),r.setAttribute("data-content-type",e);for(const[i,a]of Object.entries(t))i!=="class"&&r.setAttribute(i,a);const s=document.createElement(n);s.className=Q("bn-inline-content",o.class);for(const[i,a]of Object.entries(o))i!=="class"&&s.setAttribute(i,a);return r.appendChild(s),{dom:r,contentDOM:s}}const ct=(e,n)=>{let t=se(e,n.pmSchema);t.type.name==="blockContainer"&&(t=t.firstChild);const o=n.pmSchema.nodes[t.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 r=o(t);if(typeof r!="object"||!("dom"in r))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 r};function gn(e){const n=e.querySelectorAll("p");if(n.length>1){const t=n[0];for(let o=1;o<n.length;o++){const r=n[o];t.innerHTML+="<br>"+r.innerHTML,r.remove()}}}const A={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},Et=["backgroundColor","textColor"];function Se(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function es(e){const n=e.split("/");return!n.length||n[n.length-1]===""?e:n[n.length-1]}function be(e){const n={};return Object.entries(e).filter(([t,o])=>!Et.includes(t)).forEach(([t,o])=>{n[t]={default:o.default,keepOnSplit:!0,parseHTML:r=>{const s=r.getAttribute(Se(t));if(s===null)return null;if(o.default===void 0&&o.type==="boolean"||o.default!==void 0&&typeof o.default=="boolean")return s==="true"?!0:s==="false"?!1:null;if(o.default===void 0&&o.type==="number"||o.default!==void 0&&typeof o.default=="number"){const i=parseFloat(s);return!Number.isNaN(i)&&Number.isFinite(i)?i:null}return s},renderHTML:r=>r[t]!==o.default?{[Se(t)]:r[t]}:{}}}),n}function je(e,n,t,o){if(typeof e=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const r=e(),i=t.state.doc.resolve(r).node().attrs.id;if(!i)throw new Error("Block doesn't have id");const a=n.getBlock(i);if(a.type!==o)throw new Error("Block type does not match");return a}function ve(e,n,t,o,r=!1,s){const i=document.createElement("div");if(s!==void 0)for(const[a,l]of Object.entries(s))a!=="class"&&i.setAttribute(a,l);i.className=Q("bn-block-content",(s==null?void 0:s.class)||""),i.setAttribute("data-content-type",n);for(const[a,l]of Object.entries(t)){const d=o[a].default;!Et.includes(a)&&l!==d&&i.setAttribute(Se(a),l)}return r&&i.setAttribute("data-file-block",""),i.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=Q("bn-inline-content",e.contentDOM.className)),{...e,dom:i}}function j(e){return w.Node.create(e)}function Bt(e,n){return{config:e,implementation:n}}function Z(e,n,t){return Bt({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:n},{node:e,requiredExtensions:t,toInternalHTML:ct,toExternalHTML:ct})}function Tt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function bn(e,n){e.stopEvent=t=>(t.type==="mousedown"&&setTimeout(()=>{n.view.dom.blur()},10),!0)}function kn(e,n){const t=[{tag:"[data-content-type="+e.type+"]",contentElement:".bn-inline-content"}];return n&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const r=n==null?void 0:n(o);return r===void 0?!1:r}}),t}function ke(e,n){const t=j({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes(){return be(e.propSchema)},parseHTML(){return kn(e,n.parse)},renderHTML({HTMLAttributes:o}){const r=document.createElement("div");return ve({dom:r,contentDOM:e.content==="inline"?r:void 0},e.type,{},e.propSchema,e.isFileBlock,o)},addNodeView(){return({getPos:o})=>{var c;const r=this.options.editor,s=je(o,r,this.editor,e.type),i=((c=this.options.domAttributes)==null?void 0:c.blockContent)||{},a=n.render(s,r),l=ve(a,s.type,s.props,e.propSchema,e.isFileBlock,i);return e.isSelectable===!1&&bn(l,this.editor),l}}});if(t.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return Bt(e,{node:t,toInternalHTML:(o,r)=>{var a;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},i=n.render(o,r);return ve(i,o.type,o.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(o,r)=>{var a,l;const s=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let i=(l=n.toExternalHTML)==null?void 0:l.call(n,o,r);return i===void 0&&(i=n.render(o,r)),ve(i,o.type,o.props,e.propSchema,s)}})}function J(e,n){const t=e.resolve(n);if(t.nodeAfter&&t.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:t.pos,node:t.nodeAfter};let o=t.depth,r=t.node(o);for(;o>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:t.before(o),node:r};o--,r=t.node(o)}const s=[];e.descendants((a,l)=>{a.type.isInGroup("bnBlock")&&s.push(l)}),console.warn(`Position ${n} is not within a blockContainer node.`);const i=e.resolve(s.find(a=>a>=n)||s[s.length-1]);return{posBeforeNode:i.pos,node:i.nodeAfter}}function Ge(e,n){if(!e.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${e.type.name}`);const t=e,o=n,r=o+t.nodeSize,s={node:t,beforePos:o,afterPos:r};if(t.type.name==="blockContainer"){let i,a;if(t.forEach((l,c)=>{if(l.type.spec.group==="blockContent"){const d=l,u=o+c+1,p=u+l.nodeSize;i={node:d,beforePos:u,afterPos:p}}else if(l.type.name==="blockGroup"){const d=l,u=o+c+1,p=u+l.nodeSize;a={node:d,beforePos:u,afterPos:p}}}),!i)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${t}`);return{isBlockContainer:!0,bnBlock:s,blockContent:i,childContainer:a,blockNoteType:i.node.type.name}}else{if(!s.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${s.node}`);return{isBlockContainer:!1,bnBlock:s,childContainer:s,blockNoteType:s.node.type.name}}}function ee(e){return Ge(e.node,e.posBeforeNode)}function ye(e){if(!e.nodeAfter)throw new Error(`Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`);return Ge(e.nodeAfter,e.pos)}function T(e){const n=J(e.doc,e.selection.anchor);return ee(n)}function Te(e){const n=J(e.doc,e.selection.anchor);return ee(n)}function R(e){return"doc"in e?e.doc.type.schema:e.type.schema}function yn(e){return e.cached.blockNoteEditor}function we(e){return yn(e).schema}function Ye(e){return we(e).blockSchema}function Xe(e){return we(e).inlineContentSchema}function ce(e){return we(e).styleSchema}function Je(e){return yn(e).blockCache}function xt(e,n,t){var s,i;const o={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},r=[];e.content.forEach((a,l,c)=>{const d={cells:[]};c===0&&a.content.forEach(u=>{let p=u.attrs.colwidth;p==null&&(p=new Array(u.attrs.colspan??1).fill(void 0)),o.columnWidths.push(...p)}),d.cells=a.content.content.map((u,p)=>(r[c]||(r[c]=[]),r[c][p]=u.type.name==="tableHeader",{type:"tableCell",content:u.content.content.map(m=>xe(m,n,t)).reduce((m,g)=>{if(!m.length)return g;const b=m[m.length-1],k=g[0];return k&&oe(b)&&oe(k)&&JSON.stringify(b.styles)===JSON.stringify(k.styles)?(b.text+=`
2
2
  `+k.text,m.push(...g.slice(1)),m):(m.push(...g),m)},[]),props:{colspan:u.attrs.colspan,rowspan:u.attrs.rowspan,backgroundColor:u.attrs.backgroundColor,textColor:u.attrs.textColor,textAlignment:u.attrs.textAlignment}})),o.rows.push(d)});for(let a=0;a<r.length;a++)(s=r[a])!=null&&s.every(l=>l)&&(o.headerRows=(o.headerRows??0)+1);for(let a=0;a<((i=r[0])==null?void 0:i.length);a++)r!=null&&r.every(l=>l[a])&&(o.headerCols=(o.headerCols??0)+1);return o}function xe(e,n,t){const o=[];let r;return e.content.forEach(s=>{if(s.type.name==="hardBreak"){if(r)if(oe(r))r.text+=`
3
3
  `;else if(lt(r))r.content[r.content.length-1].text+=`
4
4
  `;else throw new Error("unexpected");else r={type:"text",text:`
5
- `,styles:{}};return}if(s.type.name!=="link"&&s.type.name!=="text"){if(!n[s.type.name]){console.warn("unrecognized inline content type",s.type.name);return}r&&(o.push(r),r=void 0),o.push($e(s,n,t));return}const i={};let a;for(const l of s.marks)if(l.type.name==="link")a=l;else{const c=t[l.type.name];if(!c){if(l.type.spec.blocknoteIgnore)continue;throw new Error(`style ${l.type.name} not found in styleSchema`)}if(c.propSchema==="boolean")i[c.type]=!0;else if(c.propSchema==="string")i[c.type]=l.attrs.stringValue;else throw new j(c.propSchema)}r?oe(r)?a?(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):JSON.stringify(r.styles)===JSON.stringify(i)?r.text+=s.textContent:(o.push(r),r={type:"text",text:s.textContent,styles:i}):lt(r)&&(a?r.href===a.attrs.href?JSON.stringify(r.content[r.content.length-1].styles)===JSON.stringify(i)?r.content[r.content.length-1].text+=s.textContent:r.content.push({type:"text",text:s.textContent,styles:i}):(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):(o.push(r),r={type:"text",text:s.textContent,styles:i})):a?r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}:r={type:"text",text:s.textContent,styles:i}}),r&&o.push(r),o}function $e(e,n,t){if(e.type.name==="text"||e.type.name==="link")throw new Error("unexpected");const o={},r=n[e.type.name];for(const[a,l]of Object.entries(e.attrs)){if(!r)throw Error("ic node is of an unrecognized type: "+e.type.name);const c=r.propSchema;a in c&&(o[a]=l)}let s;return r.content==="styled"?s=xe(e,n,t):s=void 0,{type:e.type.name,props:o,content:s}}function T(e,n,t=Ye(n),o=Je(n),r=ce(n),s=Xe(n)){var g;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const i=s==null?void 0:s.get(e);if(i)return i;const a=Ge(e,0);let l=a.bnBlock.node.attrs.id;l===null&&(l=Be.options.generateID());const c=t[a.blockNoteType];if(!c)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const d={};for(const[b,k]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const w=c.propSchema;b in w&&!(w[b].default===void 0&&k===void 0)&&(d[b]=k)}const u=t[a.blockNoteType],h=[];(g=a.childContainer)==null||g.node.forEach(b=>{h.push(T(b,n,t,o,r,s))});let f;if(u.content==="inline"){if(!a.isBlockContainer)throw new Error("impossible");f=xe(a.blockContent.node,o,r)}else if(u.content==="table"){if(!a.isBlockContainer)throw new Error("impossible");f=xt(a.blockContent.node,o,r)}else if(u.content==="none")f=void 0;else throw new j(u.content);const m={id:l,type:u.type,props:d,content:f,children:h};return s==null||s.set(e,m),m}function wn(e,n,t=Ye(n),o=Je(n),r=ce(n),s=Xe(n)){const i=[];return e.firstChild.descendants(a=>(i.push(T(a,n,t,o,r,s)),!1)),i}function Cn(e,n,t=Ye(n),o=Je(n),r=ce(n),s=Xe(n)){function i(a,l,c){if(a.type.name!=="blockGroup")throw new Error("unexpected");const d=[];let u,h;return a.forEach((f,m,g)=>{if(f.type.name!=="blockContainer")throw new Error("unexpected");if(f.childCount===0)return;if(f.childCount===0||f.childCount>2)throw new Error("unexpected, blockContainer.childCount: "+f.childCount);const b=g===0,k=g===a.childCount-1;if(f.firstChild.type.name==="blockGroup"){if(!b)throw new Error("unexpected");const _=i(f.firstChild,Math.max(0,l-1),k?Math.max(0,c-1):0);u=_.blockCutAtStart,k&&(h=_.blockCutAtEnd),d.push(..._.blocks);return}const w=T(f,n,t,o,r,s),v=f.childCount>1?f.child(1):void 0;let E=[];if(v){const _=i(v,0,k?Math.max(0,c-1):0);E=_.blocks,k&&(h=_.blockCutAtEnd)}k&&!v&&c>1&&(h=w.id),b&&l>1&&(u=w.id),d.push({...w,children:E})}),{blocks:d,blockCutAtStart:u,blockCutAtEnd:h}}if(e.content.childCount===0)return{blocks:[],blockCutAtStart:void 0,blockCutAtEnd:void 0};if(e.content.childCount!==1)throw new Error("slice must be a single block, did you forget includeParents=true?");return i(e.content.firstChild,Math.max(e.openStart-1,0),Math.max(e.openEnd-1,0))}function dt(e,n,t,o){return e.dom.setAttribute("data-inline-content-type",n),Object.entries(t).filter(([r,s])=>{const i=o[r];return s!==i.default}).map(([r,s])=>[ve(r),s]).forEach(([r,s])=>e.dom.setAttribute(r,s)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function vn(e){return{Backspace:({editor:n})=>{const t=n.state.selection.$from;return n.state.selection.empty&&t.node().type.name===e.type&&t.parentOffset===0}}}function Sn(e,n){return{config:e,implementation:n}}function En(e,n){return Sn({type:e.name,propSchema:n,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function Pt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Bn(e){return[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function Qr(e,n){const t=y.Node.create({name:e.type,inline:!0,group:"inline",selectable:e.content==="styled",atom:e.content==="none",content:e.content==="styled"?"inline*":"",addAttributes(){return ge(e.propSchema)},addKeyboardShortcuts(){return vn(e)},parseHTML(){return Bn(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render($e(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return dt(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render($e(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=W([a],s.pmSchema);s.transact(c=>c.replaceWith(r(),r()+o.nodeSize,l))},s);return dt(i,e.type,o.attrs,e.propSchema)}}});return En(t,e.propSchema)}function Tn(e){return e==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:n=>n.getAttribute("data-value"),renderHTML:n=>n.stringValue!==void 0?{"data-value":n.stringValue}:{}}}}function xn(e,n,t,o){return e.dom.setAttribute("data-style-type",n),o==="string"&&e.dom.setAttribute("data-value",t),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function Mt(e,n){return{config:e,implementation:n}}function ne(e,n){return Mt({type:e.name,propSchema:n},{mark:e})}function It(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Pn(e){return[{tag:`[data-style-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function es(e,n){const t=y.Mark.create({name:e.type,addAttributes(){return Tn(e.propSchema)},parseHTML(){return Pn(e)},renderHTML({mark:o}){let r;if(e.propSchema==="boolean")r=n.render();else if(e.propSchema==="string")r=n.render(o.attrs.stringValue);else throw new j(e.propSchema);return xn(r,e.type,o.attrs.stringValue,e.propSchema)}});return Mt(e,{mark:t})}function re(e){const{height:n,width:t}=Lt(e),o=new Array(n).fill(!1).map(()=>new Array(t).fill(null)),r=(s,i)=>{for(let a=s;a<n;a++)for(let l=i;l<t;l++)if(!o[a][l])return{row:a,col:l};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let s=0;s<e.content.rows.length;s++)for(let i=0;i<e.content.rows[s].cells.length;i++){const a=Ue(e.content.rows[s].cells[i]),l=Fe(a),c=me(a),{row:d,col:u}=r(s,i);for(let h=d;h<d+l;h++)for(let f=u;f<u+c;f++){if(o[h][f])throw new Error(`Unable to create occupancy grid for table, cell at ${h},${f} is already occupied`);o[h][f]={row:s,col:i,rowspan:l,colspan:c,cell:a}}}return o}function Se(e){const n=new Set;return e.map(t=>({cells:t.map(o=>n.has(o.row+":"+o.col)?!1:(n.add(o.row+":"+o.col),o.cell)).filter(o=>o!==!1)}))}function le(e,n,t=re(n)){for(let o=0;o<t.length;o++)for(let r=0;r<t[o].length;r++){const s=t[o][r];if(s.row===e.row&&s.col===e.col)return{row:o,col:r,cell:s.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`)}function Lt(e){const n=e.content.rows.length;let t=0;return e.content.rows.forEach(o=>{let r=0;o.cells.forEach(s=>{r+=me(s)}),t=Math.max(t,r)}),{height:n,width:t}}function Mn(e,n,t=re(n)){var r;const o=(r=t[e.row])==null?void 0:r[e.col];if(o)return{row:o.row,col:o.col,cell:o.cell}}function ut(e,n){var s;const t=re(e);if(n<0||n>=t.length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[o])==null?void 0:s[0];if(!a)return[];o+=a.rowspan}const r=new Array(t[0].length).fill(!1).map((i,a)=>Mn({row:o,col:a},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function pt(e,n){var s;const t=re(e);if(n<0||n>=t[0].length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[0])==null?void 0:s[o];if(!a)return[];o+=a.colspan}const r=new Array(t.length).fill(!1).map((i,a)=>Mn({row:a,col:o},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function ts(e,n,t,o=re(e)){const{col:r}=le({row:0,col:n},e,o),{col:s}=le({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),Se(o)}function ns(e,n,t,o=re(e)){const{row:r}=le({row:n,col:0},e,o),{row:s}=le({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),Se(o)}function ht(e){return e?fe(e)?ht(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:oe(n)?n.text.length===0:St(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function os(e,n,t=re(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>ht(l[i].cell)&&l[i].colspan===1);i--)s++;for(let i=t.length-1;i>=0;i--){const a=Math.max(t[i].length-s,1);t[i]=t[i].slice(0,a)}return Se(t)}let o=0;for(let s=t.length-1;s>=0&&t[s].every(a=>ht(a.cell)&&a.rowspan===1);s--)o++;const r=Math.min(o,t.length-1);return t.splice(t.length-r,r),Se(t)}function rs(e,n,t,o=re(e)){const{width:r,height:s}=Lt(e);if(n==="columns")o.forEach((i,a)=>{if(t>=0)for(let l=0;l<t;l++)i.push({row:a,col:Math.max(...i.map(c=>c.col))+1,rowspan:1,colspan:1,cell:Ue("")});else i.splice(r+t,-1*t)});else if(t>0)for(let i=0;i<t;i++){const a=new Array(r).fill(null).map((l,c)=>({row:s+i,col:c,rowspan:1,colspan:1,cell:Ue("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return Se(o)}function In(e,n,t){const o=ut(e,t);if(!o.some(l=>Fe(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=Fe(l.cell);s=Math.max(s,l.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function Ln(e,n,t){const o=pt(e,t);if(!o.some(l=>me(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=me(l.cell);s=Math.max(s,l.col+c-1),i=Math.min(i,l.col)}),n<t?t===s:t===i}function ss(e,n,t){const o=le(e,t),r=le(n,t);return o.col===r.col}function Gt(e,n,t,o){const r=[];for(const[i,a]of Object.entries(e.styles||{})){const l=t[i];if(!l)throw new Error(`style ${i} not found in styleSchema`);if(l.propSchema==="boolean")a&&r.push(n.mark(i));else if(l.propSchema==="string")a&&r.push(n.mark(i,{stringValue:a}));else throw new j(l.propSchema)}return!o||!n.nodes[o].spec.code?e.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
6
- `?n.nodes.hardBreak.createChecked():n.text(i,r)):e.text.length>0?[n.text(e.text,r)]:[]}function is(e,n,t){const o=n.marks.link.create({href:e.href});return ft(e.content,n,t).map(r=>{if(r.type.name==="text")return r.mark([...r.marks,o]);if(r.type.name==="hardBreak")return r;throw new Error("unexpected node type")})}function ft(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Gt({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Gt(s,n,t,o));return r}function W(e,n,t,o=ce(n)){const r=[];for(const s of e)typeof s=="string"?r.push(...ft(s,n,o,t)):St(s)?r.push(...is(s,n,o)):oe(s)?r.push(...ft([s],n,o,t)):r.push(An(s,n,o));return r}function Pe(e,n,t=ce(n)){const o=[],r=new Array(e.headerRows??0).fill(!0),s=new Array(e.headerCols??0).fill(!0),i=e.columnWidths??[];for(let a=0;a<e.rows.length;a++){const l=e.rows[a],c=[],d=r[a];for(let h=0;h<l.cells.length;h++){const f=l.cells[h],m=s[h],g=void 0;let b=null;const k=le({row:a,col:h},{content:e});let w=i[k.col]?[i[k.col]]:null;if(f)if(typeof f=="string")b=n.text(f);else if(fe(f)){f.content&&(b=W(f.content,n,"tableParagraph",t));const E=me(f);E>1&&(w=new Array(E).fill(!1).map((_,q)=>i[k.col+q]??void 0))}else b=W(f,n,"tableParagraph",t);const v=n.nodes[m||d?"tableHeader":"tableCell"].createChecked({...fe(f)?f.props:{},colwidth:w},n.nodes.tableParagraph.createChecked(g,b));c.push(v)}const u=n.nodes.tableRow.createChecked({},c);o.push(u)}return o}function An(e,n,t){let o,r=e.type;if(r===void 0&&(r="paragraph"),!n.nodes[r])throw new Error(`node type ${r} not found in schema`);if(!e.content)o=n.nodes[r].createChecked(e.props);else if(typeof e.content=="string"){const s=W([e.content],n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=W(e.content,n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=Pe(e.content,n,t);o=n.nodes[r].createChecked(e.props,s)}else throw new j(e.content.type);return o}function se(e,n,t=ce(n)){let o=e.id;o===void 0&&(o=Be.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(se(i,n,t));if(!e.type||n.nodes[e.type].isInGroup("blockContent")){const i=An(e,n,t),a=r.length>0?n.nodes.blockGroup.createChecked({},r):void 0;return n.nodes.blockContainer.createChecked({id:o,...e.props},a?[i,a]:i)}else{if(n.nodes[e.type].isInGroup("bnBlock"))return n.nodes[e.type].createChecked({id:o,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}}function as(e,n){if(n===0)return;const t=e.resolve(n);for(let o=t.depth;o>0;o--){const r=t.node(o);if(Ze(r))return r.attrs.id}}function z(e,n){let t,o;if(n.firstChild.descendants((r,s)=>t?!1:!Ze(r)||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}function Ze(e){return e.type.isInGroup("bnBlock")}function ls(e,n){return e.id!==n.id||e.type!==n.type||JSON.stringify(e.props)!==JSON.stringify(n.props)||JSON.stringify(e.content)!==JSON.stringify(n.content)}function cs(e){return e.getMeta("paste")?{type:"paste"}:e.getMeta("uiEvent")==="drop"?{type:"drop"}:e.getMeta("history$")?{type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")?e.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}function Yt(e){const n={},t=R(e);return e.descendants((o,r)=>{if(Ze(o)){const s=as(e,r);n[o.attrs.id]={block:T(o,t),parentId:s}}return!0}),n}function At(e,n=[]){const t=cs(e),o=y.combineTransactionSteps(e.before,[e,...n]),r=Yt(o.before),s=Yt(o.doc),i=[];return Object.keys(s).filter(a=>!(a in r)).forEach(a=>{i.push({type:"insert",block:s[a].block,source:t,prevBlock:void 0})}),Object.keys(r).filter(a=>!(a in s)).forEach(a=>{i.push({type:"delete",block:r[a].block,source:t,prevBlock:void 0})}),Object.keys(s).filter(a=>a in r).forEach(a=>{var u,h;const l=r[a],c=s[a];l.parentId!==c.parentId?i.push({type:"move",block:c.block,prevBlock:l.block,source:t,prevParent:l.parentId?(u=r[l.parentId])==null?void 0:u.block:void 0,currentParent:c.parentId?(h=s[c.parentId])==null?void 0:h.block:void 0}):ls(l.block,c.block)&&i.push({type:"update",block:c.block,prevBlock:l.block,source:t})}),i}function Nn(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=R(e),i=n.map(d=>se(d,s)),a=z(r,e.doc);if(!a)throw new Error(`Block with ID ${r} not found`);let l=a.posBeforeNode;return o==="after"&&(l+=a.node.nodeSize),e.step(new he.ReplaceStep(l,l,new S.Slice(S.Fragment.from(i),0,0))),i.map(d=>T(d,s))}function mt(e,n,t){const o=R(e),r=t.map(d=>se(d,o)),s=new Set(n.map(d=>typeof d=="string"?d:d.id)),i=[],a=typeof n[0]=="string"?n[0]:n[0].id;let l=0;if(e.doc.descendants((d,u)=>{if(s.size===0)return!1;if(!d.type.isInGroup("bnBlock")||!s.has(d.attrs.id))return!0;if(i.push(T(d,o)),s.delete(d.attrs.id),t.length>0&&d.attrs.id===a){const g=e.doc.nodeSize;e.insert(u,r);const b=e.doc.nodeSize;l+=g-b}const h=e.doc.nodeSize,f=e.doc.resolve(u-l);f.node().type.name==="blockGroup"&&f.node(f.depth-1).type.name!=="doc"&&f.node().childCount===1?e.delete(f.before(),f.after()):e.delete(u-l,u-l+d.nodeSize);const m=e.doc.nodeSize;return l+=h-m,!1}),s.size>0){const d=[...s].join(`
7
- `);throw Error("Blocks with the following IDs could not be found in the editor: "+d)}return{insertedBlocks:r.map(d=>T(d,o)),removedBlocks:i}}const U=(e,n)=>({tr:t,dispatch:o})=>(o&&Nt(t,e,n),!0);function Nt(e,n,t,o,r){const s=ke(e.doc.resolve(n));let i=null;s.blockNoteType==="table"&&(i=Hn(e));const a=R(e);if(o!==void 0&&r!==void 0&&o>r)throw new Error("Invalid replaceFromPos or replaceToPos");const l=a.nodes[s.blockNoteType],c=a.nodes[t.type||s.blockNoteType],d=c.isInGroup("bnBlock")?c:a.nodes.blockContainer;if(s.isBlockContainer&&c.isInGroup("blockContent")){const u=o!==void 0&&o>s.blockContent.beforePos&&o<s.blockContent.afterPos?o-s.blockContent.beforePos-1:void 0,h=r!==void 0&&r>s.blockContent.beforePos&&r<s.blockContent.afterPos?r-s.blockContent.beforePos-1:void 0;Jt(t,e,s),ds(t,e,l,c,s,u,h)}else if(!s.isBlockContainer&&c.isInGroup("bnBlock"))Jt(t,e,s);else{const u=T(s.bnBlock.node,a);e.replaceWith(s.bnBlock.beforePos,s.bnBlock.afterPos,se({children:u.children,...t},a));return}e.setNodeMarkup(s.bnBlock.beforePos,d,{...s.bnBlock.node.attrs,...t.props}),i&&us(e,s,i)}function ds(e,n,t,o,r,s,i){const a=R(n);let l="keep";if(e.content)if(typeof e.content=="string")l=W([e.content],a,o.name);else if(Array.isArray(e.content))l=W(e.content,a,o.name);else if(e.content.type==="tableContent")l=Pe(e.content,a);else throw new j(e.content.type);else t.spec.content===""||o.spec.content!==t.spec.content&&(l=[]);if(l==="keep")n.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props});else if(s!==void 0||i!==void 0){n.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props});const c=r.blockContent.beforePos+1+(s??0),d=r.blockContent.beforePos+1+(i??r.blockContent.node.content.size),u=n.doc.resolve(r.blockContent.beforePos).depth,h=n.doc.resolve(c).depth,f=n.doc.resolve(d).depth;n.replace(c,d,new S.Slice(S.Fragment.from(l),h-u-1,f-u-1))}else n.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},l))}function Jt(e,n,t){const o=R(n);if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>se(s,o));if(t.childContainer)n.step(new he.ReplaceStep(t.childContainer.beforePos+1,t.childContainer.afterPos-1,new S.Slice(S.Fragment.from(r),0,0)));else{if(!t.isBlockContainer)throw new Error("impossible");n.insert(t.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function Dn(e,n,t,o,r){const s=typeof n=="string"?n:n.id,i=z(s,e.doc);if(!i)throw new Error(`Block with ID ${s} not found`);Nt(e,i.posBeforeNode,t,o,r);const a=e.doc.resolve(i.posBeforeNode+1).node(),l=R(e);return T(a,l)}function Hn(e){const n="selection"in e?e.selection:null;if(!(n instanceof C.TextSelection))return null;const t=e.doc.resolve(n.head);let o=-1,r=-1;for(let b=t.depth;b>=0;b--){const k=t.node(b).type.name;if(o<0&&(k==="tableCell"||k==="tableHeader")&&(o=b),k==="table"){r=b;break}}if(o<0||r<0)return null;const s=t.before(o),i=t.before(r),a=e.doc.nodeAt(i);if(!a||a.type.name!=="table")return null;const l=I.TableMap.get(a),c=s-(i+1),d=l.map.indexOf(c);if(d<0)return null;const u=Math.floor(d/l.width),h=d%l.width,m=s+1+1,g=Math.max(0,n.head-m);return{row:u,col:h,offset:g}}function us(e,n,t){var b;if(n.blockNoteType!=="table")return!1;let o=-1;if(n.isBlockContainer)o=e.mapping.map(n.blockContent.beforePos);else{const k=e.mapping.map(n.bnBlock.beforePos),w=k+(((b=e.doc.nodeAt(k))==null?void 0:b.nodeSize)||0);e.doc.nodesBetween(k,w,(v,E)=>v.type.name==="table"?(o=E,!1):!0)}const r=o>=0?e.doc.nodeAt(o):null;if(!r||r.type.name!=="table")return!1;const s=I.TableMap.get(r),i=Math.max(0,Math.min(t.row,s.height-1)),a=Math.max(0,Math.min(t.col,s.width-1)),l=i*s.width+a,c=s.map[l];if(c==null)return!1;const u=o+1+c+1,h=e.doc.nodeAt(u),f=u+1,m=h?h.content.size:0,g=f+Math.max(0,Math.min(t.offset,m));return"selection"in e&&e.setSelection(C.TextSelection.create(e.doc,g)),!0}function On(e){const n=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];n.length>0?e.className=n.join(" "):e.removeAttribute("class")}function Rn(e,n,t,o){let r;if(n)if(typeof n=="string")r=W([n],e.pmSchema);else if(Array.isArray(n))r=W(n,e.pmSchema);else if(n.type==="tableContent")r=Pe(n,e.pmSchema);else throw new j(n.type);else throw new Error("blockContent is required");const s=t.serializeFragment(S.Fragment.from(r),o);return s.nodeType===1&&On(s),s}function ps(e,n,t,o,r,s,i){var g,b,k,w,v,E,_,q;const a=(i==null?void 0:i.document)??document,l=n.pmSchema.nodes.blockContainer;let c=t.props;if(!t.props){c={};for(const[P,x]of Object.entries(n.schema.blockSchema[t.type].propSchema))x.default!==void 0&&(c[P]=x.default)}const d=(b=(g=l.spec)==null?void 0:g.toDOM)==null?void 0:b.call(g,l.create({id:t.id,...c})),u=Array.from(d.dom.attributes),h=n.blockImplementations[t.type].implementation.toExternalHTML({...t,props:c},n),f=a.createDocumentFragment();if(h.dom.classList.contains("bn-block-content")){const P=[...u,...Array.from(h.dom.attributes)].filter(x=>x.name.startsWith("data")&&x.name!=="data-content-type"&&x.name!=="data-file-block"&&x.name!=="data-node-view-wrapper"&&x.name!=="data-node-type"&&x.name!=="data-id"&&x.name!=="data-index"&&x.name!=="data-editable");for(const x of P)h.dom.firstChild.setAttribute(x.name,x.value);On(h.dom.firstChild),f.append(...Array.from(h.dom.childNodes))}else f.append(h.dom);if(h.contentDOM&&t.content){const P=Rn(n,t.content,o,i);h.contentDOM.appendChild(P)}let m;if(r.has(t.type)?m="OL":s.has(t.type)&&(m="UL"),m){if(((k=e.lastChild)==null?void 0:k.nodeName)!==m){const x=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&x.setAttribute("start",c.start+""),e.append(x)}const P=a.createElement("li");P.append(f),e.lastChild.appendChild(P)}else e.append(f);if(t.children&&t.children.length>0){const P=a.createDocumentFragment();if(_n(P,n,t.children,o,r,s,i),((w=e.lastChild)==null?void 0:w.nodeName)==="UL"||((v=e.lastChild)==null?void 0:v.nodeName)==="OL")for(;((E=P.firstChild)==null?void 0:E.nodeName)==="UL"||((_=P.firstChild)==null?void 0:_.nodeName)==="OL";)e.lastChild.lastChild.appendChild(P.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(P):(q=h.contentDOM)==null||q.append(P)}}const _n=(e,n,t,o,r,s,i)=>{for(const a of t)ps(e,n,a,o,r,s,i)},hs=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return _n(a,e,n,t,o,r,s),a},Me=(e,n)=>{const t=S.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=hs(n,o,t,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(o,r)=>{const s=Rn(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function fs(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=W([n],e.pmSchema,o);else if(Array.isArray(n))s=W(n,e.pmSchema,o);else if(n.type==="tableContent")s=Pe(n,e.pmSchema);else throw new j(n.type);else throw new Error("blockContent is required");return t.serializeFragment(S.Fragment.from(s),r)}function ms(e,n,t,o,r){var u,h,f,m,g;const s=e.pmSchema.nodes.blockContainer;let i=n.props;if(!n.props){i={};for(const[b,k]of Object.entries(e.schema.blockSchema[n.type].propSchema))k.default!==void 0&&(i[b]=k.default)}const l=e.blockImplementations[n.type].implementation.toInternalHTML({...n,props:i},e);if(n.type==="numberedListItem"&&l.dom.setAttribute("data-index",o.toString()),l.contentDOM&&n.content){const b=fs(e,n.content,t,n.type,r);l.contentDOM.appendChild(b)}if(e.pmSchema.nodes[n.type].isInGroup("bnBlock")){if(n.children&&n.children.length>0){const b=Vn(e,n.children,t,r);(u=l.contentDOM)==null||u.append(b)}return l.dom}const d=(f=(h=s.spec)==null?void 0:h.toDOM)==null?void 0:f.call(h,s.create({id:n.id,...i}));return(m=d.contentDOM)==null||m.appendChild(l.dom),n.children&&n.children.length>0&&((g=d.contentDOM)==null||g.appendChild(Un(e,n.children,t,r))),d.dom}function Vn(e,n,t,o){const s=((o==null?void 0:o.document)??document).createDocumentFragment();let i=0;for(const a of n){a.type==="numberedListItem"?i++:i=0;const l=ms(e,a,t,i,o);s.appendChild(l)}return s}const Un=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=Vn(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},Fn=(e,n)=>{const t=S.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>Un(n,o,t,r).outerHTML}},Ie=(e,n)=>{const t=e.querySelector(n);if(!t)return;const o=e.querySelector("figcaption"),r=(o==null?void 0:o.textContent)??void 0;return{targetElement:t,caption:r}},$n=(e,n,t,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const s=document.createElement("div");s.className="bn-add-file-button-icon",o?s.appendChild(o):s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(s);const i=document.createElement("p");i.className="bn-add-file-button-text",i.innerHTML=t||n.dictionary.file_blocks.file.add_button_text,r.appendChild(i);const a=c=>{c.preventDefault()},l=()=>{n.transact(c=>c.setMeta(n.filePanel.plugins[0],{block:e}))};return r.addEventListener("mousedown",a,!0),r.addEventListener("click",l,!0),{dom:r,destroy:()=>{r.removeEventListener("mousedown",a,!0),r.removeEventListener("click",l,!0)}}},zn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',Wn=e=>{const n=document.createElement("div");n.className="bn-file-name-with-icon";const t=document.createElement("div");t.className="bn-file-icon",t.innerHTML=zn,n.appendChild(t);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,n.appendChild(o),{dom:n}},Qe=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=$n(e,n,o,r);s.appendChild(a.dom);const l=n.onUploadStart(c=>{if(c===e.id){s.removeChild(a.dom);const d=document.createElement("div");d.className="bn-file-loading-preview",d.textContent="Loading...",s.appendChild(d)}});return{dom:s,destroy:()=>{l(),a.destroy()}}}const i={dom:s};if(e.props.showPreview===!1||!t){const a=Wn(e);s.appendChild(a.dom),i.destroy=()=>{var l;(l=a.destroy)==null||l.call(a)}}else s.appendChild(t.dom);if(e.props.caption){const a=document.createElement("p");a.className="bn-file-caption",a.textContent=e.props.caption,s.appendChild(a)}return i},et=(e,n)=>{const t=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Le=(e,n)=>{const t=document.createElement("div"),o=document.createElement("p");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Xt=e=>({url:e.src||void 0}),qn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>',Kn={backgroundColor:L.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},jn={type:"audio",propSchema:Kn,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Gn=(e,n)=>{const t=document.createElement("div");t.innerHTML=qn;const o=document.createElement("audio");return o.className="bn-audio",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(r=>{o.src=r}):o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,Qe(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Yn=e=>{if(e.tagName==="AUDIO")return e.closest("figure")?void 0:Xt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...Xt(t),caption:o}}},Jn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add audio",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("audio"),n.src=e.props.url):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?et(n,e.props.caption):Le(n,e.props.caption):{dom:n}},Xn=be(jn,{render:Gn,parse:Yn,toExternalHTML:Jn}),gt=Symbol.for("blocknote.shikiParser"),_e=Symbol.for("blocknote.shikiHighlighterPromise"),Zn={language:{default:"text"}},gs=G({name:"codeBlock",content:"inline*",group:"blockContent",marks:"insertion deletion modification",code:!0,defining:!0,addOptions(){return{defaultLanguage:"text",indentLineWithTab:!0,supportedLanguages:{}}},addAttributes(){const e=this.options;return{language:{default:e.editor.settings.codeBlock.defaultLanguage,parseHTML:n=>{let t=n,o=null;(t==null?void 0:t.tagName)==="DIV"&&(t==null?void 0:t.dataset.contentType)==="codeBlock"&&(t=t.children[0]),(t==null?void 0:t.tagName)==="PRE"&&(t=t==null?void 0:t.children[0]);const r=t==null?void 0:t.getAttribute("data-language");if(r)o=r.toLowerCase();else{const i=[...(t==null?void 0:t.className.split(" "))||[]].filter(a=>a.startsWith("language-")).map(a=>a.replace("language-",""));i.length>0&&(o=i[0].toLowerCase())}return o?st(e.editor.settings.codeBlock,o)??o:null},renderHTML:n=>n.language?{class:`language-${n.language}`,"data-language":n.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"pre",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){var r,s;const n=document.createElement("pre"),{dom:t,contentDOM:o}=$(this.name,"code",((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},{...((s=this.options.domAttributes)==null?void 0:s.inlineContent)||{},...e});return t.removeChild(o),t.appendChild(n),n.appendChild(o),{dom:t,contentDOM:o}},addNodeView(){const e=this.options;return({editor:n,node:t,getPos:o,HTMLAttributes:r})=>{var u,h;const s=document.createElement("pre"),i=document.createElement("select"),a=document.createElement("div"),{dom:l,contentDOM:c}=$(this.name,"code",{...((u=this.options.domAttributes)==null?void 0:u.blockContent)||{},...r},((h=this.options.domAttributes)==null?void 0:h.inlineContent)||{}),d=f=>{const m=f.target.value;n.commands.command(({tr:g})=>(g.setNodeAttribute(o(),"language",m),!0))};return Object.entries(e.editor.settings.codeBlock.supportedLanguages).forEach(([f,{name:m}])=>{const g=document.createElement("option");g.value=f,g.text=m,i.appendChild(g)}),a.contentEditable="false",i.value=t.attrs.language||e.editor.settings.codeBlock.defaultLanguage,l.removeChild(c),l.appendChild(a),l.appendChild(s),s.appendChild(c),a.appendChild(i),i.addEventListener("change",d),{dom:l,contentDOM:c,update:f=>f.type===this.type,destroy:()=>{i.removeEventListener("change",d)}}}},addProseMirrorPlugins(){const e=this.options,n=globalThis;let t,o,r=!1;const s=a=>{if(!e.editor.settings.codeBlock.createHighlighter)return process.env.NODE_ENV==="development"&&!r&&(console.log("For syntax highlighting of code blocks, you must provide a `codeBlock.createHighlighter` function"),r=!0),[];if(!t)return n[_e]=n[_e]||e.editor.settings.codeBlock.createHighlighter(),n[_e].then(c=>{t=c});const l=st(e.editor.settings.codeBlock,a.language);return!l||l==="text"||l==="none"||l==="plaintext"||l==="txt"?[]:t.getLoadedLanguages().includes(l)?(o||(o=n[gt]||xr.createParser(t),n[gt]=o),o(a)):t.loadLanguage(l)};return[Tr.createHighlightPlugin({parser:s,languageExtractor:a=>a.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new y.InputRule({find:/^```(.*?)\s$/,handler:({state:n,range:t,match:o})=>{const r=n.doc.resolve(t.from),s=o[1].trim(),i={language:st(e.editor.settings.codeBlock,s)??s};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;n.tr.delete(t.from,t.to).setBlockType(t.from,t.from,this.type,i).setSelection(C.TextSelection.create(n.tr.doc,t.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:n}=e.state,{$from:t}=n;if(e.isActive(this.name)&&!t.parent.textContent&&y.isTextSelection(n)){const o=t.pos-t.parentOffset-2;return e.chain().setNodeSelection(o).deleteSelection().run(),!0}return!1},Tab:({editor:e})=>this.options.indentLineWithTab&&e.isActive(this.name)?(e.commands.insertContent(" "),!0):!1,Enter:({editor:e})=>{const{$from:n}=e.state.selection;if(!e.isActive(this.name))return!1;const t=n.parentOffset===n.parent.nodeSize-2,o=n.parent.textContent.endsWith(`
5
+ `,styles:{}};return}if(s.type.name!=="link"&&s.type.name!=="text"){if(!n[s.type.name]){console.warn("unrecognized inline content type",s.type.name);return}r&&(o.push(r),r=void 0),o.push($e(s,n,t));return}const i={};let a;for(const l of s.marks)if(l.type.name==="link")a=l;else{const c=t[l.type.name];if(!c){if(l.type.spec.blocknoteIgnore)continue;throw new Error(`style ${l.type.name} not found in styleSchema`)}if(c.propSchema==="boolean")i[c.type]=!0;else if(c.propSchema==="string")i[c.type]=l.attrs.stringValue;else throw new K(c.propSchema)}r?oe(r)?a?(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):JSON.stringify(r.styles)===JSON.stringify(i)?r.text+=s.textContent:(o.push(r),r={type:"text",text:s.textContent,styles:i}):lt(r)&&(a?r.href===a.attrs.href?JSON.stringify(r.content[r.content.length-1].styles)===JSON.stringify(i)?r.content[r.content.length-1].text+=s.textContent:r.content.push({type:"text",text:s.textContent,styles:i}):(o.push(r),r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}):(o.push(r),r={type:"text",text:s.textContent,styles:i})):a?r={type:"link",href:a.attrs.href,content:[{type:"text",text:s.textContent,styles:i}]}:r={type:"text",text:s.textContent,styles:i}}),r&&o.push(r),o}function $e(e,n,t){if(e.type.name==="text"||e.type.name==="link")throw new Error("unexpected");const o={},r=n[e.type.name];for(const[a,l]of Object.entries(e.attrs)){if(!r)throw Error("ic node is of an unrecognized type: "+e.type.name);const c=r.propSchema;a in c&&(o[a]=l)}let s;return r.content==="styled"?s=xe(e,n,t):s=void 0,{type:e.type.name,props:o,content:s}}function x(e,n,t=Ye(n),o=Xe(n),r=ce(n),s=Je(n)){var g;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const i=s==null?void 0:s.get(e);if(i)return i;const a=Ge(e,0);let l=a.bnBlock.node.attrs.id;l===null&&(l=Be.options.generateID());const c=t[a.blockNoteType];if(!c)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const d={};for(const[b,k]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const y=c.propSchema;b in y&&!(y[b].default===void 0&&k===void 0)&&(d[b]=k)}const u=t[a.blockNoteType],p=[];(g=a.childContainer)==null||g.node.forEach(b=>{p.push(x(b,n,t,o,r,s))});let f;if(u.content==="inline"){if(!a.isBlockContainer)throw new Error("impossible");f=xe(a.blockContent.node,o,r)}else if(u.content==="table"){if(!a.isBlockContainer)throw new Error("impossible");f=xt(a.blockContent.node,o,r)}else if(u.content==="none")f=void 0;else throw new K(u.content);const m={id:l,type:u.type,props:d,content:f,children:p};return s==null||s.set(e,m),m}function wn(e,n,t=Ye(n),o=Xe(n),r=ce(n),s=Je(n)){const i=[];return e.firstChild.descendants(a=>(i.push(x(a,n,t,o,r,s)),!1)),i}function Cn(e,n,t=Ye(n),o=Xe(n),r=ce(n),s=Je(n)){function i(a,l,c){if(a.type.name!=="blockGroup")throw new Error("unexpected");const d=[];let u,p;return a.forEach((f,m,g)=>{if(f.type.name!=="blockContainer")throw new Error("unexpected");if(f.childCount===0)return;if(f.childCount===0||f.childCount>2)throw new Error("unexpected, blockContainer.childCount: "+f.childCount);const b=g===0,k=g===a.childCount-1;if(f.firstChild.type.name==="blockGroup"){if(!b)throw new Error("unexpected");const P=i(f.firstChild,Math.max(0,l-1),k?Math.max(0,c-1):0);u=P.blockCutAtStart,k&&(p=P.blockCutAtEnd),d.push(...P.blocks);return}const y=x(f,n,t,o,r,s),S=f.childCount>1?f.child(1):void 0;let v=[];if(S){const P=i(S,0,k?Math.max(0,c-1):0);v=P.blocks,k&&(p=P.blockCutAtEnd)}k&&!S&&c>1&&(p=y.id),b&&l>1&&(u=y.id),d.push({...y,children:v})}),{blocks:d,blockCutAtStart:u,blockCutAtEnd:p}}if(e.content.childCount===0)return{blocks:[],blockCutAtStart:void 0,blockCutAtEnd:void 0};if(e.content.childCount!==1)throw new Error("slice must be a single block, did you forget includeParents=true?");return i(e.content.firstChild,Math.max(e.openStart-1,0),Math.max(e.openEnd-1,0))}function dt(e,n,t,o){return e.dom.setAttribute("data-inline-content-type",n),Object.entries(t).filter(([r,s])=>{const i=o[r];return s!==i.default}).map(([r,s])=>[Se(r),s]).forEach(([r,s])=>e.dom.setAttribute(r,s)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function vn(e){return{Backspace:({editor:n})=>{const t=n.state.selection.$from;return n.state.selection.empty&&t.node().type.name===e.type&&t.parentOffset===0}}}function Sn(e,n){return{config:e,implementation:n}}function En(e,n){return Sn({type:e.name,propSchema:n,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function Pt(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Bn(e){return[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function ts(e,n){const t=w.Node.create({name:e.type,inline:!0,group:"inline",selectable:e.content==="styled",atom:e.content==="none",content:e.content==="styled"?"inline*":"",addAttributes(){return be(e.propSchema)},addKeyboardShortcuts(){return vn(e)},parseHTML(){return Bn(e)},renderHTML({node:o}){const r=this.options.editor,s=n.render($e(o,r.schema.inlineContentSchema,r.schema.styleSchema),()=>{},r);return dt(s,e.type,o.attrs,e.propSchema)},addNodeView(){return({node:o,getPos:r})=>{const s=this.options.editor,i=n.render($e(o,s.schema.inlineContentSchema,s.schema.styleSchema),a=>{if(typeof r=="boolean")return;const l=z([a],s.pmSchema);s.transact(c=>c.replaceWith(r(),r()+o.nodeSize,l))},s);return dt(i,e.type,o.attrs,e.propSchema)}}});return En(t,e.propSchema)}function Tn(e){return e==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:n=>n.getAttribute("data-value"),renderHTML:n=>n.stringValue!==void 0?{"data-value":n.stringValue}:{}}}}function xn(e,n,t,o){return e.dom.setAttribute("data-style-type",n),o==="string"&&e.dom.setAttribute("data-value",t),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function Mt(e,n){return{config:e,implementation:n}}function ne(e,n){return Mt({type:e.name,propSchema:n},{mark:e})}function It(e){return Object.fromEntries(Object.entries(e).map(([n,t])=>[n,t.config]))}function Pn(e){return[{tag:`[data-style-type="${e.type}"]`,contentElement:n=>{const t=n;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function ns(e,n){const t=w.Mark.create({name:e.type,addAttributes(){return Tn(e.propSchema)},parseHTML(){return Pn(e)},renderHTML({mark:o}){let r;if(e.propSchema==="boolean")r=n.render();else if(e.propSchema==="string")r=n.render(o.attrs.stringValue);else throw new K(e.propSchema);return xn(r,e.type,o.attrs.stringValue,e.propSchema)}});return Mt(e,{mark:t})}function re(e){const{height:n,width:t}=Lt(e),o=new Array(n).fill(!1).map(()=>new Array(t).fill(null)),r=(s,i)=>{for(let a=s;a<n;a++)for(let l=i;l<t;l++)if(!o[a][l])return{row:a,col:l};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let s=0;s<e.content.rows.length;s++)for(let i=0;i<e.content.rows[s].cells.length;i++){const a=Ue(e.content.rows[s].cells[i]),l=Fe(a),c=me(a),{row:d,col:u}=r(s,i);for(let p=d;p<d+l;p++)for(let f=u;f<u+c;f++){if(o[p][f])throw new Error(`Unable to create occupancy grid for table, cell at ${p},${f} is already occupied`);o[p][f]={row:s,col:i,rowspan:l,colspan:c,cell:a}}}return o}function Ee(e){const n=new Set;return e.map(t=>({cells:t.map(o=>n.has(o.row+":"+o.col)?!1:(n.add(o.row+":"+o.col),o.cell)).filter(o=>o!==!1)}))}function le(e,n,t=re(n)){for(let o=0;o<t.length;o++)for(let r=0;r<t[o].length;r++){const s=t[o][r];if(s.row===e.row&&s.col===e.col)return{row:o,col:r,cell:s.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`)}function Lt(e){const n=e.content.rows.length;let t=0;return e.content.rows.forEach(o=>{let r=0;o.cells.forEach(s=>{r+=me(s)}),t=Math.max(t,r)}),{height:n,width:t}}function Mn(e,n,t=re(n)){var r;const o=(r=t[e.row])==null?void 0:r[e.col];if(o)return{row:o.row,col:o.col,cell:o.cell}}function ut(e,n){var s;const t=re(e);if(n<0||n>=t.length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[o])==null?void 0:s[0];if(!a)return[];o+=a.rowspan}const r=new Array(t[0].length).fill(!1).map((i,a)=>Mn({row:o,col:a},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function pt(e,n){var s;const t=re(e);if(n<0||n>=t[0].length)return[];let o=0;for(let i=0;i<n;i++){const a=(s=t[0])==null?void 0:s[o];if(!a)return[];o+=a.colspan}const r=new Array(t.length).fill(!1).map((i,a)=>Mn({row:a,col:o},e,t)).filter(i=>i!==void 0);return r.filter((i,a)=>r.findIndex(l=>l.row===i.row&&l.col===i.col)===a)}function os(e,n,t,o=re(e)){const{col:r}=le({row:0,col:n},e,o),{col:s}=le({row:0,col:t},e,o);return o.forEach(i=>{const[a]=i.splice(r,1);i.splice(s,0,a)}),Ee(o)}function rs(e,n,t,o=re(e)){const{row:r}=le({row:n,col:0},e,o),{row:s}=le({row:t,col:0},e,o),[i]=o.splice(r,1);return o.splice(s,0,i),Ee(o)}function ht(e){return e?fe(e)?ht(e.content):typeof e=="string"?e.length===0:Array.isArray(e)?e.every(n=>typeof n=="string"?n.length===0:oe(n)?n.text.length===0:St(n)?typeof n.content=="string"?n.content.length===0:n.content.every(t=>t.text.length===0):!1):!1:!0}function ss(e,n,t=re(e)){if(n==="columns"){let s=0;for(let i=t[0].length-1;i>=0&&t.every(l=>ht(l[i].cell)&&l[i].colspan===1);i--)s++;for(let i=t.length-1;i>=0;i--){const a=Math.max(t[i].length-s,1);t[i]=t[i].slice(0,a)}return Ee(t)}let o=0;for(let s=t.length-1;s>=0&&t[s].every(a=>ht(a.cell)&&a.rowspan===1);s--)o++;const r=Math.min(o,t.length-1);return t.splice(t.length-r,r),Ee(t)}function is(e,n,t,o=re(e)){const{width:r,height:s}=Lt(e);if(n==="columns")o.forEach((i,a)=>{if(t>=0)for(let l=0;l<t;l++)i.push({row:a,col:Math.max(...i.map(c=>c.col))+1,rowspan:1,colspan:1,cell:Ue("")});else i.splice(r+t,-1*t)});else if(t>0)for(let i=0;i<t;i++){const a=new Array(r).fill(null).map((l,c)=>({row:s+i,col:c,rowspan:1,colspan:1,cell:Ue("")}));o.push(a)}else t<0&&o.splice(s+t,-1*t);return Ee(o)}function In(e,n,t){const o=ut(e,t);if(!o.some(l=>Fe(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=Fe(l.cell);s=Math.max(s,l.row+c-1),i=Math.min(i,l.row)}),n<t?t===s:t===i}function Ln(e,n,t){const o=pt(e,t);if(!o.some(l=>me(l.cell)>1))return!0;let s=t,i=t;return o.forEach(l=>{const c=me(l.cell);s=Math.max(s,l.col+c-1),i=Math.min(i,l.col)}),n<t?t===s:t===i}function as(e,n,t){const o=le(e,t),r=le(n,t);return o.col===r.col}function Gt(e,n,t,o){const r=[];for(const[i,a]of Object.entries(e.styles||{})){const l=t[i];if(!l)throw new Error(`style ${i} not found in styleSchema`);if(l.propSchema==="boolean")a&&r.push(n.mark(i));else if(l.propSchema==="string")a&&r.push(n.mark(i,{stringValue:a}));else throw new K(l.propSchema)}return!o||!n.nodes[o].spec.code?e.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
6
+ `?n.nodes.hardBreak.createChecked():n.text(i,r)):e.text.length>0?[n.text(e.text,r)]:[]}function ls(e,n,t){const o=n.marks.link.create({href:e.href});return ft(e.content,n,t).map(r=>{if(r.type.name==="text")return r.mark([...r.marks,o]);if(r.type.name==="hardBreak")return r;throw new Error("unexpected node type")})}function ft(e,n,t,o){const r=[];if(typeof e=="string")return r.push(...Gt({text:e,styles:{}},n,t,o)),r;for(const s of e)r.push(...Gt(s,n,t,o));return r}function z(e,n,t,o=ce(n)){const r=[];for(const s of e)typeof s=="string"?r.push(...ft(s,n,o,t)):St(s)?r.push(...ls(s,n,o)):oe(s)?r.push(...ft([s],n,o,t)):r.push(An(s,n,o));return r}function Pe(e,n,t=ce(n)){const o=[],r=new Array(e.headerRows??0).fill(!0),s=new Array(e.headerCols??0).fill(!0),i=e.columnWidths??[];for(let a=0;a<e.rows.length;a++){const l=e.rows[a],c=[],d=r[a];for(let p=0;p<l.cells.length;p++){const f=l.cells[p],m=s[p],g=void 0;let b=null;const k=le({row:a,col:p},{content:e});let y=i[k.col]?[i[k.col]]:null;if(f)if(typeof f=="string")b=n.text(f);else if(fe(f)){f.content&&(b=z(f.content,n,"tableParagraph",t));const v=me(f);v>1&&(y=new Array(v).fill(!1).map((P,Y)=>i[k.col+Y]??void 0))}else b=z(f,n,"tableParagraph",t);const S=n.nodes[m||d?"tableHeader":"tableCell"].createChecked({...fe(f)?f.props:{},colwidth:y},n.nodes.tableParagraph.createChecked(g,b));c.push(S)}const u=n.nodes.tableRow.createChecked({},c);o.push(u)}return o}function An(e,n,t){let o,r=e.type;if(r===void 0&&(r="paragraph"),!n.nodes[r])throw new Error(`node type ${r} not found in schema`);if(!e.content)o=n.nodes[r].createChecked(e.props);else if(typeof e.content=="string"){const s=z([e.content],n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(Array.isArray(e.content)){const s=z(e.content,n,r,t);o=n.nodes[r].createChecked(e.props,s)}else if(e.content.type==="tableContent"){const s=Pe(e.content,n,t);o=n.nodes[r].createChecked(e.props,s)}else throw new K(e.content.type);return o}function se(e,n,t=ce(n)){let o=e.id;o===void 0&&(o=Be.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(se(i,n,t));if(!e.type||n.nodes[e.type].isInGroup("blockContent")){const i=An(e,n,t),a=r.length>0?n.nodes.blockGroup.createChecked({},r):void 0;return n.nodes.blockContainer.createChecked({id:o,...e.props},a?[i,a]:i)}else{if(n.nodes[e.type].isInGroup("bnBlock"))return n.nodes[e.type].createChecked({id:o,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}}function W(e,n){let t,o;if(n.firstChild.descendants((r,s)=>t?!1:!Ze(r)||r.attrs.id!==e?!0:(t=r,o=s+1,!1)),!(t===void 0||o===void 0))return{node:t,posBeforeNode:o}}function Ze(e){return e.type.isInGroup("bnBlock")}function Nn(e,n,t,o="before"){const r=typeof t=="string"?t:t.id,s=R(e),i=n.map(d=>se(d,s)),a=W(r,e.doc);if(!a)throw new Error(`Block with ID ${r} not found`);let l=a.posBeforeNode;return o==="after"&&(l+=a.node.nodeSize),e.step(new he.ReplaceStep(l,l,new E.Slice(E.Fragment.from(i),0,0))),i.map(d=>x(d,s))}function mt(e,n,t){const o=R(e),r=t.map(d=>se(d,o)),s=new Set(n.map(d=>typeof d=="string"?d:d.id)),i=[],a=typeof n[0]=="string"?n[0]:n[0].id;let l=0;if(e.doc.descendants((d,u)=>{if(s.size===0)return!1;if(!d.type.isInGroup("bnBlock")||!s.has(d.attrs.id))return!0;if(i.push(x(d,o)),s.delete(d.attrs.id),t.length>0&&d.attrs.id===a){const g=e.doc.nodeSize;e.insert(u,r);const b=e.doc.nodeSize;l+=g-b}const p=e.doc.nodeSize,f=e.doc.resolve(u-l);f.node().type.name==="blockGroup"&&f.node(f.depth-1).type.name!=="doc"&&f.node().childCount===1?e.delete(f.before(),f.after()):e.delete(u-l,u-l+d.nodeSize);const m=e.doc.nodeSize;return l+=p-m,!1}),s.size>0){const d=[...s].join(`
7
+ `);throw Error("Blocks with the following IDs could not be found in the editor: "+d)}return{insertedBlocks:r.map(d=>x(d,o)),removedBlocks:i}}const U=(e,n)=>({tr:t,dispatch:o})=>(o&&At(t,e,n),!0);function At(e,n,t,o,r){const s=ye(e.doc.resolve(n));let i=null;s.blockNoteType==="table"&&(i=Hn(e));const a=R(e);if(o!==void 0&&r!==void 0&&o>r)throw new Error("Invalid replaceFromPos or replaceToPos");const l=a.nodes[s.blockNoteType],c=a.nodes[t.type||s.blockNoteType],d=c.isInGroup("bnBlock")?c:a.nodes.blockContainer;if(s.isBlockContainer&&c.isInGroup("blockContent")){const u=o!==void 0&&o>s.blockContent.beforePos&&o<s.blockContent.afterPos?o-s.blockContent.beforePos-1:void 0,p=r!==void 0&&r>s.blockContent.beforePos&&r<s.blockContent.afterPos?r-s.blockContent.beforePos-1:void 0;Yt(t,e,s),cs(t,e,l,c,s,u,p)}else if(!s.isBlockContainer&&c.isInGroup("bnBlock"))Yt(t,e,s);else{const u=x(s.bnBlock.node,a);e.replaceWith(s.bnBlock.beforePos,s.bnBlock.afterPos,se({children:u.children,...t},a));return}e.setNodeMarkup(s.bnBlock.beforePos,d,{...s.bnBlock.node.attrs,...t.props}),i&&ds(e,s,i)}function cs(e,n,t,o,r,s,i){const a=R(n);let l="keep";if(e.content)if(typeof e.content=="string")l=z([e.content],a,o.name);else if(Array.isArray(e.content))l=z(e.content,a,o.name);else if(e.content.type==="tableContent")l=Pe(e.content,a);else throw new K(e.content.type);else t.spec.content===""||o.spec.content!==t.spec.content&&(l=[]);if(l==="keep")n.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props});else if(s!==void 0||i!==void 0){n.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props});const c=r.blockContent.beforePos+1+(s??0),d=r.blockContent.beforePos+1+(i??r.blockContent.node.content.size),u=n.doc.resolve(r.blockContent.beforePos).depth,p=n.doc.resolve(c).depth,f=n.doc.resolve(d).depth;n.replace(c,d,new E.Slice(E.Fragment.from(l),p-u-1,f-u-1))}else n.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},l))}function Yt(e,n,t){const o=R(n);if(e.children!==void 0&&e.children.length>0){const r=e.children.map(s=>se(s,o));if(t.childContainer)n.step(new he.ReplaceStep(t.childContainer.beforePos+1,t.childContainer.afterPos-1,new E.Slice(E.Fragment.from(r),0,0)));else{if(!t.isBlockContainer)throw new Error("impossible");n.insert(t.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function Dn(e,n,t,o,r){const s=typeof n=="string"?n:n.id,i=W(s,e.doc);if(!i)throw new Error(`Block with ID ${s} not found`);At(e,i.posBeforeNode,t,o,r);const a=e.doc.resolve(i.posBeforeNode+1).node(),l=R(e);return x(a,l)}function Hn(e){const n="selection"in e?e.selection:null;if(!(n instanceof C.TextSelection))return null;const t=e.doc.resolve(n.head);let o=-1,r=-1;for(let b=t.depth;b>=0;b--){const k=t.node(b).type.name;if(o<0&&(k==="tableCell"||k==="tableHeader")&&(o=b),k==="table"){r=b;break}}if(o<0||r<0)return null;const s=t.before(o),i=t.before(r),a=e.doc.nodeAt(i);if(!a||a.type.name!=="table")return null;const l=L.TableMap.get(a),c=s-(i+1),d=l.map.indexOf(c);if(d<0)return null;const u=Math.floor(d/l.width),p=d%l.width,m=s+1+1,g=Math.max(0,n.head-m);return{row:u,col:p,offset:g}}function ds(e,n,t){var b;if(n.blockNoteType!=="table")return!1;let o=-1;if(n.isBlockContainer)o=e.mapping.map(n.blockContent.beforePos);else{const k=e.mapping.map(n.bnBlock.beforePos),y=k+(((b=e.doc.nodeAt(k))==null?void 0:b.nodeSize)||0);e.doc.nodesBetween(k,y,(S,v)=>S.type.name==="table"?(o=v,!1):!0)}const r=o>=0?e.doc.nodeAt(o):null;if(!r||r.type.name!=="table")return!1;const s=L.TableMap.get(r),i=Math.max(0,Math.min(t.row,s.height-1)),a=Math.max(0,Math.min(t.col,s.width-1)),l=i*s.width+a,c=s.map[l];if(c==null)return!1;const u=o+1+c+1,p=e.doc.nodeAt(u),f=u+1,m=p?p.content.size:0,g=f+Math.max(0,Math.min(t.offset,m));return"selection"in e&&e.setSelection(C.TextSelection.create(e.doc,g)),!0}function On(e){const n=Array.from(e.classList).filter(t=>!t.startsWith("bn-"))||[];n.length>0?e.className=n.join(" "):e.removeAttribute("class")}function _n(e,n,t,o){let r;if(n)if(typeof n=="string")r=z([n],e.pmSchema);else if(Array.isArray(n))r=z(n,e.pmSchema);else if(n.type==="tableContent")r=Pe(n,e.pmSchema);else throw new K(n.type);else throw new Error("blockContent is required");const s=t.serializeFragment(E.Fragment.from(r),o);return s.nodeType===1&&On(s),s}function us(e,n,t,o,r,s,i){var g,b,k,y,S,v,P,Y;const a=(i==null?void 0:i.document)??document,l=n.pmSchema.nodes.blockContainer;let c=t.props;if(!t.props){c={};for(const[M,B]of Object.entries(n.schema.blockSchema[t.type].propSchema))B.default!==void 0&&(c[M]=B.default)}const d=(b=(g=l.spec)==null?void 0:g.toDOM)==null?void 0:b.call(g,l.create({id:t.id,...c})),u=Array.from(d.dom.attributes),p=n.blockImplementations[t.type].implementation.toExternalHTML({...t,props:c},n),f=a.createDocumentFragment();if(p.dom.classList.contains("bn-block-content")){const M=[...u,...Array.from(p.dom.attributes)].filter(B=>B.name.startsWith("data")&&B.name!=="data-content-type"&&B.name!=="data-file-block"&&B.name!=="data-node-view-wrapper"&&B.name!=="data-node-type"&&B.name!=="data-id"&&B.name!=="data-index"&&B.name!=="data-editable");for(const B of M)p.dom.firstChild.setAttribute(B.name,B.value);On(p.dom.firstChild),f.append(...Array.from(p.dom.childNodes))}else f.append(p.dom);if(p.contentDOM&&t.content){const M=_n(n,t.content,o,i);p.contentDOM.appendChild(M)}let m;if(r.has(t.type)?m="OL":s.has(t.type)&&(m="UL"),m){if(((k=e.lastChild)==null?void 0:k.nodeName)!==m){const B=a.createElement(m);m==="OL"&&(c!=null&&c.start)&&(c==null?void 0:c.start)!==1&&B.setAttribute("start",c.start+""),e.append(B)}const M=a.createElement("li");M.append(f),e.lastChild.appendChild(M)}else e.append(f);if(t.children&&t.children.length>0){const M=a.createDocumentFragment();if(Rn(M,n,t.children,o,r,s,i),((y=e.lastChild)==null?void 0:y.nodeName)==="UL"||((S=e.lastChild)==null?void 0:S.nodeName)==="OL")for(;((v=M.firstChild)==null?void 0:v.nodeName)==="UL"||((P=M.firstChild)==null?void 0:P.nodeName)==="OL";)e.lastChild.lastChild.appendChild(M.firstChild);n.pmSchema.nodes[t.type].isInGroup("blockContent")?e.append(M):(Y=p.contentDOM)==null||Y.append(M)}}const Rn=(e,n,t,o,r,s,i)=>{for(const a of t)us(e,n,a,o,r,s,i)},ps=(e,n,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return Rn(a,e,n,t,o,r,s),a},Me=(e,n)=>{const t=E.DOMSerializer.fromSchema(e);return{exportBlocks:(o,r)=>{const s=ps(n,o,t,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(o,r)=>{const s=_n(n,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function hs(e,n,t,o,r){let s;if(n)if(typeof n=="string")s=z([n],e.pmSchema,o);else if(Array.isArray(n))s=z(n,e.pmSchema,o);else if(n.type==="tableContent")s=Pe(n,e.pmSchema);else throw new K(n.type);else throw new Error("blockContent is required");return t.serializeFragment(E.Fragment.from(s),r)}function fs(e,n,t,o,r){var u,p,f,m,g;const s=e.pmSchema.nodes.blockContainer;let i=n.props;if(!n.props){i={};for(const[b,k]of Object.entries(e.schema.blockSchema[n.type].propSchema))k.default!==void 0&&(i[b]=k.default)}const l=e.blockImplementations[n.type].implementation.toInternalHTML({...n,props:i},e);if(n.type==="numberedListItem"&&l.dom.setAttribute("data-index",o.toString()),l.contentDOM&&n.content){const b=hs(e,n.content,t,n.type,r);l.contentDOM.appendChild(b)}if(e.pmSchema.nodes[n.type].isInGroup("bnBlock")){if(n.children&&n.children.length>0){const b=Vn(e,n.children,t,r);(u=l.contentDOM)==null||u.append(b)}return l.dom}const d=(f=(p=s.spec)==null?void 0:p.toDOM)==null?void 0:f.call(p,s.create({id:n.id,...i}));return(m=d.contentDOM)==null||m.appendChild(l.dom),n.children&&n.children.length>0&&((g=d.contentDOM)==null||g.appendChild(Un(e,n.children,t,r))),d.dom}function Vn(e,n,t,o){const s=((o==null?void 0:o.document)??document).createDocumentFragment();let i=0;for(const a of n){a.type==="numberedListItem"?i++:i=0;const l=fs(e,a,t,i,o);s.appendChild(l)}return s}const Un=(e,n,t,o)=>{var a;const r=e.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=Vn(e,n,t,o);return(a=s.contentDOM)==null||a.appendChild(i),s.dom},Fn=(e,n)=>{const t=E.DOMSerializer.fromSchema(e);return{serializeBlocks:(o,r)=>Un(n,o,t,r).outerHTML}};function ms(e,n){if(n===0)return;const t=e.resolve(n);for(let o=t.depth;o>0;o--){const r=t.node(o);if(Ze(r))return r.attrs.id}}function gs(e){return e.getMeta("paste")?{type:"paste"}:e.getMeta("uiEvent")==="drop"?{type:"drop"}:e.getMeta("history$")?{type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")?e.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}function Xt(e){const n="__root__",t={},o={},r=R(e);return e.descendants((s,i)=>{if(!Ze(s))return!0;const a=ms(e,i),l=a??n;o[l]||(o[l]=[]);const c=x(s,r);return t[s.attrs.id]={block:c,parentId:a},o[l].push(s.attrs.id),!0}),{byId:t,childrenByParent:o}}function bs(e,n){const t=new Set;if(!e||!n)return t;const o=new Set(e),r=n.filter(g=>o.has(g)),s=e.filter(g=>r.includes(g));if(s.length<=1||r.length<=1)return t;const i={};for(let g=0;g<s.length;g++)i[s[g]]=g;const a=r.map(g=>i[g]),l=a.length,c=[],d=[],u=new Array(l).fill(-1),p=(g,b)=>{let k=0,y=g.length;for(;k<y;){const S=k+y>>>1;g[S]<b?k=S+1:y=S}return k};for(let g=0;g<l;g++){const b=a[g],k=p(c,b);k>0&&(u[g]=d[k-1]),k===c.length?(c.push(b),d.push(g)):(c[k]=b,d[k]=g)}const f=new Set;let m=d[d.length-1]??-1;for(;m!==-1;)f.add(m),m=u[m];for(let g=0;g<r.length;g++)f.has(g)||t.add(r[g]);return t}function Nt(e,n=[]){const t=gs(e),o=w.combineTransactionSteps(e.before,[e,...n]),r=Xt(o.before),s=Xt(o.doc),i=[],a=new Set;Object.keys(s.byId).filter(f=>!(f in r.byId)).forEach(f=>{i.push({type:"insert",block:s.byId[f].block,source:t,prevBlock:void 0}),a.add(f)}),Object.keys(r.byId).filter(f=>!(f in s.byId)).forEach(f=>{i.push({type:"delete",block:r.byId[f].block,source:t,prevBlock:void 0}),a.add(f)}),Object.keys(s.byId).filter(f=>f in r.byId).forEach(f=>{var k,y;const m=r.byId[f],g=s.byId[f];m.parentId!==g.parentId?(i.push({type:"move",block:g.block,prevBlock:m.block,source:t,prevParent:m.parentId?(k=r.byId[m.parentId])==null?void 0:k.block:void 0,currentParent:g.parentId?(y=s.byId[g.parentId])==null?void 0:y.block:void 0}),a.add(f)):zr.default({...m.block,children:void 0},{...g.block,children:void 0})||(i.push({type:"update",block:g.block,prevBlock:m.block,source:t}),a.add(f))});const l=r.childrenByParent,c=s.childrenByParent,d="__root__",u=new Set([...Object.keys(l),...Object.keys(c)]),p=new Set;return u.forEach(f=>{const m=bs(l[f],c[f]);m.size!==0&&m.forEach(g=>{var S,v;const b=r.byId[g],k=s.byId[g];!b||!k||b.parentId!==k.parentId||a.has(g)||(b.parentId??d)!==f||p.has(g)||(p.add(g),i.push({type:"move",block:k.block,prevBlock:b.block,source:t,prevParent:b.parentId?(S=r.byId[b.parentId])==null?void 0:S.block:void 0,currentParent:k.parentId?(v=s.byId[k.parentId])==null?void 0:v.block:void 0}),a.add(g))})}),i}const Ie=(e,n)=>{const t=e.querySelector(n);if(!t)return;const o=e.querySelector("figcaption"),r=(o==null?void 0:o.textContent)??void 0;return{targetElement:t,caption:r}},$n=(e,n,t,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const s=document.createElement("div");s.className="bn-add-file-button-icon",o?s.appendChild(o):s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(s);const i=document.createElement("p");i.className="bn-add-file-button-text",i.innerHTML=t||n.dictionary.file_blocks.file.add_button_text,r.appendChild(i);const a=c=>{c.preventDefault()},l=()=>{n.transact(c=>c.setMeta(n.filePanel.plugins[0],{block:e}))};return r.addEventListener("mousedown",a,!0),r.addEventListener("click",l,!0),{dom:r,destroy:()=>{r.removeEventListener("mousedown",a,!0),r.removeEventListener("click",l,!0)}}},Wn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',zn=e=>{const n=document.createElement("div");n.className="bn-file-name-with-icon";const t=document.createElement("div");t.className="bn-file-icon",t.innerHTML=Wn,n.appendChild(t);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,n.appendChild(o),{dom:n}},Qe=(e,n,t,o,r)=>{const s=document.createElement("div");if(s.className="bn-file-block-content-wrapper",e.props.url===""){const a=$n(e,n,o,r);s.appendChild(a.dom);const l=n.onUploadStart(c=>{if(c===e.id){s.removeChild(a.dom);const d=document.createElement("div");d.className="bn-file-loading-preview",d.textContent="Loading...",s.appendChild(d)}});return{dom:s,destroy:()=>{l(),a.destroy()}}}const i={dom:s};if(e.props.showPreview===!1||!t){const a=zn(e);s.appendChild(a.dom),i.destroy=()=>{var l;(l=a.destroy)==null||l.call(a)}}else s.appendChild(t.dom);if(e.props.caption){const a=document.createElement("p");a.className="bn-file-caption",a.textContent=e.props.caption,s.appendChild(a)}return i},et=(e,n)=>{const t=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Le=(e,n)=>{const t=document.createElement("div"),o=document.createElement("p");return o.textContent=n,t.appendChild(e),t.appendChild(o),{dom:t}},Jt=e=>({url:e.src||void 0}),qn='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>',Kn={backgroundColor:A.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},jn={type:"audio",propSchema:Kn,content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Gn=(e,n)=>{const t=document.createElement("div");t.innerHTML=qn;const o=document.createElement("audio");return o.className="bn-audio",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(r=>{o.src=r}):o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,Qe(e,n,{dom:o},n.dictionary.file_blocks.audio.add_button_text,t.firstElementChild)},Yn=e=>{if(e.tagName==="AUDIO")return e.closest("figure")?void 0:Jt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"audio");if(!n)return;const{targetElement:t,caption:o}=n;return{...Jt(t),caption:o}}},Xn=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add audio",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("audio"),n.src=e.props.url):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?et(n,e.props.caption):Le(n,e.props.caption):{dom:n}},Jn=ke(jn,{render:Gn,parse:Yn,toExternalHTML:Xn}),gt=Symbol.for("blocknote.shikiParser"),Re=Symbol.for("blocknote.shikiHighlighterPromise"),Zn={language:{default:"text"}},ks=j({name:"codeBlock",content:"inline*",group:"blockContent",marks:"insertion deletion modification",code:!0,defining:!0,addOptions(){return{defaultLanguage:"text",indentLineWithTab:!0,supportedLanguages:{}}},addAttributes(){const e=this.options;return{language:{default:e.editor.settings.codeBlock.defaultLanguage,parseHTML:n=>{let t=n,o=null;(t==null?void 0:t.tagName)==="DIV"&&(t==null?void 0:t.dataset.contentType)==="codeBlock"&&(t=t.children[0]),(t==null?void 0:t.tagName)==="PRE"&&(t=t==null?void 0:t.children[0]);const r=t==null?void 0:t.getAttribute("data-language");if(r)o=r.toLowerCase();else{const i=[...(t==null?void 0:t.className.split(" "))||[]].filter(a=>a.startsWith("language-")).map(a=>a.replace("language-",""));i.length>0&&(o=i[0].toLowerCase())}return o?st(e.editor.settings.codeBlock,o)??o:null},renderHTML:n=>n.language?{class:`language-${n.language}`,"data-language":n.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"pre",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){var r,s;const n=document.createElement("pre"),{dom:t,contentDOM:o}=$(this.name,"code",((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},{...((s=this.options.domAttributes)==null?void 0:s.inlineContent)||{},...e});return t.removeChild(o),t.appendChild(n),n.appendChild(o),{dom:t,contentDOM:o}},addNodeView(){const e=this.options;return({editor:n,node:t,getPos:o,HTMLAttributes:r})=>{var u,p;const s=document.createElement("pre"),i=document.createElement("select"),a=document.createElement("div"),{dom:l,contentDOM:c}=$(this.name,"code",{...((u=this.options.domAttributes)==null?void 0:u.blockContent)||{},...r},((p=this.options.domAttributes)==null?void 0:p.inlineContent)||{}),d=f=>{const m=f.target.value;n.commands.command(({tr:g})=>(g.setNodeAttribute(o(),"language",m),!0))};return Object.entries(e.editor.settings.codeBlock.supportedLanguages).forEach(([f,{name:m}])=>{const g=document.createElement("option");g.value=f,g.text=m,i.appendChild(g)}),a.contentEditable="false",i.value=t.attrs.language||e.editor.settings.codeBlock.defaultLanguage,l.removeChild(c),l.appendChild(a),l.appendChild(s),s.appendChild(c),a.appendChild(i),i.addEventListener("change",d),{dom:l,contentDOM:c,update:f=>f.type===this.type,destroy:()=>{i.removeEventListener("change",d)}}}},addProseMirrorPlugins(){const e=this.options,n=globalThis;let t,o,r=!1;const s=a=>{if(!e.editor.settings.codeBlock.createHighlighter)return process.env.NODE_ENV==="development"&&!r&&(console.log("For syntax highlighting of code blocks, you must provide a `codeBlock.createHighlighter` function"),r=!0),[];if(!t)return n[Re]=n[Re]||e.editor.settings.codeBlock.createHighlighter(),n[Re].then(c=>{t=c});const l=st(e.editor.settings.codeBlock,a.language);return!l||l==="text"||l==="none"||l==="plaintext"||l==="txt"?[]:t.getLoadedLanguages().includes(l)?(o||(o=n[gt]||Pr.createParser(t),n[gt]=o),o(a)):t.loadLanguage(l)};return[xr.createHighlightPlugin({parser:s,languageExtractor:a=>a.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new w.InputRule({find:/^```(.*?)\s$/,handler:({state:n,range:t,match:o})=>{const r=n.doc.resolve(t.from),s=o[1].trim(),i={language:st(e.editor.settings.codeBlock,s)??s};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;n.tr.delete(t.from,t.to).setBlockType(t.from,t.from,this.type,i).setSelection(C.TextSelection.create(n.tr.doc,t.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:n}=e.state,{$from:t}=n;if(e.isActive(this.name)&&!t.parent.textContent&&w.isTextSelection(n)){const o=t.pos-t.parentOffset-2;return e.chain().setNodeSelection(o).deleteSelection().run(),!0}return!1},Tab:({editor:e})=>this.options.indentLineWithTab&&e.isActive(this.name)?(e.commands.insertContent(" "),!0):!1,Enter:({editor:e})=>{const{$from:n}=e.state.selection;if(!e.isActive(this.name))return!1;const t=n.parentOffset===n.parent.nodeSize-2,o=n.parent.textContent.endsWith(`
8
8
 
9
9
  `);return!t||!o?(e.commands.insertContent(`
10
- `),!0):e.chain().command(({tr:r})=>(r.delete(n.pos-2,n.pos),!0)).exitCode().run()},"Shift-Enter":({editor:e})=>{const{$from:n}=e.state.selection;return e.isActive(this.name)?(e.chain().insertContentAt(n.pos-n.parentOffset+n.parent.nodeSize,{type:"paragraph"}).run(),!0):!1}}}}),Qn=Z(gs,Zn);function st(e,n){var t;return(t=Object.entries(e.supportedLanguages).find(([o,{aliases:r}])=>(r==null?void 0:r.includes(n))||o===n))==null?void 0:t[0]}const bs=y.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-background-color")?{stringValue:e.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),ks=ne(bs,"string"),ys=y.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-text-color")?{stringValue:e.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),ws=ne(ys,"string"),bt=e=>({url:e.src||void 0}),eo={backgroundColor:L.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},to={type:"file",propSchema:eo,content:"none",isFileBlock:!0},no=(e,n)=>Qe(e,n),oo=e=>{if(e.tagName==="EMBED")return e.closest("figure")?void 0:bt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...bt(t),caption:o}}},ro=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add file",{dom:t}}const n=document.createElement("a");return n.href=e.props.url,n.textContent=e.props.name||e.props.url,e.props.caption?Le(n,e.props.caption):{dom:n}},so=be(to,{render:no,parse:oo,toExternalHTML:ro}),io={set:(e,n)=>window.localStorage.setItem(`toggle-${e.id}`,n?"true":"false"),get:e=>window.localStorage.getItem(`toggle-${e.id}`)==="true"},Dt=(e,n,t,o=io)=>{if("isToggleable"in e.props&&!e.props.isToggleable)return{dom:t};const r=document.createElement("div"),s=document.createElement("div");s.className="bn-toggle-wrapper";const i=document.createElement("button");i.className="bn-toggle-button",i.type="button",i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="CURRENTCOLOR"><path d="M320-200v-560l440 280-440 280Z"/></svg>';const a=m=>m.preventDefault();i.addEventListener("mousedown",a);const l=()=>{var m;s.getAttribute("data-show-children")==="true"?(s.setAttribute("data-show-children","false"),o.set(n.getBlock(e),!1),r.contains(c)&&r.removeChild(c)):(s.setAttribute("data-show-children","true"),o.set(n.getBlock(e),!0),((m=n.getBlock(e))==null?void 0:m.children.length)===0&&!r.contains(c)&&r.appendChild(c))};i.addEventListener("click",l),s.appendChild(i),s.appendChild(t);const c=document.createElement("button");c.className="bn-toggle-add-block-button",c.type="button",c.textContent=n.dictionary.toggle_blocks.add_block_button;const d=m=>m.preventDefault();c.addEventListener("mousedown",d);const u=()=>{n.transact(()=>{const m=n.updateBlock(e,{children:[{}]});n.setTextCursorPosition(m.children[0].id,"end"),n.focus()})};c.addEventListener("click",u),r.appendChild(s);let h=e.children.length;const f=n.onChange(()=>{var g;const m=((g=n.getBlock(e))==null?void 0:g.children.length)??0;m>h?(s.getAttribute("data-show-children")==="false"&&(s.setAttribute("data-show-children","true"),o.set(n.getBlock(e),!0)),r.contains(c)&&r.removeChild(c)):m===0&&m<h&&(s.getAttribute("data-show-children")==="true"&&(s.setAttribute("data-show-children","false"),o.set(n.getBlock(e),!1)),r.contains(c)&&r.removeChild(c)),h=m});return o.get(e)?(s.setAttribute("data-show-children","true"),e.children.length===0&&r.appendChild(c)):s.setAttribute("data-show-children","false"),{dom:r,ignoreMutation:m=>m instanceof MutationRecord&&(m.type==="attributes"&&m.target===s&&m.attributeName==="data-show-children"||m.type==="childList"&&(m.addedNodes[0]===c||m.removedNodes[0]===c)),destroy:()=>{i.removeEventListener("mousedown",a),i.removeEventListener("click",l),c.removeEventListener("mousedown",d),c.removeEventListener("click",u),f==null||f()}}},Cs=[1,2,3,4,5,6],ao={...L,level:{default:1,values:Cs},isToggleable:{default:!1}},vs=G({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return ge(ao)},addInputRules(){return[...this.options.editor.settings.heading.levels.map(n=>new y.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:t,chain:o,range:r})=>{const s=B(t);!s.isBlockContainer||s.blockContent.node.type.spec.content!=="inline*"||o().command(U(s.bnBlock.beforePos,{type:"heading",props:{level:n}})).deleteRange({from:r.from,to:r.to}).run()}}))]},addKeyboardShortcuts(){const e=this.options.editor;return Object.fromEntries(e.settings.heading.levels.map(n=>[`Mod-Alt-${n}`,()=>{const t=B(this.editor.state);return!t.isBlockContainer||t.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(t.bnBlock.beforePos,{type:"heading",props:{level:n}}))}]))},parseHTML(){const e=this.options.editor;return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},...e.settings.heading.levels.map(n=>({tag:`h${n}`,attrs:{level:n},node:"heading"}))]},renderHTML({node:e,HTMLAttributes:n}){var t,o;return $(this.name,`h${e.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:n,getPos:t})=>{var l,c;const{dom:o,contentDOM:r}=$(this.name,`h${e.attrs.level}`,{...((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},...n},((c=this.options.domAttributes)==null?void 0:c.inlineContent)||{});o.removeChild(r);const s=this.options.editor,i=je(t,s,this.editor,this.name),a=Dt(i,s,r);return o.appendChild(a.dom),{dom:o,contentDOM:r,ignoreMutation:a.ignoreMutation,destroy:a.destroy}}}}),Ss=Z(vs,ao),Ht=(e,n,t,o,r,s)=>{const{dom:i,destroy:a}=Qe(e,n,t,r,s),l=i;e.props.url&&e.props.showPreview&&(e.props.previewWidth?l.style.width=`${e.props.previewWidth}px`:l.style.width="fit-content");const c=document.createElement("div");c.className="bn-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-resize-handle",d.style.right="4px";let u,h=e.props.previewWidth;const f=v=>{var q,P;if(!u){!n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d));return}let E;e.props.textAlignment==="center"?u.handleUsed==="left"?E=u.initialWidth+(u.initialClientX-v.clientX)*2:E=u.initialWidth+(v.clientX-u.initialClientX)*2:u.handleUsed==="left"?E=u.initialWidth+u.initialClientX-v.clientX:E=u.initialWidth+v.clientX-u.initialClientX,h=Math.min(Math.max(E,64),((P=(q=n.domElement)==null?void 0:q.firstElementChild)==null?void 0:P.clientWidth)||Number.MAX_VALUE),l.style.width=`${h}px`},m=v=>{(!v.target||!l.contains(v.target)||!n.isEditable)&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)),u&&(u=void 0,n.updateBlock(e,{props:{previewWidth:h}}))},g=()=>{n.isEditable&&(o.appendChild(c),o.appendChild(d))},b=v=>{v.relatedTarget===c||v.relatedTarget===d||u||n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d))},k=v=>{v.preventDefault(),u={handleUsed:"left",initialWidth:l.clientWidth,initialClientX:v.clientX}},w=v=>{v.preventDefault(),u={handleUsed:"right",initialWidth:l.clientWidth,initialClientX:v.clientX}};return window.addEventListener("mousemove",f),window.addEventListener("mouseup",m),l.addEventListener("mouseenter",g),l.addEventListener("mouseleave",b),c.addEventListener("mousedown",k),d.addEventListener("mousedown",w),{dom:l,destroy:()=>{a==null||a(),window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",m),l.removeEventListener("mouseenter",g),l.removeEventListener("mouseleave",b),c.removeEventListener("mousedown",k),d.removeEventListener("mousedown",w)}}},Zt=e=>{const n=e.src||void 0,t=e.width||void 0,o=e.alt||void 0;return{url:n,previewWidth:t,name:o}},lo='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>',co={textAlignment:L.textAlignment,backgroundColor:L.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},uo={type:"image",propSchema:co,content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},po=(e,n)=>{const t=document.createElement("div");t.innerHTML=lo;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.alt=e.props.name||e.props.caption||"BlockNote image",r.contentEditable="false",r.draggable=!1,o.appendChild(r),Ht(e,n,{dom:o},o,n.dictionary.file_blocks.image.add_button_text,t.firstElementChild)},ho=e=>{if(e.tagName==="IMG")return e.closest("figure")?void 0:Zt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"img");if(!n)return;const{targetElement:t,caption:o}=n;return{...Zt(t),caption:o}}},fo=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add image",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("img"),n.src=e.props.url,n.alt=e.props.name||e.props.caption||"BlockNote image",e.props.previewWidth&&(n.width=e.props.previewWidth)):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?et(n,e.props.caption):Le(n,e.props.caption):{dom:n}},mo=be(uo,{render:po,parse:ho,toExternalHTML:fo}),go=(e,n,t)=>({state:o,dispatch:r})=>{const s=X(o.doc,e),i=ee(s);if(!i.isBlockContainer)throw new Error(`BlockContainer expected when calling splitBlock, position ${e}`);const a=[{type:i.bnBlock.node.type,attrs:t?{...i.bnBlock.node.attrs,id:void 0}:{}},{type:n?i.blockContent.node.type:o.schema.nodes.paragraph,attrs:t?{...i.blockContent.node.attrs}:{}}];return r&&o.tr.split(e,2,a),!0},tt=e=>{const{blockInfo:n,selectionEmpty:t}=e.transact(s=>({blockInfo:Te(s),selectionEmpty:s.selection.anchor===s.selection.head}));if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n;return!(r.node.type.name==="toggleListItem"||r.node.type.name==="bulletListItem"||r.node.type.name==="numberedListItem"||r.node.type.name==="checkListItem")||!t?!1:e._tiptapEditor.commands.first(({state:s,chain:i,commands:a})=>[()=>a.command(()=>r.node.childCount===0?a.command(U(o.beforePos,{type:"paragraph",props:{}})):!1),()=>a.command(()=>r.node.childCount>0?(i().deleteSelection().command(go(s.selection.from,!0)).run(),!0):!1)])},Es={...L},Bs=G({name:"toggleListItem",content:"inline*",group:"blockContent",priority:90,addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-6":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"toggleListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})},addNodeView(){return({HTMLAttributes:e,getPos:n})=>{var a,l;const{dom:t,contentDOM:o}=$(this.name,"p",{...((a=this.options.domAttributes)==null?void 0:a.blockContent)||{},...e},((l=this.options.domAttributes)==null?void 0:l.inlineContent)||{}),r=this.options.editor,s=je(n,r,this.editor,this.name),i=Dt(s,r,o);return t.appendChild(i.dom),{dom:t,contentDOM:o,ignoreMutation:i.ignoreMutation,destroy:i.destroy}}}}),Ts=Z(Bs,Es);function Ot(e,n,t){var u,h,f;const o=S.DOMParser.fromSchema(n),r=e,s=document.createElement("div");s.setAttribute("data-node-type","blockGroup");for(const m of Array.from(r.childNodes))s.appendChild(m.cloneNode(!0));let i=o.parse(s,{topNode:n.nodes.blockGroup.create()});((h=(u=i.firstChild)==null?void 0:u.firstChild)==null?void 0:h.type.name)==="checkListItem"&&(i=i.copy(i.content.cut(i.firstChild.firstChild.nodeSize+2)));const a=(f=i.firstChild)==null?void 0:f.firstChild;if(!(a!=null&&a.isTextblock))return S.Fragment.from(i);const l=n.nodes[t].create({},a.content),c=i.content.cut(a.nodeSize+2);if(c.size>0){const m=i.copy(c);return l.content.addToEnd(m)}return l.content}const xs={...L},Ps=G({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules(){return[new y.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||o.blockNoteType==="heading"||n().command(U(o.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-8":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"bulletListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;return n===null?!1:n.tagName==="UL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="UL"?{}:!1},getContent:(e,n)=>Ot(e,n,this.name),node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Ms=Z(Ps,xs),bo={...L,checked:{default:!1}},Is=G({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return ge(bo)},addInputRules(){return[new y.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(U(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!1}})).deleteRange({from:t.from,to:t.to})}}),new y.InputRule({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(U(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-9":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"checkListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"input",getAttrs:e=>typeof e=="string"||e.closest("[data-content-type]")||e.closest("li")?!1:e.type==="checkbox"?{checked:e.checked}:!1,node:"checkListItem"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="UL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="UL"){const o=e.querySelector("input[type=checkbox]")||null;return o===null?!1:{checked:o.checked}}return!1},getContent:(e,n)=>Ot(e,n,this.name),node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:n}){var s,i;const t=document.createElement("input");t.type="checkbox",t.checked=e.attrs.checked,e.attrs.checked&&t.setAttribute("checked","");const{dom:o,contentDOM:r}=$(this.name,"p",{...((s=this.options.domAttributes)==null?void 0:s.blockContent)||{},...n},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{});return o.insertBefore(t,r),{dom:o,contentDOM:r}},addNodeView(){return({node:e,getPos:n,editor:t,HTMLAttributes:o})=>{var d,u;const r=document.createElement("div"),s=document.createElement("div");s.contentEditable="false";const i=document.createElement("input");i.type="checkbox",i.checked=e.attrs.checked,e.attrs.checked&&i.setAttribute("checked","");const a=()=>{if(!t.isEditable){i.checked=!i.checked;return}if(typeof n!="boolean"){const h=X(t.state.doc,n());if(h.node.type.name!=="blockContainer")throw new Error(`Expected blockContainer node, got ${h.node.type.name}`);this.editor.commands.command(U(h.posBeforeNode,{type:"checkListItem",props:{checked:i.checked}}))}};i.addEventListener("change",a);const{dom:l,contentDOM:c}=$(this.name,"p",{...((d=this.options.domAttributes)==null?void 0:d.blockContent)||{},...o},((u=this.options.domAttributes)==null?void 0:u.inlineContent)||{});if(typeof n!="boolean"){const f="label-"+this.editor.state.doc.resolve(n()).node().attrs.id;i.setAttribute("aria-labelledby",f),c.id=f}return l.removeChild(c),l.appendChild(r),r.appendChild(s),r.appendChild(c),s.appendChild(i),{dom:l,contentDOM:c,destroy:()=>{i.removeEventListener("change",a)}}}}}),Ls=Z(Is,bo),As=new C.PluginKey("numbered-list-indexing"),Ns=()=>new C.Plugin({key:As,appendTransaction:(e,n,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((s,i)=>{var a;if(s.type.name==="blockContainer"&&s.firstChild.type.name==="numberedListItem"){let l=`${s.firstChild.attrs.start||1}`;const c=ee({posBeforeNode:i,node:s});if(!c.isBlockContainer)throw new Error("impossible");const d=o.doc.resolve(c.bnBlock.beforePos).nodeBefore;if(d){const m=ee({posBeforeNode:c.bnBlock.beforePos-d.nodeSize,node:d});if(m.blockNoteType==="numberedListItem"){if(!m.isBlockContainer)throw new Error("impossible");const b=m.blockContent.node.attrs.index;l=(parseInt(b)+1).toString()}}const u=c.blockContent.node,h=u.attrs.index,f=((a=d==null?void 0:d.firstChild)==null?void 0:a.type.name)!=="numberedListItem";if(h!==l||u.attrs.start&&!f){r=!0;const{start:m,...g}=u.attrs;o.setNodeMarkup(c.blockContent.beforePos,void 0,{...g,index:l,...typeof m=="number"&&f&&{start:m}})}}}),r?o:null}}),ko={...L,start:{default:void 0,type:"number"}},Ds=G({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{...ge(ko),index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}},addInputRules(){return[new y.InputRule({find:new RegExp("^(\\d+)\\.\\s$"),handler:({state:e,chain:n,range:t,match:o})=>{const r=B(e);if(!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||r.blockNoteType==="numberedListItem"||r.blockNoteType==="heading")return;const s=parseInt(o[1]);n().command(U(r.bnBlock.beforePos,{type:"numberedListItem",props:s===1&&{}||{start:s}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-7":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins(){return[Ns()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="OL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="OL"){const o=parseInt(n.getAttribute("start")||"1")||1;return e.previousSibling||o===1?{}:{start:o}}return!1},getContent:(e,n)=>Ot(e,n,this.name),priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Hs=Z(Ds,ko),Os={...L},Rs=G({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"p",getAttrs:e=>{var n;return typeof e=="string"||!((n=e.textContent)!=null&&n.trim())?!1:{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),_s=Z(Rs,Os),Vs={...L},Us=G({name:"quote",content:"inline*",group:"blockContent",addInputRules(){return[new y.InputRule({find:new RegExp("^>\\s$"),handler:({state:e,chain:n,range:t})=>{const o=B(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(U(o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=B(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"blockquote",node:"quote",getContent:(e,n)=>{const o=e.cloneNode(!0);return gn(o),S.DOMParser.fromSchema(n).parse(o,{topNode:n.nodes.paragraph.create()}).content}}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"blockquote",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Fs=Z(Us,Vs),$s=35,Rt=120,zs=31,Ws=y.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[I.columnResizing({cellMinWidth:$s,defaultCellMinWidth:Rt,View:null}),I.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.insertContent({type:"hardBreak"}),!0):!1,Backspace:()=>{const e=this.editor.state.selection,n=e.empty,t=e.$head.parentOffset===0,o=e.$head.node().type.name==="tableParagraph";return n&&t&&o},Tab:()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>I.goToNextCell(1)(e,n,t)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>I.goToNextCell(-1)(e,n,t))}},extendNodeSchema(e){const n={name:e.name,options:e.options,storage:e.storage};return{tableRole:y.callOrReturn(y.getExtensionField(e,"tableRole",n))}}}),qs={textColor:L.textColor},Ks=G({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",marks:"deletion insertion modification",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"table",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:n})=>{var o;class t extends I.TableView{constructor(s,i,a){super(s,i),this.node=s,this.cellMinWidth=i,this.blockContentHTMLAttributes=a;const l=document.createElement("div");l.className=Q("bn-block-content",a.class),l.setAttribute("data-content-type","table");for(const[h,f]of Object.entries(a))h!=="class"&&l.setAttribute(h,f);const c=this.dom,d=document.createElement("div");d.className="tableWrapper-inner",d.appendChild(c.firstChild),c.appendChild(d),l.appendChild(c);const u=document.createElement("div");u.className="table-widgets-container",u.style.position="relative",c.appendChild(u),this.dom=l}ignoreMutation(s){return!s.target.closest(".tableWrapper-inner")||super.ignoreMutation(s)}}return new t(e,Rt,{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...n})}}}),js=G({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p",getAttrs:e=>{if(typeof e=="string"||!e.textContent||!e.closest("[data-content-type]"))return!1;const n=e.parentElement;return n===null?!1:n.tagName==="TD"||n.tagName==="TH"?{}:!1},node:"tableParagraph"}]},renderHTML({HTMLAttributes:e}){return["p",e,0]}}),Gs=y.Node.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)+",tableRole:"row",marks:"deletion insertion modification",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:e}){return["tr",y.mergeAttributes(this.options.HTMLAttributes,e),0]}});function Qt(e,n){const o=S.DOMParser.fromSchema(n).parse(e,{topNode:n.nodes.blockGroup.create()}),r=[];return o.content.descendants(s=>{if(s.isInline)return r.push(s),!1}),S.Fragment.fromArray(r)}const Ys=Z(Ks,qs,[Ws,js,Dr.TableHeader.extend({content:"tableContent+",parseHTML(){return[{tag:"th",getContent:(e,n)=>Qt(e,n)}]}}),Nr.TableCell.extend({content:"tableContent+",parseHTML(){return[{tag:"td",getContent:(e,n)=>Qt(e,n)}]}}),Gs]),en=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},yo='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>',wo={textAlignment:L.textAlignment,backgroundColor:L.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},Co={type:"video",propSchema:wo,content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},vo=(e,n)=>{const t=document.createElement("div");t.innerHTML=yo;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.controls=!0,r.contentEditable="false",r.draggable=!1,r.width=e.props.previewWidth,o.appendChild(r),Ht(e,n,{dom:o},o,n.dictionary.file_blocks.video.add_button_text,t.firstElementChild)},So=e=>{if(e.tagName==="VIDEO")return e.closest("figure")?void 0:en(e);if(e.tagName==="FIGURE"){const n=Ie(e,"video");if(!n)return;const{targetElement:t,caption:o}=n;return{...en(t),caption:o}}},Eo=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add video",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("video"),n.src=e.props.url,e.props.previewWidth&&(n.width=e.props.previewWidth)):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?et(n,e.props.caption):Le(n,e.props.caption):{dom:n}},Bo=be(Co,{render:vo,parse:So,toExternalHTML:Eo}),_t={paragraph:_s,heading:Ss,quote:Fs,codeBlock:Qn,toggleListItem:Ts,bulletListItem:Ms,numberedListItem:Hs,checkListItem:Ls,table:Ys,file:so,image:mo,video:Bo,audio:Xn},To=Tt(_t),Vt={bold:ne(zr.default,"boolean"),italic:ne(qr.default,"boolean"),underline:ne(jr.default,"boolean"),strike:ne(Kr.default,"boolean"),code:ne(Wr.default,"boolean"),textColor:ws,backgroundColor:ks},Js=It(Vt),Ut={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},xo=Pt(Ut);function V(e,n){return e in n.schema.blockSchema&&n.schema.blockSchema[e]===To[e]}function Xs(e,n,t){return e in t.schema.blockSchema&&t.schema.blockSchema[e]===n}function Po(e,n){return e in n.schema.inlineContentSchema&&n.schema.inlineContentSchema[e]===xo[e]}function Zs(e,n,t){return e in t.schema.inlineContentSchema&&t.schema.inlineContentSchema[e]===n}function Mo(e,n,t){return n.type===e&&n.type in t.schema.blockSchema&&V(n.type,t)}function Qs(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock||!1}function ei(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock&&"showPreview"in n.schema.blockSchema[e.type].propSchema||!1}function ti(e,n){return n.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function Io(e,n,t){return n in t.schema.blockSchema&&e in t.schema.blockSchema[n].propSchema&&t.schema.blockSchema[n].propSchema[e]===L[e]}function ni(e,n,t){return Io(e,n.type,t)}function kt(e){return e instanceof I.CellSelection}const oi=async e=>{const n=new FormData;return n.append("file",e),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:n})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};function ri(e){let n=e.getTextCursorPosition().block,t=e.schema.blockSchema[n.type].content;for(;t==="none";){if(n=e.getTextCursorPosition().nextBlock,n===void 0)return;t=e.schema.blockSchema[n.type].content,e.setTextCursorPosition(n,"end")}}function N(e,n){const t=e.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");let o;return Array.isArray(t.content)&&(t.content.length===1&&oe(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?(o=e.updateBlock(t,n),e.setTextCursorPosition(o)):(o=e.insertBlocks([n],t,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),ri(e),o}function si(e){const n=[];return V("heading",e)&&n.push({onItemClick:()=>{N(e,{type:"heading",props:{level:1}})},badge:J("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{N(e,{type:"heading",props:{level:2}})},badge:J("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{N(e,{type:"heading",props:{level:3}})},badge:J("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),V("quote",e)&&n.push({onItemClick:()=>{N(e,{type:"quote"})},key:"quote",...e.dictionary.slash_menu.quote}),V("toggleListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"toggleListItem"})},badge:J("Mod-Shift-6"),key:"toggle_list",...e.dictionary.slash_menu.toggle_list}),V("numberedListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"numberedListItem"})},badge:J("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),V("bulletListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"bulletListItem"})},badge:J("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),V("checkListItem",e)&&n.push({onItemClick:()=>{N(e,{type:"checkListItem"})},badge:J("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),V("paragraph",e)&&n.push({onItemClick:()=>{N(e,{type:"paragraph"})},badge:J("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),V("codeBlock",e)&&n.push({onItemClick:()=>{N(e,{type:"codeBlock"})},badge:J("Mod-Alt-c"),key:"code_block",...e.dictionary.slash_menu.code_block}),V("table",e)&&n.push({onItemClick:()=>{N(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),V("image",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"image"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"image",...e.dictionary.slash_menu.image}),V("video",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"video"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"video",...e.dictionary.slash_menu.video}),V("audio",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"audio"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"audio",...e.dictionary.slash_menu.audio}),V("file",e)&&n.push({onItemClick:()=>{const t=N(e,{type:"file"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"file",...e.dictionary.slash_menu.file}),V("heading",e)&&(n.push({onItemClick:()=>{N(e,{type:"heading",props:{level:1,isToggleable:!0}})},key:"toggle_heading",...e.dictionary.slash_menu.toggle_heading},{onItemClick:()=>{N(e,{type:"heading",props:{level:2,isToggleable:!0}})},key:"toggle_heading_2",...e.dictionary.slash_menu.toggle_heading_2},{onItemClick:()=>{N(e,{type:"heading",props:{level:3,isToggleable:!0}})},key:"toggle_heading_3",...e.dictionary.slash_menu.toggle_heading_3}),e.settings.heading.levels.filter(t=>t>3).forEach(t=>{n.push({onItemClick:()=>{N(e,{type:"heading",props:{level:t}})},key:`heading_${t}`,...e.dictionary.slash_menu[`heading_${t}`]})})),n.push({onItemClick:()=>{e.openSuggestionMenu(":",{deleteTriggerCharacter:!0,ignoreQueryLength:!0})},key:"emoji",...e.dictionary.slash_menu.emoji}),n}function ii(e,n){return e.filter(({title:t,aliases:o})=>t.toLowerCase().includes(n.toLowerCase())||o&&o.filter(r=>r.toLowerCase().includes(n.toLowerCase())).length!==0)}function it(e){return e&&Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}class we{constructor(n){p(this,"blockSpecs");p(this,"inlineContentSpecs");p(this,"styleSpecs");p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"BlockNoteEditor","only for types");p(this,"Block","only for types");p(this,"PartialBlock","only for types");this.blockSpecs=it(n==null?void 0:n.blockSpecs)||_t,this.inlineContentSpecs=it(n==null?void 0:n.inlineContentSpecs)||Ut,this.styleSpecs=it(n==null?void 0:n.styleSpecs)||Vt,this.blockSchema=Tt(this.blockSpecs),this.inlineContentSchema=Pt(this.inlineContentSpecs),this.styleSchema=It(this.styleSpecs)}static create(n){return new we(n)}}const Lo={type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},Ao=()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},No=e=>{if(e.tagName==="DIV"&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},Do=()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}},Ho=be(Lo,{render:Ao,parse:No,toExternalHTML:Do}),Ft=we.create({blockSpecs:{pageBreak:Ho}}),ai=e=>we.create({blockSpecs:{...e.blockSpecs,...Ft.blockSpecs},inlineContentSpecs:e.inlineContentSpecs,styleSpecs:e.styleSpecs});function Oo(e){return"pageBreak"in e.schema.blockSchema&&e.schema.blockSchema.pageBreak===Ft.blockSchema.pageBreak}function li(e){const n=[];return Oo(e)&&n.push({...e.dictionary.slash_menu.page_break,onItemClick:()=>{N(e,{type:"pageBreak"})},key:"page_break"}),n}function ci(e){return e.transact(n=>{const t=X(n.doc,n.selection.anchor);if(n.selection instanceof I.CellSelection)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:n.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:n.selection.$headCell.pos-t.posBeforeNode};if(n.selection instanceof C.NodeSelection)return{type:"node",anchorBlockId:t.node.attrs.id};{const o=X(n.doc,n.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:o.node.attrs.id,anchorOffset:n.selection.anchor-t.posBeforeNode,headOffset:n.selection.head-o.posBeforeNode}}})}function di(e,n){var r,s;const t=(r=z(n.anchorBlockId,e.doc))==null?void 0:r.posBeforeNode;if(t===void 0)throw new Error(`Could not find block with ID ${n.anchorBlockId} to update selection`);let o;if(n.type==="cell")o=I.CellSelection.create(e.doc,t+n.anchorCellOffset,t+n.headCellOffset);else if(n.type==="node")o=C.NodeSelection.create(e.doc,t+1);else{const i=(s=z(n.headBlockId,e.doc))==null?void 0:s.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${n.headBlockId} to update selection`);o=C.TextSelection.create(e.doc,t+n.anchorOffset,i+n.headOffset)}e.setSelection(o)}function yt(e){return e.map(n=>n.type==="columnList"?n.children.map(t=>yt(t.children)).flat():{...n,children:yt(n.children)}).flat()}function Ro(e,n,t){e.transact(o=>{var i;const r=((i=e.getSelection())==null?void 0:i.blocks)||[e.getTextCursorPosition().block],s=ci(e);e.removeBlocks(r),e.insertBlocks(yt(r),n,t),di(o,s)})}function _o(e){return!e||e.type!=="columnList"}function Vo(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[n.children.length-1],r="after"):(o=n,r="before"):t&&(o=t,r="before"),!o||!r)return;const s=e.getParentBlock(o);return _o(s)?{referenceBlock:o,placement:r}:Vo(e,r==="after"?o:e.getPrevBlock(o),s)}function Uo(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[0],r="before"):(o=n,r="after"):t&&(o=t,r="after"),!o||!r)return;const s=e.getParentBlock(o);return _o(s)?{referenceBlock:o,placement:r}:Uo(e,r==="before"?o:e.getNextBlock(o),s)}function ui(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[0])||e.getTextCursorPosition().block,o=Vo(e,e.getPrevBlock(t),e.getParentBlock(t));o&&Ro(e,o.referenceBlock,o.placement)})}function pi(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[(n==null?void 0:n.blocks.length)-1])||e.getTextCursorPosition().block,o=Uo(e,e.getNextBlock(t),e.getParentBlock(t));o&&Ro(e,o.referenceBlock,o.placement)})}function hi(e,n,t){const{$from:o,$to:r}=e.selection,s=o.blockRange(r,m=>m.childCount>0&&(m.type.name==="blockGroup"||m.type.name==="column"));if(!s)return!1;const i=s.startIndex;if(i===0)return!1;const l=s.parent.child(i-1);if(l.type!==n)return!1;const c=l.lastChild&&l.lastChild.type===t,d=S.Fragment.from(c?n.create():null),u=new S.Slice(S.Fragment.from(n.create(null,S.Fragment.from(t.create(null,d)))),c?3:1,0),h=s.start,f=s.end;return e.step(new he.ReplaceAroundStep(h-(c?3:1),f,h,f,u,1,!0)).scrollIntoView(),!0}function Fo(e){return e.transact(n=>hi(n,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function fi(e){e._tiptapEditor.commands.liftListItem("blockContainer")}function mi(e){return e.transact(n=>{const{bnBlock:t}=Te(n);return n.doc.resolve(t.beforePos).nodeBefore!==null})}function gi(e){return e.transact(n=>{const{bnBlock:t}=Te(n);return n.doc.resolve(t.beforePos).depth>1})}function $o(e,n){const t=typeof n=="string"?n:n.id,o=R(e),r=z(t,e);if(r)return T(r.node,o)}function zo(e,n){const t=typeof n=="string"?n:n.id,o=z(t,e),r=R(e);if(!o)return;const i=e.resolve(o.posBeforeNode).nodeBefore;if(i)return T(i,r)}function Wo(e,n){const t=typeof n=="string"?n:n.id,o=z(t,e),r=R(e);if(!o)return;const i=e.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(i)return T(i,r)}function qo(e,n){const t=typeof n=="string"?n:n.id,o=R(e),r=z(t,e);if(!r)return;const s=e.resolve(r.posBeforeNode),i=s.node(),a=s.node(-1),l=a.type.name!=="doc"?i.type.name==="blockGroup"?a:i:void 0;if(l)return T(l,o)}function bi(e,n,t,o={updateSelection:!0}){let{from:r,to:s}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},i=!0,a=!0,l="";if(t.forEach(c=>{c.check(),i&&c.isText&&c.marks.length===0?l+=c.text:i=!1,a=a?c.isBlock:!1}),r===s&&a){const{parent:c}=e.doc.resolve(r);c.isTextblock&&!c.type.spec.code&&!c.childCount&&(r-=1,s+=1)}return i?e.insertText(l,r,s):e.replaceWith(r,s,t),o.updateSelection&&y.selectionToInsertionEnd(e,e.steps.length-1,-1),!0}function ki(e){const n=R(e);if(e.selection.empty||"node"in e.selection)return;const t=e.doc.resolve(X(e.doc,e.selection.from).posBeforeNode),o=e.doc.resolve(X(e.doc,e.selection.to).posBeforeNode),r=(c,d)=>{const u=t.posAtIndex(c,d),h=e.doc.resolve(u).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${u}`);return T(h,n)},s=[],i=t.sharedDepth(o.pos),a=t.index(i),l=o.index(i);if(t.depth>i){s.push(T(t.nodeAfter,n));for(let c=t.depth;c>i;c--)if(t.node(c).type.isInGroup("childContainer")){const u=t.index(c)+1,h=t.node(c).childCount;for(let f=u;f<h;f++)s.push(r(f,c))}}else s.push(r(a,i));for(let c=a+1;c<=l;c++)s.push(r(c,i));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:s}}function yi(e,n,t){const o=typeof n=="string"?n:n.id,r=typeof t=="string"?t:t.id,s=R(e),i=ye(s);if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const a=z(o,e.doc);if(!a)throw new Error(`Block with ID ${o} not found`);const l=z(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const c=ee(a),d=ee(l),u=i.blockSchema[c.blockNoteType],h=i.blockSchema[d.blockNoteType];if(!c.isBlockContainer||u.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!d.isBlockContainer||h.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let f,m;if(u.content==="table"){const g=I.TableMap.get(c.blockContent.node);f=c.blockContent.beforePos+g.positionAt(0,0,c.blockContent.node)+1+2}else f=c.blockContent.beforePos+1;if(h.content==="table"){const g=I.TableMap.get(d.blockContent.node),b=d.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,d.blockContent.node)+1,k=e.doc.resolve(b).nodeAfter.nodeSize;m=b+k-2}else m=d.blockContent.afterPos-1;e.setSelection(C.TextSelection.create(e.doc,f,m))}function wi(e){const n=R(e);let t=e.selection.$from,o=e.selection.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=e.doc.resolve(o.pos+1);for(;o.parentOffset===0&&o.depth>0;)o=e.doc.resolve(o.pos-1);for(;t.parentOffset===0&&t.depth>0;)t=e.doc.resolve(t.pos-1);for(;t.parentOffset>=t.parent.nodeSize-2&&t.depth>0;)t=e.doc.resolve(t.pos+1);const r=Cn(e.doc.slice(t.pos,o.pos,!0),n);return{_meta:{startPos:t.pos,endPos:o.pos},...r}}function Ci(e){const{bnBlock:n}=Te(e),t=R(e.doc),o=e.doc.resolve(n.beforePos),r=o.nodeBefore,s=e.doc.resolve(n.afterPos).nodeAfter;let i;return o.depth>1&&(i=o.node(),i.type.isInGroup("bnBlock")||(i=o.node(o.depth-1))),{block:T(n.node,t),prevBlock:r===null?void 0:T(r,t),nextBlock:s===null?void 0:T(s,t),parentBlock:i===void 0?void 0:T(i,t)}}function Ko(e,n,t="start"){const o=typeof n=="string"?n:n.id,r=R(e.doc),s=ye(r),i=z(o,e.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const a=ee(i),l=s.blockSchema[a.blockNoteType].content;if(a.isBlockContainer){const c=a.blockContent;if(l==="none"){e.setSelection(C.NodeSelection.create(e.doc,c.beforePos));return}if(l==="inline")t==="start"?e.setSelection(C.TextSelection.create(e.doc,c.beforePos+1)):e.setSelection(C.TextSelection.create(e.doc,c.afterPos-1));else if(l==="table")t==="start"?e.setSelection(C.TextSelection.create(e.doc,c.beforePos+4)):e.setSelection(C.TextSelection.create(e.doc,c.afterPos-4));else throw new j(l)}else{const c=t==="start"?a.childContainer.node.firstChild:a.childContainer.node.lastChild;Ko(e,c.attrs.id,t)}}exports.esmDependencies=void 0;async function Ae(){if(exports.esmDependencies)return exports.esmDependencies;const e=await Promise.all([import("rehype-parse"),import("rehype-stringify"),import("unified"),import("hast-util-from-dom"),import("rehype-remark"),import("remark-gfm"),import("remark-stringify"),import("remark-parse"),import("remark-rehype"),import("rehype-format")]);return exports.esmDependencies={rehypeParse:e[0],rehypeStringify:e[1],unified:e[2],hastUtilFromDom:e[3],rehypeRemark:e[4],remarkGfm:e[5],remarkStringify:e[6],remarkParse:e[7],remarkRehype:e[8],rehypeFormat:e[9]},exports.esmDependencies}function vi(){const e=n=>{let t=n.children.length;for(let o=0;o<t;o++){const r=n.children[o];if(r.type==="element"&&(e(r),r.tagName==="u"))if(r.children.length>0){n.children.splice(o,1,...r.children);const s=r.children.length-1;t+=s,o+=s}else n.children.splice(o,1),t--,o--}};return e}function Si(){const e=exports.esmDependencies;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const n=t=>{var o;if(t.children&&"length"in t.children&&t.children.length)for(let r=t.children.length-1;r>=0;r--){const s=t.children[r],i=r+1<t.children.length?t.children[r+1]:void 0;s.type==="element"&&s.tagName==="input"&&((o=s.properties)==null?void 0:o.type)==="checkbox"&&(i==null?void 0:i.type)==="element"&&i.tagName==="p"?(i.tagName="span",i.children.splice(0,0,e.hastUtilFromDom.fromDom(document.createTextNode(" ")))):n(s)}};return n}function nt(e){const n=exports.esmDependencies;if(!n)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return n.unified.unified().use(n.rehypeParse.default,{fragment:!0}).use(vi).use(Si).use(n.rehypeRemark.default).use(n.remarkGfm.default).use(n.remarkStringify.default,{handlers:{text:o=>o.value}}).processSync(e).value}async function jo(e,n,t,o){await Ae();const s=Me(n,t).exportBlocks(e,o);return nt(s)}function Ei(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Bi(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function Ti(e){e.querySelectorAll("li > ul, li > ol").forEach(n=>{const t=Ei(n),o=n.parentElement,r=Array.from(o.childNodes).slice(t+1);n.remove(),r.forEach(s=>{s.remove()}),o.insertAdjacentElement("afterend",n),r.reverse().forEach(s=>{if(Bi(s))return;const i=document.createElement("li");i.append(s),n.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function xi(e){e.querySelectorAll("li + ul, li + ol").forEach(n=>{var s,i;const t=n.previousElementSibling,o=document.createElement("div");t.insertAdjacentElement("afterend",o),o.append(t);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),o.append(r);((s=o.nextElementSibling)==null?void 0:s.nodeName)==="UL"||((i=o.nextElementSibling)==null?void 0:i.nodeName)==="OL";)r.append(o.nextElementSibling)})}let tn=null;function Pi(){return tn||(tn=document.implementation.createHTMLDocument("title"))}function Go(e){if(typeof e=="string"){const n=Pi().createElement("div");n.innerHTML=e,e=n}return Ti(e),xi(e),e}async function $t(e,n){const t=Go(e),r=S.DOMParser.fromSchema(n).parse(t,{topNode:n.nodes.blockGroup.create()}),s=[];for(let i=0;i<r.childCount;i++)s.push(T(r.child(i),n));return s}function Mi(e,n){const t=n.value?n.value:"",o={};n.lang&&(o["data-language"]=n.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:t}]};return n.meta&&(r.data={meta:n.meta}),e.patch(n,r),r=e.applyData(n,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(n,r),r}async function zt(e){const n=await Ae();return n.unified.unified().use(n.remarkParse.default).use(n.remarkGfm.default).use(n.remarkRehype.default,{handlers:{...n.remarkRehype.defaultHandlers,code:Mi}}).use(n.rehypeStringify.default).processSync(e).value}async function Yo(e,n){const t=await zt(e);return $t(t,n)}const Wt=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function Ii(e,n){if(!e.startsWith(".")||!n.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===n}function Li(e,n){const t=e.split("/"),o=n.split("/");if(t.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${n} is not a valid MIME type.`);return t[1]==="*"||o[1]==="*"?t[0]===o[0]:(t[0]==="*"||o[0]==="*"||t[0]===o[0])&&t[1]===o[1]}function nn(e,n,t,o="after"){let r;return Array.isArray(n.content)&&n.content.length===0?r=e.updateBlock(n,t).id:r=e.insertBlocks([t],n,o)[0].id,r}async function Jo(e,n){var i;if(!n.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const t="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(t===null)return;let o=null;for(const a of Wt)if(t.types.includes(a)){o=a;break}if(o!=="Files")return;const r=t.items;if(!r)return;e.preventDefault();const s=Object.values(n.schema.blockSchema).filter(a=>a.isFileBlock);for(let a=0;a<r.length;a++){let l="file";for(const d of s)for(const u of d.fileBlockAccept||[]){const h=u.startsWith("."),f=r[a].getAsFile();if(f&&(!h&&f.type&&Li(r[a].type,u)||h&&Ii("."+f.name.split(".").pop(),u))){l=d.type;break}}const c=r[a].getAsFile();if(c){const d={type:l,props:{name:c.name}};let u;if(e.type==="paste"){const m=n.getTextCursorPosition().block;u=nn(n,m,d)}else if(e.type==="drop"){const m={left:e.clientX,top:e.clientY},g=(i=n.prosemirrorView)==null?void 0:i.posAtCoords(m);if(!g)return;u=n.transact(b=>{var E;const k=X(b.doc,g.pos),w=(E=n.prosemirrorView)==null?void 0:E.dom.querySelector(`[data-id="${k.node.attrs.id}"]`),v=w==null?void 0:w.getBoundingClientRect();return nn(n,n.getBlock(k.node.attrs.id),d,v&&(v.top+v.bottom)/2>m.top?"before":"after")})}else return;const h=await n.uploadFile(c,u),f=typeof h=="string"?{props:{url:h}}:{...h};n.updateBlock(u,f)}}}const Ai=e=>y.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new C.Plugin({props:{handleDOMEvents:{drop(n,t){if(!e.isEditable)return;let o=null;for(const r of Wt)if(t.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(Jo(t,e),!0):!1}}}})]}}),Ni=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,Di=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,Hi=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,Oi=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,Ri=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,_i=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,Vi=/\n{2} {0,3}-{2,48}\n{2}/,Ui=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,Fi=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,$i=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,zi=/^\s*\|(.+\|)+\s*$/m,Wi=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,qi=/^\s*\|(.+\|)+\s*$/m,Ki=e=>Ni.test(e)||Di.test(e)||Hi.test(e)||Oi.test(e)||Ri.test(e)||_i.test(e)||Vi.test(e)||Ui.test(e)||Fi.test(e)||$i.test(e)||zi.test(e)||Wi.test(e)||qi.test(e);async function ji(e,n){const{schema:t}=n.state;if(!e.clipboardData)return!1;const o=e.clipboardData.getData("text/plain");if(!o)return!1;if(!t.nodes.codeBlock)return n.pasteText(o),!0;const r=e.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;return i?(n.pasteHTML(`<pre><code class="language-${i}">${o.replace(/\r\n?/g,`
11
- `)}</code></pre>`),!0):!1}function Gi({event:e,editor:n,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:o}){var a;if(n.transact(l=>l.selection.$from.parent.type.spec.code&&l.selection.$to.parent.type.spec.code)){const l=(a=e.clipboardData)==null?void 0:a.getData("text/plain");if(l)return n.pasteText(l),!0}let s;for(const l of Wt)if(e.clipboardData.types.includes(l)){s=l;break}if(!s)return!0;if(s==="vscode-editor-data")return ji(e,n.prosemirrorView),!0;if(s==="Files")return Jo(e,n),!0;const i=e.clipboardData.getData(s);if(s==="blocknote/html")return n.pasteHTML(i,!0),!0;if(s==="text/markdown")return n.pasteMarkdown(i),!0;if(t){const l=e.clipboardData.getData("text/plain");if(Ki(l))return n.pasteMarkdown(l),!0}return s==="text/html"?(n.pasteHTML(i),!0):o?(n.pasteMarkdown(i),!0):(n.pasteText(i),!0)}const Yi=(e,n)=>y.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new C.Plugin({props:{handleDOMEvents:{paste(t,o){if(o.preventDefault(),!!e.isEditable)return n({event:o,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>Gi({event:o,editor:e,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function Xo(e){const n=[];return e.descendants(t=>{var r,s;const o=R(t);return t.type.name==="blockContainer"&&((r=t.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:t.type.name==="columnList"&&t.childCount===1?((s=t.firstChild)==null||s.forEach(i=>{n.push(T(i,o))}),!1):t.type.isInGroup("bnBlock")?(n.push(T(t,o)),!1):!0}),n}function Ji(e,n,t){var a;let o=!1;const r=e.state.selection instanceof I.CellSelection;if(!r){const l=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,c=[];for(let d=0;d<l.childCount;d++)c.push(l.child(d));o=c.find(d=>d.type.isInGroup("bnBlock")||d.type.name==="blockGroup"||d.type.spec.group==="blockContent")===void 0,o&&(n=l)}let s;const i=Me(e.state.schema,t);if(r){((a=n.firstChild)==null?void 0:a.type.name)==="table"&&(n=n.firstChild.content);const l=xt(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(o){const l=xe(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=Xo(n);s=i.exportBlocks(l,{})}return s}function qt(e,n){"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&n.transact(i=>i.setSelection(new C.NodeSelection(i.doc.resolve(e.state.selection.from-1))));const t=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=Ji(e,o,n),s=nt(r);return{clipboardHTML:t,externalHTML:r,markdown:s}}const on=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let n=e.focusNode;for(;n;){if(n instanceof HTMLElement&&n.getAttribute("contenteditable")==="false")return!0;n=n.parentElement}return!1},rn=(e,n,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=qt(n,e);t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",s)},Xi=e=>y.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return Ae(),[new C.Plugin({props:{handleDOMEvents:{copy(n,t){return on()||rn(e,n,t),!0},cut(n,t){return on()||(rn(e,n,t),n.editable&&n.dispatch(n.state.tr.deleteSelection())),!0},dragstart(n,t){if(!("node"in n.state.selection)||n.state.selection.node.type.spec.group!=="blockContent")return;e.transact(i=>i.setSelection(new C.NodeSelection(i.doc.resolve(n.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=qt(n,e);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",s),!0}}}})]}}),Zi=y.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{backgroundColor:{default:L.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):L.backgroundColor.default,renderHTML:e=>e.backgroundColor===L.backgroundColor.default?{}:{"data-background-color":e.backgroundColor}}}}]}});class ot{constructor(){p(this,"callbacks",{})}on(n,t){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(t),()=>this.off(n,t)}emit(n,...t){const o=this.callbacks[n];o&&o.forEach(r=>r.apply(this,t))}off(n,t){const o=this.callbacks[n];o&&(t?this.callbacks[n]=o.filter(r=>r!==t):delete this.callbacks[n])}removeAllListeners(){this.callbacks={}}}class O extends ot{constructor(...t){super();p(this,"plugins",[])}static key(){throw new Error("You must implement the key method in your extension")}addProsemirrorPlugin(t){this.plugins.push(t)}get priority(){}}class Qi extends O{constructor(){super();p(this,"beforeChangeCallbacks",[]);this.addProsemirrorPlugin(new C.Plugin({filterTransaction:t=>{let o;return this.beforeChangeCallbacks.reduce((r,s)=>r===!1?r:s({getChanges(){return o||(o=At(t),o)},tr:t})!==!1,!0)}}))}static key(){return"blockChange"}subscribe(t){return this.beforeChangeCallbacks.push(t),()=>{this.beforeChangeCallbacks=this.beforeChangeCallbacks.filter(o=>o!==t)}}}const ue=class ue extends O{constructor(t){super();p(this,"provider");p(this,"recentlyUpdatedCursors");p(this,"renderCursor",(t,o)=>{let r=this.recentlyUpdatedCursors.get(o);if(!r){const s=(this.collaboration.renderCursor??ue.defaultCursorRender)(t);this.collaboration.showCursorLabels!=="always"&&(s.addEventListener("mouseenter",()=>{const i=this.recentlyUpdatedCursors.get(o);i.element.setAttribute("data-active",""),i.hideTimeout&&(clearTimeout(i.hideTimeout),this.recentlyUpdatedCursors.set(o,{element:i.element,hideTimeout:void 0}))}),s.addEventListener("mouseleave",()=>{const i=this.recentlyUpdatedCursors.get(o);this.recentlyUpdatedCursors.set(o,{element:i.element,hideTimeout:setTimeout(()=>{i.element.removeAttribute("data-active")},2e3)})})),r={element:s,hideTimeout:void 0},this.recentlyUpdatedCursors.set(o,r)}return r.element});p(this,"updateUser",t=>{this.provider.awareness.setLocalStateField("user",t)});this.collaboration=t,this.provider=t.provider,this.recentlyUpdatedCursors=new Map,this.provider.awareness.setLocalStateField("user",t.user),t.showCursorLabels!=="always"&&this.provider.awareness.on("change",({updated:o})=>{for(const r of o){const s=this.recentlyUpdatedCursors.get(r);s&&(s.element.setAttribute("data-active",""),s.hideTimeout&&clearTimeout(s.hideTimeout),this.recentlyUpdatedCursors.set(r,{element:s.element,hideTimeout:setTimeout(()=>{s.element.removeAttribute("data-active")},2e3)}))}}),this.addProsemirrorPlugin(D.yCursorPlugin(this.provider.awareness,{selectionBuilder:D.defaultSelectionBuilder,cursorBuilder:this.renderCursor}))}static key(){return"yCursorPlugin"}get priority(){return 999}static isDarkColor(t){const o=t.charAt(0)==="#"?t.substring(1,7):t,r=parseInt(o.substring(0,2),16),s=parseInt(o.substring(2,4),16),i=parseInt(o.substring(4,6),16),l=[r/255,s/255,i/255].map(d=>d<=.03928?d/12.92:Math.pow((d+.055)/1.055,2.4));return .2126*l[0]+.7152*l[1]+.0722*l[2]<=.179}};p(ue,"defaultCursorRender",t=>{const o=document.createElement("span");o.classList.add("bn-collaboration-cursor__base");const r=document.createElement("span");r.setAttribute("contentedEditable","false"),r.classList.add("bn-collaboration-cursor__caret"),r.setAttribute("style",`background-color: ${t.color}; color: ${ue.isDarkColor(t.color)?"white":"black"}`);const s=document.createElement("span");return s.classList.add("bn-collaboration-cursor__label"),s.setAttribute("style",`background-color: ${t.color}; color: ${ue.isDarkColor(t.color)?"white":"black"}`),s.insertBefore(document.createTextNode(t.name),null),r.insertBefore(s,null),o.insertBefore(document.createTextNode("⁠"),null),o.insertBefore(r,null),o.insertBefore(document.createTextNode("⁠"),null),o});let ze=ue;class wt extends O{static key(){return"ySyncPlugin"}constructor(n){super(),this.addProsemirrorPlugin(D.ySyncPlugin(n))}get priority(){return 1001}}class Ct extends O{static key(){return"yUndoPlugin"}constructor({editor:n}){super(),this.addProsemirrorPlugin(D.yUndoPlugin({trackedOrigins:[n]}))}get priority(){return 1e3}}const Zo=y.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:e=>!!e.getAttribute("data-orphan"),renderHTML:e=>e.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:e=>e.getAttribute("data-bn-thread-id"),renderHTML:e=>({"data-bn-thread-id":e.threadId}),default:""}}},renderHTML({HTMLAttributes:e}){return["span",y.mergeAttributes(e,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(e){return e.name==="comment"?{blocknoteIgnore:!0}:{}}});class ea extends ot{constructor(t){super();p(this,"userCache",new Map);p(this,"loadingUsers",new Set);this.resolveUsers=t}async loadUsers(t){const o=t.filter(r=>!this.userCache.has(r)&&!this.loadingUsers.has(r));if(o.length!==0){for(const r of o)this.loadingUsers.add(r);try{const r=await this.resolveUsers(o);for(const s of r)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const r of o)this.loadingUsers.delete(r)}}}getUser(t){return this.userCache.get(t)}subscribe(t){return this.on("update",t)}}const De=new C.PluginKey("blocknote-comments"),ta="SET_SELECTED_THREAD_ID";function na(e,n){const t=new Map;return e.descendants((o,r)=>{o.marks.forEach(s=>{if(s.type.name===n){const i=s.attrs.threadId;if(!i)return;const a=r,l=a+o.nodeSize,c=t.get(i)??{from:1/0,to:0};t.set(i,{from:Math.min(a,c.from),to:Math.max(l,c.to)})}})}),t}class oa extends O{constructor(t,o,r){super();p(this,"userStore");p(this,"pendingComment",!1);p(this,"selectedThreadId");p(this,"threadPositions",new Map);p(this,"updateMarksFromThreads",t=>{this.editor.transact(o=>{o.doc.descendants((r,s)=>{r.marks.forEach(i=>{if(i.type.name===this.markType){const a=i.type,l=i.attrs.threadId,c=t.get(l),d=!!(!c||c.resolved||c.deletedAt);if(d!==i.attrs.orphan){const u=Math.max(s,0),h=Math.min(s+r.nodeSize,o.doc.content.size-1,o.doc.content.size-1);o.removeMark(u,h,i),o.addMark(u,h,a.create({...i.attrs,orphan:d})),d&&this.selectedThreadId===l&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})});if(this.editor=t,this.threadStore=o,this.markType=r,!t.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new ea(t.resolveUsers),this.threadStore.subscribe(this.updateMarksFromThreads),t.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),t.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const s=this;this.addProsemirrorPlugin(new C.Plugin({key:De,state:{init(){return{decorations:H.DecorationSet.empty}},apply(i,a){const l=i.getMeta(De);if(!i.docChanged&&!l)return a;const c=i.docChanged?na(i.doc,s.markType):s.threadPositions;(c.size>0||s.threadPositions.size>0)&&(s.threadPositions=c,s.emitStateUpdate());const d=[];if(s.selectedThreadId){const u=c.get(s.selectedThreadId);u&&d.push(H.Decoration.inline(u.from,u.to,{class:"bn-thread-mark-selected"}))}return{decorations:H.DecorationSet.create(i.doc,d)}}},props:{decorations(i){var a;return((a=De.getState(i))==null?void 0:a.decorations)??H.DecorationSet.empty},handleClick:(i,a,l)=>{if(l.button!==0)return;const c=i.state.doc.nodeAt(a);if(!c){s.selectThread(void 0);return}const d=c.marks.find(h=>h.type.name===r&&h.attrs.orphan!==!0),u=d==null?void 0:d.attrs.threadId;s.selectThread(u,!1)}}}))}static key(){return"comments"}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(t){return this.on("update",t)}selectThread(t,o=!0){var r,s;if(this.selectedThreadId!==t&&(this.selectedThreadId=t,this.emitStateUpdate(),this.editor.transact(i=>i.setMeta(De,{name:ta})),t&&o)){const i=this.threadPositions.get(t);if(!i)return;(s=(r=this.editor.prosemirrorView)==null?void 0:r.domAtPos(i.from).node)==null||s.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(t){const o=await this.threadStore.createThread(t);if(this.threadStore.addThreadToDocument){const r=this.editor.prosemirrorView,s=r.state.selection,i=D.ySyncPluginKey.getState(r.state),a={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?D.getRelativeSelection(i.binding,r.state):void 0};await this.threadStore.addThreadToDocument({threadId:o.id,selection:a})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:o.id})}}class Qo{constructor(n,t,o,r){p(this,"state");p(this,"emitUpdate");p(this,"mouseDownHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"dragstartHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;if((n=this.state)!=null&&n.show){const t=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!t)return;this.state.referencePos=t.getBoundingClientRect(),this.emitUpdate()}});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pluginKey=t,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");r(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var a,l;const o=this.pluginKey.getState(n.state),r=this.pluginKey.getState(t);if(!((a=this.state)!=null&&a.show)&&(o!=null&&o.block)&&this.editor.isEditable){const c=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);if(!c)return;this.state={show:!0,referencePos:c.getBoundingClientRect(),block:o.block},this.emitUpdate();return}const s=(o==null?void 0:o.block)&&!(r!=null&&r.block),i=!(o!=null&&o.block)&&(r==null?void 0:r.block);s&&this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate()),i&&((l=this.state)!=null&&l.show)&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const at=new C.PluginKey("FilePanelPlugin");class er extends O{constructor(t){super();p(this,"view");p(this,"closeMenu",()=>{var t;return(t=this.view)==null?void 0:t.closeMenu()});this.addProsemirrorPlugin(new C.Plugin({key:at,view:o=>(this.view=new Qo(t,at,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>{var s;return r.key==="Escape"&&this.shown?((s=this.view)==null||s.closeMenu(),!0):!1}},state:{init:()=>({block:void 0}),apply:(o,r)=>{const s=o.getMeta(at);return s||(!o.getMeta(D.ySyncPluginKey)&&(o.selectionSet||o.docChanged)?{block:void 0}:r)}}}))}static key(){return"filePanel"}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}class tr{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"shouldShow",({view:n,state:t,from:o,to:r})=>{const{doc:s,selection:i}=t,{empty:a}=i,l=!s.textBetween(o,r).length&&y.isTextSelection(t.selection);if(i.$from.parent.type.spec.code||y.isNodeSelection(i)&&i.node.type.spec.code||a||l)return!1;const c=document.activeElement;return!(!this.isElementWithinEditorWrapper(c)&&n.editable)});p(this,"blurHandler",n=>{var o;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;n&&n.relatedTarget&&(t===n.relatedTarget||t.contains(n.relatedTarget)||n.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"isElementWithinEditorWrapper",n=>{if(!n)return!1;const t=this.pmView.dom.parentElement;return t?t.contains(n):!1});p(this,"viewMousedownHandler",n=>{(!this.isElementWithinEditorWrapper(n.target)||n.button===0)&&(this.preventShow=!0)});p(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))});p(this,"dragHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.root.addEventListener("mouseup",this.mouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("blur",this.blurHandler),t.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var f,m,g;const{state:o,composing:r}=n,{doc:s,selection:i}=o,a=t&&t.doc.eq(s)&&t.selection.eq(i);if(r||a)return;const{ranges:l}=i,c=Math.min(...l.map(b=>b.$from.pos)),d=Math.max(...l.map(b=>b.$to.pos)),u=this.shouldShow({view:n,state:o,from:c,to:d}),h=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(u||this.preventHide)&&!h){const b=this.getSelectionBoundingBox();if(b.x===0||b.y===0||b.height===0){queueMicrotask(()=>{const w={show:!0,referencePos:this.getSelectionBoundingBox()};this.state=w,this.emitUpdate(),n.dispatch(n.state.tr.setSelection(C.TextSelection.create(n.state.doc,n.state.selection.from+1,n.state.selection.to))),n.dispatch(n.state.tr.setSelection(C.TextSelection.create(n.state.doc,n.state.selection.from-1,n.state.selection.to)))});return}const k={show:!0,referencePos:this.getSelectionBoundingBox()};(k.show!==((f=this.state)==null?void 0:f.show)||k.referencePos.toJSON()!==((m=this.state)==null?void 0:m.referencePos.toJSON()))&&(this.state=k,this.emitUpdate());return}if((g=this.state)!=null&&g.show&&!this.preventHide&&(!u||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:n}=this.pmView,{selection:t}=n,{ranges:o}=t,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(y.isNodeSelection(t)){const i=this.pmView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return y.posToDOMRect(this.pmView,r,s)}}const nr=new C.PluginKey("FormattingToolbarPlugin");class or extends O{constructor(t){super();p(this,"view");p(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new C.Plugin({key:nr,view:o=>(this.view=new tr(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}}))}static key(){return"formattingToolbar"}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}const ra=y.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:e}){return["br",y.mergeAttributes(this.options.HTMLAttributes,e)]},renderText(){return`
12
- `}}),sn=(e,n)=>{const t=e.resolve(n);if(t.depth<=1)return;const o=t.posAtIndex(t.index(t.depth-1),t.depth-1);return ke(e.resolve(o))},Ve=(e,n)=>{const t=e.resolve(n),o=t.index();if(o===0)return;const r=t.posAtIndex(o-1);return ke(e.resolve(r))},rr=(e,n)=>{for(;n.childContainer;){const t=n.childContainer.node,o=e.resolve(n.childContainer.beforePos+1).posAtIndex(t.childCount-1);n=ke(e.resolve(o))}return n},sa=(e,n)=>e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*"&&e.blockContent.node.childCount>0&&n.isBlockContainer&&n.blockContent.node.type.spec.content==="inline*",ia=(e,n,t,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const r=e.doc.resolve(o.childContainer.beforePos+1),s=e.doc.resolve(o.childContainer.afterPos-1),i=r.blockRange(s);if(n){const a=e.doc.resolve(o.bnBlock.beforePos);e.tr.lift(i,a.depth)}}if(n){if(!t.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`);n(e.tr.delete(t.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0},an=e=>({state:n,dispatch:t})=>{const o=n.doc.resolve(e),r=ke(o),s=Ve(n.doc,r.bnBlock.beforePos);if(!s)return!1;const i=rr(n.doc,s);return sa(i,r)?ia(n,t,i,r):!1},aa=y.Extension.create({priority:50,addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({chain:o,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const a=s.selection.from===i.blockContent.beforePos+1,l=i.blockContent.node.type.name==="paragraph";return a&&!l?r.command(U(i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const{blockContent:a}=i;return s.selection.from===a.beforePos+1?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=i,c=s.selection.from===l.beforePos+1,d=s.selection.empty,u=a.beforePos;return c&&d?o().command(an(u)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const a=B(s);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1)||Ve(s.doc,a.bnBlock.beforePos))return!1;const d=sn(s.doc,a.bnBlock.beforePos);if((d==null?void 0:d.blockNoteType)!=="column")return!1;const u=d,h=sn(s.doc,u.bnBlock.beforePos);if((h==null?void 0:h.blockNoteType)!=="columnList")throw new Error("parent of column is not a column list");const f=u.childContainer.node.childCount===1,m=f&&h.childContainer.node.childCount===2,g=h.childContainer.node.firstChild===u.bnBlock.node;if(i){const b=s.doc.slice(a.bnBlock.beforePos,a.bnBlock.afterPos,!1);if(m)if(g){s.tr.step(new he.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,u.bnBlock.afterPos+1,h.bnBlock.afterPos-2,b,b.size,!1));const k=s.tr.doc.resolve(u.bnBlock.beforePos);s.tr.setSelection(C.TextSelection.between(k,k))}else{s.tr.step(new he.ReplaceAroundStep(h.bnBlock.beforePos,h.bnBlock.afterPos,h.bnBlock.beforePos+2,u.bnBlock.beforePos-1,b,0,!1));const k=s.tr.doc.resolve(s.tr.mapping.map(u.bnBlock.beforePos-1));s.tr.setSelection(C.TextSelection.between(k,k))}else if(f)if(g){s.tr.delete(u.bnBlock.beforePos,u.bnBlock.afterPos),s.tr.insert(h.bnBlock.beforePos,b.content);const k=s.tr.doc.resolve(h.bnBlock.beforePos);s.tr.setSelection(C.TextSelection.between(k,k))}else s.tr.delete(u.bnBlock.beforePos-1,u.bnBlock.beforePos+1);else{s.tr.delete(a.bnBlock.beforePos,a.bnBlock.afterPos),g?s.tr.insert(h.bnBlock.beforePos-1,b.content):s.tr.insert(u.bnBlock.beforePos-1,b.content);const k=s.tr.doc.resolve(u.bnBlock.beforePos-1);s.tr.setSelection(C.TextSelection.between(k,k))}}return!0}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=Ve(s.doc,i.bnBlock.beforePos);if(!l||!l.isBlockContainer)return!1;let c=o();if(l.blockContent.node.type.spec.content==="tableRow+"){const m=i.bnBlock.beforePos-1-1-1-1-1;c=c.setTextSelection(m)}else if(l.blockContent.node.type.spec.content===""){const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setNodeSelection(d)}else{const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setTextSelection(d)}return c.deleteRange({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:s})=>{const i=B(s);if(!i.isBlockContainer)throw new Error("todo");const a=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,c=Ve(s.doc,i.bnBlock.beforePos);if(c&&a&&l){const d=rr(s.doc,c);if(!d.isBlockContainer)throw new Error("todo");if(d.blockContent.node.type.spec.content===""||d.blockContent.node.type.spec.content==="inline*"&&d.blockContent.node.childCount===0)return o().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},d.bnBlock.afterPos).deleteRange({from:d.bnBlock.beforePos,to:d.bnBlock.afterPos}).run()}return!1})]),n=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:r})=>{const s=B(r);if(!s.isBlockContainer)return!1;const{bnBlock:i,blockContent:a,childContainer:l}=s,{depth:c}=r.doc.resolve(i.beforePos),d=i.afterPos===r.doc.nodeSize-3,u=r.selection.from===a.afterPos-1,h=r.selection.empty;if(!d&&u&&h&&!(l!==void 0)){let m=c,g=i.afterPos+1,b=r.doc.resolve(g).depth;for(;b<m;)m=b,g+=2,b=r.doc.resolve(g).depth;return o.command(an(g-1))}return!1})]),t=(o=!1)=>this.editor.commands.first(({commands:r,tr:s})=>[()=>r.command(({state:i})=>{const a=B(i);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:c}=a,{depth:d}=i.doc.resolve(l.beforePos),u=i.selection.$anchor.parentOffset===0,h=i.selection.anchor===i.selection.head,f=c.node.childCount===0,m=d>1;return u&&h&&f&&m?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:i})=>{const a=B(i),l=this.options.editor.schema.blockSchema[a.blockNoteType].hardBreakShortcut??"shift+enter";if(l==="none")return!1;if(l==="shift+enter"&&o||l==="enter"){const c=s.storedMarks||s.selection.$head.marks().filter(d=>this.editor.extensionManager.splittableMarks.includes(d.type.name));return s.insert(s.selection.head,s.doc.type.schema.nodes.hardBreak.create()).ensureMarks(c),!0}return!1}),()=>r.command(({state:i,dispatch:a})=>{const l=B(i);if(!l.isBlockContainer)return!1;const{bnBlock:c,blockContent:d}=l,u=i.selection.$anchor.parentOffset===0,h=i.selection.anchor===i.selection.head,f=d.node.childCount===0;if(u&&h&&f){const m=c.afterPos,g=m+2;if(a){const b=i.schema.nodes.blockContainer.createAndFill();i.tr.insert(m,b).scrollIntoView(),i.tr.setSelection(new C.TextSelection(i.doc.resolve(g)))}return!0}return!1}),()=>r.command(({state:i,chain:a})=>{const l=B(i);if(!l.isBlockContainer)return!1;const{blockContent:c}=l,d=i.selection.$anchor.parentOffset===0;return c.node.childCount===0?!1:(a().deleteSelection().command(go(i.selection.from,d,d)).run(),!0)})]);return{Backspace:e,Delete:n,Enter:()=>t(),"Shift-Enter":()=>t(!0),Tab:()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:Fo(this.options.editor)},"Shift-Tab":()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:(this.editor.commands.liftListItem("blockContainer"),!0)},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}});class la{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredLinkMark");p(this,"mouseHoveredLinkMarkRange");p(this,"keyboardHoveredLinkMark");p(this,"keyboardHoveredLinkMarkRange");p(this,"linkMark");p(this,"linkMarkRange");p(this,"mouseOverHandler",n=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),n.target instanceof HTMLAnchorElement&&n.target.nodeName==="A"){const t=n.target,o=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(o),s=r.marks();for(const i of s)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=i,this.mouseHoveredLinkMarkRange=y.getMarkRange(r,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",n=>{var o;const t=this.pmView.dom.parentElement;this.linkMark&&n&&n.target&&!(t===n.target||t.contains(n.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});p(this,"scrollHandler",()=>{var n;this.linkMark!==void 0&&(n=this.state)!=null&&n.show&&(this.state.referencePos=y.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});p(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(n,t){var o;this.editor.transact(r=>{const s=R(r);r.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to),r.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,s.mark("link",{href:n}))}),this.pmView.focus(),(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var n;this.editor.transact(t=>t.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())}update(n,t,o=!1){var a;const{state:r}=n;if(t&&t.selection.from===r.selection.from&&t.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=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 l=this.pmView.state.selection.$from.marks();for(const c of l)if(c.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=c,this.keyboardHoveredLinkMarkRange=y.getMarkRange(this.pmView.state.selection.$from,c.type,c.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&o&&(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:y.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((a=this.state)!=null&&a.show&&i&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const sr=new C.PluginKey("LinkToolbarPlugin");class ir extends O{constructor(t){super();p(this,"view");p(this,"editLink",(t,o)=>{this.view.editLink(t,o)});p(this,"deleteLink",()=>{this.view.deleteLink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});p(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new C.Plugin({key:sr,view:o=>(this.view=new la(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}}))}static key(){return"linkToolbar"}onUpdate(t){return this.on("update",t)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}const ar=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],lr="https",ca=new C.PluginKey("node-selection-keyboard");class da extends O{static key(){return"nodeSelectionKeyboard"}constructor(){super(),this.addProsemirrorPlugin(new C.Plugin({key:ca,props:{handleKeyDown:(n,t)=>{if("node"in n.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(t.key.length===1)return t.preventDefault(),!0;if(t.key==="Enter"&&!t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey){const o=n.state.tr;return n.dispatch(o.insert(n.state.tr.selection.$to.after(),n.state.schema.nodes.paragraph.createChecked()).setSelection(new C.TextSelection(o.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}}))}}const ua=new C.PluginKey("blocknote-placeholder");class pa extends O{static key(){return"placeholder"}constructor(n,t){super(),this.addProsemirrorPlugin(new C.Plugin({key:ua,view:o=>{var c,d;const r=`placeholder-selector-${fn.v4()}`;o.dom.classList.add(r);const s=document.createElement("style"),i=n._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),((c=n.prosemirrorView)==null?void 0:c.root)instanceof ShadowRoot?n.prosemirrorView.root.append(s):(d=n.prosemirrorView)==null||d.root.head.appendChild(s);const a=s.sheet,l=(u="")=>`.${r} .bn-block-content${u} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:u,emptyDocument:h,...f}=t;for(const[b,k]of Object.entries(f)){const w=`[data-content-type="${b}"]`;a.insertRule(`${l(w)} { content: ${JSON.stringify(k)}; }`)}const m="[data-is-only-empty-block]",g="[data-is-empty-and-focused]";a.insertRule(`${l(m)} { content: ${JSON.stringify(h)}; }`),a.insertRule(`${l(g)} { content: ${JSON.stringify(u)}; }`)}catch(u){console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)",u)}return{destroy:()=>{var u,h;((u=n.prosemirrorView)==null?void 0:u.root)instanceof ShadowRoot?n.prosemirrorView.root.removeChild(s):(h=n.prosemirrorView)==null||h.root.head.removeChild(s)}}},props:{decorations:o=>{const{doc:r,selection:s}=o;if(!n.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];o.doc.content.size===6&&i.push(H.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const a=s.$anchor,l=a.parent;if(l.content.size===0){const c=a.before();i.push(H.Decoration.node(c,c+l.nodeSize,{"data-is-empty-and-focused":"true"}))}return H.DecorationSet.create(r,i)}}}))}}const ln=new C.PluginKey("previous-blocks"),ha={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class fa extends O{static key(){return"previousBlockType"}constructor(){super();let n;this.addProsemirrorPlugin(new C.Plugin({key:ln,view(t){return{update:async(o,r)=>{var s;((s=this.key)==null?void 0:s.getState(o.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{o.dispatch(o.state.tr.setMeta(ln,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,o,r,s){if(o.currentTransactionOldBlockAttrs={},o.updatedBlocks.clear(),!t.docChanged||r.doc.eq(s.doc))return o;const i={},a=y.findChildren(r.doc,d=>d.attrs.id),l=new Map(a.map(d=>[d.node.attrs.id,d])),c=y.findChildren(s.doc,d=>d.attrs.id);for(const d of c){const u=l.get(d.node.attrs.id),h=u==null?void 0:u.node.firstChild,f=d.node.firstChild;if(u&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:s.doc.resolve(d.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:r.doc.resolve(u.pos).depth};i[d.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in o.prevTransactionOldBlockAttrs&&(g=o.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),o.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,o.updatedBlocks.add(d.node.attrs.id))}}return o.prevTransactionOldBlockAttrs=i,o}},props:{decorations(t){const o=this.getState(t);if(o.updatedBlocks.size===0)return;const r=[];return t.doc.descendants((s,i)=>{if(!s.attrs.id||!o.updatedBlocks.has(s.attrs.id))return;const a=o.currentTransactionOldBlockAttrs[s.attrs.id],l={};for(const[d,u]of Object.entries(a))l["data-prev-"+ha[d]]=u||"none";const c=H.Decoration.node(i,i+s.nodeSize,{...l});r.push(c)}),H.DecorationSet.create(t.doc,r)}}}))}}const cn=new C.PluginKey("blocknote-show-selection");class ma extends O{constructor(t){super();p(this,"enabled",!1);this.editor=t,this.addProsemirrorPlugin(new C.Plugin({key:cn,props:{decorations:o=>{const{doc:r,selection:s}=o;if(!this.enabled)return H.DecorationSet.empty;const i=H.Decoration.inline(s.from,s.to,{"data-show-selection":"true"});return H.DecorationSet.create(r,[i])}}}))}static key(){return"showSelection"}setEnabled(t){this.enabled!==t&&(this.enabled=t,this.editor.transact(o=>o.setMeta(cn,{})))}getEnabled(){return this.enabled}}function cr(e,n){var t,o;for(;e&&e.parentElement&&e.parentElement!==n.dom&&((t=e.getAttribute)==null?void 0:t.call(e,"data-node-type"))!=="blockContainer";)e=e.parentElement;if(((o=e.getAttribute)==null?void 0:o.call(e,"data-node-type"))==="blockContainer")return{node:e,id:e.getAttribute("data-id")}}class ae extends C.Selection{constructor(t,o){super(t,o);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(t,o,r=o){return new ae(t.resolve(o),t.resolve(r))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof ae)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){const r=o.mapResult(this.from),s=o.mapResult(this.to);return s.deleted?C.Selection.near(t.resolve(r.pos)):r.deleted?C.Selection.near(t.resolve(s.pos)):new ae(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}C.Selection.jsonID("multiple-node",ae);let Y;function ga(e,n){let t,o;const r=n.resolve(e.from).node().type.spec.group==="blockContent",s=n.resolve(e.to).node().type.spec.group==="blockContent",i=Math.min(e.$anchor.depth,e.$head.depth);if(r&&s){const a=e.$from.start(i-1),l=e.$to.end(i-1);t=n.resolve(a-1).pos,o=n.resolve(l+1).pos}else t=e.from,o=e.to;return{from:t,to:o}}function dn(e,n,t=n){n===t&&(t+=e.state.doc.resolve(n+1).node().nodeSize);const o=e.domAtPos(n).node.cloneNode(!0),r=e.domAtPos(n).node,s=(u,h)=>Array.prototype.indexOf.call(u.children,h),i=s(r,e.domAtPos(n+1).node.parentElement),a=s(r,e.domAtPos(t-1).node.parentElement);for(let u=r.childElementCount-1;u>=0;u--)(u>a||u<i)&&o.removeChild(o.children[u]);dr(e.root),Y=o;const l=Y.getElementsByTagName("iframe");for(let u=0;u<l.length;u++){const h=l[u],f=h.parentElement;f&&f.removeChild(h)}const d=e.dom.className.split(" ").filter(u=>u!=="ProseMirror"&&u!=="bn-root"&&u!=="bn-editor").join(" ");Y.className=Y.className+" bn-drag-preview "+d,e.root instanceof ShadowRoot?e.root.appendChild(Y):e.root.body.appendChild(Y)}function dr(e){Y!==void 0&&(e instanceof ShadowRoot?e.removeChild(Y):e.body.removeChild(Y),Y=void 0)}function ba(e,n,t){if(!e.dataTransfer)return;const o=t.prosemirrorView;if(!o)return;const r=z(n.id,o.state.doc);if(!r)throw new Error(`Block with ID ${n.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=o.state.selection,a=o.state.doc,{from:l,to:c}=ga(i,a),d=l<=s&&s<c,u=i.$anchor.node()!==i.$head.node()||i instanceof ae;d&&u?(o.dispatch(o.state.tr.setSelection(ae.create(a,l,c))),dn(o,l,c)):(o.dispatch(o.state.tr.setSelection(C.NodeSelection.create(o.state.doc,s))),dn(o,s));const h=o.state.selection.content(),f=t.pmSchema,m=o.serializeForClipboard(h).dom.innerHTML,g=Me(f,t),b=Xo(h.content),k=g.exportBlocks(b,{}),w=nt(k);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",m),e.dataTransfer.setData("text/html",k),e.dataTransfer.setData("text/plain",w),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(Y,0,0)}}const un=250;function vt(e,n,t=!0){const o=e.root.elementsFromPoint(n.left,n.top);for(const r of o)if(e.dom.contains(r))return t&&r.closest("[data-node-type=columnList]")?vt(e,{left:n.left+50,top:n.top},!1):cr(r,e)}function ka(e,n){if(!n.dom.firstChild)return;const t=n.dom.firstChild.getBoundingClientRect(),o={left:Math.min(Math.max(t.left+10,e.x),t.right-10),top:e.y},r=vt(n,o);if(!r)return;const s=r.node.getBoundingClientRect();return vt(n,{left:s.right-10,top:e.y},!1)}class ur{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"mousePos");p(this,"hoveredBlock");p(this,"menuFrozen",!1);p(this,"isDragOrigin",!1);p(this,"updateState",n=>{this.state=n,this.emitUpdate(this.state)});p(this,"updateStateFromMousePos",()=>{var o,r,s,i,a;if(this.menuFrozen||!this.mousePos)return;const n=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((n==null?void 0:n.element)!==this.pmView.dom||n.distance>un){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}const t=ka(this.mousePos,this.pmView);if(!t||!this.editor.isEditable){(r=this.state)!=null&&r.show&&(this.state.show=!1,this.updateState(this.state));return}if(!((s=this.state)!=null&&s.show&&((i=this.hoveredBlock)!=null&&i.hasAttribute("data-id"))&&((a=this.hoveredBlock)==null?void 0:a.getAttribute("data-id"))===t.id)&&(this.hoveredBlock=t.node,this.editor.isEditable)){const l=t.node.getBoundingClientRect(),c=t.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(c?c.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,l.y,l.width,l.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}});p(this,"onDragStart",n=>{var i;const t=(i=n.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!t||this.pmView.dragging)return;const o=document.createElement("div");o.innerHTML=t;const s=S.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new S.Slice(s.content,0,0),move:!0}});p(this,"findClosestEditorElement",n=>{const t=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(t.length===0)return null;let o=t[0],r=Number.MAX_VALUE;return t.forEach(s=>{const i=s.querySelector(".bn-block-group").getBoundingClientRect(),a=n.clientX<i.left?i.left-n.clientX:n.clientX>i.right?n.clientX-i.right:0,l=n.clientY<i.top?i.top-n.clientY:n.clientY>i.bottom?n.clientY-i.bottom:0,c=Math.sqrt(Math.pow(a,2)+Math.pow(l,2));c<r&&(r=c,o=s)}),{element:o,distance:r}});p(this,"onDragOver",n=>{if(n.synthetic)return;const t=this.getDragEventContext(n);if(!t||!t.isDropPoint){this.closeDropCursor();return}t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(n)});p(this,"closeDropCursor",()=>{const n=new Event("dragleave",{bubbles:!1});n.synthetic=!0,this.pmView.dom.dispatchEvent(n)});p(this,"getDragEventContext",n=>{var l;const t=!((l=n.dataTransfer)!=null&&l.types.includes("blocknote/html"))&&!!this.pmView.dragging,o=!!this.isDragOrigin,r=t||o,s=this.findClosestEditorElement(n);if(!s||s.distance>un)return;const i=s.element===this.pmView.dom,a=i&&s.distance===0;if(!(!i&&!r))return{isDropPoint:i,isDropWithinEditorBounds:a,isDragOrigin:r}});p(this,"onDrop",n=>{if(n.synthetic)return;const t=this.getDragEventContext(n);if(!t){this.closeDropCursor();return}const{isDropPoint:o,isDropWithinEditorBounds:r,isDragOrigin:s}=t;if(!r&&o&&this.dispatchSyntheticEvent(n),o){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(C.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)));return}else if(s){setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0);return}});p(this,"onDragEnd",n=>{n.synthetic||(this.pmView.dragging=null)});p(this,"onKeyDown",n=>{var t;(t=this.state)!=null&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});p(this,"onMouseMove",n=>{var s;if(this.menuFrozen)return;this.mousePos={x:n.clientX,y:n.clientY};const t=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom,r=this.pmView.dom.parentElement;if(o&&n&&n.target&&!(r===n.target||r.contains(n.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});p(this,"onScroll",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state)),this.updateStateFromMousePos()});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),Ae(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),t.root.addEventListener("scroll",this.onScroll,!0)}dispatchSyntheticEvent(n){const t=new Event(n.type,n),o=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=n.clientX,t.clientY=n.clientY,t.clientX=Math.min(Math.max(n.clientX,o.left),o.left+o.width),t.clientY=Math.min(Math.max(n.clientY,o.top),o.top+o.height),t.dataTransfer=n.dataTransfer,t.preventDefault=()=>n.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(n,t){var r;!t.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const pr=new C.PluginKey("SideMenuPlugin");class hr extends O{constructor(t){super();p(this,"view");p(this,"blockDragStart",(t,o)=>{this.view&&(this.view.isDragOrigin=!0),ba(t,o,this.editor)});p(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&dr(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)});p(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)});p(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=t,this.addProsemirrorPlugin(new C.Plugin({key:pr,view:o=>(this.view=new ur(t,o,r=>{this.emit("update",r)}),this.view)}))}static key(){return"sideMenu"}onUpdate(t){return this.on("update",t)}}const He=new Map;function ya(e){if(He.has(e))return He.get(e);const n=new he.Mapping;return e._tiptapEditor.on("transaction",({transaction:t})=>{n.appendMapping(t.mapping)}),e._tiptapEditor.on("destroy",()=>{He.delete(e)}),He.set(e,n),n}function fr(e,n,t="left"){const o=D.ySyncPluginKey.getState(e._tiptapEditor.state);if(!o){const s=ya(e),i=s.maps.length;return()=>s.slice(i).map(n,t==="left"?-1:1)}const r=D.absolutePositionToRelativePosition(n+(t==="right"?1:0),o.binding.type,o.binding.mapping);return()=>{const s=D.ySyncPluginKey.getState(e._tiptapEditor.state),i=D.relativePositionToAbsolutePosition(s.doc,s.binding.type,r,s.binding.mapping);if(i===null)throw new Error("Position not found, cannot track positions");return i+(t==="right"?-1:0)}}const wa=y.findParentNode(e=>e.type.name==="blockContainer");class Ca{constructor(n,t){p(this,"state");p(this,"emitUpdate");p(this,"rootEl");p(this,"pluginState");p(this,"handleScroll",()=>{var n,t;if((n=this.state)!=null&&n.show){const o=(t=this.rootEl)==null?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!o)return;this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});p(this,"closeMenu",()=>{this.editor.transact(n=>n.setMeta(pe,null))});p(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(n=>n.selection.from)}).run()});var o,r;this.editor=n,this.pluginState=void 0,this.emitUpdate=s=>{var i;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(s,{...this.state,ignoreQueryLength:(i=this.pluginState)==null?void 0:i.ignoreQueryLength})},this.rootEl=(o=this.editor.prosemirrorView)==null?void 0:o.root,(r=this.rootEl)==null||r.addEventListener("scroll",this.handleScroll,!0)}update(n,t){var c;const o=pe.getState(t),r=pe.getState(n.state),s=o===void 0&&r!==void 0,i=o!==void 0&&r===void 0;if(!s&&!(o!==void 0&&r!==void 0)&&!i)return;if(this.pluginState=i?o:r,i||!this.editor.isEditable){this.state&&(this.state.show=!1),this.emitUpdate(this.pluginState.triggerCharacter);return}const l=(c=this.rootEl)==null?void 0:c.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&l&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var n;(n=this.rootEl)==null||n.removeEventListener("scroll",this.handleScroll,!0)}}const pe=new C.PluginKey("SuggestionMenuPlugin");class mr extends O{constructor(t){super();p(this,"view");p(this,"triggerCharacters",[]);p(this,"addTriggerCharacter",t=>{this.triggerCharacters.push(t)});p(this,"removeTriggerCharacter",t=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==t)});p(this,"closeMenu",()=>this.view.closeMenu());p(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.addProsemirrorPlugin(new C.Plugin({key:pe,view:()=>(this.view=new Ca(t,(r,s)=>{this.emit(`update ${r}`,s)}),this.view),state:{init(){},apply:(r,s,i,a)=>{if(r.getMeta("orderedListIndexing")!==void 0||r.selection.$from.parent.type.spec.code)return s;const l=r.getMeta(pe);if(typeof l=="object"&&l!==null){s&&this.closeMenu();const d=fr(t,a.selection.from-l.triggerCharacter.length);return{triggerCharacter:l.triggerCharacter,deleteTriggerCharacter:l.deleteTriggerCharacter!==!1,queryStartPos:()=>d()+l.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`,ignoreQueryLength:l==null?void 0:l.ignoreQueryLength}}if(s===void 0)return s;if(a.selection.from!==a.selection.to||l===null||r.getMeta("focus")||r.getMeta("blur")||r.getMeta("pointer")||s.triggerCharacter!==void 0&&a.selection.from<s.queryStartPos()||!a.selection.$from.sameParent(a.doc.resolve(s.queryStartPos())))return;const c={...s};return c.query=a.doc.textBetween(s.queryStartPos(),a.selection.from),c}},props:{handleTextInput(r,s,i,a){if(s===i){const l=r.state.doc;for(const c of o){const d=c.length>1?l.textBetween(s-c.length,s)+a:a;if(c===d)return r.dispatch(r.state.tr.insertText(a)),r.dispatch(r.state.tr.setMeta(pe,{triggerCharacter:d}).scrollIntoView()),!0}}return!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=wa(r.selection);if(i)return H.DecorationSet.create(r.doc,[H.Decoration.node(i.pos,i.pos+i.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}return H.DecorationSet.create(r.doc,[H.Decoration.inline(s.queryStartPos()-s.triggerCharacter.length,s.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}}}))}static key(){return"suggestionMenu"}onUpdate(t,o){return this.triggerCharacters.includes(t)||this.addTriggerCharacter(t),this.on(`update ${t}`,o)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}function va(e,n){e.suggestionMenus.addTriggerCharacter(n)}const Sa=y.Mark.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(e){return e.name!=="insertion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(n,t){return["ins",{"data-id":String(n.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0]},parseDOM:[{tag:"ins",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10)}:!1}}]}}}),Ea=y.Mark.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(e){return e.name!=="deletion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(n,t){return["del",{"data-id":String(n.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0]},parseDOM:[{tag:"del",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10)}:!1}}]}}}),Ba=y.Mark.create({name:"modification",inclusive:!1,excludes:"deletion insertion",addAttributes(){return{id:{default:null,validate:"number"},type:{validate:"string"},attrName:{default:null,validate:"string|null"},previousValue:{default:null},newValue:{default:null}}},extendMarkSchema(e){return e.name!=="modification"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(n,t){return[t?"span":"div",{"data-type":"modification","data-id":String(n.attrs.id),"data-mod-type":n.attrs.type,"data-mod-prev-val":JSON.stringify(n.attrs.previousValue),"data-mod-new-val":JSON.stringify(n.attrs.newValue)},0]},parseDOM:[{tag:"span[data-type='modification']",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10),type:n.dataset.modType,previousValue:n.dataset.modPrevVal,newValue:n.dataset.modNewVal}:!1}},{tag:"div[data-type='modification']",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10),type:n.dataset.modType,previousValue:n.dataset.modPrevVal}:!1}}]}}});let F;function pn(e){F||(F=document.createElement("div"),F.innerHTML="_",F.style.opacity="0",F.style.height="1px",F.style.width="1px",e instanceof Document?e.body.appendChild(F):e.appendChild(F))}function Ta(e){F&&(e instanceof Document?e.body.removeChild(F):e.removeChild(F),F=void 0)}function Oe(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function xa(e){let n=e;for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH"&&!n.classList.contains("tableWrapper");){if(n.classList.contains("ProseMirror"))return;const t=n.parentNode;if(!t||!(t instanceof Element))return;n=t}return n.nodeName==="TD"||n.nodeName==="TH"?{type:"cell",domNode:n,tbodyNode:n.closest("tbody")}:{type:"wrapper",domNode:n,tbodyNode:n.querySelector("tbody")}}function Pa(e,n){const t=n.querySelectorAll(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class gr{constructor(n,t,o){p(this,"state");p(this,"emitUpdate");p(this,"tableId");p(this,"tablePos");p(this,"tableElement");p(this,"menuFrozen",!1);p(this,"mouseState","up");p(this,"prevWasEditable",null);p(this,"viewMousedownHandler",()=>{this.mouseState="down"});p(this,"mouseUpHandler",n=>{this.mouseState="up",this.mouseMoveHandler(n)});p(this,"mouseMoveHandler",n=>{var c,d,u,h,f,m,g;if(this.menuFrozen||this.mouseState==="selecting"||!(n.target instanceof Element)||!this.pmView.dom.contains(n.target))return;const t=xa(n.target);if((t==null?void 0:t.type)==="cell"&&this.mouseState==="down"&&!((c=this.state)!=null&&c.draggingState)){this.mouseState="selecting",(d=this.state)!=null&&d.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t||!this.editor.isEditable){(u=this.state)!=null&&u.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t.tbodyNode)return;const o=t.tbodyNode.getBoundingClientRect(),r=cr(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(b=>z(r.id,b.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=T(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(Mo("table",a,this.editor)&&(this.tablePos=i.posBeforeNode+1,s=a),!s)return;this.tableId=r.id;const l=(h=t.domNode.closest(".tableWrapper"))==null?void 0:h.querySelector(".table-widgets-container");if((t==null?void 0:t.type)==="wrapper"){const b=n.clientY>=o.bottom-1&&n.clientY<o.bottom+20,k=n.clientX>=o.right-1&&n.clientX<o.right+20,w=n.clientX>o.right||n.clientY>o.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:b,showAddOrRemoveColumnsButton:k,referencePosTable:o,block:s,widgetContainer:l,colIndex:w||(f=this.state)==null?void 0:f.colIndex,rowIndex:w||(m=this.state)==null?void 0:m.rowIndex,referencePosCell:w||(g=this.state)==null?void 0:g.referencePosCell}}else{const b=Oe(t.domNode),k=Oe(t.domNode.parentElement),w=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===k&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:k===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:w,colIndex:b,rowIndex:k,widgetContainer:l}}return this.emitUpdate(),!1});p(this,"dragOverHandler",n=>{var h;if(((h=this.state)==null?void 0:h.draggingState)===void 0)return;n.preventDefault(),n.dataTransfer.dropEffect="move",Pa(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const t={left:Math.min(Math.max(n.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(n.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(t.left,t.top).filter(f=>f.tagName==="TD"||f.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=Oe(r.parentElement),a=Oe(r),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,d=(this.state.draggingState.draggedCellOrientation==="row"?i:a)!==l;(this.state.rowIndex!==i||this.state.colIndex!==a)&&(this.state.rowIndex=i,this.state.colIndex=a,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const u=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==u&&(this.state.draggingState.mousePos=u,s=!0),s&&this.emitUpdate(),d&&this.editor.transact(f=>f.setMeta(de,!0))});p(this,"dropHandler",n=>{if(this.mouseState="up",this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");n.preventDefault();const{draggingState:t,colIndex:o,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(t.draggedCellOrientation==="row"){if(!In(this.state.block,t.originalIndex,r))return!1;const i=ns(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!Ln(this.state.block,t.originalIndex,o))return!1;const i=ts(this.state.block,t.originalIndex,o),[a]=s.splice(t.originalIndex,1);s.splice(o,0,a),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:s,rows:i}})}return this.editor.setTextCursorPosition(this.state.block.id),!0});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),t.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),t.root.addEventListener("dragover",this.dragOverHandler),t.root.addEventListener("drop",this.dropHandler)}update(){var r;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||this.state.block.type!=="table"||!((r=this.tableElement)!=null&&r.isConnected)){this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate();return}const{height:n,width:t}=Lt(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=n&&(this.state.rowIndex=n-1),this.state.colIndex>=t&&(this.state.colIndex=t-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(this.state.rowIndex!==void 0&&this.state.colIndex!==void 0){const i=o.children[this.state.rowIndex].children[this.state.colIndex];i?this.state.referencePosCell=i.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const de=new C.PluginKey("TableHandlesPlugin");class br extends O{constructor(t){super();p(this,"view");p(this,"colDragStart",t=>{if(this.view.state===void 0||this.view.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:t.clientX},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(de,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");pn(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(F,0,0),t.dataTransfer.effectAllowed="move"});p(this,"rowDragStart",t=>{if(this.view.state===void 0||this.view.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:t.clientY},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(de,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");pn(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(F,0,0),t.dataTransfer.effectAllowed="copyMove"});p(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(t=>t.setMeta(de,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");Ta(this.editor.prosemirrorView.root)});p(this,"freezeHandles",()=>{this.view.menuFrozen=!0});p(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});p(this,"getCellsAtRowHandle",(t,o)=>ut(t,o));p(this,"getCellsAtColumnHandle",(t,o)=>pt(t,o));p(this,"setCellSelection",(t,o,r=o)=>{const s=this.view;if(!s)throw new Error("Table handles view not initialized");const i=t.doc.resolve(s.tablePos+1),a=t.doc.resolve(i.posAtIndex(o.row)+1),l=t.doc.resolve(a.posAtIndex(o.col)),c=t.doc.resolve(i.posAtIndex(r.row)+1),d=t.doc.resolve(c.posAtIndex(r.col)),u=t.tr;return u.setSelection(new I.CellSelection(l,d)),t.apply(u)});p(this,"addRowOrColumn",(t,o)=>{this.editor.exec((r,s)=>{const i=this.setCellSelection(r,o.orientation==="row"?{row:t,col:0}:{row:0,col:t});return o.orientation==="row"?o.side==="above"?I.addRowBefore(i,s):I.addRowAfter(i,s):o.side==="left"?I.addColumnBefore(i,s):I.addColumnAfter(i,s)})});p(this,"removeRowOrColumn",(t,o)=>o==="row"?this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:t,col:0});return I.deleteRow(i,s)}):this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:0,col:t});return I.deleteColumn(i,s)}));p(this,"mergeCells",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t.relativeStartCell,t.relativeEndCell):o;return I.mergeCells(s,r)}));p(this,"splitCell",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t):o;return I.splitCell(s,r)}));p(this,"getCellSelection",()=>this.editor.transact(t=>{const o=t.selection;let r=o.$from,s=o.$to;if(kt(o)){const{ranges:m}=o;m.forEach(g=>{r=g.$from.min(r??g.$from),s=g.$to.max(s??g.$to)})}else if(r=t.doc.resolve(o.$from.pos-o.$from.parentOffset-1),s=t.doc.resolve(o.$to.pos-o.$to.parentOffset-1),r.pos===0||s.pos===0)return;const i=t.doc.resolve(r.pos-r.parentOffset-1),a=t.doc.resolve(s.pos-s.parentOffset-1),l=t.doc.resolve(i.pos-i.parentOffset-1),c=r.index(i.depth),d=i.index(l.depth),u=s.index(a.depth),h=a.index(l.depth),f=[];for(let m=d;m<=h;m++)for(let g=c;g<=u;g++)f.push({row:m,col:g});return{from:{row:d,col:c},to:{row:h,col:u},cells:f}}));p(this,"getMergeDirection",t=>this.editor.transact(o=>{const r=kt(o.selection)?o.selection:void 0;if(!r||!t||r.ranges.length<=1)return;const s=this.getCellSelection();if(s)return ss(s.from,s.to,t)?"vertical":"horizontal"}));p(this,"cropEmptyRowsOrColumns",(t,o)=>os(t,o));p(this,"addRowsOrColumns",(t,o,r)=>rs(t,o,r));this.editor=t,this.addProsemirrorPlugin(new C.Plugin({key:de,view:o=>(this.view=new gr(t,o,r=>{this.emit("update",r)}),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 r=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:a}=this.view.state,{originalIndex:l,draggedCellOrientation:c}=a;if(r===l||!i||c==="row"&&!In(i,l,r)||c==="col"&&!Ln(i,l,r))return H.DecorationSet.create(o.doc,s);const d=o.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?ut(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=o.doc.resolve(d.posAtIndex(h)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),k=g.pos+(r>l?b.nodeSize-2:0);s.push(H.Decoration.widget(k,()=>{const w=document.createElement("div");return w.className="bn-table-drop-cursor",w.style.left="0",w.style.right="0",r>l?w.style.bottom="-2px":w.style.top="-3px",w.style.height="4px",w}))}):pt(this.view.state.block,r).forEach(({row:h,col:f})=>{const m=o.doc.resolve(d.posAtIndex(h)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),k=g.pos+(r>l?b.nodeSize-2:0);s.push(H.Decoration.widget(k,()=>{const w=document.createElement("div");return w.className="bn-table-drop-cursor",w.style.top="0",w.style.bottom="0",r>l?w.style.right="-2px":w.style.left="-3px",w.style.width="4px",w}))}),H.DecorationSet.create(o.doc,s)}}}))}static key(){return"tableHandles"}onUpdate(t){return this.on("update",t)}}const Ma=y.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem","tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>e.textAlignment==="left"?{}:{"data-text-alignment":e.textAlignment}}}}]}}),Ia=y.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{textColor:{default:L.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):L.textColor.default,renderHTML:e=>e.textColor===L.textColor.default?{}:{"data-text-color":e.textColor}}}}]}}),La=y.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new C.PluginKey(this.name);return[new C.Plugin({key:e,appendTransaction:(n,t,o)=>{const{doc:r,tr:s,schema:i}=o,a=e.getState(o),l=r.content.size-2,c=i.nodes.blockContainer,d=i.nodes.paragraph;if(a)return s.insert(l,c.create(void 0,d.create()))},state:{init:(n,t)=>{},apply:(n,t)=>{if(!n.docChanged)return t;let o=n.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")return!0;const r=o.firstChild;if(!r)throw new Error("Expected blockContent");return o.nodeSize>4||r.type.spec.content!=="inline*"}}})]}}),Aa={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Na=y.Node.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,marks:"insertion modification deletion",parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:e=>{if(typeof e=="string")return!1;const n={};for(const[t,o]of Object.entries(Aa))e.getAttribute(o)&&(n[t]=e.getAttribute(o));return n}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:e}){var r;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[s,i]of Object.entries(e))s!=="class"&&n.setAttribute(s,i);const t={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...e},o=document.createElement("div");o.className=Q("bn-block",t.class),o.setAttribute("data-node-type",this.name);for(const[s,i]of Object.entries(t))s!=="class"&&o.setAttribute(s,i);return n.appendChild(o),{dom:n,contentDOM:o}}}),Da=y.Node.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML(){return[{tag:"div",getAttrs:e=>typeof e=="string"?!1:e.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:e}){var o;const n={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...e},t=document.createElement("div");t.className=Q("bn-block-group",n.class),t.setAttribute("data-node-type","blockGroup");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);return{dom:t,contentDOM:t}}}),Ha=y.Node.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"});class Oa extends O{constructor({editor:t,collaboration:o}){super(t);p(this,"editor");p(this,"collaboration");p(this,"forkedState");this.editor=t,this.collaboration=o}static key(){return"ForkYDocPlugin"}findTypeInOtherYdoc(t,o){const r=t.doc;if(t._item===null){const s=Array.from(r.share.keys()).find(i=>r.share.get(i)===t);if(s==null)throw new Error("type does not exist in other ydoc");return o.get(s,t.constructor)}else{const s=t._item,i=o.store.clients.get(s.id.client)??[],a=ie.findIndexSS(i,s.id.clock);return i[a].content.type}}get isForkedFromRemote(){return this.forkedState!==void 0}fork(){var s;if(this.isForkedFromRemote)return;const t=(s=this.collaboration)==null?void 0:s.fragment;if(!t)throw new Error("No fragment to fork from");const o=new ie.Doc;ie.applyUpdate(o,ie.encodeStateAsUpdate(t.doc));const r=this.findTypeInOtherYdoc(t,o);this.forkedState={undoStack:D.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack,originalFragment:t,forkedFragment:r},this.editor._tiptapEditor.unregisterPlugin([D.yCursorPluginKey,D.yUndoPluginKey,D.ySyncPluginKey]),this.editor._tiptapEditor.registerPlugin(new wt(r).plugins[0]),this.editor._tiptapEditor.registerPlugin(new Ct({editor:this.editor}).plugins[0]),this.emit("forked",!0)}merge({keepChanges:t}){if(!this.forkedState)return;this.editor._tiptapEditor.unregisterPlugin(D.ySyncPluginKey),this.editor._tiptapEditor.unregisterPlugin(D.yUndoPluginKey);const{originalFragment:o,forkedFragment:r,undoStack:s}=this.forkedState;if(this.editor.extensions.ySyncPlugin=new wt(o),this.editor.extensions.yCursorPlugin=new ze(this.collaboration),this.editor.extensions.yUndoPlugin=new Ct({editor:this.editor}),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.ySyncPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yCursorPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yUndoPlugin.plugins[0]),D.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack=s,t){const i=ie.encodeStateAsUpdate(r.doc,ie.encodeStateVector(o.doc));ie.applyUpdate(o.doc,i,this.editor)}this.forkedState=void 0,this.emit("forked",!1)}}const kr=e=>{var r;const n={},t=Ra(e);for(const s of t)n[s.name]=s;e.collaboration&&(n.ySyncPlugin=new wt(e.collaboration.fragment),n.yUndoPlugin=new Ct({editor:e.editor}),(r=e.collaboration.provider)!=null&&r.awareness&&(n.yCursorPlugin=new ze(e.collaboration)),n.forkYDocPlugin=new Oa({editor:e.editor,collaboration:e.collaboration})),n.formattingToolbar=new or(e.editor),n.linkToolbar=new ir(e.editor),n.sideMenu=new hr(e.editor),n.suggestionMenus=new mr(e.editor),n.filePanel=new er(e.editor),n.placeholder=new pa(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new fa),e.tableHandles&&(n.tableHandles=new br(e.editor)),n.nodeSelectionKeyboard=new da,n.blockChange=new Qi,n.showSelection=new ma(e.editor),e.comments&&(n.comments=new oa(e.editor,e.comments.threadStore,Zo.name));const o=e.disableExtensions||[];for(const s of o)delete n[s];return n};let hn=!1;const Ra=e=>{const n=[y.extensions.ClipboardTextSerializer,y.extensions.Commands,y.extensions.Editable,y.extensions.FocusEvents,y.extensions.Tabindex,Hr.Gapcursor,y.Extension.create({name:"dropCursor",addProseMirrorPlugins:()=>[e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})]}),Be.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),ra,_r.Text,Sa,Ea,Ba,Rr.Link.extend({inclusive:!1}).configure({defaultProtocol:lr,protocols:hn?[]:ar}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),Ia,Zi,Ma,y.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),Ha,Na.configure({editor:e.editor,domAttributes:e.domAttributes}),aa.configure({editor:e.editor,tabBehavior:e.tabBehavior}),Da.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(t=>t.config!=="link"&&t.config!=="text").map(t=>t.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(t=>[...(t.implementation.requiredExtensions||[]).map(o=>o.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),Xi(e.editor),Yi(e.editor,e.pasteHandler||(t=>t.defaultPasteHandler())),Ai(e.editor),...e.trailingBlock===void 0||e.trailingBlock?[La]:[],...e.comments?[Zo]:[]];return hn=!0,e.collaboration||n.push(Or.History),n};function _a(e,n){const t=[];return e.forEach((o,r,s)=>{s!==n&&t.push(o)}),S.Fragment.from(t)}function Va(e,n){const t=[];for(let o=0;o<e.childCount;o++)if(e.child(o).type.name==="tableRow")if(t.length>0&&t[t.length-1].type.name==="table"){const r=t[t.length-1],s=r.copy(r.content.addToEnd(e.child(o)));t[t.length-1]=s}else{const r=n.nodes.table.createChecked(void 0,e.child(o));t.push(r)}else t.push(e.child(o));return e=S.Fragment.from(t),e}function Ua(e,n){let t=S.Fragment.from(e.content);if(t=Va(t,n.state.schema),!Fa(t,n))return new S.Slice(t,e.openStart,e.openEnd);for(let o=0;o<t.childCount;o++)if(t.child(o).type.spec.group==="blockContent"){const r=[t.child(o)];if(o+1<t.childCount&&t.child(o+1).type.name==="blockGroup"){const i=t.child(o+1).child(0).child(0);(i.type.name==="bulletListItem"||i.type.name==="numberedListItem"||i.type.name==="checkListItem")&&(r.push(t.child(o+1)),t=_a(t,o+1))}const s=n.state.schema.nodes.blockContainer.createChecked(void 0,r);t=t.replaceChild(o,s)}return new S.Slice(t,e.openStart,e.openEnd)}function Fa(e,n){var s,i;const t=e.childCount===1,o=((s=e.firstChild)==null?void 0:s.type.spec.content)==="inline*",r=((i=e.firstChild)==null?void 0:i.type.spec.content)==="tableRow+";if(t){if(o)return!1;if(r){const a=B(n.state);if(a.isBlockContainer)return!(a.blockContent.node.type.spec.content==="tableRow+")}}return!0}const qe=class qe extends y.Editor{constructor(t,o){super({...t,content:void 0});p(this,"_state");p(this,"mount",(t,o,r)=>{o?(this.options.element=o,this.createViewAlternative(t,r)):(this.destroy(),this.isInitialized=!1)});const r=this.schema;let s;const i=r.nodes.doc.createAndFill;r.nodes.doc.createAndFill=(...l)=>{if(s)return s;const c=i.apply(r.nodes.doc,l),d=JSON.parse(JSON.stringify(c.toJSON()));return d.content[0].content[0].attrs.id="initialBlockId",s=S.Node.fromJSON(r,d),s};let a;try{const l=t==null?void 0:t.content.map(c=>se(c,this.schema,o).toJSON());a=y.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(t.content))}this._state=C.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(t){if(!this.view){this._state=this.state.apply(t),this.emit("transaction",{editor:this,transaction:t});return}if(this.view.isDestroyed)return;if(this.isCapturingTransaction){this.dispatchTransaction(t);return}const{state:o,transactions:r}=this.state.applyTransaction(t),s=!this.state.selection.eq(o.selection);this.emit("beforeTransaction",{editor:this,transaction:t,nextState:o}),this.view.updateState(o),this.emit("transaction",{editor:this,transaction:t}),s&&this.emit("selectionUpdate",{editor:this,transaction:t});const i=t.getMeta("focus"),a=t.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:t}),a&&this.emit("blur",{editor:this,event:a.event,transaction:t}),!(!t.docChanged||t.getMeta("preventUpdate"))&&(this.emit("update",{editor:this,transaction:t}),this.emit("v3-update",{editor:this,transaction:t,appendedTransactions:r.slice(1)}))}forceEnablePlugins(){if(this.view)throw new Error("forcePluginsEnabled called after view has been initialized");this._state=this.state.reconfigure({plugins:this.extensionManager.plugins})}createViewAlternative(t,o){this.contentComponent=o;const r={};this.extensionManager.extensions.forEach(i=>{i.type==="mark"&&i.config.addMarkView&&(r[i.name]=i.config.addMarkView(t))}),this.view=new H.EditorView({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatch.bind(this),state:this.state,markViews:r,nodeViews:this.extensionManager.nodeViews});const s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.commands.focus(this.options.autofocus||this.options.element.getAttribute("data-bn-autofocus")==="true",{scrollIntoView:!1}),this.emit("create",{editor:this}),this.isInitialized=!0}};p(qe,"create",(t,o)=>{var s,i;const r=(s=globalThis==null?void 0:globalThis.window)==null?void 0:s.setTimeout;typeof((i=globalThis==null?void 0:globalThis.window)==null?void 0:i.setTimeout)<"u"&&(globalThis.window.setTimeout=()=>0);try{return new qe(t,o)}finally{r&&(globalThis.window.setTimeout=r)}});let We=qe;We.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const $a={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Kt extends ot{constructor(t){var c,d,u,h,f,m,g,b,k,w,v,E,_,q,P,x;super();p(this,"pmSchema");p(this,"extensions",{});p(this,"headless",!1);p(this,"_tiptapEditor");p(this,"elementRenderer",null);p(this,"blockCache",new WeakMap);p(this,"dictionary");p(this,"schema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"formattingToolbar");p(this,"linkToolbar");p(this,"sideMenu");p(this,"suggestionMenus");p(this,"filePanel");p(this,"tableHandles");p(this,"comments");p(this,"showSelectionPlugin");p(this,"forkYDocPlugin");p(this,"uploadFile");p(this,"onUploadStartCallbacks",[]);p(this,"onUploadEndCallbacks",[]);p(this,"resolveFileUrl");p(this,"resolveUsers");p(this,"settings");p(this,"activeTransaction",null);p(this,"mount",(t,o)=>{this._tiptapEditor.mount(this,t,o)});this.options=t;const o=t;if(o.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(o.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(o.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(o.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||Fr.en,this.settings={tables:{splitCells:((c=t==null?void 0:t.tables)==null?void 0:c.splitCells)??!1,cellBackgroundColor:((d=t==null?void 0:t.tables)==null?void 0:d.cellBackgroundColor)??!1,cellTextColor:((u=t==null?void 0:t.tables)==null?void 0:u.cellTextColor)??!1,headers:((h=t==null?void 0:t.tables)==null?void 0:h.headers)??!1},codeBlock:{indentLineWithTab:((f=t==null?void 0:t.codeBlock)==null?void 0:f.indentLineWithTab)??!0,defaultLanguage:((m=t==null?void 0:t.codeBlock)==null?void 0:m.defaultLanguage)??"text",supportedLanguages:((g=t==null?void 0:t.codeBlock)==null?void 0:g.supportedLanguages)??{},createHighlighter:((b=t==null?void 0:t.codeBlock)==null?void 0:b.createHighlighter)??void 0},heading:{levels:((k=t==null?void 0:t.heading)==null?void 0:k.levels)??[1,2,3]}};const r={defaultStyles:!0,schema:t.schema||we.create(),_headless:!1,...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};if(r.comments&&!r.resolveUsers)throw new Error("resolveUsers is required when using comments");this.resolveUsers=r.resolveUsers,this.schema=r.schema,this.blockImplementations=r.schema.blockSpecs,this.inlineContentImplementations=r.schema.inlineContentSpecs,this.styleImplementations=r.schema.styleSpecs,this.extensions=kr({editor:this,domAttributes:r.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:r.collaboration,trailingBlock:r.trailingBlock,disableExtensions:r.disableExtensions,setIdAttribute:r.setIdAttribute,animations:r.animations??!0,tableHandles:V("table",this),dropCursor:this.options.dropCursor??Ur.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,comments:r.comments,pasteHandler:r.pasteHandler}),(((w=r._tiptapOptions)==null?void 0:w.extensions)||[]).forEach(A=>{this.extensions[A.name]=A});for(let A of r.extensions||[]){typeof A=="function"&&(A=A(this));const M=A.constructor.key();if(!M)throw new Error(`Extension ${A.constructor.name} does not have a key method`);if(this.extensions[M])throw new Error(`Extension ${A.constructor.name} already exists with key ${M}`);this.extensions[M]=A}if(Object.entries(r._extensions||{}).forEach(([A,M])=>{const te=typeof M=="function"?M(this):M;if(!("plugin"in te)){this.extensions[A]=te;return}this.extensions[A]=new class extends O{static key(){return A}constructor(){super(),this.addProsemirrorPlugin(te.plugin)}get priority(){return te.priority}}}),this.formattingToolbar=this.extensions.formattingToolbar,this.linkToolbar=this.extensions.linkToolbar,this.sideMenu=this.extensions.sideMenu,this.suggestionMenus=this.extensions.suggestionMenus,this.filePanel=this.extensions.filePanel,this.tableHandles=this.extensions.tableHandles,this.comments=this.extensions.comments,this.showSelectionPlugin=this.extensions.showSelection,this.forkYDocPlugin=this.extensions.forkYDocPlugin,r.uploadFile){const A=r.uploadFile;this.uploadFile=async(M,Ne)=>{this.onUploadStartCallbacks.forEach(te=>te.apply(this,[Ne]));try{return await A(M,Ne)}finally{this.onUploadEndCallbacks.forEach(te=>te.apply(this,[Ne]))}}}this.resolveFileUrl=r.resolveFileUrl,this.headless=r._headless;const s="ySyncPlugin"in this.extensions||"liveblocksExtension"in this.extensions;s&&r.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const i=r.initialContent||(s?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:Be.options.generateID()}]);if(!Array.isArray(i)||i.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+i);const a=[...Object.entries(this.extensions).map(([A,M])=>{if(M instanceof y.Extension||M instanceof y.Node||M instanceof y.Mark)return M;if(!(M instanceof O&&!M.plugins.length))return y.Extension.create({name:A,priority:M.priority,addProseMirrorPlugins:()=>M.plugins})})].filter(A=>A!==void 0),l={...$a,...r._tiptapOptions,content:i,extensions:a,editorProps:{...(v=r._tiptapOptions)==null?void 0:v.editorProps,attributes:{tabIndex:"0",...(_=(E=r._tiptapOptions)==null?void 0:E.editorProps)==null?void 0:_.attributes,...(q=r.domAttributes)==null?void 0:q.editor,class:Q("bn-editor",r.defaultStyles?"bn-default-styles":"",((x=(P=r.domAttributes)==null?void 0:P.editor)==null?void 0:x.class)||"")},transformPasted:Ua}};this.headless?this.pmSchema=y.getSchema(l.extensions):(this._tiptapEditor=We.create(l,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.pmSchema.cached.blockNoteEditor=this,this.emit("create")}static create(t={}){return new Kt(t)}exec(t){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,i=>this._tiptapEditor.dispatch(i),r)}canExec(t){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,void 0,r)}transact(t){if(this.activeTransaction)return t(this.activeTransaction);try{this.activeTransaction=this._tiptapEditor.state.tr;const o=t(this.activeTransaction),r=this.activeTransaction;return this.activeTransaction=null,r&&(r.docChanged||r.selectionSet||r.scrolledIntoView||r.storedMarksSet||!r.isGeneric)&&this._tiptapEditor.dispatch(r),o}finally{this.activeTransaction=null}}extension(t,o=t.key()){const r=this.extensions[o];if(!r)throw new Error(`Extension ${o} not found`);return r}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this._tiptapEditor.state}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){var t;return(t=this.prosemirrorView)==null?void 0:t.dom}isFocused(){var t;return((t=this.prosemirrorView)==null?void 0:t.hasFocus())||!1}focus(){var t;(t=this.prosemirrorView)==null||t.focus()}onUploadStart(t){return this.onUploadStartCallbacks.push(t),()=>{const o=this.onUploadStartCallbacks.indexOf(t);o>-1&&this.onUploadStartCallbacks.splice(o,1)}}onUploadEnd(t){return this.onUploadEndCallbacks.push(t),()=>{const o=this.onUploadEndCallbacks.indexOf(t);o>-1&&this.onUploadEndCallbacks.splice(o,1)}}get topLevelBlocks(){return this.document}get document(){return this.transact(t=>wn(t.doc,this.pmSchema))}getBlock(t){return this.transact(o=>$o(o.doc,t))}getPrevBlock(t){return this.transact(o=>zo(o.doc,t))}getNextBlock(t){return this.transact(o=>Wo(o.doc,t))}getParentBlock(t){return this.transact(o=>qo(o.doc,t))}forEachBlock(t,o=!1){const r=this.document.slice();o&&r.reverse();function s(i){for(const a of i){if(t(a)===!1)return!1;const l=o?a.children.slice().reverse():a.children;if(!s(l))return!1}return!0}s(r)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){return this.transact(t=>Ci(t))}setTextCursorPosition(t,o="start"){return this.transact(r=>Ko(r,t,o))}getSelection(){return this.transact(t=>ki(t))}getSelectionCutBlocks(){return this.transact(t=>wi(t))}setSelection(t,o){return this.transact(r=>yi(r,t,o))}get isEditable(){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return!1}return this._tiptapEditor.isEditable===void 0?!0:this._tiptapEditor.isEditable}set isEditable(t){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return}this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,o,r="before"){return this.transact(s=>Nn(s,t,o,r))}updateBlock(t,o){return this.transact(r=>Dn(r,t,o))}removeBlocks(t){return this.transact(o=>mt(o,t,[]).removedBlocks)}replaceBlocks(t,o){return this.transact(r=>mt(r,t,o))}undo(){return this.options.collaboration?this.exec(D.undoCommand):this.exec(jt.undo)}redo(){return this.options.collaboration?this.exec(D.redoCommand):this.exec(jt.redo)}insertInlineContent(t,{updateSelection:o=!1}={}){const r=W(t,this.pmSchema);this.transact(s=>{bi(s,{from:s.selection.from,to:s.selection.to},r,{updateSelection:o})})}getActiveStyles(){return this.transact(t=>{const o={},r=t.selection.$to.marks();for(const s of r){const i=this.schema.styleSchema[s.type.name];if(!i){s.type.name!=="link"&&!s.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",s.type.name);continue}i.propSchema==="boolean"?o[i.type]=!0:o[i.type]=s.attrs.stringValue}return o})}addStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.setMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.setMark(o,{stringValue:r});else throw new j(s.propSchema)}}removeStyles(t){for(const o of Object.keys(t))this._tiptapEditor.commands.unsetMark(o)}toggleStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.toggleMark(o,{stringValue:r});else throw new j(s.propSchema)}}getSelectedText(){return this.transact(t=>t.doc.textBetween(t.selection.from,t.selection.to))}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,o){if(t==="")return;const r=this.pmSchema.mark("link",{href:t});this.transact(s=>{const{from:i,to:a}=s.selection;o?s.insertText(o,i,a).addMark(i,i+o.length,r):s.setSelection(C.TextSelection.create(s.doc,a)).addMark(i,a,r)})}canNestBlock(){return mi(this)}nestBlock(){Fo(this)}canUnnestBlock(){return gi(this)}unnestBlock(){fi(this)}moveBlocksUp(){return ui(this)}moveBlocksDown(){return pi(this)}async blocksToHTMLLossy(t=this.document){return Me(this.pmSchema,this).exportBlocks(t,{})}async blocksToFullHTML(t){return Fn(this.pmSchema,this).serializeBlocks(t,{})}async tryParseHTMLToBlocks(t){return $t(t,this.pmSchema)}async blocksToMarkdownLossy(t=this.document){return jo(t,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(t){return Yo(t,this.pmSchema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this.extensions.yCursorPlugin.updateUser(t)}onBeforeChange(t){return this.headless?()=>{}:this.extensions.blockChange.subscribe(o=>t(this,o))}onChange(t){if(this.headless)return;const o=({transaction:r,appendedTransactions:s})=>{t(this,{getChanges:()=>At(r,s)})};return this._tiptapEditor.on("v3-update",o),()=>{this._tiptapEditor.off("v3-update",o)}}onSelectionChange(t,o){if(this.headless)return;const r=s=>{s.transaction.getMeta(D.ySyncPluginKey)&&!o||t(this)};return this._tiptapEditor.on("selectionUpdate",r),()=>{this._tiptapEditor.off("selectionUpdate",r)}}onCreate(t){return this.on("create",t),()=>{this.off("create",t)}}getSelectionBoundingBox(){if(!this.prosemirrorView)return;const{selection:t}=this.prosemirrorState,{ranges:o}=t,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(y.isNodeSelection(t)){const i=this.prosemirrorView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return y.posToDOMRect(this.prosemirrorView,r,s)}get isEmpty(){const t=this.document;return t.length===0||t.length===1&&t[0].type==="paragraph"&&t[0].content.length===0}openSuggestionMenu(t,o){this.prosemirrorView&&(this.focus(),this.transact(r=>{o!=null&&o.deleteTriggerCharacter&&r.insertText(t),r.scrollIntoView().setMeta(this.suggestionMenus.plugins[0],{triggerCharacter:t,deleteTriggerCharacter:(o==null?void 0:o.deleteTriggerCharacter)||!1,ignoreQueryLength:(o==null?void 0:o.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(t){this.showSelectionPlugin.setEnabled(t)}convertHtmlToBlockNoteHtml(t){return Go(t.trim()).innerHTML}pasteHTML(t,o=!1){var s;let r=t;o||(r=this.convertHtmlToBlockNoteHtml(t)),r&&((s=this.prosemirrorView)==null||s.pasteHTML(r))}pasteText(t){var o;return(o=this.prosemirrorView)==null?void 0:o.pasteText(t)}async pasteMarkdown(t){return this.pasteHTML(await zt(t))}}const za={gray:{text:"#9b9a97",background:"#ebeced"},brown:{text:"#64473a",background:"#e9e5e3"},red:{text:"#e03e3e",background:"#fbe4e4"},orange:{text:"#d9730d",background:"#f6e9d9"},yellow:{text:"#dfab01",background:"#fbf3db"},green:{text:"#4d6461",background:"#ddedea"},blue:{text:"#0b6e99",background:"#ddebf1"},purple:{text:"#6940a5",background:"#eae4f2"},pink:{text:"#ad1a72",background:"#f4dfeb"}},Wa={gray:{text:"#bebdb8",background:"#9b9a97"},brown:{text:"#8e6552",background:"#64473a"},red:{text:"#ec4040",background:"#be3434"},orange:{text:"#e3790d",background:"#b7600a"},yellow:{text:"#dfab01",background:"#b58b00"},green:{text:"#6b8b87",background:"#4d6461"},blue:{text:"#0e87bc",background:"#0b6e99"},purple:{text:"#8552d7",background:"#6940a5"},pink:{text:"#da208f",background:"#ad1a72"}};class qa{constructor(n,t,o){this.mappings=t,this.options=o}async resolveFile(n){var o;if(!((o=this.options)!=null&&o.resolveFileUrl))return(await fetch(n)).blob();const t=await this.options.resolveFileUrl(n);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(n){return Object.entries(n).map(([o,r])=>this.mappings.styleMapping[o](r,this))}mapInlineContent(n){return this.mappings.inlineContentMapping[n.type](n,this)}transformInlineContent(n){return n.map(t=>this.mapInlineContent(t))}async mapBlock(n,t,o,r){return this.mappings.blockMapping[n.type](n,this,t,o,r)}}function Ka(e){return{createBlockMapping:n=>n,createInlineContentMapping:n=>n,createStyleMapping:n=>n}}let Re;async function ja(){return Re||(Re=(async()=>{const[e,n]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),t="default"in e?e.default:e,o="default"in n?n.default:n;return await t.init({data:o}),{emojiMart:t,emojiData:o}})(),Re)}async function Ga(e,n){if(!Po("text",e))return[];const{emojiData:t,emojiMart:o}=await ja();return(n.trim()===""?Object.values(t.emojis):await o.SearchIndex.search(n)).map(s=>({id:s.skins[0].native,onItemClick:()=>e.insertInlineContent(s.skins[0].native+" ")}))}function Ya(e,...n){const t=[...e];for(const o of n)for(const r of o){const s=t.findLastIndex(i=>i.group===r.group);s===-1?t.push(r):t.splice(s+1,0,r)}return t}exports.AudioBlock=Xn;exports.BlockNoteEditor=Kt;exports.BlockNoteExtension=O;exports.BlockNoteSchema=we;exports.COLORS_DARK_MODE_DEFAULT=Wa;exports.COLORS_DEFAULT=za;exports.CodeBlock=Qn;exports.DEFAULT_LINK_PROTOCOL=lr;exports.EMPTY_CELL_HEIGHT=zs;exports.EMPTY_CELL_WIDTH=Rt;exports.EventEmitter=ot;exports.Exporter=qa;exports.FILE_AUDIO_ICON_SVG=qn;exports.FILE_ICON_SVG=zn;exports.FILE_IMAGE_ICON_SVG=lo;exports.FILE_VIDEO_ICON_SVG=yo;exports.FileBlock=so;exports.FilePanelProsemirrorPlugin=er;exports.FilePanelView=Qo;exports.FormattingToolbarProsemirrorPlugin=or;exports.FormattingToolbarView=tr;exports.HTMLToBlocks=$t;exports.ImageBlock=mo;exports.LinkToolbarProsemirrorPlugin=ir;exports.PageBreak=Ho;exports.SideMenuProsemirrorPlugin=hr;exports.SideMenuView=ur;exports.SuggestionMenuProseMirrorPlugin=mr;exports.TableHandlesProsemirrorPlugin=br;exports.TableHandlesView=gr;exports.UniqueID=Be;exports.UnreachableCaseError=j;exports.VALID_LINK_PROTOCOLS=ar;exports.VideoBlock=Bo;exports.addInlineContentAttributes=dt;exports.addInlineContentKeyboardShortcuts=vn;exports.addStyleAttributes=xn;exports.applyNonSelectableBlockFix=bn;exports.assertEmpty=Jr;exports.audioBlockConfig=jn;exports.audioParse=Yn;exports.audioPropSchema=Kn;exports.audioRender=Gn;exports.audioToExternalHTML=Jn;exports.blockToNode=se;exports.blocksToMarkdown=jo;exports.camelToDataKebab=ve;exports.captureCellAnchor=Hn;exports.checkBlockHasDefaultProp=ni;exports.checkBlockIsDefaultType=Mo;exports.checkBlockIsFileBlock=Qs;exports.checkBlockIsFileBlockWithPlaceholder=ti;exports.checkBlockIsFileBlockWithPreview=ei;exports.checkBlockTypeHasDefaultProp=Io;exports.checkBlockTypeInSchema=Xs;exports.checkDefaultBlockTypeInSchema=V;exports.checkDefaultInlineContentTypeInSchema=Po;exports.checkInlineContentTypeInSchema=Zs;exports.checkPageBreakBlocksInSchema=Oo;exports.cleanHTMLToMarkdown=nt;exports.combineByGroup=Ya;exports.contentNodeToInlineContent=xe;exports.contentNodeToTableContent=xt;exports.createAddFileButton=$n;exports.createBlockSpec=be;exports.createBlockSpecFromStronglyTypedTiptapNode=Z;exports.createDefaultBlockDOMOutputSpec=$;exports.createExternalHTMLExporter=Me;exports.createFigureWithCaption=et;exports.createFileBlockWrapper=Qe;exports.createFileNameWithIcon=Wn;exports.createInlineContentSpec=Qr;exports.createInlineContentSpecFromTipTapNode=En;exports.createInternalBlockSpec=Bt;exports.createInternalHTMLSerializer=Fn;exports.createInternalInlineContentSpec=Sn;exports.createInternalStyleSpec=Mt;exports.createLinkWithCaption=Le;exports.createResizableFileBlockWrapper=Ht;exports.createStronglyTypedTiptapNode=G;exports.createStyleSpec=es;exports.createStyleSpecFromTipTapMark=ne;exports.createSuggestionMenu=va;exports.createToggleWrapper=Dt;exports.defaultBlockSchema=To;exports.defaultBlockSpecs=_t;exports.defaultBlockToHTML=ct;exports.defaultCodeBlockPropSchema=Zn;exports.defaultInlineContentSchema=xo;exports.defaultInlineContentSpecs=Ut;exports.defaultProps=L;exports.defaultStyleSchema=Js;exports.defaultStyleSpecs=Vt;exports.defaultToggledState=io;exports.docToBlocks=wn;exports.fileBlockConfig=to;exports.fileParse=oo;exports.filePropSchema=eo;exports.fileRender=no;exports.fileToExternalHTML=ro;exports.filenameFromURL=Zr;exports.filterSuggestionItems=ii;exports.formatKeyboardShortcut=J;exports.formattingToolbarPluginKey=nr;exports.getBlock=$o;exports.getBlockCache=Xe;exports.getBlockFromPos=je;exports.getBlockInfo=ee;exports.getBlockInfoFromResolvedPos=ke;exports.getBlockInfoFromSelection=B;exports.getBlockInfoFromTransaction=Te;exports.getBlockInfoWithManualOffset=Ge;exports.getBlockNoteExtensions=kr;exports.getBlockNoteSchema=ye;exports.getBlockSchema=Ye;exports.getBlockSchemaFromSpecs=Tt;exports.getBlocksChangedByTransaction=At;exports.getColspan=me;exports.getDefaultEmojiPickerItems=Ga;exports.getDefaultSlashMenuItems=si;exports.getInlineContentParseRules=Bn;exports.getInlineContentSchema=Je;exports.getInlineContentSchemaFromSpecs=Pt;exports.getNearestBlockPos=X;exports.getNextBlock=Wo;exports.getNodeById=z;exports.getPageBreakSlashMenuItems=li;exports.getParentBlock=qo;exports.getParseRules=kn;exports.getPmSchema=R;exports.getPrevBlock=zo;exports.getRowspan=Fe;exports.getStyleParseRules=Pn;exports.getStyleSchema=ce;exports.getStyleSchemaFromSpecs=It;exports.imageBlockConfig=uo;exports.imageParse=ho;exports.imagePropSchema=co;exports.imageRender=po;exports.imageToExternalHTML=fo;exports.inheritedProps=Et;exports.initializeESMDependencies=Ae;exports.inlineContentToNodes=W;exports.insertBlocks=Nn;exports.insertOrUpdateBlock=N;exports.isAppleOS=mn;exports.isLinkInlineContent=lt;exports.isNodeBlock=Ze;exports.isPartialLinkInlineContent=St;exports.isPartialTableCell=fe;exports.isSafari=Xr;exports.isStyledTextInlineContent=oe;exports.isTableCell=Ke;exports.isTableCellSelection=kt;exports.linkToolbarPluginKey=sr;exports.mapTableCell=Ue;exports.mappingFactory=Ka;exports.markdownToBlocks=Yo;exports.markdownToHTML=zt;exports.mergeCSSClasses=Q;exports.mergeParagraphs=gn;exports.nodeToBlock=T;exports.nodeToCustomInlineContent=$e;exports.pageBreakConfig=Lo;exports.pageBreakParse=No;exports.pageBreakRender=Ao;exports.pageBreakSchema=Ft;exports.pageBreakToExternalHTML=Do;exports.parseEmbedElement=bt;exports.parseFigureElement=Ie;exports.propsToAttributes=ge;exports.prosemirrorSliceToSlicedBlocks=Cn;exports.removeAndInsertBlocks=mt;exports.selectedFragmentToHTML=qt;exports.shikiHighlighterPromiseSymbol=_e;exports.shikiParserSymbol=gt;exports.sideMenuPluginKey=pr;exports.stylePropsToAttributes=Tn;exports.tableContentToNodes=Pe;exports.tableHandlesPluginKey=de;exports.trackPosition=fr;exports.updateBlock=Dn;exports.updateBlockCommand=U;exports.updateBlockTr=Nt;exports.uploadToTmpFilesDotOrg_DEV_ONLY=oi;exports.videoBlockConfig=Co;exports.videoParse=So;exports.videoPropSchema=wo;exports.videoRender=vo;exports.videoToExternalHTML=Eo;exports.withPageBreak=ai;exports.wrapInBlockStructure=Ce;
10
+ `),!0):e.chain().command(({tr:r})=>(r.delete(n.pos-2,n.pos),!0)).exitCode().run()},"Shift-Enter":({editor:e})=>{const{$from:n}=e.state.selection;return e.isActive(this.name)?(e.chain().insertContentAt(n.pos-n.parentOffset+n.parent.nodeSize,{type:"paragraph"}).run(),!0):!1}}}}),Qn=Z(ks,Zn);function st(e,n){var t;return(t=Object.entries(e.supportedLanguages).find(([o,{aliases:r}])=>(r==null?void 0:r.includes(n))||o===n))==null?void 0:t[0]}const ys=w.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-background-color")?{stringValue:e.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),ws=ne(ys,"string"),Cs=w.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-text-color")?{stringValue:e.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),vs=ne(Cs,"string"),bt=e=>({url:e.src||void 0}),eo={backgroundColor:A.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},to={type:"file",propSchema:eo,content:"none",isFileBlock:!0},no=(e,n)=>Qe(e,n),oo=e=>{if(e.tagName==="EMBED")return e.closest("figure")?void 0:bt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"embed");if(!n)return;const{targetElement:t,caption:o}=n;return{...bt(t),caption:o}}},ro=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add file",{dom:t}}const n=document.createElement("a");return n.href=e.props.url,n.textContent=e.props.name||e.props.url,e.props.caption?Le(n,e.props.caption):{dom:n}},so=ke(to,{render:no,parse:oo,toExternalHTML:ro}),io={set:(e,n)=>window.localStorage.setItem(`toggle-${e.id}`,n?"true":"false"),get:e=>window.localStorage.getItem(`toggle-${e.id}`)==="true"},Dt=(e,n,t,o=io)=>{if("isToggleable"in e.props&&!e.props.isToggleable)return{dom:t};const r=document.createElement("div"),s=document.createElement("div");s.className="bn-toggle-wrapper";const i=document.createElement("button");i.className="bn-toggle-button",i.type="button",i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="CURRENTCOLOR"><path d="M320-200v-560l440 280-440 280Z"/></svg>';const a=m=>m.preventDefault();i.addEventListener("mousedown",a);const l=()=>{var m;s.getAttribute("data-show-children")==="true"?(s.setAttribute("data-show-children","false"),o.set(n.getBlock(e),!1),r.contains(c)&&r.removeChild(c)):(s.setAttribute("data-show-children","true"),o.set(n.getBlock(e),!0),((m=n.getBlock(e))==null?void 0:m.children.length)===0&&!r.contains(c)&&r.appendChild(c))};i.addEventListener("click",l),s.appendChild(i),s.appendChild(t);const c=document.createElement("button");c.className="bn-toggle-add-block-button",c.type="button",c.textContent=n.dictionary.toggle_blocks.add_block_button;const d=m=>m.preventDefault();c.addEventListener("mousedown",d);const u=()=>{n.transact(()=>{const m=n.updateBlock(e,{children:[{}]});n.setTextCursorPosition(m.children[0].id,"end"),n.focus()})};c.addEventListener("click",u),r.appendChild(s);let p=e.children.length;const f=n.onChange(()=>{var g;const m=((g=n.getBlock(e))==null?void 0:g.children.length)??0;m>p?(s.getAttribute("data-show-children")==="false"&&(s.setAttribute("data-show-children","true"),o.set(n.getBlock(e),!0)),r.contains(c)&&r.removeChild(c)):m===0&&m<p&&(s.getAttribute("data-show-children")==="true"&&(s.setAttribute("data-show-children","false"),o.set(n.getBlock(e),!1)),r.contains(c)&&r.removeChild(c)),p=m});return o.get(e)?(s.setAttribute("data-show-children","true"),e.children.length===0&&r.appendChild(c)):s.setAttribute("data-show-children","false"),{dom:r,ignoreMutation:m=>m instanceof MutationRecord&&(m.type==="attributes"&&m.target===s&&m.attributeName==="data-show-children"||m.type==="childList"&&(m.addedNodes[0]===c||m.removedNodes[0]===c)),destroy:()=>{i.removeEventListener("mousedown",a),i.removeEventListener("click",l),c.removeEventListener("mousedown",d),c.removeEventListener("click",u),f==null||f()}}},Ss=[1,2,3,4,5,6],ao={...A,level:{default:1,values:Ss},isToggleable:{default:!1}},Es=j({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return be(ao)},addInputRules(){return[...this.options.editor.settings.heading.levels.map(n=>new w.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:t,chain:o,range:r})=>{const s=T(t);!s.isBlockContainer||s.blockContent.node.type.spec.content!=="inline*"||o().command(U(s.bnBlock.beforePos,{type:"heading",props:{level:n}})).deleteRange({from:r.from,to:r.to}).run()}}))]},addKeyboardShortcuts(){const e=this.options.editor;return Object.fromEntries(e.settings.heading.levels.map(n=>[`Mod-Alt-${n}`,()=>{const t=T(this.editor.state);return!t.isBlockContainer||t.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(t.bnBlock.beforePos,{type:"heading",props:{level:n}}))}]))},parseHTML(){const e=this.options.editor;return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},...e.settings.heading.levels.map(n=>({tag:`h${n}`,attrs:{level:n},node:"heading"}))]},renderHTML({node:e,HTMLAttributes:n}){var t,o;return $(this.name,`h${e.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:n,getPos:t})=>{var l,c;const{dom:o,contentDOM:r}=$(this.name,`h${e.attrs.level}`,{...((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},...n},((c=this.options.domAttributes)==null?void 0:c.inlineContent)||{});o.removeChild(r);const s=this.options.editor,i=je(t,s,this.editor,this.name),a=Dt(i,s,r);return o.appendChild(a.dom),{dom:o,contentDOM:r,ignoreMutation:a.ignoreMutation,destroy:a.destroy}}}}),Bs=Z(Es,ao),Ht=(e,n,t,o,r,s)=>{const{dom:i,destroy:a}=Qe(e,n,t,r,s),l=i;l.style.position="relative",e.props.url&&e.props.showPreview&&(e.props.previewWidth?l.style.width=`${e.props.previewWidth}px`:l.style.width="fit-content");const c=document.createElement("div");c.className="bn-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-resize-handle",d.style.right="4px";const u=document.createElement("div");u.style.position="absolute",u.style.height="100%",u.style.width="100%";let p,f=e.props.previewWidth;const m=v=>{var M,B;if(!p){!n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d));return}let P;e.props.textAlignment==="center"?p.handleUsed==="left"?P=p.initialWidth+(p.initialClientX-v.clientX)*2:P=p.initialWidth+(v.clientX-p.initialClientX)*2:p.handleUsed==="left"?P=p.initialWidth+p.initialClientX-v.clientX:P=p.initialWidth+v.clientX-p.initialClientX,f=Math.min(Math.max(P,64),((B=(M=n.domElement)==null?void 0:M.firstElementChild)==null?void 0:B.clientWidth)||Number.MAX_VALUE),l.style.width=`${f}px`},g=v=>{(!v.target||!l.contains(v.target)||!n.isEditable)&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)),p&&(p=void 0,l.contains(u)&&l.removeChild(u),n.updateBlock(e,{props:{previewWidth:f}}))},b=()=>{n.isEditable&&(o.appendChild(c),o.appendChild(d))},k=v=>{v.relatedTarget===c||v.relatedTarget===d||p||n.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d))},y=v=>{v.preventDefault(),l.contains(u)||l.appendChild(u),p={handleUsed:"left",initialWidth:l.clientWidth,initialClientX:v.clientX}},S=v=>{v.preventDefault(),l.contains(u)||l.appendChild(u),p={handleUsed:"right",initialWidth:l.clientWidth,initialClientX:v.clientX}};return window.addEventListener("mousemove",m),window.addEventListener("mouseup",g),l.addEventListener("mouseenter",b),l.addEventListener("mouseleave",k),c.addEventListener("mousedown",y),d.addEventListener("mousedown",S),{dom:l,destroy:()=>{a==null||a(),window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",g),l.removeEventListener("mouseenter",b),l.removeEventListener("mouseleave",k),c.removeEventListener("mousedown",y),d.removeEventListener("mousedown",S)}}},Zt=e=>{const n=e.src||void 0,t=e.width||void 0,o=e.alt||void 0;return{url:n,previewWidth:t,name:o}},lo='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>',co={textAlignment:A.textAlignment,backgroundColor:A.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},uo={type:"image",propSchema:co,content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},po=(e,n)=>{const t=document.createElement("div");t.innerHTML=lo;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.alt=e.props.name||e.props.caption||"BlockNote image",r.contentEditable="false",r.draggable=!1,o.appendChild(r),Ht(e,n,{dom:o},o,n.dictionary.file_blocks.image.add_button_text,t.firstElementChild)},ho=e=>{if(e.tagName==="IMG")return e.closest("figure")?void 0:Zt(e);if(e.tagName==="FIGURE"){const n=Ie(e,"img");if(!n)return;const{targetElement:t,caption:o}=n;return{...Zt(t),caption:o}}},fo=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add image",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("img"),n.src=e.props.url,n.alt=e.props.name||e.props.caption||"BlockNote image",e.props.previewWidth&&(n.width=e.props.previewWidth)):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?et(n,e.props.caption):Le(n,e.props.caption):{dom:n}},mo=ke(uo,{render:po,parse:ho,toExternalHTML:fo}),go=(e,n,t)=>({state:o,dispatch:r})=>{const s=J(o.doc,e),i=ee(s);if(!i.isBlockContainer)throw new Error(`BlockContainer expected when calling splitBlock, position ${e}`);const a=[{type:i.bnBlock.node.type,attrs:t?{...i.bnBlock.node.attrs,id:void 0}:{}},{type:n?i.blockContent.node.type:o.schema.nodes.paragraph,attrs:t?{...i.blockContent.node.attrs}:{}}];return r&&o.tr.split(e,2,a),!0},tt=e=>{const{blockInfo:n,selectionEmpty:t}=e.transact(s=>({blockInfo:Te(s),selectionEmpty:s.selection.anchor===s.selection.head}));if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n;return!(r.node.type.name==="toggleListItem"||r.node.type.name==="bulletListItem"||r.node.type.name==="numberedListItem"||r.node.type.name==="checkListItem")||!t?!1:e._tiptapEditor.commands.first(({state:s,chain:i,commands:a})=>[()=>a.command(()=>r.node.childCount===0?a.command(U(o.beforePos,{type:"paragraph",props:{}})):!1),()=>a.command(()=>r.node.childCount>0?(i().deleteSelection().command(go(s.selection.from,!0)).run(),!0):!1)])},Ts={...A},xs=j({name:"toggleListItem",content:"inline*",group:"blockContent",priority:90,addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-6":()=>{const e=T(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"toggleListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})},addNodeView(){return({HTMLAttributes:e,getPos:n})=>{var a,l;const{dom:t,contentDOM:o}=$(this.name,"p",{...((a=this.options.domAttributes)==null?void 0:a.blockContent)||{},...e},((l=this.options.domAttributes)==null?void 0:l.inlineContent)||{}),r=this.options.editor,s=je(n,r,this.editor,this.name),i=Dt(s,r,o);return t.appendChild(i.dom),{dom:t,contentDOM:o,ignoreMutation:i.ignoreMutation,destroy:i.destroy}}}}),Ps=Z(xs,Ts);function Ot(e,n,t){var u,p,f;const o=E.DOMParser.fromSchema(n),r=e,s=document.createElement("div");s.setAttribute("data-node-type","blockGroup");for(const m of Array.from(r.childNodes))s.appendChild(m.cloneNode(!0));let i=o.parse(s,{topNode:n.nodes.blockGroup.create()});((p=(u=i.firstChild)==null?void 0:u.firstChild)==null?void 0:p.type.name)==="checkListItem"&&(i=i.copy(i.content.cut(i.firstChild.firstChild.nodeSize+2)));const a=(f=i.firstChild)==null?void 0:f.firstChild;if(!(a!=null&&a.isTextblock))return E.Fragment.from(i);const l=n.nodes[t].create({},a.content),c=i.content.cut(a.nodeSize+2);if(c.size>0){const m=i.copy(c);return l.content.addToEnd(m)}return l.content}const Ms={...A},Is=j({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules(){return[new w.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=T(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||o.blockNoteType==="heading"||n().command(U(o.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-8":()=>{const e=T(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"bulletListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;return n===null?!1:n.tagName==="UL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="UL"?{}:!1},getContent:(e,n)=>Ot(e,n,this.name),node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Ls=Z(Is,Ms),bo={...A,checked:{default:!1}},As=j({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return be(bo)},addInputRules(){return[new w.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=T(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(U(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!1}})).deleteRange({from:t.from,to:t.to})}}),new w.InputRule({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:n,range:t})=>{const o=T(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(U(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-9":()=>{const e=T(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"checkListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"input",getAttrs:e=>typeof e=="string"||e.closest("[data-content-type]")||e.closest("li")?!1:e.type==="checkbox"?{checked:e.checked}:!1,node:"checkListItem"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="UL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="UL"){const o=e.querySelector("input[type=checkbox]")||null;return o===null?!1:{checked:o.checked}}return!1},getContent:(e,n)=>Ot(e,n,this.name),node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:n}){var s,i;const t=document.createElement("input");t.type="checkbox",t.checked=e.attrs.checked,e.attrs.checked&&t.setAttribute("checked","");const{dom:o,contentDOM:r}=$(this.name,"p",{...((s=this.options.domAttributes)==null?void 0:s.blockContent)||{},...n},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{});return o.insertBefore(t,r),{dom:o,contentDOM:r}},addNodeView(){return({node:e,getPos:n,editor:t,HTMLAttributes:o})=>{var d,u;const r=document.createElement("div"),s=document.createElement("div");s.contentEditable="false";const i=document.createElement("input");i.type="checkbox",i.checked=e.attrs.checked,e.attrs.checked&&i.setAttribute("checked","");const a=()=>{if(!t.isEditable){i.checked=!i.checked;return}if(typeof n!="boolean"){const p=J(t.state.doc,n());if(p.node.type.name!=="blockContainer")throw new Error(`Expected blockContainer node, got ${p.node.type.name}`);this.editor.commands.command(U(p.posBeforeNode,{type:"checkListItem",props:{checked:i.checked}}))}};i.addEventListener("change",a);const{dom:l,contentDOM:c}=$(this.name,"p",{...((d=this.options.domAttributes)==null?void 0:d.blockContent)||{},...o},((u=this.options.domAttributes)==null?void 0:u.inlineContent)||{});if(typeof n!="boolean"){const f="label-"+this.editor.state.doc.resolve(n()).node().attrs.id;i.setAttribute("aria-labelledby",f),c.id=f}return l.removeChild(c),l.appendChild(r),r.appendChild(s),r.appendChild(c),s.appendChild(i),{dom:l,contentDOM:c,destroy:()=>{i.removeEventListener("change",a)}}}}}),Ns=Z(As,bo),Ds=new C.PluginKey("numbered-list-indexing"),Hs=()=>new C.Plugin({key:Ds,appendTransaction:(e,n,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((s,i)=>{var a;if(s.type.name==="blockContainer"&&s.firstChild.type.name==="numberedListItem"){let l=`${s.firstChild.attrs.start||1}`;const c=ee({posBeforeNode:i,node:s});if(!c.isBlockContainer)throw new Error("impossible");const d=o.doc.resolve(c.bnBlock.beforePos).nodeBefore;if(d){const m=ee({posBeforeNode:c.bnBlock.beforePos-d.nodeSize,node:d});if(m.blockNoteType==="numberedListItem"){if(!m.isBlockContainer)throw new Error("impossible");const b=m.blockContent.node.attrs.index;l=(parseInt(b)+1).toString()}}const u=c.blockContent.node,p=u.attrs.index,f=((a=d==null?void 0:d.firstChild)==null?void 0:a.type.name)!=="numberedListItem";if(p!==l||u.attrs.start&&!f){r=!0;const{start:m,...g}=u.attrs;o.setNodeMarkup(c.blockContent.beforePos,void 0,{...g,index:l,...typeof m=="number"&&f&&{start:m}})}}}),r?o:null}}),ko={...A,start:{default:void 0,type:"number"}},Os=j({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{...be(ko),index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}},addInputRules(){return[new w.InputRule({find:new RegExp("^(\\d+)\\.\\s$"),handler:({state:e,chain:n,range:t,match:o})=>{const r=T(e);if(!r.isBlockContainer||r.blockContent.node.type.spec.content!=="inline*"||r.blockNoteType==="numberedListItem"||r.blockNoteType==="heading")return;const s=parseInt(o[1]);n().command(U(r.bnBlock.beforePos,{type:"numberedListItem",props:s===1&&{}||{start:s}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>tt(this.options.editor),"Mod-Shift-7":()=>{const e=T(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins(){return[Hs()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if(typeof e=="string")return!1;const n=e.parentElement;if(n===null)return!1;if(n.tagName==="OL"||n.tagName==="DIV"&&((t=n.parentElement)==null?void 0:t.tagName)==="OL"){const o=parseInt(n.getAttribute("start")||"1")||1;return e.previousSibling||o===1?{}:{start:o}}return!1},getContent:(e,n)=>Ot(e,n,this.name),priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),_s=Z(Os,ko),Rs={...A},Vs=j({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=T(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"p",getAttrs:e=>{var n;return typeof e=="string"||!((n=e.textContent)!=null&&n.trim())?!1:{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"p",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Us=Z(Vs,Rs),Fs={...A},$s=j({name:"quote",content:"inline*",group:"blockContent",addInputRules(){return[new w.InputRule({find:new RegExp("^>\\s$"),handler:({state:e,chain:n,range:t})=>{const o=T(e);!o.isBlockContainer||o.blockContent.node.type.spec.content!=="inline*"||n().command(U(o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=T(this.editor.state);return!e.isBlockContainer||e.blockContent.node.type.spec.content!=="inline*"?!0:this.editor.commands.command(U(e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"blockquote",node:"quote",getContent:(e,n)=>{const o=e.cloneNode(!0);return gn(o),E.DOMParser.fromSchema(n).parse(o,{topNode:n.nodes.paragraph.create()}).content}}]},renderHTML({HTMLAttributes:e}){var n,t;return $(this.name,"blockquote",{...((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},...e},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Ws=Z($s,Fs),zs=35,_t=120,qs=31,Ks=w.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[L.columnResizing({cellMinWidth:zs,defaultCellMinWidth:_t,View:null}),L.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.insertContent({type:"hardBreak"}),!0):!1,Backspace:()=>{const e=this.editor.state.selection,n=e.empty,t=e.$head.parentOffset===0,o=e.$head.node().type.name==="tableParagraph";return n&&t&&o},Tab:()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>L.goToNextCell(1)(e,n,t)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:n,view:t})=>L.goToNextCell(-1)(e,n,t))}},extendNodeSchema(e){const n={name:e.name,options:e.options,storage:e.storage};return{tableRole:w.callOrReturn(w.getExtensionField(e,"tableRole",n))}}}),js={textColor:A.textColor},Gs=j({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",marks:"deletion insertion modification",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({node:e,HTMLAttributes:n}){var r,s,i;const t=$(this.name,"table",{...((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},...n},((s=this.options.domAttributes)==null?void 0:s.inlineContent)||{}),o=document.createElement("colgroup");for(const a of e.children[0].children)if(a.attrs.colwidth)for(const c of a.attrs.colwidth){const d=document.createElement("col");c&&(d.style=`width: ${c}px`),o.appendChild(d)}else o.appendChild(document.createElement("col"));return(i=t.dom.firstChild)==null||i.appendChild(o),t},addNodeView(){return({node:e,HTMLAttributes:n})=>{var o;class t extends L.TableView{constructor(s,i,a){super(s,i),this.node=s,this.cellMinWidth=i,this.blockContentHTMLAttributes=a;const l=document.createElement("div");l.className=Q("bn-block-content",a.class),l.setAttribute("data-content-type","table");for(const[p,f]of Object.entries(a))p!=="class"&&l.setAttribute(p,f);const c=this.dom,d=document.createElement("div");d.className="tableWrapper-inner",d.appendChild(c.firstChild),c.appendChild(d),l.appendChild(c);const u=document.createElement("div");u.className="table-widgets-container",u.style.position="relative",c.appendChild(u),this.dom=l}ignoreMutation(s){return!s.target.closest(".tableWrapper-inner")||super.ignoreMutation(s)}}return new t(e,_t,{...((o=this.options.domAttributes)==null?void 0:o.blockContent)||{},...n})}}}),Ys=j({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p",getAttrs:e=>{if(typeof e=="string"||!e.textContent||!e.closest("[data-content-type]"))return!1;const n=e.parentElement;return n===null?!1:n.tagName==="TD"||n.tagName==="TH"?{}:!1},node:"tableParagraph"}]},renderHTML({HTMLAttributes:e}){return["p",e,0]}}),Xs=w.Node.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)+",tableRole:"row",marks:"deletion insertion modification",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:e}){return["tr",w.mergeAttributes(this.options.HTMLAttributes,e),0]}});function Qt(e,n){const o=E.DOMParser.fromSchema(n).parse(e,{topNode:n.nodes.blockGroup.create()}),r=[];return o.content.descendants(s=>{if(s.isInline)return r.push(s),!1}),E.Fragment.fromArray(r)}const Js=Z(Gs,js,[Ks,Ys,Hr.TableHeader.extend({content:"tableContent+",parseHTML(){return[{tag:"th",getContent:(e,n)=>Qt(e,n)}]}}),Dr.TableCell.extend({content:"tableContent+",parseHTML(){return[{tag:"td",getContent:(e,n)=>Qt(e,n)}]}}),Xs]),en=e=>{const n=e.src||void 0,t=e.width||void 0;return{url:n,previewWidth:t}},yo='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>',wo={textAlignment:A.textAlignment,backgroundColor:A.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},Co={type:"video",propSchema:wo,content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},vo=(e,n)=>{const t=document.createElement("div");t.innerHTML=yo;const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",n.resolveFileUrl?n.resolveFileUrl(e.props.url).then(s=>{r.src=s}):r.src=e.props.url,r.controls=!0,r.contentEditable="false",r.draggable=!1,r.width=e.props.previewWidth,o.appendChild(r),Ht(e,n,{dom:o},o,n.dictionary.file_blocks.video.add_button_text,t.firstElementChild)},So=e=>{if(e.tagName==="VIDEO")return e.closest("figure")?void 0:en(e);if(e.tagName==="FIGURE"){const n=Ie(e,"video");if(!n)return;const{targetElement:t,caption:o}=n;return{...en(t),caption:o}}},Eo=e=>{if(!e.props.url){const t=document.createElement("p");return t.textContent="Add video",{dom:t}}let n;return e.props.showPreview?(n=document.createElement("video"),n.src=e.props.url,e.props.previewWidth&&(n.width=e.props.previewWidth)):(n=document.createElement("a"),n.href=e.props.url,n.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?et(n,e.props.caption):Le(n,e.props.caption):{dom:n}},Bo=ke(Co,{render:vo,parse:So,toExternalHTML:Eo}),Rt={paragraph:Us,heading:Bs,quote:Ws,codeBlock:Qn,toggleListItem:Ps,bulletListItem:Ls,numberedListItem:_s,checkListItem:Ns,table:Js,file:so,image:mo,video:Bo,audio:Jn},To=Tt(Rt),Vt={bold:ne(qr.default,"boolean"),italic:ne(jr.default,"boolean"),underline:ne(Yr.default,"boolean"),strike:ne(Gr.default,"boolean"),code:ne(Kr.default,"boolean"),textColor:vs,backgroundColor:ws},Zs=It(Vt),Ut={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},xo=Pt(Ut);function V(e,n){return e in n.schema.blockSchema&&n.schema.blockSchema[e]===To[e]}function Qs(e,n,t){return e in t.schema.blockSchema&&t.schema.blockSchema[e]===n}function Po(e,n){return e in n.schema.inlineContentSchema&&n.schema.inlineContentSchema[e]===xo[e]}function ei(e,n,t){return e in t.schema.inlineContentSchema&&t.schema.inlineContentSchema[e]===n}function Mo(e,n,t){return n.type===e&&n.type in t.schema.blockSchema&&V(n.type,t)}function ti(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock||!1}function ni(e,n){return e.type in n.schema.blockSchema&&n.schema.blockSchema[e.type].isFileBlock&&"showPreview"in n.schema.blockSchema[e.type].propSchema||!1}function oi(e,n){return n.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function Io(e,n,t){return n in t.schema.blockSchema&&e in t.schema.blockSchema[n].propSchema&&t.schema.blockSchema[n].propSchema[e]===A[e]}function ri(e,n,t){return Io(e,n.type,t)}function kt(e){return e instanceof L.CellSelection}const si=async e=>{const n=new FormData;return n.append("file",e),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:n})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};function ii(e){let n=e.getTextCursorPosition().block,t=e.schema.blockSchema[n.type].content;for(;t==="none";){if(n=e.getTextCursorPosition().nextBlock,n===void 0)return;t=e.schema.blockSchema[n.type].content,e.setTextCursorPosition(n,"end")}}function D(e,n){const t=e.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");let o;return Array.isArray(t.content)&&(t.content.length===1&&oe(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?(o=e.updateBlock(t,n),e.setTextCursorPosition(o)):(o=e.insertBlocks([n],t,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),ii(e),o}function ai(e){const n=[];return V("heading",e)&&n.push({onItemClick:()=>{D(e,{type:"heading",props:{level:1}})},badge:X("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{D(e,{type:"heading",props:{level:2}})},badge:X("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{D(e,{type:"heading",props:{level:3}})},badge:X("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),V("quote",e)&&n.push({onItemClick:()=>{D(e,{type:"quote"})},key:"quote",...e.dictionary.slash_menu.quote}),V("toggleListItem",e)&&n.push({onItemClick:()=>{D(e,{type:"toggleListItem"})},badge:X("Mod-Shift-6"),key:"toggle_list",...e.dictionary.slash_menu.toggle_list}),V("numberedListItem",e)&&n.push({onItemClick:()=>{D(e,{type:"numberedListItem"})},badge:X("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),V("bulletListItem",e)&&n.push({onItemClick:()=>{D(e,{type:"bulletListItem"})},badge:X("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),V("checkListItem",e)&&n.push({onItemClick:()=>{D(e,{type:"checkListItem"})},badge:X("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),V("paragraph",e)&&n.push({onItemClick:()=>{D(e,{type:"paragraph"})},badge:X("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),V("codeBlock",e)&&n.push({onItemClick:()=>{D(e,{type:"codeBlock"})},badge:X("Mod-Alt-c"),key:"code_block",...e.dictionary.slash_menu.code_block}),V("table",e)&&n.push({onItemClick:()=>{D(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),V("image",e)&&n.push({onItemClick:()=>{const t=D(e,{type:"image"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"image",...e.dictionary.slash_menu.image}),V("video",e)&&n.push({onItemClick:()=>{const t=D(e,{type:"video"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"video",...e.dictionary.slash_menu.video}),V("audio",e)&&n.push({onItemClick:()=>{const t=D(e,{type:"audio"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"audio",...e.dictionary.slash_menu.audio}),V("file",e)&&n.push({onItemClick:()=>{const t=D(e,{type:"file"});e.transact(o=>o.setMeta(e.filePanel.plugins[0],{block:t}))},key:"file",...e.dictionary.slash_menu.file}),V("heading",e)&&(n.push({onItemClick:()=>{D(e,{type:"heading",props:{level:1,isToggleable:!0}})},key:"toggle_heading",...e.dictionary.slash_menu.toggle_heading},{onItemClick:()=>{D(e,{type:"heading",props:{level:2,isToggleable:!0}})},key:"toggle_heading_2",...e.dictionary.slash_menu.toggle_heading_2},{onItemClick:()=>{D(e,{type:"heading",props:{level:3,isToggleable:!0}})},key:"toggle_heading_3",...e.dictionary.slash_menu.toggle_heading_3}),e.settings.heading.levels.filter(t=>t>3).forEach(t=>{n.push({onItemClick:()=>{D(e,{type:"heading",props:{level:t}})},key:`heading_${t}`,...e.dictionary.slash_menu[`heading_${t}`]})})),n.push({onItemClick:()=>{e.openSuggestionMenu(":",{deleteTriggerCharacter:!0,ignoreQueryLength:!0})},key:"emoji",...e.dictionary.slash_menu.emoji}),n}function li(e,n){return e.filter(({title:t,aliases:o})=>t.toLowerCase().includes(n.toLowerCase())||o&&o.filter(r=>r.toLowerCase().includes(n.toLowerCase())).length!==0)}function it(e){return e&&Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}class Ce{constructor(n){h(this,"blockSpecs");h(this,"inlineContentSpecs");h(this,"styleSpecs");h(this,"blockSchema");h(this,"inlineContentSchema");h(this,"styleSchema");h(this,"BlockNoteEditor","only for types");h(this,"Block","only for types");h(this,"PartialBlock","only for types");this.blockSpecs=it(n==null?void 0:n.blockSpecs)||Rt,this.inlineContentSpecs=it(n==null?void 0:n.inlineContentSpecs)||Ut,this.styleSpecs=it(n==null?void 0:n.styleSpecs)||Vt,this.blockSchema=Tt(this.blockSpecs),this.inlineContentSchema=Pt(this.inlineContentSpecs),this.styleSchema=It(this.styleSpecs)}static create(n){return new Ce(n)}}const Lo={type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},Ao=()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},No=e=>{if(e.tagName==="DIV"&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},Do=()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}},Ho=ke(Lo,{render:Ao,parse:No,toExternalHTML:Do}),Ft=Ce.create({blockSpecs:{pageBreak:Ho}}),ci=e=>Ce.create({blockSpecs:{...e.blockSpecs,...Ft.blockSpecs},inlineContentSpecs:e.inlineContentSpecs,styleSpecs:e.styleSpecs});function Oo(e){return"pageBreak"in e.schema.blockSchema&&e.schema.blockSchema.pageBreak===Ft.blockSchema.pageBreak}function di(e){const n=[];return Oo(e)&&n.push({...e.dictionary.slash_menu.page_break,onItemClick:()=>{D(e,{type:"pageBreak"})},key:"page_break"}),n}function ui(e){return e.transact(n=>{const t=J(n.doc,n.selection.anchor);if(n.selection instanceof L.CellSelection)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:n.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:n.selection.$headCell.pos-t.posBeforeNode};if(n.selection instanceof C.NodeSelection)return{type:"node",anchorBlockId:t.node.attrs.id};{const o=J(n.doc,n.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:o.node.attrs.id,anchorOffset:n.selection.anchor-t.posBeforeNode,headOffset:n.selection.head-o.posBeforeNode}}})}function pi(e,n){var r,s;const t=(r=W(n.anchorBlockId,e.doc))==null?void 0:r.posBeforeNode;if(t===void 0)throw new Error(`Could not find block with ID ${n.anchorBlockId} to update selection`);let o;if(n.type==="cell")o=L.CellSelection.create(e.doc,t+n.anchorCellOffset,t+n.headCellOffset);else if(n.type==="node")o=C.NodeSelection.create(e.doc,t+1);else{const i=(s=W(n.headBlockId,e.doc))==null?void 0:s.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${n.headBlockId} to update selection`);o=C.TextSelection.create(e.doc,t+n.anchorOffset,i+n.headOffset)}e.setSelection(o)}function yt(e){return e.map(n=>n.type==="columnList"?n.children.map(t=>yt(t.children)).flat():{...n,children:yt(n.children)}).flat()}function _o(e,n,t){e.transact(o=>{var i;const r=((i=e.getSelection())==null?void 0:i.blocks)||[e.getTextCursorPosition().block],s=ui(e);e.removeBlocks(r),e.insertBlocks(yt(r),n,t),pi(o,s)})}function Ro(e){return!e||e.type!=="columnList"}function Vo(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[n.children.length-1],r="after"):(o=n,r="before"):t&&(o=t,r="before"),!o||!r)return;const s=e.getParentBlock(o);return Ro(s)?{referenceBlock:o,placement:r}:Vo(e,r==="after"?o:e.getPrevBlock(o),s)}function Uo(e,n,t){let o,r;if(n?n.children.length>0?(o=n.children[0],r="before"):(o=n,r="after"):t&&(o=t,r="after"),!o||!r)return;const s=e.getParentBlock(o);return Ro(s)?{referenceBlock:o,placement:r}:Uo(e,r==="before"?o:e.getNextBlock(o),s)}function hi(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[0])||e.getTextCursorPosition().block,o=Vo(e,e.getPrevBlock(t),e.getParentBlock(t));o&&_o(e,o.referenceBlock,o.placement)})}function fi(e){e.transact(()=>{const n=e.getSelection(),t=(n==null?void 0:n.blocks[(n==null?void 0:n.blocks.length)-1])||e.getTextCursorPosition().block,o=Uo(e,e.getNextBlock(t),e.getParentBlock(t));o&&_o(e,o.referenceBlock,o.placement)})}function mi(e,n,t){const{$from:o,$to:r}=e.selection,s=o.blockRange(r,m=>m.childCount>0&&(m.type.name==="blockGroup"||m.type.name==="column"));if(!s)return!1;const i=s.startIndex;if(i===0)return!1;const l=s.parent.child(i-1);if(l.type!==n)return!1;const c=l.lastChild&&l.lastChild.type===t,d=E.Fragment.from(c?n.create():null),u=new E.Slice(E.Fragment.from(n.create(null,E.Fragment.from(t.create(null,d)))),c?3:1,0),p=s.start,f=s.end;return e.step(new he.ReplaceAroundStep(p-(c?3:1),f,p,f,u,1,!0)).scrollIntoView(),!0}function Fo(e){return e.transact(n=>mi(n,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function gi(e){e._tiptapEditor.commands.liftListItem("blockContainer")}function bi(e){return e.transact(n=>{const{bnBlock:t}=Te(n);return n.doc.resolve(t.beforePos).nodeBefore!==null})}function ki(e){return e.transact(n=>{const{bnBlock:t}=Te(n);return n.doc.resolve(t.beforePos).depth>1})}function $o(e,n){const t=typeof n=="string"?n:n.id,o=R(e),r=W(t,e);if(r)return x(r.node,o)}function Wo(e,n){const t=typeof n=="string"?n:n.id,o=W(t,e),r=R(e);if(!o)return;const i=e.resolve(o.posBeforeNode).nodeBefore;if(i)return x(i,r)}function zo(e,n){const t=typeof n=="string"?n:n.id,o=W(t,e),r=R(e);if(!o)return;const i=e.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(i)return x(i,r)}function qo(e,n){const t=typeof n=="string"?n:n.id,o=R(e),r=W(t,e);if(!r)return;const s=e.resolve(r.posBeforeNode),i=s.node(),a=s.node(-1),l=a.type.name!=="doc"?i.type.name==="blockGroup"?a:i:void 0;if(l)return x(l,o)}function yi(e,n,t,o={updateSelection:!0}){let{from:r,to:s}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},i=!0,a=!0,l="";if(t.forEach(c=>{c.check(),i&&c.isText&&c.marks.length===0?l+=c.text:i=!1,a=a?c.isBlock:!1}),r===s&&a){const{parent:c}=e.doc.resolve(r);c.isTextblock&&!c.type.spec.code&&!c.childCount&&(r-=1,s+=1)}return i?e.insertText(l,r,s):e.replaceWith(r,s,t),o.updateSelection&&w.selectionToInsertionEnd(e,e.steps.length-1,-1),!0}function wi(e){const n=R(e);if(e.selection.empty||"node"in e.selection)return;const t=e.doc.resolve(J(e.doc,e.selection.from).posBeforeNode),o=e.doc.resolve(J(e.doc,e.selection.to).posBeforeNode),r=(c,d)=>{const u=t.posAtIndex(c,d),p=e.doc.resolve(u).nodeAfter;if(!p)throw new Error(`Error getting selection - node not found at position ${u}`);return x(p,n)},s=[],i=t.sharedDepth(o.pos),a=t.index(i),l=o.index(i);if(t.depth>i){s.push(x(t.nodeAfter,n));for(let c=t.depth;c>i;c--)if(t.node(c).type.isInGroup("childContainer")){const u=t.index(c)+1,p=t.node(c).childCount;for(let f=u;f<p;f++)s.push(r(f,c))}}else s.push(r(a,i));for(let c=a+1;c<=l;c++)s.push(r(c,i));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:s}}function Ci(e,n,t){const o=typeof n=="string"?n:n.id,r=typeof t=="string"?t:t.id,s=R(e),i=we(s);if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const a=W(o,e.doc);if(!a)throw new Error(`Block with ID ${o} not found`);const l=W(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const c=ee(a),d=ee(l),u=i.blockSchema[c.blockNoteType],p=i.blockSchema[d.blockNoteType];if(!c.isBlockContainer||u.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!d.isBlockContainer||p.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let f,m;if(u.content==="table"){const g=L.TableMap.get(c.blockContent.node);f=c.blockContent.beforePos+g.positionAt(0,0,c.blockContent.node)+1+2}else f=c.blockContent.beforePos+1;if(p.content==="table"){const g=L.TableMap.get(d.blockContent.node),b=d.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,d.blockContent.node)+1,k=e.doc.resolve(b).nodeAfter.nodeSize;m=b+k-2}else m=d.blockContent.afterPos-1;e.setSelection(C.TextSelection.create(e.doc,f,m))}function vi(e){const n=R(e);let t=e.selection.$from,o=e.selection.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=e.doc.resolve(o.pos+1);for(;o.parentOffset===0&&o.depth>0;)o=e.doc.resolve(o.pos-1);for(;t.parentOffset===0&&t.depth>0;)t=e.doc.resolve(t.pos-1);for(;t.parentOffset>=t.parent.nodeSize-2&&t.depth>0;)t=e.doc.resolve(t.pos+1);const r=Cn(e.doc.slice(t.pos,o.pos,!0),n);return{_meta:{startPos:t.pos,endPos:o.pos},...r}}function Si(e){const{bnBlock:n}=Te(e),t=R(e.doc),o=e.doc.resolve(n.beforePos),r=o.nodeBefore,s=e.doc.resolve(n.afterPos).nodeAfter;let i;return o.depth>1&&(i=o.node(),i.type.isInGroup("bnBlock")||(i=o.node(o.depth-1))),{block:x(n.node,t),prevBlock:r===null?void 0:x(r,t),nextBlock:s===null?void 0:x(s,t),parentBlock:i===void 0?void 0:x(i,t)}}function Ko(e,n,t="start"){const o=typeof n=="string"?n:n.id,r=R(e.doc),s=we(r),i=W(o,e.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const a=ee(i),l=s.blockSchema[a.blockNoteType].content;if(a.isBlockContainer){const c=a.blockContent;if(l==="none"){e.setSelection(C.NodeSelection.create(e.doc,c.beforePos));return}if(l==="inline")t==="start"?e.setSelection(C.TextSelection.create(e.doc,c.beforePos+1)):e.setSelection(C.TextSelection.create(e.doc,c.afterPos-1));else if(l==="table")t==="start"?e.setSelection(C.TextSelection.create(e.doc,c.beforePos+4)):e.setSelection(C.TextSelection.create(e.doc,c.afterPos-4));else throw new K(l)}else{const c=t==="start"?a.childContainer.node.firstChild:a.childContainer.node.lastChild;Ko(e,c.attrs.id,t)}}exports.esmDependencies=void 0;async function Ae(){if(exports.esmDependencies)return exports.esmDependencies;const e=await Promise.all([import("rehype-parse"),import("rehype-stringify"),import("unified"),import("hast-util-from-dom"),import("rehype-remark"),import("remark-gfm"),import("remark-stringify"),import("remark-parse"),import("remark-rehype"),import("rehype-format")]);return exports.esmDependencies={rehypeParse:e[0],rehypeStringify:e[1],unified:e[2],hastUtilFromDom:e[3],rehypeRemark:e[4],remarkGfm:e[5],remarkStringify:e[6],remarkParse:e[7],remarkRehype:e[8],rehypeFormat:e[9]},exports.esmDependencies}function Ei(){const e=n=>{let t=n.children.length;for(let o=0;o<t;o++){const r=n.children[o];if(r.type==="element"&&(e(r),r.tagName==="u"))if(r.children.length>0){n.children.splice(o,1,...r.children);const s=r.children.length-1;t+=s,o+=s}else n.children.splice(o,1),t--,o--}};return e}function Bi(){const e=exports.esmDependencies;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const n=t=>{var o;if(t.children&&"length"in t.children&&t.children.length)for(let r=t.children.length-1;r>=0;r--){const s=t.children[r],i=r+1<t.children.length?t.children[r+1]:void 0;s.type==="element"&&s.tagName==="input"&&((o=s.properties)==null?void 0:o.type)==="checkbox"&&(i==null?void 0:i.type)==="element"&&i.tagName==="p"?(i.tagName="span",i.children.splice(0,0,e.hastUtilFromDom.fromDom(document.createTextNode(" ")))):n(s)}};return n}function nt(e){const n=exports.esmDependencies;if(!n)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return n.unified.unified().use(n.rehypeParse.default,{fragment:!0}).use(Ei).use(Bi).use(n.rehypeRemark.default).use(n.remarkGfm.default).use(n.remarkStringify.default,{handlers:{text:o=>o.value}}).processSync(e).value}async function jo(e,n,t,o){await Ae();const s=Me(n,t).exportBlocks(e,o);return nt(s)}function Ti(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function xi(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function Pi(e){e.querySelectorAll("li > ul, li > ol").forEach(n=>{const t=Ti(n),o=n.parentElement,r=Array.from(o.childNodes).slice(t+1);n.remove(),r.forEach(s=>{s.remove()}),o.insertAdjacentElement("afterend",n),r.reverse().forEach(s=>{if(xi(s))return;const i=document.createElement("li");i.append(s),n.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function Mi(e){e.querySelectorAll("li + ul, li + ol").forEach(n=>{var s,i;const t=n.previousElementSibling,o=document.createElement("div");t.insertAdjacentElement("afterend",o),o.append(t);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),o.append(r);((s=o.nextElementSibling)==null?void 0:s.nodeName)==="UL"||((i=o.nextElementSibling)==null?void 0:i.nodeName)==="OL";)r.append(o.nextElementSibling)})}let tn=null;function Ii(){return tn||(tn=document.implementation.createHTMLDocument("title"))}function Go(e){if(typeof e=="string"){const n=Ii().createElement("div");n.innerHTML=e,e=n}return Pi(e),Mi(e),e}async function $t(e,n){const t=Go(e),r=E.DOMParser.fromSchema(n).parse(t,{topNode:n.nodes.blockGroup.create()}),s=[];for(let i=0;i<r.childCount;i++)s.push(x(r.child(i),n));return s}function Li(e,n){const t=n.value?n.value:"",o={};n.lang&&(o["data-language"]=n.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:t}]};return n.meta&&(r.data={meta:n.meta}),e.patch(n,r),r=e.applyData(n,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(n,r),r}async function Wt(e){const n=await Ae();return n.unified.unified().use(n.remarkParse.default).use(n.remarkGfm.default).use(n.remarkRehype.default,{handlers:{...n.remarkRehype.defaultHandlers,code:Li}}).use(n.rehypeStringify.default).processSync(e).value}async function Yo(e,n){const t=await Wt(e);return $t(t,n)}const zt=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function Ai(e,n){if(!e.startsWith(".")||!n.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===n}function Ni(e,n){const t=e.split("/"),o=n.split("/");if(t.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${n} is not a valid MIME type.`);return t[1]==="*"||o[1]==="*"?t[0]===o[0]:(t[0]==="*"||o[0]==="*"||t[0]===o[0])&&t[1]===o[1]}function nn(e,n,t,o="after"){let r;return Array.isArray(n.content)&&n.content.length===0?r=e.updateBlock(n,t).id:r=e.insertBlocks([t],n,o)[0].id,r}async function Xo(e,n){var i;if(!n.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const t="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(t===null)return;let o=null;for(const a of zt)if(t.types.includes(a)){o=a;break}if(o!=="Files")return;const r=t.items;if(!r)return;e.preventDefault();const s=Object.values(n.schema.blockSchema).filter(a=>a.isFileBlock);for(let a=0;a<r.length;a++){let l="file";for(const d of s)for(const u of d.fileBlockAccept||[]){const p=u.startsWith("."),f=r[a].getAsFile();if(f&&(!p&&f.type&&Ni(r[a].type,u)||p&&Ai("."+f.name.split(".").pop(),u))){l=d.type;break}}const c=r[a].getAsFile();if(c){const d={type:l,props:{name:c.name}};let u;if(e.type==="paste"){const m=n.getTextCursorPosition().block;u=nn(n,m,d)}else if(e.type==="drop"){const m={left:e.clientX,top:e.clientY},g=(i=n.prosemirrorView)==null?void 0:i.posAtCoords(m);if(!g)return;u=n.transact(b=>{var v;const k=J(b.doc,g.pos),y=(v=n.prosemirrorView)==null?void 0:v.dom.querySelector(`[data-id="${k.node.attrs.id}"]`),S=y==null?void 0:y.getBoundingClientRect();return nn(n,n.getBlock(k.node.attrs.id),d,S&&(S.top+S.bottom)/2>m.top?"before":"after")})}else return;const p=await n.uploadFile(c,u),f=typeof p=="string"?{props:{url:p}}:{...p};n.updateBlock(u,f)}}}const Di=e=>w.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new C.Plugin({props:{handleDOMEvents:{drop(n,t){if(!e.isEditable)return;let o=null;for(const r of zt)if(t.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(Xo(t,e),!0):!1}}}})]}}),Hi=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,Oi=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,_i=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,Ri=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,Vi=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,Ui=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,Fi=/\n{2} {0,3}-{2,48}\n{2}/,$i=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,Wi=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,zi=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,qi=/^\s*\|(.+\|)+\s*$/m,Ki=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,ji=/^\s*\|(.+\|)+\s*$/m,Gi=e=>Hi.test(e)||Oi.test(e)||_i.test(e)||Ri.test(e)||Vi.test(e)||Ui.test(e)||Fi.test(e)||$i.test(e)||Wi.test(e)||zi.test(e)||qi.test(e)||Ki.test(e)||ji.test(e);async function Yi(e,n){const{schema:t}=n.state;if(!e.clipboardData)return!1;const o=e.clipboardData.getData("text/plain");if(!o)return!1;if(!t.nodes.codeBlock)return n.pasteText(o),!0;const r=e.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;return i?(n.pasteHTML(`<pre><code class="language-${i}">${o.replace(/\r\n?/g,`
11
+ `)}</code></pre>`),!0):!1}function Xi({event:e,editor:n,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:o}){var a;if(n.transact(l=>l.selection.$from.parent.type.spec.code&&l.selection.$to.parent.type.spec.code)){const l=(a=e.clipboardData)==null?void 0:a.getData("text/plain");if(l)return n.pasteText(l),!0}let s;for(const l of zt)if(e.clipboardData.types.includes(l)){s=l;break}if(!s)return!0;if(s==="vscode-editor-data")return Yi(e,n.prosemirrorView),!0;if(s==="Files")return Xo(e,n),!0;const i=e.clipboardData.getData(s);if(s==="blocknote/html")return n.pasteHTML(i,!0),!0;if(s==="text/markdown")return n.pasteMarkdown(i),!0;if(t){const l=e.clipboardData.getData("text/plain");if(Gi(l))return n.pasteMarkdown(l),!0}return s==="text/html"?(n.pasteHTML(i),!0):o?(n.pasteMarkdown(i),!0):(n.pasteText(i),!0)}const Ji=(e,n)=>w.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new C.Plugin({props:{handleDOMEvents:{paste(t,o){if(o.preventDefault(),!!e.isEditable)return n({event:o,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>Xi({event:o,editor:e,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function Jo(e){const n=[];return e.descendants(t=>{var r,s;const o=R(t);return t.type.name==="blockContainer"&&((r=t.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:t.type.name==="columnList"&&t.childCount===1?((s=t.firstChild)==null||s.forEach(i=>{n.push(x(i,o))}),!1):t.type.isInGroup("bnBlock")?(n.push(x(t,o)),!1):!0}),n}function Zi(e,n,t){var a;let o=!1;const r=e.state.selection instanceof L.CellSelection;if(!r){const l=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,c=[];for(let d=0;d<l.childCount;d++)c.push(l.child(d));o=c.find(d=>d.type.isInGroup("bnBlock")||d.type.name==="blockGroup"||d.type.spec.group==="blockContent")===void 0,o&&(n=l)}let s;const i=Me(e.state.schema,t);if(r){((a=n.firstChild)==null?void 0:a.type.name)==="table"&&(n=n.firstChild.content);const l=xt(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(o){const l=xe(n,t.schema.inlineContentSchema,t.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=Jo(n);s=i.exportBlocks(l,{})}return s}function qt(e,n){"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&n.transact(i=>i.setSelection(new C.NodeSelection(i.doc.resolve(e.state.selection.from-1))));const t=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=Zi(e,o,n),s=nt(r);return{clipboardHTML:t,externalHTML:r,markdown:s}}const on=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let n=e.focusNode;for(;n;){if(n instanceof HTMLElement&&n.getAttribute("contenteditable")==="false")return!0;n=n.parentElement}return!1},rn=(e,n,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=qt(n,e);t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",s)},Qi=e=>w.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return Ae(),[new C.Plugin({props:{handleDOMEvents:{copy(n,t){return on()||rn(e,n,t),!0},cut(n,t){return on()||(rn(e,n,t),n.editable&&n.dispatch(n.state.tr.deleteSelection())),!0},dragstart(n,t){if(!("node"in n.state.selection)||n.state.selection.node.type.spec.group!=="blockContent")return;e.transact(i=>i.setSelection(new C.NodeSelection(i.doc.resolve(n.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=qt(n,e);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",s),!0}}}})]}}),ea=w.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{backgroundColor:{default:A.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):A.backgroundColor.default,renderHTML:e=>e.backgroundColor===A.backgroundColor.default?{}:{"data-background-color":e.backgroundColor}}}}]}});class ot{constructor(){h(this,"callbacks",{})}on(n,t){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(t),()=>this.off(n,t)}emit(n,...t){const o=this.callbacks[n];o&&o.forEach(r=>r.apply(this,t))}off(n,t){const o=this.callbacks[n];o&&(t?this.callbacks[n]=o.filter(r=>r!==t):delete this.callbacks[n])}removeAllListeners(){this.callbacks={}}}class _ extends ot{constructor(...t){super();h(this,"plugins",[])}static key(){throw new Error("You must implement the key method in your extension")}addProsemirrorPlugin(t){this.plugins.push(t)}get priority(){}}class ta extends _{constructor(){super();h(this,"beforeChangeCallbacks",[]);this.addProsemirrorPlugin(new C.Plugin({filterTransaction:t=>{let o;return this.beforeChangeCallbacks.reduce((r,s)=>r===!1?r:s({getChanges(){return o||(o=Nt(t),o)},tr:t})!==!1,!0)}}))}static key(){return"blockChange"}subscribe(t){return this.beforeChangeCallbacks.push(t),()=>{this.beforeChangeCallbacks=this.beforeChangeCallbacks.filter(o=>o!==t)}}}const ue=class ue extends _{constructor(t){super();h(this,"provider");h(this,"recentlyUpdatedCursors");h(this,"renderCursor",(t,o)=>{let r=this.recentlyUpdatedCursors.get(o);if(!r){const s=(this.collaboration.renderCursor??ue.defaultCursorRender)(t);this.collaboration.showCursorLabels!=="always"&&(s.addEventListener("mouseenter",()=>{const i=this.recentlyUpdatedCursors.get(o);i.element.setAttribute("data-active",""),i.hideTimeout&&(clearTimeout(i.hideTimeout),this.recentlyUpdatedCursors.set(o,{element:i.element,hideTimeout:void 0}))}),s.addEventListener("mouseleave",()=>{const i=this.recentlyUpdatedCursors.get(o);this.recentlyUpdatedCursors.set(o,{element:i.element,hideTimeout:setTimeout(()=>{i.element.removeAttribute("data-active")},2e3)})})),r={element:s,hideTimeout:void 0},this.recentlyUpdatedCursors.set(o,r)}return r.element});h(this,"updateUser",t=>{this.provider.awareness.setLocalStateField("user",t)});this.collaboration=t,this.provider=t.provider,this.recentlyUpdatedCursors=new Map,this.provider.awareness.setLocalStateField("user",t.user),t.showCursorLabels!=="always"&&this.provider.awareness.on("change",({updated:o})=>{for(const r of o){const s=this.recentlyUpdatedCursors.get(r);s&&(s.element.setAttribute("data-active",""),s.hideTimeout&&clearTimeout(s.hideTimeout),this.recentlyUpdatedCursors.set(r,{element:s.element,hideTimeout:setTimeout(()=>{s.element.removeAttribute("data-active")},2e3)}))}}),this.addProsemirrorPlugin(H.yCursorPlugin(this.provider.awareness,{selectionBuilder:H.defaultSelectionBuilder,cursorBuilder:this.renderCursor}))}static key(){return"yCursorPlugin"}get priority(){return 999}static isDarkColor(t){const o=t.charAt(0)==="#"?t.substring(1,7):t,r=parseInt(o.substring(0,2),16),s=parseInt(o.substring(2,4),16),i=parseInt(o.substring(4,6),16),l=[r/255,s/255,i/255].map(d=>d<=.03928?d/12.92:Math.pow((d+.055)/1.055,2.4));return .2126*l[0]+.7152*l[1]+.0722*l[2]<=.179}};h(ue,"defaultCursorRender",t=>{const o=document.createElement("span");o.classList.add("bn-collaboration-cursor__base");const r=document.createElement("span");r.setAttribute("contentedEditable","false"),r.classList.add("bn-collaboration-cursor__caret"),r.setAttribute("style",`background-color: ${t.color}; color: ${ue.isDarkColor(t.color)?"white":"black"}`);const s=document.createElement("span");return s.classList.add("bn-collaboration-cursor__label"),s.setAttribute("style",`background-color: ${t.color}; color: ${ue.isDarkColor(t.color)?"white":"black"}`),s.insertBefore(document.createTextNode(t.name),null),r.insertBefore(s,null),o.insertBefore(document.createTextNode("⁠"),null),o.insertBefore(r,null),o.insertBefore(document.createTextNode("⁠"),null),o});let We=ue;class wt extends _{static key(){return"ySyncPlugin"}constructor(n){super(),this.addProsemirrorPlugin(H.ySyncPlugin(n))}get priority(){return 1001}}class Ct extends _{static key(){return"yUndoPlugin"}constructor({editor:n}){super(),this.addProsemirrorPlugin(H.yUndoPlugin({trackedOrigins:[n]}))}get priority(){return 1e3}}const Zo=w.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:e=>!!e.getAttribute("data-orphan"),renderHTML:e=>e.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:e=>e.getAttribute("data-bn-thread-id"),renderHTML:e=>({"data-bn-thread-id":e.threadId}),default:""}}},renderHTML({HTMLAttributes:e}){return["span",w.mergeAttributes(e,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(e){return e.name==="comment"?{blocknoteIgnore:!0}:{}}});class na extends ot{constructor(t){super();h(this,"userCache",new Map);h(this,"loadingUsers",new Set);this.resolveUsers=t}async loadUsers(t){const o=t.filter(r=>!this.userCache.has(r)&&!this.loadingUsers.has(r));if(o.length!==0){for(const r of o)this.loadingUsers.add(r);try{const r=await this.resolveUsers(o);for(const s of r)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const r of o)this.loadingUsers.delete(r)}}}getUser(t){return this.userCache.get(t)}subscribe(t){return this.on("update",t)}}const De=new C.PluginKey("blocknote-comments"),oa="SET_SELECTED_THREAD_ID";function ra(e,n){const t=new Map;return e.descendants((o,r)=>{o.marks.forEach(s=>{if(s.type.name===n){const i=s.attrs.threadId;if(!i)return;const a=r,l=a+o.nodeSize,c=t.get(i)??{from:1/0,to:0};t.set(i,{from:Math.min(a,c.from),to:Math.max(l,c.to)})}})}),t}class sa extends _{constructor(t,o,r){super();h(this,"userStore");h(this,"pendingComment",!1);h(this,"selectedThreadId");h(this,"threadPositions",new Map);h(this,"updateMarksFromThreads",t=>{this.editor.transact(o=>{o.doc.descendants((r,s)=>{r.marks.forEach(i=>{if(i.type.name===this.markType){const a=i.type,l=i.attrs.threadId,c=t.get(l),d=!!(!c||c.resolved||c.deletedAt);if(d!==i.attrs.orphan){const u=Math.max(s,0),p=Math.min(s+r.nodeSize,o.doc.content.size-1,o.doc.content.size-1);o.removeMark(u,p,i),o.addMark(u,p,a.create({...i.attrs,orphan:d})),d&&this.selectedThreadId===l&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})});if(this.editor=t,this.threadStore=o,this.markType=r,!t.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new na(t.resolveUsers),this.threadStore.subscribe(this.updateMarksFromThreads),t.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),t.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const s=this;this.addProsemirrorPlugin(new C.Plugin({key:De,state:{init(){return{decorations:O.DecorationSet.empty}},apply(i,a){const l=i.getMeta(De);if(!i.docChanged&&!l)return a;const c=i.docChanged?ra(i.doc,s.markType):s.threadPositions;(c.size>0||s.threadPositions.size>0)&&(s.threadPositions=c,s.emitStateUpdate());const d=[];if(s.selectedThreadId){const u=c.get(s.selectedThreadId);u&&d.push(O.Decoration.inline(u.from,u.to,{class:"bn-thread-mark-selected"}))}return{decorations:O.DecorationSet.create(i.doc,d)}}},props:{decorations(i){var a;return((a=De.getState(i))==null?void 0:a.decorations)??O.DecorationSet.empty},handleClick:(i,a,l)=>{if(l.button!==0)return;const c=i.state.doc.nodeAt(a);if(!c){s.selectThread(void 0);return}const d=c.marks.find(p=>p.type.name===r&&p.attrs.orphan!==!0),u=d==null?void 0:d.attrs.threadId;s.selectThread(u,!1)}}}))}static key(){return"comments"}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(t){return this.on("update",t)}selectThread(t,o=!0){var r,s;if(this.selectedThreadId!==t&&(this.selectedThreadId=t,this.emitStateUpdate(),this.editor.transact(i=>i.setMeta(De,{name:oa})),t&&o)){const i=this.threadPositions.get(t);if(!i)return;(s=(r=this.editor.prosemirrorView)==null?void 0:r.domAtPos(i.from).node)==null||s.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(t){const o=await this.threadStore.createThread(t);if(this.threadStore.addThreadToDocument){const r=this.editor.prosemirrorView,s=r.state.selection,i=H.ySyncPluginKey.getState(r.state),a={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?H.getRelativeSelection(i.binding,r.state):void 0};await this.threadStore.addThreadToDocument({threadId:o.id,selection:a})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:o.id})}}class Qo{constructor(n,t,o,r){h(this,"state");h(this,"emitUpdate");h(this,"mouseDownHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});h(this,"dragstartHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});h(this,"scrollHandler",()=>{var n;if((n=this.state)!=null&&n.show){const t=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!t)return;this.state.referencePos=t.getBoundingClientRect(),this.emitUpdate()}});h(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pluginKey=t,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");r(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var a,l;const o=this.pluginKey.getState(n.state),r=this.pluginKey.getState(t);if(!((a=this.state)!=null&&a.show)&&(o!=null&&o.block)&&this.editor.isEditable){const c=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);if(!c)return;this.state={show:!0,referencePos:c.getBoundingClientRect(),block:o.block},this.emitUpdate();return}const s=(o==null?void 0:o.block)&&!(r!=null&&r.block),i=!(o!=null&&o.block)&&(r==null?void 0:r.block);s&&this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate()),i&&((l=this.state)!=null&&l.show)&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const at=new C.PluginKey("FilePanelPlugin");class er extends _{constructor(t){super();h(this,"view");h(this,"closeMenu",()=>{var t;return(t=this.view)==null?void 0:t.closeMenu()});this.addProsemirrorPlugin(new C.Plugin({key:at,view:o=>(this.view=new Qo(t,at,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>{var s;return r.key==="Escape"&&this.shown?((s=this.view)==null||s.closeMenu(),!0):!1}},state:{init:()=>({block:void 0}),apply:(o,r)=>{const s=o.getMeta(at);return s||(!o.getMeta(H.ySyncPluginKey)&&(o.selectionSet||o.docChanged)?{block:void 0}:r)}}}))}static key(){return"filePanel"}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}class tr{constructor(n,t,o){h(this,"state");h(this,"emitUpdate");h(this,"preventHide",!1);h(this,"preventShow",!1);h(this,"shouldShow",({view:n,state:t,from:o,to:r})=>{const{doc:s,selection:i}=t,{empty:a}=i,l=!s.textBetween(o,r).length&&w.isTextSelection(t.selection);if(i.$from.parent.type.spec.code||w.isNodeSelection(i)&&i.node.type.spec.code||a||l)return!1;const c=document.activeElement;return!(!this.isElementWithinEditorWrapper(c)&&n.editable)});h(this,"blurHandler",n=>{var o;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;n&&n.relatedTarget&&(t===n.relatedTarget||t.contains(n.relatedTarget)||n.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});h(this,"isElementWithinEditorWrapper",n=>{if(!n)return!1;const t=this.pmView.dom.parentElement;return t?t.contains(n):!1});h(this,"viewMousedownHandler",n=>{(!this.isElementWithinEditorWrapper(n.target)||n.button===0)&&(this.preventShow=!0)});h(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))});h(this,"dragHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});h(this,"scrollHandler",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});h(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.root.addEventListener("mouseup",this.mouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("blur",this.blurHandler),t.root.addEventListener("scroll",this.scrollHandler,!0)}update(n,t){var f,m,g;const{state:o,composing:r}=n,{doc:s,selection:i}=o,a=t&&t.doc.eq(s)&&t.selection.eq(i);if(r||a)return;const{ranges:l}=i,c=Math.min(...l.map(b=>b.$from.pos)),d=Math.max(...l.map(b=>b.$to.pos)),u=this.shouldShow({view:n,state:o,from:c,to:d}),p=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(u||this.preventHide)&&!p){const b=this.getSelectionBoundingBox();if(b.height===0&&b.width===0){queueMicrotask(()=>{const y={show:!0,referencePos:this.getSelectionBoundingBox()};this.state=y,this.emitUpdate(),n.dispatch(n.state.tr.setSelection(C.TextSelection.create(n.state.doc,n.state.selection.from+1,n.state.selection.to))),n.dispatch(n.state.tr.setSelection(C.TextSelection.create(n.state.doc,n.state.selection.from-1,n.state.selection.to)))});return}const k={show:!0,referencePos:this.getSelectionBoundingBox()};(k.show!==((f=this.state)==null?void 0:f.show)||k.referencePos.toJSON()!==((m=this.state)==null?void 0:m.referencePos.toJSON()))&&(this.state=k,this.emitUpdate());return}if((g=this.state)!=null&&g.show&&!this.preventHide&&(!u||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:n}=this.pmView,{selection:t}=n,{ranges:o}=t,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(w.isNodeSelection(t)){const i=this.pmView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return w.posToDOMRect(this.pmView,r,s)}}const nr=new C.PluginKey("FormattingToolbarPlugin");class or extends _{constructor(t){super();h(this,"view");h(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new C.Plugin({key:nr,view:o=>(this.view=new tr(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}}))}static key(){return"formattingToolbar"}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}onUpdate(t){return this.on("update",t)}}const ia=w.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:e}){return["br",w.mergeAttributes(this.options.HTMLAttributes,e)]},renderText(){return`
12
+ `}}),sn=(e,n)=>{const t=e.resolve(n);if(t.depth<=1)return;const o=t.posAtIndex(t.index(t.depth-1),t.depth-1);return ye(e.resolve(o))},Ve=(e,n)=>{const t=e.resolve(n),o=t.index();if(o===0)return;const r=t.posAtIndex(o-1);return ye(e.resolve(r))},rr=(e,n)=>{for(;n.childContainer;){const t=n.childContainer.node,o=e.resolve(n.childContainer.beforePos+1).posAtIndex(t.childCount-1);n=ye(e.resolve(o))}return n},aa=(e,n)=>e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*"&&e.blockContent.node.childCount>0&&n.isBlockContainer&&n.blockContent.node.type.spec.content==="inline*",la=(e,n,t,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const r=e.doc.resolve(o.childContainer.beforePos+1),s=e.doc.resolve(o.childContainer.afterPos-1),i=r.blockRange(s);if(n){const a=e.doc.resolve(o.bnBlock.beforePos);e.tr.lift(i,a.depth)}}if(n){if(!t.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`);n(e.tr.delete(t.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0},an=e=>({state:n,dispatch:t})=>{const o=n.doc.resolve(e),r=ye(o),s=Ve(n.doc,r.bnBlock.beforePos);if(!s)return!1;const i=rr(n.doc,s);return aa(i,r)?la(n,t,i,r):!1},ca=w.Extension.create({priority:50,addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({chain:o,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:s})=>{const i=T(s);if(!i.isBlockContainer)return!1;const a=s.selection.from===i.blockContent.beforePos+1,l=i.blockContent.node.type.name==="paragraph";return a&&!l?r.command(U(i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=T(s);if(!i.isBlockContainer)return!1;const{blockContent:a}=i;return s.selection.from===a.beforePos+1?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=T(s);if(!i.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=i,c=s.selection.from===l.beforePos+1,d=s.selection.empty,u=a.beforePos;return c&&d?o().command(an(u)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const a=T(s);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1)||Ve(s.doc,a.bnBlock.beforePos))return!1;const d=sn(s.doc,a.bnBlock.beforePos);if((d==null?void 0:d.blockNoteType)!=="column")return!1;const u=d,p=sn(s.doc,u.bnBlock.beforePos);if((p==null?void 0:p.blockNoteType)!=="columnList")throw new Error("parent of column is not a column list");const f=u.childContainer.node.childCount===1,m=f&&p.childContainer.node.childCount===2,g=p.childContainer.node.firstChild===u.bnBlock.node;if(i){const b=s.doc.slice(a.bnBlock.beforePos,a.bnBlock.afterPos,!1);if(m)if(g){s.tr.step(new he.ReplaceAroundStep(p.bnBlock.beforePos,p.bnBlock.afterPos,u.bnBlock.afterPos+1,p.bnBlock.afterPos-2,b,b.size,!1));const k=s.tr.doc.resolve(u.bnBlock.beforePos);s.tr.setSelection(C.TextSelection.between(k,k))}else{s.tr.step(new he.ReplaceAroundStep(p.bnBlock.beforePos,p.bnBlock.afterPos,p.bnBlock.beforePos+2,u.bnBlock.beforePos-1,b,0,!1));const k=s.tr.doc.resolve(s.tr.mapping.map(u.bnBlock.beforePos-1));s.tr.setSelection(C.TextSelection.between(k,k))}else if(f)if(g){s.tr.delete(u.bnBlock.beforePos,u.bnBlock.afterPos),s.tr.insert(p.bnBlock.beforePos,b.content);const k=s.tr.doc.resolve(p.bnBlock.beforePos);s.tr.setSelection(C.TextSelection.between(k,k))}else s.tr.delete(u.bnBlock.beforePos-1,u.bnBlock.beforePos+1);else{s.tr.delete(a.bnBlock.beforePos,a.bnBlock.afterPos),g?s.tr.insert(p.bnBlock.beforePos-1,b.content):s.tr.insert(u.bnBlock.beforePos-1,b.content);const k=s.tr.doc.resolve(u.bnBlock.beforePos-1);s.tr.setSelection(C.TextSelection.between(k,k))}}return!0}),()=>r.command(({state:s})=>{const i=T(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=Ve(s.doc,i.bnBlock.beforePos);if(!l||!l.isBlockContainer)return!1;let c=o();if(l.blockContent.node.type.spec.content==="tableRow+"){const m=i.bnBlock.beforePos-1-1-1-1-1;c=c.setTextSelection(m)}else if(l.blockContent.node.type.spec.content===""){const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setNodeSelection(d)}else{const d=l.blockContent.afterPos-l.blockContent.node.nodeSize;c=c.setTextSelection(d)}return c.deleteRange({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:s})=>{const i=T(s);if(!i.isBlockContainer)throw new Error("todo");const a=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,c=Ve(s.doc,i.bnBlock.beforePos);if(c&&a&&l){const d=rr(s.doc,c);if(!d.isBlockContainer)throw new Error("todo");if(d.blockContent.node.type.spec.content===""||d.blockContent.node.type.spec.content==="inline*"&&d.blockContent.node.childCount===0)return o().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},d.bnBlock.afterPos).deleteRange({from:d.bnBlock.beforePos,to:d.bnBlock.afterPos}).run()}return!1})]),n=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:r})=>{const s=T(r);if(!s.isBlockContainer)return!1;const{bnBlock:i,blockContent:a,childContainer:l}=s,{depth:c}=r.doc.resolve(i.beforePos),d=i.afterPos===r.doc.nodeSize-3,u=r.selection.from===a.afterPos-1,p=r.selection.empty;if(!d&&u&&p&&!(l!==void 0)){let m=c,g=i.afterPos+1,b=r.doc.resolve(g).depth;for(;b<m;)m=b,g+=2,b=r.doc.resolve(g).depth;return o.command(an(g-1))}return!1})]),t=(o=!1)=>this.editor.commands.first(({commands:r,tr:s})=>[()=>r.command(({state:i})=>{const a=T(i);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:c}=a,{depth:d}=i.doc.resolve(l.beforePos),u=i.selection.$anchor.parentOffset===0,p=i.selection.anchor===i.selection.head,f=c.node.childCount===0,m=d>1;return u&&p&&f&&m?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:i})=>{const a=T(i),l=this.options.editor.schema.blockSchema[a.blockNoteType].hardBreakShortcut??"shift+enter";if(l==="none")return!1;if(l==="shift+enter"&&o||l==="enter"){const c=s.storedMarks||s.selection.$head.marks().filter(d=>this.editor.extensionManager.splittableMarks.includes(d.type.name));return s.insert(s.selection.head,s.doc.type.schema.nodes.hardBreak.create()).ensureMarks(c),!0}return!1}),()=>r.command(({state:i,dispatch:a})=>{const l=T(i);if(!l.isBlockContainer)return!1;const{bnBlock:c,blockContent:d}=l,u=i.selection.$anchor.parentOffset===0,p=i.selection.anchor===i.selection.head,f=d.node.childCount===0;if(u&&p&&f){const m=c.afterPos,g=m+2;if(a){const b=i.schema.nodes.blockContainer.createAndFill();i.tr.insert(m,b).scrollIntoView(),i.tr.setSelection(new C.TextSelection(i.doc.resolve(g)))}return!0}return!1}),()=>r.command(({state:i,chain:a})=>{const l=T(i);if(!l.isBlockContainer)return!1;const{blockContent:c}=l,d=i.selection.$anchor.parentOffset===0;return c.node.childCount===0?!1:(a().deleteSelection().command(go(i.selection.from,d,d)).run(),!0)})]);return{Backspace:e,Delete:n,Enter:()=>t(),"Shift-Enter":()=>t(!0),Tab:()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:Fo(this.options.editor)},"Shift-Tab":()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:(this.editor.commands.liftListItem("blockContainer"),!0)},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}});class da{constructor(n,t,o){h(this,"state");h(this,"emitUpdate");h(this,"menuUpdateTimer");h(this,"startMenuUpdateTimer");h(this,"stopMenuUpdateTimer");h(this,"mouseHoveredLinkMark");h(this,"mouseHoveredLinkMarkRange");h(this,"keyboardHoveredLinkMark");h(this,"keyboardHoveredLinkMarkRange");h(this,"linkMark");h(this,"linkMarkRange");h(this,"mouseOverHandler",n=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),n.target instanceof HTMLAnchorElement&&n.target.nodeName==="A"){const t=n.target,o=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(o),s=r.marks();for(const i of s)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=i,this.mouseHoveredLinkMarkRange=w.getMarkRange(r,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});h(this,"clickHandler",n=>{var o;const t=this.pmView.dom.parentElement;this.linkMark&&n&&n.target&&!(t===n.target||t.contains(n.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});h(this,"scrollHandler",()=>{var n;this.linkMark!==void 0&&(n=this.state)!=null&&n.show&&(this.state.referencePos=w.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});h(this,"closeMenu",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(n,t){var o;this.editor.transact(r=>{const s=R(r);r.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to),r.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,s.mark("link",{href:n}))}),this.pmView.focus(),(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var n;this.editor.transact(t=>t.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())}update(n,t,o=!1){var a;const{state:r}=n;if(t&&t.selection.from===r.selection.from&&t.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=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 l=this.pmView.state.selection.$from.marks();for(const c of l)if(c.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=c,this.keyboardHoveredLinkMarkRange=w.getMarkRange(this.pmView.state.selection.$from,c.type,c.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&o&&(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:w.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((a=this.state)!=null&&a.show&&i&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const sr=new C.PluginKey("LinkToolbarPlugin");class ir extends _{constructor(t){super();h(this,"view");h(this,"editLink",(t,o)=>{this.view.editLink(t,o)});h(this,"deleteLink",()=>{this.view.deleteLink()});h(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});h(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});h(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new C.Plugin({key:sr,view:o=>(this.view=new da(t,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}}))}static key(){return"linkToolbar"}onUpdate(t){return this.on("update",t)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}const ar=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],lr="https",ua=new C.PluginKey("node-selection-keyboard");class pa extends _{static key(){return"nodeSelectionKeyboard"}constructor(){super(),this.addProsemirrorPlugin(new C.Plugin({key:ua,props:{handleKeyDown:(n,t)=>{if("node"in n.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(t.key.length===1)return t.preventDefault(),!0;if(t.key==="Enter"&&!t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey){const o=n.state.tr;return n.dispatch(o.insert(n.state.tr.selection.$to.after(),n.state.schema.nodes.paragraph.createChecked()).setSelection(new C.TextSelection(o.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}}))}}const ha=new C.PluginKey("blocknote-placeholder");class fa extends _{static key(){return"placeholder"}constructor(n,t){super(),this.addProsemirrorPlugin(new C.Plugin({key:ha,view:o=>{var c,d;const r=`placeholder-selector-${fn.v4()}`;o.dom.classList.add(r);const s=document.createElement("style"),i=n._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),((c=n.prosemirrorView)==null?void 0:c.root)instanceof ShadowRoot?n.prosemirrorView.root.append(s):(d=n.prosemirrorView)==null||d.root.head.appendChild(s);const a=s.sheet,l=(u="")=>`.${r} .bn-block-content${u} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:u,emptyDocument:p,...f}=t;for(const[b,k]of Object.entries(f)){const y=`[data-content-type="${b}"]`;a.insertRule(`${l(y)} { content: ${JSON.stringify(k)}; }`)}const m="[data-is-only-empty-block]",g="[data-is-empty-and-focused]";a.insertRule(`${l(m)} { content: ${JSON.stringify(p)}; }`),a.insertRule(`${l(g)} { content: ${JSON.stringify(u)}; }`)}catch(u){console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)",u)}return{destroy:()=>{var u,p;((u=n.prosemirrorView)==null?void 0:u.root)instanceof ShadowRoot?n.prosemirrorView.root.removeChild(s):(p=n.prosemirrorView)==null||p.root.head.removeChild(s)}}},props:{decorations:o=>{const{doc:r,selection:s}=o;if(!n.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];o.doc.content.size===6&&i.push(O.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const a=s.$anchor,l=a.parent;if(l.content.size===0){const c=a.before();i.push(O.Decoration.node(c,c+l.nodeSize,{"data-is-empty-and-focused":"true"}))}return O.DecorationSet.create(r,i)}}}))}}const ln=new C.PluginKey("previous-blocks"),ma={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class ga extends _{static key(){return"previousBlockType"}constructor(){super();let n;this.addProsemirrorPlugin(new C.Plugin({key:ln,view(t){return{update:async(o,r)=>{var s;((s=this.key)==null?void 0:s.getState(o.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{o.dispatch(o.state.tr.setMeta(ln,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,o,r,s){if(o.currentTransactionOldBlockAttrs={},o.updatedBlocks.clear(),!t.docChanged||r.doc.eq(s.doc))return o;const i={},a=w.findChildren(r.doc,d=>d.attrs.id),l=new Map(a.map(d=>[d.node.attrs.id,d])),c=w.findChildren(s.doc,d=>d.attrs.id);for(const d of c){const u=l.get(d.node.attrs.id),p=u==null?void 0:u.node.firstChild,f=d.node.firstChild;if(u&&p&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:s.doc.resolve(d.pos).depth};let g={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:r.doc.resolve(u.pos).depth};i[d.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in o.prevTransactionOldBlockAttrs&&(g=o.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),o.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,o.updatedBlocks.add(d.node.attrs.id))}}return o.prevTransactionOldBlockAttrs=i,o}},props:{decorations(t){const o=this.getState(t);if(o.updatedBlocks.size===0)return;const r=[];return t.doc.descendants((s,i)=>{if(!s.attrs.id||!o.updatedBlocks.has(s.attrs.id))return;const a=o.currentTransactionOldBlockAttrs[s.attrs.id],l={};for(const[d,u]of Object.entries(a))l["data-prev-"+ma[d]]=u||"none";const c=O.Decoration.node(i,i+s.nodeSize,{...l});r.push(c)}),O.DecorationSet.create(t.doc,r)}}}))}}const cn=new C.PluginKey("blocknote-show-selection");class ba extends _{constructor(t){super();h(this,"enabled",!1);this.editor=t,this.addProsemirrorPlugin(new C.Plugin({key:cn,props:{decorations:o=>{const{doc:r,selection:s}=o;if(!this.enabled)return O.DecorationSet.empty;const i=O.Decoration.inline(s.from,s.to,{"data-show-selection":"true"});return O.DecorationSet.create(r,[i])}}}))}static key(){return"showSelection"}setEnabled(t){this.enabled!==t&&(this.enabled=t,this.editor.transact(o=>o.setMeta(cn,{})))}getEnabled(){return this.enabled}}function cr(e,n){var t,o;for(;e&&e.parentElement&&e.parentElement!==n.dom&&((t=e.getAttribute)==null?void 0:t.call(e,"data-node-type"))!=="blockContainer";)e=e.parentElement;if(((o=e.getAttribute)==null?void 0:o.call(e,"data-node-type"))==="blockContainer")return{node:e,id:e.getAttribute("data-id")}}class ae extends C.Selection{constructor(t,o){super(t,o);h(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(t,o,r=o){return new ae(t.resolve(o),t.resolve(r))}content(){return new E.Slice(E.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof ae)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){const r=o.mapResult(this.from),s=o.mapResult(this.to);return s.deleted?C.Selection.near(t.resolve(r.pos)):r.deleted?C.Selection.near(t.resolve(s.pos)):new ae(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}C.Selection.jsonID("multiple-node",ae);let G;function ka(e,n){let t,o;const r=n.resolve(e.from).node().type.spec.group==="blockContent",s=n.resolve(e.to).node().type.spec.group==="blockContent",i=Math.min(e.$anchor.depth,e.$head.depth);if(r&&s){const a=e.$from.start(i-1),l=e.$to.end(i-1);t=n.resolve(a-1).pos,o=n.resolve(l+1).pos}else t=e.from,o=e.to;return{from:t,to:o}}function dn(e,n,t=n){n===t&&(t+=e.state.doc.resolve(n+1).node().nodeSize);const o=e.domAtPos(n).node.cloneNode(!0),r=e.domAtPos(n).node,s=(u,p)=>Array.prototype.indexOf.call(u.children,p),i=s(r,e.domAtPos(n+1).node.parentElement),a=s(r,e.domAtPos(t-1).node.parentElement);for(let u=r.childElementCount-1;u>=0;u--)(u>a||u<i)&&o.removeChild(o.children[u]);dr(e.root),G=o;const l=G.getElementsByTagName("iframe");for(let u=0;u<l.length;u++){const p=l[u],f=p.parentElement;f&&f.removeChild(p)}const d=e.dom.className.split(" ").filter(u=>u!=="ProseMirror"&&u!=="bn-root"&&u!=="bn-editor").join(" ");G.className=G.className+" bn-drag-preview "+d,e.root instanceof ShadowRoot?e.root.appendChild(G):e.root.body.appendChild(G)}function dr(e){G!==void 0&&(e instanceof ShadowRoot?e.removeChild(G):e.body.removeChild(G),G=void 0)}function ya(e,n,t){if(!e.dataTransfer)return;const o=t.prosemirrorView;if(!o)return;const r=W(n.id,o.state.doc);if(!r)throw new Error(`Block with ID ${n.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=o.state.selection,a=o.state.doc,{from:l,to:c}=ka(i,a),d=l<=s&&s<c,u=i.$anchor.node()!==i.$head.node()||i instanceof ae;d&&u?(o.dispatch(o.state.tr.setSelection(ae.create(a,l,c))),dn(o,l,c)):(o.dispatch(o.state.tr.setSelection(C.NodeSelection.create(o.state.doc,s))),dn(o,s));const p=o.state.selection.content(),f=t.pmSchema,m=o.serializeForClipboard(p).dom.innerHTML,g=Me(f,t),b=Jo(p.content),k=g.exportBlocks(b,{}),y=nt(k);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",m),e.dataTransfer.setData("text/html",k),e.dataTransfer.setData("text/plain",y),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(G,0,0)}}const un=250;function vt(e,n,t=!0){const o=e.root.elementsFromPoint(n.left,n.top);for(const r of o)if(e.dom.contains(r))return t&&r.closest("[data-node-type=columnList]")?vt(e,{left:n.left+50,top:n.top},!1):cr(r,e)}function wa(e,n){if(!n.dom.firstChild)return;const t=n.dom.firstChild.getBoundingClientRect(),o={left:Math.min(Math.max(t.left+10,e.x),t.right-10),top:e.y},r=vt(n,o);if(!r)return;const s=r.node.getBoundingClientRect();return vt(n,{left:s.right-10,top:e.y},!1)}class ur{constructor(n,t,o){h(this,"state");h(this,"emitUpdate");h(this,"mousePos");h(this,"hoveredBlock");h(this,"menuFrozen",!1);h(this,"isDragOrigin",!1);h(this,"updateState",n=>{this.state=n,this.emitUpdate(this.state)});h(this,"updateStateFromMousePos",()=>{var o,r,s,i,a;if(this.menuFrozen||!this.mousePos)return;const n=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((n==null?void 0:n.element)!==this.pmView.dom||n.distance>un){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}const t=wa(this.mousePos,this.pmView);if(!t||!this.editor.isEditable){(r=this.state)!=null&&r.show&&(this.state.show=!1,this.updateState(this.state));return}if(!((s=this.state)!=null&&s.show&&((i=this.hoveredBlock)!=null&&i.hasAttribute("data-id"))&&((a=this.hoveredBlock)==null?void 0:a.getAttribute("data-id"))===t.id)&&(this.hoveredBlock=t.node,this.editor.isEditable)){const l=t.node.getBoundingClientRect(),c=t.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(c?c.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,l.y,l.width,l.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}});h(this,"onDragStart",n=>{var i;const t=(i=n.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!t||this.pmView.dragging)return;const o=document.createElement("div");o.innerHTML=t;const s=E.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new E.Slice(s.content,0,0),move:!0}});h(this,"findClosestEditorElement",n=>{const t=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(t.length===0)return null;let o=t[0],r=Number.MAX_VALUE;return t.forEach(s=>{const i=s.querySelector(".bn-block-group").getBoundingClientRect(),a=n.clientX<i.left?i.left-n.clientX:n.clientX>i.right?n.clientX-i.right:0,l=n.clientY<i.top?i.top-n.clientY:n.clientY>i.bottom?n.clientY-i.bottom:0,c=Math.sqrt(Math.pow(a,2)+Math.pow(l,2));c<r&&(r=c,o=s)}),{element:o,distance:r}});h(this,"onDragOver",n=>{if(n.synthetic)return;const t=this.getDragEventContext(n);if(!t||!t.isDropPoint){this.closeDropCursor();return}t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(n)});h(this,"closeDropCursor",()=>{const n=new Event("dragleave",{bubbles:!1});n.synthetic=!0,this.pmView.dom.dispatchEvent(n)});h(this,"getDragEventContext",n=>{var l;const t=!((l=n.dataTransfer)!=null&&l.types.includes("blocknote/html"))&&!!this.pmView.dragging,o=!!this.isDragOrigin,r=t||o,s=this.findClosestEditorElement(n);if(!s||s.distance>un)return;const i=s.element===this.pmView.dom,a=i&&s.distance===0;if(!(!i&&!r))return{isDropPoint:i,isDropWithinEditorBounds:a,isDragOrigin:r}});h(this,"onDrop",n=>{if(n.synthetic)return;const t=this.getDragEventContext(n);if(!t){this.closeDropCursor();return}const{isDropPoint:o,isDropWithinEditorBounds:r,isDragOrigin:s}=t;if(!r&&o&&this.dispatchSyntheticEvent(n),o){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(C.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)));return}else if(s){setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0);return}});h(this,"onDragEnd",n=>{n.synthetic||(this.pmView.dragging=null)});h(this,"onKeyDown",n=>{var t;(t=this.state)!=null&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});h(this,"onMouseMove",n=>{var s;if(this.menuFrozen)return;this.mousePos={x:n.clientX,y:n.clientY};const t=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom,r=this.pmView.dom.parentElement;if(o&&n&&n.target&&!(r===n.target||r.contains(n.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});h(this,"onScroll",()=>{var n;(n=this.state)!=null&&n.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state)),this.updateStateFromMousePos()});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),Ae(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),t.root.addEventListener("scroll",this.onScroll,!0)}dispatchSyntheticEvent(n){const t=new Event(n.type,n),o=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=n.clientX,t.clientY=n.clientY,t.clientX=Math.min(Math.max(n.clientX,o.left),o.left+o.width),t.clientY=Math.min(Math.max(n.clientY,o.top),o.top+o.height),t.dataTransfer=n.dataTransfer,t.preventDefault=()=>n.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(n,t){var r;!t.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var n;(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const pr=new C.PluginKey("SideMenuPlugin");class hr extends _{constructor(t){super();h(this,"view");h(this,"blockDragStart",(t,o)=>{this.view&&(this.view.isDragOrigin=!0),ya(t,o,this.editor)});h(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&dr(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)});h(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)});h(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=t,this.addProsemirrorPlugin(new C.Plugin({key:pr,view:o=>(this.view=new ur(t,o,r=>{this.emit("update",r)}),this.view)}))}static key(){return"sideMenu"}onUpdate(t){return this.on("update",t)}}const He=new Map;function Ca(e){if(He.has(e))return He.get(e);const n=new he.Mapping;return e._tiptapEditor.on("transaction",({transaction:t})=>{n.appendMapping(t.mapping)}),e._tiptapEditor.on("destroy",()=>{He.delete(e)}),He.set(e,n),n}function fr(e,n,t="left"){const o=H.ySyncPluginKey.getState(e._tiptapEditor.state);if(!o){const s=Ca(e),i=s.maps.length;return()=>s.slice(i).map(n,t==="left"?-1:1)}const r=H.absolutePositionToRelativePosition(n+(t==="right"?1:0),o.binding.type,o.binding.mapping);return()=>{const s=H.ySyncPluginKey.getState(e._tiptapEditor.state),i=H.relativePositionToAbsolutePosition(s.doc,s.binding.type,r,s.binding.mapping);if(i===null)throw new Error("Position not found, cannot track positions");return i+(t==="right"?-1:0)}}const va=w.findParentNode(e=>e.type.name==="blockContainer");class Sa{constructor(n,t){h(this,"state");h(this,"emitUpdate");h(this,"rootEl");h(this,"pluginState");h(this,"handleScroll",()=>{var n,t;if((n=this.state)!=null&&n.show){const o=(t=this.rootEl)==null?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!o)return;this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});h(this,"closeMenu",()=>{this.editor.transact(n=>n.setMeta(pe,null))});h(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(n=>n.selection.from)}).run()});var o,r;this.editor=n,this.pluginState=void 0,this.emitUpdate=s=>{var i;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(s,{...this.state,ignoreQueryLength:(i=this.pluginState)==null?void 0:i.ignoreQueryLength})},this.rootEl=(o=this.editor.prosemirrorView)==null?void 0:o.root,(r=this.rootEl)==null||r.addEventListener("scroll",this.handleScroll,!0)}update(n,t){var c;const o=pe.getState(t),r=pe.getState(n.state),s=o===void 0&&r!==void 0,i=o!==void 0&&r===void 0;if(!s&&!(o!==void 0&&r!==void 0)&&!i)return;if(this.pluginState=i?o:r,i||!this.editor.isEditable){this.state&&(this.state.show=!1),this.emitUpdate(this.pluginState.triggerCharacter);return}const l=(c=this.rootEl)==null?void 0:c.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&l&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var n;(n=this.rootEl)==null||n.removeEventListener("scroll",this.handleScroll,!0)}}const pe=new C.PluginKey("SuggestionMenuPlugin");class mr extends _{constructor(t){super();h(this,"view");h(this,"triggerCharacters",[]);h(this,"addTriggerCharacter",t=>{this.triggerCharacters.push(t)});h(this,"removeTriggerCharacter",t=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==t)});h(this,"closeMenu",()=>this.view.closeMenu());h(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.addProsemirrorPlugin(new C.Plugin({key:pe,view:()=>(this.view=new Sa(t,(r,s)=>{this.emit(`update ${r}`,s)}),this.view),state:{init(){},apply:(r,s,i,a)=>{if(r.getMeta("orderedListIndexing")!==void 0||r.selection.$from.parent.type.spec.code)return s;const l=r.getMeta(pe);if(typeof l=="object"&&l!==null){s&&this.closeMenu();const d=fr(t,a.selection.from-l.triggerCharacter.length);return{triggerCharacter:l.triggerCharacter,deleteTriggerCharacter:l.deleteTriggerCharacter!==!1,queryStartPos:()=>d()+l.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`,ignoreQueryLength:l==null?void 0:l.ignoreQueryLength}}if(s===void 0)return s;if(a.selection.from!==a.selection.to||l===null||r.getMeta("focus")||r.getMeta("blur")||r.getMeta("pointer")||s.triggerCharacter!==void 0&&a.selection.from<s.queryStartPos()||!a.selection.$from.sameParent(a.doc.resolve(s.queryStartPos())))return;const c={...s};return c.query=a.doc.textBetween(s.queryStartPos(),a.selection.from),c}},props:{handleTextInput(r,s,i,a){if(s===i){const l=r.state.doc;for(const c of o){const d=c.length>1?l.textBetween(s-c.length,s)+a:a;if(c===d)return r.dispatch(r.state.tr.insertText(a)),r.dispatch(r.state.tr.setMeta(pe,{triggerCharacter:d}).scrollIntoView()),!0}}return!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=va(r.selection);if(i)return O.DecorationSet.create(r.doc,[O.Decoration.node(i.pos,i.pos+i.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}return O.DecorationSet.create(r.doc,[O.Decoration.inline(s.queryStartPos()-s.triggerCharacter.length,s.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}}}))}static key(){return"suggestionMenu"}onUpdate(t,o){return this.triggerCharacters.includes(t)||this.addTriggerCharacter(t),this.on(`update ${t}`,o)}get shown(){var t,o;return((o=(t=this.view)==null?void 0:t.state)==null?void 0:o.show)||!1}}function Ea(e,n){e.suggestionMenus.addTriggerCharacter(n)}const Ba=w.Mark.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(e){return e.name!=="insertion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(n,t){return["ins",{"data-id":String(n.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0]},parseDOM:[{tag:"ins",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10)}:!1}}]}}}),Ta=w.Mark.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(e){return e.name!=="deletion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(n,t){return["del",{"data-id":String(n.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0]},parseDOM:[{tag:"del",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10)}:!1}}]}}}),xa=w.Mark.create({name:"modification",inclusive:!1,excludes:"deletion insertion",addAttributes(){return{id:{default:null,validate:"number"},type:{validate:"string"},attrName:{default:null,validate:"string|null"},previousValue:{default:null},newValue:{default:null}}},extendMarkSchema(e){return e.name!=="modification"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(n,t){return[t?"span":"div",{"data-type":"modification","data-id":String(n.attrs.id),"data-mod-type":n.attrs.type,"data-mod-prev-val":JSON.stringify(n.attrs.previousValue),"data-mod-new-val":JSON.stringify(n.attrs.newValue)},0]},parseDOM:[{tag:"span[data-type='modification']",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10),type:n.dataset.modType,previousValue:n.dataset.modPrevVal,newValue:n.dataset.modNewVal}:!1}},{tag:"div[data-type='modification']",getAttrs(n){return n.dataset.id?{id:parseInt(n.dataset.id,10),type:n.dataset.modType,previousValue:n.dataset.modPrevVal}:!1}}]}}});let F;function pn(e){F||(F=document.createElement("div"),F.innerHTML="_",F.style.opacity="0",F.style.height="1px",F.style.width="1px",e instanceof Document?e.body.appendChild(F):e.appendChild(F))}function Pa(e){F&&(e instanceof Document?e.body.removeChild(F):e.removeChild(F),F=void 0)}function Oe(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Ma(e){let n=e;for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH"&&!n.classList.contains("tableWrapper");){if(n.classList.contains("ProseMirror"))return;const t=n.parentNode;if(!t||!(t instanceof Element))return;n=t}return n.nodeName==="TD"||n.nodeName==="TH"?{type:"cell",domNode:n,tbodyNode:n.closest("tbody")}:{type:"wrapper",domNode:n,tbodyNode:n.querySelector("tbody")}}function Ia(e,n){const t=n.querySelectorAll(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class gr{constructor(n,t,o){h(this,"state");h(this,"emitUpdate");h(this,"tableId");h(this,"tablePos");h(this,"tableElement");h(this,"menuFrozen",!1);h(this,"mouseState","up");h(this,"prevWasEditable",null);h(this,"viewMousedownHandler",()=>{this.mouseState="down"});h(this,"mouseUpHandler",n=>{this.mouseState="up",this.mouseMoveHandler(n)});h(this,"mouseMoveHandler",n=>{var c,d,u,p,f,m,g;if(this.menuFrozen||this.mouseState==="selecting"||!(n.target instanceof Element)||!this.pmView.dom.contains(n.target))return;const t=Ma(n.target);if((t==null?void 0:t.type)==="cell"&&this.mouseState==="down"&&!((c=this.state)!=null&&c.draggingState)){this.mouseState="selecting",(d=this.state)!=null&&d.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t||!this.editor.isEditable){(u=this.state)!=null&&u.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t.tbodyNode)return;const o=t.tbodyNode.getBoundingClientRect(),r=cr(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(b=>W(r.id,b.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=x(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(Mo("table",a,this.editor)&&(this.tablePos=i.posBeforeNode+1,s=a),!s)return;this.tableId=r.id;const l=(p=t.domNode.closest(".tableWrapper"))==null?void 0:p.querySelector(".table-widgets-container");if((t==null?void 0:t.type)==="wrapper"){const b=n.clientY>=o.bottom-1&&n.clientY<o.bottom+20,k=n.clientX>=o.right-1&&n.clientX<o.right+20,y=n.clientX>o.right||n.clientY>o.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:b,showAddOrRemoveColumnsButton:k,referencePosTable:o,block:s,widgetContainer:l,colIndex:y||(f=this.state)==null?void 0:f.colIndex,rowIndex:y||(m=this.state)==null?void 0:m.rowIndex,referencePosCell:y||(g=this.state)==null?void 0:g.referencePosCell}}else{const b=Oe(t.domNode),k=Oe(t.domNode.parentElement),y=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===k&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:k===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:y,colIndex:b,rowIndex:k,widgetContainer:l}}return this.emitUpdate(),!1});h(this,"dragOverHandler",n=>{var p;if(((p=this.state)==null?void 0:p.draggingState)===void 0)return;n.preventDefault(),n.dataTransfer.dropEffect="move",Ia(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const t={left:Math.min(Math.max(n.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(n.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(t.left,t.top).filter(f=>f.tagName==="TD"||f.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=Oe(r.parentElement),a=Oe(r),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,d=(this.state.draggingState.draggedCellOrientation==="row"?i:a)!==l;(this.state.rowIndex!==i||this.state.colIndex!==a)&&(this.state.rowIndex=i,this.state.colIndex=a,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const u=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==u&&(this.state.draggingState.mousePos=u,s=!0),s&&this.emitUpdate(),d&&this.editor.transact(f=>f.setMeta(de,!0))});h(this,"dropHandler",n=>{if(this.mouseState="up",this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");n.preventDefault();const{draggingState:t,colIndex:o,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(t.draggedCellOrientation==="row"){if(!In(this.state.block,t.originalIndex,r))return!1;const i=rs(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!Ln(this.state.block,t.originalIndex,o))return!1;const i=os(this.state.block,t.originalIndex,o),[a]=s.splice(t.originalIndex,1);s.splice(o,0,a),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:s,rows:i}})}return this.editor.setTextCursorPosition(this.state.block.id),!0});this.editor=n,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),t.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),t.root.addEventListener("dragover",this.dragOverHandler),t.root.addEventListener("drop",this.dropHandler)}update(){var r;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||this.state.block.type!=="table"||!((r=this.tableElement)!=null&&r.isConnected)){this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate();return}const{height:n,width:t}=Lt(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=n&&(this.state.rowIndex=n-1),this.state.colIndex>=t&&(this.state.colIndex=t-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(this.state.rowIndex!==void 0&&this.state.colIndex!==void 0){const i=o.children[this.state.rowIndex].children[this.state.colIndex];i?this.state.referencePosCell=i.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const de=new C.PluginKey("TableHandlesPlugin");class br extends _{constructor(t){super();h(this,"view");h(this,"colDragStart",t=>{if(this.view.state===void 0||this.view.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:t.clientX},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(de,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");pn(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(F,0,0),t.dataTransfer.effectAllowed="move"});h(this,"rowDragStart",t=>{if(this.view.state===void 0||this.view.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:t.clientY},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(de,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");pn(this.editor.prosemirrorView.root),t.dataTransfer.setDragImage(F,0,0),t.dataTransfer.effectAllowed="copyMove"});h(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(t=>t.setMeta(de,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");Pa(this.editor.prosemirrorView.root)});h(this,"freezeHandles",()=>{this.view.menuFrozen=!0});h(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});h(this,"getCellsAtRowHandle",(t,o)=>ut(t,o));h(this,"getCellsAtColumnHandle",(t,o)=>pt(t,o));h(this,"setCellSelection",(t,o,r=o)=>{const s=this.view;if(!s)throw new Error("Table handles view not initialized");const i=t.doc.resolve(s.tablePos+1),a=t.doc.resolve(i.posAtIndex(o.row)+1),l=t.doc.resolve(a.posAtIndex(o.col)),c=t.doc.resolve(i.posAtIndex(r.row)+1),d=t.doc.resolve(c.posAtIndex(r.col)),u=t.tr;return u.setSelection(new L.CellSelection(l,d)),t.apply(u)});h(this,"addRowOrColumn",(t,o)=>{this.editor.exec((r,s)=>{const i=this.setCellSelection(r,o.orientation==="row"?{row:t,col:0}:{row:0,col:t});return o.orientation==="row"?o.side==="above"?L.addRowBefore(i,s):L.addRowAfter(i,s):o.side==="left"?L.addColumnBefore(i,s):L.addColumnAfter(i,s)})});h(this,"removeRowOrColumn",(t,o)=>o==="row"?this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:t,col:0});return L.deleteRow(i,s)}):this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:0,col:t});return L.deleteColumn(i,s)}));h(this,"mergeCells",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t.relativeStartCell,t.relativeEndCell):o;return L.mergeCells(s,r)}));h(this,"splitCell",t=>this.editor.exec((o,r)=>{const s=t?this.setCellSelection(o,t):o;return L.splitCell(s,r)}));h(this,"getCellSelection",()=>this.editor.transact(t=>{const o=t.selection;let r=o.$from,s=o.$to;if(kt(o)){const{ranges:m}=o;m.forEach(g=>{r=g.$from.min(r??g.$from),s=g.$to.max(s??g.$to)})}else if(r=t.doc.resolve(o.$from.pos-o.$from.parentOffset-1),s=t.doc.resolve(o.$to.pos-o.$to.parentOffset-1),r.pos===0||s.pos===0)return;const i=t.doc.resolve(r.pos-r.parentOffset-1),a=t.doc.resolve(s.pos-s.parentOffset-1),l=t.doc.resolve(i.pos-i.parentOffset-1),c=r.index(i.depth),d=i.index(l.depth),u=s.index(a.depth),p=a.index(l.depth),f=[];for(let m=d;m<=p;m++)for(let g=c;g<=u;g++)f.push({row:m,col:g});return{from:{row:d,col:c},to:{row:p,col:u},cells:f}}));h(this,"getMergeDirection",t=>this.editor.transact(o=>{const r=kt(o.selection)?o.selection:void 0;if(!r||!t||r.ranges.length<=1)return;const s=this.getCellSelection();if(s)return as(s.from,s.to,t)?"vertical":"horizontal"}));h(this,"cropEmptyRowsOrColumns",(t,o)=>ss(t,o));h(this,"addRowsOrColumns",(t,o,r)=>is(t,o,r));this.editor=t,this.addProsemirrorPlugin(new C.Plugin({key:de,view:o=>(this.view=new gr(t,o,r=>{this.emit("update",r)}),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 r=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:a}=this.view.state,{originalIndex:l,draggedCellOrientation:c}=a;if(r===l||!i||c==="row"&&!In(i,l,r)||c==="col"&&!Ln(i,l,r))return O.DecorationSet.create(o.doc,s);const d=o.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?ut(this.view.state.block,r).forEach(({row:p,col:f})=>{const m=o.doc.resolve(d.posAtIndex(p)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),k=g.pos+(r>l?b.nodeSize-2:0);s.push(O.Decoration.widget(k,()=>{const y=document.createElement("div");return y.className="bn-table-drop-cursor",y.style.left="0",y.style.right="0",r>l?y.style.bottom="-2px":y.style.top="-3px",y.style.height="4px",y}))}):pt(this.view.state.block,r).forEach(({row:p,col:f})=>{const m=o.doc.resolve(d.posAtIndex(p)+1),g=o.doc.resolve(m.posAtIndex(f)+1),b=g.node(),k=g.pos+(r>l?b.nodeSize-2:0);s.push(O.Decoration.widget(k,()=>{const y=document.createElement("div");return y.className="bn-table-drop-cursor",y.style.top="0",y.style.bottom="0",r>l?y.style.right="-2px":y.style.left="-3px",y.style.width="4px",y}))}),O.DecorationSet.create(o.doc,s)}}}))}static key(){return"tableHandles"}onUpdate(t){return this.on("update",t)}}const La=w.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem","tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>e.textAlignment==="left"?{}:{"data-text-alignment":e.textAlignment}}}}]}}),Aa=w.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer","tableCell","tableHeader"],attributes:{textColor:{default:A.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):A.textColor.default,renderHTML:e=>e.textColor===A.textColor.default?{}:{"data-text-color":e.textColor}}}}]}}),Na=w.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new C.PluginKey(this.name);return[new C.Plugin({key:e,appendTransaction:(n,t,o)=>{const{doc:r,tr:s,schema:i}=o,a=e.getState(o),l=r.content.size-2,c=i.nodes.blockContainer,d=i.nodes.paragraph;if(a)return s.insert(l,c.create(void 0,d.create()))},state:{init:(n,t)=>{},apply:(n,t)=>{if(!n.docChanged)return t;let o=n.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")return!0;const r=o.firstChild;if(!r)throw new Error("Expected blockContent");return o.nodeSize>4||r.type.spec.content!=="inline*"}}})]}}),Da={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ha=w.Node.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,marks:"insertion modification deletion",parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:e=>{if(typeof e=="string")return!1;const n={};for(const[t,o]of Object.entries(Da))e.getAttribute(o)&&(n[t]=e.getAttribute(o));return n}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:e}){var r;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[s,i]of Object.entries(e))s!=="class"&&n.setAttribute(s,i);const t={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...e},o=document.createElement("div");o.className=Q("bn-block",t.class),o.setAttribute("data-node-type",this.name);for(const[s,i]of Object.entries(t))s!=="class"&&o.setAttribute(s,i);return n.appendChild(o),{dom:n,contentDOM:o}}}),Oa=w.Node.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML(){return[{tag:"div",getAttrs:e=>typeof e=="string"?!1:e.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:e}){var o;const n={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...e},t=document.createElement("div");t.className=Q("bn-block-group",n.class),t.setAttribute("data-node-type","blockGroup");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);return{dom:t,contentDOM:t}}}),_a=w.Node.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"});class Ra extends _{constructor({editor:t,collaboration:o}){super(t);h(this,"editor");h(this,"collaboration");h(this,"forkedState");this.editor=t,this.collaboration=o}static key(){return"ForkYDocPlugin"}findTypeInOtherYdoc(t,o){const r=t.doc;if(t._item===null){const s=Array.from(r.share.keys()).find(i=>r.share.get(i)===t);if(s==null)throw new Error("type does not exist in other ydoc");return o.get(s,t.constructor)}else{const s=t._item,i=o.store.clients.get(s.id.client)??[],a=ie.findIndexSS(i,s.id.clock);return i[a].content.type}}get isForkedFromRemote(){return this.forkedState!==void 0}fork(){var s;if(this.isForkedFromRemote)return;const t=(s=this.collaboration)==null?void 0:s.fragment;if(!t)throw new Error("No fragment to fork from");const o=new ie.Doc;ie.applyUpdate(o,ie.encodeStateAsUpdate(t.doc));const r=this.findTypeInOtherYdoc(t,o);this.forkedState={undoStack:H.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack,originalFragment:t,forkedFragment:r},this.editor._tiptapEditor.unregisterPlugin([H.yCursorPluginKey,H.yUndoPluginKey,H.ySyncPluginKey]),this.editor._tiptapEditor.registerPlugin(new wt(r).plugins[0]),this.editor._tiptapEditor.registerPlugin(new Ct({editor:this.editor}).plugins[0]),this.emit("forked",!0)}merge({keepChanges:t}){if(!this.forkedState)return;this.editor._tiptapEditor.unregisterPlugin(H.ySyncPluginKey),this.editor._tiptapEditor.unregisterPlugin(H.yUndoPluginKey);const{originalFragment:o,forkedFragment:r,undoStack:s}=this.forkedState;if(this.editor.extensions.ySyncPlugin=new wt(o),this.editor.extensions.yCursorPlugin=new We(this.collaboration),this.editor.extensions.yUndoPlugin=new Ct({editor:this.editor}),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.ySyncPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yCursorPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yUndoPlugin.plugins[0]),H.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack=s,t){const i=ie.encodeStateAsUpdate(r.doc,ie.encodeStateVector(o.doc));ie.applyUpdate(o.doc,i,this.editor)}this.forkedState=void 0,this.emit("forked",!1)}}const kr=e=>{var r;const n={},t=Va(e);for(const s of t)n[s.name]=s;e.collaboration&&(n.ySyncPlugin=new wt(e.collaboration.fragment),n.yUndoPlugin=new Ct({editor:e.editor}),(r=e.collaboration.provider)!=null&&r.awareness&&(n.yCursorPlugin=new We(e.collaboration)),n.forkYDocPlugin=new Ra({editor:e.editor,collaboration:e.collaboration})),n.formattingToolbar=new or(e.editor),n.linkToolbar=new ir(e.editor),n.sideMenu=new hr(e.editor),n.suggestionMenus=new mr(e.editor),n.filePanel=new er(e.editor),n.placeholder=new fa(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new ga),e.tableHandles&&(n.tableHandles=new br(e.editor)),n.nodeSelectionKeyboard=new pa,n.blockChange=new ta,n.showSelection=new ba(e.editor),e.comments&&(n.comments=new sa(e.editor,e.comments.threadStore,Zo.name));const o=e.disableExtensions||[];for(const s of o)delete n[s];return n};let hn=!1;const Va=e=>{const n=[w.extensions.ClipboardTextSerializer,w.extensions.Commands,w.extensions.Editable,w.extensions.FocusEvents,w.extensions.Tabindex,Or.Gapcursor,w.Extension.create({name:"dropCursor",addProseMirrorPlugins:()=>[e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})]}),Be.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),ia,Vr.Text,Ba,Ta,xa,Rr.Link.extend({inclusive:!1}).configure({defaultProtocol:lr,protocols:hn?[]:ar}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),Aa,ea,La,w.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),_a,Ha.configure({editor:e.editor,domAttributes:e.domAttributes}),ca.configure({editor:e.editor,tabBehavior:e.tabBehavior}),Oa.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(t=>t.config!=="link"&&t.config!=="text").map(t=>t.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(t=>[...(t.implementation.requiredExtensions||[]).map(o=>o.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),Qi(e.editor),Ji(e.editor,e.pasteHandler||(t=>t.defaultPasteHandler())),Di(e.editor),...e.trailingBlock===void 0||e.trailingBlock?[Na]:[],...e.comments?[Zo]:[]];return hn=!0,e.collaboration||n.push(_r.History),n};function Ua(e,n){const t=[];return e.forEach((o,r,s)=>{s!==n&&t.push(o)}),E.Fragment.from(t)}function Fa(e,n){const t=[];for(let o=0;o<e.childCount;o++)if(e.child(o).type.name==="tableRow")if(t.length>0&&t[t.length-1].type.name==="table"){const r=t[t.length-1],s=r.copy(r.content.addToEnd(e.child(o)));t[t.length-1]=s}else{const r=n.nodes.table.createChecked(void 0,e.child(o));t.push(r)}else t.push(e.child(o));return e=E.Fragment.from(t),e}function $a(e,n){let t=E.Fragment.from(e.content);if(t=Fa(t,n.state.schema),!Wa(t,n))return new E.Slice(t,e.openStart,e.openEnd);for(let o=0;o<t.childCount;o++)if(t.child(o).type.spec.group==="blockContent"){const r=[t.child(o)];if(o+1<t.childCount&&t.child(o+1).type.name==="blockGroup"){const i=t.child(o+1).child(0).child(0);(i.type.name==="bulletListItem"||i.type.name==="numberedListItem"||i.type.name==="checkListItem")&&(r.push(t.child(o+1)),t=Ua(t,o+1))}const s=n.state.schema.nodes.blockContainer.createChecked(void 0,r);t=t.replaceChild(o,s)}return new E.Slice(t,e.openStart,e.openEnd)}function Wa(e,n){var s,i;const t=e.childCount===1,o=((s=e.firstChild)==null?void 0:s.type.spec.content)==="inline*",r=((i=e.firstChild)==null?void 0:i.type.spec.content)==="tableRow+";if(t){if(o)return!1;if(r){const a=T(n.state);if(a.isBlockContainer)return!(a.blockContent.node.type.spec.content==="tableRow+")}}return!0}const qe=class qe extends w.Editor{constructor(t,o){super({...t,content:void 0});h(this,"_state");h(this,"mount",(t,o,r)=>{o?(this.options.element=o,this.createViewAlternative(t,r)):(this.destroy(),this.isInitialized=!1)});const r=this.schema;let s;const i=r.nodes.doc.createAndFill;r.nodes.doc.createAndFill=(...l)=>{if(s)return s;const c=i.apply(r.nodes.doc,l),d=JSON.parse(JSON.stringify(c.toJSON()));return d.content[0].content[0].attrs.id="initialBlockId",s=E.Node.fromJSON(r,d),s};let a;try{const l=t==null?void 0:t.content.map(c=>se(c,this.schema,o).toJSON());a=w.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(t.content))}this._state=C.EditorState.create({doc:a,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(t){if(!this.view){this._state=this.state.apply(t),this.emit("transaction",{editor:this,transaction:t});return}if(this.view.isDestroyed)return;if(this.isCapturingTransaction){this.dispatchTransaction(t);return}const{state:o,transactions:r}=this.state.applyTransaction(t),s=!this.state.selection.eq(o.selection);this.emit("beforeTransaction",{editor:this,transaction:t,nextState:o}),this.view.updateState(o),this.emit("transaction",{editor:this,transaction:t}),s&&this.emit("selectionUpdate",{editor:this,transaction:t});const i=t.getMeta("focus"),a=t.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:t}),a&&this.emit("blur",{editor:this,event:a.event,transaction:t}),!(!t.docChanged||t.getMeta("preventUpdate"))&&(this.emit("update",{editor:this,transaction:t}),this.emit("v3-update",{editor:this,transaction:t,appendedTransactions:r.slice(1)}))}forceEnablePlugins(){if(this.view)throw new Error("forcePluginsEnabled called after view has been initialized");this._state=this.state.reconfigure({plugins:this.extensionManager.plugins})}createViewAlternative(t,o){this.contentComponent=o;const r={};this.extensionManager.extensions.forEach(i=>{i.type==="mark"&&i.config.addMarkView&&(r[i.name]=i.config.addMarkView(t))}),this.view=new O.EditorView({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatch.bind(this),state:this.state,markViews:r,nodeViews:this.extensionManager.nodeViews});const s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.commands.focus(this.options.autofocus||this.options.element.getAttribute("data-bn-autofocus")==="true",{scrollIntoView:!1}),this.emit("create",{editor:this}),this.isInitialized=!0}};h(qe,"create",(t,o)=>{var s,i;const r=(s=globalThis==null?void 0:globalThis.window)==null?void 0:s.setTimeout;typeof((i=globalThis==null?void 0:globalThis.window)==null?void 0:i.setTimeout)<"u"&&(globalThis.window.setTimeout=()=>0);try{return new qe(t,o)}finally{r&&(globalThis.window.setTimeout=r)}});let ze=qe;ze.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const za={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Kt extends ot{constructor(t){var c,d,u,p,f,m,g,b,k,y,S,v,P,Y,M,B;super();h(this,"pmSchema");h(this,"extensions",{});h(this,"headless",!1);h(this,"_tiptapEditor");h(this,"elementRenderer",null);h(this,"blockCache",new WeakMap);h(this,"dictionary");h(this,"schema");h(this,"blockImplementations");h(this,"inlineContentImplementations");h(this,"styleImplementations");h(this,"formattingToolbar");h(this,"linkToolbar");h(this,"sideMenu");h(this,"suggestionMenus");h(this,"filePanel");h(this,"tableHandles");h(this,"comments");h(this,"showSelectionPlugin");h(this,"forkYDocPlugin");h(this,"uploadFile");h(this,"onUploadStartCallbacks",[]);h(this,"onUploadEndCallbacks",[]);h(this,"resolveFileUrl");h(this,"resolveUsers");h(this,"settings");h(this,"activeTransaction",null);h(this,"mount",(t,o)=>{this._tiptapEditor.mount(this,t,o)});this.options=t;const o=t;if(o.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(o.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(o.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(o.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||$r.en,this.settings={tables:{splitCells:((c=t==null?void 0:t.tables)==null?void 0:c.splitCells)??!1,cellBackgroundColor:((d=t==null?void 0:t.tables)==null?void 0:d.cellBackgroundColor)??!1,cellTextColor:((u=t==null?void 0:t.tables)==null?void 0:u.cellTextColor)??!1,headers:((p=t==null?void 0:t.tables)==null?void 0:p.headers)??!1},codeBlock:{indentLineWithTab:((f=t==null?void 0:t.codeBlock)==null?void 0:f.indentLineWithTab)??!0,defaultLanguage:((m=t==null?void 0:t.codeBlock)==null?void 0:m.defaultLanguage)??"text",supportedLanguages:((g=t==null?void 0:t.codeBlock)==null?void 0:g.supportedLanguages)??{},createHighlighter:((b=t==null?void 0:t.codeBlock)==null?void 0:b.createHighlighter)??void 0},heading:{levels:((k=t==null?void 0:t.heading)==null?void 0:k.levels)??[1,2,3]}};const r={defaultStyles:!0,schema:t.schema||Ce.create(),_headless:!1,...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};if(r.comments&&!r.resolveUsers)throw new Error("resolveUsers is required when using comments");this.resolveUsers=r.resolveUsers,this.schema=r.schema,this.blockImplementations=r.schema.blockSpecs,this.inlineContentImplementations=r.schema.inlineContentSpecs,this.styleImplementations=r.schema.styleSpecs,this.extensions=kr({editor:this,domAttributes:r.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:r.collaboration,trailingBlock:r.trailingBlock,disableExtensions:r.disableExtensions,setIdAttribute:r.setIdAttribute,animations:r.animations??!0,tableHandles:V("table",this),dropCursor:this.options.dropCursor??Fr.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,comments:r.comments,pasteHandler:r.pasteHandler}),(((y=r._tiptapOptions)==null?void 0:y.extensions)||[]).forEach(N=>{this.extensions[N.name]=N});for(let N of r.extensions||[]){typeof N=="function"&&(N=N(this));const I=N.constructor.key();if(!I)throw new Error(`Extension ${N.constructor.name} does not have a key method`);if(this.extensions[I])throw new Error(`Extension ${N.constructor.name} already exists with key ${I}`);this.extensions[I]=N}if(Object.entries(r._extensions||{}).forEach(([N,I])=>{const te=typeof I=="function"?I(this):I;if(!("plugin"in te)){this.extensions[N]=te;return}this.extensions[N]=new class extends _{static key(){return N}constructor(){super(),this.addProsemirrorPlugin(te.plugin)}get priority(){return te.priority}}}),this.formattingToolbar=this.extensions.formattingToolbar,this.linkToolbar=this.extensions.linkToolbar,this.sideMenu=this.extensions.sideMenu,this.suggestionMenus=this.extensions.suggestionMenus,this.filePanel=this.extensions.filePanel,this.tableHandles=this.extensions.tableHandles,this.comments=this.extensions.comments,this.showSelectionPlugin=this.extensions.showSelection,this.forkYDocPlugin=this.extensions.forkYDocPlugin,r.uploadFile){const N=r.uploadFile;this.uploadFile=async(I,Ne)=>{this.onUploadStartCallbacks.forEach(te=>te.apply(this,[Ne]));try{return await N(I,Ne)}finally{this.onUploadEndCallbacks.forEach(te=>te.apply(this,[Ne]))}}}this.resolveFileUrl=r.resolveFileUrl,this.headless=r._headless;const s="ySyncPlugin"in this.extensions||"liveblocksExtension"in this.extensions;s&&r.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const i=r.initialContent||(s?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:Be.options.generateID()}]);if(!Array.isArray(i)||i.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+i);const a=[...Object.entries(this.extensions).map(([N,I])=>{if(I instanceof w.Extension||I instanceof w.Node||I instanceof w.Mark)return I;if(!(I instanceof _&&!I.plugins.length))return w.Extension.create({name:N,priority:I.priority,addProseMirrorPlugins:()=>I.plugins})})].filter(N=>N!==void 0),l={...za,...r._tiptapOptions,content:i,extensions:a,editorProps:{...(S=r._tiptapOptions)==null?void 0:S.editorProps,attributes:{tabIndex:"0",...(P=(v=r._tiptapOptions)==null?void 0:v.editorProps)==null?void 0:P.attributes,...(Y=r.domAttributes)==null?void 0:Y.editor,class:Q("bn-editor",r.defaultStyles?"bn-default-styles":"",((B=(M=r.domAttributes)==null?void 0:M.editor)==null?void 0:B.class)||"")},transformPasted:$a}};this.headless?this.pmSchema=w.getSchema(l.extensions):(this._tiptapEditor=ze.create(l,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.pmSchema.cached.blockNoteEditor=this,this.emit("create")}static create(t={}){return new Kt(t)}exec(t){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,i=>this._tiptapEditor.dispatch(i),r)}canExec(t){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const o=this._tiptapEditor.state,r=this._tiptapEditor.view;return t(o,void 0,r)}transact(t){if(this.activeTransaction)return t(this.activeTransaction);try{this.activeTransaction=this._tiptapEditor.state.tr;const o=t(this.activeTransaction),r=this.activeTransaction;return this.activeTransaction=null,r&&(r.docChanged||r.selectionSet||r.scrolledIntoView||r.storedMarksSet||!r.isGeneric)&&this._tiptapEditor.dispatch(r),o}finally{this.activeTransaction=null}}extension(t,o=t.key()){const r=this.extensions[o];if(!r)throw new Error(`Extension ${o} not found`);return r}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this._tiptapEditor.state}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){var t;return(t=this.prosemirrorView)==null?void 0:t.dom}isFocused(){var t;return((t=this.prosemirrorView)==null?void 0:t.hasFocus())||!1}focus(){var t;(t=this.prosemirrorView)==null||t.focus()}onUploadStart(t){return this.onUploadStartCallbacks.push(t),()=>{const o=this.onUploadStartCallbacks.indexOf(t);o>-1&&this.onUploadStartCallbacks.splice(o,1)}}onUploadEnd(t){return this.onUploadEndCallbacks.push(t),()=>{const o=this.onUploadEndCallbacks.indexOf(t);o>-1&&this.onUploadEndCallbacks.splice(o,1)}}get topLevelBlocks(){return this.document}get document(){return this.transact(t=>wn(t.doc,this.pmSchema))}getBlock(t){return this.transact(o=>$o(o.doc,t))}getPrevBlock(t){return this.transact(o=>Wo(o.doc,t))}getNextBlock(t){return this.transact(o=>zo(o.doc,t))}getParentBlock(t){return this.transact(o=>qo(o.doc,t))}forEachBlock(t,o=!1){const r=this.document.slice();o&&r.reverse();function s(i){for(const a of i){if(t(a)===!1)return!1;const l=o?a.children.slice().reverse():a.children;if(!s(l))return!1}return!0}s(r)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){return this.transact(t=>Si(t))}setTextCursorPosition(t,o="start"){return this.transact(r=>Ko(r,t,o))}getSelection(){return this.transact(t=>wi(t))}getSelectionCutBlocks(){return this.transact(t=>vi(t))}setSelection(t,o){return this.transact(r=>Ci(r,t,o))}get isEditable(){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return!1}return this._tiptapEditor.isEditable===void 0?!0:this._tiptapEditor.isEditable}set isEditable(t){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return}this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,o,r="before"){return this.transact(s=>Nn(s,t,o,r))}updateBlock(t,o){return this.transact(r=>Dn(r,t,o))}removeBlocks(t){return this.transact(o=>mt(o,t,[]).removedBlocks)}replaceBlocks(t,o){return this.transact(r=>mt(r,t,o))}undo(){return this.options.collaboration?this.exec(H.undoCommand):this.exec(jt.undo)}redo(){return this.options.collaboration?this.exec(H.redoCommand):this.exec(jt.redo)}insertInlineContent(t,{updateSelection:o=!1}={}){const r=z(t,this.pmSchema);this.transact(s=>{yi(s,{from:s.selection.from,to:s.selection.to},r,{updateSelection:o})})}getActiveStyles(){return this.transact(t=>{const o={},r=t.selection.$to.marks();for(const s of r){const i=this.schema.styleSchema[s.type.name];if(!i){s.type.name!=="link"&&!s.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",s.type.name);continue}i.propSchema==="boolean"?o[i.type]=!0:o[i.type]=s.attrs.stringValue}return o})}addStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.setMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.setMark(o,{stringValue:r});else throw new K(s.propSchema)}}removeStyles(t){for(const o of Object.keys(t))this._tiptapEditor.commands.unsetMark(o)}toggleStyles(t){for(const[o,r]of Object.entries(t)){const s=this.schema.styleSchema[o];if(!s)throw new Error(`style ${o} not found in styleSchema`);if(s.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(o);else if(s.propSchema==="string")this._tiptapEditor.commands.toggleMark(o,{stringValue:r});else throw new K(s.propSchema)}}getSelectedText(){return this.transact(t=>t.doc.textBetween(t.selection.from,t.selection.to))}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,o){if(t==="")return;const r=this.pmSchema.mark("link",{href:t});this.transact(s=>{const{from:i,to:a}=s.selection;o?s.insertText(o,i,a).addMark(i,i+o.length,r):s.setSelection(C.TextSelection.create(s.doc,a)).addMark(i,a,r)})}canNestBlock(){return bi(this)}nestBlock(){Fo(this)}canUnnestBlock(){return ki(this)}unnestBlock(){gi(this)}moveBlocksUp(){return hi(this)}moveBlocksDown(){return fi(this)}async blocksToHTMLLossy(t=this.document){return Me(this.pmSchema,this).exportBlocks(t,{})}async blocksToFullHTML(t){return Fn(this.pmSchema,this).serializeBlocks(t,{})}async tryParseHTMLToBlocks(t){return $t(t,this.pmSchema)}async blocksToMarkdownLossy(t=this.document){return jo(t,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(t){return Yo(t,this.pmSchema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this.extensions.yCursorPlugin.updateUser(t)}onBeforeChange(t){return this.headless?()=>{}:this.extensions.blockChange.subscribe(o=>t(this,o))}onChange(t){if(this.headless)return;const o=({transaction:r,appendedTransactions:s})=>{t(this,{getChanges:()=>Nt(r,s)})};return this._tiptapEditor.on("v3-update",o),()=>{this._tiptapEditor.off("v3-update",o)}}onSelectionChange(t,o){if(this.headless)return;const r=s=>{s.transaction.getMeta(H.ySyncPluginKey)&&!o||t(this)};return this._tiptapEditor.on("selectionUpdate",r),()=>{this._tiptapEditor.off("selectionUpdate",r)}}onCreate(t){return this.on("create",t),()=>{this.off("create",t)}}getSelectionBoundingBox(){if(!this.prosemirrorView)return;const{selection:t}=this.prosemirrorState,{ranges:o}=t,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(w.isNodeSelection(t)){const i=this.prosemirrorView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return w.posToDOMRect(this.prosemirrorView,r,s)}get isEmpty(){const t=this.document;return t.length===0||t.length===1&&t[0].type==="paragraph"&&t[0].content.length===0}openSuggestionMenu(t,o){this.prosemirrorView&&(this.focus(),this.transact(r=>{o!=null&&o.deleteTriggerCharacter&&r.insertText(t),r.scrollIntoView().setMeta(this.suggestionMenus.plugins[0],{triggerCharacter:t,deleteTriggerCharacter:(o==null?void 0:o.deleteTriggerCharacter)||!1,ignoreQueryLength:(o==null?void 0:o.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(t){this.showSelectionPlugin.setEnabled(t)}convertHtmlToBlockNoteHtml(t){return Go(t.trim()).innerHTML}pasteHTML(t,o=!1){var s;let r=t;o||(r=this.convertHtmlToBlockNoteHtml(t)),r&&((s=this.prosemirrorView)==null||s.pasteHTML(r))}pasteText(t){var o;return(o=this.prosemirrorView)==null?void 0:o.pasteText(t)}async pasteMarkdown(t){return this.pasteHTML(await Wt(t))}}const qa={gray:{text:"#9b9a97",background:"#ebeced"},brown:{text:"#64473a",background:"#e9e5e3"},red:{text:"#e03e3e",background:"#fbe4e4"},orange:{text:"#d9730d",background:"#f6e9d9"},yellow:{text:"#dfab01",background:"#fbf3db"},green:{text:"#4d6461",background:"#ddedea"},blue:{text:"#0b6e99",background:"#ddebf1"},purple:{text:"#6940a5",background:"#eae4f2"},pink:{text:"#ad1a72",background:"#f4dfeb"}},Ka={gray:{text:"#bebdb8",background:"#9b9a97"},brown:{text:"#8e6552",background:"#64473a"},red:{text:"#ec4040",background:"#be3434"},orange:{text:"#e3790d",background:"#b7600a"},yellow:{text:"#dfab01",background:"#b58b00"},green:{text:"#6b8b87",background:"#4d6461"},blue:{text:"#0e87bc",background:"#0b6e99"},purple:{text:"#8552d7",background:"#6940a5"},pink:{text:"#da208f",background:"#ad1a72"}};class ja{constructor(n,t,o){this.mappings=t,this.options=o}async resolveFile(n){var o;if(!((o=this.options)!=null&&o.resolveFileUrl))return(await fetch(n)).blob();const t=await this.options.resolveFileUrl(n);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(n){return Object.entries(n).map(([o,r])=>this.mappings.styleMapping[o](r,this))}mapInlineContent(n){return this.mappings.inlineContentMapping[n.type](n,this)}transformInlineContent(n){return n.map(t=>this.mapInlineContent(t))}async mapBlock(n,t,o,r){return this.mappings.blockMapping[n.type](n,this,t,o,r)}}function Ga(e){return{createBlockMapping:n=>n,createInlineContentMapping:n=>n,createStyleMapping:n=>n}}let _e;async function Ya(){return _e||(_e=(async()=>{const[e,n]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),t="default"in e?e.default:e,o="default"in n?n.default:n;return await t.init({data:o}),{emojiMart:t,emojiData:o}})(),_e)}async function Xa(e,n){if(!Po("text",e))return[];const{emojiData:t,emojiMart:o}=await Ya();return(n.trim()===""?Object.values(t.emojis):await o.SearchIndex.search(n)).map(s=>({id:s.skins[0].native,onItemClick:()=>e.insertInlineContent(s.skins[0].native+" ")}))}function Ja(e,...n){const t=[...e];for(const o of n)for(const r of o){const s=t.findLastIndex(i=>i.group===r.group);s===-1?t.push(r):t.splice(s+1,0,r)}return t}exports.AudioBlock=Jn;exports.BlockNoteEditor=Kt;exports.BlockNoteExtension=_;exports.BlockNoteSchema=Ce;exports.COLORS_DARK_MODE_DEFAULT=Ka;exports.COLORS_DEFAULT=qa;exports.CodeBlock=Qn;exports.DEFAULT_LINK_PROTOCOL=lr;exports.EMPTY_CELL_HEIGHT=qs;exports.EMPTY_CELL_WIDTH=_t;exports.EventEmitter=ot;exports.Exporter=ja;exports.FILE_AUDIO_ICON_SVG=qn;exports.FILE_ICON_SVG=Wn;exports.FILE_IMAGE_ICON_SVG=lo;exports.FILE_VIDEO_ICON_SVG=yo;exports.FileBlock=so;exports.FilePanelProsemirrorPlugin=er;exports.FilePanelView=Qo;exports.FormattingToolbarProsemirrorPlugin=or;exports.FormattingToolbarView=tr;exports.HTMLToBlocks=$t;exports.ImageBlock=mo;exports.LinkToolbarProsemirrorPlugin=ir;exports.PageBreak=Ho;exports.SideMenuProsemirrorPlugin=hr;exports.SideMenuView=ur;exports.SuggestionMenuProseMirrorPlugin=mr;exports.TableHandlesProsemirrorPlugin=br;exports.TableHandlesView=gr;exports.UniqueID=Be;exports.UnreachableCaseError=K;exports.VALID_LINK_PROTOCOLS=ar;exports.VideoBlock=Bo;exports.addInlineContentAttributes=dt;exports.addInlineContentKeyboardShortcuts=vn;exports.addStyleAttributes=xn;exports.applyNonSelectableBlockFix=bn;exports.assertEmpty=Zr;exports.audioBlockConfig=jn;exports.audioParse=Yn;exports.audioPropSchema=Kn;exports.audioRender=Gn;exports.audioToExternalHTML=Xn;exports.blockToNode=se;exports.blocksToMarkdown=jo;exports.camelToDataKebab=Se;exports.captureCellAnchor=Hn;exports.checkBlockHasDefaultProp=ri;exports.checkBlockIsDefaultType=Mo;exports.checkBlockIsFileBlock=ti;exports.checkBlockIsFileBlockWithPlaceholder=oi;exports.checkBlockIsFileBlockWithPreview=ni;exports.checkBlockTypeHasDefaultProp=Io;exports.checkBlockTypeInSchema=Qs;exports.checkDefaultBlockTypeInSchema=V;exports.checkDefaultInlineContentTypeInSchema=Po;exports.checkInlineContentTypeInSchema=ei;exports.checkPageBreakBlocksInSchema=Oo;exports.cleanHTMLToMarkdown=nt;exports.combineByGroup=Ja;exports.contentNodeToInlineContent=xe;exports.contentNodeToTableContent=xt;exports.createAddFileButton=$n;exports.createBlockSpec=ke;exports.createBlockSpecFromStronglyTypedTiptapNode=Z;exports.createDefaultBlockDOMOutputSpec=$;exports.createExternalHTMLExporter=Me;exports.createFigureWithCaption=et;exports.createFileBlockWrapper=Qe;exports.createFileNameWithIcon=zn;exports.createInlineContentSpec=ts;exports.createInlineContentSpecFromTipTapNode=En;exports.createInternalBlockSpec=Bt;exports.createInternalHTMLSerializer=Fn;exports.createInternalInlineContentSpec=Sn;exports.createInternalStyleSpec=Mt;exports.createLinkWithCaption=Le;exports.createResizableFileBlockWrapper=Ht;exports.createStronglyTypedTiptapNode=j;exports.createStyleSpec=ns;exports.createStyleSpecFromTipTapMark=ne;exports.createSuggestionMenu=Ea;exports.createToggleWrapper=Dt;exports.defaultBlockSchema=To;exports.defaultBlockSpecs=Rt;exports.defaultBlockToHTML=ct;exports.defaultCodeBlockPropSchema=Zn;exports.defaultInlineContentSchema=xo;exports.defaultInlineContentSpecs=Ut;exports.defaultProps=A;exports.defaultStyleSchema=Zs;exports.defaultStyleSpecs=Vt;exports.defaultToggledState=io;exports.docToBlocks=wn;exports.fileBlockConfig=to;exports.fileParse=oo;exports.filePropSchema=eo;exports.fileRender=no;exports.fileToExternalHTML=ro;exports.filenameFromURL=es;exports.filterSuggestionItems=li;exports.formatKeyboardShortcut=X;exports.formattingToolbarPluginKey=nr;exports.getBlock=$o;exports.getBlockCache=Je;exports.getBlockFromPos=je;exports.getBlockInfo=ee;exports.getBlockInfoFromResolvedPos=ye;exports.getBlockInfoFromSelection=T;exports.getBlockInfoFromTransaction=Te;exports.getBlockInfoWithManualOffset=Ge;exports.getBlockNoteExtensions=kr;exports.getBlockNoteSchema=we;exports.getBlockSchema=Ye;exports.getBlockSchemaFromSpecs=Tt;exports.getBlocksChangedByTransaction=Nt;exports.getColspan=me;exports.getDefaultEmojiPickerItems=Xa;exports.getDefaultSlashMenuItems=ai;exports.getInlineContentParseRules=Bn;exports.getInlineContentSchema=Xe;exports.getInlineContentSchemaFromSpecs=Pt;exports.getNearestBlockPos=J;exports.getNextBlock=zo;exports.getNodeById=W;exports.getPageBreakSlashMenuItems=di;exports.getParentBlock=qo;exports.getParseRules=kn;exports.getPmSchema=R;exports.getPrevBlock=Wo;exports.getRowspan=Fe;exports.getStyleParseRules=Pn;exports.getStyleSchema=ce;exports.getStyleSchemaFromSpecs=It;exports.imageBlockConfig=uo;exports.imageParse=ho;exports.imagePropSchema=co;exports.imageRender=po;exports.imageToExternalHTML=fo;exports.inheritedProps=Et;exports.initializeESMDependencies=Ae;exports.inlineContentToNodes=z;exports.insertBlocks=Nn;exports.insertOrUpdateBlock=D;exports.isAppleOS=mn;exports.isLinkInlineContent=lt;exports.isNodeBlock=Ze;exports.isPartialLinkInlineContent=St;exports.isPartialTableCell=fe;exports.isSafari=Qr;exports.isStyledTextInlineContent=oe;exports.isTableCell=Ke;exports.isTableCellSelection=kt;exports.linkToolbarPluginKey=sr;exports.mapTableCell=Ue;exports.mappingFactory=Ga;exports.markdownToBlocks=Yo;exports.markdownToHTML=Wt;exports.mergeCSSClasses=Q;exports.mergeParagraphs=gn;exports.nodeToBlock=x;exports.nodeToCustomInlineContent=$e;exports.pageBreakConfig=Lo;exports.pageBreakParse=No;exports.pageBreakRender=Ao;exports.pageBreakSchema=Ft;exports.pageBreakToExternalHTML=Do;exports.parseEmbedElement=bt;exports.parseFigureElement=Ie;exports.propsToAttributes=be;exports.prosemirrorSliceToSlicedBlocks=Cn;exports.removeAndInsertBlocks=mt;exports.selectedFragmentToHTML=qt;exports.shikiHighlighterPromiseSymbol=Re;exports.shikiParserSymbol=gt;exports.sideMenuPluginKey=pr;exports.stylePropsToAttributes=Tn;exports.tableContentToNodes=Pe;exports.tableHandlesPluginKey=de;exports.trackPosition=fr;exports.updateBlock=Dn;exports.updateBlockCommand=U;exports.updateBlockTr=At;exports.uploadToTmpFilesDotOrg_DEV_ONLY=si;exports.videoBlockConfig=Co;exports.videoParse=So;exports.videoPropSchema=wo;exports.videoRender=vo;exports.videoToExternalHTML=Eo;exports.withPageBreak=ci;exports.wrapInBlockStructure=ve;
13
13
  //# sourceMappingURL=blocknote.cjs.map