@blocknote/core 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/blocknote.js +753 -633
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +1 -1
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +19 -28
  7. package/src/BlockNoteExtensions.ts +10 -0
  8. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +61 -0
  9. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +62 -0
  10. package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +107 -97
  11. package/src/extensions/Blocks/nodes/Block.module.css +91 -6
  12. package/src/extensions/Blocks/nodes/BlockContainer.ts +39 -26
  13. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
  14. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +8 -0
  15. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +80 -35
  16. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +16 -0
  17. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +34 -3
  18. package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -1
  19. package/src/extensions/SlashMenu/SlashMenuExtension.ts +1 -1
  20. package/src/extensions/SlashMenu/SlashMenuItem.ts +3 -28
  21. package/src/extensions/SlashMenu/defaultCommands.tsx +14 -32
  22. package/src/extensions/SlashMenu/index.ts +1 -6
  23. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +75 -0
  24. package/src/extensions/TextColor/TextColorExtension.ts +54 -0
  25. package/src/extensions/TextColor/TextColorMark.ts +62 -0
  26. package/src/shared/plugins/suggestion/SuggestionItem.ts +0 -9
  27. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +191 -228
  28. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +1 -1
  29. package/types/src/api/Document.d.ts +5 -0
  30. package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +9 -0
  31. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +9 -0
  32. package/types/src/extensions/Blocks/PreviousBlockTypePlugin.d.ts +3 -2
  33. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -0
  34. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +4 -9
  35. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +10 -0
  36. package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +2 -19
  37. package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +5 -0
  38. package/types/src/extensions/SlashMenu/index.d.ts +1 -2
  39. package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +9 -0
  40. package/types/src/extensions/TextColor/TextColorExtension.d.ts +9 -0
  41. package/types/src/extensions/TextColor/TextColorMark.d.ts +9 -0
  42. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +0 -6
  43. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +9 -23
  44. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +1 -1
