@blocknote/core 0.41.1 → 0.42.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.
- package/dist/BlockNoteSchema-Bi-eeHal.js +3288 -0
- package/dist/BlockNoteSchema-Bi-eeHal.js.map +1 -0
- package/dist/BlockNoteSchema-DjDaA2C3.cjs +6 -0
- package/dist/BlockNoteSchema-DjDaA2C3.cjs.map +1 -0
- package/dist/blockToNode-DIfPWLH8.js +1140 -0
- package/dist/blockToNode-DIfPWLH8.js.map +1 -0
- package/dist/blockToNode-w7H99R6p.cjs +7 -0
- package/dist/blockToNode-w7H99R6p.cjs.map +1 -0
- package/dist/blocknote.cjs +4 -4
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1413 -1366
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +49 -49
- package/dist/comments.js.map +1 -1
- package/dist/en-Cl87Uuyf.cjs.map +1 -1
- package/dist/en-njEqD7AG.js.map +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.cjs +2 -0
- package/dist/yjs.cjs.map +1 -0
- package/dist/yjs.js +44 -0
- package/dist/yjs.js.map +1 -0
- package/package.json +30 -25
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +19 -6
- package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +173 -0
- package/src/api/nodeConversions/nodeToBlock.ts +17 -14
- package/src/blocks/Code/block.ts +1 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +2 -1
- package/src/blocks/defaultBlockTypeGuards.ts +7 -18
- package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +3 -1
- package/src/editor/BlockNoteEditor.test.ts +70 -1
- package/src/editor/BlockNoteEditor.ts +55 -4
- package/src/editor/managers/ExportManager.ts +1 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
- package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +10 -3
- package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.ts +130 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +34 -21
- package/src/extensions/Comments/CommentsPlugin.ts +37 -7
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +30 -128
- package/src/extensions/SideMenu/SideMenuPlugin.ts +2 -0
- package/src/index.ts +1 -0
- package/src/schema/inlineContent/createSpec.ts +3 -0
- package/src/schema/inlineContent/types.ts +1 -0
- package/src/schema/schema.ts +49 -6
- package/src/schema/styles/createSpec.ts +6 -0
- package/src/schema/styles/types.ts +1 -0
- package/src/yjs/index.ts +1 -0
- package/src/yjs/utils.test.ts +1023 -0
- package/src/yjs/utils.ts +150 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +32 -0
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +1 -1
- package/types/src/editor/BlockNoteEditor.d.ts +6 -1
- package/types/src/editor/managers/ExportManager.d.ts +1 -1
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
- package/types/src/index.d.ts +1 -0
- package/types/src/schema/inlineContent/createSpec.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +1 -0
- package/types/src/schema/styles/createSpec.d.ts +1 -0
- package/types/src/schema/styles/types.d.ts +1 -0
- package/types/src/yjs/index.d.ts +1 -0
- package/types/src/yjs/utils.d.ts +55 -0
- package/types/src/yjs/utils.test.d.ts +1 -0
- package/dist/BlockNoteSchema-COA0fsXW.cjs +0 -11
- package/dist/BlockNoteSchema-COA0fsXW.cjs.map +0 -1
- package/dist/BlockNoteSchema-CYRHak18.js +0 -4375
- package/dist/BlockNoteSchema-CYRHak18.js.map +0 -1
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +0 -46
- package/src/extensions/TextColor/TextColorMark.ts +0 -38
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +0 -10
- package/types/src/extensions/TextColor/TextColorMark.d.ts +0 -10
package/dist/blocknote.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+u)}return{insertedBlocks:r.map(u=>a.nodeToBlock(u,o)),removedBlocks:i}}function Ve(n){const t=Array.from(n.classList).filter(e=>!e.startsWith("bn-"))||[];t.length>0?n.className=t.join(" "):n.removeAttribute("class")}function $e(n,t,e,o){var c;let r;if(t)if(typeof t=="string")r=a.inlineContentToNodes([t],n.pmSchema);else if(Array.isArray(t))r=a.inlineContentToNodes(t,n.pmSchema);else if(t.type==="tableContent")r=a.tableContentToNodes(t,n.pmSchema);else throw new a.UnreachableCaseError(t.type);else throw new Error("blockContent is required");const i=((o==null?void 0:o.document)??document).createDocumentFragment();for(const l of r)if(l.type.name!=="text"&&n.schema.inlineContentSchema[l.type.name]){const d=n.schema.inlineContentSpecs[l.type.name].implementation;if(d){const u=a.nodeToCustomInlineContent(l,n.schema.inlineContentSchema,n.schema.styleSchema),p=d.toExternalHTML?d.toExternalHTML(u,n):d.render.call({renderType:"dom",props:void 0},u,()=>{},n);if(p){if(i.appendChild(p.dom),p.contentDOM){const m=e.serializeFragment(l.content,o);p.contentDOM.dataset.editable="",p.contentDOM.appendChild(m)}continue}}}else if(l.type.name==="text"){let d=document.createTextNode(l.textContent);for(const u of l.marks.toReversed())if(u.type.name in n.schema.styleSpecs){const p=(n.schema.styleSpecs[u.type.name].implementation.toExternalHTML??n.schema.styleSpecs[u.type.name].implementation.render)(u.attrs.stringValue,n);p.contentDOM.appendChild(d),d=p.dom}else{const p=u.type.spec.toDOM(u,!0),m=P.DOMSerializer.renderSpec(document,p);m.contentDOM.appendChild(d),d=m.dom}i.appendChild(d)}else{const d=e.serializeFragment(P.Fragment.from([l]),o);i.appendChild(d)}return i.childNodes.length===1&&((c=i.firstChild)==null?void 0:c.nodeType)===1&&Ve(i.firstChild),i}function po(n,t,e,o,r,s,i){var b,y,C,N,H,z,K,q,G;const c=(i==null?void 0:i.document)??document,l=t.pmSchema.nodes.blockContainer,d=e.props||{};for(const[M,x]of Object.entries(t.schema.blockSchema[e.type].propSchema))!(M in d)&&x.default!==void 0&&(d[M]=x.default);const u=(y=(b=l.spec)==null?void 0:b.toDOM)==null?void 0:y.call(b,l.create({id:e.id,...d})),p=Array.from(u.dom.attributes),m=t.blockImplementations[e.type].implementation,f=((C=m.toExternalHTML)==null?void 0:C.call({},{...e,props:d},t))||m.render.call({},{...e,props:d},t),k=c.createDocumentFragment();if(f.dom.classList.contains("bn-block-content")){const M=[...p,...Array.from(f.dom.attributes)].filter(x=>x.name.startsWith("data")&&x.name!=="data-content-type"&&x.name!=="data-file-block"&&x.name!=="data-node-view-wrapper"&&x.name!=="data-node-type"&&x.name!=="data-id"&&x.name!=="data-editable");for(const x of M)f.dom.firstChild.setAttribute(x.name,x.value);Ve(f.dom.firstChild),k.append(...Array.from(f.dom.childNodes))}else k.append(f.dom);if(f.contentDOM&&e.content){const M=$e(t,e.content,o,i);f.contentDOM.appendChild(M)}let g;if(r.has(e.type)?g="OL":s.has(e.type)&&(g="UL"),g){if(((N=n.lastChild)==null?void 0:N.nodeName)!==g){const M=c.createElement(g);g==="OL"&&"start"in d&&d.start&&(d==null?void 0:d.start)!==1&&M.setAttribute("start",d.start+""),n.append(M)}n.lastChild.appendChild(k)}else n.append(k);if(e.children&&e.children.length>0){const M=c.createDocumentFragment();if(ze(M,t,e.children,o,r,s,i),((H=n.lastChild)==null?void 0:H.nodeName)==="UL"||((z=n.lastChild)==null?void 0:z.nodeName)==="OL")for(;((K=M.firstChild)==null?void 0:K.nodeName)==="UL"||((q=M.firstChild)==null?void 0:q.nodeName)==="OL";)n.lastChild.lastChild.appendChild(M.firstChild);t.pmSchema.nodes[e.type].isInGroup("blockContent")?n.append(M):(G=f.contentDOM)==null||G.append(M)}}const ze=(n,t,e,o,r,s,i)=>{for(const c of e)po(n,t,c,o,r,s,i)},mo=(n,t,e,o,r,s)=>{const c=((s==null?void 0:s.document)??document).createDocumentFragment();return ze(c,n,t,e,o,r,s),c},Y=(n,t)=>{const e=P.DOMSerializer.fromSchema(n);return{exportBlocks:(o,r)=>{const s=mo(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=$e(t,o,e,r),i=document.createElement("div");return i.append(s.cloneNode(!0)),i.innerHTML}}};function fo(n,t,e,o,r){let s;if(t)if(typeof t=="string")s=a.inlineContentToNodes([t],n.pmSchema,o);else if(Array.isArray(t))s=a.inlineContentToNodes(t,n.pmSchema,o);else if(t.type==="tableContent")s=a.tableContentToNodes(t,n.pmSchema);else throw new a.UnreachableCaseError(t.type);else throw new Error("blockContent is required");const c=((r==null?void 0:r.document)??document).createDocumentFragment();for(const l of s)if(l.type.name!=="text"&&n.schema.inlineContentSchema[l.type.name]){const d=n.schema.inlineContentSpecs[l.type.name].implementation;if(d){const u=a.nodeToCustomInlineContent(l,n.schema.inlineContentSchema,n.schema.styleSchema),p=d.render.call({renderType:"dom",props:void 0},u,()=>{},n);if(p){if(c.appendChild(p.dom),p.contentDOM){const m=e.serializeFragment(l.content,r);p.contentDOM.dataset.editable="",p.contentDOM.appendChild(m)}continue}}}else if(l.type.name==="text"){let d=document.createTextNode(l.textContent);for(const u of l.marks.toReversed())if(u.type.name in n.schema.styleSpecs){const p=n.schema.styleSpecs[u.type.name].implementation.render(u.attrs.stringValue,n);p.contentDOM.appendChild(d),d=p.dom}else{const p=u.type.spec.toDOM(u,!0),m=P.DOMSerializer.renderSpec(document,p);m.contentDOM.appendChild(d),d=m.dom}c.appendChild(d)}else{const d=e.serializeFragment(P.Fragment.from([l]),r);c.appendChild(d)}return c}function go(n,t,e,o){var p,m,f,k,g;const r=n.pmSchema.nodes.blockContainer,s=t.props||{};for(const[b,y]of Object.entries(n.schema.blockSchema[t.type].propSchema))!(b in s)&&y.default!==void 0&&(s[b]=y.default);const i=t.children||[],l=n.blockImplementations[t.type].implementation.render.call({renderType:"dom",props:void 0},{...t,props:s,children:i},n);if(l.contentDOM&&t.content){const b=fo(n,t.content,e,t.type,o);l.contentDOM.appendChild(b)}if(n.pmSchema.nodes[t.type].isInGroup("bnBlock")){if(t.children&&t.children.length>0){const b=Ke(n,t.children,e,o);(p=l.contentDOM)==null||p.append(b)}return l.dom}const u=(f=(m=r.spec)==null?void 0:m.toDOM)==null?void 0:f.call(m,r.create({id:t.id,...s}));return(k=u.contentDOM)==null||k.appendChild(l.dom),t.children&&t.children.length>0&&((g=u.contentDOM)==null||g.appendChild(qe(n,t.children,e,o))),u.dom}function Ke(n,t,e,o){const s=((o==null?void 0:o.document)??document).createDocumentFragment();for(const i of t){const c=go(n,i,e,o);s.appendChild(c)}return s}const qe=(n,t,e,o)=>{var c;const r=n.pmSchema.nodes.blockGroup,s=r.spec.toDOM(r.create({})),i=Ke(n,t,e,o);return(c=s.contentDOM)==null||c.appendChild(i),s.dom},Ge=(n,t)=>{const e=P.DOMSerializer.fromSchema(n);return{serializeBlocks:(o,r)=>qe(t,o,e,r).outerHTML}};function ko(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(a.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 ve(n){const t="__root__",e={},o={},r=a.getPmSchema(n);return n.descendants((s,i)=>{if(!a.isNodeBlock(s))return!0;const c=ko(n,i),l=c??t;o[l]||(o[l]=[]);const d=a.nodeToBlock(s,r);return e[s.attrs.id]={block:d,parentId:c},o[l].push(s.attrs.id),!0}),{byId:e,childrenByParent:o}}function yo(n,t){const e=new Set;if(!n||!t)return e;const o=new Set(n),r=t.filter(g=>o.has(g)),s=n.filter(g=>r.includes(g));if(s.length<=1||r.length<=1)return e;const i={};for(let g=0;g<s.length;g++)i[s[g]]=g;const c=r.map(g=>i[g]),l=c.length,d=[],u=[],p=new Array(l).fill(-1),m=(g,b)=>{let y=0,C=g.length;for(;y<C;){const N=y+C>>>1;g[N]<b?y=N+1:C=N}return y};for(let g=0;g<l;g++){const b=c[g],y=m(d,b);y>0&&(p[g]=u[y-1]),y===d.length?(d.push(b),u.push(g)):(d[y]=b,u[y]=g)}const f=new Set;let k=u[u.length-1]??-1;for(;k!==-1;)f.add(k),k=p[k];for(let g=0;g<r.length;g++)f.has(g)||e.add(r[g]);return e}function he(n,t=[]){const e=bo(n),o=S.combineTransactionSteps(n.before,[n,...t]),r=ve(o.before),s=ve(o.doc),i=[],c=new Set;Object.keys(s.byId).filter(f=>!(f in r.byId)).forEach(f=>{i.push({type:"insert",block:s.byId[f].block,source:e,prevBlock:void 0}),c.add(f)}),Object.keys(r.byId).filter(f=>!(f in s.byId)).forEach(f=>{i.push({type:"delete",block:r.byId[f].block,source:e,prevBlock:void 0}),c.add(f)}),Object.keys(s.byId).filter(f=>f in r.byId).forEach(f=>{var y,C;const k=r.byId[f],g=s.byId[f];k.parentId!==g.parentId?(i.push({type:"move",block:g.block,prevBlock:k.block,source:e,prevParent:k.parentId?(y=r.byId[k.parentId])==null?void 0:y.block:void 0,currentParent:g.parentId?(C=s.byId[g.parentId])==null?void 0:C.block:void 0}),c.add(f)):ro.default({...k.block,children:void 0},{...g.block,children:void 0})||(i.push({type:"update",block:g.block,prevBlock:k.block,source:e}),c.add(f))});const l=r.childrenByParent,d=s.childrenByParent,u="__root__",p=new Set([...Object.keys(l),...Object.keys(d)]),m=new Set;return p.forEach(f=>{const k=yo(l[f],d[f]);k.size!==0&&k.forEach(g=>{var N,H;const b=r.byId[g],y=s.byId[g];!b||!y||b.parentId!==y.parentId||c.has(g)||(b.parentId??u)!==f||m.has(g)||(m.add(g),i.push({type:"move",block:y.block,prevBlock:b.block,source:e,prevParent:b.parentId?(N=r.byId[b.parentId])==null?void 0:N.block:void 0,currentParent:y.parentId?(H=s.byId[y.parentId])==null?void 0:H.block:void 0}),c.add(g))})}),i}const pe=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function wo(n,t){if(!n.startsWith(".")||!t.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return n===t}function So(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 Pe(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 je(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 pe)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 d of Object.values(t.schema.blockSpecs))for(const u of((s=d.implementation.meta)==null?void 0:s.fileBlockAccept)||[]){const p=u.startsWith("."),m=r[i].getAsFile();if(m&&(!p&&m.type&&So(r[i].type,u)||p&&wo("."+m.name.split(".").pop(),u))){c=d.config.type;break}}const l=r[i].getAsFile();if(l){const d={type:c,props:{name:l.name}};let u;if(n.type==="paste"){const f=t.getTextCursorPosition().block;u=Pe(t,f,d)}else if(n.type==="drop"){const f={left:n.clientX,top:n.clientY},k=t.prosemirrorView.posAtCoords(f);if(!k)return;u=t.transact(g=>{const b=a.getNearestBlockPos(g.doc,k.pos),y=t.prosemirrorView.dom.querySelector(`[data-id="${b.node.attrs.id}"]`),C=y==null?void 0:y.getBoundingClientRect();return Pe(t,t.getBlock(b.node.attrs.id),d,C&&(C.top+C.bottom)/2>f.top?"before":"after")})}else return;const p=await t.uploadFile(l,u),m=typeof p=="string"?{props:{url:p}}:{...p};t.updateBlock(u,m)}}}}const Co=n=>S.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{drop(t,e){if(!n.isEditable)return;let o=null;for(const r of pe)if(e.dataTransfer.types.includes(r)){o=r;break}return o===null?!0:o==="Files"?(je(e,n),!0):!1}}}})]}}),Bo=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,vo=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,Po=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,To=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,Eo=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,Mo=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,xo=/\n{2} {0,3}-{2,48}\n{2}/,Io=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,Do=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,Lo=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,No=/^\s*\|(.+\|)+\s*$/m,Ao=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,_o=/^\s*\|(.+\|)+\s*$/m,Oo=n=>Bo.test(n)||vo.test(n)||Po.test(n)||To.test(n)||Eo.test(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);async function Ho(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 Uo({event:n,editor:t,prioritizeMarkdownOverHTML:e,plainTextAsMarkdown:o}){var c;if(t.transact(l=>l.selection.$from.parent.type.spec.code&&l.selection.$to.parent.type.spec.code)){const l=(c=n.clipboardData)==null?void 0:c.getData("text/plain");if(l)return t.pasteText(l),!0}let s;for(const l of pe)if(n.clipboardData.types.includes(l)){s=l;break}if(!s)return!0;if(s==="vscode-editor-data")return Ho(n,t.prosemirrorView),!0;if(s==="Files")return je(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 l=n.clipboardData.getData("text/plain");if(Oo(l))return t.pasteMarkdown(l),!0}return s==="text/html"?(t.pasteHTML(i),!0):o?(t.pasteMarkdown(i),!0):(t.pasteText(i),!0)}const Ro=(n,t)=>S.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{paste(e,o){if(o.preventDefault(),!!n.isEditable)return t({event:o,editor:n,defaultPasteHandler:({prioritizeMarkdownOverHTML:r=!0,plainTextAsMarkdown:s=!0}={})=>Uo({event:o,editor:n,prioritizeMarkdownOverHTML:r,plainTextAsMarkdown:s})})}}}})]}});function Fo(){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 Vo(){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,Jt.fromDom(document.createTextNode(" ")))):n(r)}};return n}function $o(){return n=>{Qt.visit(n,"element",(t,e,o)=>{var r,s,i,c;if(o&&t.tagName==="video"){const l=((r=t.properties)==null?void 0:r.src)||((s=t.properties)==null?void 0:s["data-url"])||"",d=((i=t.properties)==null?void 0:i.title)||((c=t.properties)==null?void 0:c["data-name"])||"";o.children[e]={type:"text",value:``}}})}}function re(n){return He.unified().use(so.default,{fragment:!0}).use($o).use(Fo).use(Vo).use(io.default).use(Ue.default).use(ao.default,{handlers:{text:e=>e.value}}).processSync(n).value}function We(n,t,e,o){const s=Y(t,e).exportBlocks(n,o);return re(s)}function Ye(n){const t=[];return n.descendants(e=>{var r,s;const o=a.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(a.nodeToBlock(i,o))}),!1):e.type.isInGroup("bnBlock")?(t.push(a.nodeToBlock(e,o)),!1):!0}),t}function zo(n,t,e){var c;let o=!1;const r=n.state.selection instanceof D.CellSelection;if(!r){const l=n.state.doc.slice(n.state.selection.from,n.state.selection.to,!1).content,d=[];for(let u=0;u<l.childCount;u++)d.push(l.child(u));o=d.find(u=>u.type.isInGroup("bnBlock")||u.type.name==="blockGroup"||u.type.spec.group==="blockContent")===void 0,o&&(t=l)}let s;const i=Y(n.state.schema,e);if(r){((c=t.firstChild)==null?void 0:c.type.name)==="table"&&(t=t.firstChild.content);const l=a.contentNodeToTableContent(t,e.schema.inlineContentSchema,e.schema.styleSchema);s=`<table>${i.exportInlineContent(l,{})}</table>`}else if(o){const l=a.contentNodeToInlineContent(t,e.schema.inlineContentSchema,e.schema.styleSchema);s=i.exportInlineContent(l,{})}else{const l=Ye(t);s=i.exportBlocks(l,{})}return s}function me(n,t){"node"in n.state.selection&&n.state.selection.node.type.spec.group==="blockContent"&&t.transact(i=>i.setSelection(new w.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=zo(n,o,t),s=re(r);return{clipboardHTML:e,externalHTML:r,markdown:s}}const Te=()=>{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},Ee=(n,t,e)=>{e.preventDefault(),e.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=me(t,n);e.clipboardData.setData("blocknote/html",o),e.clipboardData.setData("text/html",r),e.clipboardData.setData("text/plain",s)},Ko=n=>S.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new w.Plugin({props:{handleDOMEvents:{copy(t,e){return Te()||Ee(n,t,e),!0},cut(t,e){return Te()||(Ee(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 w.NodeSelection(i.doc.resolve(t.state.selection.from-1)))),e.preventDefault(),e.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:s}=me(t,n);return e.dataTransfer.setData("blocknote/html",o),e.dataTransfer.setData("text/html",r),e.dataTransfer.setData("text/plain",s),!0}}}})]}}),qo=S.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{backgroundColor:a.getBackgroundColorAttribute()}}]}});class Go extends a.BlockNoteExtension{constructor(){super();h(this,"beforeChangeCallbacks",[]);this.addProsemirrorPlugin(new w.Plugin({key:new w.PluginKey("blockChange"),filterTransaction:e=>{let o;return this.beforeChangeCallbacks.reduce((r,s)=>r===!1?r:s({getChanges(){return o||(o=he(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 V=class V extends a.BlockNoteExtension{constructor(e){super();h(this,"provider");h(this,"recentlyUpdatedCursors");h(this,"renderCursor",(e,o)=>{let r=this.recentlyUpdatedCursors.get(o);if(!r){const s=(this.collaboration.renderCursor??V.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});h(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(T.yCursorPlugin(this.provider.awareness,{selectionBuilder:T.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),l=[r/255,s/255,i/255].map(u=>u<=.03928?u/12.92:Math.pow((u+.055)/1.055,2.4));return .2126*l[0]+.7152*l[1]+.0722*l[2]<=.179}};h(V,"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: ${V.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: ${V.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 W=V;class te extends a.BlockNoteExtension{static key(){return"ySyncPlugin"}constructor(t){super(),this.addProsemirrorPlugin(T.ySyncPlugin(t))}get priority(){return 1001}}class oe extends a.BlockNoteExtension{static key(){return"yUndoPlugin"}constructor({editor:t}){super(),this.addProsemirrorPlugin(T.yUndoPlugin({trackedOrigins:[t]}))}get priority(){return 1e3}}class Xe extends a.BlockNoteExtension{constructor({editor:e,collaboration:o}){super(e);h(this,"editor");h(this,"collaboration");h(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=O.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 O.Doc;O.applyUpdate(o,O.encodeStateAsUpdate(e.doc));const r=this.findTypeInOtherYdoc(e,o);this.forkedState={undoStack:T.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack,originalFragment:e,forkedFragment:r},this.editor._tiptapEditor.unregisterPlugin([T.yCursorPluginKey,T.yUndoPluginKey,T.ySyncPluginKey]),this.editor._tiptapEditor.registerPlugin(new te(r).plugins[0]),this.editor._tiptapEditor.registerPlugin(new oe({editor:this.editor}).plugins[0]),this.emit("forked",!0)}merge({keepChanges:e}){if(!this.forkedState)return;this.editor._tiptapEditor.unregisterPlugin(T.ySyncPluginKey),this.editor._tiptapEditor.unregisterPlugin(T.yUndoPluginKey);const{originalFragment:o,forkedFragment:r,undoStack:s}=this.forkedState;if(this.editor.extensions.ySyncPlugin=new te(o),this.editor.extensions.yCursorPlugin=new W(this.collaboration),this.editor.extensions.yUndoPlugin=new oe({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]),T.yUndoPluginKey.getState(this.editor.prosemirrorState).undoManager.undoStack=s,e){const i=O.encodeStateAsUpdate(r.doc,O.encodeStateVector(o.doc));O.applyUpdate(o.doc,i,this.editor)}this.forkedState=void 0,this.emit("forked",!1)}}const Je=(n,t)=>{t(n),n.forEach(e=>{e instanceof O.XmlElement&&Je(e,t)})},jo=(n,t)=>{const e={};n.forEach(o=>{o instanceof O.XmlElement&&Je(o,r=>{if(r.nodeName==="blockContainer"&&r.hasAttribute("id")){const s={textColor:r.getAttribute("textColor"),backgroundColor:r.getAttribute("backgroundColor")};s.textColor===a.defaultProps.textColor.default&&(s.textColor=void 0),s.backgroundColor===a.defaultProps.backgroundColor.default&&(s.backgroundColor=void 0),(s.textColor||s.backgroundColor)&&(e[r.getAttribute("id")]=s)}})}),t.doc.descendants((o,r)=>{o.type.name==="blockContainer"&&e[o.attrs.id]&&(t=t.setNodeMarkup(r+1,void 0,e[o.attrs.id]))})},Wo=[jo];class fe extends a.BlockNoteExtension{constructor(e){const o=new w.PluginKey(fe.key());super();h(this,"migrationDone",!1);this.addProsemirrorPlugin(new w.Plugin({key:o,appendTransaction:(r,s,i)=>{if(this.migrationDone||r.length!==1||!r[0].getMeta(T.ySyncPluginKey))return;const c=i.tr;for(const l of Wo)l(e,c);return this.migrationDone=!0,c}}))}static key(){return"schemaMigrationPlugin"}}const ne=S.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",S.mergeAttributes(n,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(n){return n.name==="comment"?{blocknoteIgnore:!0}:{}}});class Yo extends a.EventEmitter{constructor(e){super();h(this,"userCache",new Map);h(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 X=new w.PluginKey("blocknote-comments"),Xo="SET_SELECTED_THREAD_ID";function Jo(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,l=c+o.nodeSize,d=e.get(i)??{from:1/0,to:0};e.set(i,{from:Math.min(c,d.from),to:Math.max(l,d.to)})}})}),e}class Qe extends a.BlockNoteExtension{constructor(e,o,r,s,i){super();h(this,"userStore");h(this,"pendingComment",!1);h(this,"selectedThreadId");h(this,"threadPositions",new Map);h(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,l=i.attrs.threadId,d=e.get(l),u=!!(!d||d.resolved||d.deletedAt);if(u!==i.attrs.orphan){const p=Math.max(s,0),m=Math.min(s+r.nodeSize,o.doc.content.size-1,o.doc.content.size-1);o.removeMark(p,m,i),o.addMark(p,m,c.create({...i.attrs,orphan:u})),u&&this.selectedThreadId===l&&(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 Yo(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 w.Plugin({key:X,state:{init(){return{decorations:E.DecorationSet.empty}},apply(l,d){const u=l.getMeta(X);if(!l.docChanged&&!u)return d;const p=l.docChanged?Jo(l.doc,c.markType):c.threadPositions;(p.size>0||c.threadPositions.size>0)&&(c.threadPositions=p,c.emitStateUpdate());const m=[];if(c.selectedThreadId){const f=p.get(c.selectedThreadId);f&&m.push(E.Decoration.inline(f.from,f.to,{class:"bn-thread-mark-selected"}))}return{decorations:E.DecorationSet.create(l.doc,m)}}},props:{decorations(l){var d;return((d=X.getState(l))==null?void 0:d.decorations)??E.DecorationSet.empty},handleClick:(l,d,u)=>{if(u.button!==0)return;const p=l.state.doc.nodeAt(d);if(!p){c.selectThread(void 0);return}const m=p.marks.find(k=>k.type.name===r&&k.attrs.orphan!==!0),f=m==null?void 0:m.attrs.threadId;c.selectThread(f,!1)}}}))}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,o=!0){var r,s;if(this.selectedThreadId!==e&&(this.selectedThreadId=e,this.emitStateUpdate(),this.editor.transact(i=>i.setMeta(X,{name:Xo})),e&&o)){const i=this.threadPositions.get(e);if(!i)return;(s=(r=this.editor.prosemirrorView)==null?void 0:r.domAtPos(i.from).node)==null||s.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=T.ySyncPluginKey.getState(r.state),c={prosemirror:{head:s.head,anchor:s.anchor},yjs:i?T.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 Ze{constructor(t,e,o,r){h(this,"state");h(this,"emitUpdate");h(this,"mouseDownHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});h(this,"dragstartHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});h(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()}});h(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,l;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 d=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);if(!d)return;this.state={show:!0,referencePos:d.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&&((l=this.state)!=null&&l.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 ae=new w.PluginKey("FilePanelPlugin");class et extends a.BlockNoteExtension{constructor(e){super();h(this,"view");h(this,"closeMenu",()=>{var e;return(e=this.view)==null?void 0:e.closeMenu()});this.addProsemirrorPlugin(new w.Plugin({key:ae,view:o=>(this.view=new Ze(e,ae,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(ae);return s||(!o.getMeta(T.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 tt{constructor(t,e,o){h(this,"state");h(this,"emitUpdate");h(this,"preventHide",!1);h(this,"preventShow",!1);h(this,"shouldShow",({view:t,state:e,from:o,to:r})=>{const{doc:s,selection:i}=e,{empty:c}=i,l=!s.textBetween(o,r).length&&S.isTextSelection(e.selection);if(i.$from.parent.type.spec.code||S.isNodeSelection(i)&&i.node.type.spec.code||c||l)return!1;const d=document.activeElement;return!(!this.isElementWithinEditorWrapper(d)&&t.editable)});h(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())});h(this,"isElementWithinEditorWrapper",t=>{if(!t)return!1;const e=this.pmView.dom.parentElement;return e?e.contains(t):!1});h(this,"viewMousedownHandler",t=>{(!this.isElementWithinEditorWrapper(t.target)||t.button===0)&&(this.preventShow=!0)});h(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))});h(this,"dragHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.show=!1,this.emitUpdate())});h(this,"scrollHandler",()=>{var t;(t=this.state)!=null&&t.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())});h(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 f,k,g;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:l}=i,d=Math.min(...l.map(b=>b.$from.pos)),u=Math.max(...l.map(b=>b.$to.pos)),p=this.shouldShow({view:t,state:o,from:d,to:u}),m=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(p||this.preventHide)&&!m){const b=this.getSelectionBoundingBox();if(b.height===0&&b.width===0){queueMicrotask(()=>{const C={show:!0,referencePos:this.getSelectionBoundingBox()};this.state=C,this.emitUpdate(),t.dispatch(t.state.tr.setSelection(w.TextSelection.create(t.state.doc,t.state.selection.from+1,t.state.selection.to))),t.dispatch(t.state.tr.setSelection(w.TextSelection.create(t.state.doc,t.state.selection.from-1,t.state.selection.to)))});return}const y={show:!0,referencePos:this.getSelectionBoundingBox()};(y.show!==((f=this.state)==null?void 0:f.show)||y.referencePos.toJSON()!==((k=this.state)==null?void 0:k.referencePos.toJSON()))&&(this.state=y,this.emitUpdate());return}if((g=this.state)!=null&&g.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(S.isNodeSelection(e)){const i=this.pmView.nodeDOM(r);if(i)return i.getBoundingClientRect()}return S.posToDOMRect(this.pmView,r,s)}}const ot=new w.PluginKey("FormattingToolbarPlugin");class nt extends a.BlockNoteExtension{constructor(e){super();h(this,"view");h(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new w.Plugin({key:ot,view:o=>(this.view=new tt(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 Qo=S.Node.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:n}){return["br",S.mergeAttributes(this.options.HTMLAttributes,n)]},renderText(){return`
|
|
4
|
-
`}}),Me=(n,t)=>{const e=n.resolve(t);if(e.depth<=1)return;const o=e.posAtIndex(e.index(e.depth-1),e.depth-1);return a.getBlockInfoFromResolvedPos(n.resolve(o))},ee=(n,t)=>{const e=n.resolve(t),o=e.index();if(o===0)return;const r=e.posAtIndex(o-1);return a.getBlockInfoFromResolvedPos(n.resolve(r))},rt=(n,t)=>{for(;t.childContainer;){const e=t.childContainer.node,o=n.resolve(t.childContainer.beforePos+1).posAtIndex(e.childCount-1);t=a.getBlockInfoFromResolvedPos(n.resolve(o))}return t},Zo=(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*",en=(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},xe=n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n),r=a.getBlockInfoFromResolvedPos(o),s=ee(t.doc,r.bnBlock.beforePos);if(!s)return!1;const i=rt(t.doc,s);return Zo(i,r)?en(t,e,i,r):!1};function tn(n,t,e){const{$from:o,$to:r}=n.selection,s=o.blockRange(r,k=>k.childCount>0&&(k.type.name==="blockGroup"||k.type.name==="column"));if(!s)return!1;const i=s.startIndex;if(i===0)return!1;const l=s.parent.child(i-1);if(l.type!==t)return!1;const d=l.lastChild&&l.lastChild.type===e,u=P.Fragment.from(d?t.create():null),p=new P.Slice(P.Fragment.from(t.create(null,P.Fragment.from(e.create(null,u)))),d?3:1,0),m=s.start,f=s.end;return n.step(new j.ReplaceAroundStep(m-(d?3:1),f,m,f,p,1,!0)).scrollIntoView(),!0}function st(n){return n.transact(t=>tn(t,n.pmSchema.nodes.blockContainer,n.pmSchema.nodes.blockGroup))}function on(n){n._tiptapEditor.commands.liftListItem("blockContainer")}function nn(n){return n.transact(t=>{const{bnBlock:e}=a.getBlockInfoFromTransaction(t);return t.doc.resolve(e.beforePos).nodeBefore!==null})}function rn(n){return n.transact(t=>{const{bnBlock:e}=a.getBlockInfoFromTransaction(t);return t.doc.resolve(e.beforePos).depth>1})}const sn=S.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=a.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;const c=s.selection.from===i.blockContent.beforePos+1,l=i.blockContent.node.type.name==="paragraph";return c&&!l?r.command(a.updateBlockCommand(i.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>r.command(({state:s})=>{const i=a.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=a.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;const{bnBlock:c,blockContent:l}=i,d=s.selection.from===l.beforePos+1,u=s.selection.empty,p=c.beforePos;return d&&u?o().command(xe(p)).scrollIntoView().run():!1}),()=>r.command(({state:s,dispatch:i})=>{const c=a.getBlockInfoFromSelection(s);if(!c.isBlockContainer||!(s.selection.from===c.blockContent.beforePos+1)||ee(s.doc,c.bnBlock.beforePos))return!1;const u=Me(s.doc,c.bnBlock.beforePos);if((u==null?void 0:u.blockNoteType)!=="column")return!1;const p=u,m=Me(s.doc,p.bnBlock.beforePos);if((m==null?void 0:m.blockNoteType)!=="columnList")throw new Error("parent of column is not a column list");const f=p.childContainer.node.childCount===1,k=f&&m.childContainer.node.childCount===2,g=m.childContainer.node.firstChild===p.bnBlock.node;if(i){const b=s.doc.slice(c.bnBlock.beforePos,c.bnBlock.afterPos,!1);if(k)if(g){s.tr.step(new j.ReplaceAroundStep(m.bnBlock.beforePos,m.bnBlock.afterPos,p.bnBlock.afterPos+1,m.bnBlock.afterPos-2,b,b.size,!1));const y=s.tr.doc.resolve(p.bnBlock.beforePos);s.tr.setSelection(w.TextSelection.between(y,y))}else{s.tr.step(new j.ReplaceAroundStep(m.bnBlock.beforePos,m.bnBlock.afterPos,m.bnBlock.beforePos+2,p.bnBlock.beforePos-1,b,0,!1));const y=s.tr.doc.resolve(s.tr.mapping.map(p.bnBlock.beforePos-1));s.tr.setSelection(w.TextSelection.between(y,y))}else if(f)if(g){s.tr.delete(p.bnBlock.beforePos,p.bnBlock.afterPos),s.tr.insert(m.bnBlock.beforePos,b.content);const y=s.tr.doc.resolve(m.bnBlock.beforePos);s.tr.setSelection(w.TextSelection.between(y,y))}else s.tr.delete(p.bnBlock.beforePos-1,p.bnBlock.beforePos+1);else{s.tr.delete(c.bnBlock.beforePos,c.bnBlock.afterPos),g?s.tr.insert(m.bnBlock.beforePos-1,b.content):s.tr.insert(p.bnBlock.beforePos-1,b.content);const y=s.tr.doc.resolve(p.bnBlock.beforePos-1);s.tr.setSelection(w.TextSelection.between(y,y))}}return!0}),()=>r.command(({state:s})=>{const i=a.getBlockInfoFromSelection(s);if(!i.isBlockContainer)return!1;if(i.blockContent.node.childCount===0&&i.blockContent.node.type.spec.content==="inline*"){const l=ee(s.doc,i.bnBlock.beforePos);if(!l||!l.isBlockContainer)return!1;let d=o();if(l.blockContent.node.type.spec.content==="tableRow+"){const k=i.bnBlock.beforePos-1-1-1-1-1;d=d.setTextSelection(k)}else if(l.blockContent.node.type.spec.content===""){const u=l.blockContent.afterPos-l.blockContent.node.nodeSize;d=d.setNodeSelection(u)}else{const u=l.blockContent.afterPos-l.blockContent.node.nodeSize;d=d.setTextSelection(u)}return d.deleteRange({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>r.command(({state:s})=>{const i=a.getBlockInfoFromSelection(s);if(!i.isBlockContainer)throw new Error("todo");const c=s.selection.from===i.blockContent.beforePos+1,l=s.selection.empty,d=ee(s.doc,i.bnBlock.beforePos);if(d&&c&&l){const u=rt(s.doc,d);if(!u.isBlockContainer)throw new Error("todo");if(u.blockContent.node.type.spec.content===""||u.blockContent.node.type.spec.content==="inline*"&&u.blockContent.node.childCount===0)return o().cut({from:i.bnBlock.beforePos,to:i.bnBlock.afterPos},u.bnBlock.afterPos).deleteRange({from:u.bnBlock.beforePos,to:u.bnBlock.afterPos}).run()}return!1})]),t=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:r})=>{const s=a.getBlockInfoFromSelection(r);if(!s.isBlockContainer)return!1;const{bnBlock:i,blockContent:c,childContainer:l}=s,{depth:d}=r.doc.resolve(i.beforePos),u=i.afterPos===r.doc.nodeSize-3,p=r.selection.from===c.afterPos-1,m=r.selection.empty;if(!u&&p&&m&&!(l!==void 0)){let k=d,g=i.afterPos+1,b=r.doc.resolve(g).depth;for(;b<k;)k=b,g+=2,b=r.doc.resolve(g).depth;return o.command(xe(g-1))}return!1})]),e=(o=!1)=>this.editor.commands.first(({commands:r,tr:s})=>[()=>r.command(({state:i})=>{const c=a.getBlockInfoFromSelection(i);if(!c.isBlockContainer)return!1;const{bnBlock:l,blockContent:d}=c,{depth:u}=i.doc.resolve(l.beforePos),p=i.selection.$anchor.parentOffset===0,m=i.selection.anchor===i.selection.head,f=d.node.childCount===0,k=u>1;return p&&m&&f&&k?r.liftListItem("blockContainer"):!1}),()=>r.command(({state:i})=>{var d;const c=a.getBlockInfoFromSelection(i),l=((d=this.options.editor.schema.blockSchema[c.blockNoteType].meta)==null?void 0:d.hardBreakShortcut)??"shift+enter";if(l==="none")return!1;if(l==="shift+enter"&&o||l==="enter"){const u=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(u),!0}return!1}),()=>r.command(({state:i,dispatch:c})=>{const l=a.getBlockInfoFromSelection(i);if(!l.isBlockContainer)return!1;const{bnBlock:d,blockContent:u}=l,p=i.selection.$anchor.parentOffset===0,m=i.selection.anchor===i.selection.head,f=u.node.childCount===0;if(p&&m&&f){const k=d.afterPos,g=k+2;if(c){const b=i.schema.nodes.blockContainer.createAndFill();i.tr.insert(k,b).scrollIntoView(),i.tr.setSelection(new w.TextSelection(i.doc.resolve(g)))}return!0}return!1}),()=>r.command(({state:i,chain:c})=>{const l=a.getBlockInfoFromSelection(i);if(!l.isBlockContainer)return!1;const{blockContent:d}=l,u=i.selection.$anchor.parentOffset===0;return d.node.childCount===0?!1:(c().deleteSelection().command(a.splitBlockCommand(i.selection.from,u,u)).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:st(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 an{constructor(t,e,o){h(this,"state");h(this,"emitUpdate");h(this,"menuUpdateTimer");h(this,"startMenuUpdateTimer");h(this,"stopMenuUpdateTimer");h(this,"mouseHoveredLinkMark");h(this,"mouseHoveredLinkMarkRange");h(this,"keyboardHoveredLinkMark");h(this,"keyboardHoveredLinkMarkRange");h(this,"linkMark");h(this,"linkMarkRange");h(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=S.getMarkRange(r,i.type,i.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});h(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())});h(this,"scrollHandler",()=>{var t;this.linkMark!==void 0&&(t=this.state)!=null&&t.show&&(this.state.referencePos=S.posToDOMRect(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())});h(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=a.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 l=this.pmView.state.selection.$from.marks();for(const d of l)if(d.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=d,this.keyboardHoveredLinkMarkRange=S.getMarkRange(this.pmView.state.selection.$from,d.type,d.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:S.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 it=new w.PluginKey("LinkToolbarPlugin");class at extends a.BlockNoteExtension{constructor(e){super();h(this,"view");h(this,"editLink",(e,o)=>{this.view.editLink(e,o)});h(this,"deleteLink",()=>{this.view.deleteLink()});h(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});h(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});h(this,"closeMenu",()=>this.view.closeMenu());this.addProsemirrorPlugin(new w.Plugin({key:it,view:o=>(this.view=new an(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 lt=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],ct="https",ln=new w.PluginKey("node-selection-keyboard");class cn extends a.BlockNoteExtension{static key(){return"nodeSelectionKeyboard"}constructor(){super(),this.addProsemirrorPlugin(new w.Plugin({key:ln,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 w.TextSelection(o.doc.resolve(t.state.tr.selection.$to.after()+1)))),!0}}return!1}}}))}}const dn=new w.PluginKey("blocknote-placeholder");class un extends a.BlockNoteExtension{static key(){return"placeholder"}constructor(t,e){super(),this.addProsemirrorPlugin(new w.Plugin({key:dn,view:o=>{const r=`placeholder-selector-${Zt.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,l=(d="")=>`.${r} .bn-block-content${d} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:d,emptyDocument:u,...p}=e;for(const[k,g]of Object.entries(p)){const b=`[data-content-type="${k}"]`;c.insertRule(`${l(b)} { content: ${JSON.stringify(g)}; }`)}const m="[data-is-only-empty-block]",f="[data-is-empty-and-focused]";c.insertRule(`${l(m)} { content: ${JSON.stringify(u)}; }`),c.insertRule(`${l(f)} { content: ${JSON.stringify(d)}; }`)}catch(d){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)",d)}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(E.Decoration.node(2,4,{"data-is-only-empty-block":"true"}));const c=s.$anchor,l=c.parent;if(l.content.size===0){const d=c.before();i.push(E.Decoration.node(d,d+l.nodeSize,{"data-is-empty-and-focused":"true"}))}return E.DecorationSet.create(r,i)}}}))}}const Ie=new w.PluginKey("previous-blocks"),hn={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class pn extends a.BlockNoteExtension{static key(){return"previousBlockType"}constructor(){super();let t;this.addProsemirrorPlugin(new w.Plugin({key:Ie,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(Ie,{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=S.findChildren(r.doc,u=>u.attrs.id),l=new Map(c.map(u=>[u.node.attrs.id,u])),d=S.findChildren(s.doc,u=>u.attrs.id);for(const u of d){const p=l.get(u.node.attrs.id),m=p==null?void 0:p.node.firstChild,f=u.node.firstChild;if(p&&m&&f){const k={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:s.doc.resolve(u.pos).depth},g={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:r.doc.resolve(p.pos).depth};i[u.node.attrs.id]=g,o.currentTransactionOldBlockAttrs[u.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(k)&&(g["depth-change"]=g.depth-k.depth,o.updatedBlocks.add(u.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],l={};for(const[u,p]of Object.entries(c))l["data-prev-"+hn[u]]=p||"none";const d=E.Decoration.node(i,i+s.nodeSize,{...l});r.push(d)}),E.DecorationSet.create(e.doc,r)}}}))}}const De=new w.PluginKey("blocknote-show-selection");class mn extends a.BlockNoteExtension{constructor(e){super();h(this,"enabled",!1);this.editor=e,this.addProsemirrorPlugin(new w.Plugin({key:De,props:{decorations:o=>{const{doc:r,selection:s}=o;if(!this.enabled)return E.DecorationSet.empty;const i=E.Decoration.inline(s.from,s.to,{"data-show-selection":"true"});return E.DecorationSet.create(r,[i])}}}))}static key(){return"showSelection"}setEnabled(e){this.enabled!==e&&(this.enabled=e,this.editor.transact(o=>o.setMeta(De,{})))}getEnabled(){return this.enabled}}function dt(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 R extends w.Selection{constructor(e,o){super(e,o);h(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 R(e.resolve(o),e.resolve(r))}content(){return new P.Slice(P.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof R)||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?w.Selection.near(e.resolve(r.pos)):r.deleted?w.Selection.near(e.resolve(s.pos)):new R(e.resolve(r.pos),e.resolve(s.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}}w.Selection.jsonID("multiple-node",R);let _;function fn(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),l=n.$to.end(i-1);e=t.resolve(c-1).pos,o=t.resolve(l+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function Le(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,m)=>Array.prototype.indexOf.call(p.children,m),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]);ut(n.root),_=o;const l=_.getElementsByTagName("iframe");for(let p=0;p<l.length;p++){const m=l[p],f=m.parentElement;f&&f.removeChild(m)}const u=n.dom.className.split(" ").filter(p=>p!=="ProseMirror"&&p!=="bn-root"&&p!=="bn-editor").join(" ");_.className=_.className+" bn-drag-preview "+u,n.root instanceof ShadowRoot?n.root.appendChild(_):n.root.body.appendChild(_)}function ut(n){_!==void 0&&(n instanceof ShadowRoot?n.removeChild(_):n.body.removeChild(_),_=void 0)}function gn(n,t,e){if(!n.dataTransfer||e.headless)return;const o=e.prosemirrorView,r=a.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:l,to:d}=fn(i,c),u=l<=s&&s<d,p=i.$anchor.node()!==i.$head.node()||i instanceof R;u&&p?(o.dispatch(o.state.tr.setSelection(R.create(c,l,d))),Le(o,l,d)):(o.dispatch(o.state.tr.setSelection(w.NodeSelection.create(o.state.doc,s))),Le(o,s));const m=o.state.selection.content(),f=e.pmSchema,k=o.serializeForClipboard(m).dom.innerHTML,g=Y(f,e),b=Ye(m.content),y=g.exportBlocks(b,{}),C=re(y);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",k),n.dataTransfer.setData("text/html",y),n.dataTransfer.setData("text/plain",C),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(_,0,0)}}const Ne=250;function de(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]")?de(n,{left:t.left+50,top:t.top},!1):dt(r,n)}function kn(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=de(t,o);if(!r)return;const s=r.node.getBoundingClientRect();return de(t,{left:s.right-10,top:n.y},!1)}class ht{constructor(t,e,o){h(this,"state");h(this,"emitUpdate");h(this,"mousePos");h(this,"hoveredBlock");h(this,"menuFrozen",!1);h(this,"isDragOrigin",!1);h(this,"updateState",t=>{this.state=t,this.emitUpdate(this.state)});h(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>Ne){(o=this.state)!=null&&o.show&&(this.state.show=!1,this.updateState(this.state));return}const e=kn(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 l=e.node.getBoundingClientRect(),d=e.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(d?d.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,l.y,l.width,l.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}});h(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=P.DOMParser.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new P.Slice(s.content,0,0),move:!0}});h(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,l=t.clientY<i.top?i.top-t.clientY:t.clientY>i.bottom?t.clientY-i.bottom:0,d=Math.sqrt(Math.pow(c,2)+Math.pow(l,2));d<r&&(r=d,o=s)}),{element:o,distance:r}});h(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)});h(this,"closeDropCursor",()=>{const t=new Event("dragleave",{bubbles:!1});t.synthetic=!0,this.pmView.dom.dispatchEvent(t)});h(this,"getDragEventContext",t=>{var l;const e=!((l=t.dataTransfer)!=null&&l.types.includes("blocknote/html"))&&!!this.pmView.dragging,o=!!this.isDragOrigin,r=e||o,s=this.findClosestEditorElement(t);if(!s||s.distance>Ne)return;const i=s.element===this.pmView.dom,c=i&&s.distance===0;if(!(!i&&!r))return{isDropPoint:i,isDropWithinEditorBounds:c,isDragOrigin:r}});h(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(w.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}});h(this,"onDragEnd",t=>{t.synthetic||(this.pmView.dragging=null)});h(this,"onKeyDown",t=>{var e;(e=this.state)!=null&&e.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))});h(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()});h(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 pt=new w.PluginKey("SideMenuPlugin");class mt extends a.BlockNoteExtension{constructor(e){super();h(this,"view");h(this,"blockDragStart",(e,o)=>{this.view&&(this.view.isDragOrigin=!0),gn(e,o,this.editor)});h(this,"blockDragEnd",()=>{ut(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)});h(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)});h(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=e,this.addProsemirrorPlugin(new w.Plugin({key:pt,view:o=>(this.view=new ht(e,o,r=>{this.emit("update",r)}),this.view)}))}static key(){return"sideMenu"}onUpdate(e){return this.on("update",e)}}const J=new Map;function bn(n){if(J.has(n))return J.get(n);const t=new j.Mapping;return n._tiptapEditor.on("transaction",({transaction:e})=>{t.appendMapping(e.mapping)}),n._tiptapEditor.on("destroy",()=>{J.delete(n)}),J.set(n,t),t}function ft(n,t,e="left"){const o=T.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=T.absolutePositionToRelativePosition(t+(e==="right"?1:-1),o.binding.type,o.binding.mapping);return()=>{const s=T.ySyncPluginKey.getState(n.prosemirrorState),i=T.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 yn=S.findParentNode(n=>n.type.name==="blockContainer");class wn{constructor(t,e,o){h(this,"state");h(this,"emitUpdate");h(this,"rootEl");h(this,"pluginState");h(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)}});h(this,"closeMenu",()=>{this.editor.transact(t=>t.setMeta($,null))});h(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 d;const o=$.getState(e),r=$.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 l=(d=this.rootEl)==null?void 0:d.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&l&&(this.state={show:!0,referencePos:l.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var t;(t=this.rootEl)==null||t.removeEventListener("scroll",this.handleScroll,!0)}}const $=new w.PluginKey("SuggestionMenuPlugin");class gt extends a.BlockNoteExtension{constructor(e){super();h(this,"view");h(this,"triggerCharacters",[]);h(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)});h(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==e)});h(this,"closeMenu",()=>this.view.closeMenu());h(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.addProsemirrorPlugin(new w.Plugin({key:$,view:r=>(this.view=new wn(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 l=r.getMeta($);if(typeof l=="object"&&l!==null){s&&this.closeMenu();const u=ft(e,c.selection.from-l.triggerCharacter.length);return{triggerCharacter:l.triggerCharacter,deleteTriggerCharacter:l.deleteTriggerCharacter!==!1,queryStartPos:()=>u()+l.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`,ignoreQueryLength:l==null?void 0:l.ignoreQueryLength}}if(s===void 0)return s;if(c.selection.from!==c.selection.to||l===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 d={...s};return d.query=c.doc.textBetween(s.queryStartPos(),c.selection.from),d}},props:{handleTextInput(r,s,i,c){if(s===i){const l=r.state.doc;for(const d of o){const u=d.length>1?l.textBetween(s-d.length,s)+c:c;if(d===u)return r.dispatch(r.state.tr.insertText(c)),r.dispatch(r.state.tr.setMeta($,{triggerCharacter:u}).scrollIntoView()),!0}}return!1},decorations(r){const s=this.getState(r);if(s===void 0)return null;if(!s.deleteTriggerCharacter){const i=yn(r.selection);if(i)return E.DecorationSet.create(r.doc,[E.Decoration.node(i.pos,i.pos+i.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":s.decorationId})])}return E.DecorationSet.create(r.doc,[E.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 Sn(n,t){n.suggestionMenus.addTriggerCharacter(t)}const Cn=S.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}}]}}}),Bn=S.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}}]}}}),vn=S.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 L;function Ae(n){L||(L=document.createElement("div"),L.innerHTML="_",L.style.opacity="0",L.style.height="1px",L.style.width="1px",n instanceof Document?n.body.appendChild(L):n.appendChild(L))}function Pn(n){L&&(n instanceof Document?n.body.removeChild(L):n.removeChild(L),L=void 0)}function Q(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function Tn(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 En(n,t){const e=t.querySelectorAll(n);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"}class kt{constructor(t,e,o){h(this,"state");h(this,"emitUpdate");h(this,"tableId");h(this,"tablePos");h(this,"tableElement");h(this,"menuFrozen",!1);h(this,"mouseState","up");h(this,"prevWasEditable",null);h(this,"viewMousedownHandler",()=>{this.mouseState="down"});h(this,"mouseUpHandler",t=>{this.mouseState="up",this.mouseMoveHandler(t)});h(this,"mouseMoveHandler",t=>{var d,u,p,m,f,k,g;if(this.menuFrozen||this.mouseState==="selecting"||!(t.target instanceof Element)||!this.pmView.dom.contains(t.target))return;const e=Tn(t.target);if((e==null?void 0:e.type)==="cell"&&this.mouseState==="down"&&!((d=this.state)!=null&&d.draggingState)){this.mouseState="selecting",(u=this.state)!=null&&u.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!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=dt(e.domNode,this.pmView);if(!r)return;this.tableElement=r.node;let s;const i=this.editor.transact(b=>a.getNodeById(r.id,b.doc));if(!i)throw new Error(`Block with ID ${r.id} not found`);const c=a.nodeToBlock(i.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(a.editorHasBlockWithType(this.editor,"table")&&(this.tablePos=i.posBeforeNode+1,s=c),!s)return;this.tableId=r.id;const l=(m=e.domNode.closest(".tableWrapper"))==null?void 0:m.querySelector(".table-widgets-container");if((e==null?void 0:e.type)==="wrapper"){const b=t.clientY>=o.bottom-1&&t.clientY<o.bottom+20,y=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:b,showAddOrRemoveColumnsButton:y,referencePosTable:o,block:s,widgetContainer:l,colIndex:C||(f=this.state)==null?void 0:f.colIndex,rowIndex:C||(k=this.state)==null?void 0:k.rowIndex,referencePosCell:C||(g=this.state)==null?void 0:g.referencePosCell}}else{const b=Q(e.domNode),y=Q(e.domNode.parentElement),C=e.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===r.id&&this.state.rowIndex===y&&this.state.colIndex===b)return;this.state={show:!0,showAddOrRemoveColumnsButton:b===s.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:y===s.content.rows.length-1,referencePosTable:o,block:s,draggingState:void 0,referencePosCell:C,colIndex:b,rowIndex:y,widgetContainer:l}}return this.emitUpdate(),!1});h(this,"dragOverHandler",t=>{var m;if(((m=this.state)==null?void 0:m.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",En(".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(f=>f.tagName==="TD"||f.tagName==="TH");if(o.length===0)return;const r=o[0];let s=!1;const i=Q(r.parentElement),c=Q(r),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,u=(this.state.draggingState.draggedCellOrientation==="row"?i:c)!==l;(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(),u&&this.editor.transact(f=>f.setMeta(F,!0))});h(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(!a.canRowBeDraggedInto(this.state.block,e.originalIndex,r))return!1;const i=a.moveRow(this.state.block,e.originalIndex,r);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:i}})}else{if(!a.canColumnBeDraggedInto(this.state.block,e.originalIndex,o))return!1;const i=a.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}=a.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 F=new w.PluginKey("TableHandlesPlugin");class bt extends a.BlockNoteExtension{constructor(e){super();h(this,"view");h(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(F,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.headless&&(Ae(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(L,0,0),e.dataTransfer.effectAllowed="move")});h(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(F,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.headless&&(Ae(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(L,0,0),e.dataTransfer.effectAllowed="copyMove")});h(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(F,null)),!this.editor.headless&&Pn(this.editor.prosemirrorView.root)});h(this,"freezeHandles",()=>{this.view.menuFrozen=!0});h(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});h(this,"getCellsAtRowHandle",(e,o)=>a.getCellsAtRowHandle(e,o));h(this,"getCellsAtColumnHandle",(e,o)=>a.getCellsAtColumnHandle(e,o));h(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),l=e.doc.resolve(c.posAtIndex(o.col)),d=e.doc.resolve(i.posAtIndex(r.row)+1),u=e.doc.resolve(d.posAtIndex(r.col)),p=e.tr;return p.setSelection(new D.CellSelection(l,u)),e.apply(p)});h(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"?D.addRowBefore(i,s):D.addRowAfter(i,s):o.side==="left"?D.addColumnBefore(i,s):D.addColumnAfter(i,s)})});h(this,"removeRowOrColumn",(e,o)=>o==="row"?this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:e,col:0});return D.deleteRow(i,s)}):this.editor.exec((r,s)=>{const i=this.setCellSelection(r,{row:0,col:e});return D.deleteColumn(i,s)}));h(this,"mergeCells",e=>this.editor.exec((o,r)=>{const s=e?this.setCellSelection(o,e.relativeStartCell,e.relativeEndCell):o;return D.mergeCells(s,r)}));h(this,"splitCell",e=>this.editor.exec((o,r)=>{const s=e?this.setCellSelection(o,e):o;return D.splitCell(s,r)}));h(this,"getCellSelection",()=>this.editor.transact(e=>{const o=e.selection;let r=o.$from,s=o.$to;if(a.isTableCellSelection(o)){const{ranges:k}=o;k.forEach(g=>{r=g.$from.min(r??g.$from),s=g.$to.max(s??g.$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),l=e.doc.resolve(i.pos-i.parentOffset-1),d=r.index(i.depth),u=i.index(l.depth),p=s.index(c.depth),m=c.index(l.depth),f=[];for(let k=u;k<=m;k++)for(let g=d;g<=p;g++)f.push({row:k,col:g});return{from:{row:u,col:d},to:{row:m,col:p},cells:f}}));h(this,"getMergeDirection",e=>this.editor.transact(o=>{const r=a.isTableCellSelection(o.selection)?o.selection:void 0;if(!r||!e||r.ranges.length<=1)return;const s=this.getCellSelection();if(s)return a.areInSameColumn(s.from,s.to,e)?"vertical":"horizontal"}));h(this,"cropEmptyRowsOrColumns",(e,o)=>a.cropEmptyRowsOrColumns(e,o));h(this,"addRowsOrColumns",(e,o,r)=>a.addRowsOrColumns(e,o,r));this.editor=e,this.addProsemirrorPlugin(new w.Plugin({key:F,view:o=>(this.view=new kt(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:l,draggedCellOrientation:d}=c;if(r===l||!i||d==="row"&&!a.canRowBeDraggedInto(i,l,r)||d==="col"&&!a.canColumnBeDraggedInto(i,l,r))return E.DecorationSet.create(o.doc,s);const u=o.doc.resolve(this.view.tablePos+1);return this.view.state.draggingState.draggedCellOrientation==="row"?a.getCellsAtRowHandle(this.view.state.block,r).forEach(({row:m,col:f})=>{const k=o.doc.resolve(u.posAtIndex(m)+1),g=o.doc.resolve(k.posAtIndex(f)+1),b=g.node(),y=g.pos+(r>l?b.nodeSize-2:0);s.push(E.Decoration.widget(y,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.left="0",C.style.right="0",r>l?C.style.bottom="-2px":C.style.top="-3px",C.style.height="4px",C}))}):a.getCellsAtColumnHandle(this.view.state.block,r).forEach(({row:m,col:f})=>{const k=o.doc.resolve(u.posAtIndex(m)+1),g=o.doc.resolve(k.posAtIndex(f)+1),b=g.node(),y=g.pos+(r>l?b.nodeSize-2:0);s.push(E.Decoration.widget(y,()=>{const C=document.createElement("div");return C.className="bn-table-drop-cursor",C.style.top="0",C.style.bottom="0",r>l?C.style.right="-2px":C.style.left="-3px",C.style.width="4px",C}))}),E.DecorationSet.create(o.doc,s)}}}))}static key(){return"tableHandles"}onUpdate(e){return this.on("update",e)}}const Mn=S.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}}}}]}}),xn=S.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["table","tableCell","tableHeader"],attributes:{textColor:a.getTextColorAttribute()}}]}}),In=S.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new w.PluginKey(this.name);return[new w.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:r,tr:s,schema:i}=o,c=n.getState(o),l=r.content.size-2,d=i.nodes.blockContainer,u=i.nodes.paragraph;if(c)return s.insert(l,d.create(void 0,u.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*"}}})]}}),Dn={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ln=S.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(Dn))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=a.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}}}),Nn=S.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=a.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}}}),An=S.Node.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"}),yt=n=>{var r;const t={},e=_n(n);for(const s of e)t[s.name]=s;n.collaboration&&(t.ySyncPlugin=new te(n.collaboration.fragment),t.yUndoPlugin=new oe({editor:n.editor}),(r=n.collaboration.provider)!=null&&r.awareness&&(t.yCursorPlugin=new W(n.collaboration)),t.forkYDocPlugin=new Xe({editor:n.editor,collaboration:n.collaboration}),t.schemaMigrationPlugin=new fe(n.collaboration.fragment)),t.formattingToolbar=new nt(n.editor),t.linkToolbar=new at(n.editor),t.sideMenu=new mt(n.editor),t.suggestionMenus=new gt(n.editor),t.filePanel=new et(n.editor),t.placeholder=new un(n.editor,n.placeholders),(n.animations??!0)&&(t.animations=new pn),n.tableHandles&&(t.tableHandles=new bt(n.editor)),t.nodeSelectionKeyboard=new cn,t.blockChange=new Go,t.showSelection=new mn(n.editor),n.comments&&(t.comments=new Qe(n.editor,n.comments.threadStore,ne.name,n.comments.resolveUsers,n.comments.schema));const o=n.disableExtensions||[];for(const s of o)delete t[s];return t};let _e=!1;const _n=n=>{const t=[S.extensions.ClipboardTextSerializer,S.extensions.Commands,S.extensions.Editable,S.extensions.FocusEvents,S.extensions.Tabindex,zt.Gapcursor,S.Extension.create({name:"dropCursor",addProseMirrorPlugins:()=>[n.dropCursor({width:5,color:"#ddeeff",editor:n.editor})]}),a.UniqueID.configure({types:["blockContainer","columnList","column"],setIdAttribute:n.setIdAttribute}),Qo,Gt.Text,Cn,Bn,vn,qt.Link.extend({inclusive:!1}).configure({defaultProtocol:ct,protocols:_e?[]:lt}),...Object.values(n.styleSpecs).map(e=>e.implementation.mark.configure({editor:n.editor})),xn,qo,Mn,S.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>n.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),An,Ln.configure({editor:n.editor,domAttributes:n.domAttributes}),sn.configure({editor:n.editor,tabBehavior:n.tabBehavior}),Nn.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})]:[]]),Ko(n.editor),Ro(n.editor,n.pasteHandler||(e=>e.defaultPasteHandler())),Co(n.editor),...n.trailingBlock===void 0||n.trailingBlock?[In]:[],...n.comments?[ne]:[]];return _e=!0,n.collaboration||t.push(Kt.History),t};function On(n){return n.transact(t=>{const e=a.getNearestBlockPos(t.doc,t.selection.anchor);if(t.selection instanceof D.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 w.NodeSelection)return{type:"node",anchorBlockId:e.node.attrs.id};{const o=a.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 Hn(n,t){var r,s;const e=(r=a.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=D.CellSelection.create(n.doc,e+t.anchorCellOffset,e+t.headCellOffset);else if(t.type==="node")o=w.NodeSelection.create(n.doc,e+1);else{const i=(s=a.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=w.TextSelection.create(n.doc,e+t.anchorOffset,i+t.headOffset)}n.setSelection(o)}function ue(n){return n.map(t=>t.type==="columnList"?t.children.map(e=>ue(e.children)).flat():{...t,children:ue(t.children)}).flat()}function wt(n,t,e){n.transact(o=>{var i;const r=((i=n.getSelection())==null?void 0:i.blocks)||[n.getTextCursorPosition().block],s=On(n);n.removeBlocks(r),n.insertBlocks(ue(r),t,e),Hn(o,s)})}function St(n){return!n||n.type!=="columnList"}function Ct(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 St(s)?{referenceBlock:o,placement:r}:Ct(n,r==="after"?o:n.getPrevBlock(o),s)}function Bt(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 St(s)?{referenceBlock:o,placement:r}:Bt(n,r==="before"?o:n.getNextBlock(o),s)}function Un(n){n.transact(()=>{const t=n.getSelection(),e=(t==null?void 0:t.blocks[0])||n.getTextCursorPosition().block,o=Ct(n,n.getPrevBlock(e),n.getParentBlock(e));o&&wt(n,o.referenceBlock,o.placement)})}function Rn(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=Bt(n,n.getNextBlock(e),n.getParentBlock(e));o&&wt(n,o.referenceBlock,o.placement)})}function vt(n,t){const e=typeof t=="string"?t:t.id,o=a.getPmSchema(n),r=a.getNodeById(e,n);if(r)return a.nodeToBlock(r.node,o)}function Pt(n,t){const e=typeof t=="string"?t:t.id,o=a.getNodeById(e,n),r=a.getPmSchema(n);if(!o)return;const i=n.resolve(o.posBeforeNode).nodeBefore;if(i)return a.nodeToBlock(i,r)}function Tt(n,t){const e=typeof t=="string"?t:t.id,o=a.getNodeById(e,n),r=a.getPmSchema(n);if(!o)return;const i=n.resolve(o.posBeforeNode+o.node.nodeSize).nodeAfter;if(i)return a.nodeToBlock(i,r)}function Et(n,t){const e=typeof t=="string"?t:t.id,o=a.getPmSchema(n),r=a.getNodeById(e,n);if(!r)return;const s=n.resolve(r.posBeforeNode),i=s.node(),c=s.node(-1),l=c.type.name!=="doc"?i.type.name==="blockGroup"?c:i:void 0;if(l)return a.nodeToBlock(l,o)}class Fn{constructor(t){this.editor=t}get document(){return this.editor.transact(t=>a.docToBlocks(t.doc,this.editor.pmSchema))}getBlock(t){return this.editor.transact(e=>vt(e.doc,t))}getPrevBlock(t){return this.editor.transact(e=>Pt(e.doc,t))}getNextBlock(t){return this.editor.transact(e=>Tt(e.doc,t))}getParentBlock(t){return this.editor.transact(e=>Et(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=>Fe(r,t,e,o))}updateBlock(t,e){return this.editor.transact(o=>a.updateBlock(o,t,e))}removeBlocks(t){return this.editor.transact(e=>ce(e,t,[]).removedBlocks)}replaceBlocks(t,e){return this.editor.transact(o=>ce(o,t,e))}canNestBlock(){return nn(this.editor)}nestBlock(){st(this.editor)}canUnnestBlock(){return rn(this.editor)}unnestBlock(){on(this.editor)}moveBlocksUp(){return Un(this.editor)}moveBlocksDown(){return Rn(this.editor)}}class Vn{constructor(t,e){h(this,"editor");h(this,"options");h(this,"_commentsPlugin");h(this,"_forkYDocPlugin");h(this,"_syncPlugin");h(this,"_undoPlugin");h(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 te(this.options.fragment),t.ySyncPlugin=this._syncPlugin,this._undoPlugin=new oe({editor:this.editor}),t.yUndoPlugin=this._undoPlugin,(e=this.options.provider)!=null&&e.awareness&&(this._cursorPlugin=new W(this.options),t.yCursorPlugin=this._cursorPlugin),this._forkYDocPlugin=new Xe({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 Qe(this.editor,this.options.comments.threadStore,ne.name,this.options.resolveUsers,this.options.comments.schema),t.comments=this._commentsPlugin,t.commentMark=ne}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 T.undoCommand}getRedoCommand(){return T.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 $n extends a.EventEmitter{constructor(t){super(),this.editor=t,t.onCreate(()=>{t._tiptapEditor.on("update",({transaction:e,appendedTransactions:o})=>{this.emit("onChange",t,{getChanges(){return he(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 zn(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function Kn(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function qn(n){n.querySelectorAll("li > ul, li > ol").forEach(t=>{const e=zn(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(Kn(s))return;const i=document.createElement("li");i.append(s),t.insertAdjacentElement("afterend",i)}),o.childNodes.length===0&&o.remove()})}function Gn(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 Oe=null;function jn(){return Oe||(Oe=document.implementation.createHTMLDocument("title"))}function Wn(n){if(typeof n=="string"){const t=jn().createElement("div");t.innerHTML=n,n=t}return qn(n),Gn(n),n}function ge(n,t){const e=Wn(n),r=P.DOMParser.fromSchema(t).parse(e,{topNode:t.nodes.blockGroup.create()}),s=[];for(let i=0;i<r.childCount;i++)s.push(a.nodeToBlock(r.child(i),t));return s}function Yn(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 Xn(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 ke(n){return He.unified().use(lo.default).use(Ue.default).use(co.default,{handlers:{...le.defaultHandlers,image:(e,o)=>{const r=String((o==null?void 0:o.url)||"");return a.isVideoUrl(r)?Xn(e,o):le.defaultHandlers.image(e,o)},code:Yn}}).use(uo.default).processSync(n).value}function Mt(n,t){const e=ke(n);return ge(e,t)}class Jn{constructor(t){this.editor=t}blocksToHTMLLossy(t=this.editor.document){return Y(this.editor.pmSchema,this.editor).exportBlocks(t,{})}blocksToFullHTML(t){return Ge(this.editor.pmSchema,this.editor).serializeBlocks(t,{})}tryParseHTMLToBlocks(t){return ge(t,this.editor.pmSchema)}blocksToMarkdownLossy(t=this.editor.document){return We(t,this.editor.pmSchema,this.editor,{})}tryParseMarkdownToBlocks(t){return Mt(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=ke(t);return this.pasteHTML(e)}}class Qn{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 Zn(n){const t=a.getPmSchema(n);if(n.selection.empty||"node"in n.selection)return;const e=n.doc.resolve(a.getNearestBlockPos(n.doc,n.selection.from).posBeforeNode),o=n.doc.resolve(a.getNearestBlockPos(n.doc,n.selection.to).posBeforeNode),r=(d,u)=>{const p=e.posAtIndex(d,u),m=n.doc.resolve(p).nodeAfter;if(!m)throw new Error(`Error getting selection - node not found at position ${p}`);return a.nodeToBlock(m,t)},s=[],i=e.sharedDepth(o.pos),c=e.index(i),l=o.index(i);if(e.depth>i){s.push(a.nodeToBlock(e.nodeAfter,t));for(let d=e.depth;d>i;d--)if(e.node(d).type.isInGroup("childContainer")){const p=e.index(d)+1,m=e.node(d).childCount;for(let f=p;f<m;f++)s.push(r(f,d))}}else s.push(r(c,i));for(let d=c+1;d<=l;d++)s.push(r(d,i));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${n.selection})`);return{blocks:s}}function er(n,t,e){const o=typeof t=="string"?t:t.id,r=typeof e=="string"?e:e.id,s=a.getPmSchema(n),i=a.getBlockNoteSchema(s);if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const c=a.getNodeById(o,n.doc);if(!c)throw new Error(`Block with ID ${o} not found`);const l=a.getNodeById(r,n.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const d=a.getBlockInfo(c),u=a.getBlockInfo(l),p=i.blockSchema[d.blockNoteType],m=i.blockSchema[u.blockNoteType];if(!d.isBlockContainer||p.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!u.isBlockContainer||m.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let f,k;if(p.content==="table"){const g=D.TableMap.get(d.blockContent.node);f=d.blockContent.beforePos+g.positionAt(0,0,d.blockContent.node)+1+2}else f=d.blockContent.beforePos+1;if(m.content==="table"){const g=D.TableMap.get(u.blockContent.node),b=u.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,u.blockContent.node)+1,y=n.doc.resolve(b).nodeAfter.nodeSize;k=b+y-2}else k=u.blockContent.afterPos-1;n.setSelection(w.TextSelection.create(n.doc,f,k))}function tr(n){const t=a.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=a.prosemirrorSliceToSlicedBlocks(n.doc.slice(e.pos,o.pos,!0),t);return{_meta:{startPos:e.pos,endPos:o.pos},...r}}function or(n){const{bnBlock:t}=a.getBlockInfoFromTransaction(n),e=a.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:a.nodeToBlock(t.node,e),prevBlock:r===null?void 0:a.nodeToBlock(r,e),nextBlock:s===null?void 0:a.nodeToBlock(s,e),parentBlock:i===void 0?void 0:a.nodeToBlock(i,e)}}function xt(n,t,e="start"){const o=typeof t=="string"?t:t.id,r=a.getPmSchema(n.doc),s=a.getBlockNoteSchema(r),i=a.getNodeById(o,n.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const c=a.getBlockInfo(i),l=s.blockSchema[c.blockNoteType].content;if(c.isBlockContainer){const d=c.blockContent;if(l==="none"){n.setSelection(w.NodeSelection.create(n.doc,d.beforePos));return}if(l==="inline")e==="start"?n.setSelection(w.TextSelection.create(n.doc,d.beforePos+1)):n.setSelection(w.TextSelection.create(n.doc,d.afterPos-1));else if(l==="table")e==="start"?n.setSelection(w.TextSelection.create(n.doc,d.beforePos+4)):n.setSelection(w.TextSelection.create(n.doc,d.afterPos-4));else throw new a.UnreachableCaseError(l)}else{const d=e==="start"?c.childContainer.node.firstChild:c.childContainer.node.lastChild;xt(n,d.attrs.id,e)}}class nr{constructor(t){this.editor=t}getSelection(){return this.editor.transact(t=>Zn(t))}getSelectionCutBlocks(){return this.editor.transact(t=>tr(t))}setSelection(t,e){return this.editor.transact(o=>er(o,t,e))}getTextCursorPosition(){return this.editor.transact(t=>or(t))}setTextCursorPosition(t,e="start"){return this.editor.transact(o=>xt(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(S.isNodeSelection(t)){const s=this.editor.prosemirrorView.nodeDOM(o);if(s)return s.getBoundingClientRect()}return S.posToDOMRect(this.editor.prosemirrorView,o,r)}}class rr{constructor(t,e){h(this,"activeTransaction",null);h(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)??Be.undo)}redo(){var t;return this.exec(((t=this.options)==null?void 0:t.redo)??Be.redo)}}function sr(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,l="";if(e.forEach(d=>{d.check(),i&&d.isText&&d.marks.length===0?l+=d.text:i=!1,c=c?d.isBlock:!1}),r===s&&c){const{parent:d}=n.doc.resolve(r);d.isTextblock&&!d.type.spec.code&&!d.childCount&&(r-=1,s+=1)}return i?n.insertText(l,r,s):n.replaceWith(r,s,e),o.updateSelection&&S.selectionToInsertionEnd(n,n.steps.length-1,-1),!0}class ir{constructor(t){this.editor=t}insertInlineContent(t,{updateSelection:e=!1}={}){const o=a.inlineContentToNodes(t,this.editor.pmSchema);this.editor.transact(r=>{sr(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 a.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 a.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(w.TextSelection.create(r.doc,i)).addMark(s,i,o)})}}function ar(n,t){const e=[];return n.forEach((o,r,s)=>{s!==t&&e.push(o)}),P.Fragment.from(e)}function lr(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=P.Fragment.from(e),n}function cr(n,t){let e=P.Fragment.from(n.content);if(e=lr(e,t.state.schema),!dr(e,t))return new P.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=ar(e,o+1))}const s=t.state.schema.nodes.blockContainer.createChecked(void 0,r);e=e.replaceChild(o,s)}return new P.Slice(e,n.openStart,n.openEnd)}function dr(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=a.getBlockInfoFromSelection(t.state);if(c.isBlockContainer)return!(c.blockContent.node.type.spec.content==="tableRow+")}}return!0}const ur={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class be extends a.EventEmitter{constructor(e){var d,u,p,m,f,k,g,b,y,C,N,H,z,K,q,G,M,x,ye;super();h(this,"pmSchema");h(this,"extensions",{});h(this,"_tiptapEditor");h(this,"elementRenderer",null);h(this,"blockCache",new WeakMap);h(this,"dictionary");h(this,"schema");h(this,"blockImplementations");h(this,"inlineContentImplementations");h(this,"styleImplementations");h(this,"uploadFile");h(this,"onUploadStartCallbacks",[]);h(this,"onUploadEndCallbacks",[]);h(this,"resolveFileUrl");h(this,"resolveUsers");h(this,"settings");h(this,"_blockManager");h(this,"_collaborationManager");h(this,"_eventManager");h(this,"_exportManager");h(this,"_extensionManager");h(this,"_selectionManager");h(this,"_stateManager");h(this,"_styleManager");h(this,"mount",e=>{this._tiptapEditor.mount({mount:e})});h(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||eo.en,this.settings={tables:{splitCells:((d=e==null?void 0:e.tables)==null?void 0:d.splitCells)??!1,cellBackgroundColor:((u=e==null?void 0:e.tables)==null?void 0:u.cellBackgroundColor)??!1,cellTextColor:((p=e==null?void 0:e.tables)==null?void 0:p.cellTextColor)??!1,headers:((m=e==null?void 0:e.tables)==null?void 0:m.headers)??!1}};const r={defaultStyles:!0,schema:e.schema||a.BlockNoteSchema.create(),...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(r.collaboration||r.comments){const B={fragment:((f=r.collaboration)==null?void 0:f.fragment)||new O.XmlFragment,user:((k=r.collaboration)==null?void 0:k.user)||{name:"User",color:"#FF0000"},provider:((g=r.collaboration)==null?void 0:g.provider)||null,renderCursor:(b=r.collaboration)==null?void 0:b.renderCursor,showCursorLabels:(y=r.collaboration)==null?void 0:y.showCursorLabels,comments:r.comments,resolveUsers:r.resolveUsers};this._collaborationManager=new Vn(this,B)}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={...yt({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:a.editorHasBlockWithType(this,"table"),dropCursor:this.options.dropCursor??Vt.dropCursor,placeholders:r.placeholders,tabBehavior:r.tabBehavior,pasteHandler:r.pasteHandler}),...(C=this._collaborationManager)==null?void 0:C.initExtensions()},(((N=r._tiptapOptions)==null?void 0:N.extensions)||[]).forEach(B=>{this.extensions[B.name]=B});for(let B of r.extensions||[]){typeof B=="function"&&(B=B(this));const v=B.key??B.constructor.key();if(!v)throw new Error(`Extension ${B.constructor.name} does not have a key method`);if(this.extensions[v])throw new Error(`Extension ${B.constructor.name} already exists with key ${v}`);this.extensions[v]=B}if(Object.entries(r._extensions||{}).forEach(([B,v])=>{const I=typeof v=="function"?v(this):v;if(!("plugin"in I)){this.extensions[B]=I;return}this.extensions[B]=new class extends a.BlockNoteExtension{static key(){return B}constructor(){super(),this.addProsemirrorPlugin(I.plugin)}get priority(){return I.priority}}}),r.uploadFile){const B=r.uploadFile;this.uploadFile=async(v,A)=>{this.onUploadStartCallbacks.forEach(I=>I.apply(this,[A]));try{return await B(v,A)}finally{this.onUploadEndCallbacks.forEach(I=>I.apply(this,[A]))}}}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(B=>B.extensions).filter(B=>B!==void 0).flat().map(B=>[B.key??B.constructor.key(),B])),c=[...Object.entries({...this.extensions,...i}).map(([B,v])=>{if(v instanceof S.Extension||v instanceof S.Node||v instanceof S.Mark)return v;if(v instanceof a.BlockNoteExtension)return!v.plugins.length&&!v.keyboardShortcuts&&!v.inputRules&&!v.tiptapExtensions?void 0:S.Extension.create({name:B,priority:v.priority,addProseMirrorPlugins:()=>v.plugins,addExtensions:()=>v.tiptapExtensions||[],addInputRules:v.inputRules?()=>v.inputRules.map(A=>new S.InputRule({find:A.find,handler:({range:I,match:se,state:we})=>{const Se=A.replace({match:se,range:I,editor:this});if(Se){const It=this.getTextCursorPosition();if(this.schema.blockSchema[It.block.type].content!=="inline")return;const Dt=a.getBlockInfoFromTransaction(we.tr),Lt=we.tr.deleteRange(I.from,I.to);a.updateBlockTr(Lt,Dt.bnBlock.beforePos,Se);return}return null}})):void 0,addKeyboardShortcuts:v.keyboardShortcuts?()=>Object.fromEntries(Object.entries(v.keyboardShortcuts).map(([A,I])=>[A,()=>I({editor:this})])):void 0})})].filter(B=>B!==void 0),l={...ur,...r._tiptapOptions,element:null,autofocus:r.autofocus??!1,extensions:c,editorProps:{...(H=r._tiptapOptions)==null?void 0:H.editorProps,attributes:{tabIndex:"0",...(K=(z=r._tiptapOptions)==null?void 0:z.editorProps)==null?void 0:K.attributes,...(q=r.domAttributes)==null?void 0:q.editor,class:a.mergeCSSClasses("bn-editor",r.defaultStyles?"bn-default-styles":"",((M=(G=r.domAttributes)==null?void 0:G.editor)==null?void 0:M.class)||"")},transformPasted:cr}};try{const B=r.initialContent||(s?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:a.UniqueID.options.generateID()}]);if(!Array.isArray(B)||B.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+B);const v=S.getSchema(l.extensions),A=B.map(se=>a.blockToNode(se,v,this.schema.styleSchema).toJSON()),I=S.createDocument({type:"doc",content:[{type:"blockGroup",content:A}]},v,l.parseOptions);this._tiptapEditor=new S.Editor({...l,content:I.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(B){throw new Error("Error creating document from blocks passed as `initialContent`",{cause:B})}this.pmSchema.cached.blockNoteEditor=this,this._blockManager=new Fn(this),this._eventManager=new $n(this),this._exportManager=new Jn(this),this._extensionManager=new Qn(this),this._selectionManager=new nr(this),this._stateManager=new rr(this,s?{undo:(x=this._collaborationManager)==null?void 0:x.getUndoCommand(),redo:(ye=this._collaborationManager)==null?void 0:ye.getRedoCommand()}:void 0),this._styleManager=new ir(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 be(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()}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){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 hr{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 pr(n){return{createBlockMapping:t=>t,createInlineContentMapping:t=>t,createStyleMapping:t=>t}}let Z;async function mr(){return Z||(Z=(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}})(),Z)}async function fr(n,t){if(!("text"in n.schema.inlineContentSchema)||n.schema.inlineContentSchema.text!==a.defaultInlineContentSchema.text)return[];const{emojiData:e,emojiMart:o}=await mr();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 gr(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.BlockNoteExtension=a.BlockNoteExtension;exports.BlockNoteSchema=a.BlockNoteSchema;exports.COLORS_DARK_MODE_DEFAULT=a.COLORS_DARK_MODE_DEFAULT;exports.COLORS_DEFAULT=a.COLORS_DEFAULT;exports.CustomBlockNoteSchema=a.CustomBlockNoteSchema;exports.EMPTY_CELL_HEIGHT=a.EMPTY_CELL_HEIGHT;exports.EMPTY_CELL_WIDTH=a.EMPTY_CELL_WIDTH;exports.EventEmitter=a.EventEmitter;exports.FILE_AUDIO_ICON_SVG=a.FILE_AUDIO_ICON_SVG;exports.FILE_IMAGE_ICON_SVG=a.FILE_IMAGE_ICON_SVG;exports.FILE_VIDEO_ICON_SVG=a.FILE_VIDEO_ICON_SVG;exports.UniqueID=a.UniqueID;exports.UnreachableCaseError=a.UnreachableCaseError;exports.addDefaultPropsExternalHTML=a.addDefaultPropsExternalHTML;exports.addInlineContentAttributes=a.addInlineContentAttributes;exports.addInlineContentKeyboardShortcuts=a.addInlineContentKeyboardShortcuts;exports.addNodeAndExtensionsToSpec=a.addNodeAndExtensionsToSpec;exports.addStyleAttributes=a.addStyleAttributes;exports.applyNonSelectableBlockFix=a.applyNonSelectableBlockFix;exports.assertEmpty=a.assertEmpty;exports.audioParse=a.audioParse;exports.audioRender=a.audioRender;exports.audioToExternalHTML=a.audioToExternalHTML;exports.blockHasType=a.blockHasType;exports.blockToNode=a.blockToNode;exports.camelToDataKebab=a.camelToDataKebab;exports.captureCellAnchor=a.captureCellAnchor;exports.checkPageBreakBlocksInSchema=a.checkPageBreakBlocksInSchema;exports.contentNodeToInlineContent=a.contentNodeToInlineContent;exports.contentNodeToTableContent=a.contentNodeToTableContent;exports.createAudioBlockConfig=a.createAudioBlockConfig;exports.createAudioBlockSpec=a.createAudioBlockSpec;exports.createBlockConfig=a.createBlockConfig;exports.createBlockNoteExtension=a.createBlockNoteExtension;exports.createBlockSpec=a.createBlockSpec;exports.createBlockSpecFromTiptapNode=a.createBlockSpecFromTiptapNode;exports.createBulletListItemBlockConfig=a.createBulletListItemBlockConfig;exports.createBulletListItemBlockSpec=a.createBulletListItemBlockSpec;exports.createCheckListItemBlockSpec=a.createCheckListItemBlockSpec;exports.createCheckListItemConfig=a.createCheckListItemConfig;exports.createCodeBlockConfig=a.createCodeBlockConfig;exports.createCodeBlockSpec=a.createCodeBlockSpec;exports.createDefaultBlockDOMOutputSpec=a.createDefaultBlockDOMOutputSpec;exports.createDividerBlockConfig=a.createDividerBlockConfig;exports.createDividerBlockSpec=a.createDividerBlockSpec;exports.createFileBlockConfig=a.createFileBlockConfig;exports.createFileBlockSpec=a.createFileBlockSpec;exports.createHeadingBlockConfig=a.createHeadingBlockConfig;exports.createHeadingBlockSpec=a.createHeadingBlockSpec;exports.createImageBlockConfig=a.createImageBlockConfig;exports.createImageBlockSpec=a.createImageBlockSpec;exports.createInlineContentSpecFromTipTapNode=a.createInlineContentSpecFromTipTapNode;exports.createInternalInlineContentSpec=a.createInternalInlineContentSpec;exports.createInternalStyleSpec=a.createInternalStyleSpec;exports.createNumberedListItemBlockConfig=a.createNumberedListItemBlockConfig;exports.createNumberedListItemBlockSpec=a.createNumberedListItemBlockSpec;exports.createPageBreakBlockConfig=a.createPageBreakBlockConfig;exports.createPageBreakBlockSpec=a.createPageBreakBlockSpec;exports.createParagraphBlockConfig=a.createParagraphBlockConfig;exports.createParagraphBlockSpec=a.createParagraphBlockSpec;exports.createQuoteBlockConfig=a.createQuoteBlockConfig;exports.createQuoteBlockSpec=a.createQuoteBlockSpec;exports.createStyleSpec=a.createStyleSpec;exports.createStyleSpecFromTipTapMark=a.createStyleSpecFromTipTapMark;exports.createTableBlockSpec=a.createTableBlockSpec;exports.createToggleListItemBlockConfig=a.createToggleListItemBlockConfig;exports.createToggleListItemBlockSpec=a.createToggleListItemBlockSpec;exports.createToggleWrapper=a.createToggleWrapper;exports.createVideoBlockConfig=a.createVideoBlockConfig;exports.createVideoBlockSpec=a.createVideoBlockSpec;exports.defaultBlockSpecs=a.defaultBlockSpecs;exports.defaultBlockToHTML=a.defaultBlockToHTML;exports.defaultInlineContentSchema=a.defaultInlineContentSchema;exports.defaultInlineContentSpecs=a.defaultInlineContentSpecs;exports.defaultProps=a.defaultProps;exports.defaultStyleSchema=a.defaultStyleSchema;exports.defaultStyleSpecs=a.defaultStyleSpecs;exports.defaultToggledState=a.defaultToggledState;exports.docToBlocks=a.docToBlocks;exports.editorHasBlockWithType=a.editorHasBlockWithType;exports.fileParse=a.fileParse;exports.filenameFromURL=a.filenameFromURL;exports.filterSuggestionItems=a.filterSuggestionItems;exports.formatKeyboardShortcut=a.formatKeyboardShortcut;exports.getBackgroundColorAttribute=a.getBackgroundColorAttribute;exports.getBlockCache=a.getBlockCache;exports.getBlockFromPos=a.getBlockFromPos;exports.getBlockInfo=a.getBlockInfo;exports.getBlockInfoFromResolvedPos=a.getBlockInfoFromResolvedPos;exports.getBlockInfoFromSelection=a.getBlockInfoFromSelection;exports.getBlockInfoFromTransaction=a.getBlockInfoFromTransaction;exports.getBlockInfoWithManualOffset=a.getBlockInfoWithManualOffset;exports.getBlockNoteSchema=a.getBlockNoteSchema;exports.getBlockSchema=a.getBlockSchema;exports.getColspan=a.getColspan;exports.getDefaultSlashMenuItems=a.getDefaultSlashMenuItems;exports.getInlineContentSchema=a.getInlineContentSchema;exports.getInlineContentSchemaFromSpecs=a.getInlineContentSchemaFromSpecs;exports.getLanguageId=a.getLanguageId;exports.getNearestBlockPos=a.getNearestBlockPos;exports.getNodeById=a.getNodeById;exports.getPageBreakSlashMenuItems=a.getPageBreakSlashMenuItems;exports.getParseRules=a.getParseRules;exports.getPmSchema=a.getPmSchema;exports.getRowspan=a.getRowspan;exports.getStyleParseRules=a.getStyleParseRules;exports.getStyleSchema=a.getStyleSchema;exports.getStyleSchemaFromSpecs=a.getStyleSchemaFromSpecs;exports.getTextAlignmentAttribute=a.getTextAlignmentAttribute;exports.getTextColorAttribute=a.getTextColorAttribute;exports.imageParse=a.imageParse;exports.imageRender=a.imageRender;exports.imageToExternalHTML=a.imageToExternalHTML;exports.inlineContentToNodes=a.inlineContentToNodes;exports.insertOrUpdateBlock=a.insertOrUpdateBlock;exports.isAppleOS=a.isAppleOS;exports.isLinkInlineContent=a.isLinkInlineContent;exports.isNodeBlock=a.isNodeBlock;exports.isPartialLinkInlineContent=a.isPartialLinkInlineContent;exports.isPartialTableCell=a.isPartialTableCell;exports.isSafari=a.isSafari;exports.isStyledTextInlineContent=a.isStyledTextInlineContent;exports.isTableCell=a.isTableCell;exports.isTableCellSelection=a.isTableCellSelection;exports.isVideoUrl=a.isVideoUrl;exports.mapTableCell=a.mapTableCell;exports.mergeCSSClasses=a.mergeCSSClasses;exports.mergeParagraphs=a.mergeParagraphs;exports.nodeToBlock=a.nodeToBlock;exports.nodeToCustomInlineContent=a.nodeToCustomInlineContent;exports.parseAudioElement=a.parseAudioElement;exports.parseDefaultProps=a.parseDefaultProps;exports.propsToAttributes=a.propsToAttributes;exports.prosemirrorSliceToSlicedBlocks=a.prosemirrorSliceToSlicedBlocks;exports.stylePropsToAttributes=a.stylePropsToAttributes;exports.tableContentToNodes=a.tableContentToNodes;exports.tablePropSchema=a.tablePropSchema;exports.updateBlock=a.updateBlock;exports.updateBlockCommand=a.updateBlockCommand;exports.updateBlockTr=a.updateBlockTr;exports.uploadToTmpFilesDotOrg_DEV_ONLY=a.uploadToTmpFilesDotOrg_DEV_ONLY;exports.videoParse=a.videoParse;exports.withPageBreak=a.withPageBreak;exports.wrapInBlockStructure=a.wrapInBlockStructure;exports.BlockNoteEditor=be;exports.DEFAULT_LINK_PROTOCOL=ct;exports.Exporter=hr;exports.FilePanelProsemirrorPlugin=et;exports.FilePanelView=Ze;exports.FormattingToolbarProsemirrorPlugin=nt;exports.FormattingToolbarView=tt;exports.HTMLToBlocks=ge;exports.LinkToolbarProsemirrorPlugin=at;exports.SideMenuProsemirrorPlugin=mt;exports.SideMenuView=ht;exports.SuggestionMenuProseMirrorPlugin=gt;exports.TableHandlesProsemirrorPlugin=bt;exports.TableHandlesView=kt;exports.VALID_LINK_PROTOCOLS=lt;exports.blocksToMarkdown=We;exports.cleanHTMLToMarkdown=re;exports.combineByGroup=gr;exports.createExternalHTMLExporter=Y;exports.createInlineContentSpec=ho;exports.createInternalHTMLSerializer=Ge;exports.createSuggestionMenu=Sn;exports.formattingToolbarPluginKey=ot;exports.getBlock=vt;exports.getBlockNoteExtensions=yt;exports.getBlocksChangedByTransaction=he;exports.getDefaultEmojiPickerItems=fr;exports.getInlineContentParseRules=Re;exports.getNextBlock=Tt;exports.getParentBlock=Et;exports.getPrevBlock=Pt;exports.insertBlocks=Fe;exports.linkToolbarPluginKey=it;exports.mappingFactory=pr;exports.markdownToBlocks=Mt;exports.markdownToHTML=ke;exports.removeAndInsertBlocks=ce;exports.selectedFragmentToHTML=me;exports.sideMenuPluginKey=pt;exports.tableHandlesPluginKey=F;exports.trackPosition=ft;
|
|
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:``}}})}}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=>{if(this.scheduledDestructionTimeout&&this.prosemirrorView.dom===e){clearTimeout(this.scheduledDestructionTimeout),this.scheduledDestructionTimeout=void 0;return}this._tiptapEditor.mount({mount:e})});u(this,"scheduledDestructionTimeout");u(this,"unmount",()=>{this.scheduledDestructionTimeout=setTimeout(()=>{this._tiptapEditor.unmount(),this.scheduledDestructionTimeout=void 0},1)});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;
|
|
5
5
|
//# sourceMappingURL=blocknote.cjs.map
|