tyrell-components 1.0.0-TC8 → 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.
Files changed (386) hide show
  1. package/AGENTS.md +122 -0
  2. package/CHANGELOG.md +1531 -0
  3. package/README.md +71 -53
  4. package/css/tyrell-colors-static.css +1 -0
  5. package/css/tyrell-theme.css +1 -0
  6. package/css/tyrell.css +1 -1783
  7. package/dist/tyrell-colors-static.css +1 -0
  8. package/dist/tyrell-theme.css +1 -0
  9. package/dist/tyrell.css +1 -1783
  10. package/dist/tyrell.js +1 -1
  11. package/guides/AGENT_INSTRUCTIONS.md +124 -0
  12. package/guides/AI_GUIDE.md +53 -0
  13. package/guides/CSS_GUIDE.md +1016 -0
  14. package/guides/DATASTAR_TY_GUIDE.md +657 -0
  15. package/guides/ICONS_GUIDE.md +212 -0
  16. package/guides/TY_GUIDE.md +935 -0
  17. package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
  18. package/guides/clj/CODE_SPLITTING.md +279 -0
  19. package/guides/clj/COMPONENT_GUIDE.md +391 -0
  20. package/guides/clj/HELIX_TY_GUIDE.md +428 -0
  21. package/guides/clj/I18N_GUIDE.md +478 -0
  22. package/guides/clj/LAYOUT_GUIDE.md +273 -0
  23. package/guides/clj/QUICKSTART.md +266 -0
  24. package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
  25. package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
  26. package/guides/clj/ROUTING_GUIDE.md +346 -0
  27. package/guides/clj/UIX_TY_GUIDE.md +319 -0
  28. package/guides/js/HTMX_TY_GUIDE.md +252 -0
  29. package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
  30. package/guides/js/REACT_TY_GUIDE.md +983 -0
  31. package/guides/js/SVELTE_TY_GUIDE.md +682 -0
  32. package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
  33. package/guides/js/VUE_TY_GUIDE.md +738 -0
  34. package/lib/base/ty-component.d.ts +57 -13
  35. package/lib/base/ty-component.js +266 -292
  36. package/lib/components/button.d.ts +42 -18
  37. package/lib/components/button.js +318 -235
  38. package/lib/components/calendar-month.d.ts +30 -47
  39. package/lib/components/calendar-month.js +455 -429
  40. package/lib/components/calendar-navigation.d.ts +41 -49
  41. package/lib/components/calendar-navigation.js +287 -346
  42. package/lib/components/calendar.d.ts +73 -83
  43. package/lib/components/calendar.js +837 -762
  44. package/lib/components/checkbox.d.ts +26 -75
  45. package/lib/components/checkbox.js +298 -391
  46. package/lib/components/copy.d.ts +20 -60
  47. package/lib/components/copy.js +276 -380
  48. package/lib/components/date-picker.d.ts +100 -183
  49. package/lib/components/date-picker.js +1155 -1570
  50. package/lib/components/file-upload.d.ts +122 -0
  51. package/lib/components/file-upload.js +451 -0
  52. package/lib/components/icon.d.ts +3 -24
  53. package/lib/components/icon.js +141 -230
  54. package/lib/components/input.d.ts +93 -108
  55. package/lib/components/input.js +734 -710
  56. package/lib/components/modal.d.ts +39 -29
  57. package/lib/components/modal.js +419 -438
  58. package/lib/components/option.d.ts +20 -35
  59. package/lib/components/option.js +184 -309
  60. package/lib/components/popup.d.ts +2 -17
  61. package/lib/components/popup.js +353 -347
  62. package/lib/components/radio.d.ts +33 -25
  63. package/lib/components/radio.js +433 -422
  64. package/lib/components/resize-observer.d.ts +3 -30
  65. package/lib/components/resize-observer.js +71 -103
  66. package/lib/components/scroll-container.d.ts +21 -14
  67. package/lib/components/scroll-container.js +292 -234
  68. package/lib/components/select.d.ts +446 -0
  69. package/lib/components/select.js +1381 -0
  70. package/lib/components/selected-tags.d.ts +60 -0
  71. package/lib/components/selected-tags.js +225 -0
  72. package/lib/components/sortable.d.ts +175 -0
  73. package/lib/components/sortable.js +1844 -0
  74. package/lib/components/step.d.ts +1 -6
  75. package/lib/components/step.js +62 -68
  76. package/lib/components/switch.d.ts +15 -15
  77. package/lib/components/switch.js +237 -231
  78. package/lib/components/tab.d.ts +50 -7
  79. package/lib/components/tab.js +203 -69
  80. package/lib/components/tabs.d.ts +19 -64
  81. package/lib/components/tabs.js +600 -618
  82. package/lib/components/tag.d.ts +17 -55
  83. package/lib/components/tag.js +235 -308
  84. package/lib/components/textarea.d.ts +58 -89
  85. package/lib/components/textarea.js +523 -573
  86. package/lib/components/tooltip.d.ts +8 -13
  87. package/lib/components/tooltip.js +322 -409
  88. package/lib/components/wizard.d.ts +7 -54
  89. package/lib/components/wizard.js +376 -606
  90. package/lib/icons/fontawesome/brands.d.ts +0 -1
  91. package/lib/icons/fontawesome/brands.js +0 -8
  92. package/lib/icons/fontawesome/regular.d.ts +0 -1
  93. package/lib/icons/fontawesome/regular.js +0 -8
  94. package/lib/icons/fontawesome/solid.d.ts +0 -1
  95. package/lib/icons/fontawesome/solid.js +0 -8
  96. package/lib/icons/heroicons/micro.d.ts +0 -1
  97. package/lib/icons/heroicons/micro.js +392 -400
  98. package/lib/icons/heroicons/mini.d.ts +0 -1
  99. package/lib/icons/heroicons/mini.js +382 -390
  100. package/lib/icons/heroicons/outline.d.ts +0 -1
  101. package/lib/icons/heroicons/outline.js +337 -345
  102. package/lib/icons/heroicons/solid.d.ts +0 -1
  103. package/lib/icons/heroicons/solid.js +407 -415
  104. package/lib/icons/lucide.d.ts +0 -1
  105. package/lib/icons/lucide.js +24479 -26351
  106. package/lib/icons/material/filled.d.ts +0 -1
  107. package/lib/icons/material/filled.js +9653 -9663
  108. package/lib/icons/material/outlined.d.ts +0 -1
  109. package/lib/icons/material/outlined.js +10271 -10281
  110. package/lib/icons/material/round.d.ts +0 -1
  111. package/lib/icons/material/round.js +10495 -10505
  112. package/lib/icons/material/sharp.d.ts +0 -1
  113. package/lib/icons/material/sharp.js +9905 -9915
  114. package/lib/icons/material/two-tone.d.ts +0 -1
  115. package/lib/icons/material/two-tone.js +12792 -12802
  116. package/lib/index.d.ts +15 -4
  117. package/lib/index.js +28 -38
  118. package/lib/styles/button.d.ts +24 -7
  119. package/lib/styles/button.js +298 -417
  120. package/lib/styles/calendar-month.d.ts +7 -6
  121. package/lib/styles/calendar-month.js +157 -179
  122. package/lib/styles/calendar-navigation.d.ts +2 -6
  123. package/lib/styles/calendar-navigation.js +108 -109
  124. package/lib/styles/calendar.d.ts +3 -3
  125. package/lib/styles/calendar.js +87 -23
  126. package/lib/styles/checkbox.d.ts +7 -6
  127. package/lib/styles/checkbox.js +101 -15
  128. package/lib/styles/copy.d.ts +3 -2
  129. package/lib/styles/copy.js +91 -71
  130. package/lib/styles/custom-scrollbar.d.ts +1 -2
  131. package/lib/styles/custom-scrollbar.js +80 -115
  132. package/lib/styles/date-picker.d.ts +4 -6
  133. package/lib/styles/date-picker.js +320 -352
  134. package/lib/styles/field-size.d.ts +6 -0
  135. package/lib/styles/field-size.js +91 -0
  136. package/lib/styles/file-upload.d.ts +1 -0
  137. package/lib/styles/file-upload.js +196 -0
  138. package/lib/styles/icon.d.ts +2 -6
  139. package/lib/styles/icon.js +92 -170
  140. package/lib/styles/input.d.ts +4 -7
  141. package/lib/styles/input.js +148 -643
  142. package/lib/styles/modal.d.ts +1 -2
  143. package/lib/styles/modal.js +127 -108
  144. package/lib/styles/option.d.ts +2 -6
  145. package/lib/styles/option.js +53 -96
  146. package/lib/styles/popup.d.ts +1 -2
  147. package/lib/styles/popup.js +47 -77
  148. package/lib/styles/radio.d.ts +3 -2
  149. package/lib/styles/radio.js +90 -116
  150. package/lib/styles/resize-observer.d.ts +1 -2
  151. package/lib/styles/resize-observer.js +2 -12
  152. package/lib/styles/scroll-container.d.ts +1 -2
  153. package/lib/styles/scroll-container.js +103 -146
  154. package/lib/styles/select-base.d.ts +8 -0
  155. package/lib/styles/select-base.js +747 -0
  156. package/lib/styles/select.d.ts +11 -0
  157. package/lib/styles/select.js +229 -0
  158. package/lib/styles/sortable.d.ts +16 -0
  159. package/lib/styles/sortable.js +85 -0
  160. package/lib/styles/step.d.ts +1 -2
  161. package/lib/styles/step.js +15 -34
  162. package/lib/styles/switch.d.ts +3 -2
  163. package/lib/styles/switch.js +52 -68
  164. package/lib/styles/tab.d.ts +1 -2
  165. package/lib/styles/tab.js +86 -34
  166. package/lib/styles/tabs.d.ts +3 -11
  167. package/lib/styles/tabs.js +204 -162
  168. package/lib/styles/tag.d.ts +2 -6
  169. package/lib/styles/tag.js +170 -359
  170. package/lib/styles/textarea.d.ts +1 -2
  171. package/lib/styles/textarea.js +238 -306
  172. package/lib/styles/tooltip.d.ts +4 -3
  173. package/lib/styles/tooltip.js +3 -131
  174. package/lib/styles/wizard.d.ts +8 -20
  175. package/lib/styles/wizard.js +306 -295
  176. package/lib/types/common.d.ts +9 -8
  177. package/lib/types/common.js +8 -5
  178. package/lib/utils/calendar-utils.d.ts +49 -65
  179. package/lib/utils/calendar-utils.js +158 -343
  180. package/lib/utils/custom-scrollbar.d.ts +6 -20
  181. package/lib/utils/custom-scrollbar.js +273 -317
  182. package/lib/utils/flavor-sheet.d.ts +31 -0
  183. package/lib/utils/flavor-sheet.js +17 -0
  184. package/lib/utils/icon-registry.d.ts +0 -15
  185. package/lib/utils/icon-registry.js +138 -279
  186. package/lib/utils/icons.d.ts +9 -0
  187. package/lib/utils/icons.js +1 -0
  188. package/lib/utils/loader-registry.d.ts +34 -0
  189. package/lib/utils/loader-registry.js +11 -0
  190. package/lib/utils/locale.d.ts +2 -80
  191. package/lib/utils/locale.js +30 -205
  192. package/lib/utils/mobile.d.ts +0 -1
  193. package/lib/utils/mobile.js +1 -18
  194. package/lib/utils/number-format.d.ts +6 -24
  195. package/lib/utils/number-format.js +53 -136
  196. package/lib/utils/positioning.d.ts +72 -22
  197. package/lib/utils/positioning.js +224 -298
  198. package/lib/utils/property-capture.d.ts +5 -27
  199. package/lib/utils/property-capture.js +36 -144
  200. package/lib/utils/property-manager.d.ts +6 -6
  201. package/lib/utils/property-manager.js +127 -196
  202. package/lib/utils/resize-observer.d.ts +0 -1
  203. package/lib/utils/resize-observer.js +23 -59
  204. package/lib/utils/scroll-lock.d.ts +10 -11
  205. package/lib/utils/scroll-lock.js +165 -173
  206. package/lib/utils/styles.d.ts +0 -6
  207. package/lib/utils/styles.js +17 -48
  208. package/lib/utils/upgrade-properties.d.ts +21 -0
  209. package/lib/utils/upgrade-properties.js +47 -0
  210. package/lib/utils/validity.d.ts +122 -0
  211. package/lib/utils/validity.js +289 -0
  212. package/lib/version.d.ts +1 -2
  213. package/lib/version.js +1 -11
  214. package/package.json +66 -18
  215. package/lib/base/ty-component.d.ts.map +0 -1
  216. package/lib/base/ty-component.js.map +0 -1
  217. package/lib/components/button.d.ts.map +0 -1
  218. package/lib/components/button.js.map +0 -1
  219. package/lib/components/calendar-month.d.ts.map +0 -1
  220. package/lib/components/calendar-month.js.map +0 -1
  221. package/lib/components/calendar-navigation.d.ts.map +0 -1
  222. package/lib/components/calendar-navigation.js.map +0 -1
  223. package/lib/components/calendar.d.ts.map +0 -1
  224. package/lib/components/calendar.js.map +0 -1
  225. package/lib/components/checkbox.d.ts.map +0 -1
  226. package/lib/components/checkbox.js.map +0 -1
  227. package/lib/components/copy.d.ts.map +0 -1
  228. package/lib/components/copy.js.map +0 -1
  229. package/lib/components/date-picker.d.ts.map +0 -1
  230. package/lib/components/date-picker.js.map +0 -1
  231. package/lib/components/dropdown.d.ts +0 -402
  232. package/lib/components/dropdown.d.ts.map +0 -1
  233. package/lib/components/dropdown.js +0 -1564
  234. package/lib/components/dropdown.js.map +0 -1
  235. package/lib/components/icon.d.ts.map +0 -1
  236. package/lib/components/icon.js.map +0 -1
  237. package/lib/components/input.d.ts.map +0 -1
  238. package/lib/components/input.js.map +0 -1
  239. package/lib/components/modal.d.ts.map +0 -1
  240. package/lib/components/modal.js.map +0 -1
  241. package/lib/components/multiselect.d.ts +0 -397
  242. package/lib/components/multiselect.d.ts.map +0 -1
  243. package/lib/components/multiselect.js +0 -1580
  244. package/lib/components/multiselect.js.map +0 -1
  245. package/lib/components/option.d.ts.map +0 -1
  246. package/lib/components/option.js.map +0 -1
  247. package/lib/components/popup.d.ts.map +0 -1
  248. package/lib/components/popup.js.map +0 -1
  249. package/lib/components/radio.d.ts.map +0 -1
  250. package/lib/components/radio.js.map +0 -1
  251. package/lib/components/resize-observer.d.ts.map +0 -1
  252. package/lib/components/resize-observer.js.map +0 -1
  253. package/lib/components/scroll-container.d.ts.map +0 -1
  254. package/lib/components/scroll-container.js.map +0 -1
  255. package/lib/components/step.d.ts.map +0 -1
  256. package/lib/components/step.js.map +0 -1
  257. package/lib/components/switch.d.ts.map +0 -1
  258. package/lib/components/switch.js.map +0 -1
  259. package/lib/components/tab.d.ts.map +0 -1
  260. package/lib/components/tab.js.map +0 -1
  261. package/lib/components/tabs.d.ts.map +0 -1
  262. package/lib/components/tabs.js.map +0 -1
  263. package/lib/components/tag.d.ts.map +0 -1
  264. package/lib/components/tag.js.map +0 -1
  265. package/lib/components/textarea.d.ts.map +0 -1
  266. package/lib/components/textarea.js.map +0 -1
  267. package/lib/components/tooltip.d.ts.map +0 -1
  268. package/lib/components/tooltip.js.map +0 -1
  269. package/lib/components/wizard.d.ts.map +0 -1
  270. package/lib/components/wizard.js.map +0 -1
  271. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  272. package/lib/icons/fontawesome/brands.js.map +0 -1
  273. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  274. package/lib/icons/fontawesome/regular.js.map +0 -1
  275. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  276. package/lib/icons/fontawesome/solid.js.map +0 -1
  277. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  278. package/lib/icons/heroicons/micro.js.map +0 -1
  279. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  280. package/lib/icons/heroicons/mini.js.map +0 -1
  281. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  282. package/lib/icons/heroicons/outline.js.map +0 -1
  283. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  284. package/lib/icons/heroicons/solid.js.map +0 -1
  285. package/lib/icons/lucide.d.ts.map +0 -1
  286. package/lib/icons/lucide.js.map +0 -1
  287. package/lib/icons/material/filled.d.ts.map +0 -1
  288. package/lib/icons/material/filled.js.map +0 -1
  289. package/lib/icons/material/outlined.d.ts.map +0 -1
  290. package/lib/icons/material/outlined.js.map +0 -1
  291. package/lib/icons/material/round.d.ts.map +0 -1
  292. package/lib/icons/material/round.js.map +0 -1
  293. package/lib/icons/material/sharp.d.ts.map +0 -1
  294. package/lib/icons/material/sharp.js.map +0 -1
  295. package/lib/icons/material/two-tone.d.ts.map +0 -1
  296. package/lib/icons/material/two-tone.js.map +0 -1
  297. package/lib/index.d.ts.map +0 -1
  298. package/lib/index.js.map +0 -1
  299. package/lib/styles/button.d.ts.map +0 -1
  300. package/lib/styles/button.js.map +0 -1
  301. package/lib/styles/calendar-month.d.ts.map +0 -1
  302. package/lib/styles/calendar-month.js.map +0 -1
  303. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  304. package/lib/styles/calendar-navigation.js.map +0 -1
  305. package/lib/styles/calendar.d.ts.map +0 -1
  306. package/lib/styles/calendar.js.map +0 -1
  307. package/lib/styles/checkbox.d.ts.map +0 -1
  308. package/lib/styles/checkbox.js.map +0 -1
  309. package/lib/styles/copy.d.ts.map +0 -1
  310. package/lib/styles/copy.js.map +0 -1
  311. package/lib/styles/custom-scrollbar.d.ts.map +0 -1
  312. package/lib/styles/custom-scrollbar.js.map +0 -1
  313. package/lib/styles/date-picker.d.ts.map +0 -1
  314. package/lib/styles/date-picker.js.map +0 -1
  315. package/lib/styles/dropdown.d.ts +0 -12
  316. package/lib/styles/dropdown.d.ts.map +0 -1
  317. package/lib/styles/dropdown.js +0 -983
  318. package/lib/styles/dropdown.js.map +0 -1
  319. package/lib/styles/icon.d.ts.map +0 -1
  320. package/lib/styles/icon.js.map +0 -1
  321. package/lib/styles/input.d.ts.map +0 -1
  322. package/lib/styles/input.js.map +0 -1
  323. package/lib/styles/modal.d.ts.map +0 -1
  324. package/lib/styles/modal.js.map +0 -1
  325. package/lib/styles/multiselect.d.ts +0 -6
  326. package/lib/styles/multiselect.d.ts.map +0 -1
  327. package/lib/styles/multiselect.js +0 -774
  328. package/lib/styles/multiselect.js.map +0 -1
  329. package/lib/styles/option.d.ts.map +0 -1
  330. package/lib/styles/option.js.map +0 -1
  331. package/lib/styles/popup.d.ts.map +0 -1
  332. package/lib/styles/popup.js.map +0 -1
  333. package/lib/styles/radio.d.ts.map +0 -1
  334. package/lib/styles/radio.js.map +0 -1
  335. package/lib/styles/resize-observer.d.ts.map +0 -1
  336. package/lib/styles/resize-observer.js.map +0 -1
  337. package/lib/styles/scroll-container.d.ts.map +0 -1
  338. package/lib/styles/scroll-container.js.map +0 -1
  339. package/lib/styles/step.d.ts.map +0 -1
  340. package/lib/styles/step.js.map +0 -1
  341. package/lib/styles/switch.d.ts.map +0 -1
  342. package/lib/styles/switch.js.map +0 -1
  343. package/lib/styles/tab.d.ts.map +0 -1
  344. package/lib/styles/tab.js.map +0 -1
  345. package/lib/styles/tabs.d.ts.map +0 -1
  346. package/lib/styles/tabs.js.map +0 -1
  347. package/lib/styles/tag.d.ts.map +0 -1
  348. package/lib/styles/tag.js.map +0 -1
  349. package/lib/styles/textarea.d.ts.map +0 -1
  350. package/lib/styles/textarea.js.map +0 -1
  351. package/lib/styles/tooltip.d.ts.map +0 -1
  352. package/lib/styles/tooltip.js.map +0 -1
  353. package/lib/styles/wizard.d.ts.map +0 -1
  354. package/lib/styles/wizard.js.map +0 -1
  355. package/lib/types/common.d.ts.map +0 -1
  356. package/lib/types/common.js.map +0 -1
  357. package/lib/utils/calendar-utils.d.ts.map +0 -1
  358. package/lib/utils/calendar-utils.js.map +0 -1
  359. package/lib/utils/custom-scrollbar.d.ts.map +0 -1
  360. package/lib/utils/custom-scrollbar.js.map +0 -1
  361. package/lib/utils/icon-registry.d.ts.map +0 -1
  362. package/lib/utils/icon-registry.js.map +0 -1
  363. package/lib/utils/locale.d.ts.map +0 -1
  364. package/lib/utils/locale.js.map +0 -1
  365. package/lib/utils/mobile.d.ts.map +0 -1
  366. package/lib/utils/mobile.js.map +0 -1
  367. package/lib/utils/number-format.d.ts.map +0 -1
  368. package/lib/utils/number-format.js.map +0 -1
  369. package/lib/utils/parse-boolean.d.ts +0 -39
  370. package/lib/utils/parse-boolean.d.ts.map +0 -1
  371. package/lib/utils/parse-boolean.js +0 -58
  372. package/lib/utils/parse-boolean.js.map +0 -1
  373. package/lib/utils/positioning.d.ts.map +0 -1
  374. package/lib/utils/positioning.js.map +0 -1
  375. package/lib/utils/property-capture.d.ts.map +0 -1
  376. package/lib/utils/property-capture.js.map +0 -1
  377. package/lib/utils/property-manager.d.ts.map +0 -1
  378. package/lib/utils/property-manager.js.map +0 -1
  379. package/lib/utils/resize-observer.d.ts.map +0 -1
  380. package/lib/utils/resize-observer.js.map +0 -1
  381. package/lib/utils/scroll-lock.d.ts.map +0 -1
  382. package/lib/utils/scroll-lock.js.map +0 -1
  383. package/lib/utils/styles.d.ts.map +0 -1
  384. package/lib/utils/styles.js.map +0 -1
  385. package/lib/version.d.ts.map +0 -1
  386. package/lib/version.js.map +0 -1
