Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-availability-calendar

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-availability-calendar - npm Package Compare versions

Comparing version 0.2.15 to 0.2.16

39

dist/react-availability-calendar.cjs.development.js

@@ -94,4 +94,2 @@ 'use strict';

var msInHour = 1 * 60 * 60 * 1000;
var msInMinute = 1 * 60 * 1000;
var minuteInHour = 60;

@@ -147,9 +145,9 @@ function rotateMs(ms, msOffset) {

function calcOffsetFromProviderTimeZoneMs(providerTimeZone) {
function calcOffsetFromProviderTimeZoneMs(localMs, providerTimeZone) {
if (!providerTimeZone) return 0;
var now = new Date();
var tzNow = new Date(now.toLocaleString('en-US', {
var localDate = new Date(localMs);
var localDateInProviderTz = new Date(localDate.toLocaleString('en-US', {
timeZone: providerTimeZone
}));
var offsetRoundedToNearestHour = Math.floor((tzNow.getTime() - now.getTime()) / msInHour + 0.5) * msInHour;
var offsetRoundedToNearestHour = Math.floor((localDateInProviderTz.getTime() - localDate.getTime()) / msInHour + 0.5) * msInHour;
return offsetRoundedToNearestHour;

@@ -161,3 +159,3 @@ }

function roundToHour(ms) {
return Math.floor(ms / ms_in_hour) * ms_in_hour;
return Math.floor(ms / msInHour) * msInHour;
}

@@ -235,11 +233,12 @@

function addBlockOutBookings(blockOutPeriods, provideTimeZone, bookings, periodStart, periodEnd) {
var tzOffsetMs = calcOffsetFromProviderTimeZoneMs(provideTimeZone);
var blockOutPeriodsTz = rotateRangesByms(blockOutPeriods, tzOffsetMs);
function addBlockOutBookings(blockOutPeriods, providerTimeZone, bookings, localStart, //client local start midnight
localEnd //client local end midnight
) {
var res = [].concat(bookings);
var periodStartRoundedToDayMs = new Date(periodStart.getFullYear(), periodStart.getMonth(), periodStart.getDate()).getTime();
var periodEndRoundedToDayMs = new Date(periodEnd.getFullYear(), periodEnd.getMonth(), periodEnd.getDate()).getTime();
var periodStartRoundedToDayMs = localStart.getTime();
var periodEndRoundedToDayMs = localEnd.getTime();
for (var i = periodStartRoundedToDayMs; i <= periodEndRoundedToDayMs; i = i + msInDay) {
var day = new Date(i);
var tzOffsetMs = calcOffsetFromProviderTimeZoneMs(i, providerTimeZone);
var blockOutPeriodsTz = rotateRangesByms(blockOutPeriods, tzOffsetMs);

@@ -259,16 +258,12 @@ for (var _iterator3 = blockOutPeriodsTz, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {

var period = _ref3;
var hourStart = Math.floor(period[0] / msInHour);
var hourEnd = Math.floor(period[1] / msInHour);
var minuteStart = Math.floor(period[0] / msInMinute) % minuteInHour;
var minuteEnd = Math.floor(period[1] / msInMinute) % minuteInHour;
res.push({
startDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), hourStart, minuteStart),
endDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), hourEnd, minuteEnd)
startDate: new Date(i + period[0]),
endDate: new Date(i + period[1])
});
} // Ensure each availability is broken up at EOD and doesn't span days
} // Ensure each availability is broken up at local EOD and doesn't span days
res.push({
startDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), 23, 59),
endDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), 24)
startDate: new Date(i + msInDay - 1),
endDate: new Date(i + msInDay)
});

