@zealakit/chrono-react 1.0.0-beta.1 → 1.0.0-beta.2

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 (163) hide show
  1. package/README.md +1 -0
  2. package/dist/calendar/components.d.ts +2 -2
  3. package/dist/calendar/components.js +10 -12
  4. package/dist/calendar/mini-calendar.js +6 -5
  5. package/dist/calendar/use-calendar.js +1 -3
  6. package/dist/calendar/use-mini-calendar.js +1 -1
  7. package/dist/date/bind-panel.js +1 -1
  8. package/dist/date/components.js +20 -29
  9. package/dist/date/utilities.d.ts +1 -1
  10. package/dist/date/utilities.js +1 -1
  11. package/dist/datetime/components.js +16 -21
  12. package/dist/datetime/use-datetime-panel.js +1 -1
  13. package/dist/shared/defined-options.d.ts +18 -0
  14. package/dist/shared/defined-options.js +9 -0
  15. package/dist/shared/merge-props.js +1 -3
  16. package/dist/shared/part.d.ts +1 -1
  17. package/dist/shared/slot.js +1 -4
  18. package/dist/shared/style-properties.js +1 -1
  19. package/dist/time/bind-panel.js +2 -2
  20. package/dist/time/components.d.ts +2 -2
  21. package/dist/time/components.js +16 -21
  22. package/dist/time/utilities.d.ts +1 -1
  23. package/dist/time/utilities.js +1 -1
  24. package/dist/vendor/core/calendar/availability.d.ts +2 -2
  25. package/dist/vendor/core/calendar/availability.js +4 -5
  26. package/dist/vendor/core/calendar/controllers/calendar-controller.js +93 -145
  27. package/dist/vendor/core/calendar/controllers/drag-engine.js +15 -34
  28. package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +3 -2
  29. package/dist/vendor/core/calendar/controllers/shared.d.ts +9 -5
  30. package/dist/vendor/core/calendar/controllers/shared.js +8 -8
  31. package/dist/vendor/core/calendar/events/agenda-layout.js +4 -3
  32. package/dist/vendor/core/calendar/events/all-day-row.d.ts +1 -1
  33. package/dist/vendor/core/calendar/events/all-day-row.js +5 -5
  34. package/dist/vendor/core/calendar/events/background-layout.d.ts +1 -1
  35. package/dist/vendor/core/calendar/events/background-layout.js +6 -7
  36. package/dist/vendor/core/calendar/events/month-layout.js +6 -5
  37. package/dist/vendor/core/calendar/events/normalize.d.ts +2 -2
  38. package/dist/vendor/core/calendar/events/normalize.js +6 -9
  39. package/dist/vendor/core/calendar/events/now-indicator.d.ts +2 -2
  40. package/dist/vendor/core/calendar/events/time-grid-layout.d.ts +4 -4
  41. package/dist/vendor/core/calendar/events/time-grid-layout.js +8 -15
  42. package/dist/vendor/core/calendar/events/types.d.ts +2 -2
  43. package/dist/vendor/core/calendar/index.d.ts +11 -11
  44. package/dist/vendor/core/calendar/index.js +5 -5
  45. package/dist/vendor/core/calendar/interaction/auto-scroll.d.ts +1 -9
  46. package/dist/vendor/core/calendar/interaction/auto-scroll.js +12 -39
  47. package/dist/vendor/core/calendar/interaction/drag-geometry.js +2 -5
  48. package/dist/vendor/core/calendar/interaction/drag-keyboard.js +1 -4
  49. package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +5 -4
  50. package/dist/vendor/core/calendar/interaction/drag-pointer.js +33 -193
  51. package/dist/vendor/core/calendar/interaction/gesture-handle.d.ts +17 -0
  52. package/dist/vendor/core/calendar/interaction/gesture-handle.js +26 -0
  53. package/dist/vendor/core/calendar/interaction/pointer.d.ts +1 -1
  54. package/dist/vendor/core/calendar/interaction/pointer.js +65 -15
  55. package/dist/vendor/core/calendar/interaction/selection.d.ts +1 -1
  56. package/dist/vendor/core/calendar/navigation/navigate.d.ts +3 -3
  57. package/dist/vendor/core/calendar/navigation/navigate.js +1 -3
  58. package/dist/vendor/core/calendar/navigation/range.js +1 -1
  59. package/dist/vendor/core/calendar/navigation/view-definition.d.ts +1 -1
  60. package/dist/vendor/core/calendar/navigation/view-definition.js +2 -1
  61. package/dist/vendor/core/calendar/recurrence/apply.js +7 -8
  62. package/dist/vendor/core/calendar/recurrence/expand.d.ts +1 -1
  63. package/dist/vendor/core/calendar/recurrence/expand.js +14 -18
  64. package/dist/vendor/core/calendar/recurrence/pack.js +4 -7
  65. package/dist/vendor/core/calendar/recurrence/rrule.js +6 -16
  66. package/dist/vendor/core/calendar/recurrence/series.js +1 -3
  67. package/dist/vendor/core/calendar/recurrence/types.d.ts +1 -1
  68. package/dist/vendor/core/calendar/resources/resource-time-grid.js +1 -2
  69. package/dist/vendor/core/calendar/resources/timeline-layout.js +4 -6
  70. package/dist/vendor/core/calendar/resources/types.d.ts +7 -7
  71. package/dist/vendor/core/calendar/views/day.d.ts +5 -5
  72. package/dist/vendor/core/calendar/views/day.js +2 -5
  73. package/dist/vendor/core/calendar/views/mini-calendar.d.ts +8 -8
  74. package/dist/vendor/core/calendar/views/mini-calendar.js +1 -1
  75. package/dist/vendor/core/calendar/views/month-layout.d.ts +1 -1
  76. package/dist/vendor/core/calendar/views/month-layout.js +1 -1
  77. package/dist/vendor/core/calendar/views/time-grid-layout.js +1 -4
  78. package/dist/vendor/core/date/input/date-input-controller.d.ts +15 -15
  79. package/dist/vendor/core/date/input/date-input-controller.js +9 -21
  80. package/dist/vendor/core/date/input/date-range-input-controller.js +2 -5
  81. package/dist/vendor/core/date/input/parse.d.ts +2 -2
  82. package/dist/vendor/core/date/input/parse.js +3 -9
  83. package/dist/vendor/core/date/input/validity.js +1 -1
  84. package/dist/vendor/core/date/panel/panel-controller.d.ts +11 -11
  85. package/dist/vendor/core/date/panel/panel-controller.js +18 -40
  86. package/dist/vendor/core/date/presets.js +1 -2
  87. package/dist/vendor/core/date/selection/multiple.js +2 -5
  88. package/dist/vendor/core/date/selection/range.d.ts +2 -2
  89. package/dist/vendor/core/date/selection/range.js +2 -6
  90. package/dist/vendor/core/datetime/compose.d.ts +3 -3
  91. package/dist/vendor/core/datetime/constraints.d.ts +9 -9
  92. package/dist/vendor/core/datetime/input/datetime-input-controller.d.ts +2 -2
  93. package/dist/vendor/core/datetime/input/datetime-input-controller.js +12 -27
  94. package/dist/vendor/core/datetime/input/datetime-range-input-controller.js +5 -16
  95. package/dist/vendor/core/datetime/input/parse.d.ts +2 -2
  96. package/dist/vendor/core/datetime/input/parse.js +2 -5
  97. package/dist/vendor/core/datetime/panel/controller.js +4 -10
  98. package/dist/vendor/core/datetime/panel/range-controller.js +4 -16
  99. package/dist/vendor/core/datetime/zone/day-instants.js +1 -3
  100. package/dist/vendor/core/datetime/zone/resolve.js +2 -4
  101. package/dist/vendor/core/dom/auto-scroll.d.ts +37 -0
  102. package/dist/vendor/core/dom/auto-scroll.js +57 -0
  103. package/dist/vendor/core/dom/drag-session.d.ts +25 -0
  104. package/dist/vendor/core/dom/drag-session.js +257 -0
  105. package/dist/vendor/core/foundation/a11y/announcer.d.ts +9 -4
  106. package/dist/vendor/core/foundation/a11y/announcer.js +15 -27
  107. package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +2 -2
  108. package/dist/vendor/core/foundation/a11y/grid-navigation.js +2 -12
  109. package/dist/vendor/core/foundation/a11y/roving-focus.js +23 -2
  110. package/dist/vendor/core/foundation/constraints/availability-rules.js +2 -4
  111. package/dist/vendor/core/foundation/constraints/availability.d.ts +6 -6
  112. package/dist/vendor/core/foundation/constraints/availability.js +6 -16
  113. package/dist/vendor/core/foundation/constraints/date.d.ts +3 -3
  114. package/dist/vendor/core/foundation/constraints/index.d.ts +1 -1
  115. package/dist/vendor/core/foundation/constraints/range.d.ts +4 -4
  116. package/dist/vendor/core/foundation/constraints/range.js +1 -1
  117. package/dist/vendor/core/foundation/constraints/time.d.ts +5 -5
  118. package/dist/vendor/core/foundation/constraints/time.js +1 -1
  119. package/dist/vendor/core/foundation/grid/index.d.ts +2 -2
  120. package/dist/vendor/core/foundation/grid/month-grid.d.ts +2 -2
  121. package/dist/vendor/core/foundation/grid/time-axis.d.ts +3 -3
  122. package/dist/vendor/core/foundation/grid/time-axis.js +1 -1
  123. package/dist/vendor/core/foundation/input/index.d.ts +1 -1
  124. package/dist/vendor/core/foundation/input/index.js +1 -1
  125. package/dist/vendor/core/foundation/input/segment-engine.js +2 -6
  126. package/dist/vendor/core/foundation/locale/direction.js +1 -13
  127. package/dist/vendor/core/foundation/locale/format.js +1 -3
  128. package/dist/vendor/core/foundation/locale/hour-cycle.js +2 -6
  129. package/dist/vendor/core/foundation/locale/index.d.ts +1 -1
  130. package/dist/vendor/core/foundation/locale/index.js +1 -1
  131. package/dist/vendor/core/foundation/locale/resolve.js +12 -2
  132. package/dist/vendor/core/foundation/locale/week-info.js +1 -2
  133. package/dist/vendor/core/foundation/ranges/index.d.ts +1 -1
  134. package/dist/vendor/core/foundation/ranges/index.js +1 -1
  135. package/dist/vendor/core/foundation/ranges/interval.js +1 -3
  136. package/dist/vendor/core/foundation/store/controllable.d.ts +1 -1
  137. package/dist/vendor/core/foundation/store/ids.d.ts +8 -1
  138. package/dist/vendor/core/foundation/store/ids.js +10 -5
  139. package/dist/vendor/core/foundation/store/index.d.ts +2 -2
  140. package/dist/vendor/core/foundation/store/index.js +2 -2
  141. package/dist/vendor/core/foundation/store/with-optional.d.ts +15 -0
  142. package/dist/vendor/core/foundation/store/with-optional.js +3 -0
  143. package/dist/vendor/core/foundation/values/convert.js +3 -7
  144. package/dist/vendor/core/foundation/values/epoch-day.js +1 -5
  145. package/dist/vendor/core/foundation/values/index.d.ts +1 -1
  146. package/dist/vendor/core/foundation/values/index.js +1 -1
  147. package/dist/vendor/core/foundation/values/iso.js +2 -4
  148. package/dist/vendor/core/foundation/values/plain-time.js +1 -3
  149. package/dist/vendor/core/foundation/values/zoned.js +2 -5
  150. package/dist/vendor/core/time/input/parse.d.ts +1 -1
  151. package/dist/vendor/core/time/input/parse.js +1 -3
  152. package/dist/vendor/core/time/input/time-input-controller.d.ts +18 -18
  153. package/dist/vendor/core/time/input/time-input-controller.js +12 -27
  154. package/dist/vendor/core/time/input/time-range-input-controller.js +3 -10
  155. package/dist/vendor/core/time/input/validity.js +1 -1
  156. package/dist/vendor/core/time/panel/time-panel-controller.d.ts +12 -12
  157. package/dist/vendor/core/time/panel/time-panel-controller.js +19 -49
  158. package/dist/vendor/core/time/selection/range.d.ts +3 -3
  159. package/dist/vendor/core/time/selection/slots.d.ts +9 -9
  160. package/dist/vendor/core/time/selection/slots.js +1 -3
  161. package/package.json +21 -28
  162. package/dist/vendor/core/foundation/store/global-state.d.ts +0 -1
  163. package/dist/vendor/core/foundation/store/global-state.js +0 -21
