@blocknote/core 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/blocknote.js +1536 -1458
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -6
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +5 -3
- package/src/api/blockManipulation/blockManipulation.ts +144 -30
- package/src/api/exporters/copyExtension.ts +97 -24
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/button/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +0 -1
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +9 -0
- package/src/api/parsers/pasteExtension.ts +0 -1
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +19 -19
- package/src/editor/Block.css +19 -14
- package/src/editor/BlockNoteEditor.ts +11 -12
- package/src/editor/editor.css +1 -0
- package/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.ts +12 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +2 -2
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +3 -1
- package/src/pm-nodes/BlockContainer.ts +1 -1
- package/types/src/api/blockManipulation/blockManipulation.d.ts +8 -6
- package/types/src/editor/BlockNoteEditor.d.ts +9 -7
- package/types/src/BlockNoteEditor.d.ts +0 -300
- package/types/src/BlockNoteEditor.test.d.ts +0 -1
- package/types/src/BlockNoteExtensions.d.ts +0 -26
- package/types/src/api/nodeConversions/testUtil.d.ts +0 -7
- package/types/src/api/testCases/cases/customBlocks.d.ts +0 -345
- package/types/src/api/testCases/cases/customInlineContent.d.ts +0 -29
- package/types/src/api/testCases/cases/customStyles.d.ts +0 -64
- package/types/src/api/testCases/cases/defaultSchema.d.ts +0 -3
- package/types/src/api/testCases/index.d.ts +0 -12
- package/types/src/api/util/nodeUtil.d.ts +0 -8
- package/types/src/extensions/Blocks/NonEditableBlockPlugin.d.ts +0 -2
- package/types/src/extensions/Blocks/PreviousBlockTypePlugin.d.ts +0 -14
- package/types/src/extensions/Blocks/api/blocks/createSpec.d.ts +0 -35
- package/types/src/extensions/Blocks/api/blocks/internal.d.ts +0 -45
- package/types/src/extensions/Blocks/api/blocks/types.d.ts +0 -114
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +0 -8
- package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +0 -577
- package/types/src/extensions/Blocks/api/defaultProps.d.ts +0 -15
- package/types/src/extensions/Blocks/api/inlineContent/createSpec.d.ts +0 -21
- package/types/src/extensions/Blocks/api/inlineContent/internal.d.ts +0 -25
- package/types/src/extensions/Blocks/api/inlineContent/types.d.ts +0 -62
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +0 -6
- package/types/src/extensions/Blocks/api/styles/createSpec.d.ts +0 -13
- package/types/src/extensions/Blocks/api/styles/internal.d.ts +0 -22
- package/types/src/extensions/Blocks/api/styles/types.d.ts +0 -21
- package/types/src/extensions/Blocks/helpers/findBlock.d.ts +0 -6
- package/types/src/extensions/Blocks/helpers/getBlockInfoFromPos.d.ts +0 -27
- package/types/src/extensions/Blocks/index.d.ts +0 -4
- package/types/src/extensions/Blocks/nodes/BlockAttributes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +0 -30
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +0 -58
- package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/ImageBlockContent.d.ts +0 -95
- package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -1
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -46
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
- package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableBlockContent.d.ts +0 -53
- package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableExtension.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/defaultBlockHelpers.d.ts +0 -12
- package/types/src/extensions/Blocks/nodes/BlockGroup.d.ts +0 -10
- package/types/src/shared/BaseUiElementTypes.d.ts +0 -7
- package/types/src/shared/EditorElement.d.ts +0 -0
- package/types/src/shared/EventEmitter.d.ts +0 -11
- package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +0 -3
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +0 -37
- package/types/src/shared/utils.d.ts +0 -6
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`?
|
|
3
|
-
`;else if(
|
|
1
|
+
(function(u,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("prosemirror-model"),require("rehype-parse"),require("rehype-stringify"),require("unified"),require("@tiptap/core"),require("prosemirror-state"),require("uuid"),require("hast-util-from-dom"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-underline"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("prosemirror-tables"),require("rehype-remark"),require("remark-gfm"),require("remark-stringify"),require("remark-parse"),require("remark-rehype"),require("prosemirror-view"),require("@tiptap/extension-collaboration"),require("@tiptap/extension-collaboration-cursor"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-link"),require("@tiptap/extension-text")):typeof define=="function"&&define.amd?define(["exports","prosemirror-model","rehype-parse","rehype-stringify","unified","@tiptap/core","prosemirror-state","uuid","hast-util-from-dom","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-underline","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","prosemirror-tables","rehype-remark","remark-gfm","remark-stringify","remark-parse","remark-rehype","prosemirror-view","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-link","@tiptap/extension-text"],y):(u=typeof globalThis<"u"?globalThis:u||self,y(u.blocknote={},u.prosemirrorModel,u.rehypeParse,u.rehypeStringify,u.unified,u.core,u.prosemirrorState,u.uuid,u.hastUtilFromDom,u.Bold,u.Code,u.Italic,u.Strike,u.Underline,u.extensionTableCell,u.extensionTableHeader,u.extensionTableRow,u.prosemirrorTables,u.rehypeRemark,u.remarkGfm,u.remarkStringify,u.remarkParse,u.remarkRehype,u.prosemirrorView,u.Collaboration,u.CollaborationCursor,u.extensionDropcursor,u.extensionGapcursor,u.extensionHardBreak,u.extensionHistory,u.extensionLink,u.extensionText))})(this,function(u,y,V,Nt,le,b,k,At,Le,Dt,_t,Ot,Rt,Ft,zt,Vt,Ut,Ne,qt,$t,Gt,jt,Ae,N,Kt,Wt,Xt,Jt,Yt,Zt,Qt,en){"use strict";var zo=Object.defineProperty;var Vo=(u,y,V)=>y in u?zo(u,y,{enumerable:!0,configurable:!0,writable:!0,value:V}):u[y]=V;var p=(u,y,V)=>(Vo(u,typeof y!="symbol"?y+"":y,V),V);const P=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},De=P(V),_e=P(Nt),tn=P(Dt),nn=P(_t),on=P(Ot),rn=P(Rt),sn=P(Ft),an=P(qt),Oe=P($t),ln=P(Gt),cn=P(jt),dn=P(Ae),un=P(Kt),pn=P(Wt);function hn(n,e=JSON.stringify){const t={};return n.filter(o=>{const i=e(o);return Object.prototype.hasOwnProperty.call(t,i)?!1:t[i]=!0})}function mn(n){const e=n.filter((o,i)=>n.indexOf(o)!==i);return hn(e)}const $=b.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const n=window.__TEST_OPTIONS;return n.mockID===void 0?n.mockID=0:n.mockID++,n.mockID.toString()}return At.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:n=>n.getAttribute(`data-${this.options.attributeName}`),renderHTML:n=>({[`data-${this.options.attributeName}`]:n[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let n=null,e=!1;return[new k.Plugin({key:new k.PluginKey("uniqueID"),appendTransaction:(t,o,i)=>{const r=t.some(g=>g.docChanged)&&!o.doc.eq(i.doc),s=this.options.filterTransaction&&t.some(g=>{let T,M;return!(!((M=(T=this.options).filterTransaction)===null||M===void 0)&&M.call(T,g))});if(!r||s)return;const{tr:a}=i,{types:l,attributeName:c,generateID:d}=this.options,h=b.combineTransactionSteps(o.doc,t),{mapping:f}=h;if(b.getChangedRanges(h).forEach(({newRange:g})=>{const T=b.findChildrenInRange(i.doc,g,v=>l.includes(v.type.name)),M=T.map(({node:v})=>v.attrs[c]).filter(v=>v!==null),x=mn(M);T.forEach(({node:v,pos:S})=>{let C;const B=(C=a.doc.nodeAt(S))===null||C===void 0?void 0:C.attrs[c];if(B===null){const Y=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(Y)===null){const q=JSON.parse(JSON.stringify(i.doc.toJSON()));if(q.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(q.content)===JSON.stringify(Y.toJSON())){a.setNodeMarkup(S,void 0,{...v.attrs,[c]:"initialBlockId"});return}}a.setNodeMarkup(S,void 0,{...v.attrs,[c]:d()});return}const{deleted:w}=f.invert().mapResult(S);w&&x.includes(B)&&a.setNodeMarkup(S,void 0,{...v.attrs,[c]:d()})})}),!!a.steps.length)return a},view(t){const o=i=>{let r;n=!((r=t.dom.parentElement)===null||r===void 0)&&r.contains(i.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(t,o)=>{let i;return(n!==t.dom.parentElement||((i=o.dataTransfer)===null||i===void 0?void 0:i.effectAllowed)==="copy")&&(n=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:o,attributeName:i}=this.options,r=s=>{const a=[];return s.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(r(l.content)));return}const c=l.type.create({...l.attrs,[i]:null},r(l.content),l.marks);a.push(c)}),y.Fragment.from(a)};return e=!1,new y.Slice(r(t.content),t.openStart,t.openEnd)}}})]}});function Re(n){const e=n.attrs.id,t=n.firstChild,o=t.type,i=n.childCount===2?n.lastChild.childCount:0;return{id:e,node:n,contentNode:t,contentType:o,numChildBlocks:i}}function E(n,e){const o=n.nodeSize-2;if(e<=1)for(e=1+1;n.resolve(e).parent.type.name!=="blockContainer"&&e<o;)e++;else if(e>=o)for(e=o-1;n.resolve(e).parent.type.name!=="blockContainer"&&e>1;)e--;n.resolve(e).parent.type.name==="blockGroup"&&e++;const i=n.resolve(e),r=i.depth;let s=i.node(r),a=r;for(;;){if(a<0)throw new Error("Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited.");if(s.type.name==="blockContainer")break;a-=1,s=i.node(a)}const{id:l,contentNode:c,contentType:d,numChildBlocks:h}=Re(s),f=i.start(a),m=i.end(a);return{id:l,node:s,contentNode:c,contentType:d,numChildBlocks:h,startPos:f,endPos:m,depth:a}}function ce(n){return n.type==="link"}function de(n){return typeof n!="string"&&n.type==="link"}function G(n){return typeof n!="string"&&n.type==="text"}class D extends Error{constructor(e){super(`Unreachable case: ${e}`)}}function Fe(n,e,t){const o=[];for(const[i,r]of Object.entries(n.styles)){const s=t[i];if(!s)throw new Error(`style ${i} not found in styleSchema`);if(s.propSchema==="boolean")o.push(e.mark(i));else if(s.propSchema==="string")o.push(e.mark(i,{stringValue:r}));else throw new D(s.propSchema)}return n.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
|
|
2
|
+
`?e.nodes.hardBreak.create():e.text(i,o))}function fn(n,e,t){const o=e.marks.link.create({href:n.href});return ue(n.content,e,t).map(i=>{if(i.type.name==="text")return i.mark([...i.marks,o]);if(i.type.name==="hardBreak")return i;throw new Error("unexpected node type")})}function ue(n,e,t){const o=[];if(typeof n=="string")return o.push(...Fe({type:"text",text:n,styles:{}},e,t)),o;for(const i of n)o.push(...Fe(i,e,t));return o}function ne(n,e,t){const o=[];for(const i of n)typeof i=="string"?o.push(...ue(i,e,t)):de(i)?o.push(...fn(i,e,t)):G(i)?o.push(...ue([i],e,t)):o.push(ze(i,e,t));return o}function pe(n,e,t){const o=[];for(const i of n.rows){const r=[];for(const a of i.cells){let l;if(!a)l=e.nodes.tableParagraph.create({});else if(typeof a=="string")l=e.nodes.tableParagraph.create({},e.text(a));else{const d=ne(a,e,t);l=e.nodes.tableParagraph.create({},d)}const c=e.nodes.tableCell.create({},l);r.push(c)}const s=e.nodes.tableRow.create({},r);o.push(s)}return o}function ze(n,e,t){let o,i=n.type;if(i===void 0&&(i="paragraph"),!e.nodes[i])throw new Error(`node type ${i} not found in schema`);if(!n.content)o=e.nodes[i].create(n.props);else if(typeof n.content=="string")o=e.nodes[i].create(n.props,e.text(n.content));else if(Array.isArray(n.content)){const r=ne(n.content,e,t);o=e.nodes[i].create(n.props,r)}else if(n.content.type==="tableContent"){const r=pe(n.content,e,t);o=e.nodes[i].create(n.props,r)}else throw new D(n.content.type);return o}function _(n,e,t){let o=n.id;o===void 0&&(o=$.options.generateID());const i=ze(n,e,t),r=[];if(n.children)for(const a of n.children)r.push(_(a,e,t));const s=e.nodes.blockGroup.create({},r);return e.nodes.blockContainer.create({id:o,...n.props},r.length>0?[i,s]:i)}function gn(n,e,t){const o={type:"tableContent",rows:[]};return n.content.forEach(i=>{const r={cells:[]};i.content.forEach(s=>{r.cells.push(oe(s.firstChild,e,t))}),o.rows.push(r)}),o}function oe(n,e,t){const o=[];let i;return n.content.forEach(r=>{if(r.type.name==="hardBreak"){if(i)if(G(i))i.text+=`
|
|
3
|
+
`;else if(ce(i))i.content[i.content.length-1].text+=`
|
|
4
4
|
`;else throw new Error("unexpected");else i={type:"text",text:`
|
|
5
|
-
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&t[r.type.name]){i&&(o.push(i),i=void 0),o.push(he(r,t,e));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const d=e[l.type.name];if(!d)throw new Error(`style ${l.type.name} not found in styleSchema`);if(d.propSchema==="boolean")s[d.type]=!0;else if(d.propSchema==="string")s[d.type]=l.attrs.stringValue;else throw new A(d.propSchema)}i?G(i)?a?(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):JSON.stringify(i.styles)===JSON.stringify(s)?i.text+=r.textContent:(o.push(i),i={type:"text",text:r.textContent,styles:s}):de(i)&&(a?i.href===a.attrs.href?JSON.stringify(i.content[i.content.length-1].styles)===JSON.stringify(s)?i.content[i.content.length-1].text+=r.textContent:i.content.push({type:"text",text:r.textContent,styles:s}):(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):(o.push(i),i={type:"text",text:r.textContent,styles:s})):a?i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}:i={type:"text",text:r.textContent,styles:s}}),i&&o.push(i),o}function he(n,t,e){if(n.type.name==="text"||n.type.name==="link")throw new Error("unexpected");const o={},i=t[n.type.name];for(const[a,l]of Object.entries(n.attrs)){if(!i)throw Error("ic node is of an unrecognized type: "+n.type.name);const d=i.propSchema;a in d&&(o[a]=l)}let r;return i.content==="styled"?r=oe(n,t,e):r=void 0,{type:n.type.name,props:o,content:r}}function L(n,t,e,o,i){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const r=i==null?void 0:i.get(n);if(r)return r;const s=Re(n);let a=s.id;a===null&&(a=$.options.generateID());const l={};for(const[m,g]of Object.entries({...n.attrs,...s.contentNode.attrs})){const E=t[s.contentType.name];if(!E)throw Error("Block is of an unrecognized type: "+s.contentType.name);const M=E.propSchema;m in M&&(l[m]=g)}const d=t[s.contentType.name],u=[];for(let m=0;m<s.numChildBlocks;m++)u.push(L(n.lastChild.child(m),t,e,o,i));let h;if(d.content==="inline")h=oe(s.contentNode,e,o);else if(d.content==="table")h=gn(s.contentNode,e,o);else if(d.content==="none")h=void 0;else throw new A(d.content);const f={id:a,type:d.type,props:l,content:h,children:u};return i==null||i.set(n,f),f}function bn(n){return n.document||window.document}const Ve=(n,t,e,o,i)=>{if(!e.nodes[n.type.name])throw new Error("Serializer is missing a node type: "+n.type.name);const{dom:r,contentDOM:s}=k.DOMSerializer.renderSpec(bn(t),e.nodes[n.type.name](n));if(s){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(n.type.name==="blockContainer"){const a=n.childCount>0&&n.firstChild.type.spec.group==="blockContent"?n.firstChild:void 0,l=n.childCount>0&&n.lastChild.type.spec.group==="blockGroup"?n.lastChild:void 0;if(a!==void 0){const d=o.blockImplementations[a.type.name].implementation,h=(i?d.toExternalHTML:d.toInternalHTML)(L(n,o.blockSchema,o.inlineContentSchema,o.styleSchema,o.blockCache),o);if(h.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");h.contentDOM.appendChild(e.serializeFragment(a.content,t))}s.appendChild(h.dom)}l!==void 0&&e.serializeFragment(k.Fragment.from(l),t,s)}else e.serializeFragment(n.content,t,s)}return r},Ue=(n,t)=>{const e=t.serializeFragment(n),o=document.createElement("div");return o.appendChild(e),o.innerHTML};function yn(n){const t=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),e=o=>{var s;if(o.children.length===1&&((s=o.children[0].properties)==null?void 0:s.dataNodeType)==="blockGroup"){const a=o.children[0];o.children.pop(),o.children.push(...a.children)}let i=o.children.length,r;for(let a=0;a<i;a++){const d=o.children[a].children[0],u=d.children[0],h=d.children.length===2?d.children[1]:null,f=t.has(u.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(u.properties.dataContentType)?"ol":"ul":null;if(h!==null&&e(h),r&&r.tagName!==m){o.children.splice(a-r.children.length,r.children.length,r);const g=r.children.length-1;a-=g,i-=g,r=void 0}if(f){r||(r=Ne.fromDom(document.createElement(m)));const g=Ne.fromDom(document.createElement("li"));g.children.push(u.children[0]),h!==null&&g.children.push(...h.children),r.children.push(g)}else if(h!==null){o.children.splice(a+1,0,...h.children),o.children[a]=u.children[0];const g=h.children.length;a+=g,i+=g}else o.children[a]=u.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return e}const Z=(n,t)=>{const e=k.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>Ve(o,i,e,t,!0),e.exportProseMirrorFragment=o=>le.unified().use(De.default,{fragment:!0}).use(yn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(_e.default).processSync(Ue(o,e)).value,e.exportBlocks=o=>{const i=o.map(s=>_(s,n,t.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.exportProseMirrorFragment(k.Fragment.from(r))},e},me=(n,t)=>{const e=k.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>Ve(o,i,e,t,!1),e.serializeProseMirrorFragment=o=>Ue(o,e),e.serializeBlocks=o=>{const i=o.map(s=>_(s,n,t.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.serializeProseMirrorFragment(k.Fragment.from(r))},e},kn=async n=>{const t=new FormData;return t.append("file",n),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},qe=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function wn(n){return qe()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function O(...n){return n.filter(t=>t).join(" ")}function Q(n,t,e,o){const i=document.createElement("div");i.className=O("bn-block-content",e.class),i.setAttribute("data-content-type",n);for(const[s,a]of Object.entries(e))s!=="class"&&i.setAttribute(s,a);const r=document.createElement(t);r.className=O("bn-inline-content",o.class);for(const[s,a]of Object.entries(o))s!=="class"&&r.setAttribute(s,a);return i.appendChild(r),{dom:i,contentDOM:r}}const $e=(n,t)=>{const e=_(n,t._tiptapEditor.schema,t.styleSchema).firstChild,o=t._tiptapEditor.schema.nodes[e.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 i=o(e);if(typeof i!="object"||!("dom"in i))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 i},P={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},fe=["backgroundColor","textColor"];function ee(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ge(n){const t={};return Object.entries(n).filter(([e,o])=>!fe.includes(e)).forEach(([e,o])=>{t[e]={default:o.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(ee(e));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[e]!==o.default?{[ee(e)]:i[e]}:{}}}),t}function Ge(n,t,e,o){if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const i=n(),s=e.state.doc.resolve(i).node().attrs.id,a=t.getBlock(s);if(a.type!==o)throw new Error("Block type does not match");return a}function ie(n,t,e,o,i){const r=document.createElement("div");if(i!==void 0)for(const[s,a]of Object.entries(i))s!=="class"&&r.setAttribute(s,a);r.className=O("bn-block-content",(i==null?void 0:i.class)||""),r.setAttribute("data-content-type",t);for(const[s,a]of Object.entries(e))!fe.includes(s)&&a!==o[s].default&&r.setAttribute(ee(s),a);return r.appendChild(n.dom),n.contentDOM!==void 0&&(n.contentDOM.className=O("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function U(n){return b.Node.create(n)}function be(n,t){return{config:n,implementation:t}}function j(n,t,e){return be({type:n.name,content:n.config.content==="inline*"?"inline":n.config.content==="tableRow+"?"table":"none",propSchema:t},{node:n,requiredExtensions:e,toInternalHTML:$e,toExternalHTML:$e})}function ye(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function je(n,t){const e=[{tag:"[data-content-type="+n.type+"]",contentElement:"[data-editable]"}];return t&&e.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const i=t==null?void 0:t(o);return i===void 0?!1:i}}),e}function Ke(n,t){const e=U({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return ge(n.propSchema)},parseHTML(){return je(n,t.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const i=this.options.editor,r=Ge(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=t.render(r,i);return ie(a,r.type,r.props,n.propSchema,s)}}});if(e.name!==n.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return be(n,{node:e,toInternalHTML:(o,i)=>{var a;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{},s=t.render(o,i);return ie(s,o.type,o.props,n.propSchema,r)},toExternalHTML:(o,i)=>{var a,l;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{};let s=(l=t.toExternalHTML)==null?void 0:l.call(t,o,i);return s===void 0&&(s=t.render(o,i)),ie(s,o.type,o.props,n.propSchema,r)}})}function We(n,t,e,o){return n.dom.setAttribute("data-inline-content-type",t),Object.entries(e).filter(([i,r])=>r!==o[i].default).map(([i,r])=>[ee(i),r]).forEach(([i,r])=>n.dom.setAttribute(i,r)),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Xe(n){return{Backspace:({editor:t})=>{const e=t.state.selection.$from;return t.state.selection.empty&&e.node().type.name===n.type&&e.parentOffset===0}}}function Je(n,t){return{config:n,implementation:t}}function Ye(n,t){return Je({type:n.name,propSchema:t,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function ke(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function Ze(n){return[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function vn(n,t){const e=b.Node.create({name:n.type,inline:!0,group:"inline",selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return ge(n.propSchema)},addKeyboardShortcuts(){return Xe(n)},parseHTML(){return Ze(n)},renderHTML({node:o}){const i=this.options.editor,r=t.render(he(o,i.inlineContentSchema,i.styleSchema));return We(r,n.type,o.attrs,n.propSchema)}});return Ye(e,n.propSchema)}function Qe(n){return n==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:t=>t.getAttribute("data-value"),renderHTML:t=>t.stringValue!==void 0?{"data-value":t.stringValue}:{}}}}function et(n,t,e,o){return n.dom.setAttribute("data-style-type",t),o==="string"&&n.dom.setAttribute("data-value",e),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function we(n,t){return{config:n,implementation:t}}function R(n,t){return we({type:n.name,propSchema:t},{mark:n})}function ve(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function tt(n){return[{tag:`[data-style-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function Sn(n,t){const e=b.Mark.create({name:n.type,addAttributes(){return Qe(n.propSchema)},parseHTML(){return tt(n)},renderHTML({mark:o}){let i;if(n.propSchema==="boolean")i=t.render();else if(n.propSchema==="string")i=t.render(o.attrs.stringValue);else throw new A(n.propSchema);return et(i,n.type,o.attrs.stringValue,n.propSchema)}});return we(n,{mark:e})}const En=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{stringValue:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Tn=R(En,"string"),Cn=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{stringValue:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Mn=R(Cn,"string"),xn={...P,level:{default:1,values:[1,2,3]}},Bn=U({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:n=>{const t=n.getAttribute("data-level"),e=parseInt(t);if(isFinite(e))return e},renderHTML:n=>({"data-level":n.level.toString()})}}},addInputRules(){return[...[1,2,3].map(n=>new b.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:t,chain:e,range:o})=>{e().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:n=>typeof n=="string"?!1:{level:n.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:n,HTMLAttributes:t}){var e,o;return Q(this.name,`h${n.attrs.level}`,{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...t},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),In=j(Bn,xn);class K{constructor(){p(this,"callbacks",{})}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),()=>this.off(t,e)}emit(t,...e){const o=this.callbacks[t];o&&o.forEach(i=>i.apply(this,e))}off(t,e){const o=this.callbacks[t];o&&(e?this.callbacks[t]=o.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class nt{constructor(t,e,o){p(this,"imageToolbarState");p(this,"updateImageToolbar");p(this,"prevWasEditable",null);p(this,"mouseDownHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"dragstartHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"blurHandler",t=>{var o;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.imageToolbarState)!=null&&o.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"scrollHandler",()=>{var t;if((t=this.imageToolbarState)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=e.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=t,this.pmView=e,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");o(this.imageToolbarState)},e.dom.addEventListener("mousedown",this.mouseDownHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var i,r;const o=this.pluginKey.getState(t.state);if(!((i=this.imageToolbarState)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.updateImageToolbar();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const W=new y.PluginKey("ImageToolbarPlugin");class ot extends K{constructor(e){super();p(this,"view");p(this,"plugin");this.plugin=new y.Plugin({key:W,view:o=>(this.view=new nt(W,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(W))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}const Pn={textAlignment:P.textAlignment,backgroundColor:P.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},it=n=>{switch(n){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},rt=64,Hn=Ke({type:"image",propSchema:Pn,content:"none"},{render:(n,t)=>{const e=document.createElement("div");e.className="bn-image-block-content-wrapper",e.style.alignItems=it(n.props.textAlignment);const o=document.createElement("div");o.className="bn-add-image-button",o.style.display=n.props.url===""?"":"none";const i=document.createElement("div");i.className="bn-add-image-button-icon";const r=document.createElement("p");r.className="bn-add-image-button-text",r.innerText="Add Image";const s=document.createElement("div");s.className="bn-image-and-caption-wrapper",s.style.display=n.props.url!==""?"":"none";const a=document.createElement("div");a.className="bn-image-wrapper",a.style.display=n.props.url!==""?"":"none";const l=document.createElement("img");l.className="bn-image",l.src=n.props.url,l.alt="placeholder",l.contentEditable="false",l.draggable=!1,l.style.width=`${Math.min(n.props.width,t.domElement.firstElementChild.clientWidth)}px`;const d=document.createElement("div");d.className="bn-image-resize-handle",d.style.left="4px";const u=document.createElement("div");u.className="bn-image-resize-handle",u.style.right="4px";const h=document.createElement("p");h.className="bn-image-caption",h.innerText=n.props.caption,h.style.padding=n.props.caption?"4px":"";const f=()=>{var te;const v=((te=t.getSelection())==null?void 0:te.blocks)||[];[t.getTextCursorPosition().block,...v].find(q=>q.id===n.id)!==void 0?(o.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(o.style.outline="",s.style.outline="")};t.onEditorContentChange(f),t.onEditorSelectionChange(f);let m;const g=v=>{if(!m)return;let H;it(n.props.textAlignment)==="center"?m.handleUsed==="left"?H=m.initialWidth+(m.initialClientX-v.clientX)*2:H=m.initialWidth+(v.clientX-m.initialClientX)*2:m.handleUsed==="left"?H=m.initialWidth+m.initialClientX-v.clientX:H=m.initialWidth+v.clientX-m.initialClientX,H<rt?l.style.width=`${rt}px`:H>t.domElement.firstElementChild.clientWidth?l.style.width=`${t.domElement.firstElementChild.clientWidth}px`:l.style.width=`${H}px`},E=v=>{m&&((!v.target||!a.contains(v.target))&&a.contains(d)&&a.contains(u)&&(d.style.display="none",u.style.display="none"),m=void 0,t.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},M=v=>{v.preventDefault()},x=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(W,{block:n}))},S=()=>{t.isEditable?(d.style.display="block",u.style.display="block"):(d.style.display="none",u.style.display="none")},w=v=>{v.relatedTarget===d||v.relatedTarget===u||m||(d.style.display="none",u.style.display="none")},C=v=>{v.preventDefault(),d.style.display="block",u.style.display="block",m={handleUsed:"left",initialWidth:n.props.width,initialClientX:v.clientX}},B=v=>{v.preventDefault(),d.style.display="block",u.style.display="block",m={handleUsed:"right",initialWidth:n.props.width,initialClientX:v.clientX}};return e.appendChild(o),o.appendChild(i),o.appendChild(r),e.appendChild(s),s.appendChild(a),a.appendChild(l),a.appendChild(d),a.appendChild(u),s.appendChild(h),window.addEventListener("mousemove",g),window.addEventListener("mouseup",E),o.addEventListener("mousedown",M),o.addEventListener("click",x),l.addEventListener("mouseenter",S),l.addEventListener("mouseleave",w),d.addEventListener("mousedown",C),u.addEventListener("mousedown",B),{dom:e,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",E),o.removeEventListener("mousedown",M),o.removeEventListener("click",x),d.removeEventListener("mousedown",C),u.removeEventListener("mousedown",B)}}},toExternalHTML:n=>{if(n.props.url===""){const o=document.createElement("p");return o.innerHTML="Add Image",{dom:o}}const t=document.createElement("figure"),e=document.createElement("img");if(e.src=n.props.url,t.appendChild(e),n.props.caption!==""){const o=document.createElement("figcaption");o.innerHTML=n.props.caption,t.appendChild(o)}return{dom:t}},parse:n=>{if(n.tagName==="FIGURE"){const t=n.querySelector("img"),e=n.querySelector("figcaption");return{url:(t==null?void 0:t.getAttribute("src"))||"",caption:(e==null?void 0:e.textContent)||(t==null?void 0:t.getAttribute("alt"))||void 0}}else if(n.tagName==="IMG")return{url:n.getAttribute("src")||"",caption:n.getAttribute("alt")||void 0}}}),st=n=>{const{node:t,contentType:e}=T(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!e.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>t.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>t.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},Nn={...P},Ln=U({name:"bulletListItem",content:"inline*",group:"blockContent",addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:t,range:e})=>{t().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>st(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="UL"||t.tagName==="DIV"&&t.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),An=j(Ln,Nn),Dn=new y.PluginKey("numbered-list-indexing"),_n=()=>new y.Plugin({key:Dn,appendTransaction:(n,t,e)=>{const o=e.tr;o.setMeta("numberedListIndexing",!0);let i=!1;return e.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,d=T(o.doc,s+1);if(d===void 0)return;if(!l){const f=T(o.doc,s-2);if(f===void 0)return;if(!(d.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const x=g.attrs.index;a=(parseInt(x)+1).toString()}}}d.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),On={...P},Rn=U({name:"numberedListItem",content:"inline*",group:"blockContent",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:t,range:e})=>{t().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>st(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[_n()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="OL"||t.tagName==="DIV"&&t.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Fn=j(Rn,On),zn={...P},Vn=U({name:"paragraph",content:"inline*",group:"blockContent",parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Un=j(Vn,zn),qn=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[Le.columnResizing({cellMinWidth:100}),Le.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 n=this.editor.state.selection,t=n.empty,e=n.$head.parentOffset===0,o=n.$head.node().type.name==="tableParagraph";return t&&e&&o}}},extendNodeSchema(n){const t={name:n.name,options:n.options,storage:n.storage};return{tableRole:b.callOrReturn(b.getExtensionField(n,"tableRole",t))}}}),$n={...P},Gn=U({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"table",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),jn=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",b.mergeAttributes(this.options.HTMLAttributes,n),0]}}),Kn=j(Gn,$n,[qn,jn,Vt.TableHeader.extend({content:"tableContent"}),zt.TableCell.extend({content:"tableContent"}),Ut.TableRow]),Se={paragraph:Un,heading:In,bulletListItem:An,numberedListItem:Fn,image:Hn,table:Kn},Ee=ye(Se),Te={bold:R(tn.default,"boolean"),italic:R(on.default,"boolean"),underline:R(sn.default,"boolean"),strike:R(rn.default,"boolean"),code:R(nn.default,"boolean"),textColor:Mn,backgroundColor:Tn},Wn=ve(Te),Ce={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Xn=ke(Ce);function Me(n,t){let e,o;if(t.firstChild.descendants((i,r)=>e?!1:i.type.name!=="blockContainer"||i.attrs.id!==n?!0:(e=i,o=r+1,!1)),e===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:o}}function at(n,t,e="before",o){const i=o._tiptapEditor,r=typeof t=="string"?t:t.id,s=[];for(const u of n)s.push(_(u,i.schema,o.styleSchema));let a=-1;const{node:l,posBeforeNode:d}=Me(r,i.state.doc);if(e==="before"&&(a=d),e==="after"&&(a=d+l.nodeSize),e==="nested"){if(l.childCount<2){a=d+l.firstChild.nodeSize+1;const u=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(a,u));return}a=d+l.firstChild.nodeSize+2}i.view.dispatch(i.state.tr.insert(a,s))}function Jn(n,t,e){const o=typeof n=="string"?n:n.id,{posBeforeNode:i}=Me(o,e.state.doc);e.commands.BNUpdateBlock(i+1,t)}function lt(n,t){const e=new Set(n.map(i=>typeof i=="string"?i:i.id));let o=0;if(t.state.doc.descendants((i,r)=>{if(e.size===0)return!1;if(i.type.name!=="blockContainer"||!e.has(i.attrs.id))return!0;e.delete(i.attrs.id);const s=t.state.doc.nodeSize;t.commands.BNDeleteBlock(r-o+1);const a=t.state.doc.nodeSize;return o+=s-a,!1}),e.size>0){const i=[...e].join(`
|
|
6
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+i)}}function
|
|
7
|
-
`:"",o={};t.lang&&(o["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),n.patch(t,i),i=n.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(t,i),i}function ro(n,t,e,o,i){const r=le.unified().use(dn.default).use(Oe.default).use(cn.default,{handlers:{...Ae.defaultHandlers,code:io}}).use(_e.default).processSync(n);return ct(r.value,t,e,o,i)}class ut{constructor(t,e,o){p(this,"formattingToolbarState");p(this,"updateFormattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"prevWasEditable",null);p(this,"shouldShow",({state:t})=>!t.selection.empty);p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});p(this,"dragstartHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});p(this,"blurHandler",t=>{var o;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.formattingToolbarState)!=null&&o.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"scrollHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=t,this.pmView=e,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.formattingToolbarState)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var f,m;const{state:o,composing:i}=t,{doc:r,selection:s}=o,a=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,d=Math.min(...l.map(g=>g.$from.pos)),u=Math.max(...l.map(g=>g.$to.pos)),h=(f=this.shouldShow)==null?void 0:f.call(this,{view:t,state:o,from:d,to:u});if(this.editor.isEditable&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((m=this.formattingToolbarState)!=null&&m.show&&!this.preventHide&&(!h||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:e}=t,{ranges:o}=e,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const pt=new y.PluginKey("FormattingToolbarPlugin");class ht extends K{constructor(e){super();p(this,"view");p(this,"plugin");this.plugin=new y.Plugin({key:pt,view:o=>(this.view=new ut(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class so{constructor(t,e,o){p(this,"hyperlinkToolbarState");p(this,"updateHyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");p(this,"mouseOverHandler",t=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",t=>{var o;const e=this.pmView.dom.parentElement;this.hyperlinkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(o=this.hyperlinkToolbarState)!=null&&o.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});p(this,"scrollHandler",()=>{var t;this.hyperlinkMark!==void 0&&(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.referencePos=b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=t,this.pmView=e,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");o(this.hyperlinkToolbarState)},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),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(t,e){var i;const o=this.pmView.state.tr.insertText(e,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}deleteHyperlink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){this.hyperlinkToolbarState={show:!0,referencePos:b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.updateHyperlinkToolbar();return}if((e=this.hyperlinkToolbarState)!=null&&e.show&&t&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const mt=new y.PluginKey("HyperlinkToolbarPlugin");class ft extends K{constructor(e){super();p(this,"view");p(this,"plugin");p(this,"editHyperlink",(e,o)=>{this.view.editHyperlink(e,o)});p(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new y.Plugin({key:mt,view:o=>(this.view=new so(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}const ao=b.findParentNode(n=>n.type.name==="blockContainer");class lo{constructor(t,e,o=()=>{}){p(this,"suggestionsMenuState");p(this,"updateSuggestionsMenu");p(this,"pluginState");p(this,"handleScroll",()=>{var t;if((t=this.suggestionsMenuState)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=e.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=t,this.pluginKey=e,this.pluginState=Be(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");o(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const o=this.pluginKey.getState(e),i=this.pluginKey.getState(t.state),r=!o.active&&i.active,s=o.active&&!i.active,a=o.active&&i.active;if(!r&&!a&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:l.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function Be(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const gt=(n,t,e,o,i=()=>[],r=()=>{})=>{if(o.length!==1)throw new Error("'char' should be a single character");let s;const a=l=>{l.dispatch(l.state.tr.setMeta(e,{deactivate:!0}))};return{plugin:new y.Plugin({key:e,view:()=>(s=new lo(n,e,t),s),state:{init(){return Be()},apply(l,d,u,h){var m,g,E,M;if(l.getMeta("orderedListIndexing")!==void 0)return d;if((m=l.getMeta(e))!=null&&m.activate)return{active:!0,triggerCharacter:((g=l.getMeta(e))==null?void 0:g.triggerCharacter)||"",queryStartPos:h.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const f={...d};if(f.items=i(h.doc.textBetween(d.queryStartPos,h.selection.from)),f.notFoundCount=0,f.items.length===0&&(f.notFoundCount=Math.max(0,d.notFoundCount+(h.selection.from-u.selection.from))),h.selection.from!==h.selection.to||(E=l.getMeta(e))!=null&&E.deactivate||l.getMeta("focus")||l.getMeta("blur")||l.getMeta("pointer")||d.active&&h.selection.from<d.queryStartPos||f.notFoundCount>3)return Be();if(((M=l.getMeta(e))==null?void 0:M.selectedItemIndexChanged)!==void 0){let x=l.getMeta(e).selectedItemIndexChanged;x<0?x=d.items.length-1:x>=d.items.length&&(x=0),f.keyboardHoveredItemIndex=x}else u.selection.from!==h.selection.from&&(f.keyboardHoveredItemIndex=0);return f}},props:{handleKeyDown(l,d){const u=this.getState(l.state).active;if(d.key===o&&!u)return l.dispatch(l.state.tr.insertText(o).scrollIntoView().setMeta(e,{activate:!0,triggerCharacter:o})),!0;if(!u)return!1;const{triggerCharacter:h,queryStartPos:f,items:m,keyboardHoveredItemIndex:g}=e.getState(l.state);return d.key==="ArrowUp"?(l.dispatch(l.state.tr.setMeta(e,{selectedItemIndexChanged:g-1})),!0):d.key==="ArrowDown"?(l.dispatch(l.state.tr.setMeta(e,{selectedItemIndexChanged:g+1})),!0):d.key==="Enter"?(m.length===0||(a(l),n._tiptapEditor.chain().focus().deleteRange({from:f-h.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:m[g],editor:n})),!0):d.key==="Escape"?(a(l),!0):!1},decorations(l){const{active:d,decorationId:u,queryStartPos:h,triggerCharacter:f}=this.getState(l);if(!d)return null;if(f===""){const m=ao(l.selection);if(m)return N.DecorationSet.create(l.doc,[N.Decoration.node(m.pos,m.pos+m.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":u})])}return N.DecorationSet.create(l.doc,[N.Decoration.inline(h-f.length,h,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":u})])}}}),itemCallback:l=>{a(n._tiptapEditor.view),n._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:l,editor:n})}}},re=new y.PluginKey("SlashMenuPlugin");class bt extends K{constructor(e,o){super();p(this,"plugin");p(this,"itemCallback");const i=gt(e,r=>{this.emit("update",r)},re,"/",r=>o.filter(({name:s,aliases:a})=>s.toLowerCase().startsWith(r.toLowerCase())||a&&a.filter(l=>l.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(e){return this.on("update",e)}}class X extends y.Selection{constructor(e,o){super(e,o);p(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(e,o,i=o){return new X(e.resolve(o),e.resolve(i))}content(){return new k.Slice(k.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof X)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?y.Selection.near(e.resolve(i.pos)):i.deleted?y.Selection.near(e.resolve(r.pos)):new X(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let F;function se(n,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(n);if(!e)return;let o=t.domAtPos(e.pos).node;if(o!==t.dom){for(;o&&o.parentNode&&o.parentNode!==t.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function co(n,t){const e=se(n,t);if(e&&e.node.nodeType===1){const o=t.docView,i=o.nearestDesc(e.node,!0);return!i||i===o?null:i.posBefore}return null}function uo(n,t){let e,o;const i=t.resolve(n.from).node().type.spec.group==="blockContent",r=t.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);e=t.resolve(a-1).pos,o=t.resolve(l+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function yt(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),i=n.domAtPos(t).node,r=(u,h)=>Array.prototype.indexOf.call(u.children,h),s=r(i,n.domAtPos(t+1).node.parentElement),a=r(i,n.domAtPos(e-1).node.parentElement);for(let u=i.childElementCount-1;u>=0;u--)(u>a||u<s)&&o.removeChild(o.children[u]);kt(),F=o;const d=n.dom.className.split(" ").filter(u=>u!=="ProseMirror"&&u!=="bn-root"&&u!=="bn-editor").join(" ");F.className=F.className+" bn-drag-preview "+d,document.body.appendChild(F)}function kt(){F!==void 0&&(document.body.removeChild(F),F=void 0)}function po(n,t){if(!n.dataTransfer)return;const e=t.prosemirrorView,o=e.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=co(i,e);if(r!=null){const s=e.state.selection,a=e.state.doc,{from:l,to:d}=uo(s,a),u=l<=r&&r<d,h=s.$anchor.node()!==s.$head.node()||s instanceof X;u&&h?(e.dispatch(e.state.tr.setSelection(X.create(a,l,d))),yt(e,l,d)):(e.dispatch(e.state.tr.setSelection(y.NodeSelection.create(e.state.doc,r))),yt(e,r));const f=e.state.selection.content(),m=t._tiptapEditor.schema,E=me(m,t).serializeProseMirrorFragment(f.content),x=Z(m,t).exportProseMirrorFragment(f.content),S=xe(x);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",E),n.dataTransfer.setData("text/html",x),n.dataTransfer.setData("text/plain",S),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(F,0,0),e.dragging={slice:f,move:!0}}}class wt{constructor(t,e,o){p(this,"sideMenuState");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"hoveredBlock");p(this,"isDragging",!1);p(this,"menuFrozen",!1);p(this,"onDragStart",()=>{this.isDragging=!0});p(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!e||e.inside===-1){const o=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});p(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!e||e.inside===-1){const o=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});p(this,"onKeyDown",t=>{var e;(e=this.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseDown",t=>{this.sideMenuState&&!this.sideMenuState.show&&(this.sideMenuState.show=!0,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseMove",t=>{var d,u,h,f,m;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=o.left&&t.clientX<=o.right&&t.clientY>=o.top&&t.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},a=se(s,this.pmView);if(!a||!this.editor.isEditable){(u=this.sideMenuState)!=null&&u.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((h=this.sideMenuState)!=null&&h.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.sideMenuState={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateSideMenu(this.sideMenuState)}});p(this,"onScroll",()=>{var t;if((t=this.sideMenuState)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.updateSideMenu(this.sideMenuState)}});this.editor=t,this.pmView=e,this.updateSideMenu=o,this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var a;(a=this.sideMenuState)!=null&&a.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const i=T(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,endPos:s}=i;if(r.textContent.length!==0){const l=s+1,d=l+2;this.editor._tiptapEditor.chain().BNCreateBlock(l).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.editor._tiptapEditor.commands.setTextSelection(s);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(re,{activate:!0,type:"drag"}))}}const vt=new y.PluginKey("SideMenuPlugin");class St extends K{constructor(e){super();p(this,"sideMenuView");p(this,"plugin");p(this,"addBlock",()=>this.sideMenuView.addBlock());p(this,"blockDragStart",e=>{this.sideMenuView.isDragging=!0,po(e,this.editor)});p(this,"blockDragEnd",()=>kt());p(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);p(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=e,this.plugin=new y.Plugin({key:vt,view:o=>(this.sideMenuView=new wt(e,o,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(e){return this.on("update",e)}}function ho(n){let t=n.getTextCursorPosition().block,e=n.blockSchema[t.type].content;for(;e==="none";)t=n.getTextCursorPosition().nextBlock,e=n.blockSchema[t.type].content,n.setTextCursorPosition(t,"end")}function z(n,t){const e=n.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(e.content)&&(e.content.length===1&&G(e.content[0])&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0)?n.updateBlock(e,t):(n.insertBlocks([t],e,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return ho(n),o}const Et=(n=Ee)=>{var e,o,i;const t=[];return"heading"in n&&"level"in n.heading.propSchema&&((e=n.heading.propSchema.level.values)!=null&&e.includes(1)&&t.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>z(r,{type:"heading",props:{level:1}})}),(o=n.heading.propSchema.level.values)!=null&&o.includes(2)&&t.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>z(r,{type:"heading",props:{level:2}})}),(i=n.heading.propSchema.level.values)!=null&&i.includes(3)&&t.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>z(r,{type:"heading",props:{level:3}})})),"bulletListItem"in n&&t.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>z(r,{type:"bulletListItem"})}),"numberedListItem"in n&&t.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>z(r,{type:"numberedListItem"})}),"paragraph"in n&&t.push({name:"Paragraph",aliases:["p"],execute:r=>z(r,{type:"paragraph"})}),"table"in n&&t.push({name:"Table",aliases:["table"],execute:r=>{z(r,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})}}),"image"in n&&t.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{const s=z(r,{type:"image"});r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(W,{block:s}))}}),t};let D;function Tt(){D||(D=document.createElement("div"),D.innerHTML="_",D.style.visibility="hidden",document.body.appendChild(D))}function mo(){D&&(document.body.removeChild(D),D=void 0)}function ae(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function fo(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function go(n){n.forEach(t=>{const e=document.getElementsByClassName(t);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"})}class Ct{constructor(t,e,o){p(this,"state");p(this,"updateState");p(this,"tableId");p(this,"tablePos");p(this,"menuFrozen",!1);p(this,"prevWasEditable",null);p(this,"mouseMoveHandler",t=>{var d;if(this.menuFrozen)return;const e=fo(t.target);if(!e||!this.editor.isEditable){(d=this.state)!=null&&d.show&&(this.state.show=!1,this.updateState());return}const o=ae(e),i=ae(e.parentElement),r=e.getBoundingClientRect(),s=e.parentElement.parentElement.getBoundingClientRect(),a=se(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((u,h)=>typeof l<"u"?!1:u.type.name!=="blockContainer"||u.attrs.id!==a.id?!0:(l=L(u,this.editor.blockSchema,this.editor.inlineContentSchema,this.editor.styleSchema,this.editor.blockCache),this.tablePos=h+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.updateState(),!1});p(this,"dragOverHandler",t=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",go(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const e={left:Math.min(Math.max(t.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(t.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(e.left,e.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=ae(i.parentElement),a=ae(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,u=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?e.top:e.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,r=!0),r&&this.updateState(),u&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});p(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const e=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=e[this.state.draggingState.originalIndex];e.splice(this.state.draggingState.originalIndex,1),e.splice(this.state.rowIndex,0,o)}else{const o=e.map(i=>i.cells[this.state.draggingState.originalIndex]);e.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:e}})});p(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=e.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=e.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.updateState()}});this.editor=t,this.pmView=e,this.updateState=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},e.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const J=new y.PluginKey("TableHandlesPlugin");class Mt extends K{constructor(e){super();p(this,"view");p(this,"plugin");p(this,"colDragStart",e=>{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:e.clientX},this.view.updateState(),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})),Tt(),e.dataTransfer.setDragImage(D,0,0),e.dataTransfer.effectAllowed="move"});p(this,"rowDragStart",e=>{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:e.clientY},this.view.updateState(),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})),Tt(),e.dataTransfer.setDragImage(D,0,0),e.dataTransfer.effectAllowed="copyMove"});p(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.updateState(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),mo()});p(this,"freezeHandles",()=>this.view.menuFrozen=!0);p(this,"unfreezeHandles",()=>this.view.menuFrozen=!1);this.editor=e,this.plugin=new y.Plugin({key:J,view:o=>(this.view=new Ct(e,o,i=>{this.emit("update",i)}),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 i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return N.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),d=l.node();for(let u=0;u<d.childCount;u++){const h=o.doc.resolve(l.posAtIndex(u)+1),f=h.node(),m=h.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(N.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const d=o.doc.resolve(s.posAtIndex(l)+1),u=o.doc.resolve(d.posAtIndex(i)+1),h=u.node(),f=u.pos+(i>this.view.state.draggingState.originalIndex?h.nodeSize-2:0);r.push(N.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return N.DecorationSet.create(o.doc,r)}}})}onUpdate(e){return this.on("update",e)}}const bo=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){const t=this.editor,e=this.editor.schema;return[new y.Plugin({props:{handleDOMEvents:{copy(o,i){i.preventDefault(),i.clipboardData.clearData();const r=t.state.selection.content().content,a=me(e,n).serializeProseMirrorFragment(r),d=Z(e,n).exportProseMirrorFragment(r),u=xe(d);return i.clipboardData.setData("blocknote/html",a),i.clipboardData.setData("text/html",d),i.clipboardData.setData("text/plain",u),!0}}}})]}}),yo=["blocknote/html","text/html","text/plain"],ko=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{paste(t,e){e.preventDefault();let o=null;for(const i of yo)if(e.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=e.clipboardData.getData(o);o==="text/html"&&(i=dt(i.trim()).innerHTML,console.log(i)),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),wo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:P.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):P.backgroundColor.default,renderHTML:n=>n.backgroundColor!==P.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),vo=new y.PluginKey("blocknote-placeholder"),So=b.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"bn-is-editor-empty",emptyNodeClass:"bn-is-empty",isFilterClass:"bn-is-filter",hasAnchorClass:"bn-has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new y.Plugin({key:vo,props:{decorations:n=>{const{doc:t,selection:e}=n,o=re.getState(n),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=e,s=[];if(i)return t.descendants((a,l)=>{const d=r>=l&&r<=l+a.nodeSize,u=!a.isLeaf&&!a.childCount;if((d||!this.options.showOnlyCurrent)&&u){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),d&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&h.push(this.options.isFilterClass);const f=N.Decoration.node(l,l+a.nodeSize,{class:h.join(" ")});s.push(f)}return this.options.includeChildren}),N.DecorationSet.create(t,s)}}})]}}),Eo=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),To=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:P.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):P.textColor.default,renderHTML:n=>n.textColor!==P.textColor.default&&{"data-text-color":n.textColor}}}}]}}),Co=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new y.PluginKey(this.name);return[new y.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,d=s.nodes.blockContainer,u=s.nodes.paragraph;if(a)return r.insert(l,d.create(void 0,u.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Mo=new y.PluginKey("non-editable-block"),xo=()=>new y.Plugin({key:Mo,props:{handleKeyDown:(n,t)=>{"node"in n.state.selection&&t.preventDefault()}}}),xt=new y.PluginKey("previous-blocks"),Bo={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Io=()=>{let n;return new y.Plugin({key:xt,view(t){return{update:async(e,o)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(xt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(i.doc))return e;const r={},s=b.findChildren(o.doc,d=>d.attrs.id),a=new Map(s.map(d=>[d.node.attrs.id,d])),l=b.findChildren(i.doc,d=>d.attrs.id);for(const d of l){const u=a.get(d.node.attrs.id),h=u==null?void 0:u.node.firstChild,f=d.node.firstChild;if(u&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(d.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(u.pos).depth};r[d.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in e.prevTransactionOldBlockAttrs&&(g=e.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),e.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,e.updatedBlocks.add(d.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[d,u]of Object.entries(s))a["data-prev-"+Bo[d]]=u||"none";const l=N.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),N.DecorationSet.create(t.doc,o)}}})},Po={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ho=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const t={};for(const[e,o]of Object.entries(Po))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:n}){var i;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);const e={...((i=this.options.domAttributes)==null?void 0:i.blockContainer)||{},...n},o=document.createElement("div");o.className=O("bn-block",e.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(e))r!=="class"&&o.setAttribute(r,s);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:t,dispatch:e})=>{const o=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:t,dispatch:e})=>{const o=T(t.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,t)=>({state:e,dispatch:o})=>{const i=T(e.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(t.children!==void 0){const f=[];for(const m of t.children)f.push(_(m,e.schema,this.options.editor.styleSchema));a.childCount===2?e.tr.replace(r+l.nodeSize+1,s-1,new k.Slice(k.Fragment.from(f),0,0)):e.tr.insert(r+l.nodeSize,e.schema.nodes.blockGroup.create({},f))}const d=l.type.name,u=t.type||d;let h="keep";if(t.content)if(typeof t.content=="string")h=[e.schema.text(t.content)];else if(Array.isArray(t.content))h=ne(t.content,e.schema,this.options.editor.styleSchema);else if(t.content.type==="tableContent")h=pe(t.content,e.schema,this.options.editor.styleSchema);else throw new A(t.content.type);else{const f=e.schema.nodes[d].spec.content,m=e.schema.nodes[u].spec.content;f===""||m!==f&&(h=[])}h==="keep"?e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...l.attrs,...t.props}):e.tr.replaceWith(r,s,e.schema.nodes[u].create({...l.attrs,...t.props},h)).setSelection(e.schema.nodes[u].spec.content===""?new y.NodeSelection(e.tr.doc.resolve(r)):e.schema.nodes[u].spec.content==="inline*"?new y.TextSelection(e.tr.doc.resolve(r)):new y.TextSelection(e.tr.doc.resolve(r+4))),e.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...t.props})}return!0},BNMergeBlocks:n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n+1).node().type.name==="blockContainer",i=t.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=T(t.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:d,depth:u}=r;if(s.childCount===2){const m=t.doc.resolve(l+a.nodeSize+1),g=t.doc.resolve(d-1),E=m.blockRange(g);e&&t.tr.lift(E,u-1)}let h=n-1,f=T(t.doc,h);for(;f.numChildBlocks>0;)if(h--,f=T(t.doc,h),f===void 0)return!1;return e&&(e(t.tr.deleteRange(l,l+a.nodeSize).replace(h-1,l,new k.Slice(a.content,0,0)).scrollIntoView()),t.tr.setSelection(new y.TextSelection(t.doc.resolve(h-1)))),!0},BNSplitBlock:(n,t)=>({state:e,dispatch:o})=>{const i=T(e.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:d}=i,u=e.doc.cut(a+1,n),h=e.doc.cut(n,l-1),f=e.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(e.tr.insert(m,f),e.tr.replace(g,g+1,h.content.size>0?new k.Slice(k.Fragment.from(h),d+2,d+2):void 0),t&&e.tr.setBlockType(g,g,e.schema.node(s).type,r.attrs),e.tr.setSelection(new y.TextSelection(e.doc.resolve(g))),e.tr.replace(a+1,l-1,u.content.size>0?new k.Slice(k.Fragment.from(u),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Io(),xo()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=T(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=T(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=T(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,d=s===2,u=s-1;return!d&&a&&l&&r===2?o.BNMergeBlocks(u):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=T(i.doc,i.selection.from),l=i.selection.from===a-1,d=i.selection.empty,u=r.childCount===2;if(l&&d&&!u){let h=s,f=a+2,m=i.doc.resolve(f).depth;for(;m<h;)h=m,f+=2,m=i.doc.resolve(f).depth;return o.BNMergeBlocks(f-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=T(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,d=r.textContent.length===0,u=s>2;return a&&l&&d&&u?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=T(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,d=i.selection.anchor===i.selection.head,u=s.textContent.length===0;if(l&&d&&u){const h=a+1,f=h+2;return r().BNCreateBlock(h).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=T(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2)}}}),No=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},e=document.createElement("div");e.className=O("bn-block-group",t.class),e.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(t))i!=="class"&&e.setAttribute(i,r);return{dom:e,contentDOM:e}}}),Lo=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Bt=n=>{var e;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Jt.Gapcursor,So.configure({includeChildren:!0,showOnlyCurrent:!1}),$.configure({types:["blockContainer"]}),Yt.HardBreak,en.Text,Qt.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),To,wo,Eo,Lo,Ho.configure({editor:n.editor,domAttributes:n.domAttributes}),No.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),bo(n.editor),ko(n.editor),Xt.Dropcursor.configure({width:5,color:"#ddeeff"}),Co];if(n.collaboration){if(t.push(un.default.configure({fragment:n.collaboration.fragment})),(e=n.collaboration.provider)!=null&&e.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};t.push(pn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else t.push(Zt.History);return t};function Ao(n,t){const e=[];return n.forEach((o,i,r)=>{r!==t&&e.push(o)}),k.Fragment.from(e)}function Do(n,t){let e=k.Fragment.from(n.content);for(let o=0;o<e.childCount;o++)if(e.child(o).type.spec.group==="blockContent"){const i=[e.child(o)];if(o+1<e.childCount&&e.child(o+1).type.spec.group==="blockGroup"){const s=e.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(e.child(o+1)),e=Ao(e,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,i);e=e.replaceChild(o,r)}return new k.Slice(e,n.openStart,n.openEnd)}const Vo="",Uo="",_o={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ie{constructor(t){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"ready",!1);p(this,"sideMenu");p(this,"formattingToolbar");p(this,"slashMenu");p(this,"hyperlinkToolbar");p(this,"imageToolbar");p(this,"tableHandles");p(this,"uploadFile");var l,d,u,h,f,m,g,E,M,x;this.options=t;const e={defaultStyles:!0,blockSpecs:t.blockSpecs||Se,styleSpecs:t.styleSpecs||Te,inlineContentSpecs:t.inlineContentSpecs||Ce,...t};this.blockSchema=ye(e.blockSpecs),this.inlineContentSchema=ke(e.inlineContentSpecs),this.styleSchema=ve(e.styleSpecs),this.blockImplementations=e.blockSpecs,this.inlineContentImplementations=e.inlineContentSpecs,this.styleImplementations=e.styleSpecs,this.sideMenu=new St(this),this.formattingToolbar=new ht(this),this.slashMenu=new bt(this,e.slashMenuItems||Et(this.blockSchema)),this.hyperlinkToolbar=new ft(this),this.imageToolbar=new ot(this),this.blockSchema.table===Ee.table&&(this.tableHandles=new Mt(this));const o=Bt({editor:this,domAttributes:e.domAttributes||{},blockSchema:this.blockSchema,blockSpecs:e.blockSpecs,styleSpecs:e.styleSpecs,inlineContentSpecs:e.inlineContentSpecs,collaboration:e.collaboration}),i=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin,...this.tableHandles?[this.tableHandles.plugin]:[]]});o.push(i),this.uploadFile=e.uploadFile,e.collaboration&&e.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const r=e.initialContent||(t.collaboration?void 0:[{type:"paragraph",id:$.options.generateID()}]),s=this.styleSchema,a={..._o,...e._tiptapOptions,onBeforeCreate(S){var H,Y;(Y=(H=e._tiptapOptions)==null?void 0:H.onBeforeCreate)==null||Y.call(H,S);const w=S.editor.schema;let C;const B=w.nodes.doc.createAndFill;w.nodes.doc.createAndFill=(...te)=>{if(C)return C;const q=B.apply(w.nodes.doc,te),Nt=JSON.parse(JSON.stringify(q.toJSON()));return Nt.content[0].content[0].attrs.id="initialBlockId",C=k.Node.fromJSON(w,Nt),q};const v=w.node("doc",void 0,w.node("blockGroup",void 0,[_({id:"initialBlockId",type:"paragraph"},w,s)]));S.editor.options.content=v.toJSON()},onCreate:S=>{var w,C,B;(C=(w=e._tiptapOptions)==null?void 0:w.onCreate)==null||C.call(w,S),r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(B=e.onEditorReady)==null||B.call(e,this),this.ready=!0},onUpdate:S=>{var w,C,B;(C=(w=e._tiptapOptions)==null?void 0:w.onUpdate)==null||C.call(w,S),this.ready&&((B=e.onEditorContentChange)==null||B.call(e,this))},onSelectionUpdate:S=>{var w,C,B;(C=(w=e._tiptapOptions)==null?void 0:w.onSelectionUpdate)==null||C.call(w,S),this.ready&&((B=e.onTextCursorPositionChange)==null||B.call(e,this))},editable:t.editable!==void 0?t.editable:((l=e._tiptapOptions)==null?void 0:l.editable)!==void 0?(d=e._tiptapOptions)==null?void 0:d.editable:!0,extensions:e.enableBlockNoteExtensions===!1?((u=e._tiptapOptions)==null?void 0:u.extensions)||[]:[...((h=e._tiptapOptions)==null?void 0:h.extensions)||[],...o],editorProps:{...(f=e._tiptapOptions)==null?void 0:f.editorProps,attributes:{...(g=(m=e._tiptapOptions)==null?void 0:m.editorProps)==null?void 0:g.attributes,...(E=e.domAttributes)==null?void 0:E.editor,class:O("bn-root","bn-editor",e.defaultStyles?"bn-default-styles":"",((x=(M=e.domAttributes)==null?void 0:M.editor)==null?void 0:x.class)||"")},transformPasted:Do}};e.parentElement&&(a.element=e.parentElement),this._tiptapEditor=new b.Editor(a)}static create(t={}){return new Ie(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(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(L(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(o=L(i,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),!1)),o}forEachBlock(t,e=!1){const o=this.topLevelBlocks.slice();e&&o.reverse();function i(r){for(const s of r){if(!t(s))return!1;const a=e?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:o,endPos:i}=T(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(e-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:L(t,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:L(a,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:L(l,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)}}setTextCursorPosition(t,e="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:i}=Me(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=T(this._tiptapEditor.state.doc,i+2),a=this.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")e==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new A(a)}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((e,o)=>e.type.spec.group!=="blockContent"||o+e.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(L(this._tiptapEditor.state.doc.resolve(o).node(),this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.setEditable(t)}insertBlocks(t,e,o="before"){at(t,e,o,this)}updateBlock(t,e){Jn(t,e,this._tiptapEditor)}removeBlocks(t){lt(t,this._tiptapEditor)}replaceBlocks(t,e){Yn(t,e,this)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks();for(const o of e){const i=this.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?t[i.type]=!0:t[i.type]=o.attrs.stringValue}return t}addStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(e,{stringValue:o});else throw new A(i.propSchema)}}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(e,{stringValue:o});else throw new A(i.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,e){if(t==="")return;const{from:o,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,o,i).addMark(o,o+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=T(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(e-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=T(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.topLevelBlocks){return Z(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return ct(t,this.blockSchema,this.inlineContentSchema,this.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.topLevelBlocks){return Qn(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return ro(t,this.blockSchema,this.inlineContentSchema,this.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)}}function Pe(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function It(n){return typeof n=="string"?Pe(n):Array.isArray(n)?n.flatMap(t=>typeof t=="string"?Pe(t):ce(t)?{...t,content:Pe(t.content)}:G(t)?t:{props:{},...t,content:It(t.content)}):n}function Oo(n,t){return t.map(e=>He(n,e))}function He(n,t){const e={id:"",type:t.type,props:{},content:n[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(n[t.type].propSchema).forEach(([o,i])=>{e.props[o]===void 0&&(e.props[o]=i.default)}),{...e,content:It(e.content),children:e.children.map(o=>He(n,o))}}function Pt(n){n.id||(n.id=$.options.generateID()),n.children&&Ht(n.children)}function Ht(n){for(const t of n)Pt(t)}c.BlockNoteEditor=Ie,c.FormattingToolbarProsemirrorPlugin=ht,c.FormattingToolbarView=ut,c.HyperlinkToolbarProsemirrorPlugin=ft,c.ImageToolbarProsemirrorPlugin=ot,c.ImageToolbarView=nt,c.SideMenuProsemirrorPlugin=St,c.SideMenuView=wt,c.SlashMenuProsemirrorPlugin=bt,c.TableHandlesProsemirrorPlugin=Mt,c.TableHandlesView=Ct,c.UniqueID=$,c.UnreachableCaseError=A,c.addIdsToBlock=Pt,c.addIdsToBlocks=Ht,c.addInlineContentAttributes=We,c.addInlineContentKeyboardShortcuts=Xe,c.addStyleAttributes=et,c.blockToNode=_,c.camelToDataKebab=ee,c.contentNodeToInlineContent=oe,c.createBlockSpec=Ke,c.createBlockSpecFromStronglyTypedTiptapNode=j,c.createExternalHTMLExporter=Z,c.createInlineContentSpec=vn,c.createInlineContentSpecFromTipTapNode=Ye,c.createInternalBlockSpec=be,c.createInternalHTMLSerializer=me,c.createInternalInlineContentSpec=Je,c.createInternalStyleSpec=we,c.createStronglyTypedTiptapNode=U,c.createStyleSpec=Sn,c.createStyleSpecFromTipTapMark=R,c.defaultBlockSchema=Ee,c.defaultBlockSpecs=Se,c.defaultInlineContentSchema=Xn,c.defaultInlineContentSpecs=Ce,c.defaultProps=P,c.defaultStyleSchema=Wn,c.defaultStyleSpecs=Te,c.formatKeyboardShortcut=wn,c.formattingToolbarPluginKey=pt,c.getBlockFromPos=Ge,c.getBlockNoteExtensions=Bt,c.getBlockSchemaFromSpecs=ye,c.getDefaultSlashMenuItems=Et,c.getDraggableBlockFromCoords=se,c.getInlineContentParseRules=Ze,c.getInlineContentSchemaFromSpecs=ke,c.getParseRules=je,c.getStyleParseRules=tt,c.getStyleSchemaFromSpecs=ve,c.hyperlinkToolbarPluginKey=mt,c.imageToolbarPluginKey=W,c.inheritedProps=fe,c.inlineContentToNodes=ne,c.isAppleOS=qe,c.isLinkInlineContent=de,c.isPartialLinkInlineContent=ce,c.isStyledTextInlineContent=G,c.mergeCSSClasses=O,c.nodeToBlock=L,c.nodeToCustomInlineContent=he,c.partialBlockToBlockForTesting=He,c.partialBlocksToBlocksForTesting=Oo,c.propsToAttributes=ge,c.setupSuggestionsMenu=gt,c.sideMenuPluginKey=vt,c.slashMenuPluginKey=re,c.stylePropsToAttributes=Qe,c.tableContentToNodes=pe,c.tableHandlesPluginKey=J,c.uploadToTmpFilesDotOrg_DEV_ONLY=kn,c.wrapInBlockStructure=ie,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
5
|
+
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&e[r.type.name]){i&&(o.push(i),i=void 0),o.push(he(r,e,t));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const c=t[l.type.name];if(!c)throw new Error(`style ${l.type.name} not found in styleSchema`);if(c.propSchema==="boolean")s[c.type]=!0;else if(c.propSchema==="string")s[c.type]=l.attrs.stringValue;else throw new D(c.propSchema)}i?G(i)?a?(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):JSON.stringify(i.styles)===JSON.stringify(s)?i.text+=r.textContent:(o.push(i),i={type:"text",text:r.textContent,styles:s}):ce(i)&&(a?i.href===a.attrs.href?JSON.stringify(i.content[i.content.length-1].styles)===JSON.stringify(s)?i.content[i.content.length-1].text+=r.textContent:i.content.push({type:"text",text:r.textContent,styles:s}):(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):(o.push(i),i={type:"text",text:r.textContent,styles:s})):a?i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}:i={type:"text",text:r.textContent,styles:s}}),i&&o.push(i),o}function he(n,e,t){if(n.type.name==="text"||n.type.name==="link")throw new Error("unexpected");const o={},i=e[n.type.name];for(const[a,l]of Object.entries(n.attrs)){if(!i)throw Error("ic node is of an unrecognized type: "+n.type.name);const c=i.propSchema;a in c&&(o[a]=l)}let r;return i.content==="styled"?r=oe(n,e,t):r=void 0,{type:n.type.name,props:o,content:r}}function I(n,e,t,o,i){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const r=i==null?void 0:i.get(n);if(r)return r;const s=Re(n);let a=s.id;a===null&&(a=$.options.generateID());const l={};for(const[m,g]of Object.entries({...n.attrs,...s.contentNode.attrs})){const T=e[s.contentType.name];if(!T)throw Error("Block is of an unrecognized type: "+s.contentType.name);const M=T.propSchema;m in M&&(l[m]=g)}const c=e[s.contentType.name],d=[];for(let m=0;m<s.numChildBlocks;m++)d.push(I(n.lastChild.child(m),e,t,o,i));let h;if(c.content==="inline")h=oe(s.contentNode,t,o);else if(c.content==="table")h=gn(s.contentNode,t,o);else if(c.content==="none")h=void 0;else throw new D(c.content);const f={id:a,type:c.type,props:l,content:h,children:d};return i==null||i.set(n,f),f}function bn(n){return n.document||window.document}const Ve=(n,e,t,o,i)=>{if(!t.nodes[n.type.name])throw new Error("Serializer is missing a node type: "+n.type.name);const{dom:r,contentDOM:s}=y.DOMSerializer.renderSpec(bn(e),t.nodes[n.type.name](n));if(s){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(n.type.name==="blockContainer"){const a=n.childCount>0&&n.firstChild.type.spec.group==="blockContent"?n.firstChild:void 0,l=n.childCount>0&&n.lastChild.type.spec.group==="blockGroup"?n.lastChild:void 0;if(a!==void 0){const c=o.blockImplementations[a.type.name].implementation,h=(i?c.toExternalHTML:c.toInternalHTML)(I(n,o.blockSchema,o.inlineContentSchema,o.styleSchema,o.blockCache),o);if(h.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");h.contentDOM.appendChild(t.serializeFragment(a.content,e))}s.appendChild(h.dom)}l!==void 0&&t.serializeFragment(y.Fragment.from(l),e,s)}else t.serializeFragment(n.content,e,s)}return r},Ue=(n,e)=>{const t=e.serializeFragment(n),o=document.createElement("div");return o.appendChild(t),o.innerHTML};function kn(n){const e=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),t=o=>{var s;if(o.children.length===1&&((s=o.children[0].properties)==null?void 0:s.dataNodeType)==="blockGroup"){const a=o.children[0];o.children.pop(),o.children.push(...a.children)}let i=o.children.length,r;for(let a=0;a<i;a++){const c=o.children[a].children[0],d=c.children[0],h=c.children.length===2?c.children[1]:null,f=e.has(d.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(h!==null&&t(h),r&&r.tagName!==m){o.children.splice(a-r.children.length,r.children.length,r);const g=r.children.length-1;a-=g,i-=g,r=void 0}if(f){r||(r=Le.fromDom(document.createElement(m)));const g=Le.fromDom(document.createElement("li"));g.children.push(d.children[0]),h!==null&&g.children.push(...h.children),r.children.push(g)}else if(h!==null){o.children.splice(a+1,0,...h.children),o.children[a]=d.children[0];const g=h.children.length;a+=g,i+=g}else o.children[a]=d.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return t}const Z=(n,e)=>{const t=y.DOMSerializer.fromSchema(n);return t.serializeNodeInner=(o,i)=>Ve(o,i,t,e,!0),t.exportProseMirrorFragment=o=>le.unified().use(De.default,{fragment:!0}).use(kn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(_e.default).processSync(Ue(o,t)).value,t.exportBlocks=o=>{const i=o.map(s=>_(s,n,e.styleSchema)),r=n.nodes.blockGroup.create(null,i);return t.exportProseMirrorFragment(y.Fragment.from(r))},t},me=(n,e)=>{const t=y.DOMSerializer.fromSchema(n);return t.serializeNodeInner=(o,i)=>Ve(o,i,t,e,!1),t.serializeProseMirrorFragment=o=>Ue(o,t),t.serializeBlocks=o=>{const i=o.map(s=>_(s,n,e.styleSchema)),r=n.nodes.blockGroup.create(null,i);return t.serializeProseMirrorFragment(y.Fragment.from(r))},t},yn=async n=>{const e=new FormData;return e.append("file",n),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:e})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},qe=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function Sn(n){return qe()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function O(...n){return n.filter(e=>e).join(" ")}function Q(n,e,t,o){const i=document.createElement("div");i.className=O("bn-block-content",t.class),i.setAttribute("data-content-type",n);for(const[s,a]of Object.entries(t))s!=="class"&&i.setAttribute(s,a);const r=document.createElement(e);r.className=O("bn-inline-content",o.class);for(const[s,a]of Object.entries(o))s!=="class"&&r.setAttribute(s,a);return i.appendChild(r),{dom:i,contentDOM:r}}const $e=(n,e)=>{const t=_(n,e._tiptapEditor.schema,e.styleSchema).firstChild,o=e._tiptapEditor.schema.nodes[t.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 i=o(t);if(typeof i!="object"||!("dom"in i))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 i},H={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},fe=["backgroundColor","textColor"];function ee(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ge(n){const e={};return Object.entries(n).filter(([t,o])=>!fe.includes(t)).forEach(([t,o])=>{e[t]={default:o.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(ee(t));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[t]!==o.default?{[ee(t)]:i[t]}:{}}}),e}function Ge(n,e,t,o){if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const i=n(),s=t.state.doc.resolve(i).node().attrs.id,a=e.getBlock(s);if(a.type!==o)throw new Error("Block type does not match");return a}function ie(n,e,t,o,i){const r=document.createElement("div");if(i!==void 0)for(const[s,a]of Object.entries(i))s!=="class"&&r.setAttribute(s,a);r.className=O("bn-block-content",(i==null?void 0:i.class)||""),r.setAttribute("data-content-type",e);for(const[s,a]of Object.entries(t))!fe.includes(s)&&a!==o[s].default&&r.setAttribute(ee(s),a);return r.appendChild(n.dom),n.contentDOM!==void 0&&(n.contentDOM.className=O("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function U(n){return b.Node.create(n)}function be(n,e){return{config:n,implementation:e}}function j(n,e,t){return be({type:n.name,content:n.config.content==="inline*"?"inline":n.config.content==="tableRow+"?"table":"none",propSchema:e},{node:n,requiredExtensions:t,toInternalHTML:$e,toExternalHTML:$e})}function ke(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function je(n,e){const t=[{tag:"[data-content-type="+n.type+"]",contentElement:"[data-editable]"}];return e&&t.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const i=e==null?void 0:e(o);return i===void 0?!1:i}}),t}function Ke(n,e){const t=U({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return ge(n.propSchema)},parseHTML(){return je(n,e.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const i=this.options.editor,r=Ge(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=e.render(r,i);return ie(a,r.type,r.props,n.propSchema,s)}}});if(t.name!==n.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return be(n,{node:t,toInternalHTML:(o,i)=>{var a;const r=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{},s=e.render(o,i);return ie(s,o.type,o.props,n.propSchema,r)},toExternalHTML:(o,i)=>{var a,l;const r=((a=t.options.domAttributes)==null?void 0:a.blockContent)||{};let s=(l=e.toExternalHTML)==null?void 0:l.call(e,o,i);return s===void 0&&(s=e.render(o,i)),ie(s,o.type,o.props,n.propSchema,r)}})}function We(n,e,t,o){return n.dom.setAttribute("data-inline-content-type",e),Object.entries(t).filter(([i,r])=>r!==o[i].default).map(([i,r])=>[ee(i),r]).forEach(([i,r])=>n.dom.setAttribute(i,r)),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Xe(n){return{Backspace:({editor:e})=>{const t=e.state.selection.$from;return e.state.selection.empty&&t.node().type.name===n.type&&t.parentOffset===0}}}function Je(n,e){return{config:n,implementation:e}}function Ye(n,e){return Je({type:n.name,propSchema:e,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function ye(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function Ze(n){return[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:e=>{const t=e;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function wn(n,e){const t=b.Node.create({name:n.type,inline:!0,group:"inline",selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return ge(n.propSchema)},addKeyboardShortcuts(){return Xe(n)},parseHTML(){return Ze(n)},renderHTML({node:o}){const i=this.options.editor,r=e.render(he(o,i.inlineContentSchema,i.styleSchema));return We(r,n.type,o.attrs,n.propSchema)}});return Ye(t,n.propSchema)}function Qe(n){return n==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:e=>e.getAttribute("data-value"),renderHTML:e=>e.stringValue!==void 0?{"data-value":e.stringValue}:{}}}}function et(n,e,t,o){return n.dom.setAttribute("data-style-type",e),o==="string"&&n.dom.setAttribute("data-value",t),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Se(n,e){return{config:n,implementation:e}}function R(n,e){return Se({type:n.name,propSchema:e},{mark:n})}function we(n){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.config]))}function tt(n){return[{tag:`[data-style-type="${n.type}"]`,contentElement:e=>{const t=e;return t.matches("[data-editable]")?t:t.querySelector("[data-editable]")||t}}]}function vn(n,e){const t=b.Mark.create({name:n.type,addAttributes(){return Qe(n.propSchema)},parseHTML(){return tt(n)},renderHTML({mark:o}){let i;if(n.propSchema==="boolean")i=e.render();else if(n.propSchema==="string")i=e.render(o.attrs.stringValue);else throw new D(n.propSchema);return et(i,n.type,o.attrs.stringValue,n.propSchema)}});return Se(n,{mark:t})}const Tn=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{stringValue:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),En=R(Tn,"string"),Cn=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{stringValue:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Mn=R(Cn,"string"),xn={...H,level:{default:1,values:[1,2,3]}},Bn=U({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:n=>{const e=n.getAttribute("data-level"),t=parseInt(e);if(isFinite(t))return t},renderHTML:n=>({"data-level":n.level.toString()})}}},addInputRules(){return[...[1,2,3].map(n=>new b.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:e,chain:t,range:o})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:n=>typeof n=="string"?!1:{level:n.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:n,HTMLAttributes:e}){var t,o;return Q(this.name,`h${n.attrs.level}`,{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...e},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),In=j(Bn,xn);class K{constructor(){p(this,"callbacks",{})}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),()=>this.off(e,t)}emit(e,...t){const o=this.callbacks[e];o&&o.forEach(i=>i.apply(this,t))}off(e,t){const o=this.callbacks[e];o&&(t?this.callbacks[e]=o.filter(i=>i!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}class nt{constructor(e,t,o){p(this,"imageToolbarState");p(this,"updateImageToolbar");p(this,"prevWasEditable",null);p(this,"mouseDownHandler",()=>{var e;(e=this.imageToolbarState)!=null&&e.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"dragstartHandler",()=>{var e;(e=this.imageToolbarState)!=null&&e.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"blurHandler",e=>{var o;const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(o=this.imageToolbarState)!=null&&o.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"scrollHandler",()=>{var e;if((e=this.imageToolbarState)!=null&&e.show){const t=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=t.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=e,this.pmView=t,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");o(this.imageToolbarState)},t.dom.addEventListener("mousedown",this.mouseDownHandler),t.dom.addEventListener("dragstart",this.dragstartHandler),t.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var i,r;const o=this.pluginKey.getState(e.state);if(!((i=this.imageToolbarState)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.updateImageToolbar();return}(!e.state.selection.eq(t.selection)||!e.state.doc.eq(t.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const W=new k.PluginKey("ImageToolbarPlugin");class ot extends K{constructor(t){super();p(this,"view");p(this,"plugin");this.plugin=new k.Plugin({key:W,view:o=>(this.view=new nt(W,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(W))==null?void 0:r.block}}}})}onUpdate(t){return this.on("update",t)}}const Pn={textAlignment:H.textAlignment,backgroundColor:H.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},it=n=>{switch(n){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},rt=64,Hn=Ke({type:"image",propSchema:Pn,content:"none"},{render:(n,e)=>{const t=document.createElement("div");t.className="bn-image-block-content-wrapper",t.style.alignItems=it(n.props.textAlignment);const o=document.createElement("div");o.className="bn-add-image-button";const i=document.createElement("div");i.className="bn-add-image-button-icon";const r=document.createElement("p");r.className="bn-add-image-button-text",r.innerText="Add Image";const s=document.createElement("div");s.className="bn-image-and-caption-wrapper";const a=document.createElement("div");a.className="bn-image-wrapper";const l=document.createElement("img");l.className="bn-image",l.src=n.props.url,l.alt="placeholder",l.contentEditable="false",l.draggable=!1,l.style.width=`${Math.min(n.props.width,e.domElement.firstElementChild.clientWidth)}px`;const c=document.createElement("div");c.className="bn-image-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-image-resize-handle",d.style.right="4px";const h=document.createElement("p");h.className="bn-image-caption",h.innerText=n.props.caption,h.style.padding=n.props.caption?"4px":"";const f=()=>{var te;const w=((te=e.getSelection())==null?void 0:te.blocks)||[];[e.getTextCursorPosition().block,...w].find(q=>q.id===n.id)!==void 0?(o.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(o.style.outline="",s.style.outline="")};e.onEditorContentChange(f),e.onEditorSelectionChange(f);let m;const g=w=>{if(!m)return;let L;it(n.props.textAlignment)==="center"?m.handleUsed==="left"?L=m.initialWidth+(m.initialClientX-w.clientX)*2:L=m.initialWidth+(w.clientX-m.initialClientX)*2:m.handleUsed==="left"?L=m.initialWidth+m.initialClientX-w.clientX:L=m.initialWidth+w.clientX-m.initialClientX,L<rt?l.style.width=`${rt}px`:L>e.domElement.firstElementChild.clientWidth?l.style.width=`${e.domElement.firstElementChild.clientWidth}px`:l.style.width=`${L}px`},T=w=>{m&&((!w.target||!a.contains(w.target))&&a.contains(c)&&a.contains(d)&&(a.removeChild(c),a.removeChild(d)),m=void 0,e.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},M=w=>{w.preventDefault()},x=()=>{e._tiptapEditor.view.dispatch(e._tiptapEditor.state.tr.setMeta(W,{block:n}))},v=()=>{e.isEditable?(a.appendChild(c),a.appendChild(d)):(a.removeChild(c),a.removeChild(d))},S=w=>{w.relatedTarget===c||w.relatedTarget===d||m||(a.removeChild(c),a.removeChild(d))},C=w=>{w.preventDefault(),a.appendChild(c),a.appendChild(d),m={handleUsed:"left",initialWidth:n.props.width,initialClientX:w.clientX}},B=w=>{w.preventDefault(),a.appendChild(c),a.appendChild(d),m={handleUsed:"right",initialWidth:n.props.width,initialClientX:w.clientX}};return o.appendChild(i),o.appendChild(r),s.appendChild(a),a.appendChild(l),s.appendChild(h),n.props.url===""?t.appendChild(o):t.appendChild(s),window.addEventListener("mousemove",g),window.addEventListener("mouseup",T),o.addEventListener("mousedown",M),o.addEventListener("click",x),l.addEventListener("mouseenter",v),l.addEventListener("mouseleave",S),c.addEventListener("mousedown",C),d.addEventListener("mousedown",B),{dom:t,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",T),o.removeEventListener("mousedown",M),o.removeEventListener("click",x),c.removeEventListener("mousedown",C),d.removeEventListener("mousedown",B)}}},toExternalHTML:n=>{if(n.props.url===""){const o=document.createElement("p");return o.innerHTML="Add Image",{dom:o}}const e=document.createElement("figure"),t=document.createElement("img");if(t.src=n.props.url,e.appendChild(t),n.props.caption!==""){const o=document.createElement("figcaption");o.innerHTML=n.props.caption,e.appendChild(o)}return{dom:e}},parse:n=>{if(n.tagName==="FIGURE"){const e=n.querySelector("img"),t=n.querySelector("figcaption");return{url:(e==null?void 0:e.getAttribute("src"))||"",caption:(t==null?void 0:t.textContent)||(e==null?void 0:e.getAttribute("alt"))||void 0}}else if(n.tagName==="IMG")return{url:n.getAttribute("src")||"",caption:n.getAttribute("alt")||void 0}}}),st=n=>{const{node:e,contentType:t}=E(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!t.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},Ln={...H},Nn=U({name:"bulletListItem",content:"inline*",group:"blockContent",addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>st(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="UL"||e.tagName==="DIV"&&e.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){var e,t;return Q(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),An=j(Nn,Ln),Dn=new k.PluginKey("numbered-list-indexing"),_n=()=>new k.Plugin({key:Dn,appendTransaction:(n,e,t)=>{const o=t.tr;o.setMeta("numberedListIndexing",!0);let i=!1;return t.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,c=E(o.doc,s+1);if(c===void 0)return;if(!l){const f=E(o.doc,s-2);if(f===void 0)return;if(!(c.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const x=g.attrs.index;a=(parseInt(x)+1).toString()}}}c.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),On={...H},Rn=U({name:"numberedListItem",content:"inline*",group:"blockContent",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:e,range:t})=>{e().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>st(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[_n()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.tagName==="OL"||e.tagName==="DIV"&&e.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const e=n.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){var e,t;return Q(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Fn=j(Rn,On),zn={...H},Vn=U({name:"paragraph",content:"inline*",group:"blockContent",parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var e,t;return Q(this.name,"p",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),Un=j(Vn,zn),qn=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[Ne.columnResizing({cellMinWidth:100}),Ne.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 n=this.editor.state.selection,e=n.empty,t=n.$head.parentOffset===0,o=n.$head.node().type.name==="tableParagraph";return e&&t&&o}}},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:b.callOrReturn(b.getExtensionField(n,"tableRole",e))}}}),$n={...H},Gn=U({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var e,t;return Q(this.name,"table",{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...n},((t=this.options.domAttributes)==null?void 0:t.inlineContent)||{})}}),jn=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",b.mergeAttributes(this.options.HTMLAttributes,n),0]}}),Kn=j(Gn,$n,[qn,jn,Vt.TableHeader.extend({content:"tableContent"}),zt.TableCell.extend({content:"tableContent"}),Ut.TableRow]),ve={paragraph:Un,heading:In,bulletListItem:An,numberedListItem:Fn,image:Hn,table:Kn},Te=ke(ve),Ee={bold:R(tn.default,"boolean"),italic:R(on.default,"boolean"),underline:R(sn.default,"boolean"),strike:R(rn.default,"boolean"),code:R(nn.default,"boolean"),textColor:Mn,backgroundColor:En},Wn=we(Ee),Ce={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Xn=ye(Ce);function Me(n,e){let t,o;if(e.firstChild.descendants((i,r)=>t?!1:i.type.name!=="blockContainer"||i.attrs.id!==n?!0:(t=i,o=r+1,!1)),t===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:o}}function Jn(n,e,t="before",o){const i=o._tiptapEditor,r=typeof e=="string"?e:e.id,s=[];for(const d of n)s.push(_(d,i.schema,o.styleSchema));const{node:a,posBeforeNode:l}=Me(r,i.state.doc);if(t==="before"&&i.view.dispatch(i.state.tr.insert(l,s)),t==="after"&&i.view.dispatch(i.state.tr.insert(l+a.nodeSize,s)),t==="nested"&&a.childCount<2){const d=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(l+a.firstChild.nodeSize+1,d))}const c=[];for(const d of s)c.push(I(d,o.blockSchema,o.inlineContentSchema,o.styleSchema,o.blockCache));return c}function Yn(n,e,t){const o=t._tiptapEditor,i=typeof n=="string"?n:n.id,{posBeforeNode:r}=Me(i,o.state.doc);o.commands.BNUpdateBlock(r+1,e);const s=o.state.doc.resolve(r+1).node();return I(s,t.blockSchema,t.inlineContentSchema,t.styleSchema,t.blockCache)}function at(n,e,t){const o=e._tiptapEditor,i=o.state.tr,r=new Set(n.map(l=>typeof l=="string"?l:l.id)),s=[];let a=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;s.push(I(l,e.blockSchema,e.inlineContentSchema,e.styleSchema,e.blockCache)),r.delete(l.attrs.id),a=(t==null?void 0:t(l,c,i,a))||a;const d=i.doc.nodeSize;i.delete(c-a-1,c-a+l.nodeSize+1);const h=i.doc.nodeSize;return a+=d-h,!1}),r.size>0){const l=[...r].join(`
|
|
6
|
+
`);throw Error("Blocks with the following IDs could not be found in the editor: "+l)}return o.view.dispatch(i),s}function Zn(n,e){return at(n,e)}function Qn(n,e,t){const o=t._tiptapEditor,i=[];for(const l of e)i.push(_(l,o.schema,t.styleSchema));const r=typeof n[0]=="string"?n[0]:n[0].id,s=at(n,t,(l,c,d,h)=>{if(l.attrs.id===r){const f=d.doc.nodeSize;d.insert(c,i);const m=d.doc.nodeSize;return h+f-m}return h}),a=[];for(const l of i)a.push(I(l,t.blockSchema,t.inlineContentSchema,t.styleSchema,t.blockCache));return{insertedBlocks:a,removedBlocks:s}}function eo(){const n=e=>{let t=e.children.length;for(let o=0;o<t;o++){const i=e.children[o];if(i.type==="element"&&(n(i),i.tagName==="u"))if(i.children.length>0){e.children.splice(o,1,...i.children);const r=i.children.length-1;t+=r,o+=r}else e.children.splice(o,1),t--,o--}};return n}function xe(n){return le.unified().use(De.default,{fragment:!0}).use(eo).use(an.default).use(Oe.default).use(ln.default).processSync(n).value}function to(n,e,t){const i=Z(e,t).exportBlocks(n);return xe(i)}function no(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function oo(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function io(n){n.querySelectorAll("li > ul, li > ol").forEach(e=>{const t=no(e),o=e.parentElement,i=Array.from(o.childNodes).slice(t+1);e.remove(),i.forEach(r=>{r.remove()}),o.insertAdjacentElement("afterend",e),i.reverse().forEach(r=>{if(oo(r))return;const s=document.createElement("li");s.append(r),e.insertAdjacentElement("afterend",s)}),o.childNodes.length===0&&o.remove()})}function ro(n){n.querySelectorAll("li + ul, li + ol").forEach(e=>{var r,s;const t=e.previousElementSibling,o=document.createElement("div");t.insertAdjacentElement("afterend",o),o.append(t);const i=document.createElement("div");for(i.setAttribute("data-node-type","blockGroup"),o.append(i);((r=o.nextElementSibling)==null?void 0:r.nodeName)==="UL"||((s=o.nextElementSibling)==null?void 0:s.nodeName)==="OL";)i.append(o.nextElementSibling)})}function lt(n){if(typeof n=="string"){const e=document.createElement("div");e.innerHTML=n,n=e}return io(n),ro(n),n}async function ct(n,e,t,o,i){const r=lt(n),a=y.DOMParser.fromSchema(i).parse(r,{topNode:i.nodes.blockGroup.create()}),l=[];for(let c=0;c<a.childCount;c++)l.push(I(a.child(c),e,t,o));return l}function so(n,e){const t=e.value?e.value+`
|
|
7
|
+
`:"",o={};e.lang&&(o["data-language"]=e.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:t}]};return e.meta&&(i.data={meta:e.meta}),n.patch(e,i),i=n.applyData(e,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(e,i),i}function ao(n,e,t,o,i){const r=le.unified().use(cn.default).use(Oe.default).use(dn.default,{handlers:{...Ae.defaultHandlers,code:so}}).use(_e.default).processSync(n);return ct(r.value,e,t,o,i)}class dt{constructor(e,t,o){p(this,"formattingToolbarState");p(this,"updateFormattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"prevWasEditable",null);p(this,"shouldShow",({state:e})=>!e.selection.empty);p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});p(this,"dragstartHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});p(this,"blurHandler",e=>{var o;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(o=this.formattingToolbarState)!=null&&o.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"scrollHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=e,this.pmView=t,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.formattingToolbarState)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.dom.addEventListener("mouseup",this.viewMouseupHandler),t.dom.addEventListener("dragstart",this.dragstartHandler),t.dom.addEventListener("focus",this.focusHandler),t.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(e,t){var f,m;const{state:o,composing:i}=e,{doc:r,selection:s}=o,a=t&&t.doc.eq(r)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,c=Math.min(...l.map(g=>g.$from.pos)),d=Math.max(...l.map(g=>g.$to.pos)),h=(f=this.shouldShow)==null?void 0:f.call(this,{view:e,state:o,from:c,to:d});if(this.editor.isEditable&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((m=this.formattingToolbarState)!=null&&m.show&&!this.preventHide&&(!h||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:e}=this.pmView,{selection:t}=e,{ranges:o}=t,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(t)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const ut=new k.PluginKey("FormattingToolbarPlugin");class pt extends K{constructor(t){super();p(this,"view");p(this,"plugin");this.plugin=new k.Plugin({key:ut,view:o=>(this.view=new dt(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}class lo{constructor(e,t,o){p(this,"hyperlinkToolbarState");p(this,"updateHyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");p(this,"mouseOverHandler",e=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),e.target instanceof HTMLAnchorElement&&e.target.nodeName==="A"){const t=e.target,o=this.pmView.posAtDOM(t,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",e=>{var o;const t=this.pmView.dom.parentElement;this.hyperlinkMark&&e&&e.target&&!(t===e.target||t.contains(e.target))&&(o=this.hyperlinkToolbarState)!=null&&o.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});p(this,"scrollHandler",()=>{var e;this.hyperlinkMark!==void 0&&(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.referencePos=b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=e,this.pmView=t,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");o(this.hyperlinkToolbarState)},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),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(e,t){var i;const o=this.pmView.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:e})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}deleteHyperlink(){var e;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}update(){var t;if(!this.pmView.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){this.hyperlinkToolbarState={show:!0,referencePos:b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.updateHyperlinkToolbar();return}if((t=this.hyperlinkToolbarState)!=null&&t.show&&e&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const ht=new k.PluginKey("HyperlinkToolbarPlugin");class mt extends K{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"editHyperlink",(t,o)=>{this.view.editHyperlink(t,o)});p(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new k.Plugin({key:ht,view:o=>(this.view=new lo(t,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(t){return this.on("update",t)}}const co=b.findParentNode(n=>n.type.name==="blockContainer");class uo{constructor(e,t,o=()=>{}){p(this,"suggestionsMenuState");p(this,"updateSuggestionsMenu");p(this,"pluginState");p(this,"handleScroll",()=>{var e;if((e=this.suggestionsMenuState)!=null&&e.show){const t=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=t.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=e,this.pluginKey=t,this.pluginState=Be(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");o(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(e,t){const o=this.pluginKey.getState(t),i=this.pluginKey.getState(e.state),r=!o.active&&i.active,s=o.active&&!i.active,a=o.active&&i.active;if(!r&&!a&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:l.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function Be(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const ft=(n,e,t,o,i=()=>[],r=()=>{})=>{if(o.length!==1)throw new Error("'char' should be a single character");let s;const a=l=>{l.dispatch(l.state.tr.setMeta(t,{deactivate:!0}))};return{plugin:new k.Plugin({key:t,view:()=>(s=new uo(n,t,e),s),state:{init(){return Be()},apply(l,c,d,h){var m,g,T,M;if(l.getMeta("orderedListIndexing")!==void 0)return c;if((m=l.getMeta(t))!=null&&m.activate)return{active:!0,triggerCharacter:((g=l.getMeta(t))==null?void 0:g.triggerCharacter)||"",queryStartPos:h.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!c.active)return c;const f={...c};if(f.items=i(h.doc.textBetween(c.queryStartPos,h.selection.from)),f.notFoundCount=0,f.items.length===0&&(f.notFoundCount=Math.max(0,c.notFoundCount+(h.selection.from-d.selection.from))),h.selection.from!==h.selection.to||(T=l.getMeta(t))!=null&&T.deactivate||l.getMeta("focus")||l.getMeta("blur")||l.getMeta("pointer")||c.active&&h.selection.from<c.queryStartPos||f.notFoundCount>3)return Be();if(((M=l.getMeta(t))==null?void 0:M.selectedItemIndexChanged)!==void 0){let x=l.getMeta(t).selectedItemIndexChanged;x<0?x=c.items.length-1:x>=c.items.length&&(x=0),f.keyboardHoveredItemIndex=x}else d.selection.from!==h.selection.from&&(f.keyboardHoveredItemIndex=0);return f}},props:{handleKeyDown(l,c){const d=this.getState(l.state).active;if(c.key===o&&!d)return l.dispatch(l.state.tr.insertText(o).scrollIntoView().setMeta(t,{activate:!0,triggerCharacter:o})),!0;if(!d)return!1;const{triggerCharacter:h,queryStartPos:f,items:m,keyboardHoveredItemIndex:g}=t.getState(l.state);return c.key==="ArrowUp"?(l.dispatch(l.state.tr.setMeta(t,{selectedItemIndexChanged:g-1})),!0):c.key==="ArrowDown"?(l.dispatch(l.state.tr.setMeta(t,{selectedItemIndexChanged:g+1})),!0):c.key==="Enter"?(m.length===0||(a(l),n._tiptapEditor.chain().focus().deleteRange({from:f-h.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:m[g],editor:n})),!0):c.key==="Escape"?(a(l),!0):!1},decorations(l){const{active:c,decorationId:d,queryStartPos:h,triggerCharacter:f}=this.getState(l);if(!c)return null;if(f===""){const m=co(l.selection);if(m)return N.DecorationSet.create(l.doc,[N.Decoration.node(m.pos,m.pos+m.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":d})])}return N.DecorationSet.create(l.doc,[N.Decoration.inline(h-f.length,h,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":d})])}}}),itemCallback:l=>{a(n._tiptapEditor.view),n._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:l,editor:n})}}},re=new k.PluginKey("SlashMenuPlugin");class gt extends K{constructor(t,o){super();p(this,"plugin");p(this,"itemCallback");const i=ft(t,r=>{this.emit("update",r)},re,"/",r=>o.filter(({name:s,aliases:a})=>s.toLowerCase().startsWith(r.toLowerCase())||a&&a.filter(l=>l.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(t){return this.on("update",t)}}class X extends k.Selection{constructor(t,o){super(t,o);p(this,"nodes");const i=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(t,o,i=o){return new X(t.resolve(o),t.resolve(i))}content(){return new y.Slice(y.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof X)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(t.nodes[o]))return!1;return!0}map(t,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?k.Selection.near(t.resolve(i.pos)):i.deleted?k.Selection.near(t.resolve(r.pos)):new X(t.resolve(i.pos),t.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let F;function se(n,e){var i;if(!e.dom.isConnected)return;const t=e.posAtCoords(n);if(!t)return;let o=e.domAtPos(t.pos).node;if(o!==e.dom){for(;o&&o.parentNode&&o.parentNode!==e.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function po(n,e){const t=se(n,e);if(t&&t.node.nodeType===1){const o=e.docView,i=o.nearestDesc(t.node,!0);return!i||i===o?null:i.posBefore}return null}function ho(n,e){let t,o;const i=e.resolve(n.from).node().type.spec.group==="blockContent",r=e.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);t=e.resolve(a-1).pos,o=e.resolve(l+1).pos}else t=n.from,o=n.to;return{from:t,to:o}}function bt(n,e,t=e){e===t&&(t+=n.state.doc.resolve(e+1).node().nodeSize);const o=n.domAtPos(e).node.cloneNode(!0),i=n.domAtPos(e).node,r=(d,h)=>Array.prototype.indexOf.call(d.children,h),s=r(i,n.domAtPos(e+1).node.parentElement),a=r(i,n.domAtPos(t-1).node.parentElement);for(let d=i.childElementCount-1;d>=0;d--)(d>a||d<s)&&o.removeChild(o.children[d]);kt(),F=o;const c=n.dom.className.split(" ").filter(d=>d!=="ProseMirror"&&d!=="bn-root"&&d!=="bn-editor").join(" ");F.className=F.className+" bn-drag-preview "+c,document.body.appendChild(F)}function kt(){F!==void 0&&(document.body.removeChild(F),F=void 0)}function mo(n,e){if(!n.dataTransfer)return;const t=e.prosemirrorView,o=t.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=po(i,t);if(r!=null){const s=t.state.selection,a=t.state.doc,{from:l,to:c}=ho(s,a),d=l<=r&&r<c,h=s.$anchor.node()!==s.$head.node()||s instanceof X;d&&h?(t.dispatch(t.state.tr.setSelection(X.create(a,l,c))),bt(t,l,c)):(t.dispatch(t.state.tr.setSelection(k.NodeSelection.create(t.state.doc,r))),bt(t,r));const f=t.state.selection.content(),m=e._tiptapEditor.schema,T=me(m,e).serializeProseMirrorFragment(f.content),x=Z(m,e).exportProseMirrorFragment(f.content),v=xe(x);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",T),n.dataTransfer.setData("text/html",x),n.dataTransfer.setData("text/plain",v),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(F,0,0),t.dragging={slice:f,move:!0}}}class yt{constructor(e,t,o){p(this,"sideMenuState");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"hoveredBlock");p(this,"isDragging",!1);p(this,"menuFrozen",!1);p(this,"onDragStart",()=>{this.isDragging=!0});p(this,"onDrop",e=>{if(this.editor._tiptapEditor.commands.blur(),e.synthetic||!this.isDragging)return;const t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(this.isDragging=!1,!t||t.inside===-1){const o=new Event("drop",e),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});p(this,"onDragOver",e=>{if(e.synthetic||!this.isDragging)return;const t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const o=new Event("dragover",e),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=e.clientY,o.dataTransfer=e.dataTransfer,o.preventDefault=()=>e.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});p(this,"onKeyDown",e=>{var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseDown",e=>{this.sideMenuState&&!this.sideMenuState.show&&(this.sideMenuState.show=!0,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseMove",e=>{var c,d,h,f,m;if(this.menuFrozen)return;const t=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=e.clientX>=o.left&&e.clientX<=o.right&&e.clientY>=o.top&&e.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&e&&e.target&&!(r===e.target||r.contains(e.target))){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=t.x;const s={left:t.left+t.width/2,top:e.clientY},a=se(s,this.pmView);if(!a||!this.editor.isEditable){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((h=this.sideMenuState)!=null&&h.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.sideMenuState={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateSideMenu(this.sideMenuState)}});p(this,"onScroll",()=>{var e;if((e=this.sideMenuState)!=null&&e.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.updateSideMenu(this.sideMenuState)}});this.editor=e,this.pmView=t,this.updateSideMenu=o,this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var e;(e=this.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.sideMenuState)!=null&&l.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!0;const t=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!o)return;const i=E(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,startPos:s,endPos:a}=i;if(r.textContent.length!==0){const c=a+1,d=c+2;this.editor._tiptapEditor.chain().BNCreateBlock(c).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.editor._tiptapEditor.commands.setTextSelection(s+1);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(re,{activate:!0,type:"drag"}))}}const St=new k.PluginKey("SideMenuPlugin");class wt extends K{constructor(t){super();p(this,"sideMenuView");p(this,"plugin");p(this,"addBlock",()=>this.sideMenuView.addBlock());p(this,"blockDragStart",t=>{this.sideMenuView.isDragging=!0,mo(t,this.editor)});p(this,"blockDragEnd",()=>kt());p(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);p(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=t,this.plugin=new k.Plugin({key:St,view:o=>(this.sideMenuView=new yt(t,o,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(t){return this.on("update",t)}}function fo(n){let e=n.getTextCursorPosition().block,t=n.blockSchema[e.type].content;for(;t==="none";)e=n.getTextCursorPosition().nextBlock,t=n.blockSchema[e.type].content,n.setTextCursorPosition(e,"end")}function z(n,e){const t=n.getTextCursorPosition().block;if(t.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(t.content)&&(t.content.length===1&&G(t.content[0])&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0)?n.updateBlock(t,e):(n.insertBlocks([e],t,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return fo(n),o}const vt=(n=Te)=>{var t,o,i;const e=[];return"heading"in n&&"level"in n.heading.propSchema&&((t=n.heading.propSchema.level.values)!=null&&t.includes(1)&&e.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>z(r,{type:"heading",props:{level:1}})}),(o=n.heading.propSchema.level.values)!=null&&o.includes(2)&&e.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>z(r,{type:"heading",props:{level:2}})}),(i=n.heading.propSchema.level.values)!=null&&i.includes(3)&&e.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>z(r,{type:"heading",props:{level:3}})})),"bulletListItem"in n&&e.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>z(r,{type:"bulletListItem"})}),"numberedListItem"in n&&e.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>z(r,{type:"numberedListItem"})}),"paragraph"in n&&e.push({name:"Paragraph",aliases:["p"],execute:r=>z(r,{type:"paragraph"})}),"table"in n&&e.push({name:"Table",aliases:["table"],execute:r=>{z(r,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})}}),"image"in n&&e.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{const s=z(r,{type:"image"});r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(W,{block:s}))}}),e};let A;function Tt(){A||(A=document.createElement("div"),A.innerHTML="_",A.style.opacity="0",A.style.height="1px",A.style.width="1px",document.body.appendChild(A))}function go(){A&&(document.body.removeChild(A),A=void 0)}function ae(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function bo(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function ko(n){n.forEach(e=>{const t=document.getElementsByClassName(e);for(let o=0;o<t.length;o++)t[o].style.visibility="hidden"})}class Et{constructor(e,t,o){p(this,"state");p(this,"updateState");p(this,"tableId");p(this,"tablePos");p(this,"menuFrozen",!1);p(this,"prevWasEditable",null);p(this,"mouseMoveHandler",e=>{var c;if(this.menuFrozen)return;const t=bo(e.target);if(!t||!this.editor.isEditable){(c=this.state)!=null&&c.show&&(this.state.show=!1,this.updateState());return}const o=ae(t),i=ae(t.parentElement),r=t.getBoundingClientRect(),s=t.parentElement.parentElement.getBoundingClientRect(),a=se(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((d,h)=>typeof l<"u"?!1:d.type.name!=="blockContainer"||d.attrs.id!==a.id?!0:(l=I(d,this.editor.blockSchema,this.editor.inlineContentSchema,this.editor.styleSchema,this.editor.blockCache),this.tablePos=h+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.updateState(),!1});p(this,"dragOverHandler",e=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;e.preventDefault(),e.dataTransfer.dropEffect="move",ko(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const t={left:Math.min(Math.max(e.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(e.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(t.left,t.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=ae(i.parentElement),a=ae(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,d=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?t.top:t.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,r=!0),r&&this.updateState(),d&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});p(this,"dropHandler",e=>{if(this.state===void 0||this.state.draggingState===void 0)return;e.preventDefault();const t=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=t[this.state.draggingState.originalIndex];t.splice(this.state.draggingState.originalIndex,1),t.splice(this.state.rowIndex,0,o)}else{const o=t.map(i=>i.cells[this.state.draggingState.originalIndex]);t.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:t}})});p(this,"scrollHandler",()=>{var e;if((e=this.state)!=null&&e.show){const t=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=t.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=t.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.updateState()}});this.editor=e,this.pmView=t,this.updateState=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const J=new k.PluginKey("TableHandlesPlugin");class Ct extends K{constructor(t){super();p(this,"view");p(this,"plugin");p(this,"colDragStart",t=>{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:t.clientX},this.view.updateState(),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})),Tt(),t.dataTransfer.setDragImage(A,0,0),t.dataTransfer.effectAllowed="move"});p(this,"rowDragStart",t=>{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:t.clientY},this.view.updateState(),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})),Tt(),t.dataTransfer.setDragImage(A,0,0),t.dataTransfer.effectAllowed="copyMove"});p(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.updateState(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),go()});p(this,"freezeHandles",()=>this.view.menuFrozen=!0);p(this,"unfreezeHandles",()=>this.view.menuFrozen=!1);this.editor=t,this.plugin=new k.Plugin({key:J,view:o=>(this.view=new Et(t,o,i=>{this.emit("update",i)}),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 i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return N.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),c=l.node();for(let d=0;d<c.childCount;d++){const h=o.doc.resolve(l.posAtIndex(d)+1),f=h.node(),m=h.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(N.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const c=o.doc.resolve(s.posAtIndex(l)+1),d=o.doc.resolve(c.posAtIndex(i)+1),h=d.node(),f=d.pos+(i>this.view.state.draggingState.originalIndex?h.nodeSize-2:0);r.push(N.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return N.DecorationSet.create(o.doc,r)}}})}onUpdate(t){return this.on("update",t)}}function Mt(n,e){const t=n.state.selection.content().content,i=me(n.state.schema,e).serializeProseMirrorFragment(t),s=Z(n.state.schema,e).exportProseMirrorFragment(t),a=xe(s);return{internalHTML:i,externalHTML:s,plainText:a}}const yo=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{copy(e,t){t.preventDefault(),t.clipboardData.clearData(),"node"in e.state.selection&&e.state.selection.node.type.spec.group==="blockContent"&&e.dispatch(e.state.tr.setSelection(new k.NodeSelection(e.state.doc.resolve(e.state.selection.from-1))));const{internalHTML:o,externalHTML:i,plainText:r}=Mt(e,n);return t.clipboardData.setData("blocknote/html",o),t.clipboardData.setData("text/html",i),t.clipboardData.setData("text/plain",r),!0},dragstart(e,t){if(!("node"in e.state.selection)||e.state.selection.node.type.spec.group!=="blockContent")return;e.dispatch(e.state.tr.setSelection(new k.NodeSelection(e.state.doc.resolve(e.state.selection.from-1)))),t.preventDefault(),t.dataTransfer.clearData();const{internalHTML:o,externalHTML:i,plainText:r}=Mt(e,n);return t.dataTransfer.setData("blocknote/html",o),t.dataTransfer.setData("text/html",i),t.dataTransfer.setData("text/plain",r),!0}}}})]}}),So=["blocknote/html","text/html","text/plain"],wo=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new k.Plugin({props:{handleDOMEvents:{paste(e,t){t.preventDefault();let o=null;for(const i of So)if(t.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=t.clipboardData.getData(o);o==="text/html"&&(i=lt(i.trim()).innerHTML),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),vo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:H.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):H.backgroundColor.default,renderHTML:n=>n.backgroundColor!==H.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),To=new k.PluginKey("blocknote-placeholder"),Eo=b.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"bn-is-editor-empty",emptyNodeClass:"bn-is-empty",isFilterClass:"bn-is-filter",hasAnchorClass:"bn-has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new k.Plugin({key:To,props:{decorations:n=>{const{doc:e,selection:t}=n,o=re.getState(n),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(i)return e.descendants((a,l)=>{const c=r>=l&&r<=l+a.nodeSize,d=!a.isLeaf&&!a.childCount;if((c||!this.options.showOnlyCurrent)&&d){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),c&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&h.push(this.options.isFilterClass);const f=N.Decoration.node(l,l+a.nodeSize,{class:h.join(" ")});s.push(f)}return this.options.includeChildren}),N.DecorationSet.create(e,s)}}})]}}),Co=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),Mo=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:H.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):H.textColor.default,renderHTML:n=>n.textColor!==H.textColor.default&&{"data-text-color":n.textColor}}}}]}}),xo=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new k.PluginKey(this.name);return[new k.Plugin({key:n,appendTransaction:(e,t,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,c=s.nodes.blockContainer,d=s.nodes.paragraph;if(a)return r.insert(l,c.create(void 0,d.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let o=e.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 i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Bo=new k.PluginKey("non-editable-block"),Io=()=>new k.Plugin({key:Bo,props:{handleKeyDown:(n,e)=>{"node"in n.state.selection&&e.key.length===1&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey&&e.preventDefault()}}}),xt=new k.PluginKey("previous-blocks"),Po={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Ho=()=>{let n;return new k.Plugin({key:xt,view(e){return{update:async(t,o)=>{var i;((i=this.key)==null?void 0:i.getState(t.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(xt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,o,i){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||o.doc.eq(i.doc))return t;const r={},s=b.findChildren(o.doc,c=>c.attrs.id),a=new Map(s.map(c=>[c.node.attrs.id,c])),l=b.findChildren(i.doc,c=>c.attrs.id);for(const c of l){const d=a.get(c.node.attrs.id),h=d==null?void 0:d.node.firstChild,f=c.node.firstChild;if(d&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(c.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(d.pos).depth};r[c.node.attrs.id]=g,e.getMeta("numberedListIndexing")&&(c.node.attrs.id in t.prevTransactionOldBlockAttrs&&(g=t.prevTransactionOldBlockAttrs[c.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),t.currentTransactionOldBlockAttrs[c.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,t.updatedBlocks.add(c.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=r,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const o=[];return e.doc.descendants((i,r)=>{if(!i.attrs.id||!t.updatedBlocks.has(i.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[c,d]of Object.entries(s))a["data-prev-"+Po[c]]=d||"none";const l=N.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),N.DecorationSet.create(e.doc,o)}}})},Lo={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},No=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const e={};for(const[t,o]of Object.entries(Lo))n.getAttribute(o)&&(e[t]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:n}){var i;const e=document.createElement("div");e.className="bn-block-outer",e.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&e.setAttribute(r,s);const t={...((i=this.options.domAttributes)==null?void 0:i.blockContainer)||{},...n},o=document.createElement("div");o.className=O("bn-block",t.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(t))r!=="class"&&o.setAttribute(r,s);return e.appendChild(o),{dom:e,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:e,dispatch:t})=>{const o=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:e,dispatch:t})=>{const o=E(e.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return t&&e.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,e)=>({state:t,dispatch:o})=>{const i=E(t.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(e.children!==void 0){const f=[];for(const m of e.children)f.push(_(m,t.schema,this.options.editor.styleSchema));a.childCount===2?t.tr.replace(r+l.nodeSize+1,s-1,new y.Slice(y.Fragment.from(f),0,0)):t.tr.insert(r+l.nodeSize,t.schema.nodes.blockGroup.create({},f))}const c=l.type.name,d=e.type||c;let h="keep";if(e.content)if(typeof e.content=="string")h=[t.schema.text(e.content)];else if(Array.isArray(e.content))h=ne(e.content,t.schema,this.options.editor.styleSchema);else if(e.content.type==="tableContent")h=pe(e.content,t.schema,this.options.editor.styleSchema);else throw new D(e.content.type);else{const f=t.schema.nodes[c].spec.content,m=t.schema.nodes[d].spec.content;f===""||m!==f&&(h=[])}h==="keep"?t.tr.setNodeMarkup(r,e.type===void 0?void 0:t.schema.nodes[e.type],{...l.attrs,...e.props}):t.tr.replaceWith(r,s,t.schema.nodes[d].create({...l.attrs,...e.props},h)).setSelection(t.schema.nodes[d].spec.content===""?new k.NodeSelection(t.tr.doc.resolve(r)):t.schema.nodes[d].spec.content==="inline*"?new k.TextSelection(t.tr.doc.resolve(r)):new k.TextSelection(t.tr.doc.resolve(r+4))),t.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...e.props})}return!0},BNMergeBlocks:n=>({state:e,dispatch:t})=>{const o=e.doc.resolve(n+1).node().type.name==="blockContainer",i=e.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=E(e.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:c,depth:d}=r;if(s.childCount===2){const m=e.doc.resolve(l+a.nodeSize+1),g=e.doc.resolve(c-1),T=m.blockRange(g);t&&e.tr.lift(T,d-1)}let h=n-1,f=E(e.doc,h);for(;f.numChildBlocks>0;)if(h--,f=E(e.doc,h),f===void 0)return!1;return t&&(t(e.tr.deleteRange(l,l+a.nodeSize).replace(h-1,l,new y.Slice(a.content,0,0)).scrollIntoView()),e.tr.setSelection(new k.TextSelection(e.doc.resolve(h-1)))),!0},BNSplitBlock:(n,e)=>({state:t,dispatch:o})=>{const i=E(t.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:c}=i,d=t.doc.cut(a+1,n),h=t.doc.cut(n,l-1),f=t.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(t.tr.insert(m,f),t.tr.replace(g,g+1,h.content.size>0?new y.Slice(y.Fragment.from(h),c+2,c+2):void 0),e&&t.tr.setBlockType(g,g,t.schema.node(s).type,r.attrs),t.tr.setSelection(new k.TextSelection(t.doc.resolve(g))),t.tr.replace(a+1,l-1,d.content.size>0?new y.Slice(y.Fragment.from(d),c+2,c+2):void 0)),!0}}},addProseMirrorPlugins(){return[Ho(),Io()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=E(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=E(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=E(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,c=s===2,d=s-1;return!c&&a&&l&&r===2?o.BNMergeBlocks(d):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=E(i.doc,i.selection.from),l=a===i.doc.nodeSize-4,c=i.selection.from===a-1,d=i.selection.empty,h=r.childCount===2;if(!l&&c&&d&&!h){let f=s,m=a+2,g=i.doc.resolve(m).depth;for(;g<f;)f=g,m+=2,g=i.doc.resolve(m).depth;return o.BNMergeBlocks(m-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=E(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,c=r.textContent.length===0,d=s>2;return a&&l&&c&&d?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=E(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,c=i.selection.anchor===i.selection.head,d=s.textContent.length===0;if(l&&c&&d){const h=a+1,f=h+2;return r().BNCreateBlock(h).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=E(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2)}}}),Ao=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const e={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},t=document.createElement("div");t.className=O("bn-block-group",e.class),t.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(e))i!=="class"&&t.setAttribute(i,r);return{dom:t,contentDOM:t}}}),Do=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Bt=n=>{var t;const e=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Jt.Gapcursor,Eo.configure({includeChildren:!0,showOnlyCurrent:!1}),$.configure({types:["blockContainer"]}),Yt.HardBreak,en.Text,Qt.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),Mo,vo,Co,Do,No.configure({editor:n.editor,domAttributes:n.domAttributes}),Ao.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),yo(n.editor),wo(n.editor),Xt.Dropcursor.configure({width:5,color:"#ddeeff"}),xo];if(n.collaboration){if(e.push(un.default.configure({fragment:n.collaboration.fragment})),(t=n.collaboration.provider)!=null&&t.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};e.push(pn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else e.push(Zt.History);return e};function _o(n,e){const t=[];return n.forEach((o,i,r)=>{r!==e&&t.push(o)}),y.Fragment.from(t)}function Oo(n,e){let t=y.Fragment.from(n.content);for(let o=0;o<t.childCount;o++)if(t.child(o).type.spec.group==="blockContent"){const i=[t.child(o)];if(o+1<t.childCount&&t.child(o+1).type.spec.group==="blockGroup"){const s=t.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(t.child(o+1)),t=_o(t,o+1))}const r=e.state.schema.nodes.blockContainer.create(void 0,i);t=t.replaceChild(o,r)}return new y.Slice(t,n.openStart,n.openEnd)}const qo="",$o="",Ro={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ie{constructor(e){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"ready",!1);p(this,"sideMenu");p(this,"formattingToolbar");p(this,"slashMenu");p(this,"hyperlinkToolbar");p(this,"imageToolbar");p(this,"tableHandles");p(this,"uploadFile");var l,c,d,h,f,m,g,T,M,x;this.options=e;const t={defaultStyles:!0,blockSpecs:e.blockSpecs||ve,styleSpecs:e.styleSpecs||Ee,inlineContentSpecs:e.inlineContentSpecs||Ce,...e};this.blockSchema=ke(t.blockSpecs),this.inlineContentSchema=ye(t.inlineContentSpecs),this.styleSchema=we(t.styleSpecs),this.blockImplementations=t.blockSpecs,this.inlineContentImplementations=t.inlineContentSpecs,this.styleImplementations=t.styleSpecs,this.sideMenu=new wt(this),this.formattingToolbar=new pt(this),this.slashMenu=new gt(this,t.slashMenuItems||vt(this.blockSchema)),this.hyperlinkToolbar=new mt(this),this.imageToolbar=new ot(this),this.blockSchema.table===Te.table&&(this.tableHandles=new Ct(this));const o=Bt({editor:this,domAttributes:t.domAttributes||{},blockSchema:this.blockSchema,blockSpecs:t.blockSpecs,styleSpecs:t.styleSpecs,inlineContentSpecs:t.inlineContentSpecs,collaboration:t.collaboration}),i=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin,...this.tableHandles?[this.tableHandles.plugin]:[]]});o.push(i),this.uploadFile=t.uploadFile,t.collaboration&&t.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const r=t.initialContent||(e.collaboration?void 0:[{type:"paragraph",id:$.options.generateID()}]),s=this.styleSchema,a={...Ro,...t._tiptapOptions,onBeforeCreate(v){var L,Y;(Y=(L=t._tiptapOptions)==null?void 0:L.onBeforeCreate)==null||Y.call(L,v);const S=v.editor.schema;let C;const B=S.nodes.doc.createAndFill;S.nodes.doc.createAndFill=(...te)=>{if(C)return C;const q=B.apply(S.nodes.doc,te),Lt=JSON.parse(JSON.stringify(q.toJSON()));return Lt.content[0].content[0].attrs.id="initialBlockId",C=y.Node.fromJSON(S,Lt),q};const w=S.node("doc",void 0,S.node("blockGroup",void 0,[_({id:"initialBlockId",type:"paragraph"},S,s)]));v.editor.options.content=w.toJSON()},onCreate:v=>{var S,C,B;(C=(S=t._tiptapOptions)==null?void 0:S.onCreate)==null||C.call(S,v),r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(B=t.onEditorReady)==null||B.call(t,this),this.ready=!0},onUpdate:v=>{var S,C,B;(C=(S=t._tiptapOptions)==null?void 0:S.onUpdate)==null||C.call(S,v),this.ready&&((B=t.onEditorContentChange)==null||B.call(t,this))},onSelectionUpdate:v=>{var S,C,B;(C=(S=t._tiptapOptions)==null?void 0:S.onSelectionUpdate)==null||C.call(S,v),this.ready&&((B=t.onTextCursorPositionChange)==null||B.call(t,this))},editable:e.editable!==void 0?e.editable:((l=t._tiptapOptions)==null?void 0:l.editable)!==void 0?(c=t._tiptapOptions)==null?void 0:c.editable:!0,extensions:t.enableBlockNoteExtensions===!1?((d=t._tiptapOptions)==null?void 0:d.extensions)||[]:[...((h=t._tiptapOptions)==null?void 0:h.extensions)||[],...o],editorProps:{...(f=t._tiptapOptions)==null?void 0:f.editorProps,attributes:{...(g=(m=t._tiptapOptions)==null?void 0:m.editorProps)==null?void 0:g.attributes,...(T=t.domAttributes)==null?void 0:T.editor,class:O("bn-root","bn-editor",t.defaultStyles?"bn-default-styles":"",((x=(M=t.domAttributes)==null?void 0:M.editor)==null?void 0:x.class)||"")},transformPasted:Oo}};t.parentElement&&(a.element=t.parentElement),this._tiptapEditor=new b.Editor(a)}static create(e={}){return new Ie(e)}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(){const e=[];return this._tiptapEditor.state.doc.firstChild.descendants(t=>(e.push(I(t,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==t?!0:(o=I(i,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),!1)),o}forEachBlock(e,t=!1){const o=this.topLevelBlocks.slice();t&&o.reverse();function i(r){for(const s of r){if(!e(s))return!1;const a=t?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:o,endPos:i}=E(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(t-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:I(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:I(a,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:I(l,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)}}setTextCursorPosition(e,t="start"){const o=typeof e=="string"?e:e.id,{posBeforeNode:i}=Me(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=E(this._tiptapEditor.state.doc,i+2),a=this.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")t==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")t==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new D(a)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,o)=>t.type.spec.group!=="blockContent"||o+t.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(e.push(I(this._tiptapEditor.state.doc.resolve(o).node(),this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,o="before"){return Jn(e,t,o,this)}updateBlock(e,t){return Yn(e,t,this)}removeBlocks(e){return Zn(e,this)}replaceBlocks(e,t){return Qn(e,t,this)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks();for(const o of t){const i=this.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?e[i.type]=!0:e[i.type]=o.attrs.stringValue}return e}addStyles(e){this._tiptapEditor.view.focus();for(const[t,o]of Object.entries(e)){const i=this.styleSchema[t];if(!i)throw new Error(`style ${t} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(t);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(t,{stringValue:o});else throw new D(i.propSchema)}}removeStyles(e){this._tiptapEditor.view.focus();for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){this._tiptapEditor.view.focus();for(const[t,o]of Object.entries(e)){const i=this.styleSchema[t];if(!i)throw new Error(`style ${t} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(t);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(t,{stringValue:o});else throw new D(i.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(e,t){if(e==="")return;const{from:o,to:i}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,o,i).addMark(o,o+t.length,r))}canNestBlock(){const{startPos:e,depth:t}=E(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(e).index(t-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:e}=E(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(e=this.topLevelBlocks){return Z(this._tiptapEditor.schema,this).exportBlocks(e)}async tryParseHTMLToBlocks(e){return ct(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(e=this.topLevelBlocks){return to(e,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(e){return ao(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this._tiptapEditor.schema)}updateCollaborationUserInfo(e){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(e)}}function Pe(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function It(n){return typeof n=="string"?Pe(n):Array.isArray(n)?n.flatMap(e=>typeof e=="string"?Pe(e):de(e)?{...e,content:Pe(e.content)}:G(e)?e:{props:{},...e,content:It(e.content)}):n}function Fo(n,e){return e.map(t=>He(n,t))}function He(n,e){const t={id:"",type:e.type,props:{},content:n[e.type].content==="inline"?[]:void 0,children:[],...e};return Object.entries(n[e.type].propSchema).forEach(([o,i])=>{t.props[o]===void 0&&(t.props[o]=i.default)}),{...t,content:It(t.content),children:t.children.map(o=>He(n,o))}}function Pt(n){n.id||(n.id=$.options.generateID()),n.children&&Ht(n.children)}function Ht(n){for(const e of n)Pt(e)}u.BlockNoteEditor=Ie,u.FormattingToolbarProsemirrorPlugin=pt,u.FormattingToolbarView=dt,u.HyperlinkToolbarProsemirrorPlugin=mt,u.ImageToolbarProsemirrorPlugin=ot,u.ImageToolbarView=nt,u.SideMenuProsemirrorPlugin=wt,u.SideMenuView=yt,u.SlashMenuProsemirrorPlugin=gt,u.TableHandlesProsemirrorPlugin=Ct,u.TableHandlesView=Et,u.UniqueID=$,u.UnreachableCaseError=D,u.addIdsToBlock=Pt,u.addIdsToBlocks=Ht,u.addInlineContentAttributes=We,u.addInlineContentKeyboardShortcuts=Xe,u.addStyleAttributes=et,u.blockToNode=_,u.camelToDataKebab=ee,u.contentNodeToInlineContent=oe,u.createBlockSpec=Ke,u.createBlockSpecFromStronglyTypedTiptapNode=j,u.createExternalHTMLExporter=Z,u.createInlineContentSpec=wn,u.createInlineContentSpecFromTipTapNode=Ye,u.createInternalBlockSpec=be,u.createInternalHTMLSerializer=me,u.createInternalInlineContentSpec=Je,u.createInternalStyleSpec=Se,u.createStronglyTypedTiptapNode=U,u.createStyleSpec=vn,u.createStyleSpecFromTipTapMark=R,u.defaultBlockSchema=Te,u.defaultBlockSpecs=ve,u.defaultInlineContentSchema=Xn,u.defaultInlineContentSpecs=Ce,u.defaultProps=H,u.defaultStyleSchema=Wn,u.defaultStyleSpecs=Ee,u.formatKeyboardShortcut=Sn,u.formattingToolbarPluginKey=ut,u.getBlockFromPos=Ge,u.getBlockNoteExtensions=Bt,u.getBlockSchemaFromSpecs=ke,u.getDefaultSlashMenuItems=vt,u.getDraggableBlockFromCoords=se,u.getInlineContentParseRules=Ze,u.getInlineContentSchemaFromSpecs=ye,u.getParseRules=je,u.getStyleParseRules=tt,u.getStyleSchemaFromSpecs=we,u.hyperlinkToolbarPluginKey=ht,u.imageToolbarPluginKey=W,u.inheritedProps=fe,u.inlineContentToNodes=ne,u.isAppleOS=qe,u.isLinkInlineContent=ce,u.isPartialLinkInlineContent=de,u.isStyledTextInlineContent=G,u.mergeCSSClasses=O,u.nodeToBlock=I,u.nodeToCustomInlineContent=he,u.partialBlockToBlockForTesting=He,u.partialBlocksToBlocksForTesting=Fo,u.propsToAttributes=ge,u.setupSuggestionsMenu=ft,u.sideMenuPluginKey=St,u.slashMenuPluginKey=re,u.stylePropsToAttributes=Qe,u.tableContentToNodes=pe,u.tableHandlesPluginKey=J,u.uploadToTmpFilesDotOrg_DEV_ONLY=yn,u.wrapInBlockStructure=ie,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
8
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|