@tabworthy/components 0.12.4 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/tabworthy-components.cjs.js +1 -1
- package/dist/cjs/tabworthy-dates-calendar_2.cjs.entry.js +35 -17
- package/dist/cjs/tabworthy-dates.cjs.entry.js +58 -10
- package/dist/cjs/tabworthy-times-picker.cjs.entry.js +82 -10
- package/dist/cjs/tabworthy-times.cjs.entry.js +147 -6
- package/dist/cjs/{utils-y5Vtky2t.js → utils-DGbdK8VF.js} +29 -8
- package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +78 -10
- package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +35 -17
- package/dist/collection/components/tabworthy-times/tabworthy-times.js +167 -5
- package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +128 -10
- package/dist/components/p-BzY8iIVW.js +1 -0
- package/dist/components/p-C_uZGgcG.js +1 -0
- package/dist/components/tabworthy-dates-calendar.js +1 -1
- package/dist/components/tabworthy-dates.js +1 -1
- package/dist/components/tabworthy-times-picker.js +1 -1
- package/dist/components/tabworthy-times.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/tabworthy-components.js +1 -1
- package/dist/esm/tabworthy-dates-calendar_2.entry.js +35 -17
- package/dist/esm/tabworthy-dates.entry.js +58 -10
- package/dist/esm/tabworthy-times-picker.entry.js +82 -10
- package/dist/esm/tabworthy-times.entry.js +147 -6
- package/dist/esm/{utils-BVHu5CWV.js → utils-CoFOnMSw.js} +29 -9
- package/dist/shared/utils/utils.js +28 -8
- package/dist/tabworthy-components/p-4eedf24e.entry.js +1 -0
- package/dist/tabworthy-components/p-69334c34.entry.js +1 -0
- package/dist/tabworthy-components/p-7cd6ccc1.entry.js +1 -0
- package/dist/tabworthy-components/{p-BVHu5CWV.js → p-CoFOnMSw.js} +1 -1
- package/dist/tabworthy-components/p-b6a5d970.entry.js +1 -0
- package/dist/tabworthy-components/tabworthy-components.esm.js +1 -1
- package/dist/themes/light.css +1 -1
- package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +7 -0
- package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +13 -1
- package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +15 -0
- package/dist/types/components.d.ts +14 -4
- package/dist/types/home/runner/work/tabworthy-components/tabworthy-components/.stencil/shared/utils/utils.d.ts +6 -0
- package/package.json +1 -1
- package/dist/components/p-BTQaxOHo.js +0 -1
- package/dist/components/p-DAc3jaFB.js +0 -1
- package/dist/tabworthy-components/p-1743bf7a.entry.js +0 -1
- package/dist/tabworthy-components/p-28192b55.entry.js +0 -1
- package/dist/tabworthy-components/p-3b548ae1.entry.js +0 -1
- package/dist/tabworthy-components/p-626a5c0b.entry.js +0 -1
|
@@ -36,6 +36,8 @@ const TabworthyTimesPicker = class {
|
|
|
36
36
|
this.period = this.hours >= 12 ? "PM" : "AM";
|
|
37
37
|
this.handleHourChange = (e) => {
|
|
38
38
|
const value = parseInt(e.target.value, 10);
|
|
39
|
+
if (isNaN(value))
|
|
40
|
+
return;
|
|
39
41
|
if (this.useTwelveHourFormat) {
|
|
40
42
|
// Convert to 24-hour format based on period
|
|
41
43
|
if (this.period === "AM") {
|
|
@@ -51,7 +53,10 @@ const TabworthyTimesPicker = class {
|
|
|
51
53
|
this.emitTimeChange();
|
|
52
54
|
};
|
|
53
55
|
this.handleMinuteChange = (e) => {
|
|
54
|
-
|
|
56
|
+
const value = parseInt(e.target.value, 10);
|
|
57
|
+
if (isNaN(value))
|
|
58
|
+
return;
|
|
59
|
+
this.internalMinutes = value;
|
|
55
60
|
this.emitTimeChange();
|
|
56
61
|
};
|
|
57
62
|
this.handlePeriodChange = (period) => {
|
|
@@ -111,7 +116,10 @@ const TabworthyTimesPicker = class {
|
|
|
111
116
|
this.emitTimeChange();
|
|
112
117
|
};
|
|
113
118
|
this.handleSecondChange = (e) => {
|
|
114
|
-
|
|
119
|
+
const value = parseInt(e.target.value, 10);
|
|
120
|
+
if (isNaN(value))
|
|
121
|
+
return;
|
|
122
|
+
this.internalSeconds = value;
|
|
115
123
|
this.emitTimeChange();
|
|
116
124
|
};
|
|
117
125
|
this.handleSecondIncrement = () => {
|
|
@@ -163,6 +171,7 @@ const TabworthyTimesPicker = class {
|
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
emitTimeChange() {
|
|
174
|
+
this.clampToBounds();
|
|
166
175
|
this.timeChanged.emit({
|
|
167
176
|
hours: this.get24HourValue(),
|
|
168
177
|
minutes: this.internalMinutes,
|
|
@@ -170,6 +179,69 @@ const TabworthyTimesPicker = class {
|
|
|
170
179
|
period: this.useTwelveHourFormat ? this.period : undefined
|
|
171
180
|
});
|
|
172
181
|
}
|
|
182
|
+
clampToBounds() {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
const h = this.get24HourValue();
|
|
185
|
+
const m = this.internalMinutes;
|
|
186
|
+
const s = this.internalSeconds;
|
|
187
|
+
if (this.minTime) {
|
|
188
|
+
const minS = (_a = this.minTime.seconds) !== null && _a !== void 0 ? _a : 0;
|
|
189
|
+
if (h < this.minTime.hours ||
|
|
190
|
+
(h === this.minTime.hours && m < this.minTime.minutes) ||
|
|
191
|
+
(h === this.minTime.hours && m === this.minTime.minutes && s < minS)) {
|
|
192
|
+
this.setInternal24Hours(this.minTime.hours);
|
|
193
|
+
this.internalMinutes = this.minTime.minutes;
|
|
194
|
+
this.internalSeconds = minS;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (this.maxTime) {
|
|
198
|
+
const maxS = (_b = this.maxTime.seconds) !== null && _b !== void 0 ? _b : 59;
|
|
199
|
+
const curH = this.get24HourValue();
|
|
200
|
+
const curM = this.internalMinutes;
|
|
201
|
+
const curS = this.internalSeconds;
|
|
202
|
+
if (curH > this.maxTime.hours ||
|
|
203
|
+
(curH === this.maxTime.hours && curM > this.maxTime.minutes) ||
|
|
204
|
+
(curH === this.maxTime.hours &&
|
|
205
|
+
curM === this.maxTime.minutes &&
|
|
206
|
+
curS > maxS)) {
|
|
207
|
+
this.setInternal24Hours(this.maxTime.hours);
|
|
208
|
+
this.internalMinutes = this.maxTime.minutes;
|
|
209
|
+
this.internalSeconds = maxS;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
setInternal24Hours(h24) {
|
|
214
|
+
this.internalHours = h24;
|
|
215
|
+
this.period = h24 >= 12 ? "PM" : "AM";
|
|
216
|
+
}
|
|
217
|
+
isAtMinHour() {
|
|
218
|
+
return !!this.minTime && this.get24HourValue() <= this.minTime.hours;
|
|
219
|
+
}
|
|
220
|
+
isAtMaxHour() {
|
|
221
|
+
return !!this.maxTime && this.get24HourValue() >= this.maxTime.hours;
|
|
222
|
+
}
|
|
223
|
+
isAtMinMinute() {
|
|
224
|
+
return (this.isAtMinHour() &&
|
|
225
|
+
!!this.minTime &&
|
|
226
|
+
this.internalMinutes <= this.minTime.minutes);
|
|
227
|
+
}
|
|
228
|
+
isAtMaxMinute() {
|
|
229
|
+
return (this.isAtMaxHour() &&
|
|
230
|
+
!!this.maxTime &&
|
|
231
|
+
this.internalMinutes >= this.maxTime.minutes);
|
|
232
|
+
}
|
|
233
|
+
isAtMinSecond() {
|
|
234
|
+
var _a;
|
|
235
|
+
return (this.isAtMinMinute() &&
|
|
236
|
+
!!this.minTime &&
|
|
237
|
+
this.internalSeconds <= ((_a = this.minTime.seconds) !== null && _a !== void 0 ? _a : 0));
|
|
238
|
+
}
|
|
239
|
+
isAtMaxSecond() {
|
|
240
|
+
var _a;
|
|
241
|
+
return (this.isAtMaxMinute() &&
|
|
242
|
+
!!this.maxTime &&
|
|
243
|
+
this.internalSeconds >= ((_a = this.maxTime.seconds) !== null && _a !== void 0 ? _a : 59));
|
|
244
|
+
}
|
|
173
245
|
padZero(num) {
|
|
174
246
|
return num.toString().padStart(2, "0");
|
|
175
247
|
}
|
|
@@ -177,22 +249,22 @@ const TabworthyTimesPicker = class {
|
|
|
177
249
|
const displayHours = this.getDisplayHours();
|
|
178
250
|
const maxHours = this.useTwelveHourFormat ? 12 : 23;
|
|
179
251
|
const minHours = this.useTwelveHourFormat ? 1 : 0;
|
|
180
|
-
return (h(Host, { key: '
|
|
252
|
+
return (h(Host, { key: '190cabad78886b1902d70c42c6c5b1f4ee90e5fe', class: this.elementClassName, "aria-label": this.labels.timePicker }, h("div", { key: '98b3d39baf501aeb9894949e807a365e26253fbc', class: `${this.elementClassName}__container` }, h("div", { key: '6697b77b177164a36297f911572d89beaa01cf23', class: `${this.elementClassName}__field` }, h("label", { key: '43f6e821b49f19041422741840439081f819f71c', htmlFor: `${this.elementClassName}-hours`, class: {
|
|
181
253
|
[`${this.elementClassName}__label`]: true,
|
|
182
254
|
[`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
|
|
183
|
-
} }, this.labels.hours), h("div", { key: '
|
|
255
|
+
} }, this.labels.hours), h("div", { key: 'a0e177ded2a849c22e41dbca95bad0888f7f956c', class: `${this.elementClassName}__control` }, h("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 }, h("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" }, h("polyline", { key: '279b80304fc77a2fd74e26a2aba89f12155f9334', points: "18 15 12 9 6 15" }))), h("input", { key: '93f17e7c848d40bd513ad7af9f29d39586391573', id: `${this.elementClassName}-hours`, type: "number", class: `${this.elementClassName}__input`, value: this.padZero(displayHours), min: minHours, max: maxHours, onInput: this.handleHourChange, disabled: this.disabled, "aria-label": this.labels.hours }), h("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 }, h("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" }, h("polyline", { key: '742b64bddf3873a7bea1c10ed93b9b1e99588ede', points: "6 9 12 15 18 9" }))))), h("div", { key: 'f81f40c465cc84a5d02b9904631d3d24e33150e3', class: `${this.elementClassName}__separator` }, ":"), h("div", { key: 'd028bae721c1c9c2cc7290cd19f7050a901f4a4e', class: `${this.elementClassName}__field` }, h("label", { key: '3c88a3fa04ed2a65f72c48ded459e19d580f9c36', htmlFor: `${this.elementClassName}-minutes`, class: {
|
|
184
256
|
[`${this.elementClassName}__label`]: true,
|
|
185
257
|
[`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
|
|
186
|
-
} }, this.labels.minutes), h("div", { key: '
|
|
187
|
-
h("div", { key: '
|
|
188
|
-
h("div", { key: '
|
|
258
|
+
} }, this.labels.minutes), h("div", { key: 'dbd89633addd003b2e42414b587d03a6e65e9239', class: `${this.elementClassName}__control` }, h("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 }, h("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" }, h("polyline", { key: 'dbc89190f6fe10bb8c8074252b83ab3397112de4', points: "18 15 12 9 6 15" }))), h("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 }), h("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 }, h("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" }, h("polyline", { key: '56045b19ec716a82f21406b647762ba0efcd8170', points: "6 9 12 15 18 9" }))))), this.showSeconds && [
|
|
259
|
+
h("div", { key: '9c2619ccebd147e626e10a21fb1a5fa1268128f3', class: `${this.elementClassName}__separator` }, ":"),
|
|
260
|
+
h("div", { key: 'dea8135d47a06d9624b480aa6123350a0899ca02', class: `${this.elementClassName}__field` }, h("label", { key: 'afaa88b59df63091088620ff2a49bf8472f4401f', htmlFor: `${this.elementClassName}-seconds`, class: {
|
|
189
261
|
[`${this.elementClassName}__label`]: true,
|
|
190
262
|
[`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
|
|
191
|
-
} }, this.labels.seconds), h("div", { key: '
|
|
192
|
-
], this.useTwelveHourFormat && (h("div", { key: '
|
|
263
|
+
} }, this.labels.seconds), h("div", { key: 'c2ed4d63a95a65bdc26926932e705744bbe776c5', class: `${this.elementClassName}__control` }, h("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 }, h("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" }, h("polyline", { key: '5e2dad75d96a521f56f616bc2b88e4baa6c0eb50', points: "18 15 12 9 6 15" }))), h("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 }), h("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 }, h("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" }, h("polyline", { key: '3bb717320e078f5fa36912f15995ed604d9f702b', points: "6 9 12 15 18 9" })))))
|
|
264
|
+
], this.useTwelveHourFormat && (h("div", { key: 'ec583890c2f7d97c6a6196f3556dfd76c8209227', class: `${this.elementClassName}__period` }, h("button", { key: 'e99d9b41ded6b138660f2777f60991bf3af12182', type: "button", class: {
|
|
193
265
|
[`${this.elementClassName}__period-button`]: true,
|
|
194
266
|
[`${this.elementClassName}__period-button--active`]: this.period === "AM"
|
|
195
|
-
}, onClick: () => this.handlePeriodChange("AM"), disabled: this.disabled, "aria-label": this.labels.am, "aria-pressed": this.period === "AM" }, this.labels.am), h("button", { key: '
|
|
267
|
+
}, onClick: () => this.handlePeriodChange("AM"), disabled: this.disabled, "aria-label": this.labels.am, "aria-pressed": this.period === "AM" }, this.labels.am), h("button", { key: '3a3cbc3b47b0218694db2c8909da97ea50e521f2', type: "button", class: {
|
|
196
268
|
[`${this.elementClassName}__period-button`]: true,
|
|
197
269
|
[`${this.elementClassName}__period-button--active`]: this.period === "PM"
|
|
198
270
|
}, onClick: () => this.handlePeriodChange("PM"), disabled: this.disabled, "aria-label": this.labels.pm, "aria-pressed": this.period === "PM" }, this.labels.pm))))));
|
|
@@ -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-
|
|
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,9 +112,14 @@ const TabworthyTimes = class {
|
|
|
109
112
|
}
|
|
110
113
|
else {
|
|
111
114
|
const date = removeTimezoneOffset(new Date(dates[0]));
|
|
115
|
+
if (!this.isDateValid(date))
|
|
116
|
+
return;
|
|
117
|
+
// Clamp time to boundary constraints when selecting a boundary day
|
|
118
|
+
this.clampTimeToBounds(date);
|
|
112
119
|
this.updateValue(date);
|
|
113
|
-
//
|
|
120
|
+
// Reset then set calendar value so re-clicking the same date still emits
|
|
114
121
|
if (this.pickerRef) {
|
|
122
|
+
this.pickerRef.value = undefined;
|
|
115
123
|
this.pickerRef.value = date;
|
|
116
124
|
}
|
|
117
125
|
}
|
|
@@ -167,6 +175,25 @@ const TabworthyTimes = class {
|
|
|
167
175
|
parsed = dayjs(value);
|
|
168
176
|
}
|
|
169
177
|
if (parsed.isValid()) {
|
|
178
|
+
// Check minDate/maxDate bounds (supports both date-only and datetime strings)
|
|
179
|
+
if (this.minDate && parsed.isBefore(dayjs(this.minDate))) {
|
|
180
|
+
this.errorState = true;
|
|
181
|
+
this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
|
|
182
|
+
this.emitErrorChange("minDate", this.errorMessage);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (this.maxDate && parsed.isAfter(dayjs(this.maxDate))) {
|
|
186
|
+
this.errorState = true;
|
|
187
|
+
this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
|
|
188
|
+
this.emitErrorChange("maxDate", this.errorMessage);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (this.disableDate(parsed.toDate())) {
|
|
192
|
+
this.errorState = true;
|
|
193
|
+
this.errorMessage = this.timesLabels.disabledDateError;
|
|
194
|
+
this.emitErrorChange("disabledDate", this.errorMessage);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
170
197
|
this.errorState = false;
|
|
171
198
|
this.selectedHours = parsed.hour();
|
|
172
199
|
this.selectedMinutes = parsed.minute();
|
|
@@ -177,9 +204,99 @@ const TabworthyTimes = class {
|
|
|
177
204
|
// Set error state for invalid/garbage input
|
|
178
205
|
this.errorState = true;
|
|
179
206
|
this.errorMessage = this.timesLabels.invalidDateError;
|
|
207
|
+
this.emitErrorChange("invalid", this.errorMessage);
|
|
180
208
|
}
|
|
181
209
|
};
|
|
182
210
|
}
|
|
211
|
+
emitErrorChange(reason, message) {
|
|
212
|
+
this.errorChange.emit({ reason, message });
|
|
213
|
+
}
|
|
214
|
+
formatBoundaryDate(dateString) {
|
|
215
|
+
const parsed = dayjs(dateString);
|
|
216
|
+
if (!parsed.isValid())
|
|
217
|
+
return dateString;
|
|
218
|
+
const hasTime = dateString.includes("T") || dateString.includes(" ");
|
|
219
|
+
if (!hasTime) {
|
|
220
|
+
return Intl.DateTimeFormat(this.locale, {
|
|
221
|
+
day: "numeric",
|
|
222
|
+
month: "short",
|
|
223
|
+
year: "numeric"
|
|
224
|
+
}).format(parsed.toDate());
|
|
225
|
+
}
|
|
226
|
+
const options = Object.assign({ day: "numeric", month: "short", year: "numeric", hour: "numeric", minute: "numeric" }, (this.showSeconds ? { second: "numeric" } : {}));
|
|
227
|
+
return Intl.DateTimeFormat(this.locale, options).format(parsed.toDate());
|
|
228
|
+
}
|
|
229
|
+
getEffectiveMinTime() {
|
|
230
|
+
if (!this.minDate || !this.selectedDate)
|
|
231
|
+
return undefined;
|
|
232
|
+
const min = dayjs(this.minDate);
|
|
233
|
+
const sel = dayjs(this.selectedDate);
|
|
234
|
+
if (!min.isValid() || !sel.isSame(min, "day"))
|
|
235
|
+
return undefined;
|
|
236
|
+
return {
|
|
237
|
+
hours: min.hour(),
|
|
238
|
+
minutes: min.minute(),
|
|
239
|
+
seconds: min.second()
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
getEffectiveMaxTime() {
|
|
243
|
+
if (!this.maxDate || !this.selectedDate)
|
|
244
|
+
return undefined;
|
|
245
|
+
const max = dayjs(this.maxDate);
|
|
246
|
+
const sel = dayjs(this.selectedDate);
|
|
247
|
+
if (!max.isValid() || !sel.isSame(max, "day"))
|
|
248
|
+
return undefined;
|
|
249
|
+
return {
|
|
250
|
+
hours: max.hour(),
|
|
251
|
+
minutes: max.minute(),
|
|
252
|
+
seconds: max.second()
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
isDateOutOfBounds() {
|
|
256
|
+
if (!this.selectedDate)
|
|
257
|
+
return false;
|
|
258
|
+
const sel = dayjs(this.selectedDate);
|
|
259
|
+
if (this.minDate && sel.isBefore(dayjs(this.minDate), "day"))
|
|
260
|
+
return true;
|
|
261
|
+
if (this.maxDate && sel.isAfter(dayjs(this.maxDate), "day"))
|
|
262
|
+
return true;
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* When selecting a date on a boundary day, adjust the time to the first
|
|
267
|
+
* available time if the current selection falls outside the allowed range.
|
|
268
|
+
*/
|
|
269
|
+
clampTimeToBounds(date) {
|
|
270
|
+
const sel = dayjs(date);
|
|
271
|
+
if (this.minDate) {
|
|
272
|
+
const min = dayjs(this.minDate);
|
|
273
|
+
if (min.isValid() && sel.isSame(min, "day")) {
|
|
274
|
+
const curTotal = this.selectedHours * 3600 +
|
|
275
|
+
this.selectedMinutes * 60 +
|
|
276
|
+
this.selectedSeconds;
|
|
277
|
+
const minTotal = min.hour() * 3600 + min.minute() * 60 + min.second();
|
|
278
|
+
if (curTotal < minTotal) {
|
|
279
|
+
this.selectedHours = min.hour();
|
|
280
|
+
this.selectedMinutes = min.minute();
|
|
281
|
+
this.selectedSeconds = min.second();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (this.maxDate) {
|
|
286
|
+
const max = dayjs(this.maxDate);
|
|
287
|
+
if (max.isValid() && sel.isSame(max, "day")) {
|
|
288
|
+
const curTotal = this.selectedHours * 3600 +
|
|
289
|
+
this.selectedMinutes * 60 +
|
|
290
|
+
this.selectedSeconds;
|
|
291
|
+
const maxTotal = max.hour() * 3600 + max.minute() * 60 + max.second();
|
|
292
|
+
if (curTotal > maxTotal) {
|
|
293
|
+
this.selectedHours = max.hour();
|
|
294
|
+
this.selectedMinutes = max.minute();
|
|
295
|
+
this.selectedSeconds = max.second();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
183
300
|
shouldInputFormat() {
|
|
184
301
|
if (typeof this.inputShouldFormat === "string") {
|
|
185
302
|
return this.inputShouldFormat === "true";
|
|
@@ -252,6 +369,30 @@ const TabworthyTimes = class {
|
|
|
252
369
|
this.formatInput();
|
|
253
370
|
}
|
|
254
371
|
}
|
|
372
|
+
isDateValid(date) {
|
|
373
|
+
const parsed = dayjs(date);
|
|
374
|
+
if (!parsed.isValid())
|
|
375
|
+
return false;
|
|
376
|
+
if (this.minDate && parsed.isBefore(dayjs(this.minDate), "day")) {
|
|
377
|
+
this.errorState = true;
|
|
378
|
+
this.errorMessage = `${this.timesLabels.minDateError} ${this.formatBoundaryDate(this.minDate)}`;
|
|
379
|
+
this.emitErrorChange("minDate", this.errorMessage);
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
if (this.maxDate && parsed.isAfter(dayjs(this.maxDate), "day")) {
|
|
383
|
+
this.errorState = true;
|
|
384
|
+
this.errorMessage = `${this.timesLabels.maxDateError} ${this.formatBoundaryDate(this.maxDate)}`;
|
|
385
|
+
this.emitErrorChange("maxDate", this.errorMessage);
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
if (this.disableDate(date)) {
|
|
389
|
+
this.errorState = true;
|
|
390
|
+
this.errorMessage = this.timesLabels.disabledDateError;
|
|
391
|
+
this.emitErrorChange("disabledDate", this.errorMessage);
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
255
396
|
formatInput() {
|
|
256
397
|
if (!this.internalValue)
|
|
257
398
|
return;
|
|
@@ -292,12 +433,12 @@ const TabworthyTimes = class {
|
|
|
292
433
|
}
|
|
293
434
|
render() {
|
|
294
435
|
var _a;
|
|
295
|
-
return (h(Host, { key: '
|
|
436
|
+
return (h(Host, { key: '6c3049b02eda2e976f14616027cfb3fd1a0b0100', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, h("label", { key: 'eb9ecc8c81d04338a5935ad414c6cd544a01bb58', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), h("div", { key: '8906972aec0b8c7b24cc3f2d07212c3f6c2d8f56', class: this.getClassName("input-container"), ref: (r) => (this.inputContainerRef = r) }, h("input", { key: 'bca908ac7aa2710569fa86be5c7c6643d7f73574', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: {
|
|
296
437
|
[this.getClassName("input")]: true,
|
|
297
438
|
[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: '
|
|
439
|
+
}, placeholder: this.placeholder, disabled: this.disabledState || this.disableFreeformInput, value: (_a = this.internalValue) === null || _a === void 0 ? void 0 : _a.toString(), onBlur: this.handleInputBlur, onChange: this.handleInputChange, "aria-describedby": this.errorState ? `${this.id}-error` : undefined, "aria-invalid": this.errorState }), !this.inline && (h("button", { key: 'c0d27ab5207fb62606e017bea14c93bc44daebb9', type: "button", onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState, "aria-label": this.calendarButtonContent
|
|
299
440
|
? this.timesLabels.openCalendar
|
|
300
|
-
: undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '
|
|
441
|
+
: undefined }, this.calendarButtonContent ? (h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), h("tabworthy-dates-modal", { key: '1e6761504cd55a9fd380902861aeec0e7e655d47', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
|
|
301
442
|
if (this.pickerRef) {
|
|
302
443
|
this.pickerRef.modalIsOpen = true;
|
|
303
444
|
}
|
|
@@ -305,7 +446,7 @@ const TabworthyTimes = class {
|
|
|
305
446
|
if (this.pickerRef) {
|
|
306
447
|
this.pickerRef.modalIsOpen = false;
|
|
307
448
|
}
|
|
308
|
-
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '
|
|
449
|
+
}, inline: this.inline, appendTo: this.appendTo }, h("div", { key: '14966bd22b73a14fcb54bf118543e6aedf6e291f', class: this.getClassName("picker-container") }, h("tabworthy-dates-calendar", { key: 'aef55f7ee2cb19eb68bf8db51dd3e111e4f0dbff', range: this.range, locale: this.locale, onSelectDate: (event) => this.handlePickerSelection(event.detail), onChangeMonth: (event) => this.handleChangedMonths(event.detail), onChangeYear: (event) => this.handleYearChange(event.detail), onRequestClose: () => { var _a; return (_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.close(); }, labels: this.datesCalendarLabels, ref: (el) => (this.pickerRef = el), startDate: this.startDate, firstDayOfWeek: this.firstDayOfWeek, showHiddenTitle: true, disabled: this.disabledState, showMonthStepper: this.showMonthStepper, showYearStepper: this.showYearStepper, showClearButton: this.showClearButton, showCloseButton: this.showCloseButton, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline, value: this.value ? this.toDate(this.value) : undefined, nextMonthButtonContent: this.nextMonthButtonContent, nextYearButtonContent: this.nextYearButtonContent, previousMonthButtonContent: this.previousMonthButtonContent, previousYearButtonContent: this.previousYearButtonContent, todayButtonContent: this.todayButtonContent, clearButtonContent: this.clearButtonContent, closeButtonContent: this.closeButtonContent }, h("div", { key: 'f89b6d83e9ef68bd98eb6e08ea3aec00c2b6dd86', slot: "after-calendar", class: this.getClassName("time-section") }, h("hr", { key: '2ae84e5817c25641ab56ff096f164355524abfdf', class: this.getClassName("divider") }), h("tabworthy-times-picker", { key: '55bfe07297efd0c60d47d6049572f502311abf15', hours: this.selectedHours, minutes: this.selectedMinutes, seconds: this.selectedSeconds, showSeconds: this.showSeconds, useTwelveHourFormat: this.useTwelveHourFormat, disabled: this.disabledState || this.isDateOutOfBounds(), onTimeChanged: this.handleTimeChange, labels: this.timesPickerLabels, minTime: this.getEffectiveMinTime(), maxTime: this.getEffectiveMaxTime() }))))), this.errorState && (h("div", { key: '97dbda7bc8725c8964a627e37e9236e9bf699ee0', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
|
|
309
450
|
}
|
|
310
451
|
get el() { return getElement(this); }
|
|
311
452
|
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 =
|
|
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 =
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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,
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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}$/;
|