@@ -38,7 +38,7 @@ function dayMatchesByDay(year, month, day, entry) {
38
38
  }
39
39
  if (entry.ordinal > 0) {
40
40
  const first = nthWeekday(year, month, entry.day, 1);
41
- return (first !== null && Math.floor((day - first) / 7) + 1 === entry.ordinal);
41
+ return first !== null && Math.floor((day - first) / 7) + 1 === entry.ordinal;
42
42
  }
43
43
  const last = nthWeekday(year, month, entry.day, -1);
44
44
  return last !== null && -Math.floor((last - day) / 7) - 1 === entry.ordinal;
@@ -53,8 +53,7 @@ function daysInMonthFor(year, month, defaultDay, rule) {
53
53
  const day = entry > 0 ? entry : limit + 1 + entry;
54
54
  if (day >= 1 &&
55
55
  day <= limit &&
56
- (!byDay ||
57
- byDay.some((item) => dayMatchesByDay(year, month, day, item)))) {
56
+ (!byDay || byDay.some((item) => dayMatchesByDay(year, month, day, item)))) {
58
57
  result.add(day);
59
58
  }
60
59
  }
@@ -89,7 +88,7 @@ function matchesMonthFilters(date, rule) {
89
88
  }
90
89
  if (rule.byMonthDay !== undefined) {
91
90
  const limit = daysInMonth(date.year, date.month);
92
- const days = rule.byMonthDay.map((entry) => entry > 0 ? entry : limit + 1 + entry);
91
+ const days = rule.byMonthDay.map((entry) => (entry > 0 ? entry : limit + 1 + entry));
93
92
  if (!days.includes(date.day)) {
94
93
  return false;
95
94
  }
@@ -115,9 +114,7 @@ function periodOf(rule, startDate, index) {
115
114
  const wkst = rule.wkst ?? DEFAULT_WKST;
116
115
  const weekStart = startOfWeek(startDate, wkst);
117
116
  const anchor = addDays(weekStart, index * interval * 7);
118
- const days = rule.byDay === undefined
119
- ? [dayOfWeek(startDate)]
120
- : rule.byDay.map((entry) => entry.day);
117
+ const days = rule.byDay === undefined ? [dayOfWeek(startDate)] : rule.byDay.map((entry) => entry.day);
121
118
  const dates = [];
122
119
  for (const day of days) {
123
120
  const date = addDays(anchor, (day - wkst + 7) % 7);
@@ -129,7 +126,7 @@ function periodOf(rule, startDate, index) {
129
126
  }
130
127
  if (rule.byMonthDay !== undefined) {
131
128
  const limit = daysInMonth(date.year, date.month);
132
- const wanted = rule.byMonthDay.map((entry) => entry > 0 ? entry : limit + 1 + entry);
129
+ const wanted = rule.byMonthDay.map((entry) => (entry > 0 ? entry : limit + 1 + entry));
133
130
  if (!wanted.includes(date.day)) {
134
131
  continue;
135
132
  }
@@ -170,8 +167,7 @@ function pastUntil(candidate, rule, timeZone, zoned) {
170
167
  return compare(datePart(candidate), until) > 0;
171
168
  }
172
169
  if (zoned && until.timeZone !== undefined) {
173
- return (toInstant(toZoned(candidate, timeZone)) >
174
- toInstant(until));
170
+ return toInstant(toZoned(candidate, timeZone)) > toInstant(until);
175
171
  }
176
172
  return compare(candidate, until) > 0;
177
173
  }
@@ -225,15 +221,17 @@ export function expandRule(rule, options) {
225
221
  return candidate;
226
222
  }
227
223
  const resolved = toZoned(candidate, timeZone, "compatible");
228
- return plainDateTime(plainDate(resolved.year, resolved.month, resolved.day), { hour: resolved.hour, minute: resolved.minute, second: resolved.second });
224
+ return plainDateTime(plainDate(resolved.year, resolved.month, resolved.day), {
225
+ hour: resolved.hour,
226
+ minute: resolved.minute,
227
+ second: resolved.second,
228
+ });
229
229
  };
230
230
  const overlaps = (occurrence) => {
231
231
  if (compare(occurrence.start, occurrence.end) === 0) {
232
- return (compare(occurrence.start, rangeStart) >= 0 &&
233
- compare(occurrence.start, rangeEnd) <= 0);
232
+ return compare(occurrence.start, rangeStart) >= 0 && compare(occurrence.start, rangeEnd) <= 0;
234
233
  }
235
- return (compare(occurrence.start, rangeEnd) <= 0 &&
236
- compare(occurrence.end, rangeStart) > 0);
234
+ return compare(occurrence.start, rangeEnd) <= 0 && compare(occurrence.end, rangeStart) > 0;
237
235
  };
238
236
  const add = (candidate, force = false) => {
239
237
  const key = wallSeconds(candidate);
@@ -272,9 +270,7 @@ export function expandRule(rule, options) {
272
270
  if (rule.count !== undefined && generated >= rule.count) {
273
271
  return [...dates.values()];
274
272
  }
275
- const jumpTo = rule.count === undefined
276
- ? Math.max(0, firstPeriodIndex(rule, startDate, windowStart) - 1)
277
- : 0;
273
+ const jumpTo = rule.count === undefined ? Math.max(0, firstPeriodIndex(rule, startDate, windowStart) - 1) : 0;
278
274
  for (let step = jumpTo; step <= ITERATION_CAP + jumpTo; step += 1) {
279
275
  const iterations = step - jumpTo + 1;
280
276
  if (iterations > ITERATION_CAP) {
@@ -1,6 +1,6 @@
1
1
  import { addDays, compare, plainDateTime, toEpochDay, toIsoString, } from "../../foundation/index.js";
2
- import { normalizeEventInput, normalizeEvents, warnOnce, } from "../events/normalize.js";
3
- import { expandRecurrence, overrideInfo, overrideOf, recurrenceWall, } from "./series.js";
2
+ import { normalizeEventInput, normalizeEvents, warnOnce } from "../events/normalize.js";
3
+ import { expandRecurrence, overrideInfo, overrideOf, recurrenceWall } from "./series.js";
4
4
  const CACHE_LIMIT = 500;
5
5
  const cache = new Map();
6
6
  /** Once per series object and error code (plan 12 R5). */
@@ -150,9 +150,7 @@ function expand(events, options) {
150
150
  const occurrences = cached.map((occurrence) => ({
151
151
  ...occurrence,
152
152
  event: value,
153
- recurrence: occurrence.recurrence
154
- ? { ...occurrence.recurrence, series: value }
155
- : undefined,
153
+ recurrence: occurrence.recurrence ? { ...occurrence.recurrence, series: value } : undefined,
156
154
  }));
157
155
  const byStart = new Map();
158
156
  for (const entry of own) {
@@ -205,8 +203,7 @@ function expand(events, options) {
205
203
  for (const event of overrides) {
206
204
  const shape = event;
207
205
  if (matched.has(event) ||
208
- (shape.recurringId !== undefined &&
209
- seriesById.has(String(shape.recurringId)))) {
206
+ (shape.recurringId !== undefined && seriesById.has(String(shape.recurringId)))) {
210
207
  continue;
211
208
  }
212
209
  const info = parsed.get(event);
@@ -133,15 +133,11 @@ function parseString(text) {
133
133
  }
134
134
  const byMonthDay = parts.get("BYMONTHDAY");
135
135
  if (byMonthDay !== undefined) {
136
- rule.byMonthDay = byMonthDay
137
- .split(",")
138
- .map((entry) => parseNumber(entry, "BYMONTHDAY"));
136
+ rule.byMonthDay = byMonthDay.split(",").map((entry) => parseNumber(entry, "BYMONTHDAY"));
139
137
  }
140
138
  const byMonth = parts.get("BYMONTH");
141
139
  if (byMonth !== undefined) {
142
- rule.byMonth = byMonth
143
- .split(",")
144
- .map((entry) => parseNumber(entry, "BYMONTH"));
140
+ rule.byMonth = byMonth.split(",").map((entry) => parseNumber(entry, "BYMONTH"));
145
141
  }
146
142
  const wkst = parts.get("WKST");
147
143
  if (wkst !== undefined) {
@@ -153,8 +149,7 @@ function validate(rule) {
153
149
  if (!isFreq(rule.freq)) {
154
150
  throw rruleError("unsupported-part", `FREQ=${String(rule.freq)} is not supported.`, "FREQ");
155
151
  }
156
- if (rule.interval !== undefined &&
157
- (!Number.isInteger(rule.interval) || rule.interval < 1)) {
152
+ if (rule.interval !== undefined && (!Number.isInteger(rule.interval) || rule.interval < 1)) {
158
153
  throw rruleError("invalid-value", "INTERVAL must be a positive integer.", "INTERVAL");
159
154
  }
160
155
  if (rule.count !== undefined) {
@@ -200,9 +195,7 @@ function validate(rule) {
200
195
  entry.day < 1 ||
201
196
  entry.day > 7 ||
202
197
  (entry.ordinal !== undefined &&
203
- (!Number.isInteger(entry.ordinal) ||
204
- entry.ordinal === 0 ||
205
- Math.abs(entry.ordinal) > 53))) {
198
+ (!Number.isInteger(entry.ordinal) || entry.ordinal === 0 || Math.abs(entry.ordinal) > 53))) {
206
199
  throw rruleError("invalid-value", "Invalid BYDAY entry.", "BYDAY");
207
200
  }
208
201
  if (entry.ordinal === undefined) {
@@ -216,8 +209,7 @@ function validate(rule) {
216
209
  }
217
210
  }
218
211
  }
219
- if (rule.wkst !== undefined &&
220
- (!Number.isInteger(rule.wkst) || rule.wkst < 1 || rule.wkst > 7)) {
212
+ if (rule.wkst !== undefined && (!Number.isInteger(rule.wkst) || rule.wkst < 1 || rule.wkst > 7)) {
221
213
  throw rruleError("invalid-value", "WKST must be a weekday.", "WKST");
222
214
  }
223
215
  const copy = { freq: rule.freq };
@@ -250,9 +242,7 @@ function untilText(until) {
250
242
  if (!isDateTime(until)) {
251
243
  return date;
252
244
  }
253
- const wall = isZoned(until)
254
- ? fromInstant(toInstant(until), "UTC")
255
- : until;
245
+ const wall = isZoned(until) ? fromInstant(toInstant(until), "UTC") : until;
256
246
  const time = `${pad(wall.hour)}${pad(wall.minute)}${pad(wall.second)}`;
257
247
  return `${date}T${time}${isZoned(until) ? "Z" : ""}`;
258
248
  }
@@ -83,9 +83,7 @@ export function expandRecurrence(series, range, options = {}) {
83
83
  const durationSeconds = allDay
84
84
  ? 0
85
85
  : Math.max(0, wallSeconds(parsed.end) - wallSeconds(parsed.start));
86
- const durationDays = allDay
87
- ? Math.max(1, toEpochDay(parsed.end) - toEpochDay(parsed.start))
88
- : 0;
86
+ const durationDays = allDay ? Math.max(1, toEpochDay(parsed.end) - toEpochDay(parsed.start)) : 0;
89
87
  let rule;
90
88
  try {
91
89
  rule = parseRRule(series.rrule);
@@ -19,7 +19,7 @@ export type RecurrenceExpandOptions = {
19
19
  /** Display zone; the expansion keeps DTSTART's wall time in this zone. */
20
20
  timeZone: string;
21
21
  /** Called once per series object and error code (plan 12 R5). */
22
- onRecurrenceError?: RecurrenceErrorHandler;
22
+ onRecurrenceError?: RecurrenceErrorHandler | undefined;
23
23
  };
24
24
  /**
25
25
  * The opt-in recurrence pack (plan 12 RR2). A plain value: importing
@@ -104,8 +104,7 @@ export function layoutResourceTimeGrid(ctx) {
104
104
  }
105
105
  }
106
106
  const rowStart = leafRows.length
107
- ? Math.floor(window.start /
108
- Math.max(1, ctx.grouping === "date-first" ? leafRows.length : dayCount))
107
+ ? Math.floor(window.start / Math.max(1, ctx.grouping === "date-first" ? leafRows.length : dayCount))
109
108
  : 0;
110
109
  return {
111
110
  kind: "resource-time-grid",
@@ -3,6 +3,7 @@ import { compareEventIds } from "../events/sort.js";
3
3
  import { buildTimelineAxis } from "./timeline-axis.js";
4
4
  import { buildResourceTree } from "./tree.js";
5
5
  import { clampWindow, windowInfo } from "./windowing.js";
6
+ import { withOptional } from "../../foundation/store/with-optional.js";
6
7
  const DAY = 86400;
7
8
  const wall = (v) => toEpochDay(v) * DAY + toSecondOfDay(v);
8
9
  /** Lane packing per row on the continuous axis: first fit, half-open (plan 10 R7). */
@@ -41,10 +42,7 @@ function packLanes(pieces) {
41
42
  */
42
43
  export function layoutTimeline(ctx) {
43
44
  const definition = ctx.definition;
44
- const headerUnits = (definition.headerRows ?? [
45
- "day",
46
- "hour",
47
- ]);
45
+ const headerUnits = (definition.headerRows ?? ["day", "hour"]);
48
46
  const firstDay = (ctx.days[0] ?? { date: ctx.range.start }).date;
49
47
  const dayCount = ctx.days.length || 1;
50
48
  const axis = buildTimelineAxis(firstDay, dayCount, definition.slot ?? { minutes: 60 }, headerUnits, ctx.locale);
@@ -71,7 +69,7 @@ export function layoutTimeline(ctx) {
71
69
  if (!visibleKeys.has(key))
72
70
  continue;
73
71
  const list = byRow.get(key) ?? [];
74
- list.push({
72
+ list.push(withOptional({
75
73
  key: `${event.key}:${encodeURIComponent(key)}`,
76
74
  event: event.event,
77
75
  eventId: event.id,
@@ -87,7 +85,7 @@ export function layoutTimeline(ctx) {
87
85
  continuesAfter: e > axisEnd,
88
86
  past: e <= nowSeconds,
89
87
  recurrence: event.recurrence,
90
- });
88
+ }));
91
89
  byRow.set(key, list);
92
90
  }
93
91
  }
@@ -165,13 +165,13 @@ export type ResourceBuildContext<TEvent extends CalendarEventInput = CalendarEve
165
165
  resources: readonly TResource[];
166
166
  collapsed: readonly ResourceId[];
167
167
  grouping: ResourceGrouping;
168
- getLabel?: (resource: TResource) => string;
169
- resourceWindow?: WindowRange;
170
- slotWindow?: WindowRange;
171
- dayStart?: PlainTime;
172
- dayEnd?: PlainTime;
173
- minEventDuration?: number;
174
- longEventsInAllDayRow?: boolean;
168
+ getLabel?: ((resource: TResource) => string) | undefined;
169
+ resourceWindow?: WindowRange | undefined;
170
+ slotWindow?: WindowRange | undefined;
171
+ dayStart?: PlainTime | undefined;
172
+ dayEnd?: PlainTime | undefined;
173
+ minEventDuration?: number | undefined;
174
+ longEventsInAllDayRow?: boolean | undefined;
175
175
  };
176
176
  export type ResourceLayoutBuilder = (context: ResourceBuildContext<any, any>) => ResourceLayout<any, any>;
177
177
  export type { PlainDate };
@@ -21,11 +21,11 @@ export type DayContext = {
21
21
  inRangeOf?: DateRange | null;
22
22
  focusedDate: PlainDate;
23
23
  hiddenDays: readonly DayOfWeek[];
24
- min?: PlainDate;
25
- max?: PlainDate;
26
- selectedDate?: PlainDate;
27
- isHighlighted?: (date: PlainDate) => boolean;
28
- isMarked?: (date: PlainDate) => boolean;
24
+ min?: PlainDate | undefined;
25
+ max?: PlainDate | undefined;
26
+ selectedDate?: PlainDate | undefined;
27
+ isHighlighted?: ((date: PlainDate) => boolean) | undefined;
28
+ isMarked?: ((date: PlainDate) => boolean) | undefined;
29
29
  };
30
30
  /** Outside `min` / `max`. */
31
31
  export declare function isOutside(date: PlainDate, min?: PlainDate, max?: PlainDate): boolean;
@@ -1,17 +1,14 @@
1
1
  import { compare, dayOfWeek, eachDay, isDateInRange, isSameDay, toIsoString, } from "../../foundation/index.js";
2
2
  /** Outside `min` / `max`. */
3
3
  export function isOutside(date, min, max) {
4
- return ((min !== undefined && compare(date, min) < 0) ||
5
- (max !== undefined && compare(date, max) > 0));
4
+ return ((min !== undefined && compare(date, min) < 0) || (max !== undefined && compare(date, max) > 0));
6
5
  }
7
6
  export function makeDay(grid, ctx) {
8
7
  const { date } = grid;
9
8
  return {
10
9
  ...grid,
11
10
  key: toIsoString(date),
12
- inRange: ctx.inRangeOf === null
13
- ? false
14
- : isDateInRange(date, ctx.inRangeOf ?? ctx.range),
11
+ inRange: ctx.inRangeOf === null ? false : isDateInRange(date, ctx.inRangeOf ?? ctx.range),
15
12
  hidden: ctx.hiddenDays.includes(grid.dayOfWeek),
16
13
  disabled: isOutside(date, ctx.min, ctx.max),
17
14
  focused: isSameDay(date, ctx.focusedDate),
@@ -7,17 +7,17 @@ export type MiniCalendarLayoutOptions = {
7
7
  };
8
8
  weekStartsOn: DayOfWeek;
9
9
  weekInfo: Pick<WeekInfo, "weekend" | "firstDay" | "minimalDays">;
10
- locale?: string;
10
+ locale?: string | undefined;
11
11
  today: PlainDate;
12
12
  focusedDate: PlainDate;
13
13
  /** Days inside it get `inRange` (the main calendar's visible range, C11). */
14
- highlight?: DateRange;
15
- isMarked?: (date: PlainDate) => boolean;
16
- selectedDate?: PlainDate;
17
- isHighlighted?: (date: PlainDate) => boolean;
18
- min?: PlainDate;
19
- max?: PlainDate;
20
- weekNumbers?: "iso" | "locale" | false;
14
+ highlight?: DateRange | undefined;
15
+ isMarked?: ((date: PlainDate) => boolean) | undefined;
16
+ selectedDate?: PlainDate | undefined;
17
+ isHighlighted?: ((date: PlainDate) => boolean) | undefined;
18
+ min?: PlainDate | undefined;
19
+ max?: PlainDate | undefined;
20
+ weekNumbers?: "iso" | "locale" | false | undefined;
21
21
  };
22
22
  /** One 6-row month grid. Every day adds `marked`, and `inRange` for the synced range. */
23
23
  export declare function getMiniCalendarLayout(options: MiniCalendarLayoutOptions): MonthLayout;
@@ -1,5 +1,5 @@
1
1
  import { plainDate, } from "../../foundation/index.js";
2
- import { getMonthLayout, } from "./month-layout.js";
2
+ import { getMonthLayout } from "./month-layout.js";
3
3
  /** One 6-row month grid. Every day adds `marked`, and `inRange` for the synced range. */
4
4
  export function getMiniCalendarLayout(options) {
5
5
  const first = plainDate(options.month.year, options.month.month, 1);
@@ -23,7 +23,7 @@ export type LayoutContext = DayContext & {
23
23
  visibleRange: DateRange;
24
24
  weekStartsOn: DayOfWeek;
25
25
  weekInfo: Pick<WeekInfo, "weekend" | "firstDay" | "minimalDays">;
26
- locale?: string;
26
+ locale?: string | undefined;
27
27
  today: PlainDate;
28
28
  weekNumbers: "iso" | "locale" | false;
29
29
  };
@@ -1,5 +1,5 @@
1
1
  import { dayOfWeekFromEpochDay, endOfWeek, fromEpochDay, getIsoWeek, getLocaleWeek, getMonths, getWeekdayHeaders, isDateInRange, isSameDay, startOfWeek, toEpochDay, } from "../../foundation/index.js";
2
- import { getMonthCount, } from "../navigation/view-definition.js";
2
+ import { getMonthCount } from "../navigation/view-definition.js";
3
3
  import { makeDay } from "./day.js";
4
4
  function weekNumberOf(days, ctx) {
5
5
  if (ctx.weekNumbers === "locale") {
@@ -2,10 +2,7 @@ import { getTimeAxis, getWeekdayHeaders, toPlainTime, } from "../../foundation/i
2
2
  import { visibleDays } from "./day.js";
3
3
  export function getTimeGridLayout(ctx, options = {}) {
4
4
  const days = visibleDays(ctx);
5
- const headers = new Map(getWeekdayHeaders(ctx.locale, { weekStartsOn: 1 }).map((header) => [
6
- header.dayOfWeek,
7
- header,
8
- ]));
5
+ const headers = new Map(getWeekdayHeaders(ctx.locale, { weekStartsOn: 1 }).map((header) => [header.dayOfWeek, header]));
9
6
  const workingHours = options.workingHours;
10
7
  const slots = getTimeAxis({
11
8
  start: options.start === undefined ? undefined : toPlainTime(options.start),
@@ -3,35 +3,35 @@ import type { DateValue, PartName } from "../types.js";
3
3
  import { type ParseContext } from "./parse.js";
4
4
  import { type DateValidity } from "./validity.js";
5
5
  export type FormatContext = {
6
- locale?: string;
6
+ locale?: string | undefined;
7
7
  };
8
8
  export type DateInputOptions = {
9
9
  id?: string;
10
10
  value?: DateValue;
11
- defaultValue?: DateValue;
11
+ defaultValue?: DateValue | undefined;
12
12
  onValueChange?: (value: DateValue) => void;
13
13
  /** On blur or Enter with a valid value. */
14
14
  onValueCommit?: (value: PlainDate) => void;
15
- mode?: "segmented" | "text";
15
+ mode?: "segmented" | "text" | undefined;
16
16
  /** The value ↑/↓ starts from on an empty part (default today). */
17
17
  placeholderValue?: DateInput;
18
18
  parse?: (text: string, context: ParseContext) => PlainDate | null;
19
19
  format?: (date: PlainDate, context: FormatContext) => string;
20
- onInvalidInput?: (text: string) => void;
20
+ onInvalidInput?: ((text: string) => void) | undefined;
21
21
  name?: string;
22
- required?: boolean;
23
- readOnly?: boolean;
24
- disabled?: boolean;
25
- min?: DateInput;
26
- max?: DateInput;
22
+ required?: boolean | undefined;
23
+ readOnly?: boolean | undefined;
24
+ disabled?: boolean | undefined;
25
+ min?: DateInput | undefined;
26
+ max?: DateInput | undefined;
27
27
  isDateDisabled?: (date: PlainDate) => boolean;
28
- isDateUnavailable?: (date: PlainDate) => boolean;
28
+ isDateUnavailable?: ((date: PlainDate) => boolean) | undefined;
29
29
  /** Availability model (plan 11 V7): fully unavailable days are not selectable. */
30
- availability?: AvailabilitySpec | Availability;
31
- locale?: string;
32
- timeZone?: string;
33
- now?: number;
34
- messages?: Partial<Messages>;
30
+ availability?: AvailabilitySpec | Availability | undefined;
31
+ locale?: string | undefined;
32
+ timeZone?: string | undefined;
33
+ now?: number | undefined;
34
+ messages?: Partial<Messages> | undefined;
35
35
  /** Internal: called when focus tries to leave the first (-1) or last (1) part. */
36
36
  onFocusEdge?: (direction: 1 | -1) => void;
37
37
  };
@@ -1,6 +1,7 @@
1
1
  import { backspace, compileAvailability, createControllable, createId, daysInMonth, defaultMessages, emptySegment, formatDate, getDateFormatPattern, getDatePartOrder, getHiddenInputs, getMonthNames, getTextDirection, isSameDay, isValidDate, mergeMessages, plainDate, resolveLocale, segmentOf, stepSegment, toIsoString, toLatinDigits, toLocaleDigits, toPlainDate, today as readToday, typeDigit, } from "../../foundation/index.js";
2
- import { parseDate, resolveTwoDigitYear, } from "./parse.js";
2
+ import { parseDate, resolveTwoDigitYear } from "./parse.js";
3
3
  import { getValidity, isInvalid } from "./validity.js";
4
+ import { withOptional } from "../../foundation/store/with-optional.js";
4
5
  const PARTS = ["day", "month", "year"];
5
6
  const sameNullable = (a, b) => a === b || (a !== null && b !== null && isSameDay(a, b));
6
7
  export function createDateInputController(initial = {}) {
@@ -161,7 +162,7 @@ export function createDateInputController(initial = {}) {
161
162
  if (suffix)
162
163
  segments.push(literal(suffix));
163
164
  const value = control.get();
164
- return {
165
+ return withOptional({
165
166
  id,
166
167
  mode: options.mode ?? "segmented",
167
168
  segments,
@@ -176,10 +177,8 @@ export function createDateInputController(initial = {}) {
176
177
  direction: getTextDirection(locale),
177
178
  locale,
178
179
  messages,
179
- hidden: getHiddenInputs([
180
- [options.name, value ? toIsoString(value) : null],
181
- ]),
182
- };
180
+ hidden: getHiddenInputs([[options.name, value ? toIsoString(value) : null]]),
181
+ });
183
182
  };
184
183
  const refresh = () => {
185
184
  const next = compute();
@@ -203,9 +202,7 @@ export function createDateInputController(initial = {}) {
203
202
  if (part !== "year" || segment.buffer === "")
204
203
  return;
205
204
  const typed = Number(segment.buffer);
206
- const resolved = segment.buffer.length === 2
207
- ? resolveTwoDigitYear(typed, todayNow().year)
208
- : typed;
205
+ const resolved = segment.buffer.length === 2 ? resolveTwoDigitYear(typed, todayNow().year) : typed;
209
206
  parts = {
210
207
  ...parts,
211
208
  year: {
@@ -299,10 +296,7 @@ export function createDateInputController(initial = {}) {
299
296
  }
300
297
  const pv = toPlainDate(options.placeholderValue ?? todayNow(), options.timeZone);
301
298
  const bounds = def(part);
302
- if (key === "ArrowUp" ||
303
- key === "ArrowDown" ||
304
- key === "PageUp" ||
305
- key === "PageDown") {
299
+ if (key === "ArrowUp" || key === "ArrowDown" || key === "PageUp" || key === "PageDown") {
306
300
  settlePart(part);
307
301
  const direction = key === "ArrowUp" || key === "PageUp" ? 1 : -1;
308
302
  const amount = key.startsWith("Page") ? bounds.pageStep : 1;
@@ -394,9 +388,7 @@ export function createDateInputController(initial = {}) {
394
388
  afterEdit();
395
389
  }
396
390
  const value = control.get();
397
- if (value &&
398
- state.validity === "valid" &&
399
- !sameNullable(value, lastCommitted)) {
391
+ if (value && state.validity === "valid" && !sameNullable(value, lastCommitted)) {
400
392
  lastCommitted = value;
401
393
  options.onValueCommit?.(value);
402
394
  }
@@ -443,11 +435,7 @@ export function createDateInputController(initial = {}) {
443
435
  "aria-disabled": state.disabled ? "true" : undefined,
444
436
  "aria-required": state.required ? "true" : undefined,
445
437
  "aria-invalid": isInvalid(state.validity) ? "true" : undefined,
446
- tabindex: state.disabled
447
- ? undefined
448
- : segment.type === state.focusedPart
449
- ? 0
450
- : -1,
438
+ tabindex: state.disabled ? undefined : segment.type === state.focusedPart ? 0 : -1,
451
439
  inputmode: "numeric",
452
440
  "data-placeholder": segment.value === null && segment.text === segment.placeholder,
453
441
  "data-invalid": isInvalid(state.validity),
@@ -1,13 +1,10 @@
1
1
  import { compare, compileAvailability, createControllable, createId, getHiddenInputs, isSameDay, toIsoString, } from "../../foundation/index.js";
2
- import { checkPicked, } from "../selection/range.js";
2
+ import { checkPicked } from "../selection/range.js";
3
3
  import { createDateInputController, } from "./date-input-controller.js";
4
4
  import { isInvalid } from "./validity.js";
5
5
  const sameNullable = (a, b) => a === b || (a !== null && b !== null && isSameDay(a, b));
6
6
  const sameRange = (a, b) => a === b ||
7
- (a !== null &&
8
- b !== null &&
9
- sameNullable(a.start, b.start) &&
10
- sameNullable(a.end, b.end));
7
+ (a !== null && b !== null && sameNullable(a.start, b.start) && sameNullable(a.end, b.end));
11
8
  export function createDateRangeInputController(initial = {}) {
12
9
  let options = initial;
13
10
  const id = options.id ?? createId("chrono-date-range-input");
@@ -1,8 +1,8 @@
1
1
  import { type PlainDate } from "../../foundation/index.js";
2
2
  export type ParseContext = {
3
- locale?: string;
3
+ locale?: string | undefined;
4
4
  today?: PlainDate;
5
- timeZone?: string;
5
+ timeZone?: string | undefined;
6
6
  };
7
7
  export type ParseResult = {
8
8
  date: PlainDate;
@@ -6,15 +6,10 @@ import { fold, getDatePartOrder, getMonthNames, isValidDate, plainDate, toLatinD
6
6
  export function resolveTwoDigitYear(year, today) {
7
7
  const century = Math.floor(today / 100) * 100;
8
8
  let best = century + year;
9
- for (const candidate of [
10
- century - 100 + year,
11
- century + year,
12
- century + 100 + year,
13
- ]) {
9
+ for (const candidate of [century - 100 + year, century + year, century + 100 + year]) {
14
10
  const distance = Math.abs(candidate - today);
15
11
  const bestDistance = Math.abs(best - today);
16
- if (distance < bestDistance ||
17
- (distance === bestDistance && candidate < best)) {
12
+ if (distance < bestDistance || (distance === bestDistance && candidate < best)) {
18
13
  best = candidate;
19
14
  }
20
15
  }
@@ -63,8 +58,7 @@ export function parseDate(text, context = {}) {
63
58
  let first = numbers[0];
64
59
  let second = numbers[1];
65
60
  const rest = order.filter((part) => part !== "month");
66
- if (first.text.length === 4 ||
67
- (rest[0] === "year" && second.text.length !== 4)) {
61
+ if (first.text.length === 4 || (rest[0] === "year" && second.text.length !== 4)) {
68
62
  [first, second] = [second, first];
69
63
  }
70
64
  // `first` is the day, `second` the year.
@@ -1,4 +1,4 @@
1
- import { getDateStatus, } from "../../foundation/index.js";
1
+ import { getDateStatus } from "../../foundation/index.js";
2
2
  /** `filled` is how many of the three parts hold a value. */
3
3
  export function getValidity(filled, date, constraints) {
4
4
  if (filled === 0)
@@ -30,21 +30,21 @@ export type DatePanelBaseOptions = {
30
30
  pageBy?: "month" | "visible";
31
31
  /** Show the month of a value that changes from outside (default true). */
32
32
  followValue?: boolean;
33
- autoFocus?: boolean;
34
- min?: DateInput;
35
- max?: DateInput;
33
+ autoFocus?: boolean | undefined;
34
+ min?: DateInput | undefined;
35
+ max?: DateInput | undefined;
36
36
  isDateDisabled?: (date: PlainDate) => boolean;
37
- isDateUnavailable?: (date: PlainDate) => boolean;
37
+ isDateUnavailable?: ((date: PlainDate) => boolean) | undefined;
38
38
  /** Availability model (plan 11 V7): fully unavailable days are not selectable, partial days are. */
39
- availability?: AvailabilitySpec | Availability;
40
- locale?: string;
39
+ availability?: AvailabilitySpec | Availability | undefined;
40
+ locale?: string | undefined;
41
41
  weekStartsOn?: DayOfWeek;
42
- timeZone?: string;
43
- now?: number;
42
+ timeZone?: string | undefined;
43
+ now?: number | undefined;
44
44
  weekNumbers?: "iso" | "locale" | false;
45
- readOnly?: boolean;
46
- disabled?: boolean;
47
- messages?: Partial<Messages>;
45
+ readOnly?: boolean | undefined;
46
+ disabled?: boolean | undefined;
47
+ messages?: Partial<Messages> | undefined;
48
48
  /** `today()` also picks today (single panel). */
49
49
  selectToday?: boolean;
50
50
  };