Socket
Socket
Sign inDemoInstall

datetime-slot-picker

Package Overview
Dependencies
1
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.1.6

dist/datetime-slot-picker/p-7eaea2e2.system.entry.js

4

dist/cjs/datetime-slot-picker.cjs.entry.js

@@ -241,2 +241,6 @@ 'use strict';

this.isTimeSlotGridVisible = false;
if (!this.displayText) {
this.selectedDate = undefined;
this.selectedTime = undefined;
}
}

@@ -243,0 +247,0 @@ goBack() {

@@ -102,2 +102,6 @@ import { Component, Prop, h, State, Event, Watch } from '@stencil/core';

this.isTimeSlotGridVisible = false;
if (!this.displayText) {
this.selectedDate = undefined;
this.selectedTime = undefined;
}
}

@@ -104,0 +108,0 @@ goBack() {

@@ -239,2 +239,6 @@ import { createEvent, h, proxyCustomElement } from '@stencil/core/internal/client';

this.isTimeSlotGridVisible = false;
if (!this.displayText) {
this.selectedDate = undefined;
this.selectedTime = undefined;
}
}

@@ -241,0 +245,0 @@ goBack() {

2

dist/datetime-slot-picker/datetime-slot-picker.esm.js

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

import{p as e,w as t,d as s,N as i,a,b as o}from"./p-e1d7db57.js";(()=>{e.t=t.__cssshim;const o=Array.from(s.querySelectorAll("script")).find((e=>new RegExp(`/${i}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===i)),n=o["data-opts"]||{};return"onbeforeload"in o&&!history.scrollRestoration?{then(){}}:(n.resourcesUrl=new URL(".",new URL(o.getAttribute("data-resources-url")||o.src,t.location.href)).href,((e,a)=>{const o="__sc_import_"+i.replace(/\s|-/g,"_");try{t[o]=new Function("w","return import(w);//"+Math.random())}catch(n){const i=new Map;t[o]=n=>{const r=new URL(n,e).href;let d=i.get(r);if(!d){const e=s.createElement("script");e.type="module",e.crossOrigin=a.crossOrigin,e.src=URL.createObjectURL(new Blob([`import * as m from '${r}'; window.${o}.m = m;`],{type:"application/javascript"})),d=new Promise((s=>{e.onload=()=>{s(t[o].m),e.remove()}})),i.set(r,d),s.head.appendChild(e)}return d}}})(n.resourcesUrl,o),t.customElements?a(n):__sc_import_datetime_slot_picker("./p-b4e039be.js").then((()=>n)))})().then((e=>o([["p-54f2e484",[[0,"datetime-slot-picker",{placeholder:[1],timeSlotsText:[1,"time-slots-text"],noSlotsText:[1,"no-slots-text"],slots:[16],language:[1],translations:[16],amPmDisabled:[4,"am-pm-disabled"],datesHiddenWhenTimesShown:[4,"dates-hidden-when-times-shown"],isPopped:[32],isNeoInputAboveFold:[32],isNeoInputLeftSide:[32],neoInputHeight:[32],isTimeSlotGridVisible:[32],activeDateGridPage:[32],dateGrids:[32],selectedDate:[32],activeTimeGridPage:[32],timeGrids:[32],selectedTime:[32],displayText:[32]}]]]],e)));
import{p as e,w as t,d as s,N as i,a,b as o}from"./p-e1d7db57.js";(()=>{e.t=t.__cssshim;const o=Array.from(s.querySelectorAll("script")).find((e=>new RegExp(`/${i}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===i)),n=o["data-opts"]||{};return"onbeforeload"in o&&!history.scrollRestoration?{then(){}}:(n.resourcesUrl=new URL(".",new URL(o.getAttribute("data-resources-url")||o.src,t.location.href)).href,((e,a)=>{const o="__sc_import_"+i.replace(/\s|-/g,"_");try{t[o]=new Function("w","return import(w);//"+Math.random())}catch(n){const i=new Map;t[o]=n=>{const r=new URL(n,e).href;let d=i.get(r);if(!d){const e=s.createElement("script");e.type="module",e.crossOrigin=a.crossOrigin,e.src=URL.createObjectURL(new Blob([`import * as m from '${r}'; window.${o}.m = m;`],{type:"application/javascript"})),d=new Promise((s=>{e.onload=()=>{s(t[o].m),e.remove()}})),i.set(r,d),s.head.appendChild(e)}return d}}})(n.resourcesUrl,o),t.customElements?a(n):__sc_import_datetime_slot_picker("./p-b4e039be.js").then((()=>n)))})().then((e=>o([["p-ce9e38f3",[[0,"datetime-slot-picker",{placeholder:[1],timeSlotsText:[1,"time-slots-text"],noSlotsText:[1,"no-slots-text"],slots:[16],language:[1],translations:[16],amPmDisabled:[4,"am-pm-disabled"],datesHiddenWhenTimesShown:[4,"dates-hidden-when-times-shown"],isPopped:[32],isNeoInputAboveFold:[32],isNeoInputLeftSide:[32],neoInputHeight:[32],isTimeSlotGridVisible:[32],activeDateGridPage:[32],dateGrids:[32],selectedDate:[32],activeTimeGridPage:[32],timeGrids:[32],selectedTime:[32],displayText:[32]}]]]],e)));

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

System.register(["./p-72edf5ff.system.js"],(function(e,t){"use strict";var r,n,s,i,o,a;return{setters:[function(e){r=e.p;n=e.w;s=e.d;i=e.N;o=e.a;a=e.b}],execute:function(){var e=function(e){return"__sc_import_"+e.replace(/\s|-/g,"_")};var c=function(){{r.$cssShim$=n.__cssshim}var e=Array.from(s.querySelectorAll("script")).find((function(e){return new RegExp("/"+i+"(\\.esm)?\\.js($|\\?|#)").test(e.src)||e.getAttribute("data-stencil-namespace")===i}));var a=e["data-opts"]||{};if("onbeforeload"in e&&!history.scrollRestoration){return{then:function(){}}}{a.resourcesUrl=new URL(".",new URL(e.getAttribute("data-resources-url")||e.src,n.location.href)).href;{u(a.resourcesUrl,e)}if(!n.customElements){return t.import("./p-6be85f10.system.js").then((function(){return a}))}}return o(a)};var u=function(t,r){var o=e(i);try{n[o]=new Function("w","return import(w);//"+Math.random())}catch(c){var a=new Map;n[o]=function(e){var i=new URL(e,t).href;var c=a.get(i);if(!c){var u=s.createElement("script");u.type="module";u.crossOrigin=r.crossOrigin;u.src=URL.createObjectURL(new Blob(["import * as m from '"+i+"'; window."+o+".m = m;"],{type:"application/javascript"}));c=new Promise((function(e){u.onload=function(){e(n[o].m);u.remove()}}));a.set(i,c);s.head.appendChild(u)}return c}}};c().then((function(e){return a([["p-7b5c17f5.system",[[0,"datetime-slot-picker",{placeholder:[1],timeSlotsText:[1,"time-slots-text"],noSlotsText:[1,"no-slots-text"],slots:[16],language:[1],translations:[16],amPmDisabled:[4,"am-pm-disabled"],datesHiddenWhenTimesShown:[4,"dates-hidden-when-times-shown"],isPopped:[32],isNeoInputAboveFold:[32],isNeoInputLeftSide:[32],neoInputHeight:[32],isTimeSlotGridVisible:[32],activeDateGridPage:[32],dateGrids:[32],selectedDate:[32],activeTimeGridPage:[32],timeGrids:[32],selectedTime:[32],displayText:[32]}]]]],e)}))}}}));
System.register(["./p-72edf5ff.system.js"],(function(e,t){"use strict";var r,n,s,i,o,a;return{setters:[function(e){r=e.p;n=e.w;s=e.d;i=e.N;o=e.a;a=e.b}],execute:function(){var e=function(e){return"__sc_import_"+e.replace(/\s|-/g,"_")};var c=function(){{r.$cssShim$=n.__cssshim}var e=Array.from(s.querySelectorAll("script")).find((function(e){return new RegExp("/"+i+"(\\.esm)?\\.js($|\\?|#)").test(e.src)||e.getAttribute("data-stencil-namespace")===i}));var a=e["data-opts"]||{};if("onbeforeload"in e&&!history.scrollRestoration){return{then:function(){}}}{a.resourcesUrl=new URL(".",new URL(e.getAttribute("data-resources-url")||e.src,n.location.href)).href;{u(a.resourcesUrl,e)}if(!n.customElements){return t.import("./p-6be85f10.system.js").then((function(){return a}))}}return o(a)};var u=function(t,r){var o=e(i);try{n[o]=new Function("w","return import(w);//"+Math.random())}catch(c){var a=new Map;n[o]=function(e){var i=new URL(e,t).href;var c=a.get(i);if(!c){var u=s.createElement("script");u.type="module";u.crossOrigin=r.crossOrigin;u.src=URL.createObjectURL(new Blob(["import * as m from '"+i+"'; window."+o+".m = m;"],{type:"application/javascript"}));c=new Promise((function(e){u.onload=function(){e(n[o].m);u.remove()}}));a.set(i,c);s.head.appendChild(u)}return c}}};c().then((function(e){return a([["p-7eaea2e2.system",[[0,"datetime-slot-picker",{placeholder:[1],timeSlotsText:[1,"time-slots-text"],noSlotsText:[1,"no-slots-text"],slots:[16],language:[1],translations:[16],amPmDisabled:[4,"am-pm-disabled"],datesHiddenWhenTimesShown:[4,"dates-hidden-when-times-shown"],isPopped:[32],isNeoInputAboveFold:[32],isNeoInputLeftSide:[32],neoInputHeight:[32],isTimeSlotGridVisible:[32],activeDateGridPage:[32],dateGrids:[32],selectedDate:[32],activeTimeGridPage:[32],timeGrids:[32],selectedTime:[32],displayText:[32]}]]]],e)}))}}}));

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

import{r as registerInstance,c as createEvent,h}from"./index-dc459d91.js";var builtInTranslations={en:{Mon:"Mon",Tue:"Tue",Wed:"Wed",Thu:"Thu",Fri:"Fri",Sat:"Sat",Sun:"Sun",AM:"AM",PM:"PM",Jan:"Jan",Feb:"Feb",Mar:"Mar",Apr:"Apr",May:"May",Jun:"Jun",Jul:"Jul",Aug:"Aug",Sep:"Sep",Oct:"Oct",Nov:"Nov",Dec:"Dec"}};var monthIndex={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var days=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function generateDateGrid(e){var t=[];var i=true;var n,s;for(var a=0,l=e;a<l.length;a++){var o=l[a];if(o.date&&o.date.substring(5)&&o.date.substring(5).split(" ").length===3&&monthIndex[o.date.substring(5).split(" ")[1]]>-1&&parseInt(o.date.substring(5).split(" ")[2])&&parseInt(o.date.substring(5).split(" ")[0])){var r=new Date(parseInt(o.date.substring(5).split(" ")[2]),monthIndex[o.date.substring(5).split(" ")[1]],parseInt(o.date.substring(5).split(" ")[0]));if(!n||n>r)n=r;if(!s||s<r)s=r}else{i=false;break}}if(i&&n&&s){var d={m1:n.getMonth(),y1:n.getFullYear()},h=d.m1,c=d.y1;var p={m2:s.getMonth(),y2:s.getFullYear()},u=p.m2,g=p.y2;do{var f={monthYear:months[h]+" "+c,weeks:[]};var m=[];var T=new Date(c,h,1);var v=new Date(c,h+1,0);for(var S=1;S<=T.getDay();S++){m.push(null)}var b=function(t){var i=new Date(c,h,t);var n=days[i.getDay()]+", "+t+" "+months[h]+" "+c;var s=e.find((function(e){return e.date===n}));m.push({dayOfMonth:t,isEnabled:s?true:false,dateText:n})};for(var w=1;w<=v.getDate();w++){b(w)}for(var x=m.length+1;x<=42;x++){m.push(null)}for(var G=1;G<=6;G++){var y={days:[]};for(var D=1;D<=7;D++){y.days.push(m.shift())}f.weeks.push(y)}t.push(f);if(h===11){h=0;c++}else{h++}}while(c<g||c===g&&h<=u)}return t}function generateTimeGrid(e,t){var i=[];var n=e.timeSlots.filter((function(e){var t=true;if(!e)t=false;return t}));if(n.length){var s=n[0].length<=8?4:2;var a=s*t;var l=Math.ceil(n.length/a);for(var o=1;o<=l;o++){var r={dateText:e.date.substring(5),rows:[]};for(var d=1;d<=t;d++){var h={times:[]};for(var c=1;c<=s;c++){var p=n.shift();h.times.push(p?{timeText:p}:null)}r.rows.push(h)}i.push(r)}}return i}var datetimeSlotPickerCss=":host{display:block}.neo-slot-picker{position:relative}.neo-popup{position:absolute;z-index:999;background-color:white;padding:2px;margin:3px 0px;-webkit-box-shadow:0 0 10px lightgray;box-shadow:0 0 10px lightgray;border:1px solid whitesmoke}.neo-input{min-width:275px;cursor:pointer}.neo-paginate,.neo-close,.neo-back{padding:2px 10px;cursor:pointer}.neo-paginate-hidden{padding:2px 10px}table{table-layout:fixed;width:100%}tr.neo-equal-width>*:nth-last-child(2)~*{width:50%}tr.neo-equal-width>*:nth-last-child(3)~*{width:33.3%}tr.neo-equal-width>*:nth-last-child(4)~*{width:25%}tr.neo-equal-width>*:nth-last-child(5)~*{width:20%}tr.neo-equal-width>*:nth-last-child(6)~*{width:16.7%}tr.neo-equal-width>*:nth-last-child(7)~*{width:14.3%}table,th,td{border:1px solid whitesmoke;border-collapse:collapse}th,td{padding:3px}td{text-align:center}.neo-right-end{text-align:right;width:15%}.neo-left-end{text-align:left;width:15%}.neo-grid{font-size:small;min-width:275px}.neo-day,.neo-time{padding:2px}.neo-cell-enabled{color:black}@media only screen and (min-width: 768px){.neo-cell-enabled:hover{color:white;background-color:black}}.neo-cell-selected{color:white;background-color:black}.neo-day-enabled,.neo-day-selected,.neo-time-enabled,.neo-time-selected{cursor:pointer}.neo-day-disabled{color:lightgray;cursor:not-allowed}.neo-center{border-right:0px;border-left:0px}.neo-left-end{border-right:0px}.neo-right-end{border-left:0px}.neo-empty-grid th,.neo-empty-grid td{border:1px solid white}.neo-no-slots-text{color:gray}";var DatetimeSlotPicker=function(){function e(e){registerInstance(this,e);this.slotUpdate=createEvent(this,"slotUpdate",7);this.placeholder="Pick a time slot";this.timeSlotsText="Time";this.noSlotsText="No slots are available";this.slots=[];this.language="en";this.translations=builtInTranslations;this.amPmDisabled=false;this.datesHiddenWhenTimesShown=false}e.prototype.componentWillLoad=function(){this.processSlots(this.slots)};e.prototype.processSlots=function(e){if(this.slots){this.isTimeSlotGridVisible=false;this.selectedDate=undefined;this.selectedTime=undefined;this.displayText=undefined;this.dateGrids=generateDateGrid(e);if(this.dateGrids&&this.dateGrids.length)this.activeDateGridPage=0}};e.prototype.togglePopup=function(){if(this.slots){if(this.neoInput.getBoundingClientRect().top<window.innerHeight/2)this.isNeoInputAboveFold=true;else this.isNeoInputAboveFold=false;if(this.neoInput.getBoundingClientRect().left<window.innerWidth/2)this.isNeoInputLeftSide=true;else this.isNeoInputLeftSide=false;this.neoInputHeight=this.neoInput.getBoundingClientRect().bottom-this.neoInput.getBoundingClientRect().top;this.isPopped=!this.isPopped;this.isTimeSlotGridVisible=false}};e.prototype.setSelectedDate=function(e){var t=this;if(e){this.selectedDate=e;if(this.slots.length&&this.slots[0].timeSlots){this.resetSlot();var i=this.slots.find((function(e){return e.date===t.selectedDate}));this.timeGrids=generateTimeGrid(i,this.datesHiddenWhenTimesShown?7:4);this.selectedTime=undefined;if(this.timeGrids&&this.timeGrids.length)this.activeTimeGridPage=0;this.isTimeSlotGridVisible=true}else this.setSlot()}};e.prototype.setSelectedTime=function(e){if(e){this.selectedTime=e;this.setSlot()}};e.prototype.setSlot=function(){var e,t;var i=this.selectedDate.split(" ");console.log(i);e=this.getTranslation(i[0].substring(0,i[0].length-1))+", "+i[1]+" "+this.getTranslation(i[2])+" "+i[3];if(this.selectedTime){t=this.formatTimeSlot(this.selectedTime);t=t.replace(/AM/g,this.getTranslation("AM"));t=t.replace(/PM/g,this.getTranslation("PM"))}this.displayText=e+(this.selectedTime?", "+t:"");this.slotUpdate.emit({date:this.selectedDate,timeSlot:this.selectedTime,translatedDate:e,translatedTimeSlot:t});this.isPopped=false;this.isTimeSlotGridVisible=false};e.prototype.resetSlot=function(){this.displayText=undefined;this.slotUpdate.emit({date:null,timeSlot:null,translatedDate:null,translatedTimeSlot:null})};e.prototype.closeGrid=function(){this.isPopped=false;this.isTimeSlotGridVisible=false};e.prototype.goBack=function(){this.isTimeSlotGridVisible=false};e.prototype.prevDateGrid=function(){if(this.activeDateGridPage>0)this.activeDateGridPage--};e.prototype.nextDateGrid=function(){if(this.activeDateGridPage<this.dateGrids.length-1)this.activeDateGridPage++};e.prototype.prevTimeGrid=function(){if(this.activeTimeGridPage>0)this.activeTimeGridPage--};e.prototype.nextTimeGrid=function(){if(this.activeTimeGridPage<this.timeGrids.length-1)this.activeTimeGridPage++};e.prototype.getTranslation=function(e){if(this.translations[this.language])return this.translations[this.language][e];else return builtInTranslations["en"][e]};e.prototype.formatTimeSlot=function(e){var t=function(e){var t=e.replace(/ AM/g,"");t=t.replace(/ PM/g,"");if(e.indexOf("AM")>-1){var i=t.split(":")[0].trim();if(i.length===1)i="0"+i;if(i.indexOf("12")===0)i="00";return i+":"+(t.split(":")[1]?t.split(":")[1].trim():"00")}else if(e.indexOf("PM")>-1){var i=t.split(":")[0].trim();if(i.indexOf("12")!==0)i=(parseInt(i)+12).toString();return i+":"+(t.split(":")[1]?t.split(":")[1].trim():"00")}};var i=e;if(this.amPmDisabled){if(e.indexOf("-")>-1){var n=void 0;n=e.split("-");n=n.map((function(e){return t(e)}));i=n[0]+" - "+n[1]}else{i=t(e)}}return i};e.prototype.render=function(){var e=this;var t={bottom:!this.isNeoInputAboveFold?this.neoInputHeight+"px":undefined,left:this.isNeoInputLeftSide?"0px":undefined,right:!this.isNeoInputLeftSide?"0px":undefined};var i;if(this.dateGrids&&this.dateGrids.length>0)i=this.dateGrids[this.activeDateGridPage].monthYear.split(" ");return h("span",{class:"neo-slot-picker"},h("input",{class:"neo-input",type:"text",readonly:true,placeholder:this.placeholder,value:this.displayText,onClick:function(){return e.togglePopup()},ref:function(t){return e.neoInput=t}}),this.isPopped&&h("div",{style:t,class:this.isNeoInputAboveFold?"neo-popup neo-popup-below":"neo-popup neo-popup-above"},(!this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown)&&this.dateGrids&&this.dateGrids.length>0&&h("table",{class:"neo-grid neo-date-grid"},h("tr",null,h("th",{class:"neo-left-end"}),h("th",{colSpan:5,class:"neo-center"},this.activeDateGridPage>0?h("span",{class:"neo-paginate",onClick:function(){return e.prevDateGrid()}},"<"):h("span",{class:"neo-paginate-hidden"}," "),this.getTranslation(i[0])+" "+i[1],this.activeDateGridPage<this.dateGrids.length-1?h("span",{class:"neo-paginate",onClick:function(){return e.nextDateGrid()}},">"):h("span",{class:"neo-paginate-hidden"}," ")),h("th",{class:"neo-right-end"},h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"))),h("tr",{class:"neo-equal-width"},h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Sun"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Mon"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Tue"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Wed"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Thu"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Fri"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Sat")))),this.dateGrids[this.activeDateGridPage].weeks.map((function(t){return h("tr",{class:"neo-equal-width"},t.days.map((function(t){return t?h("td",{class:!t.isEnabled?"neo-cell neo-cell-disabled":t.dateText==e.selectedDate?"neo-cell neo-cell-selected":"neo-cell neo-cell-enabled",onClick:function(){return e.setSelectedDate(t.isEnabled?t.dateText:undefined)}},h("span",{class:!t.isEnabled?"neo-day neo-day-disabled":t.dateText==e.selectedDate?"neo-day neo-day-selected":"neo-day neo-day-enabled"},t.dayOfMonth)):h("td",null," ")})))}))),(!this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown)&&this.dateGrids&&!this.dateGrids.length&&h("table",{class:"neo-grid neo-empty-grid"},h("tr",null,h("th",{class:"neo-left-end"}),h("th",{colSpan:5,class:"neo-center"}," "),h("th",{class:"neo-right-end"},h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"))),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7,class:"neo-no-slots-text"},this.noSlotsText)),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," "))),(this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown&&this.selectedDate)&&this.timeGrids&&this.timeGrids.length>0&&h("table",{class:"neo-grid neo-time-grid"},h("tr",null,h("th",{class:"neo-left-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-back",onClick:function(){return e.goBack()}},"←"):h("span",null," ")),h("th",{class:"neo-center",colSpan:6},this.activeTimeGridPage>0?h("span",{class:"neo-paginate",onClick:function(){return e.prevTimeGrid()}},"<"):h("span",{class:"neo-paginate-hidden"}," "),this.timeSlotsText,this.activeTimeGridPage<this.timeGrids.length-1?h("span",{class:"neo-paginate",onClick:function(){return e.nextTimeGrid()}},">"):h("span",{class:"neo-paginate-hidden"}," ")),h("th",{class:"neo-right-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"):h("span",null," "))),this.timeGrids[this.activeTimeGridPage].rows.map((function(t){return h("tr",{class:"neo-equal-width"},t.times.map((function(i){var n;if(i){n=e.formatTimeSlot(i.timeText);n=n.replace(/AM/g,e.getTranslation("AM"));n=n.replace(/PM/g,e.getTranslation("PM"))}return i?h("td",{colSpan:t.times.length===2?4:2,class:i.timeText==e.selectedTime?"neo-cell neo-cell-selected":"neo-cell neo-cell-enabled",onClick:function(){return e.setSelectedTime(i.timeText)}},h("span",{class:i.timeText==e.selectedTime?"neo-time neo-time-selected":"neo-time neo-time-enabled"},n)):h("td",{colSpan:t.times.length===2?4:2}," ")})))}))),(this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown&&this.selectedDate)&&this.timeGrids&&!this.timeGrids.length&&h("table",{class:"neo-grid neo-empty-grid"},h("tr",null,h("th",{class:"neo-left-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-back",onClick:function(){return e.goBack()}},"←"):h("span",null," ")),h("th",{colSpan:5,class:"neo-center"}," "),h("th",{class:"neo-right-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"):h("span",null," "))),this.datesHiddenWhenTimesShown&&h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7,class:"neo-no-slots-text"},this.noSlotsText)),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),this.datesHiddenWhenTimesShown&&h("tr",null,h("td",{colSpan:7}," ")),this.datesHiddenWhenTimesShown&&h("tr",null,h("td",{colSpan:7}," ")))))};Object.defineProperty(e,"watchers",{get:function(){return{slots:["processSlots"]}},enumerable:false,configurable:true});return e}();DatetimeSlotPicker.style=datetimeSlotPickerCss;export{DatetimeSlotPicker as datetime_slot_picker};
import{r as registerInstance,c as createEvent,h}from"./index-dc459d91.js";var builtInTranslations={en:{Mon:"Mon",Tue:"Tue",Wed:"Wed",Thu:"Thu",Fri:"Fri",Sat:"Sat",Sun:"Sun",AM:"AM",PM:"PM",Jan:"Jan",Feb:"Feb",Mar:"Mar",Apr:"Apr",May:"May",Jun:"Jun",Jul:"Jul",Aug:"Aug",Sep:"Sep",Oct:"Oct",Nov:"Nov",Dec:"Dec"}};var monthIndex={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var days=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function generateDateGrid(e){var t=[];var i=true;var n,s;for(var a=0,l=e;a<l.length;a++){var o=l[a];if(o.date&&o.date.substring(5)&&o.date.substring(5).split(" ").length===3&&monthIndex[o.date.substring(5).split(" ")[1]]>-1&&parseInt(o.date.substring(5).split(" ")[2])&&parseInt(o.date.substring(5).split(" ")[0])){var r=new Date(parseInt(o.date.substring(5).split(" ")[2]),monthIndex[o.date.substring(5).split(" ")[1]],parseInt(o.date.substring(5).split(" ")[0]));if(!n||n>r)n=r;if(!s||s<r)s=r}else{i=false;break}}if(i&&n&&s){var d={m1:n.getMonth(),y1:n.getFullYear()},h=d.m1,c=d.y1;var p={m2:s.getMonth(),y2:s.getFullYear()},u=p.m2,g=p.y2;do{var f={monthYear:months[h]+" "+c,weeks:[]};var m=[];var T=new Date(c,h,1);var v=new Date(c,h+1,0);for(var S=1;S<=T.getDay();S++){m.push(null)}var b=function(t){var i=new Date(c,h,t);var n=days[i.getDay()]+", "+t+" "+months[h]+" "+c;var s=e.find((function(e){return e.date===n}));m.push({dayOfMonth:t,isEnabled:s?true:false,dateText:n})};for(var x=1;x<=v.getDate();x++){b(x)}for(var w=m.length+1;w<=42;w++){m.push(null)}for(var G=1;G<=6;G++){var y={days:[]};for(var D=1;D<=7;D++){y.days.push(m.shift())}f.weeks.push(y)}t.push(f);if(h===11){h=0;c++}else{h++}}while(c<g||c===g&&h<=u)}return t}function generateTimeGrid(e,t){var i=[];var n=e.timeSlots.filter((function(e){var t=true;if(!e)t=false;return t}));if(n.length){var s=n[0].length<=8?4:2;var a=s*t;var l=Math.ceil(n.length/a);for(var o=1;o<=l;o++){var r={dateText:e.date.substring(5),rows:[]};for(var d=1;d<=t;d++){var h={times:[]};for(var c=1;c<=s;c++){var p=n.shift();h.times.push(p?{timeText:p}:null)}r.rows.push(h)}i.push(r)}}return i}var datetimeSlotPickerCss=":host{display:block}.neo-slot-picker{position:relative}.neo-popup{position:absolute;z-index:999;background-color:white;padding:2px;margin:3px 0px;-webkit-box-shadow:0 0 10px lightgray;box-shadow:0 0 10px lightgray;border:1px solid whitesmoke}.neo-input{min-width:275px;cursor:pointer}.neo-paginate,.neo-close,.neo-back{padding:2px 10px;cursor:pointer}.neo-paginate-hidden{padding:2px 10px}table{table-layout:fixed;width:100%}tr.neo-equal-width>*:nth-last-child(2)~*{width:50%}tr.neo-equal-width>*:nth-last-child(3)~*{width:33.3%}tr.neo-equal-width>*:nth-last-child(4)~*{width:25%}tr.neo-equal-width>*:nth-last-child(5)~*{width:20%}tr.neo-equal-width>*:nth-last-child(6)~*{width:16.7%}tr.neo-equal-width>*:nth-last-child(7)~*{width:14.3%}table,th,td{border:1px solid whitesmoke;border-collapse:collapse}th,td{padding:3px}td{text-align:center}.neo-right-end{text-align:right;width:15%}.neo-left-end{text-align:left;width:15%}.neo-grid{font-size:small;min-width:275px}.neo-day,.neo-time{padding:2px}.neo-cell-enabled{color:black}@media only screen and (min-width: 768px){.neo-cell-enabled:hover{color:white;background-color:black}}.neo-cell-selected{color:white;background-color:black}.neo-day-enabled,.neo-day-selected,.neo-time-enabled,.neo-time-selected{cursor:pointer}.neo-day-disabled{color:lightgray;cursor:not-allowed}.neo-center{border-right:0px;border-left:0px}.neo-left-end{border-right:0px}.neo-right-end{border-left:0px}.neo-empty-grid th,.neo-empty-grid td{border:1px solid white}.neo-no-slots-text{color:gray}";var DatetimeSlotPicker=function(){function e(e){registerInstance(this,e);this.slotUpdate=createEvent(this,"slotUpdate",7);this.placeholder="Pick a time slot";this.timeSlotsText="Time";this.noSlotsText="No slots are available";this.slots=[];this.language="en";this.translations=builtInTranslations;this.amPmDisabled=false;this.datesHiddenWhenTimesShown=false}e.prototype.componentWillLoad=function(){this.processSlots(this.slots)};e.prototype.processSlots=function(e){if(this.slots){this.isTimeSlotGridVisible=false;this.selectedDate=undefined;this.selectedTime=undefined;this.displayText=undefined;this.dateGrids=generateDateGrid(e);if(this.dateGrids&&this.dateGrids.length)this.activeDateGridPage=0}};e.prototype.togglePopup=function(){if(this.slots){if(this.neoInput.getBoundingClientRect().top<window.innerHeight/2)this.isNeoInputAboveFold=true;else this.isNeoInputAboveFold=false;if(this.neoInput.getBoundingClientRect().left<window.innerWidth/2)this.isNeoInputLeftSide=true;else this.isNeoInputLeftSide=false;this.neoInputHeight=this.neoInput.getBoundingClientRect().bottom-this.neoInput.getBoundingClientRect().top;this.isPopped=!this.isPopped;this.isTimeSlotGridVisible=false}};e.prototype.setSelectedDate=function(e){var t=this;if(e){this.selectedDate=e;if(this.slots.length&&this.slots[0].timeSlots){this.resetSlot();var i=this.slots.find((function(e){return e.date===t.selectedDate}));this.timeGrids=generateTimeGrid(i,this.datesHiddenWhenTimesShown?7:4);this.selectedTime=undefined;if(this.timeGrids&&this.timeGrids.length)this.activeTimeGridPage=0;this.isTimeSlotGridVisible=true}else this.setSlot()}};e.prototype.setSelectedTime=function(e){if(e){this.selectedTime=e;this.setSlot()}};e.prototype.setSlot=function(){var e,t;var i=this.selectedDate.split(" ");console.log(i);e=this.getTranslation(i[0].substring(0,i[0].length-1))+", "+i[1]+" "+this.getTranslation(i[2])+" "+i[3];if(this.selectedTime){t=this.formatTimeSlot(this.selectedTime);t=t.replace(/AM/g,this.getTranslation("AM"));t=t.replace(/PM/g,this.getTranslation("PM"))}this.displayText=e+(this.selectedTime?", "+t:"");this.slotUpdate.emit({date:this.selectedDate,timeSlot:this.selectedTime,translatedDate:e,translatedTimeSlot:t});this.isPopped=false;this.isTimeSlotGridVisible=false};e.prototype.resetSlot=function(){this.displayText=undefined;this.slotUpdate.emit({date:null,timeSlot:null,translatedDate:null,translatedTimeSlot:null})};e.prototype.closeGrid=function(){this.isPopped=false;this.isTimeSlotGridVisible=false;if(!this.displayText){this.selectedDate=undefined;this.selectedTime=undefined}};e.prototype.goBack=function(){this.isTimeSlotGridVisible=false};e.prototype.prevDateGrid=function(){if(this.activeDateGridPage>0)this.activeDateGridPage--};e.prototype.nextDateGrid=function(){if(this.activeDateGridPage<this.dateGrids.length-1)this.activeDateGridPage++};e.prototype.prevTimeGrid=function(){if(this.activeTimeGridPage>0)this.activeTimeGridPage--};e.prototype.nextTimeGrid=function(){if(this.activeTimeGridPage<this.timeGrids.length-1)this.activeTimeGridPage++};e.prototype.getTranslation=function(e){if(this.translations[this.language])return this.translations[this.language][e];else return builtInTranslations["en"][e]};e.prototype.formatTimeSlot=function(e){var t=function(e){var t=e.replace(/ AM/g,"");t=t.replace(/ PM/g,"");if(e.indexOf("AM")>-1){var i=t.split(":")[0].trim();if(i.length===1)i="0"+i;if(i.indexOf("12")===0)i="00";return i+":"+(t.split(":")[1]?t.split(":")[1].trim():"00")}else if(e.indexOf("PM")>-1){var i=t.split(":")[0].trim();if(i.indexOf("12")!==0)i=(parseInt(i)+12).toString();return i+":"+(t.split(":")[1]?t.split(":")[1].trim():"00")}};var i=e;if(this.amPmDisabled){if(e.indexOf("-")>-1){var n=void 0;n=e.split("-");n=n.map((function(e){return t(e)}));i=n[0]+" - "+n[1]}else{i=t(e)}}return i};e.prototype.render=function(){var e=this;var t={bottom:!this.isNeoInputAboveFold?this.neoInputHeight+"px":undefined,left:this.isNeoInputLeftSide?"0px":undefined,right:!this.isNeoInputLeftSide?"0px":undefined};var i;if(this.dateGrids&&this.dateGrids.length>0)i=this.dateGrids[this.activeDateGridPage].monthYear.split(" ");return h("span",{class:"neo-slot-picker"},h("input",{class:"neo-input",type:"text",readonly:true,placeholder:this.placeholder,value:this.displayText,onClick:function(){return e.togglePopup()},ref:function(t){return e.neoInput=t}}),this.isPopped&&h("div",{style:t,class:this.isNeoInputAboveFold?"neo-popup neo-popup-below":"neo-popup neo-popup-above"},(!this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown)&&this.dateGrids&&this.dateGrids.length>0&&h("table",{class:"neo-grid neo-date-grid"},h("tr",null,h("th",{class:"neo-left-end"}),h("th",{colSpan:5,class:"neo-center"},this.activeDateGridPage>0?h("span",{class:"neo-paginate",onClick:function(){return e.prevDateGrid()}},"<"):h("span",{class:"neo-paginate-hidden"}," "),this.getTranslation(i[0])+" "+i[1],this.activeDateGridPage<this.dateGrids.length-1?h("span",{class:"neo-paginate",onClick:function(){return e.nextDateGrid()}},">"):h("span",{class:"neo-paginate-hidden"}," ")),h("th",{class:"neo-right-end"},h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"))),h("tr",{class:"neo-equal-width"},h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Sun"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Mon"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Tue"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Wed"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Thu"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Fri"))),h("td",null,h("span",{class:"neo-dow"},this.getTranslation("Sat")))),this.dateGrids[this.activeDateGridPage].weeks.map((function(t){return h("tr",{class:"neo-equal-width"},t.days.map((function(t){return t?h("td",{class:!t.isEnabled?"neo-cell neo-cell-disabled":t.dateText==e.selectedDate?"neo-cell neo-cell-selected":"neo-cell neo-cell-enabled",onClick:function(){return e.setSelectedDate(t.isEnabled?t.dateText:undefined)}},h("span",{class:!t.isEnabled?"neo-day neo-day-disabled":t.dateText==e.selectedDate?"neo-day neo-day-selected":"neo-day neo-day-enabled"},t.dayOfMonth)):h("td",null," ")})))}))),(!this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown)&&this.dateGrids&&!this.dateGrids.length&&h("table",{class:"neo-grid neo-empty-grid"},h("tr",null,h("th",{class:"neo-left-end"}),h("th",{colSpan:5,class:"neo-center"}," "),h("th",{class:"neo-right-end"},h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"))),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7,class:"neo-no-slots-text"},this.noSlotsText)),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," "))),(this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown&&this.selectedDate)&&this.timeGrids&&this.timeGrids.length>0&&h("table",{class:"neo-grid neo-time-grid"},h("tr",null,h("th",{class:"neo-left-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-back",onClick:function(){return e.goBack()}},"←"):h("span",null," ")),h("th",{class:"neo-center",colSpan:6},this.activeTimeGridPage>0?h("span",{class:"neo-paginate",onClick:function(){return e.prevTimeGrid()}},"<"):h("span",{class:"neo-paginate-hidden"}," "),this.timeSlotsText,this.activeTimeGridPage<this.timeGrids.length-1?h("span",{class:"neo-paginate",onClick:function(){return e.nextTimeGrid()}},">"):h("span",{class:"neo-paginate-hidden"}," ")),h("th",{class:"neo-right-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"):h("span",null," "))),this.timeGrids[this.activeTimeGridPage].rows.map((function(t){return h("tr",{class:"neo-equal-width"},t.times.map((function(i){var n;if(i){n=e.formatTimeSlot(i.timeText);n=n.replace(/AM/g,e.getTranslation("AM"));n=n.replace(/PM/g,e.getTranslation("PM"))}return i?h("td",{colSpan:t.times.length===2?4:2,class:i.timeText==e.selectedTime?"neo-cell neo-cell-selected":"neo-cell neo-cell-enabled",onClick:function(){return e.setSelectedTime(i.timeText)}},h("span",{class:i.timeText==e.selectedTime?"neo-time neo-time-selected":"neo-time neo-time-enabled"},n)):h("td",{colSpan:t.times.length===2?4:2}," ")})))}))),(this.isTimeSlotGridVisible||!this.datesHiddenWhenTimesShown&&this.selectedDate)&&this.timeGrids&&!this.timeGrids.length&&h("table",{class:"neo-grid neo-empty-grid"},h("tr",null,h("th",{class:"neo-left-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-back",onClick:function(){return e.goBack()}},"←"):h("span",null," ")),h("th",{colSpan:5,class:"neo-center"}," "),h("th",{class:"neo-right-end"},this.datesHiddenWhenTimesShown?h("span",{class:"neo-close",onClick:function(){return e.closeGrid()}},"×"):h("span",null," "))),this.datesHiddenWhenTimesShown&&h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7,class:"neo-no-slots-text"},this.noSlotsText)),h("tr",null,h("td",{colSpan:7}," ")),h("tr",null,h("td",{colSpan:7}," ")),this.datesHiddenWhenTimesShown&&h("tr",null,h("td",{colSpan:7}," ")),this.datesHiddenWhenTimesShown&&h("tr",null,h("td",{colSpan:7}," ")))))};Object.defineProperty(e,"watchers",{get:function(){return{slots:["processSlots"]}},enumerable:false,configurable:true});return e}();DatetimeSlotPicker.style=datetimeSlotPickerCss;export{DatetimeSlotPicker as datetime_slot_picker};

@@ -237,2 +237,6 @@ import { r as registerInstance, c as createEvent, h } from './index-dc459d91.js';

this.isTimeSlotGridVisible = false;
if (!this.displayText) {
this.selectedDate = undefined;
this.selectedTime = undefined;
}
}

@@ -239,0 +243,0 @@ goBack() {

{
"name": "datetime-slot-picker",
"version": "0.1.5",
"version": "0.1.6",
"description": "A webcomponent for date and time slot picker",

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc