@blocknote/core 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.js +337 -298
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +5 -4
- package/dist/blocknote.umd.cjs.map +1 -1
- package/package.json +2 -2
- package/src/BlockNoteEditor.ts +2 -2
- package/src/BlockNoteExtensions.ts +24 -22
- package/src/api/blockManipulation/blockManipulation.test.ts +2 -2
- package/src/api/blockManipulation/blockManipulation.ts +1 -1
- package/src/api/formatConversions/formatConversions.test.ts +2 -2
- package/src/api/formatConversions/formatConversions.ts +47 -3
- package/src/api/nodeConversions/nodeConversions.test.ts +6 -6
- package/src/api/nodeConversions/nodeConversions.ts +6 -6
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +2 -2
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +27 -5
- package/src/extensions/Blocks/nodes/BlockContainer.ts +5 -5
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +3 -3
- package/src/extensions/SideMenu/SideMenuPlugin.ts +9 -9
- package/src/extensions/UniqueID/UniqueID.ts +10 -9
- package/src/shared/EventEmitter.ts +1 -0
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +6 -2
- package/types/src/extensions/Blocks/helpers/getBlockInfoFromPos.d.ts +9 -1
- package/types/src/extensions/Blocks/nodes/TableCell.d.ts +5 -0
- package/types/src/extensions/Blocks/nodes/TableRow.d.ts +5 -0
- package/types/src/extensions/SideMenu/MultipleNodeSelection.d.ts +1 -1
- package/types/src/EventEmitter.d.ts +0 -11
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +0 -0
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +0 -16
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +0 -55
- package/types/src/extensions/DraggableBlocks/MultipleNodeSelection.d.ts +0 -24
- package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +0 -11
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +0 -10
- package/types/src/extensions/HyperlinkToolbar/HyperlinkMark.d.ts +0 -8
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +0 -0
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +0 -13
- package/types/src/extensions/SlashMenu/index.d.ts +0 -3
- package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +0 -12
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("@tiptap/core"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),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-italic"),require("@tiptap/extension-link"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-model"),require("prosemirror-state"),require("uuid"),require("prosemirror-view"),require("rehype-parse"),require("rehype-remark"),require("rehype-stringify"),require("remark-gfm"),require("remark-parse"),require("remark-rehype"),require("remark-stringify"),require("unified"),require("hast-util-from-dom")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-link","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-model","prosemirror-state","uuid","prosemirror-view","rehype-parse","rehype-remark","rehype-stringify","remark-gfm","remark-parse","remark-rehype","remark-stringify","unified","hast-util-from-dom"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.blocknote={},h.core,h.extensionBold,h.extensionCode,h.Collaboration,h.CollaborationCursor,h.extensionDropcursor,h.extensionGapcursor,h.extensionHardBreak,h.extensionHistory,h.extensionItalic,h.extensionLink,h.extensionStrike,h.extensionText,h.extensionUnderline,h.prosemirrorModel,h.prosemirrorState,h.uuid,h.pv,h.rehypeParse,h.rehypeRemark,h.rehypeStringify,h.remarkGfm,h.remarkParse,h.remarkRehype,h.remarkStringify,h.unified,h.hastUtilFromDom))})(this,function(h,m,P,zt,Ft,Ut,qt,Gt,$t,jt,Kt,Wt,Yt,Jt,Xt,S,b,Zt,B,Qt,te,ee,ne,oe,re,ie,U,W){"use strict";var rn=Object.defineProperty;var sn=(h,m,P)=>m in h?rn(h,m,{enumerable:!0,configurable:!0,writable:!0,value:P}):h[m]=P;var u=(h,m,P)=>(sn(h,typeof m!="symbol"?m+"":m,P),P);const T=o=>o&&typeof o=="object"&&"default"in o?o:{default:o};function se(o){if(o&&typeof o=="object"&&"default"in o)return o;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const ae=T(Ft),le=T(Ut),de=se(B),Y=T(Qt),ce=T(te),J=T(ee),X=T(ne),ue=T(oe),pe=T(re),he=T(ie),I={bnEditor:"_bnEditor_1pmoa_3",bnRoot:"_bnRoot_1pmoa_19",defaultStyles:"_defaultStyles_1pmoa_34",dragPreview:"_dragPreview_1pmoa_57","collaboration-cursor__caret":"_collaboration-cursor__caret_1pmoa_63","collaboration-cursor__label":"_collaboration-cursor__label_1pmoa_74"};function y(o,e){const n=o.nodeSize-2;if(e<=1)for(e=1+1;o.resolve(e).parent.type.name!=="blockContainer"&&e<n;)e++;else if(e>=n)for(e=n-1;o.resolve(e).parent.type.name!=="blockContainer"&&e>1;)e--;o.resolve(e).parent.type.name==="blockGroup"&&e++;const r=o.resolve(e),i=r.depth;let s=r.node(i),l=i;for(;;){if(l<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;l-=1,s=r.node(l)}const a=s.attrs.id,d=s.firstChild,c=d.type,f=s.childCount===2?s.lastChild.childCount:0,p=r.start(l),k=r.end(l);return{id:a,node:s,contentNode:d,contentType:c,numChildBlocks:f,startPos:p,endPos:k,depth:l}}const fe=m.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:"default",parseHTML:o=>o.hasAttribute("data-background-color")?o.getAttribute("data-background-color"):"default",renderHTML:o=>o.backgroundColor!=="default"&&{"data-background-color":o.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(o,e)=>({state:t,view:n})=>{const r=y(t.doc,o);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"backgroundColor",e),n.focus(),!0)}}}}),me=m.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-background-color"),renderHTML:o=>({"data-background-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-background-color")?{color:o.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setBackgroundColor:o=>({commands:e})=>o!=="default"?e.setMark(this.name,{color:o}):e.unsetMark(this.name)}}}),Z="_blockOuter_7sok8_5",Q="_block_7sok8_5",tt="_reactNodeViewRenderer_7sok8_17",et="_blockContent_7sok8_22",nt="_blockGroup_7sok8_42",ot="_isEmpty_7sok8_240",rt="_inlineContent_7sok8_240",it="_isFilter_7sok8_241",st="_hasAnchor_7sok8_263",w={blockOuter:Z,block:Q,reactNodeViewRenderer:tt,blockContent:et,blockGroup:nt,isEmpty:ot,inlineContent:rt,isFilter:it,hasAnchor:st},ke=Object.freeze(Object.defineProperty({__proto__:null,block:Q,blockContent:et,blockGroup:nt,blockOuter:Z,default:w,hasAnchor:st,inlineContent:rt,isEmpty:ot,isFilter:it,reactNodeViewRenderer:tt},Symbol.toStringTag,{value:"Module"})),at=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function ge(o){return at()?o.replace("Mod","⌘"):o.replace("Mod","Ctrl")}function M(...o){return o.filter(e=>e).join(" ")}class lt extends Error{constructor(e){super(`Unreachable case: ${e}`)}}function q(o){return"data-"+o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function dt(o){const e={};return Object.entries(o.propSchema).forEach(([t,n])=>{e[t]={default:n.default,keepOnSplit:!0,parseHTML:r=>r.getAttribute(q(t)),renderHTML:r=>r[t]!==n.default?{[q(t)]:r[t]}:{}}}),e}function ct(o){return[{tag:"div[data-content-type="+o.type+"]"}]}function ut(o,e){const t=document.createElement("div");t.setAttribute("data-content-type",o.type);for(const[r,i]of Object.entries(e))t.setAttribute(r,i);let n;return o.containsInlineContent?(n=document.createElement("div"),t.appendChild(n)):n=void 0,n!==void 0?{dom:t,contentDOM:n}:{dom:t}}function be(o){return{node:N({name:o.type,content:o.containsInlineContent?"inline*":"",selectable:o.containsInlineContent,addAttributes(){return dt(o)},parseHTML(){return ct(o)},renderHTML({HTMLAttributes:t}){return ut(o,t)},addNodeView(){return({HTMLAttributes:t,getPos:n})=>{var k,g;const r=document.createElement("div"),i=((k=this.options.domAttributes)==null?void 0:k.blockContent)||{};for(const[v,C]of Object.entries(i))v!=="class"&&r.setAttribute(v,C);r.className=M(w.blockContent,i.class),r.setAttribute("data-content-type",o.type);for(const[v,C]of Object.entries(t))r.setAttribute(v,C);const s=this.options.editor;if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const l=n(),c=s._tiptapEditor.state.doc.resolve(l).node().attrs.id,f=s.getBlock(c);if(f.type!==o.type)throw new Error("Block type does not match");const p=o.render(f,s);if("contentDOM"in p){const v=((g=this.options.domAttributes)==null?void 0:g.inlineContent)||{};for(const[C,E]of Object.entries(v))C!=="class"&&p.contentDOM.setAttribute(C,E);p.contentDOM.className=M(p.contentDOM.className,w.inlineContent,v.class)}return r.appendChild(p.dom),"contentDOM"in p?{dom:r,contentDOM:p.contentDOM}:{dom:r}}}}),propSchema:o.propSchema}}function N(o){return m.Node.create({...o,group:"blockContent"})}const ye=N({name:"heading",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:o=>o.getAttribute("data-level"),renderHTML:o=>({"data-level":o.level})}}},addInputRules(){return[...["1","2","3"].map(o=>new m.InputRule({find:new RegExp(`^(#{${parseInt(o)}})\\s$`),handler:({state:e,chain:t,range:n})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:o}}).deleteRange({from:n.from,to:n.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"heading"},{tag:"h2",attrs:{level:"2"},node:"heading"},{tag:"h3",attrs:{level:"3"},node:"heading"}]},renderHTML({node:o,HTMLAttributes:e}){var r,i;const t=((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},n=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",m.mergeAttributes(e,{class:M(w.blockContent,t.class),"data-content-type":this.name}),["h"+o.attrs.level,{class:M(w.inlineContent,n.class)},0]]}}),pt=o=>{const{node:e,contentType:t}=y(o.state.doc,o.state.selection.from),n=o.state.selection.anchor===o.state.selection.head;return!t.name.endsWith("ListItem")||!n?!1:o.commands.first(({state:r,chain:i,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},ve=N({name:"bulletListItem",content:"inline*",addInputRules(){return[new m.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:o,chain:e,range:t})=>{e().BNUpdateBlock(o.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>pt(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:o}){var n,r;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",m.mergeAttributes(o,{class:M(w.blockContent,e.class),"data-content-type":this.name}),["p",{class:M(w.inlineContent,t.class)},0]]}}),Ce=new b.PluginKey("numbered-list-indexing"),Se=()=>new b.Plugin({key:Ce,appendTransaction:(o,e,t)=>{const n=t.tr;n.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((i,s)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let l="1";const a=s===1,d=y(n.doc,s+1);if(d===void 0)return;if(!a){const p=y(n.doc,s-2);if(p===void 0)return;if(!(d.depth!==p.depth)){const g=p.contentNode;if(p.contentType.name==="numberedListItem"){const E=g.attrs.index;l=(parseInt(E)+1).toString()}}}d.contentNode.attrs.index!==l&&(r=!0,n.setNodeMarkup(s+1,void 0,{index:l}))}}),r?n:null}}),we=N({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:o=>o.getAttribute("data-index"),renderHTML:o=>({"data-index":o.index})}}},addInputRules(){return[new m.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:o,chain:e,range:t})=>{e().BNUpdateBlock(o.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>pt(this.editor)}},addProseMirrorPlugins(){return[Se()]},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:o}){var n,r;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",m.mergeAttributes(o,{class:M(w.blockContent,e.class),"data-content-type":this.name}),["p",{class:M(w.inlineContent,t.class)},0]]}}),Me=N({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:o}){var n,r;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",m.mergeAttributes({...e,class:M(w.blockContent,e.class),"data-content-type":this.name},o),["p",{...t,class:M(w.inlineContent,t.class)},0]]}}),H={backgroundColor:{default:"transparent"},textColor:{default:"black"},textAlignment:{default:"left",values:["left","center","right","justify"]}},G={paragraph:{propSchema:H,node:Me},heading:{propSchema:{...H,level:{default:"1",values:["1","2","3"]}},node:ye},bulletListItem:{propSchema:H,node:ve},numberedListItem:{propSchema:H,node:we}};function Ee(o,e=JSON.stringify){const t={};return o.filter(n=>{const r=e(n);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Be(o){const e=o.filter((n,r)=>o.indexOf(n)!==r);return Ee(e)}const R=m.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>window.__TEST_OPTIONS?(window.__TEST_OPTIONS.mockID===void 0?window.__TEST_OPTIONS.mockID=0:window.__TEST_OPTIONS.mockID++,window.__TEST_OPTIONS.mockID.toString()):Zt.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:o=>o.getAttribute(`data-${this.options.attributeName}`),renderHTML:o=>({[`data-${this.options.attributeName}`]:o[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let o=null,e=!1;return[new b.Plugin({key:new b.PluginKey("uniqueID"),appendTransaction:(t,n,r)=>{const i=t.some(g=>g.docChanged)&&!n.doc.eq(r.doc),s=this.options.filterTransaction&&t.some(g=>{var v,C;return!(!((C=(v=this.options).filterTransaction)===null||C===void 0)&&C.call(v,g))});if(!i||s)return;const{tr:l}=r,{types:a,attributeName:d,generateID:c}=this.options,f=m.combineTransactionSteps(n.doc,t),{mapping:p}=f;if(m.getChangedRanges(f).forEach(({newRange:g})=>{const v=m.findChildrenInRange(r.doc,g,_=>a.includes(_.type.name)),C=v.map(({node:_})=>_.attrs[d]).filter(_=>_!==null),E=Be(C);v.forEach(({node:_,pos:F})=>{var K;const Vt=(K=l.doc.nodeAt(F))===null||K===void 0?void 0:K.attrs[d];if(Vt===null){l.setNodeMarkup(F,void 0,{..._.attrs,[d]:c()});return}const{deleted:on}=p.invert().mapResult(F);on&&E.includes(Vt)&&l.setNodeMarkup(F,void 0,{..._.attrs,[d]:c()})})}),!!l.steps.length)return l},view(t){const n=r=>{var i;o=!((i=t.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(t,n)=>{var r;return(o!==t.dom.parentElement||((r=n.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(o=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:n,attributeName:r}=this.options,i=s=>{const l=[];return s.forEach(a=>{if(a.isText){l.push(a);return}if(!n.includes(a.type.name)){l.push(a.copy(i(a.content)));return}const d=a.type.create({...a.attrs,[r]:null},i(a.content),a.marks);l.push(d)}),S.Fragment.from(l)};return e=!1,new S.Slice(i(t.content),t.openStart,t.openEnd)}}})]}}),ht=new Set(["bold","italic","underline","strike","code"]),ft=new Set(["textColor","backgroundColor"]);function mt(o,e){const t=[];for(const[n,r]of Object.entries(o.styles))ht.has(n)?t.push(e.mark(n)):ft.has(n)&&t.push(e.mark(n,{color:r}));return o.text.split(/(\n)/g).filter(n=>n.length>0).map(n=>n===`
|
|
2
|
-
`?e.nodes.hardBreak.create():e.text(n,t))}function
|
|
1
|
+
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("@tiptap/core"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),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-italic"),require("@tiptap/extension-link"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-model"),require("prosemirror-state"),require("uuid"),require("prosemirror-view"),require("rehype-parse"),require("rehype-remark"),require("rehype-stringify"),require("remark-gfm"),require("remark-parse"),require("remark-rehype"),require("remark-stringify"),require("unified"),require("hast-util-from-dom")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-link","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-model","prosemirror-state","uuid","prosemirror-view","rehype-parse","rehype-remark","rehype-stringify","remark-gfm","remark-parse","remark-rehype","remark-stringify","unified","hast-util-from-dom"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.blocknote={},h.core,h.extensionBold,h.extensionCode,h.Collaboration,h.CollaborationCursor,h.extensionDropcursor,h.extensionGapcursor,h.extensionHardBreak,h.extensionHistory,h.extensionItalic,h.extensionLink,h.extensionStrike,h.extensionText,h.extensionUnderline,h.prosemirrorModel,h.prosemirrorState,h.uuid,h.pv,h.rehypeParse,h.rehypeRemark,h.rehypeStringify,h.remarkGfm,h.remarkParse,h.remarkRehype,h.remarkStringify,h.unified,h.hastUtilFromDom))})(this,function(h,m,P,Ut,qt,Gt,$t,jt,Kt,Wt,Yt,Jt,Xt,Zt,Qt,S,b,te,B,ee,ne,oe,re,ie,W,se,U,Y){"use strict";var an=Object.defineProperty;var ln=(h,m,P)=>m in h?an(h,m,{enumerable:!0,configurable:!0,writable:!0,value:P}):h[m]=P;var u=(h,m,P)=>(ln(h,typeof m!="symbol"?m+"":m,P),P);const T=o=>o&&typeof o=="object"&&"default"in o?o:{default:o};function ae(o){if(o&&typeof o=="object"&&"default"in o)return o;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const le=T(qt),de=T(Gt),ce=ae(B),J=T(ee),ue=T(ne),X=T(oe),Z=T(re),pe=T(ie),he=T(W),fe=T(se),I={bnEditor:"_bnEditor_1pmoa_3",bnRoot:"_bnRoot_1pmoa_19",defaultStyles:"_defaultStyles_1pmoa_34",dragPreview:"_dragPreview_1pmoa_57","collaboration-cursor__caret":"_collaboration-cursor__caret_1pmoa_63","collaboration-cursor__label":"_collaboration-cursor__label_1pmoa_74"};function Q(o){const e=o.attrs.id,t=o.firstChild,n=t.type,r=o.childCount===2?o.lastChild.childCount:0;return{id:e,node:o,contentNode:t,contentType:n,numChildBlocks:r}}function y(o,e){const n=o.nodeSize-2;if(e<=1)for(e=1+1;o.resolve(e).parent.type.name!=="blockContainer"&&e<n;)e++;else if(e>=n)for(e=n-1;o.resolve(e).parent.type.name!=="blockContainer"&&e>1;)e--;o.resolve(e).parent.type.name==="blockGroup"&&e++;const r=o.resolve(e),i=r.depth;let s=r.node(i),l=i;for(;;){if(l<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;l-=1,s=r.node(l)}const{id:a,contentNode:d,contentType:c,numChildBlocks:f}=Q(s),p=r.start(l),k=r.end(l);return{id:a,node:s,contentNode:d,contentType:c,numChildBlocks:f,startPos:p,endPos:k,depth:l}}const me=m.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:"default",parseHTML:o=>o.hasAttribute("data-background-color")?o.getAttribute("data-background-color"):"default",renderHTML:o=>o.backgroundColor!=="default"&&{"data-background-color":o.backgroundColor}}}}]},addCommands(){return{setBlockBackgroundColor:(o,e)=>({state:t,view:n})=>{const r=y(t.doc,o);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"backgroundColor",e),n.focus(),!0)}}}}),ke=m.Mark.create({name:"backgroundColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-background-color"),renderHTML:o=>({"data-background-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-background-color")?{color:o.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setBackgroundColor:o=>({commands:e})=>o!=="default"?e.setMark(this.name,{color:o}):e.unsetMark(this.name)}}}),tt="_blockOuter_7sok8_5",et="_block_7sok8_5",nt="_reactNodeViewRenderer_7sok8_17",ot="_blockContent_7sok8_22",rt="_blockGroup_7sok8_42",it="_isEmpty_7sok8_240",st="_inlineContent_7sok8_240",at="_isFilter_7sok8_241",lt="_hasAnchor_7sok8_263",w={blockOuter:tt,block:et,reactNodeViewRenderer:nt,blockContent:ot,blockGroup:rt,isEmpty:it,inlineContent:st,isFilter:at,hasAnchor:lt},ge=Object.freeze(Object.defineProperty({__proto__:null,block:et,blockContent:ot,blockGroup:rt,blockOuter:tt,default:w,hasAnchor:lt,inlineContent:st,isEmpty:it,isFilter:at,reactNodeViewRenderer:nt},Symbol.toStringTag,{value:"Module"})),dt=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function be(o){return dt()?o.replace("Mod","⌘"):o.replace("Mod","Ctrl")}function M(...o){return o.filter(e=>e).join(" ")}class ct extends Error{constructor(e){super(`Unreachable case: ${e}`)}}function q(o){return"data-"+o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ut(o){const e={};return Object.entries(o.propSchema).forEach(([t,n])=>{e[t]={default:n.default,keepOnSplit:!0,parseHTML:r=>r.getAttribute(q(t)),renderHTML:r=>r[t]!==n.default?{[q(t)]:r[t]}:{}}}),e}function pt(o){return[{tag:"div[data-content-type="+o.type+"]"}]}function ht(o,e){const t=document.createElement("div");t.setAttribute("data-content-type",o.type);for(const[r,i]of Object.entries(e))t.setAttribute(r,i);let n;return o.containsInlineContent?(n=document.createElement("div"),t.appendChild(n)):n=void 0,n!==void 0?{dom:t,contentDOM:n}:{dom:t}}function ye(o){return{node:N({name:o.type,content:o.containsInlineContent?"inline*":"",selectable:o.containsInlineContent,addAttributes(){return ut(o)},parseHTML(){return pt(o)},renderHTML({HTMLAttributes:t}){return ht(o,t)},addNodeView(){return({HTMLAttributes:t,getPos:n})=>{var k,g;const r=document.createElement("div"),i=((k=this.options.domAttributes)==null?void 0:k.blockContent)||{};for(const[v,C]of Object.entries(i))v!=="class"&&r.setAttribute(v,C);r.className=M(w.blockContent,i.class),r.setAttribute("data-content-type",o.type);for(const[v,C]of Object.entries(t))r.setAttribute(v,C);const s=this.options.editor;if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const l=n(),c=s._tiptapEditor.state.doc.resolve(l).node().attrs.id,f=s.getBlock(c);if(f.type!==o.type)throw new Error("Block type does not match");const p=o.render(f,s);if("contentDOM"in p){const v=((g=this.options.domAttributes)==null?void 0:g.inlineContent)||{};for(const[C,E]of Object.entries(v))C!=="class"&&p.contentDOM.setAttribute(C,E);p.contentDOM.className=M(p.contentDOM.className,w.inlineContent,v.class)}return r.appendChild(p.dom),"contentDOM"in p?{dom:r,contentDOM:p.contentDOM}:{dom:r}}}}),propSchema:o.propSchema}}function N(o){return m.Node.create({...o,group:"blockContent"})}const ve=N({name:"heading",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:o=>o.getAttribute("data-level"),renderHTML:o=>({"data-level":o.level})}}},addInputRules(){return[...["1","2","3"].map(o=>new m.InputRule({find:new RegExp(`^(#{${parseInt(o)}})\\s$`),handler:({state:e,chain:t,range:n})=>{t().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:o}}).deleteRange({from:n.from,to:n.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"heading"},{tag:"h2",attrs:{level:"2"},node:"heading"},{tag:"h3",attrs:{level:"3"},node:"heading"}]},renderHTML({node:o,HTMLAttributes:e}){var r,i;const t=((r=this.options.domAttributes)==null?void 0:r.blockContent)||{},n=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",m.mergeAttributes(e,{class:M(w.blockContent,t.class),"data-content-type":this.name}),["h"+o.attrs.level,{class:M(w.inlineContent,n.class)},0]]}}),ft=o=>{const{node:e,contentType:t}=y(o.state.doc,o.state.selection.from),n=o.state.selection.anchor===o.state.selection.head;return!t.name.endsWith("ListItem")||!n?!1:o.commands.first(({state:r,chain:i,commands:s})=>[()=>s.command(()=>e.textContent.length===0?s.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>e.textContent.length>0?(i().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},Ce=N({name:"bulletListItem",content:"inline*",addInputRules(){return[new m.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:o,chain:e,range:t})=>{e().BNUpdateBlock(o.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>ft(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:o}){var n,r;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",m.mergeAttributes(o,{class:M(w.blockContent,e.class),"data-content-type":this.name}),["p",{class:M(w.inlineContent,t.class)},0]]}}),Se=new b.PluginKey("numbered-list-indexing"),we=()=>new b.Plugin({key:Se,appendTransaction:(o,e,t)=>{const n=t.tr;n.setMeta("numberedListIndexing",!0);let r=!1;return t.doc.descendants((i,s)=>{if(i.type.name==="blockContainer"&&i.firstChild.type.name==="numberedListItem"){let l="1";const a=s===1,d=y(n.doc,s+1);if(d===void 0)return;if(!a){const p=y(n.doc,s-2);if(p===void 0)return;if(!(d.depth!==p.depth)){const g=p.contentNode;if(p.contentType.name==="numberedListItem"){const E=g.attrs.index;l=(parseInt(E)+1).toString()}}}d.contentNode.attrs.index!==l&&(r=!0,n.setNodeMarkup(s+1,void 0,{index:l}))}}),r?n:null}}),Me=N({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:o=>o.getAttribute("data-index"),renderHTML:o=>({"data-index":o.index})}}},addInputRules(){return[new m.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:o,chain:e,range:t})=>{e().BNUpdateBlock(o.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:t.from,to:t.to})}})]},addKeyboardShortcuts(){return{Enter:()=>ft(this.editor)}},addProseMirrorPlugins(){return[we()]},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const e=o.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:o}){var n,r;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",m.mergeAttributes(o,{class:M(w.blockContent,e.class),"data-content-type":this.name}),["p",{class:M(w.inlineContent,t.class)},0]]}}),Ee=N({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:o}){var n,r;const e=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},t=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",m.mergeAttributes({...e,class:M(w.blockContent,e.class),"data-content-type":this.name},o),["p",{...t,class:M(w.inlineContent,t.class)},0]]}}),H={backgroundColor:{default:"transparent"},textColor:{default:"black"},textAlignment:{default:"left",values:["left","center","right","justify"]}},G={paragraph:{propSchema:H,node:Ee},heading:{propSchema:{...H,level:{default:"1",values:["1","2","3"]}},node:ve},bulletListItem:{propSchema:H,node:Ce},numberedListItem:{propSchema:H,node:Me}};function Be(o,e=JSON.stringify){const t={};return o.filter(n=>{const r=e(n);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Te(o){const e=o.filter((n,r)=>o.indexOf(n)!==r);return Be(e)}const R=m.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const o=window.__TEST_OPTIONS;return o.mockID===void 0?o.mockID=0:o.mockID++,o.mockID.toString()}return te.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:o=>o.getAttribute(`data-${this.options.attributeName}`),renderHTML:o=>({[`data-${this.options.attributeName}`]:o[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let o=null,e=!1;return[new b.Plugin({key:new b.PluginKey("uniqueID"),appendTransaction:(t,n,r)=>{const i=t.some(g=>g.docChanged)&&!n.doc.eq(r.doc),s=this.options.filterTransaction&&t.some(g=>{let v,C;return!(!((C=(v=this.options).filterTransaction)===null||C===void 0)&&C.call(v,g))});if(!i||s)return;const{tr:l}=r,{types:a,attributeName:d,generateID:c}=this.options,f=m.combineTransactionSteps(n.doc,t),{mapping:p}=f;if(m.getChangedRanges(f).forEach(({newRange:g})=>{const v=m.findChildrenInRange(r.doc,g,_=>a.includes(_.type.name)),C=v.map(({node:_})=>_.attrs[d]).filter(_=>_!==null),E=Te(C);v.forEach(({node:_,pos:F})=>{let K;const Ft=(K=l.doc.nodeAt(F))===null||K===void 0?void 0:K.attrs[d];if(Ft===null){l.setNodeMarkup(F,void 0,{..._.attrs,[d]:c()});return}const{deleted:sn}=p.invert().mapResult(F);sn&&E.includes(Ft)&&l.setNodeMarkup(F,void 0,{..._.attrs,[d]:c()})})}),!!l.steps.length)return l},view(t){const n=r=>{let i;o=!((i=t.dom.parentElement)===null||i===void 0)&&i.contains(r.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(t,n)=>{let r;return(o!==t.dom.parentElement||((r=n.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(o=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:t=>{if(!e)return t;const{types:n,attributeName:r}=this.options,i=s=>{const l=[];return s.forEach(a=>{if(a.isText){l.push(a);return}if(!n.includes(a.type.name)){l.push(a.copy(i(a.content)));return}const d=a.type.create({...a.attrs,[r]:null},i(a.content),a.marks);l.push(d)}),S.Fragment.from(l)};return e=!1,new S.Slice(i(t.content),t.openStart,t.openEnd)}}})]}}),mt=new Set(["bold","italic","underline","strike","code"]),kt=new Set(["textColor","backgroundColor"]);function gt(o,e){const t=[];for(const[n,r]of Object.entries(o.styles))mt.has(n)?t.push(e.mark(n)):kt.has(n)&&t.push(e.mark(n,{color:r}));return o.text.split(/(\n)/g).filter(n=>n.length>0).map(n=>n===`
|
|
2
|
+
`?e.nodes.hardBreak.create():e.text(n,t))}function xe(o,e){const t=e.marks.link.create({href:o.href});return bt(o.content,e).map(n=>{if(n.type.name==="text")return n.mark([...n.marks,t]);if(n.type.name==="hardBreak")return n;throw new Error("unexpected node type")})}function bt(o,e){const t=[];if(typeof o=="string")return t.push(...gt({type:"text",text:o,styles:{}},e)),t;for(const n of o)t.push(...gt(n,e));return t}function yt(o,e){const t=[];for(const n of o)if(n.type==="link")t.push(...xe(n,e));else if(n.type==="text")t.push(...bt([n],e));else throw new ct(n);return t}function D(o,e){let t=o.id;t===void 0&&(t=R.options.generateID());let n=o.type;n===void 0&&(n="paragraph");let r;if(!o.content)r=e.nodes[n].create(o.props);else if(typeof o.content=="string")r=e.nodes[n].create(o.props,e.text(o.content));else{const l=yt(o.content,e);r=e.nodes[n].create(o.props,l)}const i=[];if(o.children)for(const l of o.children)i.push(D(l,e));const s=e.nodes.blockGroup.create({},i);return e.nodes.blockContainer.create({id:t,...o.props},i.length>0?[r,s]:r)}function Ae(o){const e=[];let t;return o.content.forEach(n=>{if(n.type.name==="hardBreak"){t?t.type==="text"?t.text+=`
|
|
3
3
|
`:t.type==="link"&&(t.content[t.content.length-1].text+=`
|
|
4
4
|
`):t={type:"text",text:`
|
|
5
|
-
`,styles:{}};return}const r={};let i;for(const s of n.marks)if(s.type.name==="link")i=s;else if(ht.has(s.type.name))r[s.type.name]=!0;else if(ft.has(s.type.name))r[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);t?t.type==="text"?i?(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:n.textContent,styles:r}]}):JSON.stringify(t.styles)===JSON.stringify(r)?t.text+=n.textContent:(e.push(t),t={type:"text",text:n.textContent,styles:r}):t.type==="link"&&(i?t.href===i.attrs.href?JSON.stringify(t.content[t.content.length-1].styles)===JSON.stringify(r)?t.content[t.content.length-1].text+=n.textContent:t.content.push({type:"text",text:n.textContent,styles:r}):(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:n.textContent,styles:r}]}):(e.push(t),t={type:"text",text:n.textContent,styles:r})):i?t={type:"link",href:i.attrs.href,content:[{type:"text",text:n.textContent,styles:r}]}:t={type:"text",text:n.textContent,styles:r}}),t&&e.push(t),e}function x(o,e,t){if(o.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+o.type.name+".");const n=t==null?void 0:t.get(o);if(n)return n;const r=y(o,0);let i=r.id;i===null&&(i=R.options.generateID());const s={};for(const[c,f]of Object.entries({...r.node.attrs,...r.contentNode.attrs})){const p=e[r.contentType.name];if(!p)throw Error("Block is of an unrecognized type: "+r.contentType.name);const k=p.propSchema;c in k?s[c]=f:c!=="id"&&!(c in H)&&console.warn("Block has an unrecognized attribute: "+c)}const l=xe(r.contentNode),a=[];for(let c=0;c<r.numChildBlocks;c++)a.push(x(r.node.lastChild.child(c),e,t));const d={id:i,type:r.contentType.name,props:s,content:l,children:a};return t==null||t.set(o,d),d}const bt=new b.PluginKey("previous-blocks"),Ae={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},_e=()=>{let o;return new b.Plugin({key:bt,view(e){return{update:async(t,n)=>{var r;((r=this.key)==null?void 0:r.getState(t.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(bt,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,n,r){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||n.doc.eq(r.doc))return t;const i={},s=m.findChildren(n.doc,d=>d.attrs.id),l=new Map(s.map(d=>[d.node.attrs.id,d])),a=m.findChildren(r.doc,d=>d.attrs.id);for(let d of a){const c=l.get(d.node.attrs.id),f=c==null?void 0:c.node.firstChild,p=d.node.firstChild;if(c&&f&&p){const k={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:r.doc.resolve(d.pos).depth};let g={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:n.doc.resolve(c.pos).depth};i[d.node.attrs.id]=g,e.getMeta("numberedListIndexing")&&(d.node.attrs.id in t.prevTransactionOldBlockAttrs&&(g=t.prevTransactionOldBlockAttrs[d.node.attrs.id]),k.type==="numberedListItem"&&(g.index=k.index)),t.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(k)&&(g["depth-change"]=g.depth-k.depth,t.updatedBlocks.add(d.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=i,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const n=[];return e.doc.descendants((r,i)=>{if(!r.attrs.id||!t.updatedBlocks.has(r.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[r.attrs.id],l={};for(let[d,c]of Object.entries(s))l["data-prev-"+Ae[d]]=c||"none";const a=B.Decoration.node(i,i+r.nodeSize,{...l});n.push(a)}),B.DecorationSet.create(e.doc,n)}}})},Pe={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ie=m.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:o=>{if(typeof o=="string")return!1;const e={};for(let[t,n]of Object.entries(Pe))o.getAttribute(n)&&(e[t]=o.getAttribute(n));return o.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:o}){var t;const e=((t=this.options.domAttributes)==null?void 0:t.blockContainer)||{};return["div",m.mergeAttributes(o,{class:w.blockOuter,"data-node-type":"block-outer"}),["div",m.mergeAttributes({...e,class:M(w.block,e.class),"data-node-type":this.name},o),0]]},addCommands(){return{BNCreateBlock:o=>({state:e,dispatch:t})=>{const n=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(o,n),!0},BNDeleteBlock:o=>({state:e,dispatch:t})=>{const n=y(e.doc,o);if(n===void 0)return!1;const{startPos:r,endPos:i}=n;return t&&e.tr.deleteRange(r,i),!0},BNUpdateBlock:(o,e)=>({state:t,dispatch:n})=>{const r=y(t.doc,o);if(r===void 0)return!1;const{startPos:i,endPos:s,node:l,contentNode:a}=r;if(n){if(e.children!==void 0){const d=[];for(const c of e.children)d.push(D(c,t.schema));l.childCount===2?t.tr.replace(i+a.nodeSize+1,s-1,new S.Slice(S.Fragment.from(d),0,0)):t.tr.insert(i+a.nodeSize,t.schema.nodes.blockGroup.create({},d))}if(e.content!==void 0){let d=[];typeof e.content=="string"?d.push(t.schema.text(e.content)):d=gt(e.content,t.schema),t.tr.replace(i+1,i+a.nodeSize-1,new S.Slice(S.Fragment.from(d),0,0))}t.tr.setNodeMarkup(i,e.type===void 0?void 0:t.schema.nodes[e.type],{...a.attrs,...e.props}),t.tr.setNodeMarkup(i-1,void 0,{...l.attrs,...e.props})}return!0},BNMergeBlocks:o=>({state:e,dispatch:t})=>{const n=e.doc.resolve(o+1).node().type.name==="blockContainer",r=e.doc.resolve(o-1).node().type.name==="blockContainer";if(!n||!r)return!1;const i=y(e.doc,o+1),{node:s,contentNode:l,startPos:a,endPos:d,depth:c}=i;if(s.childCount===2){const k=e.doc.resolve(a+l.nodeSize+1),g=e.doc.resolve(d-1),v=k.blockRange(g);t&&e.tr.lift(v,c-1)}let f=o-1,p=y(e.doc,f);for(;p.numChildBlocks>0;)if(f--,p=y(e.doc,f),p===void 0)return!1;return t&&(t(e.tr.deleteRange(a,a+l.nodeSize).replace(f-1,a,new S.Slice(l.content,0,0)).scrollIntoView()),e.tr.setSelection(new b.TextSelection(e.doc.resolve(f-1)))),!0},BNSplitBlock:(o,e)=>({state:t,dispatch:n})=>{const r=y(t.doc,o);if(r===void 0)return!1;const{contentNode:i,contentType:s,startPos:l,endPos:a,depth:d}=r,c=t.doc.cut(l+1,o),f=t.doc.cut(o,a-1),p=t.schema.nodes.blockContainer.createAndFill(),k=a+1,g=k+2;return n&&(t.tr.insert(k,p),t.tr.replace(g,g+1,f.content.size>0?new S.Slice(S.Fragment.from(f),d+2,d+2):void 0),e&&t.tr.setBlockType(g,g,t.schema.node(s).type,i.attrs),t.tr.setSelection(new b.TextSelection(t.doc.resolve(g))),t.tr.replace(l+1,a-1,c.content.size>0?new S.Slice(S.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[_e()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:n})=>{const{contentType:r}=y(n.doc,n.selection.from),i=n.selection.$anchor.parentOffset===0,s=r.name==="paragraph";return i&&!s?t.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1}),()=>t.command(({state:n})=>n.selection.$anchor.parentOffset===0?t.liftListItem("blockContainer"):!1),()=>t.command(({state:n})=>{const{depth:r,startPos:i}=y(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,a=i===2,d=i-1;return!a&&s&&l&&r===2?t.BNMergeBlocks(d):!1})]),Enter:()=>this.editor.commands.first(({commands:t})=>[()=>t.command(({state:n})=>{const{node:r,depth:i}=y(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,a=r.textContent.length===0,d=i>2;return s&&l&&a&&d?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:n,chain:r})=>{const{node:i,endPos:s}=y(n.doc,n.selection.from),l=n.selection.$anchor.parentOffset===0,a=n.selection.anchor===n.selection.head,d=i.textContent.length===0;if(l&&a&&d){const c=s+1,f=c+2;return r().BNCreateBlock(c).setTextSelection(f).run(),!0}return!1}),()=>t.command(({state:n,chain:r})=>{const{node:i}=y(n.doc,n.selection.from);return i.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(n.selection.from,!1).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),"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"}}),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}}),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}}}),Ne=m.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:o=>typeof o=="string"?!1:o.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:o}){var t;const e=((t=this.options.domAttributes)==null?void 0:t.blockGroup)||{};return["div",m.mergeAttributes({...e,class:M(w.blockGroup,e.class),"data-node-type":"blockGroup"},o),0]}}),He=m.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Le=o=>{const e=S.DOMSerializer.fromSchema(o);return new S.DOMSerializer({...e.nodes},e.marks)},yt=m.Extension.create({addProseMirrorPlugins(){return[new b.Plugin({props:{clipboardSerializer:Le(this.editor.schema)}})]}});class V{constructor(){u(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 n=this.callbacks[e];n&&n.forEach(r=>r.apply(this,t))}off(e,t){const n=this.callbacks[e];n&&(t?this.callbacks[e]=n.filter(r=>r!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}const Oe=m.findParentNode(o=>o.type.name==="blockContainer");class De{constructor(e,t,n=()=>{}){u(this,"suggestionsMenuState");u(this,"updateSuggestionsMenu");u(this,"pluginState");u(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=$(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");n(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(e,t){const n=this.pluginKey.getState(t),r=this.pluginKey.getState(e.state),i=!n.active&&r.active,s=n.active&&!r.active,l=n.active&&r.active;if(!i&&!l&&!s)return;if(this.pluginState=s?n:r,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const a=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:a.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function $(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const vt=(o,e,t,n,r=()=>[],i=()=>{})=>{if(n.length!==1)throw new Error("'char' should be a single character");let s;const l=a=>{a.dispatch(a.state.tr.setMeta(t,{deactivate:!0}))};return{plugin:new b.Plugin({key:t,view:()=>(s=new De(o,t,e),s),state:{init(){return $()},apply(a,d,c,f){var k,g,v,C;if(a.getMeta("orderedListIndexing")!==void 0)return d;if((k=a.getMeta(t))!=null&&k.activate)return{active:!0,triggerCharacter:((g=a.getMeta(t))==null?void 0:g.triggerCharacter)||"",queryStartPos:f.selection.from,items:r(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const p={...d};if(p.items=r(f.doc.textBetween(d.queryStartPos,f.selection.from)),p.notFoundCount=0,p.items.length===0&&(p.notFoundCount=Math.max(0,d.notFoundCount+(f.selection.from-c.selection.from))),f.selection.from!==f.selection.to||(v=a.getMeta(t))!=null&&v.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||d.active&&f.selection.from<d.queryStartPos||p.notFoundCount>3)return $();if(((C=a.getMeta(t))==null?void 0:C.selectedItemIndexChanged)!==void 0){let E=a.getMeta(t).selectedItemIndexChanged;E<0?E=d.items.length-1:E>=d.items.length&&(E=0),p.keyboardHoveredItemIndex=E}else c.selection.from!==f.selection.from&&(p.keyboardHoveredItemIndex=0);return p}},props:{handleKeyDown(a,d){const c=this.getState(a.state).active;if(d.key===n&&!c)return a.dispatch(a.state.tr.insertText(n).scrollIntoView().setMeta(t,{activate:!0,triggerCharacter:n})),!0;if(!c)return!1;const{triggerCharacter:f,queryStartPos:p,items:k,keyboardHoveredItemIndex:g}=t.getState(a.state);return d.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(t,{selectedItemIndexChanged:g-1})),!0):d.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(t,{selectedItemIndexChanged:g+1})),!0):d.key==="Enter"?(l(a),o._tiptapEditor.chain().focus().deleteRange({from:p-f.length,to:o._tiptapEditor.state.selection.from}).run(),i({item:k[g],editor:o}),!0):d.key==="Escape"?(l(a),!0):!1},decorations(a){const{active:d,decorationId:c,queryStartPos:f,triggerCharacter:p}=this.getState(a);if(!d)return null;if(p===""){const k=Oe(a.selection);if(k)return B.DecorationSet.create(a.doc,[B.Decoration.node(k.pos,k.pos+k.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}return B.DecorationSet.create(a.doc,[B.Decoration.inline(f-p.length,f,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}}}),itemCallback:a=>{l(o._tiptapEditor.view),o._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:o._tiptapEditor.state.selection.from}).run(),i({item:a,editor:o})}}},z=new b.PluginKey("SlashMenuPlugin");class Ct extends V{constructor(t,n){super();u(this,"plugin");u(this,"itemCallback");const r=vt(t,i=>{this.emit("update",i)},z,"/",i=>n.filter(({name:s,aliases:l})=>s.toLowerCase().startsWith(i.toLowerCase())||l&&l.filter(a=>a.toLowerCase().startsWith(i.toLowerCase())).length!==0),({item:i,editor:s})=>i.execute(s));this.plugin=r.plugin,this.itemCallback=r.itemCallback}onUpdate(t){return this.on("update",t)}}const Re=new b.PluginKey("blocknote-placeholder"),Ve=m.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new b.Plugin({key:Re,props:{decorations:o=>{const{doc:e,selection:t}=o,n=z.getState(o),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,s=[];if(r)return e.descendants((l,a)=>{const d=i>=a&&i<=a+l.nodeSize,c=!l.isLeaf&&!l.childCount;if((d||!this.options.showOnlyCurrent)&&c){const f=[this.options.emptyNodeClass];this.editor.isEmpty&&f.push(this.options.emptyEditorClass),d&&f.push(this.options.hasAnchorClass),(n==null?void 0:n.triggerCharacter)===""&&(n!=null&&n.active)&&f.push(this.options.isFilterClass);const p=B.Decoration.node(a,a+l.nodeSize,{class:f.join(" ")});s.push(p)}return this.options.includeChildren}),B.DecorationSet.create(e,s)}}})]}}),ze=m.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:o=>o.getAttribute("data-text-alignment"),renderHTML:o=>o.textAlignment!=="left"&&{"data-text-alignment":o.textAlignment}}}}]},addCommands(){return{setTextAlignment:o=>({state:e})=>{const t=[],n=y(e.doc,e.selection.from);if(n===void 0)return!1;let r=n.startPos;for(;r<e.selection.to;)e.doc.resolve(r).node().type.spec.group==="blockContent"?(t.push(r-1),r+=e.doc.resolve(r).node().nodeSize-1):r+=1;for(const i of t)e.tr.setNodeAttribute(i,"textAlignment",o);return!0}}}}),Fe=m.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:"default",parseHTML:o=>o.hasAttribute("data-text-color")?o.getAttribute("data-text-color"):"default",renderHTML:o=>o.textColor!=="default"&&{"data-text-color":o.textColor}}}}]},addCommands(){return{setBlockTextColor:(o,e)=>({state:t,view:n})=>{const r=y(t.doc,o);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"textColor",e),n.focus(),!0)}}}}),Ue=m.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-text-color"),renderHTML:o=>({"data-text-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-text-color")?{color:o.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setTextColor:o=>({commands:e})=>o!=="default"?e.setMark(this.name,{color:o}):e.unsetMark(this.name)}}}),qe=m.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const o=new b.PluginKey(this.name);return[new b.Plugin({key:o,appendTransaction:(e,t,n)=>{const{doc:r,tr:i,schema:s}=n,l=o.getState(n),a=r.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(l)return i.insert(a,d.create(void 0,c.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let n=e.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")throw new Error("Expected blockContainer");return n.nodeSize>4}}})]}}),St=o=>{const e=[m.extensions.ClipboardTextSerializer,m.extensions.Commands,m.extensions.Editable,m.extensions.FocusEvents,m.extensions.Tabindex,Gt.Gapcursor,Ve.configure({emptyNodeClass:w.isEmpty,hasAnchorClass:w.hasAnchor,isFilterClass:w.isFilter,includeChildren:!0,showOnlyCurrent:!1}),R.configure({types:["blockContainer"]}),$t.HardBreak,Jt.Text,P.Bold,zt.Code,Kt.Italic,Yt.Strike,Xt.Underline,Wt.Link,Ue,Fe,me,fe,ze,He,Ie.configure({domAttributes:o.domAttributes}),Ne.configure({domAttributes:o.domAttributes}),...Object.values(o.blockSchema).map(t=>t.node.configure({editor:o.editor,domAttributes:o.domAttributes})),yt,qt.Dropcursor.configure({width:5,color:"#ddeeff"}),qe];if(o.collaboration){e.push(ae.default.configure({fragment:o.collaboration.fragment}));const t=n=>{const r=document.createElement("span");r.classList.add(I["collaboration-cursor__caret"]),r.setAttribute("style",`border-color: ${n.color}`);const i=document.createElement("span");i.classList.add(I["collaboration-cursor__label"]),i.setAttribute("style",`background-color: ${n.color}`),i.insertBefore(document.createTextNode(n.name),null);const s=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(s,null),r.insertBefore(i,null),r.insertBefore(l,null),r};e.push(le.default.configure({user:o.collaboration.user,render:o.collaboration.renderCursor||t,provider:o.collaboration.provider}))}else e.push(jt.History);return e};function j(o,e){let t,n;if(e.firstChild.descendants((r,i)=>t?!1:r.type.name!=="blockContainer"||r.attrs.id!==o?!0:(t=r,n=i+1,!1)),t===void 0||n===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:n}}function wt(o,e,t="before",n){const r=typeof e=="string"?e:e.id,i=[];for(const d of o)i.push(D(d,n.schema));let s=-1;const{node:l,posBeforeNode:a}=j(r,n.state.doc);if(t==="before"&&(s=a),t==="after"&&(s=a+l.nodeSize),t==="nested"){if(l.childCount<2){s=a+l.firstChild.nodeSize+1;const d=n.state.schema.nodes.blockGroup.create({},i);n.view.dispatch(n.state.tr.insert(s,d));return}s=a+l.firstChild.nodeSize+2}n.view.dispatch(n.state.tr.insert(s,i))}function Ge(o,e,t){const n=typeof o=="string"?o:o.id,{posBeforeNode:r}=j(n,t.state.doc);t.commands.BNUpdateBlock(r+1,e)}function Mt(o,e){const t=new Set(o.map(r=>typeof r=="string"?r:r.id));let n=0;if(e.state.doc.descendants((r,i)=>{if(t.size===0)return!1;if(r.type.name!=="blockContainer"||!t.has(r.attrs.id))return!0;t.delete(r.attrs.id);const s=e.state.doc.nodeSize;e.commands.BNDeleteBlock(i-n+1);const l=e.state.doc.nodeSize;return n+=s-l,!1}),t.size>0){let r=[...t].join(`
|
|
6
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function $e(o,e,t){wt(e,o[0],"before",t),Mt(o,t)}function je(){const o=e=>{let t=e.children.length;for(let n=0;n<t;n++){const r=e.children[n];if(r.type==="element"&&(o(r),r.tagName==="u"))if(r.children.length>0){e.children.splice(n,1,...r.children);const i=r.children.length-1;t+=i,n+=i}else e.children.splice(n,1),t--,n--}};return o}function Ke(o){const e=new Set([...o.orderedListItemBlockTypes,...o.unorderedListItemBlockTypes]),t=n=>{let r=n.children.length,i;for(let s=0;s<r;s++){const a=n.children[s].children[0],d=a.children[0],c=a.children.length===2?a.children[1]:null,f=e.has(d.properties.dataContentType),p=f?o.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(c!==null&&t(c),i&&i.tagName!==p){n.children.splice(s-i.children.length,i.children.length,i);const k=i.children.length-1;s-=k,r-=k,i=void 0}if(f){i||(i=W.fromDom(document.createElement(p)));const k=W.fromDom(document.createElement("li"));k.children.push(d.children[0]),c!==null&&k.children.push(...c.children),i.children.push(k)}else if(c!==null){n.children.splice(s+1,0,...c.children),n.children[s]=d.children[0];const k=c.children.length;s+=k,r+=k}else n.children[s]=d.children[0]}i&&n.children.splice(r-i.children.length,i.children.length,i)};return t}async function Et(o,e){const t=document.createElement("div"),n=S.DOMSerializer.fromSchema(e);for(const i of o){const s=D(i,e),l=n.serializeNode(s);t.appendChild(l)}return(await U.unified().use(Y.default,{fragment:!0}).use(Ke,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(J.default).process(t.innerHTML)).value}async function Bt(o,e,t){const n=document.createElement("div");n.innerHTML=o.trim();const i=S.DOMParser.fromSchema(t).parse(n),s=[];for(let l=0;l<i.firstChild.childCount;l++)s.push(x(i.firstChild.child(l),e));return s}async function We(o,e){return(await U.unified().use(Y.default,{fragment:!0}).use(je).use(ce.default).use(X.default).use(he.default).process(await Et(o,e))).value}async function Ye(o,e,t){const n=await U.unified().use(ue.default).use(X.default).use(pe.default).use(J.default).process(o);return Bt(n.value,e,t)}class Tt{constructor(e,t,n){u(this,"formattingToolbarState");u(this,"updateFormattingToolbar");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({view:e,state:t,from:n,to:r})=>{const{doc:i,selection:s}=t,{empty:l}=s,a=!i.textBetween(n,r).length&&m.isTextSelection(t.selection);return!(!e.hasFocus()||l||a)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragstartHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",e=>{var n;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(n=this.formattingToolbarState)!=null&&n.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(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");n(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 p,k;const{state:n,composing:r}=e,{doc:i,selection:s}=n,l=t&&t.doc.eq(i)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(r||l))return;this.prevWasEditable=this.editor.isEditable;const{ranges:a}=s,d=Math.min(...a.map(g=>g.$from.pos)),c=Math.max(...a.map(g=>g.$to.pos)),f=(p=this.shouldShow)==null?void 0:p.call(this,{view:e,state:n,from:d,to:c});if(this.editor.isEditable&&!this.preventShow&&(f||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((k=this.formattingToolbarState)!=null&&k.show&&!this.preventHide&&(!f||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:n}=t,r=Math.min(...n.map(s=>s.$from.pos)),i=Math.max(...n.map(s=>s.$to.pos));if(m.isNodeSelection(t)){const s=this.pmView.nodeDOM(r);if(s)return s.getBoundingClientRect()}return m.posToDOMRect(this.pmView,r,i)}}const xt=new b.PluginKey("FormattingToolbarPlugin");class At extends V{constructor(t){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:xt,view:n=>(this.view=new Tt(t,n,r=>{this.emit("update",r)}),this.view)})}onUpdate(t){return this.on("update",t)}}class Je{constructor(e,t,n){u(this,"hyperlinkToolbarState");u(this,"updateHyperlinkToolbar");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredHyperlinkMark");u(this,"mouseHoveredHyperlinkMarkRange");u(this,"keyboardHoveredHyperlinkMark");u(this,"keyboardHoveredHyperlinkMarkRange");u(this,"hyperlinkMark");u(this,"hyperlinkMarkRange");u(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,n=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(n),i=r.marks();for(const s of i)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=m.getMarkRange(r,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",e=>{var n;const t=this.pmView.dom.parentElement;this.hyperlinkMark&&e&&e.target&&!(t===e.target||t.contains(e.target))&&(n=this.hyperlinkToolbarState)!=null&&n.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});u(this,"scrollHandler",()=>{var e;this.hyperlinkMark!==void 0&&(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.referencePos=m.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");n(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 r;const n=this.pmView.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);n.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:e})),this.pmView.dispatch(n),this.pmView.focus(),(r=this.hyperlinkToolbarState)!=null&&r.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 n=this.pmView.state.selection.$from.marks();for(const r of n)if(r.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=r,this.keyboardHoveredHyperlinkMarkRange=m.getMarkRange(this.pmView.state.selection.$from,r.type,r.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:m.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 _t=new b.PluginKey("HyperlinkToolbarPlugin");class Pt extends V{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"editHyperlink",(t,n)=>{this.view.editHyperlink(t,n)});u(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new b.Plugin({key:_t,view:n=>(this.view=new Je(t,n,r=>{this.emit("update",r)}),this.view)})}onUpdate(t){return this.on("update",t)}}class L extends b.Selection{constructor(t,n){super(t,n);u(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,n.pos,(i,s,l)=>{if(l!==null&&l.eq(r))return this.nodes.push(i),!1})}static create(t,n,r=n){return new L(t.resolve(n),t.resolve(r))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof L)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(t.nodes[n]))return!1;return!0}map(t,n){let r=n.mapResult(this.from),i=n.mapResult(this.to);return i.deleted?b.Selection.near(t.resolve(r.pos)):r.deleted?b.Selection.near(t.resolve(i.pos)):new L(t.resolve(r.pos),t.resolve(i.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Xe=de.__serializeForClipboard;let A;function It(o,e){var r;if(!e.dom.isConnected)return;let t=e.posAtCoords(o);if(!t)return;let n=e.domAtPos(t.pos).node;if(n!==e.dom){for(;n&&n.parentNode&&n.parentNode!==e.dom&&!((r=n.hasAttribute)!=null&&r.call(n,"data-id"));)n=n.parentNode;if(n)return{node:n,id:n.getAttribute("data-id")}}}function Ze(o,e){let t=It(o,e);if(t&&t.node.nodeType===1){const n=e.docView;let r=n.nearestDesc(t.node,!0);return!r||r===n?null:r.posBefore}return null}function Qe(o,e){let t,n;const r=e.resolve(o.from).node().type.spec.group==="blockContent",i=e.resolve(o.to).node().type.spec.group==="blockContent",s=Math.min(o.$anchor.depth,o.$head.depth);if(r&&i){const l=o.$from.start(s-1),a=o.$to.end(s-1);t=e.resolve(l-1).pos,n=e.resolve(a+1).pos}else t=o.from,n=o.to;return{from:t,to:n}}function Nt(o,e,t=e){e===t&&(t+=o.state.doc.resolve(e+1).node().nodeSize);const n=o.domAtPos(e).node.cloneNode(!0),r=o.domAtPos(e).node,i=(c,f)=>Array.prototype.indexOf.call(c.children,f),s=i(r,o.domAtPos(e+1).node.parentElement),l=i(r,o.domAtPos(t-1).node.parentElement);for(let c=r.childElementCount-1;c>=0;c--)(c>l||c<s)&&n.removeChild(n.children[c]);Ht(),A=n;const d=o.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");A.className=A.className+" "+I.dragPreview+" "+d,document.body.appendChild(A)}function Ht(){A!==void 0&&(document.body.removeChild(A),A=void 0)}function tn(o,e){if(!o.dataTransfer)return;const t=e.dom.getBoundingClientRect();let n={left:t.left+t.width/2,top:o.clientY},r=Ze(n,e);if(r!=null){const i=e.state.selection,s=e.state.doc,{from:l,to:a}=Qe(i,s),d=l<=r&&r<a,c=i.$anchor.node()!==i.$head.node()||i instanceof L;d&&c?(e.dispatch(e.state.tr.setSelection(L.create(s,l,a))),Nt(e,l,a)):(e.dispatch(e.state.tr.setSelection(b.NodeSelection.create(e.state.doc,r))),Nt(e,r));let f=e.state.selection.content(),{dom:p,text:k}=Xe(e,f);o.dataTransfer.clearData(),o.dataTransfer.setData("text/html",p.innerHTML),o.dataTransfer.setData("text/plain",k),o.dataTransfer.effectAllowed="move",o.dataTransfer.setDragImage(A,0,0),e.dragging={slice:f,move:!0}}}class Lt{constructor(e,t,n){u(this,"sideMenuState");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",e=>{if(this.editor._tiptapEditor.commands.blur(),e.synthetic||!this.isDragging)return;let t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(this.isDragging=!1,!t||t.inside===-1){const n=new Event("drop",e),r=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=r.left+r.width/2,n.clientY=e.clientY,n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onDragOver",e=>{if(e.synthetic||!this.isDragging)return;let t=this.pmView.posAtCoords({left:e.clientX,top:e.clientY});if(!t||t.inside===-1){const n=new Event("dragover",e),r=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=r.left+r.width/2,n.clientY=e.clientY,n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onKeyDown",e=>{var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});u(this,"onMouseMove",e=>{var d,c,f,p,k;if(this.menuFrozen)return;const t=this.pmView.dom.firstChild.getBoundingClientRect(),n=this.pmView.dom.getBoundingClientRect(),r=e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom,i=this.pmView.dom.parentElement;if(r&&e&&e.target&&!(i===e.target||i.contains(e.target))){(d=this.sideMenuState)!=null&&d.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},l=It(s,this.pmView);if(!l||!this.editor.isEditable){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((f=this.sideMenuState)!=null&&f.show&&((p=this.hoveredBlock)!=null&&p.hasAttribute("data-id"))&&((k=this.hoveredBlock)==null?void 0:k.getAttribute("data-id"))===l.id)return;this.hoveredBlock=l.node;const a=l.node.firstChild;if(a&&this.editor.isEditable){const g=a.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)}});u(this,"onScroll",()=>{var e;if((e=this.sideMenuState)!=null&&e.show){const n=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:n.x,n.y,n.width,n.height),this.updateSideMenu(this.sideMenuState)}});this.editor=e,this.pmView=t,this.updateSideMenu=n,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("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("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(),n=this.pmView.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!n)return;const r=y(this.editor._tiptapEditor.state.doc,n.pos);if(r===void 0)return;const{contentNode:i,endPos:s}=r;if(i.textContent.length!==0){const a=s+1,d=a+2;this.editor._tiptapEditor.chain().BNCreateBlock(a).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(z,{activate:!0,type:"drag"}))}}const Ot=new b.PluginKey("SideMenuPlugin");class Dt extends V{constructor(t){super();u(this,"sideMenuView");u(this,"plugin");u(this,"addBlock",()=>this.sideMenuView.addBlock());u(this,"blockDragStart",t=>{this.sideMenuView.isDragging=!0,tn(t,this.editor.prosemirrorView)});u(this,"blockDragEnd",()=>Ht());u(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=t,this.plugin=new b.Plugin({key:Ot,view:n=>(this.sideMenuView=new Lt(t,n,r=>{this.emit("update",r)}),this.sideMenuView)})}onUpdate(t){return this.on("update",t)}}function O(o,e){const t=o.getTextCursorPosition().block;t.content.length===1&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0?o.updateBlock(t,e):(o.insertBlocks([e],t,"after"),o.setTextCursorPosition(o.getTextCursorPosition().nextBlock))}const Rt=(o=G)=>{var t,n,r;const e=[];return"heading"in o&&"level"in o.heading.propSchema&&((t=o.heading.propSchema.level.values)!=null&&t.includes("1")&&e.push({name:"Heading",aliases:["h","heading1","h1"],execute:i=>O(i,{type:"heading",props:{level:"1"}})}),(n=o.heading.propSchema.level.values)!=null&&n.includes("2")&&e.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:i=>O(i,{type:"heading",props:{level:"2"}})}),(r=o.heading.propSchema.level.values)!=null&&r.includes("3")&&e.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:i=>O(i,{type:"heading",props:{level:"3"}})})),"bulletListItem"in o&&e.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:i=>O(i,{type:"bulletListItem"})}),"numberedListItem"in o&&e.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:i=>O(i,{type:"numberedListItem"})}),"paragraph"in o&&e.push({name:"Paragraph",aliases:["p"],execute:i=>O(i,{type:"paragraph"})}),e},en={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class nn{constructor(e={}){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"ready",!1);u(this,"sideMenu");u(this,"formattingToolbar");u(this,"slashMenu");u(this,"hyperlinkToolbar");var l,a,d,c,f;this.options=e;const t={defaultStyles:!0,blockSchema:e.blockSchema||G,...e};this.sideMenu=new Dt(this),this.formattingToolbar=new At(this),this.slashMenu=new Ct(this,t.slashMenuItems||Rt(t.blockSchema)),this.hyperlinkToolbar=new Pt(this);const n=St({editor:this,domAttributes:t.domAttributes||{},blockSchema:t.blockSchema,collaboration:t.collaboration}),r=m.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin]});n.push(r),this.schema=t.blockSchema;const i=t.initialContent||(e.collaboration?void 0:[{type:"paragraph",id:R.options.generateID()}]),s={...en,...t._tiptapOptions,onCreate:()=>{var p;(p=t.onEditorReady)==null||p.call(t,this),this.ready=!0},onBeforeCreate(p){if(!i)return;const k=p.editor.schema,g=i.map(C=>D(C,k)),v=k.node("doc",void 0,k.node("blockGroup",void 0,g));p.editor.options.content=v.toJSON()},onUpdate:()=>{var p;this.ready&&((p=t.onEditorContentChange)==null||p.call(t,this))},onSelectionUpdate:()=>{var p;this.ready&&((p=t.onTextCursorPositionChange)==null||p.call(t,this))},editable:e.editable===void 0?!0:e.editable,extensions:t.enableBlockNoteExtensions===!1?(l=t._tiptapOptions)==null?void 0:l.extensions:[...((a=t._tiptapOptions)==null?void 0:a.extensions)||[],...n],editorProps:{attributes:{...(d=t.domAttributes)==null?void 0:d.editor,class:M(I.bnEditor,I.bnRoot,t.defaultStyles?I.defaultStyles:"",((f=(c=t.domAttributes)==null?void 0:c.editor)==null?void 0:f.class)||"")}}};t.parentElement&&(s.element=t.parentElement),this._tiptapEditor=new m.Editor(s)}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(x(t,this.schema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let n;return this._tiptapEditor.state.doc.firstChild.descendants(r=>typeof n<"u"?!1:r.type.name!=="blockContainer"||r.attrs.id!==t?!0:(n=x(r,this.schema,this.blockCache),!1)),n}forEachBlock(e,t=!1){const n=this.topLevelBlocks.slice();t&&n.reverse();function r(i){for(const s of i){if(!e(s))return!1;const l=t?s.children.slice().reverse():s.children;if(!r(l))return!1}return!0}r(n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:n,endPos:r}=y(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),i=this._tiptapEditor.state.doc.resolve(r).index(t-1),s=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let l;i>0&&(l=this._tiptapEditor.state.doc.resolve(n-2).node());let a;return i<s-1&&(a=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:x(e,this.schema,this.blockCache),prevBlock:l===void 0?void 0:x(l,this.schema,this.blockCache),nextBlock:a===void 0?void 0:x(a,this.schema,this.blockCache)}}setTextCursorPosition(e,t="start"){const n=typeof e=="string"?e:e.id,{posBeforeNode:r}=j(n,this._tiptapEditor.state.doc),{startPos:i,contentNode:s}=y(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,n)=>t.type.spec.group!=="blockContent"||n+t.nodeSize<this._tiptapEditor.state.selection.from||n>this._tiptapEditor.state.selection.to?!0:(e.push(x(this._tiptapEditor.state.doc.resolve(n).node(),this.schema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,n="before"){wt(e,t,n,this._tiptapEditor)}updateBlock(e,t){Ge(e,t,this._tiptapEditor)}removeBlocks(e){Mt(e,this._tiptapEditor)}replaceBlocks(e,t){$e(e,t,this._tiptapEditor)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks(),n=new Set(["bold","italic","underline","strike","code"]),r=new Set(["textColor","backgroundColor"]);for(const i of t)n.has(i.type.name)?e[i.type.name]=!0:r.has(i.type.name)&&(e[i.type.name]=i.attrs.color);return e}addStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.setMark(r):n.has(r)&&this._tiptapEditor.commands.setMark(r,{color:i})}removeStyles(e){this._tiptapEditor.view.focus();for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.toggleMark(r):n.has(r)&&this._tiptapEditor.commands.toggleMark(r,{color:i})}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;let{from:n,to:r}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(n,r));const i=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,n,r).addMark(n,n+t.length,i))}canNestBlock(){const{startPos:e,depth:t}=y(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}=y(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(e){return Et(e,this._tiptapEditor.schema)}async HTMLToBlocks(e){return Bt(e,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(e){return We(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return Ye(e,this.schema,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)}}h.BlockNoteEditor=nn,h.CustomBlockSerializerExtension=yt,h.FormattingToolbarProsemirrorPlugin=At,h.FormattingToolbarView=Tt,h.HyperlinkToolbarProsemirrorPlugin=Pt,h.SideMenuProsemirrorPlugin=Dt,h.SideMenuView=Lt,h.SlashMenuProsemirrorPlugin=Ct,h.UnreachableCaseError=lt,h.blockStyles=ke,h.camelToDataKebab=q,h.createBlockSpec=be,h.createTipTapBlock=N,h.defaultBlockSchema=G,h.defaultProps=H,h.formatKeyboardShortcut=ge,h.formattingToolbarPluginKey=xt,h.getBlockNoteExtensions=St,h.getDefaultSlashMenuItems=Rt,h.hyperlinkToolbarPluginKey=_t,h.isAppleOS=at,h.mergeCSSClasses=M,h.parse=ct,h.propsToAttributes=dt,h.render=ut,h.setupSuggestionsMenu=vt,h.sideMenuPluginKey=Ot,h.slashMenuPluginKey=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
5
|
+
`,styles:{}};return}const r={};let i;for(const s of n.marks)if(s.type.name==="link")i=s;else if(mt.has(s.type.name))r[s.type.name]=!0;else if(kt.has(s.type.name))r[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);t?t.type==="text"?i?(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:n.textContent,styles:r}]}):JSON.stringify(t.styles)===JSON.stringify(r)?t.text+=n.textContent:(e.push(t),t={type:"text",text:n.textContent,styles:r}):t.type==="link"&&(i?t.href===i.attrs.href?JSON.stringify(t.content[t.content.length-1].styles)===JSON.stringify(r)?t.content[t.content.length-1].text+=n.textContent:t.content.push({type:"text",text:n.textContent,styles:r}):(e.push(t),t={type:"link",href:i.attrs.href,content:[{type:"text",text:n.textContent,styles:r}]}):(e.push(t),t={type:"text",text:n.textContent,styles:r})):i?t={type:"link",href:i.attrs.href,content:[{type:"text",text:n.textContent,styles:r}]}:t={type:"text",text:n.textContent,styles:r}}),t&&e.push(t),e}function x(o,e,t){if(o.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+o.type.name+".");const n=t==null?void 0:t.get(o);if(n)return n;const r=Q(o);let i=r.id;i===null&&(i=R.options.generateID());const s={};for(const[c,f]of Object.entries({...o.attrs,...r.contentNode.attrs})){const p=e[r.contentType.name];if(!p)throw Error("Block is of an unrecognized type: "+r.contentType.name);const k=p.propSchema;c in k?s[c]=f:c!=="id"&&!(c in H)&&console.warn("Block has an unrecognized attribute: "+c)}const l=Ae(r.contentNode),a=[];for(let c=0;c<r.numChildBlocks;c++)a.push(x(o.lastChild.child(c),e,t));const d={id:i,type:r.contentType.name,props:s,content:l,children:a};return t==null||t.set(o,d),d}const vt=new b.PluginKey("previous-blocks"),_e={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Pe=()=>{let o;return new b.Plugin({key:vt,view(e){return{update:async(t,n)=>{var r;((r=this.key)==null?void 0:r.getState(t.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(vt,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(e,t,n,r){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||n.doc.eq(r.doc))return t;const i={},s=m.findChildren(n.doc,d=>d.attrs.id),l=new Map(s.map(d=>[d.node.attrs.id,d])),a=m.findChildren(r.doc,d=>d.attrs.id);for(const d of a){const c=l.get(d.node.attrs.id),f=c==null?void 0:c.node.firstChild,p=d.node.firstChild;if(c&&f&&p){const k={index:p.attrs.index,level:p.attrs.level,type:p.type.name,depth:r.doc.resolve(d.pos).depth};let g={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:n.doc.resolve(c.pos).depth};i[d.node.attrs.id]=g,e.getMeta("numberedListIndexing")&&(d.node.attrs.id in t.prevTransactionOldBlockAttrs&&(g=t.prevTransactionOldBlockAttrs[d.node.attrs.id]),k.type==="numberedListItem"&&(g.index=k.index)),t.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(k)&&(g["depth-change"]=g.depth-k.depth,t.updatedBlocks.add(d.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=i,t}},props:{decorations(e){const t=this.getState(e);if(t.updatedBlocks.size===0)return;const n=[];return e.doc.descendants((r,i)=>{if(!r.attrs.id||!t.updatedBlocks.has(r.attrs.id))return;const s=t.currentTransactionOldBlockAttrs[r.attrs.id],l={};for(const[d,c]of Object.entries(s))l["data-prev-"+_e[d]]=c||"none";const a=B.Decoration.node(i,i+r.nodeSize,{...l});n.push(a)}),B.DecorationSet.create(e.doc,n)}}})},Ie={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ne=m.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:o=>{if(typeof o=="string")return!1;const e={};for(const[t,n]of Object.entries(Ie))o.getAttribute(n)&&(e[t]=o.getAttribute(n));return o.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:o}){var t;const e=((t=this.options.domAttributes)==null?void 0:t.blockContainer)||{};return["div",m.mergeAttributes(o,{class:w.blockOuter,"data-node-type":"block-outer"}),["div",m.mergeAttributes({...e,class:M(w.block,e.class),"data-node-type":this.name},o),0]]},addCommands(){return{BNCreateBlock:o=>({state:e,dispatch:t})=>{const n=e.schema.nodes.blockContainer.createAndFill();return t&&e.tr.insert(o,n),!0},BNDeleteBlock:o=>({state:e,dispatch:t})=>{const n=y(e.doc,o);if(n===void 0)return!1;const{startPos:r,endPos:i}=n;return t&&e.tr.deleteRange(r,i),!0},BNUpdateBlock:(o,e)=>({state:t,dispatch:n})=>{const r=y(t.doc,o);if(r===void 0)return!1;const{startPos:i,endPos:s,node:l,contentNode:a}=r;if(n){if(e.children!==void 0){const d=[];for(const c of e.children)d.push(D(c,t.schema));l.childCount===2?t.tr.replace(i+a.nodeSize+1,s-1,new S.Slice(S.Fragment.from(d),0,0)):t.tr.insert(i+a.nodeSize,t.schema.nodes.blockGroup.create({},d))}if(e.content!==void 0){let d=[];typeof e.content=="string"?d.push(t.schema.text(e.content)):d=yt(e.content,t.schema),t.tr.replace(i+1,i+a.nodeSize-1,new S.Slice(S.Fragment.from(d),0,0))}t.tr.setNodeMarkup(i,e.type===void 0?void 0:t.schema.nodes[e.type],{...a.attrs,...e.props}),t.tr.setNodeMarkup(i-1,void 0,{...l.attrs,...e.props})}return!0},BNMergeBlocks:o=>({state:e,dispatch:t})=>{const n=e.doc.resolve(o+1).node().type.name==="blockContainer",r=e.doc.resolve(o-1).node().type.name==="blockContainer";if(!n||!r)return!1;const i=y(e.doc,o+1),{node:s,contentNode:l,startPos:a,endPos:d,depth:c}=i;if(s.childCount===2){const k=e.doc.resolve(a+l.nodeSize+1),g=e.doc.resolve(d-1),v=k.blockRange(g);t&&e.tr.lift(v,c-1)}let f=o-1,p=y(e.doc,f);for(;p.numChildBlocks>0;)if(f--,p=y(e.doc,f),p===void 0)return!1;return t&&(t(e.tr.deleteRange(a,a+l.nodeSize).replace(f-1,a,new S.Slice(l.content,0,0)).scrollIntoView()),e.tr.setSelection(new b.TextSelection(e.doc.resolve(f-1)))),!0},BNSplitBlock:(o,e)=>({state:t,dispatch:n})=>{const r=y(t.doc,o);if(r===void 0)return!1;const{contentNode:i,contentType:s,startPos:l,endPos:a,depth:d}=r,c=t.doc.cut(l+1,o),f=t.doc.cut(o,a-1),p=t.schema.nodes.blockContainer.createAndFill(),k=a+1,g=k+2;return n&&(t.tr.insert(k,p),t.tr.replace(g,g+1,f.content.size>0?new S.Slice(S.Fragment.from(f),d+2,d+2):void 0),e&&t.tr.setBlockType(g,g,t.schema.node(s).type,i.attrs),t.tr.setSelection(new b.TextSelection(t.doc.resolve(g))),t.tr.replace(l+1,a-1,c.content.size>0?new S.Slice(S.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Pe()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:n})=>{const{contentType:r}=y(n.doc,n.selection.from),i=n.selection.$anchor.parentOffset===0,s=r.name==="paragraph";return i&&!s?t.BNUpdateBlock(n.selection.from,{type:"paragraph",props:{}}):!1}),()=>t.command(({state:n})=>n.selection.$anchor.parentOffset===0?t.liftListItem("blockContainer"):!1),()=>t.command(({state:n})=>{const{depth:r,startPos:i}=y(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,a=i===2,d=i-1;return!a&&s&&l&&r===2?t.BNMergeBlocks(d):!1})]),Enter:()=>this.editor.commands.first(({commands:t})=>[()=>t.command(({state:n})=>{const{node:r,depth:i}=y(n.doc,n.selection.from),s=n.selection.$anchor.parentOffset===0,l=n.selection.anchor===n.selection.head,a=r.textContent.length===0,d=i>2;return s&&l&&a&&d?t.liftListItem("blockContainer"):!1}),()=>t.command(({state:n,chain:r})=>{const{node:i,endPos:s}=y(n.doc,n.selection.from),l=n.selection.$anchor.parentOffset===0,a=n.selection.anchor===n.selection.head,d=i.textContent.length===0;if(l&&a&&d){const c=s+1,f=c+2;return r().BNCreateBlock(c).setTextSelection(f).run(),!0}return!1}),()=>t.command(({state:n,chain:r})=>{const{node:i}=y(n.doc,n.selection.from);return i.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(n.selection.from,!1).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),"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"}}),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}}),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}}}),He=m.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:o=>typeof o=="string"?!1:o.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:o}){var t;const e=((t=this.options.domAttributes)==null?void 0:t.blockGroup)||{};return["div",m.mergeAttributes({...e,class:M(w.blockGroup,e.class),"data-node-type":"blockGroup"},o),0]}}),Le=m.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Oe=o=>{const e=S.DOMSerializer.fromSchema(o);return new S.DOMSerializer({...e.nodes},e.marks)},Ct=m.Extension.create({addProseMirrorPlugins(){return[new b.Plugin({props:{clipboardSerializer:Oe(this.editor.schema)}})]}});class V{constructor(){u(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 n=this.callbacks[e];n&&n.forEach(r=>r.apply(this,t))}off(e,t){const n=this.callbacks[e];n&&(t?this.callbacks[e]=n.filter(r=>r!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}const De=m.findParentNode(o=>o.type.name==="blockContainer");class Re{constructor(e,t,n=()=>{}){u(this,"suggestionsMenuState");u(this,"updateSuggestionsMenu");u(this,"pluginState");u(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=$(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");n(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(e,t){const n=this.pluginKey.getState(t),r=this.pluginKey.getState(e.state),i=!n.active&&r.active,s=n.active&&!r.active,l=n.active&&r.active;if(!i&&!l&&!s)return;if(this.pluginState=s?n:r,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const a=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:a.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function $(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const St=(o,e,t,n,r=()=>[],i=()=>{})=>{if(n.length!==1)throw new Error("'char' should be a single character");let s;const l=a=>{a.dispatch(a.state.tr.setMeta(t,{deactivate:!0}))};return{plugin:new b.Plugin({key:t,view:()=>(s=new Re(o,t,e),s),state:{init(){return $()},apply(a,d,c,f){var k,g,v,C;if(a.getMeta("orderedListIndexing")!==void 0)return d;if((k=a.getMeta(t))!=null&&k.activate)return{active:!0,triggerCharacter:((g=a.getMeta(t))==null?void 0:g.triggerCharacter)||"",queryStartPos:f.selection.from,items:r(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const p={...d};if(p.items=r(f.doc.textBetween(d.queryStartPos,f.selection.from)),p.notFoundCount=0,p.items.length===0&&(p.notFoundCount=Math.max(0,d.notFoundCount+(f.selection.from-c.selection.from))),f.selection.from!==f.selection.to||(v=a.getMeta(t))!=null&&v.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||d.active&&f.selection.from<d.queryStartPos||p.notFoundCount>3)return $();if(((C=a.getMeta(t))==null?void 0:C.selectedItemIndexChanged)!==void 0){let E=a.getMeta(t).selectedItemIndexChanged;E<0?E=d.items.length-1:E>=d.items.length&&(E=0),p.keyboardHoveredItemIndex=E}else c.selection.from!==f.selection.from&&(p.keyboardHoveredItemIndex=0);return p}},props:{handleKeyDown(a,d){const c=this.getState(a.state).active;if(d.key===n&&!c)return a.dispatch(a.state.tr.insertText(n).scrollIntoView().setMeta(t,{activate:!0,triggerCharacter:n})),!0;if(!c)return!1;const{triggerCharacter:f,queryStartPos:p,items:k,keyboardHoveredItemIndex:g}=t.getState(a.state);return d.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(t,{selectedItemIndexChanged:g-1})),!0):d.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(t,{selectedItemIndexChanged:g+1})),!0):d.key==="Enter"?(l(a),o._tiptapEditor.chain().focus().deleteRange({from:p-f.length,to:o._tiptapEditor.state.selection.from}).run(),i({item:k[g],editor:o}),!0):d.key==="Escape"?(l(a),!0):!1},decorations(a){const{active:d,decorationId:c,queryStartPos:f,triggerCharacter:p}=this.getState(a);if(!d)return null;if(p===""){const k=De(a.selection);if(k)return B.DecorationSet.create(a.doc,[B.Decoration.node(k.pos,k.pos+k.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}return B.DecorationSet.create(a.doc,[B.Decoration.inline(f-p.length,f,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}}}),itemCallback:a=>{l(o._tiptapEditor.view),o._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:o._tiptapEditor.state.selection.from}).run(),i({item:a,editor:o})}}},z=new b.PluginKey("SlashMenuPlugin");class wt extends V{constructor(t,n){super();u(this,"plugin");u(this,"itemCallback");const r=St(t,i=>{this.emit("update",i)},z,"/",i=>n.filter(({name:s,aliases:l})=>s.toLowerCase().startsWith(i.toLowerCase())||l&&l.filter(a=>a.toLowerCase().startsWith(i.toLowerCase())).length!==0),({item:i,editor:s})=>i.execute(s));this.plugin=r.plugin,this.itemCallback=r.itemCallback}onUpdate(t){return this.on("update",t)}}const Ve=new b.PluginKey("blocknote-placeholder"),ze=m.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new b.Plugin({key:Ve,props:{decorations:o=>{const{doc:e,selection:t}=o,n=z.getState(o),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=t,s=[];if(r)return e.descendants((l,a)=>{const d=i>=a&&i<=a+l.nodeSize,c=!l.isLeaf&&!l.childCount;if((d||!this.options.showOnlyCurrent)&&c){const f=[this.options.emptyNodeClass];this.editor.isEmpty&&f.push(this.options.emptyEditorClass),d&&f.push(this.options.hasAnchorClass),(n==null?void 0:n.triggerCharacter)===""&&(n!=null&&n.active)&&f.push(this.options.isFilterClass);const p=B.Decoration.node(a,a+l.nodeSize,{class:f.join(" ")});s.push(p)}return this.options.includeChildren}),B.DecorationSet.create(e,s)}}})]}}),Fe=m.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:o=>o.getAttribute("data-text-alignment"),renderHTML:o=>o.textAlignment!=="left"&&{"data-text-alignment":o.textAlignment}}}}]},addCommands(){return{setTextAlignment:o=>({state:e})=>{const t=[],n=y(e.doc,e.selection.from);if(n===void 0)return!1;let r=n.startPos;for(;r<e.selection.to;)e.doc.resolve(r).node().type.spec.group==="blockContent"?(t.push(r-1),r+=e.doc.resolve(r).node().nodeSize-1):r+=1;for(const i of t)e.tr.setNodeAttribute(i,"textAlignment",o);return!0}}}}),Ue=m.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:"default",parseHTML:o=>o.hasAttribute("data-text-color")?o.getAttribute("data-text-color"):"default",renderHTML:o=>o.textColor!=="default"&&{"data-text-color":o.textColor}}}}]},addCommands(){return{setBlockTextColor:(o,e)=>({state:t,view:n})=>{const r=y(t.doc,o);return r===void 0?!1:(t.tr.setNodeAttribute(r.startPos-1,"textColor",e),n.focus(),!0)}}}}),qe=m.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-text-color"),renderHTML:o=>({"data-text-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-text-color")?{color:o.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setTextColor:o=>({commands:e})=>o!=="default"?e.setMark(this.name,{color:o}):e.unsetMark(this.name)}}}),Ge=m.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const o=new b.PluginKey(this.name);return[new b.Plugin({key:o,appendTransaction:(e,t,n)=>{const{doc:r,tr:i,schema:s}=n,l=o.getState(n),a=r.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(l)return i.insert(a,d.create(void 0,c.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let n=e.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")throw new Error("Expected blockContainer");return n.nodeSize>4}}})]}}),Mt=o=>{var t;const e=[m.extensions.ClipboardTextSerializer,m.extensions.Commands,m.extensions.Editable,m.extensions.FocusEvents,m.extensions.Tabindex,jt.Gapcursor,ze.configure({emptyNodeClass:w.isEmpty,hasAnchorClass:w.hasAnchor,isFilterClass:w.isFilter,includeChildren:!0,showOnlyCurrent:!1}),R.configure({types:["blockContainer"]}),Kt.HardBreak,Zt.Text,P.Bold,Ut.Code,Yt.Italic,Xt.Strike,Qt.Underline,Jt.Link,qe,Ue,ke,me,Fe,Le,Ne.configure({domAttributes:o.domAttributes}),He.configure({domAttributes:o.domAttributes}),...Object.values(o.blockSchema).map(n=>n.node.configure({editor:o.editor,domAttributes:o.domAttributes})),Ct,$t.Dropcursor.configure({width:5,color:"#ddeeff"}),Ge];if(o.collaboration){if(e.push(le.default.configure({fragment:o.collaboration.fragment})),(t=o.collaboration.provider)!=null&&t.awareness){const n=r=>{const i=document.createElement("span");i.classList.add(I["collaboration-cursor__caret"]),i.setAttribute("style",`border-color: ${r.color}`);const s=document.createElement("span");s.classList.add(I["collaboration-cursor__label"]),s.setAttribute("style",`background-color: ${r.color}`),s.insertBefore(document.createTextNode(r.name),null);const l=document.createTextNode(""),a=document.createTextNode("");return i.insertBefore(l,null),i.insertBefore(s,null),i.insertBefore(a,null),i};e.push(de.default.configure({user:o.collaboration.user,render:o.collaboration.renderCursor||n,provider:o.collaboration.provider}))}}else e.push(Wt.History);return e};function j(o,e){let t,n;if(e.firstChild.descendants((r,i)=>t?!1:r.type.name!=="blockContainer"||r.attrs.id!==o?!0:(t=r,n=i+1,!1)),t===void 0||n===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:t,posBeforeNode:n}}function Et(o,e,t="before",n){const r=typeof e=="string"?e:e.id,i=[];for(const d of o)i.push(D(d,n.schema));let s=-1;const{node:l,posBeforeNode:a}=j(r,n.state.doc);if(t==="before"&&(s=a),t==="after"&&(s=a+l.nodeSize),t==="nested"){if(l.childCount<2){s=a+l.firstChild.nodeSize+1;const d=n.state.schema.nodes.blockGroup.create({},i);n.view.dispatch(n.state.tr.insert(s,d));return}s=a+l.firstChild.nodeSize+2}n.view.dispatch(n.state.tr.insert(s,i))}function $e(o,e,t){const n=typeof o=="string"?o:o.id,{posBeforeNode:r}=j(n,t.state.doc);t.commands.BNUpdateBlock(r+1,e)}function Bt(o,e){const t=new Set(o.map(r=>typeof r=="string"?r:r.id));let n=0;if(e.state.doc.descendants((r,i)=>{if(t.size===0)return!1;if(r.type.name!=="blockContainer"||!t.has(r.attrs.id))return!0;t.delete(r.attrs.id);const s=e.state.doc.nodeSize;e.commands.BNDeleteBlock(i-n+1);const l=e.state.doc.nodeSize;return n+=s-l,!1}),t.size>0){const r=[...t].join(`
|
|
6
|
+
`);throw Error("Blocks with the following IDs could not be found in the editor: "+r)}}function je(o,e,t){Et(e,o[0],"before",t),Bt(o,t)}function Ke(){const o=e=>{let t=e.children.length;for(let n=0;n<t;n++){const r=e.children[n];if(r.type==="element"&&(o(r),r.tagName==="u"))if(r.children.length>0){e.children.splice(n,1,...r.children);const i=r.children.length-1;t+=i,n+=i}else e.children.splice(n,1),t--,n--}};return o}function We(o){const e=new Set([...o.orderedListItemBlockTypes,...o.unorderedListItemBlockTypes]),t=n=>{let r=n.children.length,i;for(let s=0;s<r;s++){const a=n.children[s].children[0],d=a.children[0],c=a.children.length===2?a.children[1]:null,f=e.has(d.properties.dataContentType),p=f?o.orderedListItemBlockTypes.has(d.properties.dataContentType)?"ol":"ul":null;if(c!==null&&t(c),i&&i.tagName!==p){n.children.splice(s-i.children.length,i.children.length,i);const k=i.children.length-1;s-=k,r-=k,i=void 0}if(f){i||(i=Y.fromDom(document.createElement(p)));const k=Y.fromDom(document.createElement("li"));k.children.push(d.children[0]),c!==null&&k.children.push(...c.children),i.children.push(k)}else if(c!==null){n.children.splice(s+1,0,...c.children),n.children[s]=d.children[0];const k=c.children.length;s+=k,r+=k}else n.children[s]=d.children[0]}i&&n.children.splice(r-i.children.length,i.children.length,i)};return t}async function Tt(o,e){const t=document.createElement("div"),n=S.DOMSerializer.fromSchema(e);for(const i of o){const s=D(i,e),l=n.serializeNode(s);t.appendChild(l)}return(await U.unified().use(J.default,{fragment:!0}).use(We,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(X.default).process(t.innerHTML)).value}async function xt(o,e,t){const n=document.createElement("div");n.innerHTML=o.trim();const i=S.DOMParser.fromSchema(t).parse(n),s=[];for(let l=0;l<i.firstChild.childCount;l++)s.push(x(i.firstChild.child(l),e));return s}async function Ye(o,e){return(await U.unified().use(J.default,{fragment:!0}).use(Ke).use(ue.default).use(Z.default).use(fe.default).process(await Tt(o,e))).value}function Je(o,e){const t=e.value?e.value+`
|
|
7
|
+
`:"",n={};e.lang&&(n["data-language"]=e.lang);let r={type:"element",tagName:"code",properties:n,children:[{type:"text",value:t}]};return e.meta&&(r.data={meta:e.meta}),o.patch(e,r),r=o.applyData(e,r),r={type:"element",tagName:"pre",properties:{},children:[r]},o.patch(e,r),r}async function Xe(o,e,t){const n=await U.unified().use(pe.default).use(Z.default).use(he.default,{handlers:{...W.defaultHandlers,code:Je}}).use(X.default).process(o);return xt(n.value,e,t)}class At{constructor(e,t,n){u(this,"formattingToolbarState");u(this,"updateFormattingToolbar");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({view:e,state:t,from:n,to:r})=>{const{doc:i,selection:s}=t,{empty:l}=s,a=!i.textBetween(n,r).length&&m.isTextSelection(t.selection);return!(!e.hasFocus()||l||a)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragstartHandler",()=>{var e;(e=this.formattingToolbarState)!=null&&e.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",e=>{var n;if(this.preventHide){this.preventHide=!1;return}const t=this.pmView.dom.parentElement;e&&e.relatedTarget&&(t===e.relatedTarget||t.contains(e.relatedTarget))||(n=this.formattingToolbarState)!=null&&n.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(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");n(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 p,k;const{state:n,composing:r}=e,{doc:i,selection:s}=n,l=t&&t.doc.eq(i)&&t.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(r||l))return;this.prevWasEditable=this.editor.isEditable;const{ranges:a}=s,d=Math.min(...a.map(g=>g.$from.pos)),c=Math.max(...a.map(g=>g.$to.pos)),f=(p=this.shouldShow)==null?void 0:p.call(this,{view:e,state:n,from:d,to:c});if(this.editor.isEditable&&!this.preventShow&&(f||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((k=this.formattingToolbarState)!=null&&k.show&&!this.preventHide&&(!f||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:n}=t,r=Math.min(...n.map(s=>s.$from.pos)),i=Math.max(...n.map(s=>s.$to.pos));if(m.isNodeSelection(t)){const s=this.pmView.nodeDOM(r);if(s)return s.getBoundingClientRect()}return m.posToDOMRect(this.pmView,r,i)}}const _t=new b.PluginKey("FormattingToolbarPlugin");class Pt extends V{constructor(t){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:_t,view:n=>(this.view=new At(t,n,r=>{this.emit("update",r)}),this.view)})}onUpdate(t){return this.on("update",t)}}class Ze{constructor(e,t,n){u(this,"hyperlinkToolbarState");u(this,"updateHyperlinkToolbar");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredHyperlinkMark");u(this,"mouseHoveredHyperlinkMarkRange");u(this,"keyboardHoveredHyperlinkMark");u(this,"keyboardHoveredHyperlinkMarkRange");u(this,"hyperlinkMark");u(this,"hyperlinkMarkRange");u(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,n=this.pmView.posAtDOM(t,0)+1,r=this.pmView.state.doc.resolve(n),i=r.marks();for(const s of i)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=m.getMarkRange(r,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",e=>{var n;const t=this.pmView.dom.parentElement;this.hyperlinkMark&&e&&e.target&&!(t===e.target||t.contains(e.target))&&(n=this.hyperlinkToolbarState)!=null&&n.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});u(this,"scrollHandler",()=>{var e;this.hyperlinkMark!==void 0&&(e=this.hyperlinkToolbarState)!=null&&e.show&&(this.hyperlinkToolbarState.referencePos=m.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");n(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 r;const n=this.pmView.state.tr.insertText(t,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);n.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+t.length,this.pmView.state.schema.mark("link",{href:e})),this.pmView.dispatch(n),this.pmView.focus(),(r=this.hyperlinkToolbarState)!=null&&r.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 n=this.pmView.state.selection.$from.marks();for(const r of n)if(r.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=r,this.keyboardHoveredHyperlinkMarkRange=m.getMarkRange(this.pmView.state.selection.$from,r.type,r.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:m.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 It=new b.PluginKey("HyperlinkToolbarPlugin");class Nt extends V{constructor(t){super();u(this,"view");u(this,"plugin");u(this,"editHyperlink",(t,n)=>{this.view.editHyperlink(t,n)});u(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new b.Plugin({key:It,view:n=>(this.view=new Ze(t,n,r=>{this.emit("update",r)}),this.view)})}onUpdate(t){return this.on("update",t)}}class L extends b.Selection{constructor(t,n){super(t,n);u(this,"nodes");const r=t.node();this.nodes=[],t.doc.nodesBetween(t.pos,n.pos,(i,s,l)=>{if(l!==null&&l.eq(r))return this.nodes.push(i),!1})}static create(t,n,r=n){return new L(t.resolve(n),t.resolve(r))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(t){if(!(t instanceof L)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(t.nodes[n]))return!1;return!0}map(t,n){const r=n.mapResult(this.from),i=n.mapResult(this.to);return i.deleted?b.Selection.near(t.resolve(r.pos)):r.deleted?b.Selection.near(t.resolve(i.pos)):new L(t.resolve(r.pos),t.resolve(i.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Qe=ce.__serializeForClipboard;let A;function Ht(o,e){var r;if(!e.dom.isConnected)return;const t=e.posAtCoords(o);if(!t)return;let n=e.domAtPos(t.pos).node;if(n!==e.dom){for(;n&&n.parentNode&&n.parentNode!==e.dom&&!((r=n.hasAttribute)!=null&&r.call(n,"data-id"));)n=n.parentNode;if(n)return{node:n,id:n.getAttribute("data-id")}}}function tn(o,e){const t=Ht(o,e);if(t&&t.node.nodeType===1){const n=e.docView,r=n.nearestDesc(t.node,!0);return!r||r===n?null:r.posBefore}return null}function en(o,e){let t,n;const r=e.resolve(o.from).node().type.spec.group==="blockContent",i=e.resolve(o.to).node().type.spec.group==="blockContent",s=Math.min(o.$anchor.depth,o.$head.depth);if(r&&i){const l=o.$from.start(s-1),a=o.$to.end(s-1);t=e.resolve(l-1).pos,n=e.resolve(a+1).pos}else t=o.from,n=o.to;return{from:t,to:n}}function Lt(o,e,t=e){e===t&&(t+=o.state.doc.resolve(e+1).node().nodeSize);const n=o.domAtPos(e).node.cloneNode(!0),r=o.domAtPos(e).node,i=(c,f)=>Array.prototype.indexOf.call(c.children,f),s=i(r,o.domAtPos(e+1).node.parentElement),l=i(r,o.domAtPos(t-1).node.parentElement);for(let c=r.childElementCount-1;c>=0;c--)(c>l||c<s)&&n.removeChild(n.children[c]);Ot(),A=n;const d=o.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");A.className=A.className+" "+I.dragPreview+" "+d,document.body.appendChild(A)}function Ot(){A!==void 0&&(document.body.removeChild(A),A=void 0)}function nn(o,e){if(!o.dataTransfer)return;const t=e.dom.getBoundingClientRect(),n={left:t.left+t.width/2,top:o.clientY},r=tn(n,e);if(r!=null){const i=e.state.selection,s=e.state.doc,{from:l,to:a}=en(i,s),d=l<=r&&r<a,c=i.$anchor.node()!==i.$head.node()||i instanceof L;d&&c?(e.dispatch(e.state.tr.setSelection(L.create(s,l,a))),Lt(e,l,a)):(e.dispatch(e.state.tr.setSelection(b.NodeSelection.create(e.state.doc,r))),Lt(e,r));const f=e.state.selection.content(),{dom:p,text:k}=Qe(e,f);o.dataTransfer.clearData(),o.dataTransfer.setData("text/html",p.innerHTML),o.dataTransfer.setData("text/plain",k),o.dataTransfer.effectAllowed="move",o.dataTransfer.setDragImage(A,0,0),e.dragging={slice:f,move:!0}}}class Dt{constructor(e,t,n){u(this,"sideMenuState");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(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 n=new Event("drop",e),r=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=r.left+r.width/2,n.clientY=e.clientY,n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(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 n=new Event("dragover",e),r=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=r.left+r.width/2,n.clientY=e.clientY,n.dataTransfer=e.dataTransfer,n.preventDefault=()=>e.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onKeyDown",e=>{var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});u(this,"onMouseMove",e=>{var d,c,f,p,k;if(this.menuFrozen)return;const t=this.pmView.dom.firstChild.getBoundingClientRect(),n=this.pmView.dom.getBoundingClientRect(),r=e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom,i=this.pmView.dom.parentElement;if(r&&e&&e.target&&!(i===e.target||i.contains(e.target))){(d=this.sideMenuState)!=null&&d.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},l=Ht(s,this.pmView);if(!l||!this.editor.isEditable){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((f=this.sideMenuState)!=null&&f.show&&((p=this.hoveredBlock)!=null&&p.hasAttribute("data-id"))&&((k=this.hoveredBlock)==null?void 0:k.getAttribute("data-id"))===l.id)return;this.hoveredBlock=l.node;const a=l.node.firstChild;if(a&&this.editor.isEditable){const g=a.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)}});u(this,"onScroll",()=>{var e;if((e=this.sideMenuState)!=null&&e.show){const n=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:n.x,n.y,n.width,n.height),this.updateSideMenu(this.sideMenuState)}});this.editor=e,this.pmView=t,this.updateSideMenu=n,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("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("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(),n=this.pmView.posAtCoords({left:t.left+t.width/2,top:t.top+t.height/2});if(!n)return;const r=y(this.editor._tiptapEditor.state.doc,n.pos);if(r===void 0)return;const{contentNode:i,endPos:s}=r;if(i.textContent.length!==0){const a=s+1,d=a+2;this.editor._tiptapEditor.chain().BNCreateBlock(a).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(z,{activate:!0,type:"drag"}))}}const Rt=new b.PluginKey("SideMenuPlugin");class Vt extends V{constructor(t){super();u(this,"sideMenuView");u(this,"plugin");u(this,"addBlock",()=>this.sideMenuView.addBlock());u(this,"blockDragStart",t=>{this.sideMenuView.isDragging=!0,nn(t,this.editor.prosemirrorView)});u(this,"blockDragEnd",()=>Ot());u(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=t,this.plugin=new b.Plugin({key:Rt,view:n=>(this.sideMenuView=new Dt(t,n,r=>{this.emit("update",r)}),this.sideMenuView)})}onUpdate(t){return this.on("update",t)}}function O(o,e){const t=o.getTextCursorPosition().block;t.content.length===1&&t.content[0].type==="text"&&t.content[0].text==="/"||t.content.length===0?o.updateBlock(t,e):(o.insertBlocks([e],t,"after"),o.setTextCursorPosition(o.getTextCursorPosition().nextBlock))}const zt=(o=G)=>{var t,n,r;const e=[];return"heading"in o&&"level"in o.heading.propSchema&&((t=o.heading.propSchema.level.values)!=null&&t.includes("1")&&e.push({name:"Heading",aliases:["h","heading1","h1"],execute:i=>O(i,{type:"heading",props:{level:"1"}})}),(n=o.heading.propSchema.level.values)!=null&&n.includes("2")&&e.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:i=>O(i,{type:"heading",props:{level:"2"}})}),(r=o.heading.propSchema.level.values)!=null&&r.includes("3")&&e.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:i=>O(i,{type:"heading",props:{level:"3"}})})),"bulletListItem"in o&&e.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:i=>O(i,{type:"bulletListItem"})}),"numberedListItem"in o&&e.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:i=>O(i,{type:"numberedListItem"})}),"paragraph"in o&&e.push({name:"Paragraph",aliases:["p"],execute:i=>O(i,{type:"paragraph"})}),e},on={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class rn{constructor(e={}){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"ready",!1);u(this,"sideMenu");u(this,"formattingToolbar");u(this,"slashMenu");u(this,"hyperlinkToolbar");var l,a,d,c,f;this.options=e;const t={defaultStyles:!0,blockSchema:e.blockSchema||G,...e};this.sideMenu=new Vt(this),this.formattingToolbar=new Pt(this),this.slashMenu=new wt(this,t.slashMenuItems||zt(t.blockSchema)),this.hyperlinkToolbar=new Nt(this);const n=Mt({editor:this,domAttributes:t.domAttributes||{},blockSchema:t.blockSchema,collaboration:t.collaboration}),r=m.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin]});n.push(r),this.schema=t.blockSchema;const i=t.initialContent||(e.collaboration?void 0:[{type:"paragraph",id:R.options.generateID()}]),s={...on,...t._tiptapOptions,onCreate:()=>{var p;(p=t.onEditorReady)==null||p.call(t,this),this.ready=!0},onBeforeCreate(p){if(!i)return;const k=p.editor.schema,g=i.map(C=>D(C,k)),v=k.node("doc",void 0,k.node("blockGroup",void 0,g));p.editor.options.content=v.toJSON()},onUpdate:()=>{var p;this.ready&&((p=t.onEditorContentChange)==null||p.call(t,this))},onSelectionUpdate:()=>{var p;this.ready&&((p=t.onTextCursorPositionChange)==null||p.call(t,this))},editable:e.editable===void 0?!0:e.editable,extensions:t.enableBlockNoteExtensions===!1?(l=t._tiptapOptions)==null?void 0:l.extensions:[...((a=t._tiptapOptions)==null?void 0:a.extensions)||[],...n],editorProps:{attributes:{...(d=t.domAttributes)==null?void 0:d.editor,class:M(I.bnEditor,I.bnRoot,t.defaultStyles?I.defaultStyles:"",((f=(c=t.domAttributes)==null?void 0:c.editor)==null?void 0:f.class)||"")}}};t.parentElement&&(s.element=t.parentElement),this._tiptapEditor=new m.Editor(s)}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(x(t,this.schema,this.blockCache)),!1)),e}getBlock(e){const t=typeof e=="string"?e:e.id;let n;return this._tiptapEditor.state.doc.firstChild.descendants(r=>typeof n<"u"?!1:r.type.name!=="blockContainer"||r.attrs.id!==t?!0:(n=x(r,this.schema,this.blockCache),!1)),n}forEachBlock(e,t=!1){const n=this.topLevelBlocks.slice();t&&n.reverse();function r(i){for(const s of i){if(!e(s))return!1;const l=t?s.children.slice().reverse():s.children;if(!r(l))return!1}return!0}r(n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){const{node:e,depth:t,startPos:n,endPos:r}=y(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),i=this._tiptapEditor.state.doc.resolve(r).index(t-1),s=this._tiptapEditor.state.doc.resolve(r+1).node().childCount;let l;i>0&&(l=this._tiptapEditor.state.doc.resolve(n-2).node());let a;return i<s-1&&(a=this._tiptapEditor.state.doc.resolve(r+2).node()),{block:x(e,this.schema,this.blockCache),prevBlock:l===void 0?void 0:x(l,this.schema,this.blockCache),nextBlock:a===void 0?void 0:x(a,this.schema,this.blockCache)}}setTextCursorPosition(e,t="start"){const n=typeof e=="string"?e:e.id,{posBeforeNode:r}=j(n,this._tiptapEditor.state.doc),{startPos:i,contentNode:s}=y(this._tiptapEditor.state.doc,r+2);t==="start"?this._tiptapEditor.commands.setTextSelection(i+1):this._tiptapEditor.commands.setTextSelection(i+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to)return;const e=[];return this._tiptapEditor.state.doc.descendants((t,n)=>t.type.spec.group!=="blockContent"||n+t.nodeSize<this._tiptapEditor.state.selection.from||n>this._tiptapEditor.state.selection.to?!0:(e.push(x(this._tiptapEditor.state.doc.resolve(n).node(),this.schema,this.blockCache)),!1)),{blocks:e}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(e){this._tiptapEditor.setEditable(e)}insertBlocks(e,t,n="before"){Et(e,t,n,this._tiptapEditor)}updateBlock(e,t){$e(e,t,this._tiptapEditor)}removeBlocks(e){Bt(e,this._tiptapEditor)}replaceBlocks(e,t){je(e,t,this._tiptapEditor)}getActiveStyles(){const e={},t=this._tiptapEditor.state.selection.$to.marks(),n=new Set(["bold","italic","underline","strike","code"]),r=new Set(["textColor","backgroundColor"]);for(const i of t)n.has(i.type.name)?e[i.type.name]=!0:r.has(i.type.name)&&(e[i.type.name]=i.attrs.color);return e}addStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.setMark(r):n.has(r)&&this._tiptapEditor.commands.setMark(r,{color:i})}removeStyles(e){this._tiptapEditor.view.focus();for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){const t=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[r,i]of Object.entries(e))t.has(r)?this._tiptapEditor.commands.toggleMark(r):n.has(r)&&this._tiptapEditor.commands.toggleMark(r,{color:i})}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:n,to:r}=this._tiptapEditor.state.selection;t||(t=this._tiptapEditor.state.doc.textBetween(n,r));const i=this._tiptapEditor.schema.mark("link",{href:e});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(t,n,r).addMark(n,n+t.length,i))}canNestBlock(){const{startPos:e,depth:t}=y(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}=y(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return e>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(e){return Tt(e,this._tiptapEditor.schema)}async HTMLToBlocks(e){return xt(e,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(e){return Ye(e,this._tiptapEditor.schema)}async markdownToBlocks(e){return Xe(e,this.schema,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)}}h.BlockNoteEditor=rn,h.CustomBlockSerializerExtension=Ct,h.FormattingToolbarProsemirrorPlugin=Pt,h.FormattingToolbarView=At,h.HyperlinkToolbarProsemirrorPlugin=Nt,h.SideMenuProsemirrorPlugin=Vt,h.SideMenuView=Dt,h.SlashMenuProsemirrorPlugin=wt,h.UnreachableCaseError=ct,h.blockStyles=ge,h.camelToDataKebab=q,h.createBlockSpec=ye,h.createTipTapBlock=N,h.defaultBlockSchema=G,h.defaultProps=H,h.formatKeyboardShortcut=be,h.formattingToolbarPluginKey=_t,h.getBlockNoteExtensions=Mt,h.getDefaultSlashMenuItems=zt,h.hyperlinkToolbarPluginKey=It,h.isAppleOS=dt,h.mergeCSSClasses=M,h.parse=pt,h.propsToAttributes=ut,h.render=ht,h.setupSuggestionsMenu=St,h.sideMenuPluginKey=Rt,h.slashMenuPluginKey=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
7
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|