@blocknote/core 0.8.2 → 0.8.3

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