@blocknote/core 0.14.3 → 0.14.4
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/blocknote.js +1 -1
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +1 -1
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -2
- package/src/editor/editor.css +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +1 -1
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
`;else throw new Error("unexpected");else n={type:"text",text:`
|
|
5
5
|
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&t[r.type.name]){n&&(o.push(n),n=void 0),o.push(ke(r,t,i));return}const a={};let s;for(const l of r.marks)if(l.type.name==="link")s=l;else{const c=i[l.type.name];if(!c)throw new Error(`style ${l.type.name} not found in styleSchema`);if(c.propSchema==="boolean")a[c.type]=!0;else if(c.propSchema==="string")a[c.type]=l.attrs.stringValue;else throw new I(c.propSchema)}n?$(n)?s?(o.push(n),n={type:"link",href:s.attrs.href,content:[{type:"text",text:r.textContent,styles:a}]}):JSON.stringify(n.styles)===JSON.stringify(a)?n.text+=r.textContent:(o.push(n),n={type:"text",text:r.textContent,styles:a}):me(n)&&(s?n.href===s.attrs.href?JSON.stringify(n.content[n.content.length-1].styles)===JSON.stringify(a)?n.content[n.content.length-1].text+=r.textContent:n.content.push({type:"text",text:r.textContent,styles:a}):(o.push(n),n={type:"link",href:s.attrs.href,content:[{type:"text",text:r.textContent,styles:a}]}):(o.push(n),n={type:"text",text:r.textContent,styles:a})):s?n={type:"link",href:s.attrs.href,content:[{type:"text",text:r.textContent,styles:a}]}:n={type:"text",text:r.textContent,styles:a}}),n&&o.push(n),o}function ke(e,t,i){if(e.type.name==="text"||e.type.name==="link")throw new Error("unexpected");const o={},n=t[e.type.name];for(const[s,l]of Object.entries(e.attrs)){if(!n)throw Error("ic node is of an unrecognized type: "+e.type.name);const c=n.propSchema;s in c&&(o[s]=l)}let r;return n.content==="styled"?r=se(e,t,i):r=void 0,{type:e.type.name,props:o,content:r}}function x(e,t,i,o,n){if(e.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+e.type.name+".");const r=n==null?void 0:n.get(e);if(r)return r;const a=$e(e);let s=a.id;s===null&&(s=W.options.generateID());const l={};for(const[g,f]of Object.entries({...e.attrs,...a.contentNode.attrs})){const k=t[a.contentType.name];if(!k)throw Error("Block is of an unrecognized type: "+a.contentType.name);const w=k.propSchema;g in w&&(l[g]=f)}const c=t[a.contentType.name],p=[];for(let g=0;g<a.numChildBlocks;g++)p.push(x(e.lastChild.child(g),t,i,o,n));let h;if(c.content==="inline")h=se(a.contentNode,i,o);else if(c.content==="table")h=to(a.contentNode,i,o);else if(c.content==="none")h=void 0;else throw new I(c.content);const m={id:s,type:c.type,props:l,content:h,children:p};return n==null||n.set(e,m),m}function io(e){return e.document||window.document}const Je=(e,t,i,o,n)=>{if(!i.nodes[e.type.name])throw new Error("Serializer is missing a node type: "+e.type.name);const{dom:r,contentDOM:a}=y.DOMSerializer.renderSpec(io(t),i.nodes[e.type.name](e));if(a){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(e.type.name==="blockContainer"){const s=e.childCount>0&&e.firstChild.type.spec.group==="blockContent"?e.firstChild:void 0,l=e.childCount>0&&e.lastChild.type.spec.group==="blockGroup"?e.lastChild:void 0;if(s!==void 0){const c=o.blockImplementations[s.type.name].implementation,h=(n?c.toExternalHTML:c.toInternalHTML)(x(e,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache),o);if(h.contentDOM!==void 0){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");h.contentDOM.appendChild(i.serializeFragment(s.content,t))}a.appendChild(h.dom)}l!==void 0&&i.serializeFragment(y.Fragment.from(l),t,a)}else i.serializeFragment(e.content,t,a)}return r},Ye=(e,t)=>{const i=t.serializeFragment(e),o=document.createElement("div");return o.appendChild(i),o.innerHTML};function oo(e){const t=new Set([...e.orderedListItemBlockTypes,...e.unorderedListItemBlockTypes]),i=o=>{var a;if(o.children.length===1&&((a=o.children[0].properties)==null?void 0:a.dataNodeType)==="blockGroup"){const s=o.children[0];o.children.pop(),o.children.push(...s.children)}let n=o.children.length,r;for(let s=0;s<n;s++){const c=o.children[s].children[0],p=c.children.find(f=>{const k=f.properties,w=k==null?void 0:k.className;return w==null?void 0:w.includes("bn-block-content")}),h=c.children.find(f=>{const k=f.properties,w=k==null?void 0:k.className;return w==null?void 0:w.includes("bn-block-group")});if(!p){o.children.splice(s,1,...h.children),i(o);return}const m=t.has(p.properties.dataContentType),g=m?e.orderedListItemBlockTypes.has(p.properties.dataContentType)?"ol":"ul":null;if(h&&i(h),r&&r.tagName!==g){o.children.splice(s-r.children.length,r.children.length,r);const f=r.children.length-1;s-=f,n-=f,r=void 0}if(m){r||(r=he.fromDom(document.createElement(g)));const f=he.fromDom(document.createElement("li"));f.children.push(...p.children),h&&f.children.push(...h.children),r.children.push(f)}else if(h){o.children.splice(s+1,0,...h.children),o.children[s]=p.children[0];const f=h.children.length;s+=f,n+=f}else o.children[s]=p.children[0]}r&&o.children.splice(n-r.children.length,r.children.length,r)};return i}const Y=(e,t)=>{const i=y.DOMSerializer.fromSchema(e);return i.serializeNodeInner=(o,n)=>Je(o,n,i,t,!0),i.exportProseMirrorFragment=o=>pe.unified().use(Ke.default,{fragment:!0}).use(oo,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem","checkListItem"])}).use(qe.default).processSync(Ye(o,i)).value,i.exportBlocks=o=>{const n=o.map(a=>N(a,e,t.schema.styleSchema)),r=e.nodes.blockGroup.create(null,n);return i.exportProseMirrorFragment(y.Fragment.from(r))},i},_e=(e,t)=>{const i=y.DOMSerializer.fromSchema(e);return i.serializeNodeInner=(o,n)=>Je(o,n,i,t,!1),i.serializeProseMirrorFragment=o=>Ye(o,i),i.serializeBlocks=o=>{const n=o.map(a=>N(a,e,t.schema.styleSchema)),r=e.nodes.blockGroup.create(null,n);return i.serializeProseMirrorFragment(y.Fragment.from(r))},i},Qe=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function H(e,t="Ctrl"){return Qe()?e.replace("Mod","⌘"):e.replace("Mod",t)}function U(...e){return e.filter(t=>t).join(" ")}const no=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function q(e,t,i,o){const n=document.createElement("div");n.className=U("bn-block-content",i.class),n.setAttribute("data-content-type",e);for(const[a,s]of Object.entries(i))a!=="class"&&n.setAttribute(a,s);const r=document.createElement(t);r.className=U("bn-inline-content",o.class);for(const[a,s]of Object.entries(o))a!=="class"&&r.setAttribute(a,s);return n.appendChild(r),{dom:n,contentDOM:r}}const et=(e,t)=>{const i=N(e,t._tiptapEditor.schema,t.schema.styleSchema).firstChild,o=t._tiptapEditor.schema.nodes[i.type.name].spec.toDOM;if(o===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const n=o(i);if(typeof n!="object"||!("dom"in n))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return n},E={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},ye=["backgroundColor","textColor"];function Q(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ro(e){const t=e.split("/");return!t.length||t[t.length-1]===""?e:t[t.length-1]}function we(e){const t={};return Object.entries(e).filter(([i,o])=>!ye.includes(i)).forEach(([i,o])=>{t[i]={default:o.default,keepOnSplit:!0,parseHTML:n=>{const r=n.getAttribute(Q(i));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const a=parseFloat(r);return!Number.isNaN(a)&&Number.isFinite(a)?a:null}return r},renderHTML:n=>n[i]!==o.default?{[Q(i)]:n[i]}:{}}}),t}function tt(e,t,i,o){if(typeof e=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const n=e(),a=i.state.doc.resolve(n).node().attrs.id;if(!a)throw new Error("Block doesn't have id");const s=t.getBlock(a);if(s.type!==o)throw new Error("Block type does not match");return s}function le(e,t,i,o,n=!1,r){const a=document.createElement("div");if(r!==void 0)for(const[s,l]of Object.entries(r))s!=="class"&&a.setAttribute(s,l);a.className=U("bn-block-content",(r==null?void 0:r.class)||""),a.setAttribute("data-content-type",t);for(const[s,l]of Object.entries(i))!ye.includes(s)&&l!==o[s].default&&a.setAttribute(Q(s),l);return n&&a.setAttribute("data-file-block",""),a.appendChild(e.dom),e.contentDOM!==void 0&&(e.contentDOM.className=U("bn-inline-content",e.contentDOM.className),e.contentDOM.setAttribute("data-editable","")),{...e,dom:a}}function D(e){return b.Node.create(e)}function ve(e,t){return{config:e,implementation:t}}function G(e,t,i){return ve({type:e.name,content:e.config.content==="inline*"?"inline":e.config.content==="tableRow+"?"table":"none",propSchema:t},{node:e,requiredExtensions:i,toInternalHTML:et,toExternalHTML:et})}function Ee(e){return Object.fromEntries(Object.entries(e).map(([t,i])=>[t,i.config]))}function it(e,t){const i=[{tag:"[data-content-type="+e.type+"]",contentElement:"[data-editable]"}];return t&&i.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const n=t==null?void 0:t(o);return n===void 0?!1:n}}),i}function ee(e,t){const i=D({name:e.type,content:e.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return we(e.propSchema)},parseHTML(){return it(e,t.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const n=this.options.editor,r=tt(o,n,this.editor,e.type),a=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},s=t.render(r,n);return le(s,r.type,r.props,e.propSchema,a)}}});if(i.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return ve(e,{node:i,toInternalHTML:(o,n)=>{var s;const r=((s=i.options.domAttributes)==null?void 0:s.blockContent)||{},a=t.render(o,n);return le(a,o.type,o.props,e.propSchema,e.isFileBlock,r)},toExternalHTML:(o,n)=>{var s,l;const r=((s=i.options.domAttributes)==null?void 0:s.blockContent)||{};let a=(l=t.toExternalHTML)==null?void 0:l.call(t,o,n);return a===void 0&&(a=t.render(o,n)),le(a,o.type,o.props,e.propSchema,r)}})}function ot(e,t,i,o){return e.dom.setAttribute("data-inline-content-type",t),Object.entries(i).filter(([n,r])=>r!==o[n].default).map(([n,r])=>[Q(n),r]).forEach(([n,r])=>e.dom.setAttribute(n,r)),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function nt(e){return{Backspace:({editor:t})=>{const i=t.state.selection.$from;return t.state.selection.empty&&i.node().type.name===e.type&&i.parentOffset===0}}}function rt(e,t){return{config:e,implementation:t}}function at(e,t){return rt({type:e.name,propSchema:t,content:e.config.content==="inline*"?"styled":"none"},{node:e})}function xe(e){return Object.fromEntries(Object.entries(e).map(([t,i])=>[t,i.config]))}function st(e){return[{tag:`[data-inline-content-type="${e.type}"]`,contentElement:t=>{const i=t;return i.matches("[data-editable]")?i:i.querySelector("[data-editable]")||i}}]}function ao(e,t){const i=b.Node.create({name:e.type,inline:!0,group:"inline",selectable:e.content==="styled",atom:e.content==="none",content:e.content==="styled"?"inline*":"",addAttributes(){return we(e.propSchema)},addKeyboardShortcuts(){return nt(e)},parseHTML(){return st(e)},renderHTML({node:o}){const n=this.options.editor,r=t.render(ke(o,n.schema.inlineContentSchema,n.schema.styleSchema));return ot(r,e.type,o.attrs,e.propSchema)}});return at(i,e.propSchema)}function lt(e){return e==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:t=>t.getAttribute("data-value"),renderHTML:t=>t.stringValue!==void 0?{"data-value":t.stringValue}:{}}}}function dt(e,t,i,o){return e.dom.setAttribute("data-style-type",t),o==="string"&&e.dom.setAttribute("data-value",i),e.contentDOM!==void 0&&e.contentDOM.setAttribute("data-editable",""),e}function Ce(e,t){return{config:e,implementation:t}}function R(e,t){return Ce({type:e.name,propSchema:t},{mark:e})}function Se(e){return Object.fromEntries(Object.entries(e).map(([t,i])=>[t,i.config]))}function ct(e){return[{tag:`[data-style-type="${e.type}"]`,contentElement:t=>{const i=t;return i.matches("[data-editable]")?i:i.querySelector("[data-editable]")||i}}]}function so(e,t){const i=b.Mark.create({name:e.type,addAttributes(){return lt(e.propSchema)},parseHTML(){return ct(e)},renderHTML({mark:o}){let n;if(e.propSchema==="boolean")n=t.render();else if(e.propSchema==="string")n=t.render(o.attrs.stringValue);else throw new I(e.propSchema);return dt(n,e.type,o.attrs.stringValue,e.propSchema)}});return Ce(e,{mark:i})}const te=e=>{const t=document.createElement("div");t.className="bn-file-default-preview";const i=document.createElement("div");i.className="bn-file-default-preview-icon",i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>';const o=document.createElement("p");return o.className="bn-file-default-preview-name",o.textContent=e.props.name||"",t.appendChild(i),t.appendChild(o),{dom:t}},O=(e,t)=>{const i=document.createElement("div");i.className="bn-file-and-caption-wrapper";const o=document.createElement("p");return o.className="bn-file-caption",o.textContent=e.props.caption,i.appendChild(t),i.appendChild(o),{dom:i}},ie=(e,t,i,o)=>{const n=document.createElement("div");n.className="bn-add-file-button";const r=document.createElement("div");r.className="bn-add-file-button-icon",o?r.appendChild(o):r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>';const a=document.createElement("p");a.className="bn-add-file-button-text",a.innerHTML=i||t.dictionary.file_blocks.file.add_button_text;const s=c=>{c.preventDefault()},l=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(t.filePanel.plugin,{block:e}))};return n.appendChild(r),n.appendChild(a),n.addEventListener("mousedown",s,!0),n.addEventListener("click",l,!0),{dom:n,destroy:()=>{n.removeEventListener("mousedown",s,!0),n.removeEventListener("click",l,!0)}}},Te=e=>({url:e.src||void 0}),oe=(e,t)=>{const i=e.querySelector(t);if(!i)return;const o=e.querySelector("figcaption"),n=(o==null?void 0:o.textContent)??void 0;return{targetElement:i,caption:n}},ne=(e,t)=>{const i=document.createElement("div"),o=document.createElement("p");return o.textContent=t,i.appendChild(e),i.appendChild(o),{dom:i}},de=(e,t)=>{const i=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=t,i.appendChild(e),i.appendChild(o),{dom:i}},Me=(e,t,i,o,n)=>{if(!e.props.previewWidth)throw new Error("Block must have a `previewWidth` prop.");const r=document.createElement("div");r.className="bn-visual-media-wrapper";const a=document.createElement("div");a.className="bn-visual-media-resize-handle",a.style.left="4px";const s=document.createElement("div");s.className="bn-visual-media-resize-handle",s.style.right="4px";let l;const c=k=>{if(!l){!t.isEditable&&r.contains(a)&&r.contains(s)&&(r.removeChild(a),r.removeChild(s));return}let w;e.props.textAlignment==="center"?l.handleUsed==="left"?w=l.initialWidth+(l.initialClientX-k.clientX)*2:w=l.initialWidth+(k.clientX-l.initialClientX)*2:l.handleUsed==="left"?w=l.initialWidth+l.initialClientX-k.clientX:w=l.initialWidth+k.clientX-l.initialClientX;const j=64;w<j?n(j):w>t.domElement.firstElementChild.clientWidth?n(t.domElement.firstElementChild.clientWidth):n(w)},p=k=>{(!k.target||!r.contains(k.target)||!t.isEditable)&&r.contains(a)&&r.contains(s)&&(r.removeChild(a),r.removeChild(s)),l&&(l=void 0,t.updateBlock(e,{props:{previewWidth:o()}}))},h=()=>{t.isEditable&&(r.appendChild(a),r.appendChild(s))},m=k=>{k.relatedTarget===a||k.relatedTarget===s||l||t.isEditable&&r.contains(a)&&r.contains(s)&&(r.removeChild(a),r.removeChild(s))},g=k=>{k.preventDefault(),r.appendChild(a),r.appendChild(s),l={handleUsed:"left",initialWidth:e.props.previewWidth,initialClientX:k.clientX}},f=k=>{k.preventDefault(),r.appendChild(a),r.appendChild(s),l={handleUsed:"right",initialWidth:e.props.previewWidth,initialClientX:k.clientX}};return r.appendChild(i),window.addEventListener("mousemove",c),window.addEventListener("mouseup",p),i.addEventListener("mouseenter",h),i.addEventListener("mouseleave",m),a.addEventListener("mousedown",g),s.addEventListener("mousedown",f),{dom:r,destroy:()=>{window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",p),i.removeEventListener("mouseenter",h),i.removeEventListener("mouseleave",m),a.removeEventListener("mousedown",g),s.removeEventListener("mousedown",f)}}},ut={backgroundColor:E.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},pt={type:"file",propSchema:ut,content:"none",isFileBlock:!0},ht=(e,t)=>{const i=document.createElement("div");if(i.className="bn-file-block-content-wrapper",e.props.url===""){const o=ie(e,t);return i.appendChild(o.dom),{dom:i,destroy:o.destroy}}else{const o=te(e).dom,n=O(e,o);return i.appendChild(n.dom),{dom:i}}},mt=e=>{if(e.tagName==="EMBED")return Te(e);if(e.tagName==="FIGURE"){const t=oe(e,"embed");if(!t)return;const{targetElement:i,caption:o}=t;return{...Te(i),caption:o}}},ft=e=>{if(!e.props.url){const i=document.createElement("p");return i.textContent="Add file",{dom:i}}const t=document.createElement("a");return t.href=e.props.url,t.textContent=e.props.name||e.props.url,e.props.caption?ne(t,e.props.caption):{dom:t}},gt=ee(pt,{render:ht,parse:mt,toExternalHTML:ft}),Be=e=>{const t=e.src||void 0,i=e.width||void 0;return{url:t,previewWidth:i}},bt={textAlignment:E.textAlignment,backgroundColor:E.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},kt={type:"image",propSchema:bt,content:"none",isFileBlock:!0,fileBlockAcceptMimeTypes:["image/*"]},_t=(e,t)=>{const i=document.createElement("div");if(i.className="bn-file-block-content-wrapper",e.props.url===""){const o=document.createElement("div");o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>';const n=ie(e,t,t.dictionary.file_blocks.image.add_button_text,o.firstElementChild);return i.appendChild(n.dom),{dom:i,destroy:()=>{var r;(r=n==null?void 0:n.destroy)==null||r.call(n)}}}else if(e.props.showPreview){const o=document.createElement("img");o.className="bn-visual-media",t.resolveFileUrl(e.props.url).then(a=>{o.src=a}),o.alt=e.props.name||e.props.caption||"BlockNote image",o.contentEditable="false",o.draggable=!1,o.width=Math.min(e.props.previewWidth,t.domElement.firstElementChild.clientWidth);const n=Me(e,t,o,()=>o.width,a=>o.width=a),r=O(e,n.dom);return i.appendChild(r.dom),{dom:i,destroy:n.destroy}}else{const o=te(e).dom;return{dom:O(e,o).dom}}},yt=e=>{if(e.tagName==="IMG")return Be(e);if(e.tagName==="FIGURE"){const t=oe(e,"img");if(!t)return;const{targetElement:i,caption:o}=t;return{...Be(i),caption:o}}},wt=e=>{if(!e.props.url){const i=document.createElement("p");return i.textContent="Add image",{dom:i}}let t;return e.props.showPreview?(t=document.createElement("img"),t.src=e.props.url,t.alt=e.props.name||e.props.caption||"BlockNote image",t.width=e.props.previewWidth):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?de(t,e.props.caption):ne(t,e.props.caption):{dom:t}},vt=ee(kt,{render:_t,parse:yt,toExternalHTML:wt}),Et=e=>{const t=e.src||void 0,i=e.width||void 0;return{url:t,previewWidth:i}},xt={textAlignment:E.textAlignment,backgroundColor:E.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:512}},Ct={type:"video",propSchema:xt,content:"none",isFileBlock:!0,fileBlockAcceptMimeTypes:["video/*"]},St=(e,t)=>{const i=document.createElement("div");if(i.className="bn-file-block-content-wrapper",e.props.url===""){const o=document.createElement("div");o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>';const n=ie(e,t,t.dictionary.file_blocks.video.add_button_text,o.firstElementChild);return i.appendChild(n.dom),{dom:i,destroy:()=>{var r;(r=n==null?void 0:n.destroy)==null||r.call(n)}}}else if(e.props.showPreview){const o=document.createElement("video");o.className="bn-visual-media",o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,o.width=Math.min(e.props.previewWidth,t.domElement.firstElementChild.clientWidth);const n=Me(e,t,o,()=>o.width,a=>o.width=a),r=O(e,n.dom);return i.appendChild(r.dom),{dom:i,destroy:n.destroy}}else{const o=te(e).dom;return{dom:O(e,o).dom}}},Tt=e=>{if(e.tagName==="VIDEO")return Et(e);if(e.tagName==="FIGURE"){const t=oe(e,"video");if(!t)return;const{targetElement:i,caption:o}=t;return{...Et(i),caption:o}}},Mt=e=>{if(!e.props.url){const i=document.createElement("p");return i.textContent="Add video",{dom:i}}let t;return e.props.showPreview?(t=document.createElement("video"),t.src=e.props.url,t.width=e.props.previewWidth):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?de(t,e.props.caption):ne(t,e.props.caption):{dom:t}},Bt=ee(Ct,{render:St,parse:Tt,toExternalHTML:Mt}),Lt=e=>({url:e.src||void 0}),It={backgroundColor:E.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},Pt={type:"audio",propSchema:It,content:"none",isFileBlock:!0,fileBlockAcceptMimeTypes:["audio/*"]},At=(e,t)=>{const i=document.createElement("div");if(i.className="bn-file-block-content-wrapper",e.props.url===""){const o=document.createElement("div");o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>';const n=ie(e,t,t.dictionary.file_blocks.audio.add_button_text,o.firstElementChild);return i.appendChild(n.dom),{dom:i,destroy:()=>{var r;(r=n==null?void 0:n.destroy)==null||r.call(n)}}}else if(e.props.showPreview){const o=document.createElement("audio");o.className="bn-audio",t.resolveFileUrl(e.props.url).then(r=>{o.src=r}),o.controls=!0,o.contentEditable="false",o.draggable=!1;const n=O(e,o);return i.appendChild(n.dom),{dom:i}}else{const o=te(e).dom;return{dom:O(e,o).dom}}},Nt=e=>{if(e.tagName==="AUDIO")return Lt(e);if(e.tagName==="FIGURE"){const t=oe(e,"audio");if(!t)return;const{targetElement:i,caption:o}=t;return{...Lt(i),caption:o}}},Ht=e=>{if(!e.props.url){const i=document.createElement("p");return i.textContent="Add audio",{dom:i}}let t;return e.props.showPreview?(t=document.createElement("audio"),t.src=e.props.url):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?de(t,e.props.caption):ne(t,e.props.caption):{dom:t}},Ut=ee(Pt,{render:At,parse:Nt,toExternalHTML:Ht}),lo=async e=>{const t=new FormData;return t.append("file",e),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},co=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-background-color")?{stringValue:e.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),uo=R(co,"string"),po=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:e=>typeof e=="string"?!1:e.hasAttribute("data-text-color")?{stringValue:e.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:e}){return["span",e,0]}}),ho=R(po,"string"),L=e=>{const{contentType:t}=v(e.state.doc,e.state.selection.from);return t.spec.content},mo={...E,level:{default:1,values:[1,2,3]}},fo=D({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:e=>{const t=e.getAttribute("data-level"),i=parseInt(t);if(isFinite(i))return i},renderHTML:e=>({"data-level":e.level.toString()})}}},addInputRules(){return[...[1,2,3].map(e=>new b.InputRule({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:t,chain:i,range:o})=>{L(this.editor)==="inline*"&&i().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:e}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:e=>typeof e=="string"?!1:{level:e.getAttribute("data-level")}},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:e,HTMLAttributes:t}){var i,o;return q(this.name,`h${e.attrs.level}`,{...((i=this.options.domAttributes)==null?void 0:i.blockContent)||{},...t},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),go=G(fo,mo),Le=e=>{const{contentNode:t,contentType:i}=v(e.state.doc,e.state.selection.from),o=e.state.selection.anchor===e.state.selection.head;return!(i.name==="bulletListItem"||i.name==="numberedListItem"||i.name==="checkListItem")||!o?!1:e.commands.first(({state:n,chain:r,commands:a})=>[()=>a.command(()=>t.childCount===0?a.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1),()=>a.command(()=>t.childCount>0?(r().deleteSelection().BNSplitBlock(n.selection.from,!0).run(),!0):!1)])},bo={...E},ko=D({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:t,range:i})=>{L(this.editor)==="inline*"&&t().BNUpdateBlock(e.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:i.from,to:i.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Le(this.editor),"Mod-Shift-8":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const t=e.parentElement;return t===null?!1:t.tagName==="UL"||t.tagName==="DIV"&&t.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:e=>{if(typeof e=="string")return!1;const t=e.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var t,i;return q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...e},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{})}}),_o=G(ko,bo),yo=new _.PluginKey("numbered-list-indexing"),wo=()=>new _.Plugin({key:yo,appendTransaction:(e,t,i)=>{const o=i.tr;o.setMeta("numberedListIndexing",!0);let n=!1;return i.doc.descendants((r,a)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let s="1";const l=a===1,c=v(o.doc,a+1);if(c===void 0)return;if(!l){const m=v(o.doc,a-2);if(m===void 0)return;if(!(c.depth!==m.depth)){const f=m.contentNode;if(m.contentType.name==="numberedListItem"){const j=f.attrs.index;s=(parseInt(j)+1).toString()}}}c.contentNode.attrs.index!==s&&(n=!0,o.setNodeMarkup(a+1,void 0,{index:s}))}}),n?o:null}}),vo={...E},Eo=D({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes(){return{index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:e,chain:t,range:i})=>{L(this.editor)==="inline*"&&t().BNUpdateBlock(e.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:i.from,to:i.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Le(this.editor),"Mod-Shift-7":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[wo()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const t=e.parentElement;return t===null?!1:t.tagName==="OL"||t.tagName==="DIV"&&t.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:e=>{if(typeof e=="string")return!1;const t=e.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var t,i;return q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...e},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{})}}),xo=G(Eo,vo),Co={...E,checked:{default:!1}},So=D({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes(){return{checked:{default:!1,parseHTML:e=>e.getAttribute("data-checked")==="true"||void 0,renderHTML:e=>e.checked?{"data-checked":e.checked.toString()}:{}}}},addInputRules(){return[new b.InputRule({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:t,range:i})=>{L(this.editor)==="inline*"&&t().BNUpdateBlock(e.selection.from,{type:"checkListItem",props:{checked:!1}}).deleteRange({from:i.from,to:i.to})}}),new b.InputRule({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:t,range:i})=>{L(this.editor)==="inline*"&&t().BNUpdateBlock(e.selection.from,{type:"checkListItem",props:{checked:!0}}).deleteRange({from:i.from,to:i.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Le(this.editor),"Mod-Shift-9":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"checkListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"input",getAttrs:e=>typeof e=="string"?!1:e.type==="checkbox"?{checked:e.checked}:!1,node:"checkListItem"},{tag:"li",getAttrs:e=>{if(typeof e=="string")return!1;const t=e.parentElement;if(t===null)return!1;if(t.tagName==="UL"||t.tagName==="DIV"&&t.parentElement.tagName==="UL"){const i=e.querySelector("input[type=checkbox]")||null;return i===null?!1:{checked:i.checked}}return!1},node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:t}){var r,a;const i=document.createElement("input");i.type="checkbox",i.checked=e.attrs.checked,e.attrs.checked&&i.setAttribute("checked","");const{dom:o,contentDOM:n}=q(this.name,"p",{...((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},...t},((a=this.options.domAttributes)==null?void 0:a.inlineContent)||{});return o.insertBefore(i,n),{dom:o,contentDOM:n}},addNodeView(){return({node:e,getPos:t,editor:i,HTMLAttributes:o})=>{var p,h;const n=document.createElement("div"),r=document.createElement("div");r.contentEditable="false";const a=document.createElement("input");a.type="checkbox",a.checked=e.attrs.checked,e.attrs.checked&&a.setAttribute("checked","");const s=()=>{if(!i.isEditable){a.checked=!a.checked;return}typeof t!="boolean"&&this.editor.commands.BNUpdateBlock(t(),{type:"checkListItem",props:{checked:a.checked}})};a.addEventListener("change",s);const{dom:l,contentDOM:c}=q(this.name,"p",{...((p=this.options.domAttributes)==null?void 0:p.blockContent)||{},...o},((h=this.options.domAttributes)==null?void 0:h.inlineContent)||{});if(typeof t!="boolean"){const g="label-"+this.editor.state.doc.resolve(t()).node().attrs.id;a.setAttribute("aria-labelledby",g),c.id=g}return l.removeChild(c),l.appendChild(n),n.appendChild(r),n.appendChild(c),r.appendChild(a),{dom:l,contentDOM:c,destroy:()=>{a.removeEventListener("change",s)}}}}}),To=G(So,Co),Mo={...E},Bo=D({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>L(this.editor)!=="inline*"?!0:this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"paragraph",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,getAttrs:e=>{var t;return typeof e=="string"||!((t=e.textContent)!=null&&t.trim())?!1:{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var t,i;return q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...e},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{})}}),Lo=G(Bo,Mo),Io=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[ze.columnResizing({cellMinWidth:100}),ze.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.setHardBreak(),!0):!1,Backspace:()=>{const e=this.editor.state.selection,t=e.empty,i=e.$head.parentOffset===0,o=e.$head.node().type.name==="tableParagraph";return t&&i&&o}}},extendNodeSchema(e){const t={name:e.name,options:e.options,storage:e.storage};return{tableRole:b.callOrReturn(b.getExtensionField(e,"tableRole",t))}}}),Po={...E},Ao=D({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:e}){var t,i;return q(this.name,"table",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...e},((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{})}}),No=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"td"},{tag:"p",getAttrs:e=>{if(typeof e=="string"||!e.textContent)return!1;const t=e.parentElement;return t===null?!1:t.tagName==="TD"?{}:!1}}]},renderHTML({HTMLAttributes:e}){return["p",b.mergeAttributes(this.options.HTMLAttributes,e),0]}}),Ho=G(Ao,Po,[Io,No,xi.TableHeader.extend({content:"tableContent"}),Ei.TableCell.extend({content:"tableContent"}),Ci.TableRow]),Ie={paragraph:Lo,heading:go,bulletListItem:_o,numberedListItem:xo,checkListItem:To,table:Ho,file:gt,image:vt,video:Bt,audio:Ut},Dt=Ee(Ie),Pe={bold:R(Ri.default,"boolean"),italic:R(Vi.default,"boolean"),underline:R(zi.default,"boolean"),strike:R(ji.default,"boolean"),code:R(Oi.default,"boolean"),textColor:ho,backgroundColor:uo},Uo=Se(Pe),Ae={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Do=xe(Ae);function B(e,t){return e in t.schema.blockSchema&&t.schema.blockSchema[e]===Dt[e]}function Rt(e,t,i){return t.type===e&&t.type in i.schema.blockSchema&&B(t.type,i)}function Ro(e,t){return e.type in t.schema.blockSchema&&t.schema.blockSchema[e.type].isFileBlock||!1}function Oo(e,t){return e.type in t.schema.blockSchema&&t.schema.blockSchema[e.type].isFileBlock&&"showPreview"in t.schema.blockSchema[e.type].propSchema||!1}function Vo(e,t){return t.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function Ot(e,t,i){return t in i.schema.blockSchema&&e in i.schema.blockSchema[t].propSchema&&i.schema.blockSchema[t].propSchema[e]===E[e]}function jo(e,t,i){return Ot(e,t.type,i)}function Ne(e,t){let i,o;if(t.firstChild.descendants((n,r)=>i?!1:n.type.name!=="blockContainer"||n.attrs.id!==e?!0:(i=n,o=r+1,!1)),i===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:i,posBeforeNode:o}}function zo(e,t,i="before",o){const n=o._tiptapEditor,r=typeof t=="string"?t:t.id,a=[];for(const p of e)a.push(N(p,n.schema,o.schema.styleSchema));const{node:s,posBeforeNode:l}=Ne(r,n.state.doc);if(i==="before"&&n.view.dispatch(n.state.tr.insert(l,a)),i==="after"&&n.view.dispatch(n.state.tr.insert(l+s.nodeSize,a)),i==="nested"&&s.childCount<2){const p=n.state.schema.nodes.blockGroup.create({},a);n.view.dispatch(n.state.tr.insert(l+s.firstChild.nodeSize+1,p))}const c=[];for(const p of a)c.push(x(p,o.schema.blockSchema,o.schema.inlineContentSchema,o.schema.styleSchema,o.blockCache));return c}function Fo(e,t,i){const o=i._tiptapEditor,n=typeof e=="string"?e:e.id,{posBeforeNode:r}=Ne(n,o.state.doc);o.commands.BNUpdateBlock(r+1,t);const a=o.state.doc.resolve(r+1).node();return x(a,i.schema.blockSchema,i.schema.inlineContentSchema,i.schema.styleSchema,i.blockCache)}function Vt(e,t,i){const o=t._tiptapEditor,n=o.state.tr,r=new Set(e.map(l=>typeof l=="string"?l:l.id)),a=[];let s=0;if(o.state.doc.descendants((l,c)=>{if(r.size===0)return!1;if(l.type.name!=="blockContainer"||!r.has(l.attrs.id))return!0;a.push(x(l,t.schema.blockSchema,t.schema.inlineContentSchema,t.schema.styleSchema,t.blockCache)),r.delete(l.attrs.id),s=(i==null?void 0:i(l,c,n,s))||s;const p=n.doc.nodeSize;n.delete(c-s-1,c-s+l.nodeSize+1);const h=n.doc.nodeSize;return s+=p-h,!1}),r.size>0){const l=[...r].join(`
|
|
6
6
|
`);throw Error("Blocks with the following IDs could not be found in the editor: "+l)}return o.view.dispatch(n),a}function Ko(e,t){return Vt(e,t)}function qo(e,t,i){const o=i._tiptapEditor,n=[];for(const l of t)n.push(N(l,o.schema,i.schema.styleSchema));const r=typeof e[0]=="string"?e[0]:e[0].id,a=Vt(e,i,(l,c,p,h)=>{if(l.attrs.id===r){const m=p.doc.nodeSize;p.insert(c,n);const g=p.doc.nodeSize;return h+m-g}return h}),s=[];for(const l of n)s.push(x(l,i.schema.blockSchema,i.schema.inlineContentSchema,i.schema.styleSchema,i.blockCache));return{insertedBlocks:s,removedBlocks:a}}function Go(e,t,i,o={updateSelection:!0}){const n=i._tiptapEditor,r=n.state.tr;let{from:a,to:s}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},l=!0,c=!0,p="";if(t.forEach(h=>{h.check(),l&&h.isText&&h.marks.length===0?p+=h.text:l=!1,c=c?h.isBlock:!1}),a===s&&c){const{parent:h}=r.doc.resolve(a);h.isTextblock&&!h.type.spec.code&&!h.childCount&&(a-=1,s+=1)}return l?r.insertText(p,a,s):r.replaceWith(a,s,t),o.updateSelection&&b.selectionToInsertionEnd(r,r.steps.length-1,-1),n.view.dispatch(r),!0}function Wo(){const e=t=>{let i=t.children.length;for(let o=0;o<i;o++){const n=t.children[o];if(n.type==="element"&&(e(n),n.tagName==="u"))if(n.children.length>0){t.children.splice(o,1,...n.children);const r=n.children.length-1;i+=r,o+=r}else t.children.splice(o,1),i--,o--}};return e}function $o(){const e=t=>{var i;if(t.children&&"length"in t.children&&t.children.length)for(let o=t.children.length-1;o>=0;o--){const n=t.children[o],r=o+1<t.children.length?t.children[o+1]:void 0;n.type==="element"&&n.tagName==="input"&&((i=n.properties)==null?void 0:i.type)==="checkbox"&&(r==null?void 0:r.type)==="element"&&r.tagName==="p"?(r.tagName="span",r.children.splice(0,0,he.fromDom(document.createTextNode(" ")))):e(n)}};return e}function He(e){return pe.unified().use(Ke.default,{fragment:!0}).use(Wo).use($o).use(Fi.default).use(Ge.default).use(Ki.default,{handlers:{text:i=>i.value}}).processSync(e).value}function Xo(e,t,i){const n=Y(t,i).exportBlocks(e);return He(n)}function Zo(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function Jo(e){return e.nodeType===3&&!/\S/.test(e.nodeValue||"")}function Yo(e){e.querySelectorAll("li > ul, li > ol").forEach(t=>{const i=Zo(t),o=t.parentElement,n=Array.from(o.childNodes).slice(i+1);t.remove(),n.forEach(r=>{r.remove()}),o.insertAdjacentElement("afterend",t),n.reverse().forEach(r=>{if(Jo(r))return;const a=document.createElement("li");a.append(r),t.insertAdjacentElement("afterend",a)}),o.childNodes.length===0&&o.remove()})}function Qo(e){e.querySelectorAll("li + ul, li + ol").forEach(t=>{var r,a;const i=t.previousElementSibling,o=document.createElement("div");i.insertAdjacentElement("afterend",o),o.append(i);const n=document.createElement("div");for(n.setAttribute("data-node-type","blockGroup"),o.append(n);((r=o.nextElementSibling)==null?void 0:r.nodeName)==="UL"||((a=o.nextElementSibling)==null?void 0:a.nodeName)==="OL";)n.append(o.nextElementSibling)})}let jt=null;function en(){return jt||(jt=document.implementation.createHTMLDocument("title"))}function zt(e){if(typeof e=="string"){const t=en().createElement("div");t.innerHTML=e,e=t}return Yo(e),Qo(e),e}async function Ft(e,t,i,o,n){const r=zt(e),s=y.DOMParser.fromSchema(n).parse(r,{topNode:n.nodes.blockGroup.create()}),l=[];for(let c=0;c<s.childCount;c++)l.push(x(s.child(c),t,i,o));return l}function tn(e,t){const i=t.value?t.value+`
|
|
7
|
-
`:"",o={};t.lang&&(o["data-language"]=t.lang);let n={type:"element",tagName:"code",properties:o,children:[{type:"text",value:i}]};return t.meta&&(n.data={meta:t.meta}),e.patch(t,n),n=e.applyData(t,n),n={type:"element",tagName:"pre",properties:{},children:[n]},e.patch(t,n),n}function on(e,t,i,o,n){const r=pe.unified().use(qi.default).use(Ge.default).use(Gi.default,{handlers:{...Fe.defaultHandlers,code:tn}}).use(qe.default).processSync(e);return Ft(r.value,t,i,o,n)}class X{constructor(){u(this,"callbacks",{})}on(t,i){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(i),()=>this.off(t,i)}emit(t,...i){const o=this.callbacks[t];o&&o.forEach(n=>n.apply(this,i))}off(t,i){const o=this.callbacks[t];o&&(i?this.callbacks[t]=o.filter(n=>n!==i):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class Kt{constructor(t,i,o,n){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 i=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);this.state.referencePos=i.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=i,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");n(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(t,i){var n,r;const o=this.pluginKey.getState(t.state);if(!((n=this.state)!=null&&n.show)&&o.block&&this.editor.isEditable){const a=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.state={show:!0,referencePos:a.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!t.state.selection.eq(i.selection)||!t.state.doc.eq(i.doc)||!this.editor.isEditable)&&(r=this.state)!=null&&r.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 Ue=new _.PluginKey("FilePanelPlugin");class qt extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new _.Plugin({key:Ue,view:o=>(this.view=new Kt(i,Ue,o,n=>{this.emit("update",n)}),this.view),props:{handleKeyDown:(o,n)=>n.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1},state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(Ue))==null?void 0:r.block}}}})}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}onUpdate(i){return this.on("update",i)}}class Gt{constructor(t,i,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"shouldShow",({state:t,from:i,to:o,view:n})=>{const{doc:r,selection:a}=t,{empty:s}=a,l=!r.textBetween(i,o).length&&b.isTextSelection(t.selection);return!(!n.hasFocus()||s||l)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{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=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},i.dom.addEventListener("mousedown",this.viewMousedownHandler),i.dom.addEventListener("mouseup",this.viewMouseupHandler),i.dom.addEventListener("dragstart",this.dragHandler),i.dom.addEventListener("dragover",this.dragHandler),i.root.addEventListener("scroll",this.scrollHandler,!0)}update(t,i){var m,g;const{state:o,composing:n}=t,{doc:r,selection:a}=o,s=i&&i.doc.eq(r)&&i.selection.eq(a);if(n||s)return;const{ranges:l}=a,c=Math.min(...l.map(f=>f.$from.pos)),p=Math.max(...l.map(f=>f.$to.pos)),h=(m=this.shouldShow)==null?void 0:m.call(this,{view:t,state:o,from:c,to:p});if(!this.preventShow&&(h||this.preventHide)){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((g=this.state)!=null&&g.show&&!this.preventHide&&(!h||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:i}=t,{ranges:o}=i,n=Math.min(...o.map(a=>a.$from.pos)),r=Math.max(...o.map(a=>a.$to.pos));if(b.isNodeSelection(i)){const a=this.pmView.nodeDOM(n);if(a)return a.getBoundingClientRect()}return b.posToDOMRect(this.pmView,n,r)}}const Wt=new _.PluginKey("FormattingToolbarPlugin");class $t extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new _.Plugin({key:Wt,view:o=>(this.view=new Gt(i,o,n=>{this.emit("update",n)}),this.view),props:{handleKeyDown:(o,n)=>n.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}onUpdate(i){return this.on("update",i)}}class nn{constructor(t,i,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 i=t.target,o=this.pmView.posAtDOM(i,0)+1,n=this.pmView.state.doc.resolve(o),r=n.marks();for(const a of r)if(a.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=a,this.mouseHoveredLinkMarkRange=b.getMarkRange(n,a.type,a.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var o;const i=this.pmView.dom.parentElement;this.linkMark&&t&&t.target&&!(i===t.target||i.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=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},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,i){var n;const o=this.pmView.state.tr.insertText(i,this.linkMarkRange.from,this.linkMarkRange.to);o.addMark(this.linkMarkRange.from,this.linkMarkRange.from+i.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var t;this.pmView.dispatch(this.pmView.state.tr.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(){var i;if(!this.pmView.hasFocus())return;const t=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 o=this.pmView.state.selection.$from.marks();for(const n of o)if(n.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=n,this.keyboardHoveredLinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,n.type,n.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&(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((i=this.state)!=null&&i.show&&t&&(!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 Xt=new _.PluginKey("LinkToolbarPlugin");class Zt extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"editLink",(i,o)=>{this.view.editLink(i,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.plugin=new _.Plugin({key:Xt,view:o=>(this.view=new nn(i,o,n=>{this.emit("update",n)}),this.view),props:{handleKeyDown:(o,n)=>n.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}onUpdate(i){return this.on("update",i)}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}}const rn=b.findParentNode(e=>e.type.name==="blockContainer");class an{constructor(t,i){u(this,"state");u(this,"emitUpdate");u(this,"rootEl");u(this,"pluginState");u(this,"handleScroll",()=>{var t,i;if((t=this.state)!=null&&t.show){const o=(i=this.rootEl)==null?void 0:i.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.view.state.tr.setMeta(V,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-(this.pluginState.fromUserInput?this.pluginState.triggerCharacter.length:0),to:this.editor._tiptapEditor.state.selection.from}).run()});this.editor=t,this.pluginState=void 0,this.emitUpdate=o=>{if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");i(o,this.state)},this.rootEl=this.editor._tiptapEditor.view.root,this.rootEl.addEventListener("scroll",this.handleScroll,!0)}update(t,i){var c;const o=V.getState(i),n=V.getState(t.state),r=o===void 0&&n!==void 0,a=o!==void 0&&n===void 0;if(!r&&!(o!==void 0&&n!==void 0)&&!a)return;if(this.pluginState=a?o:n,a||!this.editor.isEditable){this.state.show=!1,this.emitUpdate(this.pluginState.triggerCharacter);return}const l=(c=this.rootEl)==null?void 0:c.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(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 V=new _.PluginKey("SuggestionMenuPlugin");class Jt extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",i=>{this.triggerCharacters.push(i)});u(this,"removeTriggerCharacter",i=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==i)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new _.Plugin({key:V,view:()=>(this.view=new an(i,(n,r)=>{this.emit(`update ${n}`,r)}),this.view),state:{init(){},apply(n,r,a,s){if(n.getMeta("orderedListIndexing")!==void 0)return r;const l=n.getMeta(V);if(typeof l=="object"&&l!==null&&r===void 0)return{triggerCharacter:l.triggerCharacter,fromUserInput:l.fromUserInput!==!1,queryStartPos:s.selection.from,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(r===void 0)return r;if(s.selection.from!==s.selection.to||l===null||n.getMeta("focus")||n.getMeta("blur")||n.getMeta("pointer")||r.triggerCharacter!==void 0&&s.selection.from<r.queryStartPos)return;const c={...r};return c.query=s.doc.textBetween(r.queryStartPos,s.selection.from),c}},props:{handleTextInput(n,r,a,s){const l=this.getState(n.state);return o.includes(s)&&l===void 0?(n.dispatch(n.state.tr.insertText(s).scrollIntoView().setMeta(V,{triggerCharacter:s})),!0):!1},decorations(n){const r=this.getState(n);if(r===void 0)return null;if(!r.fromUserInput){const a=rn(n.selection);if(a)return M.DecorationSet.create(n.doc,[M.Decoration.node(a.pos,a.pos+a.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}return M.DecorationSet.create(n.doc,[M.Decoration.inline(r.queryStartPos-r.triggerCharacter.length,r.queryStartPos,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}}})}onUpdate(i,o){return this.triggerCharacters.includes(i)||this.addTriggerCharacter(i),this.on(`update ${i}`,o)}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}}function sn(e,t){e.suggestionMenus.addTriggerCharacter(t)}class Z extends _.Selection{constructor(i,o){super(i,o);u(this,"nodes");const n=i.node();this.nodes=[],i.doc.nodesBetween(i.pos,o.pos,(r,a,s)=>{if(s!==null&&s.eq(n))return this.nodes.push(r),!1})}static create(i,o,n=o){return new Z(i.resolve(o),i.resolve(n))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(i){if(!(i instanceof Z)||this.nodes.length!==i.nodes.length||this.from!==i.from||this.to!==i.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(i.nodes[o]))return!1;return!0}map(i,o){const n=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?_.Selection.near(i.resolve(n.pos)):n.deleted?_.Selection.near(i.resolve(r.pos)):new Z(i.resolve(n.pos),i.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let P;function re(e,t){var i;for(;e&&e.parentElement&&e.parentElement!==t.dom&&!((i=e.hasAttribute)!=null&&i.call(e,"data-id"));)e=e.parentElement;if(e.hasAttribute("data-id"))return{node:e,id:e.getAttribute("data-id")}}function ln(e,t){const i=re(e,t);if(i&&i.node.nodeType===1){const o=t.docView,n=o.nearestDesc(i.node,!0);return!n||n===o?null:n.posBefore}return null}function dn(e,t){let i,o;const n=t.resolve(e.from).node().type.spec.group==="blockContent",r=t.resolve(e.to).node().type.spec.group==="blockContent",a=Math.min(e.$anchor.depth,e.$head.depth);if(n&&r){const s=e.$from.start(a-1),l=e.$to.end(a-1);i=t.resolve(s-1).pos,o=t.resolve(l+1).pos}else i=e.from,o=e.to;return{from:i,to:o}}function Yt(e,t,i=t){t===i&&(i+=e.state.doc.resolve(t+1).node().nodeSize);const o=e.domAtPos(t).node.cloneNode(!0),n=e.domAtPos(t).node,r=(p,h)=>Array.prototype.indexOf.call(p.children,h),a=r(n,e.domAtPos(t+1).node.parentElement),s=r(n,e.domAtPos(i-1).node.parentElement);for(let p=n.childElementCount-1;p>=0;p--)(p>s||p<a)&&o.removeChild(o.children[p]);Qt(e.root),P=o;const c=e.dom.className.split(" ").filter(p=>p!=="ProseMirror"&&p!=="bn-root"&&p!=="bn-editor").join(" ");P.className=P.className+" bn-drag-preview "+c,e.root instanceof ShadowRoot?e.root.appendChild(P):e.root.body.appendChild(P)}function Qt(e){P!==void 0&&(e instanceof ShadowRoot?e.removeChild(P):e.body.appendChild(P),P=void 0)}function cn(e,t){if(!e.dataTransfer)return;const i=t.prosemirrorView,o=i.dom.getBoundingClientRect(),n={left:o.left+o.width/2,top:e.clientY},r=i.root.elementsFromPoint(n.left,n.top);let a;for(const l of r)if(i.dom.contains(l)){a=re(l,i);break}if(!a)return;const s=ln(a.node,i);if(s!=null){const l=i.state.selection,c=i.state.doc,{from:p,to:h}=dn(l,c),m=p<=s&&s<h,g=l.$anchor.node()!==l.$head.node()||l instanceof Z;m&&g?(i.dispatch(i.state.tr.setSelection(Z.create(c,p,h))),Yt(i,p,h)):(i.dispatch(i.state.tr.setSelection(_.NodeSelection.create(i.state.doc,s))),Yt(i,s));const f=i.state.selection.content(),k=t._tiptapEditor.schema,j=_e(k,t).serializeProseMirrorFragment(f.content),z=Y(k,t).exportProseMirrorFragment(f.content),ae=He(z);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",j),e.dataTransfer.setData("text/html",z),e.dataTransfer.setData("text/plain",ae),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(P,0,0),i.dragging={slice:f,move:!0}}}class ei{constructor(t,i,o){u(this,"state");u(this,"emitUpdate");u(this,"needUpdate",!1);u(this,"mousePos");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"updateState",()=>{var a,s,l,c;if(this.menuFrozen||!this.mousePos)return;const t=this.pmView.dom.firstChild.getBoundingClientRect();this.horizontalPosAnchor=t.x;const i={left:t.left+t.width/2,top:this.mousePos.y},o=this.pmView.root.elementsFromPoint(i.left,i.top);let n;for(const p of o)if(this.pmView.dom.contains(p)){n=re(p,this.pmView);break}if(!n||!this.editor.isEditable){(a=this.state)!=null&&a.show&&(this.state.show=!1,this.needUpdate=!0);return}if((s=this.state)!=null&&s.show&&((l=this.hoveredBlock)!=null&&l.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===n.id)return;this.hoveredBlock=n.node;const r=n.node.firstChild;if(r&&this.editor.isEditable){const p=r.getBoundingClientRect();this.state={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:p.x,p.y,p.width,p.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.needUpdate=!0}});u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const i=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!i||i.inside===-1){const o=new Event("drop",t),n=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=n.left+n.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const i=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!i||i.inside===-1){const o=new Event("dragover",t),n=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=n.left+n.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onKeyDown",t=>{var i;(i=this.state)!=null&&i.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state),this.menuFrozen=!1)});u(this,"onMouseDown",()=>{this.state&&this.state.show&&this.menuFrozen&&(this.menuFrozen=!1,this.state.show=!1,this.emitUpdate(this.state))});u(this,"onMouseMove",t=>{var r;this.mousePos={x:t.clientX,y:t.clientY};const i=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>i.left&&this.mousePos.x<i.right&&this.mousePos.y>i.top&&this.mousePos.y<i.bottom,n=this.pmView.dom.parentElement;if(o&&t&&t.target&&!(n===t.target||n.contains(t.target))){(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateState(),this.needUpdate&&(this.emitUpdate(this.state),this.needUpdate=!1)});u(this,"onScroll",()=>{var t;if((t=this.state)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.state.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.emitUpdate(this.state)}});this.editor=t,this.pmView=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.dom.addEventListener("mousedown",this.onMouseDown),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),this.pmView.root.addEventListener("scroll",this.onScroll,!0)}update(){var i;const t=(i=this.state)==null?void 0:i.block.id;this.updateState(),this.needUpdate&&this.state&&t!==this.state.block.id&&(this.emitUpdate(this.state),this.needUpdate=!1)}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("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0),this.pmView.dom.removeEventListener("mousedown",this.onMouseDown),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.state)!=null&&l.show&&(this.state.show=!1,this.emitUpdate(this.state));const i=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:i.left+i.width/2,top:i.top+i.height/2});if(!o)return;const n=v(this.editor._tiptapEditor.state.doc,o.pos);if(n===void 0)return;const{contentNode:r,startPos:a,endPos:s}=n;if(r.type.spec.content!=="inline*"||r.textContent.length!==0){const c=s+1,p=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).setTextSelection(p).run()}else this.editor._tiptapEditor.commands.setTextSelection(a+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(V,{triggerCharacter:"/",fromUserInput:!1}))}}const ti=new _.PluginKey("SideMenuPlugin");class ii extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"addBlock",()=>this.view.addBlock());u(this,"blockDragStart",i=>{this.view.isDragging=!0,cn(i,this.editor)});u(this,"blockDragEnd",()=>Qt(this.editor.prosemirrorView.root));u(this,"freezeMenu",()=>this.view.menuFrozen=!0);u(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=i,this.plugin=new _.Plugin({key:ti,view:o=>(this.view=new ei(i,o,n=>{this.emit("update",n)}),this.view)})}onUpdate(i){return this.on("update",i)}}let S;function oi(e){S||(S=document.createElement("div"),S.innerHTML="_",S.style.opacity="0",S.style.height="1px",S.style.width="1px",e instanceof Document?e.body.appendChild(S):e.appendChild(S))}function un(e){S&&(e instanceof Document?e.body.removeChild(S):e.removeChild(S),S=void 0)}function ce(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function pn(e){for(;e&&e.nodeName!=="TD"&&e.nodeName!=="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function hn(e,t){e.forEach(i=>{const o=t.querySelectorAll(i);for(let n=0;n<o.length;n++)o[n].style.visibility="hidden"})}class ni{constructor(t,i,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"menuFrozen",!1);u(this,"prevWasEditable",null);u(this,"mouseMoveHandler",t=>{var c;if(this.menuFrozen)return;const i=pn(t.target);if(!i||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate());return}const o=ce(i),n=ce(i.parentElement),r=i.getBoundingClientRect(),a=i.parentElement.parentElement.getBoundingClientRect(),s=re(i,this.pmView);if(!s)return;let l;if(this.editor._tiptapEditor.state.doc.descendants((p,h)=>{if(typeof l<"u")return!1;if(p.type.name!=="blockContainer"||p.attrs.id!==s.id)return!0;const m=x(p,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache);return Rt("table",m,this.editor)&&(this.tablePos=h+1,l=m),!1}),!!l&&(this.tableId=s.id,!(this.state!==void 0&&this.state.show&&this.tableId===s.id&&this.state.rowIndex===n&&this.state.colIndex===o)))return this.state={show:!0,referencePosCell:r,referencePosTable:a,block:l,colIndex:o,rowIndex:n,draggingState:void 0},this.emitUpdate(),!1});u(this,"dragOverHandler",t=>{var m;if(((m=this.state)==null?void 0:m.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",hn(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"],this.pmView.root);const i={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(i.left,i.top).filter(g=>g.tagName==="TD"||g.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const n=o[0];let r=!1;const a=ce(n.parentElement),s=ce(n),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,p=(this.state.draggingState.draggedCellOrientation==="row"?a:s)!==l;(this.state.rowIndex!==a||this.state.colIndex!==s)&&(this.state.rowIndex=a,this.state.colIndex=s,this.state.referencePosCell=n.getBoundingClientRect(),r=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?i.top:i.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,r=!0),r&&this.emitUpdate(),p&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});u(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const i=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=i[this.state.draggingState.originalIndex];i.splice(this.state.draggingState.originalIndex,1),i.splice(this.state.rowIndex,0,o)}else{const o=i.map(n=>n.cells[this.state.draggingState.originalIndex]);i.forEach((n,r)=>{n.cells.splice(this.state.draggingState.originalIndex,1),n.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:i}})});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const i=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=i.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=i.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.emitUpdate()}});this.editor=t,this.pmView=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},i.dom.addEventListener("mousemove",this.mouseMoveHandler),i.root.addEventListener("dragover",this.dragOverHandler),i.root.addEventListener("drop",this.dropHandler),i.root.addEventListener("scroll",this.scrollHandler,!0)}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const J=new _.PluginKey("TableHandlesPlugin");class ri extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"colDragStart",i=>{if(this.view.state===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:i.clientX},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),oi(this.editor._tiptapEditor.view.root),i.dataTransfer.setDragImage(S,0,0),i.dataTransfer.effectAllowed="move"});u(this,"rowDragStart",i=>{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={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:i.clientY},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),oi(this.editor._tiptapEditor.view.root),i.dataTransfer.setDragImage(S,0,0),i.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._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),un(this.editor._tiptapEditor.view.root)});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});this.editor=i,this.plugin=new _.Plugin({key:J,view:o=>(this.view=new ni(i,o,n=>{this.emit("update",n)}),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 n=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(n===this.view.state.draggingState.originalIndex)return M.DecorationSet.create(o.doc,r);const a=o.doc.resolve(this.view.tablePos+1),s=a.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(a.posAtIndex(n)+1),c=l.node();for(let p=0;p<c.childCount;p++){const h=o.doc.resolve(l.posAtIndex(p)+1),m=h.node(),g=h.pos+(n>this.view.state.draggingState.originalIndex?m.nodeSize-2:0);r.push(M.Decoration.widget(g,()=>{const f=document.createElement("div");return f.className="bn-table-drop-cursor",f.style.left="0",f.style.right="0",n>this.view.state.draggingState.originalIndex?f.style.bottom="-2px":f.style.top="-3px",f.style.height="4px",f}))}}else for(let l=0;l<s.childCount;l++){const c=o.doc.resolve(a.posAtIndex(l)+1),p=o.doc.resolve(c.posAtIndex(n)+1),h=p.node(),m=p.pos+(n>this.view.state.draggingState.originalIndex?h.nodeSize-2:0);r.push(M.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.top="0",g.style.bottom="0",n>this.view.state.draggingState.originalIndex?g.style.right="-2px":g.style.left="-3px",g.style.width="4px",g}))}return M.DecorationSet.create(o.doc,r)}}})}onUpdate(i){return this.on("update",i)}}function ai(e,t){const i=e.state.selection.content().content,n=_e(e.state.schema,t).serializeProseMirrorFragment(i),a=Y(e.state.schema,t).exportProseMirrorFragment(i),s=He(a);return{internalHTML:n,externalHTML:a,plainText:s}}const mn=e=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new _.Plugin({props:{handleDOMEvents:{copy(t,i){i.preventDefault(),i.clipboardData.clearData(),"node"in t.state.selection&&t.state.selection.node.type.spec.group==="blockContent"&&t.dispatch(t.state.tr.setSelection(new _.NodeSelection(t.state.doc.resolve(t.state.selection.from-1))));const{internalHTML:o,externalHTML:n,plainText:r}=ai(t,e);return i.clipboardData.setData("blocknote/html",o),i.clipboardData.setData("text/html",n),i.clipboardData.setData("text/plain",r),!0},dragstart(t,i){if(!("node"in t.state.selection)||t.state.selection.node.type.spec.group!=="blockContent")return;t.dispatch(t.state.tr.setSelection(new _.NodeSelection(t.state.doc.resolve(t.state.selection.from-1)))),i.preventDefault(),i.dataTransfer.clearData();const{internalHTML:o,externalHTML:n,plainText:r}=ai(t,e);return i.dataTransfer.setData("blocknote/html",o),i.dataTransfer.setData("text/html",n),i.dataTransfer.setData("text/plain",r),!0}}}})]}});function fn(e){let t=e.getTextCursorPosition().block,i=e.schema.blockSchema[t.type].content;for(;i==="none";)t=e.getTextCursorPosition().nextBlock,i=e.schema.blockSchema[t.type].content,e.setTextCursorPosition(t,"end")}function T(e,t){const i=e.getTextCursorPosition().block;if(i.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(i.content)&&(i.content.length===1&&$(i.content[0])&&i.content[0].type==="text"&&i.content[0].text==="/"||i.content.length===0)?e.updateBlock(i,t):(e.insertBlocks([t],i,"after"),e.setTextCursorPosition(e.getTextCursorPosition().nextBlock,"end"));const o=e.getTextCursorPosition().block;return fn(e),o}function gn(e){const t=[];return B("heading",e)&&t.push({onItemClick:()=>{T(e,{type:"heading",props:{level:1}})},badge:H("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{T(e,{type:"heading",props:{level:2}})},badge:H("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{T(e,{type:"heading",props:{level:3}})},badge:H("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),B("numberedListItem",e)&&t.push({onItemClick:()=>{T(e,{type:"numberedListItem"})},badge:H("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),B("bulletListItem",e)&&t.push({onItemClick:()=>{T(e,{type:"bulletListItem"})},badge:H("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),B("checkListItem",e)&&t.push({onItemClick:()=>{T(e,{type:"checkListItem"})},badge:H("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),B("paragraph",e)&&t.push({onItemClick:()=>{T(e,{type:"paragraph"})},badge:H("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),B("table",e)&&t.push({onItemClick:()=>{T(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),B("image",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"image"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"image",...e.dictionary.slash_menu.image}),B("video",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"video"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"video",...e.dictionary.slash_menu.video}),B("audio",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"audio"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"audio",...e.dictionary.slash_menu.audio}),B("file",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"file"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"image",...e.dictionary.slash_menu.file}),t}function bn(e,t){return e.filter(({title:i,aliases:o})=>i.toLowerCase().includes(t.toLowerCase())||o&&o.filter(n=>n.toLowerCase().includes(t.toLowerCase())).length!==0)}const De=["blocknote/html","Files","text/html","text/plain"];function kn(e,t){const i=e.split("/"),o=t.split("/");if(i.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${t} is not a valid MIME type.`);return i[1]==="*"||o[1]==="*"?i[0]===o[0]:(i[0]==="*"||o[0]==="*"||i[0]===o[0])&&i[1]===o[1]}async function si(e,t){if(!t.uploadFile)return;const i="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(i===null)return;let o=null;for(const a of De)if(i.types.includes(a)){o=a;break}if(o!=="Files")return;const n=i.items;if(!n)return;e.preventDefault();const r=Object.values(t.schema.blockSchema).filter(a=>a.isFileBlock);for(let a=0;a<n.length;a++){let s="file";for(const c of r)for(const p of c.fileBlockAcceptMimeTypes||[])if(kn(n[a].type,p)){s=c.type;break}const l=n[a].getAsFile();if(l){const c=await t.uploadFile(l);if(typeof c=="string"){const p={type:s,props:{name:l.name,url:c}};T(t,p)}}}}const _n=e=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new _.Plugin({props:{handleDOMEvents:{paste(t,i){if(i.preventDefault(),!e.isEditable)return;let o=null;for(const r of De)if(i.clipboardData.types.includes(r)){o=r;break}if(o===null)return!0;if(o==="Files")return si(i,e),!0;let n=i.clipboardData.getData(o);return o==="text/html"&&(n=zt(n.trim()).innerHTML),e._tiptapEditor.view.pasteHTML(n),!0}}}})]}}),yn=e=>b.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new _.Plugin({props:{handleDOMEvents:{drop(t,i){if(!e.isEditable)return;let o=null;for(const n of De)if(i.dataTransfer.types.includes(n)){o=n;break}return o===null?!0:o==="Files"?(si(i,e),!0):!1}}}})]}}),wn=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:E.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):E.backgroundColor.default,renderHTML:e=>e.backgroundColor!==E.backgroundColor.default&&{"data-background-color":e.backgroundColor}}}}]}}),vn=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>e.textAlignment!=="left"&&{"data-text-alignment":e.textAlignment}}}}]}}),En=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:E.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):E.textColor.default,renderHTML:e=>e.textColor!==E.textColor.default&&{"data-text-color":e.textColor}}}}]}}),xn=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new _.PluginKey(this.name);return[new _.Plugin({key:e,appendTransaction:(t,i,o)=>{const{doc:n,tr:r,schema:a}=o,s=e.getState(o),l=n.content.size-2,c=a.nodes.blockContainer,p=a.nodes.paragraph;if(s)return r.insert(l,c.create(void 0,p.create()))},state:{init:(t,i)=>{},apply:(t,i)=>{if(!t.docChanged)return i;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")throw new Error("Expected blockContainer");const n=o.firstChild;if(!n)throw new Error("Expected blockContent");return o.nodeSize>4||n.type.spec.content!=="inline*"}}})]}}),Cn=new _.PluginKey("non-editable-block"),Sn=()=>new _.Plugin({key:Cn,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"){const i=e.state.tr;return e.dispatch(i.insert(e.state.tr.selection.$to.after(),e.state.schema.nodes.paragraph.create()).setSelection(new _.TextSelection(i.doc.resolve(e.state.tr.selection.$to.after()+1)))),!0}}return!1}}}),li=new _.PluginKey("previous-blocks"),Tn={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Mn=()=>{let e;return new _.Plugin({key:li,view(t){return{update:async(i,o)=>{var n;((n=this.key)==null?void 0:n.getState(i.state).updatedBlocks.size)>0&&(e=setTimeout(()=>{i.dispatch(i.state.tr.setMeta(li,{clearUpdate:!0}))},0))},destroy:()=>{e&&clearTimeout(e)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,i,o,n){if(i.currentTransactionOldBlockAttrs={},i.updatedBlocks.clear(),!t.docChanged||o.doc.eq(n.doc))return i;const r={},a=b.findChildren(o.doc,c=>c.attrs.id),s=new Map(a.map(c=>[c.node.attrs.id,c])),l=b.findChildren(n.doc,c=>c.attrs.id);for(const c of l){const p=s.get(c.node.attrs.id),h=p==null?void 0:p.node.firstChild,m=c.node.firstChild;if(p&&h&&m){const g={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:n.doc.resolve(c.pos).depth};let f={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(p.pos).depth};r[c.node.attrs.id]=f,t.getMeta("numberedListIndexing")&&(c.node.attrs.id in i.prevTransactionOldBlockAttrs&&(f=i.prevTransactionOldBlockAttrs[c.node.attrs.id]),g.type==="numberedListItem"&&(f.index=g.index)),i.currentTransactionOldBlockAttrs[c.node.attrs.id]=f,JSON.stringify(f)!==JSON.stringify(g)&&(f["depth-change"]=f.depth-g.depth,i.updatedBlocks.add(c.node.attrs.id))}}return i.prevTransactionOldBlockAttrs=r,i}},props:{decorations(t){const i=this.getState(t);if(i.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((n,r)=>{if(!n.attrs.id||!i.updatedBlocks.has(n.attrs.id))return;const a=i.currentTransactionOldBlockAttrs[n.attrs.id],s={};for(const[c,p]of Object.entries(a))s["data-prev-"+Tn[c]]=p||"none";const l=M.Decoration.node(r,r+n.nodeSize,{...s});o.push(l)}),M.DecorationSet.create(t.doc,o)}}})},Bn={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ln=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:e=>{if(typeof e=="string")return!1;const t={};for(const[i,o]of Object.entries(Bn))e.getAttribute(o)&&(t[i]=e.getAttribute(o));return e.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:e}){var n;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,a]of Object.entries(e))r!=="class"&&t.setAttribute(r,a);const i={...((n=this.options.domAttributes)==null?void 0:n.block)||{},...e},o=document.createElement("div");o.className=U("bn-block",i.class),o.setAttribute("data-node-type",this.name);for(const[r,a]of Object.entries(i))r!=="class"&&o.setAttribute(r,a);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:e=>({state:t,dispatch:i})=>{const o=t.schema.nodes.blockContainer.createAndFill();return i&&t.tr.insert(e,o).scrollIntoView(),!0},BNDeleteBlock:e=>({state:t,dispatch:i})=>{const o=v(t.doc,e);if(o===void 0)return!1;const{startPos:n,endPos:r}=o;return i&&t.tr.deleteRange(n,r),!0},BNUpdateBlock:(e,t)=>({state:i,dispatch:o})=>{const n=v(i.doc,e);if(n===void 0)return!1;const{startPos:r,endPos:a,node:s,contentNode:l}=n;if(o){if(t.children!==void 0){const m=[];for(const g of t.children)m.push(N(g,i.schema,this.options.editor.schema.styleSchema));s.childCount===2?i.tr.replace(r+l.nodeSize+1,a-1,new y.Slice(y.Fragment.from(m),0,0)):i.tr.insert(r+l.nodeSize,i.schema.nodes.blockGroup.create({},m))}const c=l.type.name,p=t.type||c;let h="keep";if(t.content)if(typeof t.content=="string")h=K([t.content],i.schema,this.options.editor.schema.styleSchema);else if(Array.isArray(t.content))h=K(t.content,i.schema,this.options.editor.schema.styleSchema);else if(t.content.type==="tableContent")h=be(t.content,i.schema,this.options.editor.schema.styleSchema);else throw new I(t.content.type);else{const m=i.schema.nodes[c].spec.content,g=i.schema.nodes[p].spec.content;m===""||g!==m&&(h=[])}h==="keep"?i.tr.setNodeMarkup(r,t.type===void 0?void 0:i.schema.nodes[t.type],{...l.attrs,...t.props}):i.tr.replaceWith(r,a,i.schema.nodes[p].create({...l.attrs,...t.props},h)).setSelection(i.schema.nodes[p].spec.content===""?new _.NodeSelection(i.tr.doc.resolve(r)):i.schema.nodes[p].spec.content==="inline*"?new _.TextSelection(i.tr.doc.resolve(r)):new _.TextSelection(i.tr.doc.resolve(r+4))),i.tr.setNodeMarkup(r-1,void 0,{...s.attrs,...t.props})}return!0},BNMergeBlocks:e=>({state:t,dispatch:i})=>{const o=t.doc.resolve(e+1).node().type.name==="blockContainer",n=t.doc.resolve(e-1).node().type.name==="blockContainer";if(!o||!n)return!1;const r=v(t.doc,e+1),{node:a,contentNode:s,startPos:l,endPos:c,depth:p}=r;if(a.childCount===2){const g=t.doc.resolve(l+s.nodeSize+1),f=t.doc.resolve(c-1),k=g.blockRange(f);i&&t.tr.lift(k,p-1)}let h=e-1,m=v(t.doc,h);for(;m.numChildBlocks>0;)if(h--,m=v(t.doc,h),m===void 0)return!1;return i&&(i(t.tr.deleteRange(l,l+s.nodeSize).replace(h-1,l,new y.Slice(s.content,0,0)).scrollIntoView()),t.tr.setSelection(new _.TextSelection(t.doc.resolve(h-1)))),!0},BNSplitBlock:(e,t,i)=>({state:o,dispatch:n})=>{const r=v(o.doc,e);if(r===void 0)return!1;const{contentNode:a,contentType:s,startPos:l,endPos:c,depth:p}=r,h=o.doc.cut(l+1,e),m=o.doc.cut(e,c-1),g=o.schema.nodes.blockContainer.createAndFill(),f=c+1,k=f+2;return n&&(o.tr.insert(f,g),o.tr.replace(k,k+1,m.content.size>0?new y.Slice(y.Fragment.from(m),p+2,p+2):void 0),t&&o.tr.setBlockType(k,k,o.schema.node(s).type,i?a.attrs:void 0),o.tr.setSelection(new _.TextSelection(o.doc.resolve(k))),o.tr.replace(l+1,c-1,h.content.size>0?new y.Slice(y.Fragment.from(h),p+2,p+2):void 0),o.tr.scrollIntoView()),!0}}},addProseMirrorPlugins(){return[Mn(),Sn()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:n})=>{const{contentType:r,startPos:a}=v(n.doc,n.selection.from),s=n.selection.from===a+1,l=r.name==="paragraph";return s&&!l?o.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:n})=>{const{startPos:r}=v(n.doc,n.selection.from);return n.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:n})=>{const{depth:r,startPos:a}=v(n.doc,n.selection.from),s=n.selection.from===a+1,l=n.selection.empty,c=a===2,p=a-1;return!c&&s&&l&&r===2?o.BNMergeBlocks(p):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:n})=>{const{node:r,depth:a,endPos:s}=v(n.doc,n.selection.from),l=s===n.doc.nodeSize-4,c=n.selection.from===s-1,p=n.selection.empty,h=r.childCount===2;if(!l&&c&&p&&!h){let m=a,g=s+2,f=n.doc.resolve(g).depth;for(;f<m;)m=f,g+=2,f=n.doc.resolve(g).depth;return o.BNMergeBlocks(g-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:n})=>{const{contentNode:r,depth:a}=v(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,c=r.childCount===0,p=a>2;return s&&l&&c&&p?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:n,chain:r})=>{const{contentNode:a,endPos:s}=v(n.doc,n.selection.from),l=n.selection.$anchor.parentOffset===0,c=n.selection.anchor===n.selection.head,p=a.childCount===0;if(l&&c&&p){const h=s+1,m=h+2;return r().BNCreateBlock(h).setTextSelection(m).run(),!0}return!1}),()=>o.command(({state:n,chain:r})=>{const{contentNode:a}=v(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0;return a.childCount===0?!1:(r().deleteSelection().BNSplitBlock(n.selection.from,s,s).run(),!0)})]),Tab:()=>{var o,n,r;return(o=this.options.editor.formattingToolbar)!=null&&o.shown||(n=this.options.editor.linkToolbar)!=null&&n.shown||(r=this.options.editor.filePanel)!=null&&r.shown?!1:(this.editor.commands.sinkListItem("blockContainer"),!0)},"Shift-Tab":()=>{var o,n,r;return(o=this.options.editor.formattingToolbar)!=null&&o.shown||(n=this.options.editor.linkToolbar)!=null&&n.shown||(r=this.options.editor.filePanel)!=null&&r.shown?!1:(this.editor.commands.liftListItem("blockContainer"),!0)}}}}),In=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:e=>typeof e=="string"?!1:e.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:e}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...e},i=document.createElement("div");i.className=U("bn-block-group",t.class),i.setAttribute("data-node-type","blockGroup");for(const[n,r]of Object.entries(t))n!=="class"&&i.setAttribute(n,r);return{dom:i,contentDOM:i}}}),Pn=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),di=e=>{var o;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Ai.Gapcursor,W.configure({types:["blockContainer"]}),Ni.HardBreak.extend({priority:10}),Di.Text,Ui.Link.extend({addKeyboardShortcuts(){return{"Mod-k":()=>(this.editor.commands.toggleLink({href:""}),!0)}}}),...Object.values(e.styleSpecs).map(n=>n.implementation.mark),En,wn,vn,b.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),Pn,Ln.configure({editor:e.editor,domAttributes:e.domAttributes}),In.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(n=>n.config!=="link"&&n.config!=="text").map(n=>n.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(n=>[...(n.implementation.requiredExtensions||[]).map(r=>r.configure({editor:e.editor,domAttributes:e.domAttributes})),n.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),mn(e.editor),_n(e.editor),yn(e.editor),Pi.Dropcursor.configure({width:5,color:"#ddeeff"}),...e.trailingBlock===void 0||e.trailingBlock?[xn]:[]];if(e.collaboration){if(t.push(Wi.default.configure({fragment:e.collaboration.fragment})),(o=e.collaboration.provider)!=null&&o.awareness){const n=r=>{const a=document.createElement("span");a.classList.add("collaboration-cursor__caret"),a.setAttribute("style",`border-color: ${r.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${r.color}`),s.insertBefore(document.createTextNode(r.name),null);const l=document.createTextNode(""),c=document.createTextNode("");return a.insertBefore(l,null),a.insertBefore(s,null),a.insertBefore(c,null),a};t.push($i.default.configure({user:e.collaboration.user,render:e.collaboration.renderCursor||n,provider:e.collaboration.provider}))}}else t.push(Hi.History);const i=e.disableExtensions||[];return t.filter(n=>!i.includes(n.name))};function An(e,t){const i=[];return e.forEach((o,n,r)=>{r!==t&&i.push(o)}),y.Fragment.from(i)}function Nn(e,t){let i=y.Fragment.from(e.content);for(let o=0;o<i.childCount;o++)if(i.child(o).type.spec.group==="blockContent"){const n=[i.child(o)];if(o+1<i.childCount&&i.child(o+1).type.spec.group==="blockGroup"){const a=i.child(o+1).child(0).child(0);(a.type.name==="bulletListItem"||a.type.name==="numberedListItem"||a.type.name==="checkListItem")&&(n.push(i.child(o+1)),i=An(i,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,n);i=i.replaceChild(o,r)}return new y.Slice(i,e.openStart,e.openEnd)}function Re(e){return e&&Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}class ue{constructor(t){u(this,"blockSpecs");u(this,"inlineContentSpecs");u(this,"styleSpecs");u(this,"blockSchema");u(this,"inlineContentSchema");u(this,"styleSchema");u(this,"BlockNoteEditor","only for types");u(this,"Block","only for types");u(this,"PartialBlock","only for types");this.blockSpecs=Re(t==null?void 0:t.blockSpecs)||Ie,this.inlineContentSpecs=Re(t==null?void 0:t.inlineContentSpecs)||Ae,this.styleSpecs=Re(t==null?void 0:t.styleSpecs)||Pe,this.blockSchema=Ee(this.blockSpecs),this.inlineContentSchema=xe(this.inlineContentSpecs),this.styleSchema=Se(this.styleSpecs)}static create(t){return new ue(t)}}class Hn extends b.Editor{constructor(i,o){super({...i,content:void 0});u(this,"_state");u(this,"mount",i=>{i?(this.options.element=i,this.createViewAlternative()):this.destroy()});const n=this.schema;let r;const a=n.nodes.doc.createAndFill;n.nodes.doc.createAndFill=(...l)=>{if(r)return r;const c=a.apply(n.nodes.doc,l),p=JSON.parse(JSON.stringify(c.toJSON()));return p.content[0].content[0].attrs.id="initialBlockId",r=y.Node.fromJSON(n,p),r};let s;try{const l=i==null?void 0:i.content.map(c=>N(c,this.schema,o).toJSON());s=b.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(i.content))}this._state=_.EditorState.create({doc:s,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}createView(){}createViewAlternative(){queueMicrotask(()=>{this.view=new M.EditorView({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:this.state});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.createNodeViews()})}}const Un=new _.PluginKey("blocknote-placeholder"),Dn=(e,t)=>new _.Plugin({key:Un,view:()=>{const i=document.createElement("style"),o=e._tiptapEditor.options.injectNonce;o&&i.setAttribute("nonce",o),e._tiptapEditor.view.root instanceof ShadowRoot?e._tiptapEditor.view.root.append(i):e._tiptapEditor.view.root.head.appendChild(i);const n=i.sheet,r=(s="")=>`.bn-block-content${s} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`,a=(s,l=!0)=>{const c=l?"[data-is-empty-and-focused]":"";if(s==="default")return r(c);const p=`[data-content-type="${s}"]`;return r(c+p)};for(const[s,l]of Object.entries(t)){const c=s==="default";n.insertRule(`${a(s,c)}{ content: ${JSON.stringify(l)}; }`),c||n.insertRule(`${a(s,!0)}{ content: ${JSON.stringify(l)}; }`)}return{destroy:()=>{e._tiptapEditor.view.root instanceof ShadowRoot?e._tiptapEditor.view.root.removeChild(i):e._tiptapEditor.view.root.head.removeChild(i)}}},props:{decorations:i=>{const{doc:o,selection:n}=i;if(!e.isEditable||!n.empty)return;const r=n.$anchor,a=r.parent;if(a.content.size>0)return null;const s=r.before(),l=M.Decoration.node(s,s+a.nodeSize,{"data-is-empty-and-focused":"true"});return M.DecorationSet.create(o,[l])}}}),Qn="",er="",Rn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Oe{constructor(t){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"dictionary");u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"formattingToolbar");u(this,"linkToolbar");u(this,"sideMenu");u(this,"suggestionMenus");u(this,"filePanel");u(this,"tableHandles");u(this,"uploadFile");u(this,"resolveFileUrl");var l,c,p,h,m,g,f;this.options=t;const i=t;if(i.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(i.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(i.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(i.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||We;const o={defaultStyles:!0,schema:t.schema||ue.create(),...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};this.schema=o.schema,this.blockImplementations=o.schema.blockSpecs,this.inlineContentImplementations=o.schema.inlineContentSpecs,this.styleImplementations=o.schema.styleSpecs,this.formattingToolbar=new $t(this),this.linkToolbar=new Zt(this),this.sideMenu=new ii(this),this.suggestionMenus=new Jt(this),this.filePanel=new qt(this),B("table",this)&&(this.tableHandles=new ri(this));const n=di({editor:this,domAttributes:o.domAttributes||{},blockSchema:this.schema.blockSchema,blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:o.collaboration,trailingBlock:o.trailingBlock,disableExtensions:o.disableExtensions}),r=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.formattingToolbar.plugin,this.linkToolbar.plugin,this.sideMenu.plugin,this.suggestionMenus.plugin,...this.filePanel?[this.filePanel.plugin]:[],...this.tableHandles?[this.tableHandles.plugin]:[],Dn(this,o.placeholders)]});n.push(r),this.uploadFile=o.uploadFile,this.resolveFileUrl=o.resolveFileUrl||(async k=>k),o.collaboration&&o.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const a=o.initialContent||(t.collaboration?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:W.options.generateID()}]);if(!Array.isArray(a)||a.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+a);const s={...Rn,...o._tiptapOptions,content:a,extensions:[...((l=o._tiptapOptions)==null?void 0:l.extensions)||[],...n],editorProps:{...(c=o._tiptapOptions)==null?void 0:c.editorProps,attributes:{...(h=(p=o._tiptapOptions)==null?void 0:p.editorProps)==null?void 0:h.attributes,...(m=o.domAttributes)==null?void 0:m.editor,class:U("bn-editor",o.defaultStyles?"bn-default-styles":"",((f=(g=o.domAttributes)==null?void 0:g.editor)==null?void 0:f.class)||"")},transformPasted:Nn}};this._tiptapEditor=new Hn(s,this.schema.styleSchema)}static create(t={}){return new Oe(t)}mount(t){this._tiptapEditor.mount(t)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){return this.topLevelBlocks}get document(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(i=>(t.push(x(i,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){const i=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(n=>typeof o<"u"?!1:n.type.name!=="blockContainer"||n.attrs.id!==i?!0:(o=x(n,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),!1)),o}forEachBlock(t,i=!1){const o=this.document.slice();i&&o.reverse();function n(r){for(const a of r){if(!t(a))return!1;const s=i?a.children.slice().reverse():a.children;if(!n(s))return!1}return!0}n(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:i,startPos:o,endPos:n}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(n).index(i-1),a=this._tiptapEditor.state.doc.resolve(n+1).node().childCount;let s;r>0&&(s=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<a-1&&(l=this._tiptapEditor.state.doc.resolve(n+2).node()),{block:x(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),prevBlock:s===void 0?void 0:x(s,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:x(l,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)}}setTextCursorPosition(t,i="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:n}=Ne(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:a}=v(this._tiptapEditor.state.doc,n+2),s=this.schema.blockSchema[a.type.name].content;if(s==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(s==="inline")i==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+a.nodeSize-1);else if(s==="table")i==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+a.nodeSize-4);else throw new I(s)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const t=[];return this._tiptapEditor.state.doc.descendants((i,o)=>i.type.spec.group!=="blockContent"||o+i.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(x(this._tiptapEditor.state.doc.resolve(o).node(),this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,i,o="before"){return zo(t,i,o,this)}updateBlock(t,i){return Fo(t,i,this)}removeBlocks(t){return Ko(t,this)}replaceBlocks(t,i){return qo(t,i,this)}insertInlineContent(t){const i=K(t,this._tiptapEditor.schema,this.schema.styleSchema);Go({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},i,this)}getActiveStyles(){const t={},i=this._tiptapEditor.state.selection.$to.marks();for(const o of i){const n=this.schema.styleSchema[o.type.name];if(!n){o.type.name!=="link"&&console.warn("mark not found in styleschema",o.type.name);continue}n.propSchema==="boolean"?t[n.type]=!0:t[n.type]=o.attrs.stringValue}return t}addStyles(t){for(const[i,o]of Object.entries(t)){const n=this.schema.styleSchema[i];if(!n)throw new Error(`style ${i} not found in styleSchema`);if(n.propSchema==="boolean")this._tiptapEditor.commands.setMark(i);else if(n.propSchema==="string")this._tiptapEditor.commands.setMark(i,{stringValue:o});else throw new I(n.propSchema)}}removeStyles(t){for(const i of Object.keys(t))this._tiptapEditor.commands.unsetMark(i)}toggleStyles(t){for(const[i,o]of Object.entries(t)){const n=this.schema.styleSchema[i];if(!n)throw new Error(`style ${i} not found in styleSchema`);if(n.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(i);else if(n.propSchema==="string")this._tiptapEditor.commands.toggleMark(i,{stringValue:o});else throw new I(n.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,i){if(t==="")return;const{from:o,to:n}=this._tiptapEditor.state.selection;i||(i=this._tiptapEditor.state.doc.textBetween(o,n));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(i,o,n).addMark(o,o+i.length,r))}canNestBlock(){const{startPos:t,depth:i}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(i-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.document){return Y(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return Ft(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.document){return Xo(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return on(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}onChange(t){const i=()=>{t(this)};return this._tiptapEditor.on("update",i),()=>{this._tiptapEditor.off("update",i)}}onSelectionChange(t){const i=()=>{t(this)};return this._tiptapEditor.on("selectionUpdate",i),()=>{this._tiptapEditor.off("selectionUpdate",i)}}}function Ve(e=""){return typeof e=="string"?[{type:"text",text:e,styles:{}}]:e}function ci(e){return typeof e=="string"?Ve(e):Array.isArray(e)?e.flatMap(t=>typeof t=="string"?Ve(t):fe(t)?{...t,content:Ve(t.content)}:$(t)?t:{props:{},...t,content:ci(t.content)}):e}function On(e,t){return t.map(i=>je(e,i))}function je(e,t){const i={id:"",type:t.type,props:{},content:e[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(e[t.type].propSchema).forEach(([o,n])=>{i.props[o]===void 0&&(i.props[o]=n.default)}),{...i,content:ci(i.content),children:i.children.map(o=>je(e,o))}}function ui(e){e.id||(e.id=W.options.generateID()),e.children&&pi(e.children)}function pi(e){for(const t of e)ui(t)}d.AudioBlock=Ut,d.BlockNoteEditor=Oe,d.BlockNoteSchema=ue,d.FileBlock=gt,d.FilePanelProsemirrorPlugin=qt,d.FilePanelView=Kt,d.FormattingToolbarProsemirrorPlugin=$t,d.FormattingToolbarView=Gt,d.ImageBlock=vt,d.LinkToolbarProsemirrorPlugin=Zt,d.SideMenuProsemirrorPlugin=ii,d.SideMenuView=ei,d.SuggestionMenuProseMirrorPlugin=Jt,d.TableHandlesProsemirrorPlugin=ri,d.TableHandlesView=ni,d.UniqueID=W,d.UnreachableCaseError=I,d.VideoBlock=Bt,d.addIdsToBlock=ui,d.addIdsToBlocks=pi,d.addInlineContentAttributes=ot,d.addInlineContentKeyboardShortcuts=nt,d.addStyleAttributes=dt,d.assertEmpty=Qi,d.audioBlockConfig=Pt,d.audioParse=Nt,d.audioPropSchema=It,d.audioRender=At,d.audioToExternalHTML=Ht,d.blockToNode=N,d.camelToDataKebab=Q,d.checkBlockHasDefaultProp=jo,d.checkBlockIsDefaultType=Rt,d.checkBlockIsFileBlock=Ro,d.checkBlockIsFileBlockWithPlaceholder=Vo,d.checkBlockIsFileBlockWithPreview=Oo,d.checkBlockTypeHasDefaultProp=Ot,d.checkDefaultBlockTypeInSchema=B,d.contentNodeToInlineContent=se,d.createAddFileButton=ie,d.createBlockSpec=ee,d.createBlockSpecFromStronglyTypedTiptapNode=G,d.createDefaultFilePreview=te,d.createExternalHTMLExporter=Y,d.createFigureWithCaption=de,d.createFileAndCaptionWrapper=O,d.createInlineContentSpec=ao,d.createInlineContentSpecFromTipTapNode=at,d.createInternalBlockSpec=ve,d.createInternalHTMLSerializer=_e,d.createInternalInlineContentSpec=rt,d.createInternalStyleSpec=Ce,d.createLinkWithCaption=ne,d.createResizeHandlesWrapper=Me,d.createStronglyTypedTiptapNode=D,d.createStyleSpec=so,d.createStyleSpecFromTipTapMark=R,d.createSuggestionMenu=sn,d.defaultBlockSchema=Dt,d.defaultBlockSpecs=Ie,d.defaultInlineContentSchema=Do,d.defaultInlineContentSpecs=Ae,d.defaultProps=E,d.defaultStyleSchema=Uo,d.defaultStyleSpecs=Pe,d.fileBlockConfig=pt,d.fileParse=mt,d.filePropSchema=ut,d.fileRender=ht,d.fileToExternalHTML=ft,d.filenameFromURL=ro,d.filterSuggestionItems=bn,d.formatKeyboardShortcut=H,d.formattingToolbarPluginKey=Wt,d.getBlockFromPos=tt,d.getBlockNoteExtensions=di,d.getBlockSchemaFromSpecs=Ee,d.getDefaultSlashMenuItems=gn,d.getDraggableBlockFromElement=re,d.getInlineContentParseRules=st,d.getInlineContentSchemaFromSpecs=xe,d.getParseRules=it,d.getStyleParseRules=ct,d.getStyleSchemaFromSpecs=Se,d.imageBlockConfig=kt,d.imageParse=yt,d.imagePropSchema=bt,d.imageRender=_t,d.imageToExternalHTML=wt,d.inheritedProps=ye,d.inlineContentToNodes=K,d.insertOrUpdateBlock=T,d.isAppleOS=Qe,d.isLinkInlineContent=me,d.isPartialLinkInlineContent=fe,d.isSafari=no,d.isStyledTextInlineContent=$,d.linkToolbarPluginKey=Xt,d.locales=Zi,d.mergeCSSClasses=U,d.nodeToBlock=x,d.nodeToCustomInlineContent=ke,d.parseEmbedElement=Te,d.parseFigureElement=oe,d.parseImageElement=Be,d.partialBlockToBlockForTesting=je,d.partialBlocksToBlocksForTesting=On,d.propsToAttributes=we,d.sideMenuPluginKey=ti,d.stylePropsToAttributes=lt,d.suggestionMenuPluginKey=V,d.tableContentToNodes=be,d.tableHandlesPluginKey=J,d.uploadToTmpFilesDotOrg_DEV_ONLY=lo,d.videoBlockConfig=Ct,d.videoParse=Tt,d.videoPropSchema=xt,d.videoRender=St,d.videoToExternalHTML=Mt,d.wrapInBlockStructure=le,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
7
|
+
`:"",o={};t.lang&&(o["data-language"]=t.lang);let n={type:"element",tagName:"code",properties:o,children:[{type:"text",value:i}]};return t.meta&&(n.data={meta:t.meta}),e.patch(t,n),n=e.applyData(t,n),n={type:"element",tagName:"pre",properties:{},children:[n]},e.patch(t,n),n}function on(e,t,i,o,n){const r=pe.unified().use(qi.default).use(Ge.default).use(Gi.default,{handlers:{...Fe.defaultHandlers,code:tn}}).use(qe.default).processSync(e);return Ft(r.value,t,i,o,n)}class X{constructor(){u(this,"callbacks",{})}on(t,i){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(i),()=>this.off(t,i)}emit(t,...i){const o=this.callbacks[t];o&&o.forEach(n=>n.apply(this,i))}off(t,i){const o=this.callbacks[t];o&&(i?this.callbacks[t]=o.filter(n=>n!==i):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class Kt{constructor(t,i,o,n){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 i=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);this.state.referencePos=i.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=i,this.pmView=o,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");n(this.state)},o.dom.addEventListener("mousedown",this.mouseDownHandler),o.dom.addEventListener("dragstart",this.dragstartHandler),o.root.addEventListener("scroll",this.scrollHandler,!0)}update(t,i){var n,r;const o=this.pluginKey.getState(t.state);if(!((n=this.state)!=null&&n.show)&&o.block&&this.editor.isEditable){const a=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.state={show:!0,referencePos:a.getBoundingClientRect(),block:o.block},this.emitUpdate();return}(!t.state.selection.eq(i.selection)||!t.state.doc.eq(i.doc)||!this.editor.isEditable)&&(r=this.state)!=null&&r.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 Ue=new _.PluginKey("FilePanelPlugin");class qt extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new _.Plugin({key:Ue,view:o=>(this.view=new Kt(i,Ue,o,n=>{this.emit("update",n)}),this.view),props:{handleKeyDown:(o,n)=>n.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1},state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(Ue))==null?void 0:r.block}}}})}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}onUpdate(i){return this.on("update",i)}}class Gt{constructor(t,i,o){u(this,"state");u(this,"emitUpdate");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"shouldShow",({state:t,from:i,to:o,view:n})=>{const{doc:r,selection:a}=t,{empty:s}=a,l=!r.textBetween(i,o).length&&b.isTextSelection(t.selection);return!(!n.hasFocus()||s||l)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{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=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.state)},i.dom.addEventListener("mousedown",this.viewMousedownHandler),i.dom.addEventListener("mouseup",this.viewMouseupHandler),i.dom.addEventListener("dragstart",this.dragHandler),i.dom.addEventListener("dragover",this.dragHandler),i.root.addEventListener("scroll",this.scrollHandler,!0)}update(t,i){var m,g;const{state:o,composing:n}=t,{doc:r,selection:a}=o,s=i&&i.doc.eq(r)&&i.selection.eq(a);if(n||s)return;const{ranges:l}=a,c=Math.min(...l.map(f=>f.$from.pos)),p=Math.max(...l.map(f=>f.$to.pos)),h=(m=this.shouldShow)==null?void 0:m.call(this,{view:t,state:o,from:c,to:p});if(!this.preventShow&&(h||this.preventHide)){this.state={show:!0,referencePos:this.getSelectionBoundingBox()},this.emitUpdate();return}if((g=this.state)!=null&&g.show&&!this.preventHide&&(!h||this.preventShow||!this.editor.isEditable)){this.state.show=!1,this.emitUpdate();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:i}=t,{ranges:o}=i,n=Math.min(...o.map(a=>a.$from.pos)),r=Math.max(...o.map(a=>a.$to.pos));if(b.isNodeSelection(i)){const a=this.pmView.nodeDOM(n);if(a)return a.getBoundingClientRect()}return b.posToDOMRect(this.pmView,n,r)}}const Wt=new _.PluginKey("FormattingToolbarPlugin");class $t extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"closeMenu",()=>this.view.closeMenu());this.plugin=new _.Plugin({key:Wt,view:o=>(this.view=new Gt(i,o,n=>{this.emit("update",n)}),this.view),props:{handleKeyDown:(o,n)=>n.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}onUpdate(i){return this.on("update",i)}}class nn{constructor(t,i,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 i=t.target,o=this.pmView.posAtDOM(i,0)+1,n=this.pmView.state.doc.resolve(o),r=n.marks();for(const a of r)if(a.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=a,this.mouseHoveredLinkMarkRange=b.getMarkRange(n,a.type,a.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var o;const i=this.pmView.dom.parentElement;this.linkMark&&t&&t.target&&!(i===t.target||i.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=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");o(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},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,i){var n;const o=this.pmView.state.tr.insertText(i,this.linkMarkRange.from,this.linkMarkRange.to);o.addMark(this.linkMarkRange.from,this.linkMarkRange.from+i.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(n=this.state)!=null&&n.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var t;this.pmView.dispatch(this.pmView.state.tr.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(){var i;if(!this.pmView.hasFocus())return;const t=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 o=this.pmView.state.selection.$from.marks();for(const n of o)if(n.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=n,this.keyboardHoveredLinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,n.type,n.attrs)||void 0;break}}if(this.mouseHoveredLinkMark&&(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((i=this.state)!=null&&i.show&&t&&(!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 Xt=new _.PluginKey("LinkToolbarPlugin");class Zt extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"editLink",(i,o)=>{this.view.editLink(i,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.plugin=new _.Plugin({key:Xt,view:o=>(this.view=new nn(i,o,n=>{this.emit("update",n)}),this.view),props:{handleKeyDown:(o,n)=>n.key==="Escape"&&this.shown?(this.view.closeMenu(),!0):!1}})}onUpdate(i){return this.on("update",i)}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}}const rn=b.findParentNode(e=>e.type.name==="blockContainer");class an{constructor(t,i){u(this,"state");u(this,"emitUpdate");u(this,"rootEl");u(this,"pluginState");u(this,"handleScroll",()=>{var t,i;if((t=this.state)!=null&&t.show){const o=(i=this.rootEl)==null?void 0:i.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.state.referencePos=o.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}});u(this,"closeMenu",()=>{this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.view.state.tr.setMeta(V,null))});u(this,"clearQuery",()=>{this.pluginState!==void 0&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos-(this.pluginState.fromUserInput?this.pluginState.triggerCharacter.length:0),to:this.editor._tiptapEditor.state.selection.from}).run()});this.editor=t,this.pluginState=void 0,this.emitUpdate=o=>{if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");i(o,this.state)},this.rootEl=this.editor._tiptapEditor.view.root,this.rootEl.addEventListener("scroll",this.handleScroll,!0)}update(t,i){var c;const o=V.getState(i),n=V.getState(t.state),r=o===void 0&&n!==void 0,a=o!==void 0&&n===void 0;if(!r&&!(o!==void 0&&n!==void 0)&&!a)return;if(this.pluginState=a?o:n,a||!this.editor.isEditable){this.state.show=!1,this.emitUpdate(this.pluginState.triggerCharacter);return}const l=(c=this.rootEl)==null?void 0:c.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(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 V=new _.PluginKey("SuggestionMenuPlugin");class Jt extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"triggerCharacters",[]);u(this,"addTriggerCharacter",i=>{this.triggerCharacters.push(i)});u(this,"removeTriggerCharacter",i=>{this.triggerCharacters=this.triggerCharacters.filter(o=>o!==i)});u(this,"closeMenu",()=>this.view.closeMenu());u(this,"clearQuery",()=>this.view.clearQuery());const o=this.triggerCharacters;this.plugin=new _.Plugin({key:V,view:()=>(this.view=new an(i,(n,r)=>{this.emit(`update ${n}`,r)}),this.view),state:{init(){},apply(n,r,a,s){if(n.getMeta("orderedListIndexing")!==void 0)return r;const l=n.getMeta(V);if(typeof l=="object"&&l!==null&&r===void 0)return{triggerCharacter:l.triggerCharacter,fromUserInput:l.fromUserInput!==!1,queryStartPos:s.selection.from,query:"",decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(r===void 0)return r;if(s.selection.from!==s.selection.to||l===null||n.getMeta("focus")||n.getMeta("blur")||n.getMeta("pointer")||r.triggerCharacter!==void 0&&s.selection.from<r.queryStartPos)return;const c={...r};return c.query=s.doc.textBetween(r.queryStartPos,s.selection.from),c}},props:{handleTextInput(n,r,a,s){const l=this.getState(n.state);return o.includes(s)&&l===void 0?(n.dispatch(n.state.tr.insertText(s).scrollIntoView().setMeta(V,{triggerCharacter:s})),!0):!1},decorations(n){const r=this.getState(n);if(r===void 0)return null;if(!r.fromUserInput){const a=rn(n.selection);if(a)return M.DecorationSet.create(n.doc,[M.Decoration.node(a.pos,a.pos+a.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}return M.DecorationSet.create(n.doc,[M.Decoration.inline(r.queryStartPos-r.triggerCharacter.length,r.queryStartPos,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":r.decorationId})])}}})}onUpdate(i,o){return this.triggerCharacters.includes(i)||this.addTriggerCharacter(i),this.on(`update ${i}`,o)}get shown(){var i,o;return((o=(i=this.view)==null?void 0:i.state)==null?void 0:o.show)||!1}}function sn(e,t){e.suggestionMenus.addTriggerCharacter(t)}class Z extends _.Selection{constructor(i,o){super(i,o);u(this,"nodes");const n=i.node();this.nodes=[],i.doc.nodesBetween(i.pos,o.pos,(r,a,s)=>{if(s!==null&&s.eq(n))return this.nodes.push(r),!1})}static create(i,o,n=o){return new Z(i.resolve(o),i.resolve(n))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(i){if(!(i instanceof Z)||this.nodes.length!==i.nodes.length||this.from!==i.from||this.to!==i.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(i.nodes[o]))return!1;return!0}map(i,o){const n=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?_.Selection.near(i.resolve(n.pos)):n.deleted?_.Selection.near(i.resolve(r.pos)):new Z(i.resolve(n.pos),i.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let P;function re(e,t){var i;for(;e&&e.parentElement&&e.parentElement!==t.dom&&!((i=e.hasAttribute)!=null&&i.call(e,"data-id"));)e=e.parentElement;if(e.hasAttribute("data-id"))return{node:e,id:e.getAttribute("data-id")}}function ln(e,t){const i=re(e,t);if(i&&i.node.nodeType===1){const o=t.docView,n=o.nearestDesc(i.node,!0);return!n||n===o?null:n.posBefore}return null}function dn(e,t){let i,o;const n=t.resolve(e.from).node().type.spec.group==="blockContent",r=t.resolve(e.to).node().type.spec.group==="blockContent",a=Math.min(e.$anchor.depth,e.$head.depth);if(n&&r){const s=e.$from.start(a-1),l=e.$to.end(a-1);i=t.resolve(s-1).pos,o=t.resolve(l+1).pos}else i=e.from,o=e.to;return{from:i,to:o}}function Yt(e,t,i=t){t===i&&(i+=e.state.doc.resolve(t+1).node().nodeSize);const o=e.domAtPos(t).node.cloneNode(!0),n=e.domAtPos(t).node,r=(p,h)=>Array.prototype.indexOf.call(p.children,h),a=r(n,e.domAtPos(t+1).node.parentElement),s=r(n,e.domAtPos(i-1).node.parentElement);for(let p=n.childElementCount-1;p>=0;p--)(p>s||p<a)&&o.removeChild(o.children[p]);Qt(e.root),P=o;const c=e.dom.className.split(" ").filter(p=>p!=="ProseMirror"&&p!=="bn-root"&&p!=="bn-editor").join(" ");P.className=P.className+" bn-drag-preview "+c,e.root instanceof ShadowRoot?e.root.appendChild(P):e.root.body.appendChild(P)}function Qt(e){P!==void 0&&(e instanceof ShadowRoot?e.removeChild(P):e.body.removeChild(P),P=void 0)}function cn(e,t){if(!e.dataTransfer)return;const i=t.prosemirrorView,o=i.dom.getBoundingClientRect(),n={left:o.left+o.width/2,top:e.clientY},r=i.root.elementsFromPoint(n.left,n.top);let a;for(const l of r)if(i.dom.contains(l)){a=re(l,i);break}if(!a)return;const s=ln(a.node,i);if(s!=null){const l=i.state.selection,c=i.state.doc,{from:p,to:h}=dn(l,c),m=p<=s&&s<h,g=l.$anchor.node()!==l.$head.node()||l instanceof Z;m&&g?(i.dispatch(i.state.tr.setSelection(Z.create(c,p,h))),Yt(i,p,h)):(i.dispatch(i.state.tr.setSelection(_.NodeSelection.create(i.state.doc,s))),Yt(i,s));const f=i.state.selection.content(),k=t._tiptapEditor.schema,j=_e(k,t).serializeProseMirrorFragment(f.content),z=Y(k,t).exportProseMirrorFragment(f.content),ae=He(z);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",j),e.dataTransfer.setData("text/html",z),e.dataTransfer.setData("text/plain",ae),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(P,0,0),i.dragging={slice:f,move:!0}}}class ei{constructor(t,i,o){u(this,"state");u(this,"emitUpdate");u(this,"needUpdate",!1);u(this,"mousePos");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"updateState",()=>{var a,s,l,c;if(this.menuFrozen||!this.mousePos)return;const t=this.pmView.dom.firstChild.getBoundingClientRect();this.horizontalPosAnchor=t.x;const i={left:t.left+t.width/2,top:this.mousePos.y},o=this.pmView.root.elementsFromPoint(i.left,i.top);let n;for(const p of o)if(this.pmView.dom.contains(p)){n=re(p,this.pmView);break}if(!n||!this.editor.isEditable){(a=this.state)!=null&&a.show&&(this.state.show=!1,this.needUpdate=!0);return}if((s=this.state)!=null&&s.show&&((l=this.hoveredBlock)!=null&&l.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===n.id)return;this.hoveredBlock=n.node;const r=n.node.firstChild;if(r&&this.editor.isEditable){const p=r.getBoundingClientRect();this.state={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:p.x,p.y,p.width,p.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.needUpdate=!0}});u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const i=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!i||i.inside===-1){const o=new Event("drop",t),n=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=n.left+n.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const i=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!i||i.inside===-1){const o=new Event("dragover",t),n=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=n.left+n.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});u(this,"onKeyDown",t=>{var i;(i=this.state)!=null&&i.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state),this.menuFrozen=!1)});u(this,"onMouseDown",()=>{this.state&&this.state.show&&this.menuFrozen&&(this.menuFrozen=!1,this.state.show=!1,this.emitUpdate(this.state))});u(this,"onMouseMove",t=>{var r;this.mousePos={x:t.clientX,y:t.clientY};const i=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>i.left&&this.mousePos.x<i.right&&this.mousePos.y>i.top&&this.mousePos.y<i.bottom,n=this.pmView.dom.parentElement;if(o&&t&&t.target&&!(n===t.target||n.contains(t.target))){(r=this.state)!=null&&r.show&&(this.state.show=!1,this.emitUpdate(this.state));return}this.updateState(),this.needUpdate&&(this.emitUpdate(this.state),this.needUpdate=!1)});u(this,"onScroll",()=>{var t;if((t=this.state)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.state.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.emitUpdate(this.state)}});this.editor=t,this.pmView=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");o(this.state)},this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.dom.addEventListener("mousedown",this.onMouseDown),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),this.pmView.root.addEventListener("scroll",this.onScroll,!0)}update(){var i;const t=(i=this.state)==null?void 0:i.block.id;this.updateState(),this.needUpdate&&this.state&&t!==this.state.block.id&&(this.emitUpdate(this.state),this.needUpdate=!1)}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("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0),this.pmView.dom.removeEventListener("mousedown",this.onMouseDown),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.state)!=null&&l.show&&(this.state.show=!1,this.emitUpdate(this.state));const i=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:i.left+i.width/2,top:i.top+i.height/2});if(!o)return;const n=v(this.editor._tiptapEditor.state.doc,o.pos);if(n===void 0)return;const{contentNode:r,startPos:a,endPos:s}=n;if(r.type.spec.content!=="inline*"||r.textContent.length!==0){const c=s+1,p=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).setTextSelection(p).run()}else this.editor._tiptapEditor.commands.setTextSelection(a+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(V,{triggerCharacter:"/",fromUserInput:!1}))}}const ti=new _.PluginKey("SideMenuPlugin");class ii extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"addBlock",()=>this.view.addBlock());u(this,"blockDragStart",i=>{this.view.isDragging=!0,cn(i,this.editor)});u(this,"blockDragEnd",()=>Qt(this.editor.prosemirrorView.root));u(this,"freezeMenu",()=>this.view.menuFrozen=!0);u(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)});this.editor=i,this.plugin=new _.Plugin({key:ti,view:o=>(this.view=new ei(i,o,n=>{this.emit("update",n)}),this.view)})}onUpdate(i){return this.on("update",i)}}let S;function oi(e){S||(S=document.createElement("div"),S.innerHTML="_",S.style.opacity="0",S.style.height="1px",S.style.width="1px",e instanceof Document?e.body.appendChild(S):e.appendChild(S))}function un(e){S&&(e instanceof Document?e.body.removeChild(S):e.removeChild(S),S=void 0)}function ce(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}function pn(e){for(;e&&e.nodeName!=="TD"&&e.nodeName!=="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function hn(e,t){e.forEach(i=>{const o=t.querySelectorAll(i);for(let n=0;n<o.length;n++)o[n].style.visibility="hidden"})}class ni{constructor(t,i,o){u(this,"state");u(this,"emitUpdate");u(this,"tableId");u(this,"tablePos");u(this,"menuFrozen",!1);u(this,"prevWasEditable",null);u(this,"mouseMoveHandler",t=>{var c;if(this.menuFrozen)return;const i=pn(t.target);if(!i||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.emitUpdate());return}const o=ce(i),n=ce(i.parentElement),r=i.getBoundingClientRect(),a=i.parentElement.parentElement.getBoundingClientRect(),s=re(i,this.pmView);if(!s)return;let l;if(this.editor._tiptapEditor.state.doc.descendants((p,h)=>{if(typeof l<"u")return!1;if(p.type.name!=="blockContainer"||p.attrs.id!==s.id)return!0;const m=x(p,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema,this.editor.blockCache);return Rt("table",m,this.editor)&&(this.tablePos=h+1,l=m),!1}),!!l&&(this.tableId=s.id,!(this.state!==void 0&&this.state.show&&this.tableId===s.id&&this.state.rowIndex===n&&this.state.colIndex===o)))return this.state={show:!0,referencePosCell:r,referencePosTable:a,block:l,colIndex:o,rowIndex:n,draggingState:void 0},this.emitUpdate(),!1});u(this,"dragOverHandler",t=>{var m;if(((m=this.state)==null?void 0:m.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",hn(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"],this.pmView.root);const i={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(i.left,i.top).filter(g=>g.tagName==="TD"||g.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const n=o[0];let r=!1;const a=ce(n.parentElement),s=ce(n),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,p=(this.state.draggingState.draggedCellOrientation==="row"?a:s)!==l;(this.state.rowIndex!==a||this.state.colIndex!==s)&&(this.state.rowIndex=a,this.state.colIndex=s,this.state.referencePosCell=n.getBoundingClientRect(),r=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?i.top:i.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,r=!0),r&&this.emitUpdate(),p&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});u(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const i=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=i[this.state.draggingState.originalIndex];i.splice(this.state.draggingState.originalIndex,1),i.splice(this.state.rowIndex,0,o)}else{const o=i.map(n=>n.cells[this.state.draggingState.originalIndex]);i.forEach((n,r)=>{n.cells.splice(this.state.draggingState.originalIndex,1),n.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:i}})});u(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const i=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=i.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=i.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.emitUpdate()}});this.editor=t,this.pmView=i,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},i.dom.addEventListener("mousemove",this.mouseMoveHandler),i.root.addEventListener("dragover",this.dragOverHandler),i.root.addEventListener("drop",this.dropHandler),i.root.addEventListener("scroll",this.scrollHandler,!0)}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const J=new _.PluginKey("TableHandlesPlugin");class ri extends X{constructor(i){super();u(this,"view");u(this,"plugin");u(this,"colDragStart",i=>{if(this.view.state===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:i.clientX},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),oi(this.editor._tiptapEditor.view.root),i.dataTransfer.setDragImage(S,0,0),i.dataTransfer.effectAllowed="move"});u(this,"rowDragStart",i=>{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={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:i.clientY},this.view.emitUpdate(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),oi(this.editor._tiptapEditor.view.root),i.dataTransfer.setDragImage(S,0,0),i.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._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),un(this.editor._tiptapEditor.view.root)});u(this,"freezeHandles",()=>{this.view.menuFrozen=!0});u(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1});this.editor=i,this.plugin=new _.Plugin({key:J,view:o=>(this.view=new ni(i,o,n=>{this.emit("update",n)}),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 n=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(n===this.view.state.draggingState.originalIndex)return M.DecorationSet.create(o.doc,r);const a=o.doc.resolve(this.view.tablePos+1),s=a.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(a.posAtIndex(n)+1),c=l.node();for(let p=0;p<c.childCount;p++){const h=o.doc.resolve(l.posAtIndex(p)+1),m=h.node(),g=h.pos+(n>this.view.state.draggingState.originalIndex?m.nodeSize-2:0);r.push(M.Decoration.widget(g,()=>{const f=document.createElement("div");return f.className="bn-table-drop-cursor",f.style.left="0",f.style.right="0",n>this.view.state.draggingState.originalIndex?f.style.bottom="-2px":f.style.top="-3px",f.style.height="4px",f}))}}else for(let l=0;l<s.childCount;l++){const c=o.doc.resolve(a.posAtIndex(l)+1),p=o.doc.resolve(c.posAtIndex(n)+1),h=p.node(),m=p.pos+(n>this.view.state.draggingState.originalIndex?h.nodeSize-2:0);r.push(M.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.top="0",g.style.bottom="0",n>this.view.state.draggingState.originalIndex?g.style.right="-2px":g.style.left="-3px",g.style.width="4px",g}))}return M.DecorationSet.create(o.doc,r)}}})}onUpdate(i){return this.on("update",i)}}function ai(e,t){const i=e.state.selection.content().content,n=_e(e.state.schema,t).serializeProseMirrorFragment(i),a=Y(e.state.schema,t).exportProseMirrorFragment(i),s=He(a);return{internalHTML:n,externalHTML:a,plainText:s}}const mn=e=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new _.Plugin({props:{handleDOMEvents:{copy(t,i){i.preventDefault(),i.clipboardData.clearData(),"node"in t.state.selection&&t.state.selection.node.type.spec.group==="blockContent"&&t.dispatch(t.state.tr.setSelection(new _.NodeSelection(t.state.doc.resolve(t.state.selection.from-1))));const{internalHTML:o,externalHTML:n,plainText:r}=ai(t,e);return i.clipboardData.setData("blocknote/html",o),i.clipboardData.setData("text/html",n),i.clipboardData.setData("text/plain",r),!0},dragstart(t,i){if(!("node"in t.state.selection)||t.state.selection.node.type.spec.group!=="blockContent")return;t.dispatch(t.state.tr.setSelection(new _.NodeSelection(t.state.doc.resolve(t.state.selection.from-1)))),i.preventDefault(),i.dataTransfer.clearData();const{internalHTML:o,externalHTML:n,plainText:r}=ai(t,e);return i.dataTransfer.setData("blocknote/html",o),i.dataTransfer.setData("text/html",n),i.dataTransfer.setData("text/plain",r),!0}}}})]}});function fn(e){let t=e.getTextCursorPosition().block,i=e.schema.blockSchema[t.type].content;for(;i==="none";)t=e.getTextCursorPosition().nextBlock,i=e.schema.blockSchema[t.type].content,e.setTextCursorPosition(t,"end")}function T(e,t){const i=e.getTextCursorPosition().block;if(i.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(i.content)&&(i.content.length===1&&$(i.content[0])&&i.content[0].type==="text"&&i.content[0].text==="/"||i.content.length===0)?e.updateBlock(i,t):(e.insertBlocks([t],i,"after"),e.setTextCursorPosition(e.getTextCursorPosition().nextBlock,"end"));const o=e.getTextCursorPosition().block;return fn(e),o}function gn(e){const t=[];return B("heading",e)&&t.push({onItemClick:()=>{T(e,{type:"heading",props:{level:1}})},badge:H("Mod-Alt-1"),key:"heading",...e.dictionary.slash_menu.heading},{onItemClick:()=>{T(e,{type:"heading",props:{level:2}})},badge:H("Mod-Alt-2"),key:"heading_2",...e.dictionary.slash_menu.heading_2},{onItemClick:()=>{T(e,{type:"heading",props:{level:3}})},badge:H("Mod-Alt-3"),key:"heading_3",...e.dictionary.slash_menu.heading_3}),B("numberedListItem",e)&&t.push({onItemClick:()=>{T(e,{type:"numberedListItem"})},badge:H("Mod-Shift-7"),key:"numbered_list",...e.dictionary.slash_menu.numbered_list}),B("bulletListItem",e)&&t.push({onItemClick:()=>{T(e,{type:"bulletListItem"})},badge:H("Mod-Shift-8"),key:"bullet_list",...e.dictionary.slash_menu.bullet_list}),B("checkListItem",e)&&t.push({onItemClick:()=>{T(e,{type:"checkListItem"})},badge:H("Mod-Shift-9"),key:"check_list",...e.dictionary.slash_menu.check_list}),B("paragraph",e)&&t.push({onItemClick:()=>{T(e,{type:"paragraph"})},badge:H("Mod-Alt-0"),key:"paragraph",...e.dictionary.slash_menu.paragraph}),B("table",e)&&t.push({onItemClick:()=>{T(e,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})},badge:void 0,key:"table",...e.dictionary.slash_menu.table}),B("image",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"image"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"image",...e.dictionary.slash_menu.image}),B("video",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"video"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"video",...e.dictionary.slash_menu.video}),B("audio",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"audio"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"audio",...e.dictionary.slash_menu.audio}),B("file",e)&&t.push({onItemClick:()=>{const i=T(e,{type:"file"});e.prosemirrorView.dispatch(e._tiptapEditor.state.tr.setMeta(e.filePanel.plugin,{block:i}))},key:"image",...e.dictionary.slash_menu.file}),t}function bn(e,t){return e.filter(({title:i,aliases:o})=>i.toLowerCase().includes(t.toLowerCase())||o&&o.filter(n=>n.toLowerCase().includes(t.toLowerCase())).length!==0)}const De=["blocknote/html","Files","text/html","text/plain"];function kn(e,t){const i=e.split("/"),o=t.split("/");if(i.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);if(o.length!==2)throw new Error(`The string ${t} is not a valid MIME type.`);return i[1]==="*"||o[1]==="*"?i[0]===o[0]:(i[0]==="*"||o[0]==="*"||i[0]===o[0])&&i[1]===o[1]}async function si(e,t){if(!t.uploadFile)return;const i="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(i===null)return;let o=null;for(const a of De)if(i.types.includes(a)){o=a;break}if(o!=="Files")return;const n=i.items;if(!n)return;e.preventDefault();const r=Object.values(t.schema.blockSchema).filter(a=>a.isFileBlock);for(let a=0;a<n.length;a++){let s="file";for(const c of r)for(const p of c.fileBlockAcceptMimeTypes||[])if(kn(n[a].type,p)){s=c.type;break}const l=n[a].getAsFile();if(l){const c=await t.uploadFile(l);if(typeof c=="string"){const p={type:s,props:{name:l.name,url:c}};T(t,p)}}}}const _n=e=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new _.Plugin({props:{handleDOMEvents:{paste(t,i){if(i.preventDefault(),!e.isEditable)return;let o=null;for(const r of De)if(i.clipboardData.types.includes(r)){o=r;break}if(o===null)return!0;if(o==="Files")return si(i,e),!0;let n=i.clipboardData.getData(o);return o==="text/html"&&(n=zt(n.trim()).innerHTML),e._tiptapEditor.view.pasteHTML(n),!0}}}})]}}),yn=e=>b.Extension.create({name:"dropFile",addProseMirrorPlugins(){return[new _.Plugin({props:{handleDOMEvents:{drop(t,i){if(!e.isEditable)return;let o=null;for(const n of De)if(i.dataTransfer.types.includes(n)){o=n;break}return o===null?!0:o==="Files"?(si(i,e),!0):!1}}}})]}}),wn=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:E.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):E.backgroundColor.default,renderHTML:e=>e.backgroundColor!==E.backgroundColor.default&&{"data-background-color":e.backgroundColor}}}}]}}),vn=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>e.textAlignment!=="left"&&{"data-text-alignment":e.textAlignment}}}}]}}),En=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:E.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):E.textColor.default,renderHTML:e=>e.textColor!==E.textColor.default&&{"data-text-color":e.textColor}}}}]}}),xn=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const e=new _.PluginKey(this.name);return[new _.Plugin({key:e,appendTransaction:(t,i,o)=>{const{doc:n,tr:r,schema:a}=o,s=e.getState(o),l=n.content.size-2,c=a.nodes.blockContainer,p=a.nodes.paragraph;if(s)return r.insert(l,c.create(void 0,p.create()))},state:{init:(t,i)=>{},apply:(t,i)=>{if(!t.docChanged)return i;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")throw new Error("Expected blockContainer");const n=o.firstChild;if(!n)throw new Error("Expected blockContent");return o.nodeSize>4||n.type.spec.content!=="inline*"}}})]}}),Cn=new _.PluginKey("non-editable-block"),Sn=()=>new _.Plugin({key:Cn,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"){const i=e.state.tr;return e.dispatch(i.insert(e.state.tr.selection.$to.after(),e.state.schema.nodes.paragraph.create()).setSelection(new _.TextSelection(i.doc.resolve(e.state.tr.selection.$to.after()+1)))),!0}}return!1}}}),li=new _.PluginKey("previous-blocks"),Tn={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Mn=()=>{let e;return new _.Plugin({key:li,view(t){return{update:async(i,o)=>{var n;((n=this.key)==null?void 0:n.getState(i.state).updatedBlocks.size)>0&&(e=setTimeout(()=>{i.dispatch(i.state.tr.setMeta(li,{clearUpdate:!0}))},0))},destroy:()=>{e&&clearTimeout(e)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,i,o,n){if(i.currentTransactionOldBlockAttrs={},i.updatedBlocks.clear(),!t.docChanged||o.doc.eq(n.doc))return i;const r={},a=b.findChildren(o.doc,c=>c.attrs.id),s=new Map(a.map(c=>[c.node.attrs.id,c])),l=b.findChildren(n.doc,c=>c.attrs.id);for(const c of l){const p=s.get(c.node.attrs.id),h=p==null?void 0:p.node.firstChild,m=c.node.firstChild;if(p&&h&&m){const g={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:n.doc.resolve(c.pos).depth};let f={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(p.pos).depth};r[c.node.attrs.id]=f,t.getMeta("numberedListIndexing")&&(c.node.attrs.id in i.prevTransactionOldBlockAttrs&&(f=i.prevTransactionOldBlockAttrs[c.node.attrs.id]),g.type==="numberedListItem"&&(f.index=g.index)),i.currentTransactionOldBlockAttrs[c.node.attrs.id]=f,JSON.stringify(f)!==JSON.stringify(g)&&(f["depth-change"]=f.depth-g.depth,i.updatedBlocks.add(c.node.attrs.id))}}return i.prevTransactionOldBlockAttrs=r,i}},props:{decorations(t){const i=this.getState(t);if(i.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((n,r)=>{if(!n.attrs.id||!i.updatedBlocks.has(n.attrs.id))return;const a=i.currentTransactionOldBlockAttrs[n.attrs.id],s={};for(const[c,p]of Object.entries(a))s["data-prev-"+Tn[c]]=p||"none";const l=M.Decoration.node(r,r+n.nodeSize,{...s});o.push(l)}),M.DecorationSet.create(t.doc,o)}}})},Bn={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ln=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:e=>{if(typeof e=="string")return!1;const t={};for(const[i,o]of Object.entries(Bn))e.getAttribute(o)&&(t[i]=e.getAttribute(o));return e.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:e}){var n;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,a]of Object.entries(e))r!=="class"&&t.setAttribute(r,a);const i={...((n=this.options.domAttributes)==null?void 0:n.block)||{},...e},o=document.createElement("div");o.className=U("bn-block",i.class),o.setAttribute("data-node-type",this.name);for(const[r,a]of Object.entries(i))r!=="class"&&o.setAttribute(r,a);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:e=>({state:t,dispatch:i})=>{const o=t.schema.nodes.blockContainer.createAndFill();return i&&t.tr.insert(e,o).scrollIntoView(),!0},BNDeleteBlock:e=>({state:t,dispatch:i})=>{const o=v(t.doc,e);if(o===void 0)return!1;const{startPos:n,endPos:r}=o;return i&&t.tr.deleteRange(n,r),!0},BNUpdateBlock:(e,t)=>({state:i,dispatch:o})=>{const n=v(i.doc,e);if(n===void 0)return!1;const{startPos:r,endPos:a,node:s,contentNode:l}=n;if(o){if(t.children!==void 0){const m=[];for(const g of t.children)m.push(N(g,i.schema,this.options.editor.schema.styleSchema));s.childCount===2?i.tr.replace(r+l.nodeSize+1,a-1,new y.Slice(y.Fragment.from(m),0,0)):i.tr.insert(r+l.nodeSize,i.schema.nodes.blockGroup.create({},m))}const c=l.type.name,p=t.type||c;let h="keep";if(t.content)if(typeof t.content=="string")h=K([t.content],i.schema,this.options.editor.schema.styleSchema);else if(Array.isArray(t.content))h=K(t.content,i.schema,this.options.editor.schema.styleSchema);else if(t.content.type==="tableContent")h=be(t.content,i.schema,this.options.editor.schema.styleSchema);else throw new I(t.content.type);else{const m=i.schema.nodes[c].spec.content,g=i.schema.nodes[p].spec.content;m===""||g!==m&&(h=[])}h==="keep"?i.tr.setNodeMarkup(r,t.type===void 0?void 0:i.schema.nodes[t.type],{...l.attrs,...t.props}):i.tr.replaceWith(r,a,i.schema.nodes[p].create({...l.attrs,...t.props},h)).setSelection(i.schema.nodes[p].spec.content===""?new _.NodeSelection(i.tr.doc.resolve(r)):i.schema.nodes[p].spec.content==="inline*"?new _.TextSelection(i.tr.doc.resolve(r)):new _.TextSelection(i.tr.doc.resolve(r+4))),i.tr.setNodeMarkup(r-1,void 0,{...s.attrs,...t.props})}return!0},BNMergeBlocks:e=>({state:t,dispatch:i})=>{const o=t.doc.resolve(e+1).node().type.name==="blockContainer",n=t.doc.resolve(e-1).node().type.name==="blockContainer";if(!o||!n)return!1;const r=v(t.doc,e+1),{node:a,contentNode:s,startPos:l,endPos:c,depth:p}=r;if(a.childCount===2){const g=t.doc.resolve(l+s.nodeSize+1),f=t.doc.resolve(c-1),k=g.blockRange(f);i&&t.tr.lift(k,p-1)}let h=e-1,m=v(t.doc,h);for(;m.numChildBlocks>0;)if(h--,m=v(t.doc,h),m===void 0)return!1;return i&&(i(t.tr.deleteRange(l,l+s.nodeSize).replace(h-1,l,new y.Slice(s.content,0,0)).scrollIntoView()),t.tr.setSelection(new _.TextSelection(t.doc.resolve(h-1)))),!0},BNSplitBlock:(e,t,i)=>({state:o,dispatch:n})=>{const r=v(o.doc,e);if(r===void 0)return!1;const{contentNode:a,contentType:s,startPos:l,endPos:c,depth:p}=r,h=o.doc.cut(l+1,e),m=o.doc.cut(e,c-1),g=o.schema.nodes.blockContainer.createAndFill(),f=c+1,k=f+2;return n&&(o.tr.insert(f,g),o.tr.replace(k,k+1,m.content.size>0?new y.Slice(y.Fragment.from(m),p+2,p+2):void 0),t&&o.tr.setBlockType(k,k,o.schema.node(s).type,i?a.attrs:void 0),o.tr.setSelection(new _.TextSelection(o.doc.resolve(k))),o.tr.replace(l+1,c-1,h.content.size>0?new y.Slice(y.Fragment.from(h),p+2,p+2):void 0),o.tr.scrollIntoView()),!0}}},addProseMirrorPlugins(){return[Mn(),Sn()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:n})=>{const{contentType:r,startPos:a}=v(n.doc,n.selection.from),s=n.selection.from===a+1,l=r.name==="paragraph";return s&&!l?o.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:n})=>{const{startPos:r}=v(n.doc,n.selection.from);return n.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:n})=>{const{depth:r,startPos:a}=v(n.doc,n.selection.from),s=n.selection.from===a+1,l=n.selection.empty,c=a===2,p=a-1;return!c&&s&&l&&r===2?o.BNMergeBlocks(p):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:n})=>{const{node:r,depth:a,endPos:s}=v(n.doc,n.selection.from),l=s===n.doc.nodeSize-4,c=n.selection.from===s-1,p=n.selection.empty,h=r.childCount===2;if(!l&&c&&p&&!h){let m=a,g=s+2,f=n.doc.resolve(g).depth;for(;f<m;)m=f,g+=2,f=n.doc.resolve(g).depth;return o.BNMergeBlocks(g-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:n})=>{const{contentNode:r,depth:a}=v(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,c=r.childCount===0,p=a>2;return s&&l&&c&&p?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:n,chain:r})=>{const{contentNode:a,endPos:s}=v(n.doc,n.selection.from),l=n.selection.$anchor.parentOffset===0,c=n.selection.anchor===n.selection.head,p=a.childCount===0;if(l&&c&&p){const h=s+1,m=h+2;return r().BNCreateBlock(h).setTextSelection(m).run(),!0}return!1}),()=>o.command(({state:n,chain:r})=>{const{contentNode:a}=v(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0;return a.childCount===0?!1:(r().deleteSelection().BNSplitBlock(n.selection.from,s,s).run(),!0)})]),Tab:()=>{var o,n,r;return(o=this.options.editor.formattingToolbar)!=null&&o.shown||(n=this.options.editor.linkToolbar)!=null&&n.shown||(r=this.options.editor.filePanel)!=null&&r.shown?!1:(this.editor.commands.sinkListItem("blockContainer"),!0)},"Shift-Tab":()=>{var o,n,r;return(o=this.options.editor.formattingToolbar)!=null&&o.shown||(n=this.options.editor.linkToolbar)!=null&&n.shown||(r=this.options.editor.filePanel)!=null&&r.shown?!1:(this.editor.commands.liftListItem("blockContainer"),!0)}}}}),In=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:e=>typeof e=="string"?!1:e.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:e}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...e},i=document.createElement("div");i.className=U("bn-block-group",t.class),i.setAttribute("data-node-type","blockGroup");for(const[n,r]of Object.entries(t))n!=="class"&&i.setAttribute(n,r);return{dom:i,contentDOM:i}}}),Pn=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),di=e=>{var o;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Ai.Gapcursor,W.configure({types:["blockContainer"]}),Ni.HardBreak.extend({priority:10}),Di.Text,Ui.Link.extend({addKeyboardShortcuts(){return{"Mod-k":()=>(this.editor.commands.toggleLink({href:""}),!0)}}}),...Object.values(e.styleSpecs).map(n=>n.implementation.mark),En,wn,vn,b.Extension.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>e.editor.suggestionMenus.shown?!1:this.editor.commands.blur()}}}),Pn,Ln.configure({editor:e.editor,domAttributes:e.domAttributes}),In.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(n=>n.config!=="link"&&n.config!=="text").map(n=>n.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(n=>[...(n.implementation.requiredExtensions||[]).map(r=>r.configure({editor:e.editor,domAttributes:e.domAttributes})),n.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),mn(e.editor),_n(e.editor),yn(e.editor),Pi.Dropcursor.configure({width:5,color:"#ddeeff"}),...e.trailingBlock===void 0||e.trailingBlock?[xn]:[]];if(e.collaboration){if(t.push(Wi.default.configure({fragment:e.collaboration.fragment})),(o=e.collaboration.provider)!=null&&o.awareness){const n=r=>{const a=document.createElement("span");a.classList.add("collaboration-cursor__caret"),a.setAttribute("style",`border-color: ${r.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${r.color}`),s.insertBefore(document.createTextNode(r.name),null);const l=document.createTextNode(""),c=document.createTextNode("");return a.insertBefore(l,null),a.insertBefore(s,null),a.insertBefore(c,null),a};t.push($i.default.configure({user:e.collaboration.user,render:e.collaboration.renderCursor||n,provider:e.collaboration.provider}))}}else t.push(Hi.History);const i=e.disableExtensions||[];return t.filter(n=>!i.includes(n.name))};function An(e,t){const i=[];return e.forEach((o,n,r)=>{r!==t&&i.push(o)}),y.Fragment.from(i)}function Nn(e,t){let i=y.Fragment.from(e.content);for(let o=0;o<i.childCount;o++)if(i.child(o).type.spec.group==="blockContent"){const n=[i.child(o)];if(o+1<i.childCount&&i.child(o+1).type.spec.group==="blockGroup"){const a=i.child(o+1).child(0).child(0);(a.type.name==="bulletListItem"||a.type.name==="numberedListItem"||a.type.name==="checkListItem")&&(n.push(i.child(o+1)),i=An(i,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,n);i=i.replaceChild(o,r)}return new y.Slice(i,e.openStart,e.openEnd)}function Re(e){return e&&Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}class ue{constructor(t){u(this,"blockSpecs");u(this,"inlineContentSpecs");u(this,"styleSpecs");u(this,"blockSchema");u(this,"inlineContentSchema");u(this,"styleSchema");u(this,"BlockNoteEditor","only for types");u(this,"Block","only for types");u(this,"PartialBlock","only for types");this.blockSpecs=Re(t==null?void 0:t.blockSpecs)||Ie,this.inlineContentSpecs=Re(t==null?void 0:t.inlineContentSpecs)||Ae,this.styleSpecs=Re(t==null?void 0:t.styleSpecs)||Pe,this.blockSchema=Ee(this.blockSpecs),this.inlineContentSchema=xe(this.inlineContentSpecs),this.styleSchema=Se(this.styleSpecs)}static create(t){return new ue(t)}}class Hn extends b.Editor{constructor(i,o){super({...i,content:void 0});u(this,"_state");u(this,"mount",i=>{i?(this.options.element=i,this.createViewAlternative()):this.destroy()});const n=this.schema;let r;const a=n.nodes.doc.createAndFill;n.nodes.doc.createAndFill=(...l)=>{if(r)return r;const c=a.apply(n.nodes.doc,l),p=JSON.parse(JSON.stringify(c.toJSON()));return p.content[0].content[0].attrs.id="initialBlockId",r=y.Node.fromJSON(n,p),r};let s;try{const l=i==null?void 0:i.content.map(c=>N(c,this.schema,o).toJSON());s=b.createDocument({type:"doc",content:[{type:"blockGroup",content:l}]},this.schema,this.options.parseOptions)}catch(l){throw console.error("Error creating document from blocks passed as `initialContent`. Caused by exception: ",l),new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(i.content))}this._state=_.EditorState.create({doc:s,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}createView(){}createViewAlternative(){queueMicrotask(()=>{this.view=new M.EditorView({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:this.state});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.createNodeViews()})}}const Un=new _.PluginKey("blocknote-placeholder"),Dn=(e,t)=>new _.Plugin({key:Un,view:()=>{const i=document.createElement("style"),o=e._tiptapEditor.options.injectNonce;o&&i.setAttribute("nonce",o),e._tiptapEditor.view.root instanceof ShadowRoot?e._tiptapEditor.view.root.append(i):e._tiptapEditor.view.root.head.appendChild(i);const n=i.sheet,r=(s="")=>`.bn-block-content${s} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`,a=(s,l=!0)=>{const c=l?"[data-is-empty-and-focused]":"";if(s==="default")return r(c);const p=`[data-content-type="${s}"]`;return r(c+p)};for(const[s,l]of Object.entries(t)){const c=s==="default";n.insertRule(`${a(s,c)}{ content: ${JSON.stringify(l)}; }`),c||n.insertRule(`${a(s,!0)}{ content: ${JSON.stringify(l)}; }`)}return{destroy:()=>{e._tiptapEditor.view.root instanceof ShadowRoot?e._tiptapEditor.view.root.removeChild(i):e._tiptapEditor.view.root.head.removeChild(i)}}},props:{decorations:i=>{const{doc:o,selection:n}=i;if(!e.isEditable||!n.empty)return;const r=n.$anchor,a=r.parent;if(a.content.size>0)return null;const s=r.before(),l=M.Decoration.node(s,s+a.nodeSize,{"data-is-empty-and-focused":"true"});return M.DecorationSet.create(o,[l])}}}),Qn="",er="",Rn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Oe{constructor(t){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"dictionary");u(this,"schema");u(this,"blockImplementations");u(this,"inlineContentImplementations");u(this,"styleImplementations");u(this,"formattingToolbar");u(this,"linkToolbar");u(this,"sideMenu");u(this,"suggestionMenus");u(this,"filePanel");u(this,"tableHandles");u(this,"uploadFile");u(this,"resolveFileUrl");var l,c,p,h,m,g,f;this.options=t;const i=t;if(i.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(i.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(i.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(i.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=t.dictionary||We;const o={defaultStyles:!0,schema:t.schema||ue.create(),...t,placeholders:{...this.dictionary.placeholders,...t.placeholders}};this.schema=o.schema,this.blockImplementations=o.schema.blockSpecs,this.inlineContentImplementations=o.schema.inlineContentSpecs,this.styleImplementations=o.schema.styleSpecs,this.formattingToolbar=new $t(this),this.linkToolbar=new Zt(this),this.sideMenu=new ii(this),this.suggestionMenus=new Jt(this),this.filePanel=new qt(this),B("table",this)&&(this.tableHandles=new ri(this));const n=di({editor:this,domAttributes:o.domAttributes||{},blockSchema:this.schema.blockSchema,blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:o.collaboration,trailingBlock:o.trailingBlock,disableExtensions:o.disableExtensions}),r=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.formattingToolbar.plugin,this.linkToolbar.plugin,this.sideMenu.plugin,this.suggestionMenus.plugin,...this.filePanel?[this.filePanel.plugin]:[],...this.tableHandles?[this.tableHandles.plugin]:[],Dn(this,o.placeholders)]});n.push(r),this.uploadFile=o.uploadFile,this.resolveFileUrl=o.resolveFileUrl||(async k=>k),o.collaboration&&o.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const a=o.initialContent||(t.collaboration?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:W.options.generateID()}]);if(!Array.isArray(a)||a.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+a);const s={...Rn,...o._tiptapOptions,content:a,extensions:[...((l=o._tiptapOptions)==null?void 0:l.extensions)||[],...n],editorProps:{...(c=o._tiptapOptions)==null?void 0:c.editorProps,attributes:{...(h=(p=o._tiptapOptions)==null?void 0:p.editorProps)==null?void 0:h.attributes,...(m=o.domAttributes)==null?void 0:m.editor,class:U("bn-editor",o.defaultStyles?"bn-default-styles":"",((f=(g=o.domAttributes)==null?void 0:g.editor)==null?void 0:f.class)||"")},transformPasted:Nn}};this._tiptapEditor=new Hn(s,this.schema.styleSchema)}static create(t={}){return new Oe(t)}mount(t){this._tiptapEditor.mount(t)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){return this.topLevelBlocks}get document(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(i=>(t.push(x(i,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),t}getBlock(t){const i=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(n=>typeof o<"u"?!1:n.type.name!=="blockContainer"||n.attrs.id!==i?!0:(o=x(n,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),!1)),o}forEachBlock(t,i=!1){const o=this.document.slice();i&&o.reverse();function n(r){for(const a of r){if(!t(a))return!1;const s=i?a.children.slice().reverse():a.children;if(!n(s))return!1}return!0}n(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:i,startPos:o,endPos:n}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(n).index(i-1),a=this._tiptapEditor.state.doc.resolve(n+1).node().childCount;let s;r>0&&(s=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<a-1&&(l=this._tiptapEditor.state.doc.resolve(n+2).node()),{block:x(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),prevBlock:s===void 0?void 0:x(s,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:x(l,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)}}setTextCursorPosition(t,i="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:n}=Ne(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:a}=v(this._tiptapEditor.state.doc,n+2),s=this.schema.blockSchema[a.type.name].content;if(s==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(s==="inline")i==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+a.nodeSize-1);else if(s==="table")i==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+a.nodeSize-4);else throw new I(s)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const t=[];return this._tiptapEditor.state.doc.descendants((i,o)=>i.type.spec.group!=="blockContent"||o+i.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(x(this._tiptapEditor.state.doc.resolve(o).node(),this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.options.editable!==t&&this._tiptapEditor.setEditable(t)}insertBlocks(t,i,o="before"){return zo(t,i,o,this)}updateBlock(t,i){return Fo(t,i,this)}removeBlocks(t){return Ko(t,this)}replaceBlocks(t,i){return qo(t,i,this)}insertInlineContent(t){const i=K(t,this._tiptapEditor.schema,this.schema.styleSchema);Go({from:this._tiptapEditor.state.selection.from,to:this._tiptapEditor.state.selection.to},i,this)}getActiveStyles(){const t={},i=this._tiptapEditor.state.selection.$to.marks();for(const o of i){const n=this.schema.styleSchema[o.type.name];if(!n){o.type.name!=="link"&&console.warn("mark not found in styleschema",o.type.name);continue}n.propSchema==="boolean"?t[n.type]=!0:t[n.type]=o.attrs.stringValue}return t}addStyles(t){for(const[i,o]of Object.entries(t)){const n=this.schema.styleSchema[i];if(!n)throw new Error(`style ${i} not found in styleSchema`);if(n.propSchema==="boolean")this._tiptapEditor.commands.setMark(i);else if(n.propSchema==="string")this._tiptapEditor.commands.setMark(i,{stringValue:o});else throw new I(n.propSchema)}}removeStyles(t){for(const i of Object.keys(t))this._tiptapEditor.commands.unsetMark(i)}toggleStyles(t){for(const[i,o]of Object.entries(t)){const n=this.schema.styleSchema[i];if(!n)throw new Error(`style ${i} not found in styleSchema`);if(n.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(i);else if(n.propSchema==="string")this._tiptapEditor.commands.toggleMark(i,{stringValue:o});else throw new I(n.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,i){if(t==="")return;const{from:o,to:n}=this._tiptapEditor.state.selection;i||(i=this._tiptapEditor.state.doc.textBetween(o,n));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(i,o,n).addMark(o,o+i.length,r))}canNestBlock(){const{startPos:t,depth:i}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(i-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.document){return Y(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return Ft(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.document){return Xo(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return on(t,this.schema.blockSchema,this.schema.inlineContentSchema,this.schema.styleSchema,this._tiptapEditor.schema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}onChange(t){const i=()=>{t(this)};return this._tiptapEditor.on("update",i),()=>{this._tiptapEditor.off("update",i)}}onSelectionChange(t){const i=()=>{t(this)};return this._tiptapEditor.on("selectionUpdate",i),()=>{this._tiptapEditor.off("selectionUpdate",i)}}}function Ve(e=""){return typeof e=="string"?[{type:"text",text:e,styles:{}}]:e}function ci(e){return typeof e=="string"?Ve(e):Array.isArray(e)?e.flatMap(t=>typeof t=="string"?Ve(t):fe(t)?{...t,content:Ve(t.content)}:$(t)?t:{props:{},...t,content:ci(t.content)}):e}function On(e,t){return t.map(i=>je(e,i))}function je(e,t){const i={id:"",type:t.type,props:{},content:e[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(e[t.type].propSchema).forEach(([o,n])=>{i.props[o]===void 0&&(i.props[o]=n.default)}),{...i,content:ci(i.content),children:i.children.map(o=>je(e,o))}}function ui(e){e.id||(e.id=W.options.generateID()),e.children&&pi(e.children)}function pi(e){for(const t of e)ui(t)}d.AudioBlock=Ut,d.BlockNoteEditor=Oe,d.BlockNoteSchema=ue,d.FileBlock=gt,d.FilePanelProsemirrorPlugin=qt,d.FilePanelView=Kt,d.FormattingToolbarProsemirrorPlugin=$t,d.FormattingToolbarView=Gt,d.ImageBlock=vt,d.LinkToolbarProsemirrorPlugin=Zt,d.SideMenuProsemirrorPlugin=ii,d.SideMenuView=ei,d.SuggestionMenuProseMirrorPlugin=Jt,d.TableHandlesProsemirrorPlugin=ri,d.TableHandlesView=ni,d.UniqueID=W,d.UnreachableCaseError=I,d.VideoBlock=Bt,d.addIdsToBlock=ui,d.addIdsToBlocks=pi,d.addInlineContentAttributes=ot,d.addInlineContentKeyboardShortcuts=nt,d.addStyleAttributes=dt,d.assertEmpty=Qi,d.audioBlockConfig=Pt,d.audioParse=Nt,d.audioPropSchema=It,d.audioRender=At,d.audioToExternalHTML=Ht,d.blockToNode=N,d.camelToDataKebab=Q,d.checkBlockHasDefaultProp=jo,d.checkBlockIsDefaultType=Rt,d.checkBlockIsFileBlock=Ro,d.checkBlockIsFileBlockWithPlaceholder=Vo,d.checkBlockIsFileBlockWithPreview=Oo,d.checkBlockTypeHasDefaultProp=Ot,d.checkDefaultBlockTypeInSchema=B,d.contentNodeToInlineContent=se,d.createAddFileButton=ie,d.createBlockSpec=ee,d.createBlockSpecFromStronglyTypedTiptapNode=G,d.createDefaultFilePreview=te,d.createExternalHTMLExporter=Y,d.createFigureWithCaption=de,d.createFileAndCaptionWrapper=O,d.createInlineContentSpec=ao,d.createInlineContentSpecFromTipTapNode=at,d.createInternalBlockSpec=ve,d.createInternalHTMLSerializer=_e,d.createInternalInlineContentSpec=rt,d.createInternalStyleSpec=Ce,d.createLinkWithCaption=ne,d.createResizeHandlesWrapper=Me,d.createStronglyTypedTiptapNode=D,d.createStyleSpec=so,d.createStyleSpecFromTipTapMark=R,d.createSuggestionMenu=sn,d.defaultBlockSchema=Dt,d.defaultBlockSpecs=Ie,d.defaultInlineContentSchema=Do,d.defaultInlineContentSpecs=Ae,d.defaultProps=E,d.defaultStyleSchema=Uo,d.defaultStyleSpecs=Pe,d.fileBlockConfig=pt,d.fileParse=mt,d.filePropSchema=ut,d.fileRender=ht,d.fileToExternalHTML=ft,d.filenameFromURL=ro,d.filterSuggestionItems=bn,d.formatKeyboardShortcut=H,d.formattingToolbarPluginKey=Wt,d.getBlockFromPos=tt,d.getBlockNoteExtensions=di,d.getBlockSchemaFromSpecs=Ee,d.getDefaultSlashMenuItems=gn,d.getDraggableBlockFromElement=re,d.getInlineContentParseRules=st,d.getInlineContentSchemaFromSpecs=xe,d.getParseRules=it,d.getStyleParseRules=ct,d.getStyleSchemaFromSpecs=Se,d.imageBlockConfig=kt,d.imageParse=yt,d.imagePropSchema=bt,d.imageRender=_t,d.imageToExternalHTML=wt,d.inheritedProps=ye,d.inlineContentToNodes=K,d.insertOrUpdateBlock=T,d.isAppleOS=Qe,d.isLinkInlineContent=me,d.isPartialLinkInlineContent=fe,d.isSafari=no,d.isStyledTextInlineContent=$,d.linkToolbarPluginKey=Xt,d.locales=Zi,d.mergeCSSClasses=U,d.nodeToBlock=x,d.nodeToCustomInlineContent=ke,d.parseEmbedElement=Te,d.parseFigureElement=oe,d.parseImageElement=Be,d.partialBlockToBlockForTesting=je,d.partialBlocksToBlocksForTesting=On,d.propsToAttributes=we,d.sideMenuPluginKey=ti,d.stylePropsToAttributes=lt,d.suggestionMenuPluginKey=V,d.tableContentToNodes=be,d.tableHandlesPluginKey=J,d.uploadToTmpFilesDotOrg_DEV_ONLY=lo,d.videoBlockConfig=Ct,d.videoParse=Tt,d.videoPropSchema=xt,d.videoRender=St,d.videoToExternalHTML=Mt,d.wrapInBlockStructure=le,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
8
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|