index-legacy-2c98c5e9.js 7.0 KB

1
  1. System.register(["./index-legacy-e1ea41b7.js"],(function(e,t){"use strict";var l,n,o,i,a,s,u,c,r,v,p,d,m,f,h,b,g,x,y,w,H,O,k,T,I,S,N,C,D,B,M;return{setters:[e=>{l=e.c,n=e.X,o=e.ac,i=e.$,a=e.d,s=e.n,u=e.b6,c=e.ab,r=e.r,v=e.u,p=e.e,d=e.ad,m=e.Y,f=e.aD,h=e.Z,b=e.a,g=e.p,x=e.H,y=e.b,w=e.t,H=e.m,O=e.aa,k=e.bE,T=e.w,I=e.aS,S=e.L,N=e.ae,C=e.h,D=e.z,B=e.bF,M=e.k}],execute:function(){const[t,V,$]=l("picker"),P=e=>e.find((e=>!e.disabled))||e[0];function j(e,t){for(let l=t=i(t,0,e.length);l<e.length;l++)if(!e[l].disabled)return l;for(let l=t-1;l>=0;l--)if(!e[l].disabled)return l;return 0}const E=(e,t,l)=>void 0!==t&&!!e.find((e=>e[l.value]===t));function F(e,t,l){const n=e.findIndex((e=>e[l.value]===t));return e[j(e,n)]}const[z,A]=l("picker-column"),L=Symbol(z);var Y=a({name:z,props:{value:s,fields:u(Object),options:c(),readonly:Boolean,allowHtml:Boolean,optionHeight:u(Number),swipeDuration:u(s),visibleOptionNum:u(s)},emits:["change","clickOption","scrollInto"],setup(e,{emit:t,slots:l}){let n,o,a,s,u;const c=r(),x=r(),y=r(0),w=r(0),H=v(),O=()=>e.options.length,k=()=>e.optionHeight*(+e.visibleOptionNum-1)/2,T=l=>{let o=j(e.options,l);const i=-o*e.optionHeight,a=()=>{o>O()-1&&(o=j(e.options,l));const n=e.options[o][e.fields.value];n!==e.value&&t("change",n)};n&&i!==y.value?u=a:a(),y.value=i},I=()=>e.readonly||!e.options.length,S=t=>i(Math.round(-t/e.optionHeight),0,O()-1),N=p((()=>S(y.value))),C=()=>{n=!1,w.value=0,u&&(u(),u=null)},D=e=>{if(!I()){if(H.start(e),n){const e=function(e){const{transform:t}=window.getComputedStyle(e),l=t.slice(7,t.length-1).split(", ")[5];return Number(l)}(x.value);y.value=Math.min(0,e-k())}w.value=0,o=y.value,a=Date.now(),s=o,u=null}},B=()=>{if(I())return;const t=y.value-s,l=Date.now()-a;if(l<300&&Math.abs(t)>15)return void((t,l)=>{const n=Math.abs(t/l);t=y.value+n/.003*(t<0?-1:1);const o=S(t);w.value=+e.swipeDuration,T(o)})(t,l);const o=S(y.value);w.value=200,T(o),setTimeout((()=>{n=!1}),0)},M=()=>{const o={height:`${e.optionHeight}px`};return e.options.map(((i,a)=>{const s=i[e.fields.text],{disabled:c}=i,r=i[e.fields.value],v={role:"button",style:o,tabindex:c?-1:0,class:[A("item",{disabled:c,selected:r===e.value}),i.className],onClick:()=>(l=>{n||I()||(u=null,w.value=200,T(l),t("clickOption",e.options[l]))})(a)},p={class:"van-ellipsis",[e.allowHtml?"innerHTML":"textContent"]:s};return b("li",v,[l.option?l.option(i,a):b("div",p,null)])}))};return d(L),m({stopMomentum:C}),f((()=>{const t=n?Math.floor(-y.value/e.optionHeight):e.options.findIndex((t=>t[e.fields.value]===e.value)),l=j(e.options,t),o=-l*e.optionHeight;n&&l<t&&C(),y.value=o})),h("touchmove",(l=>{if(I())return;H.move(l),H.isVertical()&&(n=!0,g(l,!0));const u=i(o+H.deltaY.value,-O()*e.optionHeight,e.optionHeight),c=S(u);c!==N.value&&t("scrollInto",e.options[c]),y.value=u;const r=Date.now();r-a>300&&(a=r,s=u)}),{target:c}),()=>b("div",{ref:c,class:A(),onTouchstartPassive:D,onTouchend:B,onTouchcancel:B},[b("ul",{ref:x,style:{transform:`translate3d(0, ${y.value+k()}px, 0)`,transitionDuration:`${w.value}ms`,transitionProperty:w.value?"all":"none"},class:A("wrapper"),onTransitionend:C},[M()])])}});const[X]=l("picker-toolbar"),Z={title:String,cancelButtonText:String,confirmButtonText:String},q=["cancel","confirm","title","toolbar"],G=Object.keys(Z);var J=a({name:X,props:Z,emits:["confirm","cancel"],setup(e,{emit:t,slots:l}){const n=()=>t("cancel"),o=()=>t("confirm"),i=()=>{const t=e.cancelButtonText||$("cancel");return b("button",{type:"button",class:[V("cancel"),x],onClick:n},[l.cancel?l.cancel():t])},a=()=>{const t=e.confirmButtonText||$("confirm");return b("button",{type:"button",class:[V("confirm"),x],onClick:o},[l.confirm?l.confirm():t])};return()=>b("div",{class:V("toolbar")},[l.toolbar?l.toolbar():[i(),l.title?l.title():e.title?b("div",{class:[V("title"),"van-ellipsis"]},[e.title]):void 0,a()]])}});const[K,Q]=l("picker-group"),R=Symbol(K);o({tabs:c(),activeTab:y(0),nextStepText:String},Z);const U=e("p",o({loading:Boolean,readonly:Boolean,allowHtml:Boolean,optionHeight:y(44),showToolbar:w,swipeDuration:y(1e3),visibleOptionNum:y(6)},Z)),W=o({},U,{columns:c(),modelValue:c(),toolbarPosition:H("top"),columnsFieldNames:Object});var _=a({name:t,props:W,emits:["confirm","cancel","change","scrollInto","clickOption","update:modelValue"],setup(e,{emit:t,slots:l}){const i=r(),a=r(e.modelValue.slice(0)),{parent:s}=d(R),{children:u,linkChildren:c}=O(L);c();const v=p((()=>function(e){return o({text:"text",value:"value",children:"children"},e)}(e.columnsFieldNames))),f=p((()=>k(e.optionHeight))),x=p((()=>function(e,t){const l=e[0];if(l){if(Array.isArray(l))return"multiple";if(t.children in l)return"cascade"}return"default"}(e.columns,v.value))),y=p((()=>{const{columns:t}=e;switch(x.value){case"multiple":return t;case"cascade":return function(e,t,l){const o=[];let i={[t.children]:e},a=0;for(;i&&i[t.children];){const e=i[t.children],s=l.value[a];i=n(s)?F(e,s,t):void 0,!i&&e.length&&(i=F(e,P(e)[t.value],t)),a++,o.push(e)}return o}(t,v.value,a);default:return[t]}})),w=p((()=>y.value.some((e=>e.length)))),H=p((()=>y.value.map(((e,t)=>F(e,a.value[t],v.value))))),M=p((()=>y.value.map(((e,t)=>e.findIndex((e=>e[v.value.value]===a.value[t])))))),$=(e,t)=>{if(a.value[e]!==t){const l=a.value.slice(0);l[e]=t,a.value=l}},j=()=>({selectedValues:a.value.slice(0),selectedOptions:H.value,selectedIndexes:M.value}),z=()=>{u.forEach((e=>e.stopMomentum()));const e=j();return D((()=>{t("confirm",e)})),e},A=()=>t("cancel",j()),X=()=>y.value.map(((n,i)=>b(Y,{value:a.value[i],fields:v.value,options:n,readonly:e.readonly,allowHtml:e.allowHtml,optionHeight:f.value,swipeDuration:e.swipeDuration,visibleOptionNum:e.visibleOptionNum,onChange:e=>((e,l)=>{$(l,e),"cascade"===x.value&&a.value.forEach(((e,t)=>{const l=y.value[t];E(l,e,v.value)||$(t,l.length?l[0][v.value.value]:void 0)})),D((()=>{t("change",o({columnIndex:l},j()))}))})(e,i),onClickOption:e=>((e,l)=>{const n={columnIndex:l,currentOption:e};t("clickOption",o(j(),n)),t("scrollInto",n)})(e,i),onScrollInto:e=>{t("scrollInto",{currentOption:e,columnIndex:i})}},{option:l.option}))),Z=e=>{if(w.value){const t={height:`${f.value}px`},l={backgroundSize:`100% ${(e-f.value)/2}px`};return[b("div",{class:V("mask"),style:l},null),b("div",{class:[B,V("frame")],style:t},null)]}},K=()=>{const t=f.value*+e.visibleOptionNum,l={height:`${t}px`};return b("div",{ref:i,class:V("columns"),style:l},[X(),Z(t)])},Q=()=>{if(e.showToolbar&&!s)return b(J,C(N(e,G),{onConfirm:z,onCancel:A}),N(l,q))};let U;return T(y,(e=>{e.forEach(((e,t)=>{e.length&&!E(e,a.value[t],v.value)&&$(t,P(e)[v.value.value])}))}),{immediate:!0}),T((()=>e.modelValue),(e=>{I(e,a.value)||I(e,U)||(a.value=e.slice(0),U=e.slice(0))}),{deep:!0}),T(a,(l=>{I(l,e.modelValue)||(U=l.slice(0),t("update:modelValue",U))}),{immediate:!0}),h("touchmove",g,{target:i}),m({confirm:z,getSelectedOptions:()=>H.value}),()=>{var t,n;return b("div",{class:V()},["top"===e.toolbarPosition?Q():null,e.loading?b(S,{class:V("loading")},null):null,null==(t=l["columns-top"])?void 0:t.call(l),K(),null==(n=l["columns-bottom"])?void 0:n.call(l),"bottom"===e.toolbarPosition?Q():null])}}});e("P",M(_))}}}));