3 lines
3.8 KiB
Java
3 lines
3.8 KiB
Java
import{e as U,a4 as W,c as x,r as f,h as z,o as X,K as Z,C as b,z as s,H as A,f as S,J as g,u as h,Q as m,G as T,A as w,y as _,F as ee,D as ae}from"./vue-vendor-DNhG1Cve.js";import{bo as te,aR as ne,aS as le,bL as ue,w as O}from"./index-X7Y8jykP.js";import"./index-CfNJyBRj.js";import{D as oe}from"./dropdown-jkliuVyN.js";import"./emoji-mart-vue-fast-R0uJEDq-.js";const se={style:{display:"flex","justify-content":"space-between"}},re={style:{color:"#999999"}},ie=["contenteditable"],me=U({__name:"VarTextarea",props:{value:{type:String,required:!0},type:{type:String,default:"textarea"},placeholder:{type:String,default:""},width:{type:[Number,String],default:300},height:{type:[Number,String],default:80},minHeight:{type:Number,default:32},varsOptions:{type:Array,default:()=>[]},readonly:{type:Boolean,default:!1}},emits:["update:value","blur","focus"],setup(r,{emit:R}){W(e=>({ae0931ae:F.value,v1c2aee25:Y.value}));const{prefixCls:y}=te("airag-var-textarea"),t=r,i=R,n=f(),v=x(()=>t.type==="input"),V=x(()=>!O(t.placeholder)&&O(t.value)),F=x(()=>v.value?typeof t.width=="number"?`${t.width}px`:t.width:"100%"),u=f(t.height);z(()=>t.height,e=>u.value=e);const Y=x(()=>v.value?"32px":typeof u.value=="number"?`${u.value}px`:u.value),k=f(t.value),C=f(!0),E=f(!1);z(()=>t.value,e=>{if(e===`
|
|
`){e="",i("update:value",e);return}C.value&&$(e)});const c=f(!1);let l=null,d=null;function H(e){if(c.value=!1,e.data==="/"){const a=window.getSelection();if(a){const p=document.createRange();p.setStart(a.anchorNode,a.anchorOffset-1),p.setEnd(a.anchorNode,a.anchorOffset),a.removeAllRanges(),a.addRange(p),d=p,l=a}c.value=!0}const o=n.value.innerText;i("update:value",o)}function K(e){E.value=!1,C.value=!0,i("blur",e),setTimeout(()=>{c.value&&(c.value=!1)},300)}function M(e){E.value=!0,C.value=!1,i("focus",e)}function $(e){v.value?k.value=e.replace(/\n/g,""):k.value=e,n.value&&(n.value.innerText=k.value)}function j({key:e}){e=`{{${e}}}`,n.value.focus(),d?(d.deleteContents(),d.insertNode(document.createTextNode(e)),l==null||l.removeAllRanges(),l==null||l.addRange(d),l==null||l.collapseToEnd()):n.value.innerText+=e,c.value=!1,v.value?i("update:value",n.value.innerText.replace(/\n/g,"")):i("update:value",n.value.innerText),d=null,l=null}function q(e){v.value&&e.key==="Enter"&&e.preventDefault()}function G(e){const o=e.clipboardData||window.clipboardData;if(!o)return;e.preventDefault();const a=o.getData("text/plain");document.execCommand("insertText",!1,a)}X(()=>{$(t.value)});let D=0;function I(e){D=e.clientY,n.value.style.pointerEvents="none",window.addEventListener("mousemove",B),window.addEventListener("mouseup",L)}function L(){window.removeEventListener("mousemove",B),window.removeEventListener("mouseup",L),n.value.style.pointerEvents="auto"}function B(e){if(typeof u.value!="number")return;const o=e.clientY-D,a=u.value+o;a>t.minHeight&&(u.value=a),D=e.clientY}return(e,o)=>{const a=Z("Icon"),p=le,P=ne,J=ue,Q=oe;return s(),b("div",{class:g([h(y),r.type,{focus:E.value}])},[V.value?(s(),b("div",{key:0,class:g([`${h(y)}-place`])},[m("span",null,T(r.placeholder),1)],2)):A("",!0),S(Q,{open:c.value},{overlay:w(()=>[r.varsOptions.length?(s(),_(P,{key:0,onClick:j},{default:w(()=>[(s(!0),b(ee,null,ae(r.varsOptions,N=>(s(),_(p,{key:N.name},{icon:w(()=>[S(a,{icon:"mdi:variable"})]),default:w(()=>[m("div",se,[m("div",null,T(N.name),1),m("div",re,T(N.type),1)])]),_:2},1024))),128))]),_:1})):(s(),_(J,{key:1,description:"没有变量可选"}))]),default:w(()=>[m("div",{class:g([`${h(y)}-border`])},[m("div",{ref_key:"inputRef",ref:n,class:g([`${h(y)}-inner`]),contenteditable:r.readonly?"false":"true",onInput:H,onBlur:K,onFocus:M,onKeydown:q,onPaste:G},null,42,ie),v.value?A("",!0):(s(),b("div",{key:0,class:g([`${h(y)}-resize`]),onMousedown:I},[S(a,{icon:"hugeicons:resize-field"})],34))],2)]),_:1},8,["open"])],2)}}});export{me as default};
|