tyrell-components 1.0.0-RC14 → 1.0.0-RC16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/README.md +53 -53
  2. package/css/tyrell-theme.css +32 -4
  3. package/css/tyrell.css +10 -15
  4. package/dist/tyrell-colors-static.css +1 -316
  5. package/dist/tyrell-theme.css +1 -1443
  6. package/dist/tyrell.css +1 -1390
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.d.ts +14 -0
  9. package/lib/base/ty-component.d.ts.map +1 -0
  10. package/lib/base/ty-component.js +223 -196
  11. package/lib/base/ty-component.js.map +1 -0
  12. package/lib/components/button.d.ts +1 -1
  13. package/lib/components/button.d.ts.map +1 -0
  14. package/lib/components/button.js +267 -259
  15. package/lib/components/button.js.map +1 -0
  16. package/lib/components/calendar-month.d.ts +2 -2
  17. package/lib/components/calendar-month.d.ts.map +1 -0
  18. package/lib/components/calendar-month.js +440 -416
  19. package/lib/components/calendar-month.js.map +1 -0
  20. package/lib/components/calendar-navigation.d.ts +11 -0
  21. package/lib/components/calendar-navigation.d.ts.map +1 -0
  22. package/lib/components/calendar-navigation.js +272 -261
  23. package/lib/components/calendar-navigation.js.map +1 -0
  24. package/lib/components/calendar.d.ts +31 -3
  25. package/lib/components/calendar.d.ts.map +1 -0
  26. package/lib/components/calendar.js +785 -603
  27. package/lib/components/calendar.js.map +1 -0
  28. package/lib/components/checkbox.d.ts +1 -1
  29. package/lib/components/checkbox.d.ts.map +1 -0
  30. package/lib/components/checkbox.js +273 -272
  31. package/lib/components/checkbox.js.map +1 -0
  32. package/lib/components/copy.d.ts +1 -1
  33. package/lib/components/copy.d.ts.map +1 -0
  34. package/lib/components/copy.js +287 -278
  35. package/lib/components/copy.js.map +1 -0
  36. package/lib/components/date-picker.d.ts +16 -10
  37. package/lib/components/date-picker.d.ts.map +1 -0
  38. package/lib/components/date-picker.js +1068 -1122
  39. package/lib/components/date-picker.js.map +1 -0
  40. package/lib/components/dropdown.d.ts +403 -0
  41. package/lib/components/dropdown.d.ts.map +1 -0
  42. package/lib/components/dropdown.js +1315 -0
  43. package/lib/components/dropdown.js.map +1 -0
  44. package/lib/components/file-upload.d.ts +4 -0
  45. package/lib/components/file-upload.js +418 -404
  46. package/lib/components/icon.d.ts.map +1 -0
  47. package/lib/components/icon.js +141 -141
  48. package/lib/components/icon.js.map +1 -0
  49. package/lib/components/input.d.ts +1 -1
  50. package/lib/components/input.d.ts.map +1 -0
  51. package/lib/components/input.js +593 -596
  52. package/lib/components/input.js.map +1 -0
  53. package/lib/components/modal.d.ts +2 -8
  54. package/lib/components/modal.d.ts.map +1 -0
  55. package/lib/components/modal.js +309 -319
  56. package/lib/components/modal.js.map +1 -0
  57. package/lib/components/multiselect.d.ts +389 -0
  58. package/lib/components/multiselect.d.ts.map +1 -0
  59. package/lib/components/multiselect.js +1301 -0
  60. package/lib/components/multiselect.js.map +1 -0
  61. package/lib/components/option.d.ts.map +1 -0
  62. package/lib/components/option.js +167 -167
  63. package/lib/components/option.js.map +1 -0
  64. package/lib/components/popup.d.ts.map +1 -0
  65. package/lib/components/popup.js +236 -233
  66. package/lib/components/popup.js.map +1 -0
  67. package/lib/components/radio.d.ts +17 -2
  68. package/lib/components/radio.js +437 -406
  69. package/lib/components/resize-observer.d.ts.map +1 -0
  70. package/lib/components/resize-observer.js +67 -67
  71. package/lib/components/resize-observer.js.map +1 -0
  72. package/lib/components/scroll-container.d.ts +3 -2
  73. package/lib/components/scroll-container.d.ts.map +1 -0
  74. package/lib/components/scroll-container.js +289 -294
  75. package/lib/components/scroll-container.js.map +1 -0
  76. package/lib/components/select.d.ts +85 -18
  77. package/lib/components/select.js +1647 -1529
  78. package/lib/components/selected-tags.d.ts +1 -1
  79. package/lib/components/selected-tags.js +188 -182
  80. package/lib/components/step.d.ts.map +1 -0
  81. package/lib/components/step.js +62 -62
  82. package/lib/components/step.js.map +1 -0
  83. package/lib/components/switch.d.ts +1 -1
  84. package/lib/components/switch.js +214 -213
  85. package/lib/components/tab.d.ts +49 -1
  86. package/lib/components/tab.d.ts.map +1 -0
  87. package/lib/components/tab.js +203 -62
  88. package/lib/components/tab.js.map +1 -0
  89. package/lib/components/tabs.d.ts +15 -2
  90. package/lib/components/tabs.d.ts.map +1 -0
  91. package/lib/components/tabs.js +576 -496
  92. package/lib/components/tabs.js.map +1 -0
  93. package/lib/components/tag.d.ts +5 -8
  94. package/lib/components/tag.d.ts.map +1 -0
  95. package/lib/components/tag.js +235 -235
  96. package/lib/components/tag.js.map +1 -0
  97. package/lib/components/textarea.d.ts +5 -4
  98. package/lib/components/textarea.d.ts.map +1 -0
  99. package/lib/components/textarea.js +458 -456
  100. package/lib/components/textarea.js.map +1 -0
  101. package/lib/components/tooltip.d.ts +4 -3
  102. package/lib/components/tooltip.d.ts.map +1 -0
  103. package/lib/components/tooltip.js +293 -283
  104. package/lib/components/tooltip.js.map +1 -0
  105. package/lib/components/wizard.d.ts +5 -4
  106. package/lib/components/wizard.d.ts.map +1 -0
  107. package/lib/components/wizard.js +359 -395
  108. package/lib/components/wizard.js.map +1 -0
  109. package/lib/icons/fontawesome/brands.d.ts.map +1 -0
  110. package/lib/icons/fontawesome/brands.js.map +1 -0
  111. package/lib/icons/fontawesome/regular.d.ts.map +1 -0
  112. package/lib/icons/fontawesome/regular.js.map +1 -0
  113. package/lib/icons/fontawesome/solid.d.ts.map +1 -0
  114. package/lib/icons/fontawesome/solid.js.map +1 -0
  115. package/lib/icons/heroicons/micro.d.ts.map +1 -0
  116. package/lib/icons/heroicons/micro.js +392 -392
  117. package/lib/icons/heroicons/micro.js.map +1 -0
  118. package/lib/icons/heroicons/mini.d.ts.map +1 -0
  119. package/lib/icons/heroicons/mini.js +382 -382
  120. package/lib/icons/heroicons/mini.js.map +1 -0
  121. package/lib/icons/heroicons/outline.d.ts.map +1 -0
  122. package/lib/icons/heroicons/outline.js +337 -337
  123. package/lib/icons/heroicons/outline.js.map +1 -0
  124. package/lib/icons/heroicons/solid.d.ts.map +1 -0
  125. package/lib/icons/heroicons/solid.js +407 -407
  126. package/lib/icons/heroicons/solid.js.map +1 -0
  127. package/lib/icons/lucide.d.ts.map +1 -0
  128. package/lib/icons/lucide.js +22843 -22843
  129. package/lib/icons/lucide.js.map +1 -0
  130. package/lib/icons/material/filled.d.ts.map +1 -0
  131. package/lib/icons/material/filled.js +9653 -9653
  132. package/lib/icons/material/filled.js.map +1 -0
  133. package/lib/icons/material/outlined.d.ts.map +1 -0
  134. package/lib/icons/material/outlined.js +10271 -10271
  135. package/lib/icons/material/outlined.js.map +1 -0
  136. package/lib/icons/material/round.d.ts.map +1 -0
  137. package/lib/icons/material/round.js +10495 -10495
  138. package/lib/icons/material/round.js.map +1 -0
  139. package/lib/icons/material/sharp.d.ts.map +1 -0
  140. package/lib/icons/material/sharp.js +9905 -9905
  141. package/lib/icons/material/sharp.js.map +1 -0
  142. package/lib/icons/material/two-tone.d.ts.map +1 -0
  143. package/lib/icons/material/two-tone.js +12792 -12792
  144. package/lib/icons/material/two-tone.js.map +1 -0
  145. package/lib/index.d.ts +1 -1
  146. package/lib/index.d.ts.map +1 -0
  147. package/lib/index.js +21 -21
  148. package/lib/index.js.map +1 -0
  149. package/lib/styles/button.d.ts.map +1 -0
  150. package/lib/styles/button.js +200 -302
  151. package/lib/styles/button.js.map +1 -0
  152. package/lib/styles/calendar-month.d.ts +3 -0
  153. package/lib/styles/calendar-month.d.ts.map +1 -0
  154. package/lib/styles/calendar-month.js +141 -185
  155. package/lib/styles/calendar-month.js.map +1 -0
  156. package/lib/styles/calendar-navigation.d.ts +1 -1
  157. package/lib/styles/calendar-navigation.d.ts.map +1 -0
  158. package/lib/styles/calendar-navigation.js +100 -86
  159. package/lib/styles/calendar-navigation.js.map +1 -0
  160. package/lib/styles/calendar.d.ts +3 -2
  161. package/lib/styles/calendar.d.ts.map +1 -0
  162. package/lib/styles/calendar.js +83 -9
  163. package/lib/styles/calendar.js.map +1 -0
  164. package/lib/styles/checkbox.js +62 -77
  165. package/lib/styles/copy.d.ts.map +1 -0
  166. package/lib/styles/copy.js +71 -91
  167. package/lib/styles/copy.js.map +1 -0
  168. package/lib/styles/custom-scrollbar.js +80 -100
  169. package/lib/styles/date-picker.d.ts.map +1 -0
  170. package/lib/styles/date-picker.js +295 -335
  171. package/lib/styles/date-picker.js.map +1 -0
  172. package/lib/styles/dropdown.d.ts +12 -0
  173. package/lib/styles/dropdown.d.ts.map +1 -0
  174. package/lib/styles/dropdown.js +725 -0
  175. package/lib/styles/dropdown.js.map +1 -0
  176. package/lib/styles/field-size.d.ts +6 -0
  177. package/lib/styles/field-size.js +91 -0
  178. package/lib/styles/file-upload.js +139 -169
  179. package/lib/styles/icon.d.ts.map +1 -0
  180. package/lib/styles/icon.js +92 -156
  181. package/lib/styles/icon.js.map +1 -0
  182. package/lib/styles/input.d.ts.map +1 -0
  183. package/lib/styles/input.js +125 -241
  184. package/lib/styles/input.js.map +1 -0
  185. package/lib/styles/modal.d.ts.map +1 -0
  186. package/lib/styles/modal.js +67 -102
  187. package/lib/styles/modal.js.map +1 -0
  188. package/lib/styles/multiselect.d.ts +6 -0
  189. package/lib/styles/multiselect.d.ts.map +1 -0
  190. package/lib/styles/multiselect.js +568 -0
  191. package/lib/styles/multiselect.js.map +1 -0
  192. package/lib/styles/option.d.ts +1 -1
  193. package/lib/styles/option.d.ts.map +1 -0
  194. package/lib/styles/option.js +47 -67
  195. package/lib/styles/option.js.map +1 -0
  196. package/lib/styles/popup.d.ts +1 -1
  197. package/lib/styles/popup.d.ts.map +1 -0
  198. package/lib/styles/popup.js +37 -65
  199. package/lib/styles/popup.js.map +1 -0
  200. package/lib/styles/radio.js +75 -96
  201. package/lib/styles/resize-observer.d.ts.map +1 -0
  202. package/lib/styles/resize-observer.js +2 -5
  203. package/lib/styles/resize-observer.js.map +1 -0
  204. package/lib/styles/scroll-container.d.ts +1 -1
  205. package/lib/styles/scroll-container.d.ts.map +1 -0
  206. package/lib/styles/scroll-container.js +101 -131
  207. package/lib/styles/scroll-container.js.map +1 -0
  208. package/lib/styles/select-base.js +596 -773
  209. package/lib/styles/select.d.ts +1 -1
  210. package/lib/styles/select.js +146 -228
  211. package/lib/styles/step.d.ts +1 -1
  212. package/lib/styles/step.d.ts.map +1 -0
  213. package/lib/styles/step.js +15 -30
  214. package/lib/styles/step.js.map +1 -0
  215. package/lib/styles/switch.js +37 -55
  216. package/lib/styles/tab.d.ts +1 -1
  217. package/lib/styles/tab.d.ts.map +1 -0
  218. package/lib/styles/tab.js +86 -29
  219. package/lib/styles/tab.js.map +1 -0
  220. package/lib/styles/tabs.d.ts +1 -1
  221. package/lib/styles/tabs.d.ts.map +1 -0
  222. package/lib/styles/tabs.js +190 -180
  223. package/lib/styles/tabs.js.map +1 -0
  224. package/lib/styles/tag.d.ts.map +1 -0
  225. package/lib/styles/tag.js +137 -191
  226. package/lib/styles/tag.js.map +1 -0
  227. package/lib/styles/textarea.d.ts +1 -1
  228. package/lib/styles/textarea.d.ts.map +1 -0
  229. package/lib/styles/textarea.js +205 -271
  230. package/lib/styles/textarea.js.map +1 -0
  231. package/lib/styles/tooltip.d.ts.map +1 -0
  232. package/lib/styles/tooltip.js +3 -3
  233. package/lib/styles/tooltip.js.map +1 -0
  234. package/lib/styles/wizard.d.ts +9 -5
  235. package/lib/styles/wizard.d.ts.map +1 -0
  236. package/lib/styles/wizard.js +301 -245
  237. package/lib/styles/wizard.js.map +1 -0
  238. package/lib/types/common.d.ts +4 -2
  239. package/lib/types/common.d.ts.map +1 -0
  240. package/lib/types/common.js +6 -5
  241. package/lib/types/common.js.map +1 -0
  242. package/lib/utils/calendar-utils.d.ts.map +1 -0
  243. package/lib/utils/calendar-utils.js +100 -100
  244. package/lib/utils/calendar-utils.js.map +1 -0
  245. package/lib/utils/custom-scrollbar.js +272 -272
  246. package/lib/utils/flavor-sheet.js +14 -14
  247. package/lib/utils/icon-registry.d.ts.map +1 -0
  248. package/lib/utils/icon-registry.js +127 -127
  249. package/lib/utils/icon-registry.js.map +1 -0
  250. package/lib/utils/loader-registry.js +3 -3
  251. package/lib/utils/locale.d.ts.map +1 -0
  252. package/lib/utils/locale.js +34 -34
  253. package/lib/utils/locale.js.map +1 -0
  254. package/lib/utils/mobile.js +1 -1
  255. package/lib/utils/number-format.d.ts.map +1 -0
  256. package/lib/utils/number-format.js +54 -54
  257. package/lib/utils/number-format.js.map +1 -0
  258. package/lib/utils/parse-boolean.d.ts +39 -0
  259. package/lib/utils/parse-boolean.d.ts.map +1 -0
  260. package/lib/utils/parse-boolean.js +23 -0
  261. package/lib/utils/parse-boolean.js.map +1 -0
  262. package/lib/utils/positioning.d.ts.map +1 -0
  263. package/lib/utils/positioning.js +212 -212
  264. package/lib/utils/positioning.js.map +1 -0
  265. package/lib/utils/property-capture.d.ts.map +1 -0
  266. package/lib/utils/property-capture.js +36 -36
  267. package/lib/utils/property-capture.js.map +1 -0
  268. package/lib/utils/property-manager.d.ts +1 -1
  269. package/lib/utils/property-manager.d.ts.map +1 -0
  270. package/lib/utils/property-manager.js +127 -125
  271. package/lib/utils/property-manager.js.map +1 -0
  272. package/lib/utils/resize-observer.d.ts.map +1 -0
  273. package/lib/utils/resize-observer.js +23 -23
  274. package/lib/utils/resize-observer.js.map +1 -0
  275. package/lib/utils/scroll-lock.d.ts.map +1 -0
  276. package/lib/utils/scroll-lock.js +57 -57
  277. package/lib/utils/scroll-lock.js.map +1 -0
  278. package/lib/utils/styles.d.ts.map +1 -0
  279. package/lib/utils/styles.js +17 -17
  280. package/lib/utils/styles.js.map +1 -0
  281. package/lib/utils/validity.d.ts +26 -0
  282. package/lib/utils/validity.js +53 -0
  283. package/lib/version.d.ts +1 -1
  284. package/lib/version.d.ts.map +1 -0
  285. package/lib/version.js +1 -1
  286. package/lib/version.js.map +1 -0
  287. package/package.json +28 -7
