@blocknote/core 0.9.3 → 0.9.4

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