@@ -275,0 +270,0 @@ }

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}function r(e){function t(e){return e.endDate.getTime()-e.startDate.getTime()}function a(e,t){t=t>0?Math.min(864e5,t):Math.max(-864e5,t);var a=(e=Math.min(864e5,Math.max(0,e)))-t;return a<0?a+864e5:a}function n(e,t){return e&&t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function r(e,t,n,r,o){for(var l=function(e,t){var n=e.map((function(e){return[a(e[0],t)%864e5,a(e[1],t)%864e5]})),r=n.map((function(e,t){return e[1]<e[0]?t:-1})).filter((function(e){return e>=0})),o=Array.isArray(r),l=0;for(r=o?r:r[Symbol.iterator]();;){var s;if(o){if(l>=r.length)break;s=r[l++]}else{if((l=r.next()).done)break;s=l.value}var i=n[s];n[s]=[-1,-1],n.push([i[0],864e5]),n.push([0,i[1]])}var u=n.filter((function(e){return e[0]>=0}));return u.sort((function(e,t){return e[0]-t[0]})),u}(e,function(e){if(!e)return 0;var t=new Date,a=new Date(t.toLocaleString("en-US",{timeZone:e}));return 36e5*Math.floor((a.getTime()-t.getTime())/36e5+.5)}(t)),s=[].concat(n),i=new Date(r.getFullYear(),r.getMonth(),r.getDate()).getTime(),u=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),m=i;m<=u;m+=864e5){var d=new Date(m),c=l,f=Array.isArray(c),v=0;for(c=f?c:c[Symbol.iterator]();;){var h;if(f){if(v>=c.length)break;h=c[v++]}else{if((v=c.next()).done)break;h=v.value}var y=h,D=Math.floor(y[0]/36e5),g=Math.floor(y[1]/36e5),p=Math.floor(y[0]/6e4)%60,b=Math.floor(y[1]/6e4)%60;s.push({startDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),D,p),endDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),g,b)})}s.push({startDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),23,59),endDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),24)})}return s}return{msInHour:36e5,datesEqual:n,formatAsMonth:function(t){return e(t).format("MMM YYYY")},sameMonth:function(t,a){return n(e(t).startOf("month").toDate(),e(a).startOf("month").toDate())},formatAsDateWithTime:function(t){return e(t).format("ddd, MMM Do h:mma")},formatAsDateJustTime:function(t){return e(t).format("h:mma")},formatAsDate:function(t){return e(t).format("ddd, MMM Do YYYY")},shouldHideWeek:function(t,a,r){return t&&(o=a[0],!n(e(t).startOf("week").toDate(),e(o).startOf("week").toDate()))&&r.length>0;var o},availByIndex:function(e,t){return(e||[]).map((function(e){return{hasAvail:t.some((function(t){return n(t.startDate,e)}))}}))},addBlockOutBookings:r,availabilitiesFromBookings:function(e,t,a,n,o,l){var s,i=Math.max((s=n.getTime(),36e5*Math.floor(s/36e5)+36e5),o.getTime()),u=new Date(i);if(l.getTime()<=u.getTime())return[];var m=[{startDate:u,endDate:l}],d=r(e,t,a,u,l).sort((function(e,t){return e.startDate.getTime()-t.startDate.getTime()})),c=Array.isArray(d),f=0;for(d=c?d:d[Symbol.iterator]();;){var v;if(c){if(f>=d.length)break;v=d[f++]}else{if((f=d.next()).done)break;v=f.value}var h=v,y=m[m.length-1],D=h.startDate.getTime(),g=h.endDate.getTime();if(h.startDate&&h.endDate&&!(D>=g))if(D<y.startDate.getTime())y.startDate=new Date(Math.max(y.startDate.getTime(),g));else if(D<y.endDate.getTime()){var p=y.endDate;y.endDate=new Date(D),g<p.getTime()&&m.push({startDate:new Date(g),endDate:p})}}return m},toStartAndEnd:function(e){var t={startDate:e.start||e[0],endDate:e.end||e[e.length-1]};return t.startDate.getTime()===t.endDate.getTime()&&(t.endDate=new Date(t.endDate.getTime()+864e5)),t},monthRangeForDate:function(t){return{start:e(t).startOf("month").toDate(),end:e(t).endOf("month").toDate()}},monthDaysForDate:function(t){for(var a=e(t).startOf("month"),n=e(t).endOf("month"),r=a.startOf("week"),o=n.endOf("week").diff(r,"days")+1,l=[],s=[],i=r,u=Math.floor(o/7),m=0;m<u;++m){var d=[];l.push(d);for(var c=0;c<7;++c)d.push(i.toDate()),s.push(i.toDate()),i.add(1,"day")}return{weeks:l,days:s}},chunkify:function(e,a,n){var r=[],o=e,l=Array.isArray(o),s=0;for(o=l?o:o[Symbol.iterator]();;){var i;if(l){if(s>=o.length)break;i=o[s++]}else{if((s=o.next()).done)break;i=s.value}for(var u=i,m=u.endDate.getTime(),d=u.startDate.getTime();d<m;d+=n){var c=d,f={startDate:new Date(c),endDate:new Date(Math.min(m,c+a))};t(f)>=a&&r.push(f)}}return r}}}var o={dayClassBase:"rounded-circle",dayClassSelected:"border-primary",dayClassHasAvailability:"border-info",dayClassDefault:"border border-default",slotsContainerStyleShow:{transition:"transform 300ms",transform:"scale(1)"},slotsContainerStyleHide:{transition:"transform 300ms",transform:"scale(0)"},slotContainerCloseClass:"close",slotButtonClass:"btn btn-primary",toolBarStyle:{flexWrap:"nowrap",width:350,minHeight:50},toolBarButtonsContainerClass:"border btn-group w-100",toolBarButtonClass:"btn",toolBarLabelClass:"btn btn-link",requestAppointmentLabel:"Request Appointment"},l={format:function(e){throw new Error("not implemented")},startOf:function(e){throw new Error("not implemented")},endOf:function(e){throw new Error("not implemented")},add:function(e,t){throw new Error("not implemented")},diff:function(e,t,a){throw new Error("not implemented")},toDate:function(){throw new Error("not implemented")}},s=a.createContext({moment:function(){return l},utils:r((function(){return l})),theme:o}),i=function(){return t.useContext(s)},u=function(e){var n=e.moment,o=e.theme,l=e.children,i=t.useMemo((function(){return r(n)}),[n]);return a.createElement(s.Provider,{value:{moment:n,utils:i,theme:o}},l)};function m(e,t){return"function"==typeof e?e(t||{}):e}function d(e,t){return"function"==typeof e?e(t||{}):e}function c(e,t,a,r,o,l){return void 0===e?{Root:t.Root,className:d(t.className,a),style:n({},m(t.style,a)),internalProps:t.internalProps}:{Root:e.Root||t.Root,className:d(e.className,a)||d(t.className,a),style:n({},m(t.style,a),{},m(e.style,a)),internalProps:n({},t.internalProps,{},e.internalProps)}}function f(e,t){return c(e?e.ToolBar:void 0,t,{})}function v(e,t){return c(e?e.ToolBarButton:void 0,t,{})}function h(e,t){return c(e?e.Weekdays:void 0,t,{})}function y(e,t){return c(e?e.Weekday:void 0,t,{})}function D(e,t){return c(e?e.DayCells:void 0,t,{})}function g(e,t,a){return c(e?e.DayCell:void 0,t,a)}function p(e,t){return c(e?e.Availabilities:void 0,t,{})}function b(e,t,a){return c(e?e.AvailSlot:void 0,t,a)}var w=function(e){var t=e.localizer.messages,n=e.label,r=e.onNavigate,o=e.overrides,l=i().theme,s=f(o,{style:l.toolBarStyle,className:l.toolBarButtonsContainerClass}),u=s.Root,m=s.style,d=s.className;return u?a.createElement(u,Object.assign({},{localizer:{messages:t},label:n,onNavigate:r})):a.createElement("div",{style:m,className:d,role:"group"},a.createElement(E,{theme:l,overrides:o,onClick:function(){return r("TODAY")},message:t.today}),a.createElement(E,{theme:l,overrides:o,onClick:function(){return r("PREV")},message:t.previous}),a.createElement(E,{theme:l,overrides:o,onClick:function(){return r("NEXT")},message:t.next}),a.createElement("button",{disabled:!0,className:l.toolBarLabelClass,style:{width:110}},a.createElement("span",null,n)))};function E(e){var t=e.message,n=e.onClick,r=v(e.overrides,{className:e.theme.toolBarButtonClass}),o=r.Root,l=r.style,s=r.internalProps,i=r.className;return void 0!==o?a.createElement(o,{message:t,onClicked:n}):a.createElement("button",Object.assign({className:i,onClick:n,style:l},s),t)}var x=["S","M","T","W","Th","F","Sa"],C=function(e){var t=e.overrides,n=h(t,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),r=n.Root,o=n.style;if(r)return a.createElement(r,null);var l=y(t,{className:"border border-default",style:{flex:1,height:50,marginBottom:10,display:"flex",justifyContent:"center",alignItems:"center"}}),s=l.Root,i=l.className,u=l.style;return a.createElement("div",{style:o},x.map((function(e){return s?a.createElement(s,{weekday:e}):a.createElement("div",{className:i,key:e,style:u},e)})))};function M(e){var t=e.theme,n=e.onAvailabilitySelected,r=e.s,o=e.formatAsDateJustTime,l=b(e.overrides,{className:t.slotButtonClass,style:{minWidth:200}},{date:r.startDate}),s=l.Root,i=l.className,u=l.style;return s?a.createElement(s,Object.assign({},{theme:t,onAvailabilitySelected:n,s:r,formatAsDateJustTime:o})):a.createElement("div",{style:{marginBottom:10}},a.createElement("button",{className:i,disabled:!1,style:u,onClick:function(){return n({startDate:new Date(r.startDate),endDate:new Date(r.endDate)})}},o(new Date(r.startDate))))}var k=function(e){var t=e.viewingDayAvailabilities,n=e.handleUnselect,r=e.onAvailabilitySelected,o=e.show,l=e.slotStepMs,s=e.slotLengthMs,i=e.utils,u=e.theme,m=e.overrides,d=p(m,{style:o?u.slotsContainerStyleShow:u.slotsContainerStyleHide}),c=d.Root,f=d.style;return c?a.createElement(c,Object.assign({},{viewingDayAvailabilities:t,handleUnselect:n,onAvailabilitySelected:r,show:o,slotStepMs:l,slotLengthMs:s,utils:i,theme:u})):a.createElement("div",{style:f},o&&a.createElement("div",{className:"mt-2 mr-1"},a.createElement("button",{type:"button",className:u.slotContainerCloseClass,"aria-label":"Close",style:{outline:"none"},onClick:n},a.createElement("span",{"aria-hidden":"true"},"×")),a.createElement(A,{theme:u,durationMinutes:60,avails:t,onAvailabilitySelected:r,slotLengthMs:s,slotStepMs:l,utils:i,overrides:m})))},A=function(e){var n=e.avails,r=e.slotLengthMs,o=e.slotStepMs,l=e.onAvailabilitySelected,s=e.theme,i=e.utils,u=e.overrides,m=i.chunkify,d=i.msInHour,c=i.formatAsDate,f=i.formatAsDateJustTime,v=t.useMemo((function(){return m(n.map((function(e){return{startDate:e.startDate,endDate:e.endDate}})),r||1*d,o||.5*d)}),[n,d,m,r,o]);return a.createElement("div",null,a.createElement("h4",null,s.requestAppointmentLabel),a.createElement("h5",null,n&&n.length>0?c(n[0].startDate):""),v.map((function(e,t){return a.createElement(M,Object.assign({key:"b_"+t},{theme:s,onAvailabilitySelected:l,s:e,formatAsDateJustTime:f,overrides:u}))})))},S=function(e){var t=e.date,r=e.shouldDisplay,o=e.dayIndexInWeek,l=e.weekIndexInCalRange,s=e.availsByIndex,i=e.selectedDate,u=e.handleSelected,m=e.moment,d=e.utils,c=e.theme,f=e.overrides,v=7*l+o,h=!!i&&d.datesEqual(t,i),y=s[v].hasAvail,D=g(f,{className:c.dayClassBase+" "+(i&&d.datesEqual(t,i)?c.dayClassSelected:s[v].hasAvail?c.dayClassHasAvailability:c.dayClassDefault),style:{cursor:"pointer",border:i&&d.datesEqual(t,i)?"4px solid":s[v].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{date:t,isSelected:h,hasAvail:y}),p=D.Root,b=D.style,w=D.className;if(p)return a.createElement(p,Object.assign({},{shouldDisplay:r,date:t,dayIndexInWeek:o,weekIndexInCalRange:l,availsByIndex:s,selectedDate:i,handleSelected:u,moment:m,utils:d,theme:c}));var E=r?b:n({},b,{visibility:"hidden"});return a.createElement("div",{className:w,style:E,onClick:function(){return u(t)}},m(t).format("D"))};function T(e){var t=e.week,n=e.date,r=e.selectedDate,o=e.weekIndexInCalRange,l=e.handleSelected,s=e.availsByIndex,i=e.moment,u=e.utils,m=e.theme,d=e.overrides,c=D(d,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),f=c.Root,v=c.style;return f?a.createElement(f,Object.assign({},{date:n,week:t,selectedDate:r,weekIndexInCalRange:o,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m})):a.createElement("div",{style:v},t.map((function(e,t){return a.createElement(S,Object.assign({key:"d_"+t},{shouldDisplay:u.sameMonth(e,n),date:e,selectedDate:r,weekIndexInCalRange:o,dayIndexInWeek:t,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m,overrides:d}))})))}var O=function(e){var r=e.availabilities,o=e.onAvailabilitySelected,l=e.slotLengthMs,s=e.slotStepMs,u=e.date,m=e.style,d=e.overrides,c=i(),f=c.moment,v=c.theme,h=c.utils,y=t.useState(null),D=y[0],g=y[1];t.useEffect((function(){g(null)}),[u]);var p=function(e){D&&h.datesEqual(e,D)?g(null):g(e)},b=t.useMemo((function(){return h.monthDaysForDate(u)}),[u,h]),w=b.days,E=b.weeks,x=t.useMemo((function(){return h.availByIndex(w,r)}),[w,r,h]),M=t.useMemo((function(){return null!==D?(r||[]).filter((function(e){return h.datesEqual(e.startDate,D)})):[]}),[D,r,h]);return a.createElement("div",{style:n({minHeight:368},m)},a.createElement(C,{overrides:d}),E.map((function(e,t){return h.shouldHideWeek(D,e,M)?null:a.createElement(a.Fragment,{key:"w_"+t},a.createElement(T,Object.assign({},{date:u,week:e,selectedDate:D,weekIndexInCalRange:t,handleSelected:p,availsByIndex:x,moment:f,utils:h,theme:v,overrides:d})))})),a.createElement(k,Object.assign({},{show:!!D&&M.length>0,onAvailabilitySelected:o,viewingDayAvailabilities:M,handleUnselect:function(){g(null)},slotLengthMs:l,slotStepMs:s,utils:h,theme:v,overrides:d})))},B=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.blockOutPeriods,l=e.providerTimeZone,s=e.bookings,u=e.avails,m=e.onCalRangeChange,d=e.slotLengthMs,c=e.slotStepMs,f=e.overrides,v=i(),h=v.moment,y=v.utils,D=t.useState(n||new Date)[0],g=t.useState(y.monthRangeForDate(D)),p=g[0],b=g[1],E=t.useState(D),x=E[0],C=E[1],M=t.useRef(null);t.useEffect((function(){M.current!==p&&(m&&m(p),M.current=p)}),[p,m]);var k=t.useMemo((function(){if(u)return u;var e=y.toStartAndEnd(p);return y.availabilitiesFromBookings(o||[],l,s,D,e.startDate,e.endDate)}),[u,s,l,p,D,o,y]);return a.createElement("div",null,a.createElement(w,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return C(t),void b(y.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=h(x).add("NEXT"===e?1:-1,"month").toDate();C(a),b(y.monthRangeForDate(a))}},label:y.formatAsMonth(x),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:f}),a.createElement(O,{availabilities:k,date:x,onAvailabilitySelected:r,slotLengthMs:d,slotStepMs:c,overrides:f}))};exports.AvailSlot=M,exports.AvailSlots=k,exports.AvailabilityCalendar=function(e){var t=e.moment,r=e.theme,l=function(e,t){if(null==e)return{};var a,n,r={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(a=o[n])>=0||(r[a]=e[a]);return r}(e,["moment","theme"]);return a.createElement(u,{moment:t,theme:r?n({},o,{},r):o},a.createElement(B,Object.assign({},l)))},exports.createUtils=r,exports.defaultComponents={ToolBar:{},ToolBarButton:{},Weekdays:{},Weekday:{},DayCells:{},DayCell:{},Availabilities:{},AvailSlot:{}},exports.defaultTheme=o,exports.getAvailOverride=b,exports.getAvailsOverride=p,exports.getDayCellOverride=g,exports.getDayCellsOverride=D,exports.getToolBarButtonOverride=v,exports.getToolBarOverride=f,exports.getWeekdayOverride=y,exports.getWeekdaysOverride=h;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}function r(e){function t(e){return e.endDate.getTime()-e.startDate.getTime()}function a(e,t){t=t>0?Math.min(864e5,t):Math.max(-864e5,t);var a=(e=Math.min(864e5,Math.max(0,e)))-t;return a<0?a+864e5:a}function n(e,t){var n=e.map((function(e){return[a(e[0],t)%864e5,a(e[1],t)%864e5]})),r=n.map((function(e,t){return e[1]<e[0]?t:-1})).filter((function(e){return e>=0})),o=Array.isArray(r),s=0;for(r=o?r:r[Symbol.iterator]();;){var l;if(o){if(s>=r.length)break;l=r[s++]}else{if((s=r.next()).done)break;l=s.value}var i=n[l];n[l]=[-1,-1],n.push([i[0],864e5]),n.push([0,i[1]])}var u=n.filter((function(e){return e[0]>=0}));return u.sort((function(e,t){return e[0]-t[0]})),u}function r(e,t){if(!t)return 0;var a=new Date(e),n=new Date(a.toLocaleString("en-US",{timeZone:t}));return 36e5*Math.floor((n.getTime()-a.getTime())/36e5+.5)}function o(e,t){return e&&t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function s(e,t,a,o,s){for(var l=[].concat(a),i=o.getTime(),u=s.getTime(),m=i;m<=u;m+=864e5){var d=n(e,r(m,t)),c=Array.isArray(d),f=0;for(d=c?d:d[Symbol.iterator]();;){var v;if(c){if(f>=d.length)break;v=d[f++]}else{if((f=d.next()).done)break;v=f.value}var h=v;l.push({startDate:new Date(m+h[0]),endDate:new Date(m+h[1])})}l.push({startDate:new Date(m+864e5-1),endDate:new Date(m+864e5)})}return l}return{msInHour:36e5,datesEqual:o,formatAsMonth:function(t){return e(t).format("MMM YYYY")},sameMonth:function(t,a){return o(e(t).startOf("month").toDate(),e(a).startOf("month").toDate())},formatAsDateWithTime:function(t){return e(t).format("ddd, MMM Do h:mma")},formatAsDateJustTime:function(t){return e(t).format("h:mma")},formatAsDate:function(t){return e(t).format("ddd, MMM Do YYYY")},shouldHideWeek:function(t,a,n){return t&&(r=a[0],!o(e(t).startOf("week").toDate(),e(r).startOf("week").toDate()))&&n.length>0;var r},availByIndex:function(e,t){return(e||[]).map((function(e){return{hasAvail:t.some((function(t){return o(t.startDate,e)}))}}))},addBlockOutBookings:s,availabilitiesFromBookings:function(e,t,a,n,r,o){var l,i=Math.max((l=n.getTime(),36e5*Math.floor(l/36e5)+36e5),r.getTime()),u=new Date(i);if(o.getTime()<=u.getTime())return[];var m=[{startDate:u,endDate:o}],d=s(e,t,a,u,o).sort((function(e,t){return e.startDate.getTime()-t.startDate.getTime()})),c=Array.isArray(d),f=0;for(d=c?d:d[Symbol.iterator]();;){var v;if(c){if(f>=d.length)break;v=d[f++]}else{if((f=d.next()).done)break;v=f.value}var h=v,y=m[m.length-1],D=h.startDate.getTime(),g=h.endDate.getTime();if(h.startDate&&h.endDate&&!(D>=g))if(D<y.startDate.getTime())y.startDate=new Date(Math.max(y.startDate.getTime(),g));else if(D<y.endDate.getTime()){var p=y.endDate;y.endDate=new Date(D),g<p.getTime()&&m.push({startDate:new Date(g),endDate:p})}}return m},toStartAndEnd:function(e){var t={startDate:e.start||e[0],endDate:e.end||e[e.length-1]};return t.startDate.getTime()===t.endDate.getTime()&&(t.endDate=new Date(t.endDate.getTime()+864e5)),t},monthRangeForDate:function(t){return{start:e(t).startOf("month").toDate(),end:e(t).endOf("month").toDate()}},monthDaysForDate:function(t){for(var a=e(t).startOf("month"),n=e(t).endOf("month"),r=a.startOf("week"),o=n.endOf("week").diff(r,"days")+1,s=[],l=[],i=r,u=Math.floor(o/7),m=0;m<u;++m){var d=[];s.push(d);for(var c=0;c<7;++c)d.push(i.toDate()),l.push(i.toDate()),i.add(1,"day")}return{weeks:s,days:l}},chunkify:function(e,a,n){var r=[],o=e,s=Array.isArray(o),l=0;for(o=s?o:o[Symbol.iterator]();;){var i;if(s){if(l>=o.length)break;i=o[l++]}else{if((l=o.next()).done)break;i=l.value}for(var u=i,m=u.endDate.getTime(),d=u.startDate.getTime();d<m;d+=n){var c=d,f={startDate:new Date(c),endDate:new Date(Math.min(m,c+a))};t(f)>=a&&r.push(f)}}return r}}}var o={dayClassBase:"rounded-circle",dayClassSelected:"border-primary",dayClassHasAvailability:"border-info",dayClassDefault:"border border-default",slotsContainerStyleShow:{transition:"transform 300ms",transform:"scale(1)"},slotsContainerStyleHide:{transition:"transform 300ms",transform:"scale(0)"},slotContainerCloseClass:"close",slotButtonClass:"btn btn-primary",toolBarStyle:{flexWrap:"nowrap",width:350,minHeight:50},toolBarButtonsContainerClass:"border btn-group w-100",toolBarButtonClass:"btn",toolBarLabelClass:"btn btn-link",requestAppointmentLabel:"Request Appointment"},s={format:function(e){throw new Error("not implemented")},startOf:function(e){throw new Error("not implemented")},endOf:function(e){throw new Error("not implemented")},add:function(e,t){throw new Error("not implemented")},diff:function(e,t,a){throw new Error("not implemented")},toDate:function(){throw new Error("not implemented")}},l=a.createContext({moment:function(){return s},utils:r((function(){return s})),theme:o}),i=function(){return t.useContext(l)},u=function(e){var n=e.moment,o=e.theme,s=e.children,i=t.useMemo((function(){return r(n)}),[n]);return a.createElement(l.Provider,{value:{moment:n,utils:i,theme:o}},s)};function m(e,t){return"function"==typeof e?e(t||{}):e}function d(e,t){return"function"==typeof e?e(t||{}):e}function c(e,t,a,r,o,s){return void 0===e?{Root:t.Root,className:d(t.className,a),style:n({},m(t.style,a)),internalProps:t.internalProps}:{Root:e.Root||t.Root,className:d(e.className,a)||d(t.className,a),style:n({},m(t.style,a),{},m(e.style,a)),internalProps:n({},t.internalProps,{},e.internalProps)}}function f(e,t){return c(e?e.ToolBar:void 0,t,{})}function v(e,t){return c(e?e.ToolBarButton:void 0,t,{})}function h(e,t){return c(e?e.Weekdays:void 0,t,{})}function y(e,t){return c(e?e.Weekday:void 0,t,{})}function D(e,t){return c(e?e.DayCells:void 0,t,{})}function g(e,t,a){return c(e?e.DayCell:void 0,t,a)}function p(e,t){return c(e?e.Availabilities:void 0,t,{})}function b(e,t,a){return c(e?e.AvailSlot:void 0,t,a)}var w=function(e){var t=e.localizer.messages,n=e.label,r=e.onNavigate,o=e.overrides,s=i().theme,l=f(o,{style:s.toolBarStyle,className:s.toolBarButtonsContainerClass}),u=l.Root,m=l.style,d=l.className;return u?a.createElement(u,Object.assign({},{localizer:{messages:t},label:n,onNavigate:r})):a.createElement("div",{style:m,className:d,role:"group"},a.createElement(E,{theme:s,overrides:o,onClick:function(){return r("TODAY")},message:t.today}),a.createElement(E,{theme:s,overrides:o,onClick:function(){return r("PREV")},message:t.previous}),a.createElement(E,{theme:s,overrides:o,onClick:function(){return r("NEXT")},message:t.next}),a.createElement("button",{disabled:!0,className:s.toolBarLabelClass,style:{width:110}},a.createElement("span",null,n)))};function E(e){var t=e.message,n=e.onClick,r=v(e.overrides,{className:e.theme.toolBarButtonClass}),o=r.Root,s=r.style,l=r.internalProps,i=r.className;return void 0!==o?a.createElement(o,{message:t,onClicked:n}):a.createElement("button",Object.assign({className:i,onClick:n,style:s},l),t)}var x=["S","M","T","W","Th","F","Sa"],C=function(e){var t=e.overrides,n=h(t,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),r=n.Root,o=n.style;if(r)return a.createElement(r,null);var s=y(t,{className:"border border-default",style:{flex:1,height:50,marginBottom:10,display:"flex",justifyContent:"center",alignItems:"center"}}),l=s.Root,i=s.className,u=s.style;return a.createElement("div",{style:o},x.map((function(e){return l?a.createElement(l,{weekday:e}):a.createElement("div",{className:i,key:e,style:u},e)})))};function k(e){var t=e.theme,n=e.onAvailabilitySelected,r=e.s,o=e.formatAsDateJustTime,s=b(e.overrides,{className:t.slotButtonClass,style:{minWidth:200}},{date:r.startDate}),l=s.Root,i=s.className,u=s.style;return l?a.createElement(l,Object.assign({},{theme:t,onAvailabilitySelected:n,s:r,formatAsDateJustTime:o})):a.createElement("div",{style:{marginBottom:10}},a.createElement("button",{className:i,disabled:!1,style:u,onClick:function(){return n({startDate:new Date(r.startDate),endDate:new Date(r.endDate)})}},o(new Date(r.startDate))))}var A=function(e){var t=e.viewingDayAvailabilities,n=e.handleUnselect,r=e.onAvailabilitySelected,o=e.show,s=e.slotStepMs,l=e.slotLengthMs,i=e.utils,u=e.theme,m=e.overrides,d=p(m,{style:o?u.slotsContainerStyleShow:u.slotsContainerStyleHide}),c=d.Root,f=d.style;return c?a.createElement(c,Object.assign({},{viewingDayAvailabilities:t,handleUnselect:n,onAvailabilitySelected:r,show:o,slotStepMs:s,slotLengthMs:l,utils:i,theme:u})):a.createElement("div",{style:f},o&&a.createElement("div",{className:"mt-2 mr-1"},a.createElement("button",{type:"button",className:u.slotContainerCloseClass,"aria-label":"Close",style:{outline:"none"},onClick:n},a.createElement("span",{"aria-hidden":"true"},"×")),a.createElement(S,{theme:u,durationMinutes:60,avails:t,onAvailabilitySelected:r,slotLengthMs:l,slotStepMs:s,utils:i,overrides:m})))},S=function(e){var n=e.avails,r=e.slotLengthMs,o=e.slotStepMs,s=e.onAvailabilitySelected,l=e.theme,i=e.utils,u=e.overrides,m=i.chunkify,d=i.msInHour,c=i.formatAsDate,f=i.formatAsDateJustTime,v=t.useMemo((function(){return m(n.map((function(e){return{startDate:e.startDate,endDate:e.endDate}})),r||1*d,o||.5*d)}),[n,d,m,r,o]);return a.createElement("div",null,a.createElement("h4",null,l.requestAppointmentLabel),a.createElement("h5",null,n&&n.length>0?c(n[0].startDate):""),v.map((function(e,t){return a.createElement(k,Object.assign({key:"b_"+t},{theme:l,onAvailabilitySelected:s,s:e,formatAsDateJustTime:f,overrides:u}))})))},M=function(e){var t=e.date,r=e.shouldDisplay,o=e.dayIndexInWeek,s=e.weekIndexInCalRange,l=e.availsByIndex,i=e.selectedDate,u=e.handleSelected,m=e.moment,d=e.utils,c=e.theme,f=e.overrides,v=7*s+o,h=!!i&&d.datesEqual(t,i),y=l[v].hasAvail,D=g(f,{className:c.dayClassBase+" "+(i&&d.datesEqual(t,i)?c.dayClassSelected:l[v].hasAvail?c.dayClassHasAvailability:c.dayClassDefault),style:{cursor:"pointer",border:i&&d.datesEqual(t,i)?"4px solid":l[v].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{date:t,isSelected:h,hasAvail:y}),p=D.Root,b=D.style,w=D.className;if(p)return a.createElement(p,Object.assign({},{shouldDisplay:r,date:t,dayIndexInWeek:o,weekIndexInCalRange:s,availsByIndex:l,selectedDate:i,handleSelected:u,moment:m,utils:d,theme:c}));var E=r?b:n({},b,{visibility:"hidden"});return a.createElement("div",{className:w,style:E,onClick:function(){return u(t)}},m(t).format("D"))};function T(e){var t=e.week,n=e.date,r=e.selectedDate,o=e.weekIndexInCalRange,s=e.handleSelected,l=e.availsByIndex,i=e.moment,u=e.utils,m=e.theme,d=e.overrides,c=D(d,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),f=c.Root,v=c.style;return f?a.createElement(f,Object.assign({},{date:n,week:t,selectedDate:r,weekIndexInCalRange:o,handleSelected:s,availsByIndex:l,moment:i,utils:u,theme:m})):a.createElement("div",{style:v},t.map((function(e,t){return a.createElement(M,Object.assign({key:"d_"+t},{shouldDisplay:u.sameMonth(e,n),date:e,selectedDate:r,weekIndexInCalRange:o,dayIndexInWeek:t,handleSelected:s,availsByIndex:l,moment:i,utils:u,theme:m,overrides:d}))})))}var O=function(e){var r=e.availabilities,o=e.onAvailabilitySelected,s=e.slotLengthMs,l=e.slotStepMs,u=e.date,m=e.style,d=e.overrides,c=i(),f=c.moment,v=c.theme,h=c.utils,y=t.useState(null),D=y[0],g=y[1];t.useEffect((function(){g(null)}),[u]);var p=function(e){D&&h.datesEqual(e,D)?g(null):g(e)},b=t.useMemo((function(){return h.monthDaysForDate(u)}),[u,h]),w=b.days,E=b.weeks,x=t.useMemo((function(){return h.availByIndex(w,r)}),[w,r,h]),k=t.useMemo((function(){return null!==D?(r||[]).filter((function(e){return h.datesEqual(e.startDate,D)})):[]}),[D,r,h]);return a.createElement("div",{style:n({minHeight:368},m)},a.createElement(C,{overrides:d}),E.map((function(e,t){return h.shouldHideWeek(D,e,k)?null:a.createElement(a.Fragment,{key:"w_"+t},a.createElement(T,Object.assign({},{date:u,week:e,selectedDate:D,weekIndexInCalRange:t,handleSelected:p,availsByIndex:x,moment:f,utils:h,theme:v,overrides:d})))})),a.createElement(A,Object.assign({},{show:!!D&&k.length>0,onAvailabilitySelected:o,viewingDayAvailabilities:k,handleUnselect:function(){g(null)},slotLengthMs:s,slotStepMs:l,utils:h,theme:v,overrides:d})))},B=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.blockOutPeriods,s=e.providerTimeZone,l=e.bookings,u=e.avails,m=e.onCalRangeChange,d=e.slotLengthMs,c=e.slotStepMs,f=e.overrides,v=i(),h=v.moment,y=v.utils,D=t.useState(n||new Date)[0],g=t.useState(y.monthRangeForDate(D)),p=g[0],b=g[1],E=t.useState(D),x=E[0],C=E[1],k=t.useRef(null);t.useEffect((function(){k.current!==p&&(m&&m(p),k.current=p)}),[p,m]);var A=t.useMemo((function(){if(u)return u;var e=y.toStartAndEnd(p);return y.availabilitiesFromBookings(o||[],s,l,D,e.startDate,e.endDate)}),[u,l,s,p,D,o,y]);return a.createElement("div",null,a.createElement(w,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return C(t),void b(y.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=h(x).add("NEXT"===e?1:-1,"month").toDate();C(a),b(y.monthRangeForDate(a))}},label:y.formatAsMonth(x),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:f}),a.createElement(O,{availabilities:A,date:x,onAvailabilitySelected:r,slotLengthMs:d,slotStepMs:c,overrides:f}))};exports.AvailSlot=k,exports.AvailSlots=A,exports.AvailabilityCalendar=function(e){var t=e.moment,r=e.theme,s=function(e,t){if(null==e)return{};var a,n,r={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(a=o[n])>=0||(r[a]=e[a]);return r}(e,["moment","theme"]);return a.createElement(u,{moment:t,theme:r?n({},o,{},r):o},a.createElement(B,Object.assign({},s)))},exports.createUtils=r,exports.defaultComponents={ToolBar:{},ToolBarButton:{},Weekdays:{},Weekday:{},DayCells:{},DayCell:{},Availabilities:{},AvailSlot:{}},exports.defaultTheme=o,exports.getAvailOverride=b,exports.getAvailsOverride=p,exports.getDayCellOverride=g,exports.getDayCellsOverride=D,exports.getToolBarButtonOverride=v,exports.getToolBarOverride=f,exports.getWeekdayOverride=y,exports.getWeekdaysOverride=h;
//# sourceMappingURL=react-availability-calendar.cjs.production.min.js.map

@@ -87,4 +87,2 @@ import React, { useMemo, useContext, useState, useEffect, useRef } from 'react';

var msInHour = 1 * 60 * 60 * 1000;
var msInMinute = 1 * 60 * 1000;
var minuteInHour = 60;

@@ -140,9 +138,9 @@ function rotateMs(ms, msOffset) {

function calcOffsetFromProviderTimeZoneMs(providerTimeZone) {
function calcOffsetFromProviderTimeZoneMs(localMs, providerTimeZone) {
if (!providerTimeZone) return 0;
var now = new Date();
var tzNow = new Date(now.toLocaleString('en-US', {
var localDate = new Date(localMs);
var localDateInProviderTz = new Date(localDate.toLocaleString('en-US', {
timeZone: providerTimeZone
}));
var offsetRoundedToNearestHour = Math.floor((tzNow.getTime() - now.getTime()) / msInHour + 0.5) * msInHour;
var offsetRoundedToNearestHour = Math.floor((localDateInProviderTz.getTime() - localDate.getTime()) / msInHour + 0.5) * msInHour;
return offsetRoundedToNearestHour;

@@ -154,3 +152,3 @@ }

function roundToHour(ms) {
return Math.floor(ms / ms_in_hour) * ms_in_hour;
return Math.floor(ms / msInHour) * msInHour;
}

@@ -228,11 +226,12 @@

function addBlockOutBookings(blockOutPeriods, provideTimeZone, bookings, periodStart, periodEnd) {
var tzOffsetMs = calcOffsetFromProviderTimeZoneMs(provideTimeZone);
var blockOutPeriodsTz = rotateRangesByms(blockOutPeriods, tzOffsetMs);
function addBlockOutBookings(blockOutPeriods, providerTimeZone, bookings, localStart, //client local start midnight
localEnd //client local end midnight
) {
var res = [].concat(bookings);
var periodStartRoundedToDayMs = new Date(periodStart.getFullYear(), periodStart.getMonth(), periodStart.getDate()).getTime();
var periodEndRoundedToDayMs = new Date(periodEnd.getFullYear(), periodEnd.getMonth(), periodEnd.getDate()).getTime();
var periodStartRoundedToDayMs = localStart.getTime();
var periodEndRoundedToDayMs = localEnd.getTime();
for (var i = periodStartRoundedToDayMs; i <= periodEndRoundedToDayMs; i = i + msInDay) {
var day = new Date(i);
var tzOffsetMs = calcOffsetFromProviderTimeZoneMs(i, providerTimeZone);
var blockOutPeriodsTz = rotateRangesByms(blockOutPeriods, tzOffsetMs);

@@ -252,16 +251,12 @@ for (var _iterator3 = blockOutPeriodsTz, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {

var period = _ref3;
var hourStart = Math.floor(period[0] / msInHour);
var hourEnd = Math.floor(period[1] / msInHour);
var minuteStart = Math.floor(period[0] / msInMinute) % minuteInHour;
var minuteEnd = Math.floor(period[1] / msInMinute) % minuteInHour;
res.push({
startDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), hourStart, minuteStart),
endDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), hourEnd, minuteEnd)
startDate: new Date(i + period[0]),
endDate: new Date(i + period[1])
});
} // Ensure each availability is broken up at EOD and doesn't span days
} // Ensure each availability is broken up at local EOD and doesn't span days
res.push({
startDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), 23, 59),
endDate: new Date(day.getFullYear(), day.getMonth(), day.getDate(), 24)
startDate: new Date(i + msInDay - 1),
endDate: new Date(i + msInDay)
});

@@ -268,0 +263,0 @@ }

@@ -15,3 +15,3 @@ import { Range, MsSinceMidnightRange, AvailabilityEvent, Booking } from '../types';

}[];
addBlockOutBookings: (blockOutPeriods: MsSinceMidnightRange[], provideTimeZone: string, bookings: Booking[], periodStart: Date, periodEnd: Date) => Booking[];
addBlockOutBookings: (blockOutPeriods: MsSinceMidnightRange[], providerTimeZone: string, bookings: Booking[], localStart: Date, localEnd: Date) => Booking[];
availabilitiesFromBookings: (blockOutPeriods: MsSinceMidnightRange[], providerTimeZone: string, bookings: Booking[], now: Date, periodStartArg: Date, periodEnd: Date) => AvailabilityEvent[];

@@ -18,0 +18,0 @@ toStartAndEnd: (range: Range) => {

{
"version": "0.2.15",
"version": "0.2.16",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc