@zealakit/chrono-react 0.0.0-stage → 1.0.0-beta.1

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 (355) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +624 -2
  3. package/dist/calendar/components.d.ts +346 -0
  4. package/dist/calendar/components.js +245 -0
  5. package/dist/calendar/context.d.ts +636 -0
  6. package/dist/calendar/context.js +21 -0
  7. package/dist/calendar/index.d.ts +6 -0
  8. package/dist/calendar/index.js +6 -0
  9. package/dist/calendar/mini-calendar.d.ts +60 -0
  10. package/dist/calendar/mini-calendar.js +50 -0
  11. package/dist/calendar/options.d.ts +4 -0
  12. package/dist/calendar/options.js +98 -0
  13. package/dist/calendar/use-calendar.d.ts +340 -0
  14. package/dist/calendar/use-calendar.js +156 -0
  15. package/dist/calendar/use-mini-calendar.d.ts +302 -0
  16. package/dist/calendar/use-mini-calendar.js +56 -0
  17. package/dist/calendar/utilities.d.ts +9 -0
  18. package/dist/calendar/utilities.js +8 -0
  19. package/dist/date/bind-panel.d.ts +30 -0
  20. package/dist/date/bind-panel.js +125 -0
  21. package/dist/date/components.d.ts +197 -0
  22. package/dist/date/components.js +202 -0
  23. package/dist/date/context.d.ts +34 -0
  24. package/dist/date/context.js +19 -0
  25. package/dist/date/index.d.ts +4 -0
  26. package/dist/date/index.js +4 -0
  27. package/dist/date/options.d.ts +7 -0
  28. package/dist/date/options.js +91 -0
  29. package/dist/date/use-date-input.d.ts +43 -0
  30. package/dist/date/use-date-input.js +138 -0
  31. package/dist/date/use-date-panel.d.ts +81 -0
  32. package/dist/date/use-date-panel.js +21 -0
  33. package/dist/date/utilities.d.ts +4 -0
  34. package/dist/date/utilities.js +4 -0
  35. package/dist/datetime/components.d.ts +121 -0
  36. package/dist/datetime/components.js +169 -0
  37. package/dist/datetime/context.d.ts +8 -0
  38. package/dist/datetime/context.js +18 -0
  39. package/dist/datetime/index.d.ts +4 -0
  40. package/dist/datetime/index.js +4 -0
  41. package/dist/datetime/options.d.ts +5 -0
  42. package/dist/datetime/options.js +99 -0
  43. package/dist/datetime/use-datetime-input.d.ts +44 -0
  44. package/dist/datetime/use-datetime-input.js +145 -0
  45. package/dist/datetime/use-datetime-panel.d.ts +128 -0
  46. package/dist/datetime/use-datetime-panel.js +60 -0
  47. package/dist/datetime/utilities.d.ts +4 -0
  48. package/dist/datetime/utilities.js +4 -0
  49. package/dist/index.d.ts +4 -0
  50. package/dist/index.js +4 -0
  51. package/dist/shared/merge-props.d.ts +9 -0
  52. package/dist/shared/merge-props.js +33 -0
  53. package/dist/shared/modifiers.d.ts +7 -0
  54. package/dist/shared/modifiers.js +6 -0
  55. package/dist/shared/part.d.ts +10 -0
  56. package/dist/shared/part.js +9 -0
  57. package/dist/shared/slot.d.ts +12 -0
  58. package/dist/shared/slot.js +60 -0
  59. package/dist/shared/style-properties.d.ts +8 -0
  60. package/dist/shared/style-properties.js +13 -0
  61. package/dist/shared/to-react-props.d.ts +11 -0
  62. package/dist/shared/to-react-props.js +27 -0
  63. package/dist/time/bind-panel.d.ts +19 -0
  64. package/dist/time/bind-panel.js +97 -0
  65. package/dist/time/components.d.ts +183 -0
  66. package/dist/time/components.js +174 -0
  67. package/dist/time/context.d.ts +24 -0
  68. package/dist/time/context.js +19 -0
  69. package/dist/time/index.d.ts +4 -0
  70. package/dist/time/index.js +4 -0
  71. package/dist/time/options.d.ts +5 -0
  72. package/dist/time/options.js +85 -0
  73. package/dist/time/use-time-input.d.ts +43 -0
  74. package/dist/time/use-time-input.js +138 -0
  75. package/dist/time/use-time-panel.d.ts +37 -0
  76. package/dist/time/use-time-panel.js +18 -0
  77. package/dist/time/utilities.d.ts +4 -0
  78. package/dist/time/utilities.js +4 -0
  79. package/dist/vendor/core/calendar/availability.d.ts +39 -0
  80. package/dist/vendor/core/calendar/availability.js +74 -0
  81. package/dist/vendor/core/calendar/controllers/calendar-controller.d.ts +251 -0
  82. package/dist/vendor/core/calendar/controllers/calendar-controller.js +1448 -0
  83. package/dist/vendor/core/calendar/controllers/drag-engine.d.ts +99 -0
  84. package/dist/vendor/core/calendar/controllers/drag-engine.js +382 -0
  85. package/dist/vendor/core/calendar/controllers/mini-calendar-controller.d.ts +66 -0
  86. package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +170 -0
  87. package/dist/vendor/core/calendar/controllers/shared.d.ts +29 -0
  88. package/dist/vendor/core/calendar/controllers/shared.js +82 -0
  89. package/dist/vendor/core/calendar/events/agenda-layout.d.ts +21 -0
  90. package/dist/vendor/core/calendar/events/agenda-layout.js +71 -0
  91. package/dist/vendor/core/calendar/events/all-day-row.d.ts +22 -0
  92. package/dist/vendor/core/calendar/events/all-day-row.js +93 -0
  93. package/dist/vendor/core/calendar/events/background-layout.d.ts +66 -0
  94. package/dist/vendor/core/calendar/events/background-layout.js +107 -0
  95. package/dist/vendor/core/calendar/events/index.d.ts +17 -0
  96. package/dist/vendor/core/calendar/events/index.js +8 -0
  97. package/dist/vendor/core/calendar/events/month-layout.d.ts +13 -0
  98. package/dist/vendor/core/calendar/events/month-layout.js +156 -0
  99. package/dist/vendor/core/calendar/events/normalize.d.ts +33 -0
  100. package/dist/vendor/core/calendar/events/normalize.js +159 -0
  101. package/dist/vendor/core/calendar/events/now-indicator.d.ts +18 -0
  102. package/dist/vendor/core/calendar/events/now-indicator.js +19 -0
  103. package/dist/vendor/core/calendar/events/overflow.d.ts +36 -0
  104. package/dist/vendor/core/calendar/events/overflow.js +112 -0
  105. package/dist/vendor/core/calendar/events/sort.d.ts +21 -0
  106. package/dist/vendor/core/calendar/events/sort.js +35 -0
  107. package/dist/vendor/core/calendar/events/time-grid-layout.d.ts +22 -0
  108. package/dist/vendor/core/calendar/events/time-grid-layout.js +184 -0
  109. package/dist/vendor/core/calendar/events/types.d.ts +141 -0
  110. package/dist/vendor/core/calendar/events/types.js +1 -0
  111. package/dist/vendor/core/calendar/index.d.ts +70 -0
  112. package/dist/vendor/core/calendar/index.js +37 -0
  113. package/dist/vendor/core/calendar/interaction/auto-scroll.d.ts +19 -0
  114. package/dist/vendor/core/calendar/interaction/auto-scroll.js +64 -0
  115. package/dist/vendor/core/calendar/interaction/drag-geometry.d.ts +52 -0
  116. package/dist/vendor/core/calendar/interaction/drag-geometry.js +125 -0
  117. package/dist/vendor/core/calendar/interaction/drag-keyboard.d.ts +38 -0
  118. package/dist/vendor/core/calendar/interaction/drag-keyboard.js +56 -0
  119. package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +23 -0
  120. package/dist/vendor/core/calendar/interaction/drag-pointer.js +203 -0
  121. package/dist/vendor/core/calendar/interaction/event-focus.d.ts +28 -0
  122. package/dist/vendor/core/calendar/interaction/event-focus.js +44 -0
  123. package/dist/vendor/core/calendar/interaction/hit-test.d.ts +17 -0
  124. package/dist/vendor/core/calendar/interaction/hit-test.js +26 -0
  125. package/dist/vendor/core/calendar/interaction/pending.d.ts +17 -0
  126. package/dist/vendor/core/calendar/interaction/pending.js +17 -0
  127. package/dist/vendor/core/calendar/interaction/pointer.d.ts +21 -0
  128. package/dist/vendor/core/calendar/interaction/pointer.js +119 -0
  129. package/dist/vendor/core/calendar/interaction/selection.d.ts +29 -0
  130. package/dist/vendor/core/calendar/interaction/selection.js +47 -0
  131. package/dist/vendor/core/calendar/internal/equal.d.ts +3 -0
  132. package/dist/vendor/core/calendar/internal/equal.js +43 -0
  133. package/dist/vendor/core/calendar/navigation/navigate.d.ts +33 -0
  134. package/dist/vendor/core/calendar/navigation/navigate.js +83 -0
  135. package/dist/vendor/core/calendar/navigation/range.d.ts +15 -0
  136. package/dist/vendor/core/calendar/navigation/range.js +52 -0
  137. package/dist/vendor/core/calendar/navigation/title.d.ts +12 -0
  138. package/dist/vendor/core/calendar/navigation/title.js +39 -0
  139. package/dist/vendor/core/calendar/navigation/view-definition.d.ts +39 -0
  140. package/dist/vendor/core/calendar/navigation/view-definition.js +61 -0
  141. package/dist/vendor/core/calendar/navigation/zoom.d.ts +5 -0
  142. package/dist/vendor/core/calendar/navigation/zoom.js +11 -0
  143. package/dist/vendor/core/calendar/recurrence/apply.d.ts +50 -0
  144. package/dist/vendor/core/calendar/recurrence/apply.js +207 -0
  145. package/dist/vendor/core/calendar/recurrence/expand.d.ts +27 -0
  146. package/dist/vendor/core/calendar/recurrence/expand.js +302 -0
  147. package/dist/vendor/core/calendar/recurrence/pack.d.ts +3 -0
  148. package/dist/vendor/core/calendar/recurrence/pack.js +251 -0
  149. package/dist/vendor/core/calendar/recurrence/rrule-types.d.ts +30 -0
  150. package/dist/vendor/core/calendar/recurrence/rrule-types.js +8 -0
  151. package/dist/vendor/core/calendar/recurrence/rrule.d.ts +12 -0
  152. package/dist/vendor/core/calendar/recurrence/rrule.js +288 -0
  153. package/dist/vendor/core/calendar/recurrence/series.d.ts +25 -0
  154. package/dist/vendor/core/calendar/recurrence/series.js +165 -0
  155. package/dist/vendor/core/calendar/recurrence/types.d.ts +30 -0
  156. package/dist/vendor/core/calendar/recurrence/types.js +1 -0
  157. package/dist/vendor/core/calendar/resources/keys.d.ts +2 -0
  158. package/dist/vendor/core/calendar/resources/keys.js +2 -0
  159. package/dist/vendor/core/calendar/resources/resource-time-grid.d.ts +7 -0
  160. package/dist/vendor/core/calendar/resources/resource-time-grid.js +130 -0
  161. package/dist/vendor/core/calendar/resources/timeline-axis.d.ts +10 -0
  162. package/dist/vendor/core/calendar/resources/timeline-axis.js +98 -0
  163. package/dist/vendor/core/calendar/resources/timeline-layout.d.ts +7 -0
  164. package/dist/vendor/core/calendar/resources/timeline-layout.js +111 -0
  165. package/dist/vendor/core/calendar/resources/tree.d.ts +10 -0
  166. package/dist/vendor/core/calendar/resources/tree.js +86 -0
  167. package/dist/vendor/core/calendar/resources/types.d.ts +177 -0
  168. package/dist/vendor/core/calendar/resources/types.js +1 -0
  169. package/dist/vendor/core/calendar/resources/views.d.ts +7 -0
  170. package/dist/vendor/core/calendar/resources/views.js +45 -0
  171. package/dist/vendor/core/calendar/resources/windowing.d.ts +11 -0
  172. package/dist/vendor/core/calendar/resources/windowing.js +17 -0
  173. package/dist/vendor/core/calendar/views/day.d.ts +37 -0
  174. package/dist/vendor/core/calendar/views/day.js +39 -0
  175. package/dist/vendor/core/calendar/views/list-layout.d.ts +8 -0
  176. package/dist/vendor/core/calendar/views/list-layout.js +5 -0
  177. package/dist/vendor/core/calendar/views/mini-calendar.d.ts +23 -0
  178. package/dist/vendor/core/calendar/views/mini-calendar.js +31 -0
  179. package/dist/vendor/core/calendar/views/month-layout.d.ts +30 -0
  180. package/dist/vendor/core/calendar/views/month-layout.js +63 -0
  181. package/dist/vendor/core/calendar/views/time-grid-layout.d.ts +26 -0
  182. package/dist/vendor/core/calendar/views/time-grid-layout.js +30 -0
  183. package/dist/vendor/core/date/index.d.ts +9 -0
  184. package/dist/vendor/core/date/index.js +9 -0
  185. package/dist/vendor/core/date/input/date-input-controller.d.ts +97 -0
  186. package/dist/vendor/core/date/input/date-input-controller.js +478 -0
  187. package/dist/vendor/core/date/input/date-range-input-controller.d.ts +43 -0
  188. package/dist/vendor/core/date/input/date-range-input-controller.js +189 -0
  189. package/dist/vendor/core/date/input/parse.d.ts +22 -0
  190. package/dist/vendor/core/date/input/parse.js +84 -0
  191. package/dist/vendor/core/date/input/validity.d.ts +6 -0
  192. package/dist/vendor/core/date/input/validity.js +13 -0
  193. package/dist/vendor/core/date/panel/panel-controller.d.ts +176 -0
  194. package/dist/vendor/core/date/panel/panel-controller.js +726 -0
  195. package/dist/vendor/core/date/presets.d.ts +22 -0
  196. package/dist/vendor/core/date/presets.js +104 -0
  197. package/dist/vendor/core/date/selection/multiple.d.ts +7 -0
  198. package/dist/vendor/core/date/selection/multiple.js +32 -0
  199. package/dist/vendor/core/date/selection/range.d.ts +29 -0
  200. package/dist/vendor/core/date/selection/range.js +39 -0
  201. package/dist/vendor/core/date/types.d.ts +12 -0
  202. package/dist/vendor/core/date/types.js +1 -0
  203. package/dist/vendor/core/datetime/compose.d.ts +24 -0
  204. package/dist/vendor/core/datetime/compose.js +49 -0
  205. package/dist/vendor/core/datetime/constraints.d.ts +42 -0
  206. package/dist/vendor/core/datetime/constraints.js +56 -0
  207. package/dist/vendor/core/datetime/index.d.ts +9 -0
  208. package/dist/vendor/core/datetime/index.js +9 -0
  209. package/dist/vendor/core/datetime/input/datetime-input-controller.d.ts +96 -0
  210. package/dist/vendor/core/datetime/input/datetime-input-controller.js +395 -0
  211. package/dist/vendor/core/datetime/input/datetime-range-input-controller.d.ts +46 -0
  212. package/dist/vendor/core/datetime/input/datetime-range-input-controller.js +182 -0
  213. package/dist/vendor/core/datetime/input/parse.d.ts +20 -0
  214. package/dist/vendor/core/datetime/input/parse.js +59 -0
  215. package/dist/vendor/core/datetime/panel/controller.d.ts +64 -0
  216. package/dist/vendor/core/datetime/panel/controller.js +197 -0
  217. package/dist/vendor/core/datetime/panel/range-controller.d.ts +71 -0
  218. package/dist/vendor/core/datetime/panel/range-controller.js +217 -0
  219. package/dist/vendor/core/datetime/types.d.ts +12 -0
  220. package/dist/vendor/core/datetime/types.js +1 -0
  221. package/dist/vendor/core/datetime/zone/day-instants.d.ts +19 -0
  222. package/dist/vendor/core/datetime/zone/day-instants.js +54 -0
  223. package/dist/vendor/core/datetime/zone/resolve.d.ts +16 -0
  224. package/dist/vendor/core/datetime/zone/resolve.js +26 -0
  225. package/dist/vendor/core/foundation/a11y/announcer.d.ts +7 -0
  226. package/dist/vendor/core/foundation/a11y/announcer.js +36 -0
  227. package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +19 -0
  228. package/dist/vendor/core/foundation/a11y/grid-navigation.js +86 -0
  229. package/dist/vendor/core/foundation/a11y/index.d.ts +8 -0
  230. package/dist/vendor/core/foundation/a11y/index.js +5 -0
  231. package/dist/vendor/core/foundation/a11y/labels.d.ts +21 -0
  232. package/dist/vendor/core/foundation/a11y/labels.js +43 -0
  233. package/dist/vendor/core/foundation/a11y/messages.d.ts +80 -0
  234. package/dist/vendor/core/foundation/a11y/messages.js +74 -0
  235. package/dist/vendor/core/foundation/a11y/roving-focus.d.ts +18 -0
  236. package/dist/vendor/core/foundation/a11y/roving-focus.js +52 -0
  237. package/dist/vendor/core/foundation/constraints/availability-rules.d.ts +52 -0
  238. package/dist/vendor/core/foundation/constraints/availability-rules.js +66 -0
  239. package/dist/vendor/core/foundation/constraints/availability.d.ts +93 -0
  240. package/dist/vendor/core/foundation/constraints/availability.js +490 -0
  241. package/dist/vendor/core/foundation/constraints/date.d.ts +21 -0
  242. package/dist/vendor/core/foundation/constraints/date.js +41 -0
  243. package/dist/vendor/core/foundation/constraints/index.d.ts +9 -0
  244. package/dist/vendor/core/foundation/constraints/index.js +4 -0
  245. package/dist/vendor/core/foundation/constraints/range.d.ts +44 -0
  246. package/dist/vendor/core/foundation/constraints/range.js +70 -0
  247. package/dist/vendor/core/foundation/constraints/time.d.ts +30 -0
  248. package/dist/vendor/core/foundation/constraints/time.js +56 -0
  249. package/dist/vendor/core/foundation/grid/index.d.ts +8 -0
  250. package/dist/vendor/core/foundation/grid/index.js +4 -0
  251. package/dist/vendor/core/foundation/grid/month-grid.d.ts +33 -0
  252. package/dist/vendor/core/foundation/grid/month-grid.js +52 -0
  253. package/dist/vendor/core/foundation/grid/time-axis.d.ts +25 -0
  254. package/dist/vendor/core/foundation/grid/time-axis.js +32 -0
  255. package/dist/vendor/core/foundation/grid/weekday-headers.d.ts +17 -0
  256. package/dist/vendor/core/foundation/grid/weekday-headers.js +26 -0
  257. package/dist/vendor/core/foundation/grid/year-grid.d.ts +29 -0
  258. package/dist/vendor/core/foundation/grid/year-grid.js +40 -0
  259. package/dist/vendor/core/foundation/index.d.ts +8 -0
  260. package/dist/vendor/core/foundation/index.js +8 -0
  261. package/dist/vendor/core/foundation/input/form.d.ts +7 -0
  262. package/dist/vendor/core/foundation/input/form.js +10 -0
  263. package/dist/vendor/core/foundation/input/index.d.ts +6 -0
  264. package/dist/vendor/core/foundation/input/index.js +3 -0
  265. package/dist/vendor/core/foundation/input/segment-engine.d.ts +33 -0
  266. package/dist/vendor/core/foundation/input/segment-engine.js +49 -0
  267. package/dist/vendor/core/foundation/input/tokenize.d.ts +19 -0
  268. package/dist/vendor/core/foundation/input/tokenize.js +24 -0
  269. package/dist/vendor/core/foundation/locale/digits.d.ts +6 -0
  270. package/dist/vendor/core/foundation/locale/digits.js +35 -0
  271. package/dist/vendor/core/foundation/locale/direction.d.ts +1 -0
  272. package/dist/vendor/core/foundation/locale/direction.js +37 -0
  273. package/dist/vendor/core/foundation/locale/format.d.ts +31 -0
  274. package/dist/vendor/core/foundation/locale/format.js +79 -0
  275. package/dist/vendor/core/foundation/locale/hour-cycle.d.ts +12 -0
  276. package/dist/vendor/core/foundation/locale/hour-cycle.js +45 -0
  277. package/dist/vendor/core/foundation/locale/index.d.ts +10 -0
  278. package/dist/vendor/core/foundation/locale/index.js +8 -0
  279. package/dist/vendor/core/foundation/locale/names.d.ts +6 -0
  280. package/dist/vendor/core/foundation/locale/names.js +30 -0
  281. package/dist/vendor/core/foundation/locale/resolve.d.ts +7 -0
  282. package/dist/vendor/core/foundation/locale/resolve.js +29 -0
  283. package/dist/vendor/core/foundation/locale/week-info.d.ts +5 -0
  284. package/dist/vendor/core/foundation/locale/week-info.js +61 -0
  285. package/dist/vendor/core/foundation/locale/zone-label.d.ts +6 -0
  286. package/dist/vendor/core/foundation/locale/zone-label.js +24 -0
  287. package/dist/vendor/core/foundation/ranges/date-range.d.ts +18 -0
  288. package/dist/vendor/core/foundation/ranges/date-range.js +40 -0
  289. package/dist/vendor/core/foundation/ranges/index.d.ts +4 -0
  290. package/dist/vendor/core/foundation/ranges/index.js +2 -0
  291. package/dist/vendor/core/foundation/ranges/interval.d.ts +24 -0
  292. package/dist/vendor/core/foundation/ranges/interval.js +56 -0
  293. package/dist/vendor/core/foundation/store/attributes.d.ts +19 -0
  294. package/dist/vendor/core/foundation/store/attributes.js +43 -0
  295. package/dist/vendor/core/foundation/store/controllable.d.ts +19 -0
  296. package/dist/vendor/core/foundation/store/controllable.js +50 -0
  297. package/dist/vendor/core/foundation/store/env.d.ts +1 -0
  298. package/dist/vendor/core/foundation/store/env.js +3 -0
  299. package/dist/vendor/core/foundation/store/global-state.d.ts +1 -0
  300. package/dist/vendor/core/foundation/store/global-state.js +21 -0
  301. package/dist/vendor/core/foundation/store/ids.d.ts +2 -0
  302. package/dist/vendor/core/foundation/store/ids.js +7 -0
  303. package/dist/vendor/core/foundation/store/index.d.ts +11 -0
  304. package/dist/vendor/core/foundation/store/index.js +7 -0
  305. package/dist/vendor/core/foundation/store/store.d.ts +7 -0
  306. package/dist/vendor/core/foundation/store/store.js +25 -0
  307. package/dist/vendor/core/foundation/store/ticker.d.ts +11 -0
  308. package/dist/vendor/core/foundation/store/ticker.js +27 -0
  309. package/dist/vendor/core/foundation/values/clock.d.ts +4 -0
  310. package/dist/vendor/core/foundation/values/clock.js +21 -0
  311. package/dist/vendor/core/foundation/values/compare.d.ts +16 -0
  312. package/dist/vendor/core/foundation/values/compare.js +70 -0
  313. package/dist/vendor/core/foundation/values/convert.d.ts +31 -0
  314. package/dist/vendor/core/foundation/values/convert.js +112 -0
  315. package/dist/vendor/core/foundation/values/epoch-day.d.ts +15 -0
  316. package/dist/vendor/core/foundation/values/epoch-day.js +47 -0
  317. package/dist/vendor/core/foundation/values/index.d.ts +14 -0
  318. package/dist/vendor/core/foundation/values/index.js +10 -0
  319. package/dist/vendor/core/foundation/values/iso.d.ts +24 -0
  320. package/dist/vendor/core/foundation/values/iso.js +113 -0
  321. package/dist/vendor/core/foundation/values/plain-date-time.d.ts +8 -0
  322. package/dist/vendor/core/foundation/values/plain-date-time.js +25 -0
  323. package/dist/vendor/core/foundation/values/plain-date.d.ts +33 -0
  324. package/dist/vendor/core/foundation/values/plain-date.js +105 -0
  325. package/dist/vendor/core/foundation/values/plain-time.d.ts +15 -0
  326. package/dist/vendor/core/foundation/values/plain-time.js +45 -0
  327. package/dist/vendor/core/foundation/values/types.d.ts +37 -0
  328. package/dist/vendor/core/foundation/values/types.js +1 -0
  329. package/dist/vendor/core/foundation/values/week.d.ts +9 -0
  330. package/dist/vendor/core/foundation/values/week.js +31 -0
  331. package/dist/vendor/core/foundation/values/year-month.d.ts +10 -0
  332. package/dist/vendor/core/foundation/values/year-month.js +19 -0
  333. package/dist/vendor/core/foundation/values/zoned.d.ts +16 -0
  334. package/dist/vendor/core/foundation/values/zoned.js +155 -0
  335. package/dist/vendor/core/index.d.ts +5 -0
  336. package/dist/vendor/core/index.js +5 -0
  337. package/dist/vendor/core/time/index.d.ts +8 -0
  338. package/dist/vendor/core/time/index.js +8 -0
  339. package/dist/vendor/core/time/input/parse.d.ts +19 -0
  340. package/dist/vendor/core/time/input/parse.js +84 -0
  341. package/dist/vendor/core/time/input/time-input-controller.d.ts +102 -0
  342. package/dist/vendor/core/time/input/time-input-controller.js +562 -0
  343. package/dist/vendor/core/time/input/time-range-input-controller.d.ts +49 -0
  344. package/dist/vendor/core/time/input/time-range-input-controller.js +185 -0
  345. package/dist/vendor/core/time/input/validity.d.ts +7 -0
  346. package/dist/vendor/core/time/input/validity.js +16 -0
  347. package/dist/vendor/core/time/panel/time-panel-controller.d.ts +163 -0
  348. package/dist/vendor/core/time/panel/time-panel-controller.js +839 -0
  349. package/dist/vendor/core/time/selection/range.d.ts +25 -0
  350. package/dist/vendor/core/time/selection/range.js +35 -0
  351. package/dist/vendor/core/time/selection/slots.d.ts +46 -0
  352. package/dist/vendor/core/time/selection/slots.js +78 -0
  353. package/dist/vendor/core/time/types.d.ts +11 -0
  354. package/dist/vendor/core/time/types.js +1 -0
  355. package/package.json +90 -4
