@blocknote/core 0.5.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.js +1126 -1031
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +2 -2
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/BlockNoteEditor.ts +246 -4
- package/src/BlockNoteExtensions.ts +3 -2
- package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +35 -35
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +10 -10
- package/src/api/nodeConversions/nodeConversions.ts +11 -10
- package/src/editor.module.css +11 -2
- package/src/extensions/Blocks/api/inlineContentTypes.ts +3 -2
- package/src/extensions/Blocks/api/selectionTypes.ts +5 -0
- package/src/extensions/Blocks/nodes/Block.module.css +20 -2
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +5 -6
- package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +5 -2
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +76 -113
- package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +6 -3
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +2 -34
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +39 -113
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +56 -39
- package/src/extensions/UniqueID/UniqueID.ts +1 -1
- package/src/index.ts +1 -0
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +14 -2
- package/types/src/BlockNoteEditor.d.ts +81 -1
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +3 -2
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +4 -0
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -5
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +3 -1
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +14 -16
- package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +2 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -25
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +9 -4
- package/types/src/index.d.ts +1 -0
- package/types/src/api/Editor.d.ts +0 -93
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +0 -24
- package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +0 -5
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(f,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@tiptap/core"),require("prosemirror-model"),require("prosemirror-state"),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-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-model","prosemirror-state","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-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"],u):(f=typeof globalThis<"u"?globalThis:f||self,u(f.blocknote={},f.core,f.prosemirrorModel,f.prosemirrorState,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.extensionDropcursor,f.extensionGapcursor,f.extensionHardBreak,f.extensionHistory,f.extensionItalic,f.extensionLink,f.extensionStrike,f.extensionText,f.extensionUnderline,f.pv))})(this,function(f,u,v,y,
|
|
2
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function qe(n,e,t){Z(e,n[0],"before",t),ee(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 $e(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{let r=o.children.length,i;for(let a=0;a<r;a++){const d=o.children[a].children[0],l=d.children[0],c=d.children.length===2?d.children[1]:null,h=e.has(l.properties.dataContentType),k=h?n.orderedListItemBlockTypes.has(l.properties.dataContentType)?"ol":"ul":null;if(c!==null&&t(c),i&&i.tagName!==k){o.children.splice(a-i.children.length,i.children.length,i);const m=i.children.length-1;a-=m,r-=m,i=void 0}if(h){i||(i=$.fromDom(document.createElement(k)));const m=$.fromDom(document.createElement("li"));m.children.push(l.children[0]),c!==null&&m.children.push(...c.children),i.children.push(m)}else if(c!==null){o.children.splice(a+1,0,...c.children),o.children[a]=l.children[0];const m=c.children.length;a+=m,r+=m}else o.children[a]=l.children[0]}i&&o.children.splice(r-i.children.length,i.children.length,i)};return t}async function te(n,e){const t=document.createElement("div"),o=v.DOMSerializer.fromSchema(e);for(const i of n){const a=L(i,e),s=o.serializeNode(a);t.appendChild(s)}return(await O.unified().use(K.default,{fragment:!0}).use($e,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(Y.default).process(t.innerHTML)).value}async function ne(n,e){const t=document.createElement("div");t.innerHTML=n.trim();const r=v.DOMParser.fromSchema(e).parse(t),i=[];for(let a=0;a<r.firstChild.childCount;a++)i.push(I(r.firstChild.child(a)));return i}async function je(n,e){return(await O.unified().use(K.default,{fragment:!0}).use(Ge).use(Ae.default).use(W.default).use(Le.default).process(await te(n,e))).value}async function Ke(n,e){const t=await O.unified().use(Se.default).use(W.default).use(Ne.default).use(Y.default).process(n);return ne(t.value,e)}const Ye=u.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)}}}}),We=u.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)}}}),oe=new y.PluginKey("previous-blocks"),Ve={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Je=()=>{let n;return new y.Plugin({key:oe,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(oe,{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={},a=u.findChildren(o.doc,l=>l.attrs.id),s=new Map(a.map(l=>[l.node.attrs.id,l])),d=u.findChildren(r.doc,l=>l.attrs.id);for(let l of d){const c=s.get(l.node.attrs.id),h=c==null?void 0:c.node.firstChild,k=l.node.firstChild;if(c&&h&&k){const m={index:k.attrs.index,level:k.attrs.level,type:k.type.name,depth:r.doc.resolve(l.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(c.pos).depth};i[l.node.attrs.id]=g,e.getMeta("numberedListIndexing")&&(l.node.attrs.id in t.prevTransactionOldBlockAttrs&&(g=t.prevTransactionOldBlockAttrs[l.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),t.currentTransactionOldBlockAttrs[l.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,t.updatedBlocks.add(l.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 a=t.currentTransactionOldBlockAttrs[r.attrs.id],s={};for(let[l,c]of Object.entries(a))s["data-prev-"+Ve[l]]=c||"none";const d=T.Decoration.node(i,i+r.nodeSize,{...s});o.push(d)}),T.DecorationSet.create(e.doc,o)}}})},x={blockOuter:"_blockOuter_1xym9_5",blockContent:"_blockContent_1xym9_10",blockGroup:"_blockGroup_1xym9_26",block:"_block_1xym9_5",isEmpty:"_isEmpty_1xym9_215",isFilter:"_isFilter_1xym9_216",hasAnchor:"_hasAnchor_1xym9_229"},Xe={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Qe=u.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(Xe))n.getAttribute(o)&&(e[t]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:n}){return["div",u.mergeAttributes(n,{class:x.blockOuter,"data-node-type":"block-outer"}),["div",u.mergeAttributes(n,{class:x.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:a,node:s,contentNode:d}=r;if(o){if(e.children!==void 0){const l=[];for(const c of e.children)l.push(L(c,t.schema));s.childCount===2?t.tr.replace(i+d.nodeSize+1,a-1,new v.Slice(v.Fragment.from(l),0,0)):t.tr.insert(i+d.nodeSize,t.schema.nodes.blockGroup.create({},l))}if(e.content!==void 0){let l=[];typeof e.content=="string"?l.push(t.schema.text(e.content)):l=Q(e.content,t.schema),t.tr.replace(i+1,i+d.nodeSize-1,new v.Slice(v.Fragment.from(l),0,0))}t.tr.setNodeMarkup(i,e.type===void 0?void 0:t.schema.nodes[e.type],{...d.attrs,...e.props}),t.tr.setNodeMarkup(i-1,void 0,{...s.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:a,contentNode:s,startPos:d,endPos:l,depth:c}=i;if(a.childCount===2){const m=e.doc.resolve(d+s.nodeSize+1),g=e.doc.resolve(l-1),B=m.blockRange(g);t&&e.tr.lift(B,c-1)}let h=n-1,k=b(e.doc,h);for(;k.numChildBlocks>0;)if(h--,k=b(e.doc,h),k===void 0)return!1;return t&&(e.tr.deleteRange(d,d+s.nodeSize),e.tr.insertText(s.textContent,h-1),e.tr.setSelection(new y.TextSelection(e.doc.resolve(h-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:a,startPos:s,endPos:d,depth:l}=r,c=t.doc.cut(s+1,n),h=t.doc.cut(n,d-1),k=t.schema.nodes.blockContainer.createAndFill(),m=d+1,g=m+2;return o&&(t.tr.insert(m,k),t.tr.replace(g,g+1,h.content.size>0?new v.Slice(v.Fragment.from(h),l+2,l+2):void 0),e&&t.tr.setBlockType(g,g,t.schema.node(a).type,i.attrs),t.tr.setSelection(new y.TextSelection(t.doc.resolve(g))),t.tr.replace(s+1,d-1,c.content.size>0?new v.Slice(v.Fragment.from(c),l+2,l+2):void 0)),!0}}},addProseMirrorPlugins(){return[Je()]},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,a=r.name==="paragraph";return i&&!a?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),a=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,d=i===2,l=i-1;return!d&&a&&s&&r===2?t.BNMergeBlocks(l):!1})]),Enter:()=>this.editor.commands.first(({commands:t})=>[()=>t.command(({state:o})=>{const{node:r,depth:i}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,d=r.textContent.length===0,l=i>2;return a&&s&&d&&l?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:o,chain:r})=>{const{node:i,endPos:a}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,d=o.selection.anchor===o.selection.head,l=i.textContent.length===0;if(s&&d&&l){const c=a+1,h=c+2;return r().BNCreateBlock(c).setTextSelection(h).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:{}})}}}),Ze=u.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",u.mergeAttributes(this.options.HTMLAttributes,n,{class:x.blockGroup,"data-node-type":"blockGroup"}),0]}}),et=u.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){return["div",u.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),tt=u.Node.create({name:"heading",group:"blockContent",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 u.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",u.mergeAttributes(e,{class:x.blockContent,"data-content-type":this.name}),["h"+n.attrs.level,0]]}}),re=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:a})=>[()=>a.command(()=>e.textContent.length===0?a.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>a.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},nt=u.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new u.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:()=>re(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",u.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),ot=new y.PluginKey("numbered-list-indexing"),rt=()=>new y.Plugin({key:ot,appendTransaction:(n,e,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((i,a)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let s="1";const d=a===1,l=b(o.doc,a+1);if(l===void 0)return;if(!d){const k=b(o.doc,a-2);if(k===void 0)return;if(!(l.depth!==k.depth)){const g=k.contentNode;if(k.contentType.name==="numberedListItem"){const q=g.attrs.index;s=(parseInt(q)+1).toString()}}}l.contentNode.attrs.index!==s&&(r=!0,o.setNodeMarkup(a+1,void 0,{index:s}))}}),r?o:null}}),it=u.Node.create({name:"numberedListItem",group:"blockContent",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new u.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:()=>re(this.editor)}},addProseMirrorPlugins(){return[rt()]},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",u.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),st=[et,tt,nt,it,Qe,Ze,u.Node.create({name:"doc",topNode:!0,content:"blockGroup"})],H={bnEditor:"_bnEditor_ft05x_3",bnRoot:"_bnRoot_ft05x_19",defaultStyles:"_defaultStyles_ft05x_34",dragPreview:"_dragPreview_ft05x_57"},at=u.findParentNode(n=>n.type.name==="blockContainer");function z(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}class dt{constructor({editor:e,pluginKey:t,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");this.editor=e,this.pluginKey=t,this.pluginState=z(),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,a=o.active&&!r.active,s=o.active&&r.active;!i&&!s&&!a||(this.pluginState=a?o:r,a&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",d=>d.preventDefault())),s&&this.suggestionsMenu.render(this.getDynamicParams(),!1),i&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",d=>d.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 lt({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 a=s=>{s.dispatch(s.state.tr.setMeta(n,{deactivate:!0}))};return new y.Plugin({key:n,view:s=>new dt({editor:e,pluginKey:n,onSelectItem:d=>{a(s),r(d)},suggestionsMenuFactory:o}),state:{init(){return z()},apply(s,d,l,c){var k,m,g,B;if(s.getMeta("orderedListIndexing")!==void 0)return d;if((k=s.getMeta(n))!=null&&k.activate)return{active:!0,triggerCharacter:((m=s.getMeta(n))==null?void 0:m.triggerCharacter)||"",queryStartPos:c.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const h={...d};if(h.items=i(c.doc.textBetween(d.queryStartPos,c.selection.from)),h.notFoundCount=0,h.items.length===0&&(h.notFoundCount=Math.max(0,d.notFoundCount+(c.selection.from-l.selection.from))),c.selection.from!==c.selection.to||(g=s.getMeta(n))!=null&&g.deactivate||s.getMeta("focus")||s.getMeta("blur")||s.getMeta("pointer")||d.active&&c.selection.from<d.queryStartPos||h.notFoundCount>3)return z();if(((B=s.getMeta(n))==null?void 0:B.selectedItemIndexChanged)!==void 0){let C=s.getMeta(n).selectedItemIndexChanged;C<0?C=d.items.length-1:C>=d.items.length&&(C=0),h.keyboardHoveredItemIndex=C}return h}},props:{handleKeyDown(s,d){const l=this.getState(s.state).active;if(d.key===t&&!l)return s.dispatch(s.state.tr.insertText(t).scrollIntoView().setMeta(n,{activate:!0,triggerCharacter:t})),!0;if(!l)return!1;const{triggerCharacter:c,queryStartPos:h,items:k,keyboardHoveredItemIndex:m}=n.getState(s.state);return d.key==="ArrowUp"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m-1})),!0):d.key==="ArrowDown"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m+1})),!0):d.key==="Enter"?(a(s),e._tiptapEditor.chain().focus().deleteRange({from:h-c.length,to:e._tiptapEditor.state.selection.from}).run(),r({item:k[m],editor:e}),!0):d.key==="Escape"?(a(s),!0):!1},handleClick(s){a(s)},decorations(s){const{active:d,decorationId:l,queryStartPos:c,triggerCharacter:h}=this.getState(s);if(!d)return null;if(h===""){const k=at(s.selection);if(k)return T.DecorationSet.create(s.doc,[T.Decoration.node(k.pos,k.pos+k.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}return T.DecorationSet.create(s.doc,[T.Decoration.inline(c-h.length,c,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}}})}const U=new y.PluginKey("suggestions-slash-commands"),ct=u.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[lt({pluginKey:U,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 y.Selection{constructor(t,o){super(t,o);p(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(i,a,s)=>{if(s!==null&&s.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?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 ut=He.__serializeForClipboard;let w;function ie(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 ht(n,e){let t=ie(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 pt(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",a=Math.min(n.$anchor.depth,n.$head.depth);if(r&&i){const s=n.$from.start(a-1),d=n.$to.end(a-1);t=e.resolve(s-1).pos,o=e.resolve(d+1).pos}else t=n.from,o=n.to;return{from:t,to:o}}function se(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,h)=>Array.prototype.indexOf.call(c.children,h),a=i(r,n.domAtPos(e+1).node.parentElement),s=i(r,n.domAtPos(t-1).node.parentElement);for(let c=r.childElementCount-1;c>=0;c--)(c>s||c<a)&&o.removeChild(o.children[c]);ae(),w=o;const l=n.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");w.className=w.className+" "+H.dragPreview+" "+l,document.body.appendChild(w)}function ae(){w!==void 0&&(document.body.removeChild(w),w=void 0)}function ft(n,e){if(!n.dataTransfer)return;const t=e.dom.getBoundingClientRect();let o={left:t.left+t.width/2,top:n.clientY},r=ht(o,e);if(r!=null){const i=e.state.selection,a=e.state.doc,{from:s,to:d}=pt(i,a),l=s<=r&&r<d,c=!i.$anchor.node().eq(i.$head.node());l&&c?(e.dispatch(e.state.tr.setSelection(N.create(a,s,d))),se(e,s,d)):(e.dispatch(e.state.tr.setSelection(y.NodeSelection.create(e.state.doc,r))),se(e,r));let h=e.state.selection.content(),{dom:k,text:m}=ut(e,h);n.dataTransfer.clearData(),n.dataTransfer.setData("text/html",k.innerHTML),n.dataTransfer.setData("text/plain",m),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(w,0,0),e.dragging={slice:h,move:!0}}}class mt{constructor({editor:e,blockMenuFactory:t,horizontalPosAnchoredAtRoot:o}){p(this,"editor");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"blockMenu");p(this,"hoveredBlockContent");p(this,"menuOpen",!1);p(this,"menuFrozen",!1);p(this,"onDrop",e=>{if(e.synthetic)return;let t=this.editor.view.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const o=new Event("drop",e),r=this.editor.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.editor.view.dom.dispatchEvent(o)}});p(this,"onDragOver",e=>{if(e.synthetic)return;let t=this.editor.view.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const o=new Event("dragover",e),r=this.editor.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.editor.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 a,s;if(this.menuFrozen)return;const t=this.editor.view.dom.firstChild.getBoundingClientRect();this.horizontalPosAnchor=t.x;const o={left:t.left+t.width/2,top:e.clientY},r=ie(o,this.editor.view);if(!r){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}if(this.menuOpen&&((a=this.hoveredBlockContent)!=null&&a.hasAttribute("data-id"))&&((s=this.hoveredBlockContent)==null?void 0:s.getAttribute("data-id"))===r.id)return;const i=r.node.firstChild;this.hoveredBlockContent=i,i&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))});this.editor=e,this.horizontalPosAnchoredAtRoot=o,this.horizontalPosAnchor=e.view.dom.firstChild.getBoundingClientRect().x,this.blockMenu=t(this.getStaticParams()),document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),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),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 e=this.hoveredBlockContent.getBoundingClientRect(),t=this.editor.view.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!t)return;const o=b(this.editor.state.doc,t.pos);if(o===void 0)return;const{contentNode:r,endPos:i}=o;if(r.textContent.length!==0){const a=i+1,s=a+2;this.editor.chain().BNCreateBlock(a).BNUpdateBlock(s,{type:"paragraph",props:{}}).setTextSelection(s).run()}else this.editor.commands.setTextSelection(i);this.editor.view.focus(),this.editor.view.dispatch(this.editor.view.state.tr.scrollIntoView().setMeta(U,{activate:!0,type:"drag"}))}deleteBlock(){this.menuOpen=!1,this.blockMenu.hide();const e=this.hoveredBlockContent.getBoundingClientRect(),t=this.editor.view.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});t&&this.editor.commands.BNDeleteBlock(t.pos)}setBlockBackgroundColor(e){this.menuOpen=!1,this.blockMenu.hide();const t=this.hoveredBlockContent.getBoundingClientRect(),o=this.editor.view.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});o&&this.editor.commands.setBlockBackgroundColor(o.pos,e)}setBlockTextColor(e){this.menuOpen=!1,this.blockMenu.hide();const t=this.hoveredBlockContent.getBoundingClientRect(),o=this.editor.view.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});o&&this.editor.commands.setBlockTextColor(o.pos,e)}getStaticParams(){return{addBlock:()=>this.addBlock(),deleteBlock:()=>this.deleteBlock(),blockDragStart:e=>ft(e,this.editor.view),blockDragEnd:()=>ae(),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 kt=n=>new y.Plugin({key:new y.PluginKey("DraggableBlocksPlugin"),view:()=>new mt({editor:n.editor,blockMenuFactory:n.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),gt=u.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[kt({editor:this.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}});class yt{constructor({editor:e,formattingToolbarFactory:t,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:t,from:o,to:r})=>{const{doc:i,selection:a}=t,{empty:s}=a,d=!i.textBetween(o,r).length&&u.isTextSelection(t.selection);return!(!e.hasFocus()||s||d)});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 t,o;if(this.preventHide){this.preventHide=!1;return}e!=null&&e.relatedTarget&&((o=(t=this.formattingToolbar.element)==null?void 0:t.parentNode)!=null&&o.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});this.editor=e,this.view=o,this.formattingToolbar=t(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,t){var k;const{state:o,composing:r}=e,{doc:i,selection:a}=o,s=t&&t.doc.eq(i)&&t.selection.eq(a);if(r||s)return;const{ranges:d}=a,l=Math.min(...d.map(m=>m.$from.pos)),c=Math.max(...d.map(m=>m.$to.pos)),h=(k=this.shouldShow)==null?void 0:k.call(this,{editor:this.editor,view:e,state:o,oldState:t,from:l,to:c});if(!this.toolbarIsOpen&&!this.preventShow&&(h||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&&(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",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:t}=e,{ranges:o}=t,r=Math.min(...o.map(a=>a.$from.pos)),i=Math.max(...o.map(a=>a.$to.pos));if(u.isNodeSelection(t)){const a=this.editor.view.nodeDOM(r);if(a)return a.getBoundingClientRect()}return u.posToDOMRect(this.editor.view,r,i)}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,t)=>{if(e==="")return;let{from:o,to:r}=this.editor.state.selection;t||(t=this.editor.state.doc.textBetween(o,r));const i=this.editor.schema.mark("link",{href:e});this.editor.view.dispatch(this.editor.view.state.tr.insertText(t,o,r).addMark(o,o+t.length,i)),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 bt=n=>new y.Plugin({key:new y.PluginKey("FormattingToolbarPlugin"),view:e=>new yt({view:e,...n})}),vt=u.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory)throw new Error("UI Element factory not defined for FormattingToolbarExtension");return[bt({editor:this.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new y.PluginKey("FormattingToolbarPlugin")})]}}),Ct=new y.PluginKey("HyperlinkToolbarPlugin");class Bt{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");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),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,i=e.view.posAtDOM(r,0)+1,a=e.state.doc.resolve(i),s=a.marks();for(const d of s)if(d.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=d,this.mouseHoveredHyperlinkMarkRange=u.getMarkRange(a,d.type,d.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1})}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 a=this.editor.state.selection.$from.marks();for(const s of a)if(s.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=s,this.keyboardHoveredHyperlinkMarkRange=u.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),(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(!this.hyperlinkMark&&e){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(i=this.hyperlinkToolbar.element)==null||i.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}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()}}}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 xt=(n,e)=>new y.Plugin({key:Ct,view:()=>new Bt({editor:n,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),Tt=j.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))||[],xt(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),wt=new y.PluginKey("blocknote-placeholder"),Mt=u.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:wt,props:{decorations:n=>{const{doc:e,selection:t}=n,o=U.getState(n),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,a=[];if(r)return e.descendants((s,d)=>{const l=i>=d&&i<=d+s.nodeSize,c=!s.isLeaf&&!s.childCount;if((l||!this.options.showOnlyCurrent)&&c){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),l&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&h.push(this.options.isFilterClass);const k=T.Decoration.node(d,d+s.nodeSize,{class:h.join(" ")});a.push(k)}return this.options.includeChildren}),T.DecorationSet.create(e,a)}}})]}});class Et{constructor(e,t){this.name=e,this.match=t}}class P extends Et{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 A(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 de=[new P("Heading",n=>A(n,{type:"heading",props:{level:"1"}}),["h","heading1","h1"]),new P("Heading 2",n=>A(n,{type:"heading",props:{level:"2"}}),["h2","heading2","subheading"]),new P("Heading 3",n=>A(n,{type:"heading",props:{level:"3"}}),["h3","heading3","subheading"]),new P("Numbered List",n=>A(n,{type:"numberedListItem"}),["li","list","numberedlist","numbered list"]),new P("Bullet List",n=>A(n,{type:"bulletListItem"}),["ul","list","bulletlist","bullet list"]),new P("Paragraph",n=>A(n,{type:"paragraph"}),["p"])],It=u.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}}}}),Pt=u.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)}}}}),At=u.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)}}}),St=u.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new y.PluginKey(this.name);return[new y.Plugin({key:n,appendTransaction:(e,t,o)=>{const{doc:r,tr:i,schema:a}=o,s=n.getState(o),d=r.content.size-2,l=a.nodes.blockContainer,c=a.nodes.paragraph;if(s)return i.insert(d,l.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}}})]}}),le=n=>{const e=[u.extensions.ClipboardTextSerializer,u.extensions.Commands,u.extensions.Editable,u.extensions.FocusEvents,u.extensions.Tabindex,Be.Gapcursor,Mt.configure({emptyNodeClass:x.isEmpty,hasAnchorClass:x.hasAnchor,isFilterClass:x.isFilter,includeChildren:!0,showOnlyCurrent:!1}),F.configure({types:["blockContainer"]}),xe.HardBreak,Ee.Text,be.Bold,ve.Code,we.Italic,Me.Strike,Ie.Underline,At,Pt,We,Ye,It,...st,Ce.Dropcursor.configure({width:5,color:"#ddeeff"}),Te.History,St];return n.uiFactories.blockSideMenuFactory&&e.push(gt.configure({blockSideMenuFactory:n.uiFactories.blockSideMenuFactory})),n.uiFactories.formattingToolbarFactory&&e.push(vt.configure({formattingToolbarFactory:n.uiFactories.formattingToolbarFactory})),n.uiFactories.hyperlinkToolbarFactory?e.push(Tt.configure({hyperlinkToolbarFactory:n.uiFactories.hyperlinkToolbarFactory})):e.push(j.Link),n.uiFactories.slashMenuFactory&&e.push(ct.configure({editor:n.editor,commands:n.slashCommands,slashMenuFactory:n.uiFactories.slashMenuFactory})),e},Nt={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Lt{constructor(e={}){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);var i,a,s;e={defaultStyles:!0,...e};const t=le({editor:this,uiFactories:e.uiFactories||{},slashCommands:e.slashCommands||de});let o=e.disableHistoryExtension?t.filter(d=>d.name!=="history"):t;const r={...Nt,...e._tiptapOptions,onCreate:()=>{var d;(d=e.onEditorReady)==null||d.call(e,this),e.initialContent&&this.replaceBlocks(this.topLevelBlocks,e.initialContent)},onUpdate:()=>{var d;(d=e.onEditorContentChange)==null||d.call(e,this)},onSelectionUpdate:()=>{var d;(d=e.onTextCursorPositionChange)==null||d.call(e,this)},extensions:e.enableBlockNoteExtensions===!1?(i=e._tiptapOptions)==null?void 0:i.extensions:[...((a=e._tiptapOptions)==null?void 0:a.extensions)||[],...o],editorProps:{attributes:{...e.editorDOMAttributes||{},class:[H.bnEditor,H.bnRoot,e.defaultStyles?H.defaultStyles:"",((s=e.editorDOMAttributes)==null?void 0:s.class)||""].join(" ")}}};e.parentElement&&(r.element=e.parentElement),this._tiptapEditor=new u.Editor(r)}get domElement(){return this._tiptapEditor.view.dom}get topLevelBlocks(){const e=[];return this._tiptapEditor.state.doc.firstChild.descendants(t=>(e.push(I(t,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=I(r,this.blockCache),!1)),o}forEachBlock(e,t=!1){const o=this.topLevelBlocks.slice();t&&o.reverse();function r(i){for(const a of i){if(e(a)===!1)return!1;const s=t?a.children.slice().reverse():a.children;if(r(s)===!1)return!1}return!0}r(o)}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),a=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let s;i>0&&(s=this._tiptapEditor.state.doc.resolve(o-2).node());let d;return i<a-1&&(d=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:I(e,this.blockCache),prevBlock:s===void 0?void 0:I(s,this.blockCache),nextBlock:d===void 0?void 0:I(d,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:r}=R(o,this._tiptapEditor.state.doc),{startPos:i,contentNode:a}=b(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+a.nodeSize-1)}insertBlocks(e,t,o="before"){Z(e,t,o,this._tiptapEditor)}updateBlock(e,t){Ue(e,t,this._tiptapEditor)}removeBlocks(e){ee(e,this._tiptapEditor)}replaceBlocks(e,t){qe(e,t,this._tiptapEditor)}async blocksToHTML(e){return te(e,this._tiptapEditor.schema)}async HTMLToBlocks(e){return ne(e,this._tiptapEditor.schema)}async blocksToMarkdown(e){return je(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return Ke(e,this._tiptapEditor.schema)}}f.BaseSlashMenuItem=P,f.BlockNoteEditor=Lt,f.blockProps=D,f.defaultSlashMenuItems=de,f.getBlockNoteExtensions=le,f.globalProps=S,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(f,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@tiptap/core"),require("prosemirror-model"),require("prosemirror-state"),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-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-model","prosemirror-state","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-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"],u):(f=typeof globalThis<"u"?globalThis:f||self,u(f.blocknote={},f.core,f.prosemirrorModel,f.prosemirrorState,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.extensionDropcursor,f.extensionGapcursor,f.extensionHardBreak,f.extensionHistory,f.extensionItalic,f.extensionLink,f.extensionStrike,f.extensionText,f.extensionUnderline,f.pv))})(this,function(f,u,v,y,ut,ht,pt,ft,mt,gt,kt,yt,D,$,bt,vt,Et,Ct,Tt,Bt,Mt,j,xt,wt,St,B){"use strict";var He=Object.defineProperty;var De=(f,u,v)=>u in f?He(f,u,{enumerable:!0,configurable:!0,writable:!0,value:v}):f[u]=v;var h=(f,u,v)=>(De(f,typeof u!="symbol"?u+"":u,v),v);const S=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Pt(n){if(n&&typeof n=="object"&&"default"in n)return n;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const K=S(ht),It=S(pt),W=S(ft),Y=S(mt),Lt=S(gt),_t=S(kt),Nt=S(yt),At=Pt(B),_=["backgroundColor","textColor","textAlignment"],O={paragraph:new Set([..._]),heading:new Set([..._,"level"]),numberedListItem:new Set([..._]),bulletListItem:new Set([..._])};function b(n,t){if(t<0||t>n.nodeSize)return;const e=n.resolve(t),o=e.depth;let r=e.node(o),i=o;for(;;){if(i<0)return;if(r.type.name==="blockContainer")break;i-=1,r=e.node(i)}const a=r.attrs.id,s=r.firstChild,d=s.type,l=r.childCount===2?r.lastChild.childCount:0,c=e.start(i),p=e.end(i);return{id:a,node:r,contentNode:s,contentType:d,numChildBlocks:l,startPos:c,endPos:p,depth:i}}function Ht(n,t=JSON.stringify){const e={};return n.filter(o=>{const r=t(o);return Object.prototype.hasOwnProperty.call(e,r)?!1:e[r]=!0})}function Dt(n){const t=n.filter((o,r)=>n.indexOf(o)!==r);return Ht(t)}const F=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++,window.__TEST_OPTIONS.mockID.toString()):ut.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(d=>d.name==="collaboration"))return;const{view:n,state:t}=this.editor,{tr:e,doc:o}=t,{types:r,attributeName:i,generateID:a}=this.options;u.findChildren(o,d=>r.includes(d.type.name)&&d.attrs[i]===null).forEach(({node:d,pos:l})=>{e.setNodeMarkup(l,void 0,{...d.attrs,[i]:a()})}),e.setMeta("addToHistory",!1),n.dispatch(e)},addProseMirrorPlugins(){let n=null,t=!1;return[new y.Plugin({key:new y.PluginKey("uniqueID"),appendTransaction:(e,o,r)=>{const i=e.some(k=>k.docChanged)&&!o.doc.eq(r.doc),a=this.options.filterTransaction&&e.some(k=>{var C,E;return!(!((E=(C=this.options).filterTransaction)===null||E===void 0)&&E.call(C,k))});if(!i||a)return;const{tr:s}=r,{types:d,attributeName:l,generateID:c}=this.options,p=u.combineTransactionSteps(o.doc,e),{mapping:g}=p;if(u.getChangedRanges(p).forEach(({newRange:k})=>{const C=u.findChildrenInRange(r.doc,k,w=>d.includes(w.type.name)),E=C.map(({node:w})=>w.attrs[l]).filter(w=>w!==null),U=Dt(E);C.forEach(({node:w,pos:H})=>{var G;const ct=(G=s.doc.nodeAt(H))===null||G===void 0?void 0:G.attrs[l];if(ct===null){s.setNodeMarkup(H,void 0,{...w.attrs,[l]:c()});return}const{deleted:Ae}=g.invert().mapResult(H);Ae&&U.includes(ct)&&s.setNodeMarkup(H,void 0,{...w.attrs,[l]:c()})})}),!!s.steps.length)return s},view(e){const o=r=>{var i;n=!((i=e.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?e.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(e,o)=>{var r;return(n!==e.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(n=null,t=!0),!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:o,attributeName:r}=this.options,i=a=>{const s=[];return a.forEach(d=>{if(d.isText){s.push(d);return}if(!o.includes(d.type.name)){s.push(d.copy(i(d.content)));return}const l=d.type.create({...d.attrs,[r]:null},i(d.content),d.marks);s.push(l)}),v.Fragment.from(s)};return t=!1,new v.Slice(i(e.content),e.openStart,e.openEnd)}}})]}});class Ot extends Error{constructor(t){super(`Unreachable case: ${t}`)}}const V=new Set(["bold","italic","underline","strike","code"]),J=new Set(["textColor","backgroundColor"]);function Ft(n,t){const e=[];for(const[o,r]of Object.entries(n.styles))V.has(o)?e.push(t.mark(o)):J.has(o)&&e.push(t.mark(o,{color:r}));return t.text(n.text,e)}function Rt(n,t){const e=t.marks.link.create({href:n.href});return X(n.content,t).map(o=>o.mark([...o.marks,e]))}function X(n,t){let e=[];if(typeof n=="string")return e.push(t.text(n)),e;for(const o of n)e.push(Ft(o,t));return e}function Q(n,t){let e=[];for(const o of n)if(o.type==="link")e.push(...Rt(o,t));else if(o.type==="text")e.push(...X([o],t));else throw new Ot(o);return e}function N(n,t){let e=n.id;e===void 0&&(e=F.options.generateID());let o=n.type;o===void 0&&(o="paragraph");let r;if(!n.content)r=t.nodes[o].create(n.props);else if(typeof n.content=="string")r=t.nodes[o].create(n.props,t.text(n.content));else{const s=Q(n.content,t);r=t.nodes[o].create(n.props,s)}const i=[];if(n.children)for(const s of n.children)i.push(N(s,t));const a=t.nodes.blockGroup.create({},i);return t.nodes.blockContainer.create({id:e,...n.props},i.length>0?[r,a]:r)}function zt(n){const t=[];let e;return n.content.forEach(o=>{const r={};let i;for(const a of o.marks)if(a.type.name==="link")i=a;else if(V.has(a.type.name))r[a.type.name]=!0;else if(J.has(a.type.name))r[a.type.name]=a.attrs.color;else throw Error("Mark is of an unrecognized type: "+a.type.name);i&&e&&i.attrs.href===e.href?e.content.push({type:"text",text:o.textContent,styles:r}):i?(e={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]},t.push(e)):(t.push({type:"text",text:o.textContent,styles:r}),e=void 0)}),t}function M(n,t){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const e=t==null?void 0:t.get(n);if(e)return e;const o=b(n,0);let r=o.id;r===null&&(r=F.options.generateID());const i={};for(const[l,c]of Object.entries({...o.node.attrs,...o.contentNode.attrs})){if(!(o.contentType.name in O))throw Error("Block is of an unrecognized type: "+o.contentType.name);O[o.contentType.name].has(l)&&(i[l]=c)}const a=zt(o.contentNode),s=[];for(let l=0;l<o.numChildBlocks;l++)s.push(M(o.node.lastChild.child(l)));const d={id:r,type:o.contentType.name,props:i,content:a,children:s};return t==null||t.set(n,d),d}function R(n,t){let e,o;if(t.firstChild.descendants((r,i)=>e?!1:r.type.name!=="blockContainer"||r.attrs.id!==n?!0:(e=r,o=i+1,!1)),e===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:o}}function Z(n,t,e="before",o){const r=typeof t=="string"?t:t.id,i=[];for(const l of n)i.push(N(l,o.schema));let a=-1;const{node:s,posBeforeNode:d}=R(r,o.state.doc);if(e==="before"&&(a=d),e==="after"&&(a=d+s.nodeSize),e==="nested"){if(s.childCount<2){a=d+s.firstChild.nodeSize+1;const l=o.state.schema.nodes.blockGroup.create({},i);o.view.dispatch(o.state.tr.insert(a,l));return}a=d+s.firstChild.nodeSize+2}o.view.dispatch(o.state.tr.insert(a,i))}function qt(n,t,e){const o=typeof n=="string"?n:n.id,{posBeforeNode:r}=R(o,e.state.doc);e.commands.BNUpdateBlock(r+1,t)}function tt(n,t){const e=new Set(n.map(r=>typeof r=="string"?r:r.id));let o=0;if(t.state.doc.descendants((r,i)=>{if(e.size===0)return!1;if(r.type.name!=="blockContainer"||!e.has(r.attrs.id))return!0;e.delete(r.attrs.id);const a=t.state.doc.nodeSize;t.commands.BNDeleteBlock(i-o+1);const s=t.state.doc.nodeSize;return o+=a-s,!1}),e.size>0){let r=[...e].join(`
|
|
2
|
+
`);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function Ut(n,t,e){Z(t,n[0],"before",e),tt(n,e)}function Gt(){const n=t=>{let e=t.children.length;for(let o=0;o<e;o++){const r=t.children[o];if(r.type==="element"&&(n(r),r.tagName==="u"))if(r.children.length>0){t.children.splice(o,1,...r.children);const i=r.children.length-1;e+=i,o+=i}else t.children.splice(o,1),e--,o--}};return n}function $t(n){const t=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),e=o=>{let r=o.children.length,i;for(let a=0;a<r;a++){const d=o.children[a].children[0],l=d.children[0],c=d.children.length===2?d.children[1]:null,p=t.has(l.properties.dataContentType),g=p?n.orderedListItemBlockTypes.has(l.properties.dataContentType)?"ol":"ul":null;if(c!==null&&e(c),i&&i.tagName!==g){o.children.splice(a-i.children.length,i.children.length,i);const m=i.children.length-1;a-=m,r-=m,i=void 0}if(p){i||(i=$.fromDom(document.createElement(g)));const m=$.fromDom(document.createElement("li"));m.children.push(l.children[0]),c!==null&&m.children.push(...c.children),i.children.push(m)}else if(c!==null){o.children.splice(a+1,0,...c.children),o.children[a]=l.children[0];const m=c.children.length;a+=m,r+=m}else o.children[a]=l.children[0]}i&&o.children.splice(r-i.children.length,i.children.length,i)};return e}async function et(n,t){const e=document.createElement("div"),o=v.DOMSerializer.fromSchema(t);for(const i of n){const a=N(i,t),s=o.serializeNode(a);e.appendChild(s)}return(await D.unified().use(K.default,{fragment:!0}).use($t,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(W.default).process(e.innerHTML)).value}async function nt(n,t){const e=document.createElement("div");e.innerHTML=n.trim();const r=v.DOMParser.fromSchema(t).parse(e),i=[];for(let a=0;a<r.firstChild.childCount;a++)i.push(M(r.firstChild.child(a)));return i}async function jt(n,t){return(await D.unified().use(K.default,{fragment:!0}).use(Gt).use(It.default).use(Y.default).use(Nt.default).process(await et(n,t))).value}async function Kt(n,t){const e=await D.unified().use(Lt.default).use(Y.default).use(_t.default).use(W.default).process(n);return nt(e.value,t)}const Wt=u.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,t)=>({state:e,view:o})=>{const r=b(e.doc,n);return r===void 0?!1:(e.tr.setNodeAttribute(r.startPos-1,"backgroundColor",t),o.focus(),!0)}}}}),Yt=u.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:t})=>n!=="default"?t.setMark(this.name,{color:n}):t.unsetMark(this.name)}}}),ot=new y.PluginKey("previous-blocks"),Vt={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Jt=()=>{let n;return new y.Plugin({key:ot,view(t){return{update:async(e,o)=>{var r;((r=this.key)==null?void 0:r.getState(e.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(ot,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,r){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(r.doc))return e;const i={},a=u.findChildren(o.doc,l=>l.attrs.id),s=new Map(a.map(l=>[l.node.attrs.id,l])),d=u.findChildren(r.doc,l=>l.attrs.id);for(let l of d){const c=s.get(l.node.attrs.id),p=c==null?void 0:c.node.firstChild,g=l.node.firstChild;if(c&&p&&g){const m={index:g.attrs.index,level:g.attrs.level,type:g.type.name,depth:r.doc.resolve(l.pos).depth};let k={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:o.doc.resolve(c.pos).depth};i[l.node.attrs.id]=k,t.getMeta("numberedListIndexing")&&(l.node.attrs.id in e.prevTransactionOldBlockAttrs&&(k=e.prevTransactionOldBlockAttrs[l.node.attrs.id]),m.type==="numberedListItem"&&(k.index=m.index)),e.currentTransactionOldBlockAttrs[l.node.attrs.id]=k,JSON.stringify(k)!==JSON.stringify(m)&&(k["depth-change"]=k.depth-m.depth,e.updatedBlocks.add(l.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=i,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((r,i)=>{if(!r.attrs.id||!e.updatedBlocks.has(r.attrs.id))return;const a=e.currentTransactionOldBlockAttrs[r.attrs.id],s={};for(let[l,c]of Object.entries(a))s["data-prev-"+Vt[l]]=c||"none";const d=B.Decoration.node(i,i+r.nodeSize,{...s});o.push(d)}),B.DecorationSet.create(t.doc,o)}}})},T={blockOuter:"_blockOuter_63zqr_5",blockContent:"_blockContent_63zqr_10",blockGroup:"_blockGroup_63zqr_26",block:"_block_63zqr_5",isEmpty:"_isEmpty_63zqr_224",isFilter:"_isFilter_63zqr_225",hasAnchor:"_hasAnchor_63zqr_247"},Xt={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Qt=u.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 t={};for(let[e,o]of Object.entries(Xt))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:n}){return["div",u.mergeAttributes(n,{class:T.blockOuter,"data-node-type":"block-outer"}),["div",u.mergeAttributes(n,{class:T.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:n=>({state:t,dispatch:e})=>{const o=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:t,dispatch:e})=>{const o=b(t.doc,n);if(o===void 0)return!1;const{startPos:r,endPos:i}=o;return e&&t.tr.deleteRange(r,i),!0},BNUpdateBlock:(n,t)=>({state:e,dispatch:o})=>{const r=b(e.doc,n);if(r===void 0)return!1;const{startPos:i,endPos:a,node:s,contentNode:d}=r;if(o){if(t.children!==void 0){const l=[];for(const c of t.children)l.push(N(c,e.schema));s.childCount===2?e.tr.replace(i+d.nodeSize+1,a-1,new v.Slice(v.Fragment.from(l),0,0)):e.tr.insert(i+d.nodeSize,e.schema.nodes.blockGroup.create({},l))}if(t.content!==void 0){let l=[];typeof t.content=="string"?l.push(e.schema.text(t.content)):l=Q(t.content,e.schema),e.tr.replace(i+1,i+d.nodeSize-1,new v.Slice(v.Fragment.from(l),0,0))}e.tr.setNodeMarkup(i,t.type===void 0?void 0:e.schema.nodes[t.type],{...d.attrs,...t.props}),e.tr.setNodeMarkup(i-1,void 0,{...s.attrs,...t.props})}return!0},BNMergeBlocks:n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n+1).node().type.name==="blockContainer",r=t.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!r)return!1;const i=b(t.doc,n+1),{node:a,contentNode:s,startPos:d,endPos:l,depth:c}=i;if(a.childCount===2){const m=t.doc.resolve(d+s.nodeSize+1),k=t.doc.resolve(l-1),C=m.blockRange(k);e&&t.tr.lift(C,c-1)}let p=n-1,g=b(t.doc,p);for(;g.numChildBlocks>0;)if(p--,g=b(t.doc,p),g===void 0)return!1;return e&&(t.tr.deleteRange(d,d+s.nodeSize),t.tr.insertText(s.textContent,p-1),t.tr.setSelection(new y.TextSelection(t.doc.resolve(p-1)))),!0},BNSplitBlock:(n,t)=>({state:e,dispatch:o})=>{const r=b(e.doc,n);if(r===void 0)return!1;const{contentNode:i,contentType:a,startPos:s,endPos:d,depth:l}=r,c=e.doc.cut(s+1,n),p=e.doc.cut(n,d-1),g=e.schema.nodes.blockContainer.createAndFill(),m=d+1,k=m+2;return o&&(e.tr.insert(m,g),e.tr.replace(k,k+1,p.content.size>0?new v.Slice(v.Fragment.from(p),l+2,l+2):void 0),t&&e.tr.setBlockType(k,k,e.schema.node(a).type,i.attrs),e.tr.setSelection(new y.TextSelection(e.doc.resolve(k))),e.tr.replace(s+1,d-1,c.content.size>0?new v.Slice(v.Fragment.from(c),l+2,l+2):void 0)),!0}}},addProseMirrorPlugins(){return[Jt()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.undoInputRule(),()=>e.command(({state:o})=>{const{contentType:r}=b(o.doc,o.selection.from),i=o.selection.$anchor.parentOffset===0,a=r.name==="paragraph";return i&&!a?e.BNUpdateBlock(o.selection.from,{type:"paragraph",props:{}}):!1}),()=>e.command(({state:o})=>o.selection.$anchor.parentOffset===0?e.liftListItem("blockContainer"):!1),()=>e.command(({state:o})=>{const{depth:r,startPos:i}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,d=i===2,l=i-1;return!d&&a&&s&&r===2?e.BNMergeBlocks(l):!1})]),Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.command(({state:o})=>{const{node:r,depth:i}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,d=r.textContent.length===0,l=i>2;return a&&s&&d&&l?e.liftListItem("blockContainer"):!1}),()=>e.command(({state:o,chain:r})=>{const{node:i,endPos:a}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,d=o.selection.anchor===o.selection.head,l=i.textContent.length===0;if(s&&d&&l){const c=a+1,p=c+2;return r().BNCreateBlock(c).setTextSelection(p).run(),!0}return!1}),()=>e.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:{}})}}}),Zt=u.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",u.mergeAttributes(this.options.HTMLAttributes,n,{class:T.blockGroup,"data-node-type":"blockGroup"}),0]}}),te=u.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){return["div",u.mergeAttributes(n,{class:T.blockContent,"data-content-type":this.name}),["p",0]]}}),ee=u.Node.create({name:"heading",group:"blockContent",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 u.InputRule({find:new RegExp(`^(#{${parseInt(n)}})\\s$`),handler:({state:t,chain:e,range:o})=>{e().BNUpdateBlock(t.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:t}){return["div",u.mergeAttributes(t,{class:T.blockContent,"data-content-type":this.name}),["h"+n.attrs.level,0]]}}),rt=n=>{const{node:t,contentType:e}=b(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!e.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:r,chain:i,commands:a})=>[()=>a.command(()=>t.textContent.length===0?a.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>a.command(()=>t.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},ne=u.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new u.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:t,range:e})=>{t().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>rt(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){return["div",u.mergeAttributes(n,{class:T.blockContent,"data-content-type":this.name}),["p",0]]}}),oe=new y.PluginKey("numbered-list-indexing"),re=()=>new y.Plugin({key:oe,appendTransaction:(n,t,e)=>{const o=e.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return e.doc.descendants((i,a)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let s="1";const d=a===1,l=b(o.doc,a+1);if(l===void 0)return;if(!d){const g=b(o.doc,a-2);if(g===void 0)return;if(!(l.depth!==g.depth)){const k=g.contentNode;if(g.contentType.name==="numberedListItem"){const U=k.attrs.index;s=(parseInt(U)+1).toString()}}}l.contentNode.attrs.index!==s&&(r=!0,o.setNodeMarkup(a+1,void 0,{index:s}))}}),r?o:null}}),ie=u.Node.create({name:"numberedListItem",group:"blockContent",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new u.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:t,range:e})=>{t().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>rt(this.editor)}},addProseMirrorPlugins(){return[re()]},parseHTML(){return[{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){return["div",u.mergeAttributes(n,{class:T.blockContent,"data-content-type":this.name}),["p",0]]}}),se=[te,ee,ne,ie,Qt,Zt,u.Node.create({name:"doc",topNode:!0,content:"blockGroup"})],A={bnEditor:"_bnEditor_dbz5y_3",bnRoot:"_bnRoot_dbz5y_20",defaultStyles:"_defaultStyles_dbz5y_35",dragPreview:"_dragPreview_dbz5y_66"},ae=u.findParentNode(n=>n.type.name==="blockContainer");function z(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}class de{constructor({editor:t,pluginKey:e,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){h(this,"editor");h(this,"pluginKey");h(this,"suggestionsMenu");h(this,"pluginState");h(this,"itemCallback");h(this,"handleScroll",()=>{this.pluginKey.getState(this.editor._tiptapEditor.state).active&&this.suggestionsMenu.render(this.getDynamicParams(),!1)});this.editor=t,this.pluginKey=e,this.pluginState=z(),this.itemCallback=i=>{t._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-this.pluginState.triggerCharacter.length,to:t._tiptapEditor.state.selection.from}).run(),o({item:i,editor:t})},this.suggestionsMenu=r(this.getStaticParams()),document.addEventListener("scroll",this.handleScroll)}update(t,e){const o=this.pluginKey.getState(e),r=this.pluginKey.getState(t.state),i=!o.active&&r.active,a=o.active&&!r.active,s=o.active&&r.active;!i&&!s&&!a||(this.pluginState=a?o:r,(a||!this.editor.isEditable)&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",d=>d.preventDefault())),s&&this.suggestionsMenu.render(this.getDynamicParams(),!1),i&&this.editor.isEditable&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",d=>d.preventDefault())))}destroy(){document.removeEventListener("scroll",this.handleScroll)}getStaticParams(){return{itemCallback:t=>this.itemCallback(t)}}getDynamicParams(){const t=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);return{items:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex,referenceRect:t.getBoundingClientRect()}}}function le({pluginKey:n,editor:t,defaultTriggerCharacter:e,suggestionsMenuFactory:o,onSelectItem:r=()=>{},items:i=()=>[]}){if(e.length!==1)throw new Error("'char' should be a single character");const a=s=>{s.dispatch(s.state.tr.setMeta(n,{deactivate:!0}))};return new y.Plugin({key:n,view:s=>new de({editor:t,pluginKey:n,onSelectItem:d=>{a(s),r(d)},suggestionsMenuFactory:o}),state:{init(){return z()},apply(s,d,l,c){var g,m,k,C;if(s.getMeta("orderedListIndexing")!==void 0)return d;if((g=s.getMeta(n))!=null&&g.activate)return{active:!0,triggerCharacter:((m=s.getMeta(n))==null?void 0:m.triggerCharacter)||"",queryStartPos:c.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const p={...d};if(p.items=i(c.doc.textBetween(d.queryStartPos,c.selection.from)),p.notFoundCount=0,p.items.length===0&&(p.notFoundCount=Math.max(0,d.notFoundCount+(c.selection.from-l.selection.from))),c.selection.from!==c.selection.to||(k=s.getMeta(n))!=null&&k.deactivate||s.getMeta("focus")||s.getMeta("blur")||s.getMeta("pointer")||d.active&&c.selection.from<d.queryStartPos||p.notFoundCount>3)return z();if(((C=s.getMeta(n))==null?void 0:C.selectedItemIndexChanged)!==void 0){let E=s.getMeta(n).selectedItemIndexChanged;E<0?E=d.items.length-1:E>=d.items.length&&(E=0),p.keyboardHoveredItemIndex=E}return p}},props:{handleKeyDown(s,d){const l=this.getState(s.state).active;if(d.key===e&&!l)return s.dispatch(s.state.tr.insertText(e).scrollIntoView().setMeta(n,{activate:!0,triggerCharacter:e})),!0;if(!l)return!1;const{triggerCharacter:c,queryStartPos:p,items:g,keyboardHoveredItemIndex:m}=n.getState(s.state);return d.key==="ArrowUp"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m-1})),!0):d.key==="ArrowDown"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m+1})),!0):d.key==="Enter"?(a(s),t._tiptapEditor.chain().focus().deleteRange({from:p-c.length,to:t._tiptapEditor.state.selection.from}).run(),r({item:g[m],editor:t}),!0):d.key==="Escape"?(a(s),!0):!1},handleClick(s){a(s)},decorations(s){const{active:d,decorationId:l,queryStartPos:c,triggerCharacter:p}=this.getState(s);if(!d)return null;if(p===""){const g=ae(s.selection);if(g)return B.DecorationSet.create(s.doc,[B.Decoration.node(g.pos,g.pos+g.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}return B.DecorationSet.create(s.doc,[B.Decoration.inline(c-p.length,c,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}}})}const q=new y.PluginKey("suggestions-slash-commands"),ce=u.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[le({pluginKey:q,editor:this.options.editor,defaultTriggerCharacter:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:t=>n.filter(e=>e.match(t)),onSelectItem:({item:t,editor:e})=>{t.execute(e)}})]}});class I extends y.Selection{constructor(e,o){super(e,o);h(this,"nodes");const r=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(i,a,s)=>{if(s!==null&&s.eq(r))return this.nodes.push(i),!1})}static create(e,o,r=o){return new I(e.resolve(o),e.resolve(r))}content(){return new v.Slice(v.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof I)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){let r=o.mapResult(this.from),i=o.mapResult(this.to);return i.deleted?y.Selection.near(e.resolve(r.pos)):r.deleted?y.Selection.near(e.resolve(i.pos)):new I(e.resolve(r.pos),e.resolve(i.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const ue=At.__serializeForClipboard;let x;function it(n,t){var r;if(!t.dom.isConnected)return;let e=t.posAtCoords(n);if(!e)return;let o=t.domAtPos(e.pos).node;if(o!==t.dom){for(;o&&o.parentNode&&o.parentNode!==t.dom&&!((r=o.hasAttribute)!=null&&r.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function he(n,t){let e=it(n,t);if(e&&e.node.nodeType===1){const o=t.docView;let r=o.nearestDesc(e.node,!0);return!r||r===o?null:r.posBefore}return null}function pe(n,t){let e,o;const r=t.resolve(n.from).node().type.spec.group==="blockContent",i=t.resolve(n.to).node().type.spec.group==="blockContent",a=Math.min(n.$anchor.depth,n.$head.depth);if(r&&i){const s=n.$from.start(a-1),d=n.$to.end(a-1);e=t.resolve(s-1).pos,o=t.resolve(d+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function st(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),r=n.domAtPos(t).node,i=(c,p)=>Array.prototype.indexOf.call(c.children,p),a=i(r,n.domAtPos(t+1).node.parentElement),s=i(r,n.domAtPos(e-1).node.parentElement);for(let c=r.childElementCount-1;c>=0;c--)(c>s||c<a)&&o.removeChild(o.children[c]);at(),x=o;const l=n.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");x.className=x.className+" "+A.dragPreview+" "+l,document.body.appendChild(x)}function at(){x!==void 0&&(document.body.removeChild(x),x=void 0)}function fe(n,t){if(!n.dataTransfer)return;const e=t.dom.getBoundingClientRect();let o={left:e.left+e.width/2,top:n.clientY},r=he(o,t);if(r!=null){const i=t.state.selection,a=t.state.doc,{from:s,to:d}=pe(i,a),l=s<=r&&r<d,c=i.$anchor.node()!==i.$head.node()||i instanceof I;l&&c?(t.dispatch(t.state.tr.setSelection(I.create(a,s,d))),st(t,s,d)):(t.dispatch(t.state.tr.setSelection(y.NodeSelection.create(t.state.doc,r))),st(t,r));let p=t.state.selection.content(),{dom:g,text:m}=ue(t,p);n.dataTransfer.clearData(),n.dataTransfer.setData("text/html",g.innerHTML),n.dataTransfer.setData("text/plain",m),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(x,0,0),t.dragging={slice:p,move:!0}}}class me{constructor({tiptapEditor:t,editor:e,blockMenuFactory:o,horizontalPosAnchoredAtRoot:r}){h(this,"editor");h(this,"ttEditor");h(this,"horizontalPosAnchoredAtRoot");h(this,"horizontalPosAnchor");h(this,"blockMenu");h(this,"hoveredBlock");h(this,"isDragging",!1);h(this,"menuOpen",!1);h(this,"menuFrozen",!1);h(this,"onDragStart",()=>{this.isDragging=!0});h(this,"onDrop",t=>{if(t.synthetic||!this.isDragging)return;let e=this.ttEditor.view.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!e||e.inside===-1){const o=new Event("drop",t),r=this.ttEditor.view.dom.firstChild.getBoundingClientRect();o.clientX=r.left+r.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.ttEditor.view.dom.dispatchEvent(o)}});h(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;let e=this.ttEditor.view.posAtCoords({left:t.clientX,top:t.clientY});if(!e||e.inside===-1){const o=new Event("dragover",t),r=this.ttEditor.view.dom.firstChild.getBoundingClientRect();o.clientX=r.left+r.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.ttEditor.view.dom.dispatchEvent(o)}});h(this,"onKeyDown",t=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1});h(this,"onMouseDown",t=>{var e;(e=this.blockMenu.element)!=null&&e.contains(t.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)});h(this,"onMouseMove",t=>{var a,s;if(this.menuFrozen)return;const e=this.ttEditor.view.dom.firstChild.getBoundingClientRect();this.horizontalPosAnchor=e.x;const o={left:e.left+e.width/2,top:t.clientY},r=it(o,this.ttEditor.view);if(!r||!this.editor.isEditable){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}this.menuOpen&&((a=this.hoveredBlock)!=null&&a.hasAttribute("data-id"))&&((s=this.hoveredBlock)==null?void 0:s.getAttribute("data-id"))===r.id||(this.hoveredBlock=r.node,!r.node.firstChild)||this.editor.isEditable&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))});h(this,"onScroll",()=>{this.menuOpen&&this.blockMenu.render(this.getDynamicParams(),!1)});this.editor=e,this.ttEditor=t,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.addEventListener("scroll",this.onScroll),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.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("keydown",this.onKeyDown)}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const e=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.ttEditor.view.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const r=b(this.ttEditor.state.doc,o.pos);if(r===void 0)return;const{contentNode:i,endPos:a}=r;if(i.textContent.length!==0){const s=a+1,d=s+2;this.ttEditor.chain().BNCreateBlock(s).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.ttEditor.commands.setTextSelection(a);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:t=>{this.isDragging=!0,fe(t,this.ttEditor.view)},blockDragEnd:()=>at(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1}}}getDynamicParams(){const e=this.hoveredBlock.firstChild.getBoundingClientRect();return{block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id")),referenceRect:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:e.x,e.y,e.width,e.height)}}}const ge=n=>new y.Plugin({key:new y.PluginKey("DraggableBlocksPlugin"),view:()=>new me({tiptapEditor:n.tiptapEditor,editor:n.editor,blockMenuFactory:n.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),ke=u.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[ge({tiptapEditor:this.editor,editor:this.options.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}});class ye{constructor({editor:t,tiptapEditor:e,formattingToolbarFactory:o,view:r,shouldShow:i}){h(this,"editor");h(this,"ttEditor");h(this,"view");h(this,"formattingToolbar");h(this,"preventHide",!1);h(this,"preventShow",!1);h(this,"toolbarIsOpen",!1);h(this,"prevWasEditable",null);h(this,"shouldShow",({view:t,state:e,from:o,to:r})=>{const{doc:i,selection:a}=e,{empty:s}=a,d=!i.textBetween(o,r).length&&u.isTextSelection(e.selection);return!(!t.hasFocus()||s||d)});h(this,"viewMousedownHandler",()=>{this.preventShow=!0});h(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.ttEditor.view))});h(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});h(this,"focusHandler",()=>{setTimeout(()=>this.update(this.ttEditor.view))});h(this,"blurHandler",({event:t})=>{var e,o;if(this.preventHide){this.preventHide=!1;return}t!=null&&t.relatedTarget&&((o=(e=this.formattingToolbar.element)==null?void 0:e.parentNode)!=null&&o.contains(t.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});h(this,"scrollHandler",()=>{this.toolbarIsOpen&&this.formattingToolbar.render(this.getDynamicParams(),!1)});this.editor=t,this.ttEditor=e,this.view=r,this.formattingToolbar=o(this.getStaticParams()),i&&(this.shouldShow=i),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),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var g;const{state:o,composing:r}=t,{doc:i,selection:a}=o,s=e&&e.doc.eq(i)&&e.selection.eq(a);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(r||s))return;this.prevWasEditable=this.editor.isEditable;const{ranges:d}=a,l=Math.min(...d.map(m=>m.$from.pos)),c=Math.max(...d.map(m=>m.$to.pos)),p=(g=this.shouldShow)==null?void 0:g.call(this,{editor:this.editor,view:t,state:o,oldState:e,from:l,to:c});if(this.editor.isEditable&&!this.toolbarIsOpen&&!this.preventShow&&(p||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&&(p||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!p||this.preventShow||!this.editor.isEditable)){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.ttEditor.off("focus",this.focusHandler),this.ttEditor.off("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:t}=this.ttEditor.view,{selection:e}=t,{ranges:o}=e,r=Math.min(...o.map(a=>a.$from.pos)),i=Math.max(...o.map(a=>a.$to.pos));if(u.isNodeSelection(e)){const a=this.ttEditor.view.nodeDOM(r);if(a)return a.getBoundingClientRect()}return u.posToDOMRect(this.ttEditor.view,r,i)}getStaticParams(){return{editor:this.editor}}getDynamicParams(){return{referenceRect:this.getSelectionBoundingBox()}}}const be=n=>new y.Plugin({key:new y.PluginKey("FormattingToolbarPlugin"),view:t=>new ye({view:t,...n})}),ve=u.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory||!this.options.editor)throw new Error("required args not defined for FormattingToolbarExtension");return[be({tiptapEditor:this.editor,editor:this.options.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new y.PluginKey("FormattingToolbarPlugin")})]}}),Ee=new y.PluginKey("HyperlinkToolbarPlugin");class Ce{constructor({editor:t,hyperlinkToolbarFactory:e}){h(this,"editor");h(this,"hyperlinkToolbar");h(this,"menuUpdateTimer");h(this,"startMenuUpdateTimer");h(this,"stopMenuUpdateTimer");h(this,"mouseHoveredHyperlinkMark");h(this,"mouseHoveredHyperlinkMarkRange");h(this,"keyboardHoveredHyperlinkMark");h(this,"keyboardHoveredHyperlinkMarkRange");h(this,"hyperlinkMark");h(this,"hyperlinkMarkRange");h(this,"mouseOverHandler",t=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.editor.view.posAtDOM(e,0)+1,r=this.editor.state.doc.resolve(o),i=r.marks();for(const a of i)if(a.type.name===this.editor.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=a,this.mouseHoveredHyperlinkMarkRange=u.getMarkRange(r,a.type,a.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});h(this,"scrollHandler",()=>{this.hyperlinkMark!==void 0&&this.hyperlinkToolbar.render(this.getDynamicParams(),!1)});this.editor=t,this.hyperlinkToolbar=e(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("scroll",this.scrollHandler)}update(){var e,o,r,i;if(!this.editor.view.hasFocus())return;const t=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 a=this.editor.state.selection.$from.marks();for(const s of a)if(s.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=s,this.keyboardHoveredHyperlinkMarkRange=u.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&&this.editor.isEditable){if(this.getDynamicParams(),!t){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(e=this.hyperlinkToolbar.element)==null||e.addEventListener("mouseleave",this.startMenuUpdateTimer),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1);return}if(t&&(!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),document.removeEventListener("scroll",this.scrollHandler)}getStaticParams(){return{editHyperlink:(t,e)=>{const o=this.editor.view.state.tr.insertText(e,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+e.length,this.editor.schema.mark("link",{href:t})),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 Te=(n,t)=>new y.Plugin({key:Ee,view:()=>new Ce({editor:n,hyperlinkToolbarFactory:t.hyperlinkToolbarFactory})}),Be=j.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))||[],Te(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),Me=new y.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 …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new y.Plugin({key:Me,props:{decorations:n=>{const{doc:t,selection:e}=n,o=q.getState(n),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=e,a=[];if(r)return t.descendants((s,d)=>{const l=i>=d&&i<=d+s.nodeSize,c=!s.isLeaf&&!s.childCount;if((l||!this.options.showOnlyCurrent)&&c){const p=[this.options.emptyNodeClass];this.editor.isEmpty&&p.push(this.options.emptyEditorClass),l&&p.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&p.push(this.options.isFilterClass);const g=B.Decoration.node(d,d+s.nodeSize,{class:p.join(" ")});a.push(g)}return this.options.includeChildren}),B.DecorationSet.create(t,a)}}})]}});class we{constructor(t,e){this.name=t,this.match=e}}class P extends we{constructor(t,e,o=[]){super(t,r=>this.name.toLowerCase().startsWith(r.toLowerCase())||this.aliases.filter(i=>i.toLowerCase().startsWith(r.toLowerCase())).length!==0),this.name=t,this.execute=e,this.aliases=o}}function L(n,t){const e=n.getTextCursorPosition().block;e.content.length===1&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0?n.updateBlock(e,t):(n.insertBlocks([t],e,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock))}const dt=[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"])],Se=u.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:t})=>{const e=[],o=b(t.doc,t.selection.from);if(o===void 0)return!1;let r=o.startPos;for(;r<t.selection.to;)t.doc.resolve(r).node().type.spec.group==="blockContent"?(e.push(r-1),r+=t.doc.resolve(r).node().nodeSize-1):r+=1;for(const i of e)t.tr.setNodeAttribute(i,"textAlignment",n);return!0}}}}),Pe=u.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,t)=>({state:e,view:o})=>{const r=b(e.doc,n);return r===void 0?!1:(e.tr.setNodeAttribute(r.startPos-1,"textColor",t),o.focus(),!0)}}}}),Ie=u.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:t})=>n!=="default"?t.setMark(this.name,{color:n}):t.unsetMark(this.name)}}}),Le=u.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new y.PluginKey(this.name);return[new y.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:r,tr:i,schema:a}=o,s=n.getState(o),d=r.content.size-2,l=a.nodes.blockContainer,c=a.nodes.paragraph;if(s)return i.insert(d,l.create(void 0,c.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");return o.nodeSize>4}}})]}}),lt=n=>{const t=[u.extensions.ClipboardTextSerializer,u.extensions.Commands,u.extensions.Editable,u.extensions.FocusEvents,u.extensions.Tabindex,Ct.Gapcursor,xe.configure({emptyNodeClass:T.isEmpty,hasAnchorClass:T.hasAnchor,isFilterClass:T.isFilter,includeChildren:!0,showOnlyCurrent:!1}),F.configure({types:["blockContainer"]}),Tt.HardBreak,wt.Text,bt.Bold,vt.Code,Mt.Italic,xt.Strike,St.Underline,Ie,Pe,Yt,Wt,Se,...se,Et.Dropcursor.configure({width:5,color:"#ddeeff"}),Bt.History,Le];return n.uiFactories.blockSideMenuFactory&&t.push(ke.configure({editor:n.editor,blockSideMenuFactory:n.uiFactories.blockSideMenuFactory})),n.uiFactories.formattingToolbarFactory&&t.push(ve.configure({editor:n.editor,formattingToolbarFactory:n.uiFactories.formattingToolbarFactory})),n.uiFactories.hyperlinkToolbarFactory?t.push(Be.configure({hyperlinkToolbarFactory:n.uiFactories.hyperlinkToolbarFactory})):t.push(j.Link),n.uiFactories.slashMenuFactory&&t.push(ce.configure({editor:n.editor,commands:n.slashCommands,slashMenuFactory:n.uiFactories.slashMenuFactory})),t},_e={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ne{constructor(t={}){h(this,"_tiptapEditor");h(this,"blockCache",new WeakMap);var i,a,s;t={defaultStyles:!0,...t};const e=lt({editor:this,uiFactories:t.uiFactories||{},slashCommands:t.slashCommands||dt});let o=t.disableHistoryExtension?e.filter(d=>d.name!=="history"):e;const r={..._e,...t._tiptapOptions,onCreate:()=>{var d;(d=t.onEditorReady)==null||d.call(t,this),t.initialContent&&this.replaceBlocks(this.topLevelBlocks,t.initialContent)},onUpdate:()=>{var d;(d=t.onEditorContentChange)==null||d.call(t,this)},onSelectionUpdate:()=>{var d;(d=t.onTextCursorPositionChange)==null||d.call(t,this)},editable:t.editable===void 0?!0:t.editable,extensions:t.enableBlockNoteExtensions===!1?(i=t._tiptapOptions)==null?void 0:i.extensions:[...((a=t._tiptapOptions)==null?void 0:a.extensions)||[],...o],editorProps:{attributes:{"data-theme":t.theme||"light",...t.editorDOMAttributes||{},class:[A.bnEditor,A.bnRoot,t.defaultStyles?A.defaultStyles:"",((s=t.editorDOMAttributes)==null?void 0:s.class)||""].join(" ")}}};t.parentElement&&(r.element=t.parentElement),this._tiptapEditor=new u.Editor(r)}get domElement(){return this._tiptapEditor.view.dom}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(M(e,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(r=>typeof o<"u"?!1:r.type.name!=="blockContainer"||r.attrs.id!==e?!0:(o=M(r,this.blockCache),!1)),o}forEachBlock(t,e=!1){const o=this.topLevelBlocks.slice();e&&o.reverse();function r(i){for(const a of i){if(!t(a))return!1;const s=e?a.children.slice().reverse():a.children;if(!r(s))return!1}return!0}r(o)}getTextCursorPosition(){const{node:t,depth:e,startPos:o,endPos:r}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),i=this._tiptapEditor.state.doc.resolve(r).index(e-1),a=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let s;i>0&&(s=this._tiptapEditor.state.doc.resolve(o-2).node());let d;return i<a-1&&(d=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:M(t,this.blockCache),prevBlock:s===void 0?void 0:M(s,this.blockCache),nextBlock:d===void 0?void 0:M(d,this.blockCache)}}setTextCursorPosition(t,e="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:r}=R(o,this._tiptapEditor.state.doc),{startPos:i,contentNode:a}=b(this._tiptapEditor.state.doc,r+2);e==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+a.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to)return;const t=[];return this._tiptapEditor.state.doc.descendants((e,o)=>e.type.spec.group!=="blockContent"||o+e.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(M(this._tiptapEditor.state.doc.resolve(o).node(),this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.setEditable(t)}insertBlocks(t,e,o="before"){Z(t,e,o,this._tiptapEditor)}updateBlock(t,e){qt(t,e,this._tiptapEditor)}removeBlocks(t){tt(t,this._tiptapEditor)}replaceBlocks(t,e){Ut(t,e,this._tiptapEditor)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks(),o=new Set(["bold","italic","underline","strike","code"]),r=new Set(["textColor","backgroundColor"]);for(const i of e)o.has(i.type.name)?t[i.type.name]=!0:r.has(i.type.name)&&(t[i.type.name]=i.attrs.color);return t}addStyles(t){const e=new Set(["bold","italic","underline","strike","code"]),o=new Set(["textColor","backgroundColor"]);for(const[r,i]of Object.entries(t))e.has(r)?this._tiptapEditor.commands.setMark(r):o.has(r)&&this._tiptapEditor.commands.setMark(r,{color:i})}removeStyles(t){for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){const e=new Set(["bold","italic","underline","strike","code"]),o=new Set(["textColor","backgroundColor"]);for(const[r,i]of Object.entries(t))e.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(t,e){if(t==="")return;let{from:o,to:r}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(o,r));const i=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,o,r).addMark(o,o+e.length,i))}canNestBlock(){const{startPos:t,depth:e}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(e-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=b(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(t){return et(t,this._tiptapEditor.schema)}async HTMLToBlocks(t){return nt(t,this._tiptapEditor.schema)}async blocksToMarkdown(t){return jt(t,this._tiptapEditor.schema)}async markdownToBlocks(t){return Kt(t,this._tiptapEditor.schema)}}f.BaseSlashMenuItem=P,f.BlockNoteEditor=Ne,f.blockProps=O,f.defaultSlashMenuItems=dt,f.getBlockNoteExtensions=lt,f.globalProps=_,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
3
3
|
//# sourceMappingURL=blocknote.umd.cjs.map
|