index-fcf30747.js 1.9 KB

1
  1. import{c as A,m as F,n as D,A as R,S as I,K as L,T as M,D as O,F as _,w as z}from"./index-f74a9797.js";import{b as K}from"./function-call-2cfc4e68.js";import{u as V}from"./use-expose-8ee00450.js";import{d as X,r as m,s as $,a as x,c as v}from"./index-df5648cd.js";import{c as j}from"./on-popup-reopen-80498ca6.js";const[q,p]=A("swipe-cell"),G={name:F(""),disabled:Boolean,leftWidth:D,rightWidth:D,beforeClose:Function,stopPropagation:Boolean};var J=X({name:q,props:G,emits:["open","close","click"],setup(t,{emit:i,slots:r}){let n,c,f;const u=m(),C=m(),k=m(),o=$({offset:0,dragging:!1}),l=K(),w=e=>e.value?M(e).width:0,d=x(()=>R(t.leftWidth)?+t.leftWidth:w(C)),g=x(()=>R(t.rightWidth)?+t.rightWidth:w(k)),T=e=>{o.offset=e==="left"?d.value:-g.value,n||(n=!0,i("open",{name:t.name,position:e}))},h=e=>{o.offset=0,n&&(n=!1,i("close",{name:t.name,position:e}))},y=e=>{const a=Math.abs(o.offset),s=.15,B=n?1-s:s,E=e==="left"?d.value:g.value;E&&a>E*B?T(e):h(e)},H=e=>{t.disabled||(f=o.offset,l.start(e))},N=e=>{if(t.disabled)return;const{deltaX:a}=l;l.move(e),l.isHorizontal()&&(c=!0,o.dragging=!0,(!n||a.value*f<0)&&O(e,t.stopPropagation),o.offset=_(a.value+f,-g.value,d.value))},W=()=>{o.dragging&&(o.dragging=!1,y(o.offset>0?"left":"right"),setTimeout(()=>{c=!1},0))},b=(e="outside")=>{i("click",e),n&&!c&&j(t.beforeClose,{args:[{name:t.name,position:e}],done:()=>h(e)})},S=(e,a)=>s=>{a&&s.stopPropagation(),b(e)},P=(e,a)=>{const s=r[e];if(s)return v("div",{ref:a,class:p(e),onClick:S(e,!0)},[s()])};return V({open:T,close:h}),I(u,()=>b("outside"),{eventName:"touchstart"}),L("touchmove",N,{target:u}),()=>{var e;const a={transform:`translate3d(${o.offset}px, 0, 0)`,transitionDuration:o.dragging?"0s":".6s"};return v("div",{ref:u,class:p(),onClick:S("cell",c),onTouchstartPassive:H,onTouchend:W,onTouchcancel:W},[v("div",{class:p("wrapper"),style:a},[P("left",C),(e=r.default)==null?void 0:e.call(r),P("right",k)])])}}});const te=z(J);export{te as S};