@h6s/calendar
Advanced tools
Comparing version 1.1.0-alpha.2 to 2.0.0
@@ -1,4 +0,161 @@ | ||
export * from './models'; | ||
export * from './plugins'; | ||
export * from './useCalendar'; | ||
export * from './utils'; | ||
import * as react from 'react'; | ||
interface DateCell extends Record<string, unknown> { | ||
value: Date; | ||
} | ||
interface WeekRow extends Record<string, unknown> { | ||
value: DateCell[]; | ||
} | ||
interface MonthMatrix extends Record<string, unknown> { | ||
value: WeekRow[]; | ||
} | ||
declare enum CalendarViewtype { | ||
Month = "month", | ||
Week = "week", | ||
Day = "day" | ||
} | ||
type WeekDayType = 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
declare function withDateProps(baseDate: Date, cursorDate: Date): <T extends DateCell>(cell: T) => T & { | ||
date: number; | ||
isCurrentMonth: boolean; | ||
isCurrentDate: boolean; | ||
isWeekend: boolean; | ||
}; | ||
declare function withKeyProps(keyPrefix: string): <T extends DateCell>(cell: T) => T & { | ||
key: string; | ||
}; | ||
interface UseCalendarOptions { | ||
defaultDate?: Date | number | string; | ||
defaultWeekStart?: WeekDayType; | ||
defaultViewType?: CalendarViewtype; | ||
} | ||
declare function useCalendar({ defaultDate, defaultWeekStart, defaultViewType, }?: UseCalendarOptions): { | ||
headers: { | ||
weekDays: ({ | ||
value: Date; | ||
} & { | ||
key: string; | ||
})[]; | ||
}; | ||
body: { | ||
value: { | ||
key: string; | ||
value: ({ | ||
value: Date; | ||
} & { | ||
date: number; | ||
isCurrentMonth: boolean; | ||
isCurrentDate: boolean; | ||
isWeekend: boolean; | ||
} & { | ||
key: string; | ||
})[]; | ||
}[]; | ||
} | { | ||
value: { | ||
key: string; | ||
value: ({ | ||
value: Date; | ||
} & { | ||
date: number; | ||
isCurrentMonth: boolean; | ||
isCurrentDate: boolean; | ||
isWeekend: boolean; | ||
} & { | ||
key: string; | ||
})[]; | ||
}[]; | ||
} | { | ||
value: { | ||
key: string; | ||
value: ({ | ||
value: Date; | ||
} & { | ||
date: number; | ||
isCurrentMonth: boolean; | ||
isCurrentDate: boolean; | ||
isWeekend: boolean; | ||
} & { | ||
key: string; | ||
})[]; | ||
}[]; | ||
}; | ||
navigation: { | ||
toNext: () => void; | ||
toPrev: () => void; | ||
setToday: () => void; | ||
setDate: (date: Date) => void; | ||
}; | ||
view: { | ||
type: CalendarViewtype; | ||
setViewType: react.Dispatch<react.SetStateAction<CalendarViewtype>>; | ||
setWeekStartsOn: react.Dispatch<react.SetStateAction<0 | 1 | 2 | 3 | 4 | 5 | 6>>; | ||
isMonthView: boolean; | ||
isWeekView: boolean; | ||
isDayView: boolean; | ||
showMonthView: () => void; | ||
showWeekView: () => void; | ||
showDayView: () => void; | ||
}; | ||
cursorDate: Date; | ||
year: number; | ||
month: number; | ||
day: number; | ||
weekStartsOn: WeekDayType; | ||
startWeekdayInMonth: number; | ||
weeksInMonth: number; | ||
weekendDays: { | ||
value: Date; | ||
}[]; | ||
today: { | ||
weekIndex: number; | ||
dateIndex: 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
}; | ||
getDateCellByIndex: (weekIndex: number, dayIndex: number) => { | ||
value: Date; | ||
}; | ||
}; | ||
declare function arrayOf(count: number): number[]; | ||
declare function generateID(prefix: string): string; | ||
declare function isSameDate(baseDate: Date, targetDate: Date): boolean; | ||
declare function isSameYearAndMonth(baseDate: Date, targetDate: Date): boolean; | ||
declare function parseDate(date: Date): { | ||
year: number; | ||
month: number; | ||
day: number; | ||
}; | ||
declare function pipe<A extends unknown[], B>(ab: (this: void, ...a: A) => B): (...args: A) => B; | ||
declare function pipe<A extends unknown[], B, C>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C): (...args: A) => C; | ||
declare function pipe<A extends unknown[], B, C, D>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D): (...args: A) => D; | ||
declare function pipe<A extends unknown[], B, C, D, E>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E): (...args: A) => E; | ||
declare function pipe<A extends unknown[], B, C, D, E, F>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F): (...args: A) => F; | ||
declare function pipe<A extends unknown[], B, C, D, E, F, G>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G): (...args: A) => G; | ||
declare function pipe<A extends unknown[], B, C, D, E, F, G, H>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G, gh: (this: void, g: G) => H): (...args: A) => H; | ||
declare function pipe<A extends unknown[], B, C, D, E, F, G, H, I>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G, gh: (this: void, g: G) => H, hi: (this: void, h: H) => I): (...args: A) => I; | ||
declare function pipe<A extends unknown[], B, C, D, E, F, G, H, I, J>(ab: (this: void, ...a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G, gh: (this: void, g: G) => H, hi: (this: void, h: H) => I, ij: (this: void, i: I) => J): (...args: A) => J; | ||
declare function pipeWith<A, B>(a: A, ab: (this: void, a: A) => B): B; | ||
declare function pipeWith<A, B, C>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C): C; | ||
declare function pipeWith<A, B, C, D>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D): D; | ||
declare function pipeWith<A, B, C, D, E>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E): E; | ||
declare function pipeWith<A, B, C, D, E, F>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F): F; | ||
declare function pipeWith<A, B, C, D, E, F, G>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G): G; | ||
declare function pipeWith<A, B, C, D, E, F, G, H>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G, gh: (this: void, g: G) => H): H; | ||
declare function pipeWith<A, B, C, D, E, F, G, H, I>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G, gh: (this: void, g: G) => H, hi: (this: void, h: H) => I): I; | ||
declare function pipeWith<A, B, C, D, E, F, G, H, I, J>(a: A, ab: (this: void, a: A) => B, bc: (this: void, b: B) => C, cd: (this: void, c: C) => D, de: (this: void, d: D) => E, ef: (this: void, e: E) => F, fg: (this: void, f: F) => G, gh: (this: void, g: G) => H, hi: (this: void, h: H) => I, ij: (this: void, i: I) => J): J; | ||
declare function withKey<T>(arr: T[], keyPrefix: string): (T & { | ||
key: string; | ||
})[]; | ||
export { CalendarViewtype as CalendarViewType, type DateCell, type MonthMatrix, type UseCalendarOptions, type WeekDayType, type WeekRow, arrayOf, generateID, isSameDate, isSameYearAndMonth, parseDate, pipe, pipeWith, useCalendar, withDateProps, withKey, withKeyProps }; |
@@ -1,2 +0,312 @@ | ||
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 | ||
// src/models/CalendarViewType.ts | ||
var CalendarViewtype = /* @__PURE__ */ ((CalendarViewtype2) => { | ||
CalendarViewtype2["Month"] = "month"; | ||
CalendarViewtype2["Week"] = "week"; | ||
CalendarViewtype2["Day"] = "day"; | ||
return CalendarViewtype2; | ||
})(CalendarViewtype || {}); | ||
var CalendarViewType_default = CalendarViewtype; | ||
// src/plugins/withDateProps.ts | ||
import { getDate, isWeekend as _isWeekend } from "date-fns"; | ||
// src/utils/arrayOf.ts | ||
function arrayOf(count) { | ||
return [...new Array(count).keys()]; | ||
} | ||
// src/utils/generateID.ts | ||
var randomId = 0; | ||
var map = /* @__PURE__ */ new Map(); | ||
function generateID(prefix) { | ||
if (map.has(prefix)) { | ||
const id = map.get(prefix); | ||
const newId = id + 1; | ||
map.set(prefix, newId); | ||
randomId = newId; | ||
} else { | ||
const id = 1; | ||
map.set(prefix, id); | ||
randomId = id; | ||
} | ||
return `${prefix}-${randomId}`; | ||
} | ||
// src/utils/isSameDate.ts | ||
import { isEqual } from "date-fns"; | ||
// src/utils/resetTimeOfDate.ts | ||
import { setHours, setMilliseconds, setMinutes, setSeconds } from "date-fns"; | ||
function resetTimeOfDate(date) { | ||
return setHours(setMinutes(setSeconds(setMilliseconds(date, 0), 0), 0), 0); | ||
} | ||
// src/utils/isSameDate.ts | ||
function isSameDate(baseDate, targetDate) { | ||
const base = resetTimeOfDate(baseDate); | ||
const target = resetTimeOfDate(targetDate); | ||
return isEqual(base, target); | ||
} | ||
// src/utils/isSameYearAndMonth.ts | ||
import { isSameMonth as _isSameMonth, isSameYear } from "date-fns"; | ||
function isSameYearAndMonth(baseDate, targetDate) { | ||
return _isSameMonth(targetDate, baseDate) && isSameYear(targetDate, baseDate); | ||
} | ||
// src/utils/parseDate.ts | ||
function parseDate(date) { | ||
return { | ||
year: date.getFullYear(), | ||
month: date.getMonth(), | ||
day: date.getDate() | ||
}; | ||
} | ||
// src/utils/pipe.ts | ||
function pipe(...fns) { | ||
return (...initialParams) => fns.reduce((value, fn, index) => { | ||
const params = index === 0 ? value : [value]; | ||
return fn(...params); | ||
}, initialParams); | ||
} | ||
function pipeWith(value, ...fns) { | ||
return pipe( | ||
...fns | ||
)(value); | ||
} | ||
// src/utils/withKey.ts | ||
function withKey(arr, keyPrefix) { | ||
return arr.map((value) => { | ||
return { | ||
...value, | ||
key: generateID(keyPrefix) | ||
}; | ||
}); | ||
} | ||
// src/plugins/withDateProps.ts | ||
function withDateProps(baseDate, cursorDate) { | ||
return function(cell) { | ||
const { value: targetDate } = cell; | ||
const isCurrentMonth = isSameYearAndMonth(cursorDate, targetDate); | ||
const isCurrentDate = isSameDate(baseDate, targetDate); | ||
const isWeekend = _isWeekend(targetDate); | ||
return { | ||
...cell, | ||
date: getDate(targetDate), | ||
isCurrentMonth, | ||
isCurrentDate, | ||
isWeekend | ||
}; | ||
}; | ||
} | ||
// src/plugins/withKeyProps.ts | ||
function withKeyProps(keyPrefix) { | ||
return function(cell) { | ||
return { | ||
...cell, | ||
key: generateID(keyPrefix) | ||
}; | ||
}; | ||
} | ||
// src/useCalendar.ts | ||
import { | ||
addDays, | ||
addMonths, | ||
addWeeks, | ||
startOfMonth as startOfMonth2, | ||
startOfWeek, | ||
subDays, | ||
subMonths, | ||
subWeeks | ||
} from "date-fns"; | ||
import { useCallback, useMemo, useState as useState2 } from "react"; | ||
// src/core/createCalendarInfo.ts | ||
import { getDay, getDaysInMonth, setDay, startOfMonth } from "date-fns"; | ||
function createCalendarInfo(cursorDate, { weekStartsOn }) { | ||
const { year, month, day } = parseDate(cursorDate); | ||
const startWeekdayInMonth = getStartWeekdayInMonth(cursorDate, weekStartsOn); | ||
const weeksInMonth = getWeeksInMonth(cursorDate, startWeekdayInMonth); | ||
const weekendDays = arrayOf(7).map((index) => ({ | ||
value: setDay(cursorDate, index + weekStartsOn) | ||
})); | ||
const getDateCellByIndex = (weekIndex, dayIndex) => { | ||
const day2 = weekIndex * 7 + dayIndex - startWeekdayInMonth + 1; | ||
return { value: new Date(year, month, day2) }; | ||
}; | ||
return { | ||
cursorDate, | ||
year, | ||
month, | ||
day, | ||
weekStartsOn, | ||
startWeekdayInMonth, | ||
weeksInMonth, | ||
weekendDays, | ||
today: { | ||
weekIndex: getCurrentWeekIndex(day, startWeekdayInMonth), | ||
dateIndex: getDay(cursorDate) | ||
}, | ||
getDateCellByIndex | ||
}; | ||
} | ||
function getStartWeekdayInMonth(date, weekStartsOn) { | ||
const monthStartsAt = (startOfMonth(date).getDay() - weekStartsOn) % 7; | ||
return monthStartsAt < 0 ? monthStartsAt + 7 : monthStartsAt; | ||
} | ||
function getWeeksInMonth(date, startWeekdayInMonth) { | ||
const totalDaysOfMonth = getDaysInMonth(date); | ||
return Math.ceil((startWeekdayInMonth + totalDaysOfMonth) / 7); | ||
} | ||
function getCurrentWeekIndex(day, startWeekdayInMonth) { | ||
if ((day + startWeekdayInMonth) % 7 > 0) { | ||
return Math.floor((day + startWeekdayInMonth) / 7); | ||
} | ||
return Math.floor((day + startWeekdayInMonth) / 7) - 1; | ||
} | ||
// src/hooks/useIsMounted.tsx | ||
import { useEffect, useState } from "react"; | ||
function useIsMounted() { | ||
const [mounted, setMounted] = useState(false); | ||
useEffect(() => { | ||
setMounted(true); | ||
}, []); | ||
return mounted; | ||
} | ||
// src/useCalendar.ts | ||
function useCalendar({ | ||
defaultDate, | ||
defaultWeekStart = 0, | ||
defaultViewType = CalendarViewType_default.Month | ||
} = {}) { | ||
const isMounted = useIsMounted(); | ||
const baseDate = useMemo(() => { | ||
return defaultDate != null ? new Date(defaultDate) : /* @__PURE__ */ new Date(); | ||
}, [defaultDate, isMounted]); | ||
const [weekStartsOn, setWeekStartsOn] = useState2(defaultWeekStart); | ||
const [cursorDate, setCursorDate] = useState2(baseDate); | ||
const [viewType, setViewType] = useState2(defaultViewType); | ||
const calendar = createCalendarInfo(cursorDate, { weekStartsOn }); | ||
const { weekendDays, weeksInMonth, today, getDateCellByIndex } = calendar; | ||
const getHeaders = useCallback( | ||
(viewType2) => { | ||
switch (viewType2) { | ||
case CalendarViewType_default.Month: | ||
case CalendarViewType_default.Week: | ||
return { | ||
weekDays: withKey(weekendDays, "weekdays") | ||
}; | ||
case CalendarViewType_default.Day: | ||
default: | ||
return { | ||
weekDays: withKey([{ value: cursorDate }], "weekdays") | ||
}; | ||
} | ||
}, | ||
[cursorDate, weekendDays] | ||
); | ||
const createMatrix = useCallback( | ||
(weeksInMonth2) => ({ | ||
value: arrayOf(weeksInMonth2).map((weekIndex) => { | ||
return { | ||
key: generateID("weeks"), | ||
value: arrayOf(7).map((dayIndex) => { | ||
return pipeWith( | ||
getDateCellByIndex(weekIndex, dayIndex), | ||
withDateProps(baseDate, cursorDate), | ||
withKeyProps("days") | ||
); | ||
}) | ||
}; | ||
}) | ||
}), | ||
[baseDate, cursorDate, getDateCellByIndex] | ||
); | ||
const getBody = useCallback( | ||
(viewType2) => { | ||
const matrix = createMatrix(weeksInMonth); | ||
const { weekIndex, dateIndex } = today; | ||
return { | ||
[CalendarViewType_default.Month]: matrix, | ||
[CalendarViewType_default.Week]: { | ||
value: [matrix.value[weekIndex]] | ||
}, | ||
[CalendarViewType_default.Day]: { | ||
value: [ | ||
{ | ||
key: "week-day-type", | ||
value: [matrix.value[weekIndex]?.value[dateIndex]] | ||
} | ||
] | ||
} | ||
}[viewType2]; | ||
}, | ||
[createMatrix, today, weeksInMonth] | ||
); | ||
const setNext = useMemo(() => { | ||
switch (viewType) { | ||
case CalendarViewType_default.Month: | ||
return (date) => addMonths(startOfMonth2(date), 1); | ||
case CalendarViewType_default.Week: | ||
return (date) => addWeeks(startOfWeek(date, { weekStartsOn }), 1); | ||
case CalendarViewType_default.Day: | ||
return (date) => addDays(date, 1); | ||
} | ||
}, [viewType, weekStartsOn]); | ||
const setPrev = useMemo(() => { | ||
switch (viewType) { | ||
case CalendarViewType_default.Month: | ||
return (date) => subMonths(startOfMonth2(date), 1); | ||
case CalendarViewType_default.Week: | ||
return (date) => subWeeks(startOfWeek(date, { weekStartsOn }), 1); | ||
case CalendarViewType_default.Day: | ||
return (date) => subDays(date, 1); | ||
} | ||
}, [viewType, weekStartsOn]); | ||
return useMemo( | ||
() => ({ | ||
...calendar, | ||
headers: getHeaders(viewType), | ||
body: getBody(viewType), | ||
navigation: { | ||
toNext: () => setCursorDate((date) => setNext(date)), | ||
toPrev: () => setCursorDate((date) => setPrev(date)), | ||
setToday: () => setCursorDate(/* @__PURE__ */ new Date()), | ||
setDate: (date) => setCursorDate(date) | ||
}, | ||
view: { | ||
type: viewType, | ||
setViewType, | ||
setWeekStartsOn, | ||
isMonthView: viewType === CalendarViewType_default.Month, | ||
isWeekView: viewType === CalendarViewType_default.Week, | ||
isDayView: viewType === CalendarViewType_default.Day, | ||
showMonthView: () => setViewType(CalendarViewType_default.Month), | ||
showWeekView: () => setViewType(CalendarViewType_default.Week), | ||
showDayView: () => setViewType(CalendarViewType_default.Day) | ||
} | ||
}), | ||
[calendar, getBody, getHeaders, setNext, setPrev, viewType] | ||
); | ||
} | ||
export { | ||
CalendarViewType_default as CalendarViewType, | ||
arrayOf, | ||
generateID, | ||
isSameDate, | ||
isSameYearAndMonth, | ||
parseDate, | ||
pipe, | ||
pipeWith, | ||
useCalendar, | ||
withDateProps, | ||
withKey, | ||
withKeyProps | ||
}; |
{ | ||
"name": "@h6s/calendar", | ||
"version": "1.1.0-alpha.2", | ||
"version": "2.0.0", | ||
"sideEffects": false, | ||
"main": "dist/index.js", | ||
"files": [ | ||
"dist", | ||
"esm" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./esm/index.mjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "src/index.ts", | ||
"type": "module", | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.cts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./esm/index.mjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"import": "esm/index.mjs", | ||
"module": "esm/index.mjs" | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
}, | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepack": "yarn build", | ||
"prebuild": "rimraf dist esm", | ||
"build:type": "yarn run -T tsc --emitDeclarationOnly --declaration", | ||
"build": "yarn build:type && node ../../scripts/build.js", | ||
"build": "yarn run -T tsup", | ||
"lint": "yarn run -T eslint 'src/**/*.{js,jsx,ts,tsx}'", | ||
"lint:fix": "yarn lint --fix", | ||
"typecheck": "yarn run -T tsc", | ||
"test": "yarn run -T jest --config ../../jest.config.js --roots './packages/calendar/src'", | ||
"test": "vitest", | ||
"test:playwright": "playwright test", | ||
"test:cov": "yarn test --coverage", | ||
"test:watch": "yarn test --watch", | ||
"semantic-release": "semantic-release" | ||
"test:watch": "yarn test --watch" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "1.17.1", | ||
"@storybook/react": "6.4.9", | ||
"@testing-library/react-hooks": "7.0.2", | ||
"@types/jest": "27.4.0", | ||
"@types/node": "17.0.5", | ||
"@types/react": "^18.0.25", | ||
"date-fns": "2.28.0", | ||
"@storybook/react": "7.6.4", | ||
"@testing-library/jest-dom": "^6.1.5", | ||
"@testing-library/react-hooks": "8.0.1", | ||
"@types/node": "20.10.4", | ||
"@types/react": "^18.2.43", | ||
"date-fns": "2.30.0", | ||
"playwright": "1.17.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-test-renderer": "^18.2.0" | ||
"react-test-renderer": "^18.2.0", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.7", | ||
"vitest": "^1.0.4" | ||
}, | ||
"peerDependencies": { | ||
"date-fns": ">= 2", | ||
"react": "^16.8 || ^17.0 || ^18.0" | ||
"react": ">= 18" | ||
}, | ||
@@ -71,4 +65,3 @@ "peerDependenciesMeta": { | ||
} | ||
}, | ||
"module": "esm/index.mjs" | ||
} | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
771
1
Yes
36921
14
7
1