UNPKG

vue-simple-tiptap-editor

Version:

A lightweight Vue 3 wrapper around **Tiptap**, designed for simplicity and flexibility. ---

13 lines (12 loc) 36.1 kB
(function(c,v){typeof exports=="object"&&typeof module<"u"?module.exports=v(require("vue"),require("@tiptap/vue-3"),require("axios"),require("lowlight"),require("@tiptap/core"),require("@tiptap/extension-text-style"),require("@tiptap/starter-kit"),require("@tiptap/extension-code-block-lowlight"),require("@tiptap/extension-file-handler"),require("@tiptap/extension-text-align"),require("@tiptap/extension-image"),require("@tiptap/extension-heading"),require("@tiptap/extension-link")):typeof define=="function"&&define.amd?define(["vue","@tiptap/vue-3","axios","lowlight","@tiptap/core","@tiptap/extension-text-style","@tiptap/starter-kit","@tiptap/extension-code-block-lowlight","@tiptap/extension-file-handler","@tiptap/extension-text-align","@tiptap/extension-image","@tiptap/extension-heading","@tiptap/extension-link"],v):(c=typeof globalThis<"u"?globalThis:c||self,c["vue-simple-tiptap-editor"]=v(c.Vue,c.vue3,c.axios,c.lowlight,c.core,c.extensionTextStyle,c.StarterKit,c.CodeBlockLowlight,c.FileHandler,c.TextAlign,c.Image,c.Heading,c.Link))})(this,(function(c,v,A,C,p,w,V,_,P,D,q,F,K){"use strict";function z(e,t,n,s){return c.computed(()=>[{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x-icon lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',title:"clear",action:()=>{t()&&(e.value.chain().focus().unsetAllMarks().run(),e.value.chain().focus().clearNodes().run())}},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-bold-icon lucide-bold"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/></svg>',title:"Bold",action:()=>t()&&e.value.chain().focus().toggleBold().run(),active:()=>t()&&e.value.isActive("bold")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-italic-icon lucide-italic"><line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/></svg>',title:"Italic",action:()=>t()&&e.value.chain().focus().toggleItalic().run(),active:()=>t()&&e.value.isActive("italic")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-strikethrough-icon lucide-strikethrough"><path d="M16 4H9a3 3 0 0 0-2.83 4"/><path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/></svg>',title:"Strike",action:()=>t()&&e.value.chain().focus().toggleStrike().run(),active:()=>t()&&e.value.isActive("strike")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-xml-icon lucide-code-xml"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>',title:"Code",action:()=>t()&&e.value.chain().focus().toggleCode().run(),active:()=>t()&&e.value.isActive("code")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pilcrow-icon lucide-pilcrow"><path d="M13 4v16"/><path d="M17 4v16"/><path d="M19 4H9.5a4.5 4.5 0 0 0 0 9H13"/></svg>',title:"Code Block",action:()=>t()&&e.value.chain().focus().setParagraph().run(),active:()=>t()&&e.value.isActive("paragraph")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heading-icon lucide-heading"><path d="M6 12h12"/><path d="M6 20V4"/><path d="M18 20V4"/></svg>',title:"Heading 1",action:()=>t()&&e.value.chain().focus().toggleHeading({level:1}).run(),active:()=>t()&&e.value.isActive("heading",{level:1})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heading2-icon lucide-heading-2"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>',title:"Heading 2",action:()=>t()&&e.value.chain().focus().toggleHeading({level:2}).run(),active:()=>t()&&e.value.isActive("heading",{level:2})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heading3-icon lucide-heading-3"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"/><path d="M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"/></svg>',title:"Heading 3",action:()=>t()&&e.value.chain().focus().toggleHeading({level:3}).run(),active:()=>t()&&e.value.isActive("heading",{level:3})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heading4-icon lucide-heading-4"><path d="M12 18V6"/><path d="M17 10v3a1 1 0 0 0 1 1h3"/><path d="M21 10v8"/><path d="M4 12h8"/><path d="M4 18V6"/></svg>',title:"Heading 4",action:()=>t()&&e.value.chain().focus().toggleHeading({level:4}).run(),active:()=>t()&&e.value.isActive("heading",{level:4})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heading5-icon lucide-heading-5"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 13v-3h4"/><path d="M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17"/></svg>',title:"Heading 5",action:()=>t()&&e.value.chain().focus().toggleHeading({level:5}).run(),active:()=>t()&&e.value.isActive("heading",{level:5})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-heading6-icon lucide-heading-6"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><circle cx="19" cy="16" r="2"/><path d="M20 10c-2 2-3 3.5-3 6"/></svg>',title:"Heading 6",action:()=>t()&&e.value.chain().focus().toggleHeading({level:6}).run(),active:()=>t()&&e.value.isActive("heading",{level:6})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-list-ordered-icon lucide-list-ordered"><path d="M11 5h10"/><path d="M11 12h10"/><path d="M11 19h10"/><path d="M4 4h1v5"/><path d="M4 9h2"/><path d="M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02"/></svg>',title:"Ordered List",action:()=>t()&&e.value.chain().focus().toggleOrderedList().run(),active:()=>t()&&e.value.isActive("orderedList")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-list-icon lucide-list"><path d="M3 5h.01"/><path d="M3 12h.01"/><path d="M3 19h.01"/><path d="M8 5h13"/><path d="M8 12h13"/><path d="M8 19h13"/></svg>',title:"Bullet List",action:()=>t()&&e.value.chain().focus().toggleBulletList().run(),active:()=>t()&&e.value.isActive("bulletList")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-code-corner-icon lucide-file-code-corner"><path d="M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="m5 16-3 3 3 3"/><path d="m9 22 3-3-3-3"/></svg>',title:"Code Block",action:()=>t()&&e.value.chain().focus().toggleCodeBlock().run(),active:()=>t()&&e.value.isActive("codeBlock")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-message-square-quote-icon lucide-message-square-quote"><path d="M14 14a2 2 0 0 0 2-2V8h-2"/><path d="M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"/><path d="M8 14a2 2 0 0 0 2-2V8H8"/></svg>',title:"Block Quote",action:()=>t()&&e.value.chain().focus().toggleBlockquote().run(),active:()=>t()&&e.value.isActive("blockquote")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-undo-icon lucide-undo"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',title:"Undo",action:()=>t()&&e.value.chain().focus().undo().run(),disabled:()=>t()&&!e.value.can().chain().focus().undo().run()},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-redo-icon lucide-redo"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"/></svg>',title:"Redo",action:()=>t()&&e.value.chain().focus().redo().run(),disabled:()=>t()&&!e.value.can().chain().focus().redo().run()},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-image-icon lucide-image"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',title:"Add Image",action:()=>t()&&n()},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link-icon lucide-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',title:"Link",action:()=>t()&&s(),active:()=>t()&&e.value.isActive("link")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-unlink-icon lucide-unlink"><path d="m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71"/><path d="m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71"/><line x1="8" x2="8" y1="2" y2="5"/><line x1="2" x2="5" y1="8" y2="8"/><line x1="16" x2="16" y1="19" y2="22"/><line x1="19" x2="22" y1="16" y2="16"/></svg>',title:"Unset Link",action:()=>t()&&e.value.chain().focus().unsetLink().run(),disabled:()=>t()&&!e.value.isActive("link")},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-text-align-start-icon lucide-text-align-start"><path d="M21 5H3"/><path d="M15 12H3"/><path d="M17 19H3"/></svg>',title:"Align Left",action:()=>t()&&e.value.chain().focus().setTextAlign("left").run(),active:()=>t()&&e.value.isActive({textAlign:"left"})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-text-align-center-icon lucide-text-align-center"><path d="M21 5H3"/><path d="M17 12H7"/><path d="M19 19H5"/></svg>',title:"Align Center",action:()=>t()&&e.value.chain().focus().setTextAlign("center").run(),active:()=>t()&&e.value.isActive({textAlign:"center"})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-text-align-end-icon lucide-text-align-end"><path d="M21 5H3"/><path d="M21 12H9"/><path d="M21 19H7"/></svg>',title:"Align Right",action:()=>t()&&e.value.chain().focus().setTextAlign("right").run(),active:()=>t()&&e.value.isActive({textAlign:"right"})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-text-align-justify-icon lucide-text-align-justify"><path d="M3 5h18"/><path d="M3 12h18"/><path d="M3 19h18"/></svg>',title:"Justify",action:()=>t()&&e.value.chain().focus().setTextAlign("justify").run(),active:()=>t()&&e.value.isActive({textAlign:"justify"})},{label:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-list-x-icon lucide-list-x"><path d="M16 5H3"/><path d="M11 12H3"/><path d="M16 19H3"/><path d="m15.5 9.5 5 5"/><path d="m20.5 9.5-5 5"/></svg>',title:"Unset Alignment",action:()=>t()&&e.value.chain().focus().unsetTextAlign().run()}])}function X(e,t,n){const s=c.shallowRef(new Set),i=c.shallowRef(new Map);async function a(r){if(!t.uploadUrl)throw new Error("uploadUrl prop is not set");const h=new FormData;h.append("file",r),n("upload-start",r);try{const o=(await A.post(t.uploadUrl,h,{headers:{...t.headers,"Content-Type":"multipart/form-data"}})).data,l=o.url||o.path||o.data?.url;if(!l)throw new Error("Upload response did not include url");return n("upload-success",l,r),l}catch(d){throw n("upload-error",d,r),d}}function u(){const r=document.createElement("input");r.type="file",r.accept="image/*",r.multiple=!0,r.onchange=async()=>{const h=Array.from(r.files);for(const d of h){if(t.uploadOnInsert)if(!t.uploadUrl)console.warn("uploadOnInsert is true but uploadUrl is not provided");else{const g=URL.createObjectURL(d);e.value.chain().focus().insertContentAt(e.value.state.selection.anchor,{type:"image",attrs:{src:g,"data-uploading":"true"}}).run();const f=a(d).then(m=>{e.value.chain().focus().updateAttributes("image",{src:m,"data-uploading":null}).run(),s.value.add(m),i.value.delete(g)}).catch(m=>{console.error("upload failed",m),i.value.delete(g)});i.value.set(g,f);continue}const o=e.value.state.selection.anchor;e.value.chain().focus().insertContentAt(o,"Loading...").run();const l=URL.createObjectURL(d);e.value.chain().focus().insertContentAt(e.value.state.selection.anchor,{type:"image",attrs:{src:l}}).run(),e.value.chain().focus().deleteRange({from:o,to:o+10}).run()}},r.click()}return{uploadFile:a,addImage:u,uploadedImages:s,pendingUploads:i}}var G=Object.defineProperty,W=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},J="listItem",I="textStyle",T=/^\s*([-+*])\s$/,Q=p.Node.create({name:"bulletList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:"ul"}]},renderHTML({HTMLAttributes:e}){return["ul",p.mergeAttributes(this.options.HTMLAttributes,e),0]},markdownTokenName:"list",parseMarkdown:(e,t)=>e.type!=="list"||e.ordered?[]:{type:"bulletList",content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` `):"",markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(J,this.editor.getAttributes(I)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=p.wrappingInputRule({find:T,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=p.wrappingInputRule({find:T,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(I),editor:this.editor})),[e]}}),x=p.Node.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:e}){return["li",p.mergeAttributes(this.options.HTMLAttributes,e),0]},markdownTokenName:"list_item",parseMarkdown:(e,t)=>{if(e.type!=="list_item")return[];let n=[];if(e.tokens&&e.tokens.length>0)if(e.tokens.some(i=>i.type==="paragraph"))n=t.parseChildren(e.tokens);else{const i=e.tokens[0];if(i&&i.type==="text"&&i.tokens&&i.tokens.length>0){if(n=[{type:"paragraph",content:t.parseInline(i.tokens)}],e.tokens.length>1){const u=e.tokens.slice(1),r=t.parseChildren(u);n.push(...r)}}else n=t.parseChildren(e.tokens)}return n.length===0&&(n=[{type:"paragraph",content:[]}]),{type:"listItem",content:n}},renderMarkdown:(e,t,n)=>p.renderNestedMarkdownContent(e,t,s=>s.parentType==="bulletList"?"- ":s.parentType==="orderedList"?`${s.index+1}. `:"- ",n),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),Y={};W(Y,{findListItemPos:()=>k,getNextListDepth:()=>b,handleBackspace:()=>L,handleDelete:()=>M,hasListBefore:()=>H,hasListItemAfter:()=>Z,hasListItemBefore:()=>B,listItemHasSubList:()=>N,nextListIsDeeper:()=>j,nextListIsHigher:()=>E});var k=(e,t)=>{const{$from:n}=t.selection,s=p.getNodeType(e,t.schema);let i=null,a=n.depth,u=n.pos,r=null;for(;a>0&&r===null;)i=n.node(a),i.type===s?r=a:(a-=1,u-=1);return r===null?null:{$pos:t.doc.resolve(u),depth:r}},b=(e,t)=>{const n=k(e,t);if(!n)return!1;const[,s]=p.getNodeAtPosition(t,e,n.$pos.pos+4);return s},H=(e,t,n)=>{const{$anchor:s}=e.selection,i=Math.max(0,s.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},B=(e,t)=>{var n;const{$anchor:s}=t.selection,i=t.doc.resolve(s.pos-2);return!(i.index()===0||((n=i.nodeBefore)==null?void 0:n.type.name)!==e)},N=(e,t,n)=>{if(!n)return!1;const s=p.getNodeType(e,t.schema);let i=!1;return n.descendants(a=>{a.type===s&&(i=!0)}),i},L=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!p.isNodeActive(e.state,t)&&H(e.state,t,n)){const{$anchor:r}=e.state.selection,h=e.state.doc.resolve(r.before()-1),d=[];h.node().descendants((g,f)=>{g.type.name===t&&d.push({node:g,pos:f})});const o=d.at(-1);if(!o)return!1;const l=e.state.doc.resolve(h.start()+o.pos+1);return e.chain().cut({from:r.start()-1,to:r.end()+1},l.end()).joinForward().run()}if(!p.isNodeActive(e.state,t)||!p.isAtStartOfNode(e.state))return!1;const s=k(t,e.state);if(!s)return!1;const a=e.state.doc.resolve(s.$pos.pos-2).node(s.depth),u=N(t,e.state,a);return B(t,e.state)&&!u?e.commands.joinItemBackward():e.chain().liftListItem(t).run()},j=(e,t)=>{const n=b(e,t),s=k(e,t);return!s||!n?!1:n>s.depth},E=(e,t)=>{const n=b(e,t),s=k(e,t);return!s||!n?!1:n<s.depth},M=(e,t)=>{if(!p.isNodeActive(e.state,t)||!p.isAtEndOfNode(e.state,t))return!1;const{selection:n}=e.state,{$from:s,$to:i}=n;return!n.empty&&s.sameParent(i)?!1:j(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():E(t,e.state)?e.chain().joinForward().joinBackward().run():e.commands.joinItemForward()},Z=(e,t)=>{var n;const{$anchor:s}=t.selection,i=t.doc.resolve(s.pos-s.parentOffset-2);return!(i.index()===i.parent.childCount-1||((n=i.nodeAfter)==null?void 0:n.type.name)!==e)},R=p.Extension.create({name:"listKeymap",addOptions(){return{listTypes:[{itemName:"listItem",wrapperNames:["bulletList","orderedList"]},{itemName:"taskItem",wrapperNames:["taskList"]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&M(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&M(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:s})=>{e.state.schema.nodes[n]!==void 0&&L(e,n,s)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:s})=>{e.state.schema.nodes[n]!==void 0&&L(e,n,s)&&(t=!0)}),t}}}}),S=/^(\s*)(\d+)\.\s+(.*)$/,ee=/^\s/;function te(e){const t=[];let n=0,s=0;for(;n<e.length;){const i=e[n],a=i.match(S);if(!a)break;const[,u,r,h]=a,d=u.length;let o=h,l=n+1;const g=[i];for(;l<e.length;){const f=e[l];if(f.match(S))break;if(f.trim()==="")g.push(f),o+=` `,l+=1;else if(f.match(ee))g.push(f),o+=` ${f.slice(d+2)}`,l+=1;else break}t.push({indent:d,number:parseInt(r,10),content:o.trim(),raw:g.join(` `)}),s=l,n=l}return[t,s]}function O(e,t,n){var s;const i=[];let a=0;for(;a<e.length;){const u=e[a];if(u.indent===t){const r=u.content.split(` `),h=((s=r[0])==null?void 0:s.trim())||"",d=[];h&&d.push({type:"paragraph",raw:h,tokens:n.inlineTokens(h)});const o=r.slice(1).join(` `).trim();if(o){const f=n.blockTokens(o);d.push(...f)}let l=a+1;const g=[];for(;l<e.length&&e[l].indent>t;)g.push(e[l]),l+=1;if(g.length>0){const f=Math.min(...g.map(y=>y.indent)),m=O(g,f,n);d.push({type:"list",ordered:!0,start:g[0].number,items:m,raw:g.map(y=>y.raw).join(` `)})}i.push({type:"list_item",raw:u.raw,tokens:d}),a=l}else a+=1}return i}function ne(e,t){return e.map(n=>{if(n.type!=="list_item")return t.parseChildren([n])[0];const s=[];return n.tokens&&n.tokens.length>0&&n.tokens.forEach(i=>{if(i.type==="paragraph"||i.type==="list"||i.type==="blockquote"||i.type==="code")s.push(...t.parseChildren([i]));else if(i.type==="text"&&i.tokens){const a=t.parseChildren([i]);s.push({type:"paragraph",content:a})}else{const a=t.parseChildren([i]);a.length>0&&s.push(...a)}}),{type:"listItem",content:s}})}var se="listItem",U="textStyle",$=/^(\d+)\.\s$/,ie=p.Node.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:e=>e.hasAttribute("start")?parseInt(e.getAttribute("start")||"",10):1},type:{default:null,parseHTML:e=>e.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:e}){const{start:t,...n}=e;return t===1?["ol",p.mergeAttributes(this.options.HTMLAttributes,n),0]:["ol",p.mergeAttributes(this.options.HTMLAttributes,e),0]},markdownTokenName:"list",parseMarkdown:(e,t)=>{if(e.type!=="list"||!e.ordered)return[];const n=e.start||1,s=e.items?ne(e.items,t):[];return n!==1?{type:"orderedList",attrs:{start:n},content:s}:{type:"orderedList",content:s}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` `):"",markdownTokenizer:{name:"orderedList",level:"block",start:e=>{const t=e.match(/^(\s*)(\d+)\.\s+/),n=t?.index;return n!==void 0?n:-1},tokenize:(e,t,n)=>{var s;const i=e.split(` `),[a,u]=te(i);if(a.length===0)return;const r=O(a,0,n);return r.length===0?void 0:{type:"list",ordered:!0,start:((s=a[0])==null?void 0:s.number)||1,items:r,raw:i.slice(0,u).join(` `)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(se,this.editor.getAttributes(U)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=p.wrappingInputRule({find:$,type:this.type,getAttributes:t=>({start:+t[1]}),joinPredicate:(t,n)=>n.childCount+n.attrs.start===+t[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=p.wrappingInputRule({find:$,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:t=>({start:+t[1],...this.editor.getAttributes(U)}),joinPredicate:(t,n)=>n.childCount+n.attrs.start===+t[1],editor:this.editor})),[e]}}),re=/^\s*(\[([( |x])?\])\s$/,ae=p.Node.create({name:"taskItem",addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:"taskList",a11y:void 0}},content(){return this.options.nested?"paragraph block*":"paragraph+"},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{const t=e.getAttribute("data-checked");return t===""||t==="true"},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:e,HTMLAttributes:t}){return["li",p.mergeAttributes(this.options.HTMLAttributes,t,{"data-type":this.name}),["label",["input",{type:"checkbox",checked:e.attrs.checked?"checked":null}],["span"]],["div",0]]},parseMarkdown:(e,t)=>{const n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode("paragraph",{},t.parseInline(e.tokens))):e.text?n.push(t.createNode("paragraph",{},[t.createNode("text",{text:e.text})])):n.push(t.createNode("paragraph",{},[])),e.nestedTokens&&e.nestedTokens.length>0){const s=t.parseChildren(e.nestedTokens);n.push(...s)}return t.createNode("taskItem",{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>{var n;const i=`- [${(n=e.attrs)!=null&&n.checked?"x":" "}] `;return p.renderNestedMarkdownContent(e,t,i)},addKeyboardShortcuts(){const e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:s})=>{const i=document.createElement("li"),a=document.createElement("label"),u=document.createElement("span"),r=document.createElement("input"),h=document.createElement("div"),d=o=>{var l,g;r.ariaLabel=((g=(l=this.options.a11y)==null?void 0:l.checkboxLabel)==null?void 0:g.call(l,o,r.checked))||`Task item checkbox for ${o.textContent||"empty task item"}`};return d(e),a.contentEditable="false",r.type="checkbox",r.addEventListener("mousedown",o=>o.preventDefault()),r.addEventListener("change",o=>{if(!s.isEditable&&!this.options.onReadOnlyChecked){r.checked=!r.checked;return}const{checked:l}=o.target;s.isEditable&&typeof n=="function"&&s.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:g})=>{const f=n();if(typeof f!="number")return!1;const m=g.doc.nodeAt(f);return g.setNodeMarkup(f,void 0,{...m?.attrs,checked:l}),!0}).run(),!s.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,l)||(r.checked=!r.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([o,l])=>{i.setAttribute(o,l)}),i.dataset.checked=e.attrs.checked,r.checked=e.attrs.checked,a.append(r,u),i.append(a,h),Object.entries(t).forEach(([o,l])=>{i.setAttribute(o,l)}),{dom:i,contentDOM:h,update:o=>o.type!==this.type?!1:(i.dataset.checked=o.attrs.checked,r.checked=o.attrs.checked,d(o),!0)}}},addInputRules(){return[p.wrappingInputRule({find:re,type:this.type,getAttributes:e=>({checked:e[e.length-1]==="x"})})]}}),oe=p.Node.create({name:"taskList",addOptions(){return{itemTypeName:"taskItem",HTMLAttributes:{}}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return["ul",p.mergeAttributes(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode("taskList",{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` `):"",markdownTokenizer:{name:"taskList",level:"block",start(e){var t;const n=(t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))==null?void 0:t.index;return n!==void 0?n:-1},tokenize(e,t,n){const s=a=>{const u=p.parseIndentedBlocks(a,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:r=>({indentLevel:r[1].length,mainContent:r[4],checked:r[3].toLowerCase()==="x"}),createToken:(r,h)=>({type:"taskItem",raw:"",mainContent:r.mainContent,indentLevel:r.indentLevel,checked:r.checked,text:r.mainContent,tokens:n.inlineTokens(r.mainContent),nestedTokens:h}),customNestedParser:s},n);return u?[{type:"taskList",raw:u.raw,items:u.items}]:n.blockTokens(a)},i=p.parseIndentedBlocks(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:a=>({indentLevel:a[1].length,mainContent:a[4],checked:a[3].toLowerCase()==="x"}),createToken:(a,u)=>({type:"taskItem",raw:"",mainContent:a.mainContent,indentLevel:a.indentLevel,checked:a.checked,text:a.mainContent,tokens:n.inlineTokens(a.mainContent),nestedTokens:u}),customNestedParser:s},n);if(i)return{type:"taskList",raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});p.Extension.create({name:"listKit",addExtensions(){const e=[];return this.options.bulletList!==!1&&e.push(Q.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(x.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(R.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(ie.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(ae.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(oe.configure(this.options.taskList)),e}});const le=p.Node.create({name:"iframe",group:"block",atom:!0,addOptions(){return{allowFullscreen:!0,HTMLAttributes:{class:"iframe-wrapper"}}},addAttributes(){return{src:{default:null},frameborder:{default:0},allow:{default:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"},allowfullscreen:{default:this.options.allowFullscreen}}},parseHTML(){return[{tag:"iframe"}]},renderHTML({HTMLAttributes:e}){return["div",{class:"iframe-wrapper"},["iframe",p.mergeAttributes(e)]]},addCommands(){return{setIframe:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addPasteRules(){return[{find:/<iframe.*?src="(.*?)".*?>.*?<\/iframe>/gi,handler:({match:e,chain:t,range:n})=>{const s=e[1];s&&t().focus().deleteRange(n).setIframe({src:s}).run()}}]}});function ue(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-")}function ce(){return F.extend({renderHTML({node:e,HTMLAttributes:t}){const n=e.textContent,s=ue(n);return[`h${e.attrs.level}`,{...t,id:s},0]}})}function de(e,t){const n=C.createLowlight(C.common),s=ce();async function i(u){if(!e.uploadUrl)throw new Error("uploadUrl prop is not set");const r=new FormData;r.append("file",u),t("upload-start",u);try{const d=(await A.post(e.uploadUrl,r,{headers:{...e.headers,"Content-Type":"multipart/form-data"}})).data,o=d.url||d.path||d.data?.url;if(!o)throw new Error("Upload response did not include url");return t("upload-success",o,u),o}catch(h){throw t("upload-error",h,u),h}}return v.useEditor({editorProps:{attributes:{class:"tiptap prose prose-sm sm:prose-base lg:prose-lg xl:prose-xl max-w-none p-4 m-0 focus:outline-none"},uploadOnInsert:{type:Boolean,default:!1},uploadUrl:{type:String,default:null},deleteUrl:{type:String,default:null},headers:{type:Object,default:()=>({})},extractImages:{type:Function,default:null}},extensions:[w.Color.configure({types:[w.TextStyle.name,x.name]}),w.TextStyle.configure({types:[x.name]}),V.configure({codeBlock:!1,link:!1,heading:!1}),K.configure({HTMLAttributes:{rel:"noopener"}}),D.configure({types:["heading","paragraph"]}),_.configure({lowlight:n,enableTabIndentation:!0}),s,q,P.configure({allowedMimeTypes:["image/png","image/jpeg","image/gif","image/webp"],onDrop:(u,r,h)=>{r.forEach(d=>{const o=URL.createObjectURL(d);e.uploadOnInsert&&e.uploadUrl?(u.chain().focus().insertContentAt(h,{type:"image",attrs:{src:o,"data-uploading":"true"}}).run(),i(d).then(l=>{u.chain().focus().updateAttributes("image",{src:l,"data-uploading":null}).run()}).catch(l=>{console.error("upload failed",l),pendingUploads.value.delete(o)})):u.chain().focus().insertContentAt(h,{type:"image",attrs:{src:o}}).run()})},onPaste:(u,r)=>{r.forEach(h=>{const d=URL.createObjectURL(h);e.uploadOnInsert&&e.uploadUrl?(u.chain().focus().insertContentAt(pos,{type:"image",attrs:{src:d,"data-uploading":"true"}}).run(),i(h).then(o=>{u.chain().focus().updateAttributes("image",{src:o,"data-uploading":null}).run()}).catch(o=>{console.error("upload failed",o),pendingUploads.value.delete(d)})):u.chain().focus().insertContentAt(pos,{type:"image",attrs:{src:d}}).run()})}}),le],content:e.modelValue,onUpdate:({editor:u})=>{u.getHTML()!==e.modelValue&&t("update:modelValue",u.getHTML())}})}function pe(e){function t(){const{empty:s}=e.value.state.selection,i=e.value.getAttributes("link").href,a=window.prompt("URL",i);if(s){e.value.chain().focus().insertContent(a).run();const u=e.value.state.selection.from-a.length,r=e.value.state.selection.from;e.value.chain().setTextSelection({from:u,to:r}).setLink({href:a}).setTextSelection(r).run()}else{if(a===null)return;if(a===""){e.value.chain().focus().extendMarkRange("link").unsetLink().run();return}e.value.chain().focus().extendMarkRange("link").setLink({href:a}).run();return}}function n(){console.log("test")}return{setLink:t,test:n}}const he={class:"sticky top-0 overflow-hidden w-full rounded-t-2xl mx-auto z-10 bg-gray-100!"},ge={class:"flex md:flex-wrap flex-nowrap overflow-x-auto gap-2 p-2 scrollbar-hide masked-overflow"},fe=["title","aria-label","onClick","disabled","innerHTML"],me={__name:"Editor",props:{modelValue:{type:String,required:!0},classes:{type:String,default:"w-full sm:w-11/12 md:w-4/5 lg:w-3/4 xl:w-2/3 mx-auto"},uploadOnInsert:{type:Boolean,default:!1},uploadUrl:{type:String,default:null},headers:{type:Object,default:()=>({})},extractImages:{type:Function,default:null}},emits:["update:modelValue","upload-start","upload-success","upload-error","image-deleted"],setup(e,{emit:t}){const n=e,s=t,i=de(n,s),a=()=>!!(i&&i.value),{addImage:u}=X(i,n,s),{setLink:r}=pe(i),h=z(i,a,u,r);return c.onBeforeUnmount(()=>{i.value?.destroy()}),(d,o)=>c.withDirectives((c.openBlock(),c.createElementBlock("div",{class:c.normalizeClass(`bg-white! rounded-2xl mt-4 border border-gray-300 ${n.classes}`)},[c.createElementVNode("div",he,[c.createElementVNode("div",ge,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(c.unref(h),l=>(c.openBlock(),c.createElementBlock("button",{type:"button",title:l.title,key:l.label,"aria-label":l.label,class:c.normalizeClass(["px-1.5 sm:px-3 py-1 text-xs text-gray-900 sm:text-sm border border-gray-800 dark:border-neutral-600 rounded-sm whitespace-nowrap transition delay-100 duration-100 ease-in-out hover:-translate-y-1 hover:scale-102",{"is-active":l.active?l.active():!1}]),onClick:l.action,disabled:l.disabled?l.disabled():!1,innerHTML:l.label},null,10,fe))),128))]),o[0]||(o[0]=c.createElementVNode("div",{class:"pointer-events-none absolute left-0 top-0 h-full w-8 fade-left"},null,-1)),o[1]||(o[1]=c.createElementVNode("div",{class:"pointer-events-none absolute right-0 top-0 h-full w-8 fade-right"},null,-1))]),c.createVNode(c.unref(v.EditorContent),{class:"w-full",editor:c.unref(i)},null,8,["editor"])],2)),[[c.vShow,c.unref(i)]])}};return{install:(e,t)=>{e.component("Editor",me)}}}));