@blocknote/core 0.47.3 → 0.48.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.
Files changed (121) hide show
  1. package/dist/BlockNoteExtension-B6RhuQ3V.js +27 -0
  2. package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
  3. package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
  4. package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
  5. package/dist/EventEmitter-CuPnGDYt.js +22 -0
  6. package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
  7. package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
  8. package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
  9. package/dist/ShowSelection-BsHFfdMi.js +29 -0
  10. package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
  11. package/dist/ShowSelection-DhXglbt8.cjs +2 -0
  12. package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
  13. package/dist/blocknote.cjs +1 -5
  14. package/dist/blocknote.js +7 -4256
  15. package/dist/blocks-BEvIOzln.cjs +11 -0
  16. package/dist/blocks-BEvIOzln.cjs.map +1 -0
  17. package/dist/blocks-DYl7UTS4.js +3313 -0
  18. package/dist/blocks-DYl7UTS4.js.map +1 -0
  19. package/dist/blocks.cjs +1 -2
  20. package/dist/blocks.js +2 -74
  21. package/dist/comments.cjs +2 -2
  22. package/dist/comments.cjs.map +1 -1
  23. package/dist/comments.js +604 -900
  24. package/dist/comments.js.map +1 -1
  25. package/dist/en-C4ykW581.cjs +2 -0
  26. package/dist/en-C4ykW581.cjs.map +1 -0
  27. package/dist/en-QsSI16s5.js +453 -0
  28. package/dist/en-QsSI16s5.js.map +1 -0
  29. package/dist/extensions-3nf9PPhA.js +1495 -0
  30. package/dist/extensions-3nf9PPhA.js.map +1 -0
  31. package/dist/extensions-D9y6evn6.cjs +2 -0
  32. package/dist/extensions-D9y6evn6.cjs.map +1 -0
  33. package/dist/extensions.cjs +1 -2
  34. package/dist/extensions.js +4 -36
  35. package/dist/locales.cjs +2 -2
  36. package/dist/locales.cjs.map +1 -1
  37. package/dist/locales.js +10049 -9111
  38. package/dist/locales.js.map +1 -1
  39. package/dist/src-BKJH7Jla.cjs +5 -0
  40. package/dist/src-BKJH7Jla.cjs.map +1 -0
  41. package/dist/src-Hjv1f5lc.js +2386 -0
  42. package/dist/src-Hjv1f5lc.js.map +1 -0
  43. package/dist/style.css +2 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.cjs +2 -2
  46. package/dist/yjs.cjs.map +1 -1
  47. package/dist/yjs.js +20 -38
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +8 -8
  50. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
  51. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
  52. package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
  53. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
  54. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
  55. package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
  56. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
  57. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
  58. package/src/editor/Block.css +5 -8
  59. package/src/editor/BlockNoteEditor.ts +38 -1
  60. package/src/editor/editor.css +0 -20
  61. package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
  62. package/src/editor/performance.test.ts +134 -0
  63. package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
  64. package/src/extensions/Placeholder/Placeholder.ts +1 -1
  65. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
  66. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
  67. package/src/extensions/SideMenu/SideMenu.ts +14 -8
  68. package/src/extensions/TableHandles/TableHandles.ts +14 -0
  69. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
  70. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
  71. package/src/index.ts +1 -1
  72. package/src/schema/blocks/createSpec.ts +6 -2
  73. package/src/schema/inlineContent/types.ts +0 -1
  74. package/src/vite-env.d.ts +6 -0
  75. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
  76. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
  77. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
  78. package/types/src/editor/BlockNoteEditor.d.ts +13 -0
  79. package/types/src/editor/performance.test.d.ts +1 -0
  80. package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
  81. package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
  82. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
  83. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
  84. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
  85. package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
  86. package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
  87. package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
  88. package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
  89. package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
  90. package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
  91. package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
  92. package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
  93. package/dist/EventEmitter-CjSwpTbz.js +0 -27
  94. package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
  95. package/dist/ShowSelection-B0ch3unP.js +0 -51
  96. package/dist/ShowSelection-B0ch3unP.js.map +0 -1
  97. package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
  98. package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
  99. package/dist/TrailingNode-GzE59m_7.js +0 -2288
  100. package/dist/TrailingNode-GzE59m_7.js.map +0 -1
  101. package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
  102. package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
  103. package/dist/blockToNode-BNoNIXU7.js +0 -1140
  104. package/dist/blockToNode-BNoNIXU7.js.map +0 -1
  105. package/dist/blockToNode-CumVjgem.cjs +0 -7
  106. package/dist/blockToNode-CumVjgem.cjs.map +0 -1
  107. package/dist/blocknote.cjs.map +0 -1
  108. package/dist/blocknote.js.map +0 -1
  109. package/dist/blocks.cjs.map +0 -1
  110. package/dist/blocks.js.map +0 -1
  111. package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
  112. package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
  113. package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
  114. package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
  115. package/dist/en-Cl87Uuyf.cjs +0 -2
  116. package/dist/en-Cl87Uuyf.cjs.map +0 -1
  117. package/dist/en-njEqD7AG.js +0 -408
  118. package/dist/en-njEqD7AG.js.map +0 -1
  119. package/dist/extensions.cjs.map +0 -1
  120. package/dist/extensions.js.map +0 -1
  121. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,5 @@
