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