index.36db2313.js 10 KB

1
  1. import{t as L,d as Z,aB as j,aC as me,y as x,c,aD as he,R as E,aE as ge,U as ve,W as fe,z as ee,an as te,aF as ye,am as q,u as se,v as H,w as De,aG as ne,Z as X,aH as we,P as be,aI as p,ar as ke,E as Se,o as ce,B as Te,D as xe}from"./index.1c621181.js";import{u as Re}from"./index.88a00aa9.js";import{g as Me}from"./utils.3d9f83cd.js";const[Oe,d,W]=L("calendar"),Ce=e=>W("monthTitle",e.getFullYear(),e.getMonth()+1);function ae(e,s){const i=e.getFullYear(),m=s.getFullYear();if(i===m){const b=e.getMonth(),S=s.getMonth();return b===S?0:b>S?1:-1}return i>m?1:-1}function R(e,s){const i=ae(e,s);if(i===0){const m=e.getDate(),b=s.getDate();return m===b?0:m>b?1:-1}return i}const G=e=>new Date(e),ue=e=>Array.isArray(e)?e.map(G):G(e);function le(e,s){const i=G(e);return i.setDate(i.getDate()+s),i}const oe=e=>le(e,-1),de=e=>le(e,1),re=()=>{const e=new Date;return e.setHours(0,0,0,0),e};function Pe(e){const s=e[0].getTime();return(e[1].getTime()-s)/(1e3*60*60*24)+1}const[Be]=L("calendar-day");var Ae=Z({name:Be,props:{item:j(Object),color:String,index:Number,offset:me(0),rowHeight:String},emits:["click"],setup(e,{emit:s,slots:i}){const m=x(()=>{var a;const{item:u,index:O,color:P,offset:T,rowHeight:F}=e,B={height:F};if(u.type==="placeholder")return B.width="100%",B;if(O===0&&(B.marginLeft=`${100*T/7}%`),P)switch(u.type){case"end":case"start":case"start-end":case"multiple-middle":case"multiple-selected":B.background=P;break;case"middle":B.color=P;break}return T+(((a=u.date)==null?void 0:a.getDate())||1)>28&&(B.marginBottom=0),B}),b=()=>{e.item.type!=="disabled"&&s("click",e.item)},S=()=>{const{topInfo:a}=e.item;if(a||i["top-info"])return c("div",{class:d("top-info")},[i["top-info"]?i["top-info"](e.item):a])},M=()=>{const{bottomInfo:a}=e.item;if(a||i["bottom-info"])return c("div",{class:d("bottom-info")},[i["bottom-info"]?i["bottom-info"](e.item):a])},w=()=>{const{item:a,color:u,rowHeight:O}=e,{type:P,text:T}=a,F=[S(),T,M()];return P==="selected"?c("div",{class:d("selected-day"),style:{width:O,height:O,background:u}},[F]):F};return()=>{const{type:a,className:u}=e.item;return a==="placeholder"?c("div",{class:d("day"),style:m.value},null):c("div",{role:"gridcell",style:m.value,class:[d("day",a),u],tabindex:a==="disabled"?void 0:-1,onClick:b},[w()])}}});const[Ie]=L("calendar-month"),He={date:j(Date),type:String,color:String,minDate:j(Date),maxDate:j(Date),showMark:Boolean,rowHeight:ee,formatter:Function,lazyRender:Boolean,currentDate:[Date,Array],allowSameDay:Boolean,showSubtitle:Boolean,showMonthTitle:Boolean,firstDayOfWeek:Number};var We=Z({name:Ie,props:He,emits:["click"],setup(e,{emit:s,slots:i}){const[m,b]=he(),S=E(),M=E(),w=ge(M),a=x(()=>Ce(e.date)),u=x(()=>ve(e.rowHeight)),O=x(()=>{const o=e.date.getDay();return e.firstDayOfWeek?(o+7-e.firstDayOfWeek)%7:o}),P=x(()=>Me(e.date.getFullYear(),e.date.getMonth()+1)),T=x(()=>m.value||!e.lazyRender),F=()=>a.value,B=o=>{const h=v=>e.currentDate.some(f=>R(f,v)===0);if(h(o)){const v=oe(o),f=de(o),y=h(v),t=h(f);return y&&t?"multiple-middle":y?"end":t?"start":"multiple-selected"}return""},N=o=>{const[h,v]=e.currentDate;if(!h)return"";const f=R(o,h);if(!v)return f===0?"start":"";const y=R(o,v);return e.allowSameDay&&f===0&&y===0?"start-end":f===0?"start":y===0?"end":f>0&&y<0?"middle":""},Y=o=>{const{type:h,minDate:v,maxDate:f,currentDate:y}=e;if(R(o,v)<0||R(o,f)>0)return"disabled";if(y===null)return"";if(Array.isArray(y)){if(h==="multiple")return B(o);if(h==="range")return N(o)}else if(h==="single")return R(o,y)===0?"selected":"";return""},_=o=>{if(e.type==="range"){if(o==="start"||o==="end")return W(o);if(o==="start-end")return`${W("start")}/${W("end")}`}},z=()=>{if(e.showMonthTitle)return c("div",{class:d("month-title")},[a.value])},U=()=>{if(e.showMark&&T.value)return c("div",{class:d("month-mark")},[e.date.getMonth()+1])},V=x(()=>{const o=Math.ceil((P.value+O.value)/7);return Array(o).fill({type:"placeholder"})}),$=x(()=>{const o=[],h=e.date.getFullYear(),v=e.date.getMonth();for(let f=1;f<=P.value;f++){const y=new Date(h,v,f),t=Y(y);let n={date:y,type:t,text:f,bottomInfo:_(t)};e.formatter&&(n=e.formatter(n)),o.push(n)}return o}),C=x(()=>$.value.filter(o=>o.type==="disabled")),J=(o,h)=>{if(S.value){const v=te(S.value),f=V.value.length,t=(Math.ceil((h.getDate()+O.value)/7)-1)*v.height/f;ye(o,v.top+t+o.scrollTop-te(o).top)}},K=(o,h)=>c(Ae,{item:o,index:h,color:e.color,offset:O.value,rowHeight:u.value,onClick:v=>s("click",v)},q(i,["top-info","bottom-info"])),Q=()=>c("div",{ref:S,role:"grid",class:d("days")},[U(),(T.value?$:V).value.map(K)]);return fe({getTitle:F,getHeight:()=>w.value,setVisible:b,scrollToDate:J,disabledDays:C}),()=>c("div",{class:d("month"),ref:M},[z(),Q()])}});const[Fe]=L("calendar-header");var Ne=Z({name:Fe,props:{date:Date,title:String,subtitle:String,showTitle:Boolean,showSubtitle:Boolean,firstDayOfWeek:Number},emits:["clickSubtitle"],setup(e,{slots:s,emit:i}){const m=()=>{if(e.showTitle){const w=e.title||W("title"),a=s.title?s.title():w;return c("div",{class:d("header-title")},[a])}},b=w=>i("clickSubtitle",w),S=()=>{if(e.showSubtitle){const w=s.subtitle?s.subtitle({date:e.date,text:e.subtitle}):e.subtitle;return c("div",{class:d("header-subtitle"),onClick:b},[w])}},M=()=>{const{firstDayOfWeek:w}=e,a=W("weekdays"),u=[...a.slice(w,7),...a.slice(0,w)];return c("div",{class:d("weekdays")},[u.map(O=>c("span",{class:d("weekday")},[O]))])};return()=>c("div",{class:d("header")},[m(),S(),M()])}});const _e={show:Boolean,type:se("single"),title:String,color:String,round:H,readonly:Boolean,poppable:H,maxRange:De(null),position:se("bottom"),teleport:[String,Object],showMark:H,showTitle:H,formatter:Function,rowHeight:ee,confirmText:String,rangePrompt:String,lazyRender:H,showConfirm:H,defaultDate:[Date,Array],allowSameDay:Boolean,showSubtitle:H,closeOnPopstate:H,showRangePrompt:H,confirmDisabledText:String,closeOnClickOverlay:H,safeAreaInsetTop:Boolean,safeAreaInsetBottom:H,minDate:{type:Date,validator:ne,default:re},maxDate:{type:Date,validator:ne,default:()=>{const e=re();return new Date(e.getFullYear(),e.getMonth()+6,e.getDate())}},firstDayOfWeek:{type:ee,default:0,validator:e=>e>=0&&e<=6}};var $e=Z({name:Oe,props:_e,emits:["select","confirm","unselect","monthShow","overRange","update:show","clickSubtitle"],setup(e,{emit:s,slots:i}){const m=(t,n=e.minDate,r=e.maxDate)=>R(t,n)===-1?n:R(t,r)===1?r:t,b=(t=e.defaultDate)=>{const{type:n,minDate:r,maxDate:l,allowSameDay:k}=e;if(t===null)return t;const D=re();if(n==="range"){Array.isArray(t)||(t=[]);const A=m(t[0]||D,r,k?l:oe(l)),g=m(t[1]||D,k?r:de(r));return[A,g]}return n==="multiple"?Array.isArray(t)?t.map(A=>m(A)):[m(D)]:((!t||Array.isArray(t))&&(t=D),m(t))};let S;const M=E(),w=E({text:"",date:void 0}),a=E(b()),[u,O]=Re(),P=x(()=>e.firstDayOfWeek?+e.firstDayOfWeek%7:0),T=x(()=>{const t=[],n=new Date(e.minDate);n.setDate(1);do t.push(new Date(n)),n.setMonth(n.getMonth()+1);while(ae(n,e.maxDate)!==1);return t}),F=x(()=>{if(a.value){if(e.type==="range")return!a.value[0]||!a.value[1];if(e.type==="multiple")return!a.value.length}return!a.value}),B=()=>a.value,N=()=>{const t=ke(M.value),n=t+S,r=T.value.map((g,I)=>u.value[I].getHeight()),l=r.reduce((g,I)=>g+I,0);if(n>l&&t>0)return;let k=0,D;const A=[-1,-1];for(let g=0;g<T.value.length;g++){const I=u.value[g];k<=n&&k+r[g]>=t&&(A[1]=g,D||(D=I,A[0]=g),u.value[g].showed||(u.value[g].showed=!0,s("monthShow",{date:I.date,title:I.getTitle()}))),k+=r[g]}T.value.forEach((g,I)=>{const ie=I>=A[0]-1&&I<=A[1]+1;u.value[I].setVisible(ie)}),D&&(w.value={text:D.getTitle(),date:D.date})},Y=t=>{p(()=>{T.value.some((n,r)=>ae(n,t)===0?(M.value&&u.value[r].scrollToDate(M.value,t),!0):!1),N()})},_=()=>{if(!(e.poppable&&!e.show))if(a.value){const t=e.type==="single"?a.value:a.value[0];ne(t)&&Y(t)}else p(N)},z=()=>{e.poppable&&!e.show||(p(()=>{S=Math.floor(te(M).height)}),_())},U=(t=b())=>{a.value=t,_()},V=t=>{const{maxRange:n,rangePrompt:r,showRangePrompt:l}=e;return n&&Pe(t)>n?(l&&ce(r||W("rangePrompt",n)),s("overRange"),!1):!0},$=()=>{var t;return s("confirm",(t=a.value)!=null?t:ue(a.value))},C=(t,n)=>{const r=l=>{a.value=l,s("select",ue(l))};if(n&&e.type==="range"&&!V(t)){r([t[0],le(t[0],+e.maxRange-1)]);return}r(t),n&&!e.showConfirm&&$()},J=(t,n,r)=>{var l;return(l=t.find(k=>R(n,k.date)===-1&&R(k.date,r)===-1))==null?void 0:l.date},K=x(()=>u.value.reduce((t,n)=>{var r,l;return t.push(...(l=(r=n.disabledDays)==null?void 0:r.value)!=null?l:[]),t},[])),Q=t=>{if(e.readonly||!t.date)return;const{date:n}=t,{type:r}=e;if(r==="range"){if(!a.value){C([n]);return}const[l,k]=a.value;if(l&&!k){const D=R(n,l);if(D===1){const A=J(K.value,l,n);if(A){const g=oe(A);R(l,g)===-1?C([l,g]):C([n])}else C([l,n],!0)}else D===-1?C([n]):e.allowSameDay&&C([n,n],!0)}else C([n])}else if(r==="multiple"){if(!a.value){C([n]);return}const l=a.value,k=l.findIndex(D=>R(D,n)===0);if(k!==-1){const[D]=l.splice(k,1);s("unselect",G(D))}else e.maxRange&&l.length>=e.maxRange?ce(e.rangePrompt||W("rangePrompt",e.maxRange)):C([...l,n])}else C(n,!0)},o=t=>s("update:show",t),h=(t,n)=>{const r=n!==0||!e.showSubtitle;return c(We,Se({ref:O(n),date:t,currentDate:a.value,showMonthTitle:r,firstDayOfWeek:P.value},q(e,["type","color","minDate","maxDate","showMark","formatter","rowHeight","lazyRender","showSubtitle","allowSameDay"]),{onClick:Q}),q(i,["top-info","bottom-info"]))},v=()=>{if(i.footer)return i.footer();if(e.showConfirm){const t=i["confirm-text"],n=F.value,r=n?e.confirmDisabledText:e.confirmText;return c(Te,{round:!0,block:!0,type:"primary",color:e.color,class:d("confirm"),disabled:n,nativeType:"button",onClick:$},{default:()=>[t?t({disabled:n}):r||W("confirm")]})}},f=()=>c("div",{class:[d("footer"),{"van-safe-area-bottom":e.safeAreaInsetBottom}]},[v()]),y=()=>c("div",{class:d()},[c(Ne,{date:w.value.date,title:e.title,subtitle:w.value.text,showTitle:e.showTitle,showSubtitle:e.showSubtitle,firstDayOfWeek:P.value,onClickSubtitle:t=>s("clickSubtitle",t)},q(i,["title","subtitle"])),c("div",{ref:M,class:d("body"),onScroll:N},[T.value.map(h)]),f()]);return X(()=>e.show,z),X(()=>[e.type,e.minDate,e.maxDate],()=>U(b(a.value))),X(()=>e.defaultDate,(t=null)=>{a.value=t,_()}),fe({reset:U,scrollToDate:Y,getSelectedDate:B}),we(z),()=>e.poppable?c(be,{show:e.show,class:d("popup"),round:e.round,position:e.position,closeable:e.showTitle||e.showSubtitle,teleport:e.teleport,closeOnPopstate:e.closeOnPopstate,safeAreaInsetTop:e.safeAreaInsetTop,closeOnClickOverlay:e.closeOnClickOverlay,"onUpdate:show":o},{default:y}):y()}});const Ue=xe($e);export{Ue as C};