tyrell-components 1.0.0-RC13 → 1.0.0-RC15
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/README.md +10 -2
- package/css/tyrell-theme.css +192 -180
- package/css/tyrell.css +23 -0
- package/dist/tyrell-colors-static.css +1 -316
- package/dist/tyrell-theme.css +1 -1454
- package/dist/tyrell.css +1 -1371
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +20 -10
- package/lib/base/ty-component.js +196 -319
- package/lib/components/button.d.ts +3 -17
- package/lib/components/button.js +261 -295
- package/lib/components/calendar-month.d.ts +4 -50
- package/lib/components/calendar-month.js +443 -582
- package/lib/components/calendar-navigation.d.ts +3 -48
- package/lib/components/calendar-navigation.js +239 -362
- package/lib/components/calendar.d.ts +8 -83
- package/lib/components/calendar.js +616 -829
- package/lib/components/checkbox.d.ts +5 -72
- package/lib/components/checkbox.js +273 -416
- package/lib/components/copy.d.ts +4 -57
- package/lib/components/copy.js +280 -397
- package/lib/components/date-picker.d.ts +21 -163
- package/lib/components/date-picker.js +1143 -1674
- package/lib/components/file-upload.d.ts +9 -15
- package/lib/components/file-upload.js +404 -426
- package/lib/components/icon.d.ts +3 -24
- package/lib/components/icon.js +141 -230
- package/lib/components/input.d.ts +8 -108
- package/lib/components/input.js +593 -784
- package/lib/components/modal.d.ts +17 -26
- package/lib/components/modal.js +340 -484
- package/lib/components/option.d.ts +2 -9
- package/lib/components/option.js +168 -216
- package/lib/components/popup.d.ts +2 -17
- package/lib/components/popup.js +249 -380
- package/lib/components/radio.d.ts +5 -25
- package/lib/components/radio.js +407 -461
- package/lib/components/resize-observer.d.ts +3 -30
- package/lib/components/resize-observer.js +69 -103
- package/lib/components/scroll-container.d.ts +2 -12
- package/lib/components/scroll-container.js +293 -338
- package/lib/components/select.d.ts +87 -159
- package/lib/components/select.js +1609 -2090
- package/lib/components/selected-tags.d.ts +5 -48
- package/lib/components/selected-tags.js +188 -276
- package/lib/components/step.d.ts +1 -6
- package/lib/components/step.js +62 -68
- package/lib/components/switch.d.ts +1 -12
- package/lib/components/switch.js +214 -247
- package/lib/components/tab.d.ts +1 -6
- package/lib/components/tab.js +62 -69
- package/lib/components/tabs.d.ts +6 -63
- package/lib/components/tabs.js +545 -777
- package/lib/components/tag.d.ts +3 -37
- package/lib/components/tag.js +236 -335
- package/lib/components/textarea.d.ts +7 -87
- package/lib/components/textarea.js +457 -627
- package/lib/components/tooltip.d.ts +3 -11
- package/lib/components/tooltip.js +307 -443
- package/lib/components/wizard.d.ts +6 -54
- package/lib/components/wizard.js +405 -618
- package/lib/icons/fontawesome/brands.d.ts +0 -1
- package/lib/icons/fontawesome/brands.js +0 -8
- package/lib/icons/fontawesome/regular.d.ts +0 -1
- package/lib/icons/fontawesome/regular.js +0 -8
- package/lib/icons/fontawesome/solid.d.ts +0 -1
- package/lib/icons/fontawesome/solid.js +0 -8
- package/lib/icons/heroicons/micro.d.ts +0 -1
- package/lib/icons/heroicons/micro.js +392 -400
- package/lib/icons/heroicons/mini.d.ts +0 -1
- package/lib/icons/heroicons/mini.js +382 -390
- package/lib/icons/heroicons/outline.d.ts +0 -1
- package/lib/icons/heroicons/outline.js +337 -345
- package/lib/icons/heroicons/solid.d.ts +0 -1
- package/lib/icons/heroicons/solid.js +407 -415
- package/lib/icons/lucide.d.ts +0 -1
- package/lib/icons/lucide.js +24479 -26351
- package/lib/icons/material/filled.d.ts +0 -1
- package/lib/icons/material/filled.js +9653 -9663
- package/lib/icons/material/outlined.d.ts +0 -1
- package/lib/icons/material/outlined.js +10271 -10281
- package/lib/icons/material/round.d.ts +0 -1
- package/lib/icons/material/round.js +10495 -10505
- package/lib/icons/material/sharp.d.ts +0 -1
- package/lib/icons/material/sharp.js +9905 -9915
- package/lib/icons/material/two-tone.d.ts +0 -1
- package/lib/icons/material/two-tone.js +12792 -12802
- package/lib/index.d.ts +0 -1
- package/lib/index.js +21 -41
- package/lib/styles/button.d.ts +2 -20
- package/lib/styles/button.js +202 -404
- package/lib/styles/calendar-month.d.ts +1 -5
- package/lib/styles/calendar-month.js +127 -244
- package/lib/styles/calendar-navigation.d.ts +2 -6
- package/lib/styles/calendar-navigation.js +64 -104
- package/lib/styles/calendar.d.ts +1 -2
- package/lib/styles/calendar.js +9 -22
- package/lib/styles/checkbox.d.ts +0 -1
- package/lib/styles/checkbox.js +45 -94
- package/lib/styles/copy.d.ts +0 -1
- package/lib/styles/copy.js +67 -106
- package/lib/styles/custom-scrollbar.d.ts +1 -2
- package/lib/styles/custom-scrollbar.js +80 -115
- package/lib/styles/date-picker.d.ts +1 -5
- package/lib/styles/date-picker.js +261 -335
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.d.ts +1 -2
- package/lib/styles/file-upload.js +143 -188
- package/lib/styles/icon.d.ts +2 -6
- package/lib/styles/icon.js +92 -170
- package/lib/styles/input.d.ts +1 -6
- package/lib/styles/input.js +125 -290
- package/lib/styles/modal.d.ts +1 -2
- package/lib/styles/modal.js +71 -108
- package/lib/styles/option.d.ts +2 -6
- package/lib/styles/option.js +49 -64
- package/lib/styles/popup.d.ts +1 -2
- package/lib/styles/popup.js +42 -77
- package/lib/styles/radio.d.ts +0 -1
- package/lib/styles/radio.js +69 -110
- package/lib/styles/resize-observer.d.ts +1 -2
- package/lib/styles/resize-observer.js +2 -12
- package/lib/styles/scroll-container.d.ts +1 -2
- package/lib/styles/scroll-container.js +100 -149
- package/lib/styles/select-base.d.ts +0 -1
- package/lib/styles/select-base.js +597 -785
- package/lib/styles/select.d.ts +1 -2
- package/lib/styles/select.js +140 -236
- package/lib/styles/step.d.ts +1 -2
- package/lib/styles/step.js +22 -33
- package/lib/styles/switch.d.ts +0 -1
- package/lib/styles/switch.js +34 -73
- package/lib/styles/tab.d.ts +1 -2
- package/lib/styles/tab.js +22 -34
- package/lib/styles/tabs.d.ts +3 -11
- package/lib/styles/tabs.js +190 -222
- package/lib/styles/tag.d.ts +1 -5
- package/lib/styles/tag.js +136 -218
- package/lib/styles/textarea.d.ts +1 -2
- package/lib/styles/textarea.js +210 -319
- package/lib/styles/tooltip.d.ts +0 -1
- package/lib/styles/tooltip.js +3 -13
- package/lib/styles/wizard.d.ts +5 -21
- package/lib/styles/wizard.js +170 -306
- package/lib/types/common.d.ts +2 -2
- package/lib/types/common.js +6 -17
- package/lib/utils/calendar-utils.d.ts +4 -21
- package/lib/utils/calendar-utils.js +100 -273
- package/lib/utils/custom-scrollbar.d.ts +6 -20
- package/lib/utils/custom-scrollbar.js +273 -317
- package/lib/utils/flavor-sheet.d.ts +0 -1
- package/lib/utils/flavor-sheet.js +14 -37
- package/lib/utils/icon-registry.d.ts +0 -2
- package/lib/utils/icon-registry.js +137 -243
- package/lib/utils/icons.d.ts +0 -1
- package/lib/utils/icons.js +0 -9
- package/lib/utils/loader-registry.d.ts +0 -1
- package/lib/utils/loader-registry.js +3 -35
- package/lib/utils/locale.d.ts +2 -23
- package/lib/utils/locale.js +34 -120
- package/lib/utils/mobile.d.ts +0 -1
- package/lib/utils/mobile.js +1 -18
- package/lib/utils/number-format.d.ts +6 -3
- package/lib/utils/number-format.js +54 -110
- package/lib/utils/positioning.d.ts +50 -7
- package/lib/utils/positioning.js +224 -234
- package/lib/utils/property-capture.d.ts +5 -27
- package/lib/utils/property-capture.js +36 -144
- package/lib/utils/property-manager.d.ts +0 -1
- package/lib/utils/property-manager.js +126 -196
- package/lib/utils/resize-observer.d.ts +0 -1
- package/lib/utils/resize-observer.js +23 -59
- package/lib/utils/scroll-lock.d.ts +4 -11
- package/lib/utils/scroll-lock.js +65 -172
- package/lib/utils/styles.d.ts +0 -1
- package/lib/utils/styles.js +17 -41
- package/lib/version.d.ts +1 -2
- package/lib/version.js +1 -11
- package/package.json +4 -4
- package/lib/base/ty-component.d.ts.map +0 -1
- package/lib/base/ty-component.js.map +0 -1
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js.map +0 -1
- package/lib/components/calendar-month.d.ts.map +0 -1
- package/lib/components/calendar-month.js.map +0 -1
- package/lib/components/calendar-navigation.d.ts.map +0 -1
- package/lib/components/calendar-navigation.js.map +0 -1
- package/lib/components/calendar.d.ts.map +0 -1
- package/lib/components/calendar.js.map +0 -1
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js.map +0 -1
- package/lib/components/copy.d.ts.map +0 -1
- package/lib/components/copy.js.map +0 -1
- package/lib/components/date-picker.d.ts.map +0 -1
- package/lib/components/date-picker.js.map +0 -1
- package/lib/components/file-upload.d.ts.map +0 -1
- package/lib/components/file-upload.js.map +0 -1
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js.map +0 -1
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js.map +0 -1
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js.map +0 -1
- package/lib/components/option.d.ts.map +0 -1
- package/lib/components/option.js.map +0 -1
- package/lib/components/popup.d.ts.map +0 -1
- package/lib/components/popup.js.map +0 -1
- package/lib/components/radio.d.ts.map +0 -1
- package/lib/components/radio.js.map +0 -1
- package/lib/components/resize-observer.d.ts.map +0 -1
- package/lib/components/resize-observer.js.map +0 -1
- package/lib/components/scroll-container.d.ts.map +0 -1
- package/lib/components/scroll-container.js.map +0 -1
- package/lib/components/select.d.ts.map +0 -1
- package/lib/components/select.js.map +0 -1
- package/lib/components/selected-tags.d.ts.map +0 -1
- package/lib/components/selected-tags.js.map +0 -1
- package/lib/components/step.d.ts.map +0 -1
- package/lib/components/step.js.map +0 -1
- package/lib/components/switch.d.ts.map +0 -1
- package/lib/components/switch.js.map +0 -1
- package/lib/components/tab.d.ts.map +0 -1
- package/lib/components/tab.js.map +0 -1
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js.map +0 -1
- package/lib/components/tag.d.ts.map +0 -1
- package/lib/components/tag.js.map +0 -1
- package/lib/components/textarea.d.ts.map +0 -1
- package/lib/components/textarea.js.map +0 -1
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js.map +0 -1
- package/lib/components/wizard.d.ts.map +0 -1
- package/lib/components/wizard.js.map +0 -1
- package/lib/icons/fontawesome/brands.d.ts.map +0 -1
- package/lib/icons/fontawesome/brands.js.map +0 -1
- package/lib/icons/fontawesome/regular.d.ts.map +0 -1
- package/lib/icons/fontawesome/regular.js.map +0 -1
- package/lib/icons/fontawesome/solid.d.ts.map +0 -1
- package/lib/icons/fontawesome/solid.js.map +0 -1
- package/lib/icons/heroicons/micro.d.ts.map +0 -1
- package/lib/icons/heroicons/micro.js.map +0 -1
- package/lib/icons/heroicons/mini.d.ts.map +0 -1
- package/lib/icons/heroicons/mini.js.map +0 -1
- package/lib/icons/heroicons/outline.d.ts.map +0 -1
- package/lib/icons/heroicons/outline.js.map +0 -1
- package/lib/icons/heroicons/solid.d.ts.map +0 -1
- package/lib/icons/heroicons/solid.js.map +0 -1
- package/lib/icons/lucide.d.ts.map +0 -1
- package/lib/icons/lucide.js.map +0 -1
- package/lib/icons/material/filled.d.ts.map +0 -1
- package/lib/icons/material/filled.js.map +0 -1
- package/lib/icons/material/outlined.d.ts.map +0 -1
- package/lib/icons/material/outlined.js.map +0 -1
- package/lib/icons/material/round.d.ts.map +0 -1
- package/lib/icons/material/round.js.map +0 -1
- package/lib/icons/material/sharp.d.ts.map +0 -1
- package/lib/icons/material/sharp.js.map +0 -1
- package/lib/icons/material/two-tone.d.ts.map +0 -1
- package/lib/icons/material/two-tone.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/styles/button.d.ts.map +0 -1
- package/lib/styles/button.js.map +0 -1
- package/lib/styles/calendar-month.d.ts.map +0 -1
- package/lib/styles/calendar-month.js.map +0 -1
- package/lib/styles/calendar-navigation.d.ts.map +0 -1
- package/lib/styles/calendar-navigation.js.map +0 -1
- package/lib/styles/calendar.d.ts.map +0 -1
- package/lib/styles/calendar.js.map +0 -1
- package/lib/styles/checkbox.d.ts.map +0 -1
- package/lib/styles/checkbox.js.map +0 -1
- package/lib/styles/copy.d.ts.map +0 -1
- package/lib/styles/copy.js.map +0 -1
- package/lib/styles/custom-scrollbar.d.ts.map +0 -1
- package/lib/styles/custom-scrollbar.js.map +0 -1
- package/lib/styles/date-picker.d.ts.map +0 -1
- package/lib/styles/date-picker.js.map +0 -1
- package/lib/styles/file-upload.d.ts.map +0 -1
- package/lib/styles/file-upload.js.map +0 -1
- package/lib/styles/icon.d.ts.map +0 -1
- package/lib/styles/icon.js.map +0 -1
- package/lib/styles/input.d.ts.map +0 -1
- package/lib/styles/input.js.map +0 -1
- package/lib/styles/modal.d.ts.map +0 -1
- package/lib/styles/modal.js.map +0 -1
- package/lib/styles/multiselect.d.ts +0 -8
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -849
- package/lib/styles/multiselect.js.map +0 -1
- package/lib/styles/option.d.ts.map +0 -1
- package/lib/styles/option.js.map +0 -1
- package/lib/styles/popup.d.ts.map +0 -1
- package/lib/styles/popup.js.map +0 -1
- package/lib/styles/radio.d.ts.map +0 -1
- package/lib/styles/radio.js.map +0 -1
- package/lib/styles/resize-observer.d.ts.map +0 -1
- package/lib/styles/resize-observer.js.map +0 -1
- package/lib/styles/scroll-container.d.ts.map +0 -1
- package/lib/styles/scroll-container.js.map +0 -1
- package/lib/styles/select-base.d.ts.map +0 -1
- package/lib/styles/select-base.js.map +0 -1
- package/lib/styles/select.d.ts.map +0 -1
- package/lib/styles/select.js.map +0 -1
- package/lib/styles/step.d.ts.map +0 -1
- package/lib/styles/step.js.map +0 -1
- package/lib/styles/switch.d.ts.map +0 -1
- package/lib/styles/switch.js.map +0 -1
- package/lib/styles/tab.d.ts.map +0 -1
- package/lib/styles/tab.js.map +0 -1
- package/lib/styles/tabs.d.ts.map +0 -1
- package/lib/styles/tabs.js.map +0 -1
- package/lib/styles/tag.d.ts.map +0 -1
- package/lib/styles/tag.js.map +0 -1
- package/lib/styles/textarea.d.ts.map +0 -1
- package/lib/styles/textarea.js.map +0 -1
- package/lib/styles/tooltip.d.ts.map +0 -1
- package/lib/styles/tooltip.js.map +0 -1
- package/lib/styles/wizard.d.ts.map +0 -1
- package/lib/styles/wizard.js.map +0 -1
- package/lib/types/common.d.ts.map +0 -1
- package/lib/types/common.js.map +0 -1
- package/lib/utils/calendar-utils.d.ts.map +0 -1
- package/lib/utils/calendar-utils.js.map +0 -1
- package/lib/utils/custom-scrollbar.d.ts.map +0 -1
- package/lib/utils/custom-scrollbar.js.map +0 -1
- package/lib/utils/flavor-sheet.d.ts.map +0 -1
- package/lib/utils/flavor-sheet.js.map +0 -1
- package/lib/utils/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.js.map +0 -1
- package/lib/utils/icons.d.ts.map +0 -1
- package/lib/utils/icons.js.map +0 -1
- package/lib/utils/loader-registry.d.ts.map +0 -1
- package/lib/utils/loader-registry.js.map +0 -1
- package/lib/utils/locale.d.ts.map +0 -1
- package/lib/utils/locale.js.map +0 -1
- package/lib/utils/mobile.d.ts.map +0 -1
- package/lib/utils/mobile.js.map +0 -1
- package/lib/utils/number-format.d.ts.map +0 -1
- package/lib/utils/number-format.js.map +0 -1
- package/lib/utils/parse-boolean.d.ts +0 -39
- package/lib/utils/parse-boolean.d.ts.map +0 -1
- package/lib/utils/parse-boolean.js +0 -58
- package/lib/utils/parse-boolean.js.map +0 -1
- package/lib/utils/positioning.d.ts.map +0 -1
- package/lib/utils/positioning.js.map +0 -1
- package/lib/utils/property-capture.d.ts.map +0 -1
- package/lib/utils/property-capture.js.map +0 -1
- package/lib/utils/property-manager.d.ts.map +0 -1
- package/lib/utils/property-manager.js.map +0 -1
- package/lib/utils/resize-observer.d.ts.map +0 -1
- package/lib/utils/resize-observer.js.map +0 -1
- package/lib/utils/scroll-lock.d.ts.map +0 -1
- package/lib/utils/scroll-lock.js.map +0 -1
- package/lib/utils/styles.d.ts.map +0 -1
- package/lib/utils/styles.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js.map +0 -1
|
@@ -1,597 +1,458 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TyCalendarMonth Web Component
|
|
3
|
-
* PORTED FROM: cljs/ty/components/calendar_month.cljs
|
|
4
|
-
*
|
|
5
|
-
* A stateless, property-driven calendar month renderer with customizable
|
|
6
|
-
* day content and styling.
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - 42-day grid (6 weeks × 7 days) with Monday-first ordering
|
|
10
|
-
* - Localized weekday headers
|
|
11
|
-
* - Custom day content rendering via dayContentFn
|
|
12
|
-
* - Custom day classes via dayClassesFn
|
|
13
|
-
* - Custom CSS injection via customCSS
|
|
14
|
-
* - Responsive width system (width, minWidth, maxWidth)
|
|
15
|
-
* - Rich day-click events with full context
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```html
|
|
19
|
-
* <!-- Basic usage -->
|
|
20
|
-
* <ty-calendar-month
|
|
21
|
-
* display-year="2025"
|
|
22
|
-
* display-month="10"
|
|
23
|
-
* locale="en-US">
|
|
24
|
-
* </ty-calendar-month>
|
|
25
|
-
*
|
|
26
|
-
* <!-- With custom rendering -->
|
|
27
|
-
* <ty-calendar-month id="custom"></ty-calendar-month>
|
|
28
|
-
* <script type="module">
|
|
29
|
-
* const cal = document.getElementById('custom');
|
|
30
|
-
* cal.dayContentFn = (ctx) => {
|
|
31
|
-
* const el = document.createElement('div');
|
|
32
|
-
* el.textContent = ctx.dayInMonth;
|
|
33
|
-
* return el;
|
|
34
|
-
* };
|
|
35
|
-
* </script>
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
1
|
import { ensureStyles } from '../utils/styles.js';
|
|
39
2
|
import { syncCustomFlavorSheet } from '../utils/flavor-sheet.js';
|
|
40
3
|
import { calendarMonthStyles, calendarMonthCustomFlavorCss } from '../styles/calendar-month.js';
|
|
41
4
|
import { getCalendarMonthDays, getLocalizedWeekdays, parseISODate } from '../utils/calendar-utils.js';
|
|
42
5
|
import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
|
|
43
|
-
// ============================================================================
|
|
44
|
-
// Default Render Functions
|
|
45
|
-
// ============================================================================
|
|
46
|
-
/**
|
|
47
|
-
* Default day content renderer - just the day number
|
|
48
|
-
*/
|
|
49
6
|
function defaultDayContent(dayContext) {
|
|
50
|
-
|
|
7
|
+
return dayContext.dayInMonth.toString();
|
|
51
8
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Default day classes based on day context
|
|
54
|
-
*/
|
|
55
9
|
function getDefaultDayClasses(dayContext) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
// ============================================================================
|
|
68
|
-
// Helper Functions
|
|
69
|
-
// ============================================================================
|
|
70
|
-
/**
|
|
71
|
-
* Check if value is a DOM element
|
|
72
|
-
*/
|
|
10
|
+
const classes = ['calendar-day'];
|
|
11
|
+
if (dayContext.today)
|
|
12
|
+
classes.push('today');
|
|
13
|
+
if (dayContext.weekend)
|
|
14
|
+
classes.push('weekend');
|
|
15
|
+
if (dayContext.otherMonth)
|
|
16
|
+
classes.push('other-month');
|
|
17
|
+
if (dayContext.isSelected)
|
|
18
|
+
classes.push('selected');
|
|
19
|
+
return classes;
|
|
20
|
+
}
|
|
73
21
|
function isDOMElement(value) {
|
|
74
|
-
|
|
22
|
+
return value instanceof HTMLElement;
|
|
75
23
|
}
|
|
76
|
-
/**
|
|
77
|
-
* ISO date string ("YYYY-MM-DD") → UTC-midnight timestamp, matching
|
|
78
|
-
* DayContext.value semantics. null when unset/invalid.
|
|
79
|
-
*/
|
|
80
24
|
function isoToUTCTimestamp(iso) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Normalize size value - add 'px' if just a number
|
|
90
|
-
*/
|
|
25
|
+
if (!iso)
|
|
26
|
+
return null;
|
|
27
|
+
const parsed = parseISODate(iso);
|
|
28
|
+
if (!parsed)
|
|
29
|
+
return null;
|
|
30
|
+
return Date.UTC(parsed.year, parsed.month - 1, parsed.day);
|
|
31
|
+
}
|
|
91
32
|
function normalizeSizeValue(value) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return strValue;
|
|
101
|
-
}
|
|
102
|
-
// ============================================================================
|
|
103
|
-
// Component Implementation
|
|
104
|
-
// ============================================================================
|
|
105
|
-
/**
|
|
106
|
-
* TyCalendarMonth Web Component
|
|
107
|
-
*/
|
|
33
|
+
if (!value || value === '')
|
|
34
|
+
return null;
|
|
35
|
+
const strValue = String(value);
|
|
36
|
+
if (/^\d+(\.\d+)?$/.test(strValue)) {
|
|
37
|
+
return `${strValue}px`;
|
|
38
|
+
}
|
|
39
|
+
return strValue;
|
|
40
|
+
}
|
|
108
41
|
export class TyCalendarMonth extends HTMLElement {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
const minTs = isoToUTCTimestamp(this._min);
|
|
524
|
-
const maxTs = isoToUTCTimestamp(this._max);
|
|
525
|
-
// Roving-tabindex target: keep the persisted index if still valid and
|
|
526
|
-
// not disabled, else fall back to selected day, else today, else the
|
|
527
|
-
// first rendered day — always something focusable exists in the grid.
|
|
528
|
-
const disabledAt = (i) => {
|
|
529
|
-
const v = days[i].value;
|
|
530
|
-
return (minTs !== null && v < minTs) || (maxTs !== null && v > maxTs);
|
|
531
|
-
};
|
|
532
|
-
let defaultIndex = days.findIndex(d => d.isSelected);
|
|
533
|
-
if (defaultIndex === -1)
|
|
534
|
-
defaultIndex = days.findIndex(d => d.today);
|
|
535
|
-
if (defaultIndex === -1)
|
|
536
|
-
defaultIndex = 0;
|
|
537
|
-
if (this._focusedIndex === null ||
|
|
538
|
-
this._focusedIndex < 0 ||
|
|
539
|
-
this._focusedIndex > 41 ||
|
|
540
|
-
disabledAt(this._focusedIndex)) {
|
|
541
|
-
this._focusedIndex = defaultIndex;
|
|
542
|
-
}
|
|
543
|
-
this._cellElements = [];
|
|
544
|
-
let flatIndex = 0;
|
|
545
|
-
dayWeeks.forEach(week => {
|
|
546
|
-
const dayRow = document.createElement('div');
|
|
547
|
-
dayRow.className = 'calendar-row calendar-day-row';
|
|
548
|
-
dayRow.setAttribute('role', 'row');
|
|
549
|
-
week.forEach(dayContext => {
|
|
550
|
-
const disabled = (minTs !== null && dayContext.value < minTs) ||
|
|
551
|
-
(maxTs !== null && dayContext.value > maxTs);
|
|
552
|
-
const dayCell = this.renderDayCell(dayContext, disabled, flatIndex === this._focusedIndex);
|
|
553
|
-
// Add unified cell classes for flex layout
|
|
554
|
-
dayCell.className = `${dayCell.className} calendar-cell calendar-day-cell`;
|
|
555
|
-
dayRow.appendChild(dayCell);
|
|
556
|
-
this._cellElements[flatIndex] = dayCell;
|
|
557
|
-
flatIndex++;
|
|
558
|
-
});
|
|
559
|
-
calendarContainer.appendChild(dayRow);
|
|
560
|
-
});
|
|
561
|
-
// Arrow-key roving-tabindex navigation: Left/Right move a day,
|
|
562
|
-
// Up/Down move a week — pure index arithmetic works because `days` is a
|
|
563
|
-
// flat, chronologically-ordered 42-cell array (Monday-first weeks), so
|
|
564
|
-
// index+1 is always the next calendar day and index+7 the next week.
|
|
565
|
-
// Delegated on the grid (one listener, not 42) — this component is
|
|
566
|
-
// stateless about which month is shown, so moving past the rendered
|
|
567
|
-
// 42-day range just clamps at the edge rather than crossing months.
|
|
568
|
-
calendarContainer.addEventListener('keydown', (event) => {
|
|
569
|
-
const ke = event;
|
|
570
|
-
const delta = ke.key === 'ArrowLeft' ? -1 :
|
|
571
|
-
ke.key === 'ArrowRight' ? 1 :
|
|
572
|
-
ke.key === 'ArrowUp' ? -7 :
|
|
573
|
-
ke.key === 'ArrowDown' ? 7 :
|
|
574
|
-
0;
|
|
575
|
-
if (delta === 0)
|
|
576
|
-
return;
|
|
577
|
-
const currentIndex = this._focusedIndex ?? defaultIndex;
|
|
578
|
-
const nextIndex = currentIndex + delta;
|
|
579
|
-
if (nextIndex < 0 || nextIndex > 41 || disabledAt(nextIndex))
|
|
580
|
-
return;
|
|
581
|
-
ke.preventDefault();
|
|
582
|
-
this._cellElements[currentIndex]?.setAttribute('tabindex', '-1');
|
|
583
|
-
this._focusedIndex = nextIndex;
|
|
584
|
-
const nextCell = this._cellElements[nextIndex];
|
|
585
|
-
if (nextCell) {
|
|
586
|
-
nextCell.setAttribute('tabindex', '0');
|
|
587
|
-
nextCell.focus();
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
root.appendChild(calendarContainer);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
// Register the custom element
|
|
42
|
+
static get observedAttributes() {
|
|
43
|
+
return ['display-year', 'display-month', 'locale', 'size', 'min', 'max', 'flavor'];
|
|
44
|
+
}
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this._locale = 'en-US';
|
|
48
|
+
this._size = 'md';
|
|
49
|
+
this._customFlavorSheet = null;
|
|
50
|
+
this._focusedIndex = null;
|
|
51
|
+
this._cellElements = [];
|
|
52
|
+
const today = new Date();
|
|
53
|
+
this._displayYear = today.getFullYear();
|
|
54
|
+
this._displayMonth = today.getMonth() + 1;
|
|
55
|
+
this.attachShadow({ mode: 'open' });
|
|
56
|
+
}
|
|
57
|
+
connectedCallback() {
|
|
58
|
+
if (!this._displayMonth) {
|
|
59
|
+
this._displayMonth = new Date().getMonth() + 1;
|
|
60
|
+
}
|
|
61
|
+
if (!this._displayYear) {
|
|
62
|
+
this._displayYear = new Date().getFullYear();
|
|
63
|
+
}
|
|
64
|
+
if (!this._locale) {
|
|
65
|
+
this._locale = this.getAttribute('locale') || 'en-US';
|
|
66
|
+
}
|
|
67
|
+
const sizeAttr = this.getAttribute('size');
|
|
68
|
+
if (sizeAttr && (sizeAttr === 'sm' || sizeAttr === 'md' || sizeAttr === 'lg')) {
|
|
69
|
+
this._size = sizeAttr;
|
|
70
|
+
}
|
|
71
|
+
const plainDayContentFn = this.dayContentFn;
|
|
72
|
+
if (plainDayContentFn && !this._dayContentFn) {
|
|
73
|
+
this._dayContentFn = plainDayContentFn;
|
|
74
|
+
delete this.dayContentFn;
|
|
75
|
+
}
|
|
76
|
+
const plainCustomCSS = this.customCSS;
|
|
77
|
+
if (plainCustomCSS && !this._customCSS) {
|
|
78
|
+
this._customCSS = plainCustomCSS;
|
|
79
|
+
delete this.customCSS;
|
|
80
|
+
}
|
|
81
|
+
this._localeObserver = observeLocaleChanges(this, () => {
|
|
82
|
+
this.render();
|
|
83
|
+
});
|
|
84
|
+
this._syncCustomFlavor();
|
|
85
|
+
this.render();
|
|
86
|
+
}
|
|
87
|
+
disconnectedCallback() {
|
|
88
|
+
if (this._localeObserver) {
|
|
89
|
+
this._localeObserver();
|
|
90
|
+
this._localeObserver = undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
94
|
+
if (name === 'display-year' || name === 'display-month') {
|
|
95
|
+
const n = Number(newValue);
|
|
96
|
+
const valid = Number.isInteger(n) && (name === 'display-year' ? n > 0 : n >= 1 && n <= 12);
|
|
97
|
+
if (valid) {
|
|
98
|
+
if (name === 'display-year')
|
|
99
|
+
this.displayYear = n;
|
|
100
|
+
else
|
|
101
|
+
this.displayMonth = n;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (name === 'locale') {
|
|
105
|
+
this._locale = newValue || 'en-US';
|
|
106
|
+
this.render();
|
|
107
|
+
}
|
|
108
|
+
else if (name === 'size') {
|
|
109
|
+
if (newValue === 'sm' || newValue === 'md' || newValue === 'lg') {
|
|
110
|
+
this._size = newValue;
|
|
111
|
+
this.render();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (name === 'min' || name === 'max') {
|
|
115
|
+
this[name === 'min' ? '_min' : '_max'] = newValue ?? undefined;
|
|
116
|
+
this.render();
|
|
117
|
+
}
|
|
118
|
+
else if (name === 'flavor') {
|
|
119
|
+
this._syncCustomFlavor();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
_syncCustomFlavor() {
|
|
123
|
+
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.getAttribute('flavor'), ({ base }) => calendarMonthCustomFlavorCss(base));
|
|
124
|
+
}
|
|
125
|
+
get displayYear() {
|
|
126
|
+
return this._displayYear;
|
|
127
|
+
}
|
|
128
|
+
set displayYear(value) {
|
|
129
|
+
if (this._displayYear !== value) {
|
|
130
|
+
this._displayYear = value;
|
|
131
|
+
this._focusedIndex = null;
|
|
132
|
+
this.render();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
get displayMonth() {
|
|
136
|
+
return this._displayMonth;
|
|
137
|
+
}
|
|
138
|
+
set displayMonth(value) {
|
|
139
|
+
if (this._displayMonth !== value) {
|
|
140
|
+
this._displayMonth = value;
|
|
141
|
+
this._focusedIndex = null;
|
|
142
|
+
this.render();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
get locale() {
|
|
146
|
+
return getEffectiveLocale(this, this.getAttribute('locale'));
|
|
147
|
+
}
|
|
148
|
+
set locale(value) {
|
|
149
|
+
if (this._locale !== value) {
|
|
150
|
+
this._locale = value;
|
|
151
|
+
this.render();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
get size() {
|
|
155
|
+
return this._size;
|
|
156
|
+
}
|
|
157
|
+
set size(value) {
|
|
158
|
+
if (this._size !== value) {
|
|
159
|
+
this._size = value;
|
|
160
|
+
this.render();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
get flavor() {
|
|
164
|
+
return this.getAttribute('flavor') || 'primary';
|
|
165
|
+
}
|
|
166
|
+
set flavor(value) {
|
|
167
|
+
if (value)
|
|
168
|
+
this.setAttribute('flavor', value);
|
|
169
|
+
else
|
|
170
|
+
this.removeAttribute('flavor');
|
|
171
|
+
}
|
|
172
|
+
get width() {
|
|
173
|
+
return this._width;
|
|
174
|
+
}
|
|
175
|
+
set width(value) {
|
|
176
|
+
if (this._width !== value) {
|
|
177
|
+
this._width = value;
|
|
178
|
+
this.applyWidthProperties();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
get minWidth() {
|
|
182
|
+
return this._minWidth;
|
|
183
|
+
}
|
|
184
|
+
set minWidth(value) {
|
|
185
|
+
if (this._minWidth !== value) {
|
|
186
|
+
this._minWidth = value;
|
|
187
|
+
this.applyWidthProperties();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
get maxWidth() {
|
|
191
|
+
return this._maxWidth;
|
|
192
|
+
}
|
|
193
|
+
set maxWidth(value) {
|
|
194
|
+
if (this._maxWidth !== value) {
|
|
195
|
+
this._maxWidth = value;
|
|
196
|
+
this.applyWidthProperties();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
get dayContentFn() {
|
|
200
|
+
return this._dayContentFn;
|
|
201
|
+
}
|
|
202
|
+
set dayContentFn(fn) {
|
|
203
|
+
if (this._dayContentFn !== fn) {
|
|
204
|
+
this._dayContentFn = fn;
|
|
205
|
+
this.render();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
get customCSS() {
|
|
209
|
+
return this._customCSS;
|
|
210
|
+
}
|
|
211
|
+
set customCSS(sheet) {
|
|
212
|
+
if (this._customCSS !== sheet) {
|
|
213
|
+
this._customCSS = sheet;
|
|
214
|
+
this.applyCustomCSS();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
get min() {
|
|
218
|
+
return this._min;
|
|
219
|
+
}
|
|
220
|
+
set min(value) {
|
|
221
|
+
if (this._min !== value) {
|
|
222
|
+
this._min = value;
|
|
223
|
+
this.render();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
get max() {
|
|
227
|
+
return this._max;
|
|
228
|
+
}
|
|
229
|
+
set max(value) {
|
|
230
|
+
if (this._max !== value) {
|
|
231
|
+
this._max = value;
|
|
232
|
+
this.render();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
get value() {
|
|
236
|
+
return this._value;
|
|
237
|
+
}
|
|
238
|
+
set value(timestamp) {
|
|
239
|
+
const newValue = timestamp ?? undefined;
|
|
240
|
+
if (this._value !== newValue) {
|
|
241
|
+
this._value = newValue;
|
|
242
|
+
this.render();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
applyWidthProperties() {
|
|
246
|
+
const normalizedWidth = normalizeSizeValue(this._width);
|
|
247
|
+
const normalizedMinWidth = normalizeSizeValue(this._minWidth);
|
|
248
|
+
const normalizedMaxWidth = normalizeSizeValue(this._maxWidth);
|
|
249
|
+
if (normalizedWidth) {
|
|
250
|
+
this.style.setProperty('--calendar-width', normalizedWidth);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this.style.removeProperty('--calendar-width');
|
|
254
|
+
}
|
|
255
|
+
if (normalizedMinWidth) {
|
|
256
|
+
this.style.setProperty('--calendar-min-width', normalizedMinWidth);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
this.style.removeProperty('--calendar-min-width');
|
|
260
|
+
}
|
|
261
|
+
if (normalizedMaxWidth) {
|
|
262
|
+
this.style.setProperty('--calendar-max-width', normalizedMaxWidth);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
this.style.removeProperty('--calendar-max-width');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
applyCustomCSS() {
|
|
269
|
+
if (!this._customCSS || !this.shadowRoot)
|
|
270
|
+
return;
|
|
271
|
+
const existing = this.shadowRoot.adoptedStyleSheets;
|
|
272
|
+
if (!existing.includes(this._customCSS)) {
|
|
273
|
+
this.shadowRoot.adoptedStyleSheets = [...existing, this._customCSS];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
refresh() {
|
|
277
|
+
this.render();
|
|
278
|
+
}
|
|
279
|
+
dispatchDayClick(dayContext, _domEvent) {
|
|
280
|
+
const detail = {
|
|
281
|
+
dayContext,
|
|
282
|
+
value: dayContext.value,
|
|
283
|
+
year: dayContext.year,
|
|
284
|
+
month: dayContext.month,
|
|
285
|
+
day: dayContext.dayInMonth,
|
|
286
|
+
isHoliday: dayContext.holiday,
|
|
287
|
+
isToday: dayContext.today,
|
|
288
|
+
isWeekend: dayContext.weekend,
|
|
289
|
+
isOtherMonth: dayContext.otherMonth,
|
|
290
|
+
};
|
|
291
|
+
for (const eventType of ['day-click', 'day-select']) {
|
|
292
|
+
const event = new CustomEvent(eventType, {
|
|
293
|
+
detail,
|
|
294
|
+
bubbles: true,
|
|
295
|
+
cancelable: true,
|
|
296
|
+
});
|
|
297
|
+
this.dispatchEvent(event);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
renderDayCell(dayContext, disabled, isRoving) {
|
|
301
|
+
const dayElement = document.createElement('div');
|
|
302
|
+
const content = this._dayContentFn
|
|
303
|
+
? this._dayContentFn(dayContext)
|
|
304
|
+
: defaultDayContent(dayContext);
|
|
305
|
+
if (this._dayContentFn && content && !isDOMElement(content) && typeof content !== 'string') {
|
|
306
|
+
throw new Error(`Custom dayContentFn must return a DOM element or string, got: ${typeof content}. ` +
|
|
307
|
+
`Use document.createElement() to create DOM elements.`);
|
|
308
|
+
}
|
|
309
|
+
const classes = getDefaultDayClasses(dayContext);
|
|
310
|
+
if (disabled)
|
|
311
|
+
classes.push('disabled');
|
|
312
|
+
dayElement.className = classes.join(' ');
|
|
313
|
+
if (typeof content === 'string') {
|
|
314
|
+
dayElement.textContent = content;
|
|
315
|
+
}
|
|
316
|
+
else if (isDOMElement(content)) {
|
|
317
|
+
dayElement.appendChild(content);
|
|
318
|
+
}
|
|
319
|
+
dayElement.setAttribute('role', 'gridcell');
|
|
320
|
+
dayElement.setAttribute('aria-label', new Intl.DateTimeFormat(this._locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
|
321
|
+
.format(new Date(dayContext.localValue)));
|
|
322
|
+
dayElement.setAttribute('aria-selected', String(!!dayContext.isSelected));
|
|
323
|
+
if (dayContext.today)
|
|
324
|
+
dayElement.setAttribute('aria-current', 'date');
|
|
325
|
+
if (disabled) {
|
|
326
|
+
dayElement.setAttribute('aria-disabled', 'true');
|
|
327
|
+
dayElement.setAttribute('tabindex', '-1');
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
dayElement.setAttribute('tabindex', isRoving ? '0' : '-1');
|
|
331
|
+
dayElement.addEventListener('pointerdown', (event) => {
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
this.dispatchDayClick(dayContext, event);
|
|
334
|
+
});
|
|
335
|
+
dayElement.addEventListener('keydown', (event) => {
|
|
336
|
+
const ke = event;
|
|
337
|
+
if (ke.key === 'Enter' || ke.key === ' ') {
|
|
338
|
+
ke.preventDefault();
|
|
339
|
+
this.dispatchDayClick(dayContext, event);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return dayElement;
|
|
344
|
+
}
|
|
345
|
+
render() {
|
|
346
|
+
const root = this.shadowRoot;
|
|
347
|
+
if (!root)
|
|
348
|
+
return;
|
|
349
|
+
ensureStyles(root, { css: calendarMonthStyles, id: 'ty-calendar-month' });
|
|
350
|
+
this.applyCustomCSS();
|
|
351
|
+
this.applyWidthProperties();
|
|
352
|
+
let selection;
|
|
353
|
+
if (this._value) {
|
|
354
|
+
const date = new Date(this._value);
|
|
355
|
+
selection = {
|
|
356
|
+
year: date.getFullYear(),
|
|
357
|
+
month: date.getMonth() + 1,
|
|
358
|
+
day: date.getDate()
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const days = getCalendarMonthDays(this._displayYear, this._displayMonth, selection);
|
|
362
|
+
const weekdays = getLocalizedWeekdays(this._locale, 'short');
|
|
363
|
+
root.innerHTML = '';
|
|
364
|
+
const calendarContainer = document.createElement('div');
|
|
365
|
+
calendarContainer.className = `calendar-flex-container calendar-size-${this._size}`;
|
|
366
|
+
calendarContainer.setAttribute('role', 'grid');
|
|
367
|
+
calendarContainer.setAttribute('aria-label', new Intl.DateTimeFormat(this._locale, { month: 'long', year: 'numeric' })
|
|
368
|
+
.format(new Date(this._displayYear, this._displayMonth - 1, 1)));
|
|
369
|
+
const headerRow = document.createElement('div');
|
|
370
|
+
headerRow.className = 'calendar-row calendar-header-row';
|
|
371
|
+
headerRow.setAttribute('role', 'row');
|
|
372
|
+
weekdays.forEach(weekday => {
|
|
373
|
+
const headerCell = document.createElement('div');
|
|
374
|
+
headerCell.className = 'calendar-cell calendar-header-cell';
|
|
375
|
+
headerCell.setAttribute('role', 'columnheader');
|
|
376
|
+
headerCell.textContent = weekday;
|
|
377
|
+
headerRow.appendChild(headerCell);
|
|
378
|
+
});
|
|
379
|
+
calendarContainer.appendChild(headerRow);
|
|
380
|
+
const dayWeeks = [];
|
|
381
|
+
for (let i = 0; i < 42; i += 7) {
|
|
382
|
+
dayWeeks.push(days.slice(i, i + 7));
|
|
383
|
+
}
|
|
384
|
+
const minTs = isoToUTCTimestamp(this._min);
|
|
385
|
+
const maxTs = isoToUTCTimestamp(this._max);
|
|
386
|
+
const disabledAt = (i) => {
|
|
387
|
+
const v = days[i].value;
|
|
388
|
+
return (minTs !== null && v < minTs) || (maxTs !== null && v > maxTs);
|
|
389
|
+
};
|
|
390
|
+
const firstEnabled = (pred) => {
|
|
391
|
+
for (let i = 0; i < 42; i++) {
|
|
392
|
+
if (pred(i) && !disabledAt(i))
|
|
393
|
+
return i;
|
|
394
|
+
}
|
|
395
|
+
return -1;
|
|
396
|
+
};
|
|
397
|
+
let defaultIndex = firstEnabled(i => !!days[i].isSelected);
|
|
398
|
+
let provisional = false;
|
|
399
|
+
if (defaultIndex === -1)
|
|
400
|
+
defaultIndex = firstEnabled(i => !!days[i].today);
|
|
401
|
+
if (defaultIndex === -1) {
|
|
402
|
+
defaultIndex = firstEnabled(() => true);
|
|
403
|
+
provisional = true;
|
|
404
|
+
}
|
|
405
|
+
if (defaultIndex === -1)
|
|
406
|
+
defaultIndex = 0;
|
|
407
|
+
if (this._focusedIndex === null ||
|
|
408
|
+
this._focusedIndex < 0 ||
|
|
409
|
+
this._focusedIndex > 41 ||
|
|
410
|
+
disabledAt(this._focusedIndex)) {
|
|
411
|
+
this._focusedIndex = provisional ? null : defaultIndex;
|
|
412
|
+
}
|
|
413
|
+
const effectiveFocusedIndex = this._focusedIndex ?? defaultIndex;
|
|
414
|
+
this._cellElements = [];
|
|
415
|
+
let flatIndex = 0;
|
|
416
|
+
dayWeeks.forEach(week => {
|
|
417
|
+
const dayRow = document.createElement('div');
|
|
418
|
+
dayRow.className = 'calendar-row calendar-day-row';
|
|
419
|
+
dayRow.setAttribute('role', 'row');
|
|
420
|
+
week.forEach(dayContext => {
|
|
421
|
+
const disabled = (minTs !== null && dayContext.value < minTs) ||
|
|
422
|
+
(maxTs !== null && dayContext.value > maxTs);
|
|
423
|
+
const dayCell = this.renderDayCell(dayContext, disabled, flatIndex === effectiveFocusedIndex);
|
|
424
|
+
dayCell.className = `${dayCell.className} calendar-cell calendar-day-cell`;
|
|
425
|
+
dayRow.appendChild(dayCell);
|
|
426
|
+
this._cellElements[flatIndex] = dayCell;
|
|
427
|
+
flatIndex++;
|
|
428
|
+
});
|
|
429
|
+
calendarContainer.appendChild(dayRow);
|
|
430
|
+
});
|
|
431
|
+
calendarContainer.addEventListener('keydown', (event) => {
|
|
432
|
+
const ke = event;
|
|
433
|
+
const delta = ke.key === 'ArrowLeft' ? -1 :
|
|
434
|
+
ke.key === 'ArrowRight' ? 1 :
|
|
435
|
+
ke.key === 'ArrowUp' ? -7 :
|
|
436
|
+
ke.key === 'ArrowDown' ? 7 :
|
|
437
|
+
0;
|
|
438
|
+
if (delta === 0)
|
|
439
|
+
return;
|
|
440
|
+
const currentIndex = this._focusedIndex ?? defaultIndex;
|
|
441
|
+
const nextIndex = currentIndex + delta;
|
|
442
|
+
if (nextIndex < 0 || nextIndex > 41 || disabledAt(nextIndex))
|
|
443
|
+
return;
|
|
444
|
+
ke.preventDefault();
|
|
445
|
+
this._cellElements[currentIndex]?.setAttribute('tabindex', '-1');
|
|
446
|
+
this._focusedIndex = nextIndex;
|
|
447
|
+
const nextCell = this._cellElements[nextIndex];
|
|
448
|
+
if (nextCell) {
|
|
449
|
+
nextCell.setAttribute('tabindex', '0');
|
|
450
|
+
nextCell.focus();
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
root.appendChild(calendarContainer);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
594
456
|
if (!customElements.get('ty-calendar-month')) {
|
|
595
|
-
|
|
457
|
+
customElements.define('ty-calendar-month', TyCalendarMonth);
|
|
596
458
|
}
|
|
597
|
-
//# sourceMappingURL=calendar-month.js.map
|