@blocknote/core 0.42.2 → 0.43.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 (200) hide show
  1. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +2 -0
  2. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +1 -0
  3. package/dist/BlockNoteExtension-C2X7LW-V.js +25 -0
  4. package/dist/BlockNoteExtension-C2X7LW-V.js.map +1 -0
  5. package/dist/BlockNoteSchema-CbSavEwr.js +270 -0
  6. package/dist/BlockNoteSchema-CbSavEwr.js.map +1 -0
  7. package/dist/BlockNoteSchema-D8TyvlfU.cjs +2 -0
  8. package/dist/BlockNoteSchema-D8TyvlfU.cjs.map +1 -0
  9. package/dist/EventEmitter-CLwfmbqG.cjs +2 -0
  10. package/dist/EventEmitter-CLwfmbqG.cjs.map +1 -0
  11. package/dist/EventEmitter-CjSwpTbz.js +27 -0
  12. package/dist/EventEmitter-CjSwpTbz.js.map +1 -0
  13. package/dist/ShowSelection-BW37oJ6h.cjs +2 -0
  14. package/dist/ShowSelection-BW37oJ6h.cjs.map +1 -0
  15. package/dist/ShowSelection-Dz-NEase.js +43 -0
  16. package/dist/ShowSelection-Dz-NEase.js.map +1 -0
  17. package/dist/TrailingNode-BUhuMJrB.js +2096 -0
  18. package/dist/TrailingNode-BUhuMJrB.js.map +1 -0
  19. package/dist/TrailingNode-CaT_wbho.cjs +2 -0
  20. package/dist/TrailingNode-CaT_wbho.cjs.map +1 -0
  21. package/dist/{blockToNode-DIfPWLH8.js → blockToNode-DBNbhwwC.js} +33 -33
  22. package/dist/blockToNode-DBNbhwwC.js.map +1 -0
  23. package/dist/blockToNode-w7H99R6p.cjs.map +1 -1
  24. package/dist/blocknote.cjs +4 -4
  25. package/dist/blocknote.cjs.map +1 -1
  26. package/dist/blocknote.js +2401 -5592
  27. package/dist/blocknote.js.map +1 -1
  28. package/dist/blocks.cjs +1 -1
  29. package/dist/blocks.js +71 -70
  30. package/dist/blocks.js.map +1 -1
  31. package/dist/comments.cjs +1 -1
  32. package/dist/comments.cjs.map +1 -1
  33. package/dist/comments.js +451 -137
  34. package/dist/comments.js.map +1 -1
  35. package/dist/{BlockNoteSchema-Bi-eeHal.js → defaultBlocks-BJtxTOM2.js} +991 -1047
  36. package/dist/defaultBlocks-BJtxTOM2.js.map +1 -0
  37. package/dist/defaultBlocks-BxFclIGP.cjs +6 -0
  38. package/dist/defaultBlocks-BxFclIGP.cjs.map +1 -0
  39. package/dist/extensions.cjs +2 -0
  40. package/dist/extensions.cjs.map +1 -0
  41. package/dist/extensions.js +57 -0
  42. package/dist/extensions.js.map +1 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.js +1 -1
  46. package/package.json +12 -6
  47. package/src/api/nodeConversions/blockToNode.ts +1 -1
  48. package/src/api/nodeConversions/nodeToBlock.ts +1 -1
  49. package/src/blocks/Code/block.ts +4 -4
  50. package/src/blocks/Divider/block.ts +2 -2
  51. package/src/blocks/File/helpers/render/createAddFileButton.ts +7 -5
  52. package/src/blocks/Heading/block.ts +23 -20
  53. package/src/blocks/ListItem/BulletListItem/block.ts +2 -2
  54. package/src/blocks/ListItem/CheckListItem/block.ts +2 -2
  55. package/src/blocks/ListItem/NumberedListItem/block.ts +3 -3
  56. package/src/blocks/ListItem/ToggleListItem/block.ts +2 -2
  57. package/src/blocks/PageBreak/getPageBreakSlashMenuItems.ts +2 -2
  58. package/src/blocks/Paragraph/block.ts +2 -2
  59. package/src/blocks/Quote/block.ts +2 -2
  60. package/src/blocks/Table/block.ts +4 -3
  61. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +2 -1
  62. package/src/comments/extension.ts +353 -0
  63. package/src/comments/index.ts +2 -1
  64. package/src/comments/types.ts +8 -0
  65. package/src/{extensions/Comments → comments}/userstore/UserStore.ts +2 -2
  66. package/src/editor/BlockNoteEditor.test.ts +2 -23
  67. package/src/editor/BlockNoteEditor.ts +66 -453
  68. package/src/editor/BlockNoteExtension.test.ts +103 -0
  69. package/src/editor/BlockNoteExtension.ts +174 -56
  70. package/src/editor/managers/EventManager.ts +64 -35
  71. package/src/editor/managers/ExtensionManager/extensions.ts +214 -0
  72. package/src/editor/managers/ExtensionManager/index.ts +514 -0
  73. package/src/editor/managers/ExtensionManager/symbol.ts +6 -0
  74. package/src/editor/managers/SelectionManager.ts +5 -1
  75. package/src/editor/managers/StateManager.ts +29 -17
  76. package/src/editor/managers/index.ts +1 -5
  77. package/src/extensions/BlockChange/{BlockChangePlugin.ts → BlockChange.ts} +27 -29
  78. package/src/extensions/Collaboration/{ForkYDocPlugin.test.ts → ForkYDoc.test.ts} +6 -5
  79. package/src/extensions/Collaboration/ForkYDoc.ts +158 -0
  80. package/src/extensions/Collaboration/YCursorPlugin.ts +183 -0
  81. package/src/extensions/Collaboration/YSync.ts +16 -0
  82. package/src/extensions/Collaboration/YUndo.ts +12 -0
  83. package/src/extensions/Collaboration/schemaMigration/SchemaMigration.ts +59 -0
  84. package/src/extensions/DropCursor/DropCursor.ts +26 -0
  85. package/src/extensions/FilePanel/FilePanel.ts +41 -0
  86. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +119 -0
  87. package/src/extensions/History/History.ts +11 -0
  88. package/src/extensions/LinkToolbar/LinkToolbar.ts +121 -0
  89. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +74 -0
  90. package/src/extensions/Placeholder/Placeholder.ts +148 -0
  91. package/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.ts → PreviousBlockType.ts} +9 -13
  92. package/src/extensions/ShowSelection/{ShowSelectionPlugin.ts → ShowSelection.ts} +27 -33
  93. package/src/extensions/SideMenu/{SideMenuPlugin.ts → SideMenu.ts} +63 -83
  94. package/src/extensions/SuggestionMenu/{SuggestionPlugin.ts → SuggestionMenu.ts} +71 -77
  95. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +29 -44
  96. package/src/extensions/TableHandles/{TableHandlesPlugin.ts → TableHandles.ts} +416 -437
  97. package/src/extensions/TrailingNode/{TrailingNodeExtension.ts → TrailingNode.ts} +8 -17
  98. package/src/extensions/index.ts +24 -0
  99. package/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.ts +1 -1
  100. package/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.ts +21 -16
  101. package/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.ts +1 -1
  102. package/src/extensions/tiptap-extensions/index.ts +31 -0
  103. package/src/index.ts +1 -13
  104. package/src/schema/blocks/createSpec.ts +14 -11
  105. package/src/schema/blocks/internal.ts +2 -2
  106. package/src/schema/blocks/types.ts +8 -5
  107. package/src/schema/schema.ts +11 -36
  108. package/src/util/topo-sort.ts +46 -0
  109. package/types/src/comments/extension.d.ts +70 -0
  110. package/types/src/comments/index.d.ts +2 -1
  111. package/types/src/comments/types.d.ts +8 -0
  112. package/types/src/{extensions/Comments → comments}/userstore/UserStore.d.ts +2 -2
  113. package/types/src/editor/BlockNoteEditor.d.ts +34 -105
  114. package/types/src/editor/BlockNoteExtension.d.ts +87 -22
  115. package/types/src/editor/managers/EventManager.d.ts +25 -16
  116. package/types/src/editor/managers/ExtensionManager/extensions.d.ts +8 -0
  117. package/types/src/editor/managers/ExtensionManager/index.d.ts +83 -0
  118. package/types/src/editor/managers/ExtensionManager/symbol.d.ts +5 -0
  119. package/types/src/editor/managers/StateManager.d.ts +1 -12
  120. package/types/src/editor/managers/index.d.ts +1 -2
  121. package/types/src/extensions/BlockChange/BlockChange.d.ts +16 -0
  122. package/types/src/extensions/Collaboration/ForkYDoc.d.ts +34 -0
  123. package/types/src/extensions/Collaboration/ForkYDoc.test.d.ts +1 -0
  124. package/types/src/extensions/Collaboration/YCursorPlugin.d.ts +24 -0
  125. package/types/src/extensions/Collaboration/YSync.d.ts +8 -0
  126. package/types/src/extensions/Collaboration/YUndo.d.ts +12 -0
  127. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigration.d.ts +8 -0
  128. package/types/src/extensions/DropCursor/DropCursor.d.ts +5 -0
  129. package/types/src/extensions/FilePanel/FilePanel.d.ts +11 -0
  130. package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +9 -0
  131. package/types/src/extensions/History/History.d.ts +6 -0
  132. package/types/src/extensions/LinkToolbar/LinkToolbar.d.ts +24 -0
  133. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +5 -0
  134. package/types/src/extensions/Placeholder/Placeholder.d.ts +6 -0
  135. package/types/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.d.ts → PreviousBlockType.d.ts} +9 -5
  136. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +21 -0
  137. package/types/src/extensions/SideMenu/{SideMenuPlugin.d.ts → SideMenu.d.ts} +11 -15
  138. package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +54 -0
  139. package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +1 -1
  140. package/types/src/extensions/TableHandles/{TableHandlesPlugin.d.ts → TableHandles.d.ts} +28 -31
  141. package/types/src/extensions/TrailingNode/TrailingNode.d.ts +8 -0
  142. package/types/src/extensions/index.d.ts +24 -0
  143. package/types/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.d.ts +1 -1
  144. package/types/src/extensions/tiptap-extensions/index.d.ts +11 -0
  145. package/types/src/index.d.ts +1 -13
  146. package/types/src/schema/blocks/createSpec.d.ts +4 -4
  147. package/types/src/schema/blocks/internal.d.ts +2 -2
  148. package/types/src/schema/blocks/types.d.ts +5 -5
  149. package/types/src/util/topo-sort.d.ts +8 -0
  150. package/dist/BlockNoteSchema-Bi-eeHal.js.map +0 -1
  151. package/dist/BlockNoteSchema-DjDaA2C3.cjs +0 -6
  152. package/dist/BlockNoteSchema-DjDaA2C3.cjs.map +0 -1
  153. package/dist/blockToNode-DIfPWLH8.js.map +0 -1
  154. package/src/comments/models/User.ts +0 -8
  155. package/src/editor/BlockNoteExtensions.ts +0 -325
  156. package/src/editor/managers/CollaborationManager.ts +0 -212
  157. package/src/editor/managers/ExtensionManager.ts +0 -130
  158. package/src/extensions/Collaboration/CursorPlugin.ts +0 -189
  159. package/src/extensions/Collaboration/ForkYDocPlugin.ts +0 -192
  160. package/src/extensions/Collaboration/SyncPlugin.ts +0 -18
  161. package/src/extensions/Collaboration/UndoPlugin.ts +0 -18
  162. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +0 -59
  163. package/src/extensions/Comments/CommentsPlugin.ts +0 -392
  164. package/src/extensions/FilePanel/FilePanelPlugin.ts +0 -206
  165. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +0 -363
  166. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +0 -380
  167. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +0 -75
  168. package/src/extensions/Placeholder/PlaceholderPlugin.ts +0 -147
  169. package/types/src/comments/models/User.d.ts +0 -8
  170. package/types/src/editor/BlockNoteExtensions.d.ts +0 -43
  171. package/types/src/editor/managers/CollaborationManager.d.ts +0 -115
  172. package/types/src/editor/managers/ExtensionManager.d.ts +0 -68
  173. package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +0 -15
  174. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +0 -37
  175. package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +0 -41
  176. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +0 -7
  177. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +0 -9
  178. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +0 -7
  179. package/types/src/extensions/Comments/CommentsPlugin.d.ts +0 -66
  180. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +0 -31
  181. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +0 -41
  182. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +0 -42
  183. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +0 -5
  184. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +0 -6
  185. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +0 -15
  186. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +0 -31
  187. package/types/src/extensions/TrailingNode/TrailingNodeExtension.d.ts +0 -13
  188. /package/src/{extensions/Comments/CommentMark.ts → comments/mark.ts} +0 -0
  189. /package/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.ts +0 -0
  190. /package/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.ts +0 -0
  191. /package/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.ts +0 -0
  192. /package/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.ts +0 -0
  193. /package/types/src/{extensions/Comments/CommentMark.d.ts → comments/mark.d.ts} +0 -0
  194. /package/types/src/{extensions/Collaboration/ForkYDocPlugin.test.d.ts → editor/BlockNoteExtension.test.d.ts} +0 -0
  195. /package/types/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.d.ts +0 -0
  196. /package/types/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.d.ts +0 -0
  197. /package/types/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.d.ts +0 -0
  198. /package/types/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.d.ts +0 -0
  199. /package/types/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.d.ts +0 -0
  200. /package/types/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.d.ts +0 -0
