@h6s/calendar
Advanced tools
Comparing version 1.0.3-alpha.1 to 1.0.3-alpha.2
@@ -1,2 +0,2 @@ | ||
var U=(a=>(a.Month="month",a.Week="week",a.Day="day",a))(U||{}),n=U;import{getDate as ee,isWeekend as te}from"date-fns";function p(e){return[...new Array(e).keys()]}var M=0,x=new Map;function h(e){if(x.has(e)){let o=x.get(e)+1;x.set(e,o),M=o}else{let t=1;x.set(e,t),M=t}return`${e}-${M}`}import{isEqual as Q}from"date-fns";import{setHours as $,setMilliseconds as q,setMinutes as z,setSeconds as L}from"date-fns";function w(e){return $(z(L(q(e,0),0),0),0)}function C(e,t){let o=w(e),a=w(t);return Q(o,a)}import{isSameMonth as R,isSameYear as X}from"date-fns";function k(e,t){return R(t,e)&&X(t,e)}function b(e){return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function Z(...e){return(...t)=>e.reduce((o,a,d)=>a(...d===0?o:[o]),t)}function Y(e,...t){return Z(...t)(e)}function y(e,t){return e.map(o=>({...o,key:h(t)}))}function A(e,t){return function(o){let{value:a}=o,d=k(t,a),r=C(e,a),D=te(a);return{...o,date:ee(a),isCurrentMonth:d,isCurrentDate:r,isWeekend:D}}}function B(e){return function(t){return{...t,key:h(e)}}}import{addDays as pe,addMonths as fe,addWeeks as ce,startOfMonth as j,startOfWeek as N,subDays as De,subMonths as ve,subWeeks as me}from"date-fns";import{useCallback as F,useMemo as E,useState as I}from"react";import{getDay as oe,getDaysInMonth as ie,setDay as ne,startOfMonth as ae}from"date-fns";function g(e,{weekStartsOn:t}){let{year:o,month:a,day:d}=b(e),r=se(e,t),D=re(e,r),u=p(7).map(s=>({value:ne(e,s+t)})),f=(s,c)=>{let v=s*7+c-r+1;return{value:new Date(o,a,v)}};return{cursorDate:e,year:o,month:a,day:d,weekStartsOn:t,startWeekdayInMonth:r,weeksInMonth:D,weekendDays:u,today:{weekIndex:de(d,r),dateIndex:oe(e)},getDateCellByIndex:f}}function se(e,t){let o=(ae(e).getDay()-t)%7;return o<0?o+7:o}function re(e,t){let o=ie(e);return Math.ceil((t+o)/7)}function de(e,t){return(e+t)%7>0?Math.floor((e+t)/7):Math.floor((e+t)/7)-1}import{useEffect as he,useState as ue}from"react";function W(){let[e,t]=ue(!1);return he(()=>{t(!0)},[]),e}function ft({defaultDate:e,defaultWeekStart:t=0,defaultViewType:o=n.Month}={}){let a=W(),d=E(()=>e!=null?new Date(e):new Date,[e,a]),[r,D]=I(t),[u,f]=I(d),[s,c]=I(o),v=g(u,{weekStartsOn:r}),{weekendDays:G,weeksInMonth:T,today:H,getDateCellByIndex:S}=v,O=F(i=>{switch(i){case n.Month:case n.Week:return{weekDays:y(G,"weekdays")};case n.Day:default:return{weekDays:y([{value:u}],"weekdays")}}},[u,G]),V=F(i=>({value:p(i).map(m=>({key:h("weeks"),value:p(7).map(l=>Y(S(m,l),A(d,u),B("days")))}))}),[d,u,S]),P=F(i=>{let m=V(T),{weekIndex:l,dateIndex:_}=H;return{[n.Month]:m,[n.Week]:{value:[m.value[l]]},[n.Day]:{value:[{key:"week-day-type",value:[m.value[l]?.value[_]]}]}}[i]},[V,H,T]),J=E(()=>{switch(s){case n.Month:return i=>fe(j(i),1);case n.Week:return i=>ce(N(i,{weekStartsOn:r}),1);case n.Day:return i=>pe(i,1)}},[s,r]),K=E(()=>{switch(s){case n.Month:return i=>ve(j(i),1);case n.Week:return i=>me(N(i,{weekStartsOn:r}),1);case n.Day:return i=>De(i,1)}},[s,r]);return E(()=>({...v,headers:O(s),body:P(s),navigation:{toNext:()=>f(i=>J(i)),toPrev:()=>f(i=>K(i)),setToday:()=>f(new Date),setDate:i=>f(i)},view:{type:s,setViewType:c,setWeekStartsOn:D,isMonthView:s===n.Month,isWeekView:s===n.Week,isDayView:s===n.Day,showMonthView:()=>c(n.Month),showWeekView:()=>c(n.Week),showDayView:()=>c(n.Day)}}),[v,P,O,J,K,s])}export{n as CalendarViewType,p as arrayOf,h as generateID,C as isSameDate,k as isSameYearAndMonth,b as parseDate,Z as pipe,Y as pipeWith,ft as useCalendar,A as withDateProps,y as withKey,B as withKeyProps}; | ||
var H=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=e=>H(e,"__esModule",{value:!0});var te=(e,t)=>{for(var o in t)H(e,o,{get:t[o],enumerable:!0})},oe=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of X(t))!Z.call(e,r)&&(o||r!=="default")&&H(e,r,{get:()=>t[r],enumerable:!(a=R(t,r))||a.enumerable});return e};var ie=(e=>(t,o)=>e&&e.get(t)||(o=oe(ee({}),t,1),e&&e.set(t,o),o))(typeof WeakMap!="undefined"?new WeakMap:0);var de={};te(de,{CalendarViewType:()=>n,arrayOf:()=>f,generateID:()=>p,isSameDate:()=>k,isSameYearAndMonth:()=>b,parseDate:()=>A,pipe:()=>L,pipeWith:()=>O,useCalendar:()=>re,withDateProps:()=>B,withKey:()=>l,withKeyProps:()=>g});var q=(a=>(a.Month="month",a.Week="week",a.Day="day",a))(q||{}),n=q;var I=require("date-fns");function f(e){return[...new Array(e).keys()]}var S=0,M=new Map;function p(e){if(M.has(e)){let o=M.get(e)+1;M.set(e,o),S=o}else{let t=1;M.set(e,t),S=t}return`${e}-${S}`}var z=require("date-fns");var c=require("date-fns");function W(e){return(0,c.setHours)((0,c.setMinutes)((0,c.setSeconds)((0,c.setMilliseconds)(e,0),0),0),0)}function k(e,t){let o=W(e),a=W(t);return(0,z.isEqual)(o,a)}var F=require("date-fns");function b(e,t){return(0,F.isSameMonth)(t,e)&&(0,F.isSameYear)(t,e)}function A(e){return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function L(...e){return(...t)=>e.reduce((o,a,r)=>a(...r===0?o:[o]),t)}function O(e,...t){return L(...t)(e)}function l(e,t){return e.map(o=>({...o,key:p(t)}))}function B(e,t){return function(o){let{value:a}=o,r=b(t,a),h=k(e,a),x=(0,I.isWeekend)(a);return{...o,date:(0,I.getDate)(a),isCurrentMonth:r,isCurrentDate:h,isWeekend:x}}}function g(e){return function(t){return{...t,key:p(e)}}}var s=require("date-fns"),u=require("react");var D=require("date-fns");function G(e,{weekStartsOn:t}){let{year:o,month:a,day:r}=A(e),h=ne(e,t),x=ae(e,h),v=f(7).map(d=>({value:(0,D.setDay)(e,d+t)})),m=(d,y)=>{let w=d*7+y-h+1;return{value:new Date(o,a,w)}};return{cursorDate:e,year:o,month:a,day:r,weekStartsOn:t,startWeekdayInMonth:h,weeksInMonth:x,weekendDays:v,today:{weekIndex:se(r,h),dateIndex:(0,D.getDay)(e)},getDateCellByIndex:m}}function ne(e,t){let o=((0,D.startOfMonth)(e).getDay()-t)%7;return o<0?o+7:o}function ae(e,t){let o=(0,D.getDaysInMonth)(e);return Math.ceil((t+o)/7)}function se(e,t){return(e+t)%7>0?Math.floor((e+t)/7):Math.floor((e+t)/7)-1}var T=require("react");function V(){let[e,t]=(0,T.useState)(!1);return(0,T.useEffect)(()=>{t(!0)},[]),e}function re({defaultDate:e,defaultWeekStart:t=0,defaultViewType:o=n.Month}={}){let a=V(),r=(0,u.useMemo)(()=>e!=null?new Date(e):new Date,[e,a]),[h,x]=(0,u.useState)(t),[v,m]=(0,u.useState)(r),[d,y]=(0,u.useState)(o),w=G(v,{weekStartsOn:h}),{weekendDays:P,weeksInMonth:J,today:K,getDateCellByIndex:U}=w,Y=(0,u.useCallback)(i=>{switch(i){case n.Month:case n.Week:return{weekDays:l(P,"weekdays")};case n.Day:default:return{weekDays:l([{value:v}],"weekdays")}}},[v,P]),j=(0,u.useCallback)(i=>({value:f(i).map(C=>({key:p("weeks"),value:f(7).map(E=>O(U(C,E),B(r,v),g("days")))}))}),[r,v,U]),N=(0,u.useCallback)(i=>{let C=j(J),{weekIndex:E,dateIndex:Q}=K;return{[n.Month]:C,[n.Week]:{value:[C.value[E]]},[n.Day]:{value:[{key:"week-day-type",value:[C.value[E]?.value[Q]]}]}}[i]},[j,K,J]),_=(0,u.useMemo)(()=>{switch(d){case n.Month:return i=>(0,s.addMonths)((0,s.startOfMonth)(i),1);case n.Week:return i=>(0,s.addWeeks)((0,s.startOfWeek)(i,{weekStartsOn:h}),1);case n.Day:return i=>(0,s.addDays)(i,1)}},[d,h]),$=(0,u.useMemo)(()=>{switch(d){case n.Month:return i=>(0,s.subMonths)((0,s.startOfMonth)(i),1);case n.Week:return i=>(0,s.subWeeks)((0,s.startOfWeek)(i,{weekStartsOn:h}),1);case n.Day:return i=>(0,s.subDays)(i,1)}},[d,h]);return(0,u.useMemo)(()=>({...w,headers:Y(d),body:N(d),navigation:{toNext:()=>m(i=>_(i)),toPrev:()=>m(i=>$(i)),setToday:()=>m(new Date),setDate:i=>m(i)},view:{type:d,setViewType:y,setWeekStartsOn:x,isMonthView:d===n.Month,isWeekView:d===n.Week,isDayView:d===n.Day,showMonthView:()=>y(n.Month),showWeekView:()=>y(n.Week),showDayView:()=>y(n.Day)}}),[w,N,Y,_,$,d])}module.exports=ie(de); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@h6s/calendar", | ||
"version": "1.0.3-alpha.1", | ||
"version": "1.0.3-alpha.2", | ||
"main": "src/index.ts", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"main": "cjs/index.js", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"module": "dist/index.js" | ||
"module": "esm/index.js" | ||
}, | ||
@@ -11,0 +11,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet