@blocknote/core 0.4.6-alpha.1 → 0.4.6-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- (function(f,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(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,c,v,y,ue,he,pe,fe,me,ke,ge,ye,_,j,be,ve,Ce,Be,xe,Te,we,$,Me,Ee,Ie,T){"use strict";var _t=Object.defineProperty;var Ot=(f,c,v)=>c in f?_t(f,c,{enumerable:!0,configurable:!0,writable:!0,value:v}):f[c]=v;var p=(f,c,v)=>(Ot(f,typeof c!="symbol"?c+"":c,v),v);const E=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Pe(n){if(n&&typeof n=="object"&&"default"in n)return n;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const K=E(he),Ae=E(pe),Y=E(fe),W=E(me),Se=E(ke),Ne=E(ge),He=E(ye),Le=Pe(T),S=["backgroundColor","textColor","textAlignment"],O={paragraph:new Set([...S]),heading:new Set([...S,"level"]),numberedListItem:new Set([...S]),bulletListItem:new Set([...S])};function b(n,e){if(e<0||e>n.nodeSize)return;const t=n.resolve(e),o=t.depth;let r=t.node(o),i=o;for(;;){if(i<0)return;if(r.type.name==="blockContainer")break;i-=1,r=t.node(i)}const d=r.attrs.id,s=r.firstChild,a=s.type,l=r.childCount===2?r.lastChild.childCount:0,u=t.start(i),h=t.end(i);return{id:d,node:r,contentNode:s,contentType:a,numChildBlocks:l,startPos:u,endPos:h,depth:i}}function _e(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Oe(n){const e=n.filter((o,r)=>n.indexOf(o)!==r);return _e(e)}const D=c.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>window.__TEST_OPTIONS?(window.__TEST_OPTIONS.mockID===void 0?window.__TEST_OPTIONS.mockID=0:window.__TEST_OPTIONS.mockID++,parseInt(window.__TEST_OPTIONS.mockID)):ue.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(a=>a.name==="collaboration"))return;const{view:n,state:e}=this.editor,{tr:t,doc:o}=e,{types:r,attributeName:i,generateID:d}=this.options;c.findChildren(o,a=>r.includes(a.type.name)&&a.attrs[i]===null).forEach(({node:a,pos:l})=>{t.setNodeMarkup(l,void 0,{...a.attrs,[i]:d()})}),t.setMeta("addToHistory",!1),n.dispatch(t)},addProseMirrorPlugins(){let n=null,e=!1;return[new y.Plugin({key:new y.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const i=t.some(g=>g.docChanged)&&!o.doc.eq(r.doc),d=this.options.filterTransaction&&t.some(g=>{var B,C;return!(!((C=(B=this.options).filterTransaction)===null||C===void 0)&&C.call(B,g))});if(!i||d)return;const{tr:s}=r,{types:a,attributeName:l,generateID:u}=this.options,h=c.combineTransactionSteps(o.doc,t),{mapping:k}=h;if(c.getChangedRanges(h).forEach(({newRange:g})=>{const B=c.findChildrenInRange(r.doc,g,M=>a.includes(M.type.name)),C=B.map(({node:M})=>M.attrs[l]).filter(M=>M!==null),U=Oe(C);B.forEach(({node:M,pos:L})=>{var G;const ce=(G=s.doc.nodeAt(L))===null||G===void 0?void 0:G.attrs[l];if(ce===null){s.setNodeMarkup(L,void 0,{...M.attrs,[l]:u()});return}const{deleted:Lt}=k.invert().mapResult(L);Lt&&U.includes(ce)&&s.setNodeMarkup(L,void 0,{...M.attrs,[l]:u()})})}),!!s.steps.length)return s},view(t){const o=r=>{var i;n=!((i=t.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{var r;return(n!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(n=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:o,attributeName:r}=this.options,i=d=>{const s=[];return d.forEach(a=>{if(a.isText){s.push(a);return}if(!o.includes(a.type.name)){s.push(a.copy(i(a.content)));return}const l=a.type.create({...a.attrs,[r]:null},i(a.content),a.marks);s.push(l)}),v.Fragment.from(s)};return e=!1,new v.Slice(i(t.content),t.openStart,t.openEnd)}}})]}});class De extends Error{constructor(e){super(`Unreachable case: ${e}`)}}const V=new Set(["bold","italic","underline","strike"]),J=new Set(["textColor","backgroundColor"]);function Fe(n,e){const t=[];for(const[o,r]of Object.entries(n.styles))V.has(o)?t.push(e.mark(o)):J.has(o)&&t.push(e.mark(o,{color:r}));return e.text(n.text,t)}function Re(n,e){const t=e.marks.link.create({href:n.href});return X(n.content,e).map(o=>o.mark([...o.marks,t]))}function X(n,e){let t=[];if(typeof n=="string")return t.push(e.text(n)),t;for(const o of n)t.push(Fe(o,e));return t}function Q(n,e){let t=[];for(const o of n)if(o.type==="link")t.push(...Re(o,e));else if(o.type==="text")t.push(...X([o],e));else throw new De(o);return t}function H(n,e){let t=n.id;t===void 0&&(t=D.options.generateID());let o=n.type;o===void 0&&(o="paragraph");let r;if(!n.content)r=e.nodes[o].create(n.props);else if(typeof n.content=="string")r=e.nodes[o].create(n.props,e.text(n.content));else{const s=Q(n.content,e);r=e.nodes[o].create(n.props,s)}const i=[];if(n.children)for(const s of n.children)i.push(H(s,e));const d=e.nodes.blockGroup.create({},i);return e.nodes.blockContainer.create({id:t,...n.props},i.length>0?[r,d]:r)}function ze(n){const e=[];let t;return n.content.forEach(o=>{const r={};let i;for(const d of o.marks)if(d.type.name==="link")i=d;else if(V.has(d.type.name))r[d.type.name]=!0;else if(J.has(d.type.name))r[d.type.name]=d.attrs.color;else throw Error("Mark is of an unrecognized type: "+d.type.name);i&&t&&i.attrs.href===t.href?t.content.push({type:"text",text:o.textContent,styles:r}):i?(t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]},e.push(t)):(e.push({type:"text",text:o.textContent,styles:r}),t=void 0)}),e}function I(n,e){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const t=e==null?void 0:e.get(n);if(t)return t;const o=b(n,0);let r=o.id;r===null&&(r=D.options.generateID());const i={};for(const[l,u]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]=u)}const d=ze(o.contentNode),s=[];for(let l=0;l<o.numChildBlocks;l++)s.push(I(o.node.lastChild.child(l)));const a={id:r,type:o.contentType.name,props:i,content:d,children:s};return e==null||e.set(n,a),a}function F(n,e){let t,o;if(e.firstChild.descendants((r,i)=>t?!1:r.type.name!=="blockContainer"||r.attrs.id!==n?!0:(t=r,o=i+1,!1)),t===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:o}}function Z(n,e,t="before",o){const r=typeof e=="string"?e:e.id,i=[];for(const l of n)i.push(H(l,o.schema));let d=-1;const{node:s,posBeforeNode:a}=F(r,o.state.doc);if(t==="before"&&(d=a),t==="after"&&(d=a+s.nodeSize),t==="nested"){if(s.childCount<2){d=a+s.firstChild.nodeSize+1;const l=o.state.schema.nodes.blockGroup.create({},i);o.view.dispatch(o.state.tr.insert(d,l));return}d=a+s.firstChild.nodeSize+2}o.view.dispatch(o.state.tr.insert(d,i))}function qe(n,e,t){const o=typeof n=="string"?n:n.id,{posBeforeNode:r}=F(o,t.state.doc);t.commands.BNUpdateBlock(r+1,e)}function ee(n,e){const t=new Set(n.map(r=>typeof r=="string"?r:r.id));let o=0;if(e.state.doc.descendants((r,i)=>{if(t.size===0)return!1;if(r.type.name!=="blockContainer"||!t.has(r.attrs.id))return!0;t.delete(r.attrs.id);const d=e.state.doc.nodeSize;e.commands.BNDeleteBlock(i-o+1);const s=e.state.doc.nodeSize;return o+=d-s,!1}),t.size>0){let r=[...t].join(`
2
- `);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function Ue(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 je(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{let r=o.children.length,i;for(let d=0;d<r;d++){const a=o.children[d].children[0],l=a.children[0],u=a.children.length===2?a.children[1]:null,h=e.has(l.properties.dataContentType),k=h?n.orderedListItemBlockTypes.has(l.properties.dataContentType)?"ol":"ul":null;if(u!==null&&t(u),i&&i.tagName!==k){o.children.splice(d-i.children.length,i.children.length,i);const m=i.children.length-1;d-=m,r-=m,i=void 0}if(h){i||(i=j.fromDom(document.createElement(k)));const m=j.fromDom(document.createElement("li"));m.children.push(l.children[0]),u!==null&&m.children.push(...u.children),i.children.push(m)}else if(u!==null){o.children.splice(d+1,0,...u.children),o.children[d]=l.children[0];const m=u.children.length;d+=m,r+=m}else o.children[d]=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 d=H(i,e),s=o.serializeNode(d);t.appendChild(s)}return(await _.unified().use(K.default,{fragment:!0}).use(je,{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 d=0;d<r.firstChild.childCount;d++)i.push(I(r.firstChild.child(d)));return i}async function $e(n,e){return(await _.unified().use(K.default,{fragment:!0}).use(Ge).use(Ae.default).use(W.default).use(He.default).process(await te(n,e))).value}async function Ke(n,e){const t=await _.unified().use(Se.default).use(W.default).use(Ne.default).use(Y.default).process(n);return ne(t.value,e)}const Ye=c.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=c.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={},d=c.findChildren(o.doc,l=>l.attrs.id),s=new Map(d.map(l=>[l.node.attrs.id,l])),a=c.findChildren(r.doc,l=>l.attrs.id);for(let l of a){const u=s.get(l.node.attrs.id),h=u==null?void 0:u.node.firstChild,k=l.node.firstChild;if(u&&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(u.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 d=t.currentTransactionOldBlockAttrs[r.attrs.id],s={};for(let[l,u]of Object.entries(d))s["data-prev-"+Ve[l]]=u||"none";const a=T.Decoration.node(i,i+r.nodeSize,{...s});o.push(a)}),T.DecorationSet.create(e.doc,o)}}})},x={blockOuter:"_blockOuter_qwsjj_5",block:"_block_qwsjj_5",blockContent:"_blockContent_qwsjj_19",blockGroup:"_blockGroup_qwsjj_48",isEmpty:"_isEmpty_qwsjj_237",isFilter:"_isFilter_qwsjj_238",hasAnchor:"_hasAnchor_qwsjj_251"},Xe={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Qe=c.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",c.mergeAttributes(n,{class:x.blockOuter,"data-node-type":"block-outer"}),["div",c.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:d,node:s,contentNode:a}=r;if(o){if(e.children!==void 0){const l=[];for(const u of e.children)l.push(H(u,t.schema));s.childCount===2?t.tr.replace(i+a.nodeSize+1,d-1,new v.Slice(v.Fragment.from(l),0,0)):t.tr.insert(i+a.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+a.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],{...a.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:d,contentNode:s,startPos:a,endPos:l,depth:u}=i;if(d.childCount===2){const m=e.doc.resolve(a+s.nodeSize+1),g=e.doc.resolve(l-1),B=m.blockRange(g);t&&e.tr.lift(B,u-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(a,a+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:d,startPos:s,endPos:a,depth:l}=r,u=t.doc.cut(s+1,n),h=t.doc.cut(n,a-1),k=t.schema.nodes.blockContainer.createAndFill(),m=a+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(d).type,i.attrs),t.tr.setSelection(new y.TextSelection(t.doc.resolve(g))),t.tr.replace(s+1,a-1,u.content.size>0?new v.Slice(v.Fragment.from(u),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,d=r.name==="paragraph";return i&&!d?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),d=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,a=i===2,l=i-1;return!a&&d&&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),d=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,a=r.textContent.length===0,l=i>2;return d&&s&&a&&l?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:o,chain:r})=>{const{node:i,endPos:d}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,a=o.selection.anchor===o.selection.head,l=i.textContent.length===0;if(s&&a&&l){const u=d+1,h=u+2;return r().BNCreateBlock(u).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=c.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",c.mergeAttributes(this.options.HTMLAttributes,n,{class:x.blockGroup,"data-node-type":"blockGroup"}),0]}}),et=c.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"blockContainer"}]},renderHTML({HTMLAttributes:n}){return["div",c.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),tt=c.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 c.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:"blockContainer"},{tag:"h2",attrs:{level:"2"},node:"blockContainer"},{tag:"h3",attrs:{level:"3"},node:"blockContainer"}]},renderHTML({node:n,HTMLAttributes:e}){return["div",c.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:d})=>[()=>d.command(()=>e.textContent.length===0?d.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>d.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},nt=c.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new c.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:"blockContainer"},{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:"blockContainer"}]},renderHTML({HTMLAttributes:n}){return["div",c.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,d)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let s="1";const a=d===1,l=b(o.doc,d+1);if(l===void 0)return;if(!a){const k=b(o.doc,d-2);if(k===void 0)return;if(!(l.depth!==k.depth)){const g=k.contentNode;if(k.contentType.name==="numberedListItem"){const U=g.attrs.index;s=(parseInt(U)+1).toString()}}}l.contentNode.attrs.index!==s&&(r=!0,o.setNodeMarkup(d+1,void 0,{index:s}))}}),r?o:null}}),it=c.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 c.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:"blockContainer"},{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:"blockContainer"}]},renderHTML({HTMLAttributes:n}){return["div",c.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),st=[et,tt,nt,it,Qe,Ze,c.Node.create({name:"doc",topNode:!0,content:"blockGroup"})],R={bnEditor:"_bnEditor_yxlqg_3",bnRoot:"_bnRoot_yxlqg_14",dragPreview:"_dragPreview_yxlqg_29"},at=c.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,d=o.active&&!r.active,s=o.active&&r.active;!i&&!s&&!d||(this.pluginState=d?o:r,d&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",a=>a.preventDefault())),s&&this.suggestionsMenu.render(this.getDynamicParams(),!1),i&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",a=>a.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 d=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:a=>{d(s),r(a)},suggestionsMenuFactory:o}),state:{init(){return z()},apply(s,a,l,u){var k,m,g,B;if(s.getMeta("orderedListIndexing")!==void 0)return a;if((k=s.getMeta(n))!=null&&k.activate)return{active:!0,triggerCharacter:((m=s.getMeta(n))==null?void 0:m.triggerCharacter)||"",queryStartPos:u.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!a.active)return a;const h={...a};if(h.items=i(u.doc.textBetween(a.queryStartPos,u.selection.from)),h.notFoundCount=0,h.items.length===0&&(h.notFoundCount=Math.max(0,a.notFoundCount+(u.selection.from-l.selection.from))),u.selection.from!==u.selection.to||(g=s.getMeta(n))!=null&&g.deactivate||s.getMeta("focus")||s.getMeta("blur")||s.getMeta("pointer")||a.active&&u.selection.from<a.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=a.items.length-1:C>=a.items.length&&(C=0),h.keyboardHoveredItemIndex=C}return h}},props:{handleKeyDown(s,a){const l=this.getState(s.state).active;if(a.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:u,queryStartPos:h,items:k,keyboardHoveredItemIndex:m}=n.getState(s.state);return a.key==="ArrowUp"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m-1})),!0):a.key==="ArrowDown"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m+1})),!0):a.key==="Enter"?(d(s),e._tiptapEditor.chain().focus().deleteRange({from:h-u.length,to:e._tiptapEditor.state.selection.from}).run(),r({item:k[m],editor:e}),!0):a.key==="Escape"?(d(s),!0):!1},handleClick(s){d(s)},decorations(s){const{active:a,decorationId:l,queryStartPos:u,triggerCharacter:h}=this.getState(s);if(!a)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(u-h.length,u,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}}})}const q=new y.PluginKey("suggestions-slash-commands"),ct=c.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:q,editor:this.options.editor,defaultTriggerCharacter:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:e=>n.filter(t=>t.match(e)),onSelectItem:({item:e,editor:t})=>{e.execute(t)}})]}});class N extends 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,d,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=Le.__serializeForClipboard;let w;function ie(n,e){var r;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",d=Math.min(n.$anchor.depth,n.$head.depth);if(r&&i){const s=n.$from.start(d-1),a=n.$to.end(d-1);t=e.resolve(s-1).pos,o=e.resolve(a+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=(a,l)=>Array.prototype.indexOf.call(a.children,l),d=i(r,n.domAtPos(e+1).node.parentElement),s=i(r,n.domAtPos(t-1).node.parentElement);for(let a=r.childElementCount-1;a>=0;a--)(a>s||a<d)&&o.removeChild(o.children[a]);ae(),w=o,w.className=w.className+" "+R.dragPreview,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,d=e.state.doc,{from:s,to:a}=pt(i,d),l=s<=r&&r<a,u=!i.$anchor.node().eq(i.$head.node());l&&u?(e.dispatch(e.state.tr.setSelection(N.create(d,s,a))),se(e,s,a)):(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 d,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&&((d=this.hoveredBlockContent)!=null&&d.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 d=i+1,s=d+2;this.editor.chain().BNCreateBlock(d).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(q,{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=c.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:d}=t,{empty:s}=d,a=!i.textBetween(o,r).length&&c.isTextSelection(t.selection);return!(!e.hasFocus()||s||a)});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:d}=o,s=t&&t.doc.eq(i)&&t.selection.eq(d);if(r||s)return;const{ranges:a}=d,l=Math.min(...a.map(m=>m.$from.pos)),u=Math.max(...a.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:u});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(d=>d.$from.pos)),i=Math.max(...o.map(d=>d.$to.pos));if(c.isNodeSelection(t)){const d=this.editor.view.nodeDOM(r);if(d)return d.getBoundingClientRect()}return c.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=c.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,d=e.state.doc.resolve(i),s=d.marks();for(const a of s)if(a.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=a,this.mouseHoveredHyperlinkMarkRange=c.getMarkRange(d,a.type,a.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 d=this.editor.state.selection.$from.marks();for(const s of d)if(s.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=s,this.keyboardHoveredHyperlinkMarkRange=c.getMarkRange(this.editor.state.selection.$from,s.type,s.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(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:c.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=$.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=c.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=q.getState(n),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,d=[];if(r)return e.descendants((s,a)=>{const l=i>=a&&i<=a+s.nodeSize,u=!s.isLeaf&&!s.childCount;if((l||!this.options.showOnlyCurrent)&&u){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(a,a+s.nodeSize,{class:h.join(" ")});d.push(k)}return this.options.includeChildren}),T.DecorationSet.create(e,d)}}})]}});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=c.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=c.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=c.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=c.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:d}=o,s=n.getState(o),a=r.content.size-2,l=d.nodes.blockContainer,u=d.nodes.paragraph;if(s)return i.insert(a,l.create(void 0,u.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=[c.extensions.ClipboardTextSerializer,c.extensions.Commands,c.extensions.Editable,c.extensions.FocusEvents,c.extensions.Tabindex,Be.Gapcursor,Mt.configure({emptyNodeClass:x.isEmpty,hasAnchorClass:x.hasAnchor,isFilterClass:x.isFilter,includeChildren:!0,showOnlyCurrent:!1}),D.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($.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 Ht{constructor(e={}){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);var i,d,s;const t=le({editor:this,uiFactories:e.uiFactories||{},slashCommands:e.slashCommands||de});let o=e.disableHistoryExtension?t.filter(a=>a.name!=="history"):t;const r={...Nt,...e._tiptapOptions,onCreate:()=>{var a;(a=e.onEditorCreate)==null||a.call(e,this)},onUpdate:()=>{var a;(a=e.onEditorContentChange)==null||a.call(e,this)},onSelectionUpdate:()=>{var a;(a=e.onTextCursorPositionChange)==null||a.call(e,this)},extensions:e.enableBlockNoteExtensions===!1?(i=e._tiptapOptions)==null?void 0:i.extensions:[...((d=e._tiptapOptions)==null?void 0:d.extensions)||[],...o],editorProps:{attributes:{...e.editorDOMAttributes||{},class:[R.bnEditor,R.bnRoot,((s=e.editorDOMAttributes)==null?void 0:s.class)||""].join(" ")}}};e.parentElement&&(r.element=e.parentElement),this._tiptapEditor=new c.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){function o(r){if(t)for(const i of r.reverse())o(i.children),e(i);else for(const i of r)e(i),o(i.children)}o(this.topLevelBlocks)}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),d=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let s;i>0&&(s=this._tiptapEditor.state.doc.resolve(o-2).node());let a;return i<d-1&&(a=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:I(e,this.blockCache),prevBlock:s===void 0?void 0:I(s,this.blockCache),nextBlock:a===void 0?void 0:I(a,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:r}=F(o,this._tiptapEditor.state.doc),{startPos:i,contentNode:d}=b(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+d.nodeSize-1)}insertBlocks(e,t,o="before"){Z(e,t,o,this._tiptapEditor)}updateBlock(e,t){qe(e,t,this._tiptapEditor)}removeBlocks(e){ee(e,this._tiptapEditor)}replaceBlocks(e,t){Ue(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 $e(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return Ke(e,this._tiptapEditor.schema)}}f.BaseSlashMenuItem=P,f.BlockNoteEditor=Ht,f.blockProps=O,f.defaultSlashMenuItems=de,f.getBlockNoteExtensions=le,f.globalProps=S,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(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,c,v,y,ue,he,pe,fe,me,ke,ge,ye,_,j,be,ve,Ce,Be,xe,Te,we,$,Me,Ee,Ie,T){"use strict";var _t=Object.defineProperty;var Ot=(f,c,v)=>c in f?_t(f,c,{enumerable:!0,configurable:!0,writable:!0,value:v}):f[c]=v;var p=(f,c,v)=>(Ot(f,typeof c!="symbol"?c+"":c,v),v);const E=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Pe(n){if(n&&typeof n=="object"&&"default"in n)return n;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const K=E(he),Ae=E(pe),Y=E(fe),W=E(me),Se=E(ke),Ne=E(ge),Le=E(ye),He=Pe(T),S=["backgroundColor","textColor","textAlignment"],O={paragraph:new Set([...S]),heading:new Set([...S,"level"]),numberedListItem:new Set([...S]),bulletListItem:new Set([...S])};function b(n,e){if(e<0||e>n.nodeSize)return;const t=n.resolve(e),o=t.depth;let r=t.node(o),i=o;for(;;){if(i<0)return;if(r.type.name==="blockContainer")break;i-=1,r=t.node(i)}const d=r.attrs.id,s=r.firstChild,a=s.type,l=r.childCount===2?r.lastChild.childCount:0,u=t.start(i),h=t.end(i);return{id:d,node:r,contentNode:s,contentType:a,numChildBlocks:l,startPos:u,endPos:h,depth:i}}function _e(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Oe(n){const e=n.filter((o,r)=>n.indexOf(o)!==r);return _e(e)}const D=c.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>window.__TEST_OPTIONS?(window.__TEST_OPTIONS.mockID===void 0?window.__TEST_OPTIONS.mockID=0:window.__TEST_OPTIONS.mockID++,parseInt(window.__TEST_OPTIONS.mockID)):ue.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(a=>a.name==="collaboration"))return;const{view:n,state:e}=this.editor,{tr:t,doc:o}=e,{types:r,attributeName:i,generateID:d}=this.options;c.findChildren(o,a=>r.includes(a.type.name)&&a.attrs[i]===null).forEach(({node:a,pos:l})=>{t.setNodeMarkup(l,void 0,{...a.attrs,[i]:d()})}),t.setMeta("addToHistory",!1),n.dispatch(t)},addProseMirrorPlugins(){let n=null,e=!1;return[new y.Plugin({key:new y.PluginKey("uniqueID"),appendTransaction:(t,o,r)=>{const i=t.some(g=>g.docChanged)&&!o.doc.eq(r.doc),d=this.options.filterTransaction&&t.some(g=>{var B,C;return!(!((C=(B=this.options).filterTransaction)===null||C===void 0)&&C.call(B,g))});if(!i||d)return;const{tr:s}=r,{types:a,attributeName:l,generateID:u}=this.options,h=c.combineTransactionSteps(o.doc,t),{mapping:k}=h;if(c.getChangedRanges(h).forEach(({newRange:g})=>{const B=c.findChildrenInRange(r.doc,g,M=>a.includes(M.type.name)),C=B.map(({node:M})=>M.attrs[l]).filter(M=>M!==null),U=Oe(C);B.forEach(({node:M,pos:H})=>{var G;const ce=(G=s.doc.nodeAt(H))===null||G===void 0?void 0:G.attrs[l];if(ce===null){s.setNodeMarkup(H,void 0,{...M.attrs,[l]:u()});return}const{deleted:Ht}=k.invert().mapResult(H);Ht&&U.includes(ce)&&s.setNodeMarkup(H,void 0,{...M.attrs,[l]:u()})})}),!!s.steps.length)return s},view(t){const o=r=>{var i;n=!((i=t.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{var r;return(n!==t.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(n=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:o,attributeName:r}=this.options,i=d=>{const s=[];return d.forEach(a=>{if(a.isText){s.push(a);return}if(!o.includes(a.type.name)){s.push(a.copy(i(a.content)));return}const l=a.type.create({...a.attrs,[r]:null},i(a.content),a.marks);s.push(l)}),v.Fragment.from(s)};return e=!1,new v.Slice(i(t.content),t.openStart,t.openEnd)}}})]}});class De extends Error{constructor(e){super(`Unreachable case: ${e}`)}}const V=new Set(["bold","italic","underline","strike"]),J=new Set(["textColor","backgroundColor"]);function Fe(n,e){const t=[];for(const[o,r]of Object.entries(n.styles))V.has(o)?t.push(e.mark(o)):J.has(o)&&t.push(e.mark(o,{color:r}));return e.text(n.text,t)}function Re(n,e){const t=e.marks.link.create({href:n.href});return X(n.content,e).map(o=>o.mark([...o.marks,t]))}function X(n,e){let t=[];if(typeof n=="string")return t.push(e.text(n)),t;for(const o of n)t.push(Fe(o,e));return t}function Q(n,e){let t=[];for(const o of n)if(o.type==="link")t.push(...Re(o,e));else if(o.type==="text")t.push(...X([o],e));else throw new De(o);return t}function L(n,e){let t=n.id;t===void 0&&(t=D.options.generateID());let o=n.type;o===void 0&&(o="paragraph");let r;if(!n.content)r=e.nodes[o].create(n.props);else if(typeof n.content=="string")r=e.nodes[o].create(n.props,e.text(n.content));else{const s=Q(n.content,e);r=e.nodes[o].create(n.props,s)}const i=[];if(n.children)for(const s of n.children)i.push(L(s,e));const d=e.nodes.blockGroup.create({},i);return e.nodes.blockContainer.create({id:t,...n.props},i.length>0?[r,d]:r)}function ze(n){const e=[];let t;return n.content.forEach(o=>{const r={};let i;for(const d of o.marks)if(d.type.name==="link")i=d;else if(V.has(d.type.name))r[d.type.name]=!0;else if(J.has(d.type.name))r[d.type.name]=d.attrs.color;else throw Error("Mark is of an unrecognized type: "+d.type.name);i&&t&&i.attrs.href===t.href?t.content.push({type:"text",text:o.textContent,styles:r}):i?(t={type:"link",href:i.attrs.href,content:[{type:"text",text:o.textContent,styles:r}]},e.push(t)):(e.push({type:"text",text:o.textContent,styles:r}),t=void 0)}),e}function I(n,e){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const t=e==null?void 0:e.get(n);if(t)return t;const o=b(n,0);let r=o.id;r===null&&(r=D.options.generateID());const i={};for(const[l,u]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]=u)}const d=ze(o.contentNode),s=[];for(let l=0;l<o.numChildBlocks;l++)s.push(I(o.node.lastChild.child(l)));const a={id:r,type:o.contentType.name,props:i,content:d,children:s};return e==null||e.set(n,a),a}function F(n,e){let t,o;if(e.firstChild.descendants((r,i)=>t?!1:r.type.name!=="blockContainer"||r.attrs.id!==n?!0:(t=r,o=i+1,!1)),t===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:o}}function Z(n,e,t="before",o){const r=typeof e=="string"?e:e.id,i=[];for(const l of n)i.push(L(l,o.schema));let d=-1;const{node:s,posBeforeNode:a}=F(r,o.state.doc);if(t==="before"&&(d=a),t==="after"&&(d=a+s.nodeSize),t==="nested"){if(s.childCount<2){d=a+s.firstChild.nodeSize+1;const l=o.state.schema.nodes.blockGroup.create({},i);o.view.dispatch(o.state.tr.insert(d,l));return}d=a+s.firstChild.nodeSize+2}o.view.dispatch(o.state.tr.insert(d,i))}function qe(n,e,t){const o=typeof n=="string"?n:n.id,{posBeforeNode:r}=F(o,t.state.doc);t.commands.BNUpdateBlock(r+1,e)}function ee(n,e){const t=new Set(n.map(r=>typeof r=="string"?r:r.id));let o=0;if(e.state.doc.descendants((r,i)=>{if(t.size===0)return!1;if(r.type.name!=="blockContainer"||!t.has(r.attrs.id))return!0;t.delete(r.attrs.id);const d=e.state.doc.nodeSize;e.commands.BNDeleteBlock(i-o+1);const s=e.state.doc.nodeSize;return o+=d-s,!1}),t.size>0){let r=[...t].join(`
2
+ `);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function Ue(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 je(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{let r=o.children.length,i;for(let d=0;d<r;d++){const a=o.children[d].children[0],l=a.children[0],u=a.children.length===2?a.children[1]:null,h=e.has(l.properties.dataContentType),k=h?n.orderedListItemBlockTypes.has(l.properties.dataContentType)?"ol":"ul":null;if(u!==null&&t(u),i&&i.tagName!==k){o.children.splice(d-i.children.length,i.children.length,i);const m=i.children.length-1;d-=m,r-=m,i=void 0}if(h){i||(i=j.fromDom(document.createElement(k)));const m=j.fromDom(document.createElement("li"));m.children.push(l.children[0]),u!==null&&m.children.push(...u.children),i.children.push(m)}else if(u!==null){o.children.splice(d+1,0,...u.children),o.children[d]=l.children[0];const m=u.children.length;d+=m,r+=m}else o.children[d]=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 d=L(i,e),s=o.serializeNode(d);t.appendChild(s)}return(await _.unified().use(K.default,{fragment:!0}).use(je,{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 d=0;d<r.firstChild.childCount;d++)i.push(I(r.firstChild.child(d)));return i}async function $e(n,e){return(await _.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 _.unified().use(Se.default).use(W.default).use(Ne.default).use(Y.default).process(n);return ne(t.value,e)}const Ye=c.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=c.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={},d=c.findChildren(o.doc,l=>l.attrs.id),s=new Map(d.map(l=>[l.node.attrs.id,l])),a=c.findChildren(r.doc,l=>l.attrs.id);for(let l of a){const u=s.get(l.node.attrs.id),h=u==null?void 0:u.node.firstChild,k=l.node.firstChild;if(u&&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(u.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 d=t.currentTransactionOldBlockAttrs[r.attrs.id],s={};for(let[l,u]of Object.entries(d))s["data-prev-"+Ve[l]]=u||"none";const a=T.Decoration.node(i,i+r.nodeSize,{...s});o.push(a)}),T.DecorationSet.create(e.doc,o)}}})},x={blockOuter:"_blockOuter_qwsjj_5",block:"_block_qwsjj_5",blockContent:"_blockContent_qwsjj_19",blockGroup:"_blockGroup_qwsjj_48",isEmpty:"_isEmpty_qwsjj_237",isFilter:"_isFilter_qwsjj_238",hasAnchor:"_hasAnchor_qwsjj_251"},Xe={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Qe=c.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",c.mergeAttributes(n,{class:x.blockOuter,"data-node-type":"block-outer"}),["div",c.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:d,node:s,contentNode:a}=r;if(o){if(e.children!==void 0){const l=[];for(const u of e.children)l.push(L(u,t.schema));s.childCount===2?t.tr.replace(i+a.nodeSize+1,d-1,new v.Slice(v.Fragment.from(l),0,0)):t.tr.insert(i+a.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+a.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],{...a.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:d,contentNode:s,startPos:a,endPos:l,depth:u}=i;if(d.childCount===2){const m=e.doc.resolve(a+s.nodeSize+1),g=e.doc.resolve(l-1),B=m.blockRange(g);t&&e.tr.lift(B,u-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(a,a+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:d,startPos:s,endPos:a,depth:l}=r,u=t.doc.cut(s+1,n),h=t.doc.cut(n,a-1),k=t.schema.nodes.blockContainer.createAndFill(),m=a+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(d).type,i.attrs),t.tr.setSelection(new y.TextSelection(t.doc.resolve(g))),t.tr.replace(s+1,a-1,u.content.size>0?new v.Slice(v.Fragment.from(u),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,d=r.name==="paragraph";return i&&!d?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),d=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,a=i===2,l=i-1;return!a&&d&&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),d=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,a=r.textContent.length===0,l=i>2;return d&&s&&a&&l?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:o,chain:r})=>{const{node:i,endPos:d}=b(o.doc,o.selection.from),s=o.selection.$anchor.parentOffset===0,a=o.selection.anchor===o.selection.head,l=i.textContent.length===0;if(s&&a&&l){const u=d+1,h=u+2;return r().BNCreateBlock(u).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=c.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",c.mergeAttributes(this.options.HTMLAttributes,n,{class:x.blockGroup,"data-node-type":"blockGroup"}),0]}}),et=c.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){return["div",c.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),tt=c.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 c.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",c.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:d})=>[()=>d.command(()=>e.textContent.length===0?d.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>d.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},nt=c.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new c.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",c.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,d)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let s="1";const a=d===1,l=b(o.doc,d+1);if(l===void 0)return;if(!a){const k=b(o.doc,d-2);if(k===void 0)return;if(!(l.depth!==k.depth)){const g=k.contentNode;if(k.contentType.name==="numberedListItem"){const U=g.attrs.index;s=(parseInt(U)+1).toString()}}}l.contentNode.attrs.index!==s&&(r=!0,o.setNodeMarkup(d+1,void 0,{index:s}))}}),r?o:null}}),it=c.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 c.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",c.mergeAttributes(n,{class:x.blockContent,"data-content-type":this.name}),["p",0]]}}),st=[et,tt,nt,it,Qe,Ze,c.Node.create({name:"doc",topNode:!0,content:"blockGroup"})],R={bnEditor:"_bnEditor_yxlqg_3",bnRoot:"_bnRoot_yxlqg_14",dragPreview:"_dragPreview_yxlqg_29"},at=c.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,d=o.active&&!r.active,s=o.active&&r.active;!i&&!s&&!d||(this.pluginState=d?o:r,d&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",a=>a.preventDefault())),s&&this.suggestionsMenu.render(this.getDynamicParams(),!1),i&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",a=>a.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 d=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:a=>{d(s),r(a)},suggestionsMenuFactory:o}),state:{init(){return z()},apply(s,a,l,u){var k,m,g,B;if(s.getMeta("orderedListIndexing")!==void 0)return a;if((k=s.getMeta(n))!=null&&k.activate)return{active:!0,triggerCharacter:((m=s.getMeta(n))==null?void 0:m.triggerCharacter)||"",queryStartPos:u.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!a.active)return a;const h={...a};if(h.items=i(u.doc.textBetween(a.queryStartPos,u.selection.from)),h.notFoundCount=0,h.items.length===0&&(h.notFoundCount=Math.max(0,a.notFoundCount+(u.selection.from-l.selection.from))),u.selection.from!==u.selection.to||(g=s.getMeta(n))!=null&&g.deactivate||s.getMeta("focus")||s.getMeta("blur")||s.getMeta("pointer")||a.active&&u.selection.from<a.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=a.items.length-1:C>=a.items.length&&(C=0),h.keyboardHoveredItemIndex=C}return h}},props:{handleKeyDown(s,a){const l=this.getState(s.state).active;if(a.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:u,queryStartPos:h,items:k,keyboardHoveredItemIndex:m}=n.getState(s.state);return a.key==="ArrowUp"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m-1})),!0):a.key==="ArrowDown"?(s.dispatch(s.state.tr.setMeta(n,{selectedItemIndexChanged:m+1})),!0):a.key==="Enter"?(d(s),e._tiptapEditor.chain().focus().deleteRange({from:h-u.length,to:e._tiptapEditor.state.selection.from}).run(),r({item:k[m],editor:e}),!0):a.key==="Escape"?(d(s),!0):!1},handleClick(s){d(s)},decorations(s){const{active:a,decorationId:l,queryStartPos:u,triggerCharacter:h}=this.getState(s);if(!a)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(u-h.length,u,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":l})])}}})}const q=new y.PluginKey("suggestions-slash-commands"),ct=c.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:q,editor:this.options.editor,defaultTriggerCharacter:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:e=>n.filter(t=>t.match(e)),onSelectItem:({item:e,editor:t})=>{e.execute(t)}})]}});class N extends 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,d,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",d=Math.min(n.$anchor.depth,n.$head.depth);if(r&&i){const s=n.$from.start(d-1),a=n.$to.end(d-1);t=e.resolve(s-1).pos,o=e.resolve(a+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=(a,l)=>Array.prototype.indexOf.call(a.children,l),d=i(r,n.domAtPos(e+1).node.parentElement),s=i(r,n.domAtPos(t-1).node.parentElement);for(let a=r.childElementCount-1;a>=0;a--)(a>s||a<d)&&o.removeChild(o.children[a]);ae(),w=o,w.className=w.className+" "+R.dragPreview,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,d=e.state.doc,{from:s,to:a}=pt(i,d),l=s<=r&&r<a,u=!i.$anchor.node().eq(i.$head.node());l&&u?(e.dispatch(e.state.tr.setSelection(N.create(d,s,a))),se(e,s,a)):(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 d,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&&((d=this.hoveredBlockContent)!=null&&d.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 d=i+1,s=d+2;this.editor.chain().BNCreateBlock(d).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(q,{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=c.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:d}=t,{empty:s}=d,a=!i.textBetween(o,r).length&&c.isTextSelection(t.selection);return!(!e.hasFocus()||s||a)});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:d}=o,s=t&&t.doc.eq(i)&&t.selection.eq(d);if(r||s)return;const{ranges:a}=d,l=Math.min(...a.map(m=>m.$from.pos)),u=Math.max(...a.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:u});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(d=>d.$from.pos)),i=Math.max(...o.map(d=>d.$to.pos));if(c.isNodeSelection(t)){const d=this.editor.view.nodeDOM(r);if(d)return d.getBoundingClientRect()}return c.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=c.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,d=e.state.doc.resolve(i),s=d.marks();for(const a of s)if(a.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=a,this.mouseHoveredHyperlinkMarkRange=c.getMarkRange(d,a.type,a.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 d=this.editor.state.selection.$from.marks();for(const s of d)if(s.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=s,this.keyboardHoveredHyperlinkMarkRange=c.getMarkRange(this.editor.state.selection.$from,s.type,s.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(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:c.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=$.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=c.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=q.getState(n),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,d=[];if(r)return e.descendants((s,a)=>{const l=i>=a&&i<=a+s.nodeSize,u=!s.isLeaf&&!s.childCount;if((l||!this.options.showOnlyCurrent)&&u){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(a,a+s.nodeSize,{class:h.join(" ")});d.push(k)}return this.options.includeChildren}),T.DecorationSet.create(e,d)}}})]}});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=c.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=c.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=c.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=c.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:d}=o,s=n.getState(o),a=r.content.size-2,l=d.nodes.blockContainer,u=d.nodes.paragraph;if(s)return i.insert(a,l.create(void 0,u.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=[c.extensions.ClipboardTextSerializer,c.extensions.Commands,c.extensions.Editable,c.extensions.FocusEvents,c.extensions.Tabindex,Be.Gapcursor,Mt.configure({emptyNodeClass:x.isEmpty,hasAnchorClass:x.hasAnchor,isFilterClass:x.isFilter,includeChildren:!0,showOnlyCurrent:!1}),D.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($.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,d,s;const t=le({editor:this,uiFactories:e.uiFactories||{},slashCommands:e.slashCommands||de});let o=e.disableHistoryExtension?t.filter(a=>a.name!=="history"):t;const r={...Nt,...e._tiptapOptions,onCreate:()=>{var a;(a=e.onEditorReady)==null||a.call(e,this)},onUpdate:()=>{var a;(a=e.onEditorContentChange)==null||a.call(e,this)},onSelectionUpdate:()=>{var a;(a=e.onTextCursorPositionChange)==null||a.call(e,this)},extensions:e.enableBlockNoteExtensions===!1?(i=e._tiptapOptions)==null?void 0:i.extensions:[...((d=e._tiptapOptions)==null?void 0:d.extensions)||[],...o],editorProps:{attributes:{...e.editorDOMAttributes||{},class:[R.bnEditor,R.bnRoot,((s=e.editorDOMAttributes)==null?void 0:s.class)||""].join(" ")}}};e.parentElement&&(r.element=e.parentElement),this._tiptapEditor=new c.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){function o(r){if(t)for(const i of r.reverse())o(i.children),e(i);else for(const i of r)e(i),o(i.children)}o(this.topLevelBlocks)}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),d=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let s;i>0&&(s=this._tiptapEditor.state.doc.resolve(o-2).node());let a;return i<d-1&&(a=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:I(e,this.blockCache),prevBlock:s===void 0?void 0:I(s,this.blockCache),nextBlock:a===void 0?void 0:I(a,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:r}=F(o,this._tiptapEditor.state.doc),{startPos:i,contentNode:d}=b(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+d.nodeSize-1)}insertBlocks(e,t,o="before"){Z(e,t,o,this._tiptapEditor)}updateBlock(e,t){qe(e,t,this._tiptapEditor)}removeBlocks(e){ee(e,this._tiptapEditor)}replaceBlocks(e,t){Ue(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 $e(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return Ke(e,this._tiptapEditor.schema)}}f.BaseSlashMenuItem=P,f.BlockNoteEditor=Lt,f.blockProps=O,f.defaultSlashMenuItems=de,f.getBlockNoteExtensions=le,f.globalProps=S,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
3
3
  //# sourceMappingURL=blocknote.umd.cjs.map