tyrell-components 1.0.0-TC9 → 1.0.0-rc.21
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/AGENTS.md +122 -0
- package/CHANGELOG.md +1531 -0
- package/README.md +71 -53
- package/css/tyrell-colors-static.css +1 -0
- package/css/tyrell-theme.css +1 -0
- package/css/tyrell.css +1 -1783
- package/dist/tyrell-colors-static.css +1 -0
- package/dist/tyrell-theme.css +1 -0
- package/dist/tyrell.css +1 -1783
- package/dist/tyrell.js +1 -1
- package/guides/AGENT_INSTRUCTIONS.md +124 -0
- package/guides/AI_GUIDE.md +53 -0
- package/guides/CSS_GUIDE.md +1016 -0
- package/guides/DATASTAR_TY_GUIDE.md +657 -0
- package/guides/ICONS_GUIDE.md +212 -0
- package/guides/TY_GUIDE.md +935 -0
- package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
- package/guides/clj/CODE_SPLITTING.md +279 -0
- package/guides/clj/COMPONENT_GUIDE.md +391 -0
- package/guides/clj/HELIX_TY_GUIDE.md +428 -0
- package/guides/clj/I18N_GUIDE.md +478 -0
- package/guides/clj/LAYOUT_GUIDE.md +273 -0
- package/guides/clj/QUICKSTART.md +266 -0
- package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
- package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
- package/guides/clj/ROUTING_GUIDE.md +346 -0
- package/guides/clj/UIX_TY_GUIDE.md +319 -0
- package/guides/js/HTMX_TY_GUIDE.md +252 -0
- package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
- package/guides/js/REACT_TY_GUIDE.md +983 -0
- package/guides/js/SVELTE_TY_GUIDE.md +682 -0
- package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
- package/guides/js/VUE_TY_GUIDE.md +738 -0
- package/lib/base/ty-component.d.ts +57 -13
- package/lib/base/ty-component.js +266 -292
- package/lib/components/button.d.ts +33 -18
- package/lib/components/button.js +317 -267
- package/lib/components/calendar-month.d.ts +30 -47
- package/lib/components/calendar-month.js +455 -429
- package/lib/components/calendar-navigation.d.ts +41 -49
- package/lib/components/calendar-navigation.js +287 -346
- package/lib/components/calendar.d.ts +73 -83
- package/lib/components/calendar.js +837 -762
- package/lib/components/checkbox.d.ts +26 -75
- package/lib/components/checkbox.js +298 -391
- package/lib/components/copy.d.ts +20 -60
- package/lib/components/copy.js +276 -380
- package/lib/components/date-picker.d.ts +100 -183
- package/lib/components/date-picker.js +1155 -1570
- package/lib/components/file-upload.d.ts +16 -15
- package/lib/components/file-upload.js +436 -426
- package/lib/components/icon.d.ts +3 -24
- package/lib/components/icon.js +141 -230
- package/lib/components/input.d.ts +93 -108
- package/lib/components/input.js +734 -710
- package/lib/components/modal.d.ts +39 -29
- package/lib/components/modal.js +419 -438
- package/lib/components/option.d.ts +20 -35
- package/lib/components/option.js +184 -309
- package/lib/components/popup.d.ts +2 -17
- package/lib/components/popup.js +353 -347
- package/lib/components/radio.d.ts +33 -25
- package/lib/components/radio.js +433 -422
- package/lib/components/resize-observer.d.ts +3 -30
- package/lib/components/resize-observer.js +71 -103
- package/lib/components/scroll-container.d.ts +21 -14
- package/lib/components/scroll-container.js +292 -234
- package/lib/components/select.d.ts +446 -0
- package/lib/components/select.js +1381 -0
- package/lib/components/selected-tags.d.ts +60 -0
- package/lib/components/selected-tags.js +225 -0
- package/lib/components/sortable.d.ts +175 -0
- package/lib/components/sortable.js +1844 -0
- package/lib/components/step.d.ts +1 -6
- package/lib/components/step.js +62 -68
- package/lib/components/switch.d.ts +15 -15
- package/lib/components/switch.js +237 -231
- package/lib/components/tab.d.ts +50 -7
- package/lib/components/tab.js +203 -69
- package/lib/components/tabs.d.ts +19 -64
- package/lib/components/tabs.js +600 -618
- package/lib/components/tag.d.ts +14 -52
- package/lib/components/tag.js +231 -306
- package/lib/components/textarea.d.ts +58 -89
- package/lib/components/textarea.js +523 -573
- package/lib/components/tooltip.d.ts +8 -13
- package/lib/components/tooltip.js +322 -409
- package/lib/components/wizard.d.ts +7 -54
- package/lib/components/wizard.js +376 -606
- 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 +7 -4
- package/lib/index.js +26 -39
- package/lib/styles/button.d.ts +24 -7
- package/lib/styles/button.js +285 -445
- package/lib/styles/calendar-month.d.ts +7 -6
- package/lib/styles/calendar-month.js +158 -226
- package/lib/styles/calendar-navigation.d.ts +2 -6
- package/lib/styles/calendar-navigation.js +108 -127
- package/lib/styles/calendar.d.ts +3 -3
- package/lib/styles/calendar.js +87 -23
- package/lib/styles/checkbox.d.ts +7 -6
- package/lib/styles/checkbox.js +101 -15
- package/lib/styles/copy.d.ts +3 -2
- package/lib/styles/copy.js +91 -71
- package/lib/styles/custom-scrollbar.d.ts +1 -2
- package/lib/styles/custom-scrollbar.js +80 -115
- package/lib/styles/date-picker.d.ts +4 -6
- package/lib/styles/date-picker.js +321 -388
- 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 +4 -7
- package/lib/styles/input.js +148 -643
- package/lib/styles/modal.d.ts +1 -2
- package/lib/styles/modal.js +127 -108
- package/lib/styles/option.d.ts +2 -6
- package/lib/styles/option.js +53 -96
- package/lib/styles/popup.d.ts +1 -2
- package/lib/styles/popup.js +47 -77
- package/lib/styles/radio.d.ts +3 -2
- package/lib/styles/radio.js +90 -116
- 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 +103 -146
- package/lib/styles/select-base.d.ts +8 -0
- package/lib/styles/select-base.js +747 -0
- package/lib/styles/select.d.ts +11 -0
- package/lib/styles/select.js +229 -0
- package/lib/styles/sortable.d.ts +16 -0
- package/lib/styles/sortable.js +85 -0
- package/lib/styles/step.d.ts +1 -2
- package/lib/styles/step.js +15 -34
- package/lib/styles/switch.d.ts +3 -2
- package/lib/styles/switch.js +52 -68
- package/lib/styles/tab.d.ts +1 -2
- package/lib/styles/tab.js +86 -34
- package/lib/styles/tabs.d.ts +3 -11
- package/lib/styles/tabs.js +204 -162
- package/lib/styles/tag.d.ts +2 -6
- package/lib/styles/tag.js +168 -362
- package/lib/styles/textarea.d.ts +1 -2
- package/lib/styles/textarea.js +238 -306
- package/lib/styles/tooltip.d.ts +4 -3
- package/lib/styles/tooltip.js +3 -131
- package/lib/styles/wizard.d.ts +8 -20
- package/lib/styles/wizard.js +306 -295
- package/lib/types/common.d.ts +9 -8
- package/lib/types/common.js +8 -5
- package/lib/utils/calendar-utils.d.ts +49 -65
- package/lib/utils/calendar-utils.js +158 -343
- package/lib/utils/custom-scrollbar.d.ts +6 -20
- package/lib/utils/custom-scrollbar.js +273 -317
- package/lib/utils/flavor-sheet.d.ts +31 -0
- package/lib/utils/flavor-sheet.js +17 -0
- package/lib/utils/icon-registry.d.ts +0 -15
- package/lib/utils/icon-registry.js +138 -279
- package/lib/utils/icons.d.ts +9 -0
- package/lib/utils/icons.js +1 -0
- package/lib/utils/loader-registry.d.ts +2 -3
- package/lib/utils/loader-registry.js +3 -35
- package/lib/utils/locale.d.ts +2 -80
- package/lib/utils/locale.js +30 -205
- package/lib/utils/mobile.d.ts +0 -1
- package/lib/utils/mobile.js +1 -18
- package/lib/utils/number-format.d.ts +6 -24
- package/lib/utils/number-format.js +53 -136
- package/lib/utils/positioning.d.ts +72 -22
- package/lib/utils/positioning.js +224 -298
- package/lib/utils/property-capture.d.ts +5 -27
- package/lib/utils/property-capture.js +36 -144
- package/lib/utils/property-manager.d.ts +6 -6
- package/lib/utils/property-manager.js +127 -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 +10 -11
- package/lib/utils/scroll-lock.js +165 -173
- package/lib/utils/styles.d.ts +0 -6
- package/lib/utils/styles.js +17 -48
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -2
- package/lib/version.js +1 -11
- package/package.json +62 -18
- 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/dropdown.d.ts +0 -404
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -1563
- package/lib/components/dropdown.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/multiselect.d.ts +0 -408
- package/lib/components/multiselect.d.ts.map +0 -1
- package/lib/components/multiselect.js +0 -1611
- package/lib/components/multiselect.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/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/dropdown.d.ts +0 -12
- package/lib/styles/dropdown.d.ts.map +0 -1
- package/lib/styles/dropdown.js +0 -1048
- package/lib/styles/dropdown.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 -6
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -837
- 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/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/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.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,1586 +1,1171 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TyDatePicker Web Component
|
|
3
|
-
* PORTED FROM: cljs/ty/components/date_picker.cljs
|
|
4
|
-
*
|
|
5
|
-
* A date picker component with read-only input and calendar dropdown.
|
|
6
|
-
* Supports date-only and date+time modes with smart time input.
|
|
7
|
-
*
|
|
8
|
-
* Architecture:
|
|
9
|
-
* - Read-only input stub (displays formatted date)
|
|
10
|
-
* - Calendar dropdown (modal dialog with ty-calendar)
|
|
11
|
-
* - Optional time input (with smart digit navigation)
|
|
12
|
-
* - Form participation via ElementInternals
|
|
13
|
-
* - UTC output, local display
|
|
14
|
-
*
|
|
15
|
-
* Features:
|
|
16
|
-
* - Date selection with calendar dropdown
|
|
17
|
-
* - Optional time input with smart navigation
|
|
18
|
-
* - Form integration (works with FormData)
|
|
19
|
-
* - UTC value output for server communication
|
|
20
|
-
* - Localized display formatting (Intl API)
|
|
21
|
-
* - Clearable with clear button
|
|
22
|
-
* - Keyboard navigation (Escape to close)
|
|
23
|
-
* - Outside click handling
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```html
|
|
27
|
-
* <!-- Basic date picker -->
|
|
28
|
-
* <ty-date-picker
|
|
29
|
-
* label="Select Date"
|
|
30
|
-
* placeholder="Choose a date">
|
|
31
|
-
* </ty-date-picker>
|
|
32
|
-
*
|
|
33
|
-
* <!-- With time -->
|
|
34
|
-
* <ty-date-picker
|
|
35
|
-
* with-time="true"
|
|
36
|
-
* label="Select Date & Time">
|
|
37
|
-
* </ty-date-picker>
|
|
38
|
-
*
|
|
39
|
-
* <!-- Form integration -->
|
|
40
|
-
* <form>
|
|
41
|
-
* <ty-date-picker name="booking-date"></ty-date-picker>
|
|
42
|
-
* <button type="submit">Submit</button>
|
|
43
|
-
* </form>
|
|
44
|
-
*
|
|
45
|
-
* <!-- Pre-filled value (UTC) -->
|
|
46
|
-
* <ty-date-picker value="2024-09-21T08:30:00.000Z"></ty-date-picker>
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
1
|
import { ensureStyles } from '../utils/styles.js';
|
|
50
|
-
import {
|
|
2
|
+
import { syncCustomFlavorSheet } from '../utils/flavor-sheet.js';
|
|
3
|
+
import { datePickerStyles, datePickerCustomFlavorCss } from '../styles/date-picker.js';
|
|
51
4
|
import { lockScroll, unlockScroll } from '../utils/scroll-lock.js';
|
|
5
|
+
import { computeAnchoredPosition, placementToAnchored } from '../utils/positioning.js';
|
|
52
6
|
import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
|
|
53
7
|
import { isMobileTouch } from '../utils/mobile.js';
|
|
54
8
|
import { TyComponent } from '../base/ty-component.js';
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
9
|
+
import { DEFAULT_SIZE } from '../types/common.js';
|
|
10
|
+
import { nativeMessage } from '../utils/validity.js';
|
|
11
|
+
import { parseDateTime, toISODay, wallClockDate } from '../utils/calendar-utils.js';
|
|
58
12
|
const CALENDAR_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='16' height='16' xmlns='http://www.w3.org/2000/svg'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>`;
|
|
59
13
|
const CLEAR_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='14' height='14' xmlns='http://www.w3.org/2000/svg'><line x1='18' y1='6' x2='6' y2='18'></line><line x1='6' y1='6' x2='18' y2='18'></line></svg>`;
|
|
60
14
|
const SCHEDULE_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='16' height='16' xmlns='http://www.w3.org/2000/svg'><circle cx='12' cy='12' r='10'></circle><polyline points='12,6 12,12 16,14'></polyline></svg>`;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* - With timezone: '2024-09-21T10:30:00+02:00'
|
|
72
|
-
*
|
|
73
|
-
* Always extracts components in LOCAL timezone for display/editing.
|
|
74
|
-
*
|
|
75
|
-
* PORTED FROM: parse-value in date_picker.cljs
|
|
76
|
-
*/
|
|
77
|
-
function parseValue(value, withTime) {
|
|
78
|
-
if (!value)
|
|
79
|
-
return null;
|
|
80
|
-
let dateObj = null;
|
|
81
|
-
if (typeof value === 'string') {
|
|
82
|
-
// Date-only format: YYYY-MM-DD
|
|
83
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
84
|
-
const [yearStr, monthStr, dayStr] = value.split('-');
|
|
85
|
-
const year = parseInt(yearStr, 10);
|
|
86
|
-
const month = parseInt(monthStr, 10) - 1; // 0-based for JS Date
|
|
87
|
-
const day = parseInt(dayStr, 10);
|
|
88
|
-
// Create at midnight local time
|
|
89
|
-
dateObj = new Date(year, month, day, 0, 0, 0, 0);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
// Let JS Date handle datetime-local, UTC, with timezone
|
|
93
|
-
dateObj = new Date(value);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else if (typeof value === 'number') {
|
|
97
|
-
// Numeric inputs (milliseconds)
|
|
98
|
-
dateObj = new Date(value);
|
|
99
|
-
}
|
|
100
|
-
if (!dateObj || isNaN(dateObj.getTime())) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
// Extract components in LOCAL timezone for display
|
|
104
|
-
const components = {
|
|
105
|
-
year: dateObj.getFullYear(),
|
|
106
|
-
month: dateObj.getMonth() + 1, // Convert to 1-based
|
|
107
|
-
day: dateObj.getDate(),
|
|
108
|
-
hour: withTime ? dateObj.getHours() : 0,
|
|
109
|
-
minute: withTime ? dateObj.getMinutes() : 0,
|
|
110
|
-
};
|
|
111
|
-
return components;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Convert internal components to Date object.
|
|
115
|
-
*
|
|
116
|
-
* PORTED FROM: components->date-object in date_picker.cljs
|
|
117
|
-
*/
|
|
15
|
+
const elementIds = new WeakMap();
|
|
16
|
+
let elementIdCounter = 0;
|
|
17
|
+
function getElementHash(element) {
|
|
18
|
+
let id = elementIds.get(element);
|
|
19
|
+
if (id === undefined) {
|
|
20
|
+
id = ++elementIdCounter;
|
|
21
|
+
elementIds.set(element, id);
|
|
22
|
+
}
|
|
23
|
+
return id;
|
|
24
|
+
}
|
|
118
25
|
function componentsToDateObject(components) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (!components.year || !components.month || !components.day) {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
const dateObj = componentsToDateObject(components);
|
|
146
|
-
return dateObj ? dateObj.toISOString() : null;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Convert internal components to local datetime-local format.
|
|
150
|
-
*
|
|
151
|
-
* For date+time mode: Outputs local datetime without timezone
|
|
152
|
-
* Example: '2024-09-21T10:30'
|
|
153
|
-
*
|
|
154
|
-
* For date-only mode: Outputs date only
|
|
155
|
-
* Example: '2024-09-21'
|
|
156
|
-
*
|
|
157
|
-
* This format matches HTML5 <input type="datetime-local"> and is useful
|
|
158
|
-
* for setting other inputs or displaying local time without timezone conversion.
|
|
159
|
-
*/
|
|
26
|
+
const { year, month, day, hour, minute, second } = components;
|
|
27
|
+
if (!year || !month || !day)
|
|
28
|
+
return null;
|
|
29
|
+
const date = new Date(2000, 0, 1, 12);
|
|
30
|
+
date.setFullYear(year, month - 1, day);
|
|
31
|
+
date.setHours(hour || 0, minute || 0, second || 0, 0);
|
|
32
|
+
return date;
|
|
33
|
+
}
|
|
34
|
+
function effectiveComponents(components, withTime) {
|
|
35
|
+
return withTime ? components : { ...components, hour: 0, minute: 0, second: 0, epoch: undefined };
|
|
36
|
+
}
|
|
37
|
+
function componentsToOutputValue(components, withTime, native) {
|
|
38
|
+
if (!components.year || !components.month || !components.day) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const c = effectiveComponents(components, withTime);
|
|
42
|
+
if (native)
|
|
43
|
+
return componentsToLocalValue(c, withTime);
|
|
44
|
+
if (c.epoch !== undefined)
|
|
45
|
+
return new Date(c.epoch).toISOString();
|
|
46
|
+
const dateObj = componentsToDateObject(c);
|
|
47
|
+
return dateObj ? dateObj.toISOString() : null;
|
|
48
|
+
}
|
|
160
49
|
function componentsToLocalValue(components, withTime) {
|
|
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
|
-
this.element = element;
|
|
309
|
-
this.datePickerElement = datePickerElement;
|
|
310
|
-
// Initialize state
|
|
311
|
-
const display = formatTimeDisplay(hour, minute);
|
|
312
|
-
const rawDigits = hour.toString().padStart(2, '0') + minute.toString().padStart(2, '0');
|
|
313
|
-
this.state = {
|
|
314
|
-
hour,
|
|
315
|
-
minute,
|
|
316
|
-
caretPosition: 0,
|
|
317
|
-
displayValue: display,
|
|
318
|
-
rawDigits,
|
|
319
|
-
};
|
|
320
|
-
// Set initial value
|
|
321
|
-
this.element.value = display;
|
|
322
|
-
// Bind event handlers
|
|
323
|
-
this.setupEventListeners();
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Setup all event listeners for the time input
|
|
327
|
-
*/
|
|
328
|
-
setupEventListeners() {
|
|
329
|
-
this.element.addEventListener('keydown', (e) => this.handleKeyDown(e));
|
|
330
|
-
this.element.addEventListener('input', (e) => this.handleInput(e));
|
|
331
|
-
this.element.addEventListener('click', (e) => this.handleClick(e));
|
|
332
|
-
this.element.addEventListener('focus', (e) => this.handleFocus(e));
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Handle keydown events
|
|
336
|
-
*/
|
|
337
|
-
handleKeyDown(event) {
|
|
338
|
-
const key = event.key;
|
|
339
|
-
switch (key) {
|
|
340
|
-
case 'ArrowRight':
|
|
341
|
-
this.handleArrowRight(event);
|
|
342
|
-
break;
|
|
343
|
-
case 'ArrowLeft':
|
|
344
|
-
this.handleArrowLeft(event);
|
|
345
|
-
break;
|
|
346
|
-
case 'Backspace':
|
|
347
|
-
this.handleBackspace(event);
|
|
348
|
-
break;
|
|
349
|
-
case 'Delete':
|
|
350
|
-
this.handleDelete(event);
|
|
351
|
-
break;
|
|
352
|
-
case 'Home':
|
|
353
|
-
event.preventDefault();
|
|
354
|
-
this.updateState({ caretPosition: 0 });
|
|
355
|
-
break;
|
|
356
|
-
case 'End':
|
|
357
|
-
event.preventDefault();
|
|
358
|
-
this.updateState({ caretPosition: 5 });
|
|
359
|
-
break;
|
|
360
|
-
case 'Tab':
|
|
361
|
-
// Allow default tab behavior
|
|
362
|
-
break;
|
|
363
|
-
default:
|
|
364
|
-
// Handle digit input
|
|
365
|
-
if (/^\d$/.test(key)) {
|
|
366
|
-
this.handleDigitInput(event, parseInt(key, 10));
|
|
367
|
-
}
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Handle input events (prevent default browser input)
|
|
373
|
-
*/
|
|
374
|
-
handleInput(event) {
|
|
375
|
-
event.preventDefault();
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Handle click events - position cursor at first digit
|
|
379
|
-
*/
|
|
380
|
-
handleClick(event) {
|
|
381
|
-
this.updateState({ caretPosition: 0 });
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Handle focus events - position cursor at first digit
|
|
385
|
-
*/
|
|
386
|
-
handleFocus(event) {
|
|
387
|
-
this.updateState({ caretPosition: 0 });
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Handle arrow right - move to next editable position
|
|
391
|
-
*
|
|
392
|
-
* PORTED FROM: handle-time-arrow-right! in date_picker.cljs
|
|
393
|
-
*/
|
|
394
|
-
handleArrowRight(event) {
|
|
395
|
-
event.preventDefault();
|
|
396
|
-
const nextPos = findNextEditablePosition(this.state.caretPosition);
|
|
397
|
-
this.updateState({ caretPosition: nextPos });
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Handle arrow left - move to previous editable position
|
|
401
|
-
*
|
|
402
|
-
* PORTED FROM: handle-time-arrow-left! in date_picker.cljs
|
|
403
|
-
*/
|
|
404
|
-
handleArrowLeft(event) {
|
|
405
|
-
event.preventDefault();
|
|
406
|
-
const prevPos = findPrevEditablePosition(this.state.caretPosition);
|
|
407
|
-
this.updateState({ caretPosition: prevPos });
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Handle digit input - replace digit at cursor position
|
|
411
|
-
*
|
|
412
|
-
* PORTED FROM: handle-time-digit-input! in date_picker.cljs
|
|
413
|
-
*/
|
|
414
|
-
handleDigitInput(event, digit) {
|
|
415
|
-
event.preventDefault();
|
|
416
|
-
const currentPos = this.state.caretPosition;
|
|
417
|
-
// Only process if at editable position and digit is valid
|
|
418
|
-
if (![0, 1, 3, 4].includes(currentPos))
|
|
419
|
-
return;
|
|
420
|
-
if (!validateTimeDigit(digit, currentPos, this.state.rawDigits))
|
|
421
|
-
return;
|
|
422
|
-
// Replace digit at current position
|
|
423
|
-
const newState = this.replaceDigitAtPosition(currentPos, digit);
|
|
424
|
-
if (!newState)
|
|
425
|
-
return;
|
|
426
|
-
// Move to next position
|
|
427
|
-
const nextPos = findNextEditablePosition(currentPos);
|
|
428
|
-
this.updateState({ ...newState, caretPosition: nextPos });
|
|
429
|
-
// Notify date picker of time change
|
|
430
|
-
this.notifyTimeChange();
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Handle backspace - zero digit and move back
|
|
434
|
-
*
|
|
435
|
-
* PORTED FROM: handle-time-backspace! in date_picker.cljs
|
|
436
|
-
*/
|
|
437
|
-
handleBackspace(event) {
|
|
438
|
-
event.preventDefault();
|
|
439
|
-
const currentPos = this.state.caretPosition;
|
|
440
|
-
// Can't go back from position 0
|
|
441
|
-
if (currentPos === 0)
|
|
442
|
-
return;
|
|
443
|
-
// Find target position to zero
|
|
444
|
-
const targetPos = currentPos === 1 ? 0 :
|
|
445
|
-
currentPos === 3 ? 1 :
|
|
446
|
-
currentPos === 4 ? 3 :
|
|
447
|
-
currentPos === 5 ? 4 : 0;
|
|
448
|
-
const newState = this.zeroDigitAtPosition(targetPos);
|
|
449
|
-
if (!newState)
|
|
450
|
-
return;
|
|
451
|
-
this.updateState({ ...newState, caretPosition: targetPos });
|
|
452
|
-
this.notifyTimeChange();
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Handle delete - zero digit at current position
|
|
456
|
-
*
|
|
457
|
-
* PORTED FROM: handle-time-delete! in date_picker.cljs
|
|
458
|
-
*/
|
|
459
|
-
handleDelete(event) {
|
|
460
|
-
event.preventDefault();
|
|
461
|
-
const currentPos = this.state.caretPosition;
|
|
462
|
-
// Only at editable positions
|
|
463
|
-
if (![0, 1, 3, 4].includes(currentPos))
|
|
464
|
-
return;
|
|
465
|
-
const newState = this.zeroDigitAtPosition(currentPos);
|
|
466
|
-
if (!newState)
|
|
467
|
-
return;
|
|
468
|
-
this.updateState({ ...newState, caretPosition: currentPos });
|
|
469
|
-
this.notifyTimeChange();
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Replace digit at specific position
|
|
473
|
-
*
|
|
474
|
-
* PORTED FROM: replace-digit-at-position in date_picker.cljs
|
|
475
|
-
*/
|
|
476
|
-
replaceDigitAtPosition(position, newDigit) {
|
|
477
|
-
const rawIndex = positionToRawDigitIndex(position);
|
|
478
|
-
const digitsArray = this.state.rawDigits.split('');
|
|
479
|
-
digitsArray[rawIndex] = newDigit.toString();
|
|
480
|
-
const newDigits = digitsArray.join('');
|
|
481
|
-
const parsed = parseTimeComponents(newDigits);
|
|
482
|
-
if (!parsed)
|
|
483
|
-
return null;
|
|
484
|
-
return {
|
|
485
|
-
rawDigits: newDigits,
|
|
486
|
-
hour: parsed.hour,
|
|
487
|
-
minute: parsed.minute,
|
|
488
|
-
displayValue: formatTimeDisplay(parsed.hour, parsed.minute),
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Zero digit at specific position
|
|
493
|
-
*
|
|
494
|
-
* PORTED FROM: zero-digit-at-position in date_picker.cljs
|
|
495
|
-
*/
|
|
496
|
-
zeroDigitAtPosition(position) {
|
|
497
|
-
return this.replaceDigitAtPosition(position, 0);
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Update internal state and refresh display
|
|
501
|
-
*
|
|
502
|
-
* PORTED FROM: update-time-input-state! in date_picker.cljs
|
|
503
|
-
*/
|
|
504
|
-
updateState(updates) {
|
|
505
|
-
this.state = { ...this.state, ...updates };
|
|
506
|
-
// Update display value
|
|
507
|
-
this.element.value = this.state.displayValue;
|
|
508
|
-
// Set cursor position, mapping internal positions to DOM positions
|
|
509
|
-
const caretPos = this.state.caretPosition;
|
|
510
|
-
const actualPos = caretPos === 0 ? 0 :
|
|
511
|
-
caretPos === 1 ? 1 :
|
|
512
|
-
caretPos === 2 ? 3 :
|
|
513
|
-
caretPos === 3 ? 3 :
|
|
514
|
-
caretPos === 4 ? 4 :
|
|
515
|
-
caretPos === 5 ? 5 : caretPos;
|
|
516
|
-
this.element.setSelectionRange(actualPos, actualPos);
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Notify date picker of time change
|
|
520
|
-
*/
|
|
521
|
-
notifyTimeChange() {
|
|
522
|
-
this.datePickerElement.handleTimeInputChange(this.state.hour, this.state.minute);
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* Get current time values
|
|
526
|
-
*/
|
|
527
|
-
getTime() {
|
|
528
|
-
return {
|
|
529
|
-
hour: this.state.hour,
|
|
530
|
-
minute: this.state.minute,
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Update time from external source
|
|
535
|
-
*/
|
|
536
|
-
setTime(hour, minute) {
|
|
537
|
-
const display = formatTimeDisplay(hour, minute);
|
|
538
|
-
const rawDigits = hour.toString().padStart(2, '0') + minute.toString().padStart(2, '0');
|
|
539
|
-
this.state = {
|
|
540
|
-
...this.state,
|
|
541
|
-
hour,
|
|
542
|
-
minute,
|
|
543
|
-
displayValue: display,
|
|
544
|
-
rawDigits,
|
|
545
|
-
};
|
|
546
|
-
this.element.value = display;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
// ============================================================================
|
|
550
|
-
// TyDatePicker Custom Element
|
|
551
|
-
// ============================================================================
|
|
50
|
+
if (!components.year || !components.month || !components.day) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const year = components.year.toString().padStart(4, '0');
|
|
54
|
+
const month = components.month.toString().padStart(2, '0');
|
|
55
|
+
const day = components.day.toString().padStart(2, '0');
|
|
56
|
+
if (withTime) {
|
|
57
|
+
const hour = (components.hour || 0).toString().padStart(2, '0');
|
|
58
|
+
const minute = (components.minute || 0).toString().padStart(2, '0');
|
|
59
|
+
const second = components.second ? `:${components.second.toString().padStart(2, '0')}` : '';
|
|
60
|
+
return `${year}-${month}-${day}T${hour}:${minute}${second}`;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return `${year}-${month}-${day}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function displayDate(components, native) {
|
|
67
|
+
return native
|
|
68
|
+
? { date: wallClockDate(components), timeZone: 'UTC' }
|
|
69
|
+
: { date: componentsToDateObject(components) };
|
|
70
|
+
}
|
|
71
|
+
function formatDisplayValue(components, formatType, locale, withTime, native) {
|
|
72
|
+
if (!components.year || !components.month || !components.day) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const { date, timeZone } = displayDate(components, native);
|
|
76
|
+
if (!date)
|
|
77
|
+
return null;
|
|
78
|
+
const options = {
|
|
79
|
+
dateStyle: formatType || 'long',
|
|
80
|
+
timeZone,
|
|
81
|
+
};
|
|
82
|
+
if (withTime) {
|
|
83
|
+
options.timeStyle = 'short';
|
|
84
|
+
}
|
|
85
|
+
const formatter = new Intl.DateTimeFormat(locale, options);
|
|
86
|
+
return formatter.format(date);
|
|
87
|
+
}
|
|
88
|
+
class TimeFields {
|
|
89
|
+
constructor(hourEl, minuteEl, onChange, hour = 0, minute = 0) {
|
|
90
|
+
this.hourEl = hourEl;
|
|
91
|
+
this.minuteEl = minuteEl;
|
|
92
|
+
this.onChange = onChange;
|
|
93
|
+
this.typed = '';
|
|
94
|
+
this.hour = hour;
|
|
95
|
+
this.minute = minute;
|
|
96
|
+
this.paint();
|
|
97
|
+
this.wire(hourEl, 'hour');
|
|
98
|
+
this.wire(minuteEl, 'minute');
|
|
99
|
+
}
|
|
100
|
+
static pad(n) {
|
|
101
|
+
return n.toString().padStart(2, '0');
|
|
102
|
+
}
|
|
103
|
+
paint() {
|
|
104
|
+
this.hourEl.value = TimeFields.pad(this.hour);
|
|
105
|
+
this.minuteEl.value = TimeFields.pad(this.minute);
|
|
106
|
+
}
|
|
107
|
+
wire(el, part) {
|
|
108
|
+
const max = part === 'hour' ? 23 : 59;
|
|
109
|
+
const maxLead = part === 'hour' ? 2 : 5;
|
|
110
|
+
el.addEventListener('focus', () => {
|
|
111
|
+
this.typed = '';
|
|
112
|
+
el.select();
|
|
113
|
+
});
|
|
114
|
+
el.addEventListener('click', () => el.select());
|
|
115
|
+
el.addEventListener('blur', () => { this.typed = ''; });
|
|
116
|
+
el.addEventListener('input', () => this.paint());
|
|
117
|
+
el.addEventListener('keydown', (e) => {
|
|
118
|
+
const set = (v) => {
|
|
119
|
+
if (part === 'hour')
|
|
120
|
+
this.hour = v;
|
|
121
|
+
else
|
|
122
|
+
this.minute = v;
|
|
123
|
+
this.paint();
|
|
124
|
+
this.onChange(this.hour, this.minute);
|
|
125
|
+
};
|
|
126
|
+
const current = part === 'hour' ? this.hour : this.minute;
|
|
127
|
+
if (/^\d$/.test(e.key)) {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
const digit = Number(e.key);
|
|
130
|
+
const next = this.typed + e.key;
|
|
131
|
+
const complete = next.length === 2 || (next.length === 1 && digit > maxLead);
|
|
132
|
+
set(Math.min(Number(next), max));
|
|
133
|
+
if (complete) {
|
|
134
|
+
this.typed = '';
|
|
135
|
+
if (part === 'hour')
|
|
136
|
+
this.minuteEl.focus();
|
|
137
|
+
else
|
|
138
|
+
el.select();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.typed = next;
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
switch (e.key) {
|
|
146
|
+
case 'ArrowUp':
|
|
147
|
+
case 'ArrowDown': {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
const delta = e.key === 'ArrowUp' ? 1 : -1;
|
|
150
|
+
this.typed = '';
|
|
151
|
+
set((current + delta + max + 1) % (max + 1));
|
|
152
|
+
el.select();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
case 'Backspace':
|
|
156
|
+
case 'Delete':
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
if (part === 'minute' && this.typed === '' && e.key === 'Backspace' && current === 0) {
|
|
159
|
+
this.hourEl.focus();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.typed = '';
|
|
163
|
+
set(0);
|
|
164
|
+
el.select();
|
|
165
|
+
return;
|
|
166
|
+
case 'ArrowLeft':
|
|
167
|
+
if (part === 'minute') {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
this.hourEl.focus();
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
case 'ArrowRight':
|
|
173
|
+
if (part === 'hour') {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
this.minuteEl.focus();
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
case 'Tab':
|
|
179
|
+
case 'Escape':
|
|
180
|
+
case 'Enter':
|
|
181
|
+
return;
|
|
182
|
+
default:
|
|
183
|
+
if (e.key.length === 1 && !e.metaKey && !e.ctrlKey)
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
getTime() {
|
|
189
|
+
return { hour: this.hour, minute: this.minute };
|
|
190
|
+
}
|
|
191
|
+
setTime(hour, minute) {
|
|
192
|
+
this.hour = hour;
|
|
193
|
+
this.minute = minute;
|
|
194
|
+
this.paint();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
552
197
|
export class TyDatePicker extends TyComponent {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
if (focusedElement) {
|
|
1418
|
-
focusedElement.blur();
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Close calendar dropdown
|
|
1425
|
-
*
|
|
1426
|
-
* PORTED FROM: close-dropdown! in date_picker.cljs
|
|
1427
|
-
*/
|
|
1428
|
-
closeDropdown() {
|
|
1429
|
-
if (!this._state.open)
|
|
1430
|
-
return;
|
|
1431
|
-
this._closeTimestamp = Date.now();
|
|
1432
|
-
const pickerId = `date-picker-${this.id || this.toString()}`;
|
|
1433
|
-
// Force sync any staged updates when closing
|
|
1434
|
-
this.updateState({ open: false }, true);
|
|
1435
|
-
unlockScroll(pickerId);
|
|
1436
|
-
if (this.shadowRoot) {
|
|
1437
|
-
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
1438
|
-
if (dialog) {
|
|
1439
|
-
dialog.classList.remove('position-above', 'position-below', 'open');
|
|
1440
|
-
dialog.close();
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
this.dispatchEvent(new CustomEvent('close', {
|
|
1444
|
-
bubbles: true,
|
|
1445
|
-
composed: true
|
|
1446
|
-
}));
|
|
1447
|
-
this.render();
|
|
1448
|
-
}
|
|
1449
|
-
// ==========================================================================
|
|
1450
|
-
// Cleanup
|
|
1451
|
-
// ==========================================================================
|
|
1452
|
-
/**
|
|
1453
|
-
* Clean up event listeners and state
|
|
1454
|
-
*
|
|
1455
|
-
* PORTED FROM: cleanup! in date_picker.cljs
|
|
1456
|
-
*/
|
|
1457
|
-
cleanup() {
|
|
1458
|
-
// Remove document listeners
|
|
1459
|
-
if (this._clickListener) {
|
|
1460
|
-
document.removeEventListener('click', this._clickListener);
|
|
1461
|
-
}
|
|
1462
|
-
if (this._keydownListener) {
|
|
1463
|
-
document.removeEventListener('keydown', this._keydownListener);
|
|
1464
|
-
}
|
|
1465
|
-
// Remove dialog listener
|
|
1466
|
-
if (this._dialogClickListener && this.shadowRoot) {
|
|
1467
|
-
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
1468
|
-
if (dialog) {
|
|
1469
|
-
dialog.removeEventListener('click', this._dialogClickListener);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
// Unlock scroll if open
|
|
1473
|
-
if (this._state.open) {
|
|
1474
|
-
const pickerId = `date-picker-${this.id || this.toString()}`;
|
|
1475
|
-
unlockScroll(pickerId);
|
|
1476
|
-
}
|
|
1477
|
-
// Clear references
|
|
1478
|
-
this._clickListener = undefined;
|
|
1479
|
-
this._keydownListener = undefined;
|
|
1480
|
-
this._dialogClickListener = undefined;
|
|
1481
|
-
this._timeInput = undefined;
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
// ============================================================================
|
|
1485
|
-
// PROPERTY CONFIGURATION - Single source of truth
|
|
1486
|
-
// ============================================================================
|
|
198
|
+
constructor() {
|
|
199
|
+
super();
|
|
200
|
+
this._state = {
|
|
201
|
+
withTime: false,
|
|
202
|
+
open: false,
|
|
203
|
+
};
|
|
204
|
+
this._closeTimestamp = 0;
|
|
205
|
+
this._initialized = false;
|
|
206
|
+
this._syncing = false;
|
|
207
|
+
this._customFlavorSheet = null;
|
|
208
|
+
const shadow = this.shadowRoot;
|
|
209
|
+
ensureStyles(shadow, { css: datePickerStyles, id: 'ty-date-picker' });
|
|
210
|
+
}
|
|
211
|
+
onConnect() {
|
|
212
|
+
if (this._initialized)
|
|
213
|
+
this._state.open = false;
|
|
214
|
+
else
|
|
215
|
+
this.initializeState();
|
|
216
|
+
this.render();
|
|
217
|
+
this.updateFormValue();
|
|
218
|
+
this._localeObserver = observeLocaleChanges(this, () => {
|
|
219
|
+
this.render();
|
|
220
|
+
});
|
|
221
|
+
this._syncCustomFlavor();
|
|
222
|
+
}
|
|
223
|
+
_syncCustomFlavor() {
|
|
224
|
+
const flavor = this.flavor === 'default' ? 'neutral' : this.flavor;
|
|
225
|
+
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, flavor, ({ base }) => datePickerCustomFlavorCss(base));
|
|
226
|
+
}
|
|
227
|
+
onDisconnect() {
|
|
228
|
+
if (this._localeObserver) {
|
|
229
|
+
this._localeObserver();
|
|
230
|
+
this._localeObserver = undefined;
|
|
231
|
+
}
|
|
232
|
+
this.cleanup();
|
|
233
|
+
}
|
|
234
|
+
onPropertiesChanged(changes) {
|
|
235
|
+
for (const { name, newValue } of changes) {
|
|
236
|
+
switch (name) {
|
|
237
|
+
case 'flavor':
|
|
238
|
+
this._syncCustomFlavor();
|
|
239
|
+
break;
|
|
240
|
+
case 'size':
|
|
241
|
+
case 'label':
|
|
242
|
+
case 'placeholder':
|
|
243
|
+
case 'required':
|
|
244
|
+
case 'disabled':
|
|
245
|
+
this.updateValidity();
|
|
246
|
+
break;
|
|
247
|
+
case 'noClear':
|
|
248
|
+
case 'format':
|
|
249
|
+
case 'locale':
|
|
250
|
+
case 'error':
|
|
251
|
+
break;
|
|
252
|
+
case 'value': {
|
|
253
|
+
if (!this._initialized || this._syncing)
|
|
254
|
+
break;
|
|
255
|
+
this._state = {
|
|
256
|
+
withTime: this._state.withTime,
|
|
257
|
+
open: this._state.open,
|
|
258
|
+
...parseDateTime(newValue),
|
|
259
|
+
};
|
|
260
|
+
this.syncFormValue();
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case 'with-time': {
|
|
264
|
+
if (!this._initialized)
|
|
265
|
+
break;
|
|
266
|
+
const newWithTime = newValue;
|
|
267
|
+
if (newWithTime !== this._state.withTime) {
|
|
268
|
+
this._state.withTime = newWithTime;
|
|
269
|
+
this.syncFormValue();
|
|
270
|
+
this.updateValidity();
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case 'native':
|
|
275
|
+
if (this._initialized)
|
|
276
|
+
this.syncFormValue();
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
getFormValue() {
|
|
282
|
+
return this.outputValue(this.getComponents());
|
|
283
|
+
}
|
|
284
|
+
outputValue(components) {
|
|
285
|
+
return componentsToOutputValue(components, this._state.withTime, !!this.getProperty('native'));
|
|
286
|
+
}
|
|
287
|
+
updateFormValue() {
|
|
288
|
+
this._internals.setFormValue(this.getFormValue() ?? '');
|
|
289
|
+
this.updateValidity();
|
|
290
|
+
}
|
|
291
|
+
focusTarget() {
|
|
292
|
+
return this.shadowRoot?.querySelector('.native-date-input')
|
|
293
|
+
?? this.shadowRoot?.querySelector('.date-picker-stub')
|
|
294
|
+
?? null;
|
|
295
|
+
}
|
|
296
|
+
focus(options) {
|
|
297
|
+
if (this.getProperty('disabled'))
|
|
298
|
+
return;
|
|
299
|
+
const target = this.focusTarget();
|
|
300
|
+
if (target)
|
|
301
|
+
target.focus(options);
|
|
302
|
+
else
|
|
303
|
+
super.focus(options);
|
|
304
|
+
}
|
|
305
|
+
updateValidity() {
|
|
306
|
+
if (this.getProperty('disabled') || !this.getProperty('required') || this.getFormValue()) {
|
|
307
|
+
this.applyValidity({});
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const type = this._state.withTime ? 'datetime-local' : 'date';
|
|
311
|
+
this.applyValidity({ valueMissing: true }, nativeMessage('input', { type, required: true }), this.focusTarget() ?? undefined);
|
|
312
|
+
}
|
|
313
|
+
getComponents() {
|
|
314
|
+
return {
|
|
315
|
+
year: this._state.year,
|
|
316
|
+
month: this._state.month,
|
|
317
|
+
day: this._state.day,
|
|
318
|
+
hour: this._state.hour,
|
|
319
|
+
minute: this._state.minute,
|
|
320
|
+
second: this._state.second,
|
|
321
|
+
epoch: this._state.epoch,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
hasDate() {
|
|
325
|
+
return !!(this._state.year && this._state.month && this._state.day);
|
|
326
|
+
}
|
|
327
|
+
getFormattedValue(components) {
|
|
328
|
+
const c = components || this.getComponents();
|
|
329
|
+
if (!c.year || !c.month || !c.day)
|
|
330
|
+
return null;
|
|
331
|
+
return formatDisplayValue(c, this.getProperty('format') || 'long', getEffectiveLocale(this, this.getProperty('locale')), this._state.withTime, !!this.getProperty('native'));
|
|
332
|
+
}
|
|
333
|
+
initializeState() {
|
|
334
|
+
this._state = {
|
|
335
|
+
...parseDateTime(this.getProperty('value')),
|
|
336
|
+
withTime: this.getProperty('with-time'),
|
|
337
|
+
open: false,
|
|
338
|
+
};
|
|
339
|
+
this._initialized = true;
|
|
340
|
+
this.syncFormValue();
|
|
341
|
+
}
|
|
342
|
+
updateState(updates, forceSync = false) {
|
|
343
|
+
this._state = { ...this._state, ...updates };
|
|
344
|
+
const shouldSync = forceSync || !this._state.open || !this._state.withTime;
|
|
345
|
+
if (shouldSync) {
|
|
346
|
+
this.syncFormValue();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
syncFormValue() {
|
|
350
|
+
const formValue = this.getFormValue();
|
|
351
|
+
const currentValue = this.getProperty('value');
|
|
352
|
+
if (formValue !== currentValue) {
|
|
353
|
+
this._syncing = true;
|
|
354
|
+
try {
|
|
355
|
+
this.setProperty('value', formValue || null);
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
this._syncing = false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
handleTimeInputChange(hour, minute) {
|
|
363
|
+
if (!this.hasDate())
|
|
364
|
+
return;
|
|
365
|
+
const components = { ...this.getComponents(), hour, minute, second: 0, epoch: undefined };
|
|
366
|
+
this.updateState(components, true);
|
|
367
|
+
this.emitChangeEvent(components, 'time-change');
|
|
368
|
+
this.updateTimeSummary();
|
|
369
|
+
this.revealValidity();
|
|
370
|
+
}
|
|
371
|
+
updateTimeSummary(summary = this.shadowRoot?.querySelector('.time-summary')) {
|
|
372
|
+
if (!summary)
|
|
373
|
+
return;
|
|
374
|
+
const c = this.getComponents();
|
|
375
|
+
const text = summary.querySelector('.time-summary-date');
|
|
376
|
+
const iso = summary.querySelector('.time-summary-iso');
|
|
377
|
+
if (!c.year || !c.month || !c.day) {
|
|
378
|
+
text.textContent = 'Pick a day';
|
|
379
|
+
iso.textContent = '';
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const locale = getEffectiveLocale(this, this.getProperty('locale')) || undefined;
|
|
383
|
+
const { date, timeZone } = displayDate(c, !!this.getProperty('native'));
|
|
384
|
+
const day = new Intl.DateTimeFormat(locale, { weekday: 'short', month: 'short', day: 'numeric', timeZone }).format(date);
|
|
385
|
+
const time = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23', timeZone }).format(date);
|
|
386
|
+
text.textContent = `${day} · ${time}`;
|
|
387
|
+
iso.textContent = componentsToLocalValue(c, true) ?? '';
|
|
388
|
+
}
|
|
389
|
+
emitChangeEvent(components, source) {
|
|
390
|
+
const value = components ? this.outputValue(components) : null;
|
|
391
|
+
const localValue = components ? componentsToLocalValue(components, this._state.withTime) : null;
|
|
392
|
+
const effective = components && effectiveComponents(components, this._state.withTime);
|
|
393
|
+
const milliseconds = effective
|
|
394
|
+
? effective.epoch ?? componentsToDateObject(effective)?.getTime() ?? null
|
|
395
|
+
: null;
|
|
396
|
+
const formatted = components ? this.getFormattedValue(components) : null;
|
|
397
|
+
const detail = {
|
|
398
|
+
value,
|
|
399
|
+
localValue,
|
|
400
|
+
milliseconds,
|
|
401
|
+
formatted,
|
|
402
|
+
source,
|
|
403
|
+
};
|
|
404
|
+
const event = new CustomEvent('change', {
|
|
405
|
+
detail,
|
|
406
|
+
bubbles: true,
|
|
407
|
+
cancelable: true,
|
|
408
|
+
});
|
|
409
|
+
this.dispatchEvent(event);
|
|
410
|
+
}
|
|
411
|
+
get size() { return this.getProperty('size'); }
|
|
412
|
+
set size(v) { this.setProperty('size', v); }
|
|
413
|
+
get placement() { return this.getProperty('placement'); }
|
|
414
|
+
set placement(v) { this.setProperty('placement', v); }
|
|
415
|
+
get flavor() { return this.getProperty('flavor'); }
|
|
416
|
+
set flavor(v) { this.setProperty('flavor', v); }
|
|
417
|
+
get label() { return this.getProperty('label'); }
|
|
418
|
+
set label(v) { this.setProperty('label', v); }
|
|
419
|
+
get placeholder() { return this.getProperty('placeholder'); }
|
|
420
|
+
set placeholder(v) { this.setProperty('placeholder', v); }
|
|
421
|
+
get name() { return this.getProperty('name'); }
|
|
422
|
+
set name(v) { this.setProperty('name', v); }
|
|
423
|
+
get format() { return this.getProperty('format'); }
|
|
424
|
+
set format(v) { this.setProperty('format', v); }
|
|
425
|
+
get locale() { return this.getProperty('locale'); }
|
|
426
|
+
set locale(v) { this.setProperty('locale', v); }
|
|
427
|
+
get required() { return this.getProperty('required'); }
|
|
428
|
+
set required(v) { this.setProperty('required', v); }
|
|
429
|
+
get disabled() { return this.getProperty('disabled'); }
|
|
430
|
+
set disabled(v) { this.setProperty('disabled', v); }
|
|
431
|
+
get noClear() { return this.getProperty('noClear'); }
|
|
432
|
+
set noClear(v) { this.setProperty('noClear', v); }
|
|
433
|
+
get min() { return this.getProperty('min'); }
|
|
434
|
+
set min(v) { this.setProperty('min', v ?? ''); }
|
|
435
|
+
get max() { return this.getProperty('max'); }
|
|
436
|
+
set max(v) { this.setProperty('max', v ?? ''); }
|
|
437
|
+
get withTime() { return this.getProperty('with-time'); }
|
|
438
|
+
set withTime(v) { this.setProperty('with-time', v); }
|
|
439
|
+
get native() { return this.getProperty('native'); }
|
|
440
|
+
set native(v) { this.setProperty('native', v); }
|
|
441
|
+
get error() { return this.getProperty('error'); }
|
|
442
|
+
set error(v) { this.setProperty('error', v); }
|
|
443
|
+
get value() {
|
|
444
|
+
if (this._initialized)
|
|
445
|
+
return this.getProperty('value') || null;
|
|
446
|
+
const parsed = parseDateTime(this.getProperty('value'));
|
|
447
|
+
return parsed && componentsToOutputValue(parsed, !!this.getProperty('with-time'), !!this.getProperty('native'));
|
|
448
|
+
}
|
|
449
|
+
set value(val) {
|
|
450
|
+
if (val === null || val === undefined || val === '') {
|
|
451
|
+
this.setProperty('value', null);
|
|
452
|
+
}
|
|
453
|
+
else if (typeof val === 'string') {
|
|
454
|
+
this.setProperty('value', val);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
const date = new Date(val);
|
|
458
|
+
this.setProperty('value', isNaN(date.getTime()) ? null : date.toISOString());
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
clear() {
|
|
462
|
+
this.clearValue();
|
|
463
|
+
}
|
|
464
|
+
buildStubClasses() {
|
|
465
|
+
const classes = ['date-picker-stub'];
|
|
466
|
+
if (this.getProperty('disabled'))
|
|
467
|
+
classes.push('disabled');
|
|
468
|
+
if (this.getProperty('required'))
|
|
469
|
+
classes.push('required');
|
|
470
|
+
if (this.getProperty('error'))
|
|
471
|
+
classes.push('error');
|
|
472
|
+
if (this._state.open)
|
|
473
|
+
classes.push('open');
|
|
474
|
+
return classes.join(' ');
|
|
475
|
+
}
|
|
476
|
+
renderStub() {
|
|
477
|
+
const stub = document.createElement('div');
|
|
478
|
+
stub.className = this.buildStubClasses();
|
|
479
|
+
const isDisabled = this.getProperty('disabled');
|
|
480
|
+
if (isDisabled) {
|
|
481
|
+
stub.setAttribute('disabled', 'true');
|
|
482
|
+
}
|
|
483
|
+
stub.setAttribute('role', 'button');
|
|
484
|
+
stub.setAttribute('aria-haspopup', 'dialog');
|
|
485
|
+
stub.setAttribute('aria-expanded', String(this._state.open));
|
|
486
|
+
stub.setAttribute('tabindex', isDisabled ? '-1' : '0');
|
|
487
|
+
if (isDisabled)
|
|
488
|
+
stub.setAttribute('aria-disabled', 'true');
|
|
489
|
+
if (this.getProperty('label')) {
|
|
490
|
+
stub.setAttribute('aria-labelledby', `date-picker-label-${getElementHash(this)}`);
|
|
491
|
+
}
|
|
492
|
+
stub.addEventListener('keydown', (e) => {
|
|
493
|
+
const ke = e;
|
|
494
|
+
if (this._state.open || e.target !== stub)
|
|
495
|
+
return;
|
|
496
|
+
if (ke.key === 'Enter' || ke.key === ' ') {
|
|
497
|
+
ke.preventDefault();
|
|
498
|
+
this.handleStubClick(e);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
const startSlot = document.createElement('slot');
|
|
502
|
+
startSlot.name = 'start';
|
|
503
|
+
const displayText = document.createElement('span');
|
|
504
|
+
displayText.className = 'stub-text';
|
|
505
|
+
const formattedValue = this.getFormattedValue();
|
|
506
|
+
const placeholder = this.getProperty('placeholder') || 'Select date...';
|
|
507
|
+
displayText.textContent = formattedValue || placeholder;
|
|
508
|
+
if (!formattedValue) {
|
|
509
|
+
displayText.classList.add('placeholder');
|
|
510
|
+
}
|
|
511
|
+
const iconContainer = document.createElement('div');
|
|
512
|
+
iconContainer.className = 'stub-icons';
|
|
513
|
+
const clearable = !this.getProperty('noClear');
|
|
514
|
+
if (clearable && formattedValue && !isDisabled) {
|
|
515
|
+
const clearButton = document.createElement('button');
|
|
516
|
+
clearButton.className = 'stub-clear';
|
|
517
|
+
clearButton.type = 'button';
|
|
518
|
+
clearButton.innerHTML = CLEAR_ICON_SVG;
|
|
519
|
+
clearButton.addEventListener('click', (e) => this.handleClearClick(e));
|
|
520
|
+
iconContainer.appendChild(clearButton);
|
|
521
|
+
}
|
|
522
|
+
const calendarIcon = document.createElement('span');
|
|
523
|
+
calendarIcon.className = 'stub-arrow';
|
|
524
|
+
calendarIcon.innerHTML = CALENDAR_ICON_SVG;
|
|
525
|
+
iconContainer.appendChild(calendarIcon);
|
|
526
|
+
stub.addEventListener('click', (e) => this.handleStubClick(e));
|
|
527
|
+
stub.appendChild(startSlot);
|
|
528
|
+
stub.appendChild(displayText);
|
|
529
|
+
stub.appendChild(iconContainer);
|
|
530
|
+
return stub;
|
|
531
|
+
}
|
|
532
|
+
createTimeField(part) {
|
|
533
|
+
const input = document.createElement('input');
|
|
534
|
+
input.type = 'text';
|
|
535
|
+
input.className = `time-input time-${part}`;
|
|
536
|
+
input.inputMode = 'numeric';
|
|
537
|
+
input.autocomplete = 'off';
|
|
538
|
+
input.maxLength = 2;
|
|
539
|
+
input.setAttribute('aria-label', part === 'hour' ? 'Hours' : 'Minutes');
|
|
540
|
+
return input;
|
|
541
|
+
}
|
|
542
|
+
renderTimeSection() {
|
|
543
|
+
const timeSection = document.createElement('div');
|
|
544
|
+
timeSection.className = 'time-section';
|
|
545
|
+
timeSection.setAttribute('role', 'group');
|
|
546
|
+
timeSection.setAttribute('aria-label', 'Time');
|
|
547
|
+
const row = document.createElement('div');
|
|
548
|
+
row.className = 'time-row';
|
|
549
|
+
const label = document.createElement('span');
|
|
550
|
+
label.className = 'time-label';
|
|
551
|
+
const icon = document.createElement('span');
|
|
552
|
+
icon.className = 'time-icon';
|
|
553
|
+
icon.innerHTML = SCHEDULE_ICON_SVG;
|
|
554
|
+
label.appendChild(icon);
|
|
555
|
+
label.appendChild(document.createTextNode('Time'));
|
|
556
|
+
const fields = document.createElement('div');
|
|
557
|
+
fields.className = 'time-fields';
|
|
558
|
+
const hourEl = this.createTimeField('hour');
|
|
559
|
+
const minuteEl = this.createTimeField('minute');
|
|
560
|
+
const colon = document.createElement('span');
|
|
561
|
+
colon.className = 'time-colon';
|
|
562
|
+
colon.textContent = ':';
|
|
563
|
+
fields.appendChild(hourEl);
|
|
564
|
+
fields.appendChild(colon);
|
|
565
|
+
fields.appendChild(minuteEl);
|
|
566
|
+
this._timeInput = new TimeFields(hourEl, minuteEl, (hour, minute) => this.handleTimeInputChange(hour, minute), this._state.hour || 0, this._state.minute || 0);
|
|
567
|
+
row.appendChild(label);
|
|
568
|
+
row.appendChild(fields);
|
|
569
|
+
const summary = document.createElement('div');
|
|
570
|
+
summary.className = 'time-summary';
|
|
571
|
+
summary.setAttribute('aria-live', 'polite');
|
|
572
|
+
const summaryDate = document.createElement('span');
|
|
573
|
+
summaryDate.className = 'time-summary-date';
|
|
574
|
+
const summaryIso = document.createElement('span');
|
|
575
|
+
summaryIso.className = 'time-summary-iso';
|
|
576
|
+
summary.appendChild(summaryDate);
|
|
577
|
+
summary.appendChild(summaryIso);
|
|
578
|
+
this.updateTimeSummary(summary);
|
|
579
|
+
timeSection.appendChild(row);
|
|
580
|
+
timeSection.appendChild(summary);
|
|
581
|
+
return timeSection;
|
|
582
|
+
}
|
|
583
|
+
renderCalendarDropdown() {
|
|
584
|
+
const dialog = document.createElement('dialog');
|
|
585
|
+
dialog.className = 'calendar-dialog';
|
|
586
|
+
const contentWrapper = document.createElement('div');
|
|
587
|
+
contentWrapper.className = 'calendar-content';
|
|
588
|
+
const calendar = document.createElement('ty-calendar');
|
|
589
|
+
if (this._state.year && this._state.month && this._state.day) {
|
|
590
|
+
calendar.setAttribute('year', String(this._state.year).padStart(4, '0'));
|
|
591
|
+
calendar.setAttribute('month', this._state.month.toString());
|
|
592
|
+
calendar.setAttribute('day', this._state.day.toString());
|
|
593
|
+
}
|
|
594
|
+
const locale = getEffectiveLocale(this, this.getProperty('locale'));
|
|
595
|
+
if (locale) {
|
|
596
|
+
calendar.setAttribute('locale', locale);
|
|
597
|
+
}
|
|
598
|
+
const min = this.getProperty('min');
|
|
599
|
+
const max = this.getProperty('max');
|
|
600
|
+
if (min)
|
|
601
|
+
calendar.setAttribute('min', min);
|
|
602
|
+
if (max)
|
|
603
|
+
calendar.setAttribute('max', max);
|
|
604
|
+
const flavor = this.calendarFlavor();
|
|
605
|
+
if (flavor)
|
|
606
|
+
calendar.setAttribute('flavor', flavor);
|
|
607
|
+
calendar.addEventListener('change', (e) => this.handleCalendarChange(e));
|
|
608
|
+
contentWrapper.appendChild(calendar);
|
|
609
|
+
if (this._state.withTime) {
|
|
610
|
+
contentWrapper.appendChild(this.renderTimeSection());
|
|
611
|
+
}
|
|
612
|
+
dialog.appendChild(contentWrapper);
|
|
613
|
+
new MutationObserver(() => {
|
|
614
|
+
if (this._state.open && !dialog.open && dialog.isConnected && this.isConnected)
|
|
615
|
+
this.closeDropdown();
|
|
616
|
+
}).observe(dialog, { attributes: true, attributeFilter: ['open'] });
|
|
617
|
+
return dialog;
|
|
618
|
+
}
|
|
619
|
+
calendarFlavor() {
|
|
620
|
+
if (this.getProperty('error'))
|
|
621
|
+
return 'danger';
|
|
622
|
+
const flavor = this.getProperty('flavor');
|
|
623
|
+
return flavor && flavor !== 'default' ? flavor : null;
|
|
624
|
+
}
|
|
625
|
+
renderNativeInput() {
|
|
626
|
+
const wrapper = document.createElement('div');
|
|
627
|
+
wrapper.className = 'dropdown-wrapper';
|
|
628
|
+
const stub = document.createElement('div');
|
|
629
|
+
stub.className = this.buildStubClasses();
|
|
630
|
+
const isDisabled = this.getProperty('disabled');
|
|
631
|
+
if (isDisabled) {
|
|
632
|
+
stub.setAttribute('disabled', 'true');
|
|
633
|
+
}
|
|
634
|
+
const input = document.createElement('input');
|
|
635
|
+
input.className = 'native-date-input';
|
|
636
|
+
this.syncNativeInput(input);
|
|
637
|
+
const localValue = input.value;
|
|
638
|
+
const placeholder = this.getProperty('placeholder') || 'Select date...';
|
|
639
|
+
const formattedValue = this.getFormattedValue();
|
|
640
|
+
const placeholderEl = document.createElement('span');
|
|
641
|
+
placeholderEl.className = 'stub-text' + (formattedValue ? '' : ' placeholder');
|
|
642
|
+
placeholderEl.textContent = formattedValue || placeholder;
|
|
643
|
+
input.addEventListener('change', () => {
|
|
644
|
+
if (!input.value) {
|
|
645
|
+
this.clearValue();
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
const parsed = parseDateTime(input.value);
|
|
649
|
+
if (parsed) {
|
|
650
|
+
const { hour, minute, second } = this._state.withTime ? parsed : this._state;
|
|
651
|
+
const components = { ...parsed, hour, minute, second, epoch: undefined };
|
|
652
|
+
this.updateState(components, true);
|
|
653
|
+
this.emitChangeEvent(components, 'selection');
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
this.revealValidity();
|
|
657
|
+
});
|
|
658
|
+
const startSlot = document.createElement('slot');
|
|
659
|
+
startSlot.name = 'start';
|
|
660
|
+
stub.appendChild(startSlot);
|
|
661
|
+
stub.appendChild(input);
|
|
662
|
+
stub.appendChild(placeholderEl);
|
|
663
|
+
const iconContainer = document.createElement('div');
|
|
664
|
+
iconContainer.className = 'stub-icons';
|
|
665
|
+
const clearable = !this.getProperty('noClear');
|
|
666
|
+
if (clearable && localValue && !isDisabled) {
|
|
667
|
+
const clearButton = document.createElement('button');
|
|
668
|
+
clearButton.className = 'stub-clear';
|
|
669
|
+
clearButton.type = 'button';
|
|
670
|
+
clearButton.innerHTML = CLEAR_ICON_SVG;
|
|
671
|
+
clearButton.addEventListener('click', (e) => this.handleClearClick(e));
|
|
672
|
+
iconContainer.appendChild(clearButton);
|
|
673
|
+
}
|
|
674
|
+
const calendarIcon = document.createElement('span');
|
|
675
|
+
calendarIcon.className = 'stub-arrow';
|
|
676
|
+
calendarIcon.innerHTML = CALENDAR_ICON_SVG;
|
|
677
|
+
iconContainer.appendChild(calendarIcon);
|
|
678
|
+
stub.appendChild(iconContainer);
|
|
679
|
+
wrapper.appendChild(stub);
|
|
680
|
+
return wrapper;
|
|
681
|
+
}
|
|
682
|
+
syncNativeInput(input) {
|
|
683
|
+
const withTime = this._state.withTime;
|
|
684
|
+
input.type = withTime ? 'datetime-local' : 'date';
|
|
685
|
+
input.disabled = !!this.getProperty('disabled');
|
|
686
|
+
input.required = !!this.getProperty('required');
|
|
687
|
+
const min = toISODay(this.getProperty('min'));
|
|
688
|
+
const max = toISODay(this.getProperty('max'));
|
|
689
|
+
if (min)
|
|
690
|
+
input.min = withTime ? `${min}T00:00` : min;
|
|
691
|
+
else
|
|
692
|
+
input.removeAttribute('min');
|
|
693
|
+
if (max)
|
|
694
|
+
input.max = withTime ? `${max}T23:59` : max;
|
|
695
|
+
else
|
|
696
|
+
input.removeAttribute('max');
|
|
697
|
+
input.value = componentsToLocalValue(this.getComponents(), withTime) ?? '';
|
|
698
|
+
}
|
|
699
|
+
calculateCalendarPosition() {
|
|
700
|
+
if (!this.shadowRoot)
|
|
701
|
+
return;
|
|
702
|
+
if (isMobileTouch())
|
|
703
|
+
return;
|
|
704
|
+
const stub = this.shadowRoot.querySelector('.date-picker-stub');
|
|
705
|
+
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
706
|
+
if (!stub || !dialog)
|
|
707
|
+
return;
|
|
708
|
+
const stubRect = stub.getBoundingClientRect();
|
|
709
|
+
const dialogRect = dialog.getBoundingClientRect();
|
|
710
|
+
const estimatedHeight = dialogRect.height || 400;
|
|
711
|
+
const popupWidth = dialogRect.width || 320;
|
|
712
|
+
const wrapPadding = 8;
|
|
713
|
+
const anchored = placementToAnchored(this.getProperty('placement'));
|
|
714
|
+
const pos = computeAnchoredPosition({
|
|
715
|
+
anchorRect: stubRect,
|
|
716
|
+
popupWidth,
|
|
717
|
+
popupHeight: estimatedHeight,
|
|
718
|
+
gap: 0,
|
|
719
|
+
align: anchored.align,
|
|
720
|
+
side: anchored.side,
|
|
721
|
+
});
|
|
722
|
+
const positionBelow = pos.below;
|
|
723
|
+
const x = pos.x - wrapPadding;
|
|
724
|
+
const y = positionBelow ? pos.topY : pos.bottomY;
|
|
725
|
+
this.style.setProperty('--calendar-x', `${x}px`);
|
|
726
|
+
this.style.setProperty('--calendar-y', `${y}px`);
|
|
727
|
+
this.style.setProperty('--calendar-offset-x', '0px');
|
|
728
|
+
this.style.setProperty('--calendar-offset-y', '0px');
|
|
729
|
+
if (positionBelow) {
|
|
730
|
+
dialog.classList.add('position-below');
|
|
731
|
+
dialog.classList.remove('position-above');
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
dialog.classList.add('position-above');
|
|
735
|
+
dialog.classList.remove('position-below');
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
renderContainer() {
|
|
739
|
+
const container = document.createElement('div');
|
|
740
|
+
container.className = 'dropdown-container';
|
|
741
|
+
const label = this.getProperty('label');
|
|
742
|
+
if (label) {
|
|
743
|
+
const labelEl = document.createElement('label');
|
|
744
|
+
labelEl.className = 'ty-field-label';
|
|
745
|
+
labelEl.id = `date-picker-label-${getElementHash(this)}`;
|
|
746
|
+
labelEl.innerHTML = label + (this.getProperty('required') ? '<span class="required-icon">*</span>' : '');
|
|
747
|
+
container.appendChild(labelEl);
|
|
748
|
+
}
|
|
749
|
+
return container;
|
|
750
|
+
}
|
|
751
|
+
render() {
|
|
752
|
+
if (!this.shadowRoot)
|
|
753
|
+
return;
|
|
754
|
+
ensureStyles(this.shadowRoot, { css: datePickerStyles, id: 'ty-date-picker' });
|
|
755
|
+
if (isMobileTouch()) {
|
|
756
|
+
const existingNativeInput = this.shadowRoot.querySelector('.native-date-input');
|
|
757
|
+
if (existingNativeInput) {
|
|
758
|
+
this.updateDisplay();
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
this.shadowRoot.innerHTML = '';
|
|
762
|
+
const container = this.renderContainer();
|
|
763
|
+
container.appendChild(this.renderNativeInput());
|
|
764
|
+
this.shadowRoot.appendChild(container);
|
|
765
|
+
this.syncErrorLine();
|
|
766
|
+
this.updateValidity();
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const existingDialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
770
|
+
const isDialogOpen = existingDialog && existingDialog.open;
|
|
771
|
+
if (isDialogOpen && this._state.open) {
|
|
772
|
+
this.updateDisplay();
|
|
773
|
+
this.calculateCalendarPosition();
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
const hadFocus = !!this.shadowRoot.activeElement;
|
|
777
|
+
this.shadowRoot.innerHTML = '';
|
|
778
|
+
const container = this.renderContainer();
|
|
779
|
+
const wrapper = document.createElement('div');
|
|
780
|
+
wrapper.className = 'dropdown-wrapper';
|
|
781
|
+
wrapper.appendChild(this.renderStub());
|
|
782
|
+
wrapper.appendChild(this.renderCalendarDropdown());
|
|
783
|
+
container.appendChild(wrapper);
|
|
784
|
+
this.shadowRoot.appendChild(container);
|
|
785
|
+
this.syncErrorLine();
|
|
786
|
+
this.setupEventListeners();
|
|
787
|
+
this.updateValidity();
|
|
788
|
+
if (hadFocus)
|
|
789
|
+
this.focus({ preventScroll: true });
|
|
790
|
+
}
|
|
791
|
+
syncErrorLine() {
|
|
792
|
+
const container = this.shadowRoot?.querySelector('.dropdown-container');
|
|
793
|
+
if (!container)
|
|
794
|
+
return;
|
|
795
|
+
const error = this.getProperty('error');
|
|
796
|
+
const errorId = `date-picker-error-${getElementHash(this)}`;
|
|
797
|
+
let line = container.querySelector(':scope > .error-message');
|
|
798
|
+
if (error) {
|
|
799
|
+
if (!line) {
|
|
800
|
+
line = document.createElement('div');
|
|
801
|
+
line.className = 'error-message';
|
|
802
|
+
line.id = errorId;
|
|
803
|
+
container.appendChild(line);
|
|
804
|
+
}
|
|
805
|
+
line.textContent = error;
|
|
806
|
+
this.focusTarget()?.setAttribute('aria-describedby', errorId);
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
line?.remove();
|
|
810
|
+
this.focusTarget()?.removeAttribute('aria-describedby');
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
updateDisplay() {
|
|
814
|
+
if (!this.shadowRoot)
|
|
815
|
+
return;
|
|
816
|
+
const formattedValue = this.getFormattedValue();
|
|
817
|
+
const placeholder = this.getProperty('placeholder') || 'Select date...';
|
|
818
|
+
const hasValue = this.hasDate();
|
|
819
|
+
const clearable = !this.getProperty('noClear');
|
|
820
|
+
const isDisabled = this.getProperty('disabled');
|
|
821
|
+
const stubText = this.shadowRoot.querySelector('.stub-text');
|
|
822
|
+
if (stubText) {
|
|
823
|
+
stubText.textContent = formattedValue || placeholder;
|
|
824
|
+
stubText.classList.toggle('placeholder', !formattedValue);
|
|
825
|
+
}
|
|
826
|
+
const clearButton = this.shadowRoot.querySelector('.stub-clear');
|
|
827
|
+
if (clearButton) {
|
|
828
|
+
clearButton.style.display = (clearable && hasValue && !isDisabled) ? '' : 'none';
|
|
829
|
+
}
|
|
830
|
+
const stub = this.shadowRoot.querySelector('.date-picker-stub');
|
|
831
|
+
if (stub)
|
|
832
|
+
stub.className = this.buildStubClasses();
|
|
833
|
+
this.syncErrorLine();
|
|
834
|
+
if (isMobileTouch()) {
|
|
835
|
+
const nativeInput = this.shadowRoot.querySelector('.native-date-input');
|
|
836
|
+
if (nativeInput)
|
|
837
|
+
this.syncNativeInput(nativeInput);
|
|
838
|
+
stub?.toggleAttribute('disabled', !!isDisabled);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const calendar = this.shadowRoot.querySelector('ty-calendar');
|
|
842
|
+
if (calendar && hasValue) {
|
|
843
|
+
calendar.setAttribute('year', String(this._state.year).padStart(4, '0'));
|
|
844
|
+
calendar.setAttribute('month', this._state.month.toString());
|
|
845
|
+
calendar.setAttribute('day', this._state.day.toString());
|
|
846
|
+
}
|
|
847
|
+
if (calendar) {
|
|
848
|
+
const flavor = this.calendarFlavor();
|
|
849
|
+
if (flavor)
|
|
850
|
+
calendar.setAttribute('flavor', flavor);
|
|
851
|
+
else
|
|
852
|
+
calendar.removeAttribute('flavor');
|
|
853
|
+
const min = this.getProperty('min');
|
|
854
|
+
const max = this.getProperty('max');
|
|
855
|
+
if (min)
|
|
856
|
+
calendar.setAttribute('min', min);
|
|
857
|
+
else
|
|
858
|
+
calendar.removeAttribute('min');
|
|
859
|
+
if (max)
|
|
860
|
+
calendar.setAttribute('max', max);
|
|
861
|
+
else
|
|
862
|
+
calendar.removeAttribute('max');
|
|
863
|
+
}
|
|
864
|
+
if (this._timeInput && this._state.hour !== undefined && this._state.minute !== undefined) {
|
|
865
|
+
this._timeInput.setTime(this._state.hour, this._state.minute);
|
|
866
|
+
}
|
|
867
|
+
this.updateTimeSummary();
|
|
868
|
+
}
|
|
869
|
+
setupEventListeners() {
|
|
870
|
+
if (this._clickListener) {
|
|
871
|
+
document.removeEventListener('click', this._clickListener);
|
|
872
|
+
}
|
|
873
|
+
if (this._keydownListener) {
|
|
874
|
+
document.removeEventListener('keydown', this._keydownListener);
|
|
875
|
+
}
|
|
876
|
+
this._clickListener = (e) => this.handleOutsideClick(e);
|
|
877
|
+
this._keydownListener = (e) => this.handleEscapeKey(e);
|
|
878
|
+
document.addEventListener('click', this._clickListener);
|
|
879
|
+
document.addEventListener('keydown', this._keydownListener);
|
|
880
|
+
const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
|
|
881
|
+
if (dialog) {
|
|
882
|
+
this._dialogClickListener = (e) => this.handleDialogClick(e);
|
|
883
|
+
dialog.addEventListener('click', this._dialogClickListener);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
handleStubClick(event) {
|
|
887
|
+
event.preventDefault();
|
|
888
|
+
const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
|
|
889
|
+
if (this._state.open && (!dialog || !dialog.open)) {
|
|
890
|
+
this.updateState({ open: false }, true);
|
|
891
|
+
unlockScroll(`date-picker-${getElementHash(this)}`);
|
|
892
|
+
}
|
|
893
|
+
const disabled = this.getProperty('disabled');
|
|
894
|
+
if (!disabled && Date.now() - this._closeTimestamp > 300) {
|
|
895
|
+
this.openDropdown();
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
clearValue() {
|
|
899
|
+
this.updateState({
|
|
900
|
+
year: undefined,
|
|
901
|
+
month: undefined,
|
|
902
|
+
day: undefined,
|
|
903
|
+
hour: undefined,
|
|
904
|
+
minute: undefined,
|
|
905
|
+
second: undefined,
|
|
906
|
+
epoch: undefined,
|
|
907
|
+
}, true);
|
|
908
|
+
this.value = null;
|
|
909
|
+
this.emitChangeEvent(null, 'clear');
|
|
910
|
+
this.render();
|
|
911
|
+
}
|
|
912
|
+
handleClearClick(event) {
|
|
913
|
+
event.preventDefault();
|
|
914
|
+
event.stopPropagation();
|
|
915
|
+
this.clearValue();
|
|
916
|
+
const active = document.activeElement;
|
|
917
|
+
if (this.matches(':focus-within') || !active || active === document.body) {
|
|
918
|
+
this.shadowRoot?.querySelector('.native-date-input')?.focus({ preventScroll: true });
|
|
919
|
+
}
|
|
920
|
+
this.revealValidity();
|
|
921
|
+
}
|
|
922
|
+
handleCalendarChange(event) {
|
|
923
|
+
event.preventDefault();
|
|
924
|
+
event.stopPropagation();
|
|
925
|
+
const customEvent = event;
|
|
926
|
+
const detail = customEvent.detail;
|
|
927
|
+
const dayContext = detail.dayContext;
|
|
928
|
+
if (!dayContext)
|
|
929
|
+
return;
|
|
930
|
+
const newComponents = {
|
|
931
|
+
year: dayContext.year,
|
|
932
|
+
month: dayContext.month,
|
|
933
|
+
day: dayContext.dayInMonth,
|
|
934
|
+
hour: this._state.hour,
|
|
935
|
+
minute: this._state.minute,
|
|
936
|
+
second: this._state.second,
|
|
937
|
+
epoch: undefined,
|
|
938
|
+
};
|
|
939
|
+
this.updateState(newComponents, true);
|
|
940
|
+
this.emitChangeEvent(newComponents, 'selection');
|
|
941
|
+
this.revealValidity();
|
|
942
|
+
if (!this._state.withTime) {
|
|
943
|
+
this.closeDropdown();
|
|
944
|
+
}
|
|
945
|
+
else {
|
|
946
|
+
requestAnimationFrame(() => {
|
|
947
|
+
if (!this.shadowRoot)
|
|
948
|
+
return;
|
|
949
|
+
this.updateTimeSummary();
|
|
950
|
+
const timeInput = this.shadowRoot.querySelector('.time-hour');
|
|
951
|
+
if (timeInput) {
|
|
952
|
+
timeInput.focus();
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
handleDialogClick(event) {
|
|
958
|
+
if (!this.shadowRoot)
|
|
959
|
+
return;
|
|
960
|
+
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
961
|
+
const content = this.shadowRoot.querySelector('.calendar-content');
|
|
962
|
+
if (event.target === dialog && this._state.open && content && !content.contains(event.target)) {
|
|
963
|
+
event.preventDefault();
|
|
964
|
+
event.stopPropagation();
|
|
965
|
+
this.closeDropdown();
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
handleOutsideClick(event) {
|
|
969
|
+
if (!this.shadowRoot)
|
|
970
|
+
return;
|
|
971
|
+
const target = event.target;
|
|
972
|
+
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
973
|
+
if (this._state.open && dialog && !this.contains(target) && !dialog.contains(target)) {
|
|
974
|
+
this.closeDropdown();
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
handleEscapeKey(event) {
|
|
978
|
+
const keyboardEvent = event;
|
|
979
|
+
if (keyboardEvent.key === 'Escape' && this._state.open) {
|
|
980
|
+
keyboardEvent.preventDefault();
|
|
981
|
+
this.closeDropdown();
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
openDropdown() {
|
|
985
|
+
if (this._state.open)
|
|
986
|
+
return;
|
|
987
|
+
if (isMobileTouch())
|
|
988
|
+
return;
|
|
989
|
+
this.updateState({ open: true });
|
|
990
|
+
this.dispatchEvent(new CustomEvent('open'));
|
|
991
|
+
this.render();
|
|
992
|
+
requestAnimationFrame(() => {
|
|
993
|
+
if (!this.shadowRoot)
|
|
994
|
+
return;
|
|
995
|
+
if (!this._state.open || !this.isConnected)
|
|
996
|
+
return;
|
|
997
|
+
if (this.shadowRoot.querySelector('.date-picker-stub')?.checkVisibility() === false) {
|
|
998
|
+
this.closeDropdown();
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
1002
|
+
if (dialog) {
|
|
1003
|
+
const pickerId = `date-picker-${getElementHash(this)}`;
|
|
1004
|
+
lockScroll(pickerId);
|
|
1005
|
+
dialog.showModal();
|
|
1006
|
+
this.calculateCalendarPosition();
|
|
1007
|
+
dialog.classList.add('open');
|
|
1008
|
+
const stubEl = this.shadowRoot.querySelector('.date-picker-stub');
|
|
1009
|
+
if (stubEl)
|
|
1010
|
+
stubEl.setAttribute('aria-expanded', 'true');
|
|
1011
|
+
const focusedElement = this.shadowRoot.activeElement;
|
|
1012
|
+
if (focusedElement) {
|
|
1013
|
+
focusedElement.blur();
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
closeDropdown() {
|
|
1019
|
+
if (!this._state.open)
|
|
1020
|
+
return;
|
|
1021
|
+
this._closeTimestamp = Date.now();
|
|
1022
|
+
const pickerId = `date-picker-${getElementHash(this)}`;
|
|
1023
|
+
this.updateState({ open: false }, true);
|
|
1024
|
+
unlockScroll(pickerId);
|
|
1025
|
+
if (this.shadowRoot) {
|
|
1026
|
+
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
1027
|
+
if (dialog) {
|
|
1028
|
+
dialog.classList.remove('position-above', 'position-below', 'open');
|
|
1029
|
+
dialog.close();
|
|
1030
|
+
}
|
|
1031
|
+
const stubEl = this.shadowRoot.querySelector('.date-picker-stub');
|
|
1032
|
+
if (stubEl)
|
|
1033
|
+
stubEl.setAttribute('aria-expanded', 'false');
|
|
1034
|
+
}
|
|
1035
|
+
this.dispatchEvent(new CustomEvent('close'));
|
|
1036
|
+
this.render();
|
|
1037
|
+
this.focus();
|
|
1038
|
+
}
|
|
1039
|
+
cleanup() {
|
|
1040
|
+
if (this._clickListener) {
|
|
1041
|
+
document.removeEventListener('click', this._clickListener);
|
|
1042
|
+
}
|
|
1043
|
+
if (this._keydownListener) {
|
|
1044
|
+
document.removeEventListener('keydown', this._keydownListener);
|
|
1045
|
+
}
|
|
1046
|
+
if (this._dialogClickListener && this.shadowRoot) {
|
|
1047
|
+
const dialog = this.shadowRoot.querySelector('.calendar-dialog');
|
|
1048
|
+
if (dialog) {
|
|
1049
|
+
dialog.removeEventListener('click', this._dialogClickListener);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
if (this._state.open) {
|
|
1053
|
+
const pickerId = `date-picker-${getElementHash(this)}`;
|
|
1054
|
+
unlockScroll(pickerId);
|
|
1055
|
+
}
|
|
1056
|
+
this._clickListener = undefined;
|
|
1057
|
+
this._keydownListener = undefined;
|
|
1058
|
+
this._dialogClickListener = undefined;
|
|
1059
|
+
this._timeInput = undefined;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1487
1062
|
TyDatePicker.properties = {
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1063
|
+
placement: {
|
|
1064
|
+
type: 'string',
|
|
1065
|
+
visual: true,
|
|
1066
|
+
default: '',
|
|
1067
|
+
},
|
|
1068
|
+
size: {
|
|
1069
|
+
type: 'string',
|
|
1070
|
+
visual: true,
|
|
1071
|
+
default: DEFAULT_SIZE,
|
|
1072
|
+
validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
|
|
1073
|
+
coerce: (v) => {
|
|
1074
|
+
if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
|
|
1075
|
+
console.warn(`[ty-date-picker] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
|
|
1076
|
+
return DEFAULT_SIZE;
|
|
1077
|
+
}
|
|
1078
|
+
return v;
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
flavor: {
|
|
1082
|
+
type: 'string',
|
|
1083
|
+
visual: true,
|
|
1084
|
+
default: 'default'
|
|
1085
|
+
},
|
|
1086
|
+
label: {
|
|
1087
|
+
type: 'string',
|
|
1088
|
+
visual: true,
|
|
1089
|
+
default: ''
|
|
1090
|
+
},
|
|
1091
|
+
placeholder: {
|
|
1092
|
+
type: 'string',
|
|
1093
|
+
visual: true,
|
|
1094
|
+
default: 'Select date...'
|
|
1095
|
+
},
|
|
1096
|
+
name: {
|
|
1097
|
+
type: 'string',
|
|
1098
|
+
visual: false,
|
|
1099
|
+
default: ''
|
|
1100
|
+
},
|
|
1101
|
+
min: {
|
|
1102
|
+
type: 'string',
|
|
1103
|
+
visual: true,
|
|
1104
|
+
default: ''
|
|
1105
|
+
},
|
|
1106
|
+
max: {
|
|
1107
|
+
type: 'string',
|
|
1108
|
+
visual: true,
|
|
1109
|
+
default: ''
|
|
1110
|
+
},
|
|
1111
|
+
required: {
|
|
1112
|
+
type: 'boolean',
|
|
1113
|
+
visual: true,
|
|
1114
|
+
default: false
|
|
1115
|
+
},
|
|
1116
|
+
disabled: {
|
|
1117
|
+
type: 'boolean',
|
|
1118
|
+
visual: true,
|
|
1119
|
+
default: false
|
|
1120
|
+
},
|
|
1121
|
+
noClear: {
|
|
1122
|
+
type: 'boolean',
|
|
1123
|
+
visual: true,
|
|
1124
|
+
default: false
|
|
1125
|
+
},
|
|
1126
|
+
error: {
|
|
1127
|
+
type: 'string',
|
|
1128
|
+
visual: true,
|
|
1129
|
+
default: ''
|
|
1130
|
+
},
|
|
1131
|
+
format: {
|
|
1132
|
+
type: 'string',
|
|
1133
|
+
visual: true,
|
|
1134
|
+
default: 'long',
|
|
1135
|
+
validate: (v) => ['short', 'medium', 'long', 'full'].includes(v),
|
|
1136
|
+
coerce: (v) => {
|
|
1137
|
+
const validFormats = ['short', 'medium', 'long', 'full'];
|
|
1138
|
+
if (!validFormats.includes(v)) {
|
|
1139
|
+
console.warn(`[ty-date-picker] Invalid format '${v}'. Using 'long'.`);
|
|
1140
|
+
return 'long';
|
|
1141
|
+
}
|
|
1142
|
+
return v;
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
locale: {
|
|
1146
|
+
type: 'string',
|
|
1147
|
+
visual: true,
|
|
1148
|
+
default: ''
|
|
1149
|
+
},
|
|
1150
|
+
value: {
|
|
1151
|
+
type: 'string',
|
|
1152
|
+
visual: true,
|
|
1153
|
+
formValue: true,
|
|
1154
|
+
emitChange: false,
|
|
1155
|
+
default: null
|
|
1156
|
+
},
|
|
1157
|
+
'with-time': {
|
|
1158
|
+
type: 'boolean',
|
|
1159
|
+
visual: true,
|
|
1160
|
+
default: false
|
|
1161
|
+
},
|
|
1162
|
+
native: {
|
|
1163
|
+
type: 'boolean',
|
|
1164
|
+
visual: true,
|
|
1165
|
+
default: false
|
|
1166
|
+
}
|
|
1577
1167
|
};
|
|
1578
|
-
/**
|
|
1579
|
-
* Form-associated custom element
|
|
1580
|
-
*/
|
|
1581
1168
|
TyDatePicker.formAssociated = true;
|
|
1582
|
-
// Register custom element
|
|
1583
1169
|
if (!customElements.get('ty-date-picker')) {
|
|
1584
|
-
|
|
1170
|
+
customElements.define('ty-date-picker', TyDatePicker);
|
|
1585
1171
|
}
|
|
1586
|
-
//# sourceMappingURL=date-picker.js.map
|