@@ -0,0 +1,1448 @@
1
+ import { compileAvailability, addDays, announce, createControllable, createTicker, dayOfWeek, defaultMessages, formatMessage, fromEpochDay, fromSecondOfDay, getTextDirection, getWeekInfo, isDateInRange, isSameDay, mergeMessages, nowZoned, parseCellKey, plainDateTime, plainDate, resolveLocale, toIsoString, toPlainDate, toPlainDateTime, toPlainTime, toSecondOfDay, today as readToday, } from "../../foundation/index.js";
2
+ import { resolveCalendarAvailability, } from "../availability.js";
3
+ import { backgroundAttributes, layoutBackgrounds, layoutTimelineBackgrounds, } from "../events/background-layout.js";
4
+ import { statesEqual } from "../internal/equal.js";
5
+ import { canNavigate, firstVisibleDay, getDefinition, getHiddenDays, navigate, } from "../navigation/navigate.js";
6
+ import { getRange, getVisibleRange } from "../navigation/range.js";
7
+ import { getCalendarTitle } from "../navigation/title.js";
8
+ import { resolveViews, } from "../navigation/view-definition.js";
9
+ import { isOutside } from "../views/day.js";
10
+ import { getListLayout } from "../views/list-layout.js";
11
+ import { getMonthLayout, } from "../views/month-layout.js";
12
+ import { getTimeGridLayout, } from "../views/time-grid-layout.js";
13
+ import { applyEventLimit, layoutAgenda, layoutAllDayRow, layoutMonthEvents, layoutTimeGridEvents, normalizeEvents, wallSecondsOf, } from "../events/index.js";
14
+ import { getNowIndicator } from "../events/now-indicator.js";
15
+ import { computeSelection, selectionPieces, } from "../interaction/selection.js";
16
+ import { enterCell as enterInteractionCell, stepFocus, } from "../interaction/event-focus.js";
17
+ import { createSelectionPointer, } from "../interaction/pointer.js";
18
+ import { createDragPointer, } from "../interaction/drag-pointer.js";
19
+ import { warnOnce } from "../events/normalize.js";
20
+ import { zoomTarget } from "../navigation/zoom.js";
21
+ import { resourceCellKey } from "../resources/keys.js";
22
+ import { createDragEngine, } from "./drag-engine.js";
23
+ import { cellAttributes, columnHeaderAttributes, dayAttributes, isNavKey, keyOf, moveInMonthGrid, navAttributes, nextId, toHighlighter, weekNumberAttributes, } from "./shared.js";
24
+ const day1 = (month) => ({
25
+ calendar: "gregory",
26
+ year: month.year,
27
+ month: month.month,
28
+ day: 1,
29
+ });
30
+ const isCalendarDay = (value) => "date" in value;
31
+ export function createCalendarController(initial = {}) {
32
+ const { lazyStart, ...rest } = initial;
33
+ let options = rest;
34
+ const id = initial.id ?? nextId("chrono-calendar");
35
+ const titleId = `${id}-title`;
36
+ const readConfig = () => {
37
+ const locale = options.locale === undefined ? undefined : resolveLocale(options.locale);
38
+ const weekInfo = getWeekInfo(locale);
39
+ const weekStartsOn = options.weekStartsOn ?? weekInfo.firstDay;
40
+ const timeZone = options.timeZone ?? new Intl.DateTimeFormat().resolvedOptions().timeZone;
41
+ const today = readToday(timeZone, options.now);
42
+ return {
43
+ locale,
44
+ weekInfo,
45
+ weekStartsOn,
46
+ today,
47
+ timeZone,
48
+ messages: mergeMessages(defaultMessages, options.messages),
49
+ nav: {
50
+ views: resolveViews(options.views, weekInfo.weekend),
51
+ weekStartsOn,
52
+ hiddenDays: options.hiddenDays ?? [],
53
+ min: options.min === undefined
54
+ ? undefined
55
+ : toPlainDate(options.min, timeZone),
56
+ max: options.max === undefined
57
+ ? undefined
58
+ : toPlainDate(options.max, timeZone),
59
+ today,
60
+ },
61
+ };
62
+ };
63
+ let config = readConfig();
64
+ const viewControl = createControllable({
65
+ value: options.view,
66
+ defaultValue: options.defaultView ?? "month",
67
+ onChange: (view) => options.onViewChange?.(view),
68
+ });
69
+ const dateControl = createControllable({
70
+ value: options.date === undefined
71
+ ? undefined
72
+ : toPlainDate(options.date, config.timeZone),
73
+ defaultValue: options.defaultDate === undefined
74
+ ? config.today
75
+ : toPlainDate(options.defaultDate, config.timeZone),
76
+ onChange: (date) => options.onDateChange?.(date),
77
+ equals: isSameDay,
78
+ });
79
+ const selectedEventControl = createControllable({
80
+ value: options.selectedEventId === undefined
81
+ ? undefined
82
+ : options.selectedEventId,
83
+ defaultValue: options.defaultSelectedEventId ?? null,
84
+ onChange: (selected) => options.onSelectedEventChange?.(selected, eventById(selected)),
85
+ });
86
+ const collapsedControl = createControllable({
87
+ value: options.collapsedResourceIds,
88
+ defaultValue: options.defaultCollapsedResourceIds ?? [],
89
+ onChange: (ids) => options.onCollapsedResourceIdsChange?.(ids),
90
+ equals: (a, b) => a.length === b.length && a.every((id, i) => id === b[i]),
91
+ });
92
+ let custom;
93
+ let focusedDate = dateControl.get();
94
+ let started = false;
95
+ let lastRange;
96
+ let state;
97
+ let nowMs = options.now ?? Date.now();
98
+ let ticker;
99
+ let pointer;
100
+ let dragPointer;
101
+ let eventLimitOverride;
102
+ let focus;
103
+ const listeners = new Set();
104
+ // Memoization of the events pipeline (plan 05 R1): unchanged inputs reuse
105
+ // the same arrays, so the state comparer sees equal references.
106
+ let eventsCache;
107
+ const navState = () => ({
108
+ view: custom ? "custom" : viewControl.get(),
109
+ anchor: dateControl.get(),
110
+ focusedDate,
111
+ custom,
112
+ });
113
+ const normalizeFor = (source, visibleRange) => {
114
+ if (!source) {
115
+ return [];
116
+ }
117
+ return normalizeEvents(source, {
118
+ visibleRange,
119
+ timeZone: config.timeZone,
120
+ recurrence: options.recurrence,
121
+ onRecurrenceError: options.onRecurrenceError,
122
+ });
123
+ };
124
+ const eventsFor = (layout, visibleRange, now) => {
125
+ const source = options.events;
126
+ const timeGrid = options.timeGrid;
127
+ const key = [
128
+ toIsoString(visibleRange.start),
129
+ toIsoString(visibleRange.end),
130
+ config.timeZone,
131
+ layout.kind,
132
+ options.eventLimit ?? eventLimitOverride ?? "auto",
133
+ options.allDayEventLimit ?? 3,
134
+ options.minEventDuration ?? 15,
135
+ options.longEventsInAllDayRow ?? true,
136
+ timeGrid?.start ? toIsoString(toPlainTime(timeGrid.start)) : "",
137
+ timeGrid?.end ? toIsoString(toPlainTime(timeGrid.end)) : "",
138
+ config.nav.hiddenDays.join(","),
139
+ Math.floor(nowMs / 60_000),
140
+ engine.pendingSignature(),
141
+ options.recurrence === undefined ? "" : "recurrence",
142
+ ].join("|");
143
+ if (eventsCache &&
144
+ eventsCache.source === source &&
145
+ eventsCache.key === key) {
146
+ return eventsCache.result;
147
+ }
148
+ const normalized = normalizeFor(source, visibleRange).map((event) => engine.override(event));
149
+ const result = buildEvents(layout, normalized, now);
150
+ eventsCache = { source, key, result };
151
+ return result;
152
+ };
153
+ const buildEvents = (layout, normalized, now) => {
154
+ if (layout.kind === "month") {
155
+ const segments = layoutMonthEvents(normalized, layout, { now });
156
+ const limit = effectiveLimit();
157
+ const { segments: limited, more } = applyEventLimit(segments, limit, layout);
158
+ return { events: limited, more, allDayRow: [], nowIndicator: null };
159
+ }
160
+ if (layout.kind === "time-grid") {
161
+ const timeGrid = options.timeGrid;
162
+ const dayStart = timeGrid?.start === undefined ? undefined : toPlainTime(timeGrid.start);
163
+ const dayEnd = timeGrid?.end === undefined ? undefined : toPlainTime(timeGrid.end);
164
+ const { segments } = layoutAllDayRow(normalized, layout.days, {
165
+ eventLimit: options.allDayEventLimit ?? 3,
166
+ longEventsInAllDayRow: options.longEventsInAllDayRow,
167
+ now,
168
+ });
169
+ const events = layoutTimeGridEvents(normalized, layout.days, {
170
+ dayStart,
171
+ dayEnd,
172
+ minEventDuration: options.minEventDuration,
173
+ longEventsInAllDayRow: options.longEventsInAllDayRow,
174
+ now,
175
+ });
176
+ const nowIndicator = getNowIndicator(now, layout.days, {
177
+ dayStart,
178
+ dayEnd,
179
+ });
180
+ return { events, more: [], allDayRow: segments, nowIndicator };
181
+ }
182
+ const days = layoutAgenda(normalized, layout.days, { now });
183
+ return {
184
+ events: days.flatMap((day) => day.items),
185
+ more: [],
186
+ allDayRow: [],
187
+ nowIndicator: null,
188
+ };
189
+ };
190
+ /** `eventLimit: "auto"` measures after mount; before that it falls back to 3 (plan 05 §3.1). */
191
+ const effectiveLimit = () => {
192
+ if (eventLimitOverride !== undefined) {
193
+ return eventLimitOverride;
194
+ }
195
+ const limit = options.eventLimit;
196
+ if (typeof limit === "number") {
197
+ return limit;
198
+ }
199
+ return limit === "auto" ? 3 : undefined;
200
+ };
201
+ const eventById = (eventId) => {
202
+ if (eventId == null) {
203
+ return null;
204
+ }
205
+ return options.events?.find((event) => event.id === eventId) ?? null;
206
+ };
207
+ const nowDateTime = () => toPlainDateTime(nowZoned(config.timeZone, nowMs), config.timeZone);
208
+ /** The focus cell key: a day key, or a slot key in a time grid (plan 05 R3). */
209
+ const focusCellKey = (layout, date) => {
210
+ const dayKey = keyOf(date);
211
+ if (layout.kind === "time-grid" && layout.slots[0]) {
212
+ return `${dayKey}T${toIsoString(layout.slots[0].start)}`;
213
+ }
214
+ return dayKey;
215
+ };
216
+ let resourcesCache;
217
+ const resourcesFor = (definition, range, visibleRange, layout, now) => {
218
+ const collapsed = collapsedControl.get();
219
+ const timeGrid = options.timeGrid;
220
+ const key = [
221
+ definition.id,
222
+ toIsoString(range.start),
223
+ toIsoString(range.end),
224
+ config.timeZone,
225
+ config.locale ?? "",
226
+ options.resourceGrouping ?? "resource-first",
227
+ collapsed.map(String).join(","),
228
+ JSON.stringify(options.resourceWindow ?? null),
229
+ JSON.stringify(options.slotWindow ?? null),
230
+ timeGrid?.start ? toIsoString(toPlainTime(timeGrid.start)) : "",
231
+ timeGrid?.end ? toIsoString(toPlainTime(timeGrid.end)) : "",
232
+ options.minEventDuration ?? 15,
233
+ options.longEventsInAllDayRow ?? true,
234
+ config.nav.hiddenDays.join(","),
235
+ Math.floor(nowMs / 60_000),
236
+ engine.pendingSignature(),
237
+ options.recurrence === undefined ? "" : "recurrence",
238
+ ].join("|");
239
+ if (resourcesCache &&
240
+ resourcesCache.events === options.events &&
241
+ resourcesCache.resources === options.resources &&
242
+ resourcesCache.label === options.getResourceLabel &&
243
+ resourcesCache.key === key) {
244
+ return resourcesCache.result;
245
+ }
246
+ const normalized = normalizeFor(options.events, visibleRange).map((event) => engine.override(event));
247
+ if (normalized.some((event) => !event.resourceIds?.length)) {
248
+ warnOnce("[chrono] Events without a resourceId are not shown in resource views.");
249
+ }
250
+ const builder = definition.layoutBuilder;
251
+ const result = builder({
252
+ definition,
253
+ range,
254
+ days: layout.days,
255
+ locale: config.locale,
256
+ now,
257
+ events: normalized,
258
+ resources: options.resources ?? [],
259
+ collapsed,
260
+ grouping: options.resourceGrouping ?? "resource-first",
261
+ getLabel: options.getResourceLabel,
262
+ resourceWindow: options.resourceWindow,
263
+ slotWindow: options.slotWindow,
264
+ dayStart: timeGrid?.start === undefined ? undefined : toPlainTime(timeGrid.start),
265
+ dayEnd: timeGrid?.end === undefined ? undefined : toPlainTime(timeGrid.end),
266
+ minEventDuration: options.minEventDuration,
267
+ longEventsInAllDayRow: options.longEventsInAllDayRow,
268
+ });
269
+ resourcesCache = {
270
+ events: options.events,
271
+ resources: options.resources,
272
+ label: options.getResourceLabel,
273
+ key,
274
+ result,
275
+ };
276
+ return result;
277
+ };
278
+ const compute = (fix = false) => {
279
+ const nav = navState();
280
+ const definition = getDefinition(nav, config.nav);
281
+ const range = getRange(definition, nav.anchor, config.nav);
282
+ const visibleRange = getVisibleRange(definition, range, config.nav);
283
+ const hidden = getHiddenDays(definition, config.nav);
284
+ const scope = definition.layout === "month" ? visibleRange : range;
285
+ if (fix &&
286
+ (!isDateInRange(focusedDate, scope) ||
287
+ hidden.includes(dayOfWeek(focusedDate)))) {
288
+ focusedDate =
289
+ isDateInRange(nav.anchor, range) &&
290
+ !hidden.includes(dayOfWeek(nav.anchor))
291
+ ? nav.anchor
292
+ : firstVisibleDay(range, hidden);
293
+ }
294
+ const selectedDate = options.selectedDate === undefined
295
+ ? undefined
296
+ : toPlainDate(options.selectedDate, config.timeZone);
297
+ const ctx = {
298
+ definition,
299
+ range,
300
+ visibleRange,
301
+ focusedDate,
302
+ hiddenDays: hidden,
303
+ min: config.nav.min,
304
+ max: config.nav.max,
305
+ selectedDate,
306
+ isHighlighted: toHighlighter(options.highlightedDates, config.timeZone),
307
+ weekStartsOn: config.weekStartsOn,
308
+ weekInfo: config.weekInfo,
309
+ locale: config.locale,
310
+ today: config.today,
311
+ weekNumbers: options.weekNumbers ?? false,
312
+ };
313
+ // Resource layouts sit on the time-grid layout for days, slots and focus (plan 10 IG1).
314
+ const layout = definition.layout === "month"
315
+ ? getMonthLayout(ctx)
316
+ : definition.layout === "list"
317
+ ? getListLayout(ctx)
318
+ : getTimeGridLayout(ctx, options.timeGrid);
319
+ const now = nowDateTime();
320
+ const events = eventsFor(layout, visibleRange, now);
321
+ const resources = definition.layoutBuilder && layout.kind === "time-grid"
322
+ ? resourcesFor(definition, range, visibleRange, layout, now)
323
+ : null;
324
+ const currentFocus = focus ?? {
325
+ mode: "navigation",
326
+ cellKey: focusCellKey(layout, focusedDate),
327
+ };
328
+ return {
329
+ id,
330
+ view: nav.view,
331
+ definition,
332
+ date: nav.anchor,
333
+ focusedDate,
334
+ today: config.today,
335
+ range,
336
+ visibleRange,
337
+ title: getCalendarTitle(range, definition, config.locale),
338
+ layout,
339
+ canGoPrev: canNavigate(nav, -1, config.nav),
340
+ canGoNext: canNavigate(nav, 1, config.nav),
341
+ direction: getTextDirection(config.locale),
342
+ locale: config.locale,
343
+ hiddenDays: hidden,
344
+ messages: config.messages,
345
+ events: events.events,
346
+ more: events.more,
347
+ allDayRow: events.allDayRow,
348
+ nowIndicator: events.nowIndicator,
349
+ selection: selection ?? null,
350
+ selectedEventId: selectedEventControl.get(),
351
+ focus: currentFocus,
352
+ drag: engine.drag,
353
+ pending: engine.pending,
354
+ resources,
355
+ backgrounds: backgroundsFor(layout, resources, visibleRange),
356
+ };
357
+ };
358
+ const emitRange = () => {
359
+ if (!started) {
360
+ return;
361
+ }
362
+ const visible = state.visibleRange;
363
+ if (!lastRange ||
364
+ !isSameDay(lastRange.start, visible.start) ||
365
+ !isSameDay(lastRange.end, visible.end)) {
366
+ lastRange = visible;
367
+ options.onVisibleRangeChange?.(visible, { view: state.view });
368
+ }
369
+ };
370
+ const refresh = (fix = false) => {
371
+ const next = compute(fix);
372
+ if (state && statesEqual(state, next)) {
373
+ return;
374
+ }
375
+ state = next;
376
+ emitRange();
377
+ for (const listener of [...listeners]) {
378
+ listener(state);
379
+ }
380
+ };
381
+ // Selection state (E14/E15). `selection` is the active range (preview or confirmed).
382
+ let selection = null;
383
+ let selectionAnchor = null;
384
+ let selectionSource = "pointer";
385
+ // Availability (plan 11 V4, R6, R7): compile once per identity, cache the
386
+ // function form for the duration of one drag (its exclude id is constant).
387
+ let dragAvailability;
388
+ const resolveAvailability = (excludeEventId) => {
389
+ const input = options.availability;
390
+ if (input === undefined) {
391
+ return undefined;
392
+ }
393
+ const compileOptions = {
394
+ timeZone: config.timeZone,
395
+ now: options.now,
396
+ };
397
+ if (typeof input !== "function") {
398
+ return resolveCalendarAvailability(input, {}, compileOptions);
399
+ }
400
+ const key = String(excludeEventId ?? "");
401
+ if (dragAvailability?.key === key) {
402
+ return dragAvailability.value;
403
+ }
404
+ const value = resolveCalendarAvailability(input, { excludeEventId }, compileOptions);
405
+ dragAvailability = { key, value };
406
+ return value;
407
+ };
408
+ const selectionCovered = (proposal) => {
409
+ if (options.availabilityBlocksInteraction === false) {
410
+ return false;
411
+ }
412
+ const availability = resolveAvailability();
413
+ return availability
414
+ ? !availability.isRangeAvailable(proposal.start, proposal.end)
415
+ : false;
416
+ };
417
+ // Moving and resizing events (plan 09). The engine owns the drag and pending changes.
418
+ let normalizedCache;
419
+ const normalizedNow = () => {
420
+ if (!state)
421
+ return [];
422
+ const visible = state.visibleRange;
423
+ const key = `${toIsoString(visible.start)}|${toIsoString(visible.end)}|${config.timeZone}`;
424
+ if (normalizedCache &&
425
+ normalizedCache.source === options.events &&
426
+ normalizedCache.key === key) {
427
+ return normalizedCache.value;
428
+ }
429
+ const value = normalizeFor(options.events, visible);
430
+ normalizedCache = { source: options.events, key, value };
431
+ return value;
432
+ };
433
+ const dragOptions = () => {
434
+ const base = options;
435
+ if (base.availabilityBlocksInteraction === false ||
436
+ base.availability === undefined) {
437
+ return base;
438
+ }
439
+ return {
440
+ ...base,
441
+ validateEventChange: (proposal) => {
442
+ const availability = resolveAvailability(proposal.event.id);
443
+ if (availability &&
444
+ !availability.isRangeAvailable(proposal.to.start, proposal.to.end)) {
445
+ return false;
446
+ }
447
+ return base.validateEventChange?.(proposal) ?? true;
448
+ },
449
+ };
450
+ };
451
+ const engine = createDragEngine({
452
+ options: dragOptions,
453
+ layoutKind: () => (state ? state.layout.kind : "month"),
454
+ timeZone: () => config.timeZone,
455
+ locale: () => config.locale,
456
+ messages: () => config.messages,
457
+ rtl: () => getTextDirection(config.locale) === "rtl",
458
+ normalized: normalizedNow,
459
+ segmentEvent: (segmentKey) => [
460
+ ...state.events,
461
+ ...state.allDayRow,
462
+ ].find((segment) => segment.key === segmentKey)?.event,
463
+ segmentNormalized: (segmentKey) => {
464
+ let best;
465
+ for (const item of normalizedNow()) {
466
+ if ((segmentKey === item.key || segmentKey.startsWith(`${item.key}:`)) &&
467
+ (best === undefined || item.key.length > best.key.length)) {
468
+ best = item;
469
+ }
470
+ }
471
+ return best;
472
+ },
473
+ buildPreview: (event) => {
474
+ const built = buildEvents(state.layout, [event], nowDateTime());
475
+ return { events: built.events, allDayRow: built.allDayRow };
476
+ },
477
+ refresh: () => refresh(),
478
+ });
479
+ const SECONDS_PER_DAY = 86400;
480
+ // Availability on cells and slots (plan 11 V7, V12): attributes plus a label suffix.
481
+ const reasonOf = (rules) => options.getAvailabilityLabel
482
+ ? options.getAvailabilityLabel(rules)
483
+ : (rules[0]?.reason ?? "");
484
+ const dayAvailability = (date) => {
485
+ const availability = resolveAvailability();
486
+ if (!availability) {
487
+ return { status: "available", label: "" };
488
+ }
489
+ const status = availability.getDayStatus(date);
490
+ if (status !== "unavailable") {
491
+ return { status, label: "" };
492
+ }
493
+ const piece = availability
494
+ .getIntervals(date, addDays(date, 1))
495
+ .find((interval) => interval.status === "unavailable");
496
+ const reason = piece ? reasonOf(piece.rules) : "";
497
+ return {
498
+ status,
499
+ label: reason
500
+ ? `${state.messages.unavailable}: ${reason}`
501
+ : state.messages.unavailable,
502
+ };
503
+ };
504
+ const slotUnavailable = (slot, day) => {
505
+ const availability = resolveAvailability();
506
+ if (!availability) {
507
+ return false;
508
+ }
509
+ const end = slot.endSecond >= SECONDS_PER_DAY
510
+ ? plainDateTime(addDays(day.date, 1), fromSecondOfDay(0))
511
+ : plainDateTime(day.date, fromSecondOfDay(slot.endSecond));
512
+ return !availability.isRangeAvailable(plainDateTime(day.date, slot.start), end);
513
+ };
514
+ // Availability backgrounds (plan 11 V9). The array is memoized so
515
+ // `statesEqual` can compare it by reference (rule `data` is app-owned).
516
+ const EMPTY_BACKGROUNDS = [];
517
+ let backgroundsCache;
518
+ const objectIds = new WeakMap();
519
+ let objectIdCounter = 0;
520
+ const objectKey = (value) => {
521
+ if (value === null || value === undefined) {
522
+ return "";
523
+ }
524
+ if (typeof value === "object" || typeof value === "function") {
525
+ let id = objectIds.get(value);
526
+ if (id === undefined) {
527
+ id = ++objectIdCounter;
528
+ objectIds.set(value, id);
529
+ }
530
+ return String(id);
531
+ }
532
+ return String(value);
533
+ };
534
+ const wallFromSeconds = (seconds) => {
535
+ const day = Math.floor(seconds / SECONDS_PER_DAY);
536
+ return plainDateTime(fromEpochDay(day), fromSecondOfDay(seconds - day * SECONDS_PER_DAY));
537
+ };
538
+ const backgroundsFor = (layout, resources, visibleRange) => {
539
+ const mode = options.backgrounds ?? "unavailable";
540
+ if (mode === false || options.availability === undefined) {
541
+ return EMPTY_BACKGROUNDS;
542
+ }
543
+ const availability = resolveAvailability();
544
+ if (!availability) {
545
+ return EMPTY_BACKGROUNDS;
546
+ }
547
+ const availabilityOf = (resource) => {
548
+ const spec = options.getResourceAvailability?.(resource);
549
+ return spec
550
+ ? compileAvailability(spec, {
551
+ timeZone: config.timeZone,
552
+ now: options.now,
553
+ })
554
+ : availability;
555
+ };
556
+ const base = [
557
+ toIsoString(visibleRange.start),
558
+ toIsoString(visibleRange.end),
559
+ config.timeZone,
560
+ String(mode),
561
+ objectKey(options.availability),
562
+ objectKey(options.events),
563
+ objectKey(options.getResourceAvailability),
564
+ String(options.now ?? ""),
565
+ layout.kind === "time-grid"
566
+ ? `${layout.slots[0]?.startSecond ?? ""}-${layout.slots[layout.slots.length - 1]?.endSecond ?? ""}`
567
+ : "",
568
+ ].join("|");
569
+ const signature = resources
570
+ ? `${base}|${resources.kind}|${resources.kind === "timeline"
571
+ ? resources.rows.map((row) => row.key).join(",")
572
+ : resources.columns.map((column) => column.key).join(",")}`
573
+ : `${base}|${layout.kind}|${layout.kind === "time-grid"
574
+ ? layout.days.map((day) => day.key).join(",")
575
+ : ""}`;
576
+ if (backgroundsCache?.key === signature) {
577
+ return backgroundsCache.value;
578
+ }
579
+ let value = EMPTY_BACKGROUNDS;
580
+ if (resources?.kind === "timeline") {
581
+ const axis = resources.axis;
582
+ const end = wallFromSeconds(wallSecondsOf(axis.start) + axis.length);
583
+ value = resources.rows.flatMap((row) => layoutTimelineBackgrounds({
584
+ availability: availabilityOf(row.resource),
585
+ timeZone: config.timeZone,
586
+ rows: [
587
+ { key: row.key, resourceId: String(row.id), resourceKey: row.key },
588
+ ],
589
+ start: axis.start,
590
+ end,
591
+ mode,
592
+ }));
593
+ }
594
+ else if (resources?.kind === "resource-time-grid") {
595
+ const slots = layout.kind === "time-grid" ? layout.slots : [];
596
+ const dayEnd = slots[slots.length - 1]
597
+ ? fromSecondOfDay(slots[slots.length - 1].endSecond %
598
+ SECONDS_PER_DAY)
599
+ : undefined;
600
+ value = resources.columns.flatMap((column) => layoutBackgrounds({
601
+ availability: availabilityOf(column.resource),
602
+ timeZone: config.timeZone,
603
+ days: [
604
+ {
605
+ date: column.day.date,
606
+ key: column.day.key,
607
+ resourceId: String(column.resourceId),
608
+ resourceKey: column.resourceKey,
609
+ },
610
+ ],
611
+ dayStart: slots[0]?.start,
612
+ dayEnd,
613
+ mode,
614
+ }));
615
+ }
616
+ else if (layout.kind === "time-grid") {
617
+ const slots = layout.slots;
618
+ value = layoutBackgrounds({
619
+ availability,
620
+ timeZone: config.timeZone,
621
+ days: layout.days.map((day) => ({ date: day.date, key: day.key })),
622
+ dayStart: slots[0]?.start,
623
+ dayEnd: slots[slots.length - 1]
624
+ ? fromSecondOfDay(slots[slots.length - 1].endSecond %
625
+ SECONDS_PER_DAY)
626
+ : undefined,
627
+ mode,
628
+ });
629
+ }
630
+ backgroundsCache = { key: signature, value };
631
+ return value;
632
+ };
633
+ state = compute(true);
634
+ const apply = (next) => {
635
+ custom = next.custom;
636
+ focusedDate = next.focusedDate;
637
+ if (!next.custom && next.view !== viewControl.get()) {
638
+ viewControl.set(next.view);
639
+ }
640
+ if (!isSameDay(next.anchor, dateControl.get())) {
641
+ dateControl.set(next.anchor);
642
+ }
643
+ refresh();
644
+ };
645
+ const go = (action) => apply(navigate(navState(), action, config.nav));
646
+ const moveFocusTo = (target) => {
647
+ if (!isDateInRange(target, state.range)) {
648
+ go({ goTo: target });
649
+ return;
650
+ }
651
+ focusedDate = target;
652
+ refresh();
653
+ };
654
+ const visibleDays = () => state.layout.kind === "month" ? [] : state.layout.days;
655
+ const cellItems = (cellKey) => {
656
+ const segments = segmentList();
657
+ const keys = segments
658
+ .filter((segment) => segmentCellKey(segment) === cellKey)
659
+ .map((segment) => segment.key);
660
+ const hasMore = state.more.some((m) => m.dayKey === cellKey);
661
+ return hasMore ? [...keys, `more:${cellKey}`] : keys;
662
+ };
663
+ const segmentList = () => {
664
+ const events = state.events;
665
+ if (Array.isArray(events)) {
666
+ return events;
667
+ }
668
+ return [];
669
+ };
670
+ const segmentCellKey = (segment) => {
671
+ if ("dayKey" in segment) {
672
+ return segment.dayKey;
673
+ }
674
+ if ("month" in segment) {
675
+ // Month segment: resolve via the layout.
676
+ return monthSegmentCellKey(segment);
677
+ }
678
+ return "";
679
+ };
680
+ const monthSegmentCellKey = (segment) => {
681
+ const layout = state.layout;
682
+ if (layout.kind !== "month") {
683
+ return "";
684
+ }
685
+ const month = layout.months[segment.month];
686
+ const week = month?.weeks[segment.week];
687
+ const day = week?.days.filter((d) => !d.hidden)[segment.startColumn];
688
+ return day?.key ?? "";
689
+ };
690
+ const handleKeyDown = (key, modifiers) => {
691
+ if (modifiers.ctrl || modifiers.meta) {
692
+ return false;
693
+ }
694
+ // 0. Keyboard editing of an event (plan 09 M10).
695
+ if (engine.isEditing()) {
696
+ return engine.handleKey(key, modifiers);
697
+ }
698
+ // 1. Active selection preview.
699
+ if (selection) {
700
+ if (key === "Escape") {
701
+ cancelSelection();
702
+ return true;
703
+ }
704
+ if (key === "Enter") {
705
+ confirmSelection();
706
+ return true;
707
+ }
708
+ if (isNavKey(key) && modifiers.shift) {
709
+ extendSelectionKeyboard(key);
710
+ return true;
711
+ }
712
+ return false;
713
+ }
714
+ // 2. Interaction mode (focus on events inside a cell).
715
+ if (state.focus.mode === "interaction") {
716
+ const edit = state.focus.itemKey
717
+ ? engine.shortcut(key, { ...modifiers, alt: false })
718
+ : null;
719
+ if (edit &&
720
+ state.focus.itemKey &&
721
+ engine.canEditSegment(state.focus.itemKey, edit)) {
722
+ return engine.start(edit, state.focus.itemKey, "keyboard");
723
+ }
724
+ if (key === " ") {
725
+ const segment = segmentByKey(state.focus.itemKey);
726
+ if (segment) {
727
+ selectEvent(segment.event.id);
728
+ announce(formatMessage(state.messages.eventSelected, {}));
729
+ return true;
730
+ }
731
+ }
732
+ if (key === "Enter") {
733
+ const itemKey = state.focus.itemKey;
734
+ if (itemKey?.startsWith("more:")) {
735
+ activateMore(state.focus.cellKey);
736
+ return true;
737
+ }
738
+ const segment = segmentByKey(itemKey);
739
+ if (segment) {
740
+ activateEvent(segment.key, "keyboard");
741
+ return true;
742
+ }
743
+ }
744
+ const next = stepFocus(state.focus, key, modifiers, cellItems(state.focus.cellKey));
745
+ if (next) {
746
+ focus = next.mode === "navigation" ? undefined : next;
747
+ refresh();
748
+ return true;
749
+ }
750
+ return false;
751
+ }
752
+ // 3. Navigation mode.
753
+ if (key === "Enter") {
754
+ if (modifiers.shift) {
755
+ controller.activateDate(state.focusedDate, "keyboard");
756
+ return true;
757
+ }
758
+ const cellKey = keyOf(state.focusedDate);
759
+ if (cellItems(cellKey).length > 0) {
760
+ enterCellAction(cellKey);
761
+ return true;
762
+ }
763
+ controller.activateDate(state.focusedDate, "keyboard");
764
+ return true;
765
+ }
766
+ if (key === "F2") {
767
+ const cellKey = keyOf(state.focusedDate);
768
+ if (cellItems(cellKey).length > 0) {
769
+ enterCellAction(cellKey);
770
+ return true;
771
+ }
772
+ }
773
+ if (isNavKey(key) && modifiers.shift && options.selectable) {
774
+ startSelection({ date: state.focusedDate }, "keyboard");
775
+ return true;
776
+ }
777
+ if (!isNavKey(key)) {
778
+ return false;
779
+ }
780
+ const rtl = state.direction === "rtl";
781
+ if (state.definition.layout === "month") {
782
+ moveFocusTo(moveInMonthGrid(state.focusedDate, key, modifiers.shift, {
783
+ weekStartsOn: config.weekStartsOn,
784
+ direction: state.direction,
785
+ min: config.nav.min,
786
+ max: config.nav.max,
787
+ level: "day",
788
+ }, state.hiddenDays));
789
+ return true;
790
+ }
791
+ if (key === "PageUp" || key === "PageDown") {
792
+ go(key === "PageUp" ? "prev" : "next");
793
+ return true;
794
+ }
795
+ const days = visibleDays();
796
+ const keys = days.map((day) => day.key);
797
+ const index = keys.indexOf(keyOf(state.focusedDate));
798
+ if (key === "Home" || key === "End") {
799
+ const edge = key === "Home" ? days[0] : days[days.length - 1];
800
+ if (edge) {
801
+ moveFocusTo(edge.date);
802
+ }
803
+ return true;
804
+ }
805
+ const list = state.definition.layout === "list";
806
+ const forward = key === "ArrowRight"
807
+ ? !rtl
808
+ : key === "ArrowLeft"
809
+ ? rtl
810
+ : key === "ArrowDown"
811
+ ? list
812
+ : false;
813
+ const backward = key === "ArrowLeft"
814
+ ? !rtl
815
+ : key === "ArrowRight"
816
+ ? rtl
817
+ : key === "ArrowUp"
818
+ ? list
819
+ : false;
820
+ if (!forward && !backward) {
821
+ return true;
822
+ }
823
+ const step = forward ? 1 : -1;
824
+ const neighbor = days[index + step];
825
+ if (neighbor) {
826
+ moveFocusTo(neighbor.date);
827
+ }
828
+ else {
829
+ let candidate = addDays(state.focusedDate, step);
830
+ for (let guard = 0; guard < 7 && state.hiddenDays.includes(dayOfWeek(candidate)); guard += 1) {
831
+ candidate = addDays(candidate, step);
832
+ }
833
+ go({ goTo: candidate });
834
+ }
835
+ return true;
836
+ };
837
+ const segmentByKey = (itemKey) => {
838
+ if (!itemKey) {
839
+ return undefined;
840
+ }
841
+ return segmentList().find((segment) => segment.key === itemKey);
842
+ };
843
+ const extendSelectionKeyboard = (key) => {
844
+ const days = state.layout.kind === "month" ? [] : state.layout.days;
845
+ const keys = days.map((day) => day.key);
846
+ const index = keys.indexOf(keyOf(state.focusedDate));
847
+ const target = days[index + (key === "ArrowLeft" || key === "ArrowUp" ? -1 : 1)];
848
+ if (target) {
849
+ extendSelection({ date: target.date });
850
+ }
851
+ };
852
+ const activateMore = (cellKey) => {
853
+ const overflow = state.more.find((m) => m.dayKey === cellKey);
854
+ if (!overflow) {
855
+ return;
856
+ }
857
+ const date = toPlainDate(cellKey, config.timeZone);
858
+ options.onMoreActivate?.(date, [...overflow.events]);
859
+ };
860
+ const selectionToProposal = (range) => ({
861
+ kind: "create",
862
+ start: range.allDay
863
+ ? plainDate(range.start.year, range.start.month, range.start.day)
864
+ : range.start,
865
+ end: range.allDay
866
+ ? plainDate(range.end.year, range.end.month, range.end.day)
867
+ : range.end,
868
+ allDay: range.allDay,
869
+ source: selectionSource,
870
+ });
871
+ const selectEvent = (eventId) => {
872
+ selectedEventControl.set(eventId);
873
+ refresh();
874
+ };
875
+ const activateEvent = (segmentKey, source) => {
876
+ const segment = segmentByKey(segmentKey);
877
+ if (!segment) {
878
+ return;
879
+ }
880
+ options.onEventActivate?.(segment.event, {
881
+ source,
882
+ dayKey: segmentCellKey(segment),
883
+ });
884
+ };
885
+ const enterCellAction = (cellKey) => {
886
+ focus = enterInteractionCell(cellKey, cellItems(cellKey));
887
+ refresh();
888
+ };
889
+ const exitCellAction = () => {
890
+ focus = undefined;
891
+ refresh();
892
+ };
893
+ const startSelection = (target, source) => {
894
+ if (!options.selectable) {
895
+ return;
896
+ }
897
+ selectionSource = source;
898
+ const allDay = state.definition.layout === "month";
899
+ // The anchor is the cell the selection starts on (plan 05 E14).
900
+ selectionAnchor = allDay
901
+ ? { date: target.date }
902
+ : { date: target.date, time: target.time };
903
+ selection = computeSelection(selectionAnchor, target, {
904
+ allDay,
905
+ slotDurationMinutes: options.timeGrid?.step ?? 30,
906
+ maxDurationMinutes: options.maxSelectionDuration,
907
+ });
908
+ refresh();
909
+ };
910
+ const extendSelection = (target) => {
911
+ if (!selection || !selectionAnchor) {
912
+ return;
913
+ }
914
+ selection = computeSelection(selectionAnchor, target, {
915
+ allDay: selection.allDay,
916
+ slotDurationMinutes: options.timeGrid?.step ?? 30,
917
+ maxDurationMinutes: options.maxSelectionDuration,
918
+ });
919
+ refresh();
920
+ };
921
+ const confirmSelection = () => {
922
+ if (!selection) {
923
+ return;
924
+ }
925
+ const proposal = selectionToProposal(selection);
926
+ if (selectionCovered(proposal)) {
927
+ return;
928
+ }
929
+ if (options.validateSelection && !options.validateSelection(proposal)) {
930
+ return;
931
+ }
932
+ options.onSelectRange?.(proposal);
933
+ options.onSelectionChange?.(proposal);
934
+ announce(formatMessage(state.messages.selectionCreated, {
935
+ range: toIsoString(selection.start),
936
+ }), options.announcer);
937
+ };
938
+ const cancelSelection = () => {
939
+ if (!selection) {
940
+ return;
941
+ }
942
+ selection = null;
943
+ selectionAnchor = null;
944
+ announce(state.messages.selectionCancelled, options.announcer);
945
+ refresh();
946
+ };
947
+ const clearSelection = () => {
948
+ selection = null;
949
+ selectionAnchor = null;
950
+ refresh();
951
+ };
952
+ const setEventLimit = (limit) => {
953
+ if (eventLimitOverride === limit) {
954
+ return;
955
+ }
956
+ eventLimitOverride = limit;
957
+ refresh();
958
+ };
959
+ const controller = {
960
+ getState: () => state,
961
+ subscribe(listener) {
962
+ listeners.add(listener);
963
+ return () => {
964
+ listeners.delete(listener);
965
+ };
966
+ },
967
+ setOptions(next) {
968
+ const previousView = options.view;
969
+ options = { ...options, ...next };
970
+ if (next.view !== undefined && next.view !== previousView) {
971
+ custom = undefined;
972
+ }
973
+ if (next.now !== undefined) {
974
+ nowMs = next.now;
975
+ }
976
+ config = readConfig();
977
+ viewControl.sync({ value: options.view });
978
+ dateControl.sync({
979
+ value: options.date === undefined
980
+ ? undefined
981
+ : toPlainDate(options.date, config.timeZone),
982
+ });
983
+ selectedEventControl.sync({ value: options.selectedEventId });
984
+ collapsedControl.sync({ value: options.collapsedResourceIds });
985
+ if (next.events !== undefined) {
986
+ engine.onEventsChanged(normalizedNow());
987
+ }
988
+ refresh(true);
989
+ },
990
+ start() {
991
+ if (started) {
992
+ return;
993
+ }
994
+ started = true;
995
+ emitRange();
996
+ },
997
+ prev: () => go("prev"),
998
+ next: () => go("next"),
999
+ today: () => go("today"),
1000
+ toggleResource(id) {
1001
+ const current = collapsedControl.get();
1002
+ const key = String(id);
1003
+ collapsedControl.set(current.some((entry) => String(entry) === key)
1004
+ ? current.filter((entry) => String(entry) !== key)
1005
+ : [...current, id]);
1006
+ refresh();
1007
+ },
1008
+ zoomIn() {
1009
+ const next = zoomTarget(options.zoomLevels ?? [], state.view, -1);
1010
+ if (next)
1011
+ go({ view: next });
1012
+ },
1013
+ zoomOut() {
1014
+ const next = zoomTarget(options.zoomLevels ?? [], state.view, 1);
1015
+ if (next)
1016
+ go({ view: next });
1017
+ },
1018
+ getResourceHeaderAttributes: (column) => ({
1019
+ role: "columnheader",
1020
+ "aria-label": column.label,
1021
+ "data-resource-id": column.resourceKey,
1022
+ "data-chrono-key": resourceCellKey(column.day.key, column.resourceKey),
1023
+ }),
1024
+ getResourceGroupHeaderAttributes: (group) => ({
1025
+ role: "columnheader",
1026
+ "aria-label": group.label,
1027
+ "aria-colspan": group.colSpan,
1028
+ "data-resource-id": group.resourceKey,
1029
+ "data-resource-group": true,
1030
+ "data-level": group.level,
1031
+ }),
1032
+ getTimelineAttributes: () => ({
1033
+ role: state.resources?.kind === "timeline" && state.resources.grouped
1034
+ ? "treegrid"
1035
+ : "grid",
1036
+ "aria-rowcount": state.resources?.kind === "timeline"
1037
+ ? state.resources.window.totalRows +
1038
+ state.resources.axis.headerRows.length
1039
+ : undefined,
1040
+ "aria-colcount": state.resources?.kind === "timeline"
1041
+ ? state.resources.window.totalColumns
1042
+ : undefined,
1043
+ }),
1044
+ getTimelineHeaderCellAttributes: (cell) => ({
1045
+ role: "columnheader",
1046
+ "aria-colspan": cell.span,
1047
+ "aria-label": cell.label,
1048
+ "data-header-level": cell.unit,
1049
+ }),
1050
+ getTimelineRowAttributes: (row) => {
1051
+ const headerRows = state.resources?.kind === "timeline"
1052
+ ? state.resources.axis.headerRows.length
1053
+ : 0;
1054
+ return {
1055
+ role: "row",
1056
+ "aria-level": row.level + 1,
1057
+ "aria-expanded": row.group ? String(row.expanded) : undefined,
1058
+ "aria-rowindex": row.index + 1 + headerRows,
1059
+ "data-resource-id": row.key,
1060
+ "data-collapsed": row.group && !row.expanded,
1061
+ "--chrono-row-lanes": row.lanes,
1062
+ };
1063
+ },
1064
+ getTimelineRowHeaderAttributes: (row) => ({
1065
+ role: "rowheader",
1066
+ "aria-label": row.label,
1067
+ "data-resource-id": row.key,
1068
+ "data-level": row.level,
1069
+ "data-resource-group": row.group,
1070
+ }),
1071
+ getTimelineCellAttributes: (row, slot) => ({
1072
+ role: "gridcell",
1073
+ "data-chrono-key": resourceCellKey(slot.key, row.key),
1074
+ "data-resource-id": row.key,
1075
+ }),
1076
+ getResourcePieceAttributes: (piece) => ({
1077
+ "data-chrono-event": true,
1078
+ "data-resource-id": piece.resourceKey,
1079
+ "data-past": piece.past,
1080
+ "data-continues-before": piece.continuesBefore,
1081
+ "data-continues-after": piece.continuesAfter,
1082
+ "data-all-day": piece.allDay,
1083
+ "data-recurring": piece.recurrence !== undefined || piece.event.recurringId !== undefined,
1084
+ "data-override": piece.recurrence?.isOverride === true,
1085
+ "data-selected": selectedEventControl.get() === piece.event.id,
1086
+ "--chrono-event-lane": piece.lane,
1087
+ "--chrono-event-left": piece.left,
1088
+ "--chrono-event-width": piece.width,
1089
+ "--chrono-event-top": piece.top,
1090
+ "--chrono-event-height": piece.height,
1091
+ "--chrono-event-column": piece.column,
1092
+ "--chrono-event-columns": piece.columns,
1093
+ "--chrono-event-span": piece.span,
1094
+ }),
1095
+ goTo: (date) => go({ goTo: toPlainDate(date, config.timeZone) }),
1096
+ setView: (view) => go({ view }),
1097
+ setRange: (range) => go({ range }),
1098
+ focusDate(date) {
1099
+ if (isDateInRange(date, state.visibleRange)) {
1100
+ focusedDate = date;
1101
+ focus = undefined;
1102
+ refresh();
1103
+ }
1104
+ else {
1105
+ go({ goTo: date });
1106
+ }
1107
+ },
1108
+ activateDate(date, source) {
1109
+ controller.focusDate(date);
1110
+ if (!isOutside(date, config.nav.min, config.nav.max)) {
1111
+ options.onDateActivate?.(date, { view: state.view, source });
1112
+ }
1113
+ },
1114
+ handleKeyDown,
1115
+ selectEvent,
1116
+ activateEvent,
1117
+ activateMore,
1118
+ enterCell: enterCellAction,
1119
+ exitCell: exitCellAction,
1120
+ startSelection,
1121
+ extendSelection,
1122
+ confirmSelection,
1123
+ cancelSelection,
1124
+ clearSelection,
1125
+ setEventLimit,
1126
+ getEventLimit: () => options.eventLimit,
1127
+ startMove: (segmentKey, source = "pointer") => engine.start("move", segmentKey, source),
1128
+ startResize: (segmentKey, edge, source = "pointer") => engine.start(edge === "start" ? "resize-start" : "resize-end", segmentKey, source),
1129
+ updateDrag: (target) => engine.update(target),
1130
+ dropDrag: () => engine.drop(),
1131
+ cancelDrag: () => engine.cancel(),
1132
+ getResizeHandleAttributes: (segment, edge) => engine.resizeHandle(segment.key, edge),
1133
+ getDragPreviewAttributes: (piece) => {
1134
+ const { role: _r, tabindex: _t, "aria-pressed": _p, ...rest } = eventAttributes(piece);
1135
+ return {
1136
+ ...rest,
1137
+ "data-chrono-event": undefined,
1138
+ "data-chrono-event-key": undefined,
1139
+ "data-editable": undefined,
1140
+ "data-dragging": undefined,
1141
+ "data-pending": undefined,
1142
+ "data-focused": undefined,
1143
+ "data-selected": undefined,
1144
+ "aria-keyshortcuts": undefined,
1145
+ "aria-description": undefined,
1146
+ "aria-label": undefined,
1147
+ "aria-hidden": "true",
1148
+ "data-drag-preview": true,
1149
+ "data-invalid": state.drag ? !state.drag.valid : false,
1150
+ };
1151
+ },
1152
+ mount(root) {
1153
+ if (options.now === undefined && root && !ticker) {
1154
+ ticker = createTicker((now) => {
1155
+ nowMs = now;
1156
+ refresh();
1157
+ });
1158
+ ticker.start(nowMs);
1159
+ }
1160
+ if (options.editable && root && !dragPointer) {
1161
+ dragPointer = createDragPointer(root, {
1162
+ canStart: (kind, key) => engine.canEditSegment(key, kind),
1163
+ begin: (kind, key, target) => engine.start(kind, key, "pointer", target),
1164
+ update: (target) => engine.update(target),
1165
+ drop: () => engine.drop(),
1166
+ cancel: () => engine.cancel(),
1167
+ hitTest: options.hitTest,
1168
+ scroll: () => options.autoScroll === false
1169
+ ? false
1170
+ : (options.scrollContainer ?? null),
1171
+ });
1172
+ }
1173
+ if (options.selectable && root && !pointer) {
1174
+ pointer = createSelectionPointer(root, {
1175
+ ignore: (event) => !!options.editable &&
1176
+ !!event.target?.closest?.("[data-chrono-event-key]"),
1177
+ start: (target) => startSelectionFromKey(target),
1178
+ extend: (target) => extendSelectionFromKey(target),
1179
+ confirm: confirmSelection,
1180
+ cancel: cancelSelection,
1181
+ hitTest: options.hitTest,
1182
+ });
1183
+ }
1184
+ },
1185
+ unmount() {
1186
+ ticker?.stop();
1187
+ ticker = undefined;
1188
+ pointer?.destroy();
1189
+ pointer = undefined;
1190
+ dragPointer?.destroy();
1191
+ dragPointer = undefined;
1192
+ },
1193
+ getRootAttributes: () => ({
1194
+ "data-chrono-calendar": true,
1195
+ "data-view": state.view,
1196
+ "data-layout": state.definition.layout,
1197
+ "data-dragging": state.drag !== null,
1198
+ dir: state.direction,
1199
+ }),
1200
+ getTitleAttributes: () => ({ id: titleId, "aria-live": "polite" }),
1201
+ getNavAttributes: (kind) => navAttributes(kind === "prev"
1202
+ ? state.messages.previous
1203
+ : kind === "next"
1204
+ ? state.messages.next
1205
+ : state.messages.goToToday, kind === "prev"
1206
+ ? !state.canGoPrev
1207
+ : kind === "next"
1208
+ ? !state.canGoNext
1209
+ : false),
1210
+ getViewButtonAttributes: (view) => ({
1211
+ type: "button",
1212
+ "aria-pressed": state.view === view ? "true" : "false",
1213
+ "data-view": view,
1214
+ }),
1215
+ getGridAttributes(monthIndex = 0) {
1216
+ const months = state.layout.kind === "month" ? state.layout.months : [];
1217
+ const month = months[monthIndex];
1218
+ if (months.length > 1 && month) {
1219
+ return {
1220
+ role: "grid",
1221
+ "aria-label": getCalendarTitle({ start: day1(month), end: day1(month) }, state.definition, config.locale).text,
1222
+ };
1223
+ }
1224
+ return { role: "grid", "aria-labelledby": titleId };
1225
+ },
1226
+ getColumnHeaderAttributes(day) {
1227
+ if (!isCalendarDay(day)) {
1228
+ return columnHeaderAttributes(day);
1229
+ }
1230
+ // E13: day headers are no longer the focusable row; drop focus + key.
1231
+ const attributes = dayAttributes(day, "columnheader", {
1232
+ locale: config.locale,
1233
+ messages: state.messages,
1234
+ });
1235
+ delete attributes.tabindex;
1236
+ delete attributes["data-chrono-key"];
1237
+ return attributes;
1238
+ },
1239
+ getCellAttributes: (day) => {
1240
+ const { status, label } = dayAvailability(day.date);
1241
+ return {
1242
+ ...cellAttributes(day, {
1243
+ locale: config.locale,
1244
+ messages: state.messages,
1245
+ extraLabel: label || undefined,
1246
+ }),
1247
+ "data-unavailable": status === "unavailable",
1248
+ "data-partially-available": status === "partial",
1249
+ };
1250
+ },
1251
+ getWeekNumberAttributes: (weekNumber) => weekNumberAttributes(weekNumber, state.messages),
1252
+ getTimeGridAttributes: () => ({
1253
+ role: "grid",
1254
+ "aria-labelledby": titleId,
1255
+ "aria-rowcount": state.layout.kind === "time-grid"
1256
+ ? state.layout.slots.length
1257
+ : undefined,
1258
+ "aria-colcount": state.layout.kind === "time-grid"
1259
+ ? state.layout.days.length
1260
+ : undefined,
1261
+ }),
1262
+ getSlotAttributes: (slot, day) => {
1263
+ const slotKey = `${day.key}T${toIsoString(slot.start)}`;
1264
+ const focused = state.focus.cellKey === slotKey;
1265
+ return {
1266
+ role: "gridcell",
1267
+ tabindex: focused ? 0 : -1,
1268
+ "data-chrono-key": slotKey,
1269
+ "data-slot-start": toIsoString(slot.start),
1270
+ "data-unavailable": slotUnavailable(slot, day),
1271
+ "data-working-hours": slot.working &&
1272
+ (state.layout.kind !== "time-grid" ||
1273
+ state.layout.workingDays.includes(day.dayOfWeek)),
1274
+ "data-selecting": state.selection !== null && state.layout.kind === "time-grid",
1275
+ "data-has-events": slotHasEvents(slot, day),
1276
+ };
1277
+ },
1278
+ getAgendaAttributes: () => ({ role: "list", "aria-labelledby": titleId }),
1279
+ getAgendaDayAttributes: (day) => {
1280
+ const { status, label } = dayAvailability(day.date);
1281
+ return {
1282
+ ...dayAttributes(day, "listitem", {
1283
+ locale: config.locale,
1284
+ messages: state.messages,
1285
+ extraLabel: label || undefined,
1286
+ }),
1287
+ "data-unavailable": status === "unavailable",
1288
+ "data-partially-available": status === "partial",
1289
+ };
1290
+ },
1291
+ getEventAttributes: (segment) => eventAttributes(segment),
1292
+ getCellEventSegments: (day) => segmentList().filter((segment) => segmentCellKey(segment) === day.key),
1293
+ getBackgroundAttributes: (piece) => backgroundAttributes(piece),
1294
+ getCellDragPreviewSegments: (day, allDay = false) => {
1295
+ const preview = state.drag?.preview;
1296
+ if (!preview) {
1297
+ return [];
1298
+ }
1299
+ const pieces = (allDay ? preview.allDayRow : preview.events);
1300
+ return Array.isArray(pieces)
1301
+ ? pieces.filter((piece) => segmentCellKey(piece) === day.key)
1302
+ : [];
1303
+ },
1304
+ getEventSegment: (key) => segmentByKey(key),
1305
+ getMoreAttributes: (day) => {
1306
+ const overflow = state.more.find((m) => m.dayKey === day.key);
1307
+ return {
1308
+ type: "button",
1309
+ "aria-label": formatMessage(state.messages.moreEvents, {
1310
+ count: overflow?.count ?? 0,
1311
+ }),
1312
+ "data-overflow": overflow !== undefined,
1313
+ "data-chrono-key": day.key,
1314
+ };
1315
+ },
1316
+ getAllDayCellAttributes: (day) => ({
1317
+ "data-chrono-key": day.key,
1318
+ "data-all-day-cell": true,
1319
+ "data-has-events": state.allDayRow.some((s) => segmentCovers(s, day.key)),
1320
+ }),
1321
+ getNowIndicatorAttributes: () => state.nowIndicator
1322
+ ? {
1323
+ "aria-hidden": "true",
1324
+ "data-now": true,
1325
+ "--chrono-now-top": state.nowIndicator.top,
1326
+ }
1327
+ : {},
1328
+ getSelectionPreviewAttributes: (day) => {
1329
+ if (!state.selection) {
1330
+ return {};
1331
+ }
1332
+ const pieces = selectionPieces(state.selection);
1333
+ const piece = pieces.find((p) => toIsoString(p.date) === day.key);
1334
+ if (!piece) {
1335
+ return {};
1336
+ }
1337
+ return {
1338
+ "aria-hidden": "true",
1339
+ "data-selection": true,
1340
+ "data-invalid": selectionInvalid(),
1341
+ "data-continues-before": piece.continuesBefore,
1342
+ "data-continues-after": piece.continuesAfter,
1343
+ "--chrono-event-top": topOf(piece.start),
1344
+ "--chrono-event-height": heightOf(piece.start, piece.end),
1345
+ };
1346
+ },
1347
+ destroy() {
1348
+ controller.unmount();
1349
+ engine.dispose();
1350
+ listeners.clear();
1351
+ },
1352
+ };
1353
+ const slotHasEvents = (slot, day) => {
1354
+ if (state.layout.kind !== "time-grid") {
1355
+ return false;
1356
+ }
1357
+ const start = toSecondOfDay(slot.start);
1358
+ const end = slot.endSecond;
1359
+ return state.events.some((segment) => segment.dayKey === day.key &&
1360
+ toSecondOfDay(segment.start) < end &&
1361
+ start < toSecondOfDay(segment.end));
1362
+ };
1363
+ const segmentCovers = (segment, dayKey) => {
1364
+ if (state.layout.kind !== "time-grid") {
1365
+ return false;
1366
+ }
1367
+ const start = state.layout.days.findIndex((d) => d.key === segment.dayKey);
1368
+ const target = state.layout.days.findIndex((d) => d.key === dayKey);
1369
+ return start >= 0 && target >= start && target < start + segment.days;
1370
+ };
1371
+ const selectionInvalid = () => {
1372
+ if (!state.selection) {
1373
+ return false;
1374
+ }
1375
+ const proposal = selectionToProposal(state.selection);
1376
+ if (selectionCovered(proposal)) {
1377
+ return true;
1378
+ }
1379
+ return options.validateSelection
1380
+ ? !options.validateSelection(proposal)
1381
+ : false;
1382
+ };
1383
+ const axisStart = () => state.layout.kind === "time-grid" && state.layout.slots[0]
1384
+ ? toSecondOfDay(state.layout.slots[0].start)
1385
+ : 0;
1386
+ const axisEnd = () => state.layout.kind === "time-grid" &&
1387
+ state.layout.slots[state.layout.slots.length - 1]
1388
+ ? state.layout.slots[state.layout.slots.length - 1]
1389
+ .endSecond
1390
+ : 86400;
1391
+ const topOf = (value) => (toSecondOfDay(value) - axisStart()) / (axisEnd() - axisStart());
1392
+ const heightOf = (start, end) => (toSecondOfDay(end) - toSecondOfDay(start)) / (axisEnd() - axisStart());
1393
+ const eventAttributes = (segment) => {
1394
+ const base = {
1395
+ role: "button",
1396
+ "aria-pressed": selectedEventControl.get() === segment.event.id ? "true" : "false",
1397
+ tabindex: state.focus.mode === "interaction" &&
1398
+ state.focus.itemKey === segment.key
1399
+ ? 0
1400
+ : -1,
1401
+ "data-chrono-event": true,
1402
+ "data-chrono-event-key": segment.key,
1403
+ "data-calendar-id": segment.event.calendarId,
1404
+ "data-selected": selectedEventControl.get() === segment.event.id,
1405
+ "data-focused": state.focus.mode === "interaction" &&
1406
+ state.focus.itemKey === segment.key,
1407
+ "data-all-day": segment.allDay,
1408
+ "data-continues-before": segment.continuesBefore,
1409
+ "data-continues-after": segment.continuesAfter,
1410
+ "data-past": segment.past,
1411
+ "data-recurring": segment.recurrence !== undefined ||
1412
+ segment.event.recurringId !== undefined,
1413
+ "data-override": segment.recurrence?.isOverride === true,
1414
+ };
1415
+ Object.assign(base, engine.attributes(segment.key));
1416
+ const label = options.getEventLabel?.(segment.event);
1417
+ const recurring = segment.recurrence ? state.messages.recurring : "";
1418
+ if (label !== undefined) {
1419
+ base["aria-label"] = recurring ? `${label}, ${recurring}` : label;
1420
+ }
1421
+ else if (recurring) {
1422
+ base["aria-label"] = recurring;
1423
+ }
1424
+ if ("top" in segment) {
1425
+ base["--chrono-event-top"] = segment.top;
1426
+ base["--chrono-event-height"] = segment.height;
1427
+ base["--chrono-event-column"] = segment.column;
1428
+ base["--chrono-event-columns"] = segment.columns;
1429
+ base["--chrono-event-span"] = segment.span;
1430
+ }
1431
+ else if ("startColumn" in segment) {
1432
+ base["--chrono-event-start"] = segment.startColumn;
1433
+ base["--chrono-event-days"] = segment.days;
1434
+ base["--chrono-event-lane"] = segment.lane;
1435
+ }
1436
+ return base;
1437
+ };
1438
+ const startSelectionFromKey = (target) => {
1439
+ startSelection(parseCellKey(target.cellKey), "pointer");
1440
+ };
1441
+ const extendSelectionFromKey = (target) => {
1442
+ extendSelection(parseCellKey(target.cellKey));
1443
+ };
1444
+ if (!lazyStart) {
1445
+ controller.start();
1446
+ }
1447
+ return controller;
1448
+ }