@@ -2,622 +2,804 @@ import { ensureStyles } from '../utils/styles.js';
2
2
  import { calendarStyles } from '../styles/calendar.js';
3
3
  import './calendar-month.js';
4
4
  import './calendar-navigation.js';
5
- import { parseISODate } from '../utils/calendar-utils.js';
5
+ import { parseISODate, getMonthName } from '../utils/calendar-utils.js';
6
6
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
7
+ import { ValidityController } from '../utils/validity.js';
7
8
  function getCurrentDate() {
8
- const now = new Date();
9
- return {
10
- year: now.getFullYear(),
11
- month: now.getMonth() + 1,
12
- day: now.getDate(),
13
- };
9
+ const now = new Date();
10
+ return {
11
+ year: now.getFullYear(),
12
+ month: now.getMonth() + 1,
13
+ day: now.getDate(),
14
+ };
14
15
  }
15
16
  function parseYear(yearStr) {
16
- if (!yearStr || !/^\d{4}$/.test(yearStr))
17
- return null;
18
- return parseInt(yearStr, 10);
17
+ if (!yearStr || !/^\d{4}$/.test(yearStr))
18
+ return null;
19
+ return parseInt(yearStr, 10);
19
20
  }
20
21
  function parseMonth(monthStr) {
21
- if (!monthStr || !/^\d{1,2}$/.test(monthStr))
22
- return null;
23
- const month = parseInt(monthStr, 10);
24
- return month >= 1 && month <= 12 ? month : null;
22
+ if (!monthStr || !/^\d{1,2}$/.test(monthStr))
23
+ return null;
24
+ const month = parseInt(monthStr, 10);
25
+ return month >= 1 && month <= 12 ? month : null;
25
26
  }
