@blocknote/core 0.43.0 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ "use strict";var we=Object.defineProperty;var ye=(n,e,o)=>e in n?we(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o;var b=(n,e,o)=>ye(n,typeof e!="symbol"?e+"":e,o);const C=require("prosemirror-state"),R=require("@tiptap/core"),be=require("fast-deep-equal"),k=require("./blockToNode-w7H99R6p.cjs"),O=require("./defaultBlocks-DLJ4Q1_J.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 o in n)if(o!=="default"){const t=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(e,o,t.get?t:{enumerable:!0,get:()=>n[o]})}}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(o=>!o.startsWith("bn-"))||[];e.length>0?n.className=e.join(" "):n.removeAttribute("class")}function ae(n,e,o,t){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=((t==null?void 0:t.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=o.serializeFragment(c.content,t);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=o.serializeFragment(H.Fragment.from([c]),t);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,o,t,r,s,i){var p,w,y,P,N,X,W,G,J;const a=(i==null?void 0:i.document)??document,c=e.pmSchema.nodes.blockContainer,l=o.props||{};for(const[x,E]of Object.entries(e.schema.blockSchema[o.type].propSchema))!(x in l)&&E.default!==void 0&&(l[x]=E.default);const m=(w=(p=c.spec)==null?void 0:p.toDOM)==null?void 0:w.call(p,c.create({id:o.id,...l})),h=Array.from(m.dom.attributes),f=e.blockImplementations[o.type].implementation,u=((y=f.toExternalHTML)==null?void 0:y.call({},{...o,props:l},e))||f.render.call({},{...o,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&&o.content){const x=ae(e,o.content,t,i);u.contentDOM.appendChild(x)}let d;if(r.has(o.type)?d="OL":s.has(o.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(o.children&&o.children.length>0){const x=a.createDocumentFragment();if(le(x,e,o.children,t,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[o.type].isInGroup("blockContent")?n.append(x):(J=u.contentDOM)==null||J.append(x)}}const le=(n,e,o,t,r,s,i)=>{for(const a of o)Re(n,e,a,t,r,s,i)},Ve=(n,e,o,t,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return le(a,n,e,o,t,r,s),a},Y=(n,e)=>{const o=H.DOMSerializer.fromSchema(n);return{exportBlocks:(t,r)=>{const s=Ve(e,t,o,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem","toggleListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(t,r)=>{const s=ae(e,t,o,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function He(n,e){if(e===0)return;const o=n.resolve(e);for(let t=o.depth;t>0;t--){const r=o.node(t);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__",o={},t={},r=k.getPmSchema(n);return n.descendants((s,i)=>{if(!O.isNodeBlock(s))return!0;const a=He(n,i),c=a??e;t[c]||(t[c]=[]);const l=k.nodeToBlock(s,r);return o[s.attrs.id]={block:l,parentId:a},t[c].push(s.attrs.id),!0}),{byId:o,childrenByParent:t}}function _e(n,e){const o=new Set;if(!n||!e)return o;const t=new Set(n),r=e.filter(d=>t.has(d)),s=n.filter(d=>r.includes(d));if(s.length<=1||r.length<=1)return o;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 w=0,y=d.length;for(;w<y;){const P=w+y>>>1;d[P]<p?w=P+1:y=P}return w};for(let d=0;d<c;d++){const p=a[d],w=f(l,p);w>0&&(h[d]=m[w-1]),w===l.length?(l.push(p),m.push(d)):(l[w]=p,m[w]=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)||o.add(r[d]);return o}function ce(n,e=[]){const o=Fe(n),t=R.combineTransactionSteps(n.before,[n,...e]),r=Z(t.before),s=Z(t.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:o,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:o,prevBlock:void 0}),a.add(u)}),Object.keys(s.byId).filter(u=>u in r.byId).forEach(u=>{var w,y;const g=r.byId[u],d=s.byId[u];g.parentId!==d.parentId?(i.push({type:"move",block:d.block,prevBlock:g.block,source:o,prevParent:g.parentId?(w=r.byId[g.parentId])==null?void 0:w.block:void 0,currentParent:d.parentId?(y=s.byId[d.parentId])==null?void 0:y.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:o}),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],w=s.byId[d];!p||!w||p.parentId!==w.parentId||a.has(d)||(p.parentId??m)!==u||f.has(d)||(f.add(d),i.push({type:"move",block:w.block,prevBlock:p.block,source:o,prevParent:p.parentId?(P=r.byId[p.parentId])==null?void 0:P.block:void 0,currentParent:w.parentId?(N=s.byId[w.parentId])==null?void 0:N.block:void 0}),a.add(d))})}),i}function Ue(){const n=e=>{let o=e.children.length;for(let t=0;t<o;t++){const r=e.children[t];if(r.type==="element"&&(n(r),r.tagName==="u"))if(r.children.length>0){e.children.splice(t,1,...r.children);const s=r.children.length-1;o+=s,t+=s}else e.children.splice(t,1),o--,t--}};return n}function $e(){const n=e=>{var o;if(e.children&&"length"in e.children&&e.children.length)for(let t=e.children.length-1;t>=0;t--){const r=e.children[t],s=t+1<e.children.length?e.children[t+1]:void 0;r.type==="element"&&r.tagName==="input"&&((o=r.properties)==null?void 0:o.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 qe(){return n=>{Be.visit(n,"element",(e,o,t)=>{var r,s,i,a;if(t&&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"])||"";t.children[o]={type:"text",value:`![${l}](${c})`}}})}}function j(n){return Pe.unified().use(Me.default,{fragment:!0}).use(qe).use(Ue).use($e).use(Ae.default).use(Le.default).use(Ne.default,{handlers:{text:o=>o.value}}).processSync(n).value}function ze(n,e,o,t){const s=Y(e,o).exportBlocks(n,t);return j(s)}function de(n){const e=[];return n.descendants(o=>{var r,s;const t=k.getPmSchema(o);return o.type.name==="blockContainer"&&((r=o.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:o.type.name==="columnList"&&o.childCount===1?((s=o.firstChild)==null||s.forEach(i=>{e.push(k.nodeToBlock(i,t))}),!1):o.type.isInGroup("bnBlock")?(e.push(k.nodeToBlock(o,t)),!1):!0}),e}const Ke=v.createExtension(()=>{const n=[];return{key:"blockChange",prosemirrorPlugins:[new C.Plugin({key:new C.PluginKey("blockChange"),filterTransaction:e=>{let o;return n.reduce((t,r)=>t===!1?t:r({getChanges(){return o||(o=ce(e),o)},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,o=parseInt(e.substring(0,2),16),t=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16),i=[o/255,t/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 Ye(n){const e=document.createElement("span");e.classList.add("bn-collaboration-cursor__base");const o=document.createElement("span");o.setAttribute("contentedEditable","false"),o.classList.add("bn-collaboration-cursor__caret"),o.setAttribute("style",`background-color: ${n.color}; color: ${ee(n.color)?"white":"black"}`);const t=document.createElement("span");return t.classList.add("bn-collaboration-cursor__label"),t.setAttribute("style",`background-color: ${n.color}; color: ${ee(n.color)?"white":"black"}`),t.insertBefore(document.createTextNode(n.name),null),o.insertBefore(t,null),e.insertBefore(document.createTextNode("⁠"),null),e.insertBefore(o,null),e.insertBefore(document.createTextNode("⁠"),null),e}const z=v.createExtension(({options:n})=>{const e=new Map;return n.provider&&"awareness"in n.provider&&typeof n.provider.awareness=="object"&&("setLocalStateField"in n.provider.awareness&&typeof n.provider.awareness.setLocalStateField=="function"&&n.provider.awareness.setLocalStateField("user",n.user),"on"in n.provider.awareness&&typeof n.provider.awareness.on=="function"&&n.showCursorLabels!=="always"&&n.provider.awareness.on("change",({updated:o})=>{for(const t of o){const r=e.get(t);r&&(r.element.setAttribute("data-active",""),r.hideTimeout&&clearTimeout(r.hideTimeout),e.set(t,{element:r.element,hideTimeout:setTimeout(()=>{r.element.removeAttribute("data-active")},2e3)}))}})),{key:"yCursor",prosemirrorPlugins:[M.yCursorPlugin(n.provider.awareness,{selectionBuilder:M.defaultSelectionBuilder,cursorBuilder(o,t){let r=e.get(t);if(!r){const s=(n.renderCursor??Ye)(o);n.showCursorLabels!=="always"&&(s.addEventListener("mouseenter",()=>{const i=e.get(t);i.element.setAttribute("data-active",""),i.hideTimeout&&(clearTimeout(i.hideTimeout),e.set(t,{element:i.element,hideTimeout:void 0}))}),s.addEventListener("mouseleave",()=>{const i=e.get(t);e.set(t,{element:i.element,hideTimeout:setTimeout(()=>{i.element.removeAttribute("data-active")},2e3)})})),r={element:s,hideTimeout:void 0},e.set(t,r)}return r.element}})],dependsOn:["ySync"],updateUser(o){n.provider.awareness.setLocalStateField("user",o)}}}),U=v.createExtension(({options:n})=>({key:"ySync",prosemirrorPlugins:[M.ySyncPlugin(n.fragment)],runsBefore:["default"]})),$=v.createExtension(({editor:n})=>({key:"yUndo",prosemirrorPlugins:[M.yUndoPlugin({trackedOrigins:[n]})],dependsOn:["yCursor","ySync"],undoCommand:M.undoCommand,redoCommand:M.redoCommand}));function je(n,e){const o=n.doc;if(n._item===null){const t=Array.from(o.share.keys()).find(r=>o.share.get(r)===n);if(t==null)throw new Error("type does not exist in other ydoc");return e.get(t,n.constructor)}else{const t=n._item,r=e.store.clients.get(t.id.client)??[],s=B.findIndexSS(r,t.id.clock);return r[s].content.type}}const Xe=v.createExtension(({editor:n,options:e})=>{let o;const t=v.createStore({isForked:!1});return{key:"yForkDoc",store:t,fork(){if(o)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=je(r,s);o={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),$({})]),t.setState({isForked:!0})},merge({keepChanges:r}){if(!o)return;n.unregisterExtension(["ySync","yCursor","yUndo"]);const{originalFragment:s,forkedFragment:i,undoStack:a}=o;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)}o=void 0,t.setState({isForked:!1})}}}),ue=(n,e)=>{e(n),n.forEach(o=>{o instanceof B.XmlElement&&ue(o,e)})},We=(n,e)=>{const o=new Map;return n.forEach(t=>{t instanceof B.XmlElement&&ue(t,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)&&o.set(r.getAttribute("id"),a)}})}),o.size===0?!1:(e.doc.descendants((t,r)=>{if(t.type.name==="blockContainer"&&o.has(t.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,...o.get(t.attrs.id)})}}),!0)},Ge=[We],Je=v.createExtension(({options:n})=>{let e=!1;const o=new V.PluginKey("schemaMigration");return{key:"schemaMigration",prosemirrorPlugins:[new V.Plugin({key:o,appendTransaction:(t,r,s)=>{if(e||!t.some(a=>a.getMeta("y-sync$"))||t.every(a=>!a.docChanged)||!n.fragment.firstChild)return;const i=s.tr;for(const a of Ge)a(n.fragment,i);if(e=!0,!!i.docChanged)return i}})]}}),Qe=v.createExtension(({editor:n,options:e})=>({key:"dropCursor",prosemirrorPlugins:[(e.dropCursor??Ce.dropCursor)({width:5,color:"#ddeeff",editor:n})]})),Ze=v.createExtension(({editor:n})=>{const e=v.createStore(!1),o=()=>n.transact(t=>{var s;if(t.selection.empty||t.selection instanceof C.NodeSelection&&(t.selection.node.type.spec.content==="inline*"||((s=t.selection.node.firstChild)==null?void 0:s.type.spec.content)==="inline*")||t.selection instanceof C.TextSelection&&t.doc.textBetween(t.selection.from,t.selection.to).length===0)return!1;let r=!1;return t.selection.content().content.descendants(i=>(i.type.spec.code&&(r=!0),!r)),!r});return{key:"formattingToolbar",store:e,mount({dom:t,signal:r}){let s=!1;const i=n.onChange(()=>{s||e.setState(o())}),a=n.onSelectionChange(()=>{s||e.setState(o())});t.addEventListener("pointerdown",()=>{s=!0,e.setState(!1)},{signal:r}),n.prosemirrorView.root.addEventListener("pointerup",()=>{s=!1,n.isFocused()&&e.setState(o())},{signal:r,capture:!0}),t.addEventListener("pointercancel",()=>{s=!1},{signal:r,capture:!0}),r.addEventListener("abort",()=>{i(),a()})}}}),et=v.createExtension(()=>({key:"history",prosemirrorPlugins:[q.history()],undoCommand:q.undo,redoCommand:q.redo})),tt=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 o(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 t(){return n.transact(r=>{const s=r.selection;if(s.empty)return o(s.anchor,"link")})}return{key:"linkToolbar",getLinkAtSelection:t,getLinkElementAtPos:e,getMarkAtPos:o,getLinkAtElement(r){return n.transact(()=>{const s=n.prosemirrorView.posAtDOM(r,0)+1;return o(s,"link")})},editLink(r,s,i=n.transact(a=>a.selection.anchor)){n.transact(a=>{const c=k.getPmSchema(a),{range:l}=o(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}=o(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()}}}),ot=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],nt="https",rt=new C.PluginKey("node-selection-keyboard"),st=v.createExtension(()=>({key:"nodeSelectionKeyboard",prosemirrorPlugins:[new C.Plugin({key:rt,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 o=n.state.tr;return n.dispatch(o.insert(n.state.tr.selection.$to.after(),n.state.schema.nodes.paragraph.createChecked()).setSelection(new C.TextSelection(o.doc.resolve(n.state.tr.selection.$to.after()+1)))),!0}}return!1}}})]})),it=new C.PluginKey("blocknote-placeholder"),at=v.createExtension(({editor:n,options:e})=>{const o=e.placeholders;return{key:"placeholder",prosemirrorPlugins:[new C.Plugin({key:it,view:t=>{const r=`placeholder-selector-${ve.v4()}`;t.dom.classList.add(r);const s=document.createElement("style"),i=n._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),t.root instanceof window.ShadowRoot?t.root.append(s):t.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}=o||{};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:()=>{t.root instanceof window.ShadowRoot?t.root.removeChild(s):t.root.head.removeChild(s)}}},props:{decorations:t=>{const{doc:r,selection:s}=t;if(!n.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];t.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"),lt={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},ct=v.createExtension(()=>{let n;return{key:"previousBlockType",prosemirrorPlugins:[new C.Plugin({key:te,view(e){return{update:async(o,t)=>{var r;((r=this.key)==null?void 0:r.getState(o.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{o.dispatch(o.state.tr.setMeta(te,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,o,t,r){if(o.currentTransactionOldBlockAttrs={},o.updatedBlocks.clear(),!e.docChanged||t.doc.eq(r.doc))return o;const s={},i=R.findChildren(t.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:t.doc.resolve(m.pos).depth};s[l.node.attrs.id]=g,o.currentTransactionOldBlockAttrs[l.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(u)&&(g["depth-change"]=g.depth-u.depth,o.updatedBlocks.add(l.node.attrs.id))}}return o.prevTransactionOldBlockAttrs=s,o}},props:{decorations(e){const o=this.getState(e);if(o.updatedBlocks.size===0)return;const t=[];return e.doc.descendants((r,s)=>{if(!r.attrs.id||!o.updatedBlocks.has(r.attrs.id))return;const i=o.currentTransactionOldBlockAttrs[r.attrs.id],a={};for(const[l,m]of Object.entries(i))a["data-prev-"+lt[l]]=m||"none";const c=D.Decoration.node(s,s+r.nodeSize,{...a});t.push(c)}),D.DecorationSet.create(e.doc,t)}}})]}});function he(n,e){var o,t;for(;n&&n.parentElement&&n.parentElement!==e.dom&&((o=n.getAttribute)==null?void 0:o.call(n,"data-node-type"))!=="blockContainer";)n=n.parentElement;if(((t=n.getAttribute)==null?void 0:t.call(n,"data-node-type"))==="blockContainer")return{node:n,id:n.getAttribute("data-id")}}class A extends C.Selection{constructor(o,t){super(o,t);b(this,"nodes");const r=o.node();this.nodes=[],o.doc.nodesBetween(o.pos,t.pos,(s,i,a)=>{if(a!==null&&a.eq(r))return this.nodes.push(s),!1})}static create(o,t,r=t){return new A(o.resolve(t),o.resolve(r))}content(){return new H.Slice(H.Fragment.from(this.nodes),0,0)}eq(o){if(!(o instanceof A)||this.nodes.length!==o.nodes.length||this.from!==o.from||this.to!==o.to)return!1;for(let t=0;t<this.nodes.length;t++)if(!this.nodes[t].eq(o.nodes[t]))return!1;return!0}map(o,t){const r=t.mapResult(this.from),s=t.mapResult(this.to);return s.deleted?C.Selection.near(o.resolve(r.pos)):r.deleted?C.Selection.near(o.resolve(s.pos)):new A(o.resolve(r.pos),o.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 o,t;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);o=e.resolve(a-1).pos,t=e.resolve(c+1).pos}else o=n.from,t=n.to;return{from:o,to:t}}function oe(n,e,o=e){e===o&&(o+=n.state.doc.resolve(e+1).node().nodeSize);const t=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(o-1).node.parentElement);for(let h=r.childElementCount-1;h>=0;h--)(h>a||h<i)&&t.removeChild(t.children[h]);me(n.root),I=t;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,o){if(!n.dataTransfer||o.headless)return;const t=o.prosemirrorView,r=O.getNodeById(e.id,t.state.doc);if(!r)throw new Error(`Block with ID ${e.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=t.state.selection,a=t.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?(t.dispatch(t.state.tr.setSelection(A.create(a,c,l))),oe(t,c,l)):(t.dispatch(t.state.tr.setSelection(C.NodeSelection.create(t.state.doc,s))),oe(t,s));const f=t.state.selection.content(),u=o.pmSchema,g=t.serializeForClipboard(f).dom.innerHTML,d=Y(u,o),p=de(f.content),w=d.exportBlocks(p,{}),y=j(w);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",g),n.dataTransfer.setData("text/html",w),n.dataTransfer.setData("text/plain",y),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(I,0,0)}}const ne=250;function K(n,e,o=!0){const t=n.root.elementsFromPoint(e.left,e.top);for(const r of t)if(n.dom.contains(r))return o&&r.closest("[data-node-type=columnList]")?K(n,{left:e.left+50,top:e.top},!1):he(r,n)}function ht(n,e){if(!e.dom.firstChild)return;const o=e.dom.firstChild.getBoundingClientRect(),t={left:Math.min(Math.max(o.left+10,n.x),o.right-10),top:n.y},r=K(e,t);if(!r)return;const s=r.node.getBoundingClientRect();return K(e,{left:s.right-10,top:n.y},!1)}class pe{constructor(e,o,t){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 t,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){(t=this.state)!=null&&t.show&&(this.state.show=!1,this.updateState(this.state));return}const o=ht(this.mousePos,this.pmView);if(!o||!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"))===o.id)&&(this.hoveredBlock=o.node,this.editor.isEditable)){const c=o.node.getBoundingClientRect(),l=o.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 o=(i=e.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!o||this.pmView.dragging)return;const t=document.createElement("div");t.innerHTML=o;const s=Q.DOMParser.fromSchema(this.pmView.state.schema).parse(t,{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 o=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(o.length===0)return null;let t=o[0],r=Number.MAX_VALUE;return o.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,t=s)}),{element:t,distance:r}});b(this,"onDragOver",e=>{if(e.synthetic)return;const o=this.getDragEventContext(e);if(!o||!o.isDropPoint){this.closeDropCursor();return}o.isDropPoint&&!o.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 o=!((c=e.dataTransfer)!=null&&c.types.includes("blocknote/html"))&&!!this.pmView.dragging,t=!!this.isDragOrigin,r=o||t,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 o=this.getDragEventContext(e);if(!o){this.closeDropCursor();return}const{isDropPoint:t,isDropWithinEditorBounds:r,isDragOrigin:s}=o;if(!r&&t&&this.dispatchSyntheticEvent(e),t){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 o;(o=this.state)!=null&&o.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 o=this.pmView.dom.getBoundingClientRect(),t=this.mousePos.x>o.left&&this.mousePos.x<o.right&&this.mousePos.y>o.top&&this.mousePos.y<o.bottom,r=this.pmView.dom.parentElement;if(t&&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=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");t(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 o=new Event(e.type,e),t=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=e.clientX,o.clientY=e.clientY,o.clientX=Math.min(Math.max(e.clientX,t.left),t.left+t.width),o.clientY=Math.min(Math.max(e.clientY,t.top),t.top+t.height),o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}update(e,o){var r;!o.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 o=v.createStore(void 0);return{key:"sideMenu",store:o,prosemirrorPlugins:[new V.Plugin({key:fe,view:t=>(e=new pe(n,t,r=>{o.setState({...r})}),e)})],blockDragStart(t,r){e&&(e.isDragOrigin=!0),ut(t,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 o=e.parentNode;if(!o||!(o instanceof Element))return;e=o}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 o=e.querySelectorAll(n);for(let t=0;t<o.length;t++)o[t].style.visibility="hidden"}class ge{constructor(e,o,t){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 o=ft(e.target);if((o==null?void 0:o.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(!o||!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(!o.tbodyNode)return;const t=o.tbodyNode.getBoundingClientRect(),r=he(o.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=o.domNode.closest(".tableWrapper"))==null?void 0:f.querySelector(".table-widgets-container");if((o==null?void 0:o.type)==="wrapper"){const p=e.clientY>=t.bottom-1&&e.clientY<t.bottom+20,w=e.clientX>=t.right-1&&e.clientX<t.right+20,y=e.clientX>t.right||e.clientY>t.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:p,showAddOrRemoveColumnsButton:w,referencePosTable:t,block:s,widgetContainer:c,colIndex:y||(u=this.state)==null?void 0:u.colIndex,rowIndex:y||(g=this.state)==null?void 0:g.rowIndex,referencePosCell:y||(d=this.state)==null?void 0:d.referencePosCell}}else{const p=_(o.domNode),w=_(o.domNode.parentElement),y=o.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===w&&this.state.colIndex===p)return;this.state={show:!0,showAddOrRemoveColumnsButton:p===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:w===s.content.rows.length-1,referencePosTable:t,block:s,draggingState:void 0,referencePosCell:y,colIndex:p,rowIndex:w,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 o={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)},t=this.pmView.root.elementsFromPoint(o.left,o.top).filter(u=>u.tagName==="TD"||u.tagName==="TH");if(t.length===0)return;const r=t[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"?o.top:o.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:o,colIndex:t,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(o.draggedCellOrientation==="row"){if(!k.canRowBeDraggedInto(this.state.block,o.originalIndex,r))return!1;const i=k.moveRow(this.state.block,o.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!k.canColumnBeDraggedInto(this.state.block,o.originalIndex,t))return!1;const i=k.moveColumn(this.state.block,o.originalIndex,t),[a]=s.splice(o.originalIndex,1);s.splice(t,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=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");t(this.state)},o.dom.addEventListener("mousemove",this.mouseMoveHandler),o.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),o.root.addEventListener("dragover",this.dragOverHandler),o.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:o}=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>=o&&(this.state.colIndex=o-1));const t=this.tableElement.querySelector("tbody");if(!t)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=t.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=t.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"),wt=v.createExtension(({editor:n})=>{let e;const o=v.createStore(void 0);return{key:"tableHandles",store:o,prosemirrorPlugins:[new C.Plugin({key:L,view:t=>(e=new ge(n,t,r=>{o.setState({...r,draggingState:r.draggingState?{...r.draggingState}:void 0})}),e),props:{decorations:t=>{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(t.doc,s);const m=t.doc.resolve(e.tablePos+1);return e.state.draggingState.draggedCellOrientation==="row"?k.getCellsAtRowHandle(e.state.block,r).forEach(({row:f,col:u})=>{const g=t.doc.resolve(m.posAtIndex(f)+1),d=t.doc.resolve(g.posAtIndex(u)+1),p=d.node(),w=d.pos+(r>c?p.nodeSize-2:0);s.push(D.Decoration.widget(w,()=>{const y=document.createElement("div");return y.className="bn-table-drop-cursor",y.style.left="0",y.style.right="0",r>c?y.style.bottom="-2px":y.style.top="-3px",y.style.height="4px",y}))}):k.getCellsAtColumnHandle(e.state.block,r).forEach(({row:f,col:u})=>{const g=t.doc.resolve(m.posAtIndex(f)+1),d=t.doc.resolve(g.posAtIndex(u)+1),p=d.node(),w=d.pos+(r>c?p.nodeSize-2:0);s.push(D.Decoration.widget(w,()=>{const y=document.createElement("div");return y.className="bn-table-drop-cursor",y.style.top="0",y.style.bottom="0",r>c?y.style.right="-2px":y.style.left="-3px",y.style.width="4px",y}))}),D.DecorationSet.create(t.doc,s)}}})],colDragStart(t){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:t.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),t.dataTransfer.setDragImage(S,0,0),t.dataTransfer.effectAllowed="move")},rowDragStart(t){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:t.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),t.dataTransfer.setDragImage(S,0,0),t.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(t=>t.setMeta(L,null)),!n.headless&&pt(n.prosemirrorView.root)},freezeHandles(){e.menuFrozen=!0},unfreezeHandles(){e.menuFrozen=!1},getCellsAtRowHandle(t,r){return k.getCellsAtRowHandle(t,r)},getCellsAtColumnHandle(t,r){return k.getCellsAtColumnHandle(t,r)},setCellSelection(t,r,s=r){if(!e)throw new Error("Table handles view not initialized");const i=t.doc.resolve(e.tablePos+1),a=t.doc.resolve(i.posAtIndex(r.row)+1),c=t.doc.resolve(a.posAtIndex(r.col)),l=t.doc.resolve(i.posAtIndex(s.row)+1),m=t.doc.resolve(l.posAtIndex(s.col)),h=t.tr;return h.setSelection(new T.CellSelection(c,m)),t.apply(h)},addRowOrColumn(t,r){n.exec((s,i)=>{const a=this.setCellSelection(s,r.orientation==="row"?{row:t,col:0}:{row:0,col:t});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(t,r){return r==="row"?n.exec((s,i)=>{const a=this.setCellSelection(s,{row:t,col:0});return T.deleteRow(a,i)}):n.exec((s,i)=>{const a=this.setCellSelection(s,{row:0,col:t});return T.deleteColumn(a,i)})},mergeCells(t){return n.exec((r,s)=>{const i=t?this.setCellSelection(r,t.relativeStartCell,t.relativeEndCell):r;return T.mergeCells(i,s)})},splitCell(t){return n.exec((r,s)=>{const i=t?this.setCellSelection(r,t):r;return T.splitCell(i,s)})},getCellSelection(){return n.transact(t=>{const r=t.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=t.doc.resolve(r.$from.pos-r.$from.parentOffset-1),i=t.doc.resolve(r.$to.pos-r.$to.parentOffset-1),s.pos===0||i.pos===0)return;const a=t.doc.resolve(s.pos-s.parentOffset-1),c=t.doc.resolve(i.pos-i.parentOffset-1),l=t.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(t){return n.transact(r=>{const s=O.isTableCellSelection(r.selection)?r.selection:void 0;if(!s||!t||s.ranges.length<=1)return;const i=this.getCellSelection();if(i)return k.areInSameColumn(i.from,i.to,t)?"vertical":"horizontal"})},cropEmptyRowsOrColumns(t,r){return k.cropEmptyRowsOrColumns(t,r)},addRowsOrColumns(t,r,s){return k.addRowsOrColumns(t,r,s)}}}),se=new C.PluginKey("trailingNode"),yt=v.createExtension(()=>({key:"trailingNode",prosemirrorPlugins:[new C.Plugin({key:se,appendTransaction:(n,e,o)=>{const{doc:t,tr:r,schema:s}=o,i=se.getState(o),a=t.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 o=n.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")return!0;const t=o.firstChild;if(!t)throw new Error("Expected blockContent");return o.nodeSize>4||t.type.spec.content!=="inline*"}}})]}));exports.BlockChangeExtension=Ke;exports.DEFAULT_LINK_PROTOCOL=nt;exports.DropCursorExtension=Qe;exports.ForkYDocExtension=Xe;exports.FormattingToolbarExtension=Ze;exports.HistoryExtension=et;exports.LinkToolbarExtension=tt;exports.NodeSelectionKeyboardExtension=st;exports.PlaceholderExtension=at;exports.PreviousBlockTypeExtension=ct;exports.SchemaMigration=Je;exports.SideMenuExtension=mt;exports.SideMenuView=pe;exports.TableHandlesExtension=wt;exports.TableHandlesView=ge;exports.TrailingNodeExtension=yt;exports.VALID_LINK_PROTOCOLS=ot;exports.YCursorExtension=z;exports.YSyncExtension=U;exports.YUndoExtension=$;exports.blocksToMarkdown=ze;exports.cleanHTMLToMarkdown=j;exports.createExternalHTMLExporter=Y;exports.fragmentToBlocks=de;exports.getBlocksChangedByTransaction=ce;exports.sideMenuPluginKey=fe;exports.tableHandlesPluginKey=L;
2
+ //# sourceMappingURL=TrailingNode-CRHrgOnK.cjs.map