@tabworthy/components 0.14.0 → 0.14.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.
@@ -322,8 +322,8 @@ const TabworthyTimes = class {
322
322
  }
323
323
  }
324
324
  syncFromValueProp() {
325
+ this.internalValue = this.value || null;
325
326
  if (this.value) {
326
- this.internalValue = this.value;
327
327
  // Parse the first datetime value to set time picker
328
328
  const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
329
329
  if (firstValue) {
@@ -337,7 +337,35 @@ const TabworthyTimes = class {
337
337
  }
338
338
  }
339
339
  else {
340
- this.internalValue = null;
340
+ this.selectedDate = undefined;
341
+ }
342
+ // Update calendar picker
343
+ if (this.pickerRef) {
344
+ if (Array.isArray(this.value)) {
345
+ const dates = this.value.reduce((acc, v) => {
346
+ const d = customParseFormat.dayjs(v, this.format, true);
347
+ if (d.isValid())
348
+ acc.push(d.toDate());
349
+ return acc;
350
+ }, []);
351
+ this.pickerRef.value = dates.length ? dates : null;
352
+ }
353
+ else if (this.value) {
354
+ const parsedDate = customParseFormat.dayjs(this.value, this.format, true);
355
+ if (parsedDate.isValid()) {
356
+ this.pickerRef.value = parsedDate.toDate();
357
+ }
358
+ }
359
+ else {
360
+ this.pickerRef.value = null;
361
+ }
362
+ }
363
+ // Update text input display
364
+ if (!this.value && this.inputRef) {
365
+ this.inputRef.value = "";
366
+ }
367
+ else if (this.value && this.inputRef && this.shouldInputFormat()) {
368
+ this.formatInput();
341
369
  }
342
370
  }
343
371
  updateValue(date) {
@@ -441,12 +469,12 @@ const TabworthyTimes = class {
441
469
  }
442
470
  render() {
443
471
  var _a;
444
- return (index.h(index.Host, { key: '315801393d1528c6e6ba98b9e1c51187e40f62f5', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, index.h("label", { key: 'c0ff6094ad4f9a2c12c1f041cd75996a792f2b1c', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: 'ede6bcbbd1874acc47360facc5220a0b7fef358c', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, index.h("input", { key: '4dcbd71cdd54fca3bb3ae26d4982c49fa32db8d6', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
472
+ return (index.h(index.Host, { key: 'db58173120d568c6bccb3af0d0955e4c9d043989', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, index.h("label", { key: '30f94ed70b443c3b78f9e0ac347ef82cdc3d875d', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: '7ce024e38c8c91490f5d7dc35d4c79570b9974f6', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, index.h("input", { key: 'bf8ceea9dec20c699feb879a6b002006763ca281', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
445
473
  [this.getClassName("input")]: true,
446
474
  [this.inputClass]: !!this.inputClass
447
- }, 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 && (index.h("button", { key: 'f486c98770077cd7ff39d2a56cafaf3d8c80a36c', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
475
+ }, 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 && (index.h("button", { key: 'aa1ab4ccac43e28b4dd3e9b2eee4913bba683849', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
448
476
  ? this.timesLabels.openCalendar
449
- : undefined }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: 'b1cd3cbcea01f7147fe33abf11d62d35c50cbdb6', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
477
+ : undefined }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '15beb881dc3781674cc29a8498a4a9364c39267c', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
450
478
  if (this.pickerRef) {
451
479
  this.pickerRef.modalIsOpen = true;
452
480
  }
@@ -454,7 +482,7 @@ const TabworthyTimes = class {
454
482
  if (this.pickerRef) {
455
483
  this.pickerRef.modalIsOpen = false;
456
484
  }
457
- }, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: 'cec6685037168dd633037a6d723823572d9db5e5', class: this.getClassName("picker-container") }, index.h("tabworthy-dates-calendar", { key: '0dec8076bb3aee853979d6de95bd07a7095b717a', 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 }, index.h("div", { key: 'f69a1b84ebceaf5d0c359190bec9ae11189d75e0', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("hr", { key: '6b9e5ae7c1f5aaa447da7b1b393c9bd75043dac2', class: this.getClassName("divider") }), index.h("tabworthy-times-picker", { key: '406f5ac12c09d0fddc0ebe3330961b783c2d7366', 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 && (index.h("div", { key: 'ddc92f2c8d936a3a38f61d841860b17cd9c06283', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
485
+ }, inline: this.inline, appendTo: this.appendTo }, index.h("div", { key: '02a70b2008e2027c3c69e4fbe0ba0c6a673a8f4c', class: this.getClassName("picker-container") }, index.h("tabworthy-dates-calendar", { key: '84c959f8485472139a576ac74365877431be78f0', 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 }, index.h("div", { key: '0494b0e142b36320c2932827a844b583390a775c', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("hr", { key: '7d10d1832bb1d414fc76fd17cdaafe4f3ca96c5d', class: this.getClassName("divider") }), index.h("tabworthy-times-picker", { key: 'ff0c9d27e52d90038dbdfcacb02fb14911ec53a6', 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 && (index.h("div", { key: 'af0c35a6eaf1cef0d182c911c1d3a2b0bc08d56b', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
458
486
  }
459
487
  get el() { return index.getElement(this); }
460
488
  static get watchers() { return {
@@ -298,8 +298,8 @@ export class TabworthyTimes {
298
298
  }
299
299
  }
300
300
  syncFromValueProp() {
301
+ this.internalValue = this.value || null;
301
302
  if (this.value) {
302
- this.internalValue = this.value;
303
303
  // Parse the first datetime value to set time picker
304
304
  const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
305
305
  if (firstValue) {
@@ -313,7 +313,35 @@ export class TabworthyTimes {
313
313
  }
314
314
  }
315
315
  else {
316
- this.internalValue = null;
316
+ this.selectedDate = undefined;
317
+ }
318
+ // Update calendar picker
319
+ if (this.pickerRef) {
320
+ if (Array.isArray(this.value)) {
321
+ const dates = this.value.reduce((acc, v) => {
322
+ const d = dayjs(v, this.format, true);
323
+ if (d.isValid())
324
+ acc.push(d.toDate());
325
+ return acc;
326
+ }, []);
327
+ this.pickerRef.value = dates.length ? dates : null;
328
+ }
329
+ else if (this.value) {
330
+ const parsedDate = dayjs(this.value, this.format, true);
331
+ if (parsedDate.isValid()) {
332
+ this.pickerRef.value = parsedDate.toDate();
333
+ }
334
+ }
335
+ else {
336
+ this.pickerRef.value = null;
337
+ }
338
+ }
339
+ // Update text input display
340
+ if (!this.value && this.inputRef) {
341
+ this.inputRef.value = "";
342
+ }
343
+ else if (this.value && this.inputRef && this.shouldInputFormat()) {
344
+ this.formatInput();
317
345
  }
318
346
  }
319
347
  updateValue(date) {
@@ -417,12 +445,12 @@ export class TabworthyTimes {
417
445
  }
418
446
  render() {
419
447
  var _a;
420
- return (h(Host, { key: '315801393d1528c6e6ba98b9e1c51187e40f62f5', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: 'c0ff6094ad4f9a2c12c1f041cd75996a792f2b1c', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: 'ede6bcbbd1874acc47360facc5220a0b7fef358c', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: '4dcbd71cdd54fca3bb3ae26d4982c49fa32db8d6', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
448
+ return (h(Host, { key: 'db58173120d568c6bccb3af0d0955e4c9d043989', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: '30f94ed70b443c3b78f9e0ac347ef82cdc3d875d', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '7ce024e38c8c91490f5d7dc35d4c79570b9974f6', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: 'bf8ceea9dec20c699feb879a6b002006763ca281', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
421
449
  [this.getClassName("input")]: true,
422
450
  [this.inputClass]: !!this.inputClass
423
- }, 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: 'f486c98770077cd7ff39d2a56cafaf3d8c80a36c', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
451
+ }, 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: 'aa1ab4ccac43e28b4dd3e9b2eee4913bba683849', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
424
452
  ? this.timesLabels.openCalendar
425
- : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: 'b1cd3cbcea01f7147fe33abf11d62d35c50cbdb6', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
453
+ : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '15beb881dc3781674cc29a8498a4a9364c39267c', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
426
454
  if (this.pickerRef) {
427
455
  this.pickerRef.modalIsOpen = true;
428
456
  }
@@ -430,7 +458,7 @@ export class TabworthyTimes {
430
458
  if (this.pickerRef) {
431
459
  this.pickerRef.modalIsOpen = false;
432
460
  }
433
- }, inline: this.inline, appendTo: this.appendTo }, h("div", { key: 'cec6685037168dd633037a6d723823572d9db5e5', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '0dec8076bb3aee853979d6de95bd07a7095b717a', 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: 'f69a1b84ebceaf5d0c359190bec9ae11189d75e0', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '6b9e5ae7c1f5aaa447da7b1b393c9bd75043dac2', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: '406f5ac12c09d0fddc0ebe3330961b783c2d7366', 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: 'ddc92f2c8d936a3a38f61d841860b17cd9c06283', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
461
+ }, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '02a70b2008e2027c3c69e4fbe0ba0c6a673a8f4c', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '84c959f8485472139a576ac74365877431be78f0', 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: '0494b0e142b36320c2932827a844b583390a775c', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '7d10d1832bb1d414fc76fd17cdaafe4f3ca96c5d', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: 'ff0c9d27e52d90038dbdfcacb02fb14911ec53a6', 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: 'af0c35a6eaf1cef0d182c911c1d3a2b0bc08d56b', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
434
462
  }
435
463
  static get is() { return "tabworthy-times"; }
436
464
  static get encapsulation() { return "scoped"; }
@@ -1 +1 @@
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 c,c as l}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=c(new Date(s[0])),i=c(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=c(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 revertInput(t,s=!1){s&&(this.errorState=!1),this.value=t,this.syncFromValueProp()}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:"315801393d1528c6e6ba98b9e1c51187e40f62f5",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},e("label",{key:"c0ff6094ad4f9a2c12c1f041cd75996a792f2b1c",htmlFor:this.id+"-input",class:this.getClassName("label")},this.label),e("div",{key:"ede6bcbbd1874acc47360facc5220a0b7fef358c",class:this.getClassName("input-container"),ref:t=>this.inputContainerRef=t},e("input",{key:"4dcbd71cdd54fca3bb3ae26d4982c49fa32db8d6",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:"f486c98770077cd7ff39d2a56cafaf3d8c80a36c",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:"b1cd3cbcea01f7147fe33abf11d62d35c50cbdb6",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:"cec6685037168dd633037a6d723823572d9db5e5",class:this.getClassName("picker-container")},e("tabworthy-dates-calendar",{key:"0dec8076bb3aee853979d6de95bd07a7095b717a",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:"f69a1b84ebceaf5d0c359190bec9ae11189d75e0",slot:"after-calendar",class:this.getClassName("time-section")},e("hr",{key:"6b9e5ae7c1f5aaa447da7b1b393c9bd75043dac2",class:this.getClassName("divider")}),e("tabworthy-times-picker",{key:"406f5ac12c09d0fddc0ebe3330961b783c2d7366",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:"ddc92f2c8d936a3a38f61d841860b17cd9c06283",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],revertInput:[64],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))||l();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 c,c as l}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=c(new Date(s[0])),i=c(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=c(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.internalValue=this.value||null,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.selectedDate=void 0;if(this.pickerRef)if(Array.isArray(this.value)){const t=this.value.reduce(((t,s)=>{const i=o(s,this.format,!0);return i.isValid()&&t.push(i.toDate()),t}),[]);this.pickerRef.value=t.length?t:null}else if(this.value){const t=o(this.value,this.format,!0);t.isValid()&&(this.pickerRef.value=t.toDate())}else this.pickerRef.value=null;!this.value&&this.inputRef?this.inputRef.value="":this.value&&this.inputRef&&this.shouldInputFormat()&&this.formatInput()}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 revertInput(t,s=!1){s&&(this.errorState=!1),this.value=t,this.syncFromValueProp()}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:"db58173120d568c6bccb3af0d0955e4c9d043989",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},e("label",{key:"30f94ed70b443c3b78f9e0ac347ef82cdc3d875d",htmlFor:this.id+"-input",class:this.getClassName("label")},this.label),e("div",{key:"7ce024e38c8c91490f5d7dc35d4c79570b9974f6",class:this.getClassName("input-container"),ref:t=>this.inputContainerRef=t},e("input",{key:"bf8ceea9dec20c699feb879a6b002006763ca281",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:"aa1ab4ccac43e28b4dd3e9b2eee4913bba683849",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:"15beb881dc3781674cc29a8498a4a9364c39267c",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:"02a70b2008e2027c3c69e4fbe0ba0c6a673a8f4c",class:this.getClassName("picker-container")},e("tabworthy-dates-calendar",{key:"84c959f8485472139a576ac74365877431be78f0",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:"0494b0e142b36320c2932827a844b583390a775c",slot:"after-calendar",class:this.getClassName("time-section")},e("hr",{key:"7d10d1832bb1d414fc76fd17cdaafe4f3ca96c5d",class:this.getClassName("divider")}),e("tabworthy-times-picker",{key:"ff0c9d27e52d90038dbdfcacb02fb14911ec53a6",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:"af0c35a6eaf1cef0d182c911c1d3a2b0bc08d56b",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],revertInput:[64],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))||l();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}
@@ -320,8 +320,8 @@ const TabworthyTimes = class {
320
320
  }
321
321
  }
322
322
  syncFromValueProp() {
323
+ this.internalValue = this.value || null;
323
324
  if (this.value) {
324
- this.internalValue = this.value;
325
325
  // Parse the first datetime value to set time picker
326
326
  const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
327
327
  if (firstValue) {
@@ -335,7 +335,35 @@ const TabworthyTimes = class {
335
335
  }
336
336
  }
337
337
  else {
338
- this.internalValue = null;
338
+ this.selectedDate = undefined;
339
+ }
340
+ // Update calendar picker
341
+ if (this.pickerRef) {
342
+ if (Array.isArray(this.value)) {
343
+ const dates = this.value.reduce((acc, v) => {
344
+ const d = dayjs(v, this.format, true);
345
+ if (d.isValid())
346
+ acc.push(d.toDate());
347
+ return acc;
348
+ }, []);
349
+ this.pickerRef.value = dates.length ? dates : null;
350
+ }
351
+ else if (this.value) {
352
+ const parsedDate = dayjs(this.value, this.format, true);
353
+ if (parsedDate.isValid()) {
354
+ this.pickerRef.value = parsedDate.toDate();
355
+ }
356
+ }
357
+ else {
358
+ this.pickerRef.value = null;
359
+ }
360
+ }
361
+ // Update text input display
362
+ if (!this.value && this.inputRef) {
363
+ this.inputRef.value = "";
364
+ }
365
+ else if (this.value && this.inputRef && this.shouldInputFormat()) {
366
+ this.formatInput();
339
367
  }
340
368
  }
341
369
  updateValue(date) {
@@ -439,12 +467,12 @@ const TabworthyTimes = class {
439
467
  }
440
468
  render() {
441
469
  var _a;
442
- return (h(Host, { key: '315801393d1528c6e6ba98b9e1c51187e40f62f5', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: 'c0ff6094ad4f9a2c12c1f041cd75996a792f2b1c', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: 'ede6bcbbd1874acc47360facc5220a0b7fef358c', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: '4dcbd71cdd54fca3bb3ae26d4982c49fa32db8d6', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
470
+ return (h(Host, { key: 'db58173120d568c6bccb3af0d0955e4c9d043989', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: '30f94ed70b443c3b78f9e0ac347ef82cdc3d875d', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '7ce024e38c8c91490f5d7dc35d4c79570b9974f6', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: 'bf8ceea9dec20c699feb879a6b002006763ca281', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
443
471
  [this.getClassName("input")]: true,
444
472
  [this.inputClass]: !!this.inputClass
445
- }, 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: 'f486c98770077cd7ff39d2a56cafaf3d8c80a36c', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
473
+ }, 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: 'aa1ab4ccac43e28b4dd3e9b2eee4913bba683849', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
446
474
  ? this.timesLabels.openCalendar
447
- : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: 'b1cd3cbcea01f7147fe33abf11d62d35c50cbdb6', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
475
+ : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '15beb881dc3781674cc29a8498a4a9364c39267c', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
448
476
  if (this.pickerRef) {
449
477
  this.pickerRef.modalIsOpen = true;
450
478
  }
@@ -452,7 +480,7 @@ const TabworthyTimes = class {
452
480
  if (this.pickerRef) {
453
481
  this.pickerRef.modalIsOpen = false;
454
482
  }
455
- }, inline: this.inline, appendTo: this.appendTo }, h("div", { key: 'cec6685037168dd633037a6d723823572d9db5e5', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '0dec8076bb3aee853979d6de95bd07a7095b717a', 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: 'f69a1b84ebceaf5d0c359190bec9ae11189d75e0', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '6b9e5ae7c1f5aaa447da7b1b393c9bd75043dac2', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: '406f5ac12c09d0fddc0ebe3330961b783c2d7366', 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: 'ddc92f2c8d936a3a38f61d841860b17cd9c06283', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
483
+ }, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '02a70b2008e2027c3c69e4fbe0ba0c6a673a8f4c', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '84c959f8485472139a576ac74365877431be78f0', 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: '0494b0e142b36320c2932827a844b583390a775c', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '7d10d1832bb1d414fc76fd17cdaafe4f3ca96c5d', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: 'ff0c9d27e52d90038dbdfcacb02fb14911ec53a6', 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: 'af0c35a6eaf1cef0d182c911c1d3a2b0bc08d56b', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
456
484
  }
457
485
  get el() { return getElement(this); }
458
486
  static get watchers() { return {
@@ -0,0 +1 @@
1
+ import{r as t,c as i,h as s,H as h,g as e}from"./p-CwtZ_Lud.js";import{g as a,d as n,c as r}from"./p-DkyM-7xr.js";import{g as o,r as d}from"./p-CoFOnMSw.js";var c,l,u={exports:{}},f=a(c?u.exports:(c=1,u.exports=(l={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"},function(t,i,s){var h=i.prototype,e=h.format;s.en.formats=l,h.format=function(t){void 0===t&&(t="YYYY-MM-DDTHH:mm:ssZ");var i=this.$locale().formats,s=function(t,i){return t.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(t,s,h){var e=h&&h.toUpperCase();return s||i[h]||l[h]||i[e].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,i,s){return i||s.slice(1)}))}))}(t,void 0===i?{}:i);return e.call(this,s)}})));n.extend(r),n.extend(f);const m={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"},b=class{constructor(s){t(this,s),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=o(new Date),this.referenceDate=o(new Date),this.useTwelveHourFormat=!0,this.showSeconds=!1,this.timesLabels=m,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 i=t.split(",");if(this.range&&2===i.length){const t=d(new Date(i[0])),s=d(new Date(i[1]));if(!this.isDateValid(t)||!this.isDateValid(s))return;this.updateValue([t,s]),this.pickerRef&&(this.pickerRef.value=[t,s])}else{const t=d(new Date(i[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 i=t.target.value;if(0===i.length)return this.errorState=!1,this.internalValue="",this.pickerRef&&(this.pickerRef.value=null),this.value=this.internalValue,this.selectDateTime.emit(this.internalValue);let s=n(i,this.format,!0);if(s.isValid()||(s=n(i)),s.isValid()){if(this.minDate&&s.isBefore(n(this.minDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,void this.emitErrorChange("minDate",this.errorMessage);if(this.maxDate&&s.isAfter(n(this.maxDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`,void this.emitErrorChange("maxDate",this.errorMessage);if(this.disableDate(s.toDate()))return this.errorState=!0,this.errorMessage=this.timesLabels.disabledDateError,void this.emitErrorChange("disabledDate",this.errorMessage);this.errorState=!1,this.selectedHours=s.hour(),this.selectedMinutes=s.minute(),this.selectedSeconds=s.second(),this.updateValue(s.toDate())}else this.errorState=!0,this.errorMessage=this.timesLabels.invalidDateError,this.emitErrorChange("invalid",this.errorMessage)}}emitErrorChange(t,i){this.errorChange.emit({reason:t,message:i})}formatBoundaryDate(t){const i=n(t);if(!i.isValid())return t;if(!t.includes("T")&&!t.includes(" "))return Intl.DateTimeFormat(this.locale,{day:"numeric",month:"short",year:"numeric"}).format(i.toDate());const s=Object.assign({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"numeric"},this.showSeconds?{second:"numeric"}:{});return Intl.DateTimeFormat(this.locale,s).format(i.toDate())}getEffectiveMinTime(){if(!this.minDate||!this.selectedDate)return;const t=n(this.minDate),i=n(this.selectedDate);return t.isValid()&&i.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}getEffectiveMaxTime(){if(!this.maxDate||!this.selectedDate)return;const t=n(this.maxDate),i=n(this.selectedDate);return t.isValid()&&i.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}isDateOutOfBounds(){if(!this.selectedDate)return!1;const t=n(this.selectedDate);return!(!this.minDate||!t.isBefore(n(this.minDate),"day"))||!(!this.maxDate||!t.isAfter(n(this.maxDate),"day"))}clampTimeToBounds(t){const i=n(t);if(this.minDate){const t=n(this.minDate);t.isValid()&&i.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=n(this.maxDate);t.isValid()&&i.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.internalValue=this.value||null,this.value){const t=Array.isArray(this.value)?this.value[0]:this.value;if(t){const i=n(t,this.format);i.isValid()&&(this.selectedDate=i.toDate(),this.selectedHours=i.hour(),this.selectedMinutes=i.minute(),this.selectedSeconds=i.second())}}else this.selectedDate=void 0;if(this.pickerRef)if(Array.isArray(this.value)){const t=this.value.reduce(((t,i)=>{const s=n(i,this.format,!0);return s.isValid()&&t.push(s.toDate()),t}),[]);this.pickerRef.value=t.length?t:null}else if(this.value){const t=n(this.value,this.format,!0);t.isValid()&&(this.pickerRef.value=t.toDate())}else this.pickerRef.value=null;!this.value&&this.inputRef?this.inputRef.value="":this.value&&this.inputRef&&this.shouldInputFormat()&&this.formatInput()}updateValue(t){if(Array.isArray(t)){const i=t.map((t=>n(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format)));this.internalValue=i,this.value=i,this.selectDateTime.emit(i)}else{const i=n(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format);this.internalValue=i,this.value=i,this.selectedDate=t,this.selectDateTime.emit(i)}this.errorState=!1,this.shouldInputFormat()&&this.formatInput()}isDateValid(t){const i=n(t);return!(!i.isValid()||(this.minDate&&i.isBefore(n(this.minDate),"day")?(this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,this.emitErrorChange("minDate",this.errorMessage),1):this.maxDate&&i.isAfter(n(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=>n(t,this.format).format("lll"))).join(` ${this.timesLabels.to} `);this.inputRef.value=t}else this.inputRef.value=n(this.internalValue,this.format).format("lll")}getClassName(t){return`${this.elementClassName}__${t}`}toDate(t){return t?Array.isArray(t)?t.map((t=>n(t,this.format).toDate())):n(t,this.format).toDate():null}async revertInput(t,i=!1){i&&(this.errorState=!1),this.value=t,this.syncFromValueProp()}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 s(h,{key:"db58173120d568c6bccb3af0d0955e4c9d043989",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},s("label",{key:"30f94ed70b443c3b78f9e0ac347ef82cdc3d875d",htmlFor:`${this.id}-input`,class:this.getClassName("label")},this.label),s("div",{key:"7ce024e38c8c91490f5d7dc35d4c79570b9974f6",class:this.getClassName("input-container"),ref:t=>this.inputContainerRef=t},s("input",{key:"bf8ceea9dec20c699feb879a6b002006763ca281",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.toString(),onBlur:this.handleInputBlur,onChange:this.handleInputChange,"aria-describedby":this.errorState?`${this.id}-error`:void 0,"aria-invalid":this.errorState}),!this.inline&&s("button",{key:"aa1ab4ccac43e28b4dd3e9b2eee4913bba683849",type:"button",onClick:this.handleCalendarButtonClick,class:this.getClassName("calendar-button"),disabled:this.disabledState,"aria-label":this.calendarButtonContent?this.timesLabels.openCalendar:void 0},this.calendarButtonContent?s("span",{innerHTML:this.calendarButtonContent}):this.timesLabels.openCalendar)),s("tabworthy-dates-modal",{key:"15beb881dc3781674cc29a8498a4a9364c39267c",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},s("div",{key:"02a70b2008e2027c3c69e4fbe0ba0c6a673a8f4c",class:this.getClassName("picker-container")},s("tabworthy-dates-calendar",{key:"84c959f8485472139a576ac74365877431be78f0",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},s("div",{key:"0494b0e142b36320c2932827a844b583390a775c",slot:"after-calendar",class:this.getClassName("time-section")},s("hr",{key:"7d10d1832bb1d414fc76fd17cdaafe4f3ca96c5d",class:this.getClassName("divider")}),s("tabworthy-times-picker",{key:"ff0c9d27e52d90038dbdfcacb02fb14911ec53a6",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&&s("div",{key:"af0c35a6eaf1cef0d182c911c1d3a2b0bc08d56b",class:this.getClassName("input-error"),id:this.id?`${this.id}-error`:void 0,role:"status"},this.errorMessage))}get el(){return e(this)}static get watchers(){return{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}}};export{b as tabworthy_times}
@@ -1 +1 @@
1
- import{p as t,b as e}from"./p-CwtZ_Lud.js";export{s as setNonce}from"./p-CwtZ_Lud.js";import{g as n}from"./p-DQuL1Twl.js";(()=>{const e=import.meta.url,n={};return""!==e&&(n.resourcesUrl=new URL(".",e).href),t(n)})().then((async t=>(await n(),e([["p-69334c34",[[2,"tabworthy-times-picker",{hours:[1026],minutes:[1026],seconds:[1026],useTwelveHourFormat:[4,"use-twelve-hour-format"],showSeconds:[4,"show-seconds"],labels:[16],labelsSrOnly:[4,"labels-sr-only"],disabled:[4],elementClassName:[1,"element-class-name"],minTime:[16],maxTime:[16],internalHours:[32],internalMinutes:[32],internalSeconds:[32],period:[32]},null,{hours:[{watchHours:0}],minutes:[{watchMinutes:0}],seconds:[{watchSeconds:0}]}]]],["p-7cd6ccc1",[[262,"tabworthy-dates-calendar",{clearButtonContent:[1,"clear-button-content"],closeButtonContent:[1,"close-button-content"],disabled:[4],modalIsOpen:[4,"modal-is-open"],disableDate:[16],elementClassName:[1,"element-class-name"],firstDayOfWeek:[2,"first-day-of-week"],range:[4],labels:[16],locale:[1],nextMonthButtonContent:[1,"next-month-button-content"],nextYearButtonContent:[1,"next-year-button-content"],previousMonthButtonContent:[1,"previous-month-button-content"],previousYearButtonContent:[1,"previous-year-button-content"],minDate:[1,"min-date"],maxDate:[1,"max-date"],inline:[4],showClearButton:[4,"show-clear-button"],showCloseButton:[4,"show-close-button"],showMonthStepper:[4,"show-month-stepper"],showTodayButton:[4,"show-today-button"],showYearStepper:[4,"show-year-stepper"],showKeyboardHint:[4,"show-keyboard-hint"],showHiddenTitle:[4,"show-hidden-title"],startDate:[1,"start-date"],todayButtonContent:[1,"today-button-content"],value:[1040],currentDate:[32],hoveredDate:[32],weekdays:[32]},null,{modalIsOpen:[{watchModalIsOpen:0}],firstDayOfWeek:[{watchFirstDayOfWeek:0}],locale:[{watchLocale:0}],range:[{watchRange:0}],startDate:[{watchStartDate:0}],value:[{watchValue:0}]}],[257,"tabworthy-dates-modal",{label:[1],inline:[4],placement:[1],offset:[16],appendTo:[1,"append-to"],closing:[32],showing:[32],positioned:[32],open:[64],close:[64],getState:[64],setTriggerElement:[64],updatePosition:[64]},[[10,"click","handleClick"]],{showing:[{watchShowing:0}]}]]],["p-792d275e",[[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],revertInput:[64],clearValue:[64]},null,{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}]]],["p-af49d0fc",[[2,"tabworthy-dates",{id:[513],value:[1025],range:[4],yearOnly:[4,"year-only"],label:[1],placeholder:[1],locale:[1],disabled:[4],minDate:[1,"min-date"],maxDate:[1,"max-date"],startDate:[1,"start-date"],referenceDate:[1,"reference-date"],useStrictDateParsing:[4,"use-strict-date-parsing"],datesLabels:[16],datesCalendarLabels:[16],inline:[4],hasError:[1028,"has-error"],nextMonthButtonContent:[1,"next-month-button-content"],nextYearButtonContent:[1,"next-year-button-content"],previousMonthButtonContent:[1,"previous-month-button-content"],previousYearButtonContent:[1,"previous-year-button-content"],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"],inputShouldFormat:[8,"input-should-format"],showKeyboardHint:[4,"show-keyboard-hint"],disableDate:[16],elementClassName:[1,"element-class-name"],firstDayOfWeek:[2,"first-day-of-week"],format:[1],quickButtons:[16],todayButtonContent:[1,"today-button-content"],clearButtonContent:[1,"clear-button-content"],closeButtonContent:[1,"close-button-content"],calendarButtonContent:[1,"calendar-button-content"],showQuickButtons:[4,"show-quick-buttons"],disableFreeformInput:[4,"disable-freeform-input"],inputClass:[1,"input-class"],appendTo:[1,"append-to"],internalValue:[32],errorState:[32],disabledState:[32],parseDate:[64],revertInput:[64]},null,{disabled:[{watchDisabled:0}],value:[{watchValue:0}]}]]]],t))));
1
+ import{p as t,b as e}from"./p-CwtZ_Lud.js";export{s as setNonce}from"./p-CwtZ_Lud.js";import{g as n}from"./p-DQuL1Twl.js";(()=>{const e=import.meta.url,n={};return""!==e&&(n.resourcesUrl=new URL(".",e).href),t(n)})().then((async t=>(await n(),e([["p-69334c34",[[2,"tabworthy-times-picker",{hours:[1026],minutes:[1026],seconds:[1026],useTwelveHourFormat:[4,"use-twelve-hour-format"],showSeconds:[4,"show-seconds"],labels:[16],labelsSrOnly:[4,"labels-sr-only"],disabled:[4],elementClassName:[1,"element-class-name"],minTime:[16],maxTime:[16],internalHours:[32],internalMinutes:[32],internalSeconds:[32],period:[32]},null,{hours:[{watchHours:0}],minutes:[{watchMinutes:0}],seconds:[{watchSeconds:0}]}]]],["p-7cd6ccc1",[[262,"tabworthy-dates-calendar",{clearButtonContent:[1,"clear-button-content"],closeButtonContent:[1,"close-button-content"],disabled:[4],modalIsOpen:[4,"modal-is-open"],disableDate:[16],elementClassName:[1,"element-class-name"],firstDayOfWeek:[2,"first-day-of-week"],range:[4],labels:[16],locale:[1],nextMonthButtonContent:[1,"next-month-button-content"],nextYearButtonContent:[1,"next-year-button-content"],previousMonthButtonContent:[1,"previous-month-button-content"],previousYearButtonContent:[1,"previous-year-button-content"],minDate:[1,"min-date"],maxDate:[1,"max-date"],inline:[4],showClearButton:[4,"show-clear-button"],showCloseButton:[4,"show-close-button"],showMonthStepper:[4,"show-month-stepper"],showTodayButton:[4,"show-today-button"],showYearStepper:[4,"show-year-stepper"],showKeyboardHint:[4,"show-keyboard-hint"],showHiddenTitle:[4,"show-hidden-title"],startDate:[1,"start-date"],todayButtonContent:[1,"today-button-content"],value:[1040],currentDate:[32],hoveredDate:[32],weekdays:[32]},null,{modalIsOpen:[{watchModalIsOpen:0}],firstDayOfWeek:[{watchFirstDayOfWeek:0}],locale:[{watchLocale:0}],range:[{watchRange:0}],startDate:[{watchStartDate:0}],value:[{watchValue:0}]}],[257,"tabworthy-dates-modal",{label:[1],inline:[4],placement:[1],offset:[16],appendTo:[1,"append-to"],closing:[32],showing:[32],positioned:[32],open:[64],close:[64],getState:[64],setTriggerElement:[64],updatePosition:[64]},[[10,"click","handleClick"]],{showing:[{watchShowing:0}]}]]],["p-2c444b5b",[[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],revertInput:[64],clearValue:[64]},null,{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}]]],["p-af49d0fc",[[2,"tabworthy-dates",{id:[513],value:[1025],range:[4],yearOnly:[4,"year-only"],label:[1],placeholder:[1],locale:[1],disabled:[4],minDate:[1,"min-date"],maxDate:[1,"max-date"],startDate:[1,"start-date"],referenceDate:[1,"reference-date"],useStrictDateParsing:[4,"use-strict-date-parsing"],datesLabels:[16],datesCalendarLabels:[16],inline:[4],hasError:[1028,"has-error"],nextMonthButtonContent:[1,"next-month-button-content"],nextYearButtonContent:[1,"next-year-button-content"],previousMonthButtonContent:[1,"previous-month-button-content"],previousYearButtonContent:[1,"previous-year-button-content"],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"],inputShouldFormat:[8,"input-should-format"],showKeyboardHint:[4,"show-keyboard-hint"],disableDate:[16],elementClassName:[1,"element-class-name"],firstDayOfWeek:[2,"first-day-of-week"],format:[1],quickButtons:[16],todayButtonContent:[1,"today-button-content"],clearButtonContent:[1,"clear-button-content"],closeButtonContent:[1,"close-button-content"],calendarButtonContent:[1,"calendar-button-content"],showQuickButtons:[4,"show-quick-buttons"],disableFreeformInput:[4,"disable-freeform-input"],inputClass:[1,"input-class"],appendTo:[1,"append-to"],internalValue:[32],errorState:[32],disabledState:[32],parseDate:[64],revertInput:[64]},null,{disabled:[{watchDisabled:0}],value:[{watchValue:0}]}]]]],t))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tabworthy/components",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Small, accessible datepicker and datetimepicker Web Components with natural language date input.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- import{r as t,c as i,h as s,H as h,g as e}from"./p-CwtZ_Lud.js";import{g as a,d as n,c as r}from"./p-DkyM-7xr.js";import{g as o,r as d}from"./p-CoFOnMSw.js";var c,l,u={exports:{}},f=a(c?u.exports:(c=1,u.exports=(l={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"},function(t,i,s){var h=i.prototype,e=h.format;s.en.formats=l,h.format=function(t){void 0===t&&(t="YYYY-MM-DDTHH:mm:ssZ");var i=this.$locale().formats,s=function(t,i){return t.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(t,s,h){var e=h&&h.toUpperCase();return s||i[h]||l[h]||i[e].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,i,s){return i||s.slice(1)}))}))}(t,void 0===i?{}:i);return e.call(this,s)}})));n.extend(r),n.extend(f);const m={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"},b=class{constructor(s){t(this,s),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=o(new Date),this.referenceDate=o(new Date),this.useTwelveHourFormat=!0,this.showSeconds=!1,this.timesLabels=m,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 i=t.split(",");if(this.range&&2===i.length){const t=d(new Date(i[0])),s=d(new Date(i[1]));if(!this.isDateValid(t)||!this.isDateValid(s))return;this.updateValue([t,s]),this.pickerRef&&(this.pickerRef.value=[t,s])}else{const t=d(new Date(i[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 i=t.target.value;if(0===i.length)return this.errorState=!1,this.internalValue="",this.pickerRef&&(this.pickerRef.value=null),this.value=this.internalValue,this.selectDateTime.emit(this.internalValue);let s=n(i,this.format,!0);if(s.isValid()||(s=n(i)),s.isValid()){if(this.minDate&&s.isBefore(n(this.minDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,void this.emitErrorChange("minDate",this.errorMessage);if(this.maxDate&&s.isAfter(n(this.maxDate)))return this.errorState=!0,this.errorMessage=`${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`,void this.emitErrorChange("maxDate",this.errorMessage);if(this.disableDate(s.toDate()))return this.errorState=!0,this.errorMessage=this.timesLabels.disabledDateError,void this.emitErrorChange("disabledDate",this.errorMessage);this.errorState=!1,this.selectedHours=s.hour(),this.selectedMinutes=s.minute(),this.selectedSeconds=s.second(),this.updateValue(s.toDate())}else this.errorState=!0,this.errorMessage=this.timesLabels.invalidDateError,this.emitErrorChange("invalid",this.errorMessage)}}emitErrorChange(t,i){this.errorChange.emit({reason:t,message:i})}formatBoundaryDate(t){const i=n(t);if(!i.isValid())return t;if(!t.includes("T")&&!t.includes(" "))return Intl.DateTimeFormat(this.locale,{day:"numeric",month:"short",year:"numeric"}).format(i.toDate());const s=Object.assign({day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"numeric"},this.showSeconds?{second:"numeric"}:{});return Intl.DateTimeFormat(this.locale,s).format(i.toDate())}getEffectiveMinTime(){if(!this.minDate||!this.selectedDate)return;const t=n(this.minDate),i=n(this.selectedDate);return t.isValid()&&i.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}getEffectiveMaxTime(){if(!this.maxDate||!this.selectedDate)return;const t=n(this.maxDate),i=n(this.selectedDate);return t.isValid()&&i.isSame(t,"day")?{hours:t.hour(),minutes:t.minute(),seconds:t.second()}:void 0}isDateOutOfBounds(){if(!this.selectedDate)return!1;const t=n(this.selectedDate);return!(!this.minDate||!t.isBefore(n(this.minDate),"day"))||!(!this.maxDate||!t.isAfter(n(this.maxDate),"day"))}clampTimeToBounds(t){const i=n(t);if(this.minDate){const t=n(this.minDate);t.isValid()&&i.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=n(this.maxDate);t.isValid()&&i.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 i=n(t,this.format);i.isValid()&&(this.selectedDate=i.toDate(),this.selectedHours=i.hour(),this.selectedMinutes=i.minute(),this.selectedSeconds=i.second())}}else this.internalValue=null}updateValue(t){if(Array.isArray(t)){const i=t.map((t=>n(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format)));this.internalValue=i,this.value=i,this.selectDateTime.emit(i)}else{const i=n(t).hour(this.selectedHours).minute(this.selectedMinutes).second(this.selectedSeconds).format(this.format);this.internalValue=i,this.value=i,this.selectedDate=t,this.selectDateTime.emit(i)}this.errorState=!1,this.shouldInputFormat()&&this.formatInput()}isDateValid(t){const i=n(t);return!(!i.isValid()||(this.minDate&&i.isBefore(n(this.minDate),"day")?(this.errorState=!0,this.errorMessage=`${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`,this.emitErrorChange("minDate",this.errorMessage),1):this.maxDate&&i.isAfter(n(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=>n(t,this.format).format("lll"))).join(` ${this.timesLabels.to} `);this.inputRef.value=t}else this.inputRef.value=n(this.internalValue,this.format).format("lll")}getClassName(t){return`${this.elementClassName}__${t}`}toDate(t){return t?Array.isArray(t)?t.map((t=>n(t,this.format).toDate())):n(t,this.format).toDate():null}async revertInput(t,i=!1){i&&(this.errorState=!1),this.value=t,this.syncFromValueProp()}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 s(h,{key:"315801393d1528c6e6ba98b9e1c51187e40f62f5",class:this.elementClassName,"has-error":this.errorState,disabled:this.disabledState},s("label",{key:"c0ff6094ad4f9a2c12c1f041cd75996a792f2b1c",htmlFor:`${this.id}-input`,class:this.getClassName("label")},this.label),s("div",{key:"ede6bcbbd1874acc47360facc5220a0b7fef358c",class:this.getClassName("input-container"),ref:t=>this.inputContainerRef=t},s("input",{key:"4dcbd71cdd54fca3bb3ae26d4982c49fa32db8d6",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.toString(),onBlur:this.handleInputBlur,onChange:this.handleInputChange,"aria-describedby":this.errorState?`${this.id}-error`:void 0,"aria-invalid":this.errorState}),!this.inline&&s("button",{key:"f486c98770077cd7ff39d2a56cafaf3d8c80a36c",type:"button",onClick:this.handleCalendarButtonClick,class:this.getClassName("calendar-button"),disabled:this.disabledState,"aria-label":this.calendarButtonContent?this.timesLabels.openCalendar:void 0},this.calendarButtonContent?s("span",{innerHTML:this.calendarButtonContent}):this.timesLabels.openCalendar)),s("tabworthy-dates-modal",{key:"b1cd3cbcea01f7147fe33abf11d62d35c50cbdb6",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},s("div",{key:"cec6685037168dd633037a6d723823572d9db5e5",class:this.getClassName("picker-container")},s("tabworthy-dates-calendar",{key:"0dec8076bb3aee853979d6de95bd07a7095b717a",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},s("div",{key:"f69a1b84ebceaf5d0c359190bec9ae11189d75e0",slot:"after-calendar",class:this.getClassName("time-section")},s("hr",{key:"6b9e5ae7c1f5aaa447da7b1b393c9bd75043dac2",class:this.getClassName("divider")}),s("tabworthy-times-picker",{key:"406f5ac12c09d0fddc0ebe3330961b783c2d7366",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&&s("div",{key:"ddc92f2c8d936a3a38f61d841860b17cd9c06283",class:this.getClassName("input-error"),id:this.id?`${this.id}-error`:void 0,role:"status"},this.errorMessage))}get el(){return e(this)}static get watchers(){return{value:[{watchValue:0}],disabled:[{watchDisabled:0}],hasError:[{watchHasError:0}]}}};export{b as tabworthy_times}