@mario9/tiptap-editor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/index.d.ts +80 -0
- package/dist/tiptap-vue.css +1 -0
- package/dist/tiptap-vue.js +1689 -0
- package/dist/tiptap-vue.umd.cjs +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(V,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@tiptap/starter-kit"),require("@tiptap/vue-3"),require("@tiptap/extension-list"),require("@tiptap/extension-text-align"),require("@tiptap/extensions"),require("@tiptap/extension-image"),require("@tiptap/pm/state"),require("@tiptap/pm/view"),require("@tiptap/extension-table"),require("@tiptap/extension-mathematics"),require("@tiptap/core"),require("element-plus"),require("katex")):typeof define=="function"&&define.amd?define(["exports","vue","@tiptap/starter-kit","@tiptap/vue-3","@tiptap/extension-list","@tiptap/extension-text-align","@tiptap/extensions","@tiptap/extension-image","@tiptap/pm/state","@tiptap/pm/view","@tiptap/extension-table","@tiptap/extension-mathematics","@tiptap/core","element-plus","katex"],e):(V=typeof globalThis<"u"?globalThis:V||self,e(V.TiptapVue={},V.Vue,V.StarterKit,V.vue3,V.extensionList,V.extensionTextAlign,V.extensions,V.extensionImage,V.state,V.view,V.extensionTable,V.extensionMathematics,V.core,V.ElementPlus,V.katex))})(this,(function(V,e,q,y,v,P,W,K,D,_,I,G,Z,s,J){"use strict";const R=K.Image.extend({addAttributes(){return{...this.parent?.(),align:{default:"left",parseHTML:t=>t.getAttribute("data-align")??"left",renderHTML:t=>({"data-align":t.align})}}},addProseMirrorPlugins(){const t=this.name;return[new D.Plugin({props:{decorations(o){const l=[];return o.doc.descendants((i,c)=>{i.type.name===t&&i.attrs.align&&l.push(_.Decoration.node(c,c+i.nodeSize,{"data-align":i.attrs.align}))}),_.DecorationSet.create(o.doc,l)}}})]}}),X={class:"tiptap-image-upload-content"},Q={class:"tiptap-image-upload-subtext"},Y={key:1,class:"tiptap-image-upload-previews"},ee={class:"tiptap-image-upload-preview-content"},te={class:"tiptap-image-upload-text"},oe={class:"tiptap-image-upload-subtext"},ne=["onClick"],le=["accept","multiple"],re=e.defineComponent({__name:"ImageUploadView",props:y.nodeViewProps,setup(t){const o=t,l=e.computed(()=>o.node.attrs.accept),i=e.computed(()=>o.node.attrs.limit),c=e.computed(()=>o.node.attrs.maxSize),a=e.ref([]),h=e.ref(),g=e.ref(!1),C=async d=>{if(c.value>0&&d.size>c.value)return o.extension.options.onError?.(new Error(`文件大小超出限制 ${c.value/1024/1024}MB`)),null;const u=crypto.randomUUID();a.value.push({id:u,file:d,progress:0,status:"uploading"});try{const f=o.extension.options.upload;if(!f)throw new Error("未配置 upload 函数");const H=await f(d);if(!H)throw new Error("上传失败:未返回 URL");const N=a.value.find(b=>b.id===u);return N&&(N.status="success",N.progress=100),o.extension.options.onSuccess?.(H),H}catch(f){const H=a.value.find(N=>N.id===u);return H&&(H.status="error",H.progress=0),o.extension.options.onError?.(f instanceof Error?f:new Error("上传失败")),null}},p=async d=>{if(!d.length)return;if(d.length>i.value){o.extension.options.onError?.(new Error(`最多上传 ${i.value} 个文件`));return}const u=(await Promise.all(d.map(C))).filter(f=>!!f);if(u.length>0){const f=o.getPos();if(typeof f!="number")return;const H=u.map(N=>({type:"image",attrs:{src:N}}));o.editor.chain().focus().deleteRange({from:f,to:f+o.node.nodeSize}).insertContentAt(f,H).run()}},n=()=>{a.value.length===0&&h.value&&(h.value.value="",h.value.click())},r=d=>{const u=d.target.files;u&&p(Array.from(u))},m=d=>{d.preventDefault(),g.value=!0},k=d=>{d.currentTarget.contains(d.relatedTarget)||(g.value=!1)},E=d=>{d.preventDefault(),g.value=!1;const u=Array.from(d.dataTransfer?.files??[]);u.length&&p(u)},w=d=>{a.value=a.value.filter(u=>u.id!==d)};return(d,u)=>(e.openBlock(),e.createBlock(e.unref(y.NodeViewWrapper),{class:"tiptap-image-upload",onClick:n},{default:e.withCtx(()=>[a.value.length?(e.openBlock(),e.createElementBlock("div",Y,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.value,f=>(e.openBlock(),e.createElementBlock("div",{key:f.id,class:"tiptap-image-upload-preview"},[f.status==="uploading"?(e.openBlock(),e.createElementBlock("div",{key:0,class:"tiptap-image-upload-progress",style:e.normalizeStyle({width:`${f.progress}%`})},null,4)):e.createCommentVNode("",!0),e.createElementVNode("div",ee,[e.createElementVNode("span",te,e.toDisplayString(f.file.name),1),e.createElementVNode("span",oe,e.toDisplayString(f.status==="uploading"?`${f.progress}%`:f.status==="error"?"上传失败":"上传成功"),1),e.createElementVNode("button",{class:"tiptap-image-upload-remove",onClick:e.withModifiers(H=>w(f.id),["stop"])},"×",8,ne)])]))),128))])):(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["tiptap-image-upload-drag-area",{"drag-active":g.value}]),onDragover:m,onDragleave:k,onDrop:E},[e.createElementVNode("div",X,[u[1]||(u[1]=e.createElementVNode("span",{class:"tiptap-image-upload-text"},[e.createElementVNode("em",null,"点击上传"),e.createTextVNode(" 或拖拽图片到此处")],-1)),e.createElementVNode("span",Q," 最多 "+e.toDisplayString(i.value)+" 个文件"+e.toDisplayString(c.value?`,每个不超过 ${c.value/1024/1024}MB`:""),1)])],34)),e.createElementVNode("input",{ref_key:"inputRef",ref:h,type:"file",accept:l.value,multiple:i.value>1,onChange:r,onClick:u[0]||(u[0]=e.withModifiers(()=>{},["stop"]))},null,40,le)]),_:1}))}}),ie=Z.Node.create({name:"imageUpload",group:"block",draggable:!0,selectable:!0,atom:!0,addOptions(){return{type:"image",accept:"image/*",limit:1,maxSize:0,upload:t=>new Promise(o=>{const l=new FileReader;l.onloadend=()=>o(l.result),l.readAsDataURL(t)}),onError:void 0,onSuccess:void 0,HTMLAttributes:{}}},addAttributes(){return{accept:{default:this.options.accept},limit:{default:this.options.limit},maxSize:{default:this.options.maxSize}}},parseHTML(){return[{tag:'div[data-type="image-upload"]'}]},renderHTML({HTMLAttributes:t}){return["div",Z.mergeAttributes({"data-type":"image-upload"},t)]},addNodeView(){return y.VueNodeViewRenderer(re)},addCommands(){return{setImageUploadNode:()=>({commands:t})=>t.insertContent({type:this.name})}},addKeyboardShortcuts(){return{Enter:({editor:t})=>{const{selection:o}=t.state,{nodeAfter:l}=o.$from;if(l?.type.name==="imageUpload"&&t.isActive("imageUpload")){const i=t.view.nodeDOM(o.$from.pos);if(i instanceof HTMLElement){const c=i.firstChild;if(c instanceof HTMLElement)return c.click(),!0}}return!1}}}}),ae={icon:{type:Object,required:!0},tooltip:{type:String,required:!0},isActive:{type:Boolean},disabled:{type:Boolean,default:!1},onClick:{type:Function}},x=e.defineComponent({name:"IconButton",props:ae,setup(t){return()=>e.createVNode(s.ElTooltip,{showArrow:!1,offset:6,content:t.tooltip},{default:()=>[e.createVNode(s.ElButton,{text:!0,icon:t.icon,class:["tiptap-button",{"is-active":t.isActive}],disabled:t.disabled,onClick:t.onClick},null)]})}}),ce=e.defineComponent({name:"UndoIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9.70711 3.70711C10.0976 3.31658 10.0976 2.68342 9.70711 2.29289C9.31658 1.90237 8.68342 1.90237 8.29289 2.29289L3.29289 7.29289C2.90237 7.68342 2.90237 8.31658 3.29289 8.70711L8.29289 13.7071C8.68342 14.0976 9.31658 14.0976 9.70711 13.7071C10.0976 13.3166 10.0976 12.6834 9.70711 12.2929L6.41421 9H14.5C15.0909 9 15.6761 9.1164 16.2221 9.34254C16.768 9.56869 17.2641 9.90016 17.682 10.318C18.0998 10.7359 18.4313 11.232 18.6575 11.7779C18.8836 12.3239 19 12.9091 19 13.5C19 14.0909 18.8836 14.6761 18.6575 15.2221C18.4313 15.768 18.0998 16.2641 17.682 16.682C17.2641 17.0998 16.768 17.4313 16.2221 17.6575C15.6761 17.8836 15.0909 18 14.5 18H11C10.4477 18 10 18.4477 10 19C10 19.5523 10.4477 20 11 20H14.5C15.3536 20 16.1988 19.8319 16.9874 19.5052C17.7761 19.1786 18.4926 18.6998 19.0962 18.0962C19.6998 17.4926 20.1786 16.7761 20.5052 15.9874C20.8319 15.1988 21 14.3536 21 13.5C21 12.6464 20.8319 11.8012 20.5052 11.0126C20.1786 10.2239 19.6998 9.50739 19.0962 8.90381C18.4926 8.30022 17.7761 7.82144 16.9874 7.49478C16.1988 7.16813 15.3536 7 14.5 7H6.41421L9.70711 3.70711Z",fill:"currentColor"},null)])}}),de=e.defineComponent({name:"RedoIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M15.7071 2.29289C15.3166 1.90237 14.6834 1.90237 14.2929 2.29289C13.9024 2.68342 13.9024 3.31658 14.2929 3.70711L17.5858 7H9.5C7.77609 7 6.12279 7.68482 4.90381 8.90381C3.68482 10.1228 3 11.7761 3 13.5C3 14.3536 3.16813 15.1988 3.49478 15.9874C3.82144 16.7761 4.30023 17.4926 4.90381 18.0962C6.12279 19.3152 7.77609 20 9.5 20H13C13.5523 20 14 19.5523 14 19C14 18.4477 13.5523 18 13 18H9.5C8.30653 18 7.16193 17.5259 6.31802 16.682C5.90016 16.2641 5.56869 15.768 5.34254 15.2221C5.1164 14.6761 5 14.0909 5 13.5C5 12.3065 5.47411 11.1619 6.31802 10.318C7.16193 9.47411 8.30653 9 9.5 9H17.5858L14.2929 12.2929C13.9024 12.6834 13.9024 13.3166 14.2929 13.7071C14.6834 14.0976 15.3166 14.0976 15.7071 13.7071L20.7071 8.70711C21.0976 8.31658 21.0976 7.68342 20.7071 7.29289L15.7071 2.29289Z",fill:"currentColor"},null)])}}),se=e.defineComponent({name:"UndoRedoButton",setup(){const t=e.inject("editor"),o=e.computed(()=>t?.value?.can().undo()??!1),l=e.computed(()=>t?.value?.can().redo()??!1);return()=>e.createVNode("div",null,[e.createVNode(x,{icon:ce,tooltip:"撤销",disabled:!o.value,onClick:()=>t?.value?.chain().focus().undo().run()},null),e.createVNode(x,{icon:de,tooltip:"重做",disabled:!l.value,onClick:()=>t?.value?.chain().focus().redo().run()},null)])}}),ue=e.defineComponent({name:"LinkIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{d:"M16.9958 1.06669C15.4226 1.05302 13.907 1.65779 12.7753 2.75074L12.765 2.76086L11.045 4.47086C10.6534 4.86024 10.6515 5.49341 11.0409 5.88507C11.4303 6.27673 12.0634 6.27858 12.4551 5.88919L14.1697 4.18456C14.9236 3.45893 15.9319 3.05752 16.9784 3.06662C18.0272 3.07573 19.0304 3.49641 19.772 4.23804C20.5137 4.97967 20.9344 5.98292 20.9435 7.03171C20.9526 8.07776 20.5515 9.08563 19.8265 9.83941L16.833 12.8329C16.4274 13.2386 15.9393 13.5524 15.4019 13.7529C14.8645 13.9533 14.2903 14.0359 13.7181 13.9949C13.146 13.9539 12.5894 13.7904 12.0861 13.5154C11.5827 13.2404 11.1444 12.8604 10.8008 12.401C10.47 11.9588 9.84333 11.8685 9.40108 12.1993C8.95883 12.5301 8.86849 13.1568 9.1993 13.599C9.71464 14.288 10.3721 14.858 11.1272 15.2705C11.8822 15.683 12.7171 15.9283 13.5753 15.9898C14.4334 16.0513 15.2948 15.9274 16.1009 15.6267C16.907 15.326 17.639 14.8555 18.2473 14.247L21.2472 11.2471L21.2593 11.2347C22.3523 10.1031 22.9571 8.58751 22.9434 7.01433C22.9297 5.44115 22.2987 3.93628 21.1863 2.82383C20.0738 1.71138 18.5689 1.08036 16.9958 1.06669Z",fill:"currentColor"},null),e.createVNode("path",{d:"M10.4247 8.0102C9.56657 7.94874 8.70522 8.07256 7.89911 8.37326C7.09305 8.67395 6.36096 9.14458 5.75272 9.753L2.75285 12.7529L2.74067 12.7653C1.64772 13.8969 1.04295 15.4125 1.05662 16.9857C1.07029 18.5589 1.70131 20.0637 2.81376 21.1762C3.9262 22.2886 5.43108 22.9196 7.00426 22.9333C8.57744 22.947 10.0931 22.3422 11.2247 21.2493L11.2371 21.2371L12.9471 19.5271C13.3376 19.1366 13.3376 18.5034 12.9471 18.1129C12.5565 17.7223 11.9234 17.7223 11.5328 18.1129L9.82932 19.8164C9.07555 20.5414 8.06768 20.9425 7.02164 20.9334C5.97285 20.9243 4.9696 20.5036 4.22797 19.762C3.48634 19.0203 3.06566 18.0171 3.05655 16.9683C3.04746 15.9222 3.44851 14.9144 4.17355 14.1606L7.16719 11.167C7.5727 10.7613 8.06071 10.4476 8.59811 10.2471C9.13552 10.0467 9.70976 9.96412 10.2819 10.0051C10.854 10.0461 11.4106 10.2096 11.9139 10.4846C12.4173 10.7596 12.8556 11.1397 13.1992 11.599C13.53 12.0412 14.1567 12.1316 14.5989 11.8007C15.0412 11.4699 15.1315 10.8433 14.8007 10.401C14.2854 9.71205 13.6279 9.14198 12.8729 8.72948C12.1178 8.31697 11.2829 8.07166 10.4247 8.0102Z",fill:"currentColor"},null)])}}),pe=e.defineComponent({name:"CornerDownLeftIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("polyline",{points:"9 10 4 15 9 20"},null),e.createVNode("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"},null)])}}),Ce=e.defineComponent({name:"ExternalLinkIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"},null),e.createVNode("polyline",{points:"15 3 21 3 21 9"},null),e.createVNode("line",{x1:"10",y1:"14",x2:"21",y2:"3"},null)])}}),fe=e.defineComponent({name:"TrashIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("polyline",{points:"3 6 5 6 21 6"},null),e.createVNode("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"},null)])}}),me=e.defineComponent({name:"LinkPopover",setup(){const t=e.inject("editor"),o=e.ref(!1),l=e.ref("");let i=!1;e.watch(()=>t?.value?.isActive("link"),n=>{i||n&&(l.value=t?.value?.getAttributes("link").href??"",e.nextTick(()=>{o.value=!0}))});const c=()=>{const n=t?.value;if(!n||!l.value)return;i=!0;const{empty:r}=n.state.selection;let m=n.chain().focus().extendMarkRange("link").setLink({href:l.value});r&&(m=m.insertContent({type:"text",text:l.value})),m.run(),o.value=!1,e.nextTick(()=>{i=!1})},a=()=>{const n=t?.value;n&&(i=!0,n.chain().focus().extendMarkRange("link").unsetLink().run(),l.value="",o.value=!1,e.nextTick(()=>{i=!1}))},h=()=>{const n=t?.value?.getAttributes("link").href;n&&window.open(n,"_blank","noopener,noreferrer")},g=n=>{n.key==="Enter"&&(n.preventDefault(),c())},C=n=>{n&&(l.value=t?.value?.getAttributes("link").href??""),o.value=n},p=n=>{l.value=n};return()=>{const n=t?.value?.isActive("link")??!1;return e.createVNode(s.ElPopover,{visible:o.value,"onUpdate:visible":C,placement:"bottom",width:300,trigger:"click",showArrow:!1,popperClass:"link-popover-popper",offset:6},{reference:()=>e.createVNode("span",null,[e.createVNode(x,{tooltip:"链接",icon:ue,class:["tiptap-button",{"is-active":n}]},null)]),default:()=>e.createVNode("div",{class:"link-popover-inner"},[e.createVNode(s.ElInput,{modelValue:l.value,"onUpdate:modelValue":p,type:"url",placeholder:"请输入链接...",size:"small",autofocus:!0,onKeydown:g},null),e.createVNode("div",{class:"link-popover-actions"},[e.createVNode(s.ElTooltip,{content:"确认",showArrow:!1,offset:4},{default:()=>[e.createVNode(s.ElButton,{text:!0,icon:pe,disabled:!l.value,onClick:c},null)]}),e.createVNode(s.ElTooltip,{content:"在新标签页打开",showArrow:!1,offset:4},{default:()=>[e.createVNode(s.ElButton,{text:!0,icon:Ce,disabled:!l.value&&!n,onClick:h},null)]}),e.createVNode(s.ElTooltip,{content:"移除链接",showArrow:!1,offset:4},{default:()=>[e.createVNode(s.ElButton,{text:!0,icon:fe,disabled:!n,onClick:a},null)]})])])})}}}),he=e.defineComponent({name:"BoldIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6 2.5C5.17157 2.5 4.5 3.17157 4.5 4V20C4.5 20.8284 5.17157 21.5 6 21.5H15C16.4587 21.5 17.8576 20.9205 18.8891 19.8891C19.9205 18.8576 20.5 17.4587 20.5 16C20.5 14.5413 19.9205 13.1424 18.8891 12.1109C18.6781 11.9 18.4518 11.7079 18.2128 11.5359C19.041 10.5492 19.5 9.29829 19.5 8C19.5 6.54131 18.9205 5.14236 17.8891 4.11091C16.8576 3.07946 15.4587 2.5 14 2.5H6ZM14 10.5C14.663 10.5 15.2989 10.2366 15.7678 9.76777C16.2366 9.29893 16.5 8.66304 16.5 8C16.5 7.33696 16.2366 6.70107 15.7678 6.23223C15.2989 5.76339 14.663 5.5 14 5.5H7.5V10.5H14ZM7.5 18.5V13.5H15C15.663 13.5 16.2989 13.7634 16.7678 14.2322C17.2366 14.7011 17.5 15.337 17.5 16C17.5 16.663 17.2366 17.2989 16.7678 17.7678C16.2989 18.2366 15.663 18.5 15 18.5H7.5Z",fill:"currentColor"},null)])}}),ge=e.defineComponent({name:"ItalicIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{d:"M15.0222 3H19C19.5523 3 20 3.44772 20 4C20 4.55228 19.5523 5 19 5H15.693L10.443 19H14C14.5523 19 15 19.4477 15 20C15 20.5523 14.5523 21 14 21H9.02418C9.00802 21.0004 8.99181 21.0004 8.97557 21H5C4.44772 21 4 20.5523 4 20C4 19.4477 4.44772 19 5 19H8.30704L13.557 5H10C9.44772 5 9 4.55228 9 4C9 3.44772 9.44772 3 10 3H14.9782C14.9928 2.99968 15.0075 2.99967 15.0222 3Z",fill:"currentColor"},null)])}}),Ve=e.defineComponent({name:"StrikeIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{d:"M9.00039 3H16.0001C16.5524 3 17.0001 3.44772 17.0001 4C17.0001 4.55229 16.5524 5 16.0001 5H9.00011C8.68006 4.99983 8.36412 5.07648 8.07983 5.22349C7.79555 5.37051 7.55069 5.5836 7.36585 5.84487C7.181 6.10614 7.06155 6.40796 7.01754 6.72497C6.97352 7.04198 7.00623 7.36492 7.11292 7.66667C7.29701 8.18737 7.02414 8.75872 6.50344 8.94281C5.98274 9.1269 5.4114 8.85403 5.2273 8.33333C5.01393 7.72984 4.94851 7.08396 5.03654 6.44994C5.12456 5.81592 5.36346 5.21229 5.73316 4.68974C6.10285 4.1672 6.59256 3.74101 7.16113 3.44698C7.72955 3.15303 8.36047 2.99975 9.00039 3Z",fill:"currentColor"},null),e.createVNode("path",{d:"M18 13H20C20.5523 13 21 12.5523 21 12C21 11.4477 20.5523 11 20 11H4C3.44772 11 3 11.4477 3 12C3 12.5523 3.44772 13 4 13H14C14.7956 13 15.5587 13.3161 16.1213 13.8787C16.6839 14.4413 17 15.2044 17 16C17 16.7956 16.6839 17.5587 16.1213 18.1213C15.5587 18.6839 14.7956 19 14 19H6C5.44772 19 5 19.4477 5 20C5 20.5523 5.44772 21 6 21H14C15.3261 21 16.5979 20.4732 17.5355 19.5355C18.4732 18.5979 19 17.3261 19 16C19 14.9119 18.6453 13.8604 18 13Z",fill:"currentColor"},null)])}}),we=e.defineComponent({name:"UnderlineIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4V10C5 11.8565 5.7375 13.637 7.05025 14.9497C8.36301 16.2625 10.1435 17 12 17C13.8565 17 15.637 16.2625 16.9497 14.9497C18.2625 13.637 19 11.8565 19 10V4C19 3.44772 18.5523 3 18 3C17.4477 3 17 3.44772 17 4V10C17 11.3261 16.4732 12.5979 15.5355 13.5355C14.5979 14.4732 13.3261 15 12 15C10.6739 15 9.40215 14.4732 8.46447 13.5355C7.52678 12.5979 7 11.3261 7 10V4ZM4 19C3.44772 19 3 19.4477 3 20C3 20.5523 3.44772 21 4 21H20C20.5523 21 21 20.5523 21 20C21 19.4477 20.5523 19 20 19H4Z",fill:"currentColor"},null)])}}),Ne=e.defineComponent({name:"TextStyleButton",setup(){const t=e.inject("editor");return()=>e.createVNode("div",null,[e.createVNode(x,{icon:he,tooltip:"粗体",isActive:t?.value?.isActive("bold"),onClick:()=>t?.value?.chain().focus().toggleBold().run()},null),e.createVNode(x,{icon:ge,tooltip:"斜体",isActive:t?.value?.isActive("italic"),onClick:()=>t?.value?.chain().focus().toggleItalic().run()},null),e.createVNode(x,{icon:Ve,tooltip:"删除线",isActive:t?.value?.isActive("strike"),onClick:()=>t?.value?.chain().focus().toggleStrike().run()},null),e.createVNode(x,{icon:we,tooltip:"下划线",isActive:t?.value?.isActive("underline"),onClick:()=>t?.value?.chain().focus().toggleUnderline().run()},null),e.createVNode(me,null,null)])}}),F=e.defineComponent({name:"AlignLeftIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 12C2 11.4477 2.44772 11 3 11H15C15.5523 11 16 11.4477 16 12C16 12.5523 15.5523 13 15 13H3C2.44772 13 2 12.5523 2 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 18C2 17.4477 2.44772 17 3 17H17C17.5523 17 18 17.4477 18 18C18 18.5523 17.5523 19 17 19H3C2.44772 19 2 18.5523 2 18Z",fill:"currentColor"},null)])}}),S=e.defineComponent({name:"AlignCenterIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6 12C6 11.4477 6.44772 11 7 11H17C17.5523 11 18 11.4477 18 12C18 12.5523 17.5523 13 17 13H7C6.44772 13 6 12.5523 6 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M4 18C4 17.4477 4.44772 17 5 17H19C19.5523 17 20 17.4477 20 18C20 18.5523 19.5523 19 19 19H5C4.44772 19 4 18.5523 4 18Z",fill:"currentColor"},null)])}}),U=e.defineComponent({name:"AlignRightIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M8 12C8 11.4477 8.44772 11 9 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H9C8.44772 13 8 12.5523 8 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6 18C6 17.4477 6.44772 17 7 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H7C6.44772 19 6 18.5523 6 18Z",fill:"currentColor"},null)])}}),xe=e.defineComponent({name:"AlignJustifyIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 12C2 11.4477 2.44772 11 3 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H3C2.44772 13 2 12.5523 2 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 18C2 17.4477 2.44772 17 3 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H3C2.44772 19 2 18.5523 2 18Z",fill:"currentColor"},null)])}}),ke=e.defineComponent({name:"TextAlignButton",setup(){const t=e.inject("editor");return()=>e.createVNode("div",null,[e.createVNode(x,{icon:F,tooltip:"左边对齐",isActive:t?.value?.isActive({textAlign:"left"}),onClick:()=>t?.value?.chain().focus().setTextAlign("left").run()},null),e.createVNode(x,{icon:S,tooltip:"中间对齐",isActive:t?.value?.isActive({textAlign:"center"}),onClick:()=>t?.value?.chain().focus().setTextAlign("center").run()},null),e.createVNode(x,{icon:U,tooltip:"右边对齐",isActive:t?.value?.isActive({textAlign:"right"}),onClick:()=>t?.value?.chain().focus().setTextAlign("right").run()},null),e.createVNode(x,{icon:xe,tooltip:"两端对齐",isActive:t?.value?.isActive({textAlign:"justify"}),onClick:()=>t?.value?.chain().focus().setTextAlign("justify").run()},null)])}}),He=e.defineComponent({name:"ListIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M7 6C7 5.44772 7.44772 5 8 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H8C7.44772 7 7 6.55228 7 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M7 12C7 11.4477 7.44772 11 8 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H8C7.44772 13 7 12.5523 7 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M7 18C7 17.4477 7.44772 17 8 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H8C7.44772 19 7 18.5523 7 18Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 6C2 5.44772 2.44772 5 3 5H3.01C3.56228 5 4.01 5.44772 4.01 6C4.01 6.55228 3.56228 7 3.01 7H3C2.44772 7 2 6.55228 2 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 12C2 11.4477 2.44772 11 3 11H3.01C3.56228 11 4.01 11.4477 4.01 12C4.01 12.5523 3.56228 13 3.01 13H3C2.44772 13 2 12.5523 2 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 18C2 17.4477 2.44772 17 3 17H3.01C3.56228 17 4.01 17.4477 4.01 18C4.01 18.5523 3.56228 19 3.01 19H3C2.44772 19 2 18.5523 2 18Z",fill:"currentColor"},null)])}}),Ee=e.defineComponent({name:"ListOrderedIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9 6C9 5.44772 9.44772 5 10 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H10C9.44772 7 9 6.55228 9 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9 12C9 11.4477 9.44772 11 10 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H10C9.44772 13 9 12.5523 9 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9 18C9 17.4477 9.44772 17 10 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H10C9.44772 19 9 18.5523 9 18Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M3 6C3 5.44772 3.44772 5 4 5H5C5.55228 5 6 5.44772 6 6V10C6 10.5523 5.55228 11 5 11C4.44772 11 4 10.5523 4 10V7C3.44772 7 3 6.55228 3 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M3 10C3 9.44772 3.44772 9 4 9H6C6.55228 9 7 9.44772 7 10C7 10.5523 6.55228 11 6 11H4C3.44772 11 3 10.5523 3 10Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M5.82219 13.0431C6.54543 13.4047 6.99997 14.1319 6.99997 15C6.99997 15.5763 6.71806 16.0426 6.48747 16.35C6.31395 16.5814 6.1052 16.8044 5.91309 17H5.99997C6.55226 17 6.99997 17.4477 6.99997 18C6.99997 18.5523 6.55226 19 5.99997 19H3.99997C3.44769 19 2.99997 18.5523 2.99997 18C2.99997 17.4237 3.28189 16.9575 3.51247 16.65C3.74323 16.3424 4.03626 16.0494 4.26965 15.8161C4.27745 15.8083 4.2852 15.8006 4.29287 15.7929C4.55594 15.5298 4.75095 15.3321 4.88748 15.15C4.96287 15.0495 4.99021 14.9922 4.99911 14.9714C4.99535 14.9112 4.9803 14.882 4.9739 14.8715C4.96613 14.8588 4.95382 14.845 4.92776 14.8319C4.87723 14.8067 4.71156 14.7623 4.44719 14.8944C3.95321 15.1414 3.35254 14.9412 3.10555 14.4472C2.85856 13.9533 3.05878 13.3526 3.55276 13.1056C4.28839 12.7378 5.12272 12.6934 5.82219 13.0431Z",fill:"currentColor"},null)])}}),be=e.defineComponent({name:"ListTodoIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 6C2 4.89543 2.89543 4 4 4H8C9.10457 4 10 4.89543 10 6V10C10 11.1046 9.10457 12 8 12H4C2.89543 12 2 11.1046 2 10V6ZM8 6H4V10H8V6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9.70711 14.2929C10.0976 14.6834 10.0976 15.3166 9.70711 15.7071L5.70711 19.7071C5.31658 20.0976 4.68342 20.0976 4.29289 19.7071L2.29289 17.7071C1.90237 17.3166 1.90237 16.6834 2.29289 16.2929C2.68342 15.9024 3.31658 15.9024 3.70711 16.2929L5 17.5858L8.29289 14.2929C8.68342 13.9024 9.31658 13.9024 9.70711 14.2929Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M12 6C12 5.44772 12.4477 5 13 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H13C12.4477 7 12 6.55228 12 6Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M12 12C12 11.4477 12.4477 11 13 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H13C12.4477 13 12 12.5523 12 12Z",fill:"currentColor"},null),e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M12 18C12 17.4477 12.4477 17 13 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H13C12.4477 19 12 18.5523 12 18Z",fill:"currentColor"},null)])}}),Be=e.defineComponent({name:"ListButton",setup(){const t=e.inject("editor");return()=>e.createVNode("div",null,[e.createVNode(x,{icon:He,tooltip:"无序列表",isActive:t?.value?.isActive("bulletList"),onClick:()=>t?.value?.chain().focus().toggleBulletList().run()},null),e.createVNode(x,{icon:Ee,tooltip:"有序列表",isActive:t?.value?.isActive("orderedList"),onClick:()=>t?.value?.chain().focus().toggleOrderedList().run()},null),e.createVNode(x,{icon:be,tooltip:"任务列表",isActive:t?.value?.isActive("taskList"),onClick:()=>t?.value?.chain().focus().toggleTaskList().run()},null)])}}),Me=e.defineComponent({name:"ImagePlusIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M20 2C20 1.44772 19.5523 1 19 1C18.4477 1 18 1.44772 18 2V4H16C15.4477 4 15 4.44772 15 5C15 5.55228 15.4477 6 16 6H18V8C18 8.55228 18.4477 9 19 9C19.5523 9 20 8.55228 20 8V6H22C22.5523 6 23 5.55228 23 5C23 4.44772 22.5523 4 22 4H20V2ZM5 4C4.73478 4 4.48043 4.10536 4.29289 4.29289C4.10536 4.48043 4 4.73478 4 5V19C4 19.2652 4.10536 19.5196 4.29289 19.7071C4.48043 19.8946 4.73478 20 5 20H5.58579L14.379 11.2068C14.9416 10.6444 15.7045 10.3284 16.5 10.3284C17.2955 10.3284 18.0584 10.6444 18.621 11.2068L20 12.5858V12C20 11.4477 20.4477 11 21 11C21.5523 11 22 11.4477 22 12V14.998C22 14.9994 22 15.0007 22 15.002V19C22 19.7957 21.6839 20.5587 21.1213 21.1213C20.5587 21.6839 19.7957 22 19 22H6.00219C6.00073 22 5.99927 22 5.99781 22H5C4.20435 22 3.44129 21.6839 2.87868 21.1213C2.31607 20.5587 2 19.7957 2 19V5C2 4.20435 2.31607 3.44129 2.87868 2.87868C3.44129 2.31607 4.20435 2 5 2H12C12.5523 2 13 2.44772 13 3C13 3.55228 12.5523 4 12 4H5ZM8.41422 20H19C19.2652 20 19.5196 19.8946 19.7071 19.7071C19.8946 19.5196 20 19.2652 20 19V15.4142L17.207 12.6212C17.0195 12.4338 16.7651 12.3284 16.5 12.3284C16.2349 12.3284 15.9806 12.4337 15.7931 12.6211L8.41422 20ZM6.87868 6.87868C7.44129 6.31607 8.20435 6 9 6C9.79565 6 10.5587 6.31607 11.1213 6.87868C11.6839 7.44129 12 8.20435 12 9C12 9.79565 11.6839 10.5587 11.1213 11.1213C10.5587 11.6839 9.79565 12 9 12C8.20435 12 7.44129 11.6839 6.87868 11.1213C6.31607 10.5587 6 9.79565 6 9C6 8.20435 6.31607 7.44129 6.87868 6.87868ZM9 8C8.73478 8 8.48043 8.10536 8.29289 8.29289C8.10536 8.48043 8 8.73478 8 9C8 9.26522 8.10536 9.51957 8.29289 9.70711C8.48043 9.89464 8.73478 10 9 10C9.26522 10 9.51957 9.89464 9.70711 9.70711C9.89464 9.51957 10 9.26522 10 9C10 8.73478 9.89464 8.48043 9.70711 8.29289C9.51957 8.10536 9.26522 8 9 8Z",fill:"currentColor"},null)])}}),ye=e.defineComponent({name:"ImageButton",setup(){const t=e.inject("editor");return()=>e.createVNode("div",null,[e.createVNode(x,{icon:Me,tooltip:"图片",onClick:()=>t?.value?.commands.setImageUploadNode()},null)])}}),Ie=e.defineComponent({name:"TableIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M2 5C2 3.34315 3.34315 2 5 2H19C20.6569 2 22 3.34315 22 5V19C22 20.6569 20.6569 22 19 22H5C3.34315 22 2 20.6569 2 19V5ZM4 5C4 4.44772 4.44772 4 5 4H11V8H4V5ZM4 10H11V14H4V10ZM20 14V10H13V14H20ZM13 16H20V19C20 19.5523 19.5523 20 19 20H13V16ZM11 16V20H5C4.44772 20 4 19.5523 4 19V16H11ZM13 8H20V5C20 4.44772 19.5523 4 19 4H13V8Z",fill:"currentColor"},null)])}}),Ae=8,Le=8,Te=e.defineComponent({name:"TableButton",setup(){const t=e.inject("editor"),o=e.ref(!1),l=e.ref(0),i=e.ref(0),c=(g,C)=>{l.value=g,i.value=C},a=()=>{l.value=0,i.value=0},h=(g,C)=>{t?.value?.chain().focus().insertTable({rows:C,cols:g,withHeaderRow:!0}).run(),o.value=!1};return()=>e.createVNode(s.ElPopover,{visible:o.value,"onUpdate:visible":g=>o.value=g,trigger:"click",placement:"bottom-start",popperClass:"table-picker-popper",width:"auto",showArrow:!1},{reference:()=>e.createVNode("span",null,[e.createVNode(s.ElTooltip,{content:"表格",showArrow:!1,offset:6,disabled:o.value},{default:()=>[e.createVNode(s.ElButton,{text:!0,class:["tiptap-button",{"is-active":o.value}]},{default:()=>[e.createVNode(Ie,{class:"tiptap-button-icon"},null)]})]})]),default:()=>e.createVNode("div",{class:"table-picker"},[e.createVNode("div",{class:"table-picker-grid",onMouseleave:a},[Array.from({length:Le},(g,C)=>e.createVNode("div",{key:C,class:"table-picker-row"},[Array.from({length:Ae},(p,n)=>e.createVNode("div",{key:n,class:["table-picker-cell",{"is-active":n<l.value&&C<i.value}],onMouseenter:()=>c(n+1,C+1),onClick:()=>h(n+1,C+1)},null))]))]),e.createVNode("div",{class:"table-picker-footer"},[e.createVNode("div",{class:"table-picker-counter"},[e.createVNode("span",null,[e.createTextVNode("列")]),e.createVNode("span",null,[l.value||1])]),e.createVNode("span",{class:"table-picker-x"},[e.createTextVNode("x")]),e.createVNode("div",{class:"table-picker-counter"},[e.createVNode("span",null,[e.createTextVNode("行")]),e.createVNode("span",null,[i.value||1])])])])})}});function ve(t){let o=t.nodeType===Node.TEXT_NODE?t.parentElement:t;for(;o&&o instanceof HTMLElement;){if(o.tagName==="TD"||o.tagName==="TH")return o;o=o.parentElement}return null}function De(t){if(!t.isActive("tableCell")&&!t.isActive("tableHeader"))return null;const{node:o}=t.view.domAtPos(t.state.selection.from),l=ve(o);if(!l)return null;const i=l.parentElement,c=i.parentElement,a=l.closest("table");if(!a)return null;const h=Array.from(i.children).indexOf(l),g=Array.from(c.children).indexOf(i),C=i.children.length,p=c.children.length,n=l.getBoundingClientRect(),r=a.getBoundingClientRect(),m=t.view.dom.closest(".tiptap-editor").getBoundingClientRect();return{cell:l,colIndex:h,rowIndex:g,totalCols:C,totalRows:p,cellRect:n,tableRect:r,editorRect:m}}function $(t){const{state:o}=t,l=o.selection.from;let i=null;return o.doc.nodesBetween(0,o.doc.content.size,(c,a)=>{if(c.type.name==="table"&&a<=l&&l<=a+c.nodeSize)return i={node:c,pos:a},!1}),i}const _e=e.defineComponent({name:"TableControls",setup(){const t=e.inject("editor"),o=e.ref(null),l=e.ref(null);function i(){const p=t?.value;if(l.value&&(l.value.classList.remove("tcc-cell-focused"),l.value=null),!p){o.value=null;return}const n=De(p);o.value=n,n&&(n.cell.classList.add("tcc-cell-focused"),l.value=n.cell)}e.watchEffect(p=>{const n=t?.value;n&&(n.on("selectionUpdate",i),n.on("transaction",i),p(()=>{n.off("selectionUpdate",i),n.off("transaction",i),l.value&&(l.value.classList.remove("tcc-cell-focused"),l.value=null)}))});function c(p){const n=t?.value;if(!n||!o.value)return;const{colIndex:r,totalCols:m}=o.value,k=p==="left"?r-1:r+1;if(k<0||k>=m)return;const E=$(n);if(!E)return;const{node:w,pos:d}=E,u=[];w.forEach(N=>{if(N.type.name!=="tableRow"){u.push(N);return}const b=[];N.forEach(T=>b.push(T));const L=b[r];b[r]=b[k],b[k]=L,u.push(N.type.create(N.attrs,b,N.marks))});const f=w.type.create(w.attrs,u,w.marks),H=n.state.tr.replaceWith(d,d+w.nodeSize,f);n.view.dispatch(H)}function a(p){const n=t?.value;if(!n||!o.value)return;const{rowIndex:r,totalRows:m}=o.value,k=p==="up"?r-1:r+1;if(k<0||k>=m)return;const E=$(n);if(!E)return;const{node:w,pos:d}=E,u=[];w.forEach(b=>u.push(b));const f=u[r];u[r]=u[k],u[k]=f;const H=w.type.create(w.attrs,u,w.marks),N=n.state.tr.replaceWith(d,d+w.nodeSize,H);n.view.dispatch(N)}const h=()=>e.createVNode("svg",{width:"16",height:"4",viewBox:"0 0 16 4",fill:"currentColor"},[e.createVNode("circle",{cx:"2",cy:"2",r:"1.5"},null),e.createVNode("circle",{cx:"8",cy:"2",r:"1.5"},null),e.createVNode("circle",{cx:"14",cy:"2",r:"1.5"},null)]),g=()=>e.createVNode("svg",{width:"4",height:"16",viewBox:"0 0 4 16",fill:"currentColor"},[e.createVNode("circle",{cx:"2",cy:"2",r:"1.5"},null),e.createVNode("circle",{cx:"2",cy:"8",r:"1.5"},null),e.createVNode("circle",{cx:"2",cy:"14",r:"1.5"},null)]),C=()=>e.createVNode("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},[e.createVNode("path",{d:"M5 1v8M1 5h8"},null)]);return()=>{const p=o.value;if(!p)return null;const{colIndex:n,rowIndex:r,totalCols:m,totalRows:k,cellRect:E,tableRect:w,editorRect:d}=p,u=w.top-d.top,f=w.left-d.left,H=w.right-d.left,N=w.bottom-d.top,b=E.left-d.left,L=E.top-d.top,T=E.width,j=E.height,Qe={position:"absolute",top:`${u-20}px`,left:`${b+T/2-18}px`},Ye={position:"absolute",top:`${L+j/2-18}px`,left:`${f-20}px`},et={position:"absolute",top:`${L+j/2-12}px`,left:`${H+6}px`},tt={position:"absolute",top:`${N+6}px`,left:`${b+T/2-12}px`},ot=n===0,z=n===m-1,nt=r===0,O=r===k-1,M=t?.value;return e.createVNode("div",{class:"table-cell-controls"},[e.createVNode(s.ElDropdown,{trigger:"click",placement:"bottom",style:Qe,onCommand:B=>{B==="move-left"?c("left"):B==="move-right"?c("right"):B==="insert-left"?M?.chain().focus().addColumnBefore().run():B==="insert-right"?M?.chain().focus().addColumnAfter().run():B==="delete"&&M?.chain().focus().deleteColumn().run()}},{default:()=>[e.createVNode("button",{class:"tcc-btn tcc-btn--col"},[e.createVNode(h,null,null)])],dropdown:()=>e.createVNode(s.ElDropdownMenu,null,{default:()=>[e.createVNode(s.ElDropdownItem,{command:"move-left",disabled:ot},{default:()=>[e.createTextVNode("移动列到左侧")]}),e.createVNode(s.ElDropdownItem,{command:"move-right",disabled:z},{default:()=>[e.createTextVNode("移动列到右侧")]}),e.createVNode(s.ElDropdownItem,{command:"insert-left"},{default:()=>[e.createTextVNode("在左侧插入一列")]}),e.createVNode(s.ElDropdownItem,{command:"insert-right"},{default:()=>[e.createTextVNode("在右侧插入一列")]}),e.createVNode(s.ElDropdownItem,{command:"delete",divided:!0},{default:()=>[e.createTextVNode("删除列")]})]})}),e.createVNode(s.ElDropdown,{trigger:"click",placement:"right",style:Ye,onCommand:B=>{B==="move-up"?a("up"):B==="move-down"?a("down"):B==="insert-above"?M?.chain().focus().addRowBefore().run():B==="insert-below"?M?.chain().focus().addRowAfter().run():B==="delete"&&M?.chain().focus().deleteRow().run()}},{default:()=>[e.createVNode("button",{class:"tcc-btn tcc-btn--row"},[e.createVNode(g,null,null)])],dropdown:()=>e.createVNode(s.ElDropdownMenu,null,{default:()=>[e.createVNode(s.ElDropdownItem,{command:"move-up",disabled:nt},{default:()=>[e.createTextVNode("上移")]}),e.createVNode(s.ElDropdownItem,{command:"move-down",disabled:O},{default:()=>[e.createTextVNode("下移")]}),e.createVNode(s.ElDropdownItem,{command:"insert-above"},{default:()=>[e.createTextVNode("在上方插入一行")]}),e.createVNode(s.ElDropdownItem,{command:"insert-below"},{default:()=>[e.createTextVNode("在下方插入一行")]}),e.createVNode(s.ElDropdownItem,{command:"delete",divided:!0},{default:()=>[e.createTextVNode("删除行")]})]})}),z&&e.createVNode("button",{class:"tcc-btn tcc-btn--add",style:et,onClick:()=>M?.chain().focus().addColumnAfter().run()},[e.createVNode(C,null,null)]),O&&e.createVNode("button",{class:"tcc-btn tcc-btn--add",style:tt,onClick:()=>M?.chain().focus().addRowAfter().run()},[e.createVNode(C,null,null)])])}}}),Ze=e.defineComponent({name:"MathIcon",setup(t,{attrs:o}){return()=>e.createVNode("svg",e.mergeProps({width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},o),[e.createVNode("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M9 4.8c.1-.5.5-.8 1-.8h10a1 1 0 1 1 0 2h-9.2L8.3 19.2a1 1 0 0 1-1.7.4l-3.4-4.2a1 1 0 0 1 1.6-1.2l2 2.5L9 4.8Zm9.7 5.5c.4.4.4 1 0 1.4L17 13.5l1.8 1.8a1 1 0 1 1-1.4 1.4L15.5 15l-1.8 1.8a1 1 0 0 1-1.4-1.4l1.8-1.8-1.8-1.8a1 1 0 0 1 1.4-1.4l1.8 1.8 1.8-1.8a1 1 0 0 1 1.4 0Z",fill:"currentColor"},null)])}}),Re=e.defineComponent({name:"MathButton",setup(){const t=e.inject("editor"),o=e.inject("openMathDialog");return()=>e.createVNode(x,{icon:Ze,tooltip:"数学公式",isActive:t?.value?.isActive("inlineMath")||t?.value?.isActive("blockMath"),onClick:()=>o?.()},null)}}),Fe={class:"math-dialog"},Se={key:0,class:"math-preview__placeholder"},Ue=["innerHTML"],$e=((t,o)=>{const l=t.__vccOpts||t;for(const[i,c]of o)l[i]=c;return l})(e.defineComponent({__name:"MathEditDialog",props:{visible:{type:Boolean},latex:{},pos:{},type:{}},emits:["update:visible"],setup(t,{emit:o}){const l=t,i=o,c=e.inject("editor"),a=e.ref(""),h=e.ref("inline");e.watch(()=>l.latex,n=>{a.value=n},{immediate:!0}),e.watch(()=>l.type,n=>{h.value=n},{immediate:!0});const g=e.computed(()=>l.pos===null),C=e.computed(()=>a.value.trim()?J.renderToString(a.value,{displayMode:h.value==="block",throwOnError:!1}):""),p=()=>{const n=c?.value;if(!(!n||!a.value.trim())){if(g.value)h.value==="inline"?n.chain().focus().insertInlineMath({latex:a.value}).run():n.chain().focus().insertBlockMath({latex:a.value}).run();else if(h.value===l.type)l.type==="inline"?n.commands.updateInlineMath({latex:a.value,pos:l.pos}):n.commands.updateBlockMath({latex:a.value,pos:l.pos});else{const r=l.pos;l.type==="inline"?n.chain().focus().deleteInlineMath({pos:r}).insertBlockMath({latex:a.value}).run():n.chain().focus().deleteBlockMath({pos:r}).insertInlineMath({latex:a.value}).run()}i("update:visible",!1)}};return(n,r)=>(e.openBlock(),e.createBlock(e.unref(s.ElDialog),{"model-value":t.visible,title:g.value?"插入数学公式":"编辑数学公式",width:"520px","onUpdate:modelValue":r[3]||(r[3]=m=>i("update:visible",m))},{footer:e.withCtx(()=>[e.createVNode(e.unref(s.ElButton),{onClick:r[2]||(r[2]=m=>i("update:visible",!1))},{default:e.withCtx(()=>[...r[6]||(r[6]=[e.createTextVNode("取消",-1)])]),_:1}),e.createVNode(e.unref(s.ElButton),{type:"primary",disabled:!a.value.trim(),onClick:p},{default:e.withCtx(()=>[...r[7]||(r[7]=[e.createTextVNode("确认",-1)])]),_:1},8,["disabled"])]),default:e.withCtx(()=>[e.createElementVNode("div",Fe,[e.createVNode(e.unref(s.ElRadioGroup),{modelValue:h.value,"onUpdate:modelValue":r[0]||(r[0]=m=>h.value=m)},{default:e.withCtx(()=>[e.createVNode(e.unref(s.ElRadioButton),{value:"inline"},{default:e.withCtx(()=>[...r[4]||(r[4]=[e.createTextVNode("行内公式",-1)])]),_:1}),e.createVNode(e.unref(s.ElRadioButton),{value:"block"},{default:e.withCtx(()=>[...r[5]||(r[5]=[e.createTextVNode("块级公式",-1)])]),_:1})]),_:1},8,["modelValue"]),e.createVNode(e.unref(s.ElInput),{modelValue:a.value,"onUpdate:modelValue":r[1]||(r[1]=m=>a.value=m),type:"textarea",rows:3,placeholder:"请输入 LaTeX 公式,例如:E=mc^2"},null,8,["modelValue"]),e.createElementVNode("div",{class:e.normalizeClass(["math-preview",{"math-preview--empty":!C.value}])},[C.value?(e.openBlock(),e.createElementBlock("div",{key:1,innerHTML:C.value},null,8,Ue)):(e.openBlock(),e.createElementBlock("span",Se,"预览将在此处显示"))],2)])]),_:1},8,["model-value","title"]))}}),[["__scopeId","data-v-995dc22f"]]),je=[{value:"left",title:"居左",Icon:F},{value:"center",title:"居中",Icon:S},{value:"right",title:"居右",Icon:U}],A=t=>t.preventDefault();function ze(t){if(!t.isActive("image"))return null;const{selection:o}=t.state;if(!(o instanceof D.NodeSelection)||o.node.type.name!=="image")return null;const l=o.node;return{pos:o.from,nodeSize:l.nodeSize,src:l.attrs.src,align:l.attrs.align??"left"}}function Oe(t){const o=t.startsWith("data:")?"image.png":t.split("/").pop()?.split("?")[0]||"image.png",l=document.createElement("a");l.href=t,l.download=o,document.body.appendChild(l),l.click(),document.body.removeChild(l)}const qe=()=>e.createVNode("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createVNode("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"},null),e.createVNode("polyline",{points:"7 10 12 15 17 10"},null),e.createVNode("line",{x1:"12",y1:"15",x2:"12",y2:"3"},null)]),Pe=()=>e.createVNode("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createVNode("polyline",{points:"1 4 1 10 7 10"},null),e.createVNode("path",{d:"M3.51 15a9 9 0 1 0 .49-4.1L1 10"},null)]),We=()=>e.createVNode("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createVNode("polyline",{points:"3 6 5 6 21 6"},null),e.createVNode("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"},null),e.createVNode("path",{d:"M10 11v6M14 11v6"},null),e.createVNode("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"},null)]),Ke=e.defineComponent({name:"ImageControls",setup(){const t=e.inject("editor"),o=e.ref(null);function l(){const i=t?.value;if(!i){o.value=null;return}o.value=ze(i)}return e.watchEffect(i=>{const c=t?.value;c&&(c.on("transaction",l),i(()=>{c.off("transaction",l)}))}),()=>{const i=o.value;if(!i)return null;const c=t?.value;if(!c)return null;const{pos:a,nodeSize:h,src:g,align:C}=i,p=c.view.nodeDOM(a);if(!p||!(p instanceof HTMLElement))return null;const n=p.querySelector("[data-resize-wrapper]")??p,r=c.view.dom.closest(".tiptap-editor");if(!r)return null;const m=n.getBoundingClientRect(),k=r.getBoundingClientRect(),E={position:"absolute",top:`${m.top-k.top}px`,left:`${m.left-k.left+m.width/2}px`,transform:"translate(-50%, calc(-100% - 8px))",zIndex:20};return e.createVNode("div",{class:"image-controls",style:E},[je.map(({value:w,title:d,Icon:u})=>e.createVNode("button",{key:w,class:["image-controls-btn",C===w&&"is-active"],title:d,onMousedown:A,onClick:()=>c.chain().focus().updateAttributes("image",{align:w}).run()},[e.createVNode(u,null,null)])),e.createVNode("span",{class:"image-controls-separator"},null),e.createVNode("button",{class:"image-controls-btn",title:"下载",onMousedown:A,onClick:()=>Oe(g)},[e.createVNode(qe,null,null)]),e.createVNode("button",{class:"image-controls-btn",title:"重新上传",onMousedown:A,onClick:()=>c.chain().focus().deleteRange({from:a,to:a+h}).insertContentAt(a,{type:"imageUpload"}).run()},[e.createVNode(Pe,null,null)]),e.createVNode("button",{class:"image-controls-btn",title:"删除",onMousedown:A,onClick:()=>c.chain().focus().deleteRange({from:a,to:a+h}).run()},[e.createVNode(We,null,null)])])}}}),Ge={class:"tiptap-editor"},Je={class:"tiptap-toolbar"},Xe=e.defineComponent({__name:"TiptapEditor",props:{modelValue:{default:""},placeholder:{default:"请输入内容..."}},emits:["update:modelValue"],setup(t,{emit:o}){const l=t,i=o,c=e.ref(!1),a=e.ref(""),h=e.ref(null),g=e.ref("inline"),C=(n={})=>{a.value=n.latex??"",h.value=n.pos??null,g.value=n.type??"inline",c.value=!0};e.provide("openMathDialog",C);const p=y.useEditor({content:l.modelValue,extensions:[q.configure({link:{openOnClick:!1,enableClickSelection:!0}}),W.Placeholder.configure({placeholder:l.placeholder}),P.TextAlign.configure({types:["heading","paragraph"]}),v.TaskList,v.TaskItem.configure({nested:!0}),R.configure({allowBase64:!0,resize:{enabled:!0,directions:["top","right","bottom","left","top-right","top-left","bottom-right","bottom-left"],minWidth:50,minHeight:50,alwaysPreserveAspectRatio:!1}}),ie,I.Table.configure({resizable:!0}),I.TableRow,I.TableHeader,I.TableCell,G.Mathematics.configure({inlineOptions:{onClick:(n,r)=>C({latex:n.attrs.latex,pos:r,type:"inline"})},blockOptions:{onClick:(n,r)=>C({latex:n.attrs.latex,pos:r,type:"block"})}})],onUpdate:({editor:n})=>{i("update:modelValue",n.getHTML())}});return e.provide("editor",p),e.watch(()=>l.modelValue,n=>{p.value&&n!==p.value.getHTML()&&p.value.commands.setContent(n,{emitUpdate:!1})}),(n,r)=>(e.openBlock(),e.createElementBlock("div",Ge,[e.createElementVNode("div",Je,[e.createVNode(e.unref(se)),r[1]||(r[1]=e.createElementVNode("div",{class:"tiptap-separator"},null,-1)),e.createVNode(e.unref(Ne)),r[2]||(r[2]=e.createElementVNode("div",{class:"tiptap-separator"},null,-1)),e.createVNode(e.unref(Be)),r[3]||(r[3]=e.createElementVNode("div",{class:"tiptap-separator"},null,-1)),e.createVNode(e.unref(ke)),r[4]||(r[4]=e.createElementVNode("div",{class:"tiptap-separator"},null,-1)),e.createVNode(e.unref(ye)),e.createVNode(e.unref(Te)),e.createVNode(e.unref(Re))]),e.createVNode(e.unref(y.EditorContent),{class:"tiptap-content",editor:e.unref(p)},null,8,["editor"]),e.createVNode(e.unref(_e)),e.createVNode(e.unref(Ke)),e.createVNode($e,{visible:c.value,"onUpdate:visible":r[0]||(r[0]=m=>c.value=m),latex:a.value,pos:h.value,type:g.value},null,8,["visible","latex","pos","type"])]))}});V.IconButton=x,V.ImageWithAlign=R,V.TiptapEditor=Xe,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mario9/tiptap-editor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/tiptap-vue.umd.cjs",
|
|
6
|
+
"module": "./dist/tiptap-vue.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/tiptap-vue.js",
|
|
10
|
+
"require": "./dist/tiptap-vue.umd.cjs"
|
|
11
|
+
},
|
|
12
|
+
"./style.css": "./dist/style.css"
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vite",
|
|
20
|
+
"build": "vue-tsc -b && vite build",
|
|
21
|
+
"build:lib": "vue-tsc -b && vite build --mode lib",
|
|
22
|
+
"preview": "vite preview"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@tiptap/core": "^3.20.0",
|
|
26
|
+
"@tiptap/extension-highlight": "^3.20.0",
|
|
27
|
+
"@tiptap/extension-horizontal-rule": "^3.20.0",
|
|
28
|
+
"@tiptap/extension-image": "^3.20.0",
|
|
29
|
+
"@tiptap/extension-list": "^3.20.0",
|
|
30
|
+
"@tiptap/extension-mathematics": "^3.20.0",
|
|
31
|
+
"@tiptap/extension-subscript": "^3.20.0",
|
|
32
|
+
"@tiptap/extension-superscript": "^3.20.0",
|
|
33
|
+
"@tiptap/extension-table": "^3.20.0",
|
|
34
|
+
"@tiptap/extension-text-align": "^3.20.0",
|
|
35
|
+
"@tiptap/extension-typography": "^3.20.0",
|
|
36
|
+
"@tiptap/extensions": "^3.20.0",
|
|
37
|
+
"@tiptap/pm": "^3.20.0",
|
|
38
|
+
"@tiptap/starter-kit": "^3.20.0",
|
|
39
|
+
"@tiptap/vue-3": "^3.20.0",
|
|
40
|
+
"element-plus": "^2.13.0",
|
|
41
|
+
"katex": "^0.16.0",
|
|
42
|
+
"vue": "^3.5.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^24.10.1",
|
|
47
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
48
|
+
"@vitejs/plugin-vue-jsx": "^5.1.4",
|
|
49
|
+
"@vue/tsconfig": "^0.8.1",
|
|
50
|
+
"sass-embedded": "^1.97.3",
|
|
51
|
+
"typescript": "~5.9.3",
|
|
52
|
+
"unplugin-element-plus": "^0.11.2",
|
|
53
|
+
"vite": "^7.3.1",
|
|
54
|
+
"vite-plugin-dts": "^4.5.4",
|
|
55
|
+
"vue-tsc": "^3.1.5"
|
|
56
|
+
}
|
|
57
|
+
}
|