@tabworthy/components 0.2.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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +69 -0
  3. package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
  4. package/dist/cjs/index-C15oswCE.js +2148 -0
  5. package/dist/cjs/index.cjs.js +2 -0
  6. package/dist/cjs/loader.cjs.js +13 -0
  7. package/dist/cjs/moment-CdViwxPQ.js +5681 -0
  8. package/dist/cjs/tabworthy-components.cjs.js +25 -0
  9. package/dist/cjs/tabworthy-dates-calendar_2.cjs.entry.js +884 -0
  10. package/dist/cjs/tabworthy-dates.cjs.entry.js +10906 -0
  11. package/dist/cjs/tabworthy-times-picker.cjs.entry.js +181 -0
  12. package/dist/cjs/tabworthy-times.cjs.entry.js +242 -0
  13. package/dist/cjs/utils-y5Vtky2t.js +214 -0
  14. package/dist/collection/collection-manifest.json +16 -0
  15. package/dist/collection/components/tabworthy-dates/tabworthy-dates.css +10 -0
  16. package/dist/collection/components/tabworthy-dates/tabworthy-dates.js +1197 -0
  17. package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.css +10 -0
  18. package/dist/collection/components/tabworthy-dates-calendar/tabworthy-dates-calendar.js +986 -0
  19. package/dist/collection/components/tabworthy-modal/tabworthy-dates-modal.css +14 -0
  20. package/dist/collection/components/tabworthy-modal/tabworthy-dates-modal.js +237 -0
  21. package/dist/collection/components/tabworthy-times/tabworthy-times.js +832 -0
  22. package/dist/collection/components/tabworthy-times-picker/tabworthy-times-picker.js +356 -0
  23. package/dist/collection/index.js +1 -0
  24. package/dist/components/index.d.ts +35 -0
  25. package/dist/components/index.js +1 -0
  26. package/dist/components/moment.js +8 -0
  27. package/dist/components/tabworthy-dates-calendar.d.ts +11 -0
  28. package/dist/components/tabworthy-dates-calendar.js +1 -0
  29. package/dist/components/tabworthy-dates-calendar2.js +1 -0
  30. package/dist/components/tabworthy-dates-modal.d.ts +11 -0
  31. package/dist/components/tabworthy-dates-modal.js +1 -0
  32. package/dist/components/tabworthy-dates-modal2.js +1 -0
  33. package/dist/components/tabworthy-dates.d.ts +11 -0
  34. package/dist/components/tabworthy-dates.js +1 -0
  35. package/dist/components/tabworthy-times-picker.d.ts +11 -0
  36. package/dist/components/tabworthy-times-picker.js +1 -0
  37. package/dist/components/tabworthy-times-picker2.js +1 -0
  38. package/dist/components/tabworthy-times.d.ts +11 -0
  39. package/dist/components/tabworthy-times.js +1 -0
  40. package/dist/esm/app-globals-DQuL1Twl.js +3 -0
  41. package/dist/esm/index-BusoZVTR.js +2139 -0
  42. package/dist/esm/index.js +1 -0
  43. package/dist/esm/loader.js +11 -0
  44. package/dist/esm/moment-Mki5YqAR.js +5679 -0
  45. package/dist/esm/tabworthy-components.js +21 -0
  46. package/dist/esm/tabworthy-dates-calendar_2.entry.js +881 -0
  47. package/dist/esm/tabworthy-dates.entry.js +10904 -0
  48. package/dist/esm/tabworthy-times-picker.entry.js +179 -0
  49. package/dist/esm/tabworthy-times.entry.js +240 -0
  50. package/dist/esm/utils-BVHu5CWV.js +188 -0
  51. package/dist/index.cjs.js +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/loader/cdn.js +1 -0
  54. package/dist/loader/index.cjs.js +1 -0
  55. package/dist/loader/index.d.ts +24 -0
  56. package/dist/loader/index.es2017.js +1 -0
  57. package/dist/loader/index.js +2 -0
  58. package/dist/shared/utils/chrono-parser/chrono-parser.js +146 -0
  59. package/dist/shared/utils/chrono-parser/chrono-parser.type.js +1 -0
  60. package/dist/shared/utils/utils.js +186 -0
  61. package/dist/tabworthy-components/index.esm.js +0 -0
  62. package/dist/tabworthy-components/p-170bc6ca.entry.js +1 -0
  63. package/dist/tabworthy-components/p-3ce9a767.entry.js +1 -0
  64. package/dist/tabworthy-components/p-77bd1bd4.entry.js +1 -0
  65. package/dist/tabworthy-components/p-BVHu5CWV.js +1 -0
  66. package/dist/tabworthy-components/p-BusoZVTR.js +2 -0
  67. package/dist/tabworthy-components/p-DQuL1Twl.js +1 -0
  68. package/dist/tabworthy-components/p-Mki5YqAR.js +8 -0
  69. package/dist/tabworthy-components/p-ebbb4c46.entry.js +1 -0
  70. package/dist/tabworthy-components/tabworthy-components.esm.js +1 -0
  71. package/dist/themes/dark.css +1 -0
  72. package/dist/themes/light.css +1 -0
  73. package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/chrono-parser/chrono-parser.d.ts +3 -0
  74. package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/chrono-parser/chrono-parser.type.d.ts +40 -0
  75. package/dist/types/Users/damirbogdanov_1/work/tabworthy-components/.stencil/shared/utils/utils.d.ts +28 -0
  76. package/dist/types/components/tabworthy-dates/tabworthy-dates.d.ts +80 -0
  77. package/dist/types/components/tabworthy-dates-calendar/tabworthy-dates-calendar.d.ts +89 -0
  78. package/dist/types/components/tabworthy-modal/tabworthy-dates-modal.d.ts +29 -0
  79. package/dist/types/components/tabworthy-times/tabworthy-times.d.ts +65 -0
  80. package/dist/types/components/tabworthy-times-picker/tabworthy-times-picker.d.ts +46 -0
  81. package/dist/types/components.d.ts +879 -0
  82. package/dist/types/index.d.ts +1 -0
  83. package/dist/types/stencil-public-runtime.d.ts +1858 -0
  84. package/package.json +132 -0