1
+ const e=require(`./BlockNoteExtension-ab0REuob.cjs`),t=require(`./blocks-BEvIOzln.cjs`),n=require(`./extensions-D9y6evn6.cjs`),r=require(`./ShowSelection-DhXglbt8.cjs`),i=require(`./en-C4ykW581.cjs`),a=require(`./EventEmitter-DHdSnYCD.cjs`);let o=require(`prosemirror-model`),s=require(`prosemirror-transform`),c=require(`@tiptap/core`),l=require(`prosemirror-state`),u=require(`@tiptap/pm/model`),d=require(`prosemirror-tables`),f=require(`@tiptap/pm/state`),p=require(`remark-gfm`);p=e.i(p);let m=require(`unified`),h=require(`remark-parse`);h=e.i(h);let g=require(`remark-rehype`);g=e.i(g);let _=require(`rehype-stringify`);_=e.i(_);let v=require(`@handlewithcare/prosemirror-inputrules`),ee=require(`@tiptap/pm/keymap`),te=require(`@tiptap/extensions/gap-cursor`),ne=require(`@tiptap/extension-link`),re=require(`@tiptap/extension-text`);function y(e,t){let n=[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:e=>{let t=e;return t.matches(`[data-editable]`)?t:t.querySelector(`[data-editable]`)||t}}];return t&&n.push({tag:`*`,getAttrs(e){if(typeof e==`string`)return!1;let n=t?.(e);return n===void 0?!1:n}}),n}function ie(e,n){return t.Qt(c.Node.create({name:e.type,inline:!0,group:`inline`,draggable:n.meta?.draggable,selectable:e.content===`styled`,atom:e.content===`none`,content:e.content===`styled`?`inline*`:``,addAttributes(){return t.En(e.propSchema)},addKeyboardShortcuts(){return t.Zt(e)},parseHTML(){return y(e,n.parse)},renderHTML({node:r}){let i=this.options.editor;return t.Xt(n.render.call({renderType:`dom`,props:void 0},t.an(r,i.schema.inlineContentSchema,i.schema.styleSchema),()=>{},i),e.type,r.attrs,e.propSchema)},addNodeView(){return r=>{let{node:i,getPos:a}=r,o=this.options.editor;return t.Xt(n.render.call({renderType:`nodeView`,props:r},t.an(i,o.schema.inlineContentSchema,o.schema.styleSchema),e=>{let n=t.kt([e],o.pmSchema),r=a();r&&o.transact(e=>e.replaceWith(r,r+i.nodeSize,n))},o),e.type,i.attrs,e.propSchema)}}}),e.propSchema,{...n,toExternalHTML:n.toExternalHTML,render(r,i,a){return t.Xt(n.render(r,i,a),e.type,r.props,e.propSchema)}})}function b(e,n,r,i=`before`){let a=typeof r==`string`?r:r.id,c=t.dn(e),l=n.map(e=>t.Ot(e,c)),u=t.Et(a,e.doc);if(!u)throw Error(`Block with ID ${a} not found`);let d=u.posBeforeNode;return i===`after`&&(d+=u.node.nodeSize),e.step(new s.ReplaceStep(d,d,new o.Slice(o.Fragment.from(l),0,0))),l.map(e=>t.in(e,c))}function x(e){if(!e||e.type.name!==`column`)throw Error(`Invalid columnPos: does not point to column node.`);let t=e.firstChild;if(!t)throw Error(`Invalid column: does not have child node.`);let n=t.firstChild;if(!n)throw Error(`Invalid blockContainer: does not have child node.`);return e.childCount===1&&t.childCount===1&&n.type.name===`paragraph`&&n.content.content.length===0}function S(e,t){let n=e.doc.resolve(t),r=n.nodeAfter;if(!r||r.type.name!==`columnList`)throw Error(`Invalid columnListPos: does not point to columnList node.`);for(let t=r.childCount-1;t>=0;t--){let r=e.doc.resolve(n.pos+1).posAtIndex(t),i=e.doc.resolve(r).nodeAfter;if(!i||i.type.name!==`column`)throw Error(`Invalid columnPos: does not point to column node.`);x(i)&&e.delete(r,r+i.nodeSize)}}function C(e,t){S(e,t);let n=e.doc.resolve(t).nodeAfter;if(!n||n.type.name!==`columnList`)throw Error(`Invalid columnListPos: does not point to columnList node.`);if(n.childCount>2)return;if(n.childCount<2)throw Error(`Invalid columnList: contains fewer than two children.`);let r=t+1,i=e.doc.resolve(r).nodeAfter,a=t+n.nodeSize-1,c=e.doc.resolve(a).nodeBefore;if(!i||!c)throw Error(`Invalid columnList: does not contain children.`);let l=x(i),u=x(c);if(l&&u){e.delete(t,t+n.nodeSize);return}if(l){e.step(new s.ReplaceAroundStep(t,t+n.nodeSize,a-c.nodeSize+1,a-1,o.Slice.empty,0,!1));return}if(u){e.step(new s.ReplaceAroundStep(t,t+n.nodeSize,r+1,r+i.nodeSize-1,o.Slice.empty,0,!1));return}}function w(e,n,r){let i=t.dn(e),a=r.map(e=>t.Ot(e,i)),o=new Set(n.map(e=>typeof e==`string`?e:e.id)),s=[],c=new Set,l=typeof n[0]==`string`?n[0]:n[0].id,u=0;if(e.doc.descendants((n,d)=>{if(o.size===0)return!1;if(!n.type.isInGroup(`bnBlock`)||!o.has(n.attrs.id))return!0;if(s.push(t.in(n,i)),o.delete(n.attrs.id),r.length>0&&n.attrs.id===l){let t=e.doc.nodeSize;e.insert(d,a);let n=e.doc.nodeSize;u+=t-n}let f=e.doc.nodeSize,p=e.doc.resolve(d-u);p.node().type.name===`column`?c.add(p.before(-1)):p.node().type.name===`columnList`&&c.add(p.before()),p.node().type.name===`blockGroup`&&p.node(p.depth-1).type.name!==`doc`&&p.node().childCount===1?e.delete(p.before(),p.after()):e.delete(d-u,d-u+n.nodeSize);let m=e.doc.nodeSize;return u+=f-m,!1}),o.size>0){let e=[...o].join(`
2
+ `);throw Error(`Blocks with the following IDs could not be found in the editor: `+e)}return c.forEach(t=>C(e,t)),{insertedBlocks:a.map(e=>t.in(e,i)),removedBlocks:s}}function ae(e,n,r,i,a){let s;if(!n)throw Error(`blockContent is required`);if(typeof n==`string`)s=t.kt([n],e.pmSchema,i);else if(Array.isArray(n))s=t.kt(n,e.pmSchema,i);else if(n.type===`tableContent`)s=t.At(n,e.pmSchema);else throw new t.Rn(n.type);let c=(a?.document??document).createDocumentFragment();for(let n of s)if(n.type.name!==`text`&&e.schema.inlineContentSchema[n.type.name]){let i=e.schema.inlineContentSpecs[n.type.name].implementation;if(i){let o=t.an(n,e.schema.inlineContentSchema,e.schema.styleSchema),s=i.render.call({renderType:`dom`,props:void 0},o,()=>{},e);if(s){if(c.appendChild(s.dom),s.contentDOM){let e=r.serializeFragment(n.content,a);s.contentDOM.dataset.editable=``,s.contentDOM.appendChild(e)}continue}}}else if(n.type.name===`text`){let t=document.createTextNode(n.textContent);for(let r of n.marks.toReversed())if(r.type.name in e.schema.styleSpecs){let n=e.schema.styleSpecs[r.type.name].implementation.render(r.attrs.stringValue,e);n.contentDOM.appendChild(t),t=n.dom}else{let e=r.type.spec.toDOM(r,!0),n=o.DOMSerializer.renderSpec(document,e);n.contentDOM.appendChild(t),t=n.dom}c.appendChild(t)}else{let e=r.serializeFragment(o.Fragment.from([n]),a);c.appendChild(e)}return c}function oe(e,t,n,r){let i=e.pmSchema.nodes.blockContainer,a=t.props||{};for(let[n,r]of Object.entries(e.schema.blockSchema[t.type].propSchema))!(n in a)&&r.default!==void 0&&(a[n]=r.default);let o=t.children||[],s=e.blockImplementations[t.type].implementation.render.call({renderType:`dom`,props:void 0},{...t,props:a,children:o},e);if(s.contentDOM&&t.content){let i=ae(e,t.content,n,t.type,r);s.contentDOM.appendChild(i)}if(e.pmSchema.nodes[t.type].isInGroup(`bnBlock`)){if(t.children&&t.children.length>0){let i=T(e,t.children,n,r);s.contentDOM?.append(i)}return s.dom}let c=i.spec?.toDOM?.(i.create({id:t.id,...a}));return c.contentDOM?.appendChild(s.dom),t.children&&t.children.length>0&&c.contentDOM?.appendChild(E(e,t.children,n,r)),c.dom}function T(e,t,n,r){let i=(r?.document??document).createDocumentFragment();for(let a of t){let t=oe(e,a,n,r);i.appendChild(t)}return i}var E=(e,t,n,r)=>{let i=e.pmSchema.nodes.blockGroup,a=i.spec.toDOM(i.create({})),o=T(e,t,n,r);return a.contentDOM?.appendChild(o),a.dom},se=e=>(e.querySelectorAll(`[data-content-type="numberedListItem"]`).forEach(e=>{let t=e.closest(`.bn-block-outer`)?.previousElementSibling?.querySelector(`[data-content-type="numberedListItem"]`);if(!t)e.setAttribute(`data-index`,e.getAttribute(`data-start`)||`1`);else{let n=t.getAttribute(`data-index`);e.setAttribute(`data-index`,(parseInt(n||`0`)+1).toString())}}),e),ce=e=>(e.querySelectorAll(`[data-content-type="checkListItem"] input`).forEach(e=>{e.disabled=!0}),e),le=e=>(e.querySelectorAll(`.bn-toggle-wrapper[data-show-children="false"]`).forEach(e=>{e.setAttribute(`data-show-children`,`true`)}),e),ue=e=>(e.querySelectorAll(`[data-content-type="table"] table`).forEach(e=>{e.setAttribute(`style`,`--default-cell-min-width: 120px;`),e.setAttribute(`data-show-children`,`true`)}),e),de=e=>(e.querySelectorAll(`[data-content-type="table"] table`).forEach(e=>{let t=document.createElement(`div`);t.className=`tableWrapper`;let n=document.createElement(`div`);n.className=`tableWrapper-inner`,t.appendChild(n),e.parentElement?.appendChild(t),t.appendChild(e)}),e),fe=e=>(e.querySelectorAll(`.bn-inline-content:empty`).forEach(e=>{let t=document.createElement(`span`);t.className=`ProseMirror-trailingBreak`,t.setAttribute(`style`,`display: inline-block;`),e.appendChild(t)}),e),D=(e,t)=>{let n=o.DOMSerializer.fromSchema(e),r=[se,ce,le,ue,de,fe];return{serializeBlocks:(e,i)=>{let a=E(t,e,n,i);for(let e of r)a=e(a);return a.outerHTML}}};function pe(e){return e.transact(e=>{let n=t.vn(e.doc,e.selection.anchor);if(e.selection instanceof d.CellSelection)return{type:`cell`,anchorBlockId:n.node.attrs.id,anchorCellOffset:e.selection.$anchorCell.pos-n.posBeforeNode,headCellOffset:e.selection.$headCell.pos-n.posBeforeNode};if(e.selection instanceof l.NodeSelection)return{type:`node`,anchorBlockId:n.node.attrs.id};{let r=t.vn(e.doc,e.selection.head);return{type:`text`,anchorBlockId:n.node.attrs.id,headBlockId:r.node.attrs.id,anchorOffset:e.selection.anchor-n.posBeforeNode,headOffset:e.selection.head-r.posBeforeNode}}})}function me(e,n){let r=t.Et(n.anchorBlockId,e.doc)?.posBeforeNode;if(r===void 0)throw Error(`Could not find block with ID ${n.anchorBlockId} to update selection`);let i;if(n.type===`cell`)i=d.CellSelection.create(e.doc,r+n.anchorCellOffset,r+n.headCellOffset);else if(n.type===`node`)i=l.NodeSelection.create(e.doc,r+1);else{let a=t.Et(n.headBlockId,e.doc)?.posBeforeNode;if(a===void 0)throw Error(`Could not find block with ID ${n.headBlockId} to update selection`);i=l.TextSelection.create(e.doc,r+n.anchorOffset,a+n.headOffset)}e.setSelection(i)}function O(e){return e.map(e=>e.type===`columnList`?e.children.map(e=>O(e.children)).flat():{...e,children:O(e.children)}).flat()}function k(e,t,n){e.transact(r=>{let i=e.getSelection()?.blocks||[e.getTextCursorPosition().block],a=pe(e);e.removeBlocks(i),e.insertBlocks(O(i),t,n),me(r,a)})}function A(e){return!e||e.type!==`columnList`}function he(e,t,n){let r,i;if(t?t.children.length>0?(r=t.children[t.children.length-1],i=`after`):(r=t,i=`before`):n&&(r=n,i=`before`),!r||!i)return;let a=e.getParentBlock(r);return A(a)?{referenceBlock:r,placement:i}:he(e,i===`after`?r:e.getPrevBlock(r),a)}function j(e,t,n){let r,i;if(t?t.children.length>0?(r=t.children[0],i=`before`):(r=t,i=`after`):n&&(r=n,i=`after`),!r||!i)return;let a=e.getParentBlock(r);return A(a)?{referenceBlock:r,placement:i}:j(e,i===`before`?r:e.getNextBlock(r),a)}function ge(e){e.transact(()=>{let t=e.getSelection()?.blocks[0]||e.getTextCursorPosition().block,n=he(e,e.getPrevBlock(t),e.getParentBlock(t));n&&k(e,n.referenceBlock,n.placement)})}function _e(e){e.transact(()=>{let t=e.getSelection(),n=t?.blocks[t?.blocks.length-1]||e.getTextCursorPosition().block,r=j(e,e.getNextBlock(n),e.getParentBlock(n));r&&k(e,r.referenceBlock,r.placement)})}function ve(e,t,n){let{$from:r,$to:i}=e.selection,a=r.blockRange(i,e=>e.childCount>0&&(e.type.name===`blockGroup`||e.type.name===`column`));if(!a)return!1;let c=a.startIndex;if(c===0)return!1;let l=a.parent.child(c-1);if(l.type!==t)return!1;let u=l.lastChild&&l.lastChild.type===n,d=o.Fragment.from(u?t.create():null),f=new o.Slice(o.Fragment.from(t.create(null,o.Fragment.from(n.create(null,d)))),u?3:1,0),p=a.start,m=a.end;return e.step(new s.ReplaceAroundStep(p-(u?3:1),m,p,m,f,1,!0)).scrollIntoView(),!0}function M(e){return e.transact(t=>ve(t,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function ye(e,t,n,r){let i=r.end,a=r.$to.end(r.depth);if(i<a){let c=r.parent.child(r.endIndex-1),l=c.lastChild&&c.lastChild.type===n;e.step(new s.ReplaceAroundStep(i-(l?2:1),a,i,a,new o.Slice(o.Fragment.from(t.create(null,n.create())),l?2:1,0),l?0:1,!0)),r=new o.NodeRange(e.doc.resolve(r.$from.pos),e.doc.resolve(a),r.depth)}let c=(0,s.liftTarget)(r);if(c==null)return!1;e.lift(r,c);let l=e.doc.resolve(e.mapping.map(i,-1)-1);return(0,s.canJoin)(e.doc,l.pos)&&l.nodeBefore.type===l.nodeAfter.type&&e.join(l.pos),e.scrollIntoView(),!0}function N(e,t,n){let{$from:r,$to:i}=e.selection,a=r.blockRange(i,e=>e.childCount>0&&(e.type.name===`blockGroup`||e.type.name===`column`));return a&&r.node(a.depth-1).type===t?ye(e,t,n,a):!1}function P(e){return e.transact(t=>N(t,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function be(e){return e.transact(e=>{let{bnBlock:n}=t.gn(e);return e.doc.resolve(n.beforePos).nodeBefore!==null})}function xe(e){return e.transact(e=>{let{bnBlock:n}=t.gn(e);return e.doc.resolve(n.beforePos).depth>1})}function F(e,n){let r=typeof n==`string`?n:n.id,i=t.dn(e),a=t.Et(r,e);if(a)return t.in(a.node,i)}function I(e,n){let r=t.Et(typeof n==`string`?n:n.id,e),i=t.dn(e);if(!r)return;let a=e.resolve(r.posBeforeNode).nodeBefore;if(a)return t.in(a,i)}function L(e,n){let r=t.Et(typeof n==`string`?n:n.id,e),i=t.dn(e);if(!r)return;let a=e.resolve(r.posBeforeNode+r.node.nodeSize).nodeAfter;if(a)return t.in(a,i)}function R(e,n){let r=typeof n==`string`?n:n.id,i=t.dn(e),a=t.Et(r,e);if(!a)return;let o=e.resolve(a.posBeforeNode),s=o.node(),c=o.node(-1),l=c.type.name===`doc`?void 0:s.type.name===`blockGroup`?c:s;if(l)return t.in(l,i)}var Se=class{constructor(e){this.editor=e}get document(){return this.editor.transact(e=>t.rn(e.doc,this.editor.pmSchema))}getBlock(e){return this.editor.transact(t=>F(t.doc,e))}getPrevBlock(e){return this.editor.transact(t=>I(t.doc,e))}getNextBlock(e){return this.editor.transact(t=>L(t.doc,e))}getParentBlock(e){return this.editor.transact(t=>R(t.doc,e))}forEachBlock(e,t=!1){let n=this.document.slice();t&&n.reverse();function r(n){for(let i of n)if(e(i)===!1||!r(t?i.children.slice().reverse():i.children))return!1;return!0}r(n)}insertBlocks(e,t,n=`before`){return this.editor.transact(r=>b(r,e,t,n))}updateBlock(e,n){return this.editor.transact(r=>t.Ct(r,e,n))}removeBlocks(e){return this.editor.transact(t=>w(t,e,[]).removedBlocks)}replaceBlocks(e,t){return this.editor.transact(n=>w(n,e,t))}canNestBlock(){return be(this.editor)}nestBlock(){M(this.editor)}canUnnestBlock(){return xe(this.editor)}unnestBlock(){P(this.editor)}moveBlocksUp(){return ge(this.editor)}moveBlocksDown(){return _e(this.editor)}},Ce=class extends a.t{constructor(e){super(),this.editor=e,e.on(`create`,()=>{e._tiptapEditor.on(`update`,({transaction:t,appendedTransactions:n})=>{this.emit(`onChange`,{editor:e,transaction:t,appendedTransactions:n})}),e._tiptapEditor.on(`selectionUpdate`,({transaction:t})=>{this.emit(`onSelectionChange`,{editor:e,transaction:t})}),e._tiptapEditor.on(`mount`,()=>{this.emit(`onMount`,{editor:e})}),e._tiptapEditor.on(`unmount`,()=>{this.emit(`onUnmount`,{editor:e})})})}onChange(e,t=!0){let r=({transaction:r,appendedTransactions:i})=>{!t&&z(r)||e(this.editor,{getChanges(){return n.O(r,i)}})};return this.on(`onChange`,r),()=>{this.off(`onChange`,r)}}onSelectionChange(e,t=!1){let n=n=>{!t&&z(n.transaction)||e(this.editor)};return this.on(`onSelectionChange`,n),()=>{this.off(`onSelectionChange`,n)}}onMount(e){return this.on(`onMount`,e),()=>{this.off(`onMount`,e)}}onUnmount(e){return this.on(`onUnmount`,e),()=>{this.off(`onUnmount`,e)}}};function z(e){return!!e.getMeta(`y-sync$`)}function we(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Te(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||``)}function Ee(e){e.querySelectorAll(`li > ul, li > ol`).forEach(e=>{let t=we(e),n=e.parentElement,r=Array.from(n.childNodes).slice(t+1);e.remove(),r.forEach(e=>{e.remove()}),n.insertAdjacentElement(`afterend`,e),r.reverse().forEach(t=>{if(Te(t))return;let n=document.createElement(`li`);n.append(t),e.insertAdjacentElement(`afterend`,n)}),n.childNodes.length===0&&n.remove()})}function De(e){e.querySelectorAll(`li + ul, li + ol`).forEach(e=>{let t=e.previousElementSibling,n=document.createElement(`div`);t.insertAdjacentElement(`afterend`,n),n.append(t);let r=document.createElement(`div`);for(r.setAttribute(`data-node-type`,`blockGroup`),n.append(r);n.nextElementSibling?.nodeName===`UL`||n.nextElementSibling?.nodeName===`OL`;)r.append(n.nextElementSibling)})}var Oe=null;function ke(){return Oe||=document.implementation.createHTMLDocument(`title`)}function Ae(e){if(typeof e==`string`){let t=ke().createElement(`div`);t.innerHTML=e,e=t}return Ee(e),De(e),e}function je(e){let t=e.ownerDocument.createTreeWalker(e,128),n;for(;n=t.nextNode();)if(/^\s*notionvc:/.test(n.nodeValue||``))return!0;return!1}function Me(e){let t=new Set([`PRE`,`CODE`]),n=e.ownerDocument.createTreeWalker(e,4,{acceptNode(n){let r=n.parentElement;for(;r&&r!==e;){if(t.has(r.tagName))return 2;r=r.parentElement}return 1}}),r=[],i;for(;i=n.nextNode();)r.push(i);for(let e of r)e.nodeValue&&/[\r\n]/.test(e.nodeValue)&&(e.nodeValue=e.nodeValue.replace(/[ \t\r\n\f]+/g,` `))}function Ne(e){je(e)||Me(e)}function B(e,n){let r=Ae(e);Ne(r);let i=o.DOMParser.fromSchema(n).parse(r,{topNode:n.nodes.blockGroup.create()}),a=[];for(let e=0;e<i.childCount;e++)a.push(t.in(i.child(e),n));return a}function Pe(e,t){let n=t.value?t.value:``,r={};t.lang&&(r[`data-language`]=t.lang);let i={type:`element`,tagName:`code`,properties:r,children:[{type:`text`,value:n}]};return t.meta&&(i.data={meta:t.meta}),e.patch(t,i),i=e.applyData(t,i),i={type:`element`,tagName:`pre`,properties:{},children:[i]},e.patch(t,i),i}function Fe(e,t){let n=String(t?.url||``),r=t?.title?String(t.title):void 0,i={type:`element`,tagName:`video`,properties:{src:n,"data-name":r,"data-url":n,controls:!0},children:[]};return e.patch?.(t,i),i=e.applyData?e.applyData(t,i):i,i}function V(e){return(0,m.unified)().use(h.default).use(p.default).use(g.default,{handlers:{...g.defaultHandlers,image:(e,n)=>t.An(String(n?.url||``))?Fe(e,n):g.defaultHandlers.image(e,n),code:Pe,blockquote:(e,t)=>{let n={type:`element`,tagName:`blockquote`,properties:{},children:e.wrap(e.all(t),!1)};return e.patch(t,n),e.applyData(t,n)}}}).use(_.default).processSync(e).value}function H(e,t){return B(V(e),t)}var Ie=class{constructor(e){this.editor=e}blocksToHTMLLossy(e=this.editor.document){return n.k(this.editor.pmSchema,this.editor).exportBlocks(e,{})}blocksToFullHTML(e=this.editor.document){return D(this.editor.pmSchema,this.editor).serializeBlocks(e,{})}tryParseHTMLToBlocks(e){return B(e,this.editor.pmSchema)}blocksToMarkdownLossy(e=this.editor.document){return n.u(e,this.editor.pmSchema,this.editor,{})}tryParseMarkdownToBlocks(e){return H(e,this.editor.pmSchema)}pasteHTML(e,t=!1){let n=e;if(!t){let t=this.tryParseHTMLToBlocks(e);n=this.blocksToFullHTML(t)}n&&this.editor.prosemirrorView?.pasteHTML(n)}pasteText(e){return this.editor.prosemirrorView?.pasteText(e)}pasteMarkdown(e){let t=V(e);return this.pasteHTML(t)}},U=[`vscode-editor-data`,`blocknote/html`,`text/markdown`,`text/html`,`text/plain`,`Files`];function Le(e,t){if(!e.startsWith(`.`)||!t.startsWith(`.`))throw Error(`The strings provided are not valid file extensions.`);return e===t}function Re(e,t){let n=e.split(`/`),r=t.split(`/`);if(n.length!==2)throw Error(`The string ${e} is not a valid MIME type.`);if(r.length!==2)throw Error(`The string ${t} is not a valid MIME type.`);return n[1]===`*`||r[1]===`*`?n[0]===r[0]:(n[0]===`*`||r[0]===`*`||n[0]===r[0])&&n[1]===r[1]}function W(e,t,n,r=`after`){let i;return i=Array.isArray(t.content)&&t.content.length===0?e.updateBlock(t,n).id:e.insertBlocks([n],t,r)[0].id,i}async function G(e,n){if(!n.uploadFile){console.warn(`Attempted ot insert file, but uploadFile is not set in the BlockNote editor options`);return}let r=`dataTransfer`in e?e.dataTransfer:e.clipboardData;if(r===null)return;let i=null;for(let e of U)if(r.types.includes(e)){i=e;break}if(i!==`Files`)return;let a=r.items;if(a){e.preventDefault();for(let r=0;r<a.length;r++){let i=`file`;for(let e of Object.values(n.schema.blockSpecs))for(let t of e.implementation.meta?.fileBlockAccept||[]){let n=t.startsWith(`.`),o=a[r].getAsFile();if(o&&(!n&&o.type&&Re(a[r].type,t)||n&&Le(`.`+o.name.split(`.`).pop(),t))){i=e.config.type;break}}let o=a[r].getAsFile();if(o){let r={type:i,props:{name:o.name}},a;if(e.type===`paste`){let e=n.getTextCursorPosition().block;a=W(n,e,r)}else if(e.type===`drop`){let i={left:e.clientX,top:e.clientY},o=n.prosemirrorView.posAtCoords(i);if(!o)return;a=n.transact(e=>{let a=t.vn(e.doc,o.pos),s=(n.domElement?.querySelector(`[data-id="${a.node.attrs.id}"]`))?.getBoundingClientRect();return W(n,n.getBlock(a.node.attrs.id),r,s&&(s.top+s.bottom)/2>i.top?`before`:`after`)})}else return;let s=await n.uploadFile(o,a),c=typeof s==`string`?{props:{url:s}}:{...s};n.updateBlock(a,c)}}}}var ze=e=>c.Extension.create({name:`dropFile`,addProseMirrorPlugins(){return[new l.Plugin({props:{handleDOMEvents:{drop(t,n){if(!e.isEditable)return;let r=null;for(let e of U)if(n.dataTransfer.types.includes(e)){r=e;break}return r===null?!0:r===`Files`?(G(n,e),!0):!1}}}})]}}),Be=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,Ve=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,He=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,Ue=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,We=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,Ge=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,Ke=/\n{2} {0,3}-{2,48}\n{2}/,qe=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,Je=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,Ye=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,Xe=/^\s*\|(.+\|)+\s*$/m,Ze=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,Qe=/^\s*\|(.+\|)+\s*$/m,$e=e=>Be.test(e)||Ve.test(e)||He.test(e)||Ue.test(e)||We.test(e)||Ge.test(e)||Ke.test(e)||qe.test(e)||Je.test(e)||Ye.test(e)||Xe.test(e)||Ze.test(e)||Qe.test(e);async function et(e,t){let{schema:n}=t.state;if(!e.clipboardData)return!1;let r=e.clipboardData.getData(`text/plain`);if(!r)return!1;if(!n.nodes.codeBlock)return t.pasteText(r),!0;let i=e.clipboardData.getData(`vscode-editor-data`),a=(i?JSON.parse(i):void 0)?.mode;return a?(t.pasteHTML(`<pre><code class="language-${a}">${r.replace(/\r\n?/g,`
3
+ `)}</code></pre>`),!0):!1}function tt({event:e,editor:t,prioritizeMarkdownOverHTML:n,plainTextAsMarkdown:r}){if(t.transact(e=>e.selection.$from.parent.type.spec.code&&e.selection.$to.parent.type.spec.code)){let n=e.clipboardData?.getData(`text/plain`);if(n)return t.pasteText(n),!0}let i;for(let t of U)if(e.clipboardData.types.includes(t)){i=t;break}if(!i)return!0;if(i===`vscode-editor-data`)return et(e,t.prosemirrorView),!0;if(i===`Files`)return G(e,t),!0;let a=e.clipboardData.getData(i);if(i===`blocknote/html`)return t.pasteHTML(a,!0),!0;if(i===`text/markdown`)return t.pasteMarkdown(a),!0;if(n){let n=e.clipboardData.getData(`text/plain`);if($e(n))return t.pasteMarkdown(n),!0}return i===`text/html`?(t.pasteHTML(a),!0):r?(t.pasteMarkdown(a),!0):(t.pasteText(a),!0)}var nt=(e,t)=>c.Extension.create({name:`pasteFromClipboard`,addProseMirrorPlugins(){return[new l.Plugin({props:{handleDOMEvents:{paste(n,r){if(r.preventDefault(),e.isEditable)return t({event:r,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:t=!0,plainTextAsMarkdown:n=!0}={})=>tt({event:r,editor:e,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:n})})}}}})]}});function rt(e,r,i){let a=!1,o=e.state.selection instanceof d.CellSelection;if(!o){let t=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,n=[];for(let e=0;e<t.childCount;e++)n.push(t.child(e));a=n.find(e=>e.type.isInGroup(`bnBlock`)||e.type.name===`blockGroup`||e.type.spec.group===`blockContent`)===void 0,a&&(r=t)}let s,c=n.k(e.state.schema,i);if(o){r.firstChild?.type.name===`table`&&(r=r.firstChild.content);let e=t.nn(r,i.schema.inlineContentSchema,i.schema.styleSchema);s=`<table>${c.exportInlineContent(e,{})}</table>`}else if(a){let e=t.tn(r,i.schema.inlineContentSchema,i.schema.styleSchema);s=c.exportInlineContent(e,{})}else{let e=n.l(r);s=c.exportBlocks(e,{})}return s}function K(e,t){`node`in e.state.selection&&e.state.selection.node.type.spec.group===`blockContent`&&t.transact(t=>t.setSelection(new l.NodeSelection(t.doc.resolve(e.state.selection.from-1))));let r=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,i=e.state.selection.content().content,a=rt(e,i,t);return{clipboardHTML:r,externalHTML:a,markdown:n.d(a)}}var q=()=>{let e=window.getSelection();if(!e||e.isCollapsed)return!0;let t=e.focusNode;for(;t;){if(t instanceof HTMLElement&&t.getAttribute(`contenteditable`)===`false`)return!0;t=t.parentElement}return!1},J=(e,t,n)=>{n.preventDefault(),n.clipboardData.clearData();let{clipboardHTML:r,externalHTML:i,markdown:a}=K(t,e);n.clipboardData.setData(`blocknote/html`,r),n.clipboardData.setData(`text/html`,i),n.clipboardData.setData(`text/plain`,a)},it=e=>c.Extension.create({name:`copyToClipboard`,addProseMirrorPlugins(){return[new l.Plugin({props:{handleDOMEvents:{copy(t,n){return q()||J(e,t,n),!0},cut(t,n){return q()?!0:(J(e,t,n),t.editable&&t.dispatch(t.state.tr.deleteSelection()),!0)},dragstart(t,n){if(!(`node`in t.state.selection)||t.state.selection.node.type.spec.group!==`blockContent`)return;e.transact(e=>e.setSelection(new l.NodeSelection(e.doc.resolve(t.state.selection.from-1)))),n.preventDefault(),n.dataTransfer.clearData();let{clipboardHTML:r,externalHTML:i,markdown:a}=K(t,e);return n.dataTransfer.setData(`blocknote/html`,r),n.dataTransfer.setData(`text/html`,i),n.dataTransfer.setData(`text/plain`,a),!0}}}})]}}),at=c.Extension.create({name:`blockBackgroundColor`,addGlobalAttributes(){return[{types:[`tableCell`,`tableHeader`],attributes:{backgroundColor:t.gt()}}]}}),ot=c.Node.create({name:`hardBreak`,inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,(0,c.mergeAttributes)(this.options.HTMLAttributes,e)]},renderText(){return`
4
+ `}}),Y=(e,n)=>{let r=e.resolve(n),i=r.depth-1;if(i<1)return;let a=r.before(i),o=e.resolve(a).nodeAfter;if(o)return o.type.spec.group?.includes(`bnBlock`)?t.mn(e.resolve(a)):Y(e,a)},X=(e,n)=>{let r=e.resolve(n),i=r.index();if(i===0)return;let a=r.posAtIndex(i-1);return t.mn(e.resolve(a))},Z=(e,n)=>{let r=e.resolve(n),i=r.index();if(i===r.node().childCount-1)return;let a=r.posAtIndex(i+1);return t.mn(e.resolve(a))},Q=(e,n)=>{for(;n.childContainer;){let r=n.childContainer.node,i=e.resolve(n.childContainer.beforePos+1).posAtIndex(r.childCount-1);n=t.mn(e.resolve(i))}return n},st=(e,t)=>e.isBlockContainer&&e.blockContent.node.type.spec.content===`inline*`&&e.blockContent.node.childCount>0&&t.isBlockContainer&&t.blockContent.node.type.spec.content===`inline*`,ct=(e,t,n,r)=>{if(!r.isBlockContainer)throw Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);if(r.childContainer){let n=e.doc.resolve(r.childContainer.beforePos+1),i=e.doc.resolve(r.childContainer.afterPos-1),a=n.blockRange(i);if(t){let t=e.doc.resolve(r.bnBlock.beforePos);e.tr.lift(a,t.depth)}}if(t){if(!n.isBlockContainer)throw Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);t(e.tr.delete(n.blockContent.afterPos-1,r.blockContent.beforePos+1))}return!0},$=e=>({state:n,dispatch:r})=>{let i=t.mn(n.doc.resolve(e)),a=X(n.doc,i.bnBlock.beforePos);if(!a)return!1;let o=Q(n.doc,a);return st(o,i)?ct(n,r,o,i):!1},lt=c.Extension.create({priority:50,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({chain:e,commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:e})=>{let r=t.hn(e);if(!r.isBlockContainer)return!1;let i=e.selection.from===r.blockContent.beforePos+1,a=r.blockContent.node.type.name===`paragraph`;return i&&!a?n.command(t.wt(r.bnBlock.beforePos,{type:`paragraph`,props:{}})):!1}),()=>n.command(({state:e,tr:n})=>{let r=t.hn(e);if(!r.isBlockContainer)return!1;let{blockContent:i}=r;return e.selection.from===i.beforePos+1?N(n,n.doc.type.schema.nodes.blockContainer,n.doc.type.schema.nodes.blockGroup):!1}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;let{bnBlock:i,blockContent:a}=r,o=X(n.doc,r.bnBlock.beforePos);if(!o||!o.isBlockContainer||o.blockContent.node.type.spec.content!==`inline*`)return!1;let s=n.selection.from===a.beforePos+1,c=n.selection.empty,l=i.beforePos;return s&&c?e().command($(l)).scrollIntoView().run():!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.hn(e);if(!i.isBlockContainer||e.selection.from!==i.blockContent.beforePos+1)return!1;let a=X(e.doc,i.bnBlock.beforePos);if(!a||a.isBlockContainer)return!1;if(r){let e=a.bnBlock.afterPos-1,t=n.doc.resolve(e-1);return n.delete(i.bnBlock.beforePos,i.bnBlock.afterPos),n.insert(t.pos,i.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(t.pos+1))),!0}return!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.hn(e);if(!i.isBlockContainer||n.selection.from!==i.blockContent.beforePos+1)return!1;let a=n.doc.resolve(i.bnBlock.beforePos);if(a.nodeBefore||a.node().type.name!==`column`)return!1;let o=n.doc.resolve(i.bnBlock.beforePos),s=n.doc.resolve(o.before()),c=s.before();return r&&(n.delete(i.bnBlock.beforePos,i.bnBlock.afterPos),C(n,c),s.pos===c+1?(n.insert(c,i.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(c)))):(n.insert(s.pos-1,i.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(s.pos))))),!0}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;if(r.blockContent.node.childCount===0&&r.blockContent.node.type.spec.content===`inline*`){let t=X(n.doc,r.bnBlock.beforePos);if(!t)return!1;let i=Q(n.doc,t);if(!i.isBlockContainer||!i||!i.isBlockContainer)return!1;let a=e();if(r.childContainer&&a.insertContentAt(r.bnBlock.afterPos,r.childContainer?.node.content),i.blockContent.node.type.spec.content===`tableRow+`){let e=r.bnBlock.beforePos-1-1-1-1-1;a=a.setTextSelection(e)}else if(i.blockContent.node.type.spec.content===``)a=a.setNodeSelection(i.blockContent.beforePos);else{let e=i.blockContent.afterPos-1;a=a.setTextSelection(e)}return a.deleteRange({from:r.bnBlock.beforePos,to:r.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;let i=n.selection.from===r.blockContent.beforePos+1,a=n.selection.empty,o=X(n.doc,r.bnBlock.beforePos);if(o&&i&&a){let t=Q(n.doc,o);if(!t.isBlockContainer)return!1;if(t.blockContent.node.type.spec.content===``||t.blockContent.node.type.spec.content===`inline*`&&t.blockContent.node.childCount===0)return e().cut({from:r.bnBlock.beforePos,to:r.bnBlock.afterPos},t.bnBlock.afterPos).deleteRange({from:t.bnBlock.beforePos,to:t.bnBlock.afterPos}).run()}return!1})]),r=()=>this.editor.commands.first(({chain:e,commands:n})=>[()=>n.deleteSelection(),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer||!r.childContainer)return!1;let{blockContent:i,childContainer:a}=r,s=n.selection.from===i.afterPos-1,c=n.selection.empty,l=t.mn(n.doc.resolve(a.beforePos+1));if(!l.isBlockContainer)return!1;if(s&&c){let t=l.blockContent.node,r=t.type.spec.content===`inline*`,s=i.node.type.spec.content===`inline*`;return e().insertContentAt(l.bnBlock.afterPos,l.childContainer?.node.content||o.Fragment.empty).deleteRange(a.node.childCount===1?{from:a.beforePos,to:a.afterPos}:{from:l.bnBlock.beforePos,to:l.bnBlock.afterPos}).insertContentAt(n.selection.from,r&&s?t.content:null).setTextSelection(n.selection.from).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;let{bnBlock:i,blockContent:a}=r,o=Z(n.doc,r.bnBlock.beforePos);if(!o||!o.isBlockContainer)return!1;let s=n.selection.from===a.afterPos-1,c=n.selection.empty,l=i.afterPos;return s&&c?e().command($(l)).scrollIntoView().run():!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.hn(e);if(!i.isBlockContainer||e.selection.from!==i.blockContent.afterPos-1)return!1;let a=Z(e.doc,i.bnBlock.beforePos);if(!a||a.isBlockContainer)return!1;if(r){let e=a.bnBlock.beforePos+1,t=n.doc.resolve(e+1);return n.delete(t.pos,t.pos+t.nodeAfter.nodeSize),C(n,a.bnBlock.beforePos),n.insert(i.bnBlock.afterPos,t.nodeAfter),n.setSelection(l.TextSelection.near(n.doc.resolve(t.pos))),!0}return!1}),()=>n.command(({state:e,tr:n,dispatch:r})=>{let i=t.hn(e);if(!i.isBlockContainer||n.selection.from!==i.blockContent.afterPos-1)return!1;let a=n.doc.resolve(i.bnBlock.afterPos);if(a.nodeAfter||a.node().type.name!==`column`)return!1;let o=n.doc.resolve(i.bnBlock.afterPos),s=n.doc.resolve(o.after()),c=s.after();if(r){let e=s.pos===c-1?c:s.pos+1,r=t.mn(n.doc.resolve(e));n.delete(r.bnBlock.beforePos,r.bnBlock.afterPos),C(n,c-s.node().nodeSize),n.insert(o.pos,r.bnBlock.node),n.setSelection(l.TextSelection.near(n.doc.resolve(e)))}return!0}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;let{blockContent:i}=r,a=n.selection.from===i.afterPos-1,s=n.selection.empty;if(a&&s){let t=(e,n)=>{let r=Z(e,n);if(r)return r;let i=Y(e,n);if(i)return t(e,i.bnBlock.beforePos)},a=t(n.doc,r.bnBlock.beforePos);if(!a||!a.isBlockContainer)return!1;let s=a.blockContent.node,c=s.type.spec.content===`inline*`,l=i.node.type.spec.content===`inline*`;return e().insertContentAt(a.bnBlock.afterPos,a.childContainer?.node.content||o.Fragment.empty).deleteRange({from:a.bnBlock.beforePos,to:a.bnBlock.afterPos}).insertContentAt(n.selection.from,c&&l?s.content:null).setTextSelection(n.selection.from).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;if(r.blockContent.node.childCount===0&&r.blockContent.node.type.spec.content===`inline*`){let t=Z(n.doc,r.bnBlock.beforePos);if(!t||!t.isBlockContainer)return!1;let i=e();if(t.blockContent.node.type.spec.content===`tableRow+`){let e=r.bnBlock.afterPos+1+1+1+1+1;i=i.setTextSelection(e)}else i=t.blockContent.node.type.spec.content===``?i.setNodeSelection(t.blockContent.beforePos):i.setTextSelection(t.blockContent.beforePos+1);return i.deleteRange({from:r.bnBlock.beforePos,to:r.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>n.command(({state:n})=>{let r=t.hn(n);if(!r.isBlockContainer)return!1;let i=n.selection.from===r.blockContent.afterPos-1,a=n.selection.empty,o=Z(n.doc,r.bnBlock.beforePos);if(!o||!o.isBlockContainer)return!1;if(o&&i&&a&&(o.blockContent.node.type.spec.content===``||o.blockContent.node.type.spec.content===`inline*`&&o.blockContent.node.childCount===0)){let t=o.bnBlock.node.lastChild.content;return e().deleteRange({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos}).insertContentAt(r.bnBlock.afterPos,o.bnBlock.node.childCount===2?t:null).run()}return!1})]),i=(e=!1)=>this.editor.commands.first(({commands:n,tr:r})=>[()=>n.command(({state:e,tr:n})=>{let r=t.hn(e);if(!r.isBlockContainer)return!1;let{bnBlock:i,blockContent:a}=r,{depth:o}=e.doc.resolve(i.beforePos),s=e.selection.$anchor.parentOffset===0,c=e.selection.anchor===e.selection.head,l=a.node.childCount===0;return s&&c&&l&&o>1?N(n,n.doc.type.schema.nodes.blockContainer,n.doc.type.schema.nodes.blockGroup):!1}),()=>n.command(({state:n})=>{let i=t.hn(n),a=this.options.editor.schema.blockSchema[i.blockNoteType].meta?.hardBreakShortcut??`shift+enter`;if(a===`none`)return!1;if(a===`shift+enter`&&e||a===`enter`){let e=r.storedMarks||r.selection.$head.marks().filter(e=>this.editor.extensionManager.splittableMarks.includes(e.type.name));return r.insert(r.selection.head,r.doc.type.schema.nodes.hardBreak.create()).ensureMarks(e),!0}return!1}),()=>n.command(({state:e,dispatch:n,tr:r})=>{let i=t.hn(e);if(!i.isBlockContainer)return!1;let{bnBlock:a,blockContent:o}=i,s=e.selection.$anchor.parentOffset===0,c=e.selection.anchor===e.selection.head,u=o.node.childCount===0;if(s&&c&&u){let t=a.afterPos,o=t+2;if(n){let n=e.schema.nodes.blockContainer.createAndFill(void 0,[e.schema.nodes.paragraph.createAndFill()||void 0,i.childContainer?.node].filter(e=>e!==void 0));r.insert(t,n).setSelection(new l.TextSelection(r.doc.resolve(o))).scrollIntoView(),i.childContainer&&r.delete(i.childContainer.beforePos,i.childContainer.afterPos)}return!0}return!1}),()=>n.command(({state:e,chain:n})=>{let r=t.hn(e);if(!r.isBlockContainer)return!1;let{blockContent:i}=r,a=e.selection.$anchor.parentOffset===0;return i.node.childCount===0?!1:(n().deleteSelection().command(t.V(e.selection.from,a,a)).run(),!0)})]);return{Backspace:e,Delete:r,Enter:()=>i(),"Shift-Enter":()=>i(!0),Tab:()=>this.options.tabBehavior!==`prefer-indent`&&(this.options.editor.getExtension(n.y)?.store.state||this.options.editor.getExtension(t.pt)?.store.state!==void 0)?!1:M(this.options.editor),"Shift-Tab":()=>this.options.tabBehavior!==`prefer-indent`&&(this.options.editor.getExtension(n.y)?.store.state||this.options.editor.getExtension(t.pt)?.store.state!==void 0)?!1:P(this.options.editor),"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}}),ut=c.Mark.create({name:`insertion`,inclusive:!1,excludes:`deletion modification insertion`,addAttributes(){return{id:{default:null,validate:`number`}}},extendMarkSchema(e){return e.name===`insertion`?{blocknoteIgnore:!0,inclusive:!1,toDOM(e,t){return[`ins`,{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:`display: contents`}},0]},parseDOM:[{tag:`ins`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}:{}}}),dt=c.Mark.create({name:`deletion`,inclusive:!1,excludes:`insertion modification deletion`,addAttributes(){return{id:{default:null,validate:`number`}}},extendMarkSchema(e){return e.name===`deletion`?{blocknoteIgnore:!0,inclusive:!1,toDOM(e,t){return[`del`,{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:`display: contents`}},0]},parseDOM:[{tag:`del`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}:{}}}),ft=c.Mark.create({name:`modification`,inclusive:!1,excludes:`deletion insertion`,addAttributes(){return{id:{default:null,validate:`number`},type:{validate:`string`},attrName:{default:null,validate:`string|null`},previousValue:{default:null},newValue:{default:null}}},extendMarkSchema(e){return e.name===`modification`?{blocknoteIgnore:!0,inclusive:!1,toDOM(e,t){return[t?`span`:`div`,{"data-type":`modification`,"data-id":String(e.attrs.id),"data-mod-type":e.attrs.type,"data-mod-prev-val":JSON.stringify(e.attrs.previousValue),"data-mod-new-val":JSON.stringify(e.attrs.newValue)},0]},parseDOM:[{tag:`span[data-type='modification']`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal,newValue:e.dataset.modNewVal}:!1}},{tag:`div[data-type='modification']`,getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal}:!1}}]}:{}}}),pt=c.Extension.create({name:`textAlignment`,addGlobalAttributes(){return[{types:[`tableCell`,`tableHeader`],attributes:{textAlignment:{default:`left`,parseHTML:e=>e.getAttribute(`data-text-alignment`),renderHTML:e=>e.textAlignment===`left`?{}:{"data-text-alignment":e.textAlignment}}}}]}}),mt=c.Extension.create({name:`blockTextColor`,addGlobalAttributes(){return[{types:[`table`,`tableCell`,`tableHeader`],attributes:{textColor:t.vt()}}]}}),ht={blockColor:`data-block-color`,blockStyle:`data-block-style`,id:`data-id`,depth:`data-depth`,depthChange:`data-depth-change`},gt=c.Node.create({name:`blockContainer`,group:`blockGroupChild bnBlock`,content:`blockContent blockGroup?`,priority:50,defining:!0,marks:`insertion modification deletion`,parseHTML(){return[{tag:`div[data-node-type=`+this.name+`]`,getAttrs:e=>{if(typeof e==`string`)return!1;let t={};for(let[n,r]of Object.entries(ht))e.getAttribute(r)&&(t[n]=e.getAttribute(r));return t}},{tag:`div[data-node-type="blockOuter"]`,skip:!0}]},renderHTML({HTMLAttributes:e}){let n=document.createElement(`div`);n.className=`bn-block-outer`,n.setAttribute(`data-node-type`,`blockOuter`);for(let[t,r]of Object.entries(e))t!==`class`&&n.setAttribute(t,r);let r={...this.options.domAttributes?.block||{},...e},i=document.createElement(`div`);i.className=t.Ln(`bn-block`,r.class),i.setAttribute(`data-node-type`,this.name);for(let[e,t]of Object.entries(r))e!==`class`&&i.setAttribute(e,t);return n.appendChild(i),{dom:n,contentDOM:i}}}),_t=c.Node.create({name:`blockGroup`,group:`childContainer`,content:`blockGroupChild+`,marks:`deletion insertion modification`,parseHTML(){return[{tag:`div`,getAttrs:e=>typeof e==`string`?!1:e.getAttribute(`data-node-type`)===`blockGroup`?null:!1}]},renderHTML({HTMLAttributes:e}){let n={...this.options.domAttributes?.blockGroup||{},...e},r=document.createElement(`div`);r.className=t.Ln(`bn-block-group`,n.class),r.setAttribute(`data-node-type`,`blockGroup`);for(let[e,t]of Object.entries(n))e!==`class`&&r.setAttribute(e,t);return{dom:r,contentDOM:r}}}),vt=c.Node.create({name:`doc`,topNode:!0,content:`blockGroup`,marks:`insertion modification deletion`}),yt=e.t(({options:e})=>({key:`collaboration`,blockNoteExtensions:[n.C(e),n.E(e),n.T(e),n.w(),n.S(e)]})),bt=!1;function xt(e,r){let i=[c.extensions.ClipboardTextSerializer,c.extensions.Commands,c.extensions.Editable,c.extensions.FocusEvents,c.extensions.Tabindex,te.Gapcursor,t.Jn.configure({types:[`blockContainer`,`columnList`,`column`],setIdAttribute:r.setIdAttribute,isWithinEditor:e.isWithinEditor}),ot,re.Text,ut,dt,ft,ne.Link.extend({inclusive:!1}).extend({addAttributes(){let e=this.parent?.()||{};return delete e.title,e}}).configure({defaultProtocol:n.h,protocols:bt?[]:n.g}),...Object.values(e.schema.styleSpecs).map(t=>t.implementation.mark.configure({editor:e})),mt,at,pt,c.Extension.create({name:`OverrideEscape`,addKeyboardShortcuts:()=>({Escape:()=>e.getExtension(t.f)?.shown()?!1:(e.blur(),!0)})}),vt,gt.configure({editor:e,domAttributes:r.domAttributes}),lt.configure({editor:e,tabBehavior:r.tabBehavior}),_t.configure({domAttributes:r.domAttributes}),...Object.values(e.schema.inlineContentSpecs).filter(e=>e.config!==`link`&&e.config!==`text`).map(t=>t.implementation.node.configure({editor:e})),...Object.values(e.schema.blockSpecs).flatMap(t=>[...`node`in t.implementation?[t.implementation.node.configure({editor:e,domAttributes:r.domAttributes})]:[]]),it(e),nt(e,r.pasteHandler||(e=>e.defaultPasteHandler())),ze(e)];return bt=!0,i}function St(e,i){let a=[n.D(),n.x(i),t.pt(i),n.y(i),n._(i),n.m(),n.p(i),r.t(i),n.o(i),t.f(i),...i.trailingBlock===!1?[]:[n.t()]];return i.collaboration?a.push(yt(i.collaboration)):a.push(n.v()),`table`in e.schema.blockSpecs&&a.push(n.n(i)),i.animations!==!1&&a.push(n.f()),a}var Ct=class{disabledExtensions=new Set;extensions=[];abortMap=new Map;extensionFactories=new Map;extensionPlugins=new Map;constructor(e,t){this.editor=e,this.options=t,e.onMount(()=>{for(let t of this.extensions)if(t.mount){let n=new window.AbortController,r=t.mount({dom:e.prosemirrorView.dom,root:e.prosemirrorView.root,signal:n.signal});r&&n.signal.addEventListener(`abort`,()=>{r()}),this.abortMap.set(t,n)}}),e.onUnmount(()=>{for(let[e,t]of this.abortMap.entries())this.abortMap.delete(e),t.abort()}),this.disabledExtensions=new Set(t.disableExtensions||[]);for(let e of St(this.editor,this.options))this.addExtension(e);for(let e of this.options.extensions??[])this.addExtension(e);for(let e of Object.values(this.editor.schema.blockSpecs))for(let t of e.extensions??[])this.addExtension(t)}registerExtension(e){let t=[].concat(e).filter(Boolean);if(!t.length){console.warn(`No extensions found to register`,e);return}let n=t.map(e=>this.addExtension(e)).filter(Boolean),r=new Set;for(let e of n)e?.tiptapExtensions&&console.warn(`Extension ${e.key} has tiptap extensions, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,e),e?.inputRules?.length&&console.warn(`Extension ${e.key} has input rules, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,e),this.getProsemirrorPluginsFromExtension(e).plugins.forEach(e=>{r.add(e)});this.updatePlugins(e=>[...e,...r])}addExtension(t){let n;if(n=typeof t==`function`?t({editor:this.editor}):t,!(!n||this.disabledExtensions.has(n.key))){if(typeof t==`function`){let t=n[e.r];typeof t==`function`&&this.extensionFactories.set(t,n)}if(this.extensions.push(n),n.blockNoteExtensions)for(let e of n.blockNoteExtensions)this.addExtension(e);return n}}resolveExtensions(e){let t=[];if(typeof e==`function`){let n=this.extensionFactories.get(e);n&&t.push(n)}else if(Array.isArray(e))for(let n of e)t.push(...this.resolveExtensions(n));else if(typeof e==`object`&&`key`in e)t.push(e);else if(typeof e==`string`){let n=this.extensions.find(t=>t.key===e);n&&t.push(n)}return t}unregisterExtension(e){let t=this.resolveExtensions(e);if(!t.length){console.warn(`No extensions found to unregister`,e);return}let n=!1,r=new Set;for(let i of t)this.extensions=this.extensions.filter(e=>e!==i),this.extensionFactories.forEach((e,t)=>{e===i&&this.extensionFactories.delete(t)}),this.abortMap.get(i)?.abort(),this.abortMap.delete(i),this.extensionPlugins.get(i)?.forEach(e=>{r.add(e)}),this.extensionPlugins.delete(i),i.tiptapExtensions&&!n&&(n=!0,console.warn(`Extension ${i.key} has tiptap extensions, but they will not be removed. Please separate the extension into multiple extensions if you want to remove them, or re-initialize the editor.`,e));this.updatePlugins(e=>e.filter(e=>!r.has(e)))}updatePlugins(e){let t=this.editor.prosemirrorState,n=t.reconfigure({plugins:e(t.plugins.slice())});this.editor.prosemirrorView.updateState(n)}getTiptapExtensions(){let e=xt(this.editor,this.options).filter(e=>!this.disabledExtensions.has(e.name)),n=t.Ht(this.extensions),r=new Map;for(let t of this.extensions){t.tiptapExtensions&&e.push(...t.tiptapExtensions);let i=n(t.key),{plugins:a,inputRules:o}=this.getProsemirrorPluginsFromExtension(t);a.length&&e.push(c.Extension.create({name:t.key,priority:i,addProseMirrorPlugins:()=>a})),o.length&&(r.has(i)||r.set(i,[]),r.get(i).push(...o))}e.push(c.Extension.create({name:`blocknote-input-rules`,addProseMirrorPlugins(){let e=[];return Array.from(r.keys()).sort().reverse().forEach(t=>{e.push(...r.get(t))}),[(0,v.inputRules)({rules:e})]}}));for(let t of this.options._tiptapOptions?.extensions??[])e.push(t);return e}getProsemirrorPluginsFromExtension(e){let n=[...e.prosemirrorPlugins??[]],r=[];return!e.prosemirrorPlugins?.length&&!Object.keys(e.keyboardShortcuts||{}).length&&!e.inputRules?.length?{plugins:n,inputRules:r}:(this.extensionPlugins.set(e,n),e.inputRules?.length&&r.push(...e.inputRules.map(e=>new v.InputRule(e.find,(n,r,i,a)=>{let o=e.replace({match:r,range:{from:i,to:a},editor:this.editor});if(o){let e=this.editor.getTextCursorPosition();if(this.editor.schema.blockSchema[e.block.type].content!==`inline`)return null;let r=t.gn(n.tr),s=n.tr.deleteRange(i,a);return t.Tt(s,r.bnBlock.beforePos,o),s}return null}))),Object.keys(e.keyboardShortcuts||{}).length&&n.push((0,ee.keymap)(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([e,t])=>[e,()=>t({editor:this.editor})])))),{plugins:n,inputRules:r})}getExtensions(){return new Map(this.extensions.map(e=>[e.key,e]))}getExtension(e){if(typeof e==`string`)return this.extensions.find(t=>t.key===e)||void 0;if(typeof e==`function`)return this.extensionFactories.get(e)||void 0;throw Error(`Invalid extension type: ${typeof e}`)}hasExtension(e){return typeof e==`string`?this.extensions.some(t=>t.key===e):typeof e==`object`&&`key`in e?this.extensions.some(t=>t.key===e.key):typeof e==`function`?this.extensionFactories.has(e):!1}};function wt(e,t){let{$from:n,$to:r}=t;if(n.pos>n.start()&&n.pos<e.content.size){let t=e.textBetween(n.pos,n.pos+1);if(/^[\w\p{P}]$/u.test(t)){let t=e.textBetween(n.start(),n.pos).match(/[\w\p{P}]+$/u);t&&(n=e.resolve(n.pos-t[0].length))}}if(r.pos<r.end()&&r.pos>0){let t=e.textBetween(r.pos-1,r.pos);if(/^[\w\p{P}]$/u.test(t)){let t=e.textBetween(r.pos,r.end()).match(/^[\w\p{P}]+/u);t&&(r=e.resolve(r.pos+t[0].length))}}return{$from:n,$to:r,from:n.pos,to:r.pos}}function Tt(e){let n=t.dn(e);if(e.selection.empty||`node`in e.selection)return;let r=e.doc.resolve(t.vn(e.doc,e.selection.from).posBeforeNode),i=e.doc.resolve(t.vn(e.doc,e.selection.to).posBeforeNode),a=(i,a)=>{let o=r.posAtIndex(i,a),s=e.doc.resolve(o).nodeAfter;if(!s)throw Error(`Error getting selection - node not found at position ${o}`);return t.in(s,n)},o=[],s=r.sharedDepth(i.pos),c=r.index(s),l=i.index(s);if(r.depth>s){o.push(t.in(r.nodeAfter,n));for(let e=r.depth;e>s;e--)if(r.node(e).type.isInGroup(`childContainer`)){let t=r.index(e)+1,n=r.node(e).childCount;for(let r=t;r<n;r++)o.push(a(r,e))}}else o.push(a(c,s));for(let e=c+1;e<=l;e++)o.push(a(e,s));if(o.length===0)throw Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:o}}function Et(e,n,r){let i=typeof n==`string`?n:n.id,a=typeof r==`string`?r:r.id,o=t.cn(t.dn(e));if(i===a)throw Error(`Attempting to set selection with the same anchor and head blocks (id ${i})`);let s=t.Et(i,e.doc);if(!s)throw Error(`Block with ID ${i} not found`);let c=t.Et(a,e.doc);if(!c)throw Error(`Block with ID ${a} not found`);let u=t.pn(s),f=t.pn(c),p=o.blockSchema[u.blockNoteType],m=o.blockSchema[f.blockNoteType];if(!u.isBlockContainer||p.content===`none`)throw Error(`Attempting to set selection anchor in block without content (id ${i})`);if(!f.isBlockContainer||m.content===`none`)throw Error(`Attempting to set selection anchor in block without content (id ${a})`);let h,g;if(p.content===`table`){let e=d.TableMap.get(u.blockContent.node);h=u.blockContent.beforePos+e.positionAt(0,0,u.blockContent.node)+1+2}else h=u.blockContent.beforePos+1;if(m.content===`table`){let t=d.TableMap.get(f.blockContent.node),n=f.blockContent.beforePos+t.positionAt(t.height-1,t.width-1,f.blockContent.node)+1;g=n+e.doc.resolve(n).nodeAfter.nodeSize-2}else g=f.blockContent.afterPos-1;e.setSelection(l.TextSelection.create(e.doc,h,g))}function Dt(e,n=!1){let r=t.dn(e),i=n?wt(e.doc,e.selection):e.selection,a=i.$from,o=i.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=e.doc.resolve(o.pos+1);for(;o.parentOffset===0&&o.depth>0;)o=e.doc.resolve(o.pos-1);for(;a.parentOffset===0&&a.depth>0;)a=e.doc.resolve(a.pos-1);for(;a.parentOffset>=a.parent.nodeSize-2&&a.depth>0;)a=e.doc.resolve(a.pos+1);let s=t.on(e.doc.slice(a.pos,o.pos,!0),r);return{_meta:{startPos:a.pos,endPos:o.pos},...s}}function Ot(e){let{bnBlock:n}=t.gn(e),r=t.dn(e.doc),i=e.doc.resolve(n.beforePos),a=i.nodeBefore,o=e.doc.resolve(n.afterPos).nodeAfter,s;return i.depth>1&&(s=i.node(),s.type.isInGroup(`bnBlock`)||(s=i.node(i.depth-1))),{block:t.in(n.node,r),prevBlock:a===null?void 0:t.in(a,r),nextBlock:o===null?void 0:t.in(o,r),parentBlock:s===void 0?void 0:t.in(s,r)}}function kt(e,n,r=`start`){let i=typeof n==`string`?n:n.id,a=t.cn(t.dn(e.doc)),o=t.Et(i,e.doc);if(!o)throw Error(`Block with ID ${i} not found`);let s=t.pn(o),c=a.blockSchema[s.blockNoteType].content;if(s.isBlockContainer){let n=s.blockContent;if(c===`none`){e.setSelection(l.NodeSelection.create(e.doc,n.beforePos));return}if(c===`inline`)r===`start`?e.setSelection(l.TextSelection.create(e.doc,n.beforePos+1)):e.setSelection(l.TextSelection.create(e.doc,n.afterPos-1));else if(c===`table`)r===`start`?e.setSelection(l.TextSelection.create(e.doc,n.beforePos+4)):e.setSelection(l.TextSelection.create(e.doc,n.afterPos-4));else throw new t.Rn(c)}else kt(e,(r===`start`?s.childContainer.node.firstChild:s.childContainer.node.lastChild).attrs.id,r)}var At=class{constructor(e){this.editor=e}getSelection(){return this.editor.transact(e=>Tt(e))}getSelectionCutBlocks(e=!1){return this.editor.transact(t=>Dt(t,e))}setSelection(e,t){return this.editor.transact(n=>Et(n,e,t))}getTextCursorPosition(){return this.editor.transact(e=>Ot(e))}setTextCursorPosition(e,t=`start`){return this.editor.transact(n=>kt(n,e,t))}getSelectionBoundingBox(){if(!this.editor.prosemirrorView)return;let{selection:e}=this.editor.prosemirrorState,{ranges:t}=e,n=Math.min(...t.map(e=>e.$from.pos)),r=Math.max(...t.map(e=>e.$to.pos));if((0,c.isNodeSelection)(e)){let e=this.editor.prosemirrorView.nodeDOM(n);if(e)return e.getBoundingClientRect()}return(0,c.posToDOMRect)(this.editor.prosemirrorView,n,r).toJSON()}},jt=class{constructor(e){this.editor=e}activeTransaction=null;can(e){try{return this.isInCan=!0,e()}finally{this.isInCan=!1}}isInCan=!1;exec(e){if(this.activeTransaction)throw Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");if(this.isInCan)return this.canExec(e);let t=this.prosemirrorState,n=this.prosemirrorView;return e(t,e=>this.prosemirrorView.dispatch(e),n)}canExec(e){if(this.activeTransaction)throw Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");let t=this.prosemirrorState,n=this.prosemirrorView;return e(t,void 0,n)}transact(e){if(this.activeTransaction)return e(this.activeTransaction);try{this.activeTransaction=this.editor._tiptapEditor.state.tr;let t=e(this.activeTransaction),n=this.activeTransaction;return this.activeTransaction=null,n&&(n.docChanged||n.selectionSet||n.scrolledIntoView||n.storedMarksSet||!n.isGeneric)&&this.prosemirrorView.dispatch(n),t}finally{this.activeTransaction=null}}get prosemirrorState(){if(this.activeTransaction)throw Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this.editor._tiptapEditor.state}get prosemirrorView(){return this.editor._tiptapEditor.view}isFocused(){return this.prosemirrorView?.hasFocus()||!1}focus(){this.prosemirrorView?.focus()}get isEditable(){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw Error(`no editor, but also not headless?`);return!1}return this.editor._tiptapEditor.isEditable===void 0?!0:this.editor._tiptapEditor.isEditable}set isEditable(e){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw Error(`no editor, but also not headless?`);return}this.editor._tiptapEditor.options.editable!==e&&this.editor._tiptapEditor.setEditable(e)}undo(){let e=this.editor.getExtension(`yUndo`);if(e)return this.exec(e.undoCommand);let t=this.editor.getExtension(`history`);if(t)return this.exec(t.undoCommand);throw Error(`No undo plugin found`)}redo(){let e=this.editor.getExtension(`yUndo`);if(e)return this.exec(e.redoCommand);let t=this.editor.getExtension(`history`);if(t)return this.exec(t.redoCommand);throw Error(`No redo plugin found`)}};function Mt(e,t,n,r={updateSelection:!0}){let{from:i,to:a}=typeof t==`number`?{from:t,to:t}:{from:t.from,to:t.to},o=!0,s=!0,l=``;if(n.forEach(e=>{e.check(),o&&e.isText&&e.marks.length===0?l+=e.text:o=!1,s=s?e.isBlock:!1}),i===a&&s){let{parent:t}=e.doc.resolve(i);t.isTextblock&&!t.type.spec.code&&!t.childCount&&(--i,a+=1)}return o?e.insertText(l,i,a):e.replaceWith(i,a,n),r.updateSelection&&(0,c.selectionToInsertionEnd)(e,e.steps.length-1,-1),!0}var Nt=class{constructor(e){this.editor=e}insertInlineContent(e,{updateSelection:n=!1}={}){let r=t.kt(e,this.editor.pmSchema);this.editor.transact(e=>{Mt(e,{from:e.selection.from,to:e.selection.to},r,{updateSelection:n})})}getActiveStyles(){return this.editor.transact(e=>{let t={},n=e.selection.$to.marks();for(let e of n){let n=this.editor.schema.styleSchema[e.type.name];if(!n){e.type.name!==`link`&&!e.type.spec.blocknoteIgnore&&console.warn(`mark not found in styleschema`,e.type.name);continue}n.propSchema===`boolean`?t[n.type]=!0:t[n.type]=e.attrs.stringValue}return t})}addStyles(e){for(let[n,r]of Object.entries(e)){let e=this.editor.schema.styleSchema[n];if(!e)throw Error(`style ${n} not found in styleSchema`);if(e.propSchema===`boolean`)this.editor._tiptapEditor.commands.setMark(n);else if(e.propSchema===`string`)this.editor._tiptapEditor.commands.setMark(n,{stringValue:r});else throw new t.Rn(e.propSchema)}}removeStyles(e){for(let t of Object.keys(e))this.editor._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){for(let[n,r]of Object.entries(e)){let e=this.editor.schema.styleSchema[n];if(!e)throw Error(`style ${n} not found in styleSchema`);if(e.propSchema===`boolean`)this.editor._tiptapEditor.commands.toggleMark(n);else if(e.propSchema===`string`)this.editor._tiptapEditor.commands.toggleMark(n,{stringValue:r});else throw new t.Rn(e.propSchema)}}getSelectedText(){return this.editor.transact(e=>e.doc.textBetween(e.selection.from,e.selection.to))}getSelectedLinkUrl(){return this.editor._tiptapEditor.getAttributes(`link`).href}createLink(e,t){if(e===``)return;let n=this.editor.pmSchema.mark(`link`,{href:e});this.editor.transact(e=>{let{from:r,to:i}=e.selection;t?e.insertText(t,r,i).addMark(r,r+t.length,n):e.setSelection(f.TextSelection.create(e.doc,i)).addMark(r,i,n)})}};function Pt(e){return(0,c.findParentNodeClosestToPos)(e.state.selection.$from,e=>e.type.name===`tableCell`||e.type.name===`tableHeader`)!==void 0}function Ft(e,t){let n=t.nodes.hardBreak,r=u.Fragment.empty;return e.forEach(e=>{e.isTextblock&&e.childCount>0?(r=r.append(e.content),r=r.addToEnd(n.create())):e.isText?r=r.addToEnd(e):e.isBlock&&e.childCount>0&&(r=r.append(Ft(e.content,t)),r=r.addToEnd(n.create()))}),r.lastChild?.type===n&&(r=r.cut(0,r.size-1)),r}function It(e,t){let n=[];return e.forEach((e,r,i)=>{i!==t&&n.push(e)}),u.Fragment.from(n)}function Lt(e,t){let n=[];for(let r=0;r<e.childCount;r++)if(e.child(r).type.name===`tableRow`)if(n.length>0&&n[n.length-1].type.name===`table`){let t=n[n.length-1],i=t.copy(t.content.addToEnd(e.child(r)));n[n.length-1]=i}else{let i=t.nodes.table.createChecked(void 0,e.child(r));n.push(i)}else n.push(e.child(r));return e=u.Fragment.from(n),e}function Rt(e,t){let n=u.Fragment.from(e.content);if(n=Lt(n,t.state.schema),Pt(t)){let e=!1;if(n.descendants(t=>{t.type.isInGroup(`tableContent`)&&(e=!0)}),!e&&!t.state.schema.nodes.tableParagraph.validContent(n))return new u.Slice(Ft(n,t.state.schema),0,0)}if(!zt(n,t))return new u.Slice(n,e.openStart,e.openEnd);for(let e=0;e<n.childCount;e++)if(n.child(e).type.spec.group===`blockContent`){let r=[n.child(e)];if(e+1<n.childCount&&n.child(e+1).type.name===`blockGroup`){let t=n.child(e+1).child(0).child(0);(t.type.name===`bulletListItem`||t.type.name===`numberedListItem`||t.type.name===`checkListItem`)&&(r.push(n.child(e+1)),n=It(n,e+1))}let i=t.state.schema.nodes.blockContainer.createChecked(void 0,r);n=n.replaceChild(e,i)}return new u.Slice(n,e.openStart,e.openEnd)}function zt(e,n){let r=e.childCount===1,i=e.firstChild?.type.spec.content===`inline*`,a=e.firstChild?.type.spec.content===`tableRow+`;if(r){if(i)return!1;if(a){let e=t.hn(n.state);if(e.isBlockContainer)return e.blockContent.node.type.spec.content!==`tableRow+`}}return!0}var Bt={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1},Vt=class e extends a.t{pmSchema;_tiptapEditor;elementRenderer=null;blockCache=new WeakMap;dictionary;schema;blockImplementations;inlineContentImplementations;styleImplementations;uploadFile;onUploadStartCallbacks=[];onUploadEndCallbacks=[];resolveFileUrl;settings;static create(t){return new e(t??{})}constructor(e){super(),this.options=e,this.dictionary=e.dictionary||i.t,this.settings={tables:{splitCells:e?.tables?.splitCells??!1,cellBackgroundColor:e?.tables?.cellBackgroundColor??!1,cellTextColor:e?.tables?.cellTextColor??!1,headers:e?.tables?.headers??!1}};let n={defaultStyles:!0,schema:e.schema||t.t.create(),...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(this.schema=n.schema,this.blockImplementations=n.schema.blockSpecs,this.inlineContentImplementations=n.schema.inlineContentSpecs,this.styleImplementations=n.schema.styleSpecs,n.uploadFile){let e=n.uploadFile;this.uploadFile=async(t,n)=>{this.onUploadStartCallbacks.forEach(e=>e.apply(this,[n]));try{return await e(t,n)}finally{this.onUploadEndCallbacks.forEach(e=>e.apply(this,[n]))}}}this.resolveFileUrl=n.resolveFileUrl,this._eventManager=new Ce(this),this._extensionManager=new Ct(this,n);let r=this._extensionManager.getTiptapExtensions(),a=this._extensionManager.hasExtension(`ySync`)||this._extensionManager.hasExtension(`liveblocksExtension`);a&&n.initialContent&&console.warn(`When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider`);let s={...Bt,...n._tiptapOptions,element:null,autofocus:n.autofocus??!1,extensions:r,editorProps:{...n._tiptapOptions?.editorProps,attributes:{tabIndex:`0`,...n._tiptapOptions?.editorProps?.attributes,...n.domAttributes?.editor,class:t.Ln(`bn-editor`,n.defaultStyles?`bn-default-styles`:``,n.domAttributes?.editor?.class||``)},transformPasted:Rt}};try{let e=n.initialContent||(a?[{type:`paragraph`,id:`initialBlockId`}]:[{type:`paragraph`,id:t.Jn.options.generateID()}]);if(!Array.isArray(e)||e.length===0)throw Error(`initialContent must be a non-empty array of blocks, received: `+e);let r=(0,c.getSchema)(s.extensions),i=(0,c.createDocument)({type:`doc`,content:[{type:`blockGroup`,content:e.map(e=>t.Ot(e,r,this.schema.styleSchema).toJSON())}]},r,s.parseOptions);this._tiptapEditor=new c.Editor({...s,content:i.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(e){throw Error("Error creating document from blocks passed as `initialContent`",{cause:e})}let l,u=this.pmSchema.nodes.doc.createAndFill;this.pmSchema.nodes.doc.createAndFill=(...e)=>{if(l)return l;let t=u.apply(this.pmSchema.nodes.doc,e),n=JSON.parse(JSON.stringify(t.toJSON()));return n.content[0].content[0].attrs.id=`initialBlockId`,l=o.Node.fromJSON(this.pmSchema,n),l},this.pmSchema.cached.blockNoteEditor=this,this._blockManager=new Se(this),this._exportManager=new Ie(this),this._selectionManager=new At(this),this._stateManager=new jt(this),this._styleManager=new Nt(this),this.emit(`create`)}_blockManager;_eventManager;_exportManager;_extensionManager;_selectionManager;_stateManager;_styleManager;get extensions(){return this._extensionManager.getExtensions()}exec(e){return this._stateManager.exec(e)}canExec(e){return this._stateManager.canExec(e)}transact(e){return this._stateManager.transact(e)}unregisterExtension=(...e)=>this._extensionManager.unregisterExtension(...e);registerExtension=(...e)=>this._extensionManager.registerExtension(...e);getExtension=((...e)=>this._extensionManager.getExtension(...e));mount=e=>{let t=e.getRootNode();typeof ShadowRoot<`u`&&t instanceof ShadowRoot?t.appendChild(this.portalElement):document.body.appendChild(this.portalElement),this._tiptapEditor.mount({mount:e})};unmount=()=>{this.portalElement?.remove(),this._tiptapEditor.unmount()};get prosemirrorState(){return this._stateManager.prosemirrorState}get prosemirrorView(){return this._stateManager.prosemirrorView}get domElement(){if(!this.headless)return this.prosemirrorView?.dom}_portalElement;get portalElement(){if(typeof document>`u`)throw Error(`Portal element accessed, but not available in headless mode`);return this._portalElement||=document.createElement(`div`),this._portalElement}isWithinEditor=e=>!!(this.domElement?.parentElement?.contains(e)||this.portalElement?.contains(e));isFocused(){return this.headless?!1:this.prosemirrorView?.hasFocus()||!1}get headless(){return!this._tiptapEditor.isInitialized}focus(){this.headless||this.prosemirrorView.focus()}blur(){this.headless||this.domElement?.blur()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{let t=this.onUploadStartCallbacks.indexOf(e);t>-1&&this.onUploadStartCallbacks.splice(t,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{let t=this.onUploadEndCallbacks.indexOf(e);t>-1&&this.onUploadEndCallbacks.splice(t,1)}}get topLevelBlocks(){return this.document}get document(){return this._blockManager.document}getBlock(e){return this._blockManager.getBlock(e)}getPrevBlock(e){return this._blockManager.getPrevBlock(e)}getNextBlock(e){return this._blockManager.getNextBlock(e)}getParentBlock(e){return this._blockManager.getParentBlock(e)}forEachBlock(e,t=!1){this._blockManager.forEachBlock(e,t)}onEditorContentChange(e){this._tiptapEditor.on(`update`,e)}onEditorSelectionChange(e){this._tiptapEditor.on(`selectionUpdate`,e)}onBeforeChange(e){return this._extensionManager.getExtension(n.D).subscribe(e)}getTextCursorPosition(){return this._selectionManager.getTextCursorPosition()}setTextCursorPosition(e,t=`start`){return this._selectionManager.setTextCursorPosition(e,t)}getSelection(){return this._selectionManager.getSelection()}getSelectionCutBlocks(e=!1){return this._selectionManager.getSelectionCutBlocks(e)}setSelection(e,t){return this._selectionManager.setSelection(e,t)}get isEditable(){return this._stateManager.isEditable}set isEditable(e){this._stateManager.isEditable=e}insertBlocks(e,t,n=`before`){return this._blockManager.insertBlocks(e,t,n)}updateBlock(e,t){return this._blockManager.updateBlock(e,t)}removeBlocks(e){return this._blockManager.removeBlocks(e)}replaceBlocks(e,t){return this._blockManager.replaceBlocks(e,t)}undo(){return this._stateManager.undo()}redo(){return this._stateManager.redo()}insertInlineContent(e,{updateSelection:t=!1}={}){this._styleManager.insertInlineContent(e,{updateSelection:t})}getActiveStyles(){return this._styleManager.getActiveStyles()}addStyles(e){this._styleManager.addStyles(e)}removeStyles(e){this._styleManager.removeStyles(e)}toggleStyles(e){this._styleManager.toggleStyles(e)}getSelectedText(){return this._styleManager.getSelectedText()}getSelectedLinkUrl(){return this._styleManager.getSelectedLinkUrl()}createLink(e,t){this._styleManager.createLink(e,t)}canNestBlock(){return this._blockManager.canNestBlock()}nestBlock(){this._blockManager.nestBlock()}canUnnestBlock(){return this._blockManager.canUnnestBlock()}unnestBlock(){this._blockManager.unnestBlock()}moveBlocksUp(){return this._blockManager.moveBlocksUp()}moveBlocksDown(){return this._blockManager.moveBlocksDown()}blocksToHTMLLossy(e=this.document){return this._exportManager.blocksToHTMLLossy(e)}blocksToFullHTML(e=this.document){return this._exportManager.blocksToFullHTML(e)}tryParseHTMLToBlocks(e){return this._exportManager.tryParseHTMLToBlocks(e)}blocksToMarkdownLossy(e=this.document){return this._exportManager.blocksToMarkdownLossy(e)}tryParseMarkdownToBlocks(e){return this._exportManager.tryParseMarkdownToBlocks(e)}onChange(e,t){return this._eventManager.onChange(e,t)}onSelectionChange(e,t){return this._eventManager.onSelectionChange(e,t)}onMount(e){this._eventManager.onMount(e)}onUnmount(e){this._eventManager.onUnmount(e)}getSelectionBoundingBox(){return this._selectionManager.getSelectionBoundingBox()}get isEmpty(){let e=this.document;return e.length===0||e.length===1&&e[0].type===`paragraph`&&e[0].content.length===0}pasteHTML(e,t=!1){this._exportManager.pasteHTML(e,t)}pasteText(e){return this._exportManager.pasteText(e)}pasteMarkdown(e){return this._exportManager.pasteMarkdown(e)}},Ht=class{constructor(e,t,n){this.mappings=t,this.options=n}async resolveFile(e){if(!this.options?.resolveFileUrl)return(await fetch(e)).blob();let t=await this.options.resolveFileUrl(e);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(e){return Object.entries(e).map(([e,t])=>this.mappings.styleMapping[e](t,this))}mapInlineContent(e){return this.mappings.inlineContentMapping[e.type](e,this)}transformInlineContent(e){return e.map(e=>this.mapInlineContent(e))}async mapBlock(e,t,n,r){return this.mappings.blockMapping[e.type](e,this,t,n,r)}};function Ut(e){return{createBlockMapping:e=>e,createInlineContentMapping:e=>e,createStyleMapping:e=>e}}function Wt(e,...t){let n=[...e];for(let e of t)for(let t of e){let e=n.findLastIndex(e=>e.group===t.group);e===-1?n.push(t):n.splice(e+1,0,t)}return n}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return wt}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return Vt}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Ut}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Ht}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Wt}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return b}});
5
+ //# sourceMappingURL=src-BKJH7Jla.cjs.map