@tabworthy/components 0.12.4 → 0.13.0

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.
Files changed (44) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/tabworthy-components.cjs.js +1 -1
  3. package/dist/cjs/tabworthy-dates-calendar_2.cjs.entry.js +35 -17
  4. package/dist/cjs/tabworthy-dates.cjs.entry.js +48 -10
  5. package/dist/cjs/tabworthy-times-picker.cjs.entry.js +82 -10
  6. package/dist/cjs/tabworthy-times.cjs.entry.js +108 -5
  7. package/dist/cjs/{utils-y5Vtky2t.js → utils-DGbdK8VF.js} +29 -8
  8. package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +68 -10
  9. package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +35 -17
  10. package/dist/collection/components/tabworthy-times/tabworthy-times.js +128 -4
  11. package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +128 -10
  12. package/dist/components/p-BzY8iIVW.js +1 -0
  13. package/dist/components/p-C_uZGgcG.js +1 -0
  14. package/dist/components/tabworthy-dates-calendar.js +1 -1
  15. package/dist/components/tabworthy-dates.js +1 -1
  16. package/dist/components/tabworthy-times-picker.js +1 -1
  17. package/dist/components/tabworthy-times.js +1 -1
  18. package/dist/esm/loader.js +1 -1
  19. package/dist/esm/tabworthy-components.js +1 -1
  20. package/dist/esm/tabworthy-dates-calendar_2.entry.js +35 -17
  21. package/dist/esm/tabworthy-dates.entry.js +48 -10
  22. package/dist/esm/tabworthy-times-picker.entry.js +82 -10
  23. package/dist/esm/tabworthy-times.entry.js +108 -5
  24. package/dist/esm/{utils-BVHu5CWV.js → utils-CoFOnMSw.js} +29 -9
  25. package/dist/shared/utils/utils.js +28 -8
  26. package/dist/tabworthy-components/p-69334c34.entry.js +1 -0
  27. package/dist/tabworthy-components/p-71f5c261.entry.js +1 -0
  28. package/dist/tabworthy-components/p-7cd6ccc1.entry.js +1 -0
  29. package/dist/tabworthy-components/{p-BVHu5CWV.js → p-CoFOnMSw.js} +1 -1
  30. package/dist/tabworthy-components/p-ed3c60d6.entry.js +1 -0
  31. package/dist/tabworthy-components/tabworthy-components.esm.js +1 -1
  32. package/dist/themes/light.css +1 -1
  33. package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +7 -0
  34. package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +8 -1
  35. package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +15 -0
  36. package/dist/types/components.d.ts +14 -4
  37. package/dist/types/home/runner/work/tabworthy-components/tabworthy-components/.stencil/shared/utils/utils.d.ts +6 -0
  38. package/package.json +1 -1
  39. package/dist/components/p-BTQaxOHo.js +0 -1
  40. package/dist/components/p-DAc3jaFB.js +0 -1
  41. package/dist/tabworthy-components/p-1743bf7a.entry.js +0 -1
  42. package/dist/tabworthy-components/p-28192b55.entry.js +0 -1
  43. package/dist/tabworthy-components/p-3b548ae1.entry.js +0 -1
  44. package/dist/tabworthy-components/p-626a5c0b.entry.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-CwtZ_Lud.js';
2
2
  import { g as getDefaultExportFromCjs, d as dayjs, c as customParseFormat } from './customParseFormat-DkyM-7xr.js';
3
- import { g as getISODateString, r as removeTimezoneOffset } from './utils-BVHu5CWV.js';
3
+ import { g as getISODateString, r as removeTimezoneOffset } from './utils-CoFOnMSw.js';
4
4
 
5
5
  var localizedFormat$2 = {exports: {}};
6
6
 