@@ -0,0 +1,181 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index-C15oswCE.js');
4
+
5
+ const defaultLabels = {
6
+ hours: "Hours",
7
+ minutes: "Minutes",
8
+ am: "AM",
9
+ pm: "PM",
10
+ timePicker: "Time picker",
11
+ incrementHours: "Increment hours",
12
+ decrementHours: "Decrement hours",
13
+ incrementMinutes: "Increment minutes",
14
+ decrementMinutes: "Decrement minutes"
15
+ };
16
+ const InclusiveTimesPicker = class {
17
+ constructor(hostRef) {
18
+ index.registerInstance(this, hostRef);
19
+ this.timeChanged = index.createEvent(this, "timeChanged");
20
+ // Current time value (24-hour format)
21
+ this.hours = 12;
22
+ this.minutes = 0;
23
+ this.use12HourFormat = false;
24
+ // Labels for accessibility and i18n
25
+ this.labels = defaultLabels;
26
+ // Hide labels visually but keep them for screen readers
27
+ this.labelsSrOnly = true;
28
+ this.disabled = false;
29
+ this.elementClassName = "tabworthy-times-picker";
30
+ this.internalHours = this.hours;
31
+ this.internalMinutes = this.minutes;
32
+ this.period = this.hours >= 12 ? "PM" : "AM";
33
+ this.handleHourChange = (e) => {
34
+ const value = parseInt(e.target.value, 10);
35
+ if (this.use12HourFormat) {
36
+ // Convert to 24-hour format based on period
37
+ if (this.period === "AM") {
38
+ this.internalHours = value === 12 ? 0 : value;
39
+ }
40
+ else {
41
+ this.internalHours = value === 12 ? 12 : value + 12;
42
+ }
43
+ }
44
+ else {
45
+ this.internalHours = value;
46
+ }
47
+ this.emitTimeChange();
48
+ };
49
+ this.handleMinuteChange = (e) => {
50
+ this.internalMinutes = parseInt(e.target.value, 10);
51
+ this.emitTimeChange();
52
+ };
53
+ this.handlePeriodChange = (period) => {
54
+ if (this.period === period || !this.use12HourFormat)
55
+ return;
56
+ this.period = period;
57
+ // Convert hours based on new period
58
+ const displayHours = this.getDisplayHours();
59
+ if (period === "AM") {
60
+ this.internalHours = displayHours === 12 ? 0 : displayHours;
61
+ }
62
+ else {
63
+ this.internalHours = displayHours === 12 ? 12 : displayHours + 12;
64
+ }
65
+ this.emitTimeChange();
66
+ };
67
+ this.handleHourIncrement = () => {
68
+ if (this.use12HourFormat) {
69
+ const displayHours = this.getDisplayHours();
70
+ const newDisplayHours = displayHours === 12 ? 1 : displayHours + 1;
71
+ if (this.period === "AM") {
72
+ this.internalHours = newDisplayHours === 12 ? 0 : newDisplayHours;
73
+ }
74
+ else {
75
+ this.internalHours = newDisplayHours === 12 ? 12 : newDisplayHours + 12;
76
+ }
77
+ }
78
+ else {
79
+ this.internalHours = (this.internalHours + 1) % 24;
80
+ }
81
+ this.emitTimeChange();
82
+ };
83
+ this.handleHourDecrement = () => {
84
+ if (this.use12HourFormat) {
85
+ const displayHours = this.getDisplayHours();
86
+ const newDisplayHours = displayHours === 1 ? 12 : displayHours - 1;
87
+ if (this.period === "AM") {
88
+ this.internalHours = newDisplayHours === 12 ? 0 : newDisplayHours;
89
+ }
90
+ else {
91
+ this.internalHours = newDisplayHours === 12 ? 12 : newDisplayHours + 12;
92
+ }
93
+ }
94
+ else {
95
+ this.internalHours = this.internalHours === 0 ? 23 : this.internalHours - 1;
96
+ }
97
+ this.emitTimeChange();
98
+ };
99
+ this.handleMinuteIncrement = () => {
100
+ this.internalMinutes = (this.internalMinutes + 1) % 60;
101
+ this.emitTimeChange();
102
+ };
103
+ this.handleMinuteDecrement = () => {
104
+ this.internalMinutes = this.internalMinutes === 0 ? 59 : this.internalMinutes - 1;
105
+ this.emitTimeChange();
106
+ };
107
+ }
108
+ watchHours(newValue) {
109
+ this.internalHours = newValue;
110
+ this.period = newValue >= 12 ? "PM" : "AM";
111
+ }
112
+ watchMinutes(newValue) {
113
+ this.internalMinutes = newValue;
114
+ }
115
+ componentWillLoad() {
116
+ this.internalHours = this.hours;
117
+ this.internalMinutes = this.minutes;
118
+ this.period = this.hours >= 12 ? "PM" : "AM";
119
+ }
120
+ getDisplayHours() {
121
+ if (!this.use12HourFormat) {
122
+ return this.internalHours;
123
+ }
124
+ if (this.internalHours === 0)
125
+ return 12;
126
+ if (this.internalHours > 12)
127
+ return this.internalHours - 12;
128
+ return this.internalHours;
129
+ }
130
+ get24HourValue() {
131
+ if (!this.use12HourFormat) {
132
+ return this.internalHours;
133
+ }
134
+ const displayHours = this.getDisplayHours();
135
+ if (this.period === "AM") {
136
+ return displayHours === 12 ? 0 : displayHours;
137
+ }
138
+ else {
139
+ return displayHours === 12 ? 12 : displayHours + 12;
140
+ }
141
+ }
142
+ emitTimeChange() {
143
+ this.timeChanged.emit({
144
+ hours: this.get24HourValue(),
145
+ minutes: this.internalMinutes,
146
+ period: this.use12HourFormat ? this.period : undefined
147
+ });
148
+ }
149
+ padZero(num) {
150
+ return num.toString().padStart(2, "0");
151
+ }
152
+ render() {
153
+ const displayHours = this.getDisplayHours();
154
+ const maxHours = this.use12HourFormat ? 12 : 23;
155
+ const minHours = this.use12HourFormat ? 1 : 0;
156
+ return (index.h(index.Host, { key: '826752ac3b056591e50c55198f01b232e0d914e7', class: this.elementClassName, "aria-label": this.labels.timePicker }, index.h("div", { key: '5e7179bcf1e2e9087f7fb8f62366af4b3432cf9b', class: `${this.elementClassName}__container` }, index.h("div", { key: 'f589fc8f0672b1446e0e3b9e3d2d1a134355975c', class: `${this.elementClassName}__field` }, index.h("label", { key: 'a35e5e1e6e1be6166d2908b200904c4ebf266170', htmlFor: `${this.elementClassName}-hours`, class: {
157
+ [`${this.elementClassName}__label`]: true,
158
+ [`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
159
+ } }, this.labels.hours), index.h("div", { key: '7c2340bc7b58f47ccb5cf555460665fe99d2bb14', class: `${this.elementClassName}__control` }, index.h("button", { key: 'dd0339ee230032b0ae681b19e7ccad362454e70d', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--increment`, onClick: this.handleHourIncrement, disabled: this.disabled, "aria-label": this.labels.incrementHours }, index.h("svg", { key: 'f976e2e85f45795317a8e6f8b97f56d787075b30', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, index.h("polyline", { key: 'd92fe17241918aa191b3bf8c1cf67d0783d6904c', points: "18 15 12 9 6 15" }))), index.h("input", { key: '12c6de6d83c13e437f1ec0f6e6a552c9806eee7e', 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 }), index.h("button", { key: '9a3fe68583a1a92c1cb9ce82d8c79d435cc364c6', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--decrement`, onClick: this.handleHourDecrement, disabled: this.disabled, "aria-label": this.labels.decrementHours }, index.h("svg", { key: 'c52dd2da808714a53da185d830609a83165d0435', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, index.h("polyline", { key: '759299e487f09e8047643aed7bf5c27687ba0114', points: "6 9 12 15 18 9" }))))), index.h("div", { key: '9839abd75a1d2fbbfd085b5090586e5b90e43582', class: `${this.elementClassName}__separator` }, ":"), index.h("div", { key: '40a7656ee0e1fdde1287fad6200b415361e9d8a7', class: `${this.elementClassName}__field` }, index.h("label", { key: '12924e2ce017f31969cdd17efc61c5bc2c7299e1', htmlFor: `${this.elementClassName}-minutes`, class: {
160
+ [`${this.elementClassName}__label`]: true,
161
+ [`${this.elementClassName}__label--sr-only`]: this.labelsSrOnly
162
+ } }, this.labels.minutes), index.h("div", { key: '71ce2e345a98345b591e92803ad25fe10ae52ac1', class: `${this.elementClassName}__control` }, index.h("button", { key: 'ec85968d4d7b43fb348cbc9577f6329bc510b88b', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--increment`, onClick: this.handleMinuteIncrement, disabled: this.disabled, "aria-label": this.labels.incrementMinutes }, index.h("svg", { key: '459a04638058154613fc642ac6ec3c884b2eb3ed', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, index.h("polyline", { key: '88747079b0a8cdc6f2d9bea21ec5b74dd334c889', points: "18 15 12 9 6 15" }))), index.h("input", { key: 'ccd14478435689bad16be5b3038c37fff7e55506', 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 }), index.h("button", { key: 'b645e0a9c10cf35e9b6ebfe6660f9e4770edabe7', type: "button", class: `${this.elementClassName}__button ${this.elementClassName}__button--decrement`, onClick: this.handleMinuteDecrement, disabled: this.disabled, "aria-label": this.labels.decrementMinutes }, index.h("svg", { key: 'e1fbeb018b7d3898af319f227d2f3257a281b141', fill: "none", height: "16", "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", stroke: "currentColor", viewBox: "0 0 24 24", width: "16" }, index.h("polyline", { key: '9fa1f35020d93eea906247c0eca79c6978e75c81', points: "6 9 12 15 18 9" }))))), this.use12HourFormat && (index.h("div", { key: '80f5d6355c5627d98e25a3d945f3224d217d350b', class: `${this.elementClassName}__period` }, index.h("button", { key: '7fdbfe17b0b1d50a707aeb927847626d2e4b277a', type: "button", class: {
163
+ [`${this.elementClassName}__period-button`]: true,
164
+ [`${this.elementClassName}__period-button--active`]: this.period === "AM"
165
+ }, onClick: () => this.handlePeriodChange("AM"), disabled: this.disabled, "aria-label": this.labels.am, "aria-pressed": this.period === "AM" }, this.labels.am), index.h("button", { key: '5817fb8c5a5901077320472b9535700d3e980c3c', type: "button", class: {
166
+ [`${this.elementClassName}__period-button`]: true,
167
+ [`${this.elementClassName}__period-button--active`]: this.period === "PM"
168
+ }, onClick: () => this.handlePeriodChange("PM"), disabled: this.disabled, "aria-label": this.labels.pm, "aria-pressed": this.period === "PM" }, this.labels.pm))))));
169
+ }
170
+ get el() { return index.getElement(this); }
171
+ static get watchers() { return {
172
+ "hours": [{
173
+ "watchHours": 0
174
+ }],
175
+ "minutes": [{
176
+ "watchMinutes": 0
177
+ }]
178
+ }; }
179
+ };
180
+
181
+ exports.tabworthy_times_picker = InclusiveTimesPicker;
@@ -0,0 +1,242 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index-C15oswCE.js');
4
+ var moment = require('./moment-CdViwxPQ.js');
5
+ var utils = require('./utils-y5Vtky2t.js');
6
+
7
+ const defaultLabels = {
8
+ selected: "selected",
9
+ openCalendar: "Open date and time picker",
10
+ calendar: "date and time picker",
11
+ invalidDateError: "We could not find a matching date",
12
+ minDateError: `Please fill in a date after `,
13
+ maxDateError: `Please fill in a date before `,
14
+ rangeOutOfBoundsError: `Please enter a valid range of dates`,
15
+ disabledDateError: `Please choose an available date`,
16
+ to: "to",
17
+ startDate: "Start date",
18
+ timeLabel: "Time"
19
+ };
20
+ const InclusiveTimes = class {
21
+ constructor(hostRef) {
22
+ index.registerInstance(this, hostRef);
23
+ this.selectDateTime = index.createEvent(this, "selectDateTime");
24
+ this.changeYear = index.createEvent(this, "changeYear");
25
+ this.componentReady = index.createEvent(this, "componentReady");
26
+ // Enable or disable range mode
27
+ this.range = false;
28
+ // A label for the text field
29
+ this.label = "Choose a date and time";
30
+ // A placeholder for the text field
31
+ this.placeholder = "";
32
+ // Locale used for internal translations and date parsing
33
+ this.locale = (navigator === null || navigator === void 0 ? void 0 : navigator.language) || "en-US";
34
+ // If the datetime picker is disabled
35
+ this.disabled = false;
36
+ // Which date to be displayed when calendar is first opened
37
+ this.startDate = utils.getISODateString(new Date());
38
+ // Reference date used for Chrono date parsing. Equals "today"
39
+ this.referenceDate = utils.getISODateString(new Date());
40
+ // Use 12-hour format with AM/PM
41
+ this.use12HourFormat = true;
42
+ // Labels used for internal translations
43
+ this.timesLabels = defaultLabels;
44
+ // Prevent hiding the calendar
45
+ this.inline = false;
46
+ // Current error state of the input field
47
+ this.hasError = false;
48
+ // Show or hide the next/previous year buttons
49
+ this.showYearStepper = false;
50
+ // Show or hide the next/previous month buttons
51
+ this.showMonthStepper = true;
52
+ // Show or hide the clear button
53
+ this.showClearButton = true;
54
+ // Show or hide the today button
55
+ this.showTodayButton = true;
56
+ // Function to disable individual dates
57
+ this.disableDate = () => false;
58
+ // Component name used to generate CSS classes
59
+ this.elementClassName = "tabworthy-times";
60
+ // Which day that should start the week (0 is sunday, 1 is monday)
61
+ this.firstDayOfWeek = 1;
62
+ // Format for the value prop (input/output format). Defaults to ISO 8601 format.
63
+ this.format = "YYYY-MM-DDTHH:mm:ss";
64
+ this.selectedHours = 12;
65
+ this.selectedMinutes = 0;
66
+ this.errorState = this.hasError;
67
+ this.disabledState = this.disabled;
68
+ this.errorMessage = "";
69
+ this.handlePickerSelection = async (dateString) => {
70
+ const dates = dateString.split(",");
71
+ if (this.range && dates.length === 2) {
72
+ const startDate = utils.removeTimezoneOffset(new Date(dates[0]));
73
+ const endDate = utils.removeTimezoneOffset(new Date(dates[1]));
74
+ this.updateValue([startDate, endDate]);
75
+ // Update calendar with selected dates
76
+ if (this.pickerRef) {
77
+ this.pickerRef.value = [startDate, endDate];
78
+ }
79
+ }
80
+ else {
81
+ const date = utils.removeTimezoneOffset(new Date(dates[0]));
82
+ this.updateValue(date);
83
+ // Update calendar with selected date
84
+ if (this.pickerRef) {
85
+ this.pickerRef.value = date;
86
+ }
87
+ }
88
+ };
89
+ this.handleTimeChange = (event) => {
90
+ this.selectedHours = event.detail.hours;
91
+ this.selectedMinutes = event.detail.minutes;
92
+ // Update the value if we have a selected date
93
+ if (this.selectedDate) {
94
+ this.updateValue(this.selectedDate);
95
+ }
96
+ };
97
+ this.handleCalendarButtonClick = async () => {
98
+ if (this.modalRef) {
99
+ await this.modalRef.setTriggerElement(this.calendarButtonRef);
100
+ await this.modalRef.open();
101
+ }
102
+ };
103
+ this.handleYearChange = (eventDetail) => {
104
+ if (this.changeYear) {
105
+ this.changeYear.emit(eventDetail);
106
+ }
107
+ };
108
+ this.handleChangedMonths = (_eventDetail) => {
109
+ // Can be used for month change tracking
110
+ };
111
+ this.handleInputBlur = () => {
112
+ this.formatInput();
113
+ };
114
+ this.handleInputChange = (event) => {
115
+ const value = event.target.value;
116
+ // Try to parse the input value as a datetime
117
+ const parsed = moment.hooks(value);
118
+ if (parsed.isValid()) {
119
+ this.selectedHours = parsed.hours();
120
+ this.selectedMinutes = parsed.minutes();
121
+ this.updateValue(parsed.toDate());
122
+ }
123
+ };
124
+ }
125
+ watchValue(_newValue) {
126
+ this.syncFromValueProp();
127
+ }
128
+ watchDisabled(newValue) {
129
+ this.disabledState = newValue;
130
+ }
131
+ watchHasError(newValue) {
132
+ this.errorState = newValue;
133
+ }
134
+ componentDidLoad() {
135
+ this.syncFromValueProp();
136
+ this.componentReady.emit();
137
+ if (!this.id) {
138
+ console.error('tabworthy-times: The "id" prop is required for accessibility');
139
+ }
140
+ }
141
+ syncFromValueProp() {
142
+ if (this.value) {
143
+ this.internalValue = this.value;
144
+ // Parse the first datetime value to set time picker
145
+ const firstValue = Array.isArray(this.value) ? this.value[0] : this.value;
146
+ if (firstValue) {
147
+ const parsed = moment.hooks(firstValue, this.format);
148
+ if (parsed.isValid()) {
149
+ this.selectedDate = parsed.toDate();
150
+ this.selectedHours = parsed.hours();
151
+ this.selectedMinutes = parsed.minutes();
152
+ }
153
+ }
154
+ }
155
+ else {
156
+ this.internalValue = null;
157
+ }
158
+ }
159
+ updateValue(date) {
160
+ if (Array.isArray(date)) {
161
+ // Range mode
162
+ const formattedDates = date.map((d) => {
163
+ const m = moment.hooks(d);
164
+ m.hours(this.selectedHours);
165
+ m.minutes(this.selectedMinutes);
166
+ m.seconds(0);
167
+ return m.format(this.format);
168
+ });
169
+ this.internalValue = formattedDates;
170
+ this.value = formattedDates;
171
+ this.selectDateTime.emit(formattedDates);
172
+ }
173
+ else {
174
+ // Single date mode
175
+ const m = moment.hooks(date);
176
+ m.hours(this.selectedHours);
177
+ m.minutes(this.selectedMinutes);
178
+ m.seconds(0);
179
+ const formatted = m.format(this.format);
180
+ this.internalValue = formatted;
181
+ this.value = formatted;
182
+ this.selectedDate = date;
183
+ this.selectDateTime.emit(formatted);
184
+ }
185
+ this.errorState = false;
186
+ this.formatInput();
187
+ }
188
+ formatInput() {
189
+ if (!this.internalValue)
190
+ return;
191
+ if (Array.isArray(this.internalValue)) {
192
+ // Format range
193
+ const formatted = this.internalValue
194
+ .map((v) => moment.hooks(v, this.format).format("lll"))
195
+ .join(` ${this.timesLabels.to} `);
196
+ this.inputRef.value = formatted;
197
+ }
198
+ else {
199
+ // Format single datetime
200
+ this.inputRef.value = moment.hooks(this.internalValue, this.format).format("lll");
201
+ }
202
+ }
203
+ getClassName(suffix) {
204
+ return `${this.elementClassName}__${suffix}`;
205
+ }
206
+ async clearValue() {
207
+ this.internalValue = null;
208
+ this.value = undefined;
209
+ this.selectedDate = undefined;
210
+ this.inputRef.value = "";
211
+ if (this.pickerRef) {
212
+ this.pickerRef.value = null;
213
+ }
214
+ this.selectDateTime.emit(undefined);
215
+ }
216
+ render() {
217
+ var _a;
218
+ return (index.h(index.Host, { key: 'e922c649f8ed2bf03711fe99ae73bca550c9d8ef', class: this.elementClassName, "has-error": this.errorState, disabled: this.disabledState }, index.h("label", { key: '6b8c053bcb4d232c52e0b95da141e4a433f2bc16', htmlFor: `${this.id}-input`, class: this.getClassName("label") }, this.label), index.h("div", { key: '1950259cf662cedae9b8f0fed6a61f095d3a4424', class: this.getClassName("input-container") }, index.h("input", { key: '1c6bfced55bd60706eadf6304eb7204c89bda8d6', id: `${this.id}-input`, ref: (r) => (this.inputRef = r), type: "text", class: this.getClassName("input"), placeholder: this.placeholder, disabled: this.disabledState, 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: '60b202b017d7ffe5de182908c809a24eba4f8e56', type: "button", ref: (r) => (this.calendarButtonRef = r), onClick: this.handleCalendarButtonClick, class: this.getClassName("calendar-button"), disabled: this.disabledState }, this.calendarButtonContent ? (index.h("span", { innerHTML: this.calendarButtonContent })) : (this.timesLabels.openCalendar)))), index.h("tabworthy-dates-modal", { key: '83716e92fd3711c65b23f007bba209bcc60a4d7d', label: this.timesLabels.calendar, ref: (el) => (this.modalRef = el), onOpened: () => {
219
+ if (this.pickerRef) {
220
+ this.pickerRef.modalIsOpen = true;
221
+ }
222
+ }, onClosed: () => {
223
+ if (this.pickerRef) {
224
+ this.pickerRef.modalIsOpen = false;
225
+ }
226
+ }, inline: this.inline }, index.h("div", { key: '3972712165cdc3069498d5683ca7b8b25041e44d', class: this.getClassName("picker-container") }, index.h("tabworthy-dates-calendar", { key: 'e6472861402e4926227657fb68f57d8671452260', range: this.range, locale: this.locale, onSelectDate: (event) => this.handlePickerSelection(event.detail), onChangeMonth: (event) => this.handleChangedMonths(event.detail), onChangeYear: (event) => this.handleYearChange(event.detail), 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, showTodayButton: this.showTodayButton, disableDate: this.disableDate, minDate: this.minDate, maxDate: this.maxDate, inline: this.inline }, index.h("div", { key: 'e9f7b9baa9544ae651b4b6b73094a215cabcc796', slot: "after-calendar", class: this.getClassName("time-section") }, index.h("tabworthy-times-picker", { key: 'b4c2f14b9311d1e3c186825785d6f64580f2896c', hours: this.selectedHours, minutes: this.selectedMinutes, use12HourFormat: this.use12HourFormat, disabled: this.disabledState, onTimeChanged: this.handleTimeChange }))))), this.errorState && (index.h("div", { key: '684dce5fc46c53feea28b19eca46746d7538aa3f', class: this.getClassName("input-error"), id: this.id ? `${this.id}-error` : undefined, role: "status" }, this.errorMessage))));
227
+ }
228
+ get el() { return index.getElement(this); }
229
+ static get watchers() { return {
230
+ "value": [{
231
+ "watchValue": 0
232
+ }],
233
+ "disabled": [{
234
+ "watchDisabled": 0
235
+ }],
236
+ "hasError": [{
237
+ "watchHasError": 0
238
+ }]
239
+ }; }
240
+ };
241
+
242
+ exports.tabworthy_times = InclusiveTimes;
@@ -0,0 +1,214 @@
1
+ 'use strict';
2
+
3
+ function addDays(date, days) {
4
+ const newDate = new Date(date);
5
+ newDate.setDate(newDate.getDate() + days);
6
+ return newDate;
7
+ }
8
+ function getDaysOfMonth(date, padded, firstDayOfWeek) {
9
+ const days = [];
10
+ const firstOfMonth = getFirstOfMonth(date);
11
+ const firstDayMonth = firstOfMonth.getDay() === 0 ? 7 : firstOfMonth.getDay();
12
+ const lastOfMonth = getLastOfMonth(date);
13
+ const lastDayOfMonth = lastOfMonth.getDay() === 0 ? 7 : lastOfMonth.getDay();
14
+ const lastDayOfWeek = firstDayOfWeek === 1 ? 7 : firstDayOfWeek - 1;
15
+ const leftPaddingDays = [];
16
+ const rightPaddingDays = [];
17
+ {
18
+ const leftPadding = (7 - firstDayOfWeek + firstDayMonth) % 7;
19
+ let leftPaddingAmount = leftPadding;
20
+ let leftPaddingDay = getPreviousDay(firstOfMonth);
21
+ while (leftPaddingAmount > 0) {
22
+ leftPaddingDays.push(leftPaddingDay);
23
+ leftPaddingDay = getPreviousDay(leftPaddingDay);
24
+ leftPaddingAmount -= 1;
25
+ }
26
+ leftPaddingDays.reverse();
27
+ const rightPadding = (7 - lastDayOfMonth + lastDayOfWeek) % 7;
28
+ let rightPaddingAmount = rightPadding;
29
+ let rightPaddingDay = getNextDay(lastOfMonth);
30
+ while (rightPaddingAmount > 0) {
31
+ rightPaddingDays.push(rightPaddingDay);
32
+ rightPaddingDay = getNextDay(rightPaddingDay);
33
+ rightPaddingAmount -= 1;
34
+ }
35
+ }
36
+ let currentDay = firstOfMonth;
37
+ while (currentDay.getMonth() === date.getMonth()) {
38
+ days.push(currentDay);
39
+ currentDay = getNextDay(currentDay);
40
+ }
41
+ return [...leftPaddingDays, ...days, ...rightPaddingDays];
42
+ }
43
+ function getFirstOfMonth(date) {
44
+ const firstOfMonth = removeTimezoneOffset(new Date(`${getYear(date)}-${String(getMonth(date)).padStart(2, "0")}-01`));
45
+ return firstOfMonth;
46
+ }
47
+ function getISODateStringHistoricalImplementation(date) {
48
+ if (!(date instanceof Date)) {
49
+ return;
50
+ }
51
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
52
+ }
53
+ function getISODateString(date) {
54
+ // this is a lie, but can have unpredictable issues because heavily used,
55
+ // so atm keeping historical implementation, until better test coverage and confidence is achieved
56
+ return getISODateStringHistoricalImplementation(date);
57
+ }
58
+ function getLastOfMonth(date) {
59
+ const newDate = getFirstOfMonth(date);
60
+ newDate.setMonth(newDate.getMonth() + 1);
61
+ newDate.setDate(newDate.getDate() - 1);
62
+ return newDate;
63
+ }
64
+ function getMonth(date) {
65
+ return date.getMonth() + 1;
66
+ }
67
+ function getMonths(locale) {
68
+ return new Array(12).fill(undefined).map((_, month) => {
69
+ const date = removeTimezoneOffset(new Date(`2006-${String(month + 1).padStart(2, "0")}-01`));
70
+ return Intl.DateTimeFormat(locale, {
71
+ month: "long"
72
+ }).format(date);
73
+ });
74
+ }
75
+ function getNextDay(date) {
76
+ return addDays(date, 1);
77
+ }
78
+ function getNextMonth(date) {
79
+ const newDate = new Date(date);
80
+ newDate.setMonth(newDate.getMonth() + 1);
81
+ return newDate;
82
+ }
83
+ function getNextYear(date) {
84
+ const newDate = new Date(date);
85
+ newDate.setFullYear(newDate.getFullYear() + 1);
86
+ return newDate;
87
+ }
88
+ function getPreviousDay(date) {
89
+ return subDays(date, 1);
90
+ }
91
+ function getPreviousMonth(date) {
92
+ const newDate = new Date(date);
93
+ newDate.setMonth(newDate.getMonth() - 1);
94
+ return newDate;
95
+ }
96
+ function getPreviousYear(date) {
97
+ const newDate = new Date(date);
98
+ newDate.setFullYear(newDate.getFullYear() - 1);
99
+ return newDate;
100
+ }
101
+ function getWeekDays(firstDayOfWeek, locale) {
102
+ return new Array(7)
103
+ .fill(undefined)
104
+ .map((_, index) => ((firstDayOfWeek + index) % 7) + 1)
105
+ .map((day) => {
106
+ const date = new Date(2006, 0, day);
107
+ return [
108
+ Intl.DateTimeFormat(locale, {
109
+ weekday: "short"
110
+ }).format(date),
111
+ Intl.DateTimeFormat(locale, {
112
+ weekday: "long"
113
+ }).format(date)
114
+ ];
115
+ });
116
+ }
117
+ function getYear(date) {
118
+ return date.getFullYear();
119
+ }
120
+ function isDateInRange(date, range) {
121
+ if (!date || !range || !range.from || !range.to) {
122
+ return false;
123
+ }
124
+ const earlyDate = range.from < range.to ? range.from : range.to;
125
+ const laterDate = range.from < range.to ? range.to : range.from;
126
+ return date >= earlyDate && date <= laterDate;
127
+ }
128
+ function isSameDay(date1, date2) {
129
+ if (!date1 || !date2) {
130
+ return false;
131
+ }
132
+ return (date1.getFullYear() === date2.getFullYear() &&
133
+ date1.getMonth() === date2.getMonth() &&
134
+ date1.getDate() === date2.getDate());
135
+ }
136
+ function removeTimezoneOffset(date) {
137
+ const newDate = new Date(date);
138
+ newDate.setMinutes(newDate.getMinutes() + newDate.getTimezoneOffset());
139
+ return newDate;
140
+ }
141
+ function subDays(date, days) {
142
+ const newDate = new Date(date);
143
+ newDate.setDate(newDate.getDate() - days);
144
+ return newDate;
145
+ }
146
+ function dateIsWithinLowerBounds(date, minDate) {
147
+ if (minDate) {
148
+ const min = removeTimezoneOffset(new Date(minDate));
149
+ return date >= min || isSameDay(min, date);
150
+ }
151
+ else
152
+ return true;
153
+ }
154
+ function dateIsWithinUpperBounds(date, maxDate) {
155
+ if (maxDate) {
156
+ const max = removeTimezoneOffset(new Date(maxDate));
157
+ return date <= max || isSameDay(date, max);
158
+ }
159
+ else
160
+ return true;
161
+ }
162
+ function dateIsWithinBounds(date, minDate, maxDate) {
163
+ return (dateIsWithinLowerBounds(date, minDate) &&
164
+ dateIsWithinUpperBounds(date, maxDate));
165
+ }
166
+ function monthIsDisabled(month, year, minDate, maxDate) {
167
+ const firstDate = new Date(year, month, 1);
168
+ firstDate.setDate(firstDate.getDate() - 1);
169
+ const lastDate = new Date(year, month + 1, 0);
170
+ lastDate.setDate(firstDate.getDate() + 1);
171
+ return (!dateIsWithinBounds(firstDate, minDate, maxDate) &&
172
+ !dateIsWithinBounds(lastDate, minDate, maxDate));
173
+ }
174
+ function isValidISODate(dateString) {
175
+ var isoFormat = /^\d{4}-\d{2}-\d{2}$/;
176
+ if (dateString.match(isoFormat) == null) {
177
+ return false;
178
+ }
179
+ else {
180
+ var d = new Date(dateString);
181
+ return !isNaN(d.getTime());
182
+ }
183
+ }
184
+ function extractDates(text) {
185
+ var dateRegex = /\d{4}-\d{2}-\d{2}/g;
186
+ var matches = text.match(dateRegex);
187
+ return matches === null || matches === void 0 ? void 0 : matches.slice(0, 2);
188
+ }
189
+
190
+ exports.addDays = addDays;
191
+ exports.dateIsWithinBounds = dateIsWithinBounds;
192
+ exports.dateIsWithinLowerBounds = dateIsWithinLowerBounds;
193
+ exports.dateIsWithinUpperBounds = dateIsWithinUpperBounds;
194
+ exports.extractDates = extractDates;
195
+ exports.getDaysOfMonth = getDaysOfMonth;
196
+ exports.getFirstOfMonth = getFirstOfMonth;
197
+ exports.getISODateString = getISODateString;
198
+ exports.getLastOfMonth = getLastOfMonth;
199
+ exports.getMonth = getMonth;
200
+ exports.getMonths = getMonths;
201
+ exports.getNextDay = getNextDay;
202
+ exports.getNextMonth = getNextMonth;
203
+ exports.getNextYear = getNextYear;
204
+ exports.getPreviousDay = getPreviousDay;
205
+ exports.getPreviousMonth = getPreviousMonth;
206
+ exports.getPreviousYear = getPreviousYear;
207
+ exports.getWeekDays = getWeekDays;
208
+ exports.getYear = getYear;
209
+ exports.isDateInRange = isDateInRange;
210
+ exports.isSameDay = isSameDay;
211
+ exports.isValidISODate = isValidISODate;
212
+ exports.monthIsDisabled = monthIsDisabled;
213
+ exports.removeTimezoneOffset = removeTimezoneOffset;
214
+ exports.subDays = subDays;
@@ -0,0 +1,16 @@
1
+ {
2
+ "entries": [
3
+ "components/tabworthy-dates-calendar/tabworthy-dates-calendar.js",
4
+ "components/tabworthy-dates/tabworthy-dates.js",
5
+ "components/tabworthy-times-picker/tabworthy-times-picker.js",
6
+ "components/tabworthy-times/tabworthy-times.js",
7
+ "components/tabworthy-modal/tabworthy-dates-modal.js"
8
+ ],
9
+ "compiler": {
10
+ "name": "@stencil/core",
11
+ "version": "4.42.1",
12
+ "typescriptVersion": "5.8.3"
13
+ },
14
+ "collections": [],
15
+ "bundles": []
16
+ }
@@ -0,0 +1,10 @@
1
+ .visually-hidden {
2
+ position: absolute;
3
+ overflow: hidden;
4
+ width: 1px;
5
+ height: 1px;
6
+ white-space: nowrap;
7
+ clip: rect(0 0 0 0);
8
+ -webkit-clip-path: inset(50%);
9
+ clip-path: inset(50%);
10
+ }