@blocknote/core 0.44.2 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +1 -1
  2. package/dist/BlockNoteExtension-C2X7LW-V.js.map +1 -1
  3. package/dist/{BlockNoteSchema-BsTi0fNS.js → BlockNoteSchema-DsMVJZv4.js} +2 -2
  4. package/dist/{BlockNoteSchema-BsTi0fNS.js.map → BlockNoteSchema-DsMVJZv4.js.map} +1 -1
  5. package/dist/{BlockNoteSchema-CBNkNhkw.cjs → BlockNoteSchema-qt4Czo0-.cjs} +2 -2
  6. package/dist/{BlockNoteSchema-CBNkNhkw.cjs.map → BlockNoteSchema-qt4Czo0-.cjs.map} +1 -1
  7. package/dist/ShowSelection-B0ch3unP.js +51 -0
  8. package/dist/ShowSelection-B0ch3unP.js.map +1 -0
  9. package/dist/ShowSelection-BxnbRvy4.cjs +2 -0
  10. package/dist/ShowSelection-BxnbRvy4.cjs.map +1 -0
  11. package/dist/{TrailingNode-CG2a-HDA.js → TrailingNode-C-Kyrtf1.js} +715 -709
  12. package/dist/TrailingNode-C-Kyrtf1.js.map +1 -0
  13. package/dist/TrailingNode-W7GJVng5.cjs +2 -0
  14. package/dist/TrailingNode-W7GJVng5.cjs.map +1 -0
  15. package/dist/{blockToNode-DBNbhwwC.js → blockToNode-BNoNIXU7.js} +2 -2
  16. package/dist/{blockToNode-DBNbhwwC.js.map → blockToNode-BNoNIXU7.js.map} +1 -1
  17. package/dist/{blockToNode-w7H99R6p.cjs → blockToNode-CumVjgem.cjs} +2 -2
  18. package/dist/{blockToNode-w7H99R6p.cjs.map → blockToNode-CumVjgem.cjs.map} +1 -1
  19. package/dist/blocknote.cjs +4 -4
  20. package/dist/blocknote.cjs.map +1 -1
  21. package/dist/blocknote.js +1118 -1077
  22. package/dist/blocknote.js.map +1 -1
  23. package/dist/blocks.cjs +1 -1
  24. package/dist/blocks.js +2 -2
  25. package/dist/comments.cjs +1 -1
  26. package/dist/comments.cjs.map +1 -1
  27. package/dist/comments.js +3 -3
  28. package/dist/comments.js.map +1 -1
  29. package/dist/{defaultBlocks-B63ufZ5N.js → defaultBlocks-CXOCngjC.js} +273 -312
  30. package/dist/defaultBlocks-CXOCngjC.js.map +1 -0
  31. package/dist/defaultBlocks-IsUGVZIq.cjs +6 -0
  32. package/dist/defaultBlocks-IsUGVZIq.cjs.map +1 -0
  33. package/dist/extensions.cjs +1 -1
  34. package/dist/extensions.js +4 -4
  35. package/dist/style.css +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/dist/webpack-stats.json +1 -1
  38. package/dist/yjs.cjs +1 -1
  39. package/dist/yjs.js +1 -1
  40. package/package.json +18 -18
  41. package/src/api/blockManipulation/selections/selection.ts +9 -4
  42. package/src/api/blockManipulation/tables/tables.test.ts +140 -0
  43. package/src/api/blockManipulation/tables/tables.ts +1 -1
  44. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +17 -0
  45. package/src/api/parsers/markdown/parseMarkdown.ts +11 -0
  46. package/src/blocks/ListItem/BulletListItem/block.ts +1 -1
  47. package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
  48. package/src/blocks/ListItem/NumberedListItem/block.ts +6 -2
  49. package/src/comments/extension.ts +6 -2
  50. package/src/editor/Block.css +1 -1
  51. package/src/editor/BlockNoteEditor.test.ts +0 -1
  52. package/src/editor/BlockNoteEditor.ts +9 -39
  53. package/src/editor/BlockNoteExtension.ts +5 -0
  54. package/src/editor/managers/EventManager.ts +1 -1
  55. package/src/editor/managers/ExtensionManager/extensions.ts +3 -13
  56. package/src/editor/managers/ExtensionManager/index.ts +7 -2
  57. package/src/editor/managers/SelectionManager.ts +10 -10
  58. package/src/extensions/BlockChange/BlockChange.ts +2 -2
  59. package/src/extensions/Collaboration/Collaboration.ts +55 -0
  60. package/src/extensions/Collaboration/ForkYDoc.ts +4 -9
  61. package/src/extensions/Collaboration/YCursorPlugin.ts +56 -60
  62. package/src/extensions/Collaboration/YSync.ts +2 -2
  63. package/src/extensions/Collaboration/YUndo.ts +2 -2
  64. package/src/extensions/LinkToolbar/LinkToolbar.ts +1 -1
  65. package/src/extensions/ShowSelection/ShowSelection.ts +14 -4
  66. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +40 -68
  67. package/src/extensions/TableHandles/TableHandles.ts +9 -5
  68. package/src/index.ts +2 -1
  69. package/src/schema/blocks/createSpec.ts +3 -0
  70. package/src/util/expandToWords.ts +38 -0
  71. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  72. package/types/src/editor/BlockNoteEditor.d.ts +5 -34
  73. package/types/src/editor/BlockNoteExtension.d.ts +4 -0
  74. package/types/src/editor/managers/SelectionManager.d.ts +4 -4
  75. package/types/src/extensions/Collaboration/Collaboration.d.ts +76 -0
  76. package/types/src/extensions/Collaboration/ForkYDoc.d.ts +2 -11
  77. package/types/src/extensions/Collaboration/YCursorPlugin.d.ts +3 -11
  78. package/types/src/extensions/Collaboration/YSync.d.ts +2 -4
  79. package/types/src/extensions/Collaboration/YUndo.d.ts +1 -1
  80. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +10 -4
  81. package/types/src/index.d.ts +2 -1
  82. package/types/src/util/expandToWords.d.ts +13 -0
  83. package/dist/ShowSelection-BW37oJ6h.cjs +0 -2
  84. package/dist/ShowSelection-BW37oJ6h.cjs.map +0 -1
  85. package/dist/ShowSelection-Dz-NEase.js +0 -43
  86. package/dist/ShowSelection-Dz-NEase.js.map +0 -1
  87. package/dist/TrailingNode-CG2a-HDA.js.map +0 -1
  88. package/dist/TrailingNode-Du4SNHun.cjs +0 -2
  89. package/dist/TrailingNode-Du4SNHun.cjs.map +0 -1
  90. package/dist/defaultBlocks-B63ufZ5N.js.map +0 -1
  91. package/dist/defaultBlocks-BX6UxQa8.cjs +0 -6
  92. package/dist/defaultBlocks-BX6UxQa8.cjs.map +0 -1
