@blocknote/core 0.2.2-alpha.0 → 0.2.3
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 +696 -691
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +1 -1
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +6 -4
- package/src/BlockNoteExtensions.ts +1 -10
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +22 -26
- package/src/extensions/Blocks/apiTypes.ts +48 -0
- package/src/extensions/Blocks/helpers/findBlock.ts +3 -1
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +1 -1
- package/src/extensions/Blocks/index.ts +10 -8
- package/src/extensions/Blocks/nodes/Block.module.css +31 -29
- package/src/extensions/Blocks/{BlockAttributes.ts → nodes/BlockAttributes.ts} +0 -0
- package/src/extensions/Blocks/nodes/{Block.ts → BlockContainer.ts} +75 -94
- package/src/extensions/Blocks/nodes/{BlockTypes/HeadingBlock/HeadingContent.ts → BlockContent/HeadingBlockContent/HeadingBlockContent.ts} +16 -24
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +76 -0
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/ListItemKeyboardShortcuts.ts +47 -0
- package/src/extensions/Blocks/nodes/{BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.ts → BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts} +10 -14
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +95 -0
- package/src/extensions/Blocks/nodes/{BlockTypes/TextBlock/TextContent.ts → BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts} +3 -8
- package/src/extensions/Blocks/nodes/BlockGroup.ts +4 -4
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +1 -1
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +7 -7
- package/src/extensions/{Blocks → DraggableBlocks}/MultipleNodeSelection.ts +0 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +4 -7
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +17 -9
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +1 -1
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +3 -1
- package/src/extensions/SlashMenu/defaultCommands.tsx +22 -23
- package/src/extensions/TrailingNode/TrailingNodeExtension.ts +4 -4
- package/src/extensions/UniqueID/UniqueID.ts +6 -0
- package/src/index.ts +2 -1
- package/src/shared/EditorElement.ts +12 -6
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +2 -2
- package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +1 -1
- package/types/src/BlockNoteEditor.d.ts +1 -1
- package/types/src/BlockNoteExtensions.d.ts +1 -3
- package/types/src/extensions/Blocks/apiTypes.d.ts +16 -0
- package/types/src/extensions/Blocks/helpers/getBlockInfoFromPos.d.ts +1 -1
- package/types/src/extensions/Blocks/nodes/BlockAttributes.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +21 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/BlockContentTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContentTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContentTypes.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContentTypes.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContentTypes.d.ts +2 -0
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +5 -5
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +1 -1
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +2 -2
- package/types/src/extensions/DraggableBlocks/MultipleNodeSelection.d.ts +24 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +8 -8
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +1 -1
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +5 -5
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +2 -2
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +1 -1
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +1 -1
- package/types/src/index.d.ts +2 -1
- package/types/src/shared/EditorElement.d.ts +6 -2
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +3 -3
- package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +5 -5
- package/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.ts +0 -177
- package/src/extensions/Paragraph/FixedParagraph.ts +0 -12
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(m,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@tiptap/core"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-model"),require("prosemirror-state"),require("prosemirror-view"),require("lodash"),require("@tiptap/extension-link"),require("@tiptap/extension-paragraph"),require("uuid")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-model","prosemirror-state","prosemirror-view","lodash","@tiptap/extension-link","@tiptap/extension-paragraph","uuid"],u):(m=typeof globalThis<"u"?globalThis:m||self,u(m.blocknote={},m.core,m.Bold,m.Code,m.DropCursor,m.GapCursor,m.HardBreak,m.extensionHistory,m.Italic,m.Strike,m.Text,m.Underline,m.prosemirrorModel,m.prosemirrorState,m.pv,m.lodash,m.extensionLink,m.Paragraph,m.uuid))})(this,function(m,u,P,W,V,Y,J,Q,X,Z,ee,te,A,k,B,F,U,ne,oe){"use strict";var dt=Object.defineProperty;var lt=(m,u,P)=>u in m?dt(m,u,{enumerable:!0,configurable:!0,writable:!0,value:P}):m[u]=P;var p=(m,u,P)=>(lt(m,typeof u!="symbol"?u+"":u,P),P);const C=t=>t&&typeof t=="object"&&"default"in t?t:{default:t};function re(t){if(t&&t.__esModule)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const ie=C(P),se=C(W),ae=C(V),de=C(Y),le=C(J),ce=C(X),ue=C(Z),he=C(ee),pe=C(te),fe=re(B),me=C(ne),q={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"};function v(t,e){if(e<=0||e>t.nodeSize)return;const n=t.resolve(e),o=n.depth;let r=n.node(o),a=o;for(;a>=0;){if(a===0)return;if(r.type.name==="block")break;a-=1,r=n.node(a)}const d=r.attrs.id,i=r.firstChild,s=i.type,c=r.childCount===2?r.lastChild.childCount:0,f=n.start(a),h=n.end(a);return{id:d,node:r,contentNode:i,contentType:s,numChildBlocks:c,startPos:f,endPos:h,depth:a}}const z=new k.PluginKey("previous-blocks"),ge={listItemType:"list-item-type",listItemIndex:"list-item-index",headingLevel:"heading-level",type:"type",depth:"depth","depth-change":"depth-change"},ke=()=>new k.Plugin({key:z,view(t){return{update:async(e,n)=>{var o;(o=this.key)!=null&&o.getState(e.state).needsUpdate&&setTimeout(()=>{e.dispatch(e.state.tr.setMeta(z,{clearUpdate:!0}))},0)}}},state:{init(){return{prevBlockAttrs:{},needsUpdate:!1}},apply(t,e,n,o){if(e.needsUpdate=!1,e.prevBlockAttrs={},!t.docChanged||n.doc.eq(o.doc))return e;const r=u.combineTransactionSteps(n.doc,[t]);return u.getChangedRanges(r).forEach(()=>{const d=u.findChildren(n.doc,c=>c.attrs.id),i=new Map(d.map(c=>[c.node.attrs.id,c])),s=u.findChildren(o.doc,c=>c.attrs.id);for(let c of s){const f=i.get(c.node.attrs.id),h=f==null?void 0:f.node.firstChild,l=c.node.firstChild;if(f&&h&&l){const g={listItemType:l.attrs.listItemType,listItemIndex:l.attrs.listItemIndex,headingLevel:l.attrs.headingLevel,type:l.type.name,depth:o.doc.resolve(c.pos).depth},y={listItemType:h.attrs.listItemType,listItemIndex:h.attrs.listItemIndex,headingLevel:h.attrs.headingLevel,type:h.type.name,depth:n.doc.resolve(f.pos).depth},I=y.listItemIndex===null&&g.listItemIndex!==null,T=y.listItemIndex!==null&&g.listItemIndex!==null&&y.listItemIndex===g.listItemIndex,b=y.listItemType==="ordered"&&g.listItemType==="ordered"?I||T:!0;JSON.stringify(y)!==JSON.stringify(g)&&b&&(y["depth-change"]=y.depth-g.depth,e.prevBlockAttrs[c.node.attrs.id]=y,console.log("id:",c.node.attrs.id,"previousBlockTypePlugin changes detected, oldAttrs",y,"new",g),e.needsUpdate=!0)}}}),e}},props:{decorations(t){const e=this.getState(t);if(!e.needsUpdate)return;const n=[];return t.doc.descendants((o,r)=>{if(!o.attrs.id)return;const a=e.prevBlockAttrs[o.attrs.id];if(!a)return;const d={};for(let[s,c]of Object.entries(a))d["data-prev-"+ge[s]]=c||"none";console.log("previousBlockTypePlugin committing decorations",d);const i=B.Decoration.node(r,r+o.nodeSize,{...d});n.push(i)}),B.DecorationSet.create(t.doc,n)}}}),M={blockOuter:"_blockOuter_r256c_5",block:"_block_r256c_5",blockContent:"_blockContent_r256c_25",blockGroup:"_blockGroup_r256c_53",isEmpty:"_isEmpty_r256c_238",isFilter:"_isFilter_r256c_239",hasAnchor:"_hasAnchor_r256c_252"},ye=u.Node.create({name:"block",group:"block",content:"blockContent blockGroup?",priority:50,defining:!0,addOptions(){return{HTMLAttributes:{}}},addAttributes(){return{blockColor:{default:void 0},blockStyle:{default:void 0}}},parseHTML(){return[{tag:"div",getAttrs:t=>{if(typeof t=="string")return!1;const e={};for(let[n,o]of Object.entries(q))t.getAttribute(o)&&(e[n]=t.getAttribute(o));return t.getAttribute("data-node-type")==="block"?e:!1}}]},renderHTML({HTMLAttributes:t}){const e={};for(let[n,o]of Object.entries(q))t[n]!==void 0&&(e[o]=t[n]);return["div",u.mergeAttributes(e,{class:M.blockOuter,"data-node-type":"block-outer"}),["div",u.mergeAttributes(e,{class:M.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:t=>({state:e,dispatch:n})=>{const o=e.schema.nodes.block.createAndFill();return n&&e.tr.insert(t,o),!0},BNDeleteBlock:t=>({state:e,view:n,dispatch:o})=>{const r=v(e.doc,t);if(r===void 0)return!1;const{startPos:a,endPos:d}=r;return o&&(e.tr.deleteRange(a,d),e.tr.setSelection(new k.TextSelection(e.doc.resolve(a+1))),n.focus()),!0},BNMergeBlocks:t=>({state:e,dispatch:n})=>{const o=e.doc.resolve(t+1).node().type.name==="block",r=e.doc.resolve(t-1).node().type.name==="block";if(!o||!r)return!1;const a=v(e.doc,t+1),{node:d,contentNode:i,startPos:s,endPos:c,depth:f}=a;if(d.childCount===2){const g=e.doc.resolve(s+i.nodeSize+1),y=e.doc.resolve(c-1),I=g.blockRange(y);n&&e.tr.lift(I,f-1)}let h=t-1,l=v(e.doc,h);for(;l.numChildBlocks>0;)if(h--,l=v(e.doc,h),l===void 0)return!1;return n&&(e.tr.deleteRange(s,s+i.nodeSize),e.tr.insertText(i.textContent,h-1),e.tr.setSelection(new k.TextSelection(e.doc.resolve(h-1)))),!0},BNSplitBlock:(t,e)=>({state:n,dispatch:o})=>{const r=v(n.doc,t);if(r===void 0)return!1;const{contentNode:a,contentType:d,startPos:i,endPos:s,depth:c}=r,f=s+1,h=n.doc.textBetween(t,s),l=n.schema.nodes.block.createAndFill(),g=f+2;o&&(n.tr.insert(f,l),n.tr.insertText(h,g),e&&n.tr.setBlockType(g,g,n.schema.node(d).type,a.attrs));const y=n.doc.content.cut(i,t);return o&&n.tr.replace(i,s,new A.Slice(y,c,c)),!0},BNSetContentType:(t,e)=>({state:n,dispatch:o})=>{const r=v(n.doc,t);if(r===void 0)return!1;const{startPos:a,contentNode:d}=r;return o&&n.tr.setBlockType(a+1,a+d.nodeSize+1,n.schema.node(e.name).type,e.attrs),!0},BNCreateBlockOrSetContentType:(t,e)=>({state:n,chain:o})=>{const r=v(n.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,endPos:i}=r;if(a.textContent.length===0){const s=d+1;return o().BNSetContentType(t,e).setTextSelection(s).run()}else{const s=i+1,c=s+1;return o().BNCreateBlock(s).BNSetContentType(c,e).setTextSelection(c).run()}}}},addProseMirrorPlugins(){return[ke()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:o})=>{const{contentType:r}=v(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,d=r.name==="textContent";return a&&!d?n.BNSetContentType(o.selection.from,{name:"textContent"}):!1}),()=>n.command(({state:o})=>o.selection.$anchor.parentOffset===0?n.liftListItem("block"):!1),()=>n.command(({state:o})=>{const{depth:r,startPos:a}=v(o.doc,o.selection.from),d=o.selection.$anchor.parentOffset===0,i=o.selection.anchor===o.selection.head,s=a===2,c=a-1;return!s&&d&&i&&r===2?n.BNMergeBlocks(c):!1})]),Enter:()=>this.editor.commands.first(({commands:n})=>[()=>n.command(({state:o})=>{const{node:r,depth:a}=v(o.doc,o.selection.from),d=o.selection.$anchor.parentOffset===0,i=o.selection.anchor===o.selection.head,s=r.textContent.length===0,c=a>2;return d&&i&&s&&c?n.liftListItem("block"):!1}),()=>n.command(({state:o,chain:r})=>{const{node:a,endPos:d}=v(o.doc,o.selection.from),i=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,c=a.textContent.length===0;if(i&&s&&c){const f=d+1,h=f+2;return r().BNCreateBlock(f).setTextSelection(h).run(),!0}return!1}),()=>n.command(({state:o,chain:r})=>{const{node:a}=v(o.doc,o.selection.from);return a.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(o.selection.from,!1).run(),!0)})]),Tab:()=>this.editor.commands.sinkListItem("block"),"Shift-Tab":()=>this.editor.commands.liftListItem("block"),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2),"Mod-Alt-1":()=>this.editor.commands.BNSetContentType(this.editor.state.selection.anchor,{name:"headingContent",attrs:{headingLevel:"1"}}),"Mod-Alt-2":()=>this.editor.commands.BNSetContentType(this.editor.state.selection.anchor,{name:"headingContent",attrs:{headingLevel:"2"}}),"Mod-Alt-3":()=>this.editor.commands.BNSetContentType(this.editor.state.selection.anchor,{name:"headingContent",attrs:{headingLevel:"3"}}),"Mod-Shift-7":()=>this.editor.commands.BNSetContentType(this.editor.state.selection.anchor,{name:"listItemContent",attrs:{listItemType:"unordered"}}),"Mod-Shift-8":()=>this.editor.commands.BNSetContentType(this.editor.state.selection.anchor,{name:"listItemContent",attrs:{listItemType:"ordered"}})}}}),be=u.Node.create({name:"blockGroup",addOptions(){return{HTMLAttributes:{}}},content:"block+",parseHTML(){return[{tag:"div",getAttrs:t=>typeof t=="string"?!1:t.getAttribute("data-node-type")==="block-group"?null:!1}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(this.options.HTMLAttributes,t,{class:M.blockGroup,"data-node-type":"block-group"}),0]}}),ve=u.Node.create({name:"textContent",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"block"}]},renderHTML(){return["div",{class:M.blockContent,"data-content-type":this.name},["p",0]]}}),Ie=u.Node.create({name:"headingContent",group:"blockContent",content:"inline*",addAttributes(){return{headingLevel:{default:"1",parseHTML:t=>t.getAttribute("data-heading-level"),renderHTML:t=>({"data-heading-level":t.headingLevel})}}},addInputRules(){return[...["1","2","3"].map(t=>new u.InputRule({find:new RegExp(`^(#{${parseInt(t)}})\\s$`),handler:({state:e,chain:n,range:o})=>{n().BNSetContentType(e.selection.from,{name:"headingContent",attrs:{headingLevel:t}}).deleteRange({from:o.from,to:o.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{headingLevel:"1"},node:"block"},{tag:"h2",attrs:{headingLevel:"2"},node:"block"},{tag:"h3",attrs:{headingLevel:"3"},node:"block"}]},renderHTML({node:t,HTMLAttributes:e}){return console.log(t.attrs),["div",u.mergeAttributes(e,{class:M.blockContent,"data-content-type":this.name}),["h"+t.attrs.headingLevel,0]]}}),Te=new k.PluginKey("ordered-list-item-index"),Ce=()=>new k.Plugin({key:Te,appendTransaction:(t,e,n)=>{const o=n.tr;o.setMeta("orderedListIndexing",!0);let r=!1;return n.doc.descendants((a,d)=>{if(a.type.name==="block"&&a.firstChild.type.name==="listItemContent"&&a.firstChild.attrs.listItemType==="ordered"){let i="1";const s=d===1,c=v(o.doc,d+1);if(c===void 0)return;if(!s){const l=v(o.doc,d-2);if(l===void 0)return;if(!(c.depth!==l.depth)){const y=l.contentNode;if(l.contentType.name==="listItemContent"&&y.attrs.listItemType==="ordered"){const b=y.attrs.listItemIndex;i=(parseInt(b)+1).toString()}}}c.contentNode.attrs.listItemIndex!==i&&(r=!0,o.setNodeMarkup(d+1,void 0,{listItemType:"ordered",listItemIndex:i}))}}),r?o:null}}),Be=u.Node.create({name:"listItemContent",group:"blockContent",content:"inline*",addAttributes(){return{listItemType:{default:"unordered",parseHTML:t=>t.getAttribute("data-list-item-type"),renderHTML:t=>({"data-list-item-type":t.listItemType})},listItemIndex:{default:null,parseHTML:t=>t.getAttribute("data-list-item-index"),renderHTML:t=>({"data-list-item-index":t.listItemIndex})}}},addInputRules(){return[new u.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:t,chain:e,range:n})=>{e().BNSetContentType(t.selection.from,{name:"listItemContent",attrs:{listItemType:"unordered"}}).deleteRange({from:n.from,to:n.to})}}),new u.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:t,chain:e,range:n})=>{e().BNSetContentType(t.selection.from,{name:"listItemContent",attrs:{listItemType:"ordered"}}).deleteRange({from:n.from,to:n.to})}})]},addKeyboardShortcuts(){return{Enter:()=>{const{node:e,contentType:n}=v(this.editor.state.doc,this.editor.state.selection.from),o=this.editor.state.selection.anchor===this.editor.state.selection.head;return n.name!=="listItemContent"||!o?!1:this.editor.commands.first(({state:r,chain:a,commands:d})=>[()=>d.command(()=>e.textContent.length===0?d.BNSetContentType(r.selection.from,{name:"textContent"}):!1),()=>d.command(()=>e.textContent.length>0?(a().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])}}},addProseMirrorPlugins(){return[Ce()]},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="listItemContent"?{listItemType:e.getAttribute("data-list-item-type")}:e.tagName==="UL"?{listItemType:"unordered"}:e.tagName==="OL"?{listItemType:"ordered"}:!1},node:"block"}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:M.blockContent,"data-content-type":this.name}),["li",0]]}}),Me=[ve,Ie,Be,ye,be,u.Node.create({name:"doc",topNode:!0,content:"blockGroup"})];class xe{constructor({editor:e,formattingToolbarFactory:n,view:o,shouldShow:r}){p(this,"editor");p(this,"view");p(this,"formattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"toolbarIsOpen",!1);p(this,"shouldShow",({view:e,state:n,from:o,to:r})=>{const{doc:a,selection:d}=n,{empty:i}=d,s=!a.textBetween(o,r).length&&u.isTextSelection(n.selection);return!(!e.hasFocus()||i||s)});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.editor.view))});p(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.editor.view))});p(this,"blurHandler",({event:e})=>{var n,o;if(this.preventHide){this.preventHide=!1;return}(e==null?void 0:e.relatedTarget)&&((o=(n=this.formattingToolbar.element)==null?void 0:n.parentNode)==null?void 0:o.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});this.editor=e,this.view=o,this.formattingToolbar=n(this.getStaticParams()),r&&(this.shouldShow=r),this.view.dom.addEventListener("mousedown",this.viewMousedownHandler),this.view.dom.addEventListener("mouseup",this.viewMouseupHandler),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler)}update(e,n){var l;const{state:o,composing:r}=e,{doc:a,selection:d}=o,i=n&&n.doc.eq(a)&&n.selection.eq(d);if(r||i)return;const{ranges:s}=d,c=Math.min(...s.map(g=>g.$from.pos)),f=Math.max(...s.map(g=>g.$to.pos)),h=(l=this.shouldShow)==null?void 0:l.call(this,{editor:this.editor,view:e,state:o,oldState:n,from:c,to:f});if(!this.toolbarIsOpen&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!0),this.toolbarIsOpen=!0,this.formattingToolbar.element.addEventListener("mousedown",g=>g.preventDefault());return}if(this.toolbarIsOpen&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!h||this.preventShow)){this.formattingToolbar.hide(),this.toolbarIsOpen=!1,this.formattingToolbar.element.removeEventListener("mousedown",g=>g.preventDefault());return}}destroy(){this.view.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.view.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler)}getSelectionBoundingBox(){const{state:e}=this.editor.view,{selection:n}=e,{ranges:o}=n,r=Math.min(...o.map(d=>d.$from.pos)),a=Math.max(...o.map(d=>d.$to.pos));if(u.isNodeSelection(n)){const d=this.editor.view.nodeDOM(r);if(d)return d.getBoundingClientRect()}return u.posToDOMRect(this.editor.view,r,a)}getStaticParams(){return{toggleBold:()=>{this.editor.view.focus(),this.editor.commands.toggleBold()},toggleItalic:()=>{this.editor.view.focus(),this.editor.commands.toggleItalic()},toggleUnderline:()=>{this.editor.view.focus(),this.editor.commands.toggleUnderline()},toggleStrike:()=>{this.editor.view.focus(),this.editor.commands.toggleStrike()},setHyperlink:(e,n)=>{if(e==="")return;let{from:o,to:r}=this.editor.state.selection;n||(n=this.editor.state.doc.textBetween(o,r));const a=this.editor.schema.mark("link",{href:e});this.editor.view.dispatch(this.editor.view.state.tr.insertText(n,o,r).addMark(o,o+n.length,a)),this.editor.view.focus()},setBlockType:e=>{this.editor.view.focus(),this.editor.commands.BNSetContentType(this.editor.state.selection.from,e)}}}getDynamicParams(){return{boldIsActive:this.editor.isActive("bold"),italicIsActive:this.editor.isActive("italic"),underlineIsActive:this.editor.isActive("underline"),strikeIsActive:this.editor.isActive("strike"),hyperlinkIsActive:this.editor.isActive("link"),activeHyperlinkUrl:this.editor.getAttributes("link").href?this.editor.getAttributes("link").href:"",activeHyperlinkText:this.editor.state.doc.textBetween(this.editor.state.selection.from,this.editor.state.selection.to),activeBlockType:{name:this.editor.state.selection.$from.node().type.name,attrs:this.editor.state.selection.$from.node().attrs},selectionBoundingBox:this.getSelectionBoundingBox()}}}const we=t=>new k.Plugin({key:new k.PluginKey("FormattingToolbarPlugin"),view:e=>new xe({view:e,...t})}),Pe=u.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory)throw new Error("UI Element factory not defined for FormattingToolbarExtension");return[we({editor:this.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new k.PluginKey("FormattingToolbarPlugin")})]}});class H extends k.Selection{constructor(n,o){super(n,o);p(this,"nodes");const r=n.node();this.nodes=[],n.doc.nodesBetween(n.pos,o.pos,(a,d,i)=>{if(i!==null&&i.eq(r))return this.nodes.push(a),!1})}static create(n,o,r=o){return new H(n.resolve(o),n.resolve(r))}content(){return new A.Slice(A.Fragment.from(this.nodes),0,0)}eq(n){if(!(n instanceof H)||this.nodes.length!==n.nodes.length||this.from!==n.from||this.to!==n.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(n.nodes[o]))return!1;return!0}map(n,o){let r=o.mapResult(this.from),a=o.mapResult(this.to);return a.deleted?k.Selection.near(n.resolve(r.pos)):r.deleted?k.Selection.near(n.resolve(a.pos)):new H(n.resolve(r.pos),n.resolve(a.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Se=u.findParentNode(t=>t.type.name==="block");function Ee(t,e){if(!e.empty)return;const n=e.$anchor.nodeBefore;if(!n||!n.text)return;const o=new RegExp(`${F.escapeRegExp(t)}([^${F.escapeRegExp(t)}]*)$`),r=n.text.match(o);if(!!r)return{query:r[1],range:{from:e.$anchor.pos-r[1].length-t.length,to:e.$anchor.pos}}}class Ne{constructor({editor:e,pluginKey:n,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");this.editor=e,this.pluginKey=n,this.pluginState={active:!1,range:null,query:null,notFoundCount:0,items:[],selectedItemIndex:0,type:"slash",decorationId:null},this.itemCallback=a=>o({item:a,editor:e,range:this.pluginState.range}),this.suggestionsMenu=r(this.getStaticParams())}update(e,n){const o=this.pluginKey.getState(n),r=this.pluginKey.getState(e.state),a=!o.active&&r.active,d=o.active&&!r.active,i=o.active&&r.active;!a&&!i&&!d||(this.pluginState=d?o:r,d&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",s=>s.preventDefault())),i&&this.suggestionsMenu.render(this.getDynamicParams(),!1),a&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",s=>s.preventDefault())))}getStaticParams(){return{itemCallback:e=>this.itemCallback(e)}}getDynamicParams(){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);return{items:this.pluginState.items,selectedItemIndex:this.pluginState.selectedItemIndex,queryStartBoundingBox:e.getBoundingClientRect()}}}function Ae({pluginKey:t,editor:e,char:n,suggestionsMenuFactory:o,onSelectItem:r=()=>{},items:a=()=>[]}){if(n.length!==1)throw new Error("'char' should be a single character");const d=i=>{i.dispatch(i.state.tr.setMeta(t,{deactivate:!0}))};return new k.Plugin({key:t,view:i=>new Ne({editor:e,pluginKey:t,onSelectItem:s=>{d(i),r(s)},suggestionsMenuFactory:o}),state:{init(){return{active:!1,range:null,query:null,notFoundCount:0,items:[],selectedItemIndex:0,type:"slash",decorationId:null}},apply(i,s,c,f){var g,y,I,T;const{selection:h}=i,l={...s};if(i.getMeta("orderedListIndexing")!==void 0)return l;if(((g=i.getMeta(t))==null?void 0:g.selectedItemIndexChanged)!==void 0){let b=i.getMeta(t).selectedItemIndexChanged;return b<0&&(b=s.items.length-1),b>=s.items.length&&(b=0),l.selectedItemIndex=b,l}if(h.from===h.to&&!((y=i.getMeta(t))!=null&&y.deactivate)&&!i.getMeta("focus")&&!i.getMeta("blur")&&!i.getMeta("pointer")){if(s.active&&h.from<=s.range.from)l.active=!1;else if((I=i.getMeta(t))!=null&&I.activate){const b=`id_${Math.floor(Math.random()*4294967295)}`;l.decorationId=b,l.range={from:h.from-1,to:h.to},l.query="",l.active=!0,l.type=(T=i.getMeta(t))==null?void 0:T.type,l.selectedItemIndex=0}else if(s.active){const b=Ee(s.type==="slash"?n:"",f.selection);if(!b)throw new Error("active but no match (suggestions)");l.range=b.range,l.active=!0,l.decorationId=s.decorationId,l.query=b.query,l.selectedItemIndex=0}}else l.active=!1;return l.active&&(l.items=a(l.query),l.items.length?l.notFoundCount=0:l.range.to>s.range.to?l.notFoundCount=s.notFoundCount+1:l.notFoundCount=s.notFoundCount,l.notFoundCount>3&&(l.active=!1)),l.active||(l.decorationId=null,l.range=null,l.query=null,l.notFoundCount=0,l.items=[]),l}},props:{handleKeyDown(i,s){const{active:c}=this.getState(i.state);if(c){const{items:f,range:h,selectedItemIndex:l}=t.getState(i.state);if(s.key==="ArrowUp")return i.dispatch(i.state.tr.setMeta(t,{selectedItemIndexChanged:l-1})),!0;if(s.key==="ArrowDown")return i.dispatch(i.state.tr.setMeta(t,{selectedItemIndexChanged:l+1})),!0;if(s.key==="Enter")return d(i),r({item:f[l],editor:e,range:h}),!0;if(s.key==="Escape")return d(i),!0}else if(s.key===n)return i.dispatch(i.state.tr.insertText(n).scrollIntoView().setMeta(t,{activate:!0,type:"slash"})),!0;return!1},handleClick(i){d(i)},decorations(i){const{active:s,range:c,decorationId:f,type:h}=this.getState(i);if(!s)return null;if(h==="drag"){const l=Se(i.selection);if(l)return B.DecorationSet.create(i.doc,[B.Decoration.node(l.pos,l.pos+l.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":f})])}return B.DecorationSet.create(i.doc,[B.Decoration.inline(c.from,c.to,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":f})])}}})}const He=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function N(t){return He()?t.replace("Mod","\u2318"):t.replace("Mod","Ctrl")}var x=(t=>(t.HEADINGS="Headings",t.BASIC_BLOCKS="Basic Blocks",t.CODE="Code Blocks",t.INLINE="Inline",t.EMBED="Embed",t.PLUGIN="Plugin",t))(x||{});class S{constructor(e,n,o,r=[],a,d){p(this,"groupName");this.name=e,this.group=n,this.execute=o,this.aliases=r,this.hint=a,this.shortcut=d,this.groupName=n}match(e){return this.name.toLowerCase().startsWith(e.toLowerCase())||this.aliases.filter(n=>n.toLowerCase().startsWith(e.toLowerCase())).length!==0}}const Le={heading:new S("Heading",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateBlockOrSetContentType(e.from,{name:"headingContent",attrs:{headingLevel:"1"}}).run(),["h","heading1","h1"],"Used for a top-level heading",N("Mod-Alt-1")),heading2:new S("Heading 2",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateBlockOrSetContentType(e.from,{name:"headingContent",attrs:{headingLevel:"2"}}).run(),["h2","heading2","subheading"],"Used for key sections",N("Mod-Alt-2")),heading3:new S("Heading 3",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateBlockOrSetContentType(e.from,{name:"headingContent",attrs:{headingLevel:"3"}}).run(),["h3","heading3","subheading"],"Used for subsections and group headings",N("Mod-Alt-3")),numberedList:new S("Numbered List",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateBlockOrSetContentType(e.from,{name:"listItemContent",attrs:{listItemType:"ordered"}}).run(),["li","list","numberedlist","numbered list"],"Used to display a numbered list",N("Mod-Shift-7")),bulletList:new S("Bullet List",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateBlockOrSetContentType(e.from,{name:"listItemContent",attrs:{listItemType:"unordered"}}).run(),["ul","list","bulletlist","bullet list"],"Used to display an unordered list",N("Mod-Shift-8")),paragraph:new S("Paragraph",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateBlockOrSetContentType(e.from,{name:"textContent"}).run(),["p"],"Used for the body of your document",N("Mod-Alt-0"))},_=new k.PluginKey("suggestions-slash-commands"),_e=u.Extension.create({name:"slash-command",addOptions(){return{commands:Le,slashMenuFactory:void 0}},addProseMirrorPlugins(){if(!this.options.slashMenuFactory)throw new Error("UI Element factory not defined for SlashMenuExtension");return[Ae({pluginKey:_,editor:this.editor,char:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:t=>{const e=[];for(const n in this.options.commands)e.push(this.options.commands[n]);return e.filter(n=>n.match(t))},onSelectItem:({item:t,editor:e,range:n})=>{t.execute(e,n)}})]}}),O={bnEditor:"_bnEditor_xixap_3",bnRoot:"_bnRoot_xixap_13",dragPreview:"_dragPreview_xixap_27"},Oe=fe.__serializeForClipboard;let D,E;function De(){if(!D){const t=document.querySelector(".ProseMirror > [class*='blockGroup']");t&&(D=Fe(t).left)}return D}function Re(t){let e={left:t.left+document.body.scrollLeft,top:t.top+document.body.scrollTop,width:t.width,height:t.height,bottom:0,right:0};return e.bottom=e.top+e.height,e.right=e.left+e.width,e}function Fe(t){return Re(t.getBoundingClientRect())}function $(t,e){var r;let n=e.posAtCoords(t);if(!n)return;let o=e.domAtPos(n.pos).node;if(o!==e.dom){for(;o&&o.parentNode&&o.parentNode!==e.dom&&!((r=o.hasAttribute)!=null&&r.call(o,"data-id"));)o=o.parentNode;if(!!o)return{node:o,id:o.getAttribute("data-id")}}}function Ue(t,e){let n=$(t,e);if(n&&n.node.nodeType===1){const o=e.docView;let r=o.nearestDesc(n.node,!0);return!r||r===o?null:r.posBefore}return null}function qe(t,e){let n,o;const r=e.resolve(t.from).node().type.spec.group==="blockContent",a=e.resolve(t.to).node().type.spec.group==="blockContent",d=Math.min(t.$anchor.depth,t.$head.depth);if(r&&a){const i=t.$from.start(d-1),s=t.$to.end(d-1);n=e.resolve(i-1).pos,o=e.resolve(s+1).pos}else n=t.from,o=t.to;return{from:n,to:o}}function G(t,e,n=e){e===n&&(n+=t.state.doc.resolve(e+1).node().nodeSize);const o=t.domAtPos(e).node.cloneNode(!0),r=t.domAtPos(e).node,a=(s,c)=>Array.prototype.indexOf.call(s.children,c),d=a(r,t.domAtPos(e+1).node.parentElement),i=a(r,t.domAtPos(n-1).node.parentElement);for(let s=r.childElementCount-1;s>=0;s--)(s>i||s<d)&&o.removeChild(o.children[s]);E=o,E.className=O.dragPreview,document.body.appendChild(E)}function ze(){E!==void 0&&(document.body.removeChild(E),E=void 0)}function $e(t,e){if(!t.dataTransfer)return;let n={left:e.dom.clientWidth/2,top:t.clientY},o=Ue(n,e);if(o!=null){const r=e.state.selection,a=e.state.doc,{from:d,to:i}=qe(r,a),s=d<=o&&o<i,c=!r.$anchor.node().eq(r.$head.node());s&&c?(e.dispatch(e.state.tr.setSelection(H.create(a,d,i))),G(e,d,i)):(e.dispatch(e.state.tr.setSelection(k.NodeSelection.create(e.state.doc,o))),G(e,o));let f=e.state.selection.content(),{dom:h,text:l}=Oe(e,f);t.dataTransfer.clearData(),t.dataTransfer.setData("text/html",h.innerHTML),t.dataTransfer.setData("text/plain",l),t.dataTransfer.effectAllowed="move",t.dataTransfer.setDragImage(E,0,0),e.dragging={slice:f,move:!0}}}class Ge{constructor({editor:e,blockMenuFactory:n,horizontalPosAnchoredAtRoot:o}){p(this,"editor");p(this,"horizontalPosAnchoredAtRoot");p(this,"blockMenu");p(this,"hoveredBlock");p(this,"menuOpen",!1);p(this,"menuFrozen",!1);this.editor=e,this.horizontalPosAnchoredAtRoot=o,this.blockMenu=n(this.getStaticParams()),document.body.addEventListener("mousemove",r=>{var s,c;if(this.menuFrozen)return;const a={left:this.editor.view.dom.clientWidth/2,top:r.clientY},d=$(a,this.editor.view);if(!d){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}if(this.menuOpen&&((s=this.hoveredBlock)==null?void 0:s.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===d.id)return;const i=d.node.firstChild;this.hoveredBlock=i,i&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))},!0),document.body.addEventListener("mousedown",r=>{var a;(a=this.blockMenu.element)!=null&&a.contains(r.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)},!0),document.body.addEventListener("keydown",()=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1},!0)}destroy(){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide())}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const e=this.hoveredBlock.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:e.left,top:e.top});if(!n)return;const o=v(this.editor.state.doc,n.pos);if(o===void 0)return;const{contentNode:r,endPos:a}=o;if(r.textContent.length!==0){const d=a+1,i=d+2;this.editor.chain().BNCreateBlock(d).BNSetContentType(i,{name:"textContent"}).setTextSelection(i).run()}this.editor.view.focus(),this.editor.view.dispatch(this.editor.view.state.tr.scrollIntoView().setMeta(_,{activate:!0,type:"drag"}))}deleteBlock(){this.menuOpen=!1,this.blockMenu.hide();const e=this.hoveredBlock.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:e.left,top:e.top});!n||this.editor.commands.BNDeleteBlock(n.pos)}getStaticParams(){return{addBlock:()=>this.addBlock(),deleteBlock:()=>this.deleteBlock(),blockDragStart:e=>$e(e,this.editor.view),blockDragEnd:()=>ze(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1}}}getDynamicParams(){const e=this.hoveredBlock.getBoundingClientRect();return{blockBoundingBox:new DOMRect(this.horizontalPosAnchoredAtRoot?De():e.x,e.y,e.width,e.height)}}}const Ke=t=>new k.Plugin({key:new k.PluginKey("DraggableBlocksPlugin"),view:()=>new Ge({editor:t.editor,blockMenuFactory:t.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),je=u.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[Ke({editor:this.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}}),We=new k.PluginKey("HyperlinkToolbarPlugin");class Ve{constructor({editor:e,hyperlinkToolbarFactory:n}){p(this,"editor");p(this,"hyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");this.editor=e,this.hyperlinkToolbar=n(this.getStaticParams()),this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),e.view.dom.addEventListener("mouseover",o=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),o.target instanceof HTMLAnchorElement&&o.target.nodeName==="A"){const r=o.target,a=e.view.posAtDOM(r,0)+1,d=e.state.doc.resolve(a),i=d.marks();for(const s of i)if(s.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=u.getMarkRange(d,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1})}update(){var n,o,r,a;if(!this.editor.view.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.editor.state.selection.empty){const d=this.editor.state.selection.$from.marks();for(const i of d)if(i.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=u.getMarkRange(this.editor.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(n=this.hyperlinkToolbar.element)==null||n.addEventListener("mouseleave",this.startMenuUpdateTimer),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1)}if(!this.hyperlinkMark&&e){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(a=this.hyperlinkToolbar.element)==null||a.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}getStaticParams(){return{editHyperlink:(e,n)=>{const o=this.editor.view.state.tr.insertText(n,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+n.length,this.editor.schema.mark("link",{href:e})),this.editor.view.dispatch(o),this.editor.view.focus(),this.hyperlinkToolbar.hide()},deleteHyperlink:()=>{this.editor.view.dispatch(this.editor.view.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.editor.view.focus(),this.hyperlinkToolbar.hide()}}}getDynamicParams(){return{url:this.hyperlinkMark.attrs.href,text:this.editor.view.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),boundingBox:u.posToDOMRect(this.editor.view,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)}}}const Ye=(t,e)=>new k.Plugin({key:We,view:()=>new Ve({editor:t,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),Je=U.Link.extend({priority:500,addProseMirrorPlugins(){var t;if(!this.options.hyperlinkToolbarFactory)throw new Error("UI Element factory not defined for HyperlinkMark");return[...((t=this.parent)==null?void 0:t.call(this))||[],Ye(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),Qe=me.default.extend({addKeyboardShortcuts:()=>({"Mod-Alt-0":()=>!1})}),Xe=new k.PluginKey("blocknote-placeholder"),Ze=u.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new k.Plugin({key:Xe,props:{decorations:t=>{const{doc:e,selection:n}=t,o=_.getState(t),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:a}=n,d=[];if(!!r)return e.descendants((i,s)=>{const c=a>=s&&a<=s+i.nodeSize,f=!i.isLeaf&&!i.childCount;if((c||!this.options.showOnlyCurrent)&&f){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),c&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.type)==="drag"&&(o==null?void 0:o.active)&&h.push(this.options.isFilterClass);const l=B.Decoration.node(s,s+i.nodeSize,{class:h.join(" ")});d.push(l)}return this.options.includeChildren}),B.DecorationSet.create(e,d)}}})]}}),et=u.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const t=new k.PluginKey(this.name);return[new k.Plugin({key:t,appendTransaction:(e,n,o)=>{const{doc:r,tr:a,schema:d}=o,i=t.getState(o),s=r.content.size-2,c=d.nodes.block,f=d.nodes.textContent;if(!!i)return a.insert(s,c.create(void 0,f.create()))},state:{init:(e,n)=>{},apply:(e,n)=>{if(!e.docChanged)return n;let o=e.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="block")throw new Error("Expected block");return o.nodeSize>4}}})]}});function tt(t,e=JSON.stringify){const n={};return t.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function nt(t){const e=t.filter((o,r)=>t.indexOf(o)!==r);return tt(e)}const ot=u.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++,parseInt(window.__TEST_OPTIONS.mockID)):oe.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null}}}]},onCreate(){if(this.editor.extensionManager.extensions.find(s=>s.name==="collaboration"))return;const{view:t,state:e}=this.editor,{tr:n,doc:o}=e,{types:r,attributeName:a,generateID:d}=this.options;u.findChildren(o,s=>r.includes(s.type.name)&&s.attrs[a]===null).forEach(({node:s,pos:c})=>{n.setNodeMarkup(c,void 0,{...s.attrs,[a]:d()})}),n.setMeta("addToHistory",!1),t.dispatch(n)},addProseMirrorPlugins(){let t=null,e=!1;return[new k.Plugin({key:new k.PluginKey("uniqueID"),appendTransaction:(n,o,r)=>{console.log("appendTransaction");const a=n.some(y=>y.docChanged)&&!o.doc.eq(r.doc),d=this.options.filterTransaction&&n.some(y=>{var I,T;return!(!((T=(I=this.options).filterTransaction)===null||T===void 0)&&T.call(I,y))});if(!a||d)return;const{tr:i}=r,{types:s,attributeName:c,generateID:f}=this.options,h=u.combineTransactionSteps(o.doc,n),{mapping:l}=h;if(u.getChangedRanges(h).forEach(({newRange:y})=>{const I=u.findChildrenInRange(r.doc,y,w=>s.includes(w.type.name)),T=I.map(({node:w})=>w.attrs[c]).filter(w=>w!==null),b=nt(T);I.forEach(({node:w,pos:L})=>{var R;const j=(R=i.doc.nodeAt(L))===null||R===void 0?void 0:R.attrs[c];if(j===null){i.setNodeMarkup(L,void 0,{...w.attrs,[c]:f()});return}const{deleted:at}=l.invert().mapResult(L);at&&b.includes(j)&&i.setNodeMarkup(L,void 0,{...w.attrs,[c]:f()})})}),!!i.steps.length)return i},view(n){const o=r=>{var a;t=!((a=n.dom.parentElement)===null||a===void 0)&&a.contains(r.target)?n.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(n,o)=>{var r;return(t!==n.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(t=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:n=>{if(!e)return n;const{types:o,attributeName:r}=this.options,a=d=>{const i=[];return d.forEach(s=>{if(s.isText){i.push(s);return}if(!o.includes(s.type.name)){i.push(s.copy(a(s.content)));return}const c=s.type.create({...s.attrs,[r]:null},a(s.content),s.marks);i.push(c)}),A.Fragment.from(i)};return e=!1,new A.Slice(a(n.content),n.openStart,n.openEnd)}}})]}}),rt=u.Node.create({name:"doc",topNode:!0,content:"block+"}),K=t=>{const e=[u.extensions.ClipboardTextSerializer,u.extensions.Commands,u.extensions.Editable,u.extensions.FocusEvents,u.extensions.Tabindex,de.default,Ze.configure({emptyNodeClass:M.isEmpty,hasAnchorClass:M.hasAnchor,isFilterClass:M.isFilter,includeChildren:!0,showOnlyCurrent:!1}),ot.configure({types:["block"]}),le.default,he.default,ie.default,se.default,ce.default,ue.default,pe.default,Qe,...Me,ae.default.configure({width:5,color:"#ddeeff"}),Q.History,et];return t.blockSideMenuFactory&&e.push(je.configure({blockSideMenuFactory:t.blockSideMenuFactory})),t.formattingToolbarFactory&&e.push(Pe.configure({formattingToolbarFactory:t.formattingToolbarFactory})),t.hyperlinkToolbarFactory?e.push(Je.configure({hyperlinkToolbarFactory:t.hyperlinkToolbarFactory})):e.push(U.Link),t.slashMenuFactory&&e.push(_e.configure({slashMenuFactory:t.slashMenuFactory})),e},it={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class st{constructor(e={}){p(this,"tiptapEditor");var a,d,i;const n=K(e.uiFactories||{});let o=e.disableHistoryExtension?n.filter(s=>s.name!=="history"):n;const r={...it,...e,extensions:e.enableBlockNoteExtensions===!1?e.extensions:[...e.extensions||[],...o],editorProps:{attributes:{...((a=e.editorProps)==null?void 0:a.attributes)||{},class:[O.bnEditor,O.bnRoot,((i=(d=e.editorProps)==null?void 0:d.attributes)==null?void 0:i.class)||""].join(" ")}}};this.tiptapEditor=new u.Editor(r)}}m.BlockNoteEditor=st,m.Document=rt,m.SlashMenuGroups=x,m.SlashMenuItem=S,m.getBlockNoteExtensions=K,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(m,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@tiptap/core"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-text"),require("@tiptap/extension-underline"),require("prosemirror-model"),require("prosemirror-state"),require("prosemirror-view"),require("lodash"),require("@tiptap/extension-link"),require("uuid")):typeof define=="function"&&define.amd?define(["exports","@tiptap/core","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-text","@tiptap/extension-underline","prosemirror-model","prosemirror-state","prosemirror-view","lodash","@tiptap/extension-link","uuid"],u):(m=typeof globalThis<"u"?globalThis:m||self,u(m.blocknote={},m.core,m.Bold,m.Code,m.DropCursor,m.GapCursor,m.HardBreak,m.extensionHistory,m.Italic,m.Strike,m.Text,m.Underline,m.prosemirrorModel,m.prosemirrorState,m.pv,m.lodash,m.extensionLink,m.uuid))})(this,function(m,u,P,W,V,Y,J,Q,X,Z,ee,te,S,g,w,F,U,ne){"use strict";var st=Object.defineProperty;var at=(m,u,P)=>u in m?st(m,u,{enumerable:!0,configurable:!0,writable:!0,value:P}):m[u]=P;var p=(m,u,P)=>(at(m,typeof u!="symbol"?u+"":u,P),P);const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t};function oe(t){if(t&&t.__esModule)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const re=I(P),ie=I(W),se=I(V),ae=I(Y),de=I(J),le=I(X),ce=I(Z),ue=I(ee),he=I(te),pe=oe(w);function b(t,e){if(e<=0||e>t.nodeSize)return;const n=t.resolve(e),o=n.depth;let r=n.node(o),a=o;for(;a>=0;){if(a===0)return;if(r.type.name==="blockContainer")break;a-=1,r=n.node(a)}const d=r.attrs.id,i=r.firstChild,s=i.type,c=r.childCount===2?r.lastChild.childCount:0,f=n.start(a),h=n.end(a);return{id:d,node:r,contentNode:i,contentType:s,numChildBlocks:c,startPos:f,endPos:h,depth:a}}const q=new g.PluginKey("previous-blocks"),fe={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},me=()=>new g.Plugin({key:q,view(t){return{update:async(e,n)=>{var o;(o=this.key)!=null&&o.getState(e.state).needsUpdate&&setTimeout(()=>{e.dispatch(e.state.tr.setMeta(q,{clearUpdate:!0}))},0)}}},state:{init(){return{prevBlockAttrs:{},needsUpdate:!1}},apply(t,e,n,o){if(e.needsUpdate=!1,e.prevBlockAttrs={},!t.docChanged||n.doc.eq(o.doc))return e;const r=u.combineTransactionSteps(n.doc,[t]);return u.getChangedRanges(r).forEach(()=>{const d=u.findChildren(n.doc,c=>c.attrs.id),i=new Map(d.map(c=>[c.node.attrs.id,c])),s=u.findChildren(o.doc,c=>c.attrs.id);for(let c of s){const f=i.get(c.node.attrs.id),h=f==null?void 0:f.node.firstChild,l=c.node.firstChild;if(f&&h&&l){const k={index:l.attrs.index,level:l.attrs.level,type:l.type.name,depth:o.doc.resolve(c.pos).depth},y={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:n.doc.resolve(f.pos).depth},B=y.index===null&&k.index!==null,M=y.index!==null&&k.index!==null&&y.index===k.index,v=y.type==="numberedListItem"&&k.type==="numberedListItem"?B||M:!0;JSON.stringify(y)!==JSON.stringify(k)&&v&&(y["depth-change"]=y.depth-k.depth,e.prevBlockAttrs[c.node.attrs.id]=y,console.log("id:",c.node.attrs.id,"previousBlockTypePlugin changes detected, oldAttrs",y,"new",k),e.needsUpdate=!0)}}}),e}},props:{decorations(t){const e=this.getState(t);if(!e.needsUpdate)return;const n=[];return t.doc.descendants((o,r)=>{if(!o.attrs.id)return;const a=e.prevBlockAttrs[o.attrs.id];if(!a)return;const d={};for(let[s,c]of Object.entries(a))d["data-prev-"+fe[s]]=c||"none";console.log("previousBlockTypePlugin committing decorations",d);const i=w.Decoration.node(r,r+o.nodeSize,{...d});n.push(i)}),w.DecorationSet.create(t.doc,n)}}}),C={blockOuter:"_blockOuter_6qmsf_5",block:"_block_6qmsf_5",blockContent:"_blockContent_6qmsf_25",blockGroup:"_blockGroup_6qmsf_53",isEmpty:"_isEmpty_6qmsf_238",isFilter:"_isFilter_6qmsf_239",hasAnchor:"_hasAnchor_6qmsf_252"},ke={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},ge=u.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,addOptions(){return{HTMLAttributes:{}}},addAttributes(){return{blockColor:{default:void 0},blockStyle:{default:void 0}}},parseHTML(){return[{tag:"div",getAttrs:t=>{if(typeof t=="string")return!1;const e={};for(let[n,o]of Object.entries(ke))t.getAttribute(o)&&(e[n]=t.getAttribute(o));return t.getAttribute("data-node-type")==="blockContainer"?e:!1}}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:C.blockOuter,"data-node-type":"block-outer"}),["div",u.mergeAttributes(t,{class:C.block,"data-node-type":this.name}),0]]},addCommands(){return{BNCreateBlock:t=>({state:e,dispatch:n})=>{const o=e.schema.nodes.blockContainer.createAndFill();return n&&e.tr.insert(t,o),!0},BNDeleteBlock:t=>({state:e,view:n,dispatch:o})=>{const r=b(e.doc,t);if(r===void 0)return!1;const{startPos:a,endPos:d}=r;return o&&(e.tr.deleteRange(a,d),e.tr.setSelection(new g.TextSelection(e.doc.resolve(a+1))),n.focus()),!0},BNMergeBlocks:t=>({state:e,dispatch:n})=>{const o=e.doc.resolve(t+1).node().type.name==="blockContainer",r=e.doc.resolve(t-1).node().type.name==="blockContainer";if(!o||!r)return!1;const a=b(e.doc,t+1),{node:d,contentNode:i,startPos:s,endPos:c,depth:f}=a;if(d.childCount===2){const k=e.doc.resolve(s+i.nodeSize+1),y=e.doc.resolve(c-1),B=k.blockRange(y);n&&e.tr.lift(B,f-1)}let h=t-1,l=b(e.doc,h);for(;l.numChildBlocks>0;)if(h--,l=b(e.doc,h),l===void 0)return!1;return n&&(e.tr.deleteRange(s,s+i.nodeSize),e.tr.insertText(i.textContent,h-1),e.tr.setSelection(new g.TextSelection(e.doc.resolve(h-1)))),!0},BNSplitBlock:(t,e)=>({state:n,dispatch:o})=>{const r=b(n.doc,t);if(r===void 0)return!1;const{contentNode:a,contentType:d,startPos:i,endPos:s,depth:c}=r,f=s+1,h=n.doc.textBetween(t,s),l=n.schema.nodes.blockContainer.createAndFill(),k=f+2;o&&(n.tr.insert(f,l),n.tr.insertText(h,k),e&&n.tr.setBlockType(k,k,n.schema.node(d).type,a.attrs));const y=n.doc.content.cut(i,t);return o&&n.tr.replace(i,s,new S.Slice(y,c,c)),!0},BNUpdateBlock:(t,e)=>({state:n,dispatch:o})=>{const r=b(n.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,contentNode:i}=r;return o&&n.tr.setBlockType(d+1,d+i.nodeSize+1,n.schema.node(e.type).type,{...a.attrs,...e.props}),!0},BNCreateOrUpdateBlock:(t,e)=>({state:n,chain:o})=>{const r=b(n.doc,t);if(r===void 0)return!1;const{node:a,startPos:d,endPos:i}=r;if(a.textContent.length===0){const s=d+1;return o().BNUpdateBlock(t,e).setTextSelection(s).run()}else{const s=i+1,c=s+1;return o().BNCreateBlock(s).BNUpdateBlock(c,e).setTextSelection(c).run()}}}},addProseMirrorPlugins(){return[me()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:o})=>{const{contentType:r}=b(o.doc,o.selection.from),a=o.selection.$anchor.parentOffset===0,d=r.name==="paragraph";return a&&!d?n.BNUpdateBlock(o.selection.from,{type:"paragraph",props:{}}):!1}),()=>n.command(({state:o})=>o.selection.$anchor.parentOffset===0?n.liftListItem("blockContainer"):!1),()=>n.command(({state:o})=>{const{depth:r,startPos:a}=b(o.doc,o.selection.from),d=o.selection.$anchor.parentOffset===0,i=o.selection.anchor===o.selection.head,s=a===2,c=a-1;return!s&&d&&i&&r===2?n.BNMergeBlocks(c):!1})]),Enter:()=>this.editor.commands.first(({commands:n})=>[()=>n.command(({state:o})=>{const{node:r,depth:a}=b(o.doc,o.selection.from),d=o.selection.$anchor.parentOffset===0,i=o.selection.anchor===o.selection.head,s=r.textContent.length===0,c=a>2;return d&&i&&s&&c?n.liftListItem("blockContainer"):!1}),()=>n.command(({state:o,chain:r})=>{const{node:a,endPos:d}=b(o.doc,o.selection.from),i=o.selection.$anchor.parentOffset===0,s=o.selection.anchor===o.selection.head,c=a.textContent.length===0;if(i&&s&&c){const f=d+1,h=f+2;return r().BNCreateBlock(f).setTextSelection(h).run(),!0}return!1}),()=>n.command(({state:o,chain:r})=>{const{node:a}=b(o.doc,o.selection.from);return a.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(o.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:{}})}}}),ye=u.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"div",getAttrs:t=>typeof t=="string"?!1:t.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(this.options.HTMLAttributes,t,{class:C.blockGroup,"data-node-type":"blockGroup"}),0]}}),be=u.Node.create({name:"paragraph",group:"blockContent",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"blockContainer"}]},renderHTML(){return["div",{class:C.blockContent,"data-content-type":this.name},["p",0]]}}),ve=u.Node.create({name:"heading",group:"blockContent",content:"inline*",addAttributes(){return{level:{default:"1",parseHTML:t=>t.getAttribute("data-level"),renderHTML:t=>({"data-level":t.level})}}},addInputRules(){return[...["1","2","3"].map(t=>new u.InputRule({find:new RegExp(`^(#{${parseInt(t)}})\\s$`),handler:({state:e,chain:n,range:o})=>{n().BNUpdateBlock(e.selection.from,{type:"heading",props:{level:t}}).deleteRange({from:o.from,to:o.to})}}))]},parseHTML(){return[{tag:"h1",attrs:{level:"1"},node:"blockContainer"},{tag:"h2",attrs:{level:"2"},node:"blockContainer"},{tag:"h3",attrs:{level:"3"},node:"blockContainer"}]},renderHTML({node:t,HTMLAttributes:e}){return["div",u.mergeAttributes(e,{class:C.blockContent,"data-content-type":this.name}),["h"+t.attrs.level,0]]}}),z=t=>{const{node:e,contentType:n}=b(t.state.doc,t.state.selection.from),o=t.state.selection.anchor===t.state.selection.head;return!n.name.endsWith("ListItem")||!o?!1:t.commands.first(({state:r,chain:a,commands:d})=>[()=>d.command(()=>e.textContent.length===0?d.BNUpdateBlock(r.selection.from,{type:"paragraph",props:{}}):!1),()=>d.command(()=>e.textContent.length>0?(a().deleteSelection().BNSplitBlock(r.selection.from,!0).run(),!0):!1)])},Be=u.Node.create({name:"bulletListItem",group:"blockContent",content:"inline*",addInputRules(){return[new u.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:t,chain:e,range:n})=>{e().BNUpdateBlock(t.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:n.from,to:n.to})}})]},addKeyboardShortcuts(){return{Enter:()=>z(this.editor)}},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="bulletListItem"?{}:e.tagName==="UL"?{}:!1},node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:C.blockContent,"data-content-type":this.name}),["li",0]]}}),Me=new g.PluginKey("numbered-list-indexing"),Ce=()=>new g.Plugin({key:Me,appendTransaction:(t,e,n)=>{const o=n.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return n.doc.descendants((a,d)=>{if(a.type.name==="blockContainer"&&a.firstChild.type.name==="numberedListItem"){let i="1";const s=d===1,c=b(o.doc,d+1);if(c===void 0)return;if(!s){const l=b(o.doc,d-2);if(l===void 0)return;if(!(c.depth!==l.depth)){const y=l.contentNode;if(l.contentType.name==="numberedListItem"){const v=y.attrs.index;i=(parseInt(v)+1).toString()}}}c.contentNode.attrs.index!==i&&(r=!0,o.setNodeMarkup(d+1,void 0,{index:i}))}}),r?o:null}}),we=u.Node.create({name:"numberedListItem",group:"blockContent",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:t=>t.getAttribute("data-index"),renderHTML:t=>({"data-index":t.index})}}},addInputRules(){return[new u.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:t,chain:e,range:n})=>{e().BNUpdateBlock(t.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:n.from,to:n.to})}})]},addKeyboardShortcuts(){return{Enter:()=>z(this.editor)}},addProseMirrorPlugins(){return[Ce()]},parseHTML(){return[{tag:"li",getAttrs:t=>{if(typeof t=="string")return!1;const e=t.parentElement;return e===null?!1:e.getAttribute("data-content-type")==="numberedListItem"?{}:e.tagName==="OL"?{}:!1},node:"blockContainer"}]},renderHTML({HTMLAttributes:t}){return["div",u.mergeAttributes(t,{class:C.blockContent,"data-content-type":this.name}),["li",0]]}}),Ie=[be,ve,Be,we,ge,ye,u.Node.create({name:"doc",topNode:!0,content:"blockGroup"})];class xe{constructor({editor:e,formattingToolbarFactory:n,view:o,shouldShow:r}){p(this,"editor");p(this,"view");p(this,"formattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"toolbarIsOpen",!1);p(this,"shouldShow",({view:e,state:n,from:o,to:r})=>{const{doc:a,selection:d}=n,{empty:i}=d,s=!a.textBetween(o,r).length&&u.isTextSelection(n.selection);return!(!e.hasFocus()||i||s)});p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.editor.view))});p(this,"dragstartHandler",()=>{this.formattingToolbar.hide(),this.toolbarIsOpen=!1});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.editor.view))});p(this,"blurHandler",({event:e})=>{var n,o;if(this.preventHide){this.preventHide=!1;return}(e==null?void 0:e.relatedTarget)&&((o=(n=this.formattingToolbar.element)==null?void 0:n.parentNode)==null?void 0:o.contains(e.relatedTarget))||this.toolbarIsOpen&&(this.formattingToolbar.hide(),this.toolbarIsOpen=!1)});this.editor=e,this.view=o,this.formattingToolbar=n(this.getStaticParams()),r&&(this.shouldShow=r),this.view.dom.addEventListener("mousedown",this.viewMousedownHandler),this.view.dom.addEventListener("mouseup",this.viewMouseupHandler),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler)}update(e,n){var l;const{state:o,composing:r}=e,{doc:a,selection:d}=o,i=n&&n.doc.eq(a)&&n.selection.eq(d);if(r||i)return;const{ranges:s}=d,c=Math.min(...s.map(k=>k.$from.pos)),f=Math.max(...s.map(k=>k.$to.pos)),h=(l=this.shouldShow)==null?void 0:l.call(this,{editor:this.editor,view:e,state:o,oldState:n,from:c,to:f});if(!this.toolbarIsOpen&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!0),this.toolbarIsOpen=!0,this.formattingToolbar.element.addEventListener("mousedown",k=>k.preventDefault());return}if(this.toolbarIsOpen&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbar.render(this.getDynamicParams(),!1);return}if(this.toolbarIsOpen&&!this.preventHide&&(!h||this.preventShow)){this.formattingToolbar.hide(),this.toolbarIsOpen=!1,this.formattingToolbar.element.removeEventListener("mousedown",k=>k.preventDefault());return}}destroy(){this.view.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.view.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler)}getSelectionBoundingBox(){const{state:e}=this.editor.view,{selection:n}=e,{ranges:o}=n,r=Math.min(...o.map(d=>d.$from.pos)),a=Math.max(...o.map(d=>d.$to.pos));if(u.isNodeSelection(n)){const d=this.editor.view.nodeDOM(r);if(d)return d.getBoundingClientRect()}return u.posToDOMRect(this.editor.view,r,a)}getStaticParams(){return{toggleBold:()=>{this.editor.view.focus(),this.editor.commands.toggleBold()},toggleItalic:()=>{this.editor.view.focus(),this.editor.commands.toggleItalic()},toggleUnderline:()=>{this.editor.view.focus(),this.editor.commands.toggleUnderline()},toggleStrike:()=>{this.editor.view.focus(),this.editor.commands.toggleStrike()},setHyperlink:(e,n)=>{if(e==="")return;let{from:o,to:r}=this.editor.state.selection;n||(n=this.editor.state.doc.textBetween(o,r));const a=this.editor.schema.mark("link",{href:e});this.editor.view.dispatch(this.editor.view.state.tr.insertText(n,o,r).addMark(o,o+n.length,a)),this.editor.view.focus()},updateBlock:e=>{this.editor.view.focus(),this.editor.commands.BNUpdateBlock(this.editor.state.selection.from,e)}}}getDynamicParams(){const e=b(this.editor.state.doc,this.editor.state.selection.from);return{boldIsActive:this.editor.isActive("bold"),italicIsActive:this.editor.isActive("italic"),underlineIsActive:this.editor.isActive("underline"),strikeIsActive:this.editor.isActive("strike"),hyperlinkIsActive:this.editor.isActive("link"),activeHyperlinkUrl:this.editor.getAttributes("link").href?this.editor.getAttributes("link").href:"",activeHyperlinkText:this.editor.state.doc.textBetween(this.editor.state.selection.from,this.editor.state.selection.to),block:{type:e.contentType.name,props:e.contentNode.attrs},referenceRect:this.getSelectionBoundingBox()}}}const Te=t=>new g.Plugin({key:new g.PluginKey("FormattingToolbarPlugin"),view:e=>new xe({view:e,...t})}),Pe=u.Extension.create({name:"FormattingToolbarExtension",addProseMirrorPlugins(){if(!this.options.formattingToolbarFactory)throw new Error("UI Element factory not defined for FormattingToolbarExtension");return[Te({editor:this.editor,formattingToolbarFactory:this.options.formattingToolbarFactory,pluginKey:new g.PluginKey("FormattingToolbarPlugin")})]}}),_={bnEditor:"_bnEditor_xixap_3",bnRoot:"_bnRoot_xixap_13",dragPreview:"_dragPreview_xixap_27"},Ee=u.findParentNode(t=>t.type.name==="blockContainer");function Ne(t,e){if(!e.empty)return;const n=e.$anchor.nodeBefore;if(!n||!n.text)return;const o=new RegExp(`${F.escapeRegExp(t)}([^${F.escapeRegExp(t)}]*)$`),r=n.text.match(o);if(!!r)return{query:r[1],range:{from:e.$anchor.pos-r[1].length-t.length,to:e.$anchor.pos}}}class Ae{constructor({editor:e,pluginKey:n,onSelectItem:o=()=>{},suggestionsMenuFactory:r}){p(this,"editor");p(this,"pluginKey");p(this,"suggestionsMenu");p(this,"pluginState");p(this,"itemCallback");this.editor=e,this.pluginKey=n,this.pluginState={active:!1,range:null,query:null,notFoundCount:0,items:[],selectedItemIndex:0,type:"slash",decorationId:null},this.itemCallback=a=>o({item:a,editor:e,range:this.pluginState.range}),this.suggestionsMenu=r(this.getStaticParams())}update(e,n){const o=this.pluginKey.getState(n),r=this.pluginKey.getState(e.state),a=!o.active&&r.active,d=o.active&&!r.active,i=o.active&&r.active;!a&&!i&&!d||(this.pluginState=d?o:r,d&&(this.suggestionsMenu.hide(),this.suggestionsMenu.element.removeEventListener("mousedown",s=>s.preventDefault())),i&&this.suggestionsMenu.render(this.getDynamicParams(),!1),a&&(this.suggestionsMenu.render(this.getDynamicParams(),!0),this.suggestionsMenu.element.addEventListener("mousedown",s=>s.preventDefault())))}getStaticParams(){return{itemCallback:e=>this.itemCallback(e)}}getDynamicParams(){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);return{items:this.pluginState.items,selectedItemIndex:this.pluginState.selectedItemIndex,referenceRect:e.getBoundingClientRect()}}}function Se({pluginKey:t,editor:e,char:n,suggestionsMenuFactory:o,onSelectItem:r=()=>{},items:a=()=>[]}){if(n.length!==1)throw new Error("'char' should be a single character");const d=i=>{i.dispatch(i.state.tr.setMeta(t,{deactivate:!0}))};return new g.Plugin({key:t,view:i=>new Ae({editor:e,pluginKey:t,onSelectItem:s=>{d(i),r(s)},suggestionsMenuFactory:o}),state:{init(){return{active:!1,range:null,query:null,notFoundCount:0,items:[],selectedItemIndex:0,type:"slash",decorationId:null}},apply(i,s,c,f){var k,y,B,M;const{selection:h}=i,l={...s};if(i.getMeta("numberedListIndexing")!==void 0)return l;if(((k=i.getMeta(t))==null?void 0:k.selectedItemIndexChanged)!==void 0){let v=i.getMeta(t).selectedItemIndexChanged;return v<0&&(v=s.items.length-1),v>=s.items.length&&(v=0),l.selectedItemIndex=v,l}if(h.from===h.to&&!((y=i.getMeta(t))!=null&&y.deactivate)&&!i.getMeta("focus")&&!i.getMeta("blur")&&!i.getMeta("pointer")){if(s.active&&h.from<=s.range.from)l.active=!1;else if((B=i.getMeta(t))!=null&&B.activate){const v=`id_${Math.floor(Math.random()*4294967295)}`;l.decorationId=v,l.range={from:h.from-1,to:h.to},l.query="",l.active=!0,l.type=(M=i.getMeta(t))==null?void 0:M.type,l.selectedItemIndex=0}else if(s.active){const v=Ne(s.type==="slash"?n:"",f.selection);if(!v)throw new Error("active but no match (suggestions)");l.range=v.range,l.active=!0,l.decorationId=s.decorationId,l.query=v.query,l.selectedItemIndex=0}}else l.active=!1;return l.active&&(l.items=a(l.query),l.items.length?l.notFoundCount=0:l.range.to>s.range.to?l.notFoundCount=s.notFoundCount+1:l.notFoundCount=s.notFoundCount,l.notFoundCount>3&&(l.active=!1)),l.active||(l.decorationId=null,l.range=null,l.query=null,l.notFoundCount=0,l.items=[]),l}},props:{handleKeyDown(i,s){const{active:c}=this.getState(i.state);if(c){const{items:f,range:h,selectedItemIndex:l}=t.getState(i.state);if(s.key==="ArrowUp")return i.dispatch(i.state.tr.setMeta(t,{selectedItemIndexChanged:l-1})),!0;if(s.key==="ArrowDown")return i.dispatch(i.state.tr.setMeta(t,{selectedItemIndexChanged:l+1})),!0;if(s.key==="Enter")return d(i),r({item:f[l],editor:e,range:h}),!0;if(s.key==="Escape")return d(i),!0}else if(s.key===n)return i.dispatch(i.state.tr.insertText(n).scrollIntoView().setMeta(t,{activate:!0,type:"slash"})),!0;return!1},handleClick(i){d(i)},decorations(i){const{active:s,range:c,decorationId:f,type:h}=this.getState(i);if(!s)return null;if(h==="drag"){const l=Ee(i.selection);if(l)return w.DecorationSet.create(i.doc,[w.Decoration.node(l.pos,l.pos+l.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":f})])}return w.DecorationSet.create(i.doc,[w.Decoration.inline(c.from,c.to,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":f})])}}})}const He=()=>/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent);function A(t){return He()?t.replace("Mod","\u2318"):t.replace("Mod","Ctrl")}var x=(t=>(t.HEADINGS="Headings",t.BASIC_BLOCKS="Basic Blocks",t.CODE="Code Blocks",t.INLINE="Inline",t.EMBED="Embed",t.PLUGIN="Plugin",t))(x||{});class E{constructor(e,n,o,r=[],a,d){p(this,"groupName");this.name=e,this.group=n,this.execute=o,this.aliases=r,this.hint=a,this.shortcut=d,this.groupName=n}match(e){return this.name.toLowerCase().startsWith(e.toLowerCase())||this.aliases.filter(n=>n.toLowerCase().startsWith(e.toLowerCase())).length!==0}}const Le={heading:new E("Heading",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"1"}}).run(),["h","heading1","h1"],"Used for a top-level heading",A("Mod-Alt-1")),heading2:new E("Heading 2",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"2"}}).run(),["h2","heading2","subheading"],"Used for key sections",A("Mod-Alt-2")),heading3:new E("Heading 3",x.HEADINGS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"heading",props:{level:"3"}}).run(),["h3","heading3","subheading"],"Used for subsections and group headings",A("Mod-Alt-3")),numberedList:new E("Numbered List",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"numberedListItem",props:{}}).run(),["li","list","numberedlist","numbered list"],"Used to display a numbered list",A("Mod-Shift-7")),bulletList:new E("Bullet List",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"bulletListItem",props:{}}).run(),["ul","list","bulletlist","bullet list"],"Used to display an unordered list",A("Mod-Shift-8")),paragraph:new E("Paragraph",x.BASIC_BLOCKS,(t,e)=>t.chain().focus().deleteRange(e).BNCreateOrUpdateBlock(e.from,{type:"paragraph",props:{}}).run(),["p"],"Used for the body of your document",A("Mod-Alt-0"))},O=new g.PluginKey("suggestions-slash-commands"),_e=u.Extension.create({name:"slash-command",addOptions(){return{commands:Le,slashMenuFactory:void 0}},addProseMirrorPlugins(){if(!this.options.slashMenuFactory)throw new Error("UI Element factory not defined for SlashMenuExtension");return[Se({pluginKey:O,editor:this.editor,char:"/",suggestionsMenuFactory:this.options.slashMenuFactory,items:t=>{const e=[];for(const n in this.options.commands)e.push(this.options.commands[n]);return e.filter(n=>n.match(t))},onSelectItem:({item:t,editor:e,range:n})=>{t.execute(e,n)}})]}});class H extends g.Selection{constructor(n,o){super(n,o);p(this,"nodes");const r=n.node();this.nodes=[],n.doc.nodesBetween(n.pos,o.pos,(a,d,i)=>{if(i!==null&&i.eq(r))return this.nodes.push(a),!1})}static create(n,o,r=o){return new H(n.resolve(o),n.resolve(r))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(n){if(!(n instanceof H)||this.nodes.length!==n.nodes.length||this.from!==n.from||this.to!==n.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(n.nodes[o]))return!1;return!0}map(n,o){let r=o.mapResult(this.from),a=o.mapResult(this.to);return a.deleted?g.Selection.near(n.resolve(r.pos)):r.deleted?g.Selection.near(n.resolve(a.pos)):new H(n.resolve(r.pos),n.resolve(a.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Oe=pe.__serializeForClipboard;let R,N;function Re(){if(!R){const t=document.querySelector(".ProseMirror > [class*='blockGroup']");t&&(R=Fe(t).left)}return R}function De(t){let e={left:t.left+document.body.scrollLeft,top:t.top+document.body.scrollTop,width:t.width,height:t.height,bottom:0,right:0};return e.bottom=e.top+e.height,e.right=e.left+e.width,e}function Fe(t){return De(t.getBoundingClientRect())}function $(t,e){var r;let n=e.posAtCoords(t);if(!n)return;let o=e.domAtPos(n.pos).node;if(o!==e.dom){for(;o&&o.parentNode&&o.parentNode!==e.dom&&!((r=o.hasAttribute)!=null&&r.call(o,"data-id"));)o=o.parentNode;if(!!o)return{node:o,id:o.getAttribute("data-id")}}}function Ue(t,e){let n=$(t,e);if(n&&n.node.nodeType===1){const o=e.docView;let r=o.nearestDesc(n.node,!0);return!r||r===o?null:r.posBefore}return null}function qe(t,e){let n,o;const r=e.resolve(t.from).node().type.spec.group==="blockContent",a=e.resolve(t.to).node().type.spec.group==="blockContent",d=Math.min(t.$anchor.depth,t.$head.depth);if(r&&a){const i=t.$from.start(d-1),s=t.$to.end(d-1);n=e.resolve(i-1).pos,o=e.resolve(s+1).pos}else n=t.from,o=t.to;return{from:n,to:o}}function G(t,e,n=e){e===n&&(n+=t.state.doc.resolve(e+1).node().nodeSize);const o=t.domAtPos(e).node.cloneNode(!0),r=t.domAtPos(e).node,a=(s,c)=>Array.prototype.indexOf.call(s.children,c),d=a(r,t.domAtPos(e+1).node.parentElement),i=a(r,t.domAtPos(n-1).node.parentElement);for(let s=r.childElementCount-1;s>=0;s--)(s>i||s<d)&&o.removeChild(o.children[s]);N=o,N.className=_.dragPreview,document.body.appendChild(N)}function ze(){N!==void 0&&(document.body.removeChild(N),N=void 0)}function $e(t,e){if(!t.dataTransfer)return;let n={left:e.dom.clientWidth/2,top:t.clientY},o=Ue(n,e);if(o!=null){const r=e.state.selection,a=e.state.doc,{from:d,to:i}=qe(r,a),s=d<=o&&o<i,c=!r.$anchor.node().eq(r.$head.node());s&&c?(e.dispatch(e.state.tr.setSelection(H.create(a,d,i))),G(e,d,i)):(e.dispatch(e.state.tr.setSelection(g.NodeSelection.create(e.state.doc,o))),G(e,o));let f=e.state.selection.content(),{dom:h,text:l}=Oe(e,f);t.dataTransfer.clearData(),t.dataTransfer.setData("text/html",h.innerHTML),t.dataTransfer.setData("text/plain",l),t.dataTransfer.effectAllowed="move",t.dataTransfer.setDragImage(N,0,0),e.dragging={slice:f,move:!0}}}class Ge{constructor({editor:e,blockMenuFactory:n,horizontalPosAnchoredAtRoot:o}){p(this,"editor");p(this,"horizontalPosAnchoredAtRoot");p(this,"blockMenu");p(this,"hoveredBlock");p(this,"menuOpen",!1);p(this,"menuFrozen",!1);this.editor=e,this.horizontalPosAnchoredAtRoot=o,this.blockMenu=n(this.getStaticParams()),document.body.addEventListener("mousemove",r=>{var s,c;if(this.menuFrozen)return;const a={left:this.editor.view.dom.clientWidth/2,top:r.clientY},d=$(a,this.editor.view);if(!d){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide());return}if(this.menuOpen&&((s=this.hoveredBlock)==null?void 0:s.hasAttribute("data-id"))&&((c=this.hoveredBlock)==null?void 0:c.getAttribute("data-id"))===d.id)return;const i=d.node.firstChild;this.hoveredBlock=i,i&&(this.menuOpen?this.blockMenu.render(this.getDynamicParams(),!1):(this.menuOpen=!0,this.blockMenu.render(this.getDynamicParams(),!0)))},!0),document.body.addEventListener("mousedown",r=>{var a;(a=this.blockMenu.element)!=null&&a.contains(r.target)||(this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1)},!0),document.body.addEventListener("keydown",()=>{this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide()),this.menuFrozen=!1},!0)}destroy(){this.menuOpen&&(this.menuOpen=!1,this.blockMenu.hide())}addBlock(){this.menuOpen=!1,this.menuFrozen=!0,this.blockMenu.hide();const e=this.hoveredBlock.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:e.left,top:e.top});if(!n)return;const o=b(this.editor.state.doc,n.pos);if(o===void 0)return;const{contentNode:r,endPos:a}=o;if(r.textContent.length!==0){const d=a+1,i=d+2;this.editor.chain().BNCreateBlock(d).BNUpdateBlock(i,{type:"paragraph",props:{}}).setTextSelection(i).run()}this.editor.view.focus(),this.editor.view.dispatch(this.editor.view.state.tr.scrollIntoView().setMeta(O,{activate:!0,type:"drag"}))}deleteBlock(){this.menuOpen=!1,this.blockMenu.hide();const e=this.hoveredBlock.getBoundingClientRect(),n=this.editor.view.posAtCoords({left:e.left,top:e.top});!n||this.editor.commands.BNDeleteBlock(n.pos)}getStaticParams(){return{addBlock:()=>this.addBlock(),deleteBlock:()=>this.deleteBlock(),blockDragStart:e=>$e(e,this.editor.view),blockDragEnd:()=>ze(),freezeMenu:()=>{this.menuFrozen=!0},unfreezeMenu:()=>{this.menuFrozen=!1}}}getDynamicParams(){const e=this.hoveredBlock.getBoundingClientRect();return{referenceRect:new DOMRect(this.horizontalPosAnchoredAtRoot?Re():e.x,e.y,e.width,e.height)}}}const Ke=t=>new g.Plugin({key:new g.PluginKey("DraggableBlocksPlugin"),view:()=>new Ge({editor:t.editor,blockMenuFactory:t.blockSideMenuFactory,horizontalPosAnchoredAtRoot:!0})}),je=u.Extension.create({name:"DraggableBlocksExtension",priority:1e3,addProseMirrorPlugins(){if(!this.options.blockSideMenuFactory)throw new Error("UI Element factory not defined for DraggableBlocksExtension");return[Ke({editor:this.editor,blockSideMenuFactory:this.options.blockSideMenuFactory})]}}),We=new g.PluginKey("HyperlinkToolbarPlugin");class Ve{constructor({editor:e,hyperlinkToolbarFactory:n}){p(this,"editor");p(this,"hyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");this.editor=e,this.hyperlinkToolbar=n(this.getStaticParams()),this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),e.view.dom.addEventListener("mouseover",o=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),o.target instanceof HTMLAnchorElement&&o.target.nodeName==="A"){const r=o.target,a=e.view.posAtDOM(r,0)+1,d=e.state.doc.resolve(a),i=d.marks();for(const s of i)if(s.type.name===e.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=u.getMarkRange(d,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1})}update(){var n,o,r,a;if(!this.editor.view.hasFocus())return;const e=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.editor.state.selection.empty){const d=this.editor.state.selection.$from.marks();for(const i of d)if(i.type.name===this.editor.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=u.getMarkRange(this.editor.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark){if(this.getDynamicParams(),!e){this.hyperlinkToolbar.render(this.getDynamicParams(),!0),(n=this.hyperlinkToolbar.element)==null||n.addEventListener("mouseleave",this.startMenuUpdateTimer),(o=this.hyperlinkToolbar.element)==null||o.addEventListener("mouseenter",this.stopMenuUpdateTimer);return}this.hyperlinkToolbar.render(this.getDynamicParams(),!1);return}if(!this.hyperlinkMark&&e){(r=this.hyperlinkToolbar.element)==null||r.removeEventListener("mouseleave",this.startMenuUpdateTimer),(a=this.hyperlinkToolbar.element)==null||a.removeEventListener("mouseenter",this.stopMenuUpdateTimer),this.hyperlinkToolbar.hide();return}}getStaticParams(){return{editHyperlink:(e,n)=>{const o=this.editor.view.state.tr.insertText(n,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+n.length,this.editor.schema.mark("link",{href:e})),this.editor.view.dispatch(o),this.editor.view.focus(),this.hyperlinkToolbar.hide()},deleteHyperlink:()=>{this.editor.view.dispatch(this.editor.view.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.editor.view.focus(),this.hyperlinkToolbar.hide()}}}getDynamicParams(){return{url:this.hyperlinkMark.attrs.href,text:this.editor.view.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),referenceRect:u.posToDOMRect(this.editor.view,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)}}}const Ye=(t,e)=>new g.Plugin({key:We,view:()=>new Ve({editor:t,hyperlinkToolbarFactory:e.hyperlinkToolbarFactory})}),Je=U.Link.extend({priority:500,addProseMirrorPlugins(){var t;if(!this.options.hyperlinkToolbarFactory)throw new Error("UI Element factory not defined for HyperlinkMark");return[...((t=this.parent)==null?void 0:t.call(this))||[],Ye(this.editor,{hyperlinkToolbarFactory:this.options.hyperlinkToolbarFactory})]}}),Qe=new g.PluginKey("blocknote-placeholder"),Xe=u.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new g.Plugin({key:Qe,props:{decorations:t=>{const{doc:e,selection:n}=t,o=O.getState(t),r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:a}=n,d=[];if(!!r)return e.descendants((i,s)=>{const c=a>=s&&a<=s+i.nodeSize,f=!i.isLeaf&&!i.childCount;if((c||!this.options.showOnlyCurrent)&&f){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),c&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.type)==="drag"&&(o==null?void 0:o.active)&&h.push(this.options.isFilterClass);const l=w.Decoration.node(s,s+i.nodeSize,{class:h.join(" ")});d.push(l)}return this.options.includeChildren}),w.DecorationSet.create(e,d)}}})]}}),Ze=u.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const t=new g.PluginKey(this.name);return[new g.Plugin({key:t,appendTransaction:(e,n,o)=>{const{doc:r,tr:a,schema:d}=o,i=t.getState(o),s=r.content.size-2,c=d.nodes.blockContainer,f=d.nodes.paragraph;if(!!i)return a.insert(s,c.create(void 0,f.create()))},state:{init:(e,n)=>{},apply:(e,n)=>{if(!e.docChanged)return n;let o=e.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");return o.nodeSize>4}}})]}});function et(t,e=JSON.stringify){const n={};return t.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function tt(t){const e=t.filter((o,r)=>t.indexOf(o)!==r);return et(e)}const nt=u.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++,parseInt(window.__TEST_OPTIONS.mockID)):ne.v4(),filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:t=>t.getAttribute(`data-${this.options.attributeName}`),renderHTML:t=>({[`data-${this.options.attributeName}`]:t[this.options.attributeName]})}}}]},onCreate(){if(this.editor.extensionManager.extensions.find(s=>s.name==="collaboration"))return;const{view:t,state:e}=this.editor,{tr:n,doc:o}=e,{types:r,attributeName:a,generateID:d}=this.options;u.findChildren(o,s=>r.includes(s.type.name)&&s.attrs[a]===null).forEach(({node:s,pos:c})=>{n.setNodeMarkup(c,void 0,{...s.attrs,[a]:d()})}),n.setMeta("addToHistory",!1),t.dispatch(n)},addProseMirrorPlugins(){let t=null,e=!1;return[new g.Plugin({key:new g.PluginKey("uniqueID"),appendTransaction:(n,o,r)=>{console.log("appendTransaction");const a=n.some(y=>y.docChanged)&&!o.doc.eq(r.doc),d=this.options.filterTransaction&&n.some(y=>{var B,M;return!(!((M=(B=this.options).filterTransaction)===null||M===void 0)&&M.call(B,y))});if(!a||d)return;const{tr:i}=r,{types:s,attributeName:c,generateID:f}=this.options,h=u.combineTransactionSteps(o.doc,n),{mapping:l}=h;if(u.getChangedRanges(h).forEach(({newRange:y})=>{const B=u.findChildrenInRange(r.doc,y,T=>s.includes(T.type.name)),M=B.map(({node:T})=>T.attrs[c]).filter(T=>T!==null),v=tt(M);B.forEach(({node:T,pos:L})=>{var D;const j=(D=i.doc.nodeAt(L))===null||D===void 0?void 0:D.attrs[c];if(j===null){i.setNodeMarkup(L,void 0,{...T.attrs,[c]:f()});return}const{deleted:it}=l.invert().mapResult(L);it&&v.includes(j)&&i.setNodeMarkup(L,void 0,{...T.attrs,[c]:f()})})}),!!i.steps.length)return i},view(n){const o=r=>{var a;t=!((a=n.dom.parentElement)===null||a===void 0)&&a.contains(r.target)?n.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(n,o)=>{var r;return(t!==n.dom.parentElement||((r=o.dataTransfer)===null||r===void 0?void 0:r.effectAllowed)==="copy")&&(t=null,e=!0),!1},paste:()=>(e=!0,!1)},transformPasted:n=>{if(!e)return n;const{types:o,attributeName:r}=this.options,a=d=>{const i=[];return d.forEach(s=>{if(s.isText){i.push(s);return}if(!o.includes(s.type.name)){i.push(s.copy(a(s.content)));return}const c=s.type.create({...s.attrs,[r]:null},a(s.content),s.marks);i.push(c)}),S.Fragment.from(i)};return e=!1,new S.Slice(a(n.content),n.openStart,n.openEnd)}}})]}}),K=t=>{const e=[u.extensions.ClipboardTextSerializer,u.extensions.Commands,u.extensions.Editable,u.extensions.FocusEvents,u.extensions.Tabindex,ae.default,Xe.configure({emptyNodeClass:C.isEmpty,hasAnchorClass:C.hasAnchor,isFilterClass:C.isFilter,includeChildren:!0,showOnlyCurrent:!1}),nt.configure({types:["blockContainer"]}),de.default,ue.default,re.default,ie.default,le.default,ce.default,he.default,...Ie,se.default.configure({width:5,color:"#ddeeff"}),Q.History,Ze];return t.blockSideMenuFactory&&e.push(je.configure({blockSideMenuFactory:t.blockSideMenuFactory})),t.formattingToolbarFactory&&e.push(Pe.configure({formattingToolbarFactory:t.formattingToolbarFactory})),t.hyperlinkToolbarFactory?e.push(Je.configure({hyperlinkToolbarFactory:t.hyperlinkToolbarFactory})):e.push(U.Link),t.slashMenuFactory&&e.push(_e.configure({slashMenuFactory:t.slashMenuFactory})),e},ot={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class rt{constructor(e={}){p(this,"tiptapEditor");var a,d,i;const n=K(e.uiFactories||{});let o=e.disableHistoryExtension?n.filter(s=>s.name!=="history"):n;const r={...ot,...e,extensions:e.enableBlockNoteExtensions===!1?e.extensions:[...e.extensions||[],...o],editorProps:{attributes:{...((a=e.editorProps)==null?void 0:a.attributes)||{},class:[_.bnEditor,_.bnRoot,((i=(d=e.editorProps)==null?void 0:d.attributes)==null?void 0:i.class)||""].join(" ")}}};this.tiptapEditor=new u.Editor(r)}}m.BlockNoteEditor=rt,m.SlashMenuGroups=x,m.SlashMenuItem=E,m.getBlockNoteExtensions=K,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
2
2
|
//# sourceMappingURL=blocknote.umd.cjs.map
|