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