@@ -1,774 +1,849 @@
1
- /**
2
- * TyCalendar Web Component
3
- * PORTED FROM: cljs/ty/components/calendar.cljs
4
- *
5
- * A complete calendar orchestration component that combines navigation and month display.
6
- * Manages selection state, form participation, and event coordination.
7
- *
8
- * Architecture:
9
- * - year/month/day HTML attributes for intuitive API
10
- * - Internal state management (private properties)
11
- * - Distributes properties to child components (navigation + month)
12
- * - Single 'change' event with complete day context
13
- * - Form participation via ElementInternals
14
- *
15
- * Features:
16
- * - Combines ty-calendar-navigation + ty-calendar-month
17
- * - Date selection with visual feedback
18
- * - Form integration (works with FormData)
19
- * - Custom render functions (dayContentFn)
20
- * - Custom CSS injection
21
- * - Automatic date validation
22
- * - Event coordination between components
23
- *
24
- * @example
25
- * ```html
26
- * <!-- Basic usage -->
27
- * <ty-calendar
28
- * year="2025"
29
- * month="10"
30
- * day="15">
31
- * </ty-calendar>
32
- *
33
- * <!-- Form integration -->
34
- * <form>
35
- * <ty-calendar name="booking-date"></ty-calendar>
36
- * <button type="submit">Submit</button>
37
- * </form>
38
- *
39
- * <!-- With custom rendering -->
40
- * <ty-calendar id="custom"></ty-calendar>
41
- * <script type="module">
42
- * const cal = document.getElementById('custom');
43
- * cal.dayContentFn = (ctx) => {
44
- * const el = document.createElement('div');
45
- * el.textContent = ctx.dayInMonth;
46
- * if (ctx.today) el.style.fontWeight = 'bold';
47
- * return el;
48
- * };
49
- * </script>
50
- * ```
51
- */
52
1
  import { ensureStyles } from '../utils/styles.js';
