tiptap-extensions
Version:
Extensions for tiptap
14 lines (11 loc) • 23.6 kB
JavaScript
/*!
* tiptap-extensions v1.35.1
* (c) 2021 überdosis GbR (limited liability)
* @license MIT
*/
/*!
* tiptap-extensions v1.35.1
* (c) 2021 überdosis GbR (limited liability)
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tiptap"),require("tiptap-commands"),require("lowlight/lib/core"),require("prosemirror-view"),require("tiptap-utils"),require("prosemirror-model"),require("prosemirror-state"),require("prosemirror-tables"),require("prosemirror-transform"),require("prosemirror-collab"),require("prosemirror-history")):"function"==typeof define&&define.amd?define(["exports","tiptap","tiptap-commands","lowlight/lib/core","prosemirror-view","tiptap-utils","prosemirror-model","prosemirror-state","prosemirror-tables","prosemirror-transform","prosemirror-collab","prosemirror-history"],t):t((e=e||self).tiptapExtensions={},e.tiptap,e.tiptapCommands,e.low,e.prosemirrorView,e.tiptapUtils,e.prosemirrorModel,e.prosemirrorState,e.prosemirrorTables,e.prosemirrorTransform,e.prosemirrorCollab,e.prosemirrorHistory)}(this,(function(e,t,r,n,s,o,a,i,l,c,u,d){"use strict";n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;class p extends t.Node{get name(){return"blockquote"}get schema(){return{content:"block*",group:"block",defining:!0,draggable:!1,parseDOM:[{tag:"blockquote"}],toDOM:()=>["blockquote",0]}}commands({type:e}){return()=>r.toggleWrap(e)}keys({type:e}){return{"Ctrl->":r.toggleWrap(e)}}inputRules({type:e}){return[r.wrappingInputRule(/^\s*>\s$/,e)]}}class g extends t.Node{get name(){return"bullet_list"}get schema(){return{content:"list_item+",group:"block",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]}}commands({type:e,schema:t}){return()=>r.toggleList(e,t.nodes.list_item)}keys({type:e,schema:t}){return{"Shift-Ctrl-8":r.toggleList(e,t.nodes.list_item)}}inputRules({type:e}){return[r.wrappingInputRule(/^\s*([-+*])\s$/,e)]}}class h extends t.Node{get name(){return"code_block"}get schema(){return{content:"text*",marks:"",group:"block",code:!0,defining:!0,draggable:!1,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>["pre",["code",0]]}}commands({type:e,schema:t}){return()=>r.toggleBlockType(e,t.nodes.paragraph)}keys({type:e}){return{"Shift-Ctrl-\\":r.setBlockType(e)}}inputRules({type:e}){return[r.textblockTypeInputRule(/^```$/,e)]}}function m({doc:e,name:t}){const r=[],a=o.findBlockNodes(e).filter(e=>e.node.type.name===t),i=e=>e.reduce((e,t)=>e.concat(Array.isArray(t)?i(t):t),[]);return a.forEach(e=>{let t=e.pos+1;const o=n.highlightAuto(e.node.textContent).value;i(function e(t,r=[]){return t.map(t=>{const n=[...r,...t.properties?t.properties.className:[]];return t.children?e(t.children,n):{text:t.value,classes:n}})}(o)).map(e=>{const r=t,n=r+e.text.length;return t=n,{...e,from:r,to:n}}).forEach(e=>{const t=s.Decoration.inline(e.from,e.to,{class:e.classes.join(" ")});r.push(t)})}),s.DecorationSet.create(e,r)}function f({name:e}){return new t.Plugin({name:new t.PluginKey("highlight"),state:{init:(t,{doc:r})=>m({doc:r,name:e}),apply:(t,r,n,s)=>{const a=n.selection.$head.parent.type.name,i=s.selection.$head.parent.type.name,l=o.findBlockNodes(n.doc).filter(t=>t.node.type.name===e),c=o.findBlockNodes(s.doc).filter(t=>t.node.type.name===e);return t.docChanged&&([a,i].includes(e)||c.length!==l.length)?m({doc:t.doc,name:e}):r.map(t.mapping,t.doc)}},props:{decorations(e){return this.getState(e)}}})}class y extends t.Node{constructor(e={}){super(e);try{Object.entries(this.options.languages).forEach(([e,t])=>{n.registerLanguage(e,t)})}catch(e){throw new Error("Invalid syntax highlight definitions: define at least one highlight.js language mapping")}}get name(){return"code_block"}get defaultOptions(){return{languages:{}}}get schema(){return{content:"text*",marks:"",group:"block",code:!0,defining:!0,draggable:!1,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>["pre",["code",0]]}}commands({type:e,schema:t}){return()=>r.toggleBlockType(e,t.nodes.paragraph)}keys({type:e}){return{"Shift-Ctrl-\\":r.setBlockType(e)}}inputRules({type:e}){return[r.textblockTypeInputRule(/^```$/,e)]}get plugins(){return[f({name:this.name})]}}class b extends t.Node{get name(){return"hard_break"}get schema(){return{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>["br"]}}commands({type:e}){return()=>r.chainCommands(r.exitCode,(t,r)=>(r(t.tr.replaceSelectionWith(e.create()).scrollIntoView()),!0))}keys({type:e}){const t=r.chainCommands(r.exitCode,(t,r)=>(r(t.tr.replaceSelectionWith(e.create()).scrollIntoView()),!0));return{"Mod-Enter":t,"Shift-Enter":t}}}class x extends t.Node{get name(){return"heading"}get defaultOptions(){return{levels:[1,2,3,4,5,6]}}get schema(){return{attrs:{level:{default:1}},content:"inline*",group:"block",defining:!0,draggable:!1,parseDOM:this.options.levels.map(e=>({tag:"h"+e,attrs:{level:e}})),toDOM:e=>["h"+e.attrs.level,0]}}commands({type:e,schema:t}){return n=>r.toggleBlockType(e,t.nodes.paragraph,n)}keys({type:e}){return this.options.levels.reduce((t,n)=>({...t,["Shift-Ctrl-"+n]:r.setBlockType(e,{level:n})}),{})}inputRules({type:e}){return this.options.levels.map(t=>r.textblockTypeInputRule(new RegExp(`^(#{1,${t}})\\s$`),e,()=>({level:t})))}}class k extends t.Node{get name(){return"horizontal_rule"}get schema(){return{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>["hr"]}}commands({type:e}){return()=>(t,r)=>r(t.tr.replaceSelectionWith(e.create()))}inputRules({type:e}){return[r.nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/,e)]}}const w=/!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/;class M extends t.Node{get name(){return"image"}get schema(){return{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs:e=>({src:e.getAttribute("src"),title:e.getAttribute("title"),alt:e.getAttribute("alt")})}],toDOM:e=>["img",e.attrs]}}commands({type:e}){return t=>(r,n)=>{const{selection:s}=r,o=s.$cursor?s.$cursor.pos:s.$to.pos,a=e.create(t);n(r.tr.insert(o,a))}}inputRules({type:e}){return[r.nodeInputRule(w,e,e=>{const[,t,r,n]=e;return{src:r,alt:t,title:n}})]}get plugins(){return[new t.Plugin({props:{handleDOMEvents:{drop(e,t){if(!(t.dataTransfer&&t.dataTransfer.files&&t.dataTransfer.files.length))return;const r=Array.from(t.dataTransfer.files).filter(e=>/image/i.test(e.type));if(0===r.length)return;t.preventDefault();const{schema:n}=e.state,s=e.posAtCoords({left:t.clientX,top:t.clientY});r.forEach(t=>{const r=new FileReader;r.onload=t=>{const r=n.nodes.image.create({src:t.target.result}),o=e.state.tr.insert(s.pos,r);e.dispatch(o)},r.readAsDataURL(t)})}}}})]}}class C extends t.Node{get name(){return"list_item"}get schema(){return{content:"paragraph block*",defining:!0,draggable:!1,parseDOM:[{tag:"li"}],toDOM:()=>["li",0]}}keys({type:e}){return{Enter:r.splitListItem(e),Tab:r.sinkListItem(e),"Shift-Tab":r.liftListItem(e)}}}function D({char:e="@",allowSpaces:t=!1,startOfLine:r=!1}){return n=>{if(n.depth<=0)return!1;const s="\\"+e,o=new RegExp(`\\s${s}$`),a=r?"^":"",i=t?new RegExp(`${a}${s}.*?(?=\\s${s}|$)`,"gm"):new RegExp(`${a}(?:^)?${s}[^\\s${s}]*`,"gm"),l=n.before(),c=n.end(),u=function(e,t,r,n,s,o="\0"){let a="",i=!0,l=null;return e.content.nodesBetween(t,r,(e,c)=>{if(e.isText){if(l)return void(l=null);a+=e.text.slice(Math.max(t,c)-c,r-c),i=!n}else e.isLeaf&&o?(a+=o,i=!n):e.isInline&&!e.isLeaf?(a+=s,e.textContent&&(a+=e.textContent,l=e),a+=s,i=!i):!i&&e.isBlock&&(a+=n,i=!0)},0),a}(n.doc,l,c,"\0","\0");let d,p=i.exec(u);for(;null!==p;){const r=p.input.slice(Math.max(0,p.index-1),p.index);if(/^[\s\0]?$/.test(r)){const r=p.index+n.start();let s=r+p[0].length;t&&o.test(u.slice(s-1,s+1))&&(p[0]+=" ",s+=1),r<n.pos&&s>=n.pos&&(d={range:{from:r,to:s},query:p[0].slice(e.length),text:p[0]})}p=i.exec(u)}return d}}function O({matcher:e={char:"@",allowSpaces:!1,startOfLine:!1},appendText:t=null,suggestionClass:n="suggestion",command:o=(()=>!1),items:a=[],onEnter:l=(()=>!1),onChange:c=(()=>!1),onExit:u=(()=>!1),onKeyDown:d=(()=>!1),onFilter:p=((e,t)=>t?e.filter(e=>JSON.stringify(e).toLowerCase().includes(t.toLowerCase())):e)}){return new i.Plugin({key:new i.PluginKey("suggestions"),view(){return{update:async(e,n)=>{const s=this.key.getState(n),i=this.key.getState(e.state),d=s.active&&i.active&&s.range.from!==i.range.from,g=!s.active&&i.active,h=s.active&&!i.active,m=g||d,f=!g&&!h&&s.query!==i.query&&!d,y=h||d;if(!m&&!f&&!y)return;const b=y?s:i,x=document.querySelector(`[data-decoration-id="${b.decorationId}"]`),k=x?{getBoundingClientRect:()=>x.getBoundingClientRect(),clientWidth:x.clientWidth,clientHeight:x.clientHeight}:null,w={view:e,range:b.range,query:b.query,text:b.text,decorationNode:x,virtualNode:k,items:f||m?await p(Array.isArray(a)?a:await a(),b.query):[],command:({range:n,attrs:s})=>{o({range:n,attrs:s,schema:e.state.schema})(e.state,e.dispatch,e),t&&r.insertText(t)(e.state,e.dispatch,e)}};y&&u(w),f&&c(w),m&&l(w)}}},state:{init:()=>({active:!1,range:{},query:null,text:null}),apply(t,r){const{selection:n}=t,s={...r};if(n.from===n.to){(n.from<r.range.from||n.from>r.range.to)&&(s.active=!1);const t=n.$from,o=D(e)(t),a=(Math.random()+1).toString(36).substr(2,5);o?(s.active=!0,s.decorationId=r.decorationId?r.decorationId:a,s.range=o.range,s.query=o.query,s.text=o.text):s.active=!1}else s.active=!1;return s.active||(s.decorationId=null,s.range={},s.query=null,s.text=null),s}},props:{handleKeyDown(e,t){const{active:r,range:n}=this.getState(e.state);return!!r&&d({view:e,event:t,range:n})},decorations(e){const{active:t,range:r,decorationId:o}=this.getState(e);return t?s.DecorationSet.create(e.doc,[s.Decoration.inline(r.from,r.to,{nodeName:"span",class:n,"data-decoration-id":o})]):null}}})}class S extends t.Node{get name(){return"mention"}get defaultOptions(){return{matcher:{char:"@",allowSpaces:!1,startOfLine:!1},mentionClass:"mention",suggestionClass:"mention-suggestion"}}getLabel(e){return e.innerText.split(this.options.matcher.char).join("")}createFragment(e,t){return a.Fragment.fromJSON(e,[{type:"text",text:`${this.options.matcher.char}${t}`}])}insertMention(e,t,n){const s=n.nodes[this.name],o=this.createFragment(n,t.label);return r.replaceText(e,s,t,o)}get schema(){return{attrs:{id:{},label:{}},group:"inline",inline:!0,content:"text*",selectable:!1,atom:!0,toDOM:e=>["span",{class:this.options.mentionClass,"data-mention-id":e.attrs.id},`${this.options.matcher.char}${e.attrs.label}`],parseDOM:[{tag:"span[data-mention-id]",getAttrs:e=>({id:e.getAttribute("data-mention-id"),label:this.getLabel(e)}),getContent:(e,t)=>{const r=this.getLabel(e);return this.createFragment(t,r)}}]}}commands({schema:e}){return t=>this.insertMention(null,t,e)}get plugins(){return[O({command:({range:e,attrs:t,schema:r})=>this.insertMention(e,t,r),appendText:" ",matcher:this.options.matcher,items:this.options.items,onEnter:this.options.onEnter,onChange:this.options.onChange,onExit:this.options.onExit,onKeyDown:this.options.onKeyDown,onFilter:this.options.onFilter,suggestionClass:this.options.suggestionClass})]}}class R extends t.Node{get name(){return"ordered_list"}get schema(){return{attrs:{order:{default:1}},content:"list_item+",group:"block",parseDOM:[{tag:"ol",getAttrs:e=>({order:e.hasAttribute("start")?+e.getAttribute("start"):1})}],toDOM:e=>1===e.attrs.order?["ol",0]:["ol",{start:e.attrs.order},0]}}commands({type:e,schema:t}){return()=>r.toggleList(e,t.nodes.list_item)}keys({type:e,schema:t}){return{"Shift-Ctrl-9":r.toggleList(e,t.nodes.list_item)}}inputRules({type:e}){return[r.wrappingInputRule(/^(\d+)\.\s$/,e,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order===+e[1])]}}var T=l.tableNodes({tableGroup:"block",cellContent:"block+",cellAttributes:{background:{default:null,getFromDOM:e=>e.style.backgroundColor||null,setDOMAttr(e,t){if(e){const r={style:`${t.style||""}background-color: ${e};`};Object.assign(t,r)}}}}});class v extends t.Node{get name(){return"table"}get defaultOptions(){return{resizable:!1}}get schema(){return T.table}commands({schema:e}){return{createTable:({rowsCount:t,colsCount:r,withHeaderRow:n})=>(s,a)=>{const l=s.tr.selection.anchor+1,c=o.createTable(e,t,r,n),u=s.tr.replaceSelectionWith(c).scrollIntoView(),d=u.doc.resolve(l);u.setSelection(i.TextSelection.near(d)),a(u)},addColumnBefore:()=>l.addColumnBefore,addColumnAfter:()=>l.addColumnAfter,deleteColumn:()=>l.deleteColumn,addRowBefore:()=>l.addRowBefore,addRowAfter:()=>l.addRowAfter,deleteRow:()=>l.deleteRow,deleteTable:()=>l.deleteTable,toggleCellMerge:()=>(e,t)=>{l.mergeCells(e,t)||l.splitCell(e,t)},mergeCells:()=>l.mergeCells,splitCell:()=>l.splitCell,toggleHeaderColumn:()=>l.toggleHeaderColumn,toggleHeaderRow:()=>l.toggleHeaderRow,toggleHeaderCell:()=>l.toggleHeaderCell,setCellAttr:({name:e,value:t})=>l.setCellAttr(e,t),fixTables:()=>l.fixTables}}keys(){return{Tab:l.goToNextCell(1),"Shift-Tab":l.goToNextCell(-1)}}get plugins(){return[...this.options.resizable?[l.columnResizing()]:[],l.tableEditing()]}}class _ extends t.Node{get name(){return"table_header"}get schema(){return T.table_header}}class A extends t.Node{get name(){return"table_cell"}get schema(){return T.table_cell}}class N extends t.Node{get name(){return"table_row"}get schema(){return T.table_row}}class $ extends t.Node{get name(){return"todo_item"}get defaultOptions(){return{nested:!1}}get view(){return{props:["node","updateAttrs","view"],methods:{onChange(){this.updateAttrs({done:!this.node.attrs.done})}},template:'\n <li :data-type="node.type.name" :data-done="node.attrs.done.toString()" data-drag-handle>\n <span class="todo-checkbox" contenteditable="false" @click="onChange"></span>\n <div class="todo-content" ref="content" :contenteditable="view.editable.toString()"></div>\n </li>\n '}}get schema(){return{attrs:{done:{default:!1}},draggable:!0,content:this.options.nested?"(paragraph|todo_list)+":"paragraph+",toDOM:e=>{const{done:t}=e.attrs;return["li",{"data-type":this.name,"data-done":t.toString()},["span",{class:"todo-checkbox",contenteditable:"false"}],["div",{class:"todo-content"},0]]},parseDOM:[{priority:51,tag:`[data-type="${this.name}"]`,getAttrs:e=>({done:"true"===e.getAttribute("data-done")})}]}}keys({type:e}){return{Enter:r.splitToDefaultListItem(e),Tab:this.options.nested?r.sinkListItem(e):()=>{},"Shift-Tab":r.liftListItem(e)}}}class I extends t.Node{get name(){return"todo_list"}get schema(){return{group:"block",content:"todo_item+",toDOM:()=>["ul",{"data-type":this.name},0],parseDOM:[{priority:51,tag:`[data-type="${this.name}"]`}]}}commands({type:e,schema:t}){return()=>r.toggleList(e,t.nodes.todo_item)}inputRules({type:e}){return[r.wrappingInputRule(/^\s*(\[ \])\s$/,e)]}}class E extends t.Mark{get name(){return"bold"}get schema(){return{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:e=>"normal"!==e.style.fontWeight&&null},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:()=>["strong",0]}}keys({type:e}){return{"Mod-b":r.toggleMark(e)}}commands({type:e}){return()=>r.toggleMark(e)}inputRules({type:e}){return[r.markInputRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/,e)]}pasteRules({type:e}){return[r.markPasteRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)/g,e)]}}class L extends t.Mark{get name(){return"code"}get schema(){return{excludes:"_",parseDOM:[{tag:"code"}],toDOM:()=>["code",0]}}keys({type:e}){return{"Mod-`":r.toggleMark(e)}}commands({type:e}){return()=>r.toggleMark(e)}inputRules({type:e}){return[r.markInputRule(/(?:`)([^`]+)(?:`)$/,e)]}pasteRules({type:e}){return[r.markPasteRule(/(?:`)([^`]+)(?:`)/g,e)]}}class q extends t.Mark{get name(){return"italic"}get schema(){return{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]}}keys({type:e}){return{"Mod-i":r.toggleMark(e)}}commands({type:e}){return()=>r.toggleMark(e)}inputRules({type:e}){return[r.markInputRule(/(?:^|[^_])(_([^_]+)_)$/,e),r.markInputRule(/(?:^|[^*])(\*([^*]+)\*)$/,e)]}pasteRules({type:e}){return[r.markPasteRule(/_([^_]+)_/g,e),r.markPasteRule(/\*([^*]+)\*/g,e)]}}class B extends t.Mark{get name(){return"link"}get defaultOptions(){return{openOnClick:!0,target:null}}get schema(){return{attrs:{href:{default:null},target:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:e=>({href:e.getAttribute("href"),target:e.getAttribute("target")})}],toDOM:e=>["a",{...e.attrs,rel:"noopener noreferrer nofollow",target:e.attrs.target||this.options.target},0]}}commands({type:e}){return t=>t.href?r.updateMark(e,t):r.removeMark(e)}pasteRules({type:e}){return[r.pasteRule(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b([-a-zA-Z0-9@:%_+.~#?&//=,()!]*)/gi,e,e=>({href:e}))]}get plugins(){return this.options.openOnClick?[new t.Plugin({props:{handleClick:(e,t,r)=>{const{schema:n}=e.state,s=o.getMarkAttrs(e.state,n.marks.link);s.href&&r.target instanceof HTMLAnchorElement&&(r.stopPropagation(),window.open(s.href,s.target))}}})]:[]}}class P extends t.Mark{get name(){return"strike"}get schema(){return{parseDOM:[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",getAttrs:e=>"line-through"===e}],toDOM:()=>["s",0]}}keys({type:e}){return{"Mod-d":r.toggleMark(e)}}commands({type:e}){return()=>r.toggleMark(e)}inputRules({type:e}){return[r.markInputRule(/~([^~]+)~$/,e)]}pasteRules({type:e}){return[r.markPasteRule(/~([^~]+)~/g,e)]}}class H extends t.Mark{get name(){return"underline"}get schema(){return{parseDOM:[{tag:"u"},{style:"text-decoration",getAttrs:e=>"underline"===e}],toDOM:()=>["u",0]}}keys({type:e}){return{"Mod-u":r.toggleMark(e)}}commands({type:e}){return()=>r.toggleMark(e)}}class z extends t.Extension{get name(){return"collaboration"}init(){this.getSendableSteps=this.debounce(e=>{const t=u.sendableSteps(e);t&&this.options.onSendable({editor:this.editor,sendable:{version:t.version,steps:t.steps.map(e=>e.toJSON()),clientID:t.clientID}})},this.options.debounce),this.editor.on("transaction",({state:e})=>{this.getSendableSteps(e)})}get defaultOptions(){return{version:0,clientID:Math.floor(4294967295*Math.random()),debounce:250,onSendable:()=>{},update:({steps:e,version:t})=>{const{state:r,view:n,schema:s}=this.editor;u.getVersion(r)>t||n.dispatch(u.receiveTransaction(r,e.map(e=>c.Step.fromJSON(s,e.step)),e.map(e=>e.clientID)))}}}get plugins(){return[u.collab({version:this.options.version,clientID:this.options.clientID})]}debounce(e,t){let r;return function(...n){r&&clearTimeout(r),r=setTimeout(()=>{e(...n),r=null},t)}}}class W extends t.Extension{get name(){return"focus"}get defaultOptions(){return{className:"has-focus",nested:!1}}get plugins(){return[new t.Plugin({props:{decorations:({doc:e,plugins:t,selection:r})=>{const n=t.find(e=>e.key.startsWith("editable$")).props.editable()&&this.options.className,{focused:o}=this.editor,{anchor:a}=r,i=[];return!(!n||!o)&&(e.descendants((e,t)=>{if(a>=t&&a<=t+e.nodeSize&&!e.isText){const r=s.Decoration.node(t,t+e.nodeSize,{class:this.options.className});i.push(r)}return this.options.nested}),s.DecorationSet.create(e,i))}}})]}}class j extends t.Extension{get name(){return"history"}get defaultOptions(){return{depth:"",newGroupDelay:""}}keys(){return{"Mod-z":d.undo,"Mod-y":d.redo,"Shift-Mod-z":d.redo,"Mod-\u044f":d.undo,"Shift-Mod-\u044f":d.redo}}get plugins(){return[d.history({depth:this.options.depth,newGroupDelay:this.options.newGroupDelay})]}commands(){return{undo:()=>d.undo,redo:()=>d.redo,undoDepth:()=>d.undoDepth,redoDepth:()=>d.redoDepth}}}class F extends t.Extension{get name(){return"placeholder"}get defaultOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",emptyNodeText:"Write something \u2026",showOnlyWhenEditable:!0,showOnlyCurrent:!0}}get plugins(){return[new t.Plugin({props:{decorations:({doc:e,plugins:t,selection:r})=>{const n=t.find(e=>e.key.startsWith("editable$")).props.editable()||!this.options.showOnlyWhenEditable,{anchor:o}=r,a=[],i=0===e.textContent.length;return!!n&&(e.descendants((e,t)=>{const r=o>=t&&o<=t+e.nodeSize,n=0===e.content.size;if((r||!this.options.showOnlyCurrent)&&n){const r=[this.options.emptyNodeClass];i&&r.push(this.options.emptyEditorClass);const n=s.Decoration.node(t,t+e.nodeSize,{class:r.join(" "),"data-empty-text":"function"==typeof this.options.emptyNodeText?this.options.emptyNodeText(e):this.options.emptyNodeText});a.push(n)}return!1}),s.DecorationSet.create(e,a))}}})]}}class V extends t.Extension{constructor(e={}){super(e),this.results=[],this.searchTerm=null,this._updating=!1}get name(){return"search"}get defaultOptions(){return{autoSelectNext:!0,findClass:"find",searching:!1,caseSensitive:!1,disableRegex:!0,alwaysSearch:!1}}commands(){return{find:e=>this.find(e),replace:e=>this.replace(e),replaceAll:e=>this.replaceAll(e),clearSearch:()=>this.clear()}}get findRegExp(){return RegExp(this.searchTerm,this.options.caseSensitive?"gu":"gui")}get decorations(){return this.results.map(e=>s.Decoration.inline(e.from,e.to,{class:this.options.findClass}))}_search(e){this.results=[];const t=[];let r=0;this.searchTerm&&(e.descendants((e,n)=>{e.isText?t[r]?t[r]={text:t[r].text+e.text,pos:t[r].pos}:t[r]={text:e.text,pos:n}:r+=1}),t.forEach(({text:e,pos:t})=>{const r=this.findRegExp;let n;for(;(n=r.exec(e))&&""!==n[0];)this.results.push({from:t+n.index,to:t+n.index+n[0].length})}))}replace(e){return(t,r)=>{if(!this.results[0])return;const{from:n,to:s}=this.results[0];r(t.tr.insertText(e,n,s)),this.editor.commands.find(this.searchTerm)}}rebaseNextResult(e,t,r=0){const n=t+1;if(!this.results[n])return null;const{from:s,to:o}=this.results[t],a=o-s-e.length+r,{from:i,to:l}=this.results[n];return this.results[n]={to:l-a,from:i-a},a}replaceAll(e){return({tr:t},r)=>{let n;this.results.length&&(this.results.forEach(({from:r,to:s},o)=>{t.insertText(e,r,s),n=this.rebaseNextResult(e,o,n)}),r(t),this.editor.commands.find(this.searchTerm))}}find(e){return(t,r)=>{this.searchTerm=this.options.disableRegex?e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"):e,this.updateView(t,r)}}clear(){return(e,t)=>{this.searchTerm=null,this.updateView(e,t)}}updateView({tr:e},t){this._updating=!0,t(e),this._updating=!1}createDeco(e){return this._search(e),this.decorations?s.DecorationSet.create(e,this.decorations):[]}get plugins(){return[new t.Plugin({state:{init:()=>s.DecorationSet.empty,apply:(e,t)=>this._updating||this.options.searching||e.docChanged&&this.options.alwaysSearch?this.createDeco(e.doc):e.docChanged?t.map(e.mapping,e.doc):t},props:{decorations(e){return this.getState(e)}}})]}}class K extends t.Extension{get name(){return"trailing_node"}get defaultOptions(){return{node:"paragraph",notAfter:["paragraph"]}}get plugins(){const e=new t.PluginKey(this.name),r=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>this.options.notAfter.includes(e.name));return[new t.Plugin({key:e,view:()=>({update:t=>{const{state:r}=t;if(!e.getState(r))return;const{doc:n,schema:s,tr:o}=r,a=s.nodes[this.options.node],i=o.insert(n.content.size,a.create());t.dispatch(i)}}),state:{init:(e,t)=>{const n=t.tr.doc.lastChild;return!o.nodeEqualsType({node:n,types:r})},apply:(e,t)=>{if(!e.docChanged)return t;const n=e.doc.lastChild;return!o.nodeEqualsType({node:n,types:r})}}})]}}e.Blockquote=p,e.Bold=E,e.BulletList=g,e.Code=L,e.CodeBlock=h,e.CodeBlockHighlight=y,e.Collaboration=z,e.Focus=W,e.HardBreak=b,e.Heading=x,e.Highlight=f,e.History=j,e.HorizontalRule=k,e.Image=M,e.Italic=q,e.Link=B,e.ListItem=C,e.Mention=S,e.OrderedList=R,e.Placeholder=F,e.Search=V,e.Strike=P,e.Suggestions=O,e.Table=v,e.TableCell=A,e.TableHeader=_,e.TableRow=N,e.TodoItem=$,e.TodoList=I,e.TrailingNode=K,e.Underline=H,Object.defineProperty(e,"__esModule",{value:!0})}));