26
27
  function parseDay(dayStr, year, month) {
27
- if (!dayStr || !/^\d{1,2}$/.test(dayStr))
28
- return null;
29
- const day = parseInt(dayStr, 10);
30
- const daysInMonth = new Date(year, month, 0).getDate();
31
- return day >= 1 && day <= daysInMonth ? day : null;
28
+ if (!dayStr || !/^\d{1,2}$/.test(dayStr))
29
+ return null;
30
+ const day = parseInt(dayStr, 10);
31
+ const daysInMonth = new Date(year, month, 0).getDate();
32
+ return day >= 1 && day <= daysInMonth ? day : null;
32
33
  }
33
34
  function formatDateISO(year, month, day) {
34
- const monthStr = month.toString().padStart(2, '0');
35
- const dayStr = day.toString().padStart(2, '0');
36
- return `${year}-${monthStr}-${dayStr}`;
35
+ const monthStr = month.toString().padStart(2, '0');
36
+ const dayStr = day.toString().padStart(2, '0');
37
+ return `${year}-${monthStr}-${dayStr}`;
37
38
  }
38
39
  export class TyCalendar extends HTMLElement {
39
- static get observedAttributes() {
40
- return ['year', 'month', 'day', 'show-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor'];
41
- }
42
- constructor() {
43
- super();
44
- this._showNavigation = true;
45
- this._stateless = false;
46
- this._size = 'md';
47
- this._flavor = 'primary';
48
- const current = getCurrentDate();
49
- this._state = {
50
- displayYear: current.year,
51
- displayMonth: current.month,
52
- };
53
- this.attachShadow({ mode: 'open' });
54
- if ('attachInternals' in this) {
55
- this._internals = this.attachInternals();
56
- }
57
- }
58
- connectedCallback() {
59
- this.initializeFromAttributes();
60
- const plainDayContentFn = this.dayContentFn;
61
- if (plainDayContentFn && !this._dayContentFn) {
62
- this._dayContentFn = plainDayContentFn;
63
- delete this.dayContentFn;
64
- }
65
- const plainCustomCSS = this.customCSS;
66
- if (plainCustomCSS && !this._customCSS) {
67
- this._customCSS = plainCustomCSS;
68
- delete this.customCSS;
69
- }
70
- const plainValue = this.value;
71
- if (plainValue && typeof plainValue === 'string' && plainValue !== this.value) {
72
- const match = plainValue.match(/^(\d{4})-(\d{2})-(\d{2})$/);
73
- if (match) {
74
- const year = parseInt(match[1], 10);
75
- const month = parseInt(match[2], 10);
76
- const day = parseInt(match[3], 10);
77
- this._state.selectedYear = year;
78
- this._state.selectedMonth = month;
79
- this._state.selectedDay = day;
80
- this._state.displayYear = year;
81
- this._state.displayMonth = month;
82
- if (!this._stateless) {
83
- this.setAttribute('year', year.toString());
84
- this.setAttribute('month', month.toString());
85
- this.setAttribute('day', day.toString());
86
- }
87
- }
88
- delete this.value;
89
- }
90
- this.render();
91
- this.updateFormValue();
92
- this._localeObserver = observeLocaleChanges(this, () => {
93
- this.render();
94
- });
95
- }
96
- disconnectedCallback() {
97
- if (this._localeObserver) {
98
- this._localeObserver();
99
- this._localeObserver = undefined;
100
- }
101
- this._navigation = undefined;
102
- this._monthDisplay = undefined;
103
- }
104
- attributeChangedCallback(name, oldValue, newValue) {
105
- if (oldValue === newValue)
106
- return;
107
- switch (name) {
108
- case 'year':
109
- case 'month':
110
- case 'day':
111
- this.syncStateFromAttributes();
112
- this.syncChildComponents();
113
- this.updateFormValue();
114
- break;
115
- case 'show-navigation':
116
- this._showNavigation = newValue !== 'false';
117
- this.render();
118
- break;
119
- case 'stateless':
120
- this._stateless = newValue !== null && newValue !== 'false';
121
- break;
122
- case 'locale':
123
- this.syncChildComponents();
124
- break;
125
- case 'size':
126
- if (newValue === 'sm' || newValue === 'md' || newValue === 'lg') {
127
- this._size = newValue;
128
- this._width = undefined;
129
- this.removeAttribute('width');
130
- this.syncChildComponents();
131
- }
132
- break;
133
- case 'width':
134
- this._width = newValue || undefined;
135
- if (newValue) {
136
- this._size = 'md';
137
- this.removeAttribute('size');
138
- }
139
- this.syncChildComponents();
140
- break;
141
- case 'name':
142
- this.updateFormValue();
143
- break;
144
- case 'min':
145
- case 'max':
146
- this[name === 'min' ? '_min' : '_max'] = newValue || undefined;
147
- this.syncChildComponents();
148
- this.updateValidity();
149
- break;
150
- case 'flavor':
151
- this._flavor = newValue || 'primary';
152
- this.syncChildComponents();
153
- break;
154
- }
155
- }
156
- get min() {
157
- return this._min;
158
- }
159
- set min(value) {
160
- if (value)
161
- this.setAttribute('min', value);
162
- else
163
- this.removeAttribute('min');
164
- }
165
- get max() {
166
- return this._max;
167
- }
168
- set max(value) {
169
- if (value)
170
- this.setAttribute('max', value);
171
- else
172
- this.removeAttribute('max');
173
- }
174
- get flavor() {
175
- return this._flavor;
176
- }
177
- set flavor(value) {
178
- if (value)
179
- this.setAttribute('flavor', value);
180
- else
181
- this.removeAttribute('flavor');
182
- }
183
- get year() {
184
- return this._state.selectedYear;
185
- }
186
- set year(value) {
187
- if (value !== undefined) {
188
- if (this._stateless) {
189
- this._state.displayYear = value;
190
- this.setAttribute('year', value.toString());
191
- }
192
- else {
193
- this._state.selectedYear = value;
194
- this._state.displayYear = value;
195
- this.setAttribute('year', value.toString());
196
- }
197
- }
198
- else {
199
- if (!this._stateless) {
200
- delete this._state.selectedYear;
201
- }
202
- this.removeAttribute('year');
203
- }
204
- this.syncChildComponents();
205
- if (!this._stateless) {
206
- this.updateFormValue();
207
- }
208
- }
209
- get month() {
210
- return this._state.selectedMonth;
211
- }
212
- set month(value) {
213
- if (value !== undefined) {
214
- if (this._stateless) {
215
- this._state.displayMonth = value;
216
- this.setAttribute('month', value.toString());
217
- }
218
- else {
219
- this._state.selectedMonth = value;
220
- this._state.displayMonth = value;
221
- this.setAttribute('month', value.toString());
222
- }
223
- }
224
- else {
225
- if (!this._stateless) {
226
- delete this._state.selectedMonth;
227
- }
228
- this.removeAttribute('month');
229
- }
230
- this.syncChildComponents();
231
- if (!this._stateless) {
232
- this.updateFormValue();
233
- }
234
- }
235
- get day() {
236
- return this._state.selectedDay;
237
- }
238
- set day(value) {
239
- if (value !== undefined) {
240
- this._state.selectedDay = value;
241
- this.setAttribute('day', value.toString());
242
- }
243
- else {
244
- delete this._state.selectedDay;
245
- this.removeAttribute('day');
246
- }
247
- this.syncChildComponents();
248
- this.updateFormValue();
249
- }
250
- get locale() {
251
- return getEffectiveLocale(this, this.getAttribute('locale'));
252
- }
253
- set locale(value) {
254
- this.setAttribute('locale', value);
255
- }
256
- get showNavigation() {
257
- return this._showNavigation;
258
- }
259
- set showNavigation(value) {
260
- this._showNavigation = value;
261
- this.setAttribute('show-navigation', value.toString());
262
- }
263
- get stateless() {
264
- return this._stateless;
265
- }
266
- set stateless(value) {
267
- this._stateless = value;
268
- if (value) {
269
- this.setAttribute('stateless', '');
270
- }
271
- else {
272
- this.removeAttribute('stateless');
273
- }
274
- }
275
- get size() {
276
- return this._size;
277
- }
278
- set size(value) {
279
- if (this._size !== value) {
280
- this._size = value;
281
- this._width = undefined;
282
- this.removeAttribute('width');
283
- this.setAttribute('size', value);
284
- this.syncChildComponents();
285
- }
286
- }
287
- get width() {
288
- return this._width;
289
- }
290
- set width(value) {
291
- if (this._width !== value) {
292
- this._width = value;
293
- if (value) {
294
- this._size = 'md';
295
- this.removeAttribute('size');
296
- this.setAttribute('width', value);
297
- }
298
- else {
299
- this.removeAttribute('width');
300
- }
301
- this.syncChildComponents();
302
- }
303
- }
304
- get dayContentFn() {
305
- return this._dayContentFn;
306
- }
307
- set dayContentFn(fn) {
308
- this._dayContentFn = fn;
309
- this.syncChildComponents();
310
- }
311
- get customCSS() {
312
- return this._customCSS;
313
- }
314
- set customCSS(sheet) {
315
- this._customCSS = sheet;
316
- this.syncChildComponents();
317
- }
318
- get value() {
319
- const { selectedYear, selectedMonth, selectedDay } = this._state;
320
- if (selectedYear && selectedMonth && selectedDay) {
321
- return formatDateISO(selectedYear, selectedMonth, selectedDay);
322
- }
323
- return '';
324
- }
325
- set value(isoDate) {
326
- if (!isoDate) {
327
- delete this._state.selectedYear;
328
- delete this._state.selectedMonth;
329
- delete this._state.selectedDay;
330
- if (!this._stateless) {
331
- this.removeAttribute('year');
332
- this.removeAttribute('month');
333
- this.removeAttribute('day');
334
- }
335
- }
336
- else {
337
- const match = isoDate.match(/^(\d{4})-(\d{2})-(\d{2})$/);
338
- if (match) {
339
- const year = parseInt(match[1], 10);
340
- const month = parseInt(match[2], 10);
341
- const day = parseInt(match[3], 10);
342
- this._state.selectedYear = year;
343
- this._state.selectedMonth = month;
344
- this._state.selectedDay = day;
345
- this._state.displayYear = year;
346
- this._state.displayMonth = month;
347
- if (!this._stateless) {
348
- this.setAttribute('year', year.toString());
349
- this.setAttribute('month', month.toString());
350
- this.setAttribute('day', day.toString());
351
- }
352
- }
353
- }
354
- this.syncChildComponents();
355
- if (!this._stateless) {
356
- this.updateFormValue();
357
- }
358
- }
359
- initializeFromAttributes() {
360
- const yearStr = this.getAttribute('year');
361
- const monthStr = this.getAttribute('month');
362
- const dayStr = this.getAttribute('day');
363
- const showNavStr = this.getAttribute('show-navigation');
364
- const statelessStr = this.getAttribute('stateless');
365
- const sizeStr = this.getAttribute('size');
366
- const widthStr = this.getAttribute('width');
367
- this._min = this.getAttribute('min') || undefined;
368
- this._max = this.getAttribute('max') || undefined;
369
- const year = parseYear(yearStr);
370
- if (year) {
371
- this._state.displayYear = year;
372
- }
373
- const month = parseMonth(monthStr);
374
- if (month) {
375
- this._state.displayMonth = month;
376
- }
377
- if (year && month) {
378
- const day = parseDay(dayStr, year, month);
379
- if (day) {
380
- this._state.selectedYear = year;
381
- this._state.selectedMonth = month;
382
- this._state.selectedDay = day;
383
- }
384
- }
385
- if (showNavStr) {
386
- this._showNavigation = showNavStr !== 'false';
387
- }
388
- if (statelessStr !== null) {
389
- this._stateless = statelessStr !== 'false';
390
- }
391
- if (sizeStr && (sizeStr === 'sm' || sizeStr === 'md' || sizeStr === 'lg')) {
392
- this._size = sizeStr;
393
- }
394
- if (widthStr) {
395
- this._width = widthStr;
396
- }
397
- }
398
- syncStateFromAttributes() {
399
- const yearStr = this.getAttribute('year');
400
- const monthStr = this.getAttribute('month');
401
- const dayStr = this.getAttribute('day');
402
- const year = parseYear(yearStr);
403
- const month = parseMonth(monthStr);
404
- if (year)
405
- this._state.displayYear = year;
406
- if (month)
407
- this._state.displayMonth = month;
408
- if (year && month) {
409
- const day = parseDay(dayStr, year, month);
410
- if (day) {
411
- this._state.selectedYear = year;
412
- this._state.selectedMonth = month;
413
- this._state.selectedDay = day;
414
- }
415
- else {
416
- delete this._state.selectedYear;
417
- delete this._state.selectedMonth;
418
- delete this._state.selectedDay;
419
- }
420
- }
421
- else {
422
- delete this._state.selectedYear;
423
- delete this._state.selectedMonth;
424
- delete this._state.selectedDay;
425
- }
426
- }
427
- syncChildComponents() {
428
- if (this._navigation) {
429
- this._navigation.displayMonth = this._state.displayMonth;
430
- this._navigation.displayYear = this._state.displayYear;
431
- this._navigation.locale = this.locale;
432
- this._navigation.size = this._size;
433
- this._navigation.min = this._min ?? '';
434
- this._navigation.max = this._max ?? '';
435
- this._navigation.width = this._width;
436
- }
437
- if (this._monthDisplay) {
438
- this._monthDisplay.displayMonth = this._state.displayMonth;
439
- this._monthDisplay.displayYear = this._state.displayYear;
440
- this._monthDisplay.locale = this.locale;
441
- this._monthDisplay.size = this._size;
442
- this._monthDisplay.min = this._min;
443
- this._monthDisplay.max = this._max;
444
- this._monthDisplay.flavor = this._flavor;
445
- this._monthDisplay.width = this._width;
446
- if (this._dayContentFn) {
447
- this._monthDisplay.dayContentFn = this._dayContentFn;
448
- }
449
- if (this._customCSS) {
450
- this._monthDisplay.customCSS = this._customCSS;
451
- }
452
- const { selectedYear, selectedMonth, selectedDay } = this._state;
453
- if (selectedYear && selectedMonth && selectedDay) {
454
- const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
455
- this._monthDisplay.value = date.getTime();
456
- }
457
- else {
458
- this._monthDisplay.value = null;
459
- }
460
- }
461
- }
462
- updateFormValue() {
463
- if (this._stateless)
464
- return;
465
- if (!this._internals)
466
- return;
467
- const elementName = this.getAttribute('name');
468
- const { selectedYear, selectedMonth, selectedDay } = this._state;
469
- if (elementName && selectedYear && selectedMonth && selectedDay) {
470
- const isoDate = formatDateISO(selectedYear, selectedMonth, selectedDay);
471
- this._internals.setFormValue(isoDate);
472
- }
473
- else {
474
- this._internals.setFormValue('');
475
- }
476
- this.updateValidity();
477
- }
478
- updateValidity() {
479
- if (!this._internals)
480
- return;
481
- const { selectedYear, selectedMonth, selectedDay } = this._state;
482
- if (selectedYear && selectedMonth && selectedDay) {
483
- const sel = Date.UTC(selectedYear, selectedMonth - 1, selectedDay);
484
- const min = this._min ? parseISODate(this._min) : null;
485
- const max = this._max ? parseISODate(this._max) : null;
486
- if (min && sel < Date.UTC(min.year, min.month - 1, min.day)) {
487
- this._internals.setValidity({ rangeUnderflow: true }, `Date must be ${this._min} or later`);
488
- return;
489
- }
490
- if (max && sel > Date.UTC(max.year, max.month - 1, max.day)) {
491
- this._internals.setValidity({ rangeOverflow: true }, `Date must be ${this._max} or earlier`);
492
- return;
493
- }
494
- }
495
- this._internals.setValidity({});
496
- }
497
- handleNavigationChange(event) {
498
- event.preventDefault();
499
- event.stopPropagation();
500
- const { month, year } = event.detail;
501
- this._state.displayMonth = month;
502
- this._state.displayYear = year;
503
- this.syncChildComponents();
504
- const navigateDetail = {
505
- month,
506
- year,
507
- action: 'navigate',
508
- source: 'navigation',
509
- };
510
- this.dispatchEvent(new CustomEvent('navigate', {
511
- detail: navigateDetail,
512
- bubbles: true,
513
- composed: true,
514
- cancelable: false,
515
- }));
516
- }
517
- handleDayClick(event) {
518
- event.preventDefault();
519
- event.stopPropagation();
520
- const { dayContext, year, month, day } = event.detail;
521
- if (this._stateless) {
522
- this.dispatchEvent(new CustomEvent('day-click', {
523
- detail: event.detail,
524
- bubbles: true,
525
- composed: true,
526
- cancelable: true,
527
- }));
528
- return;
529
- }
530
- this._state.selectedYear = year;
531
- this._state.selectedMonth = month;
532
- this._state.selectedDay = day;
533
- this._state.displayYear = year;
534
- this._state.displayMonth = month;
535
- this.setAttribute('year', year.toString());
536
- this.setAttribute('month', month.toString());
537
- this.setAttribute('day', day.toString());
538
- this.updateFormValue();
539
- this.syncChildComponents();
540
- const changeDetail = {
541
- year,
542
- month,
543
- day,
544
- action: 'select',
545
- source: 'day-click',
546
- dayContext,
547
- };
548
- this.dispatchEvent(new CustomEvent('change', {
549
- detail: changeDetail,
550
- bubbles: true,
551
- composed: true,
552
- cancelable: false,
553
- }));
554
- }
555
- refresh() {
556
- this.syncChildComponents();
557
- if (this._monthDisplay && typeof this._monthDisplay.refresh === 'function') {
558
- this._monthDisplay.refresh();
559
- }
560
- }
561
- createNavigation() {
562
- const nav = document.createElement('ty-calendar-navigation');
563
- nav.displayMonth = this._state.displayMonth;
564
- nav.displayYear = this._state.displayYear;
565
- nav.locale = this.locale;
566
- nav.size = this._size;
567
- nav.min = this._min ?? '';
568
- nav.max = this._max ?? '';
569
- if (this._width) {
570
- nav.width = this._width;
571
- }
572
- nav.addEventListener('change', (e) => this.handleNavigationChange(e));
573
- this._navigation = nav;
574
- return nav;
575
- }
576
- createMonthDisplay() {
577
- const month = document.createElement('ty-calendar-month');
578
- month.displayMonth = this._state.displayMonth;
579
- month.displayYear = this._state.displayYear;
580
- month.locale = this.locale;
581
- month.size = this._size;
582
- month.min = this._min;
583
- month.max = this._max;
584
- month.flavor = this._flavor;
585
- if (this._width) {
586
- month.width = this._width;
587
- }
588
- const { selectedYear, selectedMonth, selectedDay } = this._state;
589
- if (selectedYear && selectedMonth && selectedDay) {
590
- const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
591
- month.value = date.getTime();
592
- }
593
- if (this._dayContentFn) {
594
- month.dayContentFn = this._dayContentFn;
595
- }
596
- if (this._customCSS) {
597
- month.customCSS = this._customCSS;
598
- }
599
- month.addEventListener('day-click', (e) => this.handleDayClick(e));
600
- this._monthDisplay = month;
601
- return month;
602
- }
603
- render() {
604
- const root = this.shadowRoot;
605
- if (!root)
606
- return;
607
- ensureStyles(root, { css: calendarStyles, id: 'ty-calendar' });
608
- root.innerHTML = '';
609
- const container = document.createElement('div');
610
- container.className = 'calendar-container';
611
- if (this._showNavigation) {
612
- const nav = this.createNavigation();
613
- container.appendChild(nav);
614
- }
615
- const month = this.createMonthDisplay();
616
- container.appendChild(month);
617
- root.appendChild(container);
618
- }
40
+ static get observedAttributes() {
41
+ return ['value', 'year', 'month', 'day', 'hide-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor'];
42
+ }
43
+ constructor() {
44
+ super();
45
+ this._hideNavigation = false;
46
+ this._stateless = false;
47
+ this._size = 'md';
48
+ this._flavor = 'primary';
49
+ this._view = 'days';
50
+ this._dayGridHeight = 0;
51
+ this._initialValue = '';
52
+ const current = getCurrentDate();
53
+ this._state = {
54
+ displayYear: current.year,
55
+ displayMonth: current.month,
56
+ };
57
+ this.attachShadow({ mode: 'open' });
58
+ if ('attachInternals' in this) {
59
+ this._internals = this.attachInternals();
60
+ this._validity = new ValidityController(this, this._internals);
61
+ }
62
+ }
63
+ connectedCallback() {
64
+ this.initializeFromAttributes();
65
+ const plainDayContentFn = this.dayContentFn;
66
+ if (plainDayContentFn && !this._dayContentFn) {
67
+ this._dayContentFn = plainDayContentFn;
68
+ delete this.dayContentFn;
69
+ }
70
+ const plainCustomCSS = this.customCSS;
71
+ if (plainCustomCSS && !this._customCSS) {
72
+ this._customCSS = plainCustomCSS;
73
+ delete this.customCSS;
74
+ }
75
+ const plainValue = this.value;
76
+ if (plainValue && typeof plainValue === 'string' && plainValue !== this.value) {
77
+ const match = plainValue.match(/^(\d{4})-(\d{2})-(\d{2})$/);
78
+ if (match) {
79
+ const year = parseInt(match[1], 10);
80
+ const month = parseInt(match[2], 10);
81
+ const day = parseInt(match[3], 10);
82
+ this._state.selectedYear = year;
83
+ this._state.selectedMonth = month;
84
+ this._state.selectedDay = day;
85
+ this._state.displayYear = year;
86
+ this._state.displayMonth = month;
87
+ if (!this._stateless) {
88
+ this.setAttribute('year', year.toString());
89
+ this.setAttribute('month', month.toString());
90
+ this.setAttribute('day', day.toString());
91
+ }
92
+ }
93
+ delete this.value;
94
+ }
95
+ this.render();
96
+ this.updateFormValue();
97
+ this._localeObserver = observeLocaleChanges(this, () => {
98
+ this.render();
99
+ });
100
+ }
101
+ disconnectedCallback() {
102
+ if (this._localeObserver) {
103
+ this._localeObserver();
104
+ this._localeObserver = undefined;
105
+ }
106
+ this._navigation = undefined;
107
+ this._monthDisplay = undefined;
108
+ this._monthGrid = undefined;
109
+ this._container = undefined;
110
+ this._view = 'days';
111
+ }
112
+ attributeChangedCallback(name, oldValue, newValue) {
113
+ if (oldValue === newValue)
114
+ return;
115
+ switch (name) {
116
+ case 'value':
117
+ this.value = newValue || '';
118
+ break;
119
+ case 'year':
120
+ case 'month':
121
+ case 'day':
122
+ this.syncStateFromAttributes();
123
+ this.syncChildComponents();
124
+ this.updateFormValue();
125
+ break;
126
+ case 'hide-navigation':
127
+ this._hideNavigation = newValue !== null;
128
+ this.render();
129
+ break;
130
+ case 'stateless':
131
+ this._stateless = newValue !== null && newValue !== 'false';
132
+ break;
133
+ case 'locale':
134
+ this.syncChildComponents();
135
+ break;
136
+ case 'size':
137
+ if (newValue === 'sm' || newValue === 'md' || newValue === 'lg') {
138
+ this._size = newValue;
139
+ this._width = undefined;
140
+ this.removeAttribute('width');
141
+ this.syncChildComponents();
142
+ }
143
+ break;
144
+ case 'width':
145
+ this._width = newValue || undefined;
146
+ if (newValue) {
147
+ this._size = 'md';
148
+ this.removeAttribute('size');
149
+ }
150
+ this.syncChildComponents();
151
+ break;
152
+ case 'name':
153
+ this.updateFormValue();
154
+ break;
155
+ case 'min':
156
+ case 'max':
157
+ this[name === 'min' ? '_min' : '_max'] = newValue || undefined;
158
+ this.syncChildComponents();
159
+ this.updateValidity();
160
+ break;
161
+ case 'flavor':
162
+ this._flavor = newValue || 'primary';
163
+ this.syncChildComponents();
164
+ break;
165
+ }
166
+ }
167
+ get min() {
168
+ return this._min;
169
+ }
170
+ set min(value) {
171
+ if (value)
172
+ this.setAttribute('min', value);
173
+ else
174
+ this.removeAttribute('min');
175
+ }
176
+ get max() {
177
+ return this._max;
178
+ }
179
+ set max(value) {
180
+ if (value)
181
+ this.setAttribute('max', value);
182
+ else
183
+ this.removeAttribute('max');
184
+ }
185
+ get flavor() {
186
+ return this._flavor;
187
+ }
188
+ set flavor(value) {
189
+ if (value)
190
+ this.setAttribute('flavor', value);
191
+ else
192
+ this.removeAttribute('flavor');
193
+ }
194
+ get year() {
195
+ return this._state.selectedYear;
196
+ }
197
+ set year(value) {
198
+ if (value !== undefined) {
199
+ if (this._stateless) {
200
+ this._state.displayYear = value;
201
+ this.setAttribute('year', value.toString());
202
+ }
203
+ else {
204
+ this._state.selectedYear = value;
205
+ this._state.displayYear = value;
206
+ this.setAttribute('year', value.toString());
207
+ }
208
+ }
209
+ else {
210
+ if (!this._stateless) {
211
+ delete this._state.selectedYear;
212
+ }
213
+ this.removeAttribute('year');
214
+ }
215
+ this.syncChildComponents();
216
+ if (!this._stateless) {
217
+ this.updateFormValue();
218
+ }
219
+ }
220
+ get month() {
221
+ return this._state.selectedMonth;
222
+ }
223
+ set month(value) {
224
+ if (value !== undefined) {
225
+ if (this._stateless) {
226
+ this._state.displayMonth = value;
227
+ this.setAttribute('month', value.toString());
228
+ }
229
+ else {
230
+ this._state.selectedMonth = value;
231
+ this._state.displayMonth = value;
232
+ this.setAttribute('month', value.toString());
233
+ }
234
+ }
235
+ else {
236
+ if (!this._stateless) {
237
+ delete this._state.selectedMonth;
238
+ }
239
+ this.removeAttribute('month');
240
+ }
241
+ this.syncChildComponents();
242
+ if (!this._stateless) {
243
+ this.updateFormValue();
244
+ }
245
+ }
246
+ get day() {
247
+ return this._state.selectedDay;
248
+ }
249
+ set day(value) {
250
+ if (value !== undefined) {
251
+ this._state.selectedDay = value;
252
+ this.setAttribute('day', value.toString());
253
+ }
254
+ else {
255
+ delete this._state.selectedDay;
256
+ this.removeAttribute('day');
257
+ }
258
+ this.syncChildComponents();
259
+ this.updateFormValue();
260
+ }
261
+ get locale() {
262
+ return getEffectiveLocale(this, this.getAttribute('locale'));
263
+ }
264
+ set locale(value) {
265
+ this.setAttribute('locale', value);
266
+ }
267
+ get hideNavigation() {
268
+ return this._hideNavigation;
269
+ }
270
+ set hideNavigation(value) {
271
+ this._hideNavigation = value;
272
+ if (value)
273
+ this.setAttribute('hide-navigation', '');
274
+ else
275
+ this.removeAttribute('hide-navigation');
276
+ }
277
+ get stateless() {
278
+ return this._stateless;
279
+ }
280
+ set stateless(value) {
281
+ this._stateless = value;
282
+ if (value) {
283
+ this.setAttribute('stateless', '');
284
+ }
285
+ else {
286
+ this.removeAttribute('stateless');
287
+ }
288
+ }
289
+ get size() {
290
+ return this._size;
291
+ }
292
+ set size(value) {
293
+ if (this._size !== value) {
294
+ this._size = value;
295
+ this._width = undefined;
296
+ this.removeAttribute('width');
297
+ this.setAttribute('size', value);
298
+ this.syncChildComponents();
299
+ }
300
+ }
301
+ get width() {
302
+ return this._width;
303
+ }
304
+ set width(value) {
305
+ if (this._width !== value) {
306
+ this._width = value;
307
+ if (value) {
308
+ this._size = 'md';
309
+ this.removeAttribute('size');
310
+ this.setAttribute('width', value);
311
+ }
312
+ else {
313
+ this.removeAttribute('width');
314
+ }
315
+ this.syncChildComponents();
316
+ }
317
+ }
318
+ get dayContentFn() {
319
+ return this._dayContentFn;
320
+ }
321
+ set dayContentFn(fn) {
322
+ this._dayContentFn = fn;
323
+ this.syncChildComponents();
324
+ }
325
+ get customCSS() {
326
+ return this._customCSS;
327
+ }
328
+ set customCSS(sheet) {
329
+ this._customCSS = sheet;
330
+ this.syncChildComponents();
331
+ }
332
+ get value() {
333
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
334
+ if (selectedYear && selectedMonth && selectedDay) {
335
+ return formatDateISO(selectedYear, selectedMonth, selectedDay);
336
+ }
337
+ return '';
338
+ }
339
+ set value(isoDate) {
340
+ if (!isoDate) {
341
+ delete this._state.selectedYear;
342
+ delete this._state.selectedMonth;
343
+ delete this._state.selectedDay;
344
+ if (!this._stateless) {
345
+ this.removeAttribute('year');
346
+ this.removeAttribute('month');
347
+ this.removeAttribute('day');
348
+ }
349
+ }
350
+ else {
351
+ const match = isoDate.match(/^(\d{4})-(\d{2})-(\d{2})$/);
352
+ if (match) {
353
+ const year = parseInt(match[1], 10);
354
+ const month = parseInt(match[2], 10);
355
+ const day = parseInt(match[3], 10);
356
+ this._state.selectedYear = year;
357
+ this._state.selectedMonth = month;
358
+ this._state.selectedDay = day;
359
+ this._state.displayYear = year;
360
+ this._state.displayMonth = month;
361
+ if (!this._stateless) {
362
+ this.setAttribute('year', year.toString());
363
+ this.setAttribute('month', month.toString());
364
+ this.setAttribute('day', day.toString());
365
+ }
366
+ }
367
+ }
368
+ this.syncChildComponents();
369
+ if (!this._stateless) {
370
+ this.updateFormValue();
371
+ }
372
+ }
373
+ initializeFromAttributes() {
374
+ const yearStr = this.getAttribute('year');
375
+ const monthStr = this.getAttribute('month');
376
+ const dayStr = this.getAttribute('day');
377
+ const hideNav = this.hasAttribute('hide-navigation');
378
+ const statelessStr = this.getAttribute('stateless');
379
+ const sizeStr = this.getAttribute('size');
380
+ const widthStr = this.getAttribute('width');
381
+ this._min = this.getAttribute('min') || undefined;
382
+ this._max = this.getAttribute('max') || undefined;
383
+ const year = parseYear(yearStr);
384
+ if (year) {
385
+ this._state.displayYear = year;
386
+ }
387
+ const month = parseMonth(monthStr);
388
+ if (month) {
389
+ this._state.displayMonth = month;
390
+ }
391
+ if (year && month) {
392
+ const day = parseDay(dayStr, year, month);
393
+ if (day) {
394
+ this._state.selectedYear = year;
395
+ this._state.selectedMonth = month;
396
+ this._state.selectedDay = day;
397
+ }
398
+ }
399
+ this._hideNavigation = hideNav;
400
+ if (statelessStr !== null) {
401
+ this._stateless = statelessStr !== 'false';
402
+ }
403
+ if (sizeStr && (sizeStr === 'sm' || sizeStr === 'md' || sizeStr === 'lg')) {
404
+ this._size = sizeStr;
405
+ }
406
+ if (widthStr) {
407
+ this._width = widthStr;
408
+ }
409
+ this._initialValue = this.value;
410
+ }
411
+ formResetCallback() {
412
+ this.value = this._initialValue;
413
+ }
414
+ syncStateFromAttributes() {
415
+ const yearStr = this.getAttribute('year');
416
+ const monthStr = this.getAttribute('month');
417
+ const dayStr = this.getAttribute('day');
418
+ const year = parseYear(yearStr);
419
+ const month = parseMonth(monthStr);
420
+ if (year)
421
+ this._state.displayYear = year;
422
+ if (month)
423
+ this._state.displayMonth = month;
424
+ if (year && month) {
425
+ const day = parseDay(dayStr, year, month);
426
+ if (day) {
427
+ this._state.selectedYear = year;
428
+ this._state.selectedMonth = month;
429
+ this._state.selectedDay = day;
430
+ }
431
+ else {
432
+ delete this._state.selectedYear;
433
+ delete this._state.selectedMonth;
434
+ delete this._state.selectedDay;
435
+ }
436
+ }
437
+ else {
438
+ delete this._state.selectedYear;
439
+ delete this._state.selectedMonth;
440
+ delete this._state.selectedDay;
441
+ }
442
+ }
443
+ syncChildComponents() {
444
+ if (this._navigation) {
445
+ this._navigation.displayMonth = this._state.displayMonth;
446
+ this._navigation.displayYear = this._state.displayYear;
447
+ this._navigation.locale = this.locale;
448
+ this._navigation.size = this._size;
449
+ this._navigation.min = this._min ?? '';
450
+ this._navigation.max = this._max ?? '';
451
+ this._navigation.width = this._width;
452
+ this._navigation.view = this._view;
453
+ }
454
+ if (this._monthGrid) {
455
+ this.showBody();
456
+ }
457
+ if (this._monthDisplay) {
458
+ this._monthDisplay.displayMonth = this._state.displayMonth;
459
+ this._monthDisplay.displayYear = this._state.displayYear;
460
+ this._monthDisplay.locale = this.locale;
461
+ this._monthDisplay.size = this._size;
462
+ this._monthDisplay.min = this._min;
463
+ this._monthDisplay.max = this._max;
464
+ this._monthDisplay.flavor = this._flavor;
465
+ this._monthDisplay.width = this._width;
466
+ if (this._dayContentFn) {
467
+ this._monthDisplay.dayContentFn = this._dayContentFn;
468
+ }
469
+ if (this._customCSS) {
470
+ this._monthDisplay.customCSS = this._customCSS;
471
+ }
472
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
473
+ if (selectedYear && selectedMonth && selectedDay) {
474
+ const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
475
+ this._monthDisplay.value = date.getTime();
476
+ }
477
+ else {
478
+ this._monthDisplay.value = null;
479
+ }
480
+ }
481
+ }
482
+ updateFormValue() {
483
+ if (this._stateless)
484
+ return;
485
+ if (!this._internals)
486
+ return;
487
+ const elementName = this.getAttribute('name');
488
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
489
+ if (elementName && selectedYear && selectedMonth && selectedDay) {
490
+ const isoDate = formatDateISO(selectedYear, selectedMonth, selectedDay);
491
+ this._internals.setFormValue(isoDate);
492
+ }
493
+ else {
494
+ this._internals.setFormValue('');
495
+ }
496
+ this.updateValidity();
497
+ }
498
+ updateValidity() {
499
+ if (!this._internals)
500
+ return;
501
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
502
+ if (selectedYear && selectedMonth && selectedDay) {
503
+ const sel = Date.UTC(selectedYear, selectedMonth - 1, selectedDay);
504
+ const min = this._min ? parseISODate(this._min) : null;
505
+ const max = this._max ? parseISODate(this._max) : null;
506
+ if (min && sel < Date.UTC(min.year, min.month - 1, min.day)) {
507
+ this._validity.set({ rangeUnderflow: true }, `Date must be ${this._min} or later`);
508
+ return;
509
+ }
510
+ if (max && sel > Date.UTC(max.year, max.month - 1, max.day)) {
511
+ this._validity.set({ rangeOverflow: true }, `Date must be ${this._max} or earlier`);
512
+ return;
513
+ }
514
+ }
515
+ this._validity.set({});
516
+ }
517
+ get form() { return this._internals?.form ?? null; }
518
+ get validity() { return this._internals?.validity; }
519
+ get validationMessage() { return this._internals?.validationMessage ?? ''; }
520
+ get willValidate() { return this._internals?.willValidate ?? false; }
521
+ checkValidity() { return this._internals?.checkValidity() ?? true; }
522
+ reportValidity() { return this._validity?.report() ?? true; }
523
+ setCustomValidity(message) { this._validity?.setCustom(message); }
524
+ handleNavigationChange(event) {
525
+ event.preventDefault();
526
+ event.stopPropagation();
527
+ const { month, year } = event.detail;
528
+ this.goTo(month, year);
529
+ }
530
+ goTo(month, year) {
531
+ this._state.displayMonth = month;
532
+ this._state.displayYear = year;
533
+ this.syncChildComponents();
534
+ const navigateDetail = {
535
+ month,
536
+ year,
537
+ action: 'navigate',
538
+ source: 'navigation',
539
+ };
540
+ this.dispatchEvent(new CustomEvent('navigate', {
541
+ detail: navigateDetail,
542
+ bubbles: true,
543
+ composed: true,
544
+ cancelable: false,
545
+ }));
546
+ }
547
+ handleDayClick(event) {
548
+ event.preventDefault();
549
+ event.stopPropagation();
550
+ const { dayContext, year, month, day } = event.detail;
551
+ if (this._stateless) {
552
+ this.dispatchEvent(new CustomEvent('day-click', {
553
+ detail: event.detail,
554
+ bubbles: true,
555
+ composed: true,
556
+ cancelable: true,
557
+ }));
558
+ return;
559
+ }
560
+ this._state.selectedYear = year;
561
+ this._state.selectedMonth = month;
562
+ this._state.selectedDay = day;
563
+ this._state.displayYear = year;
564
+ this._state.displayMonth = month;
565
+ this.setAttribute('year', year.toString());
566
+ this.setAttribute('month', month.toString());
567
+ this.setAttribute('day', day.toString());
568
+ this.updateFormValue();
569
+ this.syncChildComponents();
570
+ const changeDetail = {
571
+ year,
572
+ month,
573
+ day,
574
+ action: 'select',
575
+ source: 'day-click',
576
+ dayContext,
577
+ };
578
+ this.dispatchEvent(new CustomEvent('change', {
579
+ detail: changeDetail,
580
+ bubbles: true,
581
+ composed: true,
582
+ cancelable: false,
583
+ }));
584
+ }
585
+ refresh() {
586
+ this.syncChildComponents();
587
+ if (this._monthDisplay && typeof this._monthDisplay.refresh === 'function') {
588
+ this._monthDisplay.refresh();
589
+ }
590
+ }
591
+ createNavigation() {
592
+ const nav = document.createElement('ty-calendar-navigation');
593
+ nav.displayMonth = this._state.displayMonth;
594
+ nav.displayYear = this._state.displayYear;
595
+ nav.locale = this.locale;
596
+ nav.size = this._size;
597
+ nav.min = this._min ?? '';
598
+ nav.max = this._max ?? '';
599
+ if (this._width) {
600
+ nav.width = this._width;
601
+ }
602
+ nav.view = this._view;
603
+ nav.addEventListener('change', (e) => this.handleNavigationChange(e));
604
+ nav.addEventListener('view-toggle', (e) => {
605
+ this.setView(e.detail.view);
606
+ this.focusNavTitle();
607
+ });
608
+ this._navigation = nav;
609
+ return nav;
610
+ }
611
+ createMonthDisplay() {
612
+ const month = document.createElement('ty-calendar-month');
613
+ month.displayMonth = this._state.displayMonth;
614
+ month.displayYear = this._state.displayYear;
615
+ month.locale = this.locale;
616
+ month.size = this._size;
617
+ month.min = this._min;
618
+ month.max = this._max;
619
+ month.flavor = this._flavor;
620
+ if (this._width) {
621
+ month.width = this._width;
622
+ }
623
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
624
+ if (selectedYear && selectedMonth && selectedDay) {
625
+ const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
626
+ month.value = date.getTime();
627
+ }
628
+ if (this._dayContentFn) {
629
+ month.dayContentFn = this._dayContentFn;
630
+ }
631
+ if (this._customCSS) {
632
+ month.customCSS = this._customCSS;
633
+ }
634
+ month.addEventListener('day-click', (e) => this.handleDayClick(e));
635
+ this._monthDisplay = month;
636
+ return month;
637
+ }
638
+ render() {
639
+ const root = this.shadowRoot;
640
+ if (!root)
641
+ return;
642
+ ensureStyles(root, { css: calendarStyles, id: 'ty-calendar' });
643
+ root.innerHTML = '';
644
+ this._monthGrid = undefined;
645
+ const container = document.createElement('div');
646
+ container.className = 'calendar-container';
647
+ container.addEventListener('keydown', (e) => this.handleKeydown(e));
648
+ this._container = container;
649
+ if (!this._hideNavigation) {
650
+ const nav = this.createNavigation();
651
+ container.appendChild(nav);
652
+ }
653
+ const month = this.createMonthDisplay();
654
+ container.appendChild(month);
655
+ root.appendChild(container);
656
+ if (this._view === 'months')
657
+ this.showBody();
658
+ }
659
+ setView(view) {
660
+ if (view === this._view)
661
+ return;
662
+ if (view === 'months' && this._monthDisplay) {
663
+ this._dayGridHeight = this._monthDisplay.getBoundingClientRect().height;
664
+ }
665
+ this._view = view;
666
+ if (this._navigation)
667
+ this._navigation.view = view;
668
+ this.showBody();
669
+ }
670
+ showBody() {
671
+ const container = this._container;
672
+ if (!container || !this._monthDisplay)
673
+ return;
674
+ if (this._view === 'days') {
675
+ this._monthGrid?.remove();
676
+ this._monthGrid = undefined;
677
+ if (!this._monthDisplay.isConnected)
678
+ container.appendChild(this._monthDisplay);
679
+ return;
680
+ }
681
+ const grid = this.buildMonthGrid();
682
+ if (this._monthGrid)
683
+ this._monthGrid.replaceWith(grid);
684
+ else {
685
+ this._monthDisplay.remove();
686
+ container.appendChild(grid);
687
+ }
688
+ this._monthGrid = grid;
689
+ }
690
+ static monthIndex(year, month) {
691
+ return year * 12 + (month - 1);
692
+ }
693
+ boundIndices() {
694
+ const min = this._min ? parseISODate(this._min) : null;
695
+ const max = this._max ? parseISODate(this._max) : null;
696
+ return {
697
+ minIdx: min ? TyCalendar.monthIndex(min.year, min.month) : null,
698
+ maxIdx: max ? TyCalendar.monthIndex(max.year, max.month) : null,
699
+ };
700
+ }
701
+ buildMonthGrid() {
702
+ const { displayYear, displayMonth, selectedYear, selectedMonth } = this._state;
703
+ const today = getCurrentDate();
704
+ const { minIdx, maxIdx } = this.boundIndices();
705
+ const grid = document.createElement('div');
706
+ grid.className = `month-grid size-${this._size}`;
707
+ grid.setAttribute('role', 'grid');
708
+ grid.setAttribute('aria-label', String(displayYear));
709
+ if (this._dayGridHeight)
710
+ grid.style.minHeight = `${this._dayGridHeight}px`;
711
+ if (this._width)
712
+ grid.style.setProperty('--calendar-width', this._width);
713
+ for (let month = 1; month <= 12; month++) {
714
+ const idx = TyCalendar.monthIndex(displayYear, month);
715
+ const disabled = (minIdx !== null && idx < minIdx) || (maxIdx !== null && idx > maxIdx);
716
+ const selected = selectedYear === displayYear && selectedMonth === month;
717
+ const cell = document.createElement('button');
718
+ cell.type = 'button';
719
+ cell.className = 'month-cell';
720
+ cell.setAttribute('role', 'gridcell');
721
+ cell.setAttribute('aria-selected', String(selected));
722
+ cell.setAttribute('aria-label', `${getMonthName(month, this.locale, 'long')} ${displayYear}`);
723
+ cell.dataset.month = String(month);
724
+ cell.tabIndex = month === displayMonth ? 0 : -1;
725
+ cell.disabled = disabled;
726
+ if (selected)
727
+ cell.classList.add('selected');
728
+ if (today.year === displayYear && today.month === month)
729
+ cell.classList.add('current');
730
+ cell.textContent = getMonthName(month, this.locale, 'short');
731
+ cell.addEventListener('click', () => this.pickMonth(month));
732
+ grid.appendChild(cell);
733
+ }
734
+ grid.addEventListener('keydown', (e) => {
735
+ const delta = e.key === 'ArrowLeft' ? -1 :
736
+ e.key === 'ArrowRight' ? 1 :
737
+ e.key === 'ArrowUp' ? -3 :
738
+ e.key === 'ArrowDown' ? 3 :
739
+ 0;
740
+ if (!delta)
741
+ return;
742
+ const cells = Array.from(grid.querySelectorAll('.month-cell'));
743
+ const current = cells.findIndex(c => c === this.shadowRoot.activeElement);
744
+ const next = cells[(current === -1 ? displayMonth - 1 : current) + delta];
745
+ if (!next || next.disabled)
746
+ return;
747
+ e.preventDefault();
748
+ cells.forEach(c => (c.tabIndex = -1));
749
+ next.tabIndex = 0;
750
+ next.focus();
751
+ });
752
+ return grid;
753
+ }
754
+ pickMonth(month) {
755
+ this.setView('days');
756
+ this.goTo(month, this._state.displayYear);
757
+ this.focusDayGrid();
758
+ }
759
+ handleKeydown(e) {
760
+ if (e.key === 'Escape' && this._view === 'months') {
761
+ e.preventDefault();
762
+ e.stopPropagation();
763
+ this.setView('days');
764
+ this.focusNavTitle();
765
+ return;
766
+ }
767
+ if (e.key !== 'PageUp' && e.key !== 'PageDown')
768
+ return;
769
+ e.preventDefault();
770
+ const sign = e.key === 'PageUp' ? -1 : 1;
771
+ const step = e.shiftKey || this._view === 'months' ? 12 : 1;
772
+ const current = TyCalendar.monthIndex(this._state.displayYear, this._state.displayMonth);
773
+ const { minIdx, maxIdx } = this.boundIndices();
774
+ let target = current + sign * step;
775
+ if (minIdx !== null && target < minIdx)
776
+ target = minIdx;
777
+ if (maxIdx !== null && target > maxIdx)
778
+ target = maxIdx;
779
+ if (target === current)
780
+ return;
781
+ this.goTo((target % 12) + 1, Math.floor(target / 12));
782
+ if (this._view === 'months') {
783
+ const cell = this._monthGrid?.querySelector('.month-cell[tabindex="0"]');
784
+ cell?.focus();
785
+ }
786
+ else {
787
+ this.focusDayGrid();
788
+ }
789
+ }
790
+ focusNavTitle() {
791
+ requestAnimationFrame(() => {
792
+ this._navigation?.shadowRoot?.querySelector('.nav-title')?.focus();
793
+ });
794
+ }
795
+ focusDayGrid() {
796
+ requestAnimationFrame(() => {
797
+ const cell = this._monthDisplay?.shadowRoot?.querySelector('.calendar-day-cell[tabindex="0"]');
798
+ cell?.focus();
799
+ });
800
+ }
619
801
  }
620
802
  TyCalendar.formAssociated = true;
621
803
  if (!customElements.get('ty-calendar')) {
622
- customElements.define('ty-calendar', TyCalendar);
804
+ customElements.define('ty-calendar', TyCalendar);
623
805
  }