@@ -0,0 +1,2 @@
1
+ "use strict";var we=Object.defineProperty;var be=(n,e,t)=>e in n?we(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var b=(n,e,t)=>be(n,typeof e!="symbol"?e+"":e,t);const C=require("prosemirror-state"),R=require("@tiptap/core"),ke=require("fast-deep-equal"),k=require("./blockToNode-CumVjgem.cjs"),O=require("./defaultBlocks-IsUGVZIq.cjs"),v=require("./BlockNoteExtension-BWw0r8Gy.cjs"),M=require("y-prosemirror"),Ce=require("yjs"),V=require("@tiptap/pm/state"),ve=require("prosemirror-dropcursor"),q=require("@tiptap/pm/history"),D=require("prosemirror-view"),Se=require("uuid"),Z=require("@tiptap/pm/model"),H=require("prosemirror-model"),xe=require("rehype-parse"),Ee=require("rehype-remark"),Ie=require("remark-gfm"),Pe=require("remark-stringify"),Te=require("unified"),Be=require("hast-util-from-dom"),De=require("unist-util-visit"),T=require("prosemirror-tables"),F=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Oe(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 Me=F(ke),B=Oe(Ce),Ae=F(xe),Ne=F(Ee),Le=F(Ie),Re=F(Pe);function ae(n){const e=Array.from(n.classList).filter(t=>!t.startsWith("bn-"))||[];e.length>0?n.className=e.join(" "):n.removeAttribute("class")}function le(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 u=k.nodeToCustomInlineContent(c,n.schema.inlineContentSchema,n.schema.styleSchema),h=l.toExternalHTML?l.toExternalHTML(u,n):l.render.call({renderType:"dom",props:void 0},u,()=>{},n);if(h){if(i.appendChild(h.dom),h.contentDOM){const g=t.serializeFragment(c.content,o);h.contentDOM.dataset.editable="",h.contentDOM.appendChild(g)}continue}}}else if(c.type.name==="text"){let l=document.createTextNode(c.textContent);for(const u of c.marks.toReversed())if(u.type.name in n.schema.styleSpecs){const h=(n.schema.styleSpecs[u.type.name].implementation.toExternalHTML??n.schema.styleSpecs[u.type.name].implementation.render)(u.attrs.stringValue,n);h.contentDOM.appendChild(l),l=h.dom}else{const h=u.type.spec.toDOM(u,!0),g=H.DOMSerializer.renderSpec(document,h);g.contentDOM.appendChild(l),l=g.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&&ae(i.firstChild),i}function Ve(n,e,t,o,r,s,i,a){var y,w,P,L,X,W,G,J,Q;const c=(a==null?void 0:a.document)??document,l=e.pmSchema.nodes.blockContainer,u=t.props||{};for(const[S,E]of Object.entries(e.schema.blockSchema[t.type].propSchema))!(S in u)&&E.default!==void 0&&(u[S]=E.default);const h=(w=(y=l.spec)==null?void 0:y.toDOM)==null?void 0:w.call(y,l.create({id:t.id,...u})),g=Array.from(h.dom.attributes),m=e.blockImplementations[t.type].implementation,p=((P=m.toExternalHTML)==null?void 0:P.call({},{...t,props:u},e))||m.render.call({},{...t,props:u},e),d=c.createDocumentFragment();if(p.dom.classList.contains("bn-block-content")){const S=[...g,...Array.from(p.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 S)p.dom.firstChild.setAttribute(E.name,E.value);ae(p.dom.firstChild),i>0&&p.dom.firstChild.setAttribute("data-nesting-level",i.toString()),d.append(...Array.from(p.dom.childNodes))}else d.append(p.dom),i>0&&p.dom.setAttribute("data-nesting-level",i.toString());if(p.contentDOM&&t.content){const S=le(e,t.content,o,a);p.contentDOM.appendChild(S)}let f;if(r.has(t.type)?f="OL":s.has(t.type)&&(f="UL"),f){if(((L=n.lastChild)==null?void 0:L.nodeName)!==f){const S=c.createElement(f);f==="OL"&&"start"in u&&u.start&&(u==null?void 0:u.start)!==1&&S.setAttribute("start",u.start+""),n.append(S)}n.lastChild.appendChild(d)}else n.append(d);if(t.children&&t.children.length>0){const S=c.createDocumentFragment();if(ce(S,e,t.children,o,r,s,i+1,a),((X=n.lastChild)==null?void 0:X.nodeName)==="UL"||((W=n.lastChild)==null?void 0:W.nodeName)==="OL")for(;((G=S.firstChild)==null?void 0:G.nodeName)==="UL"||((J=S.firstChild)==null?void 0:J.nodeName)==="OL";)n.lastChild.lastChild.appendChild(S.firstChild);e.pmSchema.nodes[t.type].isInGroup("blockContent")?n.append(S):(Q=p.contentDOM)==null||Q.append(S)}}const ce=(n,e,t,o,r,s,i=0,a)=>{for(const c of t)Ve(n,e,c,o,r,s,i,a)},He=(n,e,t,o,r,s)=>{const a=((s==null?void 0:s.document)??document).createDocumentFragment();return ce(a,n,e,t,o,r,0,s),a},Y=(n,e)=>{const t=H.DOMSerializer.fromSchema(n);return{exportBlocks:(o,r)=>{const s=He(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=le(e,o,t,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function Fe(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 _e(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 ee(n){const e="__root__",t={},o={},r=k.getPmSchema(n);return n.descendants((s,i)=>{if(!O.isNodeBlock(s))return!0;const a=Fe(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 Ue(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=[],u=[],h=new Array(c).fill(-1),g=(d,f)=>{let y=0,w=d.length;for(;y<w;){const P=y+w>>>1;d[P]<f?y=P+1:w=P}return y};for(let d=0;d<c;d++){const f=a[d],y=g(l,f);y>0&&(h[d]=u[y-1]),y===l.length?(l.push(f),u.push(d)):(l[y]=f,u[y]=d)}const m=new Set;let p=u[u.length-1]??-1;for(;p!==-1;)m.add(p),p=h[p];for(let d=0;d<r.length;d++)m.has(d)||t.add(r[d]);return t}function de(n,e=[]){const t=_e(n),o=R.combineTransactionSteps(n.before,[n,...e]),r=ee(o.before),s=ee(o.doc),i=[],a=new Set;Object.keys(s.byId).filter(m=>!(m in r.byId)).forEach(m=>{i.push({type:"insert",block:s.byId[m].block,source:t,prevBlock:void 0}),a.add(m)}),Object.keys(r.byId).filter(m=>!(m in s.byId)).forEach(m=>{i.push({type:"delete",block:r.byId[m].block,source:t,prevBlock:void 0}),a.add(m)}),Object.keys(s.byId).filter(m=>m in r.byId).forEach(m=>{var y,w;const p=r.byId[m],d=s.byId[m];p.parentId!==d.parentId?(i.push({type:"move",block:d.block,prevBlock:p.block,source:t,prevParent:p.parentId?(y=r.byId[p.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(m)):Me.default({...p.block,children:void 0},{...d.block,children:void 0})||(i.push({type:"update",block:d.block,prevBlock:p.block,source:t}),a.add(m))});const c=r.childrenByParent,l=s.childrenByParent,u="__root__",h=new Set([...Object.keys(c),...Object.keys(l)]),g=new Set;return h.forEach(m=>{const p=Ue(c[m],l[m]);p.size!==0&&p.forEach(d=>{var P,L;const f=r.byId[d],y=s.byId[d];!f||!y||f.parentId!==y.parentId||a.has(d)||(f.parentId??u)!==m||g.has(d)||(g.add(d),i.push({type:"move",block:y.block,prevBlock:f.block,source:t,prevParent:f.parentId?(P=r.byId[f.parentId])==null?void 0:P.block:void 0,currentParent:y.parentId?(L=s.byId[y.parentId])==null?void 0:L.block:void 0}),a.add(d))})}),i}const $e=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=de(e),t)},tr:e})!==!1,!0)}})],subscribe(e){return n.push(e),()=>{n.splice(n.indexOf(e),1)}}}});function te(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 qe(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: ${te(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: ${te(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??qe)(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 ze(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 Ke=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=ze(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})}}}),ue=(n,e)=>{e(n),n.forEach(t=>{t instanceof B.XmlElement&&ue(t,e)})},Ye=(n,e)=>{const t=new Map;return n.forEach(o=>{o instanceof B.XmlElement&&ue(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)},je=[Ye],Xe=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 je)a(n.fragment,i);if(e=!0,!!i.docChanged)return i}})]}}),We=v.createExtension(({editor:n,options:e})=>({key:"dropCursor",prosemirrorPlugins:[(e.dropCursor??ve.dropCursor)({width:5,color:"#ddeeff",editor:n})]})),Ge=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()})}}}),Je=v.createExtension(()=>({key:"history",prosemirrorPlugins:[q.history()],undoCommand:q.undo,redoCommand:q.redo})),Qe=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(u=>u.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()}}}),Ze=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],et="https",tt=new C.PluginKey("node-selection-keyboard"),ot=v.createExtension(()=>({key:"nodeSelectionKeyboard",prosemirrorPlugins:[new C.Plugin({key:tt,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}}})]})),nt=new C.PluginKey("blocknote-placeholder"),rt=v.createExtension(({editor:n,options:e})=>{const t=e.placeholders;return{key:"placeholder",prosemirrorPlugins:[new C.Plugin({key:nt,view:o=>{const r=`placeholder-selector-${Se.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:u,...h}=t||{};for(const[p,d]of Object.entries(h)){const f=`[data-content-type="${p}"]`;a.insertRule(`${c(f)} { content: ${JSON.stringify(d)}; }`)}const g="[data-is-only-empty-block]",m="[data-is-empty-and-focused]";a.insertRule(`${c(g)} { content: ${JSON.stringify(u)}; }`),a.insertRule(`${c(m)} { 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)}}})]}}),oe=new C.PluginKey("previous-blocks"),st={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},it=v.createExtension(()=>{let n;return{key:"previousBlockType",prosemirrorPlugins:[new C.Plugin({key:oe,view(e){return{update:async(t,o)=>{var r;((r=this.key)==null?void 0:r.getState(t.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(oe,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,o,r){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||o.doc.eq(r.doc))return t;const 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 u=a.get(l.node.attrs.id),h=u==null?void 0:u.node.firstChild,g=l.node.firstChild;if(u&&h&&g){const m={index:g.attrs.index,level:g.attrs.level,type:g.type.name,depth:r.doc.resolve(l.pos).depth},p={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(u.pos).depth};s[l.node.attrs.id]=p,t.currentTransactionOldBlockAttrs[l.node.attrs.id]=p,JSON.stringify(p)!==JSON.stringify(m)&&(p["depth-change"]=p.depth-m.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,u]of Object.entries(i))a["data-prev-"+st[l]]=u||"none";const c=D.Decoration.node(s,s+r.nodeSize,{...a});o.push(c)}),D.DecorationSet.create(e.doc,o)}}})]}});function he(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 at(){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 lt(){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,Be.fromDom(document.createTextNode(" ")))):n(r)}};return n}function ct(){return n=>{De.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:`![${l}](${c})`}}})}}function j(n){return Te.unified().use(Ae.default,{fragment:!0}).use(ct).use(at).use(lt).use(Ne.default).use(Le.default).use(Re.default,{handlers:{text:t=>t.value}}).processSync(n).value}function dt(n,e,t,o){const s=Y(e,t).exportBlocks(n,o);return j(s)}function me(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 ut(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 ne(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,g)=>Array.prototype.indexOf.call(h.children,g),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]);pe(n.root),I=o;const c=I.getElementsByTagName("iframe");for(let h=0;h<c.length;h++){const g=c[h],m=g.parentElement;m&&m.removeChild(g)}const u=n.dom.className.split(" ").filter(h=>h!=="ProseMirror"&&h!=="bn-root"&&h!=="bn-editor").join(" ");I.className=I.className+" bn-drag-preview "+u,n.root instanceof ShadowRoot?n.root.appendChild(I):n.root.body.appendChild(I)}function pe(n){I!==void 0&&(n instanceof ShadowRoot?n.removeChild(I):n.body.removeChild(I),I=void 0)}function ht(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}=ut(i,a),u=c<=s&&s<l,h=i.$anchor.node()!==i.$head.node()||i instanceof A;u&&h?(o.dispatch(o.state.tr.setSelection(A.create(a,c,l))),ne(o,c,l)):(o.dispatch(o.state.tr.setSelection(C.NodeSelection.create(o.state.doc,s))),ne(o,s));const g=o.state.selection.content(),m=t.pmSchema,p=o.serializeForClipboard(g).dom.innerHTML,d=Y(m,t),f=me(g.content),y=d.exportBlocks(f,{}),w=j(y);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",p),n.dataTransfer.setData("text/html",y),n.dataTransfer.setData("text/plain",w),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(I,0,0)}}const re=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):he(r,n)}function mt(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 fe{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>re){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}const t=mt(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=Z.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new Z.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>re)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 ge=new V.PluginKey("SideMenuPlugin"),pt=v.createExtension(({editor:n})=>{let e;const t=v.createStore(void 0);return{key:"sideMenu",store:t,prosemirrorPlugins:[new V.Plugin({key:ge,view:o=>(e=new fe(n,o,r=>{t.setState({...r})}),e)})],blockDragStart(o,r){e&&(e.isDragOrigin=!0),ht(o,r,n)},blockDragEnd(){pe(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 x;function se(n){x||(x=document.createElement("div"),x.innerHTML="_",x.style.opacity="0",x.style.height="1px",x.style.width="1px",n instanceof Document?n.body.appendChild(x):n.appendChild(x))}function ft(n){x&&(n instanceof Document?n.body.removeChild(x):n.removeChild(x),x=void 0)}function _(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function gt(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 yt(n,e){const t=e.querySelectorAll(n);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"}class ye{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,u,h,g,m,p,d;if(this.menuFrozen||this.mouseState==="selecting"||!(e.target instanceof Element)||!this.pmView.dom.contains(e.target))return;const t=gt(e.target);if((t==null?void 0:t.type)==="cell"&&this.mouseState==="down"&&!((l=this.state)!=null&&l.draggingState)){this.mouseState="selecting",(u=this.state)!=null&&u.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=he(t.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(f=>O.getNodeById(r.id,f.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=(g=t.domNode.closest(".tableWrapper"))==null?void 0:g.querySelector(".table-widgets-container");if((t==null?void 0:t.type)==="wrapper"){const f=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:f,showAddOrRemoveColumnsButton:y,referencePosTable:o,block:s,widgetContainer:c,colIndex:w||(m=this.state)==null?void 0:m.colIndex,rowIndex:w||(p=this.state)==null?void 0:p.rowIndex,referencePosCell:w||(d=this.state)==null?void 0:d.referencePosCell}}else{const f=_(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===f)return;this.state={show:!0,showAddOrRemoveColumnsButton:f===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:y===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:w,colIndex:f,rowIndex:y,widgetContainer:c}}return this.emitUpdate(),!1});b(this,"dragOverHandler",e=>{var g;if(((g=this.state)==null?void 0:g.draggingState)===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect="move",yt(".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(m=>m.tagName==="TD"||m.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,u=(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(),u&&this.editor.transact(m=>m.setMeta(N,!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 N=new C.PluginKey("TableHandlesPlugin"),wt=v.createExtension(({editor:n})=>{let e;const t=v.createStore(void 0);return{key:"tableHandles",store:t,prosemirrorPlugins:[new C.Plugin({key:N,view:o=>(e=new ye(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 u=o.doc.resolve(e.tablePos+1);return e.state.draggingState.draggedCellOrientation==="row"?k.getCellsAtRowHandle(e.state.block,r).forEach(({row:g,col:m})=>{const p=o.doc.resolve(u.posAtIndex(g)+1),d=o.doc.resolve(p.posAtIndex(m)+1),f=d.node(),y=d.pos+(r>c?f.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:g,col:m})=>{const p=o.doc.resolve(u.posAtIndex(g)+1),d=o.doc.resolve(p.posAtIndex(m)+1),f=d.node(),y=d.pos+(r>c?f.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(N,{draggedCellOrientation:e.state.draggingState.draggedCellOrientation,originalIndex:e.state.colIndex,newIndex:e.state.colIndex,tablePos:e.tablePos})),!n.headless&&(se(n.prosemirrorView.root),o.dataTransfer.setDragImage(x,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(N,{draggedCellOrientation:e.state.draggingState.draggedCellOrientation,originalIndex:e.state.rowIndex,newIndex:e.state.rowIndex,tablePos:e.tablePos})),!n.headless&&(se(n.prosemirrorView.root),o.dataTransfer.setDragImage(x,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(N,null)),!n.headless&&ft(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),u=o.doc.resolve(l.posAtIndex(s.col)),h=o.tr;return h.setSelection(new T.CellSelection(c,u)),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(f=>{s=f.$from.min(s??f.$from),i=f.$to.max(i??f.$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),u=s.index(a.depth),h=a.index(l.depth),g=i.index(c.depth),m=c.index(l.depth),p=[];for(let d=h;d<=m;d++)for(let f=u;f<=g;f++)p.push({row:d,col:f});return{from:{row:h,col:u},to:{row:m,col:g},cells:p}})},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)}}}),ie=new C.PluginKey("trailingNode"),bt=v.createExtension(()=>({key:"trailingNode",prosemirrorPlugins:[new C.Plugin({key:ie,appendTransaction:(n,e,t)=>{const{doc:o,tr:r,schema:s}=t,i=ie.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=$e;exports.DEFAULT_LINK_PROTOCOL=et;exports.DropCursorExtension=We;exports.ForkYDocExtension=Ke;exports.FormattingToolbarExtension=Ge;exports.HistoryExtension=Je;exports.LinkToolbarExtension=Qe;exports.NodeSelectionKeyboardExtension=ot;exports.PlaceholderExtension=rt;exports.PreviousBlockTypeExtension=it;exports.SchemaMigration=Xe;exports.SideMenuExtension=pt;exports.SideMenuView=fe;exports.TableHandlesExtension=wt;exports.TableHandlesView=ye;exports.TrailingNodeExtension=bt;exports.VALID_LINK_PROTOCOLS=Ze;exports.YCursorExtension=z;exports.YSyncExtension=U;exports.YUndoExtension=$;exports.blocksToMarkdown=dt;exports.cleanHTMLToMarkdown=j;exports.createExternalHTMLExporter=Y;exports.fragmentToBlocks=me;exports.getBlocksChangedByTransaction=de;exports.sideMenuPluginKey=ge;exports.tableHandlesPluginKey=N;
2
+ //# sourceMappingURL=TrailingNode-W7GJVng5.cjs.map