@@ -40,6 +40,7 @@ const TabworthyTimes = class {
40
40
  registerInstance(this, hostRef);
41
41
  this.selectDateTime = createEvent(this, "selectDateTime", 7);
42
42
  this.changeYear = createEvent(this, "changeYear", 7);
43
+ this.errorChange = createEvent(this, "errorChange", 7);
43
44
  this.componentReady = createEvent(this, "componentReady", 7);
44
45
  // Enable or disable range mode
45
46
  this.range = false;
@@ -101,6 +102,8 @@ const TabworthyTimes = class {
101
102
  if (this.range && dates.length === 2) {
102
103
  const startDate = removeTimezoneOffset(new Date(dates[0]));
103
104
  const endDate = removeTimezoneOffset(new Date(dates[1]));
105
+ if (!this.isDateValid(startDate) || !this.isDateValid(endDate))
106
+ return;
104
107
  this.updateValue([startDate, endDate]);
105
108
  // Update calendar with selected dates
106
109
  if (this.pickerRef) {
@@ -109,6 +112,8 @@ const TabworthyTimes = class {
109
112
  }
110
113
  else {
111
114
  const date = removeTimezoneOffset(new Date(dates[0]));
115
+ if (!this.isDateValid(date))
116
+ return;
112
117
  this.updateValue(date);
113
118
  // Update calendar with selected date
114
119
  if (this.pickerRef) {
@@ -167,6 +172,25 @@ const TabworthyTimes = class {
167
172
  parsed = dayjs(value);
168
173
  }
169
174
  if (parsed.isValid()) {
175
+ // Check minDate/maxDate bounds (supports both date-only and datetime strings)
176
+ if (this.minDate && parsed.isBefore(dayjs(this.minDate))) {
177
+ this.errorState = true;
178
+ this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
179
+ this.emitErrorChange("minDate", this.errorMessage);
180
+ return;
181
+ }
182
+ if (this.maxDate && parsed.isAfter(dayjs(this.maxDate))) {
183
+ this.errorState = true;
184
+ this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
185
+ this.emitErrorChange("maxDate", this.errorMessage);
186
+ return;
187
+ }
188
+ if (this.disableDate(parsed.toDate())) {
189
+ this.errorState = true;
190
+ this.errorMessage = this.timesLabels.disabledDateError;
191
+ this.emitErrorChange("disabledDate", this.errorMessage);
192
+ return;
193
+ }
170
194
  this.errorState = false;
171
195
  this.selectedHours = parsed.hour();
172
196
  this.selectedMinutes = parsed.minute();
@@ -177,9 +201,64 @@ const TabworthyTimes = class {
177
201
  // Set error state for invalid/garbage input
178
202
  this.errorState = true;
179
203
  this.errorMessage = this.timesLabels.invalidDateError;
204
+ this.emitErrorChange("invalid", this.errorMessage);
180
205
  }
181
206
  };
182
207
  }
208
+ emitErrorChange(reason, message) {
209
+ this.errorChange.emit({ reason, message });
210
+ }
211
+ formatBoundaryDate(dateString) {
212
+ const parsed = dayjs(dateString);
213
+ if (!parsed.isValid())
214
+ return dateString;
215
+ const hasTime = dateString.includes("T") || dateString.includes(" ");
216
+ if (!hasTime) {
217
+ return Intl.DateTimeFormat(this.locale, {
218
+ day: "numeric",
219
+ month: "short",
220
+ year: "numeric"
221
+ }).format(parsed.toDate());
222
+ }
223
+ const options = Object.assign({ day: "numeric", month: "short", year: "numeric", hour: "numeric", minute: "numeric" }, (this.showSeconds ? { second: "numeric" } : {}));
224
+ return Intl.DateTimeFormat(this.locale, options).format(parsed.toDate());
225
+ }
226
+ getEffectiveMinTime() {
227
+ if (!this.minDate || !this.selectedDate)
228
+ return undefined;
229
+ const min = dayjs(this.minDate);
230
+ const sel = dayjs(this.selectedDate);
231
+ if (!min.isValid() || !sel.isSame(min, "day"))
232
+ return undefined;
233
+ return {
234
+ hours: min.hour(),
235
+ minutes: min.minute(),
236
+ seconds: min.second()
237
+ };
238
+ }
239
+ getEffectiveMaxTime() {
240
+ if (!this.maxDate || !this.selectedDate)
241
+ return undefined;
242
+ const max = dayjs(this.maxDate);
243
+ const sel = dayjs(this.selectedDate);
244
+ if (!max.isValid() || !sel.isSame(max, "day"))
245
+ return undefined;
246
+ return {
247
+ hours: max.hour(),
248
+ minutes: max.minute(),
249
+ seconds: max.second()
250
+ };
251
+ }
252
+ isDateOutOfBounds() {
253
+ if (!this.selectedDate)
254
+ return false;
255
+ const sel = dayjs(this.selectedDate);
256
+ if (this.minDate && sel.isBefore(dayjs(this.minDate), "day"))
257
+ return true;
258
+ if (this.maxDate && sel.isAfter(dayjs(this.maxDate), "day"))
259
+ return true;
260
+ return false;
261
+ }
183
262
  shouldInputFormat() {
184
263
  if (typeof this.inputShouldFormat === "string") {
185
264
  return this.inputShouldFormat === "true";
@@ -252,6 +331,30 @@ const TabworthyTimes = class {
252
331
  this.formatInput();
253
332
  }
254
333
  }
334
+ isDateValid(date) {
335
+ const parsed = dayjs(date);
336
+ if (!parsed.isValid())
337
+ return false;
338
+ if (this.minDate && parsed.isBefore(dayjs(this.minDate))) {
339
+ this.errorState = true;
340
+ this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
341
+ this.emitErrorChange("minDate", this.errorMessage);
342
+ return false;
343
+ }
344
+ if (this.maxDate && parsed.isAfter(dayjs(this.maxDate))) {
345
+ this.errorState = true;
346
+ this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
347
+ this.emitErrorChange("maxDate", this.errorMessage);
348
+ return false;
349
+ }
350
+ if (this.disableDate(date)) {
351
+ this.errorState = true;
352
+ this.errorMessage = this.timesLabels.disabledDateError;
353
+ this.emitErrorChange("disabledDate", this.errorMessage);
354
+ return false;
355
+ }
356
+ return true;
357
+ }
255
358
  formatInput() {
256
359
  if (!this.internalValue)
257
360
  return;
@@ -292,12 +395,12 @@ const TabworthyTimes = class {
292
395
  }
293
396
  render() {
294
397
  var _a;
295
- return (h(Host, { key: 'e07a561aa76dedbf8f8e28c491b3aac19f45c472', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: '24e11901760a8c7f989f3d33df9cd58af899a8dc', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '17c4a53c621b66e62f857d49b4b8f4b52d51183d', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: '7dd776e464533c7bb6c842a0332f0d667f52c7cc', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
398
+ return (h(Host, { key: 'd258bd87c60aa773bd178e1e74eeb32934d8f068', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: '5e7a53cb36c350794af9fed2371c89823726ee2f', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '986905f117271cfb82a1f8415d55536a590ac2bc', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: '9ad436c1e0c8a427c1665db16913cddf93d94fed', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
296
399
  [this.getClassName("input")]: true,
297
400
  [this.inputClass]: !!this.inputClass
298
- }, 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: '0e84b4e3ae7f5abe1a59e939cccc227bf34ab992', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
401
+ }, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { key: 'd537e6f3251bada7ad50bbe1ca2c562737205897', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
299
402
  ? this.timesLabels.openCalendar
300
- : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: 'baebeeeda4200bf13fe8f023bb39e2c13fc58b0b', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
403
+ : undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '241700195e1d028f8d8b6b55af7de3aee09163ea', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
301
404
  if (this.pickerRef) {
302
405
  this.pickerRef.modalIsOpen = true;
303
406
  }
@@ -305,7 +408,7 @@ const TabworthyTimes = class {
305
408
  if (this.pickerRef) {
306
409
  this.pickerRef.modalIsOpen = false;
307
410
  }
308
- }, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '0fc94282af5f36ae9214e967dab2acac911bca14', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '4b0ef9c95058398d759fe913b22a84d5f22bd383', 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: 'b766d90c7bb4732c6ae26cadeb610a6e0c10a597', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: 'f98fc31d11a3bdd999a5dc0cc15bf1921f349b9b', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: 'cfe86bb9291d1a14d37ab7240ec2f2f7f9bece4d', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState, onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels }))))), this.errorState && (h("div", { key: '1c2d4b6469266b894402512612a71721acf28f7e', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
411
+ }, inline: this.inline, appendTo: this.appendTo }, h("div", { key: 'b99aa129e4d1d600971bc4d21b2c6a4316ff64cf', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: '6ac11c01936e2155c023d286d912ba87e0ed3415', 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: '7eead2c25334abce43fe7371436a52b0970e648b', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '06ac45a5eaaaa56d39825f941b0951f99c4b28e9', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: 'ba4187a2a369cff58ca0ecf3a60abfeff3ba9ca3', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime() }))))), this.errorState && (h("div", { key: 'c187d0bd982a5184aa796ffe8be4ed91c340230d', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
309
412
  }
310
413
  get el() { return getElement(this); }
311
414
  static get watchers() { return {
@@ -136,6 +136,17 @@ function removeTimezoneOffset(date) {
136
136
  newDate.setMinutes(newDate.getMinutes() + newDate.getTimezoneOffset());
137
137
  return newDate;
138
138
  }
139
+ /**
140
+ * Parse a date boundary string to a local Date.
141
+ * Date-only strings ("YYYY-MM-DD") are parsed as UTC by JS, so we apply removeTimezoneOffset.
142
+ * Datetime strings (containing "T" or space+time) are already parsed as local time.
143
+ */
144
+ function parseDateString(dateString) {
145
+ const hasTime = dateString.includes("T") ||
146
+ /\d{4}-\d{2}-\d{2}\s\d{2}:/.test(dateString);
147
+ const parsed = new Date(dateString);
148
+ return hasTime ? parsed : removeTimezoneOffset(parsed);
149
+ }
139
150
  function subDays(date, days) {
140
151
  const newDate = new Date(date);
141
152
  newDate.setDate(newDate.getDate() - days);
@@ -143,7 +154,7 @@ function subDays(date, days) {
143
154
  }
144
155
  function dateIsWithinLowerBounds(date, minDate) {
145
156
  if (minDate) {
146
- const min = removeTimezoneOffset(new Date(minDate));
157
+ const min = parseDateString(minDate);
147
158
  return date >= min || isSameDay(min, date);
148
159
  }
149
160
  else
@@ -151,7 +162,7 @@ function dateIsWithinLowerBounds(date, minDate) {
151
162
  }
152
163
  function dateIsWithinUpperBounds(date, maxDate) {
153
164
  if (maxDate) {
154
- const max = removeTimezoneOffset(new Date(maxDate));
165
+ const max = parseDateString(maxDate);
155
166
  return date <= max || isSameDay(date, max);
156
167
  }
157
168
  else
@@ -162,12 +173,21 @@ function dateIsWithinBounds(date, minDate, maxDate) {
162
173
  dateIsWithinUpperBounds(date, maxDate));
163
174
  }
164
175
  function monthIsDisabled(month, year, minDate, maxDate) {
165
- const firstDate = new Date(year, month, 1);
166
- firstDate.setDate(firstDate.getDate() - 1);
167
- const lastDate = new Date(year, month + 1, 0);
168
- lastDate.setDate(firstDate.getDate() + 1);
169
- return (!dateIsWithinBounds(firstDate, minDate, maxDate) &&
170
- !dateIsWithinBounds(lastDate, minDate, maxDate));
176
+ if (minDate) {
177
+ const min = parseDateString(minDate);
178
+ const minYear = min.getFullYear();
179
+ const minMonth = min.getMonth();
180
+ if (year < minYear || (year === minYear && month < minMonth))
181
+ return true;
182
+ }
183
+ if (maxDate) {
184
+ const max = parseDateString(maxDate);
185
+ const maxYear = max.getFullYear();
186
+ const maxMonth = max.getMonth();
187
+ if (year > maxYear || (year === maxYear && month > maxMonth))
188
+ return true;
189
+ }
190
+ return false;
171
191
  }
172
192
  function isValidISODate(dateString) {
173
193
  var isoFormat = /^\d{4}-\d{2}-\d{2}$/;
@@ -185,4 +205,4 @@ function extractDates(text) {
185
205
  return matches === null || matches === void 0 ? void 0 : matches.slice(0, 2);
186
206
  }
187
207
 
188
- export { getNextMonth as a, getNextYear as b, getPreviousMonth as c, getPreviousYear as d, dateIsWithinBounds as e, getPreviousDay as f, getISODateString as g, getNextDay as h, addDays as i, getFirstOfMonth as j, getLastOfMonth as k, getWeekDays as l, getDaysOfMonth as m, dateIsWithinLowerBounds as n, dateIsWithinUpperBounds as o, getYear as p, getMonth as q, removeTimezoneOffset as r, subDays as s, monthIsDisabled as t, getMonths as u, isSameDay as v, isDateInRange as w, extractDates as x, isValidISODate as y };
208
+ export { getNextMonth as a, getNextYear as b, getPreviousMonth as c, getPreviousYear as d, dateIsWithinBounds as e, getPreviousDay as f, getISODateString as g, getNextDay as h, addDays as i, getFirstOfMonth as j, getLastOfMonth as k, getWeekDays as l, monthIsDisabled as m, getDaysOfMonth as n, dateIsWithinLowerBounds as o, parseDateString as p, dateIsWithinUpperBounds as q, removeTimezoneOffset as r, subDays as s, getYear as t, getMonth as u, getMonths as v, isSameDay as w, isDateInRange as x, extractDates as y, isValidISODate as z };
@@ -136,6 +136,17 @@ export function removeTimezoneOffset(date) {
136
136
  newDate.setMinutes(newDate.getMinutes() + newDate.getTimezoneOffset());
137
137
  return newDate;
138
138
  }
139
+ /**
140
+ * Parse a date boundary string to a local Date.
141
+ * Date-only strings ("YYYY-MM-DD") are parsed as UTC by JS, so we apply removeTimezoneOffset.
142
+ * Datetime strings (containing "T" or space+time) are already parsed as local time.
143
+ */
144
+ export function parseDateString(dateString) {
145
+ const hasTime = dateString.includes("T") ||
146
+ /\d{4}-\d{2}-\d{2}\s\d{2}:/.test(dateString);
147
+ const parsed = new Date(dateString);
148
+ return hasTime ? parsed : removeTimezoneOffset(parsed);
149
+ }
139
150
  export function subDays(date, days) {
140
151
  const newDate = new Date(date);
141
152
  newDate.setDate(newDate.getDate() - days);
@@ -143,7 +154,7 @@ export function subDays(date, days) {
143
154
  }
144
155
  export function dateIsWithinLowerBounds(date, minDate) {
145
156
  if (minDate) {
146
- const min = removeTimezoneOffset(new Date(minDate));
157
+ const min = parseDateString(minDate);
147
158
  return date >= min || isSameDay(min, date);
148
159
  }
149
160
  else
@@ -151,7 +162,7 @@ export function dateIsWithinLowerBounds(date, minDate) {
151
162
  }
152
163
  export function dateIsWithinUpperBounds(date, maxDate) {
153
164
  if (maxDate) {
154
- const max = removeTimezoneOffset(new Date(maxDate));
165
+ const max = parseDateString(maxDate);
155
166
  return date <= max || isSameDay(date, max);
156
167
  }
157
168
  else
@@ -162,12 +173,21 @@ export function dateIsWithinBounds(date, minDate, maxDate) {
162
173
  dateIsWithinUpperBounds(date, maxDate));
163
174
  }
164
175
  export function monthIsDisabled(month, year, minDate, maxDate) {
165
- const firstDate = new Date(year, month, 1);
166
- firstDate.setDate(firstDate.getDate() - 1);
167
- const lastDate = new Date(year, month + 1, 0);
168
- lastDate.setDate(firstDate.getDate() + 1);
169
- return (!dateIsWithinBounds(firstDate, minDate, maxDate) &&
170
- !dateIsWithinBounds(lastDate, minDate, maxDate));
176
+ if (minDate) {
177
+ const min = parseDateString(minDate);
178
+ const minYear = min.getFullYear();
179
+ const minMonth = min.getMonth();
180
+ if (year < minYear || (year === minYear && month < minMonth))
181
+ return true;
182
+ }
183
+ if (maxDate) {
184
+ const max = parseDateString(maxDate);
185
+ const maxYear = max.getFullYear();
186
+ const maxMonth = max.getMonth();
187
+ if (year > maxYear || (year === maxYear && month > maxMonth))
188
+ return true;
189
+ }
190
+ return false;
171
191
  }
172
192
  export function isValidISODate(dateString) {
173
193
  var isoFormat = /^\d{4}-\d{2}-\d{2}$/;
@@ -0,0 +1 @@
1
+ import{r as t,c as s,h as i,H as e,g as h}from"./p-CwtZ_Lud.js";const a={hours:"Hours",minutes:"Minutes",seconds:"Seconds",am:"AM",pm:"PM",timePicker:"Time picker",incrementHours:"Increment hours",decrementHours:"Decrement hours",incrementMinutes:"Increment minutes",decrementMinutes:"Decrement minutes",incrementSeconds:"Increment seconds",decrementSeconds:"Decrement seconds"},n=class{constructor(i){t(this,i),this.timeChanged=s(this,"timeChanged",7),this.hours=12,this.minutes=0,this.seconds=0,this.useTwelveHourFormat=!1,this.showSeconds=!1,this.labels=a,this.labelsSrOnly=!0,this.disabled=!1,this.elementClassName="tabworthy-times-picker",this.internalHours=this.hours,this.internalMinutes=this.minutes,this.internalSeconds=this.seconds,this.period=this.hours>=12?"PM":"AM",this.handleHourChange=t=>{const s=parseInt(t.target.value,10);isNaN(s)||(this.internalHours=this.useTwelveHourFormat?"AM"===this.period?12===s?0:s:12===s?12:s+12:s,this.emitTimeChange())},this.handleMinuteChange=t=>{const s=parseInt(t.target.value,10);isNaN(s)||(this.internalMinutes=s,this.emitTimeChange())},this.handlePeriodChange=t=>{if(this.period===t||!this.useTwelveHourFormat)return;this.period=t;const s=this.getDisplayHours();this.internalHours="AM"===t?12===s?0:s:12===s?12:s+12,this.emitTimeChange()},this.handleHourIncrement=()=>{if(this.useTwelveHourFormat){const t=this.getDisplayHours(),s=12===t?1:t+1;this.internalHours="AM"===this.period?12===s?0:s:12===s?12:s+12}else this.internalHours=(this.internalHours+1)%24;this.emitTimeChange()},this.handleHourDecrement=()=>{if(this.useTwelveHourFormat){const t=this.getDisplayHours(),s=1===t?12:t-1;this.internalHours="AM"===this.period?12===s?0:s:12===s?12:s+12}else this.internalHours=0===this.internalHours?23:this.internalHours-1;this.emitTimeChange()},this.handleMinuteIncrement=()=>{this.internalMinutes=(this.internalMinutes+1)%60,this.emitTimeChange()},this.handleMinuteDecrement=()=>{this.internalMinutes=0===this.internalMinutes?59:this.internalMinutes-1,this.emitTimeChange()},this.handleSecondChange=t=>{const s=parseInt(t.target.value,10);isNaN(s)||(this.internalSeconds=s,this.emitTimeChange())},this.handleSecondIncrement=()=>{this.internalSeconds=(this.internalSeconds+1)%60,this.emitTimeChange()},this.handleSecondDecrement=()=>{this.internalSeconds=0===this.internalSeconds?59:this.internalSeconds-1,this.emitTimeChange()}}watchHours(t){this.internalHours=t,this.period=t>=12?"PM":"AM"}watchMinutes(t){this.internalMinutes=t}watchSeconds(t){this.internalSeconds=t}componentWillLoad(){this.internalHours=this.hours,this.internalMinutes=this.minutes,this.internalSeconds=this.seconds,this.period=this.hours>=12?"PM":"AM"}getDisplayHours(){return this.useTwelveHourFormat?0===this.internalHours?12:this.internalHours>12?this.internalHours-12:this.internalHours:this.internalHours}get24HourValue(){if(!this.useTwelveHourFormat)return this.internalHours;const t=this.getDisplayHours();return"AM"===this.period?12===t?0:t:12===t?12:t+12}emitTimeChange(){this.clampToBounds(),this.timeChanged.emit({hours:this.get24HourValue(),minutes:this.internalMinutes,seconds:this.showSeconds?this.internalSeconds:void 0,period:this.useTwelveHourFormat?this.period:void 0})}clampToBounds(){var t,s;const i=this.get24HourValue(),e=this.internalMinutes;if(this.minTime){const s=null!==(t=this.minTime.seconds)&&void 0!==t?t:0;(i<this.minTime.hours||i===this.minTime.hours&&e<this.minTime.minutes||i===this.minTime.hours&&e===this.minTime.minutes&&this.internalSeconds<s)&&(this.setInternal24Hours(this.minTime.hours),this.internalMinutes=this.minTime.minutes,this.internalSeconds=s)}if(this.maxTime){const t=null!==(s=this.maxTime.seconds)&&void 0!==s?s:59,i=this.get24HourValue(),e=this.internalMinutes;(i>this.maxTime.hours||i===this.maxTime.hours&&e>this.maxTime.minutes||i===this.maxTime.hours&&e===this.maxTime.minutes&&this.internalSeconds>t)&&(this.setInternal24Hours(this.maxTime.hours),this.internalMinutes=this.maxTime.minutes,this.internalSeconds=t)}}setInternal24Hours(t){this.internalHours=t,this.period=t>=12?"PM":"AM"}isAtMinHour(){return!!this.minTime&&this.get24HourValue()<=this.minTime.hours}isAtMaxHour(){return!!this.maxTime&&this.get24HourValue()>=this.maxTime.hours}isAtMinMinute(){return this.isAtMinHour()&&!!this.minTime&&this.internalMinutes<=this.minTime.minutes}isAtMaxMinute(){return this.isAtMaxHour()&&!!this.maxTime&&this.internalMinutes>=this.maxTime.minutes}isAtMinSecond(){var t;return this.isAtMinMinute()&&!!this.minTime&&this.internalSeconds<=(null!==(t=this.minTime.seconds)&&void 0!==t?t:0)}isAtMaxSecond(){var t;return this.isAtMaxMinute()&&!!this.maxTime&&this.internalSeconds>=(null!==(t=this.maxTime.seconds)&&void 0!==t?t:59)}padZero(t){return t.toString().padStart(2,"0")}render(){const t=this.getDisplayHours(),s=this.useTwelveHourFormat?12:23,h=this.useTwelveHourFormat?1:0;return i(e,{key:"190cabad78886b1902d70c42c6c5b1f4ee90e5fe",class:this.elementClassName,"aria-label":this.labels.timePicker},i("div",{key:"98b3d39baf501aeb9894949e807a365e26253fbc",class:`${this.elementClassName}__container`},i("div",{key:"6697b77b177164a36297f911572d89beaa01cf23",class:`${this.elementClassName}__field`},i("label",{key:"43f6e821b49f19041422741840439081f819f71c",htmlFor:`${this.elementClassName}-hours`,class:{[`${this.elementClassName}__label`]:!0,[`${this.elementClassName}__label--sr-only`]:this.labelsSrOnly}},this.labels.hours),i("div",{key:"a0e177ded2a849c22e41dbca95bad0888f7f956c",class:`${this.elementClassName}__control`},i("button",{key:"b12c268cc84f11ee078ba9285ae6d9cc605761e4",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--increment`,onClick:this.handleHourIncrement,disabled:this.disabled||this.isAtMaxHour(),"aria-label":this.labels.incrementHours},i("svg",{key:"598eff59b528ec28a0e5b34924e77a4f632ba6ca",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},i("polyline",{key:"279b80304fc77a2fd74e26a2aba89f12155f9334",points:"18 15 12 9 6 15"}))),i("input",{key:"93f17e7c848d40bd513ad7af9f29d39586391573",id:`${this.elementClassName}-hours`,type:"number",class:`${this.elementClassName}__input`,value:this.padZero(t),min:h,max:s,onInput:this.handleHourChange,disabled:this.disabled,"aria-label":this.labels.hours}),i("button",{key:"ba8f6463ee850c6349cad839eb851c67e0cb4d1e",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--decrement`,onClick:this.handleHourDecrement,disabled:this.disabled||this.isAtMinHour(),"aria-label":this.labels.decrementHours},i("svg",{key:"21e585fbd6a9aa2b957e817ec55ab2ec01cf2fc4",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},i("polyline",{key:"742b64bddf3873a7bea1c10ed93b9b1e99588ede",points:"6 9 12 15 18 9"}))))),i("div",{key:"f81f40c465cc84a5d02b9904631d3d24e33150e3",class:`${this.elementClassName}__separator`},":"),i("div",{key:"d028bae721c1c9c2cc7290cd19f7050a901f4a4e",class:`${this.elementClassName}__field`},i("label",{key:"3c88a3fa04ed2a65f72c48ded459e19d580f9c36",htmlFor:`${this.elementClassName}-minutes`,class:{[`${this.elementClassName}__label`]:!0,[`${this.elementClassName}__label--sr-only`]:this.labelsSrOnly}},this.labels.minutes),i("div",{key:"dbd89633addd003b2e42414b587d03a6e65e9239",class:`${this.elementClassName}__control`},i("button",{key:"b113074a58889691dd5452a6353b691336f5ae14",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--increment`,onClick:this.handleMinuteIncrement,disabled:this.disabled||this.isAtMaxMinute(),"aria-label":this.labels.incrementMinutes},i("svg",{key:"0d724c0e5110dd29ab4cedc005595d4e57fd3d06",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},i("polyline",{key:"dbc89190f6fe10bb8c8074252b83ab3397112de4",points:"18 15 12 9 6 15"}))),i("input",{key:"65a9a61218d443676a8a2d03d4922b2303a484c5",id:`${this.elementClassName}-minutes`,type:"number",class:`${this.elementClassName}__input`,value:this.padZero(this.internalMinutes),min:0,max:59,onInput:this.handleMinuteChange,disabled:this.disabled,"aria-label":this.labels.minutes}),i("button",{key:"3f72a62add15d9288b421b84e791ba40b9acf569",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--decrement`,onClick:this.handleMinuteDecrement,disabled:this.disabled||this.isAtMinMinute(),"aria-label":this.labels.decrementMinutes},i("svg",{key:"04eef7d1d332459e5191962c411aa9c83ace8b84",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},i("polyline",{key:"56045b19ec716a82f21406b647762ba0efcd8170",points:"6 9 12 15 18 9"}))))),this.showSeconds&&[i("div",{key:"9c2619ccebd147e626e10a21fb1a5fa1268128f3",class:`${this.elementClassName}__separator`},":"),i("div",{key:"dea8135d47a06d9624b480aa6123350a0899ca02",class:`${this.elementClassName}__field`},i("label",{key:"afaa88b59df63091088620ff2a49bf8472f4401f",htmlFor:`${this.elementClassName}-seconds`,class:{[`${this.elementClassName}__label`]:!0,[`${this.elementClassName}__label--sr-only`]:this.labelsSrOnly}},this.labels.seconds),i("div",{key:"c2ed4d63a95a65bdc26926932e705744bbe776c5",class:`${this.elementClassName}__control`},i("button",{key:"40d510ae7008802ce09ec98c9912f2f91cdb2db7",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--increment`,onClick:this.handleSecondIncrement,disabled:this.disabled||this.isAtMaxSecond(),"aria-label":this.labels.incrementSeconds},i("svg",{key:"fd3324d15759c7f2a752b6a32303c8eaddb0e588",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},i("polyline",{key:"5e2dad75d96a521f56f616bc2b88e4baa6c0eb50",points:"18 15 12 9 6 15"}))),i("input",{key:"b1b517bb8147a45632388f432ae0e3595467ebce",id:`${this.elementClassName}-seconds`,type:"number",class:`${this.elementClassName}__input`,value:this.padZero(this.internalSeconds),min:0,max:59,onInput:this.handleSecondChange,disabled:this.disabled,"aria-label":this.labels.seconds}),i("button",{key:"7b82e86f2da4bd5c0f65c95cbcb26252e357625d",type:"button",class:`${this.elementClassName}__button ${this.elementClassName}__button--decrement`,onClick:this.handleSecondDecrement,disabled:this.disabled||this.isAtMinSecond(),"aria-label":this.labels.decrementSeconds},i("svg",{key:"c3b5ae33c5475b448c1a5e7fe3bb4748318441fb",fill:"none",height:"16","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",stroke:"currentColor",viewBox:"0 0 24 24",width:"16"},i("polyline",{key:"3bb717320e078f5fa36912f15995ed604d9f702b",points:"6 9 12 15 18 9"})))))],this.useTwelveHourFormat&&i("div",{key:"ec583890c2f7d97c6a6196f3556dfd76c8209227",class:`${this.elementClassName}__period`},i("button",{key:"e99d9b41ded6b138660f2777f60991bf3af12182",type:"button",class:{[`${this.elementClassName}__period-button`]:!0,[`${this.elementClassName}__period-button--active`]:"AM"===this.period},onClick:()=>this.handlePeriodChange("AM"),disabled:this.disabled,"aria-label":this.labels.am,"aria-pressed":"AM"===this.period},this.labels.am),i("button",{key:"3a3cbc3b47b0218694db2c8909da97ea50e521f2",type:"button",class:{[`${this.elementClassName}__period-button`]:!0,[`${this.elementClassName}__period-button--active`]:"PM"===this.period},onClick:()=>this.handlePeriodChange("PM"),disabled:this.disabled,"aria-label":this.labels.pm,"aria-pressed":"PM"===this.period},this.labels.pm))))}get el(){return h(this)}static get watchers(){return{hours:[{watchHours:0}],minutes:[{watchMinutes:0}],seconds:[{watchSeconds:0}]}}};export{n as tabworthy_times_picker}