@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
52 lines • 54.9 kB
JavaScript
const e=require("./blocks-BqHv0xhc.cjs"),t=require("./BlockNoteExtension-M0znTzxP.cjs"),n=require("./UserStore-DCG6lsla.cjs");let r=require("prosemirror-model"),i=require("prosemirror-transform"),a=require("@tiptap/core"),o=require("lib0/random"),s=require("prosemirror-state"),c=require("@tiptap/pm/model"),l=require("prosemirror-tables"),u=require("@tiptap/pm/state"),d=require("prosemirror-view"),f=require("fast-deep-equal");f=e.tr(f,1);let p=require("@tiptap/pm/history");function m(e){let t=Array.from(e.classList).filter(e=>!e.startsWith(`bn-`))||[];t.length>0?e.className=t.join(` `):e.removeAttribute(`class`)}function h(t,n,i,a){let o;if(!n)throw Error(`blockContent is required`);if(typeof n==`string`)o=e.Mt([n],t.pmSchema,a?.blockType);else if(Array.isArray(n))o=e.Mt(n,t.pmSchema,a?.blockType);else if(n.type===`tableContent`)o=e.Nt(n,t.pmSchema);else throw new e.In(n.type);let s=(a?.document??document).createDocumentFragment();for(let n of o)if(n.type.name!==`text`&&t.schema.inlineContentSchema[n.type.name]){let r=t.schema.inlineContentSpecs[n.type.name].implementation;if(r){let o=e.bn(n,t.schema.inlineContentSchema,t.schema.styleSchema),c=r.toExternalHTML?r.toExternalHTML(o,t):r.render.call({renderType:`dom`,props:void 0},o,()=>{},t);if(c){if(s.appendChild(c.dom),c.contentDOM){let e=i.serializeFragment(n.content,a);c.contentDOM.dataset.editable=``,c.contentDOM.appendChild(e)}continue}}}else if(n.type.name===`text`){let e=document.createTextNode(n.textContent);for(let i of n.marks.toReversed())if(i.type.name in t.schema.styleSpecs){let n=(t.schema.styleSpecs[i.type.name].implementation.toExternalHTML??t.schema.styleSpecs[i.type.name].implementation.render)(i.attrs.stringValue,t);n.contentDOM.appendChild(e),e=n.dom}else{let t=i.type.spec.toDOM(i,!0),n=r.DOMSerializer.renderSpec(document,t);n.contentDOM.appendChild(e),e=n.dom}s.appendChild(e)}else{let e=i.serializeFragment(r.Fragment.from([n]),a);s.appendChild(e)}return s.childNodes.length===1&&s.firstChild?.nodeType===1&&m(s.firstChild),s}function g(e,t,n,r,i,a,o,s){let c=s?.document??document,l=t.pmSchema.nodes.blockContainer,u=n.props||{};for(let[e,r]of Object.entries(t.schema.blockSchema[n.type].propSchema))!(e in u)&&r.default!==void 0&&(u[e]=r.default);let d=l.spec?.toDOM?.(l.create({id:n.id,...u})),f=Array.from(d.dom.attributes),p=t.blockImplementations[n.type].implementation,g=p.toExternalHTML?.call({},{...n,props:u},t,{nestingLevel:o})||p.render.call({},{...n,props:u},t),v=c.createDocumentFragment();if(g.dom.classList.contains(`bn-block-content`)){let e=[...f,...Array.from(g.dom.attributes)].filter(e=>e.name.startsWith(`data`)&&e.name!==`data-content-type`&&e.name!==`data-file-block`&&e.name!==`data-node-view-wrapper`&&e.name!==`data-node-type`&&e.name!==`data-id`&&e.name!==`data-editable`);for(let t of e)g.dom.firstChild.setAttribute(t.name,t.value);m(g.dom.firstChild),o>0&&g.dom.firstChild.setAttribute(`data-nesting-level`,o.toString()),v.append(...Array.from(g.dom.childNodes))}else v.append(g.dom),o>0&&g.dom.setAttribute(`data-nesting-level`,o.toString());if(g.contentDOM&&n.content){let e=h(t,n.content,r,{...s,blockType:n.type});g.contentDOM.appendChild(e)}let y;if(i.has(n.type)?y=`OL`:a.has(n.type)&&(y=`UL`),y){if(e.lastChild?.nodeName!==y){let t=c.createElement(y);y===`OL`&&`start`in u&&u.start&&u?.start!==1&&t.setAttribute(`start`,String(u.start)),e.append(t)}e.lastChild.appendChild(v)}else e.append(v);if(n.children&&n.children.length>0){let l=c.createDocumentFragment();if(_(l,t,n.children,r,i,a,o+1,s),e.lastChild?.nodeName===`UL`||e.lastChild?.nodeName===`OL`)for(;l.firstChild?.nodeName===`UL`||l.firstChild?.nodeName===`OL`;)e.lastChild.lastChild.appendChild(l.firstChild);`childrenDOM`in g&&g.childrenDOM?g.childrenDOM.append(l):t.pmSchema.nodes[n.type].isInGroup(`blockContent`)?e.append(l):g.contentDOM?.append(l)}}var _=(e,t,n,r,i,a,o=0,s)=>{for(let c of n)g(e,t,c,r,i,a,o,s)},v=(e,t,n,r,i,a)=>{let o=(a?.document??document).createDocumentFragment();return _(o,e,t,n,r,i,0,a),o},y=(e,t)=>{let n=r.DOMSerializer.fromSchema(e);return{exportBlocks:(e,r)=>{let i=v(t,e,n,new Set([`numberedListItem`]),new Set([`bulletListItem`,`checkListItem`,`toggleListItem`]),r),a=document.createElement(`div`);return a.append(i),a.innerHTML},exportInlineContent:(e,r)=>{let i=h(t,e,n,r),a=document.createElement(`div`);return a.append(i.cloneNode(!0)),a.innerHTML}}};function ee(t,n){if(n===0)return;let r=t.resolve(n);for(let n=r.depth;n>0;n--){let i=r.node(n);if(e.At(i))return e.$n(i,t)}}function te(e){return e.getMeta(`paste`)?{type:`paste`}:e.getMeta(`uiEvent`)===`drop`?{type:`drop`}:e.getMeta(`history$`)?{type:e.getMeta(`history$`).redo?`redo`:`undo`}:e.getMeta(`y-sync$`)?e.getMeta(`y-sync$`).isUndoRedoOperation?{type:`undo-redo`}:{type:`yjs-remote`}:{type:`local`}}function b(t){let n={},r={};return t.descendants((i,a)=>{if(!e.At(i))return!0;let o=ee(t,a),s=o??`__root__`;r[s]||(r[s]=[]);let c=e.yn(i,t),l=e.$n(i,t);return n[l]={block:c,parentId:o},r[s].push(l),!0}),{byId:n,childrenByParent:r}}function ne(e,t){let n=new Set;if(!e||!t)return n;let r=new Set(e),i=t.filter(e=>r.has(e)),a=e.filter(e=>i.includes(e));if(a.length<=1||i.length<=1)return n;let o={};for(let e=0;e<a.length;e++)o[a[e]]=e;let s=i.map(e=>o[e]),c=s.length,l=[],u=[],d=Array(c).fill(-1),f=(e,t)=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i]<t?n=i+1:r=i}return n};for(let e=0;e<c;e++){let t=s[e],n=f(l,t);n>0&&(d[e]=u[n-1]),n===l.length?(l.push(t),u.push(e)):(l[n]=t,u[n]=e)}let p=new Set,m=u[u.length-1]??-1;for(;m!==-1;)p.add(m),m=d[m];for(let e=0;e<i.length;e++)p.has(e)||n.add(i[e]);return n}function x(e,t=[]){let n=te(e),r=(0,a.combineTransactionSteps)(e.before,[e,...t]),i=b(r.before),o=b(r.doc),s=[],c=new Set;Object.keys(o.byId).filter(e=>!(e in i.byId)).forEach(e=>{s.push({type:`insert`,block:o.byId[e].block,source:n,prevBlock:void 0}),c.add(e)}),Object.keys(i.byId).filter(e=>!(e in o.byId)).forEach(e=>{s.push({type:`delete`,block:i.byId[e].block,source:n,prevBlock:void 0}),c.add(e)}),Object.keys(o.byId).filter(e=>e in i.byId).forEach(e=>{let t=i.byId[e],r=o.byId[e];t.parentId===r.parentId?(0,f.default)({...t.block,children:void 0},{...r.block,children:void 0})||(s.push({type:`update`,block:r.block,prevBlock:t.block,source:n}),c.add(e)):(s.push({type:`move`,block:r.block,prevBlock:t.block,source:n,prevParent:t.parentId?i.byId[t.parentId]?.block:void 0,currentParent:r.parentId?o.byId[r.parentId]?.block:void 0}),c.add(e))});let l=i.childrenByParent,u=o.childrenByParent,d=new Set([...Object.keys(l),...Object.keys(u)]),p=new Set;return d.forEach(e=>{let t=ne(l[e],u[e]);t.size!==0&&t.forEach(t=>{let r=i.byId[t],a=o.byId[t];!r||!a||r.parentId===a.parentId&&(c.has(t)||(r.parentId??`__root__`)===e&&(p.has(t)||(p.add(t),s.push({type:`move`,block:a.block,prevBlock:r.block,source:n,prevParent:r.parentId?i.byId[r.parentId]?.block:void 0,currentParent:a.parentId?o.byId[a.parentId]?.block:void 0}),c.add(t))))})}),s}var re=t.t(()=>{let e=[];return{key:`blockChange`,prosemirrorPlugins:[new s.Plugin({key:new s.PluginKey(`blockChange`),filterTransaction:t=>{let n;return e.reduce((e,r)=>e===!1?e:r({getChanges(){return n||(n=x(t),n)},tr:t})!==!1,!0)}})],subscribe(t){return e.push(t),()=>{e.splice(e.indexOf(t),1)}}}});function S(e,t){return!e||!t?!1:!!e.closest(`.${t}`)}function ie(e,t,n,r,i){let a=e.state.doc.resolve(t.pos);if(a.parent.inlineContent||t.orientation===`inline`)return null;let o=a.nodeBefore,s=a.nodeAfter;if(!o&&!s)return null;let c=t.orientation===`block-vertical-left`||t.orientation===`block-vertical-right`,l=c?t.pos:t.pos-(o?o.nodeSize:0),u=e.nodeDOM(l);if(!u)return null;let d=u.getBoundingClientRect();if(c){let e=n/2*r,i=t.orientation===`block-vertical-left`?d.left:d.right;return{left:i-e,right:i+e,top:d.top,bottom:d.bottom}}let f=o?d.bottom:d.top;o&&s&&(f=(f+e.nodeDOM(t.pos).getBoundingClientRect().top)/2);let p=n/2*i;return{left:d.left,right:d.right,top:f-p,bottom:f+p}}function ae(e,t,n,r){let i=e.coordsAtPos(t.pos),a=n/2*r;return{left:i.left-a,right:i.left+a,top:i.top,bottom:i.bottom}}function oe(e,t){e.classList.toggle(`prosemirror-dropcursor-inline`,t===`inline`),e.classList.toggle(`prosemirror-dropcursor-block-horizontal`,t===`block-horizontal`),e.classList.toggle(`prosemirror-dropcursor-block-vertical-left`,t===`block-vertical-left`),e.classList.toggle(`prosemirror-dropcursor-block-vertical-right`,t===`block-vertical-right`),e.classList.toggle(`prosemirror-dropcursor-block`,t===`block-horizontal`),e.classList.toggle(`prosemirror-dropcursor-vertical`,t===`block-vertical-left`||t===`block-vertical-right`)}function se(e){if(!e||e===document.body&&getComputedStyle(e).position===`static`)return{parentLeft:-window.pageXOffset,parentTop:-window.pageYOffset};let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth,r=t.height/e.offsetHeight;return{parentLeft:t.left-e.scrollLeft*n,parentTop:t.top-e.scrollTop*r}}var ce=`bn-drag-exclude`,le=t.t(({editor:e,options:t})=>{let n=null,r=null,a=-1,o=null,s={width:t.dropCursor?.width??5,color:t.dropCursor?.color??`#ddeeff`,exclude:t.dropCursor?.exclude??`bn-drag-exclude`,hooks:t.dropCursor?.hooks},c=e=>{e?.pos===n?.pos&&e?.orientation===n?.orientation||(n=e,e==null?(r&&r.parentNode&&r.parentNode.removeChild(r),r=null):l())},l=()=>{if(!n)return;let t=e.prosemirrorView,i=t.dom,a=i.getBoundingClientRect(),o=a.width/i.offsetWidth,c=a.height/i.offsetHeight,l=ie(t,n,s.width,o,c)??ae(t,n,s.width,o),u=t.dom.offsetParent;r||(r=u.appendChild(document.createElement(`div`)),r.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,s.color&&(r.style.backgroundColor=s.color)),oe(r,n.orientation);let{parentLeft:d,parentTop:f}=se(u);r.style.left=(l.left-d)/o+`px`,r.style.top=(l.top-f)/c+`px`,r.style.width=(l.right-l.left)/o+`px`,r.style.height=(l.bottom-l.top)/c+`px`},u=e=>{clearTimeout(a),a=window.setTimeout(()=>c(null),e)},d=e=>{let t=e;o=t.target instanceof Element?t.target:null},f=t=>{let n=t;if(o&&S(o,s.exclude)||n.target instanceof Element&&S(n.target,s.exclude))return;let r=e.prosemirrorView;if(!r.editable)return;let a=r.posAtCoords({left:n.clientX,top:n.clientY}),l=a&&a.inside>=0&&r.state.doc.nodeAt(a.inside),d=l&&l.type.spec.disableDropCursor,f=typeof d==`function`?d(r,a,n):d;if(a&&!f){let t=a.pos;if(r.dragging&&r.dragging.slice){let e=(0,i.dropPoint)(r.state.doc,t,r.dragging.slice);e!=null&&(t=e)}let o=!r.state.doc.resolve(t).parent.inlineContent,l={pos:t,orientation:o?`block-horizontal`:`inline`},d=l;if(s.hooks?.computeDropPosition){let t=s.hooks.computeDropPosition({editor:e,event:n,view:r,defaultPosition:l});if(t===null){c(null);return}d=t}c(d),u(5e3)}},p=t=>{let n=t;(!(n.relatedTarget instanceof Node)||!e.prosemirrorView.dom.contains(n.relatedTarget))&&c(null)},m=()=>{u(20)},h=()=>{u(20),o=null};return{key:`dropCursor`,mount({signal:e,dom:t,root:n}){n.addEventListener(`dragstart`,d,{capture:!0,signal:e}),t.addEventListener(`dragover`,f,{signal:e}),t.addEventListener(`dragleave`,p,{signal:e}),t.addEventListener(`drop`,m,{signal:e}),t.addEventListener(`dragend`,h,{signal:e}),e.addEventListener(`abort`,()=>{clearTimeout(a),c(null)})}}}),ue=t.t(()=>({key:`history`,prosemirrorPlugins:[(0,p.history)()],undoCommand:p.undo,redoCommand:p.redo})),de=t.t(({editor:e})=>{function t(t){let n=e.prosemirrorView.nodeDOM(t);for(;n&&n.parentElement;){if(n.nodeName===`A`)return n;n=n.parentElement}return null}function n(t){let n=e.getLinkMarkAtPos(t);if(n)return{range:{from:n.from,to:n.to},mark:{attrs:{href:n.href}},get text(){return n.text},get position(){return(0,a.posToDOMRect)(e.prosemirrorView,n.from,n.to).toJSON()}}}function r(){return e.transact(e=>{if(e.selection.empty)return n(e.selection.anchor)})}return{key:`linkToolbar`,getLinkAtSelection:r,getLinkElementAtPos:t,getMarkAtPos(e,t){return n(e)},getLinkAtElement(t){return e.transact(()=>n(e.prosemirrorView.posAtDOM(t,0)+1))},editLink(t,n,r=e.transact(e=>e.selection.anchor)){e.editLink(t,n,r)},deleteLink(t=e.transact(e=>e.selection.anchor)){e.deleteLink(t)}}}),fe=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`],pe=`https`,me=new s.PluginKey(`node-selection-keyboard`),he=t.t(()=>({key:`nodeSelectionKeyboard`,prosemirrorPlugins:[new s.Plugin({key:me,props:{handleKeyDown:(e,t)=>{if(`node`in e.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(t.key.length===1)return t.preventDefault(),!0;if(t.key===`Enter`&&!t.isComposing&&!t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey){let t=e.state.tr;return e.dispatch(t.insert(e.state.tr.selection.$to.after(),e.state.schema.nodes.paragraph.createChecked()).setSelection(new s.TextSelection(t.doc.resolve(e.state.tr.selection.$to.after()+1)))),!0}}return!1}}})]})),ge=new s.PluginKey(`blocknote-placeholder`),_e=t.t(({editor:e,options:t})=>{let n=t.placeholders;return{key:`placeholder`,prosemirrorPlugins:[new s.Plugin({key:ge,view:t=>{let r=`placeholder-selector-${(0,o.uuidv4)()}`;t.dom.classList.add(r);let i=document.createElement(`style`),a=e._tiptapEditor.options.injectNonce;a&&i.setAttribute(`nonce`,a),t.root instanceof window.ShadowRoot?t.root.append(i):t.root.head.appendChild(i);let s=i.sheet,c=(e=``)=>`.${r} .bn-block-content${e}:has(.ProseMirror-trailingBreak:only-child):after`;try{let{default:e,emptyDocument:t,...r}=n||{};for(let[e,t]of Object.entries(r)){let n=`[data-content-type="${e}"]`;s.insertRule(`${c(n)} { content: ${JSON.stringify(t)}; }`)}s.insertRule(`${c(`[data-is-only-empty-block]`)} { content: ${JSON.stringify(t)}; }`),s.insertRule(`${c(`[data-is-empty-and-focused]`)} { content: ${JSON.stringify(e)}; }`)}catch(e){console.warn(`Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)`,e)}return{destroy:()=>{t.root instanceof window.ShadowRoot?t.root.removeChild(i):t.root.head.removeChild(i)}}},props:{decorations:t=>{let{doc:n,selection:r}=t;if(!e.isEditable||!r.empty||r.$from.parent.type.spec.code)return;let i=[];t.doc.content.size===6&&i.push(d.Decoration.node(2,4,{"data-is-only-empty-block":`true`}));let a=r.$anchor,o=a.parent;if(o.content.size===0){let e=a.before();i.push(d.Decoration.node(e,e+o.nodeSize,{"data-is-empty-and-focused":`true`}))}return d.DecorationSet.create(n,i)}}})]}}),ve=t.t(({editor:e})=>{let t=new i.Mapping,n=0;function r(){t=new i.Mapping,n=0}let a=typeof FinalizationRegistry<`u`?new FinalizationRegistry(()=>{n--,n===0&&r()}):null;return e.on(`create`,()=>{e._tiptapEditor.on(`transaction`,({transaction:e})=>{n!==0&&t.appendMapping(e.mapping)}),e._tiptapEditor.on(`destroy`,()=>{r()})}),{key:`positionMapping`,mapPosition:(e,r=`left`)=>{n++;let i=t.maps.length,o=()=>t.slice(i).map(e,r===`left`?-1:1);return a&&a.register(o,void 0),o}}}),C=new s.PluginKey(`previous-blocks`),ye={index:`index`,level:`level`,type:`type`,depth:`depth`,"depth-change":`depth-change`},be=t.t(()=>{let t;return{key:`previousBlockType`,prosemirrorPlugins:[new s.Plugin({key:C,view(e){return{update:async(e,n)=>{this.key?.getState(e.state).updatedBlocks.size>0&&(t=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(C,{clearUpdate:!0}))},0))},destroy:()=>{t&&clearTimeout(t)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,n,r,i){if(n.currentTransactionOldBlockAttrs={},n.updatedBlocks.clear(),!t.docChanged)return n;let o=t.changedRange();if(!o)return n;let s=t.mapping.invert(),c={from:s.map(o.from,-1),to:s.map(o.to,1)},l={},u=(0,a.findChildrenInRange)(r.doc,c,e=>e.attrs.id),d=new Map(u.map(t=>[e.$n(t.node,r.doc),t])),f=(0,a.findChildrenInRange)(i.doc,o,e=>e.attrs.id);for(let t of f){let a=e.$n(t.node,i.doc),o=d.get(a),s=o?.node.firstChild,c=t.node.firstChild;if(o&&s&&c){let e={index:c.attrs.index,level:c.attrs.level,type:c.type.name,depth:i.doc.resolve(t.pos).depth},u={index:s.attrs.index,level:s.attrs.level,type:s.type.name,depth:r.doc.resolve(o.pos).depth};l[a]=u,n.currentTransactionOldBlockAttrs[a]=u,(u.index!==e.index||u.level!==e.level||u.type!==e.type||u.depth!==e.depth)&&(u[`depth-change`]=u.depth-e.depth,n.updatedBlocks.add(a))}}return n.prevTransactionOldBlockAttrs=l,n}},props:{decorations(t){let n=this.getState(t);if(n.updatedBlocks.size===0)return;let r=[];return t.doc.descendants((i,a)=>{if(!i.attrs.id)return;let o=e.$n(i,t.doc);if(!n.updatedBlocks.has(o))return;let s=n.currentTransactionOldBlockAttrs[o],c={};for(let[e,t]of Object.entries(s))c[`data-prev-`+ye[e]]=t||`none`;r.push(d.Decoration.node(a,a+i.nodeSize,{...c}))}),d.DecorationSet.create(t.doc,r)}}})]}});function w(e,t){for(;e&&e.parentElement&&e.parentElement!==t.dom&&e.getAttribute?.(`data-node-type`)!==`blockContainer`;)e=e.parentElement;if(e.getAttribute?.(`data-node-type`)===`blockContainer`)return{node:e,id:e.getAttribute(`data-id`)}}function xe(e){let t=document.createElement(`div`);return t.innerHTML=e,T(t,{indent:``,inListItem:!1}).trim()+`
`}function T(e,t){let n=``,r=Array.from(e.childNodes);for(let e=0;e<r.length;e++){let i=r[e];n+=E(i,t)}return n}function E(e,t){if(e.nodeType===3)return e.textContent||``;if(e.nodeType!==1)return``;let n=e;switch(n.tagName.toLowerCase()){case`p`:return Se(n,t);case`h1`:case`h2`:case`h3`:case`h4`:case`h5`:case`h6`:return D(n,t);case`blockquote`:return Ce(n,t);case`pre`:return we(n,t);case`ul`:return Ee(n,t);case`ol`:return De(n,t);case`table`:return ke(n,t);case`hr`:return t.indent+`***
`;case`img`:return je(n,t);case`video`:return Me(n,t);case`audio`:return Ne(n,t);case`embed`:return Pe(n,t);case`figure`:return Fe(n,t);case`a`:return P(n,t);case`details`:return Re(n,t);case`div`:return T(n,t);case`br`:return``;default:return T(n,t)}}function Se(e,t){let n=ze(I(e));return t.inListItem?n:t.indent+n+`
`}function D(e,t){let n=parseInt(e.tagName[1],10),r=`#`.repeat(n)+` `,i=I(e);return t.indent+r+i+`
`}function Ce(e,t){let n=Array.from(e.children).filter(e=>{let t=e.tagName.toLowerCase();return[`p`,`ul`,`ol`,`pre`,`blockquote`,`table`,`hr`].includes(t)}),r;if(n.length>0){let e=[];for(let t of n)t.tagName.toLowerCase()===`p`?e.push(I(t)):e.push(E(t,{indent:``,inListItem:!1}).trim());r=e.join(`
`)}else r=I(e);return r.split(`
`).map(e=>t.indent+`> `+e).join(`
`)+`
`}function we(e,t){let n=e.querySelector(`code`);if(!n)return``;let r=n.getAttribute(`data-language`)||Te(n.className)||``,i=O(n),a=Math.max(0,...(i.match(/`+/g)??[]).map(e=>e.length)),o="`".repeat(Math.max(3,a+1));return i?t.indent+o+r+`
`+i+(i.endsWith(`
`)?``:`
`)+o+`
`:t.indent+o+r+`
`+o+`
`}function O(e){let t=``;for(let n of Array.from(e.childNodes))n.nodeType===3?t+=n.textContent||``:n.nodeType===1&&(n.tagName.toLowerCase()===`br`?t+=`
`:t+=O(n));return t}function Te(e){let t=e.match(/language-(\S+)/);return t?t[1]:``}function Ee(e,t){let n=``,r=Array.from(e.children).filter(e=>e.tagName.toLowerCase()===`li`);for(let e of r)n+=k(e,`bullet`,t);return t.inListItem||(n+=`
`),n}function De(e,t){let n=``,r=Array.from(e.children).filter(e=>e.tagName.toLowerCase()===`li`),i=parseInt(e.getAttribute(`start`)||`1`,10);for(let e=0;e<r.length;e++){let a=i+e;n+=k(r[e],`ordered`,t,a)}return t.inListItem||(n+=`
`),n}function k(e,t,n,r){let i=null,a=null;for(let t of Array.from(e.children)){let e=t.tagName.toLowerCase();e===`input`&&t.type===`checkbox`&&(i=t),e===`details`&&(a=t)}let o,s;i?(o=`* ${i.checked?`[x]`:`[ ]`} `,s=2):t===`ordered`?(o=`${r}. `,s=o.length):(o=`* `,s=2);let c,l;if(a){let e=a.querySelector(`summary`)?.querySelector(`p`);l=a,c=e?I(e):``}else l=Oe(e,i),c=l?I(l):``;let u=n.indent+o+c+`
`,d=n.indent+` `.repeat(s),f={indent:d,inListItem:!0};if(a){let e=a.querySelector(`summary`);for(let t of Array.from(a.children))if(t!==e)if(t.tagName.toLowerCase()===`p`){let e=I(t);u+=`
`+d+e+`
`}else u+=E(t,f)}let p=Array.from(e.children);for(let e of p){let t=e.tagName.toLowerCase();if(!(e===l||e===i)&&t!==`input`)if(t===`ul`||t===`ol`)u+=E(e,f);else if(t===`p`){let t=I(e);u+=`
`+d+t+`
`}else u+=`
`+E(e,f)}return u}function Oe(e,t){for(let n of Array.from(e.children)){if(n===t||n.tagName.toLowerCase()===`input`)continue;let e=n.tagName.toLowerCase();if(e===`p`||e===`span`)return n}return null}function ke(e,t){let n=e.querySelector(`colgroup`),r=0;n&&(r=n.querySelectorAll(`col`).length);let i=[],a=!1,o=e.querySelectorAll(`tr`),s=[];o.forEach((e,t)=>{s[t]||(s[t]=[]);let n=e.querySelectorAll(`th, td`),i=0;n.forEach(e=>{for(;s[t][i]!==void 0;)i++;t===0&&e.tagName.toLowerCase()===`th`&&(a=!0);let n=Ae(I(e).trim()),r=parseInt(e.getAttribute(`colspan`)||`1`,10),o=parseInt(e.getAttribute(`rowspan`)||`1`,10);for(let e=0;e<o;e++)for(let a=0;a<r;a++){let r=t+e;s[r]||(s[r]=[]),s[r][i+a]=e===0&&a===0?n:``}i+=r}),s[t]&&(r=Math.max(r,s[t].length))});for(let e of s){let t=[];for(let n=0;n<r;n++)t.push(e&&e[n]!==void 0?e[n]??``:``);i.push(t)}if(i.length===0)return``;let c=[];for(let e=0;e<r;e++){let t=3;for(let n of i){let r=e<n.length?n[e].length:0;t=Math.max(t,r)}c.push(Math.max(t,10))}let l=``;if(a){l+=t.indent+A(i[0],c,r)+`
`,l+=t.indent+j(c,r)+`
`;for(let e=1;e<i.length;e++)l+=t.indent+A(i[e],c,r)+`
`}else{let e=Array(r).fill(``);l+=t.indent+A(e,c,r)+`
`,l+=t.indent+j(c,r)+`
`;for(let e of i)l+=t.indent+A(e,c,r)+`
`}return l+=`
`,l}function Ae(e){return e.replace(/\|/g,`\\|`)}function A(e,t,n){let r=[];for(let i=0;i<n;i++){let n=i<e.length?e[i]:``;r.push(` `+n.padEnd(t[i])+` `)}return`|`+r.join(`|`)+`|`}function j(e,t){let n=[];for(let r=0;r<t;r++)n.push(` `+`-`.repeat(e[r])+` `);return`|`+n.join(`|`)+`|`}function je(e,t){let n=e.getAttribute(`src`)||``,r=e.getAttribute(`alt`)||``;return n?t.indent+`\n\n`:`
`}function Me(e,t){let n=e.getAttribute(`src`)||e.getAttribute(`data-url`)||``,r=e.getAttribute(`data-name`)||e.getAttribute(`title`)||``;return n?t.indent+`\n\n`:`
`}function Ne(e,t){let n=e.getAttribute(`src`)||``;return n?t.indent+`<audio src="${N(n)}" controls></audio>\n\n`:`
`}function Pe(e,t){let n=e.getAttribute(`src`)||``;return n?t.indent+`[](${n})\n\n`:`
`}function Fe(e,t){let n=e.querySelector(`img`),r=e.querySelector(`video`),i=e.querySelector(`audio`),a=e.querySelector(`a`),o=e.querySelector(`figcaption`)?.textContent?.trim()||``;return n?M(`img`,n.getAttribute(`src`)||``,n.getAttribute(`alt`)||``,o,t):r?M(`video`,r.getAttribute(`src`)||r.getAttribute(`data-url`)||``,r.getAttribute(`data-name`)||r.getAttribute(`title`)||``,o,t):i?M(`audio`,i.getAttribute(`src`)||``,``,o,t):a?P(a,t):``}function M(e,t,n,r,i){if(!t)return``;if(!r&&e!==`audio`)return i.indent+`\n\n`;let a=n&&n!==r?e===`img`?` alt="${N(n)}"`:e===`video`?` data-name="${N(n)}"`:``:``,o=e===`img`?`<img${a} src="${N(t)}">`:`<${e} src="${N(t)}"${a} controls></${e}>`,s=r?`<figcaption>${Ie(r)}</figcaption>`:``;return i.indent+`<figure>${o}${s}</figure>\n\n`}function N(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function Ie(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function P(e,t){let n=e.getAttribute(`href`)||``,r=e.textContent?.trim()||``;return n?t.indent+F(r,n)+`
`:t.indent+r+`
`}function F(e,t){return!e||e===t?t:`[${e}](${Le(t)})`}function Le(e){return e.replace(/[\\()]/g,`\\$&`)}function Re(e,t){let n=e.querySelector(`summary`);if(!n)return T(e,t);let r=n.querySelector(`h1, h2, h3, h4, h5, h6`);if(r){let i=D(r,t);for(let r of Array.from(e.children))r!==n&&(i+=E(r,t));return i}return T(n,t)}function I(e){let t=``;for(let n of Array.from(e.childNodes))if(n.nodeType===3)t+=n.textContent||``;else if(n.nodeType===1){let e=n;switch(e.tagName.toLowerCase()){case`strong`:case`b`:{let{content:n,trailing:r}=L(I(e));n?t+=`**${n}**${r}`:t+=r;break}case`em`:case`i`:{let{content:n,trailing:r}=L(I(e));n?t+=`*${n}*${r}`:t+=r;break}case`s`:case`del`:t+=`~~${I(e)}~~`;break;case`code`:{let n=e.textContent||``,r=Math.max(0,...(n.match(/`+/g)??[]).map(e=>e.length)),i="`".repeat(r+1),a=n.startsWith("`")||n.endsWith("`");t+=i+(a?` ${n} `:n)+i;break}case`u`:t+=I(e);break;case`a`:{let n=e.getAttribute(`href`)||``,r=I(e);t+=F(r,n);break}case`br`:t+=`\\
`;break;case`span`:t+=I(e);break;case`img`:{let n=e.getAttribute(`src`)||``,r=e.getAttribute(`alt`)||``;t+=``;break}case`video`:{let n=e.getAttribute(`src`)||e.getAttribute(`data-url`)||``,r=e.getAttribute(`data-name`)||e.getAttribute(`title`)||``;t+=``;break}case`p`:t+=I(e);break;case`input`:break;default:t+=I(e);break}}return t}function L(e){let t=e.match(/^(.*?)(\s*)$/);return t?{content:t[1],trailing:t[2]}:{content:e,trailing:``}}function ze(e){let t=e.replace(/^(\\\n)+/,``);return t=t.replace(/(\\\n)+$/,``),t}function R(e){return xe(e)}function Be(e,t,n,r){return R(y(t,n).exportBlocks(e,r))}function z(t){let n=[];return t.descendants(t=>t.type.name===`blockContainer`&&t.firstChild?.type.name===`blockGroup`?!0:t.type.name===`columnList`&&t.childCount===1?(t.firstChild?.forEach(r=>{n.push(e.yn(r,t))}),!1):t.type.isInGroup(`bnBlock`)?(n.push(e.yn(t,t)),!1):!0),n}var B=class e extends s.Selection{nodes;constructor(e,t){super(e,t);let n=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,t.pos,(e,t,r)=>{if(r!==null&&r.eq(n))return this.nodes.push(e),!1})}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}content(){return new r.Slice(r.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof e)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let e=0;e<this.nodes.length;e++)if(!this.nodes[e].eq(t.nodes[e]))return!1;return!0}map(t,n){let r=n.mapResult(this.from),i=n.mapResult(this.to);return i.deleted?s.Selection.near(t.resolve(r.pos)):r.deleted?s.Selection.near(t.resolve(i.pos)):new e(t.resolve(r.pos),t.resolve(i.pos))}toJSON(){return{type:`multiple-node`,anchor:this.anchor,head:this.head}}};s.Selection.jsonID(`multiple-node`,B);var V;function Ve(e,t){let n,r,i=t.resolve(e.from).node().type.spec.group===`blockContent`,a=t.resolve(e.to).node().type.spec.group===`blockContent`,o=Math.min(e.$anchor.depth,e.$head.depth);if(i&&a){let i=e.$from.start(o-1),a=e.$to.end(o-1);n=t.resolve(i-1).pos,r=t.resolve(a+1).pos}else n=e.from,r=e.to;return{from:n,to:r}}function H(e,t,n=t){t===n&&(n+=e.state.doc.resolve(t+1).node().nodeSize);let r=e.domAtPos(t).node.cloneNode(!0),i=e.domAtPos(t).node,a=(e,t)=>Array.prototype.indexOf.call(e.children,t),o=a(i,e.domAtPos(t+1).node.parentElement),s=a(i,e.domAtPos(n-1).node.parentElement);for(let e=i.childElementCount-1;e>=0;e--)(e>s||e<o)&&r.removeChild(r.children[e]);He(e.root),V=r,V.querySelectorAll(`iframe, embed, object`).forEach(e=>e.parentElement?.removeChild(e));let c=e.dom.className.split(` `).filter(e=>e!==`ProseMirror`&&e!==`bn-root`&&e!==`bn-editor`).join(` `);V.className=V.className+` bn-drag-preview `+c,e.root instanceof ShadowRoot?e.root.appendChild(V):e.root.body.appendChild(V)}function He(e){V!==void 0&&(e instanceof ShadowRoot?e.removeChild(V):e.body.removeChild(V),V=void 0)}function Ue(t,n,r){if(!t.dataTransfer||r.headless)return;let i=r.prosemirrorView,a=e.kt(n.id,i.state.doc);if(!a)throw Error(`Block with ID ${n.id} not found`);let o=a.posBeforeNode;if(o!=null){let e=i.state.selection,n=i.state.doc,{from:a,to:c}=Ve(e,n),l=a<=o&&o<c,u=e.$anchor.node()!==e.$head.node()||e instanceof B;l&&u?(i.dispatch(i.state.tr.setSelection(B.create(n,a,c))),H(i,a,c)):(i.dispatch(i.state.tr.setSelection(s.NodeSelection.create(i.state.doc,o))),H(i,o));let d=i.state.selection.content(),f=r.pmSchema,p=i.serializeForClipboard(d).dom.innerHTML,m=y(f,r),h=z(d.content),g=m.exportBlocks(h,{}),_=R(g);t.dataTransfer.clearData(),t.dataTransfer.setData(`blocknote/html`,p),t.dataTransfer.setData(`text/html`,g),t.dataTransfer.setData(`text/plain`,_),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setDragImage(V,0,0)}}var We=250;function U(e,t,n=!0){let r=e.root.elementsFromPoint(t.left,t.top);for(let i of r)if(e.dom.contains(i))return n&&i.closest(`[data-node-type=columnList]`)?U(e,{left:t.left+50,top:t.top},!1):w(i,e)}function Ge(e,t){if(!t.dom.firstChild)return;let n=t.dom.firstChild.getBoundingClientRect(),r=U(t,{left:Math.min(Math.max(n.left+10,e.x),n.right-10),top:e.y});if(r)return U(t,{left:r.node.getBoundingClientRect().right-10,top:e.y},!1)}var Ke=class{editor;pmView;state;emitUpdate;mousePos;hoveredBlock;menuFrozen=!1;isDragOrigin=!1;constructor(e,t,n){this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw Error(`Attempting to update uninitialized side menu`);n(this.state)},this.pmView.root.addEventListener(`dragstart`,this.onDragStart),this.pmView.root.addEventListener(`dragover`,this.onDragOver),this.pmView.root.addEventListener(`drop`,this.onDrop,!0),this.pmView.root.addEventListener(`dragend`,this.onDragEnd,!0),this.pmView.root.addEventListener(`mousemove`,this.onMouseMove,!0),this.pmView.root.addEventListener(`keydown`,this.onKeyDown,!0)}updateState=e=>{this.state=e,this.emitUpdate(this.state)};updateStateFromMousePos=()=>{if(this.menuFrozen||!this.mousePos)return;let e=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if(e?.element!==this.pmView.dom||e.distance>We){this.state?.show&&(this.state.show=!1,this.updateState(this.state));return}let t=Ge(this.mousePos,this.pmView);if(!t||!this.editor.isEditable){this.state?.show&&(this.state.show=!1,this.updateState(this.state));return}if(!(this.state?.show&&this.hoveredBlock?.hasAttribute(`data-id`)&&this.hoveredBlock?.getAttribute(`data-id`)===t.id)&&(this.hoveredBlock=t.node,this.editor.isEditable)){let e=t.node.getBoundingClientRect(),n=t.node.closest(`[data-node-type=column]`);this.state={show:!0,referencePos:new DOMRect(n?n.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,e.y,e.width,e.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute(`data-id`))},this.updateState(this.state)}};onDragStart=e=>{let t=e.dataTransfer?.getData(`blocknote/html`);if(!t||this.pmView.dragging)return;let n=document.createElement(`div`);n.innerHTML=t;let r=c.DOMParser.fromSchema(this.pmView.state.schema).parse(n,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new c.Slice(r.content,0,0),move:!0}};findClosestEditorElement=e=>{let t=Array.from(this.pmView.root.querySelectorAll(`.bn-editor`));if(t.length===0)return null;let n=t[0],r=Number.MAX_VALUE;return t.forEach(t=>{let i=t.querySelector(`.bn-block-group`).getBoundingClientRect(),a=e.clientX<i.left?i.left-e.clientX:e.clientX>i.right?e.clientX-i.right:0,o=e.clientY<i.top?i.top-e.clientY:e.clientY>i.bottom?e.clientY-i.bottom:0,s=Math.sqrt(a**2+o**2);s<r&&(r=s,n=t)}),{element:n,distance:r}};onDragOver=e=>{if(e.synthetic||!(this.pmView.dragging!==null||this.isDragOrigin||e.dataTransfer?.types.includes(`blocknote/html`)||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;let t=this.getDragEventContext(e);if(!t||!t.isDropPoint){this.closeDropCursor();return}t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(e)};closeDropCursor=()=>{let e=new Event(`dragleave`,{bubbles:!1});e.synthetic=!0,this.pmView.dom.dispatchEvent(e)};getDragEventContext=e=>{if(!(this.pmView.dragging!==null||this.isDragOrigin||e.dataTransfer?.types.includes(`blocknote/html`)||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;let t=!e.dataTransfer?.types.includes(`blocknote/html`)&&!!this.pmView.dragging,n=!!this.isDragOrigin,r=t||n,i=this.findClosestEditorElement(e);if(!i||i.distance>We)return;let a=i.element===this.pmView.dom,o=a&&i.distance===0;if(!(!a&&!r))return{isDropPoint:a,isDropWithinEditorBounds:o,isDragOrigin:r}};onDrop=e=>{if(e.synthetic||!(this.pmView.dragging!==null||this.isDragOrigin||e.dataTransfer?.types.includes(`blocknote/html`)||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;let t=this.getDragEventContext(e);if(!t){this.closeDropCursor();return}let{isDropPoint:n,isDropWithinEditorBounds:r,isDragOrigin:i}=t;if(!r&&n&&this.dispatchSyntheticEvent(e),n){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(u.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)));return}else if(i){setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0);return}};onDragEnd=e=>{e.synthetic||(this.pmView.dragging=null)};onKeyDown=e=>{this.state?.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))};onMouseMove=e=>{if(this.menuFrozen||!Number.isFinite(e.clientX)||!Number.isFinite(e.clientY))return;this.mousePos={x:e.clientX,y:e.clientY};let t=this.pmView.dom.getBoundingClientRect();if(this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom&&e&&e.target&&!this.editor.isWithinEditor(e.target)){this.state?.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()};dispatchSyntheticEvent(e){let t=new Event(e.type,e),n=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=e.clientX,t.clientY=e.clientY,t.clientX=Math.min(Math.max(e.clientX,n.left),n.left+n.width),t.clientY=Math.min(Math.max(e.clientY,n.top),n.top+n.height),t.dataTransfer=e.dataTransfer,t.preventDefault=()=>e.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(e,t){!t.doc.eq(this.pmView.state.doc)&&this.state?.show&&this.updateStateFromMousePos()}destroy(){this.state?.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener(`mousemove`,this.onMouseMove,!0),this.pmView.root.removeEventListener(`dragstart`,this.onDragStart),this.pmView.root.removeEventListener(`dragover`,this.onDragOver),this.pmView.root.removeEventListener(`drop`,this.onDrop,!0),this.pmView.root.removeEventListener(`dragend`,this.onDragEnd,!0),this.pmView.root.removeEventListener(`keydown`,this.onKeyDown,!0)}},qe=new u.PluginKey(`SideMenuPlugin`),Je=t.t(({editor:e})=>{let n,r=t.n(void 0);return{key:`sideMenu`,store:r,prosemirrorPlugins:[new u.Plugin({key:qe,view:t=>(n=new Ke(e,t,e=>{r.setState({...e})}),n)})],blockDragStart(t,r){n&&(n.isDragOrigin=!0),Ue(t,r,e)},blockDragEnd(){He(e.prosemirrorView.root),n&&(n.isDragOrigin=!1),e.blur()},freezeMenu(){n.menuFrozen=!0,n.state.show=!0,n.emitUpdate(n.state)},unfreezeMenu(){n.menuFrozen=!1,n.state.show=!1,n.emitUpdate(n.state)},hideMenuIfNotFrozen(){!n.menuFrozen&&n.state?.show&&(n.state.show=!1,n.emitUpdate(n.state))}}}),W;async function Ye(){return W||(W=(async()=>{let[e,t]=await Promise.all([import(`emoji-mart`),import(`@emoji-mart/data`)]),n=`default`in e?e.default:e,r=`default`in t?t.default:t;return await n.init({data:r}),{emojiMart:n,emojiData:r}})(),W)}async function Xe(t,n){if(!(`text`in t.schema.inlineContentSchema)||t.schema.inlineContentSchema.text!==e.r.text)return[];let{emojiData:r,emojiMart:i}=await Ye();return(n.trim()===``?Object.values(r.emojis):await i.SearchIndex.search(n)).map(e=>({id:e.skins[0].native,onItemClick:()=>t.insertInlineContent(e.skins[0].native+` `)}))}var G;function Ze(e){G||(G=document.createElement(`div`),G.innerHTML=`_`,G.style.opacity=`0`,G.style.height=`1px`,G.style.width=`1px`,e instanceof Document?e.body.appendChild(G):e.appendChild(G))}function Qe(e){G&&=(e instanceof Document?e.body.removeChild(G):e.removeChild(G),void 0)}function K(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function $e(e){let t=e;for(;t&&t.nodeName!==`TD`&&t.nodeName!==`TH`&&!t.classList.contains(`tableWrapper`);){if(t.classList.contains(`ProseMirror`))return;let e=t.parentNode;if(!e||!(e instanceof Element))return;t=e}return t.nodeName===`TD`||t.nodeName===`TH`?{type:`cell`,domNode:t,tbodyNode:t.closest(`tbody`)}:{type:`wrapper`,domNode:t,tbodyNode:t.querySelector(`tbody`)}}function et(e,t){let n=t.querySelectorAll(e);for(let e=0;e<n.length;e++)n[e].style.visibility=`hidden`}var q=class{editor;pmView;state;emitUpdate;tableId;tablePos;tableElement;menuFrozen=!1;mouseState=`up`;prevWasEditable=null;constructor(e,t,n){this.editor=e,this.pmView=t,this.emitUpdate=()=>{n(this.state)},t.dom.addEventListener(`mousemove`,this.mouseMoveHandler),t.dom.addEventListener(`mousedown`,this.viewMousedownHandler),window.addEventListener(`mouseup`,this.mouseUpHandler),t.root.addEventListener(`dragover`,this.dragOverHandler),t.root.addEventListener(`drop`,this.dropHandler)}viewMousedownHandler=()=>{this.mouseState=`down`};mouseUpHandler=e=>{this.mouseState=`up`,this.mouseMoveHandler(e)};mouseMoveHandler=t=>{if(this.menuFrozen||this.mouseState===`selecting`||!(t.target instanceof Element)||!this.pmView.dom.contains(t.target))return;let n=$e(t.target);if(n?.type===`cell`&&this.mouseState===`down`&&!this.state?.draggingState){this.mouseState=`selecting`,this.state?.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!n||!this.editor.isEditable){this.state?.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!n.tbodyNode)return;let r=n.tbodyNode.getBoundingClientRect(),i=w(n.domNode,this.pmView);if(!i)return;this.tableElement=i.node;let a,{pmNodeInfo:o,doc:s}=this.editor.transact(t=>({pmNodeInfo:e.kt(i.id,t.doc),doc:t.doc}));if(!o)throw Error(`Block with ID ${i.id} not found`);let c=e.yn(o.node,s);if(e.g(this.editor,`table`)&&(this.tablePos=o.posBeforeNode+1,a=c),!a)return;this.tableId=i.id;let l=n.domNode.closest(`.tableWrapper`)?.querySelector(`.table-widgets-container`);if(n?.type===`wrapper`){let e=t.clientY>=r.bottom-1&&t.clientY<r.bottom+20,n=t.clientX>=r.right-1&&t.clientX<r.right+20,i=this.state?.block?.id!==a.id||t.clientX>r.right||t.clientY>r.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:e,showAddOrRemoveColumnsButton:n,referencePosTable:r,block:a,widgetContainer:l,colIndex:i?void 0:this.state?.colIndex,rowIndex:i?void 0:this.state?.rowIndex,referencePosCell:i?void 0:this.state?.referencePosCell}}else{let e=K(n.domNode),t=K(n.domNode.parentElement),o=n.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===i.id&&this.state.rowIndex===t&&this.state.colIndex===e)return;this.state={show:!0,showAddOrRemoveColumnsButton:e===a.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:t===a.content.rows.length-1,referencePosTable:r,block:a,draggingState:void 0,referencePosCell:o,colIndex:e,rowIndex:t,widgetContainer:l}}return this.emitUpdate(),!1};dragOverHandler=e=>{if(this.state?.draggingState===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`,et(`.prosemirror-dropcursor-block, .prosemirror-dropcursor-inline`,this.pmView.root);let t={left:Math.min(Math.max(e.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(e.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},n=this.pmView.root.elementsFromPoint(t.left,t.top).filter(e=>e.tagName===`TD`||e.tagName===`TH`);if(n.length===0)return;let r=n[0],i=!1,a=K(r.parentElement),o=K(r),s=this.state.draggingState.draggedCellOrientation===`row`?this.state.rowIndex:this.state.colIndex,c=(this.state.draggingState.draggedCellOrientation===`row`?a:o)!==s;(this.state.rowIndex!==a||this.state.colIndex!==o)&&(this.state.rowIndex=a,this.state.colIndex=o,this.state.referencePosCell=r.getBoundingClientRect(),i=!0);let l=this.state.draggingState.draggedCellOrientation===`row`?t.top:t.left;this.state.draggingState.mousePos!==l&&(this.state.draggingState.mousePos=l,i=!0),i&&this.emitUpdate(),c&&this.editor.transact(e=>e.setMeta(J,!0))};dropHandler=t=>{if(this.mouseState=`up`,this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw Error(`Attempted to drop table row or column, but no table block was hovered prior.`);t.preventDefault();let{draggingState:n,colIndex:r,rowIndex:i}=this.state;this.state.draggingState=void 0;let a=this.state.block.content.columnWidths;if(n.draggedCellOrientation===`row`){if(!e.Lt(this.state.block,n.originalIndex,i))return!1;let t=e.Ut(this.state.block,n.originalIndex,i);this.editor.updateBlock(this.state.block,{type:`table`,content:{...this.state.block.content,rows:t}})}else{if(!e.It(this.state.block,n.originalIndex,r))return!1;let t=e.Ht(this.state.block,n.originalIndex,r),[i]=a.splice(n.originalIndex,1);a.splice(r,0,i),this.editor.updateBlock(this.state.block,{type:`table`,content:{...this.state.block.content,columnWidths:a,rows:t}})}return this.editor.setTextCursorPosition(this.state.block.id),!0};update(){if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||this.state.block.type!==`table`||!this.tableElement?.isConnected){this.state=void 0,this.tableId=void 0,this.tableElement=void 0,this.emitUpdate();return}let{height:t,width:n}=e.Vt(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=t&&(this.state.rowIndex=t-1),this.state.colIndex>=n&&(this.state.colIndex=n-1));let r=this.tableElement.querySelector(`tbody`);if(!r)throw Error(`Table block does not contain a 'tbody' HTML element. This should never happen.`);if(this.state.rowIndex!==void 0&&this.state.colIndex!==void 0){let e=r.children[this.state.rowIndex].children[this.state.colIndex];e?this.state.referencePosCell=e.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=r.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener(`mousemove`,this.mouseMoveHandler),window.removeEventListener(`mouseup`,this.mouseUpHandler),this.pmView.dom.removeEventListener(`mousedown`,this.viewMousedownHandler),this.pmView.root.removeEventListener(`dragover`,this.dragOverHandler),this.pmView.root.removeEventListener(`drop`,this.dropHandler)}},J=new s.PluginKey(`TableHandlesPlugin`),tt=t.t(({editor:n})=>{let r,i=t.n(void 0);return{key:`tableHandles`,store:i,prosemirrorPlugins:[new s.Plugin({key:J,view:e=>(r=new q(n,e,e=>{i.setState(e?.block?{...e,draggingState:e.draggingState?{...e.draggingState}:void 0}:void 0)}),r),props:{decorations:t=>{if(r===void 0||r.state===void 0||r.state.draggingState===void 0||r.tablePos===void 0)return;let n=r.state.draggingState.draggedCellOrientation===`row`?r.state.rowIndex:r.state.colIndex;if(n===void 0)return;let i=[],{block:a,draggingState:o}=r.state,{originalIndex:s,draggedCellOrientation:c}=o;if(n===s||!a||c===`row`&&!e.Lt(a,s,n)||c===`col`&&!e.It(a,s,n))return d.DecorationSet.create(t.doc,i);let l=t.doc.resolve(r.tablePos+1);return r.state.draggingState.draggedCellOrientation===`row`?e.Bt(r.state.block,n).forEach(({row:e,col:r})=>{let a=t.doc.resolve(l.posAtIndex(e)+1),o=t.doc.resolve(a.posAtIndex(r)+1),c=o.node(),u=o.pos+(n>s?c.nodeSize-2:0);i.push(d.Decoration.widget(u,()=>{let e=document.createElement(`div`);return e.className=`bn-table-drop-cursor`,e.style.left=`0`,e.style.right=`0`,n>s?e.style.bottom=`-2px`:e.style.top=`-3px`,e.style.height=`4px`,e}))}):e.zt(r.state.block,n).forEach(({row:e,col:r})=>{let a=t.doc.resolve(l.posAtIndex(e)+1),o=t.doc.resolve(a.posAtIndex(r)+1),c=o.node(),u=o.pos+(n>s?c.nodeSize-2:0);i.push(d.Decoration.widget(u,()=>{let e=document.createElement(`div`);return e.className=`bn-table-drop-cursor`,e.style.top=`0`,e.style.bottom=`0`,n>s?e.style.right=`-2px`:e.style.left=`-3px`,e.style.width=`4px`,e}))}),d.DecorationSet.create(t.doc,i)}}})],colDragStart(e){if(r===void 0||r.state===void 0||r.state.colIndex===void 0)throw Error(`Attempted to drag table column, but no table block was hovered prior.`);r.state.draggingState={draggedCellOrientation:`col`,originalIndex:r.state.colIndex,mousePos:e.clientX},r.emitUpdate(),n.transact(e=>e.setMeta(J,{draggedCellOrientation:r.state.draggingState.draggedCellOrientation,originalIndex:r.state.colIndex,newIndex:r.state.colIndex,tablePos:r.tablePos})),!n.headless&&(Ze(n.prosemirrorView.root),e.dataTransfer.setDragImage(G,0,0),e.dataTransfer.effectAllowed=`move`)},rowDragStart(e){if(r.state===void 0||r.state.rowIndex===void 0)throw Error(`Attempted to drag table row, but no table block was hovered prior.`);r.state.draggingState={draggedCellOrientation:`row`,originalIndex:r.state.rowIndex,mousePos:e.clientY},r.emitUpdate(),n.transact(e=>e.setMeta(J,{draggedCellOrientation:r.state.draggingState.draggedCellOrientation,originalIndex:r.state.rowIndex,newIndex:r.state.rowIndex,tablePos:r.tablePos})),!n.headless&&(Ze(n.prosemirrorView.root),e.dataTransfer.setDragImage(G,0,0),e.dataTransfer.effectAllowed=`copyMove`)},dragEnd(){if(r.state===void 0)throw Error(`Attempted to drag table row, but no table block was hovered prior.`);r.state.draggingState=void 0,r.emitUpdate(),n.transact(e=>e.setMeta(J,null)),!n.headless&&Qe(n.prosemirrorView.root)},freezeHandles(){r.menuFrozen=!0},unfreezeHandles(){r.menuFrozen=!1},hideHandlesIfNotFrozen(){!r.menuFrozen&&r.state?.show&&(r.state.show=!1,r.state.showAddOrRemoveRowsButton=!1,r.state.showAddOrRemoveColumnsButton=!1,r.emitUpdate())},getCellsAtRowHandle(t,n){return e.Bt(t,n)},getCellsAtColumnHandle(t,n){return e.zt(t,n)},setCellSelection(e,t,n=t){if(!r)throw Error(`Table handles view not initialized`);let i=e.doc.resolve(r.tablePos+1),a=e.doc.resolve(i.posAtIndex(t.row)+1),o=e.doc.resolve(a.posAtIndex(t.col)),s=e.doc.resolve(i.posAtIndex(n.row)+1),c=e.doc.resolve(s.posAtIndex(n.col)),u=e.tr;return u.setSelection(new l.CellSelection(o,c)),e.apply(u)},addRowOrColumn(e,t){n.exec((n,r)=>{let i=this.setCellSelection(n,t.orientation===`row`?{row:e,col:0}:{row:0,col:e});return t.orientation===`row`?t.side===`above`?(0,l.addRowBefore)(i,r):(0,l.addRowAfter)(i,r):t.side===`left`?(0,l.addColumnBefore)(i,r):(0,l.addColumnAfter)(i,r)})},removeRowOrColumn(e,t){return t===`row`?n.exec((t,n)=>(0,l.deleteRow)(this.setCellSelection(t,{row:e,col:0}),n)):n.exec((t,n)=>(0,l.deleteColumn)(this.setCellSelection(t,{row:0,col:e}),n))},mergeCells(e){return n.exec((t,n)=>(0,l.mergeCells)(e?this.setCellSelection(t,e.relativeStartCell,e.relativeEndCell):t,n))},splitCell(e){return n.exec((t,n)=>(0,l.splitCell)(e?this.setCellSelection(t,e):t,n))},getCellSelection(){return n.transact(t=>{let n=t.selection,r=n.$from,i=n.$to;if(e._(n)){let{ranges:e}=n;e.forEach(e=>{r=e.$from.min(r??e.$from),i=e.$to.max(i??e.$to)})}else if(r=t.doc.resolve(n.$from.pos-n.$from.parentOffset-1),i=t.doc.resolve(n.$to.pos-n.$to.parentOffset-1),r.pos===0||i.pos===0)return;let a=t.doc.resolve(r.pos-r.parentOffset-1),o=t.doc.resolve(i.pos-i.parentOffset-1),s=t.doc.resolve(a.pos-a.parentOffset-1),c=r.index(a.depth),l=a.index(s.depth),u=i.index(o.depth),d=o.index(s.depth),f=[];for(let e=l;e<=d;e++)for(let t=c;t<=u;t++)f.push({row:e,col:t});return{from:{row:l,col:c},to:{row:d,col:u},cells:f}})},getMergeDirection(t){return n.transact(n=>{let r=e._(n.selection)?n.selection:void 0;if(!r||!t||r.ranges.length<=1)return;let i=this.getCellSelection();if(i)return e.Ft(i.from,i.to,t)?`vertical`:`horizontal`})},cropEmptyRowsOrColumns(t,n){return e.Rt(t,n)},addRowsOrColumns(t,n,r){return e.Pt(t,n,r)}}}),Y=new s.PluginKey(`trailingNode`);function nt(e,t){if(!t)return!1;let n=e.lastChild?.lastChild,r=n?.firstChild;return!(n?.type.name===`blockContainer`&&r?.type.name===`paragraph`&&r.content.size===0)}var rt=t.t(({editor:e})=>{function t(t){return d.Decoration.widget(t,()=>{let t=document.createElement(`div`);return t.className=`bn-trailing-block`,t.contentEditable=`false`,t.addEventListener(`mousedown`,t=>{t.preventDefault(),e.transact(t=>{let[n]=e.insertBlocks([{type:`paragraph`}],e.document[e.document.length-1],`after`);e.setTextCursorPosition(n,`start`),t.scrollIntoView()}),e.prosemirrorView?.focus()}),t},{side:1})}function n(e,n,r){let i=n.map(e.mapping,e.doc),a=i.find(),o=a.length>0;return o===nt(e.doc,r)?i:o?i.remove(a):i.add(e.doc,[t(e.doc.content.size-1)])}return{key:`trailingNode`,prosemirrorPlugins:[new s.Plugin({key:Y,state:{init:(t,r)=>n(r.tr,d.DecorationSet.empty,e.isEditable),apply:(t,r)=>!t.docChanged&&!t.getMeta(Y)?r:n(t,r,e.isEditable)},view(e){let t=e.editable;return{update(e){e.editable!==t&&(t=e.editable,e.dispatch(e.state.tr.setMeta(Y,!0)))}}},props:{decorations:e=>Y.getState(e),handleKeyDown:(t,n)=>{if(n.key!==`ArrowRight`&&n.key!==`ArrowDown`)return!1;let{selection:r}=t.state;if(!r.empty)return!1;let i=s.Selection.atEnd(t.state.doc);return r.$head.pos!==i.$head.pos||!nt(t.state.doc,e.isEditable)?!1:(n.preventDefault(),!0)}}})]}}),X=Symbol(`bn-current-version`);function Z(e){return[...e].sort((e,t)=>t.createdAt-e.createdAt)}function Q(e){let t=typeof e==`object`?e.id:e;throw Error(`Snapshot not found: ${String(t)}`)}var it=t.t(({options:e,editor:r})=>{let{endpoints:i,preview:a,getCurrentDocument:o,serializeCurrentContent:s,resolveUsers:c}=typeof e==`function`?e(r):e,l=typeof i==`function`?i(r):i,u=n.n(c),d=t.n({snapshots:[],previewedSnapshotId:void 0,compareToSnapshotId:void 0}),f=e=>{let t=typeof e==`object`?e.id:e;return d.state.snapshots.find(e=>e.id===t)},p=async()=>{let e=Z(await l.list());return d.setState(t=>({...t,snapshots:e})),e},m=async(e,t)=>{let n=f(e);n||Q(e);let r=t?.compareTo?f(t.compareTo):void 0;d.setState(e=>({...e,previewedSnapshotId:n.id,compareToSnapshotId:r?.id}));let i,o;r&&(i=await l.getContent(r),l.getAttributions&&(o=await l.getAttributions(n,r)));let s=await l.getContent(n);a.enterPreview(s,i,o,{snapshot:n,compareTo:r})},h=async e=>{if(!s)throw Error("previewCurrentVersion requires `serializeCurrentContent` to be provided to the VersioningExtension options.");let t=e?.compareTo?f(e.compareTo):void 0;d.setState(e=>({...e,previewedSnapshotId:X,compareToSnapshotId:t?.id}));let n={id:X,createdAt:Date.now(),updatedAt:Date.now()},r,i;t&&(r=await l.getContent(t),l.getAttributions&&(i=await l.getAttributions(n,t)));let o=await s();a.enterPreview(o,r,i,{snapshot:n,compareTo:t})},g=()=>{d.setState(e=>({...e,previewedSnapshotId:void 0,compareToSnapshotId:void 0})),a.exitPreview()};return{key:`versioning`,store:d,userStore:u,list:async()=>await p(),get canCompare(){return a.supportsComparison!==!1},canCreate:l.create!==void 0,create:l.create?async e=>{let t=await l.create(o(),{name:e?.name,restoredFromSnapshot:f(e?.restoredFromSnapshot)});d.setState(e=>({...e,snapshots:Z([...e.snapshots,t])}));let n=await l.list();return d.setState(e=>({...e,snapshots:Z(n.some(e=>e.id===t.id)?n:[...n,t])})),t}:void 0,canRestore:l.restore!==void 0,restore:l.restore?async e=>{g();let t=f(e);t||Q(e);let n=await l.restore(o(),t);return a.applyRestore(n),await p(),n}:void 0,canRename:l.rename!==void 0,rename:l.rename?async(e,t)=>{let n=f(e);n||Q(e),await l.rename(n,t),d.setState(n=>({...n,snapshots:n.snapshots.map(n=>n.id===e?{...n,name:t,updatedAt:Date.now()}:n)}))}:void 0,canRemove:l.remove!==void 0,remove:l.remove?async e=>{let t=f(e);t||Q(e),(d.state.previewedSnapshotId===t.id||d.state.compareToSnapshotId===t.id)&&g(),await l.remove(t),d.setState(e=>({...e,snapshots:e.snapshots.filter(e=>e.id!==t.id)})),await p()}:void 0,previewSnapshot:m,canPreviewCurrent:s!==void 0,previewCurrentVersion:s?h:void 0,exitPreview:g}});function at(e){return e.id===X?`Current version`:e.name??`Unnamed version`}function ot(e){let t,n=!1,r=t=>{e.replaceBlocks(e.document,t)},i=()=>e.getExtension(`diffVersioning`);return{get supportsComparison(){return i()!==void 0},enterPreview(a,o,s,c){t===void 0&&(t=e.document);let l=i();if(o&&l){l.renderDiff(a,o,c&&at(c.snapshot)),n=!0;return}n=!1,r(a)},exitPreview(){if(t!==void 0){let e=i();n&&e?e.clearDiff(t):r(t),t=void 0,n=!1}},applyRestore(e){let a=i();n&&a?a.clearDiff(e):r(e),t=void 0,n=!1}}}function $(){let e=[],t=new Map,n=1;return{async list(){return Z([...e])},async create(r,i){let a=Date.now(),o=String(n++),s={id:o,name:i?.name,createdAt:a,updatedAt:a};return e.push(s),t.set(o,structuredClone(r)),s},async restore(r,i){let a=String(i.id),o=t.get(a);if(!o)throw Error(`Snapshot ${a} not found`);let s=Date.now(),c=String(n++),l={id:c,name:`Before restore`,createdAt:s,updatedAt:s,restoredFromSnapshotId:a};return e.push(l),t.set(c,structuredClone(r)),structuredClone(o)},async getContent(e){let n=String(e.id),r=t.get(n);if(!r)throw Error(`Snapshot ${n} not found`);return structuredClone(r)},async rename(t,n){let r=e.find(e=>e.id===t.id);if(!r)throw Error(`Snapshot ${String(t.id)} not found`);r.name=n,r.updatedAt=Date.now()},async remove(n){let r=e.findIndex(e=>e.id===n.id);if(r===-1)throw Error(`Snapshot ${String(n.id)} not found`);e.splice(r,1),t.delete(String(n.id))}}}function st(e){let t=$();return{endpoints:{...t,list:async()=>[{id:X,createdAt:Date.now(),updatedAt:Date.now()},...await t.list()]},preview:ot(e),getCurrentDocument:()=>e.document,serializeCurrentContent:()=>e.document}}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Xe}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Je}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Be}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return st}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return ve}});
//# sourceMappingURL=extensions-Ghr9QqqR.cjs.map