"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),l=require("element-plus"),y=require("../../../node_modules/.pnpm/@element-plus_icons-vue@2.3.1_vue@3.4.21/node_modules/@element-plus/icons-vue/dist/index.js"),E=require("../symbol.js"),x=require("../async-import.js"),h={key:0},N={style:{"text-align":"right"}},b=e.defineComponent({__name:"image-insert",setup(_){let s;const{quill:a,httpRequest:f}=e.inject(E.SymbolState),m=e.shallowRef(),d=e.shallowRef(!1),r=e.ref({url:"",name:""}),g=[{key:1,label:"图片链接"},{key:2,label:"内联图片"},{key:3,label:"上传图片"}],v=async(o,n)=>{const t=o.file;if(n==="inline"){const u=new FileReader;u.onload=function(i){if(i.target){const w=i.target.result,c=a.value.getSelection(!0);c&&(a.value.insertEmbed(c.index,"image",w),a.value.setSelection(c.index+1,s.sources.SILENT))}else l.ElMessage.error("图片错误，请重新选择")},u.readAsDataURL(t)}else{const u=await f.value(o),i=a.value.getSelection(!0);i&&(a.value.insertEmbed(i.index,"image",u),a.value.setSelection(i.index+1,s.sources.SILENT))}},V=o=>{o===1&&(d.value=!0)},p=()=>{d.value=!1},k=async()=>{var n;await((n=m.value)==null?void 0:n.validate());const o=a.value.getSelection(!0);o&&(a.value.insertEmbed(o.index,"image",r.value.url),a.value.setSelection(o.index+1,s.sources.SILENT),p())};return e.onMounted(async()=>{s=await x.default()}),(o,n)=>(e.openBlock(),e.createElementBlock("span",null,[e.createVNode(e.unref(l.ElDropdown),null,{dropdown:e.withCtx(()=>[e.createVNode(e.unref(l.ElDropdownMenu),null,{default:e.withCtx(()=>[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(g,t=>e.createVNode(e.unref(l.ElDropdownItem),{disabled:t.key===3&&!e.unref(f),onClick:()=>V(t.key),key:t.key},{default:e.withCtx(()=>[t.key===1?(e.openBlock(),e.createElementBlock("span",h,e.toDisplayString(t.label),1)):(e.openBlock(),e.createBlock(e.unref(l.ElUpload),{key:1,"show-file-list":!1,"http-request":u=>v(u,t.key===2?"inline":"upload")},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.label),1)]),_:2},1032,["http-request"]))]),_:2},1032,["disabled","onClick"])),64))]),_:1})]),default:e.withCtx(()=>[e.createElementVNode("button",null,[e.createVNode(e.unref(l.ElIcon),{size:18},{default:e.withCtx(()=>[e.createVNode(e.unref(y.PictureFilled))]),_:1})])]),_:1}),e.createVNode(e.unref(l.ElDialog),{class:"wet-quill-imagelink",width:"400","append-to-body":"",title:"插入图片",modelValue:d.value,"onUpdate:modelValue":n[2]||(n[2]=t=>d.value=t),modal:!1,"show-close":!1},{default:e.withCtx(()=>[e.createVNode(e.unref(l.ElForm),{model:r.value,ref_key:"formins",ref:m},{default:e.withCtx(()=>[e.createVNode(e.unref(l.ElFormItem),{label:"图片名称",prop:"name",rules:[{required:!0,message:"图片名称不能为空"}]},{default:e.withCtx(()=>[e.createVNode(e.unref(l.ElInput),{modelValue:r.value.name,"onUpdate:modelValue":n[0]||(n[0]=t=>r.value.name=t)},null,8,["modelValue"])]),_:1}),e.createVNode(e.unref(l.ElFormItem),{label:"图片链接",prop:"url",rules:[{required:!0,type:"url",message:"图片链接不能为空/url格式不正确"}]},{default:e.withCtx(()=>[e.createVNode(e.unref(l.ElInput),{modelValue:r.value.url,"onUpdate:modelValue":n[1]||(n[1]=t=>r.value.url=t)},null,8,["modelValue"])]),_:1})]),_:1},8,["model"]),e.createElementVNode("div",N,[e.createVNode(e.unref(l.ElButton),{onClick:p},{default:e.withCtx(()=>[e.createTextVNode("取消")]),_:1}),e.createVNode(e.unref(l.ElButton),{type:"primary",onClick:k},{default:e.withCtx(()=>[e.createTextVNode("确定")]),_:1})])]),_:1},8,["modelValue"])]))}});exports.default=b;
