2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
import{d as le,$ as Le,e as D,w as Te,o as y,c as h,H as w,u as d,a as f,Q as ie,T as L,a7 as T,O as I,S as k,Z as P,_ as oe,R as se}from"./@vue.53f8d7c3.js";var Ye=Object.defineProperty,Ae=(e,r,t)=>r in e?Ye(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,W=(e,r,t)=>(Ae(e,typeof r!="symbol"?r+"":r,t),t);const A=()=>B(new Date),$e=(e,r,t)=>{switch(r){case"year":return new Date(e.getFullYear(),0);case"month":return new Date(e.getFullYear(),e.getMonth());case"week":return j(e,t);default:return e}},xe=e=>[...Array(7)].map((r,t)=>S(e,t)),S=(e,r)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+r,e.getHours(),e.getMinutes(),e.getSeconds()),j=(e,r)=>S(e,(r-e.getDay()-7)%-7),He=(e,r)=>S(j(e,r),7),Y=e=>new Date(e.getFullYear(),e.getMonth()),We=e=>Math.ceil(e.getDate()/7),Be=(e,r,t)=>new Date(e.getFullYear()+(r=="year"?t:0),e.getMonth()+(r=="month"?t:0),e.getDate()+(r=="week"?t*7:0)),Q=e=>("0"+String(e.getMonth()+1)).slice(-2),q=e=>("0"+String(e.getDate())).slice(-2),de=e=>e.getFullYear()+"-"+Q(e),Ne=e=>de(e)+"-"+q(e),Ee=e=>Q(e)+"-"+q(e),Ue=(e,r,t)=>{if(e.getHours()===0&&e.getMinutes()===0&&e.getSeconds()===0)return"";if(!N()){var l=new Date().getTimezoneOffset()*6e4;return new Date(e.getTime()-l).toISOString().slice(11,16)}return e.toLocaleTimeString(r,t)},Re=(e,r,t,l)=>{const g=e.getFullYear()===r.getFullYear(),b=ge(e,r),c=t!=="year"&&t!=="month";let m=[];return m.push(l[e.getMonth()]),c&&(m.push(" "),m.push(e.getDate())),g||(m.push(c?", ":" "),m.push(e.getFullYear())),!b||!g?(m.push(" \u2013 "),b||m.push(l[r.getMonth()]),c&&m.push(" ")):c&&m.push(" \u2013 "),c?(m.push(r.getDate()),m.push(", ")):m.push(" "),m.push(r.getFullYear()),m.join("")},ue=(e,r)=>{const t=Date.UTC(r.getFullYear(),r.getMonth(),r.getDate()),l=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate());return(t-l)/864e5},ze=(e,r)=>!!e&&!!r&&ue(e,r)===0,Ve=(e,r)=>!!e&&!!r&&e.getTime()===r.getTime(),ge=(e,r)=>!!e&&!!r&&e.getFullYear()===r.getFullYear()&&e.getMonth()===r.getMonth(),_e=e=>Y(e)<Y(A()),je=e=>Y(e)>Y(A()),Qe=e=>B(e)>A(),qe=e=>B(e)<A(),Ge=e=>e.getMonth()!==S(e,7).getMonth(),Ze=e=>e.getMonth()!==S(e,1).getMonth(),ce=e=>{let r=[...Array(7)].map(t=>0);return e.split(/\D/,7).forEach((t,l)=>r[l]=Number(t)),r[1]--,new Date(r[0],r[1],r[2],r[3],r[4],r[5],r[6])},_=e=>typeof e=="string"?ce(e):new Date(e),B=e=>{const r=new Date(e);return r.setHours(0,0,0,0),r},Je=e=>e.substring(0,2),N=()=>typeof Intl<"u",Ke=(e,r)=>{if(!N())return[...Array(12)].map(l=>"");const t=new Intl.DateTimeFormat(e,{month:r});return[...Array(12)].map((l,g)=>t.format(new Date(2017,g,1)))},Xe=(e,r,t)=>{if(!N())return[...Array(7)].map(g=>"");const l=new Intl.DateTimeFormat(e,{weekday:r});return[...Array(7)].map((g,b)=>l.format(new Date(2017,0,(b+1+t)%7)))},et=()=>typeof navigator>"u"?"unk":(navigator.languages&&navigator.languages.length?navigator.languages[0]:navigator.language).toLowerCase(),tt=(e,r)=>{var l;const t=e.classes?[...e.classes]:[];return r&&t.push("isHovered"),{originalItem:e,startDate:_(e.startDate),endDate:_(e.endDate||e.startDate),classes:t,title:e.title||"Untitled",id:e.id,url:e.url,tooltip:(l=e.tooltip)!=null?l:e.title}},n={addDays:S,beginningOfMonth:Y,beginningOfPeriod:$e,beginningOfWeek:j,dateOnly:B,dayDiff:ue,daysOfWeek:xe,endOfWeek:He,formattedPeriod:Re,formattedTime:Ue,fromIsoStringToLocalDate:ce,getDefaultBrowserLocale:et,getFormattedMonthNames:Ke,getFormattedWeekdayNames:Xe,incrementPeriod:Be,instanceOfMonth:We,isFutureMonth:je,isInFuture:Qe,isInPast:qe,isLastDayOfMonth:Ze,isLastInstanceOfMonth:Ge,isoMonthDay:Ee,isoYearMonth:de,isoYearMonthDay:Ne,isPastMonth:_e,isSameDate:ze,isSameDateTime:Ve,isSameMonth:ge,languageCode:Je,normalizeItem:tt,paddedDay:q,paddedMonth:Q,supportsIntl:N,today:A,toLocalDate:_};class at{constructor(){W(this,"currentDragItem"),W(this,"dateSelectionOrigin"),W(this,"currentHoveredItemId",""),W(this,"CalendarMath",n)}}const rt={class:"cv-header-days"},nt={key:0,class:"cv-weeknumber"},it=["aria-multiselectable"],ot={key:0,class:"cv-weeknumber"},lt={class:"cv-weekdays"},st=["draggable","aria-grabbed","aria-label","aria-selected","aria-dropeffect","onClick","onDragstart","onDrop","onDragover","onDragenter","onDragleave"],dt={class:"cv-day-number"},ut=["draggable","aria-grabbed","title","onDragstart","onMouseenter","onMouseleave","onClick","innerHTML"],gt=["draggable","aria-grabbed","title","onDragstart","onMouseenter","onMouseleave","onClick"],ft=le({__name:"CalendarView",props:{showDate:{default:void 0},displayPeriodUom:{default:"month"},displayPeriodCount:{default:1},displayWeekNumbers:{type:Boolean,default:!1},locale:{default:void 0},monthNameFormat:{default:"long"},weekdayNameFormat:{default:"short"},showTimes:{type:Boolean,default:!1},timeFormatOptions:{default:()=>({})},disablePast:{type:Boolean,default:!1},disableFuture:{type:Boolean,default:!1},enableDateSelection:{type:Boolean,default:!1},selectionStart:{default:void 0},selectionEnd:{default:void 0},enableDragDrop:{type:Boolean,default:!1},startingDayOfWeek:{default:0},items:{default:()=>[]},dateClasses:{default:()=>({})},itemTop:{default:"1.4em"},itemContentHeight:{default:"1.4em"},itemBorderHeight:{default:"2px"},periodChangedCallback:{type:Function,default:void 0},currentPeriodLabel:{default:""},currentPeriodLabelIcons:{default:"\u21E4-\u21E5"},doEmitItemMouseEvents:{type:Boolean,default:!1},enableHtmlTitles:{type:Boolean,default:!0}},emits:["period-changed","click-date","click-item","item-mouseenter","item-mouseleave","drag-start","drag-over-date","drag-enter-date","drag-leave-date","drop-on-date","date-selection","date-selection-start","date-selection-finish"],setup(e,{emit:r}){const t=e,l=Le(new at),g=D(()=>t.locale||n.getDefaultBrowserLocale()),b=D(()=>t.showDate?n.dateOnly(t.showDate):n.today()),c=D(()=>n.beginningOfPeriod(b.value,t.displayPeriodUom,t.startingDayOfWeek)),m=D(()=>n.addDays(n.incrementPeriod(c.value,t.displayPeriodUom,t.displayPeriodCount),-1)),G=D(()=>{const a=n.beginningOfWeek(n.beginningOfPeriod(c.value,"year",0),t.startingDayOfWeek),o=n.beginningOfWeek(c.value,t.startingDayOfWeek);return 1+Math.floor(n.dayDiff(a,o)/7)}),$=D(()=>n.beginningOfWeek(c.value,t.startingDayOfWeek)),E=D(()=>n.endOfWeek(m.value,t.startingDayOfWeek)),me=D(()=>{const a=Math.floor((n.dayDiff($.value,E.value)+1)/7);return[...Array(a)].map((o,u)=>n.addDays($.value,u*7))}),U=D(()=>n.getFormattedMonthNames(g.value,t.monthNameFormat)),pe=D(()=>n.getFormattedWeekdayNames(g.value,t.weekdayNameFormat,t.startingDayOfWeek)),R=D(()=>t.items?t.items.map(a=>n.normalizeItem(a,a.id===l.currentHoveredItemId)):[]),z=D(()=>n.beginningOfPeriod(n.today(),t.displayPeriodUom,t.startingDayOfWeek)),De=D(()=>n.addDays(n.incrementPeriod(z.value,t.displayPeriodUom,t.displayPeriodCount),-1)),ve=D(()=>n.formattedPeriod(c.value,m.value,t.displayPeriodUom,U.value)),ye=D(()=>{const a=z.value,o=c.value;return t.currentPeriodLabel?t.currentPeriodLabel==="icons"?t.currentPeriodLabelIcons[Math.sign(a.getTime()-o.getTime())+1]:t.currentPeriodLabel:n.formattedPeriod(a,De.value,t.displayPeriodUom,U.value)}),he=D(()=>({previousYear:O(-12),previousPeriod:O(-1),nextPeriod:O(1),previousFullPeriod:O(-t.displayPeriodCount),nextFullPeriod:O(t.displayPeriodCount),nextYear:O(12),currentPeriod:z.value,currentPeriodLabel:ye.value,periodStart:c.value,periodEnd:m.value,displayLocale:g.value,displayFirstDate:$.value,displayLastDate:E.value,monthNames:U.value,fixedItems:R.value,periodLabel:ve.value})),be=D(()=>({periodStart:c,periodEnd:m,displayFirstDate:$,displayLastDate:E}));Te(()=>be,a=>{t.periodChangedCallback&&(r("period-changed"),t.periodChangedCallback(a,"watch"))},{immediate:!0,deep:!0});const fe=(a,o)=>{t.disablePast&&n.isInPast(a)||t.disableFuture&&n.isInFuture(a)||r("click-date",a,ee(a,a),o)},Z=(a,o)=>r("click-item",a,o),C=a=>"dow"+(a+t.startingDayOfWeek)%7,O=a=>{const o=n.incrementPeriod(c.value,t.displayPeriodUom,a),u=n.incrementPeriod(o,t.displayPeriodUom,t.displayPeriodCount);return t.disablePast&&u<=n.today()||t.disableFuture&&o>n.today()?null:o},J=(a,o)=>{l.currentHoveredItemId=a.id,t.doEmitItemMouseEvents&&r("item-mouseenter",a,o)},K=(a,o)=>{l.currentHoveredItemId="",t.doEmitItemMouseEvents&&r("item-mouseleave",a,o)},Pe=(a,o)=>{var u,p;if(!t.enableDateSelection)return!1;(u=o.dataTransfer)==null||u.setData("text",a.toString());let i=new Image;return i.src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",(p=o.dataTransfer)==null||p.setDragImage(i,10,10),l.dateSelectionOrigin=a,r("date-selection-start",V(a),o),!0},X=(a,o)=>{var u;return t.enableDragDrop?((u=o.dataTransfer)==null||u.setData("text",a.id),l.currentDragItem=a,l.dateSelectionOrigin=void 0,r("drag-start",a,o),!0):!1},V=a=>a<=l.dateSelectionOrigin?[a,l.dateSelectionOrigin]:[l.dateSelectionOrigin,a],ke=(a,o)=>{t.enableDragDrop&&r("drag-over-date",l.currentDragItem,a,o)},Me=(a,o)=>{t.enableDateSelection&&l.dateSelectionOrigin&&r("date-selection",V(a),o),t.enableDragDrop&&(r("drag-enter-date",l.currentDragItem,a,o),o.target.classList.add("draghover"))},we=(a,o)=>{t.enableDateSelection&&t.selectionStart||!t.enableDragDrop||(r("drag-leave-date",l.currentDragItem,a,o),o.target.classList.remove("draghover"))},Oe=(a,o)=>{if(t.enableDateSelection&&l.dateSelectionOrigin){r("date-selection-finish",V(a),o);return}!t.enableDragDrop||(r("drop-on-date",l.currentDragItem,a,o),o.target.classList.remove("draghover"))},Ie=(a,o)=>a.startDate<o.startDate?-1:o.startDate<a.startDate?1:a.endDate>o.endDate?-1:o.endDate>a.endDate?1:a.id<o.id?-1:1,Se=a=>ee(a,n.addDays(a,6)),ee=(a,o)=>R.value.filter(u=>u.endDate>=a&&n.dateOnly(u.startDate)<=o,this).sort(Ie),Ce=a=>!!R.value.find(o=>o.endDate>=a&&n.dateOnly(o.startDate)<=a),te=a=>!(!t.selectionStart||!t.selectionEnd||a<n.dateOnly(t.selectionStart)||a>n.dateOnly(t.selectionEnd)),ae=a=>{const o=Se(a),u=[],p=[[],[],[],[],[],[],[]];if(!o)return u;for(let i=0;i<o.length;i++){const s=Object.assign({},o[i],{classes:[...o[i].classes],itemRow:0}),v=s.startDate<a,F=v?0:n.dayDiff(a,s.startDate),ne=Math.min(7-F,n.dayDiff(n.addDays(a,F),s.endDate)+1);v&&s.classes.push("continued"),n.dayDiff(a,s.endDate)>6&&s.classes.push("toBeContinued"),n.isInPast(s.endDate)&&s.classes.push("past"),s.originalItem.url&&s.classes.push("hasUrl");for(let M=0;M<7;M++)if(M===F){let H=0;for(;p[M][H];)H++;s.itemRow=H,p[M][H]=!0}else M<F+ne&&(p[M][s.itemRow]=!0);s.classes.push(`offset${F}`),s.classes.push(`span${ne}`),u.push(s)}return u},Fe=a=>{const o='<span class="startTime">'+n.formattedTime(a.startDate,g.value,t.timeFormatOptions)+"</span>";let u="";return n.isSameDateTime(a.startDate,a.endDate)||(u='<span class="endTime">'+n.formattedTime(a.endDate,g.value,t.timeFormatOptions)+"</span>"),o+u},re=a=>t.showTimes?Fe(a)+" "+a.title:a.title,x=a=>{const o=a.itemRow,u=t.itemContentHeight,p=t.itemBorderHeight;return`calc(${t.itemTop} + ${o}*${u} + ${o}*${p})`};return(a,o)=>(y(),h("div",{"aria-label":"Calendar",class:I(["cv-wrapper",`locale-${d(n).languageCode(d(g))}`,`locale-${d(g)}`,`y${d(c).getFullYear()}`,`m${d(n).paddedMonth(d(c))}`,`period-${e.displayPeriodUom}`,`periodCount-${e.displayPeriodCount}`,{past:d(n).isPastMonth(d(c)),future:d(n).isFutureMonth(d(c)),noIntl:!d(n).supportsIntl}])},[w(a.$slots,"header",{headerProps:d(he)}),f("div",rt,[e.displayWeekNumbers?(y(),h("div",nt)):ie("",!0),(y(!0),h(L,null,T(d(pe),(u,p)=>w(a.$slots,"dayHeader",{index:C(p),label:u},()=>[(y(),h("div",{key:C(p),class:I([C(p),"cv-header-day"])},k(u),3))])),256))]),f("div",{"aria-multiselectable":e.enableDateSelection,class:"cv-weeks"},[(y(!0),h(L,null,T(d(me),(u,p)=>(y(),h("div",{key:`${p}-week`,class:I(["cv-week",`week${p+1}`,`ws${d(n).isoYearMonthDay(u)}`])},[e.displayWeekNumbers?(y(),h("div",ot,[w(a.$slots,"weekNumber",{date:u,numberInYear:d(G)+p,numberInPeriod:p+1},()=>[f("span",null,k(d(G)+p),1)])])):ie("",!0),f("div",lt,[(y(!0),h(L,null,T(d(n).daysOfWeek(u),(i,s)=>(y(),h("div",{key:C(s),draggable:e.enableDateSelection,class:I(["cv-day",C(s),`d${d(n).isoYearMonthDay(i)}`,`d${d(n).isoMonthDay(i)}`,`d${d(n).paddedDay(i)}`,`instance${d(n).instanceOfMonth(i)}`,{today:d(n).isSameDate(i,d(n).today()),outsideOfMonth:!d(n).isSameMonth(i,d(b)),past:d(n).isInPast(i),future:d(n).isInFuture(i),last:d(n).isLastDayOfMonth(i),lastInstance:d(n).isLastInstanceOfMonth(i),hasItems:Ce(i),selectionStart:d(n).isSameDate(i,e.selectionStart),selectionEnd:d(n).isSameDate(i,e.selectionEnd)},...e.dateClasses&&e.dateClasses[d(n).isoYearMonthDay(i)]||[]]),"aria-grabbed":e.enableDateSelection?te(i):void 0,"aria-label":i.getDate().toString(),"aria-selected":te(i),"aria-dropeffect":e.enableDragDrop&&l.currentDragItem?"move":e.enableDateSelection&&l.dateSelectionOrigin?"execute":"none",onClick:v=>fe(i,v),onDragstart:v=>Pe(i,v),onDrop:P(v=>Oe(i,v),["prevent"]),onDragover:P(v=>ke(i,v),["prevent"]),onDragenter:P(v=>Me(i,v),["prevent"]),onDragleave:P(v=>we(i,v),["prevent"])},[f("div",dt,k(i.getDate()),1),w(a.$slots,"dayContent",{day:i})],42,st))),128)),t.enableHtmlTitles?(y(!0),h(L,{key:0},T(ae(u),i=>w(a.$slots,"item",{value:i,weekStartDate:u,top:x(i)},()=>[(y(),h("div",{key:i.id,draggable:e.enableDragDrop,"aria-grabbed":e.enableDragDrop?i==l.currentDragItem:void 0,class:I([i.classes,"cv-item"]),title:i.tooltip||i.title,style:oe(`top:${x(i)};${i.originalItem.style}`),onDragstart:s=>X(i,s),onMouseenter:s=>J(i,s),onMouseleave:s=>K(i,s),onClick:P(s=>Z(i,s),["stop"]),innerHTML:re(i)},null,46,ut))])),256)):(y(!0),h(L,{key:1},T(ae(u),i=>w(a.$slots,"item",{value:i,weekStartDate:u,top:x(i)},()=>[(y(),h("div",{key:i.id,draggable:e.enableDragDrop,"aria-grabbed":e.enableDragDrop?i==l.currentDragItem:void 0,class:I([i.classes,"cv-item"]),title:i.tooltip||i.title,style:oe(`top:${x(i)};${i.originalItem.style}`),onDragstart:s=>X(i,s),onMouseenter:s=>J(i,s),onMouseleave:s=>K(i,s),onClick:P(s=>Z(i,s),["stop"])},k(re(i)),47,gt)),se(" div> ")])),256))])],2))),128))],8,it)],2))}}),ct={class:"cv-header"},mt={class:"cv-header-nav"},pt=["disabled"],Dt=["disabled","innerHTML"],vt=["disabled"],yt=["disabled"],ht={class:"periodLabel"},Pt=le({__name:"CalendarViewHeader",props:{headerProps:{type:Object,required:!0},previousYearLabel:{type:String,default:"<<"},previousPeriodLabel:{type:String,default:"<"},nextPeriodLabel:{type:String,default:">"},nextYearLabel:{type:String,default:">>"}},emits:["input"],setup(e,{emit:r}){const t=l=>r("input",l);return(l,g)=>(y(),h("div",ct,[f("div",mt,[f("button",{disabled:!e.headerProps.previousYear,class:"previousYear","aria-label":"Previous Year",onClick:g[0]||(g[0]=P(b=>t(e.headerProps.previousYear),["prevent"]))},k(e.previousYearLabel),9,pt),f("button",{disabled:!e.headerProps.previousPeriod,class:"previousPeriod","aria-label":"Previous Period",onClick:g[1]||(g[1]=P(b=>t(e.headerProps.previousPeriod),["prevent"])),innerHTML:e.previousPeriodLabel},null,8,Dt),f("button",{class:"currentPeriod","aria-label":"Current Period",onClick:g[2]||(g[2]=P(b=>t(e.headerProps.currentPeriod),["prevent"]))},k(e.headerProps.currentPeriodLabel),1),f("button",{disabled:!e.headerProps.nextPeriod,class:"nextPeriod","aria-label":"Next Period",onClick:g[3]||(g[3]=P(b=>t(e.headerProps.nextPeriod),["prevent"]))},k(e.nextPeriodLabel),9,vt),f("button",{disabled:!e.headerProps.nextYear,class:"nextYear","aria-label":"Next Year",onClick:g[4]||(g[4]=P(b=>t(e.headerProps.nextYear),["prevent"]))},k(e.nextYearLabel),9,yt)]),f("div",ht,[w(l.$slots,"label",{},()=>[se(k(e.headerProps.periodLabel),1)])])]))}});export{Pt as M,ft as P};
|