UNPKG

@blocknote/core

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

58 lines 62.4 kB
const e=require("./blocks-CzkqclGj.cjs"),t=require("./BlockNoteExtension-BJCLnwrE.cjs"),n=require("./UserStore-mj3fXW4D.cjs");let r=require("prosemirror-model"),i=require("prosemirror-transform"),a=require("@tiptap/core"),o=require("lib0/random"),s=require("prosemirror-state"),c=require("@tiptap/pm/model"),l=require("prosemirror-tables"),u=require("@tiptap/pm/state"),d=require("prosemirror-view"),f=require("fast-deep-equal");f=e.cr(f,1);let p=require("@tiptap/pm/history"),m=require("prosemirror-highlight"),h=require("prosemirror-highlight/shiki");function g(e){let t=Array.from(e.classList).filter(e=>!e.startsWith(`bn-`))||[];t.length>0?e.className=t.join(` `):e.removeAttribute(`class`)}function _(t,n,i,a){let o;if(!n)throw Error(`blockContent is required`);if(typeof n==`string`)o=e.Lt([n],t.pmSchema,a?.blockType);else if(Array.isArray(n))o=e.Lt(n,t.pmSchema,a?.blockType);else if(n.type===`tableContent`)o=e.Rt(n,t.pmSchema);else throw new e.Un(n.type);let s=(a?.document??document).createDocumentFragment();for(let n of o)if(n.type.name!==`text`&&t.schema.inlineContentSchema[n.type.name]){let r=t.schema.inlineContentSpecs[n.type.name].implementation;if(r){let o=e.En(n,t.schema.inlineContentSchema,t.schema.styleSchema),c=r.toExternalHTML?r.toExternalHTML(o,t):r.render.call({renderType:`dom`,props:void 0},o,()=>{},t);if(c){if(s.appendChild(c.dom),c.contentDOM){let e=i.serializeFragment(n.content,a);c.contentDOM.dataset.editable=``,c.contentDOM.appendChild(e)}continue}}}else if(n.type.name===`text`){let e=document.createTextNode(n.textContent);for(let i of n.marks.toReversed())if(i.type.name in t.schema.styleSpecs){let n=(t.schema.styleSpecs[i.type.name].implementation.toExternalHTML??t.schema.styleSpecs[i.type.name].implementation.render)(i.attrs.stringValue,t);n.contentDOM.appendChild(e),e=n.dom}else{let t=i.type.spec.toDOM(i,!0),n=r.DOMSerializer.renderSpec(document,t);n.contentDOM.appendChild(e),e=n.dom}s.appendChild(e)}else{let e=i.serializeFragment(r.Fragment.from([n]),a);s.appendChild(e)}return s.childNodes.length===1&&s.firstChild?.nodeType===1&&g(s.firstChild),s}function v(e,t,n,r,i,a,o,s){let c=s?.document??document,l=t.pmSchema.nodes.blockContainer,u=n.props||{};for(let[e,r]of Object.entries(t.schema.blockSchema[n.type].propSchema))!(e in u)&&r.default!==void 0&&(u[e]=r.default);let d=l.spec?.toDOM?.(l.create({id:n.id,...u})),f=Array.from(d.dom.attributes),p=t.blockImplementations[n.type].implementation,m=p.toExternalHTML?.call({},{...n,props:u},t,{nestingLevel:o})||p.render.call({},{...n,props:u},t),h=c.createDocumentFragment();if(m.dom.classList.contains(`bn-block-content`)){let e=[...f,...Array.from(m.dom.attributes)].filter(e=>e.name.startsWith(`data`)&&e.name!==`data-content-type`&&e.name!==`data-file-block`&&e.name!==`data-node-view-wrapper`&&e.name!==`data-node-type`&&e.name!==`data-id`&&e.name!==`data-editable`);for(let t of e)m.dom.firstChild.setAttribute(t.name,t.value);g(m.dom.firstChild),o>0&&m.dom.firstChild.setAttribute(`data-nesting-level`,o.toString()),h.append(...Array.from(m.dom.childNodes))}else h.append(m.dom),o>0&&m.dom.setAttribute(`data-nesting-level`,o.toString());if(m.contentDOM){if(n.content){let e=_(t,n.content,r,{...s,blockType:n.type});m.contentDOM.appendChild(e)}let e=t.pmSchema.nodes[n.type];e?.inlineContent&&!e.spec.code&&m.contentDOM.childNodes.length===0&&m.contentDOM.appendChild(c.createTextNode(``))}let v;if(i.has(n.type)?v=`OL`:a.has(n.type)&&(v=`UL`),v){if(e.lastChild?.nodeName!==v){let t=c.createElement(v);v===`OL`&&`start`in u&&u.start&&u?.start!==1&&t.setAttribute(`start`,String(u.start)),e.append(t)}e.lastChild.appendChild(h)}else e.append(h);if(n.children&&n.children.length>0){let l=c.createDocumentFragment();if(y(l,t,n.children,r,i,a,o+1,s),e.lastChild?.nodeName===`UL`||e.lastChild?.nodeName===`OL`)for(;l.firstChild?.nodeName===`UL`||l.firstChild?.nodeName===`OL`;)e.lastChild.lastChild.appendChild(l.firstChild);`childrenDOM`in m&&m.childrenDOM?m.childrenDOM.append(l):t.pmSchema.nodes[n.type].isInGroup(`blockContent`)?e.append(l):m.contentDOM?.append(l)}}var y=(e,t,n,r,i,a,o=0,s)=>{for(let c of n)v(e,t,c,r,i,a,o,s)},ee=(e,t,n,r,i,a)=>{let o=(a?.document??document).createDocumentFragment();return y(o,e,t,n,r,i,0,a),o},b=(e,t)=>{let n=r.DOMSerializer.fromSchema(e);return{exportBlocks:(e,r)=>{let i=ee(t,e,n,new Set([`numberedListItem`]),new Set([`bulletListItem`,`checkListItem`,`toggleListItem`]),r),a=document.createElement(`div`);return a.append(i),a.innerHTML},exportInlineContent:(e,r)=>{let i=_(t,e,n,r),a=document.createElement(`div`);return a.append(i.cloneNode(!0)),a.innerHTML}}};function te(t,n){if(n===0)return;let r=t.resolve(n);for(let n=r.depth;n>0;n--){let i=r.node(n);if(e.Ft(i))return e.or(i,t)}}function ne(e){return e.getMeta(`paste`)?{type:`paste`}:e.getMeta(`uiEvent`)===`drop`?{type:`drop`}:e.getMeta(`history$`)?{type:e.getMeta(`history$`).redo?`redo`:`undo`}:e.getMeta(`y-sync$`)?e.getMeta(`y-sync$`).isUndoRedoOperation?{type:`undo-redo`}:{type:`yjs-remote`}:{type:`local`}}function re(t){let n={},r={};return t.descendants((i,a)=>{if(!e.Ft(i))return!0;let o=te(t,a),s=o??`__root__`;r[s]||(r[s]=[]);let c=e.Tn(i,t),l=e.or(i,t);return n[l]={block:c,parentId:o},r[s].push(l),!0}),{byId:n,childrenByParent:r}}function ie(e,t){let n=new Set;if(!e||!t)return n;let r=new Set(e),i=t.filter(e=>r.has(e)),a=e.filter(e=>i.includes(e));if(a.length<=1||i.length<=1)return n;let o={};for(let e=0;e<a.length;e++)o[a[e]]=e;let s=i.map(e=>o[e]),c=s.length,l=[],u=[],d=Array(c).fill(-1),f=(e,t)=>{let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i]<t?n=i+1:r=i}return n};for(let e=0;e<c;e++){let t=s[e],n=f(l,t);n>0&&(d[e]=u[n-1]),n===l.length?(l.push(t),u.push(e)):(l[n]=t,u[n]=e)}let p=new Set,m=u[u.length-1]??-1;for(;m!==-1;)p.add(m),m=d[m];for(let e=0;e<i.length;e++)p.has(e)||n.add(i[e]);return n}function x(e,t=[]){let n=ne(e),r=(0,a.combineTransactionSteps)(e.before,[e,...t]),i=re(r.before),o=re(r.doc),s=[],c=new Set;Object.keys(o.byId).filter(e=>!(e in i.byId)).forEach(e=>{s.push({type:`insert`,block:o.byId[e].block,source:n,prevBlock:void 0}),c.add(e)}),Object.keys(i.byId).filter(e=>!(e in o.byId)).forEach(e=>{s.push({type:`delete`,block:i.byId[e].block,source:n,prevBlock:void 0}),c.add(e)}),Object.keys(o.byId).filter(e=>e in i.byId).forEach(e=>{let t=i.byId[e],r=o.byId[e];t.parentId===r.parentId?(0,f.default)({...t.block,children:void 0},{...r.block,children:void 0})||(s.push({type:`update`,block:r.block,prevBlock:t.block,source:n}),c.add(e)):(s.push({type:`move`,block:r.block,prevBlock:t.block,source:n,prevParent:t.parentId?i.byId[t.parentId]?.block:void 0,currentParent:r.parentId?o.byId[r.parentId]?.block:void 0}),c.add(e))});let l=i.childrenByParent,u=o.childrenByParent,d=new Set([...Object.keys(l),...Object.keys(u)]),p=new Set;return d.forEach(e=>{let t=ie(l[e],u[e]);t.size!==0&&t.forEach(t=>{let r=i.byId[t],a=o.byId[t];!r||!a||r.parentId===a.parentId&&(c.has(t)||(r.parentId??`__root__`)===e&&(p.has(t)||(p.add(t),s.push({type:`move`,block:a.block,prevBlock:r.block,source:n,prevParent:r.parentId?i.byId[r.parentId]?.block:void 0,currentParent:a.parentId?o.byId[a.parentId]?.block:void 0}),c.add(t))))})}),s}var ae=t.t(()=>{let e=[];return{key:`blockChange`,prosemirrorPlugins:[new s.Plugin({key:new s.PluginKey(`blockChange`),filterTransaction:t=>{let n;return e.reduce((e,r)=>e===!1?e:r({getChanges(){return n||(n=x(t),n)},tr:t})!==!1,!0)}})],subscribe(t){return e.push(t),()=>{e.splice(e.indexOf(t),1)}}}});function S(e,t){return!e||!t?!1:!!e.closest(`.${t}`)}function oe(e,t,n,r,i){let a=e.state.doc.resolve(t.pos);if(a.parent.inlineContent||t.orientation===`inline`)return null;let o=a.nodeBefore,s=a.nodeAfter;if(!o&&!s)return null;let c=t.orientation===`block-vertical-left`||t.orientation===`block-vertical-right`,l=c?t.pos:t.pos-(o?o.nodeSize:0),u=e.nodeDOM(l);if(!u)return null;let d=u.getBoundingClientRect();if(c){let e=n/2*r,i=t.orientation===`block-vertical-left`?d.left:d.right;return{left:i-e,right:i+e,top:d.top,bottom:d.bottom}}let f=o?d.bottom:d.top;o&&s&&(f=(f+e.nodeDOM(t.pos).getBoundingClientRect().top)/2);let p=n/2*i;return{left:d.left,right:d.right,top:f-p,bottom:f+p}}function se(e,t,n,r){let i=e.coordsAtPos(t.pos),a=n/2*r;return{left:i.left-a,right:i.left+a,top:i.top,bottom:i.bottom}}function ce(e,t){e.classList.toggle(`prosemirror-dropcursor-inline`,t===`inline`),e.classList.toggle(`prosemirror-dropcursor-block-horizontal`,t===`block-horizontal`),e.classList.toggle(`prosemirror-dropcursor-block-vertical-left`,t===`block-vertical-left`),e.classList.toggle(`prosemirror-dropcursor-block-vertical-right`,t===`block-vertical-right`),e.classList.toggle(`prosemirror-dropcursor-block`,t===`block-horizontal`),e.classList.toggle(`prosemirror-dropcursor-vertical`,t===`block-vertical-left`||t===`block-vertical-right`)}function le(e){if(!e||e===document.body&&getComputedStyle(e).position===`static`)return{parentLeft:-window.pageXOffset,parentTop:-window.pageYOffset};let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth,r=t.height/e.offsetHeight;return{parentLeft:t.left-e.scrollLeft*n,parentTop:t.top-e.scrollTop*r}}var ue=`bn-drag-exclude`,de=t.t(({editor:e,options:t})=>{let n=null,r=null,a=-1,o=null,s={width:t.dropCursor?.width??5,color:t.dropCursor?.color??`#ddeeff`,exclude:t.dropCursor?.exclude??`bn-drag-exclude`,hooks:t.dropCursor?.hooks},c=e=>{(e?.pos!==n?.pos||e?.orientation!==n?.orientation)&&(n=e,e==null?(r&&r.parentNode&&r.parentNode.removeChild(r),r=null):l())},l=()=>{if(!n)return;let t=e.prosemirrorView,i=t.dom,a=i.getBoundingClientRect(),o=a.width/i.offsetWidth,c=a.height/i.offsetHeight,l=oe(t,n,s.width,o,c)??se(t,n,s.width,o),u=t.dom.offsetParent;r||(r=u.appendChild(document.createElement(`div`)),r.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,s.color&&(r.style.backgroundColor=s.color)),ce(r,n.orientation);let{parentLeft:d,parentTop:f}=le(u);r.style.left=(l.left-d)/o+`px`,r.style.top=(l.top-f)/c+`px`,r.style.width=(l.right-l.left)/o+`px`,r.style.height=(l.bottom-l.top)/c+`px`},u=e=>{clearTimeout(a),a=window.setTimeout(()=>c(null),e)},d=e=>{let t=e;o=t.target instanceof Element?t.target:null},f=t=>{let n=t;if(o&&S(o,s.exclude)||n.target instanceof Element&&S(n.target,s.exclude))return;let r=e.prosemirrorView;if(!r.editable)return;let a=r.posAtCoords({left:n.clientX,top:n.clientY}),l=a&&a.inside>=0&&r.state.doc.nodeAt(a.inside),d=l&&l.type.spec.disableDropCursor,f=typeof d==`function`?d(r,a,n):d;if(a&&!f){let t=a.pos;if(r.dragging&&r.dragging.slice){let e=(0,i.dropPoint)(r.state.doc,t,r.dragging.slice);e!=null&&(t=e)}let o=!r.state.doc.resolve(t).parent.inlineContent,l={pos:t,orientation:o?`block-horizontal`:`inline`},d=l;if(s.hooks?.computeDropPosition){let t=s.hooks.computeDropPosition({editor:e,event:n,view:r,defaultPosition:l});if(t===null){c(null);return}d=t}c(d),u(5e3)}},p=t=>{let n=t;(!(n.relatedTarget instanceof Node)||!e.prosemirrorView.dom.contains(n.relatedTarget))&&c(null)},m=()=>{u(20)},h=()=>{u(20),o=null};return{key:`dropCursor`,mount({signal:e,dom:t,root:n}){n.addEventListener(`dragstart`,d,{capture:!0,signal:e}),t.addEventListener(`dragover`,f,{signal:e}),t.addEventListener(`dragleave`,p,{signal:e}),t.addEventListener(`drop`,m,{signal:e}),t.addEventListener(`dragend`,h,{signal:e}),e.addEventListener(`abort`,()=>{clearTimeout(a),c(null)})}}}),fe=t.t(()=>({key:`history`,prosemirrorPlugins:[(0,p.history)()],undoCommand:p.undo,redoCommand:p.redo})),pe=new s.PluginKey(`inline-content-boundary-edit`);function me(e,t,n){if(!e.empty)return e.from<=n.from&&e.to>=n.to;let r=n.to-n.from===1;return t===`Backspace`?r&&e.from===n.to:r&&e.from===n.from}var he=t.t(()=>({key:`inlineContentBoundaryEdit`,prosemirrorPlugins:[new s.Plugin({key:pe,props:{handleKeyDown:(e,t)=>{if(!e.editable)return!1;let n=t.key.length===1&&!t.ctrlKey&&!t.metaKey;if(!n&&t.key!==`Backspace`&&t.key!==`Delete`)return!1;let{selection:r}=e.state,i=r.$from.node();if(!i.type.spec.inline)return!1;let a=r.$from.before(),o=a+1,c=a+1+i.content.size;if(n&&i.content.size===0){let n=e.state.tr.insert(o,e.state.schema.text(t.key));return n.setSelection(s.TextSelection.create(n.doc,o+t.key.length)),e.dispatch(n),!0}if(i.content.size>0&&me(r,t.key,{from:o,to:c})){let t=e.state.tr.delete(o,c);return t.setSelection(s.TextSelection.create(t.doc,o)),e.dispatch(t),!0}return!1}}})]})),ge=t.t(({editor:e})=>{function t(t){let n=e.prosemirrorView.nodeDOM(t);for(;n&&n.parentElement;){if(n.nodeName===`A`)return n;n=n.parentElement}return null}function n(t){let n=e.getLinkMarkAtPos(t);if(n)return{range:{from:n.from,to:n.to},mark:{attrs:{href:n.href}},get text(){return n.text},get position(){return(0,a.posToDOMRect)(e.prosemirrorView,n.from,n.to).toJSON()}}}function r(){return e.transact(e=>{if(e.selection.empty)return n(e.selection.anchor)})}return{key:`linkToolbar`,getLinkAtSelection:r,getLinkElementAtPos:t,getMarkAtPos(e,t){return n(e)},getLinkAtElement(t){return e.transact(()=>n(e.prosemirrorView.posAtDOM(t,0)+1))},editLink(t,n,r=e.transact(e=>e.selection.anchor)){e.editLink(t,n,r)},deleteLink(t=e.transact(e=>e.selection.anchor)){e.deleteLink(t)}}}),_e=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`],ve=`https`,ye=new s.PluginKey(`node-selection-keyboard`),be=t.t(()=>({key:`nodeSelectionKeyboard`,prosemirrorPlugins:[new s.Plugin({key:ye,props:{handleKeyDown:(e,t)=>{if(`node`in e.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(t.key.length===1)return t.preventDefault(),!0;if(t.key===`Enter`&&!t.isComposing&&!t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey){let t=e.state.tr;return e.dispatch(t.insert(e.state.tr.selection.$to.after(),e.state.schema.nodes.paragraph.createChecked()).setSelection(new s.TextSelection(t.doc.resolve(e.state.tr.selection.$to.after()+1)))),!0}}return!1}}})]})),xe=new s.PluginKey(`blocknote-placeholder`),Se=t.t(({editor:e,options:t})=>{let n=t.placeholders;return{key:`placeholder`,prosemirrorPlugins:[new s.Plugin({key:xe,view:t=>{let r=`placeholder-selector-${(0,o.uuidv4)()}`;t.dom.classList.add(r);let i=document.createElement(`style`),a=e._tiptapEditor.options.injectNonce;a&&i.setAttribute(`nonce`,a),t.root instanceof window.ShadowRoot?t.root.append(i):t.root.head.appendChild(i);let s=i.sheet,c=(e=``)=>`.${r} .bn-block-content${e}:has(.ProseMirror-trailingBreak:only-child):after`;try{let{default:e,emptyDocument:t,...r}=n||{};for(let[e,t]of Object.entries(r)){let n=`[data-content-type="${e}"]`;s.insertRule(`${c(n)} { content: ${JSON.stringify(t)}; }`)}s.insertRule(`${c(`[data-is-only-empty-block]`)} { content: ${JSON.stringify(t)}; }`),s.insertRule(`${c(`[data-is-empty-and-focused]`)} { content: ${JSON.stringify(e)}; }`)}catch(e){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)`,e)}return{destroy:()=>{t.root instanceof window.ShadowRoot?t.root.removeChild(i):t.root.head.removeChild(i)}}},props:{decorations:t=>{let{doc:n,selection:r}=t;if(!e.isEditable||!r.empty||r.$from.parent.type.spec.code)return;let i=[];t.doc.content.size===6&&i.push(d.Decoration.node(2,4,{"data-is-only-empty-block":`true`}));let a=r.$anchor,o=a.parent;if(o.content.size===0){let e=a.before();i.push(d.Decoration.node(e,e+o.nodeSize,{"data-is-empty-and-focused":`true`}))}return d.DecorationSet.create(n,i)}}})]}}),Ce=t.t(({editor:e})=>{let t=new i.Mapping,n=0;function r(){t=new i.Mapping,n=0}let a=typeof FinalizationRegistry<`u`?new FinalizationRegistry(()=>{n--,n===0&&r()}):null;return e.on(`create`,()=>{e._tiptapEditor.on(`transaction`,({transaction:e})=>{n!==0&&t.appendMapping(e.mapping)}),e._tiptapEditor.on(`destroy`,()=>{r()})}),{key:`positionMapping`,mapPosition:(e,r=`left`)=>{n++;let i=t.maps.length,o=()=>t.slice(i).map(e,r===`left`?-1:1);return a&&a.register(o,void 0),o}}}),C=new s.PluginKey(`previous-blocks`),we={index:`index`,level:`level`,type:`type`,depth:`depth`,"depth-change":`depth-change`},Te=t.t(()=>{let t;return{key:`previousBlockType`,prosemirrorPlugins:[new s.Plugin({key:C,view(e){return{update:async(e,n)=>{this.key?.getState(e.state).updatedBlocks.size>0&&(t=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(C,{clearUpdate:!0}))},0))},destroy:()=>{t&&clearTimeout(t)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,n,r,i){if(n.currentTransactionOldBlockAttrs={},n.updatedBlocks.clear(),!t.docChanged)return n;let o=t.changedRange();if(!o)return n;let s=t.mapping.invert(),c={from:s.map(o.from,-1),to:s.map(o.to,1)},l={},u=(0,a.findChildrenInRange)(r.doc,c,e=>e.attrs.id),d=new Map(u.map(t=>[e.or(t.node,r.doc),t])),f=(0,a.findChildrenInRange)(i.doc,o,e=>e.attrs.id);for(let t of f){let a=e.or(t.node,i.doc),o=d.get(a),s=o?.node.firstChild,c=t.node.firstChild;if(o&&s&&c){let e={index:c.attrs.index,level:c.attrs.level,type:c.type.name,depth:i.doc.resolve(t.pos).depth},u={index:s.attrs.index,level:s.attrs.level,type:s.type.name,depth:r.doc.resolve(o.pos).depth};l[a]=u,n.currentTransactionOldBlockAttrs[a]=u,(u.index!==e.index||u.level!==e.level||u.type!==e.type||u.depth!==e.depth)&&(u[`depth-change`]=u.depth-e.depth,n.updatedBlocks.add(a))}}return n.prevTransactionOldBlockAttrs=l,n}},props:{decorations(t){let n=this.getState(t);if(n.updatedBlocks.size===0)return;let r=[];return t.doc.descendants((i,a)=>{if(!i.attrs.id)return;let o=e.or(i,t.doc);if(!n.updatedBlocks.has(o))return;let s=n.currentTransactionOldBlockAttrs[o],c={};for(let[e,t]of Object.entries(s))c[`data-prev-`+we[e]]=t||`none`;r.push(d.Decoration.node(a,a+i.nodeSize,{...c}))}),d.DecorationSet.create(t.doc,r)}}})]}});function w(e,t){for(;e&&e.parentElement&&e.parentElement!==t.dom&&e.getAttribute?.(`data-node-type`)!==`blockContainer`;)e=e.parentElement;if(e.getAttribute?.(`data-node-type`)===`blockContainer`)return{node:e,id:e.getAttribute(`data-id`)}}function Ee(e){let t=document.createElement(`div`);return t.innerHTML=e,T(t,{indent:``,inListItem:!1}).trim()+`
`}function T(e,t){let n=``,r=Array.from(e.childNodes);for(let e=0;e<r.length;e++){let i=r[e];n+=E(i,t)}return n}function E(e,t){if(e.nodeType===3)return e.textContent||``;if(e.nodeType!==1)return``;let n=e;switch(n.tagName.toLowerCase()){case`p`:return De(n,t);case`h1`:case`h2`:case`h3`:case`h4`:case`h5`:case`h6`:return D(n,t);case`blockquote`:return Oe(n,t);case`pre`:return ke(n,t);case`ul`:return Me(n,t);case`ol`:return Ne(n,t);case`table`:return Fe(n,t);case`hr`:return t.indent+`***

`;case`math`:return Ae(n,t);case`img`:return Le(n,t);case`video`:return Re(n,t);case`audio`:return ze(n,t);case`embed`:return Be(n,t);case`figure`:return Ve(n,t);case`a`:return F(n,t);case`details`:return We(n,t);case`div`:return T(n,t);case`br`:return``;default:return T(n,t)}}function De(e,t){let n=Ge(L(e));return t.inListItem?n:t.indent+n+`

`}function D(e,t){let n=parseInt(e.tagName[1],10),r=`#`.repeat(n)+` `,i=L(e);return t.indent+r+i+`

`}function Oe(e,t){let n=Array.from(e.children).filter(e=>{let t=e.tagName.toLowerCase();return[`p`,`ul`,`ol`,`pre`,`blockquote`,`table`,`hr`].includes(t)}),r;if(n.length>0){let e=[];for(let t of n)t.tagName.toLowerCase()===`p`?e.push(L(t)):e.push(E(t,{indent:``,inListItem:!1}).trim());r=e.join(`

`)}else r=L(e);return r.split(`
`).map(e=>t.indent+`> `+e).join(`
`)+`

`}function ke(e,t){let n=e.querySelector(`code`);if(!n)return``;let r=n.getAttribute(`data-language`)||je(n.className)||``,i=k(n),a=Math.max(0,...(i.match(/`+/g)??[]).map(e=>e.length)),o="`".repeat(Math.max(3,a+1));return i?[o+r,...(i.endsWith(`
`)?i.slice(0,-1):i).split(`
`),o].map(e=>e&&t.indent+e).join(`
`)+`

`:t.indent+o+r+`
`+t.indent+o+`

`}function O(e){return(e.querySelector(`annotation[encoding="application/x-tex"]`)?.textContent??e.textContent??``).trim()}function Ae(e,t){return[`$$`,...O(e).split(`
`),`$$`].map(e=>e&&t.indent+e).join(`
`)+`

`}function k(e){let t=``;for(let n of Array.from(e.childNodes))n.nodeType===3?t+=n.textContent||``:n.nodeType===1&&(n.tagName.toLowerCase()===`br`?t+=`
`:t+=k(n));return t}function je(e){let t=e.match(/language-(\S+)/);return t?t[1]:``}function Me(e,t){let n=``,r=Array.from(e.children).filter(e=>e.tagName.toLowerCase()===`li`);for(let e of r)n+=A(e,`bullet`,t);return t.inListItem||(n+=`
`),n}function Ne(e,t){let n=``,r=Array.from(e.children).filter(e=>e.tagName.toLowerCase()===`li`),i=parseInt(e.getAttribute(`start`)||`1`,10);for(let e=0;e<r.length;e++){let a=i+e;n+=A(r[e],`ordered`,t,a)}return t.inListItem||(n+=`
`),n}function A(e,t,n,r){let i=null,a=null;for(let t of Array.from(e.children)){let e=t.tagName.toLowerCase();e===`input`&&t.type===`checkbox`&&(i=t),e===`details`&&(a=t)}let o,s;i?(o=`* ${i.checked?`[x]`:`[ ]`} `,s=2):t===`ordered`?(o=`${r}. `,s=o.length):(o=`* `,s=2);let c,l;if(a){let e=a.querySelector(`summary`)?.querySelector(`p`);l=a,c=e?L(e):``}else l=Pe(e,i),c=l?L(l):``;let u=n.indent+o+c+`
`,d=n.indent+` `.repeat(s),f={indent:d,inListItem:!0};if(a){let e=a.querySelector(`summary`);for(let t of Array.from(a.children))if(t!==e){if(t.tagName.toLowerCase()===`p`){let e=L(t);u+=`
`+d+e+`
`}else u+=E(t,f)}}let p=Array.from(e.children);for(let e of p){let t=e.tagName.toLowerCase();if(e!==l&&e!==i&&t!==`input`){if(t===`ul`||t===`ol`)u+=E(e,f);else if(t===`p`){let t=L(e);u+=`
`+d+t+`
`}else u+=`
`+E(e,f)}}return u}function Pe(e,t){for(let n of Array.from(e.children)){if(n===t||n.tagName.toLowerCase()===`input`)continue;let e=n.tagName.toLowerCase();if(e===`p`||e===`span`)return n}return null}function Fe(e,t){let n=e.querySelector(`colgroup`),r=0;n&&(r=n.querySelectorAll(`col`).length);let i=[],a=!1,o=e.querySelectorAll(`tr`),s=[];o.forEach((e,t)=>{s[t]||(s[t]=[]);let n=e.querySelectorAll(`th, td`),i=0;n.forEach(e=>{for(;s[t][i]!==void 0;)i++;t===0&&e.tagName.toLowerCase()===`th`&&(a=!0);let n=Ie(L(e).trim()),r=parseInt(e.getAttribute(`colspan`)||`1`,10),o=parseInt(e.getAttribute(`rowspan`)||`1`,10);for(let e=0;e<o;e++)for(let a=0;a<r;a++){let r=t+e;s[r]||(s[r]=[]),s[r][i+a]=e===0&&a===0?n:``}i+=r}),s[t]&&(r=Math.max(r,s[t].length))});for(let e of s){let t=[];for(let n=0;n<r;n++)t.push(e&&e[n]!==void 0?e[n]??``:``);i.push(t)}if(i.length===0)return``;let c=[];for(let e=0;e<r;e++){let t=3;for(let n of i){let r=e<n.length?n[e].length:0;t=Math.max(t,r)}c.push(Math.max(t,10))}let l=``;if(a){l+=t.indent+j(i[0],c,r)+`
`,l+=t.indent+M(c,r)+`
`;for(let e=1;e<i.length;e++)l+=t.indent+j(i[e],c,r)+`
`}else{let e=Array(r).fill(``);l+=t.indent+j(e,c,r)+`
`,l+=t.indent+M(c,r)+`
`;for(let e of i)l+=t.indent+j(e,c,r)+`
`}return l+=`
`,l}function Ie(e){return e.replace(/\|/g,`\\|`)}function j(e,t,n){let r=[];for(let i=0;i<n;i++){let n=i<e.length?e[i]:``;r.push(` `+n.padEnd(t[i])+` `)}return`|`+r.join(`|`)+`|`}function M(e,t){let n=[];for(let r=0;r<t;r++)n.push(` `+`-`.repeat(e[r])+` `);return`|`+n.join(`|`)+`|`}function Le(e,t){let n=e.getAttribute(`src`)||``,r=e.getAttribute(`alt`)||``;return n?t.indent+`![${r}](${n})\n\n`:`

`}function Re(e,t){let n=e.getAttribute(`src`)||e.getAttribute(`data-url`)||``,r=e.getAttribute(`data-name`)||e.getAttribute(`title`)||``;return n?t.indent+`![${r}](${n})\n\n`:`

`}function ze(e,t){let n=e.getAttribute(`src`)||``;return n?t.indent+`<audio src="${P(n)}" controls></audio>\n\n`:`

`}function Be(e,t){let n=e.getAttribute(`src`)||``;return n?t.indent+`[](${n})\n\n`:`

`}function Ve(e,t){let n=e.querySelector(`img`),r=e.querySelector(`video`),i=e.querySelector(`audio`),a=e.querySelector(`a`),o=e.querySelector(`figcaption`)?.textContent?.trim()||``;return n?N(`img`,n.getAttribute(`src`)||``,n.getAttribute(`alt`)||``,o,t):r?N(`video`,r.getAttribute(`src`)||r.getAttribute(`data-url`)||``,r.getAttribute(`data-name`)||r.getAttribute(`title`)||``,o,t):i?N(`audio`,i.getAttribute(`src`)||``,``,o,t):a?F(a,t):``}function N(e,t,n,r,i){if(!t)return``;if(!r&&e!==`audio`)return i.indent+`![${n}](${t})\n\n`;let a=n&&n!==r?e===`img`?` alt="${P(n)}"`:e===`video`?` data-name="${P(n)}"`:``:``,o=e===`img`?`<img${a} src="${P(t)}">`:`<${e} src="${P(t)}"${a} controls></${e}>`,s=r?`<figcaption>${He(r)}</figcaption>`:``;return i.indent+`<figure>${o}${s}</figure>\n\n`}function P(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function He(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function F(e,t){let n=e.getAttribute(`href`)||``,r=e.textContent?.trim()||``;return n?t.indent+I(r,n)+`

`:t.indent+r+`

`}function I(e,t){return!e||e===t?t:`[${e}](${Ue(t)})`}function Ue(e){return e.replace(/[\\()]/g,`\\$&`)}function We(e,t){let n=e.querySelector(`summary`);if(!n)return T(e,t);let r=n.querySelector(`h1, h2, h3, h4, h5, h6`);if(r){let i=D(r,t);for(let r of Array.from(e.children))r!==n&&(i+=E(r,t));return i}return T(n,t)}function L(e){let t=``;for(let n of Array.from(e.childNodes))if(n.nodeType===3)t+=n.textContent||``;else if(n.nodeType===1){let e=n;switch(e.tagName.toLowerCase()){case`strong`:case`b`:{let{content:n,trailing:r}=R(L(e));t+=n?`**${n}**${r}`:r;break}case`em`:case`i`:{let{content:n,trailing:r}=R(L(e));t+=n?`*${n}*${r}`:r;break}case`s`:case`del`:t+=`~~${L(e)}~~`;break;case`code`:{let n=e.textContent||``,r=Math.max(0,...(n.match(/`+/g)??[]).map(e=>e.length)),i="`".repeat(r+1),a=n.startsWith("`")||n.endsWith("`");t+=i+(a?` ${n} `:n)+i;break}case`u`:t+=L(e);break;case`a`:{let n=e.getAttribute(`href`)||``,r=L(e);t+=I(r,n);break}case`br`:t+=`\\
`;break;case`math`:{let n=O(e).split(`
`).map(e=>e.trim()).join(` `);t+=`$${n}$`;break}case`span`:t+=L(e);break;case`img`:{let n=e.getAttribute(`src`)||``,r=e.getAttribute(`alt`)||``;t+=`![${r}](${n})`;break}case`video`:{let n=e.getAttribute(`src`)||e.getAttribute(`data-url`)||``,r=e.getAttribute(`data-name`)||e.getAttribute(`title`)||``;t+=`![${r}](${n})`;break}case`p`:t+=L(e);break;case`input`:break;default:t+=L(e)}}return t}function R(e){let t=e.match(/^(.*?)(\s*)$/);return t?{content:t[1],trailing:t[2]}:{content:e,trailing:``}}function Ge(e){let t=e.replace(/^(\\\n)+/,``);return t=t.replace(/(\\\n)+$/,``),t}function z(e){return Ee(e.split(``).join(``))}function Ke(e,t,n,r){return z(b(t,n).exportBlocks(e,r))}function qe(t){let n=[];return t.descendants(t=>t.type.name===`blockContainer`&&t.firstChild?.type.name===`blockGroup`?!0:t.type.name===`columnList`&&t.childCount===1?(t.firstChild?.forEach(r=>{n.push(e.Tn(r,t))}),!1):!t.type.isInGroup(`bnBlock`)||(n.push(e.Tn(t,t)),!1)),n}var B=class e extends s.Selection{nodes;constructor(e,t){super(e,t);let n=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,t.pos,(e,t,r)=>{if(r!==null&&r.eq(n))return this.nodes.push(e),!1})}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}content(){return new r.Slice(r.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof e)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let e=0;e<this.nodes.length;e++)if(!this.nodes[e].eq(t.nodes[e]))return!1;return!0}map(t,n){let r=n.mapResult(this.from),i=n.mapResult(this.to);return i.deleted?s.Selection.near(t.resolve(r.pos)):r.deleted?s.Selection.near(t.resolve(i.pos)):new e(t.resolve(r.pos),t.resolve(i.pos))}toJSON(){return{type:`multiple-node`,anchor:this.anchor,head:this.head}}};s.Selection.jsonID(`multiple-node`,B);var V;function Je(e,t){let n,r,i=t.resolve(e.from).node().type.spec.group===`blockContent`,a=t.resolve(e.to).node().type.spec.group===`blockContent`,o=Math.min(e.$anchor.depth,e.$head.depth);if(i&&a){let i=e.$from.start(o-1),a=e.$to.end(o-1);n=t.resolve(i-1).pos,r=t.resolve(a+1).pos}else n=e.from,r=e.to;return{from:n,to:r}}function Ye(e,t,n=t){t===n&&(n+=e.state.doc.resolve(t+1).node().nodeSize);let r=e.domAtPos(t).node.cloneNode(!0),i=e.domAtPos(t).node,a=(e,t)=>Array.prototype.indexOf.call(e.children,t),o=a(i,e.domAtPos(t+1).node.parentElement),s=a(i,e.domAtPos(n-1).node.parentElement);for(let e=i.childElementCount-1;e>=0;e--)(e>s||e<o)&&r.removeChild(r.children[e]);Xe(e.root),V=r,V.querySelectorAll(`iframe, embed, object`).forEach(e=>e.parentElement?.removeChild(e));let c=e.dom.className.split(` `).filter(e=>e!==`ProseMirror`&&e!==`bn-root`&&e!==`bn-editor`).join(` `);V.className=V.className+` bn-drag-preview `+c,e.root instanceof ShadowRoot?e.root.appendChild(V):e.root.body.appendChild(V)}function Xe(e){V!==void 0&&(e instanceof ShadowRoot?e.removeChild(V):e.body.removeChild(V),V=void 0)}function Ze(t,n,r){if(!t.dataTransfer||r.headless)return;let i=r.prosemirrorView,a=e.Pt(n.id,i.state.doc);if(!a)throw Error(`Block with ID ${n.id} not found`);let o=a.posBeforeNode;if(o!=null){let e=i.state.selection,n=i.state.doc,{from:a,to:c}=Je(e,n),l=a<=o&&o<c,u=e.$anchor.node()!==e.$head.node()||e instanceof B;l&&u?(i.dispatch(i.state.tr.setSelection(B.create(n,a,c))),Ye(i,a,c)):(i.dispatch(i.state.tr.setSelection(s.NodeSelection.create(i.state.doc,o))),Ye(i,o));let d=i.state.selection.content(),f=r.pmSchema,p=i.serializeForClipboard(d).dom.innerHTML,m=b(f,r),h=qe(d.content),g=m.exportBlocks(h,{}),_=z(g);t.dataTransfer.clearData(),t.dataTransfer.setData(`blocknote/html`,p),t.dataTransfer.setData(`text/html`,g),t.dataTransfer.setData(`text/plain`,_),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setDragImage(V,0,0)}}var Qe=250;function H(e,t,n=!0){let r=e.root.elementsFromPoint(t.left,t.top);for(let i of r)if(e.dom.contains(i))return n&&i.closest(`[data-node-type=columnList]`)?H(e,{left:t.left+50,top:t.top},!1):w(i,e)}function $e(e,t){if(!t.dom.firstChild)return;let n=t.dom.firstChild.getBoundingClientRect(),r=H(t,{left:Math.min(Math.max(n.left+10,e.x),n.right-10),top:e.y});if(r)return H(t,{left:r.node.getBoundingClientRect().right-10,top:e.y},!1)}var et=class{editor;pmView;state;emitUpdate;mousePos;hoveredBlock;menuFrozen=!1;isDragOrigin=!1;constructor(e,t,n){this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw Error(`Attempting to update uninitialized side menu`);n(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)}updateState=e=>{this.state=e,this.emitUpdate(this.state)};updateStateFromMousePos=()=>{if(this.menuFrozen||!this.mousePos)return;let e=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if(e?.element!==this.pmView.dom||e.distance>Qe){this.state?.show&&(this.state.show=!1,this.updateState(this.state));return}let t=$e(this.mousePos,this.pmView);if(!t||!this.editor.isEditable){this.state?.show&&(this.state.show=!1,this.updateState(this.state));return}if(!(this.state?.show&&this.hoveredBlock?.hasAttribute(`data-id`)&&this.hoveredBlock?.getAttribute(`data-id`)===t.id)&&(this.hoveredBlock=t.node,this.editor.isEditable)){let e=t.node.getBoundingClientRect(),n=t.node.closest(`[data-node-type=column]`),r=this.editor.getBlock(this.hoveredBlock.getAttribute(`data-id`));if(!r){this.state?.show&&(this.state.show=!1,this.hoveredBlock=void 0,this.emitUpdate(this.state));return}this.state={show:!0,referencePos:new DOMRect(n?n.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,e.y,e.width,e.height),block:r},this.updateState(this.state)}};onDragStart=e=>{let t=e.dataTransfer?.getData(`blocknote/html`);if(!t||this.pmView.dragging)return;let n=document.createElement(`div`);n.innerHTML=t;let r=c.DOMParser.fromSchema(this.pmView.state.schema).parse(n,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new c.Slice(r.content,0,0),move:!0}};findClosestEditorElement=e=>{let t=Array.from(this.pmView.root.querySelectorAll(`.bn-editor`));if(t.length===0)return null;let n=t[0],r=Number.MAX_VALUE;return t.forEach(t=>{let i=t.querySelector(`.bn-block-group`).getBoundingClientRect(),a=e.clientX<i.left?i.left-e.clientX:e.clientX>i.right?e.clientX-i.right:0,o=e.clientY<i.top?i.top-e.clientY:e.clientY>i.bottom?e.clientY-i.bottom:0,s=Math.sqrt(a**2+o**2);s<r&&(r=s,n=t)}),{element:n,distance:r}};onDragOver=e=>{if(e.synthetic||!(this.pmView.dragging!==null||this.isDragOrigin||e.dataTransfer?.types.includes(`blocknote/html`)||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;let t=this.getDragEventContext(e);if(!t||!t.isDropPoint){this.closeDropCursor();return}t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(e)};closeDropCursor=()=>{let e=new Event(`dragleave`,{bubbles:!1});e.synthetic=!0,this.pmView.dom.dispatchEvent(e)};getDragEventContext=e=>{if(!(this.pmView.dragging!==null||this.isDragOrigin||e.dataTransfer?.types.includes(`blocknote/html`)||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;let t=!e.dataTransfer?.types.includes(`blocknote/html`)&&!!this.pmView.dragging,n=!!this.isDragOrigin,r=t||n,i=this.findClosestEditorElement(e);if(!i||i.distance>Qe)return;let a=i.element===this.pmView.dom,o=a&&i.distance===0;if(!(!a&&!r))return{isDropPoint:a,isDropWithinEditorBounds:o,isDragOrigin:r}};onDrop=e=>{if(e.synthetic||!(this.pmView.dragging!==null||this.isDragOrigin||e.dataTransfer?.types.includes(`blocknote/html`)||e.target instanceof Node&&this.pmView.dom.contains(e.target)))return;let t=this.getDragEventContext(e);if(!t){this.closeDropCursor();return}let{isDropPoint:n,isDropWithinEditorBounds:r,isDragOrigin:i}=t;if(!r&&n&&this.dispatchSyntheticEvent(e),n){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(u.TextSelection.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)));return}if(i){setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0);return}};onDragEnd=e=>{e.synthetic||(this.pmView.dragging=null)};onKeyDown=e=>{this.state?.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))};onMouseMove=e=>{if(this.menuFrozen||!Number.isFinite(e.clientX)||!Number.isFinite(e.clientY))return;this.mousePos={x:e.clientX,y:e.clientY};let t=this.pmView.dom.getBoundingClientRect();if(this.mousePos.x>t.left&&this.mousePos.x<t.right&&this.mousePos.y>t.top&&this.mousePos.y<t.bottom&&e&&e.target&&!this.editor.isWithinEditor(e.target)){this.state?.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateStateFromMousePos()};dispatchSyntheticEvent(e){let t=new Event(e.type,e),n=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=e.clientX,t.clientY=e.clientY,t.clientX=Math.min(Math.max(e.clientX,n.left),n.left+n.width),t.clientY=Math.min(Math.max(e.clientY,n.top),n.top+n.height),t.dataTransfer=e.dataTransfer,t.preventDefault=()=>e.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(e,t){!t.doc.eq(this.pmView.state.doc)&&this.state?.show&&this.updateStateFromMousePos()}destroy(){this.state?.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)}},tt=new u.PluginKey(`SideMenuPlugin`),nt=t.t(({editor:e})=>{let n,r=t.n(void 0);return{key:`sideMenu`,store:r,prosemirrorPlugins:[new u.Plugin({key:tt,view:t=>(n=new et(e,t,e=>{r.setState({...e})}),n)})],blockDragStart(t,r){n&&(n.isDragOrigin=!0),Ze(t,r,e)},blockDragEnd(){Xe(e.prosemirrorView.root),n&&(n.isDragOrigin=!1),e.blur()},get menuFrozen(){return n.menuFrozen},freezeMenu(){n.menuFrozen=!0,n.state.show=!0,n.emitUpdate(n.state)},unfreezeMenu(){n.menuFrozen=!1,n.state.show=!1,n.emitUpdate(n.state)},hideMenuIfNotFrozen(){!n.menuFrozen&&n.state?.show&&(n.state.show=!1,n.emitUpdate(n.state))}}}),rt=t.t(({editor:e})=>{let n=t.n({popupOpen:void 0,selected:void 0}),r=t=>!!e.schema.blockSpecs[t.type]?.implementation?.meta?.hasPreview,i=e=>({editor:t})=>{let{block:i,prevBlock:a,nextBlock:o}=t.getTextCursorPosition();if(!r(i)||n.state.popupOpen===i.id)return!1;let s=e===`prev`?a:o;return s?(t.setTextCursorPosition(s.id,e===`prev`?`end`:`start`),!0):!1};return{key:`sourceBlockWithPreview`,store:n,keyboardShortcuts:{Enter:({editor:e})=>{let{block:t}=e.getTextCursorPosition();if(!r(t))return!1;if(n.state.popupOpen===t.id&&e.schema.blockSpecs[t.type]?.implementation?.meta?.hardBreakShortcut===`enter`){let t=e.prosemirrorView;return t.dispatch(t.state.tr.insertText(`
`)),!0}return e.setTextCursorPosition(t.id,`end`),n.setState(e=>({...e,popupOpen:n.state.popupOpen===t.id?void 0:t.id})),!0},Escape:({editor:e})=>{let{block:t}=e.getTextCursorPosition();return!r(t)||n.state.popupOpen!==t.id?!1:(e.setTextCursorPosition(t.id,`end`),n.setState(e=>({...e,popupOpen:void 0})),!0)},"Mod-a":({editor:e})=>{let{block:t}=e.getTextCursorPosition();if(!r(t)||n.state.popupOpen!==t.id)return!1;let i=e.prosemirrorView,{$from:a}=i.state.selection;return a.parent.type.name===t.type&&(i.dispatch(i.state.tr.setSelection(s.TextSelection.create(i.state.doc,a.start(),a.end()))),!0)},ArrowUp:i(`prev`),ArrowLeft:i(`prev`),ArrowDown:i(`next`),ArrowRight:i(`next`)},mount:({dom:t,signal:i})=>{let a=e.onSelectionChange(()=>{let{block:t}=e.getTextCursorPosition(),i=r(t)?t.id:void 0,a=n.state.popupOpen&&n.state.popupOpen!==t.id?void 0:n.state.popupOpen;(i!==n.state.selected||a!==n.state.popupOpen)&&n.setState(e=>({...e,selected:i,popupOpen:a}))});i.addEventListener(`abort`,a),t.addEventListener(`keydown`,t=>{if(!e.isEditable)return;let{block:i}=e.getTextCursorPosition();if(!(!r(i)||n.state.popupOpen===i.id)){if(t.key===`Backspace`||t.key===`Delete`){t.preventDefault(),t.stopImmediatePropagation(),e.removeBlocks([i.id]);return}(t.key.length===1&&!t.ctrlKey&&!t.metaKey||t.key===`Tab`)&&(t.preventDefault(),t.stopImmediatePropagation())}},{capture:!0,signal:i}),t.addEventListener(`blur`,()=>n.setState(e=>({...e,popupOpen:void 0})),{capture:!0,signal:i})}}}),it=t.t(({editor:e})=>{let n=t.n({selected:void 0}),r=t=>!!e.schema.inlineContentSpecs[t]?.implementation?.meta?.hasPreview,i=e=>({editor:t})=>{let{$from:n}=t.prosemirrorState.selection,i=n.node();if(!r(i.type.name))return!1;let a=t.prosemirrorView,o=s.Selection.near(a.state.doc.resolve(e===`before`?n.before():n.after()),e===`before`?-1:1);return a.dispatch(a.state.tr.setSelection(o)),!0};return{key:`sourceInlineContentWithPreview`,store:n,keyboardShortcuts:{Enter:i(`after`),"Shift-Enter":i(`after`),Escape:i(`after`),ArrowUp:i(`before`),ArrowDown:i(`after`),"Mod-a":({editor:e})=>{let{$from:t}=e.prosemirrorState.selection;if(!r(t.node().type.name))return!1;let n=e.prosemirrorView;return n.dispatch(n.state.tr.setSelection(s.TextSelection.create(n.state.doc,t.start(),t.end()))),!0}},mount:({dom:t,signal:i})=>{let a=e.onSelectionChange(()=>{let{$from:t}=e.prosemirrorState.selection,i=t.node();n.setState({selected:r(i.type.name)?t.before():void 0})});i.addEventListener(`abort`,a),t.addEventListener(`keydown`,n=>{if(n.key!==`ArrowUp`&&n.key!==`ArrowDown`)return;let{$from:i}=e.prosemirrorState.selection;r(i.node().type.name)||(t.classList.add(`bn-suppress-source-popup-caret`),requestAnimationFrame(()=>t.classList.remove(`bn-suppress-source-popup-caret`)))},{capture:!0,signal:i}),t.addEventListener(`blur`,()=>n.setState({selected:void 0}),{capture:!0,signal:i})}}}),at=Symbol.for(`blocknote.shikiParser`),U=Symbol.for(`blocknote.shikiHighlighterPromise`),ot=[`text`,`none`,`plaintext`,`txt`];function st(e,t,n){let r=globalThis,i,a,o=new Set;return(0,m.createHighlightPlugin)({parser:t=>{if(!e.createHighlighter)return[];if(!i)return r[U]=r[U]||e.createHighlighter(),r[U].then(e=>{i=e});let n=t.language;return!n||ot.includes(n)||o.has(n)?[]:i.getLoadedLanguages().includes(n)?(a||(a=r[at]||(0,h.createParser)(i,ct(i)),r[at]=a),a(t)):i.loadLanguage(n).catch(()=>{o.add(n)})},languageExtractor:e=>{let t={type:e.type.name,props:e.attrs};return(n.blockSpecs[t.type]||n.inlineContentSpecs[t.type])?.implementation?.meta?.highlight?.(t)??void 0},nodeTypes:t})}function ct(e){let t=e.getLoadedThemes(),n=t.find(e=>/light/i.test(e)),r=t.find(e=>/dark/i.test(e));if(n&&r)return{themes:{light:n,dark:r},defaultColor:!1}}function lt(e){let t=Object.values(e.blockSpecs).filter(e=>typeof e?.config==`object`&&e.config.content===`plain`&&!!e.implementation?.meta?.highlight).map(e=>e.config.type),n=Object.values(e.inlineContentSpecs).filter(e=>typeof e?.config==`object`&&e.config.content===`plain`&&!!e.implementation?.meta?.highlight).map(e=>e.config.type);return[...t,...n]}var ut=t.t(({editor:e,options:t})=>({key:`syntaxHighlighting`,prosemirrorPlugins:[st(t,lt(e.schema),e.schema)]})),W;async function dt(){return W||(W=(async()=>{let[e,t]=await Promise.all([import(`emoji-mart`),import(`@emoji-mart/data`)]),n=`default`in e?e.default:e,r=`default`in t?t.default:t;return await n.init({data:r}),{emojiMart:n,emojiData:r}})(),W)}async function ft(t,n){if(!(`text`in t.schema.inlineContentSchema)||t.schema.inlineContentSchema.text!==e.r.text)return[];let{emojiData:r,emojiMart:i}=await dt();return(n.trim()===``?Object.values(r.emojis):await i.SearchIndex.search(n)).map(e=>({id:e.skins[0].native,onItemClick:()=>t.insertInlineContent(e.skins[0].native+` `)}))}var G;function pt(e){G||(G=document.createElement(`div`),G.innerHTML=`_`,G.style.opacity=`0`,G.style.height=`1px`,G.style.width=`1px`,e instanceof Document?e.body.appendChild(G):e.appendChild(G))}function mt(e){G&&=(e instanceof Document?e.body.removeChild(G):e.removeChild(G),void 0)}function K(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function ht(e){let t=e;for(;t&&t.nodeName!==`TD`&&t.nodeName!==`TH`&&!t.classList.contains(`tableWrapper`);){if(t.classList.contains(`ProseMirror`))return;let 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 gt(e,t){let n=t.querySelectorAll(e);for(let e=0;e<n.length;e++)n[e].style.visibility=`hidden`}var _t=class{editor;pmView;state;emitUpdate;tableId;tablePos;tableElement;menuFrozen=!1;mouseState=`up`;prevWasEditable=null;constructor(e,t,n){this.editor=e,this.pmView=t,this.emitUpdate=()=>{n(this.state)},t.dom.addEventListener(`mousemove`,this.mouseMoveHandler),t.dom.addEventListener(`mousedown`,this.viewMousedownHandler),window.addEventListener(`mouseup`,this.mouseUpHandler),t.root.addEventListener(`dragover`,this.dragOverHandler),t.root.addEventListener(`drop`,this.dropHandler)}viewMousedownHandler=()=>{this.mouseState=`down`};mouseUpHandler=e=>{this.mouseState=`up`,this.mouseMoveHandler(e)};mouseMoveHandler=t=>{if(this.menuFrozen||this.mouseState===`selecting`||!(t.target instanceof Element)||!this.pmView.dom.contains(t.target))return;let n=ht(t.target);if(n?.type===`cell`&&this.mouseState===`down`&&!this.state?.draggingState){this.mouseState=`selecting`,this.state?.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!n||!this.editor.isEditable){this.state?.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate());return}if(!n.tbodyNode)return;let r=n.tbodyNode.getBoundingClientRect(),i=w(n.domNode,this.pmView);if(!i)return;this.tableElement=i.node;let a,{pmNodeInfo:o,doc:s}=this.editor.transact(t=>({pmNodeInfo:e.Pt(i.id,t.doc),doc:t.doc}));if(!o)throw Error(`Block with ID ${i.id} not found`);let c=e.Tn(o.node,s);if(e.g(this.editor,`table`)&&(this.tablePos=o.posBeforeNode+1,a=c),!a)return;this.tableId=i.id;let l=n.domNode.closest(`.tableWrapper`)?.querySelector(`.table-widgets-container`);if(n?.type===`wrapper`){let e=t.clientY>=r.bottom-1&&t.clientY<r.bottom+20,n=t.clientX>=r.right-1&&t.clientX<r.right+20,i=this.state?.block?.id!==a.id||t.clientX>r.right||t.clientY>r.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:e,showAddOrRemoveColumnsButton:n,referencePosTable:r,block:a,widgetContainer:l,colIndex:i?void 0:this.state?.colIndex,rowIndex:i?void 0:this.state?.rowIndex,referencePosCell:i?void 0:this.state?.referencePosCell}}else{let e=K(n.domNode),t=K(n.domNode.parentElement),o=n.domNode.getBoundingClientRect();if(this.state!==void 0&&this.state.show&&this.tableId===i.id&&this.state.rowIndex===t&&this.state.colIndex===e)return;this.state={show:!0,showAddOrRemoveColumnsButton:e===a.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:t===a.content.rows.length-1,referencePosTable:r,block:a,draggingState:void 0,referencePosCell:o,colIndex:e,rowIndex:t,widgetContainer:l}}return this.emitUpdate(),!1};dragOverHandler=e=>{if(this.state?.draggingState===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`,gt(`.prosemirror-dropcursor-block, .prosemirror-dropcursor-inline`,this.pmView.root);let t={left:Math.min(Math.max(e.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(e.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},n=this.pmView.root.elementsFromPoint(t.left,t.top).filter(e=>e.tagName===`TD`||e.tagName===`TH`);if(n.length===0)return;let r=n[0],i=!1,a=K(r.parentElement),o=K(r),s=this.state.draggingState.draggedCellOrientation===`row`?this.state.rowIndex:this.state.colIndex,c=(this.state.draggingState.draggedCellOrientation===`row`?a:o)!==s;(this.state.rowIndex!==a||this.state.colIndex!==o)&&(this.state.rowIndex=a,this.state.colIndex=o,this.state.referencePosCell=r.getBoundingClientRect(),i=!0);let l=this.state.draggingState.draggedCellOrientation===`row`?t.top:t.left;this.state.draggingState.mousePos!==l&&(this.state.draggingState.mousePos=l,i=!0),i&&this.emitUpdate(),c&&this.editor.transact(e=>e.setMeta(q,!0))};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 Error(`Attempted to drop table row or column, but no table block was hovered prior.`);t.preventDefault();let{draggingState:n,colIndex:r,rowIndex:i}=this.state;this.state.draggingState=void 0;let a=this.state.block.content.columnWidths;if(n.draggedCellOrientation===`row`){if(!e.Ht(this.state.block,n.originalIndex,i))return!1;let t=e.Jt(this.state.block,n.originalIndex,i);this.editor.updateBlock(this.state.block,{type:`table`,content:{...this.state.block.content,rows:t}})}else{if(!e.Vt(this.state.block,n.originalIndex,r))return!1;let t=e.qt(this.state.block,n.originalIndex,r),[i]=a.splice(n.originalIndex,1);a.splice(r,0,i),this.editor.updateBlock(this.state.block,{type:`table`,content:{...this.state.block.content,columnWidths:a,rows:t}})}return this.editor.setTextCursorPosition(this.state.block.id),!0};update(){if(!this.state||!this.state.show)return;let t=this.editor.getBlock(this.state.block.id);if(!t||t.type!==`table`||!this.tableElement?.isConnected){this.state=void 0,this.tableId=void 0,this.tableElement=void 0,this.emitUpdate();return}this.state.block=t;let{height:n,width:r}=e.Kt(this.state.block);this.state.rowIndex!==void 0&&this.state.colIndex!==void 0&&(this.state.rowIndex>=n&&(this.state.rowIndex=n-1),this.state.colIndex>=r&&(this.state.colIndex=r-1));let i=this.tableElement.querySelector(`tbody`);if(!i)throw 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){let e=i.children[this.state.rowIndex].children[this.state.colIndex];e?this.state.referencePosCell=e.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=i.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)}},q=new s.PluginKey(`TableHandlesPlugin`),vt=t.t(({editor:n})=>{let r,i=t.n(void 0);return{key:`tableHandles`,store:i,prosemirrorPlugins:[new s.Plugin({key:q,view:e=>(r=new _t(n,e,e=>{i.setState(e?.block?{...e,draggingState:e.draggingState?{...e.draggingState}:void 0}:void 0)}),r),props:{decorations:t=>{if(r===void 0||r.state===void 0||r.state.draggingState===void 0||r.tablePos===void 0)return;let n=r.state.draggingState.draggedCellOrientation===`row`?r.state.rowIndex:r.state.colIndex;if(n===void 0)return;let i=[],{block:a,draggingState:o}=r.state,{originalIndex:s,draggedCellOrientation:c}=o;if(n===s||!a||c===`row`&&!e.Ht(a,s,n)||c===`col`&&!e.Vt(a,s,n))return d.DecorationSet.create(t.doc,i);let l=t.doc.resolve(r.tablePos+1);return r.state.draggingState.draggedCellOrientation===`row`?e.Gt(r.state.block,n).forEach(({row:e,col:r})=>{let a=t.doc.resolve(l.posAtIndex(e)+1),o=t.doc.resolve(a.posAtIndex(r)+1),c=o.node(),u=o.pos+(n>s?c.nodeSize-2:0);i.push(d.Decoration.widget(u,()=>{let e=document.createElement(`div`);return e.className=`bn-table-drop-cursor`,e.style.left=`0`,e.style.right=`0`,n>s?e.style.bottom=`-2px`:e.style.top=`-3px`,e.style.height=`4px`,e}))}):e.Wt(r.state.block,n).forEach(({row:e,col:r})=>{let a=t.doc.resolve(l.posAtIndex(e)+1),o=t.doc.resolve(a.posAtIndex(r)+1),c=o.node(),u=o.pos+(n>s?c.nodeSize-2:0);i.push(d.Decoration.widget(u,()=>{let e=document.createElement(`div`);return e.className=`bn-table-drop-cursor`,e.style.top=`0`,e.style.bottom=`0`,n>s?e.style.right=`-2px`:e.style.left=`-3px`,e.style.width=`4px`,e}))}),d.DecorationSet.create(t.doc,i)}}})],colDragStart(e){if(r===void 0||r.state===void 0||r.state.colIndex===void 0)throw Error(`Attempted to drag table column, but no table block was hovered prior.`);r.state.draggingState={draggedCellOrientation:`col`,originalIndex:r.state.colIndex,mousePos:e.clientX},r.emitUpdate(),n.transact(e=>e.setMeta(q,{draggedCellOrientation:r.state.draggingState.draggedCellOrientation,originalIndex:r.state.colIndex,newIndex:r.state.colIndex,tablePos:r.tablePos})),!n.headless&&(pt(n.prosemirrorView.root),e.dataTransfer.setDragImage(G,0,0),e.dataTransfer.effectAllowed=`move`)},rowDragStart(e){if(r.state===void 0||r.state.rowIndex===void 0)throw Error(`Attempted to drag table row, but no table block was hovered prior.`);r.state.draggingState={draggedCellOrientation:`row`,originalIndex:r.state.rowIndex,mousePos:e.clientY},r.emitUpdate(),n.transact(e=>e.setMeta(q,{draggedCellOrientation:r.state.draggingState.draggedCellOrientation,originalIndex:r.state.rowIndex,newIndex:r.state.rowIndex,tablePos:r.tablePos})),!n.headless&&(pt(n.prosemirrorView.root),e.dataTransfer.setDragImage(G,0,0),e.dataTransfer.effectAllowed=`copyMove`)},dragEnd(){if(r.state===void 0)throw Error(`Attempted to drag table row, but no table block was hovered prior.`);r.state.draggingState=void 0,r.emitUpdate(),n.transact(e=>e.setMeta(q,null)),!n.headless&&mt(n.prosemirrorView.root)},freezeHandles(){r.menuFrozen=!0},unfreezeHandles(){r.menuFrozen=!1},hideHandlesIfNotFrozen(){!r.menuFrozen&&r.state?.show&&(r.state.show=!1,r.state.showAddOrRemoveRowsButton=!1,r.state.showAddOrRemoveColumnsButton=!1,r.emitUpdate())},getCellsAtRowHandle(t,n){return e.Gt(t,n)},getCellsAtColumnHandle(t,n){return e.Wt(t,n)},setCellSelection(e,t,n=t){if(!r)throw Error(`Table handles view not initialized`);let i=e.doc.resolve(r.tablePos+1),a=e.doc.resolve(i.posAtIndex(t.row)+1),o=e.doc.resolve(a.posAtIndex(t.col)),s=e.doc.resolve(i.posAtIndex(n.row)+1),c=e.doc.resolve(s.posAtIndex(n.col)),u=e.tr;return u.setSelection(new l.CellSelection(o,c)),e.apply(u)},addRowOrColumn(e,t){n.exec((n,r)=>{let i=this.setCellSelection(n,t.orientation===`row`?{row:e,col:0}:{row:0,col:e});return t.orientation===`row`?t.side===`above`?(0,l.addRowBefore)(i,r):(0,l.addRowAfter)(i,r):t.side===`left`?(0,l.addColumnBefore)(i,r):(0,l.addColumnAfter)(i,r)})},removeRowOrColumn(e,t){return t===`row`?n.exec((t,n)=>{let r=this.setCellSelection(t,{row:e,col:0});return(0,l.deleteRow)(r,n)}):n.exec((t,n)=>{let r=this.setCellSelection(t,{row:0,col:e});return(0,l.deleteColumn)(r,n)})},mergeCells(e){return n.exec((t,n)=>{let r=e?this.setCellSelection(t,e.relativeStartCell,e.relativeEndCell):t;return(0,l.mergeCells)(r,n)})},splitCell(e){return n.exec((t,n)=>{let r=e?this.setCellSelection(t,e):t;return(0,l.splitCell)(r,n)})},getCellSelection(){return n.transact(t=>{let n=t.selection,r=n.$from,i=n.$to;if(e.v(n)){let{ranges:e}=n;e.forEach(e=>{r=e.$from.min(r??e.$from),i=e.$to.max(i??e.$to)})}else{let a=n.$from.pos-n.$from.parentOffset-1,o=n.$to.pos-n.$to.parentOffset-1;if(a<0||o<0||(r=t.doc.resolve(a),i=t.doc.resolve(o),!e._(r.parent)||!e._(i.parent)))return}let a=t.doc.resolve(r.pos-r.parentOffset-1),o=t.doc.resolve(i.pos-i.parentOffset-1),s=t.doc.resolve(a.pos-a.parentOffset-1),c=r.index(a.depth),l=a.index(s.depth),u=i.index(o.depth),d=o.index(s.depth),f=[];for(let e=l;e<=d;e++)for(let t=c;t<=u;t++)f.push({row:e,col:t});return{from:{row:l,col:c},to:{row:d,col:u},cells:f}})},getMergeDirection(t){return n.transact(n=>{let r=e.v(n.selection)?n.selection:void 0;if(!r||!t||r.ranges.length<=1)return;let i=this.getCellSelection();if(i)return e.Bt(i.from,i.to,t)?`vertical`:`horizontal`})},cropEmptyRowsOrColumns(t,n){return e.Ut(t,n)},addRowsOrColumns(t,n,r){return e.zt(t,n,r)}}}),J=new s.PluginKey(`trailingNode`);function Y(e){let t=e.lastChild,n=t?.firstChild;return t?.type.name!==`blockContainer`||n?.type.name!==`paragraph`||n.content.size!==0}function yt(e){if(!e.type.schema.nodes.column){let t=e.lastChild;return t&&Y(t)?[e.content.size-1]:[]}let t=[];return e.descendants((e,n,r)=>!e.isTextblock&&((e.type.name===`column`||e.type.name===`blockGroup`&&r?.type.name===`doc`)&&Y(e)&&t.push(n+e.nodeSize-1),!0)),t}var bt=t.t(({editor:e})=>{function t(t){return d.Decoration.widget(t,()=>{let t=document.createElement(`div`);return t.className=`bn-trailing-block`,t.contentEditable=`false`,t.addEventListener(`mousedown`,n=>{n.preventDefault();let r=e.prosemirrorView;if(!r)return;let i=r.state.doc.resolve(r.posAtDOM(t,0)).parent.lastChild?.attrs.id;i&&(e.transact(t=>{let[n]=e.insertBlocks([{type:`paragraph`}],i,`after`);e.setTextCursorPosition(n,`start`),t.scrollIntoView()}),r.focus())}),t},{side:1})}function n(e,n,r){let i=n.map(e.mapping,e.doc),a=new Set(r?yt(e.doc):[]),o=new Set,s=[];for(let e of i.find())a.has(e.from)&&!o.has(e.from)?o.add(e.from):s.push(e);let c=[...a].filter(e=>!o.has(e)),l=i;return s.length>0&&(l=l.remove(s)),c.length>0&&(l=l.add(e.doc,c.map(t))),l}return{key:`trailingNode`,prosemirrorPlugins:[new s.Plugin({key:J,state:{init:(t,r)=>n(r.tr,d.DecorationSet.empty,e.isEditable),apply:(t,r)=>!t.docChanged&&!t.getMeta(J)?r:n(t,r,e.isEditable)},view(e){let t=e.editable;return{update(e){e.editable!==t&&(t=e.editable,e.dispatch(e.state.tr.setMeta(J,!0)))}}},props:{decorations:e=>J.getState(e),handleKeyDown:(t,n)=>{if(n.key!==`ArrowRight`&&n.key!==`ArrowDown`)return!1;let{selection:r}=t.state;if(!r.empty)return!1;let i=s.Selection.atEnd(t.state.doc);if(r.$head.pos!==i.$head.pos)return!1;let a=t.state.doc.lastChild;return!e.isEditable||!a||!Y(a)?!1:(n.preventDefault(),!0)}}})]}}),X=Symbol(`bn-current-version`);function Z(e){return[...e].sort((e,t)=>t.createdAt-e.createdAt)}function Q(e){let t=typeof e==`object`?e.id:e;throw Error(`Snapshot not found: ${String(t)}`)}var xt=t.t(({options:e,editor:r})=>{let{endpoints:i,preview:a,getCurrentDocument:o,serializeCurrentContent:s,resolveUsers:c}=typeof e==`function`?e(r):e,l=typeof i==`function`?i(r):i,u=n.n(c),d=t.n({snapshots:[],previewedSnapshotId:void 0,compareToSnapshotId:void 0}),f=e=>{let t=typeof e==`object`?e.id:e;return d.state.snapshots.find(e=>e.id===t)},p=async()=>{let e=Z(await l.list());return d.setState(t=>({...t,snapshots:e})),e},m=async(e,t)=>{let n=f(e);n||Q(e);let r=t?.compareTo?f(t.compareTo):void 0;d.setState(e=>({...e,previewedSnapshotId:n.id,compareToSnapshotId:r?.id}));let i,o;r&&(i=await l.getContent(r),l.getAttributions&&(o=await l.getAttributions(n,r)));let s=await l.getContent(n);a.enterPreview(s,i,o,{snapshot:n,compareTo:r})},h=async e=>{if(!s)throw Error("previewCurrentVersion requires `serializeCurrentContent` to be provided to the VersioningExtension options.");let t=e?.compareTo?f(e.compareTo):void 0;d.setState(e=>({...e,previewedSnapshotId:X,compareToSnapshotId:t?.id}));let n={id:X,createdAt:Date.now(),updatedAt:Date.now()},r,i;t&&(r=await l.getContent(t),l.getAttributions&&(i=await l.getAttributions(n,t)));let o=await s();a.enterPreview(o,r,i,{snapshot:n,compareTo:t})},g=()=>{d.setState(e=>({...e,previewedSnapshotId:void 0,compareToSnapshotId:void 0})),a.exitPreview()};return{key:`versioning`,store:d,userStore:u,list:async()=>await p(),get canCompare(){return a.supportsComparison!==!1},canCreate:l.create!==void 0,create:l.create?async e=>{let t=await l.create(o(),{name:e?.name,restoredFromSnapshot:f(e?.restoredFromSnapshot)});d.setState(e=>({...e,snapshots:Z([...e.snapshots,t])}));let n=await l.list();return d.setState(e=>({...e,snapshots:Z(n.some(e=>e.id===t.id)?n:[...n,t])})),t}:void 0,canRestore:l.restore!==void 0,restore:l.restore?async e=>{g();let t=f(e);t||Q(e);let n=await l.restore(o(),t);return a.applyRestore(n),await p(),n}:void 0,canRename:l.rename!==void 0,rename:l.rename?async(e,t)=>{let n=f(e);n||Q(e),await l.rename(n,t),d.setState(n=>({...n,snapshots:n.snapshots.map(n=>n.id===e?{...n,name:t,updatedAt:Date.now()}:n)}))}:void 0,canRemove:l.remove!==void 0,remove:l.remove?async e=>{let t=f(e);t||Q(e),(d.state.previewedSnapshotId===t.id||d.state.compareToSnapshotId===t.id)&&g(),await l.remove(t),d.setState(e=>({...e,snapshots:e.snapshots.filter(e=>e.id!==t.id)})),await p()}:void 0,previewSnapshot:m,canPreviewCurrent:s!==void 0,previewCurrentVersion:s?h:void 0,exitPreview:g}});function St(e){return e.id===X?`Current version`:e.name??`Unnamed version`}function Ct(e){let t,n=!1,r=t=>{e.replaceBlocks(e.document,t)},i=()=>e.getExtension(`diffVersioning`);return{get supportsComparison(){return i()!==void 0},enterPreview(a,o,s,c){t===void 0&&(t=e.document);let l=i();if(o&&l){l.renderDiff(a,o,c&&St(c.snapshot)),n=!0;return}n=!1,r(a)},exitPreview(){if(t!==void 0){let e=i();n&&e?e.clearDiff(t):r(t),t=void 0,n=!1}},applyRestore(e){let a=i();n&&a?a.clearDiff(e):r(e),t=void 0,n=!1}}}function $(){let e=[],t=new Map,n=1,r=0;function i(){return r=Math.max(Date.now(),r+1),r}return{async list(){return Z([...e])},async create(r,a){let o=i(),s=String(n++),c={id:s,name:a?.name,createdAt:o,updatedAt:o};return e.push(c),t.set(s,structuredClone(r)),c},async restore(r,a){let o=String(a.id),s=t.get(o);if(!s)throw Error(`Snapshot ${o} not found`);let c=i(),l=String(n++),u={id:l,name:`Before restore`,createdAt:c,updatedAt:c,restoredFromSnapshotId:o};return e.push(u),t.set(l,structuredClone(r)),structuredClone(s)},async getContent(e){let n=String(e.id),r=t.get(n);if(!r)throw Error(`Snapshot ${n} not found`);return structuredClone(r)},async rename(t,n){let r=e.find(e=>e.id===t.id);if(!r)throw Error(`Snapshot ${String(t.id)} not found`);r.name=n,r.updatedAt=i()},async remove(n){let r=e.findIndex(e=>e.id===n.id);if(r===-1)throw Error(`Snapshot ${String(n.id)} not found`);e.splice(r,1),t.delete(String(n.id))}}}function wt(e){let t=$();return{endpoints:{...t,list:async()=>[{id:X,createdAt:Date.now(),updatedAt:Date.now()},...await t.list()]},preview:Ct(e),getCurrentDocument:()=>e.document,serializeCurrentContent:()=>e.document}}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return xt}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return vt}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return ft}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return ut}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return _t}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return wt}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return lt}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return bt}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Ct}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return qe}});
//# sourceMappingURL=extensions-CSB9ZvuL.cjs.map