@@ -1,2 +1,2 @@
1
- (function(m,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@tiptap/core"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-model"),require("prosemirror-state"),require("prosemirror-view"),require("lodash"),require("@tiptap/extension-link"),require("uuid")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-model","prosemirror-state","prosemirror-view","lodash","@tiptap/extension-link","uuid"],u):(m=typeof globalThis<"u"?globalThis:m||self,u(m.blocknote={},m.core,m.Bold,m.Code,m.DropCursor,m.GapCursor,m.HardBreak,m.extensionHistory,m.Italic,m.Strike,m.Text,m.Underline,m.prosemirrorModel,m.prosemirrorState,m.pv,m.lodash,m.extensionLink,m.uuid))})(this,function(m,u,P,W,V,Y,J,Q,X,Z,ee,te,S,g,w,F,U,ne){"use strict";var st=Object.defineProperty;var at=(m,u,P)=>u in m?st(m,u,{enumerable:!0,configurable:!0,writable:!0,value:P}):m[u]=P;var p=(m,u,P)=>(at(m,typeof u!="symbol"?u+"":u,P),P);const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t};function oe(t){if(t&&t.__esModule)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const re=I(P),ie=I(W),se=I(V),ae=I(Y),de=I(J),le=I(X),ce=I(Z),ue=I(ee),he=I(te),pe=oe(w);function b(t,e){if(e<=0||e>t.nodeSize)return;const n=t.resolve(e),o=n.depth;let r=n.node(o),a=o;for(;a>=0;){if(a===0)return;if(r.type.name==="blockContainer")break;a-=1,r=n.node(a)}const d=r.attrs.id,i=r.firstChild,s=i.type,c=r.childCount===2?r.lastChild.childCount:0,f=n.start(a),h=n.end(a);return{id:d,node:r,contentNode:i,contentType:s,numChildBlocks:c,startPos:f,endPos:h,depth:a}}const q=new g.PluginKey("previous-blocks"),fe={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},me=()=>new g.Plugin({key:q,view(t){return{update:async(e,n)=>{var o;(o=this.key)!=null&&o.getState(e.state).needsUpdate&&setTimeout(()=>{e.dispatch(e.state.tr.setMeta(q,{clearUpdate:!0}))},0)}}},state:{init(){return{prevBlockAttrs:{},needsUpdate:!1}},apply(t,e,n,o){if(e.needsUpdate=!1,e.prevBlockAttrs={},!t.docChanged||n.doc.eq(o.doc))return e;const r=u.combineTransactionSteps(n.doc,[t]);return u.getChangedRanges(r).forEach(()=>{const d=u.findChildren(n.doc,c=>c.attrs.id),i=new Map(d.map(c=>[c.node.attrs.id,c])),s=u.findChildren(o.doc,c=>c.attrs.id);for(let c of s){const f=i.get(c.node.attrs.id),h=f==null?void 0:f.node.firstChild,l=c.node.firstChild;if(f&&h&&l){const k={index:l.attrs.index,level:l.attrs.level,type:l.type.name,depth:o.doc.resolve(c.pos).depth},y={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:n.doc.resolve(f.pos).depth},B=y.index===null&&k.index!==null,M=y.index!==null&&k.index!==null&&y.index===k.index,v=y.type==="numberedListItem"&&k.type==="numberedListItem"?B||M:!0;JSON.stringify(y)!==JSON.stringify(k)&&v&&(y["depth-change"]=y.depth-k.depth,e.prevBlockAttrs[c.node.attrs.id]=y,console.log("id:",c.node.attrs.id,"previousBlockTypePlugin changes detected, oldAttrs",y,"new",k),e.needsUpdate=!0)}}}),e}},props:{decorations(t){const e=this.getState(t);if(!e.needsUpdate)return;const n=[];return t.doc.descendants((o,r)=>{if(!o.attrs.id)return;const a=e.prevBlockAttrs[o.attrs.id];if(!a)return;const d={};for(let[s,c]of Object.entries(a))d["data-prev-"+fe[s]]=c||"none";console.log("previousBlockTypePlugin committing decorations",d);const i=w.Decoration.node(r,r+o.nodeSize,{...d});n.push(i)}),w.DecorationSet.create(t.doc,n)}}}),C={blockOuter:"_blockOuter_6qmsf_5",block:"_block_6qmsf_5",blockContent:"_blockContent_6qmsf_25",blockGroup:"_blockGroup_6qmsf_53",isEmpty:"_isEmpty_6qmsf_238",isFilter:"_isFilter_6qmsf_239",hasAnchor:"_hasAnchor_6qmsf_252"},ke={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},ge=u.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,addOptions(){return{HTMLAttributes:{}}},addAttributes(){return{blockColor:{default:void 0},blockStyle:{default:void 0}}},parseHTML(){return[{tag:"div",getAttrs:t=>{if(typeof t=="string")return!1;const e={};for(let[n,o]of Object.entries(ke))t.getAttribute(o)&&(e[n]=t.getAttribute(o));return t.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:C.blockOuter,"data-node-type":"block-outer"}),["div",u.mergeAttributes(t,{class:C.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:t=>({state:e,dispatch:n})=>{const o=e.schema.nodes.blockContainer.createAndFill();return n&&e.tr.insert(t,o),!0},BNDeleteBlock:t=>({state:e,view:n,dispatch:o})=>{const r=b(e.doc,t);if(r===void 0)return!1;const{startPos:a,endPos:d}=r;return o&&(e.tr.deleteRange(a,d),e.tr.setSelection(new g.TextSelection(e.doc.resolve(a+1))),n.focus()),!0},BNMergeBlocks:t=>({state:e,dispatch:n})=>{const o=e.doc.resolve(t+1).node().type.name==="blockContainer",r=e.doc.resolve(t-1).node().type.name==="blockContainer";if(!o||!r)return!1;const a=b(e.doc,t+1),{node:d,contentNode:i,startPos:s,endPos:c,depth:f}=a;if(d.childCount===2){const k=e.doc.resolve(s+i.nodeSize+1),y=e.doc.resolve(c-1),B=k.blockRange(y);n&&e.tr.lift(B,f-1)}let h=t-1,l=b(e.doc,h);for(;l.numChildBlocks>0;)if(h--,l=b(e.doc,h),l===void 0)return!1;return n&&(e.tr.deleteRange(s,s+i.nodeSize),e.tr.insertText(i.textContent,h-1),e.tr.setSelection(new g.TextSelection(e.doc.resolve(h-1)))),!0},BNSplitBlock:(t,e)=>({state:n,dispatch:o})=>{const r=b(n.doc,t);if(r===void 0)return!1;const{contentNode:a,contentType:d,startPos:i,endPos:s,depth:c}=r,f=s+1,h=n.doc.textBetween(t,s),l=n.schema.nodes.blockContainer.createAndFill(),k=f+2;o&&(n.tr.insert(f,l),n.tr.insertText(h,k),e&&n.tr.setBlockType(k,k,n.schema.node(d).type,a.attrs));const y=n.doc.content.cut(i,t);return o&&n.tr.replace(i,s,new S.Slice(y,c,c)),!0},BNUpdateBlock:(t,e)=>({state:n,dispatch:o})=>{const r=b(n.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,contentNode:i}=r;return o&&n.tr.setBlockType(d+1,d+i.nodeSize+1,n.schema.node(e.type).type,{...a.attrs,...e.props}),!0},BNCreateOrUpdateBlock:(t,e)=>({state:n,chain:o})=>{const r=b(n.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,endPos:i}=r;if(a.textContent.length===0){const s=d+1;return o().BNUpdateBlock(t,e).setTextSelection(s).run()}else{const s=i+1,c=s+1;return o().BNCreateBlock(s).BNUpdateBlock(c,e).setTextSelection(c).run()}}}},addProseMirrorPlugins(){return[me()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:o})=>{const{contentType:r}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,d=r.name==="paragraph";return a&&!d?n.BNUpdateBlock(o.selection.from,{type:"paragraph",props:{}}):!1}),()=>n.command(({state:o})=>o.selection.$anchor.parentOffset===0?n.liftListItem("blockContainer"):!1),()=>n.command(({state:o})=>{const{depth:r,startPos:a}=b(o.doc,o.selection.from),d=o.selection.$anchor.parentOffset===0,i=o.selection.anchor===o.selection.head,s=a===2,c=a-1;return!s&&d&&i&&r===2?n.BNMergeBlocks(c):!1})]),Enter:()=>this.editor.commands.first(({commands:n})=>[()=>n.command(({state:o})=>{const{node:r,depth:a}=b(o.doc,o.selection.from),d=o.selection.$anchor.parentOffset===0,i=o.selection.anchor===o.selection.head,s=r.textContent.length===0,c=a>2;return d&&i&&s&&c?n.liftListItem("blockContainer"):!1}),()=>n.command(({state:o,chain:r})=>{const{node:a,endPos:d}=b(o.doc,o.selection.from),i=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,c=a.textContent.length===0;if(i&&s&&c){const f=d+1,h=f+2;return r().BNCreateBlock(f).setTextSelection(h).run(),!0}return!1}),()=>n.command(({state:o,chain:r})=>{const{node:a}=b(o.doc,o.selection.from);return a.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:{}})}}}),ye=u.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:t=>typeof t=="string"?!1:t.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(this.options.HTMLAttributes,t,{class:C.blockGroup,"data-node-type":"blockGroup"}),0]}}),be=u.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"blockContainer"}]},renderHTML(){return["div",{class:C.blockContent,"data-content-type":this.name},["p",0]]}}),ve=u.Node.create({name:"heading",group:"blockContent",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:t=>t.getAttribute("data-level"),renderHTML:t=>({"data-level":t.level})}}},addInputRules(){return[...["1","2","3"].map(t=>new u.InputRule({find:new RegExp(`^(#{${parseInt(t)}})\\s$`),handler:({state:e,chain:n,range:o})=>{n().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:t}}).deleteRange({from:o.from,to:o.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"blockContainer"},{tag:"h2",attrs:{level:"2"},node:"blockContainer"},{tag:"h3",attrs:{level:"3"},node:"blockContainer"}]},renderHTML({node:t,HTMLAttributes:e}){return["div",u.mergeAttributes(e,{class:C.blockContent,"data-content-type":this.name}),["h"+t.attrs.level,0]]}}),z=t=>{const{node:e,contentType:n}=b(t.state.doc,t.state.selection.from),o=t.state.selection.anchor===t.state.selection.head;return!n.name.endsWith("ListItem")||!o?!1:t.commands.first(({state:r,chain:a,commands:d})=>[()=>d.command(()=>e.textContent.length===0?d.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>d.command(()=>e.textContent.length>0?(a().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},Be=u.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new u.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:t,chain:e,range:n})=>{e().BNUpdateBlock(t.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:n.from,to:n.to})}})]},addKeyboardShortcuts(){return{Enter:()=>z(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:e.tagName==="UL"?{}:!1},node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:C.blockContent,"data-content-type":this.name}),["li",0]]}}),Me=new g.PluginKey("numbered-list-indexing"),Ce=()=>new g.Plugin({key:Me,appendTransaction:(t,e,n)=>{const o=n.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return n.doc.descendants((a,d)=>{if(a.type.name==="blockContainer"&&a.firstChild.type.name==="numberedListItem"){let i="1";const s=d===1,c=b(o.doc,d+1);if(c===void 0)return;if(!s){const l=b(o.doc,d-2);if(l===void 0)return;if(!(c.depth!==l.depth)){const y=l.contentNode;if(l.contentType.name==="numberedListItem"){const v=y.attrs.index;i=(parseInt(v)+1).toString()}}}c.contentNode.attrs.index!==i&&(r=!0,o.setNodeMarkup(d+1,void 0,{index:i}))}}),r?o:null}}),we=u.Node.create({name:"numberedListItem",group:"blockContent",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:t=>t.getAttribute("data-index"),renderHTML:t=>({"data-index":t.index})}}},addInputRules(){return[new u.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:t,chain:e,range:n})=>{e().BNUpdateBlock(t.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:n.from,to:n.to})}})]},addKeyboardShortcuts(){return{Enter:()=>z(this.editor)}},addProseMirrorPlugins(){return[Ce()]},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:e.tagName==="OL"?{}:!1},node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:C.blockContent,"data-content-type":this.name}),["li",0]]}}),Ie=[be,ve,Be,we,ge,ye,u.Node.create({name:"doc",topNode:!0,content:"blockGroup"})];class xe{constructor({editor:e,formattingToolbarFactory:n,view:o,shouldShow:r}){p(this,"editor");p(this,"view");p(this,"formattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"toolbarIsOpen",!1);p(this,"shouldShow",({view:e,state:n,from:o,to:r})=>{const{doc:a,selection:d}=n,{empty:i}=d,s=!a.textBetween(o,r).length&&u.isTextSelection(n.selection);return!(!e.hasFocus()||i||s)});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.editor.view))});p(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.editor.view))});p(this,"blurHandler",({event:e})=>{var n,o;if(this.preventHide){this.preventHide=!1;return}(e==null?void 0:e.relatedTarget)&&((o=(n=this.formattingToolbar.element)==null?void 0:n.parentNode)==null?void 0:o.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});this.editor=e,this.view=o,this.formattingToolbar=n(this.getStaticParams()),r&&(this.shouldShow=r),this.view.dom.addEventListener("mousedown",this.viewMousedownHandler),this.view.dom.addEventListener("mouseup",this.viewMouseupHandler),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler)}update(e,n){var l;const{state:o,composing:r}=e,{doc:a,selection:d}=o,i=n&&n.doc.eq(a)&&n.selection.eq(d);if(r||i)return;const{ranges:s}=d,c=Math.min(...s.map(k=>k.$from.pos)),f=Math.max(...s.map(k=>k.$to.pos)),h=(l=this.shouldShow)==null?void 0:l.call(this,{editor:this.editor,view:e,state:o,oldState:n,from:c,to:f});if(!this.toolbarIsOpen&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!0),this.toolbarIsOpen=!0,this.formattingToolbar.element.addEventListener("mousedown",k=>k.preventDefault());return}if(this.toolbarIsOpen&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!h||this.preventShow)){this.formattingToolbar.hide(),this.toolbarIsOpen=!1,this.formattingToolbar.element.removeEventListener("mousedown",k=>k.preventDefault());return}}destroy(){this.view.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.view.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler)}getSelectionBoundingBox(){const{state:e}=this.editor.view,{selection:n}=e,{ranges:o}=n,r=Math.min(...o.map(d=>d.$from.pos)),a=Math.max(...o.map(d=>d.$to.pos));if(u.isNodeSelection(n)){const d=this.editor.view.nodeDOM(r);if(d)return d.getBoundingClientRect()}return u.posToDOMRect(this.editor.view,r,a)}getStaticParams(){return{toggleBold:()=>{this.editor.view.focus(),this.editor.commands.toggleBold()},toggleItalic:()=>{this.editor.view.focus(),this.editor.commands.toggleItalic()},toggleUnderline:()=>{this.editor.view.focus(),this.editor.commands.toggleUnderline()},toggleStrike:()=>{this.editor.view.focus(),this.editor.commands.toggleStrike()},setHyperlink:(e,n)=>{if(e==="")return;let{from:o,to:r}=this.editor.state.selection;n||(n=this.editor.state.doc.textBetween(o,r));const a=this.editor.schema.mark("link",{href:e});this.editor.view.dispatch(this.editor.view.state.tr.insertText(n,o,r).addMark(o,o+n.length,a)),this.editor.view.focus()},updateBlock:e=>{this.editor.view.focus(),this.editor.commands.BNUpdateBlock(this.editor.state.selection.from,e)}}}getDynamicParams(){const e=b(this.editor.state.doc,this.editor.state.selection.from);return{boldIsActive:this.editor.isActive("bold"),italicIsActive:this.editor.isActive("italic"),underlineIsActive:this.editor.isActive("underline"),strikeIsActive:this.editor.isActive("strike"),hyperlinkIsActive:this.editor.isActive("link"),activeHyperlinkUrl:this.editor.getAttributes("link").href?this.editor.getAttributes("link").href:"",activeHyperlinkText:this.editor.state.doc.textBetween(this.editor.state.selection.from,this.editor.state.selection.to),block:{type:e.contentType.name,props:e.contentNode.attrs},referenceRect:this.getSelectionBoundingBox()}}}const Te=t=>new g.Plugin({key:new g.PluginKey("FormattingToolbarPlugin"),view:e=>new xe({view:e,...t})}),Pe=u.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory)throw new Error("UI Element factory not defined for FormattingToolbarExtension");return[Te({editor:this.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new g.PluginKey("FormattingToolbarPlugin")})]}}),_={bnEditor:"_bnEditor_xixap_3",bnRoot:"_bnRoot_xixap_13",dragPreview:"_dragPreview_xixap_27"},Ee=u.findParentNode(t=>t.type.name==="blockContainer");function Ne(t,e){if(!e.empty)return;const n=e.$anchor.nodeBefore;if(!n||!n.text)return;const o=new RegExp(`${F.escapeRegExp(t)}([^${F.escapeRegExp(t)}]*)$`),r=n.text.match(o);if(!!r)return{query:r[1],range:{from:e.$anchor.pos-r[1].length-t.length,to:e.$anchor.pos}}}class Ae{constructor({editor:e,pluginKey:n,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");this.editor=e,this.pluginKey=n,this.pluginState={active:!1,range:null,query:null,notFoundCount:0,items:[],selectedItemIndex:0,type:"slash",decorationId:null},this.itemCallback=a=>o({item:a,editor:e,range:this.pluginState.range}),this.suggestionsMenu=r(this.getStaticParams())}update(e,n){const o=this.pluginKey.getState(n),r=this.pluginKey.getState(e.state),a=!o.active&&r.active,d=o.active&&!r.active,i=o.active&&r.active;!a&&!i&&!d||(this.pluginState=d?o:r,d&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",s=>s.preventDefault())),i&&this.suggestionsMenu.render(this.getDynamicParams(),!1),a&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",s=>s.preventDefault())))}getStaticParams(){return{itemCallback:e=>this.itemCallback(e)}}getDynamicParams(){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);return{items:this.pluginState.items,selectedItemIndex:this.pluginState.selectedItemIndex,referenceRect:e.getBoundingClientRect()}}}function Se({pluginKey:t,editor:e,char:n,suggestionsMenuFactory:o,onSelectItem:r=()=>{},items:a=()=>[]}){if(n.length!==1)throw new Error("'char' should be a single character");const d=i=>{i.dispatch(i.state.tr.setMeta(t,{deactivate:!0}))};return new g.Plugin({key:t,view:i=>new Ae({editor:e,pluginKey:t,onSelectItem:s=>{d(i),r(s)},suggestionsMenuFactory:o}),state:{init(){return{active:!1,range:null,query:null,notFoundCount:0,items:[],selectedItemIndex:0,type:"slash",decorationId:null}},apply(i,s,c,f){var k,y,B,M;const{selection:h}=i,l={...s};if(i.getMeta("numberedListIndexing")!==void 0)return l;if(((k=i.getMeta(t))==null?void 0:k.selectedItemIndexChanged)!==void 0){let v=i.getMeta(t).selectedItemIndexChanged;return v<0&&(v=s.items.length-1),v>=s.items.length&&(v=0),l.selectedItemIndex=v,l}if(h.from===h.to&&!((y=i.getMeta(t))!=null&&y.deactivate)&&!i.getMeta("focus")&&!i.getMeta("blur")&&!i.getMeta("pointer")){if(s.active&&h.from<=s.range.from)l.active=!1;else if((B=i.getMeta(t))!=null&&B.activate){const v=`id_${Math.floor(Math.random()*4294967295)}`;l.decorationId=v,l.range={from:h.from-1,to:h.to},l.query="",l.active=!0,l.type=(M=i.getMeta(t))==null?void 0:M.type,l.selectedItemIndex=0}else if(s.active){const v=Ne(s.type==="slash"?n:"",f.selection);if(!v)throw new Error("active but no match (suggestions)");l.range=v.range,l.active=!0,l.decorationId=s.decorationId,l.query=v.query,l.selectedItemIndex=0}}else l.active=!1;return l.active&&(l.items=a(l.query),l.items.length?l.notFoundCount=0:l.range.to>s.range.to?l.notFoundCount=s.notFoundCount+1:l.notFoundCount=s.notFoundCount,l.notFoundCount>3&&(l.active=!1)),l.active||(l.decorationId=null,l.range=null,l.query=null,l.notFoundCount=0,l.items=[]),l}},props:{handleKeyDown(i,s){const{active:c}=this.getState(i.state);if(c){const{items:f,range:h,selectedItemIndex:l}=t.getState(i.state);if(s.key==="ArrowUp")return i.dispatch(i.state.tr.setMeta(t,{selectedItemIndexChanged:l-1})),!0;if(s.key==="ArrowDown")return i.dispatch(i.state.tr.setMeta(t,{selectedItemIndexChanged:l+1})),!0;if(s.key==="Enter")return d(i),r({item:f[l],editor:e,range:h}),!0;if(s.key==="Escape")return d(i),!0}else if(s.key===n)return i.dispatch(i.state.tr.insertText(n).scrollIntoView().setMeta(t,{activate:!0,type:"slash"})),!0;return!1},handleClick(i){d(i)},decorations(i){const{active:s,range:c,decorationId:f,type:h}=this.getState(i);if(!s)return null;if(h==="drag"){const l=Ee(i.selection);if(l)return w.DecorationSet.create(i.doc,[w.Decoration.node(l.pos,l.pos+l.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":f})])}return w.DecorationSet.create(i.doc,[w.Decoration.inline(c.from,c.to,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":f})])}}})}const He=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function A(t){return He()?t.replace("Mod","\u2318"):t.replace("Mod","Ctrl")}var x=(t=>(t.HEADINGS="Headings",t.BASIC_BLOCKS="Basic Blocks",t.CODE="Code Blocks",t.INLINE="Inline",t.EMBED="Embed",t.PLUGIN="Plugin",t))(x||{});class E{constructor(e,n,o,r=[],a,d){p(this,"groupName");this.name=e,this.group=n,this.execute=o,this.aliases=r,this.hint=a,this.shortcut=d,this.groupName=n}match(e){return this.name.toLowerCase().startsWith(e.toLowerCase())||this.aliases.filter(n=>n.toLowerCase().startsWith(e.toLowerCase())).length!==0}}const Le={heading:new E("Heading",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"1"}}).run(),["h","heading1","h1"],"Used for a top-level heading",A("Mod-Alt-1")),heading2:new E("Heading 2",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"2"}}).run(),["h2","heading2","subheading"],"Used for key sections",A("Mod-Alt-2")),heading3:new E("Heading 3",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"3"}}).run(),["h3","heading3","subheading"],"Used for subsections and group headings",A("Mod-Alt-3")),numberedList:new E("Numbered List",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"numberedListItem",props:{}}).run(),["li","list","numberedlist","numbered list"],"Used to display a numbered list",A("Mod-Shift-7")),bulletList:new E("Bullet List",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"bulletListItem",props:{}}).run(),["ul","list","bulletlist","bullet list"],"Used to display an unordered list",A("Mod-Shift-8")),paragraph:new E("Paragraph",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"paragraph",props:{}}).run(),["p"],"Used for the body of your document",A("Mod-Alt-0"))},O=new g.PluginKey("suggestions-slash-commands"),_e=u.Extension.create({name:"slash-command",addOptions(){return{commands:Le,slashMenuFactory:void 0}},addProseMirrorPlugins(){if(!this.options.slashMenuFactory)throw new Error("UI Element factory not defined for SlashMenuExtension");return[Se({pluginKey:O,editor:this.editor,char:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:t=>{const e=[];for(const n in this.options.commands)e.push(this.options.commands[n]);return e.filter(n=>n.match(t))},onSelectItem:({item:t,editor:e,range:n})=>{t.execute(e,n)}})]}});class H extends g.Selection{constructor(n,o){super(n,o);p(this,"nodes");const r=n.node();this.nodes=[],n.doc.nodesBetween(n.pos,o.pos,(a,d,i)=>{if(i!==null&&i.eq(r))return this.nodes.push(a),!1})}static create(n,o,r=o){return new H(n.resolve(o),n.resolve(r))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(n){if(!(n instanceof H)||this.nodes.length!==n.nodes.length||this.from!==n.from||this.to!==n.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(n.nodes[o]))return!1;return!0}map(n,o){let r=o.mapResult(this.from),a=o.mapResult(this.to);return a.deleted?g.Selection.near(n.resolve(r.pos)):r.deleted?g.Selection.near(n.resolve(a.pos)):new H(n.resolve(r.pos),n.resolve(a.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Oe=pe.__serializeForClipboard;let R,N;function Re(){if(!R){const t=document.querySelector(".ProseMirror > [class*='blockGroup']");t&&(R=Fe(t).left)}return R}function De(t){let e={left:t.left+document.body.scrollLeft,top:t.top+document.body.scrollTop,width:t.width,height:t.height,bottom:0,right:0};return e.bottom=e.top+e.height,e.right=e.left+e.width,e}function Fe(t){return De(t.getBoundingClientRect())}function $(t,e){var r;let n=e.posAtCoords(t);if(!n)return;let o=e.domAtPos(n.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 Ue(t,e){let n=$(t,e);if(n&&n.node.nodeType===1){const o=e.docView;let r=o.nearestDesc(n.node,!0);return!r||r===o?null:r.posBefore}return null}function qe(t,e){let n,o;const r=e.resolve(t.from).node().type.spec.group==="blockContent",a=e.resolve(t.to).node().type.spec.group==="blockContent",d=Math.min(t.$anchor.depth,t.$head.depth);if(r&&a){const i=t.$from.start(d-1),s=t.$to.end(d-1);n=e.resolve(i-1).pos,o=e.resolve(s+1).pos}else n=t.from,o=t.to;return{from:n,to:o}}function G(t,e,n=e){e===n&&(n+=t.state.doc.resolve(e+1).node().nodeSize);const o=t.domAtPos(e).node.cloneNode(!0),r=t.domAtPos(e).node,a=(s,c)=>Array.prototype.indexOf.call(s.children,c),d=a(r,t.domAtPos(e+1).node.parentElement),i=a(r,t.domAtPos(n-1).node.parentElement);for(let s=r.childElementCount-1;s>=0;s--)(s>i||s<d)&&o.removeChild(o.children[s]);N=o,N.className=_.dragPreview,document.body.appendChild(N)}function ze(){N!==void 0&&(document.body.removeChild(N),N=void 0)}function $e(t,e){if(!t.dataTransfer)return;let n={left:e.dom.clientWidth/2,top:t.clientY},o=Ue(n,e);if(o!=null){const r=e.state.selection,a=e.state.doc,{from:d,to:i}=qe(r,a),s=d<=o&&o<i,c=!r.$anchor.node().eq(r.$head.node());s&&c?(e.dispatch(e.state.tr.setSelection(H.create(a,d,i))),G(e,d,i)):(e.dispatch(e.state.tr.setSelection(g.NodeSelection.create(e.state.doc,o))),G(e,o));let f=e.state.selection.content(),{dom:h,text:l}=Oe(e,f);t.dataTransfer.clearData(),t.dataTransfer.setData("text/html",h.innerHTML),t.dataTransfer.setData("text/plain",l),t.dataTransfer.effectAllowed="move",t.dataTransfer.setDragImage(N,0,0),e.dragging={slice:f,move:!0}}}class Ge{constructor({editor:e,blockMenuFactory:n,horizontalPosAnchoredAtRoot:o}){p(this,"editor");p(this,"horizontalPosAnchoredAtRoot");p(this,"blockMenu");p(this,"hoveredBlock");p(this,"menuOpen",!1);p(this,"menuFrozen",!1);this.editor=e,this.horizontalPosAnchoredAtRoot=o,this.blockMenu=n(this.getStaticParams()),document.body.addEventListener("mousemove",r=>{var s,c;if(this.menuFrozen)return;const a={left:this.editor.view.dom.clientWidth/2,top:r.clientY},d=$(a,this.editor.view);if(!d){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}if(this.menuOpen&&((s=this.hoveredBlock)==null?void 0:s.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===d.id)return;const i=d.node.firstChild;this.hoveredBlock=i,i&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))},!0),document.body.addEventListener("mousedown",r=>{var a;(a=this.blockMenu.element)!=null&&a.contains(r.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)},!0),document.body.addEventListener("keydown",()=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1},!0)}destroy(){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide())}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const e=this.hoveredBlock.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:e.left,top:e.top});if(!n)return;const o=b(this.editor.state.doc,n.pos);if(o===void 0)return;const{contentNode:r,endPos:a}=o;if(r.textContent.length!==0){const d=a+1,i=d+2;this.editor.chain().BNCreateBlock(d).BNUpdateBlock(i,{type:"paragraph",props:{}}).setTextSelection(i).run()}this.editor.view.focus(),this.editor.view.dispatch(this.editor.view.state.tr.scrollIntoView().setMeta(O,{activate:!0,type:"drag"}))}deleteBlock(){this.menuOpen=!1,this.blockMenu.hide();const e=this.hoveredBlock.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:e.left,top:e.top});!n||this.editor.commands.BNDeleteBlock(n.pos)}getStaticParams(){return{addBlock:()=>this.addBlock(),deleteBlock:()=>this.deleteBlock(),blockDragStart:e=>$e(e,this.editor.view),blockDragEnd:()=>ze(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1}}}getDynamicParams(){const e=this.hoveredBlock.getBoundingClientRect();return{referenceRect:new DOMRect(this.horizontalPosAnchoredAtRoot?Re():e.x,e.y,e.width,e.height)}}}const Ke=t=>new g.Plugin({key:new g.PluginKey("DraggableBlocksPlugin"),view:()=>new Ge({editor:t.editor,blockMenuFactory:t.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),je=u.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[Ke({editor:this.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}}),We=new g.PluginKey("HyperlinkToolbarPlugin");class Ve{constructor({editor:e,hyperlinkToolbarFactory:n}){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");this.editor=e,this.hyperlinkToolbar=n(this.getStaticParams()),this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),e.view.dom.addEventListener("mouseover",o=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),o.target instanceof HTMLAnchorElement&&o.target.nodeName==="A"){const r=o.target,a=e.view.posAtDOM(r,0)+1,d=e.state.doc.resolve(a),i=d.marks();for(const s of i)if(s.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=u.getMarkRange(d,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1})}update(){var n,o,r,a;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 d=this.editor.state.selection.$from.marks();for(const i of d)if(i.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=u.getMarkRange(this.editor.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(n=this.hyperlinkToolbar.element)==null||n.addEventListener("mouseleave",this.startMenuUpdateTimer),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1);return}if(!this.hyperlinkMark&&e){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(a=this.hyperlinkToolbar.element)==null||a.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}getStaticParams(){return{editHyperlink:(e,n)=>{const o=this.editor.view.state.tr.insertText(n,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+n.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()}}}getDynamicParams(){return{url:this.hyperlinkMark.attrs.href,text:this.editor.view.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),referenceRect:u.posToDOMRect(this.editor.view,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)}}}const Ye=(t,e)=>new g.Plugin({key:We,view:()=>new Ve({editor:t,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),Je=U.Link.extend({priority:500,addProseMirrorPlugins(){var t;if(!this.options.hyperlinkToolbarFactory)throw new Error("UI Element factory not defined for HyperlinkMark");return[...((t=this.parent)==null?void 0:t.call(this))||[],Ye(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),Qe=new g.PluginKey("blocknote-placeholder"),Xe=u.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new g.Plugin({key:Qe,props:{decorations:t=>{const{doc:e,selection:n}=t,o=O.getState(t),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:a}=n,d=[];if(!!r)return e.descendants((i,s)=>{const c=a>=s&&a<=s+i.nodeSize,f=!i.isLeaf&&!i.childCount;if((c||!this.options.showOnlyCurrent)&&f){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),c&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.type)==="drag"&&(o==null?void 0:o.active)&&h.push(this.options.isFilterClass);const l=w.Decoration.node(s,s+i.nodeSize,{class:h.join(" ")});d.push(l)}return this.options.includeChildren}),w.DecorationSet.create(e,d)}}})]}}),Ze=u.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const t=new g.PluginKey(this.name);return[new g.Plugin({key:t,appendTransaction:(e,n,o)=>{const{doc:r,tr:a,schema:d}=o,i=t.getState(o),s=r.content.size-2,c=d.nodes.blockContainer,f=d.nodes.paragraph;if(!!i)return a.insert(s,c.create(void 0,f.create()))},state:{init:(e,n)=>{},apply:(e,n)=>{if(!e.docChanged)return n;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}}})]}});function et(t,e=JSON.stringify){const n={};return t.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function tt(t){const e=t.filter((o,r)=>t.indexOf(o)!==r);return et(e)}const nt=u.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++,parseInt(window.__TEST_OPTIONS.mockID)):ne.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:t=>t.getAttribute(`data-${this.options.attributeName}`),renderHTML:t=>({[`data-${this.options.attributeName}`]:t[this.options.attributeName]})}}}]},onCreate(){if(this.editor.extensionManager.extensions.find(s=>s.name==="collaboration"))return;const{view:t,state:e}=this.editor,{tr:n,doc:o}=e,{types:r,attributeName:a,generateID:d}=this.options;u.findChildren(o,s=>r.includes(s.type.name)&&s.attrs[a]===null).forEach(({node:s,pos:c})=>{n.setNodeMarkup(c,void 0,{...s.attrs,[a]:d()})}),n.setMeta("addToHistory",!1),t.dispatch(n)},addProseMirrorPlugins(){let t=null,e=!1;return[new g.Plugin({key:new g.PluginKey("uniqueID"),appendTransaction:(n,o,r)=>{console.log("appendTransaction");const a=n.some(y=>y.docChanged)&&!o.doc.eq(r.doc),d=this.options.filterTransaction&&n.some(y=>{var B,M;return!(!((M=(B=this.options).filterTransaction)===null||M===void 0)&&M.call(B,y))});if(!a||d)return;const{tr:i}=r,{types:s,attributeName:c,generateID:f}=this.options,h=u.combineTransactionSteps(o.doc,n),{mapping:l}=h;if(u.getChangedRanges(h).forEach(({newRange:y})=>{const B=u.findChildrenInRange(r.doc,y,T=>s.includes(T.type.name)),M=B.map(({node:T})=>T.attrs[c]).filter(T=>T!==null),v=tt(M);B.forEach(({node:T,pos:L})=>{var D;const j=(D=i.doc.nodeAt(L))===null||D===void 0?void 0:D.attrs[c];if(j===null){i.setNodeMarkup(L,void 0,{...T.attrs,[c]:f()});return}const{deleted:it}=l.invert().mapResult(L);it&&v.includes(j)&&i.setNodeMarkup(L,void 0,{...T.attrs,[c]:f()})})}),!!i.steps.length)return i},view(n){const o=r=>{var a;t=!((a=n.dom.parentElement)===null||a===void 0)&&a.contains(r.target)?n.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(n,o)=>{var r;return(t!==n.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(t=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:n=>{if(!e)return n;const{types:o,attributeName:r}=this.options,a=d=>{const i=[];return d.forEach(s=>{if(s.isText){i.push(s);return}if(!o.includes(s.type.name)){i.push(s.copy(a(s.content)));return}const c=s.type.create({...s.attrs,[r]:null},a(s.content),s.marks);i.push(c)}),S.Fragment.from(i)};return e=!1,new S.Slice(a(n.content),n.openStart,n.openEnd)}}})]}}),K=t=>{const e=[u.extensions.ClipboardTextSerializer,u.extensions.Commands,u.extensions.Editable,u.extensions.FocusEvents,u.extensions.Tabindex,ae.default,Xe.configure({emptyNodeClass:C.isEmpty,hasAnchorClass:C.hasAnchor,isFilterClass:C.isFilter,includeChildren:!0,showOnlyCurrent:!1}),nt.configure({types:["blockContainer"]}),de.default,ue.default,re.default,ie.default,le.default,ce.default,he.default,...Ie,se.default.configure({width:5,color:"#ddeeff"}),Q.History,Ze];return t.blockSideMenuFactory&&e.push(je.configure({blockSideMenuFactory:t.blockSideMenuFactory})),t.formattingToolbarFactory&&e.push(Pe.configure({formattingToolbarFactory:t.formattingToolbarFactory})),t.hyperlinkToolbarFactory?e.push(Je.configure({hyperlinkToolbarFactory:t.hyperlinkToolbarFactory})):e.push(U.Link),t.slashMenuFactory&&e.push(_e.configure({slashMenuFactory:t.slashMenuFactory})),e},ot={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class rt{constructor(e={}){p(this,"tiptapEditor");var a,d,i;const n=K(e.uiFactories||{});let o=e.disableHistoryExtension?n.filter(s=>s.name!=="history"):n;const r={...ot,...e,extensions:e.enableBlockNoteExtensions===!1?e.extensions:[...e.extensions||[],...o],editorProps:{attributes:{...((a=e.editorProps)==null?void 0:a.attributes)||{},class:[_.bnEditor,_.bnRoot,((i=(d=e.editorProps)==null?void 0:d.attributes)==null?void 0:i.class)||""].join(" ")}}};this.tiptapEditor=new u.Editor(r)}}m.BlockNoteEditor=rt,m.SlashMenuGroups=x,m.SlashMenuItem=E,m.getBlockNoteExtensions=K,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(k,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@tiptap/core"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-model"),require("prosemirror-state"),require("prosemirror-view"),require("@tiptap/extension-link"),require("uuid")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-model","prosemirror-state","prosemirror-view","@tiptap/extension-link","uuid"],c):(k=typeof globalThis<"u"?globalThis:k||self,c(k.blocknote={},k.core,k.Bold,k.Code,k.DropCursor,k.GapCursor,k.HardBreak,k.extensionHistory,k.Italic,k.Strike,k.Text,k.Underline,k.prosemirrorModel,k.prosemirrorState,k.pv,k.extensionLink,k.uuid))})(this,function(k,c,I,G,K,j,V,W,Y,J,Q,X,T,g,x,R,Z){"use strict";var nt=Object.defineProperty;var rt=(k,c,I)=>c in k?nt(k,c,{enumerable:!0,configurable:!0,writable:!0,value:I}):k[c]=I;var p=(k,c,I)=>(rt(k,typeof c!="symbol"?c+"":c,I),I);const M=t=>t&&typeof t=="object"&&"default"in t?t:{default:t};function ee(t){if(t&&t.__esModule)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const n=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,n.get?n:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const te=M(I),oe=M(G),ne=M(K),re=M(j),ie=M(V),se=M(Y),ae=M(J),de=M(Q),le=M(X),ce=ee(x);function b(t,e){if(e<=0||e>t.nodeSize)return;const o=t.resolve(e),n=o.depth;let r=o.node(n),a=n;for(;a>=0;){if(a===0)return;if(r.type.name==="blockContainer")break;a-=1,r=o.node(a)}const d=r.attrs.id,s=r.firstChild,i=s.type,l=r.childCount===2?r.lastChild.childCount:0,h=o.start(a),u=o.end(a);return{id:d,node:r,contentNode:s,contentType:i,numChildBlocks:l,startPos:h,endPos:u,depth:a}}const D=new g.PluginKey("previous-blocks"),ue={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},he=()=>new g.Plugin({key:D,view(t){return{update:async(e,o)=>{var n;((n=this.key)==null?void 0:n.getState(e.state).updatedBlocks.size)>0&&setTimeout(()=>{e.dispatch(e.state.tr.setMeta(D,{clearUpdate:!0}))},0)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,n){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(n.doc))return e;const r={},a=c.findChildren(o.doc,i=>i.attrs.id),d=new Map(a.map(i=>[i.node.attrs.id,i])),s=c.findChildren(n.doc,i=>i.attrs.id);for(let i of s){const l=d.get(i.node.attrs.id),h=l==null?void 0:l.node.firstChild,u=i.node.firstChild;if(l&&h&&u){const f={index:u.attrs.index,level:u.attrs.level,type:u.type.name,depth:n.doc.resolve(i.pos).depth};let m={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(l.pos).depth};r[i.node.attrs.id]=m,t.getMeta("numberedListIndexing")&&(i.node.attrs.id in e.prevTransactionOldBlockAttrs&&(m=e.prevTransactionOldBlockAttrs[i.node.attrs.id]),f.type==="numberedListItem"&&(m.index=f.index)),e.currentTransactionOldBlockAttrs[i.node.attrs.id]=m,JSON.stringify(m)!==JSON.stringify(f)&&(m["depth-change"]=m.depth-f.depth,e.updatedBlocks.add(i.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((n,r)=>{if(!n.attrs.id||!e.updatedBlocks.has(n.attrs.id))return;const a=e.currentTransactionOldBlockAttrs[n.attrs.id],d={};for(let[i,l]of Object.entries(a))d["data-prev-"+ue[i]]=l||"none";const s=x.Decoration.node(r,r+n.nodeSize,{...d});o.push(s)}),x.DecorationSet.create(t.doc,o)}}}),B={blockOuter:"_blockOuter_1ltqa_5",block:"_block_1ltqa_5",blockContent:"_blockContent_1ltqa_19",blockGroup:"_blockGroup_1ltqa_47",isEmpty:"_isEmpty_1ltqa_232",isFilter:"_isFilter_1ltqa_233",hasAnchor:"_hasAnchor_1ltqa_246"},pe={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},fe=c.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:t=>{if(typeof t=="string")return!1;const e={};for(let[o,n]of Object.entries(pe))t.getAttribute(n)&&(e[o]=t.getAttribute(n));return t.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:t}){return["div",c.mergeAttributes(t,{class:B.blockOuter,"data-node-type":"block-outer"}),["div",c.mergeAttributes(t,{class:B.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:t=>({state:e,dispatch:o})=>{const n=e.schema.nodes.blockContainer.createAndFill();return o&&e.tr.insert(t,n),!0},BNDeleteBlock:t=>({state:e,view:o,dispatch:n})=>{const r=b(e.doc,t);if(r===void 0)return!1;const{startPos:a,endPos:d}=r;return n&&(e.tr.deleteRange(a,d),e.tr.setSelection(new g.TextSelection(e.doc.resolve(a+1))),o.focus()),!0},BNMergeBlocks:t=>({state:e,dispatch:o})=>{const n=e.doc.resolve(t+1).node().type.name==="blockContainer",r=e.doc.resolve(t-1).node().type.name==="blockContainer";if(!n||!r)return!1;const a=b(e.doc,t+1),{node:d,contentNode:s,startPos:i,endPos:l,depth:h}=a;if(d.childCount===2){const m=e.doc.resolve(i+s.nodeSize+1),y=e.doc.resolve(l-1),C=m.blockRange(y);o&&e.tr.lift(C,h-1)}let u=t-1,f=b(e.doc,u);for(;f.numChildBlocks>0;)if(u--,f=b(e.doc,u),f===void 0)return!1;return o&&(e.tr.deleteRange(i,i+s.nodeSize),e.tr.insertText(s.textContent,u-1),e.tr.setSelection(new g.TextSelection(e.doc.resolve(u-1)))),!0},BNSplitBlock:(t,e)=>({state:o,dispatch:n})=>{const r=b(o.doc,t);if(r===void 0)return!1;const{contentNode:a,contentType:d,startPos:s,endPos:i,depth:l}=r,h=o.doc.cut(s+1,t),u=o.doc.cut(t,i-1),f=o.schema.nodes.blockContainer.createAndFill(),m=i+1,y=m+2;return n&&(o.tr.insert(m,f),o.tr.replace(y,y+1,u.content.size>0?new T.Slice(T.Fragment.from(u),l+2,l+2):void 0),e&&o.tr.setBlockType(y,y,o.schema.node(d).type,a.attrs),o.tr.setSelection(new g.TextSelection(o.doc.resolve(y))),o.tr.replace(s+1,i-1,h.content.size>0?new T.Slice(T.Fragment.from(h),l+2,l+2):void 0)),!0},BNUpdateBlock:(t,e)=>({state:o,dispatch:n})=>{const r=b(o.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,contentNode:s}=r;return n&&o.tr.setBlockType(d+1,d+s.nodeSize+1,o.schema.node(e.type).type,{...a.attrs,...e.props}),!0},BNCreateOrUpdateBlock:(t,e)=>({state:o,chain:n})=>{const r=b(o.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,endPos:s}=r;if(a.textContent.length===0){const i=d+1;return n().BNUpdateBlock(t,e).setTextSelection(i).run()}else{const i=s+1,l=i+1;return n().BNCreateBlock(i).BNUpdateBlock(l,e).setTextSelection(l).run()}}}},addProseMirrorPlugins(){return[he()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:n})=>{const{contentType:r}=b(n.doc,n.selection.from),a=n.selection.$anchor.parentOffset===0,d=r.name==="paragraph";return a&&!d?o.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:n})=>n.selection.$anchor.parentOffset===0?o.liftListItem("blockContainer"):!1),()=>o.command(({state:n})=>{const{depth:r,startPos:a}=b(n.doc,n.selection.from),d=n.selection.$anchor.parentOffset===0,s=n.selection.anchor===n.selection.head,i=a===2,l=a-1;return!i&&d&&s&&r===2?o.BNMergeBlocks(l):!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:n})=>{const{node:r,depth:a}=b(n.doc,n.selection.from),d=n.selection.$anchor.parentOffset===0,s=n.selection.anchor===n.selection.head,i=r.textContent.length===0,l=a>2;return d&&s&&i&&l?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:n,chain:r})=>{const{node:a,endPos:d}=b(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,i=n.selection.anchor===n.selection.head,l=a.textContent.length===0;if(s&&i&&l){const h=d+1,u=h+2;return r().BNCreateBlock(h).setTextSelection(u).run(),!0}return!1}),()=>o.command(({state:n,chain:r})=>{const{node:a}=b(n.doc,n.selection.from);return a.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:{}})}}}),me=c.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:t=>typeof t=="string"?!1:t.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:t}){return["div",c.mergeAttributes(this.options.HTMLAttributes,t,{class:B.blockGroup,"data-node-type":"blockGroup"}),0]}}),ke=c.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",c.mergeAttributes(t,{class:B.blockContent,"data-content-type":this.name}),["p",0]]}}),ge=c.Node.create({name:"heading",group:"blockContent",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:t=>t.getAttribute("data-level"),renderHTML:t=>({"data-level":t.level})}}},addInputRules(){return[...["1","2","3"].map(t=>new c.InputRule({find:new RegExp(`^(#{${parseInt(t)}})\\s$`),handler:({state:e,chain:o,range:n})=>{o().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:t}}).deleteRange({from:n.from,to:n.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"blockContainer"},{tag:"h2",attrs:{level:"2"},node:"blockContainer"},{tag:"h3",attrs:{level:"3"},node:"blockContainer"}]},renderHTML({node:t,HTMLAttributes:e}){return["div",c.mergeAttributes(e,{class:B.blockContent,"data-content-type":this.name}),["h"+t.attrs.level,0]]}}),F=t=>{const{node:e,contentType:o}=b(t.state.doc,t.state.selection.from),n=t.state.selection.anchor===t.state.selection.head;return!o.name.endsWith("ListItem")||!n?!1:t.commands.first(({state:r,chain:a,commands:d})=>[()=>d.command(()=>e.textContent.length===0?d.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>d.command(()=>e.textContent.length>0?(a().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},be=c.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new c.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:t,chain:e,range:o})=>{e().BNUpdateBlock(t.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:o.from,to:o.to})}})]},addKeyboardShortcuts(){return{Enter:()=>F(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:e.tagName==="UL"?{}:!1},node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",c.mergeAttributes(t,{class:B.blockContent,"data-content-type":this.name}),["li",0]]}}),ye=new g.PluginKey("numbered-list-indexing"),ve=()=>new g.Plugin({key:ye,appendTransaction:(t,e,o)=>{const n=o.tr;n.setMeta("numberedListIndexing",!0);let r=!1;return o.doc.descendants((a,d)=>{if(a.type.name==="blockContainer"&&a.firstChild.type.name==="numberedListItem"){let s="1";const i=d===1,l=b(n.doc,d+1);if(l===void 0)return;if(!i){const f=b(n.doc,d-2);if(f===void 0)return;if(!(l.depth!==f.depth)){const y=f.contentNode;if(f.contentType.name==="numberedListItem"){const O=y.attrs.index;s=(parseInt(O)+1).toString()}}}l.contentNode.attrs.index!==s&&(r=!0,n.setNodeMarkup(d+1,void 0,{index:s}))}}),r?n:null}}),Ce=c.Node.create({name:"numberedListItem",group:"blockContent",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:t=>t.getAttribute("data-index"),renderHTML:t=>({"data-index":t.index})}}},addInputRules(){return[new c.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:t,chain:e,range:o})=>{e().BNUpdateBlock(t.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:o.from,to:o.to})}})]},addKeyboardShortcuts(){return{Enter:()=>F(this.editor)}},addProseMirrorPlugins(){return[ve()]},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:e.tagName==="OL"?{}:!1},node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",c.mergeAttributes(t,{class:B.blockContent,"data-content-type":this.name}),["li",0]]}}),Be=[ke,ge,be,Ce,fe,me,c.Node.create({name:"doc",topNode:!0,content:"blockGroup"})];class xe{constructor({editor:e,formattingToolbarFactory:o,view:n,shouldShow:r}){p(this,"editor");p(this,"view");p(this,"formattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"toolbarIsOpen",!1);p(this,"shouldShow",({view:e,state:o,from:n,to:r})=>{const{doc:a,selection:d}=o,{empty:s}=d,i=!a.textBetween(n,r).length&&c.isTextSelection(o.selection);return!(!e.hasFocus()||s||i)});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.editor.view))});p(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.editor.view))});p(this,"blurHandler",({event:e})=>{var o,n;if(this.preventHide){this.preventHide=!1;return}(e==null?void 0:e.relatedTarget)&&((n=(o=this.formattingToolbar.element)==null?void 0:o.parentNode)==null?void 0:n.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});this.editor=e,this.view=n,this.formattingToolbar=o(this.getStaticParams()),r&&(this.shouldShow=r),this.view.dom.addEventListener("mousedown",this.viewMousedownHandler),this.view.dom.addEventListener("mouseup",this.viewMouseupHandler),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler)}update(e,o){var f;const{state:n,composing:r}=e,{doc:a,selection:d}=n,s=o&&o.doc.eq(a)&&o.selection.eq(d);if(r||s)return;const{ranges:i}=d,l=Math.min(...i.map(m=>m.$from.pos)),h=Math.max(...i.map(m=>m.$to.pos)),u=(f=this.shouldShow)==null?void 0:f.call(this,{editor:this.editor,view:e,state:n,oldState:o,from:l,to:h});if(!this.toolbarIsOpen&&!this.preventShow&&(u||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!0),this.toolbarIsOpen=!0,this.formattingToolbar.element.addEventListener("mousedown",m=>m.preventDefault());return}if(this.toolbarIsOpen&&!this.preventShow&&(u||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!u||this.preventShow)){this.formattingToolbar.hide(),this.toolbarIsOpen=!1,this.formattingToolbar.element.removeEventListener("mousedown",m=>m.preventDefault());return}}destroy(){this.view.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.view.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler)}getSelectionBoundingBox(){const{state:e}=this.editor.view,{selection:o}=e,{ranges:n}=o,r=Math.min(...n.map(d=>d.$from.pos)),a=Math.max(...n.map(d=>d.$to.pos));if(c.isNodeSelection(o)){const d=this.editor.view.nodeDOM(r);if(d)return d.getBoundingClientRect()}return c.posToDOMRect(this.editor.view,r,a)}getStaticParams(){return{toggleBold:()=>{this.editor.view.focus(),this.editor.commands.toggleBold()},toggleItalic:()=>{this.editor.view.focus(),this.editor.commands.toggleItalic()},toggleUnderline:()=>{this.editor.view.focus(),this.editor.commands.toggleUnderline()},toggleStrike:()=>{this.editor.view.focus(),this.editor.commands.toggleStrike()},setHyperlink:(e,o)=>{if(e==="")return;let{from:n,to:r}=this.editor.state.selection;o||(o=this.editor.state.doc.textBetween(n,r));const a=this.editor.schema.mark("link",{href:e});this.editor.view.dispatch(this.editor.view.state.tr.insertText(o,n,r).addMark(n,n+o.length,a)),this.editor.view.focus()},setTextColor:e=>{this.editor.view.focus(),this.editor.commands.setTextColor(e)},setBackgroundColor:e=>{this.editor.view.focus(),this.editor.commands.setBackgroundColor(e)},setTextAlignment:e=>{this.editor.view.focus(),this.editor.commands.setTextAlignment(e)},increaseBlockIndent:()=>{this.editor.view.focus(),this.editor.commands.sinkListItem("blockContainer")},decreaseBlockIndent:()=>{this.editor.view.focus(),this.editor.commands.liftListItem("blockContainer")},updateBlock:e=>{this.editor.view.focus(),this.editor.commands.BNUpdateBlock(this.editor.state.selection.from,e)}}}getDynamicParams(){const e=b(this.editor.state.doc,this.editor.state.selection.from);return{boldIsActive:this.editor.isActive("bold"),italicIsActive:this.editor.isActive("italic"),underlineIsActive:this.editor.isActive("underline"),strikeIsActive:this.editor.isActive("strike"),hyperlinkIsActive:this.editor.isActive("link"),activeHyperlinkUrl:this.editor.getAttributes("link").href||"",activeHyperlinkText:this.editor.state.doc.textBetween(this.editor.state.selection.from,this.editor.state.selection.to),textColor:this.editor.getAttributes("textColor").color||"default",backgroundColor:this.editor.getAttributes("backgroundColor").color||"default",textAlignment:this.editor.getAttributes(e.contentType).textAlignment||"left",canIncreaseBlockIndent:this.editor.state.doc.resolve(e.startPos).index(e.depth-1)>0,canDecreaseBlockIndent:e.depth>2,block:{type:e.contentType.name,props:e.contentNode.attrs},referenceRect:this.getSelectionBoundingBox()}}}const Me=t=>new g.Plugin({key:new g.PluginKey("FormattingToolbarPlugin"),view:e=>new xe({view:e,...t})}),Te=c.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory)throw new Error("UI Element factory not defined for FormattingToolbarExtension");return[Me({editor:this.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new g.PluginKey("FormattingToolbarPlugin")})]}}),N={bnEditor:"_bnEditor_xixap_3",bnRoot:"_bnRoot_xixap_13",dragPreview:"_dragPreview_xixap_27"},we=c.findParentNode(t=>t.type.name==="blockContainer");function S(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}class Ie{constructor({editor:e,pluginKey:o,onSelectItem:n=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");this.editor=e,this.pluginKey=o,this.pluginState=S(),this.itemCallback=a=>n({item:a,editor:e,range:{from:this.pluginState.queryStartPos-this.pluginState.triggerCharacter.length,to:e.state.selection.from}}),this.suggestionsMenu=r(this.getStaticParams())}update(e,o){const n=this.pluginKey.getState(o),r=this.pluginKey.getState(e.state),a=!n.active&&r.active,d=n.active&&!r.active,s=n.active&&r.active;!a&&!s&&!d||(this.pluginState=d?n:r,d&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",i=>i.preventDefault())),s&&this.suggestionsMenu.render(this.getDynamicParams(),!1),a&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",i=>i.preventDefault())))}getStaticParams(){return{itemCallback:e=>this.itemCallback(e)}}getDynamicParams(){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);return{items:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex,referenceRect:e.getBoundingClientRect()}}}function Pe({pluginKey:t,editor:e,defaultTriggerCharacter:o,suggestionsMenuFactory:n,onSelectItem:r=()=>{},items:a=()=>[]}){if(o.length!==1)throw new Error("'char' should be a single character");const d=s=>{s.dispatch(s.state.tr.setMeta(t,{deactivate:!0}))};return new g.Plugin({key:t,view:s=>new Ie({editor:e,pluginKey:t,onSelectItem:i=>{d(s),r(i)},suggestionsMenuFactory:n}),state:{init(){return S()},apply(s,i,l,h){var f,m,y,C;if(s.getMeta("orderedListIndexing")!==void 0)return i;if((f=s.getMeta(t))!=null&&f.activate)return{active:!0,triggerCharacter:((m=s.getMeta(t))==null?void 0:m.triggerCharacter)||"",queryStartPos:h.selection.from,items:a(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!i.active)return i;const u={...i};if(u.items=a(h.doc.textBetween(i.queryStartPos,h.selection.from)),u.notFoundCount=0,u.items.length===0&&(u.notFoundCount=Math.max(0,i.notFoundCount+(h.selection.from-l.selection.from))),h.selection.from!==h.selection.to||((y=s.getMeta(t))==null?void 0:y.deactivate)||s.getMeta("focus")||s.getMeta("blur")||s.getMeta("pointer")||i.active&&h.selection.from<i.queryStartPos||u.notFoundCount>3)return S();if(((C=s.getMeta(t))==null?void 0:C.selectedItemIndexChanged)!==void 0){let v=s.getMeta(t).selectedItemIndexChanged;v<0?v=i.items.length-1:v>=i.items.length&&(v=0),u.keyboardHoveredItemIndex=v}return u}},props:{handleKeyDown(s,i){const l=this.getState(s.state).active;if(i.key===o&&!l)return s.dispatch(s.state.tr.insertText(o).scrollIntoView().setMeta(t,{activate:!0,triggerCharacter:o})),!0;if(!l)return!1;const{triggerCharacter:h,queryStartPos:u,items:f,keyboardHoveredItemIndex:m}=t.getState(s.state);return i.key==="ArrowUp"?(s.dispatch(s.state.tr.setMeta(t,{selectedItemIndexChanged:m-1})),!0):i.key==="ArrowDown"?(s.dispatch(s.state.tr.setMeta(t,{selectedItemIndexChanged:m+1})),!0):i.key==="Enter"?(d(s),r({item:f[m],editor:e,range:{from:u-h.length,to:s.state.selection.from}}),!0):i.key==="Escape"?(d(s),!0):!1},handleClick(s){d(s)},decorations(s){const{active:i,decorationId:l,queryStartPos:h,triggerCharacter:u}=this.getState(s);if(!i)return null;if(u===""){const f=we(s.selection);if(f)return x.DecorationSet.create(s.doc,[x.Decoration.node(f.pos,f.pos+f.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}return x.DecorationSet.create(s.doc,[x.Decoration.inline(h-u.length,h,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}}})}class P{constructor(e,o,n=[]){this.name=e,this.execute=o,this.aliases=n}match(e){return this.name.toLowerCase().startsWith(e.toLowerCase())||this.aliases.filter(o=>o.toLowerCase().startsWith(e.toLowerCase())).length!==0}}const Ae={heading:new P("Heading",(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"1"}}).run(),["h","heading1","h1"]),heading2:new P("Heading 2",(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"2"}}).run(),["h2","heading2","subheading"]),heading3:new P("Heading 3",(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"3"}}).run(),["h3","heading3","subheading"]),numberedList:new P("Numbered List",(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"numberedListItem",props:{}}).run(),["li","list","numberedlist","numbered list"]),bulletList:new P("Bullet List",(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"bulletListItem",props:{}}).run(),["ul","list","bulletlist","bullet list"]),paragraph:new P("Paragraph",(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"paragraph",props:{}}).run(),["p"])},L=new g.PluginKey("suggestions-slash-commands"),Ee=c.Extension.create({name:"slash-command",addOptions(){return{commands:Ae,slashMenuFactory:void 0}},addProseMirrorPlugins(){if(!this.options.slashMenuFactory)throw new Error("UI Element factory not defined for SlashMenuExtension");return[Pe({pluginKey:L,editor:this.editor,defaultTriggerCharacter:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:t=>{const e=[];for(const o in this.options.commands)e.push(this.options.commands[o]);return e.filter(o=>o.match(t))},onSelectItem:({item:t,editor:e,range:o})=>{t.execute(e,o)}})]}});class E extends g.Selection{constructor(o,n){super(o,n);p(this,"nodes");const r=o.node();this.nodes=[],o.doc.nodesBetween(o.pos,n.pos,(a,d,s)=>{if(s!==null&&s.eq(r))return this.nodes.push(a),!1})}static create(o,n,r=n){return new E(o.resolve(n),o.resolve(r))}content(){return new T.Slice(T.Fragment.from(this.nodes),0,0)}eq(o){if(!(o instanceof E)||this.nodes.length!==o.nodes.length||this.from!==o.from||this.to!==o.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(o.nodes[n]))return!1;return!0}map(o,n){let r=n.mapResult(this.from),a=n.mapResult(this.to);return a.deleted?g.Selection.near(o.resolve(r.pos)):r.deleted?g.Selection.near(o.resolve(a.pos)):new E(o.resolve(r.pos),o.resolve(a.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const He=ce.__serializeForClipboard;let A;function U(t,e){var r;let o=e.posAtCoords(t);if(!o)return;let n=e.domAtPos(o.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 Ne(t,e){let o=U(t,e);if(o&&o.node.nodeType===1){const n=e.docView;let r=n.nearestDesc(o.node,!0);return!r||r===n?null:r.posBefore}return null}function Se(t,e){let o,n;const r=e.resolve(t.from).node().type.spec.group==="blockContent",a=e.resolve(t.to).node().type.spec.group==="blockContent",d=Math.min(t.$anchor.depth,t.$head.depth);if(r&&a){const s=t.$from.start(d-1),i=t.$to.end(d-1);o=e.resolve(s-1).pos,n=e.resolve(i+1).pos}else o=t.from,n=t.to;return{from:o,to:n}}function q(t,e,o=e){e===o&&(o+=t.state.doc.resolve(e+1).node().nodeSize);const n=t.domAtPos(e).node.cloneNode(!0),r=t.domAtPos(e).node,a=(i,l)=>Array.prototype.indexOf.call(i.children,l),d=a(r,t.domAtPos(e+1).node.parentElement),s=a(r,t.domAtPos(o-1).node.parentElement);for(let i=r.childElementCount-1;i>=0;i--)(i>s||i<d)&&n.removeChild(n.children[i]);A=n,A.className=N.dragPreview,document.body.appendChild(A)}function Le(){A!==void 0&&(document.body.removeChild(A),A=void 0)}function Oe(t,e){if(!t.dataTransfer)return;const o=e.dom.getBoundingClientRect();let n={left:o.left+o.width/2,top:t.clientY},r=Ne(n,e);if(r!=null){const a=e.state.selection,d=e.state.doc,{from:s,to:i}=Se(a,d),l=s<=r&&r<i,h=!a.$anchor.node().eq(a.$head.node());l&&h?(e.dispatch(e.state.tr.setSelection(E.create(d,s,i))),q(e,s,i)):(e.dispatch(e.state.tr.setSelection(g.NodeSelection.create(e.state.doc,r))),q(e,r));let u=e.state.selection.content(),{dom:f,text:m}=He(e,u);t.dataTransfer.clearData(),t.dataTransfer.setData("text/html",f.innerHTML),t.dataTransfer.setData("text/plain",m),t.dataTransfer.effectAllowed="move",t.dataTransfer.setDragImage(A,0,0),e.dragging={slice:u,move:!0}}}class _e{constructor({editor:e,blockMenuFactory:o,horizontalPosAnchoredAtRoot:n}){p(this,"editor");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"blockMenu");p(this,"hoveredBlockContent");p(this,"menuOpen",!1);p(this,"menuFrozen",!1);this.editor=e,this.horizontalPosAnchoredAtRoot=n,this.horizontalPosAnchor=e.view.dom.firstChild.getBoundingClientRect().x,this.blockMenu=o(this.getStaticParams()),document.body.addEventListener("mousemove",r=>{var l,h;if(this.menuFrozen)return;const a=this.editor.view.dom.firstChild.getBoundingClientRect();this.horizontalPosAnchor=a.x;const d={left:a.left+a.width/2,top:r.clientY},s=U(d,this.editor.view);if(!s){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}if(this.menuOpen&&((l=this.hoveredBlockContent)==null?void 0:l.hasAttribute("data-id"))&&((h=this.hoveredBlockContent)==null?void 0:h.getAttribute("data-id"))===s.id)return;const i=s.node.firstChild;this.hoveredBlockContent=i,i&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))},!0),document.body.addEventListener("mousedown",r=>{var a;(a=this.blockMenu.element)!=null&&a.contains(r.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)},!0),document.body.addEventListener("keydown",()=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1},!0)}destroy(){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide())}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const e=this.hoveredBlockContent.getBoundingClientRect(),o=this.editor.view.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const n=b(this.editor.state.doc,o.pos);if(n===void 0)return;const{contentNode:r,endPos:a}=n;if(r.textContent.length!==0){const d=a+1,s=d+2;this.editor.chain().BNCreateBlock(d).BNUpdateBlock(s,{type:"paragraph",props:{}}).setTextSelection(s).run()}else this.editor.commands.setTextSelection(a);this.editor.view.focus(),this.editor.view.dispatch(this.editor.view.state.tr.scrollIntoView().setMeta(L,{activate:!0,type:"drag"}))}deleteBlock(){this.menuOpen=!1,this.blockMenu.hide();const e=this.hoveredBlockContent.getBoundingClientRect(),o=this.editor.view.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});!o||this.editor.commands.BNDeleteBlock(o.pos)}setBlockBackgroundColor(e){this.menuOpen=!1,this.blockMenu.hide();const o=this.hoveredBlockContent.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:o.left+o.width/2,top:o.top+o.height/2});!n||this.editor.commands.setBlockBackgroundColor(n.pos,e)}setBlockTextColor(e){this.menuOpen=!1,this.blockMenu.hide();const o=this.hoveredBlockContent.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:o.left+o.width/2,top:o.top+o.height/2});!n||this.editor.commands.setBlockTextColor(n.pos,e)}getStaticParams(){return{addBlock:()=>this.addBlock(),deleteBlock:()=>this.deleteBlock(),blockDragStart:e=>Oe(e,this.editor.view),blockDragEnd:()=>Le(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1},setBlockBackgroundColor:e=>this.setBlockBackgroundColor(e),setBlockTextColor:e=>this.setBlockTextColor(e)}}getDynamicParams(){const e=this.hoveredBlockContent.getBoundingClientRect();return{blockBackgroundColor:this.editor.getAttributes("blockContainer").backgroundColor,blockTextColor:this.editor.getAttributes("blockContainer").textColor,referenceRect:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:e.x,e.y,e.width,e.height)}}}const Re=t=>new g.Plugin({key:new g.PluginKey("DraggableBlocksPlugin"),view:()=>new _e({editor:t.editor,blockMenuFactory:t.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),De=c.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[Re({editor:this.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}}),Fe=new g.PluginKey("HyperlinkToolbarPlugin");class Ue{constructor({editor:e,hyperlinkToolbarFactory:o}){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");this.editor=e,this.hyperlinkToolbar=o(this.getStaticParams()),this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),e.view.dom.addEventListener("mouseover",n=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),n.target instanceof HTMLAnchorElement&&n.target.nodeName==="A"){const r=n.target,a=e.view.posAtDOM(r,0)+1,d=e.state.doc.resolve(a),s=d.marks();for(const i of s)if(i.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=i,this.mouseHoveredHyperlinkMarkRange=c.getMarkRange(d,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1})}update(){var o,n,r,a;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 d=this.editor.state.selection.$from.marks();for(const s of d)if(s.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=s,this.keyboardHoveredHyperlinkMarkRange=c.getMarkRange(this.editor.state.selection.$from,s.type,s.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){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseleave",this.startMenuUpdateTimer),(n=this.hyperlinkToolbar.element)==null||n.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1);return}if(!this.hyperlinkMark&&e){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(a=this.hyperlinkToolbar.element)==null||a.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}getStaticParams(){return{editHyperlink:(e,o)=>{const n=this.editor.view.state.tr.insertText(o,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);n.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+o.length,this.editor.schema.mark("link",{href:e})),this.editor.view.dispatch(n),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()}}}getDynamicParams(){return{url:this.hyperlinkMark.attrs.href,text:this.editor.view.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),referenceRect:c.posToDOMRect(this.editor.view,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)}}}const qe=(t,e)=>new g.Plugin({key:Fe,view:()=>new Ue({editor:t,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),ze=R.Link.extend({priority:500,addProseMirrorPlugins(){var t;if(!this.options.hyperlinkToolbarFactory)throw new Error("UI Element factory not defined for HyperlinkMark");return[...((t=this.parent)==null?void 0:t.call(this))||[],qe(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),$e=new g.PluginKey("blocknote-placeholder"),Ge=c.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new g.Plugin({key:$e,props:{decorations:t=>{const{doc:e,selection:o}=t,n=L.getState(t),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:a}=o,d=[];if(!!r)return e.descendants((s,i)=>{const l=a>=i&&a<=i+s.nodeSize,h=!s.isLeaf&&!s.childCount;if((l||!this.options.showOnlyCurrent)&&h){const u=[this.options.emptyNodeClass];this.editor.isEmpty&&u.push(this.options.emptyEditorClass),l&&u.push(this.options.hasAnchorClass),(n==null?void 0:n.triggerCharacter)===""&&(n==null?void 0:n.active)&&u.push(this.options.isFilterClass);const f=x.Decoration.node(i,i+s.nodeSize,{class:u.join(" ")});d.push(f)}return this.options.includeChildren}),x.DecorationSet.create(e,d)}}})]}}),Ke=c.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const t=new g.PluginKey(this.name);return[new g.Plugin({key:t,appendTransaction:(e,o,n)=>{const{doc:r,tr:a,schema:d}=n,s=t.getState(n),i=r.content.size-2,l=d.nodes.blockContainer,h=d.nodes.paragraph;if(!!s)return a.insert(i,l.create(void 0,h.create()))},state:{init:(e,o)=>{},apply:(e,o)=>{if(!e.docChanged)return o;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}}})]}});function je(t,e=JSON.stringify){const o={};return t.filter(n=>{const r=e(n);return Object.prototype.hasOwnProperty.call(o,r)?!1:o[r]=!0})}function Ve(t){const e=t.filter((n,r)=>t.indexOf(n)!==r);return je(e)}const We=c.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++,parseInt(window.__TEST_OPTIONS.mockID)):Z.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:t=>t.getAttribute(`data-${this.options.attributeName}`),renderHTML:t=>({[`data-${this.options.attributeName}`]:t[this.options.attributeName]})}}}]},onCreate(){if(this.editor.extensionManager.extensions.find(i=>i.name==="collaboration"))return;const{view:t,state:e}=this.editor,{tr:o,doc:n}=e,{types:r,attributeName:a,generateID:d}=this.options;c.findChildren(n,i=>r.includes(i.type.name)&&i.attrs[a]===null).forEach(({node:i,pos:l})=>{o.setNodeMarkup(l,void 0,{...i.attrs,[a]:d()})}),o.setMeta("addToHistory",!1),t.dispatch(o)},addProseMirrorPlugins(){let t=null,e=!1;return[new g.Plugin({key:new g.PluginKey("uniqueID"),appendTransaction:(o,n,r)=>{console.log("appendTransaction");const a=o.some(y=>y.docChanged)&&!n.doc.eq(r.doc),d=this.options.filterTransaction&&o.some(y=>{var C,v;return!(!((v=(C=this.options).filterTransaction)===null||v===void 0)&&v.call(C,y))});if(!a||d)return;const{tr:s}=r,{types:i,attributeName:l,generateID:h}=this.options,u=c.combineTransactionSteps(n.doc,o),{mapping:f}=u;if(c.getChangedRanges(u).forEach(({newRange:y})=>{const C=c.findChildrenInRange(r.doc,y,w=>i.includes(w.type.name)),v=C.map(({node:w})=>w.attrs[l]).filter(w=>w!==null),O=Ve(v);C.forEach(({node:w,pos:H})=>{var _;const $=(_=s.doc.nodeAt(H))===null||_===void 0?void 0:_.attrs[l];if($===null){s.setNodeMarkup(H,void 0,{...w.attrs,[l]:h()});return}const{deleted:ot}=f.invert().mapResult(H);ot&&O.includes($)&&s.setNodeMarkup(H,void 0,{...w.attrs,[l]:h()})})}),!!s.steps.length)return s},view(o){const n=r=>{var a;t=!((a=o.dom.parentElement)===null||a===void 0)&&a.contains(r.target)?o.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(o,n)=>{var r;return(t!==o.dom.parentElement||((r=n.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(t=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:o=>{if(!e)return o;const{types:n,attributeName:r}=this.options,a=d=>{const s=[];return d.forEach(i=>{if(i.isText){s.push(i);return}if(!n.includes(i.type.name)){s.push(i.copy(a(i.content)));return}const l=i.type.create({...i.attrs,[r]:null},a(i.content),i.marks);s.push(l)}),T.Fragment.from(s)};return e=!1,new T.Slice(a(o.content),o.openStart,o.openEnd)}}})]}}),Ye=c.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:t=>t.getAttribute("data-background-color"),renderHTML:t=>({"data-background-color":t.color})}}},parseHTML(){return[{tag:"span",getAttrs:t=>typeof t=="string"?!1:t.hasAttribute("data-background-color")?{color:t.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:t}){return["span",t,0]},addCommands(){return{setBackgroundColor:t=>({commands:e})=>t!=="default"?e.setMark(this.name,{color:t}):e.unsetMark(this.name)}}}),Je=c.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:t=>t.getAttribute("data-text-color"),renderHTML:t=>({"data-text-color":t.color})}}},parseHTML(){return[{tag:"span",getAttrs:t=>typeof t=="string"?!1:t.hasAttribute("data-text-color")?{color:t.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:t}){return["span",t,0]},addCommands(){return{setTextColor:t=>({commands:e})=>t!=="default"?e.setMark(this.name,{color:t}):e.unsetMark(this.name)}}}),Qe=c.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:"default",parseHTML:t=>t.hasAttribute("data-background-color")?t.getAttribute("data-background-color"):"default",renderHTML:t=>t.backgroundColor!=="default"&&{"data-background-color":t.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(t,e)=>({state:o,view:n})=>{const r=b(o.doc,t);return r===void 0?!1:(o.tr.setNodeAttribute(r.startPos-1,"backgroundColor",e),n.focus(),!0)}}}}),Xe=c.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:"default",parseHTML:t=>t.hasAttribute("data-text-color")?t.getAttribute("data-text-color"):"default",renderHTML:t=>t.textColor!=="default"&&{"data-text-color":t.textColor}}}}]},addCommands(){return{setBlockTextColor:(t,e)=>({state:o,view:n})=>{const r=b(o.doc,t);return r===void 0?!1:(o.tr.setNodeAttribute(r.startPos-1,"textColor",e),n.focus(),!0)}}}}),Ze=c.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:t=>t.getAttribute("data-text-alignment"),renderHTML:t=>t.textAlignment!=="left"&&{"data-text-alignment":t.textAlignment}}}}]},addCommands(){return{setTextAlignment:t=>({state:e})=>{const o=[],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"?(o.push(r-1),r+=e.doc.resolve(r).node().nodeSize-1):r+=1;for(const a of o)e.tr.setNodeAttribute(a,"textAlignment",t);return!0}}}}),z=t=>{const e=[c.extensions.ClipboardTextSerializer,c.extensions.Commands,c.extensions.Editable,c.extensions.FocusEvents,c.extensions.Tabindex,re.default,Ge.configure({emptyNodeClass:B.isEmpty,hasAnchorClass:B.hasAnchor,isFilterClass:B.isFilter,includeChildren:!0,showOnlyCurrent:!1}),We.configure({types:["blockContainer"]}),ie.default,de.default,te.default,oe.default,se.default,ae.default,le.default,Je,Xe,Ye,Qe,Ze,...Be,ne.default.configure({width:5,color:"#ddeeff"}),W.History,Ke];return t.blockSideMenuFactory&&e.push(De.configure({blockSideMenuFactory:t.blockSideMenuFactory})),t.formattingToolbarFactory&&e.push(Te.configure({formattingToolbarFactory:t.formattingToolbarFactory})),t.hyperlinkToolbarFactory?e.push(ze.configure({hyperlinkToolbarFactory:t.hyperlinkToolbarFactory})):e.push(R.Link),t.slashMenuFactory&&e.push(Ee.configure({slashMenuFactory:t.slashMenuFactory})),e},et={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class tt{constructor(e={}){p(this,"tiptapEditor");var a,d,s;const o=z(e.uiFactories||{});let n=e.disableHistoryExtension?o.filter(i=>i.name!=="history"):o;const r={...et,...e,extensions:e.enableBlockNoteExtensions===!1?e.extensions:[...e.extensions||[],...n],editorProps:{attributes:{...((a=e.editorProps)==null?void 0:a.attributes)||{},class:[N.bnEditor,N.bnRoot,((s=(d=e.editorProps)==null?void 0:d.attributes)==null?void 0:s.class)||""].join(" ")}}};this.tiptapEditor=new c.Editor(r)}}k.BlockNoteEditor=tt,k.SlashMenuItem=P,k.getBlockNoteExtensions=z,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
2
  //# sourceMappingURL=blocknote.umd.cjs.map