2
+ import { liftProperties, upgradeProperties } from '../utils/upgrade-properties.js';
53
3
  import { calendarStyles } from '../styles/calendar.js';
4
+ import './calendar-month.js';
5
+ import './calendar-navigation.js';
6
+ import { parseDateDay, formatISODay, toISODay, getMonthName, localMidnight, utcMidnight } from '../utils/calendar-utils.js';
54
7
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
55
- // ============================================================================
56
- // Helper Functions
57
- // ============================================================================
58
- /**
59
- * Get current date for defaults
60
- */
8
+ import { ValidityController, nativeMessage } from '../utils/validity.js';
61
9
  function getCurrentDate() {
62
- const now = new Date();
63
- return {
64
- year: now.getFullYear(),
65
- month: now.getMonth() + 1, // 1-based
66
- day: now.getDate(),
67
- };
68
- }
69
- /**
70
- * Validate and parse year from string
71
- */
10
+ const now = new Date();
11
+ return {
12
+ year: now.getFullYear(),
13
+ month: now.getMonth() + 1,
14
+ day: now.getDate(),
15
+ };
16
+ }
72
17
  function parseYear(yearStr) {
73
- if (!yearStr || !/^\d{4}$/.test(yearStr))
74
- return null;
75
- return parseInt(yearStr, 10);
18
+ if (!yearStr || !/^\d{4}$/.test(yearStr))
19
+ return null;
20
+ return parseInt(yearStr, 10);
76
21
  }
