@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
3 lines (2 loc) • 45.8 kB
JavaScript
"use strict";var ye=Object.defineProperty;var we=(n,e,t)=>e in n?ye(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var b=(n,e,t)=>we(n,typeof e!="symbol"?e+"":e,t);const C=require("prosemirror-state"),R=require("@tiptap/core"),be=require("fast-deep-equal"),k=require("./blockToNode-CumVjgem.cjs"),O=require("./defaultBlocks-D1cc0lV9.cjs"),v=require("./BlockNoteExtension-BWw0r8Gy.cjs"),M=require("y-prosemirror"),ke=require("yjs"),V=require("@tiptap/pm/state"),Ce=require("prosemirror-dropcursor"),q=require("@tiptap/pm/history"),D=require("prosemirror-view"),ve=require("uuid"),Q=require("@tiptap/pm/model"),H=require("prosemirror-model"),xe=require("rehype-parse"),Se=require("rehype-remark"),Ee=require("remark-gfm"),Ie=require("remark-stringify"),Pe=require("unified"),Te=require("hast-util-from-dom"),Be=require("unist-util-visit"),T=require("prosemirror-tables"),F=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function De(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 Oe=F(be),B=De(ke),Me=F(xe),Ae=F(Se),Le=F(Ee),Ne=F(Ie);function ie(n){const e=Array.from(n.classList).filter(t=>!t.startsWith("bn-"))||[];e.length>0?n.className=e.join(" "):n.removeAttribute("class")}function ae(n,e,t,o){var a;let r;if(e)if(typeof e=="string")r=k.inlineContentToNodes([e],n.pmSchema);else if(Array.isArray(e))r=k.inlineContentToNodes(e,n.pmSchema);else if(e.type==="tableContent")r=k.tableContentToNodes(e,n.pmSchema);else throw new k.UnreachableCaseError(e.type);else throw new Error("blockContent is required");const i=((o==null?void 0:o.document)??document).createDocumentFragment();for(const c of r)if(c.type.name!=="text"&&n.schema.inlineContentSchema[c.type.name]){const l=n.schema.inlineContentSpecs[c.type.name].implementation;if(l){const m=k.nodeToCustomInlineContent(c,n.schema.inlineContentSchema,n.schema.styleSchema),h=l.toExternalHTML?l.toExternalHTML(m,n):l.render.call({renderType:"dom",props:void 0},m,()=>{},n);if(h){if(i.appendChild(h.dom),h.contentDOM){const f=t.serializeFragment(c.content,o);h.contentDOM.dataset.editable="",h.contentDOM.appendChild(f)}continue}}}else if(c.type.name==="text"){let l=document.createTextNode(c.textContent);for(const m of c.marks.toReversed())if(m.type.name in n.schema.styleSpecs){const h=(n.schema.styleSpecs[m.type.name].implementation.toExternalHTML??n.schema.styleSpecs[m.type.name].implementation.render)(m.attrs.stringValue,n);h.contentDOM.appendChild(l),l=h.dom}else{const h=m.type.spec.toDOM(m,!0),f=H.DOMSerializer.renderSpec(document,h);f.contentDOM.appendChild(l),l=f.dom}i.appendChild(l)}else{const l=t.serializeFragment(H.Fragment.from([c]),o);i.appendChild(l)}return i.childNodes.length===1&&((a=i.firstChild)==null?void 0:a.nodeType)===1&&ie(i.firstChild),i}function Re(n,e,t,o,r,s,i){var p,y,w,P,N,X,W,G,J;const a=(i==null?void 0:i.document)??document,c=e.pmSchema.nodes.blockContainer,l=t.props||{};for(const[x,E]of Object.entries(e.schema.blockSchema[t.type].propSchema))!(x in l)&&E.default!==void 0&&(l[x]=E.default);const m=(y=(p=c.spec)==null?void 0:p.toDOM)==null?void 0:y.call(p,c.create({id:t.id,...l})),h=Array.from(m.dom.attributes),f=e.blockImplementations[t.type].implementation,u=((w=f.toExternalHTML)==null?void 0:w.call({},{...t,props:l},e))||f.render.call({},{...t,props:l},e),g=a.createDocumentFragment();if(u.dom.classList.contains("bn-block-content")){const x=[...h,...Array.from(u.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(const E of x)u.dom.firstChild.setAttribute(E.name,E.value);ie(u.dom.firstChild),g.append(...Array.from(u.dom.childNodes))}else g.append(u.dom);if(u.contentDOM&&t.content){const x=ae(e,t.content,o,i);u.contentDOM.appendChild(x)}let d;if(r.has(t.type)?d="OL":s.has(t.type)&&(d="UL"),d){if(((P=n.lastChild)==null?void 0:P.nodeName)!==d){const x=a.createElement(d);d==="OL"&&"start"in l&&l.start&&(l==null?void 0:l.start)!==1&&x.setAttribute("start",l.start+""),n.append(x)}n.lastChild.appendChild(g)}else n.append(g);if(t.children&&t.children.length>0){const x=a.createDocumentFragment();if(le(x,e,t.children,o,r,s,i),((N=n.lastChild)==null?void 0:N.nodeName)==="UL"||((X=n.lastChild)==null?void 0:X.nodeName)==="OL")for(;((W=x.firstChild)==null?void 0:W.nodeName)==="UL"||((G=x.firstChild)==null?void 0:G.nodeName)==="OL";)n.lastChild.lastChild.appendChild(x.firstChild);e.pmSchema.nodes[t.type].isInGroup("blockContent")?n.append(x):(J=u.contentDOM)==null||J.append(x)}}const le=(n,e,t,o,r,s,i)=>{for(const a of t)Re(n,e,a,o,r,s,i)},Ve=(n,e,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return le(a,n,e,t,o,r,s),a},Y=(n,e)=>{const t=H.DOMSerializer.fromSchema(n);return{exportBlocks:(o,r)=>{const s=Ve(e,o,t,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem","toggleListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(o,r)=>{const s=ae(e,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function He(n,e){if(e===0)return;const t=n.resolve(e);for(let o=t.depth;o>0;o--){const r=t.node(o);if(O.isNodeBlock(r))return r.attrs.id}}function Fe(n){return n.getMeta("paste")?{type:"paste"}:n.getMeta("uiEvent")==="drop"?{type:"drop"}:n.getMeta("history$")?{type:n.getMeta("history$").redo?"redo":"undo"}:n.getMeta("y-sync$")?n.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}function Z(n){const e="__root__",t={},o={},r=k.getPmSchema(n);return n.descendants((s,i)=>{if(!O.isNodeBlock(s))return!0;const a=He(n,i),c=a??e;o[c]||(o[c]=[]);const l=k.nodeToBlock(s,r);return t[s.attrs.id]={block:l,parentId:a},o[c].push(s.attrs.id),!0}),{byId:t,childrenByParent:o}}function _e(n,e){const t=new Set;if(!n||!e)return t;const o=new Set(n),r=e.filter(d=>o.has(d)),s=n.filter(d=>r.includes(d));if(s.length<=1||r.length<=1)return t;const i={};for(let d=0;d<s.length;d++)i[s[d]]=d;const a=r.map(d=>i[d]),c=a.length,l=[],m=[],h=new Array(c).fill(-1),f=(d,p)=>{let y=0,w=d.length;for(;y<w;){const P=y+w>>>1;d[P]<p?y=P+1:w=P}return y};for(let d=0;d<c;d++){const p=a[d],y=f(l,p);y>0&&(h[d]=m[y-1]),y===l.length?(l.push(p),m.push(d)):(l[y]=p,m[y]=d)}const u=new Set;let g=m[m.length-1]??-1;for(;g!==-1;)u.add(g),g=h[g];for(let d=0;d<r.length;d++)u.has(d)||t.add(r[d]);return t}function ce(n,e=[]){const t=Fe(n),o=R.combineTransactionSteps(n.before,[n,...e]),r=Z(o.before),s=Z(o.doc),i=[],a=new Set;Object.keys(s.byId).filter(u=>!(u in r.byId)).forEach(u=>{i.push({type:"insert",block:s.byId[u].block,source:t,prevBlock:void 0}),a.add(u)}),Object.keys(r.byId).filter(u=>!(u in s.byId)).forEach(u=>{i.push({type:"delete",block:r.byId[u].block,source:t,prevBlock:void 0}),a.add(u)}),Object.keys(s.byId).filter(u=>u in r.byId).forEach(u=>{var y,w;const g=r.byId[u],d=s.byId[u];g.parentId!==d.parentId?(i.push({type:"move",block:d.block,prevBlock:g.block,source:t,prevParent:g.parentId?(y=r.byId[g.parentId])==null?void 0:y.block:void 0,currentParent:d.parentId?(w=s.byId[d.parentId])==null?void 0:w.block:void 0}),a.add(u)):Oe.default({...g.block,children:void 0},{...d.block,children:void 0})||(i.push({type:"update",block:d.block,prevBlock:g.block,source:t}),a.add(u))});const c=r.childrenByParent,l=s.childrenByParent,m="__root__",h=new Set([...Object.keys(c),...Object.keys(l)]),f=new Set;return h.forEach(u=>{const g=_e(c[u],l[u]);g.size!==0&&g.forEach(d=>{var P,N;const p=r.byId[d],y=s.byId[d];!p||!y||p.parentId!==y.parentId||a.has(d)||(p.parentId??m)!==u||f.has(d)||(f.add(d),i.push({type:"move",block:y.block,prevBlock:p.block,source:t,prevParent:p.parentId?(P=r.byId[p.parentId])==null?void 0:P.block:void 0,currentParent:y.parentId?(N=s.byId[y.parentId])==null?void 0:N.block:void 0}),a.add(d))})}),i}const Ue=v.createExtension(()=>{const n=[];return{key:"blockChange",prosemirrorPlugins:[new C.Plugin({key:new C.PluginKey("blockChange"),filterTransaction:e=>{let t;return n.reduce((o,r)=>o===!1?o:r({getChanges(){return t||(t=ce(e),t)},tr:e})!==!1,!0)}})],subscribe(e){return n.push(e),()=>{n.splice(n.indexOf(e),1)}}}});function ee(n){const e=n.charAt(0)==="#"?n.substring(1,7):n,t=parseInt(e.substring(0,2),16),o=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16),i=[t/255,o/255,r/255].map(c=>c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4));return .2126*i[0]+.7152*i[1]+.0722*i[2]<=.179}function $e(n){const e=document.createElement("span");e.classList.add("bn-collaboration-cursor__base");const t=document.createElement("span");t.setAttribute("contentedEditable","false"),t.classList.add("bn-collaboration-cursor__caret"),t.setAttribute("style",`background-color: ${n.color}; color: ${ee(n.color)?"white":"black"}`);const o=document.createElement("span");return o.classList.add("bn-collaboration-cursor__label"),o.setAttribute("style",`background-color: ${n.color}; color: ${ee(n.color)?"white":"black"}`),o.insertBefore(document.createTextNode(n.name),null),t.insertBefore(o,null),e.insertBefore(document.createTextNode(""),null),e.insertBefore(t,null),e.insertBefore(document.createTextNode(""),null),e}const z=v.createExtension(({options:n})=>{const e=new Map,t=n.provider&&"awareness"in n.provider&&typeof n.provider.awareness=="object"?n.provider.awareness:void 0;return t&&("setLocalStateField"in t&&typeof t.setLocalStateField=="function"&&t.setLocalStateField("user",n.user),"on"in t&&typeof t.on=="function"&&n.showCursorLabels!=="always"&&t.on("change",({updated:o})=>{for(const r of o){const s=e.get(r);s&&(s.element.setAttribute("data-active",""),s.hideTimeout&&clearTimeout(s.hideTimeout),e.set(r,{element:s.element,hideTimeout:setTimeout(()=>{s.element.removeAttribute("data-active")},2e3)}))}})),{key:"yCursor",prosemirrorPlugins:[t?M.yCursorPlugin(t,{selectionBuilder:M.defaultSelectionBuilder,cursorBuilder(o,r){let s=e.get(r);if(!s){const i=(n.renderCursor??$e)(o);n.showCursorLabels!=="always"&&(i.addEventListener("mouseenter",()=>{const a=e.get(r);a.element.setAttribute("data-active",""),a.hideTimeout&&(clearTimeout(a.hideTimeout),e.set(r,{element:a.element,hideTimeout:void 0}))}),i.addEventListener("mouseleave",()=>{const a=e.get(r);e.set(r,{element:a.element,hideTimeout:setTimeout(()=>{a.element.removeAttribute("data-active")},2e3)})})),s={element:i,hideTimeout:void 0},e.set(r,s)}return s.element}}):void 0].filter(Boolean),dependsOn:["ySync"],updateUser(o){t==null||t.setLocalStateField("user",o)}}}),U=v.createExtension(({options:n})=>({key:"ySync",prosemirrorPlugins:[M.ySyncPlugin(n.fragment)],runsBefore:["default"]})),$=v.createExtension(()=>({key:"yUndo",prosemirrorPlugins:[M.yUndoPlugin()],dependsOn:["yCursor","ySync"],undoCommand:M.undoCommand,redoCommand:M.redoCommand}));function qe(n,e){const t=n.doc;if(n._item===null){const o=Array.from(t.share.keys()).find(r=>t.share.get(r)===n);if(o==null)throw new Error("type does not exist in other ydoc");return e.get(o,n.constructor)}else{const o=n._item,r=e.store.clients.get(o.id.client)??[],s=B.findIndexSS(r,o.id.clock);return r[s].content.type}}const ze=v.createExtension(({editor:n,options:e})=>{let t;const o=v.createStore({isForked:!1});return{key:"yForkDoc",store:o,fork(){if(t)return;const r=e.fragment;if(!r)throw new Error("No fragment to fork from");const s=new B.Doc;B.applyUpdate(s,B.encodeStateAsUpdate(r.doc));const i=qe(r,s);t={undoStack:M.yUndoPluginKey.getState(n.prosemirrorState).undoManager.undoStack,originalFragment:r,forkedFragment:i},n.unregisterExtension([$,z,U]);const a={...e,fragment:i};n.registerExtension([U(a),$()]),o.setState({isForked:!0})},merge({keepChanges:r}){if(!t)return;n.unregisterExtension(["ySync","yCursor","yUndo"]);const{originalFragment:s,forkedFragment:i,undoStack:a}=t;if(n.registerExtension([U(e),z(e),$()]),M.yUndoPluginKey.getState(n.prosemirrorState).undoManager.undoStack=a,r){const c=B.encodeStateAsUpdate(i.doc,B.encodeStateVector(s.doc));B.applyUpdate(s.doc,c,n)}t=void 0,o.setState({isForked:!1})}}}),de=(n,e)=>{e(n),n.forEach(t=>{t instanceof B.XmlElement&&de(t,e)})},Ke=(n,e)=>{const t=new Map;return n.forEach(o=>{o instanceof B.XmlElement&&de(o,r=>{if(r.nodeName==="blockContainer"&&r.hasAttribute("id")){const s=r.getAttribute("textColor"),i=r.getAttribute("backgroundColor"),a={textColor:s===O.defaultProps.textColor.default?void 0:s,backgroundColor:i===O.defaultProps.backgroundColor.default?void 0:i};(a.textColor||a.backgroundColor)&&t.set(r.getAttribute("id"),a)}})}),t.size===0?!1:(e.doc.descendants((o,r)=>{if(o.type.name==="blockContainer"&&t.has(o.attrs.id)){const s=e.doc.nodeAt(r+1);if(!s)throw new Error("No element found");e.setNodeMarkup(r+1,void 0,{...s.attrs,...t.get(o.attrs.id)})}}),!0)},Ye=[Ke],je=v.createExtension(({options:n})=>{let e=!1;const t=new V.PluginKey("schemaMigration");return{key:"schemaMigration",prosemirrorPlugins:[new V.Plugin({key:t,appendTransaction:(o,r,s)=>{if(e||!o.some(a=>a.getMeta("y-sync$"))||o.every(a=>!a.docChanged)||!n.fragment.firstChild)return;const i=s.tr;for(const a of Ye)a(n.fragment,i);if(e=!0,!!i.docChanged)return i}})]}}),Xe=v.createExtension(({editor:n,options:e})=>({key:"dropCursor",prosemirrorPlugins:[(e.dropCursor??Ce.dropCursor)({width:5,color:"#ddeeff",editor:n})]})),We=v.createExtension(({editor:n})=>{const e=v.createStore(!1),t=()=>n.transact(o=>{var s;if(o.selection.empty||o.selection instanceof C.NodeSelection&&(o.selection.node.type.spec.content==="inline*"||((s=o.selection.node.firstChild)==null?void 0:s.type.spec.content)==="inline*")||o.selection instanceof C.TextSelection&&o.doc.textBetween(o.selection.from,o.selection.to).length===0)return!1;let r=!1;return o.selection.content().content.descendants(i=>(i.type.spec.code&&(r=!0),!r)),!r});return{key:"formattingToolbar",store:e,mount({dom:o,signal:r}){let s=!1;const i=n.onChange(()=>{s||e.setState(t())}),a=n.onSelectionChange(()=>{s||e.setState(t())});o.addEventListener("pointerdown",()=>{s=!0,e.setState(!1)},{signal:r}),n.prosemirrorView.root.addEventListener("pointerup",()=>{s=!1,n.isFocused()&&e.setState(t())},{signal:r,capture:!0}),o.addEventListener("pointercancel",()=>{s=!1},{signal:r,capture:!0}),r.addEventListener("abort",()=>{i(),a()})}}}),Ge=v.createExtension(()=>({key:"history",prosemirrorPlugins:[q.history()],undoCommand:q.undo,redoCommand:q.redo})),Je=v.createExtension(({editor:n})=>{function e(r){let s=n.prosemirrorView.nodeDOM(r);for(;s&&s.parentElement;){if(s.nodeName==="A")return s;s=s.parentElement}return null}function t(r,s){return n.transact(i=>{const a=i.doc.resolve(r),c=a.marks().find(m=>m.type.name===s);if(!c)return;const l=R.getMarkRange(a,c.type);if(l)return{range:l,mark:c,get text(){return i.doc.textBetween(l.from,l.to)},get position(){return R.posToDOMRect(n.prosemirrorView,l.from,l.to).toJSON()}}})}function o(){return n.transact(r=>{const s=r.selection;if(s.empty)return t(s.anchor,"link")})}return{key:"linkToolbar",getLinkAtSelection:o,getLinkElementAtPos:e,getMarkAtPos:t,getLinkAtElement(r){return n.transact(()=>{const s=n.prosemirrorView.posAtDOM(r,0)+1;return t(s,"link")})},editLink(r,s,i=n.transact(a=>a.selection.anchor)){n.transact(a=>{const c=k.getPmSchema(a),{range:l}=t(i+1,"link")||{range:{from:a.selection.from,to:a.selection.to}};l&&(a.insertText(s,l.from,l.to),a.addMark(l.from,l.from+s.length,c.mark("link",{href:r})))}),n.prosemirrorView.focus()},deleteLink(r=n.transact(s=>s.selection.anchor)){n.transact(s=>{const i=k.getPmSchema(s),{range:a}=t(r+1,"link")||{range:{from:s.selection.from,to:s.selection.to}};a&&s.removeMark(a.from,a.to,i.marks.link).setMeta("preventAutolink",!0)}),n.prosemirrorView.focus()}}}),Qe=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],Ze="https",et=new C.PluginKey("node-selection-keyboard"),tt=v.createExtension(()=>({key:"nodeSelectionKeyboard",prosemirrorPlugins:[new C.Plugin({key:et,props:{handleKeyDown:(n,e)=>{if("node"in n.state.selection){if(e.ctrlKey||e.metaKey)return!1;if(e.key.length===1)return e.preventDefault(),!0;if(e.key==="Enter"&&!e.shiftKey&&!e.altKey&&!e.ctrlKey&&!e.metaKey){const t=n.state.tr;return n.dispatch(t.insert(n.state.tr.selection.$to.after(),n.state.schema.nodes.paragraph.createChecked()).setSelection(new C.TextSelection(t.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}})]})),ot=new C.PluginKey("blocknote-placeholder"),nt=v.createExtension(({editor:n,options:e})=>{const t=e.placeholders;return{key:"placeholder",prosemirrorPlugins:[new C.Plugin({key:ot,view:o=>{const r=`placeholder-selector-${ve.v4()}`;o.dom.classList.add(r);const s=document.createElement("style"),i=n._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),o.root instanceof window.ShadowRoot?o.root.append(s):o.root.head.appendChild(s);const a=s.sheet,c=(l="")=>`.${r} .bn-block-content${l} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:l,emptyDocument:m,...h}=t||{};for(const[g,d]of Object.entries(h)){const p=`[data-content-type="${g}"]`;a.insertRule(`${c(p)} { content: ${JSON.stringify(d)}; }`)}const f="[data-is-only-empty-block]",u="[data-is-empty-and-focused]";a.insertRule(`${c(f)} { content: ${JSON.stringify(m)}; }`),a.insertRule(`${c(u)} { content: ${JSON.stringify(l)}; }`)}catch(l){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)",l)}return{destroy:()=>{o.root instanceof window.ShadowRoot?o.root.removeChild(s):o.root.head.removeChild(s)}}},props:{decorations:o=>{const{doc:r,selection:s}=o;if(!n.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];o.doc.content.size===6&&i.push(D.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const a=s.$anchor,c=a.parent;if(c.content.size===0){const l=a.before();i.push(D.Decoration.node(l,l+c.nodeSize,{"data-is-empty-and-focused":"true"}))}return D.DecorationSet.create(r,i)}}})]}}),te=new C.PluginKey("previous-blocks"),rt={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},st=v.createExtension(()=>{let n;return{key:"previousBlockType",prosemirrorPlugins:[new C.Plugin({key:te,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(te,{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 s={},i=R.findChildren(o.doc,l=>l.attrs.id),a=new Map(i.map(l=>[l.node.attrs.id,l])),c=R.findChildren(r.doc,l=>l.attrs.id);for(const l of c){const m=a.get(l.node.attrs.id),h=m==null?void 0:m.node.firstChild,f=l.node.firstChild;if(m&&h&&f){const u={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:r.doc.resolve(l.pos).depth},g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(m.pos).depth};s[l.node.attrs.id]=g,t.currentTransactionOldBlockAttrs[l.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(u)&&(g["depth-change"]=g.depth-u.depth,t.updatedBlocks.add(l.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=s,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const o=[];return e.doc.descendants((r,s)=>{if(!r.attrs.id||!t.updatedBlocks.has(r.attrs.id))return;const i=t.currentTransactionOldBlockAttrs[r.attrs.id],a={};for(const[l,m]of Object.entries(i))a["data-prev-"+rt[l]]=m||"none";const c=D.Decoration.node(s,s+r.nodeSize,{...a});o.push(c)}),D.DecorationSet.create(e.doc,o)}}})]}});function ue(n,e){var t,o;for(;n&&n.parentElement&&n.parentElement!==e.dom&&((t=n.getAttribute)==null?void 0:t.call(n,"data-node-type"))!=="blockContainer";)n=n.parentElement;if(((o=n.getAttribute)==null?void 0:o.call(n,"data-node-type"))==="blockContainer")return{node:n,id:n.getAttribute("data-id")}}function it(){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 s=r.children.length-1;t+=s,o+=s}else e.children.splice(o,1),t--,o--}};return n}function at(){const n=e=>{var t;if(e.children&&"length"in e.children&&e.children.length)for(let o=e.children.length-1;o>=0;o--){const r=e.children[o],s=o+1<e.children.length?e.children[o+1]:void 0;r.type==="element"&&r.tagName==="input"&&((t=r.properties)==null?void 0:t.type)==="checkbox"&&(s==null?void 0:s.type)==="element"&&s.tagName==="p"?(s.tagName="span",s.children.splice(0,0,Te.fromDom(document.createTextNode(" ")))):n(r)}};return n}function lt(){return n=>{Be.visit(n,"element",(e,t,o)=>{var r,s,i,a;if(o&&e.tagName==="video"){const c=((r=e.properties)==null?void 0:r.src)||((s=e.properties)==null?void 0:s["data-url"])||"",l=((i=e.properties)==null?void 0:i.title)||((a=e.properties)==null?void 0:a["data-name"])||"";o.children[t]={type:"text",value:``}}})}}function j(n){return Pe.unified().use(Me.default,{fragment:!0}).use(lt).use(it).use(at).use(Ae.default).use(Le.default).use(Ne.default,{handlers:{text:t=>t.value}}).processSync(n).value}function ct(n,e,t,o){const s=Y(e,t).exportBlocks(n,o);return j(s)}function he(n){const e=[];return n.descendants(t=>{var r,s;const o=k.getPmSchema(t);return t.type.name==="blockContainer"&&((r=t.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:t.type.name==="columnList"&&t.childCount===1?((s=t.firstChild)==null||s.forEach(i=>{e.push(k.nodeToBlock(i,o))}),!1):t.type.isInGroup("bnBlock")?(e.push(k.nodeToBlock(t,o)),!1):!0}),e}class A extends C.Selection{constructor(t,o){super(t,o);b(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(t,o,r=o){return new A(t.resolve(o),t.resolve(r))}content(){return new H.Slice(H.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){const r=o.mapResult(this.from),s=o.mapResult(this.to);return s.deleted?C.Selection.near(t.resolve(r.pos)):r.deleted?C.Selection.near(t.resolve(s.pos)):new A(t.resolve(r.pos),t.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}C.Selection.jsonID("multiple-node",A);let I;function dt(n,e){let t,o;const r=e.resolve(n.from).node().type.spec.group==="blockContent",s=e.resolve(n.to).node().type.spec.group==="blockContent",i=Math.min(n.$anchor.depth,n.$head.depth);if(r&&s){const a=n.$from.start(i-1),c=n.$to.end(i-1);t=e.resolve(a-1).pos,o=e.resolve(c+1).pos}else t=n.from,o=n.to;return{from:t,to:o}}function oe(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,s=(h,f)=>Array.prototype.indexOf.call(h.children,f),i=s(r,n.domAtPos(e+1).node.parentElement),a=s(r,n.domAtPos(t-1).node.parentElement);for(let h=r.childElementCount-1;h>=0;h--)(h>a||h<i)&&o.removeChild(o.children[h]);me(n.root),I=o;const c=I.getElementsByTagName("iframe");for(let h=0;h<c.length;h++){const f=c[h],u=f.parentElement;u&&u.removeChild(f)}const m=n.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");I.className=I.className+" bn-drag-preview "+m,n.root instanceof ShadowRoot?n.root.appendChild(I):n.root.body.appendChild(I)}function me(n){I!==void 0&&(n instanceof ShadowRoot?n.removeChild(I):n.body.removeChild(I),I=void 0)}function ut(n,e,t){if(!n.dataTransfer||t.headless)return;const o=t.prosemirrorView,r=O.getNodeById(e.id,o.state.doc);if(!r)throw new Error(`Block with ID ${e.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=o.state.selection,a=o.state.doc,{from:c,to:l}=dt(i,a),m=c<=s&&s<l,h=i.$anchor.node()!==i.$head.node()||i instanceof A;m&&h?(o.dispatch(o.state.tr.setSelection(A.create(a,c,l))),oe(o,c,l)):(o.dispatch(o.state.tr.setSelection(C.NodeSelection.create(o.state.doc,s))),oe(o,s));const f=o.state.selection.content(),u=t.pmSchema,g=o.serializeForClipboard(f).dom.innerHTML,d=Y(u,t),p=he(f.content),y=d.exportBlocks(p,{}),w=j(y);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",g),n.dataTransfer.setData("text/html",y),n.dataTransfer.setData("text/plain",w),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(I,0,0)}}const ne=250;function K(n,e,t=!0){const o=n.root.elementsFromPoint(e.left,e.top);for(const r of o)if(n.dom.contains(r))return t&&r.closest("[data-node-type=columnList]")?K(n,{left:e.left+50,top:e.top},!1):ue(r,n)}function ht(n,e){if(!e.dom.firstChild)return;const t=e.dom.firstChild.getBoundingClientRect(),o={left:Math.min(Math.max(t.left+10,n.x),t.right-10),top:n.y},r=K(e,o);if(!r)return;const s=r.node.getBoundingClientRect();return K(e,{left:s.right-10,top:n.y},!1)}class pe{constructor(e,t,o){b(this,"state");b(this,"emitUpdate");b(this,"mousePos");b(this,"hoveredBlock");b(this,"menuFrozen",!1);b(this,"isDragOrigin",!1);b(this,"updateState",e=>{this.state=e,this.emitUpdate(this.state)});b(this,"updateStateFromMousePos",()=>{var o,r,s,i,a;if(this.menuFrozen||!this.mousePos)return;const e=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((e==null?void 0:e.element)!==this.pmView.dom||e.distance>ne){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}const t=ht(this.mousePos,this.pmView);if(!t||!this.editor.isEditable){(r=this.state)!=null&&r.show&&(this.state.show=!1,this.updateState(this.state));return}if(!((s=this.state)!=null&&s.show&&((i=this.hoveredBlock)!=null&&i.hasAttribute("data-id"))&&((a=this.hoveredBlock)==null?void 0:a.getAttribute("data-id"))===t.id)&&(this.hoveredBlock=t.node,this.editor.isEditable)){const c=t.node.getBoundingClientRect(),l=t.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(l?l.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,c.y,c.width,c.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}});b(this,"onDragStart",e=>{var i;const t=(i=e.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!t||this.pmView.dragging)return;const o=document.createElement("div");o.innerHTML=t;const s=Q.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new Q.Slice(s.content,0,0),move:!0}});b(this,"findClosestEditorElement",e=>{const t=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(t.length===0)return null;let o=t[0],r=Number.MAX_VALUE;return t.forEach(s=>{const i=s.querySelector(".bn-block-group").getBoundingClientRect(),a=e.clientX<i.left?i.left-e.clientX:e.clientX>i.right?e.clientX-i.right:0,c=e.clientY<i.top?i.top-e.clientY:e.clientY>i.bottom?e.clientY-i.bottom:0,l=Math.sqrt(Math.pow(a,2)+Math.pow(c,2));l<r&&(r=l,o=s)}),{element:o,distance:r}});b(this,"onDragOver",e=>{if(e.synthetic)return;const t=this.getDragEventContext(e);if(!t||!t.isDropPoint){this.closeDropCursor();return}t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(e)});b(this,"closeDropCursor",()=>{const e=new Event("dragleave",{bubbles:!1});e.synthetic=!0,this.pmView.dom.dispatchEvent(e)});b(this,"getDragEventContext",e=>{var c;const t=!((c=e.dataTransfer)!=null&&c.types.includes("blocknote/html"))&&!!this.pmView.dragging,o=!!this.isDragOrigin,r=t||o,s=this.findClosestEditorElement(e);if(!s||s.distance>ne)return;const i=s.element===this.pmView.dom,a=i&&s.distance===0;if(!(!i&&!r))return{isDropPoint:i,isDropWithinEditorBounds:a,isDragOrigin:r}});b(this,"onDrop",e=>{if(e.synthetic)return;const t=this.getDragEventContext(e);if(!t){this.closeDropCursor();return}const{isDropPoint:o,isDropWithinEditorBounds:r,isDragOrigin:s}=t;if(!r&&o&&this.dispatchSyntheticEvent(e),o){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(V.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)));return}else if(s){setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0);return}});b(this,"onDragEnd",e=>{e.synthetic||(this.pmView.dragging=null)});b(this,"onKeyDown",e=>{var t;(t=this.state)!=null&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});b(this,"onMouseMove",e=>{var s;if(this.menuFrozen)return;this.mousePos={x:e.clientX,y:e.clientY};const t=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom,r=this.pmView.dom.parentElement;if(o&&e&&e.target&&!(r===e.target||r.contains(e.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(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)}dispatchSyntheticEvent(e){const t=new Event(e.type,e),o=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=e.clientX,t.clientY=e.clientY,t.clientX=Math.min(Math.max(e.clientX,o.left),o.left+o.width),t.clientY=Math.min(Math.max(e.clientY,o.top),o.top+o.height),t.dataTransfer=e.dataTransfer,t.preventDefault=()=>e.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(e,t){var r;!t.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var e;(e=this.state)!=null&&e.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)}}const fe=new V.PluginKey("SideMenuPlugin"),mt=v.createExtension(({editor:n})=>{let e;const t=v.createStore(void 0);return{key:"sideMenu",store:t,prosemirrorPlugins:[new V.Plugin({key:fe,view:o=>(e=new pe(n,o,r=>{t.setState({...r})}),e)})],blockDragStart(o,r){e&&(e.isDragOrigin=!0),ut(o,r,n)},blockDragEnd(){me(n.prosemirrorView.root),e&&(e.isDragOrigin=!1),n.blur()},freezeMenu(){e.menuFrozen=!0,e.state.show=!0,e.emitUpdate(e.state)},unfreezeMenu(){e.menuFrozen=!1,e.state.show=!1,e.emitUpdate(e.state)}}});let S;function re(n){S||(S=document.createElement("div"),S.innerHTML="_",S.style.opacity="0",S.style.height="1px",S.style.width="1px",n instanceof Document?n.body.appendChild(S):n.appendChild(S))}function pt(n){S&&(n instanceof Document?n.body.removeChild(S):n.removeChild(S),S=void 0)}function _(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function ft(n){let e=n;for(;e&&e.nodeName!=="TD"&&e.nodeName!=="TH"&&!e.classList.contains("tableWrapper");){if(e.classList.contains("ProseMirror"))return;const t=e.parentNode;if(!t||!(t instanceof Element))return;e=t}return e.nodeName==="TD"||e.nodeName==="TH"?{type:"cell",domNode:e,tbodyNode:e.closest("tbody")}:{type:"wrapper",domNode:e,tbodyNode:e.querySelector("tbody")}}function gt(n,e){const t=e.querySelectorAll(n);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class ge{constructor(e,t,o){b(this,"state");b(this,"emitUpdate");b(this,"tableId");b(this,"tablePos");b(this,"tableElement");b(this,"menuFrozen",!1);b(this,"mouseState","up");b(this,"prevWasEditable",null);b(this,"viewMousedownHandler",()=>{this.mouseState="down"});b(this,"mouseUpHandler",e=>{this.mouseState="up",this.mouseMoveHandler(e)});b(this,"mouseMoveHandler",e=>{var l,m,h,f,u,g,d;if(this.menuFrozen||this.mouseState==="selecting"||!(e.target instanceof Element)||!this.pmView.dom.contains(e.target))return;const t=ft(e.target);if((t==null?void 0:t.type)==="cell"&&this.mouseState==="down"&&!((l=this.state)!=null&&l.draggingState)){this.mouseState="selecting",(m=this.state)!=null&&m.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t||!this.editor.isEditable){(h=this.state)!=null&&h.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!t.tbodyNode)return;const o=t.tbodyNode.getBoundingClientRect(),r=ue(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(p=>O.getNodeById(r.id,p.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const a=k.nodeToBlock(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(O.editorHasBlockWithType(this.editor,"table")&&(this.tablePos=i.posBeforeNode+1,s=a),!s)return;this.tableId=r.id;const c=(f=t.domNode.closest(".tableWrapper"))==null?void 0:f.querySelector(".table-widgets-container");if((t==null?void 0:t.type)==="wrapper"){const p=e.clientY>=o.bottom-1&&e.clientY<o.bottom+20,y=e.clientX>=o.right-1&&e.clientX<o.right+20,w=e.clientX>o.right||e.clientY>o.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:p,showAddOrRemoveColumnsButton:y,referencePosTable:o,block:s,widgetContainer:c,colIndex:w||(u=this.state)==null?void 0:u.colIndex,rowIndex:w||(g=this.state)==null?void 0:g.rowIndex,referencePosCell:w||(d=this.state)==null?void 0:d.referencePosCell}}else{const p=_(t.domNode),y=_(t.domNode.parentElement),w=t.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===y&&this.state.colIndex===p)return;this.state={show:!0,showAddOrRemoveColumnsButton:p===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:y===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:w,colIndex:p,rowIndex:y,widgetContainer:c}}return this.emitUpdate(),!1});b(this,"dragOverHandler",e=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect="move",gt(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const 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)},o=this.pmView.root.elementsFromPoint(t.left,t.top).filter(u=>u.tagName==="TD"||u.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=_(r.parentElement),a=_(r),c=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,m=(this.state.draggingState.draggedCellOrientation==="row"?i:a)!==c;(this.state.rowIndex!==i||this.state.colIndex!==a)&&(this.state.rowIndex=i,this.state.colIndex=a,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,s=!0),s&&this.emitUpdate(),m&&this.editor.transact(u=>u.setMeta(L,!0))});b(this,"dropHandler",e=>{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 new Error("Attempted to drop table row or column, but no table block was hovered prior.");e.preventDefault();const{draggingState:t,colIndex:o,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(t.draggedCellOrientation==="row"){if(!k.canRowBeDraggedInto(this.state.block,t.originalIndex,r))return!1;const i=k.moveRow(this.state.block,t.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!k.canColumnBeDraggedInto(this.state.block,t.originalIndex,o))return!1;const i=k.moveColumn(this.state.block,t.originalIndex,o),[a]=s.splice(t.originalIndex,1);s.splice(o,0,a),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:s,rows:i}})}return this.editor.setTextCursorPosition(this.state.block.id),!0});this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(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)}update(){var r;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"||!((r=this.tableElement)!=null&&r.isConnected)){this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate();return}const{height:e,width:t}=k.getDimensionsOfTable(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=e&&(this.state.rowIndex=e-1),this.state.colIndex>=t&&(this.state.colIndex=t-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new 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){const i=o.children[this.state.rowIndex].children[this.state.colIndex];i?this.state.referencePosCell=i.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.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)}}const L=new C.PluginKey("TableHandlesPlugin"),yt=v.createExtension(({editor:n})=>{let e;const t=v.createStore(void 0);return{key:"tableHandles",store:t,prosemirrorPlugins:[new C.Plugin({key:L,view:o=>(e=new ge(n,o,r=>{t.setState(r.block?{...r,draggingState:r.draggingState?{...r.draggingState}:void 0}:void 0)}),e),props:{decorations:o=>{if(e===void 0||e.state===void 0||e.state.draggingState===void 0||e.tablePos===void 0)return;const r=e.state.draggingState.draggedCellOrientation==="row"?e.state.rowIndex:e.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:a}=e.state,{originalIndex:c,draggedCellOrientation:l}=a;if(r===c||!i||l==="row"&&!k.canRowBeDraggedInto(i,c,r)||l==="col"&&!k.canColumnBeDraggedInto(i,c,r))return D.DecorationSet.create(o.doc,s);const m=o.doc.resolve(e.tablePos+1);return e.state.draggingState.draggedCellOrientation==="row"?k.getCellsAtRowHandle(e.state.block,r).forEach(({row:f,col:u})=>{const g=o.doc.resolve(m.posAtIndex(f)+1),d=o.doc.resolve(g.posAtIndex(u)+1),p=d.node(),y=d.pos+(r>c?p.nodeSize-2:0);s.push(D.Decoration.widget(y,()=>{const w=document.createElement("div");return w.className="bn-table-drop-cursor",w.style.left="0",w.style.right="0",r>c?w.style.bottom="-2px":w.style.top="-3px",w.style.height="4px",w}))}):k.getCellsAtColumnHandle(e.state.block,r).forEach(({row:f,col:u})=>{const g=o.doc.resolve(m.posAtIndex(f)+1),d=o.doc.resolve(g.posAtIndex(u)+1),p=d.node(),y=d.pos+(r>c?p.nodeSize-2:0);s.push(D.Decoration.widget(y,()=>{const w=document.createElement("div");return w.className="bn-table-drop-cursor",w.style.top="0",w.style.bottom="0",r>c?w.style.right="-2px":w.style.left="-3px",w.style.width="4px",w}))}),D.DecorationSet.create(o.doc,s)}}})],colDragStart(o){if(e===void 0||e.state===void 0||e.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");e.state.draggingState={draggedCellOrientation:"col",originalIndex:e.state.colIndex,mousePos:o.clientX},e.emitUpdate(),n.transact(r=>r.setMeta(L,{draggedCellOrientation:e.state.draggingState.draggedCellOrientation,originalIndex:e.state.colIndex,newIndex:e.state.colIndex,tablePos:e.tablePos})),!n.headless&&(re(n.prosemirrorView.root),o.dataTransfer.setDragImage(S,0,0),o.dataTransfer.effectAllowed="move")},rowDragStart(o){if(e.state===void 0||e.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");e.state.draggingState={draggedCellOrientation:"row",originalIndex:e.state.rowIndex,mousePos:o.clientY},e.emitUpdate(),n.transact(r=>r.setMeta(L,{draggedCellOrientation:e.state.draggingState.draggedCellOrientation,originalIndex:e.state.rowIndex,newIndex:e.state.rowIndex,tablePos:e.tablePos})),!n.headless&&(re(n.prosemirrorView.root),o.dataTransfer.setDragImage(S,0,0),o.dataTransfer.effectAllowed="copyMove")},dragEnd(){if(e.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");e.state.draggingState=void 0,e.emitUpdate(),n.transact(o=>o.setMeta(L,null)),!n.headless&&pt(n.prosemirrorView.root)},freezeHandles(){e.menuFrozen=!0},unfreezeHandles(){e.menuFrozen=!1},getCellsAtRowHandle(o,r){return k.getCellsAtRowHandle(o,r)},getCellsAtColumnHandle(o,r){return k.getCellsAtColumnHandle(o,r)},setCellSelection(o,r,s=r){if(!e)throw new Error("Table handles view not initialized");const i=o.doc.resolve(e.tablePos+1),a=o.doc.resolve(i.posAtIndex(r.row)+1),c=o.doc.resolve(a.posAtIndex(r.col)),l=o.doc.resolve(i.posAtIndex(s.row)+1),m=o.doc.resolve(l.posAtIndex(s.col)),h=o.tr;return h.setSelection(new T.CellSelection(c,m)),o.apply(h)},addRowOrColumn(o,r){n.exec((s,i)=>{const a=this.setCellSelection(s,r.orientation==="row"?{row:o,col:0}:{row:0,col:o});return r.orientation==="row"?r.side==="above"?T.addRowBefore(a,i):T.addRowAfter(a,i):r.side==="left"?T.addColumnBefore(a,i):T.addColumnAfter(a,i)})},removeRowOrColumn(o,r){return r==="row"?n.exec((s,i)=>{const a=this.setCellSelection(s,{row:o,col:0});return T.deleteRow(a,i)}):n.exec((s,i)=>{const a=this.setCellSelection(s,{row:0,col:o});return T.deleteColumn(a,i)})},mergeCells(o){return n.exec((r,s)=>{const i=o?this.setCellSelection(r,o.relativeStartCell,o.relativeEndCell):r;return T.mergeCells(i,s)})},splitCell(o){return n.exec((r,s)=>{const i=o?this.setCellSelection(r,o):r;return T.splitCell(i,s)})},getCellSelection(){return n.transact(o=>{const r=o.selection;let s=r.$from,i=r.$to;if(O.isTableCellSelection(r)){const{ranges:d}=r;d.forEach(p=>{s=p.$from.min(s??p.$from),i=p.$to.max(i??p.$to)})}else if(s=o.doc.resolve(r.$from.pos-r.$from.parentOffset-1),i=o.doc.resolve(r.$to.pos-r.$to.parentOffset-1),s.pos===0||i.pos===0)return;const a=o.doc.resolve(s.pos-s.parentOffset-1),c=o.doc.resolve(i.pos-i.parentOffset-1),l=o.doc.resolve(a.pos-a.parentOffset-1),m=s.index(a.depth),h=a.index(l.depth),f=i.index(c.depth),u=c.index(l.depth),g=[];for(let d=h;d<=u;d++)for(let p=m;p<=f;p++)g.push({row:d,col:p});return{from:{row:h,col:m},to:{row:u,col:f},cells:g}})},getMergeDirection(o){return n.transact(r=>{const s=O.isTableCellSelection(r.selection)?r.selection:void 0;if(!s||!o||s.ranges.length<=1)return;const i=this.getCellSelection();if(i)return k.areInSameColumn(i.from,i.to,o)?"vertical":"horizontal"})},cropEmptyRowsOrColumns(o,r){return k.cropEmptyRowsOrColumns(o,r)},addRowsOrColumns(o,r,s){return k.addRowsOrColumns(o,r,s)}}}),se=new C.PluginKey("trailingNode"),wt=v.createExtension(()=>({key:"trailingNode",prosemirrorPlugins:[new C.Plugin({key:se,appendTransaction:(n,e,t)=>{const{doc:o,tr:r,schema:s}=t,i=se.getState(t),a=o.content.size-2,c=s.nodes.blockContainer,l=s.nodes.paragraph;if(i)return r.insert(a,c.create(void 0,l.create()))},state:{init:(n,e)=>{},apply:(n,e)=>{if(!n.docChanged)return e;let t=n.doc.lastChild;if(!t||t.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(t=t.lastChild,!t||t.type.name!=="blockContainer")return!0;const o=t.firstChild;if(!o)throw new Error("Expected blockContent");return t.nodeSize>4||o.type.spec.content!=="inline*"}}})]}));exports.BlockChangeExtension=Ue;exports.DEFAULT_LINK_PROTOCOL=Ze;exports.DropCursorExtension=Xe;exports.ForkYDocExtension=ze;exports.FormattingToolbarExtension=We;exports.HistoryExtension=Ge;exports.LinkToolbarExtension=Je;exports.NodeSelectionKeyboardExtension=tt;exports.PlaceholderExtension=nt;exports.PreviousBlockTypeExtension=st;exports.SchemaMigration=je;exports.SideMenuExtension=mt;exports.SideMenuView=pe;exports.TableHandlesExtension=yt;exports.TableHandlesView=ge;exports.TrailingNodeExtension=wt;exports.VALID_LINK_PROTOCOLS=Qe;exports.YCursorExtension=z;exports.YSyncExtension=U;exports.YUndoExtension=$;exports.blocksToMarkdown=ct;exports.cleanHTMLToMarkdown=j;exports.createExternalHTMLExporter=Y;exports.fragmentToBlocks=he;exports.getBlocksChangedByTransaction=ce;exports.sideMenuPluginKey=fe;exports.tableHandlesPluginKey=L;
//# sourceMappingURL=TrailingNode-DPu6X9ym.cjs.map