"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("vue"),k=require("../../_util/BaseInput.js"),i=require("../../_util/KeyCode.js"),_=require("../../_util/classNames.js"),$=require("../../_util/omit.js"),z=require("../../_util/props-util/initDefaultProps.js"),G=require("./KeywordTrigger.js"),H=require("./MentionsContext.js"),E=require("./mentionsProps.js"),h=require("./util.js");function F(){}const J=s.defineComponent({compatConfig:{MODE:3},name:"Mentions",inheritAttrs:!1,props:z.default(E.vcMentionsProps,E.defaultProps),emits:["change","select","search","focus","blur","pressenter"],setup(r,{emit:l,attrs:L,expose:D,slots:N}){const S=s.ref(null),f=s.ref(null),M=s.ref(),t=s.reactive({value:r.value||"",measuring:!1,measureLocation:0,measureText:null,measurePrefix:"",activeIndex:0,isFocus:!1});s.watchEffect(()=>{t.value=r.value});const O=e=>{l("change",e)},K=({target:{value:e}})=>{O(e)},V=(e,n,o)=>{Object.assign(t,{measuring:!0,measureText:e,measurePrefix:n,measureLocation:o,activeIndex:0})},d=e=>{Object.assign(t,{measuring:!1,measureLocation:0,measureText:null}),e?.()},B=e=>{const{which:n}=e;if(t.measuring){if(n===i.default.UP||n===i.default.DOWN){const o=v.value.length,u=n===i.default.UP?-1:1,a=(t.activeIndex+u+o)%o;t.activeIndex=a,e.preventDefault()}else if(n===i.default.ESC)d();else if(n===i.default.ENTER){if(e.preventDefault(),!v.value.length){d();return}const o=v.value[t.activeIndex];y(o)}}},U=e=>{const{key:n,which:o}=e,{measureText:u,measuring:a}=t,{prefix:P,validateSearch:T}=r,m=e.target;if(m.composing)return;const x=h.getBeforeSelectionText(m),{location:g,prefix:p}=h.getLastMeasureIndex(x,P);if(![i.default.ESC,i.default.UP,i.default.DOWN,i.default.ENTER].includes(o))if(g!==-1){const c=x.slice(g+p.length),I=T(c,r),C=!!w(c).length;I?(n===p||n==="Shift"||a||c!==u&&C)&&V(c,p,g):a&&d(),I&&l("search",c,p)}else a&&d()},A=e=>{t.measuring||l("pressenter",e)},R=e=>{b(e)},j=e=>{q(e)},b=e=>{clearTimeout(M.value);const{isFocus:n}=t;!n&&e&&l("focus",e),t.isFocus=!0},q=e=>{M.value=setTimeout(()=>{t.isFocus=!1,d(),l("blur",e)},100)},y=e=>{const{split:n}=r,{value:o=""}=e,{text:u,selectionLocation:a}=h.replaceWithMeasure(t.value,{measureLocation:t.measureLocation,targetText:o,prefix:t.measurePrefix,selectionStart:f.value.getSelectionStart(),split:n});O(u),d(()=>{h.setInputSelection(f.value.input,a)}),l("select",e,t.measurePrefix)},W=e=>{t.activeIndex=e},w=e=>{const n=e||t.measureText||"",{filterOption:o}=r;return r.options.filter(a=>o?o(n,a):!0)},v=s.computed(()=>w());return D({blur:()=>{f.value.blur()},focus:()=>{f.value.focus()}}),s.provide(H.default,{activeIndex:s.toRef(t,"activeIndex"),setActiveIndex:W,selectOption:y,onFocus:b,onBlur:q,loading:s.toRef(r,"loading")}),s.onUpdated(()=>{s.nextTick(()=>{t.measuring&&(S.value.scrollTop=f.value.getScrollTop())})}),()=>{const{measureLocation:e,measurePrefix:n,measuring:o}=t,{prefixCls:u,placement:a,transitionName:P,getPopupContainer:T,direction:m,...x}=r,{class:g,style:p,...c}=L,C={...$.default(x,["value","prefix","split","validateSearch","filterOption","options","loading"]),...c,onChange:F,onSelect:F,value:t.value,onInput:K,onBlur:j,onKeydown:B,onKeyup:U,onFocus:R,onPressenter:A};return s.createVNode("div",{class:_.default(u,g),style:p},[s.createVNode(k.default,{...C,ref:f,tag:"textarea"},null),o&&s.createVNode("div",{ref:S,class:`${u}-measure`},[t.value.slice(0,e),s.createVNode(G.default,{prefixCls:u,transitionName:P,dropdownClassName:r.dropdownClassName,placement:a,options:o?v.value:[],visible:!0,direction:m,getPopupContainer:T},{default:()=>[s.createVNode("span",null,[n])],notFoundContent:N.notFoundContent,option:N.option}),t.value.slice(e+n.length)])])}}});exports.default=J;
