const e=require("../_util/classNames.js"),t=require("../_util/KeyCode.js"),n=require("../input/TextArea.js"),r=require("./style/index.js");let i=require("vue"),a=require("@antsoo-lib/icons");var o=(0,i.defineComponent)({compatConfig:{MODE:3},name:`Editable`,inheritAttrs:!1,props:{prefixCls:String,value:String,maxlength:Number,autoSize:{type:[Boolean,Object]},onSave:Function,onCancel:Function,onEnd:Function,onChange:Function,originContent:String,direction:String,component:String},setup(o,{emit:s,slots:c,attrs:l}){let{prefixCls:u}=(0,i.toRefs)(o),d=(0,i.reactive)({current:o.value||``,lastKeyCode:void 0,inComposition:!1,cancelFlag:!1});(0,i.watch)(()=>o.value,e=>{d.current=e});let f=(0,i.ref)();(0,i.onMounted)(()=>{if(f.value){let e=f.value?.resizableTextArea?.textArea;e.focus();let{length:t}=e.value;e.setSelectionRange(t,t)}});function p(e){f.value=e}function m({target:{value:e}}){d.current=e.replace(/[\r\n]/g,``),s(`change`,d.current)}function h(){d.inComposition=!0}function g(){d.inComposition=!1}function _(e){let{keyCode:n}=e;n===t.default.ENTER&&e.preventDefault(),!d.inComposition&&(d.lastKeyCode=n)}function v(e){let{keyCode:n,ctrlKey:r,altKey:i,metaKey:a,shiftKey:c}=e;d.lastKeyCode===n&&!d.inComposition&&!r&&!i&&!a&&!c&&(n===t.default.ENTER?(b(),s(`end`)):n===t.default.ESC&&(d.current=o.originContent,s(`cancel`)))}function y(){b()}function b(){s(`save`,d.current.trim())}let[x,S]=r.default(u);return()=>{let t=e.default({[`${u.value}`]:!0,[`${u.value}-edit-content`]:!0,[`${u.value}-rtl`]:o.direction===`rtl`,[o.component?`${u.value}-${o.component}`:``]:!0},l.class,S.value);return x((0,i.createVNode)(`div`,{...l,class:t},[(0,i.createVNode)(n.default,{ref:p,maxlength:o.maxlength,value:d.current,onChange:m,onKeydown:_,onKeyup:v,onCompositionstart:h,onCompositionend:g,onBlur:y,rows:1,autoSize:o.autoSize===void 0||o.autoSize},null),c.enterIcon?c.enterIcon({className:`${o.prefixCls}-edit-content-confirm`}):(0,i.createVNode)(a.EnterOutlined,{class:`${o.prefixCls}-edit-content-confirm`},null)]))}}});exports.default=o;