@tabworthy/components 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/tabworthy-dates.cjs.entry.js +10 -0
- package/dist/cjs/tabworthy-times.cjs.entry.js +45 -7
- package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +10 -0
- package/dist/collection/components/tabworthy-times/tabworthy-times.js +45 -7
- package/dist/components/tabworthy-dates.js +1 -1
- package/dist/components/tabworthy-times.js +1 -1
- package/dist/esm/tabworthy-dates.entry.js +10 -0
- package/dist/esm/tabworthy-times.entry.js +45 -7
- package/dist/tabworthy-components/{p-71f5c261.entry.js → p-4eedf24e.entry.js} +1 -1
- package/dist/tabworthy-components/p-b6a5d970.entry.js +1 -0
- package/dist/tabworthy-components/tabworthy-components.esm.js +1 -1
- package/dist/themes/light.css +1 -1
- package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +5 -0
- package/package.json +1 -1
- package/dist/tabworthy-components/p-ed3c60d6.entry.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as t,H as s,c as e,h as i,d as h,t as a}from"./p-BiJ0HZVY.js";import{g as n,d as o,c as r}from"./p-DkyM-7xr.js";import{g as d,r as l,c}from"./p-BzY8iIVW.js";import{d as u}from"./p-CMIEIvTW.js";import{d as m}from"./p-C_uZGgcG.js";var f,b={exports:{}},p=n(f?b.exports:(f=1,b.exports=function(){var t={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(s,e,i){var h=e.prototype,a=h.format;i.en.formats=t,h.format=function(s){void 0===s&&(s="YYYY-MM-DDTHH:mm:ssZ");var e=this.$locale().formats,i=function(s,e){return s.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(s,i,h){var a=h&&h.toUpperCase();return i||e[h]||t[h]||e[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,s,e){return s||e.slice(1)}))}))}(s,void 0===e?{}:e);return a.call(this,i)}}}()));o.extend(r),o.extend(p);const y={selected:"selected",openCalendar:"Choose time",calendar:"date and time picker",invalidDateError:"We could not find a matching date",minDateError:"Please fill in a date after ",maxDateError:"Please fill in a date before ",rangeOutOfBoundsError:"Please enter a valid range of dates",disabledDateError:"Please choose an available date",to:"to",startDate:"Start date",timeLabel:"Time"},v=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.selectDateTime=e(this,"selectDateTime",7),this.changeYear=e(this,"changeYear",7),this.errorChange=e(this,"errorChange",7),this.componentReady=e(this,"componentReady",7),this.range=!1,this.label="Choose a date and time",this.placeholder="",this.locale=(null===navigator||void 0===navigator?void 0:navigator.language)||"en-US",this.disabled=!1,this.startDate=d(new Date),this.referenceDate=d(new Date),this.useTwelveHourFormat=!0,this.showSeconds=!1,this.timesLabels=y,this.inline=!1,this.hasError=!1,this.showYearStepper=!1,this.showMonthStepper=!0,this.showClearButton=!0,this.showCloseButton=!1,this.showTodayButton=!0,this.disableDate=()=>!1,this.elementClassName="tabworthy-times",this.firstDayOfWeek=1,this.format="YYYY-MM-DDTHH:mm:ss",this.inputShouldFormat=!0,this.disableFreeformInput=!1,this.inputClass="",this.selectedHours=(new Date).getHours(),this.selectedMinutes=(new Date).getMinutes(),this.selectedSeconds=(new Date).getSeconds(),this.errorState=this.hasError,this.disabledState=this.disabled,this.errorMessage="",this.handlePickerSelection=async t=>{if(!t)return this.clearValue();const s=t.split(",");if(this.range&&2===s.length){const t=l(new Date(s[0])),e=l(new Date(s[1]));if(!this.isDateValid(t)||!this.isDateValid(e))return;this.updateValue([t,e]),this.pickerRef&&(this.pickerRef.value=[t,e])}else{const t=l(new Date(s[0]));if(!this.isDateValid(t))return;this.updateValue(t),this.pickerRef&&(this.pickerRef.value=t)}},this.handleTimeChange=t=>{this.selectedHours=t.detail.hours,this.selectedMinutes=t.detail.minutes,void 0!==t.detail.seconds&&(this.selectedSeconds=t.detail.seconds),this.selectedDate&&this.updateValue(this.selectedDate)},this.handleCalendarButtonClick=async()=>{this.modalRef&&(await this.modalRef.setTriggerElement(this.inputContainerRef),await this.modalRef.open())},this.handleYearChange=t=>{this.changeYear&&this.changeYear.emit(t)},this.handleChangedMonths=()=>{},this.handleInputBlur=()=>{this.shouldInputFormat()&&this.formatInput()},this.handleInputChange=t=>{const s=t.target.value;if(0===s.length)return this.errorState=!1,this.internalValue="",this.pickerRef&&(this.pickerRef.value=null),this.value=this.internalValue,this.selectDateTime.emit(this.internalValue);let e=o(s,this.format,!0);if(e.isValid()||(e=o(s)),e.isValid()){if(this.minDate&&e.isBefore(o(this.minDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,void this.emitErrorChange("minDate",this.errorMessage);if(this.maxDate&&e.isAfter(o(this.maxDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`,void this.emitErrorChange("maxDate",this.errorMessage);if(this.disableDate(e.toDate()))return this.errorState=!0,this.errorMessage=this.timesLabels.disabledDateError,void this.emitErrorChange("disabledDate",this.errorMessage);this.errorState=!1,this.selectedHours=e.hour(),this.selectedMinutes=e.minute(),this.selectedSeconds=e.second(),this.updateValue(e.toDate())}else this.errorState=!0,this.errorMessage=this.timesLabels.invalidDateError,this.emitErrorChange("invalid",this.errorMessage)}}emitErrorChange(t,s){this.errorChange.emit({reason:t,message:s})}formatBoundaryDate(t){const s=o(t);if(!s.isValid())return t;if(!t.includes("T")&&!t.includes(" "))return Intl.DateTimeFormat(this.locale,{day:"numeric",month:"short",year:"numeric"}).format(s.toDate());const e=Object.assign({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"numeric"},this.showSeconds?{second:"numeric"}:{});return Intl.DateTimeFormat(this.locale,e).format(s.toDate())}getEffectiveMinTime(){if(!this.minDate||!this.selectedDate)return;const t=o(this.minDate),s=o(this.selectedDate);return t.isValid()&&s.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}getEffectiveMaxTime(){if(!this.maxDate||!this.selectedDate)return;const t=o(this.maxDate),s=o(this.selectedDate);return t.isValid()&&s.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}isDateOutOfBounds(){if(!this.selectedDate)return!1;const t=o(this.selectedDate);return!(!this.minDate||!t.isBefore(o(this.minDate),"day"))||!(!this.maxDate||!t.isAfter(o(this.maxDate),"day"))}shouldInputFormat(){return"string"==typeof this.inputShouldFormat?"true"===this.inputShouldFormat:!!this.inputShouldFormat}watchValue(t){this.syncFromValueProp()}watchDisabled(t){this.disabledState=t}watchHasError(t){this.errorState=t}componentDidLoad(){this.syncFromValueProp(),this.componentReady.emit(),this.id||console.error('tabworthy-times: The "id" prop is required for accessibility')}syncFromValueProp(){if(this.value){this.internalValue=this.value;const t=Array.isArray(this.value)?this.value[0]:this.value;if(t){const s=o(t,this.format);s.isValid()&&(this.selectedDate=s.toDate(),this.selectedHours=s.hour(),this.selectedMinutes=s.minute(),this.selectedSeconds=s.second())}}else this.internalValue=null}updateValue(t){if(Array.isArray(t)){const s=t.map((t=>o(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format)));this.internalValue=s,this.value=s,this.selectDateTime.emit(s)}else{const s=o(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format);this.internalValue=s,this.value=s,this.selectedDate=t,this.selectDateTime.emit(s)}this.errorState=!1,this.shouldInputFormat()&&this.formatInput()}isDateValid(t){const s=o(t);return!(!s.isValid()||(this.minDate&&s.isBefore(o(this.minDate))?(this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,this.emitErrorChange("minDate",this.errorMessage),1):this.maxDate&&s.isAfter(o(this.maxDate))?(this.errorState=!0,this.errorMessage=`${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`,this.emitErrorChange("maxDate",this.errorMessage),1):this.disableDate(t)&&(this.errorState=!0,this.errorMessage=this.timesLabels.disabledDateError,this.emitErrorChange("disabledDate",this.errorMessage),1)))}formatInput(){if(this.internalValue)if(Array.isArray(this.internalValue)){const t=this.internalValue.map((t=>o(t,this.format).format("lll"))).join(` ${this.timesLabels.to} `);this.inputRef.value=t}else this.inputRef.value=o(this.internalValue,this.format).format("lll")}getClassName(t){return`${this.elementClassName}__${t}`}toDate(t){return t?Array.isArray(t)?t.map((t=>o(t,this.format).toDate())):o(t,this.format).toDate():null}async clearValue(){this.internalValue=null,this.value=void 0,this.selectedDate=void 0,this.inputRef&&(this.inputRef.value=""),this.pickerRef&&(this.pickerRef.value=null),this.selectDateTime.emit(void 0)}render(){var t;return i(h,{key:"d258bd87c60aa773bd178e1e74eeb32934d8f068",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},i("label",{key:"5e7a53cb36c350794af9fed2371c89823726ee2f",htmlFor:this.id+"-input",class:this.getClassName("label")},this.label),i("div",{key:"986905f117271cfb82a1f8415d55536a590ac2bc",class:this.getClassName("input-container"),ref:t=>this.inputContainerRef=t},i("input",{key:"9ad436c1e0c8a427c1665db16913cddf93d94fed",id:this.id+"-input",ref:t=>this.inputRef=t,type:"text",class:{[this.getClassName("input")]:!0,[this.inputClass]:!!this.inputClass},placeholder:this.placeholder,disabled:this.disabledState||this.disableFreeformInput,value:null===(t=this.internalValue)||void 0===t?void 0:""+t,onBlur:this.handleInputBlur,onChange:this.handleInputChange,"aria-describedby":this.errorState?this.id+"-error":void 0,"aria-invalid":this.errorState}),!this.inline&&i("button",{key:"d537e6f3251bada7ad50bbe1ca2c562737205897",type:"button",onClick:this.handleCalendarButtonClick,class:this.getClassName("calendar-button"),disabled:this.disabledState,"aria-label":this.calendarButtonContent?this.timesLabels.openCalendar:void 0},this.calendarButtonContent?i("span",{innerHTML:this.calendarButtonContent}):this.timesLabels.openCalendar)),i("tabworthy-dates-modal",{key:"241700195e1d028f8d8b6b55af7de3aee09163ea",label:this.timesLabels.calendar,ref:t=>this.modalRef=t,onOpened:()=>{this.pickerRef&&(this.pickerRef.modalIsOpen=!0)},onClosed:()=>{this.pickerRef&&(this.pickerRef.modalIsOpen=!1)},inline:this.inline,appendTo:this.appendTo},i("div",{key:"b99aa129e4d1d600971bc4d21b2c6a4316ff64cf",class:this.getClassName("picker-container")},i("tabworthy-dates-calendar",{key:"6ac11c01936e2155c023d286d912ba87e0ed3415",range:this.range,locale:this.locale,onSelectDate:t=>this.handlePickerSelection(t.detail),onChangeMonth:t=>this.handleChangedMonths(t.detail),onChangeYear:t=>this.handleYearChange(t.detail),onRequestClose:()=>{var t;return null===(t=this.modalRef)||void 0===t?void 0:t.close()},labels:this.datesCalendarLabels,ref:t=>this.pickerRef=t,startDate:this.startDate,firstDayOfWeek:this.firstDayOfWeek,showHiddenTitle:!0,disabled:this.disabledState,showMonthStepper:this.showMonthStepper,showYearStepper:this.showYearStepper,showClearButton:this.showClearButton,showCloseButton:this.showCloseButton,showTodayButton:this.showTodayButton,disableDate:this.disableDate,minDate:this.minDate,maxDate:this.maxDate,inline:this.inline,value:this.value?this.toDate(this.value):void 0,nextMonthButtonContent:this.nextMonthButtonContent,nextYearButtonContent:this.nextYearButtonContent,previousMonthButtonContent:this.previousMonthButtonContent,previousYearButtonContent:this.previousYearButtonContent,todayButtonContent:this.todayButtonContent,clearButtonContent:this.clearButtonContent,closeButtonContent:this.closeButtonContent},i("div",{key:"7eead2c25334abce43fe7371436a52b0970e648b",slot:"after-calendar",class:this.getClassName("time-section")},i("hr",{key:"06ac45a5eaaaa56d39825f941b0951f99c4b28e9",class:this.getClassName("divider")}),i("tabworthy-times-picker",{key:"ba4187a2a369cff58ca0ecf3a60abfeff3ba9ca3",hours:this.selectedHours,minutes:this.selectedMinutes,seconds:this.selectedSeconds,showSeconds:this.showSeconds,useTwelveHourFormat:this.useTwelveHourFormat,disabled:this.disabledState||this.isDateOutOfBounds(),onTimeChanged:this.handleTimeChange,labels:this.timesPickerLabels,minTime:this.getEffectiveMinTime(),maxTime:this.getEffectiveMaxTime()}))))),this.errorState&&i("div",{key:"c187d0bd982a5184aa796ffe8be4ed91c340230d",class:this.getClassName("input-error"),id:this.id?this.id+"-error":void 0,role:"status"},this.errorMessage))}get el(){return this}static get watchers(){return{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}}},[2,"tabworthy-times",{id:[513],value:[1025],range:[4],label:[1],placeholder:[1],locale:[1],disabled:[4],minDate:[1,"min-date"],maxDate:[1,"max-date"],startDate:[1,"start-date"],referenceDate:[1,"reference-date"],useTwelveHourFormat:[4,"use-twelve-hour-format"],showSeconds:[4,"show-seconds"],timesLabels:[16],datesCalendarLabels:[16],timesPickerLabels:[16],inline:[4],hasError:[1028,"has-error"],showYearStepper:[4,"show-year-stepper"],showMonthStepper:[4,"show-month-stepper"],showClearButton:[4,"show-clear-button"],showCloseButton:[4,"show-close-button"],showTodayButton:[4,"show-today-button"],calendarButtonContent:[1,"calendar-button-content"],nextMonthButtonContent:[1,"next-month-button-content"],nextYearButtonContent:[1,"next-year-button-content"],previousMonthButtonContent:[1,"previous-month-button-content"],previousYearButtonContent:[1,"previous-year-button-content"],todayButtonContent:[1,"today-button-content"],clearButtonContent:[1,"clear-button-content"],closeButtonContent:[1,"close-button-content"],disableDate:[16],elementClassName:[1,"element-class-name"],firstDayOfWeek:[2,"first-day-of-week"],format:[1],inputShouldFormat:[8,"input-should-format"],disableFreeformInput:[4,"disable-freeform-input"],inputClass:[1,"input-class"],appendTo:[1,"append-to"],internalValue:[32],selectedDate:[32],selectedHours:[32],selectedMinutes:[32],selectedSeconds:[32],errorState:[32],disabledState:[32],clearValue:[64]},void 0,{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}]),w=v,D=function(){"undefined"!=typeof customElements&&["tabworthy-times","tabworthy-dates-calendar","tabworthy-dates-modal","tabworthy-times-picker"].forEach((t=>{switch(t){case"tabworthy-times":customElements.get(a(t))||customElements.define(a(t),v);break;case"tabworthy-dates-calendar":customElements.get(a(t))||c();break;case"tabworthy-dates-modal":customElements.get(a(t))||u();break;case"tabworthy-times-picker":customElements.get(a(t))||m()}}))};export{w as TabworthyTimes,D as defineCustomElement}
|
|
1
|
+
import{p as t,H as s,c as i,h as e,d as h,t as a}from"./p-BiJ0HZVY.js";import{g as n,d as o,c as r}from"./p-DkyM-7xr.js";import{g as d,r as l,c}from"./p-BzY8iIVW.js";import{d as u}from"./p-CMIEIvTW.js";import{d as m}from"./p-C_uZGgcG.js";var b,f={exports:{}},p=n(b?f.exports:(b=1,f.exports=function(){var t={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(s,i,e){var h=i.prototype,a=h.format;e.en.formats=t,h.format=function(s){void 0===s&&(s="YYYY-MM-DDTHH:mm:ssZ");var i=this.$locale().formats,e=function(s,i){return s.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(s,e,h){var a=h&&h.toUpperCase();return e||i[h]||t[h]||i[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,s,i){return s||i.slice(1)}))}))}(s,void 0===i?{}:i);return a.call(this,e)}}}()));o.extend(r),o.extend(p);const y={selected:"selected",openCalendar:"Choose time",calendar:"date and time picker",invalidDateError:"We could not find a matching date",minDateError:"Please fill in a date after ",maxDateError:"Please fill in a date before ",rangeOutOfBoundsError:"Please enter a valid range of dates",disabledDateError:"Please choose an available date",to:"to",startDate:"Start date",timeLabel:"Time"},v=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.selectDateTime=i(this,"selectDateTime",7),this.changeYear=i(this,"changeYear",7),this.errorChange=i(this,"errorChange",7),this.componentReady=i(this,"componentReady",7),this.range=!1,this.label="Choose a date and time",this.placeholder="",this.locale=(null===navigator||void 0===navigator?void 0:navigator.language)||"en-US",this.disabled=!1,this.startDate=d(new Date),this.referenceDate=d(new Date),this.useTwelveHourFormat=!0,this.showSeconds=!1,this.timesLabels=y,this.inline=!1,this.hasError=!1,this.showYearStepper=!1,this.showMonthStepper=!0,this.showClearButton=!0,this.showCloseButton=!1,this.showTodayButton=!0,this.disableDate=()=>!1,this.elementClassName="tabworthy-times",this.firstDayOfWeek=1,this.format="YYYY-MM-DDTHH:mm:ss",this.inputShouldFormat=!0,this.disableFreeformInput=!1,this.inputClass="",this.selectedHours=(new Date).getHours(),this.selectedMinutes=(new Date).getMinutes(),this.selectedSeconds=(new Date).getSeconds(),this.errorState=this.hasError,this.disabledState=this.disabled,this.errorMessage="",this.handlePickerSelection=async t=>{if(!t)return this.clearValue();const s=t.split(",");if(this.range&&2===s.length){const t=l(new Date(s[0])),i=l(new Date(s[1]));if(!this.isDateValid(t)||!this.isDateValid(i))return;this.updateValue([t,i]),this.pickerRef&&(this.pickerRef.value=[t,i])}else{const t=l(new Date(s[0]));if(!this.isDateValid(t))return;this.clampTimeToBounds(t),this.updateValue(t),this.pickerRef&&(this.pickerRef.value=void 0,this.pickerRef.value=t)}},this.handleTimeChange=t=>{this.selectedHours=t.detail.hours,this.selectedMinutes=t.detail.minutes,void 0!==t.detail.seconds&&(this.selectedSeconds=t.detail.seconds),this.selectedDate&&this.updateValue(this.selectedDate)},this.handleCalendarButtonClick=async()=>{this.modalRef&&(await this.modalRef.setTriggerElement(this.inputContainerRef),await this.modalRef.open())},this.handleYearChange=t=>{this.changeYear&&this.changeYear.emit(t)},this.handleChangedMonths=()=>{},this.handleInputBlur=()=>{this.shouldInputFormat()&&this.formatInput()},this.handleInputChange=t=>{const s=t.target.value;if(0===s.length)return this.errorState=!1,this.internalValue="",this.pickerRef&&(this.pickerRef.value=null),this.value=this.internalValue,this.selectDateTime.emit(this.internalValue);let i=o(s,this.format,!0);if(i.isValid()||(i=o(s)),i.isValid()){if(this.minDate&&i.isBefore(o(this.minDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,void this.emitErrorChange("minDate",this.errorMessage);if(this.maxDate&&i.isAfter(o(this.maxDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`,void this.emitErrorChange("maxDate",this.errorMessage);if(this.disableDate(i.toDate()))return this.errorState=!0,this.errorMessage=this.timesLabels.disabledDateError,void this.emitErrorChange("disabledDate",this.errorMessage);this.errorState=!1,this.selectedHours=i.hour(),this.selectedMinutes=i.minute(),this.selectedSeconds=i.second(),this.updateValue(i.toDate())}else this.errorState=!0,this.errorMessage=this.timesLabels.invalidDateError,this.emitErrorChange("invalid",this.errorMessage)}}emitErrorChange(t,s){this.errorChange.emit({reason:t,message:s})}formatBoundaryDate(t){const s=o(t);if(!s.isValid())return t;if(!t.includes("T")&&!t.includes(" "))return Intl.DateTimeFormat(this.locale,{day:"numeric",month:"short",year:"numeric"}).format(s.toDate());const i=Object.assign({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"numeric"},this.showSeconds?{second:"numeric"}:{});return Intl.DateTimeFormat(this.locale,i).format(s.toDate())}getEffectiveMinTime(){if(!this.minDate||!this.selectedDate)return;const t=o(this.minDate),s=o(this.selectedDate);return t.isValid()&&s.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}getEffectiveMaxTime(){if(!this.maxDate||!this.selectedDate)return;const t=o(this.maxDate),s=o(this.selectedDate);return t.isValid()&&s.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}isDateOutOfBounds(){if(!this.selectedDate)return!1;const t=o(this.selectedDate);return!(!this.minDate||!t.isBefore(o(this.minDate),"day"))||!(!this.maxDate||!t.isAfter(o(this.maxDate),"day"))}clampTimeToBounds(t){const s=o(t);if(this.minDate){const t=o(this.minDate);t.isValid()&&s.isSame(t,"day")&&3600*this.selectedHours+60*this.selectedMinutes+this.selectedSeconds<3600*t.hour()+60*t.minute()+t.second()&&(this.selectedHours=t.hour(),this.selectedMinutes=t.minute(),this.selectedSeconds=t.second())}if(this.maxDate){const t=o(this.maxDate);t.isValid()&&s.isSame(t,"day")&&3600*this.selectedHours+60*this.selectedMinutes+this.selectedSeconds>3600*t.hour()+60*t.minute()+t.second()&&(this.selectedHours=t.hour(),this.selectedMinutes=t.minute(),this.selectedSeconds=t.second())}}shouldInputFormat(){return"string"==typeof this.inputShouldFormat?"true"===this.inputShouldFormat:!!this.inputShouldFormat}watchValue(t){this.syncFromValueProp()}watchDisabled(t){this.disabledState=t}watchHasError(t){this.errorState=t}componentDidLoad(){this.syncFromValueProp(),this.componentReady.emit(),this.id||console.error('tabworthy-times: The "id" prop is required for accessibility')}syncFromValueProp(){if(this.value){this.internalValue=this.value;const t=Array.isArray(this.value)?this.value[0]:this.value;if(t){const s=o(t,this.format);s.isValid()&&(this.selectedDate=s.toDate(),this.selectedHours=s.hour(),this.selectedMinutes=s.minute(),this.selectedSeconds=s.second())}}else this.internalValue=null}updateValue(t){if(Array.isArray(t)){const s=t.map((t=>o(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format)));this.internalValue=s,this.value=s,this.selectDateTime.emit(s)}else{const s=o(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format);this.internalValue=s,this.value=s,this.selectedDate=t,this.selectDateTime.emit(s)}this.errorState=!1,this.shouldInputFormat()&&this.formatInput()}isDateValid(t){const s=o(t);return!(!s.isValid()||(this.minDate&&s.isBefore(o(this.minDate),"day")?(this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,this.emitErrorChange("minDate",this.errorMessage),1):this.maxDate&&s.isAfter(o(this.maxDate),"day")?(this.errorState=!0,this.errorMessage=`${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`,this.emitErrorChange("maxDate",this.errorMessage),1):this.disableDate(t)&&(this.errorState=!0,this.errorMessage=this.timesLabels.disabledDateError,this.emitErrorChange("disabledDate",this.errorMessage),1)))}formatInput(){if(this.internalValue)if(Array.isArray(this.internalValue)){const t=this.internalValue.map((t=>o(t,this.format).format("lll"))).join(` ${this.timesLabels.to} `);this.inputRef.value=t}else this.inputRef.value=o(this.internalValue,this.format).format("lll")}getClassName(t){return`${this.elementClassName}__${t}`}toDate(t){return t?Array.isArray(t)?t.map((t=>o(t,this.format).toDate())):o(t,this.format).toDate():null}async clearValue(){this.internalValue=null,this.value=void 0,this.selectedDate=void 0,this.inputRef&&(this.inputRef.value=""),this.pickerRef&&(this.pickerRef.value=null),this.selectDateTime.emit(void 0)}render(){var t;return e(h,{key:"6c3049b02eda2e976f14616027cfb3fd1a0b0100",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},e("label",{key:"eb9ecc8c81d04338a5935ad414c6cd544a01bb58",htmlFor:this.id+"-input",class:this.getClassName("label")},this.label),e("div",{key:"8906972aec0b8c7b24cc3f2d07212c3f6c2d8f56",class:this.getClassName("input-container"),ref:t=>this.inputContainerRef=t},e("input",{key:"bca908ac7aa2710569fa86be5c7c6643d7f73574",id:this.id+"-input",ref:t=>this.inputRef=t,type:"text",class:{[this.getClassName("input")]:!0,[this.inputClass]:!!this.inputClass},placeholder:this.placeholder,disabled:this.disabledState||this.disableFreeformInput,value:null===(t=this.internalValue)||void 0===t?void 0:""+t,onBlur:this.handleInputBlur,onChange:this.handleInputChange,"aria-describedby":this.errorState?this.id+"-error":void 0,"aria-invalid":this.errorState}),!this.inline&&e("button",{key:"c0d27ab5207fb62606e017bea14c93bc44daebb9",type:"button",onClick:this.handleCalendarButtonClick,class:this.getClassName("calendar-button"),disabled:this.disabledState,"aria-label":this.calendarButtonContent?this.timesLabels.openCalendar:void 0},this.calendarButtonContent?e("span",{innerHTML:this.calendarButtonContent}):this.timesLabels.openCalendar)),e("tabworthy-dates-modal",{key:"1e6761504cd55a9fd380902861aeec0e7e655d47",label:this.timesLabels.calendar,ref:t=>this.modalRef=t,onOpened:()=>{this.pickerRef&&(this.pickerRef.modalIsOpen=!0)},onClosed:()=>{this.pickerRef&&(this.pickerRef.modalIsOpen=!1)},inline:this.inline,appendTo:this.appendTo},e("div",{key:"14966bd22b73a14fcb54bf118543e6aedf6e291f",class:this.getClassName("picker-container")},e("tabworthy-dates-calendar",{key:"aef55f7ee2cb19eb68bf8db51dd3e111e4f0dbff",range:this.range,locale:this.locale,onSelectDate:t=>this.handlePickerSelection(t.detail),onChangeMonth:t=>this.handleChangedMonths(t.detail),onChangeYear:t=>this.handleYearChange(t.detail),onRequestClose:()=>{var t;return null===(t=this.modalRef)||void 0===t?void 0:t.close()},labels:this.datesCalendarLabels,ref:t=>this.pickerRef=t,startDate:this.startDate,firstDayOfWeek:this.firstDayOfWeek,showHiddenTitle:!0,disabled:this.disabledState,showMonthStepper:this.showMonthStepper,showYearStepper:this.showYearStepper,showClearButton:this.showClearButton,showCloseButton:this.showCloseButton,showTodayButton:this.showTodayButton,disableDate:this.disableDate,minDate:this.minDate,maxDate:this.maxDate,inline:this.inline,value:this.value?this.toDate(this.value):void 0,nextMonthButtonContent:this.nextMonthButtonContent,nextYearButtonContent:this.nextYearButtonContent,previousMonthButtonContent:this.previousMonthButtonContent,previousYearButtonContent:this.previousYearButtonContent,todayButtonContent:this.todayButtonContent,clearButtonContent:this.clearButtonContent,closeButtonContent:this.closeButtonContent},e("div",{key:"f89b6d83e9ef68bd98eb6e08ea3aec00c2b6dd86",slot:"after-calendar",class:this.getClassName("time-section")},e("hr",{key:"2ae84e5817c25641ab56ff096f164355524abfdf",class:this.getClassName("divider")}),e("tabworthy-times-picker",{key:"55bfe07297efd0c60d47d6049572f502311abf15",hours:this.selectedHours,minutes:this.selectedMinutes,seconds:this.selectedSeconds,showSeconds:this.showSeconds,useTwelveHourFormat:this.useTwelveHourFormat,disabled:this.disabledState||this.isDateOutOfBounds(),onTimeChanged:this.handleTimeChange,labels:this.timesPickerLabels,minTime:this.getEffectiveMinTime(),maxTime:this.getEffectiveMaxTime()}))))),this.errorState&&e("div",{key:"97dbda7bc8725c8964a627e37e9236e9bf699ee0",class:this.getClassName("input-error"),id:this.id?this.id+"-error":void 0,role:"status"},this.errorMessage))}get el(){return this}static get watchers(){return{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}}},[2,"tabworthy-times",{id:[513],value:[1025],range:[4],label:[1],placeholder:[1],locale:[1],disabled:[4],minDate:[1,"min-date"],maxDate:[1,"max-date"],startDate:[1,"start-date"],referenceDate:[1,"reference-date"],useTwelveHourFormat:[4,"use-twelve-hour-format"],showSeconds:[4,"show-seconds"],timesLabels:[16],datesCalendarLabels:[16],timesPickerLabels:[16],inline:[4],hasError:[1028,"has-error"],showYearStepper:[4,"show-year-stepper"],showMonthStepper:[4,"show-month-stepper"],showClearButton:[4,"show-clear-button"],showCloseButton:[4,"show-close-button"],showTodayButton:[4,"show-today-button"],calendarButtonContent:[1,"calendar-button-content"],nextMonthButtonContent:[1,"next-month-button-content"],nextYearButtonContent:[1,"next-year-button-content"],previousMonthButtonContent:[1,"previous-month-button-content"],previousYearButtonContent:[1,"previous-year-button-content"],todayButtonContent:[1,"today-button-content"],clearButtonContent:[1,"clear-button-content"],closeButtonContent:[1,"close-button-content"],disableDate:[16],elementClassName:[1,"element-class-name"],firstDayOfWeek:[2,"first-day-of-week"],format:[1],inputShouldFormat:[8,"input-should-format"],disableFreeformInput:[4,"disable-freeform-input"],inputClass:[1,"input-class"],appendTo:[1,"append-to"],internalValue:[32],selectedDate:[32],selectedHours:[32],selectedMinutes:[32],selectedSeconds:[32],errorState:[32],disabledState:[32],clearValue:[64]},void 0,{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}]),w=v,D=function(){"undefined"!=typeof customElements&&["tabworthy-times","tabworthy-dates-calendar","tabworthy-dates-modal","tabworthy-times-picker"].forEach((t=>{switch(t){case"tabworthy-times":customElements.get(a(t))||customElements.define(a(t),v);break;case"tabworthy-dates-calendar":customElements.get(a(t))||c();break;case"tabworthy-dates-modal":customElements.get(a(t))||u();break;case"tabworthy-times-picker":customElements.get(a(t))||m()}}))};export{w as TabworthyTimes,D as defineCustomElement}
|
|
@@ -10664,6 +10664,16 @@ const TabworthyDates = class {
|
|
|
10664
10664
|
this.value = this.internalValue;
|
|
10665
10665
|
return this.selectDate.emit(this.internalValue);
|
|
10666
10666
|
}
|
|
10667
|
+
// Try strict format parsing first to avoid DD/MM vs MM/DD ambiguity
|
|
10668
|
+
const strictParsed = dayjs$1(value, this.format, true);
|
|
10669
|
+
if (strictParsed.isValid()) {
|
|
10670
|
+
const date = strictParsed.toDate();
|
|
10671
|
+
if (!this.isPickedDateValid(date))
|
|
10672
|
+
return;
|
|
10673
|
+
this.updateValue(date);
|
|
10674
|
+
this.formatInput(true, false);
|
|
10675
|
+
return;
|
|
10676
|
+
}
|
|
10667
10677
|
const parsedDate = await chronoParseDate(value, {
|
|
10668
10678
|
locale: this.locale.slice(0, 2),
|
|
10669
10679
|
minDate: this.minDate,
|
|
@@ -114,9 +114,12 @@ const TabworthyTimes = class {
|
|
|
114
114
|
const date = removeTimezoneOffset(new Date(dates[0]));
|
|
115
115
|
if (!this.isDateValid(date))
|
|
116
116
|
return;
|
|
117
|
+
// Clamp time to boundary constraints when selecting a boundary day
|
|
118
|
+
this.clampTimeToBounds(date);
|
|
117
119
|
this.updateValue(date);
|
|
118
|
-
//
|
|
120
|
+
// Reset then set calendar value so re-clicking the same date still emits
|
|
119
121
|
if (this.pickerRef) {
|
|
122
|
+
this.pickerRef.value = undefined;
|
|
120
123
|
this.pickerRef.value = date;
|
|
121
124
|
}
|
|
122
125
|
}
|
|
@@ -259,6 +262,41 @@ const TabworthyTimes = class {
|
|
|
259
262
|
return true;
|
|
260
263
|
return false;
|
|
261
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* When selecting a date on a boundary day, adjust the time to the first
|
|
267
|
+
* available time if the current selection falls outside the allowed range.
|
|
268
|
+
*/
|
|
269
|
+
clampTimeToBounds(date) {
|
|
270
|
+
const sel = dayjs(date);
|
|
271
|
+
if (this.minDate) {
|
|
272
|
+
const min = dayjs(this.minDate);
|
|
273
|
+
if (min.isValid() && sel.isSame(min, "day")) {
|
|
274
|
+
const curTotal = this.selectedHours * 3600 +
|
|
275
|
+
this.selectedMinutes * 60 +
|
|
276
|
+
this.selectedSeconds;
|
|
277
|
+
const minTotal = min.hour() * 3600 + min.minute() * 60 + min.second();
|
|
278
|
+
if (curTotal < minTotal) {
|
|
279
|
+
this.selectedHours = min.hour();
|
|
280
|
+
this.selectedMinutes = min.minute();
|
|
281
|
+
this.selectedSeconds = min.second();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (this.maxDate) {
|
|
286
|
+
const max = dayjs(this.maxDate);
|
|
287
|
+
if (max.isValid() && sel.isSame(max, "day")) {
|
|
288
|
+
const curTotal = this.selectedHours * 3600 +
|
|
289
|
+
this.selectedMinutes * 60 +
|
|
290
|
+
this.selectedSeconds;
|
|
291
|
+
const maxTotal = max.hour() * 3600 + max.minute() * 60 + max.second();
|
|
292
|
+
if (curTotal > maxTotal) {
|
|
293
|
+
this.selectedHours = max.hour();
|
|
294
|
+
this.selectedMinutes = max.minute();
|
|
295
|
+
this.selectedSeconds = max.second();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
262
300
|
shouldInputFormat() {
|
|
263
301
|
if (typeof this.inputShouldFormat === "string") {
|
|
264
302
|
return this.inputShouldFormat === "true";
|
|
@@ -335,13 +373,13 @@ const TabworthyTimes = class {
|
|
|
335
373
|
const parsed = dayjs(date);
|
|
336
374
|
if (!parsed.isValid())
|
|
337
375
|
return false;
|
|
338
|
-
if (this.minDate && parsed.isBefore(dayjs(this.minDate))) {
|
|
376
|
+
if (this.minDate && parsed.isBefore(dayjs(this.minDate), "day")) {
|
|
339
377
|
this.errorState = true;
|
|
340
378
|
this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
|
|
341
379
|
this.emitErrorChange("minDate", this.errorMessage);
|
|
342
380
|
return false;
|
|
343
381
|
}
|
|
344
|
-
if (this.maxDate && parsed.isAfter(dayjs(this.maxDate))) {
|
|
382
|
+
if (this.maxDate && parsed.isAfter(dayjs(this.maxDate), "day")) {
|
|
345
383
|
this.errorState = true;
|
|
346
384
|
this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
|
|
347
385
|
this.emitErrorChange("maxDate", this.errorMessage);
|
|
@@ -395,12 +433,12 @@ const TabworthyTimes = class {
|
|
|
395
433
|
}
|
|
396
434
|
render() {
|
|
397
435
|
var _a;
|
|
398
|
-
return (h(Host, { key: '
|
|
436
|
+
return (h(Host, { key: '6c3049b02eda2e976f14616027cfb3fd1a0b0100', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: 'eb9ecc8c81d04338a5935ad414c6cd544a01bb58', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '8906972aec0b8c7b24cc3f2d07212c3f6c2d8f56', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: 'bca908ac7aa2710569fa86be5c7c6643d7f73574', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
399
437
|
[this.getClassName("input")]: true,
|
|
400
438
|
[this.inputClass]: !!this.inputClass
|
|
401
|
-
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { key: '
|
|
439
|
+
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { key: 'c0d27ab5207fb62606e017bea14c93bc44daebb9', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
|
|
402
440
|
? this.timesLabels.openCalendar
|
|
403
|
-
: undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '
|
|
441
|
+
: undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '1e6761504cd55a9fd380902861aeec0e7e655d47', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
404
442
|
if (this.pickerRef) {
|
|
405
443
|
this.pickerRef.modalIsOpen = true;
|
|
406
444
|
}
|
|
@@ -408,7 +446,7 @@ const TabworthyTimes = class {
|
|
|
408
446
|
if (this.pickerRef) {
|
|
409
447
|
this.pickerRef.modalIsOpen = false;
|
|
410
448
|
}
|
|
411
|
-
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '
|
|
449
|
+
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '14966bd22b73a14fcb54bf118543e6aedf6e291f', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: 'aef55f7ee2cb19eb68bf8db51dd3e111e4f0dbff', range: this.range, locale: this.locale, onSelectDate: (event) => this.handlePickerSelection(event.detail), onChangeMonth: (event) => this.handleChangedMonths(event.detail), onChangeYear: (event) => this.handleYearChange(event.detail), onRequestClose: () => { var _a; return (_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.close(); }, labels: this.datesCalendarLabels, ref: (el) => (this.pickerRef = el), startDate: this.startDate, firstDayOfWeek: this.firstDayOfWeek, showHiddenTitle: true, disabled: this.disabledState, showMonthStepper: this.showMonthStepper, showYearStepper: this.showYearStepper, showClearButton: this.showClearButton, showCloseButton: this.showCloseButton, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline, value: this.value ? this.toDate(this.value) : undefined, nextMonthButtonContent: this.nextMonthButtonContent, nextYearButtonContent: this.nextYearButtonContent, previousMonthButtonContent: this.previousMonthButtonContent, previousYearButtonContent: this.previousYearButtonContent, todayButtonContent: this.todayButtonContent, clearButtonContent: this.clearButtonContent, closeButtonContent: this.closeButtonContent }, h("div", { key: 'f89b6d83e9ef68bd98eb6e08ea3aec00c2b6dd86', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '2ae84e5817c25641ab56ff096f164355524abfdf', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: '55bfe07297efd0c60d47d6049572f502311abf15', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime() }))))), this.errorState && (h("div", { key: '97dbda7bc8725c8964a627e37e9236e9bf699ee0', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
412
450
|
}
|
|
413
451
|
get el() { return getElement(this); }
|
|
414
452
|
static get watchers() { return {
|