@@ -1,5 +1,5 @@
1
- "use strict";var Ut=Object.create;var ce=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var Ft=Object.getOwnPropertyNames;var Vt=Object.getPrototypeOf,$t=Object.prototype.hasOwnProperty;var zt=(n,t,e)=>t in n?ce(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Kt=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ft(t))!$t.call(n,r)&&r!==e&&ce(n,r,{get:()=>t[r],enumerable:!(o=Rt(t,r))||o.enumerable});return n};var Ee=(n,t,e)=>(e=n!=null?Ut(Vt(n)):{},Kt(t||!n||!n.__esModule?ce(e,"default",{value:n,enumerable:!0}):e,n));var u=(n,t,e)=>zt(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("prosemirror-model"),W=require("prosemirror-transform"),m=require("./blockToNode-w7H99R6p.cjs"),d=require("./BlockNoteSchema-DjDaA2C3.cjs"),B=require("@tiptap/core"),qt=require("fast-deep-equal"),Gt=require("prosemirror-dropcursor"),jt=require("yjs"),Wt=require("@tiptap/extension-gapcursor"),Yt=require("@tiptap/extension-history"),Xt=require("@tiptap/extension-link"),Jt=require("@tiptap/extension-text"),S=require("prosemirror-state"),N=require("prosemirror-tables"),Qt=require("rehype-parse"),Zt=require("rehype-remark"),eo=require("remark-gfm"),to=require("remark-stringify"),Ve=require("unified"),oo=require("hast-util-from-dom"),no=require("unist-util-visit"),E=require("y-prosemirror"),M=require("prosemirror-view"),ro=require("uuid"),so=require("./en-Cl87Uuyf.cjs"),io=require("remark-parse"),de=require("remark-rehype"),ao=require("rehype-stringify"),Me=require("prosemirror-history"),R=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function co(n){if(n&&typeof n=="object"&&"default"in n)return n;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const lo=R(qt),H=co(jt),uo=R(Qt),ho=R(Zt),$e=R(eo),po=R(to),mo=R(io),fo=R(de),go=R(ao);function ze(n,t){const e=[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:o=>{const r=o;return r.matches("[data-editable]")?r:r.querySelector("[data-editable]")||r}}];return t&&e.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const r=t==null?void 0:t(o);return r===void 0?!1:r}}),e}function ko(n,t){var o;const e=B.Node.create({name:n.type,inline:!0,group:"inline",draggable:(o=t.meta)==null?void 0:o.draggable,selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return d.propsToAttributes(n.propSchema)},addKeyboardShortcuts(){return d.addInlineContentKeyboardShortcuts(n)},parseHTML(){return ze(n,t.parse)},renderHTML({node:r}){const s=this.options.editor,i=t.render.call({renderType:"dom",props:void 0},m.nodeToCustomInlineContent(r,s.schema.inlineContentSchema,s.schema.styleSchema),()=>{},s);return d.addInlineContentAttributes(i,n.type,r.attrs,n.propSchema)},addNodeView(){return r=>{const{node:s,getPos:i}=r,c=this.options.editor,a=t.render.call({renderType:"nodeView",props:r},m.nodeToCustomInlineContent(s,c.schema.inlineContentSchema,c.schema.styleSchema),l=>{const h=m.inlineContentToNodes([l],c.pmSchema),p=i();p&&c.transact(k=>k.replaceWith(p,p+s.nodeSize,h))},c);return d.addInlineContentAttributes(a,n.type,s.attrs,n.propSchema)}}});return d.createInlineContentSpecFromTipTapNode(e,n.propSchema,{...t,toExternalHTML:t.toExternalHTML,render(r,s,i){const c=t.render(r,s,i);return d.addInlineContentAttributes(c,n.type,r.props,n.propSchema)}})}function Ke(n,t,e,o="before"){const r=typeof e=="string"?e:e.id,s=m.getPmSchema(n),i=t.map(h=>m.blockToNode(h,s)),c=d.getNodeById(r,n.doc);if(!c)throw new Error(`Block with ID ${r} not found`);let a=c.posBeforeNode;return o==="after"&&(a+=c.node.nodeSize),n.step(new W.ReplaceStep(a,a,new T.Slice(T.Fragment.from(i),0,0))),i.map(h=>m.nodeToBlock(h,s))}function te(n){if(!n||n.type.name!=="column")throw new Error("Invalid columnPos: does not point to column node.");const t=n.firstChild;if(!t)throw new Error("Invalid column: does not have child node.");const e=t.firstChild;if(!e)throw new Error("Invalid blockContainer: does not have child node.");return n.childCount===1&&t.childCount===1&&e.type.name==="paragraph"&&e.content.content.length===0}function qe(n,t){const e=n.doc.resolve(t),o=e.nodeAfter;if(!o||o.type.name!=="columnList")throw new Error("Invalid columnListPos: does not point to columnList node.");for(let r=o.childCount-1;r>=0;r--){const s=n.doc.resolve(e.pos+1).posAtIndex(r),c=n.doc.resolve(s).nodeAfter;if(!c||c.type.name!=="column")throw new Error("Invalid columnPos: does not point to column node.");te(c)&&n.delete(s,s+c.nodeSize)}}function oe(n,t){qe(n,t);const o=n.doc.resolve(t).nodeAfter;if(!o||o.type.name!=="columnList")throw new Error("Invalid columnListPos: does not point to columnList node.");if(o.childCount>2)return;if(o.childCount<2)throw new Error("Invalid columnList: contains fewer than two children.");const r=t+1,i=n.doc.resolve(r).nodeAfter,c=t+o.nodeSize-1,l=n.doc.resolve(c).nodeBefore;if(!i||!l)throw new Error("Invalid columnList: does not contain children.");const h=te(i),p=te(l);if(h&&p){n.delete(t,t+o.nodeSize);return}if(h){n.step(new W.ReplaceAroundStep(t,t+o.nodeSize,c-l.nodeSize+1,c-1,T.Slice.empty,0,!1));return}if(p){n.step(new W.ReplaceAroundStep(t,t+o.nodeSize,r+1,r+i.nodeSize-1,T.Slice.empty,0,!1));return}}function ue(n,t,e){const o=m.getPmSchema(n),r=e.map(p=>m.blockToNode(p,o)),s=new Set(t.map(p=>typeof p=="string"?p:p.id)),i=[],c=new Set,a=typeof t[0]=="string"?t[0]:t[0].id;let l=0;if(n.doc.descendants((p,k)=>{if(s.size===0)return!1;if(!p.type.isInGroup("bnBlock")||!s.has(p.attrs.id))return!0;if(i.push(m.nodeToBlock(p,o)),s.delete(p.attrs.id),e.length>0&&p.attrs.id===a){const y=n.doc.nodeSize;n.insert(k,r);const w=n.doc.nodeSize;l+=y-w}const g=n.doc.nodeSize,b=n.doc.resolve(k-l);b.node().type.name==="column"?c.add(b.before(-1)):b.node().type.name==="columnList"&&c.add(b.before()),b.node().type.name==="blockGroup"&&b.node(b.depth-1).type.name!=="doc"&&b.node().childCount===1?n.delete(b.before(),b.after()):n.delete(k-l,k-l+p.nodeSize);const f=n.doc.nodeSize;return l+=g-f,!1}),s.size>0){const p=[...s].join(`
2
- `);throw Error("Blocks with the following IDs could not be found in the editor: "+p)}return c.forEach(p=>oe(n,p)),{insertedBlocks:r.map(p=>m.nodeToBlock(p,o)),removedBlocks:i}}function Ge(n){const t=Array.from(n.classList).filter(e=>!e.startsWith("bn-"))||[];t.length>0?n.className=t.join(" "):n.removeAttribute("class")}function je(n,t,e,o){var c;let r;if(t)if(typeof t=="string")r=m.inlineContentToNodes([t],n.pmSchema);else if(Array.isArray(t))r=m.inlineContentToNodes(t,n.pmSchema);else if(t.type==="tableContent")r=m.tableContentToNodes(t,n.pmSchema);else throw new m.UnreachableCaseError(t.type);else throw new Error("blockContent is required");const i=((o==null?void 0:o.document)??document).createDocumentFragment();for(const a of r)if(a.type.name!=="text"&&n.schema.inlineContentSchema[a.type.name]){const l=n.schema.inlineContentSpecs[a.type.name].implementation;if(l){const h=m.nodeToCustomInlineContent(a,n.schema.inlineContentSchema,n.schema.styleSchema),p=l.toExternalHTML?l.toExternalHTML(h,n):l.render.call({renderType:"dom",props:void 0},h,()=>{},n);if(p){if(i.appendChild(p.dom),p.contentDOM){const k=e.serializeFragment(a.content,o);p.contentDOM.dataset.editable="",p.contentDOM.appendChild(k)}continue}}}else if(a.type.name==="text"){let l=document.createTextNode(a.textContent);for(const h of a.marks.toReversed())if(h.type.name in n.schema.styleSpecs){const p=(n.schema.styleSpecs[h.type.name].implementation.toExternalHTML??n.schema.styleSpecs[h.type.name].implementation.render)(h.attrs.stringValue,n);p.contentDOM.appendChild(l),l=p.dom}else{const p=h.type.spec.toDOM(h,!0),k=T.DOMSerializer.renderSpec(document,p);k.contentDOM.appendChild(l),l=k.dom}i.appendChild(l)}else{const l=e.serializeFragment(T.Fragment.from([a]),o);i.appendChild(l)}return i.childNodes.length===1&&((c=i.firstChild)==null?void 0:c.nodeType)===1&&Ge(i.firstChild),i}function bo(n,t,e,o,r,s,i){var y,w,C,_,U,K,q,G,j;const c=(i==null?void 0:i.document)??document,a=t.pmSchema.nodes.blockContainer,l=e.props||{};for(const[x,I]of Object.entries(t.schema.blockSchema[e.type].propSchema))!(x in l)&&I.default!==void 0&&(l[x]=I.default);const h=(w=(y=a.spec)==null?void 0:y.toDOM)==null?void 0:w.call(y,a.create({id:e.id,...l})),p=Array.from(h.dom.attributes),k=t.blockImplementations[e.type].implementation,g=((C=k.toExternalHTML)==null?void 0:C.call({},{...e,props:l},t))||k.render.call({},{...e,props:l},t),b=c.createDocumentFragment();if(g.dom.classList.contains("bn-block-content")){const x=[...p,...Array.from(g.dom.attributes)].filter(I=>I.name.startsWith("data")&&I.name!=="data-content-type"&&I.name!=="data-file-block"&&I.name!=="data-node-view-wrapper"&&I.name!=="data-node-type"&&I.name!=="data-id"&&I.name!=="data-editable");for(const I of x)g.dom.firstChild.setAttribute(I.name,I.value);Ge(g.dom.firstChild),b.append(...Array.from(g.dom.childNodes))}else b.append(g.dom);if(g.contentDOM&&e.content){const x=je(t,e.content,o,i);g.contentDOM.appendChild(x)}let f;if(r.has(e.type)?f="OL":s.has(e.type)&&(f="UL"),f){if(((_=n.lastChild)==null?void 0:_.nodeName)!==f){const x=c.createElement(f);f==="OL"&&"start"in l&&l.start&&(l==null?void 0:l.start)!==1&&x.setAttribute("start",l.start+""),n.append(x)}n.lastChild.appendChild(b)}else n.append(b);if(e.children&&e.children.length>0){const x=c.createDocumentFragment();if(We(x,t,e.children,o,r,s,i),((U=n.lastChild)==null?void 0:U.nodeName)==="UL"||((K=n.lastChild)==null?void 0:K.nodeName)==="OL")for(;((q=x.firstChild)==null?void 0:q.nodeName)==="UL"||((G=x.firstChild)==null?void 0:G.nodeName)==="OL";)n.lastChild.lastChild.appendChild(x.firstChild);t.pmSchema.nodes[e.type].isInGroup("blockContent")?n.append(x):(j=g.contentDOM)==null||j.append(x)}}const We=(n,t,e,o,r,s,i)=>{for(const c of e)bo(n,t,c,o,r,s,i)},yo=(n,t,e,o,r,s)=>{const c=((s==null?void 0:s.document)??document).createDocumentFragment();return We(c,n,t,e,o,r,s),c},X=(n,t)=>{const e=T.DOMSerializer.fromSchema(n);return{exportBlocks:(o,r)=>{const s=yo(t,o,e,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem","toggleListItem"]),r),i=document.createElement("div");return i.append(s),i.innerHTML},exportInlineContent:(o,r)=>{const s=je(t,o,e,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function wo(n,t,e,o,r){let s;if(t)if(typeof t=="string")s=m.inlineContentToNodes([t],n.pmSchema,o);else if(Array.isArray(t))s=m.inlineContentToNodes(t,n.pmSchema,o);else if(t.type==="tableContent")s=m.tableContentToNodes(t,n.pmSchema);else throw new m.UnreachableCaseError(t.type);else throw new Error("blockContent is required");const c=((r==null?void 0:r.document)??document).createDocumentFragment();for(const a of s)if(a.type.name!=="text"&&n.schema.inlineContentSchema[a.type.name]){const l=n.schema.inlineContentSpecs[a.type.name].implementation;if(l){const h=m.nodeToCustomInlineContent(a,n.schema.inlineContentSchema,n.schema.styleSchema),p=l.render.call({renderType:"dom",props:void 0},h,()=>{},n);if(p){if(c.appendChild(p.dom),p.contentDOM){const k=e.serializeFragment(a.content,r);p.contentDOM.dataset.editable="",p.contentDOM.appendChild(k)}continue}}}else if(a.type.name==="text"){let l=document.createTextNode(a.textContent);for(const h of a.marks.toReversed())if(h.type.name in n.schema.styleSpecs){const p=n.schema.styleSpecs[h.type.name].implementation.render(h.attrs.stringValue,n);p.contentDOM.appendChild(l),l=p.dom}else{const p=h.type.spec.toDOM(h,!0),k=T.DOMSerializer.renderSpec(document,p);k.contentDOM.appendChild(l),l=k.dom}c.appendChild(l)}else{const l=e.serializeFragment(T.Fragment.from([a]),r);c.appendChild(l)}return c}function So(n,t,e,o){var p,k,g,b,f;const r=n.pmSchema.nodes.blockContainer,s=t.props||{};for(const[y,w]of Object.entries(n.schema.blockSchema[t.type].propSchema))!(y in s)&&w.default!==void 0&&(s[y]=w.default);const i=t.children||[],a=n.blockImplementations[t.type].implementation.render.call({renderType:"dom",props:void 0},{...t,props:s,children:i},n);if(a.contentDOM&&t.content){const y=wo(n,t.content,e,t.type,o);a.contentDOM.appendChild(y)}if(n.pmSchema.nodes[t.type].isInGroup("bnBlock")){if(t.children&&t.children.length>0){const y=Ye(n,t.children,e,o);(p=a.contentDOM)==null||p.append(y)}return a.dom}const h=(g=(k=r.spec)==null?void 0:k.toDOM)==null?void 0:g.call(k,r.create({id:t.id,...s}));return(b=h.contentDOM)==null||b.appendChild(a.dom),t.children&&t.children.length>0&&((f=h.contentDOM)==null||f.appendChild(Xe(n,t.children,e,o))),h.dom}function Ye(n,t,e,o){const s=((o==null?void 0:o.document)??document).createDocumentFragment();for(const i of t){const c=So(n,i,e,o);s.appendChild(c)}return s}const Xe=(n,t,e,o)=>{var c;const r=n.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=Ye(n,t,e,o);return(c=s.contentDOM)==null||c.appendChild(i),s.dom},Je=(n,t)=>{const e=T.DOMSerializer.fromSchema(n);return{serializeBlocks:(o,r)=>Xe(t,o,e,r).outerHTML}};function Co(n,t){if(t===0)return;const e=n.resolve(t);for(let o=e.depth;o>0;o--){const r=e.node(o);if(d.isNodeBlock(r))return r.attrs.id}}function Bo(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 xe(n){const t="__root__",e={},o={},r=m.getPmSchema(n);return n.descendants((s,i)=>{if(!d.isNodeBlock(s))return!0;const c=Co(n,i),a=c??t;o[a]||(o[a]=[]);const l=m.nodeToBlock(s,r);return e[s.attrs.id]={block:l,parentId:c},o[a].push(s.attrs.id),!0}),{byId:e,childrenByParent:o}}function vo(n,t){const e=new Set;if(!n||!t)return e;const o=new Set(n),r=t.filter(f=>o.has(f)),s=n.filter(f=>r.includes(f));if(s.length<=1||r.length<=1)return e;const i={};for(let f=0;f<s.length;f++)i[s[f]]=f;const c=r.map(f=>i[f]),a=c.length,l=[],h=[],p=new Array(a).fill(-1),k=(f,y)=>{let w=0,C=f.length;for(;w<C;){const _=w+C>>>1;f[_]<y?w=_+1:C=_}return w};for(let f=0;f<a;f++){const y=c[f],w=k(l,y);w>0&&(p[f]=h[w-1]),w===l.length?(l.push(y),h.push(f)):(l[w]=y,h[w]=f)}const g=new Set;let b=h[h.length-1]??-1;for(;b!==-1;)g.add(b),b=p[b];for(let f=0;f<r.length;f++)g.has(f)||e.add(r[f]);return e}function fe(n,t=[]){const e=Bo(n),o=B.combineTransactionSteps(n.before,[n,...t]),r=xe(o.before),s=xe(o.doc),i=[],c=new Set;Object.keys(s.byId).filter(g=>!(g in r.byId)).forEach(g=>{i.push({type:"insert",block:s.byId[g].block,source:e,prevBlock:void 0}),c.add(g)}),Object.keys(r.byId).filter(g=>!(g in s.byId)).forEach(g=>{i.push({type:"delete",block:r.byId[g].block,source:e,prevBlock:void 0}),c.add(g)}),Object.keys(s.byId).filter(g=>g in r.byId).forEach(g=>{var w,C;const b=r.byId[g],f=s.byId[g];b.parentId!==f.parentId?(i.push({type:"move",block:f.block,prevBlock:b.block,source:e,prevParent:b.parentId?(w=r.byId[b.parentId])==null?void 0:w.block:void 0,currentParent:f.parentId?(C=s.byId[f.parentId])==null?void 0:C.block:void 0}),c.add(g)):lo.default({...b.block,children:void 0},{...f.block,children:void 0})||(i.push({type:"update",block:f.block,prevBlock:b.block,source:e}),c.add(g))});const a=r.childrenByParent,l=s.childrenByParent,h="__root__",p=new Set([...Object.keys(a),...Object.keys(l)]),k=new Set;return p.forEach(g=>{const b=vo(a[g],l[g]);b.size!==0&&b.forEach(f=>{var _,U;const y=r.byId[f],w=s.byId[f];!y||!w||y.parentId!==w.parentId||c.has(f)||(y.parentId??h)!==g||k.has(f)||(k.add(f),i.push({type:"move",block:w.block,prevBlock:y.block,source:e,prevParent:y.parentId?(_=r.byId[y.parentId])==null?void 0:_.block:void 0,currentParent:w.parentId?(U=s.byId[w.parentId])==null?void 0:U.block:void 0}),c.add(f))})}),i}const ge=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function Po(n,t){if(!n.startsWith(".")||!t.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return n===t}function To(n,t){const e=n.split("/"),o=t.split("/");if(e.length!==2)throw new Error(`The string ${n} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${t} is not a valid MIME type.`);return e[1]==="*"||o[1]==="*"?e[0]===o[0]:(e[0]==="*"||o[0]==="*"||e[0]===o[0])&&e[1]===o[1]}function Ie(n,t,e,o="after"){let r;return Array.isArray(t.content)&&t.content.length===0?r=n.updateBlock(t,e).id:r=n.insertBlocks([e],t,o)[0].id,r}async function Qe(n,t){var s;if(!t.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const e="dataTransfer"in n?n.dataTransfer:n.clipboardData;if(e===null)return;let o=null;for(const i of ge)if(e.types.includes(i)){o=i;break}if(o!=="Files")return;const r=e.items;if(r){n.preventDefault();for(let i=0;i<r.length;i++){let c="file";for(const l of Object.values(t.schema.blockSpecs))for(const h of((s=l.implementation.meta)==null?void 0:s.fileBlockAccept)||[]){const p=h.startsWith("."),k=r[i].getAsFile();if(k&&(!p&&k.type&&To(r[i].type,h)||p&&Po("."+k.name.split(".").pop(),h))){c=l.config.type;break}}const a=r[i].getAsFile();if(a){const l={type:c,props:{name:a.name}};let h;if(n.type==="paste"){const g=t.getTextCursorPosition().block;h=Ie(t,g,l)}else if(n.type==="drop"){const g={left:n.clientX,top:n.clientY},b=t.prosemirrorView.posAtCoords(g);if(!b)return;h=t.transact(f=>{const y=m.getNearestBlockPos(f.doc,b.pos),w=t.prosemirrorView.dom.querySelector(`[data-id="${y.node.attrs.id}"]`),C=w==null?void 0:w.getBoundingClientRect();return Ie(t,t.getBlock(y.node.attrs.id),l,C&&(C.top+C.bottom)/2>g.top?"before":"after")})}else return;const p=await t.uploadFile(a,h),k=typeof p=="string"?{props:{url:p}}:{...p};t.updateBlock(h,k)}}}}const Eo=n=>B.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new S.Plugin({props:{handleDOMEvents:{drop(t,e){if(!n.isEditable)return;let o=null;for(const r of ge)if(e.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(Qe(e,n),!0):!1}}}})]}}),Mo=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,xo=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,Io=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,Do=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,Lo=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,No=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,Ao=/\n{2} {0,3}-{2,48}\n{2}/,_o=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,Oo=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,Ho=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,Uo=/^\s*\|(.+\|)+\s*$/m,Ro=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,Fo=/^\s*\|(.+\|)+\s*$/m,Vo=n=>Mo.test(n)||xo.test(n)||Io.test(n)||Do.test(n)||Lo.test(n)||No.test(n)||Ao.test(n)||_o.test(n)||Oo.test(n)||Ho.test(n)||Uo.test(n)||Ro.test(n)||Fo.test(n);async function $o(n,t){const{schema:e}=t.state;if(!n.clipboardData)return!1;const o=n.clipboardData.getData("text/plain");if(!o)return!1;if(!e.nodes.codeBlock)return t.pasteText(o),!0;const r=n.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;return i?(t.pasteHTML(`<pre><code class="language-${i}">${o.replace(/\r\n?/g,`
3
- `)}</code></pre>`),!0):!1}function zo({event:n,editor:t,prioritizeMarkdownOverHTML:e,plainTextAsMarkdown:o}){var c;if(t.transact(a=>a.selection.$from.parent.type.spec.code&&a.selection.$to.parent.type.spec.code)){const a=(c=n.clipboardData)==null?void 0:c.getData("text/plain");if(a)return t.pasteText(a),!0}let s;for(const a of ge)if(n.clipboardData.types.includes(a)){s=a;break}if(!s)return!0;if(s==="vscode-editor-data")return $o(n,t.prosemirrorView),!0;if(s==="Files")return Qe(n,t),!0;const i=n.clipboardData.getData(s);if(s==="blocknote/html")return t.pasteHTML(i,!0),!0;if(s==="text/markdown")return t.pasteMarkdown(i),!0;if(e){const a=n.clipboardData.getData("text/plain");if(Vo(a))return t.pasteMarkdown(a),!0}return s==="text/html"?(t.pasteHTML(i),!0):o?(t.pasteMarkdown(i),!0):(t.pasteText(i),!0)}const Ko=(n,t)=>B.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new S.Plugin({props:{handleDOMEvents:{paste(e,o){if(o.preventDefault(),!!n.isEditable)return t({event:o,editor:n,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>zo({event:o,editor:n,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function qo(){const n=t=>{let e=t.children.length;for(let o=0;o<e;o++){const r=t.children[o];if(r.type==="element"&&(n(r),r.tagName==="u"))if(r.children.length>0){t.children.splice(o,1,...r.children);const s=r.children.length-1;e+=s,o+=s}else t.children.splice(o,1),e--,o--}};return n}function Go(){const n=t=>{var e;if(t.children&&"length"in t.children&&t.children.length)for(let o=t.children.length-1;o>=0;o--){const r=t.children[o],s=o+1<t.children.length?t.children[o+1]:void 0;r.type==="element"&&r.tagName==="input"&&((e=r.properties)==null?void 0:e.type)==="checkbox"&&(s==null?void 0:s.type)==="element"&&s.tagName==="p"?(s.tagName="span",s.children.splice(0,0,oo.fromDom(document.createTextNode(" ")))):n(r)}};return n}function jo(){return n=>{no.visit(n,"element",(t,e,o)=>{var r,s,i,c;if(o&&t.tagName==="video"){const a=((r=t.properties)==null?void 0:r.src)||((s=t.properties)==null?void 0:s["data-url"])||"",l=((i=t.properties)==null?void 0:i.title)||((c=t.properties)==null?void 0:c["data-name"])||"";o.children[e]={type:"text",value:`![${l}](${a})`}}})}}function ie(n){return Ve.unified().use(uo.default,{fragment:!0}).use(jo).use(qo).use(Go).use(ho.default).use($e.default).use(po.default,{handlers:{text:e=>e.value}}).processSync(n).value}function Ze(n,t,e,o){const s=X(t,e).exportBlocks(n,o);return ie(s)}function et(n){const t=[];return n.descendants(e=>{var r,s;const o=m.getPmSchema(e);return e.type.name==="blockContainer"&&((r=e.firstChild)==null?void 0:r.type.name)==="blockGroup"?!0:e.type.name==="columnList"&&e.childCount===1?((s=e.firstChild)==null||s.forEach(i=>{t.push(m.nodeToBlock(i,o))}),!1):e.type.isInGroup("bnBlock")?(t.push(m.nodeToBlock(e,o)),!1):!0}),t}function Wo(n,t,e){var c;let o=!1;const r=n.state.selection instanceof N.CellSelection;if(!r){const a=n.state.doc.slice(n.state.selection.from,n.state.selection.to,!1).content,l=[];for(let h=0;h<a.childCount;h++)l.push(a.child(h));o=l.find(h=>h.type.isInGroup("bnBlock")||h.type.name==="blockGroup"||h.type.spec.group==="blockContent")===void 0,o&&(t=a)}let s;const i=X(n.state.schema,e);if(r){((c=t.firstChild)==null?void 0:c.type.name)==="table"&&(t=t.firstChild.content);const a=m.contentNodeToTableContent(t,e.schema.inlineContentSchema,e.schema.styleSchema);s=`<table>${i.exportInlineContent(a,{})}</table>`}else if(o){const a=m.contentNodeToInlineContent(t,e.schema.inlineContentSchema,e.schema.styleSchema);s=i.exportInlineContent(a,{})}else{const a=et(t);s=i.exportBlocks(a,{})}return s}function ke(n,t){"node"in n.state.selection&&n.state.selection.node.type.spec.group==="blockContent"&&t.transact(i=>i.setSelection(new S.NodeSelection(i.doc.resolve(n.state.selection.from-1))));const e=n.serializeForClipboard(n.state.selection.content()).dom.innerHTML,o=n.state.selection.content().content,r=Wo(n,o,t),s=ie(r);return{clipboardHTML:e,externalHTML:r,markdown:s}}const De=()=>{const n=window.getSelection();if(!n||n.isCollapsed)return!0;let t=n.focusNode;for(;t;){if(t instanceof HTMLElement&&t.getAttribute("contenteditable")==="false")return!0;t=t.parentElement}return!1},Le=(n,t,e)=>{e.preventDefault(),e.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=ke(t,n);e.clipboardData.setData("blocknote/html",o),e.clipboardData.setData("text/html",r),e.clipboardData.setData("text/plain",s)},Yo=n=>B.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new S.Plugin({props:{handleDOMEvents:{copy(t,e){return De()||Le(n,t,e),!0},cut(t,e){return De()||(Le(n,t,e),t.editable&&t.dispatch(t.state.tr.deleteSelection())),!0},dragstart(t,e){if(!("node"in t.state.selection)||t.state.selection.node.type.spec.group!=="blockContent")return;n.transact(i=>i.setSelection(new S.NodeSelection(i.doc.resolve(t.state.selection.from-1)))),e.preventDefault(),e.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=ke(t,n);return e.dataTransfer.setData("blocknote/html",o),e.dataTransfer.setData("text/html",r),e.dataTransfer.setData("text/plain",s),!0}}}})]}}),Xo=B.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{backgroundColor:d.getBackgroundColorAttribute()}}]}});class Jo extends d.BlockNoteExtension{constructor(){super();u(this,"beforeChangeCallbacks",[]);this.addProsemirrorPlugin(new S.Plugin({key:new S.PluginKey("blockChange"),filterTransaction:e=>{let o;return this.beforeChangeCallbacks.reduce((r,s)=>r===!1?r:s({getChanges(){return o||(o=fe(e),o)},tr:e})!==!1,!0)}}))}static key(){return"blockChange"}subscribe(e){return this.beforeChangeCallbacks.push(e),()=>{this.beforeChangeCallbacks=this.beforeChangeCallbacks.filter(o=>o!==e)}}}const $=class $ extends d.BlockNoteExtension{constructor(e){super();u(this,"provider");u(this,"recentlyUpdatedCursors");u(this,"renderCursor",(e,o)=>{let r=this.recentlyUpdatedCursors.get(o);if(!r){const s=(this.collaboration.renderCursor??$.defaultCursorRender)(e);this.collaboration.showCursorLabels!=="always"&&(s.addEventListener("mouseenter",()=>{const i=this.recentlyUpdatedCursors.get(o);i.element.setAttribute("data-active",""),i.hideTimeout&&(clearTimeout(i.hideTimeout),this.recentlyUpdatedCursors.set(o,{element:i.element,hideTimeout:void 0}))}),s.addEventListener("mouseleave",()=>{const i=this.recentlyUpdatedCursors.get(o);this.recentlyUpdatedCursors.set(o,{element:i.element,hideTimeout:setTimeout(()=>{i.element.removeAttribute("data-active")},2e3)})})),r={element:s,hideTimeout:void 0},this.recentlyUpdatedCursors.set(o,r)}return r.element});u(this,"updateUser",e=>{this.provider.awareness.setLocalStateField("user",e)});this.collaboration=e,this.provider=e.provider,this.recentlyUpdatedCursors=new Map,this.provider.awareness.setLocalStateField("user",e.user),e.showCursorLabels!=="always"&&this.provider.awareness.on("change",({updated:o})=>{for(const r of o){const s=this.recentlyUpdatedCursors.get(r);s&&(s.element.setAttribute("data-active",""),s.hideTimeout&&clearTimeout(s.hideTimeout),this.recentlyUpdatedCursors.set(r,{element:s.element,hideTimeout:setTimeout(()=>{s.element.removeAttribute("data-active")},2e3)}))}}),this.addProsemirrorPlugin(E.yCursorPlugin(this.provider.awareness,{selectionBuilder:E.defaultSelectionBuilder,cursorBuilder:this.renderCursor}))}static key(){return"yCursorPlugin"}get priority(){return 999}static isDarkColor(e){const o=e.charAt(0)==="#"?e.substring(1,7):e,r=parseInt(o.substring(0,2),16),s=parseInt(o.substring(2,4),16),i=parseInt(o.substring(4,6),16),a=[r/255,s/255,i/255].map(h=>h<=.03928?h/12.92:Math.pow((h+.055)/1.055,2.4));return .2126*a[0]+.7152*a[1]+.0722*a[2]<=.179}};u($,"defaultCursorRender",e=>{const o=document.createElement("span");o.classList.add("bn-collaboration-cursor__base");const r=document.createElement("span");r.setAttribute("contentedEditable","false"),r.classList.add("bn-collaboration-cursor__caret"),r.setAttribute("style",`background-color: ${e.color}; color: ${$.isDarkColor(e.color)?"white":"black"}`);const s=document.createElement("span");return s.classList.add("bn-collaboration-cursor__label"),s.setAttribute("style",`background-color: ${e.color}; color: ${$.isDarkColor(e.color)?"white":"black"}`),s.insertBefore(document.createTextNode(e.name),null),r.insertBefore(s,null),o.insertBefore(document.createTextNode("⁠"),null),o.insertBefore(r,null),o.insertBefore(document.createTextNode("⁠"),null),o});let Y=$;class ne extends d.BlockNoteExtension{static key(){return"ySyncPlugin"}constructor(t){super(),this.addProsemirrorPlugin(E.ySyncPlugin(t))}get priority(){return 1001}}class re extends d.BlockNoteExtension{static key(){return"yUndoPlugin"}constructor({editor:t}){super(),this.addProsemirrorPlugin(E.yUndoPlugin({trackedOrigins:[t]}))}get priority(){return 1e3}}class tt extends d.BlockNoteExtension{constructor({editor:e,collaboration:o}){super(e);u(this,"editor");u(this,"collaboration");u(this,"forkedState");this.editor=e,this.collaboration=o}static key(){return"ForkYDocPlugin"}findTypeInOtherYdoc(e,o){const r=e.doc;if(e._item===null){const s=Array.from(r.share.keys()).find(i=>r.share.get(i)===e);if(s==null)throw new Error("type does not exist in other ydoc");return o.get(s,e.constructor)}else{const s=e._item,i=o.store.clients.get(s.id.client)??[],c=H.findIndexSS(i,s.id.clock);return i[c].content.type}}get isForkedFromRemote(){return this.forkedState!==void 0}fork(){var s;if(this.isForkedFromRemote)return;const e=(s=this.collaboration)==null?void 0:s.fragment;if(!e)throw new Error("No fragment to fork from");const o=new H.Doc;H.applyUpdate(o,H.encodeStateAsUpdate(e.doc));const r=this.findTypeInOtherYdoc(e,o);this.forkedState={undoStack:E.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack,originalFragment:e,forkedFragment:r},this.editor._tiptapEditor.unregisterPlugin([E.yCursorPluginKey,E.yUndoPluginKey,E.ySyncPluginKey]),this.editor._tiptapEditor.registerPlugin(new ne(r).plugins[0]),this.editor._tiptapEditor.registerPlugin(new re({editor:this.editor}).plugins[0]),this.emit("forked",!0)}merge({keepChanges:e}){if(!this.forkedState)return;this.editor._tiptapEditor.unregisterPlugin(E.ySyncPluginKey),this.editor._tiptapEditor.unregisterPlugin(E.yUndoPluginKey);const{originalFragment:o,forkedFragment:r,undoStack:s}=this.forkedState;if(this.editor.extensions.ySyncPlugin=new ne(o),this.editor.extensions.yCursorPlugin=new Y(this.collaboration),this.editor.extensions.yUndoPlugin=new re({editor:this.editor}),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.ySyncPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yCursorPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yUndoPlugin.plugins[0]),E.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack=s,e){const i=H.encodeStateAsUpdate(r.doc,H.encodeStateVector(o.doc));H.applyUpdate(o.doc,i,this.editor)}this.forkedState=void 0,this.emit("forked",!1)}}const ot=(n,t)=>{t(n),n.forEach(e=>{e instanceof H.XmlElement&&ot(e,t)})},Qo=(n,t)=>{const e=new Map;return n.forEach(o=>{o instanceof H.XmlElement&&ot(o,r=>{if(r.nodeName==="blockContainer"&&r.hasAttribute("id")){const s=r.getAttribute("textColor"),i=r.getAttribute("backgroundColor"),c={textColor:s===d.defaultProps.textColor.default?void 0:s,backgroundColor:i===d.defaultProps.backgroundColor.default?void 0:i};(c.textColor||c.backgroundColor)&&e.set(r.getAttribute("id"),c)}})}),e.size===0?!1:(t.doc.descendants((o,r)=>{if(o.type.name==="blockContainer"&&e.has(o.attrs.id)){const s=t.doc.nodeAt(r+1);if(!s)throw new Error("No element found");t.setNodeMarkup(r+1,void 0,{...s.attrs,...e.get(o.attrs.id)})}}),!0)},Zo=[Qo];class be extends d.BlockNoteExtension{constructor(e){const o=new S.PluginKey(be.key());super();u(this,"migrationDone",!1);this.addProsemirrorPlugin(new S.Plugin({key:o,appendTransaction:(r,s,i)=>{if(this.migrationDone||!r.some(a=>a.getMeta("y-sync$"))||r.every(a=>!a.docChanged)||!e.firstChild)return;const c=i.tr;for(const a of Zo)a(e,c);if(this.migrationDone=!0,!!c.docChanged)return c}}))}static key(){return"schemaMigrationPlugin"}}const se=B.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:n=>!!n.getAttribute("data-orphan"),renderHTML:n=>n.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:n=>n.getAttribute("data-bn-thread-id"),renderHTML:n=>({"data-bn-thread-id":n.threadId}),default:""}}},renderHTML({HTMLAttributes:n}){return["span",B.mergeAttributes(n,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(n){return n.name==="comment"?{blocknoteIgnore:!0}:{}}});class en extends d.EventEmitter{constructor(e){super();u(this,"userCache",new Map);u(this,"loadingUsers",new Set);this.resolveUsers=e}async loadUsers(e){const o=e.filter(r=>!this.userCache.has(r)&&!this.loadingUsers.has(r));if(o.length!==0){for(const r of o)this.loadingUsers.add(r);try{const r=await this.resolveUsers(o);for(const s of r)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const r of o)this.loadingUsers.delete(r)}}}getUser(e){return this.userCache.get(e)}subscribe(e){return this.on("update",e)}}const J=new S.PluginKey("blocknote-comments"),tn="SET_SELECTED_THREAD_ID";function on(n,t){const e=new Map;return n.descendants((o,r)=>{o.marks.forEach(s=>{if(s.type.name===t){const i=s.attrs.threadId;if(!i)return;const c=r,a=c+o.nodeSize,l=e.get(i)??{from:1/0,to:0};e.set(i,{from:Math.min(c,l.from),to:Math.max(a,l.to)})}})}),e}class nt extends d.BlockNoteExtension{constructor(e,o,r,s,i){super();u(this,"userStore");u(this,"pendingComment",!1);u(this,"selectedThreadId");u(this,"threadPositions",new Map);u(this,"updateMarksFromThreads",e=>{this.editor.transact(o=>{o.doc.descendants((r,s)=>{r.marks.forEach(i=>{if(i.type.name===this.markType){const c=i.type,a=i.attrs.threadId,l=e.get(a),h=!!(!l||l.resolved||l.deletedAt);if(h!==i.attrs.orphan){const p=Math.max(s,0),k=Math.min(s+r.nodeSize,o.doc.content.size-1,o.doc.content.size-1);o.removeMark(p,k,i),o.addMark(p,k,c.create({...i.attrs,orphan:h})),h&&this.selectedThreadId===a&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})});if(this.editor=e,this.threadStore=o,this.markType=r,this.resolveUsers=s,this.commentEditorSchema=i,!s)throw new Error("resolveUsers is required for comments");this.userStore=new en(s),this.threadStore.subscribe(this.updateMarksFromThreads),e.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),e.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const c=this;this.addProsemirrorPlugin(new S.Plugin({key:J,state:{init(){return{decorations:M.DecorationSet.empty}},apply(a,l){const h=a.getMeta(J);if(!a.docChanged&&!h)return l;const p=a.docChanged?on(a.doc,c.markType):c.threadPositions;(p.size>0||c.threadPositions.size>0)&&(c.threadPositions=p,c.emitStateUpdate());const k=[];if(c.selectedThreadId){const g=p.get(c.selectedThreadId);g&&k.push(M.Decoration.inline(g.from,g.to,{class:"bn-thread-mark-selected"}))}return{decorations:M.DecorationSet.create(a.doc,k)}}},props:{decorations(a){var l;return((l=J.getState(a))==null?void 0:l.decorations)??M.DecorationSet.empty},handleClick:(a,l,h)=>{var y;if(h.button!==0)return;const p=a.state.doc.nodeAt(l);if(!p){c.selectThread(void 0);return}const k=a.state.schema.marks[r],g=a.state.doc.resolve(l),b=(y=p.marks.filter(w=>w.type.name===r&&w.attrs.orphan!==!0).map(w=>{const C=B.getMarkRange(g,k,w.attrs);return{mark:w,distance:(Math.abs(C.from-l)+Math.abs(C.to-l))/2,length:C.to-C.from}}).sort((w,C)=>w.distance!==C.distance?w.distance-C.distance:w.length-C.length)[0])==null?void 0:y.mark,f=b==null?void 0:b.attrs.threadId;c.selectThread(f)}}}))}static key(){return"comments"}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(e){return this.on("update",e)}selectThread(e){var o,r;if(this.selectedThreadId!==e&&(this.selectedThreadId=e,this.emitStateUpdate(),this.editor.transact(s=>s.setMeta(J,{name:tn})),e)){const s=this.threadPositions.get(e);if(!s)return;(r=(o=this.editor.prosemirrorView)==null?void 0:o.domAtPos(s.from).node)==null||r.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(e){const o=await this.threadStore.createThread(e);if(this.threadStore.addThreadToDocument){const r=this.editor.prosemirrorView,s=r.state.selection,i=E.ySyncPluginKey.getState(r.state),c={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?E.getRelativeSelection(i.binding,r.state):void 0};await this.threadStore.addThreadToDocument({threadId:o.id,selection:c})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:o.id})}}class rt{constructor(t,e,o,r){u(this,"state");u(this,"emitUpdate");u(this,"mouseDownHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"dragstartHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!e)return;this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate()}});u(this,"closeMenu",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});this.editor=t,this.pluginKey=e,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");r(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(t,e){var c,a;const o=this.pluginKey.getState(t.state),r=this.pluginKey.getState(e);if(!((c=this.state)!=null&&c.show)&&(o!=null&&o.block)&&this.editor.isEditable){const l=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);if(!l)return;this.state={show:!0,referencePos:l.getBoundingClientRect(),block:o.block},this.emitUpdate();return}const s=(o==null?void 0:o.block)&&!(r!=null&&r.block),i=!(o!=null&&o.block)&&(r==null?void 0:r.block);s&&this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate()),i&&((a=this.state)!=null&&a.show)&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const le=new S.PluginKey("FilePanelPlugin");class st extends d.BlockNoteExtension{constructor(e){super();u(this,"view");u(this,"closeMenu",()=>{var e;return(e=this.view)==null?void 0:e.closeMenu()});this.addProsemirrorPlugin(new S.Plugin({key:le,view:o=>(this.view=new rt(e,le,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>{var s;return r.key==="Escape"&&this.shown?((s=this.view)==null||s.closeMenu(),!0):!1}},state:{init:()=>({block:void 0}),apply:(o,r)=>{const s=o.getMeta(le);return s||(!o.getMeta(E.ySyncPluginKey)&&(o.selectionSet||o.docChanged)?{block:void 0}:r)}}}))}static key(){return"filePanel"}get shown(){var e,o;return((o=(e=this.view)==null?void 0:e.state)==null?void 0:o.show)||!1}onUpdate(e){return this.on("update",e)}}class it{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"shouldShow",({view:t,state:e,from:o,to:r})=>{const{doc:s,selection:i}=e,{empty:c}=i,a=!s.textBetween(o,r).length&&B.isTextSelection(e.selection);if(i.$from.parent.type.spec.code||B.isNodeSelection(i)&&i.node.type.spec.code||c||a)return!1;const l=document.activeElement;return!(!this.isElementWithinEditorWrapper(l)&&t.editable)});u(this,"blurHandler",t=>{var o;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget)||t.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"isElementWithinEditorWrapper",t=>{if(!t)return!1;const e=this.pmView.dom.parentElement;return e?e.contains(t):!1});u(this,"viewMousedownHandler",t=>{(!this.isElementWithinEditorWrapper(t.target)||t.button===0)&&(this.preventShow=!0)});u(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))});u(this,"dragHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});u(this,"closeMenu",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.root.addEventListener("mouseup",this.mouseupHandler),e.dom.addEventListener("dragstart",this.dragHandler),e.dom.addEventListener("dragover",this.dragHandler),e.dom.addEventListener("blur",this.blurHandler),e.root.addEventListener("scroll",this.scrollHandler,!0)}update(t,e){var g,b,f;const{state:o,composing:r}=t,{doc:s,selection:i}=o,c=e&&e.doc.eq(s)&&e.selection.eq(i);if(r||c)return;const{ranges:a}=i,l=Math.min(...a.map(y=>y.$from.pos)),h=Math.max(...a.map(y=>y.$to.pos)),p=this.shouldShow({view:t,state:o,from:l,to:h}),k=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(p||this.preventHide)&&!k){const y=this.getSelectionBoundingBox();if(y.height===0&&y.width===0){queueMicrotask(()=>{const C={show:!0,referencePos:this.getSelectionBoundingBox()};this.state=C,this.emitUpdate(),t.dispatch(t.state.tr.setSelection(S.TextSelection.create(t.state.doc,t.state.selection.from+1,t.state.selection.to))),t.dispatch(t.state.tr.setSelection(S.TextSelection.create(t.state.doc,t.state.selection.from-1,t.state.selection.to)))});return}const w={show:!0,referencePos:this.getSelectionBoundingBox()};(w.show!==((g=this.state)==null?void 0:g.show)||w.referencePos.toJSON()!==((b=this.state)==null?void 0:b.referencePos.toJSON()))&&(this.state=w,this.emitUpdate());return}if((f=this.state)!=null&&f.show&&!this.preventHide&&(!p||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:e}=t,{ranges:o}=e,r=Math.min(...o.map(i=>i.$from.pos)),s=Math.max(...o.map(i=>i.$to.pos));if(B.isNodeSelection(e)){const i=this.pmView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return B.posToDOMRect(this.pmView,r,s)}}const at=new S.PluginKey("FormattingToolbarPlugin");class ct extends d.BlockNoteExtension{constructor(e){super();u(this,"view");u(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new S.Plugin({key:at,view:o=>(this.view=new it(e,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}}))}static key(){return"formattingToolbar"}get shown(){var e,o;return((o=(e=this.view)==null?void 0:e.state)==null?void 0:o.show)||!1}onUpdate(e){return this.on("update",e)}}const nn=B.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:n}){return["br",B.mergeAttributes(this.options.HTMLAttributes,n)]},renderText(){return`
4
- `}}),he=(n,t)=>{const e=n.resolve(t),o=e.index();if(o===0)return;const r=e.posAtIndex(o-1);return m.getBlockInfoFromResolvedPos(n.resolve(r))},lt=(n,t)=>{for(;t.childContainer;){const e=t.childContainer.node,o=n.resolve(t.childContainer.beforePos+1).posAtIndex(e.childCount-1);t=m.getBlockInfoFromResolvedPos(n.resolve(o))}return t},rn=(n,t)=>n.isBlockContainer&&n.blockContent.node.type.spec.content==="inline*"&&n.blockContent.node.childCount>0&&t.isBlockContainer&&t.blockContent.node.type.spec.content==="inline*",sn=(n,t,e,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${e.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const r=n.doc.resolve(o.childContainer.beforePos+1),s=n.doc.resolve(o.childContainer.afterPos-1),i=r.blockRange(s);if(t){const c=n.doc.resolve(o.bnBlock.beforePos);n.tr.lift(i,c.depth)}}if(t){if(!e.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${e.bnBlock.beforePos}, but previous block is not a block container`);t(n.tr.delete(e.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0},Ne=n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n),r=m.getBlockInfoFromResolvedPos(o),s=he(t.doc,r.bnBlock.beforePos);if(!s)return!1;const i=lt(t.doc,s);return rn(i,r)?sn(t,e,i,r):!1};function an(n,t,e){const{$from:o,$to:r}=n.selection,s=o.blockRange(r,b=>b.childCount>0&&(b.type.name==="blockGroup"||b.type.name==="column"));if(!s)return!1;const i=s.startIndex;if(i===0)return!1;const a=s.parent.child(i-1);if(a.type!==t)return!1;const l=a.lastChild&&a.lastChild.type===e,h=T.Fragment.from(l?t.create():null),p=new T.Slice(T.Fragment.from(t.create(null,T.Fragment.from(e.create(null,h)))),l?3:1,0),k=s.start,g=s.end;return n.step(new W.ReplaceAroundStep(k-(l?3:1),g,k,g,p,1,!0)).scrollIntoView(),!0}function dt(n){return n.transact(t=>an(t,n.pmSchema.nodes.blockContainer,n.pmSchema.nodes.blockGroup))}function cn(n){n._tiptapEditor.commands.liftListItem("blockContainer")}function ln(n){return n.transact(t=>{const{bnBlock:e}=m.getBlockInfoFromTransaction(t);return t.doc.resolve(e.beforePos).nodeBefore!==null})}function dn(n){return n.transact(t=>{const{bnBlock:e}=m.getBlockInfoFromTransaction(t);return t.doc.resolve(e.beforePos).depth>1})}const un=B.Extension.create({priority:50,addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({chain:o,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:s})=>{const i=m.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;const c=s.selection.from===i.blockContent.beforePos+1,a=i.blockContent.node.type.name==="paragraph";return c&&!a?r.command(d.updateBlockCommand(i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=m.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;const{blockContent:c}=i;return s.selection.from===c.beforePos+1?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{const i=m.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;const{bnBlock:c,blockContent:a}=i,l=s.selection.from===a.beforePos+1,h=s.selection.empty,p=c.beforePos;return l&&h?o().command(Ne(p)).scrollIntoView().run():!1}),()=>r.command(({state:s,tr:i,dispatch:c})=>{const a=m.getBlockInfoFromSelection(s);if(!a.isBlockContainer||!(i.selection.from===a.blockContent.beforePos+1))return!1;const h=i.doc.resolve(a.bnBlock.beforePos);if(h.nodeBefore||h.node().type.name!=="column")return!1;const g=i.doc.resolve(a.bnBlock.beforePos),b=i.doc.resolve(g.before()),f=b.before();if(c){const y=i.doc.slice(a.bnBlock.beforePos,a.bnBlock.afterPos).content;i.delete(a.bnBlock.beforePos,a.bnBlock.afterPos),b.index()===0?(oe(i,f),i.insert(f,y),i.setSelection(S.TextSelection.near(i.doc.resolve(f)))):(i.insert(b.pos-1,y),i.setSelection(S.TextSelection.near(i.doc.resolve(b.pos-1))),oe(i,f))}return!0}),()=>r.command(({state:s})=>{const i=m.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const a=he(s.doc,i.bnBlock.beforePos);if(!a||!a.isBlockContainer)return!1;let l=o();if(a.blockContent.node.type.spec.content==="tableRow+"){const b=i.bnBlock.beforePos-1-1-1-1-1;l=l.setTextSelection(b)}else if(a.blockContent.node.type.spec.content===""){const h=a.blockContent.afterPos-a.blockContent.node.nodeSize;l=l.setNodeSelection(h)}else{const h=a.blockContent.afterPos-a.blockContent.node.nodeSize;l=l.setTextSelection(h)}return l.deleteRange({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:s})=>{const i=m.getBlockInfoFromSelection(s);if(!i.isBlockContainer)throw new Error("todo");const c=s.selection.from===i.blockContent.beforePos+1,a=s.selection.empty,l=he(s.doc,i.bnBlock.beforePos);if(l&&c&&a){const h=lt(s.doc,l);if(!h.isBlockContainer)throw new Error("todo");if(h.blockContent.node.type.spec.content===""||h.blockContent.node.type.spec.content==="inline*"&&h.blockContent.node.childCount===0)return o().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},h.bnBlock.afterPos).deleteRange({from:h.bnBlock.beforePos,to:h.bnBlock.afterPos}).run()}return!1})]),t=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:r})=>{const s=m.getBlockInfoFromSelection(r);if(!s.isBlockContainer)return!1;const{bnBlock:i,blockContent:c,childContainer:a}=s,{depth:l}=r.doc.resolve(i.beforePos),h=i.afterPos===r.doc.nodeSize-3,p=r.selection.from===c.afterPos-1,k=r.selection.empty;if(!h&&p&&k&&!(a!==void 0)){let b=l,f=i.afterPos+1,y=r.doc.resolve(f).depth;for(;y<b;)b=y,f+=2,y=r.doc.resolve(f).depth;return o.command(Ne(f-1))}return!1})]),e=(o=!1)=>this.editor.commands.first(({commands:r,tr:s})=>[()=>r.command(({state:i})=>{const c=m.getBlockInfoFromSelection(i);if(!c.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=c,{depth:h}=i.doc.resolve(a.beforePos),p=i.selection.$anchor.parentOffset===0,k=i.selection.anchor===i.selection.head,g=l.node.childCount===0,b=h>1;return p&&k&&g&&b?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:i})=>{var l;const c=m.getBlockInfoFromSelection(i),a=((l=this.options.editor.schema.blockSchema[c.blockNoteType].meta)==null?void 0:l.hardBreakShortcut)??"shift+enter";if(a==="none")return!1;if(a==="shift+enter"&&o||a==="enter"){const h=s.storedMarks||s.selection.$head.marks().filter(p=>this.editor.extensionManager.splittableMarks.includes(p.type.name));return s.insert(s.selection.head,s.doc.type.schema.nodes.hardBreak.create()).ensureMarks(h),!0}return!1}),()=>r.command(({state:i,dispatch:c})=>{const a=m.getBlockInfoFromSelection(i);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:h}=a,p=i.selection.$anchor.parentOffset===0,k=i.selection.anchor===i.selection.head,g=h.node.childCount===0;if(p&&k&&g){const b=l.afterPos,f=b+2;if(c){const y=i.schema.nodes.blockContainer.createAndFill();i.tr.insert(b,y).scrollIntoView(),i.tr.setSelection(new S.TextSelection(i.doc.resolve(f)))}return!0}return!1}),()=>r.command(({state:i,chain:c})=>{const a=m.getBlockInfoFromSelection(i);if(!a.isBlockContainer)return!1;const{blockContent:l}=a,h=i.selection.$anchor.parentOffset===0;return l.node.childCount===0?!1:(c().deleteSelection().command(d.splitBlockCommand(i.selection.from,h,h)).run(),!0)})]);return{Backspace:n,Delete:t,Enter:()=>e(),"Shift-Enter":()=>e(!0),Tab:()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:dt(this.options.editor)},"Shift-Tab":()=>{var o,r,s;return this.options.tabBehavior!=="prefer-indent"&&((o=this.options.editor.formattingToolbar)!=null&&o.shown||(r=this.options.editor.linkToolbar)!=null&&r.shown||(s=this.options.editor.filePanel)!=null&&s.shown)?!1:(this.editor.commands.liftListItem("blockContainer"),!0)},"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()}}});class hn{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredLinkMark");u(this,"mouseHoveredLinkMarkRange");u(this,"keyboardHoveredLinkMark");u(this,"keyboardHoveredLinkMarkRange");u(this,"linkMark");u(this,"linkMarkRange");u(this,"mouseOverHandler",t=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.pmView.posAtDOM(e,0)+1,r=this.pmView.state.doc.resolve(o),s=r.marks();for(const i of s)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=i,this.mouseHoveredLinkMarkRange=B.getMarkRange(r,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var o;const e=this.pmView.dom.parentElement;this.linkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())});u(this,"scrollHandler",()=>{var t;this.linkMark!==void 0&&(t=this.state)!=null&&t.show&&(this.state.referencePos=B.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});u(this,"closeMenu",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});this.editor=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(t,e){var o;this.editor.transact(r=>{const s=m.getPmSchema(r);r.insertText(e,this.linkMarkRange.from,this.linkMarkRange.to),r.addMark(this.linkMarkRange.from,this.linkMarkRange.from+e.length,s.mark("link",{href:t}))}),this.pmView.focus(),(o=this.state)!=null&&o.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var t;this.editor.transact(e=>e.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())}update(t,e,o=!1){var c;const{state:r}=t;if(e&&e.selection.from===r.selection.from&&e.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const a=this.pmView.state.selection.$from.marks();for(const l of a)if(l.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=l,this.keyboardHoveredLinkMarkRange=B.getMarkRange(this.pmView.state.selection.$from,l.type,l.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&o&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable){this.state={show:!0,referencePos:B.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},this.emitUpdate();return}if((c=this.state)!=null&&c.show&&i&&(!this.linkMark||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const ut=new S.PluginKey("LinkToolbarPlugin");class ht extends d.BlockNoteExtension{constructor(e){super();u(this,"view");u(this,"editLink",(e,o)=>{this.view.editLink(e,o)});u(this,"deleteLink",()=>{this.view.deleteLink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});u(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new S.Plugin({key:ut,view:o=>(this.view=new hn(e,o,r=>{this.emit("update",r)}),this.view),props:{handleKeyDown:(o,r)=>r.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}}))}static key(){return"linkToolbar"}onUpdate(e){return this.on("update",e)}get shown(){var e,o;return((o=(e=this.view)==null?void 0:e.state)==null?void 0:o.show)||!1}}const pt=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],mt="https",pn=new S.PluginKey("node-selection-keyboard");class mn extends d.BlockNoteExtension{static key(){return"nodeSelectionKeyboard"}constructor(){super(),this.addProsemirrorPlugin(new S.Plugin({key:pn,props:{handleKeyDown:(t,e)=>{if("node"in t.state.selection){if(e.ctrlKey||e.metaKey)return!1;if(e.key.length===1)return e.preventDefault(),!0;if(e.key==="Enter"&&!e.shiftKey&&!e.altKey&&!e.ctrlKey&&!e.metaKey){const o=t.state.tr;return t.dispatch(o.insert(t.state.tr.selection.$to.after(),t.state.schema.nodes.paragraph.createChecked()).setSelection(new S.TextSelection(o.doc.resolve(t.state.tr.selection.$to.after()+1)))),!0}}return!1}}}))}}const fn=new S.PluginKey("blocknote-placeholder");class gn extends d.BlockNoteExtension{static key(){return"placeholder"}constructor(t,e){super(),this.addProsemirrorPlugin(new S.Plugin({key:fn,view:o=>{const r=`placeholder-selector-${ro.v4()}`;o.dom.classList.add(r);const s=document.createElement("style"),i=t._tiptapEditor.options.injectNonce;i&&s.setAttribute("nonce",i),o.root instanceof window.ShadowRoot?o.root.append(s):o.root.head.appendChild(s);const c=s.sheet,a=(l="")=>`.${r} .bn-block-content${l} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:l,emptyDocument:h,...p}=e;for(const[b,f]of Object.entries(p)){const y=`[data-content-type="${b}"]`;c.insertRule(`${a(y)} { content: ${JSON.stringify(f)}; }`)}const k="[data-is-only-empty-block]",g="[data-is-empty-and-focused]";c.insertRule(`${a(k)} { content: ${JSON.stringify(h)}; }`),c.insertRule(`${a(g)} { 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(!t.isEditable||!s.empty||s.$from.parent.type.spec.code)return;const i=[];o.doc.content.size===6&&i.push(M.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const c=s.$anchor,a=c.parent;if(a.content.size===0){const l=c.before();i.push(M.Decoration.node(l,l+a.nodeSize,{"data-is-empty-and-focused":"true"}))}return M.DecorationSet.create(r,i)}}}))}}const Ae=new S.PluginKey("previous-blocks"),kn={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class bn extends d.BlockNoteExtension{static key(){return"previousBlockType"}constructor(){super();let t;this.addProsemirrorPlugin(new S.Plugin({key:Ae,view(e){return{update:async(o,r)=>{var s;((s=this.key)==null?void 0:s.getState(o.state).updatedBlocks.size)>0&&(t=setTimeout(()=>{o.dispatch(o.state.tr.setMeta(Ae,{clearUpdate:!0}))},0))},destroy:()=>{t&&clearTimeout(t)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,o,r,s){if(o.currentTransactionOldBlockAttrs={},o.updatedBlocks.clear(),!e.docChanged||r.doc.eq(s.doc))return o;const i={},c=B.findChildren(r.doc,h=>h.attrs.id),a=new Map(c.map(h=>[h.node.attrs.id,h])),l=B.findChildren(s.doc,h=>h.attrs.id);for(const h of l){const p=a.get(h.node.attrs.id),k=p==null?void 0:p.node.firstChild,g=h.node.firstChild;if(p&&k&&g){const b={index:g.attrs.index,level:g.attrs.level,type:g.type.name,depth:s.doc.resolve(h.pos).depth},f={index:k.attrs.index,level:k.attrs.level,type:k.type.name,depth:r.doc.resolve(p.pos).depth};i[h.node.attrs.id]=f,o.currentTransactionOldBlockAttrs[h.node.attrs.id]=f,JSON.stringify(f)!==JSON.stringify(b)&&(f["depth-change"]=f.depth-b.depth,o.updatedBlocks.add(h.node.attrs.id))}}return o.prevTransactionOldBlockAttrs=i,o}},props:{decorations(e){const o=this.getState(e);if(o.updatedBlocks.size===0)return;const r=[];return e.doc.descendants((s,i)=>{if(!s.attrs.id||!o.updatedBlocks.has(s.attrs.id))return;const c=o.currentTransactionOldBlockAttrs[s.attrs.id],a={};for(const[h,p]of Object.entries(c))a["data-prev-"+kn[h]]=p||"none";const l=M.Decoration.node(i,i+s.nodeSize,{...a});r.push(l)}),M.DecorationSet.create(e.doc,r)}}}))}}const _e=new S.PluginKey("blocknote-show-selection");class yn extends d.BlockNoteExtension{constructor(e){super();u(this,"enabled",!1);this.editor=e,this.addProsemirrorPlugin(new S.Plugin({key:_e,props:{decorations:o=>{const{doc:r,selection:s}=o;if(!this.enabled)return M.DecorationSet.empty;const i=M.Decoration.inline(s.from,s.to,{"data-show-selection":"true"});return M.DecorationSet.create(r,[i])}}}))}static key(){return"showSelection"}setEnabled(e){this.enabled!==e&&(this.enabled=e,this.editor.transact(o=>o.setMeta(_e,{})))}getEnabled(){return this.enabled}}function ft(n,t){var e,o;for(;n&&n.parentElement&&n.parentElement!==t.dom&&((e=n.getAttribute)==null?void 0:e.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")}}class F extends S.Selection{constructor(e,o){super(e,o);u(this,"nodes");const r=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(s,i,c)=>{if(c!==null&&c.eq(r))return this.nodes.push(s),!1})}static create(e,o,r=o){return new F(e.resolve(o),e.resolve(r))}content(){return new T.Slice(T.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof F)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){const r=o.mapResult(this.from),s=o.mapResult(this.to);return s.deleted?S.Selection.near(e.resolve(r.pos)):r.deleted?S.Selection.near(e.resolve(s.pos)):new F(e.resolve(r.pos),e.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}S.Selection.jsonID("multiple-node",F);let O;function wn(n,t){let e,o;const r=t.resolve(n.from).node().type.spec.group==="blockContent",s=t.resolve(n.to).node().type.spec.group==="blockContent",i=Math.min(n.$anchor.depth,n.$head.depth);if(r&&s){const c=n.$from.start(i-1),a=n.$to.end(i-1);e=t.resolve(c-1).pos,o=t.resolve(a+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function Oe(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),r=n.domAtPos(t).node,s=(p,k)=>Array.prototype.indexOf.call(p.children,k),i=s(r,n.domAtPos(t+1).node.parentElement),c=s(r,n.domAtPos(e-1).node.parentElement);for(let p=r.childElementCount-1;p>=0;p--)(p>c||p<i)&&o.removeChild(o.children[p]);gt(n.root),O=o;const a=O.getElementsByTagName("iframe");for(let p=0;p<a.length;p++){const k=a[p],g=k.parentElement;g&&g.removeChild(k)}const h=n.dom.className.split(" ").filter(p=>p!=="ProseMirror"&&p!=="bn-root"&&p!=="bn-editor").join(" ");O.className=O.className+" bn-drag-preview "+h,n.root instanceof ShadowRoot?n.root.appendChild(O):n.root.body.appendChild(O)}function gt(n){O!==void 0&&(n instanceof ShadowRoot?n.removeChild(O):n.body.removeChild(O),O=void 0)}function Sn(n,t,e){if(!n.dataTransfer||e.headless)return;const o=e.prosemirrorView,r=d.getNodeById(t.id,o.state.doc);if(!r)throw new Error(`Block with ID ${t.id} not found`);const s=r.posBeforeNode;if(s!=null){const i=o.state.selection,c=o.state.doc,{from:a,to:l}=wn(i,c),h=a<=s&&s<l,p=i.$anchor.node()!==i.$head.node()||i instanceof F;h&&p?(o.dispatch(o.state.tr.setSelection(F.create(c,a,l))),Oe(o,a,l)):(o.dispatch(o.state.tr.setSelection(S.NodeSelection.create(o.state.doc,s))),Oe(o,s));const k=o.state.selection.content(),g=e.pmSchema,b=o.serializeForClipboard(k).dom.innerHTML,f=X(g,e),y=et(k.content),w=f.exportBlocks(y,{}),C=ie(w);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",b),n.dataTransfer.setData("text/html",w),n.dataTransfer.setData("text/plain",C),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(O,0,0)}}const He=250;function pe(n,t,e=!0){const o=n.root.elementsFromPoint(t.left,t.top);for(const r of o)if(n.dom.contains(r))return e&&r.closest("[data-node-type=columnList]")?pe(n,{left:t.left+50,top:t.top},!1):ft(r,n)}function Cn(n,t){if(!t.dom.firstChild)return;const e=t.dom.firstChild.getBoundingClientRect(),o={left:Math.min(Math.max(e.left+10,n.x),e.right-10),top:n.y},r=pe(t,o);if(!r)return;const s=r.node.getBoundingClientRect();return pe(t,{left:s.right-10,top:n.y},!1)}class kt{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"mousePos");u(this,"hoveredBlock");u(this,"menuFrozen",!1);u(this,"isDragOrigin",!1);u(this,"updateState",t=>{this.state=t,this.emitUpdate(this.state)});u(this,"updateStateFromMousePos",()=>{var o,r,s,i,c;if(this.menuFrozen||!this.mousePos)return;const t=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((t==null?void 0:t.element)!==this.pmView.dom||t.distance>He){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}const e=Cn(this.mousePos,this.pmView);if(!e||!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"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===e.id)&&(this.hoveredBlock=e.node,this.editor.isEditable)){const a=e.node.getBoundingClientRect(),l=e.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(l?l.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,a.y,a.width,a.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}});u(this,"onDragStart",t=>{var i;const e=(i=t.dataTransfer)==null?void 0:i.getData("blocknote/html");if(!e||this.pmView.dragging)return;const o=document.createElement("div");o.innerHTML=e;const s=T.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new T.Slice(s.content,0,0),move:!0}});u(this,"findClosestEditorElement",t=>{const e=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(e.length===0)return null;let o=e[0],r=Number.MAX_VALUE;return e.forEach(s=>{const i=s.querySelector(".bn-block-group").getBoundingClientRect(),c=t.clientX<i.left?i.left-t.clientX:t.clientX>i.right?t.clientX-i.right:0,a=t.clientY<i.top?i.top-t.clientY:t.clientY>i.bottom?t.clientY-i.bottom:0,l=Math.sqrt(Math.pow(c,2)+Math.pow(a,2));l<r&&(r=l,o=s)}),{element:o,distance:r}});u(this,"onDragOver",t=>{if(t.synthetic)return;const e=this.getDragEventContext(t);if(!e||!e.isDropPoint){this.closeDropCursor();return}e.isDropPoint&&!e.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(t)});u(this,"closeDropCursor",()=>{const t=new Event("dragleave",{bubbles:!1});t.synthetic=!0,this.pmView.dom.dispatchEvent(t)});u(this,"getDragEventContext",t=>{var a;const e=!((a=t.dataTransfer)!=null&&a.types.includes("blocknote/html"))&&!!this.pmView.dragging,o=!!this.isDragOrigin,r=e||o,s=this.findClosestEditorElement(t);if(!s||s.distance>He)return;const i=s.element===this.pmView.dom,c=i&&s.distance===0;if(!(!i&&!r))return{isDropPoint:i,isDropWithinEditorBounds:c,isDragOrigin:r}});u(this,"onDrop",t=>{if(t.synthetic)return;const e=this.getDragEventContext(t);if(!e){this.closeDropCursor();return}const{isDropPoint:o,isDropWithinEditorBounds:r,isDragOrigin:s}=e;if(!r&&o&&this.dispatchSyntheticEvent(t),o){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(S.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}});u(this,"onDragEnd",t=>{t.synthetic||(this.pmView.dragging=null)});u(this,"onKeyDown",t=>{var e;(e=this.state)!=null&&e.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});u(this,"onMouseMove",t=>{var s;if(this.menuFrozen)return;this.mousePos={x:t.clientX,y:t.clientY};const e=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>e.left&&this.mousePos.x<e.right&&this.mousePos.y>e.top&&this.mousePos.y<e.bottom,r=this.pmView.dom.parentElement;if(o&&t&&t.target&&!(r===t.target||r.contains(t.target))){(s=this.state)!=null&&s.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()});u(this,"onScroll",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state)),this.updateStateFromMousePos()});this.editor=t,this.pmView=e,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),e.root.addEventListener("scroll",this.onScroll,!0)}dispatchSyntheticEvent(t){const e=new Event(t.type,t),o=this.pmView.dom.firstChild.getBoundingClientRect();e.clientX=t.clientX,e.clientY=t.clientY,e.clientX=Math.min(Math.max(t.clientX,o.left),o.left+o.width),e.clientY=Math.min(Math.max(t.clientY,o.top),o.top+o.height),e.dataTransfer=t.dataTransfer,e.preventDefault=()=>t.preventDefault(),e.synthetic=!0,this.pmView.dom.dispatchEvent(e)}update(t,e){var r;!e.doc.eq(this.pmView.state.doc)&&((r=this.state)!=null&&r.show)&&this.updateStateFromMousePos()}destroy(){var t;(t=this.state)!=null&&t.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),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const bt=new S.PluginKey("SideMenuPlugin");class yt extends d.BlockNoteExtension{constructor(e){super();u(this,"view");u(this,"blockDragStart",(e,o)=>{this.view&&(this.view.isDragOrigin=!0),Sn(e,o,this.editor)});u(this,"blockDragEnd",()=>{gt(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1),this.editor.blur()});u(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)});u(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=e,this.addProsemirrorPlugin(new S.Plugin({key:bt,view:o=>(this.view=new kt(e,o,r=>{this.emit("update",r)}),this.view)}))}static key(){return"sideMenu"}onUpdate(e){return this.on("update",e)}}const Q=new Map;function Bn(n){if(Q.has(n))return Q.get(n);const t=new W.Mapping;return n._tiptapEditor.on("transaction",({transaction:e})=>{t.appendMapping(e.mapping)}),n._tiptapEditor.on("destroy",()=>{Q.delete(n)}),Q.set(n,t),t}function wt(n,t,e="left"){const o=E.ySyncPluginKey.getState(n.prosemirrorState);if(!o){const s=Bn(n),i=s.maps.length;return()=>s.slice(i).map(t,e==="left"?-1:1)}const r=E.absolutePositionToRelativePosition(t+(e==="right"?1:-1),o.binding.type,o.binding.mapping);return()=>{const s=E.ySyncPluginKey.getState(n.prosemirrorState),i=E.relativePositionToAbsolutePosition(s.doc,s.binding.type,r,s.binding.mapping);if(i===null)throw new Error("Position not found, cannot track positions");return i+(e==="right"?-1:1)}}const vn=B.findParentNode(n=>n.type.name==="blockContainer");class Pn{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"rootEl");u(this,"pluginState");u(this,"handleScroll",()=>{var t,e;if((t=this.state)!=null&&t.show){const o=(e=this.rootEl)==null?void 0:e.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!o)return;this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor.transact(t=>t.setMeta(z,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(t=>t.selection.from)}).run()});var r;this.editor=t,this.pluginState=void 0,this.emitUpdate=s=>{var i;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");e(s,{...this.state,ignoreQueryLength:(i=this.pluginState)==null?void 0:i.ignoreQueryLength})},this.rootEl=o.root,(r=this.rootEl)==null||r.addEventListener("scroll",this.handleScroll,!0)}update(t,e){var l;const o=z.getState(e),r=z.getState(t.state),s=o===void 0&&r!==void 0,i=o!==void 0&&r===void 0;if(!s&&!(o!==void 0&&r!==void 0)&&!i)return;if(this.pluginState=i?o:r,i||!this.editor.isEditable){this.state&&(this.state.show=!1),this.emitUpdate(this.pluginState.triggerCharacter);return}const a=(l=this.rootEl)==null?void 0:l.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&a&&(this.state={show:!0,referencePos:a.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var t;(t=this.rootEl)==null||t.removeEventListener("scroll",this.handleScroll,!0)}}const z=new S.PluginKey("SuggestionMenuPlugin");class St extends d.BlockNoteExtension{constructor(e){super();u(this,"view");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)});u(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==e)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.addProsemirrorPlugin(new S.Plugin({key:z,view:r=>(this.view=new Pn(e,(s,i)=>{this.emit(`update ${s}`,i)},r),this.view),state:{init(){},apply:(r,s,i,c)=>{if(r.selection.$from.parent.type.spec.code)return s;const a=r.getMeta(z);if(typeof a=="object"&&a!==null){s&&this.closeMenu();const h=wt(e,c.selection.from-a.triggerCharacter.length);return{triggerCharacter:a.triggerCharacter,deleteTriggerCharacter:a.deleteTriggerCharacter!==!1,queryStartPos:()=>h()+a.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`,ignoreQueryLength:a==null?void 0:a.ignoreQueryLength}}if(s===void 0)return s;if(c.selection.from!==c.selection.to||a===null||r.getMeta("focus")||r.getMeta("blur")||r.getMeta("pointer")||s.triggerCharacter!==void 0&&c.selection.from<s.queryStartPos()||!c.selection.$from.sameParent(c.doc.resolve(s.queryStartPos())))return;const l={...s};return l.query=c.doc.textBetween(s.queryStartPos(),c.selection.from),l}},props:{handleTextInput(r,s,i,c){if(s===i){const a=r.state.doc;for(const l of o){const h=l.length>1?a.textBetween(s-l.length,s)+c:c;if(l===h)return r.dispatch(r.state.tr.insertText(c)),r.dispatch(r.state.tr.setMeta(z,{triggerCharacter:h}).scrollIntoView()),!0}}return!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=vn(r.selection);if(i)return M.DecorationSet.create(r.doc,[M.Decoration.node(i.pos,i.pos+i.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}return M.DecorationSet.create(r.doc,[M.Decoration.inline(s.queryStartPos()-s.triggerCharacter.length,s.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}}}))}static key(){return"suggestionMenu"}onUpdate(e,o){return this.triggerCharacters.includes(e)||this.addTriggerCharacter(e),this.on(`update ${e}`,o)}get shown(){var e,o;return((o=(e=this.view)==null?void 0:e.state)==null?void 0:o.show)||!1}}function Tn(n,t){n.suggestionMenus.addTriggerCharacter(t)}const En=B.Mark.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(n){return n.name!=="insertion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(t,e){return["ins",{"data-id":String(t.attrs.id),"data-inline":String(e),...!e&&{style:"display: contents"}},0]},parseDOM:[{tag:"ins",getAttrs(t){return t.dataset.id?{id:parseInt(t.dataset.id,10)}:!1}}]}}}),Mn=B.Mark.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(n){return n.name!=="deletion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(t,e){return["del",{"data-id":String(t.attrs.id),"data-inline":String(e),...!e&&{style:"display: contents"}},0]},parseDOM:[{tag:"del",getAttrs(t){return t.dataset.id?{id:parseInt(t.dataset.id,10)}:!1}}]}}}),xn=B.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(n){return n.name!=="modification"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(t,e){return[e?"span":"div",{"data-type":"modification","data-id":String(t.attrs.id),"data-mod-type":t.attrs.type,"data-mod-prev-val":JSON.stringify(t.attrs.previousValue),"data-mod-new-val":JSON.stringify(t.attrs.newValue)},0]},parseDOM:[{tag:"span[data-type='modification']",getAttrs(t){return t.dataset.id?{id:parseInt(t.dataset.id,10),type:t.dataset.modType,previousValue:t.dataset.modPrevVal,newValue:t.dataset.modNewVal}:!1}},{tag:"div[data-type='modification']",getAttrs(t){return t.dataset.id?{id:parseInt(t.dataset.id,10),type:t.dataset.modType,previousValue:t.dataset.modPrevVal}:!1}}]}}});let A;function Ue(n){A||(A=document.createElement("div"),A.innerHTML="_",A.style.opacity="0",A.style.height="1px",A.style.width="1px",n instanceof Document?n.body.appendChild(A):n.appendChild(A))}function In(n){A&&(n instanceof Document?n.body.removeChild(A):n.removeChild(A),A=void 0)}function Z(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function Dn(n){let t=n;for(;t&&t.nodeName!=="TD"&&t.nodeName!=="TH"&&!t.classList.contains("tableWrapper");){if(t.classList.contains("ProseMirror"))return;const e=t.parentNode;if(!e||!(e instanceof Element))return;t=e}return t.nodeName==="TD"||t.nodeName==="TH"?{type:"cell",domNode:t,tbodyNode:t.closest("tbody")}:{type:"wrapper",domNode:t,tbodyNode:t.querySelector("tbody")}}function Ln(n,t){const e=t.querySelectorAll(n);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"}class Ct{constructor(t,e,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"tableElement");u(this,"menuFrozen",!1);u(this,"mouseState","up");u(this,"prevWasEditable",null);u(this,"viewMousedownHandler",()=>{this.mouseState="down"});u(this,"mouseUpHandler",t=>{this.mouseState="up",this.mouseMoveHandler(t)});u(this,"mouseMoveHandler",t=>{var l,h,p,k,g,b,f;if(this.menuFrozen||this.mouseState==="selecting"||!(t.target instanceof Element)||!this.pmView.dom.contains(t.target))return;const e=Dn(t.target);if((e==null?void 0:e.type)==="cell"&&this.mouseState==="down"&&!((l=this.state)!=null&&l.draggingState)){this.mouseState="selecting",(h=this.state)!=null&&h.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!e||!this.editor.isEditable){(p=this.state)!=null&&p.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!e.tbodyNode)return;const o=e.tbodyNode.getBoundingClientRect(),r=ft(e.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(y=>d.getNodeById(r.id,y.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const c=m.nodeToBlock(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(d.editorHasBlockWithType(this.editor,"table")&&(this.tablePos=i.posBeforeNode+1,s=c),!s)return;this.tableId=r.id;const a=(k=e.domNode.closest(".tableWrapper"))==null?void 0:k.querySelector(".table-widgets-container");if((e==null?void 0:e.type)==="wrapper"){const y=t.clientY>=o.bottom-1&&t.clientY<o.bottom+20,w=t.clientX>=o.right-1&&t.clientX<o.right+20,C=t.clientX>o.right||t.clientY>o.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:y,showAddOrRemoveColumnsButton:w,referencePosTable:o,block:s,widgetContainer:a,colIndex:C||(g=this.state)==null?void 0:g.colIndex,rowIndex:C||(b=this.state)==null?void 0:b.rowIndex,referencePosCell:C||(f=this.state)==null?void 0:f.referencePosCell}}else{const y=Z(e.domNode),w=Z(e.domNode.parentElement),C=e.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===w&&this.state.colIndex===y)return;this.state={show:!0,showAddOrRemoveColumnsButton:y===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:w===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:C,colIndex:y,rowIndex:w,widgetContainer:a}}return this.emitUpdate(),!1});u(this,"dragOverHandler",t=>{var k;if(((k=this.state)==null?void 0:k.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",Ln(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const e={left:Math.min(Math.max(t.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(t.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(e.left,e.top).filter(g=>g.tagName==="TD"||g.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=Z(r.parentElement),c=Z(r),a=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,h=(this.state.draggingState.draggedCellOrientation==="row"?i:c)!==a;(this.state.rowIndex!==i||this.state.colIndex!==c)&&(this.state.rowIndex=i,this.state.colIndex=c,this.state.referencePosCell=r.getBoundingClientRect(),s=!0);const p=this.state.draggingState.draggedCellOrientation==="row"?e.top:e.left;this.state.draggingState.mousePos!==p&&(this.state.draggingState.mousePos=p,s=!0),s&&this.emitUpdate(),h&&this.editor.transact(g=>g.setMeta(V,!0))});u(this,"dropHandler",t=>{if(this.mouseState="up",this.state===void 0||this.state.draggingState===void 0)return!1;if(this.state.rowIndex===void 0||this.state.colIndex===void 0)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");t.preventDefault();const{draggingState:e,colIndex:o,rowIndex:r}=this.state,s=this.state.block.content.columnWidths;if(e.draggedCellOrientation==="row"){if(!m.canRowBeDraggedInto(this.state.block,e.originalIndex,r))return!1;const i=m.moveRow(this.state.block,e.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!m.canColumnBeDraggedInto(this.state.block,e.originalIndex,o))return!1;const i=m.moveColumn(this.state.block,e.originalIndex,o),[c]=s.splice(e.originalIndex,1);s.splice(o,0,c),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=t,this.pmView=e,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},e.dom.addEventListener("mousemove",this.mouseMoveHandler),e.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),e.root.addEventListener("dragover",this.dragOverHandler),e.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:t,width:e}=m.getDimensionsOfTable(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=t&&(this.state.rowIndex=t-1),this.state.colIndex>=e&&(this.state.colIndex=e-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 V=new S.PluginKey("TableHandlesPlugin");class Bt extends d.BlockNoteExtension{constructor(e){super();u(this,"view");u(this,"colDragStart",e=>{if(this.view.state===void 0||this.view.state.colIndex===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(V,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.headless&&(Ue(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(A,0,0),e.dataTransfer.effectAllowed="move")});u(this,"rowDragStart",e=>{if(this.view.state===void 0||this.view.state.rowIndex===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.emitUpdate(),this.editor.transact(o=>o.setMeta(V,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.headless&&(Ue(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(A,0,0),e.dataTransfer.effectAllowed="copyMove")});u(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(V,null)),!this.editor.headless&&In(this.editor.prosemirrorView.root)});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});u(this,"getCellsAtRowHandle",(e,o)=>m.getCellsAtRowHandle(e,o));u(this,"getCellsAtColumnHandle",(e,o)=>m.getCellsAtColumnHandle(e,o));u(this,"setCellSelection",(e,o,r=o)=>{const s=this.view;if(!s)throw new Error("Table handles view not initialized");const i=e.doc.resolve(s.tablePos+1),c=e.doc.resolve(i.posAtIndex(o.row)+1),a=e.doc.resolve(c.posAtIndex(o.col)),l=e.doc.resolve(i.posAtIndex(r.row)+1),h=e.doc.resolve(l.posAtIndex(r.col)),p=e.tr;return p.setSelection(new N.CellSelection(a,h)),e.apply(p)});u(this,"addRowOrColumn",(e,o)=>{this.editor.exec((r,s)=>{const i=this.setCellSelection(r,o.orientation==="row"?{row:e,col:0}:{row:0,col:e});return o.orientation==="row"?o.side==="above"?N.addRowBefore(i,s):N.addRowAfter(i,s):o.side==="left"?N.addColumnBefore(i,s):N.addColumnAfter(i,s)})});u(this,"removeRowOrColumn",(e,o)=>o==="row"?this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:e,col:0});return N.deleteRow(i,s)}):this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:0,col:e});return N.deleteColumn(i,s)}));u(this,"mergeCells",e=>this.editor.exec((o,r)=>{const s=e?this.setCellSelection(o,e.relativeStartCell,e.relativeEndCell):o;return N.mergeCells(s,r)}));u(this,"splitCell",e=>this.editor.exec((o,r)=>{const s=e?this.setCellSelection(o,e):o;return N.splitCell(s,r)}));u(this,"getCellSelection",()=>this.editor.transact(e=>{const o=e.selection;let r=o.$from,s=o.$to;if(d.isTableCellSelection(o)){const{ranges:b}=o;b.forEach(f=>{r=f.$from.min(r??f.$from),s=f.$to.max(s??f.$to)})}else if(r=e.doc.resolve(o.$from.pos-o.$from.parentOffset-1),s=e.doc.resolve(o.$to.pos-o.$to.parentOffset-1),r.pos===0||s.pos===0)return;const i=e.doc.resolve(r.pos-r.parentOffset-1),c=e.doc.resolve(s.pos-s.parentOffset-1),a=e.doc.resolve(i.pos-i.parentOffset-1),l=r.index(i.depth),h=i.index(a.depth),p=s.index(c.depth),k=c.index(a.depth),g=[];for(let b=h;b<=k;b++)for(let f=l;f<=p;f++)g.push({row:b,col:f});return{from:{row:h,col:l},to:{row:k,col:p},cells:g}}));u(this,"getMergeDirection",e=>this.editor.transact(o=>{const r=d.isTableCellSelection(o.selection)?o.selection:void 0;if(!r||!e||r.ranges.length<=1)return;const s=this.getCellSelection();if(s)return m.areInSameColumn(s.from,s.to,e)?"vertical":"horizontal"}));u(this,"cropEmptyRowsOrColumns",(e,o)=>m.cropEmptyRowsOrColumns(e,o));u(this,"addRowsOrColumns",(e,o,r)=>m.addRowsOrColumns(e,o,r));this.editor=e,this.addProsemirrorPlugin(new S.Plugin({key:V,view:o=>(this.view=new Ct(e,o,r=>{this.emit("update",r)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const r=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex;if(r===void 0)return;const s=[],{block:i,draggingState:c}=this.view.state,{originalIndex:a,draggedCellOrientation:l}=c;if(r===a||!i||l==="row"&&!m.canRowBeDraggedInto(i,a,r)||l==="col"&&!m.canColumnBeDraggedInto(i,a,r))return M.DecorationSet.create(o.doc,s);const h=o.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?m.getCellsAtRowHandle(this.view.state.block,r).forEach(({row:k,col:g})=>{const b=o.doc.resolve(h.posAtIndex(k)+1),f=o.doc.resolve(b.posAtIndex(g)+1),y=f.node(),w=f.pos+(r>a?y.nodeSize-2:0);s.push(M.Decoration.widget(w,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.left="0",C.style.right="0",r>a?C.style.bottom="-2px":C.style.top="-3px",C.style.height="4px",C}))}):m.getCellsAtColumnHandle(this.view.state.block,r).forEach(({row:k,col:g})=>{const b=o.doc.resolve(h.posAtIndex(k)+1),f=o.doc.resolve(b.posAtIndex(g)+1),y=f.node(),w=f.pos+(r>a?y.nodeSize-2:0);s.push(M.Decoration.widget(w,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.top="0",C.style.bottom="0",r>a?C.style.right="-2px":C.style.left="-3px",C.style.width="4px",C}))}),M.DecorationSet.create(o.doc,s)}}}))}static key(){return"tableHandles"}onUpdate(e){return this.on("update",e)}}const Nn=B.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment==="left"?{}:{"data-text-alignment":n.textAlignment}}}}]}}),An=B.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["table","tableCell","tableHeader"],attributes:{textColor:d.getTextColorAttribute()}}]}}),_n=B.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new S.PluginKey(this.name);return[new S.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:r,tr:s,schema:i}=o,c=n.getState(o),a=r.content.size-2,l=i.nodes.blockContainer,h=i.nodes.paragraph;if(c)return s.insert(a,l.create(void 0,h.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")return!0;const r=o.firstChild;if(!r)throw new Error("Expected blockContent");return o.nodeSize>4||r.type.spec.content!=="inline*"}}})]}}),On={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Hn=B.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:n=>{if(typeof n=="string")return!1;const t={};for(const[e,o]of Object.entries(On))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return t}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:n}){var r;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[s,i]of Object.entries(n))s!=="class"&&t.setAttribute(s,i);const e={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...n},o=document.createElement("div");o.className=d.mergeCSSClasses("bn-block",e.class),o.setAttribute("data-node-type",this.name);for(const[s,i]of Object.entries(e))s!=="class"&&o.setAttribute(s,i);return t.appendChild(o),{dom:t,contentDOM:o}}}),Un=B.Node.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},e=document.createElement("div");e.className=d.mergeCSSClasses("bn-block-group",t.class),e.setAttribute("data-node-type","blockGroup");for(const[r,s]of Object.entries(t))r!=="class"&&e.setAttribute(r,s);return{dom:e,contentDOM:e}}}),Rn=B.Node.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"}),vt=n=>{var r;const t={},e=Fn(n);for(const s of e)t[s.name]=s;n.collaboration&&(t.ySyncPlugin=new ne(n.collaboration.fragment),t.yUndoPlugin=new re({editor:n.editor}),(r=n.collaboration.provider)!=null&&r.awareness&&(t.yCursorPlugin=new Y(n.collaboration)),t.forkYDocPlugin=new tt({editor:n.editor,collaboration:n.collaboration}),t.schemaMigrationPlugin=new be(n.collaboration.fragment)),t.formattingToolbar=new ct(n.editor),t.linkToolbar=new ht(n.editor),t.sideMenu=new yt(n.editor),t.suggestionMenus=new St(n.editor),t.filePanel=new st(n.editor),t.placeholder=new gn(n.editor,n.placeholders),(n.animations??!0)&&(t.animations=new bn),n.tableHandles&&(t.tableHandles=new Bt(n.editor)),t.nodeSelectionKeyboard=new mn,t.blockChange=new Jo,t.showSelection=new yn(n.editor),n.comments&&(t.comments=new nt(n.editor,n.comments.threadStore,se.name,n.comments.resolveUsers,n.comments.schema));const o=n.disableExtensions||[];for(const s of o)delete t[s];return t};let Re=!1;const Fn=n=>{const t=[B.extensions.ClipboardTextSerializer,B.extensions.Commands,B.extensions.Editable,B.extensions.FocusEvents,B.extensions.Tabindex,Wt.Gapcursor,B.Extension.create({name:"dropCursor",addProseMirrorPlugins:()=>[n.dropCursor({width:5,color:"#ddeeff",editor:n.editor})]}),m.UniqueID.configure({types:["blockContainer","columnList","column"],setIdAttribute:n.setIdAttribute}),nn,Jt.Text,En,Mn,xn,Xt.Link.extend({inclusive:!1}).configure({defaultProtocol:mt,protocols:Re?[]:pt}),...Object.values(n.styleSpecs).map(e=>e.implementation.mark.configure({editor:n.editor})),An,Xo,Nn,B.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>n.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),Rn,Hn.configure({editor:n.editor,domAttributes:n.domAttributes}),un.configure({editor:n.editor,tabBehavior:n.tabBehavior}),Un.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(e=>e.config!=="link"&&e.config!=="text").map(e=>e.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(e=>[..."node"in e.implementation?[e.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]:[]]),Yo(n.editor),Ko(n.editor,n.pasteHandler||(e=>e.defaultPasteHandler())),Eo(n.editor),...n.trailingBlock===void 0||n.trailingBlock?[_n]:[],...n.comments?[se]:[]];return Re=!0,n.collaboration||t.push(Yt.History),t};function Vn(n){return n.transact(t=>{const e=m.getNearestBlockPos(t.doc,t.selection.anchor);if(t.selection instanceof N.CellSelection)return{type:"cell",anchorBlockId:e.node.attrs.id,anchorCellOffset:t.selection.$anchorCell.pos-e.posBeforeNode,headCellOffset:t.selection.$headCell.pos-e.posBeforeNode};if(t.selection instanceof S.NodeSelection)return{type:"node",anchorBlockId:e.node.attrs.id};{const o=m.getNearestBlockPos(t.doc,t.selection.head);return{type:"text",anchorBlockId:e.node.attrs.id,headBlockId:o.node.attrs.id,anchorOffset:t.selection.anchor-e.posBeforeNode,headOffset:t.selection.head-o.posBeforeNode}}})}function $n(n,t){var r,s;const e=(r=d.getNodeById(t.anchorBlockId,n.doc))==null?void 0:r.posBeforeNode;if(e===void 0)throw new Error(`Could not find block with ID ${t.anchorBlockId} to update selection`);let o;if(t.type==="cell")o=N.CellSelection.create(n.doc,e+t.anchorCellOffset,e+t.headCellOffset);else if(t.type==="node")o=S.NodeSelection.create(n.doc,e+1);else{const i=(s=d.getNodeById(t.headBlockId,n.doc))==null?void 0:s.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${t.headBlockId} to update selection`);o=S.TextSelection.create(n.doc,e+t.anchorOffset,i+t.headOffset)}n.setSelection(o)}function me(n){return n.map(t=>t.type==="columnList"?t.children.map(e=>me(e.children)).flat():{...t,children:me(t.children)}).flat()}function Pt(n,t,e){n.transact(o=>{var i;const r=((i=n.getSelection())==null?void 0:i.blocks)||[n.getTextCursorPosition().block],s=Vn(n);n.removeBlocks(r),n.insertBlocks(me(r),t,e),$n(o,s)})}function Tt(n){return!n||n.type!=="columnList"}function Et(n,t,e){let o,r;if(t?t.children.length>0?(o=t.children[t.children.length-1],r="after"):(o=t,r="before"):e&&(o=e,r="before"),!o||!r)return;const s=n.getParentBlock(o);return Tt(s)?{referenceBlock:o,placement:r}:Et(n,r==="after"?o:n.getPrevBlock(o),s)}function Mt(n,t,e){let o,r;if(t?t.children.length>0?(o=t.children[0],r="before"):(o=t,r="after"):e&&(o=e,r="after"),!o||!r)return;const s=n.getParentBlock(o);return Tt(s)?{referenceBlock:o,placement:r}:Mt(n,r==="before"?o:n.getNextBlock(o),s)}function zn(n){n.transact(()=>{const t=n.getSelection(),e=(t==null?void 0:t.blocks[0])||n.getTextCursorPosition().block,o=Et(n,n.getPrevBlock(e),n.getParentBlock(e));o&&Pt(n,o.referenceBlock,o.placement)})}function Kn(n){n.transact(()=>{const t=n.getSelection(),e=(t==null?void 0:t.blocks[(t==null?void 0:t.blocks.length)-1])||n.getTextCursorPosition().block,o=Mt(n,n.getNextBlock(e),n.getParentBlock(e));o&&Pt(n,o.referenceBlock,o.placement)})}function xt(n,t){const e=typeof t=="string"?t:t.id,o=m.getPmSchema(n),r=d.getNodeById(e,n);if(r)return m.nodeToBlock(r.node,o)}function It(n,t){const e=typeof t=="string"?t:t.id,o=d.getNodeById(e,n),r=m.getPmSchema(n);if(!o)return;const i=n.resolve(o.posBeforeNode).nodeBefore;if(i)return m.nodeToBlock(i,r)}function Dt(n,t){const e=typeof t=="string"?t:t.id,o=d.getNodeById(e,n),r=m.getPmSchema(n);if(!o)return;const i=n.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(i)return m.nodeToBlock(i,r)}function Lt(n,t){const e=typeof t=="string"?t:t.id,o=m.getPmSchema(n),r=d.getNodeById(e,n);if(!r)return;const s=n.resolve(r.posBeforeNode),i=s.node(),c=s.node(-1),a=c.type.name!=="doc"?i.type.name==="blockGroup"?c:i:void 0;if(a)return m.nodeToBlock(a,o)}class qn{constructor(t){this.editor=t}get document(){return this.editor.transact(t=>m.docToBlocks(t.doc,this.editor.pmSchema))}getBlock(t){return this.editor.transact(e=>xt(e.doc,t))}getPrevBlock(t){return this.editor.transact(e=>It(e.doc,t))}getNextBlock(t){return this.editor.transact(e=>Dt(e.doc,t))}getParentBlock(t){return this.editor.transact(e=>Lt(e.doc,t))}forEachBlock(t,e=!1){const o=this.document.slice();e&&o.reverse();function r(s){for(const i of s){if(t(i)===!1)return!1;const c=e?i.children.slice().reverse():i.children;if(!r(c))return!1}return!0}r(o)}insertBlocks(t,e,o="before"){return this.editor.transact(r=>Ke(r,t,e,o))}updateBlock(t,e){return this.editor.transact(o=>d.updateBlock(o,t,e))}removeBlocks(t){return this.editor.transact(e=>ue(e,t,[]).removedBlocks)}replaceBlocks(t,e){return this.editor.transact(o=>ue(o,t,e))}canNestBlock(){return ln(this.editor)}nestBlock(){dt(this.editor)}canUnnestBlock(){return dn(this.editor)}unnestBlock(){cn(this.editor)}moveBlocksUp(){return zn(this.editor)}moveBlocksDown(){return Kn(this.editor)}}class Gn{constructor(t,e){u(this,"editor");u(this,"options");u(this,"_commentsPlugin");u(this,"_forkYDocPlugin");u(this,"_syncPlugin");u(this,"_undoPlugin");u(this,"_cursorPlugin");this.editor=t,this.options=e}get syncPlugin(){return this._syncPlugin}get undoPlugin(){return this._undoPlugin}get cursorPlugin(){return this._cursorPlugin}get forkYDocPlugin(){return this._forkYDocPlugin}initExtensions(){var e;const t={};if(this._syncPlugin=new ne(this.options.fragment),t.ySyncPlugin=this._syncPlugin,this._undoPlugin=new re({editor:this.editor}),t.yUndoPlugin=this._undoPlugin,(e=this.options.provider)!=null&&e.awareness&&(this._cursorPlugin=new Y(this.options),t.yCursorPlugin=this._cursorPlugin),this._forkYDocPlugin=new tt({editor:this.editor,collaboration:this.options}),t.forkYDocPlugin=this._forkYDocPlugin,this.options.comments){if(!this.options.resolveUsers)throw new Error("resolveUsers is required when using comments");this._commentsPlugin=new nt(this.editor,this.options.comments.threadStore,se.name,this.options.resolveUsers,this.options.comments.schema),t.comments=this._commentsPlugin,t.commentMark=se}return t}updateUserInfo(t){const e=this.cursorPlugin;if(!e)throw new Error("Cannot update collaboration user info when collaboration is disabled.");e.updateUser(t)}getUndoCommand(){return E.undoCommand}getRedoCommand(){return E.redoCommand}shouldAvoidInitialContent(){return!!this.options.provider}getOptions(){return this.options}get comments(){return this._commentsPlugin}get hasComments(){return!!this.options.comments}get resolveUsers(){return this.options.resolveUsers}}class jn extends d.EventEmitter{constructor(t){super(),this.editor=t,t.onCreate(()=>{t._tiptapEditor.on("update",({transaction:e,appendedTransactions:o})=>{this.emit("onChange",t,{getChanges(){return fe(e,o)}})}),t._tiptapEditor.on("selectionUpdate",({transaction:e})=>{this.emit("onSelectionChange",{editor:t,transaction:e})}),t._tiptapEditor.on("mount",()=>{this.emit("onMount",{editor:t})}),t._tiptapEditor.on("unmount",()=>{this.emit("onUnmount",{editor:t})})})}onChange(t){return this.on("onChange",t),()=>{this.off("onChange",t)}}onSelectionChange(t,e=!1){const o=r=>{r.transaction.getMeta("$y-sync")&&!e||t(this.editor)};return this.on("onSelectionChange",o),()=>{this.off("onSelectionChange",o)}}onMount(t){return this.on("onMount",t),()=>{this.off("onMount",t)}}onUnmount(t){return this.on("onUnmount",t),()=>{this.off("onUnmount",t)}}}function Wn(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function Yn(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function Xn(n){n.querySelectorAll("li > ul, li > ol").forEach(t=>{const e=Wn(t),o=t.parentElement,r=Array.from(o.childNodes).slice(e+1);t.remove(),r.forEach(s=>{s.remove()}),o.insertAdjacentElement("afterend",t),r.reverse().forEach(s=>{if(Yn(s))return;const i=document.createElement("li");i.append(s),t.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function Jn(n){n.querySelectorAll("li + ul, li + ol").forEach(t=>{var s,i;const e=t.previousElementSibling,o=document.createElement("div");e.insertAdjacentElement("afterend",o),o.append(e);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),o.append(r);((s=o.nextElementSibling)==null?void 0:s.nodeName)==="UL"||((i=o.nextElementSibling)==null?void 0:i.nodeName)==="OL";)r.append(o.nextElementSibling)})}let Fe=null;function Qn(){return Fe||(Fe=document.implementation.createHTMLDocument("title"))}function Zn(n){if(typeof n=="string"){const t=Qn().createElement("div");t.innerHTML=n,n=t}return Xn(n),Jn(n),n}function ye(n,t){const e=Zn(n),r=T.DOMParser.fromSchema(t).parse(e,{topNode:t.nodes.blockGroup.create()}),s=[];for(let i=0;i<r.childCount;i++)s.push(m.nodeToBlock(r.child(i),t));return s}function er(n,t){const e=t.value?t.value:"",o={};t.lang&&(o["data-language"]=t.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:e}]};return t.meta&&(r.data={meta:t.meta}),n.patch(t,r),r=n.applyData(t,r),r={type:"element",tagName:"pre",properties:{},children:[r]},n.patch(t,r),r}function tr(n,t){var s;const e=String((t==null?void 0:t.url)||""),o=t!=null&&t.title?String(t.title):void 0;let r={type:"element",tagName:"video",properties:{src:e,"data-name":o,"data-url":e,controls:!0},children:[]};return(s=n.patch)==null||s.call(n,t,r),r=n.applyData?n.applyData(t,r):r,r}function we(n){return Ve.unified().use(mo.default).use($e.default).use(fo.default,{handlers:{...de.defaultHandlers,image:(e,o)=>{const r=String((o==null?void 0:o.url)||"");return d.isVideoUrl(r)?tr(e,o):de.defaultHandlers.image(e,o)},code:er}}).use(go.default).processSync(n).value}function Nt(n,t){const e=we(n);return ye(e,t)}class or{constructor(t){this.editor=t}blocksToHTMLLossy(t=this.editor.document){return X(this.editor.pmSchema,this.editor).exportBlocks(t,{})}blocksToFullHTML(t=this.editor.document){return Je(this.editor.pmSchema,this.editor).serializeBlocks(t,{})}tryParseHTMLToBlocks(t){return ye(t,this.editor.pmSchema)}blocksToMarkdownLossy(t=this.editor.document){return Ze(t,this.editor.pmSchema,this.editor,{})}tryParseMarkdownToBlocks(t){return Nt(t,this.editor.pmSchema)}pasteHTML(t,e=!1){var r;let o=t;if(!e){const s=this.tryParseHTMLToBlocks(t);o=this.blocksToFullHTML(s)}o&&((r=this.editor.prosemirrorView)==null||r.pasteHTML(o))}pasteText(t){var e;return(e=this.editor.prosemirrorView)==null?void 0:e.pasteText(t)}pasteMarkdown(t){const e=we(t);return this.pasteHTML(e)}}class nr{constructor(t){this.editor=t}extension(t,e=t.key()){const o=this.editor.extensions[e];if(!o)throw new Error(`Extension ${e} not found`);return o}getExtensions(){return this.editor.extensions}getExtension(t){return this.editor.extensions[t]}hasExtension(t){return t in this.editor.extensions}get formattingToolbar(){return this.editor.extensions.formattingToolbar}get linkToolbar(){return this.editor.extensions.linkToolbar}get sideMenu(){return this.editor.extensions.sideMenu}get suggestionMenus(){return this.editor.extensions.suggestionMenus}get filePanel(){return this.editor.extensions.filePanel}get tableHandles(){return this.editor.extensions.tableHandles}get showSelectionPlugin(){return this.editor.extensions.showSelection}get isCollaborationEnabled(){return this.hasExtension("ySyncPlugin")||this.hasExtension("liveblocksExtension")}}function rr(n){const t=m.getPmSchema(n);if(n.selection.empty||"node"in n.selection)return;const e=n.doc.resolve(m.getNearestBlockPos(n.doc,n.selection.from).posBeforeNode),o=n.doc.resolve(m.getNearestBlockPos(n.doc,n.selection.to).posBeforeNode),r=(l,h)=>{const p=e.posAtIndex(l,h),k=n.doc.resolve(p).nodeAfter;if(!k)throw new Error(`Error getting selection - node not found at position ${p}`);return m.nodeToBlock(k,t)},s=[],i=e.sharedDepth(o.pos),c=e.index(i),a=o.index(i);if(e.depth>i){s.push(m.nodeToBlock(e.nodeAfter,t));for(let l=e.depth;l>i;l--)if(e.node(l).type.isInGroup("childContainer")){const p=e.index(l)+1,k=e.node(l).childCount;for(let g=p;g<k;g++)s.push(r(g,l))}}else s.push(r(c,i));for(let l=c+1;l<=a;l++)s.push(r(l,i));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${n.selection})`);return{blocks:s}}function sr(n,t,e){const o=typeof t=="string"?t:t.id,r=typeof e=="string"?e:e.id,s=m.getPmSchema(n),i=m.getBlockNoteSchema(s);if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const c=d.getNodeById(o,n.doc);if(!c)throw new Error(`Block with ID ${o} not found`);const a=d.getNodeById(r,n.doc);if(!a)throw new Error(`Block with ID ${r} not found`);const l=m.getBlockInfo(c),h=m.getBlockInfo(a),p=i.blockSchema[l.blockNoteType],k=i.blockSchema[h.blockNoteType];if(!l.isBlockContainer||p.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!h.isBlockContainer||k.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let g,b;if(p.content==="table"){const f=N.TableMap.get(l.blockContent.node);g=l.blockContent.beforePos+f.positionAt(0,0,l.blockContent.node)+1+2}else g=l.blockContent.beforePos+1;if(k.content==="table"){const f=N.TableMap.get(h.blockContent.node),y=h.blockContent.beforePos+f.positionAt(f.height-1,f.width-1,h.blockContent.node)+1,w=n.doc.resolve(y).nodeAfter.nodeSize;b=y+w-2}else b=h.blockContent.afterPos-1;n.setSelection(S.TextSelection.create(n.doc,g,b))}function ir(n){const t=m.getPmSchema(n);let e=n.selection.$from,o=n.selection.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=n.doc.resolve(o.pos+1);for(;o.parentOffset===0&&o.depth>0;)o=n.doc.resolve(o.pos-1);for(;e.parentOffset===0&&e.depth>0;)e=n.doc.resolve(e.pos-1);for(;e.parentOffset>=e.parent.nodeSize-2&&e.depth>0;)e=n.doc.resolve(e.pos+1);const r=m.prosemirrorSliceToSlicedBlocks(n.doc.slice(e.pos,o.pos,!0),t);return{_meta:{startPos:e.pos,endPos:o.pos},...r}}function ar(n){const{bnBlock:t}=m.getBlockInfoFromTransaction(n),e=m.getPmSchema(n.doc),o=n.doc.resolve(t.beforePos),r=o.nodeBefore,s=n.doc.resolve(t.afterPos).nodeAfter;let i;return o.depth>1&&(i=o.node(),i.type.isInGroup("bnBlock")||(i=o.node(o.depth-1))),{block:m.nodeToBlock(t.node,e),prevBlock:r===null?void 0:m.nodeToBlock(r,e),nextBlock:s===null?void 0:m.nodeToBlock(s,e),parentBlock:i===void 0?void 0:m.nodeToBlock(i,e)}}function At(n,t,e="start"){const o=typeof t=="string"?t:t.id,r=m.getPmSchema(n.doc),s=m.getBlockNoteSchema(r),i=d.getNodeById(o,n.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const c=m.getBlockInfo(i),a=s.blockSchema[c.blockNoteType].content;if(c.isBlockContainer){const l=c.blockContent;if(a==="none"){n.setSelection(S.NodeSelection.create(n.doc,l.beforePos));return}if(a==="inline")e==="start"?n.setSelection(S.TextSelection.create(n.doc,l.beforePos+1)):n.setSelection(S.TextSelection.create(n.doc,l.afterPos-1));else if(a==="table")e==="start"?n.setSelection(S.TextSelection.create(n.doc,l.beforePos+4)):n.setSelection(S.TextSelection.create(n.doc,l.afterPos-4));else throw new m.UnreachableCaseError(a)}else{const l=e==="start"?c.childContainer.node.firstChild:c.childContainer.node.lastChild;At(n,l.attrs.id,e)}}class cr{constructor(t){this.editor=t}getSelection(){return this.editor.transact(t=>rr(t))}getSelectionCutBlocks(){return this.editor.transact(t=>ir(t))}setSelection(t,e){return this.editor.transact(o=>sr(o,t,e))}getTextCursorPosition(){return this.editor.transact(t=>ar(t))}setTextCursorPosition(t,e="start"){return this.editor.transact(o=>At(o,t,e))}getSelectionBoundingBox(){if(!this.editor.prosemirrorView)return;const{selection:t}=this.editor.prosemirrorState,{ranges:e}=t,o=Math.min(...e.map(s=>s.$from.pos)),r=Math.max(...e.map(s=>s.$to.pos));if(B.isNodeSelection(t)){const s=this.editor.prosemirrorView.nodeDOM(o);if(s)return s.getBoundingClientRect()}return B.posToDOMRect(this.editor.prosemirrorView,o,r)}}class lr{constructor(t,e){u(this,"activeTransaction",null);u(this,"isInCan",!1);this.editor=t,this.options=e}can(t){try{return this.isInCan=!0,t()}finally{this.isInCan=!1}}exec(t){if(this.activeTransaction)throw new 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(t);const e=this.prosemirrorState,o=this.prosemirrorView;return t(e,s=>this.prosemirrorView.dispatch(s),o)}canExec(t){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const e=this.prosemirrorState,o=this.prosemirrorView;return t(e,void 0,o)}transact(t){if(this.activeTransaction)return t(this.activeTransaction);try{this.activeTransaction=this.editor._tiptapEditor.state.tr;const e=t(this.activeTransaction),o=this.activeTransaction;return this.activeTransaction=null,o&&(o.docChanged||o.selectionSet||o.scrolledIntoView||o.storedMarksSet||!o.isGeneric)&&this.prosemirrorView.dispatch(o),e}finally{this.activeTransaction=null}}get prosemirrorState(){if(this.activeTransaction)throw new 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(){var t;return((t=this.prosemirrorView)==null?void 0:t.hasFocus())||!1}focus(){var t;(t=this.prosemirrorView)==null||t.focus()}get isEditable(){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new Error("no editor, but also not headless?");return!1}return this.editor._tiptapEditor.isEditable===void 0?!0:this.editor._tiptapEditor.isEditable}set isEditable(t){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new Error("no editor, but also not headless?");return}this.editor._tiptapEditor.options.editable!==t&&this.editor._tiptapEditor.setEditable(t)}undo(){var t;return this.exec(((t=this.options)==null?void 0:t.undo)??Me.undo)}redo(){var t;return this.exec(((t=this.options)==null?void 0:t.redo)??Me.redo)}}function dr(n,t,e,o={updateSelection:!0}){let{from:r,to:s}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},i=!0,c=!0,a="";if(e.forEach(l=>{l.check(),i&&l.isText&&l.marks.length===0?a+=l.text:i=!1,c=c?l.isBlock:!1}),r===s&&c){const{parent:l}=n.doc.resolve(r);l.isTextblock&&!l.type.spec.code&&!l.childCount&&(r-=1,s+=1)}return i?n.insertText(a,r,s):n.replaceWith(r,s,e),o.updateSelection&&B.selectionToInsertionEnd(n,n.steps.length-1,-1),!0}class ur{constructor(t){this.editor=t}insertInlineContent(t,{updateSelection:e=!1}={}){const o=m.inlineContentToNodes(t,this.editor.pmSchema);this.editor.transact(r=>{dr(r,{from:r.selection.from,to:r.selection.to},o,{updateSelection:e})})}getActiveStyles(){return this.editor.transact(t=>{const e={},o=t.selection.$to.marks();for(const r of o){const s=this.editor.schema.styleSchema[r.type.name];if(!s){r.type.name!=="link"&&!r.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",r.type.name);continue}s.propSchema==="boolean"?e[s.type]=!0:e[s.type]=r.attrs.stringValue}return e})}addStyles(t){for(const[e,o]of Object.entries(t)){const r=this.editor.schema.styleSchema[e];if(!r)throw new Error(`style ${e} not found in styleSchema`);if(r.propSchema==="boolean")this.editor._tiptapEditor.commands.setMark(e);else if(r.propSchema==="string")this.editor._tiptapEditor.commands.setMark(e,{stringValue:o});else throw new m.UnreachableCaseError(r.propSchema)}}removeStyles(t){for(const e of Object.keys(t))this.editor._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){for(const[e,o]of Object.entries(t)){const r=this.editor.schema.styleSchema[e];if(!r)throw new Error(`style ${e} not found in styleSchema`);if(r.propSchema==="boolean")this.editor._tiptapEditor.commands.toggleMark(e);else if(r.propSchema==="string")this.editor._tiptapEditor.commands.toggleMark(e,{stringValue:o});else throw new m.UnreachableCaseError(r.propSchema)}}getSelectedText(){return this.editor.transact(t=>t.doc.textBetween(t.selection.from,t.selection.to))}getSelectedLinkUrl(){return this.editor._tiptapEditor.getAttributes("link").href}createLink(t,e){if(t==="")return;const o=this.editor.pmSchema.mark("link",{href:t});this.editor.transact(r=>{const{from:s,to:i}=r.selection;e?r.insertText(e,s,i).addMark(s,s+e.length,o):r.setSelection(S.TextSelection.create(r.doc,i)).addMark(s,i,o)})}}function hr(n,t){const e=[];return n.forEach((o,r,s)=>{s!==t&&e.push(o)}),T.Fragment.from(e)}function pr(n,t){const e=[];for(let o=0;o<n.childCount;o++)if(n.child(o).type.name==="tableRow")if(e.length>0&&e[e.length-1].type.name==="table"){const r=e[e.length-1],s=r.copy(r.content.addToEnd(n.child(o)));e[e.length-1]=s}else{const r=t.nodes.table.createChecked(void 0,n.child(o));e.push(r)}else e.push(n.child(o));return n=T.Fragment.from(e),n}function mr(n,t){let e=T.Fragment.from(n.content);if(e=pr(e,t.state.schema),!fr(e,t))return new T.Slice(e,n.openStart,n.openEnd);for(let o=0;o<e.childCount;o++)if(e.child(o).type.spec.group==="blockContent"){const r=[e.child(o)];if(o+1<e.childCount&&e.child(o+1).type.name==="blockGroup"){const i=e.child(o+1).child(0).child(0);(i.type.name==="bulletListItem"||i.type.name==="numberedListItem"||i.type.name==="checkListItem")&&(r.push(e.child(o+1)),e=hr(e,o+1))}const s=t.state.schema.nodes.blockContainer.createChecked(void 0,r);e=e.replaceChild(o,s)}return new T.Slice(e,n.openStart,n.openEnd)}function fr(n,t){var s,i;const e=n.childCount===1,o=((s=n.firstChild)==null?void 0:s.type.spec.content)==="inline*",r=((i=n.firstChild)==null?void 0:i.type.spec.content)==="tableRow+";if(e){if(o)return!1;if(r){const c=m.getBlockInfoFromSelection(t.state);if(c.isBlockContainer)return!(c.blockContent.node.type.spec.content==="tableRow+")}}return!0}const gr={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Se extends d.EventEmitter{constructor(e){var p,k,g,b,f,y,w,C,_,U,K,q,G,j,x,I,Ce,Be,ve;super();u(this,"pmSchema");u(this,"extensions",{});u(this,"_tiptapEditor");u(this,"elementRenderer",null);u(this,"blockCache",new WeakMap);u(this,"dictionary");u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"uploadFile");u(this,"onUploadStartCallbacks",[]);u(this,"onUploadEndCallbacks",[]);u(this,"resolveFileUrl");u(this,"resolveUsers");u(this,"settings");u(this,"_blockManager");u(this,"_collaborationManager");u(this,"_eventManager");u(this,"_exportManager");u(this,"_extensionManager");u(this,"_selectionManager");u(this,"_stateManager");u(this,"_styleManager");u(this,"mount",e=>{this._tiptapEditor.mount({mount:e})});u(this,"unmount",()=>{this._tiptapEditor.unmount()});this.options=e;const o=e;if(o.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(o.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(o.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(o.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=e.dictionary||so.en,this.settings={tables:{splitCells:((p=e==null?void 0:e.tables)==null?void 0:p.splitCells)??!1,cellBackgroundColor:((k=e==null?void 0:e.tables)==null?void 0:k.cellBackgroundColor)??!1,cellTextColor:((g=e==null?void 0:e.tables)==null?void 0:g.cellTextColor)??!1,headers:((b=e==null?void 0:e.tables)==null?void 0:b.headers)??!1}};const r={defaultStyles:!0,schema:e.schema||d.BlockNoteSchema.create(),...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(r.collaboration||r.comments){const v={fragment:((f=r.collaboration)==null?void 0:f.fragment)||new H.XmlFragment,user:((y=r.collaboration)==null?void 0:y.user)||{name:"User",color:"#FF0000"},provider:((w=r.collaboration)==null?void 0:w.provider)||null,renderCursor:(C=r.collaboration)==null?void 0:C.renderCursor,showCursorLabels:(_=r.collaboration)==null?void 0:_.showCursorLabels,comments:r.comments,resolveUsers:r.resolveUsers};this._collaborationManager=new Gn(this,v)}else this._collaborationManager=void 0;if(r.comments&&!r.resolveUsers)throw new Error("resolveUsers is required when using comments");this.schema=r.schema,this.blockImplementations=r.schema.blockSpecs,this.inlineContentImplementations=r.schema.inlineContentSpecs,this.styleImplementations=r.schema.styleSpecs,this.extensions={...vt({editor:this,domAttributes:r.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:r.collaboration,trailingBlock:r.trailingBlock,disableExtensions:r.disableExtensions,setIdAttribute:r.setIdAttribute,animations:r.animations??!0,tableHandles:d.editorHasBlockWithType(this,"table"),dropCursor:this.options.dropCursor??Gt.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,pasteHandler:r.pasteHandler}),...(U=this._collaborationManager)==null?void 0:U.initExtensions()},(((K=r._tiptapOptions)==null?void 0:K.extensions)||[]).forEach(v=>{this.extensions[v.name]=v});for(let v of r.extensions||[]){typeof v=="function"&&(v=v(this));const P=v.key??v.constructor.key();if(!P)throw new Error(`Extension ${v.constructor.name} does not have a key method`);if(this.extensions[P])throw new Error(`Extension ${v.constructor.name} already exists with key ${P}`);this.extensions[P]=v}if(Object.entries(r._extensions||{}).forEach(([v,P])=>{const D=typeof P=="function"?P(this):P;if(!("plugin"in D)){this.extensions[v]=D;return}this.extensions[v]=new class extends d.BlockNoteExtension{static key(){return v}constructor(){super(),this.addProsemirrorPlugin(D.plugin)}get priority(){return D.priority}}}),r.uploadFile){const v=r.uploadFile;this.uploadFile=async(P,L)=>{this.onUploadStartCallbacks.forEach(D=>D.apply(this,[L]));try{return await v(P,L)}finally{this.onUploadEndCallbacks.forEach(D=>D.apply(this,[L]))}}}this.resolveFileUrl=r.resolveFileUrl;const s="ySyncPlugin"in this.extensions||"liveblocksExtension"in this.extensions;s&&r.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const i=Object.fromEntries(Object.values(this.schema.blockSpecs).map(v=>v.extensions).filter(v=>v!==void 0).flat().map(v=>[v.key??v.constructor.key(),v])),c=[...Object.entries({...this.extensions,...i}).map(([v,P])=>{if(P instanceof B.Extension||P instanceof B.Node||P instanceof B.Mark)return P;if(P instanceof d.BlockNoteExtension)return!P.plugins.length&&!P.keyboardShortcuts&&!P.inputRules&&!P.tiptapExtensions?void 0:B.Extension.create({name:v,priority:P.priority,addProseMirrorPlugins:()=>P.plugins,addExtensions:()=>P.tiptapExtensions||[],addInputRules:P.inputRules?()=>P.inputRules.map(L=>new B.InputRule({find:L.find,handler:({range:D,match:ae,state:Pe})=>{const Te=L.replace({match:ae,range:D,editor:this});if(Te){const _t=this.getTextCursorPosition();if(this.schema.blockSchema[_t.block.type].content!=="inline")return;const Ot=m.getBlockInfoFromTransaction(Pe.tr),Ht=Pe.tr.deleteRange(D.from,D.to);d.updateBlockTr(Ht,Ot.bnBlock.beforePos,Te);return}return null}})):void 0,addKeyboardShortcuts:P.keyboardShortcuts?()=>Object.fromEntries(Object.entries(P.keyboardShortcuts).map(([L,D])=>[L,()=>D({editor:this})])):void 0})})].filter(v=>v!==void 0),a={...gr,...r._tiptapOptions,element:null,autofocus:r.autofocus??!1,extensions:c,editorProps:{...(q=r._tiptapOptions)==null?void 0:q.editorProps,attributes:{tabIndex:"0",...(j=(G=r._tiptapOptions)==null?void 0:G.editorProps)==null?void 0:j.attributes,...(x=r.domAttributes)==null?void 0:x.editor,class:d.mergeCSSClasses("bn-editor",r.defaultStyles?"bn-default-styles":"",((Ce=(I=r.domAttributes)==null?void 0:I.editor)==null?void 0:Ce.class)||"")},transformPasted:mr}};try{const v=r.initialContent||(s?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:m.UniqueID.options.generateID()}]);if(!Array.isArray(v)||v.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+v);const P=B.getSchema(a.extensions),L=v.map(ae=>m.blockToNode(ae,P,this.schema.styleSchema).toJSON()),D=B.createDocument({type:"doc",content:[{type:"blockGroup",content:L}]},P,a.parseOptions);this._tiptapEditor=new B.Editor({...a,content:D.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(v){throw new Error("Error creating document from blocks passed as `initialContent`",{cause:v})}let l;const h=this.pmSchema.nodes.doc.createAndFill;this.pmSchema.nodes.doc.createAndFill=(...v)=>{if(l)return l;const P=h.apply(this.pmSchema.nodes.doc,v),L=JSON.parse(JSON.stringify(P.toJSON()));return L.content[0].content[0].attrs.id="initialBlockId",l=T.Node.fromJSON(this.pmSchema,L),l},this.pmSchema.cached.blockNoteEditor=this,this._blockManager=new qn(this),this._eventManager=new jn(this),this._exportManager=new or(this),this._extensionManager=new nr(this),this._selectionManager=new cr(this),this._stateManager=new lr(this,s?{undo:(Be=this._collaborationManager)==null?void 0:Be.getUndoCommand(),redo:(ve=this._collaborationManager)==null?void 0:ve.getRedoCommand()}:void 0),this._styleManager=new ur(this),this.emit("create")}get formattingToolbar(){return this._extensionManager.formattingToolbar}get linkToolbar(){return this._extensionManager.linkToolbar}get sideMenu(){return this._extensionManager.sideMenu}get suggestionMenus(){return this._extensionManager.suggestionMenus}get filePanel(){return this._extensionManager.filePanel}get tableHandles(){return this._extensionManager.tableHandles}get comments(){var e;return(e=this._collaborationManager)==null?void 0:e.comments}get showSelectionPlugin(){return this._extensionManager.showSelectionPlugin}get forkYDocPlugin(){var e;return(e=this._collaborationManager)==null?void 0:e.forkYDocPlugin}static create(e){return new Se(e??{})}exec(e){return this._stateManager.exec(e)}canExec(e){return this._stateManager.canExec(e)}transact(e){return this._stateManager.transact(e)}extension(e,o=e.key()){return this._extensionManager.extension(e,o)}get prosemirrorState(){return this._stateManager.prosemirrorState}get prosemirrorView(){return this._stateManager.prosemirrorView}get domElement(){var e;return(e=this.prosemirrorView)==null?void 0:e.dom}isFocused(){var e;return((e=this.prosemirrorView)==null?void 0:e.hasFocus())||!1}get headless(){return!this._tiptapEditor.isInitialized}focus(){this.headless||this.prosemirrorView.focus()}blur(){this.headless||this.prosemirrorView.dom.blur()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{const o=this.onUploadStartCallbacks.indexOf(e);o>-1&&this.onUploadStartCallbacks.splice(o,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{const o=this.onUploadEndCallbacks.indexOf(e);o>-1&&this.onUploadEndCallbacks.splice(o,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,o=!1){this._blockManager.forEachBlock(e,o)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){return this._selectionManager.getTextCursorPosition()}setTextCursorPosition(e,o="start"){return this._selectionManager.setTextCursorPosition(e,o)}getSelection(){return this._selectionManager.getSelection()}getSelectionCutBlocks(){return this._selectionManager.getSelectionCutBlocks()}setSelection(e,o){return this._selectionManager.setSelection(e,o)}get isEditable(){return this._stateManager.isEditable}set isEditable(e){this._stateManager.isEditable=e}insertBlocks(e,o,r="before"){return this._blockManager.insertBlocks(e,o,r)}updateBlock(e,o){return this._blockManager.updateBlock(e,o)}removeBlocks(e){return this._blockManager.removeBlocks(e)}replaceBlocks(e,o){return this._blockManager.replaceBlocks(e,o)}undo(){return this._stateManager.undo()}redo(){return this._stateManager.redo()}insertInlineContent(e,{updateSelection:o=!1}={}){this._styleManager.insertInlineContent(e,{updateSelection:o})}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,o){this._styleManager.createLink(e,o)}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)}updateCollaborationUserInfo(e){if(!this._collaborationManager)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._collaborationManager.updateUserInfo(e)}onChange(e){return this._eventManager.onChange(e)}onSelectionChange(e,o){return this._eventManager.onSelectionChange(e,o)}onCreate(e){return this.on("create",e),()=>{this.off("create",e)}}onMount(e){this._eventManager.onMount(e)}onUnmount(e){this._eventManager.onUnmount(e)}getSelectionBoundingBox(){return this._selectionManager.getSelectionBoundingBox()}get isEmpty(){const e=this.document;return e.length===0||e.length===1&&e[0].type==="paragraph"&&e[0].content.length===0}openSuggestionMenu(e,o){this.prosemirrorView&&(this.focus(),this.transact(r=>{o!=null&&o.deleteTriggerCharacter&&r.insertText(e),r.scrollIntoView().setMeta(this.suggestionMenus.plugins[0],{triggerCharacter:e,deleteTriggerCharacter:(o==null?void 0:o.deleteTriggerCharacter)||!1,ignoreQueryLength:(o==null?void 0:o.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(e){this.showSelectionPlugin.setEnabled(e)}pasteHTML(e,o=!1){this._exportManager.pasteHTML(e,o)}pasteText(e){return this._exportManager.pasteText(e)}pasteMarkdown(e){return this._exportManager.pasteMarkdown(e)}}class kr{constructor(t,e,o){this.mappings=e,this.options=o}async resolveFile(t){var o;if(!((o=this.options)!=null&&o.resolveFileUrl))return(await fetch(t)).blob();const e=await this.options.resolveFileUrl(t);return e instanceof Blob?e:(await fetch(e)).blob()}mapStyles(t){return Object.entries(t).map(([o,r])=>this.mappings.styleMapping[o](r,this))}mapInlineContent(t){return this.mappings.inlineContentMapping[t.type](t,this)}transformInlineContent(t){return t.map(e=>this.mapInlineContent(e))}async mapBlock(t,e,o,r){return this.mappings.blockMapping[t.type](t,this,e,o,r)}}function br(n){return{createBlockMapping:t=>t,createInlineContentMapping:t=>t,createStyleMapping:t=>t}}let ee;async function yr(){return ee||(ee=(async()=>{const[n,t]=await Promise.all([import("emoji-mart"),import("@emoji-mart/data")]),e="default"in n?n.default:n,o="default"in t?t.default:t;return await e.init({data:o}),{emojiMart:e,emojiData:o}})(),ee)}async function wr(n,t){if(!("text"in n.schema.inlineContentSchema)||n.schema.inlineContentSchema.text!==d.defaultInlineContentSchema.text)return[];const{emojiData:e,emojiMart:o}=await yr();return(t.trim()===""?Object.values(e.emojis):await o.SearchIndex.search(t)).map(s=>({id:s.skins[0].native,onItemClick:()=>n.insertInlineContent(s.skins[0].native+" ")}))}function Sr(n,...t){const e=[...n];for(const o of t)for(const r of o){const s=e.findLastIndex(i=>i.group===r.group);s===-1?e.push(r):e.splice(s+1,0,r)}return e}exports.UniqueID=m.UniqueID;exports.UnreachableCaseError=m.UnreachableCaseError;exports.assertEmpty=m.assertEmpty;exports.blockToNode=m.blockToNode;exports.contentNodeToInlineContent=m.contentNodeToInlineContent;exports.contentNodeToTableContent=m.contentNodeToTableContent;exports.docToBlocks=m.docToBlocks;exports.getBlockCache=m.getBlockCache;exports.getBlockInfo=m.getBlockInfo;exports.getBlockInfoFromResolvedPos=m.getBlockInfoFromResolvedPos;exports.getBlockInfoFromSelection=m.getBlockInfoFromSelection;exports.getBlockInfoFromTransaction=m.getBlockInfoFromTransaction;exports.getBlockInfoWithManualOffset=m.getBlockInfoWithManualOffset;exports.getBlockNoteSchema=m.getBlockNoteSchema;exports.getBlockSchema=m.getBlockSchema;exports.getColspan=m.getColspan;exports.getInlineContentSchema=m.getInlineContentSchema;exports.getNearestBlockPos=m.getNearestBlockPos;exports.getPmSchema=m.getPmSchema;exports.getRowspan=m.getRowspan;exports.getStyleSchema=m.getStyleSchema;exports.inlineContentToNodes=m.inlineContentToNodes;exports.isLinkInlineContent=m.isLinkInlineContent;exports.isPartialLinkInlineContent=m.isPartialLinkInlineContent;exports.isPartialTableCell=m.isPartialTableCell;exports.isStyledTextInlineContent=m.isStyledTextInlineContent;exports.isTableCell=m.isTableCell;exports.mapTableCell=m.mapTableCell;exports.nodeToBlock=m.nodeToBlock;exports.nodeToCustomInlineContent=m.nodeToCustomInlineContent;exports.prosemirrorSliceToSlicedBlocks=m.prosemirrorSliceToSlicedBlocks;exports.tableContentToNodes=m.tableContentToNodes;exports.BlockNoteExtension=d.BlockNoteExtension;exports.BlockNoteSchema=d.BlockNoteSchema;exports.COLORS_DARK_MODE_DEFAULT=d.COLORS_DARK_MODE_DEFAULT;exports.COLORS_DEFAULT=d.COLORS_DEFAULT;exports.CustomBlockNoteSchema=d.CustomBlockNoteSchema;exports.EMPTY_CELL_HEIGHT=d.EMPTY_CELL_HEIGHT;exports.EMPTY_CELL_WIDTH=d.EMPTY_CELL_WIDTH;exports.EventEmitter=d.EventEmitter;exports.FILE_AUDIO_ICON_SVG=d.FILE_AUDIO_ICON_SVG;exports.FILE_IMAGE_ICON_SVG=d.FILE_IMAGE_ICON_SVG;exports.FILE_VIDEO_ICON_SVG=d.FILE_VIDEO_ICON_SVG;exports.addDefaultPropsExternalHTML=d.addDefaultPropsExternalHTML;exports.addInlineContentAttributes=d.addInlineContentAttributes;exports.addInlineContentKeyboardShortcuts=d.addInlineContentKeyboardShortcuts;exports.addNodeAndExtensionsToSpec=d.addNodeAndExtensionsToSpec;exports.addStyleAttributes=d.addStyleAttributes;exports.applyNonSelectableBlockFix=d.applyNonSelectableBlockFix;exports.audioParse=d.audioParse;exports.audioRender=d.audioRender;exports.audioToExternalHTML=d.audioToExternalHTML;exports.blockHasType=d.blockHasType;exports.camelToDataKebab=d.camelToDataKebab;exports.captureCellAnchor=d.captureCellAnchor;exports.checkPageBreakBlocksInSchema=d.checkPageBreakBlocksInSchema;exports.createAudioBlockConfig=d.createAudioBlockConfig;exports.createAudioBlockSpec=d.createAudioBlockSpec;exports.createBlockConfig=d.createBlockConfig;exports.createBlockNoteExtension=d.createBlockNoteExtension;exports.createBlockSpec=d.createBlockSpec;exports.createBlockSpecFromTiptapNode=d.createBlockSpecFromTiptapNode;exports.createBulletListItemBlockConfig=d.createBulletListItemBlockConfig;exports.createBulletListItemBlockSpec=d.createBulletListItemBlockSpec;exports.createCheckListItemBlockSpec=d.createCheckListItemBlockSpec;exports.createCheckListItemConfig=d.createCheckListItemConfig;exports.createCodeBlockConfig=d.createCodeBlockConfig;exports.createCodeBlockSpec=d.createCodeBlockSpec;exports.createDefaultBlockDOMOutputSpec=d.createDefaultBlockDOMOutputSpec;exports.createDividerBlockConfig=d.createDividerBlockConfig;exports.createDividerBlockSpec=d.createDividerBlockSpec;exports.createFileBlockConfig=d.createFileBlockConfig;exports.createFileBlockSpec=d.createFileBlockSpec;exports.createHeadingBlockConfig=d.createHeadingBlockConfig;exports.createHeadingBlockSpec=d.createHeadingBlockSpec;exports.createImageBlockConfig=d.createImageBlockConfig;exports.createImageBlockSpec=d.createImageBlockSpec;exports.createInlineContentSpecFromTipTapNode=d.createInlineContentSpecFromTipTapNode;exports.createInternalInlineContentSpec=d.createInternalInlineContentSpec;exports.createInternalStyleSpec=d.createInternalStyleSpec;exports.createNumberedListItemBlockConfig=d.createNumberedListItemBlockConfig;exports.createNumberedListItemBlockSpec=d.createNumberedListItemBlockSpec;exports.createPageBreakBlockConfig=d.createPageBreakBlockConfig;exports.createPageBreakBlockSpec=d.createPageBreakBlockSpec;exports.createParagraphBlockConfig=d.createParagraphBlockConfig;exports.createParagraphBlockSpec=d.createParagraphBlockSpec;exports.createQuoteBlockConfig=d.createQuoteBlockConfig;exports.createQuoteBlockSpec=d.createQuoteBlockSpec;exports.createStyleSpec=d.createStyleSpec;exports.createStyleSpecFromTipTapMark=d.createStyleSpecFromTipTapMark;exports.createTableBlockSpec=d.createTableBlockSpec;exports.createToggleListItemBlockConfig=d.createToggleListItemBlockConfig;exports.createToggleListItemBlockSpec=d.createToggleListItemBlockSpec;exports.createToggleWrapper=d.createToggleWrapper;exports.createVideoBlockConfig=d.createVideoBlockConfig;exports.createVideoBlockSpec=d.createVideoBlockSpec;exports.defaultBlockSpecs=d.defaultBlockSpecs;exports.defaultBlockToHTML=d.defaultBlockToHTML;exports.defaultInlineContentSchema=d.defaultInlineContentSchema;exports.defaultInlineContentSpecs=d.defaultInlineContentSpecs;exports.defaultProps=d.defaultProps;exports.defaultStyleSchema=d.defaultStyleSchema;exports.defaultStyleSpecs=d.defaultStyleSpecs;exports.defaultToggledState=d.defaultToggledState;exports.editorHasBlockWithType=d.editorHasBlockWithType;exports.fileParse=d.fileParse;exports.filenameFromURL=d.filenameFromURL;exports.filterSuggestionItems=d.filterSuggestionItems;exports.formatKeyboardShortcut=d.formatKeyboardShortcut;exports.getBackgroundColorAttribute=d.getBackgroundColorAttribute;exports.getBlockFromPos=d.getBlockFromPos;exports.getDefaultSlashMenuItems=d.getDefaultSlashMenuItems;exports.getInlineContentSchemaFromSpecs=d.getInlineContentSchemaFromSpecs;exports.getLanguageId=d.getLanguageId;exports.getNodeById=d.getNodeById;exports.getPageBreakSlashMenuItems=d.getPageBreakSlashMenuItems;exports.getParseRules=d.getParseRules;exports.getStyleParseRules=d.getStyleParseRules;exports.getStyleSchemaFromSpecs=d.getStyleSchemaFromSpecs;exports.getTextAlignmentAttribute=d.getTextAlignmentAttribute;exports.getTextColorAttribute=d.getTextColorAttribute;exports.imageParse=d.imageParse;exports.imageRender=d.imageRender;exports.imageToExternalHTML=d.imageToExternalHTML;exports.insertOrUpdateBlock=d.insertOrUpdateBlock;exports.isAppleOS=d.isAppleOS;exports.isNodeBlock=d.isNodeBlock;exports.isSafari=d.isSafari;exports.isTableCellSelection=d.isTableCellSelection;exports.isVideoUrl=d.isVideoUrl;exports.mergeCSSClasses=d.mergeCSSClasses;exports.mergeParagraphs=d.mergeParagraphs;exports.parseAudioElement=d.parseAudioElement;exports.parseDefaultProps=d.parseDefaultProps;exports.propsToAttributes=d.propsToAttributes;exports.stylePropsToAttributes=d.stylePropsToAttributes;exports.tablePropSchema=d.tablePropSchema;exports.updateBlock=d.updateBlock;exports.updateBlockCommand=d.updateBlockCommand;exports.updateBlockTr=d.updateBlockTr;exports.uploadToTmpFilesDotOrg_DEV_ONLY=d.uploadToTmpFilesDotOrg_DEV_ONLY;exports.videoParse=d.videoParse;exports.withPageBreak=d.withPageBreak;exports.wrapInBlockStructure=d.wrapInBlockStructure;exports.BlockNoteEditor=Se;exports.DEFAULT_LINK_PROTOCOL=mt;exports.Exporter=kr;exports.FilePanelProsemirrorPlugin=st;exports.FilePanelView=rt;exports.FormattingToolbarProsemirrorPlugin=ct;exports.FormattingToolbarView=it;exports.HTMLToBlocks=ye;exports.LinkToolbarProsemirrorPlugin=ht;exports.SideMenuProsemirrorPlugin=yt;exports.SideMenuView=kt;exports.SuggestionMenuProseMirrorPlugin=St;exports.TableHandlesProsemirrorPlugin=Bt;exports.TableHandlesView=Ct;exports.VALID_LINK_PROTOCOLS=pt;exports.blocksToMarkdown=Ze;exports.cleanHTMLToMarkdown=ie;exports.combineByGroup=Sr;exports.createExternalHTMLExporter=X;exports.createInlineContentSpec=ko;exports.createInternalHTMLSerializer=Je;exports.createSuggestionMenu=Tn;exports.fixColumnList=oe;exports.formattingToolbarPluginKey=at;exports.getBlock=xt;exports.getBlockNoteExtensions=vt;exports.getBlocksChangedByTransaction=fe;exports.getDefaultEmojiPickerItems=wr;exports.getInlineContentParseRules=ze;exports.getNextBlock=Dt;exports.getParentBlock=Lt;exports.getPrevBlock=It;exports.insertBlocks=Ke;exports.isEmptyColumn=te;exports.linkToolbarPluginKey=ut;exports.mappingFactory=br;exports.markdownToBlocks=Nt;exports.markdownToHTML=we;exports.removeAndInsertBlocks=ue;exports.removeEmptyColumns=qe;exports.selectedFragmentToHTML=ke;exports.sideMenuPluginKey=bt;exports.tableHandlesPluginKey=V;exports.trackPosition=wt;
1
+ "use strict";var Ce=Object.defineProperty;var ye=(o,e,t)=>e in o?Ce(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var k=(o,e,t)=>ye(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("prosemirror-model"),A=require("prosemirror-transform"),u=require("./blockToNode-w7H99R6p.cjs"),c=require("./defaultBlocks-BxFclIGP.cjs"),S=require("./TrailingNode-CaT_wbho.cjs"),M=require("./BlockNoteSchema-D8TyvlfU.cjs"),B=require("@tiptap/core"),U=require("./EventEmitter-CLwfmbqG.cjs"),Te=require("./en-Cl87Uuyf.cjs"),W=require("@handlewithcare/prosemirror-inputrules"),Ee=require("prosemirror-keymap"),V=require("./BlockNoteExtension-BWw0r8Gy.cjs"),xe=require("@tiptap/extension-gapcursor"),Me=require("@tiptap/extension-link"),Pe=require("@tiptap/extension-text"),y=require("prosemirror-state"),N=require("prosemirror-tables"),Ie=require("./ShowSelection-BW37oJ6h.cjs"),we=require("remark-gfm"),ve=require("remark-parse"),F=require("remark-rehype"),Ne=require("rehype-stringify"),Ae=require("unified"),D=o=>o&&typeof o=="object"&&"default"in o?o:{default:o},Le=D(we),_e=D(ve),De=D(F),Fe=D(Ne);function te(o,e){const t=[{tag:`[data-inline-content-type="${o.type}"]`,contentElement:n=>{const r=n;return r.matches("[data-editable]")?r:r.querySelector("[data-editable]")||r}}];return e&&t.push({tag:"*",getAttrs(n){if(typeof n=="string")return!1;const r=e==null?void 0:e(n);return r===void 0?!1:r}}),t}function Oe(o,e){var n;const t=B.Node.create({name:o.type,inline:!0,group:"inline",draggable:(n=e.meta)==null?void 0:n.draggable,selectable:o.content==="styled",atom:o.content==="none",content:o.content==="styled"?"inline*":"",addAttributes(){return c.propsToAttributes(o.propSchema)},addKeyboardShortcuts(){return c.addInlineContentKeyboardShortcuts(o)},parseHTML(){return te(o,e.parse)},renderHTML({node:r}){const i=this.options.editor,s=e.render.call({renderType:"dom",props:void 0},u.nodeToCustomInlineContent(r,i.schema.inlineContentSchema,i.schema.styleSchema),()=>{},i);return c.addInlineContentAttributes(s,o.type,r.attrs,o.propSchema)},addNodeView(){return r=>{const{node:i,getPos:s}=r,l=this.options.editor,a=e.render.call({renderType:"nodeView",props:r},u.nodeToCustomInlineContent(i,l.schema.inlineContentSchema,l.schema.styleSchema),d=>{const p=u.inlineContentToNodes([d],l.pmSchema),f=s();f&&l.transact(h=>h.replaceWith(f,f+i.nodeSize,p))},l);return c.addInlineContentAttributes(a,o.type,i.attrs,o.propSchema)}}});return c.createInlineContentSpecFromTipTapNode(t,o.propSchema,{...e,toExternalHTML:e.toExternalHTML,render(r,i,s){const l=e.render(r,i,s);return c.addInlineContentAttributes(l,o.type,r.props,o.propSchema)}})}function oe(o,e,t,n="before"){const r=typeof t=="string"?t:t.id,i=u.getPmSchema(o),s=e.map(p=>u.blockToNode(p,i)),l=c.getNodeById(r,o.doc);if(!l)throw new Error(`Block with ID ${r} not found`);let a=l.posBeforeNode;return n==="after"&&(a+=l.node.nodeSize),o.step(new A.ReplaceStep(a,a,new T.Slice(T.Fragment.from(s),0,0))),s.map(p=>u.nodeToBlock(p,i))}function L(o){if(!o||o.type.name!=="column")throw new Error("Invalid columnPos: does not point to column node.");const e=o.firstChild;if(!e)throw new Error("Invalid column: does not have child node.");const t=e.firstChild;if(!t)throw new Error("Invalid blockContainer: does not have child node.");return o.childCount===1&&e.childCount===1&&t.type.name==="paragraph"&&t.content.content.length===0}function ne(o,e){const t=o.doc.resolve(e),n=t.nodeAfter;if(!n||n.type.name!=="columnList")throw new Error("Invalid columnListPos: does not point to columnList node.");for(let r=n.childCount-1;r>=0;r--){const i=o.doc.resolve(t.pos+1).posAtIndex(r),l=o.doc.resolve(i).nodeAfter;if(!l||l.type.name!=="column")throw new Error("Invalid columnPos: does not point to column node.");L(l)&&o.delete(i,i+l.nodeSize)}}function _(o,e){ne(o,e);const n=o.doc.resolve(e).nodeAfter;if(!n||n.type.name!=="columnList")throw new Error("Invalid columnListPos: does not point to columnList node.");if(n.childCount>2)return;if(n.childCount<2)throw new Error("Invalid columnList: contains fewer than two children.");const r=e+1,s=o.doc.resolve(r).nodeAfter,l=e+n.nodeSize-1,d=o.doc.resolve(l).nodeBefore;if(!s||!d)throw new Error("Invalid columnList: does not contain children.");const p=L(s),f=L(d);if(p&&f){o.delete(e,e+n.nodeSize);return}if(p){o.step(new A.ReplaceAroundStep(e,e+n.nodeSize,l-d.nodeSize+1,l-1,T.Slice.empty,0,!1));return}if(f){o.step(new A.ReplaceAroundStep(e,e+n.nodeSize,r+1,r+s.nodeSize-1,T.Slice.empty,0,!1));return}}function O(o,e,t){const n=u.getPmSchema(o),r=t.map(f=>u.blockToNode(f,n)),i=new Set(e.map(f=>typeof f=="string"?f:f.id)),s=[],l=new Set,a=typeof e[0]=="string"?e[0]:e[0].id;let d=0;if(o.doc.descendants((f,h)=>{if(i.size===0)return!1;if(!f.type.isInGroup("bnBlock")||!i.has(f.attrs.id))return!0;if(s.push(u.nodeToBlock(f,n)),i.delete(f.attrs.id),t.length>0&&f.attrs.id===a){const C=o.doc.nodeSize;o.insert(h,r);const E=o.doc.nodeSize;d+=C-E}const g=o.doc.nodeSize,m=o.doc.resolve(h-d);m.node().type.name==="column"?l.add(m.before(-1)):m.node().type.name==="columnList"&&l.add(m.before()),m.node().type.name==="blockGroup"&&m.node(m.depth-1).type.name!=="doc"&&m.node().childCount===1?o.delete(m.before(),m.after()):o.delete(h-d,h-d+f.nodeSize);const b=o.doc.nodeSize;return d+=g-b,!1}),i.size>0){const f=[...i].join(`
2
+ `);throw Error("Blocks with the following IDs could not be found in the editor: "+f)}return l.forEach(f=>_(o,f)),{insertedBlocks:r.map(f=>u.nodeToBlock(f,n)),removedBlocks:s}}function He(o,e,t,n,r){let i;if(e)if(typeof e=="string")i=u.inlineContentToNodes([e],o.pmSchema,n);else if(Array.isArray(e))i=u.inlineContentToNodes(e,o.pmSchema,n);else if(e.type==="tableContent")i=u.tableContentToNodes(e,o.pmSchema);else throw new u.UnreachableCaseError(e.type);else throw new Error("blockContent is required");const l=((r==null?void 0:r.document)??document).createDocumentFragment();for(const a of i)if(a.type.name!=="text"&&o.schema.inlineContentSchema[a.type.name]){const d=o.schema.inlineContentSpecs[a.type.name].implementation;if(d){const p=u.nodeToCustomInlineContent(a,o.schema.inlineContentSchema,o.schema.styleSchema),f=d.render.call({renderType:"dom",props:void 0},p,()=>{},o);if(f){if(l.appendChild(f.dom),f.contentDOM){const h=t.serializeFragment(a.content,r);f.contentDOM.dataset.editable="",f.contentDOM.appendChild(h)}continue}}}else if(a.type.name==="text"){let d=document.createTextNode(a.textContent);for(const p of a.marks.toReversed())if(p.type.name in o.schema.styleSpecs){const f=o.schema.styleSpecs[p.type.name].implementation.render(p.attrs.stringValue,o);f.contentDOM.appendChild(d),d=f.dom}else{const f=p.type.spec.toDOM(p,!0),h=T.DOMSerializer.renderSpec(document,f);h.contentDOM.appendChild(d),d=h.dom}l.appendChild(d)}else{const d=t.serializeFragment(T.Fragment.from([a]),r);l.appendChild(d)}return l}function $e(o,e,t,n){var f,h,g,m,b;const r=o.pmSchema.nodes.blockContainer,i=e.props||{};for(const[C,E]of Object.entries(o.schema.blockSchema[e.type].propSchema))!(C in i)&&E.default!==void 0&&(i[C]=E.default);const s=e.children||[],a=o.blockImplementations[e.type].implementation.render.call({renderType:"dom",props:void 0},{...e,props:i,children:s},o);if(a.contentDOM&&e.content){const C=He(o,e.content,t,e.type,n);a.contentDOM.appendChild(C)}if(o.pmSchema.nodes[e.type].isInGroup("bnBlock")){if(e.children&&e.children.length>0){const C=re(o,e.children,t,n);(f=a.contentDOM)==null||f.append(C)}return a.dom}const p=(g=(h=r.spec)==null?void 0:h.toDOM)==null?void 0:g.call(h,r.create({id:e.id,...i}));return(m=p.contentDOM)==null||m.appendChild(a.dom),e.children&&e.children.length>0&&((b=p.contentDOM)==null||b.appendChild(se(o,e.children,t,n))),p.dom}function re(o,e,t,n){const i=((n==null?void 0:n.document)??document).createDocumentFragment();for(const s of e){const l=$e(o,s,t,n);i.appendChild(l)}return i}const se=(o,e,t,n)=>{var l;const r=o.pmSchema.nodes.blockGroup,i=r.spec.toDOM(r.create({})),s=re(o,e,t,n);return(l=i.contentDOM)==null||l.appendChild(s),i.dom},ie=(o,e)=>{const t=T.DOMSerializer.fromSchema(o);return{serializeBlocks:(n,r)=>se(e,n,t,r).outerHTML}};function Ue(o){return o.transact(e=>{const t=u.getNearestBlockPos(e.doc,e.selection.anchor);if(e.selection instanceof N.CellSelection)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:e.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:e.selection.$headCell.pos-t.posBeforeNode};if(e.selection instanceof y.NodeSelection)return{type:"node",anchorBlockId:t.node.attrs.id};{const n=u.getNearestBlockPos(e.doc,e.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:n.node.attrs.id,anchorOffset:e.selection.anchor-t.posBeforeNode,headOffset:e.selection.head-n.posBeforeNode}}})}function Ve(o,e){var r,i;const t=(r=c.getNodeById(e.anchorBlockId,o.doc))==null?void 0:r.posBeforeNode;if(t===void 0)throw new Error(`Could not find block with ID ${e.anchorBlockId} to update selection`);let n;if(e.type==="cell")n=N.CellSelection.create(o.doc,t+e.anchorCellOffset,t+e.headCellOffset);else if(e.type==="node")n=y.NodeSelection.create(o.doc,t+1);else{const s=(i=c.getNodeById(e.headBlockId,o.doc))==null?void 0:i.posBeforeNode;if(s===void 0)throw new Error(`Could not find block with ID ${e.headBlockId} to update selection`);n=y.TextSelection.create(o.doc,t+e.anchorOffset,s+e.headOffset)}o.setSelection(n)}function H(o){return o.map(e=>e.type==="columnList"?e.children.map(t=>H(t.children)).flat():{...e,children:H(e.children)}).flat()}function ce(o,e,t){o.transact(n=>{var s;const r=((s=o.getSelection())==null?void 0:s.blocks)||[o.getTextCursorPosition().block],i=Ue(o);o.removeBlocks(r),o.insertBlocks(H(r),e,t),Ve(n,i)})}function ae(o){return!o||o.type!=="columnList"}function le(o,e,t){let n,r;if(e?e.children.length>0?(n=e.children[e.children.length-1],r="after"):(n=e,r="before"):t&&(n=t,r="before"),!n||!r)return;const i=o.getParentBlock(n);return ae(i)?{referenceBlock:n,placement:r}:le(o,r==="after"?n:o.getPrevBlock(n),i)}function de(o,e,t){let n,r;if(e?e.children.length>0?(n=e.children[0],r="before"):(n=e,r="after"):t&&(n=t,r="after"),!n||!r)return;const i=o.getParentBlock(n);return ae(i)?{referenceBlock:n,placement:r}:de(o,r==="before"?n:o.getNextBlock(n),i)}function Re(o){o.transact(()=>{const e=o.getSelection(),t=(e==null?void 0:e.blocks[0])||o.getTextCursorPosition().block,n=le(o,o.getPrevBlock(t),o.getParentBlock(t));n&&ce(o,n.referenceBlock,n.placement)})}function Ge(o){o.transact(()=>{const e=o.getSelection(),t=(e==null?void 0:e.blocks[(e==null?void 0:e.blocks.length)-1])||o.getTextCursorPosition().block,n=de(o,o.getNextBlock(t),o.getParentBlock(t));n&&ce(o,n.referenceBlock,n.placement)})}function ze(o,e,t){const{$from:n,$to:r}=o.selection,i=n.blockRange(r,m=>m.childCount>0&&(m.type.name==="blockGroup"||m.type.name==="column"));if(!i)return!1;const s=i.startIndex;if(s===0)return!1;const a=i.parent.child(s-1);if(a.type!==e)return!1;const d=a.lastChild&&a.lastChild.type===t,p=T.Fragment.from(d?e.create():null),f=new T.Slice(T.Fragment.from(e.create(null,T.Fragment.from(t.create(null,p)))),d?3:1,0),h=i.start,g=i.end;return o.step(new A.ReplaceAroundStep(h-(d?3:1),g,h,g,f,1,!0)).scrollIntoView(),!0}function ue(o){return o.transact(e=>ze(e,o.pmSchema.nodes.blockContainer,o.pmSchema.nodes.blockGroup))}function qe(o){o._tiptapEditor.commands.liftListItem("blockContainer")}function je(o){return o.transact(e=>{const{bnBlock:t}=u.getBlockInfoFromTransaction(e);return e.doc.resolve(t.beforePos).nodeBefore!==null})}function We(o){return o.transact(e=>{const{bnBlock:t}=u.getBlockInfoFromTransaction(e);return e.doc.resolve(t.beforePos).depth>1})}function pe(o,e){const t=typeof e=="string"?e:e.id,n=u.getPmSchema(o),r=c.getNodeById(t,o);if(r)return u.nodeToBlock(r.node,n)}function fe(o,e){const t=typeof e=="string"?e:e.id,n=c.getNodeById(t,o),r=u.getPmSchema(o);if(!n)return;const s=o.resolve(n.posBeforeNode).nodeBefore;if(s)return u.nodeToBlock(s,r)}function he(o,e){const t=typeof e=="string"?e:e.id,n=c.getNodeById(t,o),r=u.getPmSchema(o);if(!n)return;const s=o.resolve(n.posBeforeNode+n.node.nodeSize).nodeAfter;if(s)return u.nodeToBlock(s,r)}function me(o,e){const t=typeof e=="string"?e:e.id,n=u.getPmSchema(o),r=c.getNodeById(t,o);if(!r)return;const i=o.resolve(r.posBeforeNode),s=i.node(),l=i.node(-1),a=l.type.name!=="doc"?s.type.name==="blockGroup"?l:s:void 0;if(a)return u.nodeToBlock(a,n)}class Ke{constructor(e){this.editor=e}get document(){return this.editor.transact(e=>u.docToBlocks(e.doc,this.editor.pmSchema))}getBlock(e){return this.editor.transact(t=>pe(t.doc,e))}getPrevBlock(e){return this.editor.transact(t=>fe(t.doc,e))}getNextBlock(e){return this.editor.transact(t=>he(t.doc,e))}getParentBlock(e){return this.editor.transact(t=>me(t.doc,e))}forEachBlock(e,t=!1){const n=this.document.slice();t&&n.reverse();function r(i){for(const s of i){if(e(s)===!1)return!1;const l=t?s.children.slice().reverse():s.children;if(!r(l))return!1}return!0}r(n)}insertBlocks(e,t,n="before"){return this.editor.transact(r=>oe(r,e,t,n))}updateBlock(e,t){return this.editor.transact(n=>c.updateBlock(n,e,t))}removeBlocks(e){return this.editor.transact(t=>O(t,e,[]).removedBlocks)}replaceBlocks(e,t){return this.editor.transact(n=>O(n,e,t))}canNestBlock(){return je(this.editor)}nestBlock(){ue(this.editor)}canUnnestBlock(){return We(this.editor)}unnestBlock(){qe(this.editor)}moveBlocksUp(){return Re(this.editor)}moveBlocksDown(){return Ge(this.editor)}}class Ye extends U.EventEmitter{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){const n=({transaction:r,appendedTransactions:i})=>{!t&&K(r)||e(this.editor,{getChanges(){return S.getBlocksChangedByTransaction(r,i)}})};return this.on("onChange",n),()=>{this.off("onChange",n)}}onSelectionChange(e,t=!1){const n=r=>{!t&&K(r.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 K(o){return!!o.getMeta("y-sync$")}function Je(o){return Array.prototype.indexOf.call(o.parentElement.childNodes,o)}function Qe(o){return o.nodeType===3&&!/\S/.test(o.nodeValue||"")}function Xe(o){o.querySelectorAll("li > ul, li > ol").forEach(e=>{const t=Je(e),n=e.parentElement,r=Array.from(n.childNodes).slice(t+1);e.remove(),r.forEach(i=>{i.remove()}),n.insertAdjacentElement("afterend",e),r.reverse().forEach(i=>{if(Qe(i))return;const s=document.createElement("li");s.append(i),e.insertAdjacentElement("afterend",s)}),n.childNodes.length===0&&n.remove()})}function Ze(o){o.querySelectorAll("li + ul, li + ol").forEach(e=>{var i,s;const t=e.previousElementSibling,n=document.createElement("div");t.insertAdjacentElement("afterend",n),n.append(t);const r=document.createElement("div");for(r.setAttribute("data-node-type","blockGroup"),n.append(r);((i=n.nextElementSibling)==null?void 0:i.nodeName)==="UL"||((s=n.nextElementSibling)==null?void 0:s.nodeName)==="OL";)r.append(n.nextElementSibling)})}let Y=null;function et(){return Y||(Y=document.implementation.createHTMLDocument("title"))}function tt(o){if(typeof o=="string"){const e=et().createElement("div");e.innerHTML=o,o=e}return Xe(o),Ze(o),o}function R(o,e){const t=tt(o),r=T.DOMParser.fromSchema(e).parse(t,{topNode:e.nodes.blockGroup.create()}),i=[];for(let s=0;s<r.childCount;s++)i.push(u.nodeToBlock(r.child(s),e));return i}function ot(o,e){const t=e.value?e.value:"",n={};e.lang&&(n["data-language"]=e.lang);let r={type:"element",tagName:"code",properties:n,children:[{type:"text",value:t}]};return e.meta&&(r.data={meta:e.meta}),o.patch(e,r),r=o.applyData(e,r),r={type:"element",tagName:"pre",properties:{},children:[r]},o.patch(e,r),r}function nt(o,e){var i;const t=String((e==null?void 0:e.url)||""),n=e!=null&&e.title?String(e.title):void 0;let r={type:"element",tagName:"video",properties:{src:t,"data-name":n,"data-url":t,controls:!0},children:[]};return(i=o.patch)==null||i.call(o,e,r),r=o.applyData?o.applyData(e,r):r,r}function G(o){return Ae.unified().use(_e.default).use(Le.default).use(De.default,{handlers:{...F.defaultHandlers,image:(t,n)=>{const r=String((n==null?void 0:n.url)||"");return c.isVideoUrl(r)?nt(t,n):F.defaultHandlers.image(t,n)},code:ot}}).use(Fe.default).processSync(o).value}function ke(o,e){const t=G(o);return R(t,e)}class rt{constructor(e){this.editor=e}blocksToHTMLLossy(e=this.editor.document){return S.createExternalHTMLExporter(this.editor.pmSchema,this.editor).exportBlocks(e,{})}blocksToFullHTML(e=this.editor.document){return ie(this.editor.pmSchema,this.editor).serializeBlocks(e,{})}tryParseHTMLToBlocks(e){return R(e,this.editor.pmSchema)}blocksToMarkdownLossy(e=this.editor.document){return S.blocksToMarkdown(e,this.editor.pmSchema,this.editor,{})}tryParseMarkdownToBlocks(e){return ke(e,this.editor.pmSchema)}pasteHTML(e,t=!1){var r;let n=e;if(!t){const i=this.tryParseHTMLToBlocks(e);n=this.blocksToFullHTML(i)}n&&((r=this.editor.prosemirrorView)==null||r.pasteHTML(n))}pasteText(e){var t;return(t=this.editor.prosemirrorView)==null?void 0:t.pasteText(e)}pasteMarkdown(e){const t=G(e);return this.pasteHTML(t)}}const z=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function st(o,e){if(!o.startsWith(".")||!e.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return o===e}function it(o,e){const t=o.split("/"),n=e.split("/");if(t.length!==2)throw new Error(`The string ${o} is not a valid MIME type.`);if(n.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);return t[1]==="*"||n[1]==="*"?t[0]===n[0]:(t[0]==="*"||n[0]==="*"||t[0]===n[0])&&t[1]===n[1]}function J(o,e,t,n="after"){let r;return Array.isArray(e.content)&&e.content.length===0?r=o.updateBlock(e,t).id:r=o.insertBlocks([t],e,n)[0].id,r}async function ge(o,e){var i;if(!e.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const t="dataTransfer"in o?o.dataTransfer:o.clipboardData;if(t===null)return;let n=null;for(const s of z)if(t.types.includes(s)){n=s;break}if(n!=="Files")return;const r=t.items;if(r){o.preventDefault();for(let s=0;s<r.length;s++){let l="file";for(const d of Object.values(e.schema.blockSpecs))for(const p of((i=d.implementation.meta)==null?void 0:i.fileBlockAccept)||[]){const f=p.startsWith("."),h=r[s].getAsFile();if(h&&(!f&&h.type&&it(r[s].type,p)||f&&st("."+h.name.split(".").pop(),p))){l=d.config.type;break}}const a=r[s].getAsFile();if(a){const d={type:l,props:{name:a.name}};let p;if(o.type==="paste"){const g=e.getTextCursorPosition().block;p=J(e,g,d)}else if(o.type==="drop"){const g={left:o.clientX,top:o.clientY},m=e.prosemirrorView.posAtCoords(g);if(!m)return;p=e.transact(b=>{const C=u.getNearestBlockPos(b.doc,m.pos),E=e.prosemirrorView.dom.querySelector(`[data-id="${C.node.attrs.id}"]`),I=E==null?void 0:E.getBoundingClientRect();return J(e,e.getBlock(C.node.attrs.id),d,I&&(I.top+I.bottom)/2>g.top?"before":"after")})}else return;const f=await e.uploadFile(a,p),h=typeof f=="string"?{props:{url:f}}:{...f};e.updateBlock(p,h)}}}}const ct=o=>B.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{drop(e,t){if(!o.isEditable)return;let n=null;for(const r of z)if(t.dataTransfer.types.includes(r)){n=r;break}return n===null?!0:n==="Files"?(ge(t,o),!0):!1}}}})]}}),at=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,lt=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,dt=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,ut=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,pt=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,ft=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,ht=/\n{2} {0,3}-{2,48}\n{2}/,mt=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,kt=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,gt=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,bt=/^\s*\|(.+\|)+\s*$/m,St=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,Bt=/^\s*\|(.+\|)+\s*$/m,Ct=o=>at.test(o)||lt.test(o)||dt.test(o)||ut.test(o)||pt.test(o)||ft.test(o)||ht.test(o)||mt.test(o)||kt.test(o)||gt.test(o)||bt.test(o)||St.test(o)||Bt.test(o);async function yt(o,e){const{schema:t}=e.state;if(!o.clipboardData)return!1;const n=o.clipboardData.getData("text/plain");if(!n)return!1;if(!t.nodes.codeBlock)return e.pasteText(n),!0;const r=o.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,s=i==null?void 0:i.mode;return s?(e.pasteHTML(`<pre><code class="language-${s}">${n.replace(/\r\n?/g,`
3
+ `)}</code></pre>`),!0):!1}function Tt({event:o,editor:e,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:n}){var l;if(e.transact(a=>a.selection.$from.parent.type.spec.code&&a.selection.$to.parent.type.spec.code)){const a=(l=o.clipboardData)==null?void 0:l.getData("text/plain");if(a)return e.pasteText(a),!0}let i;for(const a of z)if(o.clipboardData.types.includes(a)){i=a;break}if(!i)return!0;if(i==="vscode-editor-data")return yt(o,e.prosemirrorView),!0;if(i==="Files")return ge(o,e),!0;const s=o.clipboardData.getData(i);if(i==="blocknote/html")return e.pasteHTML(s,!0),!0;if(i==="text/markdown")return e.pasteMarkdown(s),!0;if(t){const a=o.clipboardData.getData("text/plain");if(Ct(a))return e.pasteMarkdown(a),!0}return i==="text/html"?(e.pasteHTML(s),!0):n?(e.pasteMarkdown(s),!0):(e.pasteText(s),!0)}const Et=(o,e)=>B.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{paste(t,n){if(n.preventDefault(),!!o.isEditable)return e({event:n,editor:o,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:i=!0}={})=>Tt({event:n,editor:o,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:i})})}}}})]}});function xt(o,e,t){var l;let n=!1;const r=o.state.selection instanceof N.CellSelection;if(!r){const a=o.state.doc.slice(o.state.selection.from,o.state.selection.to,!1).content,d=[];for(let p=0;p<a.childCount;p++)d.push(a.child(p));n=d.find(p=>p.type.isInGroup("bnBlock")||p.type.name==="blockGroup"||p.type.spec.group==="blockContent")===void 0,n&&(e=a)}let i;const s=S.createExternalHTMLExporter(o.state.schema,t);if(r){((l=e.firstChild)==null?void 0:l.type.name)==="table"&&(e=e.firstChild.content);const a=u.contentNodeToTableContent(e,t.schema.inlineContentSchema,t.schema.styleSchema);i=`<table>${s.exportInlineContent(a,{})}</table>`}else if(n){const a=u.contentNodeToInlineContent(e,t.schema.inlineContentSchema,t.schema.styleSchema);i=s.exportInlineContent(a,{})}else{const a=S.fragmentToBlocks(e);i=s.exportBlocks(a,{})}return i}function q(o,e){"node"in o.state.selection&&o.state.selection.node.type.spec.group==="blockContent"&&e.transact(s=>s.setSelection(new y.NodeSelection(s.doc.resolve(o.state.selection.from-1))));const t=o.serializeForClipboard(o.state.selection.content()).dom.innerHTML,n=o.state.selection.content().content,r=xt(o,n,e),i=S.cleanHTMLToMarkdown(r);return{clipboardHTML:t,externalHTML:r,markdown:i}}const Q=()=>{const o=window.getSelection();if(!o||o.isCollapsed)return!0;let e=o.focusNode;for(;e;){if(e instanceof HTMLElement&&e.getAttribute("contenteditable")==="false")return!0;e=e.parentElement}return!1},X=(o,e,t)=>{t.preventDefault(),t.clipboardData.clearData();const{clipboardHTML:n,externalHTML:r,markdown:i}=q(e,o);t.clipboardData.setData("blocknote/html",n),t.clipboardData.setData("text/html",r),t.clipboardData.setData("text/plain",i)},Mt=o=>B.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{copy(e,t){return Q()||X(o,e,t),!0},cut(e,t){return Q()||(X(o,e,t),e.editable&&e.dispatch(e.state.tr.deleteSelection())),!0},dragstart(e,t){if(!("node"in e.state.selection)||e.state.selection.node.type.spec.group!=="blockContent")return;o.transact(s=>s.setSelection(new y.NodeSelection(s.doc.resolve(e.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{clipboardHTML:n,externalHTML:r,markdown:i}=q(e,o);return t.dataTransfer.setData("blocknote/html",n),t.dataTransfer.setData("text/html",r),t.dataTransfer.setData("text/plain",i),!0}}}})]}}),Pt=B.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{backgroundColor:c.getBackgroundColorAttribute()}}]}}),It=B.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:o}){return["br",B.mergeAttributes(this.options.HTMLAttributes,o)]},renderText(){return`
4
+ `}}),$=(o,e)=>{const t=o.resolve(e),n=t.index();if(n===0)return;const r=t.posAtIndex(n-1);return u.getBlockInfoFromResolvedPos(o.resolve(r))},be=(o,e)=>{for(;e.childContainer;){const t=e.childContainer.node,n=o.resolve(e.childContainer.beforePos+1).posAtIndex(t.childCount-1);e=u.getBlockInfoFromResolvedPos(o.resolve(n))}return e},wt=(o,e)=>o.isBlockContainer&&o.blockContent.node.type.spec.content==="inline*"&&o.blockContent.node.childCount>0&&e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*",vt=(o,e,t,n)=>{if(!n.isBlockContainer)throw new Error(`Attempted to merge block at position ${n.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`);if(n.childContainer){const r=o.doc.resolve(n.childContainer.beforePos+1),i=o.doc.resolve(n.childContainer.afterPos-1),s=r.blockRange(i);if(e){const l=o.doc.resolve(n.bnBlock.beforePos);o.tr.lift(s,l.depth)}}if(e){if(!t.isBlockContainer)throw new Error(`Attempted to merge block at position ${n.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`);e(o.tr.delete(t.blockContent.afterPos-1,n.blockContent.beforePos+1))}return!0},Z=o=>({state:e,dispatch:t})=>{const n=e.doc.resolve(o),r=u.getBlockInfoFromResolvedPos(n),i=$(e.doc,r.bnBlock.beforePos);if(!i)return!1;const s=be(e.doc,i);return wt(s,r)?vt(e,t,s,r):!1},Nt=B.Extension.create({priority:50,addKeyboardShortcuts(){const o=()=>this.editor.commands.first(({chain:n,commands:r})=>[()=>r.deleteSelection(),()=>r.undoInputRule(),()=>r.command(({state:i})=>{const s=u.getBlockInfoFromSelection(i);if(!s.isBlockContainer)return!1;const l=i.selection.from===s.blockContent.beforePos+1,a=s.blockContent.node.type.name==="paragraph";return l&&!a?r.command(c.updateBlockCommand(s.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:i})=>{const s=u.getBlockInfoFromSelection(i);if(!s.isBlockContainer)return!1;const{blockContent:l}=s;return i.selection.from===l.beforePos+1?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:i})=>{const s=u.getBlockInfoFromSelection(i);if(!s.isBlockContainer)return!1;const{bnBlock:l,blockContent:a}=s,d=i.selection.from===a.beforePos+1,p=i.selection.empty,f=l.beforePos;return d&&p?n().command(Z(f)).scrollIntoView().run():!1}),()=>r.command(({state:i,tr:s,dispatch:l})=>{const a=u.getBlockInfoFromSelection(i);if(!a.isBlockContainer||!(s.selection.from===a.blockContent.beforePos+1))return!1;const p=s.doc.resolve(a.bnBlock.beforePos);if(p.nodeBefore||p.node().type.name!=="column")return!1;const g=s.doc.resolve(a.bnBlock.beforePos),m=s.doc.resolve(g.before()),b=m.before();if(l){const C=s.doc.slice(a.bnBlock.beforePos,a.bnBlock.afterPos).content;s.delete(a.bnBlock.beforePos,a.bnBlock.afterPos),m.index()===0?(_(s,b),s.insert(b,C),s.setSelection(y.TextSelection.near(s.doc.resolve(b)))):(s.insert(m.pos-1,C),s.setSelection(y.TextSelection.near(s.doc.resolve(m.pos-1))),_(s,b))}return!0}),()=>r.command(({state:i})=>{const s=u.getBlockInfoFromSelection(i);if(!s.isBlockContainer)return!1;if(s.blockContent.node.childCount===0&&s.blockContent.node.type.spec.content==="inline*"){const a=$(i.doc,s.bnBlock.beforePos);if(!a||!a.isBlockContainer)return!1;let d=n();if(a.blockContent.node.type.spec.content==="tableRow+"){const m=s.bnBlock.beforePos-1-1-1-1-1;d=d.setTextSelection(m)}else if(a.blockContent.node.type.spec.content===""){const p=a.blockContent.afterPos-a.blockContent.node.nodeSize;d=d.setNodeSelection(p)}else{const p=a.blockContent.afterPos-a.blockContent.node.nodeSize;d=d.setTextSelection(p)}return d.deleteRange({from:s.bnBlock.beforePos,to:s.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:i})=>{const s=u.getBlockInfoFromSelection(i);if(!s.isBlockContainer)throw new Error("todo");const l=i.selection.from===s.blockContent.beforePos+1,a=i.selection.empty,d=$(i.doc,s.bnBlock.beforePos);if(d&&l&&a){const p=be(i.doc,d);if(!p.isBlockContainer)throw new Error("todo");if(p.blockContent.node.type.spec.content===""||p.blockContent.node.type.spec.content==="inline*"&&p.blockContent.node.childCount===0)return n().cut({from:s.bnBlock.beforePos,to:s.bnBlock.afterPos},p.bnBlock.afterPos).deleteRange({from:p.bnBlock.beforePos,to:p.bnBlock.afterPos}).run()}return!1})]),e=()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.command(({state:r})=>{const i=u.getBlockInfoFromSelection(r);if(!i.isBlockContainer)return!1;const{bnBlock:s,blockContent:l,childContainer:a}=i,{depth:d}=r.doc.resolve(s.beforePos),p=s.afterPos===r.doc.nodeSize-3,f=r.selection.from===l.afterPos-1,h=r.selection.empty;if(!p&&f&&h&&!(a!==void 0)){let m=d,b=s.afterPos+1,C=r.doc.resolve(b).depth;for(;C<m;)m=C,b+=2,C=r.doc.resolve(b).depth;return n.command(Z(b-1))}return!1})]),t=(n=!1)=>this.editor.commands.first(({commands:r,tr:i})=>[()=>r.command(({state:s})=>{const l=u.getBlockInfoFromSelection(s);if(!l.isBlockContainer)return!1;const{bnBlock:a,blockContent:d}=l,{depth:p}=s.doc.resolve(a.beforePos),f=s.selection.$anchor.parentOffset===0,h=s.selection.anchor===s.selection.head,g=d.node.childCount===0,m=p>1;return f&&h&&g&&m?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:s})=>{var d;const l=u.getBlockInfoFromSelection(s),a=((d=this.options.editor.schema.blockSchema[l.blockNoteType].meta)==null?void 0:d.hardBreakShortcut)??"shift+enter";if(a==="none")return!1;if(a==="shift+enter"&&n||a==="enter"){const p=i.storedMarks||i.selection.$head.marks().filter(f=>this.editor.extensionManager.splittableMarks.includes(f.type.name));return i.insert(i.selection.head,i.doc.type.schema.nodes.hardBreak.create()).ensureMarks(p),!0}return!1}),()=>r.command(({state:s,dispatch:l})=>{const a=u.getBlockInfoFromSelection(s);if(!a.isBlockContainer)return!1;const{bnBlock:d,blockContent:p}=a,f=s.selection.$anchor.parentOffset===0,h=s.selection.anchor===s.selection.head,g=p.node.childCount===0;if(f&&h&&g){const m=d.afterPos,b=m+2;if(l){const C=s.schema.nodes.blockContainer.createAndFill();s.tr.insert(m,C).scrollIntoView(),s.tr.setSelection(new y.TextSelection(s.doc.resolve(b)))}return!0}return!1}),()=>r.command(({state:s,chain:l})=>{const a=u.getBlockInfoFromSelection(s);if(!a.isBlockContainer)return!1;const{blockContent:d}=a,p=s.selection.$anchor.parentOffset===0;return d.node.childCount===0?!1:(l().deleteSelection().command(c.splitBlockCommand(s.selection.from,p,p)).run(),!0)})]);return{Backspace:o,Delete:e,Enter:()=>t(),"Shift-Enter":()=>t(!0),Tab:()=>{var n,r;return this.options.tabBehavior!=="prefer-indent"&&((n=this.options.editor.getExtension(S.FormattingToolbarExtension))!=null&&n.store.state||((r=this.options.editor.getExtension(c.FilePanelExtension))==null?void 0:r.store.state)!==void 0)?!1:ue(this.options.editor)},"Shift-Tab":()=>{var n,r;return this.options.tabBehavior!=="prefer-indent"&&((n=this.options.editor.getExtension(S.FormattingToolbarExtension))!=null&&n.store.state||((r=this.options.editor.getExtension(c.FilePanelExtension))==null?void 0:r.store.state)!==void 0)?!1:this.editor.commands.liftListItem("blockContainer")},"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()}}}),At=B.Mark.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(o){return o.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}}]}}}),Lt=B.Mark.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(o){return o.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}}]}}}),_t=B.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(o){return o.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}}]}}}),Dt=B.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:o=>o.getAttribute("data-text-alignment"),renderHTML:o=>o.textAlignment==="left"?{}:{"data-text-alignment":o.textAlignment}}}}]}}),Ft=B.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["table","tableCell","tableHeader"],attributes:{textColor:c.getTextColorAttribute()}}]}}),Ot={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ht=B.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:o=>{if(typeof o=="string")return!1;const e={};for(const[t,n]of Object.entries(Ot))o.getAttribute(n)&&(e[t]=o.getAttribute(n));return e}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:o}){var r;const e=document.createElement("div");e.className="bn-block-outer",e.setAttribute("data-node-type","blockOuter");for(const[i,s]of Object.entries(o))i!=="class"&&e.setAttribute(i,s);const t={...((r=this.options.domAttributes)==null?void 0:r.block)||{},...o},n=document.createElement("div");n.className=c.mergeCSSClasses("bn-block",t.class),n.setAttribute("data-node-type",this.name);for(const[i,s]of Object.entries(t))i!=="class"&&n.setAttribute(i,s);return e.appendChild(n),{dom:e,contentDOM:n}}}),$t=B.Node.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML(){return[{tag:"div",getAttrs:o=>typeof o=="string"?!1:o.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:o}){var n;const e={...((n=this.options.domAttributes)==null?void 0:n.blockGroup)||{},...o},t=document.createElement("div");t.className=c.mergeCSSClasses("bn-block-group",e.class),t.setAttribute("data-node-type","blockGroup");for(const[r,i]of Object.entries(e))r!=="class"&&t.setAttribute(r,i);return{dom:t,contentDOM:t}}}),Ut=B.Node.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"});let ee=!1;function Vt(o,e){const t=[B.extensions.ClipboardTextSerializer,B.extensions.Commands,B.extensions.Editable,B.extensions.FocusEvents,B.extensions.Tabindex,xe.Gapcursor,u.UniqueID.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),It,Pe.Text,At,Lt,_t,Me.Link.extend({inclusive:!1}).configure({defaultProtocol:S.DEFAULT_LINK_PROTOCOL,protocols:ee?[]:S.VALID_LINK_PROTOCOLS}),...Object.values(o.schema.styleSpecs).map(n=>n.implementation.mark.configure({editor:o})),Ft,Pt,Dt,B.Extension.create({name:"OverrideEscape",addKeyboardShortcuts:()=>({Escape:()=>{var n;return(n=o.getExtension(c.SuggestionMenu))!=null&&n.shown()?!1:(o.blur(),!0)}})}),Ut,Ht.configure({editor:o,domAttributes:e.domAttributes}),Nt.configure({editor:o,tabBehavior:e.tabBehavior}),$t.configure({domAttributes:e.domAttributes}),...Object.values(o.schema.inlineContentSpecs).filter(n=>n.config!=="link"&&n.config!=="text").map(n=>n.implementation.node.configure({editor:o})),...Object.values(o.schema.blockSpecs).flatMap(n=>[..."node"in n.implementation?[n.implementation.node.configure({editor:o,domAttributes:e.domAttributes})]:[]]),Mt(o),Et(o,e.pasteHandler||(n=>n.defaultPasteHandler())),ct(o)];return ee=!0,t}function Rt(o,e){var n;const t=[S.BlockChangeExtension(),S.DropCursorExtension(e),c.FilePanelExtension(e),S.FormattingToolbarExtension(e),S.LinkToolbarExtension(e),S.NodeSelectionKeyboardExtension(),S.PlaceholderExtension(e),Ie.ShowSelectionExtension(e),S.SideMenuExtension(e),c.SuggestionMenu(e),...e.trailingBlock!==!1?[S.TrailingNodeExtension()]:[]];return e.collaboration?(t.push(S.ForkYDocExtension(e.collaboration)),(n=e.collaboration.provider)!=null&&n.awareness&&t.push(S.YCursorExtension(e.collaboration)),t.push(S.YSyncExtension(e.collaboration)),t.push(S.YUndoExtension(e.collaboration)),t.push(S.SchemaMigration(e.collaboration))):t.push(S.HistoryExtension()),"table"in o.schema.blockSpecs&&t.push(S.TableHandlesExtension(e)),e.animations!==!1&&t.push(S.PreviousBlockTypeExtension()),t}class Gt{constructor(e,t){k(this,"disabledExtensions",new Set);k(this,"extensions",[]);k(this,"abortMap",new Map);k(this,"extensionFactories",new Map);k(this,"extensionPlugins",new Map);this.editor=e,this.options=t,e.onMount(()=>{for(const n of this.extensions)if(n.mount){const r=new window.AbortController,i=n.mount({dom:e.prosemirrorView.dom,root:e.prosemirrorView.root,signal:r.signal});i&&r.signal.addEventListener("abort",()=>{i()}),this.abortMap.set(n,r)}}),e.onUnmount(()=>{for(const[n,r]of this.abortMap.entries())this.abortMap.delete(n),r.abort()}),this.disabledExtensions=new Set(t.disableExtensions||[]);for(const n of Rt(this.editor,this.options))this.addExtension(n);for(const n of this.options.extensions??[])this.addExtension(n);for(const n of Object.values(this.editor.schema.blockSpecs))for(const r of n.extensions??[])this.addExtension(r)}registerExtension(e){var i;const t=[].concat(e).filter(Boolean);if(!t.length){console.warn("No extensions found to register",e);return}const n=t.map(s=>this.addExtension(s)).filter(Boolean),r=new Set;for(const s of n)s!=null&&s.tiptapExtensions&&console.warn(`Extension ${s.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.`,s),(i=s==null?void 0:s.inputRules)!=null&&i.length&&console.warn(`Extension ${s.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.`,s),this.getProsemirrorPluginsFromExtension(s).plugins.forEach(l=>{r.add(l)});this.updatePlugins(s=>[...s,...r])}addExtension(e){let t;if(typeof e=="function"?t=e({editor:this.editor}):t=e,!(!t||this.disabledExtensions.has(t.key))){if(typeof e=="function"){const n=t[V.originalFactorySymbol];typeof n=="function"&&this.extensionFactories.set(n,t)}return this.extensions.push(t),t}}resolveExtensions(e){const t=[];if(typeof e=="function"){const n=this.extensionFactories.get(e);n&&t.push(n)}else if(Array.isArray(e))for(const n of e)t.push(...this.resolveExtensions(n));else if(typeof e=="object"&&"key"in e)t.push(e);else if(typeof e=="string"){const n=this.extensions.find(r=>r.key===e);n&&t.push(n)}return t}unregisterExtension(e){var i;const t=this.resolveExtensions(e);if(!t.length){console.warn("No extensions found to unregister",e);return}let n=!1;const r=new Set;for(const s of t){this.extensions=this.extensions.filter(a=>a!==s),this.extensionFactories.forEach((a,d)=>{a===s&&this.extensionFactories.delete(d)}),(i=this.abortMap.get(s))==null||i.abort(),this.abortMap.delete(s);const l=this.extensionPlugins.get(s);l==null||l.forEach(a=>{r.add(a)}),this.extensionPlugins.delete(s),s.tiptapExtensions&&!n&&(n=!0,console.warn(`Extension ${s.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(s=>s.filter(l=>!r.has(l)))}updatePlugins(e){const t=this.editor.prosemirrorState,n=t.reconfigure({plugins:e(t.plugins.slice())});this.editor.prosemirrorView.updateState(n)}getTiptapExtensions(){var r;const e=Vt(this.editor,this.options),t=M.sortByDependencies(this.extensions),n=new Map;for(const i of this.extensions){i.tiptapExtensions&&e.push(...i.tiptapExtensions);const s=t(i.key),{plugins:l,inputRules:a}=this.getProsemirrorPluginsFromExtension(i);l.length&&e.push(B.Extension.create({name:i.key,priority:s,addProseMirrorPlugins:()=>l})),a.length&&(n.has(s)||n.set(s,[]),n.get(s).push(...a))}e.push(B.Extension.create({name:"blocknote-input-rules",addProseMirrorPlugins(){const i=[];return Array.from(n.keys()).sort().reverse().forEach(s=>{i.push(...n.get(s))}),[W.inputRules({rules:i})]}}));for(const i of((r=this.options._tiptapOptions)==null?void 0:r.extensions)??[])e.push(i);return e}getProsemirrorPluginsFromExtension(e){var r,i,s;const t=[...e.prosemirrorPlugins??[]],n=[];return!((r=e.prosemirrorPlugins)!=null&&r.length)&&!Object.keys(e.keyboardShortcuts||{}).length&&!((i=e.inputRules)!=null&&i.length)?{plugins:t,inputRules:n}:(this.extensionPlugins.set(e,t),(s=e.inputRules)!=null&&s.length&&n.push(...e.inputRules.map(l=>new W.InputRule(l.find,(a,d,p,f)=>{const h=l.replace({match:d,range:{from:p,to:f},editor:this.editor});if(h){const g=this.editor.getTextCursorPosition();if(this.editor.schema.blockSchema[g.block.type].content!=="inline")return null;const m=u.getBlockInfoFromTransaction(a.tr),b=a.tr.deleteRange(p,f);return c.updateBlockTr(b,m.bnBlock.beforePos,h),b}return null}))),Object.keys(e.keyboardShortcuts||{}).length&&t.push(Ee.keymap(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([l,a])=>[l,()=>a({editor:this.editor})])))),{plugins:t,inputRules:n})}getExtensions(){return new Map(this.extensions.map(e=>[e.key,e]))}getExtension(e){if(typeof e=="string"){const t=this.extensions.find(n=>n.key===e);return t||void 0}else if(typeof e=="function"){const t=this.extensionFactories.get(e);return t||void 0}throw new 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 zt(o){const e=u.getPmSchema(o);if(o.selection.empty||"node"in o.selection)return;const t=o.doc.resolve(u.getNearestBlockPos(o.doc,o.selection.from).posBeforeNode),n=o.doc.resolve(u.getNearestBlockPos(o.doc,o.selection.to).posBeforeNode),r=(d,p)=>{const f=t.posAtIndex(d,p),h=o.doc.resolve(f).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${f}`);return u.nodeToBlock(h,e)},i=[],s=t.sharedDepth(n.pos),l=t.index(s),a=n.index(s);if(t.depth>s){i.push(u.nodeToBlock(t.nodeAfter,e));for(let d=t.depth;d>s;d--)if(t.node(d).type.isInGroup("childContainer")){const f=t.index(d)+1,h=t.node(d).childCount;for(let g=f;g<h;g++)i.push(r(g,d))}}else i.push(r(l,s));for(let d=l+1;d<=a;d++)i.push(r(d,s));if(i.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${o.selection})`);return{blocks:i}}function qt(o,e,t){const n=typeof e=="string"?e:e.id,r=typeof t=="string"?t:t.id,i=u.getPmSchema(o),s=u.getBlockNoteSchema(i);if(n===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${n})`);const l=c.getNodeById(n,o.doc);if(!l)throw new Error(`Block with ID ${n} not found`);const a=c.getNodeById(r,o.doc);if(!a)throw new Error(`Block with ID ${r} not found`);const d=u.getBlockInfo(l),p=u.getBlockInfo(a),f=s.blockSchema[d.blockNoteType],h=s.blockSchema[p.blockNoteType];if(!d.isBlockContainer||f.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${n})`);if(!p.isBlockContainer||h.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let g,m;if(f.content==="table"){const b=N.TableMap.get(d.blockContent.node);g=d.blockContent.beforePos+b.positionAt(0,0,d.blockContent.node)+1+2}else g=d.blockContent.beforePos+1;if(h.content==="table"){const b=N.TableMap.get(p.blockContent.node),C=p.blockContent.beforePos+b.positionAt(b.height-1,b.width-1,p.blockContent.node)+1,E=o.doc.resolve(C).nodeAfter.nodeSize;m=C+E-2}else m=p.blockContent.afterPos-1;o.setSelection(y.TextSelection.create(o.doc,g,m))}function jt(o){const e=u.getPmSchema(o);let t=o.selection.$from,n=o.selection.$to;for(;n.parentOffset>=n.parent.nodeSize-2&&n.depth>0;)n=o.doc.resolve(n.pos+1);for(;n.parentOffset===0&&n.depth>0;)n=o.doc.resolve(n.pos-1);for(;t.parentOffset===0&&t.depth>0;)t=o.doc.resolve(t.pos-1);for(;t.parentOffset>=t.parent.nodeSize-2&&t.depth>0;)t=o.doc.resolve(t.pos+1);const r=u.prosemirrorSliceToSlicedBlocks(o.doc.slice(t.pos,n.pos,!0),e);return{_meta:{startPos:t.pos,endPos:n.pos},...r}}function Wt(o){const{bnBlock:e}=u.getBlockInfoFromTransaction(o),t=u.getPmSchema(o.doc),n=o.doc.resolve(e.beforePos),r=n.nodeBefore,i=o.doc.resolve(e.afterPos).nodeAfter;let s;return n.depth>1&&(s=n.node(),s.type.isInGroup("bnBlock")||(s=n.node(n.depth-1))),{block:u.nodeToBlock(e.node,t),prevBlock:r===null?void 0:u.nodeToBlock(r,t),nextBlock:i===null?void 0:u.nodeToBlock(i,t),parentBlock:s===void 0?void 0:u.nodeToBlock(s,t)}}function Se(o,e,t="start"){const n=typeof e=="string"?e:e.id,r=u.getPmSchema(o.doc),i=u.getBlockNoteSchema(r),s=c.getNodeById(n,o.doc);if(!s)throw new Error(`Block with ID ${n} not found`);const l=u.getBlockInfo(s),a=i.blockSchema[l.blockNoteType].content;if(l.isBlockContainer){const d=l.blockContent;if(a==="none"){o.setSelection(y.NodeSelection.create(o.doc,d.beforePos));return}if(a==="inline")t==="start"?o.setSelection(y.TextSelection.create(o.doc,d.beforePos+1)):o.setSelection(y.TextSelection.create(o.doc,d.afterPos-1));else if(a==="table")t==="start"?o.setSelection(y.TextSelection.create(o.doc,d.beforePos+4)):o.setSelection(y.TextSelection.create(o.doc,d.afterPos-4));else throw new u.UnreachableCaseError(a)}else{const d=t==="start"?l.childContainer.node.firstChild:l.childContainer.node.lastChild;Se(o,d.attrs.id,t)}}class Kt{constructor(e){this.editor=e}getSelection(){return this.editor.transact(e=>zt(e))}getSelectionCutBlocks(){return this.editor.transact(e=>jt(e))}setSelection(e,t){return this.editor.transact(n=>qt(n,e,t))}getTextCursorPosition(){return this.editor.transact(e=>Wt(e))}setTextCursorPosition(e,t="start"){return this.editor.transact(n=>Se(n,e,t))}getSelectionBoundingBox(){if(!this.editor.prosemirrorView)return;const{selection:e}=this.editor.prosemirrorState,{ranges:t}=e,n=Math.min(...t.map(i=>i.$from.pos)),r=Math.max(...t.map(i=>i.$to.pos));if(B.isNodeSelection(e)){const i=this.editor.prosemirrorView.nodeDOM(n);if(i)return i.getBoundingClientRect()}return B.posToDOMRect(this.editor.prosemirrorView,n,r).toJSON()}}class Yt{constructor(e){k(this,"activeTransaction",null);k(this,"isInCan",!1);this.editor=e}can(e){try{return this.isInCan=!0,e()}finally{this.isInCan=!1}}exec(e){if(this.activeTransaction)throw new 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);const t=this.prosemirrorState,n=this.prosemirrorView;return e(t,i=>this.prosemirrorView.dispatch(i),n)}canExec(e){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const 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;const 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 new 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(){var e;return((e=this.prosemirrorView)==null?void 0:e.hasFocus())||!1}focus(){var e;(e=this.prosemirrorView)==null||e.focus()}get isEditable(){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new 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 new Error("no editor, but also not headless?");return}this.editor._tiptapEditor.options.editable!==e&&this.editor._tiptapEditor.setEditable(e)}undo(){const e=this.editor.getExtension("yUndo");if(e)return this.exec(e.undoCommand);const t=this.editor.getExtension("history");if(t)return this.exec(t.undoCommand);throw new Error("No undo plugin found")}redo(){const e=this.editor.getExtension("yUndo");if(e)return this.exec(e.redoCommand);const t=this.editor.getExtension("history");if(t)return this.exec(t.redoCommand);throw new Error("No redo plugin found")}}function Jt(o,e,t,n={updateSelection:!0}){let{from:r,to:i}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},s=!0,l=!0,a="";if(t.forEach(d=>{d.check(),s&&d.isText&&d.marks.length===0?a+=d.text:s=!1,l=l?d.isBlock:!1}),r===i&&l){const{parent:d}=o.doc.resolve(r);d.isTextblock&&!d.type.spec.code&&!d.childCount&&(r-=1,i+=1)}return s?o.insertText(a,r,i):o.replaceWith(r,i,t),n.updateSelection&&B.selectionToInsertionEnd(o,o.steps.length-1,-1),!0}class Qt{constructor(e){this.editor=e}insertInlineContent(e,{updateSelection:t=!1}={}){const n=u.inlineContentToNodes(e,this.editor.pmSchema);this.editor.transact(r=>{Jt(r,{from:r.selection.from,to:r.selection.to},n,{updateSelection:t})})}getActiveStyles(){return this.editor.transact(e=>{const t={},n=e.selection.$to.marks();for(const r of n){const i=this.editor.schema.styleSchema[r.type.name];if(!i){r.type.name!=="link"&&!r.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",r.type.name);continue}i.propSchema==="boolean"?t[i.type]=!0:t[i.type]=r.attrs.stringValue}return t})}addStyles(e){for(const[t,n]of Object.entries(e)){const r=this.editor.schema.styleSchema[t];if(!r)throw new Error(`style ${t} not found in styleSchema`);if(r.propSchema==="boolean")this.editor._tiptapEditor.commands.setMark(t);else if(r.propSchema==="string")this.editor._tiptapEditor.commands.setMark(t,{stringValue:n});else throw new u.UnreachableCaseError(r.propSchema)}}removeStyles(e){for(const t of Object.keys(e))this.editor._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){for(const[t,n]of Object.entries(e)){const r=this.editor.schema.styleSchema[t];if(!r)throw new Error(`style ${t} not found in styleSchema`);if(r.propSchema==="boolean")this.editor._tiptapEditor.commands.toggleMark(t);else if(r.propSchema==="string")this.editor._tiptapEditor.commands.toggleMark(t,{stringValue:n});else throw new u.UnreachableCaseError(r.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;const n=this.editor.pmSchema.mark("link",{href:e});this.editor.transact(r=>{const{from:i,to:s}=r.selection;t?r.insertText(t,i,s).addMark(i,i+t.length,n):r.setSelection(y.TextSelection.create(r.doc,s)).addMark(i,s,n)})}}function Xt(o,e){const t=[];return o.forEach((n,r,i)=>{i!==e&&t.push(n)}),T.Fragment.from(t)}function Zt(o,e){const t=[];for(let n=0;n<o.childCount;n++)if(o.child(n).type.name==="tableRow")if(t.length>0&&t[t.length-1].type.name==="table"){const r=t[t.length-1],i=r.copy(r.content.addToEnd(o.child(n)));t[t.length-1]=i}else{const r=e.nodes.table.createChecked(void 0,o.child(n));t.push(r)}else t.push(o.child(n));return o=T.Fragment.from(t),o}function eo(o,e){let t=T.Fragment.from(o.content);if(t=Zt(t,e.state.schema),!to(t,e))return new T.Slice(t,o.openStart,o.openEnd);for(let n=0;n<t.childCount;n++)if(t.child(n).type.spec.group==="blockContent"){const r=[t.child(n)];if(n+1<t.childCount&&t.child(n+1).type.name==="blockGroup"){const s=t.child(n+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem"||s.type.name==="checkListItem")&&(r.push(t.child(n+1)),t=Xt(t,n+1))}const i=e.state.schema.nodes.blockContainer.createChecked(void 0,r);t=t.replaceChild(n,i)}return new T.Slice(t,o.openStart,o.openEnd)}function to(o,e){var i,s;const t=o.childCount===1,n=((i=o.firstChild)==null?void 0:i.type.spec.content)==="inline*",r=((s=o.firstChild)==null?void 0:s.type.spec.content)==="tableRow+";if(t){if(n)return!1;if(r){const l=u.getBlockInfoFromSelection(e.state);if(l.isBlockContainer)return!(l.blockContent.node.type.spec.content==="tableRow+")}}return!0}const oo={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class j extends U.EventEmitter{constructor(t){var d,p,f,h,g,m,b,C,E,I;super();k(this,"pmSchema");k(this,"_tiptapEditor");k(this,"elementRenderer",null);k(this,"blockCache",new WeakMap);k(this,"dictionary");k(this,"schema");k(this,"blockImplementations");k(this,"inlineContentImplementations");k(this,"styleImplementations");k(this,"uploadFile");k(this,"onUploadStartCallbacks",[]);k(this,"onUploadEndCallbacks",[]);k(this,"resolveFileUrl");k(this,"settings");k(this,"_blockManager");k(this,"_eventManager");k(this,"_exportManager");k(this,"_extensionManager");k(this,"_selectionManager");k(this,"_stateManager");k(this,"_styleManager");k(this,"unregisterExtension",(...t)=>this._extensionManager.unregisterExtension(...t));k(this,"registerExtension",(...t)=>this._extensionManager.registerExtension(...t));k(this,"getExtension",(...t)=>this._extensionManager.getExtension(...t));k(this,"mount",t=>{this._tiptapEditor.mount({mount:t})});k(this,"unmount",()=>{this._tiptapEditor.unmount()});this.options=t,this.dictionary=t.dictionary||Te.en,this.settings={tables:{splitCells:((d=t==null?void 0:t.tables)==null?void 0:d.splitCells)??!1,cellBackgroundColor:((p=t==null?void 0:t.tables)==null?void 0:p.cellBackgroundColor)??!1,cellTextColor:((f=t==null?void 0:t.tables)==null?void 0:f.cellTextColor)??!1,headers:((h=t==null?void 0:t.tables)==null?void 0:h.headers)??!1}};const n={defaultStyles:!0,schema:t.schema||M.BlockNoteSchema.create(),...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};if(this.schema=n.schema,this.blockImplementations=n.schema.blockSpecs,this.inlineContentImplementations=n.schema.inlineContentSpecs,this.styleImplementations=n.schema.styleSpecs,n.uploadFile){const x=n.uploadFile;this.uploadFile=async(w,P)=>{this.onUploadStartCallbacks.forEach(v=>v.apply(this,[P]));try{return await x(w,P)}finally{this.onUploadEndCallbacks.forEach(v=>v.apply(this,[P]))}}}this.resolveFileUrl=n.resolveFileUrl,this._eventManager=new Ye(this),this._extensionManager=new Gt(this,n);const r=this._extensionManager.getTiptapExtensions(),i=this._extensionManager.hasExtension("ySync")||this._extensionManager.hasExtension("liveblocksExtension");i&&n.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const s={...oo,...n._tiptapOptions,element:null,autofocus:n.autofocus??!1,extensions:r,editorProps:{...(g=n._tiptapOptions)==null?void 0:g.editorProps,attributes:{tabIndex:"0",...(b=(m=n._tiptapOptions)==null?void 0:m.editorProps)==null?void 0:b.attributes,...(C=n.domAttributes)==null?void 0:C.editor,class:c.mergeCSSClasses("bn-editor",n.defaultStyles?"bn-default-styles":"",((I=(E=n.domAttributes)==null?void 0:E.editor)==null?void 0:I.class)||"")},transformPasted:eo}};try{const x=n.initialContent||(i?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:u.UniqueID.options.generateID()}]);if(!Array.isArray(x)||x.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+x);const w=B.getSchema(s.extensions),P=x.map(Be=>u.blockToNode(Be,w,this.schema.styleSchema).toJSON()),v=B.createDocument({type:"doc",content:[{type:"blockGroup",content:P}]},w,s.parseOptions);this._tiptapEditor=new B.Editor({...s,content:v.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(x){throw new Error("Error creating document from blocks passed as `initialContent`",{cause:x})}let l;const a=this.pmSchema.nodes.doc.createAndFill;this.pmSchema.nodes.doc.createAndFill=(...x)=>{if(l)return l;const w=a.apply(this.pmSchema.nodes.doc,x),P=JSON.parse(JSON.stringify(w.toJSON()));return P.content[0].content[0].attrs.id="initialBlockId",l=T.Node.fromJSON(this.pmSchema,P),l},this.pmSchema.cached.blockNoteEditor=this,this._blockManager=new Ke(this),this._exportManager=new rt(this),this._selectionManager=new Kt(this),this._stateManager=new Yt(this),this._styleManager=new Qt(this),this.emit("create")}static create(t){return new j(t??{})}get extensions(){return this._extensionManager.getExtensions()}exec(t){return this._stateManager.exec(t)}canExec(t){return this._stateManager.canExec(t)}transact(t){return this._stateManager.transact(t)}get prosemirrorState(){return this._stateManager.prosemirrorState}get prosemirrorView(){return this._stateManager.prosemirrorView}get domElement(){var t;if(!this.headless)return(t=this.prosemirrorView)==null?void 0:t.dom}isFocused(){var t;return this.headless?!1:((t=this.prosemirrorView)==null?void 0:t.hasFocus())||!1}get headless(){return!this._tiptapEditor.isInitialized}focus(){this.headless||this.prosemirrorView.focus()}blur(){this.headless||this.prosemirrorView.dom.blur()}onUploadStart(t){return this.onUploadStartCallbacks.push(t),()=>{const n=this.onUploadStartCallbacks.indexOf(t);n>-1&&this.onUploadStartCallbacks.splice(n,1)}}onUploadEnd(t){return this.onUploadEndCallbacks.push(t),()=>{const n=this.onUploadEndCallbacks.indexOf(t);n>-1&&this.onUploadEndCallbacks.splice(n,1)}}get topLevelBlocks(){return this.document}get document(){return this._blockManager.document}getBlock(t){return this._blockManager.getBlock(t)}getPrevBlock(t){return this._blockManager.getPrevBlock(t)}getNextBlock(t){return this._blockManager.getNextBlock(t)}getParentBlock(t){return this._blockManager.getParentBlock(t)}forEachBlock(t,n=!1){this._blockManager.forEachBlock(t,n)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){return this._selectionManager.getTextCursorPosition()}setTextCursorPosition(t,n="start"){return this._selectionManager.setTextCursorPosition(t,n)}getSelection(){return this._selectionManager.getSelection()}getSelectionCutBlocks(){return this._selectionManager.getSelectionCutBlocks()}setSelection(t,n){return this._selectionManager.setSelection(t,n)}get isEditable(){return this._stateManager.isEditable}set isEditable(t){this._stateManager.isEditable=t}insertBlocks(t,n,r="before"){return this._blockManager.insertBlocks(t,n,r)}updateBlock(t,n){return this._blockManager.updateBlock(t,n)}removeBlocks(t){return this._blockManager.removeBlocks(t)}replaceBlocks(t,n){return this._blockManager.replaceBlocks(t,n)}undo(){return this._stateManager.undo()}redo(){return this._stateManager.redo()}insertInlineContent(t,{updateSelection:n=!1}={}){this._styleManager.insertInlineContent(t,{updateSelection:n})}getActiveStyles(){return this._styleManager.getActiveStyles()}addStyles(t){this._styleManager.addStyles(t)}removeStyles(t){this._styleManager.removeStyles(t)}toggleStyles(t){this._styleManager.toggleStyles(t)}getSelectedText(){return this._styleManager.getSelectedText()}getSelectedLinkUrl(){return this._styleManager.getSelectedLinkUrl()}createLink(t,n){this._styleManager.createLink(t,n)}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(t=this.document){return this._exportManager.blocksToHTMLLossy(t)}blocksToFullHTML(t=this.document){return this._exportManager.blocksToFullHTML(t)}tryParseHTMLToBlocks(t){return this._exportManager.tryParseHTMLToBlocks(t)}blocksToMarkdownLossy(t=this.document){return this._exportManager.blocksToMarkdownLossy(t)}tryParseMarkdownToBlocks(t){return this._exportManager.tryParseMarkdownToBlocks(t)}onChange(t,n){return this._eventManager.onChange(t,n)}onSelectionChange(t,n){return this._eventManager.onSelectionChange(t,n)}onMount(t){this._eventManager.onMount(t)}onUnmount(t){this._eventManager.onUnmount(t)}getSelectionBoundingBox(){return this._selectionManager.getSelectionBoundingBox()}get isEmpty(){const t=this.document;return t.length===0||t.length===1&&t[0].type==="paragraph"&&t[0].content.length===0}pasteHTML(t,n=!1){this._exportManager.pasteHTML(t,n)}pasteText(t){return this._exportManager.pasteText(t)}pasteMarkdown(t){return this._exportManager.pasteMarkdown(t)}}class no{constructor(e,t,n){this.mappings=t,this.options=n}async resolveFile(e){var n;if(!((n=this.options)!=null&&n.resolveFileUrl))return(await fetch(e)).blob();const t=await this.options.resolveFileUrl(e);return t instanceof Blob?t:(await fetch(t)).blob()}mapStyles(e){return Object.entries(e).map(([n,r])=>this.mappings.styleMapping[n](r,this))}mapInlineContent(e){return this.mappings.inlineContentMapping[e.type](e,this)}transformInlineContent(e){return e.map(t=>this.mapInlineContent(t))}async mapBlock(e,t,n,r){return this.mappings.blockMapping[e.type](e,this,t,n,r)}}function ro(o){return{createBlockMapping:e=>e,createInlineContentMapping:e=>e,createStyleMapping:e=>e}}function so(o,...e){const t=[...o];for(const n of e)for(const r of n){const i=t.findLastIndex(s=>s.group===r.group);i===-1?t.push(r):t.splice(i+1,0,r)}return t}exports.UniqueID=u.UniqueID;exports.UnreachableCaseError=u.UnreachableCaseError;exports.assertEmpty=u.assertEmpty;exports.blockToNode=u.blockToNode;exports.contentNodeToInlineContent=u.contentNodeToInlineContent;exports.contentNodeToTableContent=u.contentNodeToTableContent;exports.docToBlocks=u.docToBlocks;exports.getBlockCache=u.getBlockCache;exports.getBlockInfo=u.getBlockInfo;exports.getBlockInfoFromResolvedPos=u.getBlockInfoFromResolvedPos;exports.getBlockInfoFromSelection=u.getBlockInfoFromSelection;exports.getBlockInfoFromTransaction=u.getBlockInfoFromTransaction;exports.getBlockInfoWithManualOffset=u.getBlockInfoWithManualOffset;exports.getBlockNoteSchema=u.getBlockNoteSchema;exports.getBlockSchema=u.getBlockSchema;exports.getColspan=u.getColspan;exports.getInlineContentSchema=u.getInlineContentSchema;exports.getNearestBlockPos=u.getNearestBlockPos;exports.getPmSchema=u.getPmSchema;exports.getRowspan=u.getRowspan;exports.getStyleSchema=u.getStyleSchema;exports.inlineContentToNodes=u.inlineContentToNodes;exports.isLinkInlineContent=u.isLinkInlineContent;exports.isPartialLinkInlineContent=u.isPartialLinkInlineContent;exports.isPartialTableCell=u.isPartialTableCell;exports.isStyledTextInlineContent=u.isStyledTextInlineContent;exports.isTableCell=u.isTableCell;exports.mapTableCell=u.mapTableCell;exports.nodeToBlock=u.nodeToBlock;exports.nodeToCustomInlineContent=u.nodeToCustomInlineContent;exports.prosemirrorSliceToSlicedBlocks=u.prosemirrorSliceToSlicedBlocks;exports.tableContentToNodes=u.tableContentToNodes;exports.COLORS_DARK_MODE_DEFAULT=c.COLORS_DARK_MODE_DEFAULT;exports.COLORS_DEFAULT=c.COLORS_DEFAULT;exports.EMPTY_CELL_HEIGHT=c.EMPTY_CELL_HEIGHT;exports.EMPTY_CELL_WIDTH=c.EMPTY_CELL_WIDTH;exports.FILE_AUDIO_ICON_SVG=c.FILE_AUDIO_ICON_SVG;exports.FILE_IMAGE_ICON_SVG=c.FILE_IMAGE_ICON_SVG;exports.FILE_VIDEO_ICON_SVG=c.FILE_VIDEO_ICON_SVG;exports.addDefaultPropsExternalHTML=c.addDefaultPropsExternalHTML;exports.addInlineContentAttributes=c.addInlineContentAttributes;exports.addInlineContentKeyboardShortcuts=c.addInlineContentKeyboardShortcuts;exports.addNodeAndExtensionsToSpec=c.addNodeAndExtensionsToSpec;exports.addStyleAttributes=c.addStyleAttributes;exports.applyNonSelectableBlockFix=c.applyNonSelectableBlockFix;exports.audioParse=c.audioParse;exports.audioRender=c.audioRender;exports.audioToExternalHTML=c.audioToExternalHTML;exports.blockHasType=c.blockHasType;exports.camelToDataKebab=c.camelToDataKebab;exports.captureCellAnchor=c.captureCellAnchor;exports.createAudioBlockConfig=c.createAudioBlockConfig;exports.createAudioBlockSpec=c.createAudioBlockSpec;exports.createBlockConfig=c.createBlockConfig;exports.createBlockSpec=c.createBlockSpec;exports.createBlockSpecFromTiptapNode=c.createBlockSpecFromTiptapNode;exports.createBulletListItemBlockConfig=c.createBulletListItemBlockConfig;exports.createBulletListItemBlockSpec=c.createBulletListItemBlockSpec;exports.createCheckListItemBlockSpec=c.createCheckListItemBlockSpec;exports.createCheckListItemConfig=c.createCheckListItemConfig;exports.createCodeBlockConfig=c.createCodeBlockConfig;exports.createCodeBlockSpec=c.createCodeBlockSpec;exports.createDefaultBlockDOMOutputSpec=c.createDefaultBlockDOMOutputSpec;exports.createDividerBlockConfig=c.createDividerBlockConfig;exports.createDividerBlockSpec=c.createDividerBlockSpec;exports.createFileBlockConfig=c.createFileBlockConfig;exports.createFileBlockSpec=c.createFileBlockSpec;exports.createHeadingBlockConfig=c.createHeadingBlockConfig;exports.createHeadingBlockSpec=c.createHeadingBlockSpec;exports.createImageBlockConfig=c.createImageBlockConfig;exports.createImageBlockSpec=c.createImageBlockSpec;exports.createInlineContentSpecFromTipTapNode=c.createInlineContentSpecFromTipTapNode;exports.createInternalInlineContentSpec=c.createInternalInlineContentSpec;exports.createInternalStyleSpec=c.createInternalStyleSpec;exports.createNumberedListItemBlockConfig=c.createNumberedListItemBlockConfig;exports.createNumberedListItemBlockSpec=c.createNumberedListItemBlockSpec;exports.createParagraphBlockConfig=c.createParagraphBlockConfig;exports.createParagraphBlockSpec=c.createParagraphBlockSpec;exports.createQuoteBlockConfig=c.createQuoteBlockConfig;exports.createQuoteBlockSpec=c.createQuoteBlockSpec;exports.createStyleSpec=c.createStyleSpec;exports.createStyleSpecFromTipTapMark=c.createStyleSpecFromTipTapMark;exports.createTableBlockSpec=c.createTableBlockSpec;exports.createToggleListItemBlockConfig=c.createToggleListItemBlockConfig;exports.createToggleListItemBlockSpec=c.createToggleListItemBlockSpec;exports.createToggleWrapper=c.createToggleWrapper;exports.createVideoBlockConfig=c.createVideoBlockConfig;exports.createVideoBlockSpec=c.createVideoBlockSpec;exports.defaultBlockSpecs=c.defaultBlockSpecs;exports.defaultBlockToHTML=c.defaultBlockToHTML;exports.defaultInlineContentSchema=c.defaultInlineContentSchema;exports.defaultInlineContentSpecs=c.defaultInlineContentSpecs;exports.defaultProps=c.defaultProps;exports.defaultStyleSchema=c.defaultStyleSchema;exports.defaultStyleSpecs=c.defaultStyleSpecs;exports.defaultToggledState=c.defaultToggledState;exports.editorHasBlockWithType=c.editorHasBlockWithType;exports.fileParse=c.fileParse;exports.filenameFromURL=c.filenameFromURL;exports.formatKeyboardShortcut=c.formatKeyboardShortcut;exports.getBackgroundColorAttribute=c.getBackgroundColorAttribute;exports.getBlockFromPos=c.getBlockFromPos;exports.getInlineContentSchemaFromSpecs=c.getInlineContentSchemaFromSpecs;exports.getLanguageId=c.getLanguageId;exports.getNodeById=c.getNodeById;exports.getParseRules=c.getParseRules;exports.getStyleParseRules=c.getStyleParseRules;exports.getStyleSchemaFromSpecs=c.getStyleSchemaFromSpecs;exports.getTextAlignmentAttribute=c.getTextAlignmentAttribute;exports.getTextColorAttribute=c.getTextColorAttribute;exports.imageParse=c.imageParse;exports.imageRender=c.imageRender;exports.imageToExternalHTML=c.imageToExternalHTML;exports.isAppleOS=c.isAppleOS;exports.isNodeBlock=c.isNodeBlock;exports.isSafari=c.isSafari;exports.isTableCellSelection=c.isTableCellSelection;exports.isVideoUrl=c.isVideoUrl;exports.mergeCSSClasses=c.mergeCSSClasses;exports.mergeParagraphs=c.mergeParagraphs;exports.parseAudioElement=c.parseAudioElement;exports.parseDefaultProps=c.parseDefaultProps;exports.propsToAttributes=c.propsToAttributes;exports.stylePropsToAttributes=c.stylePropsToAttributes;exports.tablePropSchema=c.tablePropSchema;exports.trackPosition=c.trackPosition;exports.updateBlock=c.updateBlock;exports.updateBlockCommand=c.updateBlockCommand;exports.updateBlockTr=c.updateBlockTr;exports.videoParse=c.videoParse;exports.wrapInBlockStructure=c.wrapInBlockStructure;exports.blocksToMarkdown=S.blocksToMarkdown;exports.cleanHTMLToMarkdown=S.cleanHTMLToMarkdown;exports.createExternalHTMLExporter=S.createExternalHTMLExporter;exports.getBlocksChangedByTransaction=S.getBlocksChangedByTransaction;exports.BlockNoteSchema=M.BlockNoteSchema;exports.CustomBlockNoteSchema=M.CustomBlockNoteSchema;exports.checkPageBreakBlocksInSchema=M.checkPageBreakBlocksInSchema;exports.createPageBreakBlockConfig=M.createPageBreakBlockConfig;exports.createPageBreakBlockSpec=M.createPageBreakBlockSpec;exports.getPageBreakSlashMenuItems=M.getPageBreakSlashMenuItems;exports.uploadToTmpFilesDotOrg_DEV_ONLY=M.uploadToTmpFilesDotOrg_DEV_ONLY;exports.withPageBreak=M.withPageBreak;exports.EventEmitter=U.EventEmitter;exports.createExtension=V.createExtension;exports.createStore=V.createStore;exports.BlockNoteEditor=j;exports.Exporter=no;exports.HTMLToBlocks=R;exports.combineByGroup=so;exports.createInlineContentSpec=Oe;exports.createInternalHTMLSerializer=ie;exports.fixColumnList=_;exports.getBlock=pe;exports.getInlineContentParseRules=te;exports.getNextBlock=he;exports.getParentBlock=me;exports.getPrevBlock=fe;exports.insertBlocks=oe;exports.isEmptyColumn=L;exports.mappingFactory=ro;exports.markdownToBlocks=ke;exports.markdownToHTML=G;exports.removeAndInsertBlocks=O;exports.removeEmptyColumns=ne;exports.selectedFragmentToHTML=q;
5
5
  //# sourceMappingURL=blocknote.cjs.map