77
- /**
78
- * Validate and parse month from string (1-12)
79
- */
80
22
  function parseMonth(monthStr) {
81
- if (!monthStr || !/^\d{1,2}$/.test(monthStr))
82
- return null;
83
- const month = parseInt(monthStr, 10);
84
- return month >= 1 && month <= 12 ? month : null;
85
- }
86
- /**
87
- * Validate and parse day from string (1-31, validated against month)
88
- */
23
+ if (!monthStr || !/^\d{1,2}$/.test(monthStr))
24
+ return null;
25
+ const month = parseInt(monthStr, 10);
26
+ return month >= 1 && month <= 12 ? month : null;
27
+ }
89
28
  function parseDay(dayStr, year, month) {
90
- if (!dayStr || !/^\d{1,2}$/.test(dayStr))
91
- return null;
92
- const day = parseInt(dayStr, 10);
93
- // Get days in month for validation
94
- const daysInMonth = new Date(year, month, 0).getDate();
95
- return day >= 1 && day <= daysInMonth ? day : null;
96
- }
97
- /**
98
- * Format date as ISO string (YYYY-MM-DD) for form submission
99
- */
100
- function formatDateISO(year, month, day) {
101
- const monthStr = month.toString().padStart(2, '0');
102
- const dayStr = day.toString().padStart(2, '0');
103
- return `${year}-${monthStr}-${dayStr}`;
104
- }
105
- // ============================================================================
106
- // Component Implementation
107
- // ============================================================================
108
- /**
109
- * TyCalendar Web Component
110
- */
29
+ if (!dayStr || !/^\d{1,2}$/.test(dayStr))
30
+ return null;
31
+ const day = parseInt(dayStr, 10);
32
+ const daysInMonth = new Date(year, month, 0).getDate();
33
+ return day >= 1 && day <= daysInMonth ? day : null;
34
+ }
35
+ function formatYear(year) {
36
+ return year.toString().padStart(4, '0');
37
+ }
111
38
  export class TyCalendar extends HTMLElement {
112
- /**
113
- * Observed attributes
114
- */
115
- static get observedAttributes() {
116
- return ['year', 'month', 'day', 'show-navigation', 'stateless', 'locale', 'name', 'size', 'width'];
117
- }
118
- constructor() {
119
- super();
120
- this._locale = 'en-US';
121
- this._showNavigation = true;
122
- this._stateless = false;
123
- this._size = 'md';
124
- // Initialize state with current date
125
- const current = getCurrentDate();
126
- this._state = {
127
- displayYear: current.year,
128
- displayMonth: current.month,
129
- };
130
- this.attachShadow({ mode: 'open' });
131
- // Attach ElementInternals for form participation
132
- if ('attachInternals' in this) {
133
- this._internals = this.attachInternals();
134
- }
135
- }
136
- // ==========================================================================
137
- // Lifecycle Methods
138
- // ==========================================================================
139
- connectedCallback() {
140
- // Parse initial attributes
141
- this.initializeFromAttributes();
142
- // ✅ CHECK: Properties set before custom element upgrade
143
- // When scripts run before element is fully upgraded, properties are set as plain properties
144
- // without triggering setters. We need to migrate them to private fields.
145
- // Check for dayContentFn set before upgrade
146
- const plainDayContentFn = this.dayContentFn;
147
- if (plainDayContentFn && !this._dayContentFn) {
148
- console.log('📦 Migrating calendar dayContentFn set before upgrade');
149
- this._dayContentFn = plainDayContentFn;
150
- delete this.dayContentFn; // Clean up plain property
151
- }
152
- // Check for customCSS set before upgrade
153
- const plainCustomCSS = this.customCSS;
154
- if (plainCustomCSS && !this._customCSS) {
155
- console.log('📦 Migrating calendar customCSS set before upgrade');
156
- this._customCSS = plainCustomCSS;
157
- delete this.customCSS; // Clean up plain property
158
- }
159
- // Check for value set before upgrade
160
- const plainValue = this.value;
161
- if (plainValue && typeof plainValue === 'string' && plainValue !== this.value) {
162
- console.log('📦 Migrating calendar value set before upgrade:', plainValue);
163
- // Parse and set the value properly
164
- const match = plainValue.match(/^(\d{4})-(\d{2})-(\d{2})$/);
165
- if (match) {
166
- const year = parseInt(match[1], 10);
167
- const month = parseInt(match[2], 10);
168
- const day = parseInt(match[3], 10);
169
- this._state.selectedYear = year;
170
- this._state.selectedMonth = month;
171
- this._state.selectedDay = day;
172
- this._state.displayYear = year;
173
- this._state.displayMonth = month;
174
- // Update attributes if not in stateless mode
175
- if (!this._stateless) {
176
- this.setAttribute('year', year.toString());
177
- this.setAttribute('month', month.toString());
178
- this.setAttribute('day', day.toString());
179
- }
180
- }
181
- delete this.value; // Clean up plain property
182
- }
183
- // Render the calendar
184
- this.render();
185
- // Set initial form value if date is selected
186
- this.updateFormValue();
187
- // Setup locale observer to watch for ancestor lang changes
188
- this._localeObserver = observeLocaleChanges(this, () => {
189
- this.render();
190
- });
191
- }
192
- disconnectedCallback() {
193
- // Cleanup locale observer
194
- if (this._localeObserver) {
195
- this._localeObserver();
196
- this._localeObserver = undefined;
197
- }
198
- // Cleanup references
199
- this._navigation = undefined;
200
- this._monthDisplay = undefined;
201
- }
202
- attributeChangedCallback(name, oldValue, newValue) {
203
- if (oldValue === newValue)
204
- return;
205
- switch (name) {
206
- case 'year':
207
- case 'month':
208
- case 'day':
209
- this.syncStateFromAttributes();
210
- this.syncChildComponents();
211
- this.updateFormValue();
212
- break;
213
- case 'show-navigation':
214
- this._showNavigation = newValue !== 'false';
215
- this.render();
216
- break;
217
- case 'stateless':
218
- this._stateless = newValue !== null && newValue !== 'false';
219
- // No re-render needed, just changes behavior
220
- break;
221
- case 'locale':
222
- this._locale = newValue || 'en-US';
223
- this.syncChildComponents();
224
- break;
225
- case 'size':
226
- if (newValue === 'sm' || newValue === 'md' || newValue === 'lg') {
227
- this._size = newValue;
228
- // Clear width when size is set (mutually exclusive)
229
- this._width = undefined;
230
- this.removeAttribute('width');
231
- this.syncChildComponents();
232
- }
233
- break;
234
- case 'width':
235
- this._width = newValue || undefined;
236
- // Clear size when width is set (mutually exclusive)
237
- if (newValue) {
238
- this._size = 'md'; // Reset to default
239
- this.removeAttribute('size');
240
- }
241
- this.syncChildComponents();
242
- break;
243
- case 'name':
244
- // Name change triggers form value update
245
- this.updateFormValue();
246
- break;
247
- }
248
- }
249
- // ==========================================================================
250
- // Property Getters/Setters
251
- // ==========================================================================
252
- get year() {
253
- return this._state.selectedYear;
254
- }
255
- set year(value) {
256
- if (value !== undefined) {
257
- // In stateless mode, only update display
258
- if (this._stateless) {
259
- this._state.displayYear = value;
260
- this.setAttribute('year', value.toString());
261
- }
262
- else {
263
- // In stateful mode, update both selection and display
264
- this._state.selectedYear = value;
265
- this._state.displayYear = value;
266
- this.setAttribute('year', value.toString());
267
- }
268
- }
269
- else {
270
- if (!this._stateless) {
271
- delete this._state.selectedYear;
272
- }
273
- this.removeAttribute('year');
274
- }
275
- this.syncChildComponents();
276
- if (!this._stateless) {
277
- this.updateFormValue();
278
- }
279
- }
280
- get month() {
281
- return this._state.selectedMonth;
282
- }
283
- set month(value) {
284
- if (value !== undefined) {
285
- // In stateless mode, only update display
286
- if (this._stateless) {
287
- this._state.displayMonth = value;
288
- this.setAttribute('month', value.toString());
289
- }
290
- else {
291
- // In stateful mode, update both selection and display
292
- this._state.selectedMonth = value;
293
- this._state.displayMonth = value;
294
- this.setAttribute('month', value.toString());
295
- }
296
- }
297
- else {
298
- if (!this._stateless) {
299
- delete this._state.selectedMonth;
300
- }
301
- this.removeAttribute('month');
302
- }
303
- this.syncChildComponents();
304
- if (!this._stateless) {
305
- this.updateFormValue();
306
- }
307
- }
308
- get day() {
309
- return this._state.selectedDay;
310
- }
311
- set day(value) {
312
- if (value !== undefined) {
313
- this._state.selectedDay = value;
314
- this.setAttribute('day', value.toString());
315
- }
316
- else {
317
- delete this._state.selectedDay;
318
- this.removeAttribute('day');
319
- }
320
- this.syncChildComponents();
321
- this.updateFormValue();
322
- }
323
- get locale() {
324
- return getEffectiveLocale(this, this.getAttribute('locale'));
325
- }
326
- set locale(value) {
327
- this._locale = value;
328
- this.setAttribute('locale', value);
329
- }
330
- get showNavigation() {
331
- return this._showNavigation;
332
- }
333
- set showNavigation(value) {
334
- this._showNavigation = value;
335
- this.setAttribute('show-navigation', value.toString());
336
- }
337
- get stateless() {
338
- return this._stateless;
339
- }
340
- set stateless(value) {
341
- this._stateless = value;
342
- if (value) {
343
- this.setAttribute('stateless', '');
344
- }
345
- else {
346
- this.removeAttribute('stateless');
347
- }
348
- }
349
- get size() {
350
- return this._size;
351
- }
352
- set size(value) {
353
- if (this._size !== value) {
354
- this._size = value;
355
- // Clear width when size is set (mutually exclusive)
356
- this._width = undefined;
357
- this.removeAttribute('width');
358
- this.setAttribute('size', value);
359
- this.syncChildComponents();
360
- }
361
- }
362
- get width() {
363
- return this._width;
364
- }
365
- set width(value) {
366
- if (this._width !== value) {
367
- this._width = value;
368
- if (value) {
369
- // Clear size when width is set (mutually exclusive)
370
- this._size = 'md'; // Reset to default
371
- this.removeAttribute('size');
372
- this.setAttribute('width', value);
373
- }
374
- else {
375
- this.removeAttribute('width');
376
- }
377
- this.syncChildComponents();
378
- }
379
- }
380
- get dayContentFn() {
381
- return this._dayContentFn;
382
- }
383
- set dayContentFn(fn) {
384
- this._dayContentFn = fn;
385
- this.syncChildComponents();
386
- }
387
- get customCSS() {
388
- return this._customCSS;
389
- }
390
- set customCSS(sheet) {
391
- this._customCSS = sheet;
392
- this.syncChildComponents();
393
- }
394
- get value() {
395
- const { selectedYear, selectedMonth, selectedDay } = this._state;
396
- if (selectedYear && selectedMonth && selectedDay) {
397
- return formatDateISO(selectedYear, selectedMonth, selectedDay);
398
- }
399
- return '';
400
- }
401
- set value(isoDate) {
402
- if (!isoDate) {
403
- // Clear selection
404
- delete this._state.selectedYear;
405
- delete this._state.selectedMonth;
406
- delete this._state.selectedDay;
407
- // In normal mode, also clear attributes
408
- if (!this._stateless) {
409
- this.removeAttribute('year');
410
- this.removeAttribute('month');
411
- this.removeAttribute('day');
412
- }
413
- }
414
- else {
415
- // Parse ISO date (YYYY-MM-DD)
416
- const match = isoDate.match(/^(\d{4})-(\d{2})-(\d{2})$/);
417
- if (match) {
418
- const year = parseInt(match[1], 10);
419
- const month = parseInt(match[2], 10);
420
- const day = parseInt(match[3], 10);
421
- // Update internal selection state
422
- this._state.selectedYear = year;
423
- this._state.selectedMonth = month;
424
- this._state.selectedDay = day;
425
- // Update display to show this month
426
- this._state.displayYear = year;
427
- this._state.displayMonth = month;
428
- // In normal mode, update attributes
429
- // In stateless mode, skip attribute updates (parent controls attributes)
430
- if (!this._stateless) {
431
- this.setAttribute('year', year.toString());
432
- this.setAttribute('month', month.toString());
433
- this.setAttribute('day', day.toString());
434
- }
435
- }
436
- }
437
- this.syncChildComponents();
438
- // In normal mode, update form value
439
- if (!this._stateless) {
440
- this.updateFormValue();
441
- }
442
- }
443
- // ==========================================================================
444
- // State Management
445
- // ==========================================================================
446
- /**
447
- * Initialize state from HTML attributes on first load
448
- */
449
- initializeFromAttributes() {
450
- const yearStr = this.getAttribute('year');
451
- const monthStr = this.getAttribute('month');
452
- const dayStr = this.getAttribute('day');
453
- const localeStr = this.getAttribute('locale');
454
- const showNavStr = this.getAttribute('show-navigation');
455
- const statelessStr = this.getAttribute('stateless');
456
- const sizeStr = this.getAttribute('size');
457
- const widthStr = this.getAttribute('width');
458
- // Parse year
459
- const year = parseYear(yearStr);
460
- if (year) {
461
- this._state.displayYear = year;
462
- }
463
- // Parse month
464
- const month = parseMonth(monthStr);
465
- if (month) {
466
- this._state.displayMonth = month;
467
- }
468
- // Parse day (only if year and month are valid)
469
- if (year && month) {
470
- const day = parseDay(dayStr, year, month);
471
- if (day) {
472
- this._state.selectedYear = year;
473
- this._state.selectedMonth = month;
474
- this._state.selectedDay = day;
475
- }
476
- }
477
- // Locale
478
- if (localeStr) {
479
- this._locale = localeStr;
480
- }
481
- // Show navigation
482
- if (showNavStr) {
483
- this._showNavigation = showNavStr !== 'false';
484
- }
485
- // Stateless mode
486
- if (statelessStr !== null) {
487
- this._stateless = statelessStr !== 'false';
488
- }
489
- // Size
490
- if (sizeStr && (sizeStr === 'sm' || sizeStr === 'md' || sizeStr === 'lg')) {
491
- this._size = sizeStr;
492
- }
493
- // Width
494
- if (widthStr) {
495
- this._width = widthStr;
496
- }
497
- }
498
- /**
499
- * Sync state from changed attributes
500
- */
501
- syncStateFromAttributes() {
502
- const yearStr = this.getAttribute('year');
503
- const monthStr = this.getAttribute('month');
504
- const dayStr = this.getAttribute('day');
505
- const year = parseYear(yearStr);
506
- const month = parseMonth(monthStr);
507
- // Update display year/month
508
- if (year)
509
- this._state.displayYear = year;
510
- if (month)
511
- this._state.displayMonth = month;
512
- // Update selection (only if all three are valid)
513
- if (year && month) {
514
- const day = parseDay(dayStr, year, month);
515
- if (day) {
516
- this._state.selectedYear = year;
517
- this._state.selectedMonth = month;
518
- this._state.selectedDay = day;
519
- }
520
- else {
521
- // Clear selection if day is invalid
522
- delete this._state.selectedYear;
523
- delete this._state.selectedMonth;
524
- delete this._state.selectedDay;
525
- }
526
- }
527
- else {
528
- // Clear selection if year or month is invalid
529
- delete this._state.selectedYear;
530
- delete this._state.selectedMonth;
531
- delete this._state.selectedDay;
532
- }
533
- }
534
- /**
535
- * Update child components with current state
536
- */
537
- syncChildComponents() {
538
- // Update navigation
539
- if (this._navigation) {
540
- this._navigation.displayMonth = this._state.displayMonth;
541
- this._navigation.displayYear = this._state.displayYear;
542
- this._navigation.locale = this.locale;
543
- this._navigation.size = this._size;
544
- // Always sync width (set or clear)
545
- this._navigation.width = this._width;
546
- }
547
- // Update month display
548
- if (this._monthDisplay) {
549
- this._monthDisplay.displayMonth = this._state.displayMonth;
550
- this._monthDisplay.displayYear = this._state.displayYear;
551
- this._monthDisplay.locale = this.locale;
552
- this._monthDisplay.size = this._size;
553
- // Always sync width (set or clear)
554
- this._monthDisplay.width = this._width;
555
- // Pass render functions
556
- if (this._dayContentFn) {
557
- this._monthDisplay.dayContentFn = this._dayContentFn;
558
- }
559
- // Pass custom CSS
560
- if (this._customCSS) {
561
- this._monthDisplay.customCSS = this._customCSS;
562
- }
563
- // Update selection value (convert to Date timestamp)
564
- const { selectedYear, selectedMonth, selectedDay } = this._state;
565
- if (selectedYear && selectedMonth && selectedDay) {
566
- const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
567
- this._monthDisplay.value = date.getTime();
568
- }
569
- else {
570
- this._monthDisplay.value = null;
571
- }
572
- }
573
- }
574
- /**
575
- * Update form value using ElementInternals
576
- */
577
- updateFormValue() {
578
- // Skip form participation in stateless mode
579
- if (this._stateless)
580
- return;
581
- if (!this._internals)
582
- return;
583
- const elementName = this.getAttribute('name');
584
- const { selectedYear, selectedMonth, selectedDay } = this._state;
585
- if (elementName && selectedYear && selectedMonth && selectedDay) {
586
- const isoDate = formatDateISO(selectedYear, selectedMonth, selectedDay);
587
- this._internals.setFormValue(isoDate);
588
- }
589
- else {
590
- this._internals.setFormValue('');
591
- }
592
- }
593
- // ==========================================================================
594
- // Event Handlers
595
- // ==========================================================================
596
- /**
597
- * Handle navigation change (month/year navigation)
598
- */
599
- handleNavigationChange(event) {
600
- event.preventDefault();
601
- event.stopPropagation();
602
- const { month, year } = event.detail;
603
- // Update display state
604
- this._state.displayMonth = month;
605
- this._state.displayYear = year;
606
- // Sync child components
607
- this.syncChildComponents();
608
- // Emit navigate event
609
- const navigateDetail = {
610
- month,
611
- year,
612
- action: 'navigate',
613
- source: 'navigation',
614
- };
615
- this.dispatchEvent(new CustomEvent('navigate', {
616
- detail: navigateDetail,
617
- bubbles: true,
618
- composed: true,
619
- cancelable: false,
620
- }));
621
- }
622
- /**
623
- * Handle day click (day selection)
624
- */
625
- handleDayClick(event) {
626
- event.preventDefault();
627
- event.stopPropagation();
628
- const { dayContext, year, month, day } = event.detail;
629
- // In stateless mode, just re-dispatch the event without updating internal state
630
- if (this._stateless) {
631
- // Re-dispatch day-click event for parent to handle
632
- this.dispatchEvent(new CustomEvent('day-click', {
633
- detail: event.detail,
634
- bubbles: true,
635
- composed: true,
636
- cancelable: true,
637
- }));
638
- return;
639
- }
640
- // Normal mode: update selection state
641
- this._state.selectedYear = year;
642
- this._state.selectedMonth = month;
643
- this._state.selectedDay = day;
644
- this._state.displayYear = year;
645
- this._state.displayMonth = month;
646
- // Update HTML attributes
647
- this.setAttribute('year', year.toString());
648
- this.setAttribute('month', month.toString());
649
- this.setAttribute('day', day.toString());
650
- // Update form value
651
- this.updateFormValue();
652
- // Sync child components
653
- this.syncChildComponents();
654
- // Emit change event
655
- const changeDetail = {
656
- year,
657
- month,
658
- day,
659
- action: 'select',
660
- source: 'day-click',
661
- dayContext,
662
- };
663
- this.dispatchEvent(new CustomEvent('change', {
664
- detail: changeDetail,
665
- bubbles: true,
666
- composed: true,
667
- cancelable: false,
668
- }));
669
- }
670
- // ==========================================================================
671
- // Public Methods
672
- // ==========================================================================
673
- /**
674
- * Force re-render of the calendar
675
- * Useful after updating dayContentFn or other dynamic properties
676
- */
677
- refresh() {
678
- this.syncChildComponents();
679
- // Force month display to re-render (for async data updates)
680
- if (this._monthDisplay && typeof this._monthDisplay.refresh === 'function') {
681
- this._monthDisplay.refresh();
682
- }
683
- }
684
- // ==========================================================================
685
- // Rendering
686
- // ==========================================================================
687
- /**
688
- * Create navigation element
689
- */
690
- createNavigation() {
691
- const nav = document.createElement('ty-calendar-navigation');
692
- // Set properties
693
- nav.displayMonth = this._state.displayMonth;
694
- nav.displayYear = this._state.displayYear;
695
- nav.locale = this.locale;
696
- nav.size = this._size;
697
- // Only set width if explicitly provided
698
- if (this._width) {
699
- nav.width = this._width;
700
- }
701
- // Listen for change events
702
- nav.addEventListener('change', (e) => this.handleNavigationChange(e));
703
- // Store reference
704
- this._navigation = nav;
705
- return nav;
706
- }
707
- /**
708
- * Create month display element
709
- */
710
- createMonthDisplay() {
711
- const month = document.createElement('ty-calendar-month');
712
- // Set properties
713
- month.displayMonth = this._state.displayMonth;
714
- month.displayYear = this._state.displayYear;
715
- month.locale = this.locale;
716
- month.size = this._size;
717
- // Only set width if explicitly provided
718
- if (this._width) {
719
- month.width = this._width;
720
- }
721
- // Set selection value if exists
722
- const { selectedYear, selectedMonth, selectedDay } = this._state;
723
- if (selectedYear && selectedMonth && selectedDay) {
724
- const date = new Date(selectedYear, selectedMonth - 1, selectedDay);
725
- month.value = date.getTime();
726
- }
727
- // Pass render functions
728
- if (this._dayContentFn) {
729
- month.dayContentFn = this._dayContentFn;
730
- }
731
- // Pass custom CSS
732
- if (this._customCSS) {
733
- month.customCSS = this._customCSS;
734
- }
735
- // Listen for day-click events
736
- month.addEventListener('day-click', (e) => this.handleDayClick(e));
737
- // Store reference
738
- this._monthDisplay = month;
739
- return month;
740
- }
741
- /**
742
- * Main render function
743
- */
744
- render() {
745
- const root = this.shadowRoot;
746
- if (!root)
747
- return;
748
- // Ensure styles are loaded
749
- ensureStyles(root, { css: calendarStyles, id: 'ty-calendar' });
750
- // Clear and rebuild
751
- root.innerHTML = '';
752
- // Create main container
753
- const container = document.createElement('div');
754
- container.className = 'calendar-container';
755
- // Add navigation if requested
756
- if (this._showNavigation) {
757
- const nav = this.createNavigation();
758
- container.appendChild(nav);
759
- }
760
- // Add month display
761
- const month = this.createMonthDisplay();
762
- container.appendChild(month);
763
- root.appendChild(container);
764
- }
765
- }
766
- /**
767
- * Form-associated custom element
768
- */
39
+ static get observedAttributes() {
40
+ return ['value', 'year', 'month', 'day', 'hide-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor', 'required'];
41
+ }
42
+ constructor() {
43
+ super();
44
+ this._hideNavigation = false;
45
+ this._stateless = false;
46
+ this._size = 'md';
47
+ this._flavor = 'primary';
48
+ this._view = 'days';
49
+ this._dayGridHeight = 0;
50
+ this._initialValue = '';
51
+ this._initialized = false;
52
+ this._valueSets = 0;
53
+ this._pressing = false;
54
+ const current = getCurrentDate();
55
+ this._state = {
56
+ displayYear: current.year,
57
+ displayMonth: current.month,
58
+ };
59
+ this.attachShadow({ mode: 'open', delegatesFocus: true });
60
+ liftProperties(this);
61
+ if ('attachInternals' in this) {
62
+ this._internals = this.attachInternals();
63
+ this._validity = new ValidityController(this, this._internals);
64
+ }
65
+ }
66
+ connectedCallback() {
67
+ if (!this._initialized) {
68
+ this.initializeFromAttributes();
69
+ this._initialized = true;
70
+ }
71
+ upgradeProperties(this);
72
+ this.render();
73
+ this.updateFormValue();
74
+ this._localeObserver = observeLocaleChanges(this, () => {
75
+ this.render();
76
+ });
77
+ }
78
+ disconnectedCallback() {
79
+ if (this._localeObserver) {
80
+ this._localeObserver();
81
+ this._localeObserver = undefined;
82
+ }
83
+ this._navigation = undefined;
84
+ this._monthDisplay = undefined;
85
+ this._monthGrid = undefined;
86
+ this._container = undefined;
87
+ this._view = 'days';
88
+ }
89
+ attributeChangedCallback(name, oldValue, newValue) {
90
+ if (oldValue === newValue)
91
+ return;
92
+ switch (name) {
93
+ case 'value':
94
+ this.value = newValue || '';
95
+ break;
96
+ case 'year':
97
+ case 'month':
98
+ case 'day':
99
+ this.syncStateFromAttributes();
100
+ this.syncChildComponents();
101
+ this.updateFormValue();
102
+ break;
103
+ case 'hide-navigation':
104
+ this._hideNavigation = newValue !== null;
105
+ this.render();
106
+ break;
107
+ case 'stateless':
108
+ this._stateless = newValue !== null && newValue !== 'false';
109
+ break;
110
+ case 'locale':
111
+ this.syncChildComponents();
112
+ break;
113
+ case 'size':
114
+ if (newValue === 'sm' || newValue === 'md' || newValue === 'lg') {
115
+ this._size = newValue;
116
+ this._width = undefined;
117
+ this.removeAttribute('width');
118
+ this.syncChildComponents();
119
+ }
120
+ break;
121
+ case 'width':
122
+ this._width = newValue || undefined;
123
+ if (newValue) {
124
+ this._size = 'md';
125
+ this.removeAttribute('size');
126
+ }
127
+ this.syncChildComponents();
128
+ break;
129
+ case 'name':
130
+ this.updateFormValue();
131
+ break;
132
+ case 'min':
133
+ case 'max':
134
+ this[name === 'min' ? '_min' : '_max'] = newValue || undefined;
135
+ this.syncChildComponents();
136
+ this.updateValidity();
137
+ break;
138
+ case 'required':
139
+ this.updateValidity();
140
+ break;
141
+ case 'flavor':
142
+ this._flavor = newValue || 'primary';
143
+ this.syncChildComponents();
144
+ break;
145
+ }
146
+ }
147
+ get min() {
148
+ return this._min;
149
+ }
150
+ set min(value) {
151
+ if (value)
152
+ this.setAttribute('min', value);
153
+ else
154
+ this.removeAttribute('min');
155
+ }
156
+ get max() {
157
+ return this._max;
158
+ }
159
+ set max(value) {
160
+ if (value)
161
+ this.setAttribute('max', value);
162
+ else
163
+ this.removeAttribute('max');
164
+ }
165
+ get flavor() {
166
+ return this._flavor;
167
+ }
168
+ set flavor(value) {
169
+ if (value)
170
+ this.setAttribute('flavor', value);
171
+ else
172
+ this.removeAttribute('flavor');
173
+ }
174
+ get required() {
175
+ return this.hasAttribute('required');
176
+ }
177
+ set required(value) {
178
+ this.toggleAttribute('required', !!value);
179
+ }
180
+ get year() {
181
+ return this._state.selectedYear;
182
+ }
183
+ set year(value) {
184
+ if (value !== undefined) {
185
+ if (this._stateless) {
186
+ this._state.displayYear = value;
187
+ this.setAttribute('year', formatYear(value));
188
+ }
189
+ else {
190
+ this._state.selectedYear = value;
191
+ this._state.displayYear = value;
192
+ this.setAttribute('year', formatYear(value));
193
+ }
194
+ }
195
+ else {
196
+ if (!this._stateless) {
197
+ delete this._state.selectedYear;
198
+ }
199
+ this.removeAttribute('year');
200
+ }
201
+ this.syncChildComponents();
202
+ if (!this._stateless) {
203
+ this.updateFormValue();
204
+ }
205
+ }
206
+ get month() {
207
+ return this._state.selectedMonth;
208
+ }
209
+ set month(value) {
210
+ if (value !== undefined) {
211
+ if (this._stateless) {
212
+ this._state.displayMonth = value;
213
+ this.setAttribute('month', value.toString());
214
+ }
215
+ else {
216
+ this._state.selectedMonth = value;
217
+ this._state.displayMonth = value;
218
+ this.setAttribute('month', value.toString());
219
+ }
220
+ }
221
+ else {
222
+ if (!this._stateless) {
223
+ delete this._state.selectedMonth;
224
+ }
225
+ this.removeAttribute('month');
226
+ }
227
+ this.syncChildComponents();
228
+ if (!this._stateless) {
229
+ this.updateFormValue();
230
+ }
231
+ }
232
+ get day() {
233
+ return this._state.selectedDay;
234
+ }
235
+ set day(value) {
236
+ if (value !== undefined) {
237
+ this._state.selectedDay = value;
238
+ this.setAttribute('day', value.toString());
239
+ }
240
+ else {
241
+ delete this._state.selectedDay;
242
+ this.removeAttribute('day');
243
+ }
244
+ this.syncChildComponents();
245
+ this.updateFormValue();
246
+ }
247
+ get locale() {
248
+ return getEffectiveLocale(this, this.getAttribute('locale'));
249
+ }
250
+ set locale(value) {
251
+ this.setAttribute('locale', value);
252
+ }
253
+ get hideNavigation() {
254
+ return this._hideNavigation;
255
+ }
256
+ set hideNavigation(value) {
257
+ this._hideNavigation = value;
258
+ if (value)
259
+ this.setAttribute('hide-navigation', '');
260
+ else
261
+ this.removeAttribute('hide-navigation');
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 formatISODay(selectedYear, selectedMonth, selectedDay);
322
+ }
323
+ return '';
324
+ }
325
+ set value(isoDate) {
326
+ const set = ++this._valueSets;
327
+ const superseded = () => set !== this._valueSets;
328
+ if (isoDate === null || isoDate === undefined || isoDate === '') {
329
+ delete this._state.selectedYear;
330
+ delete this._state.selectedMonth;
331
+ delete this._state.selectedDay;
332
+ if (!this._stateless) {
333
+ this.removeAttribute('year');
334
+ if (superseded())
335
+ return;
336
+ this.removeAttribute('month');
337
+ if (superseded())
338
+ return;
339
+ this.removeAttribute('day');
340
+ }
341
+ }
342
+ else {
343
+ const parsed = parseDateDay(isoDate);
344
+ if (parsed) {
345
+ const { year, month, day } = parsed;
346
+ this._state.selectedYear = year;
347
+ this._state.selectedMonth = month;
348
+ this._state.selectedDay = day;
349
+ this._state.displayYear = year;
350
+ this._state.displayMonth = month;
351
+ if (!this._stateless) {
352
+ this.setAttribute('year', formatYear(year));
353
+ if (superseded())
354
+ return;
355
+ this.setAttribute('month', month.toString());
356
+ if (superseded())
357
+ return;
358
+ this.setAttribute('day', day.toString());
359
+ }
360
+ }
361
+ }
362
+ this.syncChildComponents();
363
+ if (!this._stateless) {
364
+ this.updateFormValue();
365
+ }
366
+ }
367
+ initializeFromAttributes() {
368
+ const yearStr = this.getAttribute('year');
369
+ const monthStr = this.getAttribute('month');
370
+ const dayStr = this.getAttribute('day');
371
+ const hideNav = this.hasAttribute('hide-navigation');
372
+ const statelessStr = this.getAttribute('stateless');
373
+ const sizeStr = this.getAttribute('size');
374
+ const widthStr = this.getAttribute('width');
375
+ this._min = this.getAttribute('min') || undefined;
376
+ this._max = this.getAttribute('max') || undefined;
377
+ const year = parseYear(yearStr);
378
+ if (year) {
379
+ this._state.displayYear = year;
380
+ }
381
+ const month = parseMonth(monthStr);
382
+ if (month) {
383
+ this._state.displayMonth = month;
384
+ }
385
+ if (year && month) {
386
+ const day = parseDay(dayStr, year, month);
387
+ if (day) {
388
+ this._state.selectedYear = year;
389
+ this._state.selectedMonth = month;
390
+ this._state.selectedDay = day;
391
+ }
392
+ }
393
+ this._hideNavigation = hideNav;
394
+ if (statelessStr !== null) {
395
+ this._stateless = statelessStr !== 'false';
396
+ }
397
+ if (sizeStr && (sizeStr === 'sm' || sizeStr === 'md' || sizeStr === 'lg')) {
398
+ this._size = sizeStr;
399
+ }
400
+ if (widthStr) {
401
+ this._width = widthStr;
402
+ }
403
+ this._initialValue = this.value;
404
+ }
405
+ formResetCallback() {
406
+ this.value = this._initialValue;
407
+ }
408
+ syncStateFromAttributes() {
409
+ const yearStr = this.getAttribute('year');
410
+ const monthStr = this.getAttribute('month');
411
+ const dayStr = this.getAttribute('day');
412
+ const year = parseYear(yearStr);
413
+ const month = parseMonth(monthStr);
414
+ if (year)
415
+ this._state.displayYear = year;
416
+ if (month)
417
+ this._state.displayMonth = month;
418
+ if (year && month) {
419
+ const day = parseDay(dayStr, year, month);
420
+ if (day) {
421
+ this._state.selectedYear = year;
422
+ this._state.selectedMonth = month;
423
+ this._state.selectedDay = day;
424
+ }
425
+ else {
426
+ delete this._state.selectedYear;
427
+ delete this._state.selectedMonth;
428
+ delete this._state.selectedDay;
429
+ }
430
+ }
431
+ else {
432
+ delete this._state.selectedYear;
433
+ delete this._state.selectedMonth;
434
+ delete this._state.selectedDay;
435
+ }
436
+ }
437
+ syncChildComponents() {
438
+ if (this._navigation) {
439
+ this._navigation.displayMonth = this._state.displayMonth;
440
+ this._navigation.displayYear = this._state.displayYear;
441
+ this._navigation.locale = this.locale;
442
+ this._navigation.size = this._size;
443
+ this._navigation.min = this._min ?? '';
444
+ this._navigation.max = this._max ?? '';
445
+ this._navigation.width = this._width;
446
+ this._navigation.view = this._view;
447
+ }
448
+ if (this._monthGrid) {
449
+ this.showBody();
450
+ }
451
+ if (this._monthDisplay) {
452
+ this._monthDisplay.displayMonth = this._state.displayMonth;
453
+ this._monthDisplay.displayYear = this._state.displayYear;
454
+ this._monthDisplay.locale = this.locale;
455
+ this._monthDisplay.size = this._size;
456
+ this._monthDisplay.min = this._min;
457
+ this._monthDisplay.max = this._max;
458
+ this._monthDisplay.flavor = this._flavor;
459
+ this._monthDisplay.width = this._width;
460
+ if (this._dayContentFn) {
461
+ this._monthDisplay.dayContentFn = this._dayContentFn;
462
+ }
463
+ if (this._customCSS) {
464
+ this._monthDisplay.customCSS = this._customCSS;
465
+ }
466
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
467
+ if (selectedYear && selectedMonth && selectedDay) {
468
+ this._monthDisplay.value = localMidnight(selectedYear, selectedMonth, selectedDay).getTime();
469
+ }
470
+ else {
471
+ this._monthDisplay.value = null;
472
+ }
473
+ }
474
+ this.updateValidity();
475
+ }
476
+ updateFormValue() {
477
+ if (this._stateless)
478
+ return;
479
+ if (!this._internals)
480
+ return;
481
+ const elementName = this.getAttribute('name');
482
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
483
+ if (elementName && selectedYear && selectedMonth && selectedDay) {
484
+ const isoDate = formatISODay(selectedYear, selectedMonth, selectedDay);
485
+ this._internals.setFormValue(isoDate);
486
+ }
487
+ else {
488
+ this._internals.setFormValue('');
489
+ }
490
+ this.updateValidity();
491
+ }
492
+ updateValidity() {
493
+ if (!this._internals)
494
+ return;
495
+ const anchor = this.gridCell() ?? undefined;
496
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
497
+ if (selectedYear && selectedMonth && selectedDay) {
498
+ const sel = utcMidnight(selectedYear, selectedMonth, selectedDay);
499
+ const min = this._min ? parseDateDay(this._min) : null;
500
+ const max = this._max ? parseDateDay(this._max) : null;
501
+ const message = () => nativeMessage('input', { type: 'date', min: toISODay(this._min) ?? undefined, max: toISODay(this._max) ?? undefined }, formatISODay(selectedYear, selectedMonth, selectedDay));
502
+ if (min && sel < utcMidnight(min.year, min.month, min.day)) {
503
+ this._validity.set({ rangeUnderflow: true }, message(), anchor);
504
+ return;
505
+ }
506
+ if (max && sel > utcMidnight(max.year, max.month, max.day)) {
507
+ this._validity.set({ rangeOverflow: true }, message(), anchor);
508
+ return;
509
+ }
510
+ }
511
+ else if (this.required) {
512
+ this._validity.set({ valueMissing: true }, nativeMessage('input', { type: 'date', required: true }), anchor);
513
+ return;
514
+ }
515
+ this._validity.set({}, undefined, anchor);
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', formatYear(year));
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
+ this.updateValidity();
591
+ }
592
+ createNavigation() {
593
+ const nav = document.createElement('ty-calendar-navigation');
594
+ nav.displayMonth = this._state.displayMonth;
595
+ nav.displayYear = this._state.displayYear;
596
+ nav.locale = this.locale;
597
+ nav.size = this._size;
598
+ nav.min = this._min ?? '';
599
+ nav.max = this._max ?? '';
600
+ if (this._width) {
601
+ nav.width = this._width;
602
+ }
603
+ nav.view = this._view;
604
+ nav.addEventListener('change', (e) => this.handleNavigationChange(e));
605
+ nav.addEventListener('view-toggle', (e) => {
606
+ this.setView(e.detail.view);
607
+ this.focusNavTitle();
608
+ });
609
+ this._navigation = nav;
610
+ return nav;
611
+ }
612
+ createMonthDisplay() {
613
+ const month = document.createElement('ty-calendar-month');
614
+ month.displayMonth = this._state.displayMonth;
615
+ month.displayYear = this._state.displayYear;
616
+ month.locale = this.locale;
617
+ month.size = this._size;
618
+ month.min = this._min;
619
+ month.max = this._max;
620
+ month.flavor = this._flavor;
621
+ if (this._width) {
622
+ month.width = this._width;
623
+ }
624
+ const { selectedYear, selectedMonth, selectedDay } = this._state;
625
+ if (selectedYear && selectedMonth && selectedDay) {
626
+ month.value = localMidnight(selectedYear, selectedMonth, selectedDay).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
+ month.shadowRoot?.addEventListener('focusin', () => this.updateValidity());
636
+ this._monthDisplay = month;
637
+ return month;
638
+ }
639
+ render() {
640
+ const root = this.shadowRoot;
641
+ if (!root)
642
+ return;
643
+ ensureStyles(root, { css: calendarStyles, id: 'ty-calendar' });
644
+ root.innerHTML = '';
645
+ this._monthGrid = undefined;
646
+ const container = document.createElement('div');
647
+ container.className = 'calendar-container';
648
+ container.tabIndex = -1;
649
+ const press = () => {
650
+ this._pressing = true;
651
+ setTimeout(() => { this._pressing = false; });
652
+ };
653
+ container.addEventListener('pointerdown', press);
654
+ container.addEventListener('mousedown', press);
655
+ container.addEventListener('focus', () => {
656
+ if (this._pressing)
657
+ return;
658
+ queueMicrotask(() => {
659
+ if (this.shadowRoot?.activeElement === container)
660
+ this.gridCell()?.focus();
661
+ });
662
+ });
663
+ container.addEventListener('keydown', (e) => this.handleKeydown(e));
664
+ container.addEventListener('focusin', () => this.updateValidity());
665
+ this._container = container;
666
+ if (!this._hideNavigation) {
667
+ const nav = this.createNavigation();
668
+ container.appendChild(nav);
669
+ }
670
+ const month = this.createMonthDisplay();
671
+ container.appendChild(month);
672
+ root.appendChild(container);
673
+ if (this._view === 'months')
674
+ this.showBody();
675
+ this.updateValidity();
676
+ }
677
+ setView(view) {
678
+ if (view === this._view)
679
+ return;
680
+ if (view === 'months' && this._monthDisplay) {
681
+ this._dayGridHeight = this._monthDisplay.getBoundingClientRect().height;
682
+ }
683
+ this._view = view;
684
+ if (this._navigation)
685
+ this._navigation.view = view;
686
+ this.showBody();
687
+ this.updateValidity();
688
+ }
689
+ showBody() {
690
+ const container = this._container;
691
+ if (!container || !this._monthDisplay)
692
+ return;
693
+ if (this._view === 'days') {
694
+ this._monthGrid?.remove();
695
+ this._monthGrid = undefined;
696
+ if (!this._monthDisplay.isConnected)
697
+ container.appendChild(this._monthDisplay);
698
+ return;
699
+ }
700
+ const grid = this.buildMonthGrid();
701
+ if (this._monthGrid)
702
+ this._monthGrid.replaceWith(grid);
703
+ else {
704
+ this._monthDisplay.remove();
705
+ container.appendChild(grid);
706
+ }
707
+ this._monthGrid = grid;
708
+ }
709
+ static monthIndex(year, month) {
710
+ return year * 12 + (month - 1);
711
+ }
712
+ boundIndices() {
713
+ const min = this._min ? parseDateDay(this._min) : null;
714
+ const max = this._max ? parseDateDay(this._max) : null;
715
+ return {
716
+ minIdx: min ? TyCalendar.monthIndex(min.year, min.month) : null,
717
+ maxIdx: max ? TyCalendar.monthIndex(max.year, max.month) : null,
718
+ };
719
+ }
720
+ buildMonthGrid() {
721
+ const { displayYear, displayMonth, selectedYear, selectedMonth } = this._state;
722
+ const today = getCurrentDate();
723
+ const { minIdx, maxIdx } = this.boundIndices();
724
+ const grid = document.createElement('div');
725
+ grid.className = `month-grid size-${this._size}`;
726
+ grid.setAttribute('role', 'grid');
727
+ grid.setAttribute('aria-label', String(displayYear));
728
+ if (this._dayGridHeight)
729
+ grid.style.minHeight = `${this._dayGridHeight}px`;
730
+ if (this._width)
731
+ grid.style.setProperty('--calendar-width', this._width);
732
+ for (let month = 1; month <= 12; month++) {
733
+ const idx = TyCalendar.monthIndex(displayYear, month);
734
+ const disabled = (minIdx !== null && idx < minIdx) || (maxIdx !== null && idx > maxIdx);
735
+ const selected = selectedYear === displayYear && selectedMonth === month;
736
+ const cell = document.createElement('button');
737
+ cell.type = 'button';
738
+ cell.className = 'month-cell';
739
+ cell.setAttribute('role', 'gridcell');
740
+ cell.setAttribute('aria-selected', String(selected));
741
+ cell.setAttribute('aria-label', `${getMonthName(month, this.locale, 'long')} ${displayYear}`);
742
+ cell.dataset.month = String(month);
743
+ cell.tabIndex = month === displayMonth ? 0 : -1;
744
+ cell.disabled = disabled;
745
+ if (selected)
746
+ cell.classList.add('selected');
747
+ if (today.year === displayYear && today.month === month)
748
+ cell.classList.add('current');
749
+ cell.textContent = getMonthName(month, this.locale, 'short');
750
+ cell.addEventListener('click', () => this.pickMonth(month));
751
+ grid.appendChild(cell);
752
+ }
753
+ grid.addEventListener('keydown', (e) => {
754
+ const delta = e.key === 'ArrowLeft' ? -1 :
755
+ e.key === 'ArrowRight' ? 1 :
756
+ e.key === 'ArrowUp' ? -3 :
757
+ e.key === 'ArrowDown' ? 3 :
758
+ 0;
759
+ if (!delta)
760
+ return;
761
+ const cells = Array.from(grid.querySelectorAll('.month-cell'));
762
+ const current = cells.findIndex(c => c === this.shadowRoot.activeElement);
763
+ const next = cells[(current === -1 ? displayMonth - 1 : current) + delta];
764
+ if (!next || next.disabled)
765
+ return;
766
+ e.preventDefault();
767
+ cells.forEach(c => (c.tabIndex = -1));
768
+ next.tabIndex = 0;
769
+ next.focus();
770
+ });
771
+ return grid;
772
+ }
773
+ pickMonth(month) {
774
+ this.setView('days');
775
+ this.goTo(month, this._state.displayYear);
776
+ this.focusDayGrid();
777
+ }
778
+ handleKeydown(e) {
779
+ if (e.target === this._container && e.key.startsWith('Arrow')) {
780
+ e.preventDefault();
781
+ this.gridCell()?.focus();
782
+ return;
783
+ }
784
+ if (e.key === 'Escape' && this._view === 'months') {
785
+ e.preventDefault();
786
+ e.stopPropagation();
787
+ this.setView('days');
788
+ this.focusNavTitle();
789
+ return;
790
+ }
791
+ if (e.key !== 'PageUp' && e.key !== 'PageDown')
792
+ return;
793
+ e.preventDefault();
794
+ const sign = e.key === 'PageUp' ? -1 : 1;
795
+ const step = e.shiftKey || this._view === 'months' ? 12 : 1;
796
+ const current = TyCalendar.monthIndex(this._state.displayYear, this._state.displayMonth);
797
+ const { minIdx, maxIdx } = this.boundIndices();
798
+ let target = current + sign * step;
799
+ if (minIdx !== null && target < minIdx)
800
+ target = minIdx;
801
+ if (maxIdx !== null && target > maxIdx)
802
+ target = maxIdx;
803
+ if (target === current)
804
+ return;
805
+ this.goTo((target % 12) + 1, Math.floor(target / 12));
806
+ if (this._view === 'months') {
807
+ const cell = this._monthGrid?.querySelector('.month-cell[tabindex="0"]');
808
+ cell?.focus();
809
+ }
810
+ else {
811
+ this.focusDayGrid();
812
+ }
813
+ }
814
+ focusNavTitle() {
815
+ requestAnimationFrame(() => {
816
+ this._navigation?.shadowRoot?.querySelector('.nav-title')?.focus();
817
+ });
818
+ }
819
+ gridCell() {
820
+ if (this._view === 'months') {
821
+ return this._monthGrid?.querySelector('.month-cell[tabindex="0"]:not(:disabled)')
822
+ ?? this._monthGrid?.querySelector('.month-cell:not(:disabled)')
823
+ ?? this._navigation?.shadowRoot?.querySelector('.nav-title')
824
+ ?? null;
825
+ }
826
+ const root = this._monthDisplay?.shadowRoot;
827
+ return root?.querySelector('.calendar-day-cell[tabindex="0"]')
828
+ ?? root?.querySelector('.calendar-day-cell.selected')
829
+ ?? root?.querySelector('.calendar-day-cell')
830
+ ?? null;
831
+ }
832
+ focus(options) {
833
+ const cell = this.gridCell();
834
+ if (cell)
835
+ cell.focus(options);
836
+ else
837
+ super.focus(options);
838
+ }
839
+ focusDayGrid() {
840
+ requestAnimationFrame(() => {
841
+ const cell = this._monthDisplay?.shadowRoot?.querySelector('.calendar-day-cell[tabindex="0"]');
842
+ cell?.focus();
843
+ });
844
+ }
845
+ }
769
846
  TyCalendar.formAssociated = true;
770
- // Register the custom element
771
847
  if (!customElements.get('ty-calendar')) {
772
- customElements.define('ty-calendar', TyCalendar);
848
+ customElements.define('ty-calendar', TyCalendar);
773
849
  }
774
- //# sourceMappingURL=calendar.js.map